reactaform 1.8.6 → 1.8.7

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/README.full.md CHANGED
@@ -17,6 +17,8 @@ Design forms using JSON schemas or a visual builder, render them instantly, and
17
17
  - **Playground & Demos:** https://reactaform.vercel.app
18
18
  - **Builder:** https://reactaform.vercel.app/builder
19
19
 
20
+ ![ReactaForm Example](https://raw.githubusercontent.com/yanggmtl/reactaform/master/docs/assets/images/reactaform_example.gif)
21
+
20
22
  ---
21
23
 
22
24
  ## Table of Contents
@@ -34,6 +36,7 @@ Design forms using JSON schemas or a visual builder, render them instantly, and
34
36
  - [Who Is ReactaForm For?](#target-customer)
35
37
  - [Roadmap](#roadmap)
36
38
  - [Contributing](#contributing)
39
+ - [Learn More](#learn-more)
37
40
  - [License](#license)
38
41
 
39
42
 
@@ -427,6 +430,17 @@ Open an issue or submit a pull request.
427
430
 
428
431
  ---
429
432
 
433
+ ## <a id="learn-more"></a> 📘 Learn more
434
+
435
+ - [Full README](https://github.com/yanggmtl/reactaform/blob/master/README.full.md)
436
+ - [ReactaForm Official Site](http://reactaform.vercel.app)
437
+ - [Documentation](https://reactaform.vercel.app/docs)
438
+ - [Demos](http://reactaform.vercel.app/features#Demos)
439
+ - [Visual Builder](https://reactaform.vercel.app/builder)
440
+ - [Examples](https://github.com/yanggmtl/reactaform/tree/master/examples)
441
+
442
+ ---
443
+
430
444
  ## <a id="license"></a> 📄 License
431
445
 
432
446
  MIT
package/README.md CHANGED
@@ -10,6 +10,8 @@ ReactaForm is a schema-driven, extendable form platform for React. Define forms
10
10
  - TypeScript-first
11
11
  - Optimized for large, dynamic forms
12
12
 
13
+ ![ReactaForm Example](https://raw.githubusercontent.com/yanggmtl/reactaform/master/docs/assets/images/reactaform_example.gif)
14
+
13
15
  ## Why ReactaForm?
14
16
 
15
17
  Most React form libraries are code-first:
@@ -101,9 +103,11 @@ npm install reactaform
101
103
  ## Learn more
102
104
 
103
105
  - [Full README](https://github.com/yanggmtl/reactaform/blob/master/README.full.md)
106
+ - [ReactaForm Official Site](http://reactaform.vercel.app)
104
107
  - [Documentation](https://reactaform.vercel.app/docs)
105
- - [ReactaForm Website (Demos)](https://reactaform.vercel.app)
108
+ - [Demos](http://reactaform.vercel.app/features#Demos)
106
109
  - [Visual Builder](https://reactaform.vercel.app/builder)
110
+ - [Examples](https://github.com/yanggmtl/reactaform/tree/master/examples)
107
111
 
108
112
  ## License
109
113
 
@@ -1,4 +1,15 @@
1
1
  import * as React from "react";
2
2
  import type { ReactaFormProps } from "../core/reactaFormTypes";
3
+ /**
4
+ * ReactaForm component - The main form rendering component
5
+ * @param {ReactaFormProps} props - The component props
6
+ * @param {string | Record<string, unknown> | ReactaDefinition} props.definitionData - Form definition data (JSON string, object, or ReactaDefinition)
7
+ * @param {ReactaInstance} [props.instance] - Optional form instance with saved values
8
+ * @param {string} [props.language] - Language code for localization
9
+ * @param {string} [props.className] - Additional CSS class names
10
+ * @param {string} [props.theme] - Theme name ('light' or 'dark')
11
+ * @param {React.CSSProperties} [props.style] - Inline styles
12
+ * @param {FieldValidationMode} [props.fieldValidationMode] - Validation timing mode ('realTime' or 'onSubmission')
13
+ */
3
14
  declare const ReactaForm: React.FC<ReactaFormProps>;
4
15
  export default ReactaForm;
@@ -1,5 +1,17 @@
1
1
  import type { FieldValidationMode, ReactaFormProviderProps } from '../core/reactaFormTypes';
2
2
  import '../core/reactaform.css';
3
+ /**
4
+ * ReactaFormProvider component - Context provider for ReactaForm configuration
5
+ * @param {ReactaFormProviderProps} props - The component props
6
+ * @param {ReactNode} props.children - Child components to wrap with context
7
+ * @param {string} [props.definitionName] - Name of the form definition
8
+ * @param {Record<string, unknown>} [props.defaultStyle] - Default styling configuration
9
+ * @param {string} [props.defaultLanguage='en'] - Default language code for translations
10
+ * @param {string} [props.defaultTheme='light'] - Default theme name
11
+ * @param {string} [props.defaultLocalizeName] - Name of custom localization file
12
+ * @param {FieldValidationMode} [props.defaultFieldValidationMode='realTime'] - Validation timing mode
13
+ * @param {string} [props.className='reactaform-container'] - CSS class name for the container
14
+ */
3
15
  export declare const ReactaFormProvider: ({ children, definitionName, defaultStyle, defaultLanguage, defaultTheme, defaultLocalizeName, defaultFieldValidationMode, className, }: ReactaFormProviderProps & {
4
16
  defaultFieldValidationMode?: FieldValidationMode;
5
17
  }) => import("react/jsx-runtime").JSX.Element;
@@ -6,5 +6,13 @@ export interface ReactaFormRendererProps {
6
6
  chunkSize?: number;
7
7
  chunkDelay?: number;
8
8
  }
9
+ /**
10
+ * ReactaFormRenderer component - Internal form renderer with field management
11
+ * @param {ReactaFormRendererProps} props - The component props
12
+ * @param {ReactaDefinition} props.definition - The form definition object
13
+ * @param {ReactaInstance} props.instance - The form instance with values
14
+ * @param {number} [props.chunkSize=50] - Number of fields to render per chunk for performance
15
+ * @param {number} [props.chunkDelay=50] - Delay in ms between rendering chunks
16
+ */
9
17
  declare const ReactaFormRenderer: React.FC<ReactaFormRendererProps>;
10
18
  export default ReactaFormRenderer;
@@ -64,7 +64,7 @@ export interface ReactaInstance {
64
64
  values: Record<string, FieldValueType>;
65
65
  }
66
66
  export interface ReactaFormProps {
67
- definitionData: string | Record<string, unknown>;
67
+ definitionData: string | Record<string, unknown> | ReactaDefinition;
68
68
  language?: string;
69
69
  instance?: ReactaInstance;
70
70
  className?: string;
@@ -297,7 +297,7 @@
297
297
  \r
298
298
  \r
299
299
  }\r
300
- `,ke=K.createContext(void 0),O=()=>{const e=K.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 tr=typeof process<"u"&&process.env.NODE_ENV==="test";function nr(e,r=300,t){const n=K.useRef(),a=K.useRef(e),o=K.useRef(null),c=t?.leading===!0,s=t?.trailing!==!1;K.useEffect(()=>{a.current=e},[e]),K.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]);const i=p=>{a.current(...p)},m=K.useCallback(()=>{n.current&&(clearTimeout(n.current),n.current=void 0),o.current=null},[]),l=K.useCallback(()=>{n.current&&s&&o.current&&(clearTimeout(n.current),n.current=void 0,i(o.current),o.current=null)},[s]);return{callback:K.useCallback((...p)=>{if(tr){i(p);return}const g=c&&!n.current;o.current=p,g&&i(p),n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{n.current=void 0,s&&o.current&&(i(o.current),o.current=null)},r)},[c,s,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 ce(e){return e.toLowerCase().includes("dark")}function qr(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 Ur=()=>f.jsxs("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[f.jsx("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),f.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),Wr=({content:e,size:r="medium",animation:t=!0})=>{const{t:n,theme:a,formStyle:o,fieldStyle:c}=O(),[s,i]=u.useState(!1),[m,l]=u.useState({x:0,y:0}),[d,p]=u.useState(!1),g=u.useRef(null),S=u.useRef(null),N=u.useRef(null),b=u.useId(),v=ce(a),[I,R]=u.useState(void 0);u.useLayoutEffect(()=>{if(!g.current)return;const x="rgba(255,255,255,0.1)",y=getComputedStyle(g.current).getPropertyValue("--reactaform-primary-bg").trim();if(y&&typeof CSS<"u"&&CSS.supports?.("color: color-mix(in srgb, red, blue)")){const C=qr(y)?"black":"white";R(`color-mix(in srgb, var(--reactaform-primary-bg) 85%, ${C} 15%)`)}else R(x)},[]);const M=u.useMemo(()=>{const h={icon:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"1.2em",height:"1.2em",fontSize:"0.9em",fontWeight:"bold",borderRadius:"50%",backgroundColor:I??(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"}},y=(k,j,E)=>{const T=k?.[j];return(E&&T?T[E]:void 0)??{}};return{icon:{...h.icon,...y(o,"tooltip","icon"),...y(c,"tooltip","icon")},text:{...h.text,...y(o,"tooltip","text"),...y(c,"tooltip","text")},textVisible:h.textVisible}},[v,r,t,o,c,I]);u.useLayoutEffect(()=>{if(!s||!g.current||!S.current){p(!1);return}const x=g.current.getBoundingClientRect();N.current=x;const h=S.current.getBoundingClientRect(),y=8,C=window.innerWidth,k=window.innerHeight,j=-4;let E=x.right+y,A=x.top+x.height/2-h.height/2+j;E+h.width>C-y&&(E=x.left-y-h.width),E=Math.max(y,Math.min(E,C-h.width-y)),A=Math.max(y,Math.min(A,k-h.height-y)),l({x:E,y:A}),p(!0);const T=g.current.closest("[data-reactaform-theme]"),Y=document.getElementById("popup-root");if(T&&Y){const ne=getComputedStyle(T);Y.style.setProperty("--reactaform-tooltip-color-bg",ne.getPropertyValue("--reactaform-tooltip-color-bg")),Y.style.setProperty("--reactaform-tooltip-color",ne.getPropertyValue("--reactaform-tooltip-color"))}},[s]);const w=typeof document<"u"?document.getElementById("popup-root"):null,F=f.jsx("div",{ref:S,"data-tooltip-id":b,style:{...M.text,transform:d?"translateY(0) scale(1)":"translateY(-4px) scale(0.98)",transition:"opacity 120ms ease, transform 120ms ease, visibility 120ms ease",width:240,...d?M.textVisible:{},top:m.y,left:m.x},children:n(e)});return f.jsxs(f.Fragment,{children:[f.jsx("span",{"data-testid":"tooltip-icon",ref:g,"aria-describedby":s?b:void 0,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),style:{...M.icon},children:f.jsx(Ur,{})}),s&&(w?fe.createPortal(F,w):F)]})},ar=u.memo(Wr),ye=u.memo(({field:e,error:r,children:t,showLabel:n=!0})=>{const{t:a}=O(),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]),s=u.useMemo(()=>({textAlign:o,width:"100%",minWidth:"unset",display:"block",marginBottom:"10px"}),[o]),i=u.useMemo(()=>({display:"flex",alignItems:"center",gap:"var(--reactaform-inline-gap, 8px)",width:"100%"}),[]);return f.jsxs("div",{className:`${V.field} column-layout`,style:c,children:[n&&f.jsx("label",{id:`${e.name}-label`,className:V.label,htmlFor:e.name,style:s,children:a(e.displayName)}),f.jsxs("div",{style:i,children:[f.jsx("div",{style:{flex:1,minWidth:0},children:t}),e.tooltip&&f.jsx(ar,{content:e.tooltip})]}),r&&f.jsx(je,{id:`${e.name}-error`,children:r})]})});ye.displayName="ColumnFieldLayout";const or=u.memo(({field:e,error:r,children:t,rightAlign:n=!1})=>{const{t:a}=O(),o=u.useMemo(()=>({display:"flex",alignItems:"center",gap:"3px"}),[]);return f.jsxs("div",{className:`${V.field} row-layout`,children:[f.jsx("label",{id:`${e.name}-label`,className:V.label,htmlFor:e.name,children:a(e.displayName)}),f.jsxs("div",{children:[f.jsxs("div",{style:o,children:[n?f.jsx("div",{style:{display:"flex",flex:1,justifyContent:"flex-end"},children:t}):t,e.tooltip&&f.jsx(ar,{content:e.tooltip})]}),r&&f.jsx(je,{id:`${e.name}-error`,children:r})]})]})});or.displayName="RowFieldLayout";const P=u.memo(({field:e,error:r,children:t,rightAlign:n=!1})=>e.labelLayout==="column-left"||e.labelLayout==="column-center"?f.jsx(ye,{field:e,error:r,showLabel:!0,children:t}):e.type==="checkbox"||e.type==="switch"?f.jsx(ye,{field:e,error:r,showLabel:!1,children:t}):f.jsx(or,{field:e,error:r,rightAlign:n,children:t}));P.displayName="StandardFieldLayout";const je=u.memo(({children:e,id:r})=>{const t=u.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 f.jsx("div",{id:r,style:t,children:e})});je.displayName="ErrorDiv";const sr=u.memo(({name:e,onChange:r})=>{const{t}=O();return f.jsxs("div",{style:{marginBottom:16},children:[f.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 2fr",gap:12,alignItems:"center"},children:[f.jsx("label",{htmlFor:"instance-name-input",style:{margin:0,fontSize:"0.95em",fontWeight:500,color:"var(--reactaform-text-color, #333)"},children:t("Instance Name")}),f.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")})]}),f.jsx("div",{style:{height:"1px",backgroundColor:"var(--reactaform-separator, #e6e6e6)",marginTop:12,marginBottom:12}})]})});sr.displayName="InstanceName";class _r 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 ir=new ie,cr=new _r,Ee=new ie;function lr(e,r){ir.register(e,r)}function ur(e,r,t){cr.registerInCategory(e,r,t)}function mr(e,r){if(At(e)){console.warn(`[ReactaForm] Can't override builtin type field validation handler for type "${e}".`);return}Ee.register(e,r)}function L(e,r){Ee.register(e,r)}function fr(e,r){return cr.getFromCategory(e,r)||null}function dr(e){return ir.get(e)||null}function pr(e){return Ee.get(e)||null}function Kr(e){return(typeof e=="object"||typeof e=="function")&&e!==null&&typeof e.then=="function"}const He=new Map,Be=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[i,m]=r.validationHandlerName;if(m)a=i,o=m;else if(i)a=e,o=i;else return null}else return null;const c=`${a}:${o}`;let s=He.get(c);if(s===void 0&&(s=fr(a,o)||null,He.set(c,s)),s)try{return s(r.name,t,n)||null}catch(i){return String(i instanceof Error?i.message:i)}return null}function Gr(e,r,t,n){return Ne(e,r,t,n)}function gr(e,r,t,n){const a=pr(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 Jr(e,r,t){if(!e||typeof e.validationHandlerName!="string")return null;const n=e.validationHandlerName;let a=Be.get(n);if(a===void 0&&(a=dr(n)||null,Be.set(n,a)),a)try{const o=a(r,t);return Kr(o)?await o||null:o||null}catch(o){return[String(o instanceof Error?o.message:o)]}return null}function z(e,r){const{definitionName:t,t:n,fieldValidationMode:a}=O();return u.useCallback(o=>a==="realTime"?gr(t,e,o,n):r??null,[t,e,n,a,r])}const Yr=({field:e,value:r=!1,onChange:t,onError:n,error:a})=>{const{t:o}=O(),s=z(e,a)(r);u.useEffect(()=>{a||n?.(s)},[s,a,n]);const i=u.useCallback(d=>{t?.(d.target.checked)},[t]),m=u.useCallback(d=>{(d.key===" "||d.key==="Space"||d.key==="Spacebar"||d.code==="Space"||d.key==="Enter")&&(d.preventDefault(),t?.(!r))},[t,r]),l=e.name;return f.jsx(P,{field:e,rightAlign:!1,error:s,children:f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[f.jsx("label",{className:V.label,htmlFor:l,style:{textAlign:"left",justifyContent:"flex-start"},children:o(e.displayName)}),f.jsx("input",{id:l,"data-testid":"boolean-checkbox",type:"checkbox",checked:r,onChange:i,onKeyDown:m,"aria-checked":r,"aria-invalid":!!s,"aria-describedby":s?`${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=u.useRef(null),o=u.useRef(null),c=u.useRef(t),[s,i]=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),i(p)),a.current&&a.current.value!==l&&(a.current.value=l)}},[e,n]);const m=u.useCallback(l=>{const d=l.target.value,p=n(d);p!==o.current&&(o.current=p,i(p),c.current?.(p??null)),r?.(d)},[r,n]);return{inputRef:a,error:s,handleChange:m}}const qe=[{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"}],Xr=/^#([0-9A-F]{3}){1,2}$/i,Zr="#000000",Qr=e=>Xr.test(e),pe=e=>{if(!e||!Qr(e))return Zr;const r=e.toLowerCase();return r.length===4?"#"+r.slice(1).split("").map(t=>t+t).join(""):r},et=e=>{const r=parseInt(e.slice(1),16);return{r:r>>16&255,g:r>>8&255,b:r&255}},rt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=O(),c=z(e,a),s=u.useMemo(()=>pe(r),[r]),{inputRef:i,error:m,handleChange:l}=W({value:s,onChange:t,onError:n,validate:c}),[d,p]=u.useState(s);u.useEffect(()=>{a||n?.(m)},[m,a,n]),u.useEffect(()=>{p(s)},[s]);const g=u.useCallback(M=>{const w=pe(M.target.value);p(w),l({target:{value:w}})},[l]),S=u.useCallback(M=>{const w=pe(M.target.value);p(w),l({target:{value:w}})},[l]),b=u.useMemo(()=>new Set(qe.map(M=>M.value)),[]).has(d),{r:v,g:I,b:R}=u.useMemo(()=>et(d),[d]);return f.jsx(P,{field:e,error:m,children:f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,width:"100%"},children:[f.jsxs("select",{id:e.name,value:d,onChange:S,className:B(V.input,V.inputSelect),"aria-invalid":!!m,children:[qe.map(M=>f.jsx("option",{value:M.value,children:o(M.label)},M.value)),!b&&f.jsxs("option",{value:d,children:["(",v,", ",I,", ",R,")"]})]}),f.jsx("label",{style:{width:"2.5em",height:"1.8em",border:"1px solid #ccc",borderRadius:4,backgroundColor:d,cursor:"pointer",overflow:"hidden",flexShrink:0},children:f.jsx("input",{ref:i,id:`${e.name}-color`,type:"color",defaultValue:d,onChange:g,style:{opacity:0,width:"100%",height:"100%"},"aria-invalid":!!m})})]})})},Ue=e=>{if(!e)return null;const r=new Date(e);return isNaN(r.getTime())?null:r},We=e=>{if(!e)return"";if(/^\d{4}-\d{2}-\d{2}$/.test(e))return Ue(e)?e:"";const t=Ue(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""},tt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),c=We(r),{inputRef:s,error:i,handleChange:m}=W({value:c,onChange:t,onError:n,validate:o});return u.useEffect(()=>{a||n?.(i)},[i,a,n]),f.jsx(P,{field:e,error:i,children:f.jsx("input",{id:e.name,type:"date",ref:s,defaultValue:We(r),onChange:m,className:B(V.input,V.textInput),...e.minDate?{min:e.minDate}:{},...e.maxDate?{max:e.maxDate}:{},"aria-invalid":!!i,"aria-describedby":i?`${e.name}-error`:void 0})})},nt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o,theme:c,formStyle:s,fieldStyle:i}=O(),m=u.useRef(null),l=u.useRef(n),[d,p]=u.useState(!1),[g,S]=u.useState(null);u.useEffect(()=>{l.current=n},[n]);const N=z(e,a),[b,v]=u.useState(null),I=u.useRef(null);u.useEffect(()=>{const y=String(r??"");let C=N(y);if(C&&e.options.length>0){const k=String(e.options[0].value);t?.(k),C=null}C!==I.current&&(I.current=C,v(C),l.current?.(C??null))},[r,N,t,e.options]);const R=()=>{if(!m.current)return;const y=m.current.getBoundingClientRect();S({x:y.left,y:y.bottom}),p(C=>!C)},M=y=>{const C=N(y);C!==I.current&&(I.current=C,v(C),l.current?.(C??null)),t?.(y),p(!1)},w=u.useMemo(()=>{const y=e.options.find(C=>String(C.value)===String(r));return y?o(y.label):""},[e.options,r,o]),F=(y,C,k)=>{if(!C)return{};const E=y?.[C];return(k&&E?E[k]:void 0)??{}},x=u.useMemo(()=>({height:"var(--reactaform-input-height, 2.5rem)",display:"flex",alignItems:"center",cursor:"pointer",position:"relative",...F(s,"dropdown","control"),...F(i,void 0,"control")}),[s,i]),h=u.useMemo(()=>({position:"absolute",right:"0.7em",top:"50%",transform:"translateY(-50%)",pointerEvents:"none",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",...F(s,"dropdown","arrow"),...F(i,void 0,"arrow")}),[s,i]);return f.jsxs("div",{children:[f.jsx(P,{field:e,error:b,children:f.jsxs("div",{ref:m,className:"reactaform-input",style:x,onClick:R,tabIndex:0,role:"combobox","aria-haspopup":"listbox","aria-expanded":d,"aria-invalid":!!b,"aria-describedby":b?`${e.name}-error`:void 0,onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),R())},children:[f.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:w}),f.jsx("span",{style:h,"aria-hidden":!0,children:"▼"})]})}),d&&g&&f.jsx(at,{position:g,options:e.options,selectedValue:String(r),onSelect:M,onClose:()=>p(!1),controlRef:m,theme:c,t:o})]})},at=({position:e,options:r,selectedValue:t,onSelect:n,onClose:a,controlRef:o,theme:c,t:s})=>{const i=u.useRef(null),[m,l]=u.useState(-1),{formStyle:d,fieldStyle:p}=O(),g=ce(c??"light");u.useLayoutEffect(()=>{if(!o.current)return;const h=o.current.closest("[data-reactaform-theme]"),y=document.getElementById("popup-root");if(h&&y){const C=getComputedStyle(h);y.style.setProperty("--reactaform-secondary-bg",C.getPropertyValue("--reactaform-secondary-bg")),y.style.setProperty("--reactaform-text-color",C.getPropertyValue("--reactaform-text-color")),y.style.setProperty("--reactaform-hover-bg",C.getPropertyValue("--reactaform-hover-bg"))}},[o]);const S=(h,y,C)=>{if(!y)return{};const j=h?.[y];return(C&&j?j[C]:void 0)??{}},N=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)",...S(d,"dropdown","popup"),...S(p,void 0,"popup")}),[d,p]),b=u.useMemo(()=>({padding:"6px 8px",cursor:"pointer",display:"flex",alignItems:"center",background:"transparent",color:"var(--reactaform-text-color, #000)",...S(d,"dropdown","option"),...S(p,void 0,"option")}),[d,p]);u.useEffect(()=>{const h=y=>{const C=y.target;!i.current?.contains(C)&&!o.current?.contains(C)&&a()};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[a,o]),u.useEffect(()=>{if(i.current&&r.length>0){const h=r.findIndex(y=>String(y.value)===t);requestAnimationFrame(()=>l(h>=0?h:0))}},[r,t]),u.useEffect(()=>{if(!i.current||m<0)return;const h=i.current.querySelector(`#opt-${m}`);h&&requestAnimationFrame(()=>h.focus())},[m]);const v=250,I=200,[R,M]=u.useState(null),[w,F]=u.useState(null);if(u.useEffect(()=>{if(typeof window>"u")return;const h=()=>{let k=e.x,j=e.y,E=v;const A=o?.current;if(A){const T=A.getBoundingClientRect();k=T.left,j=T.bottom,E=Math.max(80,Math.round(T.width))}k=Math.min(k,window.innerWidth-E),j=Math.min(j,window.innerHeight-I),M({left:k,top:j}),F(E)};h(),window.addEventListener("scroll",h,!0),window.addEventListener("resize",h);let y=null;const C=o?.current;return typeof ResizeObserver<"u"&&C&&(y=new ResizeObserver(()=>h()),y.observe(C)),()=>{window.removeEventListener("scroll",h,!0),window.removeEventListener("resize",h),y&&C&&y.unobserve(C)}},[o,e.x,e.y]),typeof window>"u")return null;let x=document.getElementById("popup-root");return x||(x=document.createElement("div"),x.id="popup-root",document.body.appendChild(x)),fe.createPortal(f.jsx("div",{ref:i,role:"listbox","aria-activedescendant":m>=0?`opt-${m}`:void 0,style:{position:"fixed",top:R?R.top:e.y,left:R?R.left:e.x,width:w??v,...N},"data-reactaform-theme":c??"light",children:r.map((h,y)=>{const C=String(h.value)===t,k=g?"var(--reactaform-hover-bg, rgba(255,255,255,0.01))":"var(--reactaform-hover-bg, #eee)",j={...b,background:y===m?k:b.background,fontWeight:C?"bold":"normal"};return f.jsx("div",{id:`opt-${y}`,onMouseDown:E=>{E.stopPropagation(),n(String(h.value))},onKeyDown:E=>{const A=r.length;switch(E.key){case"ArrowDown":E.preventDefault(),l(T=>(T+1)%A);break;case"ArrowUp":E.preventDefault(),l(T=>(T-1+A)%A);break;case"Home":E.preventDefault(),l(0);break;case"End":E.preventDefault(),l(A-1);break;case"Enter":case" ":E.preventDefault(),E.stopPropagation(),n(String(h.value));break;case"Escape":E.preventDefault(),a(),o?.current?.focus();break}},tabIndex:y===m?0:-1,role:"option","aria-selected":C,style:j,onMouseEnter:E=>{E.currentTarget.style.background=k,l(y)},onMouseLeave:E=>{E.currentTarget.style.background="transparent",l(A=>A===y?-1:A)},children:s(h.label)},String(h.value))})}),x)},ot=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o});return f.jsx(P,{field:e,error:s,children:f.jsx("input",{id:e.name,type:"email",defaultValue:String(r??""),ref:c,onChange:i,className:B(V.input,V.textInput),"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},st=({field:e})=>{const{theme:r}=O(),{color:t=ce(r)?"#444444":"#CCCCCC",thickness:n=1,margin:a="8px 0"}=e;return f.jsx("div",{style:{width:"auto",height:"0",borderTop:`${n}px solid ${t}`,margin:a}})},it=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=O(),[c,s]=u.useState(!1),i=u.useRef(null),m=u.useRef(n),l=u.useRef(null),[d,p]=u.useState(null);u.useEffect(()=>{m.current=n},[n]);const g=(w,F)=>F.some(x=>x.name===w.name&&x.size===w.size&&x.lastModified===w.lastModified),S=z(e,a);u.useEffect(()=>{const w=S(r??[]);t?.(r),w!==l.current&&(l.current=w,p(w),m.current?.(w??null))},[r,S]);const N=w=>{const F=w.target.files;let x=null;if(F&&F.length>0){const y=Array.from(F);if(e.multiple){const C=Array.isArray(r)?r:[],k=y.filter(j=>!g(j,C));x=[...C,...k]}else x=y[0]}const h=S(x??[]);h!==l.current&&(l.current=h,p(h),m.current?.(h??null)),t?.(x),w.target&&(w.target.value="")},b=w=>{w.preventDefault(),w.stopPropagation(),s(!1);const F=w.dataTransfer.files;if(F&&F.length>0){const x=Array.from(F);let h=null;if(e.multiple){const C=Array.isArray(r)?r:[],k=x.filter(j=>!g(j,C));h=[...C,...k]}else h=x[0];const y=S(h);y!==l.current&&(l.current=y,p(y),m.current?.(y??null)),t?.(h)}},v=w=>{w.preventDefault(),w.stopPropagation(),s(!0)},I=w=>{w.preventDefault(),w.stopPropagation(),s(!1)},R=w=>{if(Array.isArray(r)&&typeof w=="number"){const F=r.filter((y,C)=>C!==w),x=F.length>0?F:null,h=S(x??[]);h!==l.current&&(l.current=h,p(h),m.current?.(h??null)),t?.(x)}else{const F=S([]);F!==l.current&&(l.current=F,p(F),m.current?.(F??null)),t?.(null)}},M=()=>{const w=Array.isArray(r)?r:r?[r]:[];return w.length===0?null:f.jsx("div",{style:{marginTop:"8px",marginLeft:"20px",display:"flex",flexDirection:"column",gap:"6px",maxHeight:"200px",overflowY:"auto"},children:w.map((F,x)=>f.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[f.jsx("input",{type:"text",value:F.name,disabled:!0,readOnly:!0,title:F.name,className:"reactaform-input",style:{flex:1,cursor:"default",opacity:.8,minWidth:0}}),f.jsx("button",{type:"button",onClick:()=>R(Array.isArray(r)?x: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:h=>{h.currentTarget.style.backgroundColor="var(--reactaform-bg-hover, #fee)"},onMouseLeave:h=>{h.currentTarget.style.backgroundColor="transparent"},children:"×"})]},`${F.name}-${x}`))})};return f.jsx(P,{field:e,error:d,children:f.jsxs("div",{style:{width:"100%"},children:[f.jsxs("div",{className:"reactaform-input",onDrop:b,onDragOver:v,onDragLeave:I,style:{position:"relative",borderStyle:"dashed",borderColor:c?"var(--reactaform-color-primary, #2563eb)":d?"var(--reactaform-color-error, #ef4444)":void 0,borderWidth:"1px",borderRadius:"var(--reactaform-border-radius, 4px)",padding:"8px 12px",textAlign:"center",backgroundColor:c?"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:()=>i.current?.click(),onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),i.current?.click())},role:"button","aria-label":e.multiple?o("Choose Files or Drag & Drop"):o("Choose File or Drag & Drop"),"aria-invalid":!!d,"aria-describedby":d?`${e.name}-error`:void 0,children:[f.jsx("input",{id:e.name,ref:i,type:"file",accept:e.accept,multiple:e.multiple,style:{display:"none"},onChange:N}),f.jsx("div",{style:{fontSize:"1.25rem",opacity:.6,lineHeight:1,flexShrink:0},children:"📁"}),f.jsx("div",{style:{fontSize:"0.875rem",fontWeight:400,color:"var(--reactaform-text-color, #111827)",flex:1,textAlign:"left"},children:c?o("Drop files here"):e.multiple?o("Choose Files or Drag & Drop"):o("Choose File or Drag & Drop")}),e.accept&&f.jsx("div",{style:{fontSize:"0.75rem",color:"var(--reactaform-text-muted, #6b7280)",whiteSpace:"nowrap",opacity:c?0:1,transition:"opacity 0.15s ease",pointerEvents:c?"none":"auto"},children:e.accept})]}),M()]})})},ct=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),c=Array.isArray(r)?r.join(", "):String(r??""),{inputRef:s,error:i,handleChange:m}=W({value:c,onChange:t,onError:n,validate:o});return f.jsx(P,{field:e,error:i,children:f.jsx("input",{id:e.name,type:"text",defaultValue:c,ref:s,onChange:m,className:B(V.input,V.textInput),style:{flex:1},"aria-invalid":!!i,"aria-describedby":i?`${e.name}-error`:void 0})})},lt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o}),m=a??s;return f.jsx(P,{field:e,error:m,children:f.jsx("input",{id:e.name,type:"text",ref:c,defaultValue:String(r??""),onChange:i,className:B(V.input,V.inputNumber),"aria-invalid":!!m,"aria-describedby":m?`${e.name}-error`:void 0})})};function ut(){try{return"/"}catch{}try{if(typeof process<"u"&&process?.env?.PUBLIC_URL)return process.env.PUBLIC_URL}catch{}return"/"}const mt=({field:e,value:r})=>{const{language:t,t:n}=O(),a=e.alignment||"center",o={left:"flex-start",center:"center",right:"flex-end"},c=typeof r=="string"?r:"";let s=c&&c.trim()!==""?c:typeof e.defaultValue=="string"?e.defaultValue:"";s&&!s.startsWith("/")&&(s=`${ut()}${s}`);const i=e.localized?.split(";").map(b=>b.trim()),[m,l]=u.useState(s||""),d=u.useRef(s||null);if(u.useEffect(()=>{if(!s)return;const b=s.split("/"),v=b.pop(),I=v.lastIndexOf(".");if(I===-1)return;const R=v.substring(0,I),M=v.substring(I);let w=null;i?.includes(t)&&(w=`${R}_${t}${M}`);const F=new AbortController;if(w){const x=[...b,w].join("/");fetch(x,{method:"HEAD",signal:F.signal}).then(h=>{const y=h.ok?x:s;y!==d.current&&(d.current=y,l(y))}).catch(()=>{s!==d.current&&(d.current=s,l(s))})}else{const x=s;x!==d.current&&(d.current=x,requestAnimationFrame(()=>l(x)))}return()=>{F.abort()}},[s,t,i]),!m)return null;const{width:p,height:g}=e,S={},N={borderRadius:"8px",objectFit:"contain",boxShadow:"0 2px 6px rgba(0,0,0,0.1)",margin:"0 0 8px 0"};return p&&g?(S.width=p,S.height=g,N.width=`${p}px`,N.height=`${g}px`):p&&!g?(S.width=p,N.width=`${p}px`,N.height="auto"):!p&&g&&(S.height=g,N.width="auto",N.height=`${g}px`),f.jsx(P,{field:e,children:f.jsx("div",{"data-testid":"image-wrapper",style:{display:"flex",justifyContent:o[a]||"center",margin:"0 0"},children:f.jsx("img",{src:m,alt:n?.(e.displayName||"Image")||e.displayName||"Image",...S,style:N})})})},ft=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),c=Array.isArray(r)?r.join(", "):String(r??""),{inputRef:s,error:i,handleChange:m}=W({value:c,onChange:t,onError:n,validate:o});return f.jsx(P,{field:e,error:i,children:f.jsx("input",{id:e.name,type:"text",defaultValue:c,ref:s,onChange:m,className:B(V.input,V.textInput),style:{flex:1},"aria-invalid":!!i,"aria-describedby":i?`${e.name}-error`:void 0})})},hr=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o});return f.jsx(P,{field:e,error:s,children:f.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:c,onChange:i,className:B(V.input,V.inputNumber),"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})};hr.displayName="IntegerInput";const dt=u.memo(hr),pt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o});return f.jsx(P,{field:e,error:s,children:f.jsx("textarea",{id:e.name,defaultValue:String(r??""),ref:c,onChange:i,style:{resize:"vertical",minHeight:e.minHeight??"80px",width:"100%",boxSizing:"border-box"},className:B(V.input,V.textInput),"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},gt=({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:s,formStyle:i,fieldStyle:m}=O(),l=(k,j,E)=>{if(!j)return{};const T=k?.[j];return(E&&T?T[E]:void 0)??{}},d=u.useRef(null),[p,g]=u.useState(!1),[S,N]=u.useState(null),b=u.useMemo(()=>e.options.map(k=>({value:k.value,label:c(k.label)})),[e.options,c]),v=u.useMemo(()=>{const k=Array.isArray(r)?r:[],j=new Set(b.map(E=>E.value));return k.filter(E=>j.has(E))},[r,b]),I=z(e,a),[R,M]=u.useState(null),w=u.useRef(null);u.useEffect(()=>{const k=I(Array.isArray(r)?r:[]);k!==w.current&&(w.current=k,M(k),o.current?.(k??null))},[r,I]);const F=()=>{if(!d.current)return;const k=d.current.getBoundingClientRect();N({x:k.left,y:k.bottom}),g(j=>!j)},x=k=>{const j=v.includes(k)?v.filter(A=>A!==k):[...v,k],E=I(j);E!==w.current&&(w.current=E,M(E),o.current?.(E??null)),t?.(j)},h=u.useMemo(()=>({height:"var(--reactaform-input-height, 2.5rem)",display:"flex",alignItems:"center",cursor:"pointer",position:"relative",...l(i,"multiSelect","control"),...l(m,void 0,"control")}),[i,m]),y=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(i,"multiSelect","clearButton"),...l(m,void 0,"clearButton")}),[i,m]),C=u.useMemo(()=>({position:"absolute",right:"0.7em",top:"50%",transform:"translateY(-50%)",pointerEvents:"none",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",...l(i,"multiSelect","arrow"),...l(m,void 0,"arrow")}),[i,m]);return f.jsxs("div",{children:[f.jsx(P,{field:e,error:R,children:f.jsx("div",{style:{width:"100%"},children:f.jsxs("div",{ref:d,className:"reactaform-multiselection-control reactaform-input",style:h,onClick:F,role:"button","aria-haspopup":"listbox","aria-expanded":p,"aria-invalid":!!R,"aria-describedby":R?`${e.name}-error`:void 0,onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),F())},children:[f.jsxs("span",{style:{flex:1,color:"var(--reactaform-text-muted, #888)"},children:[v.length," / ",b.length," selected"]}),v.length>0&&f.jsx("button",{type:"button","aria-label":"Clear selections",onClick:k=>{k.stopPropagation(),t?.([])},style:y,children:f.jsx("span",{style:y,"aria-hidden":!0,children:"✖"})}),f.jsx("span",{style:C,"aria-hidden":!0,children:"▼"})]})})}),p&&S&&f.jsx(ht,{position:S,options:b,selectedValues:v,onToggleOption:x,onClose:()=>g(!1),controlRef:d,theme:s})]})},ht=({position:e,options:r,selectedValues:t,onToggleOption:n,onClose:a,controlRef:o,theme:c})=>{const s=u.useRef(null),[i,m]=u.useState(-1),{formStyle:l,fieldStyle:d}=O(),p=ce(c??"light");u.useLayoutEffect(()=>{if(!o.current)return;const x=o.current.closest("[data-reactaform-theme]"),h=document.getElementById("popup-root");if(x&&h){const y=getComputedStyle(x);h.style.setProperty("--reactaform-secondary-bg",y.getPropertyValue("--reactaform-secondary-bg")),h.style.setProperty("--reactaform-text-color",y.getPropertyValue("--reactaform-text-color")),h.style.setProperty("--reactaform-hover-bg",y.getPropertyValue("--reactaform-hover-bg"))}},[o]);const g=(x,h,y)=>{if(!h)return{};const k=x?.[h];return(y&&k?k[y]:void 0)??{}},S=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)",...g(l,"multiSelect","popup"),...g(d,void 0,"popup")}),[l,d]),N=u.useMemo(()=>({padding:"6px 8px",cursor:"pointer",display:"flex",alignItems:"center",background:"transparent",color:"var(--reactaform-text-color, #000)",...g(l,"multiSelect","option"),...g(d,void 0,"option")}),[l,d]);u.useEffect(()=>{const x=h=>{const y=h.target;!s.current?.contains(y)&&!o.current?.contains(y)&&a()};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[a,o]),u.useEffect(()=>{s.current&&r.length>0&&requestAnimationFrame(()=>m(x=>x===-1?0:x))},[r.length]),u.useEffect(()=>{if(!s.current||i<0)return;const x=s.current.querySelector(`#multi-opt-${i}`);x&&requestAnimationFrame(()=>x.focus())},[i]);const b=250,v=200,[I,R]=u.useState(null),[M,w]=u.useState(null);if(u.useEffect(()=>{if(typeof window>"u")return;const x=()=>{let C=e.x,k=e.y,j=b;const E=o?.current;if(E){const A=E.getBoundingClientRect();C=A.left,k=A.bottom,j=Math.max(80,Math.round(A.width))}C=Math.min(C,window.innerWidth-j),k=Math.min(k,window.innerHeight-v),R({left:C,top:k}),w(j)};x(),window.addEventListener("scroll",x,!0),window.addEventListener("resize",x);let h=null;const y=o?.current;return typeof ResizeObserver<"u"&&y&&(h=new ResizeObserver(()=>x()),h.observe(y)),()=>{window.removeEventListener("scroll",x,!0),window.removeEventListener("resize",x),h&&y&&h.unobserve(y)}},[o,e.x,e.y]),typeof window>"u")return null;let F=document.getElementById("popup-root");return F||(F=document.createElement("div"),F.id="popup-root",document.body.appendChild(F)),fe.createPortal(f.jsx("div",{ref:s,role:"listbox","aria-activedescendant":i>=0?`multi-opt-${i}`:void 0,style:{position:"fixed",top:I?I.top:e.y,left:I?I.left:e.x,width:M??b,...S},"data-reactaform-theme":c??"light",children:r.map((x,h)=>{const y=t.includes(x.value),C=p?"var(--reactaform-hover-bg, rgba(255,255,255,0.01))":"var(--reactaform-hover-bg, #eee)",k={...N,background:h===i?C:N.background};return f.jsxs("div",{id:`multi-opt-${h}`,onMouseDown:j=>{j.stopPropagation(),n(x.value)},onKeyDown:j=>{const E=r.length;switch(j.key){case"ArrowDown":j.preventDefault(),m(A=>(A+1)%E);break;case"ArrowUp":j.preventDefault(),m(A=>(A-1+E)%E);break;case"Home":j.preventDefault(),m(0);break;case"End":j.preventDefault(),m(E-1);break;case"Enter":case" ":j.preventDefault(),j.stopPropagation(),n(x.value);break;case"Escape":j.preventDefault(),a(),o?.current?.focus();break}},tabIndex:h===i?0:-1,role:"option","aria-selected":y,style:k,onMouseEnter:j=>{j.currentTarget.style.background=C,m(h)},onMouseLeave:j=>{j.currentTarget.style.background="transparent",m(E=>E===h?-1:E)},children:[f.jsx("input",{type:"checkbox",checked:y,readOnly:!0,style:{marginRight:8,width:"1.125em",height:"1.125em",verticalAlign:"middle",accentColor:p?"#10b981":"#22c55e",cursor:"pointer"}}),x.label]},x.value)})}),F)},yt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),{inputRef:c,error:s,handleChange:i}=W({value:String(r??""),onChange:t,onError:n,validate:o}),m=Math.max(1,Math.round(e.step??1));return f.jsx(P,{field:e,error:s,children:f.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:i,style:{width:"100%",height:"100%"},className:V.input,"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},bt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o});return f.jsx(P,{field:e,error:s,children:f.jsx("input",{id:e.name,type:"tel",defaultValue:String(r??""),ref:c,onChange:i,className:B(V.input,V.textInput),"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},vt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=O(),c=z(e,a),s=e.layout?.toLowerCase()==="horizontal"?"row":"column",i=u.useRef(n);u.useEffect(()=>{i.current=n},[n]);const[m,l]=u.useState(null),d=u.useRef(null),p=u.useCallback(b=>{b!==d.current&&(d.current=b,l(b),i.current?.(b))},[]);u.useEffect(()=>{const b=r!=null?String(r):"",v=c(b);if(v&&e.options.length>0){const I=String(e.options[0].value);t?.(I)}p(v)},[r,e.options,c,t,p]);const g=b=>{const v=b.target.value,I=c(v);p(I),t?.(v)},S={display:"flex",flexDirection:s,flexWrap:s==="row"?"wrap":"nowrap",gap:s==="row"?"12px":"4px",alignItems:s==="row"?"center":"stretch",width:"100%",padding:s==="row"?"8px":void 0,boxSizing:"border-box"},N={display:s==="column"?"flex":"inline-flex",gap:"8px",alignItems:"center",whiteSpace:"nowrap",marginBottom:s==="column"?6:0,cursor:"pointer",width:s==="column"?"100%":void 0,justifyContent:"flex-start"};return f.jsx(P,{field:e,error:m,children:f.jsx("div",{className:V.input,"aria-labelledby":`${e.name}-label`,"aria-invalid":!!m,style:S,children:e.options.map(b=>{const v=String(b.value),I=`${e.name}-${v}`;return f.jsxs("label",{className:B(V.label),style:N,onMouseDown:R=>R.preventDefault(),onClick:()=>{String(r??"")!==v&&g({target:{value:v}})},children:[f.jsx("input",{id:I,type:"radio",name:e.name,value:v,checked:String(r??"")===v,onChange:g,style:{width:"1.1em",height:"1.1em"}}),f.jsx("span",{style:{userSelect:"none",textAlign:s==="column"?"left":void 0,flex:s==="column"?1:void 0,fontWeight:400},children:o(b.label)})]},v)})})})},xt={display:"flex",gap:4},wt={cursor:"pointer",fontSize:"1.5rem",lineHeight:1,display:"inline-block",marginRight:"0.25rem",userSelect:"none",transition:"color 0.12s ease"},St=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=O(),c=z(e,a),s=e.max??5,i=e.icon?.trim()||"★",[m,l]=u.useState(null),d=u.useRef([]),p=u.useMemo(()=>Math.min(Math.max(r??0,0),s),[r,s]),g=u.useMemo(()=>c(p)??null,[c,p]);u.useEffect(()=>{n?.(g)},[g,n]);const S=u.useCallback(b=>{const v=Math.min(Math.max(b,0),s);c(v),t?.(v)},[s,c,t]),N=u.useCallback((b,v)=>{switch(b.key){case"Enter":case" ":b.preventDefault(),S(v+1);break;case"ArrowRight":case"ArrowUp":b.preventDefault(),d.current[Math.min(s-1,v+1)]?.focus();break;case"ArrowLeft":case"ArrowDown":b.preventDefault(),d.current[Math.max(0,v-1)]?.focus();break}},[s,S]);return f.jsx(P,{field:e,error:g,children:f.jsx("div",{role:"radiogroup","aria-labelledby":`${e.name}-label`,"aria-invalid":!!g,"aria-describedby":g?`${e.name}-error`:void 0,style:xt,children:Array.from({length:s},(b,v)=>{const I=v<p,M=m!==null&&v<=m||I?"gold":"lightgray";return f.jsx("span",{ref:w=>d.current[v]=w,role:"radio",tabIndex:p>0?v===p-1?0:-1:v===0?0:-1,"aria-checked":I,"aria-label":`Rating ${v+1}`,title:o(`${e.displayName} ${v+1}`),onClick:()=>S(v+1),onKeyDown:w=>N(w,v),onMouseEnter:()=>l(v),onMouseLeave:()=>l(null),style:{...wt,color:M},children:i},v)})})})},Ct=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=O(),c=z(e,a),{inputRef:s,error:i,handleChange:m}=W({value:r,onChange:t,onError:n,validate:c}),[l,d]=u.useState(!1),p=()=>d(g=>!g);return f.jsx(P,{field:e,error:i,children:f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,width:"100%"},children:[f.jsx("input",{id:e.name,type:l?"text":"password",defaultValue:String(r??""),ref:s,onChange:m,className:B(V.input,V.textInput),style:{flex:1,minWidth:0},"aria-invalid":!!i,"aria-describedby":i?`${e.name}-error`:void 0}),f.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?"🙈":"👁️"})]})})},kt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),c=e.min??0,s=e.max??100,[i,m]=u.useState(()=>isNaN(Number(r))?String(c):String(Number(r)));u.useEffect(()=>{const g=isNaN(Number(r))?String(c):String(Number(r));m(g)},[r,c]);const l=u.useMemo(()=>o(i)??null,[o,i]);u.useEffect(()=>{n?.(l)},[l,n]);const d=u.useCallback(g=>{const S=g.target.value;m(S),o(S),t?.(S)},[o,t]),p=isNaN(Number(i))?String(c):String(Number(i));return f.jsx(P,{field:e,error:l,children:f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%"},children:[f.jsx("input",{id:`${e.name}-range`,type:"range",value:p,onChange:d,min:c,max:s,step:"1.0",style:{padding:0,flex:1},className:V.rangeInput,"aria-invalid":!!l,"aria-describedby":l?`${e.name}-error`:void 0}),f.jsx("input",{id:e.name,type:"text",value:i,onChange:d,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})]})})},jt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o,formStyle:c,fieldStyle:s,fieldValidationMode:i}=O(),l=z(e,a)(r);u.useEffect(()=>{i==="realTime"&&n?.(l)},[l,i,n]);const d=c,p=s,g=(M,w,F)=>{if(!w)return{};const x=M?.[w];return(F&&x?x[F]:void 0)??{}},S=u.useMemo(()=>({display:"inline-block",position:"relative",width:44,height:24,...g(d,"switch","label"),...g(p,void 0,"label")}),[d,p]),N=u.useMemo(()=>({position:"absolute",opacity:0,top:0,left:0,width:"100%",height:"100%",margin:0,cursor:"pointer",pointerEvents:"none",...g(d,"switch","hiddenInput"),...g(p,void 0,"hiddenInput")}),[d,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",...g(d,"switch","slider"),...g(p,void 0,"slider")}),[d,p]),v=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)",...g(d,"switch","knob"),...g(p,void 0,"knob")}),[d,p]),I=!!r,R=()=>{t?.(!I)};return f.jsx(P,{field:e,error:null,rightAlign:!1,children:f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[f.jsx("label",{className:V.label,htmlFor:e.name,style:{textAlign:"left",justifyContent:"flex-start"},children:o(e.displayName)}),f.jsxs("label",{style:S,children:[f.jsx("input",{id:e.name,type:"checkbox",checked:I,readOnly:!0,"aria-label":o(e.displayName),"aria-invalid":!1,"aria-describedby":void 0,style:N,tabIndex:-1}),f.jsx("span",{role:"switch","data-testid":"switch",tabIndex:0,"aria-checked":I,"aria-invalid":!1,"aria-describedby":void 0,onClick:R,onKeyDown:M=>{(M.key===" "||M.key==="Spacebar"||M.key==="Space"||M.key==="Enter")&&(M.preventDefault(),R())},className:`reactaform-switch ${I?"active checked on":""} `,style:I?{...b,backgroundColor:"var(--reactaform-switch-on-bg, #22c55e)",borderColor:"var(--reactaform-switch-on-border, #16a34a)"}:b,children:f.jsx("span",{style:{...v,transform:I?"translateX(20px)":void 0}})})]})]})})},_e=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o});return f.jsx(P,{field:e,error:s,children:f.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:c,onChange:i,className:B(V.input,V.textInput),placeholder:e.placeholder,"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},Et=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o}),m=a??s;return f.jsx(P,{field:e,error:m,children:f.jsx("input",{id:e.name,type:"time",ref:c,defaultValue:r,step:e.includeSeconds?1:60,onChange:i,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 Nt({pos:e,options:r,onClose:t,onClickOption:n}){const a=u.useRef(null),o=u.useRef(!1),[c,s]=u.useState({top:e?.y??0,left:e?.x??0,ready:!1}),i=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,d=window.innerHeight;let p=e.x,g=e.y;p+m.width>l&&(p=Math.max(0,l-m.width-10)),g+m.height>d&&(g=Math.max(0,e.y-m.height-5)),s({top:g,left:p,ready:!0})},[e,r]),!i||r===void 0||r.length===0||!e||e.x==null||e.y==null?null:fe.createPortal(f.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)=>f.jsx("div",{"data-popup-menu":"item",onMouseDown:d=>{d.stopPropagation(),o.current=!0},onClick:d=>{d.stopPropagation(),d.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:d=>{d.currentTarget.style.backgroundColor="var(--reactaform-hover-bg, #e0e0e0)"},onMouseLeave:d=>{d.currentTarget.style.backgroundColor="transparent"},children:m.label},m.label??l))}),i)}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={},Ft=new Set([...Object.keys(Fe),...Object.keys(Ie),...Object.keys(Me)]);for(const e of Ft){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 s=typeof c=="string"?c:String(o);r[o]={name:s,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 yr(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 br(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 It=Object.freeze(Object.defineProperty({__proto__:null,convertTemperature:yr,dimensionUnitDisplayMap:Ie,dimensionUnitsMap:Fe,dimensonUnitFactorsMap:Me,getUnitFactors:br,unitsByDimension:Ve},Symbol.toStringTag,{value:"Module"})),vr=u.memo(({disabled:e,inputValue:r,selectedUnit:t,dimension:n,unitFactors:a,onConversionSelect:o,t:c})=>{const[s,i]=u.useState(!1),[m,l]=u.useState(null),[d,p]=u.useState([]),g=u.useCallback(b=>{if(e)return;const v=parseFloat(r);if(!Number.isFinite(v))return;const I=b.currentTarget.getBoundingClientRect();l({x:I.left,y:I.bottom});const R=[];if(n==="temperature")a.units.forEach(w=>{const F=yr(t,w,v);Number.isFinite(F)&&R.push({label:`${F.toFixed(6)} ${c(w)}`,value:F.toString(),unit:w})});else{const w=a.factors[t];w!==void 0&&Object.entries(a.factors).forEach(([F,x])=>{const h=v/w*x;Number.isFinite(h)&&R.push({label:`${h.toFixed(6)} ${c(F)}`,value:h.toString(),unit:F})})}p(R),i(R.length>0)},[e,r,t,n,a,c]),S=u.useCallback(b=>{i(!1),l(null),o(b)},[o]),N=u.useCallback(()=>{i(!1),l(null)},[]);return f.jsxs(f.Fragment,{children:[f.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:f.jsx("span",{style:{fontSize:"1em",lineHeight:"1",pointerEvents:"none"},children:"⇄"})}),s&&d.length>0&&f.jsx(Nt,{pos:m,options:d,onClose:N,onClickOption:S})]})});vr.displayName="ConversionButton";const Mt=({field:e,value:r,onChange:t,onError:n})=>{const{t:a}=O(),o=z(e),c=e.dimension,s=u.useMemo(()=>c?br(c):null,[c]),i=String(r?.[0]??""),m=String(r?.[1]??s?.default??""),[l,d]=u.useState(i),[p,g]=u.useState(m);u.useEffect(()=>{d(i)},[i]),u.useEffect(()=>{g(m)},[m]);const S=o([l,p]);u.useEffect(()=>{n?.(S)},[S,n]);const N=u.useCallback(M=>{const w=M.target.value;d(w),o([w,p]),t?.([w,p])},[p,o,t]),b=u.useCallback(M=>{const w=M.target.value;g(w),o([l,w]),t?.([l,w])},[l,o,t]),v=u.useCallback(M=>{d(M.value),g(M.unit),t?.([M.value,M.unit])},[t]),I=u.useMemo(()=>s?s.units.map(M=>f.jsx("option",{value:M,children:a(M)},M)):[],[s,a]);if(!c||!s)return null;const R=!!S||!l.trim();return f.jsx(P,{field:e,error:S,children:f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--reactaform-unit-gap, 8px)",width:"100%"},children:[f.jsx("input",{id:e.name,type:"text",value:l,onChange:N,style:{flex:"2 1 0"},className:B(V.input,V.textInput),"aria-invalid":!!S,"aria-describedby":S?`${e.name}-error`:void 0}),f.jsx("select",{id:`${e.name}-unit`,value:p,onChange:b,style:{flex:"1 1 0"},className:B(V.input,V.inputSelect),"aria-invalid":!!S,"aria-describedby":S?`${e.name}-error`:void 0,children:I}),f.jsx(vr,{disabled:R,inputValue:l,selectedUnit:p,dimension:c,unitFactors:s,onConversionSelect:v,t:a})]})})},Vt=u.memo(Mt),Rt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o}),m=a??s;return f.jsx(P,{field:e,error:m,children:f.jsx("input",{id:e.name,type:"url",defaultValue:String(r??""),ref:c,onChange:i,className:B(V.input,V.textInput),placeholder:"https://example.com","aria-invalid":!!m,"aria-describedby":m?`${e.name}-error`:void 0})})},$t={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:Yr,color:rt,date:tt,dropdown:nt,email:ot,file:it,float:lt,"float-array":ct,image:mt,int:dt,"int-array":ft,"multi-selection":gt,multiline:pt,password:Ct,phone:bt,radio:vt,rating:St,separator:st,slider:kt,string:_e,stepper:yt,switch:jt,text:_e,time:Et,unit:Vt,url:Rt};function At(e){return e in Re}function Dt(e,r){const{wait:t=200,leading:n,trailing:a}=r,o=u.memo(c=>{const s=u.useRef(c.onChange);u.useEffect(()=>{s.current=c.onChange},[c.onChange]);const{callback:i,cancel:m}=nr((...l)=>{s.current?.(...l)},t,{leading:n,trailing:a});return u.useEffect(()=>m,[m]),u.createElement(e,{...c,onChange:i})});return o.displayName="DebouncedFieldWrapper",o}function xr(e,r,t){const n=r;if(!t&&e in Re){console.warn(`Can't overwrite base component type "${e}".`);return}const a=$t[e];if(a===!1){me.register(e,n);return}const o=a??{wait:200};tr?me.register(e,n):me.register(e,Dt(n,o))}function $e(e,r){xr(e,r,!1)}function Ae(e){return me.get(e)}let Ke=!1;function Pt(){Ke||(Object.entries(Re).forEach(([e,r])=>{xr(e,r,!0)}),Ke=!0)}const zt=(e,r)=>{const t=new Map;let n=null,a=null,o=0;for(const c of e){const s=c.group;if(!s){n=null,a=null;continue}if(s===n)r[c.name].group=a??s;else{if(!t.has(s))t.set(s,1),a=null,r[c.name].group=s;else{const i=t.get(s),m=`${s}(${i})`;t.set(s,i+1),a=m,r[c.name].group=m,o++}n=s}}return o},Ot=(e,r={})=>{const{includeEmpty:t=!0}=r,n=[];let a=null,o=[],c=0;for(const i of e){const m=i.group||null;m!==a?((o.length>0||t)&&(o.length===0&&c++,n.push({name:a,fields:o})),a=m,o=[i]):o.push(i)}(o.length>0||t)&&(o.length===0&&c++,n.push({name:a,fields:o}));const s=Math.max(0,...n.map(i=>i.fields.length));return{groups:n,metadata:{totalGroups:n.length,emptyGroups:c,largestGroup:s}}},wr=u.memo(({field:e,value:r,handleChange:t,handleError:n,error:a})=>{const o=Ae(e.type),c=u.useMemo(()=>r,[r]),s=u.useCallback(m=>t(e.name,m),[t,e.name]),i=u.useCallback(m=>n?.(e.name,m),[n,e.name]);return o?f.jsx(o,{field:e,value:c,onChange:s,onError:i,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);wr.displayName="FieldWrapper";const Sr=(e,r,t,n,a)=>{const o=a?a[e.name]??null:void 0;return f.jsx(u.Fragment,{children:f.jsx(wr,{field:e,value:r[e.name],handleChange:t,handleError:n,error:o})},e.name)},Cr=u.memo(({groupName:e,isOpen:r,fields:t,valuesMap:n,handleChange:a,handleError:o,errorsMap:c,toggleGroup:s,t:i})=>{const m=u.useCallback(()=>s(e),[s,e]),{formStyle:l,fieldStyle:d}=O(),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||{},...d?.fieldset||{}}),[l,d]),g=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||{},...d?.legend||{}}),[l,d]);return f.jsxs("fieldset",{style:p,children:[f.jsxs("legend",{onClick:m,style:g,children:[f.jsx("span",{children:i(e)}),f.jsx("span",{children:r?"▼":"▶"})]}),r&&t.map(S=>Sr(S,n,a,o,c))]})});Cr.displayName="FieldGroup";const Lt=(e,r,t,n,a,o,c,s,i,m)=>{const l=r.slice(0,s).filter(g=>c[g.name]),d=Ot(l),p=[];return d.groups.forEach(g=>{if(g.name){const S=e[g.name]??!0;p.push(f.jsx(Cr,{groupName:g.name,isOpen:S,fields:g.fields,valuesMap:t,handleChange:a,handleError:o,errorsMap:m,toggleGroup:i,t:n},g.name))}else g.fields.forEach(S=>p.push(Sr(S,t,a,o,m)))}),p},Tt=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):"",s=a.children[c];!s||!Array.isArray(s)||s.forEach(i=>{typeof i=="string"&&(n[i]=!0,De(i,r,t,n))})},kr=(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,kr(a,r,t))})},Ht=(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},Bt=(e,r,t,n,a)=>{const o={...e};if(kr(n,r,o),a!=null){const c=r[n];if(c&&c.children){const s=String(a),i=c.children[s];i&&Array.isArray(i)&&i.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 qt(e){return Pe.get(e)}function Ut(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 Wt(e,r,t,n,a){const o=Object.values(a).filter(Boolean);if(o.length>0)return{success:!1,message:n("Please fix validation errors before submitting."),errors:o};const c={...t},s=[];if(e&&Array.isArray(e.properties))for(const m of e.properties){const l=m.name,d=c[l];if(d==null)continue;const p=m.type;try{if(p==="int"||p==="number"||p==="float"){const g=String(d).trim();if(g==="")c[l]=0;else{const S=Number(g);isNaN(S)?s.push(n("Invalid number format for field {{1}}",m.displayName||l)):c[l]=S}}else if(p==="int-array"||p==="float-array"){const g=String(d).split(",").map(b=>b.trim()).filter(Boolean),S=[];let N=!1;for(const b of g){const v=Number(b);if(isNaN(v)){s.push(n("Invalid number {{1}} in array for field {{2}}",b,m.displayName||l)),N=!0;break}S.push(v)}N||(c[l]=S)}}catch(g){s.push(n("Error processing field {{1}}: {{2}}",m.displayName||l,g instanceof Error?g.message:String(g)))}}if(s.length>0)return{success:!1,message:n("Data transformation errors occurred."),errors:s};const i=await Jr(e,c,n);if(i&&i.length>0)return{success:!1,message:n("Validation failed"),errors:i};if(e&&typeof e.submitHandlerName=="string"){const m=qt(e.submitHandlerName);if(m)try{const l=await m(e,r?.name??null,c,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)]}}}return{success:!0,message:n("Form submitted successfully."),data:c}}const jr=({message:e,success:r,onDismiss:t,t:n})=>e?f.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:[f.jsx("div",{style:{whiteSpace:"pre-wrap",flex:1},children:e}),f.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;jr.displayName="SubmissionMessage";const _t=({onClick:e,disabled:r=!1,t})=>{const[n,a]=u.useState(!1);return f.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")})},Er=({definition:e,instance:r,chunkSize:t=50,chunkDelay:n=50})=>{const{properties:a,displayName:o}=e,c=O(),{t:s,formStyle:i,language:m}=c,l={...c,definitionName:e?.name??c.definitionName},[d,p]=u.useState("en"),[g,S]=u.useState([]),[N,b]=u.useState({}),[v,I]=u.useState({}),[R,M]=u.useState({}),[w,F]=u.useState({}),[x,h]=u.useState({}),[y,C]=u.useState(null),[k,j]=u.useState(null),[E,A]=u.useState(0),[T,Y]=u.useState(!1),[ne,ae]=u.useState(r.name||""),G=u.useRef(r),de=u.useRef(!1);u.useEffect(()=>{const D=Object.fromEntries(a.map($=>[$.name,{...$,children:{}}]));a.forEach($=>{$.parents&&Object.entries($.parents).forEach(([ee,re])=>{const oe=D[ee];oe&&re.forEach(Tr=>{oe.children||(oe.children={});const Te=String(Tr);oe.children[Te]=[...oe.children[Te]||[],$.name]})})}),zt(a,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}),G.current=r,Object.keys(r.values).forEach($=>{D[$]!==void 0&&(q[$]=r.values[$])});const J=Tt(H),_={};H.forEach($=>{$.group&&!($.group in _)&&(_[$.group]=!0)});const X=requestAnimationFrame(()=>{S(H),b(D),I(q),M(Ht(H,q,J,D)),F(_),Y(!0),ae(r.name)});return()=>cancelAnimationFrame(X)},[a,r,e]),u.useEffect(()=>{if(!T||E>=g.length)return;const D=setTimeout(()=>{A(H=>Math.min(H+t,g.length))},n);return()=>clearTimeout(D)},[T,E,g.length,t,n]);const Dr=u.useCallback((D,H)=>{C(null),j(null),I(q=>{const J={...q,[D]:H},_=N[D];return _&&["checkbox","dropdown","multi-select","radio","switch"].includes(_.type)&&M($=>Bt($,N,J,D,String(H))),J})},[N,C,j]);u.useEffect(()=>{let D=0;return D=requestAnimationFrame(()=>{m!==d&&(p(m||"en"),C(null),j(null))}),()=>cancelAnimationFrame(D)},[m,d]),u.useEffect(()=>{let D=0;return D=requestAnimationFrame(()=>{if(de.current){de.current=!1,G.current=r,ae(r.name||"");return}G.current=r,C(null),j(null),ae(r.name||"")}),()=>cancelAnimationFrame(D)},[r,r.name]);const Pr=u.useCallback((D,H)=>{h(q=>H?{...q,[D]:String(H)}:Object.fromEntries(Object.entries(q).filter(([_])=>_!==D)))},[]),zr=async()=>{de.current=!0;const D=G.current?.name;G.current.name=ne;let H=x;if(l.fieldValidationMode==="onSubmission"){const X={};if(g.forEach($=>{const ee=v[$.name];if(ee===void 0)return;const re=gr(l.definitionName,$,ee,s);re&&(X[$.name]=re)}),h(X),H=X,Object.keys(X).length>0){C(s("Please fix validation errors before submitting the form.")),j(!1);return}else C(null),j(null)}const q=await Wt(e,G.current,v,s,H),J=typeof q.message=="string"?q.message:String(q.message),_=Object.values(q.errors??{}).join(`
300
+ `,ke=K.createContext(void 0),O=()=>{const e=K.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 tr=typeof process<"u"&&process.env.NODE_ENV==="test";function nr(e,r=300,t){const n=K.useRef(),a=K.useRef(e),o=K.useRef(null),c=t?.leading===!0,s=t?.trailing!==!1;K.useEffect(()=>{a.current=e},[e]),K.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]);const i=p=>{a.current(...p)},m=K.useCallback(()=>{n.current&&(clearTimeout(n.current),n.current=void 0),o.current=null},[]),l=K.useCallback(()=>{n.current&&s&&o.current&&(clearTimeout(n.current),n.current=void 0,i(o.current),o.current=null)},[s]);return{callback:K.useCallback((...p)=>{if(tr){i(p);return}const g=c&&!n.current;o.current=p,g&&i(p),n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{n.current=void 0,s&&o.current&&(i(o.current),o.current=null)},r)},[c,s,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 ce(e){return e.toLowerCase().includes("dark")}function qr(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 Ur=()=>f.jsxs("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[f.jsx("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),f.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),Wr=({content:e,size:r="medium",animation:t=!0})=>{const{t:n,theme:a,formStyle:o,fieldStyle:c}=O(),[s,i]=u.useState(!1),[m,l]=u.useState({x:0,y:0}),[d,p]=u.useState(!1),g=u.useRef(null),S=u.useRef(null),N=u.useRef(null),b=u.useId(),v=ce(a),[I,R]=u.useState(void 0);u.useLayoutEffect(()=>{if(!g.current)return;const x="rgba(255,255,255,0.1)",y=getComputedStyle(g.current).getPropertyValue("--reactaform-primary-bg").trim();if(y&&typeof CSS<"u"&&CSS.supports?.("color: color-mix(in srgb, red, blue)")){const C=qr(y)?"black":"white";R(`color-mix(in srgb, var(--reactaform-primary-bg) 85%, ${C} 15%)`)}else R(x)},[]);const M=u.useMemo(()=>{const h={icon:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"1.2em",height:"1.2em",fontSize:"0.9em",fontWeight:"bold",borderRadius:"50%",backgroundColor:I??(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"}},y=(k,j,E)=>{const T=k?.[j];return(E&&T?T[E]:void 0)??{}};return{icon:{...h.icon,...y(o,"tooltip","icon"),...y(c,"tooltip","icon")},text:{...h.text,...y(o,"tooltip","text"),...y(c,"tooltip","text")},textVisible:h.textVisible}},[v,r,t,o,c,I]);u.useLayoutEffect(()=>{if(!s||!g.current||!S.current){p(!1);return}const x=g.current.getBoundingClientRect();N.current=x;const h=S.current.getBoundingClientRect(),y=8,C=window.innerWidth,k=window.innerHeight,j=-4;let E=x.right+y,A=x.top+x.height/2-h.height/2+j;E+h.width>C-y&&(E=x.left-y-h.width),E=Math.max(y,Math.min(E,C-h.width-y)),A=Math.max(y,Math.min(A,k-h.height-y)),l({x:E,y:A}),p(!0);const T=g.current.closest("[data-reactaform-theme]"),Y=document.getElementById("popup-root");if(T&&Y){const ne=getComputedStyle(T);Y.style.setProperty("--reactaform-tooltip-color-bg",ne.getPropertyValue("--reactaform-tooltip-color-bg")),Y.style.setProperty("--reactaform-tooltip-color",ne.getPropertyValue("--reactaform-tooltip-color"))}},[s]);const w=typeof document<"u"?document.getElementById("popup-root"):null,F=f.jsx("div",{ref:S,"data-tooltip-id":b,style:{...M.text,transform:d?"translateY(0) scale(1)":"translateY(-4px) scale(0.98)",transition:"opacity 120ms ease, transform 120ms ease, visibility 120ms ease",width:240,...d?M.textVisible:{},top:m.y,left:m.x},children:n(e)});return f.jsxs(f.Fragment,{children:[f.jsx("span",{"data-testid":"tooltip-icon",ref:g,"aria-describedby":s?b:void 0,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),style:{...M.icon},children:f.jsx(Ur,{})}),s&&(w?fe.createPortal(F,w):F)]})},ar=u.memo(Wr),ye=u.memo(({field:e,error:r,children:t,showLabel:n=!0})=>{const{t:a}=O(),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]),s=u.useMemo(()=>({textAlign:o,width:"100%",minWidth:"unset",display:"block",marginBottom:"10px"}),[o]),i=u.useMemo(()=>({display:"flex",alignItems:"center",gap:"var(--reactaform-inline-gap, 8px)",width:"100%"}),[]);return f.jsxs("div",{className:`${V.field} column-layout`,style:c,children:[n&&f.jsx("label",{id:`${e.name}-label`,className:V.label,htmlFor:e.name,style:s,children:a(e.displayName)}),f.jsxs("div",{style:i,children:[f.jsx("div",{style:{flex:1,minWidth:0},children:t}),e.tooltip&&f.jsx(ar,{content:e.tooltip})]}),r&&f.jsx(je,{id:`${e.name}-error`,children:r})]})});ye.displayName="ColumnFieldLayout";const or=u.memo(({field:e,error:r,children:t,rightAlign:n=!1})=>{const{t:a}=O(),o=u.useMemo(()=>({display:"flex",alignItems:"center",gap:"3px"}),[]);return f.jsxs("div",{className:`${V.field} row-layout`,children:[f.jsx("label",{id:`${e.name}-label`,className:V.label,htmlFor:e.name,style:{textAlign:"left"},children:a(e.displayName)}),f.jsxs("div",{children:[f.jsxs("div",{style:o,children:[n?f.jsx("div",{style:{display:"flex",flex:1,justifyContent:"flex-end"},children:t}):t,e.tooltip&&f.jsx(ar,{content:e.tooltip})]}),r&&f.jsx(je,{id:`${e.name}-error`,children:r})]})]})});or.displayName="RowFieldLayout";const P=u.memo(({field:e,error:r,children:t,rightAlign:n=!1})=>e.labelLayout==="column-left"||e.labelLayout==="column-center"?f.jsx(ye,{field:e,error:r,showLabel:!0,children:t}):e.type==="checkbox"||e.type==="switch"?f.jsx(ye,{field:e,error:r,showLabel:!1,children:t}):f.jsx(or,{field:e,error:r,rightAlign:n,children:t}));P.displayName="StandardFieldLayout";const je=u.memo(({children:e,id:r})=>{const t=u.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 f.jsx("div",{id:r,style:t,children:e})});je.displayName="ErrorDiv";const sr=u.memo(({name:e,onChange:r})=>{const{t}=O();return f.jsxs("div",{style:{marginBottom:16},children:[f.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 2fr",gap:12,alignItems:"center"},children:[f.jsx("label",{htmlFor:"instance-name-input",style:{margin:0,fontSize:"0.95em",fontWeight:500,color:"var(--reactaform-text-color, #333)"},children:t("Instance Name")}),f.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")})]}),f.jsx("div",{style:{height:"1px",backgroundColor:"var(--reactaform-separator, #e6e6e6)",marginTop:12,marginBottom:12}})]})});sr.displayName="InstanceName";class _r 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 ir=new ie,cr=new _r,Ee=new ie;function lr(e,r){ir.register(e,r)}function ur(e,r,t){cr.registerInCategory(e,r,t)}function mr(e,r){if(At(e)){console.warn(`[ReactaForm] Can't override builtin type field validation handler for type "${e}".`);return}Ee.register(e,r)}function L(e,r){Ee.register(e,r)}function fr(e,r){return cr.getFromCategory(e,r)||null}function dr(e){return ir.get(e)||null}function pr(e){return Ee.get(e)||null}function Kr(e){return(typeof e=="object"||typeof e=="function")&&e!==null&&typeof e.then=="function"}const He=new Map,Be=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[i,m]=r.validationHandlerName;if(m)a=i,o=m;else if(i)a=e,o=i;else return null}else return null;const c=`${a}:${o}`;let s=He.get(c);if(s===void 0&&(s=fr(a,o)||null,He.set(c,s)),s)try{return s(r.name,t,n)||null}catch(i){return String(i instanceof Error?i.message:i)}return null}function Gr(e,r,t,n){return Ne(e,r,t,n)}function gr(e,r,t,n){const a=pr(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 Jr(e,r,t){if(!e||typeof e.validationHandlerName!="string")return null;const n=e.validationHandlerName;let a=Be.get(n);if(a===void 0&&(a=dr(n)||null,Be.set(n,a)),a)try{const o=a(r,t);return Kr(o)?await o||null:o||null}catch(o){return[String(o instanceof Error?o.message:o)]}return null}function z(e,r){const{definitionName:t,t:n,fieldValidationMode:a}=O();return u.useCallback(o=>a==="realTime"?gr(t,e,o,n):r??null,[t,e,n,a,r])}const Yr=({field:e,value:r=!1,onChange:t,onError:n,error:a})=>{const{t:o}=O(),s=z(e,a)(r);u.useEffect(()=>{a||n?.(s)},[s,a,n]);const i=u.useCallback(d=>{t?.(d.target.checked)},[t]),m=u.useCallback(d=>{(d.key===" "||d.key==="Space"||d.key==="Spacebar"||d.code==="Space"||d.key==="Enter")&&(d.preventDefault(),t?.(!r))},[t,r]),l=e.name;return f.jsx(P,{field:e,rightAlign:!1,error:s,children:f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[f.jsx("label",{className:V.label,htmlFor:l,style:{textAlign:"left",justifyContent:"flex-start"},children:o(e.displayName)}),f.jsx("input",{id:l,"data-testid":"boolean-checkbox",type:"checkbox",checked:r,onChange:i,onKeyDown:m,"aria-checked":r,"aria-invalid":!!s,"aria-describedby":s?`${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=u.useRef(null),o=u.useRef(null),c=u.useRef(t),[s,i]=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),i(p)),a.current&&a.current.value!==l&&(a.current.value=l)}},[e,n]);const m=u.useCallback(l=>{const d=l.target.value,p=n(d);p!==o.current&&(o.current=p,i(p),c.current?.(p??null)),r?.(d)},[r,n]);return{inputRef:a,error:s,handleChange:m}}const qe=[{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"}],Xr=/^#([0-9A-F]{3}){1,2}$/i,Zr="#000000",Qr=e=>Xr.test(e),pe=e=>{if(!e||!Qr(e))return Zr;const r=e.toLowerCase();return r.length===4?"#"+r.slice(1).split("").map(t=>t+t).join(""):r},et=e=>{const r=parseInt(e.slice(1),16);return{r:r>>16&255,g:r>>8&255,b:r&255}},rt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=O(),c=z(e,a),s=u.useMemo(()=>pe(r),[r]),{inputRef:i,error:m,handleChange:l}=W({value:s,onChange:t,onError:n,validate:c}),[d,p]=u.useState(s);u.useEffect(()=>{a||n?.(m)},[m,a,n]),u.useEffect(()=>{p(s)},[s]);const g=u.useCallback(M=>{const w=pe(M.target.value);p(w),l({target:{value:w}})},[l]),S=u.useCallback(M=>{const w=pe(M.target.value);p(w),l({target:{value:w}})},[l]),b=u.useMemo(()=>new Set(qe.map(M=>M.value)),[]).has(d),{r:v,g:I,b:R}=u.useMemo(()=>et(d),[d]);return f.jsx(P,{field:e,error:m,children:f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,width:"100%"},children:[f.jsxs("select",{id:e.name,value:d,onChange:S,className:B(V.input,V.inputSelect),"aria-invalid":!!m,children:[qe.map(M=>f.jsx("option",{value:M.value,children:o(M.label)},M.value)),!b&&f.jsxs("option",{value:d,children:["(",v,", ",I,", ",R,")"]})]}),f.jsx("label",{style:{width:"2.5em",height:"1.8em",border:"1px solid #ccc",borderRadius:4,backgroundColor:d,cursor:"pointer",overflow:"hidden",flexShrink:0},children:f.jsx("input",{ref:i,id:`${e.name}-color`,type:"color",defaultValue:d,onChange:g,style:{opacity:0,width:"100%",height:"100%"},"aria-invalid":!!m})})]})})},Ue=e=>{if(!e)return null;const r=new Date(e);return isNaN(r.getTime())?null:r},We=e=>{if(!e)return"";if(/^\d{4}-\d{2}-\d{2}$/.test(e))return Ue(e)?e:"";const t=Ue(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""},tt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),c=We(r),{inputRef:s,error:i,handleChange:m}=W({value:c,onChange:t,onError:n,validate:o});return u.useEffect(()=>{a||n?.(i)},[i,a,n]),f.jsx(P,{field:e,error:i,children:f.jsx("input",{id:e.name,type:"date",ref:s,defaultValue:We(r),onChange:m,className:B(V.input,V.textInput),...e.minDate?{min:e.minDate}:{},...e.maxDate?{max:e.maxDate}:{},"aria-invalid":!!i,"aria-describedby":i?`${e.name}-error`:void 0})})},nt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o,theme:c,formStyle:s,fieldStyle:i}=O(),m=u.useRef(null),l=u.useRef(n),[d,p]=u.useState(!1),[g,S]=u.useState(null);u.useEffect(()=>{l.current=n},[n]);const N=z(e,a),[b,v]=u.useState(null),I=u.useRef(null);u.useEffect(()=>{const y=String(r??"");let C=N(y);if(C&&e.options.length>0){const k=String(e.options[0].value);t?.(k),C=null}C!==I.current&&(I.current=C,v(C),l.current?.(C??null))},[r,N,t,e.options]);const R=()=>{if(!m.current)return;const y=m.current.getBoundingClientRect();S({x:y.left,y:y.bottom}),p(C=>!C)},M=y=>{const C=N(y);C!==I.current&&(I.current=C,v(C),l.current?.(C??null)),t?.(y),p(!1)},w=u.useMemo(()=>{const y=e.options.find(C=>String(C.value)===String(r));return y?o(y.label):""},[e.options,r,o]),F=(y,C,k)=>{if(!C)return{};const E=y?.[C];return(k&&E?E[k]:void 0)??{}},x=u.useMemo(()=>({height:"var(--reactaform-input-height, 2.5rem)",display:"flex",alignItems:"center",cursor:"pointer",position:"relative",...F(s,"dropdown","control"),...F(i,void 0,"control")}),[s,i]),h=u.useMemo(()=>({position:"absolute",right:"0.7em",top:"50%",transform:"translateY(-50%)",pointerEvents:"none",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",...F(s,"dropdown","arrow"),...F(i,void 0,"arrow")}),[s,i]);return f.jsxs("div",{children:[f.jsx(P,{field:e,error:b,children:f.jsxs("div",{ref:m,className:"reactaform-input",style:x,onClick:R,tabIndex:0,role:"combobox","aria-haspopup":"listbox","aria-expanded":d,"aria-invalid":!!b,"aria-describedby":b?`${e.name}-error`:void 0,onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),R())},children:[f.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:w}),f.jsx("span",{style:h,"aria-hidden":!0,children:"▼"})]})}),d&&g&&f.jsx(at,{position:g,options:e.options,selectedValue:String(r),onSelect:M,onClose:()=>p(!1),controlRef:m,theme:c,t:o})]})},at=({position:e,options:r,selectedValue:t,onSelect:n,onClose:a,controlRef:o,theme:c,t:s})=>{const i=u.useRef(null),[m,l]=u.useState(-1),{formStyle:d,fieldStyle:p}=O(),g=ce(c??"light");u.useLayoutEffect(()=>{if(!o.current)return;const h=o.current.closest("[data-reactaform-theme]"),y=document.getElementById("popup-root");if(h&&y){const C=getComputedStyle(h);y.style.setProperty("--reactaform-secondary-bg",C.getPropertyValue("--reactaform-secondary-bg")),y.style.setProperty("--reactaform-text-color",C.getPropertyValue("--reactaform-text-color")),y.style.setProperty("--reactaform-hover-bg",C.getPropertyValue("--reactaform-hover-bg"))}},[o]);const S=(h,y,C)=>{if(!y)return{};const j=h?.[y];return(C&&j?j[C]:void 0)??{}},N=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)",...S(d,"dropdown","popup"),...S(p,void 0,"popup")}),[d,p]),b=u.useMemo(()=>({padding:"6px 8px",cursor:"pointer",display:"flex",alignItems:"center",background:"transparent",color:"var(--reactaform-text-color, #000)",...S(d,"dropdown","option"),...S(p,void 0,"option")}),[d,p]);u.useEffect(()=>{const h=y=>{const C=y.target;!i.current?.contains(C)&&!o.current?.contains(C)&&a()};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[a,o]),u.useEffect(()=>{if(i.current&&r.length>0){const h=r.findIndex(y=>String(y.value)===t);requestAnimationFrame(()=>l(h>=0?h:0))}},[r,t]),u.useEffect(()=>{if(!i.current||m<0)return;const h=i.current.querySelector(`#opt-${m}`);h&&requestAnimationFrame(()=>h.focus())},[m]);const v=250,I=200,[R,M]=u.useState(null),[w,F]=u.useState(null);if(u.useEffect(()=>{if(typeof window>"u")return;const h=()=>{let k=e.x,j=e.y,E=v;const A=o?.current;if(A){const T=A.getBoundingClientRect();k=T.left,j=T.bottom,E=Math.max(80,Math.round(T.width))}k=Math.min(k,window.innerWidth-E),j=Math.min(j,window.innerHeight-I),M({left:k,top:j}),F(E)};h(),window.addEventListener("scroll",h,!0),window.addEventListener("resize",h);let y=null;const C=o?.current;return typeof ResizeObserver<"u"&&C&&(y=new ResizeObserver(()=>h()),y.observe(C)),()=>{window.removeEventListener("scroll",h,!0),window.removeEventListener("resize",h),y&&C&&y.unobserve(C)}},[o,e.x,e.y]),typeof window>"u")return null;let x=document.getElementById("popup-root");return x||(x=document.createElement("div"),x.id="popup-root",document.body.appendChild(x)),fe.createPortal(f.jsx("div",{ref:i,role:"listbox","aria-activedescendant":m>=0?`opt-${m}`:void 0,style:{position:"fixed",top:R?R.top:e.y,left:R?R.left:e.x,width:w??v,...N},"data-reactaform-theme":c??"light",children:r.map((h,y)=>{const C=String(h.value)===t,k=g?"var(--reactaform-hover-bg, rgba(255,255,255,0.01))":"var(--reactaform-hover-bg, #eee)",j={...b,background:y===m?k:b.background,fontWeight:C?"bold":"normal"};return f.jsx("div",{id:`opt-${y}`,onMouseDown:E=>{E.stopPropagation(),n(String(h.value))},onKeyDown:E=>{const A=r.length;switch(E.key){case"ArrowDown":E.preventDefault(),l(T=>(T+1)%A);break;case"ArrowUp":E.preventDefault(),l(T=>(T-1+A)%A);break;case"Home":E.preventDefault(),l(0);break;case"End":E.preventDefault(),l(A-1);break;case"Enter":case" ":E.preventDefault(),E.stopPropagation(),n(String(h.value));break;case"Escape":E.preventDefault(),a(),o?.current?.focus();break}},tabIndex:y===m?0:-1,role:"option","aria-selected":C,style:j,onMouseEnter:E=>{E.currentTarget.style.background=k,l(y)},onMouseLeave:E=>{E.currentTarget.style.background="transparent",l(A=>A===y?-1:A)},children:s(h.label)},String(h.value))})}),x)},ot=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o});return f.jsx(P,{field:e,error:s,children:f.jsx("input",{id:e.name,type:"email",defaultValue:String(r??""),ref:c,onChange:i,className:B(V.input,V.textInput),"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},st=({field:e})=>{const{theme:r}=O(),{color:t=ce(r)?"#444444":"#CCCCCC",thickness:n=1,margin:a="8px 0"}=e;return f.jsx("div",{style:{width:"auto",height:"0",borderTop:`${n}px solid ${t}`,margin:a}})},it=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=O(),[c,s]=u.useState(!1),i=u.useRef(null),m=u.useRef(n),l=u.useRef(null),[d,p]=u.useState(null);u.useEffect(()=>{m.current=n},[n]);const g=(w,F)=>F.some(x=>x.name===w.name&&x.size===w.size&&x.lastModified===w.lastModified),S=z(e,a);u.useEffect(()=>{const w=S(r??[]);t?.(r),w!==l.current&&(l.current=w,p(w),m.current?.(w??null))},[r,S]);const N=w=>{const F=w.target.files;let x=null;if(F&&F.length>0){const y=Array.from(F);if(e.multiple){const C=Array.isArray(r)?r:[],k=y.filter(j=>!g(j,C));x=[...C,...k]}else x=y[0]}const h=S(x??[]);h!==l.current&&(l.current=h,p(h),m.current?.(h??null)),t?.(x),w.target&&(w.target.value="")},b=w=>{w.preventDefault(),w.stopPropagation(),s(!1);const F=w.dataTransfer.files;if(F&&F.length>0){const x=Array.from(F);let h=null;if(e.multiple){const C=Array.isArray(r)?r:[],k=x.filter(j=>!g(j,C));h=[...C,...k]}else h=x[0];const y=S(h);y!==l.current&&(l.current=y,p(y),m.current?.(y??null)),t?.(h)}},v=w=>{w.preventDefault(),w.stopPropagation(),s(!0)},I=w=>{w.preventDefault(),w.stopPropagation(),s(!1)},R=w=>{if(Array.isArray(r)&&typeof w=="number"){const F=r.filter((y,C)=>C!==w),x=F.length>0?F:null,h=S(x??[]);h!==l.current&&(l.current=h,p(h),m.current?.(h??null)),t?.(x)}else{const F=S([]);F!==l.current&&(l.current=F,p(F),m.current?.(F??null)),t?.(null)}},M=()=>{const w=Array.isArray(r)?r:r?[r]:[];return w.length===0?null:f.jsx("div",{style:{marginTop:"8px",marginLeft:"20px",display:"flex",flexDirection:"column",gap:"6px",maxHeight:"200px",overflowY:"auto"},children:w.map((F,x)=>f.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[f.jsx("input",{type:"text",value:F.name,disabled:!0,readOnly:!0,title:F.name,className:"reactaform-input",style:{flex:1,cursor:"default",opacity:.8,minWidth:0}}),f.jsx("button",{type:"button",onClick:()=>R(Array.isArray(r)?x: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:h=>{h.currentTarget.style.backgroundColor="var(--reactaform-bg-hover, #fee)"},onMouseLeave:h=>{h.currentTarget.style.backgroundColor="transparent"},children:"×"})]},`${F.name}-${x}`))})};return f.jsx(P,{field:e,error:d,children:f.jsxs("div",{style:{width:"100%"},children:[f.jsxs("div",{className:"reactaform-input",onDrop:b,onDragOver:v,onDragLeave:I,style:{position:"relative",borderStyle:"dashed",borderColor:c?"var(--reactaform-color-primary, #2563eb)":d?"var(--reactaform-color-error, #ef4444)":void 0,borderWidth:"1px",borderRadius:"var(--reactaform-border-radius, 4px)",padding:"8px 12px",textAlign:"center",backgroundColor:c?"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:()=>i.current?.click(),onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),i.current?.click())},role:"button","aria-label":e.multiple?o("Choose Files or Drag & Drop"):o("Choose File or Drag & Drop"),"aria-invalid":!!d,"aria-describedby":d?`${e.name}-error`:void 0,children:[f.jsx("input",{id:e.name,ref:i,type:"file",accept:e.accept,multiple:e.multiple,style:{display:"none"},onChange:N}),f.jsx("div",{style:{fontSize:"1.25rem",opacity:.6,lineHeight:1,flexShrink:0},children:"📁"}),f.jsx("div",{style:{fontSize:"0.875rem",fontWeight:400,color:"var(--reactaform-text-color, #111827)",flex:1,textAlign:"left"},children:c?o("Drop files here"):e.multiple?o("Choose Files or Drag & Drop"):o("Choose File or Drag & Drop")}),e.accept&&f.jsx("div",{style:{fontSize:"0.75rem",color:"var(--reactaform-text-muted, #6b7280)",whiteSpace:"nowrap",opacity:c?0:1,transition:"opacity 0.15s ease",pointerEvents:c?"none":"auto"},children:e.accept})]}),M()]})})},ct=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),c=Array.isArray(r)?r.join(", "):String(r??""),{inputRef:s,error:i,handleChange:m}=W({value:c,onChange:t,onError:n,validate:o});return f.jsx(P,{field:e,error:i,children:f.jsx("input",{id:e.name,type:"text",defaultValue:c,ref:s,onChange:m,className:B(V.input,V.textInput),style:{flex:1},"aria-invalid":!!i,"aria-describedby":i?`${e.name}-error`:void 0})})},lt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o}),m=a??s;return f.jsx(P,{field:e,error:m,children:f.jsx("input",{id:e.name,type:"text",ref:c,defaultValue:String(r??""),onChange:i,className:B(V.input,V.inputNumber),"aria-invalid":!!m,"aria-describedby":m?`${e.name}-error`:void 0})})};function ut(){try{return"/"}catch{}try{if(typeof process<"u"&&process?.env?.PUBLIC_URL)return process.env.PUBLIC_URL}catch{}return"/"}const mt=({field:e,value:r})=>{const{language:t,t:n}=O(),a=e.alignment||"center",o={left:"flex-start",center:"center",right:"flex-end"},c=typeof r=="string"?r:"";let s=c&&c.trim()!==""?c:typeof e.defaultValue=="string"?e.defaultValue:"";s&&!s.startsWith("/")&&(s=`${ut()}${s}`);const i=e.localized?.split(";").map(b=>b.trim()),[m,l]=u.useState(s||""),d=u.useRef(s||null);if(u.useEffect(()=>{if(!s)return;const b=s.split("/"),v=b.pop(),I=v.lastIndexOf(".");if(I===-1)return;const R=v.substring(0,I),M=v.substring(I);let w=null;i?.includes(t)&&(w=`${R}_${t}${M}`);const F=new AbortController;if(w){const x=[...b,w].join("/");fetch(x,{method:"HEAD",signal:F.signal}).then(h=>{const y=h.ok?x:s;y!==d.current&&(d.current=y,l(y))}).catch(()=>{s!==d.current&&(d.current=s,l(s))})}else{const x=s;x!==d.current&&(d.current=x,requestAnimationFrame(()=>l(x)))}return()=>{F.abort()}},[s,t,i]),!m)return null;const{width:p,height:g}=e,S={},N={borderRadius:"8px",objectFit:"contain",boxShadow:"0 2px 6px rgba(0,0,0,0.1)",margin:"0 0 8px 0"};return p&&g?(S.width=p,S.height=g,N.width=`${p}px`,N.height=`${g}px`):p&&!g?(S.width=p,N.width=`${p}px`,N.height="auto"):!p&&g&&(S.height=g,N.width="auto",N.height=`${g}px`),f.jsx(P,{field:e,children:f.jsx("div",{"data-testid":"image-wrapper",style:{display:"flex",justifyContent:o[a]||"center",margin:"0 0"},children:f.jsx("img",{src:m,alt:n?.(e.displayName||"Image")||e.displayName||"Image",...S,style:N})})})},ft=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),c=Array.isArray(r)?r.join(", "):String(r??""),{inputRef:s,error:i,handleChange:m}=W({value:c,onChange:t,onError:n,validate:o});return f.jsx(P,{field:e,error:i,children:f.jsx("input",{id:e.name,type:"text",defaultValue:c,ref:s,onChange:m,className:B(V.input,V.textInput),style:{flex:1},"aria-invalid":!!i,"aria-describedby":i?`${e.name}-error`:void 0})})},hr=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o});return f.jsx(P,{field:e,error:s,children:f.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:c,onChange:i,className:B(V.input,V.inputNumber),"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})};hr.displayName="IntegerInput";const dt=u.memo(hr),pt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o});return f.jsx(P,{field:e,error:s,children:f.jsx("textarea",{id:e.name,defaultValue:String(r??""),ref:c,onChange:i,style:{resize:"vertical",minHeight:e.minHeight??"80px",width:"100%",boxSizing:"border-box"},className:B(V.input,V.textInput),"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},gt=({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:s,formStyle:i,fieldStyle:m}=O(),l=(k,j,E)=>{if(!j)return{};const T=k?.[j];return(E&&T?T[E]:void 0)??{}},d=u.useRef(null),[p,g]=u.useState(!1),[S,N]=u.useState(null),b=u.useMemo(()=>e.options.map(k=>({value:k.value,label:c(k.label)})),[e.options,c]),v=u.useMemo(()=>{const k=Array.isArray(r)?r:[],j=new Set(b.map(E=>E.value));return k.filter(E=>j.has(E))},[r,b]),I=z(e,a),[R,M]=u.useState(null),w=u.useRef(null);u.useEffect(()=>{const k=I(Array.isArray(r)?r:[]);k!==w.current&&(w.current=k,M(k),o.current?.(k??null))},[r,I]);const F=()=>{if(!d.current)return;const k=d.current.getBoundingClientRect();N({x:k.left,y:k.bottom}),g(j=>!j)},x=k=>{const j=v.includes(k)?v.filter(A=>A!==k):[...v,k],E=I(j);E!==w.current&&(w.current=E,M(E),o.current?.(E??null)),t?.(j)},h=u.useMemo(()=>({height:"var(--reactaform-input-height, 2.5rem)",display:"flex",alignItems:"center",cursor:"pointer",position:"relative",...l(i,"multiSelect","control"),...l(m,void 0,"control")}),[i,m]),y=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(i,"multiSelect","clearButton"),...l(m,void 0,"clearButton")}),[i,m]),C=u.useMemo(()=>({position:"absolute",right:"0.7em",top:"50%",transform:"translateY(-50%)",pointerEvents:"none",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",...l(i,"multiSelect","arrow"),...l(m,void 0,"arrow")}),[i,m]);return f.jsxs("div",{children:[f.jsx(P,{field:e,error:R,children:f.jsx("div",{style:{width:"100%"},children:f.jsxs("div",{ref:d,className:"reactaform-multiselection-control reactaform-input",style:h,onClick:F,role:"button","aria-haspopup":"listbox","aria-expanded":p,"aria-invalid":!!R,"aria-describedby":R?`${e.name}-error`:void 0,onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),F())},children:[f.jsxs("span",{style:{flex:1,color:"var(--reactaform-text-muted, #888)"},children:[v.length," / ",b.length," selected"]}),v.length>0&&f.jsx("button",{type:"button","aria-label":"Clear selections",onClick:k=>{k.stopPropagation(),t?.([])},style:y,children:f.jsx("span",{style:y,"aria-hidden":!0,children:"✖"})}),f.jsx("span",{style:C,"aria-hidden":!0,children:"▼"})]})})}),p&&S&&f.jsx(ht,{position:S,options:b,selectedValues:v,onToggleOption:x,onClose:()=>g(!1),controlRef:d,theme:s})]})},ht=({position:e,options:r,selectedValues:t,onToggleOption:n,onClose:a,controlRef:o,theme:c})=>{const s=u.useRef(null),[i,m]=u.useState(-1),{formStyle:l,fieldStyle:d}=O(),p=ce(c??"light");u.useLayoutEffect(()=>{if(!o.current)return;const x=o.current.closest("[data-reactaform-theme]"),h=document.getElementById("popup-root");if(x&&h){const y=getComputedStyle(x);h.style.setProperty("--reactaform-secondary-bg",y.getPropertyValue("--reactaform-secondary-bg")),h.style.setProperty("--reactaform-text-color",y.getPropertyValue("--reactaform-text-color")),h.style.setProperty("--reactaform-hover-bg",y.getPropertyValue("--reactaform-hover-bg"))}},[o]);const g=(x,h,y)=>{if(!h)return{};const k=x?.[h];return(y&&k?k[y]:void 0)??{}},S=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)",...g(l,"multiSelect","popup"),...g(d,void 0,"popup")}),[l,d]),N=u.useMemo(()=>({padding:"6px 8px",cursor:"pointer",display:"flex",alignItems:"center",background:"transparent",color:"var(--reactaform-text-color, #000)",...g(l,"multiSelect","option"),...g(d,void 0,"option")}),[l,d]);u.useEffect(()=>{const x=h=>{const y=h.target;!s.current?.contains(y)&&!o.current?.contains(y)&&a()};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[a,o]),u.useEffect(()=>{s.current&&r.length>0&&requestAnimationFrame(()=>m(x=>x===-1?0:x))},[r.length]),u.useEffect(()=>{if(!s.current||i<0)return;const x=s.current.querySelector(`#multi-opt-${i}`);x&&requestAnimationFrame(()=>x.focus())},[i]);const b=250,v=200,[I,R]=u.useState(null),[M,w]=u.useState(null);if(u.useEffect(()=>{if(typeof window>"u")return;const x=()=>{let C=e.x,k=e.y,j=b;const E=o?.current;if(E){const A=E.getBoundingClientRect();C=A.left,k=A.bottom,j=Math.max(80,Math.round(A.width))}C=Math.min(C,window.innerWidth-j),k=Math.min(k,window.innerHeight-v),R({left:C,top:k}),w(j)};x(),window.addEventListener("scroll",x,!0),window.addEventListener("resize",x);let h=null;const y=o?.current;return typeof ResizeObserver<"u"&&y&&(h=new ResizeObserver(()=>x()),h.observe(y)),()=>{window.removeEventListener("scroll",x,!0),window.removeEventListener("resize",x),h&&y&&h.unobserve(y)}},[o,e.x,e.y]),typeof window>"u")return null;let F=document.getElementById("popup-root");return F||(F=document.createElement("div"),F.id="popup-root",document.body.appendChild(F)),fe.createPortal(f.jsx("div",{ref:s,role:"listbox","aria-activedescendant":i>=0?`multi-opt-${i}`:void 0,style:{position:"fixed",top:I?I.top:e.y,left:I?I.left:e.x,width:M??b,...S},"data-reactaform-theme":c??"light",children:r.map((x,h)=>{const y=t.includes(x.value),C=p?"var(--reactaform-hover-bg, rgba(255,255,255,0.01))":"var(--reactaform-hover-bg, #eee)",k={...N,background:h===i?C:N.background};return f.jsxs("div",{id:`multi-opt-${h}`,onMouseDown:j=>{j.stopPropagation(),n(x.value)},onKeyDown:j=>{const E=r.length;switch(j.key){case"ArrowDown":j.preventDefault(),m(A=>(A+1)%E);break;case"ArrowUp":j.preventDefault(),m(A=>(A-1+E)%E);break;case"Home":j.preventDefault(),m(0);break;case"End":j.preventDefault(),m(E-1);break;case"Enter":case" ":j.preventDefault(),j.stopPropagation(),n(x.value);break;case"Escape":j.preventDefault(),a(),o?.current?.focus();break}},tabIndex:h===i?0:-1,role:"option","aria-selected":y,style:k,onMouseEnter:j=>{j.currentTarget.style.background=C,m(h)},onMouseLeave:j=>{j.currentTarget.style.background="transparent",m(E=>E===h?-1:E)},children:[f.jsx("input",{type:"checkbox",checked:y,readOnly:!0,style:{marginRight:8,width:"1.125em",height:"1.125em",verticalAlign:"middle",accentColor:p?"#10b981":"#22c55e",cursor:"pointer"}}),x.label]},x.value)})}),F)},yt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),{inputRef:c,error:s,handleChange:i}=W({value:String(r??""),onChange:t,onError:n,validate:o}),m=Math.max(1,Math.round(e.step??1));return f.jsx(P,{field:e,error:s,children:f.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:i,style:{width:"100%",height:"100%"},className:V.input,"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},bt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o});return f.jsx(P,{field:e,error:s,children:f.jsx("input",{id:e.name,type:"tel",defaultValue:String(r??""),ref:c,onChange:i,className:B(V.input,V.textInput),"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},vt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=O(),c=z(e,a),s=e.layout?.toLowerCase()==="horizontal"?"row":"column",i=u.useRef(n);u.useEffect(()=>{i.current=n},[n]);const[m,l]=u.useState(null),d=u.useRef(null),p=u.useCallback(b=>{b!==d.current&&(d.current=b,l(b),i.current?.(b))},[]);u.useEffect(()=>{const b=r!=null?String(r):"",v=c(b);if(v&&e.options.length>0){const I=String(e.options[0].value);t?.(I)}p(v)},[r,e.options,c,t,p]);const g=b=>{const v=b.target.value,I=c(v);p(I),t?.(v)},S={display:"flex",flexDirection:s,flexWrap:s==="row"?"wrap":"nowrap",gap:s==="row"?"12px":"4px",alignItems:s==="row"?"center":"stretch",width:"100%",padding:s==="row"?"8px":void 0,boxSizing:"border-box"},N={display:s==="column"?"flex":"inline-flex",gap:"8px",alignItems:"center",whiteSpace:"nowrap",marginBottom:s==="column"?6:0,cursor:"pointer",width:s==="column"?"100%":void 0,justifyContent:"flex-start"};return f.jsx(P,{field:e,error:m,children:f.jsx("div",{className:V.input,"aria-labelledby":`${e.name}-label`,"aria-invalid":!!m,style:S,children:e.options.map(b=>{const v=String(b.value),I=`${e.name}-${v}`;return f.jsxs("label",{className:B(V.label),style:N,onMouseDown:R=>R.preventDefault(),onClick:()=>{String(r??"")!==v&&g({target:{value:v}})},children:[f.jsx("input",{id:I,type:"radio",name:e.name,value:v,checked:String(r??"")===v,onChange:g,style:{width:"1.1em",height:"1.1em"}}),f.jsx("span",{style:{userSelect:"none",textAlign:s==="column"?"left":void 0,flex:s==="column"?1:void 0,fontWeight:400},children:o(b.label)})]},v)})})})},xt={display:"flex",gap:4},wt={cursor:"pointer",fontSize:"1.5rem",lineHeight:1,display:"inline-block",marginRight:"0.25rem",userSelect:"none",transition:"color 0.12s ease"},St=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=O(),c=z(e,a),s=e.max??5,i=e.icon?.trim()||"★",[m,l]=u.useState(null),d=u.useRef([]),p=u.useMemo(()=>Math.min(Math.max(r??0,0),s),[r,s]),g=u.useMemo(()=>c(p)??null,[c,p]);u.useEffect(()=>{n?.(g)},[g,n]);const S=u.useCallback(b=>{const v=Math.min(Math.max(b,0),s);c(v),t?.(v)},[s,c,t]),N=u.useCallback((b,v)=>{switch(b.key){case"Enter":case" ":b.preventDefault(),S(v+1);break;case"ArrowRight":case"ArrowUp":b.preventDefault(),d.current[Math.min(s-1,v+1)]?.focus();break;case"ArrowLeft":case"ArrowDown":b.preventDefault(),d.current[Math.max(0,v-1)]?.focus();break}},[s,S]);return f.jsx(P,{field:e,error:g,children:f.jsx("div",{role:"radiogroup","aria-labelledby":`${e.name}-label`,"aria-invalid":!!g,"aria-describedby":g?`${e.name}-error`:void 0,style:xt,children:Array.from({length:s},(b,v)=>{const I=v<p,M=m!==null&&v<=m||I?"gold":"lightgray";return f.jsx("span",{ref:w=>d.current[v]=w,role:"radio",tabIndex:p>0?v===p-1?0:-1:v===0?0:-1,"aria-checked":I,"aria-label":`Rating ${v+1}`,title:o(`${e.displayName} ${v+1}`),onClick:()=>S(v+1),onKeyDown:w=>N(w,v),onMouseEnter:()=>l(v),onMouseLeave:()=>l(null),style:{...wt,color:M},children:i},v)})})})},Ct=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o}=O(),c=z(e,a),{inputRef:s,error:i,handleChange:m}=W({value:r,onChange:t,onError:n,validate:c}),[l,d]=u.useState(!1),p=()=>d(g=>!g);return f.jsx(P,{field:e,error:i,children:f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,width:"100%"},children:[f.jsx("input",{id:e.name,type:l?"text":"password",defaultValue:String(r??""),ref:s,onChange:m,className:B(V.input,V.textInput),style:{flex:1,minWidth:0},"aria-invalid":!!i,"aria-describedby":i?`${e.name}-error`:void 0}),f.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?"🙈":"👁️"})]})})},kt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),c=e.min??0,s=e.max??100,[i,m]=u.useState(()=>isNaN(Number(r))?String(c):String(Number(r)));u.useEffect(()=>{const g=isNaN(Number(r))?String(c):String(Number(r));m(g)},[r,c]);const l=u.useMemo(()=>o(i)??null,[o,i]);u.useEffect(()=>{n?.(l)},[l,n]);const d=u.useCallback(g=>{const S=g.target.value;m(S),o(S),t?.(S)},[o,t]),p=isNaN(Number(i))?String(c):String(Number(i));return f.jsx(P,{field:e,error:l,children:f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%"},children:[f.jsx("input",{id:`${e.name}-range`,type:"range",value:p,onChange:d,min:c,max:s,step:"1.0",style:{padding:0,flex:1},className:V.rangeInput,"aria-invalid":!!l,"aria-describedby":l?`${e.name}-error`:void 0}),f.jsx("input",{id:e.name,type:"text",value:i,onChange:d,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})]})})},jt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const{t:o,formStyle:c,fieldStyle:s,fieldValidationMode:i}=O(),l=z(e,a)(r);u.useEffect(()=>{i==="realTime"&&n?.(l)},[l,i,n]);const d=c,p=s,g=(M,w,F)=>{if(!w)return{};const x=M?.[w];return(F&&x?x[F]:void 0)??{}},S=u.useMemo(()=>({display:"inline-block",position:"relative",width:44,height:24,...g(d,"switch","label"),...g(p,void 0,"label")}),[d,p]),N=u.useMemo(()=>({position:"absolute",opacity:0,top:0,left:0,width:"100%",height:"100%",margin:0,cursor:"pointer",pointerEvents:"none",...g(d,"switch","hiddenInput"),...g(p,void 0,"hiddenInput")}),[d,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",...g(d,"switch","slider"),...g(p,void 0,"slider")}),[d,p]),v=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)",...g(d,"switch","knob"),...g(p,void 0,"knob")}),[d,p]),I=!!r,R=()=>{t?.(!I)};return f.jsx(P,{field:e,error:null,rightAlign:!1,children:f.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[f.jsx("label",{className:V.label,htmlFor:e.name,style:{textAlign:"left",justifyContent:"flex-start"},children:o(e.displayName)}),f.jsxs("label",{style:S,children:[f.jsx("input",{id:e.name,type:"checkbox",checked:I,readOnly:!0,"aria-label":o(e.displayName),"aria-invalid":!1,"aria-describedby":void 0,style:N,tabIndex:-1}),f.jsx("span",{role:"switch","data-testid":"switch",tabIndex:0,"aria-checked":I,"aria-invalid":!1,"aria-describedby":void 0,onClick:R,onKeyDown:M=>{(M.key===" "||M.key==="Spacebar"||M.key==="Space"||M.key==="Enter")&&(M.preventDefault(),R())},className:`reactaform-switch ${I?"active checked on":""} `,style:I?{...b,backgroundColor:"var(--reactaform-switch-on-bg, #22c55e)",borderColor:"var(--reactaform-switch-on-border, #16a34a)"}:b,children:f.jsx("span",{style:{...v,transform:I?"translateX(20px)":void 0}})})]})]})})},_e=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e,a),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o});return f.jsx(P,{field:e,error:s,children:f.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:c,onChange:i,className:B(V.input,V.textInput),placeholder:e.placeholder,"aria-invalid":!!s,"aria-describedby":s?`${e.name}-error`:void 0})})},Et=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o}),m=a??s;return f.jsx(P,{field:e,error:m,children:f.jsx("input",{id:e.name,type:"time",ref:c,defaultValue:r,step:e.includeSeconds?1:60,onChange:i,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 Nt({pos:e,options:r,onClose:t,onClickOption:n}){const a=u.useRef(null),o=u.useRef(!1),[c,s]=u.useState({top:e?.y??0,left:e?.x??0,ready:!1}),i=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,d=window.innerHeight;let p=e.x,g=e.y;p+m.width>l&&(p=Math.max(0,l-m.width-10)),g+m.height>d&&(g=Math.max(0,e.y-m.height-5)),s({top:g,left:p,ready:!0})},[e,r]),!i||r===void 0||r.length===0||!e||e.x==null||e.y==null?null:fe.createPortal(f.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)=>f.jsx("div",{"data-popup-menu":"item",onMouseDown:d=>{d.stopPropagation(),o.current=!0},onClick:d=>{d.stopPropagation(),d.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:d=>{d.currentTarget.style.backgroundColor="var(--reactaform-hover-bg, #e0e0e0)"},onMouseLeave:d=>{d.currentTarget.style.backgroundColor="transparent"},children:m.label},m.label??l))}),i)}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={},Ft=new Set([...Object.keys(Fe),...Object.keys(Ie),...Object.keys(Me)]);for(const e of Ft){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 s=typeof c=="string"?c:String(o);r[o]={name:s,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 yr(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 br(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 It=Object.freeze(Object.defineProperty({__proto__:null,convertTemperature:yr,dimensionUnitDisplayMap:Ie,dimensionUnitsMap:Fe,dimensonUnitFactorsMap:Me,getUnitFactors:br,unitsByDimension:Ve},Symbol.toStringTag,{value:"Module"})),vr=u.memo(({disabled:e,inputValue:r,selectedUnit:t,dimension:n,unitFactors:a,onConversionSelect:o,t:c})=>{const[s,i]=u.useState(!1),[m,l]=u.useState(null),[d,p]=u.useState([]),g=u.useCallback(b=>{if(e)return;const v=parseFloat(r);if(!Number.isFinite(v))return;const I=b.currentTarget.getBoundingClientRect();l({x:I.left,y:I.bottom});const R=[];if(n==="temperature")a.units.forEach(w=>{const F=yr(t,w,v);Number.isFinite(F)&&R.push({label:`${F.toFixed(6)} ${c(w)}`,value:F.toString(),unit:w})});else{const w=a.factors[t];w!==void 0&&Object.entries(a.factors).forEach(([F,x])=>{const h=v/w*x;Number.isFinite(h)&&R.push({label:`${h.toFixed(6)} ${c(F)}`,value:h.toString(),unit:F})})}p(R),i(R.length>0)},[e,r,t,n,a,c]),S=u.useCallback(b=>{i(!1),l(null),o(b)},[o]),N=u.useCallback(()=>{i(!1),l(null)},[]);return f.jsxs(f.Fragment,{children:[f.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:f.jsx("span",{style:{fontSize:"1em",lineHeight:"1",pointerEvents:"none"},children:"⇄"})}),s&&d.length>0&&f.jsx(Nt,{pos:m,options:d,onClose:N,onClickOption:S})]})});vr.displayName="ConversionButton";const Mt=({field:e,value:r,onChange:t,onError:n})=>{const{t:a}=O(),o=z(e),c=e.dimension,s=u.useMemo(()=>c?br(c):null,[c]),i=String(r?.[0]??""),m=String(r?.[1]??s?.default??""),[l,d]=u.useState(i),[p,g]=u.useState(m);u.useEffect(()=>{d(i)},[i]),u.useEffect(()=>{g(m)},[m]);const S=o([l,p]);u.useEffect(()=>{n?.(S)},[S,n]);const N=u.useCallback(M=>{const w=M.target.value;d(w),o([w,p]),t?.([w,p])},[p,o,t]),b=u.useCallback(M=>{const w=M.target.value;g(w),o([l,w]),t?.([l,w])},[l,o,t]),v=u.useCallback(M=>{d(M.value),g(M.unit),t?.([M.value,M.unit])},[t]),I=u.useMemo(()=>s?s.units.map(M=>f.jsx("option",{value:M,children:a(M)},M)):[],[s,a]);if(!c||!s)return null;const R=!!S||!l.trim();return f.jsx(P,{field:e,error:S,children:f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--reactaform-unit-gap, 8px)",width:"100%"},children:[f.jsx("input",{id:e.name,type:"text",value:l,onChange:N,style:{flex:"2 1 0"},className:B(V.input,V.textInput),"aria-invalid":!!S,"aria-describedby":S?`${e.name}-error`:void 0}),f.jsx("select",{id:`${e.name}-unit`,value:p,onChange:b,style:{flex:"1 1 0"},className:B(V.input,V.inputSelect),"aria-invalid":!!S,"aria-describedby":S?`${e.name}-error`:void 0,children:I}),f.jsx(vr,{disabled:R,inputValue:l,selectedUnit:p,dimension:c,unitFactors:s,onConversionSelect:v,t:a})]})})},Vt=u.memo(Mt),Rt=({field:e,value:r,onChange:t,onError:n,error:a})=>{const o=z(e),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:o}),m=a??s;return f.jsx(P,{field:e,error:m,children:f.jsx("input",{id:e.name,type:"url",defaultValue:String(r??""),ref:c,onChange:i,className:B(V.input,V.textInput),placeholder:"https://example.com","aria-invalid":!!m,"aria-describedby":m?`${e.name}-error`:void 0})})},$t={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:Yr,color:rt,date:tt,dropdown:nt,email:ot,file:it,float:lt,"float-array":ct,image:mt,int:dt,"int-array":ft,"multi-selection":gt,multiline:pt,password:Ct,phone:bt,radio:vt,rating:St,separator:st,slider:kt,string:_e,stepper:yt,switch:jt,text:_e,time:Et,unit:Vt,url:Rt};function At(e){return e in Re}function Dt(e,r){const{wait:t=200,leading:n,trailing:a}=r,o=u.memo(c=>{const s=u.useRef(c.onChange);u.useEffect(()=>{s.current=c.onChange},[c.onChange]);const{callback:i,cancel:m}=nr((...l)=>{s.current?.(...l)},t,{leading:n,trailing:a});return u.useEffect(()=>m,[m]),u.createElement(e,{...c,onChange:i})});return o.displayName="DebouncedFieldWrapper",o}function xr(e,r,t){const n=r;if(!t&&e in Re){console.warn(`Can't overwrite base component type "${e}".`);return}const a=$t[e];if(a===!1){me.register(e,n);return}const o=a??{wait:200};tr?me.register(e,n):me.register(e,Dt(n,o))}function $e(e,r){xr(e,r,!1)}function Ae(e){return me.get(e)}let Ke=!1;function Pt(){Ke||(Object.entries(Re).forEach(([e,r])=>{xr(e,r,!0)}),Ke=!0)}const zt=(e,r)=>{const t=new Map;let n=null,a=null,o=0;for(const c of e){const s=c.group;if(!s){n=null,a=null;continue}if(s===n)r[c.name].group=a??s;else{if(!t.has(s))t.set(s,1),a=null,r[c.name].group=s;else{const i=t.get(s),m=`${s}(${i})`;t.set(s,i+1),a=m,r[c.name].group=m,o++}n=s}}return o},Ot=(e,r={})=>{const{includeEmpty:t=!0}=r,n=[];let a=null,o=[],c=0;for(const i of e){const m=i.group||null;m!==a?((o.length>0||t)&&(o.length===0&&c++,n.push({name:a,fields:o})),a=m,o=[i]):o.push(i)}(o.length>0||t)&&(o.length===0&&c++,n.push({name:a,fields:o}));const s=Math.max(0,...n.map(i=>i.fields.length));return{groups:n,metadata:{totalGroups:n.length,emptyGroups:c,largestGroup:s}}},wr=u.memo(({field:e,value:r,handleChange:t,handleError:n,error:a})=>{const o=Ae(e.type),c=u.useMemo(()=>r,[r]),s=u.useCallback(m=>t(e.name,m),[t,e.name]),i=u.useCallback(m=>n?.(e.name,m),[n,e.name]);return o?f.jsx(o,{field:e,value:c,onChange:s,onError:i,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);wr.displayName="FieldWrapper";const Sr=(e,r,t,n,a)=>{const o=a?a[e.name]??null:void 0;return f.jsx(u.Fragment,{children:f.jsx(wr,{field:e,value:r[e.name],handleChange:t,handleError:n,error:o})},e.name)},Cr=u.memo(({groupName:e,isOpen:r,fields:t,valuesMap:n,handleChange:a,handleError:o,errorsMap:c,toggleGroup:s,t:i})=>{const m=u.useCallback(()=>s(e),[s,e]),{formStyle:l,fieldStyle:d}=O(),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||{},...d?.fieldset||{}}),[l,d]),g=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||{},...d?.legend||{}}),[l,d]);return f.jsxs("fieldset",{style:p,children:[f.jsxs("legend",{onClick:m,style:g,children:[f.jsx("span",{children:i(e)}),f.jsx("span",{children:r?"▼":"▶"})]}),r&&t.map(S=>Sr(S,n,a,o,c))]})});Cr.displayName="FieldGroup";const Lt=(e,r,t,n,a,o,c,s,i,m)=>{const l=r.slice(0,s).filter(g=>c[g.name]),d=Ot(l),p=[];return d.groups.forEach(g=>{if(g.name){const S=e[g.name]??!0;p.push(f.jsx(Cr,{groupName:g.name,isOpen:S,fields:g.fields,valuesMap:t,handleChange:a,handleError:o,errorsMap:m,toggleGroup:i,t:n},g.name))}else g.fields.forEach(S=>p.push(Sr(S,t,a,o,m)))}),p},Tt=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):"",s=a.children[c];!s||!Array.isArray(s)||s.forEach(i=>{typeof i=="string"&&(n[i]=!0,De(i,r,t,n))})},kr=(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,kr(a,r,t))})},Ht=(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},Bt=(e,r,t,n,a)=>{const o={...e};if(kr(n,r,o),a!=null){const c=r[n];if(c&&c.children){const s=String(a),i=c.children[s];i&&Array.isArray(i)&&i.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 qt(e){return Pe.get(e)}function Ut(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 Wt(e,r,t,n,a){const o=Object.values(a).filter(Boolean);if(o.length>0)return{success:!1,message:n("Please fix validation errors before submitting."),errors:o};const c={...t},s=[];if(e&&Array.isArray(e.properties))for(const m of e.properties){const l=m.name,d=c[l];if(d==null)continue;const p=m.type;try{if(p==="int"||p==="number"||p==="float"){const g=String(d).trim();if(g==="")c[l]=0;else{const S=Number(g);isNaN(S)?s.push(n("Invalid number format for field {{1}}",m.displayName||l)):c[l]=S}}else if(p==="int-array"||p==="float-array"){const g=String(d).split(",").map(b=>b.trim()).filter(Boolean),S=[];let N=!1;for(const b of g){const v=Number(b);if(isNaN(v)){s.push(n("Invalid number {{1}} in array for field {{2}}",b,m.displayName||l)),N=!0;break}S.push(v)}N||(c[l]=S)}}catch(g){s.push(n("Error processing field {{1}}: {{2}}",m.displayName||l,g instanceof Error?g.message:String(g)))}}if(s.length>0)return{success:!1,message:n("Data transformation errors occurred."),errors:s};const i=await Jr(e,c,n);if(i&&i.length>0)return{success:!1,message:n("Validation failed"),errors:i};if(e&&typeof e.submitHandlerName=="string"){const m=qt(e.submitHandlerName);if(m)try{const l=await m(e,r?.name??null,c,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)]}}}return{success:!0,message:n("Form submitted successfully."),data:c}}const jr=({message:e,success:r,onDismiss:t,t:n})=>e?f.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:[f.jsx("div",{style:{whiteSpace:"pre-wrap",flex:1},children:e}),f.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;jr.displayName="SubmissionMessage";const _t=({onClick:e,disabled:r=!1,t})=>{const[n,a]=u.useState(!1);return f.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")})},Er=({definition:e,instance:r,chunkSize:t=50,chunkDelay:n=50})=>{const{properties:a,displayName:o}=e,c=O(),{t:s,formStyle:i,language:m}=c,l={...c,definitionName:e?.name??c.definitionName},[d,p]=u.useState("en"),[g,S]=u.useState([]),[N,b]=u.useState({}),[v,I]=u.useState({}),[R,M]=u.useState({}),[w,F]=u.useState({}),[x,h]=u.useState({}),[y,C]=u.useState(null),[k,j]=u.useState(null),[E,A]=u.useState(0),[T,Y]=u.useState(!1),[ne,ae]=u.useState(r.name||""),G=u.useRef(r),de=u.useRef(!1);u.useEffect(()=>{const D=Object.fromEntries(a.map($=>[$.name,{...$,children:{}}]));a.forEach($=>{$.parents&&Object.entries($.parents).forEach(([ee,re])=>{const oe=D[ee];oe&&re.forEach(Tr=>{oe.children||(oe.children={});const Te=String(Tr);oe.children[Te]=[...oe.children[Te]||[],$.name]})})}),zt(a,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}),G.current=r,Object.keys(r.values).forEach($=>{D[$]!==void 0&&(q[$]=r.values[$])});const J=Tt(H),_={};H.forEach($=>{$.group&&!($.group in _)&&(_[$.group]=!0)});const X=requestAnimationFrame(()=>{S(H),b(D),I(q),M(Ht(H,q,J,D)),F(_),Y(!0),ae(r.name)});return()=>cancelAnimationFrame(X)},[a,r,e]),u.useEffect(()=>{if(!T||E>=g.length)return;const D=setTimeout(()=>{A(H=>Math.min(H+t,g.length))},n);return()=>clearTimeout(D)},[T,E,g.length,t,n]);const Dr=u.useCallback((D,H)=>{C(null),j(null),I(q=>{const J={...q,[D]:H},_=N[D];return _&&["checkbox","dropdown","multi-select","radio","switch"].includes(_.type)&&M($=>Bt($,N,J,D,String(H))),J})},[N,C,j]);u.useEffect(()=>{let D=0;return D=requestAnimationFrame(()=>{m!==d&&(p(m||"en"),C(null),j(null))}),()=>cancelAnimationFrame(D)},[m,d]),u.useEffect(()=>{let D=0;return D=requestAnimationFrame(()=>{if(de.current){de.current=!1,G.current=r,ae(r.name||"");return}G.current=r,C(null),j(null),ae(r.name||"")}),()=>cancelAnimationFrame(D)},[r,r.name]);const Pr=u.useCallback((D,H)=>{h(q=>H?{...q,[D]:String(H)}:Object.fromEntries(Object.entries(q).filter(([_])=>_!==D)))},[]),zr=async()=>{de.current=!0;const D=G.current?.name;G.current.name=ne;let H=x;if(l.fieldValidationMode==="onSubmission"){const X={};if(g.forEach($=>{const ee=v[$.name];if(ee===void 0)return;const re=gr(l.definitionName,$,ee,s);re&&(X[$.name]=re)}),h(X),H=X,Object.keys(X).length>0){C(s("Please fix validation errors before submitting the form.")),j(!1);return}else C(null),j(null)}const q=await Wt(e,G.current,v,s,H),J=typeof q.message=="string"?q.message:String(q.message),_=Object.values(q.errors??{}).join(`
301
301
  `);C(_?J+`
302
302
  `+_:J),j(q.success),q.success||(G.current.name=D??G.current.name,ae(D??""))},Or=D=>{F(H=>({...H,[D]:!H[D]}))},Lr=u.useMemo(()=>l.fieldValidationMode==="realTime"?Object.values(x).some(Boolean):!1,[x,l.fieldValidationMode]);return f.jsx(ke.Provider,{value:l,children:f.jsxs("div",{style:i.container,children:[o&&f.jsx("h2",{style:i.titleStyle,children:s(o)}),f.jsx(jr,{message:y,success:k,onDismiss:()=>{C(null),j(null)},t:s}),r&&f.jsx(sr,{name:ne,onChange:D=>{ae(D),C(null),j(null)}}),f.jsxs(f.Fragment,{children:[Lt(w,g,v,s,Dr,Pr,R,E,Or,x),E<g.length&&f.jsx("div",{style:{fontSize:"0.9em",color:"var(--reactaform-text-muted, #666)"},children:s(`Loading more fields... (${E}/${g.length})`)})]}),f.jsx(_t,{onClick:zr,disabled:Lr,t:s})]})})},Nr={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:"繁體中文"}},Kt=()=>Nr,ge=new Map,le=new Map,te=new Set,be=new Map,Gt=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(Nr[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}`}}},Jt=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 Gt(r);return t.success&&(ge.set(r,t.translations),be.set(r,{loadedAt:new Date,size:Object.keys(t.translations).length,source:"common"})),t},Yt=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")&&Fr()&&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 s;try{s=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(!s||typeof s!="object"){const m="Invalid translation file format";return te.add(t),{success:!1,translations:{},error:m}}const i=Object.fromEntries(Object.entries(s).map(([m,l])=>[m,typeof l=="string"?l:String(l)]));return le.set(t,i),be.set(t,{loadedAt:new Date,size:Object.keys(i).length,source:"user"}),{success:!0,translations:i,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 Fr(){try{if(typeof process<"u"&&process?.env?.NODE_ENV==="development")return!0}catch{}return!1}function Xt(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 Zt=(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=Xt(o,a),!c&&Fr()&&console.debug(`Missing translation for "${n}" in language "${e}"`),o)};function Qt(e){return/^[-+]?\d*$/.test(e)}function en(e){const r=/^[-+]?\d*$/;return e.split(",").map(t=>t.trim()).every(t=>r.test(t))}const rn=",",tn=e=>!e||e.trim()===""?[]:e.split(rn).map(r=>r.trim()).filter(Boolean).map(r=>Number(r)),Ge=(e,r,t)=>{const n=String(r);if(n.trim()==="")return e.required?t("Value required"):null;if(!Qt(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 nn(e,r,t){const n=String(r);if(n.trim()==="")return e.required?t("Value required"):null;if(!en(n))return t("Each value must be a valid integer");const a=tn(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 an=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;function on(e){return e.split(",").map(r=>r.trim()).every(r=>an.test(r))}const sn=",",cn=e=>!e||e.trim()===""?[]:e.split(sn).map(r=>r.trim()).filter(Boolean).map(r=>Number(r));function ln(e,r,t){const n=String(r);if(n.trim()==="")return e.required?t("Value required"):null;if(!on(n))return t("Each value must be a valid float");const a=cn(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 s=he.get(e);if(s&&s.pattern===e.pattern)c=s.regex;else try{const i=new RegExp(e.pattern);he.set(e,{pattern:e.pattern,regex:i}),c=i}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},Je=new WeakMap,un=e=>{let r=Je.get(e);return r||(r={minTime:xe(e.minDate),maxTime:xe(e.maxDate)},Je.set(e,r)),r};function mn(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}=un(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 fn(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 s=c.split(":").map(l=>parseInt(l,10));if(s.some(l=>Number.isNaN(l)))return NaN;const i=s.length;if(i<2||i>3)return NaN;if(i===2&&(s[0]<0||s[0]>23||s[1]<0||s[1]>59))return NaN;if(i===3&&(s[0]<0||s[0]>23||s[1]<0||s[1]>59||s[2]<0||s[2]>59))return NaN;let m=0;if(s.length===3)m=s[0]*3600+s[1]*60+s[2];else if(s.length===2)m=s[0]*3600+s[1]*60;else if(s.length===1)m=s[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 dn(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function pn(e,r,t){const n=String(r??"").trim();return n===""?e.required?t("Value required"):null:dn(n)?Oe(e,r,t,t("Email does not match pattern: {{1}}",e.pattern)):t("Must be valid email format")}function gn(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 hn=/^(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$/i,yn=e=>{try{return new URL(e),!0}catch{return!1}};function bn(e,r,t){const n=String(r??"").trim();if(n==="")return e.required?t("Value required"):null;if(hn.test(n)||yn(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 vn(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 xn(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 wn(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 Sn(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(s=>String(s.value)===c))return t("Invalid option selected");return null}const Cn=/^#([0-9A-F]{3}){1,2}$/i,kn=e=>Cn.test(e);function jn(e,r,t){const n=String(r).trim();return n===""?e.required?t("Value required"):null:kn(n)?null:t("Invalid color format")}function En(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 Ye=!1;function Ir(){Ye||(L("int",Ge),L("stepper",Ge),L("int-array",nn),L("float",ve),L("slider",ve),L("float-array",ln),L("text",ue),L("string",ue),L("multiline",ue),L("password",ue),L("email",pn),L("date",mn),L("time",fn),L("url",bn),L("phone",gn),L("unit",vn),L("dropdown",wn),L("multi-selection",Sn),L("color",jn),L("rating",En),L("file",xn),Ye=!0)}Ir();Pt();Ir();const Nn=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"}}),Fn=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
303
303
  xmlns='http://www.w3.org/2000/svg'
@@ -617,6 +617,7 @@ const nr = u.memo(({
617
617
  id: `${e.name}-label`,
618
618
  className: R.label,
619
619
  htmlFor: e.name,
620
+ style: { textAlign: "left" },
620
621
  children: a(e.displayName)
621
622
  }
622
623
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactaform",
3
- "version": "1.8.6",
3
+ "version": "1.8.7",
4
4
  "description": "A powerful, type-safe React form builder library with dynamic field rendering, conditional visibility, multi-language support, and extensible validation",
5
5
  "keywords": [
6
6
  "react",