@vielzeug/sigil 3.1.0 → 26.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_format.cjs +1 -1
- package/dist/_format.cjs.map +1 -1
- package/dist/_format.js +1 -36
- package/dist/_format.js.map +1 -1
- package/dist/_galois.cjs +1 -1
- package/dist/_galois.cjs.map +1 -1
- package/dist/_galois.js +1 -21
- package/dist/_galois.js.map +1 -1
- package/dist/_mask.cjs +1 -1
- package/dist/_mask.cjs.map +1 -1
- package/dist/_mask.js +1 -80
- package/dist/_mask.js.map +1 -1
- package/dist/_matrix.cjs +1 -1
- package/dist/_matrix.cjs.map +1 -1
- package/dist/_matrix.js +1 -64
- package/dist/_matrix.js.map +1 -1
- package/dist/_reed-solomon.cjs +1 -1
- package/dist/_reed-solomon.cjs.map +1 -1
- package/dist/_reed-solomon.js +1 -21
- package/dist/_reed-solomon.js.map +1 -1
- package/dist/_segments.cjs +1 -1
- package/dist/_segments.cjs.map +1 -1
- package/dist/_segments.d.ts +22 -11
- package/dist/_segments.d.ts.map +1 -1
- package/dist/_segments.js +1 -69
- package/dist/_segments.js.map +1 -1
- package/dist/_tables.cjs +1 -1
- package/dist/_tables.cjs.map +1 -1
- package/dist/_tables.js +1 -408
- package/dist/_tables.js.map +1 -1
- package/dist/canvas.cjs +1 -1
- package/dist/canvas.cjs.map +1 -1
- package/dist/canvas.d.ts.map +1 -1
- package/dist/canvas.js +1 -13
- package/dist/canvas.js.map +1 -1
- package/dist/encode.cjs +1 -1
- package/dist/encode.cjs.map +1 -1
- package/dist/encode.d.ts +3 -1
- package/dist/encode.d.ts.map +1 -1
- package/dist/encode.js +1 -111
- package/dist/encode.js.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +1 -16
- package/dist/errors.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -6
- package/dist/scan.cjs +1 -1
- package/dist/scan.cjs.map +1 -1
- package/dist/scan.d.ts.map +1 -1
- package/dist/scan.js +1 -140
- package/dist/scan.js.map +1 -1
- package/dist/sigil.cjs +1 -1
- package/dist/sigil.cjs.map +1 -1
- package/dist/sigil.iife.js +1 -1
- package/dist/sigil.iife.js.map +1 -1
- package/dist/sigil.js +1 -1
- package/dist/sigil.js.map +1 -1
- package/dist/svg.cjs +1 -1
- package/dist/svg.cjs.map +1 -1
- package/dist/svg.js +1 -25
- package/dist/svg.js.map +1 -1
- package/dist/types.d.ts +4 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/dist/_dev.cjs +0 -2
- package/dist/_dev.cjs.map +0 -1
- package/dist/_dev.d.ts +0 -2
- package/dist/_dev.d.ts.map +0 -1
- package/dist/_dev.js +0 -6
- package/dist/_dev.js.map +0 -1
package/dist/_tables.js
CHANGED
|
@@ -1,409 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var e = [
|
|
3
|
-
"L",
|
|
4
|
-
"M",
|
|
5
|
-
"Q",
|
|
6
|
-
"H"
|
|
7
|
-
], t = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:", n = {
|
|
8
|
-
alphanumeric: 2,
|
|
9
|
-
byte: 4,
|
|
10
|
-
numeric: 1
|
|
11
|
-
}, r = {
|
|
12
|
-
alphanumeric: [
|
|
13
|
-
9,
|
|
14
|
-
11,
|
|
15
|
-
13
|
|
16
|
-
],
|
|
17
|
-
byte: [
|
|
18
|
-
8,
|
|
19
|
-
16,
|
|
20
|
-
16
|
|
21
|
-
],
|
|
22
|
-
numeric: [
|
|
23
|
-
10,
|
|
24
|
-
12,
|
|
25
|
-
14
|
|
26
|
-
]
|
|
27
|
-
}, i = {
|
|
28
|
-
H: 2,
|
|
29
|
-
L: 1,
|
|
30
|
-
M: 0,
|
|
31
|
-
Q: 3
|
|
32
|
-
}, a = [
|
|
33
|
-
[
|
|
34
|
-
-1,
|
|
35
|
-
7,
|
|
36
|
-
10,
|
|
37
|
-
15,
|
|
38
|
-
20,
|
|
39
|
-
26,
|
|
40
|
-
18,
|
|
41
|
-
20,
|
|
42
|
-
24,
|
|
43
|
-
30,
|
|
44
|
-
18,
|
|
45
|
-
20,
|
|
46
|
-
24,
|
|
47
|
-
26,
|
|
48
|
-
30,
|
|
49
|
-
22,
|
|
50
|
-
24,
|
|
51
|
-
28,
|
|
52
|
-
30,
|
|
53
|
-
28,
|
|
54
|
-
28,
|
|
55
|
-
28,
|
|
56
|
-
28,
|
|
57
|
-
30,
|
|
58
|
-
30,
|
|
59
|
-
26,
|
|
60
|
-
28,
|
|
61
|
-
30,
|
|
62
|
-
30,
|
|
63
|
-
30,
|
|
64
|
-
30,
|
|
65
|
-
30,
|
|
66
|
-
30,
|
|
67
|
-
30,
|
|
68
|
-
30,
|
|
69
|
-
30,
|
|
70
|
-
30,
|
|
71
|
-
30,
|
|
72
|
-
30,
|
|
73
|
-
30,
|
|
74
|
-
30
|
|
75
|
-
],
|
|
76
|
-
[
|
|
77
|
-
-1,
|
|
78
|
-
10,
|
|
79
|
-
16,
|
|
80
|
-
26,
|
|
81
|
-
18,
|
|
82
|
-
24,
|
|
83
|
-
16,
|
|
84
|
-
18,
|
|
85
|
-
22,
|
|
86
|
-
22,
|
|
87
|
-
26,
|
|
88
|
-
30,
|
|
89
|
-
22,
|
|
90
|
-
22,
|
|
91
|
-
24,
|
|
92
|
-
24,
|
|
93
|
-
28,
|
|
94
|
-
28,
|
|
95
|
-
26,
|
|
96
|
-
26,
|
|
97
|
-
26,
|
|
98
|
-
26,
|
|
99
|
-
28,
|
|
100
|
-
28,
|
|
101
|
-
28,
|
|
102
|
-
28,
|
|
103
|
-
28,
|
|
104
|
-
28,
|
|
105
|
-
28,
|
|
106
|
-
28,
|
|
107
|
-
28,
|
|
108
|
-
28,
|
|
109
|
-
28,
|
|
110
|
-
28,
|
|
111
|
-
28,
|
|
112
|
-
28,
|
|
113
|
-
28,
|
|
114
|
-
28,
|
|
115
|
-
28,
|
|
116
|
-
28,
|
|
117
|
-
28
|
|
118
|
-
],
|
|
119
|
-
[
|
|
120
|
-
-1,
|
|
121
|
-
13,
|
|
122
|
-
22,
|
|
123
|
-
18,
|
|
124
|
-
26,
|
|
125
|
-
18,
|
|
126
|
-
24,
|
|
127
|
-
18,
|
|
128
|
-
22,
|
|
129
|
-
20,
|
|
130
|
-
24,
|
|
131
|
-
28,
|
|
132
|
-
26,
|
|
133
|
-
24,
|
|
134
|
-
20,
|
|
135
|
-
30,
|
|
136
|
-
24,
|
|
137
|
-
28,
|
|
138
|
-
28,
|
|
139
|
-
26,
|
|
140
|
-
30,
|
|
141
|
-
28,
|
|
142
|
-
30,
|
|
143
|
-
30,
|
|
144
|
-
30,
|
|
145
|
-
30,
|
|
146
|
-
28,
|
|
147
|
-
30,
|
|
148
|
-
30,
|
|
149
|
-
30,
|
|
150
|
-
30,
|
|
151
|
-
30,
|
|
152
|
-
30,
|
|
153
|
-
30,
|
|
154
|
-
30,
|
|
155
|
-
30,
|
|
156
|
-
30,
|
|
157
|
-
30,
|
|
158
|
-
30,
|
|
159
|
-
30,
|
|
160
|
-
30
|
|
161
|
-
],
|
|
162
|
-
[
|
|
163
|
-
-1,
|
|
164
|
-
17,
|
|
165
|
-
28,
|
|
166
|
-
22,
|
|
167
|
-
16,
|
|
168
|
-
22,
|
|
169
|
-
28,
|
|
170
|
-
26,
|
|
171
|
-
26,
|
|
172
|
-
24,
|
|
173
|
-
28,
|
|
174
|
-
24,
|
|
175
|
-
28,
|
|
176
|
-
22,
|
|
177
|
-
24,
|
|
178
|
-
24,
|
|
179
|
-
30,
|
|
180
|
-
28,
|
|
181
|
-
28,
|
|
182
|
-
26,
|
|
183
|
-
28,
|
|
184
|
-
30,
|
|
185
|
-
24,
|
|
186
|
-
30,
|
|
187
|
-
30,
|
|
188
|
-
30,
|
|
189
|
-
30,
|
|
190
|
-
30,
|
|
191
|
-
30,
|
|
192
|
-
30,
|
|
193
|
-
30,
|
|
194
|
-
30,
|
|
195
|
-
30,
|
|
196
|
-
30,
|
|
197
|
-
30,
|
|
198
|
-
30,
|
|
199
|
-
30,
|
|
200
|
-
30,
|
|
201
|
-
30,
|
|
202
|
-
30,
|
|
203
|
-
30
|
|
204
|
-
]
|
|
205
|
-
], o = [
|
|
206
|
-
[
|
|
207
|
-
-1,
|
|
208
|
-
1,
|
|
209
|
-
1,
|
|
210
|
-
1,
|
|
211
|
-
1,
|
|
212
|
-
1,
|
|
213
|
-
2,
|
|
214
|
-
2,
|
|
215
|
-
2,
|
|
216
|
-
2,
|
|
217
|
-
4,
|
|
218
|
-
4,
|
|
219
|
-
4,
|
|
220
|
-
4,
|
|
221
|
-
4,
|
|
222
|
-
6,
|
|
223
|
-
6,
|
|
224
|
-
6,
|
|
225
|
-
6,
|
|
226
|
-
7,
|
|
227
|
-
8,
|
|
228
|
-
8,
|
|
229
|
-
9,
|
|
230
|
-
9,
|
|
231
|
-
10,
|
|
232
|
-
12,
|
|
233
|
-
12,
|
|
234
|
-
12,
|
|
235
|
-
13,
|
|
236
|
-
14,
|
|
237
|
-
15,
|
|
238
|
-
16,
|
|
239
|
-
17,
|
|
240
|
-
18,
|
|
241
|
-
19,
|
|
242
|
-
19,
|
|
243
|
-
20,
|
|
244
|
-
21,
|
|
245
|
-
22,
|
|
246
|
-
24,
|
|
247
|
-
25
|
|
248
|
-
],
|
|
249
|
-
[
|
|
250
|
-
-1,
|
|
251
|
-
1,
|
|
252
|
-
1,
|
|
253
|
-
1,
|
|
254
|
-
2,
|
|
255
|
-
2,
|
|
256
|
-
4,
|
|
257
|
-
4,
|
|
258
|
-
4,
|
|
259
|
-
5,
|
|
260
|
-
5,
|
|
261
|
-
5,
|
|
262
|
-
8,
|
|
263
|
-
9,
|
|
264
|
-
9,
|
|
265
|
-
10,
|
|
266
|
-
10,
|
|
267
|
-
11,
|
|
268
|
-
13,
|
|
269
|
-
14,
|
|
270
|
-
16,
|
|
271
|
-
17,
|
|
272
|
-
17,
|
|
273
|
-
18,
|
|
274
|
-
20,
|
|
275
|
-
21,
|
|
276
|
-
23,
|
|
277
|
-
25,
|
|
278
|
-
26,
|
|
279
|
-
28,
|
|
280
|
-
29,
|
|
281
|
-
31,
|
|
282
|
-
33,
|
|
283
|
-
35,
|
|
284
|
-
37,
|
|
285
|
-
38,
|
|
286
|
-
40,
|
|
287
|
-
43,
|
|
288
|
-
45,
|
|
289
|
-
47,
|
|
290
|
-
49
|
|
291
|
-
],
|
|
292
|
-
[
|
|
293
|
-
-1,
|
|
294
|
-
1,
|
|
295
|
-
1,
|
|
296
|
-
2,
|
|
297
|
-
2,
|
|
298
|
-
4,
|
|
299
|
-
4,
|
|
300
|
-
6,
|
|
301
|
-
6,
|
|
302
|
-
8,
|
|
303
|
-
8,
|
|
304
|
-
8,
|
|
305
|
-
10,
|
|
306
|
-
12,
|
|
307
|
-
16,
|
|
308
|
-
12,
|
|
309
|
-
17,
|
|
310
|
-
16,
|
|
311
|
-
18,
|
|
312
|
-
21,
|
|
313
|
-
20,
|
|
314
|
-
23,
|
|
315
|
-
23,
|
|
316
|
-
25,
|
|
317
|
-
27,
|
|
318
|
-
29,
|
|
319
|
-
34,
|
|
320
|
-
34,
|
|
321
|
-
35,
|
|
322
|
-
38,
|
|
323
|
-
40,
|
|
324
|
-
43,
|
|
325
|
-
45,
|
|
326
|
-
48,
|
|
327
|
-
51,
|
|
328
|
-
53,
|
|
329
|
-
56,
|
|
330
|
-
59,
|
|
331
|
-
62,
|
|
332
|
-
65,
|
|
333
|
-
68
|
|
334
|
-
],
|
|
335
|
-
[
|
|
336
|
-
-1,
|
|
337
|
-
1,
|
|
338
|
-
1,
|
|
339
|
-
2,
|
|
340
|
-
4,
|
|
341
|
-
4,
|
|
342
|
-
4,
|
|
343
|
-
5,
|
|
344
|
-
6,
|
|
345
|
-
8,
|
|
346
|
-
8,
|
|
347
|
-
11,
|
|
348
|
-
11,
|
|
349
|
-
16,
|
|
350
|
-
16,
|
|
351
|
-
18,
|
|
352
|
-
16,
|
|
353
|
-
19,
|
|
354
|
-
21,
|
|
355
|
-
25,
|
|
356
|
-
25,
|
|
357
|
-
25,
|
|
358
|
-
34,
|
|
359
|
-
30,
|
|
360
|
-
32,
|
|
361
|
-
35,
|
|
362
|
-
37,
|
|
363
|
-
40,
|
|
364
|
-
42,
|
|
365
|
-
45,
|
|
366
|
-
48,
|
|
367
|
-
51,
|
|
368
|
-
56,
|
|
369
|
-
59,
|
|
370
|
-
62,
|
|
371
|
-
65,
|
|
372
|
-
68,
|
|
373
|
-
71,
|
|
374
|
-
74,
|
|
375
|
-
77,
|
|
376
|
-
81
|
|
377
|
-
]
|
|
378
|
-
], s = (t) => e.indexOf(t), c = (e) => e * 4 + 17;
|
|
379
|
-
function l(e) {
|
|
380
|
-
if (e === 1) return [];
|
|
381
|
-
let t = Math.floor(e / 7) + 2, n = e === 32 ? 26 : Math.ceil((e * 4 + 4) / (t * 2 - 2)) * 2, r = [6];
|
|
382
|
-
for (let i = e * 4 + 10; r.length < t; i -= n) r.splice(1, 0, i);
|
|
383
|
-
return r;
|
|
384
|
-
}
|
|
385
|
-
function u(e) {
|
|
386
|
-
let t = (16 * e + 128) * e + 64;
|
|
387
|
-
if (e >= 2) {
|
|
388
|
-
let n = Math.floor(e / 7) + 2;
|
|
389
|
-
t -= (25 * n - 10) * n - 55, e >= 7 && (t -= 36);
|
|
390
|
-
}
|
|
391
|
-
return t;
|
|
392
|
-
}
|
|
393
|
-
var d = (e) => Math.floor(u(e) / 8);
|
|
394
|
-
function f(e, t) {
|
|
395
|
-
return a[s(t)][e];
|
|
396
|
-
}
|
|
397
|
-
function p(e, t) {
|
|
398
|
-
return o[s(t)][e];
|
|
399
|
-
}
|
|
400
|
-
function m(e, t) {
|
|
401
|
-
return d(e) - f(e, t) * p(e, t);
|
|
402
|
-
}
|
|
403
|
-
function h(e) {
|
|
404
|
-
return e <= 9 ? 0 : e <= 26 ? 1 : 2;
|
|
405
|
-
}
|
|
406
|
-
//#endregion
|
|
407
|
-
export { t as ALPHANUMERIC_CHARSET, r as CHAR_COUNT_BITS, a as EC_CODEWORDS_PER_BLOCK, e as EC_LEVELS, i as FORMAT_EC_BITS, n as MODE_BITS, o as NUM_EC_BLOCKS, l as alignmentPatternPositions, m as dataCodewords, f as ecCodewordsPerBlock, c as matrixSize, p as numEcBlocks, u as rawDataModules, d as totalCodewords, h as versionGroup };
|
|
408
|
-
|
|
1
|
+
var e=[`L`,`M`,`Q`,`H`],t=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`,n={alphanumeric:2,byte:4,numeric:1},r={alphanumeric:[9,11,13],byte:[8,16,16],numeric:[10,12,14]},i={H:2,L:1,M:0,Q:3},a=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],o=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,56,59,62,65,68,71,74,77,81]],ecIndex=t=>e.indexOf(t),matrixSize=e=>e*4+17;function alignmentPatternPositions(e){if(e===1)return[];let t=Math.floor(e/7)+2,n=e===32?26:Math.ceil((e*4+4)/(t*2-2))*2,r=[6];for(let i=e*4+10;r.length<t;i-=n)r.splice(1,0,i);return r}function rawDataModules(e){let t=(16*e+128)*e+64;if(e>=2){let n=Math.floor(e/7)+2;t-=(25*n-10)*n-55,e>=7&&(t-=36)}return t}var totalCodewords=e=>Math.floor(rawDataModules(e)/8);function ecCodewordsPerBlock(e,t){return a[ecIndex(t)][e]}function numEcBlocks(e,t){return o[ecIndex(t)][e]}function dataCodewords(e,t){return totalCodewords(e)-ecCodewordsPerBlock(e,t)*numEcBlocks(e,t)}function versionGroup(e){return e<=9?0:e<=26?1:2}export{t as ALPHANUMERIC_CHARSET,r as CHAR_COUNT_BITS,a as EC_CODEWORDS_PER_BLOCK,e as EC_LEVELS,i as FORMAT_EC_BITS,n as MODE_BITS,o as NUM_EC_BLOCKS,alignmentPatternPositions,dataCodewords,ecCodewordsPerBlock,matrixSize,numEcBlocks,rawDataModules,totalCodewords,versionGroup};
|
|
409
2
|
//# sourceMappingURL=_tables.js.map
|
package/dist/_tables.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_tables.js","names":[],"sources":["../src/_tables.ts"],"sourcesContent":["import type { QrErrorCorrection, QrMode } from './types';\n\n/**\n * QR Model 2 lookup tables, transcribed from ISO/IEC 18004:2015:\n * - `EC_CODEWORDS_PER_BLOCK` / `NUM_EC_BLOCKS` — Table 9 (error-correction\n * characteristics). Stored as per-block EC codewords and block count; the\n * group-1/group-2 split is derived, since all blocks share one EC length.\n * - `alignmentPatternPositions` — Table E.1, computed by the spec formula.\n * - `CHAR_COUNT_BITS` — Table 3 (character-count indicator bit widths).\n * - `FORMAT_EC_BITS` — Table 10 (2-bit level field inside format information).\n *\n * `tables.test.ts` cross-checks every entry against the raw-module formula, so\n * a transcription slip fails the consistency test before the decode oracle runs.\n */\n\n/** Index order used by the table rows below. */\nexport const EC_LEVELS = ['L', 'M', 'Q', 'H'] as const;\n\nexport const ALPHANUMERIC_CHARSET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:';\n\n/** Mode indicators (Table 2). */\nexport const MODE_BITS: Record<QrMode, number> = {\n alphanumeric: 0b0010,\n byte: 0b0100,\n numeric: 0b0001,\n};\n\n/** Character-count indicator widths for version groups 1–9 / 10–26 / 27–40. */\nexport const CHAR_COUNT_BITS: Record<QrMode, readonly [number, number, number]> = {\n alphanumeric: [9, 11, 13],\n byte: [8, 16, 16],\n numeric: [10, 12, 14],\n};\n\n/** EC level bits inside format information (L=01, M=00, Q=11, H=10). */\nexport const FORMAT_EC_BITS: Record<QrErrorCorrection, number> = { H: 0b10, L: 0b01, M: 0b00, Q: 0b11 };\n\n/** Row 0 = L, row 1 = M, row 2 = Q, row 3 = H; column 0 unused (versions start at 1). */\nexport const EC_CODEWORDS_PER_BLOCK: ReadonlyArray<ReadonlyArray<number>> = [\n // prettier-ignore\n [\n -1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30,\n 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,\n ],\n // prettier-ignore\n [\n -1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28,\n 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,\n ],\n // prettier-ignore\n [\n -1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30,\n 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,\n ],\n // prettier-ignore\n [\n -1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30,\n 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,\n ],\n];\n\nexport const NUM_EC_BLOCKS: ReadonlyArray<ReadonlyArray<number>> = [\n // prettier-ignore\n [\n -1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19,\n 19, 20, 21, 22, 24, 25,\n ],\n // prettier-ignore\n [\n -1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31,\n 33, 35, 37, 38, 40, 43, 45, 47, 49,\n ],\n // prettier-ignore\n [\n -1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43,\n 45, 48, 51, 53, 56, 59, 62, 65, 68,\n ],\n // prettier-ignore\n [\n -1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48,\n 51, 56, 59, 62, 65, 68, 71, 74, 77, 81,\n ],\n];\n\nconst ecIndex = (level: QrErrorCorrection): number => EC_LEVELS.indexOf(level);\n\n/** Total modules per side. */\nexport const matrixSize = (version: number): number => version * 4 + 17;\n\n/** Alignment-pattern center coordinates (Table E.1 formula). */\nexport function alignmentPatternPositions(version: number): readonly number[] {\n if (version === 1) return [];\n const numAlign = Math.floor(version / 7) + 2;\n const step = version === 32 ? 26 : Math.ceil((version * 4 + 4) / (numAlign * 2 - 2)) * 2;\n const result = [6];\n for (let pos = version * 4 + 10; result.length < numAlign; pos -= step) result.splice(1, 0, pos);\n return result;\n}\n\n/**\n * Total raw modules available for data + EC + remainder bits, derived from the\n * symbol geometry (Table 1 / Annex A): full grid minus finders, separators,\n * timing, alignment, dark module, format and version information.\n */\nexport function rawDataModules(version: number): number {\n let result = (16 * version + 128) * version + 64;\n if (version >= 2) {\n const numAlign = Math.floor(version / 7) + 2;\n result -= (25 * numAlign - 10) * numAlign - 55;\n if (version >= 7) result -= 36;\n }\n return result;\n}\n\n/** Total codewords (data + EC) for a version. */\nexport const totalCodewords = (version: number): number => Math.floor(rawDataModules(version) / 8);\n\n/** Leftover bits after the codeword stream (0, 3, 4, or 7 by version). */\nexport const remainderBits = (version: number): number => rawDataModules(version) % 8;\n\nexport function ecCodewordsPerBlock(version: number, level: QrErrorCorrection): number {\n return EC_CODEWORDS_PER_BLOCK[ecIndex(level)][version];\n}\n\nexport function numEcBlocks(version: number, level: QrErrorCorrection): number {\n return NUM_EC_BLOCKS[ecIndex(level)][version];\n}\n\n/** Data codewords for a (version, level) pair. */\nexport function dataCodewords(version: number, level: QrErrorCorrection): number {\n return totalCodewords(version) - ecCodewordsPerBlock(version, level) * numEcBlocks(version, level);\n}\n\n/** Version group for the character-count indicator: 0 → 1–9, 1 → 10–26, 2 → 27–40. */\nexport function versionGroup(version: number): 0 | 1 | 2 {\n return version <= 9 ? 0 : version <= 26 ? 1 : 2;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"_tables.js","names":[],"sources":["../src/_tables.ts"],"sourcesContent":["import type { QrErrorCorrection, QrMode } from './types';\n\n/**\n * QR Model 2 lookup tables, transcribed from ISO/IEC 18004:2015:\n * - `EC_CODEWORDS_PER_BLOCK` / `NUM_EC_BLOCKS` — Table 9 (error-correction\n * characteristics). Stored as per-block EC codewords and block count; the\n * group-1/group-2 split is derived, since all blocks share one EC length.\n * - `alignmentPatternPositions` — Table E.1, computed by the spec formula.\n * - `CHAR_COUNT_BITS` — Table 3 (character-count indicator bit widths).\n * - `FORMAT_EC_BITS` — Table 10 (2-bit level field inside format information).\n *\n * `tables.test.ts` cross-checks every entry against the raw-module formula, so\n * a transcription slip fails the consistency test before the decode oracle runs.\n */\n\n/** Index order used by the table rows below. */\nexport const EC_LEVELS = ['L', 'M', 'Q', 'H'] as const;\n\nexport const ALPHANUMERIC_CHARSET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:';\n\n/** Mode indicators (Table 2). */\nexport const MODE_BITS: Record<QrMode, number> = {\n alphanumeric: 0b0010,\n byte: 0b0100,\n numeric: 0b0001,\n};\n\n/** Character-count indicator widths for version groups 1–9 / 10–26 / 27–40. */\nexport const CHAR_COUNT_BITS: Record<QrMode, readonly [number, number, number]> = {\n alphanumeric: [9, 11, 13],\n byte: [8, 16, 16],\n numeric: [10, 12, 14],\n};\n\n/** EC level bits inside format information (L=01, M=00, Q=11, H=10). */\nexport const FORMAT_EC_BITS: Record<QrErrorCorrection, number> = { H: 0b10, L: 0b01, M: 0b00, Q: 0b11 };\n\n/** Row 0 = L, row 1 = M, row 2 = Q, row 3 = H; column 0 unused (versions start at 1). */\nexport const EC_CODEWORDS_PER_BLOCK: ReadonlyArray<ReadonlyArray<number>> = [\n // prettier-ignore\n [\n -1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30,\n 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,\n ],\n // prettier-ignore\n [\n -1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28,\n 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,\n ],\n // prettier-ignore\n [\n -1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30,\n 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,\n ],\n // prettier-ignore\n [\n -1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30,\n 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,\n ],\n];\n\nexport const NUM_EC_BLOCKS: ReadonlyArray<ReadonlyArray<number>> = [\n // prettier-ignore\n [\n -1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19,\n 19, 20, 21, 22, 24, 25,\n ],\n // prettier-ignore\n [\n -1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31,\n 33, 35, 37, 38, 40, 43, 45, 47, 49,\n ],\n // prettier-ignore\n [\n -1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43,\n 45, 48, 51, 53, 56, 59, 62, 65, 68,\n ],\n // prettier-ignore\n [\n -1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48,\n 51, 56, 59, 62, 65, 68, 71, 74, 77, 81,\n ],\n];\n\nconst ecIndex = (level: QrErrorCorrection): number => EC_LEVELS.indexOf(level);\n\n/** Total modules per side. */\nexport const matrixSize = (version: number): number => version * 4 + 17;\n\n/** Alignment-pattern center coordinates (Table E.1 formula). */\nexport function alignmentPatternPositions(version: number): readonly number[] {\n if (version === 1) return [];\n const numAlign = Math.floor(version / 7) + 2;\n const step = version === 32 ? 26 : Math.ceil((version * 4 + 4) / (numAlign * 2 - 2)) * 2;\n const result = [6];\n for (let pos = version * 4 + 10; result.length < numAlign; pos -= step) result.splice(1, 0, pos);\n return result;\n}\n\n/**\n * Total raw modules available for data + EC + remainder bits, derived from the\n * symbol geometry (Table 1 / Annex A): full grid minus finders, separators,\n * timing, alignment, dark module, format and version information.\n */\nexport function rawDataModules(version: number): number {\n let result = (16 * version + 128) * version + 64;\n if (version >= 2) {\n const numAlign = Math.floor(version / 7) + 2;\n result -= (25 * numAlign - 10) * numAlign - 55;\n if (version >= 7) result -= 36;\n }\n return result;\n}\n\n/** Total codewords (data + EC) for a version. */\nexport const totalCodewords = (version: number): number => Math.floor(rawDataModules(version) / 8);\n\n/** Leftover bits after the codeword stream (0, 3, 4, or 7 by version). */\nexport const remainderBits = (version: number): number => rawDataModules(version) % 8;\n\nexport function ecCodewordsPerBlock(version: number, level: QrErrorCorrection): number {\n return EC_CODEWORDS_PER_BLOCK[ecIndex(level)][version];\n}\n\nexport function numEcBlocks(version: number, level: QrErrorCorrection): number {\n return NUM_EC_BLOCKS[ecIndex(level)][version];\n}\n\n/** Data codewords for a (version, level) pair. */\nexport function dataCodewords(version: number, level: QrErrorCorrection): number {\n return totalCodewords(version) - ecCodewordsPerBlock(version, level) * numEcBlocks(version, level);\n}\n\n/** Version group for the character-count indicator: 0 → 1–9, 1 → 10–26, 2 → 27–40. */\nexport function versionGroup(version: number): 0 | 1 | 2 {\n return version <= 9 ? 0 : version <= 26 ? 1 : 2;\n}\n"],"mappings":"AAgBA,IAAa,EAAY,CAAC,IAAK,IAAK,IAAK,GAAG,EAE/B,EAAuB,gDAGvB,EAAoC,CAC/C,aAAc,EACd,KAAM,EACN,QAAS,CACX,EAGa,EAAqE,CAChF,aAAc,CAAC,EAAG,GAAI,EAAE,EACxB,KAAM,CAAC,EAAG,GAAI,EAAE,EAChB,QAAS,CAAC,GAAI,GAAI,EAAE,CACtB,EAGa,EAAoD,CAAE,EAAG,EAAM,EAAG,EAAM,EAAG,EAAM,EAAG,CAAK,EAGzF,EAA+D,CAE1E,CACE,GAAI,EAAG,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,GAAI,G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AyB,CACtD,IAAI,GAAU,GAAK,EAAU,KAAO,EAAU,GAC9C,GAAI,GAAW,EAAG,CAChB,IAAM,EAAW,KAAK,MAAM,EAAU,CAAC,EAAI,EAC3C,IAAW,GAAK,EAAW,IAAM,EAAW,GACxC,GAAW,IAAG,GAAU,GAC9B,CACA,OAAO,CACT,CAGA,IAAa,eAAkB,GAA4B,KAAK,MAAM,eAAe,CAAO,EAAI,CAAC,EAKjG,SAAgB,oBAAoB,EAAiB,EAAkC,CACrF,OAAO,EAAuB,QAAQ,CAAK,EAAE,CAAC,EAChD,CAEA,SAAgB,YAAY,EAAiB,EAAkC,CAC7E,OAAO,EAAc,QAAQ,CAAK,EAAE,CAAC,EACvC,CAGA,SAAgB,cAAc,EAAiB,EAAkC,CAC/E,OAAO,eAAe,CAAO,EAAI,oBAAoB,EAAS,CAAK,EAAI,YAAY,EAAS,CAAK,CACnG,CAGA,SAAgB,aAAa,EAA4B,CACvD,OAAO,GAAW,EAAI,EAAI,GAAW,GAAK,EAAI,CAChD"}
|
package/dist/canvas.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require("./errors.cjs");function drawToCanvas(t,n,r={}){let i=r.margin??4,a=r.scale??1,o=r.dark??`#000000`,s=r.light??`#ffffff`,c=(t.size+i*2)*a,l=globalThis.devicePixelRatio||1;n.width=c*l,n.height=c*l,n.style.width=`${c}px`,n.style.height=`${c}px`;let u=n.getContext(`2d`);if(!u)throw new e.SigilUnsupportedError(`Canvas 2D context unavailable`);u.scale(l,l),u.fillStyle=s,u.fillRect(0,0,c,c),u.fillStyle=o;for(let e=0;e<t.size;e++)for(let n=0;n<t.size;n++)t.get(n,e)&&u.fillRect((n+i)*a,(e+i)*a,a,a);return c}exports.drawToCanvas=drawToCanvas;
|
|
2
2
|
//# sourceMappingURL=canvas.cjs.map
|
package/dist/canvas.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas.cjs","names":[],"sources":["../src/canvas.ts"],"sourcesContent":["import type { QrCanvasOptions, QrMatrix } from './types';\n\n/**\n * Canvas rendering — the only DOM-touching output path.\n * Resizes the canvas to `(size + 2*margin) * scale` CSS pixels, backing-store\n * scaled by `devicePixelRatio`, and paints one `fillRect` per dark module.\n * Returns the CSS pixel size so callers can size wrappers.\n */\nexport function drawToCanvas(matrix: QrMatrix, canvas: HTMLCanvasElement, options: QrCanvasOptions = {}): number {\n const margin = options.margin ?? 4;\n const scale = options.scale ?? 1;\n const dark = options.dark ?? '#000000';\n const light = options.light ?? '#ffffff';\n const cssSize = (matrix.size + margin * 2) * scale;\n const dpr = globalThis.devicePixelRatio || 1;\n\n canvas.width = cssSize * dpr;\n canvas.height = cssSize * dpr;\n canvas.style.width = `${cssSize}px`;\n canvas.style.height = `${cssSize}px`;\n\n const ctx = canvas.getContext('2d');\n if (!ctx) throw new
|
|
1
|
+
{"version":3,"file":"canvas.cjs","names":[],"sources":["../src/canvas.ts"],"sourcesContent":["import { SigilUnsupportedError } from './errors';\nimport type { QrCanvasOptions, QrMatrix } from './types';\n\n/**\n * Canvas rendering — the only DOM-touching output path.\n * Resizes the canvas to `(size + 2*margin) * scale` CSS pixels, backing-store\n * scaled by `devicePixelRatio`, and paints one `fillRect` per dark module.\n * Returns the CSS pixel size so callers can size wrappers.\n */\nexport function drawToCanvas(matrix: QrMatrix, canvas: HTMLCanvasElement, options: QrCanvasOptions = {}): number {\n const margin = options.margin ?? 4;\n const scale = options.scale ?? 1;\n const dark = options.dark ?? '#000000';\n const light = options.light ?? '#ffffff';\n const cssSize = (matrix.size + margin * 2) * scale;\n const dpr = globalThis.devicePixelRatio || 1;\n\n canvas.width = cssSize * dpr;\n canvas.height = cssSize * dpr;\n canvas.style.width = `${cssSize}px`;\n canvas.style.height = `${cssSize}px`;\n\n const ctx = canvas.getContext('2d');\n if (!ctx) throw new SigilUnsupportedError('Canvas 2D context unavailable');\n ctx.scale(dpr, dpr);\n ctx.fillStyle = light;\n ctx.fillRect(0, 0, cssSize, cssSize);\n ctx.fillStyle = dark;\n for (let y = 0; y < matrix.size; y++)\n for (let x = 0; x < matrix.size; x++)\n if (matrix.get(x, y)) ctx.fillRect((x + margin) * scale, (y + margin) * scale, scale, scale);\n return cssSize;\n}\n"],"mappings":"gCASA,SAAgB,aAAa,EAAkB,EAA2B,EAA2B,CAAC,EAAW,CAC/G,IAAM,EAAS,EAAQ,QAAU,EAC3B,EAAQ,EAAQ,OAAS,EACzB,EAAO,EAAQ,MAAQ,UACvB,EAAQ,EAAQ,OAAS,UACzB,GAAW,EAAO,KAAO,EAAS,GAAK,EACvC,EAAM,WAAW,kBAAoB,EAE3C,EAAO,MAAQ,EAAU,EACzB,EAAO,OAAS,EAAU,EAC1B,EAAO,MAAM,MAAQ,GAAG,EAAQ,IAChC,EAAO,MAAM,OAAS,GAAG,EAAQ,IAEjC,IAAM,EAAM,EAAO,WAAW,IAAI,EAClC,GAAI,CAAC,EAAK,MAAM,IAAI,EAAA,sBAAsB,+BAA+B,EACzE,EAAI,MAAM,EAAK,CAAG,EAClB,EAAI,UAAY,EAChB,EAAI,SAAS,EAAG,EAAG,EAAS,CAAO,EACnC,EAAI,UAAY,EAChB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,KAAM,IAC/B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,KAAM,IAC3B,EAAO,IAAI,EAAG,CAAC,GAAG,EAAI,UAAU,EAAI,GAAU,GAAQ,EAAI,GAAU,EAAO,EAAO,CAAK,EAC/F,OAAO,CACT"}
|
package/dist/canvas.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../src/canvas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"canvas.d.ts","sourceRoot":"","sources":["../src/canvas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEzD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,OAAO,GAAE,eAAoB,GAAG,MAAM,CAuB/G"}
|
package/dist/canvas.js
CHANGED
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
function e(e, t, n = {}) {
|
|
3
|
-
let r = n.margin ?? 4, i = n.scale ?? 1, a = n.dark ?? "#000000", o = n.light ?? "#ffffff", s = (e.size + r * 2) * i, c = globalThis.devicePixelRatio || 1;
|
|
4
|
-
t.width = s * c, t.height = s * c, t.style.width = `${s}px`, t.style.height = `${s}px`;
|
|
5
|
-
let l = t.getContext("2d");
|
|
6
|
-
if (!l) throw Error("Canvas 2D context unavailable");
|
|
7
|
-
l.scale(c, c), l.fillStyle = o, l.fillRect(0, 0, s, s), l.fillStyle = a;
|
|
8
|
-
for (let t = 0; t < e.size; t++) for (let n = 0; n < e.size; n++) e.get(n, t) && l.fillRect((n + r) * i, (t + r) * i, i, i);
|
|
9
|
-
return s;
|
|
10
|
-
}
|
|
11
|
-
//#endregion
|
|
12
|
-
export { e as drawToCanvas };
|
|
13
|
-
|
|
1
|
+
import{SigilUnsupportedError as e}from"./errors.js";function drawToCanvas(t,n,r={}){let i=r.margin??4,a=r.scale??1,o=r.dark??`#000000`,s=r.light??`#ffffff`,c=(t.size+i*2)*a,l=globalThis.devicePixelRatio||1;n.width=c*l,n.height=c*l,n.style.width=`${c}px`,n.style.height=`${c}px`;let u=n.getContext(`2d`);if(!u)throw new e(`Canvas 2D context unavailable`);u.scale(l,l),u.fillStyle=s,u.fillRect(0,0,c,c),u.fillStyle=o;for(let e=0;e<t.size;e++)for(let n=0;n<t.size;n++)t.get(n,e)&&u.fillRect((n+i)*a,(e+i)*a,a,a);return c}export{drawToCanvas};
|
|
14
2
|
//# sourceMappingURL=canvas.js.map
|
package/dist/canvas.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas.js","names":[],"sources":["../src/canvas.ts"],"sourcesContent":["import type { QrCanvasOptions, QrMatrix } from './types';\n\n/**\n * Canvas rendering — the only DOM-touching output path.\n * Resizes the canvas to `(size + 2*margin) * scale` CSS pixels, backing-store\n * scaled by `devicePixelRatio`, and paints one `fillRect` per dark module.\n * Returns the CSS pixel size so callers can size wrappers.\n */\nexport function drawToCanvas(matrix: QrMatrix, canvas: HTMLCanvasElement, options: QrCanvasOptions = {}): number {\n const margin = options.margin ?? 4;\n const scale = options.scale ?? 1;\n const dark = options.dark ?? '#000000';\n const light = options.light ?? '#ffffff';\n const cssSize = (matrix.size + margin * 2) * scale;\n const dpr = globalThis.devicePixelRatio || 1;\n\n canvas.width = cssSize * dpr;\n canvas.height = cssSize * dpr;\n canvas.style.width = `${cssSize}px`;\n canvas.style.height = `${cssSize}px`;\n\n const ctx = canvas.getContext('2d');\n if (!ctx) throw new
|
|
1
|
+
{"version":3,"file":"canvas.js","names":[],"sources":["../src/canvas.ts"],"sourcesContent":["import { SigilUnsupportedError } from './errors';\nimport type { QrCanvasOptions, QrMatrix } from './types';\n\n/**\n * Canvas rendering — the only DOM-touching output path.\n * Resizes the canvas to `(size + 2*margin) * scale` CSS pixels, backing-store\n * scaled by `devicePixelRatio`, and paints one `fillRect` per dark module.\n * Returns the CSS pixel size so callers can size wrappers.\n */\nexport function drawToCanvas(matrix: QrMatrix, canvas: HTMLCanvasElement, options: QrCanvasOptions = {}): number {\n const margin = options.margin ?? 4;\n const scale = options.scale ?? 1;\n const dark = options.dark ?? '#000000';\n const light = options.light ?? '#ffffff';\n const cssSize = (matrix.size + margin * 2) * scale;\n const dpr = globalThis.devicePixelRatio || 1;\n\n canvas.width = cssSize * dpr;\n canvas.height = cssSize * dpr;\n canvas.style.width = `${cssSize}px`;\n canvas.style.height = `${cssSize}px`;\n\n const ctx = canvas.getContext('2d');\n if (!ctx) throw new SigilUnsupportedError('Canvas 2D context unavailable');\n ctx.scale(dpr, dpr);\n ctx.fillStyle = light;\n ctx.fillRect(0, 0, cssSize, cssSize);\n ctx.fillStyle = dark;\n for (let y = 0; y < matrix.size; y++)\n for (let x = 0; x < matrix.size; x++)\n if (matrix.get(x, y)) ctx.fillRect((x + margin) * scale, (y + margin) * scale, scale, scale);\n return cssSize;\n}\n"],"mappings":"oDASA,SAAgB,aAAa,EAAkB,EAA2B,EAA2B,CAAC,EAAW,CAC/G,IAAM,EAAS,EAAQ,QAAU,EAC3B,EAAQ,EAAQ,OAAS,EACzB,EAAO,EAAQ,MAAQ,UACvB,EAAQ,EAAQ,OAAS,UACzB,GAAW,EAAO,KAAO,EAAS,GAAK,EACvC,EAAM,WAAW,kBAAoB,EAE3C,EAAO,MAAQ,EAAU,EACzB,EAAO,OAAS,EAAU,EAC1B,EAAO,MAAM,MAAQ,GAAG,EAAQ,IAChC,EAAO,MAAM,OAAS,GAAG,EAAQ,IAEjC,IAAM,EAAM,EAAO,WAAW,IAAI,EAClC,GAAI,CAAC,EAAK,MAAM,IAAI,EAAsB,+BAA+B,EACzE,EAAI,MAAM,EAAK,CAAG,EAClB,EAAI,UAAY,EAChB,EAAI,SAAS,EAAG,EAAG,EAAS,CAAO,EACnC,EAAI,UAAY,EAChB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,KAAM,IAC/B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,KAAM,IAC3B,EAAO,IAAI,EAAG,CAAC,GAAG,EAAI,UAAU,EAAI,GAAU,GAAQ,EAAI,GAAU,EAAO,EAAO,CAAK,EAC/F,OAAO,CACT"}
|
package/dist/encode.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require("./errors.cjs"),t=require("./_tables.cjs"),n=require("./_format.cjs"),r=require("./_mask.cjs"),i=require("./_matrix.cjs"),a=require("./_reed-solomon.cjs"),o=require("./_segments.cjs");var s=40;function checkOptions(t){let{version:n,minVersion:r,mask:i,errorCorrection:a}=t,inRange=e=>Number.isInteger(e)&&e>=1&&e<=s;if(n!==void 0&&!inRange(n))throw new e.SigilOptionError(`version must be an integer 1–${s}, got ${n}`);if(r!==void 0&&!inRange(r))throw new e.SigilOptionError(`minVersion must be an integer 1–${s}, got ${r}`);if(n!==void 0&&r!==void 0&&r>n)throw new e.SigilOptionError(`minVersion (${r}) exceeds version (${n})`);if(i!==void 0&&(!Number.isInteger(i)||i<0||i>7))throw new e.SigilOptionError(`mask must be an integer 0–7, got ${i}`);if(a!==void 0&&!`LMQH`.includes(a))throw new e.SigilOptionError(`errorCorrection must be 'L', 'M', 'Q', or 'H'`)}function capacityFor(e,n,r){let i=t.CHAR_COUNT_BITS[r][t.versionGroup(e)],a=t.dataCodewords(e,n)*8-4-i;if(a<=0)return 0;switch(r){case`numeric`:return Math.floor(a/10)*3+(a%10>=7?2:+(a%10>=4));case`alphanumeric`:return Math.floor(a/11)*2+ +(a%11>=6);case`byte`:return Math.floor(a/8)}}function pickVersion(e,n,r){for(let i=r;i<=s;i++)if(o.segmentBits(e,i)<=t.dataCodewords(i,n)*8)return i;return null}function capacityError(t,n,r){let i=o.payloadLength(t),a=capacityFor(r,n,t.mode),s=t.mode===`byte`?`bytes`:`chars`;return new e.SigilCapacityError(`Input of ${i} ${s} exceeds QR capacity (${a} ${s} at version ${r}-${n})`,i,a,r)}function interleaveBlocks(e,n,r){let i=t.numEcBlocks(n,r),o=t.ecCodewordsPerBlock(n,r),s=t.totalCodewords(n),c=Math.floor(s/i)-o,l=s%i,u=[],d=0;for(let t=0;t<i;t++){let n=t>=i-l,r=e.slice(d,d+c+ +!!n);d+=r.length;let s=a.ecCodewords(r,o);u.push(n?[...r,...s]:[...r,0,...s])}let f=[];for(let e=0;e<u[0].length;e++)for(let t=0;t<i;t++)(e!==c||t>=i-l)&&f.push(u[t][e]);return f}function freezeMatrix(e,t){let n=e.map(e=>Object.freeze([...e]));return Object.freeze(n),Object.freeze({...t,get:(e,r)=>e>=0&&r>=0&&e<t.size&&r<t.size&&n[r][e]})}function encodeQr(a,c={}){if(checkOptions(c),a.length===0)throw new e.SigilOptionError(`Cannot encode an empty input`);let l=c.errorCorrection??`M`;if(typeof a!=`string`&&c.mode!==void 0&&c.mode!==`byte`)throw new e.SigilOptionError(`Uint8Array input can only be encoded in byte mode`);let u=c.mode??(typeof a==`string`?o.detectMode(a):`byte`);if(typeof a==`string`&&!isModeCompatible(a,u))throw new e.SigilOptionError(`Input cannot be encoded in ${u} mode`);let d=typeof a==`string`?o.payloadFromText(a,u):o.payloadFromBytes(a),f=c.version??pickVersion(d,l,c.minVersion??1);if(f===null||o.segmentBits(d,f)>t.dataCodewords(f,l)*8)throw capacityError(d,l,c.version??s);let p=interleaveBlocks(o.buildDataCodewords(d,f,l),f,l),m=i.createGrid(t.matrixSize(f));i.drawFunctionPatterns(m,f),i.placeData(m,p);let h=c.mask===void 0?[0,1,2,3,4,5,6,7]:[c.mask],g=h[0],_=1/0;for(let e of h){r.applyMask(m,e),n.drawFormatInfo(m,l,e);let t=r.penaltyScore(m);t<_&&(_=t,g=e),r.applyMask(m,e)}return r.applyMask(m,g),n.drawFormatInfo(m,l,g),n.drawVersionInfo(m,f),freezeMatrix(m.modules,{errorCorrection:l,mask:g,mode:u,size:m.size,version:f})}function isModeCompatible(e,n){return n===`numeric`?/^\d+$/.test(e):n!==`alphanumeric`||[...e].every(e=>t.ALPHANUMERIC_CHARSET.includes(e))}function qrCapacity(t,n,r){if(!Number.isInteger(t)||t<1||t>s)throw new e.SigilOptionError(`version must be an integer 1–${s}, got ${t}`);return capacityFor(t,n,r)}exports.encodeQr=encodeQr,exports.qrCapacity=qrCapacity;
|
|
2
2
|
//# sourceMappingURL=encode.cjs.map
|
package/dist/encode.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.cjs","names":[],"sources":["../src/encode.ts"],"sourcesContent":["import { warn } from './_dev';\nimport { drawFormatInfo, drawVersionInfo } from './_format';\nimport { applyMask, penaltyScore } from './_mask';\nimport { createGrid, drawFunctionPatterns, placeData } from './_matrix';\nimport { ecCodewords } from './_reed-solomon';\nimport { buildDataCodewords, detectMode, segmentBits } from './_segments';\nimport {\n ALPHANUMERIC_CHARSET,\n CHAR_COUNT_BITS,\n dataCodewords,\n ecCodewordsPerBlock,\n matrixSize,\n numEcBlocks,\n totalCodewords,\n versionGroup,\n} from './_tables';\nimport { SigilCapacityError, SigilOptionError } from './errors';\nimport type { QrEncodeOptions, QrErrorCorrection, QrMatrix, QrMode } from './types';\n\nconst MAX_VERSION = 40;\n\nfunction checkOptions(options: QrEncodeOptions): void {\n const { version, minVersion, mask, errorCorrection } = options;\n const inRange = (v: number) => Number.isInteger(v) && v >= 1 && v <= MAX_VERSION;\n if (version !== undefined && !inRange(version))\n throw new SigilOptionError(`version must be an integer 1–${MAX_VERSION}, got ${version}`);\n if (minVersion !== undefined && !inRange(minVersion))\n throw new SigilOptionError(`minVersion must be an integer 1–${MAX_VERSION}, got ${minVersion}`);\n if (version !== undefined && minVersion !== undefined && minVersion > version)\n throw new SigilOptionError(`minVersion (${minVersion}) exceeds version (${version})`);\n if (mask !== undefined && (!Number.isInteger(mask) || mask < 0 || mask > 7))\n throw new SigilOptionError(`mask must be an integer 0–7, got ${mask}`);\n if (errorCorrection !== undefined && !'LMQH'.includes(errorCorrection))\n throw new SigilOptionError(`errorCorrection must be 'L', 'M', 'Q', or 'H'`);\n}\n\n/** Character capacity of (version, level, mode) — the `qrCapacity` core. */\nfunction capacityFor(version: number, level: QrErrorCorrection, mode: QrMode): number {\n const countBits = CHAR_COUNT_BITS[mode][versionGroup(version)];\n const usable = dataCodewords(version, level) * 8 - 4 - countBits;\n if (usable <= 0) return 0;\n switch (mode) {\n case 'numeric':\n return Math.floor(usable / 10) * 3 + (usable % 10 >= 7 ? 2 : usable % 10 >= 4 ? 1 : 0);\n case 'alphanumeric':\n return Math.floor(usable / 11) * 2 + (usable % 11 >= 6 ? 1 : 0);\n case 'byte':\n return Math.floor(usable / 8);\n }\n}\n\n/** Smallest version ≥ minVersion whose data area fits the segment. */\nfunction pickVersion(data: string, mode: QrMode, level: QrErrorCorrection, minVersion: number): number {\n for (let v = minVersion; v <= MAX_VERSION; v++)\n if (segmentBits(data, mode, v) <= dataCodewords(v, level) * 8) return v;\n // Nothing fits — the caller reports against v40.\n return -1;\n}\n\n/** Split data codewords into EC blocks and interleave data + EC (§7.6). */\nfunction interleaveBlocks(data: readonly number[], version: number, level: QrErrorCorrection): number[] {\n const numBlocks = numEcBlocks(version, level);\n const ecLen = ecCodewordsPerBlock(version, level);\n const rawLen = totalCodewords(version);\n const shortLen = Math.floor(rawLen / numBlocks) - ecLen; // data codewords in a short block\n const numLong = rawLen % numBlocks; // long blocks carry one extra data codeword\n\n const blocks: number[][] = [];\n let offset = 0;\n for (let b = 0; b < numBlocks; b++) {\n const isLong = b >= numBlocks - numLong;\n const dat = data.slice(offset, offset + shortLen + (isLong ? 1 : 0));\n offset += dat.length;\n const ecc = ecCodewords(dat, ecLen);\n // Short blocks get a pad slot so every block array shares one length;\n // the slot is skipped during interleave below.\n blocks.push(isLong ? [...dat, ...ecc] : [...dat, 0, ...ecc]);\n }\n\n const out: number[] = [];\n for (let i = 0; i < blocks[0].length; i++)\n for (let b = 0; b < numBlocks; b++) {\n // Skip the pad slot on short blocks (index = shortLen).\n if (i !== shortLen || b >= numBlocks - numLong) out.push(blocks[b][i]);\n }\n return out;\n}\n\nfunction freezeMatrix(grid: readonly (readonly boolean[])[], meta: Omit<QrMatrix, 'modules' | 'get'>): QrMatrix {\n const modules = grid.map((row) => Object.freeze([...row]));\n Object.freeze(modules);\n return Object.freeze({\n ...meta,\n get: (x: number, y: number) => (x >= 0 && y >= 0 && x < meta.size && y < meta.size ? modules[y][x] : false),\n modules,\n });\n}\n\n/**\n * Encode `data` into a QR Model 2 symbol. Pure and synchronous.\n * Byte mode is UTF-8 without an ECI header — the industry-standard assumption.\n */\nexport function encodeQr(data: string | Uint8Array, options: QrEncodeOptions = {}): QrMatrix {\n checkOptions(options);\n const text = typeof data === 'string' ? data : new TextDecoder().decode(data);\n if (text.length === 0) throw new SigilOptionError('Cannot encode an empty input');\n\n const level = options.errorCorrection ?? 'M';\n const mode = options.mode ?? detectMode(text);\n if (mode !== 'byte' && detectMode(text) !== mode && !isModeCompatible(text, mode))\n throw new SigilOptionError(`Input cannot be encoded in ${mode} mode`);\n\n const version = options.version ?? pickVersion(text, mode, level, options.minVersion ?? 1);\n if (version === -1 || segmentBits(text, mode, version) > dataCodewords(version, level) * 8) {\n const bytes = new TextEncoder().encode(text).length;\n const max = capacityFor(options.version ?? MAX_VERSION, level, mode);\n throw new SigilCapacityError(\n `Input of ${bytes} bytes exceeds QR capacity (${max} ${mode === 'byte' ? 'bytes' : 'chars'} ` +\n `at version ${options.version ?? MAX_VERSION}-${level})`,\n bytes,\n max,\n options.version ?? MAX_VERSION,\n );\n }\n\n const used = segmentBits(text, mode, version);\n const capacity = dataCodewords(version, level) * 8;\n if (used / capacity > 0.9 && options.version === undefined)\n warn(\n `Payload uses ${Math.round((used / capacity) * 100)}% of version ${version}-${level} ` +\n `capacity; a slightly longer input will bump the QR size`,\n );\n\n const codewords = interleaveBlocks(buildDataCodewords(text, mode, version, level), version, level);\n const grid = createGrid(matrixSize(version));\n drawFunctionPatterns(grid, version);\n placeData(grid, codewords);\n\n // Try every mask (or the forced one), keep the lowest penalty.\n const candidates = options.mask !== undefined ? [options.mask] : [0, 1, 2, 3, 4, 5, 6, 7];\n let bestMask = candidates[0];\n let bestScore = Number.POSITIVE_INFINITY;\n let bestModules: boolean[][] | null = null;\n for (const m of candidates) {\n applyMask(grid, m);\n drawFormatInfo(grid, level, m);\n const score = penaltyScore(grid);\n if (score < bestScore) {\n bestScore = score;\n bestMask = m;\n bestModules = grid.modules.map((row) => [...row]);\n }\n applyMask(grid, m); // undo\n // Clear format info for the next candidate (function flags stay set).\n if (m !== candidates[candidates.length - 1]) clearFormat(grid);\n }\n\n grid.modules = bestModules as boolean[][];\n drawVersionInfo(grid, version);\n\n return freezeMatrix(grid.modules, {\n errorCorrection: level,\n mask: bestMask,\n mode,\n size: grid.size,\n version,\n });\n}\n\n/** Whether `text` is representable in `mode` (used when the mode is forced). */\nfunction isModeCompatible(text: string, mode: QrMode): boolean {\n if (mode === 'numeric') return /^\\d+$/.test(text);\n if (mode === 'alphanumeric') return [...text].every((ch) => ALPHANUMERIC_CHARSET.includes(ch));\n return true;\n}\n\n/** Un-mark and un-draw format modules so the next mask candidate starts clean. */\nfunction clearFormat(grid: ReturnType<typeof createGrid>): void {\n const size = grid.size;\n const cells: Array<readonly [number, number]> = [];\n for (let i = 0; i <= 8; i++) {\n if (i !== 6) {\n cells.push([8, i], [i, 8]);\n }\n }\n for (let i = 0; i < 8; i++) cells.push([size - 1 - i, 8]);\n for (let i = 0; i < 7; i++) cells.push([8, size - 1 - i]);\n cells.push([8, size - 8]);\n for (const [x, y] of cells) grid.modules[y][x] = false;\n}\n\n/** Max characters/bytes encodable at (version, level, mode). */\nexport function qrCapacity(version: number, errorCorrection: QrErrorCorrection, mode: QrMode): number {\n if (!Number.isInteger(version) || version < 1 || version > MAX_VERSION)\n throw new SigilOptionError(`version must be an integer 1–${MAX_VERSION}, got ${version}`);\n return capacityFor(version, errorCorrection, mode);\n}\n"],"mappings":"8NAmBA,IAAM,EAAc,GAEpB,SAAS,EAAa,EAAgC,CACpD,GAAM,CAAE,UAAS,aAAY,OAAM,mBAAoB,EACjD,EAAW,GAAc,OAAO,UAAU,CAAC,GAAK,GAAK,GAAK,GAAK,EACrE,GAAI,IAAY,IAAA,IAAa,CAAC,EAAQ,CAAO,EAC3C,MAAM,IAAI,EAAA,iBAAiB,gCAAgC,EAAY,QAAQ,GAAS,EAC1F,GAAI,IAAe,IAAA,IAAa,CAAC,EAAQ,CAAU,EACjD,MAAM,IAAI,EAAA,iBAAiB,mCAAmC,EAAY,QAAQ,GAAY,EAChG,GAAI,IAAY,IAAA,IAAa,IAAe,IAAA,IAAa,EAAa,EACpE,MAAM,IAAI,EAAA,iBA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AW,EAAW,OAAS,IAAI,EAAY,CAAI,CAC/D,CAKA,MAHA,GAAK,QAAU,EACf,EAAA,gBAAgB,EAAM,CAAO,EAEtB,EAAa,EAAK,QAAS,CAChC,gBAAiB,EACjB,KAAM,EACN,OACA,KAAM,EAAK,KACX,SACF,CAAC,CACH,CAGA,SAAS,EAAiB,EAAc,EAAuB,CAG7D,OAFI,IAAS,UAAkB,QAAQ,KAAK,CAAI,EAC5C,IAAS,gBAAuB,CAAC,GAAG,CAAI,CAAC,CAAC,MAAO,GAAO,EAAA,qBAAqB,SAAS,CAAE,CAAC,CAE/F,CAGA,SAAS,EAAY,EAA2C,CAC9D,IAAM,EAAO,EAAK,KACZ,EAA0C,CAAC,EACjD,IAAK,IAAI,EAAI,EAAG,GAAK,EAAG,IAClB,IAAM,GACR,EAAM,KAAK,CAAC,EAAG,CAAC,EAAG,CAAC,EAAG,CAAC,CAAC,EAG7B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,EAAM,KAAK,CAAC,EAAO,EAAI,EAAG,CAAC,CAAC,EACxD,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IAAK,EAAM,KAAK,CAAC,EAAG,EAAO,EAAI,CAAC,CAAC,EACxD,EAAM,KAAK,CAAC,EAAG,EAAO,CAAC,CAAC,EACxB,IAAK,GAAM,CAAC,EAAG,KAAM,EAAO,EAAK,QAAQ,EAAE,CAAC,GAAK,EACnD,CAGA,SAAgB,EAAW,EAAiB,EAAoC,EAAsB,CACpG,GAAI,CAAC,OAAO,UAAU,CAAO,GAAK,EAAU,GAAK,EAAU,EACzD,MAAM,IAAI,EAAA,iBAAiB,gCAAgC,EAAY,QAAQ,GAAS,EAC1F,OAAO,EAAY,EAAS,EAAiB,CAAI,CACnD"}
|
|
1
|
+
{"version":3,"file":"encode.cjs","names":[],"sources":["../src/encode.ts"],"sourcesContent":["import { drawFormatInfo, drawVersionInfo } from './_format';\nimport { applyMask, penaltyScore } from './_mask';\nimport { createGrid, drawFunctionPatterns, placeData } from './_matrix';\nimport { ecCodewords } from './_reed-solomon';\nimport {\n buildDataCodewords,\n detectMode,\n payloadFromBytes,\n payloadFromText,\n payloadLength,\n type QrPayload,\n segmentBits,\n} from './_segments';\nimport {\n ALPHANUMERIC_CHARSET,\n CHAR_COUNT_BITS,\n dataCodewords,\n ecCodewordsPerBlock,\n matrixSize,\n numEcBlocks,\n totalCodewords,\n versionGroup,\n} from './_tables';\nimport { SigilCapacityError, SigilOptionError } from './errors';\nimport type { QrEncodeOptions, QrErrorCorrection, QrMatrix, QrMode } from './types';\n\nconst MAX_VERSION = 40;\n\nfunction checkOptions(options: QrEncodeOptions): void {\n const { version, minVersion, mask, errorCorrection } = options;\n const inRange = (v: number) => Number.isInteger(v) && v >= 1 && v <= MAX_VERSION;\n if (version !== undefined && !inRange(version))\n throw new SigilOptionError(`version must be an integer 1–${MAX_VERSION}, got ${version}`);\n if (minVersion !== undefined && !inRange(minVersion))\n throw new SigilOptionError(`minVersion must be an integer 1–${MAX_VERSION}, got ${minVersion}`);\n if (version !== undefined && minVersion !== undefined && minVersion > version)\n throw new SigilOptionError(`minVersion (${minVersion}) exceeds version (${version})`);\n if (mask !== undefined && (!Number.isInteger(mask) || mask < 0 || mask > 7))\n throw new SigilOptionError(`mask must be an integer 0–7, got ${mask}`);\n if (errorCorrection !== undefined && !'LMQH'.includes(errorCorrection))\n throw new SigilOptionError(`errorCorrection must be 'L', 'M', 'Q', or 'H'`);\n}\n\n/** Character capacity of (version, level, mode) — the `qrCapacity` core. */\nfunction capacityFor(version: number, level: QrErrorCorrection, mode: QrMode): number {\n const countBits = CHAR_COUNT_BITS[mode][versionGroup(version)];\n const usable = dataCodewords(version, level) * 8 - 4 - countBits;\n if (usable <= 0) return 0;\n switch (mode) {\n case 'numeric':\n return Math.floor(usable / 10) * 3 + (usable % 10 >= 7 ? 2 : usable % 10 >= 4 ? 1 : 0);\n case 'alphanumeric':\n return Math.floor(usable / 11) * 2 + (usable % 11 >= 6 ? 1 : 0);\n case 'byte':\n return Math.floor(usable / 8);\n }\n}\n\n/** Smallest version ≥ minVersion whose data area fits the segment, or `null`. */\nfunction pickVersion(payload: QrPayload, level: QrErrorCorrection, minVersion: number): number | null {\n for (let v = minVersion; v <= MAX_VERSION; v++) if (segmentBits(payload, v) <= dataCodewords(v, level) * 8) return v;\n return null;\n}\n\n/** The capacity error for a payload that does not fit at `version`. */\nfunction capacityError(payload: QrPayload, level: QrErrorCorrection, version: number): SigilCapacityError {\n const length = payloadLength(payload);\n const max = capacityFor(version, level, payload.mode);\n const unit = payload.mode === 'byte' ? 'bytes' : 'chars';\n return new SigilCapacityError(\n `Input of ${length} ${unit} exceeds QR capacity (${max} ${unit} at version ${version}-${level})`,\n length,\n max,\n version,\n );\n}\n\n/** Split data codewords into EC blocks and interleave data + EC (§7.6). */\nfunction interleaveBlocks(data: readonly number[], version: number, level: QrErrorCorrection): number[] {\n const numBlocks = numEcBlocks(version, level);\n const ecLen = ecCodewordsPerBlock(version, level);\n const rawLen = totalCodewords(version);\n const shortLen = Math.floor(rawLen / numBlocks) - ecLen; // data codewords in a short block\n const numLong = rawLen % numBlocks; // long blocks carry one extra data codeword\n\n const blocks: number[][] = [];\n let offset = 0;\n for (let b = 0; b < numBlocks; b++) {\n const isLong = b >= numBlocks - numLong;\n const dat = data.slice(offset, offset + shortLen + (isLong ? 1 : 0));\n offset += dat.length;\n const ecc = ecCodewords(dat, ecLen);\n // Short blocks get a pad slot so every block array shares one length;\n // the slot is skipped during interleave below.\n blocks.push(isLong ? [...dat, ...ecc] : [...dat, 0, ...ecc]);\n }\n\n const out: number[] = [];\n for (let i = 0; i < blocks[0].length; i++)\n for (let b = 0; b < numBlocks; b++) {\n // Skip the pad slot on short blocks (index = shortLen).\n if (i !== shortLen || b >= numBlocks - numLong) out.push(blocks[b][i]);\n }\n return out;\n}\n\nfunction freezeMatrix(grid: readonly (readonly boolean[])[], meta: Omit<QrMatrix, 'get'>): QrMatrix {\n const modules = grid.map((row) => Object.freeze([...row]));\n Object.freeze(modules);\n return Object.freeze({\n ...meta,\n get: (x: number, y: number) => (x >= 0 && y >= 0 && x < meta.size && y < meta.size ? modules[y][x] : false),\n });\n}\n\n/**\n * Encode `data` into a QR Model 2 symbol. Pure and synchronous.\n * Strings pick the most compact mode; `Uint8Array` is raw binary and always\n * byte mode, encoded as-is — no UTF-8 round-trip. Byte mode is UTF-8 without\n * an ECI header for string input — the industry-standard assumption.\n */\nexport function encodeQr(data: string | Uint8Array, options: QrEncodeOptions = {}): QrMatrix {\n checkOptions(options);\n if (data.length === 0) throw new SigilOptionError('Cannot encode an empty input');\n\n const level = options.errorCorrection ?? 'M';\n if (typeof data !== 'string' && options.mode !== undefined && options.mode !== 'byte')\n throw new SigilOptionError('Uint8Array input can only be encoded in byte mode');\n const mode = options.mode ?? (typeof data === 'string' ? detectMode(data) : 'byte');\n if (typeof data === 'string' && !isModeCompatible(data, mode))\n throw new SigilOptionError(`Input cannot be encoded in ${mode} mode`);\n const payload = typeof data === 'string' ? payloadFromText(data, mode) : payloadFromBytes(data);\n\n const version = options.version ?? pickVersion(payload, level, options.minVersion ?? 1);\n if (version === null || segmentBits(payload, version) > dataCodewords(version, level) * 8)\n throw capacityError(payload, level, options.version ?? MAX_VERSION);\n\n const codewords = interleaveBlocks(buildDataCodewords(payload, version, level), version, level);\n const grid = createGrid(matrixSize(version));\n drawFunctionPatterns(grid, version);\n placeData(grid, codewords);\n\n // Try every mask (or the forced one), keep the lowest penalty. Each candidate\n // is undone by the idempotent XOR, and the final drawFormatInfo below rewrites\n // every format module, so candidates never leak into each other.\n const candidates = options.mask !== undefined ? [options.mask] : [0, 1, 2, 3, 4, 5, 6, 7];\n let bestMask = candidates[0];\n let bestScore = Number.POSITIVE_INFINITY;\n for (const m of candidates) {\n applyMask(grid, m);\n drawFormatInfo(grid, level, m);\n const score = penaltyScore(grid);\n if (score < bestScore) {\n bestScore = score;\n bestMask = m;\n }\n applyMask(grid, m); // undo\n }\n\n // The grid is unmasked again — draw the winning candidate once, finally.\n applyMask(grid, bestMask);\n drawFormatInfo(grid, level, bestMask);\n drawVersionInfo(grid, version);\n\n return freezeMatrix(grid.modules, {\n errorCorrection: level,\n mask: bestMask,\n mode,\n size: grid.size,\n version,\n });\n}\n\n/** Whether `text` is representable in `mode` (used when the mode is forced). */\nfunction isModeCompatible(text: string, mode: QrMode): boolean {\n if (mode === 'numeric') return /^\\d+$/.test(text);\n if (mode === 'alphanumeric') return [...text].every((ch) => ALPHANUMERIC_CHARSET.includes(ch));\n return true;\n}\n\n/** Max characters/bytes encodable at (version, level, mode). */\nexport function qrCapacity(version: number, errorCorrection: QrErrorCorrection, mode: QrMode): number {\n if (!Number.isInteger(version) || version < 1 || version > MAX_VERSION)\n throw new SigilOptionError(`version must be an integer 1–${MAX_VERSION}, got ${version}`);\n return capacityFor(version, errorCorrection, mode);\n}\n"],"mappings":"wMA0BA,IAAM,EAAc,GAEpB,SAAS,aAAa,EAAgC,CACpD,GAAM,CAAE,UAAS,aAAY,OAAM,mBAAoB,EACjD,QAAW,GAAc,OAAO,UAAU,CAAC,GAAK,GAAK,GAAK,GAAK,EACrE,GAAI,IAAY,IAAA,IAAa,CAAC,QAAQ,CAAO,EAC3C,MAAM,IAAI,EAAA,iBAAiB,gCAAgC,EAAY,QAAQ,GAAS,EAC1F,GAAI,IAAe,IAAA,IAAa,CAAC,QAAQ,CAAU,EACjD,MAAM,IAAI,EAAA,iBAAiB,mCAAmC,EAAY,QAAQ,GAAY,EAChG,GAAI,IAAY,IAAA,IAAa,IAAe,IAAA,IAAa,EAAa,EACpE,MAAM,IAAI,EAAA,iBAAiB,eAAe,EAAW,qBAAqB,EAAQ,EAAE,EACtF,GAAI,IAAS,IAAA,KAAc,CAAC,OAAO,UAAU,CAAI,GAAK,EAAO,GAAK,EAAO,GACvE,MAAM,IAAI,EAAA,iBAAiB,oCAAoC,GAAM,EACvE,GAAI,IAAoB,IAAA,IAAa,CAAC,OAAO,SAAS,CAAe,EACnE,MAA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AgB,WAAW,EAAiB,EAAoC,EAAsB,CACpG,GAAI,CAAC,OAAO,UAAU,CAAO,GAAK,EAAU,GAAK,EAAU,EACzD,MAAM,IAAI,EAAA,iBAAiB,gCAAgC,EAAY,QAAQ,GAAS,EAC1F,OAAO,YAAY,EAAS,EAAiB,CAAI,CACnD"}
|
package/dist/encode.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { QrEncodeOptions, QrErrorCorrection, QrMatrix, QrMode } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Encode `data` into a QR Model 2 symbol. Pure and synchronous.
|
|
4
|
-
*
|
|
4
|
+
* Strings pick the most compact mode; `Uint8Array` is raw binary and always
|
|
5
|
+
* byte mode, encoded as-is — no UTF-8 round-trip. Byte mode is UTF-8 without
|
|
6
|
+
* an ECI header for string input — the industry-standard assumption.
|
|
5
7
|
*/
|
|
6
8
|
export declare function encodeQr(data: string | Uint8Array, options?: QrEncodeOptions): QrMatrix;
|
|
7
9
|
/** Max characters/bytes encodable at (version, level, mode). */
|
package/dist/encode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AA2FpF;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,OAAO,GAAE,eAAoB,GAAG,QAAQ,CAkD3F;AASD,gEAAgE;AAChE,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIpG"}
|