@cbortech/cbor 0.26.3 → 0.26.5

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.
@@ -98,7 +98,9 @@ var m = class {
98
98
  //#region src/cdn/serialize-utils.ts
99
99
  function _(e) {
100
100
  let t = e?.indent;
101
- return t === void 0 ? null : typeof t == "number" ? " ".repeat(t) : t;
101
+ if (t === void 0) return null;
102
+ let n = typeof t == "number" ? " ".repeat(t) : t;
103
+ return n === "" ? null : n;
102
104
  }
103
105
  function v(e, t) {
104
106
  return e.repeat(t);
@@ -143,9 +145,7 @@ function ae(e, t = !1) {
143
145
  };
144
146
  }
145
147
  function x(e) {
146
- let { options: t, depth: n, openChar: r, closeChar: i, count: a } = e, o = _(t), s = t?.preserveComments, c = typeof s == "string" ? s : void 0, l = s && (te(e.node) || e.hasEntryComments());
147
- o === null && l && (o = " ");
148
- let { inlineSep: u, multilineSep: d, trailSep: f, colSep: p } = ae(t, o === null), m = e.indefiniteLength ? "" : w(t, e.encodingWidth, () => C(BigInt(a))), h = m ? m + " " : "", g = e.indefiniteLength && (t?.encodingIndicators ?? "auto") !== "never", ee = (t) => e.indefiniteLength ? g ? a === 0 ? `${r}_ ${i}` : `${r}_ ${t}${i}` : `${r}${t}${i}` : `${r}${h}${t}${i}`;
148
+ let { options: t, depth: n, openChar: r, closeChar: i, count: a } = e, o = _(t), s = t?.preserveComments, c = typeof s == "string" ? s : void 0, l = o !== null && s && (te(e.node) || e.hasEntryComments()), { inlineSep: u, multilineSep: d, trailSep: f, colSep: p } = ae(t, o === null), m = e.indefiniteLength ? "" : w(t, e.encodingWidth, () => C(BigInt(a))), h = m ? m + " " : "", g = e.indefiniteLength && (t?.encodingIndicators ?? "auto") !== "never", ee = (t) => e.indefiniteLength ? g ? a === 0 ? `${r}_ ${i}` : `${r}_ ${t}${i}` : `${r}${t}${i}` : `${r}${h}${t}${i}`;
149
149
  if (o === null || a === 0 && !l) {
150
150
  let t = "";
151
151
  for (let n = 0; n < a; n++) n > 0 && (t += u), t += e.renderEntry(n, p);
@@ -463,7 +463,7 @@ var k = class e {
463
463
  ...this._defaults,
464
464
  ...e
465
465
  } : e, n = this._toCDN(t, 0), r = t?.preserveComments;
466
- if (!r) return n;
466
+ if (!r || _(t) === null) return n;
467
467
  let i = typeof r == "string" ? r : void 0, a = this.comments?.leading?.map((e) => b(e, i)) ?? [], o = this.comments?.trailing ?? [], s = o.length === 0 ? n : `${n} ${o.map((e) => b(e, i).trimEnd()).join(" ")}`;
468
468
  return [...a, s].join("\n");
469
469
  }
@@ -612,14 +612,15 @@ var M = class extends k {
612
612
  }
613
613
  _toCDN(e, t) {
614
614
  let n = e?.encodingIndicators ?? "auto";
615
- if (e?.appStrings !== !1 && this.ednSource !== void 0) {
616
- if (n === "never") return this.ednSource.replace(/_[0-3i]$/, "");
615
+ if (e?.appStrings !== !1 && this.ednSource !== void 0 && (_(e) !== null || !/[\r\n]/.test(this.ednSource))) {
616
+ let e = this.ednSource;
617
+ if (n === "never") return e.replace(/_[0-3i]$/, "");
617
618
  if (n === "always") {
618
- if (/_[0-3i]$/.test(this.ednSource)) return this.ednSource;
619
- let e = this.precision ?? Le(this.value), t = e === "half" ? "_1" : e === "single" ? "_2" : "_3";
620
- return this.ednSource + t;
619
+ if (/_[0-3i]$/.test(e)) return e;
620
+ let t = this.precision ?? Le(this.value);
621
+ return e + (t === "half" ? "_1" : t === "single" ? "_2" : "_3");
621
622
  }
622
- return this.ednSource;
623
+ return e;
623
624
  }
624
625
  let r = Le(this.value);
625
626
  return (e?.floatFormat === "hex" ? Be(this.value) : be(this.value)) + xe(this.value, this.precision, r, n);
@@ -674,19 +675,20 @@ var M = class extends k {
674
675
  O(e, 2, this.value.length, this.encodingWidth), e.writeBytes(this.value);
675
676
  }
676
677
  _toCDN(e, t) {
677
- if (e?.preserveConcatenation && this.ednParts !== void 0 && this.ednParts.length > 1) {
678
- let n = w(e, this.encodingWidth, () => C(BigInt(this.value.length))), r = e?.bstrEncoding ?? this.ednEncoding;
679
- e?.appStrings === !1 && r !== "hex" && (r = "hex");
680
- let i = this.ednParts.map((t) => e?.preserveByteString && t.source !== void 0 ? t.source : fe(t.bytes, r, e?.sqstr));
681
- return i[i.length - 1] += n, ee(i, _(e), t);
682
- }
683
- if (e?.preserveByteString && this.ednSource !== void 0) {
678
+ let n = _(e);
679
+ if (e?.preserveConcatenation && n !== null && this.ednParts !== void 0 && this.ednParts.length > 1) {
680
+ let r = w(e, this.encodingWidth, () => C(BigInt(this.value.length))), i = e?.bstrEncoding ?? this.ednEncoding;
681
+ e?.appStrings === !1 && i !== "hex" && (i = "hex");
682
+ let a = this.ednParts.map((t) => e?.preserveByteString && t.source !== void 0 ? t.source : fe(t.bytes, i, e?.sqstr));
683
+ return a[a.length - 1] += r, ee(a, n, t);
684
+ }
685
+ if (e?.preserveByteString && this.ednSource !== void 0 && (n !== null || !/[\r\n]/.test(this.ednSource))) {
684
686
  if (/_[0-3i]$/.test(this.ednSource)) return (e?.encodingIndicators ?? "auto") === "never" ? this.ednSource.replace(/_[0-3i]$/, "") : this.ednSource;
685
687
  let t = w(e, this.encodingWidth, () => C(BigInt(this.value.length)));
686
688
  return this.ednSource + t;
687
689
  }
688
- let n = w(e, this.encodingWidth, () => C(BigInt(this.value.length))), r = e?.bstrEncoding ?? this.ednEncoding;
689
- return e?.appStrings === !1 && r !== "hex" && (r = "hex"), fe(this.value, r, e?.sqstr) + n;
690
+ let r = w(e, this.encodingWidth, () => C(BigInt(this.value.length))), i = e?.bstrEncoding ?? this.ednEncoding;
691
+ return e?.appStrings === !1 && i !== "hex" && (i = "hex"), fe(this.value, i, e?.sqstr) + r;
690
692
  }
691
693
  _toJS(e) {
692
694
  return this.value;
@@ -1076,7 +1078,7 @@ var z = class e extends k {
1076
1078
  }
1077
1079
  _toCDN(e, t) {
1078
1080
  let n = e?.encodingIndicators ?? "auto";
1079
- return e?.appStrings !== !1 && n === "auto" ? this.ednSource : this.inner._toCDN(e, t);
1081
+ return e?.appStrings !== !1 && n === "auto" && (_(e) !== null || !/[\r\n]/.test(this.ednSource)) ? this.ednSource : this.inner._toCDN(e, t);
1080
1082
  }
1081
1083
  _toJS(e) {
1082
1084
  return this.inner._toJS(e);
@@ -1823,7 +1825,8 @@ var pt = (e) => `import { ${e} } from '@cbortech/cbor' and pass it via the 'exte
1823
1825
  let r = `app-string prefix '${e}' requires an extension that is not enabled; ${n}`;
1824
1826
  this._options.onWarning ? this._options.onWarning({
1825
1827
  message: r,
1826
- ..._t(t)
1828
+ ..._t(t),
1829
+ hint: !0
1827
1830
  }) : this._options.silent || console.warn(`CDN: ${r}`);
1828
1831
  }
1829
1832
  _warn(e, t) {
@@ -1870,25 +1873,22 @@ var vt = new TextEncoder(), yt = !1, H = class extends k {
1870
1873
  }
1871
1874
  };
1872
1875
  function bt(e, t, n, r, i, a, o) {
1873
- if (n?.preserveRawString && a !== void 0) return a + t;
1874
- let s = n?.preserveRawString ? o : void 0, c = s?.some((e) => e !== void 0) ?? !1, { cdn: l, newline: u } = St(n), d = _(n), f = n?.preserveConcatenation && i !== void 0 && (i.length > 1 || c) ? i : void 0;
1875
- if (d === null) return f === void 0 ? ye(e) + t : xt(f.map((e, t) => ({
1876
- text: e,
1877
- contentDepth: 0,
1878
- source: s?.[t]
1879
- })), t, null, r);
1880
- if (!l && !u && f === void 0) return ye(e) + t;
1881
- let p = l ? Tt(e) : null;
1882
- if (f !== void 0 && (p === null || c)) {
1876
+ let s = _(n);
1877
+ if (n?.preserveRawString && a !== void 0 && (s !== null || !/[\r\n]/.test(a))) return a + t;
1878
+ if (s === null) return ye(e) + t;
1879
+ let c = n?.preserveRawString ? o : void 0, l = c?.some((e) => e !== void 0) ?? !1, { cdn: u, newline: d } = St(n), f = n?.preserveConcatenation && i !== void 0 && (i.length > 1 || l) ? i : void 0;
1880
+ if (!u && !d && f === void 0) return ye(e) + t;
1881
+ let p = u ? Tt(e) : null;
1882
+ if (f !== void 0 && (p === null || l)) {
1883
1883
  let e = [];
1884
1884
  for (let [t, n] of f.entries()) {
1885
- let r = s?.[t];
1885
+ let r = c?.[t];
1886
1886
  if (r !== void 0) e.push({
1887
1887
  text: n,
1888
1888
  contentDepth: 0,
1889
1889
  source: r
1890
1890
  });
1891
- else if (u) {
1891
+ else if (d) {
1892
1892
  let t = /* @__PURE__ */ new Map();
1893
1893
  for (let { point: e, contentDepth: r } of wt(n, 0)) t.set(e, r);
1894
1894
  e.push(...Nt(n, t));
@@ -1897,24 +1897,22 @@ function bt(e, t, n, r, i, a, o) {
1897
1897
  contentDepth: 0
1898
1898
  });
1899
1899
  }
1900
- return xt(e, t, d, r);
1900
+ return xt(e, t, s, r);
1901
1901
  }
1902
1902
  let m = /* @__PURE__ */ new Map();
1903
1903
  if (p !== null) for (let { point: e, contentDepth: t } of p) m.set(e, t);
1904
- if (u) {
1904
+ if (d) {
1905
1905
  let t = p === null ? wt(e, 0) : Et(e);
1906
1906
  for (let { point: e, contentDepth: n } of t) m.has(e) || m.set(e, n);
1907
1907
  }
1908
1908
  let h = Nt(e, m);
1909
- return h.length <= 1 ? ye(e) + t : xt(h, t, d, r);
1909
+ return h.length <= 1 ? ye(e) + t : xt(h, t, s, r);
1910
1910
  }
1911
1911
  function xt(e, t, n, r) {
1912
1912
  let i = e.map(({ text: n, source: r }, i) => {
1913
1913
  let a = r ?? ye(n);
1914
1914
  return i === e.length - 1 ? a + t : a;
1915
- });
1916
- if (n === null) return i.join(" + ");
1917
- let a = i[0];
1915
+ }), a = i[0];
1918
1916
  for (let t = 1; t < i.length; t++) {
1919
1917
  let o = v(n, r + 1 + e[t].contentDepth);
1920
1918
  a += ` +\n${o}${i[t]}`;
@@ -3017,17 +3015,25 @@ var or = 24n, sr = {
3017
3015
  tagNumbers: [or],
3018
3016
  parseTag(e, t, n) {
3019
3017
  if (e !== 24n || !(t instanceof P)) return;
3020
- let r = n ? {
3018
+ let r = (t.end ?? t.value.length) - t.value.length, i = n ? {
3021
3019
  extensions: n.extensions,
3022
3020
  builtinExtensions: n.builtinExtensions,
3023
3021
  strict: n.strict,
3024
- onWarning: n.onWarning,
3022
+ onWarning: n.onWarning ? (e) => n.onWarning({
3023
+ ...e,
3024
+ offset: e.offset + r
3025
+ }) : void 0,
3025
3026
  silent: n.silent
3026
3027
  } : void 0;
3027
3028
  try {
3028
- return new N(or, new He([ar(t.value, r)], { encodingWidth: t.encodingWidth }));
3029
+ return new N(or, new He([ar(t.value, i)], { encodingWidth: t.encodingWidth }));
3029
3030
  } catch (e) {
3030
- if (r?.strict !== !1) throw e;
3031
+ if (i?.strict !== !1) throw e;
3032
+ let t = `tag 24 content is not valid CBOR: ${e instanceof Error ? e.message : String(e)}`, a = {
3033
+ message: t,
3034
+ offset: r
3035
+ };
3036
+ n?.onWarning ? n.onWarning(a) : n?.silent || console.warn(`CBOR strict violation at offset ${a.offset}: ${t}`);
3031
3037
  return;
3032
3038
  }
3033
3039
  }
@@ -3509,4 +3515,4 @@ var $ = class extends Array {
3509
3515
  //#endregion
3510
3516
  export { A, L as C, N as D, P as E, s as F, m as I, c as L, g as M, h as N, M as O, o as P, R as S, F as T, it as _, zr as a, He as b, kr as c, ar as d, Ln as f, H as g, Kt as h, Vr as i, k as j, j as k, xr as l, Gt as m, Jr as n, Ar as o, un as p, Kr as r, Or as s, $ as t, br as u, et as v, I as w, z as x, $e as y };
3511
3517
 
3512
- //# sourceMappingURL=mapEntries-BZCOgqIt.js.map
3518
+ //# sourceMappingURL=mapEntries-Clr-oNtQ.js.map