@prose-reader/streamer 1.86.0 → 1.88.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,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 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";
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, distinctUntilChanged as me, timer as pe, tap as B, merge as _, takeUntil as fe, BehaviorSubject as ue, filter as he, ignoreElements as ge, first as be, finalize as H, of as E, lastValueFrom as G } from "rxjs";
4
4
  let x = !1;
5
5
  const g = {
6
6
  enable: (e) => {
@@ -45,23 +45,23 @@ const g = {
45
45
  const i = performance.now();
46
46
  return g.metric({ name: e, duration: i - t }, n), a;
47
47
  }
48
- }, be = (e) => {
48
+ }, ye = (e) => {
49
49
  var s;
50
50
  const n = (s = e.descendantWithPath("head")) == null ? void 0 : s.childrenNamed("meta").find((r) => r.attr.name === "calibre:cover");
51
51
  return !!(n && n.attr.name === "calibre:cover");
52
- }, ye = (e) => {
52
+ }, we = (e) => {
53
53
  var n, s, r;
54
54
  return (r = (s = (n = e.descendantWithPath("body")) == null ? void 0 : n.descendantWithPath("div")) == null ? void 0 : s.childrenNamed("svg")) == null ? void 0 : r.find(
55
55
  (t) => t.attr.width === "100%" && t.attr.preserveAspectRatio === "none"
56
56
  );
57
- }, we = ({ archive: e, resourcePath: n }) => async (s) => {
57
+ }, ve = ({ archive: e, resourcePath: n }) => async (s) => {
58
58
  const r = Object.values(e.files).find(
59
59
  (t) => t.uri === n
60
60
  );
61
61
  if (r != null && r.basename.endsWith(".xhtml")) {
62
62
  const t = s.body ?? await r.string(), a = new ce(t);
63
- if (be(a)) {
64
- const i = ye(a);
63
+ if (ye(a)) {
64
+ const i = we(a);
65
65
  return i && delete i.attr.preserveAspectRatio, {
66
66
  ...s,
67
67
  body: a == null ? void 0 : a.toString()
@@ -69,7 +69,7 @@ const g = {
69
69
  }
70
70
  }
71
71
  return s;
72
- }, ve = ({ archive: e, resourcePath: n }) => async (s) => we({ archive: e, resourcePath: n })(s), $e = ({ archive: e, resourcePath: n }) => async (s) => {
72
+ }, $e = ({ archive: e, resourcePath: n }) => async (s) => ve({ archive: e, resourcePath: n })(s), xe = ({ archive: e, resourcePath: n }) => async (s) => {
73
73
  const r = Object.values(e.files).find(
74
74
  (t) => t.uri === n
75
75
  );
@@ -109,14 +109,14 @@ const g = {
109
109
  ));
110
110
  }
111
111
  return r;
112
- }, xe = (e, { opfBasePath: n, baseUrl: s }) => {
112
+ }, Fe = (e, { opfBasePath: n, baseUrl: s }) => {
113
113
  var a, i;
114
114
  const r = [];
115
115
  let t;
116
116
  return e.descendantWithPath("body.nav.ol") ? t = (a = e.descendantWithPath("body.nav.ol")) == null ? void 0 : a.children : e.descendantWithPath("body.section.nav.ol") && (t = (i = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : i.children), t && t.length > 0 && t.filter((o) => o.name === "li").forEach(
117
117
  (o) => r.push(q(o, { opfBasePath: n, baseUrl: s }))
118
118
  ), r;
119
- }, Fe = async (e, n, { opfBasePath: s, baseUrl: r }) => {
119
+ }, Ne = async (e, n, { opfBasePath: s, baseUrl: r }) => {
120
120
  var a;
121
121
  const t = (a = e.childNamed("manifest")) == null ? void 0 : a.childrenNamed("item").find((i) => i.attr.properties === "nav");
122
122
  if (t) {
@@ -125,7 +125,7 @@ const g = {
125
125
  );
126
126
  if (i) {
127
127
  const o = new y.XmlDocument(await i.string());
128
- return xe(o, { opfBasePath: s, baseUrl: r });
128
+ return Fe(o, { opfBasePath: s, baseUrl: r });
129
129
  }
130
130
  }
131
131
  }, Y = (e, {
@@ -143,14 +143,14 @@ const g = {
143
143
  return i && i.length > 0 && (a.contents = i.map(
144
144
  (l) => Y(l, { opfBasePath: n, baseUrl: s, prefix: r })
145
145
  )), a;
146
- }, Ne = (e, { opfBasePath: n, baseUrl: s }) => {
146
+ }, Te = (e, { opfBasePath: n, baseUrl: s }) => {
147
147
  var i;
148
148
  const r = [], t = e.name;
149
149
  let a = "";
150
150
  return t.indexOf(":") !== -1 && (a = t.split(":")[0] + ":"), (i = e.childNamed(`${a}navMap`)) == null || i.childrenNamed(`${a}navPoint`).forEach(
151
151
  (o) => r.push(Y(o, { opfBasePath: n, baseUrl: s, prefix: a }))
152
152
  ), r;
153
- }, Te = async ({
153
+ }, Se = async ({
154
154
  opfData: e,
155
155
  opfBasePath: n,
156
156
  baseUrl: s,
@@ -166,19 +166,19 @@ const g = {
166
166
  );
167
167
  if (l) {
168
168
  const c = new y.XmlDocument(await l.string());
169
- return Ne(c, { opfBasePath: n, baseUrl: s });
169
+ return Te(c, { opfBasePath: n, baseUrl: s });
170
170
  }
171
171
  }
172
172
  }
173
- }, Se = async (e, n, { baseUrl: s }) => {
174
- const { basePath: r } = T(n) || {}, t = await Te({
173
+ }, ke = async (e, n, { baseUrl: s }) => {
174
+ const { basePath: r } = T(n) || {}, t = await Se({
175
175
  opfData: e,
176
176
  opfBasePath: r,
177
177
  archive: n,
178
178
  baseUrl: s
179
179
  });
180
- return t || await Fe(e, n, { opfBasePath: r, baseUrl: s });
181
- }, ke = async (e) => {
180
+ return t || await Ne(e, n, { opfBasePath: r, baseUrl: s });
181
+ }, Re = async (e) => {
182
182
  const n = {
183
183
  renditionLayout: void 0
184
184
  };
@@ -206,14 +206,14 @@ const g = {
206
206
  id: r.attr.id || "",
207
207
  mediaType: r.attr["media-type"]
208
208
  }))) || [];
209
- }, Re = ({ archive: e, baseUrl: n }) => async (s) => {
209
+ }, We = ({ archive: e, baseUrl: n }) => async (s) => {
210
210
  var P;
211
- const { data: r, basePath: t } = T(e) || {}, a = await ke(e);
211
+ const { data: r, basePath: t } = T(e) || {}, a = await Re(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), 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(
216
+ const o = new y.XmlDocument(i), d = await ke(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"
@@ -259,7 +259,7 @@ const g = {
259
259
  type: p.attr.type
260
260
  }))
261
261
  };
262
- }, We = async (e, n) => {
262
+ }, Ie = 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) {
@@ -269,9 +269,9 @@ const g = {
269
269
  };
270
270
  }
271
271
  return {
272
- mediaType: Ie(n)
272
+ mediaType: Le(n)
273
273
  };
274
- }, Ie = (e) => {
274
+ }, Le = (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
- }, Le = ({ archive: e, resourcePath: n }) => async (s) => {
285
+ }, Ae = ({ 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 We(e, n);
290
+ const t = await Ie(e, n);
291
291
  return {
292
292
  ...s,
293
293
  params: {
@@ -303,7 +303,7 @@ const g = {
303
303
  }
304
304
  }
305
305
  };
306
- }, Ae = async (e, n) => {
306
+ }, Ce = async (e, n) => {
307
307
  const s = Object.values(e.files).find(
308
308
  (a) => a.uri === n
309
309
  );
@@ -314,9 +314,9 @@ const g = {
314
314
  status: 200
315
315
  }
316
316
  }, t = [
317
- Le({ archive: e, resourcePath: n }),
318
- $e({ archive: e, resourcePath: n }),
319
- ve({ archive: e, resourcePath: n })
317
+ Ae({ archive: e, resourcePath: n }),
318
+ xe({ archive: e, resourcePath: n }),
319
+ $e({ archive: e, resourcePath: n })
320
320
  ];
321
321
  try {
322
322
  const a = await t.reduce(async (i, o) => await o(await i), Promise.resolve(r));
@@ -327,7 +327,7 @@ const g = {
327
327
  } catch (a) {
328
328
  throw g.error(a), a;
329
329
  }
330
- }, Je = (e) => ({
330
+ }, qe = (e) => ({
331
331
  body: `
332
332
  <!DOCTYPE html>
333
333
  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
@@ -345,7 +345,7 @@ const g = {
345
345
  "Content-Type": "text/html;charset=UTF-8"
346
346
  }
347
347
  }
348
- }), Ce = ({ archive: e, baseUrl: n }) => async () => {
348
+ }), Pe = ({ archive: e, baseUrl: n }) => async () => {
349
349
  var r;
350
350
  const s = Object.values(e.files).filter((t) => !t.dir);
351
351
  return {
@@ -371,7 +371,7 @@ const g = {
371
371
  href: `${n}${t.uri}`
372
372
  }))
373
373
  };
374
- }, Pe = ({ archive: e }) => async (n) => {
374
+ }, De = ({ archive: e }) => async (n) => {
375
375
  var a;
376
376
  const s = e.files.find(
377
377
  (i) => i.basename.toLowerCase() === "comicinfo.xml"
@@ -395,22 +395,22 @@ const g = {
395
395
  return console.error(`Unable to parse comicinfo.xml for content
396
396
  `, t), console.error(i), r;
397
397
  }
398
- }, De = (e) => {
398
+ }, Oe = (e) => {
399
399
  var s;
400
400
  const n = (s = e.descendantWithPath("head")) == null ? void 0 : s.childrenNamed("meta").find((r) => r.attr.name === "viewport");
401
401
  return !!(n && n.attr.name === "viewport");
402
- }, Oe = (e) => e.reduce(async (n, s) => {
402
+ }, je = (e) => e.reduce(async (n, s) => {
403
403
  if (!await n || !oe({
404
404
  mimeType: s.encodingFormat,
405
405
  uri: s.uri
406
406
  }))
407
407
  return !1;
408
408
  const t = await s.string();
409
- return t ? De(new y.XmlDocument(t)) : !1;
410
- }, Promise.resolve(!0)), je = ({ archive: e }) => async (n) => {
409
+ return t ? Oe(new y.XmlDocument(t)) : !1;
410
+ }, Promise.resolve(!0)), ze = ({ archive: e }) => async (n) => {
411
411
  if (n.renditionLayout === "reflowable" && n.spineItems.every((r) => r.renditionLayout === "reflowable")) {
412
412
  const r = await K({ archive: e });
413
- if (await Oe(r))
413
+ if (await je(r))
414
414
  return {
415
415
  ...n,
416
416
  spineItems: n.spineItems.map((a) => ({
@@ -428,7 +428,7 @@ const g = {
428
428
  if (s[a] !== r[a])
429
429
  return (t = s[a]) != null && t.match(/\d/) ? +(s[a] || "") - +(r[a] || "") : (s[a] || "").localeCompare(r[a] || "");
430
430
  return 1;
431
- }, ze = ({ archive: e, baseUrl: n }) => async (s) => {
431
+ }, Me = ({ archive: e, baseUrl: n }) => async (s) => {
432
432
  if (s.nav) return s;
433
433
  const r = [...e.files].sort(
434
434
  (a, i) => A(a.uri, i.uri)
@@ -455,7 +455,7 @@ const g = {
455
455
  toc: t
456
456
  }
457
457
  };
458
- }, Me = {
458
+ }, Ue = {
459
459
  filename: "",
460
460
  items: [],
461
461
  nav: {
@@ -466,21 +466,21 @@ const g = {
466
466
  renditionSpread: "auto",
467
467
  spineItems: [],
468
468
  title: ""
469
- }, Ue = async (e, { baseUrl: n = "" } = {}) => {
469
+ }, Ve = async (e, { baseUrl: n = "" } = {}) => {
470
470
  const s = [
471
- Ce({ archive: e, baseUrl: n }),
472
- Re({ archive: e, baseUrl: n }),
473
- je({ archive: e, baseUrl: n }),
474
471
  Pe({ archive: e, baseUrl: n }),
475
- ze({ archive: e, baseUrl: n })
472
+ We({ archive: e, baseUrl: n }),
473
+ ze({ archive: e, baseUrl: n }),
474
+ De({ archive: e, baseUrl: n }),
475
+ Me({ archive: e, baseUrl: n })
476
476
  ];
477
477
  try {
478
- const r = await s.reduce(async (t, a) => await a(await t), Promise.resolve(Me));
478
+ const r = await s.reduce(async (t, a) => await a(await t), Promise.resolve(Ue));
479
479
  return g.log("Generated manifest", r), r;
480
480
  } catch (r) {
481
481
  throw g.error(r), r;
482
482
  }
483
- }, $ = (e) => e.substring(e.lastIndexOf("/") + 1) || e, J = (e) => e.endsWith("/") ? e.slice(0, -1) : e, qe = async (e, n) => {
483
+ }, $ = (e) => e.substring(e.lastIndexOf("/") + 1) || e, J = (e) => e.endsWith("/") ? e.slice(0, -1) : e, Ye = async (e, n) => {
484
484
  const s = `
485
485
  <?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
486
486
  <metadata>
@@ -521,13 +521,13 @@ const g = {
521
521
  }, ...r],
522
522
  close: () => Promise.resolve()
523
523
  };
524
- }, Ve = async (e) => new Promise((n) => {
524
+ }, Xe = 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;
528
528
  n(r);
529
529
  };
530
- }), Ye = async (e, {
530
+ }), Ke = async (e, {
531
531
  mimeType: n,
532
532
  direction: s
533
533
  } = { mimeType: "text/plain" }) => {
@@ -565,14 +565,14 @@ 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) : Ve(e),
568
+ base64: async () => typeof e == "string" ? btoa(e) : Xe(e),
569
569
  size: typeof e == "string" ? e.length : e.size,
570
570
  encodingFormat: n
571
571
  }
572
572
  ],
573
573
  close: () => Promise.resolve()
574
574
  };
575
- }, Ke = async (e, { orderByAlpha: n, name: s } = {}) => {
575
+ }, Qe = async (e, { orderByAlpha: n, name: s } = {}) => {
576
576
  let r = Object.values(e.files);
577
577
  n && (r = r.slice().sort((a, i) => A(a.name, i.name)));
578
578
  const t = {
@@ -595,7 +595,7 @@ const g = {
595
595
  close: () => Promise.resolve()
596
596
  };
597
597
  return g.log("Generated archive", t), t;
598
- }, Qe = async (e, { name: n } = {}) => {
598
+ }, Ze = async (e, { name: n } = {}) => {
599
599
  const s = await e.getFilesArray(), r = {
600
600
  close: () => e.close(),
601
601
  filename: n ?? "",
@@ -610,7 +610,7 @@ const g = {
610
610
  }))
611
611
  };
612
612
  return g.log("Generated archive", r), r;
613
- }, Ze = async (e, { orderByAlpha: n, name: s } = {}) => {
613
+ }, et = async (e, { orderByAlpha: n, name: s } = {}) => {
614
614
  let r = e;
615
615
  return n && (r = r.slice().sort((t, a) => A(t.name, a.name))), {
616
616
  filename: s || "",
@@ -631,11 +631,11 @@ const g = {
631
631
  })),
632
632
  close: () => Promise.resolve()
633
633
  };
634
- }, et = ({
634
+ }, tt = ({
635
635
  enableReport: e
636
636
  } = {}) => {
637
637
  g.enable(!!e);
638
- }, Xe = ({
638
+ }, Be = ({
639
639
  getArchive: e,
640
640
  cleanArchiveAfter: n
641
641
  }) => {
@@ -663,9 +663,12 @@ const g = {
663
663
  F(() => V),
664
664
  le()
665
665
  ), i = a.pipe(
666
- X(({ archiveEntry: d, key: l }) => d.pipe(v(({ locks: f }) => f)).pipe(v((f) => f <= 0)).pipe(
666
+ X(({ archiveEntry: d, key: l }) => d.pipe(v(({ locks: f }) => f)).pipe(
667
+ v((f) => f <= 0),
668
+ me()
669
+ ).pipe(
667
670
  X(
668
- (f) => f ? me(n) : V
671
+ (f) => f ? pe(n) : V
669
672
  ),
670
673
  B(() => {
671
674
  var f;
@@ -674,7 +677,7 @@ const g = {
674
677
  ))
675
678
  ), o = (d) => {
676
679
  let l = !1;
677
- const c = t[d] ?? new fe({
680
+ const c = t[d] ?? new ue({
678
681
  archive: void 0,
679
682
  status: "idle",
680
683
  locks: 0,
@@ -693,37 +696,37 @@ const g = {
693
696
  s.next(d);
694
697
  const f = c.pipe(
695
698
  v(({ archive: h }) => h),
696
- ue((h) => !!h)
699
+ he((h) => !!h)
697
700
  ), w = c.pipe(
698
701
  B(({ error: h }) => {
699
702
  if (h)
700
703
  throw h;
701
704
  }),
702
- he()
705
+ ge()
703
706
  );
704
707
  return _(f, w).pipe(
705
- ge(),
708
+ be(),
706
709
  v((h) => ({ archive: h, release: u })),
707
710
  F((h) => {
708
711
  throw u(), h;
709
712
  })
710
713
  );
711
714
  };
712
- return _(i, a).pipe(pe(r)).subscribe(), {
715
+ return _(i, a).pipe(fe(r)).subscribe(), {
713
716
  access: o
714
717
  };
715
718
  };
716
- class Be {
719
+ class _e {
717
720
  constructor({
718
721
  onError: n,
719
722
  ...s
720
723
  }) {
721
- this.onError = (r) => new Response(String(r), { status: 500 }), this.epubLoader = Xe(s), this.onError = n ?? this.onError;
724
+ this.onError = (r) => new Response(String(r), { status: 500 }), this.epubLoader = Be(s), this.onError = n ?? this.onError;
722
725
  }
723
726
  fetchManifest({ key: n, baseUrl: s }) {
724
727
  const r = this.epubLoader.access(n).pipe(
725
728
  I(({ archive: t, release: a }) => L(
726
- Ue(t, { baseUrl: s })
729
+ Ve(t, { baseUrl: s })
727
730
  ).pipe(
728
731
  v(
729
732
  (o) => new Response(JSON.stringify(o), {
@@ -744,7 +747,7 @@ class Be {
744
747
  }) {
745
748
  const r = this.epubLoader.access(n).pipe(
746
749
  I(({ archive: t, release: a }) => L(
747
- Ae(t, s)
750
+ Ce(t, s)
748
751
  ).pipe(
749
752
  v((o) => new Response(o.body, { status: 200 })),
750
753
  H(() => {
@@ -756,7 +759,7 @@ class Be {
756
759
  return G(r);
757
760
  }
758
761
  }
759
- class tt extends Be {
762
+ class nt extends _e {
760
763
  constructor({
761
764
  getUriInfo: n,
762
765
  ...s
@@ -781,17 +784,17 @@ class tt extends Be {
781
784
  }
782
785
  }
783
786
  export {
784
- tt as ServiceWorkerStreamer,
785
- Be as Streamer,
786
- et as configure,
787
- Ze as createArchiveFromArrayBufferList,
788
- Ke as createArchiveFromJszip,
789
- Qe as createArchiveFromLibArchive,
790
- Ye as createArchiveFromText,
791
- qe as createArchiveFromUrls,
792
- Ue as generateManifestFromArchive,
793
- Ae as generateResourceFromArchive,
794
- Je as generateResourceFromError,
787
+ nt as ServiceWorkerStreamer,
788
+ _e as Streamer,
789
+ tt as configure,
790
+ et as createArchiveFromArrayBufferList,
791
+ Qe as createArchiveFromJszip,
792
+ Ze as createArchiveFromLibArchive,
793
+ Ke as createArchiveFromText,
794
+ Ye as createArchiveFromUrls,
795
+ Ve as generateManifestFromArchive,
796
+ Ce as generateResourceFromArchive,
797
+ qe as generateResourceFromError,
795
798
  T as getArchiveOpfInfo
796
799
  };
797
800
  //# sourceMappingURL=index.js.map