@ticketlayer/elements 0.2.0

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