@verbb/formie-browser 1.0.0 → 1.0.2

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 (120) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/chunks/address-finder-CQW81kY0.js +37 -0
  3. package/dist/chunks/bpoint-D8OjLmsn.js +26 -0
  4. package/dist/chunks/calculations-BqZsENCq.js +147 -0
  5. package/dist/chunks/captcha-eu-DIa6aUWz.js +34 -0
  6. package/dist/chunks/checkbox-radio-BI-UjgMF.js +136 -0
  7. package/dist/chunks/conditions-BVl6jTYo.js +433 -0
  8. package/dist/chunks/date-picker-69TgvErA.js +4994 -0
  9. package/dist/chunks/eway-1GPxH6DU.js +74 -0
  10. package/dist/chunks/file-upload-BDZZftgL.js +281 -0
  11. package/dist/chunks/friendly-captcha-v1-DA2QPKA3.js +33 -0
  12. package/dist/chunks/friendly-captcha-v2-BorOWiz_.js +38 -0
  13. package/dist/chunks/go-cardless-DwBgERcA.js +24 -0
  14. package/dist/chunks/google-address-BcTBncyS.js +162 -0
  15. package/dist/chunks/hcaptcha-BchdVCqq.js +56 -0
  16. package/dist/chunks/hidden-D8RqSPt7.js +31 -0
  17. package/dist/chunks/index-BEsfee-D.js +1839 -0
  18. package/dist/chunks/index-BP7Unm5Y.js +863 -0
  19. package/dist/chunks/index-C1ZOKiAi.js +4229 -0
  20. package/dist/chunks/loqate-nXuTX7In.js +55 -0
  21. package/dist/chunks/mollie-qdCynQCd.js +24 -0
  22. package/dist/chunks/moneris-BNEA-laO.js +101 -0
  23. package/dist/chunks/opayo-BJtXOkuK.js +122 -0
  24. package/dist/chunks/paddle-D72Pa8kr.js +60 -0
  25. package/dist/chunks/paypal-Cqt2bned.js +100 -0
  26. package/dist/chunks/payway-BjCqsc0H.js +56 -0
  27. package/dist/chunks/phone-country-K9pYAlzM.js +3765 -0
  28. package/dist/chunks/place-kit-Dg6f_UoM.js +42 -0
  29. package/dist/chunks/placekit-autocomplete.esm-LAwfbPZl.js +1299 -0
  30. package/dist/chunks/recaptcha-enterprise--VYAeeqz.js +71 -0
  31. package/dist/chunks/recaptcha-shared-PSIEEEe1.js +15 -0
  32. package/dist/chunks/recaptcha-v2-checkbox-atBNe5ml.js +41 -0
  33. package/dist/chunks/recaptcha-v2-invisible-DnBufNPT.js +59 -0
  34. package/dist/chunks/recaptcha-v3-CF6O8rDj.js +28 -0
  35. package/dist/chunks/repeater-CB7Yojvx.js +124 -0
  36. package/dist/chunks/rich-text-nAV_SQZo.js +304 -0
  37. package/dist/chunks/scripts-BkAAux0i.js +36 -0
  38. package/dist/chunks/sdk-3SicTWby.js +1559 -0
  39. package/dist/chunks/shared-DGqeMvcJ.js +80 -0
  40. package/dist/chunks/signature-BT6CsQ6n.js +550 -0
  41. package/dist/chunks/snaptcha-C7qQo02f.js +8 -0
  42. package/dist/chunks/square-C5AH3trb.js +46 -0
  43. package/dist/chunks/stripe-EJK0RyUv.js +202 -0
  44. package/dist/chunks/styles-C3aqgtek.js +21 -0
  45. package/dist/chunks/summary-DC_ipXCU.js +126 -0
  46. package/dist/chunks/table-BEAI99qo.js +95 -0
  47. package/dist/chunks/text-limit-Blgq5G-G.js +135 -0
  48. package/dist/chunks/turnstile-_uCRwnU-.js +59 -0
  49. package/dist/chunks/utils-BntI3W4S.js +6149 -0
  50. package/dist/index.js +39 -3205
  51. package/package.json +5 -5
  52. package/src/js/modules/fields/file-upload.ts +1 -1
  53. package/src/js/modules/fields/repeater.ts +1 -1
  54. package/src/js/modules/fields/rich-text.ts +2 -2
  55. package/src/js/modules/fields/signature.ts +1 -1
  56. package/src/js/modules/fields/summary.ts +1 -1
  57. package/src/js/modules/fields/table.ts +1 -1
  58. package/src/js/modules/fields/text-limit.ts +1 -1
  59. package/src/js/modules/payments/paypal.ts +1 -1
  60. package/src/js/modules/payments/payway.ts +1 -1
  61. package/src/js/modules/payments/stripe.ts +1 -1
  62. package/dist/chunks/address-finder-DfMCiW89.js +0 -47
  63. package/dist/chunks/api-CbqEMQT5.js +0 -181
  64. package/dist/chunks/api-DE7LfK-R.js +0 -960
  65. package/dist/chunks/api-DOfDzYC_.js +0 -538
  66. package/dist/chunks/async-B3DUf1GZ.js +0 -26
  67. package/dist/chunks/bpoint-Ciy3yY9Q.js +0 -34
  68. package/dist/chunks/calculations-CkYAqO_-.js +0 -197
  69. package/dist/chunks/captcha-eu-DnOWhMwr.js +0 -43
  70. package/dist/chunks/checkbox-radio-0x7Tc0br.js +0 -197
  71. package/dist/chunks/chunk-K6L4z4UQ.js +0 -24
  72. package/dist/chunks/conditions-4fXKhEJS.js +0 -609
  73. package/dist/chunks/date-picker-B6iZkjHS.js +0 -6204
  74. package/dist/chunks/debug-KnZeKYBI.js +0 -39
  75. package/dist/chunks/dist-D09GnXMW.js +0 -2663
  76. package/dist/chunks/event-names-DamGPtXR.js +0 -51
  77. package/dist/chunks/eway-DEAYcwT0.js +0 -86
  78. package/dist/chunks/field-references.keys-BpBZ_quS.js +0 -24
  79. package/dist/chunks/field-references.resolver-Ba6xhiJC.js +0 -183
  80. package/dist/chunks/file-upload-Bh63PQSE.js +0 -430
  81. package/dist/chunks/friendly-captcha-v1-CqO4WVre.js +0 -40
  82. package/dist/chunks/friendly-captcha-v2-CyykcJcM.js +0 -47
  83. package/dist/chunks/friendly-challenge-Dg8XkStd.js +0 -1101
  84. package/dist/chunks/go-cardless-CuND59rR.js +0 -26
  85. package/dist/chunks/google-address--uR8WDSm.js +0 -208
  86. package/dist/chunks/hcaptcha-CmaFUesv.js +0 -72
  87. package/dist/chunks/hidden-CYnZYple.js +0 -36
  88. package/dist/chunks/http-18nn97DZ.js +0 -29
  89. package/dist/chunks/i18n-vUh-KGiH.js +0 -55
  90. package/dist/chunks/loqate-BICNJlVK.js +0 -97
  91. package/dist/chunks/mollie-DwlsgHZ1.js +0 -26
  92. package/dist/chunks/moneris-B_IFZFTx.js +0 -159
  93. package/dist/chunks/opayo-U2x_TOII.js +0 -192
  94. package/dist/chunks/paddle-BqXFrc79.js +0 -75
  95. package/dist/chunks/paypal-Cn_DYGDb.js +0 -121
  96. package/dist/chunks/payway-Rnq796eC.js +0 -75
  97. package/dist/chunks/phone-country-B6Me4lK0.js +0 -3317
  98. package/dist/chunks/place-kit-ldUl-u9w.js +0 -56
  99. package/dist/chunks/placekit-autocomplete.esm-D-lGeaZl.js +0 -1771
  100. package/dist/chunks/recaptcha-enterprise-DPJNyv1X.js +0 -72
  101. package/dist/chunks/recaptcha-shared-DTI4qWVR.js +0 -22
  102. package/dist/chunks/recaptcha-v2-checkbox-zFjpvJ5c.js +0 -49
  103. package/dist/chunks/recaptcha-v2-invisible-CnYtkNvz.js +0 -62
  104. package/dist/chunks/recaptcha-v3-EAlWhnkX.js +0 -33
  105. package/dist/chunks/repeater-CXD1eLSn.js +0 -151
  106. package/dist/chunks/rich-text-DkmZRhGj.js +0 -442
  107. package/dist/chunks/scripts-BGD_iU_6.js +0 -41
  108. package/dist/chunks/sdk-B7u9fTlP.js +0 -2103
  109. package/dist/chunks/shared-DC6_1u8X.js +0 -85
  110. package/dist/chunks/signature-E9KyYXS1.js +0 -765
  111. package/dist/chunks/snaptcha-CCDunGeb.js +0 -8
  112. package/dist/chunks/square-BLqK51rS.js +0 -61
  113. package/dist/chunks/stripe-B8gHpZNC.js +0 -273
  114. package/dist/chunks/styles-BIh6g7V_.js +0 -22
  115. package/dist/chunks/summary-EcNE0cvg.js +0 -191
  116. package/dist/chunks/table-yxEDL6kA.js +0 -124
  117. package/dist/chunks/text-limit-D0H_Ca2c.js +0 -179
  118. package/dist/chunks/theme-classes-vSHpdCUO.js +0 -59
  119. package/dist/chunks/turnstile-DP0bdR7T.js +0 -68
  120. package/dist/chunks/utils-ByrEVYrJ.js +0 -49584
@@ -1,765 +0,0 @@
1
- import { t as ensureModuleStyles } from "./styles-BIh6g7V_.js";
2
- import { r as getModuleFieldContainers, t as dispatchFieldEvent } from "./shared-DC6_1u8X.js";
3
- //#region ../../node_modules/signature_pad/dist/signature_pad.js
4
- /*!
5
- * Signature Pad v5.1.3 | https://github.com/szimek/signature_pad
6
- * (c) 2025 Szymon Nowak | Released under the MIT license
7
- */
8
- var Point = class {
9
- x;
10
- y;
11
- pressure;
12
- time;
13
- constructor(x, y, pressure, time) {
14
- if (isNaN(x) || isNaN(y)) throw new Error(`Point is invalid: (${x}, ${y})`);
15
- this.x = +x;
16
- this.y = +y;
17
- this.pressure = pressure || 0;
18
- this.time = time || Date.now();
19
- }
20
- distanceTo(start) {
21
- return Math.sqrt(Math.pow(this.x - start.x, 2) + Math.pow(this.y - start.y, 2));
22
- }
23
- equals(other) {
24
- return this.x === other.x && this.y === other.y && this.pressure === other.pressure && this.time === other.time;
25
- }
26
- velocityFrom(start) {
27
- return this.time !== start.time ? this.distanceTo(start) / (this.time - start.time) : 0;
28
- }
29
- };
30
- var Bezier = class _Bezier {
31
- constructor(startPoint, control2, control1, endPoint, startWidth, endWidth) {
32
- this.startPoint = startPoint;
33
- this.control2 = control2;
34
- this.control1 = control1;
35
- this.endPoint = endPoint;
36
- this.startWidth = startWidth;
37
- this.endWidth = endWidth;
38
- }
39
- static fromPoints(points, widths) {
40
- const c2 = this.calculateControlPoints(points[0], points[1], points[2]).c2;
41
- const c3 = this.calculateControlPoints(points[1], points[2], points[3]).c1;
42
- return new _Bezier(points[1], c2, c3, points[2], widths.start, widths.end);
43
- }
44
- static calculateControlPoints(s1, s2, s3) {
45
- const dx1 = s1.x - s2.x;
46
- const dy1 = s1.y - s2.y;
47
- const dx2 = s2.x - s3.x;
48
- const dy2 = s2.y - s3.y;
49
- const m1 = {
50
- x: (s1.x + s2.x) / 2,
51
- y: (s1.y + s2.y) / 2
52
- };
53
- const m2 = {
54
- x: (s2.x + s3.x) / 2,
55
- y: (s2.y + s3.y) / 2
56
- };
57
- const l1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
58
- const l2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
59
- const dxm = m1.x - m2.x;
60
- const dym = m1.y - m2.y;
61
- const k = l1 + l2 == 0 ? 0 : l2 / (l1 + l2);
62
- const cm = {
63
- x: m2.x + dxm * k,
64
- y: m2.y + dym * k
65
- };
66
- const tx = s2.x - cm.x;
67
- const ty = s2.y - cm.y;
68
- return {
69
- c1: new Point(m1.x + tx, m1.y + ty),
70
- c2: new Point(m2.x + tx, m2.y + ty)
71
- };
72
- }
73
- length() {
74
- const steps = 10;
75
- let length = 0;
76
- let px;
77
- let py;
78
- for (let i = 0; i <= steps; i += 1) {
79
- const t = i / steps;
80
- const cx = this.point(t, this.startPoint.x, this.control1.x, this.control2.x, this.endPoint.x);
81
- const cy = this.point(t, this.startPoint.y, this.control1.y, this.control2.y, this.endPoint.y);
82
- if (i > 0) {
83
- const xdiff = cx - px;
84
- const ydiff = cy - py;
85
- length += Math.sqrt(xdiff * xdiff + ydiff * ydiff);
86
- }
87
- px = cx;
88
- py = cy;
89
- }
90
- return length;
91
- }
92
- point(t, start, c1, c2, end) {
93
- return start * (1 - t) * (1 - t) * (1 - t) + 3 * c1 * (1 - t) * (1 - t) * t + 3 * c2 * (1 - t) * t * t + end * t * t * t;
94
- }
95
- };
96
- var SignatureEventTarget = class {
97
- _et;
98
- constructor() {
99
- try {
100
- this._et = new EventTarget();
101
- } catch {
102
- this._et = document;
103
- }
104
- }
105
- addEventListener(type, listener, options) {
106
- this._et.addEventListener(type, listener, options);
107
- }
108
- dispatchEvent(event) {
109
- return this._et.dispatchEvent(event);
110
- }
111
- removeEventListener(type, callback, options) {
112
- this._et.removeEventListener(type, callback, options);
113
- }
114
- };
115
- function throttle(fn, wait = 250) {
116
- let previous = 0;
117
- let timeout = null;
118
- let result;
119
- let storedContext;
120
- let storedArgs;
121
- const later = () => {
122
- previous = Date.now();
123
- timeout = null;
124
- result = fn.apply(storedContext, storedArgs);
125
- if (!timeout) {
126
- storedContext = null;
127
- storedArgs = [];
128
- }
129
- };
130
- return function wrapper(...args) {
131
- const now = Date.now();
132
- const remaining = wait - (now - previous);
133
- storedContext = this;
134
- storedArgs = args;
135
- if (remaining <= 0 || remaining > wait) {
136
- if (timeout) {
137
- clearTimeout(timeout);
138
- timeout = null;
139
- }
140
- previous = now;
141
- result = fn.apply(storedContext, storedArgs);
142
- if (!timeout) {
143
- storedContext = null;
144
- storedArgs = [];
145
- }
146
- } else if (!timeout) timeout = window.setTimeout(later, remaining);
147
- return result;
148
- };
149
- }
150
- var SignaturePad = class _SignaturePad extends SignatureEventTarget {
151
- constructor(canvas, options = {}) {
152
- super();
153
- this.canvas = canvas;
154
- this.velocityFilterWeight = options.velocityFilterWeight || .7;
155
- this.minWidth = options.minWidth || .5;
156
- this.maxWidth = options.maxWidth || 2.5;
157
- this.throttle = options.throttle ?? 16;
158
- this.minDistance = options.minDistance ?? 5;
159
- this.dotSize = options.dotSize || 0;
160
- this.penColor = options.penColor || "black";
161
- this.backgroundColor = options.backgroundColor || "rgba(0,0,0,0)";
162
- this.compositeOperation = options.compositeOperation || "source-over";
163
- this.canvasContextOptions = options.canvasContextOptions ?? {};
164
- this._strokeMoveUpdate = this.throttle ? throttle(_SignaturePad.prototype._strokeUpdate, this.throttle) : _SignaturePad.prototype._strokeUpdate;
165
- this._handleMouseDown = this._handleMouseDown.bind(this);
166
- this._handleMouseMove = this._handleMouseMove.bind(this);
167
- this._handleMouseUp = this._handleMouseUp.bind(this);
168
- this._handleTouchStart = this._handleTouchStart.bind(this);
169
- this._handleTouchMove = this._handleTouchMove.bind(this);
170
- this._handleTouchEnd = this._handleTouchEnd.bind(this);
171
- this._handlePointerDown = this._handlePointerDown.bind(this);
172
- this._handlePointerMove = this._handlePointerMove.bind(this);
173
- this._handlePointerUp = this._handlePointerUp.bind(this);
174
- this._handlePointerCancel = this._handlePointerCancel.bind(this);
175
- this._handleTouchCancel = this._handleTouchCancel.bind(this);
176
- this._ctx = canvas.getContext("2d", this.canvasContextOptions);
177
- this.clear();
178
- this.on();
179
- }
180
- dotSize;
181
- minWidth;
182
- maxWidth;
183
- penColor;
184
- minDistance;
185
- velocityFilterWeight;
186
- compositeOperation;
187
- backgroundColor;
188
- throttle;
189
- canvasContextOptions;
190
- _ctx;
191
- _drawingStroke = false;
192
- _isEmpty = true;
193
- _dataUrl;
194
- _dataUrlOptions;
195
- _lastPoints = [];
196
- _data = [];
197
- _lastVelocity = 0;
198
- _lastWidth = 0;
199
- _strokeMoveUpdate;
200
- _strokePointerId;
201
- clear() {
202
- const { _ctx: ctx, canvas } = this;
203
- ctx.fillStyle = this.backgroundColor;
204
- ctx.clearRect(0, 0, canvas.width, canvas.height);
205
- ctx.fillRect(0, 0, canvas.width, canvas.height);
206
- this._data = [];
207
- this._reset(this._getPointGroupOptions());
208
- this._isEmpty = true;
209
- this._dataUrl = void 0;
210
- this._dataUrlOptions = void 0;
211
- this._strokePointerId = void 0;
212
- }
213
- redraw() {
214
- const data = this._data;
215
- const dataUrl = this._dataUrl;
216
- const dataUrlOptions = this._dataUrlOptions;
217
- this.clear();
218
- if (dataUrl) this.fromDataURL(dataUrl, dataUrlOptions);
219
- this.fromData(data, { clear: false });
220
- }
221
- fromDataURL(dataUrl, options = {}) {
222
- return new Promise((resolve, reject) => {
223
- const image = new Image();
224
- const ratio = options.ratio || window.devicePixelRatio || 1;
225
- const width = options.width || this.canvas.width / ratio;
226
- const height = options.height || this.canvas.height / ratio;
227
- const xOffset = options.xOffset || 0;
228
- const yOffset = options.yOffset || 0;
229
- this._reset(this._getPointGroupOptions());
230
- image.onload = () => {
231
- this._ctx.drawImage(image, xOffset, yOffset, width, height);
232
- resolve();
233
- };
234
- image.onerror = (error) => {
235
- reject(error);
236
- };
237
- image.crossOrigin = "anonymous";
238
- image.src = dataUrl;
239
- this._isEmpty = false;
240
- this._dataUrl = dataUrl;
241
- this._dataUrlOptions = { ...options };
242
- });
243
- }
244
- toDataURL(type = "image/png", encoderOptions) {
245
- switch (type) {
246
- case "image/svg+xml":
247
- if (typeof encoderOptions !== "object") encoderOptions = void 0;
248
- return `data:image/svg+xml;base64,${btoa(this.toSVG(encoderOptions))}`;
249
- default:
250
- if (typeof encoderOptions !== "number") encoderOptions = void 0;
251
- return this.canvas.toDataURL(type, encoderOptions);
252
- }
253
- }
254
- on() {
255
- this.canvas.style.touchAction = "none";
256
- this.canvas.style.msTouchAction = "none";
257
- this.canvas.style.userSelect = "none";
258
- this.canvas.style.webkitUserSelect = "none";
259
- const isIOS = /Macintosh/.test(navigator.userAgent) && "ontouchstart" in document;
260
- if (window.PointerEvent && !isIOS) this._handlePointerEvents();
261
- else {
262
- this._handleMouseEvents();
263
- if ("ontouchstart" in window) this._handleTouchEvents();
264
- }
265
- }
266
- off() {
267
- this.canvas.style.touchAction = "auto";
268
- this.canvas.style.msTouchAction = "auto";
269
- this.canvas.style.userSelect = "auto";
270
- this.canvas.style.webkitUserSelect = "auto";
271
- this.canvas.removeEventListener("pointerdown", this._handlePointerDown);
272
- this.canvas.removeEventListener("mousedown", this._handleMouseDown);
273
- this.canvas.removeEventListener("touchstart", this._handleTouchStart);
274
- this._removeMoveUpEventListeners();
275
- }
276
- _getListenerFunctions() {
277
- const canvasWindow = window.document === this.canvas.ownerDocument ? window : this.canvas.ownerDocument.defaultView ?? this.canvas.ownerDocument;
278
- return {
279
- addEventListener: canvasWindow.addEventListener.bind(canvasWindow),
280
- removeEventListener: canvasWindow.removeEventListener.bind(canvasWindow)
281
- };
282
- }
283
- _removeMoveUpEventListeners() {
284
- const { removeEventListener } = this._getListenerFunctions();
285
- removeEventListener("pointermove", this._handlePointerMove);
286
- removeEventListener("pointerup", this._handlePointerUp);
287
- removeEventListener("pointercancel", this._handlePointerCancel);
288
- removeEventListener("mousemove", this._handleMouseMove);
289
- removeEventListener("mouseup", this._handleMouseUp);
290
- removeEventListener("touchmove", this._handleTouchMove);
291
- removeEventListener("touchend", this._handleTouchEnd);
292
- removeEventListener("touchcancel", this._handleTouchCancel);
293
- }
294
- isEmpty() {
295
- return this._isEmpty;
296
- }
297
- fromData(pointGroups, { clear = true } = {}) {
298
- if (clear) this.clear();
299
- this._fromData(pointGroups, this._drawCurve.bind(this), this._drawDot.bind(this));
300
- this._data = this._data.concat(pointGroups);
301
- }
302
- toData() {
303
- return this._data;
304
- }
305
- _isLeftButtonPressed(event, only) {
306
- if (only) return event.buttons === 1;
307
- return (event.buttons & 1) === 1;
308
- }
309
- _pointerEventToSignatureEvent(event) {
310
- return {
311
- event,
312
- type: event.type,
313
- x: event.clientX,
314
- y: event.clientY,
315
- pressure: "pressure" in event ? event.pressure : 0
316
- };
317
- }
318
- _touchEventToSignatureEvent(event) {
319
- const touch = event.changedTouches[0];
320
- return {
321
- event,
322
- type: event.type,
323
- x: touch.clientX,
324
- y: touch.clientY,
325
- pressure: touch.force
326
- };
327
- }
328
- _handleMouseDown(event) {
329
- if (!this._isLeftButtonPressed(event, true) || this._drawingStroke) return;
330
- this._strokeBegin(this._pointerEventToSignatureEvent(event));
331
- }
332
- _handleMouseMove(event) {
333
- if (!this._isLeftButtonPressed(event, true) || !this._drawingStroke) {
334
- this._strokeEnd(this._pointerEventToSignatureEvent(event), false);
335
- return;
336
- }
337
- this._strokeMoveUpdate(this._pointerEventToSignatureEvent(event));
338
- }
339
- _handleMouseUp(event) {
340
- if (this._isLeftButtonPressed(event)) return;
341
- this._strokeEnd(this._pointerEventToSignatureEvent(event));
342
- }
343
- _handleTouchStart(event) {
344
- if (event.targetTouches.length !== 1 || this._drawingStroke) return;
345
- if (event.cancelable) event.preventDefault();
346
- this._strokeBegin(this._touchEventToSignatureEvent(event));
347
- }
348
- _handleTouchMove(event) {
349
- if (event.targetTouches.length !== 1) return;
350
- if (event.cancelable) event.preventDefault();
351
- if (!this._drawingStroke) {
352
- this._strokeEnd(this._touchEventToSignatureEvent(event), false);
353
- return;
354
- }
355
- this._strokeMoveUpdate(this._touchEventToSignatureEvent(event));
356
- }
357
- _handleTouchEnd(event) {
358
- if (event.targetTouches.length !== 0) return;
359
- if (event.cancelable) event.preventDefault();
360
- this._strokeEnd(this._touchEventToSignatureEvent(event));
361
- }
362
- _handlePointerCancel(event) {
363
- if (!this._allowPointerId(event)) return;
364
- event.preventDefault();
365
- this._strokeEnd(this._pointerEventToSignatureEvent(event), false);
366
- }
367
- _handleTouchCancel(event) {
368
- if (event.cancelable) event.preventDefault();
369
- this._strokeEnd(this._touchEventToSignatureEvent(event), false);
370
- }
371
- _getPointerId(event) {
372
- return event.persistentDeviceId || event.pointerId;
373
- }
374
- _allowPointerId(event, allowUndefined = false) {
375
- if (typeof this._strokePointerId === "undefined") return allowUndefined;
376
- return this._getPointerId(event) === this._strokePointerId;
377
- }
378
- _handlePointerDown(event) {
379
- if (this._drawingStroke || !this._isLeftButtonPressed(event) || !this._allowPointerId(event, true)) return;
380
- this._strokePointerId = this._getPointerId(event);
381
- event.preventDefault();
382
- this._strokeBegin(this._pointerEventToSignatureEvent(event));
383
- }
384
- _handlePointerMove(event) {
385
- if (!this._allowPointerId(event)) return;
386
- if (!this._isLeftButtonPressed(event, true) || !this._drawingStroke) {
387
- this._strokeEnd(this._pointerEventToSignatureEvent(event), false);
388
- return;
389
- }
390
- event.preventDefault();
391
- this._strokeMoveUpdate(this._pointerEventToSignatureEvent(event));
392
- }
393
- _handlePointerUp(event) {
394
- if (this._isLeftButtonPressed(event) || !this._allowPointerId(event)) return;
395
- event.preventDefault();
396
- this._strokeEnd(this._pointerEventToSignatureEvent(event));
397
- }
398
- _getPointGroupOptions(group) {
399
- return {
400
- penColor: group && "penColor" in group ? group.penColor : this.penColor,
401
- dotSize: group && "dotSize" in group ? group.dotSize : this.dotSize,
402
- minWidth: group && "minWidth" in group ? group.minWidth : this.minWidth,
403
- maxWidth: group && "maxWidth" in group ? group.maxWidth : this.maxWidth,
404
- velocityFilterWeight: group && "velocityFilterWeight" in group ? group.velocityFilterWeight : this.velocityFilterWeight,
405
- compositeOperation: group && "compositeOperation" in group ? group.compositeOperation : this.compositeOperation
406
- };
407
- }
408
- _strokeBegin(event) {
409
- if (!this.dispatchEvent(new CustomEvent("beginStroke", {
410
- detail: event,
411
- cancelable: true
412
- }))) return;
413
- const { addEventListener } = this._getListenerFunctions();
414
- switch (event.event.type) {
415
- case "mousedown":
416
- addEventListener("mousemove", this._handleMouseMove, { passive: false });
417
- addEventListener("mouseup", this._handleMouseUp, { passive: false });
418
- break;
419
- case "touchstart":
420
- addEventListener("touchmove", this._handleTouchMove, { passive: false });
421
- addEventListener("touchend", this._handleTouchEnd, { passive: false });
422
- addEventListener("touchcancel", this._handleTouchCancel, { passive: false });
423
- break;
424
- case "pointerdown":
425
- addEventListener("pointermove", this._handlePointerMove, { passive: false });
426
- addEventListener("pointerup", this._handlePointerUp, { passive: false });
427
- addEventListener("pointercancel", this._handlePointerCancel, { passive: false });
428
- break;
429
- default:
430
- }
431
- this._drawingStroke = true;
432
- const pointGroupOptions = this._getPointGroupOptions();
433
- const newPointGroup = {
434
- ...pointGroupOptions,
435
- points: []
436
- };
437
- this._data.push(newPointGroup);
438
- this._reset(pointGroupOptions);
439
- this._strokeUpdate(event);
440
- }
441
- _strokeUpdate(event) {
442
- if (!this._drawingStroke) return;
443
- if (this._data.length === 0) {
444
- this._strokeBegin(event);
445
- return;
446
- }
447
- this.dispatchEvent(new CustomEvent("beforeUpdateStroke", { detail: event }));
448
- const point = this._createPoint(event.x, event.y, event.pressure);
449
- const lastPointGroup = this._data[this._data.length - 1];
450
- const lastPoints = lastPointGroup.points;
451
- const lastPoint = lastPoints.length > 0 && lastPoints[lastPoints.length - 1];
452
- const isLastPointTooClose = lastPoint ? point.distanceTo(lastPoint) <= this.minDistance : false;
453
- const pointGroupOptions = this._getPointGroupOptions(lastPointGroup);
454
- if (!lastPoint || !(lastPoint && isLastPointTooClose)) {
455
- const curve = this._addPoint(point, pointGroupOptions);
456
- if (!lastPoint) this._drawDot(point, pointGroupOptions);
457
- else if (curve) this._drawCurve(curve, pointGroupOptions);
458
- lastPoints.push({
459
- time: point.time,
460
- x: point.x,
461
- y: point.y,
462
- pressure: point.pressure
463
- });
464
- }
465
- this.dispatchEvent(new CustomEvent("afterUpdateStroke", { detail: event }));
466
- }
467
- _strokeEnd(event, shouldUpdate = true) {
468
- this._removeMoveUpEventListeners();
469
- if (!this._drawingStroke) return;
470
- if (shouldUpdate) this._strokeUpdate(event);
471
- this._drawingStroke = false;
472
- this._strokePointerId = void 0;
473
- this.dispatchEvent(new CustomEvent("endStroke", { detail: event }));
474
- }
475
- _handlePointerEvents() {
476
- this._drawingStroke = false;
477
- this.canvas.addEventListener("pointerdown", this._handlePointerDown, { passive: false });
478
- }
479
- _handleMouseEvents() {
480
- this._drawingStroke = false;
481
- this.canvas.addEventListener("mousedown", this._handleMouseDown, { passive: false });
482
- }
483
- _handleTouchEvents() {
484
- this.canvas.addEventListener("touchstart", this._handleTouchStart, { passive: false });
485
- }
486
- _reset(options) {
487
- this._lastPoints = [];
488
- this._lastVelocity = 0;
489
- this._lastWidth = (options.minWidth + options.maxWidth) / 2;
490
- this._ctx.fillStyle = options.penColor;
491
- this._ctx.globalCompositeOperation = options.compositeOperation;
492
- }
493
- _createPoint(x, y, pressure) {
494
- const rect = this.canvas.getBoundingClientRect();
495
- return new Point(x - rect.left, y - rect.top, pressure, (/* @__PURE__ */ new Date()).getTime());
496
- }
497
- _addPoint(point, options) {
498
- const { _lastPoints } = this;
499
- _lastPoints.push(point);
500
- if (_lastPoints.length > 2) {
501
- if (_lastPoints.length === 3) _lastPoints.unshift(_lastPoints[0]);
502
- const widths = this._calculateCurveWidths(_lastPoints[1], _lastPoints[2], options);
503
- const curve = Bezier.fromPoints(_lastPoints, widths);
504
- _lastPoints.shift();
505
- return curve;
506
- }
507
- return null;
508
- }
509
- _calculateCurveWidths(startPoint, endPoint, options) {
510
- const velocity = options.velocityFilterWeight * endPoint.velocityFrom(startPoint) + (1 - options.velocityFilterWeight) * this._lastVelocity;
511
- const newWidth = this._strokeWidth(velocity, options);
512
- const widths = {
513
- end: newWidth,
514
- start: this._lastWidth
515
- };
516
- this._lastVelocity = velocity;
517
- this._lastWidth = newWidth;
518
- return widths;
519
- }
520
- _strokeWidth(velocity, options) {
521
- return Math.max(options.maxWidth / (velocity + 1), options.minWidth);
522
- }
523
- _drawCurveSegment(x, y, width) {
524
- const ctx = this._ctx;
525
- ctx.moveTo(x, y);
526
- ctx.arc(x, y, width, 0, 2 * Math.PI, false);
527
- this._isEmpty = false;
528
- }
529
- _drawCurve(curve, options) {
530
- const ctx = this._ctx;
531
- const widthDelta = curve.endWidth - curve.startWidth;
532
- const drawSteps = Math.ceil(curve.length()) * 2;
533
- ctx.beginPath();
534
- ctx.fillStyle = options.penColor;
535
- for (let i = 0; i < drawSteps; i += 1) {
536
- const t = i / drawSteps;
537
- const tt = t * t;
538
- const ttt = tt * t;
539
- const u = 1 - t;
540
- const uu = u * u;
541
- const uuu = uu * u;
542
- let x = uuu * curve.startPoint.x;
543
- x += 3 * uu * t * curve.control1.x;
544
- x += 3 * u * tt * curve.control2.x;
545
- x += ttt * curve.endPoint.x;
546
- let y = uuu * curve.startPoint.y;
547
- y += 3 * uu * t * curve.control1.y;
548
- y += 3 * u * tt * curve.control2.y;
549
- y += ttt * curve.endPoint.y;
550
- const width = Math.min(curve.startWidth + ttt * widthDelta, options.maxWidth);
551
- this._drawCurveSegment(x, y, width);
552
- }
553
- ctx.closePath();
554
- ctx.fill();
555
- }
556
- _drawDot(point, options) {
557
- const ctx = this._ctx;
558
- const width = options.dotSize > 0 ? options.dotSize : (options.minWidth + options.maxWidth) / 2;
559
- ctx.beginPath();
560
- this._drawCurveSegment(point.x, point.y, width);
561
- ctx.closePath();
562
- ctx.fillStyle = options.penColor;
563
- ctx.fill();
564
- }
565
- _fromData(pointGroups, drawCurve, drawDot) {
566
- for (const group of pointGroups) {
567
- const { points } = group;
568
- const pointGroupOptions = this._getPointGroupOptions(group);
569
- if (points.length > 1) for (let j = 0; j < points.length; j += 1) {
570
- const basicPoint = points[j];
571
- const point = new Point(basicPoint.x, basicPoint.y, basicPoint.pressure, basicPoint.time);
572
- if (j === 0) this._reset(pointGroupOptions);
573
- const curve = this._addPoint(point, pointGroupOptions);
574
- if (curve) drawCurve(curve, pointGroupOptions);
575
- }
576
- else {
577
- this._reset(pointGroupOptions);
578
- drawDot(points[0], pointGroupOptions);
579
- }
580
- }
581
- }
582
- toSVG({ includeBackgroundColor = false, includeDataUrl = false } = {}) {
583
- const pointGroups = this._data;
584
- const ratio = Math.max(window.devicePixelRatio || 1, 1);
585
- const minX = 0;
586
- const minY = 0;
587
- const maxX = this.canvas.width / ratio;
588
- const maxY = this.canvas.height / ratio;
589
- const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
590
- svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
591
- svg.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
592
- svg.setAttribute("viewBox", `${minX} ${minY} ${maxX} ${maxY}`);
593
- svg.setAttribute("width", maxX.toString());
594
- svg.setAttribute("height", maxY.toString());
595
- if (includeBackgroundColor && this.backgroundColor) {
596
- const rect = document.createElement("rect");
597
- rect.setAttribute("width", "100%");
598
- rect.setAttribute("height", "100%");
599
- rect.setAttribute("fill", this.backgroundColor);
600
- svg.appendChild(rect);
601
- }
602
- if (includeDataUrl && this._dataUrl) {
603
- const ratio2 = this._dataUrlOptions?.ratio || window.devicePixelRatio || 1;
604
- const width = this._dataUrlOptions?.width || this.canvas.width / ratio2;
605
- const height = this._dataUrlOptions?.height || this.canvas.height / ratio2;
606
- const xOffset = this._dataUrlOptions?.xOffset || 0;
607
- const yOffset = this._dataUrlOptions?.yOffset || 0;
608
- const image = document.createElement("image");
609
- image.setAttribute("x", xOffset.toString());
610
- image.setAttribute("y", yOffset.toString());
611
- image.setAttribute("width", width.toString());
612
- image.setAttribute("height", height.toString());
613
- image.setAttribute("preserveAspectRatio", "none");
614
- image.setAttribute("href", this._dataUrl);
615
- svg.appendChild(image);
616
- }
617
- this._fromData(pointGroups, (curve, { penColor }) => {
618
- const path = document.createElement("path");
619
- if (!isNaN(curve.control1.x) && !isNaN(curve.control1.y) && !isNaN(curve.control2.x) && !isNaN(curve.control2.y)) {
620
- const attr = `M ${curve.startPoint.x.toFixed(3)},${curve.startPoint.y.toFixed(3)} C ${curve.control1.x.toFixed(3)},${curve.control1.y.toFixed(3)} ${curve.control2.x.toFixed(3)},${curve.control2.y.toFixed(3)} ${curve.endPoint.x.toFixed(3)},${curve.endPoint.y.toFixed(3)}`;
621
- path.setAttribute("d", attr);
622
- path.setAttribute("stroke-width", (curve.endWidth * 2.25).toFixed(3));
623
- path.setAttribute("stroke", penColor);
624
- path.setAttribute("fill", "none");
625
- path.setAttribute("stroke-linecap", "round");
626
- svg.appendChild(path);
627
- }
628
- }, (point, { penColor, dotSize, minWidth, maxWidth }) => {
629
- const circle = document.createElement("circle");
630
- const size = dotSize > 0 ? dotSize : (minWidth + maxWidth) / 2;
631
- circle.setAttribute("r", size.toString());
632
- circle.setAttribute("cx", point.x.toString());
633
- circle.setAttribute("cy", point.y.toString());
634
- circle.setAttribute("fill", penColor);
635
- svg.appendChild(circle);
636
- });
637
- return svg.outerHTML;
638
- }
639
- };
640
- //#endregion
641
- //#region src/css/theme/fields/_signature.css?inline
642
- var _signature_default = "@layer formie-theme{[data-formie-field-type=signature] .formie-field-control{transition:border-color .15s,box-shadow .15s,background-color .15s;position:relative}[data-formie-field-type=signature] .formie-field-control:focus-within .formie-signature-canvas{border-color:var(--formie-focus-ring-border-color);box-shadow:var(--formie-shadow-focus)}.formie-field-has-error[data-formie-field-type=signature] .formie-signature-canvas{border-color:var(--formie-color-danger)}.formie-field-has-error[data-formie-field-type=signature] .formie-field-control:focus-within .formie-signature-canvas{box-shadow:var(--formie-shadow-danger-focus)}[data-formie-field-type=signature] .formie-signature-canvas{width:var(--formie-signature-width);height:var(--formie-signature-height);border:var(--formie-signature-border);background:var(--formie-signature-background);border-radius:var(--formie-signature-border-radius);touch-action:none;transition:border-color .15s,box-shadow .15s,background-color .15s;display:block}[data-formie-field-type=signature] .formie-signature-remove-button{top:var(--formie-signature-remove-button-top);right:var(--formie-signature-remove-button-right);transform:var(--formie-signature-remove-button-transform);font-size:0;line-height:0;position:absolute}}";
643
- //#endregion
644
- //#region src/js/modules/fields/signature.ts
645
- var INPUT_SELECTOR = "input[data-formie-signature-input]";
646
- var CANVAS_SELECTOR = "canvas[data-formie-signature-canvas]";
647
- var CLEAR_SELECTOR = "[data-formie-signature-clear]";
648
- var MODULE_ID = "signature";
649
- ensureModuleStyles(MODULE_ID, [_signature_default]);
650
- function getCanvasSize(canvas) {
651
- const rect = canvas.getBoundingClientRect();
652
- return {
653
- width: Math.round(rect.width),
654
- height: Math.round(rect.height)
655
- };
656
- }
657
- function drawValueOnCanvas(canvas, value) {
658
- if (!value) return;
659
- const image = new Image();
660
- image.src = value;
661
- image.onload = () => {
662
- const ratio = Math.max(window.devicePixelRatio || 1, 1);
663
- const context = canvas.getContext("2d");
664
- if (!context) return;
665
- context.drawImage(image, 0, 0, canvas.width / ratio, canvas.height / ratio);
666
- };
667
- }
668
- function initSignatureField(root, field, input, canvas, clearButton, options) {
669
- const penWeight = parseFloat(options.penWeight || "2") || 2;
670
- const resizeTarget = canvas.parentElement instanceof HTMLElement ? canvas.parentElement : field;
671
- const signaturePad = new SignaturePad(canvas, {
672
- backgroundColor: options.backgroundColor || "rgba(255, 255, 255, 0)",
673
- penColor: options.penColor || "#000000",
674
- dotSize: penWeight,
675
- minWidth: penWeight,
676
- maxWidth: penWeight
677
- });
678
- const resizeCanvas = () => {
679
- const { width, height } = getCanvasSize(canvas);
680
- if (!(width > 0) || !(height > 0)) return;
681
- const ratio = Math.max(window.devicePixelRatio || 1, 1);
682
- const context = canvas.getContext("2d");
683
- if (!context) return;
684
- const existingValue = input.value || (signaturePad.isEmpty() ? "" : signaturePad.toDataURL());
685
- canvas.width = width * ratio;
686
- canvas.height = height * ratio;
687
- context.setTransform(1, 0, 0, 1, 0, 0);
688
- context.scale(ratio, ratio);
689
- signaturePad.clear();
690
- drawValueOnCanvas(canvas, existingValue);
691
- };
692
- const scheduleResize = (delay = 0) => {
693
- window.setTimeout(() => {
694
- window.requestAnimationFrame(() => {
695
- resizeCanvas();
696
- });
697
- }, delay);
698
- };
699
- const resizeHandler = () => {
700
- scheduleResize();
701
- };
702
- const pageNavigateHandler = () => {
703
- scheduleResize(100);
704
- };
705
- const resizeObserver = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(() => {
706
- scheduleResize();
707
- });
708
- const syncInputValue = (nextValue) => {
709
- const valueChanged = input.value !== nextValue;
710
- input.value = nextValue;
711
- if (!valueChanged) return;
712
- input.dispatchEvent(new Event("input", { bubbles: true }));
713
- input.dispatchEvent(new Event("change", { bubbles: true }));
714
- };
715
- const syncValue = () => {
716
- syncInputValue(signaturePad.isEmpty() ? "" : signaturePad.toDataURL());
717
- };
718
- const clearSignature = () => {
719
- signaturePad.clear();
720
- syncInputValue("");
721
- };
722
- signaturePad.addEventListener("endStroke", syncValue);
723
- window.addEventListener("resize", resizeHandler);
724
- root.addEventListener("formie:page:navigate:after", pageNavigateHandler);
725
- resizeObserver?.observe(resizeTarget);
726
- scheduleResize();
727
- if (clearButton) clearButton.addEventListener("click", clearSignature);
728
- dispatchFieldEvent(field, MODULE_ID, "init", { signature: signaturePad });
729
- return () => {
730
- signaturePad.removeEventListener("endStroke", syncValue);
731
- window.removeEventListener("resize", resizeHandler);
732
- root.removeEventListener("formie:page:navigate:after", pageNavigateHandler);
733
- resizeObserver?.disconnect();
734
- if (clearButton) clearButton.removeEventListener("click", clearSignature);
735
- signaturePad.clear();
736
- };
737
- }
738
- var signatureModule = {
739
- id: MODULE_ID,
740
- kind: "field",
741
- match: (ctx) => {
742
- return !!ctx.target.querySelector(CANVAS_SELECTOR);
743
- },
744
- setup: async (ctx) => {
745
- const options = ctx.options || {};
746
- const root = ctx.root instanceof HTMLElement ? ctx.root : ctx.target instanceof HTMLElement ? ctx.target : null;
747
- if (!root) return;
748
- const cleanups = getModuleFieldContainers(ctx).map((field) => {
749
- const input = field.querySelector(INPUT_SELECTOR);
750
- const canvas = field.querySelector(CANVAS_SELECTOR);
751
- const clearButton = field.querySelector(CLEAR_SELECTOR);
752
- if (!(input instanceof HTMLInputElement) || !(canvas instanceof HTMLCanvasElement)) return () => {};
753
- return initSignatureField(root, field, input, canvas, clearButton instanceof HTMLElement ? clearButton : null, options);
754
- });
755
- await ctx.emit("formie:module:signature:init", { count: cleanups.length });
756
- return { destroy: () => {
757
- cleanups.forEach((cleanup) => {
758
- cleanup();
759
- });
760
- ctx.emit("formie:module:signature:destroy", {});
761
- } };
762
- }
763
- };
764
- //#endregion
765
- export { signatureModule };