@eudi-verify/embed 0.1.0 → 0.1.2
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 +86 -83
- package/dist/eudi-verify.cjs +43 -8
- package/dist/eudi-verify.cjs.map +1 -1
- package/dist/eudi-verify.d.cts +14 -10
- package/dist/eudi-verify.d.ts +14 -10
- package/dist/eudi-verify.iife.js +1923 -421
- package/dist/eudi-verify.iife.js.map +1 -1
- package/dist/eudi-verify.js +43 -8
- package/dist/eudi-verify.js.map +1 -1
- package/package.json +2 -2
package/dist/eudi-verify.iife.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var EudiVerify = (() => {
|
|
3
|
+
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
+
try {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
throw mod = 0, e;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
7
16
|
var __export = (target, all) => {
|
|
8
17
|
for (var name in all)
|
|
9
18
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,8 +25,1846 @@ var EudiVerify = (() => {
|
|
|
16
25
|
}
|
|
17
26
|
return to;
|
|
18
27
|
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
19
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
37
|
|
|
38
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js
|
|
39
|
+
var require_utils = __commonJS({
|
|
40
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/utils.js"(exports) {
|
|
41
|
+
"use strict";
|
|
42
|
+
var toSJISFunction;
|
|
43
|
+
var CODEWORDS_COUNT = [
|
|
44
|
+
0,
|
|
45
|
+
// Not used
|
|
46
|
+
26,
|
|
47
|
+
44,
|
|
48
|
+
70,
|
|
49
|
+
100,
|
|
50
|
+
134,
|
|
51
|
+
172,
|
|
52
|
+
196,
|
|
53
|
+
242,
|
|
54
|
+
292,
|
|
55
|
+
346,
|
|
56
|
+
404,
|
|
57
|
+
466,
|
|
58
|
+
532,
|
|
59
|
+
581,
|
|
60
|
+
655,
|
|
61
|
+
733,
|
|
62
|
+
815,
|
|
63
|
+
901,
|
|
64
|
+
991,
|
|
65
|
+
1085,
|
|
66
|
+
1156,
|
|
67
|
+
1258,
|
|
68
|
+
1364,
|
|
69
|
+
1474,
|
|
70
|
+
1588,
|
|
71
|
+
1706,
|
|
72
|
+
1828,
|
|
73
|
+
1921,
|
|
74
|
+
2051,
|
|
75
|
+
2185,
|
|
76
|
+
2323,
|
|
77
|
+
2465,
|
|
78
|
+
2611,
|
|
79
|
+
2761,
|
|
80
|
+
2876,
|
|
81
|
+
3034,
|
|
82
|
+
3196,
|
|
83
|
+
3362,
|
|
84
|
+
3532,
|
|
85
|
+
3706
|
|
86
|
+
];
|
|
87
|
+
exports.getSymbolSize = function getSymbolSize(version) {
|
|
88
|
+
if (!version) throw new Error('"version" cannot be null or undefined');
|
|
89
|
+
if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40');
|
|
90
|
+
return version * 4 + 17;
|
|
91
|
+
};
|
|
92
|
+
exports.getSymbolTotalCodewords = function getSymbolTotalCodewords(version) {
|
|
93
|
+
return CODEWORDS_COUNT[version];
|
|
94
|
+
};
|
|
95
|
+
exports.getBCHDigit = function(data) {
|
|
96
|
+
let digit = 0;
|
|
97
|
+
while (data !== 0) {
|
|
98
|
+
digit++;
|
|
99
|
+
data >>>= 1;
|
|
100
|
+
}
|
|
101
|
+
return digit;
|
|
102
|
+
};
|
|
103
|
+
exports.setToSJISFunction = function setToSJISFunction(f) {
|
|
104
|
+
if (typeof f !== "function") {
|
|
105
|
+
throw new Error('"toSJISFunc" is not a valid function.');
|
|
106
|
+
}
|
|
107
|
+
toSJISFunction = f;
|
|
108
|
+
};
|
|
109
|
+
exports.isKanjiModeEnabled = function() {
|
|
110
|
+
return typeof toSJISFunction !== "undefined";
|
|
111
|
+
};
|
|
112
|
+
exports.toSJIS = function toSJIS(kanji) {
|
|
113
|
+
return toSJISFunction(kanji);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js
|
|
119
|
+
var require_error_correction_level = __commonJS({
|
|
120
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-level.js"(exports) {
|
|
121
|
+
"use strict";
|
|
122
|
+
exports.L = { bit: 1 };
|
|
123
|
+
exports.M = { bit: 0 };
|
|
124
|
+
exports.Q = { bit: 3 };
|
|
125
|
+
exports.H = { bit: 2 };
|
|
126
|
+
function fromString(string) {
|
|
127
|
+
if (typeof string !== "string") {
|
|
128
|
+
throw new Error("Param is not a string");
|
|
129
|
+
}
|
|
130
|
+
const lcStr = string.toLowerCase();
|
|
131
|
+
switch (lcStr) {
|
|
132
|
+
case "l":
|
|
133
|
+
case "low":
|
|
134
|
+
return exports.L;
|
|
135
|
+
case "m":
|
|
136
|
+
case "medium":
|
|
137
|
+
return exports.M;
|
|
138
|
+
case "q":
|
|
139
|
+
case "quartile":
|
|
140
|
+
return exports.Q;
|
|
141
|
+
case "h":
|
|
142
|
+
case "high":
|
|
143
|
+
return exports.H;
|
|
144
|
+
default:
|
|
145
|
+
throw new Error("Unknown EC Level: " + string);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.isValid = function isValid(level) {
|
|
149
|
+
return level && typeof level.bit !== "undefined" && level.bit >= 0 && level.bit < 4;
|
|
150
|
+
};
|
|
151
|
+
exports.from = function from(value, defaultValue) {
|
|
152
|
+
if (exports.isValid(value)) {
|
|
153
|
+
return value;
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
return fromString(value);
|
|
157
|
+
} catch (e) {
|
|
158
|
+
return defaultValue;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-buffer.js
|
|
165
|
+
var require_bit_buffer = __commonJS({
|
|
166
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-buffer.js"(exports, module) {
|
|
167
|
+
"use strict";
|
|
168
|
+
function BitBuffer() {
|
|
169
|
+
this.buffer = [];
|
|
170
|
+
this.length = 0;
|
|
171
|
+
}
|
|
172
|
+
BitBuffer.prototype = {
|
|
173
|
+
get: function(index) {
|
|
174
|
+
const bufIndex = Math.floor(index / 8);
|
|
175
|
+
return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) === 1;
|
|
176
|
+
},
|
|
177
|
+
put: function(num, length) {
|
|
178
|
+
for (let i = 0; i < length; i++) {
|
|
179
|
+
this.putBit((num >>> length - i - 1 & 1) === 1);
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
getLengthInBits: function() {
|
|
183
|
+
return this.length;
|
|
184
|
+
},
|
|
185
|
+
putBit: function(bit) {
|
|
186
|
+
const bufIndex = Math.floor(this.length / 8);
|
|
187
|
+
if (this.buffer.length <= bufIndex) {
|
|
188
|
+
this.buffer.push(0);
|
|
189
|
+
}
|
|
190
|
+
if (bit) {
|
|
191
|
+
this.buffer[bufIndex] |= 128 >>> this.length % 8;
|
|
192
|
+
}
|
|
193
|
+
this.length++;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
module.exports = BitBuffer;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-matrix.js
|
|
201
|
+
var require_bit_matrix = __commonJS({
|
|
202
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/bit-matrix.js"(exports, module) {
|
|
203
|
+
"use strict";
|
|
204
|
+
function BitMatrix(size) {
|
|
205
|
+
if (!size || size < 1) {
|
|
206
|
+
throw new Error("BitMatrix size must be defined and greater than 0");
|
|
207
|
+
}
|
|
208
|
+
this.size = size;
|
|
209
|
+
this.data = new Uint8Array(size * size);
|
|
210
|
+
this.reservedBit = new Uint8Array(size * size);
|
|
211
|
+
}
|
|
212
|
+
BitMatrix.prototype.set = function(row, col, value, reserved) {
|
|
213
|
+
const index = row * this.size + col;
|
|
214
|
+
this.data[index] = value;
|
|
215
|
+
if (reserved) this.reservedBit[index] = true;
|
|
216
|
+
};
|
|
217
|
+
BitMatrix.prototype.get = function(row, col) {
|
|
218
|
+
return this.data[row * this.size + col];
|
|
219
|
+
};
|
|
220
|
+
BitMatrix.prototype.xor = function(row, col, value) {
|
|
221
|
+
this.data[row * this.size + col] ^= value;
|
|
222
|
+
};
|
|
223
|
+
BitMatrix.prototype.isReserved = function(row, col) {
|
|
224
|
+
return this.reservedBit[row * this.size + col];
|
|
225
|
+
};
|
|
226
|
+
module.exports = BitMatrix;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alignment-pattern.js
|
|
231
|
+
var require_alignment_pattern = __commonJS({
|
|
232
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alignment-pattern.js"(exports) {
|
|
233
|
+
"use strict";
|
|
234
|
+
var getSymbolSize = require_utils().getSymbolSize;
|
|
235
|
+
exports.getRowColCoords = function getRowColCoords(version) {
|
|
236
|
+
if (version === 1) return [];
|
|
237
|
+
const posCount = Math.floor(version / 7) + 2;
|
|
238
|
+
const size = getSymbolSize(version);
|
|
239
|
+
const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
|
|
240
|
+
const positions = [size - 7];
|
|
241
|
+
for (let i = 1; i < posCount - 1; i++) {
|
|
242
|
+
positions[i] = positions[i - 1] - intervals;
|
|
243
|
+
}
|
|
244
|
+
positions.push(6);
|
|
245
|
+
return positions.reverse();
|
|
246
|
+
};
|
|
247
|
+
exports.getPositions = function getPositions(version) {
|
|
248
|
+
const coords = [];
|
|
249
|
+
const pos = exports.getRowColCoords(version);
|
|
250
|
+
const posLength = pos.length;
|
|
251
|
+
for (let i = 0; i < posLength; i++) {
|
|
252
|
+
for (let j = 0; j < posLength; j++) {
|
|
253
|
+
if (i === 0 && j === 0 || // top-left
|
|
254
|
+
i === 0 && j === posLength - 1 || // bottom-left
|
|
255
|
+
i === posLength - 1 && j === 0) {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
coords.push([pos[i], pos[j]]);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return coords;
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/finder-pattern.js
|
|
267
|
+
var require_finder_pattern = __commonJS({
|
|
268
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/finder-pattern.js"(exports) {
|
|
269
|
+
"use strict";
|
|
270
|
+
var getSymbolSize = require_utils().getSymbolSize;
|
|
271
|
+
var FINDER_PATTERN_SIZE = 7;
|
|
272
|
+
exports.getPositions = function getPositions(version) {
|
|
273
|
+
const size = getSymbolSize(version);
|
|
274
|
+
return [
|
|
275
|
+
// top-left
|
|
276
|
+
[0, 0],
|
|
277
|
+
// top-right
|
|
278
|
+
[size - FINDER_PATTERN_SIZE, 0],
|
|
279
|
+
// bottom-left
|
|
280
|
+
[0, size - FINDER_PATTERN_SIZE]
|
|
281
|
+
];
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mask-pattern.js
|
|
287
|
+
var require_mask_pattern = __commonJS({
|
|
288
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mask-pattern.js"(exports) {
|
|
289
|
+
"use strict";
|
|
290
|
+
exports.Patterns = {
|
|
291
|
+
PATTERN000: 0,
|
|
292
|
+
PATTERN001: 1,
|
|
293
|
+
PATTERN010: 2,
|
|
294
|
+
PATTERN011: 3,
|
|
295
|
+
PATTERN100: 4,
|
|
296
|
+
PATTERN101: 5,
|
|
297
|
+
PATTERN110: 6,
|
|
298
|
+
PATTERN111: 7
|
|
299
|
+
};
|
|
300
|
+
var PenaltyScores = {
|
|
301
|
+
N1: 3,
|
|
302
|
+
N2: 3,
|
|
303
|
+
N3: 40,
|
|
304
|
+
N4: 10
|
|
305
|
+
};
|
|
306
|
+
exports.isValid = function isValid(mask) {
|
|
307
|
+
return mask != null && mask !== "" && !isNaN(mask) && mask >= 0 && mask <= 7;
|
|
308
|
+
};
|
|
309
|
+
exports.from = function from(value) {
|
|
310
|
+
return exports.isValid(value) ? parseInt(value, 10) : void 0;
|
|
311
|
+
};
|
|
312
|
+
exports.getPenaltyN1 = function getPenaltyN1(data) {
|
|
313
|
+
const size = data.size;
|
|
314
|
+
let points = 0;
|
|
315
|
+
let sameCountCol = 0;
|
|
316
|
+
let sameCountRow = 0;
|
|
317
|
+
let lastCol = null;
|
|
318
|
+
let lastRow = null;
|
|
319
|
+
for (let row = 0; row < size; row++) {
|
|
320
|
+
sameCountCol = sameCountRow = 0;
|
|
321
|
+
lastCol = lastRow = null;
|
|
322
|
+
for (let col = 0; col < size; col++) {
|
|
323
|
+
let module2 = data.get(row, col);
|
|
324
|
+
if (module2 === lastCol) {
|
|
325
|
+
sameCountCol++;
|
|
326
|
+
} else {
|
|
327
|
+
if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
|
|
328
|
+
lastCol = module2;
|
|
329
|
+
sameCountCol = 1;
|
|
330
|
+
}
|
|
331
|
+
module2 = data.get(col, row);
|
|
332
|
+
if (module2 === lastRow) {
|
|
333
|
+
sameCountRow++;
|
|
334
|
+
} else {
|
|
335
|
+
if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
|
|
336
|
+
lastRow = module2;
|
|
337
|
+
sameCountRow = 1;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
|
|
341
|
+
if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
|
|
342
|
+
}
|
|
343
|
+
return points;
|
|
344
|
+
};
|
|
345
|
+
exports.getPenaltyN2 = function getPenaltyN2(data) {
|
|
346
|
+
const size = data.size;
|
|
347
|
+
let points = 0;
|
|
348
|
+
for (let row = 0; row < size - 1; row++) {
|
|
349
|
+
for (let col = 0; col < size - 1; col++) {
|
|
350
|
+
const last = data.get(row, col) + data.get(row, col + 1) + data.get(row + 1, col) + data.get(row + 1, col + 1);
|
|
351
|
+
if (last === 4 || last === 0) points++;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return points * PenaltyScores.N2;
|
|
355
|
+
};
|
|
356
|
+
exports.getPenaltyN3 = function getPenaltyN3(data) {
|
|
357
|
+
const size = data.size;
|
|
358
|
+
let points = 0;
|
|
359
|
+
let bitsCol = 0;
|
|
360
|
+
let bitsRow = 0;
|
|
361
|
+
for (let row = 0; row < size; row++) {
|
|
362
|
+
bitsCol = bitsRow = 0;
|
|
363
|
+
for (let col = 0; col < size; col++) {
|
|
364
|
+
bitsCol = bitsCol << 1 & 2047 | data.get(row, col);
|
|
365
|
+
if (col >= 10 && (bitsCol === 1488 || bitsCol === 93)) points++;
|
|
366
|
+
bitsRow = bitsRow << 1 & 2047 | data.get(col, row);
|
|
367
|
+
if (col >= 10 && (bitsRow === 1488 || bitsRow === 93)) points++;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return points * PenaltyScores.N3;
|
|
371
|
+
};
|
|
372
|
+
exports.getPenaltyN4 = function getPenaltyN4(data) {
|
|
373
|
+
let darkCount = 0;
|
|
374
|
+
const modulesCount = data.data.length;
|
|
375
|
+
for (let i = 0; i < modulesCount; i++) darkCount += data.data[i];
|
|
376
|
+
const k = Math.abs(Math.ceil(darkCount * 100 / modulesCount / 5) - 10);
|
|
377
|
+
return k * PenaltyScores.N4;
|
|
378
|
+
};
|
|
379
|
+
function getMaskAt(maskPattern, i, j) {
|
|
380
|
+
switch (maskPattern) {
|
|
381
|
+
case exports.Patterns.PATTERN000:
|
|
382
|
+
return (i + j) % 2 === 0;
|
|
383
|
+
case exports.Patterns.PATTERN001:
|
|
384
|
+
return i % 2 === 0;
|
|
385
|
+
case exports.Patterns.PATTERN010:
|
|
386
|
+
return j % 3 === 0;
|
|
387
|
+
case exports.Patterns.PATTERN011:
|
|
388
|
+
return (i + j) % 3 === 0;
|
|
389
|
+
case exports.Patterns.PATTERN100:
|
|
390
|
+
return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0;
|
|
391
|
+
case exports.Patterns.PATTERN101:
|
|
392
|
+
return i * j % 2 + i * j % 3 === 0;
|
|
393
|
+
case exports.Patterns.PATTERN110:
|
|
394
|
+
return (i * j % 2 + i * j % 3) % 2 === 0;
|
|
395
|
+
case exports.Patterns.PATTERN111:
|
|
396
|
+
return (i * j % 3 + (i + j) % 2) % 2 === 0;
|
|
397
|
+
default:
|
|
398
|
+
throw new Error("bad maskPattern:" + maskPattern);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
exports.applyMask = function applyMask(pattern, data) {
|
|
402
|
+
const size = data.size;
|
|
403
|
+
for (let col = 0; col < size; col++) {
|
|
404
|
+
for (let row = 0; row < size; row++) {
|
|
405
|
+
if (data.isReserved(row, col)) continue;
|
|
406
|
+
data.xor(row, col, getMaskAt(pattern, row, col));
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
exports.getBestMask = function getBestMask(data, setupFormatFunc) {
|
|
411
|
+
const numPatterns = Object.keys(exports.Patterns).length;
|
|
412
|
+
let bestPattern = 0;
|
|
413
|
+
let lowerPenalty = Infinity;
|
|
414
|
+
for (let p = 0; p < numPatterns; p++) {
|
|
415
|
+
setupFormatFunc(p);
|
|
416
|
+
exports.applyMask(p, data);
|
|
417
|
+
const penalty = exports.getPenaltyN1(data) + exports.getPenaltyN2(data) + exports.getPenaltyN3(data) + exports.getPenaltyN4(data);
|
|
418
|
+
exports.applyMask(p, data);
|
|
419
|
+
if (penalty < lowerPenalty) {
|
|
420
|
+
lowerPenalty = penalty;
|
|
421
|
+
bestPattern = p;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return bestPattern;
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-code.js
|
|
430
|
+
var require_error_correction_code = __commonJS({
|
|
431
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/error-correction-code.js"(exports) {
|
|
432
|
+
"use strict";
|
|
433
|
+
var ECLevel = require_error_correction_level();
|
|
434
|
+
var EC_BLOCKS_TABLE = [
|
|
435
|
+
// L M Q H
|
|
436
|
+
1,
|
|
437
|
+
1,
|
|
438
|
+
1,
|
|
439
|
+
1,
|
|
440
|
+
1,
|
|
441
|
+
1,
|
|
442
|
+
1,
|
|
443
|
+
1,
|
|
444
|
+
1,
|
|
445
|
+
1,
|
|
446
|
+
2,
|
|
447
|
+
2,
|
|
448
|
+
1,
|
|
449
|
+
2,
|
|
450
|
+
2,
|
|
451
|
+
4,
|
|
452
|
+
1,
|
|
453
|
+
2,
|
|
454
|
+
4,
|
|
455
|
+
4,
|
|
456
|
+
2,
|
|
457
|
+
4,
|
|
458
|
+
4,
|
|
459
|
+
4,
|
|
460
|
+
2,
|
|
461
|
+
4,
|
|
462
|
+
6,
|
|
463
|
+
5,
|
|
464
|
+
2,
|
|
465
|
+
4,
|
|
466
|
+
6,
|
|
467
|
+
6,
|
|
468
|
+
2,
|
|
469
|
+
5,
|
|
470
|
+
8,
|
|
471
|
+
8,
|
|
472
|
+
4,
|
|
473
|
+
5,
|
|
474
|
+
8,
|
|
475
|
+
8,
|
|
476
|
+
4,
|
|
477
|
+
5,
|
|
478
|
+
8,
|
|
479
|
+
11,
|
|
480
|
+
4,
|
|
481
|
+
8,
|
|
482
|
+
10,
|
|
483
|
+
11,
|
|
484
|
+
4,
|
|
485
|
+
9,
|
|
486
|
+
12,
|
|
487
|
+
16,
|
|
488
|
+
4,
|
|
489
|
+
9,
|
|
490
|
+
16,
|
|
491
|
+
16,
|
|
492
|
+
6,
|
|
493
|
+
10,
|
|
494
|
+
12,
|
|
495
|
+
18,
|
|
496
|
+
6,
|
|
497
|
+
10,
|
|
498
|
+
17,
|
|
499
|
+
16,
|
|
500
|
+
6,
|
|
501
|
+
11,
|
|
502
|
+
16,
|
|
503
|
+
19,
|
|
504
|
+
6,
|
|
505
|
+
13,
|
|
506
|
+
18,
|
|
507
|
+
21,
|
|
508
|
+
7,
|
|
509
|
+
14,
|
|
510
|
+
21,
|
|
511
|
+
25,
|
|
512
|
+
8,
|
|
513
|
+
16,
|
|
514
|
+
20,
|
|
515
|
+
25,
|
|
516
|
+
8,
|
|
517
|
+
17,
|
|
518
|
+
23,
|
|
519
|
+
25,
|
|
520
|
+
9,
|
|
521
|
+
17,
|
|
522
|
+
23,
|
|
523
|
+
34,
|
|
524
|
+
9,
|
|
525
|
+
18,
|
|
526
|
+
25,
|
|
527
|
+
30,
|
|
528
|
+
10,
|
|
529
|
+
20,
|
|
530
|
+
27,
|
|
531
|
+
32,
|
|
532
|
+
12,
|
|
533
|
+
21,
|
|
534
|
+
29,
|
|
535
|
+
35,
|
|
536
|
+
12,
|
|
537
|
+
23,
|
|
538
|
+
34,
|
|
539
|
+
37,
|
|
540
|
+
12,
|
|
541
|
+
25,
|
|
542
|
+
34,
|
|
543
|
+
40,
|
|
544
|
+
13,
|
|
545
|
+
26,
|
|
546
|
+
35,
|
|
547
|
+
42,
|
|
548
|
+
14,
|
|
549
|
+
28,
|
|
550
|
+
38,
|
|
551
|
+
45,
|
|
552
|
+
15,
|
|
553
|
+
29,
|
|
554
|
+
40,
|
|
555
|
+
48,
|
|
556
|
+
16,
|
|
557
|
+
31,
|
|
558
|
+
43,
|
|
559
|
+
51,
|
|
560
|
+
17,
|
|
561
|
+
33,
|
|
562
|
+
45,
|
|
563
|
+
54,
|
|
564
|
+
18,
|
|
565
|
+
35,
|
|
566
|
+
48,
|
|
567
|
+
57,
|
|
568
|
+
19,
|
|
569
|
+
37,
|
|
570
|
+
51,
|
|
571
|
+
60,
|
|
572
|
+
19,
|
|
573
|
+
38,
|
|
574
|
+
53,
|
|
575
|
+
63,
|
|
576
|
+
20,
|
|
577
|
+
40,
|
|
578
|
+
56,
|
|
579
|
+
66,
|
|
580
|
+
21,
|
|
581
|
+
43,
|
|
582
|
+
59,
|
|
583
|
+
70,
|
|
584
|
+
22,
|
|
585
|
+
45,
|
|
586
|
+
62,
|
|
587
|
+
74,
|
|
588
|
+
24,
|
|
589
|
+
47,
|
|
590
|
+
65,
|
|
591
|
+
77,
|
|
592
|
+
25,
|
|
593
|
+
49,
|
|
594
|
+
68,
|
|
595
|
+
81
|
|
596
|
+
];
|
|
597
|
+
var EC_CODEWORDS_TABLE = [
|
|
598
|
+
// L M Q H
|
|
599
|
+
7,
|
|
600
|
+
10,
|
|
601
|
+
13,
|
|
602
|
+
17,
|
|
603
|
+
10,
|
|
604
|
+
16,
|
|
605
|
+
22,
|
|
606
|
+
28,
|
|
607
|
+
15,
|
|
608
|
+
26,
|
|
609
|
+
36,
|
|
610
|
+
44,
|
|
611
|
+
20,
|
|
612
|
+
36,
|
|
613
|
+
52,
|
|
614
|
+
64,
|
|
615
|
+
26,
|
|
616
|
+
48,
|
|
617
|
+
72,
|
|
618
|
+
88,
|
|
619
|
+
36,
|
|
620
|
+
64,
|
|
621
|
+
96,
|
|
622
|
+
112,
|
|
623
|
+
40,
|
|
624
|
+
72,
|
|
625
|
+
108,
|
|
626
|
+
130,
|
|
627
|
+
48,
|
|
628
|
+
88,
|
|
629
|
+
132,
|
|
630
|
+
156,
|
|
631
|
+
60,
|
|
632
|
+
110,
|
|
633
|
+
160,
|
|
634
|
+
192,
|
|
635
|
+
72,
|
|
636
|
+
130,
|
|
637
|
+
192,
|
|
638
|
+
224,
|
|
639
|
+
80,
|
|
640
|
+
150,
|
|
641
|
+
224,
|
|
642
|
+
264,
|
|
643
|
+
96,
|
|
644
|
+
176,
|
|
645
|
+
260,
|
|
646
|
+
308,
|
|
647
|
+
104,
|
|
648
|
+
198,
|
|
649
|
+
288,
|
|
650
|
+
352,
|
|
651
|
+
120,
|
|
652
|
+
216,
|
|
653
|
+
320,
|
|
654
|
+
384,
|
|
655
|
+
132,
|
|
656
|
+
240,
|
|
657
|
+
360,
|
|
658
|
+
432,
|
|
659
|
+
144,
|
|
660
|
+
280,
|
|
661
|
+
408,
|
|
662
|
+
480,
|
|
663
|
+
168,
|
|
664
|
+
308,
|
|
665
|
+
448,
|
|
666
|
+
532,
|
|
667
|
+
180,
|
|
668
|
+
338,
|
|
669
|
+
504,
|
|
670
|
+
588,
|
|
671
|
+
196,
|
|
672
|
+
364,
|
|
673
|
+
546,
|
|
674
|
+
650,
|
|
675
|
+
224,
|
|
676
|
+
416,
|
|
677
|
+
600,
|
|
678
|
+
700,
|
|
679
|
+
224,
|
|
680
|
+
442,
|
|
681
|
+
644,
|
|
682
|
+
750,
|
|
683
|
+
252,
|
|
684
|
+
476,
|
|
685
|
+
690,
|
|
686
|
+
816,
|
|
687
|
+
270,
|
|
688
|
+
504,
|
|
689
|
+
750,
|
|
690
|
+
900,
|
|
691
|
+
300,
|
|
692
|
+
560,
|
|
693
|
+
810,
|
|
694
|
+
960,
|
|
695
|
+
312,
|
|
696
|
+
588,
|
|
697
|
+
870,
|
|
698
|
+
1050,
|
|
699
|
+
336,
|
|
700
|
+
644,
|
|
701
|
+
952,
|
|
702
|
+
1110,
|
|
703
|
+
360,
|
|
704
|
+
700,
|
|
705
|
+
1020,
|
|
706
|
+
1200,
|
|
707
|
+
390,
|
|
708
|
+
728,
|
|
709
|
+
1050,
|
|
710
|
+
1260,
|
|
711
|
+
420,
|
|
712
|
+
784,
|
|
713
|
+
1140,
|
|
714
|
+
1350,
|
|
715
|
+
450,
|
|
716
|
+
812,
|
|
717
|
+
1200,
|
|
718
|
+
1440,
|
|
719
|
+
480,
|
|
720
|
+
868,
|
|
721
|
+
1290,
|
|
722
|
+
1530,
|
|
723
|
+
510,
|
|
724
|
+
924,
|
|
725
|
+
1350,
|
|
726
|
+
1620,
|
|
727
|
+
540,
|
|
728
|
+
980,
|
|
729
|
+
1440,
|
|
730
|
+
1710,
|
|
731
|
+
570,
|
|
732
|
+
1036,
|
|
733
|
+
1530,
|
|
734
|
+
1800,
|
|
735
|
+
570,
|
|
736
|
+
1064,
|
|
737
|
+
1590,
|
|
738
|
+
1890,
|
|
739
|
+
600,
|
|
740
|
+
1120,
|
|
741
|
+
1680,
|
|
742
|
+
1980,
|
|
743
|
+
630,
|
|
744
|
+
1204,
|
|
745
|
+
1770,
|
|
746
|
+
2100,
|
|
747
|
+
660,
|
|
748
|
+
1260,
|
|
749
|
+
1860,
|
|
750
|
+
2220,
|
|
751
|
+
720,
|
|
752
|
+
1316,
|
|
753
|
+
1950,
|
|
754
|
+
2310,
|
|
755
|
+
750,
|
|
756
|
+
1372,
|
|
757
|
+
2040,
|
|
758
|
+
2430
|
|
759
|
+
];
|
|
760
|
+
exports.getBlocksCount = function getBlocksCount(version, errorCorrectionLevel) {
|
|
761
|
+
switch (errorCorrectionLevel) {
|
|
762
|
+
case ECLevel.L:
|
|
763
|
+
return EC_BLOCKS_TABLE[(version - 1) * 4 + 0];
|
|
764
|
+
case ECLevel.M:
|
|
765
|
+
return EC_BLOCKS_TABLE[(version - 1) * 4 + 1];
|
|
766
|
+
case ECLevel.Q:
|
|
767
|
+
return EC_BLOCKS_TABLE[(version - 1) * 4 + 2];
|
|
768
|
+
case ECLevel.H:
|
|
769
|
+
return EC_BLOCKS_TABLE[(version - 1) * 4 + 3];
|
|
770
|
+
default:
|
|
771
|
+
return void 0;
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
exports.getTotalCodewordsCount = function getTotalCodewordsCount(version, errorCorrectionLevel) {
|
|
775
|
+
switch (errorCorrectionLevel) {
|
|
776
|
+
case ECLevel.L:
|
|
777
|
+
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0];
|
|
778
|
+
case ECLevel.M:
|
|
779
|
+
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1];
|
|
780
|
+
case ECLevel.Q:
|
|
781
|
+
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2];
|
|
782
|
+
case ECLevel.H:
|
|
783
|
+
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3];
|
|
784
|
+
default:
|
|
785
|
+
return void 0;
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/galois-field.js
|
|
792
|
+
var require_galois_field = __commonJS({
|
|
793
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/galois-field.js"(exports) {
|
|
794
|
+
"use strict";
|
|
795
|
+
var EXP_TABLE = new Uint8Array(512);
|
|
796
|
+
var LOG_TABLE = new Uint8Array(256);
|
|
797
|
+
(function initTables() {
|
|
798
|
+
let x = 1;
|
|
799
|
+
for (let i = 0; i < 255; i++) {
|
|
800
|
+
EXP_TABLE[i] = x;
|
|
801
|
+
LOG_TABLE[x] = i;
|
|
802
|
+
x <<= 1;
|
|
803
|
+
if (x & 256) {
|
|
804
|
+
x ^= 285;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
for (let i = 255; i < 512; i++) {
|
|
808
|
+
EXP_TABLE[i] = EXP_TABLE[i - 255];
|
|
809
|
+
}
|
|
810
|
+
})();
|
|
811
|
+
exports.log = function log(n) {
|
|
812
|
+
if (n < 1) throw new Error("log(" + n + ")");
|
|
813
|
+
return LOG_TABLE[n];
|
|
814
|
+
};
|
|
815
|
+
exports.exp = function exp(n) {
|
|
816
|
+
return EXP_TABLE[n];
|
|
817
|
+
};
|
|
818
|
+
exports.mul = function mul(x, y) {
|
|
819
|
+
if (x === 0 || y === 0) return 0;
|
|
820
|
+
return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]];
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/polynomial.js
|
|
826
|
+
var require_polynomial = __commonJS({
|
|
827
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/polynomial.js"(exports) {
|
|
828
|
+
"use strict";
|
|
829
|
+
var GF = require_galois_field();
|
|
830
|
+
exports.mul = function mul(p1, p2) {
|
|
831
|
+
const coeff = new Uint8Array(p1.length + p2.length - 1);
|
|
832
|
+
for (let i = 0; i < p1.length; i++) {
|
|
833
|
+
for (let j = 0; j < p2.length; j++) {
|
|
834
|
+
coeff[i + j] ^= GF.mul(p1[i], p2[j]);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
return coeff;
|
|
838
|
+
};
|
|
839
|
+
exports.mod = function mod(divident, divisor) {
|
|
840
|
+
let result = new Uint8Array(divident);
|
|
841
|
+
while (result.length - divisor.length >= 0) {
|
|
842
|
+
const coeff = result[0];
|
|
843
|
+
for (let i = 0; i < divisor.length; i++) {
|
|
844
|
+
result[i] ^= GF.mul(divisor[i], coeff);
|
|
845
|
+
}
|
|
846
|
+
let offset = 0;
|
|
847
|
+
while (offset < result.length && result[offset] === 0) offset++;
|
|
848
|
+
result = result.slice(offset);
|
|
849
|
+
}
|
|
850
|
+
return result;
|
|
851
|
+
};
|
|
852
|
+
exports.generateECPolynomial = function generateECPolynomial(degree) {
|
|
853
|
+
let poly = new Uint8Array([1]);
|
|
854
|
+
for (let i = 0; i < degree; i++) {
|
|
855
|
+
poly = exports.mul(poly, new Uint8Array([1, GF.exp(i)]));
|
|
856
|
+
}
|
|
857
|
+
return poly;
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/reed-solomon-encoder.js
|
|
863
|
+
var require_reed_solomon_encoder = __commonJS({
|
|
864
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/reed-solomon-encoder.js"(exports, module) {
|
|
865
|
+
"use strict";
|
|
866
|
+
var Polynomial = require_polynomial();
|
|
867
|
+
function ReedSolomonEncoder(degree) {
|
|
868
|
+
this.genPoly = void 0;
|
|
869
|
+
this.degree = degree;
|
|
870
|
+
if (this.degree) this.initialize(this.degree);
|
|
871
|
+
}
|
|
872
|
+
ReedSolomonEncoder.prototype.initialize = function initialize(degree) {
|
|
873
|
+
this.degree = degree;
|
|
874
|
+
this.genPoly = Polynomial.generateECPolynomial(this.degree);
|
|
875
|
+
};
|
|
876
|
+
ReedSolomonEncoder.prototype.encode = function encode(data) {
|
|
877
|
+
if (!this.genPoly) {
|
|
878
|
+
throw new Error("Encoder not initialized");
|
|
879
|
+
}
|
|
880
|
+
const paddedData = new Uint8Array(data.length + this.degree);
|
|
881
|
+
paddedData.set(data);
|
|
882
|
+
const remainder = Polynomial.mod(paddedData, this.genPoly);
|
|
883
|
+
const start = this.degree - remainder.length;
|
|
884
|
+
if (start > 0) {
|
|
885
|
+
const buff = new Uint8Array(this.degree);
|
|
886
|
+
buff.set(remainder, start);
|
|
887
|
+
return buff;
|
|
888
|
+
}
|
|
889
|
+
return remainder;
|
|
890
|
+
};
|
|
891
|
+
module.exports = ReedSolomonEncoder;
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version-check.js
|
|
896
|
+
var require_version_check = __commonJS({
|
|
897
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version-check.js"(exports) {
|
|
898
|
+
"use strict";
|
|
899
|
+
exports.isValid = function isValid(version) {
|
|
900
|
+
return !isNaN(version) && version >= 1 && version <= 40;
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/regex.js
|
|
906
|
+
var require_regex = __commonJS({
|
|
907
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/regex.js"(exports) {
|
|
908
|
+
"use strict";
|
|
909
|
+
var numeric = "[0-9]+";
|
|
910
|
+
var alphanumeric = "[A-Z $%*+\\-./:]+";
|
|
911
|
+
var kanji = "(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";
|
|
912
|
+
kanji = kanji.replace(/u/g, "\\u");
|
|
913
|
+
var byte = "(?:(?![A-Z0-9 $%*+\\-./:]|" + kanji + ")(?:.|[\r\n]))+";
|
|
914
|
+
exports.KANJI = new RegExp(kanji, "g");
|
|
915
|
+
exports.BYTE_KANJI = new RegExp("[^A-Z0-9 $%*+\\-./:]+", "g");
|
|
916
|
+
exports.BYTE = new RegExp(byte, "g");
|
|
917
|
+
exports.NUMERIC = new RegExp(numeric, "g");
|
|
918
|
+
exports.ALPHANUMERIC = new RegExp(alphanumeric, "g");
|
|
919
|
+
var TEST_KANJI = new RegExp("^" + kanji + "$");
|
|
920
|
+
var TEST_NUMERIC = new RegExp("^" + numeric + "$");
|
|
921
|
+
var TEST_ALPHANUMERIC = new RegExp("^[A-Z0-9 $%*+\\-./:]+$");
|
|
922
|
+
exports.testKanji = function testKanji(str) {
|
|
923
|
+
return TEST_KANJI.test(str);
|
|
924
|
+
};
|
|
925
|
+
exports.testNumeric = function testNumeric(str) {
|
|
926
|
+
return TEST_NUMERIC.test(str);
|
|
927
|
+
};
|
|
928
|
+
exports.testAlphanumeric = function testAlphanumeric(str) {
|
|
929
|
+
return TEST_ALPHANUMERIC.test(str);
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
|
|
934
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js
|
|
935
|
+
var require_mode = __commonJS({
|
|
936
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/mode.js"(exports) {
|
|
937
|
+
"use strict";
|
|
938
|
+
var VersionCheck = require_version_check();
|
|
939
|
+
var Regex = require_regex();
|
|
940
|
+
exports.NUMERIC = {
|
|
941
|
+
id: "Numeric",
|
|
942
|
+
bit: 1 << 0,
|
|
943
|
+
ccBits: [10, 12, 14]
|
|
944
|
+
};
|
|
945
|
+
exports.ALPHANUMERIC = {
|
|
946
|
+
id: "Alphanumeric",
|
|
947
|
+
bit: 1 << 1,
|
|
948
|
+
ccBits: [9, 11, 13]
|
|
949
|
+
};
|
|
950
|
+
exports.BYTE = {
|
|
951
|
+
id: "Byte",
|
|
952
|
+
bit: 1 << 2,
|
|
953
|
+
ccBits: [8, 16, 16]
|
|
954
|
+
};
|
|
955
|
+
exports.KANJI = {
|
|
956
|
+
id: "Kanji",
|
|
957
|
+
bit: 1 << 3,
|
|
958
|
+
ccBits: [8, 10, 12]
|
|
959
|
+
};
|
|
960
|
+
exports.MIXED = {
|
|
961
|
+
bit: -1
|
|
962
|
+
};
|
|
963
|
+
exports.getCharCountIndicator = function getCharCountIndicator(mode, version) {
|
|
964
|
+
if (!mode.ccBits) throw new Error("Invalid mode: " + mode);
|
|
965
|
+
if (!VersionCheck.isValid(version)) {
|
|
966
|
+
throw new Error("Invalid version: " + version);
|
|
967
|
+
}
|
|
968
|
+
if (version >= 1 && version < 10) return mode.ccBits[0];
|
|
969
|
+
else if (version < 27) return mode.ccBits[1];
|
|
970
|
+
return mode.ccBits[2];
|
|
971
|
+
};
|
|
972
|
+
exports.getBestModeForData = function getBestModeForData(dataStr) {
|
|
973
|
+
if (Regex.testNumeric(dataStr)) return exports.NUMERIC;
|
|
974
|
+
else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC;
|
|
975
|
+
else if (Regex.testKanji(dataStr)) return exports.KANJI;
|
|
976
|
+
else return exports.BYTE;
|
|
977
|
+
};
|
|
978
|
+
exports.toString = function toString(mode) {
|
|
979
|
+
if (mode && mode.id) return mode.id;
|
|
980
|
+
throw new Error("Invalid mode");
|
|
981
|
+
};
|
|
982
|
+
exports.isValid = function isValid(mode) {
|
|
983
|
+
return mode && mode.bit && mode.ccBits;
|
|
984
|
+
};
|
|
985
|
+
function fromString(string) {
|
|
986
|
+
if (typeof string !== "string") {
|
|
987
|
+
throw new Error("Param is not a string");
|
|
988
|
+
}
|
|
989
|
+
const lcStr = string.toLowerCase();
|
|
990
|
+
switch (lcStr) {
|
|
991
|
+
case "numeric":
|
|
992
|
+
return exports.NUMERIC;
|
|
993
|
+
case "alphanumeric":
|
|
994
|
+
return exports.ALPHANUMERIC;
|
|
995
|
+
case "kanji":
|
|
996
|
+
return exports.KANJI;
|
|
997
|
+
case "byte":
|
|
998
|
+
return exports.BYTE;
|
|
999
|
+
default:
|
|
1000
|
+
throw new Error("Unknown mode: " + string);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
exports.from = function from(value, defaultValue) {
|
|
1004
|
+
if (exports.isValid(value)) {
|
|
1005
|
+
return value;
|
|
1006
|
+
}
|
|
1007
|
+
try {
|
|
1008
|
+
return fromString(value);
|
|
1009
|
+
} catch (e) {
|
|
1010
|
+
return defaultValue;
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
}
|
|
1014
|
+
});
|
|
1015
|
+
|
|
1016
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version.js
|
|
1017
|
+
var require_version = __commonJS({
|
|
1018
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/version.js"(exports) {
|
|
1019
|
+
"use strict";
|
|
1020
|
+
var Utils = require_utils();
|
|
1021
|
+
var ECCode = require_error_correction_code();
|
|
1022
|
+
var ECLevel = require_error_correction_level();
|
|
1023
|
+
var Mode = require_mode();
|
|
1024
|
+
var VersionCheck = require_version_check();
|
|
1025
|
+
var G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
|
|
1026
|
+
var G18_BCH = Utils.getBCHDigit(G18);
|
|
1027
|
+
function getBestVersionForDataLength(mode, length, errorCorrectionLevel) {
|
|
1028
|
+
for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
|
|
1029
|
+
if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
|
|
1030
|
+
return currentVersion;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
return void 0;
|
|
1034
|
+
}
|
|
1035
|
+
function getReservedBitsCount(mode, version) {
|
|
1036
|
+
return Mode.getCharCountIndicator(mode, version) + 4;
|
|
1037
|
+
}
|
|
1038
|
+
function getTotalBitsFromDataArray(segments, version) {
|
|
1039
|
+
let totalBits = 0;
|
|
1040
|
+
segments.forEach(function(data) {
|
|
1041
|
+
const reservedBits = getReservedBitsCount(data.mode, version);
|
|
1042
|
+
totalBits += reservedBits + data.getBitsLength();
|
|
1043
|
+
});
|
|
1044
|
+
return totalBits;
|
|
1045
|
+
}
|
|
1046
|
+
function getBestVersionForMixedData(segments, errorCorrectionLevel) {
|
|
1047
|
+
for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
|
|
1048
|
+
const length = getTotalBitsFromDataArray(segments, currentVersion);
|
|
1049
|
+
if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
|
|
1050
|
+
return currentVersion;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
return void 0;
|
|
1054
|
+
}
|
|
1055
|
+
exports.from = function from(value, defaultValue) {
|
|
1056
|
+
if (VersionCheck.isValid(value)) {
|
|
1057
|
+
return parseInt(value, 10);
|
|
1058
|
+
}
|
|
1059
|
+
return defaultValue;
|
|
1060
|
+
};
|
|
1061
|
+
exports.getCapacity = function getCapacity(version, errorCorrectionLevel, mode) {
|
|
1062
|
+
if (!VersionCheck.isValid(version)) {
|
|
1063
|
+
throw new Error("Invalid QR Code version");
|
|
1064
|
+
}
|
|
1065
|
+
if (typeof mode === "undefined") mode = Mode.BYTE;
|
|
1066
|
+
const totalCodewords = Utils.getSymbolTotalCodewords(version);
|
|
1067
|
+
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
|
1068
|
+
const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
|
|
1069
|
+
if (mode === Mode.MIXED) return dataTotalCodewordsBits;
|
|
1070
|
+
const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version);
|
|
1071
|
+
switch (mode) {
|
|
1072
|
+
case Mode.NUMERIC:
|
|
1073
|
+
return Math.floor(usableBits / 10 * 3);
|
|
1074
|
+
case Mode.ALPHANUMERIC:
|
|
1075
|
+
return Math.floor(usableBits / 11 * 2);
|
|
1076
|
+
case Mode.KANJI:
|
|
1077
|
+
return Math.floor(usableBits / 13);
|
|
1078
|
+
case Mode.BYTE:
|
|
1079
|
+
default:
|
|
1080
|
+
return Math.floor(usableBits / 8);
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
exports.getBestVersionForData = function getBestVersionForData(data, errorCorrectionLevel) {
|
|
1084
|
+
let seg;
|
|
1085
|
+
const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M);
|
|
1086
|
+
if (Array.isArray(data)) {
|
|
1087
|
+
if (data.length > 1) {
|
|
1088
|
+
return getBestVersionForMixedData(data, ecl);
|
|
1089
|
+
}
|
|
1090
|
+
if (data.length === 0) {
|
|
1091
|
+
return 1;
|
|
1092
|
+
}
|
|
1093
|
+
seg = data[0];
|
|
1094
|
+
} else {
|
|
1095
|
+
seg = data;
|
|
1096
|
+
}
|
|
1097
|
+
return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl);
|
|
1098
|
+
};
|
|
1099
|
+
exports.getEncodedBits = function getEncodedBits(version) {
|
|
1100
|
+
if (!VersionCheck.isValid(version) || version < 7) {
|
|
1101
|
+
throw new Error("Invalid QR Code version");
|
|
1102
|
+
}
|
|
1103
|
+
let d = version << 12;
|
|
1104
|
+
while (Utils.getBCHDigit(d) - G18_BCH >= 0) {
|
|
1105
|
+
d ^= G18 << Utils.getBCHDigit(d) - G18_BCH;
|
|
1106
|
+
}
|
|
1107
|
+
return version << 12 | d;
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
|
|
1112
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/format-info.js
|
|
1113
|
+
var require_format_info = __commonJS({
|
|
1114
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/format-info.js"(exports) {
|
|
1115
|
+
"use strict";
|
|
1116
|
+
var Utils = require_utils();
|
|
1117
|
+
var G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
|
|
1118
|
+
var G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
|
|
1119
|
+
var G15_BCH = Utils.getBCHDigit(G15);
|
|
1120
|
+
exports.getEncodedBits = function getEncodedBits(errorCorrectionLevel, mask) {
|
|
1121
|
+
const data = errorCorrectionLevel.bit << 3 | mask;
|
|
1122
|
+
let d = data << 10;
|
|
1123
|
+
while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
|
|
1124
|
+
d ^= G15 << Utils.getBCHDigit(d) - G15_BCH;
|
|
1125
|
+
}
|
|
1126
|
+
return (data << 10 | d) ^ G15_MASK;
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
});
|
|
1130
|
+
|
|
1131
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/numeric-data.js
|
|
1132
|
+
var require_numeric_data = __commonJS({
|
|
1133
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/numeric-data.js"(exports, module) {
|
|
1134
|
+
"use strict";
|
|
1135
|
+
var Mode = require_mode();
|
|
1136
|
+
function NumericData(data) {
|
|
1137
|
+
this.mode = Mode.NUMERIC;
|
|
1138
|
+
this.data = data.toString();
|
|
1139
|
+
}
|
|
1140
|
+
NumericData.getBitsLength = function getBitsLength(length) {
|
|
1141
|
+
return 10 * Math.floor(length / 3) + (length % 3 ? length % 3 * 3 + 1 : 0);
|
|
1142
|
+
};
|
|
1143
|
+
NumericData.prototype.getLength = function getLength() {
|
|
1144
|
+
return this.data.length;
|
|
1145
|
+
};
|
|
1146
|
+
NumericData.prototype.getBitsLength = function getBitsLength() {
|
|
1147
|
+
return NumericData.getBitsLength(this.data.length);
|
|
1148
|
+
};
|
|
1149
|
+
NumericData.prototype.write = function write(bitBuffer) {
|
|
1150
|
+
let i, group, value;
|
|
1151
|
+
for (i = 0; i + 3 <= this.data.length; i += 3) {
|
|
1152
|
+
group = this.data.substr(i, 3);
|
|
1153
|
+
value = parseInt(group, 10);
|
|
1154
|
+
bitBuffer.put(value, 10);
|
|
1155
|
+
}
|
|
1156
|
+
const remainingNum = this.data.length - i;
|
|
1157
|
+
if (remainingNum > 0) {
|
|
1158
|
+
group = this.data.substr(i);
|
|
1159
|
+
value = parseInt(group, 10);
|
|
1160
|
+
bitBuffer.put(value, remainingNum * 3 + 1);
|
|
1161
|
+
}
|
|
1162
|
+
};
|
|
1163
|
+
module.exports = NumericData;
|
|
1164
|
+
}
|
|
1165
|
+
});
|
|
1166
|
+
|
|
1167
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alphanumeric-data.js
|
|
1168
|
+
var require_alphanumeric_data = __commonJS({
|
|
1169
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/alphanumeric-data.js"(exports, module) {
|
|
1170
|
+
"use strict";
|
|
1171
|
+
var Mode = require_mode();
|
|
1172
|
+
var ALPHA_NUM_CHARS = [
|
|
1173
|
+
"0",
|
|
1174
|
+
"1",
|
|
1175
|
+
"2",
|
|
1176
|
+
"3",
|
|
1177
|
+
"4",
|
|
1178
|
+
"5",
|
|
1179
|
+
"6",
|
|
1180
|
+
"7",
|
|
1181
|
+
"8",
|
|
1182
|
+
"9",
|
|
1183
|
+
"A",
|
|
1184
|
+
"B",
|
|
1185
|
+
"C",
|
|
1186
|
+
"D",
|
|
1187
|
+
"E",
|
|
1188
|
+
"F",
|
|
1189
|
+
"G",
|
|
1190
|
+
"H",
|
|
1191
|
+
"I",
|
|
1192
|
+
"J",
|
|
1193
|
+
"K",
|
|
1194
|
+
"L",
|
|
1195
|
+
"M",
|
|
1196
|
+
"N",
|
|
1197
|
+
"O",
|
|
1198
|
+
"P",
|
|
1199
|
+
"Q",
|
|
1200
|
+
"R",
|
|
1201
|
+
"S",
|
|
1202
|
+
"T",
|
|
1203
|
+
"U",
|
|
1204
|
+
"V",
|
|
1205
|
+
"W",
|
|
1206
|
+
"X",
|
|
1207
|
+
"Y",
|
|
1208
|
+
"Z",
|
|
1209
|
+
" ",
|
|
1210
|
+
"$",
|
|
1211
|
+
"%",
|
|
1212
|
+
"*",
|
|
1213
|
+
"+",
|
|
1214
|
+
"-",
|
|
1215
|
+
".",
|
|
1216
|
+
"/",
|
|
1217
|
+
":"
|
|
1218
|
+
];
|
|
1219
|
+
function AlphanumericData(data) {
|
|
1220
|
+
this.mode = Mode.ALPHANUMERIC;
|
|
1221
|
+
this.data = data;
|
|
1222
|
+
}
|
|
1223
|
+
AlphanumericData.getBitsLength = function getBitsLength(length) {
|
|
1224
|
+
return 11 * Math.floor(length / 2) + 6 * (length % 2);
|
|
1225
|
+
};
|
|
1226
|
+
AlphanumericData.prototype.getLength = function getLength() {
|
|
1227
|
+
return this.data.length;
|
|
1228
|
+
};
|
|
1229
|
+
AlphanumericData.prototype.getBitsLength = function getBitsLength() {
|
|
1230
|
+
return AlphanumericData.getBitsLength(this.data.length);
|
|
1231
|
+
};
|
|
1232
|
+
AlphanumericData.prototype.write = function write(bitBuffer) {
|
|
1233
|
+
let i;
|
|
1234
|
+
for (i = 0; i + 2 <= this.data.length; i += 2) {
|
|
1235
|
+
let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45;
|
|
1236
|
+
value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]);
|
|
1237
|
+
bitBuffer.put(value, 11);
|
|
1238
|
+
}
|
|
1239
|
+
if (this.data.length % 2) {
|
|
1240
|
+
bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);
|
|
1241
|
+
}
|
|
1242
|
+
};
|
|
1243
|
+
module.exports = AlphanumericData;
|
|
1244
|
+
}
|
|
1245
|
+
});
|
|
1246
|
+
|
|
1247
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/byte-data.js
|
|
1248
|
+
var require_byte_data = __commonJS({
|
|
1249
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/byte-data.js"(exports, module) {
|
|
1250
|
+
"use strict";
|
|
1251
|
+
var Mode = require_mode();
|
|
1252
|
+
function ByteData(data) {
|
|
1253
|
+
this.mode = Mode.BYTE;
|
|
1254
|
+
if (typeof data === "string") {
|
|
1255
|
+
this.data = new TextEncoder().encode(data);
|
|
1256
|
+
} else {
|
|
1257
|
+
this.data = new Uint8Array(data);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
ByteData.getBitsLength = function getBitsLength(length) {
|
|
1261
|
+
return length * 8;
|
|
1262
|
+
};
|
|
1263
|
+
ByteData.prototype.getLength = function getLength() {
|
|
1264
|
+
return this.data.length;
|
|
1265
|
+
};
|
|
1266
|
+
ByteData.prototype.getBitsLength = function getBitsLength() {
|
|
1267
|
+
return ByteData.getBitsLength(this.data.length);
|
|
1268
|
+
};
|
|
1269
|
+
ByteData.prototype.write = function(bitBuffer) {
|
|
1270
|
+
for (let i = 0, l = this.data.length; i < l; i++) {
|
|
1271
|
+
bitBuffer.put(this.data[i], 8);
|
|
1272
|
+
}
|
|
1273
|
+
};
|
|
1274
|
+
module.exports = ByteData;
|
|
1275
|
+
}
|
|
1276
|
+
});
|
|
1277
|
+
|
|
1278
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/kanji-data.js
|
|
1279
|
+
var require_kanji_data = __commonJS({
|
|
1280
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/kanji-data.js"(exports, module) {
|
|
1281
|
+
"use strict";
|
|
1282
|
+
var Mode = require_mode();
|
|
1283
|
+
var Utils = require_utils();
|
|
1284
|
+
function KanjiData(data) {
|
|
1285
|
+
this.mode = Mode.KANJI;
|
|
1286
|
+
this.data = data;
|
|
1287
|
+
}
|
|
1288
|
+
KanjiData.getBitsLength = function getBitsLength(length) {
|
|
1289
|
+
return length * 13;
|
|
1290
|
+
};
|
|
1291
|
+
KanjiData.prototype.getLength = function getLength() {
|
|
1292
|
+
return this.data.length;
|
|
1293
|
+
};
|
|
1294
|
+
KanjiData.prototype.getBitsLength = function getBitsLength() {
|
|
1295
|
+
return KanjiData.getBitsLength(this.data.length);
|
|
1296
|
+
};
|
|
1297
|
+
KanjiData.prototype.write = function(bitBuffer) {
|
|
1298
|
+
let i;
|
|
1299
|
+
for (i = 0; i < this.data.length; i++) {
|
|
1300
|
+
let value = Utils.toSJIS(this.data[i]);
|
|
1301
|
+
if (value >= 33088 && value <= 40956) {
|
|
1302
|
+
value -= 33088;
|
|
1303
|
+
} else if (value >= 57408 && value <= 60351) {
|
|
1304
|
+
value -= 49472;
|
|
1305
|
+
} else {
|
|
1306
|
+
throw new Error(
|
|
1307
|
+
"Invalid SJIS character: " + this.data[i] + "\nMake sure your charset is UTF-8"
|
|
1308
|
+
);
|
|
1309
|
+
}
|
|
1310
|
+
value = (value >>> 8 & 255) * 192 + (value & 255);
|
|
1311
|
+
bitBuffer.put(value, 13);
|
|
1312
|
+
}
|
|
1313
|
+
};
|
|
1314
|
+
module.exports = KanjiData;
|
|
1315
|
+
}
|
|
1316
|
+
});
|
|
1317
|
+
|
|
1318
|
+
// ../../node_modules/.pnpm/dijkstrajs@1.0.3/node_modules/dijkstrajs/dijkstra.js
|
|
1319
|
+
var require_dijkstra = __commonJS({
|
|
1320
|
+
"../../node_modules/.pnpm/dijkstrajs@1.0.3/node_modules/dijkstrajs/dijkstra.js"(exports, module) {
|
|
1321
|
+
"use strict";
|
|
1322
|
+
var dijkstra = {
|
|
1323
|
+
single_source_shortest_paths: function(graph, s, d) {
|
|
1324
|
+
var predecessors = {};
|
|
1325
|
+
var costs = {};
|
|
1326
|
+
costs[s] = 0;
|
|
1327
|
+
var open = dijkstra.PriorityQueue.make();
|
|
1328
|
+
open.push(s, 0);
|
|
1329
|
+
var closest, u, v, cost_of_s_to_u, adjacent_nodes, cost_of_e, cost_of_s_to_u_plus_cost_of_e, cost_of_s_to_v, first_visit;
|
|
1330
|
+
while (!open.empty()) {
|
|
1331
|
+
closest = open.pop();
|
|
1332
|
+
u = closest.value;
|
|
1333
|
+
cost_of_s_to_u = closest.cost;
|
|
1334
|
+
adjacent_nodes = graph[u] || {};
|
|
1335
|
+
for (v in adjacent_nodes) {
|
|
1336
|
+
if (adjacent_nodes.hasOwnProperty(v)) {
|
|
1337
|
+
cost_of_e = adjacent_nodes[v];
|
|
1338
|
+
cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
|
|
1339
|
+
cost_of_s_to_v = costs[v];
|
|
1340
|
+
first_visit = typeof costs[v] === "undefined";
|
|
1341
|
+
if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
|
|
1342
|
+
costs[v] = cost_of_s_to_u_plus_cost_of_e;
|
|
1343
|
+
open.push(v, cost_of_s_to_u_plus_cost_of_e);
|
|
1344
|
+
predecessors[v] = u;
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
if (typeof d !== "undefined" && typeof costs[d] === "undefined") {
|
|
1350
|
+
var msg = ["Could not find a path from ", s, " to ", d, "."].join("");
|
|
1351
|
+
throw new Error(msg);
|
|
1352
|
+
}
|
|
1353
|
+
return predecessors;
|
|
1354
|
+
},
|
|
1355
|
+
extract_shortest_path_from_predecessor_list: function(predecessors, d) {
|
|
1356
|
+
var nodes = [];
|
|
1357
|
+
var u = d;
|
|
1358
|
+
var predecessor;
|
|
1359
|
+
while (u) {
|
|
1360
|
+
nodes.push(u);
|
|
1361
|
+
predecessor = predecessors[u];
|
|
1362
|
+
u = predecessors[u];
|
|
1363
|
+
}
|
|
1364
|
+
nodes.reverse();
|
|
1365
|
+
return nodes;
|
|
1366
|
+
},
|
|
1367
|
+
find_path: function(graph, s, d) {
|
|
1368
|
+
var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
|
|
1369
|
+
return dijkstra.extract_shortest_path_from_predecessor_list(
|
|
1370
|
+
predecessors,
|
|
1371
|
+
d
|
|
1372
|
+
);
|
|
1373
|
+
},
|
|
1374
|
+
/**
|
|
1375
|
+
* A very naive priority queue implementation.
|
|
1376
|
+
*/
|
|
1377
|
+
PriorityQueue: {
|
|
1378
|
+
make: function(opts) {
|
|
1379
|
+
var T = dijkstra.PriorityQueue, t = {}, key;
|
|
1380
|
+
opts = opts || {};
|
|
1381
|
+
for (key in T) {
|
|
1382
|
+
if (T.hasOwnProperty(key)) {
|
|
1383
|
+
t[key] = T[key];
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
t.queue = [];
|
|
1387
|
+
t.sorter = opts.sorter || T.default_sorter;
|
|
1388
|
+
return t;
|
|
1389
|
+
},
|
|
1390
|
+
default_sorter: function(a, b) {
|
|
1391
|
+
return a.cost - b.cost;
|
|
1392
|
+
},
|
|
1393
|
+
/**
|
|
1394
|
+
* Add a new item to the queue and ensure the highest priority element
|
|
1395
|
+
* is at the front of the queue.
|
|
1396
|
+
*/
|
|
1397
|
+
push: function(value, cost) {
|
|
1398
|
+
var item = { value, cost };
|
|
1399
|
+
this.queue.push(item);
|
|
1400
|
+
this.queue.sort(this.sorter);
|
|
1401
|
+
},
|
|
1402
|
+
/**
|
|
1403
|
+
* Return the highest priority element in the queue.
|
|
1404
|
+
*/
|
|
1405
|
+
pop: function() {
|
|
1406
|
+
return this.queue.shift();
|
|
1407
|
+
},
|
|
1408
|
+
empty: function() {
|
|
1409
|
+
return this.queue.length === 0;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
};
|
|
1413
|
+
if (typeof module !== "undefined") {
|
|
1414
|
+
module.exports = dijkstra;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
});
|
|
1418
|
+
|
|
1419
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/segments.js
|
|
1420
|
+
var require_segments = __commonJS({
|
|
1421
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/segments.js"(exports) {
|
|
1422
|
+
"use strict";
|
|
1423
|
+
var Mode = require_mode();
|
|
1424
|
+
var NumericData = require_numeric_data();
|
|
1425
|
+
var AlphanumericData = require_alphanumeric_data();
|
|
1426
|
+
var ByteData = require_byte_data();
|
|
1427
|
+
var KanjiData = require_kanji_data();
|
|
1428
|
+
var Regex = require_regex();
|
|
1429
|
+
var Utils = require_utils();
|
|
1430
|
+
var dijkstra = require_dijkstra();
|
|
1431
|
+
function getStringByteLength(str) {
|
|
1432
|
+
return unescape(encodeURIComponent(str)).length;
|
|
1433
|
+
}
|
|
1434
|
+
function getSegments(regex, mode, str) {
|
|
1435
|
+
const segments = [];
|
|
1436
|
+
let result;
|
|
1437
|
+
while ((result = regex.exec(str)) !== null) {
|
|
1438
|
+
segments.push({
|
|
1439
|
+
data: result[0],
|
|
1440
|
+
index: result.index,
|
|
1441
|
+
mode,
|
|
1442
|
+
length: result[0].length
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
return segments;
|
|
1446
|
+
}
|
|
1447
|
+
function getSegmentsFromString(dataStr) {
|
|
1448
|
+
const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr);
|
|
1449
|
+
const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr);
|
|
1450
|
+
let byteSegs;
|
|
1451
|
+
let kanjiSegs;
|
|
1452
|
+
if (Utils.isKanjiModeEnabled()) {
|
|
1453
|
+
byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr);
|
|
1454
|
+
kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr);
|
|
1455
|
+
} else {
|
|
1456
|
+
byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr);
|
|
1457
|
+
kanjiSegs = [];
|
|
1458
|
+
}
|
|
1459
|
+
const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
|
|
1460
|
+
return segs.sort(function(s1, s2) {
|
|
1461
|
+
return s1.index - s2.index;
|
|
1462
|
+
}).map(function(obj) {
|
|
1463
|
+
return {
|
|
1464
|
+
data: obj.data,
|
|
1465
|
+
mode: obj.mode,
|
|
1466
|
+
length: obj.length
|
|
1467
|
+
};
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
function getSegmentBitsLength(length, mode) {
|
|
1471
|
+
switch (mode) {
|
|
1472
|
+
case Mode.NUMERIC:
|
|
1473
|
+
return NumericData.getBitsLength(length);
|
|
1474
|
+
case Mode.ALPHANUMERIC:
|
|
1475
|
+
return AlphanumericData.getBitsLength(length);
|
|
1476
|
+
case Mode.KANJI:
|
|
1477
|
+
return KanjiData.getBitsLength(length);
|
|
1478
|
+
case Mode.BYTE:
|
|
1479
|
+
return ByteData.getBitsLength(length);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
function mergeSegments(segs) {
|
|
1483
|
+
return segs.reduce(function(acc, curr) {
|
|
1484
|
+
const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
|
|
1485
|
+
if (prevSeg && prevSeg.mode === curr.mode) {
|
|
1486
|
+
acc[acc.length - 1].data += curr.data;
|
|
1487
|
+
return acc;
|
|
1488
|
+
}
|
|
1489
|
+
acc.push(curr);
|
|
1490
|
+
return acc;
|
|
1491
|
+
}, []);
|
|
1492
|
+
}
|
|
1493
|
+
function buildNodes(segs) {
|
|
1494
|
+
const nodes = [];
|
|
1495
|
+
for (let i = 0; i < segs.length; i++) {
|
|
1496
|
+
const seg = segs[i];
|
|
1497
|
+
switch (seg.mode) {
|
|
1498
|
+
case Mode.NUMERIC:
|
|
1499
|
+
nodes.push([
|
|
1500
|
+
seg,
|
|
1501
|
+
{ data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
|
|
1502
|
+
{ data: seg.data, mode: Mode.BYTE, length: seg.length }
|
|
1503
|
+
]);
|
|
1504
|
+
break;
|
|
1505
|
+
case Mode.ALPHANUMERIC:
|
|
1506
|
+
nodes.push([
|
|
1507
|
+
seg,
|
|
1508
|
+
{ data: seg.data, mode: Mode.BYTE, length: seg.length }
|
|
1509
|
+
]);
|
|
1510
|
+
break;
|
|
1511
|
+
case Mode.KANJI:
|
|
1512
|
+
nodes.push([
|
|
1513
|
+
seg,
|
|
1514
|
+
{ data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
|
|
1515
|
+
]);
|
|
1516
|
+
break;
|
|
1517
|
+
case Mode.BYTE:
|
|
1518
|
+
nodes.push([
|
|
1519
|
+
{ data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
|
|
1520
|
+
]);
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
return nodes;
|
|
1524
|
+
}
|
|
1525
|
+
function buildGraph(nodes, version) {
|
|
1526
|
+
const table = {};
|
|
1527
|
+
const graph = { start: {} };
|
|
1528
|
+
let prevNodeIds = ["start"];
|
|
1529
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
1530
|
+
const nodeGroup = nodes[i];
|
|
1531
|
+
const currentNodeIds = [];
|
|
1532
|
+
for (let j = 0; j < nodeGroup.length; j++) {
|
|
1533
|
+
const node = nodeGroup[j];
|
|
1534
|
+
const key = "" + i + j;
|
|
1535
|
+
currentNodeIds.push(key);
|
|
1536
|
+
table[key] = { node, lastCount: 0 };
|
|
1537
|
+
graph[key] = {};
|
|
1538
|
+
for (let n = 0; n < prevNodeIds.length; n++) {
|
|
1539
|
+
const prevNodeId = prevNodeIds[n];
|
|
1540
|
+
if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
|
|
1541
|
+
graph[prevNodeId][key] = getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) - getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
|
|
1542
|
+
table[prevNodeId].lastCount += node.length;
|
|
1543
|
+
} else {
|
|
1544
|
+
if (table[prevNodeId]) table[prevNodeId].lastCount = node.length;
|
|
1545
|
+
graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) + 4 + Mode.getCharCountIndicator(node.mode, version);
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
prevNodeIds = currentNodeIds;
|
|
1550
|
+
}
|
|
1551
|
+
for (let n = 0; n < prevNodeIds.length; n++) {
|
|
1552
|
+
graph[prevNodeIds[n]].end = 0;
|
|
1553
|
+
}
|
|
1554
|
+
return { map: graph, table };
|
|
1555
|
+
}
|
|
1556
|
+
function buildSingleSegment(data, modesHint) {
|
|
1557
|
+
let mode;
|
|
1558
|
+
const bestMode = Mode.getBestModeForData(data);
|
|
1559
|
+
mode = Mode.from(modesHint, bestMode);
|
|
1560
|
+
if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
|
|
1561
|
+
throw new Error('"' + data + '" cannot be encoded with mode ' + Mode.toString(mode) + ".\n Suggested mode is: " + Mode.toString(bestMode));
|
|
1562
|
+
}
|
|
1563
|
+
if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
|
|
1564
|
+
mode = Mode.BYTE;
|
|
1565
|
+
}
|
|
1566
|
+
switch (mode) {
|
|
1567
|
+
case Mode.NUMERIC:
|
|
1568
|
+
return new NumericData(data);
|
|
1569
|
+
case Mode.ALPHANUMERIC:
|
|
1570
|
+
return new AlphanumericData(data);
|
|
1571
|
+
case Mode.KANJI:
|
|
1572
|
+
return new KanjiData(data);
|
|
1573
|
+
case Mode.BYTE:
|
|
1574
|
+
return new ByteData(data);
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
exports.fromArray = function fromArray(array) {
|
|
1578
|
+
return array.reduce(function(acc, seg) {
|
|
1579
|
+
if (typeof seg === "string") {
|
|
1580
|
+
acc.push(buildSingleSegment(seg, null));
|
|
1581
|
+
} else if (seg.data) {
|
|
1582
|
+
acc.push(buildSingleSegment(seg.data, seg.mode));
|
|
1583
|
+
}
|
|
1584
|
+
return acc;
|
|
1585
|
+
}, []);
|
|
1586
|
+
};
|
|
1587
|
+
exports.fromString = function fromString(data, version) {
|
|
1588
|
+
const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled());
|
|
1589
|
+
const nodes = buildNodes(segs);
|
|
1590
|
+
const graph = buildGraph(nodes, version);
|
|
1591
|
+
const path = dijkstra.find_path(graph.map, "start", "end");
|
|
1592
|
+
const optimizedSegs = [];
|
|
1593
|
+
for (let i = 1; i < path.length - 1; i++) {
|
|
1594
|
+
optimizedSegs.push(graph.table[path[i]].node);
|
|
1595
|
+
}
|
|
1596
|
+
return exports.fromArray(mergeSegments(optimizedSegs));
|
|
1597
|
+
};
|
|
1598
|
+
exports.rawSplit = function rawSplit(data) {
|
|
1599
|
+
return exports.fromArray(
|
|
1600
|
+
getSegmentsFromString(data, Utils.isKanjiModeEnabled())
|
|
1601
|
+
);
|
|
1602
|
+
};
|
|
1603
|
+
}
|
|
1604
|
+
});
|
|
1605
|
+
|
|
1606
|
+
// ../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/qrcode.js
|
|
1607
|
+
var require_qrcode = __commonJS({
|
|
1608
|
+
"../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/core/qrcode.js"(exports) {
|
|
1609
|
+
"use strict";
|
|
1610
|
+
var Utils = require_utils();
|
|
1611
|
+
var ECLevel = require_error_correction_level();
|
|
1612
|
+
var BitBuffer = require_bit_buffer();
|
|
1613
|
+
var BitMatrix = require_bit_matrix();
|
|
1614
|
+
var AlignmentPattern = require_alignment_pattern();
|
|
1615
|
+
var FinderPattern = require_finder_pattern();
|
|
1616
|
+
var MaskPattern = require_mask_pattern();
|
|
1617
|
+
var ECCode = require_error_correction_code();
|
|
1618
|
+
var ReedSolomonEncoder = require_reed_solomon_encoder();
|
|
1619
|
+
var Version = require_version();
|
|
1620
|
+
var FormatInfo = require_format_info();
|
|
1621
|
+
var Mode = require_mode();
|
|
1622
|
+
var Segments = require_segments();
|
|
1623
|
+
function setupFinderPattern(matrix, version) {
|
|
1624
|
+
const size = matrix.size;
|
|
1625
|
+
const pos = FinderPattern.getPositions(version);
|
|
1626
|
+
for (let i = 0; i < pos.length; i++) {
|
|
1627
|
+
const row = pos[i][0];
|
|
1628
|
+
const col = pos[i][1];
|
|
1629
|
+
for (let r = -1; r <= 7; r++) {
|
|
1630
|
+
if (row + r <= -1 || size <= row + r) continue;
|
|
1631
|
+
for (let c = -1; c <= 7; c++) {
|
|
1632
|
+
if (col + c <= -1 || size <= col + c) continue;
|
|
1633
|
+
if (r >= 0 && r <= 6 && (c === 0 || c === 6) || c >= 0 && c <= 6 && (r === 0 || r === 6) || r >= 2 && r <= 4 && c >= 2 && c <= 4) {
|
|
1634
|
+
matrix.set(row + r, col + c, true, true);
|
|
1635
|
+
} else {
|
|
1636
|
+
matrix.set(row + r, col + c, false, true);
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
function setupTimingPattern(matrix) {
|
|
1643
|
+
const size = matrix.size;
|
|
1644
|
+
for (let r = 8; r < size - 8; r++) {
|
|
1645
|
+
const value = r % 2 === 0;
|
|
1646
|
+
matrix.set(r, 6, value, true);
|
|
1647
|
+
matrix.set(6, r, value, true);
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
function setupAlignmentPattern(matrix, version) {
|
|
1651
|
+
const pos = AlignmentPattern.getPositions(version);
|
|
1652
|
+
for (let i = 0; i < pos.length; i++) {
|
|
1653
|
+
const row = pos[i][0];
|
|
1654
|
+
const col = pos[i][1];
|
|
1655
|
+
for (let r = -2; r <= 2; r++) {
|
|
1656
|
+
for (let c = -2; c <= 2; c++) {
|
|
1657
|
+
if (r === -2 || r === 2 || c === -2 || c === 2 || r === 0 && c === 0) {
|
|
1658
|
+
matrix.set(row + r, col + c, true, true);
|
|
1659
|
+
} else {
|
|
1660
|
+
matrix.set(row + r, col + c, false, true);
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
function setupVersionInfo(matrix, version) {
|
|
1667
|
+
const size = matrix.size;
|
|
1668
|
+
const bits = Version.getEncodedBits(version);
|
|
1669
|
+
let row, col, mod;
|
|
1670
|
+
for (let i = 0; i < 18; i++) {
|
|
1671
|
+
row = Math.floor(i / 3);
|
|
1672
|
+
col = i % 3 + size - 8 - 3;
|
|
1673
|
+
mod = (bits >> i & 1) === 1;
|
|
1674
|
+
matrix.set(row, col, mod, true);
|
|
1675
|
+
matrix.set(col, row, mod, true);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
function setupFormatInfo(matrix, errorCorrectionLevel, maskPattern) {
|
|
1679
|
+
const size = matrix.size;
|
|
1680
|
+
const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
|
|
1681
|
+
let i, mod;
|
|
1682
|
+
for (i = 0; i < 15; i++) {
|
|
1683
|
+
mod = (bits >> i & 1) === 1;
|
|
1684
|
+
if (i < 6) {
|
|
1685
|
+
matrix.set(i, 8, mod, true);
|
|
1686
|
+
} else if (i < 8) {
|
|
1687
|
+
matrix.set(i + 1, 8, mod, true);
|
|
1688
|
+
} else {
|
|
1689
|
+
matrix.set(size - 15 + i, 8, mod, true);
|
|
1690
|
+
}
|
|
1691
|
+
if (i < 8) {
|
|
1692
|
+
matrix.set(8, size - i - 1, mod, true);
|
|
1693
|
+
} else if (i < 9) {
|
|
1694
|
+
matrix.set(8, 15 - i - 1 + 1, mod, true);
|
|
1695
|
+
} else {
|
|
1696
|
+
matrix.set(8, 15 - i - 1, mod, true);
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
matrix.set(size - 8, 8, 1, true);
|
|
1700
|
+
}
|
|
1701
|
+
function setupData(matrix, data) {
|
|
1702
|
+
const size = matrix.size;
|
|
1703
|
+
let inc = -1;
|
|
1704
|
+
let row = size - 1;
|
|
1705
|
+
let bitIndex = 7;
|
|
1706
|
+
let byteIndex = 0;
|
|
1707
|
+
for (let col = size - 1; col > 0; col -= 2) {
|
|
1708
|
+
if (col === 6) col--;
|
|
1709
|
+
while (true) {
|
|
1710
|
+
for (let c = 0; c < 2; c++) {
|
|
1711
|
+
if (!matrix.isReserved(row, col - c)) {
|
|
1712
|
+
let dark = false;
|
|
1713
|
+
if (byteIndex < data.length) {
|
|
1714
|
+
dark = (data[byteIndex] >>> bitIndex & 1) === 1;
|
|
1715
|
+
}
|
|
1716
|
+
matrix.set(row, col - c, dark);
|
|
1717
|
+
bitIndex--;
|
|
1718
|
+
if (bitIndex === -1) {
|
|
1719
|
+
byteIndex++;
|
|
1720
|
+
bitIndex = 7;
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
row += inc;
|
|
1725
|
+
if (row < 0 || size <= row) {
|
|
1726
|
+
row -= inc;
|
|
1727
|
+
inc = -inc;
|
|
1728
|
+
break;
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
function createData(version, errorCorrectionLevel, segments) {
|
|
1734
|
+
const buffer = new BitBuffer();
|
|
1735
|
+
segments.forEach(function(data) {
|
|
1736
|
+
buffer.put(data.mode.bit, 4);
|
|
1737
|
+
buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version));
|
|
1738
|
+
data.write(buffer);
|
|
1739
|
+
});
|
|
1740
|
+
const totalCodewords = Utils.getSymbolTotalCodewords(version);
|
|
1741
|
+
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
|
1742
|
+
const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
|
|
1743
|
+
if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
|
|
1744
|
+
buffer.put(0, 4);
|
|
1745
|
+
}
|
|
1746
|
+
while (buffer.getLengthInBits() % 8 !== 0) {
|
|
1747
|
+
buffer.putBit(0);
|
|
1748
|
+
}
|
|
1749
|
+
const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
|
|
1750
|
+
for (let i = 0; i < remainingByte; i++) {
|
|
1751
|
+
buffer.put(i % 2 ? 17 : 236, 8);
|
|
1752
|
+
}
|
|
1753
|
+
return createCodewords(buffer, version, errorCorrectionLevel);
|
|
1754
|
+
}
|
|
1755
|
+
function createCodewords(bitBuffer, version, errorCorrectionLevel) {
|
|
1756
|
+
const totalCodewords = Utils.getSymbolTotalCodewords(version);
|
|
1757
|
+
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
|
1758
|
+
const dataTotalCodewords = totalCodewords - ecTotalCodewords;
|
|
1759
|
+
const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel);
|
|
1760
|
+
const blocksInGroup2 = totalCodewords % ecTotalBlocks;
|
|
1761
|
+
const blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
|
|
1762
|
+
const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
|
|
1763
|
+
const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
|
|
1764
|
+
const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1;
|
|
1765
|
+
const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1;
|
|
1766
|
+
const rs = new ReedSolomonEncoder(ecCount);
|
|
1767
|
+
let offset = 0;
|
|
1768
|
+
const dcData = new Array(ecTotalBlocks);
|
|
1769
|
+
const ecData = new Array(ecTotalBlocks);
|
|
1770
|
+
let maxDataSize = 0;
|
|
1771
|
+
const buffer = new Uint8Array(bitBuffer.buffer);
|
|
1772
|
+
for (let b = 0; b < ecTotalBlocks; b++) {
|
|
1773
|
+
const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2;
|
|
1774
|
+
dcData[b] = buffer.slice(offset, offset + dataSize);
|
|
1775
|
+
ecData[b] = rs.encode(dcData[b]);
|
|
1776
|
+
offset += dataSize;
|
|
1777
|
+
maxDataSize = Math.max(maxDataSize, dataSize);
|
|
1778
|
+
}
|
|
1779
|
+
const data = new Uint8Array(totalCodewords);
|
|
1780
|
+
let index = 0;
|
|
1781
|
+
let i, r;
|
|
1782
|
+
for (i = 0; i < maxDataSize; i++) {
|
|
1783
|
+
for (r = 0; r < ecTotalBlocks; r++) {
|
|
1784
|
+
if (i < dcData[r].length) {
|
|
1785
|
+
data[index++] = dcData[r][i];
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
for (i = 0; i < ecCount; i++) {
|
|
1790
|
+
for (r = 0; r < ecTotalBlocks; r++) {
|
|
1791
|
+
data[index++] = ecData[r][i];
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
return data;
|
|
1795
|
+
}
|
|
1796
|
+
function createSymbol(data, version, errorCorrectionLevel, maskPattern) {
|
|
1797
|
+
let segments;
|
|
1798
|
+
if (Array.isArray(data)) {
|
|
1799
|
+
segments = Segments.fromArray(data);
|
|
1800
|
+
} else if (typeof data === "string") {
|
|
1801
|
+
let estimatedVersion = version;
|
|
1802
|
+
if (!estimatedVersion) {
|
|
1803
|
+
const rawSegments = Segments.rawSplit(data);
|
|
1804
|
+
estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel);
|
|
1805
|
+
}
|
|
1806
|
+
segments = Segments.fromString(data, estimatedVersion || 40);
|
|
1807
|
+
} else {
|
|
1808
|
+
throw new Error("Invalid data");
|
|
1809
|
+
}
|
|
1810
|
+
const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel);
|
|
1811
|
+
if (!bestVersion) {
|
|
1812
|
+
throw new Error("The amount of data is too big to be stored in a QR Code");
|
|
1813
|
+
}
|
|
1814
|
+
if (!version) {
|
|
1815
|
+
version = bestVersion;
|
|
1816
|
+
} else if (version < bestVersion) {
|
|
1817
|
+
throw new Error(
|
|
1818
|
+
"\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: " + bestVersion + ".\n"
|
|
1819
|
+
);
|
|
1820
|
+
}
|
|
1821
|
+
const dataBits = createData(version, errorCorrectionLevel, segments);
|
|
1822
|
+
const moduleCount = Utils.getSymbolSize(version);
|
|
1823
|
+
const modules = new BitMatrix(moduleCount);
|
|
1824
|
+
setupFinderPattern(modules, version);
|
|
1825
|
+
setupTimingPattern(modules);
|
|
1826
|
+
setupAlignmentPattern(modules, version);
|
|
1827
|
+
setupFormatInfo(modules, errorCorrectionLevel, 0);
|
|
1828
|
+
if (version >= 7) {
|
|
1829
|
+
setupVersionInfo(modules, version);
|
|
1830
|
+
}
|
|
1831
|
+
setupData(modules, dataBits);
|
|
1832
|
+
if (isNaN(maskPattern)) {
|
|
1833
|
+
maskPattern = MaskPattern.getBestMask(
|
|
1834
|
+
modules,
|
|
1835
|
+
setupFormatInfo.bind(null, modules, errorCorrectionLevel)
|
|
1836
|
+
);
|
|
1837
|
+
}
|
|
1838
|
+
MaskPattern.applyMask(maskPattern, modules);
|
|
1839
|
+
setupFormatInfo(modules, errorCorrectionLevel, maskPattern);
|
|
1840
|
+
return {
|
|
1841
|
+
modules,
|
|
1842
|
+
version,
|
|
1843
|
+
errorCorrectionLevel,
|
|
1844
|
+
maskPattern,
|
|
1845
|
+
segments
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
exports.create = function create(data, options) {
|
|
1849
|
+
if (typeof data === "undefined" || data === "") {
|
|
1850
|
+
throw new Error("No input text");
|
|
1851
|
+
}
|
|
1852
|
+
let errorCorrectionLevel = ECLevel.M;
|
|
1853
|
+
let version;
|
|
1854
|
+
let mask;
|
|
1855
|
+
if (typeof options !== "undefined") {
|
|
1856
|
+
errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M);
|
|
1857
|
+
version = Version.from(options.version);
|
|
1858
|
+
mask = MaskPattern.from(options.maskPattern);
|
|
1859
|
+
if (options.toSJISFunc) {
|
|
1860
|
+
Utils.setToSJISFunction(options.toSJISFunc);
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
return createSymbol(data, version, errorCorrectionLevel, mask);
|
|
1864
|
+
};
|
|
1865
|
+
}
|
|
1866
|
+
});
|
|
1867
|
+
|
|
21
1868
|
// src/index.ts
|
|
22
1869
|
var src_exports = {};
|
|
23
1870
|
__export(src_exports, {
|
|
@@ -36,6 +1883,7 @@ var EudiVerify = (() => {
|
|
|
36
1883
|
});
|
|
37
1884
|
|
|
38
1885
|
// ../client/dist/index.js
|
|
1886
|
+
var import_qrcode = __toESM(require_qrcode(), 1);
|
|
39
1887
|
var TERMINAL_STATUSES = Object.freeze([
|
|
40
1888
|
"verified",
|
|
41
1889
|
"rejected",
|
|
@@ -75,7 +1923,10 @@ var EudiVerify = (() => {
|
|
|
75
1923
|
var SessionNotFoundError = class extends ApiResponseError {
|
|
76
1924
|
sessionId;
|
|
77
1925
|
constructor(sessionId) {
|
|
78
|
-
super(404, {
|
|
1926
|
+
super(404, {
|
|
1927
|
+
error: "not_found",
|
|
1928
|
+
message: `Session ${sessionId} not found`
|
|
1929
|
+
});
|
|
79
1930
|
this.name = "SessionNotFoundError";
|
|
80
1931
|
this.sessionId = sessionId;
|
|
81
1932
|
}
|
|
@@ -121,7 +1972,10 @@ var EudiVerify = (() => {
|
|
|
121
1972
|
if (error.name === "AbortError") {
|
|
122
1973
|
throw new NetworkError(`Request timeout after ${timeoutMs}ms`);
|
|
123
1974
|
}
|
|
124
|
-
throw new NetworkError(
|
|
1975
|
+
throw new NetworkError(
|
|
1976
|
+
`Network request failed: ${error.message}`,
|
|
1977
|
+
error
|
|
1978
|
+
);
|
|
125
1979
|
}
|
|
126
1980
|
throw new NetworkError("Unknown network error");
|
|
127
1981
|
}
|
|
@@ -152,10 +2006,15 @@ var EudiVerify = (() => {
|
|
|
152
2006
|
}
|
|
153
2007
|
return {
|
|
154
2008
|
async createSession(verificationRequest) {
|
|
155
|
-
return request("POST", "/sessions", {
|
|
2009
|
+
return request("POST", "/sessions", {
|
|
2010
|
+
request: verificationRequest
|
|
2011
|
+
});
|
|
156
2012
|
},
|
|
157
2013
|
async getSession(sessionId) {
|
|
158
|
-
return request(
|
|
2014
|
+
return request(
|
|
2015
|
+
"GET",
|
|
2016
|
+
`/sessions/${encodeURIComponent(sessionId)}`
|
|
2017
|
+
);
|
|
159
2018
|
},
|
|
160
2019
|
async cancelSession(sessionId) {
|
|
161
2020
|
return request(
|
|
@@ -216,422 +2075,24 @@ var EudiVerify = (() => {
|
|
|
216
2075
|
}
|
|
217
2076
|
};
|
|
218
2077
|
}
|
|
219
|
-
var EC_LEVELS = { L: 0, M: 1, Q: 2, H: 3 };
|
|
220
|
-
var VERSION_TABLE = {
|
|
221
|
-
L: [
|
|
222
|
-
{ version: 1, totalCodewords: 19, ecCodewordsPerBlock: 7, numBlocks: 1 },
|
|
223
|
-
{ version: 2, totalCodewords: 34, ecCodewordsPerBlock: 10, numBlocks: 1 },
|
|
224
|
-
{ version: 3, totalCodewords: 55, ecCodewordsPerBlock: 15, numBlocks: 1 },
|
|
225
|
-
{ version: 4, totalCodewords: 80, ecCodewordsPerBlock: 20, numBlocks: 1 },
|
|
226
|
-
{ version: 5, totalCodewords: 108, ecCodewordsPerBlock: 26, numBlocks: 1 },
|
|
227
|
-
{ version: 6, totalCodewords: 136, ecCodewordsPerBlock: 18, numBlocks: 2 },
|
|
228
|
-
{ version: 7, totalCodewords: 156, ecCodewordsPerBlock: 20, numBlocks: 2 },
|
|
229
|
-
{ version: 8, totalCodewords: 194, ecCodewordsPerBlock: 24, numBlocks: 2 },
|
|
230
|
-
{ version: 9, totalCodewords: 232, ecCodewordsPerBlock: 30, numBlocks: 2 },
|
|
231
|
-
{ version: 10, totalCodewords: 274, ecCodewordsPerBlock: 18, numBlocks: 4 },
|
|
232
|
-
{ version: 11, totalCodewords: 401, ecCodewordsPerBlock: 20, numBlocks: 4 },
|
|
233
|
-
{ version: 12, totalCodewords: 466, ecCodewordsPerBlock: 24, numBlocks: 4 },
|
|
234
|
-
{ version: 13, totalCodewords: 532, ecCodewordsPerBlock: 26, numBlocks: 4 },
|
|
235
|
-
{ version: 14, totalCodewords: 588, ecCodewordsPerBlock: 30, numBlocks: 4 }
|
|
236
|
-
],
|
|
237
|
-
M: [
|
|
238
|
-
{ version: 1, totalCodewords: 16, ecCodewordsPerBlock: 10, numBlocks: 1 },
|
|
239
|
-
{ version: 2, totalCodewords: 28, ecCodewordsPerBlock: 16, numBlocks: 1 },
|
|
240
|
-
{ version: 3, totalCodewords: 44, ecCodewordsPerBlock: 26, numBlocks: 1 },
|
|
241
|
-
{ version: 4, totalCodewords: 64, ecCodewordsPerBlock: 18, numBlocks: 2 },
|
|
242
|
-
{ version: 5, totalCodewords: 86, ecCodewordsPerBlock: 24, numBlocks: 2 },
|
|
243
|
-
{ version: 6, totalCodewords: 108, ecCodewordsPerBlock: 16, numBlocks: 4 },
|
|
244
|
-
{ version: 7, totalCodewords: 124, ecCodewordsPerBlock: 18, numBlocks: 4 },
|
|
245
|
-
{ version: 8, totalCodewords: 154, ecCodewordsPerBlock: 22, numBlocks: 4 },
|
|
246
|
-
{ version: 9, totalCodewords: 182, ecCodewordsPerBlock: 22, numBlocks: 5 },
|
|
247
|
-
{ version: 10, totalCodewords: 216, ecCodewordsPerBlock: 26, numBlocks: 5 }
|
|
248
|
-
],
|
|
249
|
-
Q: [
|
|
250
|
-
{ version: 1, totalCodewords: 13, ecCodewordsPerBlock: 13, numBlocks: 1 },
|
|
251
|
-
{ version: 2, totalCodewords: 22, ecCodewordsPerBlock: 22, numBlocks: 1 },
|
|
252
|
-
{ version: 3, totalCodewords: 34, ecCodewordsPerBlock: 18, numBlocks: 2 },
|
|
253
|
-
{ version: 4, totalCodewords: 48, ecCodewordsPerBlock: 26, numBlocks: 2 },
|
|
254
|
-
{ version: 5, totalCodewords: 62, ecCodewordsPerBlock: 18, numBlocks: 4 },
|
|
255
|
-
{ version: 6, totalCodewords: 76, ecCodewordsPerBlock: 24, numBlocks: 4 },
|
|
256
|
-
{ version: 7, totalCodewords: 88, ecCodewordsPerBlock: 18, numBlocks: 6 },
|
|
257
|
-
{ version: 8, totalCodewords: 110, ecCodewordsPerBlock: 22, numBlocks: 6 },
|
|
258
|
-
{ version: 9, totalCodewords: 132, ecCodewordsPerBlock: 20, numBlocks: 8 },
|
|
259
|
-
{ version: 10, totalCodewords: 154, ecCodewordsPerBlock: 24, numBlocks: 8 }
|
|
260
|
-
],
|
|
261
|
-
H: [
|
|
262
|
-
{ version: 1, totalCodewords: 9, ecCodewordsPerBlock: 17, numBlocks: 1 },
|
|
263
|
-
{ version: 2, totalCodewords: 16, ecCodewordsPerBlock: 28, numBlocks: 1 },
|
|
264
|
-
{ version: 3, totalCodewords: 26, ecCodewordsPerBlock: 22, numBlocks: 2 },
|
|
265
|
-
{ version: 4, totalCodewords: 36, ecCodewordsPerBlock: 16, numBlocks: 4 },
|
|
266
|
-
{ version: 5, totalCodewords: 46, ecCodewordsPerBlock: 22, numBlocks: 4 },
|
|
267
|
-
{ version: 6, totalCodewords: 60, ecCodewordsPerBlock: 28, numBlocks: 4 },
|
|
268
|
-
{ version: 7, totalCodewords: 66, ecCodewordsPerBlock: 26, numBlocks: 5 },
|
|
269
|
-
{ version: 8, totalCodewords: 86, ecCodewordsPerBlock: 26, numBlocks: 6 },
|
|
270
|
-
{ version: 9, totalCodewords: 100, ecCodewordsPerBlock: 24, numBlocks: 8 },
|
|
271
|
-
{ version: 10, totalCodewords: 122, ecCodewordsPerBlock: 28, numBlocks: 8 }
|
|
272
|
-
]
|
|
273
|
-
};
|
|
274
|
-
var FORMAT_INFO_STRINGS = {
|
|
275
|
-
0: [1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0],
|
|
276
|
-
1: [1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1],
|
|
277
|
-
2: [1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0],
|
|
278
|
-
3: [1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1],
|
|
279
|
-
4: [1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1],
|
|
280
|
-
5: [1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0],
|
|
281
|
-
6: [1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1],
|
|
282
|
-
7: [1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0],
|
|
283
|
-
8: [1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0],
|
|
284
|
-
9: [1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1],
|
|
285
|
-
10: [1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0],
|
|
286
|
-
11: [1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1],
|
|
287
|
-
12: [1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1],
|
|
288
|
-
13: [1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0],
|
|
289
|
-
14: [1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1],
|
|
290
|
-
15: [1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0],
|
|
291
|
-
16: [0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1],
|
|
292
|
-
17: [0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0],
|
|
293
|
-
18: [0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1],
|
|
294
|
-
19: [0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0],
|
|
295
|
-
20: [0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0],
|
|
296
|
-
21: [0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1],
|
|
297
|
-
22: [0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0],
|
|
298
|
-
23: [0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1],
|
|
299
|
-
24: [0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1],
|
|
300
|
-
25: [0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0],
|
|
301
|
-
26: [0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1],
|
|
302
|
-
27: [0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0],
|
|
303
|
-
28: [0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0],
|
|
304
|
-
29: [0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1],
|
|
305
|
-
30: [0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0],
|
|
306
|
-
31: [0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1]
|
|
307
|
-
};
|
|
308
|
-
var ALIGNMENT_PATTERNS = [
|
|
309
|
-
[],
|
|
310
|
-
[],
|
|
311
|
-
[6, 18],
|
|
312
|
-
[6, 22],
|
|
313
|
-
[6, 26],
|
|
314
|
-
[6, 30],
|
|
315
|
-
[6, 34],
|
|
316
|
-
[6, 22, 38],
|
|
317
|
-
[6, 24, 42],
|
|
318
|
-
[6, 26, 46],
|
|
319
|
-
[6, 28, 50],
|
|
320
|
-
[6, 30, 54],
|
|
321
|
-
[6, 32, 58],
|
|
322
|
-
[6, 34, 62],
|
|
323
|
-
[6, 26, 46, 66]
|
|
324
|
-
];
|
|
325
|
-
function getVersionInfo(dataLength, ecLevel) {
|
|
326
|
-
const table = VERSION_TABLE[ecLevel];
|
|
327
|
-
for (const info of table) {
|
|
328
|
-
const dataCodewords = info.totalCodewords - info.ecCodewordsPerBlock * info.numBlocks;
|
|
329
|
-
const maxBytes = dataCodewords - (info.version < 10 ? 2 : 3);
|
|
330
|
-
if (maxBytes >= dataLength) {
|
|
331
|
-
return info;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
throw new Error(`Data too long for QR code (max ~270 bytes with ${ecLevel} EC)`);
|
|
335
|
-
}
|
|
336
|
-
function createByteData(data, version) {
|
|
337
|
-
const bytes = new TextEncoder().encode(data);
|
|
338
|
-
const bits = [];
|
|
339
|
-
bits.push(0, 1, 0, 0);
|
|
340
|
-
const countBits = version < 10 ? 8 : 16;
|
|
341
|
-
for (let i = countBits - 1; i >= 0; i--) {
|
|
342
|
-
bits.push(bytes.length >> i & 1);
|
|
343
|
-
}
|
|
344
|
-
for (const byte of bytes) {
|
|
345
|
-
for (let i = 7; i >= 0; i--) {
|
|
346
|
-
bits.push(byte >> i & 1);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
bits.push(0, 0, 0, 0);
|
|
350
|
-
while (bits.length % 8 !== 0) {
|
|
351
|
-
bits.push(0);
|
|
352
|
-
}
|
|
353
|
-
const codewords = [];
|
|
354
|
-
for (let i = 0; i < bits.length; i += 8) {
|
|
355
|
-
let byte = 0;
|
|
356
|
-
for (let j = 0; j < 8; j++) {
|
|
357
|
-
byte = byte << 1 | (bits[i + j] ?? 0);
|
|
358
|
-
}
|
|
359
|
-
codewords.push(byte);
|
|
360
|
-
}
|
|
361
|
-
return codewords;
|
|
362
|
-
}
|
|
363
|
-
var GF_EXP = new Uint8Array(512);
|
|
364
|
-
var GF_LOG = new Uint8Array(256);
|
|
365
|
-
(function initGaloisField() {
|
|
366
|
-
let x = 1;
|
|
367
|
-
for (let i = 0; i < 255; i++) {
|
|
368
|
-
GF_EXP[i] = x;
|
|
369
|
-
GF_LOG[x] = i;
|
|
370
|
-
x <<= 1;
|
|
371
|
-
if (x & 256) x ^= 285;
|
|
372
|
-
}
|
|
373
|
-
for (let i = 255; i < 512; i++) {
|
|
374
|
-
GF_EXP[i] = GF_EXP[i - 255];
|
|
375
|
-
}
|
|
376
|
-
})();
|
|
377
|
-
function gfMul(a, b) {
|
|
378
|
-
if (a === 0 || b === 0) return 0;
|
|
379
|
-
return GF_EXP[GF_LOG[a] + GF_LOG[b]];
|
|
380
|
-
}
|
|
381
|
-
function generateECCodewords(data, numECCodewords) {
|
|
382
|
-
const gen = [1];
|
|
383
|
-
for (let i = 0; i < numECCodewords; i++) {
|
|
384
|
-
const newGen = new Array(gen.length + 1).fill(0);
|
|
385
|
-
for (let j = 0; j < gen.length; j++) {
|
|
386
|
-
newGen[j] ^= gen[j];
|
|
387
|
-
newGen[j + 1] ^= gfMul(gen[j], GF_EXP[i]);
|
|
388
|
-
}
|
|
389
|
-
gen.length = newGen.length;
|
|
390
|
-
for (let j = 0; j < newGen.length; j++) gen[j] = newGen[j];
|
|
391
|
-
}
|
|
392
|
-
const msg = [...data, ...new Array(numECCodewords).fill(0)];
|
|
393
|
-
for (let i = 0; i < data.length; i++) {
|
|
394
|
-
const coef = msg[i];
|
|
395
|
-
if (coef !== 0) {
|
|
396
|
-
for (let j = 0; j < gen.length; j++) {
|
|
397
|
-
msg[i + j] ^= gfMul(gen[j], coef);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
return msg.slice(data.length);
|
|
402
|
-
}
|
|
403
|
-
function interleaveBlocks(dataCodewords, info) {
|
|
404
|
-
const { numBlocks, ecCodewordsPerBlock, totalCodewords } = info;
|
|
405
|
-
const totalDataCodewords = totalCodewords - numBlocks * ecCodewordsPerBlock;
|
|
406
|
-
const smallBlockSize = Math.floor(totalDataCodewords / numBlocks);
|
|
407
|
-
const largeBlockCount = totalDataCodewords % numBlocks;
|
|
408
|
-
const dataBlocks = [];
|
|
409
|
-
const ecBlocks = [];
|
|
410
|
-
let offset = 0;
|
|
411
|
-
for (let i = 0; i < numBlocks; i++) {
|
|
412
|
-
const blockSize = smallBlockSize + (i >= numBlocks - largeBlockCount ? 1 : 0);
|
|
413
|
-
const block = dataCodewords.slice(offset, offset + blockSize);
|
|
414
|
-
offset += blockSize;
|
|
415
|
-
dataBlocks.push(block);
|
|
416
|
-
ecBlocks.push(generateECCodewords(block, ecCodewordsPerBlock));
|
|
417
|
-
}
|
|
418
|
-
const result = [];
|
|
419
|
-
const maxDataLen = Math.max(...dataBlocks.map((b) => b.length));
|
|
420
|
-
for (let i = 0; i < maxDataLen; i++) {
|
|
421
|
-
for (const block of dataBlocks) {
|
|
422
|
-
if (i < block.length) result.push(block[i]);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
for (let i = 0; i < ecCodewordsPerBlock; i++) {
|
|
426
|
-
for (const block of ecBlocks) {
|
|
427
|
-
result.push(block[i]);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
return result;
|
|
431
|
-
}
|
|
432
|
-
function createMatrix(version) {
|
|
433
|
-
const size = version * 4 + 17;
|
|
434
|
-
const matrix = Array.from(
|
|
435
|
-
{ length: size },
|
|
436
|
-
() => new Array(size).fill(null)
|
|
437
|
-
);
|
|
438
|
-
function setFinderPattern(row, col) {
|
|
439
|
-
for (let r = -1; r <= 7; r++) {
|
|
440
|
-
for (let c = -1; c <= 7; c++) {
|
|
441
|
-
const nr = row + r;
|
|
442
|
-
const nc = col + c;
|
|
443
|
-
if (nr < 0 || nr >= size || nc < 0 || nc >= size) continue;
|
|
444
|
-
const isOuter = r === -1 || r === 7 || c === -1 || c === 7;
|
|
445
|
-
const isInner = r >= 1 && r <= 5 && c >= 1 && c <= 5;
|
|
446
|
-
const isCore = r >= 2 && r <= 4 && c >= 2 && c <= 4;
|
|
447
|
-
matrix[nr][nc] = isOuter ? 0 : isCore ? 1 : isInner ? 0 : 1;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
setFinderPattern(0, 0);
|
|
452
|
-
setFinderPattern(0, size - 7);
|
|
453
|
-
setFinderPattern(size - 7, 0);
|
|
454
|
-
for (let i = 8; i < size - 8; i++) {
|
|
455
|
-
matrix[6][i] = i % 2 === 0 ? 1 : 0;
|
|
456
|
-
matrix[i][6] = i % 2 === 0 ? 1 : 0;
|
|
457
|
-
}
|
|
458
|
-
matrix[size - 8][8] = 1;
|
|
459
|
-
if (version >= 2) {
|
|
460
|
-
const positions = ALIGNMENT_PATTERNS[version];
|
|
461
|
-
for (const row of positions) {
|
|
462
|
-
for (const col of positions) {
|
|
463
|
-
if (matrix[row][col] !== null) continue;
|
|
464
|
-
for (let r = -2; r <= 2; r++) {
|
|
465
|
-
for (let c = -2; c <= 2; c++) {
|
|
466
|
-
const isOuter = Math.abs(r) === 2 || Math.abs(c) === 2;
|
|
467
|
-
const isCore = r === 0 && c === 0;
|
|
468
|
-
matrix[row + r][col + c] = isOuter || isCore ? 1 : 0;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
return matrix;
|
|
475
|
-
}
|
|
476
|
-
function placeData(matrix, codewords) {
|
|
477
|
-
const size = matrix.length;
|
|
478
|
-
let bitIndex = 0;
|
|
479
|
-
const bits = [];
|
|
480
|
-
for (const cw of codewords) {
|
|
481
|
-
for (let i = 7; i >= 0; i--) {
|
|
482
|
-
bits.push(cw >> i & 1);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
let col = size - 1;
|
|
486
|
-
let goingUp = true;
|
|
487
|
-
while (col > 0) {
|
|
488
|
-
if (col === 6) col--;
|
|
489
|
-
for (let row = goingUp ? size - 1 : 0; goingUp ? row >= 0 : row < size; row += goingUp ? -1 : 1) {
|
|
490
|
-
for (const offset of [0, -1]) {
|
|
491
|
-
const c = col + offset;
|
|
492
|
-
if (c < 0 || matrix[row][c] !== null) continue;
|
|
493
|
-
matrix[row][c] = bitIndex < bits.length ? bits[bitIndex++] : 0;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
col -= 2;
|
|
497
|
-
goingUp = !goingUp;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
function applyMask(matrix, maskPattern) {
|
|
501
|
-
const size = matrix.length;
|
|
502
|
-
const maskFns = [
|
|
503
|
-
(r, c) => (r + c) % 2 === 0,
|
|
504
|
-
(r) => r % 2 === 0,
|
|
505
|
-
(_, c) => c % 3 === 0,
|
|
506
|
-
(r, c) => (r + c) % 3 === 0,
|
|
507
|
-
(r, c) => (Math.floor(r / 2) + Math.floor(c / 3)) % 2 === 0,
|
|
508
|
-
(r, c) => r * c % 2 + r * c % 3 === 0,
|
|
509
|
-
(r, c) => (r * c % 2 + r * c % 3) % 2 === 0,
|
|
510
|
-
(r, c) => ((r + c) % 2 + r * c % 3) % 2 === 0
|
|
511
|
-
];
|
|
512
|
-
const maskFn = maskFns[maskPattern];
|
|
513
|
-
const reserved = createReservedMask(size);
|
|
514
|
-
for (let r = 0; r < size; r++) {
|
|
515
|
-
for (let c = 0; c < size; c++) {
|
|
516
|
-
if (!reserved[r][c] && maskFn(r, c)) {
|
|
517
|
-
matrix[r][c] ^= 1;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
function createReservedMask(size) {
|
|
523
|
-
const reserved = Array.from(
|
|
524
|
-
{ length: size },
|
|
525
|
-
() => new Array(size).fill(false)
|
|
526
|
-
);
|
|
527
|
-
for (let i = 0; i < 8; i++) {
|
|
528
|
-
for (let j = 0; j < 8; j++) {
|
|
529
|
-
reserved[i][j] = true;
|
|
530
|
-
reserved[i][size - 8 + j] = true;
|
|
531
|
-
reserved[size - 8 + i][j] = true;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
for (let i = 0; i < 9; i++) {
|
|
535
|
-
reserved[i][8] = true;
|
|
536
|
-
reserved[8][i] = true;
|
|
537
|
-
reserved[size - 8 + i - 1][8] = true;
|
|
538
|
-
reserved[8][size - 8 + i - 1] = true;
|
|
539
|
-
}
|
|
540
|
-
for (let i = 0; i < size; i++) {
|
|
541
|
-
reserved[6][i] = true;
|
|
542
|
-
reserved[i][6] = true;
|
|
543
|
-
}
|
|
544
|
-
return reserved;
|
|
545
|
-
}
|
|
546
|
-
function addFormatInfo(matrix, ecLevel, maskPattern) {
|
|
547
|
-
const formatIndex = EC_LEVELS[ecLevel] * 8 + maskPattern;
|
|
548
|
-
const bits = FORMAT_INFO_STRINGS[formatIndex];
|
|
549
|
-
const size = matrix.length;
|
|
550
|
-
for (let i = 0; i < 6; i++) {
|
|
551
|
-
matrix[8][i] = bits[i];
|
|
552
|
-
matrix[i][8] = bits[14 - i];
|
|
553
|
-
}
|
|
554
|
-
matrix[8][7] = bits[6];
|
|
555
|
-
matrix[8][8] = bits[7];
|
|
556
|
-
matrix[7][8] = bits[8];
|
|
557
|
-
for (let i = 0; i < 7; i++) {
|
|
558
|
-
matrix[8][size - 1 - i] = bits[14 - i];
|
|
559
|
-
matrix[size - 1 - i][8] = bits[i];
|
|
560
|
-
}
|
|
561
|
-
matrix[size - 8][8] = bits[7];
|
|
562
|
-
}
|
|
563
|
-
function evaluatePenalty(matrix) {
|
|
564
|
-
const size = matrix.length;
|
|
565
|
-
let penalty = 0;
|
|
566
|
-
for (let r = 0; r < size; r++) {
|
|
567
|
-
let count = 1;
|
|
568
|
-
for (let c = 1; c < size; c++) {
|
|
569
|
-
if (matrix[r][c] === matrix[r][c - 1]) {
|
|
570
|
-
count++;
|
|
571
|
-
if (count === 5) penalty += 3;
|
|
572
|
-
else if (count > 5) penalty++;
|
|
573
|
-
} else {
|
|
574
|
-
count = 1;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
for (let c = 0; c < size; c++) {
|
|
579
|
-
let count = 1;
|
|
580
|
-
for (let r = 1; r < size; r++) {
|
|
581
|
-
if (matrix[r][c] === matrix[r - 1][c]) {
|
|
582
|
-
count++;
|
|
583
|
-
if (count === 5) penalty += 3;
|
|
584
|
-
else if (count > 5) penalty++;
|
|
585
|
-
} else {
|
|
586
|
-
count = 1;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
return penalty;
|
|
591
|
-
}
|
|
592
|
-
function generateQRMatrix(data, ecLevel) {
|
|
593
|
-
const info = getVersionInfo(data.length, ecLevel);
|
|
594
|
-
const dataCodewords = createByteData(data, info.version);
|
|
595
|
-
const totalDataCodewords = info.totalCodewords - info.numBlocks * info.ecCodewordsPerBlock;
|
|
596
|
-
while (dataCodewords.length < totalDataCodewords) {
|
|
597
|
-
dataCodewords.push(dataCodewords.length % 2 === 0 ? 236 : 17);
|
|
598
|
-
}
|
|
599
|
-
const codewords = interleaveBlocks(dataCodewords, info);
|
|
600
|
-
const baseMatrix = createMatrix(info.version);
|
|
601
|
-
placeData(baseMatrix, codewords);
|
|
602
|
-
let bestMatrix = null;
|
|
603
|
-
let bestPenalty = Infinity;
|
|
604
|
-
for (let mask = 0; mask < 8; mask++) {
|
|
605
|
-
const matrix = baseMatrix.map(
|
|
606
|
-
(row) => row.map((cell) => cell === null ? 0 : cell)
|
|
607
|
-
);
|
|
608
|
-
applyMask(matrix, mask);
|
|
609
|
-
addFormatInfo(matrix, ecLevel, mask);
|
|
610
|
-
const penalty = evaluatePenalty(matrix);
|
|
611
|
-
if (penalty < bestPenalty) {
|
|
612
|
-
bestPenalty = penalty;
|
|
613
|
-
bestMatrix = matrix;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
return bestMatrix;
|
|
617
|
-
}
|
|
618
2078
|
function generateQRSvg(data, options = {}) {
|
|
619
2079
|
const { size = 200, errorCorrection = "L", quietZone = 4 } = options;
|
|
620
|
-
const
|
|
621
|
-
const moduleCount =
|
|
2080
|
+
const qr = (0, import_qrcode.create)(data, { errorCorrectionLevel: errorCorrection });
|
|
2081
|
+
const moduleCount = qr.modules.size;
|
|
622
2082
|
const totalModules = moduleCount + quietZone * 2;
|
|
623
|
-
const
|
|
2083
|
+
const modulePx = Math.max(1, Math.floor(size / totalModules));
|
|
2084
|
+
const pad = Math.floor((size - modulePx * totalModules) / 2);
|
|
624
2085
|
let paths = "";
|
|
625
2086
|
for (let r = 0; r < moduleCount; r++) {
|
|
626
2087
|
for (let c = 0; c < moduleCount; c++) {
|
|
627
|
-
if (
|
|
628
|
-
const x = (c + quietZone) *
|
|
629
|
-
const y = (r + quietZone) *
|
|
630
|
-
paths += `M${x},${y}h${
|
|
2088
|
+
if (qr.modules.get(r, c)) {
|
|
2089
|
+
const x = pad + (c + quietZone) * modulePx;
|
|
2090
|
+
const y = pad + (r + quietZone) * modulePx;
|
|
2091
|
+
paths += `M${x},${y}h${modulePx}v${modulePx}h-${modulePx}z`;
|
|
631
2092
|
}
|
|
632
2093
|
}
|
|
633
2094
|
}
|
|
634
|
-
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}" width="${size}" height="${size}"><rect width="100%" height="100%" fill="white"/><path d="${paths}" fill="black"/></svg>`;
|
|
2095
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}" width="${size}" height="${size}" shape-rendering="crispEdges"><rect width="100%" height="100%" fill="white"/><path d="${paths}" fill="black"/></svg>`;
|
|
635
2096
|
}
|
|
636
2097
|
function generateQRDataUrl(data, options = {}) {
|
|
637
2098
|
const svg = generateQRSvg(data, options);
|
|
@@ -640,7 +2101,10 @@ var EudiVerify = (() => {
|
|
|
640
2101
|
}
|
|
641
2102
|
function createVerification(config) {
|
|
642
2103
|
const { apiUrl, polling, qr, fetch: fetchFn } = config;
|
|
643
|
-
const client = createApiClient({
|
|
2104
|
+
const client = createApiClient({
|
|
2105
|
+
baseUrl: apiUrl,
|
|
2106
|
+
fetch: fetchFn
|
|
2107
|
+
});
|
|
644
2108
|
const subscribers = /* @__PURE__ */ new Set();
|
|
645
2109
|
let currentState = { status: "idle" };
|
|
646
2110
|
let currentSessionId = null;
|
|
@@ -681,7 +2145,10 @@ var EudiVerify = (() => {
|
|
|
681
2145
|
case "cancelled":
|
|
682
2146
|
return { status: "idle" };
|
|
683
2147
|
case "error":
|
|
684
|
-
return {
|
|
2148
|
+
return {
|
|
2149
|
+
status: "error",
|
|
2150
|
+
error: session.error ?? "Verification failed"
|
|
2151
|
+
};
|
|
685
2152
|
default:
|
|
686
2153
|
return { status: "error", error: "Unknown session status" };
|
|
687
2154
|
}
|
|
@@ -1209,7 +2676,7 @@ var EudiVerify = (() => {
|
|
|
1209
2676
|
<div class="eudi-error">
|
|
1210
2677
|
${ERROR_ICON}
|
|
1211
2678
|
<p class="eudi-error-text">Verification declined</p>
|
|
1212
|
-
<p class="eudi-error-detail"></p>
|
|
2679
|
+
<p id="eudi-rejected-detail" class="eudi-error-detail"></p>
|
|
1213
2680
|
<button class="eudi-retry-btn" type="button" data-action="reset">Try again</button>
|
|
1214
2681
|
</div>
|
|
1215
2682
|
</div>
|
|
@@ -1238,7 +2705,7 @@ var EudiVerify = (() => {
|
|
|
1238
2705
|
<div class="eudi-error">
|
|
1239
2706
|
${ERROR_ICON}
|
|
1240
2707
|
<p class="eudi-error-text">Verification failed</p>
|
|
1241
|
-
<p class="eudi-error-detail"></p>
|
|
2708
|
+
<p id="eudi-error-state-detail" class="eudi-error-detail"></p>
|
|
1242
2709
|
<button class="eudi-retry-btn" type="button" data-action="reset">Try again</button>
|
|
1243
2710
|
</div>
|
|
1244
2711
|
</div>
|
|
@@ -1291,16 +2758,42 @@ var EudiVerify = (() => {
|
|
|
1291
2758
|
}
|
|
1292
2759
|
}
|
|
1293
2760
|
if (state.status === "rejected" && "error" in state && state.error) {
|
|
1294
|
-
const detail = container.querySelector(
|
|
2761
|
+
const detail = container.querySelector(
|
|
2762
|
+
`#${getStateId("rejected")} #eudi-rejected-detail`
|
|
2763
|
+
);
|
|
1295
2764
|
if (detail) {
|
|
1296
2765
|
detail.textContent = state.error;
|
|
1297
2766
|
}
|
|
2767
|
+
wireRetryDescribedBy(
|
|
2768
|
+
container,
|
|
2769
|
+
getStateId("rejected"),
|
|
2770
|
+
"eudi-rejected-detail"
|
|
2771
|
+
);
|
|
1298
2772
|
}
|
|
1299
2773
|
if (state.status === "error" && "error" in state) {
|
|
1300
|
-
const detail = container.querySelector(
|
|
2774
|
+
const detail = container.querySelector(
|
|
2775
|
+
`#${getStateId("error")} #eudi-error-state-detail`
|
|
2776
|
+
);
|
|
1301
2777
|
if (detail) {
|
|
1302
2778
|
detail.textContent = state.error;
|
|
1303
2779
|
}
|
|
2780
|
+
wireRetryDescribedBy(
|
|
2781
|
+
container,
|
|
2782
|
+
getStateId("error"),
|
|
2783
|
+
"eudi-error-state-detail"
|
|
2784
|
+
);
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
function wireRetryDescribedBy(container, stateId, detailId) {
|
|
2788
|
+
const detail = container.querySelector(`#${detailId}`);
|
|
2789
|
+
const retryBtn = container.querySelector(
|
|
2790
|
+
`#${stateId} .eudi-retry-btn`
|
|
2791
|
+
);
|
|
2792
|
+
if (!retryBtn) return;
|
|
2793
|
+
if (detail?.textContent) {
|
|
2794
|
+
retryBtn.setAttribute("aria-describedby", detailId);
|
|
2795
|
+
} else {
|
|
2796
|
+
retryBtn.removeAttribute("aria-describedby");
|
|
1304
2797
|
}
|
|
1305
2798
|
}
|
|
1306
2799
|
|
|
@@ -1312,7 +2805,9 @@ var EudiVerify = (() => {
|
|
|
1312
2805
|
"input:not([disabled])"
|
|
1313
2806
|
].join(", ");
|
|
1314
2807
|
function getFocusableElements(container) {
|
|
1315
|
-
return Array.from(
|
|
2808
|
+
return Array.from(
|
|
2809
|
+
container.querySelectorAll(FOCUSABLE_SELECTORS)
|
|
2810
|
+
);
|
|
1316
2811
|
}
|
|
1317
2812
|
function createFocusTrap(container) {
|
|
1318
2813
|
let previouslyFocused = null;
|
|
@@ -1576,6 +3071,11 @@ var EudiVerify = (() => {
|
|
|
1576
3071
|
#updateState(state) {
|
|
1577
3072
|
if (!this.#container) return;
|
|
1578
3073
|
updateWidgetState(this.#container, state);
|
|
3074
|
+
if (state.status === "loading") {
|
|
3075
|
+
this.#container.setAttribute("aria-busy", "true");
|
|
3076
|
+
} else {
|
|
3077
|
+
this.#container.removeAttribute("aria-busy");
|
|
3078
|
+
}
|
|
1579
3079
|
if (this.#liveRegion && state.status !== this.#lastStatus) {
|
|
1580
3080
|
const message = STATE_MESSAGES[state.status];
|
|
1581
3081
|
if (message) {
|
|
@@ -1589,12 +3089,14 @@ var EudiVerify = (() => {
|
|
|
1589
3089
|
#manageFocus(state) {
|
|
1590
3090
|
if (!this.#container) return;
|
|
1591
3091
|
switch (state.status) {
|
|
1592
|
-
case "showQR":
|
|
1593
|
-
|
|
3092
|
+
case "showQR":
|
|
3093
|
+
case "waitingForWallet": {
|
|
3094
|
+
const cancelBtn = this.#container.querySelector(
|
|
3095
|
+
`#eudi-state-${state.status} .eudi-cancel-btn`
|
|
3096
|
+
);
|
|
1594
3097
|
cancelBtn?.focus();
|
|
1595
3098
|
break;
|
|
1596
3099
|
}
|
|
1597
|
-
case "verified":
|
|
1598
3100
|
case "rejected":
|
|
1599
3101
|
case "expired":
|
|
1600
3102
|
case "error": {
|