@cbortech/cbor 0.27.1 → 0.27.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.ja.md +27 -0
  2. package/README.md +28 -0
  3. package/dist/ast/CborItem.d.ts +17 -2
  4. package/dist/ast/CborTag.d.ts +22 -0
  5. package/dist/ast/CborUnresolvedAppExt.d.ts +9 -0
  6. package/dist/ast/index.cjs +1 -1
  7. package/dist/ast/index.js +2 -2
  8. package/dist/cbor/tagLabels.d.ts +26 -0
  9. package/dist/cddl/eRefScope.d.ts +241 -0
  10. package/dist/cddl/eref.d.ts +64 -0
  11. package/dist/cddl/implicitTags.d.ts +28 -0
  12. package/dist/cddl/index.cjs +2 -2
  13. package/dist/cddl/index.cjs.map +1 -1
  14. package/dist/cddl/index.d.ts +2 -0
  15. package/dist/cddl/index.js +26 -25
  16. package/dist/cddl/index.js.map +1 -1
  17. package/dist/cddl/validator.d.ts +98 -2
  18. package/dist/cdn/index.cjs +1 -1
  19. package/dist/cdn/index.js +1 -1
  20. package/dist/cdn/serialize-utils.d.ts +20 -13
  21. package/dist/extensions/eref.d.ts +135 -0
  22. package/dist/index.cjs +7 -7
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.ts +1 -0
  25. package/dist/index.js +190 -81
  26. package/dist/index.js.map +1 -1
  27. package/dist/js/fromJS.d.ts +23 -1
  28. package/dist/mapEntries-8zshEr-t.js +7085 -0
  29. package/dist/mapEntries-8zshEr-t.js.map +1 -0
  30. package/dist/mapEntries-DwHPAzCN.cjs +68 -0
  31. package/dist/mapEntries-DwHPAzCN.cjs.map +1 -0
  32. package/dist/schema-7r2xjpMK.js +345 -0
  33. package/dist/schema-7r2xjpMK.js.map +1 -0
  34. package/dist/schema-YiigSWjR.cjs +8 -0
  35. package/dist/schema-YiigSWjR.cjs.map +1 -0
  36. package/dist/{serialize-utils-h-CVB9rg.js → serialize-utils-BQtutOo6.js} +14 -6
  37. package/dist/serialize-utils-BQtutOo6.js.map +1 -0
  38. package/dist/{serialize-utils-DhlW61ZX.cjs → serialize-utils-DQ8T3Mzw.cjs} +5 -5
  39. package/dist/serialize-utils-DQ8T3Mzw.cjs.map +1 -0
  40. package/dist/types.d.ts +153 -4
  41. package/package.json +8 -8
  42. package/dist/mapEntries-CCLaJSaJ.js +0 -4127
  43. package/dist/mapEntries-CCLaJSaJ.js.map +0 -1
  44. package/dist/mapEntries-CZZJScaj.cjs +0 -13
  45. package/dist/mapEntries-CZZJScaj.cjs.map +0 -1
  46. package/dist/schema-DN9inJny.js +0 -1977
  47. package/dist/schema-DN9inJny.js.map +0 -1
  48. package/dist/schema-zsg5yCPK.cjs +0 -63
  49. package/dist/schema-zsg5yCPK.cjs.map +0 -1
  50. package/dist/serialize-utils-DhlW61ZX.cjs.map +0 -1
  51. package/dist/serialize-utils-h-CVB9rg.js.map +0 -1
@@ -1,4127 +0,0 @@
1
- import { A as e, C as t, D as n, E as r, F as i, I as a, M as o, N as s, O as c, P as l, S as u, T as d, _ as f, a as p, b as m, c as h, d as g, f as _, g as v, h as y, i as b, j as ee, k as x, l as S, m as C, n as w, o as T, p as te, r as E, s as ne, t as D, u as re, v as ie, w as O, x as ae, y as oe } from "./serialize-utils-h-CVB9rg.js";
2
- //#region src/tag.ts
3
- var se = Symbol.for("cbor.tag"), ce = class {
4
- valueOf() {
5
- return null;
6
- }
7
- toJSON() {
8
- return null;
9
- }
10
- }, le = class {
11
- valueOf() {}
12
- toJSON() {}
13
- };
14
- function ue(e) {
15
- if (!me(e)) return;
16
- let t = e[se];
17
- return typeof t == "bigint" ? t : void 0;
18
- }
19
- function de(e, t) {
20
- let n;
21
- switch (typeof e) {
22
- case "number":
23
- n = new Number(e);
24
- break;
25
- case "string":
26
- n = new String(e);
27
- break;
28
- case "boolean":
29
- n = new Boolean(e);
30
- break;
31
- case "bigint":
32
- n = Object(e);
33
- break;
34
- case "undefined":
35
- n = new le();
36
- break;
37
- case "object":
38
- if (e === null) {
39
- n = new ce();
40
- break;
41
- }
42
- n = e;
43
- break;
44
- default: throw TypeError(`setCborTag: cannot tag value of type ${typeof e}`);
45
- }
46
- return n[se] = t, n;
47
- }
48
- function fe(e) {
49
- if (e instanceof Number || e instanceof String || e instanceof Boolean || Object.prototype.toString.call(e) === "[object BigInt]") return e.valueOf();
50
- if (e instanceof ce) return null;
51
- if (!(e instanceof le)) return typeof e == "object" && e && delete e[se], e;
52
- }
53
- function pe(e) {
54
- if (e instanceof Number || e instanceof String || e instanceof Boolean || Object.prototype.toString.call(e) === "[object BigInt]") return e.valueOf();
55
- if (e instanceof ce) return null;
56
- if (!(e instanceof le)) return e;
57
- }
58
- function me(e) {
59
- return typeof e == "object" && !!e;
60
- }
61
- var k = class {
62
- constructor() {}
63
- static symbol = se;
64
- static Null = ce;
65
- static Undefined = le;
66
- static get(e) {
67
- return ue(e);
68
- }
69
- static set(e, t) {
70
- return de(e, t);
71
- }
72
- static remove(e) {
73
- return fe(e);
74
- }
75
- static getValue(e) {
76
- return pe(e);
77
- }
78
- }, A = Symbol("cbor.omit"), he = class e {
79
- value;
80
- constructor(e) {
81
- if (!Number.isInteger(e) || e < 0 || e > 255) throw RangeError("Simple value must be an integer in 0–255");
82
- this.value = e;
83
- }
84
- valueOf() {
85
- return this.value;
86
- }
87
- toJSON() {
88
- throw TypeError(`simple(${this.value}) cannot be serialized to JSON`);
89
- }
90
- static is(t) {
91
- return t instanceof e;
92
- }
93
- static get(t) {
94
- return t instanceof e ? t.value : void 0;
95
- }
96
- }, ge = "getFloat16" in DataView.prototype && "setFloat16" in DataView.prototype, _e = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(8));
97
- function ve(e) {
98
- _e.setFloat64(0, e, !1);
99
- let t = _e.getUint32(0, !1), n = _e.getUint32(4, !1), r = t >>> 31 & 1, i = t >>> 20 & 2047, a = t & 1048575;
100
- if (i === 2047) {
101
- if (a === 0 && n === 0) return r << 15 | 31744;
102
- let e = a >> 10 | (n === 0 ? 0 : 1) || 1;
103
- return r << 15 | 31744 | e & 1023;
104
- }
105
- let o = i - 1023 + 15;
106
- if (o >= 31) return r << 15 | 31744;
107
- let s, c, l;
108
- if (o <= 0) {
109
- if (o < -10) return r << 15;
110
- let e = 1 << 20 | a, t = 11 - o;
111
- t <= 20 ? (s = e >> t & 1023, c = e >> t - 1 & 1, l = !!(e & (1 << t - 1) - 1) || n !== 0) : (s = 0, c = 1, l = a !== 0 || n !== 0);
112
- } else s = a >> 10, c = a >> 9 & 1, l = !!(a & 511) || n !== 0;
113
- if (c !== 0 && (l || s & 1) && s++, s >= 1024) {
114
- let e = o <= 0 ? 1 : o + 1;
115
- return e >= 31 ? r << 15 | 31744 : r << 15 | e << 10;
116
- }
117
- let u = o <= 0 ? 0 : o;
118
- return r << 15 | u << 10 | s;
119
- }
120
- function j(e) {
121
- let t = e >>> 15 & 1, n = e >>> 10 & 31, r = e & 1023;
122
- return n === 31 ? r === 0 ? t ? -Infinity : Infinity : NaN : n === 0 ? r === 0 ? t ? -0 : 0 : (t ? -1 : 1) * 2 ** -14 * (r / 1024) : (t ? -1 : 1) * 2 ** (n - 15) * (1 + r / 1024);
123
- }
124
- var ye = ge ? (e, t, n, r) => {
125
- e.setFloat16(t, n, r);
126
- } : (e, t, n, r) => {
127
- e.setUint16(t, ve(n), r);
128
- }, be = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(8)), M = new Uint8Array(be.buffer), xe = new TextEncoder(), Se = typeof xe.encodeInto == "function";
129
- function Ce(e) {
130
- return e <= 23 ? 1 : e <= 255 ? 2 : e <= 65535 ? 3 : e <= 4294967295 ? 5 : 9;
131
- }
132
- function we(e) {
133
- return e === "i" ? 1 : [
134
- 2,
135
- 3,
136
- 5,
137
- 9
138
- ][e];
139
- }
140
- var Te = class {
141
- buf;
142
- len = 0;
143
- constructor(e = 256) {
144
- this.buf = new Uint8Array(e);
145
- }
146
- _ensure(e) {
147
- let t = this.len + e;
148
- if (t <= this.buf.length) return;
149
- let n = this.buf.length * 2;
150
- for (; n < t;) n *= 2;
151
- let r = new Uint8Array(n);
152
- r.set(this.buf), this.buf = r;
153
- }
154
- writeByte(e) {
155
- this._ensure(1), this.buf[this.len++] = e;
156
- }
157
- writeBytes(e) {
158
- this._ensure(e.length), this.buf.set(e, this.len), this.len += e.length;
159
- }
160
- writeUint16(e) {
161
- this._ensure(2);
162
- let t = this.buf;
163
- t[this.len++] = e >>> 8 & 255, t[this.len++] = e & 255;
164
- }
165
- writeUint32(e) {
166
- this._ensure(4);
167
- let t = this.buf;
168
- t[this.len++] = e >>> 24 & 255, t[this.len++] = e >>> 16 & 255, t[this.len++] = e >>> 8 & 255, t[this.len++] = e & 255;
169
- }
170
- writeBigUint64(e) {
171
- be.setBigUint64(0, e, !1), this._ensure(8), this.buf.set(M, this.len), this.len += 8;
172
- }
173
- writeFloat16(e) {
174
- ye(be, 0, e, !1), this._ensure(2);
175
- let t = this.buf;
176
- t[this.len++] = M[0], t[this.len++] = M[1];
177
- }
178
- writeFloat32(e) {
179
- be.setFloat32(0, e, !1), this._ensure(4);
180
- let t = this.buf;
181
- t[this.len++] = M[0], t[this.len++] = M[1], t[this.len++] = M[2], t[this.len++] = M[3];
182
- }
183
- writeFloat64(e) {
184
- be.setFloat64(0, e, !1), this._ensure(8), this.buf.set(M, this.len), this.len += 8;
185
- }
186
- writeTextString(e, t, n) {
187
- if (!Se) {
188
- let r = xe.encode(t);
189
- N(this, e, r.length, n), this.writeBytes(r);
190
- return;
191
- }
192
- let r = n === void 0 ? Ce(t.length) : we(n);
193
- this._ensure(9 + 3 * t.length);
194
- let { written: i } = xe.encodeInto(t, this.buf.subarray(this.len + r)), a = n === void 0 ? Ce(i) : r;
195
- a !== r && this.buf.copyWithin(this.len + a, this.len + r, this.len + r + i), N(this, e, i, n), this.len += i;
196
- }
197
- finish() {
198
- return this.buf.slice(0, this.len);
199
- }
200
- }, Ee = [
201
- 255n,
202
- 65535n,
203
- 4294967295n,
204
- 18446744073709551615n
205
- ];
206
- function De(e) {
207
- return e === "i" ? 23n : Ee[e];
208
- }
209
- function N(e, t, n, r) {
210
- if (r === void 0 && typeof n == "number" && n < 4294967296) {
211
- n <= 23 ? e.writeByte(t << 5 | n) : n <= 255 ? (e.writeByte(t << 5 | 24), e.writeByte(n)) : n <= 65535 ? (e.writeByte(t << 5 | 25), e.writeUint16(n)) : (e.writeByte(t << 5 | 26), e.writeUint32(n));
212
- return;
213
- }
214
- let i = typeof n == "number" ? BigInt(n) : n;
215
- if (r !== void 0) {
216
- if (r === "i") {
217
- if (i > 23n) throw RangeError(`value ${i} does not fit in immediate encoding _i (max 23)`);
218
- e.writeByte(t << 5 | Number(i));
219
- return;
220
- }
221
- if (i > Ee[r]) throw RangeError(`value ${i} does not fit in encodingWidth _${r} (max ${Ee[r]})`);
222
- let n = 24 + r;
223
- e.writeByte(t << 5 | n), n === 24 ? e.writeByte(Number(i)) : n === 25 ? e.writeUint16(Number(i)) : n === 26 ? e.writeUint32(Number(i)) : e.writeBigUint64(i);
224
- return;
225
- }
226
- i <= 23n ? e.writeByte(t << 5 | Number(i)) : i <= 255n ? (e.writeByte(t << 5 | 24), e.writeByte(Number(i))) : i <= 65535n ? (e.writeByte(t << 5 | 25), e.writeUint16(Number(i))) : i <= 4294967295n ? (e.writeByte(t << 5 | 26), e.writeUint32(Number(i))) : (e.writeByte(t << 5 | 27), e.writeBigUint64(i));
227
- }
228
- function Oe(e, t, n) {
229
- let r = new Te(9);
230
- return N(r, e, t, n), r.finish();
231
- }
232
- var ke = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(4));
233
- function Ae(e) {
234
- return Object.is(j(ve(e)), e);
235
- }
236
- function je(e) {
237
- return ke.setFloat32(0, e, !1), Object.is(ke.getFloat32(0, !1), e);
238
- }
239
- function P(e) {
240
- return Ae(e) ? "half" : je(e) ? "single" : "double";
241
- }
242
- //#endregion
243
- //#region src/ast/CborItem.ts
244
- function Me(e) {
245
- return {
246
- ...e,
247
- preserveComments: e.comments === void 0 ? e.preserveComments ?? !0 : e.preserveComments,
248
- preserveByteString: e.preserveByteString ?? !0,
249
- preserveRawString: e.preserveRawString ?? !0,
250
- preserveConcatenation: e.preserveConcatenation ?? !0,
251
- preserveNumberFormat: e.preserveNumberFormat ?? !0,
252
- preserveAppPrefix: e.preserveAppPrefix ?? !0,
253
- preserveBlankLines: e.preserveBlankLines ?? !0
254
- };
255
- }
256
- function Ne(e) {
257
- return e.preserveAppSequence === void 0 && e.appStrings === void 0 ? e : {
258
- ...e,
259
- preserveAppPrefix: e.preserveAppPrefix ?? e.preserveAppSequence,
260
- appPrefix: e.appPrefix ?? e.appStrings
261
- };
262
- }
263
- function Pe(e) {
264
- if (e.preserveAppSequence === void 0 && e.appStrings === void 0) return e;
265
- let t = Ne(e), n = { ...e };
266
- return t.preserveAppPrefix !== void 0 && (n.preserveAppPrefix = t.preserveAppPrefix), t.appPrefix !== void 0 && (n.appPrefix = t.appPrefix), n;
267
- }
268
- var Fe = Object.freeze([]);
269
- function Ie(e) {
270
- return !!(e?.itemOptions || e?.extensions?.length);
271
- }
272
- function Le(e) {
273
- return e && {
274
- ...e,
275
- reviver: void 0
276
- };
277
- }
278
- function Re(e) {
279
- let { reviver: t, extensions: n, ...r } = e;
280
- return n ? {
281
- ...r,
282
- extensions: [...n]
283
- } : r;
284
- }
285
- var ze = Symbol("cbor.itemOptions.dispatchCache"), Be = Symbol("cbor.itemOptions.rawPass"), Ve = Object.freeze([]);
286
- function He(e) {
287
- return e?.[ze];
288
- }
289
- function Ue(e) {
290
- let t = /* @__PURE__ */ new WeakMap();
291
- return Object.assign({}, e, { [ze]: t });
292
- }
293
- function We(e, t) {
294
- if (e.length !== t.length) return !1;
295
- for (let n = 0; n < e.length; n++) if (e[n] !== t[n]) return !1;
296
- return !0;
297
- }
298
- function Ge(e, t) {
299
- return e?.find((e) => We(e.occurrence, t));
300
- }
301
- function Ke(e, t, n) {
302
- let r = e.get(t);
303
- r ? r.push(n) : e.set(t, [n]);
304
- }
305
- function qe(e) {
306
- return !!e?.itemOptions;
307
- }
308
- function Je(e) {
309
- let { textStringFormat: t, ...n } = e;
310
- return delete n[Ye], t ? {
311
- ...n,
312
- textStringFormat: [...t]
313
- } : n;
314
- }
315
- var Ye = Symbol("cdnOverrideTracker"), F = class e {
316
- start;
317
- end;
318
- comments;
319
- blankLineBefore;
320
- appSeqSource;
321
- appSeqComments;
322
- appSeqEncodingEdits;
323
- appSeqEncodingEditsComplete;
324
- appSeqInnerEnd;
325
- appSeqSourceFeatures;
326
- warnings;
327
- _defaults;
328
- get _containsCdnContainer() {
329
- return !1;
330
- }
331
- _isMultiWordText(e, t = !0, n) {
332
- return !1;
333
- }
334
- toCBOR(e) {
335
- let t = this._defaults ? {
336
- ...this._defaults,
337
- ...e
338
- } : e, n = new Te();
339
- return this._encode(n, t), n.finish();
340
- }
341
- toCDN(e) {
342
- let t = this._defaults ? {
343
- ...this._defaults,
344
- ...e
345
- } : e;
346
- t &&= Ne(t), t?.preserveAll && (t = Me(t));
347
- let r = this._resolveCdnOptions(t, Fe, {}), i = this._toCDN(r, 0, Fe);
348
- if (!n(r) || O(r) === null) return i;
349
- let a = u(r), { ownLines: o, inlinePrefix: s } = c(this, "", a), l = this.comments?.trailing ?? [], d = l.length === 0 ? i : `${i} ${l.map((e) => b(e, a).trimEnd()).join(" ")}`;
350
- return [...o, `${s}${d}`].join("\n");
351
- }
352
- toEDN(e) {
353
- return this.toCDN(e);
354
- }
355
- toJS(e) {
356
- let t = this._defaults ? {
357
- ...this._defaults,
358
- ...e
359
- } : e, n = Ie(t) ? this._toJSChild(Ue(t), Fe, Ve, {}) : this._toJS(t);
360
- if (!t?.reviver) return n;
361
- let r = t.reviver.call({ "": n }, "", n);
362
- return r === A ? void 0 : r;
363
- }
364
- toHexDump(e) {
365
- let t = this._defaults ? {
366
- ...this._defaults,
367
- ...e
368
- } : e;
369
- t &&= Ne(t);
370
- let n = t?.indent ?? 3, r = typeof n == "string" ? n : " ".repeat(n), i = (t?.commentStyle ?? "--") + " ", a = this._toHexDump(0, t), o = 0;
371
- for (let e of a) {
372
- let t = e.depth * r.length + e.hex.length;
373
- t > o && (o = t);
374
- }
375
- let s = o + 2;
376
- return a.map((e) => (r.repeat(e.depth) + e.hex).padEnd(s) + i + e.comment).join("\n");
377
- }
378
- _encode(t, n) {
379
- if (this._toCBOR !== e.prototype._toCBOR) {
380
- t.writeBytes(this._toCBOR(n));
381
- return;
382
- }
383
- this._encodeTo(t, n);
384
- }
385
- _encodeTo(t, n) {
386
- if (this._toCBOR === e.prototype._toCBOR) throw TypeError("CborItem subclass must implement _encodeTo() or _toCBOR()");
387
- t.writeBytes(this._toCBOR(n));
388
- }
389
- _toCBOR(e) {
390
- let t = new Te();
391
- return this._encodeTo(t, e), t.finish();
392
- }
393
- _resolveCdnOptions(e, t, n) {
394
- if (!qe(e)) return e;
395
- let r = n.isMapKey || t.length === 0 ? void 0 : t[t.length - 1], i = e.itemOptions(this, {
396
- ...n,
397
- key: r,
398
- path: t,
399
- options: Je(e)
400
- });
401
- if (!i) return e;
402
- let a = e[Ye];
403
- a && (a.applied = !0);
404
- let o = {
405
- ...e,
406
- ...Pe(i)
407
- };
408
- return o.preserveAll && (o = Me(o)), o;
409
- }
410
- _toJSChild(e, t, n, r) {
411
- let i = He(e), a = Ge(i?.get(this), n);
412
- if (a) {
413
- if (a.outcome.kind === "value") return a.outcome.value;
414
- let r = a.outcome.override ? {
415
- ...e,
416
- ...a.outcome.override
417
- } : e;
418
- return this._toJS(r, t, n);
419
- }
420
- let o = r.isMapKey || t.length === 0 ? void 0 : t[t.length - 1], s = e, c;
421
- if (e?.itemOptions && (c = e.itemOptions(this, {
422
- ...r,
423
- key: o,
424
- path: t,
425
- options: Re(e)
426
- }), c && (s = {
427
- ...e,
428
- ...c
429
- })), s?.extensions?.length) for (let e of s.extensions) {
430
- let t = e.toJS?.(this, Re(s));
431
- if (t) return i && Ke(i, this, {
432
- occurrence: n,
433
- outcome: {
434
- kind: "value",
435
- value: t.value
436
- }
437
- }), t.value;
438
- }
439
- return i && Ke(i, this, {
440
- occurrence: n,
441
- outcome: {
442
- kind: "override",
443
- override: c
444
- }
445
- }), this._toJS(s, t, n);
446
- }
447
- _toHexDump(e, t) {
448
- return [{
449
- depth: e,
450
- hex: l(this._toCBOR()),
451
- comment: this._toCDN(t, 0)
452
- }];
453
- }
454
- }, I = class extends F {
455
- value;
456
- encodingWidth;
457
- ednSource;
458
- constructor(e, t) {
459
- if (super(), this.value = BigInt(e), this.value < 0n) throw RangeError("CborUint value must be non-negative");
460
- if (this.value > 18446744073709551615n) throw RangeError("CborUint value exceeds maximum uint64");
461
- this.encodingWidth = t?.encodingWidth, this.ednSource = t?.ednSource;
462
- }
463
- _encodeTo(e, t) {
464
- N(e, 0, this.value, this.encodingWidth);
465
- }
466
- _toCDN(e, n, r) {
467
- let i = t(e, this.encodingWidth, () => E(this.value));
468
- if (e?.preserveNumberFormat && this.ednSource !== void 0) return this.ednSource + i;
469
- let a = this.value;
470
- switch (e?.intFormat) {
471
- case "hex": return `0x${a.toString(16)}${i}`;
472
- case "octal": return `0o${a.toString(8)}${i}`;
473
- case "binary": return `0b${a.toString(2)}${i}`;
474
- default: return a.toString() + i;
475
- }
476
- }
477
- _toJS(e) {
478
- let t = e?.integerAs ?? "auto";
479
- return t === "bigint" ? this.value : t === "number" || this.value <= BigInt(2 ** 53 - 1) ? Number(this.value) : this.value;
480
- }
481
- }, L = class extends F {
482
- argument;
483
- encodingWidth;
484
- ednSource;
485
- constructor(e, t) {
486
- super();
487
- let n = BigInt(e);
488
- if (n >= 0n) throw RangeError("CborNint value must be negative");
489
- if (n < -18446744073709551616n) throw RangeError("CborNint value exceeds minimum int64");
490
- this.argument = -1n - n, this.encodingWidth = t?.encodingWidth, this.ednSource = t?.ednSource;
491
- }
492
- get value() {
493
- return -1n - this.argument;
494
- }
495
- _encodeTo(e, t) {
496
- N(e, 1, this.argument, this.encodingWidth);
497
- }
498
- _toCDN(e, n, r) {
499
- let i = t(e, this.encodingWidth, () => E(this.argument));
500
- if (e?.preserveNumberFormat && this.ednSource !== void 0) return this.ednSource + i;
501
- let a = this.argument + 1n;
502
- switch (e?.intFormat) {
503
- case "hex": return `-0x${a.toString(16)}${i}`;
504
- case "octal": return `-0o${a.toString(8)}${i}`;
505
- case "binary": return `-0b${a.toString(2)}${i}`;
506
- default: return this.value.toString() + i;
507
- }
508
- }
509
- _toJS(e) {
510
- let t = this.value, n = e?.integerAs ?? "auto";
511
- return n === "bigint" ? t : n === "number" || t >= BigInt(-(2 ** 53 - 1)) ? Number(t) : t;
512
- }
513
- }, Xe = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(8));
514
- function Ze(e) {
515
- let t = e.startsWith("-"), n = e.slice(t ? 3 : 2), r = n.search(/[pP]/);
516
- if (r === -1) throw SyntaxError(`EDN parse error: hex float missing 'p' exponent: ${e}`);
517
- let i = n.slice(0, r), a = n.slice(r + 1);
518
- if (!/^[+-]?\d+$/.test(a)) throw SyntaxError(`EDN parse error: hex float has invalid or missing exponent: ${e}`);
519
- let o = parseInt(a, 10), s = i.indexOf("."), c;
520
- if (s === -1) {
521
- if (!/^[0-9a-fA-F]+$/.test(i)) throw SyntaxError(`EDN parse error: hex float has no mantissa digits: ${e}`);
522
- c = parseInt(i, 16);
523
- } else {
524
- let t = i.slice(0, s), n = i.slice(s + 1);
525
- if (t === "" && n === "") throw SyntaxError(`EDN parse error: hex float has no mantissa digits: ${e}`);
526
- if (t !== "" && !/^[0-9a-fA-F]+$/.test(t) || n !== "" && !/^[0-9a-fA-F]+$/.test(n)) throw SyntaxError(`EDN parse error: hex float has invalid mantissa: ${e}`);
527
- c = (t === "" ? 0 : parseInt(t, 16)) + (n === "" ? 0 : parseInt(n, 16) / 16 ** n.length);
528
- }
529
- let l = c * 2 ** o;
530
- return t ? -l : l;
531
- }
532
- function Qe(e) {
533
- if (isNaN(e)) return "NaN";
534
- if (!isFinite(e)) return e > 0 ? "Infinity" : "-Infinity";
535
- let t = Object.is(e, -0) || e < 0, n = Math.abs(e);
536
- if (n === 0) return t ? "-0x0p+0" : "0x0p+0";
537
- Xe.setFloat64(0, n, !1);
538
- let r = Xe.getUint32(0, !1), i = Xe.getUint32(4, !1), a = r >>> 20 & 2047, o = r & 1048575, s = i, c, l;
539
- if (a === 0) {
540
- let e = BigInt(o) << 32n | BigInt(s), t = e.toString(2).length;
541
- c = e - (1n << BigInt(t - 1)) << BigInt(52 - (t - 1)), l = t - 1075;
542
- } else c = BigInt(o) << 32n | BigInt(s), l = a - 1023;
543
- let u = c.toString(16).padStart(13, "0").replace(/0+$/, ""), d = `0x1${u === "" ? "" : `.${u}`}p${l >= 0 ? `+${l}` : `${l}`}`;
544
- return t ? `-${d}` : d;
545
- }
546
- //#endregion
547
- //#region src/ast/CborFloat.ts
548
- var R = class extends F {
549
- value;
550
- precision;
551
- ednSource;
552
- literalSource;
553
- rawBits;
554
- constructor(e, t) {
555
- super(), this.value = e, this.precision = t?.precision, this.rawBits = t?.rawBits, this.literalSource = t?.literalSource;
556
- }
557
- _encodeTo(e, t) {
558
- let n = this.precision ?? P(this.value), r = Number.isNaN(this.value) ? this.rawBits : void 0;
559
- n === "half" ? (e.writeByte(249), r?.length === 2 ? e.writeBytes(r) : e.writeFloat16(this.value)) : n === "single" ? (e.writeByte(250), r?.length === 4 ? e.writeBytes(r) : e.writeFloat32(this.value)) : (e.writeByte(251), r?.length === 8 ? e.writeBytes(r) : e.writeFloat64(this.value));
560
- }
561
- _toCDN(e, t, n) {
562
- let r = e?.encodingIndicators ?? "auto";
563
- if (e?.appPrefix !== !1 && (e?.floatFormat === void 0 || e?.floatFormat === "app-extension") && this.ednSource !== void 0 && (O(e) !== null || !/[\r\n]/.test(this.ednSource))) {
564
- let e = this.ednSource;
565
- if (r === "never") return e.replace(/_[0-3i]$/, "");
566
- if (r === "always") {
567
- if (/_[0-3i]$/.test(e)) return e;
568
- let t = this.precision ?? P(this.value);
569
- return e + (t === "half" ? "_1" : t === "single" ? "_2" : "_3");
570
- }
571
- return e;
572
- }
573
- if (e?.preserveNumberFormat && this.literalSource !== void 0) {
574
- let e = this.literalSource;
575
- if (r === "never") return e.replace(/_[0-7i]$/, "");
576
- if (r === "always") {
577
- if (/_[0-7i]$/.test(e)) return e;
578
- let t = P(this.value);
579
- return e + S(this.value, this.precision, t, "always");
580
- }
581
- return e;
582
- }
583
- let i = P(this.value);
584
- if (e?.floatFormat === "app-extension" && e?.appPrefix !== !1) {
585
- let e = this.toCBOR();
586
- return `float'${s(e.subarray(1))}'` + S(this.value, this.precision, i, r);
587
- }
588
- return (e?.floatFormat === "hex" ? Qe(this.value) : re(this.value)) + S(this.value, this.precision, i, r);
589
- }
590
- _toJS(e) {
591
- return this.value;
592
- }
593
- }, z = class extends F {
594
- tag;
595
- content;
596
- encodingWidth;
597
- ednSource;
598
- constructor(e, t, n) {
599
- if (super(), this.tag = BigInt(e), this.tag < 0n) throw RangeError("CborTag tag number must be non-negative");
600
- this.content = t, this.encodingWidth = n?.encodingWidth, this.ednSource = n?.ednSource;
601
- }
602
- get _containsCdnContainer() {
603
- return this.content._containsCdnContainer;
604
- }
605
- _isMultiWordText(e, t = !0, n) {
606
- return y(this._toCDN(e, 0, n), t);
607
- }
608
- _encodeTo(e, t) {
609
- N(e, 6, this.tag, this.encodingWidth), this.content._encode(e, t);
610
- }
611
- _toCDN(e, n, r) {
612
- let i = t(e, this.encodingWidth, () => E(this.tag)), a = e?.preserveNumberFormat && this.ednSource !== void 0 ? this.ednSource : this.tag.toString(), o = this.content._resolveCdnOptions(e, r ?? [], { parent: this });
613
- return `${a}${i}${ae(this.content, this, e, o, n, (e) => this.content._toCDN(o, e, r), "(", ")")}`;
614
- }
615
- _toHexDump(e, t) {
616
- let n = [{
617
- depth: e,
618
- hex: l(Oe(6, this.tag, this.encodingWidth)),
619
- comment: `Tag ${this.tag}`
620
- }];
621
- return m(n, this.content._toHexDump(e + 1, {
622
- ...t,
623
- appPrefix: !1
624
- })), n;
625
- }
626
- _toJS(e, t, n) {
627
- let r = Ie(e) ? this.content._toJSChild(e, t ?? [], n ?? Ve, { parent: this }) : this.content._toJS(e);
628
- return e?.stripTags ? r : k.set(r, this.tag);
629
- }
630
- };
631
- //#endregion
632
- //#region src/ast/CborByteString.ts
633
- function $e(e, t, r) {
634
- if (e !== void 0) return n(t) || r === void 0 ? e : x(e, r);
635
- }
636
- var B = class extends F {
637
- indefiniteLength = !1;
638
- value;
639
- ednEncoding;
640
- encodingWidth;
641
- ednSource;
642
- ednCommentSyntax;
643
- ednParts;
644
- constructor(e, t) {
645
- super(), this.value = e, this.ednEncoding = t?.ednEncoding ?? "hex", this.encodingWidth = t?.encodingWidth, this.ednSource = t?.ednSource, this.ednCommentSyntax = t?.ednCommentSyntax, this.ednParts = t?.ednParts;
646
- }
647
- _isMultiWordText(e, t = !0, n) {
648
- return C(this.value, e?.sqstr);
649
- }
650
- _encodeTo(e, t) {
651
- N(e, 2, this.value.length, this.encodingWidth), e.writeBytes(this.value);
652
- }
653
- _toCDN(e, r, i) {
654
- let a = O(e);
655
- if (e?.preserveConcatenation && a !== null && this.ednParts !== void 0 && this.ednParts.length > 1) {
656
- let i = t(e, this.encodingWidth, () => E(BigInt(this.value.length))), o = e?.bstrEncoding ?? this.ednEncoding;
657
- e?.appPrefix === !1 && o !== "hex" && (o = "hex");
658
- let s = this.ednParts.map((t) => {
659
- let n = e?.preserveByteString ? $e(t.source, e, t.commentSyntax) : void 0;
660
- return n === void 0 ? d(t.bytes, o, e?.sqstr) : n;
661
- }), c = n(e) ? p(this.comments?.dangling, this.ednParts, u(e)) : void 0;
662
- return e?.modernConcat && e?.appPrefix !== !1 ? ie("b1", s, i, a, r, c) : (s[s.length - 1] += i, oe(s, a, r, c));
663
- }
664
- let o = e?.preserveByteString ? $e(this.ednSource, e, this.ednCommentSyntax) : void 0;
665
- if (o !== void 0 && (a !== null || !/[\r\n]/.test(o))) return /_[0-3i]$/.test(o) ? (e?.encodingIndicators ?? "auto") === "never" ? o.replace(/_[0-3i]$/, "") : o : o + t(e, this.encodingWidth, () => E(BigInt(this.value.length)));
666
- let s = t(e, this.encodingWidth, () => E(BigInt(this.value.length))), c = e?.bstrEncoding ?? this.ednEncoding;
667
- return e?.appPrefix === !1 && c !== "hex" && (c = "hex"), d(this.value, c, e?.sqstr) + s;
668
- }
669
- _toJS(e) {
670
- return this.value;
671
- }
672
- }, V = class extends F {
673
- indefiniteLength = !0;
674
- chunks;
675
- constructor(e) {
676
- super(), this.chunks = e;
677
- }
678
- _encodeTo(e, t) {
679
- e.writeByte(95);
680
- for (let n of this.chunks) n._encode(e, t);
681
- e.writeByte(255);
682
- }
683
- _isMultiWordText(e, t = !0) {
684
- return this.chunks.some((t) => t._isMultiWordText(e));
685
- }
686
- _toCDN(e, t, n) {
687
- if ((e?.encodingIndicators ?? "auto") === "never") {
688
- let n = this.chunks.reduce((e, t) => e + t.value.length, 0), r = new Uint8Array(n), i = 0;
689
- for (let e of this.chunks) r.set(e.value, i), i += e.value.length;
690
- return new B(r)._toCDN(e, t);
691
- }
692
- let i = n ?? [], a = qe(e), o = (t) => a ? this.chunks[t]._resolveCdnOptions(e, [...i, t], { parent: this }) : e, s = !!e?.modernStreamSyntax && e?.appPrefix !== !1;
693
- return !s && this.chunks.length === 0 ? "''_" : r({
694
- node: this,
695
- options: e,
696
- depth: t,
697
- openChar: s ? "ilbs<<" : "(",
698
- closeChar: s ? ">>" : ")",
699
- count: this.chunks.length,
700
- indefiniteLength: !0,
701
- indefiniteMarker: !s,
702
- encodingWidth: void 0,
703
- hasEntryComments: (e) => _(this.chunks[e]),
704
- renderEntry: (e) => this.chunks[e]._toCDN(o(e), t + 1, a ? [...i, e] : void 0),
705
- entryIsLeaf: s ? void 0 : () => !0,
706
- alwaysInlineLeaf: s,
707
- entryIsMultiWordText: (e) => this.chunks[e]._isMultiWordText(o(e), !s, a ? [...i, e] : void 0),
708
- entryLeadingNode: (e) => this.chunks[e],
709
- entryTrailing: (e, t) => g(this.chunks[e], t),
710
- entryOptions: a ? o : void 0
711
- });
712
- }
713
- _toHexDump(e, t) {
714
- let n = [{
715
- depth: e,
716
- hex: o(95),
717
- comment: "Start indefinite-length byte string"
718
- }];
719
- for (let r of this.chunks) m(n, r._toHexDump(e + 1, t));
720
- return n.push({
721
- depth: e,
722
- hex: o(255),
723
- comment: "\"break\""
724
- }), n;
725
- }
726
- _toJS(e) {
727
- let t = this.chunks.reduce((e, t) => e + t.value.length, 0), n = new Uint8Array(t), r = 0;
728
- for (let e of this.chunks) n.set(e.value, r), r += e.value.length;
729
- return n;
730
- }
731
- }, H = class extends F {
732
- indefiniteLength = !0;
733
- chunks;
734
- constructor(e) {
735
- super(), this.chunks = e;
736
- }
737
- _encodeTo(e, t) {
738
- e.writeByte(127);
739
- for (let n of this.chunks) n._encode(e, t);
740
- e.writeByte(255);
741
- }
742
- _isMultiWordText(e, t = !0) {
743
- return this.chunks.some((t) => t._isMultiWordText(e));
744
- }
745
- _toCDN(e, t, n) {
746
- if ((e?.encodingIndicators ?? "auto") === "never") return new Y(this.chunks.map((e) => e.value).join(""))._toCDN(e, t);
747
- let i = n ?? [], a = qe(e), o = (t) => a ? this.chunks[t]._resolveCdnOptions(e, [...i, t], { parent: this }) : e, s = !!e?.modernStreamSyntax && e?.appPrefix !== !1;
748
- return !s && this.chunks.length === 0 ? "\"\"_" : r({
749
- node: this,
750
- options: e,
751
- depth: t,
752
- openChar: s ? "ilts<<" : "(",
753
- closeChar: s ? ">>" : ")",
754
- count: this.chunks.length,
755
- indefiniteLength: !0,
756
- indefiniteMarker: !s,
757
- encodingWidth: void 0,
758
- hasEntryComments: (e) => _(this.chunks[e]),
759
- renderEntry: (e) => this.chunks[e]._toCDN(o(e), t + 1, a ? [...i, e] : void 0),
760
- entryIsLeaf: s ? void 0 : () => !0,
761
- alwaysInlineLeaf: s,
762
- entryIsMultiWordText: (e) => this.chunks[e]._isMultiWordText(o(e), !s, a ? [...i, e] : void 0),
763
- entryLeadingNode: (e) => this.chunks[e],
764
- entryTrailing: (e, t) => g(this.chunks[e], t),
765
- entryOptions: a ? o : void 0
766
- });
767
- }
768
- _toHexDump(e, t) {
769
- let n = [{
770
- depth: e,
771
- hex: o(127),
772
- comment: "Start indefinite-length text string"
773
- }];
774
- for (let r of this.chunks) m(n, r._toHexDump(e + 1, t));
775
- return n.push({
776
- depth: e,
777
- hex: o(255),
778
- comment: "\"break\""
779
- }), n;
780
- }
781
- _toJS(e) {
782
- return this.chunks.map((e) => e.value).join("");
783
- }
784
- }, U = class extends F {
785
- items;
786
- indefiniteLength;
787
- encodingWidth;
788
- constructor(e, t) {
789
- super(), this.items = e, this.indefiniteLength = t?.indefiniteLength ?? !1, this.encodingWidth = t?.encodingWidth;
790
- }
791
- get _containsCdnContainer() {
792
- return !0;
793
- }
794
- _encodeTo(e, t) {
795
- if (this.indefiniteLength) {
796
- e.writeByte(159);
797
- for (let n of this.items) n._encode(e, t);
798
- e.writeByte(255);
799
- return;
800
- }
801
- N(e, 4, this.items.length, this.encodingWidth);
802
- for (let n of this.items) n._encode(e, t);
803
- }
804
- _toCDN(e, t, n) {
805
- let i = n ?? [], a = qe(e), o = (t) => a ? this.items[t]._resolveCdnOptions(e, [...i, t], { parent: this }) : e;
806
- return r({
807
- node: this,
808
- options: e,
809
- depth: t,
810
- openChar: "[",
811
- closeChar: "]",
812
- count: this.items.length,
813
- indefiniteLength: this.indefiniteLength,
814
- encodingWidth: this.encodingWidth,
815
- hasEntryComments: (e) => _(this.items[e]),
816
- renderEntry: (e) => this.items[e]._toCDN(o(e), t + 1, a ? [...i, e] : void 0),
817
- entryIsLeaf: (e) => !this.items[e]._containsCdnContainer,
818
- entryIsMultiWordText: (e) => this.items[e]._isMultiWordText(o(e), !0, a ? [...i, e] : void 0),
819
- entryLeadingNode: (e) => this.items[e],
820
- entryTrailing: (e, t) => g(this.items[e], t),
821
- entryOptions: a ? o : void 0
822
- });
823
- }
824
- _toHexDump(e, t) {
825
- if (this.indefiniteLength) {
826
- let n = [{
827
- depth: e,
828
- hex: o(159),
829
- comment: "Start indefinite-length array"
830
- }];
831
- for (let r of this.items) m(n, r._toHexDump(e + 1, t));
832
- return n.push({
833
- depth: e,
834
- hex: o(255),
835
- comment: "\"break\""
836
- }), n;
837
- }
838
- let n = [{
839
- depth: e,
840
- hex: l(Oe(4, BigInt(this.items.length), this.encodingWidth)),
841
- comment: `Array of length ${this.items.length}`
842
- }];
843
- for (let r of this.items) m(n, r._toHexDump(e + 1, t));
844
- return n;
845
- }
846
- _toJS(e, t, n) {
847
- let r = e?.reviver, i = Ie(e), a = n ?? Ve, o = (e, n, r, o) => i ? e._toJSChild(r, [...t ?? [], n], o ? [
848
- ...a,
849
- Be,
850
- n
851
- ] : [...a, n], { parent: this }) : e._toJS(r);
852
- if (!r) return this.items.map((t, n) => o(t, n, e, !1));
853
- let s = Le(e), c = this.items.map((e, t) => o(e, t, s, !0)), l = 0;
854
- for (let t = 0; t < this.items.length; t++) {
855
- let n = t - l, i = o(this.items[t], t, e, !1), a = r.call(c, String(t), i);
856
- a === A || e?.undefinedOmits && a === void 0 ? (c.splice(n, 1), l++) : c[n] = a;
857
- }
858
- return c;
859
- }
860
- }, W = class extends F {
861
- entries;
862
- indefiniteLength;
863
- encodingWidth;
864
- constructor(e, t) {
865
- super(), this.entries = e, this.indefiniteLength = t?.indefiniteLength ?? !1, this.encodingWidth = t?.encodingWidth;
866
- }
867
- get _containsCdnContainer() {
868
- return !0;
869
- }
870
- _encodeTo(e, t) {
871
- if (this.indefiniteLength) {
872
- e.writeByte(191);
873
- for (let [n, r] of this.entries) n._encode(e, t), r._encode(e, t);
874
- e.writeByte(255);
875
- return;
876
- }
877
- N(e, 5, this.entries.length, this.encodingWidth);
878
- for (let [n, r] of this.entries) n._encode(e, t), r._encode(e, t);
879
- }
880
- _toCDN(e, t, n) {
881
- let i = n ?? [], a = qe(e), o = [], s = (t) => {
882
- let n = o[t];
883
- if (!n) {
884
- let [r, s] = this.entries[t];
885
- if (!a) n = [
886
- void 0,
887
- e,
888
- e
889
- ];
890
- else {
891
- let t = r instanceof Y ? r.value : r.toCDN();
892
- n = [
893
- t,
894
- r._resolveCdnOptions(e, i, {
895
- parent: this,
896
- isMapKey: !0,
897
- keyNode: r
898
- }),
899
- s._resolveCdnOptions(e, [...i, t], {
900
- parent: this,
901
- keyNode: r
902
- })
903
- ];
904
- }
905
- o[t] = n;
906
- }
907
- return n;
908
- }, c = [], l = (e) => {
909
- let n = c[e];
910
- if (!n) {
911
- let [r, o] = this.entries[e], [l, u, d] = s(e);
912
- n = [r._toCDN(u, t + 1, a ? i : void 0), o._toCDN(d, t + 1, a ? [...i, l] : void 0)], c[e] = n;
913
- }
914
- return n;
915
- };
916
- return r({
917
- node: this,
918
- options: e,
919
- depth: t,
920
- openChar: "{",
921
- closeChar: "}",
922
- count: this.entries.length,
923
- indefiniteLength: this.indefiniteLength,
924
- encodingWidth: this.encodingWidth,
925
- hasEntryComments: (e) => {
926
- let [t, n] = this.entries[e];
927
- return _(t) || _(n);
928
- },
929
- renderEntry: (e, t) => {
930
- let [n, r] = l(e);
931
- return `${n}${t}${r}`;
932
- },
933
- entryIsLeaf: (e) => {
934
- let [t, n] = this.entries[e];
935
- return !t._containsCdnContainer && !n._containsCdnContainer;
936
- },
937
- entryIsMultiWordText: (e) => {
938
- let [t, n] = this.entries[e], [r, o, c] = s(e), u = a ? i : void 0, d = a ? [...i, r] : void 0;
939
- if (t._isMultiWordText(o, !0, u) || n._isMultiWordText(c, !0, d)) return !0;
940
- let [p, m] = l(e);
941
- return f(p) || f(m);
942
- },
943
- entryLeadingNode: (e) => this.entries[e][0],
944
- entryTrailing: (e, t) => {
945
- let [n, r] = this.entries[e];
946
- return et([
947
- ...n.comments?.trailing ?? [],
948
- ...r.comments?.leading ?? [],
949
- ...r.comments?.trailing ?? []
950
- ], t);
951
- },
952
- entryOptions: a ? (e) => s(e)[1] : void 0
953
- });
954
- }
955
- _toHexDump(e, t) {
956
- if (this.indefiniteLength) {
957
- let n = [{
958
- depth: e,
959
- hex: o(191),
960
- comment: "Start indefinite-length map"
961
- }];
962
- for (let [r, i] of this.entries) m(n, r._toHexDump(e + 1, t)), m(n, i._toHexDump(e + 1, t));
963
- return n.push({
964
- depth: e,
965
- hex: o(255),
966
- comment: "\"break\""
967
- }), n;
968
- }
969
- let n = [{
970
- depth: e,
971
- hex: l(Oe(5, BigInt(this.entries.length), this.encodingWidth)),
972
- comment: `Map of length ${this.entries.length}`
973
- }];
974
- for (let [r, i] of this.entries) m(n, r._toHexDump(e + 1, t)), m(n, i._toHexDump(e + 1, t));
975
- return n;
976
- }
977
- _toJS(e, t, n) {
978
- let r = e?.reviver, i = Ie(e), a = t ?? [], o = n ?? Ve, s = () => {
979
- let t = (e, t, n, r) => {
980
- if (!i) return [e._toJS(r), t._toJS(r)];
981
- let s = e._toJSChild(r, a, [...o, `k${n}`], {
982
- parent: this,
983
- isMapKey: !0,
984
- keyNode: e
985
- });
986
- return [s, t._toJSChild(r, [...a, s], [...o, `v${n}`], {
987
- parent: this,
988
- keyNode: e
989
- })];
990
- }, n = $.from(this.entries, ([n, r], i) => t(n, r, i, e));
991
- if (!r) return n;
992
- let s = e?.undefinedOmits;
993
- for (let e = 0; e < n.length; e++) {
994
- let [t, i] = n[e], a = r.call(n, t, i);
995
- a === A || s && a === void 0 ? n.splice(e--, 1) : n[e] = [t, a];
996
- }
997
- return n;
998
- };
999
- return e?.mapAs === "entries" ? s() : e?.mapAs === "object" || this.entries.every(([e]) => e instanceof Y) ? (() => {
1000
- let t = (e, t, n, r, s, c) => i ? t._toJSChild(s, [...a, n], c ? [
1001
- ...o,
1002
- Be,
1003
- `v${r}`
1004
- ] : [...o, `v${r}`], {
1005
- parent: this,
1006
- keyNode: e
1007
- }) : t._toJS(s), n = Le(e), s = {};
1008
- for (let e = 0; e < this.entries.length; e++) {
1009
- let [i, a] = this.entries[e], o = i instanceof Y ? i.value : i.toCDN(), c = t(i, a, o, e, n, !!r);
1010
- o === "__proto__" ? Object.defineProperty(s, o, {
1011
- value: c,
1012
- writable: !0,
1013
- enumerable: !0,
1014
- configurable: !0
1015
- }) : s[o] = c;
1016
- }
1017
- if (!r) return s;
1018
- let c = /* @__PURE__ */ new Map();
1019
- for (let e = 0; e < this.entries.length; e++) {
1020
- let [t] = this.entries[e];
1021
- c.set(t instanceof Y ? t.value : t.toCDN(), e);
1022
- }
1023
- for (let n = 0; n < this.entries.length; n++) {
1024
- let [i, a] = this.entries[n], o = i instanceof Y ? i.value : i.toCDN();
1025
- if (c.get(o) !== n) continue;
1026
- let l = t(i, a, o, n, e, !1), u = r.call(s, o, l);
1027
- u === A || e?.undefinedOmits && u === void 0 ? delete s[o] : o === "__proto__" ? Object.defineProperty(s, o, {
1028
- value: u,
1029
- writable: !0,
1030
- enumerable: !0,
1031
- configurable: !0
1032
- }) : s[o] = u;
1033
- }
1034
- return s;
1035
- })() : s();
1036
- }
1037
- };
1038
- function et(e, t) {
1039
- return e.length === 0 ? "" : " " + e.map((e) => b(e, t).trimEnd()).join(" ");
1040
- }
1041
- //#endregion
1042
- //#region src/ast/CborSimple.ts
1043
- var G = class e extends F {
1044
- value;
1045
- ednSource;
1046
- constructor(e, t) {
1047
- if (super(), !Number.isInteger(e) || e < 0 || e > 255) throw RangeError("CborSimple value must be an integer in 0–255");
1048
- this.value = e, this.ednSource = t?.ednSource;
1049
- }
1050
- static FALSE = new e(20);
1051
- static TRUE = new e(21);
1052
- static NULL = new e(22);
1053
- static UNDEFINED = new e(23);
1054
- _encodeTo(e, t) {
1055
- if (this.value <= 23) {
1056
- e.writeByte(224 | this.value);
1057
- return;
1058
- }
1059
- e.writeByte(248), e.writeByte(this.value);
1060
- }
1061
- _toCDN(e, t) {
1062
- if (e?.preserveNumberFormat && this.ednSource !== void 0) return `simple(${this.ednSource})`;
1063
- switch (this.value) {
1064
- case 20: return "false";
1065
- case 21: return "true";
1066
- case 22: return "null";
1067
- case 23: return "undefined";
1068
- default: return `simple(${this.value})`;
1069
- }
1070
- }
1071
- _toJS(e) {
1072
- switch (this.value) {
1073
- case 20: return !1;
1074
- case 21: return !0;
1075
- case 22: return null;
1076
- case 23: return;
1077
- default: return new he(this.value);
1078
- }
1079
- }
1080
- }, K = class extends F {
1081
- items;
1082
- encodingWidth;
1083
- constructor(e, t) {
1084
- super(), this.items = e, this.encodingWidth = t?.encodingWidth;
1085
- }
1086
- get _containsCdnContainer() {
1087
- return this.items.some((e) => e._containsCdnContainer);
1088
- }
1089
- _content(e) {
1090
- let t = new Te();
1091
- for (let n of this.items) n._encode(t, e);
1092
- return t.finish();
1093
- }
1094
- _encodeTo(e, t) {
1095
- let n = this._content(t);
1096
- N(e, 2, n.length, this.encodingWidth), e.writeBytes(n);
1097
- }
1098
- _toCDN(e, t, n) {
1099
- let i = n ?? [], a = qe(e), o = (t) => a ? this.items[t]._resolveCdnOptions(e, [...i, t], { parent: this }) : e;
1100
- return r({
1101
- node: this,
1102
- options: e,
1103
- depth: t,
1104
- openChar: "<<",
1105
- closeChar: ">>",
1106
- count: this.items.length,
1107
- indefiniteLength: !1,
1108
- encodingWidth: this.encodingWidth,
1109
- eiPosition: "close",
1110
- canonicalCount: () => BigInt(this._content(e).length),
1111
- hasEntryComments: (e) => _(this.items[e]),
1112
- renderEntry: (e) => this.items[e]._toCDN(o(e), t + 1, a ? [...i, e] : void 0),
1113
- alwaysInlineLeaf: !0,
1114
- entryIsMultiWordText: (e) => this.items[e]._isMultiWordText(o(e), !1, a ? [...i, e] : void 0),
1115
- entryLeadingNode: (e) => this.items[e],
1116
- entryTrailing: (e, t) => g(this.items[e], t),
1117
- entryOptions: a ? o : void 0
1118
- });
1119
- }
1120
- _toHexDump(e, t) {
1121
- let n = this._content().length, r = [{
1122
- depth: e,
1123
- hex: l(Oe(2, BigInt(n), this.encodingWidth)),
1124
- comment: `Embedded CBOR sequence, ${n} byte${n === 1 ? "" : "s"}`
1125
- }];
1126
- for (let n of this.items) m(r, n._toHexDump(e + 1, t));
1127
- return r;
1128
- }
1129
- _toJS(e) {
1130
- return this._content();
1131
- }
1132
- };
1133
- //#endregion
1134
- //#region src/utils/strip-comments.ts
1135
- function tt(e) {
1136
- let t = "", n = 0;
1137
- for (; n < e.length;) {
1138
- let r = e[n];
1139
- if (r === " " || r === "\n" || r === "\r") {
1140
- n++;
1141
- continue;
1142
- }
1143
- if (r === "#") {
1144
- for (; n < e.length && e[n] !== "\n";) n++;
1145
- continue;
1146
- }
1147
- if (r === "/") {
1148
- let t = e[n + 1] ?? "";
1149
- if (t === "/") {
1150
- for (; n < e.length && e[n] !== "\n";) n++;
1151
- continue;
1152
- }
1153
- if (t === "*") {
1154
- for (n += 2; n < e.length && (e[n] !== "*" || (e[n + 1] ?? "") !== "/");) n++;
1155
- if (n >= e.length) throw SyntaxError("unterminated block comment");
1156
- n += 2;
1157
- continue;
1158
- }
1159
- for (n++; n < e.length && e[n] !== "/";) n++;
1160
- if (n >= e.length) throw SyntaxError("unterminated block comment");
1161
- n++;
1162
- continue;
1163
- }
1164
- t += r, n++;
1165
- }
1166
- return t;
1167
- }
1168
- //#endregion
1169
- //#region src/extensions/b32.ts
1170
- var nt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", rt = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
1171
- function it(e) {
1172
- let t = e.length;
1173
- for (; t > 0 && e.charCodeAt(t - 1) === 61;) t--;
1174
- return e.slice(0, t);
1175
- }
1176
- function at(e, t, n) {
1177
- let r = it(e).toUpperCase(), i = r.length % 8;
1178
- if (i === 1 || i === 3 || i === 6) throw SyntaxError(`invalid base32 length: ${r.length} characters`);
1179
- let a = (/* @__PURE__ */ new Uint8Array(128)).fill(255);
1180
- for (let e = 0; e < t.length; e++) a[t.charCodeAt(e)] = e;
1181
- let o = new Uint8Array(Math.floor(r.length * 5 / 8)), s = 0, c = 0, l = 0;
1182
- for (let e of r) {
1183
- let t = e.charCodeAt(0), n = t < 128 ? a[t] : 255;
1184
- if (n === 255) throw SyntaxError(`invalid character in byte string: ${JSON.stringify(e)}`);
1185
- s = s << 5 | n, c += 5, c >= 8 && (c -= 8, o[l++] = s >> c & 255);
1186
- }
1187
- if (c > 0 && s & (1 << c) - 1) {
1188
- let e = "non-zero trailing bits in base32 input";
1189
- if (n) n(e);
1190
- else throw SyntaxError(e);
1191
- }
1192
- return o;
1193
- }
1194
- var ot = {
1195
- appStringPrefixes: ["b32"],
1196
- parseAppString(e, t, n) {
1197
- return new B(at(tt(t), nt, n), { ednEncoding: "base32" });
1198
- }
1199
- }, st = {
1200
- appStringPrefixes: ["h32"],
1201
- parseAppString(e, t, n) {
1202
- return new B(at(tt(t), rt, n), { ednEncoding: "base32hex" });
1203
- }
1204
- }, ct = 999n, lt = class extends z {
1205
- constructor(e, t) {
1206
- let n = t.length === 1 && t[0] instanceof Y ? t[0] : new U(t);
1207
- super(ct, new U([new Y(e), n]));
1208
- }
1209
- _toCDN(e, t) {
1210
- if (e?.appPrefix === !1) return super._toCDN(e, t);
1211
- let n = this.content, r = n.items[0].value, i = n.items[1];
1212
- return i instanceof Y ? `${r}${ne(i.value)}` : `${r}<<${i.items.map((n) => n._toCDN(e, t)).join(", ")}>>`;
1213
- }
1214
- }, ut = class extends F {
1215
- inner;
1216
- ednSource;
1217
- constructor(e, t) {
1218
- super(), this.inner = e, this.ednSource = t;
1219
- }
1220
- get _containsCdnContainer() {
1221
- return this.inner._containsCdnContainer;
1222
- }
1223
- _isMultiWordText(e, t = !0, n) {
1224
- return y(this._toCDN(e, 0, n), t);
1225
- }
1226
- _encodeTo(e, t) {
1227
- this.inner._encode(e, t);
1228
- }
1229
- _toCDN(e, t, n) {
1230
- let r = e?.encodingIndicators ?? "auto";
1231
- if (!(e?.appPrefix !== !1 && r === "auto" && (O(e) !== null || !/[\r\n]/.test(this.ednSource)))) return this.inner._toCDN(this.inner._resolveCdnOptions(e, n ?? [], { parent: this }), t, n);
1232
- if (!qe(e)) return this.ednSource;
1233
- let i = e[Ye], a = { applied: !1 }, o = {
1234
- ...e,
1235
- [Ye]: a
1236
- }, s = this.inner._toCDN(this.inner._resolveCdnOptions(o, n ?? [], { parent: this }), t, n);
1237
- return a.applied && i && (i.applied = !0), a.applied ? s : this.ednSource;
1238
- }
1239
- _toJS(e, t, n) {
1240
- return Ie(e) ? this.inner._toJSChild(e, t ?? [], n ?? Ve, { parent: this }) : this.inner._toJS(e);
1241
- }
1242
- }, dt = 888n;
1243
- function ft(e, t, n, r) {
1244
- return n ? [...(e.comments?.trailing ?? []).map((e) => b(e, r)), ...(t.comments?.leading ?? []).map((e) => b(e, r))] : [];
1245
- }
1246
- function pt(e, t, n, r) {
1247
- return n === null || !t.some((e) => e.length > 0) ? e.join(" + ") : oe(e, n, r, t);
1248
- }
1249
- function mt(e, t, r, i) {
1250
- if (e === void 0) return;
1251
- let a = n(t) || i === void 0 ? e : x(e, i);
1252
- return gt(a, r) ? a : void 0;
1253
- }
1254
- function ht(e, t) {
1255
- return e !== void 0 && gt(e, t);
1256
- }
1257
- function gt(e, t) {
1258
- return t !== null || !/[\r\n]/.test(e);
1259
- }
1260
- var q = class e extends z {
1261
- realBoundary;
1262
- fromByteLiteral;
1263
- literalSource;
1264
- constructor(e, t) {
1265
- Array.isArray(e) ? (super(dt, new U(e)), this.fromByteLiteral = !1, this.literalSource = void 0, this.realBoundary = t) : (super(dt, G.NULL), this.fromByteLiteral = e ?? !1, this.literalSource = t, this.realBoundary = void 0);
1266
- }
1267
- _toCDN(t, r) {
1268
- if (t?.appPrefix === !1) return super._toCDN(t, r);
1269
- if (this.content instanceof G) return "...";
1270
- if (this.content instanceof U) {
1271
- let i = !!t?.preserveConcatenation;
1272
- if (i || t?.preserveByteString && !this._hasRealConcatenation()) {
1273
- let e = this._renderPreservedBytesElision(t, r);
1274
- if (e !== void 0) return e;
1275
- }
1276
- if (!i || this.realBoundary === void 0) {
1277
- let e = this._compactHexElided();
1278
- if (e !== void 0) return e;
1279
- }
1280
- let a = this.content.items, o = a.map((e) => i ? this._renderFragment(e, t, r) : e._toCDN(t, r)), s = n(t), c = u(t), l = a.slice(1).map((e, t) => ft(a[t], e, s, c));
1281
- if (t?.modernConcat) {
1282
- let n = a.every((t) => t instanceof B || t instanceof e && t.content instanceof G);
1283
- return ie(n ? "b1" : "t1", o, "", O(t), r, l);
1284
- }
1285
- return pt(o, l, O(t), r);
1286
- }
1287
- return super._toCDN(t, r);
1288
- }
1289
- _hasRealConcatenation() {
1290
- return this.realBoundary?.some((e, t) => t > 0 && e) ? !0 : this.content.items.some((e) => e instanceof B && e.ednParts !== void 0 && e.ednParts.length > 1);
1291
- }
1292
- _renderFragment(e, t, r) {
1293
- let i = O(t), a = n(t), o = u(t), s = !!t?.modernConcat;
1294
- if (e instanceof B && e.ednParts !== void 0 && e.ednParts.length > 1) {
1295
- let n = t?.appPrefix === !1 ? "hex" : t?.bstrEncoding ?? e.ednEncoding, c = e.ednParts.map((e) => {
1296
- let r = t?.preserveByteString ? mt(e.source, t, i, e.commentSyntax) : void 0;
1297
- return r === void 0 ? d(e.bytes, n, t?.sqstr) : r;
1298
- }), l = a ? p(e.comments?.dangling, e.ednParts, o) ?? [] : [];
1299
- return s ? ie("b1", c, "", i, r, l) : pt(c, l, i, r);
1300
- }
1301
- if (e instanceof Y && e.ednParts !== void 0 && e.ednParts.length > 1) {
1302
- let n = t?.preserveRawString ? e.ednPartSources : void 0, c = e.ednParts.map((e, t) => {
1303
- let r = n?.[t];
1304
- return ht(r, i) ? r : h(e);
1305
- }), l = a ? p(e.comments?.dangling, e.ednPartSpans, o) ?? [] : [];
1306
- return s ? ie("t1", c, "", i, r, l) : pt(c, l, i, r);
1307
- }
1308
- return e._toCDN(t, r);
1309
- }
1310
- _compactHexElided() {
1311
- let t = this.content.items, n = "", r = !1;
1312
- for (let i of t) if (i instanceof B) n += s(i.value), r = !0;
1313
- else if (i instanceof e && i.content instanceof G) n += "...";
1314
- else return;
1315
- if (r) return `h'${n}'`;
1316
- }
1317
- _renderPreservedBytesElision(t, r) {
1318
- if (this.realBoundary === void 0) return;
1319
- let i = this.realBoundary, a = this.content.items, o = [], c = [], l = [], f = (e) => {
1320
- l.length > 0 && (o.push(l), c.push(e ?? []), l = []);
1321
- }, m = n(t), h = u(t);
1322
- for (let t = 0; t < a.length; t++) {
1323
- let n = a[t];
1324
- if (t > 0 && i[t] && f(ft(a[t - 1], n, m, h)), n instanceof e && n.content instanceof G) l.push({
1325
- ellipsis: !0,
1326
- fromByteLiteral: n.fromByteLiteral,
1327
- literalSource: n.literalSource
1328
- });
1329
- else if (n instanceof B) {
1330
- if (n.ednParts !== void 0 && n.ednParts.length > 1) {
1331
- let [e, ...t] = n.ednParts;
1332
- l.push({
1333
- bytes: e.bytes,
1334
- source: e.source,
1335
- commentSyntax: e.commentSyntax
1336
- });
1337
- let r = m ? p(n.comments?.dangling, n.ednParts, h) : void 0;
1338
- t.forEach((e, t) => {
1339
- f(r?.[t]), l.push({
1340
- bytes: e.bytes,
1341
- source: e.source,
1342
- commentSyntax: e.commentSyntax
1343
- });
1344
- });
1345
- } else l.push({
1346
- bytes: n.value,
1347
- source: n.ednSource,
1348
- commentSyntax: n.ednCommentSyntax
1349
- });
1350
- } else return;
1351
- }
1352
- if (l.length > 0 && o.push(l), o.length === 0) return;
1353
- let g = t?.appPrefix === !1 ? "hex" : t?.bstrEncoding ?? "hex", _ = O(t), v = o.map((e) => {
1354
- if (t?.preserveByteString) for (let n of e) {
1355
- if (!("ellipsis" in n)) continue;
1356
- let e = mt(n.literalSource, t, _, "full");
1357
- if (e !== void 0) return e;
1358
- }
1359
- let n = e.filter((e) => !("ellipsis" in e));
1360
- if (n.length === 0) return e.some((e) => "ellipsis" in e && e.fromByteLiteral) ? "h'...'" : "...";
1361
- if (e.length === 1) {
1362
- let e = n[0], r = t?.preserveByteString ? mt(e.source, t, _, e.commentSyntax) : void 0;
1363
- return r === void 0 ? d(e.bytes, g, t?.sqstr) : r;
1364
- }
1365
- return `h'${e.map((e) => "ellipsis" in e ? "..." : s(e.bytes)).join("")}'`;
1366
- });
1367
- return t?.preserveConcatenation && t?.modernConcat && v.length > 1 ? ie("b1", v, "", _, r, c) : pt(v, c, _, r);
1368
- }
1369
- }, _t = 2n, vt = 3n, yt = 18446744073709551615n, bt = -18446744073709551616n;
1370
- function xt(e) {
1371
- if (e < 0n) throw RangeError("bigintToBytes requires a non-negative value");
1372
- if (e === 0n) return /* @__PURE__ */ new Uint8Array();
1373
- let t = e.toString(16);
1374
- t.length % 2 != 0 && (t = "0" + t);
1375
- let n = new Uint8Array(t.length / 2);
1376
- for (let e = 0; e < n.length; e++) n[e] = parseInt(t.slice(e * 2, e * 2 + 2), 16);
1377
- return n;
1378
- }
1379
- function St(e) {
1380
- let t = 0n;
1381
- for (let n of e) t = t << 8n | BigInt(n);
1382
- return t;
1383
- }
1384
- var Ct = class extends z {
1385
- bigValue;
1386
- constructor(e) {
1387
- if (e <= yt) throw RangeError(`CborBigUint value ${e} fits in CborUint; use CborUint instead`);
1388
- super(_t, new B(xt(e))), this.bigValue = e;
1389
- }
1390
- _toCDN(e, t) {
1391
- return this.bigValue.toString();
1392
- }
1393
- _toJS(e) {
1394
- return this.bigValue;
1395
- }
1396
- }, wt = class extends z {
1397
- bigValue;
1398
- constructor(e) {
1399
- if (e >= bt) throw RangeError(`CborBigNint value ${e} fits in CborNint; use CborNint instead`);
1400
- super(vt, new B(xt(-1n - e))), this.bigValue = e;
1401
- }
1402
- _toCDN(e, t) {
1403
- return this.bigValue.toString();
1404
- }
1405
- _toJS(e) {
1406
- return this.bigValue;
1407
- }
1408
- }, Tt = new TextEncoder(), Et = new TextDecoder("utf-8", { fatal: !0 }), Dt = new TextDecoder("utf-8", { fatal: !1 });
1409
- function Ot(t, r) {
1410
- let i = new e(t, {
1411
- offset: r?.offset,
1412
- skipRS: r?._skipRS
1413
- }), a = new Jt(i, r ?? {}).parse();
1414
- return (n(r) || r?.preserveAll) && (Bt(a, i.comments, t), Ut(a)), a;
1415
- }
1416
- function kt(e) {
1417
- let t = e, n;
1418
- return /[_][0-7i]$/.test(e) && (n = e[e.length - 1], t = e.slice(0, -2)), {
1419
- numStr: t,
1420
- rawSuffix: n
1421
- };
1422
- }
1423
- function At(e) {
1424
- return e.startsWith("-") ? -BigInt(e.slice(1)) : BigInt(e);
1425
- }
1426
- function jt(e) {
1427
- if (e !== void 0) return Nt([e.appSeqSourceFeatures, Mt(e)]);
1428
- }
1429
- function Mt(e) {
1430
- if (e instanceof B) return {
1431
- byteString: !0,
1432
- concatenation: e.ednParts !== void 0 && e.ednParts.length > 1
1433
- };
1434
- if (e instanceof Y) {
1435
- let t = e.ednParts !== void 0, n = e.ednPartSources?.filter((e) => e !== void 0).length ?? 0, r = t ? e.ednParts.reduce((t, n, r) => {
1436
- let i = e.ednPartSources?.[r] !== void 0, a = e.ednPartIsByteString?.[r] ?? !1;
1437
- return i || !a ? t : t + 1;
1438
- }, 0) : 0, i = (t ? e.ednParts.length : 0) - n - r;
1439
- return {
1440
- byteString: r > 0,
1441
- textString: e.quotedEdnSource !== void 0 || i > 0,
1442
- rawString: e.ednSource !== void 0 || n > 0,
1443
- concatenation: t && e.ednParts.length > 1
1444
- };
1445
- }
1446
- if (e instanceof U) return Nt(e.items.map(jt));
1447
- if (e instanceof W) return Nt(e.entries.flatMap(([e, t]) => [jt(e), jt(t)]));
1448
- if (e instanceof z) return jt(e.content);
1449
- if (e instanceof V || e instanceof H || e instanceof K) return Nt((e instanceof K ? e.items : e.chunks).map(jt));
1450
- }
1451
- function Nt(e) {
1452
- let t = e.filter((e) => e !== void 0);
1453
- if (t.length !== 0) return {
1454
- byteString: t.some((e) => e.byteString),
1455
- textString: t.some((e) => e.textString),
1456
- rawString: t.some((e) => e.rawString),
1457
- concatenation: t.some((e) => e.concatenation)
1458
- };
1459
- }
1460
- function Pt(e, t) {
1461
- if (e.endsWith("_i") || e.endsWith("_0")) {
1462
- let n = "_0 and _i encoding indicators are not valid for floating-point values";
1463
- if (t) t(n), e = e.slice(0, -2);
1464
- else throw SyntaxError(`EDN parse error: ${n}`);
1465
- } else if (/[_][4567]$/.test(e)) {
1466
- let n = e[e.length - 1], r = n === "7" ? "indefinite-length encoding (_7) is not valid for floating-point values" : `encoding indicator _${n} (AI ${Number(n) + 24}) is reserved and not valid`;
1467
- if (t) t(r), e = e.slice(0, -2);
1468
- else throw SyntaxError(`EDN parse error: ${r}`);
1469
- }
1470
- if (e === "NaN") return {
1471
- value: NaN,
1472
- precision: void 0
1473
- };
1474
- if (e === "Infinity") return {
1475
- value: Infinity,
1476
- precision: void 0
1477
- };
1478
- if (e === "-Infinity") return {
1479
- value: -Infinity,
1480
- precision: void 0
1481
- };
1482
- let n = e, r;
1483
- return e.endsWith("_1") ? (r = "half", n = e.slice(0, -2)) : e.endsWith("_2") ? (r = "single", n = e.slice(0, -2)) : e.endsWith("_3") && (r = "double", n = e.slice(0, -2)), /^-?0[xX]/.test(n) ? {
1484
- value: Ze(n),
1485
- precision: r
1486
- } : {
1487
- value: parseFloat(n),
1488
- precision: r
1489
- };
1490
- }
1491
- var Ft = /\r?\n[ \t]*\r?\n/;
1492
- function It(e, t, n) {
1493
- return Ft.test(e.slice(t, n));
1494
- }
1495
- function Lt(e, t, n, r) {
1496
- let i = [];
1497
- for (let a = t; a < e.length; a++) {
1498
- let t = e[a];
1499
- if (t.start >= r) break;
1500
- t.start >= n && t.end <= r && i.push({
1501
- ...t,
1502
- start: t.start - n,
1503
- end: t.end - n
1504
- });
1505
- }
1506
- return i;
1507
- }
1508
- function Rt(e, t, n, r) {
1509
- if (n.end !== void 0) return {
1510
- start: (/_[0-7i]$/.test(e.slice(Math.max(0, n.end - 2), n.end)) ? n.end - 2 : n.end) - t,
1511
- end: n.end - t,
1512
- always: r,
1513
- never: ""
1514
- };
1515
- }
1516
- function zt(t, n, r) {
1517
- if (r instanceof I) {
1518
- let e = Rt(t, n, r, `_${r.encodingWidth ?? E(r.value)}`);
1519
- return e ? [e] : [];
1520
- }
1521
- if (r instanceof L) {
1522
- let e = Rt(t, n, r, `_${r.encodingWidth ?? E(r.argument)}`);
1523
- return e ? [e] : [];
1524
- }
1525
- if (r instanceof R) {
1526
- let e = r.precision ?? P(r.value), i = Rt(t, n, r, e === "half" ? "_1" : e === "single" ? "_2" : "_3");
1527
- return i ? [i] : [];
1528
- }
1529
- if (r instanceof B) {
1530
- let e = Rt(t, n, r, `_${r.encodingWidth ?? E(BigInt(r.value.length))}`);
1531
- return e ? [e] : [];
1532
- }
1533
- if (r instanceof Y) {
1534
- let e = Rt(t, n, r, `_${r.encodingWidth ?? E(BigInt(Tt.encode(r.value).length))}`);
1535
- return e ? [e] : [];
1536
- }
1537
- if (r instanceof U) {
1538
- let i = [];
1539
- if (r.indefiniteLength) return;
1540
- if (r.start !== void 0) {
1541
- let a = new e(t, { offset: r.start }), o = a.consume(), s = a.peek(), c = s.type === "ENCODING_INDICATOR", l = `_${r.encodingWidth ?? E(BigInt(r.items.length))}`, u = t[o.endOffset] ?? "", d = !c && /[+\-.0-9A-Z_a-z]/.test(u) ? " " : "";
1542
- i.push({
1543
- start: (c ? s.offset : o.endOffset) - n,
1544
- end: (c ? s.endOffset : o.endOffset) - n,
1545
- always: l + d,
1546
- never: ""
1547
- });
1548
- }
1549
- for (let e of r.items) {
1550
- let r = zt(t, n, e);
1551
- if (r === void 0) return;
1552
- m(i, r);
1553
- }
1554
- return i;
1555
- }
1556
- }
1557
- function Bt(e, t, n) {
1558
- if (t.length === 0) return;
1559
- let r = Vt(e), i = Wt(n), a = [...r].sort((e, t) => e.start - t.start || t.end - e.end), o = [...r].sort((e, t) => e.end - t.end || e.start - t.start), s = [...t].sort((e, t) => e.start - t.start), c = [], l = 0;
1560
- for (let e of s) {
1561
- let t = { ...e }, r = 0, s = o.length;
1562
- for (; r < s;) {
1563
- let t = r + s >> 1;
1564
- o[t].end <= e.start ? r = t + 1 : s = t;
1565
- }
1566
- let u = r > 0 ? o[r - 1] : void 0, d = u ? n.slice(u.end, e.start) : "";
1567
- if (u && i(u.end) === e.line && !d.includes(":")) {
1568
- Ht(u.node, "trailing", t);
1569
- continue;
1570
- }
1571
- for (; l < a.length && a[l].start < e.start;) {
1572
- let e = a[l++];
1573
- for (; c.length > 0 && c[c.length - 1].end <= e.start;) c.pop();
1574
- c.push(e);
1575
- }
1576
- for (; c.length > 0 && c[c.length - 1].end <= e.start;) c.pop();
1577
- let f = c.length > 0 ? c[c.length - 1] : void 0;
1578
- for (r = 0, s = a.length; r < s;) {
1579
- let t = r + s >> 1;
1580
- a[t].start < e.end ? r = t + 1 : s = t;
1581
- }
1582
- let p = r < a.length ? a[r] : void 0;
1583
- if ((!f || p && p.end <= f.end) && p) {
1584
- t.sameLine = i(e.end) === i(p.start), Ht(p.node, "leading", t);
1585
- continue;
1586
- }
1587
- f && Ht(f.node, "dangling", t);
1588
- }
1589
- }
1590
- function Vt(e) {
1591
- let t = [], n = (e) => {
1592
- if (e.start !== void 0 && e.end !== void 0 && t.push({
1593
- node: e,
1594
- start: e.start,
1595
- end: e.end
1596
- }), e instanceof U || e instanceof K) {
1597
- for (let t of e.items) n(t);
1598
- return;
1599
- }
1600
- if (e instanceof W) {
1601
- for (let [t, r] of e.entries) n(t), n(r);
1602
- return;
1603
- }
1604
- if (e instanceof V || e instanceof H) {
1605
- for (let t of e.chunks) n(t);
1606
- return;
1607
- }
1608
- e instanceof z && n(e.content);
1609
- };
1610
- return n(e), t;
1611
- }
1612
- function Ht(e, t, n) {
1613
- e.comments ??= {}, e.comments[t] ??= [], e.comments[t].push(n);
1614
- }
1615
- function Ut(e) {
1616
- if (e instanceof q) {
1617
- if (e.content instanceof U) {
1618
- let t = e.content.items;
1619
- for (let e of t) Ut(e);
1620
- let n = t[t.length - 1], r = n?.comments?.trailing;
1621
- r !== void 0 && r.length > 0 && !e.comments?.trailing?.length && (e.comments ??= {}, e.comments.trailing = r, n.comments.trailing = void 0);
1622
- }
1623
- return;
1624
- }
1625
- if (e instanceof U || e instanceof K) {
1626
- for (let t of e.items) Ut(t);
1627
- return;
1628
- }
1629
- if (e instanceof W) {
1630
- for (let [t, n] of e.entries) Ut(t), Ut(n);
1631
- return;
1632
- }
1633
- if (e instanceof V || e instanceof H) {
1634
- for (let t of e.chunks) Ut(t);
1635
- return;
1636
- }
1637
- e instanceof z && Ut(e.content);
1638
- }
1639
- function Wt(e) {
1640
- let t = [0];
1641
- for (let n = 0; n < e.length; n++) e[n] === "\n" && t.push(n + 1);
1642
- return (n) => {
1643
- let r = Math.max(0, Math.min(e.length, n));
1644
- r > 0 && r === e.length && r--;
1645
- let i = 0, a = t.length - 1;
1646
- for (; i <= a;) {
1647
- let e = i + a >> 1;
1648
- t[e] <= r ? i = e + 1 : a = e - 1;
1649
- }
1650
- return a + 1;
1651
- };
1652
- }
1653
- var Gt = (e) => `import { ${e} } from '@cbortech/cbor' and pass it via the 'extensions' option (extensions: [${e}])`, Kt = (e, t) => `install ${t}, import { ${e} } from '${t}', and pass it via the 'extensions' option (extensions: [${e}])`, J = (e) => `'${e}' is a default built-in extension that was excluded via the 'builtinExtensions' option; add it back to that array (or omit 'builtinExtensions' to use the default set)`, qt = /* @__PURE__ */ new Map([
1654
- ["b32", Gt("b32")],
1655
- ["h32", Gt("h32")],
1656
- ["same", Gt("same")],
1657
- ["hash", Kt("hash", "@cbortech/hash-extension")],
1658
- ["uuid", Kt("uuid", "@cbortech/uuid-extension")],
1659
- ["UUID", Kt("uuid", "@cbortech/uuid-extension")],
1660
- ["dt", J("dt")],
1661
- ["DT", J("dt")],
1662
- ["ip", J("ip")],
1663
- ["IP", J("ip")],
1664
- ["cri", J("cri")],
1665
- ["CRI", J("cri")],
1666
- ["t1", J("t1")],
1667
- ["b1", J("b1")],
1668
- ["ilbs", J("ilbs")],
1669
- ["ilts", J("ilts")],
1670
- ["float", J("float")]
1671
- ]), Jt = class {
1672
- t;
1673
- _options;
1674
- extByPrefix;
1675
- extByTag;
1676
- unresolvedExtension;
1677
- _pendingWarnings = [];
1678
- _hintedPrefixes = /* @__PURE__ */ new Set();
1679
- constructor(e, t) {
1680
- this.t = e, this._options = t, this.extByPrefix = /* @__PURE__ */ new Map(), this.extByTag = /* @__PURE__ */ new Map(), this.unresolvedExtension = t.unresolvedExtension ?? "cpa999";
1681
- let n = Oi(t.builtinExtensions);
1682
- for (let e of [...n, ...t.extensions ?? []]) {
1683
- for (let t of e.appStringPrefixes ?? []) this.extByPrefix.set(t, e);
1684
- for (let t of e.tagNumbers ?? []) this.extByTag.set(t, e);
1685
- }
1686
- this.t.onEscapeWarning = (e, t, n, r, i) => {
1687
- let o = {
1688
- message: e,
1689
- offset: t,
1690
- line: n,
1691
- column: r,
1692
- endOffset: i
1693
- };
1694
- if (this._pendingWarnings.push(o), this._options.onWarning ? this._options.onWarning(o) : this._options.silent || console.warn(`CDN strict violation at line ${n}, column ${r}: ${e}`), this._options.strict !== !1) throw new a(e, {
1695
- offset: t,
1696
- line: n,
1697
- column: r,
1698
- endOffset: i
1699
- });
1700
- };
1701
- }
1702
- parse() {
1703
- let e = this.parseValue();
1704
- if (this._options.allowTrailing) return e;
1705
- let t = this.t.peek();
1706
- if (t.type !== "EOF") for (this._warnOrFail(`unexpected token after value: ${JSON.stringify(t.value)}`, t), this._pendingWarnings.length > 0 && (e.warnings ??= [], e.warnings.push(...this._pendingWarnings), this._pendingWarnings = []); this.t.peek().type !== "EOF";) this.t.consume();
1707
- return e;
1708
- }
1709
- parseValue() {
1710
- let e = this.t.peek().offset, t = this._parseValueNode();
1711
- if (this.t.peek().type === "UNDERSCORE") {
1712
- let e = this.t.consume();
1713
- this._warnOrFail("bare _ is not a valid encoding indicator; use _0, _1, _2, _3, or _i", e);
1714
- }
1715
- if (this._pendingWarnings.length > 0) {
1716
- t.warnings ??= [];
1717
- for (let e of this._pendingWarnings) t.warnings.push(e);
1718
- this._pendingWarnings = [];
1719
- }
1720
- return t.start = e, t.end = this.t.lastEndOffset, t;
1721
- }
1722
- _parseValueNode() {
1723
- let e = this.t.peek();
1724
- switch (e.type) {
1725
- case "INTEGER": return this.parseIntegerOrTag();
1726
- case "FLOAT": return this.parseFloat();
1727
- case "TSTR":
1728
- case "RAWSTRING": return this.parseString();
1729
- case "BYTES_HEX":
1730
- case "SQSTR":
1731
- case "BYTES_B64": return this.t.consume(), this._parseBytesConcat(this._decodeBytesToken(e), e.type, e.raw, e.offset, e.endOffset);
1732
- case "EMPTY_INDEF_BYTES": return this.t.consume(), new V([]);
1733
- case "EMPTY_INDEF_TEXT": return this.t.consume(), new H([]);
1734
- case "TRUE": return this.t.consume(), new G(21);
1735
- case "FALSE": return this.t.consume(), new G(20);
1736
- case "NULL": return this.t.consume(), new G(22);
1737
- case "UNDEFINED": return this.t.consume(), new G(23);
1738
- case "SIMPLE": return this.parseSimple();
1739
- case "LBRACKET": return this.parseArray();
1740
- case "LBRACE": return this.parseMap();
1741
- case "LPAREN": return this.parseIndefGroup();
1742
- case "LT_LT": return this.parseEmbeddedCBOR();
1743
- case "APP_STRING": {
1744
- this.t.consume();
1745
- let t, n = "";
1746
- if (this.t.peek().type === "ENCODING_INDICATOR") {
1747
- let e = this.t.consume();
1748
- t = this._resolveEncodingWidth(e.value, e), n = e.raw;
1749
- }
1750
- let r = this.extByPrefix.get(e.appPrefix);
1751
- if (!r?.parseAppString) {
1752
- if (r || this._hintMissingExtension(e.appPrefix, e), this.unresolvedExtension === "cpa999") return new lt(e.appPrefix, [new Y(e.value)]);
1753
- this._fail(`unknown app-string extension: ${JSON.stringify(e.appPrefix)}`, e);
1754
- }
1755
- {
1756
- let i = this._pendingWarnings.length;
1757
- try {
1758
- let i = r.parseAppString(e.appPrefix, e.value, this._extOnError(e), t === void 0 ? void 0 : { encodingWidth: t });
1759
- return t !== void 0 && this._applyEiToResult(i, t, e), r.preserveAppSeqSource === "optional" ? (i.appSeqSource = e.raw + n, i) : i instanceof B && Object.getPrototypeOf(i) === B.prototype && i.ednSource === void 0 ? new B(i.value, {
1760
- ednEncoding: i.ednEncoding,
1761
- encodingWidth: i.encodingWidth,
1762
- ednSource: e.raw + n,
1763
- ednCommentSyntax: r === ot || r === st ? "full" : void 0
1764
- }) : (i instanceof R && i.ednSource === void 0 && (i.ednSource = e.raw + n), i);
1765
- } catch (t) {
1766
- if (this._options.strict !== !1) throw t;
1767
- return this._pendingWarnings.length === i && this._warn(t instanceof Error ? t.message : String(t), e), new lt(e.appPrefix, [new Y(e.value)]);
1768
- }
1769
- }
1770
- }
1771
- case "APP_SEQUENCE": {
1772
- let t = this.t.comments.length;
1773
- this.t.consume();
1774
- let n = [];
1775
- for (; this.t.peek().type !== "GT_GT";) {
1776
- if (this.t.peek().type === "EOF" && this._fail(`unterminated ${e.appPrefix}<<...>>`, e), n.length > 0) {
1777
- if (this.t.peek().type === "COMMA") {
1778
- if (this.t.consume(), this.t.peek().type === "GT_GT") break;
1779
- } else this.t.peek().offset === this.t.lastEndOffset && this._warnOrFail("<<...>> items must be separated by \",\" or whitespace", this.t.peek());
1780
- }
1781
- n.push(this.parseValue());
1782
- }
1783
- this.expect("GT_GT");
1784
- let r, i;
1785
- this.t.peek().type === "ENCODING_INDICATOR" && (i = this.t.consume(), r = this._resolveEncodingWidth(i.value, i));
1786
- let a = this.extByPrefix.get(e.appPrefix);
1787
- if (!a) {
1788
- if (this._hintMissingExtension(e.appPrefix, e), this.unresolvedExtension === "cpa999") return new lt(e.appPrefix, n);
1789
- this._fail(`unknown app-string extension: ${JSON.stringify(e.appPrefix)}`, e);
1790
- }
1791
- a.parseAppSequence || this._fail(`app-string extension ${JSON.stringify(e.appPrefix)} does not support <<...>> form`, e);
1792
- {
1793
- let o = this._pendingWarnings.length;
1794
- try {
1795
- let o = a.parseAppSequence(e.appPrefix, n, this._extOnError(e));
1796
- r !== void 0 && this._applyEiToResult(o, r, i ?? e);
1797
- let s = this.t.source.slice(e.offset, this.t.lastEndOffset);
1798
- if (a.preserveAppSeqSource === "optional") o.appSeqSource = s, o.appSeqComments = Lt(this.t.comments, t, e.offset, this.t.lastEndOffset), n.length === 1 && (n[0].end !== void 0 && (o.appSeqInnerEnd = n[0].end - e.offset), o.appSeqSourceFeatures = jt(n[0]));
1799
- else if (o instanceof R) o.ednSource === void 0 && (o.ednSource = s);
1800
- else if (a.preserveAppSeqSource) return new ut(o, s);
1801
- return o;
1802
- } catch (t) {
1803
- if (this._options.strict !== !1) throw t;
1804
- return this._pendingWarnings.length === o && this._warn(t instanceof Error ? t.message : String(t), e), new lt(e.appPrefix, n);
1805
- }
1806
- }
1807
- }
1808
- case "ELLIPSIS": {
1809
- if (this.t.consume(), this.t.peek().type !== "PLUS") return new q();
1810
- let e = [new q()];
1811
- for (; this.t.peek().type === "PLUS";) this.t.consume(), e.push(this.parseValue());
1812
- return new q(e, e.map(() => !0));
1813
- }
1814
- case "BYTES_HEX_ELIDED": return this.t.consume(), this._parseHexElidedConcat(e);
1815
- default: this._fail(`unexpected token: ${JSON.stringify(e.value)}`, e);
1816
- }
1817
- }
1818
- parseIntegerOrTag() {
1819
- let e = this.t.comments.length, t = this.t.consume(), { numStr: n, rawSuffix: r } = kt(t.value), i = r === void 0 ? t.endOffset : t.endOffset - 2, a = t.endOffset, o = r === void 0 ? this.consumeEncodingIndicator(void 0, (e) => {
1820
- i = e.offset, a = e.endOffset;
1821
- }) : this._resolveEncodingWidth(r, t), s = At(n), c = r === void 0 ? t.raw : t.raw.slice(0, -2);
1822
- if (s > 18446744073709551615n) return this.t.peek().type === "LPAREN" && this._fail("tag number exceeds maximum uint64", t), new Ct(s);
1823
- if (s < -18446744073709551616n) return new wt(s);
1824
- if (o !== void 0) {
1825
- let e = s >= 0n ? s : -(s + 1n);
1826
- o = this._validateEncodingFit(e, o, t);
1827
- }
1828
- let l = s >= 0n ? new I(s, {
1829
- encodingWidth: o,
1830
- ednSource: c
1831
- }) : new L(s, {
1832
- encodingWidth: o,
1833
- ednSource: c
1834
- });
1835
- if (this.t.peek().type === "LPAREN") {
1836
- l instanceof I || this._fail("tag number must be non-negative", t), this.t.consume();
1837
- let n = this._pendingWarnings.splice(0), r = this.parseValue();
1838
- this.expect("RPAREN");
1839
- let s = l.value, u = this.extByTag.get(s);
1840
- if (u?.parseTag) {
1841
- let l = u.parseTag(s, r);
1842
- if (l !== void 0) {
1843
- if (l instanceof z && (o !== void 0 && l.encodingWidth === void 0 && (l.encodingWidth = o), l.ednSource === void 0 && (l.ednSource = c), u.preserveAppSeqSource === "optional" && l.appSeqSource === void 0)) {
1844
- l.appSeqSource = this.t.source.slice(t.offset, this.t.lastEndOffset), l.appSeqComments = Lt(this.t.comments, e, t.offset, this.t.lastEndOffset);
1845
- let n = l.encodingWidth ?? E(l.tag), o = zt(this.t.source, t.offset, l.content);
1846
- l.appSeqEncodingEdits = [{
1847
- start: i - t.offset,
1848
- end: a - t.offset,
1849
- always: `_${n}`,
1850
- never: ""
1851
- }, ...o ?? []], o === void 0 && (l.appSeqEncodingEditsComplete = !1), l.appSeqSourceFeatures = jt(r);
1852
- }
1853
- return n.length > 0 && (l.warnings ??= [], l.warnings.push(...n)), l;
1854
- }
1855
- }
1856
- let d = new z(s, r, {
1857
- encodingWidth: o,
1858
- ednSource: c
1859
- });
1860
- return n.length > 0 && (d.warnings ??= [], d.warnings.push(...n)), d;
1861
- }
1862
- return l;
1863
- }
1864
- parseFloat() {
1865
- let e = this.t.consume(), t = (t) => this._warnOrFail(t, e), { value: n, precision: r } = Pt(e.value, t);
1866
- if (r === "half" || r === "single") {
1867
- let e = r === "half" ? j(ve(n)) : Math.fround(n);
1868
- Object.is(n, e) || isNaN(n) && isNaN(e) || t(`${n} cannot be exactly represented as ${r === "half" ? "f16 (_1)" : "f32 (_2)"}; use _3 or remove the indicator`);
1869
- }
1870
- return new R(n, {
1871
- precision: r,
1872
- literalSource: e.raw
1873
- });
1874
- }
1875
- parseString() {
1876
- let e = this.t.consume();
1877
- if (this.t.peek().type !== "PLUS") {
1878
- let t = this.consumeEncodingIndicator(() => BigInt(Tt.encode(e.value).length));
1879
- return e.type === "RAWSTRING" ? new Y(e.value, {
1880
- ednSource: e.raw,
1881
- ...t === void 0 ? {} : { encodingWidth: t }
1882
- }) : new Y(e.value, {
1883
- quotedEdnSource: e.raw,
1884
- ...t === void 0 ? {} : { encodingWidth: t }
1885
- });
1886
- }
1887
- let t = !1, n = [e.type === "RAWSTRING" ? {
1888
- text: e.value,
1889
- source: e.raw,
1890
- start: e.offset,
1891
- end: e.endOffset
1892
- } : {
1893
- text: e.value,
1894
- start: e.offset,
1895
- end: e.endOffset
1896
- }];
1897
- for (; this.t.peek().type === "PLUS";) {
1898
- this.t.consume();
1899
- let e = this.t.peek();
1900
- e.type === "ELLIPSIS" ? (this.t.consume(), n.push({
1901
- ellipsis: !0,
1902
- start: e.offset,
1903
- end: e.endOffset
1904
- }), t = !0) : e.type === "TSTR" || e.type === "RAWSTRING" ? (this.t.consume(), n.push(e.type === "RAWSTRING" ? {
1905
- text: e.value,
1906
- source: e.raw,
1907
- start: e.offset,
1908
- end: e.endOffset
1909
- } : {
1910
- text: e.value,
1911
- start: e.offset,
1912
- end: e.endOffset
1913
- })) : this._isBytesToken(e.type) ? (this.t.consume(), n.push({
1914
- text: this._decodeUtf8(this._decodeBytesToken(e), e),
1915
- isByteString: !0,
1916
- start: e.offset,
1917
- end: e.endOffset
1918
- })) : this._fail(`expected string or byte string after +, got ${JSON.stringify(e.value)}`, e);
1919
- }
1920
- if (!t) {
1921
- let e = n.map((e) => "text" in e ? e.text : ""), t = n.map((e) => "text" in e ? e.source : void 0), r = n.map((e) => "text" in e ? e.isByteString ?? !1 : !1), i = n.map((e) => ({
1922
- start: e.start,
1923
- end: e.end
1924
- })), a = e.join(""), o = this.consumeEncodingIndicator(() => BigInt(Tt.encode(a).length));
1925
- return new Y(a, {
1926
- ednParts: e,
1927
- ednPartSpans: i,
1928
- ...t.some((e) => e !== void 0) ? { ednPartSources: t } : {},
1929
- ...r.some((e) => e) ? { ednPartIsByteString: r } : {},
1930
- ...o === void 0 ? {} : { encodingWidth: o }
1931
- });
1932
- }
1933
- let r = [], i = [], a = () => {
1934
- let e = i.map((e) => e.text), t = e.join("");
1935
- if (t !== "") {
1936
- let n = i.map((e) => e.source), a = i.map((e) => e.isByteString ?? !1), o = new Y(t, {
1937
- ednParts: e,
1938
- ednPartSpans: i.map((e) => ({
1939
- start: e.start,
1940
- end: e.end
1941
- })),
1942
- ...n.some((e) => e !== void 0) ? { ednPartSources: n } : {},
1943
- ...a.some((e) => e) ? { ednPartIsByteString: a } : {}
1944
- });
1945
- o.start = i[0].start, o.end = i[i.length - 1].end, r.push(o);
1946
- }
1947
- i.length = 0;
1948
- };
1949
- for (let e of n) if ("ellipsis" in e) {
1950
- a();
1951
- let t = new q();
1952
- t.start = e.start, t.end = e.end, r.push(t);
1953
- } else i.push(e);
1954
- return a(), new q(r);
1955
- }
1956
- _isBytesToken(e) {
1957
- return e === "BYTES_HEX" || e === "SQSTR" || e === "BYTES_B64";
1958
- }
1959
- _hexToBytes(e, t) {
1960
- try {
1961
- return i(e);
1962
- } catch (e) {
1963
- if (e instanceof a || !(e instanceof SyntaxError)) throw e;
1964
- this._fail(e.message, t);
1965
- }
1966
- }
1967
- _decodeBytesToken(e) {
1968
- let t = (t) => this._warnOrFail(t, e);
1969
- switch (e.type) {
1970
- case "SQSTR": {
1971
- let t = e._sqstrBytes;
1972
- return t === void 0 ? this._hexToBytes(e.value, e) : t;
1973
- }
1974
- case "BYTES_HEX": return this._hexToBytes(e.value, e);
1975
- case "BYTES_B64": try {
1976
- return ee(e.value, t);
1977
- } catch (t) {
1978
- if (t instanceof a || !(t instanceof SyntaxError)) throw t;
1979
- this._fail(t.message, e);
1980
- }
1981
- default: this._fail("expected byte string token", e);
1982
- }
1983
- }
1984
- _decodeUtf8(e, t) {
1985
- if (this._options.allowInvalidUtf8) return Dt.decode(e);
1986
- try {
1987
- return Et.decode(e);
1988
- } catch {
1989
- return this._warnOrFail("byte string in text concatenation is not valid UTF-8", t), Dt.decode(e);
1990
- }
1991
- }
1992
- _tokenTypeToCdnEncoding(e) {
1993
- return e === "BYTES_B64" ? "base64" : "hex";
1994
- }
1995
- _tokenTypeToCommentSyntax(e) {
1996
- if (e === "BYTES_HEX") return "full";
1997
- if (e === "BYTES_B64") return "hash-only";
1998
- }
1999
- _parseBytesConcat(e, t, n, r, i) {
2000
- if (this.t.peek().type !== "PLUS") {
2001
- let r = this.consumeEncodingIndicator(() => BigInt(e.length));
2002
- return new B(e, {
2003
- ednEncoding: this._tokenTypeToCdnEncoding(t),
2004
- ednSource: n,
2005
- ednCommentSyntax: this._tokenTypeToCommentSyntax(t),
2006
- ...r === void 0 ? {} : { encodingWidth: r }
2007
- });
2008
- }
2009
- let a = [{
2010
- bytes: e,
2011
- source: n,
2012
- commentSyntax: this._tokenTypeToCommentSyntax(t),
2013
- real: !1,
2014
- start: r,
2015
- end: i
2016
- }], o = this._consumeByteEllipsisChain(a);
2017
- return this._buildFromByteAtoms(o, this._tokenTypeToCdnEncoding(t));
2018
- }
2019
- _parseHexElidedConcat(e) {
2020
- let t = this._consumeByteEllipsisChain(this._elidedHexAtoms(e.value, e));
2021
- return this._buildFromByteAtoms(t, "hex");
2022
- }
2023
- _consumeByteEllipsisChain(e) {
2024
- let t = e;
2025
- for (; this.t.peek().type === "PLUS";) {
2026
- this.t.consume();
2027
- let e = this.t.peek();
2028
- if (e.type === "ELLIPSIS") this.t.consume(), t.push({
2029
- ellipsis: !0,
2030
- real: !0,
2031
- fromByteLiteral: !1,
2032
- start: e.offset,
2033
- end: e.endOffset
2034
- });
2035
- else if (e.type === "BYTES_HEX_ELIDED") {
2036
- this.t.consume();
2037
- let n = this._elidedHexAtoms(e.value, e);
2038
- n.length > 0 && (n[0].real = !0), m(t, n);
2039
- } else this._isBytesToken(e.type) ? (this.t.consume(), t.push({
2040
- bytes: this._decodeBytesToken(e),
2041
- source: e.raw,
2042
- commentSyntax: this._tokenTypeToCommentSyntax(e.type),
2043
- real: !0,
2044
- start: e.offset,
2045
- end: e.endOffset
2046
- })) : e.type === "TSTR" || e.type === "RAWSTRING" ? (this.t.consume(), this._warnOrFail("text string in a byte-string concatenation is not allowed; use a byte string literal (h'...', b64'...', or '...') instead", e), t.push({
2047
- bytes: Tt.encode(e.value),
2048
- real: !0,
2049
- start: e.offset,
2050
- end: e.endOffset
2051
- })) : this._fail(`expected byte string after +, got ${JSON.stringify(e.value)}`, e);
2052
- }
2053
- return t;
2054
- }
2055
- _elidedHexAtoms(e, t) {
2056
- let n = e.split("..."), r = [];
2057
- for (let e = 0; e < n.length; e++) e > 0 && r.push({
2058
- ellipsis: !0,
2059
- real: !1,
2060
- fromByteLiteral: !0,
2061
- literalSource: t.raw,
2062
- start: t.offset,
2063
- end: t.endOffset
2064
- }), n[e].length > 0 && r.push({
2065
- bytes: this._hexToBytes(n[e], t),
2066
- commentSyntax: "full",
2067
- real: !1,
2068
- start: t.offset,
2069
- end: t.endOffset
2070
- });
2071
- return r;
2072
- }
2073
- _buildFromByteAtoms(e, t) {
2074
- if (!e.some((e) => "ellipsis" in e)) {
2075
- let n = e, r = this._concatBytes(n.map((e) => e.bytes)), i = this.consumeEncodingIndicator(() => BigInt(r.length));
2076
- return new B(r, {
2077
- ednEncoding: t,
2078
- ednParts: n,
2079
- ...i === void 0 ? {} : { encodingWidth: i }
2080
- });
2081
- }
2082
- let n = [], r = [], i = [], a = () => {
2083
- if (i.length > 0) {
2084
- let e = new B(this._concatBytes(i.map((e) => e.bytes)), { ...i.length > 1 ? { ednParts: i.map(({ bytes: e, source: t, commentSyntax: n, start: r, end: i }) => ({
2085
- bytes: e,
2086
- source: t,
2087
- commentSyntax: n,
2088
- start: r,
2089
- end: i
2090
- })) } : {
2091
- ednSource: i[0].source,
2092
- ednCommentSyntax: i[0].commentSyntax
2093
- } });
2094
- e.start = i[0].start, e.end = i[i.length - 1].end, n.push(e), r.push(i[0].real), i.length = 0;
2095
- }
2096
- };
2097
- for (let t of e) if ("ellipsis" in t) {
2098
- a();
2099
- let e = new q(t.fromByteLiteral, t.literalSource);
2100
- e.start = t.start, e.end = t.end, n.push(e), r.push(t.real);
2101
- } else i.push(t);
2102
- return a(), new q(n, r);
2103
- }
2104
- _concatBytes(e) {
2105
- let t = e.reduce((e, t) => e + t.byteLength, 0), n = new Uint8Array(t), r = 0;
2106
- for (let t of e) n.set(t, r), r += t.byteLength;
2107
- return n;
2108
- }
2109
- parseSimple() {
2110
- this.t.consume(), this.expect("LPAREN");
2111
- let e = this.t.peek();
2112
- e.type !== "INTEGER" && this._fail(`expected integer inside simple(), got ${JSON.stringify(e.value)}`, e), this.t.consume();
2113
- let { numStr: t } = kt(e.value), n = Number(At(t));
2114
- return this.expect("RPAREN"), new G(n, { ednSource: e.raw });
2115
- }
2116
- parseEmbeddedCBOR() {
2117
- this.t.consume();
2118
- let e = [];
2119
- for (; this.t.peek().type !== "GT_GT";) {
2120
- if (e.length > 0) {
2121
- if (this.t.peek().type === "COMMA") {
2122
- if (this.t.consume(), this.t.peek().type === "GT_GT") break;
2123
- } else this.t.peek().offset === this.t.lastEndOffset && this._warnOrFail("<<...>> items must be separated by \",\" or whitespace", this.t.peek());
2124
- }
2125
- e.push(this.parseValue());
2126
- }
2127
- this.expect("GT_GT");
2128
- let t;
2129
- if (this.t.peek().type === "ENCODING_INDICATOR") {
2130
- let e = this.t.consume();
2131
- t = this._resolveEncodingWidth(e.value, e);
2132
- }
2133
- return new K(e, { encodingWidth: t });
2134
- }
2135
- parseArray() {
2136
- this.t.consume();
2137
- let e = !1, t, n;
2138
- this.t.peek().type === "UNDERSCORE" ? (this.t.consume(), e = !0) : this.t.peek().type === "ENCODING_INDICATOR" && (n = this.t.consume(), n.value === "7" ? (e = !0, this._warnOrFail("encoding indicator _7 is non-standard; use _ to indicate indefinite length", n), n = void 0) : t = this._resolveEncodingWidth(n.value, n));
2139
- let r = this._pendingWarnings.splice(0), i = [], a = this.t.lastEndOffset;
2140
- for (; this.t.peek().type !== "RBRACKET";) {
2141
- if (i.length > 0) {
2142
- if (this.t.peek().type === "COMMA") {
2143
- if (this.t.consume(), this.t.peek().type === "RBRACKET") break;
2144
- } else this.t.peek().offset === this.t.lastEndOffset && this._warnOrFail("array items must be separated by \",\" or whitespace", this.t.peek());
2145
- }
2146
- let e = this.parseValue();
2147
- It(this.t.source, a, e.start) && (e.blankLineBefore = !0), a = e.end, i.push(e);
2148
- }
2149
- this.expect("RBRACKET"), t !== void 0 && n !== void 0 && (t = this._validateEncodingFit(BigInt(i.length), t, n));
2150
- let o = new U(i, {
2151
- indefiniteLength: e,
2152
- encodingWidth: t
2153
- });
2154
- return r.length > 0 && (o.warnings ??= [], o.warnings.push(...r)), o;
2155
- }
2156
- parseMap() {
2157
- this.t.consume();
2158
- let e = !1, t, n;
2159
- this.t.peek().type === "UNDERSCORE" ? (this.t.consume(), e = !0) : this.t.peek().type === "ENCODING_INDICATOR" && (n = this.t.consume(), n.value === "7" ? (e = !0, this._warnOrFail("encoding indicator _7 is non-standard; use _ to indicate indefinite length", n), n = void 0) : t = this._resolveEncodingWidth(n.value, n));
2160
- let r = this._pendingWarnings.splice(0), i = [], a = this.t.lastEndOffset;
2161
- for (; this.t.peek().type !== "RBRACE";) {
2162
- if (i.length > 0) {
2163
- if (this.t.peek().type === "COMMA") {
2164
- if (this.t.consume(), this.t.peek().type === "RBRACE") break;
2165
- } else this.t.peek().offset === this.t.lastEndOffset && this._warnOrFail("map entries must be separated by \",\" or whitespace", this.t.peek());
2166
- }
2167
- let e = this.parseValue();
2168
- It(this.t.source, a, e.start) && (e.blankLineBefore = !0), this.expect("COLON");
2169
- let t = this.parseValue();
2170
- a = t.end, i.push([e, t]);
2171
- }
2172
- this.expect("RBRACE"), t !== void 0 && n !== void 0 && (t = this._validateEncodingFit(BigInt(i.length), t, n));
2173
- let o = new W(i, {
2174
- indefiniteLength: e,
2175
- encodingWidth: t
2176
- });
2177
- return r.length > 0 && (o.warnings ??= [], o.warnings.push(...r)), o;
2178
- }
2179
- parseIndefGroup() {
2180
- this.t.consume();
2181
- let e = this.t.peek();
2182
- if (e.type === "UNDERSCORE") this.t.consume();
2183
- else if (e.type === "ENCODING_INDICATOR" && e.value === "7") this.t.consume(), this._warnOrFail("encoding indicator _7 is non-standard; use _ to indicate indefinite length", e);
2184
- else if (e.type === "ENCODING_INDICATOR") {
2185
- let e = this.t.consume(), t = `encoding indicator _${e.value} is not valid in an indefinite string group; use _`;
2186
- this._warnOrFail(t, e);
2187
- } else e.type !== "RPAREN" && this._warnOrFail("indefinite string group is missing _ after (; interpreting as (_ ...)", e);
2188
- let t = this._pendingWarnings.splice(0), n = [], r = this.t.lastEndOffset;
2189
- for (; this.t.peek().type !== "RPAREN";) {
2190
- if (n.length > 0) {
2191
- if (this.t.peek().type === "COMMA") {
2192
- if (this.t.consume(), this.t.peek().type === "RPAREN") break;
2193
- } else this.t.peek().offset === this.t.lastEndOffset && this._warnOrFail("indefinite string chunks must be separated by \",\" or whitespace", this.t.peek());
2194
- }
2195
- let e = this.parseValue();
2196
- It(this.t.source, r, e.start) && (e.blankLineBefore = !0), r = e.end, n.push(e);
2197
- }
2198
- this.expect("RPAREN"), n.length === 0 && this._fail("empty indefinite group (_ ) is ambiguous; use ''_ for bytes or \"\"_ for text");
2199
- let i = n[0];
2200
- if (i instanceof B) {
2201
- let e = new V(n.map((e, t) => {
2202
- if (e instanceof B) return e;
2203
- this._fail(`indefinite byte string chunk ${t} must be a byte string, not a text string`);
2204
- }));
2205
- return t.length > 0 && (e.warnings = t), e;
2206
- }
2207
- if (i instanceof Y) {
2208
- let e = new H(n.map((e, t) => {
2209
- if (e instanceof Y) return e;
2210
- this._fail(`indefinite text string chunk ${t} must be a text string, not a byte string`);
2211
- }));
2212
- return t.length > 0 && (e.warnings = t), e;
2213
- }
2214
- this._fail("indefinite group chunks must be byte strings or text strings");
2215
- }
2216
- consumeEncodingIndicator(e, t) {
2217
- if (this.t.peek().type === "ENCODING_INDICATOR") {
2218
- let n = this.t.consume();
2219
- t?.(n);
2220
- let r = this._resolveEncodingWidth(n.value, n);
2221
- return r !== void 0 && e !== void 0 && (r = this._validateEncodingFit(e(), r, n)), r;
2222
- }
2223
- }
2224
- expect(e) {
2225
- let t = this.t.consume();
2226
- return t.type !== e && this._fail(`expected ${e}, got ${t.type} (${JSON.stringify(t.value)})`, t), t;
2227
- }
2228
- _applyEiToResult(e, t, n) {
2229
- if (e instanceof R) {
2230
- let r = t === 1 ? "half" : t === 2 ? "single" : t === 3 ? "double" : void 0;
2231
- if (r === void 0) this._warnOrFail(`encoding indicator _${t} is not valid for a float; use _1, _2, or _3`, n);
2232
- else if (e.precision !== r) {
2233
- if (r !== "double") {
2234
- let t = r === "half" ? j(ve(e.value)) : Math.fround(e.value);
2235
- !Object.is(t, e.value) && !isNaN(e.value) && this._warnOrFail(`${e.value} cannot be exactly represented as ${r === "half" ? "float16 (_1)" : "float32 (_2)"}`, n);
2236
- }
2237
- e.precision = r;
2238
- }
2239
- } else if (e instanceof I) {
2240
- if (e.encodingWidth === void 0) {
2241
- let r = this._validateEncodingFit(e.value, t, n);
2242
- r !== void 0 && (e.encodingWidth = r);
2243
- }
2244
- } else if (e instanceof L) {
2245
- if (e.encodingWidth === void 0) {
2246
- let r = this._validateEncodingFit(e.argument, t, n);
2247
- r !== void 0 && (e.encodingWidth = r);
2248
- }
2249
- } else if (e instanceof B) {
2250
- if (e.encodingWidth === void 0) {
2251
- let r = this._validateEncodingFit(BigInt(e.value.length), t, n);
2252
- r !== void 0 && (e.encodingWidth = r);
2253
- }
2254
- } else if (e instanceof Y) {
2255
- if (e.encodingWidth === void 0) {
2256
- let r = this._validateEncodingFit(BigInt(Tt.encode(e.value).length), t, n);
2257
- r !== void 0 && (e.encodingWidth = r);
2258
- }
2259
- } else if (e instanceof U) {
2260
- if (e.encodingWidth === void 0) {
2261
- let r = this._validateEncodingFit(BigInt(e.items.length), t, n);
2262
- r !== void 0 && (e.encodingWidth = r);
2263
- }
2264
- } else if (e instanceof W) {
2265
- if (e.encodingWidth === void 0) {
2266
- let r = this._validateEncodingFit(BigInt(e.entries.length), t, n);
2267
- r !== void 0 && (e.encodingWidth = r);
2268
- }
2269
- } else if (e instanceof z) {
2270
- if (e.encodingWidth === void 0) {
2271
- let r = this._validateEncodingFit(e.tag, t, n);
2272
- r !== void 0 && (e.encodingWidth = r);
2273
- }
2274
- } else this._warnOrFail(`encoding indicator _${t} is not applicable to this app-string result type`, n);
2275
- }
2276
- _validateEncodingFit(e, t, n) {
2277
- let r = De(t);
2278
- if (e <= r) return t;
2279
- let i = `value ${e} does not fit in encoding indicator ${t === "i" ? "_i (max 23)" : `_${t} (max ${r})`}`;
2280
- this._warnOrFail(i, n);
2281
- }
2282
- _resolveEncodingWidth(e, t) {
2283
- if (e === "4" || e === "5" || e === "6") {
2284
- let n = `encoding indicator _${e} (AI ${Number(e) + 24}) is reserved and not valid`;
2285
- this._warnOrFail(n, t);
2286
- return;
2287
- }
2288
- if (e === "7") {
2289
- this._warnOrFail("indefinite-length encoding (_7) is not valid here; use [_ ...] or {_ ...} for indefinite collections", t);
2290
- return;
2291
- }
2292
- return e === "i" ? "i" : Number(e);
2293
- }
2294
- _extOnError(e) {
2295
- return (t) => this._warnOrFail(t, e);
2296
- }
2297
- _warnOrFail(e, t) {
2298
- this._warn(e, t), this._options.strict !== !1 && this._fail(e, t);
2299
- }
2300
- _hintMissingExtension(e, t) {
2301
- let n = qt.get(e);
2302
- if (n === void 0 || this._hintedPrefixes.has(e)) return;
2303
- this._hintedPrefixes.add(e);
2304
- let r = `app-string prefix '${e}' requires an extension that is not enabled; ${n}`;
2305
- this._options.onWarning ? this._options.onWarning({
2306
- message: r,
2307
- ...Yt(t),
2308
- hint: !0
2309
- }) : this._options.silent || console.warn(`CDN: ${r}`);
2310
- }
2311
- _warn(e, t) {
2312
- let n = { message: e };
2313
- if (t !== void 0 && Object.assign(n, Yt(t)), this._pendingWarnings.push(n), this._options.onWarning) this._options.onWarning(n);
2314
- else if (!this._options.silent) {
2315
- let n = t ? ` at line ${t.line}, column ${t.col}` : "";
2316
- console.warn(`CDN strict violation${n}: ${e}`);
2317
- }
2318
- }
2319
- _fail(e, t) {
2320
- throw new a(e, t ? Yt(t) : void 0);
2321
- }
2322
- };
2323
- function Yt(e) {
2324
- return {
2325
- offset: e.offset,
2326
- line: e.line,
2327
- column: e.col,
2328
- endOffset: e.endOffset
2329
- };
2330
- }
2331
- //#endregion
2332
- //#region src/ast/CborTextString.ts
2333
- var Xt = new TextEncoder(), Zt = new TextDecoder(), Qt = !1, Y = class extends F {
2334
- indefiniteLength = !1;
2335
- value;
2336
- encodingWidth;
2337
- ednParts;
2338
- ednSource;
2339
- quotedEdnSource;
2340
- ednPartSources;
2341
- ednPartIsByteString;
2342
- ednPartSpans;
2343
- constructor(e, t) {
2344
- super(), this.value = e, this.encodingWidth = t?.encodingWidth, this.ednParts = t?.ednParts, this.ednSource = t?.ednSource, this.quotedEdnSource = t?.quotedEdnSource, this.ednPartSources = t?.ednPartSources, this.ednPartIsByteString = t?.ednPartIsByteString, this.ednPartSpans = t?.ednPartSpans;
2345
- }
2346
- _isMultiWordText(e, t = !0, n) {
2347
- return v(this.value);
2348
- }
2349
- _encodeTo(e, t) {
2350
- e.writeTextString(3, this.value, this.encodingWidth);
2351
- }
2352
- _toCDN(e, n, r) {
2353
- let i = t(e, this.encodingWidth, () => E(BigInt(Xt.encode(this.value).length)));
2354
- return $t(this.value, i, e, n, this.ednParts, this.ednSource, this.quotedEdnSource, this.ednPartSources, this.ednPartSpans, this.comments?.dangling);
2355
- }
2356
- _toJS(e) {
2357
- return this.value;
2358
- }
2359
- };
2360
- function $t(e, t, r, i, a, o, s, c, l, d) {
2361
- let f = O(r);
2362
- if (r?.preserveRawString && o !== void 0 && (f !== null || !/[\r\n]/.test(o))) return o + t;
2363
- if (r?.preserveTextString && s !== void 0 && (f !== null || !/[\r\n]/.test(s))) return s + t;
2364
- if (f === null) return h(e) + t;
2365
- let g = r?.preserveRawString ? c : void 0, _ = g?.some((e) => e !== void 0) ?? !1, { cdn: v, newline: y } = tn(r), b = r?.preserveConcatenation && a !== void 0 && (a.length > 1 || _) ? a : void 0;
2366
- if (!v && !y && b === void 0) return h(e) + t;
2367
- let ee = v ? an(e, !!r?.inlineLeafContainers, y) : null;
2368
- if (b !== void 0 && (ee === null || _)) {
2369
- let e = n(r) ? p(d, l, u(r)) : void 0, a = [];
2370
- for (let [t, n] of b.entries()) {
2371
- let r = g?.[t];
2372
- if (r !== void 0) a.push({
2373
- text: n,
2374
- contentDepth: 0,
2375
- source: r
2376
- });
2377
- else if (y) {
2378
- let e = /* @__PURE__ */ new Map();
2379
- for (let { point: t, contentDepth: r } of rn(n, 0)) e.set(t, r);
2380
- m(a, mn(n, e));
2381
- } else a.push({
2382
- text: n,
2383
- contentDepth: 0
2384
- });
2385
- let i = e?.[t];
2386
- i && i.length > 0 && (a[a.length - 1].commentsAfter = i);
2387
- }
2388
- if (r?.modernConcat && r?.appPrefix !== !1) {
2389
- let e = a.map(({ text: e, source: t }) => t ?? h(e)), n = a.map((e) => e.commentsAfter ?? []);
2390
- return ie("t1", e, t, f, i, n);
2391
- }
2392
- return en(a, t, f, i);
2393
- }
2394
- let x = /* @__PURE__ */ new Map();
2395
- if (ee !== null) for (let { point: e, contentDepth: t } of ee) x.set(e, t);
2396
- if (y) {
2397
- let t = ee === null ? rn(e, 0) : on(e);
2398
- for (let { point: e, contentDepth: n } of t) x.has(e) || x.set(e, n);
2399
- }
2400
- let S = mn(e, x);
2401
- return S.length <= 1 ? h(e) + t : en(S, t, f, i);
2402
- }
2403
- function en(e, t, n, r) {
2404
- let i = e.map(({ text: n, source: r }, i) => {
2405
- let a = r ?? h(n);
2406
- return i === e.length - 1 ? a + t : a;
2407
- }), a = i[0];
2408
- for (let t = 1; t < i.length; t++) {
2409
- let o = te(n, r + 1 + e[t].contentDepth);
2410
- a += " +\n";
2411
- for (let n of e[t - 1].commentsAfter ?? []) a += `${o}${n}\n`;
2412
- a += `${o}${i[t]}`;
2413
- }
2414
- return a;
2415
- }
2416
- function tn(e) {
2417
- let t = e?.splitCdn === void 0 || e?.splitNewline === void 0 ? nn(e?.textStringFormat ?? []) : [];
2418
- return {
2419
- cdn: e?.splitCdn ?? t.includes("cdn"),
2420
- newline: e?.splitNewline ?? t.includes("newline")
2421
- };
2422
- }
2423
- function nn(e) {
2424
- return e.map((e) => e === "cboredn" ? (Qt || (Qt = !0, console.warn("`textStringFormat: ['cboredn']` is deprecated; use `textStringFormat: ['cdn']` instead.")), "cdn") : e);
2425
- }
2426
- function rn(e, t) {
2427
- let n = [];
2428
- for (let r = 0; r < e.length; r++) {
2429
- let i = e[r];
2430
- i === "\r" ? e[r + 1] === "\n" ? (n.push({
2431
- point: r + 2,
2432
- contentDepth: t
2433
- }), r++) : n.push({
2434
- point: r + 1,
2435
- contentDepth: t
2436
- }) : i === "\n" && n.push({
2437
- point: r + 1,
2438
- contentDepth: t
2439
- });
2440
- }
2441
- return n;
2442
- }
2443
- function an(t, n, r) {
2444
- try {
2445
- Ot(t);
2446
- } catch {
2447
- return null;
2448
- }
2449
- let a = [], o = new e(t), s = 0, c = null, l = !1, u = 0, d = null, f = [], p = (e, t) => {
2450
- let n = f[f.length - 1];
2451
- n ? n.ownCandidates.push({
2452
- point: e,
2453
- contentDepth: t
2454
- }) : a.push({
2455
- point: e,
2456
- contentDepth: t
2457
- });
2458
- }, m = (e) => e.kind === "LT_LT" || e.kind === "APP_SEQUENCE", h = () => {
2459
- for (let e = f.length - 1; e >= 0; e--) {
2460
- let t = f[e];
2461
- if (!(t.kind === "LPAREN" && t.isTagParen)) return t;
2462
- }
2463
- }, g = (e) => {
2464
- let t = (m(e) || !e.entryHasContainer) && !e.entryForcedBreak;
2465
- e.allOk = e.allOk && t, e.anyForcedBreak = e.anyForcedBreak || e.entryForcedBreak, e.anyForcedBreakStructural = e.anyForcedBreakStructural || e.entryForcedBreakStructural, e.entryHasContainer = !1, e.entryForcedBreak = !1, e.entryForcedBreakStructural = !1;
2466
- }, _ = "none", y = [], b = !1, x = !1, S = !1, C = !1, w = [], T = !1, te = (e) => {
2467
- w.push({
2468
- depth: e,
2469
- kind: _,
2470
- texts: y,
2471
- broken: b,
2472
- hasEllipsis: x,
2473
- sawPlus: S,
2474
- awaitingTagCheck: C
2475
- }), _ = "none", y = [], b = !1, x = !1, S = !1, C = !1, T = !0;
2476
- }, E = () => {
2477
- let e = w[w.length - 1];
2478
- e !== void 0 && s === e.depth && (w.pop(), _ = e.kind, y = e.texts, b = e.broken, x = e.hasEllipsis, S = e.sawPlus, C = e.awaitingTagCheck);
2479
- }, ne = () => {
2480
- if (x && S) for (let e of f) e.entryHasContainer = !0;
2481
- if (_ === "text" && !b && y.length > 0 && v(y.join(""))) {
2482
- let e = f[f.length - 1];
2483
- e && (e.entryForcedBreak = !0);
2484
- }
2485
- _ = "none", y = [], b = !1, x = !1, S = !1, C = !1;
2486
- };
2487
- for (;;) {
2488
- let e = o.consume();
2489
- if (e.type === "EOF") {
2490
- ne();
2491
- break;
2492
- }
2493
- let v = !1, w = !1;
2494
- if (C && (e.type === "ENCODING_INDICATOR" ? w = !0 : e.type === "LPAREN" ? (C = !1, te(s), w = !0) : C = !1), !w) {
2495
- let t = e.type === "PLUS" || e.type === "ENCODING_INDICATOR" || d === "PLUS" && (dn.has(e.type) || e.type === "ELLIPSIS");
2496
- _ !== "none" && !t && (d === "PLUS" && x ? ln.has(e.type) ? te(s) : e.type === "INTEGER" && (C = !0) : ne()), e.type === "PLUS" && _ !== "none" && (S = !0);
2497
- }
2498
- if (l || (l = !0, e.offset > 0 && fn(o.comments, 0, e.offset) && p(e.offset, s)), c !== null) {
2499
- if (c.kind === "opener" && cn.has(e.type)) {
2500
- c.point = e.endOffset, d = e.type, u = e.endOffset;
2501
- continue;
2502
- }
2503
- c.kind === "opener" && un.has(e.type) && pn(t, c.point, e.offset) ? v = !0 : p(e.offset, c.contentDepth), c = null;
2504
- }
2505
- if (ln.has(e.type)) {
2506
- if (e.type === "LBRACKET" || e.type === "LBRACE") for (let e of f) e.entryHasContainer = !0;
2507
- s++, c = {
2508
- point: e.endOffset,
2509
- contentDepth: s,
2510
- kind: "opener"
2511
- }, f.push({
2512
- kind: e.type,
2513
- isTagParen: e.type === "LPAREN" && d === "INTEGER",
2514
- isChainContinuationRoot: T,
2515
- openOffset: e.offset,
2516
- ownCandidates: [],
2517
- childCandidates: [],
2518
- entryHasContainer: !1,
2519
- entryForcedBreak: !1,
2520
- anyForcedBreak: !1,
2521
- entryForcedBreakStructural: !1,
2522
- anyForcedBreakStructural: !1,
2523
- allOk: !0
2524
- }), T = !1;
2525
- } else if (un.has(e.type)) {
2526
- s = Math.max(0, s - 1), E(), v || p(e.offset, s);
2527
- let t = f.pop();
2528
- if (t) {
2529
- g(t);
2530
- let r = t.kind === "LPAREN" && t.isTagParen, i = (m(t) || n && (t.kind === "LBRACKET" || t.kind === "LBRACE" || t.kind === "LPAREN")) && t.ownCandidates.length > 0 && (r || t.allOk) && !fn(o.comments, t.openOffset, e.endOffset) ? t.childCandidates : [...t.ownCandidates, ...t.childCandidates], s = f[f.length - 1];
2531
- if (s) {
2532
- for (let e of i) s.childCandidates.push(e);
2533
- let e = i.length > 0 || t.anyForcedBreakStructural;
2534
- (t.isChainContinuationRoot && t.isTagParen ? e : i.length > 0 || t.anyForcedBreak) && (s.entryForcedBreak = !0), e && (s.entryForcedBreakStructural = !0);
2535
- } else for (let e of i) a.push(e);
2536
- }
2537
- } else if (e.type === "COMMA") {
2538
- let t = f[f.length - 1];
2539
- t && g(t), c = {
2540
- point: e.endOffset,
2541
- contentDepth: s,
2542
- kind: "comma"
2543
- };
2544
- } else if (e.type === "TSTR" || e.type === "RAWSTRING") {
2545
- let n = t.slice(e.offset, e.endOffset);
2546
- if (r && (e.type === "TSTR" ? sn(n).length > 0 : rn(n, 0).length > 0)) {
2547
- let e = f[f.length - 1];
2548
- e && (e.entryForcedBreak = !0, e.entryForcedBreakStructural = !0);
2549
- }
2550
- d === "PLUS" && _ === "text" ? y.push(e.value) : (_ = "text", y = [e.value], b = !1);
2551
- } else if (e.type === "SQSTR") {
2552
- if (d !== "PLUS" || _ !== "byte") {
2553
- let t = e._sqstrBytes, n = t ? Zt.decode(t) : null;
2554
- d === "PLUS" && _ === "text" ? n === null ? b = !0 : y.push(n) : (_ = "text", y = n === null ? [] : [n], b = n === null);
2555
- }
2556
- } else if (e.type === "BYTES_HEX" || e.type === "BYTES_HEX_ELIDED" || e.type === "BYTES_B64" || e.type === "APP_STRING") {
2557
- if (d === "PLUS" && _ === "text") {
2558
- let t = null;
2559
- try {
2560
- e.type === "BYTES_HEX" ? t = Zt.decode(i(e.value)) : e.type === "BYTES_B64" && (t = Zt.decode(ee(e.value)));
2561
- } catch {
2562
- t = null;
2563
- }
2564
- t === null ? b = !0 : y.push(t);
2565
- } else {
2566
- let e = f[f.length - 1], t = h();
2567
- e && (!t || !m(t)) && (e.entryForcedBreak = !0), (d !== "PLUS" || _ === "none") && (_ = "byte");
2568
- }
2569
- } else e.type === "ELLIPSIS" && (x = !0, d === "PLUS" && _ === "text" ? b = !0 : (d !== "PLUS" || _ === "none") && (_ = "text", y = [], b = !0));
2570
- d = e.type, u = e.endOffset;
2571
- }
2572
- let D = o.comments.find((e) => e.start >= u);
2573
- return D !== void 0 && a.push({
2574
- point: D.start,
2575
- contentDepth: s
2576
- }), a;
2577
- }
2578
- function on(t) {
2579
- let n = [], r = new e(t), i = 0;
2580
- for (;;) {
2581
- let e = r.consume();
2582
- if (e.type === "EOF") break;
2583
- if (ln.has(e.type)) i++;
2584
- else if (un.has(e.type)) i = Math.max(0, i - 1);
2585
- else if (e.type !== "COMMA") {
2586
- if (e.type === "TSTR") {
2587
- let r = t.slice(e.offset, e.endOffset);
2588
- for (let t of sn(r)) n.push({
2589
- point: e.offset + t,
2590
- contentDepth: i + 1
2591
- });
2592
- } else if (e.type === "RAWSTRING") {
2593
- let r = t.slice(e.offset, e.endOffset);
2594
- for (let { point: t } of rn(r, 0)) n.push({
2595
- point: e.offset + t,
2596
- contentDepth: i + 1
2597
- });
2598
- }
2599
- }
2600
- }
2601
- return n;
2602
- }
2603
- function sn(e) {
2604
- let t = [], n = 1, r = e.length - 1;
2605
- for (; n < r;) {
2606
- let r = e[n];
2607
- if (r === "\\") {
2608
- let r = e[n + 1];
2609
- if (r === "n" || r === "r") t.push(n + 2), n += 2;
2610
- else if (r === "u") {
2611
- if (e[n + 2] === "{") {
2612
- let t = e.indexOf("}", n + 3);
2613
- n = t >= 0 ? t + 1 : n + 2;
2614
- } else n += 6;
2615
- } else n += 2;
2616
- } else r === "\r" ? e[n + 1] === "\n" ? (t.push(n + 2), n += 2) : (t.push(n + 1), n++) : (r === "\n" && t.push(n + 1), n++);
2617
- }
2618
- return t;
2619
- }
2620
- var cn = /* @__PURE__ */ new Set(["ENCODING_INDICATOR", "UNDERSCORE"]), ln = /* @__PURE__ */ new Set([
2621
- "LBRACKET",
2622
- "LBRACE",
2623
- "LPAREN",
2624
- "LT_LT",
2625
- "APP_SEQUENCE"
2626
- ]), un = /* @__PURE__ */ new Set([
2627
- "RBRACKET",
2628
- "RBRACE",
2629
- "RPAREN",
2630
- "GT_GT"
2631
- ]), dn = /* @__PURE__ */ new Set([
2632
- "TSTR",
2633
- "RAWSTRING",
2634
- "SQSTR",
2635
- "BYTES_HEX",
2636
- "BYTES_HEX_ELIDED",
2637
- "BYTES_B64"
2638
- ]);
2639
- function fn(e, t, n) {
2640
- return e.some((e) => e.start >= t && e.end <= n);
2641
- }
2642
- function pn(e, t, n) {
2643
- return /^[\t\n\r ]*$/.test(e.slice(t, n));
2644
- }
2645
- function mn(e, t) {
2646
- let n = [...t].filter(([t]) => t > 0 && t < e.length).sort(([e], [t]) => e - t);
2647
- if (n.length === 0) return [{
2648
- text: e,
2649
- contentDepth: 0
2650
- }];
2651
- let r = [], i = 0, a = 0;
2652
- for (let [t, o] of n) t !== i && (r.push({
2653
- text: e.slice(i, t),
2654
- contentDepth: a
2655
- }), i = t, a = o);
2656
- return i < e.length && r.push({
2657
- text: e.slice(i),
2658
- contentDepth: a
2659
- }), r;
2660
- }
2661
- //#endregion
2662
- //#region src/extensions/dt.ts
2663
- function hn(e) {
2664
- if (Number.isInteger(e)) return (/* @__PURE__ */ new Date(e * 1e3)).toISOString().replace(/\.000Z$/, "Z");
2665
- let t = Math.round(e * 1e3);
2666
- if (t / 1e3 === e) return new Date(t).toISOString().replace(/\.000Z$/, "Z");
2667
- let n = Math.floor(e), r = e - n, i = (/* @__PURE__ */ new Date(n * 1e3)).toISOString().replace(/\.\d+Z$/, ""), a = r.toString(), o = a.indexOf("."), s = o >= 0 ? a.slice(o + 1) : "0";
2668
- for (; s.length < 3;) s += "0";
2669
- return `${i}.${s}Z`;
2670
- }
2671
- var gn = new TextDecoder("utf-8", { fatal: !0 });
2672
- function _n(e) {
2673
- if (e.length !== 1) throw SyntaxError("dt<<...>>: expected exactly one item");
2674
- let t = e[0];
2675
- if (t instanceof Y) return t.value;
2676
- if (t instanceof B) return gn.decode(t.value);
2677
- throw SyntaxError("dt<<...>>: expected a text string or byte string");
2678
- }
2679
- var vn = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/i;
2680
- function yn(e, t) {
2681
- if (!vn.test(e)) {
2682
- let n = `dt: invalid RFC 3339 date-time: ${JSON.stringify(e)}`;
2683
- if (t) t(n);
2684
- else throw SyntaxError(n);
2685
- }
2686
- let n = e.match(/^(.+T\d{2}:\d{2}:\d{2})(\.\d+)(Z|[+-]\d{2}:\d{2})$/i), r, i;
2687
- n ? (r = n[1] + n[3], i = parseFloat("0" + n[2])) : (r = e, i = void 0);
2688
- let a = Date.parse(r);
2689
- if (isNaN(a)) throw SyntaxError(`dt: invalid RFC 3339 date-time: ${JSON.stringify(e)}`);
2690
- if (i === void 0) {
2691
- let e = a / 1e3;
2692
- return e >= 0 ? new xn(BigInt(e)) : new Sn(BigInt(e));
2693
- }
2694
- return new Cn(a / 1e3 + i);
2695
- }
2696
- var bn = 1n, xn = class extends I {
2697
- constructor(e, t) {
2698
- super(e, t);
2699
- }
2700
- _toCDN(e, n, r) {
2701
- if (e?.appPrefix === !1) return super._toCDN(e, n, r);
2702
- let i = t(e, this.encodingWidth, () => E(this.value));
2703
- return T(e, this.appSeqSource, void 0, this.appSeqSourceFeatures) === "adjusted" ? D(this.appSeqSource, i, e, this.appSeqInnerEnd, this.appSeqComments) : `dt'${hn(Number(this.value))}'${i}`;
2704
- }
2705
- }, Sn = class extends L {
2706
- constructor(e, t) {
2707
- super(e, t);
2708
- }
2709
- _toCDN(e, n, r) {
2710
- if (e?.appPrefix === !1) return super._toCDN(e, n, r);
2711
- let i = t(e, this.encodingWidth, () => E(this.argument));
2712
- return T(e, this.appSeqSource, void 0, this.appSeqSourceFeatures) === "adjusted" ? D(this.appSeqSource, i, e, this.appSeqInnerEnd, this.appSeqComments) : `dt'${hn(Number(this.value))}'${i}`;
2713
- }
2714
- }, Cn = class extends R {
2715
- constructor(e, t) {
2716
- super(e, t);
2717
- }
2718
- _toCDN(e, t, n) {
2719
- if (e?.appPrefix === !1) return super._toCDN(e, t, n);
2720
- let r = P(this.value), i = S(this.value, this.precision, r, e?.encodingIndicators ?? "auto");
2721
- return T(e, this.appSeqSource, void 0, this.appSeqSourceFeatures) === "adjusted" ? D(this.appSeqSource, i, e, this.appSeqInnerEnd, this.appSeqComments) : `dt'${hn(this.value)}'${i}`;
2722
- }
2723
- }, wn = class extends z {
2724
- constructor(e, t) {
2725
- super(bn, typeof e == "string" ? yn(e) : e, t);
2726
- }
2727
- _toCDN(e, n, r) {
2728
- if (e?.appPrefix === !1) return super._toCDN(e, n, r);
2729
- let i = T(e, this.appSeqSource, this.ednSource, this.appSeqSourceFeatures, this.appSeqEncodingEditsComplete);
2730
- if (i === "verbatim") return this.appSeqSource;
2731
- if (i === "source") return w(this.appSeqSource, e, this.appSeqComments, this.appSeqEncodingEdits);
2732
- if (i === "structural") return super._toCDN({
2733
- ...e,
2734
- appPrefix: !1
2735
- }, n, r);
2736
- let a = t(e, this.encodingWidth, () => E(bn));
2737
- if (i === "adjusted") return D(this.appSeqSource, a, e, this.appSeqInnerEnd, this.appSeqComments);
2738
- let o = this.content;
2739
- return (o instanceof R ? o.precision !== void 0 && o.precision !== P(o.value) : o.encodingWidth !== void 0) ? super._toCDN({
2740
- ...e,
2741
- appPrefix: !1
2742
- }, n, r) : `DT'${hn(o instanceof R ? o.value : Number(o.value))}'${a}`;
2743
- }
2744
- }, Tn = class extends wn {
2745
- constructor(e, t) {
2746
- super(e, t);
2747
- }
2748
- _toJS(e) {
2749
- let t = this.content, n = t instanceof R ? t.value * 1e3 : Number(t.value) * 1e3;
2750
- return new Date(n);
2751
- }
2752
- };
2753
- function En(e) {
2754
- return (t, n) => {
2755
- if (!(t instanceof wn)) return;
2756
- let r = t.content;
2757
- if (e) {
2758
- let e = r instanceof R ? r.value * 1e3 : Number(r.value) * 1e3;
2759
- return { value: new Date(e) };
2760
- }
2761
- let i = r._toJS(n);
2762
- return { value: n.stripTags ? i : k.set(i, t.tag) };
2763
- };
2764
- }
2765
- function Dn(e) {
2766
- let t = e?.jsDate ?? !1;
2767
- function n(e) {
2768
- return t ? new Tn(e) : new wn(e);
2769
- }
2770
- let r = {
2771
- appStringPrefixes: ["dt", "DT"],
2772
- tagNumbers: [bn],
2773
- preserveAppSeqSource: "optional",
2774
- toJS: En(t),
2775
- parseAppString(e, t, r) {
2776
- return e === "DT" ? n(t) : yn(t, r);
2777
- },
2778
- parseAppSequence(e, t, r) {
2779
- let i = _n(t);
2780
- return e === "DT" ? n(i) : yn(i, r);
2781
- },
2782
- parseTag(e, n) {
2783
- if (e !== 1n) return;
2784
- let r;
2785
- if (n instanceof I) r = new xn(n.value, {
2786
- encodingWidth: n.encodingWidth,
2787
- ednSource: n.ednSource
2788
- });
2789
- else if (n instanceof L) r = new Sn(n.value, {
2790
- encodingWidth: n.encodingWidth,
2791
- ednSource: n.ednSource
2792
- });
2793
- else if (n instanceof R) r = new Cn(n.value, {
2794
- precision: n.precision,
2795
- literalSource: n.literalSource
2796
- });
2797
- else return;
2798
- return r.start = n.start, r.end = n.end, t ? new Tn(r) : new wn(r);
2799
- }
2800
- };
2801
- return t && (r.fromJS = (e, t) => {
2802
- if (e instanceof Date) return new Tn(hn(e.getTime() / 1e3));
2803
- }, r.isJSType = (e) => e instanceof Date), r;
2804
- }
2805
- var On = Dn(), kn = Dn({ jsDate: !0 });
2806
- //#endregion
2807
- //#region src/utils/ip.ts
2808
- function An(e) {
2809
- let t = e.split(".");
2810
- if (t.length !== 4) throw SyntaxError(`ip: invalid IPv4 address: ${JSON.stringify(e)}`);
2811
- let n = /* @__PURE__ */ new Uint8Array(4);
2812
- for (let e = 0; e < 4; e++) {
2813
- let r = t[e];
2814
- if (!/^\d+$/.test(r) || r.length > 1 && r[0] === "0") throw SyntaxError(`ip: invalid IPv4 octet: ${JSON.stringify(r)}`);
2815
- let i = parseInt(r, 10);
2816
- if (i > 255) throw SyntaxError(`ip: IPv4 octet out of range: ${i}`);
2817
- n[e] = i;
2818
- }
2819
- return n;
2820
- }
2821
- function jn(e) {
2822
- let t = /* @__PURE__ */ new Uint8Array(16);
2823
- if (e === "::") return t;
2824
- let n = e, r = null, i = e.match(/^(.*):(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/);
2825
- i && (n = i[1], n.endsWith(":") && (n += ":"), r = An(i[2]));
2826
- let a = n.split("::");
2827
- if (a.length > 2) throw SyntaxError(`ip: invalid IPv6 address: ${JSON.stringify(e)}`);
2828
- let o = a.length === 2, s = a[0] ? a[0].split(":") : [], c = o && a[1] ? a[1].split(":") : [], l = r ? 6 : 8;
2829
- if (!o && s.length !== l || o && s.length + c.length >= l) throw SyntaxError(`ip: invalid IPv6 address: ${JSON.stringify(e)}`);
2830
- let u = l - s.length - c.length, d = [
2831
- ...s,
2832
- ...Array(u).fill("0"),
2833
- ...c
2834
- ], f = 0;
2835
- for (let e of d) {
2836
- if (!/^[0-9a-fA-F]{1,4}$/.test(e)) throw SyntaxError(`ip: invalid IPv6 group: ${JSON.stringify(e)}`);
2837
- let n = parseInt(e, 16);
2838
- t[f++] = n >> 8 & 255, t[f++] = n & 255;
2839
- }
2840
- return r && t.set(r, 12), t;
2841
- }
2842
- function Mn(e) {
2843
- return Array.from(e).join(".");
2844
- }
2845
- function Nn(e) {
2846
- let t = e.slice(0, 10).every((e) => e === 0) && e[10] === 255 && e[11] === 255 ? Mn(e.slice(12)) : null, n = t ? 6 : 8, r = [];
2847
- for (let t = 0; t < n * 2; t += 2) r.push(e[t] << 8 | e[t + 1]);
2848
- let i = -1, a = 0, o = 0;
2849
- for (; o < n;) if (r[o] === 0) {
2850
- let e = o + 1;
2851
- for (; e < n && r[e] === 0;) e++;
2852
- e - o > a && (i = o, a = e - o), o = e;
2853
- } else o++;
2854
- a < 2 && (i = -1);
2855
- let s = (e) => e.toString(16), c;
2856
- return c = i === -1 ? r.map(s).join(":") : `${r.slice(0, i).map(s).join(":")}::${r.slice(i + a).map(s).join(":")}`, t ? `${c}:${t}` : c;
2857
- }
2858
- //#endregion
2859
- //#region src/extensions/ip.ts
2860
- var Pn = "ip", Fn = "IP", In = 52n, Ln = 54n, Rn = new TextDecoder("utf-8", { fatal: !0 });
2861
- function zn(e) {
2862
- if (e.length !== 1) throw SyntaxError("ip<<...>>: expected exactly one item");
2863
- let t = e[0];
2864
- if (t instanceof Y) return t.value;
2865
- if (t instanceof B) return Rn.decode(t.value);
2866
- throw SyntaxError("ip<<...>>: expected a text string or byte string");
2867
- }
2868
- function Bn(e) {
2869
- return /^\d/.test(e) && e.includes(".") && !e.includes(":") ? {
2870
- bytes: An(e),
2871
- isV4: !0
2872
- } : {
2873
- bytes: jn(e),
2874
- isV4: !1
2875
- };
2876
- }
2877
- function Vn(e) {
2878
- if (e.length === 4) return Mn(e);
2879
- if (e.length === 16) return Nn(e);
2880
- throw SyntaxError(`ip: unexpected byte length: ${e.length}`);
2881
- }
2882
- function Hn(e, t) {
2883
- let n = new Uint8Array(e.length);
2884
- n.set(e);
2885
- let r = Math.floor(t / 8), i = t % 8;
2886
- i > 0 && r < e.length && (n[r] &= 255 << 8 - i & 255);
2887
- for (let t = r + +(i > 0); t < e.length; t++) n[t] = 0;
2888
- let a = Math.ceil(t / 8);
2889
- for (; a > 0 && n[a - 1] === 0;) a--;
2890
- return n.slice(0, a);
2891
- }
2892
- function Un(e, t) {
2893
- let n = new Uint8Array(t);
2894
- return n.set(e), n;
2895
- }
2896
- var Wn = class extends B {
2897
- _toCDN(e, n, r) {
2898
- if (e?.appPrefix === !1) return super._toCDN(e, n, r);
2899
- let i = t(e, this.encodingWidth, () => E(BigInt(this.value.length)));
2900
- return T(e, this.appSeqSource, void 0, this.appSeqSourceFeatures) === "adjusted" ? D(this.appSeqSource, i, e, this.appSeqInnerEnd, this.appSeqComments) : `${Pn}'${Vn(this.value)}'${i}`;
2901
- }
2902
- }, Gn = class extends U {
2903
- _isV4;
2904
- constructor(e, t, n) {
2905
- super([new I(BigInt(e)), new B(t)]), this._isV4 = n;
2906
- }
2907
- _toCDN(e, t, n) {
2908
- if (e?.appPrefix === !1) return super._toCDN(e, t, n);
2909
- if (T(e, this.appSeqSource, void 0, this.appSeqSourceFeatures) === "adjusted") return D(this.appSeqSource, "", e, this.appSeqInnerEnd, this.appSeqComments);
2910
- let r = Number(this.items[0].value), i = this.items[1].value;
2911
- return `${Pn}'${Vn(Un(i, this._isV4 ? 4 : 16))}/${r}'`;
2912
- }
2913
- }, Kn = class extends z {
2914
- constructor(e, t) {
2915
- super(e, t);
2916
- }
2917
- _toCDN(e, n, r) {
2918
- if (e?.appPrefix === !1) return super._toCDN(e, n, r);
2919
- let i = T(e, this.appSeqSource, this.ednSource, this.appSeqSourceFeatures, this.appSeqEncodingEditsComplete);
2920
- if (i === "verbatim") return this.appSeqSource;
2921
- if (i === "source") return w(this.appSeqSource, e, this.appSeqComments, this.appSeqEncodingEdits);
2922
- if (i === "structural") return super._toCDN(e, n, r);
2923
- if (i === "adjusted") {
2924
- let n = t(e, this.encodingWidth, () => E(this.tag));
2925
- return D(this.appSeqSource, n, e, this.appSeqInnerEnd, this.appSeqComments);
2926
- }
2927
- let a = this.tag === In ? 4 : 16, o = this.content;
2928
- if (o instanceof B) {
2929
- if (o.encodingWidth !== void 0) return super._toCDN(e, n, r);
2930
- let i = t(e, this.encodingWidth, () => E(this.tag));
2931
- return `${Fn}'${Vn(o.value)}'${i}`;
2932
- }
2933
- if (o instanceof U && o.items.length === 2 && o.items[0] instanceof I && o.items[1] instanceof B) {
2934
- if (o.encodingWidth !== void 0 || o.items[0].encodingWidth !== void 0 || o.items[1].encodingWidth !== void 0) return super._toCDN(e, n, r);
2935
- let i = Number(o.items[0].value), s = Un(o.items[1].value, a), c = t(e, this.encodingWidth, () => E(this.tag));
2936
- return `${Fn}'${Vn(s)}/${i}'${c}`;
2937
- }
2938
- return super._toCDN(e, n, r);
2939
- }
2940
- };
2941
- function qn(e, t) {
2942
- let n = t.indexOf("/");
2943
- if (n === -1) {
2944
- let { bytes: n, isV4: r } = Bn(t);
2945
- return e === Fn ? new Kn(r ? In : Ln, new B(n)) : new Wn(n);
2946
- }
2947
- let r = t.slice(0, n), i = t.slice(n + 1);
2948
- if (!/^\d+$/.test(i)) throw SyntaxError(`ip: invalid prefix length: ${JSON.stringify(i)}`);
2949
- let a = parseInt(i, 10), { bytes: o, isV4: s } = Bn(r), c = s ? 32 : 128;
2950
- if (a > c) throw SyntaxError(`ip: prefix length ${a} exceeds maximum ${c} for ${s ? "IPv4" : "IPv6"}`);
2951
- let l = Hn(o, a);
2952
- return e === Fn ? new Kn(s ? In : Ln, new U([new I(BigInt(a)), new B(l)])) : new Gn(a, l, s);
2953
- }
2954
- var Jn = {
2955
- appStringPrefixes: [Pn, Fn],
2956
- tagNumbers: [In, Ln],
2957
- preserveAppSeqSource: "optional",
2958
- parseAppString(e, t) {
2959
- return qn(e, t);
2960
- },
2961
- parseAppSequence(e, t) {
2962
- return qn(e, zn(t));
2963
- },
2964
- parseTag(e, t) {
2965
- if ((e === In || e === Ln) && (t instanceof B || t instanceof U)) return new Kn(e, t);
2966
- }
2967
- }, Yn = "cri", Xn = "CRI", Zn = 99n, Qn = /* @__PURE__ */ new Map([
2968
- ["coap", -1n],
2969
- ["coaps", -2n],
2970
- ["http", -3n],
2971
- ["https", -4n],
2972
- ["urn", -5n],
2973
- ["did", -6n],
2974
- ["coap+tcp", -7n],
2975
- ["coaps+tcp", -8n],
2976
- ["coap+ws", -25n],
2977
- ["coaps+ws", -26n]
2978
- ]), $n = new Map([...Qn.entries()].map(([e, t]) => [t, e]));
2979
- function X(e) {
2980
- try {
2981
- return decodeURIComponent(e);
2982
- } catch {
2983
- return e;
2984
- }
2985
- }
2986
- var er = new TextEncoder(), tr = new TextDecoder("utf-8", { fatal: !0 });
2987
- function nr(e) {
2988
- return Array.from(er.encode(e), (e) => `%${e.toString(16).toUpperCase().padStart(2, "0")}`).join("");
2989
- }
2990
- function rr(e, t) {
2991
- let n = "";
2992
- for (let r of e) n += t(r) ? r : nr(r);
2993
- return n;
2994
- }
2995
- function ir(e) {
2996
- return /[A-Za-z0-9\-._~]/.test(e);
2997
- }
2998
- function ar(e) {
2999
- return /[!$&'()*+,;=]/.test(e);
3000
- }
3001
- function or(e) {
3002
- return ir(e) || ar(e) || e === ":" || e === "@";
3003
- }
3004
- function sr(e) {
3005
- return (or(e) || e === "/" || e === "?") && e !== "&";
3006
- }
3007
- function cr(e) {
3008
- return or(e) || e === "/" || e === "?";
3009
- }
3010
- function lr(e) {
3011
- return ir(e) || ar(e) || e === ":";
3012
- }
3013
- function ur(e) {
3014
- return ir(e) || ar(e);
3015
- }
3016
- function dr(e) {
3017
- let t = [], n = e, r = n.indexOf("@");
3018
- r >= 0 && (t.push(G.FALSE), t.push(new Y(X(n.slice(0, r)))), n = n.slice(r + 1));
3019
- let i, a = null;
3020
- if (n.startsWith("[")) {
3021
- let e = n.indexOf("]");
3022
- if (e < 0) throw SyntaxError("cri: unterminated IPv6 bracket in authority");
3023
- i = n.slice(1, e);
3024
- let r = n.slice(e + 1);
3025
- if (r.startsWith(":")) a = r.slice(1);
3026
- else if (r.length > 0) throw SyntaxError("cri: unexpected characters after ']' in authority");
3027
- t.push(new B(jn(i)));
3028
- } else {
3029
- let e = n.lastIndexOf(":");
3030
- if (e >= 0 ? (i = n.slice(0, e), a = n.slice(e + 1)) : i = n, i !== "") {
3031
- if (/^\d{1,3}(\.\d{1,3}){3}$/.test(i)) t.push(new B(An(i)));
3032
- else for (let e of i.toLowerCase().split(".")) t.push(new Y(e));
3033
- }
3034
- }
3035
- if (a !== null && a !== "") {
3036
- if (!/^\d+$/.test(a)) throw SyntaxError(`cri: invalid port: ${JSON.stringify(a)}`);
3037
- let e = parseInt(a, 10);
3038
- if (e > 65535) throw SyntaxError(`cri: port ${e} out of range`);
3039
- t.push(new I(BigInt(e)));
3040
- }
3041
- return new U(t);
3042
- }
3043
- function fr(e) {
3044
- let t = e.items, n = 0, r = "";
3045
- if (n < t.length && t[n] instanceof G && t[n].value === 20) {
3046
- n++;
3047
- let e = t[n++];
3048
- r += rr(e.value, lr) + "@";
3049
- }
3050
- if (n >= t.length) return r;
3051
- let i = t[n];
3052
- if (i instanceof B) {
3053
- n++;
3054
- let { length: e } = i.value;
3055
- if (e === 4) r += Mn(i.value);
3056
- else if (e === 16) r += "[" + Nn(i.value) + "]";
3057
- else throw Error(`cri: unexpected host-ip byte length: ${e}`);
3058
- n < t.length && t[n] instanceof Y && (r += `%25${rr(t[n++].value, ur)}`);
3059
- } else {
3060
- let e = [];
3061
- for (; n < t.length && t[n] instanceof Y;) e.push(rr(t[n++].value, ur));
3062
- r += e.join(".");
3063
- }
3064
- return n < t.length && t[n] instanceof I && (r += ":" + t[n].value.toString()), r;
3065
- }
3066
- function pr(e) {
3067
- let t = e.slice(2), n = t.indexOf("/"), r, i;
3068
- return n >= 0 ? (r = t.slice(0, n), i = t.slice(n + 1).split("/").map((e) => new Y(X(e)))) : (r = t, i = []), {
3069
- authority: dr(r),
3070
- pathSegments: i
3071
- };
3072
- }
3073
- function mr(e) {
3074
- let t = e, n = null, r = t.indexOf("#");
3075
- r >= 0 && (n = X(t.slice(r + 1)), t = t.slice(0, r));
3076
- let i = null, a = t.indexOf("?");
3077
- if (a >= 0) {
3078
- let e = t.slice(a + 1);
3079
- t = t.slice(0, a), i = e.split("&").map((e) => new Y(X(e)));
3080
- }
3081
- let o = [], s = /^([a-zA-Z][a-zA-Z0-9+.\-]*):([\s\S]*)$/.exec(t);
3082
- if (s) {
3083
- let e = s[1].toLowerCase(), t = s[2], n = Qn.get(e);
3084
- if (o.push(n === void 0 ? new Y(e) : new L(n)), t.startsWith("//")) {
3085
- let { authority: e, pathSegments: n } = pr(t);
3086
- o.push(e, new U(n));
3087
- } else if (t.startsWith("/")) {
3088
- let e = t.slice(1).split("/").map((e) => new Y(X(e)));
3089
- o.push(G.NULL, new U(e));
3090
- } else {
3091
- let e = t.split("/").map((e) => new Y(X(e)));
3092
- o.push(G.TRUE, new U(e));
3093
- }
3094
- } else if (t.startsWith("//")) {
3095
- let { authority: e, pathSegments: n } = pr(t);
3096
- o.push(G.FALSE, e, new U(n));
3097
- } else if (t.startsWith("/")) {
3098
- let e = t.slice(1).split("/").map((e) => new Y(X(e)));
3099
- o.push(G.TRUE, new U(e));
3100
- } else if (t === "") o.push(new I(0n));
3101
- else {
3102
- let n = 1n, r = t, i = !1;
3103
- for (r.startsWith("./") && (i = !0, r = r.slice(2)); r.startsWith("../");) n++, r = r.slice(3);
3104
- if (r === ".." ? (n++, r = "") : r === "." && (r = ""), n === 1n && !i && r !== "" && r.split("/")[0].includes(":")) throw SyntaxError(`cri: invalid relative-path reference — first segment must not contain ':' without a './' prefix (RFC 3986 §3.3): ${JSON.stringify(e)}`);
3105
- let a = r === "" ? [] : r.split("/").map((e) => new Y(X(e)));
3106
- o.push(new I(n), new U(a));
3107
- }
3108
- if (i !== null && o.push(new U(i)), n !== null && (i === null && o.push(G.NULL), o.push(new Y(n))), n !== null && i === null && o.splice(o.length - 2, 1), i === null && n === null) {
3109
- let e = o[o.length - 1];
3110
- e instanceof U && e.items.length === 0 && o.pop();
3111
- }
3112
- return o.length === 1 && o[0] instanceof I && o[0].value === 0n ? [] : o;
3113
- }
3114
- function hr(e, t) {
3115
- let n = t, r = "";
3116
- if (n < e.length) {
3117
- let t = e[n];
3118
- if (t instanceof U) {
3119
- if (n++, t.items.length > 0) {
3120
- let e = t.items.map((e) => {
3121
- if (!(e instanceof Y)) throw Error("cri: query item must be a text string");
3122
- return rr(e.value, sr);
3123
- });
3124
- r += "?" + e.join("&");
3125
- }
3126
- } else t instanceof G && t.value === 22 && n++;
3127
- }
3128
- return n < e.length && e[n] instanceof Y && (r += "#" + rr(e[n].value, cr)), r;
3129
- }
3130
- function gr(e) {
3131
- return e.items.map((e) => {
3132
- if (!(e instanceof Y)) throw Error("cri: path segment must be a text string");
3133
- return rr(e.value, or);
3134
- });
3135
- }
3136
- function _r(e) {
3137
- if (e.length === 0) return "";
3138
- let t = 0, n = e[t++];
3139
- if (n instanceof L || n instanceof Y) {
3140
- let r;
3141
- if (n instanceof L) {
3142
- let e = $n.get(n.value);
3143
- if (e === void 0) throw Error(`cri: unrecognised scheme-id ${n.value}`);
3144
- r = e + ":";
3145
- } else r = n.value + ":";
3146
- if (t >= e.length) return r;
3147
- let i = e[t++], a = "", o = !1;
3148
- if (i instanceof U) a = "//" + fr(i), o = !0;
3149
- else if (i instanceof G) {
3150
- if (i.value === 22) o = !0;
3151
- else if (i.value === 21) o = !1;
3152
- else throw Error(`cri: unexpected no-authority value: simple(${i.value})`);
3153
- } else throw Error("cri: unexpected type for authority element");
3154
- let s = "";
3155
- if (t < e.length && e[t] instanceof U) {
3156
- let n = e[t++];
3157
- n.items.length > 0 && (s = (o ? "/" : "") + gr(n).join("/"));
3158
- }
3159
- return r + a + s + hr(e, t);
3160
- }
3161
- if (n instanceof G && n.value === 20) {
3162
- if (t >= e.length || !(e[t] instanceof U)) throw Error("cri: network-path reference requires an authority array");
3163
- let n = fr(e[t++]), r = "";
3164
- if (t < e.length && e[t] instanceof U) {
3165
- let n = e[t++];
3166
- n.items.length > 0 && (r = "/" + gr(n).join("/"));
3167
- }
3168
- return "//" + n + r + hr(e, t);
3169
- }
3170
- if (n instanceof G && n.value === 21) {
3171
- let n = "/";
3172
- if (t < e.length && e[t] instanceof U) {
3173
- let r = e[t++];
3174
- n = "/" + gr(r).join("/");
3175
- }
3176
- return n + hr(e, t);
3177
- }
3178
- if (n instanceof I) {
3179
- let r = n.value;
3180
- if (r === 0n) return hr(e, t);
3181
- let i = r === 1n ? "" : "../".repeat(Number(r) - 1), a;
3182
- if (t < e.length && e[t] instanceof U) {
3183
- let n = e[t++];
3184
- if (n.items.length > 0) {
3185
- let e = gr(n);
3186
- a = (r === 1n && e[0].includes(":") ? "./" : i) + e.join("/");
3187
- } else a = i === "" ? "./" : i;
3188
- } else a = i === "" ? "./" : i;
3189
- return a + hr(e, t);
3190
- }
3191
- throw Error("cri: unrecognised first element type in CRI array");
3192
- }
3193
- var vr = class extends U {
3194
- _toCDN(e, n, r) {
3195
- if (e?.appPrefix === !1) return super._toCDN(e, n, r);
3196
- let i = t(e, this.encodingWidth, () => E(BigInt(this.items.length)));
3197
- if (T(e, this.appSeqSource, void 0, this.appSeqSourceFeatures) === "adjusted") return D(this.appSeqSource, i, e, this.appSeqInnerEnd, this.appSeqComments);
3198
- try {
3199
- return `${Yn}'${_r(this.items)}'${i}`;
3200
- } catch {
3201
- return super._toCDN(e, n, r);
3202
- }
3203
- }
3204
- }, yr = class extends z {
3205
- constructor(e) {
3206
- super(Zn, e);
3207
- }
3208
- _toCDN(e, n, r) {
3209
- if (e?.appPrefix === !1) return super._toCDN(e, n, r);
3210
- let i = T(e, this.appSeqSource, this.ednSource, this.appSeqSourceFeatures, this.appSeqEncodingEditsComplete);
3211
- if (i === "verbatim") return this.appSeqSource;
3212
- if (i === "source") return w(this.appSeqSource, e, this.appSeqComments, this.appSeqEncodingEdits);
3213
- if (i === "structural") return super._toCDN({
3214
- ...e,
3215
- appPrefix: !1
3216
- }, n, r);
3217
- try {
3218
- let a = this.content;
3219
- if (a.encodingWidth !== void 0) return super._toCDN(e, n, r);
3220
- let o = t(e, this.encodingWidth, () => E(Zn));
3221
- return i === "adjusted" ? D(this.appSeqSource, o, e, this.appSeqInnerEnd, this.appSeqComments) : `${Xn}'${_r(a.items)}'${o}`;
3222
- } catch {
3223
- return super._toCDN(e, n, r);
3224
- }
3225
- }
3226
- };
3227
- function br(e) {
3228
- if (e.length !== 1) throw SyntaxError("cri<<...>>: expected exactly one item");
3229
- let t = e[0];
3230
- if (t instanceof Y) return t.value;
3231
- if (t instanceof B) return tr.decode(t.value);
3232
- throw SyntaxError("cri<<...>>: expected a text string or byte string");
3233
- }
3234
- function xr(e, t) {
3235
- let n = new vr(mr(t));
3236
- return e === Xn ? new yr(n) : n;
3237
- }
3238
- var Sr = {
3239
- appStringPrefixes: [Yn, Xn],
3240
- tagNumbers: [Zn],
3241
- preserveAppSeqSource: "optional",
3242
- parseAppString(e, t) {
3243
- return xr(e, t);
3244
- },
3245
- parseAppSequence(e, t) {
3246
- return xr(e, br(t));
3247
- },
3248
- parseTag(e, t) {
3249
- if (e !== 99n || !(t instanceof U)) return;
3250
- let n = new vr(t.items, {
3251
- indefiniteLength: t.indefiniteLength,
3252
- encodingWidth: t.encodingWidth
3253
- });
3254
- return n.start = t.start, n.end = t.end, new yr(n);
3255
- }
3256
- }, Cr = 18446744073709551615n, wr = -18446744073709551616n, Tr = {
3257
- tagNumbers: [_t, vt],
3258
- parseTag(e, t) {
3259
- if (t instanceof B) {
3260
- if (e === 2n) {
3261
- let e = St(t.value);
3262
- return e > Cr ? new Ct(e) : void 0;
3263
- }
3264
- if (e === 3n) {
3265
- let e = -1n - St(t.value);
3266
- return e < wr ? new wt(e) : void 0;
3267
- }
3268
- }
3269
- }
3270
- };
3271
- //#endregion
3272
- //#region src/cbor/decoder.ts
3273
- function Er(e, t) {
3274
- if (e === 24 && t <= 23n) return 0;
3275
- if (e === 25 && t <= 255n) return 1;
3276
- if (e === 26 && t <= 65535n) return 2;
3277
- if (e === 27 && t <= 4294967295n) return 3;
3278
- }
3279
- function Dr(e, t) {
3280
- if (e === 24 && t <= 23) return 0;
3281
- if (e === 25 && t <= 255) return 1;
3282
- if (e === 26 && t <= 65535) return 2;
3283
- if (e === 27 && t <= 4294967295) return 3;
3284
- }
3285
- var Or = new TextDecoder("utf-8", {
3286
- fatal: !0,
3287
- ignoreBOM: !0
3288
- }), kr = new TextDecoder("utf-8", {
3289
- fatal: !1,
3290
- ignoreBOM: !0
3291
- });
3292
- function Z(e) {
3293
- throw Error(`CBOR decode error: ${e}`);
3294
- }
3295
- function Ar(e, t, n) {
3296
- let r = {
3297
- message: e,
3298
- offset: t
3299
- };
3300
- if (n?.onWarning ? n.onWarning(r) : n?.silent || console.warn(`CBOR strict violation at offset ${t}: ${e}`), n?.strict !== !1) throw Error(`CBOR decode error: ${e}`);
3301
- return r;
3302
- }
3303
- function jr(e, t) {
3304
- e.warnings ??= [], e.warnings.push(t);
3305
- }
3306
- function Mr(e) {
3307
- if (e instanceof I) return ["u", String(e.value)];
3308
- if (e instanceof L) return ["n", String(e.value)];
3309
- if (e instanceof Y) return ["t", e.value];
3310
- if (e instanceof H) return ["t", e.chunks.map((e) => e.value).join("")];
3311
- if (e instanceof B) return ["b", s(e.value)];
3312
- if (e instanceof V) {
3313
- let t = "";
3314
- for (let n of e.chunks) t += s(n.value);
3315
- return ["b", t];
3316
- }
3317
- if (e instanceof R) return isNaN(e.value) ? ["f", "NaN"] : Object.is(e.value, -0) ? ["f", "-0"] : ["f", String(e.value)];
3318
- if (e instanceof G) return ["s", e.value];
3319
- if (e instanceof U) return ["A", e.items.map(Mr)];
3320
- if (e instanceof W) {
3321
- let t = e.entries.map(([e, t]) => [Mr(e), Mr(t)]);
3322
- if (t.length <= 1) return ["M", t];
3323
- let n = t.map((e) => [JSON.stringify(e[0]), e]);
3324
- return n.sort((e, t) => e[0] < t[0] ? -1 : +(e[0] > t[0])), ["M", n.map((e) => e[1])];
3325
- }
3326
- return e instanceof z ? [
3327
- "G",
3328
- String(e.tag),
3329
- Mr(e.content)
3330
- ] : ["c", s(e.toCBOR())];
3331
- }
3332
- function Nr(e) {
3333
- if (e instanceof I) return "u" + e.value;
3334
- if (e instanceof L) return "n" + e.value;
3335
- if (e instanceof Y) return "t" + e.value;
3336
- if (e instanceof H) {
3337
- let t = "t";
3338
- for (let n of e.chunks) t += n.value;
3339
- return t;
3340
- }
3341
- if (e instanceof B) return "b" + s(e.value);
3342
- if (e instanceof V) {
3343
- let t = "b";
3344
- for (let n of e.chunks) t += s(n.value);
3345
- return t;
3346
- }
3347
- return e instanceof R ? isNaN(e.value) ? "fNaN" : Object.is(e.value, -0) ? "f-0" : "f" + e.value : e instanceof G ? "s" + e.value : JSON.stringify(Mr(e));
3348
- }
3349
- var Pr = Array.from({ length: 24 }, (e, t) => BigInt(t)), Fr;
3350
- function Ir(e) {
3351
- return e === void 0 ? Fr ??= Oi(void 0).filter((e) => e.parseTag !== void 0) : Oi(e).filter((e) => e.parseTag !== void 0);
3352
- }
3353
- function Lr(e, t) {
3354
- for (let n = 0; n < t; n++) if (e[n] >= 128) return;
3355
- return String.fromCharCode.apply(null, e);
3356
- }
3357
- function Rr(e, t, n) {
3358
- if (n <= 23) return {
3359
- value: Pr[n],
3360
- nextOffset: t
3361
- };
3362
- switch (n) {
3363
- case 24: return t + 1 > e.byteLength && Z("unexpected end of input"), {
3364
- value: BigInt(e.getUint8(t)),
3365
- nextOffset: t + 1
3366
- };
3367
- case 25: return t + 2 > e.byteLength && Z("unexpected end of input"), {
3368
- value: BigInt(e.getUint16(t, !1)),
3369
- nextOffset: t + 2
3370
- };
3371
- case 26: return t + 4 > e.byteLength && Z("unexpected end of input"), {
3372
- value: BigInt(e.getUint32(t, !1)),
3373
- nextOffset: t + 4
3374
- };
3375
- case 27: return t + 8 > e.byteLength && Z("unexpected end of input"), {
3376
- value: e.getBigUint64(t, !1),
3377
- nextOffset: t + 8
3378
- };
3379
- default: Z(`reserved additional info value: ${n}`);
3380
- }
3381
- }
3382
- function zr(e, t, n) {
3383
- if (n <= 23) return {
3384
- value: n,
3385
- nextOffset: t
3386
- };
3387
- switch (n) {
3388
- case 24: return t + 1 > e.byteLength && Z("unexpected end of input"), {
3389
- value: e.getUint8(t),
3390
- nextOffset: t + 1
3391
- };
3392
- case 25: return t + 2 > e.byteLength && Z("unexpected end of input"), {
3393
- value: e.getUint16(t, !1),
3394
- nextOffset: t + 2
3395
- };
3396
- case 26: return t + 4 > e.byteLength && Z("unexpected end of input"), {
3397
- value: e.getUint32(t, !1),
3398
- nextOffset: t + 4
3399
- };
3400
- case 27: {
3401
- t + 8 > e.byteLength && Z("unexpected end of input");
3402
- let n = e.getUint32(t, !1), r = e.getUint32(t + 4, !1);
3403
- return {
3404
- value: n * 4294967296 + r,
3405
- nextOffset: t + 8
3406
- };
3407
- }
3408
- default: Z(`reserved additional info value: ${n}`);
3409
- }
3410
- }
3411
- function Br(e, t, n, r, i, a) {
3412
- let o = [], s = t;
3413
- for (;;) {
3414
- if (s >= e.byteLength && Z(`unexpected end of indefinite ${i}`), e.getUint8(s) === 255) {
3415
- s++;
3416
- break;
3417
- }
3418
- let t = Q(e, s, n, r);
3419
- a(t.value) || Z(`indefinite-length ${i} chunk must be a definite ${i}`), o.push(t.value), s = t.nextOffset;
3420
- }
3421
- return {
3422
- chunks: o,
3423
- nextOffset: s
3424
- };
3425
- }
3426
- function Vr(e, t, n, r) {
3427
- let i = Nr(e);
3428
- t.has(i) && n.push(Ar(`duplicate map key at offset ${e.start}`, e.start, r)), t.add(i);
3429
- }
3430
- function Q(e, t, n, r) {
3431
- let i = t, a = Ur(e, t, n, r);
3432
- return a.value.start = i, a.value.end = a.nextOffset, a;
3433
- }
3434
- function Hr(e, t, n) {
3435
- return new Uint8Array(e.buffer, e.byteOffset + t, n).slice();
3436
- }
3437
- function Ur(e, t, n, r) {
3438
- t >= e.byteLength && Z("unexpected end of input");
3439
- let i = e.getUint8(t++), a = i >> 5, o = i & 31;
3440
- switch (a) {
3441
- case 0: {
3442
- let { value: n, nextOffset: r } = Rr(e, t, o);
3443
- return {
3444
- value: new I(n, { encodingWidth: Er(o, n) }),
3445
- nextOffset: r
3446
- };
3447
- }
3448
- case 1: {
3449
- let { value: n, nextOffset: r } = Rr(e, t, o), i = Er(o, n);
3450
- return {
3451
- value: new L(-1n - n, { encodingWidth: i }),
3452
- nextOffset: r
3453
- };
3454
- }
3455
- case 2: {
3456
- if (o === 31) {
3457
- let { chunks: i, nextOffset: a } = Br(e, t, n, r, "byte string", (e) => e instanceof B);
3458
- return {
3459
- value: new V(i),
3460
- nextOffset: a
3461
- };
3462
- }
3463
- let { value: i, nextOffset: a } = zr(e, t, o), s = Dr(o, i);
3464
- return a + i > e.byteLength && Z("byte string extends beyond input"), {
3465
- value: new B(new Uint8Array(e.buffer, e.byteOffset + a, i).slice(), { encodingWidth: s }),
3466
- nextOffset: a + i
3467
- };
3468
- }
3469
- case 3: {
3470
- if (o === 31) {
3471
- let { chunks: i, nextOffset: a } = Br(e, t, n, r, "text string", (e) => e instanceof Y);
3472
- return {
3473
- value: new H(i),
3474
- nextOffset: a
3475
- };
3476
- }
3477
- let { value: i, nextOffset: a } = zr(e, t, o), s = Dr(o, i);
3478
- a + i > e.byteLength && Z("text string extends beyond input");
3479
- let c = new Uint8Array(e.buffer, e.byteOffset + a, i), l, u, d = i < 64 ? Lr(c, i) : void 0;
3480
- if (d !== void 0) l = d;
3481
- else try {
3482
- l = Or.decode(c);
3483
- } catch {
3484
- u = Ar("invalid UTF-8 sequence in text string", a, n), l = kr.decode(c);
3485
- }
3486
- let f = new Y(l, { encodingWidth: s });
3487
- return u && jr(f, u), {
3488
- value: f,
3489
- nextOffset: a + i
3490
- };
3491
- }
3492
- case 4: {
3493
- if (o === 31) {
3494
- let i = [], a = t;
3495
- for (;;) {
3496
- if (a >= e.byteLength && Z("unexpected end of indefinite array"), e.getUint8(a) === 255) {
3497
- a++;
3498
- break;
3499
- }
3500
- let t = Q(e, a, n, r);
3501
- i.push(t.value), a = t.nextOffset;
3502
- }
3503
- return {
3504
- value: new U(i, { indefiniteLength: !0 }),
3505
- nextOffset: a
3506
- };
3507
- }
3508
- let { value: i, nextOffset: a } = zr(e, t, o), s = Dr(o, i), c = [], l = a;
3509
- for (let t = 0; t < i; t++) {
3510
- let t = Q(e, l, n, r);
3511
- c.push(t.value), l = t.nextOffset;
3512
- }
3513
- return {
3514
- value: new U(c, { encodingWidth: s }),
3515
- nextOffset: l
3516
- };
3517
- }
3518
- case 5: {
3519
- if (o === 31) {
3520
- let i = [], a = /* @__PURE__ */ new Set(), o = [], s = t;
3521
- for (;;) {
3522
- if (s >= e.byteLength && Z("unexpected end of indefinite map"), e.getUint8(s) === 255) {
3523
- s++;
3524
- break;
3525
- }
3526
- let t = Q(e, s, n, r);
3527
- Vr(t.value, a, o, n), s = t.nextOffset;
3528
- let c = Q(e, s, n, r);
3529
- s = c.nextOffset, i.push([t.value, c.value]);
3530
- }
3531
- let c = new W(i, { indefiniteLength: !0 });
3532
- for (let e of o) jr(c, e);
3533
- return {
3534
- value: c,
3535
- nextOffset: s
3536
- };
3537
- }
3538
- let { value: i, nextOffset: a } = zr(e, t, o), s = Dr(o, i), c = [], l = /* @__PURE__ */ new Set(), u = [], d = a;
3539
- for (let t = 0; t < i; t++) {
3540
- let t = Q(e, d, n, r);
3541
- Vr(t.value, l, u, n), d = t.nextOffset;
3542
- let i = Q(e, d, n, r);
3543
- d = i.nextOffset, c.push([t.value, i.value]);
3544
- }
3545
- let f = new W(c, { encodingWidth: s });
3546
- for (let e of u) jr(f, e);
3547
- return {
3548
- value: f,
3549
- nextOffset: d
3550
- };
3551
- }
3552
- case 6: {
3553
- o === 31 && Z("tags cannot use indefinite-length encoding");
3554
- let { value: i, nextOffset: a } = Rr(e, t, o), s = Er(o, i), c = Q(e, a, n, r);
3555
- for (let e of r) {
3556
- let t = e.parseTag(i, c.value, n);
3557
- if (t !== void 0) return t instanceof z && s !== void 0 && (t.encodingWidth = s), {
3558
- value: t,
3559
- nextOffset: c.nextOffset
3560
- };
3561
- }
3562
- return {
3563
- value: new z(i, c.value, { encodingWidth: s }),
3564
- nextOffset: c.nextOffset
3565
- };
3566
- }
3567
- case 7:
3568
- if (o <= 19) return {
3569
- value: new G(o),
3570
- nextOffset: t
3571
- };
3572
- if (o === 20) return {
3573
- value: new G(20),
3574
- nextOffset: t
3575
- };
3576
- if (o === 21) return {
3577
- value: new G(21),
3578
- nextOffset: t
3579
- };
3580
- if (o === 22) return {
3581
- value: new G(22),
3582
- nextOffset: t
3583
- };
3584
- if (o === 23) return {
3585
- value: new G(23),
3586
- nextOffset: t
3587
- };
3588
- if (o === 24) {
3589
- t + 1 > e.byteLength && Z("unexpected end of input");
3590
- let r = e.getUint8(t);
3591
- if (r < 32) {
3592
- let e = Ar(`simple value ${r} must be encoded in initial byte (0–31 reserved for extended encoding)`, t - 1, n), i = new G(r);
3593
- return jr(i, e), {
3594
- value: i,
3595
- nextOffset: t + 1
3596
- };
3597
- }
3598
- return {
3599
- value: new G(r),
3600
- nextOffset: t + 1
3601
- };
3602
- }
3603
- if (o === 25) {
3604
- t + 2 > e.byteLength && Z("unexpected end of input");
3605
- let n = j(e.getUint16(t, !1));
3606
- return {
3607
- value: new R(n, {
3608
- precision: "half",
3609
- rawBits: Number.isNaN(n) ? Hr(e, t, 2) : void 0
3610
- }),
3611
- nextOffset: t + 2
3612
- };
3613
- }
3614
- if (o === 26) {
3615
- t + 4 > e.byteLength && Z("unexpected end of input");
3616
- let n = e.getFloat32(t, !1);
3617
- return {
3618
- value: new R(n, {
3619
- precision: "single",
3620
- rawBits: Number.isNaN(n) ? Hr(e, t, 4) : void 0
3621
- }),
3622
- nextOffset: t + 4
3623
- };
3624
- }
3625
- if (o === 27) {
3626
- t + 8 > e.byteLength && Z("unexpected end of input");
3627
- let n = e.getFloat64(t, !1);
3628
- return {
3629
- value: new R(n, {
3630
- precision: "double",
3631
- rawBits: Number.isNaN(n) ? Hr(e, t, 8) : void 0
3632
- }),
3633
- nextOffset: t + 8
3634
- };
3635
- }
3636
- return o < 31 && Z(`reserved additional info value in major type 7: ${o}`), Z("unexpected break code outside indefinite-length item");
3637
- }
3638
- return Z(`unknown major type: ${a}`);
3639
- }
3640
- function Wr(e) {
3641
- if (e instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && e instanceof SharedArrayBuffer) return new Uint8Array(e);
3642
- if (ArrayBuffer.isView(e)) return new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
3643
- throw TypeError("expected ArrayBufferView or ArrayBufferLike");
3644
- }
3645
- function Gr(e, t) {
3646
- let n = Wr(e), r = new DataView(n.buffer, n.byteOffset, n.byteLength), i = t?.offset ?? 0;
3647
- if (!Number.isInteger(i) || i < 0 || i > r.byteLength) throw RangeError(`CBOR decode offset must be an integer between 0 and ${r.byteLength}`);
3648
- let a = Ir(t?.builtinExtensions), o = t?.extensions?.length ? [...t.extensions.filter((e) => e.parseTag !== void 0), ...a] : a, { value: s, nextOffset: c } = Q(r, i, t, o);
3649
- if (!t?.allowTrailing && c !== r.byteLength) {
3650
- jr(s, Ar(`${r.byteLength - c} trailing byte(s) after end of CBOR item`, c, t));
3651
- let e = {
3652
- strict: !1,
3653
- silent: !0
3654
- }, n = c;
3655
- for (; n < r.byteLength;) ({nextOffset: n} = Q(r, n, e, o));
3656
- }
3657
- return s;
3658
- }
3659
- //#endregion
3660
- //#region src/extensions/cbordata.ts
3661
- var Kr = 24n, qr = {
3662
- tagNumbers: [Kr],
3663
- parseTag(e, t, n) {
3664
- if (e !== 24n || !(t instanceof B)) return;
3665
- let r = (t.end ?? t.value.length) - t.value.length, i = n ? {
3666
- extensions: n.extensions,
3667
- builtinExtensions: n.builtinExtensions,
3668
- strict: n.strict,
3669
- onWarning: n.onWarning ? (e) => n.onWarning({
3670
- ...e,
3671
- offset: e.offset + r
3672
- }) : void 0,
3673
- silent: n.silent
3674
- } : void 0;
3675
- try {
3676
- return new z(Kr, new K([Gr(t.value, i)], { encodingWidth: t.encodingWidth }));
3677
- } catch (e) {
3678
- if (i?.strict !== !1) throw e;
3679
- let t = `tag 24 content is not valid CBOR: ${e instanceof Error ? e.message : String(e)}`, a = {
3680
- message: t,
3681
- offset: r
3682
- };
3683
- n?.onWarning ? n.onWarning(a) : n?.silent || console.warn(`CBOR strict violation at offset ${a.offset}: ${t}`);
3684
- return;
3685
- }
3686
- }
3687
- };
3688
- //#endregion
3689
- //#region src/extensions/ellipsis.ts
3690
- function Jr(e) {
3691
- return e instanceof q && !(e.content instanceof U);
3692
- }
3693
- function Yr(e) {
3694
- let t = !1, n = !1, r = !1, i;
3695
- for (let a of e) {
3696
- let e;
3697
- if (Jr(a)) e = !0, r = !0;
3698
- else if (a instanceof Y) e = !1, t = !0;
3699
- else if (a instanceof B) e = !1, n = !0;
3700
- else return !1;
3701
- if (e === i) return !1;
3702
- i = e;
3703
- }
3704
- return r && !(t && n);
3705
- }
3706
- var Xr = {
3707
- tagNumbers: [dt],
3708
- parseTag(e, t) {
3709
- if (e === 888n) {
3710
- if (t instanceof G && t.value === 22) return new q();
3711
- if (t instanceof U && Yr(t.items)) return new q(t.items);
3712
- }
3713
- }
3714
- }, Zr = new TextEncoder(), Qr = new TextDecoder("utf-8", { fatal: !0 }), $r = new TextDecoder("utf-8", { fatal: !1 }), ei = Symbol("ellipsis");
3715
- function ti(e) {
3716
- let t = 0;
3717
- for (let n of e) t += n.length;
3718
- let n = new Uint8Array(t), r = 0;
3719
- for (let t of e) n.set(t, r), r += t.length;
3720
- return n;
3721
- }
3722
- function ni(e, t, n) {
3723
- if (t instanceof ut) {
3724
- ni(e, t.inner, n);
3725
- return;
3726
- }
3727
- if (t instanceof q) {
3728
- if (t.content instanceof U) for (let r of t.content.items) ni(e, r, n);
3729
- else n.push(ei);
3730
- return;
3731
- }
3732
- if (t instanceof Y) {
3733
- n.push(Zr.encode(t.value));
3734
- return;
3735
- }
3736
- if (t instanceof B) {
3737
- n.push(t.value);
3738
- return;
3739
- }
3740
- if (t instanceof H) {
3741
- n.push(Zr.encode(t.chunks.map((e) => e.value).join("")));
3742
- return;
3743
- }
3744
- if (t instanceof V) {
3745
- n.push(ti(t.chunks.map((e) => e.value)));
3746
- return;
3747
- }
3748
- throw SyntaxError(`${e}<<...>> arguments must be (text or byte) strings or ellipses`);
3749
- }
3750
- function ri(e, t) {
3751
- try {
3752
- return Qr.decode(e);
3753
- } catch {
3754
- let n = "t1 concatenation result is not valid UTF-8";
3755
- if (t) t(n);
3756
- else throw SyntaxError(n);
3757
- return $r.decode(e);
3758
- }
3759
- }
3760
- function ii(e, t, n) {
3761
- let r = [];
3762
- for (let n of t) ni(e, n, r);
3763
- let i = e === "t1", a = [], o = !1, s = [], c = () => {
3764
- if (s.length === 0) return;
3765
- let e = ti(s);
3766
- s.length = 0, e.length !== 0 && a.push(i ? new Y(ri(e, n)) : new B(e));
3767
- };
3768
- for (let e of r) e === ei ? (c(), a[a.length - 1] instanceof q || (a.push(new q()), o = !0)) : s.push(e);
3769
- if (!o) {
3770
- let e = ti(s);
3771
- return i ? new Y(ri(e, n)) : new B(e);
3772
- }
3773
- return c(), a.length === 1 ? new q() : new q(a);
3774
- }
3775
- function ai(e) {
3776
- return {
3777
- appStringPrefixes: [e],
3778
- preserveAppSeqSource: !0,
3779
- parseAppString(t, n, r) {
3780
- return ii(e, [new Y(n)], r);
3781
- },
3782
- parseAppSequence(t, n, r) {
3783
- return ii(e, n, r);
3784
- }
3785
- };
3786
- }
3787
- var oi = ai("t1"), si = ai("b1"), ci = new TextEncoder(), li = new TextDecoder("utf-8", { fatal: !0 }), ui = new TextDecoder("utf-8", { fatal: !1 });
3788
- function di(e) {
3789
- let t = 0;
3790
- for (let n of e) t += n.length;
3791
- let n = new Uint8Array(t), r = 0;
3792
- for (let t of e) n.set(t, r), r += t.length;
3793
- return n;
3794
- }
3795
- function fi(e, t, n) {
3796
- let r = e === "ilts", i = [], a = [];
3797
- for (let o of t) {
3798
- if (o instanceof ut && (o = o.inner), o instanceof q) throw SyntaxError(`${e}<<...>> cannot contain ellipses; there is no way to include an elision in an indefinite-length string`);
3799
- let t, s, c;
3800
- if (o instanceof Y) t = o.value, c = o.encodingWidth;
3801
- else if (o instanceof B) s = o.value, c = o.encodingWidth;
3802
- else if (o instanceof H) t = o.chunks.map((e) => e.value).join("");
3803
- else if (o instanceof V) s = di(o.chunks.map((e) => e.value));
3804
- else throw SyntaxError(`${e}<<...>> arguments must be (text or byte) strings`);
3805
- if (r) {
3806
- let e;
3807
- if (t !== void 0) e = t;
3808
- else try {
3809
- e = li.decode(s);
3810
- } catch {
3811
- let t = "ilts chunk is not valid UTF-8";
3812
- if (n) n(t);
3813
- else throw SyntaxError(t);
3814
- e = ui.decode(s);
3815
- }
3816
- a.push(new Y(e, c === void 0 ? void 0 : { encodingWidth: c }));
3817
- } else {
3818
- let e = s ?? ci.encode(t);
3819
- i.push(new B(e, c === void 0 ? void 0 : { encodingWidth: c }));
3820
- }
3821
- }
3822
- return r ? new H(a) : new V(i);
3823
- }
3824
- function pi(e) {
3825
- return {
3826
- appStringPrefixes: [e],
3827
- preserveAppSeqSource: !0,
3828
- parseAppString(t, n, r) {
3829
- return new ut(fi(e, [new Y(n)], r), `${e}${ne(n)}`);
3830
- },
3831
- parseAppSequence(t, n, r) {
3832
- return fi(e, n, r);
3833
- }
3834
- };
3835
- }
3836
- var mi = pi("ilbs"), hi = pi("ilts"), gi = class extends R {
3837
- _bits;
3838
- constructor(e) {
3839
- super(j(e), { precision: "half" }), this._bits = e & 65535;
3840
- }
3841
- _toCBOR() {
3842
- return new Uint8Array([
3843
- 249,
3844
- this._bits >> 8 & 255,
3845
- this._bits & 255
3846
- ]);
3847
- }
3848
- }, _i = class extends R {
3849
- _raw;
3850
- constructor(e) {
3851
- super(new DataView(e.buffer, e.byteOffset).getFloat32(0, !1), { precision: "single" }), this._raw = e.slice();
3852
- }
3853
- _toCBOR() {
3854
- let e = /* @__PURE__ */ new Uint8Array(5);
3855
- return e[0] = 250, e.set(this._raw, 1), e;
3856
- }
3857
- }, vi = class extends R {
3858
- _raw;
3859
- constructor(e) {
3860
- super(new DataView(e.buffer, e.byteOffset).getFloat64(0, !1), { precision: "double" }), this._raw = e.slice();
3861
- }
3862
- _toCBOR() {
3863
- let e = /* @__PURE__ */ new Uint8Array(9);
3864
- return e[0] = 251, e.set(this._raw, 1), e;
3865
- }
3866
- };
3867
- function yi(e) {
3868
- if (e.length === 2) return new gi(e[0] << 8 | e[1]);
3869
- if (e.length === 4) return new _i(e);
3870
- if (e.length === 8) return new vi(e);
3871
- throw SyntaxError(`float'...' requires 4, 8, or 16 hex digits (2, 4, or 8 bytes); got ${e.length} bytes`);
3872
- }
3873
- function bi(e) {
3874
- let t = e >>> 15 & 1, n = e >>> 10 & 31, r = e & 1023, i;
3875
- if (n === 31) i = t << 31 | 2139095040 | r << 13;
3876
- else if (n === 0 && r === 0) i = t << 31;
3877
- else if (n === 0) {
3878
- let e = r, n = 0;
3879
- for (; !(e & 512);) e <<= 1, n++;
3880
- i = t << 31 | 112 - n << 23 | (e & 511) << 14;
3881
- } else i = t << 31 | n + 112 << 23 | r << 13;
3882
- let a = /* @__PURE__ */ new Uint8Array(4);
3883
- return new DataView(a.buffer).setUint32(0, i >>> 0, !1), a;
3884
- }
3885
- function xi(e) {
3886
- let t = e >>> 15 & 1, n = e >>> 10 & 31, r = e & 1023, i = /* @__PURE__ */ new Uint8Array(8), a = new DataView(i.buffer);
3887
- if (n === 31) a.setUint32(0, (t << 31 | 2146435072 | r << 10) >>> 0, !1), a.setUint32(4, 0, !1);
3888
- else if (n === 0 && r === 0) a.setUint32(0, t << 31 >>> 0, !1), a.setUint32(4, 0, !1);
3889
- else if (n === 0) {
3890
- let e = r, n = 0;
3891
- for (; !(e & 512);) e <<= 1, n++;
3892
- a.setUint32(0, (t << 31 | 1008 - n << 20 | (e & 511) << 11) >>> 0, !1), a.setUint32(4, 0, !1);
3893
- } else a.setUint32(0, (t << 31 | n + 1008 << 20 | r << 10) >>> 0, !1), a.setUint32(4, 0, !1);
3894
- return i;
3895
- }
3896
- function Si(e) {
3897
- let t = new DataView(e.buffer, e.byteOffset).getUint32(0, !1), n = t >>> 31 & 1, r = t >>> 23 & 255, i = t & 8388607, a = /* @__PURE__ */ new Uint8Array(8), o = new DataView(a.buffer);
3898
- if (r === 255) o.setUint32(0, (n << 31 | 2146435072 | i >>> 3) >>> 0, !1), o.setUint32(4, (i & 7) << 29, !1);
3899
- else if (r === 0 && i === 0) o.setUint32(0, n << 31 >>> 0, !1), o.setUint32(4, 0, !1);
3900
- else {
3901
- let t = new DataView(e.buffer, e.byteOffset).getFloat32(0, !1);
3902
- o.setFloat64(0, t, !1);
3903
- }
3904
- return a;
3905
- }
3906
- function Ci(e, t, n) {
3907
- let r = e.length === 2 ? 1 : e.length === 4 ? 2 : 3;
3908
- if (r === 1) {
3909
- let n = e[0] << 8 | e[1];
3910
- if (t === 2) return new _i(bi(n));
3911
- if (t === 3) return new vi(xi(n));
3912
- }
3913
- if (r === 2) {
3914
- if (t === 3) return new vi(Si(e));
3915
- if (t === 1) {
3916
- let t = new DataView(e.buffer, e.byteOffset).getFloat32(0, !1), r = ve(t);
3917
- return !Object.is(j(r), t) && !isNaN(t) && n("float'...' value cannot be exactly represented as float16 (_1)"), new gi(r);
3918
- }
3919
- }
3920
- if (r === 3) {
3921
- let r = new DataView(e.buffer, e.byteOffset).getFloat64(0, !1);
3922
- if (t === 1) {
3923
- let e = ve(r);
3924
- return !Object.is(j(e), r) && !isNaN(r) && n("float'...' value cannot be exactly represented as float16 (_1)"), new gi(e);
3925
- }
3926
- if (t === 2) {
3927
- let e = Math.fround(r);
3928
- !Object.is(e, r) && !isNaN(r) && n("float'...' value cannot be exactly represented as float32 (_2)");
3929
- let t = /* @__PURE__ */ new Uint8Array(4);
3930
- return new DataView(t.buffer).setFloat32(0, e, !1), new _i(t);
3931
- }
3932
- }
3933
- return yi(e);
3934
- }
3935
- var wi = {
3936
- appStringPrefixes: ["float"],
3937
- parseAppString(e, t, n, r) {
3938
- let a = tt(t);
3939
- if (!/^[0-9a-fA-F]*$/.test(a)) throw SyntaxError("float'...' contains non-hex characters");
3940
- if (a.length % 2 != 0) throw SyntaxError(`float'...' hex content has odd length (${a.length} digits)`);
3941
- let o = i(a), s = r?.encodingWidth;
3942
- if (s === void 0) return yi(o);
3943
- if (s !== 1 && s !== 2 && s !== 3) {
3944
- let e = `float'...' encoding indicator _${s} is not valid; use _1, _2, or _3`;
3945
- if (n) return n(e), yi(o);
3946
- throw SyntaxError(e);
3947
- }
3948
- return s === (o.length === 2 ? 1 : o.length === 4 ? 2 : 3) ? yi(o) : Ci(o, s, n ?? ((e) => {
3949
- throw SyntaxError(e);
3950
- }));
3951
- },
3952
- parseAppSequence(e, t, n) {
3953
- if (t.length === 0) throw SyntaxError("float<<...>> requires exactly one byte-string item");
3954
- if (t.length > 1) {
3955
- let e = `float<<...>> expects 1 item; got ${t.length} — using first`;
3956
- if (n) n(e);
3957
- else throw SyntaxError(e);
3958
- }
3959
- if (!(t[0] instanceof B)) throw SyntaxError("float<<...>> item must be a byte string");
3960
- return yi(t[0].value);
3961
- }
3962
- }, Ti = [
3963
- Tr,
3964
- qr,
3965
- Xr
3966
- ], Ei = [
3967
- On,
3968
- Jn,
3969
- Sr,
3970
- oi,
3971
- si,
3972
- mi,
3973
- hi,
3974
- wi
3975
- ], Di;
3976
- function Oi(e) {
3977
- return e === void 0 ? Di ??= [...Ti, ...Ei] : e === !1 ? Ti : [...Ti, ...e];
3978
- }
3979
- //#endregion
3980
- //#region src/js/fromJS.ts
3981
- var ki;
3982
- function Ai(e) {
3983
- if (e === void 0) {
3984
- if (ki) return ki;
3985
- let e = Oi(void 0);
3986
- return ki = {
3987
- fromJS: e.filter((e) => e.fromJS !== void 0),
3988
- parseTag: e.filter((e) => e.parseTag !== void 0)
3989
- };
3990
- }
3991
- let t = Oi(e);
3992
- return {
3993
- fromJS: t.filter((e) => e.fromJS !== void 0),
3994
- parseTag: t.filter((e) => e.parseTag !== void 0)
3995
- };
3996
- }
3997
- function ji(e) {
3998
- let t = e?.extensions, n = Ai(e?.builtinExtensions);
3999
- return t?.length ? {
4000
- fromJS: [...t.filter((e) => e.fromJS !== void 0), ...n.fromJS],
4001
- parseTag: [...t.filter((e) => e.parseTag !== void 0), ...n.parseTag]
4002
- } : n;
4003
- }
4004
- function Mi(e, t) {
4005
- if (t?.replacer) {
4006
- let { replacer: n, ...r } = t, i = Fi(e, n, r.extensions, r.undefinedOmits, r.builtinExtensions);
4007
- return i === A ? G.UNDEFINED : Mi(i, Object.keys(r).length > 0 ? r : void 0);
4008
- }
4009
- return Ni(e, t, !0, ji(t));
4010
- }
4011
- function Ni(e, t, n, r) {
4012
- for (let n of r.fromJS) {
4013
- let r = n.fromJS(e, t ?? {});
4014
- if (r !== void 0) return r;
4015
- }
4016
- if (n && typeof e == "object" && e && k.symbol in e) {
4017
- let n = e[k.symbol], i = Ni(e, t, !1, r);
4018
- for (let e of r.parseTag) {
4019
- let t = e.parseTag(n, i);
4020
- if (t !== void 0) return t;
4021
- }
4022
- return new z(n, i);
4023
- }
4024
- if (e instanceof k.Null) return G.NULL;
4025
- if (e instanceof k.Undefined) return G.UNDEFINED;
4026
- if (e instanceof he) return new G(e.value);
4027
- if (e === null) return G.NULL;
4028
- if (e === void 0) return G.UNDEFINED;
4029
- if (e === !0) return G.TRUE;
4030
- if (e === !1) return G.FALSE;
4031
- if (typeof e == "bigint") return e > 18446744073709551615n ? new Ct(e) : e < -18446744073709551616n ? new wt(e) : e >= 0n ? new I(e) : new L(e);
4032
- if (typeof e == "number") return (t?.encodeIntegerAs ?? "int") === "int" && Number.isInteger(e) && !Object.is(e, -0) ? e >= 0 ? new I(BigInt(e)) : new L(BigInt(e)) : new R(e);
4033
- if (typeof e == "string") return new Y(e);
4034
- if (e instanceof Number || e instanceof Boolean || e instanceof String || Object.prototype.toString.call(e) === "[object BigInt]") return Ni(e.valueOf(), t, !1, r);
4035
- if (e instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && e instanceof SharedArrayBuffer) return new B(new Uint8Array(e));
4036
- if (ArrayBuffer.isView(e)) return e instanceof Uint8Array && t?.uint8ArrayAs === "array" ? new U(Array.from(e, (e) => new I(BigInt(e)))) : new B(new Uint8Array(e.buffer, e.byteOffset, e.byteLength));
4037
- if (e instanceof $) return new W([...e].map(([e, n]) => [Ni(e, t, !0, r), Ni(n, t, !0, r)]));
4038
- if (Array.isArray(e)) return new U(e.map((e) => Ni(e, t, !0, r)));
4039
- if (typeof e == "object") {
4040
- let n = [];
4041
- for (let [i, a] of Object.entries(e)) n.push([new Y(i), Ni(a, t, !0, r)]);
4042
- return new W(n);
4043
- }
4044
- throw TypeError(`fromJS: unsupported value type: ${typeof e}`);
4045
- }
4046
- function Pi(e) {
4047
- return ArrayBuffer.isView(e) || e instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && e instanceof SharedArrayBuffer || e instanceof Number || e instanceof Boolean || e instanceof String || Object.prototype.toString.call(e) === "[object BigInt]" || e instanceof k.Null || e instanceof k.Undefined || e instanceof he;
4048
- }
4049
- function Fi(e, t, n, r, i) {
4050
- let a = [...n ?? [], ...Oi(i)].filter((e) => e.isJSType !== void 0);
4051
- function o(e) {
4052
- return e === A || r === !0 && e === void 0;
4053
- }
4054
- if (Array.isArray(t)) {
4055
- let n = t.map(String);
4056
- function r(e) {
4057
- if (typeof e != "object" || !e) return e;
4058
- if (e instanceof $) return $.from(e, ([e, t]) => [e, r(t)]);
4059
- if (Array.isArray(e)) return e.map(r);
4060
- if (k.symbol in e || Pi(e) || a.some((t) => t.isJSType(e))) return e;
4061
- let t = Object.getPrototypeOf(e);
4062
- if (t === Object.prototype || t === null) {
4063
- let t = e.toJSON;
4064
- if (typeof t == "function") return r(t.call(e));
4065
- }
4066
- let i = {};
4067
- for (let t of n) Object.prototype.hasOwnProperty.call(e, t) && (i[t] = r(e[t]));
4068
- return i;
4069
- }
4070
- return r(e);
4071
- }
4072
- let s = t;
4073
- function c(e, t, n) {
4074
- if (typeof e == "object" && e && !(e instanceof $)) {
4075
- let n = Object.getPrototypeOf(e);
4076
- if (n === Object.prototype || n === null) {
4077
- let n = e.toJSON;
4078
- typeof n == "function" && (e = n.call(e, t));
4079
- }
4080
- }
4081
- if (e = s.call(n, t, e), typeof e == "object" && e) {
4082
- if (k.symbol in e) return e;
4083
- if (e instanceof $) {
4084
- let t = new $();
4085
- for (let [n, r] of e) {
4086
- let i = c(r, n, e);
4087
- o(i) || t.push([n, i]);
4088
- }
4089
- return t;
4090
- }
4091
- if (Array.isArray(e)) return e.map((t, n) => {
4092
- let r = c(t, String(n), e);
4093
- return o(r) ? null : r;
4094
- });
4095
- if (Pi(e) || a.some((t) => t.isJSType(e))) return e;
4096
- let t = {};
4097
- for (let n of Object.keys(e)) {
4098
- let r = c(e[n], n, e);
4099
- o(r) || (t[n] = r);
4100
- }
4101
- return t;
4102
- }
4103
- return e;
4104
- }
4105
- return c(e, "", { "": e });
4106
- }
4107
- //#endregion
4108
- //#region src/mapEntries.ts
4109
- var $ = class extends Array {
4110
- toJSON() {
4111
- let e = {};
4112
- for (let [t, n] of this) {
4113
- let r = typeof t == "string" ? t : Mi(t).toCDN();
4114
- r === "__proto__" ? Object.defineProperty(e, r, {
4115
- value: n,
4116
- writable: !0,
4117
- enumerable: !0,
4118
- configurable: !0
4119
- }) : e[r] = n;
4120
- }
4121
- return e;
4122
- }
4123
- };
4124
- //#endregion
4125
- export { z as A, ce as B, K as C, H as D, U as E, F, le as H, P as I, he as L, Ze as M, L as N, V as O, I as P, A as R, st as S, W as T, k as V, wt as _, wi as a, ut as b, si as c, Sr as d, Jn as f, Ot as g, Y as h, Ei as i, R as j, B as k, oi as l, kn as m, Fi as n, mi as o, On as p, Mi as r, hi as s, $ as t, Gr as u, Ct as v, G as w, ot as x, q as y, se as z };
4126
-
4127
- //# sourceMappingURL=mapEntries-CCLaJSaJ.js.map