qrcodesolid 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +493 -2
  2. package/dist/color-parse-empty.d.ts +6 -0
  3. package/dist/color-parse-empty.js +7 -0
  4. package/dist/color-parse.d.ts +8 -0
  5. package/dist/color-parse.js +49 -0
  6. package/dist/index.d.ts +372 -0
  7. package/dist/index.js +2640 -0
  8. package/dist/paint-ChCPh-rm.d.ts +29 -0
  9. package/dist/payload.d.ts +53 -0
  10. package/dist/payload.js +93 -0
  11. package/dist/server.d.ts +399 -0
  12. package/dist/server.js +2833 -0
  13. package/dist/source/components/GradientDef.jsx +19 -0
  14. package/dist/source/components/QRCode.jsx +10 -0
  15. package/dist/source/components/QRCodeCanvas.jsx +72 -0
  16. package/dist/source/components/QRCodeSVG.jsx +57 -0
  17. package/dist/source/core/caption.js +77 -0
  18. package/dist/source/core/color-names.js +34 -0
  19. package/dist/source/core/color-parse-empty.js +5 -0
  20. package/dist/source/core/color-parse.js +41 -0
  21. package/dist/source/core/encode.js +120 -0
  22. package/dist/source/core/logo.js +90 -0
  23. package/dist/source/core/options.js +56 -0
  24. package/dist/source/core/output.js +23 -0
  25. package/dist/source/core/paint.js +30 -0
  26. package/dist/source/core/path.js +46 -0
  27. package/dist/source/core/qrcodegen.js +875 -0
  28. package/dist/source/core/scene.js +141 -0
  29. package/dist/source/core/stages.js +24 -0
  30. package/dist/source/core/warnings.js +38 -0
  31. package/dist/source/export/index.js +105 -0
  32. package/dist/source/index.js +16 -0
  33. package/dist/source/payload/contact.js +42 -0
  34. package/dist/source/payload/escape.js +3 -0
  35. package/dist/source/payload/index.js +3 -0
  36. package/dist/source/payload/message.js +19 -0
  37. package/dist/source/payload/place.js +40 -0
  38. package/dist/source/primitives/createColorScheme.js +18 -0
  39. package/dist/source/primitives/createPixelRatio.js +25 -0
  40. package/dist/source/primitives/createQRCode.js +47 -0
  41. package/dist/source/render/canvas.js +46 -0
  42. package/dist/source/render/color.js +63 -0
  43. package/dist/source/render/image.js +123 -0
  44. package/dist/source/render/svg-string.js +55 -0
  45. package/dist/source/shapes/bars.js +50 -0
  46. package/dist/source/shapes/finders.js +30 -0
  47. package/dist/source/shapes/frames.js +62 -0
  48. package/dist/source/shapes/modules.js +39 -0
  49. package/dist/source/shapes/types.js +8 -0
  50. package/llms.txt +117 -0
  51. package/package.json +95 -6
  52. package/skills/qrcodesolid/SKILL.md +101 -0
@@ -0,0 +1,875 @@
1
+ /**
2
+ * @license QR Code generator library (TypeScript)
3
+ * Copyright (c) Project Nayuki.
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * Local change: the mask penalty scoring was optimised with typed arrays and fewer passes.
7
+ * Its scores match the original bit for bit; test/penalty.test.ts checks this.
8
+ */
9
+ "use strict";
10
+ var qrcodegen;
11
+ (function (qrcodegen) {
12
+ /*---- QR Code symbol class ----*/
13
+ /*
14
+ * A QR Code symbol, which is a type of two-dimension barcode.
15
+ * Invented by Denso Wave and described in the ISO/IEC 18004 standard.
16
+ * Instances of this class represent an immutable square grid of dark and light cells.
17
+ * The class provides static factory functions to create a QR Code from text or binary data.
18
+ * The class covers the QR Code Model 2 specification, supporting all versions (sizes)
19
+ * from 1 to 40, all 4 error correction levels, and 4 character encoding modes.
20
+ *
21
+ * Ways to create a QR Code object:
22
+ * - High level: Take the payload data and call QrCode.encodeText() or QrCode.encodeBinary().
23
+ * - Mid level: Custom-make the list of segments and call QrCode.encodeSegments().
24
+ * - Low level: Custom-make the array of data codeword bytes (including
25
+ * segment headers and final padding, excluding error correction codewords),
26
+ * supply the appropriate version number, and call the QrCode() constructor.
27
+ * (Note that all ways require supplying the desired error correction level.)
28
+ */
29
+ class QrCode {
30
+ version;
31
+ errorCorrectionLevel;
32
+ /*-- Static factory functions (high level) --*/
33
+ // Returns a QR Code representing the given Unicode text string at the given error correction level.
34
+ // As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer
35
+ // Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible
36
+ // QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
37
+ // ecl argument if it can be done without increasing the version.
38
+ static encodeText(text, ecl) {
39
+ const segs = qrcodegen.QrSegment.makeSegments(text);
40
+ return QrCode.encodeSegments(segs, ecl);
41
+ }
42
+ // Returns a QR Code representing the given binary data at the given error correction level.
43
+ // This function always encodes using the binary segment mode, not any text mode. The maximum number of
44
+ // bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
45
+ // The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
46
+ static encodeBinary(data, ecl) {
47
+ const seg = qrcodegen.QrSegment.makeBytes(data);
48
+ return QrCode.encodeSegments([seg], ecl);
49
+ }
50
+ /*-- Static factory functions (mid level) --*/
51
+ // Returns a QR Code representing the given segments with the given encoding parameters.
52
+ // The smallest possible QR Code version within the given range is automatically
53
+ // chosen for the output. Iff boostEcl is true, then the ECC level of the result
54
+ // may be higher than the ecl argument if it can be done without increasing the
55
+ // version. The mask number is either between 0 to 7 (inclusive) to force that
56
+ // mask, or -1 to automatically choose an appropriate mask (which may be slow).
57
+ // This function allows the user to create a custom sequence of segments that switches
58
+ // between modes (such as alphanumeric and byte) to encode text in less space.
59
+ // This is a mid-level API; the high-level API is encodeText() and encodeBinary().
60
+ static encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
61
+ if (!(QrCode.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= QrCode.MAX_VERSION)
62
+ || mask < -1 || mask > 7)
63
+ throw new RangeError("Invalid value");
64
+ // Find the minimal version number to use
65
+ let version;
66
+ let dataUsedBits;
67
+ for (version = minVersion;; version++) {
68
+ const dataCapacityBits = QrCode.getNumDataCodewords(version, ecl) * 8; // Number of data bits available
69
+ const usedBits = QrSegment.getTotalBits(segs, version);
70
+ if (usedBits <= dataCapacityBits) {
71
+ dataUsedBits = usedBits;
72
+ break; // This version number is found to be suitable
73
+ }
74
+ if (version >= maxVersion) // All versions in the range could not fit the given data
75
+ throw new RangeError("Data too long");
76
+ }
77
+ // Increase the error correction level while the data still fits in the current version number
78
+ for (const newEcl of [QrCode.Ecc.MEDIUM, QrCode.Ecc.QUARTILE, QrCode.Ecc.HIGH]) { // From low to high
79
+ if (boostEcl && dataUsedBits <= QrCode.getNumDataCodewords(version, newEcl) * 8)
80
+ ecl = newEcl;
81
+ }
82
+ // Concatenate all segments to create the data bit string
83
+ let bb = [];
84
+ for (const seg of segs) {
85
+ appendBits(seg.mode.modeBits, 4, bb);
86
+ appendBits(seg.numChars, seg.mode.numCharCountBits(version), bb);
87
+ for (const b of seg.getData())
88
+ bb.push(b);
89
+ }
90
+ assert(bb.length == dataUsedBits);
91
+ // Add terminator and pad up to a byte if applicable
92
+ const dataCapacityBits = QrCode.getNumDataCodewords(version, ecl) * 8;
93
+ assert(bb.length <= dataCapacityBits);
94
+ appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
95
+ appendBits(0, (8 - bb.length % 8) % 8, bb);
96
+ assert(bb.length % 8 == 0);
97
+ // Pad with alternating bytes until data capacity is reached
98
+ for (let padByte = 0xEC; bb.length < dataCapacityBits; padByte ^= 0xEC ^ 0x11)
99
+ appendBits(padByte, 8, bb);
100
+ // Pack bits into bytes in big endian
101
+ let dataCodewords = [];
102
+ while (dataCodewords.length * 8 < bb.length)
103
+ dataCodewords.push(0);
104
+ bb.forEach((b, i) => dataCodewords[i >>> 3] |= b << (7 - (i & 7)));
105
+ // Create the QR Code object
106
+ return new QrCode(version, ecl, dataCodewords, mask);
107
+ }
108
+ /*-- Fields --*/
109
+ // The width and height of this QR Code, measured in modules, between
110
+ // 21 and 177 (inclusive). This is equal to version * 4 + 17.
111
+ size;
112
+ // The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
113
+ // Even if a QR Code is created with automatic masking requested (mask = -1),
114
+ // the resulting object still has a mask value between 0 and 7.
115
+ mask;
116
+ // The modules of this QR Code (false = light, true = dark).
117
+ // Immutable after constructor finishes. Accessed through getModule().
118
+ modules = [];
119
+ // Indicates function modules that are not subjected to masking. Discarded when constructor finishes.
120
+ isFunction = [];
121
+ /*-- Constructor (low level) and fields --*/
122
+ // Creates a new QR Code with the given version number,
123
+ // error correction level, data codeword bytes, and mask number.
124
+ // This is a low-level API that most users should not use directly.
125
+ // A mid-level API is the encodeSegments() function.
126
+ constructor(
127
+ // The version number of this QR Code, which is between 1 and 40 (inclusive).
128
+ // This determines the size of this barcode.
129
+ version,
130
+ // The error correction level used in this QR Code.
131
+ errorCorrectionLevel, dataCodewords, msk) {
132
+ this.version = version;
133
+ this.errorCorrectionLevel = errorCorrectionLevel;
134
+ // Check scalar arguments
135
+ if (version < QrCode.MIN_VERSION || version > QrCode.MAX_VERSION)
136
+ throw new RangeError("Version value out of range");
137
+ if (msk < -1 || msk > 7)
138
+ throw new RangeError("Mask value out of range");
139
+ this.size = version * 4 + 17;
140
+ // Initialize both grids to be size*size arrays of Boolean false
141
+ let row = [];
142
+ for (let i = 0; i < this.size; i++)
143
+ row.push(false);
144
+ for (let i = 0; i < this.size; i++) {
145
+ this.modules.push(row.slice()); // Initially all light
146
+ this.isFunction.push(row.slice());
147
+ }
148
+ // Compute ECC, draw modules
149
+ this.drawFunctionPatterns();
150
+ const allCodewords = this.addEccAndInterleave(dataCodewords);
151
+ this.drawCodewords(allCodewords);
152
+ // Do masking
153
+ if (msk == -1) { // Automatically choose best mask
154
+ // Local change: each mask is scored on a typed grid, so the modules are not masked twice.
155
+ const cells = this.size * this.size;
156
+ const base = new Uint8Array(cells);
157
+ const free = new Uint8Array(cells); // 1 where the mask applies
158
+ for (let y = 0; y < this.size; y++) {
159
+ for (let x = 0; x < this.size; x++) {
160
+ base[y * this.size + x] = this.modules[y][x] ? 1 : 0;
161
+ free[y * this.size + x] = this.isFunction[y][x] ? 0 : 1;
162
+ }
163
+ }
164
+ const grid = new Uint8Array(cells);
165
+ let minPenalty = 1000000000;
166
+ for (let i = 0; i < 8; i++) {
167
+ this.drawFormatBits(i);
168
+ this.fillMaskedGrid(i, base, free, grid);
169
+ const penalty = getPenaltyScore(grid, this.size);
170
+ if (penalty < minPenalty) {
171
+ msk = i;
172
+ minPenalty = penalty;
173
+ }
174
+ }
175
+ }
176
+ assert(0 <= msk && msk <= 7);
177
+ this.mask = msk;
178
+ this.applyMask(msk); // Apply the final choice of mask
179
+ this.drawFormatBits(msk); // Overwrite old format bits
180
+ this.isFunction = [];
181
+ }
182
+ /*-- Accessor methods --*/
183
+ // Returns the color of the module (pixel) at the given coordinates, which is false
184
+ // for light or true for dark. The top left corner has the coordinates (x=0, y=0).
185
+ // If the given coordinates are out of bounds, then false (light) is returned.
186
+ getModule(x, y) {
187
+ return 0 <= x && x < this.size && 0 <= y && y < this.size && this.modules[y][x];
188
+ }
189
+ // Modified to expose modules for easy access
190
+ getModules() {
191
+ return this.modules;
192
+ }
193
+ /*-- Private helper methods for constructor: Drawing function modules --*/
194
+ // Reads this object's version field, and draws and marks all function modules.
195
+ drawFunctionPatterns() {
196
+ // Draw horizontal and vertical timing patterns
197
+ for (let i = 0; i < this.size; i++) {
198
+ this.setFunctionModule(6, i, i % 2 == 0);
199
+ this.setFunctionModule(i, 6, i % 2 == 0);
200
+ }
201
+ // Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules)
202
+ this.drawFinderPattern(3, 3);
203
+ this.drawFinderPattern(this.size - 4, 3);
204
+ this.drawFinderPattern(3, this.size - 4);
205
+ // Draw numerous alignment patterns
206
+ const alignPatPos = this.getAlignmentPatternPositions();
207
+ const numAlign = alignPatPos.length;
208
+ for (let i = 0; i < numAlign; i++) {
209
+ for (let j = 0; j < numAlign; j++) {
210
+ // Don't draw on the three finder corners
211
+ if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0))
212
+ this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
213
+ }
214
+ }
215
+ // Draw configuration data
216
+ this.drawFormatBits(0); // Dummy mask value; overwritten later in the constructor
217
+ this.drawVersion();
218
+ }
219
+ // Draws two copies of the format bits (with its own error correction code)
220
+ // based on the given mask and this object's error correction level field.
221
+ drawFormatBits(mask) {
222
+ // Calculate error correction code and pack bits
223
+ const data = this.errorCorrectionLevel.formatBits << 3 | mask; // errCorrLvl is uint2, mask is uint3
224
+ let rem = data;
225
+ for (let i = 0; i < 10; i++)
226
+ rem = (rem << 1) ^ ((rem >>> 9) * 0x537);
227
+ const bits = (data << 10 | rem) ^ 0x5412; // uint15
228
+ assert(bits >>> 15 == 0);
229
+ // Draw first copy
230
+ for (let i = 0; i <= 5; i++)
231
+ this.setFunctionModule(8, i, getBit(bits, i));
232
+ this.setFunctionModule(8, 7, getBit(bits, 6));
233
+ this.setFunctionModule(8, 8, getBit(bits, 7));
234
+ this.setFunctionModule(7, 8, getBit(bits, 8));
235
+ for (let i = 9; i < 15; i++)
236
+ this.setFunctionModule(14 - i, 8, getBit(bits, i));
237
+ // Draw second copy
238
+ for (let i = 0; i < 8; i++)
239
+ this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
240
+ for (let i = 8; i < 15; i++)
241
+ this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
242
+ this.setFunctionModule(8, this.size - 8, true); // Always dark
243
+ }
244
+ // Draws two copies of the version bits (with its own error correction code),
245
+ // based on this object's version field, iff 7 <= version <= 40.
246
+ drawVersion() {
247
+ if (this.version < 7)
248
+ return;
249
+ // Calculate error correction code and pack bits
250
+ let rem = this.version; // version is uint6, in the range [7, 40]
251
+ for (let i = 0; i < 12; i++)
252
+ rem = (rem << 1) ^ ((rem >>> 11) * 0x1F25);
253
+ const bits = this.version << 12 | rem; // uint18
254
+ assert(bits >>> 18 == 0);
255
+ // Draw two copies
256
+ for (let i = 0; i < 18; i++) {
257
+ const color = getBit(bits, i);
258
+ const a = this.size - 11 + i % 3;
259
+ const b = Math.floor(i / 3);
260
+ this.setFunctionModule(a, b, color);
261
+ this.setFunctionModule(b, a, color);
262
+ }
263
+ }
264
+ // Draws a 9*9 finder pattern including the border separator,
265
+ // with the center module at (x, y). Modules can be out of bounds.
266
+ drawFinderPattern(x, y) {
267
+ for (let dy = -4; dy <= 4; dy++) {
268
+ for (let dx = -4; dx <= 4; dx++) {
269
+ const dist = Math.max(Math.abs(dx), Math.abs(dy)); // Chebyshev/infinity norm
270
+ const xx = x + dx;
271
+ const yy = y + dy;
272
+ if (0 <= xx && xx < this.size && 0 <= yy && yy < this.size)
273
+ this.setFunctionModule(xx, yy, dist != 2 && dist != 4);
274
+ }
275
+ }
276
+ }
277
+ // Draws a 5*5 alignment pattern, with the center module
278
+ // at (x, y). All modules must be in bounds.
279
+ drawAlignmentPattern(x, y) {
280
+ for (let dy = -2; dy <= 2; dy++) {
281
+ for (let dx = -2; dx <= 2; dx++)
282
+ this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
283
+ }
284
+ }
285
+ // Sets the color of a module and marks it as a function module.
286
+ // Only used by the constructor. Coordinates must be in bounds.
287
+ setFunctionModule(x, y, isDark) {
288
+ this.modules[y][x] = isDark;
289
+ this.isFunction[y][x] = true;
290
+ }
291
+ /*-- Private helper methods for constructor: Codewords and masking --*/
292
+ // Returns a new byte string representing the given data with the appropriate error correction
293
+ // codewords appended to it, based on this object's version and error correction level.
294
+ addEccAndInterleave(data) {
295
+ const ver = this.version;
296
+ const ecl = this.errorCorrectionLevel;
297
+ if (data.length != QrCode.getNumDataCodewords(ver, ecl))
298
+ throw new RangeError("Invalid argument");
299
+ // Calculate parameter numbers
300
+ const numBlocks = QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
301
+ const blockEccLen = QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver];
302
+ const rawCodewords = Math.floor(QrCode.getNumRawDataModules(ver) / 8);
303
+ const numShortBlocks = numBlocks - rawCodewords % numBlocks;
304
+ const shortBlockLen = Math.floor(rawCodewords / numBlocks);
305
+ // Split data into blocks and append ECC to each block
306
+ let blocks = [];
307
+ const rsDiv = QrCode.reedSolomonComputeDivisor(blockEccLen);
308
+ for (let i = 0, k = 0; i < numBlocks; i++) {
309
+ let dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
310
+ k += dat.length;
311
+ const ecc = QrCode.reedSolomonComputeRemainder(dat, rsDiv);
312
+ if (i < numShortBlocks)
313
+ dat.push(0);
314
+ blocks.push(dat.concat(ecc));
315
+ }
316
+ // Interleave (not concatenate) the bytes from every block into a single sequence
317
+ let result = [];
318
+ for (let i = 0; i < blocks[0].length; i++) {
319
+ blocks.forEach((block, j) => {
320
+ // Skip the padding byte in short blocks
321
+ if (i != shortBlockLen - blockEccLen || j >= numShortBlocks)
322
+ result.push(block[i]);
323
+ });
324
+ }
325
+ assert(result.length == rawCodewords);
326
+ return result;
327
+ }
328
+ // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
329
+ // data area of this QR Code. Function modules need to be marked off before this is called.
330
+ drawCodewords(data) {
331
+ if (data.length != Math.floor(QrCode.getNumRawDataModules(this.version) / 8))
332
+ throw new RangeError("Invalid argument");
333
+ let i = 0; // Bit index into the data
334
+ // Do the funny zigzag scan
335
+ for (let right = this.size - 1; right >= 1; right -= 2) { // Index of right column in each column pair
336
+ if (right == 6)
337
+ right = 5;
338
+ for (let vert = 0; vert < this.size; vert++) { // Vertical counter
339
+ for (let j = 0; j < 2; j++) {
340
+ const x = right - j; // Actual x coordinate
341
+ const upward = ((right + 1) & 2) == 0;
342
+ const y = upward ? this.size - 1 - vert : vert; // Actual y coordinate
343
+ if (!this.isFunction[y][x] && i < data.length * 8) {
344
+ this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
345
+ i++;
346
+ }
347
+ // If this QR Code has any remainder bits (0 to 7), they were assigned as
348
+ // 0/false/light by the constructor and are left unchanged by this method
349
+ }
350
+ }
351
+ }
352
+ assert(i == data.length * 8);
353
+ }
354
+ // XORs the codeword modules in this QR Code with the given mask pattern.
355
+ // The function modules must be marked and the codeword bits must be drawn
356
+ // before masking. Due to the arithmetic of XOR, calling applyMask() with
357
+ // the same mask value a second time will undo the mask. A final well-formed
358
+ // QR Code needs exactly one (not zero, two, etc.) mask applied.
359
+ applyMask(mask) {
360
+ if (mask < 0 || mask > 7)
361
+ throw new RangeError("Mask value out of range");
362
+ for (let y = 0; y < this.size; y++) {
363
+ for (let x = 0; x < this.size; x++) {
364
+ if (!this.isFunction[y][x] && maskBit(mask, x, y))
365
+ this.modules[y][x] = !this.modules[y][x];
366
+ }
367
+ }
368
+ }
369
+ // Writes base with the given mask applied into grid, then copies the format bits,
370
+ // which lie on row 8 and column 8.
371
+ fillMaskedGrid(mask, base, free, grid) {
372
+ const size = this.size;
373
+ const pattern = getMaskPattern(mask);
374
+ for (let y = 0, p = 0; y < size; y++) {
375
+ const row = (y % MASK_PERIOD) * MASK_PERIOD;
376
+ for (let x = 0, column = 0; x < size; x++, p++) {
377
+ grid[p] = base[p] ^ (pattern[row + column] & free[p]);
378
+ if (++column == MASK_PERIOD)
379
+ column = 0;
380
+ }
381
+ }
382
+ for (let i = 0; i < size; i++) {
383
+ if (this.isFunction[8][i])
384
+ grid[8 * size + i] = this.modules[8][i] ? 1 : 0;
385
+ if (this.isFunction[i][8])
386
+ grid[i * size + 8] = this.modules[i][8] ? 1 : 0;
387
+ }
388
+ }
389
+ /*-- Private helper functions --*/
390
+ // Returns an ascending list of positions of alignment patterns for this version number.
391
+ // Each position is in the range [0,177), and are used on both the x and y axes.
392
+ // This could be implemented as lookup table of 40 variable-length lists of integers.
393
+ getAlignmentPatternPositions() {
394
+ if (this.version == 1)
395
+ return [];
396
+ else {
397
+ const numAlign = Math.floor(this.version / 7) + 2;
398
+ const step = (this.version == 32) ? 26 :
399
+ Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
400
+ let result = [6];
401
+ for (let pos = this.size - 7; result.length < numAlign; pos -= step)
402
+ result.splice(1, 0, pos);
403
+ return result;
404
+ }
405
+ }
406
+ // Returns the number of data bits that can be stored in a QR Code of the given version number, after
407
+ // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
408
+ // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
409
+ static getNumRawDataModules(ver) {
410
+ if (ver < QrCode.MIN_VERSION || ver > QrCode.MAX_VERSION)
411
+ throw new RangeError("Version number out of range");
412
+ let result = (16 * ver + 128) * ver + 64;
413
+ if (ver >= 2) {
414
+ const numAlign = Math.floor(ver / 7) + 2;
415
+ result -= (25 * numAlign - 10) * numAlign - 55;
416
+ if (ver >= 7)
417
+ result -= 36;
418
+ }
419
+ assert(208 <= result && result <= 29648);
420
+ return result;
421
+ }
422
+ // Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
423
+ // QR Code of the given version number and error correction level, with remainder bits discarded.
424
+ // This stateless pure function could be implemented as a (40*4)-cell lookup table.
425
+ static getNumDataCodewords(ver, ecl) {
426
+ return Math.floor(QrCode.getNumRawDataModules(ver) / 8) -
427
+ QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] *
428
+ QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
429
+ }
430
+ // Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
431
+ // implemented as a lookup table over all possible parameter values, instead of as an algorithm.
432
+ static reedSolomonComputeDivisor(degree) {
433
+ if (degree < 1 || degree > 255)
434
+ throw new RangeError("Degree out of range");
435
+ // Polynomial coefficients are stored from highest to lowest power, excluding the leading term which is always 1.
436
+ // For example the polynomial x^3 + 255x^2 + 8x + 93 is stored as the uint8 array [255, 8, 93].
437
+ let result = [];
438
+ for (let i = 0; i < degree - 1; i++)
439
+ result.push(0);
440
+ result.push(1); // Start off with the monomial x^0
441
+ // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}),
442
+ // and drop the highest monomial term which is always 1x^degree.
443
+ // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D).
444
+ let root = 1;
445
+ for (let i = 0; i < degree; i++) {
446
+ // Multiply the current product by (x - r^i)
447
+ for (let j = 0; j < result.length; j++) {
448
+ result[j] = QrCode.reedSolomonMultiply(result[j], root);
449
+ if (j + 1 < result.length)
450
+ result[j] ^= result[j + 1];
451
+ }
452
+ root = QrCode.reedSolomonMultiply(root, 0x02);
453
+ }
454
+ return result;
455
+ }
456
+ // Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
457
+ static reedSolomonComputeRemainder(data, divisor) {
458
+ let result = divisor.map(_ => 0);
459
+ for (const b of data) { // Polynomial division
460
+ const factor = b ^ result.shift();
461
+ result.push(0);
462
+ divisor.forEach((coef, i) => result[i] ^= QrCode.reedSolomonMultiply(coef, factor));
463
+ }
464
+ return result;
465
+ }
466
+ // Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result
467
+ // are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
468
+ static reedSolomonMultiply(x, y) {
469
+ if (x >>> 8 != 0 || y >>> 8 != 0)
470
+ throw new RangeError("Byte out of range");
471
+ // Russian peasant multiplication
472
+ let z = 0;
473
+ for (let i = 7; i >= 0; i--) {
474
+ z = (z << 1) ^ ((z >>> 7) * 0x11D);
475
+ z ^= ((y >>> i) & 1) * x;
476
+ }
477
+ assert(z >>> 8 == 0);
478
+ return z;
479
+ }
480
+ /*-- Constants and tables --*/
481
+ // The minimum version number supported in the QR Code Model 2 standard.
482
+ static MIN_VERSION = 1;
483
+ // The maximum version number supported in the QR Code Model 2 standard.
484
+ static MAX_VERSION = 40;
485
+ static ECC_CODEWORDS_PER_BLOCK = [
486
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
487
+ //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
488
+ [-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
489
+ [-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
490
+ [-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
491
+ [-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
492
+ ];
493
+ static NUM_ERROR_CORRECTION_BLOCKS = [
494
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
495
+ //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
496
+ [-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
497
+ [-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
498
+ [-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
499
+ [-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
500
+ ];
501
+ }
502
+ qrcodegen.QrCode = QrCode;
503
+ // Appends the given number of low-order bits of the given value
504
+ // to the given buffer. Requires 0 <= len <= 31 and 0 <= val < 2^len.
505
+ function appendBits(val, len, bb) {
506
+ if (len < 0 || len > 31 || val >>> len != 0)
507
+ throw new RangeError("Value out of range");
508
+ for (let i = len - 1; i >= 0; i--) // Append bit by bit
509
+ bb.push((val >>> i) & 1);
510
+ }
511
+ // Returns true iff the i'th bit of x is set to 1.
512
+ function getBit(x, i) {
513
+ return ((x >>> i) & 1) != 0;
514
+ }
515
+ // Returns true iff the given mask pattern inverts the module at (x, y).
516
+ function maskBit(mask, x, y) {
517
+ switch (mask) {
518
+ case 0: return (x + y) % 2 == 0;
519
+ case 1: return y % 2 == 0;
520
+ case 2: return x % 3 == 0;
521
+ case 3: return (x + y) % 3 == 0;
522
+ case 4: return (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0;
523
+ case 5: return x * y % 2 + x * y % 3 == 0;
524
+ case 6: return (x * y % 2 + x * y % 3) % 2 == 0;
525
+ case 7: return ((x + y) % 2 + x * y % 3) % 2 == 0;
526
+ default: throw new Error("Unreachable");
527
+ }
528
+ }
529
+ // Every mask pattern repeats every 12 modules in x and in y.
530
+ const MASK_PERIOD = 12;
531
+ const maskPatterns = [];
532
+ // Returns the 12*12 tile of the given mask pattern, 1 where it inverts.
533
+ function getMaskPattern(mask) {
534
+ if (!maskPatterns[mask]) {
535
+ const tile = new Uint8Array(MASK_PERIOD * MASK_PERIOD);
536
+ for (let y = 0; y < MASK_PERIOD; y++)
537
+ for (let x = 0; x < MASK_PERIOD; x++)
538
+ tile[y * MASK_PERIOD + x] = maskBit(mask, x, y) ? 1 : 0;
539
+ maskPatterns[mask] = tile;
540
+ }
541
+ return maskPatterns[mask];
542
+ }
543
+ const PENALTY_N1 = 3;
544
+ const PENALTY_N2 = 3;
545
+ const PENALTY_N3 = 40;
546
+ const PENALTY_N4 = 10;
547
+ // Penalty of a 2*2 block by its number of dark modules: only a block of one color scores.
548
+ const BLOCK_PENALTY = new Uint8Array([PENALTY_N2, 0, 0, 0, PENALTY_N2]);
549
+ // Calculates the penalty score of a masked grid (row-major, 1 = dark). The automatic
550
+ // mask choice picks the mask with the lowest score.
551
+ function getPenaltyScore(grid, size) {
552
+ let result = 0;
553
+ // Adjacent modules in a row or column having same color, and finder-like patterns
554
+ const runStarts = new Int32Array(size + 1);
555
+ for (let i = 0; i < size; i++) {
556
+ result += getLinePenalty(grid, i * size, 1, size, runStarts);
557
+ result += getLinePenalty(grid, i, size, size, runStarts);
558
+ }
559
+ // 2*2 blocks of modules having same color, and the balance of dark and light modules
560
+ let dark = 0;
561
+ for (let y = 0; y < size - 1; y++) {
562
+ let p = y * size;
563
+ let left = grid[p] + grid[p + size];
564
+ dark += grid[p];
565
+ for (let x = 1; x < size; x++) {
566
+ p++;
567
+ const right = grid[p] + grid[p + size];
568
+ result += BLOCK_PENALTY[left + right];
569
+ dark += grid[p];
570
+ left = right;
571
+ }
572
+ }
573
+ for (let p = (size - 1) * size; p < size * size; p++)
574
+ dark += grid[p];
575
+ const total = size * size; // Note that size is odd, so dark/total != 1/2
576
+ // Compute the smallest integer k >= 0 such that (45-5k)% <= dark/total <= (55+5k)%
577
+ const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
578
+ assert(0 <= k && k <= 9);
579
+ result += k * PENALTY_N4;
580
+ assert(0 <= result && result <= 2568888); // Non-tight upper bound based on default values of PENALTY_N1, ..., N4
581
+ return result;
582
+ }
583
+ qrcodegen.getPenaltyScore = getPenaltyScore;
584
+ // Scores one row or column: runs of 5 or more, and finder-like patterns.
585
+ // It first records where each run starts without branching on color, because module
586
+ // colors are close to random and a branch per module mispredicts often.
587
+ function getLinePenalty(grid, start, step, size, runStarts) {
588
+ const firstColor = grid[start];
589
+ let runs = 1;
590
+ let previous = firstColor;
591
+ runStarts[0] = 0;
592
+ for (let i = 1, p = start + step; i < size; i++, p += step) {
593
+ const color = grid[p];
594
+ runStarts[runs] = i;
595
+ runs += color ^ previous;
596
+ previous = color;
597
+ }
598
+ runStarts[runs] = size;
599
+ let result = 0;
600
+ // The run history, h0 newest. A line starts with a light run, of length 0 if the
601
+ // first module is dark, and the first run gets the light border of length size.
602
+ let h0 = 0, h1 = 0, h2 = 0, h3 = 0, h4 = 0, h5 = 0, h6 = 0;
603
+ let color = firstColor;
604
+ if (color == 1) {
605
+ h0 = size;
606
+ result += countFinderPatterns(h0, h1, h2, h3, h4, h5, h6) * PENALTY_N3;
607
+ }
608
+ for (let r = 0; r < runs; r++, color ^= 1) {
609
+ let length = runStarts[r + 1] - runStarts[r];
610
+ if (length >= 5)
611
+ result += PENALTY_N1 + length - 5;
612
+ const last = r == runs - 1;
613
+ if (last && color == 0)
614
+ length += size; // Add light border to final run
615
+ h6 = h5;
616
+ h5 = h4;
617
+ h4 = h3;
618
+ h3 = h2;
619
+ h2 = h1;
620
+ h1 = h0;
621
+ h0 = h1 == 0 ? length + size : length; // Add light border to initial run
622
+ if (color == 0)
623
+ result += countFinderPatterns(h0, h1, h2, h3, h4, h5, h6) * PENALTY_N3;
624
+ }
625
+ if (color == 0) { // The last run was dark: add the light border as a final run
626
+ h6 = h5;
627
+ h5 = h4;
628
+ h4 = h3;
629
+ h3 = h2;
630
+ h2 = h1;
631
+ h1 = h0;
632
+ h0 = size;
633
+ result += countFinderPatterns(h0, h1, h2, h3, h4, h5, h6) * PENALTY_N3;
634
+ }
635
+ return result;
636
+ }
637
+ // Can only be called immediately after a light run is added, and
638
+ // returns either 0, 1, or 2. A helper function for getLinePenalty().
639
+ function countFinderPatterns(h0, h1, h2, h3, h4, h5, h6) {
640
+ const n = h1;
641
+ const core = n > 0 && h2 == n && h3 == n * 3 && h4 == n && h5 == n;
642
+ return (core && h0 >= n * 4 && h6 >= n ? 1 : 0)
643
+ + (core && h6 >= n * 4 && h0 >= n ? 1 : 0);
644
+ }
645
+ // Throws an exception if the given condition is false.
646
+ function assert(cond) {
647
+ if (!cond)
648
+ throw new Error("Assertion error");
649
+ }
650
+ /*---- Data segment class ----*/
651
+ /*
652
+ * A segment of character/binary/control data in a QR Code symbol.
653
+ * Instances of this class are immutable.
654
+ * The mid-level way to create a segment is to take the payload data
655
+ * and call a static factory function such as QrSegment.makeNumeric().
656
+ * The low-level way to create a segment is to custom-make the bit buffer
657
+ * and call the QrSegment() constructor with appropriate values.
658
+ * This segment class imposes no length restrictions, but QR Codes have restrictions.
659
+ * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
660
+ * Any segment longer than this is meaningless for the purpose of generating QR Codes.
661
+ */
662
+ class QrSegment {
663
+ mode;
664
+ numChars;
665
+ bitData;
666
+ /*-- Static factory functions (mid level) --*/
667
+ // Returns a segment representing the given binary data encoded in
668
+ // byte mode. All input byte arrays are acceptable. Any text string
669
+ // can be converted to UTF-8 bytes and encoded as a byte mode segment.
670
+ static makeBytes(data) {
671
+ let bb = [];
672
+ for (const b of data)
673
+ appendBits(b, 8, bb);
674
+ return new QrSegment(QrSegment.Mode.BYTE, data.length, bb);
675
+ }
676
+ // Returns a segment representing the given string of decimal digits encoded in numeric mode.
677
+ static makeNumeric(digits) {
678
+ if (!QrSegment.isNumeric(digits))
679
+ throw new RangeError("String contains non-numeric characters");
680
+ let bb = [];
681
+ for (let i = 0; i < digits.length;) { // Consume up to 3 digits per iteration
682
+ const n = Math.min(digits.length - i, 3);
683
+ appendBits(parseInt(digits.substring(i, i + n), 10), n * 3 + 1, bb);
684
+ i += n;
685
+ }
686
+ return new QrSegment(QrSegment.Mode.NUMERIC, digits.length, bb);
687
+ }
688
+ // Returns a segment representing the given text string encoded in alphanumeric mode.
689
+ // The characters allowed are: 0 to 9, A to Z (uppercase only), space,
690
+ // dollar, percent, asterisk, plus, hyphen, period, slash, colon.
691
+ static makeAlphanumeric(text) {
692
+ if (!QrSegment.isAlphanumeric(text))
693
+ throw new RangeError("String contains unencodable characters in alphanumeric mode");
694
+ let bb = [];
695
+ let i;
696
+ for (i = 0; i + 2 <= text.length; i += 2) { // Process groups of 2
697
+ let temp = QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
698
+ temp += QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
699
+ appendBits(temp, 11, bb);
700
+ }
701
+ if (i < text.length) // 1 character remaining
702
+ appendBits(QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
703
+ return new QrSegment(QrSegment.Mode.ALPHANUMERIC, text.length, bb);
704
+ }
705
+ // Returns a new mutable list of zero or more segments to represent the given Unicode text string.
706
+ // The result may use various segment modes and switch modes to optimize the length of the bit stream.
707
+ static makeSegments(text) {
708
+ // Select the most efficient segment encoding automatically
709
+ if (text == "")
710
+ return [];
711
+ else if (QrSegment.isNumeric(text))
712
+ return [QrSegment.makeNumeric(text)];
713
+ else if (QrSegment.isAlphanumeric(text))
714
+ return [QrSegment.makeAlphanumeric(text)];
715
+ else
716
+ return [QrSegment.makeBytes(QrSegment.toUtf8ByteArray(text))];
717
+ }
718
+ // Returns a segment representing an Extended Channel Interpretation
719
+ // (ECI) designator with the given assignment value.
720
+ static makeEci(assignVal) {
721
+ let bb = [];
722
+ if (assignVal < 0)
723
+ throw new RangeError("ECI assignment value out of range");
724
+ else if (assignVal < (1 << 7))
725
+ appendBits(assignVal, 8, bb);
726
+ else if (assignVal < (1 << 14)) {
727
+ appendBits(0b10, 2, bb);
728
+ appendBits(assignVal, 14, bb);
729
+ }
730
+ else if (assignVal < 1000000) {
731
+ appendBits(0b110, 3, bb);
732
+ appendBits(assignVal, 21, bb);
733
+ }
734
+ else
735
+ throw new RangeError("ECI assignment value out of range");
736
+ return new QrSegment(QrSegment.Mode.ECI, 0, bb);
737
+ }
738
+ // Tests whether the given string can be encoded as a segment in numeric mode.
739
+ // A string is encodable iff each character is in the range 0 to 9.
740
+ static isNumeric(text) {
741
+ return QrSegment.NUMERIC_REGEX.test(text);
742
+ }
743
+ // Tests whether the given string can be encoded as a segment in alphanumeric mode.
744
+ // A string is encodable iff each character is in the following set: 0 to 9, A to Z
745
+ // (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
746
+ static isAlphanumeric(text) {
747
+ return QrSegment.ALPHANUMERIC_REGEX.test(text);
748
+ }
749
+ /*-- Constructor (low level) and fields --*/
750
+ // Creates a new QR Code segment with the given attributes and data.
751
+ // The character count (numChars) must agree with the mode and the bit buffer length,
752
+ // but the constraint isn't checked. The given bit buffer is cloned and stored.
753
+ constructor(
754
+ // The mode indicator of this segment.
755
+ mode,
756
+ // The length of this segment's unencoded data. Measured in characters for
757
+ // numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode.
758
+ // Always zero or positive. Not the same as the data's bit length.
759
+ numChars,
760
+ // The data bits of this segment. Accessed through getData().
761
+ bitData) {
762
+ this.mode = mode;
763
+ this.numChars = numChars;
764
+ this.bitData = bitData;
765
+ if (numChars < 0)
766
+ throw new RangeError("Invalid argument");
767
+ this.bitData = bitData.slice(); // Make defensive copy
768
+ }
769
+ /*-- Methods --*/
770
+ // Returns a new copy of the data bits of this segment.
771
+ getData() {
772
+ return this.bitData.slice(); // Make defensive copy
773
+ }
774
+ // (Package-private) Calculates and returns the number of bits needed to encode the given segments at
775
+ // the given version. The result is infinity if a segment has too many characters to fit its length field.
776
+ static getTotalBits(segs, version) {
777
+ let result = 0;
778
+ for (const seg of segs) {
779
+ const ccbits = seg.mode.numCharCountBits(version);
780
+ if (seg.numChars >= (1 << ccbits))
781
+ return Infinity; // The segment's length doesn't fit the field's bit width
782
+ result += 4 + ccbits + seg.bitData.length;
783
+ }
784
+ return result;
785
+ }
786
+ // Returns a new array of bytes representing the given string encoded in UTF-8.
787
+ static toUtf8ByteArray(str) {
788
+ str = encodeURI(str);
789
+ let result = [];
790
+ for (let i = 0; i < str.length; i++) {
791
+ if (str.charAt(i) != "%")
792
+ result.push(str.charCodeAt(i));
793
+ else {
794
+ result.push(parseInt(str.substring(i + 1, i + 3), 16));
795
+ i += 2;
796
+ }
797
+ }
798
+ return result;
799
+ }
800
+ /*-- Constants --*/
801
+ // Describes precisely all strings that are encodable in numeric mode.
802
+ static NUMERIC_REGEX = /^[0-9]*$/;
803
+ // Describes precisely all strings that are encodable in alphanumeric mode.
804
+ static ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
805
+ // The set of all legal characters in alphanumeric mode,
806
+ // where each character value maps to the index in the string.
807
+ static ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
808
+ }
809
+ qrcodegen.QrSegment = QrSegment;
810
+ })(qrcodegen || (qrcodegen = {}));
811
+ /*---- Public helper enumeration ----*/
812
+ (function (qrcodegen) {
813
+ var QrCode;
814
+ (function (QrCode) {
815
+ /*
816
+ * The error correction level in a QR Code symbol. Immutable.
817
+ */
818
+ class Ecc {
819
+ ordinal;
820
+ formatBits;
821
+ /*-- Constants --*/
822
+ static LOW = new Ecc(0, 1); // The QR Code can tolerate about 7% erroneous codewords
823
+ static MEDIUM = new Ecc(1, 0); // The QR Code can tolerate about 15% erroneous codewords
824
+ static QUARTILE = new Ecc(2, 3); // The QR Code can tolerate about 25% erroneous codewords
825
+ static HIGH = new Ecc(3, 2); // The QR Code can tolerate about 30% erroneous codewords
826
+ /*-- Constructor and fields --*/
827
+ constructor(
828
+ // In the range 0 to 3 (unsigned 2-bit integer).
829
+ ordinal,
830
+ // (Package-private) In the range 0 to 3 (unsigned 2-bit integer).
831
+ formatBits) {
832
+ this.ordinal = ordinal;
833
+ this.formatBits = formatBits;
834
+ }
835
+ }
836
+ QrCode.Ecc = Ecc;
837
+ })(QrCode = qrcodegen.QrCode || (qrcodegen.QrCode = {}));
838
+ })(qrcodegen || (qrcodegen = {}));
839
+ /*---- Public helper enumeration ----*/
840
+ (function (qrcodegen) {
841
+ var QrSegment;
842
+ (function (QrSegment) {
843
+ /*
844
+ * Describes how a segment's data bits are interpreted. Immutable.
845
+ */
846
+ class Mode {
847
+ modeBits;
848
+ numBitsCharCount;
849
+ /*-- Constants --*/
850
+ static NUMERIC = new Mode(0x1, [10, 12, 14]);
851
+ static ALPHANUMERIC = new Mode(0x2, [9, 11, 13]);
852
+ static BYTE = new Mode(0x4, [8, 16, 16]);
853
+ static KANJI = new Mode(0x8, [8, 10, 12]);
854
+ static ECI = new Mode(0x7, [0, 0, 0]);
855
+ /*-- Constructor and fields --*/
856
+ constructor(
857
+ // The mode indicator bits, which is a uint4 value (range 0 to 15).
858
+ modeBits,
859
+ // Number of character count bits for three different version ranges.
860
+ numBitsCharCount) {
861
+ this.modeBits = modeBits;
862
+ this.numBitsCharCount = numBitsCharCount;
863
+ }
864
+ /*-- Method --*/
865
+ // (Package-private) Returns the bit width of the character count field for a segment in
866
+ // this mode in a QR Code at the given version number. The result is in the range [0, 16].
867
+ numCharCountBits(ver) {
868
+ return this.numBitsCharCount[Math.floor((ver + 7) / 17)];
869
+ }
870
+ }
871
+ QrSegment.Mode = Mode;
872
+ })(QrSegment = qrcodegen.QrSegment || (qrcodegen.QrSegment = {}));
873
+ })(qrcodegen || (qrcodegen = {}));
874
+ // Modification to export for actual use
875
+ export default qrcodegen;