@johnhenry/sitefile 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +467 -0
- package/README.md +55 -6
- package/lib/src/archive-writers.d.ts +12 -2
- package/lib/src/archive-writers.js +53 -10
- package/lib/src/canonical.d.ts +16 -0
- package/lib/src/canonical.js +46 -0
- package/lib/src/car.d.ts +34 -0
- package/lib/src/car.js +203 -0
- package/lib/src/checklinks.js +8 -2
- package/lib/src/cli/bake.js +4 -3
- package/lib/src/cli/build-image.d.ts +1 -0
- package/lib/src/cli/build-image.js +1 -0
- package/lib/src/cli/common.js +4 -1
- package/lib/src/cli/hosts.d.ts +5 -0
- package/lib/src/cli/hosts.js +78 -0
- package/lib/src/cli/images.js +23 -5
- package/lib/src/cli/import-config.d.ts +2 -0
- package/lib/src/cli/import-config.js +56 -0
- package/lib/src/cli/index.d.ts +3 -1
- package/lib/src/cli/index.js +31 -2
- package/lib/src/cli/integrity.d.ts +2 -0
- package/lib/src/cli/integrity.js +77 -0
- package/lib/src/cli/network.d.ts +7 -0
- package/lib/src/cli/network.js +14 -3
- package/lib/src/cli/serve-keys.d.ts +39 -0
- package/lib/src/cli/serve-keys.js +106 -0
- package/lib/src/cli/serve-worker.js +46 -8
- package/lib/src/cli/servers.d.ts +124 -1
- package/lib/src/cli/servers.js +705 -62
- package/lib/src/cli/up.d.ts +2 -0
- package/lib/src/cli/up.js +193 -0
- package/lib/src/cli/watch.d.ts +14 -1
- package/lib/src/cli/watch.js +20 -3
- package/lib/src/cli.js +138 -18
- package/lib/src/csp.d.ts +17 -0
- package/lib/src/csp.js +52 -0
- package/lib/src/dictionary.d.ts +16 -0
- package/lib/src/dictionary.js +89 -0
- package/lib/src/epub.d.ts +5 -0
- package/lib/src/epub.js +113 -0
- package/lib/src/errors.d.ts +22 -9
- package/lib/src/errors.js +20 -1
- package/lib/src/executor.d.ts +31 -1
- package/lib/src/executor.js +192 -22
- package/lib/src/explain.js +33 -3
- package/lib/src/export-for.d.ts +42 -0
- package/lib/src/export-for.js +466 -0
- package/lib/src/export-formats.d.ts +2 -2
- package/lib/src/export-formats.js +52 -2
- package/lib/src/fingerprint.d.ts +3 -1
- package/lib/src/fingerprint.js +32 -5
- package/lib/src/host-config.d.ts +34 -0
- package/lib/src/host-config.js +645 -0
- package/lib/src/hosts.d.ts +47 -0
- package/lib/src/hosts.js +106 -0
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +1 -1
- package/lib/src/integrity.d.ts +115 -0
- package/lib/src/integrity.js +273 -0
- package/lib/src/language/ast.d.ts +116 -3
- package/lib/src/language/ast.js +7 -1
- package/lib/src/language/parser.js +176 -7
- package/lib/src/language/validate.js +21 -0
- package/lib/src/links.d.ts +33 -0
- package/lib/src/links.js +271 -3
- package/lib/src/lint.d.ts +1 -1
- package/lib/src/lint.js +26 -1
- package/lib/src/mime-data.d.ts +2 -0
- package/lib/src/mime-data.js +92 -0
- package/lib/src/oci.d.ts +20 -2
- package/lib/src/oci.js +70 -28
- package/lib/src/outdated.d.ts +3 -0
- package/lib/src/outdated.js +4 -4
- package/lib/src/planner.d.ts +69 -2
- package/lib/src/planner.js +150 -8
- package/lib/src/plugins/cache.d.ts +11 -0
- package/lib/src/plugins/cache.js +29 -0
- package/lib/src/plugins/host.d.ts +51 -2
- package/lib/src/plugins/host.js +141 -16
- package/lib/src/plugins/wasm.js +1 -3
- package/lib/src/portable.d.ts +8 -0
- package/lib/src/portable.js +47 -0
- package/lib/src/precache.d.ts +33 -0
- package/lib/src/precache.js +75 -0
- package/lib/src/precompress.d.ts +19 -0
- package/lib/src/precompress.js +35 -0
- package/lib/src/qr.d.ts +18 -0
- package/lib/src/qr.js +372 -0
- package/lib/src/registry-ops.js +4 -2
- package/lib/src/reload-client.d.ts +2 -0
- package/lib/src/reload-client.js +304 -0
- package/lib/src/resources/archive.d.ts +36 -0
- package/lib/src/resources/archive.js +338 -67
- package/lib/src/resources/convert.js +3 -1
- package/lib/src/resources/https.d.ts +9 -1
- package/lib/src/resources/https.js +36 -0
- package/lib/src/resources/network.d.ts +25 -3
- package/lib/src/resources/network.js +77 -6
- package/lib/src/secrets.d.ts +12 -3
- package/lib/src/secrets.js +18 -5
- package/lib/src/serve-auth.d.ts +32 -0
- package/lib/src/serve-auth.js +112 -0
- package/lib/src/serve-rules.d.ts +83 -7
- package/lib/src/serve-rules.js +264 -53
- package/lib/src/server.d.ts +437 -10
- package/lib/src/server.js +1236 -52
- package/lib/src/servers-file.d.ts +36 -0
- package/lib/src/servers-file.js +101 -0
- package/lib/src/servers.d.ts +109 -7
- package/lib/src/servers.js +151 -29
- package/lib/src/single-file.d.ts +12 -0
- package/lib/src/single-file.js +147 -0
- package/lib/src/site.d.ts +54 -0
- package/lib/src/site.js +204 -6
- package/lib/src/store.js +9 -5
- package/lib/src/swbn.d.ts +10 -0
- package/lib/src/swbn.js +86 -0
- package/lib/src/toml.d.ts +17 -0
- package/lib/src/toml.js +323 -0
- package/lib/src/wacz.d.ts +6 -0
- package/lib/src/wacz.js +96 -0
- package/lib/src/warc.d.ts +28 -0
- package/lib/src/warc.js +252 -0
- package/lib/src/watch.d.ts +12 -1
- package/lib/src/watch.js +67 -1
- package/lib/src/wbn.d.ts +9 -1
- package/lib/src/wbn.js +23 -33
- package/lib/src/zstd.d.ts +4 -0
- package/lib/src/zstd.js +328 -0
- package/package.json +1 -1
package/lib/src/qr.js
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A QR Code encoder (ISO/IEC 18004), enough for `serve --qr` (issue #224): byte mode, error correction
|
|
3
|
+
* level M, the smallest version (1–40) that fits, and the mask with the lowest penalty. Ported as
|
|
4
|
+
* rust/src/qr.rs; both produce the same modules (test/fixtures/qr/*.txt are checked by both).
|
|
5
|
+
*/
|
|
6
|
+
// Error correction level M: codewords per block and number of blocks, by version (index 0 unused).
|
|
7
|
+
const ECC_PER_BLOCK = [-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];
|
|
8
|
+
const NUM_BLOCKS = [-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];
|
|
9
|
+
/** Format bits for level M are 00. */
|
|
10
|
+
const ECL_BITS = 0;
|
|
11
|
+
/** Raw data modules (bits) available in a version, after function patterns. */
|
|
12
|
+
function rawDataModules(ver) {
|
|
13
|
+
let result = (16 * ver + 128) * ver + 64;
|
|
14
|
+
if (ver >= 2) {
|
|
15
|
+
const numAlign = Math.floor(ver / 7) + 2;
|
|
16
|
+
result -= (25 * numAlign - 10) * numAlign - 55;
|
|
17
|
+
if (ver >= 7)
|
|
18
|
+
result -= 36;
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
function dataCodewords(ver) {
|
|
23
|
+
return Math.floor(rawDataModules(ver) / 8) - ECC_PER_BLOCK[ver] * NUM_BLOCKS[ver];
|
|
24
|
+
}
|
|
25
|
+
// ---------------------------------------------------------------- Reed-Solomon over GF(2^8/0x11D)
|
|
26
|
+
function gfMul(x, y) {
|
|
27
|
+
let z = 0;
|
|
28
|
+
for (let i = 7; i >= 0; i--) {
|
|
29
|
+
z = (z << 1) ^ ((z >>> 7) * 0x11d);
|
|
30
|
+
z ^= ((y >>> i) & 1) * x;
|
|
31
|
+
}
|
|
32
|
+
return z & 0xff;
|
|
33
|
+
}
|
|
34
|
+
function rsDivisor(degree) {
|
|
35
|
+
const result = new Array(degree).fill(0);
|
|
36
|
+
result[degree - 1] = 1;
|
|
37
|
+
let root = 1;
|
|
38
|
+
for (let i = 0; i < degree; i++) {
|
|
39
|
+
for (let j = 0; j < degree; j++) {
|
|
40
|
+
result[j] = gfMul(result[j], root);
|
|
41
|
+
if (j + 1 < degree)
|
|
42
|
+
result[j] = result[j] ^ result[j + 1];
|
|
43
|
+
}
|
|
44
|
+
root = gfMul(root, 0x02);
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
function rsRemainder(data, divisor) {
|
|
49
|
+
const result = divisor.map(() => 0);
|
|
50
|
+
for (const b of data) {
|
|
51
|
+
const factor = b ^ result.shift();
|
|
52
|
+
result.push(0);
|
|
53
|
+
divisor.forEach((coef, i) => (result[i] = result[i] ^ gfMul(coef, factor)));
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
class Builder {
|
|
58
|
+
version;
|
|
59
|
+
size;
|
|
60
|
+
modules;
|
|
61
|
+
isFunction;
|
|
62
|
+
constructor(version) {
|
|
63
|
+
this.version = version;
|
|
64
|
+
this.size = version * 4 + 17;
|
|
65
|
+
this.modules = Array.from({ length: this.size }, () => new Array(this.size).fill(false));
|
|
66
|
+
this.isFunction = Array.from({ length: this.size }, () => new Array(this.size).fill(false));
|
|
67
|
+
}
|
|
68
|
+
set(x, y, dark) {
|
|
69
|
+
this.modules[y][x] = dark;
|
|
70
|
+
this.isFunction[y][x] = true;
|
|
71
|
+
}
|
|
72
|
+
alignmentPositions() {
|
|
73
|
+
if (this.version === 1)
|
|
74
|
+
return [];
|
|
75
|
+
const numAlign = Math.floor(this.version / 7) + 2;
|
|
76
|
+
const step = this.version === 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
|
|
77
|
+
const result = [6];
|
|
78
|
+
for (let pos = this.size - 7; result.length < numAlign; pos -= step)
|
|
79
|
+
result.splice(1, 0, pos);
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
drawFunctionPatterns() {
|
|
83
|
+
for (let i = 0; i < this.size; i++) {
|
|
84
|
+
this.set(6, i, i % 2 === 0);
|
|
85
|
+
this.set(i, 6, i % 2 === 0);
|
|
86
|
+
}
|
|
87
|
+
this.finder(3, 3);
|
|
88
|
+
this.finder(this.size - 4, 3);
|
|
89
|
+
this.finder(3, this.size - 4);
|
|
90
|
+
const align = this.alignmentPositions();
|
|
91
|
+
const n = align.length;
|
|
92
|
+
for (let i = 0; i < n; i++) {
|
|
93
|
+
for (let j = 0; j < n; j++) {
|
|
94
|
+
if (!((i === 0 && j === 0) || (i === 0 && j === n - 1) || (i === n - 1 && j === 0)))
|
|
95
|
+
this.alignment(align[i], align[j]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
this.formatBits(0); // placeholder, overwritten after masking
|
|
99
|
+
this.versionBits();
|
|
100
|
+
}
|
|
101
|
+
finder(x, y) {
|
|
102
|
+
for (let dy = -4; dy <= 4; dy++) {
|
|
103
|
+
for (let dx = -4; dx <= 4; dx++) {
|
|
104
|
+
const dist = Math.max(Math.abs(dx), Math.abs(dy));
|
|
105
|
+
const xx = x + dx;
|
|
106
|
+
const yy = y + dy;
|
|
107
|
+
if (xx >= 0 && xx < this.size && yy >= 0 && yy < this.size)
|
|
108
|
+
this.set(xx, yy, dist !== 2 && dist !== 4);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
alignment(x, y) {
|
|
113
|
+
for (let dy = -2; dy <= 2; dy++)
|
|
114
|
+
for (let dx = -2; dx <= 2; dx++)
|
|
115
|
+
this.set(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);
|
|
116
|
+
}
|
|
117
|
+
formatBits(mask) {
|
|
118
|
+
const data = (ECL_BITS << 3) | mask;
|
|
119
|
+
let rem = data;
|
|
120
|
+
for (let i = 0; i < 10; i++)
|
|
121
|
+
rem = (rem << 1) ^ ((rem >>> 9) * 0x537);
|
|
122
|
+
const bits = ((data << 10) | rem) ^ 0x5412;
|
|
123
|
+
const bit = (i) => ((bits >>> i) & 1) !== 0;
|
|
124
|
+
for (let i = 0; i <= 5; i++)
|
|
125
|
+
this.set(8, i, bit(i));
|
|
126
|
+
this.set(8, 7, bit(6));
|
|
127
|
+
this.set(8, 8, bit(7));
|
|
128
|
+
this.set(7, 8, bit(8));
|
|
129
|
+
for (let i = 9; i < 15; i++)
|
|
130
|
+
this.set(14 - i, 8, bit(i));
|
|
131
|
+
for (let i = 0; i < 8; i++)
|
|
132
|
+
this.set(this.size - 1 - i, 8, bit(i));
|
|
133
|
+
for (let i = 8; i < 15; i++)
|
|
134
|
+
this.set(8, this.size - 15 + i, bit(i));
|
|
135
|
+
this.set(8, this.size - 8, true);
|
|
136
|
+
}
|
|
137
|
+
versionBits() {
|
|
138
|
+
if (this.version < 7)
|
|
139
|
+
return;
|
|
140
|
+
let rem = this.version;
|
|
141
|
+
for (let i = 0; i < 12; i++)
|
|
142
|
+
rem = (rem << 1) ^ ((rem >>> 11) * 0x1f25);
|
|
143
|
+
const bits = (this.version << 12) | rem;
|
|
144
|
+
for (let i = 0; i < 18; i++) {
|
|
145
|
+
const dark = ((bits >>> i) & 1) !== 0;
|
|
146
|
+
const a = this.size - 11 + (i % 3);
|
|
147
|
+
const b = Math.floor(i / 3);
|
|
148
|
+
this.set(a, b, dark);
|
|
149
|
+
this.set(b, a, dark);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
drawCodewords(data) {
|
|
153
|
+
let i = 0;
|
|
154
|
+
for (let right = this.size - 1; right >= 1; right -= 2) {
|
|
155
|
+
if (right === 6)
|
|
156
|
+
right = 5;
|
|
157
|
+
for (let vert = 0; vert < this.size; vert++) {
|
|
158
|
+
for (let j = 0; j < 2; j++) {
|
|
159
|
+
const x = right - j;
|
|
160
|
+
const upward = ((right + 1) & 2) === 0;
|
|
161
|
+
const y = upward ? this.size - 1 - vert : vert;
|
|
162
|
+
if (!this.isFunction[y][x] && i < data.length * 8) {
|
|
163
|
+
this.modules[y][x] = ((data[i >>> 3] >>> (7 - (i & 7))) & 1) !== 0;
|
|
164
|
+
i++;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
applyMask(mask) {
|
|
171
|
+
for (let y = 0; y < this.size; y++) {
|
|
172
|
+
for (let x = 0; x < this.size; x++) {
|
|
173
|
+
let invert;
|
|
174
|
+
switch (mask) {
|
|
175
|
+
case 0:
|
|
176
|
+
invert = (x + y) % 2 === 0;
|
|
177
|
+
break;
|
|
178
|
+
case 1:
|
|
179
|
+
invert = y % 2 === 0;
|
|
180
|
+
break;
|
|
181
|
+
case 2:
|
|
182
|
+
invert = x % 3 === 0;
|
|
183
|
+
break;
|
|
184
|
+
case 3:
|
|
185
|
+
invert = (x + y) % 3 === 0;
|
|
186
|
+
break;
|
|
187
|
+
case 4:
|
|
188
|
+
invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;
|
|
189
|
+
break;
|
|
190
|
+
case 5:
|
|
191
|
+
invert = ((x * y) % 2) + ((x * y) % 3) === 0;
|
|
192
|
+
break;
|
|
193
|
+
case 6:
|
|
194
|
+
invert = (((x * y) % 2) + ((x * y) % 3)) % 2 === 0;
|
|
195
|
+
break;
|
|
196
|
+
default: invert = (((x + y) % 2) + ((x * y) % 3)) % 2 === 0;
|
|
197
|
+
}
|
|
198
|
+
const row = this.modules[y];
|
|
199
|
+
if (!this.isFunction[y][x] && invert)
|
|
200
|
+
row[x] = !row[x];
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
penalty() {
|
|
205
|
+
const n = this.size;
|
|
206
|
+
const m = this.modules;
|
|
207
|
+
const at = (x, y) => m[y][x];
|
|
208
|
+
let result = 0;
|
|
209
|
+
// Runs of five or more same-colored modules, and finder-like patterns, in rows and columns.
|
|
210
|
+
for (const horizontal of [true, false]) {
|
|
211
|
+
for (let a = 0; a < n; a++) {
|
|
212
|
+
let runColor = false;
|
|
213
|
+
let runLen = 0;
|
|
214
|
+
const history = [0, 0, 0, 0, 0, 0, 0];
|
|
215
|
+
for (let b = 0; b < n; b++) {
|
|
216
|
+
const c = horizontal ? at(b, a) : at(a, b);
|
|
217
|
+
if (c === runColor) {
|
|
218
|
+
runLen++;
|
|
219
|
+
if (runLen === 5)
|
|
220
|
+
result += 3;
|
|
221
|
+
else if (runLen > 5)
|
|
222
|
+
result++;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
finderPenaltyAddHistory(runLen, history, n);
|
|
226
|
+
if (!runColor)
|
|
227
|
+
result += finderPenaltyCountPatterns(history, n) * 40;
|
|
228
|
+
runColor = c;
|
|
229
|
+
runLen = 1;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
result += finderPenaltyTerminateAndCount(runColor, runLen, history, n) * 40;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// 2×2 blocks of one color.
|
|
236
|
+
for (let y = 0; y < n - 1; y++) {
|
|
237
|
+
for (let x = 0; x < n - 1; x++) {
|
|
238
|
+
const c = at(x, y);
|
|
239
|
+
if (c === at(x + 1, y) && c === at(x, y + 1) && c === at(x + 1, y + 1))
|
|
240
|
+
result += 3;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// Balance of dark modules.
|
|
244
|
+
let dark = 0;
|
|
245
|
+
for (const row of m)
|
|
246
|
+
for (const c of row)
|
|
247
|
+
if (c)
|
|
248
|
+
dark++;
|
|
249
|
+
const total = n * n;
|
|
250
|
+
const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
|
|
251
|
+
result += k * 10;
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function finderPenaltyCountPatterns(h, size) {
|
|
256
|
+
void size;
|
|
257
|
+
const n = h[1];
|
|
258
|
+
const core = n > 0 && h[2] === n && h[3] === n * 3 && h[4] === n && h[5] === n;
|
|
259
|
+
return (core && h[0] >= n * 4 && h[6] >= n ? 1 : 0) + (core && h[6] >= n * 4 && h[0] >= n ? 1 : 0);
|
|
260
|
+
}
|
|
261
|
+
function finderPenaltyTerminateAndCount(runColor, runLen, history, size) {
|
|
262
|
+
let len = runLen;
|
|
263
|
+
if (runColor) {
|
|
264
|
+
finderPenaltyAddHistory(len, history, size);
|
|
265
|
+
len = 0;
|
|
266
|
+
}
|
|
267
|
+
len += size;
|
|
268
|
+
finderPenaltyAddHistory(len, history, size);
|
|
269
|
+
return finderPenaltyCountPatterns(history, size);
|
|
270
|
+
}
|
|
271
|
+
function finderPenaltyAddHistory(runLen, history, size) {
|
|
272
|
+
let len = runLen;
|
|
273
|
+
if (history[0] === 0)
|
|
274
|
+
len += size;
|
|
275
|
+
history.pop();
|
|
276
|
+
history.unshift(len);
|
|
277
|
+
}
|
|
278
|
+
/** Encode `text` (UTF-8) as a QR Code, or undefined when it is too long for version 40. */
|
|
279
|
+
export function encodeQr(text) {
|
|
280
|
+
const bytes = [...new TextEncoder().encode(text)];
|
|
281
|
+
let version = 1;
|
|
282
|
+
for (; version <= 40; version++) {
|
|
283
|
+
const countBits = version < 10 ? 8 : 16;
|
|
284
|
+
if (4 + countBits + bytes.length * 8 <= dataCodewords(version) * 8)
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
if (version > 40)
|
|
288
|
+
return undefined;
|
|
289
|
+
// Bit stream: mode 0100 (byte), count, data, terminator, padding.
|
|
290
|
+
const bits = [];
|
|
291
|
+
const append = (val, len) => {
|
|
292
|
+
for (let i = len - 1; i >= 0; i--)
|
|
293
|
+
bits.push((val >>> i) & 1);
|
|
294
|
+
};
|
|
295
|
+
append(4, 4);
|
|
296
|
+
append(bytes.length, version < 10 ? 8 : 16);
|
|
297
|
+
for (const b of bytes)
|
|
298
|
+
append(b, 8);
|
|
299
|
+
const capacity = dataCodewords(version) * 8;
|
|
300
|
+
append(0, Math.min(4, capacity - bits.length));
|
|
301
|
+
append(0, (8 - (bits.length % 8)) % 8);
|
|
302
|
+
for (let pad = 0xec; bits.length < capacity; pad ^= 0xec ^ 0x11)
|
|
303
|
+
append(pad, 8);
|
|
304
|
+
const data = [];
|
|
305
|
+
for (let i = 0; i < bits.length; i += 8)
|
|
306
|
+
data.push(bits.slice(i, i + 8).reduce((a, b) => (a << 1) | b, 0));
|
|
307
|
+
// Split into blocks, add error correction, interleave.
|
|
308
|
+
const numBlocks = NUM_BLOCKS[version];
|
|
309
|
+
const blockEcc = ECC_PER_BLOCK[version];
|
|
310
|
+
const rawCodewords = Math.floor(rawDataModules(version) / 8);
|
|
311
|
+
const numShort = numBlocks - (rawCodewords % numBlocks);
|
|
312
|
+
const shortLen = Math.floor(rawCodewords / numBlocks);
|
|
313
|
+
const divisor = rsDivisor(blockEcc);
|
|
314
|
+
const blocks = [];
|
|
315
|
+
for (let i = 0, k = 0; i < numBlocks; i++) {
|
|
316
|
+
const dat = data.slice(k, k + shortLen - blockEcc + (i < numShort ? 0 : 1));
|
|
317
|
+
k += dat.length;
|
|
318
|
+
const ecc = rsRemainder(dat, divisor);
|
|
319
|
+
if (i < numShort)
|
|
320
|
+
dat.push(0);
|
|
321
|
+
blocks.push([...dat, ...ecc]);
|
|
322
|
+
}
|
|
323
|
+
const codewords = [];
|
|
324
|
+
for (let i = 0; i < blocks[0].length; i++) {
|
|
325
|
+
blocks.forEach((block, j) => {
|
|
326
|
+
if (i !== shortLen - blockEcc || j >= numShort)
|
|
327
|
+
codewords.push(block[i]);
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
// Draw, then keep the mask with the lowest penalty (the first one on a tie).
|
|
331
|
+
let best;
|
|
332
|
+
let bestPenalty = Infinity;
|
|
333
|
+
for (let mask = 0; mask < 8; mask++) {
|
|
334
|
+
const b = new Builder(version);
|
|
335
|
+
b.drawFunctionPatterns();
|
|
336
|
+
b.drawCodewords(codewords);
|
|
337
|
+
b.applyMask(mask);
|
|
338
|
+
b.formatBits(mask);
|
|
339
|
+
const p = b.penalty();
|
|
340
|
+
if (p < bestPenalty) {
|
|
341
|
+
best = b;
|
|
342
|
+
bestPenalty = p;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const b = best;
|
|
346
|
+
return { version, size: b.size, modules: b.modules };
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* The code for a terminal: two rows of modules per line with `▀`, `▄`, `█` and spaces, and a quiet zone
|
|
350
|
+
* of two modules, dark on a light background (the half blocks are the light parts' complement).
|
|
351
|
+
*/
|
|
352
|
+
export function qrTerminal(code) {
|
|
353
|
+
const quiet = 2;
|
|
354
|
+
const n = code.size + quiet * 2;
|
|
355
|
+
const dark = (x, y) => {
|
|
356
|
+
const xx = x - quiet;
|
|
357
|
+
const yy = y - quiet;
|
|
358
|
+
return xx >= 0 && yy >= 0 && xx < code.size && yy < code.size && code.modules[yy][xx];
|
|
359
|
+
};
|
|
360
|
+
let out = '';
|
|
361
|
+
for (let y = 0; y < n; y += 2) {
|
|
362
|
+
let line = '';
|
|
363
|
+
for (let x = 0; x < n; x++) {
|
|
364
|
+
const top = !dark(x, y);
|
|
365
|
+
const bottom = y + 1 < n ? !dark(x, y + 1) : false;
|
|
366
|
+
line += top && bottom ? '█' : top ? '▀' : bottom ? '▄' : ' ';
|
|
367
|
+
}
|
|
368
|
+
out += `${line}\n`;
|
|
369
|
+
}
|
|
370
|
+
return out;
|
|
371
|
+
}
|
|
372
|
+
//# sourceMappingURL=qr.js.map
|
package/lib/src/registry-ops.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { ATTEST, referrersTag } from './attest.js';
|
|
3
3
|
import { isSitefileError, SitefileError } from './errors.js';
|
|
4
|
-
import { canonicalJson, MEDIA, parseConfig, parseManifest, parsePlatform } from './oci.js';
|
|
4
|
+
import { canonicalJson, MEDIA, parseConfig, parseManifest, parsePlatform, siteLayerIndices } from './oci.js';
|
|
5
5
|
import { parseRef, withDefaultRegistry } from './ref.js';
|
|
6
6
|
import { shortId, Store } from './store.js';
|
|
7
7
|
const CONFIG_TYPES = new Set([MEDIA.config, MEDIA.dockerConfig]);
|
|
@@ -149,7 +149,9 @@ export async function pushImage(store, client, id, ref, o = {}) {
|
|
|
149
149
|
const b = withDefaultRegistry(parseRef(ann));
|
|
150
150
|
if (b.registry === client.registry && b.name !== repo) {
|
|
151
151
|
mountFrom = b.name;
|
|
152
|
-
|
|
152
|
+
// Every layer but the site layers (`--oci-layers` may give several).
|
|
153
|
+
const site = new Set(siteLayerIndices(parsed, parseConfig(await store.readBlob(parsed.config.digest))));
|
|
154
|
+
baseLayers = new Set(parsed.layers.filter((_, i) => !site.has(i)).map((l) => l.digest));
|
|
153
155
|
}
|
|
154
156
|
}
|
|
155
157
|
catch {
|