@taybart/corvid 0.1.4 → 0.1.6
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.
- package/README.md +11 -0
- package/dist/dom.d.ts +3 -1
- package/dist/index.js +30 -3
- package/dist/qr/index.d.ts +41 -0
- package/dist/qr/qr-generator.d.ts +71 -0
- package/dist/qr/qr-utils.d.ts +28 -0
- package/dist/qr.js +2078 -0
- package/dist/utils.d.ts +1 -0
- package/package.json +5 -1
- package/dist/qr.d.ts +0 -22
- package/dist/renderer.d.ts +0 -0
package/dist/qr.js
ADDED
|
@@ -0,0 +1,2078 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
3
|
+
value: value,
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true
|
|
7
|
+
});
|
|
8
|
+
else obj[key] = value;
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
class QRUtil {
|
|
12
|
+
static getBCHDigit(data) {
|
|
13
|
+
let digit = 0;
|
|
14
|
+
while(0 != data){
|
|
15
|
+
digit += 1;
|
|
16
|
+
data >>>= 1;
|
|
17
|
+
}
|
|
18
|
+
return digit;
|
|
19
|
+
}
|
|
20
|
+
static getBCHTypeInfo(data) {
|
|
21
|
+
let d = data << 10;
|
|
22
|
+
while(this.getBCHDigit(d) - this.getBCHDigit(this.G15) >= 0)d ^= this.G15 << this.getBCHDigit(d) - this.getBCHDigit(this.G15);
|
|
23
|
+
return (data << 10 | d) ^ this.G15_MASK;
|
|
24
|
+
}
|
|
25
|
+
static getBCHTypeNumber(data) {
|
|
26
|
+
let d = data << 12;
|
|
27
|
+
while(this.getBCHDigit(d) - this.getBCHDigit(this.G18) >= 0)d ^= this.G18 << this.getBCHDigit(d) - this.getBCHDigit(this.G18);
|
|
28
|
+
return data << 12 | d;
|
|
29
|
+
}
|
|
30
|
+
static getPatternPosition(typeNumber) {
|
|
31
|
+
return this.PATTERN_POSITION_TABLE[typeNumber - 1];
|
|
32
|
+
}
|
|
33
|
+
static getMaskFunction(maskPattern) {
|
|
34
|
+
switch(maskPattern){
|
|
35
|
+
case 0:
|
|
36
|
+
return (i, j)=>(i + j) % 2 == 0;
|
|
37
|
+
case 1:
|
|
38
|
+
return (i, j)=>i % 2 == 0;
|
|
39
|
+
case 2:
|
|
40
|
+
return (i, j)=>j % 3 == 0;
|
|
41
|
+
case 3:
|
|
42
|
+
return (i, j)=>(i + j) % 3 == 0;
|
|
43
|
+
case 4:
|
|
44
|
+
return (i, j)=>(Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0;
|
|
45
|
+
case 5:
|
|
46
|
+
return (i, j)=>i * j % 2 + i * j % 3 == 0;
|
|
47
|
+
case 6:
|
|
48
|
+
return (i, j)=>(i * j % 2 + i * j % 3) % 2 == 0;
|
|
49
|
+
case 7:
|
|
50
|
+
return (i, j)=>(i * j % 3 + (i + j) % 2) % 2 == 0;
|
|
51
|
+
default:
|
|
52
|
+
throw new Error('bad maskPattern:' + maskPattern);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
static getErrorCorrectPolynomial(errorCorrectLength) {
|
|
56
|
+
throw new Error('Not implemented');
|
|
57
|
+
}
|
|
58
|
+
static getLengthInBits(mode, type) {
|
|
59
|
+
if (4 != mode || type < 1 || type > 40) throw new Error('mode: ' + mode + '; type: ' + type);
|
|
60
|
+
return type < 10 ? 8 : 16;
|
|
61
|
+
}
|
|
62
|
+
static getLostPoint(qrcode) {
|
|
63
|
+
const moduleCount = qrcode.getModuleCount();
|
|
64
|
+
let lostPoint = 0;
|
|
65
|
+
for(let row = 0; row < moduleCount; row += 1)for(let col = 0; col < moduleCount; col += 1){
|
|
66
|
+
let sameCount = 0;
|
|
67
|
+
const dark = qrcode.isDark(row, col);
|
|
68
|
+
for(let r = -1; r <= 1; r += 1)if (!(row + r < 0) && !(moduleCount <= row + r)) {
|
|
69
|
+
for(let c = -1; c <= 1; c += 1)if (!(col + c < 0) && !(moduleCount <= col + c)) {
|
|
70
|
+
if (0 != r || 0 != c) {
|
|
71
|
+
if (dark == qrcode.isDark(row + r, col + c)) sameCount += 1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (sameCount > 5) lostPoint += 3 + sameCount - 5;
|
|
76
|
+
}
|
|
77
|
+
for(let row = 0; row < moduleCount - 1; row += 1)for(let col = 0; col < moduleCount - 1; col += 1){
|
|
78
|
+
let count = 0;
|
|
79
|
+
if (qrcode.isDark(row, col)) count += 1;
|
|
80
|
+
if (qrcode.isDark(row + 1, col)) count += 1;
|
|
81
|
+
if (qrcode.isDark(row, col + 1)) count += 1;
|
|
82
|
+
if (qrcode.isDark(row + 1, col + 1)) count += 1;
|
|
83
|
+
if (0 == count || 4 == count) lostPoint += 3;
|
|
84
|
+
}
|
|
85
|
+
for(let row = 0; row < moduleCount; row += 1)for(let col = 0; col < moduleCount - 6; col += 1)if (qrcode.isDark(row, col) && !qrcode.isDark(row, col + 1) && qrcode.isDark(row, col + 2) && qrcode.isDark(row, col + 3) && qrcode.isDark(row, col + 4) && !qrcode.isDark(row, col + 5) && qrcode.isDark(row, col + 6)) lostPoint += 40;
|
|
86
|
+
for(let col = 0; col < moduleCount; col += 1)for(let row = 0; row < moduleCount - 6; row += 1)if (qrcode.isDark(row, col) && !qrcode.isDark(row + 1, col) && qrcode.isDark(row + 2, col) && qrcode.isDark(row + 3, col) && qrcode.isDark(row + 4, col) && !qrcode.isDark(row + 5, col) && qrcode.isDark(row + 6, col)) lostPoint += 40;
|
|
87
|
+
let darkCount = 0;
|
|
88
|
+
for(let col = 0; col < moduleCount; col += 1)for(let row = 0; row < moduleCount; row += 1)if (qrcode.isDark(row, col)) darkCount += 1;
|
|
89
|
+
const ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
|
|
90
|
+
lostPoint += 10 * ratio;
|
|
91
|
+
return lostPoint;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
_define_property(QRUtil, "PATTERN_POSITION_TABLE", [
|
|
95
|
+
[],
|
|
96
|
+
[
|
|
97
|
+
6,
|
|
98
|
+
18
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
6,
|
|
102
|
+
22
|
|
103
|
+
],
|
|
104
|
+
[
|
|
105
|
+
6,
|
|
106
|
+
26
|
|
107
|
+
],
|
|
108
|
+
[
|
|
109
|
+
6,
|
|
110
|
+
30
|
|
111
|
+
],
|
|
112
|
+
[
|
|
113
|
+
6,
|
|
114
|
+
34
|
|
115
|
+
],
|
|
116
|
+
[
|
|
117
|
+
6,
|
|
118
|
+
22,
|
|
119
|
+
38
|
|
120
|
+
],
|
|
121
|
+
[
|
|
122
|
+
6,
|
|
123
|
+
24,
|
|
124
|
+
42
|
|
125
|
+
],
|
|
126
|
+
[
|
|
127
|
+
6,
|
|
128
|
+
26,
|
|
129
|
+
46
|
|
130
|
+
],
|
|
131
|
+
[
|
|
132
|
+
6,
|
|
133
|
+
28,
|
|
134
|
+
50
|
|
135
|
+
],
|
|
136
|
+
[
|
|
137
|
+
6,
|
|
138
|
+
30,
|
|
139
|
+
54
|
|
140
|
+
],
|
|
141
|
+
[
|
|
142
|
+
6,
|
|
143
|
+
32,
|
|
144
|
+
58
|
|
145
|
+
],
|
|
146
|
+
[
|
|
147
|
+
6,
|
|
148
|
+
34,
|
|
149
|
+
62
|
|
150
|
+
],
|
|
151
|
+
[
|
|
152
|
+
6,
|
|
153
|
+
26,
|
|
154
|
+
46,
|
|
155
|
+
66
|
|
156
|
+
],
|
|
157
|
+
[
|
|
158
|
+
6,
|
|
159
|
+
26,
|
|
160
|
+
48,
|
|
161
|
+
70
|
|
162
|
+
],
|
|
163
|
+
[
|
|
164
|
+
6,
|
|
165
|
+
26,
|
|
166
|
+
50,
|
|
167
|
+
74
|
|
168
|
+
],
|
|
169
|
+
[
|
|
170
|
+
6,
|
|
171
|
+
30,
|
|
172
|
+
54,
|
|
173
|
+
78
|
|
174
|
+
],
|
|
175
|
+
[
|
|
176
|
+
6,
|
|
177
|
+
30,
|
|
178
|
+
56,
|
|
179
|
+
82
|
|
180
|
+
],
|
|
181
|
+
[
|
|
182
|
+
6,
|
|
183
|
+
30,
|
|
184
|
+
58,
|
|
185
|
+
86
|
|
186
|
+
],
|
|
187
|
+
[
|
|
188
|
+
6,
|
|
189
|
+
34,
|
|
190
|
+
62,
|
|
191
|
+
90
|
|
192
|
+
],
|
|
193
|
+
[
|
|
194
|
+
6,
|
|
195
|
+
28,
|
|
196
|
+
50,
|
|
197
|
+
72,
|
|
198
|
+
94
|
|
199
|
+
],
|
|
200
|
+
[
|
|
201
|
+
6,
|
|
202
|
+
26,
|
|
203
|
+
50,
|
|
204
|
+
74,
|
|
205
|
+
98
|
|
206
|
+
],
|
|
207
|
+
[
|
|
208
|
+
6,
|
|
209
|
+
30,
|
|
210
|
+
54,
|
|
211
|
+
78,
|
|
212
|
+
102
|
|
213
|
+
],
|
|
214
|
+
[
|
|
215
|
+
6,
|
|
216
|
+
28,
|
|
217
|
+
54,
|
|
218
|
+
80,
|
|
219
|
+
106
|
|
220
|
+
],
|
|
221
|
+
[
|
|
222
|
+
6,
|
|
223
|
+
32,
|
|
224
|
+
58,
|
|
225
|
+
84,
|
|
226
|
+
110
|
|
227
|
+
],
|
|
228
|
+
[
|
|
229
|
+
6,
|
|
230
|
+
30,
|
|
231
|
+
58,
|
|
232
|
+
86,
|
|
233
|
+
114
|
|
234
|
+
],
|
|
235
|
+
[
|
|
236
|
+
6,
|
|
237
|
+
34,
|
|
238
|
+
62,
|
|
239
|
+
90,
|
|
240
|
+
118
|
|
241
|
+
],
|
|
242
|
+
[
|
|
243
|
+
6,
|
|
244
|
+
26,
|
|
245
|
+
50,
|
|
246
|
+
74,
|
|
247
|
+
98,
|
|
248
|
+
122
|
|
249
|
+
],
|
|
250
|
+
[
|
|
251
|
+
6,
|
|
252
|
+
30,
|
|
253
|
+
54,
|
|
254
|
+
78,
|
|
255
|
+
102,
|
|
256
|
+
126
|
|
257
|
+
],
|
|
258
|
+
[
|
|
259
|
+
6,
|
|
260
|
+
26,
|
|
261
|
+
52,
|
|
262
|
+
78,
|
|
263
|
+
104,
|
|
264
|
+
130
|
|
265
|
+
],
|
|
266
|
+
[
|
|
267
|
+
6,
|
|
268
|
+
30,
|
|
269
|
+
56,
|
|
270
|
+
82,
|
|
271
|
+
108,
|
|
272
|
+
134
|
|
273
|
+
],
|
|
274
|
+
[
|
|
275
|
+
6,
|
|
276
|
+
34,
|
|
277
|
+
60,
|
|
278
|
+
86,
|
|
279
|
+
112,
|
|
280
|
+
138
|
|
281
|
+
],
|
|
282
|
+
[
|
|
283
|
+
6,
|
|
284
|
+
30,
|
|
285
|
+
58,
|
|
286
|
+
86,
|
|
287
|
+
114,
|
|
288
|
+
142
|
|
289
|
+
],
|
|
290
|
+
[
|
|
291
|
+
6,
|
|
292
|
+
34,
|
|
293
|
+
62,
|
|
294
|
+
90,
|
|
295
|
+
118,
|
|
296
|
+
146
|
|
297
|
+
],
|
|
298
|
+
[
|
|
299
|
+
6,
|
|
300
|
+
30,
|
|
301
|
+
54,
|
|
302
|
+
78,
|
|
303
|
+
102,
|
|
304
|
+
126,
|
|
305
|
+
150
|
|
306
|
+
],
|
|
307
|
+
[
|
|
308
|
+
6,
|
|
309
|
+
24,
|
|
310
|
+
50,
|
|
311
|
+
76,
|
|
312
|
+
102,
|
|
313
|
+
128,
|
|
314
|
+
154
|
|
315
|
+
],
|
|
316
|
+
[
|
|
317
|
+
6,
|
|
318
|
+
28,
|
|
319
|
+
54,
|
|
320
|
+
80,
|
|
321
|
+
106,
|
|
322
|
+
132,
|
|
323
|
+
158
|
|
324
|
+
],
|
|
325
|
+
[
|
|
326
|
+
6,
|
|
327
|
+
32,
|
|
328
|
+
58,
|
|
329
|
+
84,
|
|
330
|
+
110,
|
|
331
|
+
136,
|
|
332
|
+
162
|
|
333
|
+
],
|
|
334
|
+
[
|
|
335
|
+
6,
|
|
336
|
+
26,
|
|
337
|
+
54,
|
|
338
|
+
82,
|
|
339
|
+
110,
|
|
340
|
+
138,
|
|
341
|
+
166
|
|
342
|
+
],
|
|
343
|
+
[
|
|
344
|
+
6,
|
|
345
|
+
30,
|
|
346
|
+
58,
|
|
347
|
+
86,
|
|
348
|
+
114,
|
|
349
|
+
142,
|
|
350
|
+
170
|
|
351
|
+
]
|
|
352
|
+
]);
|
|
353
|
+
_define_property(QRUtil, "G15", 1335);
|
|
354
|
+
_define_property(QRUtil, "G18", 7973);
|
|
355
|
+
_define_property(QRUtil, "G15_MASK", 21522);
|
|
356
|
+
class QRMath {
|
|
357
|
+
static glog(n) {
|
|
358
|
+
if (n < 1) throw new Error('glog(' + n + ')');
|
|
359
|
+
return this.LOG_TABLE[n];
|
|
360
|
+
}
|
|
361
|
+
static gexp(n) {
|
|
362
|
+
while(n < 0)n += 255;
|
|
363
|
+
while(n >= 256)n -= 255;
|
|
364
|
+
return this.EXP_TABLE[n];
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
_define_property(QRMath, "EXP_TABLE", new Array(256));
|
|
368
|
+
_define_property(QRMath, "LOG_TABLE", new Array(256));
|
|
369
|
+
(()=>{
|
|
370
|
+
for(let i = 0; i < 8; i += 1)QRMath.EXP_TABLE[i] = 1 << i;
|
|
371
|
+
for(let i = 8; i < 256; i += 1)QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] ^ QRMath.EXP_TABLE[i - 5] ^ QRMath.EXP_TABLE[i - 6] ^ QRMath.EXP_TABLE[i - 8];
|
|
372
|
+
for(let i = 0; i < 255; i += 1)QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i;
|
|
373
|
+
})();
|
|
374
|
+
class QRRSBlock {
|
|
375
|
+
static getRsBlockTable(typeNumber, errorCorrectLevel) {
|
|
376
|
+
switch(errorCorrectLevel){
|
|
377
|
+
case 1:
|
|
378
|
+
return this.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
|
|
379
|
+
case 0:
|
|
380
|
+
return this.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
|
|
381
|
+
case 3:
|
|
382
|
+
return this.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
|
|
383
|
+
case 2:
|
|
384
|
+
return this.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
|
|
385
|
+
default:
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
static getRSBlocks(typeNumber, errorCorrectLevel) {
|
|
390
|
+
const rsBlock = this.getRsBlockTable(typeNumber, errorCorrectLevel);
|
|
391
|
+
if (void 0 === rsBlock) throw new Error('bad rs block @ typeNumber:' + typeNumber + '/errorCorrectLevel:' + errorCorrectLevel);
|
|
392
|
+
const length = rsBlock.length / 3;
|
|
393
|
+
const list = [];
|
|
394
|
+
for(let i = 0; i < length; i += 1){
|
|
395
|
+
const count = rsBlock[3 * i + 0];
|
|
396
|
+
const totalCount = rsBlock[3 * i + 1];
|
|
397
|
+
const dataCount = rsBlock[3 * i + 2];
|
|
398
|
+
for(let j = 0; j < count; j += 1)list.push(new QRRSBlock(totalCount, dataCount));
|
|
399
|
+
}
|
|
400
|
+
return list;
|
|
401
|
+
}
|
|
402
|
+
constructor(totalCount, dataCount){
|
|
403
|
+
_define_property(this, "totalCount", void 0);
|
|
404
|
+
_define_property(this, "dataCount", void 0);
|
|
405
|
+
this.totalCount = totalCount;
|
|
406
|
+
this.dataCount = dataCount;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
_define_property(QRRSBlock, "RS_BLOCK_TABLE", [
|
|
410
|
+
[
|
|
411
|
+
1,
|
|
412
|
+
26,
|
|
413
|
+
19
|
|
414
|
+
],
|
|
415
|
+
[
|
|
416
|
+
1,
|
|
417
|
+
26,
|
|
418
|
+
16
|
|
419
|
+
],
|
|
420
|
+
[
|
|
421
|
+
1,
|
|
422
|
+
26,
|
|
423
|
+
13
|
|
424
|
+
],
|
|
425
|
+
[
|
|
426
|
+
1,
|
|
427
|
+
26,
|
|
428
|
+
9
|
|
429
|
+
],
|
|
430
|
+
[
|
|
431
|
+
1,
|
|
432
|
+
44,
|
|
433
|
+
34
|
|
434
|
+
],
|
|
435
|
+
[
|
|
436
|
+
1,
|
|
437
|
+
44,
|
|
438
|
+
28
|
|
439
|
+
],
|
|
440
|
+
[
|
|
441
|
+
1,
|
|
442
|
+
44,
|
|
443
|
+
22
|
|
444
|
+
],
|
|
445
|
+
[
|
|
446
|
+
1,
|
|
447
|
+
44,
|
|
448
|
+
16
|
|
449
|
+
],
|
|
450
|
+
[
|
|
451
|
+
1,
|
|
452
|
+
70,
|
|
453
|
+
55
|
|
454
|
+
],
|
|
455
|
+
[
|
|
456
|
+
1,
|
|
457
|
+
70,
|
|
458
|
+
44
|
|
459
|
+
],
|
|
460
|
+
[
|
|
461
|
+
2,
|
|
462
|
+
35,
|
|
463
|
+
17
|
|
464
|
+
],
|
|
465
|
+
[
|
|
466
|
+
2,
|
|
467
|
+
35,
|
|
468
|
+
13
|
|
469
|
+
],
|
|
470
|
+
[
|
|
471
|
+
1,
|
|
472
|
+
100,
|
|
473
|
+
80
|
|
474
|
+
],
|
|
475
|
+
[
|
|
476
|
+
2,
|
|
477
|
+
50,
|
|
478
|
+
32
|
|
479
|
+
],
|
|
480
|
+
[
|
|
481
|
+
2,
|
|
482
|
+
50,
|
|
483
|
+
24
|
|
484
|
+
],
|
|
485
|
+
[
|
|
486
|
+
4,
|
|
487
|
+
25,
|
|
488
|
+
9
|
|
489
|
+
],
|
|
490
|
+
[
|
|
491
|
+
1,
|
|
492
|
+
134,
|
|
493
|
+
108
|
|
494
|
+
],
|
|
495
|
+
[
|
|
496
|
+
2,
|
|
497
|
+
67,
|
|
498
|
+
43
|
|
499
|
+
],
|
|
500
|
+
[
|
|
501
|
+
2,
|
|
502
|
+
33,
|
|
503
|
+
15,
|
|
504
|
+
2,
|
|
505
|
+
34,
|
|
506
|
+
16
|
|
507
|
+
],
|
|
508
|
+
[
|
|
509
|
+
2,
|
|
510
|
+
33,
|
|
511
|
+
11,
|
|
512
|
+
2,
|
|
513
|
+
34,
|
|
514
|
+
12
|
|
515
|
+
],
|
|
516
|
+
[
|
|
517
|
+
2,
|
|
518
|
+
86,
|
|
519
|
+
68
|
|
520
|
+
],
|
|
521
|
+
[
|
|
522
|
+
4,
|
|
523
|
+
43,
|
|
524
|
+
27
|
|
525
|
+
],
|
|
526
|
+
[
|
|
527
|
+
4,
|
|
528
|
+
43,
|
|
529
|
+
19
|
|
530
|
+
],
|
|
531
|
+
[
|
|
532
|
+
4,
|
|
533
|
+
43,
|
|
534
|
+
15
|
|
535
|
+
],
|
|
536
|
+
[
|
|
537
|
+
2,
|
|
538
|
+
98,
|
|
539
|
+
78
|
|
540
|
+
],
|
|
541
|
+
[
|
|
542
|
+
4,
|
|
543
|
+
49,
|
|
544
|
+
31
|
|
545
|
+
],
|
|
546
|
+
[
|
|
547
|
+
2,
|
|
548
|
+
32,
|
|
549
|
+
14,
|
|
550
|
+
4,
|
|
551
|
+
33,
|
|
552
|
+
15
|
|
553
|
+
],
|
|
554
|
+
[
|
|
555
|
+
4,
|
|
556
|
+
39,
|
|
557
|
+
13,
|
|
558
|
+
1,
|
|
559
|
+
40,
|
|
560
|
+
14
|
|
561
|
+
],
|
|
562
|
+
[
|
|
563
|
+
2,
|
|
564
|
+
121,
|
|
565
|
+
97
|
|
566
|
+
],
|
|
567
|
+
[
|
|
568
|
+
2,
|
|
569
|
+
60,
|
|
570
|
+
38,
|
|
571
|
+
2,
|
|
572
|
+
61,
|
|
573
|
+
39
|
|
574
|
+
],
|
|
575
|
+
[
|
|
576
|
+
4,
|
|
577
|
+
40,
|
|
578
|
+
18,
|
|
579
|
+
2,
|
|
580
|
+
41,
|
|
581
|
+
19
|
|
582
|
+
],
|
|
583
|
+
[
|
|
584
|
+
4,
|
|
585
|
+
40,
|
|
586
|
+
14,
|
|
587
|
+
2,
|
|
588
|
+
41,
|
|
589
|
+
15
|
|
590
|
+
],
|
|
591
|
+
[
|
|
592
|
+
2,
|
|
593
|
+
146,
|
|
594
|
+
116
|
|
595
|
+
],
|
|
596
|
+
[
|
|
597
|
+
3,
|
|
598
|
+
58,
|
|
599
|
+
36,
|
|
600
|
+
2,
|
|
601
|
+
59,
|
|
602
|
+
37
|
|
603
|
+
],
|
|
604
|
+
[
|
|
605
|
+
4,
|
|
606
|
+
36,
|
|
607
|
+
16,
|
|
608
|
+
4,
|
|
609
|
+
37,
|
|
610
|
+
17
|
|
611
|
+
],
|
|
612
|
+
[
|
|
613
|
+
4,
|
|
614
|
+
36,
|
|
615
|
+
12,
|
|
616
|
+
4,
|
|
617
|
+
37,
|
|
618
|
+
13
|
|
619
|
+
],
|
|
620
|
+
[
|
|
621
|
+
2,
|
|
622
|
+
86,
|
|
623
|
+
68,
|
|
624
|
+
2,
|
|
625
|
+
87,
|
|
626
|
+
69
|
|
627
|
+
],
|
|
628
|
+
[
|
|
629
|
+
4,
|
|
630
|
+
69,
|
|
631
|
+
43,
|
|
632
|
+
1,
|
|
633
|
+
70,
|
|
634
|
+
44
|
|
635
|
+
],
|
|
636
|
+
[
|
|
637
|
+
6,
|
|
638
|
+
43,
|
|
639
|
+
19,
|
|
640
|
+
2,
|
|
641
|
+
44,
|
|
642
|
+
20
|
|
643
|
+
],
|
|
644
|
+
[
|
|
645
|
+
6,
|
|
646
|
+
43,
|
|
647
|
+
15,
|
|
648
|
+
2,
|
|
649
|
+
44,
|
|
650
|
+
16
|
|
651
|
+
],
|
|
652
|
+
[
|
|
653
|
+
4,
|
|
654
|
+
101,
|
|
655
|
+
81
|
|
656
|
+
],
|
|
657
|
+
[
|
|
658
|
+
1,
|
|
659
|
+
80,
|
|
660
|
+
50,
|
|
661
|
+
4,
|
|
662
|
+
81,
|
|
663
|
+
51
|
|
664
|
+
],
|
|
665
|
+
[
|
|
666
|
+
4,
|
|
667
|
+
50,
|
|
668
|
+
22,
|
|
669
|
+
4,
|
|
670
|
+
51,
|
|
671
|
+
23
|
|
672
|
+
],
|
|
673
|
+
[
|
|
674
|
+
3,
|
|
675
|
+
36,
|
|
676
|
+
12,
|
|
677
|
+
8,
|
|
678
|
+
37,
|
|
679
|
+
13
|
|
680
|
+
],
|
|
681
|
+
[
|
|
682
|
+
2,
|
|
683
|
+
116,
|
|
684
|
+
92,
|
|
685
|
+
2,
|
|
686
|
+
117,
|
|
687
|
+
93
|
|
688
|
+
],
|
|
689
|
+
[
|
|
690
|
+
6,
|
|
691
|
+
58,
|
|
692
|
+
36,
|
|
693
|
+
2,
|
|
694
|
+
59,
|
|
695
|
+
37
|
|
696
|
+
],
|
|
697
|
+
[
|
|
698
|
+
4,
|
|
699
|
+
46,
|
|
700
|
+
20,
|
|
701
|
+
6,
|
|
702
|
+
47,
|
|
703
|
+
21
|
|
704
|
+
],
|
|
705
|
+
[
|
|
706
|
+
7,
|
|
707
|
+
42,
|
|
708
|
+
14,
|
|
709
|
+
4,
|
|
710
|
+
43,
|
|
711
|
+
15
|
|
712
|
+
],
|
|
713
|
+
[
|
|
714
|
+
4,
|
|
715
|
+
133,
|
|
716
|
+
107
|
|
717
|
+
],
|
|
718
|
+
[
|
|
719
|
+
8,
|
|
720
|
+
59,
|
|
721
|
+
37,
|
|
722
|
+
1,
|
|
723
|
+
60,
|
|
724
|
+
38
|
|
725
|
+
],
|
|
726
|
+
[
|
|
727
|
+
8,
|
|
728
|
+
44,
|
|
729
|
+
20,
|
|
730
|
+
4,
|
|
731
|
+
45,
|
|
732
|
+
21
|
|
733
|
+
],
|
|
734
|
+
[
|
|
735
|
+
12,
|
|
736
|
+
33,
|
|
737
|
+
11,
|
|
738
|
+
4,
|
|
739
|
+
34,
|
|
740
|
+
12
|
|
741
|
+
],
|
|
742
|
+
[
|
|
743
|
+
3,
|
|
744
|
+
145,
|
|
745
|
+
115,
|
|
746
|
+
1,
|
|
747
|
+
146,
|
|
748
|
+
116
|
|
749
|
+
],
|
|
750
|
+
[
|
|
751
|
+
4,
|
|
752
|
+
64,
|
|
753
|
+
40,
|
|
754
|
+
5,
|
|
755
|
+
65,
|
|
756
|
+
41
|
|
757
|
+
],
|
|
758
|
+
[
|
|
759
|
+
11,
|
|
760
|
+
36,
|
|
761
|
+
16,
|
|
762
|
+
5,
|
|
763
|
+
37,
|
|
764
|
+
17
|
|
765
|
+
],
|
|
766
|
+
[
|
|
767
|
+
11,
|
|
768
|
+
36,
|
|
769
|
+
12,
|
|
770
|
+
5,
|
|
771
|
+
37,
|
|
772
|
+
13
|
|
773
|
+
],
|
|
774
|
+
[
|
|
775
|
+
5,
|
|
776
|
+
109,
|
|
777
|
+
87,
|
|
778
|
+
1,
|
|
779
|
+
110,
|
|
780
|
+
88
|
|
781
|
+
],
|
|
782
|
+
[
|
|
783
|
+
5,
|
|
784
|
+
65,
|
|
785
|
+
41,
|
|
786
|
+
5,
|
|
787
|
+
66,
|
|
788
|
+
42
|
|
789
|
+
],
|
|
790
|
+
[
|
|
791
|
+
5,
|
|
792
|
+
54,
|
|
793
|
+
24,
|
|
794
|
+
7,
|
|
795
|
+
55,
|
|
796
|
+
25
|
|
797
|
+
],
|
|
798
|
+
[
|
|
799
|
+
11,
|
|
800
|
+
36,
|
|
801
|
+
12,
|
|
802
|
+
7,
|
|
803
|
+
37,
|
|
804
|
+
13
|
|
805
|
+
],
|
|
806
|
+
[
|
|
807
|
+
5,
|
|
808
|
+
122,
|
|
809
|
+
98,
|
|
810
|
+
1,
|
|
811
|
+
123,
|
|
812
|
+
99
|
|
813
|
+
],
|
|
814
|
+
[
|
|
815
|
+
7,
|
|
816
|
+
73,
|
|
817
|
+
45,
|
|
818
|
+
3,
|
|
819
|
+
74,
|
|
820
|
+
46
|
|
821
|
+
],
|
|
822
|
+
[
|
|
823
|
+
15,
|
|
824
|
+
43,
|
|
825
|
+
19,
|
|
826
|
+
2,
|
|
827
|
+
44,
|
|
828
|
+
20
|
|
829
|
+
],
|
|
830
|
+
[
|
|
831
|
+
3,
|
|
832
|
+
45,
|
|
833
|
+
15,
|
|
834
|
+
13,
|
|
835
|
+
46,
|
|
836
|
+
16
|
|
837
|
+
],
|
|
838
|
+
[
|
|
839
|
+
1,
|
|
840
|
+
135,
|
|
841
|
+
107,
|
|
842
|
+
5,
|
|
843
|
+
136,
|
|
844
|
+
108
|
|
845
|
+
],
|
|
846
|
+
[
|
|
847
|
+
10,
|
|
848
|
+
74,
|
|
849
|
+
46,
|
|
850
|
+
1,
|
|
851
|
+
75,
|
|
852
|
+
47
|
|
853
|
+
],
|
|
854
|
+
[
|
|
855
|
+
1,
|
|
856
|
+
50,
|
|
857
|
+
22,
|
|
858
|
+
15,
|
|
859
|
+
51,
|
|
860
|
+
23
|
|
861
|
+
],
|
|
862
|
+
[
|
|
863
|
+
2,
|
|
864
|
+
42,
|
|
865
|
+
14,
|
|
866
|
+
17,
|
|
867
|
+
43,
|
|
868
|
+
15
|
|
869
|
+
],
|
|
870
|
+
[
|
|
871
|
+
5,
|
|
872
|
+
150,
|
|
873
|
+
120,
|
|
874
|
+
1,
|
|
875
|
+
151,
|
|
876
|
+
121
|
|
877
|
+
],
|
|
878
|
+
[
|
|
879
|
+
9,
|
|
880
|
+
69,
|
|
881
|
+
43,
|
|
882
|
+
4,
|
|
883
|
+
70,
|
|
884
|
+
44
|
|
885
|
+
],
|
|
886
|
+
[
|
|
887
|
+
17,
|
|
888
|
+
50,
|
|
889
|
+
22,
|
|
890
|
+
1,
|
|
891
|
+
51,
|
|
892
|
+
23
|
|
893
|
+
],
|
|
894
|
+
[
|
|
895
|
+
2,
|
|
896
|
+
42,
|
|
897
|
+
14,
|
|
898
|
+
19,
|
|
899
|
+
43,
|
|
900
|
+
15
|
|
901
|
+
],
|
|
902
|
+
[
|
|
903
|
+
3,
|
|
904
|
+
141,
|
|
905
|
+
113,
|
|
906
|
+
4,
|
|
907
|
+
142,
|
|
908
|
+
114
|
|
909
|
+
],
|
|
910
|
+
[
|
|
911
|
+
3,
|
|
912
|
+
70,
|
|
913
|
+
44,
|
|
914
|
+
11,
|
|
915
|
+
71,
|
|
916
|
+
45
|
|
917
|
+
],
|
|
918
|
+
[
|
|
919
|
+
17,
|
|
920
|
+
47,
|
|
921
|
+
21,
|
|
922
|
+
4,
|
|
923
|
+
48,
|
|
924
|
+
22
|
|
925
|
+
],
|
|
926
|
+
[
|
|
927
|
+
9,
|
|
928
|
+
39,
|
|
929
|
+
13,
|
|
930
|
+
16,
|
|
931
|
+
40,
|
|
932
|
+
14
|
|
933
|
+
],
|
|
934
|
+
[
|
|
935
|
+
3,
|
|
936
|
+
135,
|
|
937
|
+
107,
|
|
938
|
+
5,
|
|
939
|
+
136,
|
|
940
|
+
108
|
|
941
|
+
],
|
|
942
|
+
[
|
|
943
|
+
3,
|
|
944
|
+
67,
|
|
945
|
+
41,
|
|
946
|
+
13,
|
|
947
|
+
68,
|
|
948
|
+
42
|
|
949
|
+
],
|
|
950
|
+
[
|
|
951
|
+
15,
|
|
952
|
+
54,
|
|
953
|
+
24,
|
|
954
|
+
5,
|
|
955
|
+
55,
|
|
956
|
+
25
|
|
957
|
+
],
|
|
958
|
+
[
|
|
959
|
+
15,
|
|
960
|
+
43,
|
|
961
|
+
15,
|
|
962
|
+
10,
|
|
963
|
+
44,
|
|
964
|
+
16
|
|
965
|
+
],
|
|
966
|
+
[
|
|
967
|
+
4,
|
|
968
|
+
144,
|
|
969
|
+
116,
|
|
970
|
+
4,
|
|
971
|
+
145,
|
|
972
|
+
117
|
|
973
|
+
],
|
|
974
|
+
[
|
|
975
|
+
17,
|
|
976
|
+
68,
|
|
977
|
+
42
|
|
978
|
+
],
|
|
979
|
+
[
|
|
980
|
+
17,
|
|
981
|
+
50,
|
|
982
|
+
22,
|
|
983
|
+
6,
|
|
984
|
+
51,
|
|
985
|
+
23
|
|
986
|
+
],
|
|
987
|
+
[
|
|
988
|
+
19,
|
|
989
|
+
46,
|
|
990
|
+
16,
|
|
991
|
+
6,
|
|
992
|
+
47,
|
|
993
|
+
17
|
|
994
|
+
],
|
|
995
|
+
[
|
|
996
|
+
2,
|
|
997
|
+
139,
|
|
998
|
+
111,
|
|
999
|
+
7,
|
|
1000
|
+
140,
|
|
1001
|
+
112
|
|
1002
|
+
],
|
|
1003
|
+
[
|
|
1004
|
+
17,
|
|
1005
|
+
74,
|
|
1006
|
+
46
|
|
1007
|
+
],
|
|
1008
|
+
[
|
|
1009
|
+
7,
|
|
1010
|
+
54,
|
|
1011
|
+
24,
|
|
1012
|
+
16,
|
|
1013
|
+
55,
|
|
1014
|
+
25
|
|
1015
|
+
],
|
|
1016
|
+
[
|
|
1017
|
+
34,
|
|
1018
|
+
37,
|
|
1019
|
+
13
|
|
1020
|
+
],
|
|
1021
|
+
[
|
|
1022
|
+
4,
|
|
1023
|
+
151,
|
|
1024
|
+
121,
|
|
1025
|
+
5,
|
|
1026
|
+
152,
|
|
1027
|
+
122
|
|
1028
|
+
],
|
|
1029
|
+
[
|
|
1030
|
+
4,
|
|
1031
|
+
75,
|
|
1032
|
+
47,
|
|
1033
|
+
14,
|
|
1034
|
+
76,
|
|
1035
|
+
48
|
|
1036
|
+
],
|
|
1037
|
+
[
|
|
1038
|
+
11,
|
|
1039
|
+
54,
|
|
1040
|
+
24,
|
|
1041
|
+
14,
|
|
1042
|
+
55,
|
|
1043
|
+
25
|
|
1044
|
+
],
|
|
1045
|
+
[
|
|
1046
|
+
16,
|
|
1047
|
+
45,
|
|
1048
|
+
15,
|
|
1049
|
+
14,
|
|
1050
|
+
46,
|
|
1051
|
+
16
|
|
1052
|
+
],
|
|
1053
|
+
[
|
|
1054
|
+
6,
|
|
1055
|
+
147,
|
|
1056
|
+
117,
|
|
1057
|
+
4,
|
|
1058
|
+
148,
|
|
1059
|
+
118
|
|
1060
|
+
],
|
|
1061
|
+
[
|
|
1062
|
+
6,
|
|
1063
|
+
73,
|
|
1064
|
+
45,
|
|
1065
|
+
14,
|
|
1066
|
+
74,
|
|
1067
|
+
46
|
|
1068
|
+
],
|
|
1069
|
+
[
|
|
1070
|
+
11,
|
|
1071
|
+
54,
|
|
1072
|
+
24,
|
|
1073
|
+
16,
|
|
1074
|
+
55,
|
|
1075
|
+
25
|
|
1076
|
+
],
|
|
1077
|
+
[
|
|
1078
|
+
30,
|
|
1079
|
+
46,
|
|
1080
|
+
16,
|
|
1081
|
+
2,
|
|
1082
|
+
47,
|
|
1083
|
+
17
|
|
1084
|
+
],
|
|
1085
|
+
[
|
|
1086
|
+
8,
|
|
1087
|
+
132,
|
|
1088
|
+
106,
|
|
1089
|
+
4,
|
|
1090
|
+
133,
|
|
1091
|
+
107
|
|
1092
|
+
],
|
|
1093
|
+
[
|
|
1094
|
+
8,
|
|
1095
|
+
75,
|
|
1096
|
+
47,
|
|
1097
|
+
13,
|
|
1098
|
+
76,
|
|
1099
|
+
48
|
|
1100
|
+
],
|
|
1101
|
+
[
|
|
1102
|
+
7,
|
|
1103
|
+
54,
|
|
1104
|
+
24,
|
|
1105
|
+
22,
|
|
1106
|
+
55,
|
|
1107
|
+
25
|
|
1108
|
+
],
|
|
1109
|
+
[
|
|
1110
|
+
22,
|
|
1111
|
+
45,
|
|
1112
|
+
15,
|
|
1113
|
+
13,
|
|
1114
|
+
46,
|
|
1115
|
+
16
|
|
1116
|
+
],
|
|
1117
|
+
[
|
|
1118
|
+
10,
|
|
1119
|
+
142,
|
|
1120
|
+
114,
|
|
1121
|
+
2,
|
|
1122
|
+
143,
|
|
1123
|
+
115
|
|
1124
|
+
],
|
|
1125
|
+
[
|
|
1126
|
+
19,
|
|
1127
|
+
74,
|
|
1128
|
+
46,
|
|
1129
|
+
4,
|
|
1130
|
+
75,
|
|
1131
|
+
47
|
|
1132
|
+
],
|
|
1133
|
+
[
|
|
1134
|
+
28,
|
|
1135
|
+
50,
|
|
1136
|
+
22,
|
|
1137
|
+
6,
|
|
1138
|
+
51,
|
|
1139
|
+
23
|
|
1140
|
+
],
|
|
1141
|
+
[
|
|
1142
|
+
33,
|
|
1143
|
+
46,
|
|
1144
|
+
16,
|
|
1145
|
+
4,
|
|
1146
|
+
47,
|
|
1147
|
+
17
|
|
1148
|
+
],
|
|
1149
|
+
[
|
|
1150
|
+
8,
|
|
1151
|
+
152,
|
|
1152
|
+
122,
|
|
1153
|
+
4,
|
|
1154
|
+
153,
|
|
1155
|
+
123
|
|
1156
|
+
],
|
|
1157
|
+
[
|
|
1158
|
+
22,
|
|
1159
|
+
73,
|
|
1160
|
+
45,
|
|
1161
|
+
3,
|
|
1162
|
+
74,
|
|
1163
|
+
46
|
|
1164
|
+
],
|
|
1165
|
+
[
|
|
1166
|
+
8,
|
|
1167
|
+
53,
|
|
1168
|
+
23,
|
|
1169
|
+
26,
|
|
1170
|
+
54,
|
|
1171
|
+
24
|
|
1172
|
+
],
|
|
1173
|
+
[
|
|
1174
|
+
12,
|
|
1175
|
+
45,
|
|
1176
|
+
15,
|
|
1177
|
+
28,
|
|
1178
|
+
46,
|
|
1179
|
+
16
|
|
1180
|
+
],
|
|
1181
|
+
[
|
|
1182
|
+
3,
|
|
1183
|
+
147,
|
|
1184
|
+
117,
|
|
1185
|
+
10,
|
|
1186
|
+
148,
|
|
1187
|
+
118
|
|
1188
|
+
],
|
|
1189
|
+
[
|
|
1190
|
+
3,
|
|
1191
|
+
73,
|
|
1192
|
+
45,
|
|
1193
|
+
23,
|
|
1194
|
+
74,
|
|
1195
|
+
46
|
|
1196
|
+
],
|
|
1197
|
+
[
|
|
1198
|
+
4,
|
|
1199
|
+
54,
|
|
1200
|
+
24,
|
|
1201
|
+
31,
|
|
1202
|
+
55,
|
|
1203
|
+
25
|
|
1204
|
+
],
|
|
1205
|
+
[
|
|
1206
|
+
11,
|
|
1207
|
+
45,
|
|
1208
|
+
15,
|
|
1209
|
+
31,
|
|
1210
|
+
46,
|
|
1211
|
+
16
|
|
1212
|
+
],
|
|
1213
|
+
[
|
|
1214
|
+
7,
|
|
1215
|
+
146,
|
|
1216
|
+
116,
|
|
1217
|
+
7,
|
|
1218
|
+
147,
|
|
1219
|
+
117
|
|
1220
|
+
],
|
|
1221
|
+
[
|
|
1222
|
+
21,
|
|
1223
|
+
73,
|
|
1224
|
+
45,
|
|
1225
|
+
7,
|
|
1226
|
+
74,
|
|
1227
|
+
46
|
|
1228
|
+
],
|
|
1229
|
+
[
|
|
1230
|
+
1,
|
|
1231
|
+
53,
|
|
1232
|
+
23,
|
|
1233
|
+
37,
|
|
1234
|
+
54,
|
|
1235
|
+
24
|
|
1236
|
+
],
|
|
1237
|
+
[
|
|
1238
|
+
19,
|
|
1239
|
+
45,
|
|
1240
|
+
15,
|
|
1241
|
+
26,
|
|
1242
|
+
46,
|
|
1243
|
+
16
|
|
1244
|
+
],
|
|
1245
|
+
[
|
|
1246
|
+
5,
|
|
1247
|
+
145,
|
|
1248
|
+
115,
|
|
1249
|
+
10,
|
|
1250
|
+
146,
|
|
1251
|
+
116
|
|
1252
|
+
],
|
|
1253
|
+
[
|
|
1254
|
+
19,
|
|
1255
|
+
75,
|
|
1256
|
+
47,
|
|
1257
|
+
10,
|
|
1258
|
+
76,
|
|
1259
|
+
48
|
|
1260
|
+
],
|
|
1261
|
+
[
|
|
1262
|
+
15,
|
|
1263
|
+
54,
|
|
1264
|
+
24,
|
|
1265
|
+
25,
|
|
1266
|
+
55,
|
|
1267
|
+
25
|
|
1268
|
+
],
|
|
1269
|
+
[
|
|
1270
|
+
23,
|
|
1271
|
+
45,
|
|
1272
|
+
15,
|
|
1273
|
+
25,
|
|
1274
|
+
46,
|
|
1275
|
+
16
|
|
1276
|
+
],
|
|
1277
|
+
[
|
|
1278
|
+
13,
|
|
1279
|
+
145,
|
|
1280
|
+
115,
|
|
1281
|
+
3,
|
|
1282
|
+
146,
|
|
1283
|
+
116
|
|
1284
|
+
],
|
|
1285
|
+
[
|
|
1286
|
+
2,
|
|
1287
|
+
74,
|
|
1288
|
+
46,
|
|
1289
|
+
29,
|
|
1290
|
+
75,
|
|
1291
|
+
47
|
|
1292
|
+
],
|
|
1293
|
+
[
|
|
1294
|
+
42,
|
|
1295
|
+
54,
|
|
1296
|
+
24,
|
|
1297
|
+
1,
|
|
1298
|
+
55,
|
|
1299
|
+
25
|
|
1300
|
+
],
|
|
1301
|
+
[
|
|
1302
|
+
23,
|
|
1303
|
+
45,
|
|
1304
|
+
15,
|
|
1305
|
+
28,
|
|
1306
|
+
46,
|
|
1307
|
+
16
|
|
1308
|
+
],
|
|
1309
|
+
[
|
|
1310
|
+
17,
|
|
1311
|
+
145,
|
|
1312
|
+
115
|
|
1313
|
+
],
|
|
1314
|
+
[
|
|
1315
|
+
10,
|
|
1316
|
+
74,
|
|
1317
|
+
46,
|
|
1318
|
+
23,
|
|
1319
|
+
75,
|
|
1320
|
+
47
|
|
1321
|
+
],
|
|
1322
|
+
[
|
|
1323
|
+
10,
|
|
1324
|
+
54,
|
|
1325
|
+
24,
|
|
1326
|
+
35,
|
|
1327
|
+
55,
|
|
1328
|
+
25
|
|
1329
|
+
],
|
|
1330
|
+
[
|
|
1331
|
+
19,
|
|
1332
|
+
45,
|
|
1333
|
+
15,
|
|
1334
|
+
35,
|
|
1335
|
+
46,
|
|
1336
|
+
16
|
|
1337
|
+
],
|
|
1338
|
+
[
|
|
1339
|
+
17,
|
|
1340
|
+
145,
|
|
1341
|
+
115,
|
|
1342
|
+
1,
|
|
1343
|
+
146,
|
|
1344
|
+
116
|
|
1345
|
+
],
|
|
1346
|
+
[
|
|
1347
|
+
14,
|
|
1348
|
+
74,
|
|
1349
|
+
46,
|
|
1350
|
+
21,
|
|
1351
|
+
75,
|
|
1352
|
+
47
|
|
1353
|
+
],
|
|
1354
|
+
[
|
|
1355
|
+
29,
|
|
1356
|
+
54,
|
|
1357
|
+
24,
|
|
1358
|
+
19,
|
|
1359
|
+
55,
|
|
1360
|
+
25
|
|
1361
|
+
],
|
|
1362
|
+
[
|
|
1363
|
+
11,
|
|
1364
|
+
45,
|
|
1365
|
+
15,
|
|
1366
|
+
46,
|
|
1367
|
+
46,
|
|
1368
|
+
16
|
|
1369
|
+
],
|
|
1370
|
+
[
|
|
1371
|
+
13,
|
|
1372
|
+
145,
|
|
1373
|
+
115,
|
|
1374
|
+
6,
|
|
1375
|
+
146,
|
|
1376
|
+
116
|
|
1377
|
+
],
|
|
1378
|
+
[
|
|
1379
|
+
14,
|
|
1380
|
+
74,
|
|
1381
|
+
46,
|
|
1382
|
+
23,
|
|
1383
|
+
75,
|
|
1384
|
+
47
|
|
1385
|
+
],
|
|
1386
|
+
[
|
|
1387
|
+
44,
|
|
1388
|
+
54,
|
|
1389
|
+
24,
|
|
1390
|
+
7,
|
|
1391
|
+
55,
|
|
1392
|
+
25
|
|
1393
|
+
],
|
|
1394
|
+
[
|
|
1395
|
+
59,
|
|
1396
|
+
46,
|
|
1397
|
+
16,
|
|
1398
|
+
1,
|
|
1399
|
+
47,
|
|
1400
|
+
17
|
|
1401
|
+
],
|
|
1402
|
+
[
|
|
1403
|
+
12,
|
|
1404
|
+
151,
|
|
1405
|
+
121,
|
|
1406
|
+
7,
|
|
1407
|
+
152,
|
|
1408
|
+
122
|
|
1409
|
+
],
|
|
1410
|
+
[
|
|
1411
|
+
12,
|
|
1412
|
+
75,
|
|
1413
|
+
47,
|
|
1414
|
+
26,
|
|
1415
|
+
76,
|
|
1416
|
+
48
|
|
1417
|
+
],
|
|
1418
|
+
[
|
|
1419
|
+
39,
|
|
1420
|
+
54,
|
|
1421
|
+
24,
|
|
1422
|
+
14,
|
|
1423
|
+
55,
|
|
1424
|
+
25
|
|
1425
|
+
],
|
|
1426
|
+
[
|
|
1427
|
+
22,
|
|
1428
|
+
45,
|
|
1429
|
+
15,
|
|
1430
|
+
41,
|
|
1431
|
+
46,
|
|
1432
|
+
16
|
|
1433
|
+
],
|
|
1434
|
+
[
|
|
1435
|
+
6,
|
|
1436
|
+
151,
|
|
1437
|
+
121,
|
|
1438
|
+
14,
|
|
1439
|
+
152,
|
|
1440
|
+
122
|
|
1441
|
+
],
|
|
1442
|
+
[
|
|
1443
|
+
6,
|
|
1444
|
+
75,
|
|
1445
|
+
47,
|
|
1446
|
+
34,
|
|
1447
|
+
76,
|
|
1448
|
+
48
|
|
1449
|
+
],
|
|
1450
|
+
[
|
|
1451
|
+
46,
|
|
1452
|
+
54,
|
|
1453
|
+
24,
|
|
1454
|
+
10,
|
|
1455
|
+
55,
|
|
1456
|
+
25
|
|
1457
|
+
],
|
|
1458
|
+
[
|
|
1459
|
+
2,
|
|
1460
|
+
45,
|
|
1461
|
+
15,
|
|
1462
|
+
64,
|
|
1463
|
+
46,
|
|
1464
|
+
16
|
|
1465
|
+
],
|
|
1466
|
+
[
|
|
1467
|
+
17,
|
|
1468
|
+
152,
|
|
1469
|
+
122,
|
|
1470
|
+
4,
|
|
1471
|
+
153,
|
|
1472
|
+
123
|
|
1473
|
+
],
|
|
1474
|
+
[
|
|
1475
|
+
29,
|
|
1476
|
+
74,
|
|
1477
|
+
46,
|
|
1478
|
+
14,
|
|
1479
|
+
75,
|
|
1480
|
+
47
|
|
1481
|
+
],
|
|
1482
|
+
[
|
|
1483
|
+
49,
|
|
1484
|
+
54,
|
|
1485
|
+
24,
|
|
1486
|
+
10,
|
|
1487
|
+
55,
|
|
1488
|
+
25
|
|
1489
|
+
],
|
|
1490
|
+
[
|
|
1491
|
+
24,
|
|
1492
|
+
45,
|
|
1493
|
+
15,
|
|
1494
|
+
46,
|
|
1495
|
+
46,
|
|
1496
|
+
16
|
|
1497
|
+
],
|
|
1498
|
+
[
|
|
1499
|
+
4,
|
|
1500
|
+
152,
|
|
1501
|
+
122,
|
|
1502
|
+
18,
|
|
1503
|
+
153,
|
|
1504
|
+
123
|
|
1505
|
+
],
|
|
1506
|
+
[
|
|
1507
|
+
13,
|
|
1508
|
+
74,
|
|
1509
|
+
46,
|
|
1510
|
+
32,
|
|
1511
|
+
75,
|
|
1512
|
+
47
|
|
1513
|
+
],
|
|
1514
|
+
[
|
|
1515
|
+
48,
|
|
1516
|
+
54,
|
|
1517
|
+
24,
|
|
1518
|
+
14,
|
|
1519
|
+
55,
|
|
1520
|
+
25
|
|
1521
|
+
],
|
|
1522
|
+
[
|
|
1523
|
+
42,
|
|
1524
|
+
45,
|
|
1525
|
+
15,
|
|
1526
|
+
32,
|
|
1527
|
+
46,
|
|
1528
|
+
16
|
|
1529
|
+
],
|
|
1530
|
+
[
|
|
1531
|
+
20,
|
|
1532
|
+
147,
|
|
1533
|
+
117,
|
|
1534
|
+
4,
|
|
1535
|
+
148,
|
|
1536
|
+
118
|
|
1537
|
+
],
|
|
1538
|
+
[
|
|
1539
|
+
40,
|
|
1540
|
+
75,
|
|
1541
|
+
47,
|
|
1542
|
+
7,
|
|
1543
|
+
76,
|
|
1544
|
+
48
|
|
1545
|
+
],
|
|
1546
|
+
[
|
|
1547
|
+
43,
|
|
1548
|
+
54,
|
|
1549
|
+
24,
|
|
1550
|
+
22,
|
|
1551
|
+
55,
|
|
1552
|
+
25
|
|
1553
|
+
],
|
|
1554
|
+
[
|
|
1555
|
+
10,
|
|
1556
|
+
45,
|
|
1557
|
+
15,
|
|
1558
|
+
67,
|
|
1559
|
+
46,
|
|
1560
|
+
16
|
|
1561
|
+
],
|
|
1562
|
+
[
|
|
1563
|
+
19,
|
|
1564
|
+
148,
|
|
1565
|
+
118,
|
|
1566
|
+
6,
|
|
1567
|
+
149,
|
|
1568
|
+
119
|
|
1569
|
+
],
|
|
1570
|
+
[
|
|
1571
|
+
18,
|
|
1572
|
+
75,
|
|
1573
|
+
47,
|
|
1574
|
+
31,
|
|
1575
|
+
76,
|
|
1576
|
+
48
|
|
1577
|
+
],
|
|
1578
|
+
[
|
|
1579
|
+
34,
|
|
1580
|
+
54,
|
|
1581
|
+
24,
|
|
1582
|
+
34,
|
|
1583
|
+
55,
|
|
1584
|
+
25
|
|
1585
|
+
],
|
|
1586
|
+
[
|
|
1587
|
+
20,
|
|
1588
|
+
45,
|
|
1589
|
+
15,
|
|
1590
|
+
61,
|
|
1591
|
+
46,
|
|
1592
|
+
16
|
|
1593
|
+
]
|
|
1594
|
+
]);
|
|
1595
|
+
function qr_generator_define_property(obj, key, value) {
|
|
1596
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
1597
|
+
value: value,
|
|
1598
|
+
enumerable: true,
|
|
1599
|
+
configurable: true,
|
|
1600
|
+
writable: true
|
|
1601
|
+
});
|
|
1602
|
+
else obj[key] = value;
|
|
1603
|
+
return obj;
|
|
1604
|
+
}
|
|
1605
|
+
class QRCodeGenerator {
|
|
1606
|
+
addData(data) {
|
|
1607
|
+
const newData = new QR8BitByte(data);
|
|
1608
|
+
this.dataList.push(newData);
|
|
1609
|
+
this.dataCache = null;
|
|
1610
|
+
}
|
|
1611
|
+
isDark(row, col) {
|
|
1612
|
+
if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) throw new Error(`${row},${col}`);
|
|
1613
|
+
return this.modules[row][col];
|
|
1614
|
+
}
|
|
1615
|
+
getModuleCount() {
|
|
1616
|
+
return this.moduleCount;
|
|
1617
|
+
}
|
|
1618
|
+
make() {
|
|
1619
|
+
this.makeImpl(false, this.getBestMaskPattern());
|
|
1620
|
+
}
|
|
1621
|
+
makeImpl(test, maskPattern) {
|
|
1622
|
+
this.moduleCount = 4 * this.typeNumber + 17;
|
|
1623
|
+
this.modules = this.createModules(this.moduleCount);
|
|
1624
|
+
this.setupPositionProbePattern(0, 0);
|
|
1625
|
+
this.setupPositionProbePattern(this.moduleCount - 7, 0);
|
|
1626
|
+
this.setupPositionProbePattern(0, this.moduleCount - 7);
|
|
1627
|
+
this.setupPositionAdjustPattern();
|
|
1628
|
+
this.setupTimingPattern();
|
|
1629
|
+
this.setupTypeInfo(test, maskPattern);
|
|
1630
|
+
if (this.typeNumber >= 7) this.setupTypeNumber(test);
|
|
1631
|
+
if (null == this.dataCache) this.dataCache = this.createData(this.typeNumber, this.errorCorrectLevel, this.dataList);
|
|
1632
|
+
this.mapData(this.dataCache, maskPattern);
|
|
1633
|
+
}
|
|
1634
|
+
createModules(moduleCount) {
|
|
1635
|
+
const modules = new Array(moduleCount);
|
|
1636
|
+
for(let row = 0; row < moduleCount; row += 1){
|
|
1637
|
+
modules[row] = new Array(moduleCount);
|
|
1638
|
+
for(let col = 0; col < moduleCount; col += 1)modules[row][col] = null;
|
|
1639
|
+
}
|
|
1640
|
+
return modules;
|
|
1641
|
+
}
|
|
1642
|
+
setupPositionProbePattern(row, col) {
|
|
1643
|
+
for(let r = -1; r <= 7; r += 1)if (!(row + r <= -1) && !(this.moduleCount <= row + r)) {
|
|
1644
|
+
for(let c = -1; c <= 7; c += 1)if (!(col + c <= -1) && !(this.moduleCount <= col + c)) if (0 <= r && r <= 6 && (0 == c || 6 == c) || 0 <= c && c <= 6 && (0 == r || 6 == r) || 2 <= r && r <= 4 && 2 <= c && c <= 4) this.modules[row + r][col + c] = true;
|
|
1645
|
+
else this.modules[row + r][col + c] = false;
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
getBestMaskPattern() {
|
|
1649
|
+
let minLostPoint = 0;
|
|
1650
|
+
let pattern = 0;
|
|
1651
|
+
for(let i = 0; i < 8; i += 1){
|
|
1652
|
+
this.makeImpl(true, i);
|
|
1653
|
+
const lostPoint = QRUtil.getLostPoint(this);
|
|
1654
|
+
if (0 == i || minLostPoint > lostPoint) {
|
|
1655
|
+
minLostPoint = lostPoint;
|
|
1656
|
+
pattern = i;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
return pattern;
|
|
1660
|
+
}
|
|
1661
|
+
setupTimingPattern() {
|
|
1662
|
+
for(let r = 8; r < this.moduleCount - 8; r += 1)if (null == this.modules[r][6]) this.modules[r][6] = r % 2 == 0;
|
|
1663
|
+
for(let c = 8; c < this.moduleCount - 8; c += 1)if (null == this.modules[6][c]) this.modules[6][c] = c % 2 == 0;
|
|
1664
|
+
}
|
|
1665
|
+
setupPositionAdjustPattern() {
|
|
1666
|
+
const pos = QRUtil.getPatternPosition(this.typeNumber);
|
|
1667
|
+
for(let i = 0; i < pos.length; i += 1)for(let j = 0; j < pos.length; j += 1){
|
|
1668
|
+
const row = pos[i];
|
|
1669
|
+
const col = pos[j];
|
|
1670
|
+
if (null == this.modules[row][col]) for(let r = -2; r <= 2; r += 1)for(let c = -2; c <= 2; c += 1)this.modules[row + r][col + c] = -2 == r || 2 == r || -2 == c || 2 == c || 0 == r && 0 == c;
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
setupTypeNumber(test) {
|
|
1674
|
+
const bits = QRUtil.getBCHTypeNumber(this.typeNumber);
|
|
1675
|
+
for(let i = 0; i < 18; i += 1){
|
|
1676
|
+
const mod = !test && (bits >> i & 1) == 1;
|
|
1677
|
+
this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod;
|
|
1678
|
+
}
|
|
1679
|
+
for(let i = 0; i < 18; i += 1){
|
|
1680
|
+
const mod = !test && (bits >> i & 1) == 1;
|
|
1681
|
+
this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
setupTypeInfo(test, maskPattern) {
|
|
1685
|
+
const data = this.errorCorrectLevel << 3 | maskPattern;
|
|
1686
|
+
const bits = QRUtil.getBCHTypeInfo(data);
|
|
1687
|
+
for(let i = 0; i < 15; i += 1){
|
|
1688
|
+
const mod = !test && (bits >> i & 1) == 1;
|
|
1689
|
+
this.modules[i < 6 ? i : i < 8 ? i + 1 : this.moduleCount - 15 + i][8] = mod;
|
|
1690
|
+
this.modules[8][i < 8 ? this.moduleCount - i - 1 : i < 9 ? 15 - i : 14 - i] = mod;
|
|
1691
|
+
}
|
|
1692
|
+
this.modules[this.moduleCount - 8][8] = !test;
|
|
1693
|
+
}
|
|
1694
|
+
mapData(data, maskPattern) {
|
|
1695
|
+
let inc = -1;
|
|
1696
|
+
let row = this.moduleCount - 1;
|
|
1697
|
+
let bitIndex = 7;
|
|
1698
|
+
let byteIndex = 0;
|
|
1699
|
+
const maskFunc = QRUtil.getMaskFunction(maskPattern);
|
|
1700
|
+
for(let col = this.moduleCount - 1; col > 0; col -= 2){
|
|
1701
|
+
if (6 == col) col -= 1;
|
|
1702
|
+
while(true){
|
|
1703
|
+
for(let c = 0; c < 2; c += 1)if (null == this.modules[row][col - c]) {
|
|
1704
|
+
let dark = false;
|
|
1705
|
+
if (byteIndex < data.length) dark = (data[byteIndex] >>> bitIndex & 1) == 1;
|
|
1706
|
+
const mask = maskFunc(row, col - c);
|
|
1707
|
+
if (mask) dark = !dark;
|
|
1708
|
+
this.modules[row][col - c] = dark;
|
|
1709
|
+
bitIndex -= 1;
|
|
1710
|
+
if (-1 == bitIndex) {
|
|
1711
|
+
byteIndex += 1;
|
|
1712
|
+
bitIndex = 7;
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
row += inc;
|
|
1716
|
+
if (row < 0 || this.moduleCount <= row) {
|
|
1717
|
+
row -= inc;
|
|
1718
|
+
inc = -inc;
|
|
1719
|
+
break;
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
createBytes(buffer, rsBlocks) {
|
|
1725
|
+
let offset = 0;
|
|
1726
|
+
let maxDcCount = 0;
|
|
1727
|
+
let maxEcCount = 0;
|
|
1728
|
+
const dcdata = new Array(rsBlocks.length);
|
|
1729
|
+
const ecdata = new Array(rsBlocks.length);
|
|
1730
|
+
for(let r = 0; r < rsBlocks.length; r += 1){
|
|
1731
|
+
const dcCount = rsBlocks[r].dataCount;
|
|
1732
|
+
const ecCount = rsBlocks[r].totalCount - dcCount;
|
|
1733
|
+
maxDcCount = Math.max(maxDcCount, dcCount);
|
|
1734
|
+
maxEcCount = Math.max(maxEcCount, ecCount);
|
|
1735
|
+
dcdata[r] = new Array(dcCount);
|
|
1736
|
+
for(let i = 0; i < dcdata[r].length; i += 1)dcdata[r][i] = 0xff & buffer.getBuffer()[i + offset];
|
|
1737
|
+
offset += dcCount;
|
|
1738
|
+
const rsPoly = this.getErrorCorrectPolynomial(ecCount);
|
|
1739
|
+
const rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1);
|
|
1740
|
+
const modPoly = rawPoly.mod(rsPoly);
|
|
1741
|
+
ecdata[r] = new Array(rsPoly.getLength() - 1);
|
|
1742
|
+
for(let i = 0; i < ecdata[r].length; i += 1){
|
|
1743
|
+
const modIndex = i + modPoly.getLength() - ecdata[r].length;
|
|
1744
|
+
ecdata[r][i] = modIndex >= 0 ? modPoly.getAt(modIndex) : 0;
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
let totalCodeCount = 0;
|
|
1748
|
+
for(let i = 0; i < rsBlocks.length; i += 1)totalCodeCount += rsBlocks[i].totalCount;
|
|
1749
|
+
const data = new Array(totalCodeCount);
|
|
1750
|
+
let index = 0;
|
|
1751
|
+
for(let i = 0; i < maxDcCount; i += 1)for(let r = 0; r < rsBlocks.length; r += 1)if (i < dcdata[r].length) {
|
|
1752
|
+
data[index] = dcdata[r][i];
|
|
1753
|
+
index += 1;
|
|
1754
|
+
}
|
|
1755
|
+
for(let i = 0; i < maxEcCount; i += 1)for(let r = 0; r < rsBlocks.length; r += 1)if (i < ecdata[r].length) {
|
|
1756
|
+
data[index] = ecdata[r][i];
|
|
1757
|
+
index += 1;
|
|
1758
|
+
}
|
|
1759
|
+
return data;
|
|
1760
|
+
}
|
|
1761
|
+
getErrorCorrectPolynomial(errorCorrectLength) {
|
|
1762
|
+
let a = new QRPolynomial([
|
|
1763
|
+
1
|
|
1764
|
+
], 0);
|
|
1765
|
+
for(let i = 0; i < errorCorrectLength; i += 1)a = a.multiply(new QRPolynomial([
|
|
1766
|
+
1,
|
|
1767
|
+
QRMath.gexp(i)
|
|
1768
|
+
], 0));
|
|
1769
|
+
return a;
|
|
1770
|
+
}
|
|
1771
|
+
createData(typeNumber, errorCorrectLevel, dataList) {
|
|
1772
|
+
const rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel);
|
|
1773
|
+
const buffer = new QRBitBuffer();
|
|
1774
|
+
for(let i = 0; i < dataList.length; i += 1){
|
|
1775
|
+
const data = dataList[i];
|
|
1776
|
+
buffer.put(data.getMode(), 4);
|
|
1777
|
+
buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber));
|
|
1778
|
+
data.write(buffer);
|
|
1779
|
+
}
|
|
1780
|
+
let totalDataCount = 0;
|
|
1781
|
+
for(let i = 0; i < rsBlocks.length; i += 1)totalDataCount += rsBlocks[i].dataCount;
|
|
1782
|
+
if (buffer.getLengthInBits() > 8 * totalDataCount) throw new Error('code length overflow. (' + buffer.getLengthInBits() + '>' + 8 * totalDataCount + ')');
|
|
1783
|
+
if (buffer.getLengthInBits() + 4 <= 8 * totalDataCount) buffer.put(0, 4);
|
|
1784
|
+
while(buffer.getLengthInBits() % 8 != 0)buffer.putBit(false);
|
|
1785
|
+
while(true){
|
|
1786
|
+
if (buffer.getLengthInBits() >= 8 * totalDataCount) break;
|
|
1787
|
+
buffer.put(0xec, 8);
|
|
1788
|
+
if (buffer.getLengthInBits() >= 8 * totalDataCount) break;
|
|
1789
|
+
buffer.put(0x11, 8);
|
|
1790
|
+
}
|
|
1791
|
+
return this.createBytes(buffer, rsBlocks);
|
|
1792
|
+
}
|
|
1793
|
+
static stringToBytes(s) {
|
|
1794
|
+
function toUTF8Array(str) {
|
|
1795
|
+
const utf8 = [];
|
|
1796
|
+
for(let i = 0; i < str.length; i++){
|
|
1797
|
+
const charcode = str.charCodeAt(i);
|
|
1798
|
+
if (charcode < 0x80) utf8.push(charcode);
|
|
1799
|
+
else if (charcode < 0x800) utf8.push(0xc0 | charcode >> 6, 0x80 | 0x3f & charcode);
|
|
1800
|
+
else if (charcode < 0xd800 || charcode >= 0xe000) utf8.push(0xe0 | charcode >> 12, 0x80 | charcode >> 6 & 0x3f, 0x80 | 0x3f & charcode);
|
|
1801
|
+
else {
|
|
1802
|
+
i++;
|
|
1803
|
+
const charcode2 = 0x10000 + ((0x3ff & charcode) << 10 | 0x3ff & str.charCodeAt(i));
|
|
1804
|
+
utf8.push(0xf0 | charcode2 >> 18, 0x80 | charcode2 >> 12 & 0x3f, 0x80 | charcode2 >> 6 & 0x3f, 0x80 | 0x3f & charcode2);
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
return utf8;
|
|
1808
|
+
}
|
|
1809
|
+
return toUTF8Array(s);
|
|
1810
|
+
}
|
|
1811
|
+
constructor(typeNumber, errorCorrectLevel){
|
|
1812
|
+
qr_generator_define_property(this, "typeNumber", void 0);
|
|
1813
|
+
qr_generator_define_property(this, "errorCorrectLevel", void 0);
|
|
1814
|
+
qr_generator_define_property(this, "modules", null);
|
|
1815
|
+
qr_generator_define_property(this, "moduleCount", 0);
|
|
1816
|
+
qr_generator_define_property(this, "dataCache", null);
|
|
1817
|
+
qr_generator_define_property(this, "dataList", []);
|
|
1818
|
+
this.typeNumber = typeNumber;
|
|
1819
|
+
this.errorCorrectLevel = QRErrorCorrectLevel[errorCorrectLevel];
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
class QR8BitByte {
|
|
1823
|
+
getMode() {
|
|
1824
|
+
return this.mode;
|
|
1825
|
+
}
|
|
1826
|
+
getLength() {
|
|
1827
|
+
return this.bytes.length;
|
|
1828
|
+
}
|
|
1829
|
+
write(buffer) {
|
|
1830
|
+
for(let i = 0; i < this.bytes.length; i += 1)buffer.put(this.bytes[i], 8);
|
|
1831
|
+
}
|
|
1832
|
+
constructor(data){
|
|
1833
|
+
qr_generator_define_property(this, "mode", void 0);
|
|
1834
|
+
qr_generator_define_property(this, "data", void 0);
|
|
1835
|
+
qr_generator_define_property(this, "bytes", void 0);
|
|
1836
|
+
this.mode = QRMode.MODE_8BIT_BYTE;
|
|
1837
|
+
this.data = data;
|
|
1838
|
+
this.bytes = QRCodeGenerator.stringToBytes(data);
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
class QRBitBuffer {
|
|
1842
|
+
getBuffer() {
|
|
1843
|
+
return this.buffer;
|
|
1844
|
+
}
|
|
1845
|
+
getAt(index) {
|
|
1846
|
+
const bufIndex = Math.floor(index / 8);
|
|
1847
|
+
return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) == 1;
|
|
1848
|
+
}
|
|
1849
|
+
put(num, length) {
|
|
1850
|
+
for(let i = 0; i < length; i += 1)this.putBit((num >>> length - i - 1 & 1) == 1);
|
|
1851
|
+
}
|
|
1852
|
+
getLengthInBits() {
|
|
1853
|
+
return this.length;
|
|
1854
|
+
}
|
|
1855
|
+
putBit(bit) {
|
|
1856
|
+
const bufIndex = Math.floor(this.length / 8);
|
|
1857
|
+
if (this.buffer.length <= bufIndex) this.buffer.push(0);
|
|
1858
|
+
if (bit) this.buffer[bufIndex] |= 0x80 >>> this.length % 8;
|
|
1859
|
+
this.length += 1;
|
|
1860
|
+
}
|
|
1861
|
+
constructor(){
|
|
1862
|
+
qr_generator_define_property(this, "buffer", []);
|
|
1863
|
+
qr_generator_define_property(this, "length", 0);
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
class QRPolynomial {
|
|
1867
|
+
getAt(index) {
|
|
1868
|
+
return this.num[index];
|
|
1869
|
+
}
|
|
1870
|
+
getLength() {
|
|
1871
|
+
return this.num.length;
|
|
1872
|
+
}
|
|
1873
|
+
multiply(e) {
|
|
1874
|
+
const num = new Array(this.getLength() + e.getLength() - 1);
|
|
1875
|
+
for(let i = 0; i < this.getLength(); i += 1)for(let j = 0; j < e.getLength(); j += 1)num[i + j] ^= QRMath.gexp(QRMath.glog(this.getAt(i)) + QRMath.glog(e.getAt(j)));
|
|
1876
|
+
return new QRPolynomial(num, 0);
|
|
1877
|
+
}
|
|
1878
|
+
mod(e) {
|
|
1879
|
+
if (this.getLength() - e.getLength() < 0) return this;
|
|
1880
|
+
const ratio = QRMath.glog(this.getAt(0)) - QRMath.glog(e.getAt(0));
|
|
1881
|
+
const num = new Array(this.getLength());
|
|
1882
|
+
for(let i = 0; i < this.getLength(); i += 1)num[i] = this.getAt(i);
|
|
1883
|
+
for(let i = 0; i < e.getLength(); i += 1)num[i] ^= QRMath.gexp(QRMath.glog(e.getAt(i)) + ratio);
|
|
1884
|
+
return new QRPolynomial(num, 0).mod(e);
|
|
1885
|
+
}
|
|
1886
|
+
constructor(num, shift){
|
|
1887
|
+
qr_generator_define_property(this, "num", void 0);
|
|
1888
|
+
if (void 0 === num.length) throw new Error(num.length + '/' + shift);
|
|
1889
|
+
const offset = (()=>{
|
|
1890
|
+
let offset = 0;
|
|
1891
|
+
while(offset < num.length && 0 == num[offset])offset += 1;
|
|
1892
|
+
return offset;
|
|
1893
|
+
})();
|
|
1894
|
+
this.num = new Array(num.length - offset + shift);
|
|
1895
|
+
for(let i = 0; i < num.length - offset; i += 1)this.num[i] = num[i + offset];
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
const QRMode = {
|
|
1899
|
+
MODE_8BIT_BYTE: 4
|
|
1900
|
+
};
|
|
1901
|
+
const QRErrorCorrectLevel = {
|
|
1902
|
+
L: 1,
|
|
1903
|
+
M: 0,
|
|
1904
|
+
Q: 3,
|
|
1905
|
+
H: 2
|
|
1906
|
+
};
|
|
1907
|
+
class QR {
|
|
1908
|
+
static render(config, element) {
|
|
1909
|
+
const settings = this.getDefaultSettings(config);
|
|
1910
|
+
if (element instanceof HTMLCanvasElement) this.renderToCanvas(element, settings);
|
|
1911
|
+
else {
|
|
1912
|
+
const canvas = this.createCanvas(settings);
|
|
1913
|
+
element.appendChild(canvas);
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
static getDefaultSettings(config) {
|
|
1917
|
+
return {
|
|
1918
|
+
minVersion: 1,
|
|
1919
|
+
maxVersion: 40,
|
|
1920
|
+
ecLevel: 'L',
|
|
1921
|
+
left: 0,
|
|
1922
|
+
top: 0,
|
|
1923
|
+
size: 200,
|
|
1924
|
+
fill: '#000',
|
|
1925
|
+
background: null,
|
|
1926
|
+
radius: 0.5,
|
|
1927
|
+
quiet: 0,
|
|
1928
|
+
...config
|
|
1929
|
+
};
|
|
1930
|
+
}
|
|
1931
|
+
static createQRCode(text, level, version, quiet) {
|
|
1932
|
+
try {
|
|
1933
|
+
const qr = new QRCodeGenerator(version, level);
|
|
1934
|
+
qr.addData(text);
|
|
1935
|
+
qr.make();
|
|
1936
|
+
const qrModuleCount = qr.getModuleCount();
|
|
1937
|
+
const quietModuleCount = qrModuleCount + 2 * quiet;
|
|
1938
|
+
const isDark = (row, col)=>{
|
|
1939
|
+
row -= quiet;
|
|
1940
|
+
col -= quiet;
|
|
1941
|
+
if (row < 0 || row >= qrModuleCount || col < 0 || col >= qrModuleCount) return false;
|
|
1942
|
+
return qr.isDark(row, col);
|
|
1943
|
+
};
|
|
1944
|
+
return {
|
|
1945
|
+
text,
|
|
1946
|
+
level,
|
|
1947
|
+
version,
|
|
1948
|
+
moduleCount: quietModuleCount,
|
|
1949
|
+
isDark
|
|
1950
|
+
};
|
|
1951
|
+
} catch {
|
|
1952
|
+
return null;
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
static createMinQRCode(text, level, minVersion, maxVersion, quiet) {
|
|
1956
|
+
minVersion = Math.max(1, minVersion);
|
|
1957
|
+
maxVersion = Math.min(40, maxVersion);
|
|
1958
|
+
for(let version = minVersion; version <= maxVersion; version++){
|
|
1959
|
+
const qr = this.createQRCode(text, level, version, quiet);
|
|
1960
|
+
if (qr) return qr;
|
|
1961
|
+
}
|
|
1962
|
+
return null;
|
|
1963
|
+
}
|
|
1964
|
+
static drawBackground(qr, context, settings) {
|
|
1965
|
+
if (settings.background) {
|
|
1966
|
+
context.fillStyle = settings.background;
|
|
1967
|
+
context.fillRect(settings.left, settings.top, settings.size, settings.size);
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
static drawModuleRoundedDark(ctx, l, t, r, b, rad, nw, ne, se, sw) {
|
|
1971
|
+
if (nw) ctx.moveTo(l + rad, t);
|
|
1972
|
+
else ctx.moveTo(l, t);
|
|
1973
|
+
const lal = (b, x0, y0, x1, y1, r0, r1)=>{
|
|
1974
|
+
if (b) {
|
|
1975
|
+
ctx.lineTo(x0 + r0, y0 + r1);
|
|
1976
|
+
ctx.arcTo(x0, y0, x1, y1, rad);
|
|
1977
|
+
} else ctx.lineTo(x0, y0);
|
|
1978
|
+
};
|
|
1979
|
+
lal(ne, r, t, r, b, -rad, 0);
|
|
1980
|
+
lal(se, r, b, l, b, 0, -rad);
|
|
1981
|
+
lal(sw, l, b, l, t, rad, 0);
|
|
1982
|
+
lal(nw, l, t, r, t, 0, rad);
|
|
1983
|
+
}
|
|
1984
|
+
static drawModuleRoundedLight(ctx, l, t, r, b, rad, nw, ne, se, sw) {
|
|
1985
|
+
const mlla = (x, y, r0, r1)=>{
|
|
1986
|
+
ctx.moveTo(x + r0, y);
|
|
1987
|
+
ctx.lineTo(x, y);
|
|
1988
|
+
ctx.lineTo(x, y + r1);
|
|
1989
|
+
ctx.arcTo(x, y, x + r0, y, rad);
|
|
1990
|
+
};
|
|
1991
|
+
if (nw) mlla(l, t, rad, rad);
|
|
1992
|
+
if (ne) mlla(r, t, -rad, rad);
|
|
1993
|
+
if (se) mlla(r, b, -rad, -rad);
|
|
1994
|
+
if (sw) mlla(l, b, rad, -rad);
|
|
1995
|
+
}
|
|
1996
|
+
static drawModuleRounded(qr, context, settings, left, top, width, row, col) {
|
|
1997
|
+
const isDark = qr.isDark;
|
|
1998
|
+
const right = left + width;
|
|
1999
|
+
const bottom = top + width;
|
|
2000
|
+
const rowT = row - 1;
|
|
2001
|
+
const rowB = row + 1;
|
|
2002
|
+
const colL = col - 1;
|
|
2003
|
+
const colR = col + 1;
|
|
2004
|
+
const radius = Math.floor(Math.min(0.5, Math.max(0, settings.radius)) * width);
|
|
2005
|
+
const center = isDark(row, col);
|
|
2006
|
+
const northwest = isDark(rowT, colL);
|
|
2007
|
+
const north = isDark(rowT, col);
|
|
2008
|
+
const northeast = isDark(rowT, colR);
|
|
2009
|
+
const east = isDark(row, colR);
|
|
2010
|
+
const southeast = isDark(rowB, colR);
|
|
2011
|
+
const south = isDark(rowB, col);
|
|
2012
|
+
const southwest = isDark(rowB, colL);
|
|
2013
|
+
const west = isDark(row, colL);
|
|
2014
|
+
const leftRounded = Math.round(left);
|
|
2015
|
+
const topRounded = Math.round(top);
|
|
2016
|
+
const rightRounded = Math.round(right);
|
|
2017
|
+
const bottomRounded = Math.round(bottom);
|
|
2018
|
+
if (center) this.drawModuleRoundedDark(context, leftRounded, topRounded, rightRounded, bottomRounded, radius, !north && !west, !north && !east, !south && !east, !south && !west);
|
|
2019
|
+
else this.drawModuleRoundedLight(context, leftRounded, topRounded, rightRounded, bottomRounded, radius, north && west && northwest, north && east && northeast, south && east && southeast, south && west && southwest);
|
|
2020
|
+
}
|
|
2021
|
+
static drawModules(qr, context, settings) {
|
|
2022
|
+
const moduleCount = qr.moduleCount;
|
|
2023
|
+
const moduleSize = settings.size / moduleCount;
|
|
2024
|
+
context.beginPath();
|
|
2025
|
+
for(let row = 0; row < moduleCount; row++)for(let col = 0; col < moduleCount; col++){
|
|
2026
|
+
const l = settings.left + col * moduleSize;
|
|
2027
|
+
const t = settings.top + row * moduleSize;
|
|
2028
|
+
const w = moduleSize;
|
|
2029
|
+
this.drawModuleRounded(qr, context, settings, l, t, w, row, col);
|
|
2030
|
+
}
|
|
2031
|
+
this.setFill(context, settings);
|
|
2032
|
+
context.fill();
|
|
2033
|
+
}
|
|
2034
|
+
static setFill(context, settings) {
|
|
2035
|
+
const fill = settings.fill;
|
|
2036
|
+
if ('string' == typeof fill) {
|
|
2037
|
+
context.fillStyle = fill;
|
|
2038
|
+
return;
|
|
2039
|
+
}
|
|
2040
|
+
const type = fill.type;
|
|
2041
|
+
const position = fill.position;
|
|
2042
|
+
const colorStops = fill.colorStops;
|
|
2043
|
+
let gradient;
|
|
2044
|
+
const absolutePosition = position.map((coordinate)=>Math.round(coordinate * settings.size));
|
|
2045
|
+
if ('linear-gradient' === type) gradient = context.createLinearGradient(absolutePosition[0], absolutePosition[1], absolutePosition[2], absolutePosition[3]);
|
|
2046
|
+
else if ('radial-gradient' === type) gradient = context.createRadialGradient(absolutePosition[0], absolutePosition[1], absolutePosition[2], absolutePosition[3], absolutePosition[4], absolutePosition[5]);
|
|
2047
|
+
else throw new Error('Unsupported fill');
|
|
2048
|
+
colorStops.forEach(([offset, color])=>{
|
|
2049
|
+
gradient.addColorStop(offset, color);
|
|
2050
|
+
});
|
|
2051
|
+
context.fillStyle = gradient;
|
|
2052
|
+
}
|
|
2053
|
+
static drawOnCanvas(canvas, settings) {
|
|
2054
|
+
const qr = this.createMinQRCode(settings.text, settings.ecLevel, settings.minVersion, settings.maxVersion, settings.quiet);
|
|
2055
|
+
if (!qr) return null;
|
|
2056
|
+
const context = canvas.getContext('2d');
|
|
2057
|
+
this.drawBackground(qr, context, settings);
|
|
2058
|
+
this.drawModules(qr, context, settings);
|
|
2059
|
+
return canvas;
|
|
2060
|
+
}
|
|
2061
|
+
static createCanvas(settings) {
|
|
2062
|
+
const canvas = document.createElement('canvas');
|
|
2063
|
+
canvas.width = settings.size;
|
|
2064
|
+
canvas.height = settings.size;
|
|
2065
|
+
return this.drawOnCanvas(canvas, settings) || canvas;
|
|
2066
|
+
}
|
|
2067
|
+
static renderToCanvas(canvas, settings) {
|
|
2068
|
+
if (canvas.width !== settings.size || canvas.height !== settings.size) {
|
|
2069
|
+
canvas.width = settings.size;
|
|
2070
|
+
canvas.height = settings.size;
|
|
2071
|
+
}
|
|
2072
|
+
const context = canvas.getContext('2d');
|
|
2073
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
2074
|
+
this.drawOnCanvas(canvas, settings);
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
const src_qr = QR;
|
|
2078
|
+
export { QR, src_qr as default };
|