@ekyc_qoobiss/qbs-ect-cmp 1.2.7 → 1.2.8

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