@cbortech/cbor 0.26.4 → 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);
@@ -1871,25 +1873,22 @@ var vt = new TextEncoder(), yt = !1, H = class extends k {
1871
1873
  }
1872
1874
  };
1873
1875
  function bt(e, t, n, r, i, a, o) {
1874
- if (n?.preserveRawString && a !== void 0) return a + t;
1875
- 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;
1876
- if (d === null) return f === void 0 ? ye(e) + t : xt(f.map((e, t) => ({
1877
- text: e,
1878
- contentDepth: 0,
1879
- source: s?.[t]
1880
- })), t, null, r);
1881
- if (!l && !u && f === void 0) return ye(e) + t;
1882
- let p = l ? Tt(e) : null;
1883
- 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)) {
1884
1883
  let e = [];
1885
1884
  for (let [t, n] of f.entries()) {
1886
- let r = s?.[t];
1885
+ let r = c?.[t];
1887
1886
  if (r !== void 0) e.push({
1888
1887
  text: n,
1889
1888
  contentDepth: 0,
1890
1889
  source: r
1891
1890
  });
1892
- else if (u) {
1891
+ else if (d) {
1893
1892
  let t = /* @__PURE__ */ new Map();
1894
1893
  for (let { point: e, contentDepth: r } of wt(n, 0)) t.set(e, r);
1895
1894
  e.push(...Nt(n, t));
@@ -1898,24 +1897,22 @@ function bt(e, t, n, r, i, a, o) {
1898
1897
  contentDepth: 0
1899
1898
  });
1900
1899
  }
1901
- return xt(e, t, d, r);
1900
+ return xt(e, t, s, r);
1902
1901
  }
1903
1902
  let m = /* @__PURE__ */ new Map();
1904
1903
  if (p !== null) for (let { point: e, contentDepth: t } of p) m.set(e, t);
1905
- if (u) {
1904
+ if (d) {
1906
1905
  let t = p === null ? wt(e, 0) : Et(e);
1907
1906
  for (let { point: e, contentDepth: n } of t) m.has(e) || m.set(e, n);
1908
1907
  }
1909
1908
  let h = Nt(e, m);
1910
- 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);
1911
1910
  }
1912
1911
  function xt(e, t, n, r) {
1913
1912
  let i = e.map(({ text: n, source: r }, i) => {
1914
1913
  let a = r ?? ye(n);
1915
1914
  return i === e.length - 1 ? a + t : a;
1916
- });
1917
- if (n === null) return i.join(" + ");
1918
- let a = i[0];
1915
+ }), a = i[0];
1919
1916
  for (let t = 1; t < i.length; t++) {
1920
1917
  let o = v(n, r + 1 + e[t].contentDepth);
1921
1918
  a += ` +\n${o}${i[t]}`;
@@ -3518,4 +3515,4 @@ var $ = class extends Array {
3518
3515
  //#endregion
3519
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 };
3520
3517
 
3521
- //# sourceMappingURL=mapEntries-hyNVtz5Z.js.map
3518
+ //# sourceMappingURL=mapEntries-Clr-oNtQ.js.map