reactaform 1.5.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common-Awfy-0XP.js +1 -0
- package/dist/{common-DRxsgpaH.mjs → common-BZgeDhcm.mjs} +40 -15
- package/dist/common-BmlrZtLZ.js +1 -0
- package/dist/common-CBecOKIA.mjs +123 -0
- package/dist/{common-CTK4jqc5.mjs → common-CsY8BnXg.mjs} +58 -33
- package/dist/common-D8L4oP0c.js +1 -0
- package/dist/common-DnEDu-7h.mjs +123 -0
- package/dist/common-udunqMU-.js +1 -0
- package/dist/components/LayoutComponents.d.ts +77 -0
- package/dist/components/PopupOptionMenu.d.ts +16 -0
- package/dist/components/ReactaForm.d.ts +4 -0
- package/dist/components/ReactaFormProvider.d.ts +5 -0
- package/dist/components/ReactaFormRenderer.d.ts +10 -0
- package/dist/components/SubmissionButton.d.ts +8 -0
- package/dist/components/SubmissionMessage.d.ts +7 -0
- package/dist/components/Tooltip.d.ts +8 -0
- package/dist/components/fields/CheckboxInput.d.ts +5 -0
- package/dist/components/fields/ColorInput.d.ts +13 -0
- package/dist/components/fields/DateInput.d.ts +11 -0
- package/dist/components/fields/DropdownInput.d.ts +16 -0
- package/dist/components/fields/EmailInput.d.ts +5 -0
- package/dist/components/fields/FileInput.d.ts +5 -0
- package/dist/components/fields/FloatArrayInput.d.ts +8 -0
- package/dist/components/fields/FloatInput.d.ts +9 -0
- package/dist/components/fields/ImageDisplay.d.ts +18 -0
- package/dist/components/fields/IntegerArrayInput.d.ts +9 -0
- package/dist/components/fields/IntegerInput.d.ts +6 -0
- package/dist/components/fields/MultiSelection.d.ts +9 -0
- package/dist/components/fields/MultilineTextInput.d.ts +6 -0
- package/dist/components/fields/NumericStepperInput.d.ts +6 -0
- package/dist/components/fields/PasswordInput.d.ts +6 -0
- package/dist/components/fields/PhoneInput.d.ts +6 -0
- package/dist/components/fields/RadioInput.d.ts +8 -0
- package/dist/components/fields/RatingInput.d.ts +9 -0
- package/dist/components/fields/Separator.d.ts +21 -0
- package/dist/components/fields/SliderInput.d.ts +5 -0
- package/dist/components/fields/SpinInput.d.ts +5 -0
- package/dist/components/fields/SwitchInput.d.ts +8 -0
- package/dist/components/fields/TextInput.d.ts +8 -0
- package/dist/components/fields/TimeInput.d.ts +6 -0
- package/dist/components/fields/UnitValueInput.d.ts +5 -0
- package/dist/components/fields/UrlInput.d.ts +9 -0
- package/dist/components/renderFields.d.ts +3 -0
- package/dist/core/baseRegistry.d.ts +15 -0
- package/dist/core/componentRegistry.d.ts +15 -0
- package/dist/core/env.d.ts +1 -0
- package/dist/core/fieldVisibility.d.ts +25 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/pluginRegistry.d.ts +45 -0
- package/dist/core/reactaFormModel.d.ts +31 -0
- package/dist/core/reactaFormTypes.d.ts +148 -0
- package/dist/core/submissionHandlerRegistry.d.ts +7 -0
- package/dist/core/submitForm.d.ts +9 -0
- package/dist/hooks/useDebouncedCallback.d.ts +27 -0
- package/dist/hooks/useDropdownPosition.d.ts +6 -0
- package/dist/hooks/useFieldValidator.d.ts +2 -0
- package/dist/hooks/useReactaFormContext.d.ts +4 -0
- package/dist/hooks/useUncontrolledValidatedInput.d.ts +18 -0
- package/dist/hooks/useUnitValueField.d.ts +13 -0
- package/dist/index.d.ts +10 -9
- package/dist/reactaform.cjs.js +18 -5
- package/dist/reactaform.css +1 -1
- package/dist/reactaform.es.js +4346 -3991
- package/dist/utils/cssClasses.d.ts +14 -0
- package/dist/utils/definitionSerializers.d.ts +62 -0
- package/dist/utils/groupingHelpers.d.ts +24 -0
- package/dist/utils/themeUtils.d.ts +31 -0
- package/dist/utils/translationCache.d.ts +43 -0
- package/dist/utils/unitValueMapper.d.ts +14 -0
- package/dist/validation/registerBuiltinTypeValidators.d.ts +11 -0
- package/dist/validation/validateColorField.d.ts +2 -0
- package/dist/validation/validateDateField.d.ts +2 -0
- package/dist/validation/validateEmailField.d.ts +2 -0
- package/dist/validation/validateFieldPattern.d.ts +3 -0
- package/dist/validation/validateFileField.d.ts +2 -0
- package/dist/validation/validateFloatField.d.ts +3 -0
- package/dist/validation/validateIntegerField.d.ts +3 -0
- package/dist/validation/validatePhoneField.d.ts +2 -0
- package/dist/validation/validateRatingField.d.ts +2 -0
- package/dist/validation/validateSelectionFields.d.ts +3 -0
- package/dist/validation/validateTextField.d.ts +2 -0
- package/dist/validation/validateTimeField.d.ts +2 -0
- package/dist/validation/validateUnitValueField.d.ts +2 -0
- package/dist/validation/validateUrlField.d.ts +2 -0
- package/dist/validation/validation.d.ts +12 -0
- package/dist/validation/validationHandlerRegistry.d.ts +20 -0
- package/package.json +14 -34
- package/dist/common-BeJOG7Z0.js +0 -1
- package/dist/common-Crb-me6O.js +0 -1
- package/dist/common-DINaqn4M.mjs +0 -98
- package/dist/common-DLr0UoG9.js +0 -1
- package/dist/common-DRIndE7S.js +0 -1
- package/dist/common-DXEjsP3o.mjs +0 -98
package/dist/reactaform.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),J=require("react"),Tr=require("react-dom");function rr(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const u=rr(J),fe=rr(Tr),Hr=`/* ReactaForm CSS Custom Properties (CSS Variables) */\r
|
|
2
2
|
\r
|
|
3
3
|
/* Default Light Theme */\r
|
|
4
4
|
:root {\r
|
|
@@ -214,6 +214,19 @@
|
|
|
214
214
|
box-sizing: border-box;\r
|
|
215
215
|
}\r
|
|
216
216
|
\r
|
|
217
|
+
.reactaform-chip {\r
|
|
218
|
+
display: flex;\r
|
|
219
|
+
align-items: center;\r
|
|
220
|
+
justify-content: space-between;\r
|
|
221
|
+
padding: 6px 10px;\r
|
|
222
|
+
background-color: var(--reactaform-input-bg);\r
|
|
223
|
+
border: 1px solid var(--reactaform-border-color);\r
|
|
224
|
+
border-radius: var(--reactaform-border-radius);\r
|
|
225
|
+
color: var(--reactaform-text-color);\r
|
|
226
|
+
font-size: 0.875rem;\r
|
|
227
|
+
gap: 8px;\r
|
|
228
|
+
}\r
|
|
229
|
+
\r
|
|
217
230
|
\r
|
|
218
231
|
\r
|
|
219
232
|
/* Responsive Design */\r
|
|
@@ -284,9 +297,9 @@
|
|
|
284
297
|
\r
|
|
285
298
|
\r
|
|
286
299
|
}\r
|
|
287
|
-
`,Ee=K.createContext(void 0),V=()=>{const e=K.useContext(Ee);if(!e)throw new Error("❌ useReactaFormContext must be used within a <ReactaFormProvider>");return e};class me{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,o])=>{t&&typeof t=="string"&&this.register(t,o)}):r&&typeof r=="object"&&Object.entries(r).forEach(([t,o])=>{t&&typeof t=="string"&&this.register(t,o)})}getOrDefault(r,t){const o=this.get(r);return o!==void 0?o:t}}function Ze(e,r=300,t){const o=K.useRef(void 0),n=K.useRef(e),a=K.useRef(null),u=K.useRef(!1);K.useEffect(()=>{n.current=e},[e]),K.useEffect(()=>()=>{o.current!==void 0&&(window.clearTimeout(o.current),o.current=void 0)},[]);const c=K.useCallback(()=>{o.current!==void 0&&(window.clearTimeout(o.current),o.current=void 0),a.current=null,u.current=!1},[]),s=K.useCallback(()=>{if(o.current!==void 0&&(window.clearTimeout(o.current),o.current=void 0),a.current)try{n.current(...a.current)}finally{a.current=null,u.current=!1}},[]);return{callback:K.useCallback((...l)=>{if(t?.leading===!0&&!u.current){u.current=!0,n.current(...l),window.clearTimeout(o.current),o.current=window.setTimeout(()=>{u.current=!1,o.current=void 0},r);return}a.current=l,window.clearTimeout(o.current),o.current=window.setTimeout(()=>{o.current=void 0,a.current&&(n.current(...a.current),a.current=null,u.current=!1)},r)},[r,t?.leading]),cancel:c,flush:s}}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"},q=(...e)=>{const r=[];for(const t of e)t&&(typeof t=="string"?r.push(t):typeof t=="object"&&Object.entries(t).forEach(([o,n])=>{n&&r.push(o)}));return r.join(" ")};function de(e){return e.toLowerCase().includes("dark")}const Qe=({content:e,size:r="medium",animation:t=!0})=>{const{t:o,theme:n,formStyle:a,fieldStyle:u}=V(),[c,s]=i.useState(!1),[d,l]=i.useState({x:0,y:0}),[m,f]=i.useState(!1),p=i.useRef(null),y=i.useRef(null),h=i.useRef(null),b=i.useId(),v=de(n),x=i.useMemo(()=>{const k={icon:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"1.2em",height:"1.2em",fontSize:"0.9em",fontWeight:"bold",borderRadius:"50%",backgroundColor:v?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.06)",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"}},S=(j,M,$)=>{const z=j?.[M];return($&&z?z[$]:void 0)??{}};return{icon:{...k.icon,...S(a,"tooltip","icon"),...S(u,"tooltip","icon")},text:{...k.text,...S(a,"tooltip","text"),...S(u,"tooltip","text")},textVisible:k.textVisible}},[v,r,t,a,u]);i.useLayoutEffect(()=>{if(!c||!p.current||!y.current){f(!1);return}const w=p.current.getBoundingClientRect();h.current=w;const k=y.current.getBoundingClientRect(),S=8,N=window.innerWidth,j=window.innerHeight,M=-4;let $=w.right+S,E=w.top+w.height/2-k.height/2+M;$+k.width>N-S&&($=w.left-S-k.width),$=Math.max(S,Math.min($,N-k.width-S)),E=Math.max(S,Math.min(E,j-k.height-S)),l({x:$,y:E}),f(!0);const z=p.current.closest("[data-reactaform-theme]"),B=document.getElementById("popup-root");if(z&&B){const re=getComputedStyle(z);B.style.setProperty("--reactaform-tooltip-color-bg",re.getPropertyValue("--reactaform-tooltip-color-bg")),B.style.setProperty("--reactaform-tooltip-color",re.getPropertyValue("--reactaform-tooltip-color"))}},[c]);const C=typeof document<"u"?document.getElementById("popup-root"):null,A=g.jsx("div",{ref:y,"data-tooltip-id":b,style:{...x.text,transform:m?"translateY(0) scale(1)":"translateY(-4px) scale(0.98)",transition:"opacity 120ms ease, transform 120ms ease, visibility 120ms ease",width:240,...m?x.textVisible:{},top:d.y,left:d.x},children:o(e)});return g.jsxs(g.Fragment,{children:[g.jsx("span",{"data-testid":"tooltip-icon",ref:p,"aria-describedby":c?b:void 0,onMouseEnter:()=>s(!0),onMouseLeave:()=>s(!1),style:{...x.icon},children:"?"}),c&&(C?ke.createPortal(A,C):A)]})},ve=i.memo(({field:e,error:r,children:t,showLabel:o=!0})=>{const{t:n}=V(),a=e?.labelLayout==="column-center"?"center":"left";return g.jsxs("div",{className:`${R.field} column-layout`,style:{display:"flex",flexDirection:"column",gap:"var(--reactaform-label-gap, 4px)","--label-align":a},children:[o&&g.jsx("div",{style:{textAlign:a,width:"100%"},children:g.jsx("label",{id:`${e.name}-label`,className:R.label,htmlFor:e.name,style:{textAlign:a,width:"100%",minWidth:"unset",display:"block",marginBottom:"10px"},children:n(e.displayName)})}),g.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--reactaform-inline-gap, 8px)",width:"100%"},children:[g.jsx("div",{style:{flex:1,minWidth:0,maxWidth:"100%"},children:g.jsx("div",{style:{width:"100%"},children:t})}),e.tooltip&&g.jsx(Qe,{content:e.tooltip})]}),r&&g.jsx(Ne,{id:`${e.name}-error`,children:r})]})});ve.displayName="ColumnFieldLayout";const er=i.memo(({field:e,error:r,children:t,rightAlign:o=!1})=>{const{t:n}=V(),a=i.useMemo(()=>({display:"flex",flexDirection:"column",gap:0}),[]),u=i.useMemo(()=>({display:"flex",flexDirection:"row",alignItems:"center",gap:"3px"}),[]);return g.jsxs("div",{className:`${R.field} row-layout`,children:[g.jsx("label",{id:`${e.name}-label`,className:R.label,htmlFor:e.name,style:{textAlign:"left",justifyContent:"flex-start"},children:n(e.displayName)}),g.jsxs("div",{style:a,children:[g.jsxs("div",{style:u,children:[o?g.jsx("div",{style:{display:"flex",flex:1,justifyContent:"flex-end",alignItems:"center",gap:"var(--reactaform-inline-gap, 8px)"},children:t}):t,e.tooltip&&g.jsx(Qe,{content:e.tooltip})]}),r&&g.jsx(Ne,{id:`${e.name}-error`,children:r})]})]})});er.displayName="RowFieldLayout";const T=({field:e,error:r,children:t,rightAlign:o=!1})=>e.labelLayout==="column-left"||e.labelLayout==="column-center"?g.jsx(ve,{field:e,error:r,showLabel:!0,children:t}):e.type==="checkbox"||e.type==="switch"?g.jsx(ve,{field:e,error:r,showLabel:!1,children:t}):g.jsx(er,{field:e,error:r,rightAlign:o,children:t}),Ne=i.memo(({children:e,id:r})=>{const t=i.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 g.jsx("div",{id:r,style:t,children:e})});Ne.displayName="ErrorDiv";const rr=i.memo(({name:e,onChange:r})=>{const{t}=V();return g.jsxs("div",{style:{marginBottom:16},children:[g.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 2fr",gap:12,alignItems:"center"},children:[g.jsx("label",{htmlFor:"instance-name-input",style:{margin:0,fontSize:"0.95em",fontWeight:500,color:"var(--reactaform-text-color, #333)"},children:t("Instance Name")}),g.jsx("input",{id:"instance-name-input",type:"text",value:e,onChange:o=>r(o.target.value),style:{width:"100%",padding:"var(--reactaform-input-padding, 8px 12px)",fontSize:"var(--reactaform-input-font-size, 14px)",border:"1px solid var(--reactaform-input-border, #ddd)",borderRadius:"var(--reactaform-border-radius, 4px)",backgroundColor:"var(--reactaform-input-bg, #fff)",color:"var(--reactaform-text-color, #333)",boxSizing:"border-box"},placeholder:t("Enter instance name")})]}),g.jsx("div",{style:{height:"1px",backgroundColor:"var(--reactaform-separator, #e6e6e6)",marginTop:12,marginBottom:12}})]})});rr.displayName="InstanceName";class Er extends me{registerInCategory(r,t,o){this.get(r)||this.register(r,{});const n=this.get(r);n[t]=o}getFromCategory(r,t){return this.get(r)?.[t]}listFromCategory(r){return Object.keys(this.get(r)||{})}listCategories(){return this.list()}}const tr=new me,nr=new Er;function or(e,r){tr.register(e,r)}function ar(e,r,t){nr.registerInCategory(e,r,t)}function sr(e,r){return nr.getFromCategory(e,r)||null}function ir(e){return tr.get(e)||null}function Nr(e){return(typeof e=="object"||typeof e=="function")&&e!==null&&typeof e.then=="function"}const Te=new Map,He=new Map;function L(e,r,t,o){if(!r||!r.validationHandlerName)return null;let n,a;if(typeof r.validationHandlerName=="string")n=e,a=r.validationHandlerName;else if(Array.isArray(r.validationHandlerName)){const[s,d]=r.validationHandlerName;if(d)n=s,a=d;else if(s)n=e,a=s;else return null}else return null;const u=`${n}:${a}`;let c=Te.get(u);if(c===void 0&&(c=sr(n,a)||null,Te.set(u,c)),c)try{return c(r.name,t,o)||null}catch(s){return String(s instanceof Error?s.message:s)}return null}async function Ir(e,r,t){if(!e||typeof e.validationHandlerName!="string")return null;const o=e.validationHandlerName;let n=He.get(o);if(n===void 0&&(n=ir(o)||null,He.set(o,n)),n)try{const a=n(r,t);return Nr(a)?await a||null:a||null}catch(a){return[String(a instanceof Error?a.message:a)]}return null}function Q(e){return typeof e=="object"&&e!==null}function Ie(e){if(!Q(e))return!1;const r=e;return typeof r.name=="string"&&typeof r.displayName=="string"}function cr(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=>Ie(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 Mr(e,r,t={}){try{const{includeMetadata:o=!1,dateFormat:n="iso",fileHandling:a="metadata",prettify:u=!1,excludeFields:c=[],includeOnlyFields:s=[]}=t;if(!e||typeof e!="object")return{success:!1,error:"Instance must be a valid object"};const d=[],l=[],m={},p=(cr(r)||Q(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Ie),y=new Map(p.map(b=>[b.name,b]));for(const[b,v]of Object.entries(e)){if(c.includes(b)){l.push(b);continue}if(s.length>0&&!s.includes(b)){l.push(b);continue}if(v===void 0)continue;const x=y.get(b);try{m[b]=$r(v,x,{dateFormat:n,fileHandling:a})}catch(C){d.push(`Error serializing field '${b}': ${String(C)}`),m[b]=null}}return o&&(m._metadata={serializedAt:new Date().toISOString(),version:(Q(r)?r.version:void 0)||"1.0.0",fieldCount:Object.keys(m).length-1}),{success:!0,data:u?JSON.stringify(m,null,2):JSON.stringify(m),metadata:{fieldCount:Object.keys(m).length,excludedFields:l,warnings:d}}}catch(o){return{success:!1,error:`Serialization failed: ${o instanceof Error?o.message:"Unknown error"}`}}}function $r(e,r,t={}){const{dateFormat:o="iso",fileHandling:n="metadata"}=t;if(e==null)return null;if(r)switch(r.type){case"date":case"datetime":case"date-time":return qe(e,o);case"file":return Be(e,n);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(a=>typeof a=="string"?Number(a):a):e;default:return e}return e instanceof Date?qe(e,o):we(e)||Array.isArray(e)&&we(e[0])?Be(e,n):e}function qe(e,r){let t=null;if(e instanceof Date)t=e;else if(typeof e=="string"){const o=new Date(e);if(!isNaN(o.getTime()))t=o;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 Be(e,r){return r==="skip"?null:Array.isArray(e)?e.map(t=>Ue(t,r)):Ue(e,r)}function Ue(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 Vr(e,r,t={}){try{const{strict:o=!1,validateTypes:n=!0,preserveUnknownFields:a=!0,dateFormat:u="auto"}=t;if(!e||typeof e!="string")return{success:!1,error:"Serialized data must be a non-empty string"};let c;try{c=JSON.parse(e)}catch(h){return{success:!1,error:`Invalid JSON: ${h instanceof Error?h.message:"Unknown parsing error"}`}}if(!c||typeof c!="object")return{success:!1,error:"Parsed data must be an object"};const s=[],d=[],l={},f=(cr(r)||Q(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Ie),p=new Map(f.map(h=>[h.name,h]));for(const h of f){const b=h.name,v=c[b];if(v===void 0){o&&h.required&&d.push(`Required field '${b}' is missing`);continue}try{l[b]=Ar(v,h,{validateTypes:n,dateFormat:u})}catch(x){const C=`Error deserializing field '${b}': ${String(x)}`;o?d.push(C):(s.push(C),l[b]=v)}}if(a)for(const[h,b]of Object.entries(c))!p.has(h)&&h!=="_metadata"&&(o&&s.push(`Unknown field '${h}' preserved`),l[h]=b);const y=d.length>0;return{success:!y,data:l,warnings:s.length>0?s:void 0,validationErrors:y?d:void 0}}catch(o){return{success:!1,error:`Deserialization failed: ${o instanceof Error?o.message:"Unknown error"}`}}}function Ar(e,r,t={}){const{validateTypes:o=!0,dateFormat:n="auto"}=t;if(e==null)return e;try{switch(r.type){case"date":case"datetime":case"date-time":return zr(e,n,o);case"int":case"integer":return Se(e,o);case"float":case"number":return Ce(e,o);case"boolean":return Or(e,o);case"int-array":return We(e,"integer",o);case"float-array":return We(e,"number",o);case"string":case"text":case"email":case"url":case"phone":return o?String(e):e;default:return e}}catch(a){if(o)throw new Error(`Type conversion failed: ${String(a)}`);return e}}function Fr(e,r={}){try{const{prettify:t=!0,includeMetadata:o=!0}=r;if(!e||typeof e!="object")return{success:!1,error:"Definition must be a valid object"};const n={...e};return o&&(n._metadata={serializedAt:new Date().toISOString(),version:n.version||"1.0.0",propertyCount:(Array.isArray(n.properties)?n.properties.length:0)||0}),{success:!0,data:t?JSON.stringify(n,null,2):JSON.stringify(n),metadata:{fieldCount:(Array.isArray(n.properties)?n.properties.length:0)||0,excludedFields:[],warnings:[]}}}catch(t){return{success:!1,error:`Definition serialization failed: ${t instanceof Error?t.message:"Unknown error"}`}}}function Dr(e,r={}){try{const{strict:t=!1,validateTypes:o=!0}=r;let n;if(typeof e=="string")try{n=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")n={...e};else return{success:!1,error:"Input must be a string or object"};const a=[],u=[],c=["name","version","displayName"];for(const l of c)if(!(l in n)||!n[l])if(t)u.push(`Required field '${l}' is missing`);else switch(a.push(`Missing field '${l}', using default`),l){case"name":n.name="unnamed-definition";break;case"version":n.version="1.0.0";break;case"displayName":n.displayName=n.name||"Unnamed Definition";break}const s=Array.isArray(n.properties)?n.properties:null;s?n.properties=s.map((l,m)=>{const f=Q(l)?l:{},p={...f};if(!f.name){const y=`Property at index ${m} missing 'name'`;t?u.push(y):(a.push(`${y}, using 'field_${m}'`),p.name=`field_${m}`)}return f.displayName||(p.displayName=f.name||`Field ${m}`),f.type||(t&&o?u.push(`Property '${f.name||m}' missing 'type'`):(a.push(`Property '${f.name||m}' missing 'type', using 'string'`),p.type="string")),f.defaultValue===void 0&&(p.defaultValue=null),f.required===void 0&&(p.required=!1),p}):t?u.push("Properties must be an array"):(a.push("Properties not found or invalid, using empty array"),n.properties=[]);const d=u.length>0;return{success:!d,data:n,warnings:a.length>0?a:void 0,validationErrors:d?u:void 0}}catch(t){return{success:!1,error:`Definition deserialization failed: ${t instanceof Error?t.message:"Unknown error"}`}}}function zr(e,r,t){if(e instanceof Date)return e;if(typeof e=="number"){const o=new Date(e);if(t&&isNaN(o.getTime()))throw new Error(`Invalid timestamp: ${e}`);return o}if(typeof e=="string"){const o=new Date(e);if(t&&isNaN(o.getTime()))throw new Error(`Invalid date string: ${e}`);return o}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 o=parseInt(t,10);if(r&&isNaN(o))throw new Error(`Cannot convert "${e}" to integer`);return o}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 o=parseFloat(t);if(r&&(isNaN(o)||!isFinite(o)))throw new Error(`Cannot convert "${e}" to number`);return o}if(r)throw new Error(`Cannot convert ${typeof e} to number`);return e}function Or(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 We(e,r,t){if(!Array.isArray(e)){if(typeof e=="string")return e.split(",").map(n=>n.trim()).filter(Boolean).map(n=>r==="integer"?Se(n,t):Ce(n,t));if(t)throw new Error(`Expected array, got ${typeof e}`);return e}return e.map((o,n)=>{try{return r==="integer"?Se(o,t):Ce(o,t)}catch(a){if(t)throw new Error(`Array element ${n}: ${a}`);return o}})}const Lr=(e,r)=>{const t=new Map;let o=null,n=null,a=0;for(const u of e){const c=u.group;if(!c){o=null,n=null;continue}if(c===o)r[u.name].group=n??c;else{if(!t.has(c))t.set(c,1),n=null,r[u.name].group=c;else{const s=t.get(c),d=`${c}(${s})`;t.set(c,s+1),n=d,r[u.name].group=d,a++}o=c}}return a},Pr=(e,r={})=>{const{includeEmpty:t=!0}=r,o=[];let n=null,a=[],u=0;for(const s of e){const d=s.group||null;d!==n?((a.length>0||t)&&(a.length===0&&u++,o.push({name:n,fields:a})),n=d,a=[s]):a.push(s)}(a.length>0||t)&&(a.length===0&&u++,o.push({name:n,fields:a}));const c=Math.max(0,...o.map(s=>s.fields.length));return{groups:o,metadata:{totalGroups:o.length,emptyGroups:u,largestGroup:c}}},xe=new Map,le=new Map,ne=new Set,je=new Map,Tr=async e=>{try{let r;switch(e.toLowerCase()){case"fr":r=(await Promise.resolve().then(()=>require("./common-DLr0UoG9.js"))).default;break;case"de":r=(await Promise.resolve().then(()=>require("./common-Crb-me6O.js"))).default;break;case"es":r=(await Promise.resolve().then(()=>require("./common-DRIndE7S.js"))).default;break;case"zh-cn":r=(await Promise.resolve().then(()=>require("./common-BeJOG7Z0.js"))).default;break;case"en":r={};break;default:r={}}return{success:!0,translations:r,fromCache:!1}}catch(r){return{success:!1,translations:{},error:`Failed to load common translations for ${e}: ${r}`}}},Hr=async e=>{if(!e)return{success:!1,translations:{},error:"Language is required"};const r=e.toLowerCase();if(r==="en")return{success:!0,translations:{},fromCache:!1};if(xe.has(r))return{success:!0,translations:xe.get(r)||{},fromCache:!0};const t=await Tr(r);return t.success&&(xe.set(r,t.translations),je.set(r,{loadedAt:new Date,size:Object.keys(t.translations).length,source:"common"})),t},qr=async(e,r)=>{if(!e||!r)return{success:!1,translations:{},error:"Both language and localizeName are required"};const t=`${e.toLowerCase()}/${r}`;if(ne.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 o=r;!r.includes("/")&&!r.includes(".")&&(o=`/locales/${e}/${r}.json`);const n=await fetch(o);if(!n.ok){const d=`HTTP ${n.status}: ${n.statusText}`;return n.status===404?(le.set(t,{}),je.set(t,{loadedAt:new Date,size:0,source:"user"}),{success:!0,translations:{},fromCache:!1}):(ne.add(t),{success:!1,translations:{},error:d})}const a=n.headers.get("content-type")||"";!a.includes("application/json")&&!a.includes("text/json")&&lr()&&console.warn(`Translation file at ${o} has unexpected content-type: ${a}`);const u=await n.text();if(!u){const d="Empty translation file";return ne.add(t),{success:!1,translations:{},error:d}}let c;try{c=JSON.parse(u)}catch(d){const l=`Invalid JSON in translation file: ${d instanceof Error?d.message:String(d)}`;return ne.add(t),{success:!1,translations:{},error:l}}if(!c||typeof c!="object"){const d="Invalid translation file format";return ne.add(t),{success:!1,translations:{},error:d}}const s=Object.fromEntries(Object.entries(c).map(([d,l])=>[d,typeof l=="string"?l:String(l)]));return le.set(t,s),je.set(t,{loadedAt:new Date,size:Object.keys(s).length,source:"user"}),{success:!0,translations:s,fromCache:!1}}catch(o){const n=`Failed to load user translations: ${o instanceof Error?o.message:"Unknown error"}`;return ne.add(t),{success:!1,translations:{},error:n}}};function lr(){try{if(typeof process<"u"&&process?.env?.NODE_ENV==="development")return!0}catch{}return!1}function Br(e,r){return r.length===0||!e.includes("{{")?e:e.replace(/\{\{(\d+)\}\}/g,(t,o)=>{const n=parseInt(o,10)-1,a=r[n];if(a==null)return t;try{return String(a)}catch{return t}})}const Ur=(e,r,t)=>(o,...n)=>{let a=o,u=!1;return!o||typeof o!="string"?String(o||""):(e.toLowerCase()==="en"?(a=o,u=!0):o in t?(a=t[o],u=!0):o in r?(a=r[o],u=!0):a=o,a=Br(a,n),!u&&lr()&&console.debug(`Missing translation for "${o}" in language "${e}"`),a)},Me={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"]},$e={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)"}},Ve={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}},Ae={},Wr=new Set([...Object.keys(Me),...Object.keys($e),...Object.keys(Ve)]);for(const e of Wr){const r={},t=Me[e]??[],o=$e[e]??{},n=Ve[e]??{};for(const a of t){const u=o[a];r[a]={name:typeof u=="string"?u:String(a),shortName:a,factor:Object.prototype.hasOwnProperty.call(n,a)?n[a]:void 0}}for(const[a,u]of Object.entries(o))if(!r[a]){const c=typeof u=="string"?u:String(a);r[a]={name:c,shortName:a,factor:Object.prototype.hasOwnProperty.call(n,a)?n[a]:void 0}}for(const[a,u]of Object.entries(n))r[a]||(r[a]={name:String(a),shortName:String(a),factor:u});Ae[e]=r}const _r=Object.freeze(Object.defineProperty({__proto__:null,dimensionUnitDisplayMap:$e,dimensionUnitsMap:Me,dimensonUnitFactorsMap:Ve,unitsByDimension:Ae},Symbol.toStringTag,{value:"Module"})),Kr=({field:e,value:r,onChange:t,onError:o})=>{const{definitionName:n,t:a}=V(),u=i.useRef(o);i.useEffect(()=>{u.current=o},[o]),i.useEffect(()=>{const m=L(n,e,r??!1,a);u.current?.(m??null)},[r,e,n,a]);const c=m=>{const f=m.target.checked;t?.(f,null)},s=m=>{(m.key===" "||m.key==="Spacebar"||m.key==="Space"||m.key==="Enter")&&(m.preventDefault(),t?.(!r,null))},d=e.name,l=L(n,e,r??!1,a);return g.jsx(T,{field:e,rightAlign:!1,children:g.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[g.jsx("label",{className:R.label,htmlFor:d,style:{textAlign:"left",justifyContent:"flex-start"},children:a(e.displayName)}),g.jsx("input",{id:d,"data-testid":"boolean-checkbox",type:"checkbox",checked:!!r,onChange:c,onKeyDown:s,"aria-checked":!!r,"aria-invalid":!!l,"aria-describedby":l?`${e.name}-error`:void 0,style:{cursor:"pointer",margin:"8px 0 8px 0",width:"1.2em",height:"1.2em",verticalAlign:"middle",color:"#FFFFFF",accentColor:"#0000FF",opacity:void 0}})]})})},_e=[{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"}];function ur(e){return/^#([0-9A-F]{3}){1,2}$/i.test(e)}function Jr(e){if(!ur(e))return null;const r=fr(e),t=parseInt(r.slice(1),16);return{r:t>>16&255,g:t>>8&255,b:t&255}}function fr(e){return e?(e=e.toLowerCase(),/^#([a-f0-9]){3}$/i.test(e)?"#"+e.slice(1).split("").map(r=>r+r).join(""):e):"#000000"}const Gr=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),[u,c]=i.useState("#000000"),s=i.useRef(null),d=i.useRef(null),l=i.useRef(o);i.useEffect(()=>{l.current=o},[o]),i.useEffect(()=>{const x=r&&ur(r)?r:"#000000",C=fr(x);c(C)},[r]),i.useEffect(()=>{const x=L(a,e,r??"#000000",n);l.current?.(x??null)},[r,e,a,n]);const m=L(a,e,r??"#000000",n),f=x=>{const C=x.target.value;c(C),t?.(C,null)},p=x=>{const C=x.target.value;c(C),t?.(C,null)},y=_e.find(x=>x.value===u),{r:h,g:b,b:v}=Jr(u)||{r:0,g:0,b:0};return g.jsx(T,{field:e,error:m,children:g.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%"},children:[g.jsxs("select",{ref:s,id:e.name,value:u,onChange:f,style:{minWidth:"120px",flex:1},className:q(R.input,R.inputSelect),"aria-invalid":!!m,"aria-describedby":m?`${e.name}-error`:void 0,children:[_e.map(x=>g.jsx("option",{value:x.value,children:n(x.label)},x.value)),y?null:g.jsxs("option",{value:u,children:["(",h,", ",b,", ",v,")"]},u)]}),g.jsx("label",{style:{width:"2.5em",height:"1.8em",display:"inline-block",border:"1px solid #ccc",borderRadius:"4px",backgroundColor:u,cursor:"pointer",overflow:"hidden",flexShrink:0},children:g.jsx("input",{ref:d,id:`${e.name}-color`,type:"color",value:u,onChange:p,style:{opacity:0,width:"100%",height:"100%",border:"none",padding:0,cursor:"pointer"},"aria-invalid":!!m,"aria-describedby":m?`${e.name}-error`:void 0})})]})})},se=e=>{if(!e)return null;const r=new Date(e);return isNaN(r.getTime())?null:r},Yr=e=>{if(!e)return"";if(/^\d{4}-\d{2}-\d{2}$/.test(e))return se(e)?e:"";const t=se(e);if(t){const o=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),a=String(t.getDate()).padStart(2,"0");return`${o}-${n}-${a}`}return""},Xr=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),{name:u,required:c}=e,s=i.useRef(null),d=i.useRef(o);i.useEffect(()=>{d.current=o},[o]);const l=i.useCallback(f=>{if(!f||f.trim()==="")return c?n("Value required"):null;if(f){const y=se(f);if(!y)return n("Invalid date format");if(e.minDate){const h=se(e.minDate);if(h&&y.getTime()<h.getTime())return n("Date must be on or after {{1}}",e.minDate)}if(e.maxDate){const h=se(e.maxDate);if(h&&y.getTime()>h.getTime())return n("Date must be on or before {{1}}",e.maxDate)}}return L(a,e,f,n)??null},[e,a,n,c]),m=f=>{const p=f.target.value,y=l(p);t?.(p,y)};return i.useEffect(()=>{const f=l(r);f!==s.current&&(s.current=f,d.current?.(f??null))},[r,l]),g.jsx(T,{field:e,error:l(r),children:g.jsx("input",{id:u,type:"date",value:Yr(r),onChange:m,className:q(R.input,R.textInput),...e.minDate?{min:e.minDate}:{},...e.maxDate?{max:e.maxDate}:{},"aria-invalid":!!l(r),"aria-describedby":l(r)?`${u}-error`:void 0})})},Zr=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),u=i.useRef(null),c=i.useRef(o);i.useEffect(()=>{c.current=o},[o]);const s=i.useCallback(l=>l===""||l===null||l===void 0?n("Value required"):e.options.some(f=>f.value===l)?L(a,e,l,n)??null:n("Invalid option selected"),[e,n,a]);i.useEffect(()=>{const l=r!=null?String(r):"",m=s(l);if(m&&e.options.length>0){const f=String(e.options[0].value);u.current&&(u.current.value=f),t?.(f,null),c.current?.(null)}else u.current&&(u.current.value=l),c.current?.(m??null)},[r,s,t,e.options]);const d=l=>{const m=l.target.value,f=s(m);t?.(m,f)};return g.jsx(T,{field:e,error:s(String(r??"")),children:g.jsx("select",{id:e.name,"aria-invalid":!!s(String(r??"")),"aria-describedby":s(String(r??""))?`${e.name}-error`:void 0,defaultValue:String(r??""),ref:u,onChange:d,className:q(R.input,R.inputSelect),children:e.options.map(l=>g.jsx("option",{value:String(l.value),children:n(l.label)},String(l.value)))})})};function Qr(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}const et=({field:e,value:r,onChange:t,onError:o})=>{const{definitionName:n,t:a}=V(),u=i.useRef(null),c=i.useCallback(m=>{const f=m.trim();return f===""?e.required?a("Value required"):null:Qr(f)?e.pattern&&!new RegExp(e.pattern).test(f)?e.patternErrorMessage?a(e.patternErrorMessage):a("Email does not match pattern: {{1}}",e.pattern):L(n,e,m,a)??null:a("Must be valid email format")},[e,n,a]),s=m=>{const f=m.target.value,p=c(f);t?.(f,p)},d=i.useRef(null),l=i.useRef(o);return i.useEffect(()=>{l.current=o},[o]),i.useEffect(()=>{const m=r??"",f=c(m);u.current&&u.current.value!==String(m)&&(u.current.value=String(m)),f!==d.current&&(d.current=f,l.current?.(f??null))},[r,c]),g.jsx(T,{field:e,error:c(String(r??"")),children:g.jsx("input",{id:e.name,type:"email",defaultValue:String(r??""),ref:u,onChange:s,className:q(R.input,R.textInput),"aria-invalid":!!c(String(r??"")),"aria-describedby":c(String(r??""))?`${e.name}-error`:void 0})})},rt=({field:e})=>{const{theme:r}=V(),{color:t=de(r)?"#444444":"#CCCCCC",thickness:o=1,margin:n="8px 0"}=e;return g.jsx("div",{style:{width:"auto",height:"0",borderTop:`${o}px solid ${t}`,margin:n}})},tt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),[u,c]=i.useState(!1),s=i.useRef(null),d=i.useRef(o);i.useEffect(()=>{d.current=o},[o]);const l=i.useCallback(x=>e.required&&(!x||Array.isArray(x)&&x.length===0)?n("Value required"):L(a,e,x,n)??null,[e,a,n]),m=i.useMemo(()=>l(r),[r,l]);i.useEffect(()=>{const x=l(r);t?.(r,x),d.current?.(x??null)},[r,l]);const f=x=>{const C=x.target.files;let A=null;if(C&&C.length>0){const k=Array.from(C);e.multiple?A=[...Array.isArray(r)?r:[],...k]:A=k[0]}const w=l(A);t?.(A,w)},p=x=>{x.preventDefault(),x.stopPropagation(),c(!1);const C=x.dataTransfer.files;if(C&&C.length>0){const A=Array.from(C);let w=null;e.multiple?w=[...Array.isArray(r)?r:[],...A]:w=A[0];const k=l(w);t?.(w,k)}},y=x=>{x.preventDefault(),x.stopPropagation(),c(!0)},h=x=>{x.preventDefault(),x.stopPropagation(),c(!1)},b=x=>{if(Array.isArray(r)&&typeof x=="number"){const C=r.filter((k,S)=>S!==x),A=C.length>0?C:null,w=l(A);t?.(A,w)}else{const C=l(null);t?.(null,C)}},v=()=>{const x=Array.isArray(r)?r:r?[r]:[];return x.length===0?null:g.jsx("div",{style:{marginTop:"8px",display:"flex",flexDirection:"column",gap:"6px"},children:x.map((C,A)=>g.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 10px",backgroundColor:"var(--reactaform-input-bg, #fff)",border:"1px solid var(--reactaform-border-color, #d1d5db)",borderRadius:"4px",fontSize:"0.875rem",gap:"8px"},children:[g.jsx("div",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.name}),g.jsx("button",{type:"button",onClick:()=>b(Array.isArray(r)?A:void 0),"aria-label":n("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:w=>{w.currentTarget.style.backgroundColor="var(--reactaform-bg-hover, #fee)"},onMouseLeave:w=>{w.currentTarget.style.backgroundColor="transparent"},children:"×"})]},`${C.name}-${A}`))})};return g.jsx(T,{field:e,error:m,children:g.jsxs("div",{style:{width:"100%"},children:[g.jsxs("div",{onDrop:p,onDragOver:y,onDragLeave:h,style:{position:"relative",border:`1px dashed ${u?"var(--reactaform-color-primary, #2563eb)":m?"var(--reactaform-color-error, #ef4444)":"var(--reactaform-border-color, #d1d5db)"}`,borderRadius:"var(--reactaform-border-radius, 4px)",padding:"8px 12px",textAlign:"center",backgroundColor:u?"var(--reactaform-bg-hover, #f0f9ff)":"var(--reactaform-input-bg, #fff)",transition:"all 0.2s ease",cursor:"pointer",minHeight:"var(--reactaform-input-height, 34px)",width:"100%",maxWidth:"100%",alignSelf:"stretch",boxSizing:"border-box",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px"},onClick:()=>s.current?.click(),onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),s.current?.click())},role:"button","aria-label":e.multiple?n("Choose Files or Drag & Drop"):n("Choose File or Drag & Drop"),"aria-invalid":!!m,"aria-describedby":m?`${e.name}-error`:void 0,children:[g.jsx("input",{id:e.name,ref:s,type:"file",accept:e.accept,multiple:e.multiple,style:{display:"none"},onChange:f}),g.jsx("div",{style:{fontSize:"1.25rem",opacity:.6,lineHeight:1,flexShrink:0},children:"📁"}),g.jsx("div",{style:{fontSize:"0.875rem",fontWeight:400,color:"var(--reactaform-text-color, #111827)",flex:1,textAlign:"left"},children:u?n("Drop files here"):e.multiple?n("Choose Files or Drag & Drop"):n("Choose File or Drag & Drop")}),e.accept&&g.jsx("div",{style:{fontSize:"0.75rem",color:"var(--reactaform-text-muted, #6b7280)",whiteSpace:"nowrap",opacity:u?0:1,transition:"opacity 0.15s ease",pointerEvents:u?"none":"auto"},children:e.accept})]}),v()]})})},nt=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;function ot(e){return e.split(",").map(r=>r.trim()).every(r=>nt.test(r))}const at=e=>!e||e.trim()===""?[]:e.split(",").map(r=>r.trim()).filter(Boolean).map(Number),st=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),[u,c]=i.useState(Array.isArray(r)?r.join(", "):String(r??"")),s=i.useCallback(f=>{if(f.trim()==="")return e.required?n("Value required"):null;if(!ot(f))return n("Each value must be a valid float");const p=at(f);if(e.minCount!==void 0&&p.length<e.minCount)return n("Minimum number of values: {{1}}",e.minCount);if(e.maxCount!==void 0&&p.length>e.maxCount)return n("Maximum number of values: {{1}}",e.maxCount);for(const h of p){if(e.min!==void 0&&(e.minInclusive?h<e.min:h<=e.min))return n("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?h>e.max:h>=e.max))return n("Each value must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max)}return L(a,e,p,n)??null},[a,e,n]),d=f=>{const p=f.target.value,y=s(p);c(p),t?.(p,y)},l=i.useRef(null),m=i.useRef(o);return i.useEffect(()=>{m.current=o},[o]),i.useEffect(()=>{const f=Array.isArray(r)?r.join(", "):String(r??""),p=s(f);p!==l.current&&(l.current=p,m.current?.(p??null))},[r,e.required,s,n]),g.jsx(T,{field:e,error:s(u),children:g.jsx("input",{id:e.name,type:"text",value:u,onChange:d,className:q(R.input,R.textInput),style:{flex:1},"aria-invalid":!!s(u),"aria-describedby":s(u)?`${e.name}-error`:void 0})})},it=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),u=i.useRef(null),c=i.useCallback(f=>{if(f.trim()==="")return e.required?n("Value required"):null;const p=Number.parseFloat(f);return Number.isNaN(p)?n("Must be a valid float"):e.min!==void 0&&(e.minInclusive?p<e.min:p<=e.min)?n("Must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min):e.max!==void 0&&(e.maxInclusive?p>e.max:p>=e.max)?n("Must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max):L(a,e,p,n)??null},[e,a,n]),s=i.useRef(null),d=i.useRef(o);i.useEffect(()=>{d.current=o},[o]),i.useEffect(()=>{const f=String(r??""),p=c(f);p!==s.current&&(s.current=p,d.current?.(p??null)),u.current&&document.activeElement!==u.current&&(u.current.value=f)},[r,e,c,n]);const l=f=>{const p=f.target.value,y=c(p);t?.(p,y)},m=i.useMemo(()=>c(String(r??"")),[r,c]);return g.jsx(T,{field:e,error:m,children:g.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:u,onChange:l,className:q(R.input,R.inputNumber),"aria-invalid":!!m,"aria-describedby":m?`${e.name}-error`:void 0})})};function ct(){try{return"/"}catch{}try{if(typeof process<"u"&&process?.env?.PUBLIC_URL)return process.env.PUBLIC_URL}catch{}return"/"}const lt=({field:e,value:r})=>{const{language:t,t:o}=V(),n=e.alignment||"center",a={left:"flex-start",center:"center",right:"flex-end"},u=typeof r=="string"?r:"";let c=u&&u.trim()!==""?u:typeof e.defaultValue=="string"?e.defaultValue:"";c&&!c.startsWith("/")&&(c=`${ct()}${c}`);const s=e.localized?.split(";").map(b=>b.trim()),[d,l]=i.useState(c||""),m=i.useRef(c||null);if(i.useEffect(()=>{if(!c)return;const b=c.split("/"),v=b.pop(),x=v.lastIndexOf(".");if(x===-1)return;const C=v.substring(0,x),A=v.substring(x);let w=null;s?.includes(t)&&(w=`${C}_${t}${A}`);const k=new AbortController;if(w){const S=[...b,w].join("/");fetch(S,{method:"HEAD",signal:k.signal}).then(N=>{const j=N.ok?S:c;j!==m.current&&(m.current=j,l(j))}).catch(()=>{c!==m.current&&(m.current=c,l(c))})}else{const S=c;S!==m.current&&(m.current=S,requestAnimationFrame(()=>l(S)))}return()=>{k.abort()}},[c,t,s]),!d)return null;const{width:f,height:p}=e,y={},h={borderRadius:"8px",objectFit:"contain",boxShadow:"0 2px 6px rgba(0,0,0,0.1)",margin:"0 0 8px 0"};return f&&p?(y.width=f,y.height=p,h.width=`${f}px`,h.height=`${p}px`):f&&!p?(y.width=f,h.width=`${f}px`,h.height="auto"):!f&&p&&(y.height=p,h.width="auto",h.height=`${p}px`),g.jsx(T,{field:e,children:g.jsx("div",{"data-testid":"image-wrapper",style:{display:"flex",justifyContent:a[n]||"center",margin:"0 0"},children:g.jsx("img",{src:d,alt:o?.(e.displayName||"Image")||e.displayName||"Image",...y,style:h})})})};function ut(e){const r=/^-?\d+$/;return e.split(",").map(t=>t.trim()).every(t=>r.test(t))}const ft=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),u=",",[c,s]=i.useState(Array.isArray(r)?r.join(u+" "):String(r??"")),d=h=>!h||h.trim()===""?[]:h.split(u).map(b=>b.trim()).filter(Boolean).map(b=>Number(b)),l=i.useCallback(h=>{if(h.trim()==="")return e.required?n("Value required"):null;if(!ut(h))return n("Each value must be a valid integer");const b=d(h);if(e.minCount!==void 0&&b.length<e.minCount)return n("Minimum number of values: {{1}}",`${e.minCount}`);if(e.maxCount!==void 0&&b.length>e.maxCount)return n("Maximum number of values: {{1}}",`${e.maxCount}`);for(const x of b){if(e.min!==void 0&&(e.minInclusive?x<e.min:x<=e.min))return n("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?x>e.max:x>=e.max))return n("Each value must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max)}return L(a,e,b,n)??null},[a,e,n]),m=h=>{const b=h.target.value,v=l(b);s(b),t?.(b,v)},f=i.useRef(null),p=i.useRef(o);i.useEffect(()=>{p.current=o},[o]),i.useEffect(()=>{const h=Array.isArray(r)?r.join(u+" "):String(r??""),b=l(h);b!==f.current&&(f.current=b,p.current?.(b??null))},[r,e.required,l,n]);const y=l(c);return g.jsx(T,{field:e,error:y,children:g.jsx("input",{id:e.name,type:"text",value:c,onChange:m,className:q(R.input,R.textInput),style:{flex:1},"aria-invalid":!!y,"aria-describedby":y?`${e.name}-error`:void 0})})};function mt(e){return/^[-+]?\d*$/.test(e)}const dt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),u=i.useRef(null),c=i.useCallback(f=>{if(f.trim()==="")return e.required?n("Value required"):null;if(!mt(f))return n("Must be a valid integer");const p=parseInt(f,10);if(Number.isNaN(p))return n("Must be a valid integer");if(e.min!==void 0&&(e.minInclusive?p<e.min:p<=e.min))return n("Must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?p>e.max:p>=e.max))return n("Must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max);if(e.step!==void 0){const h=Number(e.step);if(!Number.isInteger(h))return n("Invalid step value");if(p%h!==0)return n("Must be a multiple of {{1}}",h)}return L(a,e,p,n)??null},[e,a,n]),s=i.useRef(null),d=i.useRef(o);i.useEffect(()=>{d.current=o},[o]),i.useEffect(()=>{const f=String(r??""),p=c(f);p!==s.current&&(s.current=p,d.current?.(p??null)),u.current&&document.activeElement!==u.current&&(u.current.value=f)},[r,e,c,n]);const l=f=>{const p=f.target.value,y=c(p);t?.(p,y)},m=i.useMemo(()=>c(String(r??"")),[r,c]);return g.jsx(T,{field:e,error:m,children:g.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:u,onChange:l,className:q(R.input,R.inputNumber),"aria-invalid":!!m,"aria-describedby":m?`${e.name}-error`:void 0})})},pt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),u=e.minHeight??"80px",c=i.useRef(null),s=i.useRef(null),d=i.useRef(o);i.useEffect(()=>{d.current=o},[o]);const l=i.useCallback(y=>y.trim()===""?e.required?n("Value required"):null:e.minLength!==void 0&&y.length<e.minLength?n("Must be at least {{1}} characters",e.minLength):e.maxLength!==void 0&&y.length>e.maxLength?n("Must be at most {{1}} characters",e.maxLength):L(a,e,y,n),[e,a,n]),m=y=>{const h=y.target.value,b=l(h);t?.(h,b)};i.useEffect(()=>{const y=l(r);y!==s.current&&(s.current=y,d.current?.(y??null)),c.current&&c.current.value!==String(r??"")&&(c.current.value=String(r??""))},[r,l]);const f={id:e.name,defaultValue:String(r??""),ref:c,onChange:m,style:{resize:"vertical",minHeight:u,width:"100%",boxSizing:"border-box"},className:q(R.input,R.textInput)},p=l(r);return g.jsx(T,{field:e,error:p,children:g.jsx("textarea",{...f,"aria-invalid":!!p,"aria-describedby":p?`${e.name}-error`:void 0})})},gt=({field:e,value:r,onChange:t,onError:o})=>{const n=i.useRef(o);i.useEffect(()=>{n.current=o},[o]);const{t:a,theme:u,formStyle:c,fieldStyle:s,definitionName:d}=V(),l=(j,M,$)=>{if(!M)return{};const z=j?.[M];return($&&z?z[$]:void 0)??{}},m=i.useRef(null),[f,p]=i.useState(!1),[y,h]=i.useState(null),b=i.useMemo(()=>e.options.map(j=>({value:j.value,label:a(j.label)})),[e.options,a]),v=i.useMemo(()=>{const j=Array.isArray(r)?r:[],M=new Set(b.map($=>$.value));return j.filter($=>M.has($))},[r,b]),x=j=>{const M=Array.isArray(j)?j:[];return e.required&&M.length===0?a("Value required"):L(d,e,M,a)??null},C=()=>{if(!m.current)return;const j=m.current.getBoundingClientRect();h({x:j.left,y:j.bottom}),p(M=>!M)},A=j=>{const M=v.includes(j)?v.filter(E=>E!==j):[...v,j],$=x(M);n.current?.($??null),t?.(M,$)},w=i.useMemo(()=>({height:"var(--reactaform-input-height, 2.5rem)",padding:"var(--reactaform-input-padding, 8px)",display:"flex",alignItems:"center",boxSizing:"border-box",cursor:"pointer",position:"relative",borderRadius:"var(--reactaform-border-radius, 4px)",border:"1px solid var(--reactaform-border-color, #ccc)",background:"var(--reactaform-secondary-bg, #fff)",color:"var(--reactaform-text-color, #000)",...l(c,"multiSelect","control"),...l(s,void 0,"control")}),[c,s]),k=i.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(c,"multiSelect","clearButton"),...l(s,void 0,"clearButton")}),[c,s]),S=i.useMemo(()=>({position:"absolute",right:"0.7em",top:"50%",transform:"translateY(-50%)",pointerEvents:"none",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",...l(c,"multiSelect","arrow"),...l(s,void 0,"arrow")}),[c,s]),N=x(Array.isArray(r)?r:[]);return g.jsxs("div",{children:[g.jsx(T,{field:e,error:null,children:g.jsx("div",{style:{width:"100%"},children:g.jsxs("div",{ref:m,className:"reactaform-multiselection-control",style:w,onClick:C,tabIndex:0,role:"button","aria-haspopup":"listbox","aria-expanded":f,"aria-invalid":!!N,"aria-describedby":N?`${e.name}-error`:void 0,onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),C())},children:[g.jsxs("span",{style:{flex:1,color:"var(--reactaform-text-muted, #888)"},children:[v.length," / ",b.length," selected"]}),v.length>0&&g.jsx("button",{type:"button","aria-label":"Clear selections",onClick:j=>{j.stopPropagation(),t?.([],null)},style:k,children:g.jsx("span",{style:k,"aria-hidden":!0,children:"✖"})}),g.jsx("span",{style:S,"aria-hidden":!0,children:"▼"})]})})}),f&&y&&g.jsx(ht,{position:y,options:b,selectedValues:v,onToggleOption:A,onClose:()=>p(!1),controlRef:m,theme:u})]})},ht=({position:e,options:r,selectedValues:t,onToggleOption:o,onClose:n,controlRef:a,theme:u})=>{const c=i.useRef(null),[s,d]=i.useState(-1),{formStyle:l,fieldStyle:m}=V(),f=de(u??"light"),p=(S,N,j)=>{if(!N)return{};const $=S?.[N];return(j&&$?$[j]:void 0)??{}},y=i.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)",...p(l,"multiSelect","popup"),...p(m,void 0,"popup")}),[l,m]),h=i.useMemo(()=>({padding:"6px 8px",cursor:"pointer",display:"flex",alignItems:"center",background:"transparent",color:"var(--reactaform-text-color, #000)",...p(l,"multiSelect","option"),...p(m,void 0,"option")}),[l,m]);i.useEffect(()=>{const S=N=>{const j=N.target;!c.current?.contains(j)&&!a.current?.contains(j)&&n()};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[n,a]),i.useEffect(()=>{c.current&&r.length>0&&requestAnimationFrame(()=>d(S=>S===-1?0:S))},[r.length]),i.useEffect(()=>{if(!c.current||s<0)return;const S=c.current.querySelector(`#multi-opt-${s}`);S&&requestAnimationFrame(()=>S.focus())},[s]);const b=250,v=200,[x,C]=i.useState(null),[A,w]=i.useState(null);if(i.useEffect(()=>{if(typeof window>"u")return;const S=()=>{let M=e.x,$=e.y,E=b;const z=a?.current;if(z){const B=z.getBoundingClientRect();M=B.left,$=B.bottom,E=Math.max(80,Math.round(B.width))}M=Math.min(M,window.innerWidth-E),$=Math.min($,window.innerHeight-v),C({left:M,top:$}),w(E)};S(),window.addEventListener("scroll",S,!0),window.addEventListener("resize",S);let N=null;const j=a?.current;return typeof ResizeObserver<"u"&&j&&(N=new ResizeObserver(()=>S()),N.observe(j)),()=>{window.removeEventListener("scroll",S,!0),window.removeEventListener("resize",S),N&&j&&N.unobserve(j)}},[a,e.x,e.y]),typeof window>"u")return null;let k=document.getElementById("popup-root");return k||(k=document.createElement("div"),k.id="popup-root",document.body.appendChild(k)),ke.createPortal(g.jsx("div",{ref:c,role:"listbox","aria-activedescendant":s>=0?`multi-opt-${s}`:void 0,style:{position:"fixed",top:x?x.top:e.y,left:x?x.left:e.x,width:A??b,...y},"data-reactaform-theme":u??"light",children:r.map((S,N)=>{const j=t.includes(S.value),M=f?"var(--reactaform-hover-bg, rgba(255,255,255,0.01))":"var(--reactaform-hover-bg, #eee)",$={...h,background:N===s?M:h.background};return g.jsxs("div",{id:`multi-opt-${N}`,onMouseDown:E=>{E.stopPropagation(),o(S.value)},onKeyDown:E=>{const z=r.length;switch(E.key){case"ArrowDown":E.preventDefault(),d(B=>(B+1)%z);break;case"ArrowUp":E.preventDefault(),d(B=>(B-1+z)%z);break;case"Home":E.preventDefault(),d(0);break;case"End":E.preventDefault(),d(z-1);break;case"Enter":case" ":E.preventDefault(),E.stopPropagation(),o(S.value);break;case"Escape":E.preventDefault(),n(),a?.current?.focus();break}},tabIndex:N===s?0:-1,role:"option","aria-selected":j,style:$,onMouseEnter:E=>{E.currentTarget.style.background=M,d(N)},onMouseLeave:E=>{E.currentTarget.style.background="transparent",d(z=>z===N?-1:z)},children:[g.jsx("input",{type:"checkbox",checked:j,readOnly:!0,style:{marginRight:8,width:"1.125em",height:"1.125em",verticalAlign:"middle",accentColor:f?"#10b981":"#22c55e",cursor:"pointer"}}),S.label]},S.value)})}),k)},bt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),u=i.useRef(null),c=e.min??void 0,s=e.max??void 0,d=Math.max(1,Math.round(e.step??1)),l=i.useCallback(b=>isNaN(b)?n("Must be a valid integer"):Number.isInteger(b)?c!==void 0&&b<c?n("Must be ≥ {{1}}",c):s!==void 0&&b>s?n("Must be ≤ {{1}}",s):L(a,e,b,n)??null:n("Must be an integer"),[a,e,n,c,s]),m=i.useRef(null),f=i.useRef(o);i.useEffect(()=>{f.current=o},[o]),i.useEffect(()=>{if(document.activeElement===u.current)return;const v=String(r),x=l(r);u.current&&(u.current.value=v),x!==m.current&&(m.current=x,f.current?.(x??null))},[r,l]);const p=b=>{if(b.trim()==="")return e.required?n("Value required"):null;const x=Number(b);return l(x)},y=b=>{const v=b.target.value,x=b.target.valueAsNumber,C=p(v);t?.(x,C)},h=p(String(r??""));return g.jsx(T,{field:e,error:h,children:g.jsx("input",{ref:u,id:e.name,type:"number",defaultValue:String(r??""),min:c,max:s,step:d,onChange:y,style:{width:"100%",height:"100%"},className:R.input,"aria-invalid":!!h,"aria-describedby":h?`${e.name}-error`:void 0})})},yt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n}=V(),a=i.useRef(null),{definitionName:u}=V(),c=i.useCallback(f=>{const p=String(f??"").trim();if(p==="")return e.required?n("Value required"):null;if(e.pattern)try{if(!new RegExp(e.pattern).test(p))return e.patternErrorMessage?n(e.patternErrorMessage):n("Phone number does not match pattern: {{1}}",`${e.pattern}`)}catch{}return L(u,e,p,n)},[u,e,n]),s=i.useRef(null),d=i.useRef(o);i.useEffect(()=>{d.current=o},[o]),i.useEffect(()=>{const f=String(r??""),p=c(f);a.current&&a.current.value!==String(f)&&(a.current.value=String(f)),p!==s.current&&(s.current=p,d.current?.(p??null))},[r,c]);const l=f=>{const p=f.target.value,y=p.trim();let h=null;if(y===""){h=e.required?n("Value required"):null,t?.(p,h);return}h||(h=c(p)),t?.(p,h)},m=i.useMemo(()=>c(String(r??"")),[r,c]);return g.jsx(T,{field:e,error:m,children:g.jsx("input",{id:e.name,type:"tel",defaultValue:String(r??""),ref:a,onChange:l,className:q(R.input,R.textInput),"aria-invalid":!!m,"aria-describedby":m?`${e.name}-error`:void 0})})},xt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),u=e.layout?.toLowerCase()==="horizontal"?"row":"column",c=i.useRef(null),s=i.useRef(o);i.useEffect(()=>{s.current=o},[o]);const d=i.useCallback(m=>m===""||m===null||m===void 0?n("Value required"):e.options.some(p=>p.value===m)?L(a,e,m,n)??null:n("Invalid option selected"),[e,n,a]);i.useEffect(()=>{const m=r!=null?String(r):"",f=d(m);if(s.current?.(f??null),c.current){const p=Array.from(c.current.querySelectorAll("input[type=radio]"));if(f&&e.options.length>0){const y=String(e.options[0].value);p.forEach(h=>h.checked=h.value===y),t?.(y,null)}else p.forEach(y=>y.checked=y.value===m)}},[r,d,t,e.options]);const l=m=>{const f=m.target.value,p=d(f);s.current?.(p??null),t?.(f,p)};return g.jsx(T,{field:e,error:d(String(r??"")),children:g.jsx("div",{className:R.input,role:"radiogroup","aria-labelledby":`${e.name}-label`,"aria-invalid":!!d(String(r??"")),style:{display:"flex",flexDirection:u,flexWrap:u==="row"?"wrap":"nowrap",gap:u==="row"?"12px":"4px",alignItems:u==="row"?"center":"stretch",width:"100%",padding:u==="row"?"8px":void 0,boxSizing:"border-box"},ref:c,children:e.options.map(m=>g.jsxs("label",{className:q(R.label),style:{display:u==="column"?"flex":"inline-flex",gap:"8px",alignItems:"center",whiteSpace:"nowrap",marginBottom:u==="column"?6:0,cursor:"pointer",width:u==="column"?"100%":void 0,justifyContent:"flex-start"},children:[g.jsx("input",{type:"radio",name:e.name,value:String(m.value),defaultChecked:String(r??"")===String(m.value),onChange:l,style:{width:"1.1em",height:"1.1em"}}),g.jsx("span",{style:{userSelect:"none",textAlign:u==="column"?"left":void 0,flex:u==="column"?1:void 0,fontWeight:400},children:n(m.label)})]},String(m.value)))})})},vt={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:o})=>{const{t:n,definitionName:a}=V(),[u,c]=i.useState(null),s=i.useRef([]),d=e.max||5,l=i.useCallback(h=>e.required&&h===0?n("Value required"):L(a,e,h,n)??null,[e,n,a]),m=i.useRef(null),f=i.useRef(o);i.useEffect(()=>{f.current=o},[o]),i.useEffect(()=>{let h=r||0;r<0&&(h=0),r>d&&(h=d);const b=l(h);b!==m.current&&(m.current=b,f.current?.(b??null))},[r,l,d]);const p=h=>{const b=l(h);t?.(h,b)},y=(()=>{let h=r||0;return h<0&&(h=0),h>d&&(h=d),h})();return g.jsx(T,{field:e,error:l(y),children:g.jsx("div",{role:"radiogroup","aria-labelledby":`${e.name}-label`,style:vt,"aria-invalid":!!l(y),"aria-describedby":l(y)?`${e.name}-error`:void 0,children:(()=>{const h=e.icon&&String(e.icon).trim()?String(e.icon):"★";return[...Array(d)].map((b,v)=>{const x=v<y,A=u!==null&&v<=u||x?"gold":"lightgray";return g.jsx("span",{ref:w=>s.current[v]=w,role:"radio",tabIndex:y>0?v===y-1?0:-1:v===0?0:-1,"aria-checked":x,onClick:()=>p(v+1),onKeyDown:w=>{if(w.key==="Enter"||w.key===" ")w.preventDefault(),p(v+1);else if(w.key==="ArrowRight"||w.key==="ArrowUp"){w.preventDefault();const k=Math.min(d-1,v+1);s.current[k]?.focus()}else if(w.key==="ArrowLeft"||w.key==="ArrowDown"){w.preventDefault();const k=Math.max(0,v-1);s.current[k]?.focus()}},onMouseEnter:()=>c(v),onMouseLeave:()=>c(null),style:{...wt,color:A},"aria-label":`Rating ${v+1}`,title:n(`${e.displayName} ${v+1}`),children:h},v)})})()})})},Ct=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),u=i.useRef(null),c=i.useRef(null),s=i.useRef(o);i.useEffect(()=>{s.current=o},[o]);const d=i.useMemo(()=>e.pattern?new RegExp(e.pattern):null,[e.pattern]),l=i.useCallback(b=>b===""?e.required?n("Value required"):null:e.minLength!==void 0&&b.length<e.minLength?n("Must be at least {{1}} characters",e.minLength):e.maxLength!==void 0&&b.length>e.maxLength?n("Must be at most {{1}} characters",e.maxLength):d&&!d.test(b)?e.patternErrorMessage?n(e.patternErrorMessage):n("Input does not match pattern: {{1}}",e.pattern):L(a,e,b,n),[e,a,n,d]),m=b=>{const v=b.target.value,x=l(v);t?.(v,x)};i.useEffect(()=>{const b=l(r??"");u.current&&u.current.value!==String(r??"")&&(u.current.value=String(r??"")),b!==c.current&&(c.current=b,s.current?.(b??null))},[r,l]);const[f,p]=i.useState(!1),y=()=>p(b=>!b),h=i.useMemo(()=>l(String(r??"")),[r,l]);return g.jsx(T,{field:e,error:h,children:g.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,width:"100%"},children:[g.jsx("input",{id:e.name,type:f?"text":"password",defaultValue:String(r??""),ref:u,onChange:m,className:q(R.input,R.textInput),style:{flex:1,minWidth:0},"aria-invalid":!!h,"aria-describedby":h?`${e.name}-error`:void 0}),g.jsx("button",{type:"button",onClick:y,"aria-label":n(f?"Hide password":"Show password"),style:{background:"transparent",border:"none",cursor:"pointer",fontSize:16,lineHeight:1,padding:"4px 6px",flexShrink:0},children:f?"🙈":"👁️"})]})})},jt=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;function Rt(e){return jt.test(e)}const kt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),u=i.useRef(null),c=i.useRef(null),s=i.useCallback(y=>{let h=null;if(y.trim()==="")return n("Value required");if(!Rt(y))return n("Invalid number");const b=Number(y);return typeof e.min=="number"&&b<e.min?n("Value should be at least {{1}}",e.min):typeof e.max=="number"&&b>e.max?n("Value should be at most {{1}}",e.max):(h||(h=L(a,e,b,n)),h)},[a,e,n]),d=i.useRef(null),l=i.useRef(o);i.useEffect(()=>{l.current=o},[o]),i.useEffect(()=>{const y=String(r),h=s(y);c.current&&document.activeElement!==c.current&&(c.current.value=isNaN(Number(y))?String(e.min??0):String(Number(y))),u.current&&document.activeElement!==u.current&&(u.current.value=y),h!==d.current&&(d.current=h,l.current?.(h??null))},[r,s,e.min]);const m=e.min??0,f=e.max??100,p=y=>{const h=y.target.value,b=s(h);t?.(h,b)};return g.jsx(T,{field:e,error:s(String(r??"")),children:g.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%"},children:[g.jsx("input",{ref:c,id:`${e.name}-range`,type:"range",defaultValue:isNaN(Number(r))?String(m):String(Number(r)),onChange:p,min:m,max:f,style:{padding:0,flex:1},className:R.rangeInput,"aria-invalid":!!s(String(r??"")),"aria-describedby":s(String(r??""))?`${e.name}-error`:void 0}),g.jsx("input",{id:e.name,ref:u,type:"text",defaultValue:String(r??""),onChange:p,required:!0,style:{width:"40px",minWidth:"40px",height:"2.3em",textAlign:"center",flexShrink:0},className:q(R.input,R.textInput),"aria-invalid":!!s(String(r??"")),"aria-describedby":s(String(r??""))?`${e.name}-error`:void 0})]})})},Et=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,formStyle:a,fieldStyle:u,definitionName:c}=V(),s=a,d=u,l=(w,k,S)=>{if(!k)return{};const N=w?.[k];return(S&&N?N[S]:void 0)??{}},m=i.useMemo(()=>({display:"inline-block",position:"relative",width:44,height:24,...l(s,"switch","label"),...l(d,void 0,"label")}),[s,d]),f=i.useMemo(()=>({position:"absolute",opacity:0,top:0,left:0,width:"100%",height:"100%",margin:0,cursor:"pointer",pointerEvents:"none",...l(s,"switch","hiddenInput"),...l(d,void 0,"hiddenInput")}),[s,d]),p=i.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",...l(s,"switch","slider"),...l(d,void 0,"slider")}),[s,d]),y=i.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)",...l(s,"switch","knob"),...l(d,void 0,"knob")}),[s,d]),h=!!r,b=i.useRef(null),v=i.useRef(o),x=i.useCallback(w=>w?L(c,e,w,n)??null:e.required?n("Value required"):null,[e,n,c]),C=()=>{const w=!h,k=x(w);t?.(w,k)};i.useEffect(()=>{v.current=o},[o]),i.useEffect(()=>{const w=x(h);w!==b.current&&(b.current=w,v.current?.(w??null))},[h,e,x]);const A=e.name;return g.jsx(T,{field:e,error:x(h),rightAlign:!1,children:g.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[g.jsx("label",{className:R.label,htmlFor:A,style:{textAlign:"left",justifyContent:"flex-start"},children:n(e.displayName)}),g.jsxs("label",{style:m,children:[g.jsx("input",{id:e.name,type:"checkbox",checked:h,readOnly:!0,"aria-label":n(e.displayName),"aria-invalid":!!x(h),"aria-describedby":x(h)?`${e.name}-error`:void 0,style:f,tabIndex:-1}),g.jsx("span",{role:"switch","data-testid":"switch",tabIndex:0,"aria-checked":h,"aria-invalid":!!x(h),"aria-describedby":x(h)?`${e.name}-error`:void 0,onClick:C,onKeyDown:w=>{(w.key===" "||w.key==="Spacebar"||w.key==="Space"||w.key==="Enter")&&(w.preventDefault(),C())},className:`reactaform-switch ${h?"active checked on":""} `,style:h?{...p,backgroundColor:"var(--reactaform-switch-on-bg, #22c55e)",borderColor:"var(--reactaform-switch-on-border, #16a34a)"}:p,children:g.jsx("span",{style:{...y,transform:h?"translateX(20px)":void 0}})})]})]})})},Ke=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),u=i.useRef(null),c=i.useRef(null),s=i.useRef(o);i.useEffect(()=>{s.current=o},[o]);const d=i.useMemo(()=>e.pattern?new RegExp(e.pattern):null,[e.pattern]),l=i.useCallback(f=>f.trim()===""?e.required?n("Value required"):null:e.minLength!==void 0&&f.length<e.minLength?n("Must be at least {{1}} characters",e.minLength):e.maxLength!==void 0&&f.length>e.maxLength?n("Must be at most {{1}} characters",e.maxLength):d&&!d.test(f)?e.patternErrorMessage?n(e.patternErrorMessage):n("Input does not match pattern: {{1}}",e.pattern):L(a,e,f,n),[e,a,n,d]),m=f=>{const p=f.target.value,y=l(p);t?.(p,y)};return i.useEffect(()=>{const f=l(r);u.current&&u.current.value!==String(r??"")&&(u.current.value=String(r??"")),f!==c.current&&(c.current=f,s.current?.(f??null))},[r,l]),g.jsx(T,{field:e,error:l(String(r??"")),children:g.jsx("input",{id:e.name,"aria-invalid":!!l(String(r??"")),"aria-describedby":l(String(r??""))?`${e.name}-error`:void 0,type:"text",defaultValue:String(r??""),ref:u,onChange:m,className:q(R.input,R.textInput)})})},Nt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),u=i.useRef(null),c=i.useRef(o),s=e.includeSeconds??!0;i.useEffect(()=>{c.current=o},[o]);const d=i.useCallback(m=>{if(!m||m.trim()==="")return e.required||e.min||e.max?n("Value required"):null;const f=h=>{const b=h.split(":").map(x=>parseInt(x,10));if(b.some(x=>Number.isNaN(x)))return NaN;let v=0;if(b.length===3)v=b[0]*3600+b[1]*60+b[2];else if(b.length===2)v=b[0]*3600+b[1]*60;else if(b.length===1)v=b[0]*3600;else return NaN;return v},p=f(m);if(Number.isNaN(p))return n("Invalid time format");if(e.min&&typeof e.min=="string"){const h=f(e.min);if(!Number.isNaN(h)&&p<h)return n("Time must be on or after {{1}}",e.min)}if(e.max&&typeof e.max=="string"){const h=f(e.max);if(!Number.isNaN(h)&&p>h)return n("Time must be on or before {{1}}",e.max)}return L(a,e,m,n)??null},[e,a,n]),l=m=>{const f=m.target.value,p=d(f);t?.(f,p)};return i.useEffect(()=>{const m=d(r);m!==u.current&&(u.current=m,c.current?.(m??null))},[r,d]),g.jsx(T,{field:e,error:d(r),children:g.jsx("input",{id:e.name,type:"time",value:r,step:s?1:60,onChange:l,min:typeof e.min=="string"?e.min:void 0,max:typeof e.max=="string"?e.max:void 0,className:q(R.input,R.textInput),"aria-invalid":!!d(r),"aria-describedby":d(r)?`${e.name}-error`:void 0})})};function It({pos:e,options:r,onClose:t,onClickOption:o}){const n=i.useRef(null),a=i.useRef(!1),[u,c]=i.useState({top:e?.y??0,left:e?.x??0,ready:!1}),s=typeof window<"u"?document.getElementById("popup-root")||document.body:null;return i.useEffect(()=>{function d(l){a.current||l.target.dataset?.popupMenu==="item"||n.current&&l.target instanceof Node&&!n.current.contains(l.target)&&t()}return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[t]),i.useLayoutEffect(()=>{if(!n.current||!e||e.x==null||e.y==null)return;const d=n.current.getBoundingClientRect(),l=window.innerWidth,m=window.innerHeight;let f=e.x,p=e.y;f+d.width>l&&(f=Math.max(0,l-d.width-10)),p+d.height>m&&(p=Math.max(0,e.y-d.height-5)),c({top:p,left:f,ready:!0})},[e,r]),!s||r===void 0||r.length===0||!e||e.x==null||e.y==null?null:ke.createPortal(g.jsx("div",{ref:n,onMouseDown:d=>{d.stopPropagation()},style:{position:"fixed",top:u.top,left:u.left,visibility:u.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((d,l)=>g.jsx("div",{"data-popup-menu":"item",onMouseDown:m=>{m.stopPropagation(),a.current=!0},onClick:m=>{m.stopPropagation(),m.preventDefault(),o(d),t(),setTimeout(()=>{a.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:m=>{m.currentTarget.style.backgroundColor="var(--reactaform-hover-bg, #e0e0e0)"},onMouseLeave:m=>{m.currentTarget.style.backgroundColor="transparent"},children:d.label},d.label??l))}),s)}const ie={};function Mt(e,r){if(e in ie)return;const t=Ae[e]??{},o={},n={},a={};for(const[c,s]of Object.entries(t))typeof s.factor=="number"&&(o[c]=s.factor),n[c]=r(c),a[r(c)]=c;const u=Object.keys(t)[0]??"";ie[e]={default:u,factors:o,labels:n,reverseLabels:a}}function $t(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 Vt(e,r,t){if(!Number.isFinite(e))return[];if(t===ie.temperature)return Object.keys(t.labels).map(a=>{const u=$t(r,a,e);return Number.isFinite(u)?{label:`${u.toFixed(6)} ${a}`,value:u.toString(),unit:a}:{label:`${String(u)} ${a}`,value:String(u),unit:a}});const n=t.factors[r];return n===void 0?[]:Object.entries(t.factors).map(([a,u])=>{const c=e/n*u;return Number.isFinite(c)?{label:`${c.toFixed(6)} ${a}`,value:c.toString(),unit:a}:{label:`${String(c)} ${a}`,value:String(c),unit:a}})}function ue(e,r){return e in r.labels?e:r.reverseLabels&&r.reverseLabels[e]?r.reverseLabels[e]:null}const At=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/,Ft=({unitFactors:e,field:r,value:t,onChange:o,onError:n})=>{const{t:a,definitionName:u}=V(),c=i.useRef(null),s=i.useRef(null),[d,l]=i.useState(null),[m,f]=i.useState(null),[p,y]=i.useState(!1),[h,b]=i.useState(null),[v,x]=i.useState([]),C=i.useCallback((O,I)=>{if(!O||O.trim()==="")return r.required?a("Value required"):null;if(!At.test(O))return a("Must be a valid number");const F=L(u,r,[O,I],a);return F||null},[u,r,a]),A=e.reverseLabels!==void 0?e.reverseLabels:Object.fromEntries(Object.entries(e.labels).map(([O,I])=>[I,O]));i.useEffect(()=>{const O=String(t[0]);let I=t[1]??e.default;I=ue(I,e)||I;const F=document.activeElement;F===c.current||F===s.current||(c.current&&(c.current.value=O),s.current&&(s.current.value=I),l(null),f(null))},[t,e]);const w=i.useRef(null),k=i.useRef(n);i.useEffect(()=>{k.current=n},[n]),i.useEffect(()=>{const O=String(t[0]);let I=t[1]??e.default;I=ue(I,e)||I;const F=C(O,I);F!==w.current&&(w.current=F,k.current?.(F??null))},[t,e,C]);const S=(O,I,F)=>{const U=A[I]||I;o?.([O,U],F)},N=O=>{const I=O.target.value,F=s.current?s.current.value:e.default,U=C(I,F);l(I),S(I,F,U)},j=O=>{const I=O.target.value,F=c.current?c.current.value:String(t[0]??""),U=C(F,I);f(I),s.current&&(s.current.value=I),S(F,I,U)},M=O=>{const I=c.current?c.current.value:String(t[0]??""),F=parseFloat(I),U=s.current?s.current.value:e.default;if(C(I,U)||!I.trim()||!Number.isFinite(F))return;const ce=O.currentTarget.getBoundingClientRect(),he=ce.left,be=ce.bottom;b({x:he,y:be});const Z=Vt(F,U,e);if(Z.length===0){x([]),y(!1);return}x(Z),y(D=>!D)},$=O=>{const{value:I,unit:F}=O;y(!1),b(null),c.current&&(c.current.value=I),s.current&&(s.current.value=F),l(I),f(F);const U=C(I,F);S(I,F,U)},E=String(t[0]??""),z=ue(t[1]??e.default,e)||(t[1]??e.default),B=d??E,X=!!C(B,m??z)||!B.trim(),pe={width:"var(--reactaform-unit-btn-width, 2.5em)",height:"var(--reactaform-unit-btn-height, 2.5em)",padding:"var(--reactaform-unit-btn-padding, 0)",border:"none",borderRadius:"var(--reactaform-button-border-radius, var(--reactaform-border-radius, 0.25em))",backgroundColor:X?"var(--reactaform-button-disabled-bg, #cccccc)":"var(--reactaform-button-bg, var(--reactaform-success-color))",color:"var(--reactaform-button-text, #ffffff)",cursor:X?"var(--reactaform-button-disabled-cursor, not-allowed)":"pointer",opacity:X?+"var(--reactaform-button-disabled-opacity, 0.6)":1,display:"flex",alignItems:"center",justifyContent:"center"},Y=C(E,z);return g.jsx(T,{field:r,error:Y,children:g.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--reactaform-unit-gap, 8px)",width:"100%"},children:[g.jsx("input",{id:r.name,type:"text",ref:c,defaultValue:String(t[0]??""),onChange:N,style:{width:"var(--reactaform-unit-input-width, 100px)"},className:q(R.input,R.textInput),"aria-invalid":!!Y,"aria-describedby":Y?`${r.name}-error`:void 0}),g.jsx("select",{id:`${r.name}-unit`,ref:s,defaultValue:ue(t[1]??e.default,e)||(t[1]??e.default),onChange:j,className:q(R.input,R.inputSelect),"aria-invalid":!!Y,"aria-describedby":Y?`${r.name}-error`:void 0,children:Object.keys(e.labels).map(O=>g.jsx("option",{value:O,children:e.labels[O]??O},O))}),g.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[g.jsx("button",{onClick:M,"aria-disabled":X,disabled:X,style:pe,className:R.button,children:g.jsx("span",{style:{fontSize:"var(--reactaform-unit-btn-icon-size, 1em)",lineHeight:"1",transform:"translateY(-1px)",pointerEvents:"none"},children:"⟷"})}),p&&v&&g.jsx(It,{pos:h,options:v,onClose:()=>{b(null),y(!1)},onClickOption:$})]})]})})};function Dt({field:e,value:r,onChange:t}){const{t:o}=V(),n=e.dimension;if(!n)return null;ie[n]||Mt(n,o);const a=ie[n];return a?g.jsx(Ft,{unitFactors:a,field:e,value:r,onChange:t}):null}const Je=/^(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$/i,Ge=e=>{try{return new URL(e),!0}catch{return!1}},zt=({field:e,value:r,onChange:t,onError:o})=>{const{t:n,definitionName:a}=V(),u=i.useRef(null),c=i.useCallback(f=>{const p=f.trim();if(p==="")return e.required?n("Value required"):null;if(!Je.test(p)&&!Ge(p)){const h=e.allowRelative===!0;let b=!1;if(Je.test(p)||Ge(p))b=!0;else if(h)try{new URL(p,"http://example.com"),b=!0}catch{b=!1}if(!b)return n("Must be a valid URL")}return L(a,e,p,n)??null},[a,e,n]),s=f=>{const p=f.target.value,y=c(p);t?.(p.trim(),y)},d=i.useRef(null),l=i.useRef(o);i.useEffect(()=>{l.current=o},[o]),i.useEffect(()=>{const f=r??"",p=c(f);u.current&&u.current.value!==String(f)&&(u.current.value=String(f)),p!==d.current&&(d.current=p,l.current?.(p??null))},[r,c]);const m=i.useMemo(()=>c(String(r??"")),[r,c]);return g.jsx(T,{field:e,error:m,children:g.jsx("input",{id:e.name,type:"url",defaultValue:String(r??""),ref:u,onChange:s,style:{alignItems:"left"},className:q(R.input,R.textInput),placeholder:"https://example.com","aria-invalid":!!m,"aria-describedby":m?`${e.name}-error`:void 0})})},Re=new me,Ot=new Set(["checkbox","switch","dropdown","radio","multi-selection","slider","stepper","color","rating"]),mr={checkbox:Kr,color:Gr,date:Xr,dropdown:Zr,email:et,file:tt,float:it,"float-array":st,image:lt,int:dt,"int-array":ft,"multi-selection":gt,multiline:pt,password:Ct,phone:yt,radio:xt,rating:St,separator:rt,slider:kt,string:Ke,stepper:bt,switch:Et,text:Ke,time:Nt,unit:Dt,url:zt};function dr(e,r,t){const o=r;if(!t&&e in mr){console.warn(`Can't Overwrite Base Component type "${e}".`);return}if(Ot.has(e)){Re.register(e,o);return}const n=a=>{const{callback:c,cancel:s}=Ze((...d)=>{const l=a.onChange;typeof l=="function"&&l(...d)},200);return i.useEffect(()=>()=>{s()},[s]),i.createElement(o,{...a,onChange:c})};Re.register(e,n)}function Fe(e,r){dr(e,r,!1)}function De(e){return Re.get(e)}let Ye=!1;function pr(){Ye||(Object.entries(mr).forEach(([e,r])=>{dr(e,r,!0)}),Ye=!0)}const ze=new me;function Oe(e,r){ze.register(e,r)}function Lt(e){return ze.get(e)}function Pt(e){return ze.get(e)}Oe("Preset_AlertSubmitHandler",(e,r,t)=>{const o={name:r||"Unnamed Instance",version:e.version,definition:e.name,values:t},n=JSON.stringify(o,null,2);alert(n)});const ee=new Map,_={components:new Map,fieldValidators:new Map,formValidators:new Map,submissionHandlers:new Map};function gr(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 Tt(e){const r=[];if(e.components){for(const t of Object.keys(e.components))if(De(t)){const n=_.components.get(t);n&&n!==e.name&&r.push({type:"component",name:t,existingPlugin:n,newPlugin:e.name})}}if(e.fieldValidators)for(const[t,o]of Object.entries(e.fieldValidators))for(const n of Object.keys(o)){const u=_.fieldValidators.get(t)?.get(n);sr(t,n)&&u&&u!==e.name&&r.push({type:"fieldValidator",name:`${t}:${n}`,existingPlugin:u,newPlugin:e.name})}if(e.formValidators)for(const t of Object.keys(e.formValidators)){const o=ir(t),n=_.formValidators.get(t);o&&n&&n!==e.name&&r.push({type:"formValidator",name:t,existingPlugin:n,newPlugin:e.name})}if(e.submissionHandlers)for(const t of Object.keys(e.submissionHandlers)){const o=Pt(t),n=_.submissionHandlers.get(t);o&&n&&n!==e.name&&r.push({type:"submissionHandler",name:t,existingPlugin:n,newPlugin:e.name})}return r}function fe(e,r,t,o,n,a,u,c){for(const s of Object.keys(e)){let d;if(c?d=n.find(l=>l.type==="fieldValidator"&&l.name===`${c}:${s}`):e===o.components?d=n.find(l=>l.type==="component"&&l.name===s):e===o.formValidators?d=n.find(l=>l.type==="formValidator"&&l.name===s):e===o.submissionHandlers&&(d=n.find(l=>l.type==="submissionHandler"&&l.name===s)),gr(d||null,a,u))if(c){const l=r.get(c)||new Map;l.set(s,o.name),r.set(c,l),t(s,e[s])}else r.set(s,o.name),t(s,e[s])}}function Ht(e,r){const t=r?.conflictResolution||"error";if(ee.has(e.name)){const n={type:"plugin",name:e.name,existingPlugin:e.name,newPlugin:e.name};if(!gr(n,t,r?.onConflict))return}const o=Tt(e);if(e.components&&fe(e.components,_.components,Fe,e,o,t,r?.onConflict),e.fieldValidators)for(const[n,a]of Object.entries(e.fieldValidators))fe(a,_.fieldValidators,(u,c)=>ar(n,u,c),e,o,t,r?.onConflict,n);e.formValidators&&fe(e.formValidators,_.formValidators,or,e,o,t,r?.onConflict),e.submissionHandlers&&fe(e.submissionHandlers,_.submissionHandlers,Oe,e,o,t,r?.onConflict),e.setup&&e.setup(),ee.set(e.name,e)}function qt(e,r=!1){const t=ee.get(e);if(!t)return!1;if(t.cleanup&&t.cleanup(),r){if(t.components)for(const o of Object.keys(t.components))_.components.delete(o);if(t.fieldValidators)for(const[o,n]of Object.entries(t.fieldValidators)){const a=_.fieldValidators.get(o);if(a){for(const u of Object.keys(n))a.delete(u);a.size===0&&_.fieldValidators.delete(o)}}if(t.formValidators)for(const o of Object.keys(t.formValidators))_.formValidators.delete(o);if(t.submissionHandlers)for(const o of Object.keys(t.submissionHandlers))_.submissionHandlers.delete(o)}return ee.delete(e),!0}function Bt(e){return ee.get(e)}function Ut(){return Array.from(ee.values())}function Wt(e){return ee.has(e)}function _t(e){for(const[r,t]of Object.entries(e))Fe(r,t)}const hr=i.memo(({field:e,value:r,handleChange:t,handleError:o})=>{const n=De(e.type),a=i.useCallback((c,s)=>t(e.name,c,s),[t,e.name]),u=i.useCallback(c=>o?.(e.name,c),[o,e.name]);return n?g.jsx(n,{field:e,value:r,onChange:a,onError:u}):null},(e,r)=>e.field===r.field&&e.value===r.value&&e.handleChange===r.handleChange&&e.handleError===r.handleError);hr.displayName="FieldWrapper";const br=(e,r,t,o)=>g.jsx(hr,{field:e,value:r[e.name],handleChange:t,handleError:o},e.name),yr=i.memo(({groupName:e,isOpen:r,fields:t,valuesMap:o,handleChange:n,handleError:a,toggleGroup:u,t:c})=>{const s=i.useCallback(()=>u(e),[u,e]),{formStyle:d,fieldStyle:l}=V(),m=i.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)",...d?.fieldset||{},...l?.fieldset||{}}),[d,l]),f=i.useMemo(()=>({fontWeight:"bold",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0 var(--reactaform-space, 8px)",color:"var(--reactaform-text-color, inherit)",...d?.legend||{},...l?.legend||{}}),[d,l]);return g.jsxs("fieldset",{style:m,children:[g.jsxs("legend",{onClick:s,style:f,children:[g.jsx("span",{children:c(e)}),g.jsx("span",{children:r?"▼":"▶"})]}),r&&t.map(p=>g.jsx("div",{children:br(p,o,n,a)},p.name))]})});yr.displayName="FieldGroup";const Kt=(e,r,t,o,n,a,u,c,s)=>{const d=r.slice(0,c).filter(p=>u[p.name]),m=Pr(d).groups,f=[];return m.forEach(p=>{if(p.name){const y=e[p.name]??!0;f.push(g.jsx(yr,{groupName:p.name,isOpen:y,fields:p.fields,valuesMap:t,handleChange:n,handleError:a,toggleGroup:s,t:o},p.name))}else p.fields.forEach(y=>f.push(g.jsx("div",{children:br(y,t,n,a)},y.name)))}),f},Jt=e=>{const r={};return e.forEach(t=>{r[t.name]=!1}),r},Le=(e,r,t,o)=>{const n=r[e];if(!n||!n.children)return;const a=t[e],u=a!=null?String(a):"",c=n.children[u];!c||!Array.isArray(c)||c.forEach(s=>{typeof s=="string"&&(o[s]=!0,Le(s,r,t,o))})},xr=(e,r,t)=>{const o=r[e];!o||!o.children||Object.values(o.children).filter(Array.isArray).flat().forEach(n=>{typeof n=="string"&&n in t&&(t[n]=!1,xr(n,r,t))})},Gt=(e,r,t,o)=>{const n={...t};return e.forEach(a=>{(!a.parents||Object.keys(a.parents).length===0)&&(n[a.name]=!0,Le(a.name,o,r,n))}),n},Yt=(e,r,t,o,n)=>{const a={...e};if(xr(o,r,a),n!=null){const u=r[o];if(u&&u.children){const c=String(n),s=u.children[c];s&&Array.isArray(s)&&s.forEach(d=>{typeof d=="string"&&(a[d]=!0,Le(d,r,t,a))})}}return a};async function Xt(e,r,t,o,n){const a=Object.values(n).filter(Boolean);if(a.length>0)return{success:!1,message:o("Please fix validation errors before submitting."),errors:a};const u={...t},c=[];if(e&&Array.isArray(e.properties))for(const d of e.properties){const l=d.name,m=u[l];if(m==null)continue;const f=d.type;try{if(f==="int"||f==="number"||f==="float"){const p=String(m).trim();if(p==="")u[l]=0;else{const y=Number(p);isNaN(y)?c.push(o("Invalid number format for field {{1}}",d.displayName||l)):u[l]=y}}else if(f==="int-array"||f==="float-array"){const p=String(m).split(",").map(b=>b.trim()).filter(Boolean),y=[];let h=!1;for(const b of p){const v=Number(b);if(isNaN(v)){c.push(o("Invalid number {{1}} in array for field {{2}}",b,d.displayName||l)),h=!0;break}y.push(v)}h||(u[l]=y)}}catch(p){c.push(o("Error processing field {{1}}: {{2}}",d.displayName||l,p instanceof Error?p.message:String(p)))}}if(c.length>0)return{success:!1,message:o("Data transformation errors occurred."),errors:c};const s=await Ir(e,u,o);if(s&&s.length>0)return{success:!1,message:o("Validation failed"),errors:s};if(e&&typeof e.submitHandlerName=="string"){const d=Lt(e.submitHandlerName);if(d)try{const l=await d(e,r?.name??null,u,o);if(l&&l.length>0)return{success:!1,message:o("Submission failed"),errors:Array.isArray(l)?l:[String(l)]}}catch(l){return{success:!1,message:o("Submission handler error occurred"),errors:[String(l instanceof Error?l.message:l)]}}}return{success:!0,message:o("Form submitted successfully."),data:u}}const vr=({definition:e,instance:r,chunkSize:t=50,chunkDelay:o=50})=>{const{properties:n,displayName:a}=e,u=V(),{t:c,formStyle:s,language:d}=u,l={...u,definitionName:e?.name??u.definitionName},[m,f]=i.useState("en"),[p,y]=i.useState([]),[h,b]=i.useState({}),[v,x]=i.useState({}),[C,A]=i.useState({}),[w,k]=i.useState({}),[S,N]=i.useState({}),[j,M]=i.useState(null),[$,E]=i.useState(null),[z,B]=i.useState(0),[re,X]=i.useState(!1),[pe,Y]=i.useState(!1),[O,I]=i.useState(r.name||""),F=i.useRef(r),U=i.useRef(!1);i.useEffect(()=>{const D=Object.fromEntries(n.map(P=>[P.name,{...P,children:{}}]));n.forEach(P=>{P.parents&&Object.entries(P.parents).forEach(([oe,ye])=>{const ae=D[oe];ae&&ye.forEach(jr=>{ae.children||(ae.children={});const Pe=String(jr);ae.children[Pe]=[...ae.children[Pe]||[],P.name]})})}),Lr(n,D);const H=Object.values(D),W={};H.forEach(P=>{if(P.type==="unit"){const oe=typeof P.defaultValue=="number"?String(P.defaultValue):"",ye=typeof P.defaultUnit=="string"?P.defaultUnit:String(P.defaultUnit??"m");W[P.name]=[oe,ye]}else W[P.name]=P.defaultValue}),F.current=r,Object.keys(r.values).forEach(P=>{D[P]!==void 0&&(W[P]=r.values[P])});const J=Jt(H),G={};H.forEach(P=>{P.group&&!(P.group in G)&&(G[P.group]=!0)});const te=requestAnimationFrame(()=>{y(H),b(D),x(W),A(Gt(H,W,J,D)),k(G),X(!0),I(r.name)});return()=>cancelAnimationFrame(te)},[n,r,e]),i.useEffect(()=>{if(!re||z>=p.length)return;const D=setTimeout(()=>{B(H=>Math.min(H+t,p.length))},o);return()=>clearTimeout(D)},[re,z,p.length,t,o]);const ge=i.useCallback((D,H,W)=>{M(null),E(null),x(J=>{const G={...J,[D]:H},te=h[D];return te&&["checkbox","dropdown","multi-select","radio","switch"].includes(te.type)&&A(oe=>Yt(oe,h,G,D,String(H))),G}),N(J=>W?{...J,[D]:W}:Object.fromEntries(Object.entries(J).filter(([te])=>te!==D)))},[h,M,E]);i.useEffect(()=>{let D=0;return D=requestAnimationFrame(()=>{d!==m&&(f(d||"en"),M(null),E(null))}),()=>cancelAnimationFrame(D)},[d,m]),i.useEffect(()=>{let D=0;return D=requestAnimationFrame(()=>{if(U.current){U.current=!1,F.current=r,I(r.name||"");return}F.current=r,M(null),E(null),I(r.name||"")}),()=>cancelAnimationFrame(D)},[r,r.name]);const ce=i.useCallback((D,H)=>{N(W=>H?{...W,[D]:String(H)}:Object.fromEntries(Object.entries(W).filter(([G])=>G!==D)))},[]),he=async()=>{U.current=!0;const D=F.current?.name;F.current.name=O;const H=await Xt(e,F.current,v,c,S),W=typeof H.message=="string"?H.message:String(H.message),J=Object.values(H.errors??{}).join(`
|
|
288
|
-
`);
|
|
289
|
-
`+J:W),E(H.success),H.success||(F.current.name=D??F.current.name,I(D??""))},be=D=>{k(H=>({...H,[D]:!H[D]}))},Z=i.useMemo(()=>Object.values(S).some(Boolean),[S]);return g.jsx(Ee.Provider,{value:l,children:g.jsxs("div",{style:s.container,children:[a&&g.jsx("h2",{style:s.titleStyle,children:c(a)}),j&&g.jsxs("div",{role:"status",style:{marginBottom:12,padding:12,borderRadius:6,backgroundColor:$?"rgba(76, 175, 80, 0.12)":"rgba(225, 29, 72, 0.06)",border:`1px solid ${$?"rgba(76,175,80,0.3)":"rgba(225,29,72,0.12)"}`,color:$?"var(--reactaform-success-color, #4CAF50)":"var(--reactaform-error-color, #e11d48)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[g.jsx("div",{style:{whiteSpace:"pre-wrap",flex:1},children:j}),g.jsx("button",{onClick:()=>{M(null),E(null)},"aria-label":c("Dismiss"),style:{marginLeft:12,background:"transparent",border:"none",cursor:"pointer",color:"inherit",fontSize:16,lineHeight:1},children:"×"})]}),r&&g.jsx(rr,{name:O,onChange:D=>{I(D),M(null),E(null)}}),g.jsxs(g.Fragment,{children:[Kt(w,p,v,c,ge,ce,C,z,be),z<p.length&&g.jsx("div",{style:{fontSize:"0.9em",color:"var(--reactaform-text-muted, #666)"}})]}),g.jsx("button",{onClick:he,disabled:Z,onMouseEnter:()=>Y(!0),onMouseLeave:()=>Y(!1),style:{padding:"var(--reactaform-button-padding, var(--reactaform-space) 12px)",backgroundColor:Z?"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:Z?"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:Z?"var(--reactaform-button-disabled-opacity, 0.6)":pe?"var(--reactaform-button-hover-opacity, 0.9)":"1"},children:c("Submit")})]})})};pr();const Zt=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"}}),Qt=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
|
|
300
|
+
`,je=J.createContext(void 0),O=()=>{const e=J.useContext(je);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=J.useRef(),o=J.useRef(e),a=J.useRef(null),c=t?.leading===!0,s=t?.trailing!==!1;J.useEffect(()=>{o.current=e},[e]),J.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]);const i=p=>{o.current(...p)},m=J.useCallback(()=>{n.current&&(clearTimeout(n.current),n.current=void 0),a.current=null},[]),l=J.useCallback(()=>{n.current&&s&&a.current&&(clearTimeout(n.current),n.current=void 0,i(a.current),a.current=null)},[s]);return{callback:J.useCallback((...p)=>{if(tr){i(p);return}const g=c&&!n.current;a.current=p,g&&i(p),n.current&&clearTimeout(n.current),n.current=setTimeout(()=>{n.current=void 0,s&&a.current&&(i(a.current),a.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,o])=>{o&&r.push(n)}));return r.join(" ")};function ce(e){return e.toLowerCase().includes("dark")}function Br(e){if(!e)return!1;const r=e.trim();let t=0,n=0,o=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),o=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),o=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]),o=parseFloat(c[2]))}else return!1;return(t*299+n*587+o*114)/1e3<128}const qr=()=>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"})]}),Ur=({content:e,size:r="medium",animation:t=!0})=>{const{t:n,theme:o,formStyle:a,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),M=u.useRef(null),S=u.useId(),x=ce(o),[j,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=Br(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:j??(x?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.1)"),color:`var(--reactaform-text-color, ${x?"#f0f0f0":"#333"})`,border:`1px solid ${x?"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, ${x?"rgba(45,45,45,0.95)":"rgba(34, 10, 170, 0.92)"})`,color:`var(--reactaform-tooltip-color, ${x?"#f0f0f0":"#fff"})`,borderRadius:"6px",border:`1px solid ${x?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.1)"}`,boxShadow:x?"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,F,I)=>{const T=k?.[F];return(I&&T?T[I]:void 0)??{}};return{icon:{...h.icon,...y(a,"tooltip","icon"),...y(c,"tooltip","icon")},text:{...h.text,...y(a,"tooltip","text"),...y(c,"tooltip","text")},textVisible:h.textVisible}},[x,r,t,a,c,j]);u.useLayoutEffect(()=>{if(!s||!g.current||!w.current){p(!1);return}const b=g.current.getBoundingClientRect();M.current=b;const h=w.current.getBoundingClientRect(),y=8,C=window.innerWidth,k=window.innerHeight,F=-4;let I=b.right+y,A=b.top+b.height/2-h.height/2+F;I+h.width>C-y&&(I=b.left-y-h.width),I=Math.max(y,Math.min(I,C-h.width-y)),A=Math.max(y,Math.min(A,k-h.height-y)),l({x:I,y:A}),p(!0);const T=g.current.closest("[data-reactaform-theme]"),Z=document.getElementById("popup-root");if(T&&Z){const ne=getComputedStyle(T);Z.style.setProperty("--reactaform-tooltip-color-bg",ne.getPropertyValue("--reactaform-tooltip-color-bg")),Z.style.setProperty("--reactaform-tooltip-color",ne.getPropertyValue("--reactaform-tooltip-color"))}},[s]);const v=typeof document<"u"?document.getElementById("popup-root"):null,N=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(qr,{})}),s&&(v?fe.createPortal(N,v):N)]})},or=u.memo(Ur),ye=u.memo(({field:e,error:r,children:t,showLabel:n=!0})=>{const{t:o}=O(),a=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"]=a,m},[a]),s=u.useMemo(()=>({textAlign:a,width:"100%",minWidth:"unset",display:"block",marginBottom:"10px"}),[a]),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:o(e.displayName)}),f.jsxs("div",{style:i,children:[f.jsx("div",{style:{flex:1,minWidth:0},children:t}),e.tooltip&&f.jsx(or,{content:e.tooltip})]}),r&&f.jsx(ke,{id:`${e.name}-error`,children:r})]})});ye.displayName="ColumnFieldLayout";const ar=u.memo(({field:e,error:r,children:t,rightAlign:n=!1})=>{const{t:o}=O(),a=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:o(e.displayName)}),f.jsxs("div",{children:[f.jsxs("div",{style:a,children:[n?f.jsx("div",{style:{display:"flex",flex:1,justifyContent:"flex-end"},children:t}):t,e.tooltip&&f.jsx(or,{content:e.tooltip})]}),r&&f.jsx(ke,{id:`${e.name}-error`,children:r})]})]})});ar.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(ar,{field:e,error:r,rightAlign:n,children:t}));P.displayName="StandardFieldLayout";const ke=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})});ke.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 Wr extends ie{registerInCategory(r,t,n){this.get(r)||this.register(r,{});const o=this.get(r);o[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 Wr,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($t(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 _r(e){return(typeof e=="object"||typeof e=="function")&&e!==null&&typeof e.then=="function"}const He=new Map,Be=new Map;function Fe(e,r,t,n){if(!r||!r.validationHandlerName)return null;let o,a;if(typeof r.validationHandlerName=="string")o=e,a=r.validationHandlerName;else if(Array.isArray(r.validationHandlerName)){const[i,m]=r.validationHandlerName;if(m)o=i,a=m;else if(i)o=e,a=i;else return null}else return null;const c=`${o}:${a}`;let s=He.get(c);if(s===void 0&&(s=fr(o,a)||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 Kr(e,r,t,n){return Fe(e,r,t,n)}function gr(e,r,t,n){const o=pr(r.type);if(o){const a=o(r,t,n);if(a)return a}else if(String(t??"").trim()==="")return r.required?n("Value required"):null;return Fe(e,r,t,n)}async function Jr(e,r,t){if(!e||typeof e.validationHandlerName!="string")return null;const n=e.validationHandlerName;let o=Be.get(n);if(o===void 0&&(o=dr(n)||null,Be.set(n,o)),o)try{const a=o(r,t);return _r(a)?await a||null:a||null}catch(a){return[String(a instanceof Error?a.message:a)]}return null}function z(e,r){const{definitionName:t,t:n,fieldValidationMode:o}=O();return u.useCallback(a=>o==="realTime"?gr(t,e,a,n):r??null,[t,e,n,o,r])}const Gr=({field:e,value:r=!1,onChange:t,onError:n,error:o})=>{const{t:a}=O(),s=z(e,o)(r);u.useEffect(()=>{o||n?.(s)},[s,o,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:a(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 o=u.useRef(null),a=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===o.current)){const p=n(l);p!==a.current&&(a.current=p,c.current?.(p??null),i(p)),o.current&&o.current.value!==l&&(o.current.value=l)}},[e,n]);const m=u.useCallback(l=>{const d=l.target.value,p=n(d);p!==a.current&&(a.current=p,i(p),c.current?.(p??null)),r?.(d)},[r,n]);return{inputRef:o,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"}],Yr=/^#([0-9A-F]{3}){1,2}$/i,Xr="#000000",Zr=e=>Yr.test(e),pe=e=>{if(!e||!Zr(e))return Xr;const r=e.toLowerCase();return r.length===4?"#"+r.slice(1).split("").map(t=>t+t).join(""):r},Qr=e=>{const r=parseInt(e.slice(1),16);return{r:r>>16&255,g:r>>8&255,b:r&255}},et=({field:e,value:r,onChange:t,onError:n,error:o})=>{const{t:a}=O(),c=z(e,o),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(()=>{o||n?.(m)},[m,o,n]),u.useEffect(()=>{p(s)},[s]);const g=u.useCallback(E=>{const v=pe(E.target.value);p(v),l({target:{value:v}})},[l]),w=u.useCallback(E=>{const v=pe(E.target.value);p(v),l({target:{value:v}})},[l]),S=u.useMemo(()=>new Set(qe.map(E=>E.value)),[]).has(d),{r:x,g:j,b:V}=u.useMemo(()=>Qr(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:a(E.label)},E.value)),!S&&f.jsxs("option",{value:d,children:["(",x,", ",j,", ",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(),o=String(t.getUTCMonth()+1).padStart(2,"0"),a=String(t.getUTCDate()).padStart(2,"0");return`${n}-${o}-${a}`}return""},rt=({field:e,value:r,onChange:t,onError:n,error:o})=>{const a=z(e,o),c=We(r),{inputRef:s,error:i,handleChange:m}=W({value:c,onChange:t,onError:n,validate:a});return u.useEffect(()=>{o||n?.(i)},[i,o,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})})},tt=({field:e,value:r,onChange:t,onError:n,error:o})=>{const{t:a,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 M=z(e,o),[S,x]=u.useState(null),j=u.useRef(null);u.useEffect(()=>{const y=String(r??"");let C=M(y);if(C&&e.options.length>0){const k=String(e.options[0].value);t?.(k),C=null}C!==j.current&&(j.current=C,x(C),l.current?.(C??null))},[r,M,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=M(y);C!==j.current&&(j.current=C,x(C),l.current?.(C??null)),t?.(y),p(!1)},v=u.useMemo(()=>{const y=e.options.find(C=>String(C.value)===String(r));return y?a(y.label):""},[e.options,r,a]),N=(y,C,k)=>{if(!C)return{};const I=y?.[C];return(k&&I?I[k]:void 0)??{}},b=u.useMemo(()=>({height:"var(--reactaform-input-height, 2.5rem)",display:"flex",alignItems:"center",cursor:"pointer",position:"relative",...N(s,"dropdown","control"),...N(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)",...N(s,"dropdown","arrow"),...N(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:v}),f.jsx("span",{style:h,"aria-hidden":!0,children:"▼"})]})}),d&&g&&f.jsx(nt,{position:g,options:e.options,selectedValue:String(r),onSelect:E,onClose:()=>p(!1),controlRef:m,theme:c,t:a})]})},nt=({position:e,options:r,selectedValue:t,onSelect:n,onClose:o,controlRef:a,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(!a.current)return;const h=a.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"))}},[a]);const w=(h,y,C)=>{if(!y)return{};const F=h?.[y];return(C&&F?F[C]:void 0)??{}},M=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)&&!a.current?.contains(C)&&o()};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[o,a]),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 x=250,j=200,[V,E]=u.useState(null),[v,N]=u.useState(null);if(u.useEffect(()=>{if(typeof window>"u")return;const h=()=>{let k=e.x,F=e.y,I=x;const A=a?.current;if(A){const T=A.getBoundingClientRect();k=T.left,F=T.bottom,I=Math.max(80,Math.round(T.width))}k=Math.min(k,window.innerWidth-I),F=Math.min(F,window.innerHeight-j),E({left:k,top:F}),N(I)};h(),window.addEventListener("scroll",h,!0),window.addEventListener("resize",h);let y=null;const C=a?.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)}},[a,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:v??x,...M},"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)",F={...S,background:y===m?k:S.background,fontWeight:C?"bold":"normal"};return f.jsx("div",{id:`opt-${y}`,onMouseDown:I=>{I.stopPropagation(),n(String(h.value))},onKeyDown:I=>{const A=r.length;switch(I.key){case"ArrowDown":I.preventDefault(),l(T=>(T+1)%A);break;case"ArrowUp":I.preventDefault(),l(T=>(T-1+A)%A);break;case"Home":I.preventDefault(),l(0);break;case"End":I.preventDefault(),l(A-1);break;case"Enter":case" ":I.preventDefault(),I.stopPropagation(),n(String(h.value));break;case"Escape":I.preventDefault(),o(),a?.current?.focus();break}},tabIndex:y===m?0:-1,role:"option","aria-selected":C,style:F,onMouseEnter:I=>{I.currentTarget.style.background=k,l(y)},onMouseLeave:I=>{I.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:o})=>{const a=z(e,o),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:a});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})})},at=({field:e})=>{const{theme:r}=O(),{color:t=ce(r)?"#444444":"#CCCCCC",thickness:n=1,margin:o="8px 0"}=e;return f.jsx("div",{style:{width:"auto",height:"0",borderTop:`${n}px solid ${t}`,margin:o}})},st=({field:e,value:r,onChange:t,onError:n,error:o})=>{const{t:a}=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=(v,N)=>N.some(b=>b.name===v.name&&b.size===v.size&&b.lastModified===v.lastModified),w=z(e,o);u.useEffect(()=>{const v=w(r??[]);t?.(r),v!==l.current&&(l.current=v,p(v),m.current?.(v??null))},[r,w]);const M=v=>{const N=v.target.files;let b=null;if(N&&N.length>0){const y=Array.from(N);if(e.multiple){const C=Array.isArray(r)?r:[],k=y.filter(F=>!g(F,C));b=[...C,...k]}else b=y[0]}const h=w(b??[]);h!==l.current&&(l.current=h,p(h),m.current?.(h??null)),t?.(b),v.target&&(v.target.value="")},S=v=>{v.preventDefault(),v.stopPropagation(),s(!1);const N=v.dataTransfer.files;if(N&&N.length>0){const b=Array.from(N);let h=null;if(e.multiple){const C=Array.isArray(r)?r:[],k=b.filter(F=>!g(F,C));h=[...C,...k]}else h=b[0];const y=w(h);y!==l.current&&(l.current=y,p(y),m.current?.(y??null)),t?.(h)}},x=v=>{v.preventDefault(),v.stopPropagation(),s(!0)},j=v=>{v.preventDefault(),v.stopPropagation(),s(!1)},V=v=>{if(Array.isArray(r)&&typeof v=="number"){const N=r.filter((y,C)=>C!==v),b=N.length>0?N:null,h=w(b??[]);h!==l.current&&(l.current=h,p(h),m.current?.(h??null)),t?.(b)}else{const N=w([]);N!==l.current&&(l.current=N,p(N),m.current?.(N??null)),t?.(null)}},E=()=>{const v=Array.isArray(r)?r:r?[r]:[];return v.length===0?null:f.jsx("div",{style:{marginTop:"8px",marginLeft:"20px",display:"flex",flexDirection:"column",gap:"6px",maxHeight:"200px",overflowY:"auto"},children:v.map((N,b)=>f.jsxs("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[f.jsx("input",{type:"text",value:N.name,disabled:!0,readOnly:!0,title:N.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":a("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:"×"})]},`${N.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:x,onDragLeave:j,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:v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),i.current?.click())},role:"button","aria-label":e.multiple?a("Choose Files or Drag & Drop"):a("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:M}),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?a("Drop files here"):e.multiple?a("Choose Files or Drag & Drop"):a("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()]})})},it=({field:e,value:r,onChange:t,onError:n,error:o})=>{const a=z(e,o),c=Array.isArray(r)?r.join(", "):String(r??""),{inputRef:s,error:i,handleChange:m}=W({value:c,onChange:t,onError:n,validate:a});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})})},ct=({field:e,value:r,onChange:t,onError:n,error:o})=>{const a=z(e,o),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:a}),m=o??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 lt(){try{return"/"}catch{}try{if(typeof process<"u"&&process?.env?.PUBLIC_URL)return process.env.PUBLIC_URL}catch{}return"/"}const ut=({field:e,value:r})=>{const{language:t,t:n}=O(),o=e.alignment||"center",a={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=`${lt()}${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("/"),x=S.pop(),j=x.lastIndexOf(".");if(j===-1)return;const V=x.substring(0,j),E=x.substring(j);let v=null;i?.includes(t)&&(v=`${V}_${t}${E}`);const N=new AbortController;if(v){const b=[...S,v].join("/");fetch(b,{method:"HEAD",signal:N.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()=>{N.abort()}},[s,t,i]),!m)return null;const{width:p,height:g}=e,w={},M={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,M.width=`${p}px`,M.height=`${g}px`):p&&!g?(w.width=p,M.width=`${p}px`,M.height="auto"):!p&&g&&(w.height=g,M.width="auto",M.height=`${g}px`),f.jsx(P,{field:e,children:f.jsx("div",{"data-testid":"image-wrapper",style:{display:"flex",justifyContent:a[o]||"center",margin:"0 0"},children:f.jsx("img",{src:m,alt:n?.(e.displayName||"Image")||e.displayName||"Image",...w,style:M})})})},mt=({field:e,value:r,onChange:t,onError:n,error:o})=>{const a=z(e,o),c=Array.isArray(r)?r.join(", "):String(r??""),{inputRef:s,error:i,handleChange:m}=W({value:c,onChange:t,onError:n,validate:a});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:o})=>{const a=z(e,o),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:a});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 ft=u.memo(hr),dt=({field:e,value:r,onChange:t,onError:n,error:o})=>{const a=z(e,o),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:a});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})})},pt=({field:e,value:r,onChange:t,onError:n,error:o})=>{const a=u.useRef(n);u.useEffect(()=>{a.current=n},[n]);const{t:c,theme:s,formStyle:i,fieldStyle:m}=O(),l=(k,F,I)=>{if(!F)return{};const T=k?.[F];return(I&&T?T[I]:void 0)??{}},d=u.useRef(null),[p,g]=u.useState(!1),[w,M]=u.useState(null),S=u.useMemo(()=>e.options.map(k=>({value:k.value,label:c(k.label)})),[e.options,c]),x=u.useMemo(()=>{const k=Array.isArray(r)?r:[],F=new Set(S.map(I=>I.value));return k.filter(I=>F.has(I))},[r,S]),j=z(e,o),[V,E]=u.useState(null),v=u.useRef(null);u.useEffect(()=>{const k=j(Array.isArray(r)?r:[]);k!==v.current&&(v.current=k,E(k),a.current?.(k??null))},[r,j]);const N=()=>{if(!d.current)return;const k=d.current.getBoundingClientRect();M({x:k.left,y:k.bottom}),g(F=>!F)},b=k=>{const F=x.includes(k)?x.filter(A=>A!==k):[...x,k],I=j(F);I!==v.current&&(v.current=I,E(I),a.current?.(I??null)),t?.(F)},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:N,role:"button","aria-haspopup":"listbox","aria-expanded":p,"aria-invalid":!!V,"aria-describedby":V?`${e.name}-error`:void 0,onKeyDown:k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),N())},children:[f.jsxs("span",{style:{flex:1,color:"var(--reactaform-text-muted, #888)"},children:[x.length," / ",S.length," selected"]}),x.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&&w&&f.jsx(gt,{position:w,options:S,selectedValues:x,onToggleOption:b,onClose:()=>g(!1),controlRef:d,theme:s})]})},gt=({position:e,options:r,selectedValues:t,onToggleOption:n,onClose:o,controlRef:a,theme:c})=>{const s=u.useRef(null),[i,m]=u.useState(-1),{formStyle:l,fieldStyle:d}=O(),p=ce(c??"light");u.useLayoutEffect(()=>{if(!a.current)return;const b=a.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"))}},[a]);const g=(b,h,y)=>{if(!h)return{};const k=b?.[h];return(y&&k?k[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]),M=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)&&!a.current?.contains(y)&&o()};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[o,a]),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,x=200,[j,V]=u.useState(null),[E,v]=u.useState(null);if(u.useEffect(()=>{if(typeof window>"u")return;const b=()=>{let C=e.x,k=e.y,F=S;const I=a?.current;if(I){const A=I.getBoundingClientRect();C=A.left,k=A.bottom,F=Math.max(80,Math.round(A.width))}C=Math.min(C,window.innerWidth-F),k=Math.min(k,window.innerHeight-x),V({left:C,top:k}),v(F)};b(),window.addEventListener("scroll",b,!0),window.addEventListener("resize",b);let h=null;const y=a?.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)}},[a,e.x,e.y]),typeof window>"u")return null;let N=document.getElementById("popup-root");return N||(N=document.createElement("div"),N.id="popup-root",document.body.appendChild(N)),fe.createPortal(f.jsx("div",{ref:s,role:"listbox","aria-activedescendant":i>=0?`multi-opt-${i}`:void 0,style:{position:"fixed",top:j?j.top:e.y,left:j?j.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)",k={...M,background:h===i?C:M.background};return f.jsxs("div",{id:`multi-opt-${h}`,onMouseDown:F=>{F.stopPropagation(),n(b.value)},onKeyDown:F=>{const I=r.length;switch(F.key){case"ArrowDown":F.preventDefault(),m(A=>(A+1)%I);break;case"ArrowUp":F.preventDefault(),m(A=>(A-1+I)%I);break;case"Home":F.preventDefault(),m(0);break;case"End":F.preventDefault(),m(I-1);break;case"Enter":case" ":F.preventDefault(),F.stopPropagation(),n(b.value);break;case"Escape":F.preventDefault(),o(),a?.current?.focus();break}},tabIndex:h===i?0:-1,role:"option","aria-selected":y,style:k,onMouseEnter:F=>{F.currentTarget.style.background=C,m(h)},onMouseLeave:F=>{F.currentTarget.style.background="transparent",m(I=>I===h?-1:I)},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)})}),N)},ht=({field:e,value:r,onChange:t,onError:n,error:o})=>{const a=z(e,o),{inputRef:c,error:s,handleChange:i}=W({value:String(r??""),onChange:t,onError:n,validate:a}),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})})},yt=({field:e,value:r,onChange:t,onError:n,error:o})=>{const a=z(e,o),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:a});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})})},bt=({field:e,value:r,onChange:t,onError:n,error:o})=>{const{t:a}=O(),c=z(e,o),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(x=>{x!==p.current&&(p.current=x,d(x),m.current?.(x))},[]);u.useEffect(()=>{const x=r!=null?String(r):"",j=c(x);if(j&&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(j)},[r,e.options,c,t,g]);const w=x=>{const j=x.target.value,V=c(j);g(V),t?.(j)},M={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:M,children:e.options.map(x=>{const j=String(x.value);return f.jsxs("label",{className:B(R.label),style:S,children:[f.jsx("input",{type:"radio",name:e.name,value:j,checked:String(r??"")===j,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:a(x.label)})]},j)})})})},xt={display:"flex",gap:4},vt={cursor:"pointer",fontSize:"1.5rem",lineHeight:1,display:"inline-block",marginRight:"0.25rem",userSelect:"none",transition:"color 0.12s ease"},wt=({field:e,value:r,onChange:t,onError:n,error:o})=>{const{t:a}=O(),c=z(e,o),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 x=Math.min(Math.max(S,0),s);c(x),t?.(x)},[s,c,t]),M=u.useCallback((S,x)=>{switch(S.key){case"Enter":case" ":S.preventDefault(),w(x+1);break;case"ArrowRight":case"ArrowUp":S.preventDefault(),d.current[Math.min(s-1,x+1)]?.focus();break;case"ArrowLeft":case"ArrowDown":S.preventDefault(),d.current[Math.max(0,x-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,x)=>{const j=x<p,E=m!==null&&x<=m||j?"gold":"lightgray";return f.jsx("span",{ref:v=>d.current[x]=v,role:"radio",tabIndex:p>0?x===p-1?0:-1:x===0?0:-1,"aria-checked":j,"aria-label":`Rating ${x+1}`,title:a(`${e.displayName} ${x+1}`),onClick:()=>w(x+1),onKeyDown:v=>M(v,x),onMouseEnter:()=>l(x),onMouseLeave:()=>l(null),style:{...vt,color:E},children:i},x)})})})},St=({field:e,value:r,onChange:t,onError:n,error:o})=>{const{t:a}=O(),c=z(e,o),{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":a(l?"Hide password":"Show password"),style:{background:"transparent",border:"none",cursor:"pointer",fontSize:16,lineHeight:1,padding:"4px 6px",flexShrink:0},children:l?"🙈":"👁️"})]})})},Ct=({field:e,value:r,onChange:t,onError:n,error:o})=>{const a=z(e,o),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(()=>a(i)??null,[a,i]);u.useEffect(()=>{n?.(l)},[l,n]);const d=u.useCallback(g=>{const w=g.target.value;m(w),a(w),t?.(w)},[a,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:o})=>{const{t:a,formStyle:c,fieldStyle:s,fieldValidationMode:i}=O(),l=z(e,o)(r);u.useEffect(()=>{i==="realTime"&&n?.(l)},[l,i,n]);const d=c,p=s,g=(E,v,N)=>{if(!v)return{};const b=E?.[v];return(N&&b?b[N]: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]),M=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]),x=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]),j=!!r,V=()=>{t?.(!j)};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:a(e.displayName)}),f.jsxs("label",{style:w,children:[f.jsx("input",{id:e.name,type:"checkbox",checked:j,readOnly:!0,"aria-label":a(e.displayName),"aria-invalid":!1,"aria-describedby":void 0,style:M,tabIndex:-1}),f.jsx("span",{role:"switch","data-testid":"switch",tabIndex:0,"aria-checked":j,"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 ${j?"active checked on":""} `,style:j?{...S,backgroundColor:"var(--reactaform-switch-on-bg, #22c55e)",borderColor:"var(--reactaform-switch-on-border, #16a34a)"}:S,children:f.jsx("span",{style:{...x,transform:j?"translateX(20px)":void 0}})})]})]})})},_e=({field:e,value:r,onChange:t,onError:n,error:o})=>{const a=z(e,o),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:a});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})})},kt=({field:e,value:r,onChange:t,onError:n,error:o})=>{const a=z(e),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:a}),m=o??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 Et({pos:e,options:r,onClose:t,onClickOption:n}){const o=u.useRef(null),a=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){a.current||l.target.dataset?.popupMenu==="item"||o.current&&l.target instanceof Node&&!o.current.contains(l.target)&&t()}return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[t]),u.useLayoutEffect(()=>{if(!o.current||!e||e.x==null||e.y==null)return;const m=o.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:o,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(),a.current=!0},onClick:d=>{d.stopPropagation(),d.preventDefault(),n(m),t(),setTimeout(()=>{a.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 Ie={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"]},Me={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)"}},Ne={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(Ie),...Object.keys(Me),...Object.keys(Ne)]);for(const e of Ft){const r={},t=Ie[e]??[],n=Me[e]??{},o=Ne[e]??{};for(const a of t){const c=n[a];r[a]={name:typeof c=="string"?c:String(a),shortName:a,factor:Object.prototype.hasOwnProperty.call(o,a)?o[a]:void 0}}for(const[a,c]of Object.entries(n))if(!r[a]){const s=typeof c=="string"?c:String(a);r[a]={name:s,shortName:a,factor:Object.prototype.hasOwnProperty.call(o,a)?o[a]:void 0}}for(const[a,c]of Object.entries(o))r[a]||(r[a]={name:String(a),shortName:String(a),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[a,c]of Object.entries(r))typeof c.factor=="number"&&(t[a]=c.factor),n.push(a);return{default:Object.keys(r)[0]??"",units:n,factors:t}}const It=Object.freeze(Object.defineProperty({__proto__:null,convertTemperature:yr,dimensionUnitDisplayMap:Me,dimensionUnitsMap:Ie,dimensonUnitFactorsMap:Ne,getUnitFactors:br,unitsByDimension:Ve},Symbol.toStringTag,{value:"Module"})),xr=u.memo(({disabled:e,inputValue:r,selectedUnit:t,dimension:n,unitFactors:o,onConversionSelect:a,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 x=parseFloat(r);if(!Number.isFinite(x))return;const j=S.currentTarget.getBoundingClientRect();l({x:j.left,y:j.bottom});const V=[];if(n==="temperature")o.units.forEach(v=>{const N=yr(t,v,x);Number.isFinite(N)&&V.push({label:`${N.toFixed(6)} ${c(v)}`,value:N.toString(),unit:v})});else{const v=o.factors[t];v!==void 0&&Object.entries(o.factors).forEach(([N,b])=>{const h=x/v*b;Number.isFinite(h)&&V.push({label:`${h.toFixed(6)} ${c(N)}`,value:h.toString(),unit:N})})}p(V),i(V.length>0)},[e,r,t,n,o,c]),w=u.useCallback(S=>{i(!1),l(null),a(S)},[a]),M=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(Et,{pos:m,options:d,onClose:M,onClickOption:w})]})});xr.displayName="ConversionButton";const Mt=({field:e,value:r,onChange:t,onError:n})=>{const{t:o}=O(),a=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=a([l,p]);u.useEffect(()=>{n?.(w)},[w,n]);const M=u.useCallback(E=>{const v=E.target.value;d(v),a([v,p]),t?.([v,p])},[p,a,t]),S=u.useCallback(E=>{const v=E.target.value;g(v),a([l,v]),t?.([l,v])},[l,a,t]),x=u.useCallback(E=>{d(E.value),g(E.unit),t?.([E.value,E.unit])},[t]),j=u.useMemo(()=>s?s.units.map(E=>f.jsx("option",{value:E,children:o(E)},E)):[],[s,o]);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:M,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:j}),f.jsx(xr,{disabled:V,inputValue:l,selectedUnit:p,dimension:c,unitFactors:s,onConversionSelect:x,t:o})]})})},Nt=u.memo(Mt),Vt=({field:e,value:r,onChange:t,onError:n,error:o})=>{const a=z(e),{inputRef:c,error:s,handleChange:i}=W({value:r,onChange:t,onError:n,validate:a}),m=o??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})})},Rt={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:Gr,color:et,date:rt,dropdown:tt,email:ot,file:st,float:ct,"float-array":it,image:ut,int:ft,"int-array":mt,"multi-selection":pt,multiline:dt,password:St,phone:yt,radio:bt,rating:wt,separator:at,slider:Ct,string:_e,stepper:ht,switch:jt,text:_e,time:kt,unit:Nt,url:Vt};function $t(e){return e in Re}function At(e,r){const{wait:t=200,leading:n,trailing:o}=r,a=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:o});return u.useEffect(()=>m,[m]),u.createElement(e,{...c,onChange:i})});return a.displayName="DebouncedFieldWrapper",a}function vr(e,r,t){const n=r;if(!t&&e in Re){console.warn(`Can't overwrite base component type "${e}".`);return}const o=Rt[e];if(o===!1){me.register(e,n);return}const a=o??{wait:200};tr?me.register(e,n):me.register(e,At(n,a))}function $e(e,r){vr(e,r,!1)}function Ae(e){return me.get(e)}let Ke=!1;function Dt(){Ke||(Object.entries(Re).forEach(([e,r])=>{vr(e,r,!0)}),Ke=!0)}const Pt=(e,r)=>{const t=new Map;let n=null,o=null,a=0;for(const c of e){const s=c.group;if(!s){n=null,o=null;continue}if(s===n)r[c.name].group=o??s;else{if(!t.has(s))t.set(s,1),o=null,r[c.name].group=s;else{const i=t.get(s),m=`${s}(${i})`;t.set(s,i+1),o=m,r[c.name].group=m,a++}n=s}}return a},zt=(e,r={})=>{const{includeEmpty:t=!0}=r,n=[];let o=null,a=[],c=0;for(const i of e){const m=i.group||null;m!==o?((a.length>0||t)&&(a.length===0&&c++,n.push({name:o,fields:a})),o=m,a=[i]):a.push(i)}(a.length>0||t)&&(a.length===0&&c++,n.push({name:o,fields:a}));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:o})=>{const a=Ae(e.type),c=u.useMemo(()=>r,[r]),s=u.useCallback((m,l)=>t(e.name,m,l),[t,e.name]),i=u.useCallback(m=>n?.(e.name,m),[n,e.name]);return a?f.jsx(a,{field:e,value:c,onChange:s,onError:i,error:o}):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,o)=>{const a=o?o[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:a})},e.name)},Cr=u.memo(({groupName:e,isOpen:r,fields:t,valuesMap:n,handleChange:o,handleError:a,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,o,a,c))]})});Cr.displayName="FieldGroup";const Ot=(e,r,t,n,o,a,c,s,i,m)=>{const l=r.slice(0,s).filter(g=>c[g.name]),d=zt(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:o,handleError:a,errorsMap:m,toggleGroup:i,t:n},g.name))}else g.fields.forEach(w=>p.push(Sr(w,t,o,a,m)))}),p},Lt=e=>{const r={};return e.forEach(t=>{r[t.name]=!1}),r},De=(e,r,t,n)=>{const o=r[e];if(!o||!o.children)return;const a=t[e],c=a!=null?String(a):"",s=o.children[c];!s||!Array.isArray(s)||s.forEach(i=>{typeof i=="string"&&(n[i]=!0,De(i,r,t,n))})},jr=(e,r,t)=>{const n=r[e];!n||!n.children||Object.values(n.children).filter(Array.isArray).flat().forEach(o=>{typeof o=="string"&&o in t&&(t[o]=!1,jr(o,r,t))})},Tt=(e,r,t,n)=>{const o={...t};return e.forEach(a=>{(!a.parents||Object.keys(a.parents).length===0)&&(o[a.name]=!0,De(a.name,n,r,o))}),o},Ht=(e,r,t,n,o)=>{const a={...e};if(jr(n,r,a),o!=null){const c=r[n];if(c&&c.children){const s=String(o),i=c.children[s];i&&Array.isArray(i)&&i.forEach(m=>{typeof m=="string"&&(a[m]=!0,De(m,r,t,a))})}}return a},Pe=new ie;function ze(e,r){Pe.register(e,r)}function Bt(e){return Pe.get(e)}function qt(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},o=JSON.stringify(n,null,2);alert(o)});async function Ut(e,r,t,n,o){const a=Object.values(o).filter(Boolean);if(a.length>0)return{success:!1,message:n("Please fix validation errors before submitting."),errors:a};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 M=!1;for(const S of g){const x=Number(S);if(isNaN(x)){s.push(n("Invalid number {{1}} in array for field {{2}}",S,m.displayName||l)),M=!0;break}w.push(x)}M||(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=Bt(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 kr=({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;kr.displayName="SubmissionMessage";const Wt=({onClick:e,disabled:r=!1,t})=>{const[n,o]=u.useState(!1);return f.jsx("button",{onClick:e,disabled:r,onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!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:o,displayName:a}=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([]),[M,S]=u.useState({}),[x,j]=u.useState({}),[V,E]=u.useState({}),[v,N]=u.useState({}),[b,h]=u.useState({}),[y,C]=u.useState(null),[k,F]=u.useState(null),[I,A]=u.useState(0),[T,Z]=u.useState(!1),[ne,oe]=u.useState(r.name||""),Y=u.useRef(r),de=u.useRef(!1);u.useEffect(()=>{const $=Object.fromEntries(o.map(D=>[D.name,{...D,children:{}}]));o.forEach(D=>{D.parents&&Object.entries(D.parents).forEach(([X,re])=>{const ae=$[X];ae&&re.forEach(Lr=>{ae.children||(ae.children={});const Te=String(Lr);ae.children[Te]=[...ae.children[Te]||[],D.name]})})}),Pt(o,$);const H=Object.values($),q={};H.forEach(D=>{if(D.type==="unit"){const X=typeof D.defaultValue=="number"?String(D.defaultValue):"",re=typeof D.defaultUnit=="string"?D.defaultUnit:String(D.defaultUnit??"m");q[D.name]=[X,re]}else q[D.name]=D.defaultValue}),Y.current=r,Object.keys(r.values).forEach(D=>{$[D]!==void 0&&(q[D]=r.values[D])});const G=Lt(H),_={};H.forEach(D=>{D.group&&!(D.group in _)&&(_[D.group]=!0)});const K=requestAnimationFrame(()=>{w(H),S($),j(q),E(Tt(H,q,G,$)),N(_),Z(!0),oe(r.name)});return()=>cancelAnimationFrame(K)},[o,r,e]),u.useEffect(()=>{if(!T||I>=g.length)return;const $=setTimeout(()=>{A(H=>Math.min(H+t,g.length))},n);return()=>clearTimeout($)},[T,I,g.length,t,n]);const Ar=u.useCallback(($,H,q)=>{C(null),F(null),j(G=>{const _={...G,[$]:H},K=M[$];return K&&["checkbox","dropdown","multi-select","radio","switch"].includes(K.type)&&E(X=>Ht(X,M,_,$,String(H))),_}),h(G=>q?{...G,[$]:q}:Object.fromEntries(Object.entries(G).filter(([K])=>K!==$)))},[M,C,F]);u.useEffect(()=>{let $=0;return $=requestAnimationFrame(()=>{m!==d&&(p(m||"en"),C(null),F(null))}),()=>cancelAnimationFrame($)},[m,d]),u.useEffect(()=>{let $=0;return $=requestAnimationFrame(()=>{if(de.current){de.current=!1,Y.current=r,oe(r.name||"");return}Y.current=r,C(null),F(null),oe(r.name||"")}),()=>cancelAnimationFrame($)},[r,r.name]);const Dr=u.useCallback(($,H)=>{h(q=>H?{...q,[$]:String(H)}:Object.fromEntries(Object.entries(q).filter(([_])=>_!==$)))},[]),Pr=async()=>{de.current=!0;const $=Y.current?.name;Y.current.name=ne;let H=b;if(l.fieldValidationMode==="onSubmission"){const K={};if(g.forEach(D=>{const X=x[D.name];if(X===void 0)return;const re=gr(l.definitionName,D,X,s);re&&(K[D.name]=re)}),h(K),H=K,Object.keys(K).length>0){C(s("Please fix validation errors before submitting the form.")),F(!1);return}else C(null),F(null)}const q=await Ut(e,Y.current,x,s,H),G=typeof q.message=="string"?q.message:String(q.message),_=Object.values(q.errors??{}).join(`
|
|
301
|
+
`);C(_?G+`
|
|
302
|
+
`+_:G),F(q.success),q.success||(Y.current.name=$??Y.current.name,oe($??""))},zr=$=>{N(H=>({...H,[$]:!H[$]}))},Or=u.useMemo(()=>l.fieldValidationMode==="realTime"?Object.values(b).some(Boolean):!1,[b,l.fieldValidationMode]);return f.jsx(je.Provider,{value:l,children:f.jsxs("div",{style:i.container,children:[a&&f.jsx("h2",{style:i.titleStyle,children:s(a)}),f.jsx(kr,{message:y,success:k,onDismiss:()=>{C(null),F(null)},t:s}),r&&f.jsx(sr,{name:ne,onChange:$=>{oe($),C(null),F(null)}}),f.jsxs(f.Fragment,{children:[Ot(v,g,x,s,Ar,Dr,V,I,zr,b),I<g.length&&f.jsx("div",{style:{fontSize:"0.9em",color:"var(--reactaform-text-muted, #666)"},children:s(`Loading more fields... (${I}/${g.length})`)})]}),f.jsx(Wt,{onClick:Pr,disabled:Or,t:s})]})})},ge=new Map,le=new Map,te=new Set,be=new Map,_t=async e=>{try{let r={};switch(e.toLowerCase()){case"fr":r=(await Promise.resolve().then(()=>require("./common-udunqMU-.js"))).default;break;case"de":r=(await Promise.resolve().then(()=>require("./common-Awfy-0XP.js"))).default;break;case"es":r=(await Promise.resolve().then(()=>require("./common-BmlrZtLZ.js"))).default;break;case"zh-cn":r=(await Promise.resolve().then(()=>require("./common-D8L4oP0c.js"))).default;break;case"en":r={};break;default:r={}}return{success:!0,translations:r,fromCache:!1}}catch(r){return{success:!1,translations:{},error:`Failed to load common translations for ${e}: ${r}`}}},Kt=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 _t(r);return t.success&&(ge.set(r,t.translations),be.set(r,{loadedAt:new Date,size:Object.keys(t.translations).length,source:"common"})),t},Jt=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 o=await fetch(n);if(!o.ok)return o.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 ${o.status}`,fromCache:!1});const a=o.headers.get("content-type")||"";!a.includes("application/json")&&!a.includes("text/json")&&Fr()&&console.warn(`Translation file at ${n} has unexpected content-type: ${a}`);const c=await o.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 o=`Failed to load user translations: ${n instanceof Error?n.message:"Unknown error"}`;return te.add(t),{success:!1,translations:{},error:o}}};function Fr(){try{if(typeof process<"u"&&process?.env?.NODE_ENV==="development")return!0}catch{}return!1}function Gt(e,r){return r.length===0?e:e.replace(/\{\{(\d+)\}\}/g,(t,n)=>{const o=parseInt(n,10)-1,a=r[o];return a==null?t:String(a)})}const Yt=(e,r,t)=>(n,...o)=>{let a=n,c=!1;return!n||typeof n!="string"?String(n||""):(e.toLowerCase()==="en"?(a=n,c=!0):n in t?(a=t[n],c=!0):n in r?(a=r[n],c=!0):a=n,a=Gt(a,o),!c&&Fr()&&console.debug(`Missing translation for "${n}" in language "${e}"`),a)};function Xt(e){return/^[-+]?\d*$/.test(e)}function Zt(e){const r=/^[-+]?\d*$/;return e.split(",").map(t=>t.trim()).every(t=>r.test(t))}const Qt=",",en=e=>!e||e.trim()===""?[]:e.split(Qt).map(r=>r.trim()).filter(Boolean).map(r=>Number(r)),Je=(e,r,t)=>{const n=String(r);if(n.trim()==="")return e.required?t("Value required"):null;if(!Xt(n))return t("Must be a valid integer");const o=parseInt(n,10);if(Number.isNaN(o))return t("Must be a valid integer");if(e.min!==void 0&&(e.minInclusive?o<e.min:o<=e.min))return t("Must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?o>e.max:o>=e.max))return t("Must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max);if(e.step!==void 0){const a=Number(e.step);if(!Number.isInteger(a))return t("Invalid step value");if(o%a!==0)return t("Must be a multiple of {{1}}",a)}return null};function rn(e,r,t){const n=String(r);if(n.trim()==="")return e.required?t("Value required"):null;if(!Zt(n))return t("Each value must be a valid integer");const o=en(n);if(e.minCount!==void 0&&o.length<e.minCount)return t("Minimum number of values: {{1}}",`${e.minCount}`);if(e.maxCount!==void 0&&o.length>e.maxCount)return t("Maximum number of values: {{1}}",`${e.maxCount}`);for(const a of o){if(e.min!==void 0&&(e.minInclusive?a<e.min:a<=e.min))return t("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?a>e.max:a>=e.max))return t("Each value must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max)}return null}function xe(e,r,t){const n=String(r);if(n.trim()==="")return e.required?t("Value required"):null;const o=Number(n);if(Number.isNaN(o))return t("Must be a valid float");if(e.min!==void 0){const a=e.type==="slider"?!0:e.minInclusive??!0;if(a?o<e.min:o<=e.min)return t("Must be {{1}} {{2}}",a?"≥":">",e.min)}if(e.max!==void 0){const a=e.type==="slider"?!0:e.maxInclusive??!0;if(a?o>e.max:o>=e.max)return t("Must be {{1}} {{2}}",a?"≤":"<",e.max)}return null}const tn=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;function nn(e){return e.split(",").map(r=>r.trim()).every(r=>tn.test(r))}const on=",",an=e=>!e||e.trim()===""?[]:e.split(on).map(r=>r.trim()).filter(Boolean).map(r=>Number(r));function sn(e,r,t){const n=String(r);if(n.trim()==="")return e.required?t("Value required"):null;if(!nn(n))return t("Each value must be a valid float");const o=an(n);if(e.minCount!==void 0&&o.length<e.minCount)return t("Minimum number of values: {{1}}",e.minCount);if(e.maxCount!==void 0&&o.length>e.maxCount)return t("Maximum number of values: {{1}}",e.maxCount);for(const a of o){if(e.min!==void 0&&(e.minInclusive?a<e.min:a<=e.min))return t("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?a>e.max:a>=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,...o){if(e.pattern==null)return null;const a=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(a)?e.patternErrorMessage?t(e.patternErrorMessage):n?t(n,...o):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 ve=e=>{if(!e)return null;const r=Date.parse(e);return Number.isNaN(r)?null:r},Ge=new WeakMap,cn=e=>{let r=Ge.get(e);return r||(r={minTime:ve(e.minDate),maxTime:ve(e.maxDate)},Ge.set(e,r)),r};function ln(e,r,t){if(r==null||String(r).trim()==="")return e.required?t("Value required"):null;const n=String(r).trim(),o=ve(n);if(o===null)return t("Invalid date format");const{minTime:a,maxTime:c}=cn(e);return a!==null&&o<a?t("Date must be on or after {{1}}",e.minDate):c!==null&&o>c?t("Date must be on or before {{1}}",e.maxDate):null}function un(e,r,t){const n=String(r);if(!n||n.trim()==="")return e.required||e.min||e.max?t("Value required"):null;const o=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},a=o(n);if(Number.isNaN(a))return t("Invalid time format");if(e.min&&typeof e.min=="string"){const c=o(e.min);if(!Number.isNaN(c)&&a<c)return t("Time must be on or after {{1}}",e.min)}if(e.max&&typeof e.max=="string"){const c=o(e.max);if(!Number.isNaN(c)&&a>c)return t("Time must be on or before {{1}}",e.max)}return null}function mn(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function fn(e,r,t){const n=String(r??"").trim();return n===""?e.required?t("Value required"):null:mn(n)?Oe(e,r,t,t("Email does not match pattern: {{1}}",e.pattern)):t("Must be valid email format")}function dn(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 pn=/^(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$/i,gn=e=>{try{return new URL(e),!0}catch{return!1}};function hn(e,r,t){const n=String(r??"").trim();if(n==="")return e.required?t("Value required"):null;if(pn.test(n)||gn(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 yn(e,r,t){const n=Array.isArray(r)?r:[],o=n[0],a=n[1]?String(n[1]).trim():"";return String(o??"").trim()===""||a===""?e.required?t("Value required"):null:xe(e,o,t)}function bn(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 xn(e,r,t){const n=String(r);return n===""||n===null||n===void 0?e.required?t("Value required"):null:e.options?.some(o=>String(o.value)===n)?null:t("Invalid option selected")}function vn(e,r,t){const o=String(r??"").trim();if(o==="")return e.required?t("Value required"):null;const a=o.split(",").map(c=>c.trim()).filter(c=>c!=="");if(a.length===0)return e.required?t("Value required"):null;for(const c of a)if(!e.options?.some(s=>String(s.value)===c))return t("Invalid option selected");return null}const wn=/^#([0-9A-F]{3}){1,2}$/i,Sn=e=>wn.test(e);function Cn(e,r,t){const n=String(r).trim();return n===""?e.required?t("Value required"):null:Sn(n)?null:t("Invalid color format")}function jn(e,r,t){const n=String(r??"").trim();if(n==="")return e.required?t("Value required"):null;let o=r;return typeof r!="number"&&(o=parseFloat(n)),Number.isNaN(o)||o<=0?t("Invalid value"):e.max!==void 0&&o>e.max?t("Must be ≤ {{1}}",e.max):null}let Ye=!1;function Ir(){Ye||(L("int",Je),L("stepper",Je),L("int-array",rn),L("float",xe),L("slider",xe),L("float-array",sn),L("text",ue),L("string",ue),L("multiline",ue),L("password",ue),L("email",fn),L("date",ln),L("time",un),L("url",hn),L("phone",dn),L("unit",yn),L("dropdown",xn),L("multi-selection",vn),L("color",Cn),L("rating",jn),L("file",bn),Ye=!0)}Ir();Dt();Ir();const kn=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"}}),En=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
|
|
290
303
|
xmlns='http://www.w3.org/2000/svg'
|
|
291
304
|
viewBox='0 0 24 24'
|
|
292
305
|
fill='none'
|
|
@@ -295,4 +308,4 @@
|
|
|
295
308
|
stroke-linecap='round'
|
|
296
309
|
stroke-linejoin='round'>
|
|
297
310
|
<polyline points='6,9 12,15 18,9'/>
|
|
298
|
-
</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"}}},wr=({children:e,definitionName:r="",defaultStyle:t,defaultLanguage:o="en",defaultTheme:n="light",defaultLocalizeName:a="",className:u="reactaform-container"})=>{const c=r,s=a,d=n,l=o,m=i.useMemo(()=>t??{},[t]),[f,p]=i.useState({}),[y,h]=i.useState({}),[b,v]=i.useState({}),[x,C]=i.useState({});i.useEffect(()=>{let N=!0;return(async()=>{if(l==="en"){N&&(p({}),h({}));return}try{const M=await Hr(l),$=M.success?M.translations:{};N&&p($);const E=await qr(l,s),z=E.success?E.translations:{};N&&h(z)}catch{N&&(p({}),h({}))}})(),()=>{N=!1}},[l,s]),i.useEffect(()=>{C(Zt(m)),v(Qt(m))},[m]);const A=i.useMemo(()=>Ur(l,f,y),[l,f,y]),w=i.useCallback((N,...j)=>A(N,...j),[A]),k=i.useMemo(()=>({definitionName:c,language:l,theme:d,formStyle:x,fieldStyle:b,t:w}),[c,l,d,b,x,w]),S=m?.height?{height:"100%"}:void 0;return g.jsx(Ee.Provider,{value:k,children:g.jsx("div",{"data-reactaform-theme":d,className:u,style:S,children:e})})};function en(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 o=r.properties[t];if(!o||typeof o!="object")return`Property at index ${t} must be an object`;if(!o.name||typeof o.name!="string")return`Property at index ${t} must have a string 'name'`;if(o.name.trim()==="")return`Property at index ${t} has an empty 'name'`;if(!o.type||typeof o.type!="string")return`Property '${o.name}' must have a string 'type'`;if(o.type.trim()==="")return`Property '${o.name}' has an empty 'type'`}return null}async function rn(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 o=e.trim();if(!o)return{success:!1,error:"jsonData is empty"};let n;try{n=JSON.parse(o)}catch(a){return{success:!1,error:`Invalid JSON format: ${a instanceof Error?a.message:"Unknown parsing error"}`}}if(t){const a=en(n);if(a)return{success:!1,error:`Schema validation failed: ${a}`}}return{success:!0,definition:n}}catch(o){return{success:!1,error:`Unexpected error loading definition: ${o instanceof Error?o.message:"Unknown error"}`}}}function Sr(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:{}},o=e.properties||[];return Array.isArray(o)&&o.forEach(n=>{const a=n;if(a.type==="unit"){const u=a.defaultUnit,c=Number(a.defaultValue)||void 0;t.values[a.name]=[c||0,u||"m"]}else a.defaultValue!==void 0&&(t.values[a.name]=a.defaultValue)}),{success:!0,instance:t}}catch(t){return{success:!1,error:`Error creating instance: ${t instanceof Error?t.message:"Unknown error"}`}}}function tn(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 nn(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 o={name:e.name||r.name+"-instance",definition:r.name,version:r.version,values:{}},n=o.values,a={};(r.properties||[]).forEach(s=>{a[s.name]=s});const u=(s,d,l)=>{if(s==null)return s;const m=d.toLowerCase();try{if(m==="string"||m==="text")return String(s);if(m==="int"||m==="integer"||m==="number"||m==="float"){if(typeof s=="number")return s;if(typeof s=="boolean")return s?1:0;if(typeof s=="string"){const f=s.trim();if(f==="")return null;const p=Number(f);return Number.isNaN(p)?0:p}return 0}if(m==="boolean"||m==="bool"||m==="checkbox"||m==="switch"){if(typeof s=="boolean")return s;if(typeof s=="number")return s!==0;if(typeof s=="string"){const f=s.toLowerCase().trim();return["true","1","yes","on"].includes(f)}return!!s}if(m==="unit"){if(Array.isArray(s)&&s.length>=2)return s;if(Array.isArray(s)&&s.length===1)return[s[0],l&&l.defaultUnit||"m"];if(typeof s=="number")return[s,l&&l.defaultUnit||"m"];if(typeof s=="string"){const f=Number(s);return[Number.isNaN(f)?0:f,l&&l.defaultUnit||"m"]}return[0,l&&l.defaultUnit||"m"]}if(m.endsWith("[]")||m==="array"||m==="int-array"||m==="float-array")return Array.isArray(s)?s:typeof s=="string"?s.split(",").map(f=>f.trim()).filter(Boolean):[s]}catch{}return s},c=e.values||{};Object.keys(c).forEach(s=>{const d=c[s],l=a[s];if(!l)return;const m=Array.isArray(d)?"array":d===null?"null":typeof d,f=(l.type||"").toLowerCase();m===f||f==="string"&&typeof d=="string"?n[s]=d:n[s]=u(d,f,l)}),(r.properties||[]).forEach(s=>{const d=s.name;d in n||(n[d]=s.defaultValue)});try{typeof t=="function"&&t?.(e,o,r)}catch(s){return{success:!1,error:`Upgrade callback error: ${s instanceof Error?s.message:String(s)}`}}return{success:!0,instance:o}}catch(o){return{success:!1,error:`Error upgrading instance: ${o instanceof Error?o.message:"Unknown error"}`}}}pr();function on(e){const[r,t]=i.useState(null);return i.useEffect(()=>{const o=document.querySelector("[data-reactaform-theme]");if(!o)return;const n=o.closest("[data-reactaform-theme]");if(!n)return;const a=()=>t(n.getAttribute("data-reactaform-theme"));a();const u=new MutationObserver(c=>{for(const s of c)s.type==="attributes"&&s.attributeName==="data-reactaform-theme"&&a()});return u.observe(n,{attributes:!0,attributeFilter:["data-reactaform-theme"]}),()=>u.disconnect()},[e]),r}const an=({definitionData:e,instance:r,language:t,className:o,theme:n,style:a})=>{const u=i.useMemo(()=>{try{return typeof e=="string"?JSON.parse(e):e??null}catch{return null}},[e]),c={fontSize:"inherit",fontFamily:"inherit",...a},s=on(),d=n??s??"light",l=t??"en";if(i.useEffect(()=>{let f=document.getElementById("popup-root");f||(f=document.createElement("div"),f.id="popup-root",document.body.appendChild(f))},[]),!u)return g.jsx("div",{style:{color:"red"},children:"Error: No form definition provided."});let m=r;if(!m){const f=Sr(u,u.name);if(!f.success||!f.instance)return g.jsx("div",{style:{color:"red"},children:"Error: Failed to create instance from definition."});m=f.instance}return g.jsx(wr,{definitionName:u.name,defaultStyle:c,defaultLanguage:l,defaultTheme:d,defaultLocalizeName:u.localization||"",className:o,children:g.jsx(vr,{definition:u,instance:m})})};function Cr(){if(!document.getElementById("reactaform-styles"))try{const e=document.createElement("style");e.id="reactaform-styles",e.textContent=kr,document.head.appendChild(e)}catch{}}typeof document<"u"&&Cr();exports.CSS_CLASSES=R;exports.ReactaForm=an;exports.ReactaFormProvider=wr;exports.ReactaFormRenderer=vr;exports.StandardFieldLayout=T;exports.Units=_r;exports.combineClasses=q;exports.createInstanceFromDefinition=Sr;exports.deserializeDefinition=Dr;exports.deserializeInstance=Vr;exports.getAllPlugins=Ut;exports.getComponent=De;exports.getPlugin=Bt;exports.hasPlugin=Wt;exports.injectReactaFormStyles=Cr;exports.isDarkTheme=de;exports.loadInstance=tn;exports.loadJsonDefinition=rn;exports.registerComponent=Fe;exports.registerComponents=_t;exports.registerFieldValidationHandler=ar;exports.registerFormValidationHandler=or;exports.registerPlugin=Ht;exports.registerSubmissionHandler=Oe;exports.serializeDefinition=Fr;exports.serializeInstance=Mr;exports.unregisterPlugin=qt;exports.upgradeInstanceToLatestDefinition=nn;exports.useDebouncedCallback=Ze;exports.useReactaFormContext=V;exports.validateFieldValue=L;
|
|
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:o="light",defaultLocalizeName:a="",defaultFieldValidationMode:c="realTime",className:s="reactaform-container"})=>{const i=r,m=a,l=o,d=n,p=u.useMemo(()=>t??{},[t]),[g,w]=u.useState({}),[M,S]=u.useState({});u.useEffect(()=>{let b=!0;return(async()=>{if(d==="en"){b&&(w({}),S({}));return}try{const y=await Kt(d),C=y.success?y.translations:{};b&&w(C);const k=await Jt(d,m),F=k.success?k.translations:{};b&&S(F)}catch{b&&(w({}),S({}))}})(),()=>{b=!1}},[d,m]);const x=u.useMemo(()=>kn(p),[p]),j=u.useMemo(()=>En(p),[p]),V=u.useMemo(()=>Yt(d,g,M),[d,g,M]),E=u.useCallback((b,...h)=>V(b,...h),[V]),v=u.useMemo(()=>({definitionName:i,language:d,theme:l,formStyle:x,fieldStyle:j,t:E,fieldValidationMode:c}),[i,d,l,j,x,E,c]),N=p?.height?{height:"100%"}:void 0;return f.jsx(je.Provider,{value:v,children:f.jsx("div",{"data-reactaform-theme":l,className:s,style:N,children:e})})};function Fn(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 In(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 o;try{o=JSON.parse(n)}catch(a){return{success:!1,error:`Invalid JSON format: ${a instanceof Error?a.message:"Unknown parsing error"}`}}if(t){const a=Fn(o);if(a)return{success:!1,error:`Schema validation failed: ${a}`}}return{success:!0,definition:o}}catch(n){return{success:!1,error:`Unexpected error loading definition: ${n instanceof Error?n.message:"Unknown error"}`}}}function Nr(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(o=>{const a=o;if(a.type==="unit"){const c=a.defaultUnit,s=Number(a.defaultValue)||void 0;t.values[a.name]=[s||0,c||"m"]}else a.defaultValue!==void 0&&(t.values[a.name]=a.defaultValue)}),{success:!0,instance:t}}catch(t){return{success:!1,error:`Error creating instance: ${t instanceof Error?t.message:"Unknown error"}`}}}function Mn(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 Nn(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:{}},o=n.values,a={};(r.properties||[]).forEach(i=>{a[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=a[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"?o[i]=m:o[i]=c(m,p,l)}),(r.properties||[]).forEach(i=>{const m=i.name;m in o||(o[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 Vn(e){const[r,t]=u.useState(null);return u.useEffect(()=>{const n=document.querySelector("[data-reactaform-theme]");if(!n)return;const o=n.closest("[data-reactaform-theme]");if(!o)return;const a=()=>t(o.getAttribute("data-reactaform-theme"));a();const c=new MutationObserver(s=>{for(const i of s)i.type==="attributes"&&i.attributeName==="data-reactaform-theme"&&a()});return c.observe(o,{attributes:!0,attributeFilter:["data-reactaform-theme"]}),()=>c.disconnect()},[e]),r}const Rn=({definitionData:e,instance:r,language:t,className:n,theme:o,style:a,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",...a},m=Vn(),l=o??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=Nr(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."})},Q=new Map,U={components:new Map,fieldValidators:new Map,fieldTypeValidators:new Map,formValidators:new Map,submissionHandlers:new Map};function Vr(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 $n(e){const r=[];if(e.components){for(const t of Object.keys(e.components))if(Ae(t)){const o=U.components.get(t);o&&o!==e.name&&r.push({type:"component",name:t,existingPlugin:o,newPlugin:e.name})}}if(e.fieldCustomValidators)for(const[t,n]of Object.entries(e.fieldCustomValidators))for(const o of Object.keys(n)){const c=U.fieldValidators.get(t)?.get(o);fr(t,o)&&c&&c!==e.name&&r.push({type:"fieldCustomValidator",name:`${t}:${o}`,existingPlugin:c,newPlugin:e.name})}if(e.fieldTypeValidators)for(const t of Object.keys(e.fieldTypeValidators)){const n=pr(t),o=U.fieldTypeValidators.get(t);n&&o&&o!==e.name&&r.push({type:"fieldTypeValidator",name:`type:${t}`,existingPlugin:o,newPlugin:e.name})}if(e.formValidators)for(const t of Object.keys(e.formValidators)){const n=dr(t),o=U.formValidators.get(t);n&&o&&o!==e.name&&r.push({type:"formValidator",name:t,existingPlugin:o,newPlugin:e.name})}if(e.submissionHandlers)for(const t of Object.keys(e.submissionHandlers)){const n=qt(t),o=U.submissionHandlers.get(t);n&&o&&o!==e.name&&r.push({type:"submissionHandler",name:t,existingPlugin:o,newPlugin:e.name})}return r}function se(e,r,t,n,o,a,c,s){for(const i of Object.keys(e)){let m;if(s?m=o.find(l=>l.type==="fieldCustomValidator"&&l.name===`${s}:${i}`):e===n.components?m=o.find(l=>l.type==="component"&&l.name===i):e===n.formValidators?m=o.find(l=>l.type==="formValidator"&&l.name===i):e===n.fieldTypeValidators?m=o.find(l=>l.type==="fieldTypeValidator"&&l.name===`type:${i}`):e===n.submissionHandlers&&(m=o.find(l=>l.type==="submissionHandler"&&l.name===i)),Vr(m||null,a,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 An(e,r){const t=r?.conflictResolution||"error";if(Q.has(e.name)){const o={type:"plugin",name:e.name,existingPlugin:e.name,newPlugin:e.name};if(!Vr(o,t,r?.onConflict))return}const n=$n(e);if(e.components&&se(e.components,U.components,$e,e,n,t,r?.onConflict),e.fieldCustomValidators)for(const[o,a]of Object.entries(e.fieldCustomValidators))se(a,U.fieldValidators,(c,s)=>ur(o,c,s),e,n,t,r?.onConflict,o);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(),Q.set(e.name,e)}function Dn(e,r=!1){const t=Q.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,o]of Object.entries(t.fieldCustomValidators)){const a=U.fieldValidators.get(n);if(a){for(const c of Object.keys(o))a.delete(c);a.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 Q.delete(e),!0}function Pn(e){return Q.get(e)}function zn(){return Array.from(Q.values())}function On(e){return Q.has(e)}function Ln(e){for(const[r,t]of Object.entries(e))$e(r,t)}function ee(e){return typeof e=="object"&&e!==null}function Le(e){if(!ee(e))return!1;const r=e;return typeof r.name=="string"&&typeof r.displayName=="string"}function Rr(e){if(!ee(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=ee(e)?e:void 0;return!!r&&typeof r.name=="string"&&typeof r.size=="number"}}function Tn(e,r,t={}){try{const{includeMetadata:n=!1,dateFormat:o="iso",fileHandling:a="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=(Rr(r)||ee(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Le),w=new Map(g.map(S=>[S.name,S]));for(const[S,x]of Object.entries(e)){if(s.includes(S)){l.push(S);continue}if(i.length>0&&!i.includes(S)){l.push(S);continue}if(x===void 0)continue;const j=w.get(S);try{d[S]=Hn(x,j,{dateFormat:o,fileHandling:a})}catch(V){m.push(`Error serializing field '${S}': ${String(V)}`),d[S]=null}}return n&&(d._metadata={serializedAt:new Date().toISOString(),version:(ee(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 Hn(e,r,t={}){const{dateFormat:n="iso",fileHandling:o="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,o);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(a=>typeof a=="string"?Number(a):a):e;default:return e}return e instanceof Date?Xe(e,n):we(e)||Array.isArray(e)&&we(e[0])?Ze(e,o):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 Bn(e,r,t={}){try{const{strict:n=!1,validateTypes:o=!0,preserveUnknownFields:a=!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(M){return{success:!1,error:`Invalid JSON: ${M instanceof Error?M.message:"Unknown parsing error"}`}}if(!s||typeof s!="object")return{success:!1,error:"Parsed data must be an object"};const i=[],m=[],l={},p=(Rr(r)||ee(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Le),g=new Map(p.map(M=>[M.name,M]));for(const M of p){const S=M.name,x=s[S];if(x===void 0){n&&M.required&&m.push(`Required field '${S}' is missing`);continue}try{l[S]=qn(x,M,{validateTypes:o,dateFormat:c})}catch(j){const V=`Error deserializing field '${S}': ${String(j)}`;n?m.push(V):(i.push(V),l[S]=x)}}if(a)for(const[M,S]of Object.entries(s))!g.has(M)&&M!=="_metadata"&&(n&&i.push(`Unknown field '${M}' preserved`),l[M]=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 qn(e,r,t={}){const{validateTypes:n=!0,dateFormat:o="auto"}=t;if(e==null)return e;try{switch(r.type){case"date":case"datetime":case"date-time":return _n(e,o,n);case"int":case"integer":return Se(e,n);case"float":case"number":return Ce(e,n);case"boolean":return Kn(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(a){if(n)throw new Error(`Type conversion failed: ${String(a)}`);return e}}function Un(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 o={...e};return n&&(o._metadata={serializedAt:new Date().toISOString(),version:o.version||"1.0.0",propertyCount:(Array.isArray(o.properties)?o.properties.length:0)||0}),{success:!0,data:t?JSON.stringify(o,null,2):JSON.stringify(o),metadata:{fieldCount:(Array.isArray(o.properties)?o.properties.length:0)||0,excludedFields:[],warnings:[]}}}catch(t){return{success:!1,error:`Definition serialization failed: ${t instanceof Error?t.message:"Unknown error"}`}}}function Wn(e,r={}){try{const{strict:t=!1,validateTypes:n=!0}=r;let o;if(typeof e=="string")try{o=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")o={...e};else return{success:!1,error:"Input must be a string or object"};const a=[],c=[],s=["name","version","displayName"];for(const l of s)if(!(l in o)||!o[l])if(t)c.push(`Required field '${l}' is missing`);else switch(a.push(`Missing field '${l}', using default`),l){case"name":o.name="unnamed-definition";break;case"version":o.version="1.0.0";break;case"displayName":o.displayName=o.name||"Unnamed Definition";break}const i=Array.isArray(o.properties)?o.properties:null;i?o.properties=i.map((l,d)=>{const p=ee(l)?l:{},g={...p};if(!p.name){const w=`Property at index ${d} missing 'name'`;t?c.push(w):(a.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'`):(a.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"):(a.push("Properties not found or invalid, using empty array"),o.properties=[]);const m=c.length>0;return{success:!m,data:o,warnings:a.length>0?a:void 0,validationErrors:m?c:void 0}}catch(t){return{success:!1,error:`Definition deserialization failed: ${t instanceof Error?t.message:"Unknown error"}`}}}function _n(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 Kn(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(o=>o.trim()).filter(Boolean).map(o=>r==="integer"?Se(o,t):Ce(o,t));if(t)throw new Error(`Expected array, got ${typeof e}`);return e}return e.map((n,o)=>{try{return r==="integer"?Se(n,t):Ce(n,t)}catch(a){if(t)throw new Error(`Array element ${o}: ${a}`);return n}})}function $r(){if(!document.getElementById("reactaform-styles"))try{const e=document.createElement("style");e.id="reactaform-styles",e.textContent=Hr,document.head.appendChild(e)}catch{}}typeof document<"u"&&$r();exports.CSS_CLASSES=R;exports.ReactaForm=Rn;exports.ReactaFormProvider=Mr;exports.ReactaFormRenderer=Er;exports.StandardFieldLayout=P;exports.Units=It;exports.combineClasses=B;exports.createInstanceFromDefinition=Nr;exports.deserializeDefinition=Wn;exports.deserializeInstance=Bn;exports.getAllPlugins=zn;exports.getComponent=Ae;exports.getPlugin=Pn;exports.hasPlugin=On;exports.injectReactaFormStyles=$r;exports.isDarkTheme=ce;exports.loadInstance=Mn;exports.loadJsonDefinition=In;exports.registerComponent=$e;exports.registerComponents=Ln;exports.registerFieldCustomValidationHandler=ur;exports.registerFieldTypeValidationHandler=mr;exports.registerFormValidationHandler=lr;exports.registerPlugin=An;exports.registerSubmissionHandler=ze;exports.serializeDefinition=Un;exports.serializeInstance=Tn;exports.unregisterPlugin=Dn;exports.upgradeInstanceToLatestDefinition=Nn;exports.useDebouncedCallback=nr;exports.useFieldValidator=z;exports.useReactaFormContext=O;exports.useUncontrolledValidatedInput=W;exports.validateFieldValue=Kr;exports.validateFieldWithCustomHandler=Fe;
|