@prose-reader/streamer 1.84.0 → 1.86.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.
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { urlJoin as N, PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME as ie, isXmlBasedMimeType as oe, detectMimeTypeFromName as M } from "@prose-reader/shared";
2
2
  import y, { XmlDocument as ce } from "xmldoc";
3
- import { Subject as V, mergeMap as R, EMPTY as de, from as A, map as v, catchError as F, NEVER as U, shareReplay as le, switchMap as X, timer as me, tap as B, merge as _, takeUntil as pe, BehaviorSubject as fe, filter as ue, ignoreElements as he, first as ge, finalize as H, of as E, lastValueFrom as G } from "rxjs";
3
+ import { Subject as U, mergeMap as I, EMPTY as de, from as L, map as v, catchError as F, NEVER as V, shareReplay as le, switchMap as X, timer as me, tap as B, merge as _, takeUntil as pe, BehaviorSubject as fe, filter as ue, ignoreElements as he, first as ge, finalize as H, of as E, lastValueFrom as G } from "rxjs";
4
4
  let x = !1;
5
5
  const g = {
6
6
  enable: (e) => {
@@ -39,8 +39,8 @@ const g = {
39
39
  const t = performance.now(), a = s(...r);
40
40
  if (a && a.then)
41
41
  return a.then((o) => {
42
- const c = performance.now();
43
- return g.metric({ name: e, duration: c - t }, n), o;
42
+ const d = performance.now();
43
+ return g.metric({ name: e, duration: d - t }, n), o;
44
44
  });
45
45
  const i = performance.now();
46
46
  return g.metric({ name: e, duration: i - t }, n), a;
@@ -105,7 +105,7 @@ const g = {
105
105
  if (i) {
106
106
  const o = i.childrenNamed("li");
107
107
  o && o.length > 0 && (r.contents = o.map(
108
- (c) => q(c, { opfBasePath: n, baseUrl: s })
108
+ (d) => q(d, { opfBasePath: n, baseUrl: s })
109
109
  ));
110
110
  }
111
111
  return r;
@@ -133,9 +133,9 @@ const g = {
133
133
  baseUrl: s,
134
134
  prefix: r
135
135
  }) => {
136
- var o, c;
136
+ var o, d;
137
137
  const t = ((o = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : o.attr.src) || "", a = {
138
- title: ((c = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : c.val) || "",
138
+ title: ((d = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : d.val) || "",
139
139
  path: N(n, t),
140
140
  href: N(s, n, t),
141
141
  contents: []
@@ -159,14 +159,14 @@ const g = {
159
159
  var i;
160
160
  const t = e.childNamed("spine"), a = t && t.attr.toc;
161
161
  if (a) {
162
- const o = (i = e.childNamed("manifest")) == null ? void 0 : i.childrenNamed("item").find((c) => c.attr.id === a);
162
+ const o = (i = e.childNamed("manifest")) == null ? void 0 : i.childrenNamed("item").find((d) => d.attr.id === a);
163
163
  if (o) {
164
- const c = `${n}${n === "" ? "" : "/"}${o.attr.href}`, l = Object.values(r.files).find(
165
- (d) => d.uri.endsWith(c)
164
+ const d = `${n}${n === "" ? "" : "/"}${o.attr.href}`, l = Object.values(r.files).find(
165
+ (c) => c.uri.endsWith(d)
166
166
  );
167
167
  if (l) {
168
- const d = new y.XmlDocument(await l.string());
169
- return Ne(d, { opfBasePath: n, baseUrl: s });
168
+ const c = new y.XmlDocument(await l.string());
169
+ return Ne(c, { opfBasePath: n, baseUrl: s });
170
170
  }
171
171
  }
172
172
  }
@@ -196,8 +196,8 @@ const g = {
196
196
  }) => {
197
197
  const { data: n, basePath: s } = T(e) || {}, r = await (n == null ? void 0 : n.string());
198
198
  if (!r) return [];
199
- const t = new y.XmlDocument(r), a = t.childNamed("manifest"), i = t.childNamed("spine"), o = i == null ? void 0 : i.childrenNamed("itemref").map((d) => d.attr.idref), c = (a == null ? void 0 : a.childrenNamed("item").filter((d) => o.includes(d.attr.id || ""))) || [];
200
- return e.files.filter((d) => c.find((u) => s ? `${s}/${u.attr.href}` === d.uri : `${u.attr.href}` === d.uri));
199
+ const t = new y.XmlDocument(r), a = t.childNamed("manifest"), i = t.childNamed("spine"), o = i == null ? void 0 : i.childrenNamed("itemref").map((c) => c.attr.idref), d = (a == null ? void 0 : a.childrenNamed("item").filter((c) => o.includes(c.attr.id || ""))) || [];
200
+ return e.files.filter((c) => d.find((u) => s ? `${s}/${u.attr.href}` === c.uri : `${u.attr.href}` === c.uri));
201
201
  }, Q = (e) => {
202
202
  var s;
203
203
  const n = e.childNamed("manifest");
@@ -206,27 +206,27 @@ const g = {
206
206
  id: r.attr.id || "",
207
207
  mediaType: r.attr["media-type"]
208
208
  }))) || [];
209
- }, We = ({ archive: e, baseUrl: n }) => async (s) => {
209
+ }, Re = ({ archive: e, baseUrl: n }) => async (s) => {
210
210
  var P;
211
211
  const { data: r, basePath: t } = T(e) || {}, a = await ke(e);
212
212
  if (!r)
213
213
  return s;
214
214
  const i = await r.string();
215
215
  g.log(i, a);
216
- const o = new y.XmlDocument(i), c = await Se(o, e, { baseUrl: n }) || [], l = o.childNamed("metadata"), d = o.childNamed("manifest"), u = o.childNamed("spine"), f = o.childNamed("guide"), w = l == null ? void 0 : l.childNamed("dc:title"), h = (l == null ? void 0 : l.childrenNamed("meta")) || [], S = h.find(
216
+ const o = new y.XmlDocument(i), d = await Se(o, e, { baseUrl: n }) || [], l = o.childNamed("metadata"), c = o.childNamed("manifest"), u = o.childNamed("spine"), f = o.childNamed("guide"), w = l == null ? void 0 : l.childNamed("dc:title"), h = (l == null ? void 0 : l.childrenNamed("meta")) || [], S = h.find(
217
217
  (p) => p.attr.property === "rendition:layout"
218
218
  ), k = h.find(
219
219
  (p) => p.attr.property === "rendition:flow"
220
- ), W = h.find(
220
+ ), R = h.find(
221
221
  (p) => p.attr.property === "rendition:spread"
222
- ), C = S == null ? void 0 : S.val, Z = k == null ? void 0 : k.val, ee = W == null ? void 0 : W.val, te = (w == null ? void 0 : w.val) || ((P = e.files.find(({ dir: p }) => p)) == null ? void 0 : P.basename) || "", ne = u == null ? void 0 : u.attr["page-progression-direction"], re = (await K({ archive: e })).reduce(
222
+ ), C = S == null ? void 0 : S.val, Z = k == null ? void 0 : k.val, ee = R == null ? void 0 : R.val, te = (w == null ? void 0 : w.val) || ((P = e.files.find(({ dir: p }) => p)) == null ? void 0 : P.basename) || "", ne = u == null ? void 0 : u.attr["page-progression-direction"], re = (await K({ archive: e })).reduce(
223
223
  (p, m) => m.size + p,
224
224
  0
225
225
  );
226
226
  return {
227
227
  filename: e.filename,
228
228
  nav: {
229
- toc: c
229
+ toc: d
230
230
  },
231
231
  renditionLayout: C || a.renditionLayout || "reflowable",
232
232
  renditionFlow: Z || "auto",
@@ -235,19 +235,19 @@ const g = {
235
235
  readingDirection: ne || "ltr",
236
236
  spineItems: (u == null ? void 0 : u.childrenNamed("itemref").map((p) => {
237
237
  var O, j, z;
238
- const m = d == null ? void 0 : d.childrenNamed("item").find((b) => b.attr.id === (p == null ? void 0 : p.attr.idref)), ae = (m == null ? void 0 : m.attr.href) || "", L = ((O = p == null ? void 0 : p.attr.properties) == null ? void 0 : O.split(" ")) || [], se = ((j = e.files.find((b) => b.uri.endsWith(ae))) == null ? void 0 : j.size) || 0, D = n ?? "";
238
+ const m = c == null ? void 0 : c.childrenNamed("item").find((b) => b.attr.id === (p == null ? void 0 : p.attr.idref)), ae = (m == null ? void 0 : m.attr.href) || "", W = ((O = p == null ? void 0 : p.attr.properties) == null ? void 0 : O.split(" ")) || [], se = ((j = e.files.find((b) => b.uri.endsWith(ae))) == null ? void 0 : j.size) || 0, D = n ?? "";
239
239
  return {
240
240
  id: (m == null ? void 0 : m.attr.id) || "",
241
241
  href: (z = m == null ? void 0 : m.attr.href) != null && z.startsWith("https://") ? m == null ? void 0 : m.attr.href : t ? `${D}${t}/${m == null ? void 0 : m.attr.href}` : `${D}${m == null ? void 0 : m.attr.href}`,
242
242
  renditionLayout: C || "reflowable",
243
- ...L.find(
243
+ ...W.find(
244
244
  (b) => b === "rendition:layout-reflowable"
245
245
  ) && {
246
246
  renditionLayout: "reflowable"
247
247
  },
248
248
  progressionWeight: se / re,
249
- pageSpreadLeft: L.some((b) => b === "page-spread-left") || void 0,
250
- pageSpreadRight: L.some((b) => b === "page-spread-right") || void 0,
249
+ pageSpreadLeft: W.some((b) => b === "page-spread-left") || void 0,
250
+ pageSpreadRight: W.some((b) => b === "page-spread-right") || void 0,
251
251
  // size: itemSize
252
252
  mediaType: m == null ? void 0 : m.attr["media-type"]
253
253
  };
@@ -259,19 +259,19 @@ const g = {
259
259
  type: p.attr.type
260
260
  }))
261
261
  };
262
- }, Le = async (e, n) => {
262
+ }, We = async (e, n) => {
263
263
  var t, a;
264
264
  const r = await ((t = T(e).data) == null ? void 0 : t.string());
265
265
  if (r) {
266
266
  const i = new y.XmlDocument(r);
267
267
  return {
268
- mediaType: (a = Q(i).find((c) => n.endsWith(c.href))) == null ? void 0 : a.mediaType
268
+ mediaType: (a = Q(i).find((d) => n.endsWith(d.href))) == null ? void 0 : a.mediaType
269
269
  };
270
270
  }
271
271
  return {
272
- mediaType: Re(n)
272
+ mediaType: Ie(n)
273
273
  };
274
- }, Re = (e) => {
274
+ }, Ie = (e) => {
275
275
  if (e.endsWith(".css"))
276
276
  return "text/css; charset=UTF-8";
277
277
  if (e.endsWith(".jpg"))
@@ -282,12 +282,12 @@ const g = {
282
282
  return "video/mp4";
283
283
  if (e.endsWith(".svg"))
284
284
  return "image/svg+xml";
285
- }, Ae = ({ archive: e, resourcePath: n }) => async (s) => {
285
+ }, Le = ({ archive: e, resourcePath: n }) => async (s) => {
286
286
  const r = Object.values(e.files).find(
287
287
  (a) => a.uri === n
288
288
  );
289
289
  if (!r) return s;
290
- const t = await Le(e, n);
290
+ const t = await We(e, n);
291
291
  return {
292
292
  ...s,
293
293
  params: {
@@ -303,7 +303,7 @@ const g = {
303
303
  }
304
304
  }
305
305
  };
306
- }, Ie = async (e, n) => {
306
+ }, Ae = async (e, n) => {
307
307
  const s = Object.values(e.files).find(
308
308
  (a) => a.uri === n
309
309
  );
@@ -314,7 +314,7 @@ const g = {
314
314
  status: 200
315
315
  }
316
316
  }, t = [
317
- Ae({ archive: e, resourcePath: n }),
317
+ Le({ archive: e, resourcePath: n }),
318
318
  $e({ archive: e, resourcePath: n }),
319
319
  ve({ archive: e, resourcePath: n })
320
320
  ];
@@ -380,9 +380,9 @@ const g = {
380
380
  return n;
381
381
  const r = {
382
382
  ...n,
383
- spineItems: n.spineItems.filter((i) => !i.id.toLowerCase().endsWith("comicinfo.xml")).map((i, o, c) => ({
383
+ spineItems: n.spineItems.filter((i) => !i.id.toLowerCase().endsWith("comicinfo.xml")).map((i, o, d) => ({
384
384
  ...i,
385
- progressionWeight: 1 / c.length
385
+ progressionWeight: 1 / d.length
386
386
  }))
387
387
  }, t = await s.string();
388
388
  try {
@@ -421,7 +421,7 @@ const g = {
421
421
  };
422
422
  }
423
423
  return n;
424
- }, I = (e, n) => {
424
+ }, A = (e, n) => {
425
425
  var t;
426
426
  const s = e.split(/(\d+)/), r = n.split(/(\d+)/);
427
427
  for (let a = 0, i = s.length; a < i; a++)
@@ -431,14 +431,14 @@ const g = {
431
431
  }, ze = ({ archive: e, baseUrl: n }) => async (s) => {
432
432
  if (s.nav) return s;
433
433
  const r = [...e.files].sort(
434
- (a, i) => I(a.uri, i.uri)
434
+ (a, i) => A(a.uri, i.uri)
435
435
  ), t = Object.values(
436
436
  r
437
437
  ).reduce(
438
438
  (a, i) => {
439
439
  const o = i.uri.split("/");
440
- return !i.dir && o.length > 1 && o.forEach((l, d) => {
441
- if (d === o.length - 1) return;
440
+ return !i.dir && o.length > 1 && o.forEach((l, c) => {
441
+ if (c === o.length - 1) return;
442
442
  a.find(({ title: w }) => w === l) || a.push({
443
443
  contents: [],
444
444
  href: N(n, encodeURI(i.uri)).replace(/\/$/, ""),
@@ -466,10 +466,10 @@ const g = {
466
466
  renditionSpread: "auto",
467
467
  spineItems: [],
468
468
  title: ""
469
- }, Ve = async (e, { baseUrl: n = "" } = {}) => {
469
+ }, Ue = async (e, { baseUrl: n = "" } = {}) => {
470
470
  const s = [
471
471
  Ce({ archive: e, baseUrl: n }),
472
- We({ archive: e, baseUrl: n }),
472
+ Re({ archive: e, baseUrl: n }),
473
473
  je({ archive: e, baseUrl: n }),
474
474
  Pe({ archive: e, baseUrl: n }),
475
475
  ze({ archive: e, baseUrl: n })
@@ -521,7 +521,7 @@ const g = {
521
521
  }, ...r],
522
522
  close: () => Promise.resolve()
523
523
  };
524
- }, Ue = async (e) => new Promise((n) => {
524
+ }, Ve = async (e) => new Promise((n) => {
525
525
  const s = new FileReader();
526
526
  s.readAsDataURL(e), s.onloadend = function() {
527
527
  const r = s.result;
@@ -565,7 +565,7 @@ const g = {
565
565
  uri: "p01.txt",
566
566
  blob: async () => typeof e == "string" ? new Blob([e]) : e,
567
567
  string: async () => typeof e == "string" ? e : e.text(),
568
- base64: async () => typeof e == "string" ? btoa(e) : Ue(e),
568
+ base64: async () => typeof e == "string" ? btoa(e) : Ve(e),
569
569
  size: typeof e == "string" ? e.length : e.size,
570
570
  encodingFormat: n
571
571
  }
@@ -574,7 +574,7 @@ const g = {
574
574
  };
575
575
  }, Ke = async (e, { orderByAlpha: n, name: s } = {}) => {
576
576
  let r = Object.values(e.files);
577
- n && (r = r.slice().sort((a, i) => I(a.name, i.name)));
577
+ n && (r = r.slice().sort((a, i) => A(a.name, i.name)));
578
578
  const t = {
579
579
  filename: s || "",
580
580
  files: r.map((a) => ({
@@ -612,7 +612,7 @@ const g = {
612
612
  return g.log("Generated archive", r), r;
613
613
  }, Ze = async (e, { orderByAlpha: n, name: s } = {}) => {
614
614
  let r = e;
615
- return n && (r = r.slice().sort((t, a) => I(t.name, a.name))), {
615
+ return n && (r = r.slice().sort((t, a) => A(t.name, a.name))), {
616
616
  filename: s || "",
617
617
  files: r.map((t) => ({
618
618
  dir: t.isDir,
@@ -639,62 +639,62 @@ const g = {
639
639
  getArchive: e,
640
640
  cleanArchiveAfter: n
641
641
  }) => {
642
- const s = new V(), r = new V(), t = {}, a = s.pipe(
643
- R((c) => {
644
- const l = t[c];
642
+ const s = new U(), r = new U(), t = {}, a = s.pipe(
643
+ I((d) => {
644
+ const l = t[d];
645
645
  return !l || l.getValue().status !== "idle" ? de : (l.next({
646
646
  ...l.getValue(),
647
647
  status: "loading"
648
- }), A(e(c)).pipe(
649
- v((d) => (l.next({
648
+ }), L(e(d)).pipe(
649
+ v((c) => (l.next({
650
650
  ...l.getValue(),
651
- archive: d,
651
+ archive: c,
652
652
  status: "success"
653
- }), { key: c, archiveEntry: l })),
654
- F((d) => {
653
+ }), { key: d, archiveEntry: l })),
654
+ F((c) => {
655
655
  throw l.next({
656
656
  ...l.getValue(),
657
657
  status: "error",
658
- error: d
659
- }), d;
658
+ error: c
659
+ }), c;
660
660
  })
661
661
  ));
662
662
  }),
663
- F((c) => (console.error(c), U)),
663
+ F(() => V),
664
664
  le()
665
665
  ), i = a.pipe(
666
- X(({ archiveEntry: c, key: l }) => c.pipe(v(({ locks: f }) => f)).pipe(v((f) => f <= 0)).pipe(
666
+ X(({ archiveEntry: d, key: l }) => d.pipe(v(({ locks: f }) => f)).pipe(v((f) => f <= 0)).pipe(
667
667
  X(
668
- (f) => f ? me(n) : U
668
+ (f) => f ? me(n) : V
669
669
  ),
670
670
  B(() => {
671
671
  var f;
672
- delete t[l], (f = c.getValue().archive) == null || f.close();
672
+ delete t[l], (f = d.getValue().archive) == null || f.close();
673
673
  })
674
674
  ))
675
- ), o = (c) => {
675
+ ), o = (d) => {
676
676
  let l = !1;
677
- const d = t[c] ?? new fe({
677
+ const c = t[d] ?? new fe({
678
678
  archive: void 0,
679
679
  status: "idle",
680
680
  locks: 0,
681
681
  error: void 0
682
682
  });
683
- t[c] = d, d.next({
684
- ...d.getValue(),
685
- locks: d.getValue().locks + 1
683
+ t[d] = c, c.next({
684
+ ...c.getValue(),
685
+ locks: c.getValue().locks + 1
686
686
  });
687
687
  const u = () => {
688
- l || (l = !0, d.next({
689
- ...d.getValue(),
690
- locks: d.getValue().locks - 1
688
+ l || (l = !0, c.next({
689
+ ...c.getValue(),
690
+ locks: c.getValue().locks - 1
691
691
  }));
692
692
  };
693
- s.next(c);
694
- const f = d.pipe(
693
+ s.next(d);
694
+ const f = c.pipe(
695
695
  v(({ archive: h }) => h),
696
696
  ue((h) => !!h)
697
- ), w = d.pipe(
697
+ ), w = c.pipe(
698
698
  B(({ error: h }) => {
699
699
  if (h)
700
700
  throw h;
@@ -722,8 +722,8 @@ class Be {
722
722
  }
723
723
  fetchManifest({ key: n, baseUrl: s }) {
724
724
  const r = this.epubLoader.access(n).pipe(
725
- R(({ archive: t, release: a }) => A(
726
- Ve(t, { baseUrl: s })
725
+ I(({ archive: t, release: a }) => L(
726
+ Ue(t, { baseUrl: s })
727
727
  ).pipe(
728
728
  v(
729
729
  (o) => new Response(JSON.stringify(o), {
@@ -743,8 +743,8 @@ class Be {
743
743
  resourcePath: s
744
744
  }) {
745
745
  const r = this.epubLoader.access(n).pipe(
746
- R(({ archive: t, release: a }) => A(
747
- Ie(t, s)
746
+ I(({ archive: t, release: a }) => L(
747
+ Ae(t, s)
748
748
  ).pipe(
749
749
  v((o) => new Response(o.body, { status: 200 })),
750
750
  H(() => {
@@ -769,8 +769,8 @@ class tt extends Be {
769
769
  if (!s) return;
770
770
  const r = J(s.baseUrl), t = n.request.url.substring(
771
771
  r.length + 1
772
- ), [a = ""] = t.split("/"), i = J(
773
- t.substring(a.length + 1)
772
+ ), [a = ""] = t.split("/"), i = decodeURIComponent(
773
+ J(t.substring(a.length + 1))
774
774
  );
775
775
  t.endsWith("/manifest") ? n.respondWith(
776
776
  this.fetchManifest({ key: a, baseUrl: `${r}/${a}/` })
@@ -789,8 +789,8 @@ export {
789
789
  Qe as createArchiveFromLibArchive,
790
790
  Ye as createArchiveFromText,
791
791
  qe as createArchiveFromUrls,
792
- Ve as generateManifestFromArchive,
793
- Ie as generateResourceFromArchive,
792
+ Ue as generateManifestFromArchive,
793
+ Ae as generateResourceFromArchive,
794
794
  Je as generateResourceFromError,
795
795
  T as getArchiveOpfInfo
796
796
  };