@incodetech/web 2.0.1 → 2.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ae-signature/ae-signature.es.js +15 -13
- package/dist/ae-signature/styles.css +3 -17
- package/dist/ae-signature/styles2.css +15 -5
- package/dist/aligndevicelottie-DY_bX_p8.js +12769 -0
- package/dist/antifraud/antifraud.es.js +23 -16
- package/dist/authentication/authentication.es.js +42 -27
- package/dist/autoFocusTitle-BzkUiELM.js +29 -0
- package/dist/{back-horizontal-hint-B8Brxh3U.js → back-horizontal-hint-D_8LptLm.js} +26 -26
- package/dist/back-tutorial-vb1MxlrT.js +14597 -0
- package/dist/{back-vertical-hint-BBo36dxn.js → back-vertical-hint-C1evxxq2.js} +27 -27
- package/dist/backdevicelottie-HypPqBz7.js +16690 -0
- package/dist/base.css +1258 -104
- package/dist/blurdevicelottie-CBXtBFiJ.js +15951 -0
- package/dist/bottomSheet-F1GJfQx_.js +39 -0
- package/dist/browser-ponyfill-CLLvZCVg.js +441 -0
- package/dist/button-CM_hgyIP.js +35 -0
- package/dist/checkbox-BoeLHKgp.js +96 -0
- package/dist/consent/consent.es.js +89 -73
- package/dist/consent/styles.css +35 -22
- package/dist/countrySelector-mSWyHSy4.js +60 -0
- package/dist/cpf-ocr/cpf-ocr.es.js +2 -0
- package/dist/cpfOcr-MtpRztkG.js +92 -0
- package/dist/cpfOcr-jJkYCfsX.js +2 -0
- package/dist/cross-document-data-match/cross-document-data-match.es.js +20 -16
- package/dist/curp-validation/curp-validation.es.js +247 -203
- package/dist/customFields-DXXt9HGM.js +140 -0
- package/dist/customWatchlist-DsW04UF6.js +36 -0
- package/dist/dateInputComposed-C_mh4XBg.js +69 -0
- package/dist/dateInputComposed-Cy6a7ymh.js +1 -0
- package/dist/defineProperty-mefzVtTv.js +39 -0
- package/dist/document-capture/document-capture.es.js +2 -0
- package/dist/document-capture/styles.css +2 -5
- package/dist/documentCapture-8ypBJehw.js +2 -0
- package/dist/documentCapture-BDV_921m.js +880 -0
- package/dist/dropdownComposed-CEWBSdGl.js +1 -0
- package/dist/dropdownComposed-_fgAlo_C.js +380 -0
- package/dist/dynamic-forms/styles.css +25 -13
- package/dist/dynamicForms-DyfnsS7E.js +352 -0
- package/dist/ekyb/ekyb.es.js +2 -2
- package/dist/ekyb/styles.css +2 -0
- package/dist/ekybModule-CIPGmCvD.js +279 -0
- package/dist/ekybModule-DFoYpheB.js +2 -0
- package/dist/ekyc/ekyc.es.js +2 -2
- package/dist/ekyc/styles.css +9 -7
- package/dist/ekycModule-BGzwgjl1.js +2 -0
- package/dist/ekycModule-BuTaC5ct.js +257 -0
- package/dist/electronic-signature/electronic-signature.es.js +2 -2
- package/dist/electronic-signature-B-Q7M0wK.js +430 -0
- package/dist/email/email.es.js +199 -66
- package/dist/emailInput-KZmhjOdZ.js +39 -0
- package/dist/errorIcon-DJRZpd8j.js +26 -0
- package/dist/expiredId-Q1t6aVpk.js +85 -0
- package/dist/extensibility-Cs3KQQdC.js +3070 -0
- package/dist/extensibility.es.js +26 -25
- package/dist/face-match/face-match.es.js +2 -2
- package/dist/face-match/styles.css +0 -4
- package/dist/faceMatch--RDHJe4t.js +343 -0
- package/dist/faceMatch-yEKPYaym.js +2 -0
- package/dist/field-comparison/field-comparison.es.js +2 -0
- package/dist/field-comparison/styles.css +16 -0
- package/dist/fieldComparison-CAF86bTC.js +88 -0
- package/dist/fieldComparison-D0an7T_g.js +2 -0
- package/dist/fiscal-qr/fiscal-qr.es.js +224 -0
- package/dist/fiscal-qr/styles.css +71 -0
- package/dist/{flip-animation-CgwRsEmK.js → flip-animation-BGRvygw9.js} +4221 -4221
- package/dist/flow/flow.es.js +619 -484
- package/dist/flow/styles.css +378 -418
- package/dist/{front-horizontal-hint-DGGGi8e1.js → front-horizontal-hint-Uf5bHCsd.js} +70 -70
- package/dist/{front-vertical-hint-CNr5mE6Q.js → front-vertical-hint-DdWNA45v.js} +81 -81
- package/dist/frontdevicelottie-CLqitJhG.js +17314 -0
- package/dist/geolocation/geolocation.es.js +486 -395
- package/dist/glaredevicelottie-BS04U6Fc.js +14478 -0
- package/dist/governmentValidation/governmentValidation.es.js +166 -93
- package/dist/governmentValidation/styles.css +0 -17
- package/dist/homeScreen-BZnIEDrV.js +264 -0
- package/dist/hooks-Da_yP_Dr.js +149 -0
- package/dist/i18n-CoCO2ZuN.js +2971 -0
- package/dist/icons-Dbs9ZfYM.js +360 -0
- package/dist/id/id.es.js +583 -414
- package/dist/id/styles.css +59 -43
- package/dist/id-laser-h-DX8UbVNH.js +467 -0
- package/dist/id-laser-v-DhnHdjlB.js +490 -0
- package/dist/id-tutorial-lj4iKtYT.js +13165 -0
- package/dist/id-verification/id-verification.es.js +21 -17
- package/dist/idOcr-CjGbb4dB.js +123 -0
- package/dist/identity-reuse/identity-reuse.es.js +311 -182
- package/dist/identity-reuse/styles.css +134 -80
- package/dist/incode-logo-57XFniXU.js +4 -0
- package/dist/incodeComponent-wfnHlnXx.js +63 -0
- package/dist/incodeModule-BUDoTwT9.js +13 -0
- package/dist/index.es.js +17 -13
- package/dist/inputComposed-BEn7_nZd.js +1 -0
- package/dist/inputComposed-CQ4AsvZg.js +99 -0
- package/dist/loadingIcon-B0ysgiNq.js +148 -0
- package/dist/lottie_light-Dp9Bz3mf.js +9031 -0
- package/dist/mandatoryConsent-r0PQHmv-.js +107 -0
- package/dist/modal-nTSaG7nB.js +139 -0
- package/dist/modal.hooks-D2xhIuHA.js +195 -0
- package/dist/numberedStep-CEtwZqLp.js +13 -0
- package/dist/optionAccessibleLabel-CnA-mNAU.js +202 -0
- package/dist/otpInput-_JmtVwa0.js +195 -0
- package/dist/page-DxGQj7Gk.js +71 -0
- package/dist/{passport-horizontal-hint-Bgquwtac.js → passport-horizontal-hint-Bbm2mvSn.js} +55 -55
- package/dist/{passport-tutorial-DwRwtPVX.js → passport-tutorial-zT1ZoA-D.js} +7096 -7084
- package/dist/{passport-vertical-hint-BT1D5BrW.js → passport-vertical-hint-DJbCtBiM.js} +49 -49
- package/dist/pdf-BZA70WbM.js +22398 -0
- package/dist/pdfViewer-BK-yVIve.js +114 -0
- package/dist/phone/phone.es.js +214 -70
- package/dist/phoneInputComposed-DjNdsmPE.js +12142 -0
- package/dist/processing-BM-wT-1W.js +8 -0
- package/dist/qe-signature/qe-signature.es.js +15 -13
- package/dist/radioGroupComposed-BNuaopVr.js +215 -0
- package/dist/redirect-to-mobile/redirect-to-mobile.es.js +2774 -0
- package/dist/redirect-to-mobile/styles.css +19 -269
- package/dist/registerIncodeElement-77NGCDsy.js +11 -0
- package/dist/requiredLabelHint-DEadtiwx.js +17 -0
- package/dist/richText-Cf9aMOCk.js +3153 -0
- package/dist/rolldown-runtime--E5BIlTp.js +33 -0
- package/dist/selfie/selfie.es.js +54 -37
- package/dist/selfie/styles.css +0 -4
- package/dist/selfieTutorial-CtruLyO2.js +2689 -0
- package/dist/signature/signature.es.js +778 -405
- package/dist/snackbar-CxepGC3e.js +16 -0
- package/dist/spinner-B6RxGFrI.js +1 -0
- package/dist/spinner-D8a_2LvW.js +42 -0
- package/dist/statusPage-DMYPUwRZ.js +28 -0
- package/dist/successIcon-BAyDPT7I.js +30 -0
- package/dist/tabs-C8npVBbk.js +103 -0
- package/dist/themes/dark.css +5 -0
- package/dist/themes/light.css +4 -0
- package/dist/transitionSpinner-DRRz-NV8.js +26 -0
- package/dist/{tutorial-9vHAHvMK.js → tutorial-D1qaY2Tm.js} +1105 -856
- package/dist/types/ae-signature.d.ts +4 -1
- package/dist/types/antifraud.d.ts +9 -3
- package/dist/types/authentication.d.ts +4 -1
- package/dist/types/consent.d.ts +4 -1
- package/dist/types/cpf-ocr.d.ts +12 -0
- package/dist/types/cross-document-data-match.d.ts +4 -1
- package/dist/types/curp-validation.d.ts +9 -3
- package/dist/types/document-capture.d.ts +37 -0
- package/dist/types/ekyb.d.ts +4 -1
- package/dist/types/ekyc.d.ts +4 -1
- package/dist/types/electronic-signature.d.ts +4 -1
- package/dist/types/email.d.ts +4 -1
- package/dist/types/extensibility.d.ts +40 -15
- package/dist/types/face-match.d.ts +4 -1
- package/dist/types/field-comparison.d.ts +38 -0
- package/dist/types/fiscal-qr.d.ts +43 -0
- package/dist/types/flow.d.ts +5 -2
- package/dist/types/geolocation.d.ts +4 -1
- package/dist/types/governmentValidation.d.ts +4 -1
- package/dist/types/id-verification.d.ts +4 -1
- package/dist/types/id.d.ts +4 -1
- package/dist/types/identity-reuse.d.ts +4 -1
- package/dist/types/index.d.ts +26 -2
- package/dist/types/phone.d.ts +4 -1
- package/dist/types/qe-signature.d.ts +4 -1
- package/dist/types/redirect-to-mobile.d.ts +17 -0
- package/dist/types/selfie.d.ts +4 -1
- package/dist/types/signature.d.ts +4 -1
- package/dist/types/watchlist.d.ts +4 -1
- package/dist/types/workflow.d.ts +55 -11
- package/dist/typography-YLgHHuao.js +45 -0
- package/dist/uiConfig-D2_wawvr.js +25 -0
- package/dist/useModuleLoader-CeJ2jL25.js +672 -0
- package/dist/vendor-preact-DThS2ZQ_.js +955 -0
- package/dist/verificationResult-Do5SpZ6X.js +64 -0
- package/dist/verifiedByIncode-DjXOdCml.js +103 -0
- package/dist/watchlist/watchlist.es.js +31 -28
- package/dist/watchlistForBusiness-BFFXC9d-.js +80 -0
- package/dist/workflow/styles.css +449 -427
- package/dist/workflow/workflow.es.js +268 -182
- package/package.json +32 -10
- package/dist/aligndevicelottie-DoV8xKjh.js +0 -12757
- package/dist/autoFocusTitle-QexamZ4i.js +0 -16
- package/dist/back-tutorial-1NOQobGO.js +0 -14585
- package/dist/backdevicelottie-C_ceuqY7.js +0 -16678
- package/dist/blurdevicelottie-UO14Y0WC.js +0 -15939
- package/dist/bottomSheet-DE_8TFEC.js +0 -31
- package/dist/browser-ponyfill-jOkuz57z.js +0 -299
- package/dist/button-DcCUEn2n.js +0 -24
- package/dist/checkbox-Cl57ltq_.js +0 -85
- package/dist/countrySelector-CE-JgIsv.js +0 -58
- package/dist/cpfOcr-D_tbwbvh.js +0 -78
- package/dist/customFields-CW38fQUv.js +0 -127
- package/dist/customWatchlist-D9_yjEQd.js +0 -33
- package/dist/dateInputComposed-BpAGsjN6.js +0 -55
- package/dist/dateInputComposed-DU3o6PAV.js +0 -1
- package/dist/defineProperty-Dh8nSJpJ.js +0 -39
- package/dist/documentCapture-xX-JT7ZY.js +0 -763
- package/dist/dropdownComposed-DFRBG22E.js +0 -284
- package/dist/dropdownComposed-DwTzc2YU.js +0 -1
- package/dist/dynamicForms-CJP1Ia6Q.js +0 -262
- package/dist/ekybModule-BSs7mndb.js +0 -280
- package/dist/ekybModule-D9M3E2Gm.js +0 -2
- package/dist/ekycModule-CU9pt5YN.js +0 -246
- package/dist/ekycModule-CZw9cLno.js +0 -2
- package/dist/electronic-signature-COYXjGdd.js +0 -410
- package/dist/emailInput-DppGf9pv.js +0 -37
- package/dist/expiredId-BnmzE8T3.js +0 -70
- package/dist/extensibility-CzEJfRwo.js +0 -2586
- package/dist/faceMatch-B8j0g0Yo.js +0 -2
- package/dist/faceMatch-BV8UD7tj.js +0 -201
- package/dist/frontdevicelottie-Bu6f9fDE.js +0 -17302
- package/dist/glaredevicelottie-B10axYs_.js +0 -14466
- package/dist/homeScreen-DnP1jw9A.js +0 -227
- package/dist/hooks-BVnGysT7.js +0 -80
- package/dist/i18n-9s4OSqwi.js +0 -2010
- package/dist/icons-Cc7zwchP.js +0 -310
- package/dist/id-laser-h-mBAzHVOK.js +0 -467
- package/dist/id-laser-v-CrFg4bcJ.js +0 -483
- package/dist/id-tutorial-BCr42Pnn.js +0 -13153
- package/dist/idOcr-CCjfWQvH.js +0 -94
- package/dist/incode-logo-DX016usY.js +0 -4
- package/dist/incodeComponent-C1o4M0ZK.js +0 -50
- package/dist/incodeModule-BqCjVgEI.js +0 -18
- package/dist/inputComposed-APSw8C7o.js +0 -89
- package/dist/inputComposed-XYrarFxS.js +0 -1
- package/dist/loadingIcon-BN5YRQUb.js +0 -104
- package/dist/mandatoryConsent-DssKMC3v.js +0 -100
- package/dist/modal-NMxsQHAO.js +0 -135
- package/dist/modal.hooks-CAjcIFZK.js +0 -126
- package/dist/numberedStep-CT-alrK5.js +0 -11
- package/dist/optionAccessibleLabel-CzEeX3Q4.js +0 -140
- package/dist/otpInput-DqRA_egd.js +0 -145
- package/dist/page-C1yT4DLb.js +0 -69
- package/dist/pdf-BurGZ08w.js +0 -14967
- package/dist/pdfViewer-BGBNL1Ea.js +0 -63
- package/dist/phoneInputComposed-bvWhGLFZ.js +0 -11206
- package/dist/processing-G_y3o32b.js +0 -6
- package/dist/radioGroupComposed-BbmvxmD2.js +0 -177
- package/dist/redirectToMobile-C3k1gloW.js +0 -1514
- package/dist/requiredLabelHint-BLwgqozE.js +0 -13
- package/dist/richText-DbJ5sl2n.js +0 -1973
- package/dist/rolldown-runtime-CYMK-g2i.js +0 -20
- package/dist/selfieTutorial-BgrlUMXP.js +0 -2677
- package/dist/snackbar-BDp8x7Cv.js +0 -14
- package/dist/spinner-B4dcie2T.js +0 -1
- package/dist/spinner-CKnjVHxw.js +0 -39
- package/dist/statusPage-CUI7ApcU.js +0 -28
- package/dist/successIcon-DbILeIz_.js +0 -28
- package/dist/tabs-DaPyP71c.js +0 -78
- package/dist/transitionSpinner-PIEPU2Vx.js +0 -17
- package/dist/types/cpf-ocr/styles.d.ts +0 -1
- package/dist/types/document-capture/styles.d.ts +0 -1
- package/dist/types/redirect-to-mobile/styles.d.ts +0 -1
- package/dist/typography-CxjaknHN.js +0 -28
- package/dist/uiConfig-CwpQ-IM6.js +0 -20
- package/dist/useModuleLoader-BFiVA41N.js +0 -432
- package/dist/vendor-preact-D6SntenC.js +0 -958
- package/dist/verificationResult-BrVbUJ4U.js +0 -97
- package/dist/verifiedByIncode-ChZBpqNy.js +0 -101
- package/dist/watchlistForBusiness-BcSNtHCV.js +0 -77
|
@@ -1,546 +1,919 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import { _ as
|
|
3
|
-
import { o as
|
|
4
|
-
import { t as
|
|
5
|
-
import { r as
|
|
6
|
-
import { t as
|
|
7
|
-
import "../extensibility-
|
|
8
|
-
import { t as
|
|
9
|
-
import { t as
|
|
10
|
-
import { t as
|
|
11
|
-
import { t as
|
|
12
|
-
import { createSignatureManager
|
|
1
|
+
import { n as useTranslation } from "../i18n-CoCO2ZuN.js";
|
|
2
|
+
import { _ as y, a as D, h as q, l as A, p as d, u as F, v as u } from "../vendor-preact-DThS2ZQ_.js";
|
|
3
|
+
import { c as useManager, o as useModuleTerminalCallbacks } from "../hooks-Da_yP_Dr.js";
|
|
4
|
+
import { t as IncodeComponent } from "../incodeComponent-wfnHlnXx.js";
|
|
5
|
+
import { r as Spacer } from "../loadingIcon-B0ysgiNq.js";
|
|
6
|
+
import { t as Page } from "../page-DxGQj7Gk.js";
|
|
7
|
+
import "../extensibility-Cs3KQQdC.js";
|
|
8
|
+
import { t as Button } from "../button-CM_hgyIP.js";
|
|
9
|
+
import { t as VerificationResult } from "../verificationResult-Do5SpZ6X.js";
|
|
10
|
+
import { t as registerIncodeModuleElement } from "../incodeModule-BUDoTwT9.js";
|
|
11
|
+
import { t as _defineProperty } from "../defineProperty-mefzVtTv.js";
|
|
12
|
+
import { createSignatureManager } from "@incodetech/core/signature";
|
|
13
13
|
//#region ../../node_modules/.pnpm/signature_pad@5.1.3/node_modules/signature_pad/dist/signature_pad.js
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
14
|
+
/*!
|
|
15
|
+
* Signature Pad v5.1.3 | https://github.com/szimek/signature_pad
|
|
16
|
+
* (c) 2025 Szymon Nowak | Released under the MIT license
|
|
17
|
+
*/
|
|
18
|
+
var Point = class {
|
|
19
|
+
constructor(x, y, pressure, time) {
|
|
20
|
+
_defineProperty(this, "x", void 0);
|
|
21
|
+
_defineProperty(this, "y", void 0);
|
|
22
|
+
_defineProperty(this, "pressure", void 0);
|
|
23
|
+
_defineProperty(this, "time", void 0);
|
|
24
|
+
if (isNaN(x) || isNaN(y)) throw new Error(`Point is invalid: (${x}, ${y})`);
|
|
25
|
+
this.x = +x;
|
|
26
|
+
this.y = +y;
|
|
27
|
+
this.pressure = pressure || 0;
|
|
28
|
+
this.time = time || Date.now();
|
|
29
|
+
}
|
|
30
|
+
distanceTo(start) {
|
|
31
|
+
return Math.sqrt(Math.pow(this.x - start.x, 2) + Math.pow(this.y - start.y, 2));
|
|
32
|
+
}
|
|
33
|
+
equals(other) {
|
|
34
|
+
return this.x === other.x && this.y === other.y && this.pressure === other.pressure && this.time === other.time;
|
|
35
|
+
}
|
|
36
|
+
velocityFrom(start) {
|
|
37
|
+
return this.time !== start.time ? this.distanceTo(start) / (this.time - start.time) : 0;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var Bezier = class _Bezier {
|
|
41
|
+
constructor(startPoint, control2, control1, endPoint, startWidth, endWidth) {
|
|
42
|
+
this.startPoint = startPoint;
|
|
43
|
+
this.control2 = control2;
|
|
44
|
+
this.control1 = control1;
|
|
45
|
+
this.endPoint = endPoint;
|
|
46
|
+
this.startWidth = startWidth;
|
|
47
|
+
this.endWidth = endWidth;
|
|
48
|
+
}
|
|
49
|
+
static fromPoints(points, widths) {
|
|
50
|
+
const c2 = this.calculateControlPoints(points[0], points[1], points[2]).c2;
|
|
51
|
+
const c3 = this.calculateControlPoints(points[1], points[2], points[3]).c1;
|
|
52
|
+
return new _Bezier(points[1], c2, c3, points[2], widths.start, widths.end);
|
|
53
|
+
}
|
|
54
|
+
static calculateControlPoints(s1, s2, s3) {
|
|
55
|
+
const dx1 = s1.x - s2.x;
|
|
56
|
+
const dy1 = s1.y - s2.y;
|
|
57
|
+
const dx2 = s2.x - s3.x;
|
|
58
|
+
const dy2 = s2.y - s3.y;
|
|
59
|
+
const m1 = {
|
|
60
|
+
x: (s1.x + s2.x) / 2,
|
|
61
|
+
y: (s1.y + s2.y) / 2
|
|
62
|
+
};
|
|
63
|
+
const m2 = {
|
|
64
|
+
x: (s2.x + s3.x) / 2,
|
|
65
|
+
y: (s2.y + s3.y) / 2
|
|
66
|
+
};
|
|
67
|
+
const l1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
|
|
68
|
+
const l2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
|
|
69
|
+
const dxm = m1.x - m2.x;
|
|
70
|
+
const dym = m1.y - m2.y;
|
|
71
|
+
const k = l1 + l2 == 0 ? 0 : l2 / (l1 + l2);
|
|
72
|
+
const cm = {
|
|
73
|
+
x: m2.x + dxm * k,
|
|
74
|
+
y: m2.y + dym * k
|
|
75
|
+
};
|
|
76
|
+
const tx = s2.x - cm.x;
|
|
77
|
+
const ty = s2.y - cm.y;
|
|
47
78
|
return {
|
|
48
|
-
c1: new
|
|
49
|
-
c2: new
|
|
79
|
+
c1: new Point(m1.x + tx, m1.y + ty),
|
|
80
|
+
c2: new Point(m2.x + tx, m2.y + ty)
|
|
50
81
|
};
|
|
51
82
|
}
|
|
52
83
|
length() {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
84
|
+
const steps = 10;
|
|
85
|
+
let length = 0;
|
|
86
|
+
let px;
|
|
87
|
+
let py;
|
|
88
|
+
for (let i = 0; i <= steps; i += 1) {
|
|
89
|
+
const t = i / steps;
|
|
90
|
+
const cx = this.point(t, this.startPoint.x, this.control1.x, this.control2.x, this.endPoint.x);
|
|
91
|
+
const cy = this.point(t, this.startPoint.y, this.control1.y, this.control2.y, this.endPoint.y);
|
|
92
|
+
if (i > 0) {
|
|
93
|
+
const xdiff = cx - px;
|
|
94
|
+
const ydiff = cy - py;
|
|
95
|
+
length += Math.sqrt(xdiff * xdiff + ydiff * ydiff);
|
|
59
96
|
}
|
|
60
|
-
|
|
97
|
+
px = cx;
|
|
98
|
+
py = cy;
|
|
61
99
|
}
|
|
62
|
-
return
|
|
100
|
+
return length;
|
|
63
101
|
}
|
|
64
|
-
point(
|
|
65
|
-
return
|
|
102
|
+
point(t, start, c1, c2, end) {
|
|
103
|
+
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;
|
|
66
104
|
}
|
|
67
|
-
}
|
|
105
|
+
};
|
|
106
|
+
var SignatureEventTarget = class {
|
|
68
107
|
constructor() {
|
|
69
|
-
|
|
108
|
+
_defineProperty(this, "_et", void 0);
|
|
70
109
|
try {
|
|
71
110
|
this._et = new EventTarget();
|
|
72
111
|
} catch {
|
|
73
112
|
this._et = document;
|
|
74
113
|
}
|
|
75
114
|
}
|
|
76
|
-
addEventListener(
|
|
77
|
-
this._et.addEventListener(
|
|
115
|
+
addEventListener(type, listener, options) {
|
|
116
|
+
this._et.addEventListener(type, listener, options);
|
|
78
117
|
}
|
|
79
|
-
dispatchEvent(
|
|
80
|
-
return this._et.dispatchEvent(
|
|
118
|
+
dispatchEvent(event) {
|
|
119
|
+
return this._et.dispatchEvent(event);
|
|
81
120
|
}
|
|
82
|
-
removeEventListener(
|
|
83
|
-
this._et.removeEventListener(
|
|
121
|
+
removeEventListener(type, callback, options) {
|
|
122
|
+
this._et.removeEventListener(type, callback, options);
|
|
84
123
|
}
|
|
85
124
|
};
|
|
86
|
-
function
|
|
87
|
-
let
|
|
88
|
-
|
|
125
|
+
function throttle(fn, wait = 250) {
|
|
126
|
+
let previous = 0;
|
|
127
|
+
let timeout = null;
|
|
128
|
+
let result;
|
|
129
|
+
let storedContext;
|
|
130
|
+
let storedArgs;
|
|
131
|
+
const later = () => {
|
|
132
|
+
previous = Date.now();
|
|
133
|
+
timeout = null;
|
|
134
|
+
result = fn.apply(storedContext, storedArgs);
|
|
135
|
+
if (!timeout) {
|
|
136
|
+
storedContext = null;
|
|
137
|
+
storedArgs = [];
|
|
138
|
+
}
|
|
89
139
|
};
|
|
90
|
-
return function(...
|
|
91
|
-
|
|
92
|
-
|
|
140
|
+
return function wrapper(...args) {
|
|
141
|
+
const now = Date.now();
|
|
142
|
+
const remaining = wait - (now - previous);
|
|
143
|
+
storedContext = this;
|
|
144
|
+
storedArgs = args;
|
|
145
|
+
if (remaining <= 0 || remaining > wait) {
|
|
146
|
+
if (timeout) {
|
|
147
|
+
clearTimeout(timeout);
|
|
148
|
+
timeout = null;
|
|
149
|
+
}
|
|
150
|
+
previous = now;
|
|
151
|
+
result = fn.apply(storedContext, storedArgs);
|
|
152
|
+
if (!timeout) {
|
|
153
|
+
storedContext = null;
|
|
154
|
+
storedArgs = [];
|
|
155
|
+
}
|
|
156
|
+
} else if (!timeout) timeout = window.setTimeout(later, remaining);
|
|
157
|
+
return result;
|
|
93
158
|
};
|
|
94
159
|
}
|
|
95
|
-
var
|
|
96
|
-
constructor(
|
|
97
|
-
super()
|
|
160
|
+
var SignaturePad = class _SignaturePad extends SignatureEventTarget {
|
|
161
|
+
constructor(canvas, options = {}) {
|
|
162
|
+
super();
|
|
163
|
+
_defineProperty(this, "dotSize", void 0);
|
|
164
|
+
_defineProperty(this, "minWidth", void 0);
|
|
165
|
+
_defineProperty(this, "maxWidth", void 0);
|
|
166
|
+
_defineProperty(this, "penColor", void 0);
|
|
167
|
+
_defineProperty(this, "minDistance", void 0);
|
|
168
|
+
_defineProperty(this, "velocityFilterWeight", void 0);
|
|
169
|
+
_defineProperty(this, "compositeOperation", void 0);
|
|
170
|
+
_defineProperty(this, "backgroundColor", void 0);
|
|
171
|
+
_defineProperty(this, "throttle", void 0);
|
|
172
|
+
_defineProperty(this, "canvasContextOptions", void 0);
|
|
173
|
+
_defineProperty(this, "_ctx", void 0);
|
|
174
|
+
_defineProperty(this, "_drawingStroke", false);
|
|
175
|
+
_defineProperty(this, "_isEmpty", true);
|
|
176
|
+
_defineProperty(this, "_dataUrl", void 0);
|
|
177
|
+
_defineProperty(this, "_dataUrlOptions", void 0);
|
|
178
|
+
_defineProperty(this, "_lastPoints", []);
|
|
179
|
+
_defineProperty(this, "_data", []);
|
|
180
|
+
_defineProperty(this, "_lastVelocity", 0);
|
|
181
|
+
_defineProperty(this, "_lastWidth", 0);
|
|
182
|
+
_defineProperty(this, "_strokeMoveUpdate", void 0);
|
|
183
|
+
_defineProperty(this, "_strokePointerId", void 0);
|
|
184
|
+
this.canvas = canvas;
|
|
185
|
+
this.velocityFilterWeight = options.velocityFilterWeight || .7;
|
|
186
|
+
this.minWidth = options.minWidth || .5;
|
|
187
|
+
this.maxWidth = options.maxWidth || 2.5;
|
|
188
|
+
this.throttle = options.throttle ?? 16;
|
|
189
|
+
this.minDistance = options.minDistance ?? 5;
|
|
190
|
+
this.dotSize = options.dotSize || 0;
|
|
191
|
+
this.penColor = options.penColor || "black";
|
|
192
|
+
this.backgroundColor = options.backgroundColor || "rgba(0,0,0,0)";
|
|
193
|
+
this.compositeOperation = options.compositeOperation || "source-over";
|
|
194
|
+
this.canvasContextOptions = options.canvasContextOptions ?? {};
|
|
195
|
+
this._strokeMoveUpdate = this.throttle ? throttle(_SignaturePad.prototype._strokeUpdate, this.throttle) : _SignaturePad.prototype._strokeUpdate;
|
|
196
|
+
this._handleMouseDown = this._handleMouseDown.bind(this);
|
|
197
|
+
this._handleMouseMove = this._handleMouseMove.bind(this);
|
|
198
|
+
this._handleMouseUp = this._handleMouseUp.bind(this);
|
|
199
|
+
this._handleTouchStart = this._handleTouchStart.bind(this);
|
|
200
|
+
this._handleTouchMove = this._handleTouchMove.bind(this);
|
|
201
|
+
this._handleTouchEnd = this._handleTouchEnd.bind(this);
|
|
202
|
+
this._handlePointerDown = this._handlePointerDown.bind(this);
|
|
203
|
+
this._handlePointerMove = this._handlePointerMove.bind(this);
|
|
204
|
+
this._handlePointerUp = this._handlePointerUp.bind(this);
|
|
205
|
+
this._handlePointerCancel = this._handlePointerCancel.bind(this);
|
|
206
|
+
this._handleTouchCancel = this._handleTouchCancel.bind(this);
|
|
207
|
+
this._ctx = canvas.getContext("2d", this.canvasContextOptions);
|
|
208
|
+
this.clear();
|
|
209
|
+
this.on();
|
|
98
210
|
}
|
|
99
211
|
clear() {
|
|
100
|
-
|
|
101
|
-
|
|
212
|
+
const { _ctx: ctx, canvas } = this;
|
|
213
|
+
ctx.fillStyle = this.backgroundColor;
|
|
214
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
215
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
216
|
+
this._data = [];
|
|
217
|
+
this._reset(this._getPointGroupOptions());
|
|
218
|
+
this._isEmpty = true;
|
|
219
|
+
this._dataUrl = void 0;
|
|
220
|
+
this._dataUrlOptions = void 0;
|
|
221
|
+
this._strokePointerId = void 0;
|
|
102
222
|
}
|
|
103
223
|
redraw() {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
224
|
+
const data = this._data;
|
|
225
|
+
const dataUrl = this._dataUrl;
|
|
226
|
+
const dataUrlOptions = this._dataUrlOptions;
|
|
227
|
+
this.clear();
|
|
228
|
+
if (dataUrl) this.fromDataURL(dataUrl, dataUrlOptions);
|
|
229
|
+
this.fromData(data, { clear: false });
|
|
230
|
+
}
|
|
231
|
+
fromDataURL(dataUrl, options = {}) {
|
|
232
|
+
return new Promise((resolve, reject) => {
|
|
233
|
+
const image = new Image();
|
|
234
|
+
const ratio = options.ratio || window.devicePixelRatio || 1;
|
|
235
|
+
const width = options.width || this.canvas.width / ratio;
|
|
236
|
+
const height = options.height || this.canvas.height / ratio;
|
|
237
|
+
const xOffset = options.xOffset || 0;
|
|
238
|
+
const yOffset = options.yOffset || 0;
|
|
239
|
+
this._reset(this._getPointGroupOptions());
|
|
240
|
+
image.onload = () => {
|
|
241
|
+
this._ctx.drawImage(image, xOffset, yOffset, width, height);
|
|
242
|
+
resolve();
|
|
243
|
+
};
|
|
244
|
+
image.onerror = (error) => {
|
|
245
|
+
reject(error);
|
|
246
|
+
};
|
|
247
|
+
image.crossOrigin = "anonymous";
|
|
248
|
+
image.src = dataUrl;
|
|
249
|
+
this._isEmpty = false;
|
|
250
|
+
this._dataUrl = dataUrl;
|
|
251
|
+
this._dataUrlOptions = { ...options };
|
|
115
252
|
});
|
|
116
253
|
}
|
|
117
|
-
toDataURL(
|
|
118
|
-
switch (
|
|
119
|
-
case "image/svg+xml":
|
|
120
|
-
|
|
254
|
+
toDataURL(type = "image/png", encoderOptions) {
|
|
255
|
+
switch (type) {
|
|
256
|
+
case "image/svg+xml":
|
|
257
|
+
if (typeof encoderOptions !== "object") encoderOptions = void 0;
|
|
258
|
+
return `data:image/svg+xml;base64,${btoa(this.toSVG(encoderOptions))}`;
|
|
259
|
+
default:
|
|
260
|
+
if (typeof encoderOptions !== "number") encoderOptions = void 0;
|
|
261
|
+
return this.canvas.toDataURL(type, encoderOptions);
|
|
121
262
|
}
|
|
122
263
|
}
|
|
123
264
|
on() {
|
|
124
|
-
this.canvas.style.touchAction = "none"
|
|
125
|
-
|
|
126
|
-
|
|
265
|
+
this.canvas.style.touchAction = "none";
|
|
266
|
+
this.canvas.style.msTouchAction = "none";
|
|
267
|
+
this.canvas.style.userSelect = "none";
|
|
268
|
+
this.canvas.style.webkitUserSelect = "none";
|
|
269
|
+
const isIOS = /Macintosh/.test(navigator.userAgent) && "ontouchstart" in document;
|
|
270
|
+
if (window.PointerEvent && !isIOS) this._handlePointerEvents();
|
|
271
|
+
else {
|
|
272
|
+
this._handleMouseEvents();
|
|
273
|
+
if ("ontouchstart" in window) this._handleTouchEvents();
|
|
274
|
+
}
|
|
127
275
|
}
|
|
128
276
|
off() {
|
|
129
|
-
this.canvas.style.touchAction = "auto"
|
|
277
|
+
this.canvas.style.touchAction = "auto";
|
|
278
|
+
this.canvas.style.msTouchAction = "auto";
|
|
279
|
+
this.canvas.style.userSelect = "auto";
|
|
280
|
+
this.canvas.style.webkitUserSelect = "auto";
|
|
281
|
+
this.canvas.removeEventListener("pointerdown", this._handlePointerDown);
|
|
282
|
+
this.canvas.removeEventListener("mousedown", this._handleMouseDown);
|
|
283
|
+
this.canvas.removeEventListener("touchstart", this._handleTouchStart);
|
|
284
|
+
this._removeMoveUpEventListeners();
|
|
130
285
|
}
|
|
131
286
|
_getListenerFunctions() {
|
|
132
|
-
|
|
287
|
+
const canvasWindow = window.document === this.canvas.ownerDocument ? window : this.canvas.ownerDocument.defaultView ?? this.canvas.ownerDocument;
|
|
133
288
|
return {
|
|
134
|
-
addEventListener:
|
|
135
|
-
removeEventListener:
|
|
289
|
+
addEventListener: canvasWindow.addEventListener.bind(canvasWindow),
|
|
290
|
+
removeEventListener: canvasWindow.removeEventListener.bind(canvasWindow)
|
|
136
291
|
};
|
|
137
292
|
}
|
|
138
293
|
_removeMoveUpEventListeners() {
|
|
139
|
-
|
|
140
|
-
|
|
294
|
+
const { removeEventListener } = this._getListenerFunctions();
|
|
295
|
+
removeEventListener("pointermove", this._handlePointerMove);
|
|
296
|
+
removeEventListener("pointerup", this._handlePointerUp);
|
|
297
|
+
removeEventListener("pointercancel", this._handlePointerCancel);
|
|
298
|
+
removeEventListener("mousemove", this._handleMouseMove);
|
|
299
|
+
removeEventListener("mouseup", this._handleMouseUp);
|
|
300
|
+
removeEventListener("touchmove", this._handleTouchMove);
|
|
301
|
+
removeEventListener("touchend", this._handleTouchEnd);
|
|
302
|
+
removeEventListener("touchcancel", this._handleTouchCancel);
|
|
141
303
|
}
|
|
142
304
|
isEmpty() {
|
|
143
305
|
return this._isEmpty;
|
|
144
306
|
}
|
|
145
|
-
fromData(
|
|
146
|
-
|
|
307
|
+
fromData(pointGroups, { clear = true } = {}) {
|
|
308
|
+
if (clear) this.clear();
|
|
309
|
+
this._fromData(pointGroups, this._drawCurve.bind(this), this._drawDot.bind(this));
|
|
310
|
+
this._data = this._data.concat(pointGroups);
|
|
147
311
|
}
|
|
148
312
|
toData() {
|
|
149
313
|
return this._data;
|
|
150
314
|
}
|
|
151
|
-
_isLeftButtonPressed(
|
|
152
|
-
|
|
315
|
+
_isLeftButtonPressed(event, only) {
|
|
316
|
+
if (only) return event.buttons === 1;
|
|
317
|
+
return (event.buttons & 1) === 1;
|
|
153
318
|
}
|
|
154
|
-
_pointerEventToSignatureEvent(
|
|
319
|
+
_pointerEventToSignatureEvent(event) {
|
|
155
320
|
return {
|
|
156
|
-
event
|
|
157
|
-
type:
|
|
158
|
-
x:
|
|
159
|
-
y:
|
|
160
|
-
pressure: "pressure" in
|
|
321
|
+
event,
|
|
322
|
+
type: event.type,
|
|
323
|
+
x: event.clientX,
|
|
324
|
+
y: event.clientY,
|
|
325
|
+
pressure: "pressure" in event ? event.pressure : 0
|
|
161
326
|
};
|
|
162
327
|
}
|
|
163
|
-
_touchEventToSignatureEvent(
|
|
164
|
-
|
|
328
|
+
_touchEventToSignatureEvent(event) {
|
|
329
|
+
const touch = event.changedTouches[0];
|
|
165
330
|
return {
|
|
166
|
-
event
|
|
167
|
-
type:
|
|
168
|
-
x:
|
|
169
|
-
y:
|
|
170
|
-
pressure:
|
|
331
|
+
event,
|
|
332
|
+
type: event.type,
|
|
333
|
+
x: touch.clientX,
|
|
334
|
+
y: touch.clientY,
|
|
335
|
+
pressure: touch.force
|
|
171
336
|
};
|
|
172
337
|
}
|
|
173
|
-
_handleMouseDown(
|
|
174
|
-
!this._isLeftButtonPressed(
|
|
338
|
+
_handleMouseDown(event) {
|
|
339
|
+
if (!this._isLeftButtonPressed(event, true) || this._drawingStroke) return;
|
|
340
|
+
this._strokeBegin(this._pointerEventToSignatureEvent(event));
|
|
175
341
|
}
|
|
176
|
-
_handleMouseMove(
|
|
177
|
-
if (!this._isLeftButtonPressed(
|
|
178
|
-
this._strokeEnd(this._pointerEventToSignatureEvent(
|
|
342
|
+
_handleMouseMove(event) {
|
|
343
|
+
if (!this._isLeftButtonPressed(event, true) || !this._drawingStroke) {
|
|
344
|
+
this._strokeEnd(this._pointerEventToSignatureEvent(event), false);
|
|
179
345
|
return;
|
|
180
346
|
}
|
|
181
|
-
this._strokeMoveUpdate(this._pointerEventToSignatureEvent(
|
|
182
|
-
}
|
|
183
|
-
_handleMouseUp(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
347
|
+
this._strokeMoveUpdate(this._pointerEventToSignatureEvent(event));
|
|
348
|
+
}
|
|
349
|
+
_handleMouseUp(event) {
|
|
350
|
+
if (this._isLeftButtonPressed(event)) return;
|
|
351
|
+
this._strokeEnd(this._pointerEventToSignatureEvent(event));
|
|
352
|
+
}
|
|
353
|
+
_handleTouchStart(event) {
|
|
354
|
+
if (event.targetTouches.length !== 1 || this._drawingStroke) return;
|
|
355
|
+
if (event.cancelable) event.preventDefault();
|
|
356
|
+
this._strokeBegin(this._touchEventToSignatureEvent(event));
|
|
357
|
+
}
|
|
358
|
+
_handleTouchMove(event) {
|
|
359
|
+
if (event.targetTouches.length !== 1) return;
|
|
360
|
+
if (event.cancelable) event.preventDefault();
|
|
361
|
+
if (!this._drawingStroke) {
|
|
362
|
+
this._strokeEnd(this._touchEventToSignatureEvent(event), false);
|
|
363
|
+
return;
|
|
196
364
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
this.
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (this.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
365
|
+
this._strokeMoveUpdate(this._touchEventToSignatureEvent(event));
|
|
366
|
+
}
|
|
367
|
+
_handleTouchEnd(event) {
|
|
368
|
+
if (event.targetTouches.length !== 0) return;
|
|
369
|
+
if (event.cancelable) event.preventDefault();
|
|
370
|
+
this._strokeEnd(this._touchEventToSignatureEvent(event));
|
|
371
|
+
}
|
|
372
|
+
_handlePointerCancel(event) {
|
|
373
|
+
if (!this._allowPointerId(event)) return;
|
|
374
|
+
event.preventDefault();
|
|
375
|
+
this._strokeEnd(this._pointerEventToSignatureEvent(event), false);
|
|
376
|
+
}
|
|
377
|
+
_handleTouchCancel(event) {
|
|
378
|
+
if (event.cancelable) event.preventDefault();
|
|
379
|
+
this._strokeEnd(this._touchEventToSignatureEvent(event), false);
|
|
380
|
+
}
|
|
381
|
+
_getPointerId(event) {
|
|
382
|
+
return event.persistentDeviceId || event.pointerId;
|
|
383
|
+
}
|
|
384
|
+
_allowPointerId(event, allowUndefined = false) {
|
|
385
|
+
if (typeof this._strokePointerId === "undefined") return allowUndefined;
|
|
386
|
+
return this._getPointerId(event) === this._strokePointerId;
|
|
387
|
+
}
|
|
388
|
+
_handlePointerDown(event) {
|
|
389
|
+
if (this._drawingStroke || !this._isLeftButtonPressed(event) || !this._allowPointerId(event, true)) return;
|
|
390
|
+
this._strokePointerId = this._getPointerId(event);
|
|
391
|
+
event.preventDefault();
|
|
392
|
+
this._strokeBegin(this._pointerEventToSignatureEvent(event));
|
|
393
|
+
}
|
|
394
|
+
_handlePointerMove(event) {
|
|
395
|
+
if (!this._allowPointerId(event)) return;
|
|
396
|
+
if (!this._isLeftButtonPressed(event, true) || !this._drawingStroke) {
|
|
397
|
+
this._strokeEnd(this._pointerEventToSignatureEvent(event), false);
|
|
398
|
+
return;
|
|
223
399
|
}
|
|
400
|
+
event.preventDefault();
|
|
401
|
+
this._strokeMoveUpdate(this._pointerEventToSignatureEvent(event));
|
|
224
402
|
}
|
|
225
|
-
_handlePointerUp(
|
|
226
|
-
this._isLeftButtonPressed(
|
|
403
|
+
_handlePointerUp(event) {
|
|
404
|
+
if (this._isLeftButtonPressed(event) || !this._allowPointerId(event)) return;
|
|
405
|
+
event.preventDefault();
|
|
406
|
+
this._strokeEnd(this._pointerEventToSignatureEvent(event));
|
|
227
407
|
}
|
|
228
|
-
_getPointGroupOptions(
|
|
408
|
+
_getPointGroupOptions(group) {
|
|
229
409
|
return {
|
|
230
|
-
penColor:
|
|
231
|
-
dotSize:
|
|
232
|
-
minWidth:
|
|
233
|
-
maxWidth:
|
|
234
|
-
velocityFilterWeight:
|
|
235
|
-
compositeOperation:
|
|
410
|
+
penColor: group && "penColor" in group ? group.penColor : this.penColor,
|
|
411
|
+
dotSize: group && "dotSize" in group ? group.dotSize : this.dotSize,
|
|
412
|
+
minWidth: group && "minWidth" in group ? group.minWidth : this.minWidth,
|
|
413
|
+
maxWidth: group && "maxWidth" in group ? group.maxWidth : this.maxWidth,
|
|
414
|
+
velocityFilterWeight: group && "velocityFilterWeight" in group ? group.velocityFilterWeight : this.velocityFilterWeight,
|
|
415
|
+
compositeOperation: group && "compositeOperation" in group ? group.compositeOperation : this.compositeOperation
|
|
236
416
|
};
|
|
237
417
|
}
|
|
238
|
-
_strokeBegin(
|
|
418
|
+
_strokeBegin(event) {
|
|
239
419
|
if (!this.dispatchEvent(new CustomEvent("beginStroke", {
|
|
240
|
-
detail:
|
|
241
|
-
cancelable:
|
|
420
|
+
detail: event,
|
|
421
|
+
cancelable: true
|
|
242
422
|
}))) return;
|
|
243
|
-
|
|
244
|
-
switch (
|
|
423
|
+
const { addEventListener } = this._getListenerFunctions();
|
|
424
|
+
switch (event.event.type) {
|
|
245
425
|
case "mousedown":
|
|
246
|
-
|
|
426
|
+
addEventListener("mousemove", this._handleMouseMove, { passive: false });
|
|
427
|
+
addEventListener("mouseup", this._handleMouseUp, { passive: false });
|
|
247
428
|
break;
|
|
248
429
|
case "touchstart":
|
|
249
|
-
|
|
430
|
+
addEventListener("touchmove", this._handleTouchMove, { passive: false });
|
|
431
|
+
addEventListener("touchend", this._handleTouchEnd, { passive: false });
|
|
432
|
+
addEventListener("touchcancel", this._handleTouchCancel, { passive: false });
|
|
250
433
|
break;
|
|
251
434
|
case "pointerdown":
|
|
252
|
-
|
|
435
|
+
addEventListener("pointermove", this._handlePointerMove, { passive: false });
|
|
436
|
+
addEventListener("pointerup", this._handlePointerUp, { passive: false });
|
|
437
|
+
addEventListener("pointercancel", this._handlePointerCancel, { passive: false });
|
|
253
438
|
break;
|
|
254
439
|
default:
|
|
255
440
|
}
|
|
256
|
-
this._drawingStroke =
|
|
257
|
-
|
|
258
|
-
|
|
441
|
+
this._drawingStroke = true;
|
|
442
|
+
const pointGroupOptions = this._getPointGroupOptions();
|
|
443
|
+
const newPointGroup = {
|
|
444
|
+
...pointGroupOptions,
|
|
259
445
|
points: []
|
|
260
446
|
};
|
|
261
|
-
this._data.push(
|
|
447
|
+
this._data.push(newPointGroup);
|
|
448
|
+
this._reset(pointGroupOptions);
|
|
449
|
+
this._strokeUpdate(event);
|
|
262
450
|
}
|
|
263
|
-
_strokeUpdate(
|
|
451
|
+
_strokeUpdate(event) {
|
|
264
452
|
if (!this._drawingStroke) return;
|
|
265
453
|
if (this._data.length === 0) {
|
|
266
|
-
this._strokeBegin(
|
|
454
|
+
this._strokeBegin(event);
|
|
267
455
|
return;
|
|
268
456
|
}
|
|
269
|
-
this.dispatchEvent(new CustomEvent("beforeUpdateStroke", { detail:
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
457
|
+
this.dispatchEvent(new CustomEvent("beforeUpdateStroke", { detail: event }));
|
|
458
|
+
const point = this._createPoint(event.x, event.y, event.pressure);
|
|
459
|
+
const lastPointGroup = this._data[this._data.length - 1];
|
|
460
|
+
const lastPoints = lastPointGroup.points;
|
|
461
|
+
const lastPoint = lastPoints.length > 0 && lastPoints[lastPoints.length - 1];
|
|
462
|
+
const isLastPointTooClose = lastPoint ? point.distanceTo(lastPoint) <= this.minDistance : false;
|
|
463
|
+
const pointGroupOptions = this._getPointGroupOptions(lastPointGroup);
|
|
464
|
+
if (!lastPoint || !(lastPoint && isLastPointTooClose)) {
|
|
465
|
+
const curve = this._addPoint(point, pointGroupOptions);
|
|
466
|
+
if (!lastPoint) this._drawDot(point, pointGroupOptions);
|
|
467
|
+
else if (curve) this._drawCurve(curve, pointGroupOptions);
|
|
468
|
+
lastPoints.push({
|
|
469
|
+
time: point.time,
|
|
470
|
+
x: point.x,
|
|
471
|
+
y: point.y,
|
|
472
|
+
pressure: point.pressure
|
|
278
473
|
});
|
|
279
474
|
}
|
|
280
|
-
this.dispatchEvent(new CustomEvent("afterUpdateStroke", { detail:
|
|
475
|
+
this.dispatchEvent(new CustomEvent("afterUpdateStroke", { detail: event }));
|
|
281
476
|
}
|
|
282
|
-
_strokeEnd(
|
|
283
|
-
this._removeMoveUpEventListeners()
|
|
477
|
+
_strokeEnd(event, shouldUpdate = true) {
|
|
478
|
+
this._removeMoveUpEventListeners();
|
|
479
|
+
if (!this._drawingStroke) return;
|
|
480
|
+
if (shouldUpdate) this._strokeUpdate(event);
|
|
481
|
+
this._drawingStroke = false;
|
|
482
|
+
this._strokePointerId = void 0;
|
|
483
|
+
this.dispatchEvent(new CustomEvent("endStroke", { detail: event }));
|
|
284
484
|
}
|
|
285
485
|
_handlePointerEvents() {
|
|
286
|
-
this._drawingStroke =
|
|
486
|
+
this._drawingStroke = false;
|
|
487
|
+
this.canvas.addEventListener("pointerdown", this._handlePointerDown, { passive: false });
|
|
287
488
|
}
|
|
288
489
|
_handleMouseEvents() {
|
|
289
|
-
this._drawingStroke =
|
|
490
|
+
this._drawingStroke = false;
|
|
491
|
+
this.canvas.addEventListener("mousedown", this._handleMouseDown, { passive: false });
|
|
290
492
|
}
|
|
291
493
|
_handleTouchEvents() {
|
|
292
|
-
this.canvas.addEventListener("touchstart", this._handleTouchStart, { passive:
|
|
293
|
-
}
|
|
294
|
-
_reset(
|
|
295
|
-
this._lastPoints = []
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
494
|
+
this.canvas.addEventListener("touchstart", this._handleTouchStart, { passive: false });
|
|
495
|
+
}
|
|
496
|
+
_reset(options) {
|
|
497
|
+
this._lastPoints = [];
|
|
498
|
+
this._lastVelocity = 0;
|
|
499
|
+
this._lastWidth = (options.minWidth + options.maxWidth) / 2;
|
|
500
|
+
this._ctx.fillStyle = options.penColor;
|
|
501
|
+
this._ctx.globalCompositeOperation = options.compositeOperation;
|
|
502
|
+
}
|
|
503
|
+
_createPoint(x, y, pressure) {
|
|
504
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
505
|
+
return new Point(x - rect.left, y - rect.top, pressure, (/* @__PURE__ */ new Date()).getTime());
|
|
506
|
+
}
|
|
507
|
+
_addPoint(point, options) {
|
|
508
|
+
const { _lastPoints } = this;
|
|
509
|
+
_lastPoints.push(point);
|
|
510
|
+
if (_lastPoints.length > 2) {
|
|
511
|
+
if (_lastPoints.length === 3) _lastPoints.unshift(_lastPoints[0]);
|
|
512
|
+
const widths = this._calculateCurveWidths(_lastPoints[1], _lastPoints[2], options);
|
|
513
|
+
const curve = Bezier.fromPoints(_lastPoints, widths);
|
|
514
|
+
_lastPoints.shift();
|
|
515
|
+
return curve;
|
|
307
516
|
}
|
|
308
517
|
return null;
|
|
309
518
|
}
|
|
310
|
-
_calculateCurveWidths(
|
|
311
|
-
|
|
312
|
-
|
|
519
|
+
_calculateCurveWidths(startPoint, endPoint, options) {
|
|
520
|
+
const velocity = options.velocityFilterWeight * endPoint.velocityFrom(startPoint) + (1 - options.velocityFilterWeight) * this._lastVelocity;
|
|
521
|
+
const newWidth = this._strokeWidth(velocity, options);
|
|
522
|
+
const widths = {
|
|
523
|
+
end: newWidth,
|
|
313
524
|
start: this._lastWidth
|
|
314
525
|
};
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
526
|
+
this._lastVelocity = velocity;
|
|
527
|
+
this._lastWidth = newWidth;
|
|
528
|
+
return widths;
|
|
529
|
+
}
|
|
530
|
+
_strokeWidth(velocity, options) {
|
|
531
|
+
return Math.max(options.maxWidth / (velocity + 1), options.minWidth);
|
|
532
|
+
}
|
|
533
|
+
_drawCurveSegment(x, y, width) {
|
|
534
|
+
const ctx = this._ctx;
|
|
535
|
+
ctx.moveTo(x, y);
|
|
536
|
+
ctx.arc(x, y, width, 0, 2 * Math.PI, false);
|
|
537
|
+
this._isEmpty = false;
|
|
538
|
+
}
|
|
539
|
+
_drawCurve(curve, options) {
|
|
540
|
+
const ctx = this._ctx;
|
|
541
|
+
const widthDelta = curve.endWidth - curve.startWidth;
|
|
542
|
+
const drawSteps = Math.ceil(curve.length()) * 2;
|
|
543
|
+
ctx.beginPath();
|
|
544
|
+
ctx.fillStyle = options.penColor;
|
|
545
|
+
for (let i = 0; i < drawSteps; i += 1) {
|
|
546
|
+
const t = i / drawSteps;
|
|
547
|
+
const tt = t * t;
|
|
548
|
+
const ttt = tt * t;
|
|
549
|
+
const u = 1 - t;
|
|
550
|
+
const uu = u * u;
|
|
551
|
+
const uuu = uu * u;
|
|
552
|
+
let x = uuu * curve.startPoint.x;
|
|
553
|
+
x += 3 * uu * t * curve.control1.x;
|
|
554
|
+
x += 3 * u * tt * curve.control2.x;
|
|
555
|
+
x += ttt * curve.endPoint.x;
|
|
556
|
+
let y = uuu * curve.startPoint.y;
|
|
557
|
+
y += 3 * uu * t * curve.control1.y;
|
|
558
|
+
y += 3 * u * tt * curve.control2.y;
|
|
559
|
+
y += ttt * curve.endPoint.y;
|
|
560
|
+
const width = Math.min(curve.startWidth + ttt * widthDelta, options.maxWidth);
|
|
561
|
+
this._drawCurveSegment(x, y, width);
|
|
334
562
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
563
|
+
ctx.closePath();
|
|
564
|
+
ctx.fill();
|
|
565
|
+
}
|
|
566
|
+
_drawDot(point, options) {
|
|
567
|
+
const ctx = this._ctx;
|
|
568
|
+
const width = options.dotSize > 0 ? options.dotSize : (options.minWidth + options.maxWidth) / 2;
|
|
569
|
+
ctx.beginPath();
|
|
570
|
+
this._drawCurveSegment(point.x, point.y, width);
|
|
571
|
+
ctx.closePath();
|
|
572
|
+
ctx.fillStyle = options.penColor;
|
|
573
|
+
ctx.fill();
|
|
574
|
+
}
|
|
575
|
+
_fromData(pointGroups, drawCurve, drawDot) {
|
|
576
|
+
for (const group of pointGroups) {
|
|
577
|
+
const { points } = group;
|
|
578
|
+
const pointGroupOptions = this._getPointGroupOptions(group);
|
|
579
|
+
if (points.length > 1) for (let j = 0; j < points.length; j += 1) {
|
|
580
|
+
const basicPoint = points[j];
|
|
581
|
+
const point = new Point(basicPoint.x, basicPoint.y, basicPoint.pressure, basicPoint.time);
|
|
582
|
+
if (j === 0) this._reset(pointGroupOptions);
|
|
583
|
+
const curve = this._addPoint(point, pointGroupOptions);
|
|
584
|
+
if (curve) drawCurve(curve, pointGroupOptions);
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
this._reset(pointGroupOptions);
|
|
588
|
+
drawDot(points[0], pointGroupOptions);
|
|
349
589
|
}
|
|
350
|
-
else this._reset(i), n(e[0], i);
|
|
351
590
|
}
|
|
352
591
|
}
|
|
353
|
-
toSVG({ includeBackgroundColor
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
592
|
+
toSVG({ includeBackgroundColor = false, includeDataUrl = false } = {}) {
|
|
593
|
+
const pointGroups = this._data;
|
|
594
|
+
const ratio = Math.max(window.devicePixelRatio || 1, 1);
|
|
595
|
+
const minX = 0;
|
|
596
|
+
const minY = 0;
|
|
597
|
+
const maxX = this.canvas.width / ratio;
|
|
598
|
+
const maxY = this.canvas.height / ratio;
|
|
599
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
600
|
+
svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
|
|
601
|
+
svg.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
|
|
602
|
+
svg.setAttribute("viewBox", `${minX} ${minY} ${maxX} ${maxY}`);
|
|
603
|
+
svg.setAttribute("width", maxX.toString());
|
|
604
|
+
svg.setAttribute("height", maxY.toString());
|
|
605
|
+
if (includeBackgroundColor && this.backgroundColor) {
|
|
606
|
+
const rect = document.createElement("rect");
|
|
607
|
+
rect.setAttribute("width", "100%");
|
|
608
|
+
rect.setAttribute("height", "100%");
|
|
609
|
+
rect.setAttribute("fill", this.backgroundColor);
|
|
610
|
+
svg.appendChild(rect);
|
|
358
611
|
}
|
|
359
|
-
if (
|
|
360
|
-
|
|
361
|
-
|
|
612
|
+
if (includeDataUrl && this._dataUrl) {
|
|
613
|
+
const ratio2 = this._dataUrlOptions?.ratio || window.devicePixelRatio || 1;
|
|
614
|
+
const width = this._dataUrlOptions?.width || this.canvas.width / ratio2;
|
|
615
|
+
const height = this._dataUrlOptions?.height || this.canvas.height / ratio2;
|
|
616
|
+
const xOffset = this._dataUrlOptions?.xOffset || 0;
|
|
617
|
+
const yOffset = this._dataUrlOptions?.yOffset || 0;
|
|
618
|
+
const image = document.createElement("image");
|
|
619
|
+
image.setAttribute("x", xOffset.toString());
|
|
620
|
+
image.setAttribute("y", yOffset.toString());
|
|
621
|
+
image.setAttribute("width", width.toString());
|
|
622
|
+
image.setAttribute("height", height.toString());
|
|
623
|
+
image.setAttribute("preserveAspectRatio", "none");
|
|
624
|
+
image.setAttribute("href", this._dataUrl);
|
|
625
|
+
svg.appendChild(image);
|
|
362
626
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
if (!isNaN(
|
|
366
|
-
|
|
367
|
-
|
|
627
|
+
this._fromData(pointGroups, (curve, { penColor }) => {
|
|
628
|
+
const path = document.createElement("path");
|
|
629
|
+
if (!isNaN(curve.control1.x) && !isNaN(curve.control1.y) && !isNaN(curve.control2.x) && !isNaN(curve.control2.y)) {
|
|
630
|
+
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)}`;
|
|
631
|
+
path.setAttribute("d", attr);
|
|
632
|
+
path.setAttribute("stroke-width", (curve.endWidth * 2.25).toFixed(3));
|
|
633
|
+
path.setAttribute("stroke", penColor);
|
|
634
|
+
path.setAttribute("fill", "none");
|
|
635
|
+
path.setAttribute("stroke-linecap", "round");
|
|
636
|
+
svg.appendChild(path);
|
|
368
637
|
}
|
|
369
|
-
}, (
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
638
|
+
}, (point, { penColor, dotSize, minWidth, maxWidth }) => {
|
|
639
|
+
const circle = document.createElement("circle");
|
|
640
|
+
const size = dotSize > 0 ? dotSize : (minWidth + maxWidth) / 2;
|
|
641
|
+
circle.setAttribute("r", size.toString());
|
|
642
|
+
circle.setAttribute("cx", point.x.toString());
|
|
643
|
+
circle.setAttribute("cy", point.y.toString());
|
|
644
|
+
circle.setAttribute("fill", penColor);
|
|
645
|
+
svg.appendChild(circle);
|
|
646
|
+
});
|
|
647
|
+
return svg.outerHTML;
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
//#endregion
|
|
651
|
+
//#region src/styles/resolveCssVariableToHex.ts
|
|
652
|
+
var resolveCssVariableToHex = (cssVar) => {
|
|
653
|
+
if (typeof document === "undefined") return null;
|
|
654
|
+
const tempEl = document.createElement("div");
|
|
655
|
+
tempEl.style.color = cssVar;
|
|
656
|
+
tempEl.style.position = "absolute";
|
|
657
|
+
tempEl.style.visibility = "hidden";
|
|
658
|
+
document.body.appendChild(tempEl);
|
|
659
|
+
const computedColor = getComputedStyle(tempEl).color;
|
|
660
|
+
document.body.removeChild(tempEl);
|
|
661
|
+
if (!computedColor || computedColor === "transparent") return null;
|
|
662
|
+
const rgbMatch = computedColor.match(/\d+/g);
|
|
663
|
+
if (rgbMatch && rgbMatch.length >= 3) {
|
|
664
|
+
const r = Number.parseInt(rgbMatch[0], 10);
|
|
665
|
+
const g = Number.parseInt(rgbMatch[1], 10);
|
|
666
|
+
const b = Number.parseInt(rgbMatch[2], 10);
|
|
667
|
+
const toHex = (n) => {
|
|
668
|
+
const hex = n.toString(16);
|
|
669
|
+
return hex.length === 1 ? `0${hex}` : hex;
|
|
385
670
|
};
|
|
386
|
-
return `#${
|
|
671
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
387
672
|
}
|
|
388
673
|
return null;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
674
|
+
};
|
|
675
|
+
//#endregion
|
|
676
|
+
//#region src/modules/signature/signatureCanvas.tsx
|
|
677
|
+
var SIGNATURE_PEN_COLOR = "var(--icon-neutral-800)";
|
|
678
|
+
/** Fixed white background for export (avoid transparency and theme dependency) */
|
|
679
|
+
var EXPORT_BACKGROUND_COLOR = "#ffffff";
|
|
680
|
+
var copyCanvasWithWhiteBackground = (source) => {
|
|
681
|
+
const target = document.createElement("canvas");
|
|
682
|
+
target.width = source.width;
|
|
683
|
+
target.height = source.height;
|
|
684
|
+
const ctx = target.getContext("2d");
|
|
685
|
+
if (!ctx) throw new Error("Canvas 2D context is not available");
|
|
686
|
+
ctx.fillStyle = EXPORT_BACKGROUND_COLOR;
|
|
687
|
+
ctx.fillRect(0, 0, target.width, target.height);
|
|
688
|
+
ctx.drawImage(source, 0, 0);
|
|
689
|
+
return target;
|
|
690
|
+
};
|
|
691
|
+
var canvasToBlob = (canvas, mimeType, quality) => {
|
|
692
|
+
return new Promise((resolve, reject) => {
|
|
693
|
+
canvas.toBlob((blob) => {
|
|
694
|
+
if (blob) resolve(blob);
|
|
695
|
+
else reject(/* @__PURE__ */ new Error("Canvas toBlob() returned null"));
|
|
696
|
+
}, mimeType, mimeType === "image/jpeg" || mimeType === "image/webp" ? quality : void 0);
|
|
697
|
+
});
|
|
698
|
+
};
|
|
699
|
+
var SignatureCanvas = D(({ onBeginStroke, hasDrawing, placeholder, ariaLabel, customPenColor, customPenStrokeWidth, customBackgroundColor, customBorderColor }, ref) => {
|
|
700
|
+
const containerRef = A(null);
|
|
701
|
+
const canvasRef = A(null);
|
|
702
|
+
const signaturePadRef = A(null);
|
|
703
|
+
const onBeginStrokeRef = A(onBeginStroke);
|
|
704
|
+
onBeginStrokeRef.current = onBeginStroke;
|
|
705
|
+
const resizeSignaturePad = q(() => {
|
|
706
|
+
const container = containerRef.current;
|
|
707
|
+
const canvas = canvasRef.current;
|
|
708
|
+
const pad = signaturePadRef.current;
|
|
709
|
+
if (!container || !canvas || !pad) return;
|
|
710
|
+
const ratio = Math.max(window.devicePixelRatio || 1, 1);
|
|
711
|
+
const context = canvas.getContext("2d");
|
|
712
|
+
const { width, height } = container.getBoundingClientRect();
|
|
713
|
+
if (width === 0 || height === 0 || !context) return;
|
|
714
|
+
const data = pad.isEmpty() ? null : pad.toData();
|
|
715
|
+
canvas.width = Math.floor(width * ratio);
|
|
716
|
+
canvas.height = Math.floor(height * ratio);
|
|
717
|
+
context.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
718
|
+
if (data) pad.fromData(data, { clear: true });
|
|
719
|
+
else pad.clear();
|
|
409
720
|
}, []);
|
|
410
|
-
|
|
721
|
+
F(ref, () => ({
|
|
411
722
|
clear: () => {
|
|
412
|
-
|
|
723
|
+
signaturePadRef.current?.clear();
|
|
413
724
|
},
|
|
414
|
-
isEmpty: () =>
|
|
415
|
-
toDataURL: (
|
|
416
|
-
getCanvas: () =>
|
|
417
|
-
getSignaturePad: () =>
|
|
418
|
-
on: () =>
|
|
419
|
-
off: () =>
|
|
725
|
+
isEmpty: () => signaturePadRef.current?.isEmpty() ?? true,
|
|
726
|
+
toDataURL: (type = "image/png", encoderOptions) => signaturePadRef.current?.toDataURL(type, encoderOptions) ?? "",
|
|
727
|
+
getCanvas: () => canvasRef.current,
|
|
728
|
+
getSignaturePad: () => signaturePadRef.current,
|
|
729
|
+
on: () => signaturePadRef.current?.on(),
|
|
730
|
+
off: () => signaturePadRef.current?.off(),
|
|
420
731
|
getSignatureWithWhiteBackground: () => {
|
|
421
|
-
|
|
422
|
-
|
|
732
|
+
const canvas = canvasRef.current;
|
|
733
|
+
if (!canvas) return null;
|
|
734
|
+
return copyCanvasWithWhiteBackground(canvas);
|
|
423
735
|
},
|
|
424
|
-
getBlob: (
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
736
|
+
getBlob: (canvas = canvasRef.current ?? void 0, mimeType = "image/jpeg", quality = .92) => {
|
|
737
|
+
if (!canvas) return Promise.reject(/* @__PURE__ */ new Error("No canvas available for getBlob"));
|
|
738
|
+
return canvasToBlob(canvas, mimeType, quality);
|
|
739
|
+
}
|
|
740
|
+
}), []);
|
|
741
|
+
y(() => {
|
|
742
|
+
const container = containerRef.current;
|
|
743
|
+
const canvas = canvasRef.current;
|
|
744
|
+
if (!container || !canvas) return;
|
|
745
|
+
let resizeRafId = null;
|
|
746
|
+
const scheduleResizeSignaturePad = () => {
|
|
747
|
+
if (resizeRafId !== null) return;
|
|
748
|
+
resizeRafId = requestAnimationFrame(() => {
|
|
749
|
+
resizeRafId = null;
|
|
750
|
+
resizeSignaturePad();
|
|
751
|
+
});
|
|
752
|
+
};
|
|
753
|
+
const penColor = customPenColor ?? resolveCssVariableToHex(SIGNATURE_PEN_COLOR);
|
|
754
|
+
const signaturePad = new SignaturePad(canvas, {
|
|
755
|
+
...penColor ? { penColor } : {},
|
|
756
|
+
...customPenStrokeWidth ? { maxWidth: customPenStrokeWidth } : {}
|
|
435
757
|
});
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
758
|
+
signaturePadRef.current = signaturePad;
|
|
759
|
+
const onBegin = () => onBeginStrokeRef.current?.();
|
|
760
|
+
signaturePad.addEventListener("beginStroke", onBegin);
|
|
761
|
+
resizeSignaturePad();
|
|
762
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
763
|
+
scheduleResizeSignaturePad();
|
|
441
764
|
});
|
|
442
|
-
|
|
443
|
-
|
|
765
|
+
resizeObserver.observe(container);
|
|
766
|
+
return () => {
|
|
767
|
+
if (resizeRafId !== null) cancelAnimationFrame(resizeRafId);
|
|
768
|
+
resizeObserver.disconnect();
|
|
769
|
+
signaturePad.removeEventListener("beginStroke", onBegin);
|
|
770
|
+
signaturePad.off();
|
|
771
|
+
signaturePadRef.current = null;
|
|
444
772
|
};
|
|
445
773
|
}, [
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
])
|
|
774
|
+
resizeSignaturePad,
|
|
775
|
+
customPenColor,
|
|
776
|
+
customPenStrokeWidth
|
|
777
|
+
]);
|
|
778
|
+
return /* @__PURE__ */ u("div", {
|
|
450
779
|
class: "SignatureCanvasContainer",
|
|
451
|
-
style:
|
|
452
|
-
...
|
|
453
|
-
...
|
|
780
|
+
style: customBackgroundColor || customBorderColor ? {
|
|
781
|
+
...customBackgroundColor ? { backgroundColor: customBackgroundColor } : {},
|
|
782
|
+
...customBorderColor ? { borderColor: customBorderColor } : {}
|
|
454
783
|
} : void 0,
|
|
455
|
-
ref:
|
|
456
|
-
children: [/* @__PURE__ */
|
|
784
|
+
ref: containerRef,
|
|
785
|
+
children: [/* @__PURE__ */ u("canvas", {
|
|
457
786
|
class: "SignatureCanvas",
|
|
458
|
-
ref:
|
|
459
|
-
"
|
|
460
|
-
|
|
787
|
+
ref: canvasRef,
|
|
788
|
+
role: "img",
|
|
789
|
+
"aria-label": ariaLabel ?? placeholder
|
|
790
|
+
}), !hasDrawing && /* @__PURE__ */ u("p", {
|
|
461
791
|
class: "SignatureCanvasPlaceholder",
|
|
462
|
-
|
|
792
|
+
"aria-hidden": "true",
|
|
793
|
+
children: placeholder
|
|
463
794
|
})]
|
|
464
795
|
});
|
|
465
796
|
});
|
|
466
|
-
|
|
797
|
+
SignatureCanvas.displayName = "SignatureCanvas";
|
|
467
798
|
//#endregion
|
|
468
799
|
//#region src/modules/signature/signature.tsx
|
|
469
|
-
var
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
800
|
+
var SignatureContent = ({ config, onFinish, onError }) => {
|
|
801
|
+
const { t } = useTranslation();
|
|
802
|
+
const [state, manager] = useManager(() => createSignatureManager({ config }), { autoLoad: true });
|
|
803
|
+
const [hasDrawing, setHasDrawing] = d(false);
|
|
804
|
+
const [announcement, setAnnouncement] = d("");
|
|
805
|
+
const signatureRef = A(null);
|
|
806
|
+
const error = state.status === "error" ? state.error : void 0;
|
|
807
|
+
const isSubmitting = state.status === "submitting";
|
|
808
|
+
const canContinue = state.status === "capture" && state.canContinue && !isSubmitting;
|
|
809
|
+
const clearCanvas = q(() => {
|
|
810
|
+
if (!signatureRef.current) return;
|
|
811
|
+
signatureRef.current.on();
|
|
812
|
+
signatureRef.current.clear();
|
|
813
|
+
setHasDrawing(false);
|
|
814
|
+
setAnnouncement(t("signature.cleared"));
|
|
815
|
+
manager.setSignatureValid(false);
|
|
816
|
+
}, [manager, t]);
|
|
817
|
+
useModuleTerminalCallbacks({
|
|
818
|
+
status: state.status === "finished" ? "finished" : "loading",
|
|
819
|
+
onFinish
|
|
820
|
+
});
|
|
821
|
+
y(() => {
|
|
822
|
+
if (!error) return;
|
|
823
|
+
onError?.(error);
|
|
824
|
+
signatureRef.current?.on();
|
|
825
|
+
}, [error, onError]);
|
|
826
|
+
const resolveTitle = () => {
|
|
827
|
+
const configuredTitle = config.title?.trim();
|
|
828
|
+
if (configuredTitle) return configuredTitle;
|
|
829
|
+
return t("signature.fullSignatureTitle");
|
|
830
|
+
};
|
|
831
|
+
const resolveSubtitle = () => {
|
|
832
|
+
const configuredSubtitle = config.subTitle?.trim();
|
|
833
|
+
if (configuredSubtitle) return configuredSubtitle;
|
|
834
|
+
return t("signature.subtitle");
|
|
835
|
+
};
|
|
836
|
+
const exportSignatureImage = async () => {
|
|
837
|
+
const canvasHandle = signatureRef.current;
|
|
838
|
+
if (!canvasHandle) return void 0;
|
|
839
|
+
const canvasWithWhiteBackground = canvasHandle.getSignatureWithWhiteBackground();
|
|
840
|
+
if (!canvasWithWhiteBackground) return void 0;
|
|
841
|
+
if (config.sendBase64 ?? false) return canvasWithWhiteBackground.toDataURL("image/png").replace(/^data:image\/png;base64,/, "");
|
|
842
|
+
return canvasHandle.getBlob(canvasWithWhiteBackground);
|
|
843
|
+
};
|
|
844
|
+
const handleContinue = async () => {
|
|
845
|
+
const canvasHandle = signatureRef.current;
|
|
846
|
+
if (!canvasHandle || state.status !== "capture" || canvasHandle.isEmpty()) return;
|
|
847
|
+
canvasHandle.off();
|
|
848
|
+
try {
|
|
849
|
+
const image = await exportSignatureImage();
|
|
850
|
+
if (!image) {
|
|
851
|
+
canvasHandle.on();
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
manager.submit(image);
|
|
855
|
+
} catch {
|
|
856
|
+
canvasHandle.on();
|
|
857
|
+
}
|
|
483
858
|
};
|
|
484
|
-
|
|
859
|
+
if (state.status === "idle" || state.status === "finished" || state.status === "error") return null;
|
|
860
|
+
if (state.status === "success") return /* @__PURE__ */ u(VerificationResult, {
|
|
485
861
|
status: "success",
|
|
486
|
-
successTitle:
|
|
487
|
-
})
|
|
862
|
+
successTitle: t("signature.successTitle")
|
|
863
|
+
});
|
|
864
|
+
return /* @__PURE__ */ u(Page, {
|
|
488
865
|
className: "IncodeSignature IncodeSignatureFadeIn",
|
|
489
|
-
title:
|
|
490
|
-
subtitle:
|
|
491
|
-
children: [/* @__PURE__ */
|
|
866
|
+
title: resolveTitle(),
|
|
867
|
+
subtitle: resolveSubtitle(),
|
|
868
|
+
children: [/* @__PURE__ */ u("div", {
|
|
492
869
|
class: "IncodeSignatureContent",
|
|
493
870
|
children: [
|
|
494
|
-
/* @__PURE__ */
|
|
495
|
-
ref:
|
|
496
|
-
hasDrawing
|
|
871
|
+
/* @__PURE__ */ u(SignatureCanvas, {
|
|
872
|
+
ref: signatureRef,
|
|
873
|
+
hasDrawing,
|
|
497
874
|
onBeginStroke: () => {
|
|
498
|
-
|
|
875
|
+
setHasDrawing(true);
|
|
876
|
+
setAnnouncement(t("signature.captured"));
|
|
877
|
+
manager.setSignatureValid(true);
|
|
499
878
|
},
|
|
500
|
-
placeholder:
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
879
|
+
placeholder: t("signature.fullSignaturePlaceholder"),
|
|
880
|
+
ariaLabel: t("signature.canvasAriaLabel"),
|
|
881
|
+
customBackgroundColor: config.canvasBackgroundColor,
|
|
882
|
+
customBorderColor: config.canvasBorderColor,
|
|
883
|
+
customPenColor: config.penColor,
|
|
884
|
+
customPenStrokeWidth: config.penStrokeWidth
|
|
505
885
|
}),
|
|
506
|
-
/* @__PURE__ */
|
|
507
|
-
/* @__PURE__ */
|
|
886
|
+
/* @__PURE__ */ u(Spacer, { size: 8 }),
|
|
887
|
+
/* @__PURE__ */ u(Button, {
|
|
508
888
|
variant: "link",
|
|
509
|
-
disabled: !
|
|
510
|
-
onClick:
|
|
511
|
-
children:
|
|
889
|
+
disabled: !hasDrawing || isSubmitting,
|
|
890
|
+
onClick: clearCanvas,
|
|
891
|
+
children: t("signature.clear")
|
|
892
|
+
}),
|
|
893
|
+
/* @__PURE__ */ u("span", {
|
|
894
|
+
class: "IncodeSrOnly",
|
|
895
|
+
"aria-live": "polite",
|
|
896
|
+
"aria-atomic": "true",
|
|
897
|
+
children: announcement
|
|
512
898
|
})
|
|
513
899
|
]
|
|
514
|
-
}), /* @__PURE__ */
|
|
900
|
+
}), /* @__PURE__ */ u("div", {
|
|
515
901
|
class: "IncodeSignatureButtonContainer",
|
|
516
|
-
children: /* @__PURE__ */
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
e.off();
|
|
523
|
-
try {
|
|
524
|
-
let t = await O();
|
|
525
|
-
if (!t) {
|
|
526
|
-
e.on();
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
_.submit(t);
|
|
530
|
-
} catch {
|
|
531
|
-
e.on();
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
},
|
|
535
|
-
children: m("signature.done")
|
|
902
|
+
children: /* @__PURE__ */ u(Button, {
|
|
903
|
+
variant: "primary",
|
|
904
|
+
disabled: !canContinue,
|
|
905
|
+
isLoading: isSubmitting,
|
|
906
|
+
onClick: handleContinue,
|
|
907
|
+
children: t("signature.done")
|
|
536
908
|
})
|
|
537
909
|
})]
|
|
538
910
|
});
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
911
|
+
};
|
|
912
|
+
var Signature = ({ config, onFinish, onError }) => /* @__PURE__ */ u(IncodeComponent, { children: config ? /* @__PURE__ */ u(SignatureContent, {
|
|
913
|
+
config,
|
|
914
|
+
onFinish,
|
|
915
|
+
onError
|
|
543
916
|
}) : null });
|
|
544
|
-
|
|
917
|
+
registerIncodeModuleElement(Signature, "incode-signature");
|
|
545
918
|
//#endregion
|
|
546
|
-
export {
|
|
919
|
+
export { Signature };
|