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