@incodetech/web 0.0.0-dev-20260608-c8c427ca → 0.0.0-dev-20260609-11ba3e8a

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 (211) hide show
  1. package/dist/ae-signature/ae-signature.es.js +15 -13
  2. package/dist/aligndevicelottie-DY_bX_p8.js +12769 -0
  3. package/dist/antifraud/antifraud.es.js +22 -19
  4. package/dist/authentication/authentication.es.js +42 -33
  5. package/dist/autoFocusTitle-DM6PvgcP.js +29 -0
  6. package/dist/{back-horizontal-hint-DsPhKbR4.js → back-horizontal-hint-BXYix0Wj.js} +26 -26
  7. package/dist/back-tutorial-vb1MxlrT.js +14597 -0
  8. package/dist/{back-vertical-hint-BFJbYQrX.js → back-vertical-hint-DNSh6JNH.js} +27 -27
  9. package/dist/backdevicelottie-HypPqBz7.js +16690 -0
  10. package/dist/base.css +5 -0
  11. package/dist/blurdevicelottie-CBXtBFiJ.js +15951 -0
  12. package/dist/bottomSheet-BuzqNQtG.js +39 -0
  13. package/dist/browser-ponyfill-CLLvZCVg.js +441 -0
  14. package/dist/button-B-qlr4iI.js +35 -0
  15. package/dist/checkbox-CTPETqo5.js +96 -0
  16. package/dist/consent/consent.es.js +75 -64
  17. package/dist/countrySelector-CzyuaDIs.js +60 -0
  18. package/dist/cpf-ocr/cpf-ocr.es.js +2 -2
  19. package/dist/cpfOcr-DQVs3r8N.js +92 -0
  20. package/dist/cpfOcr-WNklFuxT.js +2 -0
  21. package/dist/cross-document-data-match/cross-document-data-match.es.js +20 -17
  22. package/dist/curp-validation/curp-validation.es.js +246 -211
  23. package/dist/customFields-B4MqqDI6.js +140 -0
  24. package/dist/customWatchlist-Dfqw1DQP.js +36 -0
  25. package/dist/dateInputComposed-BsPQHG5o.js +1 -0
  26. package/dist/dateInputComposed-DY97tQVK.js +69 -0
  27. package/dist/defineProperty-mefzVtTv.js +39 -0
  28. package/dist/document-capture/document-capture.es.js +2 -2
  29. package/dist/documentCapture-BE78MIlR.js +876 -0
  30. package/dist/documentCapture-BVfNZL29.js +2 -0
  31. package/dist/dropdownComposed-BF4L-7mJ.js +380 -0
  32. package/dist/dropdownComposed-mvHuRFHn.js +1 -0
  33. package/dist/dynamicForms-BYGGAQoc.js +352 -0
  34. package/dist/ekyb/ekyb.es.js +2 -2
  35. package/dist/ekybModule-BUPX0QhW.js +2 -0
  36. package/dist/ekybModule-CkTXu-4u.js +279 -0
  37. package/dist/ekyc/ekyc.es.js +2 -2
  38. package/dist/ekycModule-BWsVX39d.js +257 -0
  39. package/dist/ekycModule-DNDPqvUc.js +2 -0
  40. package/dist/electronic-signature/electronic-signature.es.js +2 -2
  41. package/dist/electronic-signature-BJSyzex9.js +426 -0
  42. package/dist/email/email.es.js +198 -78
  43. package/dist/emailInput-BHp4Apt4.js +39 -0
  44. package/dist/errorIcon-B0rmz3rw.js +26 -0
  45. package/dist/expiredId-C105HVKv.js +85 -0
  46. package/dist/extensibility-DJwVxojG.js +3070 -0
  47. package/dist/extensibility.es.js +26 -26
  48. package/dist/face-match/face-match.es.js +2 -2
  49. package/dist/faceMatch-BOFGxzzx.js +343 -0
  50. package/dist/faceMatch-CDMcFQwR.js +2 -0
  51. package/dist/field-comparison/field-comparison.es.js +2 -2
  52. package/dist/fieldComparison-BMDmQ8eA.js +88 -0
  53. package/dist/fieldComparison-Z1NleSxD.js +2 -0
  54. package/dist/{flip-animation-CuQ57qTn.js → flip-animation-BGRvygw9.js} +4221 -4221
  55. package/dist/flow/flow.es.js +597 -493
  56. package/dist/flow/styles.css +0 -8
  57. package/dist/{front-horizontal-hint-CKm7PnmS.js → front-horizontal-hint-CLSU0iVo.js} +70 -70
  58. package/dist/{front-vertical-hint-CLHC2qoH.js → front-vertical-hint-BWq-yWQ8.js} +81 -81
  59. package/dist/frontdevicelottie-CLqitJhG.js +17314 -0
  60. package/dist/geolocation/geolocation.es.js +485 -395
  61. package/dist/glaredevicelottie-BS04U6Fc.js +14478 -0
  62. package/dist/governmentValidation/governmentValidation.es.js +145 -64
  63. package/dist/governmentValidation/styles.css +0 -36
  64. package/dist/homeScreen-BsEYyiDB.js +264 -0
  65. package/dist/hooks-BtgmGvba.js +149 -0
  66. package/dist/i18n-gTHArCl9.js +2971 -0
  67. package/dist/icons-DKY3xDkf.js +360 -0
  68. package/dist/id/id.es.js +565 -413
  69. package/dist/id-laser-h-DX8UbVNH.js +467 -0
  70. package/dist/id-laser-v-DhnHdjlB.js +490 -0
  71. package/dist/id-tutorial-lj4iKtYT.js +13165 -0
  72. package/dist/id-verification/id-verification.es.js +21 -18
  73. package/dist/idOcr-BS77o1VC.js +123 -0
  74. package/dist/identity-reuse/identity-reuse.es.js +168 -130
  75. package/dist/incode-logo-57XFniXU.js +4 -0
  76. package/dist/incodeComponent-CDJxFZvS.js +63 -0
  77. package/dist/incodeModule-DkA_yd0X.js +13 -0
  78. package/dist/index.es.js +16 -14
  79. package/dist/inputComposed-5V2nLTqH.js +99 -0
  80. package/dist/inputComposed-BPOYwUBl.js +1 -0
  81. package/dist/loadingIcon-DN62ugKs.js +148 -0
  82. package/dist/lottie_light-Dp9Bz3mf.js +9031 -0
  83. package/dist/mandatoryConsent-DP189TUn.js +107 -0
  84. package/dist/modal-B5QeulDu.js +153 -0
  85. package/dist/modal.hooks-C7K9k_pY.js +202 -0
  86. package/dist/numberedStep-DVAyTPv1.js +13 -0
  87. package/dist/optionAccessibleLabel-Czc2YC8z.js +202 -0
  88. package/dist/otpInput-2IQ-JCK8.js +195 -0
  89. package/dist/page-BZ-0eNWq.js +71 -0
  90. package/dist/{passport-horizontal-hint-C_le0HVU.js → passport-horizontal-hint-DfVsf4Cc.js} +55 -55
  91. package/dist/{passport-tutorial-BYN4T_TE.js → passport-tutorial-zT1ZoA-D.js} +7096 -7084
  92. package/dist/{passport-vertical-hint-H-pyICSv.js → passport-vertical-hint-DVxbTyQp.js} +49 -49
  93. package/dist/pdf-BZA70WbM.js +22398 -0
  94. package/dist/pdfViewer-Dr63sJ51.js +114 -0
  95. package/dist/phone/phone.es.js +214 -87
  96. package/dist/phoneInputComposed-D_IabWKJ.js +12142 -0
  97. package/dist/processing-B_u8wUB7.js +8 -0
  98. package/dist/qe-signature/qe-signature.es.js +15 -13
  99. package/dist/radioGroupComposed-DwYW-Ld-.js +215 -0
  100. package/dist/redirect-to-mobile/redirect-to-mobile.es.js +2099 -859
  101. package/dist/registerIncodeElement-BJJGzVdq.js +11 -0
  102. package/dist/requiredLabelHint-DEadtiwx.js +17 -0
  103. package/dist/richText-C7GUm0WL.js +3153 -0
  104. package/dist/rolldown-runtime--E5BIlTp.js +33 -0
  105. package/dist/selfie/selfie.es.js +54 -42
  106. package/dist/selfieTutorial-CtruLyO2.js +2689 -0
  107. package/dist/signature/signature.es.js +765 -406
  108. package/dist/snackbar-Dz9crm39.js +16 -0
  109. package/dist/spinner-BfBIZkDQ.js +42 -0
  110. package/dist/spinner-DEDtE7Pz.js +1 -0
  111. package/dist/statusPage-CVCoieyd.js +28 -0
  112. package/dist/successIcon-rmzr-pxu.js +30 -0
  113. package/dist/tabs--UMd6eEB.js +103 -0
  114. package/dist/transitionSpinner-CWhGcr7c.js +26 -0
  115. package/dist/{tutorial-QzQ536BL.js → tutorial-Jv0noW4z.js} +832 -578
  116. package/dist/types/extensibility.d.ts +3 -1
  117. package/dist/types/index.d.ts +13 -4
  118. package/dist/typography-BK4AmfKX.js +45 -0
  119. package/dist/uiConfig-sgEkFuuA.js +25 -0
  120. package/dist/useModuleLoader-CuhHtmgr.js +670 -0
  121. package/dist/vendor-preact-BH7vOa2r.js +957 -0
  122. package/dist/verificationResult-CJ0JyV6A.js +64 -0
  123. package/dist/verifiedByIncode-8QBn-kgZ.js +103 -0
  124. package/dist/watchlist/watchlist.es.js +31 -26
  125. package/dist/watchlistForBusiness-RZcnjVDb.js +80 -0
  126. package/dist/workflow/styles.css +0 -8
  127. package/dist/workflow/workflow.es.js +251 -209
  128. package/package.json +4 -2
  129. package/dist/aligndevicelottie-D8KsO77t.js +0 -12757
  130. package/dist/autoFocusTitle-BpYdaSUM.js +0 -16
  131. package/dist/back-tutorial-DhSE2FJo.js +0 -14585
  132. package/dist/backdevicelottie-CJWGVMdw.js +0 -16678
  133. package/dist/blurdevicelottie-Dxt2deEB.js +0 -15939
  134. package/dist/bottomSheet-QrpyatOD.js +0 -31
  135. package/dist/browser-ponyfill-Crda_c5R.js +0 -299
  136. package/dist/button-DcCUEn2n.js +0 -24
  137. package/dist/checkbox-DCCzBAuF.js +0 -86
  138. package/dist/countrySelector-CJ8egQ4C.js +0 -58
  139. package/dist/cpfOcr-Db06i-Lm.js +0 -2
  140. package/dist/cpfOcr-FixhUeMQ.js +0 -79
  141. package/dist/customFields-C1G9xHNX.js +0 -125
  142. package/dist/customWatchlist-IKEblz7u.js +0 -31
  143. package/dist/dateInputComposed-Cg8BvYSK.js +0 -1
  144. package/dist/dateInputComposed-Ddd7HLyM.js +0 -58
  145. package/dist/defineProperty-xczUyn-m.js +0 -39
  146. package/dist/documentCapture-D9I7FjGe.js +0 -2
  147. package/dist/documentCapture-b61wlala.js +0 -765
  148. package/dist/dropdownComposed-B4U0AIak.js +0 -1
  149. package/dist/dropdownComposed-CS2pyn-g.js +0 -293
  150. package/dist/dynamicForms-tYQog0kw.js +0 -298
  151. package/dist/ekybModule-C33C4JES.js +0 -237
  152. package/dist/ekybModule-LON6G2Bz.js +0 -2
  153. package/dist/ekycModule-BJOgtTAh.js +0 -225
  154. package/dist/ekycModule-BSf_DIG7.js +0 -2
  155. package/dist/electronic-signature-OdgTyso4.js +0 -406
  156. package/dist/emailInput-CU7mLB21.js +0 -37
  157. package/dist/errorIcon-DpHzAoAo.js +0 -24
  158. package/dist/expiredId-nfVAZgTL.js +0 -70
  159. package/dist/extensibility-BbNy3mVG.js +0 -2602
  160. package/dist/faceMatch-BIila4kf.js +0 -2
  161. package/dist/faceMatch-DJ7Mqujx.js +0 -206
  162. package/dist/fieldComparison-D2RSFYl-.js +0 -84
  163. package/dist/fieldComparison-DbUyouFd.js +0 -2
  164. package/dist/frontdevicelottie-65Vyfpff.js +0 -17302
  165. package/dist/glaredevicelottie-BEyaqtc6.js +0 -14466
  166. package/dist/homeScreen-CyPddxWl.js +0 -227
  167. package/dist/hooks-MxHtZWTS.js +0 -112
  168. package/dist/i18n-Kzzvkz94.js +0 -2019
  169. package/dist/icons-9I5g9-_1.js +0 -292
  170. package/dist/id-laser-h-iCPbFixz.js +0 -467
  171. package/dist/id-laser-v-CNzwliP2.js +0 -483
  172. package/dist/id-tutorial-CF4nO4oX.js +0 -13153
  173. package/dist/idOcr-DlMLMDqa.js +0 -97
  174. package/dist/incode-logo-DX016usY.js +0 -4
  175. package/dist/incodeComponent-BoFhgK7G.js +0 -50
  176. package/dist/incodeModule-BiCoAJ5k.js +0 -13
  177. package/dist/inputComposed-DAEey9xm.js +0 -94
  178. package/dist/inputComposed-eS4B0Mkh.js +0 -1
  179. package/dist/loadingIcon-BN5YRQUb.js +0 -104
  180. package/dist/lottie_light-DLqSnziX.js +0 -4419
  181. package/dist/mandatoryConsent-DNz2jZ43.js +0 -98
  182. package/dist/modal-ZqAhwiRF.js +0 -135
  183. package/dist/modal.hooks-LdusROLW.js +0 -126
  184. package/dist/numberedStep-CdLWASwL.js +0 -11
  185. package/dist/optionAccessibleLabel-DcygPaME.js +0 -140
  186. package/dist/otpInput-C4pk4BJU.js +0 -157
  187. package/dist/page-DA3R7q0J.js +0 -69
  188. package/dist/pdf-51QeiFSx.js +0 -14967
  189. package/dist/pdfViewer-rKzTHket.js +0 -64
  190. package/dist/phoneInputComposed-CjAxk2Gj.js +0 -11230
  191. package/dist/processing-DPktVde2.js +0 -6
  192. package/dist/radioGroupComposed-DRRxVk9Z.js +0 -178
  193. package/dist/registerIncodeElement-BHWOwdSS.js +0 -7
  194. package/dist/requiredLabelHint-B6FN3v88.js +0 -13
  195. package/dist/richText-6pIbydcz.js +0 -1973
  196. package/dist/rolldown-runtime-CYMK-g2i.js +0 -20
  197. package/dist/selfieTutorial-Yo9AlUoT.js +0 -2677
  198. package/dist/snackbar-CQiiWO4p.js +0 -14
  199. package/dist/spinner-B4dcie2T.js +0 -1
  200. package/dist/spinner-CKnjVHxw.js +0 -39
  201. package/dist/statusPage-B8b3Jg6N.js +0 -28
  202. package/dist/successIcon-SlKgTSty.js +0 -28
  203. package/dist/tabs-D7lGst3Q.js +0 -78
  204. package/dist/transitionSpinner-Di3bOyOu.js +0 -17
  205. package/dist/typography-CxjaknHN.js +0 -28
  206. package/dist/uiConfig-CwpQ-IM6.js +0 -20
  207. package/dist/useModuleLoader-Bqs7fglI.js +0 -517
  208. package/dist/vendor-preact-D6SntenC.js +0 -958
  209. package/dist/verificationResult-DhT3hH1b.js +0 -90
  210. package/dist/verifiedByIncode-DpbxzO0y.js +0 -101
  211. package/dist/watchlistForBusiness-CRXVbH4l.js +0 -75
@@ -1,547 +1,906 @@
1
- import { n as e } from "../i18n-Kzzvkz94.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 { c, o as l } from "../hooks-MxHtZWTS.js";
4
- import { t as u } from "../incodeComponent-BoFhgK7G.js";
5
- import { r as d } from "../loadingIcon-BN5YRQUb.js";
6
- import { t as f } from "../page-DA3R7q0J.js";
7
- import "../extensibility-BbNy3mVG.js";
8
- import { t as p } from "../button-DcCUEn2n.js";
9
- import { t as m } from "../verificationResult-DhT3hH1b.js";
10
- import { t as h } from "../incodeModule-BiCoAJ5k.js";
11
- import { t as g } from "../defineProperty-xczUyn-m.js";
12
- import { createSignatureManager as _ } from "@incodetech/core/signature";
1
+ import { n as useTranslation } from "../i18n-gTHArCl9.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-BH7vOa2r.js";
3
+ import { c as useManager, o as useModuleTerminalCallbacks } from "../hooks-BtgmGvba.js";
4
+ import { t as IncodeComponent } from "../incodeComponent-CDJxFZvS.js";
5
+ import { r as Spacer } from "../loadingIcon-DN62ugKs.js";
6
+ import { t as Page } from "../page-BZ-0eNWq.js";
7
+ import "../extensibility-DJwVxojG.js";
8
+ import { t as Button } from "../button-B-qlr4iI.js";
9
+ import { t as VerificationResult } from "../verificationResult-CJ0JyV6A.js";
10
+ import { t as registerIncodeModuleElement } from "../incodeModule-DkA_yd0X.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 v = class {
15
- constructor(e, t, n, r) {
16
- if (g(this, "x", void 0), g(this, "y", void 0), g(this, "pressure", void 0), g(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
- }, y = 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 v(s.x + h, s.y + g),
49
- c2: new v(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
- }, b = class {
105
+ };
106
+ var SignatureEventTarget = class {
68
107
  constructor() {
69
- g(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 x(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 S = class e extends b {
96
- constructor(t, n = {}) {
97
- super(), g(this, "dotSize", void 0), g(this, "minWidth", void 0), g(this, "maxWidth", void 0), g(this, "penColor", void 0), g(this, "minDistance", void 0), g(this, "velocityFilterWeight", void 0), g(this, "compositeOperation", void 0), g(this, "backgroundColor", void 0), g(this, "throttle", void 0), g(this, "canvasContextOptions", void 0), g(this, "_ctx", void 0), g(this, "_drawingStroke", !1), g(this, "_isEmpty", !0), g(this, "_dataUrl", void 0), g(this, "_dataUrlOptions", void 0), g(this, "_lastPoints", []), g(this, "_data", []), g(this, "_lastVelocity", 0), g(this, "_lastWidth", 0), g(this, "_strokeMoveUpdate", void 0), g(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 ? x(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 v(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 = y.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 v(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
- }, C = (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
- }, w = "var(--icon-neutral-800)", T = "#ffffff", E = (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 = T, n.fillRect(0, 0, t.width, t.height), n.drawImage(e, 0, 0), t;
395
- }, D = (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
- }), O = 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, 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 ? E(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 ? D(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 ?? C(w), a = new S(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
+ "aria-label": placeholder
789
+ }), !hasDrawing && /* @__PURE__ */ u("p", {
461
790
  class: "SignatureCanvasPlaceholder",
462
- children: a
791
+ children: placeholder
463
792
  })]
464
793
  });
465
794
  });
466
- O.displayName = "SignatureCanvas";
795
+ SignatureCanvas.displayName = "SignatureCanvas";
467
796
  //#endregion
468
797
  //#region src/modules/signature/signature.tsx
469
- var k = ({ config: n, onFinish: o, onError: u }) => {
470
- let { t: h } = e(), [g, v] = c(() => _({ config: n }), { autoLoad: !0 }), [y, b] = a(!1), x = i(null), S = g.status === "error" ? g.error : void 0, C = g.status === "submitting", w = g.status === "capture" && g.canContinue && !C, T = r(() => {
471
- x.current && (x.current.on(), x.current.clear(), b(!1), v.setSignatureValid(!1));
472
- }, [v]);
473
- l({
474
- status: g.status === "finished" ? "finished" : "loading",
475
- onFinish: o
476
- }), t(() => {
477
- S && (u?.(S), x.current?.on());
478
- }, [S, u]);
479
- let E = () => n.title?.trim() || h("signature.fullSignatureTitle"), D = () => n.subTitle?.trim() || h("signature.subtitle"), k = async () => {
480
- let e = x.current;
481
- if (!e) return;
482
- let t = e.getSignatureWithWhiteBackground();
483
- if (t) return n.sendBase64 ?? !1 ? t.toDataURL("image/png").replace(/^data:image\/png;base64,/, "") : e.getBlob(t);
798
+ var SignatureContent = ({ config, onFinish, onError }) => {
799
+ const { t } = useTranslation();
800
+ const [state, manager] = useManager(() => createSignatureManager({ config }), { autoLoad: true });
801
+ const [hasDrawing, setHasDrawing] = d(false);
802
+ const signatureRef = A(null);
803
+ const error = state.status === "error" ? state.error : void 0;
804
+ const isSubmitting = state.status === "submitting";
805
+ const canContinue = state.status === "capture" && state.canContinue && !isSubmitting;
806
+ const clearCanvas = q(() => {
807
+ if (!signatureRef.current) return;
808
+ signatureRef.current.on();
809
+ signatureRef.current.clear();
810
+ setHasDrawing(false);
811
+ manager.setSignatureValid(false);
812
+ }, [manager]);
813
+ useModuleTerminalCallbacks({
814
+ status: state.status === "finished" ? "finished" : "loading",
815
+ onFinish
816
+ });
817
+ y(() => {
818
+ if (!error) return;
819
+ onError?.(error);
820
+ signatureRef.current?.on();
821
+ }, [error, onError]);
822
+ const resolveTitle = () => {
823
+ const configuredTitle = config.title?.trim();
824
+ if (configuredTitle) return configuredTitle;
825
+ return t("signature.fullSignatureTitle");
826
+ };
827
+ const resolveSubtitle = () => {
828
+ const configuredSubtitle = config.subTitle?.trim();
829
+ if (configuredSubtitle) return configuredSubtitle;
830
+ return t("signature.subtitle");
484
831
  };
485
- return g.status === "idle" || g.status === "finished" || g.status === "error" ? null : g.status === "success" ? /* @__PURE__ */ s(m, {
832
+ const exportSignatureImage = async () => {
833
+ const canvasHandle = signatureRef.current;
834
+ if (!canvasHandle) return void 0;
835
+ const canvasWithWhiteBackground = canvasHandle.getSignatureWithWhiteBackground();
836
+ if (!canvasWithWhiteBackground) return void 0;
837
+ if (config.sendBase64 ?? false) return canvasWithWhiteBackground.toDataURL("image/png").replace(/^data:image\/png;base64,/, "");
838
+ return canvasHandle.getBlob(canvasWithWhiteBackground);
839
+ };
840
+ const handleContinue = async () => {
841
+ const canvasHandle = signatureRef.current;
842
+ if (!canvasHandle || state.status !== "capture" || canvasHandle.isEmpty()) return;
843
+ canvasHandle.off();
844
+ try {
845
+ const image = await exportSignatureImage();
846
+ if (!image) {
847
+ canvasHandle.on();
848
+ return;
849
+ }
850
+ manager.submit(image);
851
+ } catch {
852
+ canvasHandle.on();
853
+ }
854
+ };
855
+ if (state.status === "idle" || state.status === "finished" || state.status === "error") return null;
856
+ if (state.status === "success") return /* @__PURE__ */ u(VerificationResult, {
486
857
  status: "success",
487
- successTitle: h("signature.successTitle")
488
- }) : /* @__PURE__ */ s(f, {
858
+ successTitle: t("signature.successTitle")
859
+ });
860
+ return /* @__PURE__ */ u(Page, {
489
861
  className: "IncodeSignature IncodeSignatureFadeIn",
490
- title: E(),
491
- subtitle: D(),
492
- children: [/* @__PURE__ */ s("div", {
862
+ title: resolveTitle(),
863
+ subtitle: resolveSubtitle(),
864
+ children: [/* @__PURE__ */ u("div", {
493
865
  class: "IncodeSignatureContent",
494
866
  children: [
495
- /* @__PURE__ */ s(O, {
496
- ref: x,
497
- hasDrawing: y,
867
+ /* @__PURE__ */ u(SignatureCanvas, {
868
+ ref: signatureRef,
869
+ hasDrawing,
498
870
  onBeginStroke: () => {
499
- b(!0), v.setSignatureValid(!0);
871
+ setHasDrawing(true);
872
+ manager.setSignatureValid(true);
500
873
  },
501
- placeholder: h("signature.fullSignaturePlaceholder"),
502
- customBackgroundColor: n.canvasBackgroundColor,
503
- customBorderColor: n.canvasBorderColor,
504
- customPenColor: n.penColor,
505
- customPenStrokeWidth: n.penStrokeWidth
874
+ placeholder: t("signature.fullSignaturePlaceholder"),
875
+ customBackgroundColor: config.canvasBackgroundColor,
876
+ customBorderColor: config.canvasBorderColor,
877
+ customPenColor: config.penColor,
878
+ customPenStrokeWidth: config.penStrokeWidth
506
879
  }),
507
- /* @__PURE__ */ s(d, { size: 8 }),
508
- /* @__PURE__ */ s(p, {
880
+ /* @__PURE__ */ u(Spacer, { size: 8 }),
881
+ /* @__PURE__ */ u(Button, {
509
882
  variant: "link",
510
- disabled: !y || C,
511
- onClick: T,
512
- children: h("signature.clear")
883
+ disabled: !hasDrawing || isSubmitting,
884
+ onClick: clearCanvas,
885
+ children: t("signature.clear")
513
886
  })
514
887
  ]
515
- }), /* @__PURE__ */ s("div", {
888
+ }), /* @__PURE__ */ u("div", {
516
889
  class: "IncodeSignatureButtonContainer",
517
- children: /* @__PURE__ */ s(p, {
518
- disabled: !w,
519
- isLoading: C,
520
- onClick: async () => {
521
- let e = x.current;
522
- if (!(!e || g.status !== "capture" || e.isEmpty())) {
523
- e.off();
524
- try {
525
- let t = await k();
526
- if (!t) {
527
- e.on();
528
- return;
529
- }
530
- v.submit(t);
531
- } catch {
532
- e.on();
533
- }
534
- }
535
- },
536
- children: h("signature.done")
890
+ children: /* @__PURE__ */ u(Button, {
891
+ disabled: !canContinue,
892
+ isLoading: isSubmitting,
893
+ onClick: handleContinue,
894
+ children: t("signature.done")
537
895
  })
538
896
  })]
539
897
  });
540
- }, A = ({ config: e, onFinish: t, onError: n }) => /* @__PURE__ */ s(u, { children: e ? /* @__PURE__ */ s(k, {
541
- config: e,
542
- onFinish: t,
543
- onError: n
898
+ };
899
+ var Signature = ({ config, onFinish, onError }) => /* @__PURE__ */ u(IncodeComponent, { children: config ? /* @__PURE__ */ u(SignatureContent, {
900
+ config,
901
+ onFinish,
902
+ onError
544
903
  }) : null });
545
- h(A, "incode-signature");
904
+ registerIncodeModuleElement(Signature, "incode-signature");
546
905
  //#endregion
547
- export { A as Signature };
906
+ export { Signature };