@forms.expert/sdk 0.4.5 → 0.4.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/dist/react/index.cjs +16 -4
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +16 -4
- package/dist/react/index.js.map +1 -1
- package/dist/vanilla/index.cjs +34 -23
- package/dist/vanilla/index.cjs.map +1 -1
- package/dist/vanilla/index.global.js +34 -23
- package/dist/vanilla/index.global.js.map +1 -1
- package/dist/vanilla/index.js +27 -16
- package/dist/vanilla/index.js.map +1 -1
- package/package.json +1 -1
package/dist/vanilla/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var T=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var W=(t,e)=>{for(var
|
|
1
|
+
"use strict";var T=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var W=(t,e)=>{for(var a in e)T(t,a,{get:e[a],enumerable:!0})},q=(t,e,a,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of H(e))!V.call(t,l)&&l!==a&&T(t,l,{get:()=>e[l],enumerable:!(i=O(e,l))||i.enumerable});return t};var D=t=>q(T({},"__esModule",{value:!0}),t);var oe={};W(oe,{FormWidget:()=>F,autoInit:()=>M,errorsToRecord:()=>P,generateFormStyles:()=>R,renderField:()=>E,renderForm:()=>L,renderSuccess:()=>z});module.exports=D(oe);var A={theme:"light",primaryColor:"#3b82f6",backgroundColor:"#ffffff",textColor:"#1f2937",borderRadius:"md",fontSize:"md",buttonStyle:"filled",labelPosition:"top"};function j(t){switch(t){case"none":return"0";case"sm":return"0.125rem";case"md":return"0.375rem";case"lg":return"0.5rem";default:return"0.375rem"}}function K(t){switch(t){case"none":return"0";case"small":return"0.25rem";case"medium":return"0.375rem";case"large":return"0.75rem";case"full":return"9999px";default:return"0.375rem"}}function _(t){switch(t){case"none":return"0";case"small":return"4px";case"medium":return"8px";case"large":return"12px";case"full":return"9999px";default:return"8px"}}function Y(t){switch(t){case"sm":case"small":return"0.875rem";case"md":case"medium":return"1rem";case"lg":case"large":return"1.125rem";default:return"1rem"}}function X(t){switch(t){case"small":return"0.75rem";case"large":return"1rem";default:return"0.875rem"}}function G(t){switch(t){case"compact":return"0.5rem";case"relaxed":return"1.5rem";case"spacious":return"2rem";default:return"1rem"}}function J(t){switch(t){case"none":return"0";case"compact":return"1rem";case"relaxed":return"2.5rem";case"spacious":return"3.5rem";default:return"1.5rem"}}function Q(t){switch(t){case"compact":return"0.125rem";case"relaxed":return"0.75rem";default:return"0.25rem"}}function Z(t){switch(t){case"narrow":return"28rem";case"wide":return"48rem";case"full":return"100%";default:return"36rem"}}function ee(t){switch(t){case"left":return"flex-start";case"right":return"flex-end";default:return"center"}}function R(t=A){let e={...A,...t},a=j(e.borderRadius),i=K(e.fieldBorderRadius),l=_(e.buttonRadius),m=Y(e.fontSize),c=X(e.placeholderFontSize),o=G(e.fieldSpacing),d=J(e.formPadding),p=Q(e.labelSpacing),n=Z(e.formWidth),r=e.primaryColor,u=e.buttonColor,s=e.fieldBorderColor||(e.theme==="dark"?"#4b5563":"#d1d5db"),g=e.separatorColor||(e.theme==="dark"?"#4b5563":"#d1d5db"),f=e.fontFamily?e.fontFamily.includes(",")?e.fontFamily:`${e.fontFamily}, sans-serif`:"inherit",h=ee(e.buttonAlign),C={small:{px:"0.75rem",py:"0.375rem",fs:"0.875rem"},medium:{px:"1.25rem",py:"0.625rem",fs:"1rem"},large:{px:"1.75rem",py:"0.875rem",fs:"1.125rem"}}[e.buttonSize||"medium"],S=e.buttonPaddingX!=null?`${e.buttonPaddingX}px`:C.px,N=e.buttonPaddingY!=null?`${e.buttonPaddingY}px`:C.py,B=e.buttonFontSize!=null?`${e.buttonFontSize}px`:C.fs,U=e.buttonGradient||(e.buttonStyle==="filled"?r:"transparent");return`
|
|
2
2
|
.forms-expert-wrapper {
|
|
3
3
|
${e.backgroundImageUrl?`background-image: url(${e.backgroundImageUrl}); background-size: cover; background-position: center;`:""}
|
|
4
4
|
${e.backgroundImageUrl?"":`background-color: ${e.backgroundColor};`}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
color: ${e.textColor};
|
|
19
19
|
background-color: ${e.transparentBackground?"transparent":e.backgroundColor};
|
|
20
20
|
padding: ${d};
|
|
21
|
-
border-radius: ${
|
|
21
|
+
border-radius: ${a};
|
|
22
22
|
box-sizing: border-box;
|
|
23
23
|
max-width: ${n};
|
|
24
24
|
width: 100%;
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
width: 100%;
|
|
45
45
|
max-height: 200px;
|
|
46
46
|
object-fit: cover;
|
|
47
|
-
border-radius: ${
|
|
47
|
+
border-radius: ${a} ${a} 0 0;
|
|
48
48
|
margin-bottom: 1rem;
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -74,9 +74,9 @@
|
|
|
74
74
|
.forms-expert-select {
|
|
75
75
|
width: 100%;
|
|
76
76
|
padding: ${e.fieldPaddingX!=null||e.fieldPaddingY!=null?`${e.fieldPaddingY??8}px ${e.fieldPaddingX??12}px`:"0.5rem 0.75rem"};
|
|
77
|
-
border: ${e.fieldBorderStyle==="bottom"?"none":`1px solid ${
|
|
78
|
-
${e.fieldBorderStyle==="bottom"?`border-bottom: 1px solid ${
|
|
79
|
-
border-radius: ${e.fieldBorderStyle==="bottom"?"0":
|
|
77
|
+
border: ${e.fieldBorderStyle==="bottom"?"none":`1px solid ${s}`};
|
|
78
|
+
${e.fieldBorderStyle==="bottom"?`border-bottom: 1px solid ${s};`:""}
|
|
79
|
+
border-radius: ${e.fieldBorderStyle==="bottom"?"0":i};
|
|
80
80
|
font-size: ${m};
|
|
81
81
|
font-family: inherit;
|
|
82
82
|
background-color: ${e.inputBackgroundColor||(e.theme==="dark"?"#374151":"#ffffff")};
|
|
@@ -138,8 +138,8 @@
|
|
|
138
138
|
align-items: center;
|
|
139
139
|
justify-content: center;
|
|
140
140
|
gap: 0.5rem;
|
|
141
|
-
border: 2px dashed ${
|
|
142
|
-
border-radius: ${
|
|
141
|
+
border: 2px dashed ${s};
|
|
142
|
+
border-radius: ${i};
|
|
143
143
|
padding: 1.5rem;
|
|
144
144
|
cursor: pointer;
|
|
145
145
|
transition: border-color 0.15s, background-color 0.15s;
|
|
@@ -153,9 +153,9 @@
|
|
|
153
153
|
.forms-expert-file {
|
|
154
154
|
width: 100%;
|
|
155
155
|
padding: 0.5rem 0.75rem;
|
|
156
|
-
border: ${e.fieldBorderStyle==="bottom"?"none":`1px solid ${
|
|
157
|
-
${e.fieldBorderStyle==="bottom"?`border-bottom: 1px solid ${
|
|
158
|
-
border-radius: ${e.fieldBorderStyle==="bottom"?"0":
|
|
156
|
+
border: ${e.fieldBorderStyle==="bottom"?"none":`1px solid ${s}`};
|
|
157
|
+
${e.fieldBorderStyle==="bottom"?`border-bottom: 1px solid ${s};`:""}
|
|
158
|
+
border-radius: ${e.fieldBorderStyle==="bottom"?"0":i};
|
|
159
159
|
font-size: ${m};
|
|
160
160
|
background-color: ${e.inputBackgroundColor||(e.theme==="dark"?"#374151":"#ffffff")};
|
|
161
161
|
cursor: pointer;
|
|
@@ -185,9 +185,9 @@
|
|
|
185
185
|
${e.buttonFullWidth?"width: 100%;":e.buttonAlign?"":"width: 100%;"}
|
|
186
186
|
padding: ${N} ${S};
|
|
187
187
|
font-weight: 500;
|
|
188
|
-
font-size: ${
|
|
188
|
+
font-size: ${B};
|
|
189
189
|
font-family: inherit;
|
|
190
|
-
border-radius: ${
|
|
190
|
+
border-radius: ${l};
|
|
191
191
|
cursor: pointer;
|
|
192
192
|
transition: opacity 0.2s, transform 0.1s;
|
|
193
193
|
max-width: 100%;
|
|
@@ -285,7 +285,7 @@
|
|
|
285
285
|
font-weight: 500;
|
|
286
286
|
font-size: ${m};
|
|
287
287
|
font-family: inherit;
|
|
288
|
-
border-radius: ${
|
|
288
|
+
border-radius: ${l};
|
|
289
289
|
cursor: pointer;
|
|
290
290
|
transition: opacity 0.2s;
|
|
291
291
|
text-decoration: none;
|
|
@@ -318,7 +318,7 @@
|
|
|
318
318
|
.forms-expert-scale { display: flex; gap: 0.25rem; flex-wrap: wrap; }
|
|
319
319
|
.forms-expert-scale-labels { display: flex; justify-content: space-between; font-size: 0.75rem; color: ${e.theme==="dark"?"#9ca3af":"#6b7280"}; margin-top: 0.25rem; }
|
|
320
320
|
.forms-expert-scale-btn {
|
|
321
|
-
min-width: 2.25rem; height: 2.25rem; border-radius: ${
|
|
321
|
+
min-width: 2.25rem; height: 2.25rem; border-radius: ${a}; cursor: pointer;
|
|
322
322
|
border: 1px solid ${e.theme==="dark"?"#4b5563":"#d1d5db"};
|
|
323
323
|
background: ${e.theme==="dark"?"#374151":"#ffffff"}; color: ${e.textColor};
|
|
324
324
|
font-size: 0.875rem; transition: all 0.15s;
|
|
@@ -329,7 +329,18 @@
|
|
|
329
329
|
|
|
330
330
|
/* Radio & multiselect groups */
|
|
331
331
|
.forms-expert-radio-group,
|
|
332
|
-
.forms-expert-multiselect-group {
|
|
332
|
+
.forms-expert-multiselect-group {
|
|
333
|
+
display: flex;
|
|
334
|
+
flex-direction: column;
|
|
335
|
+
gap: 0.5rem;
|
|
336
|
+
width: 100%;
|
|
337
|
+
padding: ${e.fieldPaddingX!=null||e.fieldPaddingY!=null?`${e.fieldPaddingY??8}px ${e.fieldPaddingX??12}px`:"0.5rem 0.75rem"};
|
|
338
|
+
border: ${e.fieldBorderStyle==="bottom"?"none":`1px solid ${s}`};
|
|
339
|
+
${e.fieldBorderStyle==="bottom"?`border-bottom: 1px solid ${s};`:""}
|
|
340
|
+
border-radius: ${e.fieldBorderStyle==="bottom"?"0":i};
|
|
341
|
+
background-color: ${e.inputBackgroundColor||(e.theme==="dark"?"#374151":"#ffffff")};
|
|
342
|
+
box-sizing: border-box;
|
|
343
|
+
}
|
|
333
344
|
.forms-expert-radio-item,
|
|
334
345
|
.forms-expert-multiselect-item { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
|
|
335
346
|
.forms-expert-radio-item input,
|
|
@@ -342,11 +353,11 @@
|
|
|
342
353
|
/* Image choice */
|
|
343
354
|
.forms-expert-image-choice { display: flex; flex-wrap: wrap; gap: 0.5rem; }
|
|
344
355
|
.forms-expert-image-choice-item {
|
|
345
|
-
border: 2px solid ${e.theme==="dark"?"#4b5563":"#d1d5db"}; border-radius: ${
|
|
356
|
+
border: 2px solid ${e.theme==="dark"?"#4b5563":"#d1d5db"}; border-radius: ${a};
|
|
346
357
|
padding: 0.5rem; cursor: pointer; text-align: center; transition: border-color 0.15s;
|
|
347
358
|
}
|
|
348
359
|
.forms-expert-image-choice-item.active { border-color: ${e.primaryColor}; }
|
|
349
|
-
.forms-expert-image-choice-item img { max-width: 80px; max-height: 80px; object-fit: cover; border-radius: ${
|
|
360
|
+
.forms-expert-image-choice-item img { max-width: 80px; max-height: 80px; object-fit: cover; border-radius: ${a}; }
|
|
350
361
|
|
|
351
362
|
/* Responsive button scaling */
|
|
352
363
|
@media (max-width: 480px) {
|
|
@@ -354,22 +365,22 @@
|
|
|
354
365
|
.forms-expert-secondary-btn {
|
|
355
366
|
padding-left: max(0.5rem, min(${S}, 3vw));
|
|
356
367
|
padding-right: max(0.5rem, min(${S}, 3vw));
|
|
357
|
-
font-size: max(0.75rem, min(${
|
|
368
|
+
font-size: max(0.75rem, min(${B}, 3.5vw));
|
|
358
369
|
}
|
|
359
370
|
}
|
|
360
371
|
|
|
361
372
|
${e.customCss||""}
|
|
362
|
-
`.trim()}function v(t){let e=document.createElement("div");return e.textContent=t,e.innerHTML}function te(t){switch(t){case"small":return"18px";case"large":return"30px";case"extra-large":return"36px";default:return"24px"}}function re(t){switch(t){case"small":return"14px";case"large":return"18px";default:return"16px"}}function b(t,e){return e?`${t} ${e}`:t}function ne(t){switch(t){case"1/4":return"25%";case"1/3":return"33.333%";case"1/2":return"50%";case"2/3":return"66.666%";case"3/4":return"75%";case"full":return"100%";default:return}}function E(t,e,i,s){let a=document.createElement("div");if(t.type==="heading"){a.className="forms-expert-group";let o=document.createElement("h3");if(o.className="forms-expert-heading",o.style.fontSize=te(s?.headingSize),o.textContent=t.label||"",a.appendChild(o),t.content){let d=document.createElement("p");d.className="forms-expert-heading-subtitle",d.textContent=t.content,a.appendChild(d)}return a}if(t.type==="divider"){let o=document.createElement("hr");return o.className="forms-expert-divider",o}if(t.type==="paragraph"){a.className="forms-expert-group";let o=t.paragraphFontSize?`${t.paragraphFontSize}px`:re(s?.paragraphSize);if(t.label){let d=document.createElement("p");d.className="forms-expert-paragraph-label",d.style.fontSize=o,d.textContent=t.label,a.appendChild(d)}if(t.content){let d=document.createElement("div");d.className="forms-expert-paragraph",d.style.fontSize=o,d.innerHTML=t.content,a.appendChild(d)}return a}if(t.type==="hidden"){let o=document.createElement("input");return o.type="hidden",o.name=t.name,o.value=String(t.defaultValue??e??""),a.appendChild(o),a.style.display="none",a}if(t.type==="checkbox"||t.type==="toggle"||t.type==="consent"){a.className="forms-expert-checkbox-group";let o=document.createElement("input");o.type="checkbox",o.id=`mira-field-${t.name}`,o.name=t.name,o.className="forms-expert-checkbox",o.checked=!!e,t.required&&(o.required=!0);let d=document.createElement("div"),p=document.createElement("label");p.htmlFor=o.id,p.style.cursor="pointer",t.type==="consent"&&t.consentFontSize&&(p.style.fontSize=`${t.consentFontSize}px`);let n=t.type==="consent"?t.consentText||t.label||t.name:t.label||t.name;if(p.innerHTML=`${v(n)}${t.required?'<span class="forms-expert-required">*</span>':""}`,d.appendChild(p),t.type==="consent"&&t.consentUrl){let r=document.createElement("a");r.href=t.consentUrl,r.target="_blank",r.rel="noopener noreferrer",r.textContent="View policy",r.className="forms-expert-consent-link",d.appendChild(r)}if(a.appendChild(o),a.appendChild(d),i){let r=document.createElement("div");r.className="forms-expert-error-message",r.textContent=i,a.appendChild(r)}return a}if(a.className="forms-expert-group",t.label){let o=document.createElement("label");o.className=`forms-expert-label${s?.labelClassName?" "+s.labelClassName:""}`,o.htmlFor=`mira-field-${t.name}`,o.innerHTML=`${v(t.label)}${t.required?'<span class="forms-expert-required">*</span>':""}`,a.appendChild(o)}let m=document.createElement("div");m.className="forms-expert-input-wrapper";let c;switch(t.type){case"textarea":case"richText":c=document.createElement("textarea"),c.className=b("forms-expert-textarea",s?.fieldClassName),c.value=String(e||""),t.maxLength&&(c.maxLength=t.maxLength);break;case"select":case"dropdown":{c=document.createElement("select"),c.className=b("forms-expert-select",s?.fieldClassName);let o=document.createElement("option");o.value="",o.textContent=t.placeholder||"Select an option...",c.appendChild(o),(t.options||[]).forEach(p=>{let n=document.createElement("option");n.value=p,n.textContent=p,e===p&&(n.selected=!0),c.appendChild(n)});break}case"radio":{let o=document.createElement("div");if(o.className="forms-expert-radio-group",(t.options||[]).forEach(p=>{let n=document.createElement("label");n.className="forms-expert-radio-item";let r=document.createElement("input");r.type="radio",r.name=t.name,r.value=p,r.checked=e===p,n.appendChild(r),n.appendChild(document.createTextNode(` ${p}`)),o.appendChild(n)}),m.appendChild(o),i){let p=document.createElement("div");p.className="forms-expert-error-message",p.textContent=i,m.appendChild(p)}return a.appendChild(m),a}case"multiselect":{let o=document.createElement("div");o.className="forms-expert-multiselect-group";let d=e||[];if((t.options||[]).forEach(n=>{let r=document.createElement("label");r.className="forms-expert-checkbox-item";let u=document.createElement("input");u.type="checkbox",u.name=t.name,u.value=n,u.checked=d.includes(n),r.appendChild(u),r.appendChild(document.createTextNode(` ${n}`)),o.appendChild(r)}),m.appendChild(o),i){let n=document.createElement("div");n.className="forms-expert-error-message",n.textContent=i,m.appendChild(n)}return a.appendChild(m),a}case"rating":{let o=document.createElement("div");o.className="forms-expert-rating";let d=t.ratingMax||5,p=e||0;for(let n=1;n<=d;n++){let r=document.createElement("button");r.type="button",r.className=`forms-expert-rating-star ${n<=p?"active":""}`,r.textContent="\u2605",r.dataset.value=String(n),o.appendChild(r)}if(m.appendChild(o),i){let n=document.createElement("div");n.className="forms-expert-error-message",n.textContent=i,m.appendChild(n)}return a.appendChild(m),a}case"scale":case"opinionScale":{let o=document.createElement("div");o.className="forms-expert-scale";let d=t.min??(t.type==="opinionScale"?0:1),p=t.max??(t.type==="opinionScale"?10:5),n=e;for(let r=d;r<=p;r++){let u=document.createElement("button");u.type="button",u.className=`forms-expert-scale-btn ${n===r?"active":""}`,u.textContent=String(r),u.dataset.value=String(r),o.appendChild(u)}if(m.appendChild(o),t.lowLabel||t.highLabel){let r=document.createElement("div");r.className="forms-expert-scale-labels",r.innerHTML=`<span>${v(t.lowLabel||"")}</span><span>${v(t.highLabel||"")}</span>`,m.appendChild(r)}if(i){let r=document.createElement("div");r.className="forms-expert-error-message",r.textContent=i,m.appendChild(r)}return a.appendChild(m),a}case"slider":{c=document.createElement("input"),c.type="range",c.className="forms-expert-slider",c.min=String(t.min??0),c.max=String(t.max??100),c.step=String(t.step??1),c.value=String(e??t.min??0);break}case"file":{let o=s?.theme==="dark"?"#4b5563":"#d1d5db",d=s?.theme==="dark"?"#9ca3af":"#6b7280",p=s?.primaryColor||"#3b82f6",n=document.createElement("label");n.htmlFor=`mira-field-${t.name}`,n.className="forms-expert-dropzone";let r=document.createElement("input");r.id=`mira-field-${t.name}`,r.name=t.name,r.type="file",r.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0",t.allowedMimeTypes?.length&&(r.accept=t.allowedMimeTypes.join(",")),t.multiple&&(r.multiple=!0),n.appendChild(r);let u=document.createElement("div");u.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="${d}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" x2="12" y1="3" y2="15"/></svg>`,n.appendChild(u);let l=document.createElement("span");if(l.style.cssText="font-size:0.875rem;font-weight:500",l.textContent="Drag & drop a file here, or click to browse",n.appendChild(l),t.allowedMimeTypes?.length){let g=document.createElement("span");g.style.cssText=`font-size:0.75rem;color:${d}`,g.textContent=t.allowedMimeTypes.join(", "),n.appendChild(g)}if(t.maxFileSize){let g=document.createElement("span");g.style.cssText=`font-size:0.75rem;color:${d}`;let f=t.maxFileSize;g.textContent=`Max size: ${f<1048576?`${(f/1024).toFixed(0)} KB`:`${(f/1048576).toFixed(0)} MB`}`,n.appendChild(g)}if(n.addEventListener("dragover",g=>{g.preventDefault(),n.style.borderColor=p,n.style.backgroundColor=s?.theme==="dark"?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.04)"}),n.addEventListener("dragleave",()=>{n.style.borderColor=o,n.style.backgroundColor="transparent"}),n.addEventListener("drop",g=>{g.preventDefault(),n.style.borderColor=o,n.style.backgroundColor="transparent"}),a.appendChild(n),i){let g=document.createElement("div");g.className="forms-expert-error-message",g.textContent=i,a.appendChild(g)}return a}case"currency":{c=document.createElement("input"),c.type="number",c.className=b("forms-expert-input",s?.fieldClassName),c.value=String(e??""),t.min!==void 0&&(c.min=String(t.min)),t.max!==void 0&&(c.max=String(t.max)),c.step=String(t.step||.01);break}case"phone":c=document.createElement("input"),c.type="tel",c.className=b("forms-expert-input",s?.fieldClassName),c.value=String(e||"");break;case"url":c=document.createElement("input"),c.type="url",c.className=b("forms-expert-input",s?.fieldClassName),c.value=String(e||"");break;case"password":c=document.createElement("input"),c.type="password",c.className=b("forms-expert-input",s?.fieldClassName),c.value=String(e||"");break;case"time":c=document.createElement("input"),c.type="time",c.className=b("forms-expert-input",s?.fieldClassName),c.value=String(e||"");break;case"datetime":c=document.createElement("input"),c.type="datetime-local",c.className=b("forms-expert-input",s?.fieldClassName),c.value=String(e||"");break;case"colorPicker":c=document.createElement("input"),c.type="color",c.className="forms-expert-color",c.value=String(e||"#000000");break;case"dateRange":{let o=document.createElement("div");o.className="forms-expert-date-range";let d=e||{},p=document.createElement("input");p.type="date",p.className=b("forms-expert-input",s?.fieldClassName),p.name=`${t.name}.start`,p.value=d.start||"";let n=document.createElement("input");if(n.type="date",n.className=b("forms-expert-input",s?.fieldClassName),n.name=`${t.name}.end`,n.value=d.end||"",o.appendChild(p),o.appendChild(n),m.appendChild(o),i){let r=document.createElement("div");r.className="forms-expert-error-message",r.textContent=i,m.appendChild(r)}return a.appendChild(m),a}case"address":{let o=document.createElement("div");o.className="forms-expert-address";let d=t.addressFields||["street","city","state","zip","country"],p=e||{},n={street:"Street",street2:"Street Line 2",city:"City",state:"State",zip:"ZIP",country:"Country"};if(d.forEach(r=>{let u=document.createElement("input");u.type="text",u.className=b("forms-expert-input",s?.fieldClassName),u.name=`${t.name}.${r}`,u.placeholder=n[r]||r,u.value=p[r]||"",o.appendChild(u)}),m.appendChild(o),i){let r=document.createElement("div");r.className="forms-expert-error-message",r.textContent=i,m.appendChild(r)}return a.appendChild(m),a}case"name":{let o=document.createElement("div");o.className="forms-expert-name";let d=t.nameFields||["first","last"],p=e||{},n={prefix:"Prefix",first:"First Name",middle:"Middle",last:"Last Name",suffix:"Suffix"};if(d.forEach(r=>{let u=document.createElement("input");u.type="text",u.className=b("forms-expert-input",s?.fieldClassName),u.name=`${t.name}.${r}`,u.placeholder=n[r]||r,u.value=p[r]||"",o.appendChild(u)}),m.appendChild(o),i){let r=document.createElement("div");r.className="forms-expert-error-message",r.textContent=i,m.appendChild(r)}return a.appendChild(m),a}case"imageChoice":{let o=document.createElement("div");o.className="forms-expert-image-choice";let d=t.options||[],p=e;if(d.forEach(n=>{let r=document.createElement("button");if(r.type="button",r.className=`forms-expert-image-choice-item ${p===n.value?"active":""}`,r.dataset.value=n.value,n.imageUrl){let l=document.createElement("img");l.src=n.imageUrl,l.alt=n.label,r.appendChild(l)}let u=document.createElement("span");u.textContent=n.label,r.appendChild(u),o.appendChild(r)}),m.appendChild(o),i){let n=document.createElement("div");n.className="forms-expert-error-message",n.textContent=i,m.appendChild(n)}return a.appendChild(m),a}case"ranking":{let o=document.createElement("div");o.className="forms-expert-ranking";let d=t.options||[];if((e||[...d]).forEach((n,r)=>{let u=document.createElement("div");u.className="forms-expert-ranking-item",u.textContent=`${r+1}. ${n}`,u.dataset.value=n,o.appendChild(u)}),m.appendChild(o),i){let n=document.createElement("div");n.className="forms-expert-error-message",n.textContent=i,m.appendChild(n)}return a.appendChild(m),a}case"location":{let o=document.createElement("div");o.className="forms-expert-location";let d=e||{},p=document.createElement("input");p.type="text",p.className=b("forms-expert-input",s?.fieldClassName),p.name=`${t.name}.address`,p.placeholder="Address",p.value=d.address||"",o.appendChild(p);let n=document.createElement("div");n.className="forms-expert-location-coords";let r=document.createElement("input");r.type="number",r.className=b("forms-expert-input",s?.fieldClassName),r.name=`${t.name}.lat`,r.placeholder="Latitude",r.step="any",r.value=d.lat!==void 0?String(d.lat):"";let u=document.createElement("input");if(u.type="number",u.className=b("forms-expert-input",s?.fieldClassName),u.name=`${t.name}.lng`,u.placeholder="Longitude",u.step="any",u.value=d.lng!==void 0?String(d.lng):"",n.appendChild(r),n.appendChild(u),o.appendChild(n),m.appendChild(o),i){let l=document.createElement("div");l.className="forms-expert-error-message",l.textContent=i,m.appendChild(l)}return a.appendChild(m),a}default:c=document.createElement("input"),c.type=t.type==="email"?"email":t.type==="number"?"number":t.type==="date"?"date":"text",c.className=b("forms-expert-input",s?.fieldClassName),c.value=String(e||""),t.type==="number"&&(t.min!==void 0&&(c.min=String(t.min)),t.max!==void 0&&(c.max=String(t.max)),t.step!==void 0&&(c.step=String(t.step)));break}if(c.id=`mira-field-${t.name}`,c.name=t.name,t.placeholder&&"placeholder"in c&&(c.placeholder=t.placeholder),t.required&&(c.required=!0),i&&c.classList.add("forms-expert-error"),m.appendChild(c),i){let o=document.createElement("div");o.className="forms-expert-error-message",o.textContent=i,m.appendChild(o)}return a.appendChild(m),a}function L(t,e={},i={},s={}){let a=document.createElement("form");if(a.className="forms-expert",s.hideRequiredAsterisk){let l=document.createElement("style");l.textContent=".forms-expert .forms-expert-required { display: none; }",a.appendChild(l)}if(s.showFormName!==!1&&s.formName){let l=document.createElement("h1");l.className="forms-expert-title",l.textContent=s.formName,l.style.fontSize=s.formNameFontSize!=null?`${s.formNameFontSize}px`:"1.5rem";let g={normal:"400",medium:"500",semibold:"600",bold:"700"};l.style.fontWeight=g[s.formNameFontWeight||"bold"]||"700",l.style.marginBottom="0.5rem",a.appendChild(l)}let m=t.styling,c=t.fields,o=0;for(;o<c.length;){let l=c[o];if(l.row!=null){let g=[l],f=o+1;for(;f<c.length&&c[f].row===l.row;)g.push(c[f]),f++;if(g.length>1){let h=document.createElement("div");h.style.display="flex",h.style.gap="0.75rem",h.style.flexWrap="wrap",g.forEach(y=>{let C=document.createElement("div"),S=ne(y.width);S?C.style.flex=`0 0 calc(${S} - 0.75rem)`:C.style.flex="1 1 0",C.style.minWidth="180px";let N=E(y,e[y.name],i[y.name],m);C.appendChild(N),h.appendChild(C)}),a.appendChild(h)}else{let h=E(l,e[l.name],i[l.name],m);a.appendChild(h)}o=f}else{let g=E(l,e[l.name],i[l.name],m);a.appendChild(g),o++}}if(s.honeypot){let l=document.createElement("input");l.type="text",l.name="_hp",l.className="forms-expert-honeypot",l.tabIndex=-1,l.autocomplete="off",a.appendChild(l)}let d=document.createElement("input");d.type="hidden",d.name="pageUrl",d.value=typeof window<"u"?window.location.href:"",a.appendChild(d);let p=document.createElement("div");p.className="forms-expert-button-wrapper";let n=document.createElement("button");if(n.type="submit",n.className=b("forms-expert-button",s.buttonClassName),n.disabled=s.isLoading||!1,s.isLoading)n.innerHTML=`
|
|
373
|
+
`.trim()}function v(t){let e=document.createElement("div");return e.textContent=t,e.innerHTML}function te(t){switch(t){case"small":return"18px";case"large":return"30px";case"extra-large":return"36px";default:return"24px"}}function re(t){switch(t){case"small":return"14px";case"large":return"18px";default:return"16px"}}function b(t,e){return e?`${t} ${e}`:t}function ne(t){switch(t){case"1/4":return"25%";case"1/3":return"33.333%";case"1/2":return"50%";case"2/3":return"66.666%";case"3/4":return"75%";case"full":return"100%";default:return}}function E(t,e,a,i){let l=document.createElement("div");if(t.type==="heading"){l.className="forms-expert-group";let o=document.createElement("h3");if(o.className="forms-expert-heading",o.style.fontSize=te(i?.headingSize),o.textContent=t.label||"",l.appendChild(o),t.content){let d=document.createElement("p");d.className="forms-expert-heading-subtitle",d.textContent=t.content,l.appendChild(d)}return l}if(t.type==="divider"){let o=document.createElement("hr");return o.className="forms-expert-divider",o}if(t.type==="paragraph"){l.className="forms-expert-group";let o=t.paragraphFontSize?`${t.paragraphFontSize}px`:re(i?.paragraphSize);if(t.label){let d=document.createElement("p");d.className="forms-expert-paragraph-label",d.style.fontSize=o,d.textContent=t.label,l.appendChild(d)}if(t.content){let d=document.createElement("div");d.className="forms-expert-paragraph",d.style.fontSize=o,d.innerHTML=t.content,l.appendChild(d)}return l}if(t.type==="hidden"){let o=document.createElement("input");return o.type="hidden",o.name=t.name,o.value=String(t.defaultValue??e??""),l.appendChild(o),l.style.display="none",l}if(t.type==="checkbox"||t.type==="toggle"||t.type==="consent"){l.className="forms-expert-checkbox-group";let o=document.createElement("input");o.type="checkbox",o.id=`mira-field-${t.name}`,o.name=t.name,o.className="forms-expert-checkbox",o.checked=!!e,t.required&&(o.required=!0);let d=document.createElement("div"),p=document.createElement("label");p.htmlFor=o.id,p.style.cursor="pointer",t.type==="consent"&&t.consentFontSize&&(p.style.fontSize=`${t.consentFontSize}px`);let n=t.type==="consent"?t.consentText||t.label||t.name:t.label||t.name;if(p.innerHTML=`${v(n)}${t.required?'<span class="forms-expert-required">*</span>':""}`,d.appendChild(p),t.type==="consent"&&t.consentUrl){let r=document.createElement("a");r.href=t.consentUrl,r.target="_blank",r.rel="noopener noreferrer",r.textContent="View policy",r.className="forms-expert-consent-link",d.appendChild(r)}if(l.appendChild(o),l.appendChild(d),a){let r=document.createElement("div");r.className="forms-expert-error-message",r.textContent=a,l.appendChild(r)}return l}if(l.className="forms-expert-group",t.label){let o=document.createElement("label");o.className=`forms-expert-label${i?.labelClassName?" "+i.labelClassName:""}`,o.htmlFor=`mira-field-${t.name}`,o.innerHTML=`${v(t.label)}${t.required?'<span class="forms-expert-required">*</span>':""}`,l.appendChild(o)}let m=document.createElement("div");m.className="forms-expert-input-wrapper";let c;switch(t.type){case"textarea":case"richText":c=document.createElement("textarea"),c.className=b("forms-expert-textarea",i?.fieldClassName),c.value=String(e||""),t.maxLength&&(c.maxLength=t.maxLength);break;case"select":case"dropdown":{c=document.createElement("select"),c.className=b("forms-expert-select",i?.fieldClassName);let o=document.createElement("option");o.value="",o.textContent=t.placeholder||"Select an option...",c.appendChild(o),(t.options||[]).forEach(p=>{let n=document.createElement("option");n.value=p,n.textContent=p,e===p&&(n.selected=!0),c.appendChild(n)});break}case"radio":{let o=document.createElement("div");if(o.className="forms-expert-radio-group",(t.options||[]).forEach(p=>{let n=document.createElement("label");n.className="forms-expert-radio-item";let r=document.createElement("input");r.type="radio",r.name=t.name,r.value=p,r.checked=e===p,n.appendChild(r),n.appendChild(document.createTextNode(` ${p}`)),o.appendChild(n)}),m.appendChild(o),a){let p=document.createElement("div");p.className="forms-expert-error-message",p.textContent=a,m.appendChild(p)}return l.appendChild(m),l}case"multiselect":{let o=document.createElement("div");o.className="forms-expert-multiselect-group";let d=e||[];if((t.options||[]).forEach(n=>{let r=document.createElement("label");r.className="forms-expert-checkbox-item";let u=document.createElement("input");u.type="checkbox",u.name=t.name,u.value=n,u.checked=d.includes(n),r.appendChild(u),r.appendChild(document.createTextNode(` ${n}`)),o.appendChild(r)}),m.appendChild(o),a){let n=document.createElement("div");n.className="forms-expert-error-message",n.textContent=a,m.appendChild(n)}return l.appendChild(m),l}case"rating":{let o=document.createElement("div");o.className="forms-expert-rating";let d=t.ratingMax||5,p=e||0;for(let n=1;n<=d;n++){let r=document.createElement("button");r.type="button",r.className=`forms-expert-rating-star ${n<=p?"active":""}`,r.textContent="\u2605",r.dataset.value=String(n),o.appendChild(r)}if(m.appendChild(o),a){let n=document.createElement("div");n.className="forms-expert-error-message",n.textContent=a,m.appendChild(n)}return l.appendChild(m),l}case"scale":case"opinionScale":{let o=document.createElement("div");o.className="forms-expert-scale";let d=t.min??(t.type==="opinionScale"?0:1),p=t.max??(t.type==="opinionScale"?10:5),n=e;for(let r=d;r<=p;r++){let u=document.createElement("button");u.type="button",u.className=`forms-expert-scale-btn ${n===r?"active":""}`,u.textContent=String(r),u.dataset.value=String(r),o.appendChild(u)}if(m.appendChild(o),t.lowLabel||t.highLabel){let r=document.createElement("div");r.className="forms-expert-scale-labels",r.innerHTML=`<span>${v(t.lowLabel||"")}</span><span>${v(t.highLabel||"")}</span>`,m.appendChild(r)}if(a){let r=document.createElement("div");r.className="forms-expert-error-message",r.textContent=a,m.appendChild(r)}return l.appendChild(m),l}case"slider":{c=document.createElement("input"),c.type="range",c.className="forms-expert-slider",c.min=String(t.min??0),c.max=String(t.max??100),c.step=String(t.step??1),c.value=String(e??t.min??0);break}case"file":{let o=i?.theme==="dark"?"#4b5563":"#d1d5db",d=i?.theme==="dark"?"#9ca3af":"#6b7280",p=i?.primaryColor||"#3b82f6",n=document.createElement("label");n.htmlFor=`mira-field-${t.name}`,n.className="forms-expert-dropzone";let r=document.createElement("input");r.id=`mira-field-${t.name}`,r.name=t.name,r.type="file",r.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0",t.allowedMimeTypes?.length&&(r.accept=t.allowedMimeTypes.join(",")),t.multiple&&(r.multiple=!0),n.appendChild(r);let u=document.createElement("div");u.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="${d}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" x2="12" y1="3" y2="15"/></svg>`,n.appendChild(u);let s=document.createElement("span");if(s.style.cssText="font-size:0.875rem;font-weight:500",s.textContent="Drag & drop a file here, or click to browse",n.appendChild(s),t.allowedMimeTypes?.length){let g=document.createElement("span");g.style.cssText=`font-size:0.75rem;color:${d}`,g.textContent=t.allowedMimeTypes.join(", "),n.appendChild(g)}if(t.maxFileSize){let g=document.createElement("span");g.style.cssText=`font-size:0.75rem;color:${d}`;let f=t.maxFileSize;g.textContent=`Max size: ${f<1048576?`${(f/1024).toFixed(0)} KB`:`${(f/1048576).toFixed(0)} MB`}`,n.appendChild(g)}if(n.addEventListener("dragover",g=>{g.preventDefault(),n.style.borderColor=p,n.style.backgroundColor=i?.theme==="dark"?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.04)"}),n.addEventListener("dragleave",()=>{n.style.borderColor=o,n.style.backgroundColor="transparent"}),n.addEventListener("drop",g=>{g.preventDefault(),n.style.borderColor=o,n.style.backgroundColor="transparent"}),l.appendChild(n),a){let g=document.createElement("div");g.className="forms-expert-error-message",g.textContent=a,l.appendChild(g)}return l}case"currency":{c=document.createElement("input"),c.type="number",c.className=b("forms-expert-input",i?.fieldClassName),c.value=String(e??""),t.min!==void 0&&(c.min=String(t.min)),t.max!==void 0&&(c.max=String(t.max)),c.step=String(t.step||.01);break}case"phone":c=document.createElement("input"),c.type="tel",c.className=b("forms-expert-input",i?.fieldClassName),c.value=String(e||"");break;case"url":c=document.createElement("input"),c.type="url",c.className=b("forms-expert-input",i?.fieldClassName),c.value=String(e||"");break;case"password":c=document.createElement("input"),c.type="password",c.className=b("forms-expert-input",i?.fieldClassName),c.value=String(e||"");break;case"time":c=document.createElement("input"),c.type="time",c.className=b("forms-expert-input",i?.fieldClassName),c.value=String(e||"");break;case"datetime":c=document.createElement("input"),c.type="datetime-local",c.className=b("forms-expert-input",i?.fieldClassName),c.value=String(e||"");break;case"colorPicker":c=document.createElement("input"),c.type="color",c.className="forms-expert-color",c.value=String(e||"#000000");break;case"dateRange":{let o=document.createElement("div");o.className="forms-expert-date-range";let d=e||{},p=document.createElement("input");p.type="date",p.className=b("forms-expert-input",i?.fieldClassName),p.name=`${t.name}.start`,p.value=d.start||"";let n=document.createElement("input");if(n.type="date",n.className=b("forms-expert-input",i?.fieldClassName),n.name=`${t.name}.end`,n.value=d.end||"",o.appendChild(p),o.appendChild(n),m.appendChild(o),a){let r=document.createElement("div");r.className="forms-expert-error-message",r.textContent=a,m.appendChild(r)}return l.appendChild(m),l}case"address":{let o=document.createElement("div");o.className="forms-expert-address";let d=t.addressFields||["street","city","state","zip","country"],p=e||{},n={street:"Street",street2:"Street Line 2",city:"City",state:"State",zip:"ZIP",country:"Country"};if(d.forEach(r=>{let u=document.createElement("input");u.type="text",u.className=b("forms-expert-input",i?.fieldClassName),u.name=`${t.name}.${r}`,u.placeholder=n[r]||r,u.value=p[r]||"",o.appendChild(u)}),m.appendChild(o),a){let r=document.createElement("div");r.className="forms-expert-error-message",r.textContent=a,m.appendChild(r)}return l.appendChild(m),l}case"name":{let o=document.createElement("div");o.className="forms-expert-name";let d=t.nameFields||["first","last"],p=e||{},n={prefix:"Prefix",first:"First Name",middle:"Middle",last:"Last Name",suffix:"Suffix"};if(d.forEach(r=>{let u=document.createElement("input");u.type="text",u.className=b("forms-expert-input",i?.fieldClassName),u.name=`${t.name}.${r}`,u.placeholder=n[r]||r,u.value=p[r]||"",o.appendChild(u)}),m.appendChild(o),a){let r=document.createElement("div");r.className="forms-expert-error-message",r.textContent=a,m.appendChild(r)}return l.appendChild(m),l}case"imageChoice":{let o=document.createElement("div");o.className="forms-expert-image-choice";let d=t.options||[],p=e;if(d.forEach(n=>{let r=document.createElement("button");if(r.type="button",r.className=`forms-expert-image-choice-item ${p===n.value?"active":""}`,r.dataset.value=n.value,n.imageUrl){let s=document.createElement("img");s.src=n.imageUrl,s.alt=n.label,r.appendChild(s)}let u=document.createElement("span");u.textContent=n.label,r.appendChild(u),o.appendChild(r)}),m.appendChild(o),a){let n=document.createElement("div");n.className="forms-expert-error-message",n.textContent=a,m.appendChild(n)}return l.appendChild(m),l}case"ranking":{let o=document.createElement("div");o.className="forms-expert-ranking";let d=t.options||[];if((e||[...d]).forEach((n,r)=>{let u=document.createElement("div");u.className="forms-expert-ranking-item",u.textContent=`${r+1}. ${n}`,u.dataset.value=n,o.appendChild(u)}),m.appendChild(o),a){let n=document.createElement("div");n.className="forms-expert-error-message",n.textContent=a,m.appendChild(n)}return l.appendChild(m),l}case"location":{let o=document.createElement("div");o.className="forms-expert-location";let d=e||{},p=document.createElement("input");p.type="text",p.className=b("forms-expert-input",i?.fieldClassName),p.name=`${t.name}.address`,p.placeholder="Address",p.value=d.address||"",o.appendChild(p);let n=document.createElement("div");n.className="forms-expert-location-coords";let r=document.createElement("input");r.type="number",r.className=b("forms-expert-input",i?.fieldClassName),r.name=`${t.name}.lat`,r.placeholder="Latitude",r.step="any",r.value=d.lat!==void 0?String(d.lat):"";let u=document.createElement("input");if(u.type="number",u.className=b("forms-expert-input",i?.fieldClassName),u.name=`${t.name}.lng`,u.placeholder="Longitude",u.step="any",u.value=d.lng!==void 0?String(d.lng):"",n.appendChild(r),n.appendChild(u),o.appendChild(n),m.appendChild(o),a){let s=document.createElement("div");s.className="forms-expert-error-message",s.textContent=a,m.appendChild(s)}return l.appendChild(m),l}default:c=document.createElement("input"),c.type=t.type==="email"?"email":t.type==="number"?"number":t.type==="date"?"date":"text",c.className=b("forms-expert-input",i?.fieldClassName),c.value=String(e||""),t.type==="number"&&(t.min!==void 0&&(c.min=String(t.min)),t.max!==void 0&&(c.max=String(t.max)),t.step!==void 0&&(c.step=String(t.step)));break}if(c.id=`mira-field-${t.name}`,c.name=t.name,t.placeholder&&"placeholder"in c&&(c.placeholder=t.placeholder),t.required&&(c.required=!0),a&&c.classList.add("forms-expert-error"),m.appendChild(c),a){let o=document.createElement("div");o.className="forms-expert-error-message",o.textContent=a,m.appendChild(o)}return l.appendChild(m),l}function L(t,e={},a={},i={}){let l=document.createElement("form");if(l.className="forms-expert",i.hideRequiredAsterisk){let s=document.createElement("style");s.textContent=".forms-expert .forms-expert-required { display: none; }",l.appendChild(s)}if(i.showFormName!==!1&&i.formName){let s=document.createElement("h1");s.className="forms-expert-title",s.textContent=i.formName,s.style.fontSize=i.formNameFontSize!=null?`${i.formNameFontSize}px`:"1.5rem";let g={normal:"400",medium:"500",semibold:"600",bold:"700"};s.style.fontWeight=g[i.formNameFontWeight||"bold"]||"700",s.style.marginBottom="0.5rem",l.appendChild(s)}let m=t.styling,c=t.fields,o=0;for(;o<c.length;){let s=c[o];if(s.row!=null){let g=[s],f=o+1;for(;f<c.length&&c[f].row===s.row;)g.push(c[f]),f++;if(g.length>1){let h=document.createElement("div");h.style.display="flex",h.style.gap="0.75rem",h.style.flexWrap="wrap",g.forEach(y=>{let C=document.createElement("div"),S=ne(y.width);S?C.style.flex=`0 0 calc(${S} - 0.75rem)`:C.style.flex="1 1 0",C.style.minWidth="180px";let N=E(y,e[y.name],a[y.name],m);C.appendChild(N),h.appendChild(C)}),l.appendChild(h)}else{let h=E(s,e[s.name],a[s.name],m);l.appendChild(h)}o=f}else{let g=E(s,e[s.name],a[s.name],m);l.appendChild(g),o++}}if(i.honeypot){let s=document.createElement("input");s.type="text",s.name="_hp",s.className="forms-expert-honeypot",s.tabIndex=-1,s.autocomplete="off",l.appendChild(s)}let d=document.createElement("input");d.type="hidden",d.name="pageUrl",d.value=typeof window<"u"?window.location.href:"",l.appendChild(d);let p=document.createElement("div");p.className="forms-expert-button-wrapper";let n=document.createElement("button");if(n.type="submit",n.className=b("forms-expert-button",i.buttonClassName),n.disabled=i.isLoading||!1,i.isLoading)n.innerHTML=`
|
|
363
374
|
<span class="forms-expert-button-loading">
|
|
364
375
|
<span class="forms-expert-spinner"></span>
|
|
365
376
|
Submitting...
|
|
366
377
|
</span>
|
|
367
|
-
`;else{let
|
|
378
|
+
`;else{let s=m?.buttonIcon,g=m?.buttonIconPosition||"left";if(s){n.style.display="inline-flex",n.style.alignItems="center",n.style.gap="0.5rem";let f=document.createElement("span");f.style.display="inline-flex",f.style.flexShrink="0",f.innerHTML=s;let h=document.createElement("span");h.textContent=i.submitText||"Submit",g==="right"?(n.appendChild(h),n.appendChild(f)):(n.appendChild(f),n.appendChild(h))}else n.textContent=i.submitText||"Submit"}let r=i.secondaryButton,u=()=>{if(!r?.enabled)return null;let s=document.createElement("a");if(s.className="forms-expert-secondary-btn",s.href=r.href||"#",s.style.display="inline-flex",s.style.alignItems="center",s.style.gap="0.5rem",r.icon){let h=document.createElement("span");h.style.display="inline-flex",h.style.flexShrink="0",h.innerHTML=r.icon;let y=document.createElement("span");y.textContent=r.text||"Learn More",r.iconPosition==="right"?(s.appendChild(y),s.appendChild(h)):(s.appendChild(h),s.appendChild(y))}else s.textContent=r.text||"Learn More";r.openInNewTab&&(s.target="_blank",s.rel="noopener noreferrer");let g=m?.primaryColor||"#3b82f6",f=r.color||g;return r.style==="filled"?(s.style.background=f,s.style.color=r.textColor||"#ffffff",s.style.border="none"):r.style==="outlined"?(s.style.background="transparent",s.style.color=r.textColor||f,s.style.border=`2px solid ${f}`):r.style==="link"?(s.style.background="transparent",s.style.color=r.textColor||f,s.style.border="none",s.style.textDecoration="underline"):(s.style.background="transparent",s.style.color=r.textColor||f,s.style.border="none"),r.marginTop!=null&&(s.style.marginTop=`${r.marginTop}px`),r.marginBottom!=null&&(s.style.marginBottom=`${r.marginBottom}px`),r.fontSize!=null&&(s.style.fontSize=`${r.fontSize}px`),s};if(r?.enabled&&r.position==="left"){let s=u();s&&p.appendChild(s)}if(p.appendChild(n),r?.enabled&&r.position!=="left"&&r.position!=="below"){let s=u();s&&(s.style.marginLeft="auto",p.appendChild(s))}if(l.appendChild(p),r?.enabled&&r.position==="below"){let s=document.createElement("div");s.className="forms-expert-secondary-below";let g=r.align||i.buttonAlign||"left";s.style.justifyContent=g==="center"?"center":g==="right"?"flex-end":"flex-start",r.marginTop!=null&&(s.style.marginTop=`${r.marginTop}px`),r.marginBottom!=null&&(s.style.marginBottom=`${r.marginBottom}px`);let f=u();f&&(f.style.marginTop="0",f.style.marginBottom="0",s.appendChild(f)),l.appendChild(s)}if(i.showBranding!==!1){let s=i.brandingText||"Powered by Forms Expert",g=i.brandingUrl||"https://mira.io",f=document.createElement("div");f.className="forms-expert-branding",f.innerHTML=`<a href="${g}" target="_blank" rel="noopener">${s}</a>`,l.appendChild(f)}return l}function z(t){let e=document.createElement("div");return e.className="forms-expert-success",e.innerHTML=`
|
|
368
379
|
<svg class="forms-expert-success-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
369
380
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
|
|
370
381
|
</svg>
|
|
371
382
|
<div class="forms-expert-success-message">${v(t)}</div>
|
|
372
|
-
`,e}function P(t){return t.reduce((e,
|
|
383
|
+
`,e}function P(t){return t.reduce((e,a)=>({...e,[a.field]:a.message}),{})}var x=class extends Error{constructor(a,i,l,m){super(a);this.code=i;this.statusCode=l;this.retryAfter=m;this.name="FormsError"}},w=class extends Error{constructor(a){super("Validation failed");this.errors=a;this.name="FormValidationError"}};var k=class{constructor(e){this.apiKey=e.apiKey,this.resourceId=e.resourceId,this.baseUrl=(e.baseUrl||"https://api.forms.expert/api/v1").replace(/\/$/,"")}buildUrl(e){let a=e.includes("?")?"&":"?";return`${this.baseUrl}${e}${a}token=${encodeURIComponent(this.apiKey)}`}async request(e,a,i){let l=this.buildUrl(a),m=await fetch(l,{method:e,headers:{"Content-Type":"application/json"},body:i?JSON.stringify(i):void 0}),c=await m.json();if(!m.ok)throw new x(c.message||"Request failed",c.code||"UNKNOWN_ERROR",m.status,c.retryAfter);return c}async isActive(e,a){let i=a?`?lang=${encodeURIComponent(a)}`:"";return this.request("GET",`/f/${this.resourceId}/${e}/is-active${i}`)}async validate(e,a){return this.request("POST",`/f/${this.resourceId}/${e}/validate`,{data:a})}async submit(e,a,i){let l=this.buildUrl(`/f/${this.resourceId}/${e}`);return Object.values(a).some(c=>c instanceof File||c instanceof FileList&&c.length>0)||i?.onProgress?this.submitWithFormData(l,a,i):this.request("POST",`/f/${this.resourceId}/${e}`,{data:a,pageUrl:i?.pageUrl||(typeof window<"u"?window.location.href:void 0),captchaToken:i?.captchaToken})}submitWithFormData(e,a,i){return new Promise((l,m)=>{let c=new FormData;for(let[p,n]of Object.entries(a))n instanceof File?c.append(p,n):n instanceof FileList?Array.from(n).forEach(r=>c.append(p,r)):n!=null&&c.append(`data[${p}]`,String(n));let o=i?.pageUrl||(typeof window<"u"?window.location.href:"");o&&c.append("pageUrl",o),i?.captchaToken&&c.append("captchaToken",i.captchaToken);let d=new XMLHttpRequest;i?.onProgress&&d.upload.addEventListener("progress",p=>{p.lengthComputable&&i.onProgress({loaded:p.loaded,total:p.total,percentage:Math.round(p.loaded/p.total*100)})}),d.addEventListener("load",()=>{try{let p=JSON.parse(d.responseText);d.status>=200&&d.status<300?l(p):m(new x(p.message||"Submission failed",p.code||"UNKNOWN_ERROR",d.status,p.retryAfter))}catch{m(new x("Invalid response","PARSE_ERROR",d.status))}}),d.addEventListener("error",()=>{m(new x("Network error","NETWORK_ERROR",0))}),d.addEventListener("abort",()=>{m(new x("Request aborted","ABORTED",0))}),d.open("POST",e),d.send(c)})}async trackView(e){let a=this.buildUrl(`/f/${this.resourceId}/${e}/view`);await fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"}).catch(()=>{})}getResourceId(){return this.resourceId}getBaseUrl(){return this.baseUrl}};var I=class{constructor(e,a,i={}){this.config=null;this.apiClient=e,this.slug=a,this.options=i}async initialize(e){return this.config=await this.apiClient.isActive(this.slug,e),this.options.trackViews&&this.apiClient.trackView(this.slug),this.config}getConfig(){return this.config}isActive(){return this.config?.active??!1}requiresCaptcha(){return this.config?.settings?.captcha?.enabled??!1}getCaptchaProvider(){return this.config?.settings?.captcha?.provider}getSchema(){return this.config?.schema}async validate(e){return this.apiClient.validate(this.slug,e)}async submit(e,a){this.options.onSubmitStart?.();try{if(this.config?.mode==="schema"){let l=await this.validate(e);if(!l.valid)throw this.options.onValidationError?.(l.errors),new w(l.errors)}let i=await this.apiClient.submit(this.slug,e,a);return this.options.onSubmitSuccess?.(i),i}catch(i){throw i instanceof x&&this.options.onSubmitError?.(i),i}}getSuccessMessage(){return this.config?.settings?.successMessage||"Form submitted successfully!"}getRedirectUrl(){return this.config?.settings?.redirectUrl}},$=class{constructor(e){this.apiClient=new k(e)}async isActive(e,a){return this.apiClient.isActive(e,a)}async validate(e,a){return this.apiClient.validate(e,a)}async submit(e,a,i){return this.apiClient.submit(e,a,i)}form(e,a){return new I(this.apiClient,e,a)}async trackView(e){return this.apiClient.trackView(e)}async submitWithRetry(e,a,i){let l=i?.maxRetries??3,m=null;for(let c=0;c<l;c++)try{return await this.submit(e,a,i)}catch(o){if(m=o,o instanceof x){if(["VALIDATION_ERROR","CAPTCHA_REQUIRED","ORIGIN_NOT_ALLOWED"].includes(o.code))throw o;if(o.code.includes("RATE_LIMIT")){let d=o.retryAfter||Math.pow(2,c)*1e3;await new Promise(p=>setTimeout(p,d));continue}}await new Promise(d=>setTimeout(d,Math.pow(2,c)*1e3))}throw m}};var F=class{constructor(e,a){this.config=null;this.values={};this.errors={};this.isLoading=!1;this.isSubmitted=!1;this.styleEl=null;this.sdk=new $(e),this.options=a;let i=a.target;if(typeof i=="string"){let l=document.querySelector(i);if(!l)throw new Error(`Element not found: ${i}`);this.container=l}else this.container=i}async init(){try{if(this.renderLoading(),this.config=await this.sdk.isActive(this.options.slug,this.options.lang),!this.config.active){this.renderError("This form is not available");return}this.options.trackViews&&this.sdk.trackView(this.options.slug),this.injectStyles(),this.render()}catch(e){this.renderError("Failed to load form"),this.options.onError?.(e)}}injectStyles(){if(this.styleEl)return;this.styleEl=document.createElement("style"),this.styleEl.id=`forms-expert-styles-${this.options.slug}`;let e={...this.config?.schema?.styling,...this.config?.styling};this.styleEl.textContent=R(e),document.head.appendChild(this.styleEl),this.injectGoogleFont(e?.fontFamily)}injectGoogleFont(e){if(!e)return;let a=["Inter","Roboto","Open Sans","Lato","Poppins","Montserrat","Nunito","Source Sans Pro","Raleway","Ubuntu","Playfair Display","Merriweather"],i=e.split(",")[0]?.trim();if(!i||!a.includes(i))return;let l=`forms-expert-font-${this.options.slug}`;if(document.getElementById(l))return;let m=document.createElement("link");m.id=l,m.rel="stylesheet",m.href=`https://fonts.googleapis.com/css2?family=${i.replace(/ /g,"+")}:wght@400;500;600;700&display=swap`,document.head.appendChild(m)}render(){if(!this.config?.schema)return;if(this.isSubmitted){this.container.innerHTML="";let l=this.config.settings?.successMessage||"Form submitted successfully!";this.container.appendChild(z(l));return}let e={...this.config.schema.styling,...this.config.styling},a={...this.config.schema,styling:e},i=L(a,this.values,this.errors,{honeypot:this.config.settings?.honeypot,showBranding:this.config.branding?.enabled!==!1,brandingText:this.config.branding?.text,brandingUrl:this.config.branding?.url,submitText:e.buttonText||this.options.submitText,isLoading:this.isLoading,hideRequiredAsterisk:e.hideRequiredAsterisk,formName:this.config.hostedConfig?.pageTitle||this.config.name,showFormName:this.config.settings?.showFormName,secondaryButton:e.secondaryButton,buttonAlign:e.buttonAlign,buttonClassName:e.buttonClassName,formNameFontSize:e.formNameFontSize,formNameFontWeight:e.formNameFontWeight});i.addEventListener("input",l=>{let m=l.target;m.name&&m.name!=="_hp"&&m.name!=="pageUrl"&&(m.type==="checkbox"?this.values[m.name]=m.checked:m.type==="file"?this.values[m.name]=m.multiple?m.files:m.files?.[0]:this.values[m.name]=m.value,this.errors[m.name]&&(delete this.errors[m.name],this.render()))}),i.addEventListener("submit",l=>{l.preventDefault(),this.handleSubmit()}),this.container.innerHTML="",this.container.appendChild(i)}async handleSubmit(){if(!(this.isLoading||!this.config)){this.isLoading=!0,this.errors={},this.render();try{let e=await this.sdk.submit(this.options.slug,this.values);this.isLoading=!1,this.isSubmitted=!0,this.render(),this.options.onSuccess?.(e);let a=this.options.redirectUrl||this.config.settings?.redirectUrl;a&&setTimeout(()=>{window.location.href=a},1500),this.options.resetOnSuccess&&setTimeout(()=>{this.reset()},3e3)}catch(e){this.isLoading=!1,e instanceof w?(this.errors=P(e.errors),this.options.onValidationError?.(e.errors)):this.options.onError?.(e),this.render()}}}reset(){this.values={},this.errors={},this.isLoading=!1,this.isSubmitted=!1,this.render()}renderLoading(){this.container.innerHTML=`
|
|
373
384
|
<div class="forms-expert" style="display: flex; align-items: center; justify-content: center; padding: 2rem;">
|
|
374
385
|
<svg width="24" height="24" viewBox="0 0 24 24" style="animation: fe-spin 1s linear infinite; color: #9ca3af;">
|
|
375
386
|
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="3" fill="none" stroke-dasharray="31.4 31.4" stroke-linecap="round"/>
|
|
@@ -380,5 +391,5 @@ ${e.customCss||""}
|
|
|
380
391
|
<div class="forms-expert" style="text-align: center; padding: 2rem; color: #ef4444;">
|
|
381
392
|
<p>${e}</p>
|
|
382
393
|
</div>
|
|
383
|
-
`}destroy(){this.container.innerHTML="",this.styleEl?.remove(),this.styleEl=null}};function M(){document.querySelectorAll("[data-forms-expert]").forEach(e=>{let
|
|
394
|
+
`}destroy(){this.container.innerHTML="",this.styleEl?.remove(),this.styleEl=null}};function M(){document.querySelectorAll("[data-forms-expert]").forEach(e=>{let a=e.getAttribute("data-api-key"),i=e.getAttribute("data-resource-id"),l=e.getAttribute("data-forms-expert"),m=e.getAttribute("data-base-url")||void 0;if(!a||!i||!l){console.error("Forms Expert: Missing required attributes",{apiKey:!!a,resourceId:!!i,slug:!!l});return}new F({apiKey:a,resourceId:i,baseUrl:m},{target:e,slug:l,trackViews:e.getAttribute("data-track-views")==="true",submitText:e.getAttribute("data-submit-text")||void 0,resetOnSuccess:e.getAttribute("data-reset")==="true",lang:e.getAttribute("data-lang")||void 0}).init()})}typeof window<"u"&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",M):M());0&&(module.exports={FormWidget,autoInit,errorsToRecord,generateFormStyles,renderField,renderForm,renderSuccess});
|
|
384
395
|
//# sourceMappingURL=index.cjs.map
|