@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.
Files changed (253) hide show
  1. package/dist/ae-signature/ae-signature.es.js +15 -13
  2. package/dist/ae-signature/styles.css +3 -17
  3. package/dist/ae-signature/styles2.css +15 -5
  4. package/dist/aligndevicelottie-DY_bX_p8.js +12769 -0
  5. package/dist/antifraud/antifraud.es.js +23 -16
  6. package/dist/authentication/authentication.es.js +42 -27
  7. package/dist/autoFocusTitle-BzkUiELM.js +29 -0
  8. package/dist/{back-horizontal-hint-B8Brxh3U.js → back-horizontal-hint-D_8LptLm.js} +26 -26
  9. package/dist/back-tutorial-vb1MxlrT.js +14597 -0
  10. package/dist/{back-vertical-hint-BBo36dxn.js → back-vertical-hint-C1evxxq2.js} +27 -27
  11. package/dist/backdevicelottie-HypPqBz7.js +16690 -0
  12. package/dist/base.css +1258 -104
  13. package/dist/blurdevicelottie-CBXtBFiJ.js +15951 -0
  14. package/dist/bottomSheet-F1GJfQx_.js +39 -0
  15. package/dist/browser-ponyfill-CLLvZCVg.js +441 -0
  16. package/dist/button-CM_hgyIP.js +35 -0
  17. package/dist/checkbox-BoeLHKgp.js +96 -0
  18. package/dist/consent/consent.es.js +89 -73
  19. package/dist/consent/styles.css +35 -22
  20. package/dist/countrySelector-mSWyHSy4.js +60 -0
  21. package/dist/cpf-ocr/cpf-ocr.es.js +2 -0
  22. package/dist/cpfOcr-MtpRztkG.js +92 -0
  23. package/dist/cpfOcr-jJkYCfsX.js +2 -0
  24. package/dist/cross-document-data-match/cross-document-data-match.es.js +20 -16
  25. package/dist/curp-validation/curp-validation.es.js +247 -203
  26. package/dist/customFields-DXXt9HGM.js +140 -0
  27. package/dist/customWatchlist-DsW04UF6.js +36 -0
  28. package/dist/dateInputComposed-C_mh4XBg.js +69 -0
  29. package/dist/dateInputComposed-Cy6a7ymh.js +1 -0
  30. package/dist/defineProperty-mefzVtTv.js +39 -0
  31. package/dist/document-capture/document-capture.es.js +2 -0
  32. package/dist/document-capture/styles.css +2 -5
  33. package/dist/documentCapture-8ypBJehw.js +2 -0
  34. package/dist/documentCapture-BDV_921m.js +880 -0
  35. package/dist/dropdownComposed-CEWBSdGl.js +1 -0
  36. package/dist/dropdownComposed-_fgAlo_C.js +380 -0
  37. package/dist/dynamic-forms/styles.css +25 -13
  38. package/dist/dynamicForms-DyfnsS7E.js +352 -0
  39. package/dist/ekyb/ekyb.es.js +2 -2
  40. package/dist/ekyb/styles.css +2 -0
  41. package/dist/ekybModule-CIPGmCvD.js +279 -0
  42. package/dist/ekybModule-DFoYpheB.js +2 -0
  43. package/dist/ekyc/ekyc.es.js +2 -2
  44. package/dist/ekyc/styles.css +9 -7
  45. package/dist/ekycModule-BGzwgjl1.js +2 -0
  46. package/dist/ekycModule-BuTaC5ct.js +257 -0
  47. package/dist/electronic-signature/electronic-signature.es.js +2 -2
  48. package/dist/electronic-signature-B-Q7M0wK.js +430 -0
  49. package/dist/email/email.es.js +199 -66
  50. package/dist/emailInput-KZmhjOdZ.js +39 -0
  51. package/dist/errorIcon-DJRZpd8j.js +26 -0
  52. package/dist/expiredId-Q1t6aVpk.js +85 -0
  53. package/dist/extensibility-Cs3KQQdC.js +3070 -0
  54. package/dist/extensibility.es.js +26 -25
  55. package/dist/face-match/face-match.es.js +2 -2
  56. package/dist/face-match/styles.css +0 -4
  57. package/dist/faceMatch--RDHJe4t.js +343 -0
  58. package/dist/faceMatch-yEKPYaym.js +2 -0
  59. package/dist/field-comparison/field-comparison.es.js +2 -0
  60. package/dist/field-comparison/styles.css +16 -0
  61. package/dist/fieldComparison-CAF86bTC.js +88 -0
  62. package/dist/fieldComparison-D0an7T_g.js +2 -0
  63. package/dist/fiscal-qr/fiscal-qr.es.js +224 -0
  64. package/dist/fiscal-qr/styles.css +71 -0
  65. package/dist/{flip-animation-CgwRsEmK.js → flip-animation-BGRvygw9.js} +4221 -4221
  66. package/dist/flow/flow.es.js +619 -484
  67. package/dist/flow/styles.css +378 -418
  68. package/dist/{front-horizontal-hint-DGGGi8e1.js → front-horizontal-hint-Uf5bHCsd.js} +70 -70
  69. package/dist/{front-vertical-hint-CNr5mE6Q.js → front-vertical-hint-DdWNA45v.js} +81 -81
  70. package/dist/frontdevicelottie-CLqitJhG.js +17314 -0
  71. package/dist/geolocation/geolocation.es.js +486 -395
  72. package/dist/glaredevicelottie-BS04U6Fc.js +14478 -0
  73. package/dist/governmentValidation/governmentValidation.es.js +166 -93
  74. package/dist/governmentValidation/styles.css +0 -17
  75. package/dist/homeScreen-BZnIEDrV.js +264 -0
  76. package/dist/hooks-Da_yP_Dr.js +149 -0
  77. package/dist/i18n-CoCO2ZuN.js +2971 -0
  78. package/dist/icons-Dbs9ZfYM.js +360 -0
  79. package/dist/id/id.es.js +583 -414
  80. package/dist/id/styles.css +59 -43
  81. package/dist/id-laser-h-DX8UbVNH.js +467 -0
  82. package/dist/id-laser-v-DhnHdjlB.js +490 -0
  83. package/dist/id-tutorial-lj4iKtYT.js +13165 -0
  84. package/dist/id-verification/id-verification.es.js +21 -17
  85. package/dist/idOcr-CjGbb4dB.js +123 -0
  86. package/dist/identity-reuse/identity-reuse.es.js +311 -182
  87. package/dist/identity-reuse/styles.css +134 -80
  88. package/dist/incode-logo-57XFniXU.js +4 -0
  89. package/dist/incodeComponent-wfnHlnXx.js +63 -0
  90. package/dist/incodeModule-BUDoTwT9.js +13 -0
  91. package/dist/index.es.js +17 -13
  92. package/dist/inputComposed-BEn7_nZd.js +1 -0
  93. package/dist/inputComposed-CQ4AsvZg.js +99 -0
  94. package/dist/loadingIcon-B0ysgiNq.js +148 -0
  95. package/dist/lottie_light-Dp9Bz3mf.js +9031 -0
  96. package/dist/mandatoryConsent-r0PQHmv-.js +107 -0
  97. package/dist/modal-nTSaG7nB.js +139 -0
  98. package/dist/modal.hooks-D2xhIuHA.js +195 -0
  99. package/dist/numberedStep-CEtwZqLp.js +13 -0
  100. package/dist/optionAccessibleLabel-CnA-mNAU.js +202 -0
  101. package/dist/otpInput-_JmtVwa0.js +195 -0
  102. package/dist/page-DxGQj7Gk.js +71 -0
  103. package/dist/{passport-horizontal-hint-Bgquwtac.js → passport-horizontal-hint-Bbm2mvSn.js} +55 -55
  104. package/dist/{passport-tutorial-DwRwtPVX.js → passport-tutorial-zT1ZoA-D.js} +7096 -7084
  105. package/dist/{passport-vertical-hint-BT1D5BrW.js → passport-vertical-hint-DJbCtBiM.js} +49 -49
  106. package/dist/pdf-BZA70WbM.js +22398 -0
  107. package/dist/pdfViewer-BK-yVIve.js +114 -0
  108. package/dist/phone/phone.es.js +214 -70
  109. package/dist/phoneInputComposed-DjNdsmPE.js +12142 -0
  110. package/dist/processing-BM-wT-1W.js +8 -0
  111. package/dist/qe-signature/qe-signature.es.js +15 -13
  112. package/dist/radioGroupComposed-BNuaopVr.js +215 -0
  113. package/dist/redirect-to-mobile/redirect-to-mobile.es.js +2774 -0
  114. package/dist/redirect-to-mobile/styles.css +19 -269
  115. package/dist/registerIncodeElement-77NGCDsy.js +11 -0
  116. package/dist/requiredLabelHint-DEadtiwx.js +17 -0
  117. package/dist/richText-Cf9aMOCk.js +3153 -0
  118. package/dist/rolldown-runtime--E5BIlTp.js +33 -0
  119. package/dist/selfie/selfie.es.js +54 -37
  120. package/dist/selfie/styles.css +0 -4
  121. package/dist/selfieTutorial-CtruLyO2.js +2689 -0
  122. package/dist/signature/signature.es.js +778 -405
  123. package/dist/snackbar-CxepGC3e.js +16 -0
  124. package/dist/spinner-B6RxGFrI.js +1 -0
  125. package/dist/spinner-D8a_2LvW.js +42 -0
  126. package/dist/statusPage-DMYPUwRZ.js +28 -0
  127. package/dist/successIcon-BAyDPT7I.js +30 -0
  128. package/dist/tabs-C8npVBbk.js +103 -0
  129. package/dist/themes/dark.css +5 -0
  130. package/dist/themes/light.css +4 -0
  131. package/dist/transitionSpinner-DRRz-NV8.js +26 -0
  132. package/dist/{tutorial-9vHAHvMK.js → tutorial-D1qaY2Tm.js} +1105 -856
  133. package/dist/types/ae-signature.d.ts +4 -1
  134. package/dist/types/antifraud.d.ts +9 -3
  135. package/dist/types/authentication.d.ts +4 -1
  136. package/dist/types/consent.d.ts +4 -1
  137. package/dist/types/cpf-ocr.d.ts +12 -0
  138. package/dist/types/cross-document-data-match.d.ts +4 -1
  139. package/dist/types/curp-validation.d.ts +9 -3
  140. package/dist/types/document-capture.d.ts +37 -0
  141. package/dist/types/ekyb.d.ts +4 -1
  142. package/dist/types/ekyc.d.ts +4 -1
  143. package/dist/types/electronic-signature.d.ts +4 -1
  144. package/dist/types/email.d.ts +4 -1
  145. package/dist/types/extensibility.d.ts +40 -15
  146. package/dist/types/face-match.d.ts +4 -1
  147. package/dist/types/field-comparison.d.ts +38 -0
  148. package/dist/types/fiscal-qr.d.ts +43 -0
  149. package/dist/types/flow.d.ts +5 -2
  150. package/dist/types/geolocation.d.ts +4 -1
  151. package/dist/types/governmentValidation.d.ts +4 -1
  152. package/dist/types/id-verification.d.ts +4 -1
  153. package/dist/types/id.d.ts +4 -1
  154. package/dist/types/identity-reuse.d.ts +4 -1
  155. package/dist/types/index.d.ts +26 -2
  156. package/dist/types/phone.d.ts +4 -1
  157. package/dist/types/qe-signature.d.ts +4 -1
  158. package/dist/types/redirect-to-mobile.d.ts +17 -0
  159. package/dist/types/selfie.d.ts +4 -1
  160. package/dist/types/signature.d.ts +4 -1
  161. package/dist/types/watchlist.d.ts +4 -1
  162. package/dist/types/workflow.d.ts +55 -11
  163. package/dist/typography-YLgHHuao.js +45 -0
  164. package/dist/uiConfig-D2_wawvr.js +25 -0
  165. package/dist/useModuleLoader-CeJ2jL25.js +672 -0
  166. package/dist/vendor-preact-DThS2ZQ_.js +955 -0
  167. package/dist/verificationResult-Do5SpZ6X.js +64 -0
  168. package/dist/verifiedByIncode-DjXOdCml.js +103 -0
  169. package/dist/watchlist/watchlist.es.js +31 -28
  170. package/dist/watchlistForBusiness-BFFXC9d-.js +80 -0
  171. package/dist/workflow/styles.css +449 -427
  172. package/dist/workflow/workflow.es.js +268 -182
  173. package/package.json +32 -10
  174. package/dist/aligndevicelottie-DoV8xKjh.js +0 -12757
  175. package/dist/autoFocusTitle-QexamZ4i.js +0 -16
  176. package/dist/back-tutorial-1NOQobGO.js +0 -14585
  177. package/dist/backdevicelottie-C_ceuqY7.js +0 -16678
  178. package/dist/blurdevicelottie-UO14Y0WC.js +0 -15939
  179. package/dist/bottomSheet-DE_8TFEC.js +0 -31
  180. package/dist/browser-ponyfill-jOkuz57z.js +0 -299
  181. package/dist/button-DcCUEn2n.js +0 -24
  182. package/dist/checkbox-Cl57ltq_.js +0 -85
  183. package/dist/countrySelector-CE-JgIsv.js +0 -58
  184. package/dist/cpfOcr-D_tbwbvh.js +0 -78
  185. package/dist/customFields-CW38fQUv.js +0 -127
  186. package/dist/customWatchlist-D9_yjEQd.js +0 -33
  187. package/dist/dateInputComposed-BpAGsjN6.js +0 -55
  188. package/dist/dateInputComposed-DU3o6PAV.js +0 -1
  189. package/dist/defineProperty-Dh8nSJpJ.js +0 -39
  190. package/dist/documentCapture-xX-JT7ZY.js +0 -763
  191. package/dist/dropdownComposed-DFRBG22E.js +0 -284
  192. package/dist/dropdownComposed-DwTzc2YU.js +0 -1
  193. package/dist/dynamicForms-CJP1Ia6Q.js +0 -262
  194. package/dist/ekybModule-BSs7mndb.js +0 -280
  195. package/dist/ekybModule-D9M3E2Gm.js +0 -2
  196. package/dist/ekycModule-CU9pt5YN.js +0 -246
  197. package/dist/ekycModule-CZw9cLno.js +0 -2
  198. package/dist/electronic-signature-COYXjGdd.js +0 -410
  199. package/dist/emailInput-DppGf9pv.js +0 -37
  200. package/dist/expiredId-BnmzE8T3.js +0 -70
  201. package/dist/extensibility-CzEJfRwo.js +0 -2586
  202. package/dist/faceMatch-B8j0g0Yo.js +0 -2
  203. package/dist/faceMatch-BV8UD7tj.js +0 -201
  204. package/dist/frontdevicelottie-Bu6f9fDE.js +0 -17302
  205. package/dist/glaredevicelottie-B10axYs_.js +0 -14466
  206. package/dist/homeScreen-DnP1jw9A.js +0 -227
  207. package/dist/hooks-BVnGysT7.js +0 -80
  208. package/dist/i18n-9s4OSqwi.js +0 -2010
  209. package/dist/icons-Cc7zwchP.js +0 -310
  210. package/dist/id-laser-h-mBAzHVOK.js +0 -467
  211. package/dist/id-laser-v-CrFg4bcJ.js +0 -483
  212. package/dist/id-tutorial-BCr42Pnn.js +0 -13153
  213. package/dist/idOcr-CCjfWQvH.js +0 -94
  214. package/dist/incode-logo-DX016usY.js +0 -4
  215. package/dist/incodeComponent-C1o4M0ZK.js +0 -50
  216. package/dist/incodeModule-BqCjVgEI.js +0 -18
  217. package/dist/inputComposed-APSw8C7o.js +0 -89
  218. package/dist/inputComposed-XYrarFxS.js +0 -1
  219. package/dist/loadingIcon-BN5YRQUb.js +0 -104
  220. package/dist/mandatoryConsent-DssKMC3v.js +0 -100
  221. package/dist/modal-NMxsQHAO.js +0 -135
  222. package/dist/modal.hooks-CAjcIFZK.js +0 -126
  223. package/dist/numberedStep-CT-alrK5.js +0 -11
  224. package/dist/optionAccessibleLabel-CzEeX3Q4.js +0 -140
  225. package/dist/otpInput-DqRA_egd.js +0 -145
  226. package/dist/page-C1yT4DLb.js +0 -69
  227. package/dist/pdf-BurGZ08w.js +0 -14967
  228. package/dist/pdfViewer-BGBNL1Ea.js +0 -63
  229. package/dist/phoneInputComposed-bvWhGLFZ.js +0 -11206
  230. package/dist/processing-G_y3o32b.js +0 -6
  231. package/dist/radioGroupComposed-BbmvxmD2.js +0 -177
  232. package/dist/redirectToMobile-C3k1gloW.js +0 -1514
  233. package/dist/requiredLabelHint-BLwgqozE.js +0 -13
  234. package/dist/richText-DbJ5sl2n.js +0 -1973
  235. package/dist/rolldown-runtime-CYMK-g2i.js +0 -20
  236. package/dist/selfieTutorial-BgrlUMXP.js +0 -2677
  237. package/dist/snackbar-BDp8x7Cv.js +0 -14
  238. package/dist/spinner-B4dcie2T.js +0 -1
  239. package/dist/spinner-CKnjVHxw.js +0 -39
  240. package/dist/statusPage-CUI7ApcU.js +0 -28
  241. package/dist/successIcon-DbILeIz_.js +0 -28
  242. package/dist/tabs-DaPyP71c.js +0 -78
  243. package/dist/transitionSpinner-PIEPU2Vx.js +0 -17
  244. package/dist/types/cpf-ocr/styles.d.ts +0 -1
  245. package/dist/types/document-capture/styles.d.ts +0 -1
  246. package/dist/types/redirect-to-mobile/styles.d.ts +0 -1
  247. package/dist/typography-CxjaknHN.js +0 -28
  248. package/dist/uiConfig-CwpQ-IM6.js +0 -20
  249. package/dist/useModuleLoader-BFiVA41N.js +0 -432
  250. package/dist/vendor-preact-D6SntenC.js +0 -958
  251. package/dist/verificationResult-BrVbUJ4U.js +0 -97
  252. package/dist/verifiedByIncode-ChZBpqNy.js +0 -101
  253. package/dist/watchlistForBusiness-BcSNtHCV.js +0 -77
@@ -1,546 +1,919 @@
1
- import { n as e } from "../i18n-9s4OSqwi.js";
2
- import { _ as t, a as n, h as r, l as i, p as a, u as o, v as s } from "../vendor-preact-D6SntenC.js";
3
- import { o as c } from "../hooks-BVnGysT7.js";
4
- import { t as l } from "../incodeComponent-C1o4M0ZK.js";
5
- import { r as u } from "../loadingIcon-BN5YRQUb.js";
6
- import { t as d } from "../page-C1yT4DLb.js";
7
- import "../extensibility-CzEJfRwo.js";
8
- import { t as f } from "../button-DcCUEn2n.js";
9
- import { t as p } from "../verificationResult-BrVbUJ4U.js";
10
- import { t as m } from "../incodeModule-BqCjVgEI.js";
11
- import { t as h } from "../defineProperty-Dh8nSJpJ.js";
12
- import { createSignatureManager as g } from "@incodetech/core/signature";
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
- var _ = class {
15
- constructor(e, t, n, r) {
16
- if (h(this, "x", void 0), h(this, "y", void 0), h(this, "pressure", void 0), h(this, "time", void 0), isNaN(e) || isNaN(t)) throw Error(`Point is invalid: (${e}, ${t})`);
17
- this.x = +e, this.y = +t, this.pressure = n || 0, this.time = r || Date.now();
18
- }
19
- distanceTo(e) {
20
- return Math.sqrt((this.x - e.x) ** 2 + (this.y - e.y) ** 2);
21
- }
22
- equals(e) {
23
- return this.x === e.x && this.y === e.y && this.pressure === e.pressure && this.time === e.time;
24
- }
25
- velocityFrom(e) {
26
- return this.time === e.time ? 0 : this.distanceTo(e) / (this.time - e.time);
27
- }
28
- }, v = class e {
29
- constructor(e, t, n, r, i, a) {
30
- this.startPoint = e, this.control2 = t, this.control1 = n, this.endPoint = r, this.startWidth = i, this.endWidth = a;
31
- }
32
- static fromPoints(t, n) {
33
- let r = this.calculateControlPoints(t[0], t[1], t[2]).c2, i = this.calculateControlPoints(t[1], t[2], t[3]).c1;
34
- return new e(t[1], r, i, t[2], n.start, n.end);
35
- }
36
- static calculateControlPoints(e, t, n) {
37
- let r = e.x - t.x, i = e.y - t.y, a = t.x - n.x, o = t.y - n.y, s = {
38
- x: (e.x + t.x) / 2,
39
- y: (e.y + t.y) / 2
40
- }, c = {
41
- x: (t.x + n.x) / 2,
42
- y: (t.y + n.y) / 2
43
- }, l = Math.sqrt(r * r + i * i), u = Math.sqrt(a * a + o * o), d = s.x - c.x, f = s.y - c.y, p = l + u == 0 ? 0 : u / (l + u), m = {
44
- x: c.x + d * p,
45
- y: c.y + f * p
46
- }, h = t.x - m.x, g = t.y - m.y;
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 _(s.x + h, s.y + g),
49
- c2: new _(c.x + h, c.y + g)
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
- let e = 0, t, n;
54
- for (let r = 0; r <= 10; r += 1) {
55
- 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);
56
- if (r > 0) {
57
- let r = a - t, i = o - n;
58
- e += Math.sqrt(r * r + i * i);
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
- t = a, n = o;
97
+ px = cx;
98
+ py = cy;
61
99
  }
62
- return e;
100
+ return length;
63
101
  }
64
- point(e, t, n, r, i) {
65
- 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;
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
- }, y = class {
105
+ };
106
+ var SignatureEventTarget = class {
68
107
  constructor() {
69
- h(this, "_et", void 0);
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(e, t, n) {
77
- this._et.addEventListener(e, t, n);
115
+ addEventListener(type, listener, options) {
116
+ this._et.addEventListener(type, listener, options);
78
117
  }
79
- dispatchEvent(e) {
80
- return this._et.dispatchEvent(e);
118
+ dispatchEvent(event) {
119
+ return this._et.dispatchEvent(event);
81
120
  }
82
- removeEventListener(e, t, n) {
83
- this._et.removeEventListener(e, t, n);
121
+ removeEventListener(type, callback, options) {
122
+ this._et.removeEventListener(type, callback, options);
84
123
  }
85
124
  };
86
- function b(e, t = 250) {
87
- let n = 0, r = null, i, a, o, s = () => {
88
- n = Date.now(), r = null, i = e.apply(a, o), r || (a = null, o = []);
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(...c) {
91
- let l = Date.now(), u = t - (l - n);
92
- 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;
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 x = class e extends y {
96
- constructor(t, n = {}) {
97
- super(), h(this, "dotSize", void 0), h(this, "minWidth", void 0), h(this, "maxWidth", void 0), h(this, "penColor", void 0), h(this, "minDistance", void 0), h(this, "velocityFilterWeight", void 0), h(this, "compositeOperation", void 0), h(this, "backgroundColor", void 0), h(this, "throttle", void 0), h(this, "canvasContextOptions", void 0), h(this, "_ctx", void 0), h(this, "_drawingStroke", !1), h(this, "_isEmpty", !0), h(this, "_dataUrl", void 0), h(this, "_dataUrlOptions", void 0), h(this, "_lastPoints", []), h(this, "_data", []), h(this, "_lastVelocity", 0), h(this, "_lastWidth", 0), h(this, "_strokeMoveUpdate", void 0), h(this, "_strokePointerId", void 0), 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 ? b(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();
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
- let { _ctx: e, canvas: t } = this;
101
- 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;
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
- let e = this._data, t = this._dataUrl, n = this._dataUrlOptions;
105
- this.clear(), t && this.fromDataURL(t, n), this.fromData(e, { clear: !1 });
106
- }
107
- fromDataURL(e, t = {}) {
108
- return new Promise((n, r) => {
109
- 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;
110
- this._reset(this._getPointGroupOptions()), i.onload = () => {
111
- this._ctx.drawImage(i, c, l, o, s), n();
112
- }, i.onerror = (e) => {
113
- r(e);
114
- }, i.crossOrigin = "anonymous", i.src = e, this._isEmpty = !1, this._dataUrl = e, this._dataUrlOptions = { ...t };
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(e = "image/png", t) {
118
- switch (e) {
119
- case "image/svg+xml": return typeof t != "object" && (t = void 0), `data:image/svg+xml;base64,${btoa(this.toSVG(t))}`;
120
- default: return typeof t != "number" && (t = void 0), this.canvas.toDataURL(e, t);
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", this.canvas.style.msTouchAction = "none", this.canvas.style.userSelect = "none", this.canvas.style.webkitUserSelect = "none";
125
- let e = /Macintosh/.test(navigator.userAgent) && "ontouchstart" in document;
126
- window.PointerEvent && !e ? this._handlePointerEvents() : (this._handleMouseEvents(), "ontouchstart" in window && this._handleTouchEvents());
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", 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();
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
- let e = window.document === this.canvas.ownerDocument ? window : this.canvas.ownerDocument.defaultView ?? this.canvas.ownerDocument;
287
+ const canvasWindow = window.document === this.canvas.ownerDocument ? window : this.canvas.ownerDocument.defaultView ?? this.canvas.ownerDocument;
133
288
  return {
134
- addEventListener: e.addEventListener.bind(e),
135
- removeEventListener: e.removeEventListener.bind(e)
289
+ addEventListener: canvasWindow.addEventListener.bind(canvasWindow),
290
+ removeEventListener: canvasWindow.removeEventListener.bind(canvasWindow)
136
291
  };
137
292
  }
138
293
  _removeMoveUpEventListeners() {
139
- let { removeEventListener: e } = this._getListenerFunctions();
140
- 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);
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(e, { clear: t = !0 } = {}) {
146
- t && this.clear(), this._fromData(e, this._drawCurve.bind(this), this._drawDot.bind(this)), this._data = this._data.concat(e);
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(e, t) {
152
- return t ? e.buttons === 1 : (e.buttons & 1) == 1;
315
+ _isLeftButtonPressed(event, only) {
316
+ if (only) return event.buttons === 1;
317
+ return (event.buttons & 1) === 1;
153
318
  }
154
- _pointerEventToSignatureEvent(e) {
319
+ _pointerEventToSignatureEvent(event) {
155
320
  return {
156
- event: e,
157
- type: e.type,
158
- x: e.clientX,
159
- y: e.clientY,
160
- pressure: "pressure" in e ? e.pressure : 0
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(e) {
164
- let t = e.changedTouches[0];
328
+ _touchEventToSignatureEvent(event) {
329
+ const touch = event.changedTouches[0];
165
330
  return {
166
- event: e,
167
- type: e.type,
168
- x: t.clientX,
169
- y: t.clientY,
170
- pressure: t.force
331
+ event,
332
+ type: event.type,
333
+ x: touch.clientX,
334
+ y: touch.clientY,
335
+ pressure: touch.force
171
336
  };
172
337
  }
173
- _handleMouseDown(e) {
174
- !this._isLeftButtonPressed(e, !0) || this._drawingStroke || this._strokeBegin(this._pointerEventToSignatureEvent(e));
338
+ _handleMouseDown(event) {
339
+ if (!this._isLeftButtonPressed(event, true) || this._drawingStroke) return;
340
+ this._strokeBegin(this._pointerEventToSignatureEvent(event));
175
341
  }
176
- _handleMouseMove(e) {
177
- if (!this._isLeftButtonPressed(e, !0) || !this._drawingStroke) {
178
- this._strokeEnd(this._pointerEventToSignatureEvent(e), !1);
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(e));
182
- }
183
- _handleMouseUp(e) {
184
- this._isLeftButtonPressed(e) || this._strokeEnd(this._pointerEventToSignatureEvent(e));
185
- }
186
- _handleTouchStart(e) {
187
- e.targetTouches.length !== 1 || this._drawingStroke || (e.cancelable && e.preventDefault(), this._strokeBegin(this._touchEventToSignatureEvent(e)));
188
- }
189
- _handleTouchMove(e) {
190
- if (e.targetTouches.length === 1) {
191
- if (e.cancelable && e.preventDefault(), !this._drawingStroke) {
192
- this._strokeEnd(this._touchEventToSignatureEvent(e), !1);
193
- return;
194
- }
195
- this._strokeMoveUpdate(this._touchEventToSignatureEvent(e));
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
- _handleTouchEnd(e) {
199
- e.targetTouches.length === 0 && (e.cancelable && e.preventDefault(), this._strokeEnd(this._touchEventToSignatureEvent(e)));
200
- }
201
- _handlePointerCancel(e) {
202
- this._allowPointerId(e) && (e.preventDefault(), this._strokeEnd(this._pointerEventToSignatureEvent(e), !1));
203
- }
204
- _handleTouchCancel(e) {
205
- e.cancelable && e.preventDefault(), this._strokeEnd(this._touchEventToSignatureEvent(e), !1);
206
- }
207
- _getPointerId(e) {
208
- return e.persistentDeviceId || e.pointerId;
209
- }
210
- _allowPointerId(e, t = !1) {
211
- return this._strokePointerId === void 0 ? t : this._getPointerId(e) === this._strokePointerId;
212
- }
213
- _handlePointerDown(e) {
214
- this._drawingStroke || !this._isLeftButtonPressed(e) || !this._allowPointerId(e, !0) || (this._strokePointerId = this._getPointerId(e), e.preventDefault(), this._strokeBegin(this._pointerEventToSignatureEvent(e)));
215
- }
216
- _handlePointerMove(e) {
217
- if (this._allowPointerId(e)) {
218
- if (!this._isLeftButtonPressed(e, !0) || !this._drawingStroke) {
219
- this._strokeEnd(this._pointerEventToSignatureEvent(e), !1);
220
- return;
221
- }
222
- e.preventDefault(), this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e));
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(e) {
226
- this._isLeftButtonPressed(e) || !this._allowPointerId(e) || (e.preventDefault(), this._strokeEnd(this._pointerEventToSignatureEvent(e)));
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(e) {
408
+ _getPointGroupOptions(group) {
229
409
  return {
230
- penColor: e && "penColor" in e ? e.penColor : this.penColor,
231
- dotSize: e && "dotSize" in e ? e.dotSize : this.dotSize,
232
- minWidth: e && "minWidth" in e ? e.minWidth : this.minWidth,
233
- maxWidth: e && "maxWidth" in e ? e.maxWidth : this.maxWidth,
234
- velocityFilterWeight: e && "velocityFilterWeight" in e ? e.velocityFilterWeight : this.velocityFilterWeight,
235
- compositeOperation: e && "compositeOperation" in e ? e.compositeOperation : this.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(e) {
418
+ _strokeBegin(event) {
239
419
  if (!this.dispatchEvent(new CustomEvent("beginStroke", {
240
- detail: e,
241
- cancelable: !0
420
+ detail: event,
421
+ cancelable: true
242
422
  }))) return;
243
- let { addEventListener: t } = this._getListenerFunctions();
244
- switch (e.event.type) {
423
+ const { addEventListener } = this._getListenerFunctions();
424
+ switch (event.event.type) {
245
425
  case "mousedown":
246
- t("mousemove", this._handleMouseMove, { passive: !1 }), t("mouseup", this._handleMouseUp, { passive: !1 });
426
+ addEventListener("mousemove", this._handleMouseMove, { passive: false });
427
+ addEventListener("mouseup", this._handleMouseUp, { passive: false });
247
428
  break;
248
429
  case "touchstart":
249
- t("touchmove", this._handleTouchMove, { passive: !1 }), t("touchend", this._handleTouchEnd, { passive: !1 }), t("touchcancel", this._handleTouchCancel, { passive: !1 });
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
- t("pointermove", this._handlePointerMove, { passive: !1 }), t("pointerup", this._handlePointerUp, { passive: !1 }), t("pointercancel", this._handlePointerCancel, { passive: !1 });
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 = !0;
257
- let n = this._getPointGroupOptions(), r = {
258
- ...n,
441
+ this._drawingStroke = true;
442
+ const pointGroupOptions = this._getPointGroupOptions();
443
+ const newPointGroup = {
444
+ ...pointGroupOptions,
259
445
  points: []
260
446
  };
261
- this._data.push(r), this._reset(n), this._strokeUpdate(e);
447
+ this._data.push(newPointGroup);
448
+ this._reset(pointGroupOptions);
449
+ this._strokeUpdate(event);
262
450
  }
263
- _strokeUpdate(e) {
451
+ _strokeUpdate(event) {
264
452
  if (!this._drawingStroke) return;
265
453
  if (this._data.length === 0) {
266
- this._strokeBegin(e);
454
+ this._strokeBegin(event);
267
455
  return;
268
456
  }
269
- this.dispatchEvent(new CustomEvent("beforeUpdateStroke", { detail: e }));
270
- 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);
271
- if (!i || !(i && a)) {
272
- let e = this._addPoint(t, o);
273
- i ? e && this._drawCurve(e, o) : this._drawDot(t, o), r.push({
274
- time: t.time,
275
- x: t.x,
276
- y: t.y,
277
- pressure: t.pressure
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: e }));
475
+ this.dispatchEvent(new CustomEvent("afterUpdateStroke", { detail: event }));
281
476
  }
282
- _strokeEnd(e, t = !0) {
283
- this._removeMoveUpEventListeners(), this._drawingStroke && (t && this._strokeUpdate(e), this._drawingStroke = !1, this._strokePointerId = void 0, this.dispatchEvent(new CustomEvent("endStroke", { detail: e })));
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 = !1, this.canvas.addEventListener("pointerdown", this._handlePointerDown, { passive: !1 });
486
+ this._drawingStroke = false;
487
+ this.canvas.addEventListener("pointerdown", this._handlePointerDown, { passive: false });
287
488
  }
288
489
  _handleMouseEvents() {
289
- this._drawingStroke = !1, this.canvas.addEventListener("mousedown", this._handleMouseDown, { passive: !1 });
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: !1 });
293
- }
294
- _reset(e) {
295
- this._lastPoints = [], this._lastVelocity = 0, this._lastWidth = (e.minWidth + e.maxWidth) / 2, this._ctx.fillStyle = e.penColor, this._ctx.globalCompositeOperation = e.compositeOperation;
296
- }
297
- _createPoint(e, t, n) {
298
- let r = this.canvas.getBoundingClientRect();
299
- return new _(e - r.left, t - r.top, n, (/* @__PURE__ */ new Date()).getTime());
300
- }
301
- _addPoint(e, t) {
302
- let { _lastPoints: n } = this;
303
- if (n.push(e), n.length > 2) {
304
- n.length === 3 && n.unshift(n[0]);
305
- let e = this._calculateCurveWidths(n[1], n[2], t), r = v.fromPoints(n, e);
306
- return n.shift(), r;
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(e, t, n) {
311
- let r = n.velocityFilterWeight * t.velocityFrom(e) + (1 - n.velocityFilterWeight) * this._lastVelocity, i = this._strokeWidth(r, n), a = {
312
- end: i,
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
- return this._lastVelocity = r, this._lastWidth = i, a;
316
- }
317
- _strokeWidth(e, t) {
318
- return Math.max(t.maxWidth / (e + 1), t.minWidth);
319
- }
320
- _drawCurveSegment(e, t, n) {
321
- let r = this._ctx;
322
- r.moveTo(e, t), r.arc(e, t, n, 0, 2 * Math.PI, !1), this._isEmpty = !1;
323
- }
324
- _drawCurve(e, t) {
325
- let n = this._ctx, r = e.endWidth - e.startWidth, i = Math.ceil(e.length()) * 2;
326
- n.beginPath(), n.fillStyle = t.penColor;
327
- for (let n = 0; n < i; n += 1) {
328
- let a = n / i, o = a * a, s = o * a, c = 1 - a, l = c * c, u = l * c, d = u * e.startPoint.x;
329
- d += 3 * l * a * e.control1.x, d += 3 * c * o * e.control2.x, d += s * e.endPoint.x;
330
- let f = u * e.startPoint.y;
331
- f += 3 * l * a * e.control1.y, f += 3 * c * o * e.control2.y, f += s * e.endPoint.y;
332
- let p = Math.min(e.startWidth + s * r, t.maxWidth);
333
- this._drawCurveSegment(d, f, p);
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
- n.closePath(), n.fill();
336
- }
337
- _drawDot(e, t) {
338
- let n = this._ctx, r = t.dotSize > 0 ? t.dotSize : (t.minWidth + t.maxWidth) / 2;
339
- n.beginPath(), this._drawCurveSegment(e.x, e.y, r), n.closePath(), n.fillStyle = t.penColor, n.fill();
340
- }
341
- _fromData(e, t, n) {
342
- for (let r of e) {
343
- let { points: e } = r, i = this._getPointGroupOptions(r);
344
- if (e.length > 1) for (let n = 0; n < e.length; n += 1) {
345
- let r = e[n], a = new _(r.x, r.y, r.pressure, r.time);
346
- n === 0 && this._reset(i);
347
- let o = this._addPoint(a, i);
348
- o && t(o, i);
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: e = !1, includeDataUrl: t = !1 } = {}) {
354
- 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");
355
- 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) {
356
- let e = document.createElement("rect");
357
- e.setAttribute("width", "100%"), e.setAttribute("height", "100%"), e.setAttribute("fill", this.backgroundColor), o.appendChild(e);
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 (t && this._dataUrl) {
360
- 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");
361
- 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);
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
- return this._fromData(n, (e, { penColor: t }) => {
364
- let n = document.createElement("path");
365
- if (!isNaN(e.control1.x) && !isNaN(e.control1.y) && !isNaN(e.control2.x) && !isNaN(e.control2.y)) {
366
- 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)}`;
367
- 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);
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
- }, (e, { penColor: t, dotSize: n, minWidth: r, maxWidth: i }) => {
370
- let a = document.createElement("circle"), s = n > 0 ? n : (r + i) / 2;
371
- a.setAttribute("r", s.toString()), a.setAttribute("cx", e.x.toString()), a.setAttribute("cy", e.y.toString()), a.setAttribute("fill", t), o.appendChild(a);
372
- }), o.outerHTML;
373
- }
374
- }, S = (e) => {
375
- if (typeof document > "u") return null;
376
- let t = document.createElement("div");
377
- t.style.color = e, t.style.position = "absolute", t.style.visibility = "hidden", document.body.appendChild(t);
378
- let n = getComputedStyle(t).color;
379
- if (document.body.removeChild(t), !n || n === "transparent") return null;
380
- let r = n.match(/\d+/g);
381
- if (r && r.length >= 3) {
382
- let e = Number.parseInt(r[0], 10), t = Number.parseInt(r[1], 10), n = Number.parseInt(r[2], 10), i = (e) => {
383
- let t = e.toString(16);
384
- return t.length === 1 ? `0${t}` : t;
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 `#${i(e)}${i(t)}${i(n)}`;
671
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
387
672
  }
388
673
  return null;
389
- }, C = "var(--icon-neutral-800)", w = "#ffffff", T = (e) => {
390
- let t = document.createElement("canvas");
391
- t.width = e.width, t.height = e.height;
392
- let n = t.getContext("2d");
393
- if (!n) throw Error("Canvas 2D context is not available");
394
- return n.fillStyle = w, n.fillRect(0, 0, t.width, t.height), n.drawImage(e, 0, 0), t;
395
- }, E = (e, t, n) => new Promise((r, i) => {
396
- e.toBlob((e) => {
397
- e ? r(e) : i(/* @__PURE__ */ Error("Canvas toBlob() returned null"));
398
- }, t, t === "image/jpeg" || t === "image/webp" ? n : void 0);
399
- }), D = n(({ onBeginStroke: e, hasDrawing: n, placeholder: a, customPenColor: c, customPenStrokeWidth: l, customBackgroundColor: u, customBorderColor: d }, f) => {
400
- let p = i(null), m = i(null), h = i(null), g = i(e);
401
- g.current = e;
402
- let _ = r(() => {
403
- let e = p.current, t = m.current, n = h.current;
404
- if (!e || !t || !n) return;
405
- let r = Math.max(window.devicePixelRatio || 1, 1), i = t.getContext("2d"), { width: a, height: o } = e.getBoundingClientRect();
406
- if (a === 0 || o === 0 || !i) return;
407
- let s = n.isEmpty() ? null : n.toData();
408
- t.width = Math.floor(a * r), t.height = Math.floor(o * r), i.setTransform(r, 0, 0, r, 0, 0), s ? n.fromData(s, { clear: !0 }) : n.clear();
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
- return o(f, () => ({
721
+ F(ref, () => ({
411
722
  clear: () => {
412
- h.current?.clear();
723
+ signaturePadRef.current?.clear();
413
724
  },
414
- isEmpty: () => h.current?.isEmpty() ?? !0,
415
- toDataURL: (e = "image/png", t) => h.current?.toDataURL(e, t) ?? "",
416
- getCanvas: () => m.current,
417
- getSignaturePad: () => h.current,
418
- on: () => h.current?.on(),
419
- off: () => h.current?.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
- let e = m.current;
422
- return e ? T(e) : null;
732
+ const canvas = canvasRef.current;
733
+ if (!canvas) return null;
734
+ return copyCanvasWithWhiteBackground(canvas);
423
735
  },
424
- getBlob: (e = m.current ?? void 0, t = "image/jpeg", n = .92) => e ? E(e, t, n) : Promise.reject(/* @__PURE__ */ Error("No canvas available for getBlob"))
425
- }), []), t(() => {
426
- let e = p.current, t = m.current;
427
- if (!e || !t) return;
428
- let n = null, r = () => {
429
- n === null && (n = requestAnimationFrame(() => {
430
- n = null, _();
431
- }));
432
- }, i = c ?? S(C), a = new x(t, {
433
- ...i ? { penColor: i } : {},
434
- ...l ? { maxWidth: l } : {}
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
- h.current = a;
437
- let o = () => g.current?.();
438
- a.addEventListener("beginStroke", o), _();
439
- let s = new ResizeObserver(() => {
440
- r();
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
- return s.observe(e), () => {
443
- n !== null && cancelAnimationFrame(n), s.disconnect(), a.removeEventListener("beginStroke", o), a.off(), h.current = null;
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
- c,
448
- l
449
- ]), /* @__PURE__ */ s("div", {
774
+ resizeSignaturePad,
775
+ customPenColor,
776
+ customPenStrokeWidth
777
+ ]);
778
+ return /* @__PURE__ */ u("div", {
450
779
  class: "SignatureCanvasContainer",
451
- style: u || d ? {
452
- ...u ? { backgroundColor: u } : {},
453
- ...d ? { borderColor: d } : {}
780
+ style: customBackgroundColor || customBorderColor ? {
781
+ ...customBackgroundColor ? { backgroundColor: customBackgroundColor } : {},
782
+ ...customBorderColor ? { borderColor: customBorderColor } : {}
454
783
  } : void 0,
455
- ref: p,
456
- children: [/* @__PURE__ */ s("canvas", {
784
+ ref: containerRef,
785
+ children: [/* @__PURE__ */ u("canvas", {
457
786
  class: "SignatureCanvas",
458
- ref: m,
459
- "aria-label": a
460
- }), !n && /* @__PURE__ */ s("p", {
787
+ ref: canvasRef,
788
+ role: "img",
789
+ "aria-label": ariaLabel ?? placeholder
790
+ }), !hasDrawing && /* @__PURE__ */ u("p", {
461
791
  class: "SignatureCanvasPlaceholder",
462
- children: a
792
+ "aria-hidden": "true",
793
+ children: placeholder
463
794
  })]
464
795
  });
465
796
  });
466
- D.displayName = "SignatureCanvas";
797
+ SignatureCanvas.displayName = "SignatureCanvas";
467
798
  //#endregion
468
799
  //#region src/modules/signature/signature.tsx
469
- var O = ({ config: n, onFinish: o, onError: l }) => {
470
- let { t: m } = e(), [h, _] = c(() => g({ config: n }), { autoLoad: !0 }), [v, y] = a(!1), b = i(null), x = h.status === "error" ? h.error : void 0, S = h.status === "submitting", C = h.status === "capture" && h.canContinue && !S, w = r(() => {
471
- b.current && (b.current.on(), b.current.clear(), y(!1), _.setSignatureValid(!1));
472
- }, [_]);
473
- t(() => {
474
- h.status === "finished" && o?.();
475
- }, [h.status, o]), t(() => {
476
- x && (l?.(x), b.current?.on());
477
- }, [x, l]);
478
- let T = () => n.title?.trim() || m("signature.fullSignatureTitle"), E = () => n.subTitle?.trim() || m("signature.subtitle"), O = async () => {
479
- let e = b.current;
480
- if (!e) return;
481
- let t = e.getSignatureWithWhiteBackground();
482
- if (t) return n.sendBase64 ?? !1 ? t.toDataURL("image/png").replace(/^data:image\/png;base64,/, "") : e.getBlob(t);
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
- return h.status === "idle" || h.status === "finished" || h.status === "error" ? null : h.status === "success" ? /* @__PURE__ */ s(p, {
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: m("signature.successTitle")
487
- }) : /* @__PURE__ */ s(d, {
862
+ successTitle: t("signature.successTitle")
863
+ });
864
+ return /* @__PURE__ */ u(Page, {
488
865
  className: "IncodeSignature IncodeSignatureFadeIn",
489
- title: T(),
490
- subtitle: E(),
491
- children: [/* @__PURE__ */ s("div", {
866
+ title: resolveTitle(),
867
+ subtitle: resolveSubtitle(),
868
+ children: [/* @__PURE__ */ u("div", {
492
869
  class: "IncodeSignatureContent",
493
870
  children: [
494
- /* @__PURE__ */ s(D, {
495
- ref: b,
496
- hasDrawing: v,
871
+ /* @__PURE__ */ u(SignatureCanvas, {
872
+ ref: signatureRef,
873
+ hasDrawing,
497
874
  onBeginStroke: () => {
498
- y(!0), _.setSignatureValid(!0);
875
+ setHasDrawing(true);
876
+ setAnnouncement(t("signature.captured"));
877
+ manager.setSignatureValid(true);
499
878
  },
500
- placeholder: m("signature.fullSignaturePlaceholder"),
501
- customBackgroundColor: n.canvasBackgroundColor,
502
- customBorderColor: n.canvasBorderColor,
503
- customPenColor: n.penColor,
504
- customPenStrokeWidth: n.penStrokeWidth
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__ */ s(u, { size: 8 }),
507
- /* @__PURE__ */ s(f, {
886
+ /* @__PURE__ */ u(Spacer, { size: 8 }),
887
+ /* @__PURE__ */ u(Button, {
508
888
  variant: "link",
509
- disabled: !v || S,
510
- onClick: w,
511
- children: m("signature.clear")
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__ */ s("div", {
900
+ }), /* @__PURE__ */ u("div", {
515
901
  class: "IncodeSignatureButtonContainer",
516
- children: /* @__PURE__ */ s(f, {
517
- disabled: !C,
518
- isLoading: S,
519
- onClick: async () => {
520
- let e = b.current;
521
- if (!(!e || h.status !== "capture" || e.isEmpty())) {
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
- }, k = ({ config: e, onFinish: t, onError: n }) => /* @__PURE__ */ s(l, { children: e ? /* @__PURE__ */ s(O, {
540
- config: e,
541
- onFinish: t,
542
- onError: n
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
- m(k, "incode-signature");
917
+ registerIncodeModuleElement(Signature, "incode-signature");
545
918
  //#endregion
546
- export { k as Signature };
919
+ export { Signature };