@cbortech/cbor 0.23.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.ja.md +58 -6
  2. package/README.md +59 -7
  3. package/dist/ast/CborArray.d.ts +17 -0
  4. package/dist/ast/CborBignum.d.ts +36 -0
  5. package/dist/ast/CborByteString.d.ts +20 -0
  6. package/dist/ast/CborEllipsis.d.ts +11 -0
  7. package/dist/ast/CborEmbeddedCBOR.d.ts +22 -0
  8. package/dist/ast/CborFloat.d.ts +27 -0
  9. package/dist/ast/CborIndefiniteByteString.d.ts +13 -0
  10. package/dist/ast/CborIndefiniteTextString.d.ts +13 -0
  11. package/dist/ast/CborItem.d.ts +91 -0
  12. package/dist/ast/CborMap.d.ts +17 -0
  13. package/dist/ast/CborNint.d.ts +27 -0
  14. package/dist/ast/CborSimple.d.ts +22 -0
  15. package/dist/ast/CborTag.d.ts +16 -0
  16. package/dist/ast/CborTextString.d.ts +15 -0
  17. package/dist/ast/CborUint.d.ts +14 -0
  18. package/dist/ast/CborUnresolvedAppExt.d.ts +16 -0
  19. package/dist/ast/index.cjs +1 -0
  20. package/dist/ast/index.d.ts +15 -0
  21. package/dist/ast/index.js +2 -0
  22. package/dist/cbor/constants.d.ts +14 -0
  23. package/dist/cbor/decoder.d.ts +11 -0
  24. package/dist/cbor/encode.d.ts +35 -0
  25. package/dist/cbor/encoder.d.ts +7 -0
  26. package/dist/cbor.d.ts +143 -0
  27. package/dist/edn/parser.d.ts +7 -0
  28. package/dist/edn/serialize-utils.d.ts +48 -0
  29. package/dist/edn/serializer.d.ts +7 -0
  30. package/dist/edn/tokenizer.d.ts +176 -0
  31. package/dist/extensions/bignum.d.ts +3 -0
  32. package/dist/extensions/builtins.d.ts +2 -0
  33. package/dist/extensions/cbordata.d.ts +4 -0
  34. package/dist/extensions/cri.d.ts +32 -0
  35. package/dist/extensions/dt.d.ts +109 -0
  36. package/dist/extensions/ip.d.ts +41 -0
  37. package/dist/extensions/types.d.ts +70 -0
  38. package/dist/index.cjs +2 -31
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.ts +8 -695
  41. package/dist/index.js +30 -3913
  42. package/dist/index.js.map +1 -1
  43. package/dist/js/fromJS.d.ts +25 -0
  44. package/dist/js/toJS.d.ts +6 -0
  45. package/dist/mapEntries-D5MWtXqq.js +3245 -0
  46. package/dist/mapEntries-D5MWtXqq.js.map +1 -0
  47. package/dist/mapEntries-bihZ3yks.cjs +31 -0
  48. package/dist/mapEntries-bihZ3yks.cjs.map +1 -0
  49. package/dist/mapEntries.d.ts +3 -0
  50. package/dist/simple.d.ts +25 -0
  51. package/dist/tag.d.ts +45 -0
  52. package/dist/types.d.ts +362 -0
  53. package/dist/utils/float16.d.ts +38 -0
  54. package/dist/utils/hexfloat.d.ts +27 -0
  55. package/dist/utils/ip.d.ts +9 -0
  56. package/package.json +29 -17
@@ -0,0 +1,3245 @@
1
+ //#region src/tag.ts
2
+ var e = Symbol.for("cbor.tag"), t = class {
3
+ valueOf() {
4
+ return null;
5
+ }
6
+ toJSON() {
7
+ return null;
8
+ }
9
+ }, n = class {
10
+ valueOf() {}
11
+ toJSON() {}
12
+ };
13
+ function r(t) {
14
+ if (!s(t)) return;
15
+ let n = t[e];
16
+ return typeof n == "bigint" ? n : void 0;
17
+ }
18
+ function i(r, i) {
19
+ let a;
20
+ switch (typeof r) {
21
+ case "number":
22
+ a = new Number(r);
23
+ break;
24
+ case "string":
25
+ a = new String(r);
26
+ break;
27
+ case "boolean":
28
+ a = new Boolean(r);
29
+ break;
30
+ case "bigint":
31
+ a = Object(r);
32
+ break;
33
+ case "undefined":
34
+ a = new n();
35
+ break;
36
+ case "object":
37
+ if (r === null) {
38
+ a = new t();
39
+ break;
40
+ }
41
+ a = r;
42
+ break;
43
+ default: throw TypeError(`setCborTag: cannot tag value of type ${typeof r}`);
44
+ }
45
+ return a[e] = i, a;
46
+ }
47
+ function a(r) {
48
+ if (r instanceof Number || r instanceof String || r instanceof Boolean || Object.prototype.toString.call(r) === "[object BigInt]") return r.valueOf();
49
+ if (r instanceof t) return null;
50
+ if (!(r instanceof n)) return typeof r == "object" && r && delete r[e], r;
51
+ }
52
+ function o(e) {
53
+ if (e instanceof Number || e instanceof String || e instanceof Boolean || Object.prototype.toString.call(e) === "[object BigInt]") return e.valueOf();
54
+ if (e instanceof t) return null;
55
+ if (!(e instanceof n)) return e;
56
+ }
57
+ function s(e) {
58
+ return typeof e == "object" && !!e;
59
+ }
60
+ var c = class {
61
+ constructor() {}
62
+ static symbol = e;
63
+ static Null = t;
64
+ static Undefined = n;
65
+ static get(e) {
66
+ return r(e);
67
+ }
68
+ static set(e, t) {
69
+ return i(e, t);
70
+ }
71
+ static remove(e) {
72
+ return a(e);
73
+ }
74
+ static getValue(e) {
75
+ return o(e);
76
+ }
77
+ }, l = Symbol("cbor.omit"), u = class e {
78
+ value;
79
+ constructor(e) {
80
+ if (!Number.isInteger(e) || e < 0 || e > 255) throw RangeError("Simple value must be an integer in 0–255");
81
+ this.value = e;
82
+ }
83
+ valueOf() {
84
+ return this.value;
85
+ }
86
+ toJSON() {
87
+ throw TypeError(`simple(${this.value}) cannot be serialized to JSON`);
88
+ }
89
+ static is(t) {
90
+ return t instanceof e;
91
+ }
92
+ static get(t) {
93
+ return t instanceof e ? t.value : void 0;
94
+ }
95
+ }, d = class {
96
+ start;
97
+ end;
98
+ comments;
99
+ _defaults;
100
+ toCBOR(e) {
101
+ let t = this._defaults ? {
102
+ ...this._defaults,
103
+ ...e
104
+ } : e;
105
+ return this._toCBOR(t);
106
+ }
107
+ toEDN(e) {
108
+ let t = this._defaults ? {
109
+ ...this._defaults,
110
+ ...e
111
+ } : e, n = this._toEDN(t, 0);
112
+ if (!t?.preserveComments) return n;
113
+ let r = this.comments?.leading?.map((e) => e.text) ?? [], i = this.comments?.trailing ?? [], a = i.length === 0 ? n : `${n} ${i.map((e) => e.text.trimEnd()).join(" ")}`;
114
+ return [...r, a].join("\n");
115
+ }
116
+ toJS(e) {
117
+ let t = this._defaults ? {
118
+ ...this._defaults,
119
+ ...e
120
+ } : e, n = this._toJS(t);
121
+ if (!t?.reviver) return n;
122
+ let r = t.reviver.call({ "": n }, "", n);
123
+ return r === l ? void 0 : r;
124
+ }
125
+ toHexDump(e) {
126
+ let t = this._defaults ? {
127
+ ...this._defaults,
128
+ ...e
129
+ } : e, n = t?.indent ?? 3, r = typeof n == "string" ? n : " ".repeat(n), i = (t?.commentStyle ?? "--") + " ", a = this._toHexDump(0, t), o = Math.max(...a.map((e) => e.depth * r.length + e.hex.length)) + 2;
130
+ return a.map((e) => (r.repeat(e.depth) + e.hex).padEnd(o) + i + e.comment).join("\n");
131
+ }
132
+ _toHexDump(e, t) {
133
+ return [{
134
+ depth: e,
135
+ hex: Array.from(this._toCBOR(), (e) => e.toString(16).toUpperCase().padStart(2, "0")).join(" "),
136
+ comment: this._toEDN(t, 0)
137
+ }];
138
+ }
139
+ }, f = "getFloat16" in DataView.prototype && "setFloat16" in DataView.prototype, p = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(8));
140
+ function ee(e) {
141
+ p.setFloat64(0, e, !1);
142
+ let t = p.getUint32(0, !1), n = p.getUint32(4, !1), r = t >>> 31 & 1, i = t >>> 20 & 2047, a = t & 1048575;
143
+ if (i === 2047) {
144
+ if (a === 0 && n === 0) return r << 15 | 31744;
145
+ let e = a >> 10 | (n === 0 ? 0 : 1) || 1;
146
+ return r << 15 | 31744 | e & 1023;
147
+ }
148
+ let o = i - 1023 + 15;
149
+ if (o >= 31) return r << 15 | 31744;
150
+ let s, c, l;
151
+ if (o <= 0) {
152
+ if (o < -10) return r << 15;
153
+ let e = 1 << 20 | a, t = 11 - o;
154
+ t <= 20 ? (s = e >> t & 1023, c = e >> t - 1 & 1, l = (e & (1 << t - 1) - 1) != 0 || n !== 0) : (s = 0, c = 1, l = a !== 0 || n !== 0);
155
+ } else s = a >> 10, c = a >> 9 & 1, l = (a & 511) != 0 || n !== 0;
156
+ if (c !== 0 && (l || s & 1) && s++, s >= 1024) {
157
+ let e = o <= 0 ? 1 : o + 1;
158
+ return e >= 31 ? r << 15 | 31744 : r << 15 | e << 10;
159
+ }
160
+ let u = o <= 0 ? 0 : o;
161
+ return r << 15 | u << 10 | s;
162
+ }
163
+ function te(e) {
164
+ let t = e >>> 15 & 1, n = e >>> 10 & 31, r = e & 1023;
165
+ 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);
166
+ }
167
+ var ne = f ? (e, t, n, r) => {
168
+ e.setFloat16(t, n, r);
169
+ } : (e, t, n, r) => {
170
+ e.setUint16(t, ee(n), r);
171
+ };
172
+ //#endregion
173
+ //#region src/cbor/encode.ts
174
+ function m(e, t, n) {
175
+ if (n !== void 0) {
176
+ if (n === "i") {
177
+ if (t > 23n) throw RangeError(`value ${t} does not fit in immediate encoding _i (max 23)`);
178
+ return new Uint8Array([e << 5 | Number(t)]);
179
+ }
180
+ let r = [
181
+ 255n,
182
+ 65535n,
183
+ 4294967295n,
184
+ 18446744073709551615n
185
+ ];
186
+ if (t > r[n]) throw RangeError(`value ${t} does not fit in encodingWidth _${n} (max ${r[n]})`);
187
+ let i = 24 + n;
188
+ if (i === 24) return new Uint8Array([e << 5 | 24, Number(t)]);
189
+ if (i === 25) {
190
+ let n = new Uint8Array(3);
191
+ return n[0] = e << 5 | 25, n[1] = Number(t >> 8n), n[2] = Number(t & 255n), n;
192
+ }
193
+ if (i === 26) {
194
+ let n = new Uint8Array(5);
195
+ return n[0] = e << 5 | 26, new DataView(n.buffer).setUint32(1, Number(t), !1), n;
196
+ }
197
+ let a = new Uint8Array(9);
198
+ return a[0] = e << 5 | 27, new DataView(a.buffer).setBigUint64(1, t, !1), a;
199
+ }
200
+ if (t <= 23n) return new Uint8Array([e << 5 | Number(t)]);
201
+ if (t <= 255n) return new Uint8Array([e << 5 | 24, Number(t)]);
202
+ if (t <= 65535n) {
203
+ let n = new Uint8Array(3);
204
+ return n[0] = e << 5 | 25, n[1] = Number(t >> 8n), n[2] = Number(t & 255n), n;
205
+ }
206
+ if (t <= 4294967295n) {
207
+ let n = new Uint8Array(5);
208
+ return n[0] = e << 5 | 26, new DataView(n.buffer).setUint32(1, Number(t), !1), n;
209
+ }
210
+ let r = new Uint8Array(9);
211
+ return r[0] = e << 5 | 27, new DataView(r.buffer).setBigUint64(1, t, !1), r;
212
+ }
213
+ function h(e) {
214
+ let t = e.reduce((e, t) => e + t.length, 0), n = new Uint8Array(t), r = 0;
215
+ for (let t of e) n.set(t, r), r += t.length;
216
+ return n;
217
+ }
218
+ var re = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(4));
219
+ function ie(e) {
220
+ return Object.is(te(ee(e)), e);
221
+ }
222
+ function ae(e) {
223
+ return re.setFloat32(0, e, !1), Object.is(re.getFloat32(0, !1), e);
224
+ }
225
+ function oe(e) {
226
+ return ie(e) ? "half" : ae(e) ? "single" : "double";
227
+ }
228
+ //#endregion
229
+ //#region src/ast/CborUint.ts
230
+ var g = class extends d {
231
+ value;
232
+ encodingWidth;
233
+ constructor(e, t) {
234
+ if (super(), this.value = BigInt(e), this.value < 0n) throw RangeError("CborUint value must be non-negative");
235
+ if (this.value > 18446744073709551615n) throw RangeError("CborUint value exceeds maximum uint64");
236
+ this.encodingWidth = t?.encodingWidth;
237
+ }
238
+ _toCBOR(e) {
239
+ return m(0, this.value, this.encodingWidth);
240
+ }
241
+ _toEDN(e, t) {
242
+ let n = this.encodingWidth === void 0 ? "" : `_${this.encodingWidth}`, r = this.value;
243
+ switch (e?.intFormat) {
244
+ case "hex": return `0x${r.toString(16)}${n}`;
245
+ case "octal": return `0o${r.toString(8)}${n}`;
246
+ case "binary": return `0b${r.toString(2)}${n}`;
247
+ default: return r.toString() + n;
248
+ }
249
+ }
250
+ _toJS(e) {
251
+ let t = e?.integerAs ?? "auto";
252
+ return t === "bigint" ? this.value : t === "number" || this.value <= BigInt(2 ** 53 - 1) ? Number(this.value) : this.value;
253
+ }
254
+ }, _ = class extends d {
255
+ argument;
256
+ encodingWidth;
257
+ constructor(e, t) {
258
+ super();
259
+ let n = BigInt(e);
260
+ if (n >= 0n) throw RangeError("CborNint value must be negative");
261
+ if (n < -18446744073709551616n) throw RangeError("CborNint value exceeds minimum int64");
262
+ this.argument = -1n - n, this.encodingWidth = t?.encodingWidth;
263
+ }
264
+ get value() {
265
+ return -1n - this.argument;
266
+ }
267
+ _toCBOR(e) {
268
+ return m(1, this.argument, this.encodingWidth);
269
+ }
270
+ _toEDN(e, t) {
271
+ let n = this.encodingWidth === void 0 ? "" : `_${this.encodingWidth}`, r = this.argument + 1n;
272
+ switch (e?.intFormat) {
273
+ case "hex": return `-0x${r.toString(16)}${n}`;
274
+ case "octal": return `-0o${r.toString(8)}${n}`;
275
+ case "binary": return `-0b${r.toString(2)}${n}`;
276
+ default: return this.value.toString() + n;
277
+ }
278
+ }
279
+ _toJS(e) {
280
+ let t = this.value, n = e?.integerAs ?? "auto";
281
+ return n === "bigint" ? t : n === "number" || t >= BigInt(-(2 ** 53 - 1)) ? Number(t) : t;
282
+ }
283
+ };
284
+ //#endregion
285
+ //#region src/edn/serialize-utils.ts
286
+ function v(e) {
287
+ let t = e?.indent;
288
+ return t === void 0 ? null : typeof t == "number" ? " ".repeat(t) : t;
289
+ }
290
+ function y(e, t) {
291
+ return e.repeat(t);
292
+ }
293
+ function b(e) {
294
+ return !!(e.comments?.leading?.length || e.comments?.trailing?.length || e.comments?.dangling?.length);
295
+ }
296
+ function se(e) {
297
+ return !!(e.comments?.trailing?.length || e.comments?.dangling?.length);
298
+ }
299
+ function ce(e, t) {
300
+ return (e.comments?.leading ?? []).map((e) => t + e.text);
301
+ }
302
+ function le(e) {
303
+ let t = e.comments?.trailing ?? [];
304
+ return t.length === 0 ? "" : " " + t.map((e) => e.text).join(" ");
305
+ }
306
+ function ue(e, t) {
307
+ return (e.comments?.dangling ?? []).map((e) => t + e.text);
308
+ }
309
+ function x(e, t = !1) {
310
+ let n = e?.commas ?? "comma", r = n !== "none";
311
+ return {
312
+ inlineSep: r ? t ? "," : ", " : " ",
313
+ multilineSep: r ? "," : "",
314
+ trailSep: n === "trailing" ? "," : "",
315
+ colSep: t ? ":" : ": "
316
+ };
317
+ }
318
+ function de(e) {
319
+ return typeof e.toHex == "function" ? e.toHex() : Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
320
+ }
321
+ var fe = typeof new Uint8Array().toBase64 == "function";
322
+ function pe(e) {
323
+ if (fe) return e.toBase64({ omitPadding: !0 });
324
+ let t = "";
325
+ for (let n of e) t += String.fromCharCode(n);
326
+ return btoa(t).replace(/=/g, "");
327
+ }
328
+ function me(e) {
329
+ if (fe) return e.toBase64({
330
+ alphabet: "base64url",
331
+ omitPadding: !0
332
+ });
333
+ let t = "";
334
+ for (let n of e) t += String.fromCharCode(n);
335
+ return btoa(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
336
+ }
337
+ var he = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", ge = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
338
+ function _e(e, t) {
339
+ let n = "", r = 0, i = 0;
340
+ for (let a of e) for (r = r << 8 | a, i += 8; i >= 5;) i -= 5, n += t[r >> i & 31];
341
+ return i > 0 && (n += t[r << 5 - i & 31]), n;
342
+ }
343
+ function ve(e) {
344
+ for (let t of e) {
345
+ let e = t.codePointAt(0);
346
+ if (e < 32 || e === 127) return !0;
347
+ }
348
+ return !1;
349
+ }
350
+ function ye(e, t, n) {
351
+ if (n === "string") {
352
+ let t = be(e);
353
+ if (t != null) return Se(t);
354
+ }
355
+ if (n === "printable-string" || n === void 0) {
356
+ let t = be(e);
357
+ if (t != null && !ve(t)) return Se(t);
358
+ }
359
+ switch (t) {
360
+ case "base64": return `b64'${pe(e)}'`;
361
+ case "base64url": return `b64'${me(e)}'`;
362
+ case "base32": return `b32'${_e(e, he)}'`;
363
+ case "base32hex": return `h32'${_e(e, ge)}'`;
364
+ default: return `h'${de(e)}'`;
365
+ }
366
+ }
367
+ function be(e) {
368
+ try {
369
+ return new TextDecoder("utf-8", { fatal: !0 }).decode(e);
370
+ } catch {
371
+ return null;
372
+ }
373
+ }
374
+ function xe(e, t) {
375
+ let n = t.codePointAt(0), r = t;
376
+ for (let i of e) {
377
+ let e = i.codePointAt(0);
378
+ switch (e) {
379
+ case n:
380
+ r += `\\${t}`;
381
+ break;
382
+ case 92:
383
+ r += "\\\\";
384
+ break;
385
+ case 10:
386
+ r += "\\n";
387
+ break;
388
+ case 13:
389
+ r += "\\r";
390
+ break;
391
+ case 9:
392
+ r += "\\t";
393
+ break;
394
+ default: e < 32 || e === 127 || e === 8232 || e === 8233 || e === 8203 || e === 8204 || e === 8205 || e === 65279 ? r += `\\u${e.toString(16).padStart(4, "0")}` : r += i;
395
+ }
396
+ }
397
+ return r + t;
398
+ }
399
+ function Se(e) {
400
+ return xe(e, "'");
401
+ }
402
+ function Ce(e) {
403
+ return xe(e, "'");
404
+ }
405
+ function we(e) {
406
+ return xe(e, "\"");
407
+ }
408
+ function Te(e) {
409
+ if (isNaN(e)) return "NaN";
410
+ if (!isFinite(e)) return e > 0 ? "Infinity" : "-Infinity";
411
+ if (Object.is(e, -0)) return "-0.0";
412
+ let t = e.toString();
413
+ return t.includes(".") || t.includes("e") ? t : t + ".0";
414
+ }
415
+ function Ee(e, t, n) {
416
+ return t === void 0 || t === n ? "" : t === "half" ? "_1" : t === "single" ? "_2" : "_3";
417
+ }
418
+ //#endregion
419
+ //#region src/utils/hexfloat.ts
420
+ var De = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(8));
421
+ function Oe(e) {
422
+ let t = e.startsWith("-"), n = e.slice(t ? 3 : 2), r = n.search(/[pP]/);
423
+ if (r === -1) throw SyntaxError(`EDN parse error: hex float missing 'p' exponent: ${e}`);
424
+ let i = n.slice(0, r), a = n.slice(r + 1);
425
+ if (!/^[+-]?\d+$/.test(a)) throw SyntaxError(`EDN parse error: hex float has invalid or missing exponent: ${e}`);
426
+ let o = parseInt(a, 10), s = i.indexOf("."), c;
427
+ if (s === -1) {
428
+ if (!/^[0-9a-fA-F]+$/.test(i)) throw SyntaxError(`EDN parse error: hex float has no mantissa digits: ${e}`);
429
+ c = parseInt(i, 16);
430
+ } else {
431
+ let t = i.slice(0, s), n = i.slice(s + 1);
432
+ if (t === "" && n === "") throw SyntaxError(`EDN parse error: hex float has no mantissa digits: ${e}`);
433
+ 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}`);
434
+ c = (t === "" ? 0 : parseInt(t, 16)) + (n === "" ? 0 : parseInt(n, 16) / 16 ** n.length);
435
+ }
436
+ let l = c * 2 ** o;
437
+ return t ? -l : l;
438
+ }
439
+ function ke(e) {
440
+ if (isNaN(e)) return "NaN";
441
+ if (!isFinite(e)) return e > 0 ? "Infinity" : "-Infinity";
442
+ let t = Object.is(e, -0) || e < 0, n = Math.abs(e);
443
+ if (n === 0) return t ? "-0x0p+0" : "0x0p+0";
444
+ De.setFloat64(0, n, !1);
445
+ let r = De.getUint32(0, !1), i = De.getUint32(4, !1), a = r >>> 20 & 2047, o = r & 1048575, s = i, c = (o.toString(16).padStart(5, "0") + s.toString(16).padStart(8, "0")).replace(/0+$/, ""), l = c === "" ? "" : `.${c}`, u, d;
446
+ a === 0 ? (u = "0", d = -1022) : (u = "1", d = a - 1023);
447
+ let f = d >= 0 ? `+${d}` : `${d}`, p = `0x${u}${l}p${f}`;
448
+ return t ? `-${p}` : p;
449
+ }
450
+ //#endregion
451
+ //#region src/ast/CborFloat.ts
452
+ var S = class extends d {
453
+ value;
454
+ precision;
455
+ constructor(e, t) {
456
+ super(), this.value = e, this.precision = t?.precision;
457
+ }
458
+ _toCBOR(e) {
459
+ let t = this.precision ?? oe(this.value);
460
+ if (t === "half") {
461
+ let e = new Uint8Array(3);
462
+ return e[0] = 249, ne(new DataView(e.buffer), 1, this.value, !1), e;
463
+ }
464
+ if (t === "single") {
465
+ let e = new Uint8Array(5);
466
+ return e[0] = 250, new DataView(e.buffer).setFloat32(1, this.value, !1), e;
467
+ }
468
+ let n = new Uint8Array(9);
469
+ return n[0] = 251, new DataView(n.buffer).setFloat64(1, this.value, !1), n;
470
+ }
471
+ _toEDN(e, t) {
472
+ let n = oe(this.value);
473
+ return (e?.floatFormat === "hex" ? ke(this.value) : Te(this.value)) + Ee(this.value, this.precision, n);
474
+ }
475
+ _toJS(e) {
476
+ return this.value;
477
+ }
478
+ }, C = class extends d {
479
+ tag;
480
+ content;
481
+ encodingWidth;
482
+ constructor(e, t, n) {
483
+ if (super(), this.tag = BigInt(e), this.tag < 0n) throw RangeError("CborTag tag number must be non-negative");
484
+ this.content = t, this.encodingWidth = n?.encodingWidth;
485
+ }
486
+ _toCBOR(e) {
487
+ return h([m(6, this.tag, this.encodingWidth), this.content._toCBOR(e)]);
488
+ }
489
+ _toEDN(e, t) {
490
+ let n = this.encodingWidth === void 0 ? "" : `_${this.encodingWidth}`;
491
+ return `${this.tag}${n}(${this.content._toEDN(e, t)})`;
492
+ }
493
+ _toHexDump(e, t) {
494
+ let n = [{
495
+ depth: e,
496
+ hex: ((e) => Array.from(e, (e) => e.toString(16).toUpperCase().padStart(2, "0")).join(" "))(m(6, this.tag, this.encodingWidth)),
497
+ comment: `Tag ${this.tag}`
498
+ }];
499
+ return n.push(...this.content._toHexDump(e + 1, t)), n;
500
+ }
501
+ _toJS(e) {
502
+ let t = this.content._toJS(e);
503
+ return e?.stripTags ? t : c.set(t, this.tag);
504
+ }
505
+ };
506
+ //#endregion
507
+ //#region src/edn/tokenizer.ts
508
+ function Ae(e, t) {
509
+ let n = 1, r = 1;
510
+ for (let i = 0; i < t; i++) e[i] === "\n" ? (n++, r = 1) : r++;
511
+ return {
512
+ line: n,
513
+ col: r
514
+ };
515
+ }
516
+ var je = class {
517
+ input;
518
+ pos;
519
+ line;
520
+ col;
521
+ _peeked = null;
522
+ _lastConsumedEndOffset;
523
+ comments = [];
524
+ constructor(e, t) {
525
+ this.input = e;
526
+ let n = t?.offset ?? 0;
527
+ if (!Number.isInteger(n) || n < 0 || n > e.length) throw RangeError(`EDN parse offset must be an integer between 0 and ${e.length}`);
528
+ let r = Ae(e, n);
529
+ this.pos = n, this.line = r.line, this.col = r.col, this._lastConsumedEndOffset = n;
530
+ }
531
+ peek() {
532
+ return this._peeked === null && (this._peeked = this._readNext()), this._peeked;
533
+ }
534
+ consume() {
535
+ let e = this._peeked === null ? this._readNext() : this._peeked;
536
+ return this._peeked = null, this._lastConsumedEndOffset = e.endOffset, e;
537
+ }
538
+ get lastEndOffset() {
539
+ return this._lastConsumedEndOffset;
540
+ }
541
+ _ch() {
542
+ return this.input[this.pos] ?? "";
543
+ }
544
+ _eof() {
545
+ return this.pos >= this.input.length;
546
+ }
547
+ _advance() {
548
+ let e = this.input[this.pos++] ?? "";
549
+ return e === "\n" ? (this.line++, this.col = 1) : this.col++, e;
550
+ }
551
+ _fail(e, t = this.line, n = this.col) {
552
+ throw SyntaxError(`EDN parse error at line ${t}, column ${n}: ${e}`);
553
+ }
554
+ _skipWS() {
555
+ for (;;) {
556
+ for (; !this._eof() && /\s/.test(this._ch());) this._advance();
557
+ if (this._eof()) return;
558
+ let e = this._ch();
559
+ if (e === "#") {
560
+ let e = this.pos, t = this.line, n = this.col;
561
+ for (; !this._eof() && this._ch() !== "\n";) this._advance();
562
+ this.comments.push({
563
+ kind: "line",
564
+ marker: "#",
565
+ text: this.input.slice(e, this.pos),
566
+ start: e,
567
+ end: this.pos,
568
+ line: t,
569
+ col: n
570
+ });
571
+ continue;
572
+ }
573
+ if (e === "/") {
574
+ let e = this.input[this.pos + 1] ?? "";
575
+ if (e === "/") {
576
+ let e = this.pos, t = this.line, n = this.col;
577
+ for (this._advance(), this._advance(); !this._eof() && this._ch() !== "\n";) this._advance();
578
+ this.comments.push({
579
+ kind: "line",
580
+ marker: "//",
581
+ text: this.input.slice(e, this.pos),
582
+ start: e,
583
+ end: this.pos,
584
+ line: t,
585
+ col: n
586
+ });
587
+ continue;
588
+ }
589
+ if (e === "*") {
590
+ let e = this.pos, t = this.line, n = this.col;
591
+ this._advance(), this._advance(), this._skipBlockCommentStar(), this.comments.push({
592
+ kind: "block",
593
+ marker: "/*",
594
+ text: this.input.slice(e, this.pos),
595
+ start: e,
596
+ end: this.pos,
597
+ line: t,
598
+ col: n
599
+ });
600
+ continue;
601
+ }
602
+ let t = this.pos, n = this.line, r = this.col;
603
+ this._advance(), this._skipBlockCommentSlash(), this.comments.push({
604
+ kind: "block",
605
+ marker: "/",
606
+ text: this.input.slice(t, this.pos),
607
+ start: t,
608
+ end: this.pos,
609
+ line: n,
610
+ col: r
611
+ });
612
+ continue;
613
+ }
614
+ return;
615
+ }
616
+ }
617
+ _skipByteStringComment(e) {
618
+ let t = this._ch();
619
+ if (t === "/") {
620
+ let t = this.input[this.pos + 1] ?? "";
621
+ if (t === "/") {
622
+ for (this._advance(), this._advance(); !this._eof() && this._ch() !== "\n";) {
623
+ if (this._ch() === "\\") {
624
+ this._advance(), !this._eof() && this._ch() !== "\n" && this._advance();
625
+ continue;
626
+ }
627
+ if (this._ch() === e) break;
628
+ this._advance();
629
+ }
630
+ return !0;
631
+ }
632
+ return t === "*" ? (this._advance(), this._advance(), this._skipBlockCommentStar(), !0) : (this._advance(), this._skipBlockCommentSlash(), !0);
633
+ }
634
+ if (t === "#") {
635
+ for (; !this._eof() && this._ch() !== "\n";) {
636
+ if (this._ch() === "\\") {
637
+ this._advance(), !this._eof() && this._ch() !== "\n" && this._advance();
638
+ continue;
639
+ }
640
+ if (this._ch() === e) break;
641
+ this._advance();
642
+ }
643
+ return !0;
644
+ }
645
+ return !1;
646
+ }
647
+ _skipRawComment(e, t, n, r, i) {
648
+ let a = e[t];
649
+ if (a === "/") {
650
+ if (t++, e[t] === "/") {
651
+ for (t++; t < e.length && e[t] !== "\n";) t++;
652
+ return t;
653
+ }
654
+ if (e[t] === "*") {
655
+ for (t++; t < e.length;) {
656
+ if (e[t] === "*" && e[t + 1] === "/") return t + 2;
657
+ t++;
658
+ }
659
+ return t;
660
+ }
661
+ for (; t < e.length && e[t] !== "/";) t++;
662
+ if (t >= e.length) throw SyntaxError(`EDN parse error at line ${r}, column ${i}: unterminated block comment in ${n}`);
663
+ return t + 1;
664
+ }
665
+ if (a === "#") {
666
+ for (; t < e.length && e[t] !== "\n";) t++;
667
+ return t;
668
+ }
669
+ return -1;
670
+ }
671
+ _skipBlockCommentSlash() {
672
+ let e = this.line, t = this.col;
673
+ for (; !this._eof();) {
674
+ if (this._ch() === "\\") {
675
+ this._advance(), this._eof() || this._advance();
676
+ continue;
677
+ }
678
+ if (this._ch() === "/") break;
679
+ this._advance();
680
+ }
681
+ this._eof() && this._fail("unterminated block comment", e, t), this._advance();
682
+ }
683
+ _skipBlockCommentStar() {
684
+ let e = this.line, t = this.col;
685
+ for (; !this._eof();) {
686
+ if (this._ch() === "*" && (this.input[this.pos + 1] ?? "") === "/") {
687
+ this._advance(), this._advance();
688
+ return;
689
+ }
690
+ this._advance();
691
+ }
692
+ this._fail("unterminated block comment", e, t);
693
+ }
694
+ _readStringContent(e) {
695
+ this._advance();
696
+ let t = "";
697
+ for (; !this._eof() && this._ch() !== e;) {
698
+ let n = this._ch();
699
+ if (n === "\r") {
700
+ this._advance();
701
+ continue;
702
+ }
703
+ let r = n.codePointAt(0);
704
+ if ((r < 32 && r !== 10 || r === 127) && this._fail(`unescaped control character U+${r.toString(16).padStart(4, "0")} is not allowed in string literals`), n === "\\") {
705
+ this._advance();
706
+ let n = this.line, r = this.col, i = this._advance();
707
+ switch (i) {
708
+ case "n":
709
+ t += "\n";
710
+ break;
711
+ case "r":
712
+ t += "\r";
713
+ break;
714
+ case "t":
715
+ t += " ";
716
+ break;
717
+ case "b":
718
+ t += "\b";
719
+ break;
720
+ case "f":
721
+ t += "\f";
722
+ break;
723
+ case "\\":
724
+ t += "\\";
725
+ break;
726
+ case "u":
727
+ t += this._readUnicodeEscape(e);
728
+ break;
729
+ default:
730
+ if (i === e) {
731
+ t += i;
732
+ break;
733
+ }
734
+ if (i === "/") {
735
+ t += "/";
736
+ break;
737
+ }
738
+ this._fail(`invalid escape sequence \\${i} in ${e === "\"" ? "double" : "single"}-quoted string`, n, r);
739
+ }
740
+ } else t += this._advance();
741
+ }
742
+ return this._eof() && this._fail("unterminated string literal"), this._advance(), t;
743
+ }
744
+ _readUnicodeEscape(e) {
745
+ let t = this.line, n = this.col, r = (r) => {
746
+ e === "'" && r >= 32 && r <= 126 && r !== 92 && r !== 39 && this._fail(`\\u escape for printable ASCII U+${r.toString(16).padStart(4, "0")} is not allowed in single-quoted strings; write the character literally`, t, n);
747
+ };
748
+ if (!this._eof() && this._ch() === "{") {
749
+ this._advance();
750
+ let e = "";
751
+ for (; !this._eof() && this._ch() !== "}";) {
752
+ let r = this._ch();
753
+ /[0-9a-fA-F]/.test(r) || this._fail(`invalid character in \\u{} escape: ${JSON.stringify(r)}`, t, n), e += this._advance();
754
+ }
755
+ this._eof() && this._fail("unterminated \\u{} escape", t, n), this._advance(), e.length === 0 && this._fail("empty \\u{} escape", t, n);
756
+ let i = parseInt(e, 16);
757
+ return i > 1114111 && this._fail(`\\u{${e}} exceeds maximum Unicode code point U+10FFFF`, t, n), i >= 55296 && i <= 57343 && this._fail(`\\u{${e}} is a surrogate code point, which is not a valid Unicode scalar value`, t, n), r(i), String.fromCodePoint(i);
758
+ }
759
+ let i = "";
760
+ for (let e = 0; e < 4; e++) {
761
+ this._eof() && this._fail("truncated \\uXXXX escape", t, n);
762
+ let e = this._ch();
763
+ /[0-9a-fA-F]/.test(e) || this._fail(`invalid hex digit in \\uXXXX escape: ${JSON.stringify(e)}`, t, n), i += this._advance();
764
+ }
765
+ let a = parseInt(i, 16);
766
+ if (a >= 55296 && a <= 56319) {
767
+ (this._ch() !== "\\" || (this.input[this.pos + 1] ?? "") !== "u") && this._fail(`lone high surrogate \\u${i} must be followed by \\uDC00–\\uDFFF`, t, n), this._advance(), this._advance();
768
+ let e = this.line, r = this.col, o = "";
769
+ for (let t = 0; t < 4; t++) this._eof() && this._fail("truncated low-surrogate escape", e, r), o += this._advance();
770
+ let s = parseInt(o, 16);
771
+ return (s < 56320 || s > 57343) && this._fail(`\\u${i} (high surrogate) not followed by a valid low surrogate (got \\u${o})`, t, n), String.fromCodePoint(65536 + (a - 55296) * 1024 + (s - 56320));
772
+ }
773
+ return a >= 56320 && a <= 57343 && this._fail(`lone low surrogate \\u${i} is not valid`, t, n), r(a), String.fromCharCode(a);
774
+ }
775
+ _readRawStringContent() {
776
+ let e = this.line, t = this.col, n = 0;
777
+ for (; !this._eof() && this._ch() === "`";) this._advance(), n++;
778
+ !this._eof() && this._ch() === "\r" && this._advance(), !this._eof() && this._ch() === "\n" && this._advance();
779
+ let r = "";
780
+ for (; !this._eof();) {
781
+ let i = this._ch();
782
+ if (i === "\r") {
783
+ this._advance();
784
+ continue;
785
+ }
786
+ if (i === "`") {
787
+ let i = 0;
788
+ for (; !this._eof() && this._ch() === "`";) this._advance(), i++;
789
+ if (i >= n) return r += "`".repeat(i - n), r === "" && this._fail("raw string must not be empty (§2.5.3)", e, t), r;
790
+ r += "`".repeat(i);
791
+ } else {
792
+ let e = i.codePointAt(0);
793
+ e < 32 && e !== 10 && e !== 13 && this._fail(`raw string content must not contain control character U+${e.toString(16).toUpperCase().padStart(4, "0")} (§2.5.3)`, this.line, this.col), e === 127 && this._fail("raw string content must not contain DEL (U+007F) (§2.5.3)", this.line, this.col), r += this._advance();
794
+ }
795
+ }
796
+ this._fail("unterminated raw string literal", e, t);
797
+ }
798
+ _processRawHexContent(e, t, n) {
799
+ let r = "", i = !1, a = 0;
800
+ for (; a < e.length;) {
801
+ let o = e[a];
802
+ if (o === "\n" || o === " " || o === "\r") {
803
+ a++;
804
+ continue;
805
+ }
806
+ if (o === " ") throw SyntaxError(`EDN parse error at line ${t}, column ${n}: horizontal tab (HT) is not allowed inside h\`\` raw byte string literals (§5.3.3)`);
807
+ let s = this._skipRawComment(e, a, "h`` raw byte string", t, n);
808
+ if (s !== -1) {
809
+ a = s;
810
+ continue;
811
+ }
812
+ if (o === "." && e[a + 1] === "." && e[a + 2] === ".") {
813
+ for (a += 3; a < e.length && e[a] === ".";) a++;
814
+ r += "...", i = !0;
815
+ continue;
816
+ }
817
+ if (/[0-9a-fA-F]/.test(o)) {
818
+ r += o, a++;
819
+ continue;
820
+ }
821
+ throw SyntaxError(`EDN parse error at line ${t}, column ${n}: unexpected character ${JSON.stringify(o)} in h\`\` raw byte string`);
822
+ }
823
+ return {
824
+ value: r,
825
+ elided: i
826
+ };
827
+ }
828
+ _processRawB64Content(e, t, n) {
829
+ let r = "", i = 0;
830
+ for (; i < e.length;) {
831
+ let a = e[i];
832
+ if (a === "\n" || a === " " || a === "\r") {
833
+ i++;
834
+ continue;
835
+ }
836
+ if (a === " ") throw SyntaxError(`EDN parse error at line ${t}, column ${n}: horizontal tab (HT) is not allowed inside b64\`\` raw byte string literals (§5.3.4)`);
837
+ if (a === "#") {
838
+ for (; i < e.length && e[i] !== "\n";) i++;
839
+ continue;
840
+ }
841
+ r += a, i++;
842
+ }
843
+ return r;
844
+ }
845
+ _processRawB32Content(e, t, n) {
846
+ let r = "", i = 0;
847
+ for (; i < e.length;) {
848
+ let a = e[i];
849
+ if (a === "\n" || a === " " || a === "\r") {
850
+ i++;
851
+ continue;
852
+ }
853
+ if (a === " ") throw SyntaxError(`EDN parse error at line ${t}, column ${n}: horizontal tab (HT) is not allowed inside b32\`\`/h32\`\` raw byte string literals (§5.2)`);
854
+ let o = this._skipRawComment(e, i, "b32``/h32`` raw byte string", t, n);
855
+ if (o !== -1) {
856
+ i = o;
857
+ continue;
858
+ }
859
+ r += a, i++;
860
+ }
861
+ return r;
862
+ }
863
+ _readByteContent(e) {
864
+ this._advance();
865
+ let t = "";
866
+ for (; !this._eof() && this._ch() !== e;) {
867
+ let n = this._ch();
868
+ if (n === "\n" || n === " ") {
869
+ this._advance();
870
+ continue;
871
+ }
872
+ if (n === "\r") {
873
+ this._advance();
874
+ continue;
875
+ }
876
+ if (n === " " && this._fail("horizontal tab (HT) is not allowed inside byte string literals (§5.2.2)", this.line, this.col), n === "#") {
877
+ for (; !this._eof() && this._ch() !== "\n";) {
878
+ if (this._ch() === "\\") {
879
+ this._advance(), !this._eof() && this._ch() !== "\n" && this._advance();
880
+ continue;
881
+ }
882
+ if (this._ch() === e) break;
883
+ this._advance();
884
+ }
885
+ continue;
886
+ }
887
+ t += this._advance();
888
+ }
889
+ return this._eof() && this._fail("unterminated byte string literal"), this._advance(), t;
890
+ }
891
+ _readB32Content(e) {
892
+ this._advance();
893
+ let t = "";
894
+ for (; !this._eof() && this._ch() !== e;) {
895
+ let n = this._ch();
896
+ if (n === "\n" || n === " " || n === "\r") {
897
+ this._advance();
898
+ continue;
899
+ }
900
+ n === " " && this._fail("horizontal tab (HT) is not allowed inside byte string literals (§5.2)", this.line, this.col), !this._skipByteStringComment(e) && (t += this._advance());
901
+ }
902
+ return this._eof() && this._fail("unterminated byte string literal"), this._advance(), t;
903
+ }
904
+ _readHexByteContentElisionAware(e) {
905
+ this._advance();
906
+ let t = "", n = !1;
907
+ for (; !this._eof() && this._ch() !== e;) {
908
+ let r = this._ch();
909
+ if (r === "\n" || r === " " || r === "\r") {
910
+ this._advance();
911
+ continue;
912
+ }
913
+ if (r === " " && this._fail("horizontal tab (HT) is not allowed inside hex byte string literals (§5.2.1)", this.line, this.col), !this._skipByteStringComment(e)) {
914
+ if (r === "." && (this.input[this.pos + 1] ?? "") === "." && (this.input[this.pos + 2] ?? "") === ".") {
915
+ for (this._advance(), this._advance(), this._advance(); !this._eof() && this._ch() === ".";) this._advance();
916
+ t.endsWith("...") || (t += "..."), n = !0;
917
+ continue;
918
+ }
919
+ if (/[0-9a-fA-F]/.test(r)) {
920
+ t += this._advance();
921
+ continue;
922
+ }
923
+ this._fail(`unexpected character ${JSON.stringify(r)} in hex byte string`);
924
+ }
925
+ }
926
+ return this._eof() && this._fail("unterminated hex byte string literal"), this._advance(), {
927
+ value: t,
928
+ elided: n
929
+ };
930
+ }
931
+ _readNext() {
932
+ this._skipWS();
933
+ let e = this.pos;
934
+ return {
935
+ ...this._readNextCore(),
936
+ raw: this.input.slice(e, this.pos),
937
+ offset: e,
938
+ endOffset: this.pos
939
+ };
940
+ }
941
+ _readNextCore() {
942
+ let e = this.line, t = this.col;
943
+ if (this._eof()) return {
944
+ type: "EOF",
945
+ value: "",
946
+ line: e,
947
+ col: t
948
+ };
949
+ let n = this._ch();
950
+ switch (n) {
951
+ case "[": return this._advance(), {
952
+ type: "LBRACKET",
953
+ value: "[",
954
+ line: e,
955
+ col: t
956
+ };
957
+ case "]": return this._advance(), {
958
+ type: "RBRACKET",
959
+ value: "]",
960
+ line: e,
961
+ col: t
962
+ };
963
+ case "{": return this._advance(), {
964
+ type: "LBRACE",
965
+ value: "{",
966
+ line: e,
967
+ col: t
968
+ };
969
+ case "}": return this._advance(), {
970
+ type: "RBRACE",
971
+ value: "}",
972
+ line: e,
973
+ col: t
974
+ };
975
+ case "(": return this._advance(), {
976
+ type: "LPAREN",
977
+ value: "(",
978
+ line: e,
979
+ col: t
980
+ };
981
+ case ")": return this._advance(), {
982
+ type: "RPAREN",
983
+ value: ")",
984
+ line: e,
985
+ col: t
986
+ };
987
+ case ":": return this._advance(), {
988
+ type: "COLON",
989
+ value: ":",
990
+ line: e,
991
+ col: t
992
+ };
993
+ case ",": return this._advance(), {
994
+ type: "COMMA",
995
+ value: ",",
996
+ line: e,
997
+ col: t
998
+ };
999
+ case "<":
1000
+ if ((this.input[this.pos + 1] ?? "") === "<") return this._advance(), this._advance(), {
1001
+ type: "LT_LT",
1002
+ value: "<<",
1003
+ line: e,
1004
+ col: t
1005
+ };
1006
+ this._fail("unexpected character '<'", e, t);
1007
+ case ">":
1008
+ if ((this.input[this.pos + 1] ?? "") === ">") return this._advance(), this._advance(), {
1009
+ type: "GT_GT",
1010
+ value: ">>",
1011
+ line: e,
1012
+ col: t
1013
+ };
1014
+ this._fail("unexpected character '>'", e, t);
1015
+ case "+": {
1016
+ let n = this.input.slice(this.pos + 1);
1017
+ if (n.startsWith("Infinity")) {
1018
+ let r = n[8] ?? "", i = r === "_" && /[0-3i]/.test(n[9] ?? "") && !/[a-zA-Z0-9_]/.test(n[10] ?? "");
1019
+ if (!/[a-zA-Z0-9_]/.test(r) || i) {
1020
+ this._advance();
1021
+ for (let e = 0; e < 8; e++) this._advance();
1022
+ let n = "Infinity";
1023
+ return i && (n += this._advance() + this._advance()), {
1024
+ type: "FLOAT",
1025
+ value: n,
1026
+ line: e,
1027
+ col: t
1028
+ };
1029
+ }
1030
+ }
1031
+ let r = n[0] ?? "";
1032
+ return r >= "0" && r <= "9" || r === "." ? (this._advance(), this._readNumber(e, t)) : (this._advance(), {
1033
+ type: "PLUS",
1034
+ value: "+",
1035
+ line: e,
1036
+ col: t
1037
+ });
1038
+ }
1039
+ case "`": return {
1040
+ type: "RAWSTRING",
1041
+ value: this._readRawStringContent(),
1042
+ line: e,
1043
+ col: t
1044
+ };
1045
+ case "\"": {
1046
+ let n = this._readStringContent("\"");
1047
+ return n === "" && this._ch() === "_" ? (this._advance(), {
1048
+ type: "EMPTY_INDEF_TEXT",
1049
+ value: "",
1050
+ line: e,
1051
+ col: t
1052
+ }) : {
1053
+ type: "TSTR",
1054
+ value: n,
1055
+ line: e,
1056
+ col: t
1057
+ };
1058
+ }
1059
+ case "'": {
1060
+ if ((this.input[this.pos + 1] ?? "") === "'" && (this.input[this.pos + 2] ?? "") === "_") return this._advance(), this._advance(), this._advance(), {
1061
+ type: "EMPTY_INDEF_BYTES",
1062
+ value: "",
1063
+ line: e,
1064
+ col: t
1065
+ };
1066
+ let n = this._readStringContent("'"), r = new TextEncoder().encode(n);
1067
+ return {
1068
+ type: "SQSTR",
1069
+ value: Array.from(r, (e) => e.toString(16).padStart(2, "0")).join(""),
1070
+ line: e,
1071
+ col: t
1072
+ };
1073
+ }
1074
+ }
1075
+ if (n === "-") {
1076
+ let n = this.input.slice(this.pos + 1);
1077
+ if (n.startsWith("Infinity")) {
1078
+ let r = n[8] ?? "", i = r === "_" && /[0-3i]/.test(n[9] ?? "") && !/[a-zA-Z0-9_]/.test(n[10] ?? "");
1079
+ if (!/[a-zA-Z0-9_]/.test(r) || i) {
1080
+ this._advance();
1081
+ for (let e = 0; e < 8; e++) this._advance();
1082
+ let n = "-Infinity";
1083
+ return i && (n += this._advance() + this._advance()), {
1084
+ type: "FLOAT",
1085
+ value: n,
1086
+ line: e,
1087
+ col: t
1088
+ };
1089
+ }
1090
+ }
1091
+ return this._readNumber(e, t);
1092
+ }
1093
+ if (n === "+") {
1094
+ let n = this.input.slice(this.pos + 1);
1095
+ if (n.startsWith("Infinity")) {
1096
+ let r = n[8] ?? "", i = r === "_" && /[0-3i]/.test(n[9] ?? "") && !/[a-zA-Z0-9_]/.test(n[10] ?? "");
1097
+ if (!/[a-zA-Z0-9_]/.test(r) || i) {
1098
+ this._advance();
1099
+ for (let e = 0; e < 8; e++) this._advance();
1100
+ let n = "Infinity";
1101
+ return i && (n += this._advance() + this._advance()), {
1102
+ type: "FLOAT",
1103
+ value: n,
1104
+ line: e,
1105
+ col: t
1106
+ };
1107
+ }
1108
+ }
1109
+ return this._advance(), this._readNumber(e, t);
1110
+ }
1111
+ if (n >= "0" && n <= "9" || n === "." && /[0-9]/.test(this.input[this.pos + 1] ?? "")) return this._readNumber(e, t);
1112
+ if (/[a-zA-Z_]/.test(n)) return this._readIdent(e, t);
1113
+ if (n === ".") {
1114
+ if ((this.input[this.pos + 1] ?? "") === "." && (this.input[this.pos + 2] ?? "") === ".") {
1115
+ for (this._advance(), this._advance(), this._advance(); !this._eof() && this._ch() === ".";) this._advance();
1116
+ return {
1117
+ type: "ELLIPSIS",
1118
+ value: "...",
1119
+ line: e,
1120
+ col: t
1121
+ };
1122
+ }
1123
+ this._fail("unexpected character '.'", e, t);
1124
+ }
1125
+ this._fail(`unexpected character ${JSON.stringify(n)}`, e, t);
1126
+ }
1127
+ _readNumber(e, t) {
1128
+ let n = "";
1129
+ if (this._ch() === "-" && (n += this._advance()), this._ch() === "0") {
1130
+ let r = this.input[this.pos + 1] ?? "";
1131
+ if (r === "x" || r === "X") {
1132
+ n += this._advance() + this._advance();
1133
+ let r = n.length;
1134
+ for (; !this._eof() && /[0-9a-fA-F]/.test(this._ch());) n += this._advance();
1135
+ let i = n.length > r, a = !1, o = !1;
1136
+ if (!this._eof() && this._ch() === ".") {
1137
+ a = !0, n += this._advance();
1138
+ let e = n.length;
1139
+ for (; !this._eof() && /[0-9a-fA-F]/.test(this._ch());) n += this._advance();
1140
+ o = n.length > e;
1141
+ }
1142
+ if (!this._eof() && (this._ch() === "p" || this._ch() === "P")) {
1143
+ a = !0, !i && !o && this._fail(`hex float has no mantissa digits: ${n}`, e, t), n += this._advance(), !this._eof() && (this._ch() === "+" || this._ch() === "-") && (n += this._advance());
1144
+ let r = n.length;
1145
+ for (; !this._eof() && this._ch() >= "0" && this._ch() <= "9";) n += this._advance();
1146
+ n.length === r && this._fail(`hex float missing exponent digits: ${n}`, e, t);
1147
+ } else a && this._fail(`hex float missing 'p' exponent: ${n}`, e, t);
1148
+ if (a) {
1149
+ if (this._ch() === "_") {
1150
+ let e = this.input[this.pos + 1] ?? "", t = this.input[this.pos + 2] ?? "";
1151
+ (e === "0" || e === "1" || e === "2" || e === "3" || e === "i") && !/[0-9a-zA-Z_]/.test(t) && (n += this._advance() + this._advance());
1152
+ }
1153
+ return {
1154
+ type: "FLOAT",
1155
+ value: n,
1156
+ line: e,
1157
+ col: t
1158
+ };
1159
+ }
1160
+ return {
1161
+ type: "INTEGER",
1162
+ value: n,
1163
+ line: e,
1164
+ col: t
1165
+ };
1166
+ }
1167
+ if (r === "o" || r === "O") {
1168
+ for (n += this._advance() + this._advance(); !this._eof() && this._ch() >= "0" && this._ch() <= "7";) n += this._advance();
1169
+ return {
1170
+ type: "INTEGER",
1171
+ value: n,
1172
+ line: e,
1173
+ col: t
1174
+ };
1175
+ }
1176
+ if (r === "b" || r === "B") {
1177
+ for (n += this._advance() + this._advance(); !this._eof() && (this._ch() === "0" || this._ch() === "1");) n += this._advance();
1178
+ return {
1179
+ type: "INTEGER",
1180
+ value: n,
1181
+ line: e,
1182
+ col: t
1183
+ };
1184
+ }
1185
+ }
1186
+ for (; !this._eof() && this._ch() >= "0" && this._ch() <= "9";) n += this._advance();
1187
+ let r = !1;
1188
+ if (!this._eof() && this._ch() === ".") for (r = !0, n += this._advance(); !this._eof() && this._ch() >= "0" && this._ch() <= "9";) n += this._advance();
1189
+ if (!this._eof() && (this._ch() === "e" || this._ch() === "E")) {
1190
+ r = !0, n += this._advance(), !this._eof() && (this._ch() === "+" || this._ch() === "-") && (n += this._advance());
1191
+ let i = n.length;
1192
+ for (; !this._eof() && this._ch() >= "0" && this._ch() <= "9";) n += this._advance();
1193
+ n.length === i && this._fail(`float exponent has no digits: ${JSON.stringify(n)}`, e, t);
1194
+ }
1195
+ if (this._ch() === "_") {
1196
+ let e = this.input[this.pos + 1] ?? "", t = this.input[this.pos + 2] ?? "";
1197
+ (e === "0" || e === "1" || e === "2" || e === "3" || e === "i") && !/[0-9a-zA-Z_]/.test(t) && (n += this._advance() + this._advance());
1198
+ }
1199
+ return {
1200
+ type: r ? "FLOAT" : "INTEGER",
1201
+ value: n,
1202
+ line: e,
1203
+ col: t
1204
+ };
1205
+ }
1206
+ _readIdent(e, t) {
1207
+ let n = "";
1208
+ for (; !this._eof() && /[a-zA-Z0-9_]/.test(this._ch());) n += this._advance();
1209
+ switch (n) {
1210
+ case "true": return {
1211
+ type: "TRUE",
1212
+ value: n,
1213
+ line: e,
1214
+ col: t
1215
+ };
1216
+ case "false": return {
1217
+ type: "FALSE",
1218
+ value: n,
1219
+ line: e,
1220
+ col: t
1221
+ };
1222
+ case "null": return {
1223
+ type: "NULL",
1224
+ value: n,
1225
+ line: e,
1226
+ col: t
1227
+ };
1228
+ case "undefined": return {
1229
+ type: "UNDEFINED",
1230
+ value: n,
1231
+ line: e,
1232
+ col: t
1233
+ };
1234
+ case "NaN":
1235
+ case "NaN_0":
1236
+ case "NaN_1":
1237
+ case "NaN_2":
1238
+ case "NaN_3":
1239
+ case "NaN_i":
1240
+ case "Infinity":
1241
+ case "Infinity_0":
1242
+ case "Infinity_1":
1243
+ case "Infinity_2":
1244
+ case "Infinity_3":
1245
+ case "Infinity_i": return {
1246
+ type: "FLOAT",
1247
+ value: n,
1248
+ line: e,
1249
+ col: t
1250
+ };
1251
+ case "simple": return {
1252
+ type: "SIMPLE",
1253
+ value: n,
1254
+ line: e,
1255
+ col: t
1256
+ };
1257
+ case "_": return {
1258
+ type: "UNDERSCORE",
1259
+ value: "_",
1260
+ line: e,
1261
+ col: t
1262
+ };
1263
+ case "_0": return {
1264
+ type: "ENCODING_INDICATOR",
1265
+ value: "0",
1266
+ line: e,
1267
+ col: t
1268
+ };
1269
+ case "_1": return {
1270
+ type: "ENCODING_INDICATOR",
1271
+ value: "1",
1272
+ line: e,
1273
+ col: t
1274
+ };
1275
+ case "_2": return {
1276
+ type: "ENCODING_INDICATOR",
1277
+ value: "2",
1278
+ line: e,
1279
+ col: t
1280
+ };
1281
+ case "_3": return {
1282
+ type: "ENCODING_INDICATOR",
1283
+ value: "3",
1284
+ line: e,
1285
+ col: t
1286
+ };
1287
+ case "_i": return {
1288
+ type: "ENCODING_INDICATOR",
1289
+ value: "i",
1290
+ line: e,
1291
+ col: t
1292
+ };
1293
+ }
1294
+ let r = n[0] ?? "", i = r >= "a" && r <= "z";
1295
+ if (i || r >= "A" && r <= "Z") {
1296
+ let r = n.slice(1);
1297
+ if (i ? /^[a-z0-9]*$/.test(r) : /^[A-Z0-9]*$/.test(r)) {
1298
+ for (; !this._eof();) {
1299
+ let e = this._ch();
1300
+ if (!(i ? e >= "a" && e <= "z" || e >= "0" && e <= "9" || e === "-" : e >= "A" && e <= "Z" || e >= "0" && e <= "9" || e === "-")) break;
1301
+ n += this._advance();
1302
+ }
1303
+ let r = this._ch();
1304
+ if (r === "\"" && this._fail(`"${n}" prefix requires single quotes or backticks, not double quotes`, e, t), r === "'") switch (n) {
1305
+ case "h": {
1306
+ let { value: n, elided: i } = this._readHexByteContentElisionAware(r);
1307
+ return {
1308
+ type: i ? "BYTES_HEX_ELIDED" : "BYTES_HEX",
1309
+ value: n,
1310
+ line: e,
1311
+ col: t
1312
+ };
1313
+ }
1314
+ case "b64": return {
1315
+ type: "BYTES_B64",
1316
+ value: this._readByteContent(r),
1317
+ line: e,
1318
+ col: t
1319
+ };
1320
+ case "b32": return {
1321
+ type: "BYTES_B32",
1322
+ value: this._readB32Content(r),
1323
+ line: e,
1324
+ col: t
1325
+ };
1326
+ case "h32": return {
1327
+ type: "BYTES_H32",
1328
+ value: this._readB32Content(r),
1329
+ line: e,
1330
+ col: t
1331
+ };
1332
+ default: return {
1333
+ type: "APP_STRING",
1334
+ appPrefix: n,
1335
+ value: this._readStringContent(r),
1336
+ line: e,
1337
+ col: t
1338
+ };
1339
+ }
1340
+ if (r === "`") {
1341
+ let r = this._readRawStringContent();
1342
+ switch (n) {
1343
+ case "h": {
1344
+ let { value: n, elided: i } = this._processRawHexContent(r, e, t);
1345
+ return {
1346
+ type: i ? "BYTES_HEX_ELIDED" : "BYTES_HEX",
1347
+ value: n,
1348
+ line: e,
1349
+ col: t
1350
+ };
1351
+ }
1352
+ case "b64": return {
1353
+ type: "BYTES_B64",
1354
+ value: this._processRawB64Content(r, e, t),
1355
+ line: e,
1356
+ col: t
1357
+ };
1358
+ case "b32": return {
1359
+ type: "BYTES_B32",
1360
+ value: this._processRawB32Content(r, e, t),
1361
+ line: e,
1362
+ col: t
1363
+ };
1364
+ case "h32": return {
1365
+ type: "BYTES_H32",
1366
+ value: this._processRawB32Content(r, e, t),
1367
+ line: e,
1368
+ col: t
1369
+ };
1370
+ default: return {
1371
+ type: "APP_STRING",
1372
+ appPrefix: n,
1373
+ value: r,
1374
+ line: e,
1375
+ col: t
1376
+ };
1377
+ }
1378
+ }
1379
+ if (r === "<" && (this.input[this.pos + 1] ?? "") === "<") return this._advance(), this._advance(), {
1380
+ type: "APP_SEQUENCE",
1381
+ appPrefix: n,
1382
+ value: "",
1383
+ line: e,
1384
+ col: t
1385
+ };
1386
+ }
1387
+ }
1388
+ this._fail(`unknown identifier ${JSON.stringify(n)}`, e, t);
1389
+ }
1390
+ }, w = class extends d {
1391
+ indefiniteLength = !1;
1392
+ value;
1393
+ ednEncoding;
1394
+ encodingWidth;
1395
+ ednSource;
1396
+ constructor(e, t) {
1397
+ super(), this.value = e, this.ednEncoding = t?.ednEncoding ?? "hex", this.encodingWidth = t?.encodingWidth, this.ednSource = t?.ednSource;
1398
+ }
1399
+ _toCBOR(e) {
1400
+ return h([m(2, BigInt(this.value.length), this.encodingWidth), this.value]);
1401
+ }
1402
+ _toEDN(e, t) {
1403
+ let n = this.encodingWidth === void 0 ? "" : `_${this.encodingWidth}`;
1404
+ if (e?.preserveByteString && this.ednSource !== void 0) return this.ednSource + n;
1405
+ let r = e?.bstrEncoding ?? this.ednEncoding;
1406
+ return ye(this.value, r, e?.sqstr) + n;
1407
+ }
1408
+ _toJS(e) {
1409
+ return this.value;
1410
+ }
1411
+ }, T = class extends d {
1412
+ indefiniteLength = !0;
1413
+ chunks;
1414
+ constructor(e) {
1415
+ super(), this.chunks = e;
1416
+ }
1417
+ _toCBOR(e) {
1418
+ let t = [new Uint8Array([95])];
1419
+ for (let n of this.chunks) t.push(n._toCBOR(e));
1420
+ return t.push(new Uint8Array([255])), h(t);
1421
+ }
1422
+ _toEDN(e, t) {
1423
+ return this.chunks.length === 0 ? "''_" : `(_ ${this.chunks.map((t) => t._toEDN(e, 0)).join(", ")})`;
1424
+ }
1425
+ _toHexDump(e, t) {
1426
+ let n = (e) => e.toString(16).toUpperCase().padStart(2, "0"), r = [{
1427
+ depth: e,
1428
+ hex: n(95),
1429
+ comment: "Start indefinite-length byte string"
1430
+ }];
1431
+ for (let n of this.chunks) r.push(...n._toHexDump(e + 1, t));
1432
+ return r.push({
1433
+ depth: e,
1434
+ hex: n(255),
1435
+ comment: "\"break\""
1436
+ }), r;
1437
+ }
1438
+ _toJS(e) {
1439
+ let t = this.chunks.reduce((e, t) => e + t.value.length, 0), n = new Uint8Array(t), r = 0;
1440
+ for (let e of this.chunks) n.set(e.value, r), r += e.value.length;
1441
+ return n;
1442
+ }
1443
+ }, E = class extends d {
1444
+ indefiniteLength = !0;
1445
+ chunks;
1446
+ constructor(e) {
1447
+ super(), this.chunks = e;
1448
+ }
1449
+ _toCBOR(e) {
1450
+ let t = [new Uint8Array([127])];
1451
+ for (let n of this.chunks) t.push(n._toCBOR(e));
1452
+ return t.push(new Uint8Array([255])), h(t);
1453
+ }
1454
+ _toEDN(e, t) {
1455
+ return this.chunks.length === 0 ? "\"\"_" : `(_ ${this.chunks.map((t) => t._toEDN(e, 0)).join(", ")})`;
1456
+ }
1457
+ _toHexDump(e, t) {
1458
+ let n = (e) => e.toString(16).toUpperCase().padStart(2, "0"), r = [{
1459
+ depth: e,
1460
+ hex: n(127),
1461
+ comment: "Start indefinite-length text string"
1462
+ }];
1463
+ for (let n of this.chunks) r.push(...n._toHexDump(e + 1, t));
1464
+ return r.push({
1465
+ depth: e,
1466
+ hex: n(255),
1467
+ comment: "\"break\""
1468
+ }), r;
1469
+ }
1470
+ _toJS(e) {
1471
+ return this.chunks.map((e) => e.value).join("");
1472
+ }
1473
+ }, D = class extends d {
1474
+ items;
1475
+ indefiniteLength;
1476
+ encodingWidth;
1477
+ constructor(e, t) {
1478
+ super(), this.items = e, this.indefiniteLength = t?.indefiniteLength ?? !1, this.encodingWidth = t?.encodingWidth;
1479
+ }
1480
+ _toCBOR(e) {
1481
+ if (this.indefiniteLength) {
1482
+ let t = [new Uint8Array([159])];
1483
+ for (let n of this.items) t.push(n._toCBOR(e));
1484
+ return t.push(new Uint8Array([255])), h(t);
1485
+ }
1486
+ let t = [m(4, BigInt(this.items.length), this.encodingWidth)];
1487
+ for (let n of this.items) t.push(n._toCBOR(e));
1488
+ return h(t);
1489
+ }
1490
+ _toEDN(e, t) {
1491
+ let n = v(e), r = e?.preserveComments, i = r && (se(this) || this.items.some(b));
1492
+ n === null && i && (n = " ");
1493
+ let { inlineSep: a, multilineSep: o, trailSep: s } = x(e, n === null), c = !this.indefiniteLength && this.encodingWidth !== void 0 ? `_${this.encodingWidth} ` : "";
1494
+ if (n === null || this.items.length === 0 && !i) {
1495
+ let n = this.items.map((n) => n._toEDN(e, t + 1)).join(a);
1496
+ return this.indefiniteLength ? this.items.length === 0 ? "[_ ]" : `[_ ${n}]` : `[${c}${n}]`;
1497
+ }
1498
+ let l = y(n, t + 1), u = y(n, t), d = this.indefiniteLength ? "[_ " : `[${c}`, f = [];
1499
+ for (let n = 0; n < this.items.length; n++) {
1500
+ let i = this.items[n];
1501
+ r && f.push(...ce(i, l));
1502
+ let a = n < this.items.length - 1 ? o : s;
1503
+ f.push(`${l}${i._toEDN(e, t + 1)}${a}${r ? le(i) : ""}`);
1504
+ }
1505
+ return r && f.push(...ue(this, l)), `${d}\n${f.join("\n")}\n${u}]`;
1506
+ }
1507
+ _toHexDump(e, t) {
1508
+ let n = (e) => e.toString(16).toUpperCase().padStart(2, "0"), r = (e) => Array.from(e, (e) => e.toString(16).toUpperCase().padStart(2, "0")).join(" ");
1509
+ if (this.indefiniteLength) {
1510
+ let r = [{
1511
+ depth: e,
1512
+ hex: n(159),
1513
+ comment: "Start indefinite-length array"
1514
+ }];
1515
+ for (let n of this.items) r.push(...n._toHexDump(e + 1, t));
1516
+ return r.push({
1517
+ depth: e,
1518
+ hex: n(255),
1519
+ comment: "\"break\""
1520
+ }), r;
1521
+ }
1522
+ let i = [{
1523
+ depth: e,
1524
+ hex: r(m(4, BigInt(this.items.length), this.encodingWidth)),
1525
+ comment: `Array of length ${this.items.length}`
1526
+ }];
1527
+ for (let n of this.items) i.push(...n._toHexDump(e + 1, t));
1528
+ return i;
1529
+ }
1530
+ _toJS(e) {
1531
+ let t = e?.reviver;
1532
+ if (!t) return this.items.map((t) => t._toJS(e));
1533
+ let n = e ? {
1534
+ ...e,
1535
+ reviver: void 0
1536
+ } : void 0, r = this.items.map((e) => e._toJS(n)), i = 0;
1537
+ for (let n = 0; n < this.items.length; n++) {
1538
+ let a = n - i, o = this.items[n]._toJS(e), s = t.call(r, String(n), o);
1539
+ s === l || e?.undefinedOmits && s === void 0 ? (r.splice(a, 1), i++) : r[a] = s;
1540
+ }
1541
+ return r;
1542
+ }
1543
+ }, O = class extends d {
1544
+ entries;
1545
+ indefiniteLength;
1546
+ encodingWidth;
1547
+ constructor(e, t) {
1548
+ super(), this.entries = e, this.indefiniteLength = t?.indefiniteLength ?? !1, this.encodingWidth = t?.encodingWidth;
1549
+ }
1550
+ _toCBOR(e) {
1551
+ if (this.indefiniteLength) {
1552
+ let t = [new Uint8Array([191])];
1553
+ for (let [n, r] of this.entries) t.push(n._toCBOR(e), r._toCBOR(e));
1554
+ return t.push(new Uint8Array([255])), h(t);
1555
+ }
1556
+ let t = [m(5, BigInt(this.entries.length), this.encodingWidth)];
1557
+ for (let [n, r] of this.entries) t.push(n._toCBOR(e), r._toCBOR(e));
1558
+ return h(t);
1559
+ }
1560
+ _toEDN(e, t) {
1561
+ let n = v(e), r = e?.preserveComments, i = r && (se(this) || this.entries.some(([e, t]) => b(e) || b(t)));
1562
+ n === null && i && (n = " ");
1563
+ let { inlineSep: a, multilineSep: o, trailSep: s, colSep: c } = x(e, n === null), l = !this.indefiniteLength && this.encodingWidth !== void 0 ? `_${this.encodingWidth} ` : "", u = this.indefiniteLength ? "{_ " : `{${l}`;
1564
+ if (n === null || this.entries.length === 0 && !i) {
1565
+ let n = this.entries.map(([n, r]) => `${n._toEDN(e, t + 1)}${c}${r._toEDN(e, t + 1)}`).join(a);
1566
+ return this.indefiniteLength ? this.entries.length === 0 ? "{_ }" : `{_ ${n}}` : `{${l}${n}}`;
1567
+ }
1568
+ let d = y(n, t + 1), f = y(n, t), p = [];
1569
+ for (let n = 0; n < this.entries.length; n++) {
1570
+ let [i, a] = this.entries[n];
1571
+ r && p.push(...ce(i, d));
1572
+ let l = n < this.entries.length - 1 ? o : s, u = r ? Me([
1573
+ ...i.comments?.trailing ?? [],
1574
+ ...a.comments?.leading ?? [],
1575
+ ...a.comments?.trailing ?? []
1576
+ ]) : "";
1577
+ p.push(`${d}${i._toEDN(e, t + 1)}${c}${a._toEDN(e, t + 1)}${l}${u}`);
1578
+ }
1579
+ return r && p.push(...ue(this, d)), `${u}\n${p.join("\n")}\n${f}}`;
1580
+ }
1581
+ _toHexDump(e, t) {
1582
+ let n = (e) => e.toString(16).toUpperCase().padStart(2, "0"), r = (e) => Array.from(e, (e) => e.toString(16).toUpperCase().padStart(2, "0")).join(" ");
1583
+ if (this.indefiniteLength) {
1584
+ let r = [{
1585
+ depth: e,
1586
+ hex: n(191),
1587
+ comment: "Start indefinite-length map"
1588
+ }];
1589
+ for (let [n, i] of this.entries) r.push(...n._toHexDump(e + 1, t)), r.push(...i._toHexDump(e + 1, t));
1590
+ return r.push({
1591
+ depth: e,
1592
+ hex: n(255),
1593
+ comment: "\"break\""
1594
+ }), r;
1595
+ }
1596
+ let i = [{
1597
+ depth: e,
1598
+ hex: r(m(5, BigInt(this.entries.length), this.encodingWidth)),
1599
+ comment: `Map of length ${this.entries.length}`
1600
+ }];
1601
+ for (let [n, r] of this.entries) i.push(...n._toHexDump(e + 1, t)), i.push(...r._toHexDump(e + 1, t));
1602
+ return i;
1603
+ }
1604
+ _toJS(e) {
1605
+ let t = e?.reviver, n = () => {
1606
+ let n = $.from(this.entries, ([t, n]) => [t._toJS(e), n._toJS(e)]);
1607
+ if (!t) return n;
1608
+ let r = e?.undefinedOmits;
1609
+ for (let e = 0; e < n.length; e++) {
1610
+ let [i, a] = n[e], o = t.call(n, i, a);
1611
+ o === l || r && o === void 0 ? n.splice(e--, 1) : n[e] = [i, o];
1612
+ }
1613
+ return n;
1614
+ };
1615
+ return e?.mapAs === "entries" ? n() : e?.mapAs === "object" || this.entries.every(([e]) => e instanceof F) ? (() => {
1616
+ let n = e ? {
1617
+ ...e,
1618
+ reviver: void 0
1619
+ } : void 0, r = {};
1620
+ for (let [e, t] of this.entries) {
1621
+ let i = e instanceof F ? e.value : e.toEDN(), a = t._toJS(n);
1622
+ i === "__proto__" ? Object.defineProperty(r, i, {
1623
+ value: a,
1624
+ writable: !0,
1625
+ enumerable: !0,
1626
+ configurable: !0
1627
+ }) : r[i] = a;
1628
+ }
1629
+ if (!t) return r;
1630
+ let i = /* @__PURE__ */ new Map();
1631
+ for (let e = 0; e < this.entries.length; e++) {
1632
+ let [t] = this.entries[e];
1633
+ i.set(t instanceof F ? t.value : t.toEDN(), e);
1634
+ }
1635
+ for (let n = 0; n < this.entries.length; n++) {
1636
+ let [a, o] = this.entries[n], s = a instanceof F ? a.value : a.toEDN();
1637
+ if (i.get(s) !== n) continue;
1638
+ let c = o._toJS(e), u = t.call(r, s, c);
1639
+ u === l || e?.undefinedOmits && u === void 0 ? delete r[s] : s === "__proto__" ? Object.defineProperty(r, s, {
1640
+ value: u,
1641
+ writable: !0,
1642
+ enumerable: !0,
1643
+ configurable: !0
1644
+ }) : r[s] = u;
1645
+ }
1646
+ return r;
1647
+ })() : n();
1648
+ }
1649
+ };
1650
+ function Me(e) {
1651
+ return e.length === 0 ? "" : " " + e.map((e) => e.text.trimEnd()).join(" ");
1652
+ }
1653
+ //#endregion
1654
+ //#region src/ast/CborSimple.ts
1655
+ var k = class e extends d {
1656
+ value;
1657
+ constructor(e) {
1658
+ if (super(), !Number.isInteger(e) || e < 0 || e > 255) throw RangeError("CborSimple value must be an integer in 0–255");
1659
+ this.value = e;
1660
+ }
1661
+ static FALSE = new e(20);
1662
+ static TRUE = new e(21);
1663
+ static NULL = new e(22);
1664
+ static UNDEFINED = new e(23);
1665
+ _toCBOR(e) {
1666
+ return this.value <= 23 ? new Uint8Array([224 | this.value]) : new Uint8Array([248, this.value]);
1667
+ }
1668
+ _toEDN(e, t) {
1669
+ switch (this.value) {
1670
+ case 20: return "false";
1671
+ case 21: return "true";
1672
+ case 22: return "null";
1673
+ case 23: return "undefined";
1674
+ default: return `simple(${this.value})`;
1675
+ }
1676
+ }
1677
+ _toJS(e) {
1678
+ switch (this.value) {
1679
+ case 20: return !1;
1680
+ case 21: return !0;
1681
+ case 22: return null;
1682
+ case 23: return;
1683
+ default: return new u(this.value);
1684
+ }
1685
+ }
1686
+ }, A = class extends d {
1687
+ items;
1688
+ constructor(e) {
1689
+ super(), this.items = e;
1690
+ }
1691
+ _content(e) {
1692
+ return h(this.items.map((t) => t._toCBOR(e)));
1693
+ }
1694
+ _toCBOR(e) {
1695
+ let t = this._content(e);
1696
+ return h([m(2, BigInt(t.length)), t]);
1697
+ }
1698
+ _toEDN(e, t) {
1699
+ if (this.items.length === 0) return "<<>>";
1700
+ let n = v(e), { inlineSep: r, multilineSep: i, trailSep: a } = x(e, n === null);
1701
+ if (n === null) return `<<${this.items.map((n) => n._toEDN(e, t + 1)).join(r)}>>`;
1702
+ let o = y(n, t + 1), s = y(n, t), c = this.items.map((n) => `${o}${n._toEDN(e, t + 1)}`), l = c.length - 1;
1703
+ return `<<\n${c.map((e, t) => t < l ? `${e}${i}` : `${e}${a}`).join("\n")}\n${s}>>`;
1704
+ }
1705
+ _toHexDump(e, t) {
1706
+ let n = (e) => Array.from(e, (e) => e.toString(16).toUpperCase().padStart(2, "0")).join(" "), r = this._content().length, i = [{
1707
+ depth: e,
1708
+ hex: n(m(2, BigInt(r))),
1709
+ comment: `Embedded CBOR sequence, ${r} byte${r === 1 ? "" : "s"}`
1710
+ }];
1711
+ for (let n of this.items) i.push(...n._toHexDump(e + 1, t));
1712
+ return i;
1713
+ }
1714
+ _toJS(e) {
1715
+ return this._content();
1716
+ }
1717
+ }, Ne = 999n, Pe = class extends C {
1718
+ constructor(e, t) {
1719
+ let n = t.length === 1 && t[0] instanceof F ? t[0] : new D(t);
1720
+ super(Ne, new D([new F(e), n]));
1721
+ }
1722
+ _toEDN(e, t) {
1723
+ let n = this.content, r = n.items[0].value, i = n.items[1];
1724
+ return i instanceof F ? `${r}${Ce(i.value)}` : `${r}<<${i.items.map((n) => n._toEDN(e, t)).join(", ")}>>`;
1725
+ }
1726
+ }, Fe = 888n, j = class extends C {
1727
+ constructor(e) {
1728
+ e === void 0 ? super(Fe, k.NULL) : super(Fe, new D(e));
1729
+ }
1730
+ _toEDN(e, t) {
1731
+ return this.content instanceof k ? "..." : this.content instanceof D ? this.content.items.map((n) => n._toEDN(e, t)).join(" + ") : super._toEDN(e, t);
1732
+ }
1733
+ }, Ie = 2n, Le = 3n, Re = 18446744073709551615n, ze = -(Re + 1n);
1734
+ function Be(e) {
1735
+ if (e < 0n) throw RangeError("bigintToBytes requires a non-negative value");
1736
+ if (e === 0n) return new Uint8Array();
1737
+ let t = e.toString(16);
1738
+ t.length % 2 != 0 && (t = "0" + t);
1739
+ let n = new Uint8Array(t.length / 2);
1740
+ for (let e = 0; e < n.length; e++) n[e] = parseInt(t.slice(e * 2, e * 2 + 2), 16);
1741
+ return n;
1742
+ }
1743
+ function Ve(e) {
1744
+ let t = 0n;
1745
+ for (let n of e) t = t << 8n | BigInt(n);
1746
+ return t;
1747
+ }
1748
+ var M = class extends C {
1749
+ bigValue;
1750
+ constructor(e) {
1751
+ if (e <= Re) throw RangeError(`CborBigUint value ${e} fits in CborUint; use CborUint instead`);
1752
+ super(Ie, new w(Be(e))), this.bigValue = e;
1753
+ }
1754
+ _toEDN(e, t) {
1755
+ return this.bigValue.toString();
1756
+ }
1757
+ _toJS(e) {
1758
+ return this.bigValue;
1759
+ }
1760
+ }, N = class extends C {
1761
+ bigValue;
1762
+ constructor(e) {
1763
+ if (e >= ze) throw RangeError(`CborBigNint value ${e} fits in CborNint; use CborNint instead`);
1764
+ super(Le, new w(Be(-1n - e))), this.bigValue = e;
1765
+ }
1766
+ _toEDN(e, t) {
1767
+ return this.bigValue.toString();
1768
+ }
1769
+ _toJS(e) {
1770
+ return this.bigValue;
1771
+ }
1772
+ };
1773
+ //#endregion
1774
+ //#region src/edn/parser.ts
1775
+ function He(e, t) {
1776
+ let n = new je(e, { offset: t?.offset }), r = new et(n, t?.extensions, t?.unresolvedExtension, t?.allowInvalidUtf8, t?.allowTrailing).parse();
1777
+ return t?.preserveComments && Ze(r, n.comments, e), r;
1778
+ }
1779
+ function Ue(e) {
1780
+ let t = e, n;
1781
+ if (/[_][0-3i]$/.test(e)) {
1782
+ let r = e[e.length - 1];
1783
+ n = r === "i" ? "i" : Number(r), t = e.slice(0, -2);
1784
+ }
1785
+ return {
1786
+ numStr: t,
1787
+ encodingWidth: n
1788
+ };
1789
+ }
1790
+ function We(e) {
1791
+ return e.startsWith("-") ? -BigInt(e.slice(1)) : BigInt(e);
1792
+ }
1793
+ function Ge(e) {
1794
+ if (e === "NaN") return {
1795
+ value: NaN,
1796
+ precision: void 0
1797
+ };
1798
+ if (e === "Infinity") return {
1799
+ value: Infinity,
1800
+ precision: void 0
1801
+ };
1802
+ if (e === "-Infinity") return {
1803
+ value: -Infinity,
1804
+ precision: void 0
1805
+ };
1806
+ if (e.endsWith("_i") || e.endsWith("_0")) throw SyntaxError("EDN parse error: _0 and _i encoding indicators are not valid for floating-point values");
1807
+ let t = e, n;
1808
+ return e.endsWith("_1") ? (n = "half", t = e.slice(0, -2)) : e.endsWith("_2") ? (n = "single", t = e.slice(0, -2)) : e.endsWith("_3") && (n = "double", t = e.slice(0, -2)), /^-?0[xX]/.test(t) ? {
1809
+ value: Oe(t),
1810
+ precision: n
1811
+ } : {
1812
+ value: parseFloat(t),
1813
+ precision: n
1814
+ };
1815
+ }
1816
+ function Ke(e) {
1817
+ if (typeof Uint8Array.fromHex == "function") return Uint8Array.fromHex(e);
1818
+ if (e.length % 2 != 0) throw SyntaxError(`hex string has odd length: ${e.length}`);
1819
+ let t = new Uint8Array(e.length / 2);
1820
+ for (let n = 0; n < e.length; n += 2) t[n / 2] = parseInt(e.slice(n, n + 2), 16);
1821
+ return t;
1822
+ }
1823
+ var qe = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", Je = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
1824
+ function Ye(e, t) {
1825
+ let n = e.replace(/=+$/, "").toUpperCase(), r = n.length % 8;
1826
+ if (r === 1 || r === 3 || r === 6) throw SyntaxError(`invalid base32 length: ${n.length} characters`);
1827
+ let i = new Uint8Array(128).fill(255);
1828
+ for (let e = 0; e < t.length; e++) i[t.charCodeAt(e)] = e;
1829
+ let a = new Uint8Array(Math.floor(n.length * 5 / 8)), o = 0, s = 0, c = 0;
1830
+ for (let e of n) {
1831
+ let t = e.charCodeAt(0), n = t < 128 ? i[t] : 255;
1832
+ if (n === 255) throw SyntaxError(`invalid character in byte string: ${JSON.stringify(e)}`);
1833
+ o = o << 5 | n, s += 5, s >= 8 && (s -= 8, a[c++] = o >> s & 255);
1834
+ }
1835
+ if (s > 0 && o & (1 << s) - 1) throw SyntaxError("non-zero trailing bits in base32 input");
1836
+ return a;
1837
+ }
1838
+ function Xe(e) {
1839
+ if (typeof Uint8Array.fromBase64 == "function") {
1840
+ let t = /[-_]/.test(e) ? "base64url" : "base64";
1841
+ return Uint8Array.fromBase64(e, {
1842
+ alphabet: t,
1843
+ lastChunkHandling: "loose"
1844
+ });
1845
+ }
1846
+ let t = e.replace(/-/g, "+").replace(/_/g, "/"), n = t + "=".repeat((4 - t.length % 4) % 4), r = atob(n), i = new Uint8Array(r.length);
1847
+ for (let e = 0; e < r.length; e++) i[e] = r.charCodeAt(e);
1848
+ return i;
1849
+ }
1850
+ function Ze(e, t, n) {
1851
+ if (t.length === 0) return;
1852
+ let r = Qe(e), i = $e(n);
1853
+ for (let a of t) {
1854
+ let t = { ...a }, o = [...r].filter((e) => e.end <= a.start).sort((e, t) => t.end - e.end || t.start - e.start)[0], s = o ? n.slice(o.end, a.start) : "";
1855
+ if (o && i(o.end) === a.line && !s.includes(":")) {
1856
+ P(o.node, "trailing", t);
1857
+ continue;
1858
+ }
1859
+ let c = [...r].filter((e) => e.start < a.start && a.end < e.end).sort((e, t) => t.start - e.start || e.end - t.end)[0], l = [...r].filter((e) => e.start >= a.end).sort((e, t) => e.start - t.start || t.end - e.end)[0];
1860
+ if ((!c || l && l.end <= c.end) && l) {
1861
+ P(l.node, "leading", t);
1862
+ continue;
1863
+ }
1864
+ P(c?.node ?? e, "dangling", t);
1865
+ }
1866
+ }
1867
+ function Qe(e) {
1868
+ let t = [], n = (e) => {
1869
+ if (e.start !== void 0 && e.end !== void 0 && t.push({
1870
+ node: e,
1871
+ start: e.start,
1872
+ end: e.end
1873
+ }), e instanceof D || e instanceof A) {
1874
+ for (let t of e.items) n(t);
1875
+ return;
1876
+ }
1877
+ if (e instanceof O) {
1878
+ for (let [t, r] of e.entries) n(t), n(r);
1879
+ return;
1880
+ }
1881
+ if (e instanceof T || e instanceof E) {
1882
+ for (let t of e.chunks) n(t);
1883
+ return;
1884
+ }
1885
+ e instanceof C && n(e.content);
1886
+ };
1887
+ return n(e), t;
1888
+ }
1889
+ function P(e, t, n) {
1890
+ e.comments ??= {}, e.comments[t] ??= [], e.comments[t].push(n);
1891
+ }
1892
+ function $e(e) {
1893
+ let t = [0];
1894
+ for (let n = 0; n < e.length; n++) e[n] === "\n" && t.push(n + 1);
1895
+ return (n) => {
1896
+ let r = Math.max(0, Math.min(e.length, n));
1897
+ r > 0 && r === e.length && r--;
1898
+ let i = 0, a = t.length - 1;
1899
+ for (; i <= a;) {
1900
+ let e = i + a >> 1;
1901
+ t[e] <= r ? i = e + 1 : a = e - 1;
1902
+ }
1903
+ return a + 1;
1904
+ };
1905
+ }
1906
+ var et = class {
1907
+ t;
1908
+ allowInvalidUtf8;
1909
+ allowTrailing;
1910
+ extByPrefix;
1911
+ extByTag;
1912
+ unresolvedExtension;
1913
+ constructor(e, t, n, r, i) {
1914
+ this.t = e, this.allowInvalidUtf8 = r, this.allowTrailing = i, this.extByPrefix = /* @__PURE__ */ new Map(), this.extByTag = /* @__PURE__ */ new Map(), this.unresolvedExtension = n ?? "cpa999";
1915
+ for (let e of [...Z, ...t ?? []]) {
1916
+ for (let t of e.appStringPrefixes ?? []) this.extByPrefix.set(t, e);
1917
+ for (let t of e.tagNumbers ?? []) this.extByTag.set(t, e);
1918
+ }
1919
+ }
1920
+ parse() {
1921
+ let e = this.parseValue();
1922
+ if (this.allowTrailing) return e;
1923
+ let t = this.t.peek();
1924
+ return t.type !== "EOF" && this._fail(`unexpected token after value: ${JSON.stringify(t.value)}`, t), e;
1925
+ }
1926
+ parseValue() {
1927
+ let e = this.t.peek().offset, t = this._parseValueNode();
1928
+ return t.start = e, t.end = this.t.lastEndOffset, t;
1929
+ }
1930
+ _parseValueNode() {
1931
+ let e = this.t.peek();
1932
+ switch (e.type) {
1933
+ case "INTEGER": return this.parseIntegerOrTag();
1934
+ case "FLOAT": return this.parseFloat();
1935
+ case "TSTR":
1936
+ case "RAWSTRING": return this.parseString();
1937
+ case "BYTES_HEX":
1938
+ case "SQSTR":
1939
+ case "BYTES_B64":
1940
+ case "BYTES_B32":
1941
+ case "BYTES_H32": return this.t.consume(), this._parseBytesConcat(this._decodeBytesToken(e), e.type, e.raw);
1942
+ case "EMPTY_INDEF_BYTES": return this.t.consume(), new T([]);
1943
+ case "EMPTY_INDEF_TEXT": return this.t.consume(), new E([]);
1944
+ case "TRUE": return this.t.consume(), k.TRUE;
1945
+ case "FALSE": return this.t.consume(), k.FALSE;
1946
+ case "NULL": return this.t.consume(), k.NULL;
1947
+ case "UNDEFINED": return this.t.consume(), k.UNDEFINED;
1948
+ case "SIMPLE": return this.parseSimple();
1949
+ case "LBRACKET": return this.parseArray();
1950
+ case "LBRACE": return this.parseMap();
1951
+ case "LPAREN": return this.parseIndefGroup();
1952
+ case "LT_LT": return this.parseEmbeddedCBOR();
1953
+ case "APP_STRING": {
1954
+ this.t.consume();
1955
+ let t = this.extByPrefix.get(e.appPrefix);
1956
+ if (!t?.parseAppString) {
1957
+ if (this.unresolvedExtension === "cpa999") return new Pe(e.appPrefix, [new F(e.value)]);
1958
+ this._fail(`unknown app-string extension: ${JSON.stringify(e.appPrefix)}`, e);
1959
+ }
1960
+ return t.parseAppString(e.appPrefix, e.value);
1961
+ }
1962
+ case "APP_SEQUENCE": {
1963
+ this.t.consume();
1964
+ let t = [];
1965
+ for (; this.t.peek().type !== "GT_GT" && (this.t.peek().type === "EOF" && this._fail(`unterminated ${e.appPrefix}<<...>>`, e), !(t.length > 0 && this.t.peek().type === "COMMA" && (this.t.consume(), this.t.peek().type === "GT_GT")));) t.push(this.parseValue());
1966
+ this.expect("GT_GT");
1967
+ let n = this.extByPrefix.get(e.appPrefix);
1968
+ if (!n) {
1969
+ if (this.unresolvedExtension === "cpa999") return new Pe(e.appPrefix, t);
1970
+ this._fail(`unknown app-string extension: ${JSON.stringify(e.appPrefix)}`, e);
1971
+ }
1972
+ return n.parseAppSequence || this._fail(`app-string extension ${JSON.stringify(e.appPrefix)} does not support <<...>> form`, e), n.parseAppSequence(e.appPrefix, t);
1973
+ }
1974
+ case "ELLIPSIS": {
1975
+ if (this.t.consume(), this.t.peek().type !== "PLUS") return new j();
1976
+ let e = [new j()];
1977
+ for (; this.t.peek().type === "PLUS";) this.t.consume(), e.push(this.parseValue());
1978
+ return new j(e);
1979
+ }
1980
+ case "BYTES_HEX_ELIDED": return this.t.consume(), this._parseHexElidedConcat(e);
1981
+ default: this._fail(`unexpected token: ${JSON.stringify(e.value)}`, e);
1982
+ }
1983
+ }
1984
+ parseIntegerOrTag() {
1985
+ let e = this.t.consume(), { numStr: t, encodingWidth: n } = Ue(e.value), r = n === void 0 ? this.consumeEncodingIndicator() : n, i = We(t);
1986
+ if (i > 18446744073709551615n) return this.t.peek().type === "LPAREN" && this._fail("tag number exceeds maximum uint64", e), new M(i);
1987
+ if (i < -18446744073709551616n) return new N(i);
1988
+ let a = i >= 0n ? new g(i, r === void 0 ? void 0 : { encodingWidth: r }) : new _(i, r === void 0 ? void 0 : { encodingWidth: r });
1989
+ if (this.t.peek().type === "LPAREN") {
1990
+ a instanceof g || this._fail("tag number must be non-negative", e), this.t.consume();
1991
+ let t = this.parseValue();
1992
+ this.expect("RPAREN");
1993
+ let n = a.value, i = this.extByTag.get(n);
1994
+ if (i?.parseTag) {
1995
+ let e = i.parseTag(n, t);
1996
+ if (e !== void 0) return e;
1997
+ }
1998
+ return new C(n, t, r === void 0 ? void 0 : { encodingWidth: r });
1999
+ }
2000
+ return a;
2001
+ }
2002
+ parseFloat() {
2003
+ let { value: e, precision: t } = Ge(this.t.consume().value);
2004
+ return new S(e, t === void 0 ? void 0 : { precision: t });
2005
+ }
2006
+ parseString() {
2007
+ let e = this.t.consume();
2008
+ if (this.t.peek().type !== "PLUS") {
2009
+ let t = this.consumeEncodingIndicator();
2010
+ return new F(e.value, t === void 0 ? void 0 : { encodingWidth: t });
2011
+ }
2012
+ let t = !1, n = [{ text: e.value }];
2013
+ for (; this.t.peek().type === "PLUS";) {
2014
+ this.t.consume();
2015
+ let e = this.t.peek();
2016
+ e.type === "ELLIPSIS" ? (this.t.consume(), n.push({ ellipsis: !0 }), t = !0) : e.type === "TSTR" || e.type === "RAWSTRING" ? (this.t.consume(), n.push({ text: e.value })) : this._isBytesToken(e.type) ? (this.t.consume(), n.push({ text: this._decodeUtf8(this._decodeBytesToken(e), e) })) : this._fail(`expected string or byte string after +, got ${JSON.stringify(e.value)}`, e);
2017
+ }
2018
+ if (!t) {
2019
+ let e = this.consumeEncodingIndicator();
2020
+ return new F(n.map((e) => "text" in e ? e.text : "").join(""), e === void 0 ? void 0 : { encodingWidth: e });
2021
+ }
2022
+ let r = [], i = "";
2023
+ for (let e of n) "ellipsis" in e ? (i !== "" && (r.push(new F(i)), i = ""), r.push(new j())) : i += e.text;
2024
+ return i !== "" && r.push(new F(i)), new j(r);
2025
+ }
2026
+ _isBytesToken(e) {
2027
+ return e === "BYTES_HEX" || e === "SQSTR" || e === "BYTES_B64" || e === "BYTES_B32" || e === "BYTES_H32";
2028
+ }
2029
+ _decodeBytesToken(e) {
2030
+ switch (e.type) {
2031
+ case "BYTES_HEX":
2032
+ case "SQSTR": return Ke(e.value);
2033
+ case "BYTES_B64": return Xe(e.value);
2034
+ case "BYTES_B32": return Ye(e.value, qe);
2035
+ case "BYTES_H32": return Ye(e.value, Je);
2036
+ default: this._fail("expected byte string token", e);
2037
+ }
2038
+ }
2039
+ _decodeUtf8(e, t) {
2040
+ if (this.allowInvalidUtf8) return new TextDecoder("utf-8", { fatal: !1 }).decode(e);
2041
+ try {
2042
+ return new TextDecoder("utf-8", { fatal: !0 }).decode(e);
2043
+ } catch {
2044
+ this._fail("byte string in text concatenation is not valid UTF-8", t);
2045
+ }
2046
+ }
2047
+ _tokenTypeToEdnEncoding(e) {
2048
+ switch (e) {
2049
+ case "BYTES_B64": return "base64";
2050
+ case "BYTES_B32": return "base32";
2051
+ case "BYTES_H32": return "base32hex";
2052
+ default: return "hex";
2053
+ }
2054
+ }
2055
+ _parseBytesConcat(e, t, n) {
2056
+ if (this.t.peek().type !== "PLUS") {
2057
+ let r = this.consumeEncodingIndicator();
2058
+ return new w(e, {
2059
+ ednEncoding: this._tokenTypeToEdnEncoding(t),
2060
+ ednSource: n,
2061
+ ...r === void 0 ? {} : { encodingWidth: r }
2062
+ });
2063
+ }
2064
+ let r = !1, i = [{ bytes: e }];
2065
+ for (; this.t.peek().type === "PLUS";) {
2066
+ this.t.consume();
2067
+ let e = this.t.peek();
2068
+ if (e.type === "ELLIPSIS") this.t.consume(), i.push({ ellipsis: !0 }), r = !0;
2069
+ else if (e.type === "BYTES_HEX_ELIDED") {
2070
+ this.t.consume();
2071
+ let t = this._buildBytesElidedItems(e.value);
2072
+ for (let e of t) e instanceof j ? (i.push({ ellipsis: !0 }), r = !0) : e instanceof w && i.push({ bytes: e.value });
2073
+ } else this._isBytesToken(e.type) ? (this.t.consume(), i.push({ bytes: this._decodeBytesToken(e) })) : e.type === "TSTR" || e.type === "RAWSTRING" ? (this.t.consume(), i.push({ bytes: new TextEncoder().encode(e.value) })) : this._fail(`expected byte string after +, got ${JSON.stringify(e.value)}`, e);
2074
+ }
2075
+ if (!r) {
2076
+ let e = this.consumeEncodingIndicator(), t = i.map((e) => "bytes" in e ? e.bytes : new Uint8Array());
2077
+ return new w(this._concatBytes(t), e === void 0 ? void 0 : { encodingWidth: e });
2078
+ }
2079
+ let a = [], o = [], s = () => {
2080
+ o.length > 0 && (a.push(new w(this._concatBytes([...o]))), o.length = 0);
2081
+ };
2082
+ for (let e of i) "ellipsis" in e ? (s(), a.push(new j())) : o.push(e.bytes);
2083
+ return s(), new j(a);
2084
+ }
2085
+ _parseHexElidedConcat(e) {
2086
+ let t = this._buildBytesElidedItems(e.value);
2087
+ for (; this.t.peek().type === "PLUS";) {
2088
+ this.t.consume();
2089
+ let e = this.t.peek();
2090
+ if (e.type === "ELLIPSIS") this.t.consume(), t.push(new j());
2091
+ else if (e.type === "BYTES_HEX_ELIDED") {
2092
+ this.t.consume();
2093
+ let n = this._buildBytesElidedItems(e.value);
2094
+ this._mergeFirstBytesItem(t, n);
2095
+ } else if (this._isBytesToken(e.type)) {
2096
+ this.t.consume();
2097
+ let n = this._decodeBytesToken(e), r = t[t.length - 1];
2098
+ r instanceof w ? t[t.length - 1] = new w(this._concatBytes([r.value, n])) : t.push(new w(n));
2099
+ } else this._fail(`expected byte string after +, got ${JSON.stringify(e.value)}`, e);
2100
+ }
2101
+ return new j(t);
2102
+ }
2103
+ _buildBytesElidedItems(e) {
2104
+ let t = e.split("..."), n = [];
2105
+ for (let e = 0; e < t.length; e++) e > 0 && n.push(new j()), t[e].length > 0 && n.push(new w(Ke(t[e])));
2106
+ return n;
2107
+ }
2108
+ _mergeFirstBytesItem(e, t) {
2109
+ if (t.length === 0) return;
2110
+ let n = e[e.length - 1], r = t[0];
2111
+ n instanceof w && r instanceof w ? (e[e.length - 1] = new w(this._concatBytes([n.value, r.value])), e.push(...t.slice(1))) : e.push(...t);
2112
+ }
2113
+ _concatBytes(e) {
2114
+ let t = e.reduce((e, t) => e + t.byteLength, 0), n = new Uint8Array(t), r = 0;
2115
+ for (let t of e) n.set(t, r), r += t.byteLength;
2116
+ return n;
2117
+ }
2118
+ parseSimple() {
2119
+ this.t.consume(), this.expect("LPAREN");
2120
+ let e = this.t.peek();
2121
+ e.type !== "INTEGER" && this._fail(`expected integer inside simple(), got ${JSON.stringify(e.value)}`, e), this.t.consume();
2122
+ let { numStr: t } = Ue(e.value), n = Number(We(t));
2123
+ return this.expect("RPAREN"), new k(n);
2124
+ }
2125
+ parseEmbeddedCBOR() {
2126
+ this.t.consume();
2127
+ let e = [];
2128
+ for (; this.t.peek().type !== "GT_GT" && !(e.length > 0 && this.t.peek().type === "COMMA" && (this.t.consume(), this.t.peek().type === "GT_GT"));) e.push(this.parseValue());
2129
+ return this.expect("GT_GT"), new A(e);
2130
+ }
2131
+ parseArray() {
2132
+ this.t.consume();
2133
+ let e = !1, t;
2134
+ if (this.t.peek().type === "UNDERSCORE") this.t.consume(), e = !0;
2135
+ else if (this.t.peek().type === "ENCODING_INDICATOR") {
2136
+ let e = this.t.consume().value;
2137
+ t = e === "i" ? "i" : Number(e);
2138
+ }
2139
+ let n = [];
2140
+ for (; this.t.peek().type !== "RBRACKET" && !(n.length > 0 && this.t.peek().type === "COMMA" && (this.t.consume(), this.t.peek().type === "RBRACKET"));) n.push(this.parseValue());
2141
+ return this.expect("RBRACKET"), new D(n, {
2142
+ indefiniteLength: e,
2143
+ encodingWidth: t
2144
+ });
2145
+ }
2146
+ parseMap() {
2147
+ this.t.consume();
2148
+ let e = !1, t;
2149
+ if (this.t.peek().type === "UNDERSCORE") this.t.consume(), e = !0;
2150
+ else if (this.t.peek().type === "ENCODING_INDICATOR") {
2151
+ let e = this.t.consume().value;
2152
+ t = e === "i" ? "i" : Number(e);
2153
+ }
2154
+ let n = [];
2155
+ for (; this.t.peek().type !== "RBRACE" && !(n.length > 0 && this.t.peek().type === "COMMA" && (this.t.consume(), this.t.peek().type === "RBRACE"));) {
2156
+ let e = this.parseValue();
2157
+ this.expect("COLON");
2158
+ let t = this.parseValue();
2159
+ n.push([e, t]);
2160
+ }
2161
+ return this.expect("RBRACE"), new O(n, {
2162
+ indefiniteLength: e,
2163
+ encodingWidth: t
2164
+ });
2165
+ }
2166
+ parseIndefGroup() {
2167
+ this.t.consume();
2168
+ let e = this.t.peek();
2169
+ e.type !== "UNDERSCORE" && this._fail(`expected _ after (, got ${JSON.stringify(e.value)}`, e), this.t.consume();
2170
+ let t = [];
2171
+ for (; this.t.peek().type !== "RPAREN" && !(t.length > 0 && this.t.peek().type === "COMMA" && (this.t.consume(), this.t.peek().type === "RPAREN"));) t.push(this.parseValue());
2172
+ this.expect("RPAREN"), t.length === 0 && this._fail("empty indefinite group (_ ) is ambiguous; use ''_ for bytes or \"\"_ for text");
2173
+ let n = t[0];
2174
+ if (n instanceof w) return new T(t.map((e, t) => {
2175
+ if (e instanceof w) return e;
2176
+ this._fail(`indefinite byte string chunk ${t} must be a byte string, not a text string`);
2177
+ }));
2178
+ if (n instanceof F) return new E(t.map((e, t) => {
2179
+ if (e instanceof F) return e;
2180
+ this._fail(`indefinite text string chunk ${t} must be a text string, not a byte string`);
2181
+ }));
2182
+ this._fail("indefinite group chunks must be byte strings or text strings");
2183
+ }
2184
+ consumeEncodingIndicator() {
2185
+ if (this.t.peek().type === "ENCODING_INDICATOR") {
2186
+ let e = this.t.consume().value;
2187
+ return e === "i" ? "i" : Number(e);
2188
+ }
2189
+ }
2190
+ expect(e) {
2191
+ let t = this.t.consume();
2192
+ return t.type !== e && this._fail(`expected ${e}, got ${t.type} (${JSON.stringify(t.value)})`, t), t;
2193
+ }
2194
+ _fail(e, t) {
2195
+ let n = t ? ` at line ${t.line}, column ${t.col}` : "";
2196
+ throw SyntaxError(`EDN parse error${n}: ${e}`);
2197
+ }
2198
+ }, tt = new TextEncoder(), F = class extends d {
2199
+ indefiniteLength = !1;
2200
+ value;
2201
+ encodingWidth;
2202
+ constructor(e, t) {
2203
+ super(), this.value = e, this.encodingWidth = t?.encodingWidth;
2204
+ }
2205
+ _toCBOR(e) {
2206
+ let t = tt.encode(this.value);
2207
+ return h([m(3, BigInt(t.length), this.encodingWidth), t]);
2208
+ }
2209
+ _toEDN(e, t) {
2210
+ let n = this.encodingWidth === void 0 ? "" : `_${this.encodingWidth}`;
2211
+ return nt(this.value, n, e, t);
2212
+ }
2213
+ _toJS(e) {
2214
+ return this.value;
2215
+ }
2216
+ };
2217
+ function nt(e, t, n, r) {
2218
+ let i = n?.textStringFormat ?? [], a = v(n);
2219
+ if (i.length === 0 || a === null) return we(e) + t;
2220
+ let o = /* @__PURE__ */ new Map(), s = null;
2221
+ if (i.includes("cboredn") && (s = it(e), s !== null)) for (let { point: e, contentDepth: t } of s) o.set(e, t);
2222
+ if (i.includes("newline")) {
2223
+ let t = s === null ? rt(e, 0) : at(e);
2224
+ for (let { point: e, contentDepth: n } of t) o.has(e) || o.set(e, n);
2225
+ }
2226
+ let c = dt(e, o);
2227
+ if (c.length <= 1) return we(e) + t;
2228
+ let l = c.map(({ text: e }, n) => {
2229
+ let r = we(e);
2230
+ return n === c.length - 1 ? r + t : r;
2231
+ }), u = l[0];
2232
+ for (let e = 1; e < l.length; e++) {
2233
+ let t = y(a, r + 1 + c[e].contentDepth);
2234
+ u += ` +\n${t}${l[e]}`;
2235
+ }
2236
+ return u;
2237
+ }
2238
+ function rt(e, t) {
2239
+ let n = [];
2240
+ for (let r = 0; r < e.length; r++) {
2241
+ let i = e[r];
2242
+ i === "\r" ? e[r + 1] === "\n" ? (n.push({
2243
+ point: r + 2,
2244
+ contentDepth: t
2245
+ }), r++) : n.push({
2246
+ point: r + 1,
2247
+ contentDepth: t
2248
+ }) : i === "\n" && n.push({
2249
+ point: r + 1,
2250
+ contentDepth: t
2251
+ });
2252
+ }
2253
+ return n;
2254
+ }
2255
+ function it(e) {
2256
+ try {
2257
+ He(e);
2258
+ } catch {
2259
+ return null;
2260
+ }
2261
+ let t = [], n = new je(e), r = 0, i = null, a = !1, o = 0;
2262
+ for (;;) {
2263
+ let s = n.consume();
2264
+ if (s.type === "EOF") break;
2265
+ let c = !1;
2266
+ if (a || (a = !0, s.offset > 0 && lt(n.comments, 0, s.offset) && t.push({
2267
+ point: s.offset,
2268
+ contentDepth: r
2269
+ })), i !== null) {
2270
+ if (i.kind === "opener" && st.has(s.type)) {
2271
+ i.point = s.endOffset, o = s.endOffset;
2272
+ continue;
2273
+ } else i.kind === "opener" && I.has(s.type) && ut(e, i.point, s.offset) ? c = !0 : t.push({
2274
+ point: s.offset,
2275
+ contentDepth: i.contentDepth
2276
+ });
2277
+ i = null;
2278
+ }
2279
+ ct.has(s.type) ? (r++, i = {
2280
+ point: s.endOffset,
2281
+ contentDepth: r,
2282
+ kind: "opener"
2283
+ }) : I.has(s.type) ? (r = Math.max(0, r - 1), c || t.push({
2284
+ point: s.offset,
2285
+ contentDepth: r
2286
+ })) : s.type === "COMMA" && (i = {
2287
+ point: s.endOffset,
2288
+ contentDepth: r,
2289
+ kind: "comma"
2290
+ }), o = s.endOffset;
2291
+ }
2292
+ let s = n.comments.find((e) => e.start >= o);
2293
+ return s !== void 0 && t.push({
2294
+ point: s.start,
2295
+ contentDepth: r
2296
+ }), t;
2297
+ }
2298
+ function at(e) {
2299
+ let t = [], n = new je(e), r = 0;
2300
+ for (;;) {
2301
+ let i = n.consume();
2302
+ if (i.type === "EOF") break;
2303
+ if (ct.has(i.type)) r++;
2304
+ else if (I.has(i.type)) r = Math.max(0, r - 1);
2305
+ else if (i.type !== "COMMA" && ot.has(i.type)) {
2306
+ let n = e.slice(i.offset, i.endOffset);
2307
+ for (let { point: e } of rt(n, 0)) t.push({
2308
+ point: i.offset + e,
2309
+ contentDepth: r + 1
2310
+ });
2311
+ }
2312
+ }
2313
+ return t;
2314
+ }
2315
+ var ot = new Set(["TSTR", "RAWSTRING"]), st = new Set(["ENCODING_INDICATOR", "UNDERSCORE"]), ct = new Set([
2316
+ "LBRACKET",
2317
+ "LBRACE",
2318
+ "LPAREN",
2319
+ "LT_LT"
2320
+ ]), I = new Set([
2321
+ "RBRACKET",
2322
+ "RBRACE",
2323
+ "RPAREN",
2324
+ "GT_GT"
2325
+ ]);
2326
+ function lt(e, t, n) {
2327
+ return e.some((e) => e.start >= t && e.end <= n);
2328
+ }
2329
+ function ut(e, t, n) {
2330
+ return /^[\t\n\r ]*$/.test(e.slice(t, n));
2331
+ }
2332
+ function dt(e, t) {
2333
+ let n = [...t].filter(([t]) => t > 0 && t < e.length).sort(([e], [t]) => e - t);
2334
+ if (n.length === 0) return [{
2335
+ text: e,
2336
+ contentDepth: 0
2337
+ }];
2338
+ let r = [], i = 0, a = 0;
2339
+ for (let [t, o] of n) t !== i && (r.push({
2340
+ text: e.slice(i, t),
2341
+ contentDepth: a
2342
+ }), i = t, a = o);
2343
+ return i < e.length && r.push({
2344
+ text: e.slice(i),
2345
+ contentDepth: a
2346
+ }), r;
2347
+ }
2348
+ //#endregion
2349
+ //#region src/extensions/dt.ts
2350
+ function L(e) {
2351
+ if (Number.isInteger(e)) return (/* @__PURE__ */ new Date(e * 1e3)).toISOString().replace(/\.000Z$/, "Z");
2352
+ let t = Math.round(e * 1e3);
2353
+ if (t / 1e3 === e) return new Date(t).toISOString().replace(/\.000Z$/, "Z");
2354
+ 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";
2355
+ for (; s.length < 3;) s += "0";
2356
+ return `${i}.${s}Z`;
2357
+ }
2358
+ function ft(e) {
2359
+ if (e.length !== 1) throw SyntaxError("dt<<...>>: expected exactly one item");
2360
+ let t = e[0];
2361
+ if (t instanceof F) return t.value;
2362
+ if (t instanceof w) return new TextDecoder("utf-8", { fatal: !0 }).decode(t.value);
2363
+ throw SyntaxError("dt<<...>>: expected a text string or byte string");
2364
+ }
2365
+ function R(e) {
2366
+ let t = e.match(/^(.+T\d{2}:\d{2}:\d{2})(\.\d+)(Z|[+-]\d{2}:\d{2})$/i), n, r;
2367
+ t ? (n = t[1] + t[3], r = parseFloat("0" + t[2])) : (n = e, r = void 0);
2368
+ let i = Date.parse(n);
2369
+ if (isNaN(i)) throw SyntaxError(`dt: invalid RFC 3339 date-time: ${JSON.stringify(e)}`);
2370
+ if (r === void 0) {
2371
+ let e = i / 1e3;
2372
+ return e >= 0 ? new mt(BigInt(e)) : new ht(BigInt(e));
2373
+ }
2374
+ return new gt(i / 1e3 + r);
2375
+ }
2376
+ var pt = 1n, mt = class extends g {
2377
+ constructor(e, t) {
2378
+ super(e, t);
2379
+ }
2380
+ _toEDN(e, t) {
2381
+ return e?.appStrings === !1 ? super._toEDN(e, t) : `dt'${L(Number(this.value))}'`;
2382
+ }
2383
+ }, ht = class extends _ {
2384
+ constructor(e, t) {
2385
+ super(e, t);
2386
+ }
2387
+ _toEDN(e, t) {
2388
+ return e?.appStrings === !1 ? super._toEDN(e, t) : `dt'${L(Number(this.value))}'`;
2389
+ }
2390
+ }, gt = class extends S {
2391
+ constructor(e, t) {
2392
+ super(e, t);
2393
+ }
2394
+ _toEDN(e, t) {
2395
+ return e?.appStrings === !1 ? super._toEDN(e, t) : `dt'${L(this.value)}'`;
2396
+ }
2397
+ }, _t = class extends C {
2398
+ constructor(e, t) {
2399
+ super(pt, R(e), t);
2400
+ }
2401
+ _toEDN(e, t) {
2402
+ if (e?.appStrings === !1) return super._toEDN(e, t);
2403
+ let n = this.content;
2404
+ return `DT'${L(n instanceof S ? n.value : Number(n.value))}'`;
2405
+ }
2406
+ }, vt = class extends _t {
2407
+ constructor(e, t) {
2408
+ super(e, t);
2409
+ }
2410
+ _toJS(e) {
2411
+ let t = this.content, n = t instanceof S ? t.value * 1e3 : Number(t.value) * 1e3;
2412
+ return new Date(n);
2413
+ }
2414
+ };
2415
+ function yt(e) {
2416
+ let t = e?.jsDate ?? !1;
2417
+ function n(e) {
2418
+ return t ? new vt(e) : new _t(e);
2419
+ }
2420
+ let r = {
2421
+ appStringPrefixes: ["dt", "DT"],
2422
+ tagNumbers: [pt],
2423
+ parseAppString(e, t) {
2424
+ return e === "DT" ? n(t) : R(t);
2425
+ },
2426
+ parseAppSequence(e, t) {
2427
+ let r = ft(t);
2428
+ return e === "DT" ? n(r) : R(r);
2429
+ },
2430
+ parseTag(e, t) {
2431
+ if (e !== 1n) return;
2432
+ let r;
2433
+ if (t instanceof g) r = Number(t.value);
2434
+ else if (t instanceof _) r = Number(t.value);
2435
+ else if (t instanceof S) r = t.value;
2436
+ else return;
2437
+ return n(L(r));
2438
+ }
2439
+ };
2440
+ return t && (r.fromJS = (e, t) => {
2441
+ if (e instanceof Date) return new vt(L(e.getTime() / 1e3));
2442
+ }, r.isJSType = (e) => e instanceof Date), r;
2443
+ }
2444
+ var bt = yt(), xt = yt({ jsDate: !0 });
2445
+ //#endregion
2446
+ //#region src/utils/ip.ts
2447
+ function St(e) {
2448
+ let t = e.split(".");
2449
+ if (t.length !== 4) throw SyntaxError(`ip: invalid IPv4 address: ${JSON.stringify(e)}`);
2450
+ let n = new Uint8Array(4);
2451
+ for (let e = 0; e < 4; e++) {
2452
+ let r = t[e];
2453
+ if (!/^\d+$/.test(r) || r.length > 1 && r[0] === "0") throw SyntaxError(`ip: invalid IPv4 octet: ${JSON.stringify(r)}`);
2454
+ let i = parseInt(r, 10);
2455
+ if (i > 255) throw SyntaxError(`ip: IPv4 octet out of range: ${i}`);
2456
+ n[e] = i;
2457
+ }
2458
+ return n;
2459
+ }
2460
+ function Ct(e) {
2461
+ let t = new Uint8Array(16);
2462
+ if (e === "::") return t;
2463
+ let n = e, r = null, i = e.match(/^(.*):(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/);
2464
+ i && (n = i[1], n.endsWith(":") && (n += ":"), r = St(i[2]));
2465
+ let a = n.split("::");
2466
+ if (a.length > 2) throw SyntaxError(`ip: invalid IPv6 address: ${JSON.stringify(e)}`);
2467
+ let o = a.length === 2, s = a[0] ? a[0].split(":") : [], c = o && a[1] ? a[1].split(":") : [], l = r ? 6 : 8;
2468
+ if (!o && s.length !== l || o && s.length + c.length >= l) throw SyntaxError(`ip: invalid IPv6 address: ${JSON.stringify(e)}`);
2469
+ let u = l - s.length - c.length, d = [
2470
+ ...s,
2471
+ ...Array(u).fill("0"),
2472
+ ...c
2473
+ ], f = 0;
2474
+ for (let e of d) {
2475
+ if (!/^[0-9a-fA-F]{1,4}$/.test(e)) throw SyntaxError(`ip: invalid IPv6 group: ${JSON.stringify(e)}`);
2476
+ let n = parseInt(e, 16);
2477
+ t[f++] = n >> 8 & 255, t[f++] = n & 255;
2478
+ }
2479
+ return r && t.set(r, 12), t;
2480
+ }
2481
+ function wt(e) {
2482
+ return Array.from(e).join(".");
2483
+ }
2484
+ function Tt(e) {
2485
+ let t = e.slice(0, 10).every((e) => e === 0) && e[10] === 255 && e[11] === 255 ? wt(e.slice(12)) : null, n = t ? 6 : 8, r = [];
2486
+ for (let t = 0; t < n * 2; t += 2) r.push(e[t] << 8 | e[t + 1]);
2487
+ let i = -1, a = 0, o = 0;
2488
+ for (; o < n;) if (r[o] === 0) {
2489
+ let e = o + 1;
2490
+ for (; e < n && r[e] === 0;) e++;
2491
+ e - o > a && (i = o, a = e - o), o = e;
2492
+ } else o++;
2493
+ a < 2 && (i = -1);
2494
+ let s = (e) => e.toString(16), c;
2495
+ 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;
2496
+ }
2497
+ //#endregion
2498
+ //#region src/extensions/ip.ts
2499
+ var Et = "ip", z = "IP", B = 52n, V = 54n;
2500
+ function Dt(e) {
2501
+ if (e.length !== 1) throw SyntaxError("ip<<...>>: expected exactly one item");
2502
+ let t = e[0];
2503
+ if (t instanceof F) return t.value;
2504
+ if (t instanceof w) return new TextDecoder("utf-8", { fatal: !0 }).decode(t.value);
2505
+ throw SyntaxError("ip<<...>>: expected a text string or byte string");
2506
+ }
2507
+ function Ot(e) {
2508
+ return /^\d/.test(e) && e.includes(".") && !e.includes(":") ? {
2509
+ bytes: St(e),
2510
+ isV4: !0
2511
+ } : {
2512
+ bytes: Ct(e),
2513
+ isV4: !1
2514
+ };
2515
+ }
2516
+ function H(e) {
2517
+ if (e.length === 4) return wt(e);
2518
+ if (e.length === 16) return Tt(e);
2519
+ throw SyntaxError(`ip: unexpected byte length: ${e.length}`);
2520
+ }
2521
+ function kt(e, t) {
2522
+ let n = new Uint8Array(e.length);
2523
+ n.set(e);
2524
+ let r = Math.floor(t / 8), i = t % 8;
2525
+ i > 0 && r < e.length && (n[r] &= 255 << 8 - i & 255);
2526
+ for (let t = r + +(i > 0); t < e.length; t++) n[t] = 0;
2527
+ let a = Math.ceil(t / 8);
2528
+ for (; a > 0 && n[a - 1] === 0;) a--;
2529
+ return n.slice(0, a);
2530
+ }
2531
+ function At(e, t) {
2532
+ let n = new Uint8Array(t);
2533
+ return n.set(e), n;
2534
+ }
2535
+ var jt = class extends w {
2536
+ _toEDN(e, t) {
2537
+ return e?.appStrings === !1 ? super._toEDN(e, t) : `${Et}'${H(this.value)}'`;
2538
+ }
2539
+ }, Mt = class extends D {
2540
+ _isV4;
2541
+ constructor(e, t, n) {
2542
+ super([new g(BigInt(e)), new w(t)]), this._isV4 = n;
2543
+ }
2544
+ _toEDN(e, t) {
2545
+ if (e?.appStrings === !1) return super._toEDN(e, t);
2546
+ let n = Number(this.items[0].value), r = this.items[1].value;
2547
+ return `${Et}'${H(At(r, this._isV4 ? 4 : 16))}/${n}'`;
2548
+ }
2549
+ }, U = class extends C {
2550
+ constructor(e, t) {
2551
+ super(e, t);
2552
+ }
2553
+ _toEDN(e, t) {
2554
+ if (e?.appStrings === !1) return super._toEDN(e, t);
2555
+ let n = this.tag === B ? 4 : 16, r = this.content;
2556
+ if (r instanceof w) return `${z}'${H(r.value)}'`;
2557
+ if (r instanceof D && r.items.length === 2 && r.items[0] instanceof g && r.items[1] instanceof w) {
2558
+ let e = Number(r.items[0].value);
2559
+ return `${z}'${H(At(r.items[1].value, n))}/${e}'`;
2560
+ }
2561
+ return super._toEDN(e, t);
2562
+ }
2563
+ };
2564
+ function Nt(e, t) {
2565
+ let n = t.indexOf("/");
2566
+ if (n === -1) {
2567
+ let { bytes: n, isV4: r } = Ot(t);
2568
+ return e === z ? new U(r ? B : V, new w(n)) : new jt(n);
2569
+ }
2570
+ let r = t.slice(0, n), i = t.slice(n + 1);
2571
+ if (!/^\d+$/.test(i)) throw SyntaxError(`ip: invalid prefix length: ${JSON.stringify(i)}`);
2572
+ let a = parseInt(i, 10), { bytes: o, isV4: s } = Ot(r), c = s ? 32 : 128;
2573
+ if (a > c) throw SyntaxError(`ip: prefix length ${a} exceeds maximum ${c} for ${s ? "IPv4" : "IPv6"}`);
2574
+ let l = kt(o, a);
2575
+ return e === z ? new U(s ? B : V, new D([new g(BigInt(a)), new w(l)])) : new Mt(a, l, s);
2576
+ }
2577
+ var Pt = {
2578
+ appStringPrefixes: [Et, z],
2579
+ tagNumbers: [B, V],
2580
+ parseAppString(e, t) {
2581
+ return Nt(e, t);
2582
+ },
2583
+ parseAppSequence(e, t) {
2584
+ return Nt(e, Dt(t));
2585
+ },
2586
+ parseTag(e, t) {
2587
+ if (!(e !== B && e !== V) && (t instanceof w || t instanceof D)) return new U(e, t);
2588
+ }
2589
+ }, Ft = 18446744073709551615n, It = -(Ft + 1n), Lt = {
2590
+ tagNumbers: [Ie, Le],
2591
+ parseTag(e, t) {
2592
+ if (t instanceof w) {
2593
+ if (e === 2n) {
2594
+ let e = Ve(t.value);
2595
+ return e > Ft ? new M(e) : void 0;
2596
+ }
2597
+ if (e === 3n) {
2598
+ let e = -1n - Ve(t.value);
2599
+ return e < It ? new N(e) : void 0;
2600
+ }
2601
+ }
2602
+ }
2603
+ }, Rt = "cri", zt = "CRI", Bt = 99n, Vt = new Map([
2604
+ ["coap", -1n],
2605
+ ["coaps", -2n],
2606
+ ["http", -3n],
2607
+ ["https", -4n],
2608
+ ["urn", -5n],
2609
+ ["did", -6n],
2610
+ ["coap+tcp", -7n],
2611
+ ["coaps+tcp", -8n],
2612
+ ["coap+ws", -25n],
2613
+ ["coaps+ws", -26n]
2614
+ ]), Ht = new Map([...Vt.entries()].map(([e, t]) => [t, e]));
2615
+ function W(e) {
2616
+ try {
2617
+ return decodeURIComponent(e);
2618
+ } catch {
2619
+ return e;
2620
+ }
2621
+ }
2622
+ function Ut(e) {
2623
+ return Array.from(new TextEncoder().encode(e), (e) => `%${e.toString(16).toUpperCase().padStart(2, "0")}`).join("");
2624
+ }
2625
+ function G(e, t) {
2626
+ let n = "";
2627
+ for (let r of e) n += t(r) ? r : Ut(r);
2628
+ return n;
2629
+ }
2630
+ function Wt(e) {
2631
+ return /[A-Za-z0-9\-._~]/.test(e);
2632
+ }
2633
+ function Gt(e) {
2634
+ return /[!$&'()*+,;=]/.test(e);
2635
+ }
2636
+ function Kt(e) {
2637
+ return Wt(e) || Gt(e) || e === ":" || e === "@";
2638
+ }
2639
+ function qt(e) {
2640
+ return (Kt(e) || e === "/" || e === "?") && e !== "&";
2641
+ }
2642
+ function Jt(e) {
2643
+ return Kt(e) || e === "/" || e === "?";
2644
+ }
2645
+ function Yt(e) {
2646
+ return Wt(e) || Gt(e) || e === ":";
2647
+ }
2648
+ function Xt(e) {
2649
+ return Wt(e) || Gt(e);
2650
+ }
2651
+ function Zt(e) {
2652
+ let t = [], n = e, r = n.indexOf("@");
2653
+ r >= 0 && (t.push(k.FALSE), t.push(new F(W(n.slice(0, r)))), n = n.slice(r + 1));
2654
+ let i, a = null;
2655
+ if (n.startsWith("[")) {
2656
+ let e = n.indexOf("]");
2657
+ if (e < 0) throw SyntaxError("cri: unterminated IPv6 bracket in authority");
2658
+ i = n.slice(1, e);
2659
+ let r = n.slice(e + 1);
2660
+ if (r.startsWith(":")) a = r.slice(1);
2661
+ else if (r.length > 0) throw SyntaxError("cri: unexpected characters after ']' in authority");
2662
+ t.push(new w(Ct(i)));
2663
+ } else {
2664
+ let e = n.lastIndexOf(":");
2665
+ if (e >= 0 ? (i = n.slice(0, e), a = n.slice(e + 1)) : i = n, i !== "") if (/^\d{1,3}(\.\d{1,3}){3}$/.test(i)) t.push(new w(St(i)));
2666
+ else for (let e of i.toLowerCase().split(".")) t.push(new F(e));
2667
+ }
2668
+ if (a !== null && a !== "") {
2669
+ if (!/^\d+$/.test(a)) throw SyntaxError(`cri: invalid port: ${JSON.stringify(a)}`);
2670
+ let e = parseInt(a, 10);
2671
+ if (e > 65535) throw SyntaxError(`cri: port ${e} out of range`);
2672
+ t.push(new g(BigInt(e)));
2673
+ }
2674
+ return new D(t);
2675
+ }
2676
+ function Qt(e) {
2677
+ let t = e.items, n = 0, r = "";
2678
+ if (n < t.length && t[n] instanceof k && t[n].value === 20) {
2679
+ n++;
2680
+ let e = t[n++];
2681
+ r += G(e.value, Yt) + "@";
2682
+ }
2683
+ if (n >= t.length) return r;
2684
+ let i = t[n];
2685
+ if (i instanceof w) {
2686
+ n++;
2687
+ let { length: e } = i.value;
2688
+ if (e === 4) r += wt(i.value);
2689
+ else if (e === 16) r += "[" + Tt(i.value) + "]";
2690
+ else throw Error(`cri: unexpected host-ip byte length: ${e}`);
2691
+ n < t.length && t[n] instanceof F && (r += `%25${G(t[n++].value, Xt)}`);
2692
+ } else {
2693
+ let e = [];
2694
+ for (; n < t.length && t[n] instanceof F;) e.push(G(t[n++].value, Xt));
2695
+ r += e.join(".");
2696
+ }
2697
+ return n < t.length && t[n] instanceof g && (r += ":" + t[n].value.toString()), r;
2698
+ }
2699
+ function $t(e) {
2700
+ let t = e.slice(2), n = t.indexOf("/"), r, i;
2701
+ return n >= 0 ? (r = t.slice(0, n), i = t.slice(n + 1).split("/").map((e) => new F(W(e)))) : (r = t, i = []), {
2702
+ authority: Zt(r),
2703
+ pathSegments: i
2704
+ };
2705
+ }
2706
+ function en(e) {
2707
+ let t = e, n = null, r = t.indexOf("#");
2708
+ r >= 0 && (n = W(t.slice(r + 1)), t = t.slice(0, r));
2709
+ let i = null, a = t.indexOf("?");
2710
+ if (a >= 0) {
2711
+ let e = t.slice(a + 1);
2712
+ t = t.slice(0, a), i = e.split("&").map((e) => new F(W(e)));
2713
+ }
2714
+ let o = [], s = /^([a-zA-Z][a-zA-Z0-9+.\-]*):([\s\S]*)$/.exec(t);
2715
+ if (s) {
2716
+ let e = s[1].toLowerCase(), t = s[2], n = Vt.get(e);
2717
+ if (o.push(n === void 0 ? new F(e) : new _(n)), t.startsWith("//")) {
2718
+ let { authority: e, pathSegments: n } = $t(t);
2719
+ o.push(e, new D(n));
2720
+ } else if (t.startsWith("/")) {
2721
+ let e = t.slice(1).split("/").map((e) => new F(W(e)));
2722
+ o.push(k.NULL, new D(e));
2723
+ } else {
2724
+ let e = t.split("/").map((e) => new F(W(e)));
2725
+ o.push(k.TRUE, new D(e));
2726
+ }
2727
+ } else if (t.startsWith("//")) {
2728
+ let { authority: e, pathSegments: n } = $t(t);
2729
+ o.push(k.FALSE, e, new D(n));
2730
+ } else if (t.startsWith("/")) {
2731
+ let e = t.slice(1).split("/").map((e) => new F(W(e)));
2732
+ o.push(k.TRUE, new D(e));
2733
+ } else if (t === "") o.push(new g(0n));
2734
+ else {
2735
+ let n = 1n, r = t, i = !1;
2736
+ for (r.startsWith("./") && (i = !0, r = r.slice(2)); r.startsWith("../");) n++, r = r.slice(3);
2737
+ 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)}`);
2738
+ let a = r === "" ? [] : r.split("/").map((e) => new F(W(e)));
2739
+ o.push(new g(n), new D(a));
2740
+ }
2741
+ if (i !== null && o.push(new D(i)), n !== null && (i === null && o.push(k.NULL), o.push(new F(n))), n !== null && i === null && o.splice(o.length - 2, 1), i === null && n === null) {
2742
+ let e = o[o.length - 1];
2743
+ e instanceof D && e.items.length === 0 && o.pop();
2744
+ }
2745
+ return o.length === 1 && o[0] instanceof g && o[0].value === 0n ? [] : o;
2746
+ }
2747
+ function K(e, t) {
2748
+ let n = t, r = "";
2749
+ if (n < e.length) {
2750
+ let t = e[n];
2751
+ if (t instanceof D) {
2752
+ if (n++, t.items.length > 0) {
2753
+ let e = t.items.map((e) => {
2754
+ if (!(e instanceof F)) throw Error("cri: query item must be a text string");
2755
+ return G(e.value, qt);
2756
+ });
2757
+ r += "?" + e.join("&");
2758
+ }
2759
+ } else t instanceof k && t.value === 22 && n++;
2760
+ }
2761
+ return n < e.length && e[n] instanceof F && (r += "#" + G(e[n].value, Jt)), r;
2762
+ }
2763
+ function q(e) {
2764
+ return e.items.map((e) => {
2765
+ if (!(e instanceof F)) throw Error("cri: path segment must be a text string");
2766
+ return G(e.value, Kt);
2767
+ });
2768
+ }
2769
+ function tn(e) {
2770
+ if (e.length === 0) return "";
2771
+ let t = 0, n = e[t++];
2772
+ if (n instanceof _ || n instanceof F) {
2773
+ let r;
2774
+ if (n instanceof _) {
2775
+ let e = Ht.get(n.value);
2776
+ if (e === void 0) throw Error(`cri: unrecognised scheme-id ${n.value}`);
2777
+ r = e + ":";
2778
+ } else r = n.value + ":";
2779
+ if (t >= e.length) return r;
2780
+ let i = e[t++], a = "", o = !1;
2781
+ if (i instanceof D) a = "//" + Qt(i), o = !0;
2782
+ else if (i instanceof k) if (i.value === 22) o = !0;
2783
+ else if (i.value === 21) o = !1;
2784
+ else throw Error(`cri: unexpected no-authority value: simple(${i.value})`);
2785
+ else throw Error("cri: unexpected type for authority element");
2786
+ let s = "";
2787
+ if (t < e.length && e[t] instanceof D) {
2788
+ let n = e[t++];
2789
+ n.items.length > 0 && (s = (o ? "/" : "") + q(n).join("/"));
2790
+ }
2791
+ return r + a + s + K(e, t);
2792
+ }
2793
+ if (n instanceof k && n.value === 20) {
2794
+ if (t >= e.length || !(e[t] instanceof D)) throw Error("cri: network-path reference requires an authority array");
2795
+ let n = Qt(e[t++]), r = "";
2796
+ if (t < e.length && e[t] instanceof D) {
2797
+ let n = e[t++];
2798
+ n.items.length > 0 && (r = "/" + q(n).join("/"));
2799
+ }
2800
+ return "//" + n + r + K(e, t);
2801
+ }
2802
+ if (n instanceof k && n.value === 21) {
2803
+ let n = "/";
2804
+ if (t < e.length && e[t] instanceof D) {
2805
+ let r = e[t++];
2806
+ n = "/" + q(r).join("/");
2807
+ }
2808
+ return n + K(e, t);
2809
+ }
2810
+ if (n instanceof g) {
2811
+ let r = n.value;
2812
+ if (r === 0n) return K(e, t);
2813
+ let i = r === 1n ? "" : "../".repeat(Number(r) - 1), a;
2814
+ if (t < e.length && e[t] instanceof D) {
2815
+ let n = e[t++];
2816
+ if (n.items.length > 0) {
2817
+ let e = q(n);
2818
+ a = (r === 1n && e[0].includes(":") ? "./" : i) + e.join("/");
2819
+ } else a = i === "" ? "./" : i;
2820
+ } else a = i === "" ? "./" : i;
2821
+ return a + K(e, t);
2822
+ }
2823
+ throw Error("cri: unrecognised first element type in CRI array");
2824
+ }
2825
+ var nn = class extends D {
2826
+ _toEDN(e, t) {
2827
+ if (e?.appStrings === !1) return super._toEDN(e, t);
2828
+ try {
2829
+ return `${Rt}'${tn(this.items)}'`;
2830
+ } catch {
2831
+ return super._toEDN(e, t);
2832
+ }
2833
+ }
2834
+ }, rn = class extends C {
2835
+ constructor(e) {
2836
+ super(Bt, e);
2837
+ }
2838
+ _toEDN(e, t) {
2839
+ if (e?.appStrings === !1) return super._toEDN(e, t);
2840
+ try {
2841
+ return `${zt}'${tn(this.content.items)}'`;
2842
+ } catch {
2843
+ return super._toEDN(e, t);
2844
+ }
2845
+ }
2846
+ };
2847
+ function an(e) {
2848
+ if (e.length !== 1) throw SyntaxError("cri<<...>>: expected exactly one item");
2849
+ let t = e[0];
2850
+ if (t instanceof F) return t.value;
2851
+ if (t instanceof w) return new TextDecoder("utf-8", { fatal: !0 }).decode(t.value);
2852
+ throw SyntaxError("cri<<...>>: expected a text string or byte string");
2853
+ }
2854
+ function on(e, t) {
2855
+ let n = new nn(en(t));
2856
+ return e === zt ? new rn(n) : n;
2857
+ }
2858
+ var sn = {
2859
+ appStringPrefixes: [Rt, zt],
2860
+ tagNumbers: [Bt],
2861
+ parseAppString(e, t) {
2862
+ return on(e, t);
2863
+ },
2864
+ parseAppSequence(e, t) {
2865
+ return on(e, an(t));
2866
+ },
2867
+ parseTag(e, t) {
2868
+ if (e === 99n && t instanceof D) return new rn(new nn(t.items, {
2869
+ indefiniteLength: t.indefiniteLength,
2870
+ encodingWidth: t.encodingWidth
2871
+ }));
2872
+ }
2873
+ }, cn = new TextDecoder("utf-8", {
2874
+ fatal: !0,
2875
+ ignoreBOM: !0
2876
+ });
2877
+ function J(e) {
2878
+ throw Error(`CBOR decode error: ${e}`);
2879
+ }
2880
+ function Y(e, t, n) {
2881
+ if (n <= 23) return {
2882
+ value: BigInt(n),
2883
+ nextOffset: t
2884
+ };
2885
+ switch (n) {
2886
+ case 24: return t + 1 > e.byteLength && J("unexpected end of input"), {
2887
+ value: BigInt(e.getUint8(t)),
2888
+ nextOffset: t + 1
2889
+ };
2890
+ case 25: return t + 2 > e.byteLength && J("unexpected end of input"), {
2891
+ value: BigInt(e.getUint16(t, !1)),
2892
+ nextOffset: t + 2
2893
+ };
2894
+ case 26: return t + 4 > e.byteLength && J("unexpected end of input"), {
2895
+ value: BigInt(e.getUint32(t, !1)),
2896
+ nextOffset: t + 4
2897
+ };
2898
+ case 27: return t + 8 > e.byteLength && J("unexpected end of input"), {
2899
+ value: e.getBigUint64(t, !1),
2900
+ nextOffset: t + 8
2901
+ };
2902
+ default: J(`reserved additional info value: ${n}`);
2903
+ }
2904
+ }
2905
+ function X(e, t, n) {
2906
+ let r = t, i = ln(e, t, n);
2907
+ return i.value.start = r, i.value.end = i.nextOffset, i;
2908
+ }
2909
+ function ln(e, t, n) {
2910
+ t >= e.byteLength && J("unexpected end of input");
2911
+ let r = e.getUint8(t++), i = r >> 5, a = r & 31;
2912
+ switch (i) {
2913
+ case 0: {
2914
+ let { value: n, nextOffset: r } = Y(e, t, a);
2915
+ return {
2916
+ value: new g(n),
2917
+ nextOffset: r
2918
+ };
2919
+ }
2920
+ case 1: {
2921
+ let { value: n, nextOffset: r } = Y(e, t, a);
2922
+ return {
2923
+ value: new _(-1n - n),
2924
+ nextOffset: r
2925
+ };
2926
+ }
2927
+ case 2: {
2928
+ if (a === 31) {
2929
+ let r = [], i = t;
2930
+ for (;;) {
2931
+ if (i >= e.byteLength && J("unexpected end of indefinite byte string"), e.getUint8(i) === 255) {
2932
+ i++;
2933
+ break;
2934
+ }
2935
+ let t = X(e, i, n);
2936
+ t.value instanceof w || J("indefinite-length byte string chunk must be a definite byte string"), r.push(t.value), i = t.nextOffset;
2937
+ }
2938
+ return {
2939
+ value: new T(r),
2940
+ nextOffset: i
2941
+ };
2942
+ }
2943
+ let { value: r, nextOffset: i } = Y(e, t, a), o = Number(r);
2944
+ return i + o > e.byteLength && J("byte string extends beyond input"), {
2945
+ value: new w(new Uint8Array(e.buffer, e.byteOffset + i, o).slice()),
2946
+ nextOffset: i + o
2947
+ };
2948
+ }
2949
+ case 3: {
2950
+ if (a === 31) {
2951
+ let r = [], i = t;
2952
+ for (;;) {
2953
+ if (i >= e.byteLength && J("unexpected end of indefinite text string"), e.getUint8(i) === 255) {
2954
+ i++;
2955
+ break;
2956
+ }
2957
+ let t = X(e, i, n);
2958
+ t.value instanceof F || J("indefinite-length text string chunk must be a definite text string"), r.push(t.value), i = t.nextOffset;
2959
+ }
2960
+ return {
2961
+ value: new E(r),
2962
+ nextOffset: i
2963
+ };
2964
+ }
2965
+ let { value: r, nextOffset: i } = Y(e, t, a), o = Number(r);
2966
+ i + o > e.byteLength && J("text string extends beyond input");
2967
+ let s = new Uint8Array(e.buffer, e.byteOffset + i, o), c;
2968
+ try {
2969
+ c = cn.decode(s);
2970
+ } catch {
2971
+ J("invalid UTF-8 sequence in text string");
2972
+ }
2973
+ return {
2974
+ value: new F(c),
2975
+ nextOffset: i + o
2976
+ };
2977
+ }
2978
+ case 4: {
2979
+ if (a === 31) {
2980
+ let r = [], i = t;
2981
+ for (;;) {
2982
+ if (i >= e.byteLength && J("unexpected end of indefinite array"), e.getUint8(i) === 255) {
2983
+ i++;
2984
+ break;
2985
+ }
2986
+ let t = X(e, i, n);
2987
+ r.push(t.value), i = t.nextOffset;
2988
+ }
2989
+ return {
2990
+ value: new D(r, { indefiniteLength: !0 }),
2991
+ nextOffset: i
2992
+ };
2993
+ }
2994
+ let { value: r, nextOffset: i } = Y(e, t, a), o = Number(r), s = [], c = i;
2995
+ for (let t = 0; t < o; t++) {
2996
+ let t = X(e, c, n);
2997
+ s.push(t.value), c = t.nextOffset;
2998
+ }
2999
+ return {
3000
+ value: new D(s),
3001
+ nextOffset: c
3002
+ };
3003
+ }
3004
+ case 5: {
3005
+ if (a === 31) {
3006
+ let r = [], i = t;
3007
+ for (;;) {
3008
+ if (i >= e.byteLength && J("unexpected end of indefinite map"), e.getUint8(i) === 255) {
3009
+ i++;
3010
+ break;
3011
+ }
3012
+ let t = X(e, i, n);
3013
+ i = t.nextOffset;
3014
+ let a = X(e, i, n);
3015
+ i = a.nextOffset, r.push([t.value, a.value]);
3016
+ }
3017
+ return {
3018
+ value: new O(r, { indefiniteLength: !0 }),
3019
+ nextOffset: i
3020
+ };
3021
+ }
3022
+ let { value: r, nextOffset: i } = Y(e, t, a), o = Number(r), s = [], c = i;
3023
+ for (let t = 0; t < o; t++) {
3024
+ let t = X(e, c, n);
3025
+ c = t.nextOffset;
3026
+ let r = X(e, c, n);
3027
+ c = r.nextOffset, s.push([t.value, r.value]);
3028
+ }
3029
+ return {
3030
+ value: new O(s),
3031
+ nextOffset: c
3032
+ };
3033
+ }
3034
+ case 6: {
3035
+ a === 31 && J("tags cannot use indefinite-length encoding");
3036
+ let { value: r, nextOffset: i } = Y(e, t, a), o = X(e, i, n);
3037
+ for (let e of [...n?.extensions ?? [], ...Z]) if (e.parseTag) {
3038
+ let t = e.parseTag(r, o.value);
3039
+ if (t !== void 0) return {
3040
+ value: t,
3041
+ nextOffset: o.nextOffset
3042
+ };
3043
+ }
3044
+ return {
3045
+ value: new C(r, o.value),
3046
+ nextOffset: o.nextOffset
3047
+ };
3048
+ }
3049
+ case 7:
3050
+ if (a <= 19) return {
3051
+ value: new k(a),
3052
+ nextOffset: t
3053
+ };
3054
+ if (a === 20) return {
3055
+ value: k.FALSE,
3056
+ nextOffset: t
3057
+ };
3058
+ if (a === 21) return {
3059
+ value: k.TRUE,
3060
+ nextOffset: t
3061
+ };
3062
+ if (a === 22) return {
3063
+ value: k.NULL,
3064
+ nextOffset: t
3065
+ };
3066
+ if (a === 23) return {
3067
+ value: k.UNDEFINED,
3068
+ nextOffset: t
3069
+ };
3070
+ if (a === 24) {
3071
+ t + 1 > e.byteLength && J("unexpected end of input");
3072
+ let n = e.getUint8(t);
3073
+ return n < 32 && J(`simple value ${n} must be encoded in initial byte (0–31 reserved for extended encoding)`), {
3074
+ value: new k(n),
3075
+ nextOffset: t + 1
3076
+ };
3077
+ }
3078
+ return a === 25 ? (t + 2 > e.byteLength && J("unexpected end of input"), {
3079
+ value: new S(te(e.getUint16(t, !1)), { precision: "half" }),
3080
+ nextOffset: t + 2
3081
+ }) : a === 26 ? (t + 4 > e.byteLength && J("unexpected end of input"), {
3082
+ value: new S(e.getFloat32(t, !1), { precision: "single" }),
3083
+ nextOffset: t + 4
3084
+ }) : a === 27 ? (t + 8 > e.byteLength && J("unexpected end of input"), {
3085
+ value: new S(e.getFloat64(t, !1), { precision: "double" }),
3086
+ nextOffset: t + 8
3087
+ }) : (a < 31 && J(`reserved additional info value in major type 7: ${a}`), J("unexpected break code outside indefinite-length item"));
3088
+ }
3089
+ return J(`unknown major type: ${i}`);
3090
+ }
3091
+ function un(e) {
3092
+ if (e instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && e instanceof SharedArrayBuffer) return new Uint8Array(e);
3093
+ if (ArrayBuffer.isView(e)) return new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
3094
+ throw TypeError("expected ArrayBufferView or ArrayBufferLike");
3095
+ }
3096
+ function dn(e, t) {
3097
+ let n = un(e), r = new DataView(n.buffer, n.byteOffset, n.byteLength), i = t?.offset ?? 0;
3098
+ if (!Number.isInteger(i) || i < 0 || i > r.byteLength) throw RangeError(`CBOR decode offset must be an integer between 0 and ${r.byteLength}`);
3099
+ let { value: a, nextOffset: o } = X(r, i, t);
3100
+ return !t?.allowTrailing && o !== r.byteLength && J(`${r.byteLength - o} trailing byte(s) after end of CBOR item`), a;
3101
+ }
3102
+ //#endregion
3103
+ //#region src/extensions/cbordata.ts
3104
+ var fn = 24n, Z = [
3105
+ bt,
3106
+ Pt,
3107
+ Lt,
3108
+ sn,
3109
+ {
3110
+ tagNumbers: [fn],
3111
+ parseTag(e, t) {
3112
+ if (e === 24n && t instanceof w) try {
3113
+ return new C(fn, new A([dn(t.value)]));
3114
+ } catch {
3115
+ return;
3116
+ }
3117
+ }
3118
+ }
3119
+ ];
3120
+ //#endregion
3121
+ //#region src/js/fromJS.ts
3122
+ function Q(e, t) {
3123
+ if (t?.replacer) {
3124
+ let { replacer: n, ...r } = t, i = hn(e, n, r.extensions, r.undefinedOmits);
3125
+ return i === l ? k.UNDEFINED : Q(i, Object.keys(r).length > 0 ? r : void 0);
3126
+ }
3127
+ return pn(e, t, !0);
3128
+ }
3129
+ function pn(e, t, n) {
3130
+ for (let n of [...t?.extensions ?? [], ...Z]) if (n.fromJS) {
3131
+ let r = n.fromJS(e, t ?? {});
3132
+ if (r !== void 0) return r;
3133
+ }
3134
+ if (n && typeof e == "object" && e && c.symbol in e) {
3135
+ let n = e[c.symbol], r = pn(e, t, !1);
3136
+ for (let e of [...t?.extensions ?? [], ...Z]) if (e.parseTag) {
3137
+ let t = e.parseTag(n, r);
3138
+ if (t !== void 0) return t;
3139
+ }
3140
+ return new C(n, r);
3141
+ }
3142
+ if (e instanceof c.Null) return k.NULL;
3143
+ if (e instanceof c.Undefined) return k.UNDEFINED;
3144
+ if (e instanceof u) return new k(e.value);
3145
+ if (e === null) return k.NULL;
3146
+ if (e === void 0) return k.UNDEFINED;
3147
+ if (e === !0) return k.TRUE;
3148
+ if (e === !1) return k.FALSE;
3149
+ if (typeof e == "bigint") return e > 18446744073709551615n ? new M(e) : e < -18446744073709551616n ? new N(e) : e >= 0n ? new g(e) : new _(e);
3150
+ if (typeof e == "number") return (t?.encodeIntegerAs ?? "int") === "int" && Number.isInteger(e) && !Object.is(e, -0) ? e >= 0 ? new g(BigInt(e)) : new _(BigInt(e)) : new S(e);
3151
+ if (typeof e == "string") return new F(e);
3152
+ if (e instanceof Number || e instanceof Boolean || e instanceof String || Object.prototype.toString.call(e) === "[object BigInt]") return pn(e.valueOf(), t, !1);
3153
+ if (e instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && e instanceof SharedArrayBuffer) return new w(new Uint8Array(e));
3154
+ if (ArrayBuffer.isView(e)) return e instanceof Uint8Array && t?.uint8ArrayAs === "array" ? new D(Array.from(e, (e) => new g(BigInt(e)))) : new w(new Uint8Array(e.buffer, e.byteOffset, e.byteLength));
3155
+ if (e instanceof $) return new O([...e].map(([e, n]) => [Q(e, t), Q(n, t)]));
3156
+ if (Array.isArray(e)) return new D(e.map((e) => Q(e, t)));
3157
+ if (typeof e == "object") {
3158
+ let n = [];
3159
+ for (let [r, i] of Object.entries(e)) n.push([new F(r), Q(i, t)]);
3160
+ return new O(n);
3161
+ }
3162
+ throw TypeError(`fromJS: unsupported value type: ${typeof e}`);
3163
+ }
3164
+ function mn(e) {
3165
+ 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 c.Null || e instanceof c.Undefined || e instanceof u;
3166
+ }
3167
+ function hn(e, t, n, r) {
3168
+ let i = [...n ?? [], ...Z];
3169
+ function a(e) {
3170
+ return e === l || r === !0 && e === void 0;
3171
+ }
3172
+ if (Array.isArray(t)) {
3173
+ let n = t.map(String);
3174
+ function r(e) {
3175
+ if (typeof e != "object" || !e) return e;
3176
+ if (e instanceof $) return $.from(e, ([e, t]) => [e, r(t)]);
3177
+ if (Array.isArray(e)) return e.map(r);
3178
+ if (c.symbol in e || mn(e) || i.some((t) => t.isJSType?.(e))) return e;
3179
+ let t = Object.getPrototypeOf(e);
3180
+ if (t === Object.prototype || t === null) {
3181
+ let t = e.toJSON;
3182
+ if (typeof t == "function") return r(t.call(e));
3183
+ }
3184
+ let a = {};
3185
+ for (let t of n) Object.prototype.hasOwnProperty.call(e, t) && (a[t] = r(e[t]));
3186
+ return a;
3187
+ }
3188
+ return r(e);
3189
+ }
3190
+ let o = t;
3191
+ function s(e, t, n) {
3192
+ if (typeof e == "object" && e && !(e instanceof $)) {
3193
+ let n = Object.getPrototypeOf(e);
3194
+ if (n === Object.prototype || n === null) {
3195
+ let n = e.toJSON;
3196
+ typeof n == "function" && (e = n.call(e, t));
3197
+ }
3198
+ }
3199
+ if (e = o.call(n, t, e), typeof e == "object" && e) {
3200
+ if (c.symbol in e) return e;
3201
+ if (e instanceof $) {
3202
+ let t = new $();
3203
+ for (let [n, r] of e) {
3204
+ let i = s(r, n, e);
3205
+ a(i) || t.push([n, i]);
3206
+ }
3207
+ return t;
3208
+ }
3209
+ if (Array.isArray(e)) return e.map((t, n) => {
3210
+ let r = s(t, String(n), e);
3211
+ return a(r) ? null : r;
3212
+ });
3213
+ if (mn(e) || i.some((t) => t.isJSType?.(e))) return e;
3214
+ let t = {};
3215
+ for (let n of Object.keys(e)) {
3216
+ let r = s(e[n], n, e);
3217
+ a(r) || (t[n] = r);
3218
+ }
3219
+ return t;
3220
+ }
3221
+ return e;
3222
+ }
3223
+ return s(e, "", { "": e });
3224
+ }
3225
+ //#endregion
3226
+ //#region src/mapEntries.ts
3227
+ var $ = class extends Array {
3228
+ toJSON() {
3229
+ let e = {};
3230
+ for (let [t, n] of this) {
3231
+ let r = typeof t == "string" ? t : Q(t).toEDN();
3232
+ r === "__proto__" ? Object.defineProperty(e, r, {
3233
+ value: n,
3234
+ writable: !0,
3235
+ enumerable: !0,
3236
+ configurable: !0
3237
+ }) : e[r] = n;
3238
+ }
3239
+ return e;
3240
+ }
3241
+ };
3242
+ //#endregion
3243
+ export { l as C, n as D, c as E, u as S, t as T, C as _, xt as a, g as b, N as c, k as d, O as f, w as g, T as h, dn as i, M as l, E as m, hn as n, F as o, D as p, Q as r, He as s, $ as t, A as u, S as v, e as w, d as x, _ as y };
3244
+
3245
+ //# sourceMappingURL=mapEntries-D5MWtXqq.js.map