@justifi/webcomponents 6.12.4 → 6.13.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 (209) hide show
  1. package/dist/cjs/{Analytics-BERGweGK.js → Analytics-Be2I_aiS.js} +2 -2
  2. package/dist/cjs/{Plaid-BRSyOOuw.js → Plaid-Aw35bhCX.js} +2 -2
  3. package/dist/cjs/additional-questions-form-step_14.cjs.entry.js +5 -5
  4. package/dist/cjs/bank-account-form.cjs.entry.js +2 -2
  5. package/dist/cjs/{business.service-Z9OACEQL.js → business.service-CylI3Qrg.js} +1 -1
  6. package/dist/cjs/card-form.cjs.entry.js +2 -2
  7. package/dist/cjs/{check-pkg-version-ByKpJklZ.js → check-pkg-version-BLLLh6v-.js} +1 -1
  8. package/dist/cjs/checkout-actions-8-MUczKw.js +62 -0
  9. package/dist/cjs/{checkout.service-BZOyqXgW.js → checkout.service-BYpinbSR.js} +1 -1
  10. package/dist/cjs/dispute-notification_2.cjs.entry.js +6 -6
  11. package/dist/cjs/{event-types-AU1B76Vm.js → event-types-DptNnCEP.js} +1 -1
  12. package/dist/cjs/{get-business-aR-C83KX.js → get-business-D10Tmct1.js} +2 -2
  13. package/dist/cjs/{get-payment-details-dwhA02Zl.js → get-payment-details-BB5aa48u.js} +2 -2
  14. package/dist/cjs/{get-subaccounts-B1jmSa2d.js → get-subaccounts-CSD2nAqD.js} +2 -2
  15. package/dist/cjs/hidden-input_2.cjs.entry.js +1 -1
  16. package/dist/cjs/justifi-apple-pay_11.cjs.entry.js +10 -64
  17. package/dist/cjs/justifi-bank-account-billing-form-simple.cjs.entry.js +4 -4
  18. package/dist/cjs/justifi-bank-account-form.cjs.entry.js +4 -4
  19. package/dist/cjs/justifi-business-details.cjs.entry.js +7 -7
  20. package/dist/cjs/justifi-business-form.cjs.entry.js +7 -7
  21. package/dist/cjs/justifi-card-form.cjs.entry.js +4 -4
  22. package/dist/cjs/justifi-checkout-qr-code.cjs.entry.js +3141 -0
  23. package/dist/cjs/justifi-checkout.cjs.entry.js +4 -4
  24. package/dist/cjs/justifi-checkouts-list-filters.cjs.entry.js +1 -1
  25. package/dist/cjs/justifi-checkouts-list.cjs.entry.js +7 -7
  26. package/dist/cjs/justifi-dispute-management.cjs.entry.js +6 -6
  27. package/dist/cjs/justifi-gross-payment-chart.cjs.entry.js +5 -5
  28. package/dist/cjs/justifi-order-terminals.cjs.entry.js +8 -8
  29. package/dist/cjs/justifi-payment-details.cjs.entry.js +7 -7
  30. package/dist/cjs/justifi-payment-provisioning.cjs.entry.js +7 -7
  31. package/dist/cjs/justifi-payment-transactions-list.cjs.entry.js +6 -6
  32. package/dist/cjs/justifi-payments-list.cjs.entry.js +6 -6
  33. package/dist/cjs/justifi-payout-details.cjs.entry.js +7 -7
  34. package/dist/cjs/justifi-payout-transactions-list.cjs.entry.js +6 -6
  35. package/dist/cjs/justifi-payouts-list-filters.cjs.entry.js +1 -1
  36. package/dist/cjs/justifi-payouts-list.cjs.entry.js +8 -8
  37. package/dist/cjs/justifi-qr-terminal.cjs.entry.js +208 -0
  38. package/dist/cjs/justifi-refund-payment.cjs.entry.js +7 -7
  39. package/dist/cjs/justifi-season-interruption-insurance.cjs.entry.js +5 -5
  40. package/dist/cjs/justifi-terminal-orders-list-filters.cjs.entry.js +1 -1
  41. package/dist/cjs/justifi-terminal-orders-list.cjs.entry.js +5 -5
  42. package/dist/cjs/justifi-terminals-list-filters.cjs.entry.js +1 -1
  43. package/dist/cjs/justifi-terminals-list.cjs.entry.js +7 -7
  44. package/dist/cjs/loader.cjs.js +1 -1
  45. package/dist/cjs/{package-B6L3zyfG.js → package-gx36QXN1.js} +1 -1
  46. package/dist/cjs/{payment-provisioning-actions-BiSpysjW.js → payment-provisioning-actions-DimM0KGV.js} +2 -2
  47. package/dist/cjs/{payment.service-ByrgA_QZ.js → payment.service-fy5bXXmA.js} +1 -1
  48. package/dist/cjs/{payout.service-CnQm_BpU.js → payout.service-hp3PTXWI.js} +1 -1
  49. package/dist/cjs/{payouts-status-AuS3Mp0V.js → payouts-status-CF1YT_RL.js} +2 -2
  50. package/dist/cjs/{plaid.service-Dlb8EUR8.js → plaid.service-9PmS4X0g.js} +1 -1
  51. package/dist/cjs/{terminal.service-BdwHQ3Vv.js → terminal.service-D5D76Cnn.js} +1 -1
  52. package/dist/cjs/{utils-FVGp6se3.js → utils-Dcde8Zpt.js} +1 -1
  53. package/dist/cjs/webcomponents.cjs.js +1 -1
  54. package/dist/collection/collection-manifest.json +2 -0
  55. package/dist/collection/components/checkout-qr-code/justifi-checkout-qr-code.js +128 -0
  56. package/dist/collection/components/qr-terminal/justifi-qr-terminal.js +349 -0
  57. package/dist/docs.json +283 -1
  58. package/dist/esm/{Analytics-B1bQP71R.js → Analytics-DZWGizAK.js} +2 -2
  59. package/dist/esm/{Plaid-l6nNIjab.js → Plaid-fhlY0CIN.js} +1 -1
  60. package/dist/esm/additional-questions-form-step_14.entry.js +5 -5
  61. package/dist/esm/bank-account-form.entry.js +2 -2
  62. package/dist/esm/{business.service-C31wbMVs.js → business.service-Crs-0Mdy.js} +1 -1
  63. package/dist/esm/card-form.entry.js +2 -2
  64. package/dist/esm/{check-pkg-version-CNwUC4SV.js → check-pkg-version-CVyuA8aH.js} +1 -1
  65. package/dist/esm/checkout-actions-BMnp3uHK.js +59 -0
  66. package/dist/esm/{checkout.service-cVdOGDuI.js → checkout.service-BMAQVmHa.js} +1 -1
  67. package/dist/esm/dispute-notification_2.entry.js +6 -6
  68. package/dist/esm/{event-types-DalU_6SB.js → event-types-CVVB5p_Q.js} +1 -1
  69. package/dist/esm/{get-business-Gg6qn5on.js → get-business-B9ZS1tVq.js} +2 -2
  70. package/dist/esm/{get-payment-details-BiWgSJau.js → get-payment-details-CiR6FrkO.js} +2 -2
  71. package/dist/esm/{get-subaccounts-CkjZeR9U.js → get-subaccounts-VpDr7yN4.js} +2 -2
  72. package/dist/esm/hidden-input_2.entry.js +1 -1
  73. package/dist/esm/justifi-apple-pay_11.entry.js +8 -62
  74. package/dist/esm/justifi-bank-account-billing-form-simple.entry.js +4 -4
  75. package/dist/esm/justifi-bank-account-form.entry.js +4 -4
  76. package/dist/esm/justifi-business-details.entry.js +7 -7
  77. package/dist/esm/justifi-business-form.entry.js +7 -7
  78. package/dist/esm/justifi-card-form.entry.js +4 -4
  79. package/dist/esm/justifi-checkout-qr-code.entry.js +3139 -0
  80. package/dist/esm/justifi-checkout.entry.js +4 -4
  81. package/dist/esm/justifi-checkouts-list-filters.entry.js +1 -1
  82. package/dist/esm/justifi-checkouts-list.entry.js +7 -7
  83. package/dist/esm/justifi-dispute-management.entry.js +6 -6
  84. package/dist/esm/justifi-gross-payment-chart.entry.js +5 -5
  85. package/dist/esm/justifi-order-terminals.entry.js +8 -8
  86. package/dist/esm/justifi-payment-details.entry.js +7 -7
  87. package/dist/esm/justifi-payment-provisioning.entry.js +7 -7
  88. package/dist/esm/justifi-payment-transactions-list.entry.js +6 -6
  89. package/dist/esm/justifi-payments-list.entry.js +6 -6
  90. package/dist/esm/justifi-payout-details.entry.js +7 -7
  91. package/dist/esm/justifi-payout-transactions-list.entry.js +6 -6
  92. package/dist/esm/justifi-payouts-list-filters.entry.js +1 -1
  93. package/dist/esm/justifi-payouts-list.entry.js +8 -8
  94. package/dist/esm/justifi-qr-terminal.entry.js +206 -0
  95. package/dist/esm/justifi-refund-payment.entry.js +7 -7
  96. package/dist/esm/justifi-season-interruption-insurance.entry.js +5 -5
  97. package/dist/esm/justifi-terminal-orders-list-filters.entry.js +1 -1
  98. package/dist/esm/justifi-terminal-orders-list.entry.js +5 -5
  99. package/dist/esm/justifi-terminals-list-filters.entry.js +1 -1
  100. package/dist/esm/justifi-terminals-list.entry.js +7 -7
  101. package/dist/esm/loader.js +1 -1
  102. package/dist/esm/{package-OGt0dCJl.js → package-CZa-hHhJ.js} +1 -1
  103. package/dist/esm/{payment-provisioning-actions-cl5xIYnF.js → payment-provisioning-actions-CcDadiRe.js} +2 -2
  104. package/dist/esm/{payment.service-5_u-UzTY.js → payment.service-BiKQPL4M.js} +1 -1
  105. package/dist/esm/{payout.service-D2zS5y8N.js → payout.service-B9_cyUiU.js} +1 -1
  106. package/dist/esm/{payouts-status-DCjCGTaa.js → payouts-status-xOa5tT66.js} +2 -2
  107. package/dist/esm/{plaid.service-BiJ65YG8.js → plaid.service-bU3qIoKd.js} +1 -1
  108. package/dist/esm/{terminal.service-CIxDfM7V.js → terminal.service-BM6BvevW.js} +1 -1
  109. package/dist/esm/{utils-C1B2hVAB.js → utils-BogmBHgt.js} +1 -1
  110. package/dist/esm/webcomponents.js +1 -1
  111. package/dist/module/Plaid.js +1 -1
  112. package/dist/module/business-bank-account-form-step2.js +1 -1
  113. package/dist/module/checkout-actions.js +59 -0
  114. package/dist/module/get-payment-details.js +1 -1
  115. package/dist/module/justifi-checkout-qr-code.d.ts +11 -0
  116. package/dist/module/justifi-checkout-qr-code.js +6 -0
  117. package/dist/module/justifi-checkout-qr-code2.js +3154 -0
  118. package/dist/module/justifi-checkouts-list.js +1 -1
  119. package/dist/module/justifi-dispute-management.js +1 -1
  120. package/dist/module/justifi-modular-checkout2.js +2 -57
  121. package/dist/module/justifi-order-terminals.js +1 -1
  122. package/dist/module/justifi-payment-details.js +1 -1
  123. package/dist/module/justifi-payment-transactions-list.js +1 -1
  124. package/dist/module/justifi-payments-list.js +1 -1
  125. package/dist/module/justifi-payout-details.js +1 -1
  126. package/dist/module/justifi-payout-transactions-list.js +1 -1
  127. package/dist/module/justifi-payouts-list.js +1 -1
  128. package/dist/module/justifi-qr-terminal.d.ts +11 -0
  129. package/dist/module/justifi-qr-terminal.js +234 -0
  130. package/dist/module/justifi-refund-payment.js +1 -1
  131. package/dist/module/justifi-terminal-orders-list-filters.js +1 -1
  132. package/dist/module/justifi-terminal-orders-list.js +1 -1
  133. package/dist/module/justifi-terminals-list-filters.js +1 -1
  134. package/dist/module/justifi-terminals-list.js +1 -1
  135. package/dist/module/package.js +1 -1
  136. package/dist/types/api/Checkout.d.ts +1 -2
  137. package/dist/types/components/checkout-qr-code/justifi-checkout-qr-code.d.ts +18 -0
  138. package/dist/types/components/qr-terminal/justifi-qr-terminal.d.ts +42 -0
  139. package/dist/types/components.d.ts +92 -0
  140. package/dist/webcomponents/{p-ea0d7a98.entry.js → p-06e8df55.entry.js} +1 -1
  141. package/dist/webcomponents/{p-daaa2a99.entry.js → p-07f2f1bf.entry.js} +1 -1
  142. package/dist/webcomponents/p-0fb8fb8c.entry.js +1 -0
  143. package/dist/webcomponents/p-10087a53.entry.js +1 -0
  144. package/dist/webcomponents/{p-45c0fb53.entry.js → p-1d7b8c21.entry.js} +1 -1
  145. package/dist/webcomponents/{p-d24240a5.entry.js → p-21c89e22.entry.js} +1 -1
  146. package/dist/webcomponents/{p-d79c5ee4.entry.js → p-2ec7cd88.entry.js} +1 -1
  147. package/dist/webcomponents/p-2qotS5d_.js +1 -0
  148. package/dist/webcomponents/{p-69fdd137.entry.js → p-355a5c8d.entry.js} +1 -1
  149. package/dist/webcomponents/{p-8964f4ca.entry.js → p-37b95a11.entry.js} +1 -1
  150. package/dist/webcomponents/p-37fd1862.entry.js +1 -0
  151. package/dist/webcomponents/{p-c8f3656f.entry.js → p-392f0c1c.entry.js} +1 -1
  152. package/dist/webcomponents/{p-9d021e10.entry.js → p-44cf13ac.entry.js} +1 -1
  153. package/dist/webcomponents/{p-cde76bf8.entry.js → p-55fdab4e.entry.js} +1 -1
  154. package/dist/webcomponents/p-5ccb46ee.entry.js +1 -0
  155. package/dist/webcomponents/{p-8d173a7c.entry.js → p-5f8dfa8d.entry.js} +1 -1
  156. package/dist/webcomponents/{p-07236291.entry.js → p-70cd2808.entry.js} +1 -1
  157. package/dist/webcomponents/{p-3f5e9afb.entry.js → p-769d3d93.entry.js} +1 -1
  158. package/dist/webcomponents/{p-f30069ea.entry.js → p-79bd744e.entry.js} +1 -1
  159. package/dist/webcomponents/{p-49a4123c.entry.js → p-7a4cd292.entry.js} +1 -1
  160. package/dist/webcomponents/p-8d602e60.entry.js +1 -0
  161. package/dist/webcomponents/p-94f14640.entry.js +1 -0
  162. package/dist/webcomponents/p-98f399ec.entry.js +1 -0
  163. package/dist/webcomponents/{p-7119fddd.entry.js → p-9fca25fc.entry.js} +1 -1
  164. package/dist/webcomponents/{p-Ba8jdOkX.js → p-BGvaX-lJ.js} +1 -1
  165. package/dist/webcomponents/{p-NZS8uCtH.js → p-CSgcCWLS.js} +1 -1
  166. package/dist/webcomponents/p-CZa-hHhJ.js +1 -0
  167. package/dist/webcomponents/p-Cg_3KsGO.js +1 -0
  168. package/dist/webcomponents/p-CqPcl9v7.js +1 -0
  169. package/dist/webcomponents/p-CvgL8YaH.js +1 -0
  170. package/dist/webcomponents/{p-oTtn8xDw.js → p-D4E9P7df.js} +1 -1
  171. package/dist/webcomponents/{p-Dk26hk5T.js → p-DD-_8sbs.js} +1 -1
  172. package/dist/webcomponents/{p-mF5zKtkx.js → p-DHFQtPCq.js} +1 -1
  173. package/dist/webcomponents/p-DMqJWUK2.js +1 -0
  174. package/dist/webcomponents/{p-fE5A37L5.js → p-DZAMzLxa.js} +1 -1
  175. package/dist/webcomponents/{p-Cz_7BuGW.js → p-DbOUuBHs.js} +1 -1
  176. package/dist/webcomponents/{p-BxKbnILQ.js → p-Eb1f86_V.js} +1 -1
  177. package/dist/webcomponents/{p-av6jyzyC.js → p-XxG-t-Sl.js} +1 -1
  178. package/dist/webcomponents/{p-7ebed752.entry.js → p-aee2295b.entry.js} +1 -1
  179. package/dist/webcomponents/p-b20b8805.entry.js +1 -0
  180. package/dist/webcomponents/p-bb5de874.entry.js +1 -0
  181. package/dist/webcomponents/p-bd678d4a.entry.js +1 -0
  182. package/dist/webcomponents/{p-f3ff7e00.entry.js → p-c8ee1e4c.entry.js} +1 -1
  183. package/dist/webcomponents/p-ce1dde85.entry.js +1 -0
  184. package/dist/webcomponents/{p-8aa53ef2.entry.js → p-d620d4b4.entry.js} +1 -1
  185. package/dist/webcomponents/{p-ae91fc9b.entry.js → p-dcd600ca.entry.js} +1 -1
  186. package/dist/webcomponents/p-e6b9dfe1.entry.js +1 -0
  187. package/dist/webcomponents/p-eCeOsPHx.js +1 -0
  188. package/dist/webcomponents/{p-BJu1-9kE.js → p-eK8hZOMg.js} +1 -1
  189. package/dist/webcomponents/{p-a1dcdc8b.entry.js → p-ff5c5499.entry.js} +4 -4
  190. package/dist/webcomponents/{p-BXyADlAH.js → p-qju4tNG1.js} +1 -1
  191. package/dist/webcomponents/webcomponents.esm.js +1 -1
  192. package/package.json +16 -14
  193. package/LICENSE +0 -21
  194. package/dist/webcomponents/p-215c6b6b.entry.js +0 -1
  195. package/dist/webcomponents/p-31452258.entry.js +0 -1
  196. package/dist/webcomponents/p-35dd1fc0.entry.js +0 -1
  197. package/dist/webcomponents/p-4ec433f4.entry.js +0 -1
  198. package/dist/webcomponents/p-58b5e08e.entry.js +0 -1
  199. package/dist/webcomponents/p-5G1OMxZz.js +0 -1
  200. package/dist/webcomponents/p-6220a384.entry.js +0 -1
  201. package/dist/webcomponents/p-91aef5bf.entry.js +0 -1
  202. package/dist/webcomponents/p-APOabprT.js +0 -1
  203. package/dist/webcomponents/p-Aacb4jqT.js +0 -1
  204. package/dist/webcomponents/p-Cm9f5fyh.js +0 -1
  205. package/dist/webcomponents/p-OGt0dCJl.js +0 -1
  206. package/dist/webcomponents/p-b272a29d.entry.js +0 -1
  207. package/dist/webcomponents/p-c9fe4f33.entry.js +0 -1
  208. package/dist/webcomponents/p-ef85717f.entry.js +0 -1
  209. package/dist/webcomponents/p-nb_LhbJq.js +0 -1
@@ -0,0 +1,3154 @@
1
+ import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
2
+ import { g as getDefaultExportFromCjs } from './_commonjsHelpers.js';
3
+ import { C as ComponentErrorSeverity, a as ComponentErrorCodes } from './Plaid.js';
4
+ import { J as JustifiAnalytics } from './Analytics.js';
5
+ import { c as checkPkgVersion } from './check-pkg-version.js';
6
+
7
+ var browser = {};
8
+
9
+ var canPromise;
10
+ var hasRequiredCanPromise;
11
+
12
+ function requireCanPromise () {
13
+ if (hasRequiredCanPromise) return canPromise;
14
+ hasRequiredCanPromise = 1;
15
+ // can-promise has a crash in some versions of react native that dont have
16
+ // standard global objects
17
+ // https://github.com/soldair/node-qrcode/issues/157
18
+
19
+ canPromise = function () {
20
+ return typeof Promise === 'function' && Promise.prototype && Promise.prototype.then
21
+ };
22
+ return canPromise;
23
+ }
24
+
25
+ var qrcode = {};
26
+
27
+ var utils$1 = {};
28
+
29
+ var hasRequiredUtils$1;
30
+
31
+ function requireUtils$1 () {
32
+ if (hasRequiredUtils$1) return utils$1;
33
+ hasRequiredUtils$1 = 1;
34
+ let toSJISFunction;
35
+ const CODEWORDS_COUNT = [
36
+ 0, // Not used
37
+ 26, 44, 70, 100, 134, 172, 196, 242, 292, 346,
38
+ 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085,
39
+ 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185,
40
+ 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706
41
+ ];
42
+
43
+ /**
44
+ * Returns the QR Code size for the specified version
45
+ *
46
+ * @param {Number} version QR Code version
47
+ * @return {Number} size of QR code
48
+ */
49
+ utils$1.getSymbolSize = function getSymbolSize (version) {
50
+ if (!version) throw new Error('"version" cannot be null or undefined')
51
+ if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40')
52
+ return version * 4 + 17
53
+ };
54
+
55
+ /**
56
+ * Returns the total number of codewords used to store data and EC information.
57
+ *
58
+ * @param {Number} version QR Code version
59
+ * @return {Number} Data length in bits
60
+ */
61
+ utils$1.getSymbolTotalCodewords = function getSymbolTotalCodewords (version) {
62
+ return CODEWORDS_COUNT[version]
63
+ };
64
+
65
+ /**
66
+ * Encode data with Bose-Chaudhuri-Hocquenghem
67
+ *
68
+ * @param {Number} data Value to encode
69
+ * @return {Number} Encoded value
70
+ */
71
+ utils$1.getBCHDigit = function (data) {
72
+ let digit = 0;
73
+
74
+ while (data !== 0) {
75
+ digit++;
76
+ data >>>= 1;
77
+ }
78
+
79
+ return digit
80
+ };
81
+
82
+ utils$1.setToSJISFunction = function setToSJISFunction (f) {
83
+ if (typeof f !== 'function') {
84
+ throw new Error('"toSJISFunc" is not a valid function.')
85
+ }
86
+
87
+ toSJISFunction = f;
88
+ };
89
+
90
+ utils$1.isKanjiModeEnabled = function () {
91
+ return typeof toSJISFunction !== 'undefined'
92
+ };
93
+
94
+ utils$1.toSJIS = function toSJIS (kanji) {
95
+ return toSJISFunction(kanji)
96
+ };
97
+ return utils$1;
98
+ }
99
+
100
+ var errorCorrectionLevel = {};
101
+
102
+ var hasRequiredErrorCorrectionLevel;
103
+
104
+ function requireErrorCorrectionLevel () {
105
+ if (hasRequiredErrorCorrectionLevel) return errorCorrectionLevel;
106
+ hasRequiredErrorCorrectionLevel = 1;
107
+ (function (exports) {
108
+ exports.L = { bit: 1 };
109
+ exports.M = { bit: 0 };
110
+ exports.Q = { bit: 3 };
111
+ exports.H = { bit: 2 };
112
+
113
+ function fromString (string) {
114
+ if (typeof string !== 'string') {
115
+ throw new Error('Param is not a string')
116
+ }
117
+
118
+ const lcStr = string.toLowerCase();
119
+
120
+ switch (lcStr) {
121
+ case 'l':
122
+ case 'low':
123
+ return exports.L
124
+
125
+ case 'm':
126
+ case 'medium':
127
+ return exports.M
128
+
129
+ case 'q':
130
+ case 'quartile':
131
+ return exports.Q
132
+
133
+ case 'h':
134
+ case 'high':
135
+ return exports.H
136
+
137
+ default:
138
+ throw new Error('Unknown EC Level: ' + string)
139
+ }
140
+ }
141
+
142
+ exports.isValid = function isValid (level) {
143
+ return level && typeof level.bit !== 'undefined' &&
144
+ level.bit >= 0 && level.bit < 4
145
+ };
146
+
147
+ exports.from = function from (value, defaultValue) {
148
+ if (exports.isValid(value)) {
149
+ return value
150
+ }
151
+
152
+ try {
153
+ return fromString(value)
154
+ } catch (e) {
155
+ return defaultValue
156
+ }
157
+ };
158
+ } (errorCorrectionLevel));
159
+ return errorCorrectionLevel;
160
+ }
161
+
162
+ var bitBuffer;
163
+ var hasRequiredBitBuffer;
164
+
165
+ function requireBitBuffer () {
166
+ if (hasRequiredBitBuffer) return bitBuffer;
167
+ hasRequiredBitBuffer = 1;
168
+ function BitBuffer () {
169
+ this.buffer = [];
170
+ this.length = 0;
171
+ }
172
+
173
+ BitBuffer.prototype = {
174
+
175
+ get: function (index) {
176
+ const bufIndex = Math.floor(index / 8);
177
+ return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1
178
+ },
179
+
180
+ put: function (num, length) {
181
+ for (let i = 0; i < length; i++) {
182
+ this.putBit(((num >>> (length - i - 1)) & 1) === 1);
183
+ }
184
+ },
185
+
186
+ getLengthInBits: function () {
187
+ return this.length
188
+ },
189
+
190
+ putBit: function (bit) {
191
+ const bufIndex = Math.floor(this.length / 8);
192
+ if (this.buffer.length <= bufIndex) {
193
+ this.buffer.push(0);
194
+ }
195
+
196
+ if (bit) {
197
+ this.buffer[bufIndex] |= (0x80 >>> (this.length % 8));
198
+ }
199
+
200
+ this.length++;
201
+ }
202
+ };
203
+
204
+ bitBuffer = BitBuffer;
205
+ return bitBuffer;
206
+ }
207
+
208
+ /**
209
+ * Helper class to handle QR Code symbol modules
210
+ *
211
+ * @param {Number} size Symbol size
212
+ */
213
+
214
+ var bitMatrix;
215
+ var hasRequiredBitMatrix;
216
+
217
+ function requireBitMatrix () {
218
+ if (hasRequiredBitMatrix) return bitMatrix;
219
+ hasRequiredBitMatrix = 1;
220
+ function BitMatrix (size) {
221
+ if (!size || size < 1) {
222
+ throw new Error('BitMatrix size must be defined and greater than 0')
223
+ }
224
+
225
+ this.size = size;
226
+ this.data = new Uint8Array(size * size);
227
+ this.reservedBit = new Uint8Array(size * size);
228
+ }
229
+
230
+ /**
231
+ * Set bit value at specified location
232
+ * If reserved flag is set, this bit will be ignored during masking process
233
+ *
234
+ * @param {Number} row
235
+ * @param {Number} col
236
+ * @param {Boolean} value
237
+ * @param {Boolean} reserved
238
+ */
239
+ BitMatrix.prototype.set = function (row, col, value, reserved) {
240
+ const index = row * this.size + col;
241
+ this.data[index] = value;
242
+ if (reserved) this.reservedBit[index] = true;
243
+ };
244
+
245
+ /**
246
+ * Returns bit value at specified location
247
+ *
248
+ * @param {Number} row
249
+ * @param {Number} col
250
+ * @return {Boolean}
251
+ */
252
+ BitMatrix.prototype.get = function (row, col) {
253
+ return this.data[row * this.size + col]
254
+ };
255
+
256
+ /**
257
+ * Applies xor operator at specified location
258
+ * (used during masking process)
259
+ *
260
+ * @param {Number} row
261
+ * @param {Number} col
262
+ * @param {Boolean} value
263
+ */
264
+ BitMatrix.prototype.xor = function (row, col, value) {
265
+ this.data[row * this.size + col] ^= value;
266
+ };
267
+
268
+ /**
269
+ * Check if bit at specified location is reserved
270
+ *
271
+ * @param {Number} row
272
+ * @param {Number} col
273
+ * @return {Boolean}
274
+ */
275
+ BitMatrix.prototype.isReserved = function (row, col) {
276
+ return this.reservedBit[row * this.size + col]
277
+ };
278
+
279
+ bitMatrix = BitMatrix;
280
+ return bitMatrix;
281
+ }
282
+
283
+ var alignmentPattern = {};
284
+
285
+ /**
286
+ * Alignment pattern are fixed reference pattern in defined positions
287
+ * in a matrix symbology, which enables the decode software to re-synchronise
288
+ * the coordinate mapping of the image modules in the event of moderate amounts
289
+ * of distortion of the image.
290
+ *
291
+ * Alignment patterns are present only in QR Code symbols of version 2 or larger
292
+ * and their number depends on the symbol version.
293
+ */
294
+
295
+ var hasRequiredAlignmentPattern;
296
+
297
+ function requireAlignmentPattern () {
298
+ if (hasRequiredAlignmentPattern) return alignmentPattern;
299
+ hasRequiredAlignmentPattern = 1;
300
+ (function (exports) {
301
+ const getSymbolSize = requireUtils$1().getSymbolSize;
302
+
303
+ /**
304
+ * Calculate the row/column coordinates of the center module of each alignment pattern
305
+ * for the specified QR Code version.
306
+ *
307
+ * The alignment patterns are positioned symmetrically on either side of the diagonal
308
+ * running from the top left corner of the symbol to the bottom right corner.
309
+ *
310
+ * Since positions are simmetrical only half of the coordinates are returned.
311
+ * Each item of the array will represent in turn the x and y coordinate.
312
+ * @see {@link getPositions}
313
+ *
314
+ * @param {Number} version QR Code version
315
+ * @return {Array} Array of coordinate
316
+ */
317
+ exports.getRowColCoords = function getRowColCoords (version) {
318
+ if (version === 1) return []
319
+
320
+ const posCount = Math.floor(version / 7) + 2;
321
+ const size = getSymbolSize(version);
322
+ const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
323
+ const positions = [size - 7]; // Last coord is always (size - 7)
324
+
325
+ for (let i = 1; i < posCount - 1; i++) {
326
+ positions[i] = positions[i - 1] - intervals;
327
+ }
328
+
329
+ positions.push(6); // First coord is always 6
330
+
331
+ return positions.reverse()
332
+ };
333
+
334
+ /**
335
+ * Returns an array containing the positions of each alignment pattern.
336
+ * Each array's element represent the center point of the pattern as (x, y) coordinates
337
+ *
338
+ * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}
339
+ * and filtering out the items that overlaps with finder pattern
340
+ *
341
+ * @example
342
+ * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.
343
+ * The alignment patterns, therefore, are to be centered on (row, column)
344
+ * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).
345
+ * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns
346
+ * and are not therefore used for alignment patterns.
347
+ *
348
+ * let pos = getPositions(7)
349
+ * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]
350
+ *
351
+ * @param {Number} version QR Code version
352
+ * @return {Array} Array of coordinates
353
+ */
354
+ exports.getPositions = function getPositions (version) {
355
+ const coords = [];
356
+ const pos = exports.getRowColCoords(version);
357
+ const posLength = pos.length;
358
+
359
+ for (let i = 0; i < posLength; i++) {
360
+ for (let j = 0; j < posLength; j++) {
361
+ // Skip if position is occupied by finder patterns
362
+ if ((i === 0 && j === 0) || // top-left
363
+ (i === 0 && j === posLength - 1) || // bottom-left
364
+ (i === posLength - 1 && j === 0)) { // top-right
365
+ continue
366
+ }
367
+
368
+ coords.push([pos[i], pos[j]]);
369
+ }
370
+ }
371
+
372
+ return coords
373
+ };
374
+ } (alignmentPattern));
375
+ return alignmentPattern;
376
+ }
377
+
378
+ var finderPattern = {};
379
+
380
+ var hasRequiredFinderPattern;
381
+
382
+ function requireFinderPattern () {
383
+ if (hasRequiredFinderPattern) return finderPattern;
384
+ hasRequiredFinderPattern = 1;
385
+ const getSymbolSize = requireUtils$1().getSymbolSize;
386
+ const FINDER_PATTERN_SIZE = 7;
387
+
388
+ /**
389
+ * Returns an array containing the positions of each finder pattern.
390
+ * Each array's element represent the top-left point of the pattern as (x, y) coordinates
391
+ *
392
+ * @param {Number} version QR Code version
393
+ * @return {Array} Array of coordinates
394
+ */
395
+ finderPattern.getPositions = function getPositions (version) {
396
+ const size = getSymbolSize(version);
397
+
398
+ return [
399
+ // top-left
400
+ [0, 0],
401
+ // top-right
402
+ [size - FINDER_PATTERN_SIZE, 0],
403
+ // bottom-left
404
+ [0, size - FINDER_PATTERN_SIZE]
405
+ ]
406
+ };
407
+ return finderPattern;
408
+ }
409
+
410
+ var maskPattern = {};
411
+
412
+ /**
413
+ * Data mask pattern reference
414
+ * @type {Object}
415
+ */
416
+
417
+ var hasRequiredMaskPattern;
418
+
419
+ function requireMaskPattern () {
420
+ if (hasRequiredMaskPattern) return maskPattern;
421
+ hasRequiredMaskPattern = 1;
422
+ (function (exports) {
423
+ exports.Patterns = {
424
+ PATTERN000: 0,
425
+ PATTERN001: 1,
426
+ PATTERN010: 2,
427
+ PATTERN011: 3,
428
+ PATTERN100: 4,
429
+ PATTERN101: 5,
430
+ PATTERN110: 6,
431
+ PATTERN111: 7
432
+ };
433
+
434
+ /**
435
+ * Weighted penalty scores for the undesirable features
436
+ * @type {Object}
437
+ */
438
+ const PenaltyScores = {
439
+ N1: 3,
440
+ N2: 3,
441
+ N3: 40,
442
+ N4: 10
443
+ };
444
+
445
+ /**
446
+ * Check if mask pattern value is valid
447
+ *
448
+ * @param {Number} mask Mask pattern
449
+ * @return {Boolean} true if valid, false otherwise
450
+ */
451
+ exports.isValid = function isValid (mask) {
452
+ return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7
453
+ };
454
+
455
+ /**
456
+ * Returns mask pattern from a value.
457
+ * If value is not valid, returns undefined
458
+ *
459
+ * @param {Number|String} value Mask pattern value
460
+ * @return {Number} Valid mask pattern or undefined
461
+ */
462
+ exports.from = function from (value) {
463
+ return exports.isValid(value) ? parseInt(value, 10) : undefined
464
+ };
465
+
466
+ /**
467
+ * Find adjacent modules in row/column with the same color
468
+ * and assign a penalty value.
469
+ *
470
+ * Points: N1 + i
471
+ * i is the amount by which the number of adjacent modules of the same color exceeds 5
472
+ */
473
+ exports.getPenaltyN1 = function getPenaltyN1 (data) {
474
+ const size = data.size;
475
+ let points = 0;
476
+ let sameCountCol = 0;
477
+ let sameCountRow = 0;
478
+ let lastCol = null;
479
+ let lastRow = null;
480
+
481
+ for (let row = 0; row < size; row++) {
482
+ sameCountCol = sameCountRow = 0;
483
+ lastCol = lastRow = null;
484
+
485
+ for (let col = 0; col < size; col++) {
486
+ let module = data.get(row, col);
487
+ if (module === lastCol) {
488
+ sameCountCol++;
489
+ } else {
490
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
491
+ lastCol = module;
492
+ sameCountCol = 1;
493
+ }
494
+
495
+ module = data.get(col, row);
496
+ if (module === lastRow) {
497
+ sameCountRow++;
498
+ } else {
499
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
500
+ lastRow = module;
501
+ sameCountRow = 1;
502
+ }
503
+ }
504
+
505
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
506
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
507
+ }
508
+
509
+ return points
510
+ };
511
+
512
+ /**
513
+ * Find 2x2 blocks with the same color and assign a penalty value
514
+ *
515
+ * Points: N2 * (m - 1) * (n - 1)
516
+ */
517
+ exports.getPenaltyN2 = function getPenaltyN2 (data) {
518
+ const size = data.size;
519
+ let points = 0;
520
+
521
+ for (let row = 0; row < size - 1; row++) {
522
+ for (let col = 0; col < size - 1; col++) {
523
+ const last = data.get(row, col) +
524
+ data.get(row, col + 1) +
525
+ data.get(row + 1, col) +
526
+ data.get(row + 1, col + 1);
527
+
528
+ if (last === 4 || last === 0) points++;
529
+ }
530
+ }
531
+
532
+ return points * PenaltyScores.N2
533
+ };
534
+
535
+ /**
536
+ * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,
537
+ * preceded or followed by light area 4 modules wide
538
+ *
539
+ * Points: N3 * number of pattern found
540
+ */
541
+ exports.getPenaltyN3 = function getPenaltyN3 (data) {
542
+ const size = data.size;
543
+ let points = 0;
544
+ let bitsCol = 0;
545
+ let bitsRow = 0;
546
+
547
+ for (let row = 0; row < size; row++) {
548
+ bitsCol = bitsRow = 0;
549
+ for (let col = 0; col < size; col++) {
550
+ bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col);
551
+ if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++;
552
+
553
+ bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row);
554
+ if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++;
555
+ }
556
+ }
557
+
558
+ return points * PenaltyScores.N3
559
+ };
560
+
561
+ /**
562
+ * Calculate proportion of dark modules in entire symbol
563
+ *
564
+ * Points: N4 * k
565
+ *
566
+ * k is the rating of the deviation of the proportion of dark modules
567
+ * in the symbol from 50% in steps of 5%
568
+ */
569
+ exports.getPenaltyN4 = function getPenaltyN4 (data) {
570
+ let darkCount = 0;
571
+ const modulesCount = data.data.length;
572
+
573
+ for (let i = 0; i < modulesCount; i++) darkCount += data.data[i];
574
+
575
+ const k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10);
576
+
577
+ return k * PenaltyScores.N4
578
+ };
579
+
580
+ /**
581
+ * Return mask value at given position
582
+ *
583
+ * @param {Number} maskPattern Pattern reference value
584
+ * @param {Number} i Row
585
+ * @param {Number} j Column
586
+ * @return {Boolean} Mask value
587
+ */
588
+ function getMaskAt (maskPattern, i, j) {
589
+ switch (maskPattern) {
590
+ case exports.Patterns.PATTERN000: return (i + j) % 2 === 0
591
+ case exports.Patterns.PATTERN001: return i % 2 === 0
592
+ case exports.Patterns.PATTERN010: return j % 3 === 0
593
+ case exports.Patterns.PATTERN011: return (i + j) % 3 === 0
594
+ case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0
595
+ case exports.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0
596
+ case exports.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0
597
+ case exports.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0
598
+
599
+ default: throw new Error('bad maskPattern:' + maskPattern)
600
+ }
601
+ }
602
+
603
+ /**
604
+ * Apply a mask pattern to a BitMatrix
605
+ *
606
+ * @param {Number} pattern Pattern reference number
607
+ * @param {BitMatrix} data BitMatrix data
608
+ */
609
+ exports.applyMask = function applyMask (pattern, data) {
610
+ const size = data.size;
611
+
612
+ for (let col = 0; col < size; col++) {
613
+ for (let row = 0; row < size; row++) {
614
+ if (data.isReserved(row, col)) continue
615
+ data.xor(row, col, getMaskAt(pattern, row, col));
616
+ }
617
+ }
618
+ };
619
+
620
+ /**
621
+ * Returns the best mask pattern for data
622
+ *
623
+ * @param {BitMatrix} data
624
+ * @return {Number} Mask pattern reference number
625
+ */
626
+ exports.getBestMask = function getBestMask (data, setupFormatFunc) {
627
+ const numPatterns = Object.keys(exports.Patterns).length;
628
+ let bestPattern = 0;
629
+ let lowerPenalty = Infinity;
630
+
631
+ for (let p = 0; p < numPatterns; p++) {
632
+ setupFormatFunc(p);
633
+ exports.applyMask(p, data);
634
+
635
+ // Calculate penalty
636
+ const penalty =
637
+ exports.getPenaltyN1(data) +
638
+ exports.getPenaltyN2(data) +
639
+ exports.getPenaltyN3(data) +
640
+ exports.getPenaltyN4(data);
641
+
642
+ // Undo previously applied mask
643
+ exports.applyMask(p, data);
644
+
645
+ if (penalty < lowerPenalty) {
646
+ lowerPenalty = penalty;
647
+ bestPattern = p;
648
+ }
649
+ }
650
+
651
+ return bestPattern
652
+ };
653
+ } (maskPattern));
654
+ return maskPattern;
655
+ }
656
+
657
+ var errorCorrectionCode = {};
658
+
659
+ var hasRequiredErrorCorrectionCode;
660
+
661
+ function requireErrorCorrectionCode () {
662
+ if (hasRequiredErrorCorrectionCode) return errorCorrectionCode;
663
+ hasRequiredErrorCorrectionCode = 1;
664
+ const ECLevel = requireErrorCorrectionLevel();
665
+
666
+ const EC_BLOCKS_TABLE = [
667
+ // L M Q H
668
+ 1, 1, 1, 1,
669
+ 1, 1, 1, 1,
670
+ 1, 1, 2, 2,
671
+ 1, 2, 2, 4,
672
+ 1, 2, 4, 4,
673
+ 2, 4, 4, 4,
674
+ 2, 4, 6, 5,
675
+ 2, 4, 6, 6,
676
+ 2, 5, 8, 8,
677
+ 4, 5, 8, 8,
678
+ 4, 5, 8, 11,
679
+ 4, 8, 10, 11,
680
+ 4, 9, 12, 16,
681
+ 4, 9, 16, 16,
682
+ 6, 10, 12, 18,
683
+ 6, 10, 17, 16,
684
+ 6, 11, 16, 19,
685
+ 6, 13, 18, 21,
686
+ 7, 14, 21, 25,
687
+ 8, 16, 20, 25,
688
+ 8, 17, 23, 25,
689
+ 9, 17, 23, 34,
690
+ 9, 18, 25, 30,
691
+ 10, 20, 27, 32,
692
+ 12, 21, 29, 35,
693
+ 12, 23, 34, 37,
694
+ 12, 25, 34, 40,
695
+ 13, 26, 35, 42,
696
+ 14, 28, 38, 45,
697
+ 15, 29, 40, 48,
698
+ 16, 31, 43, 51,
699
+ 17, 33, 45, 54,
700
+ 18, 35, 48, 57,
701
+ 19, 37, 51, 60,
702
+ 19, 38, 53, 63,
703
+ 20, 40, 56, 66,
704
+ 21, 43, 59, 70,
705
+ 22, 45, 62, 74,
706
+ 24, 47, 65, 77,
707
+ 25, 49, 68, 81
708
+ ];
709
+
710
+ const EC_CODEWORDS_TABLE = [
711
+ // L M Q H
712
+ 7, 10, 13, 17,
713
+ 10, 16, 22, 28,
714
+ 15, 26, 36, 44,
715
+ 20, 36, 52, 64,
716
+ 26, 48, 72, 88,
717
+ 36, 64, 96, 112,
718
+ 40, 72, 108, 130,
719
+ 48, 88, 132, 156,
720
+ 60, 110, 160, 192,
721
+ 72, 130, 192, 224,
722
+ 80, 150, 224, 264,
723
+ 96, 176, 260, 308,
724
+ 104, 198, 288, 352,
725
+ 120, 216, 320, 384,
726
+ 132, 240, 360, 432,
727
+ 144, 280, 408, 480,
728
+ 168, 308, 448, 532,
729
+ 180, 338, 504, 588,
730
+ 196, 364, 546, 650,
731
+ 224, 416, 600, 700,
732
+ 224, 442, 644, 750,
733
+ 252, 476, 690, 816,
734
+ 270, 504, 750, 900,
735
+ 300, 560, 810, 960,
736
+ 312, 588, 870, 1050,
737
+ 336, 644, 952, 1110,
738
+ 360, 700, 1020, 1200,
739
+ 390, 728, 1050, 1260,
740
+ 420, 784, 1140, 1350,
741
+ 450, 812, 1200, 1440,
742
+ 480, 868, 1290, 1530,
743
+ 510, 924, 1350, 1620,
744
+ 540, 980, 1440, 1710,
745
+ 570, 1036, 1530, 1800,
746
+ 570, 1064, 1590, 1890,
747
+ 600, 1120, 1680, 1980,
748
+ 630, 1204, 1770, 2100,
749
+ 660, 1260, 1860, 2220,
750
+ 720, 1316, 1950, 2310,
751
+ 750, 1372, 2040, 2430
752
+ ];
753
+
754
+ /**
755
+ * Returns the number of error correction block that the QR Code should contain
756
+ * for the specified version and error correction level.
757
+ *
758
+ * @param {Number} version QR Code version
759
+ * @param {Number} errorCorrectionLevel Error correction level
760
+ * @return {Number} Number of error correction blocks
761
+ */
762
+ errorCorrectionCode.getBlocksCount = function getBlocksCount (version, errorCorrectionLevel) {
763
+ switch (errorCorrectionLevel) {
764
+ case ECLevel.L:
765
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 0]
766
+ case ECLevel.M:
767
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 1]
768
+ case ECLevel.Q:
769
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 2]
770
+ case ECLevel.H:
771
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 3]
772
+ default:
773
+ return undefined
774
+ }
775
+ };
776
+
777
+ /**
778
+ * Returns the number of error correction codewords to use for the specified
779
+ * version and error correction level.
780
+ *
781
+ * @param {Number} version QR Code version
782
+ * @param {Number} errorCorrectionLevel Error correction level
783
+ * @return {Number} Number of error correction codewords
784
+ */
785
+ errorCorrectionCode.getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel) {
786
+ switch (errorCorrectionLevel) {
787
+ case ECLevel.L:
788
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0]
789
+ case ECLevel.M:
790
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1]
791
+ case ECLevel.Q:
792
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2]
793
+ case ECLevel.H:
794
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3]
795
+ default:
796
+ return undefined
797
+ }
798
+ };
799
+ return errorCorrectionCode;
800
+ }
801
+
802
+ var polynomial = {};
803
+
804
+ var galoisField = {};
805
+
806
+ var hasRequiredGaloisField;
807
+
808
+ function requireGaloisField () {
809
+ if (hasRequiredGaloisField) return galoisField;
810
+ hasRequiredGaloisField = 1;
811
+ const EXP_TABLE = new Uint8Array(512);
812
+ const LOG_TABLE = new Uint8Array(256)
813
+ /**
814
+ * Precompute the log and anti-log tables for faster computation later
815
+ *
816
+ * For each possible value in the galois field 2^8, we will pre-compute
817
+ * the logarithm and anti-logarithm (exponential) of this value
818
+ *
819
+ * ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields}
820
+ */
821
+ ;(function initTables () {
822
+ let x = 1;
823
+ for (let i = 0; i < 255; i++) {
824
+ EXP_TABLE[i] = x;
825
+ LOG_TABLE[x] = i;
826
+
827
+ x <<= 1; // multiply by 2
828
+
829
+ // The QR code specification says to use byte-wise modulo 100011101 arithmetic.
830
+ // This means that when a number is 256 or larger, it should be XORed with 0x11D.
831
+ if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256)
832
+ x ^= 0x11D;
833
+ }
834
+ }
835
+
836
+ // Optimization: double the size of the anti-log table so that we don't need to mod 255 to
837
+ // stay inside the bounds (because we will mainly use this table for the multiplication of
838
+ // two GF numbers, no more).
839
+ // @see {@link mul}
840
+ for (let i = 255; i < 512; i++) {
841
+ EXP_TABLE[i] = EXP_TABLE[i - 255];
842
+ }
843
+ }());
844
+
845
+ /**
846
+ * Returns log value of n inside Galois Field
847
+ *
848
+ * @param {Number} n
849
+ * @return {Number}
850
+ */
851
+ galoisField.log = function log (n) {
852
+ if (n < 1) throw new Error('log(' + n + ')')
853
+ return LOG_TABLE[n]
854
+ };
855
+
856
+ /**
857
+ * Returns anti-log value of n inside Galois Field
858
+ *
859
+ * @param {Number} n
860
+ * @return {Number}
861
+ */
862
+ galoisField.exp = function exp (n) {
863
+ return EXP_TABLE[n]
864
+ };
865
+
866
+ /**
867
+ * Multiplies two number inside Galois Field
868
+ *
869
+ * @param {Number} x
870
+ * @param {Number} y
871
+ * @return {Number}
872
+ */
873
+ galoisField.mul = function mul (x, y) {
874
+ if (x === 0 || y === 0) return 0
875
+
876
+ // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized
877
+ // @see {@link initTables}
878
+ return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]]
879
+ };
880
+ return galoisField;
881
+ }
882
+
883
+ var hasRequiredPolynomial;
884
+
885
+ function requirePolynomial () {
886
+ if (hasRequiredPolynomial) return polynomial;
887
+ hasRequiredPolynomial = 1;
888
+ (function (exports) {
889
+ const GF = requireGaloisField();
890
+
891
+ /**
892
+ * Multiplies two polynomials inside Galois Field
893
+ *
894
+ * @param {Uint8Array} p1 Polynomial
895
+ * @param {Uint8Array} p2 Polynomial
896
+ * @return {Uint8Array} Product of p1 and p2
897
+ */
898
+ exports.mul = function mul (p1, p2) {
899
+ const coeff = new Uint8Array(p1.length + p2.length - 1);
900
+
901
+ for (let i = 0; i < p1.length; i++) {
902
+ for (let j = 0; j < p2.length; j++) {
903
+ coeff[i + j] ^= GF.mul(p1[i], p2[j]);
904
+ }
905
+ }
906
+
907
+ return coeff
908
+ };
909
+
910
+ /**
911
+ * Calculate the remainder of polynomials division
912
+ *
913
+ * @param {Uint8Array} divident Polynomial
914
+ * @param {Uint8Array} divisor Polynomial
915
+ * @return {Uint8Array} Remainder
916
+ */
917
+ exports.mod = function mod (divident, divisor) {
918
+ let result = new Uint8Array(divident);
919
+
920
+ while ((result.length - divisor.length) >= 0) {
921
+ const coeff = result[0];
922
+
923
+ for (let i = 0; i < divisor.length; i++) {
924
+ result[i] ^= GF.mul(divisor[i], coeff);
925
+ }
926
+
927
+ // remove all zeros from buffer head
928
+ let offset = 0;
929
+ while (offset < result.length && result[offset] === 0) offset++;
930
+ result = result.slice(offset);
931
+ }
932
+
933
+ return result
934
+ };
935
+
936
+ /**
937
+ * Generate an irreducible generator polynomial of specified degree
938
+ * (used by Reed-Solomon encoder)
939
+ *
940
+ * @param {Number} degree Degree of the generator polynomial
941
+ * @return {Uint8Array} Buffer containing polynomial coefficients
942
+ */
943
+ exports.generateECPolynomial = function generateECPolynomial (degree) {
944
+ let poly = new Uint8Array([1]);
945
+ for (let i = 0; i < degree; i++) {
946
+ poly = exports.mul(poly, new Uint8Array([1, GF.exp(i)]));
947
+ }
948
+
949
+ return poly
950
+ };
951
+ } (polynomial));
952
+ return polynomial;
953
+ }
954
+
955
+ var reedSolomonEncoder;
956
+ var hasRequiredReedSolomonEncoder;
957
+
958
+ function requireReedSolomonEncoder () {
959
+ if (hasRequiredReedSolomonEncoder) return reedSolomonEncoder;
960
+ hasRequiredReedSolomonEncoder = 1;
961
+ const Polynomial = requirePolynomial();
962
+
963
+ function ReedSolomonEncoder (degree) {
964
+ this.genPoly = undefined;
965
+ this.degree = degree;
966
+
967
+ if (this.degree) this.initialize(this.degree);
968
+ }
969
+
970
+ /**
971
+ * Initialize the encoder.
972
+ * The input param should correspond to the number of error correction codewords.
973
+ *
974
+ * @param {Number} degree
975
+ */
976
+ ReedSolomonEncoder.prototype.initialize = function initialize (degree) {
977
+ // create an irreducible generator polynomial
978
+ this.degree = degree;
979
+ this.genPoly = Polynomial.generateECPolynomial(this.degree);
980
+ };
981
+
982
+ /**
983
+ * Encodes a chunk of data
984
+ *
985
+ * @param {Uint8Array} data Buffer containing input data
986
+ * @return {Uint8Array} Buffer containing encoded data
987
+ */
988
+ ReedSolomonEncoder.prototype.encode = function encode (data) {
989
+ if (!this.genPoly) {
990
+ throw new Error('Encoder not initialized')
991
+ }
992
+
993
+ // Calculate EC for this data block
994
+ // extends data size to data+genPoly size
995
+ const paddedData = new Uint8Array(data.length + this.degree);
996
+ paddedData.set(data);
997
+
998
+ // The error correction codewords are the remainder after dividing the data codewords
999
+ // by a generator polynomial
1000
+ const remainder = Polynomial.mod(paddedData, this.genPoly);
1001
+
1002
+ // return EC data blocks (last n byte, where n is the degree of genPoly)
1003
+ // If coefficients number in remainder are less than genPoly degree,
1004
+ // pad with 0s to the left to reach the needed number of coefficients
1005
+ const start = this.degree - remainder.length;
1006
+ if (start > 0) {
1007
+ const buff = new Uint8Array(this.degree);
1008
+ buff.set(remainder, start);
1009
+
1010
+ return buff
1011
+ }
1012
+
1013
+ return remainder
1014
+ };
1015
+
1016
+ reedSolomonEncoder = ReedSolomonEncoder;
1017
+ return reedSolomonEncoder;
1018
+ }
1019
+
1020
+ var version = {};
1021
+
1022
+ var mode = {};
1023
+
1024
+ var versionCheck = {};
1025
+
1026
+ /**
1027
+ * Check if QR Code version is valid
1028
+ *
1029
+ * @param {Number} version QR Code version
1030
+ * @return {Boolean} true if valid version, false otherwise
1031
+ */
1032
+
1033
+ var hasRequiredVersionCheck;
1034
+
1035
+ function requireVersionCheck () {
1036
+ if (hasRequiredVersionCheck) return versionCheck;
1037
+ hasRequiredVersionCheck = 1;
1038
+ versionCheck.isValid = function isValid (version) {
1039
+ return !isNaN(version) && version >= 1 && version <= 40
1040
+ };
1041
+ return versionCheck;
1042
+ }
1043
+
1044
+ var regex = {};
1045
+
1046
+ var hasRequiredRegex;
1047
+
1048
+ function requireRegex () {
1049
+ if (hasRequiredRegex) return regex;
1050
+ hasRequiredRegex = 1;
1051
+ const numeric = '[0-9]+';
1052
+ const alphanumeric = '[A-Z $%*+\\-./:]+';
1053
+ let kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' +
1054
+ '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' +
1055
+ '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' +
1056
+ '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+';
1057
+ kanji = kanji.replace(/u/g, '\\u');
1058
+
1059
+ const byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+';
1060
+
1061
+ regex.KANJI = new RegExp(kanji, 'g');
1062
+ regex.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g');
1063
+ regex.BYTE = new RegExp(byte, 'g');
1064
+ regex.NUMERIC = new RegExp(numeric, 'g');
1065
+ regex.ALPHANUMERIC = new RegExp(alphanumeric, 'g');
1066
+
1067
+ const TEST_KANJI = new RegExp('^' + kanji + '$');
1068
+ const TEST_NUMERIC = new RegExp('^' + numeric + '$');
1069
+ const TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$');
1070
+
1071
+ regex.testKanji = function testKanji (str) {
1072
+ return TEST_KANJI.test(str)
1073
+ };
1074
+
1075
+ regex.testNumeric = function testNumeric (str) {
1076
+ return TEST_NUMERIC.test(str)
1077
+ };
1078
+
1079
+ regex.testAlphanumeric = function testAlphanumeric (str) {
1080
+ return TEST_ALPHANUMERIC.test(str)
1081
+ };
1082
+ return regex;
1083
+ }
1084
+
1085
+ var hasRequiredMode;
1086
+
1087
+ function requireMode () {
1088
+ if (hasRequiredMode) return mode;
1089
+ hasRequiredMode = 1;
1090
+ (function (exports) {
1091
+ const VersionCheck = requireVersionCheck();
1092
+ const Regex = requireRegex();
1093
+
1094
+ /**
1095
+ * Numeric mode encodes data from the decimal digit set (0 - 9)
1096
+ * (byte values 30HEX to 39HEX).
1097
+ * Normally, 3 data characters are represented by 10 bits.
1098
+ *
1099
+ * @type {Object}
1100
+ */
1101
+ exports.NUMERIC = {
1102
+ id: 'Numeric',
1103
+ bit: 1 << 0,
1104
+ ccBits: [10, 12, 14]
1105
+ };
1106
+
1107
+ /**
1108
+ * Alphanumeric mode encodes data from a set of 45 characters,
1109
+ * i.e. 10 numeric digits (0 - 9),
1110
+ * 26 alphabetic characters (A - Z),
1111
+ * and 9 symbols (SP, $, %, *, +, -, ., /, :).
1112
+ * Normally, two input characters are represented by 11 bits.
1113
+ *
1114
+ * @type {Object}
1115
+ */
1116
+ exports.ALPHANUMERIC = {
1117
+ id: 'Alphanumeric',
1118
+ bit: 1 << 1,
1119
+ ccBits: [9, 11, 13]
1120
+ };
1121
+
1122
+ /**
1123
+ * In byte mode, data is encoded at 8 bits per character.
1124
+ *
1125
+ * @type {Object}
1126
+ */
1127
+ exports.BYTE = {
1128
+ id: 'Byte',
1129
+ bit: 1 << 2,
1130
+ ccBits: [8, 16, 16]
1131
+ };
1132
+
1133
+ /**
1134
+ * The Kanji mode efficiently encodes Kanji characters in accordance with
1135
+ * the Shift JIS system based on JIS X 0208.
1136
+ * The Shift JIS values are shifted from the JIS X 0208 values.
1137
+ * JIS X 0208 gives details of the shift coded representation.
1138
+ * Each two-byte character value is compacted to a 13-bit binary codeword.
1139
+ *
1140
+ * @type {Object}
1141
+ */
1142
+ exports.KANJI = {
1143
+ id: 'Kanji',
1144
+ bit: 1 << 3,
1145
+ ccBits: [8, 10, 12]
1146
+ };
1147
+
1148
+ /**
1149
+ * Mixed mode will contain a sequences of data in a combination of any of
1150
+ * the modes described above
1151
+ *
1152
+ * @type {Object}
1153
+ */
1154
+ exports.MIXED = {
1155
+ bit: -1
1156
+ };
1157
+
1158
+ /**
1159
+ * Returns the number of bits needed to store the data length
1160
+ * according to QR Code specifications.
1161
+ *
1162
+ * @param {Mode} mode Data mode
1163
+ * @param {Number} version QR Code version
1164
+ * @return {Number} Number of bits
1165
+ */
1166
+ exports.getCharCountIndicator = function getCharCountIndicator (mode, version) {
1167
+ if (!mode.ccBits) throw new Error('Invalid mode: ' + mode)
1168
+
1169
+ if (!VersionCheck.isValid(version)) {
1170
+ throw new Error('Invalid version: ' + version)
1171
+ }
1172
+
1173
+ if (version >= 1 && version < 10) return mode.ccBits[0]
1174
+ else if (version < 27) return mode.ccBits[1]
1175
+ return mode.ccBits[2]
1176
+ };
1177
+
1178
+ /**
1179
+ * Returns the most efficient mode to store the specified data
1180
+ *
1181
+ * @param {String} dataStr Input data string
1182
+ * @return {Mode} Best mode
1183
+ */
1184
+ exports.getBestModeForData = function getBestModeForData (dataStr) {
1185
+ if (Regex.testNumeric(dataStr)) return exports.NUMERIC
1186
+ else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC
1187
+ else if (Regex.testKanji(dataStr)) return exports.KANJI
1188
+ else return exports.BYTE
1189
+ };
1190
+
1191
+ /**
1192
+ * Return mode name as string
1193
+ *
1194
+ * @param {Mode} mode Mode object
1195
+ * @returns {String} Mode name
1196
+ */
1197
+ exports.toString = function toString (mode) {
1198
+ if (mode && mode.id) return mode.id
1199
+ throw new Error('Invalid mode')
1200
+ };
1201
+
1202
+ /**
1203
+ * Check if input param is a valid mode object
1204
+ *
1205
+ * @param {Mode} mode Mode object
1206
+ * @returns {Boolean} True if valid mode, false otherwise
1207
+ */
1208
+ exports.isValid = function isValid (mode) {
1209
+ return mode && mode.bit && mode.ccBits
1210
+ };
1211
+
1212
+ /**
1213
+ * Get mode object from its name
1214
+ *
1215
+ * @param {String} string Mode name
1216
+ * @returns {Mode} Mode object
1217
+ */
1218
+ function fromString (string) {
1219
+ if (typeof string !== 'string') {
1220
+ throw new Error('Param is not a string')
1221
+ }
1222
+
1223
+ const lcStr = string.toLowerCase();
1224
+
1225
+ switch (lcStr) {
1226
+ case 'numeric':
1227
+ return exports.NUMERIC
1228
+ case 'alphanumeric':
1229
+ return exports.ALPHANUMERIC
1230
+ case 'kanji':
1231
+ return exports.KANJI
1232
+ case 'byte':
1233
+ return exports.BYTE
1234
+ default:
1235
+ throw new Error('Unknown mode: ' + string)
1236
+ }
1237
+ }
1238
+
1239
+ /**
1240
+ * Returns mode from a value.
1241
+ * If value is not a valid mode, returns defaultValue
1242
+ *
1243
+ * @param {Mode|String} value Encoding mode
1244
+ * @param {Mode} defaultValue Fallback value
1245
+ * @return {Mode} Encoding mode
1246
+ */
1247
+ exports.from = function from (value, defaultValue) {
1248
+ if (exports.isValid(value)) {
1249
+ return value
1250
+ }
1251
+
1252
+ try {
1253
+ return fromString(value)
1254
+ } catch (e) {
1255
+ return defaultValue
1256
+ }
1257
+ };
1258
+ } (mode));
1259
+ return mode;
1260
+ }
1261
+
1262
+ var hasRequiredVersion;
1263
+
1264
+ function requireVersion () {
1265
+ if (hasRequiredVersion) return version;
1266
+ hasRequiredVersion = 1;
1267
+ (function (exports) {
1268
+ const Utils = requireUtils$1();
1269
+ const ECCode = requireErrorCorrectionCode();
1270
+ const ECLevel = requireErrorCorrectionLevel();
1271
+ const Mode = requireMode();
1272
+ const VersionCheck = requireVersionCheck();
1273
+
1274
+ // Generator polynomial used to encode version information
1275
+ const G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0);
1276
+ const G18_BCH = Utils.getBCHDigit(G18);
1277
+
1278
+ function getBestVersionForDataLength (mode, length, errorCorrectionLevel) {
1279
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
1280
+ if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
1281
+ return currentVersion
1282
+ }
1283
+ }
1284
+
1285
+ return undefined
1286
+ }
1287
+
1288
+ function getReservedBitsCount (mode, version) {
1289
+ // Character count indicator + mode indicator bits
1290
+ return Mode.getCharCountIndicator(mode, version) + 4
1291
+ }
1292
+
1293
+ function getTotalBitsFromDataArray (segments, version) {
1294
+ let totalBits = 0;
1295
+
1296
+ segments.forEach(function (data) {
1297
+ const reservedBits = getReservedBitsCount(data.mode, version);
1298
+ totalBits += reservedBits + data.getBitsLength();
1299
+ });
1300
+
1301
+ return totalBits
1302
+ }
1303
+
1304
+ function getBestVersionForMixedData (segments, errorCorrectionLevel) {
1305
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
1306
+ const length = getTotalBitsFromDataArray(segments, currentVersion);
1307
+ if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
1308
+ return currentVersion
1309
+ }
1310
+ }
1311
+
1312
+ return undefined
1313
+ }
1314
+
1315
+ /**
1316
+ * Returns version number from a value.
1317
+ * If value is not a valid version, returns defaultValue
1318
+ *
1319
+ * @param {Number|String} value QR Code version
1320
+ * @param {Number} defaultValue Fallback value
1321
+ * @return {Number} QR Code version number
1322
+ */
1323
+ exports.from = function from (value, defaultValue) {
1324
+ if (VersionCheck.isValid(value)) {
1325
+ return parseInt(value, 10)
1326
+ }
1327
+
1328
+ return defaultValue
1329
+ };
1330
+
1331
+ /**
1332
+ * Returns how much data can be stored with the specified QR code version
1333
+ * and error correction level
1334
+ *
1335
+ * @param {Number} version QR Code version (1-40)
1336
+ * @param {Number} errorCorrectionLevel Error correction level
1337
+ * @param {Mode} mode Data mode
1338
+ * @return {Number} Quantity of storable data
1339
+ */
1340
+ exports.getCapacity = function getCapacity (version, errorCorrectionLevel, mode) {
1341
+ if (!VersionCheck.isValid(version)) {
1342
+ throw new Error('Invalid QR Code version')
1343
+ }
1344
+
1345
+ // Use Byte mode as default
1346
+ if (typeof mode === 'undefined') mode = Mode.BYTE;
1347
+
1348
+ // Total codewords for this QR code version (Data + Error correction)
1349
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
1350
+
1351
+ // Total number of error correction codewords
1352
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
1353
+
1354
+ // Total number of data codewords
1355
+ const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
1356
+
1357
+ if (mode === Mode.MIXED) return dataTotalCodewordsBits
1358
+
1359
+ const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version);
1360
+
1361
+ // Return max number of storable codewords
1362
+ switch (mode) {
1363
+ case Mode.NUMERIC:
1364
+ return Math.floor((usableBits / 10) * 3)
1365
+
1366
+ case Mode.ALPHANUMERIC:
1367
+ return Math.floor((usableBits / 11) * 2)
1368
+
1369
+ case Mode.KANJI:
1370
+ return Math.floor(usableBits / 13)
1371
+
1372
+ case Mode.BYTE:
1373
+ default:
1374
+ return Math.floor(usableBits / 8)
1375
+ }
1376
+ };
1377
+
1378
+ /**
1379
+ * Returns the minimum version needed to contain the amount of data
1380
+ *
1381
+ * @param {Segment} data Segment of data
1382
+ * @param {Number} [errorCorrectionLevel=H] Error correction level
1383
+ * @param {Mode} mode Data mode
1384
+ * @return {Number} QR Code version
1385
+ */
1386
+ exports.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel) {
1387
+ let seg;
1388
+
1389
+ const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M);
1390
+
1391
+ if (Array.isArray(data)) {
1392
+ if (data.length > 1) {
1393
+ return getBestVersionForMixedData(data, ecl)
1394
+ }
1395
+
1396
+ if (data.length === 0) {
1397
+ return 1
1398
+ }
1399
+
1400
+ seg = data[0];
1401
+ } else {
1402
+ seg = data;
1403
+ }
1404
+
1405
+ return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl)
1406
+ };
1407
+
1408
+ /**
1409
+ * Returns version information with relative error correction bits
1410
+ *
1411
+ * The version information is included in QR Code symbols of version 7 or larger.
1412
+ * It consists of an 18-bit sequence containing 6 data bits,
1413
+ * with 12 error correction bits calculated using the (18, 6) Golay code.
1414
+ *
1415
+ * @param {Number} version QR Code version
1416
+ * @return {Number} Encoded version info bits
1417
+ */
1418
+ exports.getEncodedBits = function getEncodedBits (version) {
1419
+ if (!VersionCheck.isValid(version) || version < 7) {
1420
+ throw new Error('Invalid QR Code version')
1421
+ }
1422
+
1423
+ let d = version << 12;
1424
+
1425
+ while (Utils.getBCHDigit(d) - G18_BCH >= 0) {
1426
+ d ^= (G18 << (Utils.getBCHDigit(d) - G18_BCH));
1427
+ }
1428
+
1429
+ return (version << 12) | d
1430
+ };
1431
+ } (version));
1432
+ return version;
1433
+ }
1434
+
1435
+ var formatInfo = {};
1436
+
1437
+ var hasRequiredFormatInfo;
1438
+
1439
+ function requireFormatInfo () {
1440
+ if (hasRequiredFormatInfo) return formatInfo;
1441
+ hasRequiredFormatInfo = 1;
1442
+ const Utils = requireUtils$1();
1443
+
1444
+ const G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0);
1445
+ const G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1);
1446
+ const G15_BCH = Utils.getBCHDigit(G15);
1447
+
1448
+ /**
1449
+ * Returns format information with relative error correction bits
1450
+ *
1451
+ * The format information is a 15-bit sequence containing 5 data bits,
1452
+ * with 10 error correction bits calculated using the (15, 5) BCH code.
1453
+ *
1454
+ * @param {Number} errorCorrectionLevel Error correction level
1455
+ * @param {Number} mask Mask pattern
1456
+ * @return {Number} Encoded format information bits
1457
+ */
1458
+ formatInfo.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) {
1459
+ const data = ((errorCorrectionLevel.bit << 3) | mask);
1460
+ let d = data << 10;
1461
+
1462
+ while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
1463
+ d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH));
1464
+ }
1465
+
1466
+ // xor final data with mask pattern in order to ensure that
1467
+ // no combination of Error Correction Level and data mask pattern
1468
+ // will result in an all-zero data string
1469
+ return ((data << 10) | d) ^ G15_MASK
1470
+ };
1471
+ return formatInfo;
1472
+ }
1473
+
1474
+ var segments = {};
1475
+
1476
+ var numericData;
1477
+ var hasRequiredNumericData;
1478
+
1479
+ function requireNumericData () {
1480
+ if (hasRequiredNumericData) return numericData;
1481
+ hasRequiredNumericData = 1;
1482
+ const Mode = requireMode();
1483
+
1484
+ function NumericData (data) {
1485
+ this.mode = Mode.NUMERIC;
1486
+ this.data = data.toString();
1487
+ }
1488
+
1489
+ NumericData.getBitsLength = function getBitsLength (length) {
1490
+ return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0)
1491
+ };
1492
+
1493
+ NumericData.prototype.getLength = function getLength () {
1494
+ return this.data.length
1495
+ };
1496
+
1497
+ NumericData.prototype.getBitsLength = function getBitsLength () {
1498
+ return NumericData.getBitsLength(this.data.length)
1499
+ };
1500
+
1501
+ NumericData.prototype.write = function write (bitBuffer) {
1502
+ let i, group, value;
1503
+
1504
+ // The input data string is divided into groups of three digits,
1505
+ // and each group is converted to its 10-bit binary equivalent.
1506
+ for (i = 0; i + 3 <= this.data.length; i += 3) {
1507
+ group = this.data.substr(i, 3);
1508
+ value = parseInt(group, 10);
1509
+
1510
+ bitBuffer.put(value, 10);
1511
+ }
1512
+
1513
+ // If the number of input digits is not an exact multiple of three,
1514
+ // the final one or two digits are converted to 4 or 7 bits respectively.
1515
+ const remainingNum = this.data.length - i;
1516
+ if (remainingNum > 0) {
1517
+ group = this.data.substr(i);
1518
+ value = parseInt(group, 10);
1519
+
1520
+ bitBuffer.put(value, remainingNum * 3 + 1);
1521
+ }
1522
+ };
1523
+
1524
+ numericData = NumericData;
1525
+ return numericData;
1526
+ }
1527
+
1528
+ var alphanumericData;
1529
+ var hasRequiredAlphanumericData;
1530
+
1531
+ function requireAlphanumericData () {
1532
+ if (hasRequiredAlphanumericData) return alphanumericData;
1533
+ hasRequiredAlphanumericData = 1;
1534
+ const Mode = requireMode();
1535
+
1536
+ /**
1537
+ * Array of characters available in alphanumeric mode
1538
+ *
1539
+ * As per QR Code specification, to each character
1540
+ * is assigned a value from 0 to 44 which in this case coincides
1541
+ * with the array index
1542
+ *
1543
+ * @type {Array}
1544
+ */
1545
+ const ALPHA_NUM_CHARS = [
1546
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
1547
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
1548
+ 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
1549
+ ' ', '$', '%', '*', '+', '-', '.', '/', ':'
1550
+ ];
1551
+
1552
+ function AlphanumericData (data) {
1553
+ this.mode = Mode.ALPHANUMERIC;
1554
+ this.data = data;
1555
+ }
1556
+
1557
+ AlphanumericData.getBitsLength = function getBitsLength (length) {
1558
+ return 11 * Math.floor(length / 2) + 6 * (length % 2)
1559
+ };
1560
+
1561
+ AlphanumericData.prototype.getLength = function getLength () {
1562
+ return this.data.length
1563
+ };
1564
+
1565
+ AlphanumericData.prototype.getBitsLength = function getBitsLength () {
1566
+ return AlphanumericData.getBitsLength(this.data.length)
1567
+ };
1568
+
1569
+ AlphanumericData.prototype.write = function write (bitBuffer) {
1570
+ let i;
1571
+
1572
+ // Input data characters are divided into groups of two characters
1573
+ // and encoded as 11-bit binary codes.
1574
+ for (i = 0; i + 2 <= this.data.length; i += 2) {
1575
+ // The character value of the first character is multiplied by 45
1576
+ let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45;
1577
+
1578
+ // The character value of the second digit is added to the product
1579
+ value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]);
1580
+
1581
+ // The sum is then stored as 11-bit binary number
1582
+ bitBuffer.put(value, 11);
1583
+ }
1584
+
1585
+ // If the number of input data characters is not a multiple of two,
1586
+ // the character value of the final character is encoded as a 6-bit binary number.
1587
+ if (this.data.length % 2) {
1588
+ bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);
1589
+ }
1590
+ };
1591
+
1592
+ alphanumericData = AlphanumericData;
1593
+ return alphanumericData;
1594
+ }
1595
+
1596
+ var byteData;
1597
+ var hasRequiredByteData;
1598
+
1599
+ function requireByteData () {
1600
+ if (hasRequiredByteData) return byteData;
1601
+ hasRequiredByteData = 1;
1602
+ const Mode = requireMode();
1603
+
1604
+ function ByteData (data) {
1605
+ this.mode = Mode.BYTE;
1606
+ if (typeof (data) === 'string') {
1607
+ this.data = new TextEncoder().encode(data);
1608
+ } else {
1609
+ this.data = new Uint8Array(data);
1610
+ }
1611
+ }
1612
+
1613
+ ByteData.getBitsLength = function getBitsLength (length) {
1614
+ return length * 8
1615
+ };
1616
+
1617
+ ByteData.prototype.getLength = function getLength () {
1618
+ return this.data.length
1619
+ };
1620
+
1621
+ ByteData.prototype.getBitsLength = function getBitsLength () {
1622
+ return ByteData.getBitsLength(this.data.length)
1623
+ };
1624
+
1625
+ ByteData.prototype.write = function (bitBuffer) {
1626
+ for (let i = 0, l = this.data.length; i < l; i++) {
1627
+ bitBuffer.put(this.data[i], 8);
1628
+ }
1629
+ };
1630
+
1631
+ byteData = ByteData;
1632
+ return byteData;
1633
+ }
1634
+
1635
+ var kanjiData;
1636
+ var hasRequiredKanjiData;
1637
+
1638
+ function requireKanjiData () {
1639
+ if (hasRequiredKanjiData) return kanjiData;
1640
+ hasRequiredKanjiData = 1;
1641
+ const Mode = requireMode();
1642
+ const Utils = requireUtils$1();
1643
+
1644
+ function KanjiData (data) {
1645
+ this.mode = Mode.KANJI;
1646
+ this.data = data;
1647
+ }
1648
+
1649
+ KanjiData.getBitsLength = function getBitsLength (length) {
1650
+ return length * 13
1651
+ };
1652
+
1653
+ KanjiData.prototype.getLength = function getLength () {
1654
+ return this.data.length
1655
+ };
1656
+
1657
+ KanjiData.prototype.getBitsLength = function getBitsLength () {
1658
+ return KanjiData.getBitsLength(this.data.length)
1659
+ };
1660
+
1661
+ KanjiData.prototype.write = function (bitBuffer) {
1662
+ let i;
1663
+
1664
+ // In the Shift JIS system, Kanji characters are represented by a two byte combination.
1665
+ // These byte values are shifted from the JIS X 0208 values.
1666
+ // JIS X 0208 gives details of the shift coded representation.
1667
+ for (i = 0; i < this.data.length; i++) {
1668
+ let value = Utils.toSJIS(this.data[i]);
1669
+
1670
+ // For characters with Shift JIS values from 0x8140 to 0x9FFC:
1671
+ if (value >= 0x8140 && value <= 0x9FFC) {
1672
+ // Subtract 0x8140 from Shift JIS value
1673
+ value -= 0x8140;
1674
+
1675
+ // For characters with Shift JIS values from 0xE040 to 0xEBBF
1676
+ } else if (value >= 0xE040 && value <= 0xEBBF) {
1677
+ // Subtract 0xC140 from Shift JIS value
1678
+ value -= 0xC140;
1679
+ } else {
1680
+ throw new Error(
1681
+ 'Invalid SJIS character: ' + this.data[i] + '\n' +
1682
+ 'Make sure your charset is UTF-8')
1683
+ }
1684
+
1685
+ // Multiply most significant byte of result by 0xC0
1686
+ // and add least significant byte to product
1687
+ value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff);
1688
+
1689
+ // Convert result to a 13-bit binary string
1690
+ bitBuffer.put(value, 13);
1691
+ }
1692
+ };
1693
+
1694
+ kanjiData = KanjiData;
1695
+ return kanjiData;
1696
+ }
1697
+
1698
+ var dijkstra = {exports: {}};
1699
+
1700
+ var hasRequiredDijkstra;
1701
+
1702
+ function requireDijkstra () {
1703
+ if (hasRequiredDijkstra) return dijkstra.exports;
1704
+ hasRequiredDijkstra = 1;
1705
+ (function (module) {
1706
+
1707
+ /******************************************************************************
1708
+ * Created 2008-08-19.
1709
+ *
1710
+ * Dijkstra path-finding functions. Adapted from the Dijkstar Python project.
1711
+ *
1712
+ * Copyright (C) 2008
1713
+ * Wyatt Baldwin <self@wyattbaldwin.com>
1714
+ * All rights reserved
1715
+ *
1716
+ * Licensed under the MIT license.
1717
+ *
1718
+ * http://www.opensource.org/licenses/mit-license.php
1719
+ *
1720
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1721
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1722
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1723
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1724
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1725
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1726
+ * THE SOFTWARE.
1727
+ *****************************************************************************/
1728
+ var dijkstra = {
1729
+ single_source_shortest_paths: function(graph, s, d) {
1730
+ // Predecessor map for each node that has been encountered.
1731
+ // node ID => predecessor node ID
1732
+ var predecessors = {};
1733
+
1734
+ // Costs of shortest paths from s to all nodes encountered.
1735
+ // node ID => cost
1736
+ var costs = {};
1737
+ costs[s] = 0;
1738
+
1739
+ // Costs of shortest paths from s to all nodes encountered; differs from
1740
+ // `costs` in that it provides easy access to the node that currently has
1741
+ // the known shortest path from s.
1742
+ // XXX: Do we actually need both `costs` and `open`?
1743
+ var open = dijkstra.PriorityQueue.make();
1744
+ open.push(s, 0);
1745
+
1746
+ var closest,
1747
+ u, v,
1748
+ cost_of_s_to_u,
1749
+ adjacent_nodes,
1750
+ cost_of_e,
1751
+ cost_of_s_to_u_plus_cost_of_e,
1752
+ cost_of_s_to_v,
1753
+ first_visit;
1754
+ while (!open.empty()) {
1755
+ // In the nodes remaining in graph that have a known cost from s,
1756
+ // find the node, u, that currently has the shortest path from s.
1757
+ closest = open.pop();
1758
+ u = closest.value;
1759
+ cost_of_s_to_u = closest.cost;
1760
+
1761
+ // Get nodes adjacent to u...
1762
+ adjacent_nodes = graph[u] || {};
1763
+
1764
+ // ...and explore the edges that connect u to those nodes, updating
1765
+ // the cost of the shortest paths to any or all of those nodes as
1766
+ // necessary. v is the node across the current edge from u.
1767
+ for (v in adjacent_nodes) {
1768
+ if (adjacent_nodes.hasOwnProperty(v)) {
1769
+ // Get the cost of the edge running from u to v.
1770
+ cost_of_e = adjacent_nodes[v];
1771
+
1772
+ // Cost of s to u plus the cost of u to v across e--this is *a*
1773
+ // cost from s to v that may or may not be less than the current
1774
+ // known cost to v.
1775
+ cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
1776
+
1777
+ // If we haven't visited v yet OR if the current known cost from s to
1778
+ // v is greater than the new cost we just found (cost of s to u plus
1779
+ // cost of u to v across e), update v's cost in the cost list and
1780
+ // update v's predecessor in the predecessor list (it's now u).
1781
+ cost_of_s_to_v = costs[v];
1782
+ first_visit = (typeof costs[v] === 'undefined');
1783
+ if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
1784
+ costs[v] = cost_of_s_to_u_plus_cost_of_e;
1785
+ open.push(v, cost_of_s_to_u_plus_cost_of_e);
1786
+ predecessors[v] = u;
1787
+ }
1788
+ }
1789
+ }
1790
+ }
1791
+
1792
+ if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') {
1793
+ var msg = ['Could not find a path from ', s, ' to ', d, '.'].join('');
1794
+ throw new Error(msg);
1795
+ }
1796
+
1797
+ return predecessors;
1798
+ },
1799
+
1800
+ extract_shortest_path_from_predecessor_list: function(predecessors, d) {
1801
+ var nodes = [];
1802
+ var u = d;
1803
+ while (u) {
1804
+ nodes.push(u);
1805
+ u = predecessors[u];
1806
+ }
1807
+ nodes.reverse();
1808
+ return nodes;
1809
+ },
1810
+
1811
+ find_path: function(graph, s, d) {
1812
+ var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
1813
+ return dijkstra.extract_shortest_path_from_predecessor_list(
1814
+ predecessors, d);
1815
+ },
1816
+
1817
+ /**
1818
+ * A very naive priority queue implementation.
1819
+ */
1820
+ PriorityQueue: {
1821
+ make: function (opts) {
1822
+ var T = dijkstra.PriorityQueue,
1823
+ t = {},
1824
+ key;
1825
+ opts = opts || {};
1826
+ for (key in T) {
1827
+ if (T.hasOwnProperty(key)) {
1828
+ t[key] = T[key];
1829
+ }
1830
+ }
1831
+ t.queue = [];
1832
+ t.sorter = opts.sorter || T.default_sorter;
1833
+ return t;
1834
+ },
1835
+
1836
+ default_sorter: function (a, b) {
1837
+ return a.cost - b.cost;
1838
+ },
1839
+
1840
+ /**
1841
+ * Add a new item to the queue and ensure the highest priority element
1842
+ * is at the front of the queue.
1843
+ */
1844
+ push: function (value, cost) {
1845
+ var item = {value: value, cost: cost};
1846
+ this.queue.push(item);
1847
+ this.queue.sort(this.sorter);
1848
+ },
1849
+
1850
+ /**
1851
+ * Return the highest priority element in the queue.
1852
+ */
1853
+ pop: function () {
1854
+ return this.queue.shift();
1855
+ },
1856
+
1857
+ empty: function () {
1858
+ return this.queue.length === 0;
1859
+ }
1860
+ }
1861
+ };
1862
+
1863
+
1864
+ // node.js module exports
1865
+ {
1866
+ module.exports = dijkstra;
1867
+ }
1868
+ } (dijkstra));
1869
+ return dijkstra.exports;
1870
+ }
1871
+
1872
+ var hasRequiredSegments;
1873
+
1874
+ function requireSegments () {
1875
+ if (hasRequiredSegments) return segments;
1876
+ hasRequiredSegments = 1;
1877
+ (function (exports) {
1878
+ const Mode = requireMode();
1879
+ const NumericData = requireNumericData();
1880
+ const AlphanumericData = requireAlphanumericData();
1881
+ const ByteData = requireByteData();
1882
+ const KanjiData = requireKanjiData();
1883
+ const Regex = requireRegex();
1884
+ const Utils = requireUtils$1();
1885
+ const dijkstra = requireDijkstra();
1886
+
1887
+ /**
1888
+ * Returns UTF8 byte length
1889
+ *
1890
+ * @param {String} str Input string
1891
+ * @return {Number} Number of byte
1892
+ */
1893
+ function getStringByteLength (str) {
1894
+ return unescape(encodeURIComponent(str)).length
1895
+ }
1896
+
1897
+ /**
1898
+ * Get a list of segments of the specified mode
1899
+ * from a string
1900
+ *
1901
+ * @param {Mode} mode Segment mode
1902
+ * @param {String} str String to process
1903
+ * @return {Array} Array of object with segments data
1904
+ */
1905
+ function getSegments (regex, mode, str) {
1906
+ const segments = [];
1907
+ let result;
1908
+
1909
+ while ((result = regex.exec(str)) !== null) {
1910
+ segments.push({
1911
+ data: result[0],
1912
+ index: result.index,
1913
+ mode: mode,
1914
+ length: result[0].length
1915
+ });
1916
+ }
1917
+
1918
+ return segments
1919
+ }
1920
+
1921
+ /**
1922
+ * Extracts a series of segments with the appropriate
1923
+ * modes from a string
1924
+ *
1925
+ * @param {String} dataStr Input string
1926
+ * @return {Array} Array of object with segments data
1927
+ */
1928
+ function getSegmentsFromString (dataStr) {
1929
+ const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr);
1930
+ const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr);
1931
+ let byteSegs;
1932
+ let kanjiSegs;
1933
+
1934
+ if (Utils.isKanjiModeEnabled()) {
1935
+ byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr);
1936
+ kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr);
1937
+ } else {
1938
+ byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr);
1939
+ kanjiSegs = [];
1940
+ }
1941
+
1942
+ const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
1943
+
1944
+ return segs
1945
+ .sort(function (s1, s2) {
1946
+ return s1.index - s2.index
1947
+ })
1948
+ .map(function (obj) {
1949
+ return {
1950
+ data: obj.data,
1951
+ mode: obj.mode,
1952
+ length: obj.length
1953
+ }
1954
+ })
1955
+ }
1956
+
1957
+ /**
1958
+ * Returns how many bits are needed to encode a string of
1959
+ * specified length with the specified mode
1960
+ *
1961
+ * @param {Number} length String length
1962
+ * @param {Mode} mode Segment mode
1963
+ * @return {Number} Bit length
1964
+ */
1965
+ function getSegmentBitsLength (length, mode) {
1966
+ switch (mode) {
1967
+ case Mode.NUMERIC:
1968
+ return NumericData.getBitsLength(length)
1969
+ case Mode.ALPHANUMERIC:
1970
+ return AlphanumericData.getBitsLength(length)
1971
+ case Mode.KANJI:
1972
+ return KanjiData.getBitsLength(length)
1973
+ case Mode.BYTE:
1974
+ return ByteData.getBitsLength(length)
1975
+ }
1976
+ }
1977
+
1978
+ /**
1979
+ * Merges adjacent segments which have the same mode
1980
+ *
1981
+ * @param {Array} segs Array of object with segments data
1982
+ * @return {Array} Array of object with segments data
1983
+ */
1984
+ function mergeSegments (segs) {
1985
+ return segs.reduce(function (acc, curr) {
1986
+ const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
1987
+ if (prevSeg && prevSeg.mode === curr.mode) {
1988
+ acc[acc.length - 1].data += curr.data;
1989
+ return acc
1990
+ }
1991
+
1992
+ acc.push(curr);
1993
+ return acc
1994
+ }, [])
1995
+ }
1996
+
1997
+ /**
1998
+ * Generates a list of all possible nodes combination which
1999
+ * will be used to build a segments graph.
2000
+ *
2001
+ * Nodes are divided by groups. Each group will contain a list of all the modes
2002
+ * in which is possible to encode the given text.
2003
+ *
2004
+ * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.
2005
+ * The group for '12345' will contain then 3 objects, one for each
2006
+ * possible encoding mode.
2007
+ *
2008
+ * Each node represents a possible segment.
2009
+ *
2010
+ * @param {Array} segs Array of object with segments data
2011
+ * @return {Array} Array of object with segments data
2012
+ */
2013
+ function buildNodes (segs) {
2014
+ const nodes = [];
2015
+ for (let i = 0; i < segs.length; i++) {
2016
+ const seg = segs[i];
2017
+
2018
+ switch (seg.mode) {
2019
+ case Mode.NUMERIC:
2020
+ nodes.push([seg,
2021
+ { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
2022
+ { data: seg.data, mode: Mode.BYTE, length: seg.length }
2023
+ ]);
2024
+ break
2025
+ case Mode.ALPHANUMERIC:
2026
+ nodes.push([seg,
2027
+ { data: seg.data, mode: Mode.BYTE, length: seg.length }
2028
+ ]);
2029
+ break
2030
+ case Mode.KANJI:
2031
+ nodes.push([seg,
2032
+ { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
2033
+ ]);
2034
+ break
2035
+ case Mode.BYTE:
2036
+ nodes.push([
2037
+ { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
2038
+ ]);
2039
+ }
2040
+ }
2041
+
2042
+ return nodes
2043
+ }
2044
+
2045
+ /**
2046
+ * Builds a graph from a list of nodes.
2047
+ * All segments in each node group will be connected with all the segments of
2048
+ * the next group and so on.
2049
+ *
2050
+ * At each connection will be assigned a weight depending on the
2051
+ * segment's byte length.
2052
+ *
2053
+ * @param {Array} nodes Array of object with segments data
2054
+ * @param {Number} version QR Code version
2055
+ * @return {Object} Graph of all possible segments
2056
+ */
2057
+ function buildGraph (nodes, version) {
2058
+ const table = {};
2059
+ const graph = { start: {} };
2060
+ let prevNodeIds = ['start'];
2061
+
2062
+ for (let i = 0; i < nodes.length; i++) {
2063
+ const nodeGroup = nodes[i];
2064
+ const currentNodeIds = [];
2065
+
2066
+ for (let j = 0; j < nodeGroup.length; j++) {
2067
+ const node = nodeGroup[j];
2068
+ const key = '' + i + j;
2069
+
2070
+ currentNodeIds.push(key);
2071
+ table[key] = { node: node, lastCount: 0 };
2072
+ graph[key] = {};
2073
+
2074
+ for (let n = 0; n < prevNodeIds.length; n++) {
2075
+ const prevNodeId = prevNodeIds[n];
2076
+
2077
+ if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
2078
+ graph[prevNodeId][key] =
2079
+ getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) -
2080
+ getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
2081
+
2082
+ table[prevNodeId].lastCount += node.length;
2083
+ } else {
2084
+ if (table[prevNodeId]) table[prevNodeId].lastCount = node.length;
2085
+
2086
+ graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) +
2087
+ 4 + Mode.getCharCountIndicator(node.mode, version); // switch cost
2088
+ }
2089
+ }
2090
+ }
2091
+
2092
+ prevNodeIds = currentNodeIds;
2093
+ }
2094
+
2095
+ for (let n = 0; n < prevNodeIds.length; n++) {
2096
+ graph[prevNodeIds[n]].end = 0;
2097
+ }
2098
+
2099
+ return { map: graph, table: table }
2100
+ }
2101
+
2102
+ /**
2103
+ * Builds a segment from a specified data and mode.
2104
+ * If a mode is not specified, the more suitable will be used.
2105
+ *
2106
+ * @param {String} data Input data
2107
+ * @param {Mode | String} modesHint Data mode
2108
+ * @return {Segment} Segment
2109
+ */
2110
+ function buildSingleSegment (data, modesHint) {
2111
+ let mode;
2112
+ const bestMode = Mode.getBestModeForData(data);
2113
+
2114
+ mode = Mode.from(modesHint, bestMode);
2115
+
2116
+ // Make sure data can be encoded
2117
+ if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
2118
+ throw new Error('"' + data + '"' +
2119
+ ' cannot be encoded with mode ' + Mode.toString(mode) +
2120
+ '.\n Suggested mode is: ' + Mode.toString(bestMode))
2121
+ }
2122
+
2123
+ // Use Mode.BYTE if Kanji support is disabled
2124
+ if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
2125
+ mode = Mode.BYTE;
2126
+ }
2127
+
2128
+ switch (mode) {
2129
+ case Mode.NUMERIC:
2130
+ return new NumericData(data)
2131
+
2132
+ case Mode.ALPHANUMERIC:
2133
+ return new AlphanumericData(data)
2134
+
2135
+ case Mode.KANJI:
2136
+ return new KanjiData(data)
2137
+
2138
+ case Mode.BYTE:
2139
+ return new ByteData(data)
2140
+ }
2141
+ }
2142
+
2143
+ /**
2144
+ * Builds a list of segments from an array.
2145
+ * Array can contain Strings or Objects with segment's info.
2146
+ *
2147
+ * For each item which is a string, will be generated a segment with the given
2148
+ * string and the more appropriate encoding mode.
2149
+ *
2150
+ * For each item which is an object, will be generated a segment with the given
2151
+ * data and mode.
2152
+ * Objects must contain at least the property "data".
2153
+ * If property "mode" is not present, the more suitable mode will be used.
2154
+ *
2155
+ * @param {Array} array Array of objects with segments data
2156
+ * @return {Array} Array of Segments
2157
+ */
2158
+ exports.fromArray = function fromArray (array) {
2159
+ return array.reduce(function (acc, seg) {
2160
+ if (typeof seg === 'string') {
2161
+ acc.push(buildSingleSegment(seg, null));
2162
+ } else if (seg.data) {
2163
+ acc.push(buildSingleSegment(seg.data, seg.mode));
2164
+ }
2165
+
2166
+ return acc
2167
+ }, [])
2168
+ };
2169
+
2170
+ /**
2171
+ * Builds an optimized sequence of segments from a string,
2172
+ * which will produce the shortest possible bitstream.
2173
+ *
2174
+ * @param {String} data Input string
2175
+ * @param {Number} version QR Code version
2176
+ * @return {Array} Array of segments
2177
+ */
2178
+ exports.fromString = function fromString (data, version) {
2179
+ const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled());
2180
+
2181
+ const nodes = buildNodes(segs);
2182
+ const graph = buildGraph(nodes, version);
2183
+ const path = dijkstra.find_path(graph.map, 'start', 'end');
2184
+
2185
+ const optimizedSegs = [];
2186
+ for (let i = 1; i < path.length - 1; i++) {
2187
+ optimizedSegs.push(graph.table[path[i]].node);
2188
+ }
2189
+
2190
+ return exports.fromArray(mergeSegments(optimizedSegs))
2191
+ };
2192
+
2193
+ /**
2194
+ * Splits a string in various segments with the modes which
2195
+ * best represent their content.
2196
+ * The produced segments are far from being optimized.
2197
+ * The output of this function is only used to estimate a QR Code version
2198
+ * which may contain the data.
2199
+ *
2200
+ * @param {string} data Input string
2201
+ * @return {Array} Array of segments
2202
+ */
2203
+ exports.rawSplit = function rawSplit (data) {
2204
+ return exports.fromArray(
2205
+ getSegmentsFromString(data, Utils.isKanjiModeEnabled())
2206
+ )
2207
+ };
2208
+ } (segments));
2209
+ return segments;
2210
+ }
2211
+
2212
+ var hasRequiredQrcode;
2213
+
2214
+ function requireQrcode () {
2215
+ if (hasRequiredQrcode) return qrcode;
2216
+ hasRequiredQrcode = 1;
2217
+ const Utils = requireUtils$1();
2218
+ const ECLevel = requireErrorCorrectionLevel();
2219
+ const BitBuffer = requireBitBuffer();
2220
+ const BitMatrix = requireBitMatrix();
2221
+ const AlignmentPattern = requireAlignmentPattern();
2222
+ const FinderPattern = requireFinderPattern();
2223
+ const MaskPattern = requireMaskPattern();
2224
+ const ECCode = requireErrorCorrectionCode();
2225
+ const ReedSolomonEncoder = requireReedSolomonEncoder();
2226
+ const Version = requireVersion();
2227
+ const FormatInfo = requireFormatInfo();
2228
+ const Mode = requireMode();
2229
+ const Segments = requireSegments();
2230
+
2231
+ /**
2232
+ * QRCode for JavaScript
2233
+ *
2234
+ * modified by Ryan Day for nodejs support
2235
+ * Copyright (c) 2011 Ryan Day
2236
+ *
2237
+ * Licensed under the MIT license:
2238
+ * http://www.opensource.org/licenses/mit-license.php
2239
+ *
2240
+ //---------------------------------------------------------------------
2241
+ // QRCode for JavaScript
2242
+ //
2243
+ // Copyright (c) 2009 Kazuhiko Arase
2244
+ //
2245
+ // URL: http://www.d-project.com/
2246
+ //
2247
+ // Licensed under the MIT license:
2248
+ // http://www.opensource.org/licenses/mit-license.php
2249
+ //
2250
+ // The word "QR Code" is registered trademark of
2251
+ // DENSO WAVE INCORPORATED
2252
+ // http://www.denso-wave.com/qrcode/faqpatent-e.html
2253
+ //
2254
+ //---------------------------------------------------------------------
2255
+ */
2256
+
2257
+ /**
2258
+ * Add finder patterns bits to matrix
2259
+ *
2260
+ * @param {BitMatrix} matrix Modules matrix
2261
+ * @param {Number} version QR Code version
2262
+ */
2263
+ function setupFinderPattern (matrix, version) {
2264
+ const size = matrix.size;
2265
+ const pos = FinderPattern.getPositions(version);
2266
+
2267
+ for (let i = 0; i < pos.length; i++) {
2268
+ const row = pos[i][0];
2269
+ const col = pos[i][1];
2270
+
2271
+ for (let r = -1; r <= 7; r++) {
2272
+ if (row + r <= -1 || size <= row + r) continue
2273
+
2274
+ for (let c = -1; c <= 7; c++) {
2275
+ if (col + c <= -1 || size <= col + c) continue
2276
+
2277
+ if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) ||
2278
+ (c >= 0 && c <= 6 && (r === 0 || r === 6)) ||
2279
+ (r >= 2 && r <= 4 && c >= 2 && c <= 4)) {
2280
+ matrix.set(row + r, col + c, true, true);
2281
+ } else {
2282
+ matrix.set(row + r, col + c, false, true);
2283
+ }
2284
+ }
2285
+ }
2286
+ }
2287
+ }
2288
+
2289
+ /**
2290
+ * Add timing pattern bits to matrix
2291
+ *
2292
+ * Note: this function must be called before {@link setupAlignmentPattern}
2293
+ *
2294
+ * @param {BitMatrix} matrix Modules matrix
2295
+ */
2296
+ function setupTimingPattern (matrix) {
2297
+ const size = matrix.size;
2298
+
2299
+ for (let r = 8; r < size - 8; r++) {
2300
+ const value = r % 2 === 0;
2301
+ matrix.set(r, 6, value, true);
2302
+ matrix.set(6, r, value, true);
2303
+ }
2304
+ }
2305
+
2306
+ /**
2307
+ * Add alignment patterns bits to matrix
2308
+ *
2309
+ * Note: this function must be called after {@link setupTimingPattern}
2310
+ *
2311
+ * @param {BitMatrix} matrix Modules matrix
2312
+ * @param {Number} version QR Code version
2313
+ */
2314
+ function setupAlignmentPattern (matrix, version) {
2315
+ const pos = AlignmentPattern.getPositions(version);
2316
+
2317
+ for (let i = 0; i < pos.length; i++) {
2318
+ const row = pos[i][0];
2319
+ const col = pos[i][1];
2320
+
2321
+ for (let r = -2; r <= 2; r++) {
2322
+ for (let c = -2; c <= 2; c++) {
2323
+ if (r === -2 || r === 2 || c === -2 || c === 2 ||
2324
+ (r === 0 && c === 0)) {
2325
+ matrix.set(row + r, col + c, true, true);
2326
+ } else {
2327
+ matrix.set(row + r, col + c, false, true);
2328
+ }
2329
+ }
2330
+ }
2331
+ }
2332
+ }
2333
+
2334
+ /**
2335
+ * Add version info bits to matrix
2336
+ *
2337
+ * @param {BitMatrix} matrix Modules matrix
2338
+ * @param {Number} version QR Code version
2339
+ */
2340
+ function setupVersionInfo (matrix, version) {
2341
+ const size = matrix.size;
2342
+ const bits = Version.getEncodedBits(version);
2343
+ let row, col, mod;
2344
+
2345
+ for (let i = 0; i < 18; i++) {
2346
+ row = Math.floor(i / 3);
2347
+ col = i % 3 + size - 8 - 3;
2348
+ mod = ((bits >> i) & 1) === 1;
2349
+
2350
+ matrix.set(row, col, mod, true);
2351
+ matrix.set(col, row, mod, true);
2352
+ }
2353
+ }
2354
+
2355
+ /**
2356
+ * Add format info bits to matrix
2357
+ *
2358
+ * @param {BitMatrix} matrix Modules matrix
2359
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2360
+ * @param {Number} maskPattern Mask pattern reference value
2361
+ */
2362
+ function setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) {
2363
+ const size = matrix.size;
2364
+ const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
2365
+ let i, mod;
2366
+
2367
+ for (i = 0; i < 15; i++) {
2368
+ mod = ((bits >> i) & 1) === 1;
2369
+
2370
+ // vertical
2371
+ if (i < 6) {
2372
+ matrix.set(i, 8, mod, true);
2373
+ } else if (i < 8) {
2374
+ matrix.set(i + 1, 8, mod, true);
2375
+ } else {
2376
+ matrix.set(size - 15 + i, 8, mod, true);
2377
+ }
2378
+
2379
+ // horizontal
2380
+ if (i < 8) {
2381
+ matrix.set(8, size - i - 1, mod, true);
2382
+ } else if (i < 9) {
2383
+ matrix.set(8, 15 - i - 1 + 1, mod, true);
2384
+ } else {
2385
+ matrix.set(8, 15 - i - 1, mod, true);
2386
+ }
2387
+ }
2388
+
2389
+ // fixed module
2390
+ matrix.set(size - 8, 8, 1, true);
2391
+ }
2392
+
2393
+ /**
2394
+ * Add encoded data bits to matrix
2395
+ *
2396
+ * @param {BitMatrix} matrix Modules matrix
2397
+ * @param {Uint8Array} data Data codewords
2398
+ */
2399
+ function setupData (matrix, data) {
2400
+ const size = matrix.size;
2401
+ let inc = -1;
2402
+ let row = size - 1;
2403
+ let bitIndex = 7;
2404
+ let byteIndex = 0;
2405
+
2406
+ for (let col = size - 1; col > 0; col -= 2) {
2407
+ if (col === 6) col--;
2408
+
2409
+ while (true) {
2410
+ for (let c = 0; c < 2; c++) {
2411
+ if (!matrix.isReserved(row, col - c)) {
2412
+ let dark = false;
2413
+
2414
+ if (byteIndex < data.length) {
2415
+ dark = (((data[byteIndex] >>> bitIndex) & 1) === 1);
2416
+ }
2417
+
2418
+ matrix.set(row, col - c, dark);
2419
+ bitIndex--;
2420
+
2421
+ if (bitIndex === -1) {
2422
+ byteIndex++;
2423
+ bitIndex = 7;
2424
+ }
2425
+ }
2426
+ }
2427
+
2428
+ row += inc;
2429
+
2430
+ if (row < 0 || size <= row) {
2431
+ row -= inc;
2432
+ inc = -inc;
2433
+ break
2434
+ }
2435
+ }
2436
+ }
2437
+ }
2438
+
2439
+ /**
2440
+ * Create encoded codewords from data input
2441
+ *
2442
+ * @param {Number} version QR Code version
2443
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2444
+ * @param {ByteData} data Data input
2445
+ * @return {Uint8Array} Buffer containing encoded codewords
2446
+ */
2447
+ function createData (version, errorCorrectionLevel, segments) {
2448
+ // Prepare data buffer
2449
+ const buffer = new BitBuffer();
2450
+
2451
+ segments.forEach(function (data) {
2452
+ // prefix data with mode indicator (4 bits)
2453
+ buffer.put(data.mode.bit, 4);
2454
+
2455
+ // Prefix data with character count indicator.
2456
+ // The character count indicator is a string of bits that represents the
2457
+ // number of characters that are being encoded.
2458
+ // The character count indicator must be placed after the mode indicator
2459
+ // and must be a certain number of bits long, depending on the QR version
2460
+ // and data mode
2461
+ // @see {@link Mode.getCharCountIndicator}.
2462
+ buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version));
2463
+
2464
+ // add binary data sequence to buffer
2465
+ data.write(buffer);
2466
+ });
2467
+
2468
+ // Calculate required number of bits
2469
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
2470
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2471
+ const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
2472
+
2473
+ // Add a terminator.
2474
+ // If the bit string is shorter than the total number of required bits,
2475
+ // a terminator of up to four 0s must be added to the right side of the string.
2476
+ // If the bit string is more than four bits shorter than the required number of bits,
2477
+ // add four 0s to the end.
2478
+ if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
2479
+ buffer.put(0, 4);
2480
+ }
2481
+
2482
+ // If the bit string is fewer than four bits shorter, add only the number of 0s that
2483
+ // are needed to reach the required number of bits.
2484
+
2485
+ // After adding the terminator, if the number of bits in the string is not a multiple of 8,
2486
+ // pad the string on the right with 0s to make the string's length a multiple of 8.
2487
+ while (buffer.getLengthInBits() % 8 !== 0) {
2488
+ buffer.putBit(0);
2489
+ }
2490
+
2491
+ // Add pad bytes if the string is still shorter than the total number of required bits.
2492
+ // Extend the buffer to fill the data capacity of the symbol corresponding to
2493
+ // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC)
2494
+ // and 00010001 (0x11) alternately.
2495
+ const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
2496
+ for (let i = 0; i < remainingByte; i++) {
2497
+ buffer.put(i % 2 ? 0x11 : 0xEC, 8);
2498
+ }
2499
+
2500
+ return createCodewords(buffer, version, errorCorrectionLevel)
2501
+ }
2502
+
2503
+ /**
2504
+ * Encode input data with Reed-Solomon and return codewords with
2505
+ * relative error correction bits
2506
+ *
2507
+ * @param {BitBuffer} bitBuffer Data to encode
2508
+ * @param {Number} version QR Code version
2509
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2510
+ * @return {Uint8Array} Buffer containing encoded codewords
2511
+ */
2512
+ function createCodewords (bitBuffer, version, errorCorrectionLevel) {
2513
+ // Total codewords for this QR code version (Data + Error correction)
2514
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
2515
+
2516
+ // Total number of error correction codewords
2517
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2518
+
2519
+ // Total number of data codewords
2520
+ const dataTotalCodewords = totalCodewords - ecTotalCodewords;
2521
+
2522
+ // Total number of blocks
2523
+ const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel);
2524
+
2525
+ // Calculate how many blocks each group should contain
2526
+ const blocksInGroup2 = totalCodewords % ecTotalBlocks;
2527
+ const blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
2528
+
2529
+ const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
2530
+
2531
+ const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
2532
+ const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1;
2533
+
2534
+ // Number of EC codewords is the same for both groups
2535
+ const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1;
2536
+
2537
+ // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount
2538
+ const rs = new ReedSolomonEncoder(ecCount);
2539
+
2540
+ let offset = 0;
2541
+ const dcData = new Array(ecTotalBlocks);
2542
+ const ecData = new Array(ecTotalBlocks);
2543
+ let maxDataSize = 0;
2544
+ const buffer = new Uint8Array(bitBuffer.buffer);
2545
+
2546
+ // Divide the buffer into the required number of blocks
2547
+ for (let b = 0; b < ecTotalBlocks; b++) {
2548
+ const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2;
2549
+
2550
+ // extract a block of data from buffer
2551
+ dcData[b] = buffer.slice(offset, offset + dataSize);
2552
+
2553
+ // Calculate EC codewords for this data block
2554
+ ecData[b] = rs.encode(dcData[b]);
2555
+
2556
+ offset += dataSize;
2557
+ maxDataSize = Math.max(maxDataSize, dataSize);
2558
+ }
2559
+
2560
+ // Create final data
2561
+ // Interleave the data and error correction codewords from each block
2562
+ const data = new Uint8Array(totalCodewords);
2563
+ let index = 0;
2564
+ let i, r;
2565
+
2566
+ // Add data codewords
2567
+ for (i = 0; i < maxDataSize; i++) {
2568
+ for (r = 0; r < ecTotalBlocks; r++) {
2569
+ if (i < dcData[r].length) {
2570
+ data[index++] = dcData[r][i];
2571
+ }
2572
+ }
2573
+ }
2574
+
2575
+ // Apped EC codewords
2576
+ for (i = 0; i < ecCount; i++) {
2577
+ for (r = 0; r < ecTotalBlocks; r++) {
2578
+ data[index++] = ecData[r][i];
2579
+ }
2580
+ }
2581
+
2582
+ return data
2583
+ }
2584
+
2585
+ /**
2586
+ * Build QR Code symbol
2587
+ *
2588
+ * @param {String} data Input string
2589
+ * @param {Number} version QR Code version
2590
+ * @param {ErrorCorretionLevel} errorCorrectionLevel Error level
2591
+ * @param {MaskPattern} maskPattern Mask pattern
2592
+ * @return {Object} Object containing symbol data
2593
+ */
2594
+ function createSymbol (data, version, errorCorrectionLevel, maskPattern) {
2595
+ let segments;
2596
+
2597
+ if (Array.isArray(data)) {
2598
+ segments = Segments.fromArray(data);
2599
+ } else if (typeof data === 'string') {
2600
+ let estimatedVersion = version;
2601
+
2602
+ if (!estimatedVersion) {
2603
+ const rawSegments = Segments.rawSplit(data);
2604
+
2605
+ // Estimate best version that can contain raw splitted segments
2606
+ estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel);
2607
+ }
2608
+
2609
+ // Build optimized segments
2610
+ // If estimated version is undefined, try with the highest version
2611
+ segments = Segments.fromString(data, estimatedVersion || 40);
2612
+ } else {
2613
+ throw new Error('Invalid data')
2614
+ }
2615
+
2616
+ // Get the min version that can contain data
2617
+ const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel);
2618
+
2619
+ // If no version is found, data cannot be stored
2620
+ if (!bestVersion) {
2621
+ throw new Error('The amount of data is too big to be stored in a QR Code')
2622
+ }
2623
+
2624
+ // If not specified, use min version as default
2625
+ if (!version) {
2626
+ version = bestVersion;
2627
+
2628
+ // Check if the specified version can contain the data
2629
+ } else if (version < bestVersion) {
2630
+ throw new Error('\n' +
2631
+ 'The chosen QR Code version cannot contain this amount of data.\n' +
2632
+ 'Minimum version required to store current data is: ' + bestVersion + '.\n'
2633
+ )
2634
+ }
2635
+
2636
+ const dataBits = createData(version, errorCorrectionLevel, segments);
2637
+
2638
+ // Allocate matrix buffer
2639
+ const moduleCount = Utils.getSymbolSize(version);
2640
+ const modules = new BitMatrix(moduleCount);
2641
+
2642
+ // Add function modules
2643
+ setupFinderPattern(modules, version);
2644
+ setupTimingPattern(modules);
2645
+ setupAlignmentPattern(modules, version);
2646
+
2647
+ // Add temporary dummy bits for format info just to set them as reserved.
2648
+ // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask}
2649
+ // since the masking operation must be performed only on the encoding region.
2650
+ // These blocks will be replaced with correct values later in code.
2651
+ setupFormatInfo(modules, errorCorrectionLevel, 0);
2652
+
2653
+ if (version >= 7) {
2654
+ setupVersionInfo(modules, version);
2655
+ }
2656
+
2657
+ // Add data codewords
2658
+ setupData(modules, dataBits);
2659
+
2660
+ if (isNaN(maskPattern)) {
2661
+ // Find best mask pattern
2662
+ maskPattern = MaskPattern.getBestMask(modules,
2663
+ setupFormatInfo.bind(null, modules, errorCorrectionLevel));
2664
+ }
2665
+
2666
+ // Apply mask pattern
2667
+ MaskPattern.applyMask(maskPattern, modules);
2668
+
2669
+ // Replace format info bits with correct values
2670
+ setupFormatInfo(modules, errorCorrectionLevel, maskPattern);
2671
+
2672
+ return {
2673
+ modules: modules,
2674
+ version: version,
2675
+ errorCorrectionLevel: errorCorrectionLevel,
2676
+ maskPattern: maskPattern,
2677
+ segments: segments
2678
+ }
2679
+ }
2680
+
2681
+ /**
2682
+ * QR Code
2683
+ *
2684
+ * @param {String | Array} data Input data
2685
+ * @param {Object} options Optional configurations
2686
+ * @param {Number} options.version QR Code version
2687
+ * @param {String} options.errorCorrectionLevel Error correction level
2688
+ * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis
2689
+ */
2690
+ qrcode.create = function create (data, options) {
2691
+ if (typeof data === 'undefined' || data === '') {
2692
+ throw new Error('No input text')
2693
+ }
2694
+
2695
+ let errorCorrectionLevel = ECLevel.M;
2696
+ let version;
2697
+ let mask;
2698
+
2699
+ if (typeof options !== 'undefined') {
2700
+ // Use higher error correction level as default
2701
+ errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M);
2702
+ version = Version.from(options.version);
2703
+ mask = MaskPattern.from(options.maskPattern);
2704
+
2705
+ if (options.toSJISFunc) {
2706
+ Utils.setToSJISFunction(options.toSJISFunc);
2707
+ }
2708
+ }
2709
+
2710
+ return createSymbol(data, version, errorCorrectionLevel, mask)
2711
+ };
2712
+ return qrcode;
2713
+ }
2714
+
2715
+ var canvas = {};
2716
+
2717
+ var utils = {};
2718
+
2719
+ var hasRequiredUtils;
2720
+
2721
+ function requireUtils () {
2722
+ if (hasRequiredUtils) return utils;
2723
+ hasRequiredUtils = 1;
2724
+ (function (exports) {
2725
+ function hex2rgba (hex) {
2726
+ if (typeof hex === 'number') {
2727
+ hex = hex.toString();
2728
+ }
2729
+
2730
+ if (typeof hex !== 'string') {
2731
+ throw new Error('Color should be defined as hex string')
2732
+ }
2733
+
2734
+ let hexCode = hex.slice().replace('#', '').split('');
2735
+ if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
2736
+ throw new Error('Invalid hex color: ' + hex)
2737
+ }
2738
+
2739
+ // Convert from short to long form (fff -> ffffff)
2740
+ if (hexCode.length === 3 || hexCode.length === 4) {
2741
+ hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) {
2742
+ return [c, c]
2743
+ }));
2744
+ }
2745
+
2746
+ // Add default alpha value
2747
+ if (hexCode.length === 6) hexCode.push('F', 'F');
2748
+
2749
+ const hexValue = parseInt(hexCode.join(''), 16);
2750
+
2751
+ return {
2752
+ r: (hexValue >> 24) & 255,
2753
+ g: (hexValue >> 16) & 255,
2754
+ b: (hexValue >> 8) & 255,
2755
+ a: hexValue & 255,
2756
+ hex: '#' + hexCode.slice(0, 6).join('')
2757
+ }
2758
+ }
2759
+
2760
+ exports.getOptions = function getOptions (options) {
2761
+ if (!options) options = {};
2762
+ if (!options.color) options.color = {};
2763
+
2764
+ const margin = typeof options.margin === 'undefined' ||
2765
+ options.margin === null ||
2766
+ options.margin < 0
2767
+ ? 4
2768
+ : options.margin;
2769
+
2770
+ const width = options.width && options.width >= 21 ? options.width : undefined;
2771
+ const scale = options.scale || 4;
2772
+
2773
+ return {
2774
+ width: width,
2775
+ scale: width ? 4 : scale,
2776
+ margin: margin,
2777
+ color: {
2778
+ dark: hex2rgba(options.color.dark || '#000000ff'),
2779
+ light: hex2rgba(options.color.light || '#ffffffff')
2780
+ },
2781
+ type: options.type,
2782
+ rendererOpts: options.rendererOpts || {}
2783
+ }
2784
+ };
2785
+
2786
+ exports.getScale = function getScale (qrSize, opts) {
2787
+ return opts.width && opts.width >= qrSize + opts.margin * 2
2788
+ ? opts.width / (qrSize + opts.margin * 2)
2789
+ : opts.scale
2790
+ };
2791
+
2792
+ exports.getImageWidth = function getImageWidth (qrSize, opts) {
2793
+ const scale = exports.getScale(qrSize, opts);
2794
+ return Math.floor((qrSize + opts.margin * 2) * scale)
2795
+ };
2796
+
2797
+ exports.qrToImageData = function qrToImageData (imgData, qr, opts) {
2798
+ const size = qr.modules.size;
2799
+ const data = qr.modules.data;
2800
+ const scale = exports.getScale(size, opts);
2801
+ const symbolSize = Math.floor((size + opts.margin * 2) * scale);
2802
+ const scaledMargin = opts.margin * scale;
2803
+ const palette = [opts.color.light, opts.color.dark];
2804
+
2805
+ for (let i = 0; i < symbolSize; i++) {
2806
+ for (let j = 0; j < symbolSize; j++) {
2807
+ let posDst = (i * symbolSize + j) * 4;
2808
+ let pxColor = opts.color.light;
2809
+
2810
+ if (i >= scaledMargin && j >= scaledMargin &&
2811
+ i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
2812
+ const iSrc = Math.floor((i - scaledMargin) / scale);
2813
+ const jSrc = Math.floor((j - scaledMargin) / scale);
2814
+ pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
2815
+ }
2816
+
2817
+ imgData[posDst++] = pxColor.r;
2818
+ imgData[posDst++] = pxColor.g;
2819
+ imgData[posDst++] = pxColor.b;
2820
+ imgData[posDst] = pxColor.a;
2821
+ }
2822
+ }
2823
+ };
2824
+ } (utils));
2825
+ return utils;
2826
+ }
2827
+
2828
+ var hasRequiredCanvas;
2829
+
2830
+ function requireCanvas () {
2831
+ if (hasRequiredCanvas) return canvas;
2832
+ hasRequiredCanvas = 1;
2833
+ (function (exports) {
2834
+ const Utils = requireUtils();
2835
+
2836
+ function clearCanvas (ctx, canvas, size) {
2837
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
2838
+
2839
+ if (!canvas.style) canvas.style = {};
2840
+ canvas.height = size;
2841
+ canvas.width = size;
2842
+ canvas.style.height = size + 'px';
2843
+ canvas.style.width = size + 'px';
2844
+ }
2845
+
2846
+ function getCanvasElement () {
2847
+ try {
2848
+ return document.createElement('canvas')
2849
+ } catch (e) {
2850
+ throw new Error('You need to specify a canvas element')
2851
+ }
2852
+ }
2853
+
2854
+ exports.render = function render (qrData, canvas, options) {
2855
+ let opts = options;
2856
+ let canvasEl = canvas;
2857
+
2858
+ if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
2859
+ opts = canvas;
2860
+ canvas = undefined;
2861
+ }
2862
+
2863
+ if (!canvas) {
2864
+ canvasEl = getCanvasElement();
2865
+ }
2866
+
2867
+ opts = Utils.getOptions(opts);
2868
+ const size = Utils.getImageWidth(qrData.modules.size, opts);
2869
+
2870
+ const ctx = canvasEl.getContext('2d');
2871
+ const image = ctx.createImageData(size, size);
2872
+ Utils.qrToImageData(image.data, qrData, opts);
2873
+
2874
+ clearCanvas(ctx, canvasEl, size);
2875
+ ctx.putImageData(image, 0, 0);
2876
+
2877
+ return canvasEl
2878
+ };
2879
+
2880
+ exports.renderToDataURL = function renderToDataURL (qrData, canvas, options) {
2881
+ let opts = options;
2882
+
2883
+ if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
2884
+ opts = canvas;
2885
+ canvas = undefined;
2886
+ }
2887
+
2888
+ if (!opts) opts = {};
2889
+
2890
+ const canvasEl = exports.render(qrData, canvas, opts);
2891
+
2892
+ const type = opts.type || 'image/png';
2893
+ const rendererOpts = opts.rendererOpts || {};
2894
+
2895
+ return canvasEl.toDataURL(type, rendererOpts.quality)
2896
+ };
2897
+ } (canvas));
2898
+ return canvas;
2899
+ }
2900
+
2901
+ var svgTag = {};
2902
+
2903
+ var hasRequiredSvgTag;
2904
+
2905
+ function requireSvgTag () {
2906
+ if (hasRequiredSvgTag) return svgTag;
2907
+ hasRequiredSvgTag = 1;
2908
+ const Utils = requireUtils();
2909
+
2910
+ function getColorAttrib (color, attrib) {
2911
+ const alpha = color.a / 255;
2912
+ const str = attrib + '="' + color.hex + '"';
2913
+
2914
+ return alpha < 1
2915
+ ? str + ' ' + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"'
2916
+ : str
2917
+ }
2918
+
2919
+ function svgCmd (cmd, x, y) {
2920
+ let str = cmd + x;
2921
+ if (typeof y !== 'undefined') str += ' ' + y;
2922
+
2923
+ return str
2924
+ }
2925
+
2926
+ function qrToPath (data, size, margin) {
2927
+ let path = '';
2928
+ let moveBy = 0;
2929
+ let newRow = false;
2930
+ let lineLength = 0;
2931
+
2932
+ for (let i = 0; i < data.length; i++) {
2933
+ const col = Math.floor(i % size);
2934
+ const row = Math.floor(i / size);
2935
+
2936
+ if (!col && !newRow) newRow = true;
2937
+
2938
+ if (data[i]) {
2939
+ lineLength++;
2940
+
2941
+ if (!(i > 0 && col > 0 && data[i - 1])) {
2942
+ path += newRow
2943
+ ? svgCmd('M', col + margin, 0.5 + row + margin)
2944
+ : svgCmd('m', moveBy, 0);
2945
+
2946
+ moveBy = 0;
2947
+ newRow = false;
2948
+ }
2949
+
2950
+ if (!(col + 1 < size && data[i + 1])) {
2951
+ path += svgCmd('h', lineLength);
2952
+ lineLength = 0;
2953
+ }
2954
+ } else {
2955
+ moveBy++;
2956
+ }
2957
+ }
2958
+
2959
+ return path
2960
+ }
2961
+
2962
+ svgTag.render = function render (qrData, options, cb) {
2963
+ const opts = Utils.getOptions(options);
2964
+ const size = qrData.modules.size;
2965
+ const data = qrData.modules.data;
2966
+ const qrcodesize = size + opts.margin * 2;
2967
+
2968
+ const bg = !opts.color.light.a
2969
+ ? ''
2970
+ : '<path ' + getColorAttrib(opts.color.light, 'fill') +
2971
+ ' d="M0 0h' + qrcodesize + 'v' + qrcodesize + 'H0z"/>';
2972
+
2973
+ const path =
2974
+ '<path ' + getColorAttrib(opts.color.dark, 'stroke') +
2975
+ ' d="' + qrToPath(data, size, opts.margin) + '"/>';
2976
+
2977
+ const viewBox = 'viewBox="' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '"';
2978
+
2979
+ const width = !opts.width ? '' : 'width="' + opts.width + '" height="' + opts.width + '" ';
2980
+
2981
+ const svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + '</svg>\n';
2982
+
2983
+ if (typeof cb === 'function') {
2984
+ cb(null, svgTag);
2985
+ }
2986
+
2987
+ return svgTag
2988
+ };
2989
+ return svgTag;
2990
+ }
2991
+
2992
+ var hasRequiredBrowser;
2993
+
2994
+ function requireBrowser () {
2995
+ if (hasRequiredBrowser) return browser;
2996
+ hasRequiredBrowser = 1;
2997
+ const canPromise = requireCanPromise();
2998
+
2999
+ const QRCode = requireQrcode();
3000
+ const CanvasRenderer = requireCanvas();
3001
+ const SvgRenderer = requireSvgTag();
3002
+
3003
+ function renderCanvas (renderFunc, canvas, text, opts, cb) {
3004
+ const args = [].slice.call(arguments, 1);
3005
+ const argsNum = args.length;
3006
+ const isLastArgCb = typeof args[argsNum - 1] === 'function';
3007
+
3008
+ if (!isLastArgCb && !canPromise()) {
3009
+ throw new Error('Callback required as last argument')
3010
+ }
3011
+
3012
+ if (isLastArgCb) {
3013
+ if (argsNum < 2) {
3014
+ throw new Error('Too few arguments provided')
3015
+ }
3016
+
3017
+ if (argsNum === 2) {
3018
+ cb = text;
3019
+ text = canvas;
3020
+ canvas = opts = undefined;
3021
+ } else if (argsNum === 3) {
3022
+ if (canvas.getContext && typeof cb === 'undefined') {
3023
+ cb = opts;
3024
+ opts = undefined;
3025
+ } else {
3026
+ cb = opts;
3027
+ opts = text;
3028
+ text = canvas;
3029
+ canvas = undefined;
3030
+ }
3031
+ }
3032
+ } else {
3033
+ if (argsNum < 1) {
3034
+ throw new Error('Too few arguments provided')
3035
+ }
3036
+
3037
+ if (argsNum === 1) {
3038
+ text = canvas;
3039
+ canvas = opts = undefined;
3040
+ } else if (argsNum === 2 && !canvas.getContext) {
3041
+ opts = text;
3042
+ text = canvas;
3043
+ canvas = undefined;
3044
+ }
3045
+
3046
+ return new Promise(function (resolve, reject) {
3047
+ try {
3048
+ const data = QRCode.create(text, opts);
3049
+ resolve(renderFunc(data, canvas, opts));
3050
+ } catch (e) {
3051
+ reject(e);
3052
+ }
3053
+ })
3054
+ }
3055
+
3056
+ try {
3057
+ const data = QRCode.create(text, opts);
3058
+ cb(null, renderFunc(data, canvas, opts));
3059
+ } catch (e) {
3060
+ cb(e);
3061
+ }
3062
+ }
3063
+
3064
+ browser.create = QRCode.create;
3065
+ browser.toCanvas = renderCanvas.bind(null, CanvasRenderer.render);
3066
+ browser.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL);
3067
+
3068
+ // only svg for now.
3069
+ browser.toString = renderCanvas.bind(null, function (data, _, opts) {
3070
+ return SvgRenderer.render(data, opts)
3071
+ });
3072
+ return browser;
3073
+ }
3074
+
3075
+ var browserExports = requireBrowser();
3076
+ var QRCode = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
3077
+
3078
+ const JustifiCheckoutQrCode = /*@__PURE__*/ proxyCustomElement(class JustifiCheckoutQrCode extends HTMLElement {
3079
+ constructor(registerHost) {
3080
+ super();
3081
+ if (registerHost !== false) {
3082
+ this.__registerHost();
3083
+ }
3084
+ this.errorEvent = createEvent(this, "error-event", 7);
3085
+ this.size = 256;
3086
+ }
3087
+ componentWillLoad() {
3088
+ checkPkgVersion();
3089
+ this.analytics = new JustifiAnalytics(this);
3090
+ }
3091
+ componentDidLoad() {
3092
+ this.renderQrCode();
3093
+ }
3094
+ disconnectedCallback() {
3095
+ var _a;
3096
+ (_a = this.analytics) === null || _a === void 0 ? void 0 : _a.cleanup();
3097
+ }
3098
+ propChanged() {
3099
+ this.renderQrCode();
3100
+ }
3101
+ get checkoutUrl() {
3102
+ return `https://components.justifi.ai/hosted-checkout/${this.checkoutId}`;
3103
+ }
3104
+ async renderQrCode() {
3105
+ if (!this.checkoutId) {
3106
+ this.errorEvent.emit({
3107
+ message: 'checkoutId is required',
3108
+ errorCode: ComponentErrorCodes.MISSING_PROPS,
3109
+ severity: ComponentErrorSeverity.ERROR,
3110
+ });
3111
+ return;
3112
+ }
3113
+ if (!this.qrContainerEl)
3114
+ return;
3115
+ const svg = await QRCode.toString(this.checkoutUrl, {
3116
+ type: 'svg',
3117
+ width: this.size,
3118
+ errorCorrectionLevel: 'M',
3119
+ });
3120
+ this.qrContainerEl.innerHTML = svg;
3121
+ }
3122
+ render() {
3123
+ if (!this.checkoutId)
3124
+ return null;
3125
+ return (h("div", { ref: (el) => (this.qrContainerEl = el) }));
3126
+ }
3127
+ get el() { return this; }
3128
+ static get watchers() { return {
3129
+ "checkoutId": ["propChanged"],
3130
+ "size": ["propChanged"]
3131
+ }; }
3132
+ }, [256, "justifi-checkout-qr-code", {
3133
+ "checkoutId": [1, "checkout-id"],
3134
+ "size": [2]
3135
+ }, undefined, {
3136
+ "checkoutId": ["propChanged"],
3137
+ "size": ["propChanged"]
3138
+ }]);
3139
+ function defineCustomElement() {
3140
+ if (typeof customElements === "undefined") {
3141
+ return;
3142
+ }
3143
+ const components = ["justifi-checkout-qr-code"];
3144
+ components.forEach(tagName => { switch (tagName) {
3145
+ case "justifi-checkout-qr-code":
3146
+ if (!customElements.get(tagName)) {
3147
+ customElements.define(tagName, JustifiCheckoutQrCode);
3148
+ }
3149
+ break;
3150
+ } });
3151
+ }
3152
+ defineCustomElement();
3153
+
3154
+ export { JustifiCheckoutQrCode as J, defineCustomElement as d };