@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.
- package/CHANGELOG.md +76 -22
- package/dist/chunks/address-country-Rx6GQTND.js +68 -0
- package/dist/chunks/address-finder-yXU5yMjG.js +30 -0
- package/dist/chunks/address-state-BQ0xGV9n.js +344 -0
- package/dist/chunks/api-CmwLRq_n.js +780 -0
- package/dist/chunks/api-DMK8NSUI.js +407 -0
- package/dist/chunks/api-sPqGbOww.js +125 -0
- package/dist/chunks/async-nPFRNQ06.js +25 -0
- package/dist/chunks/bpoint-DSjqRv63.js +24 -0
- package/dist/chunks/calculations-CeDgB9jt.js +299 -0
- package/dist/chunks/captcha-eu-CWJb64_j.js +31 -0
- package/dist/chunks/checkbox-radio-DQ0H67Tj.js +125 -0
- package/dist/chunks/chunk-3b4jIN3o.js +13 -0
- package/dist/chunks/combobox-D-2b42wn.js +1954 -0
- package/dist/chunks/conditions-DjZOtHfS.js +412 -0
- package/dist/chunks/constants-DVcJAvc5.js +38 -0
- package/dist/chunks/country-from-ip-BwxKaBuJ.js +26 -0
- package/dist/chunks/custom-google-maps-BsaSirEZ.js +194 -0
- package/dist/chunks/custom-link-CJ1-FjEM.js +46 -0
- package/dist/chunks/custom-maps-DYW_pBid.js +161 -0
- package/dist/chunks/date-picker-5CA_-zGb.js +5311 -0
- package/dist/chunks/debug-BV0DvdHx.js +41 -0
- package/dist/chunks/dist-BQ4a9hmy.js +2659 -0
- package/dist/chunks/event-names-BCI2FLD8.js +51 -0
- package/dist/chunks/eway-D3ctTbEk.js +70 -0
- package/dist/chunks/field-references.keys-58ZSTrCW.js +21 -0
- package/dist/chunks/field-references.resolver-CHwn0G0L.js +145 -0
- package/dist/chunks/file-upload-D49m8-DR.js +287 -0
- package/dist/chunks/friendly-captcha-v1-ByXzENYZ.js +31 -0
- package/dist/chunks/friendly-captcha-v2-BPdlmhQu.js +36 -0
- package/dist/chunks/friendly-challenge-8uPatWqk.js +832 -0
- package/dist/chunks/go-cardless-BwASSYSK.js +23 -0
- package/dist/chunks/google-address-OhKilPWE.js +161 -0
- package/dist/chunks/hcaptcha-CdCd9oEi.js +54 -0
- package/dist/chunks/hidden-D7_Ch-QN.js +26 -0
- package/dist/chunks/http-D-JExro7.js +27 -0
- package/dist/chunks/i18n-BY1ds1BL.js +121 -0
- package/dist/chunks/leaflet-src-j-lHNmhR.js +4585 -0
- package/dist/chunks/loqate-Cp2zvwpE.js +76 -0
- package/dist/chunks/mollie-COG-ko2D.js +23 -0
- package/dist/chunks/moneris-CMH8PlRc.js +117 -0
- package/dist/chunks/opayo-D2jsR5vh.js +113 -0
- package/dist/chunks/paddle-DxF88RfC.js +55 -0
- package/dist/chunks/paypal-b5pnwrA2.js +95 -0
- package/dist/chunks/payway-BJYu9DIR.js +55 -0
- package/dist/chunks/phone-country-D3ayr60L.js +2645 -0
- package/dist/chunks/place-kit-BGHklIZ-.js +48 -0
- package/dist/chunks/placekit-autocomplete.esm-DWVabQlq.js +1236 -0
- package/dist/chunks/recaptcha-enterprise-BSwi8IVX.js +65 -0
- package/dist/chunks/recaptcha-shared-B4zAescW.js +15 -0
- package/dist/chunks/recaptcha-v2-checkbox-CnDQmsKa.js +40 -0
- package/dist/chunks/recaptcha-v2-invisible-Cz5uIlp-.js +53 -0
- package/dist/chunks/recaptcha-v3-BtbbP111.js +27 -0
- package/dist/chunks/repeater-B5leVxZU.js +102 -0
- package/dist/chunks/rich-text-D0sb8bmX.js +349 -0
- package/dist/chunks/scripts-6CYSUGKQ.js +24 -0
- package/dist/chunks/sdk-BhHAYgga.js +1397 -0
- package/dist/chunks/shared-Bx9s0i0P.js +100 -0
- package/dist/chunks/signature-xz4QO7CR.js +536 -0
- package/dist/chunks/snaptcha-vz1RnZ15.js +8 -0
- package/dist/chunks/square-BP8RWAKB.js +40 -0
- package/dist/chunks/stripe-MihN63uC.js +184 -0
- package/dist/chunks/styles-BfoIZwJp.js +19 -0
- package/dist/chunks/summary-D3AjxpYN.js +114 -0
- package/dist/chunks/table-C-lkQN6I.js +78 -0
- package/dist/chunks/text-limit-DbgEFHLO.js +125 -0
- package/dist/chunks/theme-classes-Tv7q7ToE.js +44 -0
- package/dist/chunks/turnstile-D_Pi1CKM.js +58 -0
- package/dist/chunks/upload-manager-BpqWSHmU.js +2558 -0
- package/dist/chunks/utils-Vqp8i_RM.js +49401 -0
- package/dist/css/formie-theme.css +2 -0
- package/dist/css/theme/_buttons.css +16 -0
- package/dist/css/theme/_tokens.css +2 -0
- package/dist/css/theme/fields/_address-state.css +94 -0
- package/dist/css/theme/fields/_combobox.css +246 -0
- package/dist/css/theme/fields/_select.css +13 -0
- package/dist/css/theme/fields/_signature.css +19 -0
- package/dist/css/theme/fields/_upload-manager.css +279 -0
- package/dist/index.js +2448 -39
- package/dist/js/core/create-formie-client.d.ts.map +1 -1
- package/dist/js/core/submit-result-ui.d.ts.map +1 -1
- package/dist/js/core/validation-focus.d.ts +4 -0
- package/dist/js/core/validation-focus.d.ts.map +1 -0
- package/dist/js/modules/address/api.d.ts +1 -0
- package/dist/js/modules/address/api.d.ts.map +1 -1
- package/dist/js/modules/address/constants.d.ts +22 -1
- package/dist/js/modules/address/constants.d.ts.map +1 -1
- package/dist/js/modules/address/host.d.ts +2 -2
- package/dist/js/modules/address/host.d.ts.map +1 -1
- package/dist/js/modules/address/loqate.d.ts.map +1 -1
- package/dist/js/modules/fields/address-country.d.ts +3 -0
- package/dist/js/modules/fields/address-country.d.ts.map +1 -0
- package/dist/js/modules/fields/address-state.d.ts +3 -0
- package/dist/js/modules/fields/address-state.d.ts.map +1 -0
- package/dist/js/modules/fields/calculations.d.ts.map +1 -1
- package/dist/js/modules/fields/combobox.d.ts +17 -0
- package/dist/js/modules/fields/combobox.d.ts.map +1 -0
- package/dist/js/modules/fields/custom-google-maps.d.ts +64 -0
- package/dist/js/modules/fields/custom-google-maps.d.ts.map +1 -0
- package/dist/js/modules/fields/custom-link.d.ts +3 -0
- package/dist/js/modules/fields/custom-link.d.ts.map +1 -0
- package/dist/js/modules/fields/custom-maps.d.ts +3 -0
- package/dist/js/modules/fields/custom-maps.d.ts.map +1 -0
- package/dist/js/modules/fields/date-picker.d.ts.map +1 -1
- package/dist/js/modules/fields/index.d.ts.map +1 -1
- package/dist/js/modules/fields/phone-country.d.ts.map +1 -1
- package/dist/js/modules/fields/signature.d.ts.map +1 -1
- package/dist/js/modules/fields/upload-manager.d.ts +3 -0
- package/dist/js/modules/fields/upload-manager.d.ts.map +1 -0
- package/dist/js/submit/pipeline.d.ts.map +1 -1
- package/dist/js/utils/country-from-ip.d.ts +7 -0
- package/dist/js/utils/country-from-ip.d.ts.map +1 -0
- package/dist/js/utils/field-references.d.ts +1 -0
- package/dist/js/utils/field-references.d.ts.map +1 -1
- package/dist/js/utils/field-references.row-scope.d.ts +11 -0
- package/dist/js/utils/field-references.row-scope.d.ts.map +1 -0
- package/package.json +8 -3
- package/src/css/formie-theme.css +2 -0
- package/src/css/theme/_buttons.css +16 -0
- package/src/css/theme/_tokens.css +2 -0
- package/src/css/theme/fields/_address-state.css +94 -0
- package/src/css/theme/fields/_combobox.css +246 -0
- package/src/css/theme/fields/_select.css +13 -0
- package/src/css/theme/fields/_signature.css +19 -0
- package/src/css/theme/fields/_upload-manager.css +279 -0
- package/src/js/core/create-formie-client.ts +27 -0
- package/src/js/core/submit-result-ui.ts +4 -4
- package/src/js/core/validation-focus.ts +117 -0
- package/src/js/modules/address/api.ts +7 -0
- package/src/js/modules/address/constants.ts +82 -2
- package/src/js/modules/address/host.ts +16 -6
- package/src/js/modules/address/loqate.ts +3 -17
- package/src/js/modules/fields/address-country.ts +156 -0
- package/src/js/modules/fields/address-state.ts +946 -0
- package/src/js/modules/fields/calculations.ts +32 -0
- package/src/js/modules/fields/combobox.ts +188 -0
- package/src/js/modules/fields/custom-google-maps.ts +416 -0
- package/src/js/modules/fields/custom-link.ts +95 -0
- package/src/js/modules/fields/custom-maps.ts +339 -0
- package/src/js/modules/fields/date-picker.ts +96 -3
- package/src/js/modules/fields/index.ts +7 -0
- package/src/js/modules/fields/phone-country.ts +6 -0
- package/src/js/modules/fields/signature.ts +199 -15
- package/src/js/modules/fields/upload-manager.ts +1277 -0
- package/src/js/submit/pipeline.ts +11 -1
- package/src/js/utils/country-from-ip.ts +54 -0
- package/src/js/utils/field-references.row-scope.ts +303 -0
- package/src/js/utils/field-references.ts +1 -0
- package/src/vendor.d.ts +1 -1
- package/dist/chunks/address-finder-BU4roxT6.js +0 -37
- package/dist/chunks/bpoint-uNg5j6rt.js +0 -26
- package/dist/chunks/calculations-C9t6Zop9.js +0 -147
- package/dist/chunks/captcha-eu-BAPzHNts.js +0 -34
- package/dist/chunks/checkbox-radio-CHeLNVIK.js +0 -141
- package/dist/chunks/conditions-DKxVCsjD.js +0 -459
- package/dist/chunks/date-picker-B3iQ797Z.js +0 -4994
- package/dist/chunks/eway-DCielIML.js +0 -74
- package/dist/chunks/file-upload-DP2TOUYV.js +0 -316
- package/dist/chunks/friendly-captcha-v1-DdlcGiFY.js +0 -33
- package/dist/chunks/friendly-captcha-v2-76w-YnFm.js +0 -38
- package/dist/chunks/go-cardless-rwCkzbNK.js +0 -24
- package/dist/chunks/google-address-BD8IZ86V.js +0 -181
- package/dist/chunks/hcaptcha-BNNTL6uf.js +0 -56
- package/dist/chunks/hidden-CW6Rcf1N.js +0 -31
- package/dist/chunks/index-BEsfee-D.js +0 -1839
- package/dist/chunks/index-BP7Unm5Y.js +0 -863
- package/dist/chunks/index-D6npYxvr.js +0 -4423
- package/dist/chunks/loqate-B-ZNS65B.js +0 -55
- package/dist/chunks/mollie-BDAZ-1X4.js +0 -24
- package/dist/chunks/moneris-B1b0uEtY.js +0 -101
- package/dist/chunks/opayo-CC5hraHo.js +0 -122
- package/dist/chunks/paddle-B4GmrDsq.js +0 -60
- package/dist/chunks/paypal-BFS6XsIS.js +0 -100
- package/dist/chunks/payway-DekoJead.js +0 -56
- package/dist/chunks/phone-country-Cm5YUeXI.js +0 -3765
- package/dist/chunks/place-kit-DizZWV_e.js +0 -42
- package/dist/chunks/placekit-autocomplete.esm-LAwfbPZl.js +0 -1299
- package/dist/chunks/recaptcha-enterprise-BbOvO7JZ.js +0 -71
- package/dist/chunks/recaptcha-shared-Dwg1eVFS.js +0 -15
- package/dist/chunks/recaptcha-v2-checkbox-SY3ti5iQ.js +0 -41
- package/dist/chunks/recaptcha-v2-invisible-DSmQnn6c.js +0 -59
- package/dist/chunks/recaptcha-v3-DNh7YCnR.js +0 -28
- package/dist/chunks/repeater-DM0vuFNQ.js +0 -124
- package/dist/chunks/rich-text-C8aGYp70.js +0 -304
- package/dist/chunks/scripts-CKTFtxPO.js +0 -36
- package/dist/chunks/sdk-3SicTWby.js +0 -1559
- package/dist/chunks/shared--BU5CFoL.js +0 -80
- package/dist/chunks/signature-pFhZfH7d.js +0 -550
- package/dist/chunks/snaptcha-VuOUOaLj.js +0 -8
- package/dist/chunks/square-BR9pvToy.js +0 -46
- package/dist/chunks/stripe-OHUwoV9g.js +0 -202
- package/dist/chunks/styles-C3aqgtek.js +0 -21
- package/dist/chunks/summary-Da7Ktg3N.js +0 -126
- package/dist/chunks/table-C0PmR9bI.js +0 -95
- package/dist/chunks/text-limit-mLEwZDIa.js +0 -144
- package/dist/chunks/turnstile-9tM7q_LK.js +0 -59
- package/dist/chunks/utils-BntI3W4S.js +0 -6149
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { r as e } from "./event-names-BCI2FLD8.js";
|
|
2
|
+
//#region src/js/modules/fields/shared.ts
|
|
3
|
+
var t = (e) => e.replace(/["\\]/g, "\\$&"), n = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
function r(e) {
|
|
5
|
+
return typeof window.CSS?.escape == "function" ? window.CSS.escape(e) : t(e);
|
|
6
|
+
}
|
|
7
|
+
function i(e) {
|
|
8
|
+
return e.target instanceof HTMLElement && e.target.hasAttribute("data-formie-field-handle") ? [e.target] : e.target instanceof HTMLElement ? Array.from(e.target.querySelectorAll("[data-formie-field-handle]")).filter((e) => e instanceof HTMLElement) : [];
|
|
9
|
+
}
|
|
10
|
+
function a(e) {
|
|
11
|
+
return i(e)[0] || null;
|
|
12
|
+
}
|
|
13
|
+
function o(e) {
|
|
14
|
+
return e && e.formieValidation || null;
|
|
15
|
+
}
|
|
16
|
+
function s(e, t, r) {
|
|
17
|
+
if (!e) return;
|
|
18
|
+
let i = n.get(e) || /* @__PURE__ */ new Map(), a = i.get(t) || 0;
|
|
19
|
+
if (a === 0) {
|
|
20
|
+
let t = o(e);
|
|
21
|
+
t && r(t);
|
|
22
|
+
}
|
|
23
|
+
i.set(t, a + 1), n.set(e, i);
|
|
24
|
+
}
|
|
25
|
+
function c(e, t, r) {
|
|
26
|
+
if (!e) return;
|
|
27
|
+
let i = n.get(e), a = i?.get(t) || 0;
|
|
28
|
+
if (a <= 1) {
|
|
29
|
+
let a = o(e);
|
|
30
|
+
if (r.forEach((e) => {
|
|
31
|
+
a?.removeValidator(e);
|
|
32
|
+
}), i?.delete(t), !i || i.size === 0) {
|
|
33
|
+
n.delete(e);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
n.set(e, i);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
i?.set(t, a - 1);
|
|
40
|
+
}
|
|
41
|
+
function l(e, t, n, r) {
|
|
42
|
+
let i = /* @__PURE__ */ new Map(), a = (e) => {
|
|
43
|
+
if (!n(e) || i.has(e)) return;
|
|
44
|
+
let t = r(e);
|
|
45
|
+
i.set(e, t || (() => {}));
|
|
46
|
+
}, o = (e) => {
|
|
47
|
+
e instanceof Element && e.matches(t) && a(e), e.querySelectorAll(t).forEach((e) => {
|
|
48
|
+
a(e);
|
|
49
|
+
});
|
|
50
|
+
}, s = () => {
|
|
51
|
+
i.forEach((t, n) => {
|
|
52
|
+
e.contains(n) || (t(), i.delete(n));
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
o(e);
|
|
56
|
+
let c = new MutationObserver((e) => {
|
|
57
|
+
e.forEach((e) => {
|
|
58
|
+
e.addedNodes.forEach((e) => {
|
|
59
|
+
e instanceof Element && o(e);
|
|
60
|
+
});
|
|
61
|
+
}), s();
|
|
62
|
+
});
|
|
63
|
+
return c.observe(e, {
|
|
64
|
+
childList: !0,
|
|
65
|
+
subtree: !0
|
|
66
|
+
}), () => {
|
|
67
|
+
c.disconnect(), i.forEach((e) => {
|
|
68
|
+
e();
|
|
69
|
+
}), i.clear();
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function u(e) {
|
|
73
|
+
return e.ownerDocument || document;
|
|
74
|
+
}
|
|
75
|
+
function d(e, t) {
|
|
76
|
+
let n = u(e);
|
|
77
|
+
if (t) {
|
|
78
|
+
let i = [
|
|
79
|
+
e.querySelector(`template[data-formie-template-id="${r(t)}"]`),
|
|
80
|
+
e.querySelector(`script[data-formie-template-id="${r(t)}"]`),
|
|
81
|
+
n.querySelector(`template[data-formie-template-id="${r(t)}"]`),
|
|
82
|
+
n.querySelector(`script[data-formie-template-id="${r(t)}"]`),
|
|
83
|
+
n.getElementById(t)
|
|
84
|
+
];
|
|
85
|
+
for (let e of i) if (e instanceof HTMLTemplateElement || e instanceof HTMLScriptElement) return e;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
function f(e) {
|
|
90
|
+
return e instanceof HTMLTemplateElement ? e.innerHTML : e instanceof HTMLScriptElement ? e.textContent || "" : e.innerHTML;
|
|
91
|
+
}
|
|
92
|
+
function p(t, n, r, i) {
|
|
93
|
+
let a = e(n, r);
|
|
94
|
+
t.dispatchEvent(new CustomEvent(a, {
|
|
95
|
+
bubbles: !0,
|
|
96
|
+
detail: i
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
export { d as a, c, a as i, s as l, r as n, f as o, i as r, l as s, p as t };
|
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
import { t as e } from "./styles-BfoIZwJp.js";
|
|
2
|
+
import { r as t, t as n } from "./shared-Bx9s0i0P.js";
|
|
3
|
+
//#region ../../node_modules/signature_pad/dist/signature_pad.js
|
|
4
|
+
var r = class {
|
|
5
|
+
x;
|
|
6
|
+
y;
|
|
7
|
+
pressure;
|
|
8
|
+
time;
|
|
9
|
+
constructor(e, t, n, r) {
|
|
10
|
+
if (isNaN(e) || isNaN(t)) throw Error(`Point is invalid: (${e}, ${t})`);
|
|
11
|
+
this.x = +e, this.y = +t, this.pressure = n || 0, this.time = r || Date.now();
|
|
12
|
+
}
|
|
13
|
+
distanceTo(e) {
|
|
14
|
+
return Math.sqrt((this.x - e.x) ** 2 + (this.y - e.y) ** 2);
|
|
15
|
+
}
|
|
16
|
+
equals(e) {
|
|
17
|
+
return this.x === e.x && this.y === e.y && this.pressure === e.pressure && this.time === e.time;
|
|
18
|
+
}
|
|
19
|
+
velocityFrom(e) {
|
|
20
|
+
return this.time === e.time ? 0 : this.distanceTo(e) / (this.time - e.time);
|
|
21
|
+
}
|
|
22
|
+
}, i = class e {
|
|
23
|
+
constructor(e, t, n, r, i, a) {
|
|
24
|
+
this.startPoint = e, this.control2 = t, this.control1 = n, this.endPoint = r, this.startWidth = i, this.endWidth = a;
|
|
25
|
+
}
|
|
26
|
+
static fromPoints(t, n) {
|
|
27
|
+
let r = this.calculateControlPoints(t[0], t[1], t[2]).c2, i = this.calculateControlPoints(t[1], t[2], t[3]).c1;
|
|
28
|
+
return new e(t[1], r, i, t[2], n.start, n.end);
|
|
29
|
+
}
|
|
30
|
+
static calculateControlPoints(e, t, n) {
|
|
31
|
+
let i = e.x - t.x, a = e.y - t.y, o = t.x - n.x, s = t.y - n.y, c = {
|
|
32
|
+
x: (e.x + t.x) / 2,
|
|
33
|
+
y: (e.y + t.y) / 2
|
|
34
|
+
}, l = {
|
|
35
|
+
x: (t.x + n.x) / 2,
|
|
36
|
+
y: (t.y + n.y) / 2
|
|
37
|
+
}, u = Math.sqrt(i * i + a * a), d = Math.sqrt(o * o + s * s), f = c.x - l.x, p = c.y - l.y, m = u + d == 0 ? 0 : d / (u + d), h = {
|
|
38
|
+
x: l.x + f * m,
|
|
39
|
+
y: l.y + p * m
|
|
40
|
+
}, g = t.x - h.x, _ = t.y - h.y;
|
|
41
|
+
return {
|
|
42
|
+
c1: new r(c.x + g, c.y + _),
|
|
43
|
+
c2: new r(l.x + g, l.y + _)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
length() {
|
|
47
|
+
let e = 0, t, n;
|
|
48
|
+
for (let r = 0; r <= 10; r += 1) {
|
|
49
|
+
let i = r / 10, a = this.point(i, this.startPoint.x, this.control1.x, this.control2.x, this.endPoint.x), o = this.point(i, this.startPoint.y, this.control1.y, this.control2.y, this.endPoint.y);
|
|
50
|
+
if (r > 0) {
|
|
51
|
+
let r = a - t, i = o - n;
|
|
52
|
+
e += Math.sqrt(r * r + i * i);
|
|
53
|
+
}
|
|
54
|
+
t = a, n = o;
|
|
55
|
+
}
|
|
56
|
+
return e;
|
|
57
|
+
}
|
|
58
|
+
point(e, t, n, r, i) {
|
|
59
|
+
return t * (1 - e) * (1 - e) * (1 - e) + 3 * n * (1 - e) * (1 - e) * e + 3 * r * (1 - e) * e * e + i * e * e * e;
|
|
60
|
+
}
|
|
61
|
+
}, a = class {
|
|
62
|
+
_et;
|
|
63
|
+
constructor() {
|
|
64
|
+
try {
|
|
65
|
+
this._et = new EventTarget();
|
|
66
|
+
} catch {
|
|
67
|
+
this._et = document;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
addEventListener(e, t, n) {
|
|
71
|
+
this._et.addEventListener(e, t, n);
|
|
72
|
+
}
|
|
73
|
+
dispatchEvent(e) {
|
|
74
|
+
return this._et.dispatchEvent(e);
|
|
75
|
+
}
|
|
76
|
+
removeEventListener(e, t, n) {
|
|
77
|
+
this._et.removeEventListener(e, t, n);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
function o(e, t = 250) {
|
|
81
|
+
let n = 0, r = null, i, a, o, s = () => {
|
|
82
|
+
n = Date.now(), r = null, i = e.apply(a, o), r || (a = null, o = []);
|
|
83
|
+
};
|
|
84
|
+
return function(...c) {
|
|
85
|
+
let l = Date.now(), u = t - (l - n);
|
|
86
|
+
return a = this, o = c, u <= 0 || u > t ? (r &&= (clearTimeout(r), null), n = l, i = e.apply(a, o), r || (a = null, o = [])) : r ||= window.setTimeout(s, u), i;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
var s = class e extends a {
|
|
90
|
+
constructor(t, n = {}) {
|
|
91
|
+
super(), this.canvas = t, this.velocityFilterWeight = n.velocityFilterWeight || .7, this.minWidth = n.minWidth || .5, this.maxWidth = n.maxWidth || 2.5, this.throttle = n.throttle ?? 16, this.minDistance = n.minDistance ?? 5, this.dotSize = n.dotSize || 0, this.penColor = n.penColor || "black", this.backgroundColor = n.backgroundColor || "rgba(0,0,0,0)", this.compositeOperation = n.compositeOperation || "source-over", this.canvasContextOptions = n.canvasContextOptions ?? {}, this._strokeMoveUpdate = this.throttle ? o(e.prototype._strokeUpdate, this.throttle) : e.prototype._strokeUpdate, this._handleMouseDown = this._handleMouseDown.bind(this), this._handleMouseMove = this._handleMouseMove.bind(this), this._handleMouseUp = this._handleMouseUp.bind(this), this._handleTouchStart = this._handleTouchStart.bind(this), this._handleTouchMove = this._handleTouchMove.bind(this), this._handleTouchEnd = this._handleTouchEnd.bind(this), this._handlePointerDown = this._handlePointerDown.bind(this), this._handlePointerMove = this._handlePointerMove.bind(this), this._handlePointerUp = this._handlePointerUp.bind(this), this._handlePointerCancel = this._handlePointerCancel.bind(this), this._handleTouchCancel = this._handleTouchCancel.bind(this), this._ctx = t.getContext("2d", this.canvasContextOptions), this.clear(), this.on();
|
|
92
|
+
}
|
|
93
|
+
dotSize;
|
|
94
|
+
minWidth;
|
|
95
|
+
maxWidth;
|
|
96
|
+
penColor;
|
|
97
|
+
minDistance;
|
|
98
|
+
velocityFilterWeight;
|
|
99
|
+
compositeOperation;
|
|
100
|
+
backgroundColor;
|
|
101
|
+
throttle;
|
|
102
|
+
canvasContextOptions;
|
|
103
|
+
_ctx;
|
|
104
|
+
_drawingStroke = !1;
|
|
105
|
+
_isEmpty = !0;
|
|
106
|
+
_dataUrl;
|
|
107
|
+
_dataUrlOptions;
|
|
108
|
+
_lastPoints = [];
|
|
109
|
+
_data = [];
|
|
110
|
+
_lastVelocity = 0;
|
|
111
|
+
_lastWidth = 0;
|
|
112
|
+
_strokeMoveUpdate;
|
|
113
|
+
_strokePointerId;
|
|
114
|
+
clear() {
|
|
115
|
+
let { _ctx: e, canvas: t } = this;
|
|
116
|
+
e.fillStyle = this.backgroundColor, e.clearRect(0, 0, t.width, t.height), e.fillRect(0, 0, t.width, t.height), this._data = [], this._reset(this._getPointGroupOptions()), this._isEmpty = !0, this._dataUrl = void 0, this._dataUrlOptions = void 0, this._strokePointerId = void 0;
|
|
117
|
+
}
|
|
118
|
+
redraw() {
|
|
119
|
+
let e = this._data, t = this._dataUrl, n = this._dataUrlOptions;
|
|
120
|
+
this.clear(), t && this.fromDataURL(t, n), this.fromData(e, { clear: !1 });
|
|
121
|
+
}
|
|
122
|
+
fromDataURL(e, t = {}) {
|
|
123
|
+
return new Promise((n, r) => {
|
|
124
|
+
let i = new Image(), a = t.ratio || window.devicePixelRatio || 1, o = t.width || this.canvas.width / a, s = t.height || this.canvas.height / a, c = t.xOffset || 0, l = t.yOffset || 0;
|
|
125
|
+
this._reset(this._getPointGroupOptions()), i.onload = () => {
|
|
126
|
+
this._ctx.drawImage(i, c, l, o, s), n();
|
|
127
|
+
}, i.onerror = (e) => {
|
|
128
|
+
r(e);
|
|
129
|
+
}, i.crossOrigin = "anonymous", i.src = e, this._isEmpty = !1, this._dataUrl = e, this._dataUrlOptions = { ...t };
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
toDataURL(e = "image/png", t) {
|
|
133
|
+
switch (e) {
|
|
134
|
+
case "image/svg+xml": return typeof t != "object" && (t = void 0), `data:image/svg+xml;base64,${btoa(this.toSVG(t))}`;
|
|
135
|
+
default: return typeof t != "number" && (t = void 0), this.canvas.toDataURL(e, t);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
on() {
|
|
139
|
+
this.canvas.style.touchAction = "none", this.canvas.style.msTouchAction = "none", this.canvas.style.userSelect = "none", this.canvas.style.webkitUserSelect = "none";
|
|
140
|
+
let e = /Macintosh/.test(navigator.userAgent) && "ontouchstart" in document;
|
|
141
|
+
window.PointerEvent && !e ? this._handlePointerEvents() : (this._handleMouseEvents(), "ontouchstart" in window && this._handleTouchEvents());
|
|
142
|
+
}
|
|
143
|
+
off() {
|
|
144
|
+
this.canvas.style.touchAction = "auto", this.canvas.style.msTouchAction = "auto", this.canvas.style.userSelect = "auto", this.canvas.style.webkitUserSelect = "auto", this.canvas.removeEventListener("pointerdown", this._handlePointerDown), this.canvas.removeEventListener("mousedown", this._handleMouseDown), this.canvas.removeEventListener("touchstart", this._handleTouchStart), this._removeMoveUpEventListeners();
|
|
145
|
+
}
|
|
146
|
+
_getListenerFunctions() {
|
|
147
|
+
let e = window.document === this.canvas.ownerDocument ? window : this.canvas.ownerDocument.defaultView ?? this.canvas.ownerDocument;
|
|
148
|
+
return {
|
|
149
|
+
addEventListener: e.addEventListener.bind(e),
|
|
150
|
+
removeEventListener: e.removeEventListener.bind(e)
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
_removeMoveUpEventListeners() {
|
|
154
|
+
let { removeEventListener: e } = this._getListenerFunctions();
|
|
155
|
+
e("pointermove", this._handlePointerMove), e("pointerup", this._handlePointerUp), e("pointercancel", this._handlePointerCancel), e("mousemove", this._handleMouseMove), e("mouseup", this._handleMouseUp), e("touchmove", this._handleTouchMove), e("touchend", this._handleTouchEnd), e("touchcancel", this._handleTouchCancel);
|
|
156
|
+
}
|
|
157
|
+
isEmpty() {
|
|
158
|
+
return this._isEmpty;
|
|
159
|
+
}
|
|
160
|
+
fromData(e, { clear: t = !0 } = {}) {
|
|
161
|
+
t && this.clear(), this._fromData(e, this._drawCurve.bind(this), this._drawDot.bind(this)), this._data = this._data.concat(e);
|
|
162
|
+
}
|
|
163
|
+
toData() {
|
|
164
|
+
return this._data;
|
|
165
|
+
}
|
|
166
|
+
_isLeftButtonPressed(e, t) {
|
|
167
|
+
return t ? e.buttons === 1 : (e.buttons & 1) == 1;
|
|
168
|
+
}
|
|
169
|
+
_pointerEventToSignatureEvent(e) {
|
|
170
|
+
return {
|
|
171
|
+
event: e,
|
|
172
|
+
type: e.type,
|
|
173
|
+
x: e.clientX,
|
|
174
|
+
y: e.clientY,
|
|
175
|
+
pressure: "pressure" in e ? e.pressure : 0
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
_touchEventToSignatureEvent(e) {
|
|
179
|
+
let t = e.changedTouches[0];
|
|
180
|
+
return {
|
|
181
|
+
event: e,
|
|
182
|
+
type: e.type,
|
|
183
|
+
x: t.clientX,
|
|
184
|
+
y: t.clientY,
|
|
185
|
+
pressure: t.force
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
_handleMouseDown(e) {
|
|
189
|
+
!this._isLeftButtonPressed(e, !0) || this._drawingStroke || this._strokeBegin(this._pointerEventToSignatureEvent(e));
|
|
190
|
+
}
|
|
191
|
+
_handleMouseMove(e) {
|
|
192
|
+
if (!this._isLeftButtonPressed(e, !0) || !this._drawingStroke) {
|
|
193
|
+
this._strokeEnd(this._pointerEventToSignatureEvent(e), !1);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e));
|
|
197
|
+
}
|
|
198
|
+
_handleMouseUp(e) {
|
|
199
|
+
this._isLeftButtonPressed(e) || this._strokeEnd(this._pointerEventToSignatureEvent(e));
|
|
200
|
+
}
|
|
201
|
+
_handleTouchStart(e) {
|
|
202
|
+
e.targetTouches.length !== 1 || this._drawingStroke || (e.cancelable && e.preventDefault(), this._strokeBegin(this._touchEventToSignatureEvent(e)));
|
|
203
|
+
}
|
|
204
|
+
_handleTouchMove(e) {
|
|
205
|
+
if (e.targetTouches.length === 1) {
|
|
206
|
+
if (e.cancelable && e.preventDefault(), !this._drawingStroke) {
|
|
207
|
+
this._strokeEnd(this._touchEventToSignatureEvent(e), !1);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
this._strokeMoveUpdate(this._touchEventToSignatureEvent(e));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
_handleTouchEnd(e) {
|
|
214
|
+
e.targetTouches.length === 0 && (e.cancelable && e.preventDefault(), this._strokeEnd(this._touchEventToSignatureEvent(e)));
|
|
215
|
+
}
|
|
216
|
+
_handlePointerCancel(e) {
|
|
217
|
+
this._allowPointerId(e) && (e.preventDefault(), this._strokeEnd(this._pointerEventToSignatureEvent(e), !1));
|
|
218
|
+
}
|
|
219
|
+
_handleTouchCancel(e) {
|
|
220
|
+
e.cancelable && e.preventDefault(), this._strokeEnd(this._touchEventToSignatureEvent(e), !1);
|
|
221
|
+
}
|
|
222
|
+
_getPointerId(e) {
|
|
223
|
+
return e.persistentDeviceId || e.pointerId;
|
|
224
|
+
}
|
|
225
|
+
_allowPointerId(e, t = !1) {
|
|
226
|
+
return this._strokePointerId === void 0 ? t : this._getPointerId(e) === this._strokePointerId;
|
|
227
|
+
}
|
|
228
|
+
_handlePointerDown(e) {
|
|
229
|
+
this._drawingStroke || !this._isLeftButtonPressed(e) || !this._allowPointerId(e, !0) || (this._strokePointerId = this._getPointerId(e), e.preventDefault(), this._strokeBegin(this._pointerEventToSignatureEvent(e)));
|
|
230
|
+
}
|
|
231
|
+
_handlePointerMove(e) {
|
|
232
|
+
if (this._allowPointerId(e)) {
|
|
233
|
+
if (!this._isLeftButtonPressed(e, !0) || !this._drawingStroke) {
|
|
234
|
+
this._strokeEnd(this._pointerEventToSignatureEvent(e), !1);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
e.preventDefault(), this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
_handlePointerUp(e) {
|
|
241
|
+
this._isLeftButtonPressed(e) || !this._allowPointerId(e) || (e.preventDefault(), this._strokeEnd(this._pointerEventToSignatureEvent(e)));
|
|
242
|
+
}
|
|
243
|
+
_getPointGroupOptions(e) {
|
|
244
|
+
return {
|
|
245
|
+
penColor: e && "penColor" in e ? e.penColor : this.penColor,
|
|
246
|
+
dotSize: e && "dotSize" in e ? e.dotSize : this.dotSize,
|
|
247
|
+
minWidth: e && "minWidth" in e ? e.minWidth : this.minWidth,
|
|
248
|
+
maxWidth: e && "maxWidth" in e ? e.maxWidth : this.maxWidth,
|
|
249
|
+
velocityFilterWeight: e && "velocityFilterWeight" in e ? e.velocityFilterWeight : this.velocityFilterWeight,
|
|
250
|
+
compositeOperation: e && "compositeOperation" in e ? e.compositeOperation : this.compositeOperation
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
_strokeBegin(e) {
|
|
254
|
+
if (!this.dispatchEvent(new CustomEvent("beginStroke", {
|
|
255
|
+
detail: e,
|
|
256
|
+
cancelable: !0
|
|
257
|
+
}))) return;
|
|
258
|
+
let { addEventListener: t } = this._getListenerFunctions();
|
|
259
|
+
switch (e.event.type) {
|
|
260
|
+
case "mousedown":
|
|
261
|
+
t("mousemove", this._handleMouseMove, { passive: !1 }), t("mouseup", this._handleMouseUp, { passive: !1 });
|
|
262
|
+
break;
|
|
263
|
+
case "touchstart":
|
|
264
|
+
t("touchmove", this._handleTouchMove, { passive: !1 }), t("touchend", this._handleTouchEnd, { passive: !1 }), t("touchcancel", this._handleTouchCancel, { passive: !1 });
|
|
265
|
+
break;
|
|
266
|
+
case "pointerdown":
|
|
267
|
+
t("pointermove", this._handlePointerMove, { passive: !1 }), t("pointerup", this._handlePointerUp, { passive: !1 }), t("pointercancel", this._handlePointerCancel, { passive: !1 });
|
|
268
|
+
break;
|
|
269
|
+
default:
|
|
270
|
+
}
|
|
271
|
+
this._drawingStroke = !0;
|
|
272
|
+
let n = this._getPointGroupOptions(), r = {
|
|
273
|
+
...n,
|
|
274
|
+
points: []
|
|
275
|
+
};
|
|
276
|
+
this._data.push(r), this._reset(n), this._strokeUpdate(e);
|
|
277
|
+
}
|
|
278
|
+
_strokeUpdate(e) {
|
|
279
|
+
if (!this._drawingStroke) return;
|
|
280
|
+
if (this._data.length === 0) {
|
|
281
|
+
this._strokeBegin(e);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
this.dispatchEvent(new CustomEvent("beforeUpdateStroke", { detail: e }));
|
|
285
|
+
let t = this._createPoint(e.x, e.y, e.pressure), n = this._data[this._data.length - 1], r = n.points, i = r.length > 0 && r[r.length - 1], a = i ? t.distanceTo(i) <= this.minDistance : !1, o = this._getPointGroupOptions(n);
|
|
286
|
+
if (!i || !(i && a)) {
|
|
287
|
+
let e = this._addPoint(t, o);
|
|
288
|
+
i ? e && this._drawCurve(e, o) : this._drawDot(t, o), r.push({
|
|
289
|
+
time: t.time,
|
|
290
|
+
x: t.x,
|
|
291
|
+
y: t.y,
|
|
292
|
+
pressure: t.pressure
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
this.dispatchEvent(new CustomEvent("afterUpdateStroke", { detail: e }));
|
|
296
|
+
}
|
|
297
|
+
_strokeEnd(e, t = !0) {
|
|
298
|
+
this._removeMoveUpEventListeners(), this._drawingStroke && (t && this._strokeUpdate(e), this._drawingStroke = !1, this._strokePointerId = void 0, this.dispatchEvent(new CustomEvent("endStroke", { detail: e })));
|
|
299
|
+
}
|
|
300
|
+
_handlePointerEvents() {
|
|
301
|
+
this._drawingStroke = !1, this.canvas.addEventListener("pointerdown", this._handlePointerDown, { passive: !1 });
|
|
302
|
+
}
|
|
303
|
+
_handleMouseEvents() {
|
|
304
|
+
this._drawingStroke = !1, this.canvas.addEventListener("mousedown", this._handleMouseDown, { passive: !1 });
|
|
305
|
+
}
|
|
306
|
+
_handleTouchEvents() {
|
|
307
|
+
this.canvas.addEventListener("touchstart", this._handleTouchStart, { passive: !1 });
|
|
308
|
+
}
|
|
309
|
+
_reset(e) {
|
|
310
|
+
this._lastPoints = [], this._lastVelocity = 0, this._lastWidth = (e.minWidth + e.maxWidth) / 2, this._ctx.fillStyle = e.penColor, this._ctx.globalCompositeOperation = e.compositeOperation;
|
|
311
|
+
}
|
|
312
|
+
_createPoint(e, t, n) {
|
|
313
|
+
let i = this.canvas.getBoundingClientRect();
|
|
314
|
+
return new r(e - i.left, t - i.top, n, (/* @__PURE__ */ new Date()).getTime());
|
|
315
|
+
}
|
|
316
|
+
_addPoint(e, t) {
|
|
317
|
+
let { _lastPoints: n } = this;
|
|
318
|
+
if (n.push(e), n.length > 2) {
|
|
319
|
+
n.length === 3 && n.unshift(n[0]);
|
|
320
|
+
let e = this._calculateCurveWidths(n[1], n[2], t), r = i.fromPoints(n, e);
|
|
321
|
+
return n.shift(), r;
|
|
322
|
+
}
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
_calculateCurveWidths(e, t, n) {
|
|
326
|
+
let r = n.velocityFilterWeight * t.velocityFrom(e) + (1 - n.velocityFilterWeight) * this._lastVelocity, i = this._strokeWidth(r, n), a = {
|
|
327
|
+
end: i,
|
|
328
|
+
start: this._lastWidth
|
|
329
|
+
};
|
|
330
|
+
return this._lastVelocity = r, this._lastWidth = i, a;
|
|
331
|
+
}
|
|
332
|
+
_strokeWidth(e, t) {
|
|
333
|
+
return Math.max(t.maxWidth / (e + 1), t.minWidth);
|
|
334
|
+
}
|
|
335
|
+
_drawCurveSegment(e, t, n) {
|
|
336
|
+
let r = this._ctx;
|
|
337
|
+
r.moveTo(e, t), r.arc(e, t, n, 0, 2 * Math.PI, !1), this._isEmpty = !1;
|
|
338
|
+
}
|
|
339
|
+
_drawCurve(e, t) {
|
|
340
|
+
let n = this._ctx, r = e.endWidth - e.startWidth, i = Math.ceil(e.length()) * 2;
|
|
341
|
+
n.beginPath(), n.fillStyle = t.penColor;
|
|
342
|
+
for (let n = 0; n < i; n += 1) {
|
|
343
|
+
let a = n / i, o = a * a, s = o * a, c = 1 - a, l = c * c, u = l * c, d = u * e.startPoint.x;
|
|
344
|
+
d += 3 * l * a * e.control1.x, d += 3 * c * o * e.control2.x, d += s * e.endPoint.x;
|
|
345
|
+
let f = u * e.startPoint.y;
|
|
346
|
+
f += 3 * l * a * e.control1.y, f += 3 * c * o * e.control2.y, f += s * e.endPoint.y;
|
|
347
|
+
let p = Math.min(e.startWidth + s * r, t.maxWidth);
|
|
348
|
+
this._drawCurveSegment(d, f, p);
|
|
349
|
+
}
|
|
350
|
+
n.closePath(), n.fill();
|
|
351
|
+
}
|
|
352
|
+
_drawDot(e, t) {
|
|
353
|
+
let n = this._ctx, r = t.dotSize > 0 ? t.dotSize : (t.minWidth + t.maxWidth) / 2;
|
|
354
|
+
n.beginPath(), this._drawCurveSegment(e.x, e.y, r), n.closePath(), n.fillStyle = t.penColor, n.fill();
|
|
355
|
+
}
|
|
356
|
+
_fromData(e, t, n) {
|
|
357
|
+
for (let i of e) {
|
|
358
|
+
let { points: e } = i, a = this._getPointGroupOptions(i);
|
|
359
|
+
if (e.length > 1) for (let n = 0; n < e.length; n += 1) {
|
|
360
|
+
let i = e[n], o = new r(i.x, i.y, i.pressure, i.time);
|
|
361
|
+
n === 0 && this._reset(a);
|
|
362
|
+
let s = this._addPoint(o, a);
|
|
363
|
+
s && t(s, a);
|
|
364
|
+
}
|
|
365
|
+
else this._reset(a), n(e[0], a);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
toSVG({ includeBackgroundColor: e = !1, includeDataUrl: t = !1 } = {}) {
|
|
369
|
+
let n = this._data, r = Math.max(window.devicePixelRatio || 1, 1), i = this.canvas.width / r, a = this.canvas.height / r, o = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
370
|
+
if (o.setAttribute("xmlns", "http://www.w3.org/2000/svg"), o.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink"), o.setAttribute("viewBox", `0 0 ${i} ${a}`), o.setAttribute("width", i.toString()), o.setAttribute("height", a.toString()), e && this.backgroundColor) {
|
|
371
|
+
let e = document.createElement("rect");
|
|
372
|
+
e.setAttribute("width", "100%"), e.setAttribute("height", "100%"), e.setAttribute("fill", this.backgroundColor), o.appendChild(e);
|
|
373
|
+
}
|
|
374
|
+
if (t && this._dataUrl) {
|
|
375
|
+
let e = this._dataUrlOptions?.ratio || window.devicePixelRatio || 1, t = this._dataUrlOptions?.width || this.canvas.width / e, n = this._dataUrlOptions?.height || this.canvas.height / e, r = this._dataUrlOptions?.xOffset || 0, i = this._dataUrlOptions?.yOffset || 0, a = document.createElement("image");
|
|
376
|
+
a.setAttribute("x", r.toString()), a.setAttribute("y", i.toString()), a.setAttribute("width", t.toString()), a.setAttribute("height", n.toString()), a.setAttribute("preserveAspectRatio", "none"), a.setAttribute("href", this._dataUrl), o.appendChild(a);
|
|
377
|
+
}
|
|
378
|
+
return this._fromData(n, (e, { penColor: t }) => {
|
|
379
|
+
let n = document.createElement("path");
|
|
380
|
+
if (!isNaN(e.control1.x) && !isNaN(e.control1.y) && !isNaN(e.control2.x) && !isNaN(e.control2.y)) {
|
|
381
|
+
let r = `M ${e.startPoint.x.toFixed(3)},${e.startPoint.y.toFixed(3)} C ${e.control1.x.toFixed(3)},${e.control1.y.toFixed(3)} ${e.control2.x.toFixed(3)},${e.control2.y.toFixed(3)} ${e.endPoint.x.toFixed(3)},${e.endPoint.y.toFixed(3)}`;
|
|
382
|
+
n.setAttribute("d", r), n.setAttribute("stroke-width", (e.endWidth * 2.25).toFixed(3)), n.setAttribute("stroke", t), n.setAttribute("fill", "none"), n.setAttribute("stroke-linecap", "round"), o.appendChild(n);
|
|
383
|
+
}
|
|
384
|
+
}, (e, { penColor: t, dotSize: n, minWidth: r, maxWidth: i }) => {
|
|
385
|
+
let a = document.createElement("circle"), s = n > 0 ? n : (r + i) / 2;
|
|
386
|
+
a.setAttribute("r", s.toString()), a.setAttribute("cx", e.x.toString()), a.setAttribute("cy", e.y.toString()), a.setAttribute("fill", t), o.appendChild(a);
|
|
387
|
+
}), o.outerHTML;
|
|
388
|
+
}
|
|
389
|
+
}, c = "@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}[data-formie-field-type=signature] .formie-signature-pad{position:relative}[data-formie-field-type=signature] .formie-signature-message{padding:var(--formie-space-3);border:var(--formie-signature-border);border-radius:var(--formie-signature-border-radius);background:var(--formie-signature-background);color:var(--formie-color-text-muted);font-size:var(--formie-font-size-sm);line-height:var(--formie-line-height-base);margin:0}[data-formie-field-type=signature].formie-signature-has-message .formie-signature-canvas{display:none}}", l = "input[data-formie-signature-input]", u = "canvas[data-formie-signature-canvas]", d = "[data-formie-signature-clear]", f = "[data-formie-signature-message]", p = "signature", m = 20, h = 100, g = [
|
|
390
|
+
"hidden",
|
|
391
|
+
"data-formie-conditionally-hidden",
|
|
392
|
+
"data-formie-page-hidden",
|
|
393
|
+
"data-formie-row-hidden"
|
|
394
|
+
];
|
|
395
|
+
e(p, [c]);
|
|
396
|
+
function _(e) {
|
|
397
|
+
let t = e.getBoundingClientRect();
|
|
398
|
+
return {
|
|
399
|
+
width: Math.round(t.width),
|
|
400
|
+
height: Math.round(t.height)
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
function v() {
|
|
404
|
+
let e = document.createElement("canvas");
|
|
405
|
+
return typeof e.getContext == "function" && !!e.getContext("2d");
|
|
406
|
+
}
|
|
407
|
+
function y(e) {
|
|
408
|
+
let t = e.querySelector(f);
|
|
409
|
+
return t instanceof HTMLElement ? t : null;
|
|
410
|
+
}
|
|
411
|
+
function b(e) {
|
|
412
|
+
let t = y(e);
|
|
413
|
+
return {
|
|
414
|
+
noCanvas: t?.dataset.formieSignatureMessageNoCanvas || "This browser does not support canvas, which is required for signatures.",
|
|
415
|
+
initFailed: t?.dataset.formieSignatureMessageInitFailed || "The signature pad could not be loaded. Try refreshing the page."
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
function x(e, t, n) {
|
|
419
|
+
let r = y(e);
|
|
420
|
+
if (r) {
|
|
421
|
+
if (n) {
|
|
422
|
+
r.textContent = n, r.hidden = !1, t.setAttribute("aria-hidden", "true"), e.classList.add("formie-signature-has-message");
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
r.textContent = "", r.hidden = !0, t.removeAttribute("aria-hidden"), e.classList.remove("formie-signature-has-message");
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
function S(e) {
|
|
429
|
+
return !e.hasAttribute("hidden") && !e.hasAttribute("data-formie-conditionally-hidden") && !e.hasAttribute("data-formie-page-hidden") && !e.hasAttribute("data-formie-row-hidden") && e.getClientRects().length > 0;
|
|
430
|
+
}
|
|
431
|
+
function C(e, t) {
|
|
432
|
+
if (!t) return;
|
|
433
|
+
let n = new Image();
|
|
434
|
+
n.src = t, n.onload = () => {
|
|
435
|
+
let t = Math.max(window.devicePixelRatio || 1, 1), r = e.getContext("2d");
|
|
436
|
+
r && r.drawImage(n, 0, 0, e.width / t, e.height / t);
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
async function w(e, t, n) {
|
|
440
|
+
if (n) try {
|
|
441
|
+
await e.fromDataURL(n);
|
|
442
|
+
} catch {
|
|
443
|
+
C(t, n);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
function T(e, t, r, i, a, o) {
|
|
447
|
+
let c = b(t);
|
|
448
|
+
if (!v()) return x(t, i, c.noCanvas), () => {};
|
|
449
|
+
let l = parseFloat(o.penWeight || "2") || 2, u = i.parentElement instanceof HTMLElement ? i.parentElement : t, d = 0, f = null, y = !1, C = !1, T = new s(i, {
|
|
450
|
+
backgroundColor: o.backgroundColor || "rgba(255, 255, 255, 0)",
|
|
451
|
+
penColor: o.penColor || "#000000",
|
|
452
|
+
dotSize: l,
|
|
453
|
+
minWidth: l,
|
|
454
|
+
maxWidth: l
|
|
455
|
+
}), E = () => {
|
|
456
|
+
f !== null && (window.clearTimeout(f), f = null);
|
|
457
|
+
}, D = () => {
|
|
458
|
+
y || (y = !0, C = !1, x(t, i, null), n(t, p, "init", { signature: T }));
|
|
459
|
+
}, O = () => {
|
|
460
|
+
y || C || (C = !0, x(t, i, c.initFailed));
|
|
461
|
+
}, k = async () => {
|
|
462
|
+
let { width: e, height: t } = _(i);
|
|
463
|
+
if (!(e > 0) || !(t > 0)) return !1;
|
|
464
|
+
let n = Math.max(window.devicePixelRatio || 1, 1), a = i.getContext("2d");
|
|
465
|
+
if (!a) return !1;
|
|
466
|
+
let o = r.value || (T.isEmpty() ? "" : T.toDataURL());
|
|
467
|
+
return i.width = e * n, i.height = t * n, a.setTransform(1, 0, 0, 1, 0, 0), a.scale(n, n), T.clear(), await w(T, i, o), D(), !0;
|
|
468
|
+
}, A = () => {
|
|
469
|
+
if (!(y || C)) {
|
|
470
|
+
if (d >= m) {
|
|
471
|
+
O();
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
E(), f = window.setTimeout(() => {
|
|
475
|
+
f = null, d += 1, j();
|
|
476
|
+
}, h);
|
|
477
|
+
}
|
|
478
|
+
}, j = async () => {
|
|
479
|
+
if (!await k()) {
|
|
480
|
+
A();
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
E(), d = 0;
|
|
484
|
+
}, M = (e = 0) => {
|
|
485
|
+
window.setTimeout(() => {
|
|
486
|
+
window.requestAnimationFrame(() => {
|
|
487
|
+
j();
|
|
488
|
+
});
|
|
489
|
+
}, e);
|
|
490
|
+
}, N = () => {
|
|
491
|
+
S(t) && !y && (C = !1), M();
|
|
492
|
+
}, P = () => {
|
|
493
|
+
N();
|
|
494
|
+
}, F = () => {
|
|
495
|
+
S(t) && (d = 0, C = !1, M(100));
|
|
496
|
+
}, I = () => {
|
|
497
|
+
S(t) && (d = 0, C = !1, N());
|
|
498
|
+
}, L = typeof ResizeObserver > "u" ? null : new ResizeObserver(() => {
|
|
499
|
+
N();
|
|
500
|
+
}), R = new MutationObserver(() => {
|
|
501
|
+
I();
|
|
502
|
+
}), z = (e) => {
|
|
503
|
+
let t = r.value !== e;
|
|
504
|
+
r.value = e, t && (r.dispatchEvent(new Event("input", { bubbles: !0 })), r.dispatchEvent(new Event("change", { bubbles: !0 })));
|
|
505
|
+
}, B = () => {
|
|
506
|
+
z(T.isEmpty() ? "" : T.toDataURL());
|
|
507
|
+
}, V = () => {
|
|
508
|
+
T.clear(), z("");
|
|
509
|
+
};
|
|
510
|
+
return T.addEventListener("endStroke", B), window.addEventListener("resize", P), e.addEventListener("formie:page:navigate:after", F), L?.observe(u), R.observe(t, {
|
|
511
|
+
attributes: !0,
|
|
512
|
+
attributeFilter: [...g]
|
|
513
|
+
}), M(), a && a.addEventListener("click", V), () => {
|
|
514
|
+
E(), T.removeEventListener("endStroke", B), window.removeEventListener("resize", P), e.removeEventListener("formie:page:navigate:after", F), L?.disconnect(), R.disconnect(), a && a.removeEventListener("click", V), T.clear();
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
var E = {
|
|
518
|
+
id: p,
|
|
519
|
+
kind: "field",
|
|
520
|
+
match: (e) => !!e.target.querySelector(u),
|
|
521
|
+
setup: async (e) => {
|
|
522
|
+
let n = e.options || {}, r = e.root instanceof HTMLElement ? e.root : e.target instanceof HTMLElement ? e.target : null;
|
|
523
|
+
if (!r) return;
|
|
524
|
+
let i = t(e).map((e) => {
|
|
525
|
+
let t = e.querySelector(l), i = e.querySelector(u), a = e.querySelector(d);
|
|
526
|
+
return !(t instanceof HTMLInputElement) || !(i instanceof HTMLCanvasElement) ? () => {} : T(r, e, t, i, a instanceof HTMLElement ? a : null, n);
|
|
527
|
+
});
|
|
528
|
+
return await e.emit("formie:module:signature:init", { count: i.length }), { destroy: () => {
|
|
529
|
+
i.forEach((e) => {
|
|
530
|
+
e();
|
|
531
|
+
}), e.emit("formie:module:signature:destroy", {});
|
|
532
|
+
} };
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
//#endregion
|
|
536
|
+
export { E as signatureModule };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { t as e } from "./api-CmwLRq_n.js";
|
|
2
|
+
import { r as t } from "./scripts-6CYSUGKQ.js";
|
|
3
|
+
//#region src/js/modules/payments/square.ts
|
|
4
|
+
var n = "FORMIE_SQUARE_SCRIPT", r = e({
|
|
5
|
+
id: "square",
|
|
6
|
+
defaultRequiredInputSuffixes: ["squarePaymentId"],
|
|
7
|
+
load: async (e) => {
|
|
8
|
+
let { provider: r } = e.options, i = r.applicationId, a = r.locationId;
|
|
9
|
+
return !i?.trim() || !a?.trim() ? (console.error("[formie] Missing applicationId or locationId for Square."), null) : (await t("Square", {
|
|
10
|
+
id: n,
|
|
11
|
+
src: r.environment === "sandbox" ? "https://sandbox.web.squarecdn.com/v1/square.js" : "https://web.squarecdn.com/v1/square.js"
|
|
12
|
+
}), window.Square);
|
|
13
|
+
},
|
|
14
|
+
mount: async (e) => {
|
|
15
|
+
let { api: t, field: n, services: r, options: i } = e, a = i.provider, o = n.querySelector("[data-formie-square-button]");
|
|
16
|
+
if (!o || !t) return null;
|
|
17
|
+
try {
|
|
18
|
+
let e = await t.payments(a.applicationId || "", a.locationId || "").card();
|
|
19
|
+
return await e.attach(o), e;
|
|
20
|
+
} catch (e) {
|
|
21
|
+
return r.addError(e instanceof Error ? e.message : "Unable to initialize payment."), null;
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
unmount: async () => {},
|
|
25
|
+
onBeforeAuthorize: async (e) => {
|
|
26
|
+
let { widget: t, services: n } = e;
|
|
27
|
+
if (!t) return n.addError("Square card is not ready."), !1;
|
|
28
|
+
try {
|
|
29
|
+
let e = await t.tokenize();
|
|
30
|
+
return e.status === "OK" && e.token ? (n.updateInputs("squarePaymentId", e.token), !0) : (n.addError(e.errors?.[0]?.message || "Tokenization failed."), !1);
|
|
31
|
+
} catch {
|
|
32
|
+
return n.addError("Payment tokenization failed. Please try again."), !1;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
onAfterSubmit: async ({ services: e }) => {
|
|
36
|
+
e.updateInputs("squarePaymentId", "");
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
//#endregion
|
|
40
|
+
export { r as squareModule };
|