@destyler/qr-code 0.0.6 → 0.0.7-beta.1
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/dist/index.cjs +106 -1189
- package/dist/index.d.cts +68 -120
- package/dist/index.d.mts +68 -120
- package/dist/index.d.ts +68 -120
- package/dist/index.mjs +102 -1186
- package/package.json +10 -16
- package/README.md +0 -7
- package/dist/component.cjs +0 -14
- package/dist/component.d.cts +0 -4
- package/dist/component.d.mts +0 -4
- package/dist/component.d.ts +0 -4
- package/dist/component.mjs +0 -5
- package/dist/resolver.cjs +0 -21
- package/dist/resolver.d.cts +0 -6
- package/dist/resolver.d.mts +0 -6
- package/dist/resolver.d.ts +0 -6
- package/dist/resolver.mjs +0 -18
package/dist/index.cjs
CHANGED
|
@@ -1,1204 +1,121 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
3
|
+
const anatomy$1 = require('@zag-js/anatomy');
|
|
4
|
+
const domQuery = require('@zag-js/dom-query');
|
|
5
|
+
const core = require('@zag-js/core');
|
|
6
|
+
const utils = require('@zag-js/utils');
|
|
7
|
+
const proxyMemoize = require('proxy-memoize');
|
|
8
|
+
const uqr = require('uqr');
|
|
9
|
+
const types = require('@zag-js/types');
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
|
|
30
|
-
// Even if a QR Code is created with automatic masking requested (mask = -1),
|
|
31
|
-
// the resulting object still has a mask value between 0 and 7.
|
|
32
|
-
__publicField(this, "mask");
|
|
33
|
-
// The modules of this QR Code (false = light, true = dark).
|
|
34
|
-
// Immutable after constructor finishes. Accessed through getModule().
|
|
35
|
-
__publicField(this, "modules", []);
|
|
36
|
-
// Indicates function modules that are not subjected to masking. Discarded when constructor finishes.
|
|
37
|
-
__publicField(this, "isFunction", []);
|
|
38
|
-
if (version < _QrCode.MIN_VERSION || version > _QrCode.MAX_VERSION)
|
|
39
|
-
throw new RangeError("Version value out of range");
|
|
40
|
-
if (msk < -1 || msk > 7)
|
|
41
|
-
throw new RangeError("Mask value out of range");
|
|
42
|
-
this.size = version * 4 + 17;
|
|
43
|
-
const row = [];
|
|
44
|
-
for (let i = 0; i < this.size; i++)
|
|
45
|
-
row.push(false);
|
|
46
|
-
for (let i = 0; i < this.size; i++) {
|
|
47
|
-
this.modules.push(row.slice());
|
|
48
|
-
this.isFunction.push(row.slice());
|
|
49
|
-
}
|
|
50
|
-
this.drawFunctionPatterns();
|
|
51
|
-
const allCodewords = this.addEccAndInterleave(dataCodewords);
|
|
52
|
-
this.drawCodewords(allCodewords);
|
|
53
|
-
if (msk === -1) {
|
|
54
|
-
let minPenalty = 1e9;
|
|
55
|
-
for (let i = 0; i < 8; i++) {
|
|
56
|
-
this.applyMask(i);
|
|
57
|
-
this.drawFormatBits(i);
|
|
58
|
-
const penalty = this.getPenaltyScore();
|
|
59
|
-
if (penalty < minPenalty) {
|
|
60
|
-
msk = i;
|
|
61
|
-
minPenalty = penalty;
|
|
62
|
-
}
|
|
63
|
-
this.applyMask(i);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
this.mask = msk;
|
|
67
|
-
this.applyMask(msk);
|
|
68
|
-
this.drawFormatBits(msk);
|
|
69
|
-
this.isFunction = [];
|
|
70
|
-
}
|
|
71
|
-
/* -- Static factory functions (high level) -- */
|
|
72
|
-
// Returns a QR Code representing the given Unicode text string at the given error correction level.
|
|
73
|
-
// As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer
|
|
74
|
-
// Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible
|
|
75
|
-
// QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
|
|
76
|
-
// ecl argument if it can be done without increasing the version.
|
|
77
|
-
static encodeText(text, ecl) {
|
|
78
|
-
const segs = qrcodegen2.QrSegment.makeSegments(text);
|
|
79
|
-
return _QrCode.encodeSegments(segs, ecl);
|
|
80
|
-
}
|
|
81
|
-
// Returns a QR Code representing the given binary data at the given error correction level.
|
|
82
|
-
// This function always encodes using the binary segment mode, not any text mode. The maximum number of
|
|
83
|
-
// bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
|
|
84
|
-
// The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
|
|
85
|
-
static encodeBinary(data, ecl) {
|
|
86
|
-
const seg = qrcodegen2.QrSegment.makeBytes(data);
|
|
87
|
-
return _QrCode.encodeSegments([seg], ecl);
|
|
88
|
-
}
|
|
89
|
-
/* -- Static factory functions (mid level) -- */
|
|
90
|
-
// Returns a QR Code representing the given segments with the given encoding parameters.
|
|
91
|
-
// The smallest possible QR Code version within the given range is automatically
|
|
92
|
-
// chosen for the output. Iff boostEcl is true, then the ECC level of the result
|
|
93
|
-
// may be higher than the ecl argument if it can be done without increasing the
|
|
94
|
-
// version. The mask number is either between 0 to 7 (inclusive) to force that
|
|
95
|
-
// mask, or -1 to automatically choose an appropriate mask (which may be slow).
|
|
96
|
-
// This function allows the user to create a custom sequence of segments that switches
|
|
97
|
-
// between modes (such as alphanumeric and byte) to encode text in less space.
|
|
98
|
-
// This is a mid-level API; the high-level API is encodeText() and encodeBinary().
|
|
99
|
-
static encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
|
|
100
|
-
if (!(_QrCode.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= _QrCode.MAX_VERSION) || mask < -1 || mask > 7)
|
|
101
|
-
throw new RangeError("Invalid value");
|
|
102
|
-
let version;
|
|
103
|
-
let dataUsedBits;
|
|
104
|
-
for (version = minVersion; ; version++) {
|
|
105
|
-
const dataCapacityBits2 = _QrCode.getNumDataCodewords(version, ecl) * 8;
|
|
106
|
-
const usedBits = QrSegment.getTotalBits(segs, version);
|
|
107
|
-
if (usedBits <= dataCapacityBits2) {
|
|
108
|
-
dataUsedBits = usedBits;
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
if (version >= maxVersion) {
|
|
112
|
-
throw new RangeError("Data too long");
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
for (const newEcl of [
|
|
116
|
-
_QrCode.Ecc.MEDIUM,
|
|
117
|
-
_QrCode.Ecc.QUARTILE,
|
|
118
|
-
_QrCode.Ecc.HIGH
|
|
119
|
-
]) {
|
|
120
|
-
if (boostEcl && dataUsedBits <= _QrCode.getNumDataCodewords(version, newEcl) * 8)
|
|
121
|
-
ecl = newEcl;
|
|
122
|
-
}
|
|
123
|
-
const bb = [];
|
|
124
|
-
for (const seg of segs) {
|
|
125
|
-
appendBits(seg.mode.modeBits, 4, bb);
|
|
126
|
-
appendBits(seg.numChars, seg.mode.numCharCountBits(version), bb);
|
|
127
|
-
for (const b of seg.getData())
|
|
128
|
-
bb.push(b);
|
|
129
|
-
}
|
|
130
|
-
const dataCapacityBits = _QrCode.getNumDataCodewords(version, ecl) * 8;
|
|
131
|
-
appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
|
|
132
|
-
appendBits(0, (8 - bb.length % 8) % 8, bb);
|
|
133
|
-
for (let padByte = 236; bb.length < dataCapacityBits; padByte ^= 236 ^ 17)
|
|
134
|
-
appendBits(padByte, 8, bb);
|
|
135
|
-
const dataCodewords = [];
|
|
136
|
-
while (dataCodewords.length * 8 < bb.length)
|
|
137
|
-
dataCodewords.push(0);
|
|
138
|
-
bb.forEach(
|
|
139
|
-
(b, i) => dataCodewords[i >>> 3] |= b << 7 - (i & 7)
|
|
140
|
-
);
|
|
141
|
-
return new _QrCode(version, ecl, dataCodewords, mask);
|
|
142
|
-
}
|
|
143
|
-
/* -- Accessor methods -- */
|
|
144
|
-
// Returns the color of the module (pixel) at the given coordinates, which is false
|
|
145
|
-
// for light or true for dark. The top left corner has the coordinates (x=0, y=0).
|
|
146
|
-
// If the given coordinates are out of bounds, then false (light) is returned.
|
|
147
|
-
getModule(x, y) {
|
|
148
|
-
return x >= 0 && x < this.size && y >= 0 && y < this.size && this.modules[y][x];
|
|
149
|
-
}
|
|
150
|
-
/* -- Private helper methods for constructor: Drawing function modules -- */
|
|
151
|
-
// Reads this object's version field, and draws and marks all function modules.
|
|
152
|
-
drawFunctionPatterns() {
|
|
153
|
-
for (let i = 0; i < this.size; i++) {
|
|
154
|
-
this.setFunctionModule(6, i, i % 2 === 0);
|
|
155
|
-
this.setFunctionModule(i, 6, i % 2 === 0);
|
|
156
|
-
}
|
|
157
|
-
this.drawFinderPattern(3, 3);
|
|
158
|
-
this.drawFinderPattern(this.size - 4, 3);
|
|
159
|
-
this.drawFinderPattern(3, this.size - 4);
|
|
160
|
-
const alignPatPos = this.getAlignmentPatternPositions();
|
|
161
|
-
const numAlign = alignPatPos.length;
|
|
162
|
-
for (let i = 0; i < numAlign; i++) {
|
|
163
|
-
for (let j = 0; j < numAlign; j++) {
|
|
164
|
-
if (!(i === 0 && j === 0 || i === 0 && j === numAlign - 1 || i === numAlign - 1 && j === 0))
|
|
165
|
-
this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
this.drawFormatBits(0);
|
|
169
|
-
this.drawVersion();
|
|
170
|
-
}
|
|
171
|
-
// Draws two copies of the format bits (with its own error correction code)
|
|
172
|
-
// based on the given mask and this object's error correction level field.
|
|
173
|
-
drawFormatBits(mask) {
|
|
174
|
-
const data = this.errorCorrectionLevel.formatBits << 3 | mask;
|
|
175
|
-
let rem = data;
|
|
176
|
-
for (let i = 0; i < 10; i++)
|
|
177
|
-
rem = rem << 1 ^ (rem >>> 9) * 1335;
|
|
178
|
-
const bits = (data << 10 | rem) ^ 21522;
|
|
179
|
-
for (let i = 0; i <= 5; i++)
|
|
180
|
-
this.setFunctionModule(8, i, getBit(bits, i));
|
|
181
|
-
this.setFunctionModule(8, 7, getBit(bits, 6));
|
|
182
|
-
this.setFunctionModule(8, 8, getBit(bits, 7));
|
|
183
|
-
this.setFunctionModule(7, 8, getBit(bits, 8));
|
|
184
|
-
for (let i = 9; i < 15; i++)
|
|
185
|
-
this.setFunctionModule(14 - i, 8, getBit(bits, i));
|
|
186
|
-
for (let i = 0; i < 8; i++)
|
|
187
|
-
this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
|
|
188
|
-
for (let i = 8; i < 15; i++)
|
|
189
|
-
this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
|
|
190
|
-
this.setFunctionModule(8, this.size - 8, true);
|
|
191
|
-
}
|
|
192
|
-
// Draws two copies of the version bits (with its own error correction code),
|
|
193
|
-
// based on this object's version field, iff 7 <= version <= 40.
|
|
194
|
-
drawVersion() {
|
|
195
|
-
if (this.version < 7)
|
|
196
|
-
return;
|
|
197
|
-
let rem = this.version;
|
|
198
|
-
for (let i = 0; i < 12; i++)
|
|
199
|
-
rem = rem << 1 ^ (rem >>> 11) * 7973;
|
|
200
|
-
const bits = this.version << 12 | rem;
|
|
201
|
-
for (let i = 0; i < 18; i++) {
|
|
202
|
-
const color = getBit(bits, i);
|
|
203
|
-
const a = this.size - 11 + i % 3;
|
|
204
|
-
const b = Math.floor(i / 3);
|
|
205
|
-
this.setFunctionModule(a, b, color);
|
|
206
|
-
this.setFunctionModule(b, a, color);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
// Draws a 9*9 finder pattern including the border separator,
|
|
210
|
-
// with the center module at (x, y). Modules can be out of bounds.
|
|
211
|
-
drawFinderPattern(x, y) {
|
|
212
|
-
for (let dy = -4; dy <= 4; dy++) {
|
|
213
|
-
for (let dx = -4; dx <= 4; dx++) {
|
|
214
|
-
const dist = Math.max(Math.abs(dx), Math.abs(dy));
|
|
215
|
-
const xx = x + dx;
|
|
216
|
-
const yy = y + dy;
|
|
217
|
-
if (xx >= 0 && xx < this.size && yy >= 0 && yy < this.size)
|
|
218
|
-
this.setFunctionModule(xx, yy, dist !== 2 && dist !== 4);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
// Draws a 5*5 alignment pattern, with the center module
|
|
223
|
-
// at (x, y). All modules must be in bounds.
|
|
224
|
-
drawAlignmentPattern(x, y) {
|
|
225
|
-
for (let dy = -2; dy <= 2; dy++) {
|
|
226
|
-
for (let dx = -2; dx <= 2; dx++) {
|
|
227
|
-
this.setFunctionModule(
|
|
228
|
-
x + dx,
|
|
229
|
-
y + dy,
|
|
230
|
-
Math.max(Math.abs(dx), Math.abs(dy)) !== 1
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
// Sets the color of a module and marks it as a function module.
|
|
236
|
-
// Only used by the constructor. Coordinates must be in bounds.
|
|
237
|
-
setFunctionModule(x, y, isDark) {
|
|
238
|
-
this.modules[y][x] = isDark;
|
|
239
|
-
this.isFunction[y][x] = true;
|
|
240
|
-
}
|
|
241
|
-
/* -- Private helper methods for constructor: Codewords and masking -- */
|
|
242
|
-
// Returns a new byte string representing the given data with the appropriate error correction
|
|
243
|
-
// codewords appended to it, based on this object's version and error correction level.
|
|
244
|
-
addEccAndInterleave(data) {
|
|
245
|
-
const ver = this.version;
|
|
246
|
-
const ecl = this.errorCorrectionLevel;
|
|
247
|
-
if (data.length !== _QrCode.getNumDataCodewords(ver, ecl))
|
|
248
|
-
throw new RangeError("Invalid argument");
|
|
249
|
-
const numBlocks = _QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
|
|
250
|
-
const blockEccLen = _QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver];
|
|
251
|
-
const rawCodewords = Math.floor(_QrCode.getNumRawDataModules(ver) / 8);
|
|
252
|
-
const numShortBlocks = numBlocks - rawCodewords % numBlocks;
|
|
253
|
-
const shortBlockLen = Math.floor(rawCodewords / numBlocks);
|
|
254
|
-
const blocks = [];
|
|
255
|
-
const rsDiv = _QrCode.reedSolomonComputeDivisor(blockEccLen);
|
|
256
|
-
for (let i = 0, k = 0; i < numBlocks; i++) {
|
|
257
|
-
const dat = data.slice(
|
|
258
|
-
k,
|
|
259
|
-
k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1)
|
|
260
|
-
);
|
|
261
|
-
k += dat.length;
|
|
262
|
-
const ecc = _QrCode.reedSolomonComputeRemainder(dat, rsDiv);
|
|
263
|
-
if (i < numShortBlocks)
|
|
264
|
-
dat.push(0);
|
|
265
|
-
blocks.push(dat.concat(ecc));
|
|
266
|
-
}
|
|
267
|
-
const result = [];
|
|
268
|
-
for (let i = 0; i < blocks[0].length; i++) {
|
|
269
|
-
blocks.forEach((block, j) => {
|
|
270
|
-
if (i !== shortBlockLen - blockEccLen || j >= numShortBlocks)
|
|
271
|
-
result.push(block[i]);
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
return result;
|
|
275
|
-
}
|
|
276
|
-
// Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
|
|
277
|
-
// data area of this QR Code. Function modules need to be marked off before this is called.
|
|
278
|
-
drawCodewords(data) {
|
|
279
|
-
if (data.length !== Math.floor(_QrCode.getNumRawDataModules(this.version) / 8))
|
|
280
|
-
throw new RangeError("Invalid argument");
|
|
281
|
-
let i = 0;
|
|
282
|
-
for (let right = this.size - 1; right >= 1; right -= 2) {
|
|
283
|
-
if (right === 6)
|
|
284
|
-
right = 5;
|
|
285
|
-
for (let vert = 0; vert < this.size; vert++) {
|
|
286
|
-
for (let j = 0; j < 2; j++) {
|
|
287
|
-
const x = right - j;
|
|
288
|
-
const upward = (right + 1 & 2) === 0;
|
|
289
|
-
const y = upward ? this.size - 1 - vert : vert;
|
|
290
|
-
if (!this.isFunction[y][x] && i < data.length * 8) {
|
|
291
|
-
this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
|
|
292
|
-
i++;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
// XORs the codeword modules in this QR Code with the given mask pattern.
|
|
299
|
-
// The function modules must be marked and the codeword bits must be drawn
|
|
300
|
-
// before masking. Due to the arithmetic of XOR, calling applyMask() with
|
|
301
|
-
// the same mask value a second time will undo the mask. A final well-formed
|
|
302
|
-
// QR Code needs exactly one (not zero, two, etc.) mask applied.
|
|
303
|
-
applyMask(mask) {
|
|
304
|
-
if (mask < 0 || mask > 7)
|
|
305
|
-
throw new RangeError("Mask value out of range");
|
|
306
|
-
for (let y = 0; y < this.size; y++) {
|
|
307
|
-
for (let x = 0; x < this.size; x++) {
|
|
308
|
-
let invert;
|
|
309
|
-
switch (mask) {
|
|
310
|
-
case 0:
|
|
311
|
-
invert = (x + y) % 2 === 0;
|
|
312
|
-
break;
|
|
313
|
-
case 1:
|
|
314
|
-
invert = y % 2 === 0;
|
|
315
|
-
break;
|
|
316
|
-
case 2:
|
|
317
|
-
invert = x % 3 === 0;
|
|
318
|
-
break;
|
|
319
|
-
case 3:
|
|
320
|
-
invert = (x + y) % 3 === 0;
|
|
321
|
-
break;
|
|
322
|
-
case 4:
|
|
323
|
-
invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;
|
|
324
|
-
break;
|
|
325
|
-
case 5:
|
|
326
|
-
invert = x * y % 2 + x * y % 3 === 0;
|
|
327
|
-
break;
|
|
328
|
-
case 6:
|
|
329
|
-
invert = (x * y % 2 + x * y % 3) % 2 === 0;
|
|
330
|
-
break;
|
|
331
|
-
case 7:
|
|
332
|
-
invert = ((x + y) % 2 + x * y % 3) % 2 === 0;
|
|
333
|
-
break;
|
|
334
|
-
default:
|
|
335
|
-
throw new Error("Unreachable");
|
|
336
|
-
}
|
|
337
|
-
if (!this.isFunction[y][x] && invert)
|
|
338
|
-
this.modules[y][x] = !this.modules[y][x];
|
|
339
|
-
}
|
|
11
|
+
const anatomy = anatomy$1.createAnatomy("qr-code").parts("root", "frame", "pattern", "overlay");
|
|
12
|
+
const parts = anatomy.build();
|
|
13
|
+
|
|
14
|
+
const dom = domQuery.createScope({
|
|
15
|
+
getRootId: (ctx) => ctx.ids?.root ?? `qrcode:${ctx.id}:root`,
|
|
16
|
+
getFrameId: (ctx) => ctx.ids?.frame ?? `qrcode:${ctx.id}:frame`,
|
|
17
|
+
getFrameEl: (ctx) => dom.getById(ctx, dom.getFrameId(ctx))
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function connect(state, send, normalize) {
|
|
21
|
+
const encoded = state.context.encoded;
|
|
22
|
+
const pixelSize = state.context.pixelSize;
|
|
23
|
+
const height = encoded.size * pixelSize;
|
|
24
|
+
const width = encoded.size * pixelSize;
|
|
25
|
+
const paths = [];
|
|
26
|
+
for (let row = 0; row < encoded.size; row++) {
|
|
27
|
+
for (let col = 0; col < encoded.size; col++) {
|
|
28
|
+
const x = col * pixelSize;
|
|
29
|
+
const y = row * pixelSize;
|
|
30
|
+
if (encoded.data[row][col]) {
|
|
31
|
+
paths.push(`M${x},${y}h${pixelSize}v${pixelSize}h-${pixelSize}z`);
|
|
340
32
|
}
|
|
341
33
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
result += this.finderPenaltyCountPatterns(runHistory) * _QrCode.PENALTY_N3;
|
|
362
|
-
}
|
|
363
|
-
runColor = this.modules[y][x];
|
|
364
|
-
runX = 1;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * _QrCode.PENALTY_N3;
|
|
368
|
-
}
|
|
369
|
-
for (let x = 0; x < this.size; x++) {
|
|
370
|
-
let runColor = false;
|
|
371
|
-
let runY = 0;
|
|
372
|
-
const runHistory = [0, 0, 0, 0, 0, 0, 0];
|
|
373
|
-
for (let y = 0; y < this.size; y++) {
|
|
374
|
-
if (this.modules[y][x] === runColor) {
|
|
375
|
-
runY++;
|
|
376
|
-
if (runY === 5)
|
|
377
|
-
result += _QrCode.PENALTY_N1;
|
|
378
|
-
else if (runY > 5) {
|
|
379
|
-
result++;
|
|
380
|
-
}
|
|
381
|
-
} else {
|
|
382
|
-
this.finderPenaltyAddHistory(runY, runHistory);
|
|
383
|
-
if (!runColor) {
|
|
384
|
-
result += this.finderPenaltyCountPatterns(runHistory) * _QrCode.PENALTY_N3;
|
|
385
|
-
}
|
|
386
|
-
runColor = this.modules[y][x];
|
|
387
|
-
runY = 1;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * _QrCode.PENALTY_N3;
|
|
391
|
-
}
|
|
392
|
-
for (let y = 0; y < this.size - 1; y++) {
|
|
393
|
-
for (let x = 0; x < this.size - 1; x++) {
|
|
394
|
-
const color = this.modules[y][x];
|
|
395
|
-
if (color === this.modules[y][x + 1] && color === this.modules[y + 1][x] && color === this.modules[y + 1][x + 1])
|
|
396
|
-
result += _QrCode.PENALTY_N2;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
value: state.context.value,
|
|
37
|
+
setValue(value) {
|
|
38
|
+
send({ type: "VALUE.SET", value });
|
|
39
|
+
},
|
|
40
|
+
getDataUrl(type, quality) {
|
|
41
|
+
const svgEl = dom.getFrameEl(state.context);
|
|
42
|
+
return domQuery.getDataUrl(svgEl, { type, quality });
|
|
43
|
+
},
|
|
44
|
+
getRootProps() {
|
|
45
|
+
return normalize.element({
|
|
46
|
+
id: dom.getRootId(state.context),
|
|
47
|
+
...parts.root.attrs,
|
|
48
|
+
style: {
|
|
49
|
+
"--qrcode-pixel-size": `${pixelSize}px`,
|
|
50
|
+
"--qrcode-width": `${width}px`,
|
|
51
|
+
"--qrcode-height": `${height}px`,
|
|
52
|
+
"position": "relative"
|
|
397
53
|
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
// Returns the number of data bits that can be stored in a QR Code of the given version number, after
|
|
424
|
-
// all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
|
|
425
|
-
// The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
|
|
426
|
-
static getNumRawDataModules(ver) {
|
|
427
|
-
if (ver < _QrCode.MIN_VERSION || ver > _QrCode.MAX_VERSION)
|
|
428
|
-
throw new RangeError("Version number out of range");
|
|
429
|
-
let result = (16 * ver + 128) * ver + 64;
|
|
430
|
-
if (ver >= 2) {
|
|
431
|
-
const numAlign = Math.floor(ver / 7) + 2;
|
|
432
|
-
result -= (25 * numAlign - 10) * numAlign - 55;
|
|
433
|
-
if (ver >= 7)
|
|
434
|
-
result -= 36;
|
|
435
|
-
}
|
|
436
|
-
return result;
|
|
437
|
-
}
|
|
438
|
-
// Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
|
|
439
|
-
// QR Code of the given version number and error correction level, with remainder bits discarded.
|
|
440
|
-
// This stateless pure function could be implemented as a (40*4)-cell lookup table.
|
|
441
|
-
static getNumDataCodewords(ver, ecl) {
|
|
442
|
-
return Math.floor(_QrCode.getNumRawDataModules(ver) / 8) - _QrCode.ECC_CODEWORDS_PER_BLOCK[ecl.ordinal][ver] * _QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
|
|
443
|
-
}
|
|
444
|
-
// Returns a Reed-Solomon ECC generator polynomial for the given degree. This could be
|
|
445
|
-
// implemented as a lookup table over all possible parameter values, instead of as an algorithm.
|
|
446
|
-
static reedSolomonComputeDivisor(degree) {
|
|
447
|
-
if (degree < 1 || degree > 255)
|
|
448
|
-
throw new RangeError("Degree out of range");
|
|
449
|
-
const result = [];
|
|
450
|
-
for (let i = 0; i < degree - 1; i++)
|
|
451
|
-
result.push(0);
|
|
452
|
-
result.push(1);
|
|
453
|
-
let root = 1;
|
|
454
|
-
for (let i = 0; i < degree; i++) {
|
|
455
|
-
for (let j = 0; j < result.length; j++) {
|
|
456
|
-
result[j] = _QrCode.reedSolomonMultiply(result[j], root);
|
|
457
|
-
if (j + 1 < result.length)
|
|
458
|
-
result[j] ^= result[j + 1];
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
getFrameProps() {
|
|
57
|
+
return normalize.svg({
|
|
58
|
+
id: dom.getFrameId(state.context),
|
|
59
|
+
...parts.frame.attrs,
|
|
60
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
61
|
+
viewBox: `0 0 ${width} ${height}`
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
getPatternProps() {
|
|
65
|
+
return normalize.path({
|
|
66
|
+
d: paths.join(""),
|
|
67
|
+
...parts.pattern.attrs
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
getOverlayProps() {
|
|
71
|
+
return normalize.element({
|
|
72
|
+
...parts.overlay.attrs,
|
|
73
|
+
style: {
|
|
74
|
+
position: "absolute",
|
|
75
|
+
top: "50%",
|
|
76
|
+
left: "50%",
|
|
77
|
+
translate: "-50% -50%"
|
|
459
78
|
}
|
|
460
|
-
|
|
461
|
-
}
|
|
462
|
-
return result;
|
|
463
|
-
}
|
|
464
|
-
// Returns the Reed-Solomon error correction codeword for the given data and divisor polynomials.
|
|
465
|
-
static reedSolomonComputeRemainder(data, divisor) {
|
|
466
|
-
const result = divisor.map((_) => 0);
|
|
467
|
-
for (const b of data) {
|
|
468
|
-
const factor = b ^ result.shift();
|
|
469
|
-
result.push(0);
|
|
470
|
-
divisor.forEach(
|
|
471
|
-
(coef, i) => result[i] ^= _QrCode.reedSolomonMultiply(coef, factor)
|
|
472
|
-
);
|
|
473
|
-
}
|
|
474
|
-
return result;
|
|
475
|
-
}
|
|
476
|
-
// Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result
|
|
477
|
-
// are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
|
|
478
|
-
static reedSolomonMultiply(x, y) {
|
|
479
|
-
if (x >>> 8 !== 0 || y >>> 8 !== 0)
|
|
480
|
-
throw new RangeError("Byte out of range");
|
|
481
|
-
let z = 0;
|
|
482
|
-
for (let i = 7; i >= 0; i--) {
|
|
483
|
-
z = z << 1 ^ (z >>> 7) * 285;
|
|
484
|
-
z ^= (y >>> i & 1) * x;
|
|
485
|
-
}
|
|
486
|
-
return z;
|
|
487
|
-
}
|
|
488
|
-
// Can only be called immediately after a light run is added, and
|
|
489
|
-
// returns either 0, 1, or 2. A helper function for getPenaltyScore().
|
|
490
|
-
finderPenaltyCountPatterns(runHistory) {
|
|
491
|
-
const n = runHistory[1];
|
|
492
|
-
const core = n > 0 && runHistory[2] === n && runHistory[3] === n * 3 && runHistory[4] === n && runHistory[5] === n;
|
|
493
|
-
return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
|
|
494
|
-
}
|
|
495
|
-
// Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
|
|
496
|
-
finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
|
|
497
|
-
if (currentRunColor) {
|
|
498
|
-
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
|
499
|
-
currentRunLength = 0;
|
|
500
|
-
}
|
|
501
|
-
currentRunLength += this.size;
|
|
502
|
-
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
|
503
|
-
return this.finderPenaltyCountPatterns(runHistory);
|
|
504
|
-
}
|
|
505
|
-
// Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
|
|
506
|
-
finderPenaltyAddHistory(currentRunLength, runHistory) {
|
|
507
|
-
if (runHistory[0] === 0)
|
|
508
|
-
currentRunLength += this.size;
|
|
509
|
-
runHistory.pop();
|
|
510
|
-
runHistory.unshift(currentRunLength);
|
|
79
|
+
});
|
|
511
80
|
}
|
|
512
81
|
};
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
26,
|
|
533
|
-
18,
|
|
534
|
-
20,
|
|
535
|
-
24,
|
|
536
|
-
30,
|
|
537
|
-
18,
|
|
538
|
-
20,
|
|
539
|
-
24,
|
|
540
|
-
26,
|
|
541
|
-
30,
|
|
542
|
-
22,
|
|
543
|
-
24,
|
|
544
|
-
28,
|
|
545
|
-
30,
|
|
546
|
-
28,
|
|
547
|
-
28,
|
|
548
|
-
28,
|
|
549
|
-
28,
|
|
550
|
-
30,
|
|
551
|
-
30,
|
|
552
|
-
26,
|
|
553
|
-
28,
|
|
554
|
-
30,
|
|
555
|
-
30,
|
|
556
|
-
30,
|
|
557
|
-
30,
|
|
558
|
-
30,
|
|
559
|
-
30,
|
|
560
|
-
30,
|
|
561
|
-
30,
|
|
562
|
-
30,
|
|
563
|
-
30,
|
|
564
|
-
30,
|
|
565
|
-
30,
|
|
566
|
-
30,
|
|
567
|
-
30
|
|
568
|
-
],
|
|
569
|
-
// Low
|
|
570
|
-
[
|
|
571
|
-
-1,
|
|
572
|
-
10,
|
|
573
|
-
16,
|
|
574
|
-
26,
|
|
575
|
-
18,
|
|
576
|
-
24,
|
|
577
|
-
16,
|
|
578
|
-
18,
|
|
579
|
-
22,
|
|
580
|
-
22,
|
|
581
|
-
26,
|
|
582
|
-
30,
|
|
583
|
-
22,
|
|
584
|
-
22,
|
|
585
|
-
24,
|
|
586
|
-
24,
|
|
587
|
-
28,
|
|
588
|
-
28,
|
|
589
|
-
26,
|
|
590
|
-
26,
|
|
591
|
-
26,
|
|
592
|
-
26,
|
|
593
|
-
28,
|
|
594
|
-
28,
|
|
595
|
-
28,
|
|
596
|
-
28,
|
|
597
|
-
28,
|
|
598
|
-
28,
|
|
599
|
-
28,
|
|
600
|
-
28,
|
|
601
|
-
28,
|
|
602
|
-
28,
|
|
603
|
-
28,
|
|
604
|
-
28,
|
|
605
|
-
28,
|
|
606
|
-
28,
|
|
607
|
-
28,
|
|
608
|
-
28,
|
|
609
|
-
28,
|
|
610
|
-
28,
|
|
611
|
-
28
|
|
612
|
-
],
|
|
613
|
-
// Medium
|
|
614
|
-
[
|
|
615
|
-
-1,
|
|
616
|
-
13,
|
|
617
|
-
22,
|
|
618
|
-
18,
|
|
619
|
-
26,
|
|
620
|
-
18,
|
|
621
|
-
24,
|
|
622
|
-
18,
|
|
623
|
-
22,
|
|
624
|
-
20,
|
|
625
|
-
24,
|
|
626
|
-
28,
|
|
627
|
-
26,
|
|
628
|
-
24,
|
|
629
|
-
20,
|
|
630
|
-
30,
|
|
631
|
-
24,
|
|
632
|
-
28,
|
|
633
|
-
28,
|
|
634
|
-
26,
|
|
635
|
-
30,
|
|
636
|
-
28,
|
|
637
|
-
30,
|
|
638
|
-
30,
|
|
639
|
-
30,
|
|
640
|
-
30,
|
|
641
|
-
28,
|
|
642
|
-
30,
|
|
643
|
-
30,
|
|
644
|
-
30,
|
|
645
|
-
30,
|
|
646
|
-
30,
|
|
647
|
-
30,
|
|
648
|
-
30,
|
|
649
|
-
30,
|
|
650
|
-
30,
|
|
651
|
-
30,
|
|
652
|
-
30,
|
|
653
|
-
30,
|
|
654
|
-
30,
|
|
655
|
-
30
|
|
656
|
-
],
|
|
657
|
-
// Quartile
|
|
658
|
-
[
|
|
659
|
-
-1,
|
|
660
|
-
17,
|
|
661
|
-
28,
|
|
662
|
-
22,
|
|
663
|
-
16,
|
|
664
|
-
22,
|
|
665
|
-
28,
|
|
666
|
-
26,
|
|
667
|
-
26,
|
|
668
|
-
24,
|
|
669
|
-
28,
|
|
670
|
-
24,
|
|
671
|
-
28,
|
|
672
|
-
22,
|
|
673
|
-
24,
|
|
674
|
-
24,
|
|
675
|
-
30,
|
|
676
|
-
28,
|
|
677
|
-
28,
|
|
678
|
-
26,
|
|
679
|
-
28,
|
|
680
|
-
30,
|
|
681
|
-
24,
|
|
682
|
-
30,
|
|
683
|
-
30,
|
|
684
|
-
30,
|
|
685
|
-
30,
|
|
686
|
-
30,
|
|
687
|
-
30,
|
|
688
|
-
30,
|
|
689
|
-
30,
|
|
690
|
-
30,
|
|
691
|
-
30,
|
|
692
|
-
30,
|
|
693
|
-
30,
|
|
694
|
-
30,
|
|
695
|
-
30,
|
|
696
|
-
30,
|
|
697
|
-
30,
|
|
698
|
-
30,
|
|
699
|
-
30
|
|
700
|
-
]
|
|
701
|
-
// High
|
|
702
|
-
]);
|
|
703
|
-
__publicField(_QrCode, "NUM_ERROR_CORRECTION_BLOCKS", [
|
|
704
|
-
// Version: (note that index 0 is for padding, and is set to an illegal value)
|
|
705
|
-
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
|
|
706
|
-
[
|
|
707
|
-
-1,
|
|
708
|
-
1,
|
|
709
|
-
1,
|
|
710
|
-
1,
|
|
711
|
-
1,
|
|
712
|
-
1,
|
|
713
|
-
2,
|
|
714
|
-
2,
|
|
715
|
-
2,
|
|
716
|
-
2,
|
|
717
|
-
4,
|
|
718
|
-
4,
|
|
719
|
-
4,
|
|
720
|
-
4,
|
|
721
|
-
4,
|
|
722
|
-
6,
|
|
723
|
-
6,
|
|
724
|
-
6,
|
|
725
|
-
6,
|
|
726
|
-
7,
|
|
727
|
-
8,
|
|
728
|
-
8,
|
|
729
|
-
9,
|
|
730
|
-
9,
|
|
731
|
-
10,
|
|
732
|
-
12,
|
|
733
|
-
12,
|
|
734
|
-
12,
|
|
735
|
-
13,
|
|
736
|
-
14,
|
|
737
|
-
15,
|
|
738
|
-
16,
|
|
739
|
-
17,
|
|
740
|
-
18,
|
|
741
|
-
19,
|
|
742
|
-
19,
|
|
743
|
-
20,
|
|
744
|
-
21,
|
|
745
|
-
22,
|
|
746
|
-
24,
|
|
747
|
-
25
|
|
748
|
-
],
|
|
749
|
-
// Low
|
|
750
|
-
[
|
|
751
|
-
-1,
|
|
752
|
-
1,
|
|
753
|
-
1,
|
|
754
|
-
1,
|
|
755
|
-
2,
|
|
756
|
-
2,
|
|
757
|
-
4,
|
|
758
|
-
4,
|
|
759
|
-
4,
|
|
760
|
-
5,
|
|
761
|
-
5,
|
|
762
|
-
5,
|
|
763
|
-
8,
|
|
764
|
-
9,
|
|
765
|
-
9,
|
|
766
|
-
10,
|
|
767
|
-
10,
|
|
768
|
-
11,
|
|
769
|
-
13,
|
|
770
|
-
14,
|
|
771
|
-
16,
|
|
772
|
-
17,
|
|
773
|
-
17,
|
|
774
|
-
18,
|
|
775
|
-
20,
|
|
776
|
-
21,
|
|
777
|
-
23,
|
|
778
|
-
25,
|
|
779
|
-
26,
|
|
780
|
-
28,
|
|
781
|
-
29,
|
|
782
|
-
31,
|
|
783
|
-
33,
|
|
784
|
-
35,
|
|
785
|
-
37,
|
|
786
|
-
38,
|
|
787
|
-
40,
|
|
788
|
-
43,
|
|
789
|
-
45,
|
|
790
|
-
47,
|
|
791
|
-
49
|
|
792
|
-
],
|
|
793
|
-
// Medium
|
|
794
|
-
[
|
|
795
|
-
-1,
|
|
796
|
-
1,
|
|
797
|
-
1,
|
|
798
|
-
2,
|
|
799
|
-
2,
|
|
800
|
-
4,
|
|
801
|
-
4,
|
|
802
|
-
6,
|
|
803
|
-
6,
|
|
804
|
-
8,
|
|
805
|
-
8,
|
|
806
|
-
8,
|
|
807
|
-
10,
|
|
808
|
-
12,
|
|
809
|
-
16,
|
|
810
|
-
12,
|
|
811
|
-
17,
|
|
812
|
-
16,
|
|
813
|
-
18,
|
|
814
|
-
21,
|
|
815
|
-
20,
|
|
816
|
-
23,
|
|
817
|
-
23,
|
|
818
|
-
25,
|
|
819
|
-
27,
|
|
820
|
-
29,
|
|
821
|
-
34,
|
|
822
|
-
34,
|
|
823
|
-
35,
|
|
824
|
-
38,
|
|
825
|
-
40,
|
|
826
|
-
43,
|
|
827
|
-
45,
|
|
828
|
-
48,
|
|
829
|
-
51,
|
|
830
|
-
53,
|
|
831
|
-
56,
|
|
832
|
-
59,
|
|
833
|
-
62,
|
|
834
|
-
65,
|
|
835
|
-
68
|
|
836
|
-
],
|
|
837
|
-
// Quartile
|
|
838
|
-
[
|
|
839
|
-
-1,
|
|
840
|
-
1,
|
|
841
|
-
1,
|
|
842
|
-
2,
|
|
843
|
-
4,
|
|
844
|
-
4,
|
|
845
|
-
4,
|
|
846
|
-
5,
|
|
847
|
-
6,
|
|
848
|
-
8,
|
|
849
|
-
8,
|
|
850
|
-
11,
|
|
851
|
-
11,
|
|
852
|
-
16,
|
|
853
|
-
16,
|
|
854
|
-
18,
|
|
855
|
-
16,
|
|
856
|
-
19,
|
|
857
|
-
21,
|
|
858
|
-
25,
|
|
859
|
-
25,
|
|
860
|
-
25,
|
|
861
|
-
34,
|
|
862
|
-
30,
|
|
863
|
-
32,
|
|
864
|
-
35,
|
|
865
|
-
37,
|
|
866
|
-
40,
|
|
867
|
-
42,
|
|
868
|
-
45,
|
|
869
|
-
48,
|
|
870
|
-
51,
|
|
871
|
-
54,
|
|
872
|
-
57,
|
|
873
|
-
60,
|
|
874
|
-
63,
|
|
875
|
-
66,
|
|
876
|
-
70,
|
|
877
|
-
74,
|
|
878
|
-
77,
|
|
879
|
-
81
|
|
880
|
-
]
|
|
881
|
-
// High
|
|
882
|
-
]);
|
|
883
|
-
qrcodegen2.QrCode = _QrCode;
|
|
884
|
-
function appendBits(val, len, bb) {
|
|
885
|
-
if (len < 0 || len > 31 || val >>> len !== 0)
|
|
886
|
-
throw new RangeError("Value out of range");
|
|
887
|
-
for (let i = len - 1; i >= 0; i--)
|
|
888
|
-
bb.push(val >>> i & 1);
|
|
889
|
-
}
|
|
890
|
-
function getBit(x, i) {
|
|
891
|
-
return (x >>> i & 1) !== 0;
|
|
892
|
-
}
|
|
893
|
-
const _QrSegment = class _QrSegment {
|
|
894
|
-
/* -- Constructor (low level) and fields -- */
|
|
895
|
-
// Creates a new QR Code segment with the given attributes and data.
|
|
896
|
-
// The character count (numChars) must agree with the mode and the bit buffer length,
|
|
897
|
-
// but the constraint isn't checked. The given bit buffer is cloned and stored.
|
|
898
|
-
constructor(mode, numChars, bitData) {
|
|
899
|
-
this.mode = mode;
|
|
900
|
-
this.numChars = numChars;
|
|
901
|
-
this.bitData = bitData;
|
|
902
|
-
if (numChars < 0)
|
|
903
|
-
throw new RangeError("Invalid argument");
|
|
904
|
-
this.bitData = bitData.slice();
|
|
905
|
-
}
|
|
906
|
-
/* -- Static factory functions (mid level) -- */
|
|
907
|
-
// Returns a segment representing the given binary data encoded in
|
|
908
|
-
// byte mode. All input byte arrays are acceptable. Any text string
|
|
909
|
-
// can be converted to UTF-8 bytes and encoded as a byte mode segment.
|
|
910
|
-
static makeBytes(data) {
|
|
911
|
-
const bb = [];
|
|
912
|
-
for (const b of data)
|
|
913
|
-
appendBits(b, 8, bb);
|
|
914
|
-
return new _QrSegment(_QrSegment.Mode.BYTE, data.length, bb);
|
|
915
|
-
}
|
|
916
|
-
// Returns a segment representing the given string of decimal digits encoded in numeric mode.
|
|
917
|
-
static makeNumeric(digits) {
|
|
918
|
-
if (!_QrSegment.isNumeric(digits))
|
|
919
|
-
throw new RangeError("String contains non-numeric characters");
|
|
920
|
-
const bb = [];
|
|
921
|
-
for (let i = 0; i < digits.length; ) {
|
|
922
|
-
const n = Math.min(digits.length - i, 3);
|
|
923
|
-
appendBits(Number.parseInt(digits.substr(i, n), 10), n * 3 + 1, bb);
|
|
924
|
-
i += n;
|
|
925
|
-
}
|
|
926
|
-
return new _QrSegment(_QrSegment.Mode.NUMERIC, digits.length, bb);
|
|
927
|
-
}
|
|
928
|
-
// Returns a segment representing the given text string encoded in alphanumeric mode.
|
|
929
|
-
// The characters allowed are: 0 to 9, A to Z (uppercase only), space,
|
|
930
|
-
// dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
|
931
|
-
static makeAlphanumeric(text) {
|
|
932
|
-
if (!_QrSegment.isAlphanumeric(text)) {
|
|
933
|
-
throw new RangeError(
|
|
934
|
-
"String contains unencodable characters in alphanumeric mode"
|
|
935
|
-
);
|
|
936
|
-
}
|
|
937
|
-
const bb = [];
|
|
938
|
-
let i;
|
|
939
|
-
for (i = 0; i + 2 <= text.length; i += 2) {
|
|
940
|
-
let temp = _QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
|
|
941
|
-
temp += _QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
|
|
942
|
-
appendBits(temp, 11, bb);
|
|
943
|
-
}
|
|
944
|
-
if (i < text.length) {
|
|
945
|
-
appendBits(
|
|
946
|
-
_QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)),
|
|
947
|
-
6,
|
|
948
|
-
bb
|
|
949
|
-
);
|
|
950
|
-
}
|
|
951
|
-
return new _QrSegment(_QrSegment.Mode.ALPHANUMERIC, text.length, bb);
|
|
952
|
-
}
|
|
953
|
-
// Returns a new mutable list of zero or more segments to represent the given Unicode text string.
|
|
954
|
-
// The result may use various segment modes and switch modes to optimize the length of the bit stream.
|
|
955
|
-
static makeSegments(text) {
|
|
956
|
-
if (text === "")
|
|
957
|
-
return [];
|
|
958
|
-
else if (_QrSegment.isNumeric(text))
|
|
959
|
-
return [_QrSegment.makeNumeric(text)];
|
|
960
|
-
else if (_QrSegment.isAlphanumeric(text))
|
|
961
|
-
return [_QrSegment.makeAlphanumeric(text)];
|
|
962
|
-
else
|
|
963
|
-
return [_QrSegment.makeBytes(_QrSegment.toUtf8ByteArray(text))];
|
|
964
|
-
}
|
|
965
|
-
// Returns a segment representing an Extended Channel Interpretation
|
|
966
|
-
// (ECI) designator with the given assignment value.
|
|
967
|
-
static makeEci(assignVal) {
|
|
968
|
-
const bb = [];
|
|
969
|
-
if (assignVal < 0) {
|
|
970
|
-
throw new RangeError("ECI assignment value out of range");
|
|
971
|
-
} else if (assignVal < 1 << 7) {
|
|
972
|
-
appendBits(assignVal, 8, bb);
|
|
973
|
-
} else if (assignVal < 1 << 14) {
|
|
974
|
-
appendBits(2, 2, bb);
|
|
975
|
-
appendBits(assignVal, 14, bb);
|
|
976
|
-
} else if (assignVal < 1e6) {
|
|
977
|
-
appendBits(6, 3, bb);
|
|
978
|
-
appendBits(assignVal, 21, bb);
|
|
979
|
-
} else {
|
|
980
|
-
throw new RangeError("ECI assignment value out of range");
|
|
981
|
-
}
|
|
982
|
-
return new _QrSegment(_QrSegment.Mode.ECI, 0, bb);
|
|
983
|
-
}
|
|
984
|
-
// Tests whether the given string can be encoded as a segment in numeric mode.
|
|
985
|
-
// A string is encodable iff each character is in the range 0 to 9.
|
|
986
|
-
static isNumeric(text) {
|
|
987
|
-
return _QrSegment.NUMERIC_REGEX.test(text);
|
|
988
|
-
}
|
|
989
|
-
// Tests whether the given string can be encoded as a segment in alphanumeric mode.
|
|
990
|
-
// A string is encodable iff each character is in the following set: 0 to 9, A to Z
|
|
991
|
-
// (uppercase only), space, dollar, percent, asterisk, plus, hyphen, period, slash, colon.
|
|
992
|
-
static isAlphanumeric(text) {
|
|
993
|
-
return _QrSegment.ALPHANUMERIC_REGEX.test(text);
|
|
994
|
-
}
|
|
995
|
-
/* -- Methods -- */
|
|
996
|
-
// Returns a new copy of the data bits of this segment.
|
|
997
|
-
getData() {
|
|
998
|
-
return this.bitData.slice();
|
|
999
|
-
}
|
|
1000
|
-
// (Package-private) Calculates and returns the number of bits needed to encode the given segments at
|
|
1001
|
-
// the given version. The result is infinity if a segment has too many characters to fit its length field.
|
|
1002
|
-
static getTotalBits(segs, version) {
|
|
1003
|
-
let result = 0;
|
|
1004
|
-
for (const seg of segs) {
|
|
1005
|
-
const ccbits = seg.mode.numCharCountBits(version);
|
|
1006
|
-
if (seg.numChars >= 1 << ccbits)
|
|
1007
|
-
return Number.POSITIVE_INFINITY;
|
|
1008
|
-
result += 4 + ccbits + seg.bitData.length;
|
|
1009
|
-
}
|
|
1010
|
-
return result;
|
|
1011
|
-
}
|
|
1012
|
-
// Returns a new array of bytes representing the given string encoded in UTF-8.
|
|
1013
|
-
static toUtf8ByteArray(str) {
|
|
1014
|
-
str = encodeURI(str);
|
|
1015
|
-
const result = [];
|
|
1016
|
-
for (let i = 0; i < str.length; i++) {
|
|
1017
|
-
if (str.charAt(i) !== "%") {
|
|
1018
|
-
result.push(str.charCodeAt(i));
|
|
1019
|
-
} else {
|
|
1020
|
-
result.push(Number.parseInt(str.substr(i + 1, 2), 16));
|
|
1021
|
-
i += 2;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function machine(userContext) {
|
|
85
|
+
const ctx = utils.compact(userContext);
|
|
86
|
+
return core.createMachine(
|
|
87
|
+
{
|
|
88
|
+
id: "qr-code",
|
|
89
|
+
initial: "idle",
|
|
90
|
+
context: {
|
|
91
|
+
value: "",
|
|
92
|
+
...ctx,
|
|
93
|
+
pixelSize: 10
|
|
94
|
+
},
|
|
95
|
+
computed: {
|
|
96
|
+
encoded: proxyMemoize.memoize((ctx2) => uqr.encode(ctx2.value, ctx2.encoding))
|
|
97
|
+
},
|
|
98
|
+
on: {
|
|
99
|
+
"VALUE.SET": {
|
|
100
|
+
actions: ["setValue"]
|
|
1022
101
|
}
|
|
1023
102
|
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
__publicField(_QrSegment, "NUMERIC_REGEX", /^[0-9]*$/);
|
|
1030
|
-
// Describes precisely all strings that are encodable in alphanumeric mode.
|
|
1031
|
-
__publicField(_QrSegment, "ALPHANUMERIC_REGEX", /^[A-Z0-9 $%*+./:-]*$/);
|
|
1032
|
-
// The set of all legal characters in alphanumeric mode,
|
|
1033
|
-
// where each character value maps to the index in the string.
|
|
1034
|
-
__publicField(_QrSegment, "ALPHANUMERIC_CHARSET", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:");
|
|
1035
|
-
let QrSegment = _QrSegment;
|
|
1036
|
-
qrcodegen2.QrSegment = _QrSegment;
|
|
1037
|
-
})(qrcodegen || (qrcodegen = {}));
|
|
1038
|
-
((qrcodegen2) => {
|
|
1039
|
-
((QrCode2) => {
|
|
1040
|
-
const _Ecc = class _Ecc {
|
|
1041
|
-
// The QR Code can tolerate about 30% erroneous codewords
|
|
1042
|
-
/* -- Constructor and fields -- */
|
|
1043
|
-
constructor(ordinal, formatBits) {
|
|
1044
|
-
this.ordinal = ordinal;
|
|
1045
|
-
this.formatBits = formatBits;
|
|
1046
|
-
}
|
|
1047
|
-
};
|
|
1048
|
-
/* -- Constants -- */
|
|
1049
|
-
__publicField(_Ecc, "LOW", new _Ecc(0, 1));
|
|
1050
|
-
// The QR Code can tolerate about 7% erroneous codewords
|
|
1051
|
-
__publicField(_Ecc, "MEDIUM", new _Ecc(1, 0));
|
|
1052
|
-
// The QR Code can tolerate about 15% erroneous codewords
|
|
1053
|
-
__publicField(_Ecc, "QUARTILE", new _Ecc(2, 3));
|
|
1054
|
-
// The QR Code can tolerate about 25% erroneous codewords
|
|
1055
|
-
__publicField(_Ecc, "HIGH", new _Ecc(3, 2));
|
|
1056
|
-
QrCode2.Ecc = _Ecc;
|
|
1057
|
-
})(qrcodegen2.QrCode || (qrcodegen2.QrCode = {}));
|
|
1058
|
-
})(qrcodegen || (qrcodegen = {}));
|
|
1059
|
-
((qrcodegen2) => {
|
|
1060
|
-
((QrSegment2) => {
|
|
1061
|
-
const _Mode = class _Mode {
|
|
1062
|
-
/* -- Constructor and fields -- */
|
|
1063
|
-
constructor(modeBits, numBitsCharCount) {
|
|
1064
|
-
this.modeBits = modeBits;
|
|
1065
|
-
this.numBitsCharCount = numBitsCharCount;
|
|
1066
|
-
}
|
|
1067
|
-
/* -- Method -- */
|
|
1068
|
-
// (Package-private) Returns the bit width of the character count field for a segment in
|
|
1069
|
-
// this mode in a QR Code at the given version number. The result is in the range [0, 16].
|
|
1070
|
-
numCharCountBits(ver) {
|
|
1071
|
-
return this.numBitsCharCount[Math.floor((ver + 7) / 17)];
|
|
1072
|
-
}
|
|
1073
|
-
};
|
|
1074
|
-
/* -- Constants -- */
|
|
1075
|
-
__publicField(_Mode, "NUMERIC", new _Mode(1, [10, 12, 14]));
|
|
1076
|
-
__publicField(_Mode, "ALPHANUMERIC", new _Mode(2, [9, 11, 13]));
|
|
1077
|
-
__publicField(_Mode, "BYTE", new _Mode(4, [8, 16, 16]));
|
|
1078
|
-
__publicField(_Mode, "KANJI", new _Mode(8, [8, 10, 12]));
|
|
1079
|
-
__publicField(_Mode, "ECI", new _Mode(7, [0, 0, 0]));
|
|
1080
|
-
QrSegment2.Mode = _Mode;
|
|
1081
|
-
})(qrcodegen2.QrSegment || (qrcodegen2.QrSegment = {}));
|
|
1082
|
-
})(qrcodegen || (qrcodegen = {}));
|
|
1083
|
-
const qrcodegen$1 = qrcodegen;
|
|
1084
|
-
|
|
1085
|
-
const qrCodeRootProps = {
|
|
1086
|
-
...primitive.primitiveProps,
|
|
1087
|
-
value: {
|
|
1088
|
-
type: String,
|
|
1089
|
-
required: true
|
|
1090
|
-
},
|
|
1091
|
-
ErrorCorrectionLevel: {
|
|
1092
|
-
type: String,
|
|
1093
|
-
required: false,
|
|
1094
|
-
default: "M"
|
|
1095
|
-
}
|
|
1096
|
-
};
|
|
1097
|
-
const [injectQrCodeRootContext, provideQrCodeRootContext] = shared.createContext("DestylerQrCodeRootContext");
|
|
1098
|
-
const QrCodeRoot = vue.defineComponent({
|
|
1099
|
-
name: "DestylerQrCodeRoot",
|
|
1100
|
-
props: qrCodeRootProps,
|
|
1101
|
-
setup(props) {
|
|
1102
|
-
composition.useForwardExpose();
|
|
1103
|
-
const { value, ErrorCorrectionLevel } = vue.toRefs(props);
|
|
1104
|
-
provideQrCodeRootContext({
|
|
1105
|
-
value,
|
|
1106
|
-
ErrorCorrectionLevel
|
|
1107
|
-
});
|
|
1108
|
-
},
|
|
1109
|
-
render() {
|
|
1110
|
-
return vue.h(primitive.Primitive, {
|
|
1111
|
-
"as": this.$props.as,
|
|
1112
|
-
"asChild": this.$props.asChild,
|
|
1113
|
-
"aria-label": "QR Code"
|
|
1114
|
-
}, () => this.$slots.default?.());
|
|
1115
|
-
}
|
|
1116
|
-
});
|
|
1117
|
-
|
|
1118
|
-
const qrCodeItemProps = {
|
|
1119
|
-
size: {
|
|
1120
|
-
type: Number,
|
|
1121
|
-
default: 100
|
|
1122
|
-
},
|
|
1123
|
-
foregroundColor: {
|
|
1124
|
-
type: String,
|
|
1125
|
-
default: "#000"
|
|
1126
|
-
},
|
|
1127
|
-
backgroundColor: {
|
|
1128
|
-
type: String,
|
|
1129
|
-
default: "#FFF"
|
|
1130
|
-
}
|
|
1131
|
-
};
|
|
1132
|
-
const ERROR_CORRECTION_LEVEL = {
|
|
1133
|
-
L: qrcodegen$1.QrCode.Ecc.LOW,
|
|
1134
|
-
M: qrcodegen$1.QrCode.Ecc.MEDIUM,
|
|
1135
|
-
Q: qrcodegen$1.QrCode.Ecc.QUARTILE,
|
|
1136
|
-
H: qrcodegen$1.QrCode.Ecc.HIGH
|
|
1137
|
-
};
|
|
1138
|
-
const QrCodeItem = vue.defineComponent({
|
|
1139
|
-
name: "DestylerQrCodeItem",
|
|
1140
|
-
props: qrCodeItemProps,
|
|
1141
|
-
setup(props) {
|
|
1142
|
-
const UPSCALE_RATIO = 2;
|
|
1143
|
-
const rootContext = injectQrCodeRootContext();
|
|
1144
|
-
const { forwardRef, currentElement } = composition.useForwardExpose();
|
|
1145
|
-
const qr = vue.computed(() => {
|
|
1146
|
-
const errorCorrectionLevel = ERROR_CORRECTION_LEVEL[rootContext.ErrorCorrectionLevel.value];
|
|
1147
|
-
return qrcodegen$1.QrCode.encodeText(
|
|
1148
|
-
rootContext.value.value ?? "-",
|
|
1149
|
-
errorCorrectionLevel
|
|
1150
|
-
);
|
|
1151
|
-
});
|
|
1152
|
-
vue.onMounted(() => {
|
|
1153
|
-
const imageLoadedTrigger = vue.ref(0);
|
|
1154
|
-
vue.watchEffect(() => {
|
|
1155
|
-
void imageLoadedTrigger.value;
|
|
1156
|
-
drawCanvas(
|
|
1157
|
-
qr.value,
|
|
1158
|
-
props.size,
|
|
1159
|
-
props.foregroundColor,
|
|
1160
|
-
props.backgroundColor
|
|
1161
|
-
);
|
|
1162
|
-
});
|
|
1163
|
-
});
|
|
1164
|
-
function drawCanvas(qr2, size, foregroundColor, backgroundColor) {
|
|
1165
|
-
const canvas = currentElement.value;
|
|
1166
|
-
if (!canvas)
|
|
1167
|
-
return;
|
|
1168
|
-
const canvasWidth = size * UPSCALE_RATIO;
|
|
1169
|
-
const width = qr2.size;
|
|
1170
|
-
const scale = canvasWidth / width;
|
|
1171
|
-
canvas.width = canvasWidth;
|
|
1172
|
-
canvas.height = canvasWidth;
|
|
1173
|
-
const ctx = canvas.getContext("2d");
|
|
1174
|
-
if (!ctx)
|
|
1175
|
-
return;
|
|
1176
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
1177
|
-
for (let y = 0; y < qr2.size; y++) {
|
|
1178
|
-
for (let x = 0; x < qr2.size; x++) {
|
|
1179
|
-
ctx.fillStyle = qr2.getModule(x, y) ? foregroundColor : backgroundColor;
|
|
1180
|
-
const startX = Math.floor(x * scale);
|
|
1181
|
-
const endX = Math.ceil((x + 1) * scale);
|
|
1182
|
-
const startY = Math.floor(y * scale);
|
|
1183
|
-
const endY = Math.ceil((y + 1) * scale);
|
|
1184
|
-
ctx.fillRect(startX, startY, endX - startX, endY - startY);
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
actions: {
|
|
106
|
+
setValue: (ctx2, e) => {
|
|
107
|
+
ctx2.value = e.value;
|
|
1185
108
|
}
|
|
1186
109
|
}
|
|
1187
110
|
}
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
return vue.h(primitive.Primitive, {
|
|
1194
|
-
as: "canvas",
|
|
1195
|
-
asChild: false,
|
|
1196
|
-
ref: (el) => this.forwardRef(el)
|
|
1197
|
-
});
|
|
1198
|
-
}
|
|
1199
|
-
});
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const props = types.createProps()(["ids", "value", "id", "encoding", "dir", "getRootNode"]);
|
|
115
|
+
const splitProps = utils.createSplitProps(props);
|
|
1200
116
|
|
|
1201
|
-
exports.
|
|
1202
|
-
exports.
|
|
1203
|
-
exports.
|
|
1204
|
-
exports.
|
|
117
|
+
exports.anatomy = anatomy;
|
|
118
|
+
exports.connect = connect;
|
|
119
|
+
exports.machine = machine;
|
|
120
|
+
exports.props = props;
|
|
121
|
+
exports.splitProps = splitProps;
|