@lynx-js/qrcode-rsbuild-plugin 0.4.2 → 0.4.4
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/CHANGELOG.md +12 -0
- package/dist/390.js +170 -0
- package/dist/760.js +939 -0
- package/dist/8.js +2058 -0
- package/dist/generateDevUrls.d.ts +0 -3
- package/dist/index.d.ts +0 -3
- package/dist/index.js +1 -213
- package/dist/rslib-runtime.js +38 -0
- package/dist/shortcuts.d.ts +0 -3
- package/dist/shortcuts.js +1 -208
- package/package.json +5 -5
- package/dist/472.js +0 -940
- package/dist/543.js +0 -45
- package/dist/640.js +0 -30
- package/dist/759.js +0 -2005
package/dist/760.js
ADDED
|
@@ -0,0 +1,939 @@
|
|
|
1
|
+
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
2
|
+
import { R } from "./8.js";
|
|
3
|
+
var QrCodeDataType = /* @__PURE__ */ ((QrCodeDataType2)=>{
|
|
4
|
+
QrCodeDataType2[QrCodeDataType2["Border"] = -1] = "Border";
|
|
5
|
+
QrCodeDataType2[QrCodeDataType2["Data"] = 0] = "Data";
|
|
6
|
+
QrCodeDataType2[QrCodeDataType2["Function"] = 1] = "Function";
|
|
7
|
+
QrCodeDataType2[QrCodeDataType2["Position"] = 2] = "Position";
|
|
8
|
+
QrCodeDataType2[QrCodeDataType2["Timing"] = 3] = "Timing";
|
|
9
|
+
QrCodeDataType2[QrCodeDataType2["Alignment"] = 4] = "Alignment";
|
|
10
|
+
return QrCodeDataType2;
|
|
11
|
+
})(QrCodeDataType || {});
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __defNormalProp = (obj, key, value)=>key in obj ? __defProp(obj, key, {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value
|
|
18
|
+
}) : obj[key] = value;
|
|
19
|
+
var __publicField = (obj, key, value)=>{
|
|
20
|
+
__defNormalProp(obj, "symbol" != typeof key ? key + "" : key, value);
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
const LOW = [
|
|
24
|
+
0,
|
|
25
|
+
1
|
|
26
|
+
];
|
|
27
|
+
const MEDIUM = [
|
|
28
|
+
1,
|
|
29
|
+
0
|
|
30
|
+
];
|
|
31
|
+
const QUARTILE = [
|
|
32
|
+
2,
|
|
33
|
+
3
|
|
34
|
+
];
|
|
35
|
+
const HIGH = [
|
|
36
|
+
3,
|
|
37
|
+
2
|
|
38
|
+
];
|
|
39
|
+
const EccMap = {
|
|
40
|
+
L: LOW,
|
|
41
|
+
M: MEDIUM,
|
|
42
|
+
Q: QUARTILE,
|
|
43
|
+
H: HIGH
|
|
44
|
+
};
|
|
45
|
+
const NUMERIC_REGEX = /^[0-9]*$/;
|
|
46
|
+
const ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
|
|
47
|
+
const ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
|
|
48
|
+
const MIN_VERSION = 1;
|
|
49
|
+
const MAX_VERSION = 40;
|
|
50
|
+
const PENALTY_N1 = 3;
|
|
51
|
+
const PENALTY_N2 = 3;
|
|
52
|
+
const PENALTY_N3 = 40;
|
|
53
|
+
const PENALTY_N4 = 10;
|
|
54
|
+
const ECC_CODEWORDS_PER_BLOCK = [
|
|
55
|
+
[
|
|
56
|
+
-1,
|
|
57
|
+
7,
|
|
58
|
+
10,
|
|
59
|
+
15,
|
|
60
|
+
20,
|
|
61
|
+
26,
|
|
62
|
+
18,
|
|
63
|
+
20,
|
|
64
|
+
24,
|
|
65
|
+
30,
|
|
66
|
+
18,
|
|
67
|
+
20,
|
|
68
|
+
24,
|
|
69
|
+
26,
|
|
70
|
+
30,
|
|
71
|
+
22,
|
|
72
|
+
24,
|
|
73
|
+
28,
|
|
74
|
+
30,
|
|
75
|
+
28,
|
|
76
|
+
28,
|
|
77
|
+
28,
|
|
78
|
+
28,
|
|
79
|
+
30,
|
|
80
|
+
30,
|
|
81
|
+
26,
|
|
82
|
+
28,
|
|
83
|
+
30,
|
|
84
|
+
30,
|
|
85
|
+
30,
|
|
86
|
+
30,
|
|
87
|
+
30,
|
|
88
|
+
30,
|
|
89
|
+
30,
|
|
90
|
+
30,
|
|
91
|
+
30,
|
|
92
|
+
30,
|
|
93
|
+
30,
|
|
94
|
+
30,
|
|
95
|
+
30,
|
|
96
|
+
30
|
|
97
|
+
],
|
|
98
|
+
[
|
|
99
|
+
-1,
|
|
100
|
+
10,
|
|
101
|
+
16,
|
|
102
|
+
26,
|
|
103
|
+
18,
|
|
104
|
+
24,
|
|
105
|
+
16,
|
|
106
|
+
18,
|
|
107
|
+
22,
|
|
108
|
+
22,
|
|
109
|
+
26,
|
|
110
|
+
30,
|
|
111
|
+
22,
|
|
112
|
+
22,
|
|
113
|
+
24,
|
|
114
|
+
24,
|
|
115
|
+
28,
|
|
116
|
+
28,
|
|
117
|
+
26,
|
|
118
|
+
26,
|
|
119
|
+
26,
|
|
120
|
+
26,
|
|
121
|
+
28,
|
|
122
|
+
28,
|
|
123
|
+
28,
|
|
124
|
+
28,
|
|
125
|
+
28,
|
|
126
|
+
28,
|
|
127
|
+
28,
|
|
128
|
+
28,
|
|
129
|
+
28,
|
|
130
|
+
28,
|
|
131
|
+
28,
|
|
132
|
+
28,
|
|
133
|
+
28,
|
|
134
|
+
28,
|
|
135
|
+
28,
|
|
136
|
+
28,
|
|
137
|
+
28,
|
|
138
|
+
28,
|
|
139
|
+
28
|
|
140
|
+
],
|
|
141
|
+
[
|
|
142
|
+
-1,
|
|
143
|
+
13,
|
|
144
|
+
22,
|
|
145
|
+
18,
|
|
146
|
+
26,
|
|
147
|
+
18,
|
|
148
|
+
24,
|
|
149
|
+
18,
|
|
150
|
+
22,
|
|
151
|
+
20,
|
|
152
|
+
24,
|
|
153
|
+
28,
|
|
154
|
+
26,
|
|
155
|
+
24,
|
|
156
|
+
20,
|
|
157
|
+
30,
|
|
158
|
+
24,
|
|
159
|
+
28,
|
|
160
|
+
28,
|
|
161
|
+
26,
|
|
162
|
+
30,
|
|
163
|
+
28,
|
|
164
|
+
30,
|
|
165
|
+
30,
|
|
166
|
+
30,
|
|
167
|
+
30,
|
|
168
|
+
28,
|
|
169
|
+
30,
|
|
170
|
+
30,
|
|
171
|
+
30,
|
|
172
|
+
30,
|
|
173
|
+
30,
|
|
174
|
+
30,
|
|
175
|
+
30,
|
|
176
|
+
30,
|
|
177
|
+
30,
|
|
178
|
+
30,
|
|
179
|
+
30,
|
|
180
|
+
30,
|
|
181
|
+
30,
|
|
182
|
+
30
|
|
183
|
+
],
|
|
184
|
+
[
|
|
185
|
+
-1,
|
|
186
|
+
17,
|
|
187
|
+
28,
|
|
188
|
+
22,
|
|
189
|
+
16,
|
|
190
|
+
22,
|
|
191
|
+
28,
|
|
192
|
+
26,
|
|
193
|
+
26,
|
|
194
|
+
24,
|
|
195
|
+
28,
|
|
196
|
+
24,
|
|
197
|
+
28,
|
|
198
|
+
22,
|
|
199
|
+
24,
|
|
200
|
+
24,
|
|
201
|
+
30,
|
|
202
|
+
28,
|
|
203
|
+
28,
|
|
204
|
+
26,
|
|
205
|
+
28,
|
|
206
|
+
30,
|
|
207
|
+
24,
|
|
208
|
+
30,
|
|
209
|
+
30,
|
|
210
|
+
30,
|
|
211
|
+
30,
|
|
212
|
+
30,
|
|
213
|
+
30,
|
|
214
|
+
30,
|
|
215
|
+
30,
|
|
216
|
+
30,
|
|
217
|
+
30,
|
|
218
|
+
30,
|
|
219
|
+
30,
|
|
220
|
+
30,
|
|
221
|
+
30,
|
|
222
|
+
30,
|
|
223
|
+
30,
|
|
224
|
+
30,
|
|
225
|
+
30
|
|
226
|
+
]
|
|
227
|
+
];
|
|
228
|
+
const NUM_ERROR_CORRECTION_BLOCKS = [
|
|
229
|
+
[
|
|
230
|
+
-1,
|
|
231
|
+
1,
|
|
232
|
+
1,
|
|
233
|
+
1,
|
|
234
|
+
1,
|
|
235
|
+
1,
|
|
236
|
+
2,
|
|
237
|
+
2,
|
|
238
|
+
2,
|
|
239
|
+
2,
|
|
240
|
+
4,
|
|
241
|
+
4,
|
|
242
|
+
4,
|
|
243
|
+
4,
|
|
244
|
+
4,
|
|
245
|
+
6,
|
|
246
|
+
6,
|
|
247
|
+
6,
|
|
248
|
+
6,
|
|
249
|
+
7,
|
|
250
|
+
8,
|
|
251
|
+
8,
|
|
252
|
+
9,
|
|
253
|
+
9,
|
|
254
|
+
10,
|
|
255
|
+
12,
|
|
256
|
+
12,
|
|
257
|
+
12,
|
|
258
|
+
13,
|
|
259
|
+
14,
|
|
260
|
+
15,
|
|
261
|
+
16,
|
|
262
|
+
17,
|
|
263
|
+
18,
|
|
264
|
+
19,
|
|
265
|
+
19,
|
|
266
|
+
20,
|
|
267
|
+
21,
|
|
268
|
+
22,
|
|
269
|
+
24,
|
|
270
|
+
25
|
|
271
|
+
],
|
|
272
|
+
[
|
|
273
|
+
-1,
|
|
274
|
+
1,
|
|
275
|
+
1,
|
|
276
|
+
1,
|
|
277
|
+
2,
|
|
278
|
+
2,
|
|
279
|
+
4,
|
|
280
|
+
4,
|
|
281
|
+
4,
|
|
282
|
+
5,
|
|
283
|
+
5,
|
|
284
|
+
5,
|
|
285
|
+
8,
|
|
286
|
+
9,
|
|
287
|
+
9,
|
|
288
|
+
10,
|
|
289
|
+
10,
|
|
290
|
+
11,
|
|
291
|
+
13,
|
|
292
|
+
14,
|
|
293
|
+
16,
|
|
294
|
+
17,
|
|
295
|
+
17,
|
|
296
|
+
18,
|
|
297
|
+
20,
|
|
298
|
+
21,
|
|
299
|
+
23,
|
|
300
|
+
25,
|
|
301
|
+
26,
|
|
302
|
+
28,
|
|
303
|
+
29,
|
|
304
|
+
31,
|
|
305
|
+
33,
|
|
306
|
+
35,
|
|
307
|
+
37,
|
|
308
|
+
38,
|
|
309
|
+
40,
|
|
310
|
+
43,
|
|
311
|
+
45,
|
|
312
|
+
47,
|
|
313
|
+
49
|
|
314
|
+
],
|
|
315
|
+
[
|
|
316
|
+
-1,
|
|
317
|
+
1,
|
|
318
|
+
1,
|
|
319
|
+
2,
|
|
320
|
+
2,
|
|
321
|
+
4,
|
|
322
|
+
4,
|
|
323
|
+
6,
|
|
324
|
+
6,
|
|
325
|
+
8,
|
|
326
|
+
8,
|
|
327
|
+
8,
|
|
328
|
+
10,
|
|
329
|
+
12,
|
|
330
|
+
16,
|
|
331
|
+
12,
|
|
332
|
+
17,
|
|
333
|
+
16,
|
|
334
|
+
18,
|
|
335
|
+
21,
|
|
336
|
+
20,
|
|
337
|
+
23,
|
|
338
|
+
23,
|
|
339
|
+
25,
|
|
340
|
+
27,
|
|
341
|
+
29,
|
|
342
|
+
34,
|
|
343
|
+
34,
|
|
344
|
+
35,
|
|
345
|
+
38,
|
|
346
|
+
40,
|
|
347
|
+
43,
|
|
348
|
+
45,
|
|
349
|
+
48,
|
|
350
|
+
51,
|
|
351
|
+
53,
|
|
352
|
+
56,
|
|
353
|
+
59,
|
|
354
|
+
62,
|
|
355
|
+
65,
|
|
356
|
+
68
|
|
357
|
+
],
|
|
358
|
+
[
|
|
359
|
+
-1,
|
|
360
|
+
1,
|
|
361
|
+
1,
|
|
362
|
+
2,
|
|
363
|
+
4,
|
|
364
|
+
4,
|
|
365
|
+
4,
|
|
366
|
+
5,
|
|
367
|
+
6,
|
|
368
|
+
8,
|
|
369
|
+
8,
|
|
370
|
+
11,
|
|
371
|
+
11,
|
|
372
|
+
16,
|
|
373
|
+
16,
|
|
374
|
+
18,
|
|
375
|
+
16,
|
|
376
|
+
19,
|
|
377
|
+
21,
|
|
378
|
+
25,
|
|
379
|
+
25,
|
|
380
|
+
25,
|
|
381
|
+
34,
|
|
382
|
+
30,
|
|
383
|
+
32,
|
|
384
|
+
35,
|
|
385
|
+
37,
|
|
386
|
+
40,
|
|
387
|
+
42,
|
|
388
|
+
45,
|
|
389
|
+
48,
|
|
390
|
+
51,
|
|
391
|
+
54,
|
|
392
|
+
57,
|
|
393
|
+
60,
|
|
394
|
+
63,
|
|
395
|
+
66,
|
|
396
|
+
70,
|
|
397
|
+
74,
|
|
398
|
+
77,
|
|
399
|
+
81
|
|
400
|
+
]
|
|
401
|
+
];
|
|
402
|
+
class QrCode {
|
|
403
|
+
constructor(version, ecc, dataCodewords, msk){
|
|
404
|
+
this.version = version;
|
|
405
|
+
this.ecc = ecc;
|
|
406
|
+
__publicField(this, "size");
|
|
407
|
+
__publicField(this, "mask");
|
|
408
|
+
__publicField(this, "modules", []);
|
|
409
|
+
__publicField(this, "types", []);
|
|
410
|
+
if (version < MIN_VERSION || version > MAX_VERSION) throw new RangeError("Version value out of range");
|
|
411
|
+
if (msk < -1 || msk > 7) throw new RangeError("Mask value out of range");
|
|
412
|
+
this.size = 4 * version + 17;
|
|
413
|
+
const row = Array.from({
|
|
414
|
+
length: this.size
|
|
415
|
+
}, ()=>false);
|
|
416
|
+
for(let i = 0; i < this.size; i++){
|
|
417
|
+
this.modules.push(row.slice());
|
|
418
|
+
this.types.push(row.map(()=>0));
|
|
419
|
+
}
|
|
420
|
+
this.drawFunctionPatterns();
|
|
421
|
+
const allCodewords = this.addEccAndInterleave(dataCodewords);
|
|
422
|
+
this.drawCodewords(allCodewords);
|
|
423
|
+
if (-1 === msk) {
|
|
424
|
+
let minPenalty = 1e9;
|
|
425
|
+
for(let i = 0; i < 8; i++){
|
|
426
|
+
this.applyMask(i);
|
|
427
|
+
this.drawFormatBits(i);
|
|
428
|
+
const penalty = this.getPenaltyScore();
|
|
429
|
+
if (penalty < minPenalty) {
|
|
430
|
+
msk = i;
|
|
431
|
+
minPenalty = penalty;
|
|
432
|
+
}
|
|
433
|
+
this.applyMask(i);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
this.mask = msk;
|
|
437
|
+
this.applyMask(msk);
|
|
438
|
+
this.drawFormatBits(msk);
|
|
439
|
+
}
|
|
440
|
+
getModule(x, y) {
|
|
441
|
+
return x >= 0 && x < this.size && y >= 0 && y < this.size && this.modules[y][x];
|
|
442
|
+
}
|
|
443
|
+
drawFunctionPatterns() {
|
|
444
|
+
for(let i = 0; i < this.size; i++){
|
|
445
|
+
this.setFunctionModule(6, i, i % 2 === 0, QrCodeDataType.Timing);
|
|
446
|
+
this.setFunctionModule(i, 6, i % 2 === 0, QrCodeDataType.Timing);
|
|
447
|
+
}
|
|
448
|
+
this.drawFinderPattern(3, 3);
|
|
449
|
+
this.drawFinderPattern(this.size - 4, 3);
|
|
450
|
+
this.drawFinderPattern(3, this.size - 4);
|
|
451
|
+
const alignPatPos = this.getAlignmentPatternPositions();
|
|
452
|
+
const numAlign = alignPatPos.length;
|
|
453
|
+
for(let i = 0; i < numAlign; i++)for(let j = 0; j < numAlign; j++)if (!(0 === i && 0 === j || 0 === i && j === numAlign - 1 || i === numAlign - 1 && 0 === j)) this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
|
|
454
|
+
this.drawFormatBits(0);
|
|
455
|
+
this.drawVersion();
|
|
456
|
+
}
|
|
457
|
+
drawFormatBits(mask) {
|
|
458
|
+
const data = this.ecc[1] << 3 | mask;
|
|
459
|
+
let rem = data;
|
|
460
|
+
for(let i = 0; i < 10; i++)rem = rem << 1 ^ (rem >>> 9) * 1335;
|
|
461
|
+
const bits = (data << 10 | rem) ^ 21522;
|
|
462
|
+
for(let i = 0; i <= 5; i++)this.setFunctionModule(8, i, getBit(bits, i));
|
|
463
|
+
this.setFunctionModule(8, 7, getBit(bits, 6));
|
|
464
|
+
this.setFunctionModule(8, 8, getBit(bits, 7));
|
|
465
|
+
this.setFunctionModule(7, 8, getBit(bits, 8));
|
|
466
|
+
for(let i = 9; i < 15; i++)this.setFunctionModule(14 - i, 8, getBit(bits, i));
|
|
467
|
+
for(let i = 0; i < 8; i++)this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
|
|
468
|
+
for(let i = 8; i < 15; i++)this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
|
|
469
|
+
this.setFunctionModule(8, this.size - 8, true);
|
|
470
|
+
}
|
|
471
|
+
drawVersion() {
|
|
472
|
+
if (this.version < 7) return;
|
|
473
|
+
let rem = this.version;
|
|
474
|
+
for(let i = 0; i < 12; i++)rem = rem << 1 ^ (rem >>> 11) * 7973;
|
|
475
|
+
const bits = this.version << 12 | rem;
|
|
476
|
+
for(let i = 0; i < 18; i++){
|
|
477
|
+
const color = getBit(bits, i);
|
|
478
|
+
const a = this.size - 11 + i % 3;
|
|
479
|
+
const b = Math.floor(i / 3);
|
|
480
|
+
this.setFunctionModule(a, b, color);
|
|
481
|
+
this.setFunctionModule(b, a, color);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
drawFinderPattern(x, y) {
|
|
485
|
+
for(let dy = -4; dy <= 4; dy++)for(let dx = -4; dx <= 4; dx++){
|
|
486
|
+
const dist = Math.max(Math.abs(dx), Math.abs(dy));
|
|
487
|
+
const xx = x + dx;
|
|
488
|
+
const yy = y + dy;
|
|
489
|
+
if (xx >= 0 && xx < this.size && yy >= 0 && yy < this.size) this.setFunctionModule(xx, yy, 2 !== dist && 4 !== dist, QrCodeDataType.Position);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
drawAlignmentPattern(x, y) {
|
|
493
|
+
for(let dy = -2; dy <= 2; dy++)for(let dx = -2; dx <= 2; dx++)this.setFunctionModule(x + dx, y + dy, 1 !== Math.max(Math.abs(dx), Math.abs(dy)), QrCodeDataType.Alignment);
|
|
494
|
+
}
|
|
495
|
+
setFunctionModule(x, y, isDark, type = QrCodeDataType.Function) {
|
|
496
|
+
this.modules[y][x] = isDark;
|
|
497
|
+
this.types[y][x] = type;
|
|
498
|
+
}
|
|
499
|
+
addEccAndInterleave(data) {
|
|
500
|
+
const ver = this.version;
|
|
501
|
+
const ecl = this.ecc;
|
|
502
|
+
if (data.length !== getNumDataCodewords(ver, ecl)) throw new RangeError("Invalid argument");
|
|
503
|
+
const numBlocks = NUM_ERROR_CORRECTION_BLOCKS[ecl[0]][ver];
|
|
504
|
+
const blockEccLen = ECC_CODEWORDS_PER_BLOCK[ecl[0]][ver];
|
|
505
|
+
const rawCodewords = Math.floor(getNumRawDataModules(ver) / 8);
|
|
506
|
+
const numShortBlocks = numBlocks - rawCodewords % numBlocks;
|
|
507
|
+
const shortBlockLen = Math.floor(rawCodewords / numBlocks);
|
|
508
|
+
const blocks = [];
|
|
509
|
+
const rsDiv = reedSolomonComputeDivisor(blockEccLen);
|
|
510
|
+
for(let i = 0, k = 0; i < numBlocks; i++){
|
|
511
|
+
const dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
|
|
512
|
+
k += dat.length;
|
|
513
|
+
const ecc = reedSolomonComputeRemainder(dat, rsDiv);
|
|
514
|
+
if (i < numShortBlocks) dat.push(0);
|
|
515
|
+
blocks.push(dat.concat(ecc));
|
|
516
|
+
}
|
|
517
|
+
const result = [];
|
|
518
|
+
for(let i = 0; i < blocks[0].length; i++)blocks.forEach((block, j)=>{
|
|
519
|
+
if (i !== shortBlockLen - blockEccLen || j >= numShortBlocks) result.push(block[i]);
|
|
520
|
+
});
|
|
521
|
+
return result;
|
|
522
|
+
}
|
|
523
|
+
drawCodewords(data) {
|
|
524
|
+
if (data.length !== Math.floor(getNumRawDataModules(this.version) / 8)) throw new RangeError("Invalid argument");
|
|
525
|
+
let i = 0;
|
|
526
|
+
for(let right = this.size - 1; right >= 1; right -= 2){
|
|
527
|
+
if (6 === right) right = 5;
|
|
528
|
+
for(let vert = 0; vert < this.size; vert++)for(let j = 0; j < 2; j++){
|
|
529
|
+
const x = right - j;
|
|
530
|
+
const upward = (right + 1 & 2) === 0;
|
|
531
|
+
const y = upward ? this.size - 1 - vert : vert;
|
|
532
|
+
if (!this.types[y][x] && i < 8 * data.length) {
|
|
533
|
+
this.modules[y][x] = getBit(data[i >>> 3], 7 - (7 & i));
|
|
534
|
+
i++;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
applyMask(mask) {
|
|
540
|
+
if (mask < 0 || mask > 7) throw new RangeError("Mask value out of range");
|
|
541
|
+
for(let y = 0; y < this.size; y++)for(let x = 0; x < this.size; x++){
|
|
542
|
+
let invert;
|
|
543
|
+
switch(mask){
|
|
544
|
+
case 0:
|
|
545
|
+
invert = (x + y) % 2 === 0;
|
|
546
|
+
break;
|
|
547
|
+
case 1:
|
|
548
|
+
invert = y % 2 === 0;
|
|
549
|
+
break;
|
|
550
|
+
case 2:
|
|
551
|
+
invert = x % 3 === 0;
|
|
552
|
+
break;
|
|
553
|
+
case 3:
|
|
554
|
+
invert = (x + y) % 3 === 0;
|
|
555
|
+
break;
|
|
556
|
+
case 4:
|
|
557
|
+
invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;
|
|
558
|
+
break;
|
|
559
|
+
case 5:
|
|
560
|
+
invert = x * y % 2 + x * y % 3 === 0;
|
|
561
|
+
break;
|
|
562
|
+
case 6:
|
|
563
|
+
invert = (x * y % 2 + x * y % 3) % 2 === 0;
|
|
564
|
+
break;
|
|
565
|
+
case 7:
|
|
566
|
+
invert = ((x + y) % 2 + x * y % 3) % 2 === 0;
|
|
567
|
+
break;
|
|
568
|
+
default:
|
|
569
|
+
throw new Error("Unreachable");
|
|
570
|
+
}
|
|
571
|
+
if (!this.types[y][x] && invert) this.modules[y][x] = !this.modules[y][x];
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
getPenaltyScore() {
|
|
575
|
+
let result = 0;
|
|
576
|
+
for(let y = 0; y < this.size; y++){
|
|
577
|
+
let runColor = false;
|
|
578
|
+
let runX = 0;
|
|
579
|
+
const runHistory = [
|
|
580
|
+
0,
|
|
581
|
+
0,
|
|
582
|
+
0,
|
|
583
|
+
0,
|
|
584
|
+
0,
|
|
585
|
+
0,
|
|
586
|
+
0
|
|
587
|
+
];
|
|
588
|
+
for(let x = 0; x < this.size; x++)if (this.modules[y][x] === runColor) {
|
|
589
|
+
runX++;
|
|
590
|
+
if (5 === runX) result += PENALTY_N1;
|
|
591
|
+
else if (runX > 5) result++;
|
|
592
|
+
} else {
|
|
593
|
+
this.finderPenaltyAddHistory(runX, runHistory);
|
|
594
|
+
if (!runColor) result += this.finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
|
|
595
|
+
runColor = this.modules[y][x];
|
|
596
|
+
runX = 1;
|
|
597
|
+
}
|
|
598
|
+
result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * PENALTY_N3;
|
|
599
|
+
}
|
|
600
|
+
for(let x = 0; x < this.size; x++){
|
|
601
|
+
let runColor = false;
|
|
602
|
+
let runY = 0;
|
|
603
|
+
const runHistory = [
|
|
604
|
+
0,
|
|
605
|
+
0,
|
|
606
|
+
0,
|
|
607
|
+
0,
|
|
608
|
+
0,
|
|
609
|
+
0,
|
|
610
|
+
0
|
|
611
|
+
];
|
|
612
|
+
for(let y = 0; y < this.size; y++)if (this.modules[y][x] === runColor) {
|
|
613
|
+
runY++;
|
|
614
|
+
if (5 === runY) result += PENALTY_N1;
|
|
615
|
+
else if (runY > 5) result++;
|
|
616
|
+
} else {
|
|
617
|
+
this.finderPenaltyAddHistory(runY, runHistory);
|
|
618
|
+
if (!runColor) result += this.finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
|
|
619
|
+
runColor = this.modules[y][x];
|
|
620
|
+
runY = 1;
|
|
621
|
+
}
|
|
622
|
+
result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * PENALTY_N3;
|
|
623
|
+
}
|
|
624
|
+
for(let y = 0; y < this.size - 1; y++)for(let x = 0; x < this.size - 1; x++){
|
|
625
|
+
const color = this.modules[y][x];
|
|
626
|
+
if (color === this.modules[y][x + 1] && color === this.modules[y + 1][x] && color === this.modules[y + 1][x + 1]) result += PENALTY_N2;
|
|
627
|
+
}
|
|
628
|
+
let dark = 0;
|
|
629
|
+
for (const row of this.modules)dark = row.reduce((sum, color)=>sum + (color ? 1 : 0), dark);
|
|
630
|
+
const total = this.size * this.size;
|
|
631
|
+
const k = Math.ceil(Math.abs(20 * dark - 10 * total) / total) - 1;
|
|
632
|
+
result += k * PENALTY_N4;
|
|
633
|
+
return result;
|
|
634
|
+
}
|
|
635
|
+
getAlignmentPatternPositions() {
|
|
636
|
+
if (1 === this.version) return [];
|
|
637
|
+
{
|
|
638
|
+
const numAlign = Math.floor(this.version / 7) + 2;
|
|
639
|
+
const step = 32 === this.version ? 26 : 2 * Math.ceil((4 * this.version + 4) / (2 * numAlign - 2));
|
|
640
|
+
const result = [
|
|
641
|
+
6
|
|
642
|
+
];
|
|
643
|
+
for(let pos = this.size - 7; result.length < numAlign; pos -= step)result.splice(1, 0, pos);
|
|
644
|
+
return result;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
finderPenaltyCountPatterns(runHistory) {
|
|
648
|
+
const n = runHistory[1];
|
|
649
|
+
const core = n > 0 && runHistory[2] === n && runHistory[3] === 3 * n && runHistory[4] === n && runHistory[5] === n;
|
|
650
|
+
return (core && runHistory[0] >= 4 * n && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= 4 * n && runHistory[0] >= n ? 1 : 0);
|
|
651
|
+
}
|
|
652
|
+
finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
|
|
653
|
+
if (currentRunColor) {
|
|
654
|
+
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
|
655
|
+
currentRunLength = 0;
|
|
656
|
+
}
|
|
657
|
+
currentRunLength += this.size;
|
|
658
|
+
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
|
659
|
+
return this.finderPenaltyCountPatterns(runHistory);
|
|
660
|
+
}
|
|
661
|
+
finderPenaltyAddHistory(currentRunLength, runHistory) {
|
|
662
|
+
if (0 === runHistory[0]) currentRunLength += this.size;
|
|
663
|
+
runHistory.pop();
|
|
664
|
+
runHistory.unshift(currentRunLength);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
function appendBits(val, len, bb) {
|
|
668
|
+
if (len < 0 || len > 31 || val >>> len !== 0) throw new RangeError("Value out of range");
|
|
669
|
+
for(let i = len - 1; i >= 0; i--)bb.push(val >>> i & 1);
|
|
670
|
+
}
|
|
671
|
+
function getBit(x, i) {
|
|
672
|
+
return (x >>> i & 1) !== 0;
|
|
673
|
+
}
|
|
674
|
+
class QrSegment {
|
|
675
|
+
constructor(mode, numChars, bitData){
|
|
676
|
+
this.mode = mode;
|
|
677
|
+
this.numChars = numChars;
|
|
678
|
+
this.bitData = bitData;
|
|
679
|
+
if (numChars < 0) throw new RangeError("Invalid argument");
|
|
680
|
+
this.bitData = bitData.slice();
|
|
681
|
+
}
|
|
682
|
+
getData() {
|
|
683
|
+
return this.bitData.slice();
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
const MODE_NUMERIC = [
|
|
687
|
+
1,
|
|
688
|
+
10,
|
|
689
|
+
12,
|
|
690
|
+
14
|
|
691
|
+
];
|
|
692
|
+
const MODE_ALPHANUMERIC = [
|
|
693
|
+
2,
|
|
694
|
+
9,
|
|
695
|
+
11,
|
|
696
|
+
13
|
|
697
|
+
];
|
|
698
|
+
const MODE_BYTE = [
|
|
699
|
+
4,
|
|
700
|
+
8,
|
|
701
|
+
16,
|
|
702
|
+
16
|
|
703
|
+
];
|
|
704
|
+
function numCharCountBits(mode, ver) {
|
|
705
|
+
return mode[Math.floor((ver + 7) / 17) + 1];
|
|
706
|
+
}
|
|
707
|
+
function makeBytes(data) {
|
|
708
|
+
const bb = [];
|
|
709
|
+
for (const b of data)appendBits(b, 8, bb);
|
|
710
|
+
return new QrSegment(MODE_BYTE, data.length, bb);
|
|
711
|
+
}
|
|
712
|
+
function makeNumeric(digits) {
|
|
713
|
+
if (!isNumeric(digits)) throw new RangeError("String contains non-numeric characters");
|
|
714
|
+
const bb = [];
|
|
715
|
+
for(let i = 0; i < digits.length;){
|
|
716
|
+
const n = Math.min(digits.length - i, 3);
|
|
717
|
+
appendBits(Number.parseInt(digits.substring(i, i + n), 10), 3 * n + 1, bb);
|
|
718
|
+
i += n;
|
|
719
|
+
}
|
|
720
|
+
return new QrSegment(MODE_NUMERIC, digits.length, bb);
|
|
721
|
+
}
|
|
722
|
+
function makeAlphanumeric(text) {
|
|
723
|
+
if (!isAlphanumeric(text)) throw new RangeError("String contains unencodable characters in alphanumeric mode");
|
|
724
|
+
const bb = [];
|
|
725
|
+
let i;
|
|
726
|
+
for(i = 0; i + 2 <= text.length; i += 2){
|
|
727
|
+
let temp = 45 * ALPHANUMERIC_CHARSET.indexOf(text.charAt(i));
|
|
728
|
+
temp += ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
|
|
729
|
+
appendBits(temp, 11, bb);
|
|
730
|
+
}
|
|
731
|
+
if (i < text.length) appendBits(ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
|
|
732
|
+
return new QrSegment(MODE_ALPHANUMERIC, text.length, bb);
|
|
733
|
+
}
|
|
734
|
+
function makeSegments(text) {
|
|
735
|
+
if ("" === text) return [];
|
|
736
|
+
if (isNumeric(text)) return [
|
|
737
|
+
makeNumeric(text)
|
|
738
|
+
];
|
|
739
|
+
if (isAlphanumeric(text)) return [
|
|
740
|
+
makeAlphanumeric(text)
|
|
741
|
+
];
|
|
742
|
+
return [
|
|
743
|
+
makeBytes(toUtf8ByteArray(text))
|
|
744
|
+
];
|
|
745
|
+
}
|
|
746
|
+
function isNumeric(text) {
|
|
747
|
+
return NUMERIC_REGEX.test(text);
|
|
748
|
+
}
|
|
749
|
+
function isAlphanumeric(text) {
|
|
750
|
+
return ALPHANUMERIC_REGEX.test(text);
|
|
751
|
+
}
|
|
752
|
+
function getTotalBits(segs, version) {
|
|
753
|
+
let result = 0;
|
|
754
|
+
for (const seg of segs){
|
|
755
|
+
const ccbits = numCharCountBits(seg.mode, version);
|
|
756
|
+
if (seg.numChars >= 1 << ccbits) return 1 / 0;
|
|
757
|
+
result += 4 + ccbits + seg.bitData.length;
|
|
758
|
+
}
|
|
759
|
+
return result;
|
|
760
|
+
}
|
|
761
|
+
function toUtf8ByteArray(str) {
|
|
762
|
+
str = encodeURI(str);
|
|
763
|
+
const result = [];
|
|
764
|
+
for(let i = 0; i < str.length; i++)if ("%" !== str.charAt(i)) result.push(str.charCodeAt(i));
|
|
765
|
+
else {
|
|
766
|
+
result.push(Number.parseInt(str.substring(i + 1, i + 3), 16));
|
|
767
|
+
i += 2;
|
|
768
|
+
}
|
|
769
|
+
return result;
|
|
770
|
+
}
|
|
771
|
+
function getNumRawDataModules(ver) {
|
|
772
|
+
if (ver < MIN_VERSION || ver > MAX_VERSION) throw new RangeError("Version number out of range");
|
|
773
|
+
let result = (16 * ver + 128) * ver + 64;
|
|
774
|
+
if (ver >= 2) {
|
|
775
|
+
const numAlign = Math.floor(ver / 7) + 2;
|
|
776
|
+
result -= (25 * numAlign - 10) * numAlign - 55;
|
|
777
|
+
if (ver >= 7) result -= 36;
|
|
778
|
+
}
|
|
779
|
+
return result;
|
|
780
|
+
}
|
|
781
|
+
function getNumDataCodewords(ver, ecl) {
|
|
782
|
+
return Math.floor(getNumRawDataModules(ver) / 8) - ECC_CODEWORDS_PER_BLOCK[ecl[0]][ver] * NUM_ERROR_CORRECTION_BLOCKS[ecl[0]][ver];
|
|
783
|
+
}
|
|
784
|
+
function reedSolomonComputeDivisor(degree) {
|
|
785
|
+
if (degree < 1 || degree > 255) throw new RangeError("Degree out of range");
|
|
786
|
+
const result = [];
|
|
787
|
+
for(let i = 0; i < degree - 1; i++)result.push(0);
|
|
788
|
+
result.push(1);
|
|
789
|
+
let root = 1;
|
|
790
|
+
for(let i = 0; i < degree; i++){
|
|
791
|
+
for(let j = 0; j < result.length; j++){
|
|
792
|
+
result[j] = reedSolomonMultiply(result[j], root);
|
|
793
|
+
if (j + 1 < result.length) result[j] ^= result[j + 1];
|
|
794
|
+
}
|
|
795
|
+
root = reedSolomonMultiply(root, 2);
|
|
796
|
+
}
|
|
797
|
+
return result;
|
|
798
|
+
}
|
|
799
|
+
function reedSolomonComputeRemainder(data, divisor) {
|
|
800
|
+
const result = divisor.map((_)=>0);
|
|
801
|
+
for (const b of data){
|
|
802
|
+
const factor = b ^ result.shift();
|
|
803
|
+
result.push(0);
|
|
804
|
+
divisor.forEach((coef, i)=>result[i] ^= reedSolomonMultiply(coef, factor));
|
|
805
|
+
}
|
|
806
|
+
return result;
|
|
807
|
+
}
|
|
808
|
+
function reedSolomonMultiply(x, y) {
|
|
809
|
+
if (x >>> 8 !== 0 || y >>> 8 !== 0) throw new RangeError("Byte out of range");
|
|
810
|
+
let z = 0;
|
|
811
|
+
for(let i = 7; i >= 0; i--){
|
|
812
|
+
z = z << 1 ^ (z >>> 7) * 285;
|
|
813
|
+
z ^= (y >>> i & 1) * x;
|
|
814
|
+
}
|
|
815
|
+
return z;
|
|
816
|
+
}
|
|
817
|
+
function encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
|
|
818
|
+
if (!(MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= MAX_VERSION) || mask < -1 || mask > 7) throw new RangeError("Invalid value");
|
|
819
|
+
let version;
|
|
820
|
+
let dataUsedBits;
|
|
821
|
+
for(version = minVersion;; version++){
|
|
822
|
+
const dataCapacityBits2 = 8 * getNumDataCodewords(version, ecl);
|
|
823
|
+
const usedBits = getTotalBits(segs, version);
|
|
824
|
+
if (usedBits <= dataCapacityBits2) {
|
|
825
|
+
dataUsedBits = usedBits;
|
|
826
|
+
break;
|
|
827
|
+
}
|
|
828
|
+
if (version >= maxVersion) throw new RangeError("Data too long");
|
|
829
|
+
}
|
|
830
|
+
for (const newEcl of [
|
|
831
|
+
MEDIUM,
|
|
832
|
+
QUARTILE,
|
|
833
|
+
HIGH
|
|
834
|
+
])if (boostEcl && dataUsedBits <= 8 * getNumDataCodewords(version, newEcl)) ecl = newEcl;
|
|
835
|
+
const bb = [];
|
|
836
|
+
for (const seg of segs){
|
|
837
|
+
appendBits(seg.mode[0], 4, bb);
|
|
838
|
+
appendBits(seg.numChars, numCharCountBits(seg.mode, version), bb);
|
|
839
|
+
for (const b of seg.getData())bb.push(b);
|
|
840
|
+
}
|
|
841
|
+
const dataCapacityBits = 8 * getNumDataCodewords(version, ecl);
|
|
842
|
+
appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
|
|
843
|
+
appendBits(0, (8 - bb.length % 8) % 8, bb);
|
|
844
|
+
for(let padByte = 236; bb.length < dataCapacityBits; padByte ^= 253)appendBits(padByte, 8, bb);
|
|
845
|
+
const dataCodewords = Array.from({
|
|
846
|
+
length: Math.ceil(bb.length / 8)
|
|
847
|
+
}, ()=>0);
|
|
848
|
+
bb.forEach((b, i)=>dataCodewords[i >>> 3] |= b << 7 - (7 & i));
|
|
849
|
+
return new QrCode(version, ecl, dataCodewords, mask);
|
|
850
|
+
}
|
|
851
|
+
function encode(data, options) {
|
|
852
|
+
const { ecc = "L", boostEcc = false, minVersion = 1, maxVersion = 40, maskPattern = -1, border = 1 } = options || {};
|
|
853
|
+
const segment = "string" == typeof data ? makeSegments(data) : Array.isArray(data) ? [
|
|
854
|
+
makeBytes(data)
|
|
855
|
+
] : void 0;
|
|
856
|
+
if (!segment) throw new Error(`uqr only supports encoding string and binary data, but got: ${typeof data}`);
|
|
857
|
+
const qr = encodeSegments(segment, EccMap[ecc], minVersion, maxVersion, maskPattern, boostEcc);
|
|
858
|
+
const result = addBorder({
|
|
859
|
+
version: qr.version,
|
|
860
|
+
maskPattern: qr.mask,
|
|
861
|
+
size: qr.size,
|
|
862
|
+
data: qr.modules,
|
|
863
|
+
types: qr.types
|
|
864
|
+
}, border);
|
|
865
|
+
if (options?.invert) result.data = result.data.map((row)=>row.map((mod)=>!mod));
|
|
866
|
+
options?.onEncoded?.(result);
|
|
867
|
+
return result;
|
|
868
|
+
}
|
|
869
|
+
function addBorder(input, border = 1) {
|
|
870
|
+
if (!border) return input;
|
|
871
|
+
const { size } = input;
|
|
872
|
+
const newSize = size + 2 * border;
|
|
873
|
+
input.size = newSize;
|
|
874
|
+
input.data.forEach((row)=>{
|
|
875
|
+
for(let i = 0; i < border; i++){
|
|
876
|
+
row.unshift(false);
|
|
877
|
+
row.push(false);
|
|
878
|
+
}
|
|
879
|
+
});
|
|
880
|
+
for(let i = 0; i < border; i++){
|
|
881
|
+
input.data.unshift(Array.from({
|
|
882
|
+
length: newSize
|
|
883
|
+
}, (_)=>false));
|
|
884
|
+
input.data.push(Array.from({
|
|
885
|
+
length: newSize
|
|
886
|
+
}, (_)=>false));
|
|
887
|
+
}
|
|
888
|
+
const b = QrCodeDataType.Border;
|
|
889
|
+
input.types.forEach((row)=>{
|
|
890
|
+
for(let i = 0; i < border; i++){
|
|
891
|
+
row.unshift(b);
|
|
892
|
+
row.push(b);
|
|
893
|
+
}
|
|
894
|
+
});
|
|
895
|
+
for(let i = 0; i < border; i++){
|
|
896
|
+
input.types.unshift(Array.from({
|
|
897
|
+
length: newSize
|
|
898
|
+
}, (_)=>b));
|
|
899
|
+
input.types.push(Array.from({
|
|
900
|
+
length: newSize
|
|
901
|
+
}, (_)=>b));
|
|
902
|
+
}
|
|
903
|
+
return input;
|
|
904
|
+
}
|
|
905
|
+
function getDataAt(data, x, y, defaults = false) {
|
|
906
|
+
if (x < 0 || y < 0 || x >= data.length || y >= data.length) return defaults;
|
|
907
|
+
return data[y][x];
|
|
908
|
+
}
|
|
909
|
+
function renderUnicodeCompact(data, options = {}) {
|
|
910
|
+
const platte = {
|
|
911
|
+
WHITE_ALL: "\u2588",
|
|
912
|
+
WHITE_BLACK: "\u2580",
|
|
913
|
+
BLACK_WHITE: "\u2584",
|
|
914
|
+
BLACK_ALL: " "
|
|
915
|
+
};
|
|
916
|
+
const result = encode(data, options);
|
|
917
|
+
const WHITE = false;
|
|
918
|
+
const BLACK = true;
|
|
919
|
+
const at = (x, y)=>getDataAt(result.data, x, y, true);
|
|
920
|
+
const lines = [];
|
|
921
|
+
let line = "";
|
|
922
|
+
for(let row = 0; row < result.size; row += 2){
|
|
923
|
+
for(let col = 0; col < result.size; col++)if (at(col, row) === WHITE && at(col, row + 1) === WHITE) line += platte.WHITE_ALL;
|
|
924
|
+
else if (at(col, row) === WHITE && at(col, row + 1) === BLACK) line += platte.WHITE_BLACK;
|
|
925
|
+
else if (at(col, row) === BLACK && at(col, row + 1) === WHITE) line += platte.BLACK_WHITE;
|
|
926
|
+
else line += platte.BLACK_ALL;
|
|
927
|
+
lines.push(line);
|
|
928
|
+
line = "";
|
|
929
|
+
}
|
|
930
|
+
return lines.join("\n");
|
|
931
|
+
}
|
|
932
|
+
const picocolors = __webpack_require__("../../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
933
|
+
var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
|
|
934
|
+
function showQRCode(url) {
|
|
935
|
+
R.info(picocolors_default().green('Scan with Lynx'));
|
|
936
|
+
R.success(renderUnicodeCompact(url));
|
|
937
|
+
R.success(url);
|
|
938
|
+
}
|
|
939
|
+
export { showQRCode };
|