@weft-js/plugin-surface-keel 0.1.0 → 0.1.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/README.md +312 -3
- package/package.json +12 -3
- package/src/index.d.ts +5 -1
- package/src/index.mjs +20 -5
- package/src/runtime.mjs +6 -2
- package/vendor/README.md +7 -4
- package/vendor/keel-render/core-primitives.mjs +478 -0
- package/vendor/keel-render/effects-world.mjs +439 -0
- package/vendor/keel-render/indexed-render.mjs +516 -0
- package/vendor/keel-render/pixel-raster.mjs +512 -0
- package/vendor/keel-render/render-passes.mjs +530 -0
- package/vendor/keel-render/renderer-api.mjs +121 -0
- package/vendor/keel-render.mjs +1 -2268
- package/vendor/keel-theme/codec-runtime.mjs +549 -0
- package/vendor/keel-theme/collection-codecs.mjs +360 -0
- package/vendor/keel-theme/color-font.mjs +471 -0
- package/vendor/keel-theme/glyph-theme.mjs +529 -0
- package/vendor/keel-theme/icon-schema.mjs +540 -0
- package/vendor/keel-theme/scalar-codecs.mjs +535 -0
- package/vendor/keel-theme/schema-codec.mjs +515 -0
- package/vendor/keel-theme/schema-theme.mjs +533 -0
- package/vendor/keel-theme.mjs +1 -3571
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
import './collection-codecs.mjs';
|
|
2
|
+
import {
|
|
3
|
+
BitWriter,
|
|
4
|
+
bitsFor,
|
|
5
|
+
} from './icon-schema.mjs';
|
|
6
|
+
import {
|
|
7
|
+
NUM_KINDS,
|
|
8
|
+
Tables,
|
|
9
|
+
categoryOf,
|
|
10
|
+
compileBool,
|
|
11
|
+
compileInt,
|
|
12
|
+
compileUint,
|
|
13
|
+
compiled,
|
|
14
|
+
describe,
|
|
15
|
+
fail,
|
|
16
|
+
meta,
|
|
17
|
+
put,
|
|
18
|
+
rd,
|
|
19
|
+
readNum,
|
|
20
|
+
same,
|
|
21
|
+
under,
|
|
22
|
+
unzig,
|
|
23
|
+
wr,
|
|
24
|
+
writeNum,
|
|
25
|
+
zig,
|
|
26
|
+
} from './schema-codec.mjs';
|
|
27
|
+
import {
|
|
28
|
+
compileArray,
|
|
29
|
+
compileBiguint,
|
|
30
|
+
compileBytes,
|
|
31
|
+
compileConst,
|
|
32
|
+
compileDefault,
|
|
33
|
+
compileDyn,
|
|
34
|
+
compileEnum,
|
|
35
|
+
compileFixed,
|
|
36
|
+
compileFloat,
|
|
37
|
+
compileGrow,
|
|
38
|
+
compileHex,
|
|
39
|
+
compileNullable,
|
|
40
|
+
compileNum,
|
|
41
|
+
compileRef,
|
|
42
|
+
compileString,
|
|
43
|
+
compileStruct,
|
|
44
|
+
compileTuple,
|
|
45
|
+
compileVarint,
|
|
46
|
+
} from './scalar-codecs.mjs';
|
|
47
|
+
import {
|
|
48
|
+
compileAlt,
|
|
49
|
+
compileDelta,
|
|
50
|
+
compileLz,
|
|
51
|
+
compileMap,
|
|
52
|
+
compileNamed,
|
|
53
|
+
compilePlanes,
|
|
54
|
+
compileRec,
|
|
55
|
+
compileRuns,
|
|
56
|
+
compileSelf,
|
|
57
|
+
compileUnion,
|
|
58
|
+
} from './collection-codecs.mjs';
|
|
59
|
+
|
|
60
|
+
function compile(n, recs) {
|
|
61
|
+
switch (n.kind) {
|
|
62
|
+
case "uint": return compileUint(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
63
|
+
case "int": return compileInt(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
64
|
+
case "bool": return compileBool(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
65
|
+
case "fixed": return compileFixed(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
66
|
+
case "float": return compileFloat(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
67
|
+
case "varuint":
|
|
68
|
+
case "varint": return compileVarint(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
69
|
+
case "num": return compileNum(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
70
|
+
case "biguint": return compileBiguint(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
71
|
+
case "enum": return compileEnum(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
72
|
+
case "string": return compileString(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
73
|
+
case "ref": return compileRef(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
74
|
+
case "bytes": return compileBytes(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
75
|
+
case "hex": return compileHex(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
76
|
+
case "const": return compileConst(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
77
|
+
case "dyn": return compileDyn(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
78
|
+
case "array": return compileArray(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
79
|
+
case "grow": return compileGrow(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
80
|
+
case "optional":
|
|
81
|
+
case "nullable": return compileNullable(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
82
|
+
case "default": return compileDefault(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
83
|
+
case "struct": return compileStruct(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
84
|
+
case "tuple": return compileTuple(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
85
|
+
case "union": return compileUnion(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
86
|
+
case "alt": return compileAlt(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
87
|
+
case "map": return compileMap(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
88
|
+
case "delta": return compileDelta(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
89
|
+
case "runs": return compileRuns(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
90
|
+
case "lz": return compileLz(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
91
|
+
case "planes": return compilePlanes(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
92
|
+
case "named": return compileNamed(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
93
|
+
case "rec": return compileRec(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
94
|
+
case "self": return compileSelf(n, recs, compile, dynCodec, structCodec, holds, valueCategory);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function compiled2(root) {
|
|
98
|
+
return compiled(root, compile);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function holds(n, v, recs = []) {
|
|
102
|
+
const fields = (fs, ext, tag) => {
|
|
103
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return true;
|
|
104
|
+
const rec = v;
|
|
105
|
+
const all = [...fs, ...ext.flat()];
|
|
106
|
+
for (const key in rec) if (rec[key] !== void 0 && key !== tag && !all.some((f) => f.name === key)) return false;
|
|
107
|
+
return all.every((f) => rec[f.name] === void 0 || holds(f.type, rec[f.name], recs));
|
|
108
|
+
};
|
|
109
|
+
switch (n.kind) {
|
|
110
|
+
case "named":
|
|
111
|
+
case "default":
|
|
112
|
+
case "optional":
|
|
113
|
+
return v === void 0 || holds(n.of, v, recs);
|
|
114
|
+
case "nullable":
|
|
115
|
+
return v === void 0 || v === null || holds(n.of, v, recs);
|
|
116
|
+
case "rec":
|
|
117
|
+
return holds(n.of, v, [...recs, n]);
|
|
118
|
+
case "self": {
|
|
119
|
+
const at = recs.length - 1 - n.depth;
|
|
120
|
+
return at < 0 || holds(recs[at], v, recs.slice(0, at));
|
|
121
|
+
}
|
|
122
|
+
case "array":
|
|
123
|
+
case "runs":
|
|
124
|
+
case "lz": {
|
|
125
|
+
if (!Array.isArray(v) && !(ArrayBuffer.isView(v) && !(v instanceof DataView))) return true;
|
|
126
|
+
const a = v;
|
|
127
|
+
if (n.kind === "array" && n.max && a.length > n.max) return false;
|
|
128
|
+
for (let k = 0; k < a.length; k += 1) if (!holds(n.of, a[k], recs)) return false;
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
case "tuple":
|
|
132
|
+
return !Array.isArray(v) || n.items.every((t, k) => holds(t, v[k], recs));
|
|
133
|
+
case "struct":
|
|
134
|
+
return fields(n.fields, n.ext, null);
|
|
135
|
+
case "union": {
|
|
136
|
+
const tag = typeof v === "object" && v !== null ? v[n.tag] : void 0;
|
|
137
|
+
const variant = n.variants.find((x) => x.name === tag)?.type;
|
|
138
|
+
return !variant || fields(variant.fields, variant.ext, n.tag);
|
|
139
|
+
}
|
|
140
|
+
case "alt": {
|
|
141
|
+
const cat = valueCategory(v);
|
|
142
|
+
const b = n.of.find((x) => categoryOf(x) === cat);
|
|
143
|
+
return !b || holds(b, v, recs);
|
|
144
|
+
}
|
|
145
|
+
case "map":
|
|
146
|
+
return typeof v !== "object" || v === null || Array.isArray(v) || Object.values(v).every((x) => x === void 0 || holds(n.value, x, recs));
|
|
147
|
+
case "grow":
|
|
148
|
+
return holds(n.of, v, recs);
|
|
149
|
+
default:
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function valueCategory(v) {
|
|
154
|
+
if (v === null) return "null";
|
|
155
|
+
if (Array.isArray(v)) return "array";
|
|
156
|
+
if (v instanceof Uint8Array) return "bytes";
|
|
157
|
+
const t = typeof v;
|
|
158
|
+
if (t === "number" || t === "string" || t === "boolean" || t === "bigint") return t;
|
|
159
|
+
return "object";
|
|
160
|
+
}
|
|
161
|
+
function structWriter(fs, groups, known, tagKey, open, scratch, empty) {
|
|
162
|
+
return function w(o, v, x) {
|
|
163
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) fail(`${describe(v)} is not an object.`);
|
|
164
|
+
const rec = v;
|
|
165
|
+
let k = 0;
|
|
166
|
+
let given = tagKey !== null && rec[tagKey] !== void 0 ? 1 : 0;
|
|
167
|
+
try {
|
|
168
|
+
for (; k < fs.length; k += 1) {
|
|
169
|
+
const f = fs[k];
|
|
170
|
+
const fv = rec[f.name];
|
|
171
|
+
if (fv !== void 0) given += 1;
|
|
172
|
+
f.c.w(o, fv, x);
|
|
173
|
+
}
|
|
174
|
+
} catch (e) {
|
|
175
|
+
throw under(e, fs[k].name, null);
|
|
176
|
+
}
|
|
177
|
+
if (x.strict) {
|
|
178
|
+
let all = 0;
|
|
179
|
+
for (const key in rec) if (rec[key] !== void 0) all += 1;
|
|
180
|
+
if (all > given) {
|
|
181
|
+
for (const g of groups) for (const f of g) if (rec[f.name] !== void 0) given += 1;
|
|
182
|
+
if (all > given) {
|
|
183
|
+
for (const key in rec) if (!known.has(key) && rec[key] !== void 0) fail(`Unknown field ${JSON.stringify(key)} (the fields are ${[...known].join(", ")}).`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (!open) return;
|
|
188
|
+
let count = groups.length;
|
|
189
|
+
while (count > 0 && empty(groups[count - 1], rec)) count -= 1;
|
|
190
|
+
o.golomb(count, 0);
|
|
191
|
+
for (let g = 0; g < count; g += 1) {
|
|
192
|
+
const s = scratch.pop() ?? new BitWriter(64);
|
|
193
|
+
s.reset();
|
|
194
|
+
const t0 = x.text.length;
|
|
195
|
+
for (const f of groups[g]) wr(f.c, s, rec[f.name], x, f.name);
|
|
196
|
+
o.golomb(s.length, 0);
|
|
197
|
+
o.golomb((x.text.length - t0) / 8, 0);
|
|
198
|
+
o.append(s);
|
|
199
|
+
scratch.push(s);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function structCodec(fields, open, ext, recs, node2, tagKey, compile) {
|
|
205
|
+
const fs = fields.map((f) => ({ name: f.name, c: compile(f.type, recs), optional: f.type.kind === "optional" }));
|
|
206
|
+
const groups = ext.map((g) => g.map((f) => ({ name: f.name, c: compile(f.type, recs), optional: f.type.kind === "optional", node: f.type })));
|
|
207
|
+
const known = new Set([...fields, ...ext.flat()].map((f) => f.name));
|
|
208
|
+
if (tagKey !== null) known.add(tagKey);
|
|
209
|
+
const proto = known.has("__proto__");
|
|
210
|
+
const scratch = [];
|
|
211
|
+
const empty = (g, v) => g.every((f) => v[f.name] === void 0 || f.node.kind === "default" && same(v[f.name], f.node.value));
|
|
212
|
+
return {
|
|
213
|
+
node: node2,
|
|
214
|
+
w: structWriter(fs, groups, known, tagKey, open, scratch, empty),
|
|
215
|
+
r(i, x) {
|
|
216
|
+
const out = {};
|
|
217
|
+
if (x.trace !== null || proto) {
|
|
218
|
+
for (let k = 0; k < fs.length; k += 1) {
|
|
219
|
+
const f = fs[k];
|
|
220
|
+
const v = rd(f.c, i, x, f.name);
|
|
221
|
+
if (v !== void 0 || !f.optional) put(out, f.name, v);
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
let k = 0;
|
|
225
|
+
try {
|
|
226
|
+
for (; k < fs.length; k += 1) {
|
|
227
|
+
const f = fs[k];
|
|
228
|
+
const v = f.c.r(i, x);
|
|
229
|
+
if (v !== void 0 || !f.optional) out[f.name] = v;
|
|
230
|
+
}
|
|
231
|
+
} catch (e) {
|
|
232
|
+
throw under(e, fs[k].name, null);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (!open) return out;
|
|
236
|
+
const s0 = i.at;
|
|
237
|
+
const count = i.golomb(0);
|
|
238
|
+
if (x.trace) meta(x, "groups", s0, i, count, `${count} extension group${count === 1 ? "" : "s"}`);
|
|
239
|
+
for (let g = 0; g < Math.max(count, groups.length); g += 1) {
|
|
240
|
+
const group = groups[g];
|
|
241
|
+
if (g >= count) {
|
|
242
|
+
for (const f of group) if (f.node.kind === "default") out[f.name] = structuredClone(f.node.value);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
const s1 = i.at;
|
|
246
|
+
const len2 = i.golomb(0);
|
|
247
|
+
const textLen = i.golomb(0);
|
|
248
|
+
if (x.trace) meta(x, `group ${g + 1}`, s1, i, len2, `${len2} bits, ${textLen} bytes of text`);
|
|
249
|
+
const start = i.at;
|
|
250
|
+
const t0 = x.tr.at;
|
|
251
|
+
if (!group) {
|
|
252
|
+
i.skip(len2);
|
|
253
|
+
x.tr.skip(textLen * 8);
|
|
254
|
+
if (x.trace) {
|
|
255
|
+
meta(x, `group ${g + 1} (unknown)`, start, i, null, "skipped: a newer schema's fields");
|
|
256
|
+
if (textLen) x.trace.meta(`group ${g + 1} text (unknown)`, t0, textLen * 8, null, "skipped");
|
|
257
|
+
}
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
for (const f of group) {
|
|
261
|
+
const v = rd(f.c, i, x, f.name);
|
|
262
|
+
if (v !== void 0 || !f.optional) out[f.name] = v;
|
|
263
|
+
}
|
|
264
|
+
if (i.at - start !== len2) fail(`Extension group ${g + 1} is ${len2} bits long but its fields read ${i.at - start}.`);
|
|
265
|
+
if (x.tr.at - t0 !== textLen * 8) fail(`Extension group ${g + 1} has ${textLen} bytes of text but its fields read ${(x.tr.at - t0) / 8}.`);
|
|
266
|
+
}
|
|
267
|
+
return out;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
var DYN_TABLE = "str";
|
|
272
|
+
var DYN_NUMS = "$dyn";
|
|
273
|
+
function writeDynObject(o, v, x, str, w) {
|
|
274
|
+
if (Array.isArray(v)) {
|
|
275
|
+
o.bits(6, 3);
|
|
276
|
+
o.golomb(v.length, 0);
|
|
277
|
+
for (let k = 0; k < v.length; k += 1) {
|
|
278
|
+
try {
|
|
279
|
+
w(o, v[k], x);
|
|
280
|
+
} catch (e) {
|
|
281
|
+
throw under(e, k, null);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (ArrayBuffer.isView(v)) fail("A typed array isn't JSON-like (dyn): give an array, or a typed schema.");
|
|
287
|
+
const rec = v;
|
|
288
|
+
const keys = Object.keys(rec).filter((k) => rec[k] !== void 0);
|
|
289
|
+
o.bits(7, 3);
|
|
290
|
+
const t = x.tables.shapes(DYN_NUMS);
|
|
291
|
+
const sig = JSON.stringify(keys);
|
|
292
|
+
const at = keys.length ? t.index.get(sig) : void 0;
|
|
293
|
+
if (at !== void 0) {
|
|
294
|
+
o.bool(true);
|
|
295
|
+
o.bits(at, bitsFor(t.list.length));
|
|
296
|
+
} else {
|
|
297
|
+
o.bool(false);
|
|
298
|
+
o.golomb(keys.length, 0);
|
|
299
|
+
for (const k of keys) str.w(o, k, x);
|
|
300
|
+
if (keys.length) {
|
|
301
|
+
t.index.set(sig, t.list.length);
|
|
302
|
+
t.list.push(keys);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
for (const k of keys) {
|
|
306
|
+
try {
|
|
307
|
+
w(o, rec[k], x);
|
|
308
|
+
} catch (e) {
|
|
309
|
+
throw under(e, k, null);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function dynWriter(str) {
|
|
316
|
+
const w = (o, v, x) => {
|
|
317
|
+
if (v === null) {
|
|
318
|
+
o.bits(0, 3);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
switch (typeof v) {
|
|
322
|
+
case "boolean":
|
|
323
|
+
o.bits(v ? 2 : 1, 3);
|
|
324
|
+
return;
|
|
325
|
+
case "number":
|
|
326
|
+
if (Number.isSafeInteger(v) && !Object.is(v, -0) && Math.abs(v) <= 2 ** 51) {
|
|
327
|
+
o.bits(3, 3);
|
|
328
|
+
o.golomb(zig(v), 0);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
o.bits(4, 3);
|
|
332
|
+
{
|
|
333
|
+
const t = x.tables.numbers(DYN_NUMS);
|
|
334
|
+
const at = t.index.get(v);
|
|
335
|
+
if (at !== void 0) {
|
|
336
|
+
o.bits(0, 2);
|
|
337
|
+
o.bits(at, bitsFor(t.list.length));
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
writeNum(o, v, 2);
|
|
341
|
+
t.index.set(v, t.list.length);
|
|
342
|
+
t.list.push(v);
|
|
343
|
+
}
|
|
344
|
+
return;
|
|
345
|
+
case "string":
|
|
346
|
+
o.bits(5, 3);
|
|
347
|
+
str.w(o, v, x);
|
|
348
|
+
return;
|
|
349
|
+
case "object": return writeDynObject(o, v, x, str, w);
|
|
350
|
+
default:
|
|
351
|
+
fail(`${typeof v} isn't JSON-like (dyn).`);
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
return w;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function dynReader(str, getSelf) {
|
|
358
|
+
const TAGS = ["null", "false", "true", "int", "number", "string", "array", "object"];
|
|
359
|
+
const r = (i, x) => {
|
|
360
|
+
const s = i.at;
|
|
361
|
+
const tag = i.bits(3);
|
|
362
|
+
if (x.trace) meta(x, "type", s, i, TAGS[tag], TAGS[tag]);
|
|
363
|
+
switch (tag) {
|
|
364
|
+
case 0:
|
|
365
|
+
return null;
|
|
366
|
+
case 1:
|
|
367
|
+
return false;
|
|
368
|
+
case 2:
|
|
369
|
+
return true;
|
|
370
|
+
case 3:
|
|
371
|
+
return unzig(i.golomb(0));
|
|
372
|
+
case 4: {
|
|
373
|
+
const s1 = i.at;
|
|
374
|
+
const k = i.bits(2);
|
|
375
|
+
const t = x.tables.numbers(DYN_NUMS);
|
|
376
|
+
if (k === 0) {
|
|
377
|
+
const at = i.bits(bitsFor(t.list.length));
|
|
378
|
+
if (x.trace) meta(x, "repeat", s1, i, at, `the number #${at} again`);
|
|
379
|
+
if (at >= t.list.length) fail(`The number #${at} again, of ${t.list.length}.`);
|
|
380
|
+
return t.list[at];
|
|
381
|
+
}
|
|
382
|
+
if (x.trace) meta(x, "kind", s1, i, NUM_KINDS[k], "");
|
|
383
|
+
const v = readNum(i, k);
|
|
384
|
+
if (t.index.has(v)) fail("A number written again in full (not canonical: it repeats by index).");
|
|
385
|
+
t.index.set(v, t.list.length);
|
|
386
|
+
t.list.push(v);
|
|
387
|
+
return v;
|
|
388
|
+
}
|
|
389
|
+
case 5:
|
|
390
|
+
return str.r(i, x);
|
|
391
|
+
case 6: {
|
|
392
|
+
const s1 = i.at;
|
|
393
|
+
const len2 = i.golomb(0);
|
|
394
|
+
if (x.trace) meta(x, "length", s1, i, len2, `${len2} items`);
|
|
395
|
+
const out = new Array(len2);
|
|
396
|
+
for (let k = 0; k < len2; k += 1) out[k] = x.trace ? rd(getSelf(), i, x, k) : r(i, x);
|
|
397
|
+
return out;
|
|
398
|
+
}
|
|
399
|
+
default: {
|
|
400
|
+
const t = x.tables.shapes(DYN_NUMS);
|
|
401
|
+
const s1 = i.at;
|
|
402
|
+
let keys;
|
|
403
|
+
if (i.bool()) {
|
|
404
|
+
const at = i.bits(bitsFor(t.list.length));
|
|
405
|
+
if (at >= t.list.length) fail(`Object shape #${at} of ${t.list.length}.`);
|
|
406
|
+
keys = t.list[at];
|
|
407
|
+
if (x.trace) meta(x, "shape", s1, i, at, `shaped like object #${at}: ${keys.length} keys`);
|
|
408
|
+
} else {
|
|
409
|
+
const count = i.golomb(0);
|
|
410
|
+
if (x.trace) meta(x, "keys", s1, i, count, `${count} keys, a new shape`);
|
|
411
|
+
keys = [];
|
|
412
|
+
for (let k = 0; k < count; k += 1) {
|
|
413
|
+
const key = str.r(i, x);
|
|
414
|
+
if (keys.includes(key)) fail(`The key ${JSON.stringify(key)} is in the object twice.`);
|
|
415
|
+
keys.push(key);
|
|
416
|
+
}
|
|
417
|
+
if (count) {
|
|
418
|
+
const sig = JSON.stringify(keys);
|
|
419
|
+
if (t.index.has(sig)) fail("An object's keys written again in full (not canonical: its shape repeats by index).");
|
|
420
|
+
t.index.set(sig, t.list.length);
|
|
421
|
+
t.list.push(keys);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
const out = {};
|
|
425
|
+
for (const key of keys) put(out, key, x.trace ? rd(getSelf(), i, x, key) : r(i, x));
|
|
426
|
+
return out;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
return r;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function dynCodec(n, compile) {
|
|
434
|
+
const str = compile({ kind: "ref", table: DYN_TABLE, packHex: false }, []);
|
|
435
|
+
const w = dynWriter(str);
|
|
436
|
+
|
|
437
|
+
const r = dynReader(str, () => self);
|
|
438
|
+
const self = { node: n, w, r };
|
|
439
|
+
return self;
|
|
440
|
+
}
|
|
441
|
+
var WRITER = new BitWriter(4096);
|
|
442
|
+
var TEXT = new BitWriter(1024);
|
|
443
|
+
var OUT = new BitWriter(4096);
|
|
444
|
+
var writerBusy = false;
|
|
445
|
+
function writeBody(o, c, value, x, bits) {
|
|
446
|
+
c.w(bits, value, x);
|
|
447
|
+
const text = x.text;
|
|
448
|
+
let n = text.length / 8;
|
|
449
|
+
o.align();
|
|
450
|
+
do {
|
|
451
|
+
const b = n % 128;
|
|
452
|
+
n = Math.floor(n / 128);
|
|
453
|
+
o.bits(b | (n > 0 ? 128 : 0), 8);
|
|
454
|
+
} while (n > 0);
|
|
455
|
+
o.append(bits);
|
|
456
|
+
o.align();
|
|
457
|
+
o.append(text);
|
|
458
|
+
}
|
|
459
|
+
function encodeRaw(schema, value, opts = {}) {
|
|
460
|
+
const reuse = !writerBusy;
|
|
461
|
+
const bits = reuse ? WRITER : new BitWriter(256);
|
|
462
|
+
const text = reuse ? TEXT : new BitWriter(64);
|
|
463
|
+
const out = reuse ? OUT : new BitWriter(256);
|
|
464
|
+
if (reuse) {
|
|
465
|
+
writerBusy = true;
|
|
466
|
+
bits.reset();
|
|
467
|
+
text.reset();
|
|
468
|
+
out.reset();
|
|
469
|
+
}
|
|
470
|
+
try {
|
|
471
|
+
writeBody(out, compiled2(schema), value, { tables: opts.tables ?? new Tables(), trace: null, strict: opts.strict ?? true, text, tr: null, last: null }, bits);
|
|
472
|
+
return out.finish();
|
|
473
|
+
} finally {
|
|
474
|
+
if (reuse) writerBusy = false;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// packages/codec/src/sha256.ts
|
|
479
|
+
var K = new Uint32Array([
|
|
480
|
+
1116352408,
|
|
481
|
+
1899447441,
|
|
482
|
+
3049323471,
|
|
483
|
+
3921009573,
|
|
484
|
+
961987163,
|
|
485
|
+
1508970993,
|
|
486
|
+
2453635748,
|
|
487
|
+
2870763221,
|
|
488
|
+
3624381080,
|
|
489
|
+
310598401,
|
|
490
|
+
607225278,
|
|
491
|
+
1426881987,
|
|
492
|
+
1925078388,
|
|
493
|
+
2162078206,
|
|
494
|
+
2614888103,
|
|
495
|
+
3248222580,
|
|
496
|
+
3835390401,
|
|
497
|
+
4022224774,
|
|
498
|
+
264347078,
|
|
499
|
+
604807628,
|
|
500
|
+
770255983,
|
|
501
|
+
1249150122,
|
|
502
|
+
1555081692,
|
|
503
|
+
1996064986,
|
|
504
|
+
2554220882,
|
|
505
|
+
2821834349,
|
|
506
|
+
2952996808,
|
|
507
|
+
3210313671,
|
|
508
|
+
3336571891,
|
|
509
|
+
3584528711,
|
|
510
|
+
113926993,
|
|
511
|
+
338241895,
|
|
512
|
+
666307205,
|
|
513
|
+
773529912,
|
|
514
|
+
1294757372,
|
|
515
|
+
1396182291,
|
|
516
|
+
1695183700,
|
|
517
|
+
1986661051,
|
|
518
|
+
2177026350,
|
|
519
|
+
2456956037,
|
|
520
|
+
2730485921,
|
|
521
|
+
2820302411,
|
|
522
|
+
3259730800,
|
|
523
|
+
3345764771,
|
|
524
|
+
3516065817,
|
|
525
|
+
3600352804,
|
|
526
|
+
4094571909,
|
|
527
|
+
275423344,
|
|
528
|
+
430227734,
|
|
529
|
+
506948616,
|
|
530
|
+
659060556,
|
|
531
|
+
883997877,
|
|
532
|
+
958139571,
|
|
533
|
+
1322822218,
|
|
534
|
+
1537002063,
|
|
535
|
+
1747873779,
|
|
536
|
+
1955562222,
|
|
537
|
+
2024104815,
|
|
538
|
+
2227730452,
|
|
539
|
+
2361852424,
|
|
540
|
+
2428436474,
|
|
541
|
+
2756734187,
|
|
542
|
+
3204031479,
|
|
543
|
+
3329325298
|
|
544
|
+
]);
|
|
545
|
+
|
|
546
|
+
export {
|
|
547
|
+
K,
|
|
548
|
+
encodeRaw,
|
|
549
|
+
};
|