reactaform 1.1.4 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +160 -330
- package/dist/{common-BnnwzTl2.js → common-C-TIZ3UJ.js} +35 -26
- package/dist/{common-DLqVHgfX.js → common-CDu1xkTC.js} +39 -30
- package/dist/{common-BQcVe8MY.js → common-CkBVkhXb.js} +35 -26
- package/dist/{common-Bzz0clAC.js → common-D4RlfeS8.js} +28 -19
- package/dist/reactaform.cjs.js +6 -6
- package/dist/reactaform.es.js +1108 -1039
- package/package.json +1 -1
package/dist/reactaform.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),je=require("react-dom"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),je=require("react-dom"),br=`/* ReactaForm CSS Custom Properties (CSS Variables) */\r
|
|
2
2
|
\r
|
|
3
3
|
/* Default Light Theme */\r
|
|
4
4
|
:root {\r
|
|
@@ -284,14 +284,14 @@
|
|
|
284
284
|
\r
|
|
285
285
|
\r
|
|
286
286
|
}\r
|
|
287
|
-
`;var me={exports:{}},ce={};var
|
|
287
|
+
`;var me={exports:{}},ce={};var Ve;function yr(){if(Ve)return ce;Ve=1;var e=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(o,t,a){var i=null;if(a!==void 0&&(i=""+a),t.key!==void 0&&(i=""+t.key),"key"in t){a={};for(var c in t)c!=="key"&&(a[c]=t[c])}else a=t;return t=a.ref,{$$typeof:e,type:o,key:i,ref:t!==void 0?t:null,props:a}}return ce.Fragment=r,ce.jsx=n,ce.jsxs=n,ce}var le={};var ze;function xr(){return ze||(ze=1,process.env.NODE_ENV!=="production"&&(function(){function e(b){if(b==null)return null;if(typeof b=="function")return b.$$typeof===$?null:b.displayName||b.name||null;if(typeof b=="string")return b;switch(b){case x:return"Fragment";case w:return"Profiler";case v:return"StrictMode";case R:return"Suspense";case k:return"SuspenseList";case F:return"Activity"}if(typeof b=="object")switch(typeof b.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),b.$$typeof){case g:return"Portal";case E:return b.displayName||"Context";case I:return(b._context.displayName||"Context")+".Consumer";case S:var j=b.render;return b=b.displayName,b||(b=j.displayName||j.name||"",b=b!==""?"ForwardRef("+b+")":"ForwardRef"),b;case C:return j=b.displayName||null,j!==null?j:e(b.type)||"Memo";case N:j=b._payload,b=b._init;try{return e(b(j))}catch{}}return null}function r(b){return""+b}function n(b){try{r(b);var j=!1}catch{j=!0}if(j){j=console;var P=j.error,q=typeof Symbol=="function"&&Symbol.toStringTag&&b[Symbol.toStringTag]||b.constructor.name||"Object";return P.call(j,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",q),r(b)}}function o(b){if(b===x)return"<>";if(typeof b=="object"&&b!==null&&b.$$typeof===N)return"<...>";try{var j=e(b);return j?"<"+j+">":"<...>"}catch{return"<...>"}}function t(){var b=V.A;return b===null?null:b.getOwner()}function a(){return Error("react-stack-top-frame")}function i(b){if(U.call(b,"key")){var j=Object.getOwnPropertyDescriptor(b,"key").get;if(j&&j.isReactWarning)return!1}return b.key!==void 0}function c(b,j){function P(){ae||(ae=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",j))}P.isReactWarning=!0,Object.defineProperty(b,"key",{get:P,configurable:!0})}function f(){var b=e(this.type);return J[b]||(J[b]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),b=this.props.ref,b!==void 0?b:null}function m(b,j,P,q,Z,ee){var T=P.ref;return b={$$typeof:y,type:b,key:j,props:P,_owner:q},(T!==void 0?T:null)!==null?Object.defineProperty(b,"ref",{enumerable:!1,get:f}):Object.defineProperty(b,"ref",{enumerable:!1,value:null}),b._store={},Object.defineProperty(b._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(b,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(b,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:Z}),Object.defineProperty(b,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:ee}),Object.freeze&&(Object.freeze(b.props),Object.freeze(b)),b}function u(b,j,P,q,Z,ee){var T=j.children;if(T!==void 0)if(q)if(ne(T)){for(q=0;q<T.length;q++)d(T[q]);Object.freeze&&Object.freeze(T)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else d(T);if(U.call(j,"key")){T=e(b);var O=Object.keys(j).filter(function(Y){return Y!=="key"});q=0<O.length?"{key: someKey, "+O.join(": ..., ")+": ...}":"{key: someKey}",A[T+q]||(O=0<O.length?"{"+O.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
288
288
|
let props = %s;
|
|
289
289
|
<%s {...props} />
|
|
290
290
|
React keys must be passed directly to JSX without using spread:
|
|
291
291
|
let props = %s;
|
|
292
|
-
<%s key={someKey} {...props} />`,q,D,O,D),M[D+q]=!0)}if(D=null,P!==void 0&&(n(P),D=""+P),c(E)&&(n(E.key),D=""+E.key),"key"in E){P={};for(var L in E)L!=="key"&&(P[L]=E[L])}else P=E;return D&&i(P,typeof b=="function"?b.displayName||b.name||"Unknown":b),m(b,D,P,t(),Z,ee)}function p(b){l(b)?b._store&&(b._store.validated=1):typeof b=="object"&&b!==null&&b.$$typeof===k&&(b._payload.status==="fulfilled"?l(b._payload.value)&&b._payload.value._store&&(b._payload.value._store.validated=1):b._store&&(b._store.validated=1))}function l(b){return typeof b=="object"&&b!==null&&b.$$typeof===y}var d=s,y=Symbol.for("react.transitional.element"),g=Symbol.for("react.portal"),x=Symbol.for("react.fragment"),v=Symbol.for("react.strict_mode"),C=Symbol.for("react.profiler"),I=Symbol.for("react.consumer"),N=Symbol.for("react.context"),S=Symbol.for("react.forward_ref"),R=Symbol.for("react.suspense"),j=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),k=Symbol.for("react.lazy"),A=Symbol.for("react.activity"),$=Symbol.for("react.client.reference"),z=d.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,U=Object.prototype.hasOwnProperty,ne=Array.isArray,K=console.createTask?console.createTask:function(){return null};d={react_stack_bottom_frame:function(b){return b()}};var ae,J={},Q=d.react_stack_bottom_frame.bind(d,a)(),T=K(o(a)),M={};le.Fragment=x,le.jsx=function(b,E,P){var q=1e4>z.recentlyCreatedOwnerStacks++;return u(b,E,P,!1,q?Error("react-stack-top-frame"):Q,q?K(o(b)):T)},le.jsxs=function(b,E,P){var q=1e4>z.recentlyCreatedOwnerStacks++;return u(b,E,P,!0,q?Error("react-stack-top-frame"):Q,q?K(o(b)):T)}})()),le}var De;function wr(){return De||(De=1,process.env.NODE_ENV==="production"?me.exports=xr():me.exports=vr()),me.exports}var h=wr();const ke=s.createContext(void 0),V=()=>{const e=s.useContext(ke);if(!e)throw new Error("❌ useReactaFormContext must be used within a <ReactaFormProvider>");return e};class ge{map={};register(r,n){this.map[r]=n}get(r){return this.map[r]}has(r){return 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(([n,o])=>this.register(n,o)):Object.entries(r).forEach(([n,o])=>this.register(n,o))}getOrDefault(r,n){return this.get(r)??n}}function We(e,r=300,n){const o=s.useRef(void 0),t=s.useRef(e),a=s.useRef(null),c=s.useRef(!1);s.useEffect(()=>{t.current=e},[e]),s.useEffect(()=>()=>{o.current!==void 0&&(window.clearTimeout(o.current),o.current=void 0)},[]);const i=s.useCallback(()=>{o.current!==void 0&&(window.clearTimeout(o.current),o.current=void 0),a.current=null,c.current=!1},[]),f=s.useCallback(()=>{if(o.current!==void 0&&(window.clearTimeout(o.current),o.current=void 0),a.current)try{t.current(...a.current)}finally{a.current=null,c.current=!1}},[]);return{callback:s.useCallback((...u)=>{if(n?.leading===!0&&!c.current){c.current=!0,t.current(...u),window.clearTimeout(o.current),o.current=window.setTimeout(()=>{c.current=!1,o.current=void 0},r);return}a.current=u,window.clearTimeout(o.current),o.current=window.setTimeout(()=>{o.current=void 0,a.current&&(t.current(...a.current),a.current=null,c.current=!1)},r)},[r,n?.leading]),cancel:i,flush:f}}const F={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"},W=(...e)=>{const r=[];for(const n of e)n&&(typeof n=="string"?r.push(n):typeof n=="object"&&Object.entries(n).forEach(([o,t])=>{t&&r.push(o)}));return r.join(" ")},Ye=({content:e,size:r="medium",animation:n=!0})=>{const{t:o,darkMode:t,formStyle:a,fieldStyle:c}=V(),[i,f]=s.useState(!1),[m,u]=s.useState({x:0,y:0}),[p,l]=s.useState(!1),d=s.useRef(null),y=s.useRef(null),g=s.useRef(null),x=s.useMemo(()=>{const N={icon:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"1.2em",height:"1.2em",fontSize:"0.9em",fontWeight:"bold",borderRadius:"50%",backgroundColor:t?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.06)",color:t?"#f0f0f0":"#333",border:`1px solid ${t?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.1)"}`,cursor:"pointer",transition:n?"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:"absolute",backgroundColor:`var(--reactaform-tooltip-color-bg, ${t?"rgba(45,45,45,0.95)":"rgba(60,60,60,0.92)"})`,color:`var(--reactaform-tooltip-color, ${t?"#f0f0f0":"#fff"})`,borderRadius:"6px",border:`1px solid ${t?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.1)"}`,boxShadow:t?"0 8px 16px rgba(0,0,0,0.4)":"0 6px 18px rgba(0,0,0,0.12)",zIndex:2147483647,opacity:0,visibility:"hidden",transition:n?"opacity 0.2s ease, visibility 0.2s ease":void 0,pointerEvents:"none",whiteSpace:"normal",wordBreak:"break-word",boxSizing:"border-box"},textVisible:{opacity:1,visibility:"visible"}},S=(j,w,k)=>{const $=j?.[w];return(k&&$?$[k]:void 0)??{}};return{icon:{...N.icon,...S(a,"tooltip","icon"),...S(c,"tooltip","icon")},text:{...N.text,...S(a,"tooltip","text"),...S(c,"tooltip","text")},textVisible:N.textVisible}},[t,r,n,a,c]);s.useEffect(()=>{if(i){const I=requestAnimationFrame(()=>l(!1)),N=requestAnimationFrame(()=>{if(d.current){const S=d.current.getBoundingClientRect(),R=8;g.current=S;const j=S.right+R,w=S.top;u({x:j,y:w}),l(!0)}});return()=>{cancelAnimationFrame(N),cancelAnimationFrame(I)}}else requestAnimationFrame(()=>l(!1))},[i]),s.useEffect(()=>{if(!p)return;const I=requestAnimationFrame(()=>{if(!y.current)return;const N=y.current.getBoundingClientRect(),S=8,R=typeof window<"u"?window.innerWidth:1024,j=typeof window<"u"?window.innerHeight:768;let w=m.x,k=m.y;const A=g.current;A&&(w=A.right+S,k=A.top+A.height/2-N.height/2+-4,w+N.width>R-S&&(w=A.left-S-N.width)),w+N.width>R-S&&(w=Math.max(S,R-N.width-S)),w<S&&(w=S),k+N.height>j-S&&(k=Math.max(S,j-N.height-S)),k<S&&(k=S),(w!==m.x||k!==m.y)&&u({x:w,y:k})});return()=>cancelAnimationFrame(I)},[p,m.x,m.y]);const v=typeof document<"u"?document.getElementById("popup-root"):null,C=h.jsx("div",{ref:y,style:{...x.text,transform:p?"translateY(0) scale(1)":"translateY(-4px) scale(0.98)",transition:"opacity 120ms ease, transform 120ms ease, visibility 120ms ease",width:240,...p?x.textVisible:{},top:m.y,left:m.x},"data-reactaform-theme":t?"dark":"light",children:o(e)});return h.jsxs(h.Fragment,{children:[h.jsx("span",{"data-testid":"tooltip-icon",ref:d,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),style:{...x.icon},children:"?"}),i&&(v?je.createPortal(C,v):C)]})},ve=s.memo(({field:e,error:r,children:n,showLabel:o=!0})=>{const{t}=V(),a=e?.labelLayout==="column-center"?"center":"left";return h.jsxs("div",{className:`${F.field} column-layout`,style:{display:"flex",flexDirection:"column",gap:"var(--reactaform-label-gap, 4px)","--label-align":a},children:[o&&h.jsx("div",{style:{textAlign:a,width:"100%"},children:h.jsx("label",{className:F.label,htmlFor:e.name,style:{textAlign:a,width:"100%",minWidth:"unset",display:"block"},children:t(e.displayName)})}),h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--reactaform-inline-gap, 8px)",width:"100%"},children:[h.jsx("div",{style:{flex:1,minWidth:0,maxWidth:"100%"},children:h.jsx("div",{style:{width:"100%"},children:n})}),e.tooltip&&h.jsx(Ye,{content:e.tooltip})]}),r&&h.jsx(Ne,{children:r})]})});ve.displayName="ColumnFieldLayout";const Je=s.memo(({field:e,error:r,children:n,rightAlign:o=!1})=>{const{t}=V(),a=s.useMemo(()=>({display:"flex",flexDirection:"column",gap:0}),[]),c=s.useMemo(()=>({display:"flex",flexDirection:"row",alignItems:"center",gap:"3px"}),[]);return h.jsxs("div",{className:`${F.field} row-layout`,children:[h.jsx("label",{className:F.label,htmlFor:e.name,style:{textAlign:"left",justifyContent:"flex-start"},children:t(e.displayName)}),h.jsxs("div",{style:a,children:[h.jsxs("div",{style:c,children:[o?h.jsx("div",{style:{display:"flex",flex:1,justifyContent:"flex-end",alignItems:"center",gap:"var(--reactaform-inline-gap, 8px)"},children:n}):n,e.tooltip&&h.jsx(Ye,{content:e.tooltip})]}),r&&h.jsx(Ne,{children:r})]})]})});Je.displayName="RowFieldLayout";const B=({field:e,error:r,children:n,rightAlign:o=!1})=>e?.labelLayout==="column-left"||e?.labelLayout==="column-center"?h.jsx(ve,{field:e,error:r,showLabel:!0,children:n}):e?.type==="checkbox"||e?.type==="switch"?h.jsx(ve,{field:e,error:r,showLabel:!1,children:n}):h.jsx(Je,{field:e,error:r,rightAlign:o,children:n}),Ne=s.memo(({children:e})=>{const r=s.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 h.jsx("div",{style:r,children:e})});Ne.displayName="ErrorDiv";const Ge=s.memo(({name:e,onChange:r})=>{const{t:n}=V();return h.jsxs("div",{style:{marginBottom:16},children:[h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 2fr",gap:12,alignItems:"center"},children:[h.jsx("label",{htmlFor:"instance-name-input",style:{margin:0,fontSize:"0.95em",fontWeight:500,color:"var(--reactaform-text-color, #333)"},children:n("Instance Name")}),h.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:n("Enter instance name")})]}),h.jsx("div",{style:{height:"1px",backgroundColor:"var(--reactaform-separator, #e6e6e6)",marginTop:12,marginBottom:12}})]})});Ge.displayName="InstanceName";class Sr extends ge{registerInCategory(r,n,o){this.get(r)||this.register(r,{});const t=this.get(r);t[n]=o}getFromCategory(r,n){return this.get(r)?.[n]}listFromCategory(r){return Object.keys(this.get(r)||{})}listCategories(){return this.list()}}const Ke=new ge,Xe=new Sr;function Cr(e,r){Ke.register(e,r)}function Rr(e,r,n){Xe.registerInCategory(e,r,n)}function Er(e,r){return Xe.getFromCategory(e,r)||null}function jr(e){return Ke.get(e)||null}const be=new Map,ye=new Map;function H(e,r,n,o){if(r&&typeof r.validationHandlerName=="string"){const t=`${e}:${r.validationHandlerName}`;if(!be.has(t)){const c=Er(e,r.validationHandlerName);be.set(t,c)}const a=be.get(t);if(a)return a(n,o)||null}return null}function Ze(e,r,n){if(e&&typeof e.validationHandlerName=="string"){const o=e.validationHandlerName;if(!ye.has(o)){const a=jr(o);ye.set(o,a)}const t=ye.get(o);if(t)return t(r,n)||null}return null}function te(e){return typeof e=="object"&&e!==null}function Ie(e){if(!te(e))return!1;const r=e;return typeof r.name=="string"&&typeof r.displayName=="string"}function Qe(e){if(!te(e))return!1;const r=e;return typeof r.name!="string"||typeof r.version!="string"||!Array.isArray(r.properties)?!1:r.properties.every(n=>Ie(n))}function we(e){try{return typeof File<"u"&&e instanceof File}catch{const r=te(e)?e:void 0;return!!r&&typeof r.name=="string"&&typeof r.size=="number"}}function kr(e,r,n={}){try{const{includeMetadata:o=!1,dateFormat:t="iso",fileHandling:a="metadata",prettify:c=!1,excludeFields:i=[],includeOnlyFields:f=[]}=n;if(!e||typeof e!="object")return{success:!1,error:"Instance must be a valid object"};const m=[],u=[],p={},d=(Qe(r)||te(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Ie),y=new Map(d.map(x=>[x.name,x]));for(const[x,v]of Object.entries(e)){if(i.includes(x)){u.push(x);continue}if(f.length>0&&!f.includes(x)){u.push(x);continue}if(v===void 0)continue;const C=y.get(x);try{p[x]=Nr(v,C,{dateFormat:t,fileHandling:a})}catch(I){m.push(`Error serializing field '${x}': ${String(I)}`),p[x]=null}}return o&&(p._metadata={serializedAt:new Date().toISOString(),version:(te(r)?r.version:void 0)||"1.0.0",fieldCount:Object.keys(p).length-1}),{success:!0,data:c?JSON.stringify(p,null,2):JSON.stringify(p),metadata:{fieldCount:Object.keys(p).length,excludedFields:u,warnings:m}}}catch(o){return{success:!1,error:`Serialization failed: ${o instanceof Error?o.message:"Unknown error"}`}}}function Nr(e,r,n={}){const{dateFormat:o="iso",fileHandling:t="metadata"}=n;if(e==null)return null;if(r)switch(r.type){case"date":case"datetime":case"date-time":return Le(e,o);case"file":return Pe(e,t);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?Le(e,o):we(e)||Array.isArray(e)&&we(e[0])?Pe(e,t):e}function Le(e,r){let n=null;if(e instanceof Date)n=e;else if(typeof e=="string"){const o=new Date(e);if(!isNaN(o.getTime()))n=o;else return e}else return e;switch(r){case"timestamp":return n.getTime();case"locale":return n.toLocaleString();case"iso":default:return n.toISOString()}}function Pe(e,r){return r==="skip"?null:Array.isArray(e)?e.map(n=>_e(n,r)):_e(e,r)}function _e(e,r){if(!we(e))return e;const n=e;return r==="metadata"?{name:n.name,size:n.size,type:n.type,lastModified:n.lastModified}:{name:n.name,size:n.size,type:n.type,lastModified:n.lastModified,_note:"Base64 encoding requires async implementation"}}function Ir(e,r,n={}){try{const{strict:o=!1,validateTypes:t=!0,preserveUnknownFields:a=!0,dateFormat:c="auto"}=n;if(!e||typeof e!="string")return{success:!1,error:"Serialized data must be a non-empty string"};let i;try{i=JSON.parse(e)}catch(g){return{success:!1,error:`Invalid JSON: ${g instanceof Error?g.message:"Unknown parsing error"}`}}if(!i||typeof i!="object")return{success:!1,error:"Parsed data must be an object"};const f=[],m=[],u={},l=(Qe(r)||te(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Ie),d=new Map(l.map(g=>[g.name,g]));for(const g of l){const x=g.name,v=i[x];if(v===void 0){o&&g.required&&m.push(`Required field '${x}' is missing`);continue}try{u[x]=Fr(v,g,{validateTypes:t,dateFormat:c})}catch(C){const I=`Error deserializing field '${x}': ${String(C)}`;o?m.push(I):(f.push(I),u[x]=v)}}if(a)for(const[g,x]of Object.entries(i))!d.has(g)&&g!=="_metadata"&&(o&&f.push(`Unknown field '${g}' preserved`),u[g]=x);const y=m.length>0;return{success:!y,data:u,warnings:f.length>0?f:void 0,validationErrors:y?m:void 0}}catch(o){return{success:!1,error:`Deserialization failed: ${o instanceof Error?o.message:"Unknown error"}`}}}function Fr(e,r,n={}){const{validateTypes:o=!0,dateFormat:t="auto"}=n;if(e==null)return e;try{switch(r.type){case"date":case"datetime":case"date-time":return Or(e,t,o);case"int":case"integer":return Se(e,o);case"float":case"number":return Ce(e,o);case"boolean":return $r(e,o);case"int-array":return qe(e,"integer",o);case"float-array":return qe(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 Ar(e,r={}){try{const{prettify:n=!0,includeMetadata:o=!0}=r;if(!e||typeof e!="object")return{success:!1,error:"Definition must be a valid object"};const t={...e};return o&&(t._metadata={serializedAt:new Date().toISOString(),version:t.version||"1.0.0",propertyCount:(Array.isArray(t.properties)?t.properties.length:0)||0}),{success:!0,data:n?JSON.stringify(t,null,2):JSON.stringify(t),metadata:{fieldCount:(Array.isArray(t.properties)?t.properties.length:0)||0,excludedFields:[],warnings:[]}}}catch(n){return{success:!1,error:`Definition serialization failed: ${n instanceof Error?n.message:"Unknown error"}`}}}function Mr(e,r={}){try{const{strict:n=!1,validateTypes:o=!0}=r;let t;if(typeof e=="string")try{t=JSON.parse(e)}catch(u){return{success:!1,error:`Invalid JSON for definition: ${u instanceof Error?u.message:"Unknown parsing error"}`}}else if(e&&typeof e=="object")t={...e};else return{success:!1,error:"Input must be a string or object"};const a=[],c=[],i=["name","version","displayName"];for(const u of i)if(!t[u])if(n)c.push(`Required field '${u}' is missing`);else switch(a.push(`Missing field '${u}', using default`),u){case"name":t.name="unnamed-definition";break;case"version":t.version="1.0.0";break;case"displayName":t.displayName=t.name||"Unnamed Definition";break}const f=Array.isArray(t.properties)?t.properties:null;f?t.properties=f.map((u,p)=>{const l=te(u)?u:{},d={...l};if(!l.name){const y=`Property at index ${p} missing 'name'`;n?c.push(y):(a.push(`${y}, using 'field_${p}'`),d.name=`field_${p}`)}return l.displayName||(d.displayName=l.name||`Field ${p}`),l.type||(n&&o?c.push(`Property '${l.name||p}' missing 'type'`):(a.push(`Property '${l.name||p}' missing 'type', using 'string'`),d.type="string")),l.defaultValue===void 0&&(d.defaultValue=null),l.required===void 0&&(d.required=!1),d}):n?c.push("Properties must be an array"):(a.push("Properties not found or invalid, using empty array"),t.properties=[]);const m=c.length>0;return{success:!m,data:t,warnings:a.length>0?a:void 0,validationErrors:m?c:void 0}}catch(n){return{success:!1,error:`Definition deserialization failed: ${n instanceof Error?n.message:"Unknown error"}`}}}function Or(e,r,n){if(e instanceof Date)return e;if(typeof e=="number"){const o=new Date(e);if(n&&isNaN(o.getTime()))throw new Error(`Invalid timestamp: ${e}`);return o}if(typeof e=="string"){const o=new Date(e);if(n&&isNaN(o.getTime()))throw new Error(`Invalid date string: ${e}`);return o}if(n)throw new Error(`Cannot convert ${typeof e} to Date`);return e}function Se(e,r){if(typeof e=="number"&&Number.isInteger(e))return e;if(typeof e=="string"&&e.trim()!==""){const n=parseInt(e,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")return e;if(typeof e=="string"&&e.trim()!==""){const n=parseFloat(e);if(r&&isNaN(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 $r(e,r){if(typeof e=="boolean")return e;if(typeof e=="string"){const n=e.toLowerCase();if(n==="true"||n==="1")return!0;if(n==="false"||n==="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 qe(e,r,n){if(!Array.isArray(e)){if(typeof e=="string")return e.split(",").map(t=>t.trim()).filter(Boolean).map(t=>r==="integer"?Se(t,n):Ce(t,n));if(n)throw new Error(`Expected array, got ${typeof e}`);return e}return e.map((o,t)=>{try{return r==="integer"?Se(o,n):Ce(o,n)}catch(a){if(n)throw new Error(`Array element ${t}: ${a}`);return o}})}const Vr=(e,r)=>{const n=new Map;let o=null,t=null,a=0;for(const c of e){const i=c.group;if(!i){o=null,t=null;continue}if(i===o)r[c.name].group=t??i;else{if(!n.has(i))n.set(i,1),t=null,r[c.name].group=i;else{const f=n.get(i),m=`${i}(${f})`;n.set(i,f+1),t=m,r[c.name].group=m,a++}o=i}}return a},zr=(e,r={})=>{const{includeEmpty:n=!0}=r,o=[];let t=null,a=[],c=0;for(const f of e){const m=f.group||null;m!==t?((a.length>0||n)&&(a.length===0&&c++,o.push({name:t,fields:a})),t=m,a=[f]):a.push(f)}(a.length>0||n)&&(a.length===0&&c++,o.push({name:t,fields:a}));const i=Math.max(0,...o.map(f=>f.fields.length));return{groups:o,metadata:{totalGroups:o.length,emptyGroups:c,largestGroup:i}}},xe=new Map,de=new Map,re=new Set,Re=new Map,Tr=async e=>{try{let r;switch(e.toLowerCase()){case"fr":r=(await Promise.resolve().then(()=>require("./common-BxyjIoe1.cjs"))).default;break;case"de":r=(await Promise.resolve().then(()=>require("./common-BD9zx3GT.cjs"))).default;break;case"es":r=(await Promise.resolve().then(()=>require("./common-hRFTL4KF.cjs"))).default;break;case"zh-cn":r=(await Promise.resolve().then(()=>require("./common-COyDhNL-.cjs"))).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}`}}},Dr=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 n=await Tr(r);return n.success&&(xe.set(r,n.translations),Re.set(r,{loadedAt:new Date,size:Object.keys(n.translations).length,source:"common"})),n},Lr=async(e,r)=>{if(!e||!r)return{success:!1,translations:{},error:"Both language and localizeName are required"};const n=`${e.toLowerCase()}/${r}`;if(re.has(n))return{success:!1,translations:{},error:"Previously failed to load",fromCache:!0};if(de.has(n))return{success:!0,translations:de.get(n)||{},fromCache:!0};try{let o=r;!r.includes("/")&&!r.includes(".")&&(o=`/locales/${e}/${r}.json`);const t=await fetch(o);if(!t.ok){const m=`HTTP ${t.status}: ${t.statusText}`;return t.status===404?(de.set(n,{}),Re.set(n,{loadedAt:new Date,size:0,source:"user"}),{success:!0,translations:{},fromCache:!1}):(re.add(n),{success:!1,translations:{},error:m})}const a=t.headers.get("content-type")||"";!a.includes("application/json")&&!a.includes("text/json")&&er()&&console.warn(`Translation file at ${o} has unexpected content-type: ${a}`);const c=await t.text();if(!c){const m="Empty translation file";return re.add(n),{success:!1,translations:{},error:m}}let i;try{i=JSON.parse(c)}catch(m){const u=`Invalid JSON in translation file: ${m instanceof Error?m.message:String(m)}`;return re.add(n),{success:!1,translations:{},error:u}}if(!i||typeof i!="object"){const m="Invalid translation file format";return re.add(n),{success:!1,translations:{},error:m}}const f=Object.fromEntries(Object.entries(i).map(([m,u])=>[m,typeof u=="string"?u:String(u)]));if(!f||typeof f!="object"){const m="Invalid translation file format";return re.add(n),{success:!1,translations:{},error:m}}return de.set(n,f),Re.set(n,{loadedAt:new Date,size:Object.keys(f).length,source:"user"}),{success:!0,translations:f,fromCache:!1}}catch(o){const t=`Failed to load user translations: ${o instanceof Error?o.message:"Unknown error"}`;return re.add(n),{success:!1,translations:{},error:t}}};function er(){try{if(typeof process<"u"&&process?.env?.NODE_ENV==="development")return!0}catch{}return!1}function Pr(e,r){return r.length===0?e:e.replace(/\{\{(\d+)\}\}/g,(n,o)=>{const t=parseInt(o,10)-1,a=r[t];if(a==null)return n;try{return String(a)}catch{return n}})}const _r=(e,r,n)=>(o,...t)=>{let a=o,c=!1;return!o||typeof o!="string"?String(o||""):(e.toLowerCase()==="en"?(a=o,c=!0):Object.prototype.hasOwnProperty.call(n,o)?(a=n[o],c=!0):Object.prototype.hasOwnProperty.call(r,o)?(a=r[o],c=!0):a=o,a=Pr(a,t),!c&&er()&&console.debug(`Missing translation for "${o}" in language "${e}"`),a)},Fe={length:["m","cm","mm","km","in","ft","yd","mi"],area:["m^2","cm^2","mm^2","in^2","ft^2","yd^2"],volume:["L","m^3","cm^3","mL","in^3","ft^3","yd^3"],weight:["kg","g","mg","t","lb","oz"],time:["min","s","h","ms","d"],temperature:["C","F","K"],angle:["deg","rad","rev"]},Ae={length:{m:"Meter (m)",mm:"Millimeter (mm)",cm:"Centimeter (cm)",km:"Kilometer (km)",in:"Inch (in)",ft:"Foot (ft)",yd:"Yard (yd)",mi:"Mile (mi)"},area:{"m^2":"Square meter (m^2)","mm^2":"Square millimeter (mm^2)","cm^2":"Square centimeter (cm^2)","in^2":"Square inch (in^2)","ft^2":"Square foot (ft^2)","yd^2":"Square yard (yd^2)"},volume:{L:"Liter (L)","cm^3":"Cubic centimeter (cm^3)","m^3":"Cubic meter (m^3)",mL:"Milliliter (mL)","in^3":"Cubic inch (in^3)","ft^3":"Cubic foot (ft^3)","yd^3":"Cubic yard (yd^3)"},weight:{kg:"Kilogram (kg)",g:"Gram (g)",mg:"Milligram (mg)",t:"Tonne (t)",lb:"Pound (lb)",oz:"Ounce (oz)"},time:{s:"Second (s)",min:"Minute (min)",h:"Hour (h)",ms:"Millisecond (ms)",d:"Day (d)",wk:"Week (wk)"},temperature:{C:"Celsius (C)",F:"Fahrenheit (F)",K:"Kelvin (K)"},angle:{deg:"Degree (deg)",rad:"Radian (rad)",rev:"Revolution (rev)"}},Me={length:{mm:1e3,cm:100,m:1,km:.001,in:100/2.54,ft:100/(2.54*12),yd:100/(2.54*36),mi:1/1609.344},area:{"m^2":1,"mm^2":1e6,"cm^2":1e4,"km^2":1/1e6,"in^2":(100/2.54)**2,"ft^2":(100/(2.54*12))**2,"yd^2":(100/(2.54*36))**2},volume:{"cm^3":1e6,"m^3":1,L:1,mL:1e6,"in^3":(100/2.54)**3,"ft^3":(100/(2.54*12))**3,"yd^3":(100/(2.54*36))**3},weight:{mg:1e6,g:1e3,kg:1,t:.001,lb:1/.45359237,oz:1/.028349523125},time:{ms:1e3,s:1,min:1/60,h:1/3600,d:1/86400,wk:1/604800},temperature:{C:1,F:33.8,K:274.15},angle:{deg:1,rad:Math.PI/180,rev:1/360}},Oe={},qr=new Set([...Object.keys(Fe),...Object.keys(Ae),...Object.keys(Me)]);for(const e of qr){const r={},n=Fe[e]??[],o=Ae[e]??{},t=Me[e]??{};for(const a of n){const c=o[a];r[a]={name:typeof c=="string"?c:String(a),shortName:a,factor:Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0}}for(const[a,c]of Object.entries(o))if(!r[a]){const i=typeof c=="string"?c:String(a);r[a]={name:i,shortName:a,factor:Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0}}for(const[a,c]of Object.entries(t))r[a]||(r[a]={name:String(a),shortName:String(a),factor:c});Oe[e]=r}const Br=Object.freeze(Object.defineProperty({__proto__:null,dimensionUnitDisplayMap:Ae,dimensionUnitsMap:Fe,dimensonUnitFactorsMap:Me,unitsByDimension:Oe},Symbol.toStringTag,{value:"Module"})),Hr=({field:e,value:r,onChange:n,onError:o})=>{const{definitionName:t,t:a}=V(),c=s.useRef(o);s.useEffect(()=>{c.current=o},[o]),s.useEffect(()=>{const u=H(t,e,r??!1,a);c.current?.(u??null)},[r,e,t,a]);const i=u=>{const p=u.target.checked;n?.(p,null)},f=u=>{(u.key===" "||u.key==="Spacebar"||u.key==="Space"||u.key==="Enter")&&(u.preventDefault(),n?.(!r,null))},m=e.name;return h.jsx(B,{field:e,rightAlign:!1,children:h.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[h.jsx("label",{className:F.label,htmlFor:m,style:{textAlign:"left",justifyContent:"flex-start"},children:a(e.displayName)}),h.jsx("input",{id:m,"data-testid":"boolean-checkbox",type:"checkbox",checked:!!r,onChange:i,onKeyDown:f,"aria-checked":!!r,style:{cursor:"pointer",margin:"8px 0 8px 0",width:"1.2em",height:"1.2em",verticalAlign:"middle",color:"#FFFFFF",accentColor:"#0000FF",opacity:void 0}})]})})},Be=[{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 rr(e){return/^#([0-9A-F]{3}){1,2}$/i.test(e)}function Ur(e){if(!rr(e))return null;const r=tr(e),n=parseInt(r.slice(1),16);return{r:n>>16&255,g:n>>8&255,b:n&255}}function tr(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 Wr=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=V(),[c,i]=s.useState("#000000"),f=s.useRef(null),m=s.useRef(null),u=s.useRef(o);s.useEffect(()=>{u.current=o},[o]),s.useEffect(()=>{const v=r&&rr(r)?r:"#000000",C=tr(v);i(C)},[r]),s.useEffect(()=>{const v=H(a,e,r??"#000000",t);u.current?.(v??null)},[r,e,a,t]);const p=v=>{const C=v.target.value;i(C),n?.(C,null)},l=v=>{const C=v.target.value;i(C),n?.(C,null)},d=Be.find(v=>v.value===c),{r:y,g,b:x}=Ur(c)||{r:0,g:0,b:0};return h.jsx(B,{field:e,error:null,children:h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%"},children:[h.jsxs("select",{ref:f,id:e.name,value:c,onChange:p,style:{minWidth:"120px",flex:1},className:W(F.input,F.inputSelect),children:[Be.map(v=>h.jsx("option",{value:v.value,children:t(v.label)},v.value)),d?null:h.jsxs("option",{value:c,children:["(",y,", ",g,", ",x,")"]},c)]}),h.jsx("label",{style:{width:"2.5em",height:"1.8em",display:"inline-block",border:"1px solid #ccc",borderRadius:"4px",backgroundColor:c,cursor:"pointer",overflow:"hidden",flexShrink:0},children:h.jsx("input",{ref:m,type:"color",value:c,onChange:l,style:{opacity:0,width:"100%",height:"100%",border:"none",padding:0,cursor:"pointer"}})})]})})},ue=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 ue(e)?e:"";const n=ue(e);if(n){const o=n.getFullYear(),t=String(n.getMonth()+1).padStart(2,"0"),a=String(n.getDate()).padStart(2,"0");return`${o}-${t}-${a}`}return""},Jr=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=V(),{name:c,required:i}=e,f=s.useRef(null),m=s.useRef(o);s.useEffect(()=>{m.current=o},[o]);const u=s.useCallback(l=>{if(!l||l.trim()==="")return i?t("Value required"):null;if(l){const y=ue(l);if(!y)return t("Invalid date format");if(e.minDate){const g=ue(e.minDate);if(g&&y.getTime()<g.getTime())return t("Date must be on or after {{1}}",e.minDate)}if(e.maxDate){const g=ue(e.maxDate);if(g&&y.getTime()>g.getTime())return t("Date must be on or before {{1}}",e.maxDate)}}return H(a,e,l,t)??null},[e,a,t,i]),p=l=>{const d=l.target.value,y=u(d);n?.(d,y)};return s.useEffect(()=>{const l=u(r);l!==f.current&&(f.current=l,m.current?.(l??null))},[r,u]),h.jsx(B,{field:e,error:u(r),children:h.jsx("input",{id:c,type:"date",value:Yr(r),onChange:p,className:W(F.input,F.textInput),...e.minDate?{min:e.minDate}:{},...e.maxDate?{max:e.maxDate}:{},"aria-invalid":!!u(r),"aria-describedby":u(r)?`${c}-error`:void 0})})},Gr=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=V(),c=s.useRef(null),i=s.useRef(o);s.useEffect(()=>{i.current=o},[o]);const f=s.useCallback(u=>u===""||u===null||u===void 0?t("Value required"):!e.options||e.options.length===0?null:e.options.some(l=>l.value===u)?H(a,e,u,t)??null:t("Invalid option selected"),[e,t,a]);s.useEffect(()=>{const u=r!=null?String(r):"",p=f(u);if(p&&e.options&&e.options.length>0){const l=String(e.options[0].value);c.current&&(c.current.value=l),n?.(l,null),i.current?.(null)}else c.current&&(c.current.value=u),i.current?.(p??null)},[r,f,n,e.options]);const m=u=>{const p=u.target.value,l=f(p);n?.(p,l)};return h.jsx(B,{field:e,error:f(String(r??"")),children:h.jsx("select",{defaultValue:String(r??""),ref:c,onChange:m,className:W(F.input,F.inputSelect),children:(e.options??[]).map(u=>h.jsx("option",{value:String(u.value),children:t(u.label)},String(u.value)))})})};function Kr(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}const Xr=({field:e,value:r,onChange:n,onError:o})=>{const{definitionName:t,t:a}=V(),c=s.useRef(null),i=s.useCallback(p=>{const l=p.trim();return l===""?e.required?a("Value required"):null:Kr(l)?e.pattern&&!new RegExp(e.pattern).test(l)?a("Email does not match pattern: {{%1}}",{"%1":`${e.pattern}`}):H(t,e,p,a)??null:a("Must be valid email format")},[e,t,a]),f=p=>{const l=p.target.value,d=i(l);n?.(l,d)},m=s.useRef(null),u=s.useRef(o);return s.useEffect(()=>{u.current=o},[o]),s.useEffect(()=>{const p=r??"",l=i(p);c.current&&c.current.value!==String(p)&&(c.current.value=String(p)),l!==m.current&&(m.current=l,u.current?.(l??null))},[r,i]),h.jsx(B,{field:e,error:i(String(r??"")),children:h.jsx("input",{id:e.name,type:"email",defaultValue:String(r??""),ref:c,onChange:f,className:W(F.input,F.textInput)})})},Zr=({field:e})=>{const{darkMode:r}=V(),{color:n=r?"#444444":"#CCCCCC",thickness:o=1,margin:t="8px 0"}=e;return h.jsx("div",{style:{width:"auto",height:"0",borderTop:`${o}px solid ${n}`,margin:t}})};function nr({pos:e,options:r,onClose:n,onClickOption:o}){const t=s.useRef(null),a=s.useRef(!1),c=typeof window<"u"?document.getElementById("popup-root")||document.body:null;if(s.useEffect(()=>{function d(y){a.current||y.target.dataset?.popupMenu==="item"||t.current&&y.target instanceof Node&&!t.current.contains(y.target)&&n()}return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[n]),!c||r===void 0||r.length===0||!e||e.x==null||e.y==null)return null;const i=e.x,f=e.y,m=typeof window<"u"?window.innerWidth:1024,u=Math.max(0,m-160),p=Math.max(0,Math.min(i,u)),l=Math.max(0,f);return je.createPortal(h.jsx("div",{ref:t,onMouseDown:d=>{d.stopPropagation()},style:{position:"fixed",top:l,left:p,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)",pointerEvents:"auto"},children:r.map((d,y)=>h.jsx("div",{"data-popup-menu":"item",onMouseDown:g=>{g.stopPropagation(),a.current=!0},onClick:g=>{g.stopPropagation(),g.preventDefault(),o(d),n(),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:y<r.length-1?"1px solid var(--reactaform-border-light, #eee)":void 0,transition:"background-color 0.15s ease"},onMouseEnter:g=>{g.currentTarget.style.backgroundColor="var(--reactaform-hover-bg, #e0e0e0)"},onMouseLeave:g=>{g.currentTarget.style.backgroundColor="transparent"},children:d.label},d.label??y))}),c)}const Qr=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=V(),[c,i]=s.useState(!1),[f,m]=s.useState(null),[u,p]=s.useState([]),l=s.useRef(null),d=s.useRef(o);s.useEffect(()=>{d.current=o},[o]);const y=s.useCallback(C=>e.required&&(!C||Array.isArray(C)&&C.length===0)?t("Value required"):H(a,e,C,t)??null,[e,a,t]),g=s.useMemo(()=>y(r),[r,y]);s.useEffect(()=>{const C=y(r);n?.(r,C),d.current?.(C??null)},[r,y]);const x=C=>{const I=C.target.files;let N=null;I&&I.length>0&&(N=e.multiple?Array.from(I):I[0]);const S=y(N);n?.(N,S)},v=C=>{if(g)return;let I=null;try{I=C.currentTarget.getBoundingClientRect()}catch{I=null}const N=I&&typeof I.left=="number"?I.left:10,S=I&&typeof I.bottom=="number"?I.bottom:20;m({x:N,y:S});let R=[];Array.isArray(r)?R=r?r.map(j=>({label:j.name})):[]:R=r?[{label:r.name}]:[],R.length===0&&(R=[{label:t("No file selected")}]),p(R),i(j=>!j)};return h.jsx(B,{field:e,error:g,children:h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--reactaform-inline-gap, 8px)",width:"100%"},children:[h.jsx("input",{id:e.name,ref:l,type:"file",accept:e.accept,multiple:e.multiple,style:{width:0,height:0,opacity:0,position:"absolute",zIndex:-1},onChange:x}),h.jsx("label",{htmlFor:e.name,className:F.button,style:{width:"100%",height:"inherit",textAlign:"center"},children:e.multiple?t("Choose Files..."):t("Choose File...")}),h.jsx("button",{onClick:v,"aria-haspopup":!0,"aria-expanded":c,"aria-label":t("Show selected files"),className:F.button,style:{height:"inherit",display:"inline-block"},children:h.jsx("span",{children:"⋮"})}),c&&f&&u&&u.length>0&&h.jsx(nr,{pos:f,options:u,onClose:()=>{m(null),i(!1)},onClickOption:()=>{}})]})})},et=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;function rt(e){return e.split(",").map(r=>r.trim()).every(r=>et.test(r))}const tt=e=>!e||e.trim()===""?[]:e.split(",").map(r=>r.trim()).filter(Boolean).map(Number),nt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=V(),[c,i]=s.useState(Array.isArray(r)?r.join(", "):String(r??"")),f=s.useCallback(l=>{if(l.trim()==="")return e.required?t("Value required"):null;if(!rt(l))return t("Each value must be a valid float");const d=tt(l);if(e.minCount!==void 0&&d.length<e.minCount)return t("Minimum number of values: {{1}}",e.minCount);if(e.maxCount!==void 0&&d.length>e.maxCount)return t("Maximum number of values: {{1}}",e.maxCount);for(const g of d){if(e.min!==void 0&&(e.minInclusive?g<e.min:g<=e.min))return t("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?g>e.max:g>=e.max))return t("Each value must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max)}return H(a,e,d,t)??null},[a,e,t]),m=l=>{const d=l.target.value,y=f(d);i(d),n?.(d,y)},u=s.useRef(null),p=s.useRef(o);return s.useEffect(()=>{p.current=o},[o]),s.useEffect(()=>{const l=Array.isArray(r)?r.join(", "):String(r??""),d=f(l);d!==u.current&&(u.current=d,p.current?.(d??null))},[r,e.required,f,t]),h.jsx(B,{field:e,error:f(c),children:h.jsx("input",{type:"text",value:c,onChange:m,className:W(F.input,F.textInput),style:{flex:1}})})},ot=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/,at=e=>{const r=Number.parseFloat(e);return Number.isNaN(r)?null:r},st=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=V(),c=s.useRef(null),i=s.useCallback(p=>{if(p.trim()==="")return e.required?t("Value required"):null;if(!ot.test(p))return t("Must be a valid float");const l=at(p);return l===null?t("Must be a valid float"):e.min!==void 0&&(e.minInclusive?l<e.min:l<=e.min)?t("Must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min):e.max!==void 0&&(e.maxInclusive?l>e.max:l>=e.max)?t("Must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max):H(a,e,l,t)??null},[e,a,t]),f=s.useRef(null),m=s.useRef(o);s.useEffect(()=>{m.current=o},[o]),s.useEffect(()=>{const p=String(r??""),l=i(p);l!==f.current&&(f.current=l,m.current?.(l??null)),c.current&&document.activeElement!==c.current&&(c.current.value=p)},[r,e,i,t]);const u=p=>{const l=p.target.value,d=i(l);n?.(l,d)};return h.jsx(B,{field:e,error:i(String(r??"")),children:h.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:c,onChange:u,className:W(F.input,F.inputNumber)})})};function it(){try{return"/"}catch{}try{if(typeof process<"u"&&process?.env?.PUBLIC_URL)return process.env.PUBLIC_URL}catch{}return"/"}const ct=({field:e,value:r})=>{const{language:n,t:o}=V(),t=e.alignment||"center",a={left:"flex-start",center:"center",right:"flex-end"},c=typeof r=="string"?r:"";let i=c&&c.trim()!==""?c:typeof e.defaultValue=="string"?e.defaultValue:"";i&&!i.startsWith("/")&&(i=`${it()}${i}`);const f=e.localized?.split(";").map(x=>x.trim()),[m,u]=s.useState(i||""),p=s.useRef(i||null);if(s.useEffect(()=>{if(!i)return;const x=i.split("/"),v=x.pop(),C=v.lastIndexOf(".");if(C===-1)return;const I=v.substring(0,C),N=v.substring(C);let S=null;f?.includes(n)&&(S=`${I}_${n}${N}`);const R=new AbortController;if(S){const j=[...x,S].join("/");fetch(j,{method:"HEAD",signal:R.signal}).then(w=>{const k=w.ok?j:i;k!==p.current&&(p.current=k,u(k))}).catch(()=>{i!==p.current&&(p.current=i,u(i))})}else{const j=i;j!==p.current&&(p.current=j,requestAnimationFrame(()=>u(j)))}return()=>{R.abort()}},[i,n,f]),!m)return null;const{width:l,height:d}=e,y={},g={borderRadius:"8px",objectFit:"contain",boxShadow:"0 2px 6px rgba(0,0,0,0.1)",margin:"0 0 8px 0"};return l&&d?(y.width=l,y.height=d,g.width=`${l}px`,g.height=`${d}px`):l&&!d?(y.width=l,g.width=`${l}px`,g.height="auto"):!l&&d&&(y.height=d,g.width="auto",g.height=`${d}px`),h.jsx(B,{field:e,children:h.jsx("div",{"data-testid":"image-wrapper",style:{display:"flex",justifyContent:a[t]||"center",margin:"0 0"},children:h.jsx("img",{src:m,alt:o?.(e.displayName||"Image")||e.displayName||"Image",...y,style:g})})})};function lt(e){const r=/^-?\d+$/;return e.split(",").map(n=>n.trim()).every(n=>r.test(n))}const ut=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=V(),c=",",[i,f]=s.useState(Array.isArray(r)?r.join(c+" "):String(r??"")),m=y=>!y||y.trim()===""?[]:y.split(c).map(g=>g.trim()).filter(Boolean).map(g=>Number(g)),u=s.useCallback(y=>{if(y.trim()==="")return e.required?t("Value required"):null;if(!lt(y))return t("Each value must be a valid integer");const g=m(y);if(e.minCount!==void 0&&g.length<e.minCount)return t("Minimum number of values: {{1}}",`${e.minCount}`);if(e.maxCount!==void 0&&g.length>e.maxCount)return t("Maximum number of values: {{1}}",`${e.maxCount}`);for(const v of g){if(e.min!==void 0&&(e.minInclusive?v<e.min:v<=e.min))return t("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?v>e.max:v>=e.max))return t("Each value must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max)}return H(a,e,g,t)??null},[a,e,t]),p=y=>{const g=y.target.value,x=u(g);f(g),n?.(g,x)},l=s.useRef(null),d=s.useRef(o);return s.useEffect(()=>{d.current=o},[o]),s.useEffect(()=>{const y=Array.isArray(r)?r.join(c+" "):String(r??""),g=u(y);g!==l.current&&(l.current=g,d.current?.(g??null))},[r,e.required,u,t]),h.jsx(B,{field:e,error:u(i),children:h.jsx("input",{type:"text",value:i,onChange:p,className:W(F.input,F.textInput),style:{flex:1}})})};function ft(e){return/^[-+]?\d*$/.test(e)}const mt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=V(),c=s.useRef(null),i=s.useCallback(l=>{const d=parseInt(l,10);return Number.isNaN(d)?null:d},[]),f=s.useCallback(l=>{if(l.trim()==="")return e.required?t("Value required"):null;if(!ft(l))return t("Must be a valid integer");const d=i(l);if(d===null)return t("Must be a valid integer");if(e.min!==void 0&&(e.minInclusive?d<e.min:d<=e.min))return t("Must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?d>e.max:d>=e.max))return t("Must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max);if(e.step!==void 0){const g=Number(e.step);if(!Number.isInteger(g))return t("Invalid step value");if(d%g!==0)return t("Must be a multiple of {{1}}",g)}return H(a,e,d,t)??null},[e,a,t,i]),m=s.useRef(null),u=s.useRef(o);s.useEffect(()=>{u.current=o},[o]),s.useEffect(()=>{const l=String(r??""),d=f(l);d!==m.current&&(m.current=d,u.current?.(d??null)),c.current&&document.activeElement!==c.current&&(c.current.value=l)},[r,e,f,t]);const p=l=>{const d=l.target.value,y=f(d);n?.(d,y)};return h.jsx(B,{field:e,error:f(String(r??"")),children:h.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:c,onChange:p,className:W(F.input,F.inputNumber)})})},dt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=V(),c=e.minHeight??"80px",i=s.useRef(null),f=s.useRef(null),m=s.useRef(o);s.useEffect(()=>{m.current=o},[o]);const u=s.useCallback(d=>d.trim()===""?e.required?t("Value required"):null:e.minLength!==void 0&&d.length<e.minLength?t("Must be at least {{1}} characters",e.minLength):e.maxLength!==void 0&&d.length>e.maxLength?t("Must be at most {{1}} characters",e.maxLength):H(a,e,d,t),[e,a,t]),p=d=>{const y=d.target.value,g=u(y);n?.(y,g)};s.useEffect(()=>{const d=u(r);d!==f.current&&(f.current=d,m.current?.(d??null)),i.current&&i.current.value!==String(r??"")&&(i.current.value=String(r??""))},[r,u]);const l={defaultValue:String(r??""),ref:i,onChange:p,style:{resize:"vertical",minHeight:c,width:"100%",boxSizing:"border-box"},className:W(F.input,F.textInput)};return h.jsx(B,{field:e,error:u(r),children:h.jsx("textarea",{...l})})},pt=({field:e,value:r,onChange:n,onError:o})=>{const t=s.useRef(o);s.useEffect(()=>{t.current=o},[o]);const{t:a,darkMode:c,formStyle:i,fieldStyle:f,definitionName:m}=V(),u=(w,k,A)=>{if(!k)return{};const z=w?.[k];return(A&&z?z[A]:void 0)??{}},p=s.useRef(null),[l,d]=s.useState(!1),[y,g]=s.useState(null),x=s.useMemo(()=>e.options.map(w=>({value:w.value,label:a(w.label)})),[e.options,a]),v=s.useMemo(()=>{const w=Array.isArray(r)?r:[],k=new Set(x.map(A=>A.value));return w.filter(A=>k.has(A))},[r,x]),C=w=>{const k=Array.isArray(w)?w:[];return e.required&&k.length===0?a("Value required"):H(m,e,k,a)??null},I=()=>{if(!p.current)return;const w=p.current.getBoundingClientRect();g({x:w.left,y:w.bottom}),d(k=>!k)},N=w=>{const k=v.includes(w)?v.filter($=>$!==w):[...v,w],A=C(k);t.current?.(A??null),n?.(k,A)},S=s.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)",...u(i,"multiSelect","control"),...u(f,void 0,"control")}),[i,f]),R=s.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,...u(i,"multiSelect","clearButton"),...u(f,void 0,"clearButton")}),[i,f]),j=s.useMemo(()=>({position:"absolute",right:"0.7em",top:"50%",transform:"translateY(-50%)",pointerEvents:"none",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",...u(i,"multiSelect","arrow"),...u(f,void 0,"arrow")}),[i,f]);return h.jsxs("div",{children:[h.jsx(B,{field:e,error:null,children:h.jsx("div",{style:{width:"100%"},children:h.jsxs("div",{ref:p,className:"reactaform-multiselection-control",style:S,onClick:I,tabIndex:0,role:"button","aria-haspopup":"listbox","aria-expanded":l,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),I())},children:[h.jsxs("span",{style:{flex:1,color:"var(--reactaform-text-muted, #888)"},children:[v.length," / ",x.length," selected"]}),v.length>0&&h.jsx("button",{type:"button","aria-label":"Clear selections",onClick:w=>{w.stopPropagation(),n?.([],null)},style:R,children:h.jsx("span",{style:R,"aria-hidden":!0,children:"✖"})}),h.jsx("span",{style:j,"aria-hidden":!0,children:"▼"})]})})}),l&&y&&h.jsx(gt,{position:y,options:x,selectedValues:v,onToggleOption:N,onClose:()=>d(!1),controlRef:p,darkMode:c})]})},gt=({position:e,options:r,selectedValues:n,onToggleOption:o,onClose:t,controlRef:a,darkMode:c})=>{const i=s.useRef(null),[f,m]=s.useState(-1),{formStyle:u,fieldStyle:p}=V(),l=(R,j,w)=>{if(!j)return{};const A=R?.[j];return(w&&A?A[w]:void 0)??{}},d=s.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)",...l(u,"multiSelect","popup"),...l(p,void 0,"popup")}),[u,p]),y=s.useMemo(()=>({padding:"6px 8px",cursor:"pointer",display:"flex",alignItems:"center",background:"transparent",color:"var(--reactaform-text-color, #000)",...l(u,"multiSelect","option"),...l(p,void 0,"option")}),[u,p]);s.useEffect(()=>{const R=j=>{const w=j.target;!i.current?.contains(w)&&!a.current?.contains(w)&&t()};return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[t,a]),s.useEffect(()=>{i.current&&r.length>0&&requestAnimationFrame(()=>m(R=>R===-1?0:R))},[r.length]),s.useEffect(()=>{if(!i.current||f<0)return;const R=i.current.querySelector(`#multi-opt-${f}`);R&&requestAnimationFrame(()=>R.focus())},[f]);const g=250,x=200,[v,C]=s.useState(null),[I,N]=s.useState(null);if(s.useEffect(()=>{if(typeof window>"u")return;const R=()=>{let k=e.x,A=e.y,$=g;const z=a?.current;if(z){const U=z.getBoundingClientRect();k=U.left,A=U.bottom,$=Math.max(80,Math.round(U.width))}k=Math.min(k,window.innerWidth-$),A=Math.min(A,window.innerHeight-x),C({left:k,top:A}),N($)};R(),window.addEventListener("scroll",R,!0),window.addEventListener("resize",R);let j=null;const w=a?.current;return typeof ResizeObserver<"u"&&w&&(j=new ResizeObserver(()=>R()),j.observe(w)),()=>{window.removeEventListener("scroll",R,!0),window.removeEventListener("resize",R),j&&w&&j.unobserve(w)}},[a,e.x,e.y]),typeof window>"u")return null;let S=document.getElementById("popup-root");return S||(S=document.createElement("div"),S.id="popup-root",document.body.appendChild(S)),je.createPortal(h.jsx("div",{ref:i,role:"listbox","aria-activedescendant":f>=0?`multi-opt-${f}`:void 0,style:{position:"absolute",top:v?v.top:e.y,left:v?v.left:e.x,width:I??g,...d},"data-reactaform-theme":c?"dark":"light",children:r.map((R,j)=>{const w=n.includes(R.value),k=c?"var(--reactaform-hover-bg, rgba(255,255,255,0.01))":"var(--reactaform-hover-bg, #eee)",A={...y,background:j===f?k:y.background};return h.jsxs("div",{id:`multi-opt-${j}`,onMouseDown:$=>{$.stopPropagation(),o(R.value)},onKeyDown:$=>{const z=r.length;switch($.key){case"ArrowDown":$.preventDefault(),m(U=>(U+1)%z);break;case"ArrowUp":$.preventDefault(),m(U=>(U-1+z)%z);break;case"Home":$.preventDefault(),m(0);break;case"End":$.preventDefault(),m(z-1);break;case"Enter":case" ":$.preventDefault(),$.stopPropagation(),o(R.value);break;case"Escape":$.preventDefault(),t(),a?.current?.focus();break}},tabIndex:j===f?0:-1,role:"option","aria-selected":w,style:A,onMouseEnter:$=>{$.currentTarget.style.background=k,m(j)},onMouseLeave:$=>{$.currentTarget.style.background="transparent",m(z=>z===j?-1:z)},children:[h.jsx("input",{type:"checkbox",checked:w,readOnly:!0,style:{marginRight:8,width:"1.125em",height:"1.125em",verticalAlign:"middle",accentColor:c?"#10b981":"#22c55e",cursor:"pointer"}}),R.label]},R.value)})}),S)},ht=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=V(),c=s.useRef(null),i=e.min??void 0,f=e.max??void 0,m=Math.max(1,Math.round(e.step??1)),u=s.useCallback(g=>isNaN(g)?t("Must be a valid integer"):Number.isInteger(g)?i!==void 0&&g<i?t("Must be �?{{1}}",i):f!==void 0&&g>f?t("Must be �?{{1}}",f):H(a,e,g,t)??null:t("Must be an integer"),[a,e,t,i,f]),p=s.useRef(null),l=s.useRef(o);s.useEffect(()=>{l.current=o},[o]),s.useEffect(()=>{if(document.activeElement===c.current)return;const x=String(r),v=u(r);c.current&&(c.current.value=x),v!==p.current&&(p.current=v,l.current?.(v??null))},[r,u]);const d=g=>{if(g.trim()==="")return e.required?t("Value required"):null;const v=Number(g);return u(v)},y=g=>{const x=g.target.value,v=g.target.valueAsNumber,C=d(x);n?.(v,C)};return h.jsx(B,{field:e,error:d(String(r??"")),children:h.jsx("input",{ref:c,id:e.name,type:"number",defaultValue:String(r??""),min:i,max:f,step:m,onChange:y,style:{width:"100%",height:"100%"},className:F.input})})},bt=({field:e,value:r,onChange:n,onError:o})=>{const{t}=V(),a=s.useRef(null),{definitionName:c}=V(),i=s.useCallback(p=>{const l=String(p??"").trim();if(l==="")return e.required?t("Value required"):null;if(e.pattern)try{if(!new RegExp(e.pattern).test(l))return t("Phone number does not match pattern: {{1}}",`${e.pattern}`)}catch{}return H(c,e,l,t)},[c,e,t]),f=s.useRef(null),m=s.useRef(o);s.useEffect(()=>{m.current=o},[o]),s.useEffect(()=>{const p=String(r??""),l=i(p);a.current&&a.current.value!==String(p)&&(a.current.value=String(p)),l!==f.current&&(f.current=l,m.current?.(l??null))},[r,i]);const u=p=>{const l=p.target.value,d=l.trim();let y=null;if(d===""){y=e.required?t("Value required"):null,n?.(l,y);return}!y&&e.pattern&&!new RegExp(e.pattern).test(d)&&(y=t("Phone number does not match pattern: {{1}}",`${e.pattern}`)),n?.(l,y)};return h.jsx(B,{field:e,error:i(String(r??"")),children:h.jsx("input",{type:"tel",defaultValue:String(r??""),ref:a,onChange:u,className:W(F.input,F.textInput)})})},yt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=V(),c=e.layout?.toLowerCase()==="horizontal"?"row":"column",i=s.useRef(null),f=s.useRef(o);s.useEffect(()=>{f.current=o},[o]);const m=s.useCallback(p=>p===""||p===null||p===void 0?t("Value required"):!e.options||e.options.length===0?null:e.options.some(d=>d.value===p)?H(a,e,p,t)??null:t("Invalid option selected"),[e,t,a]);s.useEffect(()=>{const p=r!=null?String(r):"",l=m(p);if(f.current?.(l??null),i.current){const d=Array.from(i.current.querySelectorAll("input[type=radio]"));if(l&&e.options&&e.options.length>0){const y=String(e.options[0].value);d.forEach(g=>g.checked=g.value===y),n?.(y,null)}else d.forEach(y=>y.checked=y.value===p)}},[r,m,n,e.options]);const u=p=>{const l=p.target.value,d=m(l);f.current?.(d??null),n?.(l,d)};return h.jsx(B,{field:e,error:m(String(r??"")),children:h.jsx("div",{style:{display:"flex",flexDirection:c,flexWrap:c==="row"?"wrap":"nowrap",gap:c==="row"?"12px":"4px",alignItems:c==="row"?"center":"flex-start",width:"100%"},ref:i,children:(e.options??[]).map(p=>h.jsxs("label",{style:{display:"flex",gap:"6px",alignItems:"center",whiteSpace:"nowrap"},children:[h.jsx("input",{type:"radio",name:e.name,value:String(p.value),defaultChecked:String(r??"")===String(p.value),onChange:u}),t(p.label)]},String(p.value)))})})},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:n,onError:o})=>{const{t,definitionName:a}=V(),[c,i]=s.useState(null),f=e.max||5,m=s.useCallback(y=>e.required&&y===0?t("Value required"):H(a,e,y,t)??null,[e,t,a]),u=s.useRef(null),p=s.useRef(o);s.useEffect(()=>{p.current=o},[o]),s.useEffect(()=>{let y=r||0;r<0&&(y=0),r>f&&(y=f);const g=m(y);g!==u.current&&(u.current=g,p.current?.(g??null))},[r,m,f]);const l=y=>{const g=m(y);n?.(y,g)},d=(()=>{let y=r||0;return y<0&&(y=0),y>f&&(y=f),y})();return h.jsx(B,{field:e,error:m(d),children:h.jsx("div",{style:xt,children:(()=>{const y=e.icon,g=y&&String(y).trim()?String(y):"★";return[...Array(f)].map((x,v)=>{const C=v<d,N=c!==null&&v<=c||C?"gold":"lightgray";return h.jsx("span",{onClick:()=>l(v+1),onMouseEnter:()=>i(v),onMouseLeave:()=>i(null),style:{...vt,color:N},"aria-label":`Rating ${v+1}`,title:t(`${e.displayName} ${v+1}`),children:g},v)})})()})})},St=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;function Ct(e){return St.test(e)}const Rt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=V(),c=s.useRef(null),i=s.useRef(null),f=s.useCallback(y=>{let g=null;if(y.trim()==="")return t("Value required");if(!Ct(y))return t("Invalid number");const x=Number(y);return typeof e.min=="number"&&x<e.min?t("Value should be at least {{1}}",e.min):typeof e.max=="number"&&x>e.max?t("Value should be at most {{1}}",e.max):(g||(g=H(a,e,x,t)),g)},[a,e,t]),m=s.useRef(null),u=s.useRef(o);s.useEffect(()=>{u.current=o},[o]),s.useEffect(()=>{const y=String(r),g=f(y);i.current&&document.activeElement!==i.current&&(i.current.value=isNaN(Number(y))?String(e.min??0):String(Number(y))),c.current&&document.activeElement!==c.current&&(c.current.value=y),g!==m.current&&(m.current=g,u.current?.(g??null))},[r,f,e.min]);const p=e.min??0,l=e.max??100,d=y=>{const g=y.target.value,x=f(g);n?.(g,x)};return h.jsx(B,{field:e,error:f(String(r??"")),children:h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%"},children:[h.jsx("input",{ref:i,type:"range",defaultValue:isNaN(Number(r))?String(p):String(Number(r)),onChange:d,min:p,max:l,style:{padding:"0px, 0px",flex:1},className:F.rangeInput}),h.jsx("input",{ref:c,type:"text",defaultValue:String(r??""),onChange:d,required:!0,style:{width:"40px",minWidth:"40px",height:"2.3em",textAlign:"center",flexShrink:0},className:W(F.input,F.textInput)})]})})},Et=({field:e,value:r,onChange:n,onError:o})=>{const{t,formStyle:a,fieldStyle:c,definitionName:i}=V(),f=a,m=c,u=(S,R,j)=>{if(!R)return{};const w=S?.[R];return(j&&w?w[j]:void 0)??{}},p=s.useMemo(()=>({display:"inline-block",position:"relative",width:44,height:24,...u(f,"switch","label"),...u(m,void 0,"label")}),[f,m]),l=s.useMemo(()=>({position:"absolute",opacity:0,top:0,left:0,width:"100%",height:"100%",margin:0,cursor:"pointer",pointerEvents:"none",...u(f,"switch","hiddenInput"),...u(m,void 0,"hiddenInput")}),[f,m]),d=s.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",...u(f,"switch","slider"),...u(m,void 0,"slider")}),[f,m]),y=s.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)",...u(f,"switch","knob"),...u(m,void 0,"knob")}),[f,m]),g=!!r,x=s.useRef(null),v=s.useRef(o),C=s.useCallback(S=>S?H(i,e,S,t)??null:e.required?t("Value required"):null,[e,t,i]),I=()=>{const S=!g,R=C(S);n?.(S,R)};s.useEffect(()=>{v.current=o},[o]),s.useEffect(()=>{const S=C(g);S!==x.current&&(x.current=S,v.current?.(S??null))},[g,e,C]);const N=e.name;return h.jsx(B,{field:e,error:C(g),rightAlign:!1,children:h.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[h.jsx("label",{className:F.label,htmlFor:N,style:{textAlign:"left",justifyContent:"flex-start"},children:t(e.displayName)}),h.jsxs("label",{style:p,children:[h.jsx("input",{id:e.name,type:"checkbox",checked:g,readOnly:!0,"aria-label":t(e.displayName),style:l,tabIndex:-1}),h.jsx("span",{role:"switch","data-testid":"switch",tabIndex:0,"aria-checked":g,onClick:I,onKeyDown:S=>{(S.key===" "||S.key==="Spacebar"||S.key==="Space"||S.key==="Enter")&&(S.preventDefault(),I())},className:`reactaform-switch ${g?"active checked on":""} `,style:g?{...d,backgroundColor:"var(--reactaform-switch-on-bg, #22c55e)",borderColor:"var(--reactaform-switch-on-border, #16a34a)"}:d,children:h.jsx("span",{style:{...y,transform:g?"translateX(20px)":void 0}})})]})]})})},He=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=V(),c=s.useRef(null),i=s.useRef(null),f=s.useRef(o);s.useEffect(()=>{f.current=o},[o]);const m=s.useMemo(()=>e.pattern?new RegExp(e.pattern):null,[e.pattern]),u=s.useCallback(l=>l.trim()===""?e.required?t("Value required"):null:e.minLength!==void 0&&l.length<e.minLength?t("Must be at least {{1}} characters",e.minLength):e.maxLength!==void 0&&l.length>e.maxLength?t("Must be at most {{1}} characters",e.maxLength):m&&!m.test(l)?t("Input does not match pattern: {{1}}",e.pattern):H(a,e,l,t),[e,a,t,m]),p=l=>{const d=l.target.value,y=u(d);n?.(d,y)};return s.useEffect(()=>{const l=u(r);c.current&&c.current.value!==String(r??"")&&(c.current.value=String(r??"")),l!==i.current&&(i.current=l,f.current?.(l??null))},[r,u]),h.jsx(B,{field:e,error:u(String(r??"")),children:h.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:c,onChange:p,className:W(F.input,F.textInput)})})},jt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=V(),c=s.useRef(null),i=s.useRef(o),f=e.includeSeconds??!0;s.useEffect(()=>{i.current=o},[o]);const m=s.useCallback(p=>{if(!p||p.trim()==="")return e.required||e.min||e.max?t("Value required"):null;const l=g=>{const x=g.split(":").map(C=>parseInt(C,10));if(x.some(C=>Number.isNaN(C)))return NaN;let v=0;if(x.length===3)v=x[0]*3600+x[1]*60+x[2];else if(x.length===2)v=x[0]*3600+x[1]*60;else if(x.length===1)v=x[0]*3600;else return NaN;return v},d=l(p);if(Number.isNaN(d))return t("Invalid time format");if(e.min&&typeof e.min=="string"){const g=l(e.min);if(!Number.isNaN(g)&&d<g)return t("Time must be on or after {{1}}",e.min)}if(e.max&&typeof e.max=="string"){const g=l(e.max);if(!Number.isNaN(g)&&d>g)return t("Time must be on or before {{1}}",e.max)}return H(a,e,p,t)??null},[e,a,t]),u=p=>{const l=p.target.value,d=m(l);n?.(l,d)};return s.useEffect(()=>{const p=m(r);p!==c.current&&(c.current=p,i.current?.(p??null))},[r,m]),h.jsx(B,{field:e,error:m(r),children:h.jsx("input",{id:e.name,type:"time",value:r,step:f?1:60,onChange:u,min:typeof e.min=="string"?e.min:void 0,max:typeof e.max=="string"?e.max:void 0,className:W(F.input,F.textInput)})})},fe={};function kt(e,r){if(e in fe)return;const n=Oe[e]??{},o={},t={},a={};for(const[i,f]of Object.entries(n))typeof f.factor=="number"&&(o[i]=f.factor),t[i]=r(i),a[r(i)]=i;const c=Object.keys(n)[0]??"";fe[e]={default:c,factors:o,labels:t,reverseLabels:a}}function Nt(e,r,n){if(e==="C"){if(r==="F")return n*(9/5)+32;if(r==="K")return n+273.15}else if(e==="F"){if(r==="C")return(n-32)*5/9;if(r==="K")return(n-32)*5/9+273.15}else if(e==="K"){if(r==="C")return n-273.15;if(r==="F")return(n-273.15)*9/5+32}return n}function It(e,r,n){if(!Number.isFinite(e))return[];if(n===fe.temperature)return Object.keys(n.labels).map(a=>{const c=Nt(r,a,e);return Number.isFinite(c)?{label:`${c.toFixed(6)} ${a}`,value:c.toString(),unit:a}:{label:`${String(c)} ${a}`,value:String(c),unit:a}});const t=n.factors[r];return t===void 0?[]:Object.entries(n.factors).map(([a,c])=>{const i=e/t*c;return Number.isFinite(i)?{label:`${i.toFixed(6)} ${a}`,value:i.toString(),unit:a}:{label:`${String(i)} ${a}`,value:String(i),unit:a}})}function pe(e,r){return e in r.labels?e:r.reverseLabels&&r.reverseLabels[e]?r.reverseLabels[e]:null}const Ft=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/,At=({unitFactors:e,field:r,value:n,onChange:o,onError:t})=>{const{t:a,definitionName:c}=V(),i=s.useRef(null),f=s.useRef(null),m=s.useRef(null),[u,p]=s.useState(null),[l,d]=s.useState(null),[y,g]=s.useState(!1),[x,v]=s.useState(null),[C,I]=s.useState([]),N=s.useCallback((T,M)=>{if(!T||T.trim()==="")return r.required?a("Value required"):null;if(!Ft.test(T))return a("Must be a valid number");const b=H(c,r,[T,M],a);return b||null},[c,r,a]),S=e.reverseLabels!==void 0?e.reverseLabels:Object.fromEntries(Object.entries(e.labels).map(([T,M])=>[M,T]));s.useEffect(()=>{const T=String(n[0]);let M=n[1]??e.default;M=pe(M,e)||M;const b=document.activeElement;b===i.current||b===f.current||(i.current&&(i.current.value=T),f.current&&(f.current.value=M),m.current!==null&&(cancelAnimationFrame(m.current),m.current=null),m.current=requestAnimationFrame(()=>{m.current=null,p(null),d(null)}))},[n,e]),s.useEffect(()=>()=>{m.current!==null&&(cancelAnimationFrame(m.current),m.current=null)},[]);const R=s.useRef(null),j=s.useRef(t);s.useEffect(()=>{j.current=t},[t]),s.useEffect(()=>{const T=String(n[0]);let M=n[1]??e.default;M=pe(M,e)||M;const b=N(T,M);b!==R.current&&(R.current=b,j.current?.(b??null))},[n,e,N]);const w=(T,M,b)=>{const E=S[M]||M;o?.([T,E],b)},k=T=>{const M=T.target.value,b=f.current?f.current.value:e.default,E=N(M,b);p(M),w(M,b,E)},A=T=>{const M=T.target.value,b=i.current?i.current.value:String(n[0]??""),E=N(b,M);d(M),f.current&&(f.current.value=M),w(b,M,E)},$=T=>{const M=i.current?i.current.value:String(n[0]??""),b=parseFloat(M),E=f.current?f.current.value:e.default;if(N(M,E)||!M.trim()||!Number.isFinite(b))return;const q=T.currentTarget.getBoundingClientRect(),Z=q.left,ee=q.bottom;v({x:Z,y:ee});const D=It(b,E,e);if(D.length===0){I([]),g(!1);return}I(D),g(O=>!O)},z=T=>{const{value:M,unit:b}=T;g(!1),v(null),i.current&&(i.current.value=M),f.current&&(f.current.value=b),p(M),d(b);const E=N(M,b);w(M,b,E)},U=String(n[0]??""),ne=pe(n[1]??e.default,e)||(n[1]??e.default),K=u??U,J=!!N(K,l??ne)||!K.trim(),Q={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:J?"var(--reactaform-button-disabled-bg, #cccccc)":"var(--reactaform-button-bg, var(--reactaform-success-color))",color:"var(--reactaform-button-text, #ffffff)",cursor:J?"var(--reactaform-button-disabled-cursor, not-allowed)":"pointer",opacity:J?+"var(--reactaform-button-disabled-opacity, 0.6)":1,display:"flex",alignItems:"center",justifyContent:"center"};return h.jsx(B,{field:r,error:N(U,ne),children:h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--reactaform-unit-gap, 8px)",width:"100%"},children:[h.jsx("input",{type:"text",ref:i,defaultValue:String(n[0]??""),onChange:k,style:{width:"var(--reactaform-unit-input-width, 100px)"},className:W(F.input,F.textInput)}),h.jsx("select",{ref:f,defaultValue:pe(n[1]??e.default,e)||(n[1]??e.default),onChange:A,className:W(F.input,F.inputSelect),children:Object.keys(e.labels).map(T=>h.jsx("option",{value:T,children:e.labels[T]??T},T))}),h.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[h.jsx("button",{onClick:$,"aria-disabled":J,disabled:J,style:Q,className:F.button,children:h.jsx("span",{style:{fontSize:"var(--reactaform-unit-btn-icon-size, 1em)",lineHeight:"1",transform:"translateY(-1px)",pointerEvents:"none"},children:"⟷"})}),y&&C&&h.jsx(nr,{pos:x,options:C,onClose:()=>{v(null),g(!1)},onClickOption:z})]})]})})};function Mt({field:e,value:r,onChange:n}){const{t:o}=V(),t=e.dimension;if(!t)return null;fe[t]||kt(t,o);const a=fe[t];return a?h.jsx(At,{unitFactors:a,field:e,value:r,onChange:n}):null}const Ot=/^(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$/i,$t=e=>{try{return new URL(e),!0}catch{return!1}},Vt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=V(),c=s.useRef(null),i=s.useCallback(p=>{const l=p.trim();return l===""?e.required?t("Value required"):null:!Ot.test(l)&&!$t(l)?t("Must be a valid URL"):H(a,e,l,t)??null},[a,e,t]),f=p=>{const l=p.target.value,d=i(l);n?.(l.trim(),d)},m=s.useRef(null),u=s.useRef(o);return s.useEffect(()=>{u.current=o},[o]),s.useEffect(()=>{const p=r??"",l=i(p);c.current&&c.current.value!==String(p)&&(c.current.value=String(p)),l!==m.current&&(m.current=l,u.current?.(l??null))},[r,i]),h.jsx(B,{field:e,error:i(String(r??"")),children:h.jsx("input",{id:e.name,type:"url",defaultValue:String(r??""),ref:c,onChange:f,style:{alignItems:"left"},className:W(F.input,F.textInput),placeholder:"https://example.com"})})},Ee=new ge,zt=new Set(["checkbox","switch","dropdown","radio","multi-selection","slider","stepper","color","rating"]),or={checkbox:Hr,color:Wr,date:Jr,dropdown:Gr,email:Xr,file:Qr,float:st,"float-array":nt,image:ct,int:mt,"int-array":ut,"multi-selection":pt,multiline:dt,phone:bt,radio:yt,rating:wt,separator:Zr,slider:Rt,string:He,stepper:ht,switch:Et,text:He,time:jt,unit:Mt,url:Vt};function ar(e,r,n){if(!n&&e in or){console.warn(`Can't Overwrite Base Component type "${e}".`);return}if(zt.has(e)){Ee.register(e,r);return}const o=t=>{const{callback:c,cancel:i}=We((...f)=>{const m=t.onChange;typeof m=="function"&&m(...f)},200);return s.useEffect(()=>()=>{i()},[i]),s.createElement(r,{...t,onChange:c})};Ee.register(e,o)}function Tt(e,r){ar(e,r,!1)}function sr(e){return Ee.get(e)}let Ue=!1;function ir(){Ue||(Object.entries(or).forEach(([e,r])=>{ar(e,r,!0)}),Ue=!0)}const cr=new ge;function lr(e,r){cr.register(e,r)}function Dt(e){return cr.get(e)}lr("Preset_AlertSubmitHandler",(e,r,n)=>{const o={name:r||"Unnamed Instance",version:e.version,definition:e.name,values:n},t=JSON.stringify(o,null,2);alert(t)});const ur=s.memo(({field:e,value:r,handleChange:n,handleError:o})=>{const t=sr(e.type),a=s.useCallback((i,f)=>n(e.name,i,f),[n,e.name]),c=s.useCallback(i=>o?.(e.name,i),[o,e.name]);return t?h.jsx(t,{field:e,value:r,onChange:a,onError:c}):null},(e,r)=>e.field===r.field&&e.value===r.value&&e.handleChange===r.handleChange&&e.handleError===r.handleError);ur.displayName="FieldWrapper";const fr=(e,r,n,o)=>h.jsx(ur,{field:e,value:r[e.name],handleChange:n,handleError:o},e.name),mr=s.memo(({groupName:e,isOpen:r,fields:n,valuesMap:o,handleChange:t,handleError:a,toggleGroup:c,t:i})=>{const f=s.useCallback(()=>c(e),[c,e]),{formStyle:m,fieldStyle:u}=V(),p=s.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)",...m?.fieldset||{},...u?.fieldset||{}}),[m,u]),l=s.useMemo(()=>({fontWeight:"bold",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0 var(--reactaform-space, 8px)",color:"var(--reactaform-text-color, inherit)",...m?.legend||{},...u?.legend||{}}),[m,u]);return h.jsxs("fieldset",{style:p,children:[h.jsxs("legend",{onClick:f,style:l,children:[h.jsx("span",{children:i(e)}),h.jsx("span",{children:r?"▼":"▶"})]}),r&&n.map(d=>h.jsx("div",{children:fr(d,o,t,a)},d.name))]})});mr.displayName="FieldGroup";const Lt=(e,r,n,o,t,a,c,i,f)=>{const m=r.slice(0,i).filter(d=>c[d.name]),p=zr(m).groups,l=[];return p.forEach(d=>{if(d.name){const y=e[d.name]??!0;l.push(h.jsx(mr,{groupName:d.name,isOpen:y,fields:d.fields,valuesMap:n,handleChange:t,handleError:a,toggleGroup:f,t:o},d.name))}else d.fields.forEach(y=>l.push(h.jsx("div",{children:fr(y,n,t,a)},y.name)))}),l},Pt=e=>{const r={};return e.forEach(n=>{r[n.name]=!1}),r},$e=(e,r,n,o)=>{const t=r[e];if(!t?.children)return;const a=n[e],c=a!=null?String(a):"";(t.children[c]||[]).forEach(f=>{o[f]=!0,$e(f,r,n,o)})},dr=(e,r,n)=>{const o=r[e];o?.children&&Object.values(o.children).flat().forEach(t=>{n[t]=!1,dr(t,r,n)})},_t=(e,r,n,o)=>{const t={...n};return e.forEach(a=>{(!a.parents||Object.keys(a.parents).length===0)&&(t[a.name]=!0,$e(a.name,o,r,t))}),t},qt=(e,r,n,o,t)=>{const a={...e};if(dr(o,r,a),t!=null){const c=r[o];if(c?.children){const i=String(t);(c.children[i]||[]).forEach(m=>{a[m]=!0,$e(m,r,n,a)})}}return a};function Bt(e,r,n,o,t){const a=Object.values(t).filter(Boolean);if(a.length>0)return{success:!1,message:o("Please fix validation errors before submitting."),errors:a};const c={...n},i=[];if(e&&Array.isArray(e.properties))for(const m of e.properties){const u=m.name,p=c[u];if(p==null)continue;const l=m.type;try{if((l==="int"||l==="number"||l==="float")&&typeof p=="string"){const d=Number(String(p).trim());isNaN(d)?i.push(o(`Invalid number format for field ${m.displayName||u}`)):c[u]=d}else if((l==="int-array"||l==="float-array")&&typeof p=="string"){const y=String(p).split(",").map(g=>g.trim()).filter(Boolean).map(g=>{const x=Number(g);return isNaN(x)?(i.push(o(`Invalid number "${g}" in array for field ${m.displayName||u}`)),0):x});i.length===0&&(c[u]=y)}}catch(d){i.push(o(`Error processing field ${m.displayName||u}: ${d}`))}}if(i.length>0)return{success:!1,message:o("Data transformation errors occurred."),errors:i};const f=Ze(e,c,o);if(f&&f.length>0)return{success:!1,message:"Validation Fail",errors:f};if(e&&typeof e.submitHandlerName=="string"){const m=Dt(e.submitHandlerName);if(m)try{const u=m(e,r?.name??null,c,o);if(u&&u.length>0)return{success:!1,message:o("Submission failed."),errors:Array.isArray(u)?u:[u]}}catch(u){return{success:!1,message:o("Submission handler error occurred."),errors:[String(u)]}}}return{success:!0,message:o("Form submitted successfully."),data:c}}const pr=({definition:e,instance:r,chunkSize:n=50,chunkDelay:o=50})=>{const{properties:t,displayName:a}=e,c=V(),{t:i,formStyle:f,language:m}=c,u={...c,definitionName:e?.name??c.definitionName},[p,l]=s.useState("en"),[d,y]=s.useState([]),[g,x]=s.useState({}),[v,C]=s.useState({}),[I,N]=s.useState({}),[S,R]=s.useState({}),[j,w]=s.useState({}),[k,A]=s.useState(null),[$,z]=s.useState(null),[U,ne]=s.useState(0),[K,ae]=s.useState(!1),[J,Q]=s.useState(!1),[T,M]=s.useState(r.name||""),b=s.useRef(r),E=s.useRef(!1);s.useEffect(()=>{const O=Object.fromEntries(t.map(_=>[_.name,{..._,children:{}}]));t.forEach(_=>{_.parents&&Object.entries(_.parents).forEach(([se,he])=>{const ie=O[se];ie&&he.forEach(br=>{ie.children||(ie.children={});const Ve=String(br);ie.children[Ve]=[...ie.children[Ve]||[],_.name]})})}),Vr(t,O);const L=Object.values(O),Y={};L.forEach(_=>{if(_.type==="unit"){const se=typeof _.defaultValue=="number"?String(_.defaultValue):"",he=typeof _.defaultUnit=="string"?_.defaultUnit:String(_.defaultUnit??"m");Y[_.name]=[se,he]}else Y[_.name]=_.defaultValue}),b.current=r,Object.keys(r.values).forEach(_=>{O[_]!==void 0&&(Y[_]=r.values[_])});const G=Pt(L),X={};L.forEach(_=>{_.group&&!(_.group in X)&&(X[_.group]=!0)});const oe=requestAnimationFrame(()=>{y(L),x(O),C(Y),N(_t(L,Y,G,O)),R(X),ae(!0),M(r.name)});return()=>cancelAnimationFrame(oe)},[t,r,e]),s.useEffect(()=>{if(!K||U>=d.length)return;const O=setTimeout(()=>{ne(L=>Math.min(L+n,d.length))},o);return()=>clearTimeout(O)},[K,U,d.length,n,o]);const P=s.useCallback((O,L,Y)=>{A(null),z(null),C(G=>{const X={...G,[O]:L},oe=g[O];return oe&&["checkbox","dropdown","multi-select","radio","switch"].includes(oe.type)&&N(se=>qt(se,g,X,O,String(L))),X}),w(G=>Y?{...G,[O]:Y}:Object.fromEntries(Object.entries(G).filter(([oe])=>oe!==O)))},[g,A,z]);s.useEffect(()=>{let O=0;return O=requestAnimationFrame(()=>{m!==p&&(l(m||"en"),A(null),z(null))}),()=>cancelAnimationFrame(O)},[m,p]),s.useEffect(()=>{let O=0;return O=requestAnimationFrame(()=>{if(E.current){E.current=!1,b.current=r,M(r.name||"");return}b.current=r,A(null),z(null),M(r.name||"")}),()=>cancelAnimationFrame(O)},[r,r.name]);const q=s.useCallback((O,L)=>{w(Y=>L?{...Y,[O]:String(L)}:Object.fromEntries(Object.entries(Y).filter(([X])=>X!==O)))},[]),Z=()=>{E.current=!0;const O=b.current?.name;b.current.name=T;const L=Bt(e,b.current,v,i,j),Y=typeof L.message=="string"?L.message:String(L.message),G=Object.values(L.errors??{}).join(`
|
|
293
|
-
`);
|
|
294
|
-
`+G:Y),
|
|
292
|
+
<%s key={someKey} {...props} />`,q,T,O,T),A[T+q]=!0)}if(T=null,P!==void 0&&(n(P),T=""+P),i(j)&&(n(j.key),T=""+j.key),"key"in j){P={};for(var L in j)L!=="key"&&(P[L]=j[L])}else P=j;return T&&c(P,typeof b=="function"?b.displayName||b.name||"Unknown":b),m(b,T,P,t(),Z,ee)}function d(b){l(b)?b._store&&(b._store.validated=1):typeof b=="object"&&b!==null&&b.$$typeof===N&&(b._payload.status==="fulfilled"?l(b._payload.value)&&b._payload.value._store&&(b._payload.value._store.validated=1):b._store&&(b._store.validated=1))}function l(b){return typeof b=="object"&&b!==null&&b.$$typeof===y}var p=s,y=Symbol.for("react.transitional.element"),g=Symbol.for("react.portal"),x=Symbol.for("react.fragment"),v=Symbol.for("react.strict_mode"),w=Symbol.for("react.profiler"),I=Symbol.for("react.consumer"),E=Symbol.for("react.context"),S=Symbol.for("react.forward_ref"),R=Symbol.for("react.suspense"),k=Symbol.for("react.suspense_list"),C=Symbol.for("react.memo"),N=Symbol.for("react.lazy"),F=Symbol.for("react.activity"),$=Symbol.for("react.client.reference"),V=p.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,U=Object.prototype.hasOwnProperty,ne=Array.isArray,K=console.createTask?console.createTask:function(){return null};p={react_stack_bottom_frame:function(b){return b()}};var ae,J={},Q=p.react_stack_bottom_frame.bind(p,a)(),z=K(o(a)),A={};le.Fragment=x,le.jsx=function(b,j,P){var q=1e4>V.recentlyCreatedOwnerStacks++;return u(b,j,P,!1,q?Error("react-stack-top-frame"):Q,q?K(o(b)):z)},le.jsxs=function(b,j,P){var q=1e4>V.recentlyCreatedOwnerStacks++;return u(b,j,P,!0,q?Error("react-stack-top-frame"):Q,q?K(o(b)):z)}})()),le}var Te;function vr(){return Te||(Te=1,process.env.NODE_ENV==="production"?me.exports=yr():me.exports=xr()),me.exports}var h=vr();const ke=s.createContext(void 0),D=()=>{const e=s.useContext(ke);if(!e)throw new Error("❌ useReactaFormContext must be used within a <ReactaFormProvider>");return e};class ge{map={};register(r,n){this.map[r]=n}get(r){return this.map[r]}has(r){return 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(([n,o])=>this.register(n,o)):Object.entries(r).forEach(([n,o])=>this.register(n,o))}getOrDefault(r,n){return this.get(r)??n}}function We(e,r=300,n){const o=s.useRef(void 0),t=s.useRef(e),a=s.useRef(null),i=s.useRef(!1);s.useEffect(()=>{t.current=e},[e]),s.useEffect(()=>()=>{o.current!==void 0&&(window.clearTimeout(o.current),o.current=void 0)},[]);const c=s.useCallback(()=>{o.current!==void 0&&(window.clearTimeout(o.current),o.current=void 0),a.current=null,i.current=!1},[]),f=s.useCallback(()=>{if(o.current!==void 0&&(window.clearTimeout(o.current),o.current=void 0),a.current)try{t.current(...a.current)}finally{a.current=null,i.current=!1}},[]);return{callback:s.useCallback((...u)=>{if(n?.leading===!0&&!i.current){i.current=!0,t.current(...u),window.clearTimeout(o.current),o.current=window.setTimeout(()=>{i.current=!1,o.current=void 0},r);return}a.current=u,window.clearTimeout(o.current),o.current=window.setTimeout(()=>{o.current=void 0,a.current&&(t.current(...a.current),a.current=null,i.current=!1)},r)},[r,n?.leading]),cancel:c,flush:f}}const M={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"},W=(...e)=>{const r=[];for(const n of e)n&&(typeof n=="string"?r.push(n):typeof n=="object"&&Object.entries(n).forEach(([o,t])=>{t&&r.push(o)}));return r.join(" ")},Ye=({content:e,size:r="medium",animation:n=!0})=>{const{t:o,darkMode:t,formStyle:a,fieldStyle:i}=D(),[c,f]=s.useState(!1),[m,u]=s.useState({x:0,y:0}),[d,l]=s.useState(!1),p=s.useRef(null),y=s.useRef(null),g=s.useRef(null),x=s.useMemo(()=>{const E={icon:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:"1.2em",height:"1.2em",fontSize:"0.9em",fontWeight:"bold",borderRadius:"50%",backgroundColor:t?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.06)",color:t?"#f0f0f0":"#333",border:`1px solid ${t?"rgba(255,255,255,0.2)":"rgba(0,0,0,0.1)"}`,cursor:"pointer",transition:n?"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:"absolute",backgroundColor:`var(--reactaform-tooltip-color-bg, ${t?"rgba(45,45,45,0.95)":"rgba(60,60,60,0.92)"})`,color:`var(--reactaform-tooltip-color, ${t?"#f0f0f0":"#fff"})`,borderRadius:"6px",border:`1px solid ${t?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.1)"}`,boxShadow:t?"0 8px 16px rgba(0,0,0,0.4)":"0 6px 18px rgba(0,0,0,0.12)",zIndex:2147483647,opacity:0,visibility:"hidden",transition:n?"opacity 0.2s ease, visibility 0.2s ease":void 0,pointerEvents:"none",whiteSpace:"normal",wordBreak:"break-word",boxSizing:"border-box"},textVisible:{opacity:1,visibility:"visible"}},S=(k,C,N)=>{const $=k?.[C];return(N&&$?$[N]:void 0)??{}};return{icon:{...E.icon,...S(a,"tooltip","icon"),...S(i,"tooltip","icon")},text:{...E.text,...S(a,"tooltip","text"),...S(i,"tooltip","text")},textVisible:E.textVisible}},[t,r,n,a,i]);s.useEffect(()=>{if(c){const I=requestAnimationFrame(()=>l(!1)),E=requestAnimationFrame(()=>{if(p.current){const S=p.current.getBoundingClientRect(),R=8;g.current=S;const k=S.right+R,C=S.top;u({x:k,y:C}),l(!0)}});return()=>{cancelAnimationFrame(E),cancelAnimationFrame(I)}}else requestAnimationFrame(()=>l(!1))},[c]),s.useEffect(()=>{if(!d)return;const I=requestAnimationFrame(()=>{if(!y.current)return;const E=y.current.getBoundingClientRect(),S=8,R=typeof window<"u"?window.innerWidth:1024,k=typeof window<"u"?window.innerHeight:768;let C=m.x,N=m.y;const F=g.current;F&&(C=F.right+S,N=F.top+F.height/2-E.height/2+-4,C+E.width>R-S&&(C=F.left-S-E.width)),C+E.width>R-S&&(C=Math.max(S,R-E.width-S)),C<S&&(C=S),N+E.height>k-S&&(N=Math.max(S,k-E.height-S)),N<S&&(N=S),(C!==m.x||N!==m.y)&&u({x:C,y:N})});return()=>cancelAnimationFrame(I)},[d,m.x,m.y]);const v=typeof document<"u"?document.getElementById("popup-root"):null,w=h.jsx("div",{ref:y,style:{...x.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?x.textVisible:{},top:m.y,left:m.x},"data-reactaform-theme":t?"dark":"light",children:o(e)});return h.jsxs(h.Fragment,{children:[h.jsx("span",{"data-testid":"tooltip-icon",ref:p,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),style:{...x.icon},children:"?"}),c&&(v?je.createPortal(w,v):w)]})},ve=s.memo(({field:e,error:r,children:n,showLabel:o=!0})=>{const{t}=D(),a=e?.labelLayout==="column-center"?"center":"left";return h.jsxs("div",{className:`${M.field} column-layout`,style:{display:"flex",flexDirection:"column",gap:"var(--reactaform-label-gap, 4px)","--label-align":a},children:[o&&h.jsx("div",{style:{textAlign:a,width:"100%"},children:h.jsx("label",{className:M.label,htmlFor:e.name,style:{textAlign:a,width:"100%",minWidth:"unset",display:"block"},children:t(e.displayName)})}),h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--reactaform-inline-gap, 8px)",width:"100%"},children:[h.jsx("div",{style:{flex:1,minWidth:0,maxWidth:"100%"},children:h.jsx("div",{style:{width:"100%"},children:n})}),e.tooltip&&h.jsx(Ye,{content:e.tooltip})]}),r&&h.jsx(Ne,{children:r})]})});ve.displayName="ColumnFieldLayout";const Je=s.memo(({field:e,error:r,children:n,rightAlign:o=!1})=>{const{t}=D(),a=s.useMemo(()=>({display:"flex",flexDirection:"column",gap:0}),[]),i=s.useMemo(()=>({display:"flex",flexDirection:"row",alignItems:"center",gap:"3px"}),[]);return h.jsxs("div",{className:`${M.field} row-layout`,children:[h.jsx("label",{className:M.label,htmlFor:e.name,style:{textAlign:"left",justifyContent:"flex-start"},children:t(e.displayName)}),h.jsxs("div",{style:a,children:[h.jsxs("div",{style:i,children:[o?h.jsx("div",{style:{display:"flex",flex:1,justifyContent:"flex-end",alignItems:"center",gap:"var(--reactaform-inline-gap, 8px)"},children:n}):n,e.tooltip&&h.jsx(Ye,{content:e.tooltip})]}),r&&h.jsx(Ne,{children:r})]})]})});Je.displayName="RowFieldLayout";const B=({field:e,error:r,children:n,rightAlign:o=!1})=>e?.labelLayout==="column-left"||e?.labelLayout==="column-center"?h.jsx(ve,{field:e,error:r,showLabel:!0,children:n}):e?.type==="checkbox"||e?.type==="switch"?h.jsx(ve,{field:e,error:r,showLabel:!1,children:n}):h.jsx(Je,{field:e,error:r,rightAlign:o,children:n}),Ne=s.memo(({children:e})=>{const r=s.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 h.jsx("div",{style:r,children:e})});Ne.displayName="ErrorDiv";const Ge=s.memo(({name:e,onChange:r})=>{const{t:n}=D();return h.jsxs("div",{style:{marginBottom:16},children:[h.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 2fr",gap:12,alignItems:"center"},children:[h.jsx("label",{htmlFor:"instance-name-input",style:{margin:0,fontSize:"0.95em",fontWeight:500,color:"var(--reactaform-text-color, #333)"},children:n("Instance Name")}),h.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:n("Enter instance name")})]}),h.jsx("div",{style:{height:"1px",backgroundColor:"var(--reactaform-separator, #e6e6e6)",marginTop:12,marginBottom:12}})]})});Ge.displayName="InstanceName";class wr extends ge{registerInCategory(r,n,o){this.get(r)||this.register(r,{});const t=this.get(r);t[n]=o}getFromCategory(r,n){return this.get(r)?.[n]}listFromCategory(r){return Object.keys(this.get(r)||{})}listCategories(){return this.list()}}const Ke=new ge,Xe=new wr;function Sr(e,r){Ke.register(e,r)}function Cr(e,r,n){Xe.registerInCategory(e,r,n)}function Rr(e,r){return Xe.getFromCategory(e,r)||null}function Er(e){return Ke.get(e)||null}const be=new Map,ye=new Map;function H(e,r,n,o){if(r&&typeof r.validationHandlerName=="string"){const t=`${e}:${r.validationHandlerName}`;if(!be.has(t)){const i=Rr(e,r.validationHandlerName);be.set(t,i)}const a=be.get(t);if(a)return a(n,o)||null}return null}function Ze(e,r,n){if(e&&typeof e.validationHandlerName=="string"){const o=e.validationHandlerName;if(!ye.has(o)){const a=Er(o);ye.set(o,a)}const t=ye.get(o);if(t)return t(r,n)||null}return null}function te(e){return typeof e=="object"&&e!==null}function Ie(e){if(!te(e))return!1;const r=e;return typeof r.name=="string"&&typeof r.displayName=="string"}function Qe(e){if(!te(e))return!1;const r=e;return typeof r.name!="string"||typeof r.version!="string"||!Array.isArray(r.properties)?!1:r.properties.every(n=>Ie(n))}function we(e){try{return typeof File<"u"&&e instanceof File}catch{const r=te(e)?e:void 0;return!!r&&typeof r.name=="string"&&typeof r.size=="number"}}function jr(e,r,n={}){try{const{includeMetadata:o=!1,dateFormat:t="iso",fileHandling:a="metadata",prettify:i=!1,excludeFields:c=[],includeOnlyFields:f=[]}=n;if(!e||typeof e!="object")return{success:!1,error:"Instance must be a valid object"};const m=[],u=[],d={},p=(Qe(r)||te(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Ie),y=new Map(p.map(x=>[x.name,x]));for(const[x,v]of Object.entries(e)){if(c.includes(x)){u.push(x);continue}if(f.length>0&&!f.includes(x)){u.push(x);continue}if(v===void 0)continue;const w=y.get(x);try{d[x]=kr(v,w,{dateFormat:t,fileHandling:a})}catch(I){m.push(`Error serializing field '${x}': ${String(I)}`),d[x]=null}}return o&&(d._metadata={serializedAt:new Date().toISOString(),version:(te(r)?r.version:void 0)||"1.0.0",fieldCount:Object.keys(d).length-1}),{success:!0,data:i?JSON.stringify(d,null,2):JSON.stringify(d),metadata:{fieldCount:Object.keys(d).length,excludedFields:u,warnings:m}}}catch(o){return{success:!1,error:`Serialization failed: ${o instanceof Error?o.message:"Unknown error"}`}}}function kr(e,r,n={}){const{dateFormat:o="iso",fileHandling:t="metadata"}=n;if(e==null)return null;if(r)switch(r.type){case"date":case"datetime":case"date-time":return Le(e,o);case"file":return Pe(e,t);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?Le(e,o):we(e)||Array.isArray(e)&&we(e[0])?Pe(e,t):e}function Le(e,r){let n=null;if(e instanceof Date)n=e;else if(typeof e=="string"){const o=new Date(e);if(!isNaN(o.getTime()))n=o;else return e}else return e;switch(r){case"timestamp":return n.getTime();case"locale":return n.toLocaleString();case"iso":default:return n.toISOString()}}function Pe(e,r){return r==="skip"?null:Array.isArray(e)?e.map(n=>_e(n,r)):_e(e,r)}function _e(e,r){if(!we(e))return e;const n=e;return r==="metadata"?{name:n.name,size:n.size,type:n.type,lastModified:n.lastModified}:{name:n.name,size:n.size,type:n.type,lastModified:n.lastModified,_note:"Base64 encoding requires async implementation"}}function Nr(e,r,n={}){try{const{strict:o=!1,validateTypes:t=!0,preserveUnknownFields:a=!0,dateFormat:i="auto"}=n;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(g){return{success:!1,error:`Invalid JSON: ${g instanceof Error?g.message:"Unknown parsing error"}`}}if(!c||typeof c!="object")return{success:!1,error:"Parsed data must be an object"};const f=[],m=[],u={},l=(Qe(r)||te(r)&&Array.isArray(r.properties)?r.properties:[]).filter(Ie),p=new Map(l.map(g=>[g.name,g]));for(const g of l){const x=g.name,v=c[x];if(v===void 0){o&&g.required&&m.push(`Required field '${x}' is missing`);continue}try{u[x]=Ir(v,g,{validateTypes:t,dateFormat:i})}catch(w){const I=`Error deserializing field '${x}': ${String(w)}`;o?m.push(I):(f.push(I),u[x]=v)}}if(a)for(const[g,x]of Object.entries(c))!p.has(g)&&g!=="_metadata"&&(o&&f.push(`Unknown field '${g}' preserved`),u[g]=x);const y=m.length>0;return{success:!y,data:u,warnings:f.length>0?f:void 0,validationErrors:y?m:void 0}}catch(o){return{success:!1,error:`Deserialization failed: ${o instanceof Error?o.message:"Unknown error"}`}}}function Ir(e,r,n={}){const{validateTypes:o=!0,dateFormat:t="auto"}=n;if(e==null)return e;try{switch(r.type){case"date":case"datetime":case"date-time":return Mr(e,t,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 qe(e,"integer",o);case"float-array":return qe(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:n=!0,includeMetadata:o=!0}=r;if(!e||typeof e!="object")return{success:!1,error:"Definition must be a valid object"};const t={...e};return o&&(t._metadata={serializedAt:new Date().toISOString(),version:t.version||"1.0.0",propertyCount:(Array.isArray(t.properties)?t.properties.length:0)||0}),{success:!0,data:n?JSON.stringify(t,null,2):JSON.stringify(t),metadata:{fieldCount:(Array.isArray(t.properties)?t.properties.length:0)||0,excludedFields:[],warnings:[]}}}catch(n){return{success:!1,error:`Definition serialization failed: ${n instanceof Error?n.message:"Unknown error"}`}}}function Ar(e,r={}){try{const{strict:n=!1,validateTypes:o=!0}=r;let t;if(typeof e=="string")try{t=JSON.parse(e)}catch(u){return{success:!1,error:`Invalid JSON for definition: ${u instanceof Error?u.message:"Unknown parsing error"}`}}else if(e&&typeof e=="object")t={...e};else return{success:!1,error:"Input must be a string or object"};const a=[],i=[],c=["name","version","displayName"];for(const u of c)if(!t[u])if(n)i.push(`Required field '${u}' is missing`);else switch(a.push(`Missing field '${u}', using default`),u){case"name":t.name="unnamed-definition";break;case"version":t.version="1.0.0";break;case"displayName":t.displayName=t.name||"Unnamed Definition";break}const f=Array.isArray(t.properties)?t.properties:null;f?t.properties=f.map((u,d)=>{const l=te(u)?u:{},p={...l};if(!l.name){const y=`Property at index ${d} missing 'name'`;n?i.push(y):(a.push(`${y}, using 'field_${d}'`),p.name=`field_${d}`)}return l.displayName||(p.displayName=l.name||`Field ${d}`),l.type||(n&&o?i.push(`Property '${l.name||d}' missing 'type'`):(a.push(`Property '${l.name||d}' missing 'type', using 'string'`),p.type="string")),l.defaultValue===void 0&&(p.defaultValue=null),l.required===void 0&&(p.required=!1),p}):n?i.push("Properties must be an array"):(a.push("Properties not found or invalid, using empty array"),t.properties=[]);const m=i.length>0;return{success:!m,data:t,warnings:a.length>0?a:void 0,validationErrors:m?i:void 0}}catch(n){return{success:!1,error:`Definition deserialization failed: ${n instanceof Error?n.message:"Unknown error"}`}}}function Mr(e,r,n){if(e instanceof Date)return e;if(typeof e=="number"){const o=new Date(e);if(n&&isNaN(o.getTime()))throw new Error(`Invalid timestamp: ${e}`);return o}if(typeof e=="string"){const o=new Date(e);if(n&&isNaN(o.getTime()))throw new Error(`Invalid date string: ${e}`);return o}if(n)throw new Error(`Cannot convert ${typeof e} to Date`);return e}function Se(e,r){if(typeof e=="number"&&Number.isInteger(e))return e;if(typeof e=="string"&&e.trim()!==""){const n=parseInt(e,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")return e;if(typeof e=="string"&&e.trim()!==""){const n=parseFloat(e);if(r&&isNaN(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 Or(e,r){if(typeof e=="boolean")return e;if(typeof e=="string"){const n=e.toLowerCase();if(n==="true"||n==="1")return!0;if(n==="false"||n==="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 qe(e,r,n){if(!Array.isArray(e)){if(typeof e=="string")return e.split(",").map(t=>t.trim()).filter(Boolean).map(t=>r==="integer"?Se(t,n):Ce(t,n));if(n)throw new Error(`Expected array, got ${typeof e}`);return e}return e.map((o,t)=>{try{return r==="integer"?Se(o,n):Ce(o,n)}catch(a){if(n)throw new Error(`Array element ${t}: ${a}`);return o}})}const $r=(e,r)=>{const n=new Map;let o=null,t=null,a=0;for(const i of e){const c=i.group;if(!c){o=null,t=null;continue}if(c===o)r[i.name].group=t??c;else{if(!n.has(c))n.set(c,1),t=null,r[i.name].group=c;else{const f=n.get(c),m=`${c}(${f})`;n.set(c,f+1),t=m,r[i.name].group=m,a++}o=c}}return a},Dr=(e,r={})=>{const{includeEmpty:n=!0}=r,o=[];let t=null,a=[],i=0;for(const f of e){const m=f.group||null;m!==t?((a.length>0||n)&&(a.length===0&&i++,o.push({name:t,fields:a})),t=m,a=[f]):a.push(f)}(a.length>0||n)&&(a.length===0&&i++,o.push({name:t,fields:a}));const c=Math.max(0,...o.map(f=>f.fields.length));return{groups:o,metadata:{totalGroups:o.length,emptyGroups:i,largestGroup:c}}},xe=new Map,de=new Map,re=new Set,Re=new Map,Vr=async e=>{try{let r;switch(e.toLowerCase()){case"fr":r=(await Promise.resolve().then(()=>require("./common-CWRUxfiw.cjs"))).default;break;case"de":r=(await Promise.resolve().then(()=>require("./common-CkXqb3W2.cjs"))).default;break;case"es":r=(await Promise.resolve().then(()=>require("./common-B5h_btbq.cjs"))).default;break;case"zh-cn":r=(await Promise.resolve().then(()=>require("./common-D5Jsx5Eg.cjs"))).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}`}}},zr=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 n=await Vr(r);return n.success&&(xe.set(r,n.translations),Re.set(r,{loadedAt:new Date,size:Object.keys(n.translations).length,source:"common"})),n},Tr=async(e,r)=>{if(!e||!r)return{success:!1,translations:{},error:"Both language and localizeName are required"};const n=`${e.toLowerCase()}/${r}`;if(re.has(n))return{success:!1,translations:{},error:"Previously failed to load",fromCache:!0};if(de.has(n))return{success:!0,translations:de.get(n)||{},fromCache:!0};try{let o=r;!r.includes("/")&&!r.includes(".")&&(o=`/locales/${e}/${r}.json`);const t=await fetch(o);if(!t.ok){const m=`HTTP ${t.status}: ${t.statusText}`;return t.status===404?(de.set(n,{}),Re.set(n,{loadedAt:new Date,size:0,source:"user"}),{success:!0,translations:{},fromCache:!1}):(re.add(n),{success:!1,translations:{},error:m})}const a=t.headers.get("content-type")||"";!a.includes("application/json")&&!a.includes("text/json")&&er()&&console.warn(`Translation file at ${o} has unexpected content-type: ${a}`);const i=await t.text();if(!i){const m="Empty translation file";return re.add(n),{success:!1,translations:{},error:m}}let c;try{c=JSON.parse(i)}catch(m){const u=`Invalid JSON in translation file: ${m instanceof Error?m.message:String(m)}`;return re.add(n),{success:!1,translations:{},error:u}}if(!c||typeof c!="object"){const m="Invalid translation file format";return re.add(n),{success:!1,translations:{},error:m}}const f=Object.fromEntries(Object.entries(c).map(([m,u])=>[m,typeof u=="string"?u:String(u)]));if(!f||typeof f!="object"){const m="Invalid translation file format";return re.add(n),{success:!1,translations:{},error:m}}return de.set(n,f),Re.set(n,{loadedAt:new Date,size:Object.keys(f).length,source:"user"}),{success:!0,translations:f,fromCache:!1}}catch(o){const t=`Failed to load user translations: ${o instanceof Error?o.message:"Unknown error"}`;return re.add(n),{success:!1,translations:{},error:t}}};function er(){try{if(typeof process<"u"&&process?.env?.NODE_ENV==="development")return!0}catch{}return!1}function Lr(e,r){return r.length===0?e:e.replace(/\{\{(\d+)\}\}/g,(n,o)=>{const t=parseInt(o,10)-1,a=r[t];if(a==null)return n;try{return String(a)}catch{return n}})}const Pr=(e,r,n)=>(o,...t)=>{let a=o,i=!1;return!o||typeof o!="string"?String(o||""):(e.toLowerCase()==="en"?(a=o,i=!0):Object.prototype.hasOwnProperty.call(n,o)?(a=n[o],i=!0):Object.prototype.hasOwnProperty.call(r,o)?(a=r[o],i=!0):a=o,a=Lr(a,t),!i&&er()&&console.debug(`Missing translation for "${o}" in language "${e}"`),a)},Fe={length:["m","cm","mm","km","in","ft","yd","mi"],area:["m^2","cm^2","mm^2","in^2","ft^2","yd^2"],volume:["L","m^3","cm^3","mL","in^3","ft^3","yd^3"],weight:["kg","g","mg","t","lb","oz"],time:["min","s","h","ms","d"],temperature:["C","F","K"],angle:["deg","rad","rev"]},Ae={length:{m:"Meter (m)",mm:"Millimeter (mm)",cm:"Centimeter (cm)",km:"Kilometer (km)",in:"Inch (in)",ft:"Foot (ft)",yd:"Yard (yd)",mi:"Mile (mi)"},area:{"m^2":"Square meter (m^2)","mm^2":"Square millimeter (mm^2)","cm^2":"Square centimeter (cm^2)","in^2":"Square inch (in^2)","ft^2":"Square foot (ft^2)","yd^2":"Square yard (yd^2)"},volume:{L:"Liter (L)","cm^3":"Cubic centimeter (cm^3)","m^3":"Cubic meter (m^3)",mL:"Milliliter (mL)","in^3":"Cubic inch (in^3)","ft^3":"Cubic foot (ft^3)","yd^3":"Cubic yard (yd^3)"},weight:{kg:"Kilogram (kg)",g:"Gram (g)",mg:"Milligram (mg)",t:"Tonne (t)",lb:"Pound (lb)",oz:"Ounce (oz)"},time:{s:"Second (s)",min:"Minute (min)",h:"Hour (h)",ms:"Millisecond (ms)",d:"Day (d)",wk:"Week (wk)"},temperature:{C:"Celsius (C)",F:"Fahrenheit (F)",K:"Kelvin (K)"},angle:{deg:"Degree (deg)",rad:"Radian (rad)",rev:"Revolution (rev)"}},Me={length:{mm:1e3,cm:100,m:1,km:.001,in:100/2.54,ft:100/(2.54*12),yd:100/(2.54*36),mi:1/1609.344},area:{"m^2":1,"mm^2":1e6,"cm^2":1e4,"km^2":1/1e6,"in^2":(100/2.54)**2,"ft^2":(100/(2.54*12))**2,"yd^2":(100/(2.54*36))**2},volume:{"cm^3":1e6,"m^3":1,L:1,mL:1e6,"in^3":(100/2.54)**3,"ft^3":(100/(2.54*12))**3,"yd^3":(100/(2.54*36))**3},weight:{mg:1e6,g:1e3,kg:1,t:.001,lb:1/.45359237,oz:1/.028349523125},time:{ms:1e3,s:1,min:1/60,h:1/3600,d:1/86400,wk:1/604800},temperature:{C:1,F:33.8,K:274.15},angle:{deg:1,rad:Math.PI/180,rev:1/360}},Oe={},_r=new Set([...Object.keys(Fe),...Object.keys(Ae),...Object.keys(Me)]);for(const e of _r){const r={},n=Fe[e]??[],o=Ae[e]??{},t=Me[e]??{};for(const a of n){const i=o[a];r[a]={name:typeof i=="string"?i:String(a),shortName:a,factor:Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0}}for(const[a,i]of Object.entries(o))if(!r[a]){const c=typeof i=="string"?i:String(a);r[a]={name:c,shortName:a,factor:Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0}}for(const[a,i]of Object.entries(t))r[a]||(r[a]={name:String(a),shortName:String(a),factor:i});Oe[e]=r}const qr=Object.freeze(Object.defineProperty({__proto__:null,dimensionUnitDisplayMap:Ae,dimensionUnitsMap:Fe,dimensonUnitFactorsMap:Me,unitsByDimension:Oe},Symbol.toStringTag,{value:"Module"})),Br=({field:e,value:r,onChange:n,onError:o})=>{const{definitionName:t,t:a}=D(),i=s.useRef(o);s.useEffect(()=>{i.current=o},[o]),s.useEffect(()=>{const u=H(t,e,r??!1,a);i.current?.(u??null)},[r,e,t,a]);const c=u=>{const d=u.target.checked;n?.(d,null)},f=u=>{(u.key===" "||u.key==="Spacebar"||u.key==="Space"||u.key==="Enter")&&(u.preventDefault(),n?.(!r,null))},m=e.name;return h.jsx(B,{field:e,rightAlign:!1,children:h.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[h.jsx("label",{className:M.label,htmlFor:m,style:{textAlign:"left",justifyContent:"flex-start"},children:a(e.displayName)}),h.jsx("input",{id:m,"data-testid":"boolean-checkbox",type:"checkbox",checked:!!r,onChange:c,onKeyDown:f,"aria-checked":!!r,style:{cursor:"pointer",margin:"8px 0 8px 0",width:"1.2em",height:"1.2em",verticalAlign:"middle",color:"#FFFFFF",accentColor:"#0000FF",opacity:void 0}})]})})},Be=[{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 rr(e){return/^#([0-9A-F]{3}){1,2}$/i.test(e)}function Hr(e){if(!rr(e))return null;const r=tr(e),n=parseInt(r.slice(1),16);return{r:n>>16&255,g:n>>8&255,b:n&255}}function tr(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 Ur=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),[i,c]=s.useState("#000000"),f=s.useRef(null),m=s.useRef(null),u=s.useRef(o);s.useEffect(()=>{u.current=o},[o]),s.useEffect(()=>{const v=r&&rr(r)?r:"#000000",w=tr(v);c(w)},[r]),s.useEffect(()=>{const v=H(a,e,r??"#000000",t);u.current?.(v??null)},[r,e,a,t]);const d=v=>{const w=v.target.value;c(w),n?.(w,null)},l=v=>{const w=v.target.value;c(w),n?.(w,null)},p=Be.find(v=>v.value===i),{r:y,g,b:x}=Hr(i)||{r:0,g:0,b:0};return h.jsx(B,{field:e,error:null,children:h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%"},children:[h.jsxs("select",{ref:f,id:e.name,value:i,onChange:d,style:{minWidth:"120px",flex:1},className:W(M.input,M.inputSelect),children:[Be.map(v=>h.jsx("option",{value:v.value,children:t(v.label)},v.value)),p?null:h.jsxs("option",{value:i,children:["(",y,", ",g,", ",x,")"]},i)]}),h.jsx("label",{style:{width:"2.5em",height:"1.8em",display:"inline-block",border:"1px solid #ccc",borderRadius:"4px",backgroundColor:i,cursor:"pointer",overflow:"hidden",flexShrink:0},children:h.jsx("input",{ref:m,type:"color",value:i,onChange:l,style:{opacity:0,width:"100%",height:"100%",border:"none",padding:0,cursor:"pointer"}})})]})})},ue=e=>{if(!e)return null;const r=new Date(e);return isNaN(r.getTime())?null:r},Wr=e=>{if(!e)return"";if(/^\d{4}-\d{2}-\d{2}$/.test(e))return ue(e)?e:"";const n=ue(e);if(n){const o=n.getFullYear(),t=String(n.getMonth()+1).padStart(2,"0"),a=String(n.getDate()).padStart(2,"0");return`${o}-${t}-${a}`}return""},Yr=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),{name:i,required:c}=e,f=s.useRef(null),m=s.useRef(o);s.useEffect(()=>{m.current=o},[o]);const u=s.useCallback(l=>{if(!l||l.trim()==="")return c?t("Value required"):null;if(l){const y=ue(l);if(!y)return t("Invalid date format");if(e.minDate){const g=ue(e.minDate);if(g&&y.getTime()<g.getTime())return t("Date must be on or after {{1}}",e.minDate)}if(e.maxDate){const g=ue(e.maxDate);if(g&&y.getTime()>g.getTime())return t("Date must be on or before {{1}}",e.maxDate)}}return H(a,e,l,t)??null},[e,a,t,c]),d=l=>{const p=l.target.value,y=u(p);n?.(p,y)};return s.useEffect(()=>{const l=u(r);l!==f.current&&(f.current=l,m.current?.(l??null))},[r,u]),h.jsx(B,{field:e,error:u(r),children:h.jsx("input",{id:i,type:"date",value:Wr(r),onChange:d,className:W(M.input,M.textInput),...e.minDate?{min:e.minDate}:{},...e.maxDate?{max:e.maxDate}:{},"aria-invalid":!!u(r),"aria-describedby":u(r)?`${i}-error`:void 0})})},Jr=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),i=s.useRef(null),c=s.useRef(o);s.useEffect(()=>{c.current=o},[o]);const f=s.useCallback(u=>u===""||u===null||u===void 0?t("Value required"):!e.options||e.options.length===0?null:e.options.some(l=>l.value===u)?H(a,e,u,t)??null:t("Invalid option selected"),[e,t,a]);s.useEffect(()=>{const u=r!=null?String(r):"",d=f(u);if(d&&e.options&&e.options.length>0){const l=String(e.options[0].value);i.current&&(i.current.value=l),n?.(l,null),c.current?.(null)}else i.current&&(i.current.value=u),c.current?.(d??null)},[r,f,n,e.options]);const m=u=>{const d=u.target.value,l=f(d);n?.(d,l)};return h.jsx(B,{field:e,error:f(String(r??"")),children:h.jsx("select",{defaultValue:String(r??""),ref:i,onChange:m,className:W(M.input,M.inputSelect),children:(e.options??[]).map(u=>h.jsx("option",{value:String(u.value),children:t(u.label)},String(u.value)))})})};function Gr(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}const Kr=({field:e,value:r,onChange:n,onError:o})=>{const{definitionName:t,t:a}=D(),i=s.useRef(null),c=s.useCallback(d=>{const l=d.trim();return l===""?e.required?a("Value required"):null:Gr(l)?e.pattern&&!new RegExp(e.pattern).test(l)?a("Email does not match pattern: {{%1}}",{"%1":`${e.pattern}`}):H(t,e,d,a)??null:a("Must be valid email format")},[e,t,a]),f=d=>{const l=d.target.value,p=c(l);n?.(l,p)},m=s.useRef(null),u=s.useRef(o);return s.useEffect(()=>{u.current=o},[o]),s.useEffect(()=>{const d=r??"",l=c(d);i.current&&i.current.value!==String(d)&&(i.current.value=String(d)),l!==m.current&&(m.current=l,u.current?.(l??null))},[r,c]),h.jsx(B,{field:e,error:c(String(r??"")),children:h.jsx("input",{id:e.name,type:"email",defaultValue:String(r??""),ref:i,onChange:f,className:W(M.input,M.textInput)})})},Xr=({field:e})=>{const{darkMode:r}=D(),{color:n=r?"#444444":"#CCCCCC",thickness:o=1,margin:t="8px 0"}=e;return h.jsx("div",{style:{width:"auto",height:"0",borderTop:`${o}px solid ${n}`,margin:t}})},Zr=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),[i,c]=s.useState(!1),f=s.useRef(null),m=s.useRef(o);s.useEffect(()=>{m.current=o},[o]);const u=s.useCallback(w=>e.required&&(!w||Array.isArray(w)&&w.length===0)?t("Value required"):H(a,e,w,t)??null,[e,a,t]),d=s.useMemo(()=>u(r),[r,u]);s.useEffect(()=>{const w=u(r);n?.(r,w),m.current?.(w??null)},[r,u]);const l=w=>{const I=w.target.files;let E=null;if(I&&I.length>0){const R=Array.from(I);e.multiple?E=[...Array.isArray(r)?r:[],...R]:E=R[0]}const S=u(E);n?.(E,S)},p=w=>{w.preventDefault(),w.stopPropagation(),c(!1);const I=w.dataTransfer.files;if(I&&I.length>0){const E=Array.from(I);let S=null;e.multiple?S=[...Array.isArray(r)?r:[],...E]:S=E[0];const R=u(S);n?.(S,R)}},y=w=>{w.preventDefault(),w.stopPropagation(),c(!0)},g=w=>{w.preventDefault(),w.stopPropagation(),c(!1)},x=w=>{if(Array.isArray(r)&&typeof w=="number"){const I=r.filter((R,k)=>k!==w),E=I.length>0?I:null,S=u(E);n?.(E,S)}else{const I=u(null);n?.(null,I)}},v=()=>{const w=Array.isArray(r)?r:r?[r]:[];return w.length===0?null:h.jsx("div",{style:{marginTop:"8px",display:"flex",flexDirection:"column",gap:"6px"},children:w.map((I,E)=>h.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:[h.jsx("div",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:I.name}),h.jsx("button",{type:"button",onClick:()=>x(Array.isArray(r)?E:void 0),"aria-label":t("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:S=>{S.currentTarget.style.backgroundColor="var(--reactaform-bg-hover, #fee)"},onMouseLeave:S=>{S.currentTarget.style.backgroundColor="transparent"},children:"×"})]},`${I.name}-${E}`))})};return h.jsx(B,{field:e,error:d,children:h.jsxs("div",{style:{width:"100%"},children:[h.jsxs("div",{onDrop:p,onDragOver:y,onDragLeave:g,style:{position:"relative",border:`1px dashed ${i?"var(--reactaform-color-primary, #2563eb)":d?"var(--reactaform-color-error, #ef4444)":"var(--reactaform-border-color, #d1d5db)"}`,borderRadius:"var(--reactaform-border-radius, 4px)",padding:"8px 12px",textAlign:"center",backgroundColor:i?"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:()=>f.current?.click(),children:[h.jsx("input",{id:e.name,ref:f,type:"file",accept:e.accept,multiple:e.multiple,style:{display:"none"},onChange:l}),h.jsx("div",{style:{fontSize:"1.25rem",opacity:.6,lineHeight:1,flexShrink:0},children:"📁"}),h.jsx("div",{style:{fontSize:"0.875rem",fontWeight:400,color:"var(--reactaform-text-color, #111827)",flex:1,textAlign:"left"},children:i?t("Drop files here"):e.multiple?t("Choose Files or Drag & Drop"):t("Choose File or Drag & Drop")}),e.accept&&h.jsx("div",{style:{fontSize:"0.75rem",color:"var(--reactaform-text-muted, #6b7280)",whiteSpace:"nowrap",opacity:i?0:1,transition:"opacity 0.15s ease",pointerEvents:i?"none":"auto"},children:e.accept})]}),v()]})})},Qr=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;function et(e){return e.split(",").map(r=>r.trim()).every(r=>Qr.test(r))}const rt=e=>!e||e.trim()===""?[]:e.split(",").map(r=>r.trim()).filter(Boolean).map(Number),tt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),[i,c]=s.useState(Array.isArray(r)?r.join(", "):String(r??"")),f=s.useCallback(l=>{if(l.trim()==="")return e.required?t("Value required"):null;if(!et(l))return t("Each value must be a valid float");const p=rt(l);if(e.minCount!==void 0&&p.length<e.minCount)return t("Minimum number of values: {{1}}",e.minCount);if(e.maxCount!==void 0&&p.length>e.maxCount)return t("Maximum number of values: {{1}}",e.maxCount);for(const g of p){if(e.min!==void 0&&(e.minInclusive?g<e.min:g<=e.min))return t("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?g>e.max:g>=e.max))return t("Each value must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max)}return H(a,e,p,t)??null},[a,e,t]),m=l=>{const p=l.target.value,y=f(p);c(p),n?.(p,y)},u=s.useRef(null),d=s.useRef(o);return s.useEffect(()=>{d.current=o},[o]),s.useEffect(()=>{const l=Array.isArray(r)?r.join(", "):String(r??""),p=f(l);p!==u.current&&(u.current=p,d.current?.(p??null))},[r,e.required,f,t]),h.jsx(B,{field:e,error:f(i),children:h.jsx("input",{type:"text",value:i,onChange:m,className:W(M.input,M.textInput),style:{flex:1}})})},nt=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/,ot=e=>{const r=Number.parseFloat(e);return Number.isNaN(r)?null:r},at=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),i=s.useRef(null),c=s.useCallback(d=>{if(d.trim()==="")return e.required?t("Value required"):null;if(!nt.test(d))return t("Must be a valid float");const l=ot(d);return l===null?t("Must be a valid float"):e.min!==void 0&&(e.minInclusive?l<e.min:l<=e.min)?t("Must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min):e.max!==void 0&&(e.maxInclusive?l>e.max:l>=e.max)?t("Must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max):H(a,e,l,t)??null},[e,a,t]),f=s.useRef(null),m=s.useRef(o);s.useEffect(()=>{m.current=o},[o]),s.useEffect(()=>{const d=String(r??""),l=c(d);l!==f.current&&(f.current=l,m.current?.(l??null)),i.current&&document.activeElement!==i.current&&(i.current.value=d)},[r,e,c,t]);const u=d=>{const l=d.target.value,p=c(l);n?.(l,p)};return h.jsx(B,{field:e,error:c(String(r??"")),children:h.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:i,onChange:u,className:W(M.input,M.inputNumber)})})};function st(){try{return"/"}catch{}try{if(typeof process<"u"&&process?.env?.PUBLIC_URL)return process.env.PUBLIC_URL}catch{}return"/"}const it=({field:e,value:r})=>{const{language:n,t:o}=D(),t=e.alignment||"center",a={left:"flex-start",center:"center",right:"flex-end"},i=typeof r=="string"?r:"";let c=i&&i.trim()!==""?i:typeof e.defaultValue=="string"?e.defaultValue:"";c&&!c.startsWith("/")&&(c=`${st()}${c}`);const f=e.localized?.split(";").map(x=>x.trim()),[m,u]=s.useState(c||""),d=s.useRef(c||null);if(s.useEffect(()=>{if(!c)return;const x=c.split("/"),v=x.pop(),w=v.lastIndexOf(".");if(w===-1)return;const I=v.substring(0,w),E=v.substring(w);let S=null;f?.includes(n)&&(S=`${I}_${n}${E}`);const R=new AbortController;if(S){const k=[...x,S].join("/");fetch(k,{method:"HEAD",signal:R.signal}).then(C=>{const N=C.ok?k:c;N!==d.current&&(d.current=N,u(N))}).catch(()=>{c!==d.current&&(d.current=c,u(c))})}else{const k=c;k!==d.current&&(d.current=k,requestAnimationFrame(()=>u(k)))}return()=>{R.abort()}},[c,n,f]),!m)return null;const{width:l,height:p}=e,y={},g={borderRadius:"8px",objectFit:"contain",boxShadow:"0 2px 6px rgba(0,0,0,0.1)",margin:"0 0 8px 0"};return l&&p?(y.width=l,y.height=p,g.width=`${l}px`,g.height=`${p}px`):l&&!p?(y.width=l,g.width=`${l}px`,g.height="auto"):!l&&p&&(y.height=p,g.width="auto",g.height=`${p}px`),h.jsx(B,{field:e,children:h.jsx("div",{"data-testid":"image-wrapper",style:{display:"flex",justifyContent:a[t]||"center",margin:"0 0"},children:h.jsx("img",{src:m,alt:o?.(e.displayName||"Image")||e.displayName||"Image",...y,style:g})})})};function ct(e){const r=/^-?\d+$/;return e.split(",").map(n=>n.trim()).every(n=>r.test(n))}const lt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),i=",",[c,f]=s.useState(Array.isArray(r)?r.join(i+" "):String(r??"")),m=y=>!y||y.trim()===""?[]:y.split(i).map(g=>g.trim()).filter(Boolean).map(g=>Number(g)),u=s.useCallback(y=>{if(y.trim()==="")return e.required?t("Value required"):null;if(!ct(y))return t("Each value must be a valid integer");const g=m(y);if(e.minCount!==void 0&&g.length<e.minCount)return t("Minimum number of values: {{1}}",`${e.minCount}`);if(e.maxCount!==void 0&&g.length>e.maxCount)return t("Maximum number of values: {{1}}",`${e.maxCount}`);for(const v of g){if(e.min!==void 0&&(e.minInclusive?v<e.min:v<=e.min))return t("Each value must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?v>e.max:v>=e.max))return t("Each value must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max)}return H(a,e,g,t)??null},[a,e,t]),d=y=>{const g=y.target.value,x=u(g);f(g),n?.(g,x)},l=s.useRef(null),p=s.useRef(o);return s.useEffect(()=>{p.current=o},[o]),s.useEffect(()=>{const y=Array.isArray(r)?r.join(i+" "):String(r??""),g=u(y);g!==l.current&&(l.current=g,p.current?.(g??null))},[r,e.required,u,t]),h.jsx(B,{field:e,error:u(c),children:h.jsx("input",{type:"text",value:c,onChange:d,className:W(M.input,M.textInput),style:{flex:1}})})};function ut(e){return/^[-+]?\d*$/.test(e)}const ft=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),i=s.useRef(null),c=s.useCallback(l=>{const p=parseInt(l,10);return Number.isNaN(p)?null:p},[]),f=s.useCallback(l=>{if(l.trim()==="")return e.required?t("Value required"):null;if(!ut(l))return t("Must be a valid integer");const p=c(l);if(p===null)return t("Must be a valid integer");if(e.min!==void 0&&(e.minInclusive?p<e.min:p<=e.min))return t("Must be {{1}} {{2}}",e.minInclusive?"≥":">",e.min);if(e.max!==void 0&&(e.maxInclusive?p>e.max:p>=e.max))return t("Must be {{1}} {{2}}",e.maxInclusive?"≤":"<",e.max);if(e.step!==void 0){const g=Number(e.step);if(!Number.isInteger(g))return t("Invalid step value");if(p%g!==0)return t("Must be a multiple of {{1}}",g)}return H(a,e,p,t)??null},[e,a,t,c]),m=s.useRef(null),u=s.useRef(o);s.useEffect(()=>{u.current=o},[o]),s.useEffect(()=>{const l=String(r??""),p=f(l);p!==m.current&&(m.current=p,u.current?.(p??null)),i.current&&document.activeElement!==i.current&&(i.current.value=l)},[r,e,f,t]);const d=l=>{const p=l.target.value,y=f(p);n?.(p,y)};return h.jsx(B,{field:e,error:f(String(r??"")),children:h.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:i,onChange:d,className:W(M.input,M.inputNumber)})})},mt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),i=e.minHeight??"80px",c=s.useRef(null),f=s.useRef(null),m=s.useRef(o);s.useEffect(()=>{m.current=o},[o]);const u=s.useCallback(p=>p.trim()===""?e.required?t("Value required"):null:e.minLength!==void 0&&p.length<e.minLength?t("Must be at least {{1}} characters",e.minLength):e.maxLength!==void 0&&p.length>e.maxLength?t("Must be at most {{1}} characters",e.maxLength):H(a,e,p,t),[e,a,t]),d=p=>{const y=p.target.value,g=u(y);n?.(y,g)};s.useEffect(()=>{const p=u(r);p!==f.current&&(f.current=p,m.current?.(p??null)),c.current&&c.current.value!==String(r??"")&&(c.current.value=String(r??""))},[r,u]);const l={defaultValue:String(r??""),ref:c,onChange:d,style:{resize:"vertical",minHeight:i,width:"100%",boxSizing:"border-box"},className:W(M.input,M.textInput)};return h.jsx(B,{field:e,error:u(r),children:h.jsx("textarea",{...l})})},dt=({field:e,value:r,onChange:n,onError:o})=>{const t=s.useRef(o);s.useEffect(()=>{t.current=o},[o]);const{t:a,darkMode:i,formStyle:c,fieldStyle:f,definitionName:m}=D(),u=(C,N,F)=>{if(!N)return{};const V=C?.[N];return(F&&V?V[F]:void 0)??{}},d=s.useRef(null),[l,p]=s.useState(!1),[y,g]=s.useState(null),x=s.useMemo(()=>e.options.map(C=>({value:C.value,label:a(C.label)})),[e.options,a]),v=s.useMemo(()=>{const C=Array.isArray(r)?r:[],N=new Set(x.map(F=>F.value));return C.filter(F=>N.has(F))},[r,x]),w=C=>{const N=Array.isArray(C)?C:[];return e.required&&N.length===0?a("Value required"):H(m,e,N,a)??null},I=()=>{if(!d.current)return;const C=d.current.getBoundingClientRect();g({x:C.left,y:C.bottom}),p(N=>!N)},E=C=>{const N=v.includes(C)?v.filter($=>$!==C):[...v,C],F=w(N);t.current?.(F??null),n?.(N,F)},S=s.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)",...u(c,"multiSelect","control"),...u(f,void 0,"control")}),[c,f]),R=s.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,...u(c,"multiSelect","clearButton"),...u(f,void 0,"clearButton")}),[c,f]),k=s.useMemo(()=>({position:"absolute",right:"0.7em",top:"50%",transform:"translateY(-50%)",pointerEvents:"none",fontSize:"0.8em",color:"var(--reactaform-text-muted, #999)",...u(c,"multiSelect","arrow"),...u(f,void 0,"arrow")}),[c,f]);return h.jsxs("div",{children:[h.jsx(B,{field:e,error:null,children:h.jsx("div",{style:{width:"100%"},children:h.jsxs("div",{ref:d,className:"reactaform-multiselection-control",style:S,onClick:I,tabIndex:0,role:"button","aria-haspopup":"listbox","aria-expanded":l,onKeyDown:C=>{(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),I())},children:[h.jsxs("span",{style:{flex:1,color:"var(--reactaform-text-muted, #888)"},children:[v.length," / ",x.length," selected"]}),v.length>0&&h.jsx("button",{type:"button","aria-label":"Clear selections",onClick:C=>{C.stopPropagation(),n?.([],null)},style:R,children:h.jsx("span",{style:R,"aria-hidden":!0,children:"✖"})}),h.jsx("span",{style:k,"aria-hidden":!0,children:"▼"})]})})}),l&&y&&h.jsx(pt,{position:y,options:x,selectedValues:v,onToggleOption:E,onClose:()=>p(!1),controlRef:d,darkMode:i})]})},pt=({position:e,options:r,selectedValues:n,onToggleOption:o,onClose:t,controlRef:a,darkMode:i})=>{const c=s.useRef(null),[f,m]=s.useState(-1),{formStyle:u,fieldStyle:d}=D(),l=(R,k,C)=>{if(!k)return{};const F=R?.[k];return(C&&F?F[C]:void 0)??{}},p=s.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)",...l(u,"multiSelect","popup"),...l(d,void 0,"popup")}),[u,d]),y=s.useMemo(()=>({padding:"6px 8px",cursor:"pointer",display:"flex",alignItems:"center",background:"transparent",color:"var(--reactaform-text-color, #000)",...l(u,"multiSelect","option"),...l(d,void 0,"option")}),[u,d]);s.useEffect(()=>{const R=k=>{const C=k.target;!c.current?.contains(C)&&!a.current?.contains(C)&&t()};return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[t,a]),s.useEffect(()=>{c.current&&r.length>0&&requestAnimationFrame(()=>m(R=>R===-1?0:R))},[r.length]),s.useEffect(()=>{if(!c.current||f<0)return;const R=c.current.querySelector(`#multi-opt-${f}`);R&&requestAnimationFrame(()=>R.focus())},[f]);const g=250,x=200,[v,w]=s.useState(null),[I,E]=s.useState(null);if(s.useEffect(()=>{if(typeof window>"u")return;const R=()=>{let N=e.x,F=e.y,$=g;const V=a?.current;if(V){const U=V.getBoundingClientRect();N=U.left,F=U.bottom,$=Math.max(80,Math.round(U.width))}N=Math.min(N,window.innerWidth-$),F=Math.min(F,window.innerHeight-x),w({left:N,top:F}),E($)};R(),window.addEventListener("scroll",R,!0),window.addEventListener("resize",R);let k=null;const C=a?.current;return typeof ResizeObserver<"u"&&C&&(k=new ResizeObserver(()=>R()),k.observe(C)),()=>{window.removeEventListener("scroll",R,!0),window.removeEventListener("resize",R),k&&C&&k.unobserve(C)}},[a,e.x,e.y]),typeof window>"u")return null;let S=document.getElementById("popup-root");return S||(S=document.createElement("div"),S.id="popup-root",document.body.appendChild(S)),je.createPortal(h.jsx("div",{ref:c,role:"listbox","aria-activedescendant":f>=0?`multi-opt-${f}`:void 0,style:{position:"absolute",top:v?v.top:e.y,left:v?v.left:e.x,width:I??g,...p},"data-reactaform-theme":i?"dark":"light",children:r.map((R,k)=>{const C=n.includes(R.value),N=i?"var(--reactaform-hover-bg, rgba(255,255,255,0.01))":"var(--reactaform-hover-bg, #eee)",F={...y,background:k===f?N:y.background};return h.jsxs("div",{id:`multi-opt-${k}`,onMouseDown:$=>{$.stopPropagation(),o(R.value)},onKeyDown:$=>{const V=r.length;switch($.key){case"ArrowDown":$.preventDefault(),m(U=>(U+1)%V);break;case"ArrowUp":$.preventDefault(),m(U=>(U-1+V)%V);break;case"Home":$.preventDefault(),m(0);break;case"End":$.preventDefault(),m(V-1);break;case"Enter":case" ":$.preventDefault(),$.stopPropagation(),o(R.value);break;case"Escape":$.preventDefault(),t(),a?.current?.focus();break}},tabIndex:k===f?0:-1,role:"option","aria-selected":C,style:F,onMouseEnter:$=>{$.currentTarget.style.background=N,m(k)},onMouseLeave:$=>{$.currentTarget.style.background="transparent",m(V=>V===k?-1:V)},children:[h.jsx("input",{type:"checkbox",checked:C,readOnly:!0,style:{marginRight:8,width:"1.125em",height:"1.125em",verticalAlign:"middle",accentColor:i?"#10b981":"#22c55e",cursor:"pointer"}}),R.label]},R.value)})}),S)},gt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),i=s.useRef(null),c=e.min??void 0,f=e.max??void 0,m=Math.max(1,Math.round(e.step??1)),u=s.useCallback(g=>isNaN(g)?t("Must be a valid integer"):Number.isInteger(g)?c!==void 0&&g<c?t("Must be �?{{1}}",c):f!==void 0&&g>f?t("Must be �?{{1}}",f):H(a,e,g,t)??null:t("Must be an integer"),[a,e,t,c,f]),d=s.useRef(null),l=s.useRef(o);s.useEffect(()=>{l.current=o},[o]),s.useEffect(()=>{if(document.activeElement===i.current)return;const x=String(r),v=u(r);i.current&&(i.current.value=x),v!==d.current&&(d.current=v,l.current?.(v??null))},[r,u]);const p=g=>{if(g.trim()==="")return e.required?t("Value required"):null;const v=Number(g);return u(v)},y=g=>{const x=g.target.value,v=g.target.valueAsNumber,w=p(x);n?.(v,w)};return h.jsx(B,{field:e,error:p(String(r??"")),children:h.jsx("input",{ref:i,id:e.name,type:"number",defaultValue:String(r??""),min:c,max:f,step:m,onChange:y,style:{width:"100%",height:"100%"},className:M.input})})},ht=({field:e,value:r,onChange:n,onError:o})=>{const{t}=D(),a=s.useRef(null),{definitionName:i}=D(),c=s.useCallback(d=>{const l=String(d??"").trim();if(l==="")return e.required?t("Value required"):null;if(e.pattern)try{if(!new RegExp(e.pattern).test(l))return t("Phone number does not match pattern: {{1}}",`${e.pattern}`)}catch{}return H(i,e,l,t)},[i,e,t]),f=s.useRef(null),m=s.useRef(o);s.useEffect(()=>{m.current=o},[o]),s.useEffect(()=>{const d=String(r??""),l=c(d);a.current&&a.current.value!==String(d)&&(a.current.value=String(d)),l!==f.current&&(f.current=l,m.current?.(l??null))},[r,c]);const u=d=>{const l=d.target.value,p=l.trim();let y=null;if(p===""){y=e.required?t("Value required"):null,n?.(l,y);return}!y&&e.pattern&&!new RegExp(e.pattern).test(p)&&(y=t("Phone number does not match pattern: {{1}}",`${e.pattern}`)),n?.(l,y)};return h.jsx(B,{field:e,error:c(String(r??"")),children:h.jsx("input",{type:"tel",defaultValue:String(r??""),ref:a,onChange:u,className:W(M.input,M.textInput)})})},bt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),i=e.layout?.toLowerCase()==="horizontal"?"row":"column",c=s.useRef(null),f=s.useRef(o);s.useEffect(()=>{f.current=o},[o]);const m=s.useCallback(d=>d===""||d===null||d===void 0?t("Value required"):!e.options||e.options.length===0?null:e.options.some(p=>p.value===d)?H(a,e,d,t)??null:t("Invalid option selected"),[e,t,a]);s.useEffect(()=>{const d=r!=null?String(r):"",l=m(d);if(f.current?.(l??null),c.current){const p=Array.from(c.current.querySelectorAll("input[type=radio]"));if(l&&e.options&&e.options.length>0){const y=String(e.options[0].value);p.forEach(g=>g.checked=g.value===y),n?.(y,null)}else p.forEach(y=>y.checked=y.value===d)}},[r,m,n,e.options]);const u=d=>{const l=d.target.value,p=m(l);f.current?.(p??null),n?.(l,p)};return h.jsx(B,{field:e,error:m(String(r??"")),children:h.jsx("div",{style:{display:"flex",flexDirection:i,flexWrap:i==="row"?"wrap":"nowrap",gap:i==="row"?"12px":"4px",alignItems:i==="row"?"center":"flex-start",width:"100%"},ref:c,children:(e.options??[]).map(d=>h.jsxs("label",{style:{display:"flex",gap:"6px",alignItems:"center",whiteSpace:"nowrap"},children:[h.jsx("input",{type:"radio",name:e.name,value:String(d.value),defaultChecked:String(r??"")===String(d.value),onChange:u}),t(d.label)]},String(d.value)))})})},yt={display:"flex",gap:4},xt={cursor:"pointer",fontSize:"1.5rem",lineHeight:1,display:"inline-block",marginRight:"0.25rem",userSelect:"none",transition:"color 0.12s ease"},vt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),[i,c]=s.useState(null),f=e.max||5,m=s.useCallback(y=>e.required&&y===0?t("Value required"):H(a,e,y,t)??null,[e,t,a]),u=s.useRef(null),d=s.useRef(o);s.useEffect(()=>{d.current=o},[o]),s.useEffect(()=>{let y=r||0;r<0&&(y=0),r>f&&(y=f);const g=m(y);g!==u.current&&(u.current=g,d.current?.(g??null))},[r,m,f]);const l=y=>{const g=m(y);n?.(y,g)},p=(()=>{let y=r||0;return y<0&&(y=0),y>f&&(y=f),y})();return h.jsx(B,{field:e,error:m(p),children:h.jsx("div",{style:yt,children:(()=>{const y=e.icon,g=y&&String(y).trim()?String(y):"★";return[...Array(f)].map((x,v)=>{const w=v<p,E=i!==null&&v<=i||w?"gold":"lightgray";return h.jsx("span",{onClick:()=>l(v+1),onMouseEnter:()=>c(v),onMouseLeave:()=>c(null),style:{...xt,color:E},"aria-label":`Rating ${v+1}`,title:t(`${e.displayName} ${v+1}`),children:g},v)})})()})})},wt=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;function St(e){return wt.test(e)}const Ct=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),i=s.useRef(null),c=s.useRef(null),f=s.useCallback(y=>{let g=null;if(y.trim()==="")return t("Value required");if(!St(y))return t("Invalid number");const x=Number(y);return typeof e.min=="number"&&x<e.min?t("Value should be at least {{1}}",e.min):typeof e.max=="number"&&x>e.max?t("Value should be at most {{1}}",e.max):(g||(g=H(a,e,x,t)),g)},[a,e,t]),m=s.useRef(null),u=s.useRef(o);s.useEffect(()=>{u.current=o},[o]),s.useEffect(()=>{const y=String(r),g=f(y);c.current&&document.activeElement!==c.current&&(c.current.value=isNaN(Number(y))?String(e.min??0):String(Number(y))),i.current&&document.activeElement!==i.current&&(i.current.value=y),g!==m.current&&(m.current=g,u.current?.(g??null))},[r,f,e.min]);const d=e.min??0,l=e.max??100,p=y=>{const g=y.target.value,x=f(g);n?.(g,x)};return h.jsx(B,{field:e,error:f(String(r??"")),children:h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",width:"100%"},children:[h.jsx("input",{ref:c,type:"range",defaultValue:isNaN(Number(r))?String(d):String(Number(r)),onChange:p,min:d,max:l,style:{padding:"0px, 0px",flex:1},className:M.rangeInput}),h.jsx("input",{ref:i,type:"text",defaultValue:String(r??""),onChange:p,required:!0,style:{width:"40px",minWidth:"40px",height:"2.3em",textAlign:"center",flexShrink:0},className:W(M.input,M.textInput)})]})})},Rt=({field:e,value:r,onChange:n,onError:o})=>{const{t,formStyle:a,fieldStyle:i,definitionName:c}=D(),f=a,m=i,u=(S,R,k)=>{if(!R)return{};const C=S?.[R];return(k&&C?C[k]:void 0)??{}},d=s.useMemo(()=>({display:"inline-block",position:"relative",width:44,height:24,...u(f,"switch","label"),...u(m,void 0,"label")}),[f,m]),l=s.useMemo(()=>({position:"absolute",opacity:0,top:0,left:0,width:"100%",height:"100%",margin:0,cursor:"pointer",pointerEvents:"none",...u(f,"switch","hiddenInput"),...u(m,void 0,"hiddenInput")}),[f,m]),p=s.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",...u(f,"switch","slider"),...u(m,void 0,"slider")}),[f,m]),y=s.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)",...u(f,"switch","knob"),...u(m,void 0,"knob")}),[f,m]),g=!!r,x=s.useRef(null),v=s.useRef(o),w=s.useCallback(S=>S?H(c,e,S,t)??null:e.required?t("Value required"):null,[e,t,c]),I=()=>{const S=!g,R=w(S);n?.(S,R)};s.useEffect(()=>{v.current=o},[o]),s.useEffect(()=>{const S=w(g);S!==x.current&&(x.current=S,v.current?.(S??null))},[g,e,w]);const E=e.name;return h.jsx(B,{field:e,error:w(g),rightAlign:!1,children:h.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%"},children:[h.jsx("label",{className:M.label,htmlFor:E,style:{textAlign:"left",justifyContent:"flex-start"},children:t(e.displayName)}),h.jsxs("label",{style:d,children:[h.jsx("input",{id:e.name,type:"checkbox",checked:g,readOnly:!0,"aria-label":t(e.displayName),style:l,tabIndex:-1}),h.jsx("span",{role:"switch","data-testid":"switch",tabIndex:0,"aria-checked":g,onClick:I,onKeyDown:S=>{(S.key===" "||S.key==="Spacebar"||S.key==="Space"||S.key==="Enter")&&(S.preventDefault(),I())},className:`reactaform-switch ${g?"active checked on":""} `,style:g?{...p,backgroundColor:"var(--reactaform-switch-on-bg, #22c55e)",borderColor:"var(--reactaform-switch-on-border, #16a34a)"}:p,children:h.jsx("span",{style:{...y,transform:g?"translateX(20px)":void 0}})})]})]})})},He=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),i=s.useRef(null),c=s.useRef(null),f=s.useRef(o);s.useEffect(()=>{f.current=o},[o]);const m=s.useMemo(()=>e.pattern?new RegExp(e.pattern):null,[e.pattern]),u=s.useCallback(l=>l.trim()===""?e.required?t("Value required"):null:e.minLength!==void 0&&l.length<e.minLength?t("Must be at least {{1}} characters",e.minLength):e.maxLength!==void 0&&l.length>e.maxLength?t("Must be at most {{1}} characters",e.maxLength):m&&!m.test(l)?t("Input does not match pattern: {{1}}",e.pattern):H(a,e,l,t),[e,a,t,m]),d=l=>{const p=l.target.value,y=u(p);n?.(p,y)};return s.useEffect(()=>{const l=u(r);i.current&&i.current.value!==String(r??"")&&(i.current.value=String(r??"")),l!==c.current&&(c.current=l,f.current?.(l??null))},[r,u]),h.jsx(B,{field:e,error:u(String(r??"")),children:h.jsx("input",{id:e.name,type:"text",defaultValue:String(r??""),ref:i,onChange:d,className:W(M.input,M.textInput)})})},Et=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),i=s.useRef(null),c=s.useRef(o),f=e.includeSeconds??!0;s.useEffect(()=>{c.current=o},[o]);const m=s.useCallback(d=>{if(!d||d.trim()==="")return e.required||e.min||e.max?t("Value required"):null;const l=g=>{const x=g.split(":").map(w=>parseInt(w,10));if(x.some(w=>Number.isNaN(w)))return NaN;let v=0;if(x.length===3)v=x[0]*3600+x[1]*60+x[2];else if(x.length===2)v=x[0]*3600+x[1]*60;else if(x.length===1)v=x[0]*3600;else return NaN;return v},p=l(d);if(Number.isNaN(p))return t("Invalid time format");if(e.min&&typeof e.min=="string"){const g=l(e.min);if(!Number.isNaN(g)&&p<g)return t("Time must be on or after {{1}}",e.min)}if(e.max&&typeof e.max=="string"){const g=l(e.max);if(!Number.isNaN(g)&&p>g)return t("Time must be on or before {{1}}",e.max)}return H(a,e,d,t)??null},[e,a,t]),u=d=>{const l=d.target.value,p=m(l);n?.(l,p)};return s.useEffect(()=>{const d=m(r);d!==i.current&&(i.current=d,c.current?.(d??null))},[r,m]),h.jsx(B,{field:e,error:m(r),children:h.jsx("input",{id:e.name,type:"time",value:r,step:f?1:60,onChange:u,min:typeof e.min=="string"?e.min:void 0,max:typeof e.max=="string"?e.max:void 0,className:W(M.input,M.textInput)})})};function jt({pos:e,options:r,onClose:n,onClickOption:o}){const t=s.useRef(null),a=s.useRef(!1),i=typeof window<"u"?document.getElementById("popup-root")||document.body:null;if(s.useEffect(()=>{function p(y){a.current||y.target.dataset?.popupMenu==="item"||t.current&&y.target instanceof Node&&!t.current.contains(y.target)&&n()}return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[n]),!i||r===void 0||r.length===0||!e||e.x==null||e.y==null)return null;const c=e.x,f=e.y,m=typeof window<"u"?window.innerWidth:1024,u=Math.max(0,m-160),d=Math.max(0,Math.min(c,u)),l=Math.max(0,f);return je.createPortal(h.jsx("div",{ref:t,onMouseDown:p=>{p.stopPropagation()},style:{position:"fixed",top:l,left:d,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)",pointerEvents:"auto"},children:r.map((p,y)=>h.jsx("div",{"data-popup-menu":"item",onMouseDown:g=>{g.stopPropagation(),a.current=!0},onClick:g=>{g.stopPropagation(),g.preventDefault(),o(p),n(),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:y<r.length-1?"1px solid var(--reactaform-border-light, #eee)":void 0,transition:"background-color 0.15s ease"},onMouseEnter:g=>{g.currentTarget.style.backgroundColor="var(--reactaform-hover-bg, #e0e0e0)"},onMouseLeave:g=>{g.currentTarget.style.backgroundColor="transparent"},children:p.label},p.label??y))}),i)}const fe={};function kt(e,r){if(e in fe)return;const n=Oe[e]??{},o={},t={},a={};for(const[c,f]of Object.entries(n))typeof f.factor=="number"&&(o[c]=f.factor),t[c]=r(c),a[r(c)]=c;const i=Object.keys(n)[0]??"";fe[e]={default:i,factors:o,labels:t,reverseLabels:a}}function Nt(e,r,n){if(e==="C"){if(r==="F")return n*(9/5)+32;if(r==="K")return n+273.15}else if(e==="F"){if(r==="C")return(n-32)*5/9;if(r==="K")return(n-32)*5/9+273.15}else if(e==="K"){if(r==="C")return n-273.15;if(r==="F")return(n-273.15)*9/5+32}return n}function It(e,r,n){if(!Number.isFinite(e))return[];if(n===fe.temperature)return Object.keys(n.labels).map(a=>{const i=Nt(r,a,e);return Number.isFinite(i)?{label:`${i.toFixed(6)} ${a}`,value:i.toString(),unit:a}:{label:`${String(i)} ${a}`,value:String(i),unit:a}});const t=n.factors[r];return t===void 0?[]:Object.entries(n.factors).map(([a,i])=>{const c=e/t*i;return Number.isFinite(c)?{label:`${c.toFixed(6)} ${a}`,value:c.toString(),unit:a}:{label:`${String(c)} ${a}`,value:String(c),unit:a}})}function pe(e,r){return e in r.labels?e:r.reverseLabels&&r.reverseLabels[e]?r.reverseLabels[e]:null}const Ft=/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/,At=({unitFactors:e,field:r,value:n,onChange:o,onError:t})=>{const{t:a,definitionName:i}=D(),c=s.useRef(null),f=s.useRef(null),m=s.useRef(null),[u,d]=s.useState(null),[l,p]=s.useState(null),[y,g]=s.useState(!1),[x,v]=s.useState(null),[w,I]=s.useState([]),E=s.useCallback((z,A)=>{if(!z||z.trim()==="")return r.required?a("Value required"):null;if(!Ft.test(z))return a("Must be a valid number");const b=H(i,r,[z,A],a);return b||null},[i,r,a]),S=e.reverseLabels!==void 0?e.reverseLabels:Object.fromEntries(Object.entries(e.labels).map(([z,A])=>[A,z]));s.useEffect(()=>{const z=String(n[0]);let A=n[1]??e.default;A=pe(A,e)||A;const b=document.activeElement;b===c.current||b===f.current||(c.current&&(c.current.value=z),f.current&&(f.current.value=A),m.current!==null&&(cancelAnimationFrame(m.current),m.current=null),m.current=requestAnimationFrame(()=>{m.current=null,d(null),p(null)}))},[n,e]),s.useEffect(()=>()=>{m.current!==null&&(cancelAnimationFrame(m.current),m.current=null)},[]);const R=s.useRef(null),k=s.useRef(t);s.useEffect(()=>{k.current=t},[t]),s.useEffect(()=>{const z=String(n[0]);let A=n[1]??e.default;A=pe(A,e)||A;const b=E(z,A);b!==R.current&&(R.current=b,k.current?.(b??null))},[n,e,E]);const C=(z,A,b)=>{const j=S[A]||A;o?.([z,j],b)},N=z=>{const A=z.target.value,b=f.current?f.current.value:e.default,j=E(A,b);d(A),C(A,b,j)},F=z=>{const A=z.target.value,b=c.current?c.current.value:String(n[0]??""),j=E(b,A);p(A),f.current&&(f.current.value=A),C(b,A,j)},$=z=>{const A=c.current?c.current.value:String(n[0]??""),b=parseFloat(A),j=f.current?f.current.value:e.default;if(E(A,j)||!A.trim()||!Number.isFinite(b))return;const q=z.currentTarget.getBoundingClientRect(),Z=q.left,ee=q.bottom;v({x:Z,y:ee});const T=It(b,j,e);if(T.length===0){I([]),g(!1);return}I(T),g(O=>!O)},V=z=>{const{value:A,unit:b}=z;g(!1),v(null),c.current&&(c.current.value=A),f.current&&(f.current.value=b),d(A),p(b);const j=E(A,b);C(A,b,j)},U=String(n[0]??""),ne=pe(n[1]??e.default,e)||(n[1]??e.default),K=u??U,J=!!E(K,l??ne)||!K.trim(),Q={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:J?"var(--reactaform-button-disabled-bg, #cccccc)":"var(--reactaform-button-bg, var(--reactaform-success-color))",color:"var(--reactaform-button-text, #ffffff)",cursor:J?"var(--reactaform-button-disabled-cursor, not-allowed)":"pointer",opacity:J?+"var(--reactaform-button-disabled-opacity, 0.6)":1,display:"flex",alignItems:"center",justifyContent:"center"};return h.jsx(B,{field:r,error:E(U,ne),children:h.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--reactaform-unit-gap, 8px)",width:"100%"},children:[h.jsx("input",{type:"text",ref:c,defaultValue:String(n[0]??""),onChange:N,style:{width:"var(--reactaform-unit-input-width, 100px)"},className:W(M.input,M.textInput)}),h.jsx("select",{ref:f,defaultValue:pe(n[1]??e.default,e)||(n[1]??e.default),onChange:F,className:W(M.input,M.inputSelect),children:Object.keys(e.labels).map(z=>h.jsx("option",{value:z,children:e.labels[z]??z},z))}),h.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[h.jsx("button",{onClick:$,"aria-disabled":J,disabled:J,style:Q,className:M.button,children:h.jsx("span",{style:{fontSize:"var(--reactaform-unit-btn-icon-size, 1em)",lineHeight:"1",transform:"translateY(-1px)",pointerEvents:"none"},children:"⟷"})}),y&&w&&h.jsx(jt,{pos:x,options:w,onClose:()=>{v(null),g(!1)},onClickOption:V})]})]})})};function Mt({field:e,value:r,onChange:n}){const{t:o}=D(),t=e.dimension;if(!t)return null;fe[t]||kt(t,o);const a=fe[t];return a?h.jsx(At,{unitFactors:a,field:e,value:r,onChange:n}):null}const Ot=/^(https?|ftp|file):\/\/[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$/i,$t=e=>{try{return new URL(e),!0}catch{return!1}},Dt=({field:e,value:r,onChange:n,onError:o})=>{const{t,definitionName:a}=D(),i=s.useRef(null),c=s.useCallback(d=>{const l=d.trim();return l===""?e.required?t("Value required"):null:!Ot.test(l)&&!$t(l)?t("Must be a valid URL"):H(a,e,l,t)??null},[a,e,t]),f=d=>{const l=d.target.value,p=c(l);n?.(l.trim(),p)},m=s.useRef(null),u=s.useRef(o);return s.useEffect(()=>{u.current=o},[o]),s.useEffect(()=>{const d=r??"",l=c(d);i.current&&i.current.value!==String(d)&&(i.current.value=String(d)),l!==m.current&&(m.current=l,u.current?.(l??null))},[r,c]),h.jsx(B,{field:e,error:c(String(r??"")),children:h.jsx("input",{id:e.name,type:"url",defaultValue:String(r??""),ref:i,onChange:f,style:{alignItems:"left"},className:W(M.input,M.textInput),placeholder:"https://example.com"})})},Ee=new ge,Vt=new Set(["checkbox","switch","dropdown","radio","multi-selection","slider","stepper","color","rating"]),nr={checkbox:Br,color:Ur,date:Yr,dropdown:Jr,email:Kr,file:Zr,float:at,"float-array":tt,image:it,int:ft,"int-array":lt,"multi-selection":dt,multiline:mt,phone:ht,radio:bt,rating:vt,separator:Xr,slider:Ct,string:He,stepper:gt,switch:Rt,text:He,time:Et,unit:Mt,url:Dt};function or(e,r,n){if(!n&&e in nr){console.warn(`Can't Overwrite Base Component type "${e}".`);return}if(Vt.has(e)){Ee.register(e,r);return}const o=t=>{const{callback:i,cancel:c}=We((...f)=>{const m=t.onChange;typeof m=="function"&&m(...f)},200);return s.useEffect(()=>()=>{c()},[c]),s.createElement(r,{...t,onChange:i})};Ee.register(e,o)}function zt(e,r){or(e,r,!1)}function ar(e){return Ee.get(e)}let Ue=!1;function sr(){Ue||(Object.entries(nr).forEach(([e,r])=>{or(e,r,!0)}),Ue=!0)}const ir=new ge;function cr(e,r){ir.register(e,r)}function Tt(e){return ir.get(e)}cr("Preset_AlertSubmitHandler",(e,r,n)=>{const o={name:r||"Unnamed Instance",version:e.version,definition:e.name,values:n},t=JSON.stringify(o,null,2);alert(t)});const lr=s.memo(({field:e,value:r,handleChange:n,handleError:o})=>{const t=ar(e.type),a=s.useCallback((c,f)=>n(e.name,c,f),[n,e.name]),i=s.useCallback(c=>o?.(e.name,c),[o,e.name]);return t?h.jsx(t,{field:e,value:r,onChange:a,onError:i}):null},(e,r)=>e.field===r.field&&e.value===r.value&&e.handleChange===r.handleChange&&e.handleError===r.handleError);lr.displayName="FieldWrapper";const ur=(e,r,n,o)=>h.jsx(lr,{field:e,value:r[e.name],handleChange:n,handleError:o},e.name),fr=s.memo(({groupName:e,isOpen:r,fields:n,valuesMap:o,handleChange:t,handleError:a,toggleGroup:i,t:c})=>{const f=s.useCallback(()=>i(e),[i,e]),{formStyle:m,fieldStyle:u}=D(),d=s.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)",...m?.fieldset||{},...u?.fieldset||{}}),[m,u]),l=s.useMemo(()=>({fontWeight:"bold",cursor:"pointer",display:"flex",justifyContent:"space-between",alignItems:"center",padding:"0 var(--reactaform-space, 8px)",color:"var(--reactaform-text-color, inherit)",...m?.legend||{},...u?.legend||{}}),[m,u]);return h.jsxs("fieldset",{style:d,children:[h.jsxs("legend",{onClick:f,style:l,children:[h.jsx("span",{children:c(e)}),h.jsx("span",{children:r?"▼":"▶"})]}),r&&n.map(p=>h.jsx("div",{children:ur(p,o,t,a)},p.name))]})});fr.displayName="FieldGroup";const Lt=(e,r,n,o,t,a,i,c,f)=>{const m=r.slice(0,c).filter(p=>i[p.name]),d=Dr(m).groups,l=[];return d.forEach(p=>{if(p.name){const y=e[p.name]??!0;l.push(h.jsx(fr,{groupName:p.name,isOpen:y,fields:p.fields,valuesMap:n,handleChange:t,handleError:a,toggleGroup:f,t:o},p.name))}else p.fields.forEach(y=>l.push(h.jsx("div",{children:ur(y,n,t,a)},y.name)))}),l},Pt=e=>{const r={};return e.forEach(n=>{r[n.name]=!1}),r},$e=(e,r,n,o)=>{const t=r[e];if(!t?.children)return;const a=n[e],i=a!=null?String(a):"";(t.children[i]||[]).forEach(f=>{o[f]=!0,$e(f,r,n,o)})},mr=(e,r,n)=>{const o=r[e];o?.children&&Object.values(o.children).flat().forEach(t=>{n[t]=!1,mr(t,r,n)})},_t=(e,r,n,o)=>{const t={...n};return e.forEach(a=>{(!a.parents||Object.keys(a.parents).length===0)&&(t[a.name]=!0,$e(a.name,o,r,t))}),t},qt=(e,r,n,o,t)=>{const a={...e};if(mr(o,r,a),t!=null){const i=r[o];if(i?.children){const c=String(t);(i.children[c]||[]).forEach(m=>{a[m]=!0,$e(m,r,n,a)})}}return a};function Bt(e,r,n,o,t){const a=Object.values(t).filter(Boolean);if(a.length>0)return{success:!1,message:o("Please fix validation errors before submitting."),errors:a};const i={...n},c=[];if(e&&Array.isArray(e.properties))for(const m of e.properties){const u=m.name,d=i[u];if(d==null)continue;const l=m.type;try{if((l==="int"||l==="number"||l==="float")&&typeof d=="string"){const p=Number(String(d).trim());isNaN(p)?c.push(o(`Invalid number format for field ${m.displayName||u}`)):i[u]=p}else if((l==="int-array"||l==="float-array")&&typeof d=="string"){const y=String(d).split(",").map(g=>g.trim()).filter(Boolean).map(g=>{const x=Number(g);return isNaN(x)?(c.push(o(`Invalid number "${g}" in array for field ${m.displayName||u}`)),0):x});c.length===0&&(i[u]=y)}}catch(p){c.push(o(`Error processing field ${m.displayName||u}: ${p}`))}}if(c.length>0)return{success:!1,message:o("Data transformation errors occurred."),errors:c};const f=Ze(e,i,o);if(f&&f.length>0)return{success:!1,message:"Validation Fail",errors:f};if(e&&typeof e.submitHandlerName=="string"){const m=Tt(e.submitHandlerName);if(m)try{const u=m(e,r?.name??null,i,o);if(u&&u.length>0)return{success:!1,message:o("Submission failed."),errors:Array.isArray(u)?u:[u]}}catch(u){return{success:!1,message:o("Submission handler error occurred."),errors:[String(u)]}}}return{success:!0,message:o("Form submitted successfully."),data:i}}const dr=({definition:e,instance:r,chunkSize:n=50,chunkDelay:o=50})=>{const{properties:t,displayName:a}=e,i=D(),{t:c,formStyle:f,language:m}=i,u={...i,definitionName:e?.name??i.definitionName},[d,l]=s.useState("en"),[p,y]=s.useState([]),[g,x]=s.useState({}),[v,w]=s.useState({}),[I,E]=s.useState({}),[S,R]=s.useState({}),[k,C]=s.useState({}),[N,F]=s.useState(null),[$,V]=s.useState(null),[U,ne]=s.useState(0),[K,ae]=s.useState(!1),[J,Q]=s.useState(!1),[z,A]=s.useState(r.name||""),b=s.useRef(r),j=s.useRef(!1);s.useEffect(()=>{const O=Object.fromEntries(t.map(_=>[_.name,{..._,children:{}}]));t.forEach(_=>{_.parents&&Object.entries(_.parents).forEach(([se,he])=>{const ie=O[se];ie&&he.forEach(hr=>{ie.children||(ie.children={});const De=String(hr);ie.children[De]=[...ie.children[De]||[],_.name]})})}),$r(t,O);const L=Object.values(O),Y={};L.forEach(_=>{if(_.type==="unit"){const se=typeof _.defaultValue=="number"?String(_.defaultValue):"",he=typeof _.defaultUnit=="string"?_.defaultUnit:String(_.defaultUnit??"m");Y[_.name]=[se,he]}else Y[_.name]=_.defaultValue}),b.current=r,Object.keys(r.values).forEach(_=>{O[_]!==void 0&&(Y[_]=r.values[_])});const G=Pt(L),X={};L.forEach(_=>{_.group&&!(_.group in X)&&(X[_.group]=!0)});const oe=requestAnimationFrame(()=>{y(L),x(O),w(Y),E(_t(L,Y,G,O)),R(X),ae(!0),A(r.name)});return()=>cancelAnimationFrame(oe)},[t,r,e]),s.useEffect(()=>{if(!K||U>=p.length)return;const O=setTimeout(()=>{ne(L=>Math.min(L+n,p.length))},o);return()=>clearTimeout(O)},[K,U,p.length,n,o]);const P=s.useCallback((O,L,Y)=>{F(null),V(null),w(G=>{const X={...G,[O]:L},oe=g[O];return oe&&["checkbox","dropdown","multi-select","radio","switch"].includes(oe.type)&&E(se=>qt(se,g,X,O,String(L))),X}),C(G=>Y?{...G,[O]:Y}:Object.fromEntries(Object.entries(G).filter(([oe])=>oe!==O)))},[g,F,V]);s.useEffect(()=>{let O=0;return O=requestAnimationFrame(()=>{m!==d&&(l(m||"en"),F(null),V(null))}),()=>cancelAnimationFrame(O)},[m,d]),s.useEffect(()=>{let O=0;return O=requestAnimationFrame(()=>{if(j.current){j.current=!1,b.current=r,A(r.name||"");return}b.current=r,F(null),V(null),A(r.name||"")}),()=>cancelAnimationFrame(O)},[r,r.name]);const q=s.useCallback((O,L)=>{C(Y=>L?{...Y,[O]:String(L)}:Object.fromEntries(Object.entries(Y).filter(([X])=>X!==O)))},[]),Z=()=>{j.current=!0;const O=b.current?.name;b.current.name=z;const L=Bt(e,b.current,v,c,k),Y=typeof L.message=="string"?L.message:String(L.message),G=Object.values(L.errors??{}).join(`
|
|
293
|
+
`);F(G?Y+`
|
|
294
|
+
`+G:Y),V(L.success),L.success||(b.current.name=O??b.current.name,A(O??""))},ee=O=>{R(L=>({...L,[O]:!L[O]}))},T=s.useMemo(()=>Object.values(k).some(Boolean),[k]);return h.jsx(ke.Provider,{value:u,children:h.jsxs("div",{style:f.container,children:[a&&h.jsx("h2",{style:f.titleStyle,children:c(a)}),N&&h.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:[h.jsx("div",{style:{whiteSpace:"pre-wrap",flex:1},children:N}),h.jsx("button",{onClick:()=>{F(null),V(null)},"aria-label":c("Dismiss"),style:{marginLeft:12,background:"transparent",border:"none",cursor:"pointer",color:"inherit",fontSize:16,lineHeight:1},children:"×"})]}),r&&h.jsx(Ge,{name:z,onChange:O=>{A(O),F(null),V(null)}}),h.jsxs(h.Fragment,{children:[Lt(S,p,v,c,P,q,I,U,ee),U<p.length&&h.jsx("div",{style:{fontSize:"0.9em",color:"var(--reactaform-text-muted, #666)"}})]}),h.jsx("button",{onClick:Z,disabled:T,onMouseEnter:()=>Q(!0),onMouseLeave:()=>Q(!1),style:{padding:"var(--reactaform-button-padding, var(--reactaform-space) 12px)",backgroundColor:T?"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:T?"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:T?"var(--reactaform-button-disabled-opacity, 0.6)":J?"var(--reactaform-button-hover-opacity, 0.9)":"1"},children:c("Submit")})]})})};sr();const Ht=(e,r=!1)=>({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"}}),Ut=(e,r=!1)=>{const n={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:n,textInput:n,optionInput:n,select:{...n,cursor:"pointer",backgroundRepeat:"no-repeat",backgroundPosition:"right 8px center",backgroundSize:"16px",paddingRight:"32px",backgroundImage:`url("data:image/svg+xml;utf8,<svg
|
|
295
295
|
xmlns='http://www.w3.org/2000/svg'
|
|
296
296
|
viewBox='0 0 24 24'
|
|
297
297
|
fill='none'
|
|
@@ -300,4 +300,4 @@ React keys must be passed directly to JSX without using spread:
|
|
|
300
300
|
stroke-linecap='round'
|
|
301
301
|
stroke-linejoin='round'>
|
|
302
302
|
<polyline points='6,9 12,15 18,9'/>
|
|
303
|
-
</svg>")`},textarea:{...n,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"}}},
|
|
303
|
+
</svg>")`},textarea:{...n,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"}}},pr=({children:e,definitionName:r="",defaultStyle:n,defaultLanguage:o="en",defaultDarkMode:t=!1,defaultLocalizeName:a="",className:i="reactaform-container"})=>{const c=r,f=a,m=t,u=o,d=s.useMemo(()=>n??{},[n]),[l,p]=s.useState({}),[y,g]=s.useState({}),[x,v]=s.useState({}),[w,I]=s.useState({});s.useEffect(()=>{let C=!0;return(async()=>{if(u==="en"){C&&(p({}),g({}));return}try{const F=await zr(u),$=F.success?F.translations:{};C&&p($);const V=await Tr(u,f),U=V.success?V.translations:{};C&&g(U)}catch{C&&(p({}),g({}))}})(),()=>{C=!1}},[u,f]),s.useEffect(()=>{I(Ht(d,m)),v(Ut(d,m))},[d,m]);const E=s.useMemo(()=>Pr(u,l,y),[u,l,y]),S=s.useCallback((C,...N)=>E(C,...N),[E]),R=s.useMemo(()=>({definitionName:c,language:u,darkMode:m,formStyle:w,fieldStyle:x,t:S}),[c,u,m,x,w,S]),k=d?.height?{height:"100%"}:void 0;return h.jsx(ke.Provider,{value:R,children:h.jsx("div",{"data-reactaform-theme":m?"dark":"light",className:i,style:k,children:e})})};function Wt(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.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 n=0;n<r.properties.length;n++){const o=r.properties[n];if(!o||typeof o!="object")return`Property at index ${n} must be an object`;if(!o.name||typeof o.name!="string")return`Property at index ${n} must have a string 'name'`;if(!o.type||typeof o.type!="string")return`Property '${o.name}' must have a string 'type'`}return null}async function Yt(e,r={}){const{validateSchema:n=!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 t;try{t=JSON.parse(o)}catch(a){return{success:!1,error:`Invalid JSON format: ${a instanceof Error?a.message:"Unknown parsing error"}`}}if(n){const a=Wt(t);if(a)return{success:!1,error:`Schema validation failed: ${a}`}}return{success:!0,definition:t}}catch(o){return{success:!1,error:`Unexpected error loading definition: ${o instanceof Error?o.message:"Unknown error"}`}}}function gr(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 n={name:r,definition:e.name??"unknown",version:e.version??"1.0.0",values:{}},o=e.properties||[];return Array.isArray(o)&&o.forEach(t=>{const a=t;a.defaultValue!==void 0&&(n.values[a.name]=a.defaultValue)}),{success:!0,instance:n}}catch(n){return{success:!1,error:`Error creating instance: ${n instanceof Error?n.message:"Unknown error"}`}}}function Jt(e){try{if(!e)return{success:!1,error:"Instance data is required"};let r;if(typeof e=="string")try{r=JSON.parse(e)}catch(n){return{success:!1,error:`Invalid JSON format: ${n instanceof Error?n.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"}`}}}sr();function Gt(e){const[r,n]=s.useState(null);return s.useEffect(()=>{const o=document.querySelector("[data-reactaform-theme]");if(!o)return;const t=o.closest("[data-reactaform-theme]");if(!t)return;const a=()=>n(t.getAttribute("data-reactaform-theme"));a();const i=new MutationObserver(c=>{for(const f of c)f.type==="attributes"&&f.attributeName==="data-reactaform-theme"&&a()});return i.observe(t,{attributes:!0,attributeFilter:["data-reactaform-theme"]}),()=>i.disconnect()},[e]),r}const Kt=({definitionData:e,instance:r,language:n,className:o,darkMode:t,style:a})=>{const i=s.useMemo(()=>{try{return typeof e=="string"?JSON.parse(e):e??null}catch{return null}},[e]),c={fontSize:"inherit",fontFamily:"inherit",...a},f=Gt(),m=t??f==="dark",u=n??"en";if(s.useEffect(()=>{let l=document.getElementById("popup-root");l||(l=document.createElement("div"),l.id="popup-root",document.body.appendChild(l))},[]),!i)return h.jsx("div",{style:{color:"red"},children:"Error: No form definition provided."});let d=r;if(!d){const l=gr(i,i.name);if(!l.success||!l.instance)return h.jsx("div",{style:{color:"red"},children:"Error: Failed to create instance from definition."});d=l.instance}return h.jsx(pr,{definitionName:i.name,defaultStyle:c,defaultLanguage:u,defaultDarkMode:m,defaultLocalizeName:i.localization||"",className:o,children:h.jsx(dr,{definition:i,instance:d})})};function Xt(){if(!(typeof document>"u")&&!document.getElementById("reactaform-styles"))try{const e=document.createElement("style");e.id="reactaform-styles",e.textContent=br,document.head.appendChild(e)}catch{}}Xt();exports.CSS_CLASSES=M;exports.ReactaForm=Kt;exports.ReactaFormProvider=pr;exports.ReactaFormRenderer=dr;exports.StandardFieldLayout=B;exports.Units=qr;exports.combineClasses=W;exports.createInstanceFromDefinition=gr;exports.deserializeDefinition=Ar;exports.deserializeInstance=Nr;exports.getComponent=ar;exports.loadInstance=Jt;exports.loadJsonDefinition=Yt;exports.registerComponent=zt;exports.registerFieldValidationHandler=Cr;exports.registerFormValidationHandler=Sr;exports.registerSubmissionHandler=cr;exports.serializeDefinition=Fr;exports.serializeInstance=jr;exports.useDebouncedCallback=We;exports.useReactaFormContext=D;exports.validateFieldValue=H;exports.validateFormValues=Ze;
|