@digigov/ui 0.26.2 → 0.26.3

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 (42) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/app/QrCodeViewer/QRCode.stories.d.ts +8 -0
  3. package/app/QrCodeViewer/QRCode.stories.js +46 -0
  4. package/app/QrCodeViewer/__stories__/Custom.d.ts +2 -0
  5. package/app/QrCodeViewer/__stories__/Custom.js +37 -0
  6. package/app/QrCodeViewer/__stories__/Default.d.ts +2 -0
  7. package/app/QrCodeViewer/__stories__/Default.js +24 -0
  8. package/app/QrCodeViewer/index.d.ts +8 -0
  9. package/app/QrCodeViewer/index.js +248 -0
  10. package/app/QrCodeViewer/index.mdx +21 -0
  11. package/app/QrCodeViewer/qrcodegen.d.ts +100 -0
  12. package/app/QrCodeViewer/qrcodegen.js +1086 -0
  13. package/app/QrCodeViewer/types.d.ts +29 -0
  14. package/app/QrCodeViewer/types.js +5 -0
  15. package/app/QrCodeViewer/utils.d.ts +11 -0
  16. package/app/QrCodeViewer/utils.js +108 -0
  17. package/app/index.d.ts +1 -0
  18. package/app/index.js +13 -0
  19. package/es/app/QrCodeViewer/QRCode.stories.js +8 -0
  20. package/es/app/QrCodeViewer/__stories__/Custom.js +22 -0
  21. package/es/app/QrCodeViewer/__stories__/Default.js +11 -0
  22. package/es/app/QrCodeViewer/index.js +224 -0
  23. package/es/app/QrCodeViewer/index.mdx +21 -0
  24. package/es/app/QrCodeViewer/qrcodegen.js +1085 -0
  25. package/es/app/QrCodeViewer/types.js +1 -0
  26. package/es/app/QrCodeViewer/utils.js +95 -0
  27. package/es/app/index.js +1 -0
  28. package/es/registry.js +8 -0
  29. package/esm/app/QrCodeViewer/QRCode.stories.js +8 -0
  30. package/esm/app/QrCodeViewer/__stories__/Custom.js +22 -0
  31. package/esm/app/QrCodeViewer/__stories__/Default.js +11 -0
  32. package/esm/app/QrCodeViewer/index.js +224 -0
  33. package/esm/app/QrCodeViewer/index.mdx +21 -0
  34. package/esm/app/QrCodeViewer/qrcodegen.js +1085 -0
  35. package/esm/app/QrCodeViewer/types.js +1 -0
  36. package/esm/app/QrCodeViewer/utils.js +95 -0
  37. package/esm/app/index.js +1 -0
  38. package/esm/index.js +1 -1
  39. package/esm/registry.js +8 -0
  40. package/package.json +2 -2
  41. package/registry.d.ts +4 -0
  42. package/registry.js +12 -0
@@ -0,0 +1,1086 @@
1
+ /**
2
+ * @license QR Code generator library (TypeScript)
3
+ * Copyright (c) Project Nayuki.
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ 'use strict'; // eslint-disable-next-line @typescript-eslint/no-namespace
7
+
8
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
9
+
10
+ Object.defineProperty(exports, "__esModule", {
11
+ value: true
12
+ });
13
+ exports["default"] = void 0;
14
+
15
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
16
+
17
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
18
+
19
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
20
+
21
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
22
+
23
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
24
+
25
+ var qrcodegen;
26
+
27
+ (function (_qrcodegen) {
28
+ var QrCode = /*#__PURE__*/function () {
29
+ /*-- Constructor (low level) and fields --*/
30
+ // Creates a new QR Code with the given version number,
31
+ // error correction level, data codeword bytes, and mask number.
32
+ // This is a low-level API that most users should not use directly.
33
+ // A mid-level API is the encodeSegments() function.
34
+ function QrCode( // The version number of this QR Code, which is between 1 and 40 (inclusive).
35
+ // This determines the size of this barcode.
36
+ version, // The error correction level used in this QR Code.
37
+ errorCorrectionLevel, dataCodewords, msk) {
38
+ (0, _classCallCheck2["default"])(this, QrCode);
39
+ this.version = void 0;
40
+ this.errorCorrectionLevel = void 0;
41
+ this.size = void 0;
42
+ this.mask = void 0;
43
+ this.modules = [];
44
+ this.isFunction = [];
45
+ this.version = version;
46
+ this.errorCorrectionLevel = errorCorrectionLevel; // Check scalar arguments
47
+
48
+ if (version < QrCode.MIN_VERSION || version > QrCode.MAX_VERSION) throw new RangeError('Version value out of range');
49
+ if (msk < -1 || msk > 7) throw new RangeError('Mask value out of range');
50
+ this.size = version * 4 + 17; // Initialize both grids to be size*size arrays of Boolean false
51
+
52
+ var row = [];
53
+
54
+ for (var i = 0; i < this.size; i++) {
55
+ row.push(false);
56
+ }
57
+
58
+ for (var _i = 0; _i < this.size; _i++) {
59
+ this.modules.push(row.slice()); // Initially all light
60
+
61
+ this.isFunction.push(row.slice());
62
+ } // Compute ECC, draw modules
63
+
64
+
65
+ this.drawFunctionPatterns();
66
+ var allCodewords = this.addEccAndInterleave(dataCodewords);
67
+ this.drawCodewords(allCodewords); // Do masking
68
+
69
+ if (msk == -1) {
70
+ // Automatically choose best mask
71
+ var minPenalty = 1000000000;
72
+
73
+ for (var _i2 = 0; _i2 < 8; _i2++) {
74
+ this.applyMask(_i2);
75
+ this.drawFormatBits(_i2);
76
+ var penalty = this.getPenaltyScore();
77
+
78
+ if (penalty < minPenalty) {
79
+ msk = _i2;
80
+ minPenalty = penalty;
81
+ }
82
+
83
+ this.applyMask(_i2); // Undoes the mask due to XOR
84
+ }
85
+ }
86
+
87
+ assert(0 <= msk && msk <= 7);
88
+ this.mask = msk;
89
+ this.applyMask(msk); // Apply the final choice of mask
90
+
91
+ this.drawFormatBits(msk); // Overwrite old format bits
92
+
93
+ this.isFunction = [];
94
+ }
95
+ /*-- Accessor methods --*/
96
+ // Returns the color of the module (pixel) at the given coordinates, which is false
97
+ // for light or true for dark. The top left corner has the coordinates (x=0, y=0).
98
+ // If the given coordinates are out of bounds, then false (light) is returned.
99
+
100
+
101
+ (0, _createClass2["default"])(QrCode, [{
102
+ key: "getModule",
103
+ value: function getModule(x, y) {
104
+ return 0 <= x && x < this.size && 0 <= y && y < this.size && this.modules[y][x];
105
+ } // Modified to expose modules for easy access
106
+
107
+ }, {
108
+ key: "getModules",
109
+ value: function getModules() {
110
+ return this.modules;
111
+ }
112
+ /*-- Private helper methods for constructor: Drawing function modules --*/
113
+ // Reads this object's version field, and draws and marks all function modules.
114
+
115
+ }, {
116
+ key: "drawFunctionPatterns",
117
+ value: function drawFunctionPatterns() {
118
+ // Draw horizontal and vertical timing patterns
119
+ for (var i = 0; i < this.size; i++) {
120
+ this.setFunctionModule(6, i, i % 2 == 0);
121
+ this.setFunctionModule(i, 6, i % 2 == 0);
122
+ } // Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules)
123
+
124
+
125
+ this.drawFinderPattern(3, 3);
126
+ this.drawFinderPattern(this.size - 4, 3);
127
+ this.drawFinderPattern(3, this.size - 4); // Draw numerous alignment patterns
128
+
129
+ var alignPatPos = this.getAlignmentPatternPositions();
130
+ var numAlign = alignPatPos.length;
131
+
132
+ for (var _i3 = 0; _i3 < numAlign; _i3++) {
133
+ for (var j = 0; j < numAlign; j++) {
134
+ // Don't draw on the three finder corners
135
+ if (!(_i3 == 0 && j == 0 || _i3 == 0 && j == numAlign - 1 || _i3 == numAlign - 1 && j == 0)) this.drawAlignmentPattern(alignPatPos[_i3], alignPatPos[j]);
136
+ }
137
+ } // Draw configuration data
138
+
139
+
140
+ this.drawFormatBits(0); // Dummy mask value; overwritten later in the constructor
141
+
142
+ this.drawVersion();
143
+ } // Draws two copies of the format bits (with its own error correction code)
144
+ // based on the given mask and this object's error correction level field.
145
+
146
+ }, {
147
+ key: "drawFormatBits",
148
+ value: function drawFormatBits(mask) {
149
+ // Calculate error correction code and pack bits
150
+ var data = this.errorCorrectionLevel.formatBits << 3 | mask; // errCorrLvl is uint2, mask is uint3
151
+
152
+ var rem = data;
153
+
154
+ for (var i = 0; i < 10; i++) {
155
+ rem = rem << 1 ^ (rem >>> 9) * 0x537;
156
+ }
157
+
158
+ var bits = (data << 10 | rem) ^ 0x5412; // uint15
159
+
160
+ assert(bits >>> 15 == 0); // Draw first copy
161
+
162
+ for (var _i4 = 0; _i4 <= 5; _i4++) {
163
+ this.setFunctionModule(8, _i4, getBit(bits, _i4));
164
+ }
165
+
166
+ this.setFunctionModule(8, 7, getBit(bits, 6));
167
+ this.setFunctionModule(8, 8, getBit(bits, 7));
168
+ this.setFunctionModule(7, 8, getBit(bits, 8));
169
+
170
+ for (var _i5 = 9; _i5 < 15; _i5++) {
171
+ this.setFunctionModule(14 - _i5, 8, getBit(bits, _i5));
172
+ } // Draw second copy
173
+
174
+
175
+ for (var _i6 = 0; _i6 < 8; _i6++) {
176
+ this.setFunctionModule(this.size - 1 - _i6, 8, getBit(bits, _i6));
177
+ }
178
+
179
+ for (var _i7 = 8; _i7 < 15; _i7++) {
180
+ this.setFunctionModule(8, this.size - 15 + _i7, getBit(bits, _i7));
181
+ }
182
+
183
+ this.setFunctionModule(8, this.size - 8, true); // Always dark
184
+ } // Draws two copies of the version bits (with its own error correction code),
185
+ // based on this object's version field, iff 7 <= version <= 40.
186
+
187
+ }, {
188
+ key: "drawVersion",
189
+ value: function drawVersion() {
190
+ if (this.version < 7) return; // Calculate error correction code and pack bits
191
+
192
+ var rem = this.version; // version is uint6, in the range [7, 40]
193
+
194
+ for (var i = 0; i < 12; i++) {
195
+ rem = rem << 1 ^ (rem >>> 11) * 0x1f25;
196
+ }
197
+
198
+ var bits = this.version << 12 | rem; // uint18
199
+
200
+ assert(bits >>> 18 == 0); // Draw two copies
201
+
202
+ for (var _i8 = 0; _i8 < 18; _i8++) {
203
+ var color = getBit(bits, _i8);
204
+ var a = this.size - 11 + _i8 % 3;
205
+ var b = Math.floor(_i8 / 3);
206
+ this.setFunctionModule(a, b, color);
207
+ this.setFunctionModule(b, a, color);
208
+ }
209
+ } // Draws a 9*9 finder pattern including the border separator,
210
+ // with the center module at (x, y). Modules can be out of bounds.
211
+
212
+ }, {
213
+ key: "drawFinderPattern",
214
+ value: function drawFinderPattern(x, y) {
215
+ for (var dy = -4; dy <= 4; dy++) {
216
+ for (var dx = -4; dx <= 4; dx++) {
217
+ var dist = Math.max(Math.abs(dx), Math.abs(dy)); // Chebyshev/infinity norm
218
+
219
+ var xx = x + dx;
220
+ var yy = y + dy;
221
+ if (0 <= xx && xx < this.size && 0 <= yy && yy < this.size) this.setFunctionModule(xx, yy, dist != 2 && dist != 4);
222
+ }
223
+ }
224
+ } // Draws a 5*5 alignment pattern, with the center module
225
+ // at (x, y). All modules must be in bounds.
226
+
227
+ }, {
228
+ key: "drawAlignmentPattern",
229
+ value: function drawAlignmentPattern(x, y) {
230
+ for (var dy = -2; dy <= 2; dy++) {
231
+ for (var dx = -2; dx <= 2; dx++) {
232
+ this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
233
+ }
234
+ }
235
+ } // Sets the color of a module and marks it as a function module.
236
+ // Only used by the constructor. Coordinates must be in bounds.
237
+
238
+ }, {
239
+ key: "setFunctionModule",
240
+ value: function setFunctionModule(x, y, isDark) {
241
+ this.modules[y][x] = isDark;
242
+ this.isFunction[y][x] = true;
243
+ }
244
+ /*-- Private helper methods for constructor: Codewords and masking --*/
245
+ // Returns a new byte string representing the given data with the appropriate error correction
246
+ // codewords appended to it, based on this object's version and error correction level.
247
+
248
+ }, {
249
+ key: "addEccAndInterleave",
250
+ value: function addEccAndInterleave(data) {
251
+ var ver = this.version;
252
+ var ecl = this.errorCorrectionLevel;
253
+ if (data.length != QrCode.getNumDataCodewords(ver, ecl)) throw new RangeError('Invalid argument'); // Calculate parameter numbers
254
+
255
+ var numBlocks = QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
256
+ var blockEccLen = QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver];
257
+ var rawCodewords = Math.floor(QrCode.getNumRawDataModules(ver) / 8);
258
+ var numShortBlocks = numBlocks - rawCodewords % numBlocks;
259
+ var shortBlockLen = Math.floor(rawCodewords / numBlocks); // Split data into blocks and append ECC to each block
260
+
261
+ var blocks = [];
262
+ var rsDiv = QrCode.reedSolomonComputeDivisor(blockEccLen);
263
+
264
+ for (var i = 0, k = 0; i < numBlocks; i++) {
265
+ var dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
266
+ k += dat.length;
267
+ var ecc = QrCode.reedSolomonComputeRemainder(dat, rsDiv);
268
+ if (i < numShortBlocks) dat.push(0);
269
+ blocks.push(dat.concat(ecc));
270
+ } // Interleave (not concatenate) the bytes from every block into a single sequence
271
+
272
+
273
+ var result = [];
274
+
275
+ var _loop = function _loop(_i9) {
276
+ blocks.forEach(function (block, j) {
277
+ // Skip the padding byte in short blocks
278
+ if (_i9 != shortBlockLen - blockEccLen || j >= numShortBlocks) result.push(block[_i9]);
279
+ });
280
+ };
281
+
282
+ for (var _i9 = 0; _i9 < blocks[0].length; _i9++) {
283
+ _loop(_i9);
284
+ }
285
+
286
+ assert(result.length == rawCodewords);
287
+ return result;
288
+ } // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
289
+ // data area of this QR Code. Function modules need to be marked off before this is called.
290
+
291
+ }, {
292
+ key: "drawCodewords",
293
+ value: function drawCodewords(data) {
294
+ if (data.length != Math.floor(QrCode.getNumRawDataModules(this.version) / 8)) throw new RangeError('Invalid argument');
295
+ var i = 0; // Bit index into the data
296
+ // Do the funny zigzag scan
297
+
298
+ for (var right = this.size - 1; right >= 1; right -= 2) {
299
+ // Index of right column in each column pair
300
+ if (right == 6) right = 5;
301
+
302
+ for (var vert = 0; vert < this.size; vert++) {
303
+ // Vertical counter
304
+ for (var j = 0; j < 2; j++) {
305
+ var x = right - j; // Actual x coordinate
306
+
307
+ var upward = (right + 1 & 2) == 0;
308
+ var y = upward ? this.size - 1 - vert : vert; // Actual y coordinate
309
+
310
+ if (!this.isFunction[y][x] && i < data.length * 8) {
311
+ this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
312
+ i++;
313
+ } // If this QR Code has any remainder bits (0 to 7), they were assigned as
314
+ // 0/false/light by the constructor and are left unchanged by this method
315
+
316
+ }
317
+ }
318
+ }
319
+
320
+ assert(i == data.length * 8);
321
+ } // XORs the codeword modules in this QR Code with the given mask pattern.
322
+ // The function modules must be marked and the codeword bits must be drawn
323
+ // before masking. Due to the arithmetic of XOR, calling applyMask() with
324
+ // the same mask value a second time will undo the mask. A final well-formed
325
+ // QR Code needs exactly one (not zero, two, etc.) mask applied.
326
+
327
+ }, {
328
+ key: "applyMask",
329
+ value: function applyMask(mask) {
330
+ if (mask < 0 || mask > 7) throw new RangeError('Mask value out of range');
331
+
332
+ for (var y = 0; y < this.size; y++) {
333
+ for (var x = 0; x < this.size; x++) {
334
+ var invert = void 0;
335
+
336
+ switch (mask) {
337
+ case 0:
338
+ invert = (x + y) % 2 == 0;
339
+ break;
340
+
341
+ case 1:
342
+ invert = y % 2 == 0;
343
+ break;
344
+
345
+ case 2:
346
+ invert = x % 3 == 0;
347
+ break;
348
+
349
+ case 3:
350
+ invert = (x + y) % 3 == 0;
351
+ break;
352
+
353
+ case 4:
354
+ invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0;
355
+ break;
356
+
357
+ case 5:
358
+ invert = x * y % 2 + x * y % 3 == 0;
359
+ break;
360
+
361
+ case 6:
362
+ invert = (x * y % 2 + x * y % 3) % 2 == 0;
363
+ break;
364
+
365
+ case 7:
366
+ invert = ((x + y) % 2 + x * y % 3) % 2 == 0;
367
+ break;
368
+
369
+ default:
370
+ throw new Error('Unreachable');
371
+ }
372
+
373
+ if (!this.isFunction[y][x] && invert) this.modules[y][x] = !this.modules[y][x];
374
+ }
375
+ }
376
+ } // Calculates and returns the penalty score based on state of this QR Code's current modules.
377
+ // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
378
+
379
+ }, {
380
+ key: "getPenaltyScore",
381
+ value: function getPenaltyScore() {
382
+ var result = 0; // Adjacent modules in row having same color, and finder-like patterns
383
+
384
+ for (var y = 0; y < this.size; y++) {
385
+ var runColor = false;
386
+ var runX = 0;
387
+ var runHistory = [0, 0, 0, 0, 0, 0, 0];
388
+
389
+ for (var x = 0; x < this.size; x++) {
390
+ if (this.modules[y][x] == runColor) {
391
+ runX++;
392
+ if (runX == 5) result += QrCode.PENALTY_N1;else if (runX > 5) result++;
393
+ } else {
394
+ this.finderPenaltyAddHistory(runX, runHistory);
395
+ if (!runColor) result += this.finderPenaltyCountPatterns(runHistory) * QrCode.PENALTY_N3;
396
+ runColor = this.modules[y][x];
397
+ runX = 1;
398
+ }
399
+ }
400
+
401
+ result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * QrCode.PENALTY_N3;
402
+ } // Adjacent modules in column having same color, and finder-like patterns
403
+
404
+
405
+ for (var _x = 0; _x < this.size; _x++) {
406
+ var _runColor = false;
407
+ var runY = 0;
408
+ var _runHistory = [0, 0, 0, 0, 0, 0, 0];
409
+
410
+ for (var _y = 0; _y < this.size; _y++) {
411
+ if (this.modules[_y][_x] == _runColor) {
412
+ runY++;
413
+ if (runY == 5) result += QrCode.PENALTY_N1;else if (runY > 5) result++;
414
+ } else {
415
+ this.finderPenaltyAddHistory(runY, _runHistory);
416
+ if (!_runColor) result += this.finderPenaltyCountPatterns(_runHistory) * QrCode.PENALTY_N3;
417
+ _runColor = this.modules[_y][_x];
418
+ runY = 1;
419
+ }
420
+ }
421
+
422
+ result += this.finderPenaltyTerminateAndCount(_runColor, runY, _runHistory) * QrCode.PENALTY_N3;
423
+ } // 2*2 blocks of modules having same color
424
+
425
+
426
+ for (var _y2 = 0; _y2 < this.size - 1; _y2++) {
427
+ for (var _x2 = 0; _x2 < this.size - 1; _x2++) {
428
+ var color = this.modules[_y2][_x2];
429
+ if (color == this.modules[_y2][_x2 + 1] && color == this.modules[_y2 + 1][_x2] && color == this.modules[_y2 + 1][_x2 + 1]) result += QrCode.PENALTY_N2;
430
+ }
431
+ } // Balance of dark and light modules
432
+
433
+
434
+ var dark = 0;
435
+
436
+ var _iterator = _createForOfIteratorHelper(this.modules),
437
+ _step;
438
+
439
+ try {
440
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
441
+ var row = _step.value;
442
+ dark = row.reduce(function (sum, color) {
443
+ return sum + (color ? 1 : 0);
444
+ }, dark);
445
+ }
446
+ } catch (err) {
447
+ _iterator.e(err);
448
+ } finally {
449
+ _iterator.f();
450
+ }
451
+
452
+ var total = this.size * this.size; // Note that size is odd, so dark/total != 1/2
453
+ // Compute the smallest integer k >= 0 such that (45-5k)% <= dark/total <= (55+5k)%
454
+
455
+ var k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
456
+ assert(0 <= k && k <= 9);
457
+ result += k * QrCode.PENALTY_N4;
458
+ assert(0 <= result && result <= 2568888); // Non-tight upper bound based on default values of PENALTY_N1, ..., N4
459
+
460
+ return result;
461
+ }
462
+ /*-- Private helper functions --*/
463
+ // Returns an ascending list of positions of alignment patterns for this version number.
464
+ // Each position is in the range [0,177), and are used on both the x and y axes.
465
+ // This could be implemented as lookup table of 40 variable-length lists of integers.
466
+
467
+ }, {
468
+ key: "getAlignmentPatternPositions",
469
+ value: function getAlignmentPatternPositions() {
470
+ if (this.version == 1) return [];else {
471
+ var numAlign = Math.floor(this.version / 7) + 2;
472
+ var step = this.version == 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
473
+ var result = [6];
474
+
475
+ for (var pos = this.size - 7; result.length < numAlign; pos -= step) {
476
+ result.splice(1, 0, pos);
477
+ }
478
+
479
+ return result;
480
+ }
481
+ } // Returns the number of data bits that can be stored in a QR Code of the given version number, after
482
+ // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
483
+ // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
484
+
485
+ }, {
486
+ key: "finderPenaltyCountPatterns",
487
+ value: // Can only be called immediately after a light run is added, and
488
+ // returns either 0, 1, or 2. A helper function for getPenaltyScore().
489
+ function finderPenaltyCountPatterns(runHistory) {
490
+ var n = runHistory[1];
491
+ assert(n <= this.size * 3);
492
+ var core = n > 0 && runHistory[2] == n && runHistory[3] == n * 3 && runHistory[4] == n && runHistory[5] == n;
493
+ return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
494
+ } // Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
495
+
496
+ }, {
497
+ key: "finderPenaltyTerminateAndCount",
498
+ value: function finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
499
+ if (currentRunColor) {
500
+ // Terminate dark run
501
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
502
+ currentRunLength = 0;
503
+ }
504
+
505
+ currentRunLength += this.size; // Add light border to final run
506
+
507
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
508
+ return this.finderPenaltyCountPatterns(runHistory);
509
+ } // Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
510
+
511
+ }, {
512
+ key: "finderPenaltyAddHistory",
513
+ value: function finderPenaltyAddHistory(currentRunLength, runHistory) {
514
+ if (runHistory[0] == 0) currentRunLength += this.size; // Add light border to initial run
515
+
516
+ runHistory.pop();
517
+ runHistory.unshift(currentRunLength);
518
+ }
519
+ /*-- Constants and tables --*/
520
+ // The minimum version number supported in the QR Code Model 2 standard.
521
+
522
+ }], [{
523
+ key: "encodeText",
524
+ value:
525
+ /*-- Static factory functions (high level) --*/
526
+ // Returns a QR Code representing the given Unicode text string at the given error correction level.
527
+ // As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer
528
+ // Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible
529
+ // QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
530
+ // ecl argument if it can be done without increasing the version.
531
+ function encodeText(text, ecl) {
532
+ var segs = qrcodegen.QrSegment.makeSegments(text);
533
+ return QrCode.encodeSegments(segs, ecl);
534
+ } // Returns a QR Code representing the given binary data at the given error correction level.
535
+ // This function always encodes using the binary segment mode, not any text mode. The maximum number of
536
+ // bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
537
+ // The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
538
+
539
+ }, {
540
+ key: "encodeBinary",
541
+ value: function encodeBinary(data, ecl) {
542
+ var seg = qrcodegen.QrSegment.makeBytes(data);
543
+ return QrCode.encodeSegments([seg], ecl);
544
+ }
545
+ /*-- Static factory functions (mid level) --*/
546
+ // Returns a QR Code representing the given segments with the given encoding parameters.
547
+ // The smallest possible QR Code version within the given range is automatically
548
+ // chosen for the output. Iff boostEcl is true, then the ECC level of the result
549
+ // may be higher than the ecl argument if it can be done without increasing the
550
+ // version. The mask number is either between 0 to 7 (inclusive) to force that
551
+ // mask, or -1 to automatically choose an appropriate mask (which may be slow).
552
+ // This function allows the user to create a custom sequence of segments that switches
553
+ // between modes (such as alphanumeric and byte) to encode text in less space.
554
+ // This is a mid-level API; the high-level API is encodeText() and encodeBinary().
555
+
556
+ }, {
557
+ key: "encodeSegments",
558
+ value: function encodeSegments(segs, ecl) {
559
+ var minVersion = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
560
+ var maxVersion = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 40;
561
+ var mask = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : -1;
562
+ var boostEcl = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : true;
563
+ if (!(QrCode.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= QrCode.MAX_VERSION) || mask < -1 || mask > 7) throw new RangeError('Invalid value'); // Find the minimal version number to use
564
+
565
+ var version;
566
+ var dataUsedBits;
567
+
568
+ for (version = minVersion;; version++) {
569
+ var _dataCapacityBits = QrCode.getNumDataCodewords(version, ecl) * 8; // Number of data bits available
570
+
571
+
572
+ var usedBits = QrSegment.getTotalBits(segs, version);
573
+
574
+ if (usedBits <= _dataCapacityBits) {
575
+ dataUsedBits = usedBits;
576
+ break; // This version number is found to be suitable
577
+ }
578
+
579
+ if (version >= maxVersion) // All versions in the range could not fit the given data
580
+ throw new RangeError('Data too long');
581
+ } // Increase the error correction level while the data still fits in the current version number
582
+
583
+
584
+ for (var _i10 = 0, _arr = [QrCode.Ecc.MEDIUM, QrCode.Ecc.QUARTILE, QrCode.Ecc.HIGH]; _i10 < _arr.length; _i10++) {
585
+ var newEcl = _arr[_i10];
586
+ // From low to high
587
+ if (boostEcl && dataUsedBits <= QrCode.getNumDataCodewords(version, newEcl) * 8) ecl = newEcl;
588
+ } // Concatenate all segments to create the data bit string
589
+
590
+
591
+ var bb = [];
592
+
593
+ var _iterator2 = _createForOfIteratorHelper(segs),
594
+ _step2;
595
+
596
+ try {
597
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
598
+ var seg = _step2.value;
599
+ appendBits(seg.mode.modeBits, 4, bb);
600
+ appendBits(seg.numChars, seg.mode.numCharCountBits(version), bb);
601
+
602
+ var _iterator3 = _createForOfIteratorHelper(seg.getData()),
603
+ _step3;
604
+
605
+ try {
606
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
607
+ var b = _step3.value;
608
+ bb.push(b);
609
+ }
610
+ } catch (err) {
611
+ _iterator3.e(err);
612
+ } finally {
613
+ _iterator3.f();
614
+ }
615
+ }
616
+ } catch (err) {
617
+ _iterator2.e(err);
618
+ } finally {
619
+ _iterator2.f();
620
+ }
621
+
622
+ assert(bb.length == dataUsedBits); // Add terminator and pad up to a byte if applicable
623
+
624
+ var dataCapacityBits = QrCode.getNumDataCodewords(version, ecl) * 8;
625
+ assert(bb.length <= dataCapacityBits);
626
+ appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
627
+ appendBits(0, (8 - bb.length % 8) % 8, bb);
628
+ assert(bb.length % 8 == 0); // Pad with alternating bytes until data capacity is reached
629
+
630
+ for (var padByte = 0xec; bb.length < dataCapacityBits; padByte ^= 0xec ^ 0x11) {
631
+ appendBits(padByte, 8, bb);
632
+ } // Pack bits into bytes in big endian
633
+
634
+
635
+ var dataCodewords = [];
636
+
637
+ while (dataCodewords.length * 8 < bb.length) {
638
+ dataCodewords.push(0);
639
+ }
640
+
641
+ bb.forEach(function (b, i) {
642
+ return dataCodewords[i >>> 3] |= b << 7 - (i & 7);
643
+ }); // Create the QR Code object
644
+
645
+ return new QrCode(version, ecl, dataCodewords, mask);
646
+ }
647
+ /*-- Fields --*/
648
+ // The version number of this QR Code, which is between 1 and 40 (inclusive).
649
+ // This determines the size of this barcode.
650
+
651
+ }, {
652
+ key: "getNumRawDataModules",
653
+ value: function getNumRawDataModules(ver) {
654
+ if (ver < QrCode.MIN_VERSION || ver > QrCode.MAX_VERSION) throw new RangeError('Version number out of range');
655
+ var result = (16 * ver + 128) * ver + 64;
656
+
657
+ if (ver >= 2) {
658
+ var numAlign = Math.floor(ver / 7) + 2;
659
+ result -= (25 * numAlign - 10) * numAlign - 55;
660
+ if (ver >= 7) result -= 36;
661
+ }
662
+
663
+ assert(208 <= result && result <= 29648);
664
+ return result;
665
+ } // Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
666
+ // QR Code of the given version number and error correction level, with remainder bits discarded.
667
+ // This stateless pure function could be implemented as a (40*4)-cell lookup table.
668
+
669
+ }, {
670
+ key: "getNumDataCodewords",
671
+ value: function getNumDataCodewords(ver, ecl) {
672
+ return Math.floor(QrCode.getNumRawDataModules(ver) / 8) - QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
673
+ } // Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
674
+ // implemented as a lookup table over all possible parameter values, instead of as an algorithm.
675
+
676
+ }, {
677
+ key: "reedSolomonComputeDivisor",
678
+ value: function reedSolomonComputeDivisor(degree) {
679
+ if (degree < 1 || degree > 255) throw new RangeError('Degree out of range'); // Polynomial coefficients are stored from highest to lowest power, excluding the leading term which is always 1.
680
+ // For example the polynomial x^3 + 255x^2 + 8x + 93 is stored as the uint8 array [255, 8, 93].
681
+
682
+ var result = [];
683
+
684
+ for (var i = 0; i < degree - 1; i++) {
685
+ result.push(0);
686
+ }
687
+
688
+ result.push(1); // Start off with the monomial x^0
689
+ // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}),
690
+ // and drop the highest monomial term which is always 1x^degree.
691
+ // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D).
692
+
693
+ var root = 1;
694
+
695
+ for (var _i11 = 0; _i11 < degree; _i11++) {
696
+ // Multiply the current product by (x - r^i)
697
+ for (var j = 0; j < result.length; j++) {
698
+ result[j] = QrCode.reedSolomonMultiply(result[j], root);
699
+ if (j + 1 < result.length) result[j] ^= result[j + 1];
700
+ }
701
+
702
+ root = QrCode.reedSolomonMultiply(root, 0x02);
703
+ }
704
+
705
+ return result;
706
+ } // Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
707
+
708
+ }, {
709
+ key: "reedSolomonComputeRemainder",
710
+ value: function reedSolomonComputeRemainder(data, divisor) {
711
+ var result = divisor.map(function (_) {
712
+ return 0;
713
+ });
714
+
715
+ var _iterator4 = _createForOfIteratorHelper(data),
716
+ _step4;
717
+
718
+ try {
719
+ var _loop2 = function _loop2() {
720
+ var b = _step4.value;
721
+ // Polynomial division
722
+ var factor = b ^ result.shift();
723
+ result.push(0);
724
+ divisor.forEach(function (coef, i) {
725
+ return result[i] ^= QrCode.reedSolomonMultiply(coef, factor);
726
+ });
727
+ };
728
+
729
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
730
+ _loop2();
731
+ }
732
+ } catch (err) {
733
+ _iterator4.e(err);
734
+ } finally {
735
+ _iterator4.f();
736
+ }
737
+
738
+ return result;
739
+ } // Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result
740
+ // are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
741
+
742
+ }, {
743
+ key: "reedSolomonMultiply",
744
+ value: function reedSolomonMultiply(x, y) {
745
+ if (x >>> 8 != 0 || y >>> 8 != 0) throw new RangeError('Byte out of range'); // Russian peasant multiplication
746
+
747
+ var z = 0;
748
+
749
+ for (var i = 7; i >= 0; i--) {
750
+ z = z << 1 ^ (z >>> 7) * 0x11d;
751
+ z ^= (y >>> i & 1) * x;
752
+ }
753
+
754
+ assert(z >>> 8 == 0);
755
+ return z;
756
+ }
757
+ }]);
758
+ return QrCode;
759
+ }();
760
+
761
+ QrCode.MIN_VERSION = 1;
762
+ QrCode.MAX_VERSION = 40;
763
+ QrCode.PENALTY_N1 = 3;
764
+ QrCode.PENALTY_N2 = 3;
765
+ QrCode.PENALTY_N3 = 40;
766
+ QrCode.PENALTY_N4 = 10;
767
+ QrCode.ECC_CODEWORDS_PER_BLOCK = [// Version: (note that index 0 is for padding, and is set to an illegal value)
768
+ //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
769
+ [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // Low
770
+ [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28], // Medium
771
+ [-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // Quartile
772
+ [-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30] // High
773
+ ];
774
+ QrCode.NUM_ERROR_CORRECTION_BLOCKS = [// Version: (note that index 0 is for padding, and is set to an illegal value)
775
+ //0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
776
+ [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25], // Low
777
+ [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49], // Medium
778
+ [-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68], // Quartile
779
+ [-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81] // High
780
+ ];
781
+ _qrcodegen.QrCode = QrCode;
782
+
783
+ // Appends the given number of low-order bits of the given value
784
+ // to the given buffer. Requires 0 <= len <= 31 and 0 <= val < 2^len.
785
+ function appendBits(val, len, bb) {
786
+ if (len < 0 || len > 31 || val >>> len != 0) throw new RangeError('Value out of range');
787
+
788
+ for (var i = len - 1; i >= 0; i-- // Append bit by bit
789
+ ) {
790
+ bb.push(val >>> i & 1);
791
+ }
792
+ } // Returns true iff the i'th bit of x is set to 1.
793
+
794
+
795
+ function getBit(x, i) {
796
+ return (x >>> i & 1) != 0;
797
+ } // Throws an exception if the given condition is false.
798
+
799
+
800
+ function assert(cond) {
801
+ if (!cond) throw new Error('Assertion error');
802
+ }
803
+ /*---- Data segment class ----*/
804
+
805
+ /*
806
+ * A segment of character/binary/control data in a QR Code symbol.
807
+ * Instances of this class are immutable.
808
+ * The mid-level way to create a segment is to take the payload data
809
+ * and call a static factory function such as QrSegment.makeNumeric().
810
+ * The low-level way to create a segment is to custom-make the bit buffer
811
+ * and call the QrSegment() constructor with appropriate values.
812
+ * This segment class imposes no length restrictions, but QR Codes have restrictions.
813
+ * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
814
+ * Any segment longer than this is meaningless for the purpose of generating QR Codes.
815
+ */
816
+
817
+
818
+ var QrSegment = /*#__PURE__*/function () {
819
+ // Creates a new QR Code segment with the given attributes and data.
820
+ // The character count (numChars) must agree with the mode and the bit buffer length,
821
+ // but the constraint isn't checked. The given bit buffer is cloned and stored.
822
+ function QrSegment( // The mode indicator of this segment.
823
+ mode, // The length of this segment's unencoded data. Measured in characters for
824
+ // numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode.
825
+ // Always zero or positive. Not the same as the data's bit length.
826
+ numChars, // The data bits of this segment. Accessed through getData().
827
+ bitData) {
828
+ (0, _classCallCheck2["default"])(this, QrSegment);
829
+ this.mode = void 0;
830
+ this.numChars = void 0;
831
+ this.bitData = void 0;
832
+ this.mode = mode;
833
+ this.numChars = numChars;
834
+ this.bitData = bitData;
835
+ if (numChars < 0) throw new RangeError('Invalid argument');
836
+ this.bitData = bitData.slice(); // Make defensive copy
837
+ }
838
+ /*-- Methods --*/
839
+ // Returns a new copy of the data bits of this segment.
840
+
841
+
842
+ (0, _createClass2["default"])(QrSegment, [{
843
+ key: "getData",
844
+ value: function getData() {
845
+ return this.bitData.slice(); // Make defensive copy
846
+ } // (Package-private) Calculates and returns the number of bits needed to encode the given segments at
847
+ // the given version. The result is infinity if a segment has too many characters to fit its length field.
848
+
849
+ }], [{
850
+ key: "makeBytes",
851
+ value:
852
+ /*-- Static factory functions (mid level) --*/
853
+ // Returns a segment representing the given binary data encoded in
854
+ // byte mode. All input byte arrays are acceptable. Any text string
855
+ // can be converted to UTF-8 bytes and encoded as a byte mode segment.
856
+ function makeBytes(data) {
857
+ var bb = [];
858
+
859
+ var _iterator5 = _createForOfIteratorHelper(data),
860
+ _step5;
861
+
862
+ try {
863
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
864
+ var b = _step5.value;
865
+ appendBits(b, 8, bb);
866
+ }
867
+ } catch (err) {
868
+ _iterator5.e(err);
869
+ } finally {
870
+ _iterator5.f();
871
+ }
872
+
873
+ return new QrSegment(QrSegment.Mode.BYTE, data.length, bb);
874
+ } // Returns a segment representing the given string of decimal digits encoded in numeric mode.
875
+
876
+ }, {
877
+ key: "makeNumeric",
878
+ value: function makeNumeric(digits) {
879
+ if (!QrSegment.isNumeric(digits)) throw new RangeError('String contains non-numeric characters');
880
+ var bb = [];
881
+
882
+ for (var i = 0; i < digits.length;) {
883
+ // Consume up to 3 digits per iteration
884
+ var n = Math.min(digits.length - i, 3);
885
+ appendBits(parseInt(digits.substr(i, n), 10), n * 3 + 1, bb);
886
+ i += n;
887
+ }
888
+
889
+ return new QrSegment(QrSegment.Mode.NUMERIC, digits.length, bb);
890
+ } // Returns a segment representing the given text string encoded in alphanumeric mode.
891
+ // The characters allowed are: 0 to 9, A to Z (uppercase only), space,
892
+ // dollar, percent, asterisk, plus, hyphen, period, slash, colon.
893
+
894
+ }, {
895
+ key: "makeAlphanumeric",
896
+ value: function makeAlphanumeric(text) {
897
+ if (!QrSegment.isAlphanumeric(text)) throw new RangeError('String contains unencodable characters in alphanumeric mode');
898
+ var bb = [];
899
+ var i;
900
+
901
+ for (i = 0; i + 2 <= text.length; i += 2) {
902
+ // Process groups of 2
903
+ var temp = QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
904
+ temp += QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
905
+ appendBits(temp, 11, bb);
906
+ }
907
+
908
+ if (i < text.length) // 1 character remaining
909
+ appendBits(QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
910
+ return new QrSegment(QrSegment.Mode.ALPHANUMERIC, text.length, bb);
911
+ } // Returns a new mutable list of zero or more segments to represent the given Unicode text string.
912
+ // The result may use various segment modes and switch modes to optimize the length of the bit stream.
913
+
914
+ }, {
915
+ key: "makeSegments",
916
+ value: function makeSegments(text) {
917
+ // Select the most efficient segment encoding automatically
918
+ if (text == '') return [];else if (QrSegment.isNumeric(text)) return [QrSegment.makeNumeric(text)];else if (QrSegment.isAlphanumeric(text)) return [QrSegment.makeAlphanumeric(text)];else return [QrSegment.makeBytes(QrSegment.toUtf8ByteArray(text))];
919
+ } // Returns a segment representing an Extended Channel Interpretation
920
+ // (ECI) designator with the given assignment value.
921
+
922
+ }, {
923
+ key: "makeEci",
924
+ value: function makeEci(assignVal) {
925
+ var bb = [];
926
+ if (assignVal < 0) throw new RangeError('ECI assignment value out of range');else if (assignVal < 1 << 7) appendBits(assignVal, 8, bb);else if (assignVal < 1 << 14) {
927
+ appendBits(2, 2, bb);
928
+ appendBits(assignVal, 14, bb);
929
+ } else if (assignVal < 1000000) {
930
+ appendBits(6, 3, bb);
931
+ appendBits(assignVal, 21, bb);
932
+ } else throw new RangeError('ECI assignment value out of range');
933
+ return new QrSegment(QrSegment.Mode.ECI, 0, bb);
934
+ } // Tests whether the given string can be encoded as a segment in numeric mode.
935
+ // A string is encodable iff each character is in the range 0 to 9.
936
+
937
+ }, {
938
+ key: "isNumeric",
939
+ value: function isNumeric(text) {
940
+ return QrSegment.NUMERIC_REGEX.test(text);
941
+ } // Tests whether the given string can be encoded as a segment in alphanumeric mode.
942
+ // A string is encodable iff each character is in the following set: 0 to 9, A to Z
943
+ // (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
944
+
945
+ }, {
946
+ key: "isAlphanumeric",
947
+ value: function isAlphanumeric(text) {
948
+ return QrSegment.ALPHANUMERIC_REGEX.test(text);
949
+ }
950
+ /*-- Constructor (low level) and fields --*/
951
+
952
+ }, {
953
+ key: "getTotalBits",
954
+ value: function getTotalBits(segs, version) {
955
+ var result = 0;
956
+
957
+ var _iterator6 = _createForOfIteratorHelper(segs),
958
+ _step6;
959
+
960
+ try {
961
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
962
+ var seg = _step6.value;
963
+ var ccbits = seg.mode.numCharCountBits(version);
964
+ if (seg.numChars >= 1 << ccbits) return Infinity; // The segment's length doesn't fit the field's bit width
965
+
966
+ result += 4 + ccbits + seg.bitData.length;
967
+ }
968
+ } catch (err) {
969
+ _iterator6.e(err);
970
+ } finally {
971
+ _iterator6.f();
972
+ }
973
+
974
+ return result;
975
+ } // Returns a new array of bytes representing the given string encoded in UTF-8.
976
+
977
+ }, {
978
+ key: "toUtf8ByteArray",
979
+ value: function toUtf8ByteArray(str) {
980
+ str = encodeURI(str);
981
+ var result = [];
982
+
983
+ for (var i = 0; i < str.length; i++) {
984
+ if (str.charAt(i) != '%') result.push(str.charCodeAt(i));else {
985
+ result.push(parseInt(str.substr(i + 1, 2), 16));
986
+ i += 2;
987
+ }
988
+ }
989
+
990
+ return result;
991
+ }
992
+ /*-- Constants --*/
993
+ // Describes precisely all strings that are encodable in numeric mode.
994
+
995
+ }]);
996
+ return QrSegment;
997
+ }();
998
+
999
+ QrSegment.NUMERIC_REGEX = /^[0-9]*$/;
1000
+ QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
1001
+ QrSegment.ALPHANUMERIC_CHARSET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:';
1002
+ _qrcodegen.QrSegment = QrSegment;
1003
+ })(qrcodegen || (qrcodegen = {}));
1004
+ /*---- Public helper enumeration ----*/
1005
+ // eslint-disable-next-line @typescript-eslint/no-namespace
1006
+
1007
+
1008
+ (function (_qrcodegen2) {
1009
+ var QrCode;
1010
+
1011
+ (function (_QrCode) {
1012
+ var Ecc = /*#__PURE__*/(0, _createClass2["default"])(
1013
+ /*-- Constants --*/
1014
+ // The QR Code can tolerate about 7% erroneous codewords
1015
+ // The QR Code can tolerate about 15% erroneous codewords
1016
+ // The QR Code can tolerate about 25% erroneous codewords
1017
+ // The QR Code can tolerate about 30% erroneous codewords
1018
+
1019
+ /*-- Constructor and fields --*/
1020
+ // In the range 0 to 3 (unsigned 2-bit integer).
1021
+ // (Package-private) In the range 0 to 3 (unsigned 2-bit integer).
1022
+ function Ecc( // In the range 0 to 3 (unsigned 2-bit integer).
1023
+ ordinal, // (Package-private) In the range 0 to 3 (unsigned 2-bit integer).
1024
+ formatBits) {
1025
+ (0, _classCallCheck2["default"])(this, Ecc);
1026
+ this.ordinal = void 0;
1027
+ this.formatBits = void 0;
1028
+ this.ordinal = ordinal;
1029
+ this.formatBits = formatBits;
1030
+ });
1031
+ Ecc.LOW = new Ecc(0, 1);
1032
+ Ecc.MEDIUM = new Ecc(1, 0);
1033
+ Ecc.QUARTILE = new Ecc(2, 3);
1034
+ Ecc.HIGH = new Ecc(3, 2);
1035
+ _QrCode.Ecc = Ecc;
1036
+ })(QrCode || (QrCode = _qrcodegen2.QrCode || (_qrcodegen2.QrCode = {})));
1037
+ })(qrcodegen || (qrcodegen = {}));
1038
+ /*---- Public helper enumeration ----*/
1039
+ // eslint-disable-next-line @typescript-eslint/no-namespace
1040
+
1041
+
1042
+ (function (_qrcodegen3) {
1043
+ var QrSegment;
1044
+
1045
+ (function (_QrSegment) {
1046
+ var Mode = /*#__PURE__*/function () {
1047
+ /*-- Constants --*/
1048
+
1049
+ /*-- Constructor and fields --*/
1050
+ // The mode indicator bits, which is a uint4 value (range 0 to 15).
1051
+ // Number of character count bits for three different version ranges.
1052
+ function Mode( // The mode indicator bits, which is a uint4 value (range 0 to 15).
1053
+ modeBits, // Number of character count bits for three different version ranges.
1054
+ numBitsCharCount) {
1055
+ (0, _classCallCheck2["default"])(this, Mode);
1056
+ this.modeBits = void 0;
1057
+ this.numBitsCharCount = void 0;
1058
+ this.modeBits = modeBits;
1059
+ this.numBitsCharCount = numBitsCharCount;
1060
+ }
1061
+ /*-- Method --*/
1062
+ // (Package-private) Returns the bit width of the character count field for a segment in
1063
+ // this mode in a QR Code at the given version number. The result is in the range [0, 16].
1064
+
1065
+
1066
+ (0, _createClass2["default"])(Mode, [{
1067
+ key: "numCharCountBits",
1068
+ value: function numCharCountBits(ver) {
1069
+ return this.numBitsCharCount[Math.floor((ver + 7) / 17)];
1070
+ }
1071
+ }]);
1072
+ return Mode;
1073
+ }();
1074
+
1075
+ Mode.NUMERIC = new Mode(0x1, [10, 12, 14]);
1076
+ Mode.ALPHANUMERIC = new Mode(0x2, [9, 11, 13]);
1077
+ Mode.BYTE = new Mode(0x4, [8, 16, 16]);
1078
+ Mode.KANJI = new Mode(0x8, [8, 10, 12]);
1079
+ Mode.ECI = new Mode(0x7, [0, 0, 0]);
1080
+ _QrSegment.Mode = Mode;
1081
+ })(QrSegment || (QrSegment = _qrcodegen3.QrSegment || (_qrcodegen3.QrSegment = {})));
1082
+ })(qrcodegen || (qrcodegen = {})); // Modification to export for actual use
1083
+
1084
+
1085
+ var _default = qrcodegen;
1086
+ exports["default"] = _default;