qrcode.vue 3.3.4 → 3.4.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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * qrcode.vue v3.3.4
2
+ * qrcode.vue v3.4.0
3
3
  * A Vue.js component to generate QRCode.
4
4
  * © 2017-2023 @scopewu(https://github.com/scopewu)
5
5
  * MIT License.
@@ -34,1435 +34,1055 @@ var __assign = function() {
34
34
  return __assign.apply(this, arguments);
35
35
  };
36
36
 
37
- var mode$1 = {
38
- MODE_NUMBER : 1 << 0,
39
- MODE_ALPHA_NUM : 1 << 1,
40
- MODE_8BIT_BYTE : 1 << 2,
41
- MODE_KANJI : 1 << 3
42
- };
43
-
44
- var mode = mode$1;
45
-
46
- function QR8bitByte(data) {
47
- this.mode = mode.MODE_8BIT_BYTE;
48
- this.data = data;
49
- }
50
-
51
- QR8bitByte.prototype = {
52
-
53
- getLength : function(buffer) {
54
- return this.data.length;
55
- },
56
-
57
- write : function(buffer) {
58
- for (var i = 0; i < this.data.length; i++) {
59
- // not JIS ...
60
- buffer.put(this.data.charCodeAt(i), 8);
61
- }
62
- }
63
- };
64
-
65
- var _8BitByte = QR8bitByte;
66
-
67
- var ErrorCorrectLevel = {
68
- L : 1,
69
- M : 0,
70
- Q : 3,
71
- H : 2
72
- };
73
-
74
- // ErrorCorrectLevel
75
- var ECL = ErrorCorrectLevel;
76
-
77
- function QRRSBlock(totalCount, dataCount) {
78
- this.totalCount = totalCount;
79
- this.dataCount = dataCount;
80
- }
81
-
82
- QRRSBlock.RS_BLOCK_TABLE = [
83
-
84
- // L
85
- // M
86
- // Q
87
- // H
88
-
89
- // 1
90
- [1, 26, 19],
91
- [1, 26, 16],
92
- [1, 26, 13],
93
- [1, 26, 9],
94
-
95
- // 2
96
- [1, 44, 34],
97
- [1, 44, 28],
98
- [1, 44, 22],
99
- [1, 44, 16],
100
-
101
- // 3
102
- [1, 70, 55],
103
- [1, 70, 44],
104
- [2, 35, 17],
105
- [2, 35, 13],
106
-
107
- // 4
108
- [1, 100, 80],
109
- [2, 50, 32],
110
- [2, 50, 24],
111
- [4, 25, 9],
112
-
113
- // 5
114
- [1, 134, 108],
115
- [2, 67, 43],
116
- [2, 33, 15, 2, 34, 16],
117
- [2, 33, 11, 2, 34, 12],
118
-
119
- // 6
120
- [2, 86, 68],
121
- [4, 43, 27],
122
- [4, 43, 19],
123
- [4, 43, 15],
124
-
125
- // 7
126
- [2, 98, 78],
127
- [4, 49, 31],
128
- [2, 32, 14, 4, 33, 15],
129
- [4, 39, 13, 1, 40, 14],
130
-
131
- // 8
132
- [2, 121, 97],
133
- [2, 60, 38, 2, 61, 39],
134
- [4, 40, 18, 2, 41, 19],
135
- [4, 40, 14, 2, 41, 15],
136
-
137
- // 9
138
- [2, 146, 116],
139
- [3, 58, 36, 2, 59, 37],
140
- [4, 36, 16, 4, 37, 17],
141
- [4, 36, 12, 4, 37, 13],
142
-
143
- // 10
144
- [2, 86, 68, 2, 87, 69],
145
- [4, 69, 43, 1, 70, 44],
146
- [6, 43, 19, 2, 44, 20],
147
- [6, 43, 15, 2, 44, 16],
148
-
149
- // 11
150
- [4, 101, 81],
151
- [1, 80, 50, 4, 81, 51],
152
- [4, 50, 22, 4, 51, 23],
153
- [3, 36, 12, 8, 37, 13],
154
-
155
- // 12
156
- [2, 116, 92, 2, 117, 93],
157
- [6, 58, 36, 2, 59, 37],
158
- [4, 46, 20, 6, 47, 21],
159
- [7, 42, 14, 4, 43, 15],
160
-
161
- // 13
162
- [4, 133, 107],
163
- [8, 59, 37, 1, 60, 38],
164
- [8, 44, 20, 4, 45, 21],
165
- [12, 33, 11, 4, 34, 12],
166
-
167
- // 14
168
- [3, 145, 115, 1, 146, 116],
169
- [4, 64, 40, 5, 65, 41],
170
- [11, 36, 16, 5, 37, 17],
171
- [11, 36, 12, 5, 37, 13],
172
-
173
- // 15
174
- [5, 109, 87, 1, 110, 88],
175
- [5, 65, 41, 5, 66, 42],
176
- [5, 54, 24, 7, 55, 25],
177
- [11, 36, 12],
178
-
179
- // 16
180
- [5, 122, 98, 1, 123, 99],
181
- [7, 73, 45, 3, 74, 46],
182
- [15, 43, 19, 2, 44, 20],
183
- [3, 45, 15, 13, 46, 16],
184
-
185
- // 17
186
- [1, 135, 107, 5, 136, 108],
187
- [10, 74, 46, 1, 75, 47],
188
- [1, 50, 22, 15, 51, 23],
189
- [2, 42, 14, 17, 43, 15],
190
-
191
- // 18
192
- [5, 150, 120, 1, 151, 121],
193
- [9, 69, 43, 4, 70, 44],
194
- [17, 50, 22, 1, 51, 23],
195
- [2, 42, 14, 19, 43, 15],
196
-
197
- // 19
198
- [3, 141, 113, 4, 142, 114],
199
- [3, 70, 44, 11, 71, 45],
200
- [17, 47, 21, 4, 48, 22],
201
- [9, 39, 13, 16, 40, 14],
202
-
203
- // 20
204
- [3, 135, 107, 5, 136, 108],
205
- [3, 67, 41, 13, 68, 42],
206
- [15, 54, 24, 5, 55, 25],
207
- [15, 43, 15, 10, 44, 16],
208
-
209
- // 21
210
- [4, 144, 116, 4, 145, 117],
211
- [17, 68, 42],
212
- [17, 50, 22, 6, 51, 23],
213
- [19, 46, 16, 6, 47, 17],
214
-
215
- // 22
216
- [2, 139, 111, 7, 140, 112],
217
- [17, 74, 46],
218
- [7, 54, 24, 16, 55, 25],
219
- [34, 37, 13],
220
-
221
- // 23
222
- [4, 151, 121, 5, 152, 122],
223
- [4, 75, 47, 14, 76, 48],
224
- [11, 54, 24, 14, 55, 25],
225
- [16, 45, 15, 14, 46, 16],
226
-
227
- // 24
228
- [6, 147, 117, 4, 148, 118],
229
- [6, 73, 45, 14, 74, 46],
230
- [11, 54, 24, 16, 55, 25],
231
- [30, 46, 16, 2, 47, 17],
232
-
233
- // 25
234
- [8, 132, 106, 4, 133, 107],
235
- [8, 75, 47, 13, 76, 48],
236
- [7, 54, 24, 22, 55, 25],
237
- [22, 45, 15, 13, 46, 16],
238
-
239
- // 26
240
- [10, 142, 114, 2, 143, 115],
241
- [19, 74, 46, 4, 75, 47],
242
- [28, 50, 22, 6, 51, 23],
243
- [33, 46, 16, 4, 47, 17],
244
-
245
- // 27
246
- [8, 152, 122, 4, 153, 123],
247
- [22, 73, 45, 3, 74, 46],
248
- [8, 53, 23, 26, 54, 24],
249
- [12, 45, 15, 28, 46, 16],
250
-
251
- // 28
252
- [3, 147, 117, 10, 148, 118],
253
- [3, 73, 45, 23, 74, 46],
254
- [4, 54, 24, 31, 55, 25],
255
- [11, 45, 15, 31, 46, 16],
256
-
257
- // 29
258
- [7, 146, 116, 7, 147, 117],
259
- [21, 73, 45, 7, 74, 46],
260
- [1, 53, 23, 37, 54, 24],
261
- [19, 45, 15, 26, 46, 16],
262
-
263
- // 30
264
- [5, 145, 115, 10, 146, 116],
265
- [19, 75, 47, 10, 76, 48],
266
- [15, 54, 24, 25, 55, 25],
267
- [23, 45, 15, 25, 46, 16],
268
-
269
- // 31
270
- [13, 145, 115, 3, 146, 116],
271
- [2, 74, 46, 29, 75, 47],
272
- [42, 54, 24, 1, 55, 25],
273
- [23, 45, 15, 28, 46, 16],
274
-
275
- // 32
276
- [17, 145, 115],
277
- [10, 74, 46, 23, 75, 47],
278
- [10, 54, 24, 35, 55, 25],
279
- [19, 45, 15, 35, 46, 16],
280
-
281
- // 33
282
- [17, 145, 115, 1, 146, 116],
283
- [14, 74, 46, 21, 75, 47],
284
- [29, 54, 24, 19, 55, 25],
285
- [11, 45, 15, 46, 46, 16],
286
-
287
- // 34
288
- [13, 145, 115, 6, 146, 116],
289
- [14, 74, 46, 23, 75, 47],
290
- [44, 54, 24, 7, 55, 25],
291
- [59, 46, 16, 1, 47, 17],
292
-
293
- // 35
294
- [12, 151, 121, 7, 152, 122],
295
- [12, 75, 47, 26, 76, 48],
296
- [39, 54, 24, 14, 55, 25],
297
- [22, 45, 15, 41, 46, 16],
298
-
299
- // 36
300
- [6, 151, 121, 14, 152, 122],
301
- [6, 75, 47, 34, 76, 48],
302
- [46, 54, 24, 10, 55, 25],
303
- [2, 45, 15, 64, 46, 16],
304
-
305
- // 37
306
- [17, 152, 122, 4, 153, 123],
307
- [29, 74, 46, 14, 75, 47],
308
- [49, 54, 24, 10, 55, 25],
309
- [24, 45, 15, 46, 46, 16],
310
-
311
- // 38
312
- [4, 152, 122, 18, 153, 123],
313
- [13, 74, 46, 32, 75, 47],
314
- [48, 54, 24, 14, 55, 25],
315
- [42, 45, 15, 32, 46, 16],
316
-
317
- // 39
318
- [20, 147, 117, 4, 148, 118],
319
- [40, 75, 47, 7, 76, 48],
320
- [43, 54, 24, 22, 55, 25],
321
- [10, 45, 15, 67, 46, 16],
322
-
323
- // 40
324
- [19, 148, 118, 6, 149, 119],
325
- [18, 75, 47, 31, 76, 48],
326
- [34, 54, 24, 34, 55, 25],
327
- [20, 45, 15, 61, 46, 16]
328
- ];
329
-
330
- QRRSBlock.getRSBlocks = function(typeNumber, errorCorrectLevel) {
331
-
332
- var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel);
333
-
334
- if (rsBlock == undefined) {
335
- throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel);
336
- }
337
-
338
- var length = rsBlock.length / 3;
339
-
340
- var list = new Array();
341
-
342
- for (var i = 0; i < length; i++) {
343
-
344
- var count = rsBlock[i * 3 + 0];
345
- var totalCount = rsBlock[i * 3 + 1];
346
- var dataCount = rsBlock[i * 3 + 2];
347
-
348
- for (var j = 0; j < count; j++) {
349
- list.push(new QRRSBlock(totalCount, dataCount) );
350
- }
351
- }
352
-
353
- return list;
354
- };
355
-
356
- QRRSBlock.getRsBlockTable = function(typeNumber, errorCorrectLevel) {
357
-
358
- switch(errorCorrectLevel) {
359
- case ECL.L :
360
- return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
361
- case ECL.M :
362
- return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
363
- case ECL.Q :
364
- return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
365
- case ECL.H :
366
- return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
367
- default :
368
- return undefined;
369
- }
370
- };
371
-
372
- var RSBlock$1 = QRRSBlock;
373
-
374
- function QRBitBuffer() {
375
- this.buffer = new Array();
376
- this.length = 0;
377
- }
378
-
379
- QRBitBuffer.prototype = {
380
-
381
- get : function(index) {
382
- var bufIndex = Math.floor(index / 8);
383
- return ( (this.buffer[bufIndex] >>> (7 - index % 8) ) & 1) == 1;
384
- },
385
-
386
- put : function(num, length) {
387
- for (var i = 0; i < length; i++) {
388
- this.putBit( ( (num >>> (length - i - 1) ) & 1) == 1);
389
- }
390
- },
391
-
392
- getLengthInBits : function() {
393
- return this.length;
394
- },
395
-
396
- putBit : function(bit) {
397
-
398
- var bufIndex = Math.floor(this.length / 8);
399
- if (this.buffer.length <= bufIndex) {
400
- this.buffer.push(0);
401
- }
402
-
403
- if (bit) {
404
- this.buffer[bufIndex] |= (0x80 >>> (this.length % 8) );
405
- }
406
-
407
- this.length++;
408
- }
409
- };
410
-
411
- var BitBuffer$1 = QRBitBuffer;
412
-
413
- var QRMath = {
414
-
415
- glog : function(n) {
416
-
417
- if (n < 1) {
418
- throw new Error("glog(" + n + ")");
419
- }
420
-
421
- return QRMath.LOG_TABLE[n];
422
- },
423
-
424
- gexp : function(n) {
425
-
426
- while (n < 0) {
427
- n += 255;
428
- }
429
-
430
- while (n >= 256) {
431
- n -= 255;
432
- }
433
-
434
- return QRMath.EXP_TABLE[n];
435
- },
436
-
437
- EXP_TABLE : new Array(256),
438
-
439
- LOG_TABLE : new Array(256)
440
-
37
+ /*
38
+ * QR Code generator library (TypeScript)
39
+ *
40
+ * Copyright (c) Project Nayuki. (MIT License)
41
+ * https://www.nayuki.io/page/qr-code-generator-library
42
+ *
43
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
44
+ * this software and associated documentation files (the "Software"), to deal in
45
+ * the Software without restriction, including without limitation the rights to
46
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
47
+ * the Software, and to permit persons to whom the Software is furnished to do so,
48
+ * subject to the following conditions:
49
+ * - The above copyright notice and this permission notice shall be included in
50
+ * all copies or substantial portions of the Software.
51
+ * - The Software is provided "as is", without warranty of any kind, express or
52
+ * implied, including but not limited to the warranties of merchantability,
53
+ * fitness for a particular purpose and noninfringement. In no event shall the
54
+ * authors or copyright holders be liable for any claim, damages or other
55
+ * liability, whether in an action of contract, tort or otherwise, arising from,
56
+ * out of or in connection with the Software or the use or other dealings in the
57
+ * Software.
58
+ */
59
+ var qrcodegen;
60
+ (function (qrcodegen) {
61
+ /*---- QR Code symbol class ----*/
62
+ /*
63
+ * A QR Code symbol, which is a type of two-dimension barcode.
64
+ * Invented by Denso Wave and described in the ISO/IEC 18004 standard.
65
+ * Instances of this class represent an immutable square grid of dark and light cells.
66
+ * The class provides static factory functions to create a QR Code from text or binary data.
67
+ * The class covers the QR Code Model 2 specification, supporting all versions (sizes)
68
+ * from 1 to 40, all 4 error correction levels, and 4 character encoding modes.
69
+ *
70
+ * Ways to create a QR Code object:
71
+ * - High level: Take the payload data and call QrCode.encodeText() or QrCode.encodeBinary().
72
+ * - Mid level: Custom-make the list of segments and call QrCode.encodeSegments().
73
+ * - Low level: Custom-make the array of data codeword bytes (including
74
+ * segment headers and final padding, excluding error correction codewords),
75
+ * supply the appropriate version number, and call the QrCode() constructor.
76
+ * (Note that all ways require supplying the desired error correction level.)
77
+ */
78
+ var QrCode = /** @class */ (function () {
79
+ /*-- Constructor (low level) and fields --*/
80
+ // Creates a new QR Code with the given version number,
81
+ // error correction level, data codeword bytes, and mask number.
82
+ // This is a low-level API that most users should not use directly.
83
+ // A mid-level API is the encodeSegments() function.
84
+ function QrCode(
85
+ // The version number of this QR Code, which is between 1 and 40 (inclusive).
86
+ // This determines the size of this barcode.
87
+ version,
88
+ // The error correction level used in this QR Code.
89
+ errorCorrectionLevel, dataCodewords, msk) {
90
+ this.version = version;
91
+ this.errorCorrectionLevel = errorCorrectionLevel;
92
+ // The modules of this QR Code (false = light, true = dark).
93
+ // Immutable after constructor finishes. Accessed through getModule().
94
+ this.modules = [];
95
+ // Indicates function modules that are not subjected to masking. Discarded when constructor finishes.
96
+ this.isFunction = [];
97
+ // Check scalar arguments
98
+ if (version < QrCode.MIN_VERSION || version > QrCode.MAX_VERSION)
99
+ throw new RangeError("Version value out of range");
100
+ if (msk < -1 || msk > 7)
101
+ throw new RangeError("Mask value out of range");
102
+ this.size = version * 4 + 17;
103
+ // Initialize both grids to be size*size arrays of Boolean false
104
+ var row = [];
105
+ for (var i = 0; i < this.size; i++)
106
+ row.push(false);
107
+ for (var i = 0; i < this.size; i++) {
108
+ this.modules.push(row.slice()); // Initially all light
109
+ this.isFunction.push(row.slice());
110
+ }
111
+ // Compute ECC, draw modules
112
+ this.drawFunctionPatterns();
113
+ var allCodewords = this.addEccAndInterleave(dataCodewords);
114
+ this.drawCodewords(allCodewords);
115
+ // Do masking
116
+ if (msk == -1) { // Automatically choose best mask
117
+ var minPenalty = 1000000000;
118
+ for (var i = 0; i < 8; i++) {
119
+ this.applyMask(i);
120
+ this.drawFormatBits(i);
121
+ var penalty = this.getPenaltyScore();
122
+ if (penalty < minPenalty) {
123
+ msk = i;
124
+ minPenalty = penalty;
125
+ }
126
+ this.applyMask(i); // Undoes the mask due to XOR
127
+ }
128
+ }
129
+ assert(0 <= msk && msk <= 7);
130
+ this.mask = msk;
131
+ this.applyMask(msk); // Apply the final choice of mask
132
+ this.drawFormatBits(msk); // Overwrite old format bits
133
+ this.isFunction = [];
134
+ }
135
+ /*-- Static factory functions (high level) --*/
136
+ // Returns a QR Code representing the given Unicode text string at the given error correction level.
137
+ // As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer
138
+ // Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible
139
+ // QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
140
+ // ecl argument if it can be done without increasing the version.
141
+ QrCode.encodeText = function (text, ecl) {
142
+ var segs = qrcodegen.QrSegment.makeSegments(text);
143
+ return QrCode.encodeSegments(segs, ecl);
144
+ };
145
+ // Returns a QR Code representing the given binary data at the given error correction level.
146
+ // This function always encodes using the binary segment mode, not any text mode. The maximum number of
147
+ // bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
148
+ // The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
149
+ QrCode.encodeBinary = function (data, ecl) {
150
+ var seg = qrcodegen.QrSegment.makeBytes(data);
151
+ return QrCode.encodeSegments([seg], ecl);
152
+ };
153
+ /*-- Static factory functions (mid level) --*/
154
+ // Returns a QR Code representing the given segments with the given encoding parameters.
155
+ // The smallest possible QR Code version within the given range is automatically
156
+ // chosen for the output. Iff boostEcl is true, then the ECC level of the result
157
+ // may be higher than the ecl argument if it can be done without increasing the
158
+ // version. The mask number is either between 0 to 7 (inclusive) to force that
159
+ // mask, or -1 to automatically choose an appropriate mask (which may be slow).
160
+ // This function allows the user to create a custom sequence of segments that switches
161
+ // between modes (such as alphanumeric and byte) to encode text in less space.
162
+ // This is a mid-level API; the high-level API is encodeText() and encodeBinary().
163
+ QrCode.encodeSegments = function (segs, ecl, minVersion, maxVersion, mask, boostEcl) {
164
+ if (minVersion === void 0) { minVersion = 1; }
165
+ if (maxVersion === void 0) { maxVersion = 40; }
166
+ if (mask === void 0) { mask = -1; }
167
+ if (boostEcl === void 0) { boostEcl = true; }
168
+ if (!(QrCode.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= QrCode.MAX_VERSION)
169
+ || mask < -1 || mask > 7)
170
+ throw new RangeError("Invalid value");
171
+ // Find the minimal version number to use
172
+ var version;
173
+ var dataUsedBits;
174
+ for (version = minVersion;; version++) {
175
+ var dataCapacityBits_1 = QrCode.getNumDataCodewords(version, ecl) * 8; // Number of data bits available
176
+ var usedBits = QrSegment.getTotalBits(segs, version);
177
+ if (usedBits <= dataCapacityBits_1) {
178
+ dataUsedBits = usedBits;
179
+ break; // This version number is found to be suitable
180
+ }
181
+ if (version >= maxVersion) // All versions in the range could not fit the given data
182
+ throw new RangeError("Data too long");
183
+ }
184
+ // Increase the error correction level while the data still fits in the current version number
185
+ for (var _i = 0, _a = [QrCode.Ecc.MEDIUM, QrCode.Ecc.QUARTILE, QrCode.Ecc.HIGH]; _i < _a.length; _i++) { // From low to high
186
+ var newEcl = _a[_i];
187
+ if (boostEcl && dataUsedBits <= QrCode.getNumDataCodewords(version, newEcl) * 8)
188
+ ecl = newEcl;
189
+ }
190
+ // Concatenate all segments to create the data bit string
191
+ var bb = [];
192
+ for (var _b = 0, segs_1 = segs; _b < segs_1.length; _b++) {
193
+ var seg = segs_1[_b];
194
+ appendBits(seg.mode.modeBits, 4, bb);
195
+ appendBits(seg.numChars, seg.mode.numCharCountBits(version), bb);
196
+ for (var _c = 0, _d = seg.getData(); _c < _d.length; _c++) {
197
+ var b = _d[_c];
198
+ bb.push(b);
199
+ }
200
+ }
201
+ assert(bb.length == dataUsedBits);
202
+ // Add terminator and pad up to a byte if applicable
203
+ var dataCapacityBits = QrCode.getNumDataCodewords(version, ecl) * 8;
204
+ assert(bb.length <= dataCapacityBits);
205
+ appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
206
+ appendBits(0, (8 - bb.length % 8) % 8, bb);
207
+ assert(bb.length % 8 == 0);
208
+ // Pad with alternating bytes until data capacity is reached
209
+ for (var padByte = 0xEC; bb.length < dataCapacityBits; padByte ^= 0xEC ^ 0x11)
210
+ appendBits(padByte, 8, bb);
211
+ // Pack bits into bytes in big endian
212
+ var dataCodewords = [];
213
+ while (dataCodewords.length * 8 < bb.length)
214
+ dataCodewords.push(0);
215
+ bb.forEach(function (b, i) {
216
+ return dataCodewords[i >>> 3] |= b << (7 - (i & 7));
217
+ });
218
+ // Create the QR Code object
219
+ return new QrCode(version, ecl, dataCodewords, mask);
220
+ };
221
+ /*-- Accessor methods --*/
222
+ // Returns the color of the module (pixel) at the given coordinates, which is false
223
+ // for light or true for dark. The top left corner has the coordinates (x=0, y=0).
224
+ // If the given coordinates are out of bounds, then false (light) is returned.
225
+ QrCode.prototype.getModule = function (x, y) {
226
+ return 0 <= x && x < this.size && 0 <= y && y < this.size && this.modules[y][x];
227
+ };
228
+ QrCode.prototype.getModules = function () {
229
+ return this.modules;
230
+ };
231
+ /*-- Private helper methods for constructor: Drawing function modules --*/
232
+ // Reads this object's version field, and draws and marks all function modules.
233
+ QrCode.prototype.drawFunctionPatterns = function () {
234
+ // Draw horizontal and vertical timing patterns
235
+ for (var i = 0; i < this.size; i++) {
236
+ this.setFunctionModule(6, i, i % 2 == 0);
237
+ this.setFunctionModule(i, 6, i % 2 == 0);
238
+ }
239
+ // Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules)
240
+ this.drawFinderPattern(3, 3);
241
+ this.drawFinderPattern(this.size - 4, 3);
242
+ this.drawFinderPattern(3, this.size - 4);
243
+ // Draw numerous alignment patterns
244
+ var alignPatPos = this.getAlignmentPatternPositions();
245
+ var numAlign = alignPatPos.length;
246
+ for (var i = 0; i < numAlign; i++) {
247
+ for (var j = 0; j < numAlign; j++) {
248
+ // Don't draw on the three finder corners
249
+ if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0))
250
+ this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
251
+ }
252
+ }
253
+ // Draw configuration data
254
+ this.drawFormatBits(0); // Dummy mask value; overwritten later in the constructor
255
+ this.drawVersion();
256
+ };
257
+ // Draws two copies of the format bits (with its own error correction code)
258
+ // based on the given mask and this object's error correction level field.
259
+ QrCode.prototype.drawFormatBits = function (mask) {
260
+ // Calculate error correction code and pack bits
261
+ var data = this.errorCorrectionLevel.formatBits << 3 | mask; // errCorrLvl is uint2, mask is uint3
262
+ var rem = data;
263
+ for (var i = 0; i < 10; i++)
264
+ rem = (rem << 1) ^ ((rem >>> 9) * 0x537);
265
+ var bits = (data << 10 | rem) ^ 0x5412; // uint15
266
+ assert(bits >>> 15 == 0);
267
+ // Draw first copy
268
+ for (var i = 0; i <= 5; i++)
269
+ this.setFunctionModule(8, i, getBit(bits, i));
270
+ this.setFunctionModule(8, 7, getBit(bits, 6));
271
+ this.setFunctionModule(8, 8, getBit(bits, 7));
272
+ this.setFunctionModule(7, 8, getBit(bits, 8));
273
+ for (var i = 9; i < 15; i++)
274
+ this.setFunctionModule(14 - i, 8, getBit(bits, i));
275
+ // Draw second copy
276
+ for (var i = 0; i < 8; i++)
277
+ this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
278
+ for (var i = 8; i < 15; i++)
279
+ this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
280
+ this.setFunctionModule(8, this.size - 8, true); // Always dark
281
+ };
282
+ // Draws two copies of the version bits (with its own error correction code),
283
+ // based on this object's version field, iff 7 <= version <= 40.
284
+ QrCode.prototype.drawVersion = function () {
285
+ if (this.version < 7)
286
+ return;
287
+ // Calculate error correction code and pack bits
288
+ var rem = this.version; // version is uint6, in the range [7, 40]
289
+ for (var i = 0; i < 12; i++)
290
+ rem = (rem << 1) ^ ((rem >>> 11) * 0x1F25);
291
+ var bits = this.version << 12 | rem; // uint18
292
+ assert(bits >>> 18 == 0);
293
+ // Draw two copies
294
+ for (var i = 0; i < 18; i++) {
295
+ var color = getBit(bits, i);
296
+ var a = this.size - 11 + i % 3;
297
+ var b = Math.floor(i / 3);
298
+ this.setFunctionModule(a, b, color);
299
+ this.setFunctionModule(b, a, color);
300
+ }
301
+ };
302
+ // Draws a 9*9 finder pattern including the border separator,
303
+ // with the center module at (x, y). Modules can be out of bounds.
304
+ QrCode.prototype.drawFinderPattern = function (x, y) {
305
+ for (var dy = -4; dy <= 4; dy++) {
306
+ for (var dx = -4; dx <= 4; dx++) {
307
+ var dist = Math.max(Math.abs(dx), Math.abs(dy)); // Chebyshev/infinity norm
308
+ var xx = x + dx;
309
+ var yy = y + dy;
310
+ if (0 <= xx && xx < this.size && 0 <= yy && yy < this.size)
311
+ this.setFunctionModule(xx, yy, dist != 2 && dist != 4);
312
+ }
313
+ }
314
+ };
315
+ // Draws a 5*5 alignment pattern, with the center module
316
+ // at (x, y). All modules must be in bounds.
317
+ QrCode.prototype.drawAlignmentPattern = function (x, y) {
318
+ for (var dy = -2; dy <= 2; dy++) {
319
+ for (var dx = -2; dx <= 2; dx++)
320
+ this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
321
+ }
322
+ };
323
+ // Sets the color of a module and marks it as a function module.
324
+ // Only used by the constructor. Coordinates must be in bounds.
325
+ QrCode.prototype.setFunctionModule = function (x, y, isDark) {
326
+ this.modules[y][x] = isDark;
327
+ this.isFunction[y][x] = true;
328
+ };
329
+ /*-- Private helper methods for constructor: Codewords and masking --*/
330
+ // Returns a new byte string representing the given data with the appropriate error correction
331
+ // codewords appended to it, based on this object's version and error correction level.
332
+ QrCode.prototype.addEccAndInterleave = function (data) {
333
+ var ver = this.version;
334
+ var ecl = this.errorCorrectionLevel;
335
+ if (data.length != QrCode.getNumDataCodewords(ver, ecl))
336
+ throw new RangeError("Invalid argument");
337
+ // Calculate parameter numbers
338
+ var numBlocks = QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
339
+ var blockEccLen = QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver];
340
+ var rawCodewords = Math.floor(QrCode.getNumRawDataModules(ver) / 8);
341
+ var numShortBlocks = numBlocks - rawCodewords % numBlocks;
342
+ var shortBlockLen = Math.floor(rawCodewords / numBlocks);
343
+ // Split data into blocks and append ECC to each block
344
+ var blocks = [];
345
+ var rsDiv = QrCode.reedSolomonComputeDivisor(blockEccLen);
346
+ for (var i = 0, k = 0; i < numBlocks; i++) {
347
+ var dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
348
+ k += dat.length;
349
+ var ecc = QrCode.reedSolomonComputeRemainder(dat, rsDiv);
350
+ if (i < numShortBlocks)
351
+ dat.push(0);
352
+ blocks.push(dat.concat(ecc));
353
+ }
354
+ // Interleave (not concatenate) the bytes from every block into a single sequence
355
+ var result = [];
356
+ var _loop_1 = function (i) {
357
+ blocks.forEach(function (block, j) {
358
+ // Skip the padding byte in short blocks
359
+ if (i != shortBlockLen - blockEccLen || j >= numShortBlocks)
360
+ result.push(block[i]);
361
+ });
362
+ };
363
+ for (var i = 0; i < blocks[0].length; i++) {
364
+ _loop_1(i);
365
+ }
366
+ assert(result.length == rawCodewords);
367
+ return result;
368
+ };
369
+ // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
370
+ // data area of this QR Code. Function modules need to be marked off before this is called.
371
+ QrCode.prototype.drawCodewords = function (data) {
372
+ if (data.length != Math.floor(QrCode.getNumRawDataModules(this.version) / 8))
373
+ throw new RangeError("Invalid argument");
374
+ var i = 0; // Bit index into the data
375
+ // Do the funny zigzag scan
376
+ for (var right = this.size - 1; right >= 1; right -= 2) { // Index of right column in each column pair
377
+ if (right == 6)
378
+ right = 5;
379
+ for (var vert = 0; vert < this.size; vert++) { // Vertical counter
380
+ for (var j = 0; j < 2; j++) {
381
+ var x = right - j; // Actual x coordinate
382
+ var upward = ((right + 1) & 2) == 0;
383
+ var y = upward ? this.size - 1 - vert : vert; // Actual y coordinate
384
+ if (!this.isFunction[y][x] && i < data.length * 8) {
385
+ this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
386
+ i++;
387
+ }
388
+ // If this QR Code has any remainder bits (0 to 7), they were assigned as
389
+ // 0/false/light by the constructor and are left unchanged by this method
390
+ }
391
+ }
392
+ }
393
+ assert(i == data.length * 8);
394
+ };
395
+ // XORs the codeword modules in this QR Code with the given mask pattern.
396
+ // The function modules must be marked and the codeword bits must be drawn
397
+ // before masking. Due to the arithmetic of XOR, calling applyMask() with
398
+ // the same mask value a second time will undo the mask. A final well-formed
399
+ // QR Code needs exactly one (not zero, two, etc.) mask applied.
400
+ QrCode.prototype.applyMask = function (mask) {
401
+ if (mask < 0 || mask > 7)
402
+ throw new RangeError("Mask value out of range");
403
+ for (var y = 0; y < this.size; y++) {
404
+ for (var x = 0; x < this.size; x++) {
405
+ var invert = void 0;
406
+ switch (mask) {
407
+ case 0:
408
+ invert = (x + y) % 2 == 0;
409
+ break;
410
+ case 1:
411
+ invert = y % 2 == 0;
412
+ break;
413
+ case 2:
414
+ invert = x % 3 == 0;
415
+ break;
416
+ case 3:
417
+ invert = (x + y) % 3 == 0;
418
+ break;
419
+ case 4:
420
+ invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0;
421
+ break;
422
+ case 5:
423
+ invert = x * y % 2 + x * y % 3 == 0;
424
+ break;
425
+ case 6:
426
+ invert = (x * y % 2 + x * y % 3) % 2 == 0;
427
+ break;
428
+ case 7:
429
+ invert = ((x + y) % 2 + x * y % 3) % 2 == 0;
430
+ break;
431
+ default: throw new Error("Unreachable");
432
+ }
433
+ if (!this.isFunction[y][x] && invert)
434
+ this.modules[y][x] = !this.modules[y][x];
435
+ }
436
+ }
437
+ };
438
+ // Calculates and returns the penalty score based on state of this QR Code's current modules.
439
+ // This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
440
+ QrCode.prototype.getPenaltyScore = function () {
441
+ var result = 0;
442
+ // Adjacent modules in row having same color, and finder-like patterns
443
+ for (var y = 0; y < this.size; y++) {
444
+ var runColor = false;
445
+ var runX = 0;
446
+ var runHistory = [0, 0, 0, 0, 0, 0, 0];
447
+ for (var x = 0; x < this.size; x++) {
448
+ if (this.modules[y][x] == runColor) {
449
+ runX++;
450
+ if (runX == 5)
451
+ result += QrCode.PENALTY_N1;
452
+ else if (runX > 5)
453
+ result++;
454
+ }
455
+ else {
456
+ this.finderPenaltyAddHistory(runX, runHistory);
457
+ if (!runColor)
458
+ result += this.finderPenaltyCountPatterns(runHistory) * QrCode.PENALTY_N3;
459
+ runColor = this.modules[y][x];
460
+ runX = 1;
461
+ }
462
+ }
463
+ result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * QrCode.PENALTY_N3;
464
+ }
465
+ // Adjacent modules in column having same color, and finder-like patterns
466
+ for (var x = 0; x < this.size; x++) {
467
+ var runColor = false;
468
+ var runY = 0;
469
+ var runHistory = [0, 0, 0, 0, 0, 0, 0];
470
+ for (var y = 0; y < this.size; y++) {
471
+ if (this.modules[y][x] == runColor) {
472
+ runY++;
473
+ if (runY == 5)
474
+ result += QrCode.PENALTY_N1;
475
+ else if (runY > 5)
476
+ result++;
477
+ }
478
+ else {
479
+ this.finderPenaltyAddHistory(runY, runHistory);
480
+ if (!runColor)
481
+ result += this.finderPenaltyCountPatterns(runHistory) * QrCode.PENALTY_N3;
482
+ runColor = this.modules[y][x];
483
+ runY = 1;
484
+ }
485
+ }
486
+ result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * QrCode.PENALTY_N3;
487
+ }
488
+ // 2*2 blocks of modules having same color
489
+ for (var y = 0; y < this.size - 1; y++) {
490
+ for (var x = 0; x < this.size - 1; x++) {
491
+ var color = this.modules[y][x];
492
+ if (color == this.modules[y][x + 1] &&
493
+ color == this.modules[y + 1][x] &&
494
+ color == this.modules[y + 1][x + 1])
495
+ result += QrCode.PENALTY_N2;
496
+ }
497
+ }
498
+ // Balance of dark and light modules
499
+ var dark = 0;
500
+ for (var _i = 0, _a = this.modules; _i < _a.length; _i++) {
501
+ var row = _a[_i];
502
+ dark = row.reduce(function (sum, color) { return sum + (color ? 1 : 0); }, dark);
503
+ }
504
+ var total = this.size * this.size; // Note that size is odd, so dark/total != 1/2
505
+ // Compute the smallest integer k >= 0 such that (45-5k)% <= dark/total <= (55+5k)%
506
+ var k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
507
+ assert(0 <= k && k <= 9);
508
+ result += k * QrCode.PENALTY_N4;
509
+ assert(0 <= result && result <= 2568888); // Non-tight upper bound based on default values of PENALTY_N1, ..., N4
510
+ return result;
511
+ };
512
+ /*-- Private helper functions --*/
513
+ // Returns an ascending list of positions of alignment patterns for this version number.
514
+ // Each position is in the range [0,177), and are used on both the x and y axes.
515
+ // This could be implemented as lookup table of 40 variable-length lists of integers.
516
+ QrCode.prototype.getAlignmentPatternPositions = function () {
517
+ if (this.version == 1)
518
+ return [];
519
+ else {
520
+ var numAlign = Math.floor(this.version / 7) + 2;
521
+ var step = (this.version == 32) ? 26 :
522
+ Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
523
+ var result = [6];
524
+ for (var pos = this.size - 7; result.length < numAlign; pos -= step)
525
+ result.splice(1, 0, pos);
526
+ return result;
527
+ }
528
+ };
529
+ // Returns the number of data bits that can be stored in a QR Code of the given version number, after
530
+ // all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
531
+ // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
532
+ QrCode.getNumRawDataModules = function (ver) {
533
+ if (ver < QrCode.MIN_VERSION || ver > QrCode.MAX_VERSION)
534
+ throw new RangeError("Version number out of range");
535
+ var result = (16 * ver + 128) * ver + 64;
536
+ if (ver >= 2) {
537
+ var numAlign = Math.floor(ver / 7) + 2;
538
+ result -= (25 * numAlign - 10) * numAlign - 55;
539
+ if (ver >= 7)
540
+ result -= 36;
541
+ }
542
+ assert(208 <= result && result <= 29648);
543
+ return result;
544
+ };
545
+ // Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
546
+ // QR Code of the given version number and error correction level, with remainder bits discarded.
547
+ // This stateless pure function could be implemented as a (40*4)-cell lookup table.
548
+ QrCode.getNumDataCodewords = function (ver, ecl) {
549
+ return Math.floor(QrCode.getNumRawDataModules(ver) / 8) -
550
+ QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] *
551
+ QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
552
+ };
553
+ // Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
554
+ // implemented as a lookup table over all possible parameter values, instead of as an algorithm.
555
+ QrCode.reedSolomonComputeDivisor = function (degree) {
556
+ if (degree < 1 || degree > 255)
557
+ throw new RangeError("Degree out of range");
558
+ // Polynomial coefficients are stored from highest to lowest power, excluding the leading term which is always 1.
559
+ // For example the polynomial x^3 + 255x^2 + 8x + 93 is stored as the uint8 array [255, 8, 93].
560
+ var result = [];
561
+ for (var i = 0; i < degree - 1; i++)
562
+ result.push(0);
563
+ result.push(1); // Start off with the monomial x^0
564
+ // Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}),
565
+ // and drop the highest monomial term which is always 1x^degree.
566
+ // Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D).
567
+ var root = 1;
568
+ for (var i = 0; i < degree; i++) {
569
+ // Multiply the current product by (x - r^i)
570
+ for (var j = 0; j < result.length; j++) {
571
+ result[j] = QrCode.reedSolomonMultiply(result[j], root);
572
+ if (j + 1 < result.length)
573
+ result[j] ^= result[j + 1];
574
+ }
575
+ root = QrCode.reedSolomonMultiply(root, 0x02);
576
+ }
577
+ return result;
578
+ };
579
+ // Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
580
+ QrCode.reedSolomonComputeRemainder = function (data, divisor) {
581
+ var result = divisor.map(function (_) { return 0; });
582
+ var _loop_2 = function (b) {
583
+ var factor = b ^ result.shift();
584
+ result.push(0);
585
+ divisor.forEach(function (coef, i) {
586
+ return result[i] ^= QrCode.reedSolomonMultiply(coef, factor);
587
+ });
588
+ };
589
+ for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {
590
+ var b = data_1[_i];
591
+ _loop_2(b);
592
+ }
593
+ return result;
594
+ };
595
+ // Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result
596
+ // are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
597
+ QrCode.reedSolomonMultiply = function (x, y) {
598
+ if (x >>> 8 != 0 || y >>> 8 != 0)
599
+ throw new RangeError("Byte out of range");
600
+ // Russian peasant multiplication
601
+ var z = 0;
602
+ for (var i = 7; i >= 0; i--) {
603
+ z = (z << 1) ^ ((z >>> 7) * 0x11D);
604
+ z ^= ((y >>> i) & 1) * x;
605
+ }
606
+ assert(z >>> 8 == 0);
607
+ return z;
608
+ };
609
+ // Can only be called immediately after a light run is added, and
610
+ // returns either 0, 1, or 2. A helper function for getPenaltyScore().
611
+ QrCode.prototype.finderPenaltyCountPatterns = function (runHistory) {
612
+ var n = runHistory[1];
613
+ assert(n <= this.size * 3);
614
+ var core = n > 0 && runHistory[2] == n && runHistory[3] == n * 3 && runHistory[4] == n && runHistory[5] == n;
615
+ return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0)
616
+ + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
617
+ };
618
+ // Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
619
+ QrCode.prototype.finderPenaltyTerminateAndCount = function (currentRunColor, currentRunLength, runHistory) {
620
+ if (currentRunColor) { // Terminate dark run
621
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
622
+ currentRunLength = 0;
623
+ }
624
+ currentRunLength += this.size; // Add light border to final run
625
+ this.finderPenaltyAddHistory(currentRunLength, runHistory);
626
+ return this.finderPenaltyCountPatterns(runHistory);
627
+ };
628
+ // Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
629
+ QrCode.prototype.finderPenaltyAddHistory = function (currentRunLength, runHistory) {
630
+ if (runHistory[0] == 0)
631
+ currentRunLength += this.size; // Add light border to initial run
632
+ runHistory.pop();
633
+ runHistory.unshift(currentRunLength);
634
+ };
635
+ /*-- Constants and tables --*/
636
+ // The minimum version number supported in the QR Code Model 2 standard.
637
+ QrCode.MIN_VERSION = 1;
638
+ // The maximum version number supported in the QR Code Model 2 standard.
639
+ QrCode.MAX_VERSION = 40;
640
+ // For use in getPenaltyScore(), when evaluating which mask is best.
641
+ QrCode.PENALTY_N1 = 3;
642
+ QrCode.PENALTY_N2 = 3;
643
+ QrCode.PENALTY_N3 = 40;
644
+ QrCode.PENALTY_N4 = 10;
645
+ QrCode.ECC_CODEWORDS_PER_BLOCK = [
646
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
647
+ //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
648
+ [-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],
649
+ [-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],
650
+ [-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],
651
+ [-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
652
+ ];
653
+ QrCode.NUM_ERROR_CORRECTION_BLOCKS = [
654
+ // Version: (note that index 0 is for padding, and is set to an illegal value)
655
+ //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
656
+ [-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],
657
+ [-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],
658
+ [-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],
659
+ [-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
660
+ ];
661
+ return QrCode;
662
+ }());
663
+ qrcodegen.QrCode = QrCode;
664
+ // Appends the given number of low-order bits of the given value
665
+ // to the given buffer. Requires 0 <= len <= 31 and 0 <= val < 2^len.
666
+ function appendBits(val, len, bb) {
667
+ if (len < 0 || len > 31 || val >>> len != 0)
668
+ throw new RangeError("Value out of range");
669
+ for (var i = len - 1; i >= 0; i--) // Append bit by bit
670
+ bb.push((val >>> i) & 1);
671
+ }
672
+ // Returns true iff the i'th bit of x is set to 1.
673
+ function getBit(x, i) {
674
+ return ((x >>> i) & 1) != 0;
675
+ }
676
+ // Throws an exception if the given condition is false.
677
+ function assert(cond) {
678
+ if (!cond)
679
+ throw new Error("Assertion error");
680
+ }
681
+ /*---- Data segment class ----*/
682
+ /*
683
+ * A segment of character/binary/control data in a QR Code symbol.
684
+ * Instances of this class are immutable.
685
+ * The mid-level way to create a segment is to take the payload data
686
+ * and call a static factory function such as QrSegment.makeNumeric().
687
+ * The low-level way to create a segment is to custom-make the bit buffer
688
+ * and call the QrSegment() constructor with appropriate values.
689
+ * This segment class imposes no length restrictions, but QR Codes have restrictions.
690
+ * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
691
+ * Any segment longer than this is meaningless for the purpose of generating QR Codes.
692
+ */
693
+ var QrSegment = /** @class */ (function () {
694
+ /*-- Constructor (low level) and fields --*/
695
+ // Creates a new QR Code segment with the given attributes and data.
696
+ // The character count (numChars) must agree with the mode and the bit buffer length,
697
+ // but the constraint isn't checked. The given bit buffer is cloned and stored.
698
+ function QrSegment(
699
+ // The mode indicator of this segment.
700
+ mode,
701
+ // The length of this segment's unencoded data. Measured in characters for
702
+ // numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode.
703
+ // Always zero or positive. Not the same as the data's bit length.
704
+ numChars,
705
+ // The data bits of this segment. Accessed through getData().
706
+ bitData) {
707
+ this.mode = mode;
708
+ this.numChars = numChars;
709
+ this.bitData = bitData;
710
+ if (numChars < 0)
711
+ throw new RangeError("Invalid argument");
712
+ this.bitData = bitData.slice(); // Make defensive copy
713
+ }
714
+ /*-- Static factory functions (mid level) --*/
715
+ // Returns a segment representing the given binary data encoded in
716
+ // byte mode. All input byte arrays are acceptable. Any text string
717
+ // can be converted to UTF-8 bytes and encoded as a byte mode segment.
718
+ QrSegment.makeBytes = function (data) {
719
+ var bb = [];
720
+ for (var _i = 0, data_2 = data; _i < data_2.length; _i++) {
721
+ var b = data_2[_i];
722
+ appendBits(b, 8, bb);
723
+ }
724
+ return new QrSegment(QrSegment.Mode.BYTE, data.length, bb);
725
+ };
726
+ // Returns a segment representing the given string of decimal digits encoded in numeric mode.
727
+ QrSegment.makeNumeric = function (digits) {
728
+ if (!QrSegment.isNumeric(digits))
729
+ throw new RangeError("String contains non-numeric characters");
730
+ var bb = [];
731
+ for (var i = 0; i < digits.length;) { // Consume up to 3 digits per iteration
732
+ var n = Math.min(digits.length - i, 3);
733
+ appendBits(parseInt(digits.substring(i, i + n), 10), n * 3 + 1, bb);
734
+ i += n;
735
+ }
736
+ return new QrSegment(QrSegment.Mode.NUMERIC, digits.length, bb);
737
+ };
738
+ // Returns a segment representing the given text string encoded in alphanumeric mode.
739
+ // The characters allowed are: 0 to 9, A to Z (uppercase only), space,
740
+ // dollar, percent, asterisk, plus, hyphen, period, slash, colon.
741
+ QrSegment.makeAlphanumeric = function (text) {
742
+ if (!QrSegment.isAlphanumeric(text))
743
+ throw new RangeError("String contains unencodable characters in alphanumeric mode");
744
+ var bb = [];
745
+ var i;
746
+ for (i = 0; i + 2 <= text.length; i += 2) { // Process groups of 2
747
+ var temp = QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
748
+ temp += QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
749
+ appendBits(temp, 11, bb);
750
+ }
751
+ if (i < text.length) // 1 character remaining
752
+ appendBits(QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
753
+ return new QrSegment(QrSegment.Mode.ALPHANUMERIC, text.length, bb);
754
+ };
755
+ // Returns a new mutable list of zero or more segments to represent the given Unicode text string.
756
+ // The result may use various segment modes and switch modes to optimize the length of the bit stream.
757
+ QrSegment.makeSegments = function (text) {
758
+ // Select the most efficient segment encoding automatically
759
+ if (text == "")
760
+ return [];
761
+ else if (QrSegment.isNumeric(text))
762
+ return [QrSegment.makeNumeric(text)];
763
+ else if (QrSegment.isAlphanumeric(text))
764
+ return [QrSegment.makeAlphanumeric(text)];
765
+ else
766
+ return [QrSegment.makeBytes(QrSegment.toUtf8ByteArray(text))];
767
+ };
768
+ // Returns a segment representing an Extended Channel Interpretation
769
+ // (ECI) designator with the given assignment value.
770
+ QrSegment.makeEci = function (assignVal) {
771
+ var bb = [];
772
+ if (assignVal < 0)
773
+ throw new RangeError("ECI assignment value out of range");
774
+ else if (assignVal < (1 << 7))
775
+ appendBits(assignVal, 8, bb);
776
+ else if (assignVal < (1 << 14)) {
777
+ appendBits(2, 2, bb);
778
+ appendBits(assignVal, 14, bb);
779
+ }
780
+ else if (assignVal < 1000000) {
781
+ appendBits(6, 3, bb);
782
+ appendBits(assignVal, 21, bb);
783
+ }
784
+ else
785
+ throw new RangeError("ECI assignment value out of range");
786
+ return new QrSegment(QrSegment.Mode.ECI, 0, bb);
787
+ };
788
+ // Tests whether the given string can be encoded as a segment in numeric mode.
789
+ // A string is encodable iff each character is in the range 0 to 9.
790
+ QrSegment.isNumeric = function (text) {
791
+ return QrSegment.NUMERIC_REGEX.test(text);
792
+ };
793
+ // Tests whether the given string can be encoded as a segment in alphanumeric mode.
794
+ // A string is encodable iff each character is in the following set: 0 to 9, A to Z
795
+ // (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
796
+ QrSegment.isAlphanumeric = function (text) {
797
+ return QrSegment.ALPHANUMERIC_REGEX.test(text);
798
+ };
799
+ /*-- Methods --*/
800
+ // Returns a new copy of the data bits of this segment.
801
+ QrSegment.prototype.getData = function () {
802
+ return this.bitData.slice(); // Make defensive copy
803
+ };
804
+ // (Package-private) Calculates and returns the number of bits needed to encode the given segments at
805
+ // the given version. The result is infinity if a segment has too many characters to fit its length field.
806
+ QrSegment.getTotalBits = function (segs, version) {
807
+ var result = 0;
808
+ for (var _i = 0, segs_2 = segs; _i < segs_2.length; _i++) {
809
+ var seg = segs_2[_i];
810
+ var ccbits = seg.mode.numCharCountBits(version);
811
+ if (seg.numChars >= (1 << ccbits))
812
+ return Infinity; // The segment's length doesn't fit the field's bit width
813
+ result += 4 + ccbits + seg.bitData.length;
814
+ }
815
+ return result;
816
+ };
817
+ // Returns a new array of bytes representing the given string encoded in UTF-8.
818
+ QrSegment.toUtf8ByteArray = function (str) {
819
+ str = encodeURI(str);
820
+ var result = [];
821
+ for (var i = 0; i < str.length; i++) {
822
+ if (str.charAt(i) != "%")
823
+ result.push(str.charCodeAt(i));
824
+ else {
825
+ result.push(parseInt(str.substring(i + 1, i + 3), 16));
826
+ i += 2;
827
+ }
828
+ }
829
+ return result;
830
+ };
831
+ /*-- Constants --*/
832
+ // Describes precisely all strings that are encodable in numeric mode.
833
+ QrSegment.NUMERIC_REGEX = /^[0-9]*$/;
834
+ // Describes precisely all strings that are encodable in alphanumeric mode.
835
+ QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
836
+ // The set of all legal characters in alphanumeric mode,
837
+ // where each character value maps to the index in the string.
838
+ QrSegment.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
839
+ return QrSegment;
840
+ }());
841
+ qrcodegen.QrSegment = QrSegment;
842
+ })(qrcodegen || (qrcodegen = {}));
843
+ /*---- Public helper enumeration ----*/
844
+ (function (qrcodegen) {
845
+ (function (QrCode) {
846
+ /*
847
+ * The error correction level in a QR Code symbol. Immutable.
848
+ */
849
+ var Ecc = /** @class */ (function () {
850
+ /*-- Constructor and fields --*/
851
+ function Ecc(
852
+ // In the range 0 to 3 (unsigned 2-bit integer).
853
+ ordinal,
854
+ // (Package-private) In the range 0 to 3 (unsigned 2-bit integer).
855
+ formatBits) {
856
+ this.ordinal = ordinal;
857
+ this.formatBits = formatBits;
858
+ }
859
+ /*-- Constants --*/
860
+ Ecc.LOW = new Ecc(0, 1); // The QR Code can tolerate about 7% erroneous codewords
861
+ Ecc.MEDIUM = new Ecc(1, 0); // The QR Code can tolerate about 15% erroneous codewords
862
+ Ecc.QUARTILE = new Ecc(2, 3); // The QR Code can tolerate about 25% erroneous codewords
863
+ Ecc.HIGH = new Ecc(3, 2); // The QR Code can tolerate about 30% erroneous codewords
864
+ return Ecc;
865
+ }());
866
+ QrCode.Ecc = Ecc;
867
+ })(qrcodegen.QrCode || (qrcodegen.QrCode = {}));
868
+ })(qrcodegen || (qrcodegen = {}));
869
+ /*---- Public helper enumeration ----*/
870
+ (function (qrcodegen) {
871
+ (function (QrSegment) {
872
+ /*
873
+ * Describes how a segment's data bits are interpreted. Immutable.
874
+ */
875
+ var Mode = /** @class */ (function () {
876
+ /*-- Constructor and fields --*/
877
+ function Mode(
878
+ // The mode indicator bits, which is a uint4 value (range 0 to 15).
879
+ modeBits,
880
+ // Number of character count bits for three different version ranges.
881
+ numBitsCharCount) {
882
+ this.modeBits = modeBits;
883
+ this.numBitsCharCount = numBitsCharCount;
884
+ }
885
+ /*-- Method --*/
886
+ // (Package-private) Returns the bit width of the character count field for a segment in
887
+ // this mode in a QR Code at the given version number. The result is in the range [0, 16].
888
+ Mode.prototype.numCharCountBits = function (ver) {
889
+ return this.numBitsCharCount[Math.floor((ver + 7) / 17)];
890
+ };
891
+ /*-- Constants --*/
892
+ Mode.NUMERIC = new Mode(0x1, [10, 12, 14]);
893
+ Mode.ALPHANUMERIC = new Mode(0x2, [9, 11, 13]);
894
+ Mode.BYTE = new Mode(0x4, [8, 16, 16]);
895
+ Mode.KANJI = new Mode(0x8, [8, 10, 12]);
896
+ Mode.ECI = new Mode(0x7, [0, 0, 0]);
897
+ return Mode;
898
+ }());
899
+ QrSegment.Mode = Mode;
900
+ })(qrcodegen.QrSegment || (qrcodegen.QrSegment = {}));
901
+ })(qrcodegen || (qrcodegen = {}));
902
+ var QR = qrcodegen;
903
+
904
+ var defaultErrorCorrectLevel = 'H';
905
+ var ErrorCorrectLevelMap = {
906
+ L: QR.QrCode.Ecc.LOW,
907
+ M: QR.QrCode.Ecc.MEDIUM,
908
+ Q: QR.QrCode.Ecc.QUARTILE,
909
+ H: QR.QrCode.Ecc.HIGH,
441
910
  };
442
-
443
- for (var i = 0; i < 8; i++) {
444
- QRMath.EXP_TABLE[i] = 1 << i;
445
- }
446
- for (var i = 8; i < 256; i++) {
447
- QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4]
448
- ^ QRMath.EXP_TABLE[i - 5]
449
- ^ QRMath.EXP_TABLE[i - 6]
450
- ^ QRMath.EXP_TABLE[i - 8];
451
- }
452
- for (var i = 0; i < 255; i++) {
453
- QRMath.LOG_TABLE[QRMath.EXP_TABLE[i] ] = i;
911
+ // Thanks the `qrcode.react`
912
+ var SUPPORTS_PATH2D = (function () {
913
+ try {
914
+ new Path2D().addPath(new Path2D());
915
+ }
916
+ catch (e) {
917
+ return false;
918
+ }
919
+ return true;
920
+ })();
921
+ function validErrorCorrectLevel(level) {
922
+ return level in ErrorCorrectLevelMap;
454
923
  }
455
-
456
- var math$2 = QRMath;
457
-
458
- var math$1 = math$2;
459
-
460
- function QRPolynomial(num, shift) {
461
-
462
- if (num.length == undefined) {
463
- throw new Error(num.length + "/" + shift);
464
- }
465
-
466
- var offset = 0;
467
-
468
- while (offset < num.length && num[offset] == 0) {
469
- offset++;
470
- }
471
-
472
- this.num = new Array(num.length - offset + shift);
473
- for (var i = 0; i < num.length - offset; i++) {
474
- this.num[i] = num[i + offset];
475
- }
924
+ function generatePath(modules, margin) {
925
+ if (margin === void 0) { margin = 0; }
926
+ var ops = [];
927
+ modules.forEach(function (row, y) {
928
+ var start = null;
929
+ row.forEach(function (cell, x) {
930
+ if (!cell && start !== null) {
931
+ // M0 0h7v1H0z injects the space with the move and drops the comma,
932
+ // saving a char per operation
933
+ ops.push("M".concat(start + margin, " ").concat(y + margin, "h").concat(x - start, "v1H").concat(start + margin, "z"));
934
+ start = null;
935
+ return;
936
+ }
937
+ // end of row, clean up or skip
938
+ if (x === row.length - 1) {
939
+ if (!cell) {
940
+ // We would have closed the op above already so this can only mean
941
+ // 2+ light modules in a row.
942
+ return;
943
+ }
944
+ if (start === null) {
945
+ // Just a single dark module.
946
+ ops.push("M".concat(x + margin, ",").concat(y + margin, " h1v1H").concat(x + margin, "z"));
947
+ }
948
+ else {
949
+ // Otherwise finish the current line.
950
+ ops.push("M".concat(start + margin, ",").concat(y + margin, " h").concat(x + 1 - start, "v1H").concat(start + margin, "z"));
951
+ }
952
+ return;
953
+ }
954
+ if (cell && start === null) {
955
+ start = x;
956
+ }
957
+ });
958
+ });
959
+ return ops.join('');
476
960
  }
477
-
478
- QRPolynomial.prototype = {
479
-
480
- get : function(index) {
481
- return this.num[index];
482
- },
483
-
484
- getLength : function() {
485
- return this.num.length;
486
- },
487
-
488
- multiply : function(e) {
489
-
490
- var num = new Array(this.getLength() + e.getLength() - 1);
491
-
492
- for (var i = 0; i < this.getLength(); i++) {
493
- for (var j = 0; j < e.getLength(); j++) {
494
- num[i + j] ^= math$1.gexp(math$1.glog(this.get(i) ) + math$1.glog(e.get(j) ) );
495
- }
496
- }
497
-
498
- return new QRPolynomial(num, 0);
499
- },
500
-
501
- mod : function(e) {
502
-
503
- if (this.getLength() - e.getLength() < 0) {
504
- return this;
505
- }
506
-
507
- var ratio = math$1.glog(this.get(0) ) - math$1.glog(e.get(0) );
508
-
509
- var num = new Array(this.getLength() );
510
-
511
- for (var i = 0; i < this.getLength(); i++) {
512
- num[i] = this.get(i);
513
- }
514
-
515
- for (var i = 0; i < e.getLength(); i++) {
516
- num[i] ^= math$1.gexp(math$1.glog(e.get(i) ) + ratio);
517
- }
518
-
519
- // recursive call
520
- return new QRPolynomial(num, 0).mod(e);
521
- }
522
- };
523
-
524
- var Polynomial$2 = QRPolynomial;
525
-
526
- var Mode = mode$1;
527
- var Polynomial$1 = Polynomial$2;
528
- var math = math$2;
529
-
530
- var QRMaskPattern = {
531
- PATTERN000 : 0,
532
- PATTERN001 : 1,
533
- PATTERN010 : 2,
534
- PATTERN011 : 3,
535
- PATTERN100 : 4,
536
- PATTERN101 : 5,
537
- PATTERN110 : 6,
538
- PATTERN111 : 7
539
- };
540
-
541
- var QRUtil = {
542
-
543
- PATTERN_POSITION_TABLE : [
544
- [],
545
- [6, 18],
546
- [6, 22],
547
- [6, 26],
548
- [6, 30],
549
- [6, 34],
550
- [6, 22, 38],
551
- [6, 24, 42],
552
- [6, 26, 46],
553
- [6, 28, 50],
554
- [6, 30, 54],
555
- [6, 32, 58],
556
- [6, 34, 62],
557
- [6, 26, 46, 66],
558
- [6, 26, 48, 70],
559
- [6, 26, 50, 74],
560
- [6, 30, 54, 78],
561
- [6, 30, 56, 82],
562
- [6, 30, 58, 86],
563
- [6, 34, 62, 90],
564
- [6, 28, 50, 72, 94],
565
- [6, 26, 50, 74, 98],
566
- [6, 30, 54, 78, 102],
567
- [6, 28, 54, 80, 106],
568
- [6, 32, 58, 84, 110],
569
- [6, 30, 58, 86, 114],
570
- [6, 34, 62, 90, 118],
571
- [6, 26, 50, 74, 98, 122],
572
- [6, 30, 54, 78, 102, 126],
573
- [6, 26, 52, 78, 104, 130],
574
- [6, 30, 56, 82, 108, 134],
575
- [6, 34, 60, 86, 112, 138],
576
- [6, 30, 58, 86, 114, 142],
577
- [6, 34, 62, 90, 118, 146],
578
- [6, 30, 54, 78, 102, 126, 150],
579
- [6, 24, 50, 76, 102, 128, 154],
580
- [6, 28, 54, 80, 106, 132, 158],
581
- [6, 32, 58, 84, 110, 136, 162],
582
- [6, 26, 54, 82, 110, 138, 166],
583
- [6, 30, 58, 86, 114, 142, 170]
584
- ],
585
-
586
- G15 : (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0),
587
- G18 : (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0),
588
- G15_MASK : (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1),
589
-
590
- getBCHTypeInfo : function(data) {
591
- var d = data << 10;
592
- while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) {
593
- d ^= (QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) ) );
594
- }
595
- return ( (data << 10) | d) ^ QRUtil.G15_MASK;
961
+ var QRCodeProps = {
962
+ value: {
963
+ type: String,
964
+ required: true,
965
+ default: '',
596
966
  },
597
-
598
- getBCHTypeNumber : function(data) {
599
- var d = data << 12;
600
- while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) {
601
- d ^= (QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) ) );
602
- }
603
- return (data << 12) | d;
967
+ size: {
968
+ type: Number,
969
+ default: 100,
604
970
  },
605
-
606
- getBCHDigit : function(data) {
607
-
608
- var digit = 0;
609
-
610
- while (data != 0) {
611
- digit++;
612
- data >>>= 1;
613
- }
614
-
615
- return digit;
971
+ level: {
972
+ type: String,
973
+ default: defaultErrorCorrectLevel,
974
+ validator: function (l) { return validErrorCorrectLevel(l); },
616
975
  },
617
-
618
- getPatternPosition : function(typeNumber) {
619
- return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1];
976
+ background: {
977
+ type: String,
978
+ default: '#fff',
620
979
  },
621
-
622
- getMask : function(maskPattern, i, j) {
623
-
624
- switch (maskPattern) {
625
-
626
- case QRMaskPattern.PATTERN000 : return (i + j) % 2 == 0;
627
- case QRMaskPattern.PATTERN001 : return i % 2 == 0;
628
- case QRMaskPattern.PATTERN010 : return j % 3 == 0;
629
- case QRMaskPattern.PATTERN011 : return (i + j) % 3 == 0;
630
- case QRMaskPattern.PATTERN100 : return (Math.floor(i / 2) + Math.floor(j / 3) ) % 2 == 0;
631
- case QRMaskPattern.PATTERN101 : return (i * j) % 2 + (i * j) % 3 == 0;
632
- case QRMaskPattern.PATTERN110 : return ( (i * j) % 2 + (i * j) % 3) % 2 == 0;
633
- case QRMaskPattern.PATTERN111 : return ( (i * j) % 3 + (i + j) % 2) % 2 == 0;
634
-
635
- default :
636
- throw new Error("bad maskPattern:" + maskPattern);
637
- }
980
+ foreground: {
981
+ type: String,
982
+ default: '#000',
638
983
  },
639
-
640
- getErrorCorrectPolynomial : function(errorCorrectLength) {
641
-
642
- var a = new Polynomial$1([1], 0);
643
-
644
- for (var i = 0; i < errorCorrectLength; i++) {
645
- a = a.multiply(new Polynomial$1([1, math.gexp(i)], 0) );
646
- }
647
-
648
- return a;
649
- },
650
-
651
- getLengthInBits : function(mode, type) {
652
-
653
- if (1 <= type && type < 10) {
654
-
655
- // 1 - 9
656
-
657
- switch(mode) {
658
- case Mode.MODE_NUMBER : return 10;
659
- case Mode.MODE_ALPHA_NUM : return 9;
660
- case Mode.MODE_8BIT_BYTE : return 8;
661
- case Mode.MODE_KANJI : return 8;
662
- default :
663
- throw new Error("mode:" + mode);
664
- }
665
-
666
- } else if (type < 27) {
667
-
668
- // 10 - 26
669
-
670
- switch(mode) {
671
- case Mode.MODE_NUMBER : return 12;
672
- case Mode.MODE_ALPHA_NUM : return 11;
673
- case Mode.MODE_8BIT_BYTE : return 16;
674
- case Mode.MODE_KANJI : return 10;
675
- default :
676
- throw new Error("mode:" + mode);
677
- }
678
-
679
- } else if (type < 41) {
680
-
681
- // 27 - 40
682
-
683
- switch(mode) {
684
- case Mode.MODE_NUMBER : return 14;
685
- case Mode.MODE_ALPHA_NUM : return 13;
686
- case Mode.MODE_8BIT_BYTE : return 16;
687
- case Mode.MODE_KANJI : return 12;
688
- default :
689
- throw new Error("mode:" + mode);
690
- }
691
-
692
- } else {
693
- throw new Error("type:" + type);
694
- }
984
+ margin: {
985
+ type: Number,
986
+ required: false,
987
+ default: 0,
695
988
  },
696
-
697
- getLostPoint : function(qrCode) {
698
-
699
- var moduleCount = qrCode.getModuleCount();
700
-
701
- var lostPoint = 0;
702
-
703
- // LEVEL1
704
-
705
- for (var row = 0; row < moduleCount; row++) {
706
-
707
- for (var col = 0; col < moduleCount; col++) {
708
-
709
- var sameCount = 0;
710
- var dark = qrCode.isDark(row, col);
711
-
712
- for (var r = -1; r <= 1; r++) {
713
-
714
- if (row + r < 0 || moduleCount <= row + r) {
715
- continue;
716
- }
717
-
718
- for (var c = -1; c <= 1; c++) {
719
-
720
- if (col + c < 0 || moduleCount <= col + c) {
721
- continue;
722
- }
723
-
724
- if (r == 0 && c == 0) {
725
- continue;
726
- }
727
-
728
- if (dark == qrCode.isDark(row + r, col + c) ) {
729
- sameCount++;
730
- }
731
- }
732
- }
733
-
734
- if (sameCount > 5) {
735
- lostPoint += (3 + sameCount - 5);
736
- }
737
- }
738
- }
739
-
740
- // LEVEL2
741
-
742
- for (var row = 0; row < moduleCount - 1; row++) {
743
- for (var col = 0; col < moduleCount - 1; col++) {
744
- var count = 0;
745
- if (qrCode.isDark(row, col ) ) count++;
746
- if (qrCode.isDark(row + 1, col ) ) count++;
747
- if (qrCode.isDark(row, col + 1) ) count++;
748
- if (qrCode.isDark(row + 1, col + 1) ) count++;
749
- if (count == 0 || count == 4) {
750
- lostPoint += 3;
751
- }
752
- }
753
- }
754
-
755
- // LEVEL3
756
-
757
- for (var row = 0; row < moduleCount; row++) {
758
- for (var col = 0; col < moduleCount - 6; col++) {
759
- if (qrCode.isDark(row, col)
760
- && !qrCode.isDark(row, col + 1)
761
- && qrCode.isDark(row, col + 2)
762
- && qrCode.isDark(row, col + 3)
763
- && qrCode.isDark(row, col + 4)
764
- && !qrCode.isDark(row, col + 5)
765
- && qrCode.isDark(row, col + 6) ) {
766
- lostPoint += 40;
767
- }
768
- }
769
- }
770
-
771
- for (var col = 0; col < moduleCount; col++) {
772
- for (var row = 0; row < moduleCount - 6; row++) {
773
- if (qrCode.isDark(row, col)
774
- && !qrCode.isDark(row + 1, col)
775
- && qrCode.isDark(row + 2, col)
776
- && qrCode.isDark(row + 3, col)
777
- && qrCode.isDark(row + 4, col)
778
- && !qrCode.isDark(row + 5, col)
779
- && qrCode.isDark(row + 6, col) ) {
780
- lostPoint += 40;
781
- }
782
- }
783
- }
784
-
785
- // LEVEL4
786
-
787
- var darkCount = 0;
788
-
789
- for (var col = 0; col < moduleCount; col++) {
790
- for (var row = 0; row < moduleCount; row++) {
791
- if (qrCode.isDark(row, col) ) {
792
- darkCount++;
793
- }
794
- }
795
- }
796
-
797
- var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
798
- lostPoint += ratio * 10;
799
-
800
- return lostPoint;
801
- }
802
- };
803
-
804
- var util$1 = QRUtil;
805
-
806
- var BitByte = _8BitByte;
807
- var RSBlock = RSBlock$1;
808
- var BitBuffer = BitBuffer$1;
809
- var util = util$1;
810
- var Polynomial = Polynomial$2;
811
-
812
- function QRCode$1(typeNumber, errorCorrectLevel) {
813
- this.typeNumber = typeNumber;
814
- this.errorCorrectLevel = errorCorrectLevel;
815
- this.modules = null;
816
- this.moduleCount = 0;
817
- this.dataCache = null;
818
- this.dataList = [];
819
- }
820
-
821
- // for client side minification
822
- var proto = QRCode$1.prototype;
823
-
824
- proto.addData = function(data) {
825
- var newData = new BitByte(data);
826
- this.dataList.push(newData);
827
- this.dataCache = null;
828
- };
829
-
830
- proto.isDark = function(row, col) {
831
- if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) {
832
- throw new Error(row + "," + col);
833
- }
834
- return this.modules[row][col];
835
- };
836
-
837
- proto.getModuleCount = function() {
838
- return this.moduleCount;
839
- };
840
-
841
- proto.make = function() {
842
- // Calculate automatically typeNumber if provided is < 1
843
- if (this.typeNumber < 1 ){
844
- var typeNumber = 1;
845
- for (typeNumber = 1; typeNumber < 40; typeNumber++) {
846
- var rsBlocks = RSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel);
847
-
848
- var buffer = new BitBuffer();
849
- var totalDataCount = 0;
850
- for (var i = 0; i < rsBlocks.length; i++) {
851
- totalDataCount += rsBlocks[i].dataCount;
852
- }
853
-
854
- for (var i = 0; i < this.dataList.length; i++) {
855
- var data = this.dataList[i];
856
- buffer.put(data.mode, 4);
857
- buffer.put(data.getLength(), util.getLengthInBits(data.mode, typeNumber) );
858
- data.write(buffer);
859
- }
860
- if (buffer.getLengthInBits() <= totalDataCount * 8)
861
- break;
862
- }
863
- this.typeNumber = typeNumber;
864
- }
865
- this.makeImpl(false, this.getBestMaskPattern() );
866
989
  };
867
-
868
- proto.makeImpl = function(test, maskPattern) {
869
-
870
- this.moduleCount = this.typeNumber * 4 + 17;
871
- this.modules = new Array(this.moduleCount);
872
-
873
- for (var row = 0; row < this.moduleCount; row++) {
874
-
875
- this.modules[row] = new Array(this.moduleCount);
876
-
877
- for (var col = 0; col < this.moduleCount; col++) {
878
- this.modules[row][col] = null;//(col + row) % 3;
879
- }
880
- }
881
-
882
- this.setupPositionProbePattern(0, 0);
883
- this.setupPositionProbePattern(this.moduleCount - 7, 0);
884
- this.setupPositionProbePattern(0, this.moduleCount - 7);
885
- this.setupPositionAdjustPattern();
886
- this.setupTimingPattern();
887
- this.setupTypeInfo(test, maskPattern);
888
-
889
- if (this.typeNumber >= 7) {
890
- this.setupTypeNumber(test);
891
- }
892
-
893
- if (this.dataCache == null) {
894
- this.dataCache = QRCode$1.createData(this.typeNumber, this.errorCorrectLevel, this.dataList);
895
- }
896
-
897
- this.mapData(this.dataCache, maskPattern);
898
- };
899
-
900
- proto.setupPositionProbePattern = function(row, col) {
901
-
902
- for (var r = -1; r <= 7; r++) {
903
-
904
- if (row + r <= -1 || this.moduleCount <= row + r) continue;
905
-
906
- for (var c = -1; c <= 7; c++) {
907
-
908
- if (col + c <= -1 || this.moduleCount <= col + c) continue;
909
-
910
- if ( (0 <= r && r <= 6 && (c == 0 || c == 6) )
911
- || (0 <= c && c <= 6 && (r == 0 || r == 6) )
912
- || (2 <= r && r <= 4 && 2 <= c && c <= 4) ) {
913
- this.modules[row + r][col + c] = true;
914
- } else {
915
- this.modules[row + r][col + c] = false;
916
- }
917
- }
918
- }
919
- };
920
-
921
- proto.getBestMaskPattern = function() {
922
-
923
- var minLostPoint = 0;
924
- var pattern = 0;
925
-
926
- for (var i = 0; i < 8; i++) {
927
-
928
- this.makeImpl(true, i);
929
-
930
- var lostPoint = util.getLostPoint(this);
931
-
932
- if (i == 0 || minLostPoint > lostPoint) {
933
- minLostPoint = lostPoint;
934
- pattern = i;
935
- }
936
- }
937
-
938
- return pattern;
939
- };
940
-
941
- proto.createMovieClip = function(target_mc, instance_name, depth) {
942
-
943
- var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth);
944
- var cs = 1;
945
-
946
- this.make();
947
-
948
- for (var row = 0; row < this.modules.length; row++) {
949
-
950
- var y = row * cs;
951
-
952
- for (var col = 0; col < this.modules[row].length; col++) {
953
-
954
- var x = col * cs;
955
- var dark = this.modules[row][col];
956
-
957
- if (dark) {
958
- qr_mc.beginFill(0, 100);
959
- qr_mc.moveTo(x, y);
960
- qr_mc.lineTo(x + cs, y);
961
- qr_mc.lineTo(x + cs, y + cs);
962
- qr_mc.lineTo(x, y + cs);
963
- qr_mc.endFill();
964
- }
965
- }
966
- }
967
-
968
- return qr_mc;
969
- };
970
-
971
- proto.setupTimingPattern = function() {
972
-
973
- for (var r = 8; r < this.moduleCount - 8; r++) {
974
- if (this.modules[r][6] != null) {
975
- continue;
976
- }
977
- this.modules[r][6] = (r % 2 == 0);
978
- }
979
-
980
- for (var c = 8; c < this.moduleCount - 8; c++) {
981
- if (this.modules[6][c] != null) {
982
- continue;
983
- }
984
- this.modules[6][c] = (c % 2 == 0);
985
- }
986
- };
987
-
988
- proto.setupPositionAdjustPattern = function() {
989
-
990
- var pos = util.getPatternPosition(this.typeNumber);
991
-
992
- for (var i = 0; i < pos.length; i++) {
993
-
994
- for (var j = 0; j < pos.length; j++) {
995
-
996
- var row = pos[i];
997
- var col = pos[j];
998
-
999
- if (this.modules[row][col] != null) {
1000
- continue;
1001
- }
1002
-
1003
- for (var r = -2; r <= 2; r++) {
1004
-
1005
- for (var c = -2; c <= 2; c++) {
1006
-
1007
- if (r == -2 || r == 2 || c == -2 || c == 2
1008
- || (r == 0 && c == 0) ) {
1009
- this.modules[row + r][col + c] = true;
1010
- } else {
1011
- this.modules[row + r][col + c] = false;
1012
- }
1013
- }
1014
- }
1015
- }
1016
- }
1017
- };
1018
-
1019
- proto.setupTypeNumber = function(test) {
1020
-
1021
- var bits = util.getBCHTypeNumber(this.typeNumber);
1022
-
1023
- for (var i = 0; i < 18; i++) {
1024
- var mod = (!test && ( (bits >> i) & 1) == 1);
1025
- this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod;
1026
- }
1027
-
1028
- for (var i = 0; i < 18; i++) {
1029
- var mod = (!test && ( (bits >> i) & 1) == 1);
1030
- this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
1031
- }
1032
- };
1033
-
1034
- proto.setupTypeInfo = function(test, maskPattern) {
1035
-
1036
- var data = (this.errorCorrectLevel << 3) | maskPattern;
1037
- var bits = util.getBCHTypeInfo(data);
1038
-
1039
- // vertical
1040
- for (var i = 0; i < 15; i++) {
1041
-
1042
- var mod = (!test && ( (bits >> i) & 1) == 1);
1043
-
1044
- if (i < 6) {
1045
- this.modules[i][8] = mod;
1046
- } else if (i < 8) {
1047
- this.modules[i + 1][8] = mod;
1048
- } else {
1049
- this.modules[this.moduleCount - 15 + i][8] = mod;
1050
- }
1051
- }
1052
-
1053
- // horizontal
1054
- for (var i = 0; i < 15; i++) {
1055
-
1056
- var mod = (!test && ( (bits >> i) & 1) == 1);
1057
-
1058
- if (i < 8) {
1059
- this.modules[8][this.moduleCount - i - 1] = mod;
1060
- } else if (i < 9) {
1061
- this.modules[8][15 - i - 1 + 1] = mod;
1062
- } else {
1063
- this.modules[8][15 - i - 1] = mod;
1064
- }
1065
- }
1066
-
1067
- // fixed module
1068
- this.modules[this.moduleCount - 8][8] = (!test);
1069
- };
1070
-
1071
- proto.mapData = function(data, maskPattern) {
1072
-
1073
- var inc = -1;
1074
- var row = this.moduleCount - 1;
1075
- var bitIndex = 7;
1076
- var byteIndex = 0;
1077
-
1078
- for (var col = this.moduleCount - 1; col > 0; col -= 2) {
1079
-
1080
- if (col == 6) col--;
1081
-
1082
- while (true) {
1083
-
1084
- for (var c = 0; c < 2; c++) {
1085
-
1086
- if (this.modules[row][col - c] == null) {
1087
-
1088
- var dark = false;
1089
-
1090
- if (byteIndex < data.length) {
1091
- dark = ( ( (data[byteIndex] >>> bitIndex) & 1) == 1);
1092
- }
1093
-
1094
- var mask = util.getMask(maskPattern, row, col - c);
1095
-
1096
- if (mask) {
1097
- dark = !dark;
1098
- }
1099
-
1100
- this.modules[row][col - c] = dark;
1101
- bitIndex--;
1102
-
1103
- if (bitIndex == -1) {
1104
- byteIndex++;
1105
- bitIndex = 7;
1106
- }
1107
- }
1108
- }
1109
-
1110
- row += inc;
1111
-
1112
- if (row < 0 || this.moduleCount <= row) {
1113
- row -= inc;
1114
- inc = -inc;
1115
- break;
1116
- }
1117
- }
1118
- }
1119
- };
1120
-
1121
- QRCode$1.PAD0 = 0xEC;
1122
- QRCode$1.PAD1 = 0x11;
1123
-
1124
- QRCode$1.createData = function(typeNumber, errorCorrectLevel, dataList) {
1125
-
1126
- var rsBlocks = RSBlock.getRSBlocks(typeNumber, errorCorrectLevel);
1127
-
1128
- var buffer = new BitBuffer();
1129
-
1130
- for (var i = 0; i < dataList.length; i++) {
1131
- var data = dataList[i];
1132
- buffer.put(data.mode, 4);
1133
- buffer.put(data.getLength(), util.getLengthInBits(data.mode, typeNumber) );
1134
- data.write(buffer);
1135
- }
1136
-
1137
- // calc num max data.
1138
- var totalDataCount = 0;
1139
- for (var i = 0; i < rsBlocks.length; i++) {
1140
- totalDataCount += rsBlocks[i].dataCount;
1141
- }
1142
-
1143
- if (buffer.getLengthInBits() > totalDataCount * 8) {
1144
- throw new Error("code length overflow. ("
1145
- + buffer.getLengthInBits()
1146
- + ">"
1147
- + totalDataCount * 8
1148
- + ")");
1149
- }
1150
-
1151
- // end code
1152
- if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
1153
- buffer.put(0, 4);
1154
- }
1155
-
1156
- // padding
1157
- while (buffer.getLengthInBits() % 8 != 0) {
1158
- buffer.putBit(false);
1159
- }
1160
-
1161
- // padding
1162
- while (true) {
1163
-
1164
- if (buffer.getLengthInBits() >= totalDataCount * 8) {
1165
- break;
1166
- }
1167
- buffer.put(QRCode$1.PAD0, 8);
1168
-
1169
- if (buffer.getLengthInBits() >= totalDataCount * 8) {
1170
- break;
1171
- }
1172
- buffer.put(QRCode$1.PAD1, 8);
1173
- }
1174
-
1175
- return QRCode$1.createBytes(buffer, rsBlocks);
1176
- };
1177
-
1178
- QRCode$1.createBytes = function(buffer, rsBlocks) {
1179
-
1180
- var offset = 0;
1181
-
1182
- var maxDcCount = 0;
1183
- var maxEcCount = 0;
1184
-
1185
- var dcdata = new Array(rsBlocks.length);
1186
- var ecdata = new Array(rsBlocks.length);
1187
-
1188
- for (var r = 0; r < rsBlocks.length; r++) {
1189
-
1190
- var dcCount = rsBlocks[r].dataCount;
1191
- var ecCount = rsBlocks[r].totalCount - dcCount;
1192
-
1193
- maxDcCount = Math.max(maxDcCount, dcCount);
1194
- maxEcCount = Math.max(maxEcCount, ecCount);
1195
-
1196
- dcdata[r] = new Array(dcCount);
1197
-
1198
- for (var i = 0; i < dcdata[r].length; i++) {
1199
- dcdata[r][i] = 0xff & buffer.buffer[i + offset];
1200
- }
1201
- offset += dcCount;
1202
-
1203
- var rsPoly = util.getErrorCorrectPolynomial(ecCount);
1204
- var rawPoly = new Polynomial(dcdata[r], rsPoly.getLength() - 1);
1205
-
1206
- var modPoly = rawPoly.mod(rsPoly);
1207
- ecdata[r] = new Array(rsPoly.getLength() - 1);
1208
- for (var i = 0; i < ecdata[r].length; i++) {
1209
- var modIndex = i + modPoly.getLength() - ecdata[r].length;
1210
- ecdata[r][i] = (modIndex >= 0)? modPoly.get(modIndex) : 0;
1211
- }
1212
-
1213
- }
1214
-
1215
- var totalCodeCount = 0;
1216
- for (var i = 0; i < rsBlocks.length; i++) {
1217
- totalCodeCount += rsBlocks[i].totalCount;
1218
- }
1219
-
1220
- var data = new Array(totalCodeCount);
1221
- var index = 0;
1222
-
1223
- for (var i = 0; i < maxDcCount; i++) {
1224
- for (var r = 0; r < rsBlocks.length; r++) {
1225
- if (i < dcdata[r].length) {
1226
- data[index++] = dcdata[r][i];
1227
- }
1228
- }
1229
- }
1230
-
1231
- for (var i = 0; i < maxEcCount; i++) {
1232
- for (var r = 0; r < rsBlocks.length; r++) {
1233
- if (i < ecdata[r].length) {
1234
- data[index++] = ecdata[r][i];
1235
- }
1236
- }
1237
- }
1238
-
1239
- return data;
1240
- };
1241
-
1242
- var QRCode_1 = QRCode$1;
1243
-
1244
- var defaultErrorCorrectLevel = 'H';
1245
- // Thanks the `qrcode.react`
1246
- var SUPPORTS_PATH2D = (function () {
1247
- try {
1248
- new Path2D().addPath(new Path2D());
1249
- }
1250
- catch (e) {
1251
- return false;
1252
- }
1253
- return true;
1254
- })();
1255
- function QRCode(data, level) {
1256
- var errorCorrectLevel = ErrorCorrectLevel[level];
1257
- // We'll use type===-1 to force QRCode to automatically pick the best type
1258
- var qrcode = new QRCode_1(-1, errorCorrectLevel);
1259
- qrcode.addData(toUTF8String(data));
1260
- qrcode.make();
1261
- return qrcode;
1262
- }
1263
- function validErrorCorrectLevel(level) {
1264
- return level in ErrorCorrectLevel;
1265
- }
1266
- /**
1267
- * Encode UTF16 to UTF8.
1268
- * See: http://jonisalonen.com/2012/from-utf-16-to-utf-8-in-javascript/
1269
- * @param str {string}
1270
- * @returns {string}
1271
- */
1272
- function toUTF8String(str) {
1273
- var utf8Str = '';
1274
- for (var i = 0; i < str.length; i++) {
1275
- var charCode = str.charCodeAt(i);
1276
- if (charCode < 0x0080) {
1277
- utf8Str += String.fromCharCode(charCode);
1278
- }
1279
- else if (charCode < 0x0800) {
1280
- utf8Str += String.fromCharCode(0xc0 | (charCode >> 6));
1281
- utf8Str += String.fromCharCode(0x80 | (charCode & 0x3f));
1282
- }
1283
- else if (charCode < 0xd800 || charCode >= 0xe000) {
1284
- utf8Str += String.fromCharCode(0xe0 | (charCode >> 12));
1285
- utf8Str += String.fromCharCode(0x80 | ((charCode >> 6) & 0x3f));
1286
- utf8Str += String.fromCharCode(0x80 | (charCode & 0x3f));
1287
- }
1288
- else {
1289
- // surrogate pair
1290
- i++;
1291
- // UTF-16 encodes 0x10000-0x10FFFF by
1292
- // subtracting 0x10000 and splitting the
1293
- // 20 bits of 0x0-0xFFFFF into two halves
1294
- charCode =
1295
- 0x10000 + (((charCode & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff));
1296
- utf8Str += String.fromCharCode(0xf0 | (charCode >> 18));
1297
- utf8Str += String.fromCharCode(0x80 | ((charCode >> 12) & 0x3f));
1298
- utf8Str += String.fromCharCode(0x80 | ((charCode >> 6) & 0x3f));
1299
- utf8Str += String.fromCharCode(0x80 | (charCode & 0x3f));
1300
- }
1301
- }
1302
- return utf8Str;
1303
- }
1304
- function generatePath(modules, margin) {
1305
- if (margin === void 0) { margin = 0; }
1306
- var ops = [];
1307
- modules.forEach(function (row, y) {
1308
- var start = null;
1309
- row.forEach(function (cell, x) {
1310
- if (!cell && start !== null) {
1311
- // M0 0h7v1H0z injects the space with the move and drops the comma,
1312
- // saving a char per operation
1313
- ops.push("M".concat(start + margin, " ").concat(y + margin, "h").concat(x - start, "v1H").concat(start + margin, "z"));
1314
- start = null;
1315
- return;
1316
- }
1317
- // end of row, clean up or skip
1318
- if (x === row.length - 1) {
1319
- if (!cell) {
1320
- // We would have closed the op above already so this can only mean
1321
- // 2+ light modules in a row.
1322
- return;
1323
- }
1324
- if (start === null) {
1325
- // Just a single dark module.
1326
- ops.push("M".concat(x + margin, ",").concat(y + margin, " h1v1H").concat(x + margin, "z"));
1327
- }
1328
- else {
1329
- // Otherwise finish the current line.
1330
- ops.push("M".concat(start + margin, ",").concat(y + margin, " h").concat(x + 1 - start, "v1H").concat(start + margin, "z"));
1331
- }
1332
- return;
1333
- }
1334
- if (cell && start === null) {
1335
- start = x;
1336
- }
1337
- });
1338
- });
1339
- return ops.join('');
1340
- }
1341
- var QRCodeProps = {
1342
- value: {
1343
- type: String,
1344
- required: true,
1345
- "default": ''
1346
- },
1347
- size: {
1348
- type: Number,
1349
- "default": 100
1350
- },
1351
- level: {
1352
- type: String,
1353
- "default": defaultErrorCorrectLevel,
1354
- validator: function (l) { return validErrorCorrectLevel(l); }
1355
- },
1356
- background: {
1357
- type: String,
1358
- "default": '#fff'
1359
- },
1360
- foreground: {
1361
- type: String,
1362
- "default": '#000'
1363
- },
1364
- margin: {
1365
- type: Number,
1366
- required: false,
1367
- "default": 0
1368
- }
1369
- };
1370
- var QRCodeVueProps = __assign(__assign({}, QRCodeProps), { renderAs: {
1371
- type: String,
1372
- required: false,
1373
- "default": 'canvas',
1374
- validator: function (as) { return ['canvas', 'svg'].indexOf(as) > -1; }
1375
- } });
1376
- var QRCodeSvg = vue.defineComponent({
1377
- name: 'QRCodeSvg',
1378
- props: QRCodeProps,
1379
- setup: function (props) {
1380
- var numCells = vue.ref(0);
1381
- var fgPath = vue.ref('');
1382
- var generate = function () {
1383
- var value = props.value, level = props.level, margin = props.margin;
1384
- var cells = QRCode(value, level).modules;
1385
- numCells.value = cells.length + margin * 2;
1386
- // Drawing strategy: instead of a rect per module, we're going to create a
1387
- // single path for the dark modules and layer that on top of a light rect,
1388
- // for a total of 2 DOM nodes. We pay a bit more in string concat but that's
1389
- // way faster than DOM ops.
1390
- // For level 1, 441 nodes -> 2
1391
- // For level 40, 31329 -> 2
1392
- fgPath.value = generatePath(cells, margin);
1393
- };
1394
- generate();
1395
- vue.onUpdated(generate);
1396
- return function () { return vue.h('svg', {
1397
- width: props.size,
1398
- height: props.size,
1399
- 'shape-rendering': "crispEdges",
1400
- xmlns: 'http://www.w3.org/2000/svg',
1401
- viewBox: "0 0 ".concat(numCells.value, " ").concat(numCells.value)
1402
- }, [
1403
- vue.h('path', {
1404
- fill: props.background,
1405
- d: "M0,0 h".concat(numCells.value, "v").concat(numCells.value, "H0z")
1406
- }),
1407
- vue.h('path', { fill: props.foreground, d: fgPath.value }),
1408
- ]); };
1409
- }
1410
- });
1411
- var QRCodeCanvas = vue.defineComponent({
1412
- name: 'QRCodeCanvas',
1413
- props: QRCodeProps,
1414
- setup: function (props) {
1415
- var canvasEl = vue.ref(null);
1416
- var generate = function () {
1417
- var value = props.value, level = props.level, size = props.size, margin = props.margin, background = props.background, foreground = props.foreground;
1418
- var cells = QRCode(value, level).modules;
1419
- var numCells = cells.length + margin * 2;
1420
- var canvas = canvasEl.value;
1421
- if (!canvas) {
1422
- return;
1423
- }
1424
- var ctx = canvas.getContext('2d');
1425
- if (!ctx) {
1426
- return;
1427
- }
1428
- var devicePixelRatio = window.devicePixelRatio || 1;
1429
- var scale = (size / numCells) * devicePixelRatio;
1430
- canvas.height = canvas.width = size * devicePixelRatio;
1431
- ctx.scale(scale, scale);
1432
- ctx.fillStyle = background;
1433
- ctx.fillRect(0, 0, numCells, numCells);
1434
- ctx.fillStyle = foreground;
1435
- if (SUPPORTS_PATH2D) {
1436
- ctx.fill(new Path2D(generatePath(cells, margin)));
1437
- }
1438
- else {
1439
- cells.forEach(function (row, rdx) {
1440
- row.forEach(function (cell, cdx) {
1441
- if (cell) {
1442
- ctx.fillRect(cdx + margin, rdx + margin, 1, 1);
1443
- }
1444
- });
1445
- });
1446
- }
1447
- };
1448
- vue.onMounted(generate);
1449
- vue.onUpdated(generate);
1450
- return function () { return vue.h('canvas', {
1451
- ref: canvasEl,
1452
- style: { width: "".concat(props.size, "px"), height: "".concat(props.size, "px") }
1453
- }); };
1454
- }
1455
- });
1456
- var QrcodeVue = vue.defineComponent({
1457
- name: 'Qrcode',
1458
- render: function () {
1459
- var _a = this.$props, renderAs = _a.renderAs, value = _a.value, _size = _a.size, _margin = _a.margin, _level = _a.level, background = _a.background, foreground = _a.foreground;
1460
- var size = _size >>> 0;
1461
- var margin = _margin >>> 0;
1462
- var level = validErrorCorrectLevel(_level) ? _level : defaultErrorCorrectLevel;
1463
- return vue.h(renderAs === 'svg' ? QRCodeSvg : QRCodeCanvas, { value: value, size: size, margin: margin, level: level, background: background, foreground: foreground });
1464
- },
1465
- props: QRCodeVueProps
990
+ var QRCodeVueProps = __assign(__assign({}, QRCodeProps), { renderAs: {
991
+ type: String,
992
+ required: false,
993
+ default: 'canvas',
994
+ validator: function (as) { return ['canvas', 'svg'].indexOf(as) > -1; },
995
+ } });
996
+ var QRCodeSvg = vue.defineComponent({
997
+ name: 'QRCodeSvg',
998
+ props: QRCodeProps,
999
+ setup: function (props) {
1000
+ var numCells = vue.ref(0);
1001
+ var fgPath = vue.ref('');
1002
+ var generate = function () {
1003
+ var value = props.value, level = props.level, margin = props.margin;
1004
+ var cells = QR.QrCode.encodeText(value, ErrorCorrectLevelMap[level]).getModules();
1005
+ numCells.value = cells.length + margin * 2;
1006
+ // Drawing strategy: instead of a rect per module, we're going to create a
1007
+ // single path for the dark modules and layer that on top of a light rect,
1008
+ // for a total of 2 DOM nodes. We pay a bit more in string concat but that's
1009
+ // way faster than DOM ops.
1010
+ // For level 1, 441 nodes -> 2
1011
+ // For level 40, 31329 -> 2
1012
+ fgPath.value = generatePath(cells, margin);
1013
+ };
1014
+ generate();
1015
+ vue.onUpdated(generate);
1016
+ return function () { return vue.h('svg', {
1017
+ width: props.size,
1018
+ height: props.size,
1019
+ 'shape-rendering': "crispEdges",
1020
+ xmlns: 'http://www.w3.org/2000/svg',
1021
+ viewBox: "0 0 ".concat(numCells.value, " ").concat(numCells.value),
1022
+ }, [
1023
+ vue.h('path', {
1024
+ fill: props.background,
1025
+ d: "M0,0 h".concat(numCells.value, "v").concat(numCells.value, "H0z"),
1026
+ }),
1027
+ vue.h('path', { fill: props.foreground, d: fgPath.value }),
1028
+ ]); };
1029
+ },
1030
+ });
1031
+ var QRCodeCanvas = vue.defineComponent({
1032
+ name: 'QRCodeCanvas',
1033
+ props: QRCodeProps,
1034
+ setup: function (props) {
1035
+ var canvasEl = vue.ref(null);
1036
+ var generate = function () {
1037
+ var value = props.value, level = props.level, size = props.size, margin = props.margin, background = props.background, foreground = props.foreground;
1038
+ var canvas = canvasEl.value;
1039
+ if (!canvas) {
1040
+ return;
1041
+ }
1042
+ var ctx = canvas.getContext('2d');
1043
+ if (!ctx) {
1044
+ return;
1045
+ }
1046
+ var cells = QR.QrCode.encodeText(value, ErrorCorrectLevelMap[level]).getModules();
1047
+ var numCells = cells.length + margin * 2;
1048
+ var devicePixelRatio = window.devicePixelRatio || 1;
1049
+ var scale = (size / numCells) * devicePixelRatio;
1050
+ canvas.height = canvas.width = size * devicePixelRatio;
1051
+ ctx.scale(scale, scale);
1052
+ ctx.fillStyle = background;
1053
+ ctx.fillRect(0, 0, numCells, numCells);
1054
+ ctx.fillStyle = foreground;
1055
+ if (SUPPORTS_PATH2D) {
1056
+ ctx.fill(new Path2D(generatePath(cells, margin)));
1057
+ }
1058
+ else {
1059
+ cells.forEach(function (row, rdx) {
1060
+ row.forEach(function (cell, cdx) {
1061
+ if (cell) {
1062
+ ctx.fillRect(cdx + margin, rdx + margin, 1, 1);
1063
+ }
1064
+ });
1065
+ });
1066
+ }
1067
+ };
1068
+ vue.onMounted(generate);
1069
+ vue.onUpdated(generate);
1070
+ return function () { return vue.h('canvas', {
1071
+ ref: canvasEl,
1072
+ style: { width: "".concat(props.size, "px"), height: "".concat(props.size, "px") },
1073
+ }); };
1074
+ },
1075
+ });
1076
+ var QrcodeVue = vue.defineComponent({
1077
+ name: 'Qrcode',
1078
+ render: function () {
1079
+ var _a = this.$props, renderAs = _a.renderAs, value = _a.value, _size = _a.size, _margin = _a.margin, _level = _a.level, background = _a.background, foreground = _a.foreground;
1080
+ var size = _size >>> 0;
1081
+ var margin = _margin >>> 0;
1082
+ var level = validErrorCorrectLevel(_level) ? _level : defaultErrorCorrectLevel;
1083
+ return vue.h(renderAs === 'svg' ? QRCodeSvg : QRCodeCanvas, { value: value, size: size, margin: margin, level: level, background: background, foreground: foreground });
1084
+ },
1085
+ props: QRCodeVueProps,
1466
1086
  });
1467
1087
 
1468
1088
  module.exports = QrcodeVue;