@verbb/formie-browser 1.0.3 → 1.0.5

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.
Files changed (206) hide show
  1. package/CHANGELOG.md +65 -17
  2. package/dist/chunks/address-country-Rx6GQTND.js +68 -0
  3. package/dist/chunks/address-finder-yXU5yMjG.js +30 -0
  4. package/dist/chunks/address-state-BQ0xGV9n.js +344 -0
  5. package/dist/chunks/api-CmwLRq_n.js +780 -0
  6. package/dist/chunks/api-DMK8NSUI.js +407 -0
  7. package/dist/chunks/api-sPqGbOww.js +125 -0
  8. package/dist/chunks/async-nPFRNQ06.js +25 -0
  9. package/dist/chunks/bpoint-DSjqRv63.js +24 -0
  10. package/dist/chunks/calculations-CgVJcQ2P.js +299 -0
  11. package/dist/chunks/captcha-eu-CWJb64_j.js +31 -0
  12. package/dist/chunks/checkbox-radio-DQ0H67Tj.js +125 -0
  13. package/dist/chunks/chunk-3b4jIN3o.js +13 -0
  14. package/dist/chunks/combobox-D-2b42wn.js +1954 -0
  15. package/dist/chunks/conditions-CZ3FU5QO.js +412 -0
  16. package/dist/chunks/constants-DVcJAvc5.js +38 -0
  17. package/dist/chunks/country-from-ip-BwxKaBuJ.js +26 -0
  18. package/dist/chunks/custom-google-maps-BsaSirEZ.js +194 -0
  19. package/dist/chunks/custom-link-CJ1-FjEM.js +46 -0
  20. package/dist/chunks/custom-maps-DYW_pBid.js +161 -0
  21. package/dist/chunks/date-picker-5CA_-zGb.js +5311 -0
  22. package/dist/chunks/debug-BV0DvdHx.js +41 -0
  23. package/dist/chunks/dist-BF5GU3_9.js +2674 -0
  24. package/dist/chunks/event-names-BCI2FLD8.js +51 -0
  25. package/dist/chunks/eway-D3ctTbEk.js +70 -0
  26. package/dist/chunks/field-references.keys-58ZSTrCW.js +21 -0
  27. package/dist/chunks/field-references.resolver-CHwn0G0L.js +145 -0
  28. package/dist/chunks/file-upload-D49m8-DR.js +287 -0
  29. package/dist/chunks/friendly-captcha-v1-ByXzENYZ.js +31 -0
  30. package/dist/chunks/friendly-captcha-v2-BPdlmhQu.js +36 -0
  31. package/dist/chunks/friendly-challenge-8uPatWqk.js +832 -0
  32. package/dist/chunks/go-cardless-BwASSYSK.js +23 -0
  33. package/dist/chunks/google-address-OhKilPWE.js +161 -0
  34. package/dist/chunks/hcaptcha-CdCd9oEi.js +54 -0
  35. package/dist/chunks/hidden-D7_Ch-QN.js +26 -0
  36. package/dist/chunks/http-D-JExro7.js +27 -0
  37. package/dist/chunks/i18n-BY1ds1BL.js +121 -0
  38. package/dist/chunks/leaflet-src-j-lHNmhR.js +4585 -0
  39. package/dist/chunks/loqate-Cp2zvwpE.js +76 -0
  40. package/dist/chunks/mollie-COG-ko2D.js +23 -0
  41. package/dist/chunks/moneris-CMH8PlRc.js +117 -0
  42. package/dist/chunks/opayo-D2jsR5vh.js +113 -0
  43. package/dist/chunks/paddle-DxF88RfC.js +55 -0
  44. package/dist/chunks/paypal-b5pnwrA2.js +95 -0
  45. package/dist/chunks/payway-BJYu9DIR.js +55 -0
  46. package/dist/chunks/phone-country-D3ayr60L.js +2645 -0
  47. package/dist/chunks/place-kit-BGHklIZ-.js +48 -0
  48. package/dist/chunks/placekit-autocomplete.esm-DWVabQlq.js +1236 -0
  49. package/dist/chunks/recaptcha-enterprise-BSwi8IVX.js +65 -0
  50. package/dist/chunks/recaptcha-shared-B4zAescW.js +15 -0
  51. package/dist/chunks/recaptcha-v2-checkbox-CnDQmsKa.js +40 -0
  52. package/dist/chunks/recaptcha-v2-invisible-Cz5uIlp-.js +53 -0
  53. package/dist/chunks/recaptcha-v3-BtbbP111.js +27 -0
  54. package/dist/chunks/repeater-B5leVxZU.js +102 -0
  55. package/dist/chunks/rich-text-Cv8ADyk-.js +349 -0
  56. package/dist/chunks/scripts-6CYSUGKQ.js +24 -0
  57. package/dist/chunks/sdk-BhHAYgga.js +1397 -0
  58. package/dist/chunks/shared-Bx9s0i0P.js +100 -0
  59. package/dist/chunks/signature-CpgqHCEx.js +463 -0
  60. package/dist/chunks/snaptcha-vz1RnZ15.js +8 -0
  61. package/dist/chunks/square-BP8RWAKB.js +40 -0
  62. package/dist/chunks/stripe-MihN63uC.js +184 -0
  63. package/dist/chunks/styles-BfoIZwJp.js +19 -0
  64. package/dist/chunks/summary-D3AjxpYN.js +114 -0
  65. package/dist/chunks/table-C-lkQN6I.js +78 -0
  66. package/dist/chunks/text-limit-B09elPDB.js +125 -0
  67. package/dist/chunks/theme-classes-Tv7q7ToE.js +44 -0
  68. package/dist/chunks/turnstile-D_Pi1CKM.js +58 -0
  69. package/dist/chunks/utils-Vqp8i_RM.js +49401 -0
  70. package/dist/css/formie-theme.css +2 -0
  71. package/dist/css/theme/fields/_address-state.css +94 -0
  72. package/dist/css/theme/fields/_combobox.css +246 -0
  73. package/dist/css/theme/fields/_select.css +13 -0
  74. package/dist/index.js +2447 -39
  75. package/dist/js/core/create-formie-client.d.ts.map +1 -1
  76. package/dist/js/core/field-error-container.d.ts +4 -0
  77. package/dist/js/core/field-error-container.d.ts.map +1 -0
  78. package/dist/js/core/submit-result-state.d.ts.map +1 -1
  79. package/dist/js/core/submit-result-ui.d.ts.map +1 -1
  80. package/dist/js/core/validation-focus.d.ts +4 -0
  81. package/dist/js/core/validation-focus.d.ts.map +1 -0
  82. package/dist/js/modules/address/api.d.ts +1 -0
  83. package/dist/js/modules/address/api.d.ts.map +1 -1
  84. package/dist/js/modules/address/constants.d.ts +22 -1
  85. package/dist/js/modules/address/constants.d.ts.map +1 -1
  86. package/dist/js/modules/address/host.d.ts +2 -2
  87. package/dist/js/modules/address/host.d.ts.map +1 -1
  88. package/dist/js/modules/address/loqate.d.ts.map +1 -1
  89. package/dist/js/modules/fields/address-country.d.ts +3 -0
  90. package/dist/js/modules/fields/address-country.d.ts.map +1 -0
  91. package/dist/js/modules/fields/address-state.d.ts +3 -0
  92. package/dist/js/modules/fields/address-state.d.ts.map +1 -0
  93. package/dist/js/modules/fields/calculations.d.ts.map +1 -1
  94. package/dist/js/modules/fields/checkbox-radio.d.ts.map +1 -1
  95. package/dist/js/modules/fields/combobox.d.ts +17 -0
  96. package/dist/js/modules/fields/combobox.d.ts.map +1 -0
  97. package/dist/js/modules/fields/custom-google-maps.d.ts +64 -0
  98. package/dist/js/modules/fields/custom-google-maps.d.ts.map +1 -0
  99. package/dist/js/modules/fields/custom-link.d.ts +3 -0
  100. package/dist/js/modules/fields/custom-link.d.ts.map +1 -0
  101. package/dist/js/modules/fields/custom-maps.d.ts +3 -0
  102. package/dist/js/modules/fields/custom-maps.d.ts.map +1 -0
  103. package/dist/js/modules/fields/date-picker.d.ts.map +1 -1
  104. package/dist/js/modules/fields/file-upload.d.ts.map +1 -1
  105. package/dist/js/modules/fields/index.d.ts.map +1 -1
  106. package/dist/js/modules/fields/phone-country.d.ts.map +1 -1
  107. package/dist/js/modules/fields/text-limit.d.ts.map +1 -1
  108. package/dist/js/submit/pipeline.d.ts.map +1 -1
  109. package/dist/js/utils/country-from-ip.d.ts +7 -0
  110. package/dist/js/utils/country-from-ip.d.ts.map +1 -0
  111. package/dist/js/utils/field-references.d.ts +1 -0
  112. package/dist/js/utils/field-references.d.ts.map +1 -1
  113. package/dist/js/utils/field-references.row-scope.d.ts +11 -0
  114. package/dist/js/utils/field-references.row-scope.d.ts.map +1 -0
  115. package/dist/js/utils/i18n.d.ts.map +1 -1
  116. package/dist/js/validation/rules/email.d.ts.map +1 -1
  117. package/dist/js/validation/rules/number.d.ts.map +1 -1
  118. package/dist/js/validation/validator.d.ts.map +1 -1
  119. package/package.json +6 -3
  120. package/src/css/formie-theme.css +2 -0
  121. package/src/css/theme/fields/_address-state.css +94 -0
  122. package/src/css/theme/fields/_combobox.css +246 -0
  123. package/src/css/theme/fields/_select.css +13 -0
  124. package/src/js/core/create-formie-client.ts +27 -0
  125. package/src/js/core/field-error-container.ts +39 -0
  126. package/src/js/core/submit-result-state.ts +12 -2
  127. package/src/js/core/submit-result-ui.ts +7 -13
  128. package/src/js/core/validation-focus.ts +117 -0
  129. package/src/js/modules/address/api.ts +7 -0
  130. package/src/js/modules/address/constants.ts +82 -2
  131. package/src/js/modules/address/host.ts +16 -6
  132. package/src/js/modules/address/loqate.ts +3 -17
  133. package/src/js/modules/fields/address-country.ts +156 -0
  134. package/src/js/modules/fields/address-state.ts +946 -0
  135. package/src/js/modules/fields/calculations.ts +32 -0
  136. package/src/js/modules/fields/checkbox-radio.ts +21 -15
  137. package/src/js/modules/fields/combobox.ts +188 -0
  138. package/src/js/modules/fields/custom-google-maps.ts +416 -0
  139. package/src/js/modules/fields/custom-link.ts +95 -0
  140. package/src/js/modules/fields/custom-maps.ts +339 -0
  141. package/src/js/modules/fields/date-picker.ts +96 -3
  142. package/src/js/modules/fields/file-upload.ts +12 -9
  143. package/src/js/modules/fields/index.ts +6 -0
  144. package/src/js/modules/fields/phone-country.ts +6 -0
  145. package/src/js/modules/fields/text-limit.ts +87 -22
  146. package/src/js/submit/pipeline.ts +11 -1
  147. package/src/js/utils/country-from-ip.ts +54 -0
  148. package/src/js/utils/field-references.row-scope.ts +303 -0
  149. package/src/js/utils/field-references.ts +1 -0
  150. package/src/js/utils/i18n.ts +184 -5
  151. package/src/js/validation/rules/email.ts +3 -2
  152. package/src/js/validation/rules/match.ts +2 -2
  153. package/src/js/validation/rules/minmax.ts +4 -4
  154. package/src/js/validation/rules/number.ts +9 -5
  155. package/src/js/validation/rules/pattern.ts +4 -4
  156. package/src/js/validation/rules/required.ts +1 -1
  157. package/src/js/validation/rules/url.ts +1 -1
  158. package/src/js/validation/validator.ts +7 -7
  159. package/dist/chunks/address-finder-BjMuEiwF.js +0 -37
  160. package/dist/chunks/bpoint-KudsBCo2.js +0 -26
  161. package/dist/chunks/calculations-DlGSkQ3W.js +0 -147
  162. package/dist/chunks/captcha-eu-CterYFok.js +0 -34
  163. package/dist/chunks/checkbox-radio-CBvgk3hR.js +0 -136
  164. package/dist/chunks/conditions-DYy1-Hwt.js +0 -459
  165. package/dist/chunks/date-picker-BlD--zfe.js +0 -4994
  166. package/dist/chunks/eway-qwc-B5Us.js +0 -74
  167. package/dist/chunks/file-upload-CIgHrXfp.js +0 -316
  168. package/dist/chunks/friendly-captcha-v1-EDFac33c.js +0 -33
  169. package/dist/chunks/friendly-captcha-v2-BDpSvFGR.js +0 -38
  170. package/dist/chunks/go-cardless-DuDMVsnz.js +0 -24
  171. package/dist/chunks/google-address-Bmjp01pH.js +0 -181
  172. package/dist/chunks/hcaptcha-BTQ6An6g.js +0 -56
  173. package/dist/chunks/hidden-DbPdOxKb.js +0 -31
  174. package/dist/chunks/index-BEsfee-D.js +0 -1839
  175. package/dist/chunks/index-BP7Unm5Y.js +0 -863
  176. package/dist/chunks/index-BcqwpPNE.js +0 -4314
  177. package/dist/chunks/loqate-BdNGv93o.js +0 -55
  178. package/dist/chunks/mollie-DFOjTuGX.js +0 -24
  179. package/dist/chunks/moneris-BbFfl-EL.js +0 -101
  180. package/dist/chunks/opayo-CmgYa9ya.js +0 -122
  181. package/dist/chunks/paddle-BUi7w1_o.js +0 -60
  182. package/dist/chunks/paypal-A-ePfh6k.js +0 -100
  183. package/dist/chunks/payway-BqFCbhyo.js +0 -56
  184. package/dist/chunks/phone-country-DPMiqk4L.js +0 -3765
  185. package/dist/chunks/place-kit-CX7tamAg.js +0 -42
  186. package/dist/chunks/placekit-autocomplete.esm-LAwfbPZl.js +0 -1299
  187. package/dist/chunks/recaptcha-enterprise-DxF6cW95.js +0 -71
  188. package/dist/chunks/recaptcha-shared-DhGcbiaq.js +0 -15
  189. package/dist/chunks/recaptcha-v2-checkbox-R9EfbZ4k.js +0 -41
  190. package/dist/chunks/recaptcha-v2-invisible-DV9hswAp.js +0 -59
  191. package/dist/chunks/recaptcha-v3-V0xc-Edh.js +0 -28
  192. package/dist/chunks/repeater-DKUT6TGI.js +0 -124
  193. package/dist/chunks/rich-text-SH7KiaKH.js +0 -304
  194. package/dist/chunks/scripts-D9N2d5rN.js +0 -36
  195. package/dist/chunks/sdk-3SicTWby.js +0 -1559
  196. package/dist/chunks/shared-BmntPmnW.js +0 -80
  197. package/dist/chunks/signature-BA3tQsGT.js +0 -550
  198. package/dist/chunks/snaptcha-DV7p6J9k.js +0 -8
  199. package/dist/chunks/square-Bs-ndqYK.js +0 -46
  200. package/dist/chunks/stripe-DkZAHxtn.js +0 -202
  201. package/dist/chunks/styles-C3aqgtek.js +0 -21
  202. package/dist/chunks/summary-Dq2i9TQk.js +0 -126
  203. package/dist/chunks/table-Cu4WfVcw.js +0 -95
  204. package/dist/chunks/text-limit-2ycmB-Ae.js +0 -135
  205. package/dist/chunks/turnstile-CId90tRr.js +0 -59
  206. package/dist/chunks/utils-BntI3W4S.js +0 -6149
package/dist/index.js CHANGED
@@ -1,40 +1,2448 @@
1
- import { F as s, z as i, L as o, B as t, M as l, D as r, E as d, i as n, h as m, G as E, H as F, I as u, d as g, a as M, e as c, u as y, j as b, J as f, k as L, K as N, N as R, O as _, P as p, Q as v, R as D, S as T, n as C, T as I, U as V, V as O, r as A, W as G, X as S, Y as h, Z as K, _ as z, $ as B } from "./chunks/index-BcqwpPNE.js";
2
- export {
3
- s as FORMIE_HTML_EVENT_NAMES,
4
- i as FormieValidator,
5
- o as LEGACY_FORMIE_DOM_EVENT_BRIDGES,
6
- t as LEGACY_FORMIE_VALIDATOR_EVENT_BRIDGES,
7
- l as ModuleRegistry,
8
- r as bindLegacyDomEventCompatibility,
9
- d as bindLegacyValidatorCompatibility,
10
- n as buildFieldValueRegistry,
11
- m as createDebug,
12
- E as createFormieClient,
13
- F as debugLog,
14
- u as debugWarn,
15
- g as defineAddressModule,
16
- M as defineCaptchaModule,
17
- c as definePassiveCaptchaModule,
18
- y as definePaymentModule,
19
- b as fieldKeyToInputName,
20
- f as formie,
21
- L as getFieldModuleEventName,
22
- N as getFormieTranslations,
23
- R as getGlobalModuleLifecycleEventName,
24
- _ as getScopedModuleLifecycleEventName,
25
- p as hydrateFormieModules,
26
- v as inputNameToFieldKey,
27
- D as isFormieDebugEnabled,
28
- T as mergeFormieTranslations,
29
- C as normalizeFieldKey,
30
- I as normalizeFormieEventName,
31
- V as parseFieldReference,
32
- O as resolveFieldReferenceFromFormData,
33
- A as resolveFieldReferenceLive,
34
- G as resolveLegacyCompatibilityOptions,
35
- S as setFormieDebugEnabled,
36
- h as setFormieTranslations,
37
- K as t,
38
- z as toDomEventName,
39
- B as translate
1
+ import { c as e, d as t, l as n, o as r, r as i, t as a, u as o } from "./chunks/event-names-BCI2FLD8.js";
2
+ import { a as s, i as c, n as l, r as u, t as d } from "./chunks/debug-BV0DvdHx.js";
3
+ import { a as f, c as p, d as ee, i as m, l as h, n as g, o as _, r as v, s as y, t as b, u as x } from "./chunks/api-CmwLRq_n.js";
4
+ import { n as te, r as S, t as C } from "./chunks/theme-classes-Tv7q7ToE.js";
5
+ import { t as w } from "./chunks/http-D-JExro7.js";
6
+ import { a as T, i as E, n as ne, r as re, t as ie } from "./chunks/i18n-BY1ds1BL.js";
7
+ import { n as ae, t as oe } from "./chunks/api-DMK8NSUI.js";
8
+ import { n as se, r as ce, t as le } from "./chunks/field-references.keys-58ZSTrCW.js";
9
+ import { i as ue, n as de, r as fe, t as pe } from "./chunks/field-references.resolver-CHwn0G0L.js";
10
+ import { t as me } from "./chunks/api-sPqGbOww.js";
11
+ //#region src/js/compatibility/event-map.ts
12
+ var he = [
13
+ {
14
+ legacyEvent: "onFormieLoaded",
15
+ canonicalEvent: "formie:mount:after",
16
+ disposition: "approximate",
17
+ target: "document"
18
+ },
19
+ {
20
+ legacyEvent: "onFormieInit",
21
+ canonicalEvent: "formie:mount:after",
22
+ disposition: "approximate",
23
+ target: "document"
24
+ },
25
+ {
26
+ legacyEvent: "onFormieReady",
27
+ canonicalEvent: "formie:mount:after",
28
+ disposition: "safe"
29
+ },
30
+ {
31
+ legacyEvent: "onAfterFormieSubmit",
32
+ canonicalEvent: "formie:submit:result",
33
+ disposition: "safe"
34
+ },
35
+ {
36
+ legacyEvent: "onFormieSubmitError",
37
+ canonicalEvent: "formie:submit:result",
38
+ disposition: "safe"
39
+ },
40
+ {
41
+ legacyEvent: "onFormiePageToggle",
42
+ canonicalEvent: "formie:page:navigate:after",
43
+ disposition: "safe"
44
+ },
45
+ {
46
+ legacyEvent: "onBeforeFormieSubmit",
47
+ canonicalEvent: "formie:submit:before",
48
+ disposition: "approximate"
49
+ },
50
+ {
51
+ legacyEvent: "onFormieValidate",
52
+ canonicalEvent: "formie:stage:validate:before",
53
+ disposition: "approximate"
54
+ },
55
+ {
56
+ legacyEvent: "onAfterFormieValidate",
57
+ canonicalEvent: "formie:stage:validate:after",
58
+ disposition: "approximate"
59
+ },
60
+ {
61
+ legacyEvent: "onFormieSubmit",
62
+ canonicalEvent: "formie:submit:after",
63
+ disposition: "approximate"
64
+ }
65
+ ], ge = [
66
+ {
67
+ legacyEvent: "formieValidatorInitialized",
68
+ canonicalEvent: "formie:validator:ready",
69
+ disposition: "safe"
70
+ },
71
+ {
72
+ legacyEvent: "formieValidatorDestroyed",
73
+ canonicalEvent: "formie:validator:destroy",
74
+ disposition: "safe"
75
+ },
76
+ {
77
+ legacyEvent: "formieValidatorShowError",
78
+ canonicalEvent: "formie:validator:show-error",
79
+ disposition: "safe"
80
+ },
81
+ {
82
+ legacyEvent: "formieValidatorClearError",
83
+ canonicalEvent: "formie:validator:clear-error",
84
+ disposition: "safe"
85
+ }
86
+ ];
87
+ function _e(e) {
88
+ if (!e) return {
89
+ enabled: !1,
90
+ legacyDomEvents: !1,
91
+ legacyValidatorEvents: !1
92
+ };
93
+ if (e === !0) return {
94
+ enabled: !0,
95
+ legacyDomEvents: !0,
96
+ legacyValidatorEvents: !0
97
+ };
98
+ let t = e.legacyDomEvents ?? !0, n = e.legacyValidatorEvents ?? !0;
99
+ return {
100
+ enabled: t || n,
101
+ legacyDomEvents: t,
102
+ legacyValidatorEvents: n
103
+ };
104
+ }
105
+ //#endregion
106
+ //#region src/js/compatibility/dom-adapter.ts
107
+ function ve(e, t, n) {
108
+ e.dispatchEvent(new CustomEvent(t, {
109
+ bubbles: !0,
110
+ detail: n
111
+ }));
112
+ }
113
+ function ye(e, t) {
114
+ if (e.canonicalEvent !== "formie:submit:result") return !0;
115
+ let n = t;
116
+ return e.legacyEvent === "onAfterFormieSubmit" ? !!n?.ok : e.legacyEvent === "onFormieSubmitError" ? n?.ok === !1 : !0;
117
+ }
118
+ function be(e, t) {
119
+ let n = t && typeof t == "object" ? t : {}, r = typeof n.pageId == "string" ? n.pageId : "", i = Array.from(e.querySelectorAll("[data-formie-page-id]"));
120
+ return { data: {
121
+ nextPageId: r,
122
+ nextPageIndex: i.findIndex((e) => e.getAttribute("data-formie-page-id") === r),
123
+ totalPages: i.length
124
+ } };
125
+ }
126
+ function xe(e, t, n, r, i) {
127
+ let a = globalThis.Formie || i;
128
+ return e.legacyEvent === "onFormieLoaded" ? { formie: a } : e.legacyEvent === "onFormieInit" ? {
129
+ formie: a,
130
+ form: i,
131
+ $form: r,
132
+ formId: i.id
133
+ } : e.legacyEvent === "onFormieReady" ? {
134
+ ...t && typeof t == "object" ? t : {},
135
+ form: r,
136
+ target: n,
137
+ instance: i
138
+ } : e.legacyEvent === "onFormiePageToggle" ? be(r, t) : t;
139
+ }
140
+ function Se({ target: e, form: n, instance: r, options: i, unbinds: a }) {
141
+ i.legacyDomEvents && he.forEach((i) => {
142
+ let o = (t) => {
143
+ !(t instanceof CustomEvent) || !ye(i, t.detail) || ve(i.target === "document" ? document : n, i.legacyEvent, xe(i, t.detail, e, n, r));
144
+ };
145
+ e.addEventListener(t(i.canonicalEvent), o), a.push(() => {
146
+ e.removeEventListener(t(i.canonicalEvent), o);
147
+ });
148
+ });
149
+ }
150
+ //#endregion
151
+ //#region src/js/compatibility/validator-adapter.ts
152
+ function D(e, t, n) {
153
+ e.dispatchEvent(new CustomEvent(t, {
154
+ bubbles: !0,
155
+ detail: n
156
+ }));
157
+ }
158
+ function Ce(e, t) {
159
+ return !!e && typeof e == "object" && e.validator === t;
160
+ }
161
+ function we({ target: e, form: t, validatorDetail: n, options: r, unbinds: i }) {
162
+ if (!r.legacyValidatorEvents || !n) return;
163
+ let { validator: a, addValidator: o, removeValidator: s } = n, c = {
164
+ ...n,
165
+ form: t,
166
+ target: e
167
+ };
168
+ D(document, "formieValidatorInitialized", c);
169
+ let l = (e) => {
170
+ !(e instanceof CustomEvent) || !Ce(e.detail, a) || D(document, "formieValidatorDestroyed", {
171
+ ...c,
172
+ ...e.detail
173
+ });
174
+ }, u = (n) => {
175
+ !(n instanceof CustomEvent) || !Ce(n.detail, a) || !(n.target instanceof Element) || t.contains(n.target) && D(n.target, "formieValidatorShowError", {
176
+ ...n.detail,
177
+ addValidator: o,
178
+ removeValidator: s,
179
+ form: t,
180
+ target: e
181
+ });
182
+ }, d = (n) => {
183
+ !(n instanceof CustomEvent) || !Ce(n.detail, a) || !(n.target instanceof Element) || t.contains(n.target) && D(n.target, "formieValidatorClearError", {
184
+ ...n.detail,
185
+ addValidator: o,
186
+ removeValidator: s,
187
+ form: t,
188
+ target: e
189
+ });
190
+ };
191
+ document.addEventListener("formie:validator:destroy", l), document.addEventListener("formie:validator:show-error", u), document.addEventListener("formie:validator:clear-error", d), i.push(() => {
192
+ document.removeEventListener("formie:validator:destroy", l), document.removeEventListener("formie:validator:show-error", u), document.removeEventListener("formie:validator:clear-error", d);
193
+ });
194
+ }
195
+ //#endregion
196
+ //#region src/js/core/dom-events.ts
197
+ function O(e, n, r) {
198
+ e.dispatchEvent(new CustomEvent(t(n), {
199
+ bubbles: !0,
200
+ detail: r
201
+ }));
202
+ }
203
+ //#endregion
204
+ //#region src/js/core/validation-focus.ts
205
+ function Te(e, t) {
206
+ let n = (e.getAttribute("aria-describedby") || "").trim(), r = n ? n.split(/\s+/) : [];
207
+ r.includes(t) || r.push(t), e.setAttribute("aria-describedby", r.join(" ").trim());
208
+ }
209
+ function Ee(e) {
210
+ return Array.from(e.querySelectorAll("[data-formie-field-handle]")).find((e) => e.getAttribute("data-formie-field-has-error") === "true" ? !0 : e.querySelector("[data-formie-field-error]") !== null) || null;
211
+ }
212
+ function De(e) {
213
+ return e.querySelector("[aria-invalid=\"true\"]") || e.querySelector("input:not([type=\"hidden\"]):not([disabled]), select:not([disabled]), textarea:not([disabled])");
214
+ }
215
+ function Oe(e) {
216
+ return e.querySelector("[data-formie-message-error], [data-formie-error-container], [data-formie-errors]");
217
+ }
218
+ function ke(e) {
219
+ e.querySelectorAll("[data-formie-field-handle]").forEach((t) => {
220
+ let n = t;
221
+ if (!(n.getAttribute("data-formie-field-has-error") === "true" || n.querySelector("[data-formie-field-error]") !== null)) return;
222
+ n.setAttribute("data-formie-field-has-error", "true"), C(n, e, "fieldLayoutError");
223
+ let r = n.querySelector("[data-formie-field-errors]")?.id || "", i = n.querySelector("[data-formie-field-error]")?.id || "";
224
+ n.querySelectorAll("input, select, textarea").forEach((t) => {
225
+ let n = t;
226
+ n.setAttribute("aria-invalid", "true"), C(n, e, "fieldControlError"), n.setAttribute("data-formie-input-has-error", "true"), r && Te(n, r), i && n.setAttribute("aria-errormessage", i);
227
+ });
228
+ });
229
+ }
230
+ function Ae(e) {
231
+ return !!Ee(e) || !!Oe(e);
232
+ }
233
+ function je(e) {
234
+ let t = Ee(e);
235
+ if (t) {
236
+ let e = De(t);
237
+ if (e) {
238
+ if (e.scrollIntoView({
239
+ behavior: "smooth",
240
+ block: "center"
241
+ }), typeof e.focus == "function") try {
242
+ e.focus({ preventScroll: !0 });
243
+ } catch {
244
+ e.focus();
245
+ }
246
+ return !0;
247
+ }
248
+ return t.scrollIntoView({
249
+ behavior: "smooth",
250
+ block: "center"
251
+ }), !0;
252
+ }
253
+ let n = Oe(e);
254
+ return n ? (n.scrollIntoView({
255
+ behavior: "smooth",
256
+ block: "center"
257
+ }), !0) : !1;
258
+ }
259
+ //#endregion
260
+ //#region src/js/events/event-bus.ts
261
+ var Me = class {
262
+ constructor() {
263
+ this.listeners = /* @__PURE__ */ new Map();
264
+ }
265
+ on(e, t) {
266
+ return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e)?.add(t), () => {
267
+ this.listeners.get(e)?.delete(t);
268
+ };
269
+ }
270
+ async emit(e, t) {
271
+ let n = this.listeners.get(e);
272
+ if (!(!n || n.size === 0)) for (let e of n) await e(t);
273
+ }
274
+ async emitSafe(e, t) {
275
+ let n = this.listeners.get(e), r = {
276
+ eventName: e,
277
+ total: n?.size || 0,
278
+ succeeded: 0,
279
+ failed: []
280
+ };
281
+ if (!n || n.size === 0) return r;
282
+ let i = 0;
283
+ for (let e of n) {
284
+ try {
285
+ await e(t), r.succeeded += 1;
286
+ } catch (e) {
287
+ r.failed.push({
288
+ index: i,
289
+ error: e
290
+ });
291
+ }
292
+ i += 1;
293
+ }
294
+ return r;
295
+ }
296
+ async emitParallelSafe(e, t) {
297
+ let n = this.listeners.get(e), r = {
298
+ eventName: e,
299
+ total: n?.size || 0,
300
+ succeeded: 0,
301
+ failed: []
302
+ };
303
+ return !n || n.size === 0 || (await Promise.allSettled(Array.from(n).map(async (e) => e(t)))).forEach((e, t) => {
304
+ if (e.status === "fulfilled") {
305
+ r.succeeded += 1;
306
+ return;
307
+ }
308
+ r.failed.push({
309
+ index: t,
310
+ error: e.reason
311
+ });
312
+ }), r;
313
+ }
314
+ clear() {
315
+ this.listeners.clear();
316
+ }
317
+ }, k = d("general", "transport");
318
+ function Ne(e) {
319
+ let t = {};
320
+ return [
321
+ "theme",
322
+ "themeConfig",
323
+ "locale",
324
+ "siteId"
325
+ ].forEach((n) => {
326
+ e[n] !== void 0 && (t[n] = e[n]);
327
+ }), t;
328
+ }
329
+ function Pe(e, t = "", n = {}) {
330
+ if (Array.isArray(e)) {
331
+ let r = e.map((e) => typeof e == "string" ? e : String(e ?? "")).filter((e) => e.trim() !== "");
332
+ return t && r.length && (n[t] = (n[t] || []).concat(r)), n;
333
+ }
334
+ return e && typeof e == "object" && Object.entries(e).forEach(([e, r]) => {
335
+ Pe(r, t ? `${t}.${e}` : e, n);
336
+ }), n;
337
+ }
338
+ function Fe(e, t) {
339
+ let n = e.success === !0, r = e.keepSubmitLoading === !0, i = e.errors, a = Pe(i || {}), o = a.form || [], s = {};
340
+ Object.entries(a).forEach(([e, t]) => {
341
+ if (e === "form") return;
342
+ let n = e.split(".")[0];
343
+ s[n] = (s[n] || []).concat(t);
344
+ });
345
+ let c = !n && o.length === 0 && Object.keys(s).length > 0 ? [t || "Submission failed."] : o, l = !n && r && c.length === 0 && Object.keys(s).length === 0;
346
+ return {
347
+ ok: n,
348
+ action: e.submitAction === "back" || e.submitAction === "save" || e.submitAction === "submit" ? e.submitAction : void 0,
349
+ message: e.submitActionMessage || (n ? "Submission completed." : l ? "" : c[0] || "Submission failed."),
350
+ code: n ? void 0 : String(e.code || "SUBMIT_ERROR"),
351
+ keepSubmitLoading: r,
352
+ fieldErrors: Object.keys(s).length ? s : void 0,
353
+ formErrors: c.length ? c : void 0,
354
+ nextPage: e.nextPageId ? { id: String(e.nextPageId) } : null,
355
+ redirect: e.redirectUrl ? {
356
+ url: String(e.redirectUrl),
357
+ target: e.submitActionTab === "new-tab" ? "new-tab" : "same-tab"
358
+ } : null,
359
+ submitData: Array.isArray(e.submitData) ? e.submitData : void 0,
360
+ meta: e
361
+ };
362
+ }
363
+ async function Ie(e, t, n = {}) {
364
+ let r = JSON.stringify({
365
+ handle: t,
366
+ renderOptions: n
367
+ });
368
+ k.log("requestRender start.", {
369
+ endpoint: e,
370
+ handle: t
371
+ });
372
+ let i = await w(e, {
373
+ method: "POST",
374
+ body: r,
375
+ headers: { "Content-Type": "application/json" }
376
+ });
377
+ return k.log("requestRender complete.", { hasHtml: !!i.html }), i;
378
+ }
379
+ async function Le(e, t, n = {}) {
380
+ let r = JSON.stringify({
381
+ query: "\nquery FormieHtmlForm($handle: String!, $input: ServerRenderPayloadInput) {\n formieHtmlForm(handle: $handle, input: $input) {\n html\n }\n}",
382
+ variables: {
383
+ handle: t,
384
+ input: Ne(n)
385
+ }
386
+ });
387
+ k.log("requestGraphqlRender start.", {
388
+ endpoint: e,
389
+ handle: t
390
+ });
391
+ let i = await w(e, {
392
+ method: "POST",
393
+ body: r,
394
+ headers: { "Content-Type": "application/json" }
395
+ });
396
+ if (Array.isArray(i.errors) && i.errors.length > 0) throw Error(i.errors.map((e) => e.message || "Unknown GraphQL error").join("; "));
397
+ if (!i.data?.formieHtmlForm) throw Error(`Form not found for handle "${t}".`);
398
+ let a = i.data.formieHtmlForm;
399
+ return k.log("requestGraphqlRender complete.", { hasHtml: !!a.html }), a;
400
+ }
401
+ async function Re(e, t, n) {
402
+ let r = new URL(e, window.location.origin);
403
+ r.searchParams.set("handle", t), n && r.searchParams.set("renderId", n), k.log("requestRefreshTokens start.", {
404
+ endpoint: r.toString(),
405
+ handle: t,
406
+ hasRenderId: !!n
407
+ });
408
+ let i = await w(r.toString());
409
+ return k.log("requestRefreshTokens complete.", { hasRefreshTokens: !!i.refreshTokens }), i.refreshTokens || i;
410
+ }
411
+ async function ze(e, t, n) {
412
+ let r = new URL(e, window.location.origin), i = new FormData();
413
+ if (n && i.append("pageId", n), t) {
414
+ [
415
+ "handle",
416
+ "renderId",
417
+ "draftContextToken",
418
+ "draftContext",
419
+ "continuationToken"
420
+ ].forEach((e) => {
421
+ let n = t.querySelector(`input[name="${e}"]`)?.value?.trim();
422
+ n && i.append(e, n);
423
+ });
424
+ let e = t.querySelector("input[name=\"CRAFT_CSRF_TOKEN\"]")?.value?.trim();
425
+ e && i.append("CRAFT_CSRF_TOKEN", e);
426
+ }
427
+ k.log("requestSetPage start.", {
428
+ requestUrl: r.toString(),
429
+ pageId: n || null
430
+ });
431
+ let a = await w(r.toString(), {
432
+ method: "POST",
433
+ body: i
434
+ });
435
+ return k.log("requestSetPage complete.", a), a;
436
+ }
437
+ function Be(e, t) {
438
+ let n = new URL(e, window.location.origin), r = new FormData();
439
+ [
440
+ "handle",
441
+ "renderId",
442
+ "draftContextToken",
443
+ "draftContext"
444
+ ].forEach((e) => {
445
+ let n = t.querySelector(`input[name="${e}"]`)?.value?.trim();
446
+ n && r.append(e, n);
447
+ });
448
+ let i = t.querySelector("input[name=\"CRAFT_CSRF_TOKEN\"]")?.value?.trim();
449
+ i && r.append("CRAFT_CSRF_TOKEN", i), k.log("clearSubmissionOnUnload start.", { requestUrl: n.toString() });
450
+ try {
451
+ if (typeof navigator.sendBeacon == "function" && navigator.sendBeacon(n.toString(), r)) return;
452
+ } catch {}
453
+ fetch(n.toString(), {
454
+ method: "POST",
455
+ body: r,
456
+ credentials: "include",
457
+ keepalive: !0,
458
+ headers: { Accept: "application/json" }
459
+ });
460
+ }
461
+ async function Ve(e, t) {
462
+ let n = (e.getAttribute("method") || "POST").toUpperCase(), r = e.getAttribute("action") || window.location.href, i = e.dataset.formieErrorMessage?.trim() || "Submission failed.";
463
+ k.log("submitForm start.", {
464
+ method: n,
465
+ action: r,
466
+ submitAction: t.get("submitAction")
467
+ });
468
+ let a = await fetch(r, {
469
+ method: n,
470
+ body: t,
471
+ credentials: "include",
472
+ headers: { Accept: "application/json" }
473
+ }), o = a.headers.get("content-type") || "";
474
+ if (!o.includes("application/json")) return a.ok ? (k.log("submitForm non-JSON success response.", {
475
+ status: a.status,
476
+ contentType: o
477
+ }), {
478
+ ok: !0,
479
+ message: "Submission completed."
480
+ }) : (k.warn("submitForm non-JSON HTTP error.", {
481
+ status: a.status,
482
+ contentType: o
483
+ }), {
484
+ ok: !1,
485
+ code: "HTTP_ERROR",
486
+ message: `Request failed (${a.status}).`,
487
+ formErrors: [`Request failed (${a.status}).`]
488
+ });
489
+ let s = Fe(await a.json(), i);
490
+ return k.log("submitForm JSON response normalized.", {
491
+ ok: s.ok,
492
+ code: s.code,
493
+ hasRedirect: !!s.redirect?.url,
494
+ hasSubmitData: Array.isArray(s.submitData) && s.submitData.length > 0
495
+ }), s;
496
+ }
497
+ //#endregion
498
+ //#region src/js/submit/pipeline.ts
499
+ var He = [
500
+ "prepare",
501
+ "normalize",
502
+ "validate",
503
+ "screen",
504
+ "authorize",
505
+ "dispatch",
506
+ "finalize"
507
+ ], Ue = [
508
+ "prepare",
509
+ "normalize",
510
+ "validate",
511
+ "screen",
512
+ "authorize"
513
+ ], A = d("general", "pipeline");
514
+ function We(e, t) {
515
+ return {
516
+ ok: !1,
517
+ stage: e,
518
+ code: "ABORTED",
519
+ message: t || "Submission aborted.",
520
+ formErrors: [t || "Submission aborted."]
521
+ };
522
+ }
523
+ function Ge(e) {
524
+ return e instanceof HTMLInputElement || e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement;
525
+ }
526
+ function Ke(e) {
527
+ return !(!e.name || e.disabled || e instanceof HTMLInputElement && (e.type === "submit" || e.type === "button" || e.type === "reset" || e.type === "image" || (e.type === "checkbox" || e.type === "radio") && !e.checked || e.type === "file" && (!e.files || e.files.length === 0)));
528
+ }
529
+ function qe(e, t) {
530
+ if (t instanceof HTMLInputElement) {
531
+ if (t.type === "file") {
532
+ Array.from(t.files || []).forEach((n) => {
533
+ e.append(t.name, n);
534
+ });
535
+ return;
536
+ }
537
+ e.append(t.name, t.value);
538
+ return;
539
+ }
540
+ if (t instanceof HTMLSelectElement && t.multiple) {
541
+ Array.from(t.selectedOptions).forEach((n) => {
542
+ e.append(t.name, n.value);
543
+ });
544
+ return;
545
+ }
546
+ e.append(t.name, t.value);
547
+ }
548
+ function Je(e, t) {
549
+ t.querySelectorAll("input, select, textarea").forEach((t) => {
550
+ let n = Ge(t) ? t : null;
551
+ !n || n.closest("[data-formie-page]") || Ke(n) && qe(e, n);
552
+ });
553
+ }
554
+ function Ye(e, t) {
555
+ let n = /* @__PURE__ */ new Set();
556
+ return t.querySelectorAll("input, select, textarea").forEach((t) => {
557
+ let r = Ge(t) ? t : null;
558
+ !r || !r.name || r.disabled || r instanceof HTMLInputElement && (r.type === "submit" || r.type === "button" || r.type === "reset" || r.type === "image") || (r.name.startsWith("fields[") && n.add(r.name), Ke(r) && qe(e, r));
559
+ }), n;
560
+ }
561
+ function Xe(e, t) {
562
+ t.forEach((t) => {
563
+ e.has(t) || e.append(t, "");
564
+ });
565
+ }
566
+ function Ze(e, t) {
567
+ let n = p(e), r = n.find((e) => !e.hasAttribute("data-formie-page-hidden")) || null;
568
+ if (!n.length || !r) {
569
+ let n = new FormData(e);
570
+ return n.set("submitAction", t), n;
571
+ }
572
+ let i = new FormData();
573
+ return Je(i, e), Xe(i, Ye(i, r)), i.set("submitAction", t), i;
574
+ }
575
+ function Qe(e, t) {
576
+ if (t !== "submit") return !1;
577
+ let n = p(e);
578
+ return n.length ? (n.find((e) => !e.hasAttribute("data-formie-page-hidden")) || n[n.length - 1]) === n[n.length - 1] : !0;
579
+ }
580
+ async function $e(e, t, n, r = {}) {
581
+ A.log("Starting submit pipeline.", {
582
+ action: t,
583
+ preflightOnly: r.preflightOnly === !0
584
+ });
585
+ let i = !1, a, o = null, s = Qe(e, t), c = {
586
+ form: e,
587
+ action: t,
588
+ formData: Ze(e, t),
589
+ abort: (e) => {
590
+ i = !0, a = e, A.warn("Pipeline aborted.", { reason: e });
591
+ },
592
+ isAborted: () => i,
593
+ abortReason: () => a
594
+ }, l = {
595
+ prepare: async (e) => {
596
+ let t = e.form.querySelector("input[name=\"submitAction\"]");
597
+ return t && (t.value = e.action), e.formData.set("submitAction", e.action), null;
598
+ },
599
+ normalize: async () => null,
600
+ validate: async (e) => {
601
+ if (e.action !== "submit" || r.validateOnSubmit === !1) return null;
602
+ if (r.validator) {
603
+ let { scope: t, final: n } = h(e.form), i = r.validator.submit(n ? e.form : t, { final: n });
604
+ if (i.length > 0) {
605
+ let e = i[0]?.input;
606
+ if (e) {
607
+ e.scrollIntoView({
608
+ behavior: "smooth",
609
+ block: "center"
610
+ });
611
+ try {
612
+ e.focus({ preventScroll: !0 });
613
+ } catch {
614
+ e.focus();
615
+ }
616
+ }
617
+ return {
618
+ ok: !1,
619
+ stage: "validate",
620
+ code: "VALIDATION_FAILED",
621
+ message: r.validator.config.errorMessage || "Validation failed.",
622
+ fieldErrors: r.validator.getFieldErrors(i),
623
+ formErrors: [r.validator.config.errorMessage || "Validation failed."]
624
+ };
625
+ }
626
+ return null;
627
+ }
628
+ return e.form.checkValidity() ? null : (e.form.querySelector(":invalid")?.focus(), {
629
+ ok: !1,
630
+ stage: "validate",
631
+ code: "VALIDATION_FAILED",
632
+ message: "Validation failed.",
633
+ formErrors: ["Validation failed."]
634
+ });
635
+ },
636
+ screen: async () => null,
637
+ authorize: async () => null,
638
+ dispatch: async (e) => {
639
+ e.formData = Ze(e.form, e.action);
640
+ let t = await Ve(e.form, e.formData);
641
+ return o = t, t;
642
+ },
643
+ finalize: async (e) => (o && o.ok && o.redirect?.url && (o.redirect.target === "new-tab" ? window.open(o.redirect.url, "_blank") : window.location.href = o.redirect.url), null)
644
+ };
645
+ {
646
+ let e = await n.emitSafe("formie:submit:before", c);
647
+ e.failed.length > 0 && A.warn("Submit before listeners failed.", {
648
+ eventName: e.eventName,
649
+ failed: e.failed.length
650
+ });
651
+ }
652
+ if (s) {
653
+ let e = await n.emitSafe("formie:submit:final:before", c);
654
+ e.failed.length > 0 && A.warn("Final submit before listeners failed.", {
655
+ eventName: e.eventName,
656
+ failed: e.failed.length
657
+ });
658
+ }
659
+ let u = r.preflightOnly ? Ue : He;
660
+ for (let e of u) {
661
+ if (A.log("Stage start.", {
662
+ stage: e,
663
+ action: t
664
+ }), i) return A.warn("Stage skipped due to abort.", {
665
+ stage: e,
666
+ reason: a
667
+ }), We(e, a);
668
+ {
669
+ let t = await n.emitSafe(`formie:stage:${e}:before`, {
670
+ ...c,
671
+ stage: e
672
+ });
673
+ t.failed.length > 0 && A.warn("Stage before listeners failed.", {
674
+ stage: e,
675
+ failed: t.failed.length
676
+ });
677
+ }
678
+ if (i) {
679
+ let t = We(e, a);
680
+ {
681
+ let r = await n.emitSafe("formie:submit:after", t);
682
+ r.failed.length > 0 && A.warn("Submit after listeners failed (abort before stage).", {
683
+ stage: e,
684
+ failed: r.failed.length
685
+ });
686
+ }
687
+ if (s) {
688
+ let r = await n.emitSafe("formie:submit:final:after", t);
689
+ r.failed.length > 0 && A.warn("Final submit after listeners failed (abort before stage).", {
690
+ stage: e,
691
+ failed: r.failed.length
692
+ });
693
+ }
694
+ return A.warn("Aborted after stage before-hooks.", {
695
+ stage: e,
696
+ reason: a
697
+ }), t;
698
+ }
699
+ let r = await l[e](c);
700
+ A.log("Stage runner complete.", {
701
+ stage: e,
702
+ hasResult: !!r,
703
+ ok: r ? r.ok : void 0,
704
+ code: r?.code
705
+ });
706
+ {
707
+ let t = await n.emitSafe(`formie:stage:${e}:after`, {
708
+ ...c,
709
+ stage: e,
710
+ result: r
711
+ });
712
+ t.failed.length > 0 && A.warn("Stage after listeners failed.", {
713
+ stage: e,
714
+ failed: t.failed.length
715
+ });
716
+ }
717
+ if (i) {
718
+ let t = We(e, a);
719
+ {
720
+ let r = await n.emitSafe("formie:submit:after", t);
721
+ r.failed.length > 0 && A.warn("Submit after listeners failed (abort after stage).", {
722
+ stage: e,
723
+ failed: r.failed.length
724
+ });
725
+ }
726
+ if (s) {
727
+ let r = await n.emitSafe("formie:submit:final:after", t);
728
+ r.failed.length > 0 && A.warn("Final submit after listeners failed (abort after stage).", {
729
+ stage: e,
730
+ failed: r.failed.length
731
+ });
732
+ }
733
+ return A.warn("Aborted after stage after-hooks.", {
734
+ stage: e,
735
+ reason: a
736
+ }), t;
737
+ }
738
+ if (r && !r.ok) {
739
+ {
740
+ let t = await n.emitSafe("formie:submit:after", r);
741
+ t.failed.length > 0 && A.warn("Submit after listeners failed (failed stage).", {
742
+ stage: e,
743
+ failed: t.failed.length
744
+ });
745
+ }
746
+ if (s) {
747
+ let t = await n.emitSafe("formie:submit:final:after", r);
748
+ t.failed.length > 0 && A.warn("Final submit after listeners failed (failed stage).", {
749
+ stage: e,
750
+ failed: t.failed.length
751
+ });
752
+ }
753
+ return A.warn("Pipeline short-circuited by failed stage.", {
754
+ stage: e,
755
+ code: r.code,
756
+ message: r.message
757
+ }), r;
758
+ }
759
+ }
760
+ let d = o || {
761
+ ok: !0,
762
+ stage: r.preflightOnly ? "authorize" : "finalize",
763
+ message: r.preflightOnly ? "Submission preflight completed." : "Submission completed."
764
+ };
765
+ {
766
+ let e = await n.emitSafe("formie:submit:after", d);
767
+ e.failed.length > 0 && A.warn("Submit after listeners failed (success).", { failed: e.failed.length });
768
+ }
769
+ if (s) {
770
+ let e = await n.emitSafe("formie:submit:final:after", d);
771
+ e.failed.length > 0 && A.warn("Final submit after listeners failed (success).", { failed: e.failed.length });
772
+ }
773
+ return A.log("Pipeline completed.", {
774
+ ok: d.ok,
775
+ stage: d.stage,
776
+ code: d.code
777
+ }), d;
778
+ }
779
+ //#endregion
780
+ //#region src/js/core/field-error-container.ts
781
+ function et(e) {
782
+ return e.querySelector("[data-formie-field-layout]")?.getAttribute("data-formie-error-position")?.trim() === "above" ? "above" : "below";
783
+ }
784
+ function tt(e, t) {
785
+ let n = e.querySelector("[data-formie-field-errors]");
786
+ if (n) return n;
787
+ let r = e.querySelector("[data-formie-field-content]"), i = e.querySelector("[data-formie-field-control]"), a = et(e), o = document.createElement("div");
788
+ return o.setAttribute("data-formie-field-errors", "true"), t?.(o), r && i ? a === "above" ? r.insertBefore(o, i) : r.appendChild(o) : e.appendChild(o), o;
789
+ }
790
+ //#endregion
791
+ //#region src/js/validation/rules/email.ts
792
+ var nt = {
793
+ rule: ({ input: e, getRule: t }) => !t("email") || !e.value || e.value.length < 1 ? !0 : /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.value),
794
+ message: ({ input: e, label: t, t: n }) => e.getAttribute("data-formie-validation-email-message") ?? e.getAttribute("data-formie-pattern-email-message") ?? e.getAttribute("data-pattern-email-message") ?? n("{label} is not a valid email address.", { label: t })
40
795
  };
796
+ //#endregion
797
+ //#region src/js/validation/rules/shared.ts
798
+ function rt(e) {
799
+ return e?.querySelector("[data-formie-field-label]")?.childNodes[0]?.textContent?.trim() || "";
800
+ }
801
+ function it(e) {
802
+ let t = e.getRule("match");
803
+ if (!t || t === !0 || typeof t != "object" || !e.field) return null;
804
+ let n = typeof t.fieldHandle == "string" ? t.fieldHandle.trim() : "";
805
+ if (!n) return null;
806
+ let r = e.form.querySelector(`[data-formie-field-handle="${n}"]`);
807
+ return r ? r.querySelector(e.config.fieldsSelector) : null;
808
+ }
809
+ //#endregion
810
+ //#region src/js/validation/rules.ts
811
+ var at = {
812
+ required: {
813
+ rule: ({ input: e, getRule: t }) => {
814
+ if (!t("required") || e.type === "hidden") return !0;
815
+ if (e.type === "checkbox" || e.type === "radio") {
816
+ let t = e.form?.querySelectorAll(`[name="${e.name}"]:not([type="hidden"]):not([disabled])`) || [];
817
+ return t.length ? Array.from(t).some((e) => e instanceof HTMLInputElement && e.checked) : e instanceof HTMLInputElement ? e.checked : !0;
818
+ }
819
+ return e.value.trim() !== "";
820
+ },
821
+ message: ({ input: e, label: t, t: n }) => e.getAttribute("data-formie-required-message") ?? e.getAttribute("data-required-message") ?? n("{label} cannot be blank.", { label: t })
822
+ },
823
+ email: nt,
824
+ url: {
825
+ rule: ({ input: e, getRule: t }) => {
826
+ if (!t("url") || !e.value || e.value.length < 1) return !0;
827
+ try {
828
+ return new URL(e.value), !0;
829
+ } catch {
830
+ return !1;
831
+ }
832
+ },
833
+ message: ({ input: e, label: t, t: n }) => e.getAttribute("data-formie-pattern-url-message") ?? e.getAttribute("data-pattern-url-message") ?? n("{label} is not a valid URL.", { label: t })
834
+ },
835
+ number: {
836
+ rule: ({ input: e, getRule: t }) => {
837
+ let n = t("number");
838
+ if (!n || !e.value || e.value.trim() === "") return !0;
839
+ let r = parseFloat(e.value);
840
+ if (Number.isNaN(r)) return !1;
841
+ if (n !== !0 && typeof n == "object") {
842
+ let e = typeof n.min == "number" ? n.min : null, t = typeof n.max == "number" ? n.max : null;
843
+ if (e !== null && r < e || t !== null && r > t) return !1;
844
+ }
845
+ return !0;
846
+ },
847
+ message: ({ input: e, label: t, getRule: n, t: r }) => {
848
+ let i = n("number"), a = i !== !0 && i && typeof i == "object" && typeof i.min == "number" ? i.min : null, o = i !== !0 && i && typeof i == "object" && typeof i.max == "number" ? i.max : null;
849
+ return a !== null && o !== null ? e.getAttribute("data-formie-validation-number-min-message") ?? r("{label} must be between {min} and {max}.", {
850
+ label: t,
851
+ min: a,
852
+ max: o
853
+ }) : a === null ? o === null ? e.getAttribute("data-formie-validation-number-message") ?? e.getAttribute("data-formie-pattern-number-message") ?? e.getAttribute("data-pattern-number-message") ?? r("{label} is not a valid number.", { label: t }) : e.getAttribute("data-formie-validation-number-max-message") ?? r("{label} must be no greater than {max}.", {
854
+ label: t,
855
+ max: o
856
+ }) : e.getAttribute("data-formie-validation-number-min-message") ?? r("{label} must be no less than {min}.", {
857
+ label: t,
858
+ min: a
859
+ });
860
+ }
861
+ },
862
+ match: {
863
+ rule: (e) => {
864
+ let t = it(e);
865
+ return t ? t.value === e.input.value : !0;
866
+ },
867
+ message: (e) => {
868
+ let t = it(e)?.closest("[data-formie-field-handle]"), n = rt(t);
869
+ return e.t("{label} must match {value}.", {
870
+ label: e.label,
871
+ value: n
872
+ });
873
+ }
874
+ }
875
+ }, ot = {
876
+ email: /^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*(\.\w{2,})+$/,
877
+ url: /^(?:(?:https?|HTTPS?|ftp|FTP):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)(?:\.(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)*(?:\.(?:[a-zA-Z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/,
878
+ number: /^(?:[-+]?[0-9]*[.,]?[0-9]+)$/,
879
+ color: /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/,
880
+ date: /(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))/,
881
+ time: /^(?:(0[0-9]|1[0-9]|2[0-3])(:[0-5][0-9]))$/,
882
+ month: /^(?:(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])))$/
883
+ }, j = d("general", "validator");
884
+ function M(e) {
885
+ return !!e && (e instanceof HTMLInputElement || e instanceof HTMLSelectElement || e instanceof HTMLTextAreaElement);
886
+ }
887
+ function st(e, t) {
888
+ let n = (e.getAttribute("aria-describedby") || "").trim();
889
+ if (!n) return;
890
+ let r = n.split(/\s+/).filter((e) => e !== t);
891
+ if (r.length) {
892
+ e.setAttribute("aria-describedby", r.join(" "));
893
+ return;
894
+ }
895
+ e.removeAttribute("aria-describedby");
896
+ }
897
+ function ct(e, t) {
898
+ let n = (e.getAttribute("aria-describedby") || "").trim(), r = n ? n.split(/\s+/) : [];
899
+ r.includes(t) || r.push(t), e.setAttribute("aria-describedby", r.join(" ").trim());
900
+ }
901
+ function lt(e, t) {
902
+ e.setAttribute("aria-errormessage", t);
903
+ }
904
+ function ut(e, t) {
905
+ e.getAttribute("aria-errormessage") === t && e.removeAttribute("aria-errormessage");
906
+ }
907
+ var dt = class {
908
+ constructor(e, t = {}) {
909
+ this.errors = [], this.validators = {}, this.boundListeners = !1, this.activated = /* @__PURE__ */ new WeakSet(), this.submitted = !1, this.initialValues = /* @__PURE__ */ new WeakMap(), this.form = e, this.onBlur = this.blurHandler.bind(this), this.onChange = this.changeHandler.bind(this), this.onInput = this.inputHandler.bind(this), this.config = {
910
+ live: !1,
911
+ errorMessage: "",
912
+ fieldContainerErrorClass: [],
913
+ inputErrorClass: [],
914
+ messagesClass: [],
915
+ messageClass: [],
916
+ fieldsSelector: "input:not([type=\"hidden\"]):not([type=\"submit\"]):not([type=\"button\"]):not([disabled]), select:not([disabled]), textarea:not([disabled])",
917
+ patterns: ot,
918
+ ...t
919
+ }, Object.entries(at).forEach(([e, t]) => {
920
+ this.addValidator(e, t.rule, t.message);
921
+ }), this.init();
922
+ }
923
+ init() {
924
+ j.log("Initializing validator.", {
925
+ formId: this.form.id || null,
926
+ live: this.config.live
927
+ }), this.form.setAttribute("novalidate", "true"), this.inputs().forEach((e) => {
928
+ this.initialValues.set(e, this.getInputValue(e));
929
+ }), this.config.live && this.addEventListeners(), this.emitEvent(document, n("ready"), { validator: this });
930
+ }
931
+ inputs(e = null) {
932
+ if (M(e)) return [e];
933
+ let t = e || this.form;
934
+ return Array.from(t.querySelectorAll(this.config.fieldsSelector)).filter((e) => M(e));
935
+ }
936
+ getInputValue(e) {
937
+ return e instanceof HTMLInputElement && (e.type === "checkbox" || e.type === "radio") ? e.checked : e instanceof HTMLInputElement && e.type === "file" ? e.files?.length ? Array.from(e.files).map((e) => e.name).join("|") : "" : e.value ?? "";
938
+ }
939
+ isDirty(e) {
940
+ return this.initialValues.has(e) ? this.getInputValue(e) !== this.initialValues.get(e) : (this.initialValues.set(e, this.getInputValue(e)), !1);
941
+ }
942
+ shouldShowError(e) {
943
+ return this.submitted || this.activated.has(e);
944
+ }
945
+ isValid(e = null, t = {}) {
946
+ return this.validate(e, t).length === 0;
947
+ }
948
+ validate(e = null, t = {}) {
949
+ this.errors = [];
950
+ let n = /* @__PURE__ */ new Set();
951
+ return this.inputs(e).forEach((e) => {
952
+ let r = !1;
953
+ if (!this.isVisible(e, t)) return;
954
+ let i = e.closest("[data-formie-field-handle]"), a = e instanceof HTMLInputElement && (e.type === "checkbox" || e.type === "radio") ? `${i?.getAttribute("data-formie-field-handle") || ""}:${e.name}` : null;
955
+ if (a) {
956
+ if (n.has(a)) return;
957
+ n.add(a);
958
+ }
959
+ this.shouldShowError(e) && this.removeError(e);
960
+ let o = this.getValidatorCallbackOptions(e);
961
+ Object.entries(this.validators).forEach(([t, n]) => {
962
+ if (!n.validate(o)) {
963
+ let i = this.getErrorMessage(e, t, n, o);
964
+ this.shouldShowError(e) && !r && this.showError(e, t, i), this.errors.push({
965
+ input: e,
966
+ field: o.field,
967
+ validator: t,
968
+ message: i,
969
+ handle: o.field?.getAttribute("data-formie-field-handle") || null,
970
+ result: !1
971
+ }), r = !0;
972
+ }
973
+ }), !r && this.shouldShowError(e) && this.removeError(e);
974
+ }), j.log("Validation pass complete.", {
975
+ errorCount: this.errors.length,
976
+ includeHiddenPages: t.includeHiddenPages === !0
977
+ }), this.errors;
978
+ }
979
+ removeAllErrors() {
980
+ this.inputs().forEach((e) => {
981
+ this.removeError(e);
982
+ });
983
+ }
984
+ removeError(e) {
985
+ let t = e.closest("[data-formie-field-handle]");
986
+ if (!t) {
987
+ e.removeAttribute("aria-invalid");
988
+ return;
989
+ }
990
+ let r = t.querySelector("[data-formie-field-errors]"), i = r?.id || "";
991
+ t.querySelectorAll("[data-formie-field-error]").forEach((e) => {
992
+ e.remove();
993
+ }), r && (r.innerHTML = ""), t.querySelectorAll("input, select, textarea").forEach((e) => {
994
+ let n = e;
995
+ n.removeAttribute("aria-invalid"), this.config.inputErrorClass.length && n.classList.remove(...this.config.inputErrorClass), n.removeAttribute("data-formie-input-has-error"), i && st(n, i), t.querySelectorAll("[data-formie-field-error]").forEach((e) => {
996
+ let t = e.id;
997
+ t && ut(n, t);
998
+ });
999
+ });
1000
+ for (let e = t; e; e = e.parentElement?.closest("[data-formie-field-handle]")) this.config.fieldContainerErrorClass.length && e.classList.remove(...this.config.fieldContainerErrorClass), e.removeAttribute("data-formie-field-has-error");
1001
+ this.emitEvent(e, n("clear-error"), { validator: this }), x(this.form);
1002
+ }
1003
+ showError(e, t, r) {
1004
+ let i = e.closest("[data-formie-field-handle]");
1005
+ if (!i) return;
1006
+ let a = i.querySelector("[data-formie-field-errors]");
1007
+ a ||= tt(i, (e) => {
1008
+ this.config.messagesClass.length && e.classList.add(...this.config.messagesClass);
1009
+ }), this.config.messagesClass.length && a.classList.add(...this.config.messagesClass), a.innerHTML = "";
1010
+ let o = i.getAttribute("data-formie-field-handle") || "field", s = `${o}-error`;
1011
+ a.id = a.id || `${o}-errors`, a.setAttribute("aria-live", "polite"), a.setAttribute("aria-atomic", "true");
1012
+ let c = document.createElement("div");
1013
+ c.setAttribute("data-formie-field-error", "true"), c.setAttribute(`data-formie-field-error-${t}`, "true"), c.setAttribute("id", s), c.setAttribute("role", "alert"), this.config.messageClass.length && c.classList.add(...this.config.messageClass), c.textContent = r, a.appendChild(c), i.setAttribute("data-formie-field-has-error", "true"), i.querySelectorAll("input, select, textarea").forEach((e) => {
1014
+ let t = e;
1015
+ t.setAttribute("aria-invalid", "true"), this.config.inputErrorClass.length && t.classList.add(...this.config.inputErrorClass), t.setAttribute("data-formie-input-has-error", "true"), ct(t, a.id), lt(t, s);
1016
+ });
1017
+ for (let e = i; e; e = e.parentElement?.closest("[data-formie-field-handle]")) this.config.fieldContainerErrorClass.length && e.classList.add(...this.config.fieldContainerErrorClass), e.setAttribute("data-formie-field-has-error", "true");
1018
+ this.emitEvent(e, n("show-error"), {
1019
+ validator: this,
1020
+ validatorName: t,
1021
+ errorMessage: r
1022
+ }), x(this.form);
1023
+ }
1024
+ getValidatorCallbackOptions(e) {
1025
+ let t = e.closest("[data-formie-field-handle]"), n = t?.querySelector("[data-formie-field-label]")?.childNodes[0]?.textContent?.trim() ?? "", r = this.parseValidationRules(t?.getAttribute("data-formie-validation"));
1026
+ return {
1027
+ t: E,
1028
+ input: e,
1029
+ label: n,
1030
+ field: t,
1031
+ form: this.form,
1032
+ config: this.config,
1033
+ rules: r,
1034
+ getRule: (e) => this.getRule(t, e)
1035
+ };
1036
+ }
1037
+ getErrorMessage(e, t, n, r) {
1038
+ return (typeof n.errorMessage == "function" ? n.errorMessage(r) : n.errorMessage) ?? E("{label} is invalid.", { label: r.label });
1039
+ }
1040
+ getErrors() {
1041
+ return this.errors;
1042
+ }
1043
+ getFieldErrors(e = this.errors) {
1044
+ let t = {};
1045
+ return e.forEach((e) => {
1046
+ !e.handle || t[e.handle]?.length || (t[e.handle] = [e.message]);
1047
+ }), t;
1048
+ }
1049
+ getRule(e, t) {
1050
+ if (!e) return !1;
1051
+ let n = this.parseValidationRules(e.getAttribute("data-formie-validation"));
1052
+ return Object.prototype.hasOwnProperty.call(n, t) ? n[t] : !1;
1053
+ }
1054
+ parseValidationRules(e) {
1055
+ let t = {};
1056
+ if (!e) return t;
1057
+ let n = null;
1058
+ try {
1059
+ n = JSON.parse(e);
1060
+ } catch {
1061
+ return j.warn("Invalid validation rules payload.", { formId: this.form.id || null }), t;
1062
+ }
1063
+ return Array.isArray(n) && n.forEach((e) => {
1064
+ if (!e || typeof e != "object" || Array.isArray(e)) return;
1065
+ let n = e, r = typeof n.type == "string" ? n.type.trim() : "";
1066
+ r && (t[r] = n);
1067
+ }), t;
1068
+ }
1069
+ destroy() {
1070
+ j.log("Destroying validator.", { formId: this.form.id || null }), this.removeEventListeners(), this.form.removeAttribute("novalidate"), this.emitEvent(document, n("destroy"), { validator: this });
1071
+ }
1072
+ isVisible(e, t = {}) {
1073
+ return e.closest("[data-formie-conditionally-hidden]") ? !1 : e.closest("[data-formie-page-hidden]") ? !!t.includeHiddenPages : !!(e.offsetWidth || e.offsetHeight || e.getClientRects().length);
1074
+ }
1075
+ blurHandler(e) {
1076
+ !(e.target instanceof HTMLElement) || !M(e.target) || !e.target.form?.isSameNode(this.form) || e instanceof CustomEvent || e.target instanceof HTMLInputElement && e.target.type === "file" || e.target instanceof HTMLInputElement && (e.target.type === "checkbox" || e.target.type === "radio") || (this.isDirty(e.target) && this.activated.add(e.target), this.shouldShowError(e.target) && this.validate(e.target));
1077
+ }
1078
+ changeHandler(e) {
1079
+ if (!(!(e.target instanceof HTMLElement) || !M(e.target) || !e.target.form?.isSameNode(this.form)) && !(e instanceof CustomEvent)) {
1080
+ if (e.target instanceof HTMLSelectElement) {
1081
+ this.activated.add(e.target), this.validate(e.target);
1082
+ return;
1083
+ }
1084
+ e.target instanceof HTMLInputElement && (e.target.type !== "file" && e.target.type !== "checkbox" && e.target.type !== "radio" || (this.activated.add(e.target), this.validate(e.target)));
1085
+ }
1086
+ }
1087
+ inputHandler(e) {
1088
+ !(e.target instanceof HTMLElement) || !M(e.target) || !e.target.form?.isSameNode(this.form) || e instanceof CustomEvent || e.target instanceof HTMLInputElement && (e.target.type === "checkbox" || e.target.type === "radio") || this.shouldShowError(e.target) && this.validate(e.target);
1089
+ }
1090
+ submit(e = null, { final: t = !1 } = {}) {
1091
+ return this.submitted = !0, j.log("Submit validation requested.", { final: t }), this.boundListeners || this.addEventListeners(), this.removeAllErrors(), this.validate(e, { includeHiddenPages: t });
1092
+ }
1093
+ resetLiveState() {
1094
+ this.submitted = !1, this.activated = /* @__PURE__ */ new WeakSet(), this.errors = [], this.removeAllErrors();
1095
+ }
1096
+ addEventListeners() {
1097
+ this.boundListeners || (this.form.addEventListener("blur", this.onBlur, !0), this.form.addEventListener("change", this.onChange, !1), this.form.addEventListener("input", this.onInput, !1), this.boundListeners = !0, j.log("Event listeners attached."));
1098
+ }
1099
+ removeEventListeners() {
1100
+ this.form.removeEventListener("blur", this.onBlur, !0), this.form.removeEventListener("change", this.onChange, !1), this.form.removeEventListener("input", this.onInput, !1), this.boundListeners = !1, j.log("Event listeners removed.");
1101
+ }
1102
+ emitEvent(e, t, n = {}) {
1103
+ e.dispatchEvent(new CustomEvent(t, {
1104
+ bubbles: !0,
1105
+ detail: n
1106
+ }));
1107
+ }
1108
+ addValidator(e, t, n) {
1109
+ this.validators[e] = {
1110
+ validate: t,
1111
+ errorMessage: n
1112
+ };
1113
+ }
1114
+ removeValidator(e) {
1115
+ delete this.validators[e];
1116
+ }
1117
+ }, N = /* @__PURE__ */ new WeakMap();
1118
+ function ft(e) {
1119
+ return (e.dataset.formieSubmitAction || "").trim();
1120
+ }
1121
+ function pt(e) {
1122
+ return (e.dataset.formieErrorMessagePosition || "top-form").trim() || "top-form";
1123
+ }
1124
+ function mt(e) {
1125
+ return (e.dataset.formieSubmitActionMessagePosition || "").trim();
1126
+ }
1127
+ function ht(e) {
1128
+ let t = (e.dataset.formieSubmitActionMessageTimeout || "").trim();
1129
+ if (!t) return null;
1130
+ let n = Number.parseFloat(t);
1131
+ return !Number.isFinite(n) || n < 0 ? null : Math.round(n * 1e3);
1132
+ }
1133
+ function P(e) {
1134
+ let t = e.dataset.formieSubmitActionFormHide;
1135
+ if (t === void 0) return !1;
1136
+ let n = t.trim().toLowerCase();
1137
+ return n === "true" || n === "1" || n === "";
1138
+ }
1139
+ function gt(e) {
1140
+ let t = N.get(e);
1141
+ typeof t == "number" && (window.clearTimeout(t), N.delete(e));
1142
+ }
1143
+ function _t(e) {
1144
+ return e.querySelector("[data-formie-form-messages-top]") || e;
1145
+ }
1146
+ function vt(e) {
1147
+ return e.querySelector("[data-formie-form-messages-bottom]") || e;
1148
+ }
1149
+ function yt(e, t) {
1150
+ return t === "bottom-form" ? vt(e) : _t(e);
1151
+ }
1152
+ function bt(e, t) {
1153
+ return t === "top-form" ? _t(e) : t === "bottom-form" && !P(e) ? vt(e) : e;
1154
+ }
1155
+ function xt(e) {
1156
+ let t = pt(e), n = yt(e, t), r = n.querySelector("[data-formie-error-container], [data-formie-errors]");
1157
+ return r || (r = document.createElement("div"), r.setAttribute("data-formie-errors", "true"), C(r, e, "errors")), r.setAttribute("data-formie-error-container", "true"), t === "bottom-form" ? n.append(r) : n.prepend(r), r;
1158
+ }
1159
+ function St(e, t) {
1160
+ let n = t.querySelector("[data-formie-error-message-container], [data-formie-message][data-formie-message-error]");
1161
+ return n || (n = document.createElement("div"), n.setAttribute("data-formie-error-message-container", "true"), t.appendChild(n)), n.setAttribute("data-formie-message", "true"), n.setAttribute("data-formie-message-error", "true"), C(n, e, "message", "messageError"), n.setAttribute("role", "alert"), n.setAttribute("aria-live", "polite"), n.setAttribute("aria-atomic", "true"), n;
1162
+ }
1163
+ function Ct(e, t) {
1164
+ let n = e.querySelector("[data-formie-success-container]"), r = bt(e, t);
1165
+ return n || (n = document.createElement("div"), n.setAttribute("data-formie-success-container", "true"), C(n, e, "successes")), t === "bottom-form" ? r.append(n) : r.prepend(n), n;
1166
+ }
1167
+ function wt(e) {
1168
+ return tt(e, (t) => {
1169
+ C(t, e, "fieldErrors");
1170
+ });
1171
+ }
1172
+ function Tt(e, t) {
1173
+ let n = (e.getAttribute("aria-describedby") || "").trim();
1174
+ if (!n) return;
1175
+ let r = n.split(/\s+/).filter((e) => e !== t).join(" ").trim();
1176
+ if (r) {
1177
+ e.setAttribute("aria-describedby", r);
1178
+ return;
1179
+ }
1180
+ e.removeAttribute("aria-describedby");
1181
+ }
1182
+ function Et(e, t) {
1183
+ e.setAttribute("aria-errormessage", t);
1184
+ }
1185
+ function Dt(e, t) {
1186
+ e.getAttribute("aria-errormessage") === t && e.removeAttribute("aria-errormessage");
1187
+ }
1188
+ function Ot(e) {
1189
+ e.querySelectorAll("[data-formie-field-handle]").forEach((t) => {
1190
+ let n = t, r = n.querySelector("[data-formie-field-errors]"), i = r?.id || "", a = Array.from(n.querySelectorAll("[data-formie-field-error]")).map((e) => e.id).filter(Boolean);
1191
+ S(n, e, "fieldLayoutError"), n.removeAttribute("data-formie-field-has-error"), n.querySelectorAll("[data-formie-field-error]").forEach((e) => {
1192
+ e.remove();
1193
+ }), r && !r.querySelector("[data-formie-field-error]") && (r.innerHTML = ""), n.querySelectorAll("input, select, textarea").forEach((t) => {
1194
+ let n = t;
1195
+ n.removeAttribute("aria-invalid"), S(n, e, "fieldControlError"), n.removeAttribute("data-formie-input-has-error"), i && Tt(n, i), a.forEach((e) => {
1196
+ Dt(n, e);
1197
+ });
1198
+ });
1199
+ }), x(e);
1200
+ }
1201
+ function kt(e) {
1202
+ e.querySelectorAll("[data-formie-error-container], [data-formie-errors]").forEach((t) => {
1203
+ let n = t;
1204
+ n.querySelectorAll("[data-formie-error]").forEach((e) => {
1205
+ e.remove();
1206
+ }), S(n, e, "message", "messageError"), n.removeAttribute("data-formie-message"), n.removeAttribute("data-formie-message-error"), n.removeAttribute("role"), n.removeAttribute("aria-live"), n.removeAttribute("aria-atomic"), n.querySelector("[data-formie-error]") || (n.innerHTML = "");
1207
+ });
1208
+ }
1209
+ function F(e) {
1210
+ gt(e), e.querySelectorAll("[data-formie-message-success]:not([data-formie-success-container])").forEach((e) => {
1211
+ e.remove();
1212
+ }), e.querySelectorAll("[data-formie-success-container]").forEach((t) => {
1213
+ let n = t;
1214
+ n.querySelectorAll("[data-formie-success]").forEach((e) => {
1215
+ e.remove();
1216
+ }), S(n, e, "message", "messageSuccess"), n.removeAttribute("data-formie-message"), n.removeAttribute("data-formie-message-success"), n.removeAttribute("role"), n.removeAttribute("aria-live"), n.removeAttribute("aria-atomic"), n.querySelector("[data-formie-success]") || (n.innerHTML = "");
1217
+ }), ft(e) === "message" && P(e) || f(e, !1);
1218
+ }
1219
+ function At(e) {
1220
+ e.querySelectorAll("[aria-invalid=\"true\"]").forEach((e) => {
1221
+ e.removeAttribute("aria-invalid");
1222
+ });
1223
+ }
1224
+ function jt(e, t) {
1225
+ let n = (e.getAttribute("aria-describedby") || "").trim(), r = n ? n.split(/\s+/) : [];
1226
+ r.includes(t) || r.push(t), e.setAttribute("aria-describedby", r.join(" ").trim());
1227
+ }
1228
+ function Mt(e, t) {
1229
+ Object.entries(t).forEach(([t, n]) => {
1230
+ let r = e.querySelector(`[data-formie-field-handle="${t}"]`);
1231
+ if (!r) return;
1232
+ let i = wt(r), a = i.id && i.id.trim() ? i.id : `${t}-errors`;
1233
+ i.id = a, i.setAttribute("aria-live", "polite"), i.setAttribute("aria-atomic", "true"), C(r, e, "fieldLayoutError"), r.setAttribute("data-formie-field-has-error", "true"), n.forEach((t, n) => {
1234
+ let r = document.createElement("div");
1235
+ r.setAttribute("data-formie-field-error", "true"), r.setAttribute("role", "alert"), r.id = `${a}-${n + 1}`, C(r, e, "fieldError"), r.textContent = t, i.appendChild(r);
1236
+ });
1237
+ let o = i.querySelector("[data-formie-field-error]")?.id;
1238
+ r.querySelectorAll("input, select, textarea").forEach((t) => {
1239
+ let n = t;
1240
+ n.setAttribute("aria-invalid", "true"), C(n, e, "fieldControlError"), n.setAttribute("data-formie-input-has-error", "true"), jt(n, a), o && Et(n, o);
1241
+ let i = r.querySelector("[data-formie-instructions]");
1242
+ i?.id && jt(n, i.id);
1243
+ });
1244
+ }), x(e);
1245
+ }
1246
+ function Nt(e, t) {
1247
+ let n = xt(e), r = St(e, n);
1248
+ C(n, e, "errors"), t.forEach((t) => {
1249
+ let n = document.createElement("div");
1250
+ n.setAttribute("data-formie-error", "true"), n.setAttribute("role", "alert"), C(n, e, "error"), n.innerHTML = t, r.appendChild(n);
1251
+ });
1252
+ }
1253
+ function Pt(e, t) {
1254
+ return !t.message || t.nextPage || t.redirect ? !1 : t.action === "save" ? !0 : ft(e) === "message" && mt(e) !== "";
1255
+ }
1256
+ function Ft(e, t) {
1257
+ let n = mt(e);
1258
+ if (!n) return;
1259
+ let r = Ct(e, n);
1260
+ C(r, e, "message", "messageSuccess"), r.setAttribute("data-formie-message", "true"), r.setAttribute("data-formie-message-success", "true"), r.setAttribute("role", "status"), r.setAttribute("aria-live", "polite"), r.setAttribute("aria-atomic", "true");
1261
+ let i = document.createElement("div");
1262
+ i.setAttribute("data-formie-success", "true"), C(i, e, "success"), i.innerHTML = t, r.appendChild(i), P(e) && f(e, !0);
1263
+ let a = ht(e);
1264
+ if (a !== null) {
1265
+ let t = window.setTimeout(() => {
1266
+ N.delete(e), F(e);
1267
+ }, a);
1268
+ N.set(e, t);
1269
+ }
1270
+ }
1271
+ function I(e, t) {
1272
+ if (Ot(e), kt(e), F(e), At(e), t.ok) {
1273
+ Pt(e, t) && Ft(e, t.message || "");
1274
+ return;
1275
+ }
1276
+ t.fieldErrors && Mt(e, t.fieldErrors), t.formErrors?.length ? Nt(e, t.formErrors) : !t.fieldErrors && t.message && Nt(e, [t.message]), je(e);
1277
+ }
1278
+ //#endregion
1279
+ //#region src/js/core/submit-flow.ts
1280
+ var It = d("general", "submit-flow");
1281
+ function Lt(e) {
1282
+ return !(!e.ok && e.stage === "validate");
1283
+ }
1284
+ function Rt(e) {
1285
+ return e ? !!(e.keepSubmitLoading === !0 || e.ok && e.redirect?.url && e.redirect.target !== "new-tab") : !1;
1286
+ }
1287
+ function zt(e) {
1288
+ Ot(e), kt(e), F(e), At(e);
1289
+ }
1290
+ async function Bt(e) {
1291
+ let { id: t, target: n, form: r, bus: i, validator: a, validateOnSubmit: o, action: s, submitter: c, waitForSubmitDelay: l, onRefreshTokensAfterSubmit: u, dispatchSubmitResult: d } = e;
1292
+ zt(r), _(r, c || null);
1293
+ let f = {
1294
+ ok: !1,
1295
+ code: "SUBMIT_ERROR",
1296
+ message: "Submission failed.",
1297
+ formErrors: ["Submission failed."]
1298
+ };
1299
+ try {
1300
+ await l(r), f = await $e(r, s, i, {
1301
+ validator: a,
1302
+ validateOnSubmit: o
1303
+ }), I(r, f), v(r, f, s), Lt(f) && await u(f), d(f);
1304
+ } catch (e) {
1305
+ f = {
1306
+ ok: !1,
1307
+ code: "SUBMIT_ERROR",
1308
+ message: e instanceof Error ? e.message : "Submission failed.",
1309
+ formErrors: [e instanceof Error ? e.message : "Submission failed."]
1310
+ }, I(r, f), d(f), It.warn("Submit failed with exception.", {
1311
+ id: t,
1312
+ action: s,
1313
+ target: n,
1314
+ error: e instanceof Error ? e.message : e
1315
+ });
1316
+ } finally {
1317
+ Rt(f) || m(r);
1318
+ }
1319
+ return f;
1320
+ }
1321
+ //#endregion
1322
+ //#region src/js/modules/registry.ts
1323
+ var Vt = class {
1324
+ constructor() {
1325
+ this.modules = /* @__PURE__ */ new Map();
1326
+ }
1327
+ register(e, t = {}) {
1328
+ let n = this.modules.get(e.id);
1329
+ return n === e ? !0 : n && !t.replace ? (console.warn(`[formie] Module "${e.id}" is already registered. Pass { replace: true } to override the existing definition.`), !1) : (this.modules.set(e.id, e), !0);
1330
+ }
1331
+ unregister(e) {
1332
+ this.modules.delete(e);
1333
+ }
1334
+ get(e) {
1335
+ return this.modules.get(e) || null;
1336
+ }
1337
+ getAll() {
1338
+ return Array.from(this.modules.values());
1339
+ }
1340
+ }, Ht = {
1341
+ "address-finder": () => import("./chunks/address-finder-yXU5yMjG.js").then((e) => e.addressFinderModule),
1342
+ "google-address": () => import("./chunks/google-address-OhKilPWE.js").then((e) => e.googleAddressModule),
1343
+ loqate: () => import("./chunks/loqate-Cp2zvwpE.js").then((e) => e.loqateModule),
1344
+ "place-kit": () => import("./chunks/place-kit-BGHklIZ-.js").then((e) => e.placeKitModule)
1345
+ }, Ut = {
1346
+ "captcha-eu": () => import("./chunks/captcha-eu-CWJb64_j.js").then((e) => e.captchaEuModule),
1347
+ "friendly-captcha-v1": () => import("./chunks/friendly-captcha-v1-ByXzENYZ.js").then((e) => e.friendlyCaptchaV1Module),
1348
+ "friendly-captcha-v2": () => import("./chunks/friendly-captcha-v2-BPdlmhQu.js").then((e) => e.friendlyCaptchaV2Module),
1349
+ hcaptcha: () => import("./chunks/hcaptcha-CdCd9oEi.js").then((e) => e.hcaptchaModule),
1350
+ "recaptcha-enterprise": () => import("./chunks/recaptcha-enterprise-BSwi8IVX.js").then((e) => e.recaptchaEnterpriseModule),
1351
+ "recaptcha-v2-checkbox": () => import("./chunks/recaptcha-v2-checkbox-CnDQmsKa.js").then((e) => e.recaptchaV2CheckboxModule),
1352
+ "recaptcha-v2-invisible": () => import("./chunks/recaptcha-v2-invisible-Cz5uIlp-.js").then((e) => e.recaptchaV2InvisibleModule),
1353
+ "recaptcha-v3": () => import("./chunks/recaptcha-v3-BtbbP111.js").then((e) => e.recaptchaV3Module),
1354
+ snaptcha: () => import("./chunks/snaptcha-vz1RnZ15.js").then((e) => e.snaptchaModule),
1355
+ turnstile: () => import("./chunks/turnstile-D_Pi1CKM.js").then((e) => e.turnstileModule)
1356
+ }, Wt = {
1357
+ calculations: () => import("./chunks/calculations-CgVJcQ2P.js").then((e) => e.calculationsModule),
1358
+ "checkbox-radio": () => import("./chunks/checkbox-radio-DQ0H67Tj.js").then((e) => e.checkboxRadioModule),
1359
+ combobox: () => import("./chunks/combobox-D-2b42wn.js").then((e) => e.comboboxModule),
1360
+ conditions: () => import("./chunks/conditions-CZ3FU5QO.js").then((e) => e.conditionsModule),
1361
+ "custom-google-maps": () => import("./chunks/custom-google-maps-BsaSirEZ.js").then((e) => e.customGoogleMapsModule),
1362
+ "custom-link": () => import("./chunks/custom-link-CJ1-FjEM.js").then((e) => e.customLinkModule),
1363
+ "custom-maps": () => import("./chunks/custom-maps-DYW_pBid.js").then((e) => e.customMapsModule),
1364
+ "date-picker": () => import("./chunks/date-picker-5CA_-zGb.js").then((e) => e.datePickerModule),
1365
+ "file-upload": () => import("./chunks/file-upload-D49m8-DR.js").then((e) => e.fileUploadModule),
1366
+ hidden: () => import("./chunks/hidden-D7_Ch-QN.js").then((e) => e.hiddenModule),
1367
+ "phone-country": () => import("./chunks/phone-country-D3ayr60L.js").then((e) => e.phoneCountryModule),
1368
+ "address-country": () => import("./chunks/address-country-Rx6GQTND.js").then((e) => e.addressCountryModule),
1369
+ "address-state": () => import("./chunks/address-state-BQ0xGV9n.js").then((e) => e.addressStateModule),
1370
+ repeater: () => import("./chunks/repeater-B5leVxZU.js").then((e) => e.repeaterModule),
1371
+ "rich-text": () => import("./chunks/rich-text-Cv8ADyk-.js").then((e) => e.richTextModule),
1372
+ signature: () => import("./chunks/signature-CpgqHCEx.js").then((e) => e.signatureModule),
1373
+ summary: () => import("./chunks/summary-D3AjxpYN.js").then((e) => e.summaryModule),
1374
+ table: () => import("./chunks/table-C-lkQN6I.js").then((e) => e.tableModule),
1375
+ "text-limit": () => import("./chunks/text-limit-B09elPDB.js").then((e) => e.textLimitModule)
1376
+ }, Gt = {
1377
+ bpoint: () => import("./chunks/bpoint-DSjqRv63.js").then((e) => e.bpointModule),
1378
+ eway: () => import("./chunks/eway-D3ctTbEk.js").then((e) => e.ewayModule),
1379
+ "go-cardless": () => import("./chunks/go-cardless-BwASSYSK.js").then((e) => e.goCardlessModule),
1380
+ mollie: () => import("./chunks/mollie-COG-ko2D.js").then((e) => e.mollieModule),
1381
+ moneris: () => import("./chunks/moneris-CMH8PlRc.js").then((e) => e.monerisModule),
1382
+ opayo: () => import("./chunks/opayo-D2jsR5vh.js").then((e) => e.opayoModule),
1383
+ paddle: () => import("./chunks/paddle-DxF88RfC.js").then((e) => e.paddleModule),
1384
+ paypal: () => import("./chunks/paypal-b5pnwrA2.js").then((e) => e.paypalModule),
1385
+ payway: () => import("./chunks/payway-BJYu9DIR.js").then((e) => e.paywayModule),
1386
+ square: () => import("./chunks/square-BP8RWAKB.js").then((e) => e.squareModule),
1387
+ stripe: () => import("./chunks/stripe-MihN63uC.js").then((e) => e.stripeModule)
1388
+ }, Kt = {
1389
+ ...Wt,
1390
+ ...Ht,
1391
+ ...Ut,
1392
+ ...Gt
1393
+ }, L = /* @__PURE__ */ new Map(), R = d("general", "loader"), qt = Function("src", "return import(src);");
1394
+ async function z(t, n, i, a) {
1395
+ await t(r(i), a), await t(e(n, i), a);
1396
+ }
1397
+ function Jt(e) {
1398
+ return !!e && typeof e == "object" && typeof e.id == "string" && typeof e.setup == "function" && typeof e.match == "function";
1399
+ }
1400
+ async function Yt(e, t) {
1401
+ let n = Kt[e];
1402
+ return n ? (L.has(e) || L.set(e, (async () => {
1403
+ try {
1404
+ let e = await n();
1405
+ return Jt(e) ? (t.registry.register(e), e) : null;
1406
+ } catch (t) {
1407
+ return console.error("[formie] Failed to load builtin module:", e, t), R.warn("Failed loading builtin module.", {
1408
+ moduleId: e,
1409
+ error: t
1410
+ }), null;
1411
+ }
1412
+ })()), L.get(e) || null) : null;
1413
+ }
1414
+ async function Xt(e) {
1415
+ try {
1416
+ let t = await qt(e), n = t?.default || t?.formieModule || null;
1417
+ return Jt(n) ? n : null;
1418
+ } catch (t) {
1419
+ return console.error("[formie] Failed to load module from src:", e, t), R.warn("Failed loading module from src.", {
1420
+ src: e,
1421
+ error: t
1422
+ }), null;
1423
+ }
1424
+ }
1425
+ async function Zt(e, t) {
1426
+ let n = t.registry.get(e.id);
1427
+ if (n) return n;
1428
+ let r = await Yt(e.id, t);
1429
+ if (r) return r;
1430
+ if (e.src) {
1431
+ let n = await Xt(e.src);
1432
+ if (n) return t.registry.register(n), n;
1433
+ }
1434
+ return null;
1435
+ }
1436
+ function B(e) {
1437
+ return typeof window.CSS?.escape == "function" ? window.CSS.escape(e) : e.replace(/["\\]/g, "\\$&");
1438
+ }
1439
+ function V(e, t) {
1440
+ return e.matches(t) ? [e, ...Array.from(e.querySelectorAll(t))] : Array.from(e.querySelectorAll(t));
1441
+ }
1442
+ function Qt(e, t) {
1443
+ let n = t.setupContext.root, r = t.setupContext.form, i = e.targetType, a = e.targetId;
1444
+ return i === "selector" ? V(n, a).map((e) => ({
1445
+ scope: i,
1446
+ element: e
1447
+ })) : i === "field" ? V(n, `[data-formie-field-handle="${B(a)}"]`).map((e) => ({
1448
+ scope: i,
1449
+ element: e
1450
+ })) : i === "page" ? V(n, `[data-formie-page-id="${B(a)}"]`).map((e) => ({
1451
+ scope: i,
1452
+ element: e
1453
+ })) : i === "button" ? V(n, `[data-formie-action="${B(a)}"]`).map((e) => ({
1454
+ scope: i,
1455
+ element: e
1456
+ })) : [{
1457
+ scope: "form",
1458
+ element: r || n
1459
+ }];
1460
+ }
1461
+ function $t(e, t) {
1462
+ return (e.targets && e.targets.length > 0 ? e.targets : [{
1463
+ targetType: "form",
1464
+ targetId: "form"
1465
+ }]).flatMap((e) => Qt(e, t));
1466
+ }
1467
+ async function en(e, t) {
1468
+ let n = [];
1469
+ R.log("Loading module manifest.", { manifestCount: e.length });
1470
+ for (let r of e) {
1471
+ let e = await Zt(r, t);
1472
+ if (!e) {
1473
+ R.warn("Skipping manifest item (definition not resolved).", {
1474
+ moduleId: r.id,
1475
+ src: r.src
1476
+ });
1477
+ continue;
1478
+ }
1479
+ let i = $t(r, t);
1480
+ R.log("Resolved module targets.", {
1481
+ moduleId: e.id,
1482
+ targets: r.targets || [],
1483
+ targetCount: i.length
1484
+ }), i.length === 0 && e.kind === "address" && console.warn(`[formie] Address module "${r.id}" skipped: no target element found for fieldHandle="${r.targets?.find((e) => e.targetType === "field")?.targetId ?? "?"}". Check that the Address field exists in the rendered form.`);
1485
+ for (let a of i) {
1486
+ let i = {
1487
+ ...t.matchContext,
1488
+ target: a.element,
1489
+ scope: a.scope,
1490
+ manifestItem: r
1491
+ };
1492
+ if (!e.match(i)) {
1493
+ e.kind === "address" && console.warn(`[formie] Address module "${e.id}" skipped: target element does not contain [data-formie-address-autocomplete-input]. Enable the Auto-Complete subfield.`), R.log("Module target did not match predicate.", {
1494
+ moduleId: e.id,
1495
+ scope: a.scope
1496
+ });
1497
+ continue;
1498
+ }
1499
+ let o = r.config || t.setupContext.options, s = e.id, c = {
1500
+ moduleId: e.id,
1501
+ moduleKind: e.kind,
1502
+ target: a.element,
1503
+ scope: a.scope,
1504
+ options: o,
1505
+ manifestItem: r
1506
+ };
1507
+ await z(t.setupContext.emit, s, "before-setup", c);
1508
+ let l = null;
1509
+ try {
1510
+ let n = await e.setup({
1511
+ ...t.setupContext,
1512
+ target: a.element,
1513
+ scope: a.scope,
1514
+ options: o
1515
+ });
1516
+ n && (l = n);
1517
+ } catch (t) {
1518
+ console.error(`[formie] Module "${e.id}" setup failed:`, t), R.warn("Module setup failed.", {
1519
+ moduleId: e.id,
1520
+ scope: a.scope,
1521
+ error: t
1522
+ });
1523
+ }
1524
+ await z(t.setupContext.emit, s, "after-setup", {
1525
+ ...c,
1526
+ instanceCreated: !!l
1527
+ }), l && (R.log("Module instance created.", {
1528
+ moduleId: e.id,
1529
+ scope: a.scope
1530
+ }), n.push({
1531
+ ...l,
1532
+ destroy: async () => {
1533
+ R.log("Destroying module instance.", {
1534
+ moduleId: e.id,
1535
+ scope: a.scope
1536
+ }), await z(t.setupContext.emit, s, "before-destroy", c), await l.destroy(), await z(t.setupContext.emit, s, "after-destroy", c), R.log("Module instance destroyed.", {
1537
+ moduleId: e.id,
1538
+ scope: a.scope
1539
+ });
1540
+ }
1541
+ }));
1542
+ }
1543
+ }
1544
+ return R.log("Module manifest processing complete.", { instanceCount: n.length }), n;
1545
+ }
1546
+ //#endregion
1547
+ //#region src/js/utils/unload-warning.ts
1548
+ var tn = new Set([
1549
+ "CRAFT_CSRF_TOKEN",
1550
+ "action",
1551
+ "redirect",
1552
+ "requestToken",
1553
+ "renderId",
1554
+ "submitAction",
1555
+ "pageId",
1556
+ "draftContextToken",
1557
+ "draftContext",
1558
+ "continuationToken"
1559
+ ]);
1560
+ function nn(e, t) {
1561
+ if (e == null) return String(e);
1562
+ if (typeof e == "string") return JSON.stringify(e);
1563
+ if (typeof e == "number" || typeof e == "boolean") return String(e);
1564
+ if (typeof e == "function") return "[function]";
1565
+ if (typeof File < "u" && e instanceof File) return `[file:${e.name}:${e.size}:${e.type}]`;
1566
+ if (typeof Blob < "u" && e instanceof Blob) return `[blob:${e.size}:${e.type}]`;
1567
+ if (Array.isArray(e)) return `[${e.map((e) => nn(e, t)).join(",")}]`;
1568
+ if (typeof e == "object") {
1569
+ if (t.has(e)) return "[circular]";
1570
+ t.add(e);
1571
+ let n = Object.entries(e).sort(([e], [t]) => e.localeCompare(t)).map(([e, n]) => `${JSON.stringify(e)}:${nn(n, t)}`);
1572
+ return t.delete(e), `{${n.join(",")}}`;
1573
+ }
1574
+ return JSON.stringify(String(e));
1575
+ }
1576
+ function rn(e) {
1577
+ return nn(e, /* @__PURE__ */ new WeakSet());
1578
+ }
1579
+ function an(e) {
1580
+ if (!e) return !1;
1581
+ let t = e.endsWith("[]") ? e.slice(0, -2) : e;
1582
+ return !tn.has(t);
1583
+ }
1584
+ function on(e) {
1585
+ return rn(Array.from(new FormData(e).entries()).filter(([e]) => an(String(e || ""))));
1586
+ }
1587
+ function sn(e, t = {}) {
1588
+ let n = null, r = !1, i = !1, a = null, o = null, s = null, c = () => {
1589
+ a !== null && (window.cancelAnimationFrame(a), a = null), o !== null && (window.clearTimeout(o), o = null), s !== null && (window.clearTimeout(s), s = null);
1590
+ }, l = () => r ? (i = on(e) !== n, i) : !1, u = () => {
1591
+ n = on(e), r = !0, i = !1;
1592
+ }, d = () => {
1593
+ c(), r = !1, a = window.requestAnimationFrame(() => {
1594
+ a = null, s = window.setTimeout(() => {
1595
+ s = null, u();
1596
+ }, 0);
1597
+ });
1598
+ }, f = () => {
1599
+ o !== null && window.clearTimeout(o), o = window.setTimeout(() => {
1600
+ o = null, l();
1601
+ }, 120);
1602
+ }, p = (e) => {
1603
+ t.shouldWarn && !t.shouldWarn() || l() && (e.preventDefault(), e.returnValue = "");
1604
+ };
1605
+ return e.addEventListener("input", f), e.addEventListener("change", f), window.addEventListener("beforeunload", p), d(), {
1606
+ captureBaseline: u,
1607
+ scheduleBaselineCapture: d,
1608
+ refreshDirtyState: l,
1609
+ destroy: () => {
1610
+ c(), e.removeEventListener("input", f), e.removeEventListener("change", f), window.removeEventListener("beforeunload", p);
1611
+ }
1612
+ };
1613
+ }
1614
+ //#endregion
1615
+ //#region src/js/core/create-formie-client.ts
1616
+ var H = "[data-formie]:not([data-formie-init=\"false\"]), [data-formie-form]:not([data-formie-init=\"false\"])", cn = 300, ln = "/actions/formie/server/forms/render", un = "/api", dn = "/actions/formie/server/forms/refresh-tokens", fn = "/actions/formie/server/submissions/submit", pn = "/actions/formie/server/submissions/set-page", mn = "/actions/formie/server/submissions/clear-submission", hn = "/actions/formie/file-upload/hydrate", U = d("general", "client"), gn = /* @__PURE__ */ new Set();
1617
+ function W(e, t) {
1618
+ if (e == null || e === "") return t;
1619
+ let n = e.toLowerCase();
1620
+ return !(n === "false" || n === "0" || n === "off");
1621
+ }
1622
+ function _n(e) {
1623
+ return e.formieRefreshTokens != null && e.formieRefreshTokens !== "" ? W(e.formieRefreshTokens, !1) : e.formieStaticCache != null && e.formieStaticCache !== "" ? W(e.formieStaticCache, !1) : !1;
1624
+ }
1625
+ function G(e) {
1626
+ let t = e instanceof HTMLElement ? e.dataset : {};
1627
+ return {
1628
+ mode: "server-rendered",
1629
+ transport: t.formieTransport || "rest",
1630
+ formHandle: t.formieHandle,
1631
+ endpoint: t.formieEndpoint,
1632
+ staticCache: _n(t),
1633
+ autoVisible: W(t.formieAutoVisible, !0),
1634
+ compatibility: W(t.formieCompatibility, !1)
1635
+ };
1636
+ }
1637
+ function K(e) {
1638
+ return e || "server-rendered";
1639
+ }
1640
+ function q(e) {
1641
+ return e || "rest";
1642
+ }
1643
+ function J(e) {
1644
+ return e instanceof HTMLFormElement ? e : e.querySelector("form");
1645
+ }
1646
+ function vn(e, t) {
1647
+ gn.has(e) || (gn.add(e), U.warn(t));
1648
+ }
1649
+ function yn(e, t) {
1650
+ if (!e) return e;
1651
+ try {
1652
+ return new URL(e).toString();
1653
+ } catch {}
1654
+ if (!t) return e;
1655
+ try {
1656
+ return new URL(e, t).toString();
1657
+ } catch {
1658
+ return e;
1659
+ }
1660
+ }
1661
+ function Y(e, t) {
1662
+ let n = (e || "").trim();
1663
+ return n ? n.includes("/actions/") ? n : yn(t, n) : t;
1664
+ }
1665
+ function bn(e, t) {
1666
+ return Y(e.endpoint || t.dataset.formieEndpoint, ln);
1667
+ }
1668
+ function xn(e, t) {
1669
+ let n = (e.endpoint || t.dataset.formieEndpoint || "").trim();
1670
+ return n ? n.includes("/graphql") || n.endsWith("/api") || n.includes("/actions/graphql/") ? n : yn(un, n) : un;
1671
+ }
1672
+ function Sn(e, t) {
1673
+ return Y(t.dataset.formieRefreshTokensEndpoint || e.endpoint || t.dataset.formieEndpoint, dn);
1674
+ }
1675
+ function Cn(e, t) {
1676
+ if (!e) return t;
1677
+ try {
1678
+ let n = new URL(e, window.location.origin), r = new URL(t, window.location.origin);
1679
+ return n.searchParams.forEach((e, t) => {
1680
+ r.searchParams.has(t) || r.searchParams.set(t, e);
1681
+ }), r.toString();
1682
+ } catch {
1683
+ return t;
1684
+ }
1685
+ }
1686
+ function wn(e, t, n) {
1687
+ let r = n.endpoint || e.dataset.formieEndpoint, i = Y(r, fn), a = t.getAttribute("action");
1688
+ t.setAttribute("action", Cn(a, i)), t.querySelectorAll("[data-formie-tab-link]").forEach((e) => {
1689
+ let t = e.getAttribute("href"), n = Y(r, pn);
1690
+ e.setAttribute("href", Cn(t, n));
1691
+ }), t.querySelectorAll("[data-formie-file-upload-hydrate-endpoint]").forEach((e) => {
1692
+ e.setAttribute("data-formie-file-upload-hydrate-endpoint", Y(r, hn));
1693
+ });
1694
+ }
1695
+ function Tn(e, t) {
1696
+ if (e === "graphql" && t !== "server-rendered") throw Error(`Formie ${t} mode does not support GraphQL transport yet.`);
1697
+ }
1698
+ function En(e) {
1699
+ if (e == null) return !1;
1700
+ let t = e.trim().toLowerCase();
1701
+ return t === "true" || t === "1" || t === "";
1702
+ }
1703
+ function Dn(e) {
1704
+ return W(e.dataset.formieAutomaticSubmissionState, !0);
1705
+ }
1706
+ function On(e, t, n) {
1707
+ return Y(n.dataset.formieClearSubmissionEndpoint || e.endpoint || t.dataset.formieEndpoint, mn);
1708
+ }
1709
+ function kn(e) {
1710
+ return En(e.dataset.formieUnloadWarning);
1711
+ }
1712
+ function An(e, t) {
1713
+ e.setAttribute("data-formie-internal-navigation", t);
1714
+ }
1715
+ function jn(e) {
1716
+ e.removeAttribute("data-formie-internal-navigation");
1717
+ }
1718
+ function Mn(e) {
1719
+ return e.getAttribute("data-formie-internal-navigation") !== null;
1720
+ }
1721
+ function Nn(e, t) {
1722
+ if (!e) return !1;
1723
+ try {
1724
+ return new URL(e, window.location.origin).searchParams.has(t);
1725
+ } catch {
1726
+ return !1;
1727
+ }
1728
+ }
1729
+ function Pn(e) {
1730
+ return Nn(window.location.href, "resumeToken") || Nn(e.getAttribute("action"), "resumeToken");
1731
+ }
1732
+ function Fn(e) {
1733
+ return e instanceof MouseEvent ? e.button === 0 && !e.metaKey && !e.ctrlKey && !e.shiftKey && !e.altKey : !0;
1734
+ }
1735
+ function In(e, t = 0) {
1736
+ if (!e) return t;
1737
+ let n = Number.parseInt(e, 10);
1738
+ return Number.isFinite(n) ? n : t;
1739
+ }
1740
+ function Ln(e) {
1741
+ return Math.max(0, In(e.dataset.formieSubmitDelay, cn));
1742
+ }
1743
+ function X(e) {
1744
+ return En(e.dataset.formieValidationOnSubmit);
1745
+ }
1746
+ async function Z(e) {
1747
+ let t = Ln(e);
1748
+ t < 1 || await new Promise((e) => {
1749
+ window.setTimeout(e, t);
1750
+ });
1751
+ }
1752
+ function Rn(e, t) {
1753
+ let n = e?.getAttribute(t)?.trim();
1754
+ if (!n) return null;
1755
+ try {
1756
+ return JSON.parse(n);
1757
+ } catch (e) {
1758
+ return console.error(`[formie] Failed to parse ${t}.`, e), null;
1759
+ }
1760
+ }
1761
+ function zn(e, t) {
1762
+ let n = t || (e instanceof HTMLFormElement ? e : null);
1763
+ if (!n) return null;
1764
+ let r = Rn(n, "data-formie-modules"), i = Rn(n, "data-formie-theme");
1765
+ return !r && !i ? null : {
1766
+ modules: r || void 0,
1767
+ theme: i || void 0
1768
+ };
1769
+ }
1770
+ function Bn(e) {
1771
+ if (!(e instanceof HTMLElement)) return !0;
1772
+ if (!e.isConnected || e.hidden || e.closest("[hidden]")) return !1;
1773
+ let t = window.getComputedStyle(e);
1774
+ return t.display === "none" || t.visibility === "hidden" ? !1 : e.getClientRects().length > 0;
1775
+ }
1776
+ function Vn(e, t) {
1777
+ return t === document ? !0 : t instanceof Element ? t === e || t.contains(e) : !0;
1778
+ }
1779
+ function Q(e) {
1780
+ let t = e, n = t.id ? `#${t.id}` : "", r = t.dataset?.formieHandle ? `[handle="${t.dataset.formieHandle}"]` : "";
1781
+ return `${t.tagName ? t.tagName.toLowerCase() : "element"}${n}${r}`;
1782
+ }
1783
+ function Hn(e, t) {
1784
+ if (t) {
1785
+ if (t.csrf?.param && t.csrf?.token) {
1786
+ let n = e.querySelector(`input[name="${t.csrf.param}"]`);
1787
+ n && (n.value = t.csrf.token);
1788
+ }
1789
+ if (t.requestToken) {
1790
+ let n = e.querySelector("input[name=\"requestToken\"]");
1791
+ n && (n.value = t.requestToken);
1792
+ }
1793
+ if (t.renderId) {
1794
+ let n = e.querySelector("input[name=\"renderId\"]");
1795
+ n && (n.value = t.renderId);
1796
+ }
1797
+ t.captchas && typeof t.captchas == "object" && Object.values(t.captchas).forEach((t) => {
1798
+ if (!t || typeof t != "object") return;
1799
+ let n = t;
1800
+ if (!n.sessionKey) return;
1801
+ let r = e.querySelector(`input[name="${n.sessionKey}"]`);
1802
+ r && typeof n.value == "string" && (r.value = n.value);
1803
+ });
1804
+ }
1805
+ }
1806
+ async function Un(e, t) {
1807
+ let n = K(t.mode), r = q(t.transport);
1808
+ if (n !== "server-rendered") return null;
1809
+ if (t.payload) return t.payload.html && (e.innerHTML = t.payload.html), t.payload;
1810
+ Tn(r, n);
1811
+ let i = !!J(e), a = t.formHandle || e.dataset.formieHandle;
1812
+ if (i || !a) return null;
1813
+ let o = {
1814
+ mode: n,
1815
+ endpoint: t.endpoint,
1816
+ locale: t.locale,
1817
+ siteId: t.siteId,
1818
+ theme: t.theme,
1819
+ themeConfig: t.themeConfig
1820
+ }, s = r === "graphql" ? xn(t, e) : bn(t, e), c = r === "graphql" ? await Le(s, a, o) : await Ie(s, a, {
1821
+ ...o,
1822
+ endpoint: s
1823
+ });
1824
+ return c?.html && (e.innerHTML = c.html), c;
1825
+ }
1826
+ async function Wn(e, t, n) {
1827
+ if (t.refreshTokens === !1) return;
1828
+ Tn(q(t.transport), K(t.mode));
1829
+ let r = t.formHandle || e.dataset.formieHandle;
1830
+ if (!r) return;
1831
+ let i = await Re(Sn(t, e), r, n.querySelector("input[name=\"renderId\"]")?.value || void 0);
1832
+ Hn(n, i), O(e, "formie:refresh-tokens:refreshed", i);
1833
+ }
1834
+ function Gn(e, t, n, r, i, a) {
1835
+ let o = String(t.dataset.formieSubmitMethod || "").trim().toLowerCase(), s = On(n, e, t), c = !1, l = t.querySelectorAll("[data-formie-action]"), u = (e) => {
1836
+ if (e) {
1837
+ t.setAttribute("data-formie-pending-action", e);
1838
+ return;
1839
+ }
1840
+ t.removeAttribute("data-formie-pending-action");
1841
+ };
1842
+ if (kn(t)) {
1843
+ let n = sn(t, { shouldWarn: () => !Mn(t) }), r = (e) => {
1844
+ if (!(e instanceof CustomEvent)) return;
1845
+ let t = e.detail;
1846
+ t?.ok && t.action === "save" && n.scheduleBaselineCapture();
1847
+ }, i = () => {
1848
+ n.scheduleBaselineCapture();
1849
+ };
1850
+ e.addEventListener("formie:submit:result", r), t.addEventListener("formie:state:reset", i), a.push(() => {
1851
+ e.removeEventListener("formie:submit:result", r), t.removeEventListener("formie:state:reset", i), n.destroy();
1852
+ });
1853
+ }
1854
+ if (l.forEach((e) => {
1855
+ let n = (e) => {
1856
+ let n = e.currentTarget.getAttribute("data-formie-action"), r = t.querySelector("input[name=\"submitAction\"]");
1857
+ u(n), n && r && (r.value = n);
1858
+ };
1859
+ e.addEventListener("click", n), a.push(() => {
1860
+ e.removeEventListener("click", n);
1861
+ });
1862
+ }), t.querySelectorAll("[data-formie-tab-link]").forEach((n) => {
1863
+ let r = async (n) => {
1864
+ if (o !== "ajax") {
1865
+ Fn(n) && An(t, "set-page");
1866
+ return;
1867
+ }
1868
+ n.preventDefault();
1869
+ let r = n.currentTarget, i = r?.getAttribute("data-formie-page-id"), a = r?.getAttribute("href");
1870
+ if (!(!i || !a)) {
1871
+ g(t, i), O(e, "formie:page:navigate", {
1872
+ pageId: i,
1873
+ href: a
1874
+ });
1875
+ try {
1876
+ O(e, "formie:page:navigate:after", {
1877
+ pageId: i,
1878
+ href: a,
1879
+ response: await ze(a, t, i)
1880
+ });
1881
+ } catch (t) {
1882
+ console.error("[formie] Failed to persist page navigation state.", t), O(e, "formie:page:navigate:error", {
1883
+ pageId: i,
1884
+ href: a,
1885
+ error: t
1886
+ });
1887
+ }
1888
+ }
1889
+ };
1890
+ n.addEventListener("click", r), a.push(() => {
1891
+ n.removeEventListener("click", r);
1892
+ });
1893
+ }), !Dn(t)) {
1894
+ let e = !1, n = () => {
1895
+ e || Mn(t) || Pn(t) || (e = !0, Be(s, t));
1896
+ };
1897
+ window.addEventListener("pagehide", n), window.addEventListener("beforeunload", n), a.push(() => {
1898
+ window.removeEventListener("pagehide", n), window.removeEventListener("beforeunload", n);
1899
+ });
1900
+ }
1901
+ let d = async (a) => {
1902
+ if (c) return;
1903
+ let s = o === "ajax";
1904
+ if (a.preventDefault(), t.getAttribute("data-formie-loading") === "true") {
1905
+ if (t.getAttribute("data-formie-internal-resubmit") !== "true") return;
1906
+ t.removeAttribute("data-formie-internal-resubmit");
1907
+ } else t.removeAttribute("data-formie-internal-resubmit");
1908
+ let l = a.submitter, d = l?.getAttribute("data-formie-action"), f = t.getAttribute("data-formie-pending-action"), p = t.querySelector("input[name=\"submitAction\"]"), g = d || f || p?.value || "submit", v = null, y = !1;
1909
+ try {
1910
+ if (s) v = await Bt({
1911
+ target: e,
1912
+ form: t,
1913
+ bus: r,
1914
+ validator: i,
1915
+ validateOnSubmit: X(t),
1916
+ action: g,
1917
+ submitter: l,
1918
+ waitForSubmitDelay: Z,
1919
+ onRefreshTokensAfterSubmit: async () => {
1920
+ await Wn(e, n, t);
1921
+ },
1922
+ dispatchSubmitResult: (t) => {
1923
+ O(e, "formie:submit:result", t);
1924
+ }
1925
+ });
1926
+ else {
1927
+ if (zt(t), _(t, l), await Z(t), v = await $e(t, g, r, {
1928
+ validator: i,
1929
+ validateOnSubmit: X(t),
1930
+ preflightOnly: !0
1931
+ }), v.ok) {
1932
+ ee(t, g), c = !0, An(t, "submit"), u(null);
1933
+ let e = !1, n = () => {
1934
+ if (e = !0, c = !1, jn(t), m(t), i && X(t)) {
1935
+ let { scope: e, final: n } = h(t), r = i.submit(n ? t : e, { final: n });
1936
+ r.length > 0 && I(t, {
1937
+ ok: !1,
1938
+ stage: "validate",
1939
+ code: "VALIDATION_FAILED",
1940
+ message: i.config.errorMessage || "Validation failed.",
1941
+ fieldErrors: i.getFieldErrors(r),
1942
+ formErrors: [i.config.errorMessage || "Validation failed."]
1943
+ });
1944
+ }
1945
+ };
1946
+ if (typeof t.requestSubmit == "function") {
1947
+ t.addEventListener("invalid", n, !0);
1948
+ try {
1949
+ t.requestSubmit();
1950
+ } finally {
1951
+ t.removeEventListener("invalid", n, !0);
1952
+ }
1953
+ } else t.submit();
1954
+ if (e) return;
1955
+ y = !0;
1956
+ return;
1957
+ }
1958
+ I(t, v), O(e, "formie:submit:result", v), jn(t);
1959
+ }
1960
+ } catch (n) {
1961
+ c = !1, v = {
1962
+ ok: !1,
1963
+ code: "SUBMIT_ERROR",
1964
+ message: n instanceof Error ? n.message : "Submission failed.",
1965
+ formErrors: [n instanceof Error ? n.message : "Submission failed."]
1966
+ }, I(t, v), O(e, "formie:submit:result", v), jn(t);
1967
+ } finally {
1968
+ u(null), !s && !y && !Rt(v) && m(t);
1969
+ }
1970
+ };
1971
+ t.addEventListener("submit", d), a.push(() => {
1972
+ t.removeEventListener("submit", d);
1973
+ });
1974
+ }
1975
+ async function Kn(e, t, n) {
1976
+ if (t.refreshTokens === !1 || !t.staticCache) return;
1977
+ Tn(q(t.transport), K(t.mode));
1978
+ let r = t.formHandle || e.dataset.formieHandle, i = Sn(t, e), a = n?.querySelector("input[name=\"renderId\"]")?.value || void 0;
1979
+ if (!r) return;
1980
+ let o = await Re(i, r, a);
1981
+ !o || !n || (Hn(n, o), O(e, "formie:refresh-tokens:after", o));
1982
+ }
1983
+ function qn() {
1984
+ let e = /* @__PURE__ */ new Map(), t = new Vt(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = [
1985
+ "prepare",
1986
+ "normalize",
1987
+ "validate",
1988
+ "screen",
1989
+ "authorize",
1990
+ "dispatch",
1991
+ "finalize"
1992
+ ], a = async (t) => {
1993
+ let i = r.get(t);
1994
+ if (i) {
1995
+ await i;
1996
+ return;
1997
+ }
1998
+ let a = (async () => {
1999
+ U.log("Unmount requested.", { target: Q(t) });
2000
+ let r = n.get(t);
2001
+ r && (r(), n.delete(t));
2002
+ let i = e.get(t);
2003
+ if (!i) {
2004
+ U.log("Unmount skipped (no mounted state).", { target: Q(t) });
2005
+ return;
2006
+ }
2007
+ O(t, "formie:unmount:before", { id: i.instance.id }), i.unbinds.forEach((e) => {
2008
+ e();
2009
+ }), i.unbinds = [], i.validator?.destroy(), i.validator = null;
2010
+ for (let e of i.modules) await e.destroy();
2011
+ i.modules = [], i.bus.clear(), e.delete(t), O(t, "formie:unmount:after", { id: i.instance.id }), U.log("Unmount complete.", {
2012
+ id: i.instance.id,
2013
+ target: Q(t)
2014
+ });
2015
+ })().finally(() => {
2016
+ r.delete(t);
2017
+ });
2018
+ r.set(t, a), await a;
2019
+ }, o = async (r, o) => {
2020
+ U.log("Mount requested.", {
2021
+ target: Q(r),
2022
+ mode: o.mode,
2023
+ autoVisible: o.autoVisible
2024
+ });
2025
+ let s = n.get(r);
2026
+ s && (s(), n.delete(r));
2027
+ let c = e.get(r);
2028
+ if (c) return U.log("Mount skipped (already mounted).", {
2029
+ id: c.instance.id,
2030
+ target: Q(r)
2031
+ }), c.instance;
2032
+ let l = new Me(), u = [], d = r?.id || `formie-${e.size + 1}`, f = G(r), p = {
2033
+ ...f,
2034
+ ...o,
2035
+ mode: K(o.mode ?? f.mode),
2036
+ transport: q(o.transport ?? f.transport)
2037
+ }, ee = _e(p.compatibility);
2038
+ if (p.mode !== "server-rendered" && !J(r)) throw Error(`Formie ${p.mode} mode is not implemented yet in the browser client.`);
2039
+ let m = await Un(r, p), h = J(r);
2040
+ p.staticCache = o.staticCache ?? _n(h ? h.dataset : r.dataset);
2041
+ let g = zn(r, h), _ = m || g ? {
2042
+ ...m || {},
2043
+ ...g || {}
2044
+ } : null, v = _?.theme, b = {}, S = (_?.modules || []).filter((e) => !!e?.id && !!e?.type);
2045
+ U.log("Resolved mount payload.", {
2046
+ target: Q(r),
2047
+ hasRenderPayload: !!m,
2048
+ hasEmbeddedPayload: !!g,
2049
+ moduleCount: S.length
2050
+ });
2051
+ let C = te(r, v, h), w = h ? new dt(h, {
2052
+ live: En(h.dataset.formieValidationOnFocus),
2053
+ errorMessage: h.dataset.formieErrorMessage || "",
2054
+ fieldContainerErrorClass: C.fieldLayoutError || [],
2055
+ inputErrorClass: C.fieldControlError || [],
2056
+ messagesClass: C.fieldErrors || [],
2057
+ messageClass: C.fieldError || []
2058
+ }) : null;
2059
+ if (h && w) {
2060
+ let e = h;
2061
+ e.formieValidation = w, b.validation = w;
2062
+ let t = {
2063
+ validator: w,
2064
+ addValidator: w.addValidator.bind(w),
2065
+ removeValidator: w.removeValidator.bind(w)
2066
+ };
2067
+ O(h, "formie:validator:ready", t), O(r, "formie:validator:ready", t);
2068
+ }
2069
+ h && ((m || p.endpoint || r.dataset.formieEndpoint) && wn(r, h, p), p.mode === "server-rendered" && Ae(h) && (ke(h), je(h)), x(h)), Object.keys(C).length && O(r, "formie:theme:applied", { hasClasses: !0 });
2070
+ let T = await en(S, {
2071
+ registry: t,
2072
+ matchContext: {
2073
+ root: r,
2074
+ form: h,
2075
+ mode: p.mode
2076
+ },
2077
+ setupContext: {
2078
+ formId: d,
2079
+ root: r,
2080
+ form: h,
2081
+ target: r,
2082
+ scope: "form",
2083
+ state: b,
2084
+ on: (e, t) => l.on(e, t),
2085
+ emit: (e, t) => (O(r, e, t), l.emitSafe(e, t).then((t) => {
2086
+ t.failed.length > 0 && U.warn("Lifecycle listeners failed.", {
2087
+ eventName: e,
2088
+ failed: t.failed.length
2089
+ });
2090
+ }))
2091
+ }
2092
+ });
2093
+ U.log("Module setup complete.", {
2094
+ target: Q(r),
2095
+ moduleInstances: T.length
2096
+ });
2097
+ let E = {
2098
+ id: d,
2099
+ root: r,
2100
+ submit: async (e = "submit") => {
2101
+ if (U.log("Submit requested.", {
2102
+ id: d,
2103
+ target: Q(r),
2104
+ action: e
2105
+ }), !h) return {
2106
+ ok: !1,
2107
+ code: "FORM_NOT_FOUND",
2108
+ message: "No form element found for mount target.",
2109
+ formErrors: ["No form element found for mount target."]
2110
+ };
2111
+ let t = h.querySelector("input[name=\"submitAction\"]");
2112
+ if (t && (t.value = e), h.getAttribute("data-formie-loading") === "true") return {
2113
+ ok: !1,
2114
+ code: "SUBMIT_IN_PROGRESS",
2115
+ message: "Submission already in progress.",
2116
+ formErrors: []
2117
+ };
2118
+ let n = h.querySelector(`[data-formie-action="${e}"]`), i = await Bt({
2119
+ id: d,
2120
+ target: r,
2121
+ form: h,
2122
+ bus: l,
2123
+ validator: w,
2124
+ validateOnSubmit: X(h),
2125
+ action: e,
2126
+ submitter: n,
2127
+ waitForSubmitDelay: Z,
2128
+ onRefreshTokensAfterSubmit: async () => {
2129
+ await Wn(r, p, h);
2130
+ },
2131
+ dispatchSubmitResult: (e) => {
2132
+ O(r, "formie:submit:result", e);
2133
+ }
2134
+ });
2135
+ return U.log("Submit completed.", {
2136
+ id: d,
2137
+ action: e,
2138
+ ok: i.ok,
2139
+ code: i.code,
2140
+ message: i.message
2141
+ }), i;
2142
+ },
2143
+ destroy: async () => {
2144
+ await a(r);
2145
+ },
2146
+ on: (e, t) => l.on(e, t)
2147
+ };
2148
+ h && (we({
2149
+ target: r,
2150
+ form: h,
2151
+ validatorDetail: w ? {
2152
+ validator: w,
2153
+ addValidator: w.addValidator.bind(w),
2154
+ removeValidator: w.removeValidator.bind(w)
2155
+ } : null,
2156
+ options: ee,
2157
+ unbinds: u
2158
+ }), Se({
2159
+ target: r,
2160
+ form: h,
2161
+ instance: E,
2162
+ options: ee,
2163
+ unbinds: u
2164
+ })), h && (Gn(r, h, p, l, w, u), w && u.push(y(h, w, r)), await Kn(r, p, h)), i.forEach((e) => {
2165
+ let t = l.on(`formie:stage:${e}:before`, async (t) => {
2166
+ O(r, `formie:stage:${e}:before`, t);
2167
+ }), n = l.on(`formie:stage:${e}:before`, async (e) => {
2168
+ for (let t of T) t.onBeforeStage && await t.onBeforeStage(e);
2169
+ }), i = l.on(`formie:stage:${e}:after`, async (t) => {
2170
+ O(r, `formie:stage:${e}:after`, t);
2171
+ }), a = l.on(`formie:stage:${e}:after`, async (e) => {
2172
+ let t = e;
2173
+ for (let e of T) e.onAfterStage && await e.onAfterStage(t, t.result);
2174
+ });
2175
+ u.push(t, n, i, a);
2176
+ });
2177
+ let ne = l.on("formie:submit:before", async (e) => {
2178
+ O(r, "formie:submit:before", e);
2179
+ }), re = l.on("formie:submit:after", async (e) => {
2180
+ O(r, "formie:submit:after", e);
2181
+ }), ie = l.on("formie:submit:final:before", async (e) => {
2182
+ O(r, "formie:submit:final:before", e);
2183
+ }), ae = l.on("formie:submit:final:after", async (e) => {
2184
+ O(r, "formie:submit:final:after", e);
2185
+ });
2186
+ return u.push(ne, re, ie, ae), e.set(r, {
2187
+ options: p,
2188
+ bus: l,
2189
+ form: h,
2190
+ validator: w,
2191
+ modules: T,
2192
+ unbinds: u,
2193
+ instance: E
2194
+ }), O(r, "formie:mount:after", {
2195
+ id: d,
2196
+ mode: p.mode
2197
+ }), U.log("Mount complete.", {
2198
+ id: d,
2199
+ target: Q(r),
2200
+ mode: p.mode
2201
+ }), E;
2202
+ }, s = (t, r) => {
2203
+ if (!r.autoVisible || Bn(t) || typeof IntersectionObserver > "u") return o(t, r);
2204
+ if (e.has(t)) return Promise.resolve(e.get(t)?.instance || null);
2205
+ if (n.has(t)) return U.log("Mount deferred (already waiting visibility).", { target: Q(t) }), Promise.resolve(null);
2206
+ let i = new IntersectionObserver((e) => {
2207
+ e.some((e) => e.target === t && e.isIntersecting) && (i.disconnect(), n.delete(t), U.log("Visibility reached, proceeding mount.", { target: Q(t) }), o(t, {
2208
+ ...r,
2209
+ autoVisible: !1
2210
+ }));
2211
+ }, { threshold: .01 });
2212
+ return i.observe(t), n.set(t, () => {
2213
+ i.disconnect();
2214
+ }), U.log("Mount deferred until visible.", { target: Q(t) }), Promise.resolve(null);
2215
+ };
2216
+ return {
2217
+ mount: o,
2218
+ unmount: a,
2219
+ update: async (t, n) => {
2220
+ let r = e.get(t);
2221
+ if (!r) return o(t, {
2222
+ ...G(t),
2223
+ ...n,
2224
+ mode: n.mode || "server-rendered"
2225
+ });
2226
+ r.options = {
2227
+ ...r.options,
2228
+ ...n
2229
+ };
2230
+ let i = te(t, n.payload?.theme || r.options.payload?.theme || zn(t, r.form)?.theme, r.form);
2231
+ return r.validator && (r.validator.config.fieldContainerErrorClass = i.fieldLayoutError || [], r.validator.config.inputErrorClass = i.fieldControlError || [], r.validator.config.messagesClass = i.fieldErrors || [], r.validator.config.messageClass = i.fieldError || []), Object.keys(i).length && O(t, "formie:theme:applied", {
2232
+ hasClasses: !0,
2233
+ reason: "update"
2234
+ }), r.instance;
2235
+ },
2236
+ getInstance: (t) => e.get(t)?.instance || null,
2237
+ refreshForCache: async (t) => {
2238
+ vn("refreshForCache", "Global `Formie.refreshForCache()` has been deprecated. Use built-in static-cache token refresh handling instead.");
2239
+ let n = null;
2240
+ if (n = typeof t == "string" ? document.getElementById(t) || document.querySelector(`[data-formie-form-id="${t}"]`) : t, !n) {
2241
+ U.warn("refreshForCache target not found.", { targetOrId: t });
2242
+ return;
2243
+ }
2244
+ let r = e.get(n), i = J(n), a = r?.options || G(n);
2245
+ if (!i) {
2246
+ U.warn("refreshForCache found no form element for target.", { target: Q(n) });
2247
+ return;
2248
+ }
2249
+ let o = a.formHandle || n.dataset.formieHandle || i.dataset.formieHandle, s = Sn(a, n), c = i.querySelector("input[name=\"renderId\"]")?.value || void 0;
2250
+ if (!o) {
2251
+ U.warn("refreshForCache found no form handle for target.", { target: Q(n) });
2252
+ return;
2253
+ }
2254
+ let l = await Re(s, o, c);
2255
+ l && (Hn(i, l), O(n, "formie:refresh-tokens:after", l));
2256
+ },
2257
+ registerModule: (e, n) => t.register(e, n),
2258
+ unregisterModule: (e) => {
2259
+ t.unregister(e);
2260
+ },
2261
+ getRegisteredModules: () => t.getAll(),
2262
+ scan: async (e) => {
2263
+ let t = e || document, n = Array.from(t.querySelectorAll(H));
2264
+ U.log("Scan started.", {
2265
+ scope: t === document ? "document" : t,
2266
+ targetCount: n.length
2267
+ });
2268
+ let r = (await Promise.all(n.map((e) => s(e, G(e))))).filter((e) => !!e);
2269
+ return U.log("Scan finished.", {
2270
+ mountedCount: r.length,
2271
+ deferredCount: n.length - r.length
2272
+ }), r;
2273
+ },
2274
+ observe: (t) => {
2275
+ if (typeof MutationObserver > "u") return () => {};
2276
+ let r = t || document;
2277
+ U.log("Observer started.", { scope: r === document ? "document" : r });
2278
+ let i = new MutationObserver((t) => {
2279
+ t.forEach((t) => {
2280
+ t.addedNodes.forEach((e) => {
2281
+ e instanceof Element && (e.matches(H) && (U.log("Observer detected new root.", { target: Q(e) }), s(e, G(e))), e.querySelectorAll(H).forEach((e) => {
2282
+ U.log("Observer detected new nested root.", { target: Q(e) }), s(e, G(e));
2283
+ }));
2284
+ }), t.removedNodes.forEach((t) => {
2285
+ t instanceof Element && (e.has(t) && (U.log("Observer detected removed root.", { target: Q(t) }), a(t)), t.querySelectorAll(H).forEach((t) => {
2286
+ e.has(t) && (U.log("Observer detected removed nested root.", { target: Q(t) }), a(t));
2287
+ }));
2288
+ });
2289
+ });
2290
+ });
2291
+ return i.observe(r, {
2292
+ childList: !0,
2293
+ subtree: !0
2294
+ }), () => {
2295
+ i.disconnect(), U.log("Observer stopped."), n.forEach((e, t) => {
2296
+ Vn(t, r) && (e(), n.delete(t));
2297
+ });
2298
+ let t = [];
2299
+ r instanceof Element && r.matches(H) && t.push(r), r.querySelectorAll(H).forEach((e) => {
2300
+ t.push(e);
2301
+ }), t.forEach((t) => {
2302
+ e.has(t) && a(t);
2303
+ });
2304
+ };
2305
+ }
2306
+ };
2307
+ }
2308
+ //#endregion
2309
+ //#region src/js/core/hydrate-modules.ts
2310
+ var Jn = d("general", "module-hydrator");
2311
+ async function Yn(e) {
2312
+ let t = e.root, n = e.form ?? (t instanceof HTMLFormElement ? t : t.closest("form")), r = e.modules ?? [], i = e.mode ?? "server-rendered", a = e.registry ?? new Vt(), o = new Me(), s = await en(r, {
2313
+ registry: a,
2314
+ setupContext: {
2315
+ formId: n?.id || t.id || "formie-modules",
2316
+ root: t,
2317
+ form: n,
2318
+ target: t,
2319
+ scope: "form",
2320
+ state: {},
2321
+ options: {},
2322
+ on: (e, t) => o.on(e, t),
2323
+ emit: async (e, t) => {
2324
+ await o.emit(e, t);
2325
+ }
2326
+ },
2327
+ matchContext: {
2328
+ root: t,
2329
+ form: n,
2330
+ mode: i
2331
+ }
2332
+ });
2333
+ return Jn.log("Hydrated module manifest.", {
2334
+ moduleCount: r.length,
2335
+ instanceCount: s.length,
2336
+ mode: i
2337
+ }), {
2338
+ destroy: async () => {
2339
+ await Xn(s), o.clear();
2340
+ },
2341
+ on: (e, t) => o.on(e, t),
2342
+ emit: async (e, t) => {
2343
+ await o.emit(e, t);
2344
+ },
2345
+ registerModule: (e, t = {}) => a.register(e, t),
2346
+ unregisterModule: (e) => {
2347
+ a.unregister(e);
2348
+ },
2349
+ getRegisteredModules: () => a.getAll()
2350
+ };
2351
+ }
2352
+ async function Xn(e) {
2353
+ for (let t of e) try {
2354
+ await t.destroy();
2355
+ } catch (e) {
2356
+ console.error("[formie] Failed to destroy module instance.", e), Jn.warn("Failed destroying module instance.", { error: e });
2357
+ }
2358
+ }
2359
+ //#endregion
2360
+ //#region src/js/core/formie.ts
2361
+ function $(e) {
2362
+ return e instanceof Element;
2363
+ }
2364
+ function Zn(e) {
2365
+ return e.ok;
2366
+ }
2367
+ function Qn(e) {
2368
+ return typeof e == "string" ? `selector "${e}"` : $(e) ? `element "${e.tagName.toLowerCase()}"` : "provided element collection";
2369
+ }
2370
+ function $n(e) {
2371
+ let t = /* @__PURE__ */ new Set(), n = [];
2372
+ for (let r of e) !$(r) || t.has(r) || (t.add(r), n.push(r));
2373
+ return n;
2374
+ }
2375
+ function er(e) {
2376
+ return typeof e == "string" ? Array.from(document.querySelectorAll(e)) : $(e) ? [e] : $n(e);
2377
+ }
2378
+ function tr() {
2379
+ return document.readyState === "loading" ? new Promise((e) => {
2380
+ document.addEventListener("DOMContentLoaded", () => e(), { once: !0 });
2381
+ }) : Promise.resolve();
2382
+ }
2383
+ async function nr(e) {
2384
+ let t = er(e);
2385
+ return t.length > 0 || typeof e != "string" ? t : (await tr(), er(e));
2386
+ }
2387
+ function rr(e) {
2388
+ return typeof e == "string" ? document : $(e) ? e.getRootNode() : document;
2389
+ }
2390
+ function ir(e) {
2391
+ let { element: t, observe: n, allowEmpty: r, client: i, onReady: a, onResult: o, onSuccess: s, onError: c, onEvent: l, ...u } = e;
2392
+ return {
2393
+ mode: "server-rendered",
2394
+ ...u
2395
+ };
2396
+ }
2397
+ async function ar(e, t, n, r) {
2398
+ let i = [], o = ir(e);
2399
+ for (let s of r) {
2400
+ let r = n.get(s);
2401
+ if (r) {
2402
+ i.push(r.instance);
2403
+ continue;
2404
+ }
2405
+ let c = await t.mount(s, o), l = [];
2406
+ if (e.onReady?.(c), l.push(c.on("formie:submit:result", (t) => {
2407
+ let n = t;
2408
+ e.onResult?.(n, c), Zn(n) ? e.onSuccess?.(n, c) : e.onError?.(n, c);
2409
+ })), e.onEvent) for (let t of a) l.push(c.on(t, (n) => {
2410
+ e.onEvent?.({
2411
+ name: t,
2412
+ payload: n
2413
+ }, c);
2414
+ }));
2415
+ n.set(s, {
2416
+ instance: c,
2417
+ unsubs: l
2418
+ }), i.push(c);
2419
+ }
2420
+ return i;
2421
+ }
2422
+ async function or(e) {
2423
+ let t = e.client ?? qn(), n = /* @__PURE__ */ new Map(), r = await nr(e.element);
2424
+ if (r.length === 0 && !e.allowEmpty) throw Error(`Formie could not find any elements for ${Qn(e.element)}.`);
2425
+ await ar(e, t, n, r);
2426
+ let i = e.observe ? t.observe(rr(e.element)) : null;
2427
+ return {
2428
+ client: t,
2429
+ get instances() {
2430
+ return Array.from(n.values()).map(({ instance: e }) => e);
2431
+ },
2432
+ get(e) {
2433
+ let r = typeof e == "string" ? document.querySelector(e) : e;
2434
+ return r ? n.get(r)?.instance ?? t.getInstance(r) : null;
2435
+ },
2436
+ async rescan() {
2437
+ let r = er(e.element);
2438
+ return r.length === 0 ? Array.from(n.values()).map(({ instance: e }) => e) : ar(e, t, n, r);
2439
+ },
2440
+ async destroy() {
2441
+ i?.();
2442
+ let e = Array.from(n.entries());
2443
+ for (let [r, i] of e) i.unsubs.forEach((e) => e()), await t.unmount(r), n.delete(r);
2444
+ }
2445
+ };
2446
+ }
2447
+ //#endregion
2448
+ export { a as FORMIE_HTML_EVENT_NAMES, dt as FormieValidator, he as LEGACY_FORMIE_DOM_EVENT_BRIDGES, ge as LEGACY_FORMIE_VALIDATOR_EVENT_BRIDGES, Vt as ModuleRegistry, Se as bindLegacyDomEventCompatibility, we as bindLegacyValidatorCompatibility, fe as buildFieldValueRegistry, d as createDebug, qn as createFormieClient, l as debugLog, u as debugWarn, me as defineAddressModule, oe as defineCaptchaModule, ae as definePassiveCaptchaModule, b as definePaymentModule, le as fieldKeyToInputName, or as formie, i as getFieldModuleEventName, ie as getFormieTranslations, r as getGlobalModuleLifecycleEventName, e as getScopedModuleLifecycleEventName, Yn as hydrateFormieModules, se as inputNameToFieldKey, c as isFormieDebugEnabled, ne as mergeFormieTranslations, ce as normalizeFieldKey, o as normalizeFormieEventName, ue as parseFieldReference, pe as resolveFieldReferenceFromFormData, de as resolveFieldReferenceLive, _e as resolveLegacyCompatibilityOptions, s as setFormieDebugEnabled, re as setFormieTranslations, E as t, t as toDomEventName, T as translate };