@verbb/formie-browser 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/CHANGELOG.md +76 -22
  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-CeDgB9jt.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-DjZOtHfS.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-BQ4a9hmy.js +2659 -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-D0sb8bmX.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-xz4QO7CR.js +536 -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-DbgEFHLO.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/upload-manager-BpqWSHmU.js +2558 -0
  70. package/dist/chunks/utils-Vqp8i_RM.js +49401 -0
  71. package/dist/css/formie-theme.css +2 -0
  72. package/dist/css/theme/_buttons.css +16 -0
  73. package/dist/css/theme/_tokens.css +2 -0
  74. package/dist/css/theme/fields/_address-state.css +94 -0
  75. package/dist/css/theme/fields/_combobox.css +246 -0
  76. package/dist/css/theme/fields/_select.css +13 -0
  77. package/dist/css/theme/fields/_signature.css +19 -0
  78. package/dist/css/theme/fields/_upload-manager.css +279 -0
  79. package/dist/index.js +2448 -39
  80. package/dist/js/core/create-formie-client.d.ts.map +1 -1
  81. package/dist/js/core/submit-result-ui.d.ts.map +1 -1
  82. package/dist/js/core/validation-focus.d.ts +4 -0
  83. package/dist/js/core/validation-focus.d.ts.map +1 -0
  84. package/dist/js/modules/address/api.d.ts +1 -0
  85. package/dist/js/modules/address/api.d.ts.map +1 -1
  86. package/dist/js/modules/address/constants.d.ts +22 -1
  87. package/dist/js/modules/address/constants.d.ts.map +1 -1
  88. package/dist/js/modules/address/host.d.ts +2 -2
  89. package/dist/js/modules/address/host.d.ts.map +1 -1
  90. package/dist/js/modules/address/loqate.d.ts.map +1 -1
  91. package/dist/js/modules/fields/address-country.d.ts +3 -0
  92. package/dist/js/modules/fields/address-country.d.ts.map +1 -0
  93. package/dist/js/modules/fields/address-state.d.ts +3 -0
  94. package/dist/js/modules/fields/address-state.d.ts.map +1 -0
  95. package/dist/js/modules/fields/calculations.d.ts.map +1 -1
  96. package/dist/js/modules/fields/combobox.d.ts +17 -0
  97. package/dist/js/modules/fields/combobox.d.ts.map +1 -0
  98. package/dist/js/modules/fields/custom-google-maps.d.ts +64 -0
  99. package/dist/js/modules/fields/custom-google-maps.d.ts.map +1 -0
  100. package/dist/js/modules/fields/custom-link.d.ts +3 -0
  101. package/dist/js/modules/fields/custom-link.d.ts.map +1 -0
  102. package/dist/js/modules/fields/custom-maps.d.ts +3 -0
  103. package/dist/js/modules/fields/custom-maps.d.ts.map +1 -0
  104. package/dist/js/modules/fields/date-picker.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/signature.d.ts.map +1 -1
  108. package/dist/js/modules/fields/upload-manager.d.ts +3 -0
  109. package/dist/js/modules/fields/upload-manager.d.ts.map +1 -0
  110. package/dist/js/submit/pipeline.d.ts.map +1 -1
  111. package/dist/js/utils/country-from-ip.d.ts +7 -0
  112. package/dist/js/utils/country-from-ip.d.ts.map +1 -0
  113. package/dist/js/utils/field-references.d.ts +1 -0
  114. package/dist/js/utils/field-references.d.ts.map +1 -1
  115. package/dist/js/utils/field-references.row-scope.d.ts +11 -0
  116. package/dist/js/utils/field-references.row-scope.d.ts.map +1 -0
  117. package/package.json +8 -3
  118. package/src/css/formie-theme.css +2 -0
  119. package/src/css/theme/_buttons.css +16 -0
  120. package/src/css/theme/_tokens.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/css/theme/fields/_signature.css +19 -0
  125. package/src/css/theme/fields/_upload-manager.css +279 -0
  126. package/src/js/core/create-formie-client.ts +27 -0
  127. package/src/js/core/submit-result-ui.ts +4 -4
  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/combobox.ts +188 -0
  137. package/src/js/modules/fields/custom-google-maps.ts +416 -0
  138. package/src/js/modules/fields/custom-link.ts +95 -0
  139. package/src/js/modules/fields/custom-maps.ts +339 -0
  140. package/src/js/modules/fields/date-picker.ts +96 -3
  141. package/src/js/modules/fields/index.ts +7 -0
  142. package/src/js/modules/fields/phone-country.ts +6 -0
  143. package/src/js/modules/fields/signature.ts +199 -15
  144. package/src/js/modules/fields/upload-manager.ts +1277 -0
  145. package/src/js/submit/pipeline.ts +11 -1
  146. package/src/js/utils/country-from-ip.ts +54 -0
  147. package/src/js/utils/field-references.row-scope.ts +303 -0
  148. package/src/js/utils/field-references.ts +1 -0
  149. package/src/vendor.d.ts +1 -1
  150. package/dist/chunks/address-finder-BU4roxT6.js +0 -37
  151. package/dist/chunks/bpoint-uNg5j6rt.js +0 -26
  152. package/dist/chunks/calculations-C9t6Zop9.js +0 -147
  153. package/dist/chunks/captcha-eu-BAPzHNts.js +0 -34
  154. package/dist/chunks/checkbox-radio-CHeLNVIK.js +0 -141
  155. package/dist/chunks/conditions-DKxVCsjD.js +0 -459
  156. package/dist/chunks/date-picker-B3iQ797Z.js +0 -4994
  157. package/dist/chunks/eway-DCielIML.js +0 -74
  158. package/dist/chunks/file-upload-DP2TOUYV.js +0 -316
  159. package/dist/chunks/friendly-captcha-v1-DdlcGiFY.js +0 -33
  160. package/dist/chunks/friendly-captcha-v2-76w-YnFm.js +0 -38
  161. package/dist/chunks/go-cardless-rwCkzbNK.js +0 -24
  162. package/dist/chunks/google-address-BD8IZ86V.js +0 -181
  163. package/dist/chunks/hcaptcha-BNNTL6uf.js +0 -56
  164. package/dist/chunks/hidden-CW6Rcf1N.js +0 -31
  165. package/dist/chunks/index-BEsfee-D.js +0 -1839
  166. package/dist/chunks/index-BP7Unm5Y.js +0 -863
  167. package/dist/chunks/index-D6npYxvr.js +0 -4423
  168. package/dist/chunks/loqate-B-ZNS65B.js +0 -55
  169. package/dist/chunks/mollie-BDAZ-1X4.js +0 -24
  170. package/dist/chunks/moneris-B1b0uEtY.js +0 -101
  171. package/dist/chunks/opayo-CC5hraHo.js +0 -122
  172. package/dist/chunks/paddle-B4GmrDsq.js +0 -60
  173. package/dist/chunks/paypal-BFS6XsIS.js +0 -100
  174. package/dist/chunks/payway-DekoJead.js +0 -56
  175. package/dist/chunks/phone-country-Cm5YUeXI.js +0 -3765
  176. package/dist/chunks/place-kit-DizZWV_e.js +0 -42
  177. package/dist/chunks/placekit-autocomplete.esm-LAwfbPZl.js +0 -1299
  178. package/dist/chunks/recaptcha-enterprise-BbOvO7JZ.js +0 -71
  179. package/dist/chunks/recaptcha-shared-Dwg1eVFS.js +0 -15
  180. package/dist/chunks/recaptcha-v2-checkbox-SY3ti5iQ.js +0 -41
  181. package/dist/chunks/recaptcha-v2-invisible-DSmQnn6c.js +0 -59
  182. package/dist/chunks/recaptcha-v3-DNh7YCnR.js +0 -28
  183. package/dist/chunks/repeater-DM0vuFNQ.js +0 -124
  184. package/dist/chunks/rich-text-C8aGYp70.js +0 -304
  185. package/dist/chunks/scripts-CKTFtxPO.js +0 -36
  186. package/dist/chunks/sdk-3SicTWby.js +0 -1559
  187. package/dist/chunks/shared--BU5CFoL.js +0 -80
  188. package/dist/chunks/signature-pFhZfH7d.js +0 -550
  189. package/dist/chunks/snaptcha-VuOUOaLj.js +0 -8
  190. package/dist/chunks/square-BR9pvToy.js +0 -46
  191. package/dist/chunks/stripe-OHUwoV9g.js +0 -202
  192. package/dist/chunks/styles-C3aqgtek.js +0 -21
  193. package/dist/chunks/summary-Da7Ktg3N.js +0 -126
  194. package/dist/chunks/table-C0PmR9bI.js +0 -95
  195. package/dist/chunks/text-limit-mLEwZDIa.js +0 -144
  196. package/dist/chunks/turnstile-9tM7q_LK.js +0 -59
  197. package/dist/chunks/utils-BntI3W4S.js +0 -6149
@@ -8,7 +8,16 @@ import { ensureModuleStyles } from '#modules/styles';
8
8
  const INPUT_SELECTOR = 'input[data-formie-signature-input]';
9
9
  const CANVAS_SELECTOR = 'canvas[data-formie-signature-canvas]';
10
10
  const CLEAR_SELECTOR = '[data-formie-signature-clear]';
11
+ const MESSAGE_SELECTOR = '[data-formie-signature-message]';
11
12
  const MODULE_ID = 'signature';
13
+ const MAX_SIZE_ATTEMPTS = 20;
14
+ const SIZE_RETRY_MS = 100;
15
+ const VISIBILITY_ATTRS = [
16
+ 'hidden',
17
+ 'data-formie-conditionally-hidden',
18
+ 'data-formie-page-hidden',
19
+ 'data-formie-row-hidden',
20
+ ] as const;
12
21
 
13
22
  ensureModuleStyles(MODULE_ID, [signatureCss]);
14
23
 
@@ -18,6 +27,11 @@ type SignatureOptions = {
18
27
  penWeight?: string;
19
28
  };
20
29
 
30
+ type SignatureMessages = {
31
+ noCanvas: string;
32
+ initFailed: string;
33
+ };
34
+
21
35
  function getCanvasSize(canvas: HTMLCanvasElement): { width: number; height: number } {
22
36
  const rect = canvas.getBoundingClientRect();
23
37
 
@@ -27,6 +41,58 @@ function getCanvasSize(canvas: HTMLCanvasElement): { width: number; height: numb
27
41
  };
28
42
  }
29
43
 
44
+ function supportsCanvas(): boolean {
45
+ const probe = document.createElement('canvas');
46
+
47
+ return typeof probe.getContext === 'function' && !!probe.getContext('2d');
48
+ }
49
+
50
+ function getMessageElement(field: HTMLElement): HTMLElement | null {
51
+ const message = field.querySelector(MESSAGE_SELECTOR);
52
+
53
+ return message instanceof HTMLElement ? message : null;
54
+ }
55
+
56
+ function getSignatureMessages(field: HTMLElement): SignatureMessages {
57
+ const message = getMessageElement(field);
58
+
59
+ return {
60
+ noCanvas: message?.dataset.formieSignatureMessageNoCanvas
61
+ || 'This browser does not support canvas, which is required for signatures.',
62
+ initFailed: message?.dataset.formieSignatureMessageInitFailed
63
+ || 'The signature pad could not be loaded. Try refreshing the page.',
64
+ };
65
+ }
66
+
67
+ function setSignatureMessage(field: HTMLElement, canvas: HTMLCanvasElement, message: string | null): void {
68
+ const messageElement = getMessageElement(field);
69
+
70
+ if (!messageElement) {
71
+ return;
72
+ }
73
+
74
+ if (message) {
75
+ messageElement.textContent = message;
76
+ messageElement.hidden = false;
77
+ canvas.setAttribute('aria-hidden', 'true');
78
+ field.classList.add('formie-signature-has-message');
79
+ return;
80
+ }
81
+
82
+ messageElement.textContent = '';
83
+ messageElement.hidden = true;
84
+ canvas.removeAttribute('aria-hidden');
85
+ field.classList.remove('formie-signature-has-message');
86
+ }
87
+
88
+ function isFieldVisible(field: HTMLElement): boolean {
89
+ return !field.hasAttribute('hidden')
90
+ && !field.hasAttribute('data-formie-conditionally-hidden')
91
+ && !field.hasAttribute('data-formie-page-hidden')
92
+ && !field.hasAttribute('data-formie-row-hidden')
93
+ && field.getClientRects().length > 0;
94
+ }
95
+
30
96
  function drawValueOnCanvas(canvas: HTMLCanvasElement, value: string): void {
31
97
  if (!value) {
32
98
  return;
@@ -45,6 +111,18 @@ function drawValueOnCanvas(canvas: HTMLCanvasElement, value: string): void {
45
111
  };
46
112
  }
47
113
 
114
+ async function restoreSignatureValue(signaturePad: SignaturePad, canvas: HTMLCanvasElement, value: string): Promise<void> {
115
+ if (!value) {
116
+ return;
117
+ }
118
+
119
+ try {
120
+ await signaturePad.fromDataURL(value);
121
+ } catch {
122
+ drawValueOnCanvas(canvas, value);
123
+ }
124
+ }
125
+
48
126
  function initSignatureField(
49
127
  root: HTMLElement,
50
128
  field: HTMLElement,
@@ -53,8 +131,21 @@ function initSignatureField(
53
131
  clearButton: HTMLElement | null,
54
132
  options: SignatureOptions,
55
133
  ): () => void {
134
+ const messages = getSignatureMessages(field);
135
+
136
+ if (!supportsCanvas()) {
137
+ setSignatureMessage(field, canvas, messages.noCanvas);
138
+
139
+ return () => {};
140
+ }
141
+
56
142
  const penWeight = parseFloat(options.penWeight || '2') || 2;
57
143
  const resizeTarget = canvas.parentElement instanceof HTMLElement ? canvas.parentElement : field;
144
+ let sizeAttempts = 0;
145
+ let sizeRetryTimer: number | null = null;
146
+ let readyDispatched = false;
147
+ let initFailed = false;
148
+
58
149
  const signaturePad = new SignaturePad(canvas, {
59
150
  backgroundColor: options.backgroundColor || 'rgba(255, 255, 255, 0)',
60
151
  penColor: options.penColor || '#000000',
@@ -63,51 +154,142 @@ function initSignatureField(
63
154
  maxWidth: penWeight,
64
155
  });
65
156
 
66
- const resizeCanvas = () => {
157
+ const clearSizeRetry = () => {
158
+ if (sizeRetryTimer !== null) {
159
+ window.clearTimeout(sizeRetryTimer);
160
+ sizeRetryTimer = null;
161
+ }
162
+ };
163
+
164
+ const markReady = () => {
165
+ if (readyDispatched) {
166
+ return;
167
+ }
168
+
169
+ readyDispatched = true;
170
+ initFailed = false;
171
+ setSignatureMessage(field, canvas, null);
172
+ dispatchFieldEvent(field, MODULE_ID, 'init', {
173
+ signature: signaturePad,
174
+ });
175
+ };
176
+
177
+ const markInitFailed = () => {
178
+ if (readyDispatched || initFailed) {
179
+ return;
180
+ }
181
+
182
+ initFailed = true;
183
+ setSignatureMessage(field, canvas, messages.initFailed);
184
+ };
185
+
186
+ const resizeCanvas = async(): Promise<boolean> => {
67
187
  const { width, height } = getCanvasSize(canvas);
68
188
 
69
189
  if (!(width > 0) || !(height > 0)) {
70
- return;
190
+ return false;
71
191
  }
72
192
 
73
193
  const ratio = Math.max(window.devicePixelRatio || 1, 1);
74
194
  const context = canvas.getContext('2d');
75
195
  if (!context) {
76
- return;
196
+ return false;
77
197
  }
78
198
 
79
- // SignaturePad clears bitmap state when the canvas size changes, so resize
80
- // captures the current data URL first and redraws it onto the new surface.
81
199
  const existingValue = input.value || (signaturePad.isEmpty() ? '' : signaturePad.toDataURL());
200
+
82
201
  canvas.width = width * ratio;
83
202
  canvas.height = height * ratio;
84
203
  context.setTransform(1, 0, 0, 1, 0, 0);
85
204
  context.scale(ratio, ratio);
86
205
  signaturePad.clear();
87
- drawValueOnCanvas(canvas, existingValue);
206
+
207
+ await restoreSignatureValue(signaturePad, canvas, existingValue);
208
+ markReady();
209
+
210
+ return true;
211
+ };
212
+
213
+ const scheduleSizeRetry = () => {
214
+ if (readyDispatched || initFailed) {
215
+ return;
216
+ }
217
+
218
+ if (sizeAttempts >= MAX_SIZE_ATTEMPTS) {
219
+ markInitFailed();
220
+ return;
221
+ }
222
+
223
+ clearSizeRetry();
224
+ sizeRetryTimer = window.setTimeout(() => {
225
+ sizeRetryTimer = null;
226
+ sizeAttempts += 1;
227
+ void attemptResize();
228
+ }, SIZE_RETRY_MS);
229
+ };
230
+
231
+ const attemptResize = async() => {
232
+ const sized = await resizeCanvas();
233
+
234
+ if (!sized) {
235
+ scheduleSizeRetry();
236
+ return;
237
+ }
238
+
239
+ clearSizeRetry();
240
+ sizeAttempts = 0;
88
241
  };
89
242
 
90
243
  const scheduleResize = (delay = 0) => {
91
244
  window.setTimeout(() => {
92
245
  window.requestAnimationFrame(() => {
93
- resizeCanvas();
246
+ void attemptResize();
94
247
  });
95
248
  }, delay);
96
249
  };
97
- const resizeHandler = () => {
250
+
251
+ const requestResize = () => {
252
+ if (isFieldVisible(field) && !readyDispatched) {
253
+ initFailed = false;
254
+ }
255
+
98
256
  scheduleResize();
99
257
  };
258
+
259
+ const resizeHandler = () => {
260
+ requestResize();
261
+ };
262
+
100
263
  const pageNavigateHandler = () => {
101
- // Multi-page forms can reveal a signature pad after layout changes; delay
102
- // slightly so the newly visible page has settled before measuring.
264
+ if (!isFieldVisible(field)) {
265
+ return;
266
+ }
267
+
268
+ sizeAttempts = 0;
269
+ initFailed = false;
103
270
  scheduleResize(100);
104
271
  };
272
+
273
+ const visibilityHandler = () => {
274
+ if (!isFieldVisible(field)) {
275
+ return;
276
+ }
277
+
278
+ sizeAttempts = 0;
279
+ initFailed = false;
280
+ requestResize();
281
+ };
282
+
105
283
  const resizeObserver = typeof ResizeObserver === 'undefined'
106
284
  ? null
107
285
  : new ResizeObserver(() => {
108
- scheduleResize();
286
+ requestResize();
109
287
  });
110
288
 
289
+ const visibilityObserver = new MutationObserver(() => {
290
+ visibilityHandler();
291
+ });
292
+
111
293
  const syncInputValue = (nextValue: string) => {
112
294
  const valueChanged = input.value !== nextValue;
113
295
  input.value = nextValue;
@@ -133,21 +315,23 @@ function initSignatureField(
133
315
  window.addEventListener('resize', resizeHandler);
134
316
  root.addEventListener('formie:page:navigate:after', pageNavigateHandler as EventListener);
135
317
  resizeObserver?.observe(resizeTarget);
318
+ visibilityObserver.observe(field, {
319
+ attributes: true,
320
+ attributeFilter: [...VISIBILITY_ATTRS],
321
+ });
136
322
  scheduleResize();
137
323
 
138
324
  if (clearButton) {
139
325
  clearButton.addEventListener('click', clearSignature);
140
326
  }
141
327
 
142
- dispatchFieldEvent(field, MODULE_ID, 'init', {
143
- signature: signaturePad,
144
- });
145
-
146
328
  return () => {
329
+ clearSizeRetry();
147
330
  signaturePad.removeEventListener('endStroke', syncValue);
148
331
  window.removeEventListener('resize', resizeHandler);
149
332
  root.removeEventListener('formie:page:navigate:after', pageNavigateHandler as EventListener);
150
333
  resizeObserver?.disconnect();
334
+ visibilityObserver.disconnect();
151
335
  if (clearButton) {
152
336
  clearButton.removeEventListener('click', clearSignature);
153
337
  }