reactaform 1.8.4 → 1.8.6
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.md +1 -1
- package/dist/reactaform.cjs.js +3 -3
- package/dist/reactaform.es.js +449 -448
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -100,7 +100,7 @@ npm install reactaform
|
|
|
100
100
|
|
|
101
101
|
## Learn more
|
|
102
102
|
|
|
103
|
-
- [Full README](README.full.md)
|
|
103
|
+
- [Full README](https://github.com/yanggmtl/reactaform/blob/master/README.full.md)
|
|
104
104
|
- [Documentation](https://reactaform.vercel.app/docs)
|
|
105
105
|
- [ReactaForm Website (Demos)](https://reactaform.vercel.app)
|
|
106
106
|
- [Visual Builder](https://reactaform.vercel.app/builder)
|
package/dist/reactaform.cjs.js
CHANGED
|
@@ -297,9 +297,9 @@
|
|
|
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 R={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),w=u.useRef(null),I=u.useRef(null),S=u.useId(),v=ce(a),[k,V]=u.useState(void 0);u.useLayoutEffect(()=>{if(!g.current)return;const b="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";V(`color-mix(in srgb, var(--reactaform-primary-bg) 85%, ${C} 15%)`)}else V(b)},[]);const E=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:k??(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=(j,N,F)=>{const T=j?.[N];return(F&&T?T[F]: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,k]);u.useLayoutEffect(()=>{if(!s||!g.current||!w.current){p(!1);return}const b=g.current.getBoundingClientRect();I.current=b;const h=w.current.getBoundingClientRect(),y=8,C=window.innerWidth,j=window.innerHeight,N=-4;let F=b.right+y,A=b.top+b.height/2-h.height/2+N;F+h.width>C-y&&(F=b.left-y-h.width),F=Math.max(y,Math.min(F,C-h.width-y)),A=Math.max(y,Math.min(A,j-h.height-y)),l({x:F,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 x=typeof document<"u"?document.getElementById("popup-root"):null,M=f.jsx("div",{ref:w,"data-tooltip-id":S,style:{...E.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?E.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?S:void 0,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),style:{...E.icon},children:f.jsx(Ur,{})}),s&&(x?fe.createPortal(M,x):M)]})},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:`${R.field} column-layout`,style:c,children:[n&&f.jsx("label",{id:`${e.name}-label`,className:R.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:`${R.field} row-layout`,children:[f.jsx("label",{id:`${e.name}-label`,className:R.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(R.input,R.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:R.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(E=>{const x=pe(E.target.value);p(x),l({target:{value:x}})},[l]),w=u.useCallback(E=>{const x=pe(E.target.value);p(x),l({target:{value:x}})},[l]),S=u.useMemo(()=>new Set(qe.map(E=>E.value)),[]).has(d),{r:v,g:k,b:V}=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:w,className:B(R.input,R.inputSelect),"aria-invalid":!!m,children:[qe.map(E=>f.jsx("option",{value:E.value,children:o(E.label)},E.value)),!S&&f.jsxs("option",{value:d,children:["(",v,", ",k,", ",V,")"]})]}),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(R.input,R.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,w]=u.useState(null);u.useEffect(()=>{l.current=n},[n]);const I=z(e,a),[S,v]=u.useState(null),k=u.useRef(null);u.useEffect(()=>{const y=String(r??"");let C=I(y);if(C&&e.options.length>0){const j=String(e.options[0].value);t?.(j),C=null}C!==k.current&&(k.current=C,v(C),l.current?.(C??null))},[r,I,t,e.options]);const V=()=>{if(!m.current)return;const y=m.current.getBoundingClientRect();w({x:y.left,y:y.bottom}),p(C=>!C)},E=y=>{const C=I(y);C!==k.current&&(k.current=C,v(C),l.current?.(C??null)),t?.(y),p(!1)},x=u.useMemo(()=>{const y=e.options.find(C=>String(C.value)===String(r));return y?o(y.label):""},[e.options,r,o]),M=(y,C,j)=>{if(!C)return{};const F=y?.[C];return(j&&F?F[j]:void 0)??{}},b=u.useMemo(()=>({height:"var(--reactaform-input-height, 2.5rem)",display:"flex",alignItems:"center",cursor:"pointer",position:"relative",...M(s,"dropdown","control"),...M(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)",...M(s,"dropdown","arrow"),...M(i,void 0,"arrow")}),[s,i]);return f.jsxs("div",{children:[f.jsx(P,{field:e,error:S,children:f.jsxs("div",{ref:m,className:"reactaform-input",style:b,onClick:V,tabIndex:0,role:"combobox","aria-haspopup":"listbox","aria-expanded":d,"aria-invalid":!!S,"aria-describedby":S?`${e.name}-error`:void 0,onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),V())},children:[f.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x}),f.jsx("span",{style:h,"aria-hidden":!0,children:"▼"})]})}),d&&g&&f.jsx(at,{position:g,options:e.options,selectedValue:String(r),onSelect:E,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 w=(h,y,C)=>{if(!y)return{};const N=h?.[y];return(C&&N?N[C]:void 0)??{}},I=u.useMemo(()=>({maxHeight:200,overflowY:"auto",background:"var(--reactaform-secondary-bg, #fff)",border:"1px solid var(--reactaform-border-color, #ccc)",borderRadius:4,zIndex:2e3,boxShadow:"var(--reactaform-shadow, 0 2px 8px rgba(0,0,0,0.15))",pointerEvents:"auto",color:"var(--reactaform-text-color, #000)",fontSize:"var(--reactaform-popup-font-size, 0.875rem)",...w(d,"dropdown","popup"),...w(p,void 0,"popup")}),[d,p]),S=u.useMemo(()=>({padding:"6px 8px",cursor:"pointer",display:"flex",alignItems:"center",background:"transparent",color:"var(--reactaform-text-color, #000)",...w(d,"dropdown","option"),...w(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,k=200,[V,E]=u.useState(null),[x,M]=u.useState(null);if(u.useEffect(()=>{if(typeof window>"u")return;const h=()=>{let j=e.x,N=e.y,F=v;const A=o?.current;if(A){const T=A.getBoundingClientRect();j=T.left,N=T.bottom,F=Math.max(80,Math.round(T.width))}j=Math.min(j,window.innerWidth-F),N=Math.min(N,window.innerHeight-k),E({left:j,top:N}),M(F)};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 b=document.getElementById("popup-root");return b||(b=document.createElement("div"),b.id="popup-root",document.body.appendChild(b)),fe.createPortal(f.jsx("div",{ref:i,role:"listbox","aria-activedescendant":m>=0?`opt-${m}`:void 0,style:{position:"fixed",top:V?V.top:e.y,left:V?V.left:e.x,width:x??v,...I},"data-reactaform-theme":c??"light",children:r.map((h,y)=>{const C=String(h.value)===t,j=g?"var(--reactaform-hover-bg, rgba(255,255,255,0.01))":"var(--reactaform-hover-bg, #eee)",N={...S,background:y===m?j:S.background,fontWeight:C?"bold":"normal"};return f.jsx("div",{id:`opt-${y}`,onMouseDown:F=>{F.stopPropagation(),n(String(h.value))},onKeyDown:F=>{const A=r.length;switch(F.key){case"ArrowDown":F.preventDefault(),l(T=>(T+1)%A);break;case"ArrowUp":F.preventDefault(),l(T=>(T-1+A)%A);break;case"Home":F.preventDefault(),l(0);break;case"End":F.preventDefault(),l(A-1);break;case"Enter":case" ":F.preventDefault(),F.stopPropagation(),n(String(h.value));break;case"Escape":F.preventDefault(),a(),o?.current?.focus();break}},tabIndex:y===m?0:-1,role:"option","aria-selected":C,style:N,onMouseEnter:F=>{F.currentTarget.style.background=j,l(y)},onMouseLeave:F=>{F.currentTarget.style.background="transparent",l(A=>A===y?-1:A)},children:s(h.label)},String(h.value))})}),b)},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(R.input,R.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=(x,M)=>M.some(b=>b.name===x.name&&b.size===x.size&&b.lastModified===x.lastModified),w=z(e,a);u.useEffect(()=>{const x=w(r??[]);t?.(r),x!==l.current&&(l.current=x,p(x),m.current?.(x??null))},[r,w]);const I=x=>{const M=x.target.files;let b=null;if(M&&M.length>0){const y=Array.from(M);if(e.multiple){const C=Array.isArray(r)?r:[],j=y.filter(N=>!g(N,C));b=[...C,...j]}else b=y[0]}const h=w(b??[]);h!==l.current&&(l.current=h,p(h),m.current?.(h??null)),t?.(b),x.target&&(x.target.value="")},S=x=>{x.preventDefault(),x.stopPropagation(),s(!1);const M=x.dataTransfer.files;if(M&&M.length>0){const b=Array.from(M);let h=null;if(e.multiple){const C=Array.isArray(r)?r:[],j=b.filter(N=>!g(N,C));h=[...C,...j]}else h=b[0];const y=w(h);y!==l.current&&(l.current=y,p(y),m.current?.(y??null)),t?.(h)}},v=x=>{x.preventDefault(),x.stopPropagation(),s(!0)},k=x=>{x.preventDefault(),x.stopPropagation(),s(!1)},V=x=>{if(Array.isArray(r)&&typeof x=="number"){const M=r.filter((y,C)=>C!==x),b=M.length>0?M:null,h=w(b??[]);h!==l.current&&(l.current=h,p(h),m.current?.(h??null)),t?.(b)}else{const M=w([]);M!==l.current&&(l.current=M,p(M),m.current?.(M??null)),t?.(null)}},E=()=>{const x=Array.isArray(r)?r:r?[r]:[];return x.length===0?null:f.jsx("div",{style:{marginTop:"8px",marginLeft:"20px",display:"flex",flexDirection:"column",gap:"6px",maxHeight:"200px",overflowY:"auto"},children:x.map((M,b)=>f.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[f.jsx("input",{type:"text",value:M.name,disabled:!0,readOnly:!0,title:M.name,className:"reactaform-input",style:{flex:1,cursor:"default",opacity:.8,minWidth:0}}),f.jsx("button",{type:"button",onClick:()=>V(Array.isArray(r)?b: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:"×"})]},`${M.name}-${b}`))})};return f.jsx(P,{field:e,error:d,children:f.jsxs("div",{style:{width:"100%"},children:[f.jsxs("div",{className:"reactaform-input",onDrop:S,onDragOver:v,onDragLeave:k,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:x=>{(x.key==="Enter"||x.key===" ")&&(x.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:I}),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})]}),E()]})})},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(R.input,R.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(R.input,R.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(S=>S.trim()),[m,l]=u.useState(s||""),d=u.useRef(s||null);if(u.useEffect(()=>{if(!s)return;const S=s.split("/"),v=S.pop(),k=v.lastIndexOf(".");if(k===-1)return;const V=v.substring(0,k),E=v.substring(k);let x=null;i?.includes(t)&&(x=`${V}_${t}${E}`);const M=new AbortController;if(x){const b=[...S,x].join("/");fetch(b,{method:"HEAD",signal:M.signal}).then(h=>{const y=h.ok?b:s;y!==d.current&&(d.current=y,l(y))}).catch(()=>{s!==d.current&&(d.current=s,l(s))})}else{const b=s;b!==d.current&&(d.current=b,requestAnimationFrame(()=>l(b)))}return()=>{M.abort()}},[s,t,i]),!m)return null;const{width:p,height:g}=e,w={},I={borderRadius:"8px",objectFit:"contain",boxShadow:"0 2px 6px rgba(0,0,0,0.1)",margin:"0 0 8px 0"};return p&&g?(w.width=p,w.height=g,I.width=`${p}px`,I.height=`${g}px`):p&&!g?(w.width=p,I.width=`${p}px`,I.height="auto"):!p&&g&&(w.height=g,I.width="auto",I.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",...w,style:I})})})},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(R.input,R.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(R.input,R.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(R.input,R.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=(j,N,F)=>{if(!N)return{};const T=j?.[N];return(F&&T?T[F]:void 0)??{}},d=u.useRef(null),[p,g]=u.useState(!1),[w,I]=u.useState(null),S=u.useMemo(()=>e.options.map(j=>({value:j.value,label:c(j.label)})),[e.options,c]),v=u.useMemo(()=>{const j=Array.isArray(r)?r:[],N=new Set(S.map(F=>F.value));return j.filter(F=>N.has(F))},[r,S]),k=z(e,a),[V,E]=u.useState(null),x=u.useRef(null);u.useEffect(()=>{const j=k(Array.isArray(r)?r:[]);j!==x.current&&(x.current=j,E(j),o.current?.(j??null))},[r,k]);const M=()=>{if(!d.current)return;const j=d.current.getBoundingClientRect();I({x:j.left,y:j.bottom}),g(N=>!N)},b=j=>{const N=v.includes(j)?v.filter(A=>A!==j):[...v,j],F=k(N);F!==x.current&&(x.current=F,E(F),o.current?.(F??null)),t?.(N)},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:V,children:f.jsx("div",{style:{width:"100%"},children:f.jsxs("div",{ref:d,className:"reactaform-multiselection-control reactaform-input",style:h,onClick:M,role:"button","aria-haspopup":"listbox","aria-expanded":p,"aria-invalid":!!V,"aria-describedby":V?`${e.name}-error`:void 0,onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),M())},children:[f.jsxs("span",{style:{flex:1,color:"var(--reactaform-text-muted, #888)"},children:[v.length," / ",S.length," selected"]}),v.length>0&&f.jsx("button",{type:"button","aria-label":"Clear selections",onClick:j=>{j.stopPropagation(),t?.([])},style:y,children:f.jsx("span",{style:y,"aria-hidden":!0,children:"✖"})}),f.jsx("span",{style:C,"aria-hidden":!0,children:"▼"})]})})}),p&&w&&f.jsx(ht,{position:w,options:S,selectedValues:v,onToggleOption:b,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 b=o.current.closest("[data-reactaform-theme]"),h=document.getElementById("popup-root");if(b&&h){const y=getComputedStyle(b);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=(b,h,y)=>{if(!h)return{};const j=b?.[h];return(y&&j?j[y]:void 0)??{}},w=u.useMemo(()=>({maxHeight:200,overflowY:"auto",background:"var(--reactaform-secondary-bg, #fff)",border:"1px solid var(--reactaform-border-color, #ccc)",borderRadius:4,zIndex:2e3,boxShadow:"var(--reactaform-shadow, 0 2px 8px rgba(0,0,0,0.15))",pointerEvents:"auto",color:"var(--reactaform-text-color, #000)",fontSize:"var(--reactaform-popup-font-size, 0.875rem)",...g(l,"multiSelect","popup"),...g(d,void 0,"popup")}),[l,d]),I=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 b=h=>{const y=h.target;!s.current?.contains(y)&&!o.current?.contains(y)&&a()};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[a,o]),u.useEffect(()=>{s.current&&r.length>0&&requestAnimationFrame(()=>m(b=>b===-1?0:b))},[r.length]),u.useEffect(()=>{if(!s.current||i<0)return;const b=s.current.querySelector(`#multi-opt-${i}`);b&&requestAnimationFrame(()=>b.focus())},[i]);const S=250,v=200,[k,V]=u.useState(null),[E,x]=u.useState(null);if(u.useEffect(()=>{if(typeof window>"u")return;const b=()=>{let C=e.x,j=e.y,N=S;const F=o?.current;if(F){const A=F.getBoundingClientRect();C=A.left,j=A.bottom,N=Math.max(80,Math.round(A.width))}C=Math.min(C,window.innerWidth-N),j=Math.min(j,window.innerHeight-v),V({left:C,top:j}),x(N)};b(),window.addEventListener("scroll",b,!0),window.addEventListener("resize",b);let h=null;const y=o?.current;return typeof ResizeObserver<"u"&&y&&(h=new ResizeObserver(()=>b()),h.observe(y)),()=>{window.removeEventListener("scroll",b,!0),window.removeEventListener("resize",b),h&&y&&h.unobserve(y)}},[o,e.x,e.y]),typeof window>"u")return null;let M=document.getElementById("popup-root");return M||(M=document.createElement("div"),M.id="popup-root",document.body.appendChild(M)),fe.createPortal(f.jsx("div",{ref:s,role:"listbox","aria-activedescendant":i>=0?`multi-opt-${i}`:void 0,style:{position:"fixed",top:k?k.top:e.y,left:k?k.left:e.x,width:E??S,...w},"data-reactaform-theme":c??"light",children:r.map((b,h)=>{const y=t.includes(b.value),C=p?"var(--reactaform-hover-bg, rgba(255,255,255,0.01))":"var(--reactaform-hover-bg, #eee)",j={...I,background:h===i?C:I.background};return f.jsxs("div",{id:`multi-opt-${h}`,onMouseDown:N=>{N.stopPropagation(),n(b.value)},onKeyDown:N=>{const F=r.length;switch(N.key){case"ArrowDown":N.preventDefault(),m(A=>(A+1)%F);break;case"ArrowUp":N.preventDefault(),m(A=>(A-1+F)%F);break;case"Home":N.preventDefault(),m(0);break;case"End":N.preventDefault(),m(F-1);break;case"Enter":case" ":N.preventDefault(),N.stopPropagation(),n(b.value);break;case"Escape":N.preventDefault(),a(),o?.current?.focus();break}},tabIndex:h===i?0:-1,role:"option","aria-selected":y,style:j,onMouseEnter:N=>{N.currentTarget.style.background=C,m(h)},onMouseLeave:N=>{N.currentTarget.style.background="transparent",m(F=>F===h?-1:F)},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"}}),b.label]},b.value)})}),M)},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:R.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(R.input,R.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(null),m=u.useRef(n);u.useEffect(()=>{m.current=n},[n]);const[l,d]=u.useState(null),p=u.useRef(null),g=u.useCallback(v=>{v!==p.current&&(p.current=v,d(v),m.current?.(v))},[]);u.useEffect(()=>{const v=r!=null?String(r):"",k=c(v);if(k&&e.options.length>0){const V=String(e.options[0].value);t?.(V),i.current?.querySelectorAll("input[type=radio]").forEach(E=>{E.checked=E.value===V})}g(k)},[r,e.options,c,t,g]);const w=v=>{const k=v.target.value,V=c(k);g(V),t?.(k)},I={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"},S={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:l,children:f.jsx("div",{ref:i,className:R.input,role:"radiogroup","aria-labelledby":`${e.name}-label`,"aria-invalid":!!l,style:I,children:e.options.map(v=>{const k=String(v.value);return f.jsxs("label",{className:B(R.label),style:S,children:[f.jsx("input",{type:"radio",name:e.name,value:k,checked:String(r??"")===k,onChange:w,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(v.label)})]},k)})})})},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 w=u.useCallback(S=>{const v=Math.min(Math.max(S,0),s);c(v),t?.(v)},[s,c,t]),I=u.useCallback((S,v)=>{switch(S.key){case"Enter":case" ":S.preventDefault(),w(v+1);break;case"ArrowRight":case"ArrowUp":S.preventDefault(),d.current[Math.min(s-1,v+1)]?.focus();break;case"ArrowLeft":case"ArrowDown":S.preventDefault(),d.current[Math.max(0,v-1)]?.focus();break}},[s,w]);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},(S,v)=>{const k=v<p,E=m!==null&&v<=m||k?"gold":"lightgray";return f.jsx("span",{ref:x=>d.current[v]=x,role:"radio",tabIndex:p>0?v===p-1?0:-1:v===0?0:-1,"aria-checked":k,"aria-label":`Rating ${v+1}`,title:o(`${e.displayName} ${v+1}`),onClick:()=>w(v+1),onKeyDown:x=>I(x,v),onMouseEnter:()=>l(v),onMouseLeave:()=>l(null),style:{...wt,color:E},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(R.input,R.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 w=g.target.value;m(w),o(w),t?.(w)},[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:R.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(R.input,R.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=(E,x,M)=>{if(!x)return{};const b=E?.[x];return(M&&b?b[M]:void 0)??{}},w=u.useMemo(()=>({display:"inline-block",position:"relative",width:44,height:24,...g(d,"switch","label"),...g(p,void 0,"label")}),[d,p]),I=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]),S=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]),k=!!r,V=()=>{t?.(!k)};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:R.label,htmlFor:e.name,style:{textAlign:"left",justifyContent:"flex-start"},children:o(e.displayName)}),f.jsxs("label",{style:w,children:[f.jsx("input",{id:e.name,type:"checkbox",checked:k,readOnly:!0,"aria-label":o(e.displayName),"aria-invalid":!1,"aria-describedby":void 0,style:I,tabIndex:-1}),f.jsx("span",{role:"switch","data-testid":"switch",tabIndex:0,"aria-checked":k,"aria-invalid":!1,"aria-describedby":void 0,onClick:V,onKeyDown:E=>{(E.key===" "||E.key==="Spacebar"||E.key==="Space"||E.key==="Enter")&&(E.preventDefault(),V())},className:`reactaform-switch ${k?"active checked on":""} `,style:k?{...S,backgroundColor:"var(--reactaform-switch-on-bg, #22c55e)",borderColor:"var(--reactaform-switch-on-border, #16a34a)"}:S,children:f.jsx("span",{style:{...v,transform:k?"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(R.input,R.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(R.input,R.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(S=>{if(e)return;const v=parseFloat(r);if(!Number.isFinite(v))return;const k=S.currentTarget.getBoundingClientRect();l({x:k.left,y:k.bottom});const V=[];if(n==="temperature")a.units.forEach(x=>{const M=yr(t,x,v);Number.isFinite(M)&&V.push({label:`${M.toFixed(6)} ${c(x)}`,value:M.toString(),unit:x})});else{const x=a.factors[t];x!==void 0&&Object.entries(a.factors).forEach(([M,b])=>{const h=v/x*b;Number.isFinite(h)&&V.push({label:`${h.toFixed(6)} ${c(M)}`,value:h.toString(),unit:M})})}p(V),i(V.length>0)},[e,r,t,n,a,c]),w=u.useCallback(S=>{i(!1),l(null),o(S)},[o]),I=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:R.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:I,onClickOption:w})]})});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 w=o([l,p]);u.useEffect(()=>{n?.(w)},[w,n]);const I=u.useCallback(E=>{const x=E.target.value;d(x),o([x,p]),t?.([x,p])},[p,o,t]),S=u.useCallback(E=>{const x=E.target.value;g(x),o([l,x]),t?.([l,x])},[l,o,t]),v=u.useCallback(E=>{d(E.value),g(E.unit),t?.([E.value,E.unit])},[t]),k=u.useMemo(()=>s?s.units.map(E=>f.jsx("option",{value:E,children:a(E)},E)):[],[s,a]);if(!c||!s)return null;const V=!!w||!l.trim();return f.jsx(P,{field:e,error:w,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:I,style:{flex:"2 1 0"},className:B(R.input,R.textInput),"aria-invalid":!!w,"aria-describedby":w?`${e.name}-error`:void 0}),f.jsx("select",{id:`${e.name}-unit`,value:p,onChange:S,style:{flex:"1 1 0"},className:B(R.input,R.inputSelect),"aria-invalid":!!w,"aria-describedby":w?`${e.name}-error`:void 0,children:k}),f.jsx(vr,{disabled:V,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(R.input,R.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(w=>Sr(w,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 w=e[g.name]??!0;p.push(f.jsx(Cr,{groupName:g.name,isOpen:w,fields:g.fields,valuesMap:t,handleChange:a,handleError:o,errorsMap:m,toggleGroup:i,t:n},g.name))}else g.fields.forEach(w=>p.push(Sr(w,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 w=Number(g);isNaN(w)?s.push(n("Invalid number format for field {{1}}",m.displayName||l)):c[l]=w}}else if(p==="int-array"||p==="float-array"){const g=String(d).split(",").map(S=>S.trim()).filter(Boolean),w=[];let I=!1;for(const S of g){const v=Number(S);if(isNaN(v)){s.push(n("Invalid number {{1}} in array for field {{2}}",S,m.displayName||l)),I=!0;break}w.push(v)}I||(c[l]=w)}}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,w]=u.useState([]),[I,S]=u.useState({}),[v,k]=u.useState({}),[V,E]=u.useState({}),[x,M]=u.useState({}),[b,h]=u.useState({}),[y,C]=u.useState(null),[j,N]=u.useState(null),[F,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(()=>{w(H),S(D),k(q),E(Ht(H,q,J,D)),M(_),Y(!0),ae(r.name)});return()=>cancelAnimationFrame(X)},[a,r,e]),u.useEffect(()=>{if(!T||F>=g.length)return;const D=setTimeout(()=>{A(H=>Math.min(H+t,g.length))},n);return()=>clearTimeout(D)},[T,F,g.length,t,n]);const Dr=u.useCallback((D,H)=>{C(null),N(null),k(q=>{const J={...q,[D]:H},_=I[D];return _&&["checkbox","dropdown","multi-select","radio","switch"].includes(_.type)&&E($=>Bt($,I,J,D,String(H))),J})},[I,C,N]);u.useEffect(()=>{let D=0;return D=requestAnimationFrame(()=>{m!==d&&(p(m||"en"),C(null),N(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),N(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=b;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.")),N(!1);return}else C(null),N(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,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
|
-
`+_:J),N(q.success),q.success||(G.current.name=D??G.current.name,ae(D??""))},Or=D=>{M(H=>({...H,[D]:!H[D]}))},Lr=u.useMemo(()=>l.fieldValidationMode==="realTime"?Object.values(b).some(Boolean):!1,[b,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:j,onDismiss:()=>{C(null),N(null)},t:s}),r&&f.jsx(sr,{name:ne,onChange:D=>{ae(D),C(null),N(null)}}),f.jsxs(f.Fragment,{children:[Lt(x,g,v,s,Dr,Pr,V,F,Or,b),F<g.length&&f.jsx("div",{style:{fontSize:"0.9em",color:"var(--reactaform-text-muted, #666)"},children:s(`Loading more fields... (${F}/${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
|
|
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'
|
|
304
304
|
viewBox='0 0 24 24'
|
|
305
305
|
fill='none'
|
|
@@ -308,4 +308,4 @@
|
|
|
308
308
|
stroke-linecap='round'
|
|
309
309
|
stroke-linejoin='round'>
|
|
310
310
|
<polyline points='6,9 12,15 18,9'/>
|
|
311
|
-
</svg>")`},textarea:{...r,minHeight:"80px",resize:"vertical",paddingTop:"var(--reactaform-space-sm, 8px)"},error:{color:"var(--reactaform-color-error)",fontSize:"0.875rem",marginTop:"var(--reactaform-space-xs, 4px)",display:"block"}}},Mr=({children:e,definitionName:r="",defaultStyle:t,defaultLanguage:n="en",defaultTheme:a="light",defaultLocalizeName:o="",defaultFieldValidationMode:c="realTime",className:s="reactaform-container"})=>{const i=r,m=o,l=a,d=n,p=u.useMemo(()=>t??{},[t]),[g,w]=u.useState({}),[I,S]=u.useState({});u.useEffect(()=>{let b=!0;return(async()=>{if(d==="en"){b&&(w({}),S({}));return}try{const y=await Jt(d),C=y.success?y.translations:{};b&&w(C);const j=await Yt(d,m),N=j.success?j.translations:{};b&&S(N)}catch{b&&(w({}),S({}))}})(),()=>{b=!1}},[d,m]);const v=u.useMemo(()=>Nn(p),[p]),k=u.useMemo(()=>Fn(p),[p]),V=u.useMemo(()=>Zt(d,g,I),[d,g,I]),E=u.useCallback((b,...h)=>V(b,...h),[V]),x=u.useMemo(()=>({definitionName:i,language:d,theme:l,formStyle:v,fieldStyle:k,t:E,fieldValidationMode:c}),[i,d,l,k,v,E,c]),M=p?.height?{height:"100%"}:void 0;return f.jsx(ke.Provider,{value:x,children:f.jsx("div",{"data-reactaform-theme":l,className:s,style:M,children:e})})};function In(e){if(!e||typeof e!="object")return"Definition must be an object";const r=e;if(!r.name||typeof r.name!="string")return"Definition must include a 'name' string";if(r.name.trim()==="")return"Definition 'name' cannot be empty";if(!r.version||typeof r.version!="string")return"Definition must include a 'version' string";if(r.properties!==void 0&&!Array.isArray(r.properties))return"'properties' must be an array if provided";if(Array.isArray(r.properties))for(let t=0;t<r.properties.length;t++){const n=r.properties[t];if(!n||typeof n!="object")return`Property at index ${t} must be an object`;if(!n.name||typeof n.name!="string")return`Property at index ${t} must have a string 'name'`;if(n.name.trim()==="")return`Property at index ${t} has an empty 'name'`;if(!n.type||typeof n.type!="string")return`Property '${n.name}' must have a string 'type'`;if(n.type.trim()==="")return`Property '${n.name}' has an empty 'type'`}return null}async function Mn(e,r={}){const{validateSchema:t=!0}=r;try{if(!e||typeof e!="string")return{success:!1,error:"jsonData must be a non-empty JSON string"};const n=e.trim();if(!n)return{success:!1,error:"jsonData is empty"};let a;try{a=JSON.parse(n)}catch(o){return{success:!1,error:`Invalid JSON format: ${o instanceof Error?o.message:"Unknown parsing error"}`}}if(t){const o=In(a);if(o)return{success:!1,error:`Schema validation failed: ${o}`}}return{success:!0,definition:a}}catch(n){return{success:!1,error:`Unexpected error loading definition: ${n instanceof Error?n.message:"Unknown error"}`}}}function Vr(e,r){try{if(!e)return{success:!1,error:"Definition is required"};if(!r||typeof r!="string")return{success:!1,error:"Instance name is required"};const t={name:r,definition:e.name??"unknown",version:e.version??"1.0.0",values:{}},n=e.properties||[];return Array.isArray(n)&&n.forEach(a=>{const o=a;if(o.type==="unit"){const c=o.defaultUnit,s=Number(o.defaultValue)||void 0;t.values[o.name]=[s||0,c||"m"]}else o.defaultValue!==void 0&&(t.values[o.name]=o.defaultValue)}),{success:!0,instance:t}}catch(t){return{success:!1,error:`Error creating instance: ${t instanceof Error?t.message:"Unknown error"}`}}}function Vn(e){try{if(!e)return{success:!1,error:"Instance data is required"};let r;if(typeof e=="string")try{r=JSON.parse(e)}catch(t){return{success:!1,error:`Invalid JSON format: ${t instanceof Error?t.message:"Unknown parsing error"}`}}else r=e;return typeof r!="object"||r===null?{success:!1,error:"Instance must be a valid object"}:{success:!0,instance:r}}catch(r){return{success:!1,error:`Error loading instance: ${r instanceof Error?r.message:"Unknown error"}`}}}function Rn(e,r,t){try{if(!e)return{success:!1,error:"Instance is required"};if(!r)return{success:!1,error:"Latest definition is required"};if(e.definition===r.name&&e.version===r.version)return{success:!0,instance:e};const n={name:e.name||r.name+"-instance",definition:r.name,version:r.version,values:{}},a=n.values,o={};(r.properties||[]).forEach(i=>{o[i.name]=i});const c=(i,m,l)=>{if(i==null)return i;const d=m.toLowerCase();try{if(d==="string"||d==="text")return String(i);if(d==="int"||d==="integer"||d==="number"||d==="float"){if(typeof i=="number")return i;if(typeof i=="boolean")return i?1:0;if(typeof i=="string"){const p=i.trim();if(p==="")return null;const g=Number(p);return Number.isNaN(g)?0:g}return 0}if(d==="boolean"||d==="bool"||d==="checkbox"||d==="switch"){if(typeof i=="boolean")return i;if(typeof i=="number")return i!==0;if(typeof i=="string"){const p=i.toLowerCase().trim();return["true","1","yes","on"].includes(p)}return!!i}if(d==="unit"){if(Array.isArray(i)&&i.length>=2)return i;if(Array.isArray(i)&&i.length===1)return[i[0],l&&l.defaultUnit||"m"];if(typeof i=="number")return[i,l&&l.defaultUnit||"m"];if(typeof i=="string"){const p=Number(i);return[Number.isNaN(p)?0:p,l&&l.defaultUnit||"m"]}return[0,l&&l.defaultUnit||"m"]}if(d.endsWith("[]")||d==="array"||d==="int-array"||d==="float-array")return Array.isArray(i)?i:typeof i=="string"?i.split(",").map(p=>p.trim()).filter(Boolean):[i]}catch{}return i},s=e.values||{};Object.keys(s).forEach(i=>{const m=s[i],l=o[i];if(!l)return;const d=Array.isArray(m)?"array":m===null?"null":typeof m,p=(l.type||"").toLowerCase();d===p||p==="string"&&typeof m=="string"?a[i]=m:a[i]=c(m,p,l)}),(r.properties||[]).forEach(i=>{const m=i.name;m in a||(a[m]=i.defaultValue)});try{typeof t=="function"&&t?.(e,n,r)}catch(i){return{success:!1,error:`Upgrade callback error: ${i instanceof Error?i.message:String(i)}`}}return{success:!0,instance:n}}catch(n){return{success:!1,error:`Error upgrading instance: ${n instanceof Error?n.message:"Unknown error"}`}}}function $n(e){const[r,t]=u.useState(null);return u.useEffect(()=>{const n=document.querySelector("[data-reactaform-theme]");if(!n)return;const a=n.closest("[data-reactaform-theme]");if(!a)return;const o=()=>t(a.getAttribute("data-reactaform-theme"));o();const c=new MutationObserver(s=>{for(const i of s)i.type==="attributes"&&i.attributeName==="data-reactaform-theme"&&o()});return c.observe(a,{attributes:!0,attributeFilter:["data-reactaform-theme"]}),()=>c.disconnect()},[e]),r}const An=({definitionData:e,instance:r,language:t,className:n,theme:a,style:o,fieldValidationMode:c="realTime"})=>{const s=u.useMemo(()=>{try{return typeof e=="string"?JSON.parse(e):e??null}catch{return null}},[e]),i={fontSize:"inherit",fontFamily:"inherit",...o},m=$n(),l=a??m??"light",d=t??"en";u.useEffect(()=>{let g=document.getElementById("popup-root");g||(g=document.createElement("div"),g.id="popup-root",document.body.appendChild(g))},[]);const p=u.useMemo(()=>{if(r)return r;if(!s)return null;const g=Vr(s,s.name);return!g.success||!g.instance?null:g.instance},[r,s]);return s?p?f.jsx(Mr,{definitionName:s.name,defaultStyle:i,defaultLanguage:d,defaultTheme:l,defaultLocalizeName:s.localization||"",className:n,defaultFieldValidationMode:c,children:f.jsx(Er,{definition:s,instance:p})}):f.jsx("div",{style:{color:"red"},children:"Error: Failed to create instance from definition."}):f.jsx("div",{style:{color:"red"},children:"Error: No form definition provided."})},Z=new Map,U={components:new Map,fieldValidators:new Map,fieldTypeValidators:new Map,formValidators:new Map,submissionHandlers:new Map};function Rr(e,r,t){if(!e)return!0;if(t&&!t(e))return!1;switch(r){case"error":throw new Error(`Plugin conflict: "${e.newPlugin}" tried to register ${e.type} "${e.name}" already registered by "${e.existingPlugin}"`);case"warn":return console.warn(`Plugin conflict: "${e.newPlugin}" tried to register ${e.type} "${e.name}" already registered by "${e.existingPlugin}". Skipping.`),!1;case"override":return console.info(`Plugin "${e.newPlugin}" is overriding ${e.type} "${e.name}" previously registered by "${e.existingPlugin}"`),!0;case"skip":return!1}}function Dn(e){const r=[];if(e.components){for(const t of Object.keys(e.components))if(Ae(t)){const a=U.components.get(t);a&&a!==e.name&&r.push({type:"component",name:t,existingPlugin:a,newPlugin:e.name})}}if(e.fieldCustomValidators)for(const[t,n]of Object.entries(e.fieldCustomValidators))for(const a of Object.keys(n)){const c=U.fieldValidators.get(t)?.get(a);fr(t,a)&&c&&c!==e.name&&r.push({type:"fieldCustomValidator",name:`${t}:${a}`,existingPlugin:c,newPlugin:e.name})}if(e.fieldTypeValidators)for(const t of Object.keys(e.fieldTypeValidators)){const n=pr(t),a=U.fieldTypeValidators.get(t);n&&a&&a!==e.name&&r.push({type:"fieldTypeValidator",name:`type:${t}`,existingPlugin:a,newPlugin:e.name})}if(e.formValidators)for(const t of Object.keys(e.formValidators)){const n=dr(t),a=U.formValidators.get(t);n&&a&&a!==e.name&&r.push({type:"formValidator",name:t,existingPlugin:a,newPlugin:e.name})}if(e.submissionHandlers)for(const t of Object.keys(e.submissionHandlers)){const n=Ut(t),a=U.submissionHandlers.get(t);n&&a&&a!==e.name&&r.push({type:"submissionHandler",name:t,existingPlugin:a,newPlugin:e.name})}return r}function se(e,r,t,n,a,o,c,s){for(const i of Object.keys(e)){let m;if(s?m=a.find(l=>l.type==="fieldCustomValidator"&&l.name===`${s}:${i}`):e===n.components?m=a.find(l=>l.type==="component"&&l.name===i):e===n.formValidators?m=a.find(l=>l.type==="formValidator"&&l.name===i):e===n.fieldTypeValidators?m=a.find(l=>l.type==="fieldTypeValidator"&&l.name===`type:${i}`):e===n.submissionHandlers&&(m=a.find(l=>l.type==="submissionHandler"&&l.name===i)),Rr(m||null,o,c))if(s){const l=r.get(s)||new Map;l.set(i,n.name),r.set(s,l),t(i,e[i])}else r.set(i,n.name),t(i,e[i])}}function Pn(e,r){const t=r?.conflictResolution||"error";if(Z.has(e.name)){const a={type:"plugin",name:e.name,existingPlugin:e.name,newPlugin:e.name};if(!Rr(a,t,r?.onConflict))return}const n=Dn(e);if(e.components&&se(e.components,U.components,$e,e,n,t,r?.onConflict),e.fieldCustomValidators)for(const[a,o]of Object.entries(e.fieldCustomValidators))se(o,U.fieldValidators,(c,s)=>ur(a,c,s),e,n,t,r?.onConflict,a);e.formValidators&&se(e.formValidators,U.formValidators,lr,e,n,t,r?.onConflict),e.fieldTypeValidators&&se(e.fieldTypeValidators,U.fieldTypeValidators,mr,e,n,t,r?.onConflict),e.submissionHandlers&&se(e.submissionHandlers,U.submissionHandlers,ze,e,n,t,r?.onConflict),e.setup&&e.setup(),Z.set(e.name,e)}function zn(e,r=!1){const t=Z.get(e);if(!t)return!1;if(t.cleanup&&t.cleanup(),r){if(t.components)for(const n of Object.keys(t.components))U.components.delete(n);if(t.fieldCustomValidators)for(const[n,a]of Object.entries(t.fieldCustomValidators)){const o=U.fieldValidators.get(n);if(o){for(const c of Object.keys(a))o.delete(c);o.size===0&&U.fieldValidators.delete(n)}}if(t.formValidators)for(const n of Object.keys(t.formValidators))U.formValidators.delete(n);if(t.fieldTypeValidators)for(const n of Object.keys(t.fieldTypeValidators))U.fieldTypeValidators.delete(n);if(t.submissionHandlers)for(const n of Object.keys(t.submissionHandlers))U.submissionHandlers.delete(n)}return Z.delete(e),!0}function On(e){return Z.get(e)}function Ln(){return Array.from(Z.values())}function Tn(e){return Z.has(e)}function Hn(e){for(const[r,t]of Object.entries(e))$e(r,t)}function Q(e){return typeof e=="object"&&e!==null}function Le(e){if(!Q(e))return!1;const r=e;return typeof r.name=="string"&&typeof r.displayName=="string"}function $r(e){if(!Q(e))return!1;const r=e;return typeof r.name!="string"||typeof r.version!="string"||!Array.isArray(r.properties)?!1:r.properties.every(t=>Le(t))}function we(e){try{return typeof File<"u"&&e instanceof File}catch{const r=Q(e)?e:void 0;return!!r&&typeof r.name=="string"&&typeof r.size=="number"}}function Bn(e,r,t={}){try{const{includeMetadata:n=!1,dateFormat:a="iso",fileHandling:o="metadata",prettify:c=!1,excludeFields:s=[],includeOnlyFields:i=[]}=t;if(!e||typeof e!="object")return{success:!1,error:"Instance must be a valid object"};const m=[],l=[],d={},g=($r(r)||Q(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Le),w=new Map(g.map(S=>[S.name,S]));for(const[S,v]of Object.entries(e)){if(s.includes(S)){l.push(S);continue}if(i.length>0&&!i.includes(S)){l.push(S);continue}if(v===void 0)continue;const k=w.get(S);try{d[S]=qn(v,k,{dateFormat:a,fileHandling:o})}catch(V){m.push(`Error serializing field '${S}': ${String(V)}`),d[S]=null}}return n&&(d._metadata={serializedAt:new Date().toISOString(),version:(Q(r)?r.version:void 0)||"1.0.0",fieldCount:Object.keys(d).length-1}),{success:!0,data:c?JSON.stringify(d,null,2):JSON.stringify(d),metadata:{fieldCount:Object.keys(d).length,excludedFields:l,warnings:m}}}catch(n){return{success:!1,error:`Serialization failed: ${n instanceof Error?n.message:"Unknown error"}`}}}function qn(e,r,t={}){const{dateFormat:n="iso",fileHandling:a="metadata"}=t;if(e==null)return null;if(r)switch(r.type){case"date":case"datetime":case"date-time":return Xe(e,n);case"file":return Ze(e,a);case"int":case"integer":return typeof e=="string"?parseInt(e,10):e;case"float":case"number":return typeof e=="string"?parseFloat(e):e;case"boolean":return typeof e=="string"?e==="true":!!e;case"int-array":case"float-array":return Array.isArray(e)?e.map(o=>typeof o=="string"?Number(o):o):e;default:return e}return e instanceof Date?Xe(e,n):we(e)||Array.isArray(e)&&we(e[0])?Ze(e,a):e}function Xe(e,r){let t=null;if(e instanceof Date)t=e;else if(typeof e=="string"){const n=new Date(e);if(!isNaN(n.getTime()))t=n;else return e}else return e;switch(r){case"timestamp":return t.getTime();case"locale":return t.toLocaleString();case"iso":default:return t.toISOString()}}function Ze(e,r){return r==="skip"?null:Array.isArray(e)?e.map(t=>Qe(t,r)):Qe(e,r)}function Qe(e,r){if(!we(e))return e;const t=e;return r==="metadata"?{name:t.name,size:t.size,type:t.type,lastModified:t.lastModified}:{name:t.name,size:t.size,type:t.type,lastModified:t.lastModified,_note:"Base64 encoding requires async implementation"}}function Un(e,r,t={}){try{const{strict:n=!1,validateTypes:a=!0,preserveUnknownFields:o=!0,dateFormat:c="auto"}=t;if(!e||typeof e!="string")return{success:!1,error:"Serialized data must be a non-empty string"};let s;try{s=JSON.parse(e)}catch(I){return{success:!1,error:`Invalid JSON: ${I instanceof Error?I.message:"Unknown parsing error"}`}}if(!s||typeof s!="object")return{success:!1,error:"Parsed data must be an object"};const i=[],m=[],l={},p=($r(r)||Q(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Le),g=new Map(p.map(I=>[I.name,I]));for(const I of p){const S=I.name,v=s[S];if(v===void 0){n&&I.required&&m.push(`Required field '${S}' is missing`);continue}try{l[S]=Wn(v,I,{validateTypes:a,dateFormat:c})}catch(k){const V=`Error deserializing field '${S}': ${String(k)}`;n?m.push(V):(i.push(V),l[S]=v)}}if(o)for(const[I,S]of Object.entries(s))!g.has(I)&&I!=="_metadata"&&(n&&i.push(`Unknown field '${I}' preserved`),l[I]=S);const w=m.length>0;return{success:!w,data:l,warnings:i.length>0?i:void 0,validationErrors:w?m:void 0}}catch(n){return{success:!1,error:`Deserialization failed: ${n instanceof Error?n.message:"Unknown error"}`}}}function Wn(e,r,t={}){const{validateTypes:n=!0,dateFormat:a="auto"}=t;if(e==null)return e;try{switch(r.type){case"date":case"datetime":case"date-time":return Gn(e,a,n);case"int":case"integer":return Se(e,n);case"float":case"number":return Ce(e,n);case"boolean":return Jn(e,n);case"int-array":return er(e,"integer",n);case"float-array":return er(e,"number",n);case"string":case"text":case"email":case"url":case"phone":return n?String(e):e;default:return e}}catch(o){if(n)throw new Error(`Type conversion failed: ${String(o)}`);return e}}function _n(e,r={}){try{const{prettify:t=!0,includeMetadata:n=!0}=r;if(!e||typeof e!="object")return{success:!1,error:"Definition must be a valid object"};const a={...e};return n&&(a._metadata={serializedAt:new Date().toISOString(),version:a.version||"1.0.0",propertyCount:(Array.isArray(a.properties)?a.properties.length:0)||0}),{success:!0,data:t?JSON.stringify(a,null,2):JSON.stringify(a),metadata:{fieldCount:(Array.isArray(a.properties)?a.properties.length:0)||0,excludedFields:[],warnings:[]}}}catch(t){return{success:!1,error:`Definition serialization failed: ${t instanceof Error?t.message:"Unknown error"}`}}}function Kn(e,r={}){try{const{strict:t=!1,validateTypes:n=!0}=r;let a;if(typeof e=="string")try{a=JSON.parse(e)}catch(l){return{success:!1,error:`Invalid JSON for definition: ${l instanceof Error?l.message:"Unknown parsing error"}`}}else if(e&&typeof e=="object")a={...e};else return{success:!1,error:"Input must be a string or object"};const o=[],c=[],s=["name","version","displayName"];for(const l of s)if(!(l in a)||!a[l])if(t)c.push(`Required field '${l}' is missing`);else switch(o.push(`Missing field '${l}', using default`),l){case"name":a.name="unnamed-definition";break;case"version":a.version="1.0.0";break;case"displayName":a.displayName=a.name||"Unnamed Definition";break}const i=Array.isArray(a.properties)?a.properties:null;i?a.properties=i.map((l,d)=>{const p=Q(l)?l:{},g={...p};if(!p.name){const w=`Property at index ${d} missing 'name'`;t?c.push(w):(o.push(`${w}, using 'field_${d}'`),g.name=`field_${d}`)}return p.displayName||(g.displayName=p.name||`Field ${d}`),p.type||(t&&n?c.push(`Property '${p.name||d}' missing 'type'`):(o.push(`Property '${p.name||d}' missing 'type', using 'string'`),g.type="string")),p.defaultValue===void 0&&(g.defaultValue=null),p.required===void 0&&(g.required=!1),g}):t?c.push("Properties must be an array"):(o.push("Properties not found or invalid, using empty array"),a.properties=[]);const m=c.length>0;return{success:!m,data:a,warnings:o.length>0?o:void 0,validationErrors:m?c:void 0}}catch(t){return{success:!1,error:`Definition deserialization failed: ${t instanceof Error?t.message:"Unknown error"}`}}}function Gn(e,r,t){if(e instanceof Date)return e;if(typeof e=="number"){const n=new Date(e);if(t&&isNaN(n.getTime()))throw new Error(`Invalid timestamp: ${e}`);return n}if(typeof e=="string"){const n=new Date(e);if(t&&isNaN(n.getTime()))throw new Error(`Invalid date string: ${e}`);return n}if(t)throw new Error(`Cannot convert ${typeof e} to Date`);return e}function Se(e,r){if(typeof e=="number"){if(Number.isInteger(e))return e;if(r)throw new Error(`Number ${e} is not an integer`);return Math.floor(e)}if(typeof e=="string"){const t=e.trim();if(t===""){if(r)throw new Error("Cannot convert empty string to integer");return e}const n=parseInt(t,10);if(r&&isNaN(n))throw new Error(`Cannot convert "${e}" to integer`);return n}if(r)throw new Error(`Cannot convert ${typeof e} to integer`);return e}function Ce(e,r){if(typeof e=="number"){if(r&&!isFinite(e))throw new Error(`Number ${e} is not finite`);return e}if(typeof e=="string"){const t=e.trim();if(t===""){if(r)throw new Error("Cannot convert empty string to number");return e}const n=parseFloat(t);if(r&&(isNaN(n)||!isFinite(n)))throw new Error(`Cannot convert "${e}" to number`);return n}if(r)throw new Error(`Cannot convert ${typeof e} to number`);return e}function Jn(e,r){if(typeof e=="boolean")return e;if(typeof e=="string"){const t=e.toLowerCase();if(t==="true"||t==="1")return!0;if(t==="false"||t==="0")return!1;if(r)throw new Error(`Cannot convert "${e}" to boolean`)}if(typeof e=="number")return!!e;if(r)throw new Error(`Cannot convert ${typeof e} to boolean`);return e}function er(e,r,t){if(!Array.isArray(e)){if(typeof e=="string")return e.split(",").map(a=>a.trim()).filter(Boolean).map(a=>r==="integer"?Se(a,t):Ce(a,t));if(t)throw new Error(`Expected array, got ${typeof e}`);return e}return e.map((n,a)=>{try{return r==="integer"?Se(n,t):Ce(n,t)}catch(o){if(t)throw new Error(`Array element ${a}: ${o}`);return n}})}function Ar(){if(!document.getElementById("reactaform-styles"))try{const e=document.createElement("style");e.id="reactaform-styles",e.textContent=Br,document.head.appendChild(e)}catch{}}typeof document<"u"&&Ar();exports.CSS_CLASSES=R;exports.ReactaForm=An;exports.ReactaFormProvider=Mr;exports.ReactaFormRenderer=Er;exports.StandardFieldLayout=P;exports.Units=It;exports.combineClasses=B;exports.createInstanceFromDefinition=Vr;exports.deserializeDefinition=Kn;exports.deserializeInstance=Un;exports.getAllPlugins=Ln;exports.getComponent=Ae;exports.getPlugin=On;exports.getSupportedLanguages=Kt;exports.hasPlugin=Tn;exports.injectReactaFormStyles=Ar;exports.isDarkTheme=ce;exports.loadInstance=Vn;exports.loadJsonDefinition=Mn;exports.registerComponent=$e;exports.registerComponents=Hn;exports.registerFieldCustomValidationHandler=ur;exports.registerFieldTypeValidationHandler=mr;exports.registerFormValidationHandler=lr;exports.registerPlugin=Pn;exports.registerSubmissionHandler=ze;exports.serializeDefinition=_n;exports.serializeInstance=Bn;exports.unregisterPlugin=zn;exports.upgradeInstanceToLatestDefinition=Rn;exports.useDebouncedCallback=nr;exports.useFieldValidator=z;exports.useReactaFormContext=O;exports.useUncontrolledValidatedInput=W;exports.validateFieldValue=Gr;exports.validateFieldWithCustomHandler=Ne;
|
|
311
|
+
</svg>")`},textarea:{...r,minHeight:"80px",resize:"vertical",paddingTop:"var(--reactaform-space-sm, 8px)"},error:{color:"var(--reactaform-color-error)",fontSize:"0.875rem",marginTop:"var(--reactaform-space-xs, 4px)",display:"block"}}},Mr=({children:e,definitionName:r="",defaultStyle:t,defaultLanguage:n="en",defaultTheme:a="light",defaultLocalizeName:o="",defaultFieldValidationMode:c="realTime",className:s="reactaform-container"})=>{const i=r,m=o,l=a,d=n,p=u.useMemo(()=>t??{},[t]),[g,S]=u.useState({}),[N,b]=u.useState({});u.useEffect(()=>{let x=!0;return(async()=>{if(d==="en"){x&&(S({}),b({}));return}try{const y=await Jt(d),C=y.success?y.translations:{};x&&S(C);const k=await Yt(d,m),j=k.success?k.translations:{};x&&b(j)}catch{x&&(S({}),b({}))}})(),()=>{x=!1}},[d,m]);const v=u.useMemo(()=>Nn(p),[p]),I=u.useMemo(()=>Fn(p),[p]),R=u.useMemo(()=>Zt(d,g,N),[d,g,N]),M=u.useCallback((x,...h)=>R(x,...h),[R]),w=u.useMemo(()=>({definitionName:i,language:d,theme:l,formStyle:v,fieldStyle:I,t:M,fieldValidationMode:c}),[i,d,l,I,v,M,c]),F=p?.height?{height:"100%"}:void 0;return f.jsx(ke.Provider,{value:w,children:f.jsx("div",{"data-reactaform-theme":l,className:s,style:F,children:e})})};function In(e){if(!e||typeof e!="object")return"Definition must be an object";const r=e;if(!r.name||typeof r.name!="string")return"Definition must include a 'name' string";if(r.name.trim()==="")return"Definition 'name' cannot be empty";if(!r.version||typeof r.version!="string")return"Definition must include a 'version' string";if(r.properties!==void 0&&!Array.isArray(r.properties))return"'properties' must be an array if provided";if(Array.isArray(r.properties))for(let t=0;t<r.properties.length;t++){const n=r.properties[t];if(!n||typeof n!="object")return`Property at index ${t} must be an object`;if(!n.name||typeof n.name!="string")return`Property at index ${t} must have a string 'name'`;if(n.name.trim()==="")return`Property at index ${t} has an empty 'name'`;if(!n.type||typeof n.type!="string")return`Property '${n.name}' must have a string 'type'`;if(n.type.trim()==="")return`Property '${n.name}' has an empty 'type'`}return null}async function Mn(e,r={}){const{validateSchema:t=!0}=r;try{if(!e||typeof e!="string")return{success:!1,error:"jsonData must be a non-empty JSON string"};const n=e.trim();if(!n)return{success:!1,error:"jsonData is empty"};let a;try{a=JSON.parse(n)}catch(o){return{success:!1,error:`Invalid JSON format: ${o instanceof Error?o.message:"Unknown parsing error"}`}}if(t){const o=In(a);if(o)return{success:!1,error:`Schema validation failed: ${o}`}}return{success:!0,definition:a}}catch(n){return{success:!1,error:`Unexpected error loading definition: ${n instanceof Error?n.message:"Unknown error"}`}}}function Vr(e,r){try{if(!e)return{success:!1,error:"Definition is required"};if(!r||typeof r!="string")return{success:!1,error:"Instance name is required"};const t={name:r,definition:e.name??"unknown",version:e.version??"1.0.0",values:{}},n=e.properties||[];return Array.isArray(n)&&n.forEach(a=>{const o=a;if(o.type==="unit"){const c=o.defaultUnit,s=Number(o.defaultValue)||void 0;t.values[o.name]=[s||0,c||"m"]}else o.defaultValue!==void 0&&(t.values[o.name]=o.defaultValue)}),{success:!0,instance:t}}catch(t){return{success:!1,error:`Error creating instance: ${t instanceof Error?t.message:"Unknown error"}`}}}function Vn(e){try{if(!e)return{success:!1,error:"Instance data is required"};let r;if(typeof e=="string")try{r=JSON.parse(e)}catch(t){return{success:!1,error:`Invalid JSON format: ${t instanceof Error?t.message:"Unknown parsing error"}`}}else r=e;return typeof r!="object"||r===null?{success:!1,error:"Instance must be a valid object"}:{success:!0,instance:r}}catch(r){return{success:!1,error:`Error loading instance: ${r instanceof Error?r.message:"Unknown error"}`}}}function Rn(e,r,t){try{if(!e)return{success:!1,error:"Instance is required"};if(!r)return{success:!1,error:"Latest definition is required"};if(e.definition===r.name&&e.version===r.version)return{success:!0,instance:e};const n={name:e.name||r.name+"-instance",definition:r.name,version:r.version,values:{}},a=n.values,o={};(r.properties||[]).forEach(i=>{o[i.name]=i});const c=(i,m,l)=>{if(i==null)return i;const d=m.toLowerCase();try{if(d==="string"||d==="text")return String(i);if(d==="int"||d==="integer"||d==="number"||d==="float"){if(typeof i=="number")return i;if(typeof i=="boolean")return i?1:0;if(typeof i=="string"){const p=i.trim();if(p==="")return null;const g=Number(p);return Number.isNaN(g)?0:g}return 0}if(d==="boolean"||d==="bool"||d==="checkbox"||d==="switch"){if(typeof i=="boolean")return i;if(typeof i=="number")return i!==0;if(typeof i=="string"){const p=i.toLowerCase().trim();return["true","1","yes","on"].includes(p)}return!!i}if(d==="unit"){if(Array.isArray(i)&&i.length>=2)return i;if(Array.isArray(i)&&i.length===1)return[i[0],l&&l.defaultUnit||"m"];if(typeof i=="number")return[i,l&&l.defaultUnit||"m"];if(typeof i=="string"){const p=Number(i);return[Number.isNaN(p)?0:p,l&&l.defaultUnit||"m"]}return[0,l&&l.defaultUnit||"m"]}if(d.endsWith("[]")||d==="array"||d==="int-array"||d==="float-array")return Array.isArray(i)?i:typeof i=="string"?i.split(",").map(p=>p.trim()).filter(Boolean):[i]}catch{}return i},s=e.values||{};Object.keys(s).forEach(i=>{const m=s[i],l=o[i];if(!l)return;const d=Array.isArray(m)?"array":m===null?"null":typeof m,p=(l.type||"").toLowerCase();d===p||p==="string"&&typeof m=="string"?a[i]=m:a[i]=c(m,p,l)}),(r.properties||[]).forEach(i=>{const m=i.name;m in a||(a[m]=i.defaultValue)});try{typeof t=="function"&&t?.(e,n,r)}catch(i){return{success:!1,error:`Upgrade callback error: ${i instanceof Error?i.message:String(i)}`}}return{success:!0,instance:n}}catch(n){return{success:!1,error:`Error upgrading instance: ${n instanceof Error?n.message:"Unknown error"}`}}}function $n(e){const[r,t]=u.useState(null);return u.useEffect(()=>{const n=document.querySelector("[data-reactaform-theme]");if(!n)return;const a=n.closest("[data-reactaform-theme]");if(!a)return;const o=()=>t(a.getAttribute("data-reactaform-theme"));o();const c=new MutationObserver(s=>{for(const i of s)i.type==="attributes"&&i.attributeName==="data-reactaform-theme"&&o()});return c.observe(a,{attributes:!0,attributeFilter:["data-reactaform-theme"]}),()=>c.disconnect()},[e]),r}const An=({definitionData:e,instance:r,language:t,className:n,theme:a,style:o,fieldValidationMode:c="realTime"})=>{const s=u.useMemo(()=>{try{return typeof e=="string"?JSON.parse(e):e??null}catch{return null}},[e]),i={fontSize:"inherit",fontFamily:"inherit",...o},m=$n(),l=a??m??"light",d=t??"en";u.useEffect(()=>{let g=document.getElementById("popup-root");g||(g=document.createElement("div"),g.id="popup-root",document.body.appendChild(g))},[]);const p=u.useMemo(()=>{if(r)return r;if(!s)return null;const g=Vr(s,s.name);return!g.success||!g.instance?null:g.instance},[r,s]);return s?p?f.jsx(Mr,{definitionName:s.name,defaultStyle:i,defaultLanguage:d,defaultTheme:l,defaultLocalizeName:s.localization||"",className:n,defaultFieldValidationMode:c,children:f.jsx(Er,{definition:s,instance:p})}):f.jsx("div",{style:{color:"red"},children:"Error: Failed to create instance from definition."}):f.jsx("div",{style:{color:"red"},children:"Error: No form definition provided."})},Z=new Map,U={components:new Map,fieldValidators:new Map,fieldTypeValidators:new Map,formValidators:new Map,submissionHandlers:new Map};function Rr(e,r,t){if(!e)return!0;if(t&&!t(e))return!1;switch(r){case"error":throw new Error(`Plugin conflict: "${e.newPlugin}" tried to register ${e.type} "${e.name}" already registered by "${e.existingPlugin}"`);case"warn":return console.warn(`Plugin conflict: "${e.newPlugin}" tried to register ${e.type} "${e.name}" already registered by "${e.existingPlugin}". Skipping.`),!1;case"override":return console.info(`Plugin "${e.newPlugin}" is overriding ${e.type} "${e.name}" previously registered by "${e.existingPlugin}"`),!0;case"skip":return!1}}function Dn(e){const r=[];if(e.components){for(const t of Object.keys(e.components))if(Ae(t)){const a=U.components.get(t);a&&a!==e.name&&r.push({type:"component",name:t,existingPlugin:a,newPlugin:e.name})}}if(e.fieldCustomValidators)for(const[t,n]of Object.entries(e.fieldCustomValidators))for(const a of Object.keys(n)){const c=U.fieldValidators.get(t)?.get(a);fr(t,a)&&c&&c!==e.name&&r.push({type:"fieldCustomValidator",name:`${t}:${a}`,existingPlugin:c,newPlugin:e.name})}if(e.fieldTypeValidators)for(const t of Object.keys(e.fieldTypeValidators)){const n=pr(t),a=U.fieldTypeValidators.get(t);n&&a&&a!==e.name&&r.push({type:"fieldTypeValidator",name:`type:${t}`,existingPlugin:a,newPlugin:e.name})}if(e.formValidators)for(const t of Object.keys(e.formValidators)){const n=dr(t),a=U.formValidators.get(t);n&&a&&a!==e.name&&r.push({type:"formValidator",name:t,existingPlugin:a,newPlugin:e.name})}if(e.submissionHandlers)for(const t of Object.keys(e.submissionHandlers)){const n=Ut(t),a=U.submissionHandlers.get(t);n&&a&&a!==e.name&&r.push({type:"submissionHandler",name:t,existingPlugin:a,newPlugin:e.name})}return r}function se(e,r,t,n,a,o,c,s){for(const i of Object.keys(e)){let m;if(s?m=a.find(l=>l.type==="fieldCustomValidator"&&l.name===`${s}:${i}`):e===n.components?m=a.find(l=>l.type==="component"&&l.name===i):e===n.formValidators?m=a.find(l=>l.type==="formValidator"&&l.name===i):e===n.fieldTypeValidators?m=a.find(l=>l.type==="fieldTypeValidator"&&l.name===`type:${i}`):e===n.submissionHandlers&&(m=a.find(l=>l.type==="submissionHandler"&&l.name===i)),Rr(m||null,o,c))if(s){const l=r.get(s)||new Map;l.set(i,n.name),r.set(s,l),t(i,e[i])}else r.set(i,n.name),t(i,e[i])}}function Pn(e,r){const t=r?.conflictResolution||"error";if(Z.has(e.name)){const a={type:"plugin",name:e.name,existingPlugin:e.name,newPlugin:e.name};if(!Rr(a,t,r?.onConflict))return}const n=Dn(e);if(e.components&&se(e.components,U.components,$e,e,n,t,r?.onConflict),e.fieldCustomValidators)for(const[a,o]of Object.entries(e.fieldCustomValidators))se(o,U.fieldValidators,(c,s)=>ur(a,c,s),e,n,t,r?.onConflict,a);e.formValidators&&se(e.formValidators,U.formValidators,lr,e,n,t,r?.onConflict),e.fieldTypeValidators&&se(e.fieldTypeValidators,U.fieldTypeValidators,mr,e,n,t,r?.onConflict),e.submissionHandlers&&se(e.submissionHandlers,U.submissionHandlers,ze,e,n,t,r?.onConflict),e.setup&&e.setup(),Z.set(e.name,e)}function zn(e,r=!1){const t=Z.get(e);if(!t)return!1;if(t.cleanup&&t.cleanup(),r){if(t.components)for(const n of Object.keys(t.components))U.components.delete(n);if(t.fieldCustomValidators)for(const[n,a]of Object.entries(t.fieldCustomValidators)){const o=U.fieldValidators.get(n);if(o){for(const c of Object.keys(a))o.delete(c);o.size===0&&U.fieldValidators.delete(n)}}if(t.formValidators)for(const n of Object.keys(t.formValidators))U.formValidators.delete(n);if(t.fieldTypeValidators)for(const n of Object.keys(t.fieldTypeValidators))U.fieldTypeValidators.delete(n);if(t.submissionHandlers)for(const n of Object.keys(t.submissionHandlers))U.submissionHandlers.delete(n)}return Z.delete(e),!0}function On(e){return Z.get(e)}function Ln(){return Array.from(Z.values())}function Tn(e){return Z.has(e)}function Hn(e){for(const[r,t]of Object.entries(e))$e(r,t)}function Q(e){return typeof e=="object"&&e!==null}function Le(e){if(!Q(e))return!1;const r=e;return typeof r.name=="string"&&typeof r.displayName=="string"}function $r(e){if(!Q(e))return!1;const r=e;return typeof r.name!="string"||typeof r.version!="string"||!Array.isArray(r.properties)?!1:r.properties.every(t=>Le(t))}function we(e){try{return typeof File<"u"&&e instanceof File}catch{const r=Q(e)?e:void 0;return!!r&&typeof r.name=="string"&&typeof r.size=="number"}}function Bn(e,r,t={}){try{const{includeMetadata:n=!1,dateFormat:a="iso",fileHandling:o="metadata",prettify:c=!1,excludeFields:s=[],includeOnlyFields:i=[]}=t;if(!e||typeof e!="object")return{success:!1,error:"Instance must be a valid object"};const m=[],l=[],d={},g=($r(r)||Q(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Le),S=new Map(g.map(b=>[b.name,b]));for(const[b,v]of Object.entries(e)){if(s.includes(b)){l.push(b);continue}if(i.length>0&&!i.includes(b)){l.push(b);continue}if(v===void 0)continue;const I=S.get(b);try{d[b]=qn(v,I,{dateFormat:a,fileHandling:o})}catch(R){m.push(`Error serializing field '${b}': ${String(R)}`),d[b]=null}}return n&&(d._metadata={serializedAt:new Date().toISOString(),version:(Q(r)?r.version:void 0)||"1.0.0",fieldCount:Object.keys(d).length-1}),{success:!0,data:c?JSON.stringify(d,null,2):JSON.stringify(d),metadata:{fieldCount:Object.keys(d).length,excludedFields:l,warnings:m}}}catch(n){return{success:!1,error:`Serialization failed: ${n instanceof Error?n.message:"Unknown error"}`}}}function qn(e,r,t={}){const{dateFormat:n="iso",fileHandling:a="metadata"}=t;if(e==null)return null;if(r)switch(r.type){case"date":case"datetime":case"date-time":return Xe(e,n);case"file":return Ze(e,a);case"int":case"integer":return typeof e=="string"?parseInt(e,10):e;case"float":case"number":return typeof e=="string"?parseFloat(e):e;case"boolean":return typeof e=="string"?e==="true":!!e;case"int-array":case"float-array":return Array.isArray(e)?e.map(o=>typeof o=="string"?Number(o):o):e;default:return e}return e instanceof Date?Xe(e,n):we(e)||Array.isArray(e)&&we(e[0])?Ze(e,a):e}function Xe(e,r){let t=null;if(e instanceof Date)t=e;else if(typeof e=="string"){const n=new Date(e);if(!isNaN(n.getTime()))t=n;else return e}else return e;switch(r){case"timestamp":return t.getTime();case"locale":return t.toLocaleString();case"iso":default:return t.toISOString()}}function Ze(e,r){return r==="skip"?null:Array.isArray(e)?e.map(t=>Qe(t,r)):Qe(e,r)}function Qe(e,r){if(!we(e))return e;const t=e;return r==="metadata"?{name:t.name,size:t.size,type:t.type,lastModified:t.lastModified}:{name:t.name,size:t.size,type:t.type,lastModified:t.lastModified,_note:"Base64 encoding requires async implementation"}}function Un(e,r,t={}){try{const{strict:n=!1,validateTypes:a=!0,preserveUnknownFields:o=!0,dateFormat:c="auto"}=t;if(!e||typeof e!="string")return{success:!1,error:"Serialized data must be a non-empty string"};let s;try{s=JSON.parse(e)}catch(N){return{success:!1,error:`Invalid JSON: ${N instanceof Error?N.message:"Unknown parsing error"}`}}if(!s||typeof s!="object")return{success:!1,error:"Parsed data must be an object"};const i=[],m=[],l={},p=($r(r)||Q(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Le),g=new Map(p.map(N=>[N.name,N]));for(const N of p){const b=N.name,v=s[b];if(v===void 0){n&&N.required&&m.push(`Required field '${b}' is missing`);continue}try{l[b]=Wn(v,N,{validateTypes:a,dateFormat:c})}catch(I){const R=`Error deserializing field '${b}': ${String(I)}`;n?m.push(R):(i.push(R),l[b]=v)}}if(o)for(const[N,b]of Object.entries(s))!g.has(N)&&N!=="_metadata"&&(n&&i.push(`Unknown field '${N}' preserved`),l[N]=b);const S=m.length>0;return{success:!S,data:l,warnings:i.length>0?i:void 0,validationErrors:S?m:void 0}}catch(n){return{success:!1,error:`Deserialization failed: ${n instanceof Error?n.message:"Unknown error"}`}}}function Wn(e,r,t={}){const{validateTypes:n=!0,dateFormat:a="auto"}=t;if(e==null)return e;try{switch(r.type){case"date":case"datetime":case"date-time":return Gn(e,a,n);case"int":case"integer":return Se(e,n);case"float":case"number":return Ce(e,n);case"boolean":return Jn(e,n);case"int-array":return er(e,"integer",n);case"float-array":return er(e,"number",n);case"string":case"text":case"email":case"url":case"phone":return n?String(e):e;default:return e}}catch(o){if(n)throw new Error(`Type conversion failed: ${String(o)}`);return e}}function _n(e,r={}){try{const{prettify:t=!0,includeMetadata:n=!0}=r;if(!e||typeof e!="object")return{success:!1,error:"Definition must be a valid object"};const a={...e};return n&&(a._metadata={serializedAt:new Date().toISOString(),version:a.version||"1.0.0",propertyCount:(Array.isArray(a.properties)?a.properties.length:0)||0}),{success:!0,data:t?JSON.stringify(a,null,2):JSON.stringify(a),metadata:{fieldCount:(Array.isArray(a.properties)?a.properties.length:0)||0,excludedFields:[],warnings:[]}}}catch(t){return{success:!1,error:`Definition serialization failed: ${t instanceof Error?t.message:"Unknown error"}`}}}function Kn(e,r={}){try{const{strict:t=!1,validateTypes:n=!0}=r;let a;if(typeof e=="string")try{a=JSON.parse(e)}catch(l){return{success:!1,error:`Invalid JSON for definition: ${l instanceof Error?l.message:"Unknown parsing error"}`}}else if(e&&typeof e=="object")a={...e};else return{success:!1,error:"Input must be a string or object"};const o=[],c=[],s=["name","version","displayName"];for(const l of s)if(!(l in a)||!a[l])if(t)c.push(`Required field '${l}' is missing`);else switch(o.push(`Missing field '${l}', using default`),l){case"name":a.name="unnamed-definition";break;case"version":a.version="1.0.0";break;case"displayName":a.displayName=a.name||"Unnamed Definition";break}const i=Array.isArray(a.properties)?a.properties:null;i?a.properties=i.map((l,d)=>{const p=Q(l)?l:{},g={...p};if(!p.name){const S=`Property at index ${d} missing 'name'`;t?c.push(S):(o.push(`${S}, using 'field_${d}'`),g.name=`field_${d}`)}return p.displayName||(g.displayName=p.name||`Field ${d}`),p.type||(t&&n?c.push(`Property '${p.name||d}' missing 'type'`):(o.push(`Property '${p.name||d}' missing 'type', using 'string'`),g.type="string")),p.defaultValue===void 0&&(g.defaultValue=null),p.required===void 0&&(g.required=!1),g}):t?c.push("Properties must be an array"):(o.push("Properties not found or invalid, using empty array"),a.properties=[]);const m=c.length>0;return{success:!m,data:a,warnings:o.length>0?o:void 0,validationErrors:m?c:void 0}}catch(t){return{success:!1,error:`Definition deserialization failed: ${t instanceof Error?t.message:"Unknown error"}`}}}function Gn(e,r,t){if(e instanceof Date)return e;if(typeof e=="number"){const n=new Date(e);if(t&&isNaN(n.getTime()))throw new Error(`Invalid timestamp: ${e}`);return n}if(typeof e=="string"){const n=new Date(e);if(t&&isNaN(n.getTime()))throw new Error(`Invalid date string: ${e}`);return n}if(t)throw new Error(`Cannot convert ${typeof e} to Date`);return e}function Se(e,r){if(typeof e=="number"){if(Number.isInteger(e))return e;if(r)throw new Error(`Number ${e} is not an integer`);return Math.floor(e)}if(typeof e=="string"){const t=e.trim();if(t===""){if(r)throw new Error("Cannot convert empty string to integer");return e}const n=parseInt(t,10);if(r&&isNaN(n))throw new Error(`Cannot convert "${e}" to integer`);return n}if(r)throw new Error(`Cannot convert ${typeof e} to integer`);return e}function Ce(e,r){if(typeof e=="number"){if(r&&!isFinite(e))throw new Error(`Number ${e} is not finite`);return e}if(typeof e=="string"){const t=e.trim();if(t===""){if(r)throw new Error("Cannot convert empty string to number");return e}const n=parseFloat(t);if(r&&(isNaN(n)||!isFinite(n)))throw new Error(`Cannot convert "${e}" to number`);return n}if(r)throw new Error(`Cannot convert ${typeof e} to number`);return e}function Jn(e,r){if(typeof e=="boolean")return e;if(typeof e=="string"){const t=e.toLowerCase();if(t==="true"||t==="1")return!0;if(t==="false"||t==="0")return!1;if(r)throw new Error(`Cannot convert "${e}" to boolean`)}if(typeof e=="number")return!!e;if(r)throw new Error(`Cannot convert ${typeof e} to boolean`);return e}function er(e,r,t){if(!Array.isArray(e)){if(typeof e=="string")return e.split(",").map(a=>a.trim()).filter(Boolean).map(a=>r==="integer"?Se(a,t):Ce(a,t));if(t)throw new Error(`Expected array, got ${typeof e}`);return e}return e.map((n,a)=>{try{return r==="integer"?Se(n,t):Ce(n,t)}catch(o){if(t)throw new Error(`Array element ${a}: ${o}`);return n}})}function Ar(){if(!document.getElementById("reactaform-styles"))try{const e=document.createElement("style");e.id="reactaform-styles",e.textContent=Br,document.head.appendChild(e)}catch{}}typeof document<"u"&&Ar();exports.CSS_CLASSES=V;exports.ReactaForm=An;exports.ReactaFormProvider=Mr;exports.ReactaFormRenderer=Er;exports.StandardFieldLayout=P;exports.Units=It;exports.combineClasses=B;exports.createInstanceFromDefinition=Vr;exports.deserializeDefinition=Kn;exports.deserializeInstance=Un;exports.getAllPlugins=Ln;exports.getComponent=Ae;exports.getPlugin=On;exports.getSupportedLanguages=Kt;exports.hasPlugin=Tn;exports.injectReactaFormStyles=Ar;exports.isDarkTheme=ce;exports.loadInstance=Vn;exports.loadJsonDefinition=Mn;exports.registerComponent=$e;exports.registerComponents=Hn;exports.registerFieldCustomValidationHandler=ur;exports.registerFieldTypeValidationHandler=mr;exports.registerFormValidationHandler=lr;exports.registerPlugin=Pn;exports.registerSubmissionHandler=ze;exports.serializeDefinition=_n;exports.serializeInstance=Bn;exports.unregisterPlugin=zn;exports.upgradeInstanceToLatestDefinition=Rn;exports.useDebouncedCallback=nr;exports.useFieldValidator=z;exports.useReactaFormContext=O;exports.useUncontrolledValidatedInput=W;exports.validateFieldValue=Gr;exports.validateFieldWithCustomHandler=Ne;
|