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