@prose-reader/streamer 1.164.0 → 1.166.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.
package/dist/index.js CHANGED
@@ -1,20 +1,20 @@
1
- import $, { XmlDocument as de, XmlTextNode as le, XmlElement as pe } from "xmldoc";
2
- import { urlJoin as k, isXmlBasedMimeType as fe, parseContentType as ue, detectMimeTypeFromName as O } from "@prose-reader/shared";
1
+ import $, { XmlDocument as de, XmlTextNode as le, XmlElement as fe } from "xmldoc";
2
+ import { urlJoin as k, isXmlBasedMimeType as pe, parseContentType as ue, detectMimeTypeFromName as O } from "@prose-reader/shared";
3
3
  import { Subject as R, mergeMap as M, EMPTY as _, pairwise as me, filter as j, startWith as he, from as P, tap as D, catchError as I, switchMap as W, merge as q, takeUntil as ge, map as F, ignoreElements as ye, first as be, BehaviorSubject as we, distinctUntilChanged as ve, shareReplay as $e, NEVER as G, timer as xe, finalize as K, of as J, lastValueFrom as Y } from "rxjs";
4
4
  let T = !1;
5
5
  const w = {
6
6
  enable: (e) => {
7
7
  T = e;
8
8
  },
9
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
10
10
  log: (...e) => {
11
11
  T && console.log("[prose-reader-streamer]", ...e);
12
12
  },
13
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
14
14
  warn: (...e) => {
15
15
  T && console.warn("[prose-reader-streamer]", ...e);
16
16
  },
17
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
18
18
  error: (...e) => {
19
19
  console.error(...e);
20
20
  },
@@ -34,10 +34,10 @@ const w = {
34
34
  `${e.name} took ${e.duration}ms which is above the ${t}ms target for this function`
35
35
  ));
36
36
  },
37
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- measurePerformance: (e, t = 10, i) => (...r) => {
37
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
38
+ measurePerformance: (e, t, i) => (...r) => {
39
39
  const n = performance.now(), s = i(...r);
40
- if (s && s.then)
40
+ if (s != null && s.then)
41
41
  return s.then((a) => {
42
42
  const c = performance.now();
43
43
  return w.metric({ name: e, duration: c - n }, t), a;
@@ -84,7 +84,7 @@ const w = {
84
84
  };
85
85
  }
86
86
  return i;
87
- }, ee = (e) => e ? e.children.map((t) => t instanceof le ? t.text : t instanceof pe ? ee(t) : "").join("").trim() : "", A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Q = (e) => e.endsWith("/") ? e.slice(0, -1) : e, ke = (e) => {
87
+ }, ee = (e) => e ? e.children.map((t) => t instanceof le ? t.text : t instanceof fe ? ee(t) : "").join("").trim() : "", A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Q = (e) => e.endsWith("/") ? e.slice(0, -1) : e, ke = (e) => {
88
88
  const t = e.lastIndexOf("/");
89
89
  return t >= 0 ? e.substring(0, t) : "";
90
90
  }, te = (e, { basePath: t, baseUrl: i }) => {
@@ -144,7 +144,7 @@ const w = {
144
144
  var o;
145
145
  const r = [], n = e.name;
146
146
  let s = "";
147
- return n.indexOf(":") !== -1 && (s = n.split(":")[0] + ":"), (o = e.childNamed(`${s}navMap`)) == null || o.childrenNamed(`${s}navPoint`).forEach(
147
+ return n.indexOf(":") !== -1 && (s = `${n.split(":")[0]}:`), (o = e.childNamed(`${s}navMap`)) == null || o.childrenNamed(`${s}navPoint`).forEach(
148
148
  (a) => r.push(ne(a, { opfBasePath: t, baseUrl: i, prefix: s }))
149
149
  ), r;
150
150
  }, Ie = async ({
@@ -154,7 +154,7 @@ const w = {
154
154
  archive: r
155
155
  }) => {
156
156
  var o;
157
- const n = e.childNamed("spine"), s = n && n.attr.toc;
157
+ const n = e.childNamed("spine"), s = n == null ? void 0 : n.attr.toc;
158
158
  if (s) {
159
159
  const a = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((c) => c.attr.id === s);
160
160
  if (a) {
@@ -174,7 +174,10 @@ const w = {
174
174
  archive: t,
175
175
  baseUrl: i
176
176
  });
177
- return n || await Se(e, t, { opfBasePath: r, baseUrl: i });
177
+ return n || await Se(e, t, {
178
+ opfBasePath: r,
179
+ baseUrl: i
180
+ });
178
181
  }, Re = (e) => {
179
182
  var r;
180
183
  const t = ((r = e.attr.properties) == null ? void 0 : r.split(" ")) || [];
@@ -196,7 +199,7 @@ const w = {
196
199
  const { data: t, basePath: i } = N(e), r = await (t == null ? void 0 : t.string());
197
200
  if (!r) return [];
198
201
  const n = new $.XmlDocument(r), s = n.childNamed("manifest"), o = n.childNamed("spine"), a = o == null ? void 0 : o.childrenNamed("itemref").map((d) => d.attr.idref), c = (s == null ? void 0 : s.childrenNamed("item").filter((d) => a.includes(d.attr.id || ""))) || [];
199
- return e.files.filter((d) => c.find((p) => i ? `${i}/${p.attr.href}` === d.uri : `${p.attr.href}` === d.uri));
202
+ return e.files.filter((d) => c.find((f) => i ? `${i}/${f.attr.href}` === d.uri : `${f.attr.href}` === d.uri));
200
203
  }, je = (e, t, i) => {
201
204
  const r = e.attr.href || "", n = i == null ? void 0 : i(e);
202
205
  return {
@@ -215,7 +218,7 @@ const w = {
215
218
  return i;
216
219
  const s = await r.string();
217
220
  w.log("data", s);
218
- const o = new $.XmlDocument(s), a = await Ce(o, e, { baseUrl: t }) || [], c = o.childNamed("metadata"), l = o.childNamed("manifest"), d = o.childNamed("spine"), p = o.childNamed("guide"), u = c == null ? void 0 : c.childNamed("dc:title"), g = (c == null ? void 0 : c.childrenNamed("meta")) || [], b = g.find(
221
+ const o = new $.XmlDocument(s), a = await Ce(o, e, { baseUrl: t }) || [], c = o.childNamed("metadata"), l = o.childNamed("manifest"), d = o.childNamed("spine"), f = o.childNamed("guide"), u = c == null ? void 0 : c.childNamed("dc:title"), g = (c == null ? void 0 : c.childrenNamed("meta")) || [], b = g.find(
219
222
  (m) => m.attr.property === "rendition:layout"
220
223
  ), h = g.find(
221
224
  (m) => m.attr.property === "rendition:flow"
@@ -240,23 +243,23 @@ const w = {
240
243
  */
241
244
  spineItems: (d == null ? void 0 : d.childrenNamed("itemref").map((m, L) => {
242
245
  var V, E;
243
- const f = l == null ? void 0 : l.childrenNamed("item").find((C) => C.attr.id === (m == null ? void 0 : m.attr.idref)), B = (f == null ? void 0 : f.attr.href) || "", ce = ((V = e.files.find((C) => C.uri.endsWith(B))) == null ? void 0 : V.size) || 0, H = t || (/^https?:\/\//.test(B) ? "" : "file://"), U = Re(m);
246
+ const p = l == null ? void 0 : l.childrenNamed("item").find((C) => C.attr.id === (m == null ? void 0 : m.attr.idref)), B = (p == null ? void 0 : p.attr.href) || "", ce = ((V = e.files.find((C) => C.uri.endsWith(B))) == null ? void 0 : V.size) || 0, H = t || (/^https?:\/\//.test(B) ? "" : "file://"), U = Re(m);
244
247
  return {
245
248
  ...U,
246
- id: (f == null ? void 0 : f.attr.id) || "",
249
+ id: (p == null ? void 0 : p.attr.id) || "",
247
250
  index: L,
248
- href: (E = f == null ? void 0 : f.attr.href) != null && E.startsWith("https://") ? f == null ? void 0 : f.attr.href : n ? `${H}${n}/${f == null ? void 0 : f.attr.href}` : `${H}${f == null ? void 0 : f.attr.href}`,
251
+ href: (E = p == null ? void 0 : p.attr.href) != null && E.startsWith("https://") ? p == null ? void 0 : p.attr.href : n ? `${H}${n}/${p == null ? void 0 : p.attr.href}` : `${H}${p == null ? void 0 : p.attr.href}`,
249
252
  renditionLayout: U.renditionLayout ?? y,
250
253
  progressionWeight: ce / ae,
251
254
  // size: itemSize
252
- mediaType: f == null ? void 0 : f.attr["media-type"]
255
+ mediaType: p == null ? void 0 : p.attr["media-type"]
253
256
  };
254
257
  })) || [],
255
258
  items: se(o, e, (m) => {
256
259
  const L = m.attr.href || "";
257
260
  return /^https?:\/\//.test(L) ? "" : t || "file://";
258
261
  }),
259
- guide: p == null ? void 0 : p.childrenNamed("reference").map((m) => ({
262
+ guide: f == null ? void 0 : f.childrenNamed("reference").map((m) => ({
260
263
  href: m.attr.href || "",
261
264
  title: m.attr.title || "",
262
265
  type: m.attr.type
@@ -455,7 +458,7 @@ const w = {
455
458
  const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((r) => r.attr.name === "viewport");
456
459
  return !!(t && t.attr.name === "viewport");
457
460
  }, _e = (e) => e.reduce(async (t, i) => {
458
- if (!await t || !fe({
461
+ if (!await t || !pe({
459
462
  mimeType: i.encodingFormat,
460
463
  uri: i.uri
461
464
  }))
@@ -487,10 +490,10 @@ const w = {
487
490
  if (i.nav) return i;
488
491
  const r = [...e.files].sort(
489
492
  (a, c) => z(a.uri, c.uri)
490
- ), n = Object.values(r), s = (a, c, l, d, p) => {
493
+ ), n = Object.values(r), s = (a, c, l, d, f) => {
491
494
  const u = a.find((h) => h.title === c), [g, ...b] = l;
492
495
  return u ? g ? [
493
- ...a.filter((x) => x != u),
496
+ ...a.filter((x) => x !== u),
494
497
  {
495
498
  ...u,
496
499
  contents: [
@@ -500,15 +503,15 @@ const w = {
500
503
  g,
501
504
  b,
502
505
  d,
503
- p
506
+ f
504
507
  )
505
508
  ]
506
509
  }
507
- ] : u.path.split("/").length > p.split("/").length ? [
508
- ...a.filter((x) => x != u),
510
+ ] : u.path.split("/").length > f.split("/").length ? [
511
+ ...a.filter((x) => x !== u),
509
512
  {
510
513
  ...u,
511
- path: p,
514
+ path: f,
512
515
  href: d
513
516
  }
514
517
  ] : a : g ? [
@@ -519,10 +522,10 @@ const w = {
519
522
  g,
520
523
  b,
521
524
  d,
522
- p
525
+ f
523
526
  ),
524
527
  href: d,
525
- path: p,
528
+ path: f,
526
529
  title: c
527
530
  }
528
531
  ] : [
@@ -530,17 +533,17 @@ const w = {
530
533
  {
531
534
  contents: [],
532
535
  href: d,
533
- path: p,
536
+ path: f,
534
537
  title: c
535
538
  }
536
539
  ];
537
540
  }, o = n.reduce(
538
541
  (a, c) => {
539
542
  if (c.dir) return a;
540
- const d = c.uri.split("/").slice(0, -1), [p, ...u] = d;
541
- if (p) {
543
+ const d = c.uri.split("/").slice(0, -1), [f, ...u] = d;
544
+ if (f) {
542
545
  const g = k(t, encodeURI(c.uri)).replace(/\/$/, ""), b = c.uri.replace(/\/$/, "");
543
- return s(a, p, u, g, b);
546
+ return s(a, f, u, g, b);
544
547
  }
545
548
  return a;
546
549
  },
@@ -721,7 +724,6 @@ const w = {
721
724
  stream: s.internalStream
722
725
  },
723
726
  // this is private API
724
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
725
727
  // @ts-ignore
726
728
  size: s._data.uncompressedSize
727
729
  })),
@@ -742,7 +744,7 @@ const w = {
742
744
  }))
743
745
  };
744
746
  return w.log("Generated archive", r), r;
745
- }, pt = async (e, { orderByAlpha: t, name: i } = {}) => {
747
+ }, ft = async (e, { orderByAlpha: t, name: i } = {}) => {
746
748
  let r = e;
747
749
  return t && (r = r.slice().sort((n, s) => z(n.name, s.name))), {
748
750
  filename: i || "",
@@ -762,7 +764,7 @@ const w = {
762
764
  })),
763
765
  close: () => Promise.resolve()
764
766
  };
765
- }, ft = ({
767
+ }, pt = ({
766
768
  enableReport: e
767
769
  } = {}) => {
768
770
  w.enable(!!e);
@@ -807,11 +809,11 @@ const tt = ({
807
809
  M((l) => {
808
810
  const d = s[l];
809
811
  if (!d || d.state.status !== "idle") return _;
810
- let p = !1;
812
+ let f = !1;
811
813
  const u = (y) => {
812
814
  var S;
813
815
  const v = s[y];
814
- delete s[y], p || ((S = v == null ? void 0 : v.state.archive) == null || S.close(), p = !0);
816
+ delete s[y], f || ((S = v == null ? void 0 : v.state.archive) == null || S.close(), f = !0);
815
817
  };
816
818
  d.update({
817
819
  status: "loading"
@@ -848,20 +850,20 @@ const tt = ({
848
850
  ge(r)
849
851
  ), a = (l) => {
850
852
  let d = !1;
851
- const p = s[l] ?? new et(t);
852
- s[l] = p, p.update({
853
- locks: p.state.locks + 1
853
+ const f = s[l] ?? new et(t);
854
+ s[l] = f, f.update({
855
+ locks: f.state.locks + 1
854
856
  });
855
857
  const u = () => {
856
- d || (d = !0, p.update({
857
- locks: p.state.locks - 1
858
+ d || (d = !0, f.update({
859
+ locks: f.state.locks - 1
858
860
  }));
859
861
  };
860
862
  i.next(l);
861
- const g = p.state$.pipe(
863
+ const g = f.state$.pipe(
862
864
  F(({ archive: h }) => h),
863
865
  j((h) => !!h)
864
- ), b = p.state$.pipe(
866
+ ), b = f.state$.pipe(
865
867
  D(({ error: h }) => {
866
868
  if (h)
867
869
  throw h;
@@ -981,8 +983,8 @@ class ut extends nt {
981
983
  export {
982
984
  ut as ServiceWorkerStreamer,
983
985
  nt as Streamer,
984
- ft as configure,
985
- pt as createArchiveFromArrayBufferList,
986
+ pt as configure,
987
+ ft as createArchiveFromArrayBufferList,
986
988
  dt as createArchiveFromJszip,
987
989
  lt as createArchiveFromLibArchive,
988
990
  ct as createArchiveFromText,