@prose-reader/streamer 1.83.0 → 1.85.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.
@@ -1,4 +1,3 @@
1
- import { createArchiveLoader } from './archives/archiveLoader';
2
1
  import { Streamer } from './Streamer';
3
2
  type ConflictFreeWebWorkerFetchEvent = {
4
3
  readonly request: Request;
@@ -9,7 +8,7 @@ export declare class ServiceWorkerStreamer extends Streamer {
9
8
  protected getUriInfo: (event: ConflictFreeWebWorkerFetchEvent) => {
10
9
  baseUrl: string;
11
10
  } | undefined;
12
- constructor({ getUriInfo, ...rest }: Parameters<typeof createArchiveLoader>[0] & {
11
+ constructor({ getUriInfo, ...rest }: ConstructorParameters<typeof Streamer>[0] & {
13
12
  getUriInfo: (event: ConflictFreeWebWorkerFetchEvent) => {
14
13
  baseUrl: string;
15
14
  } | undefined;
@@ -1,7 +1,10 @@
1
1
  import { createArchiveLoader } from './archives/archiveLoader';
2
2
  export declare class Streamer {
3
3
  epubLoader: ReturnType<typeof createArchiveLoader>;
4
- constructor(params: Parameters<typeof createArchiveLoader>[0]);
4
+ onError: (error: unknown) => Response;
5
+ constructor({ onError, ...rest }: Parameters<typeof createArchiveLoader>[0] & {
6
+ onError?: (error: unknown) => Response;
7
+ });
5
8
  fetchManifest({ key, baseUrl }: {
6
9
  key: string;
7
10
  baseUrl?: string;
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 L, 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 G, lastValueFrom as J } 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) => {
@@ -90,7 +90,7 @@ const g = {
90
90
  data: s,
91
91
  basePath: (s == null ? void 0 : s.uri.substring(0, s.uri.lastIndexOf("/"))) || ""
92
92
  };
93
- }, Y = (e, { opfBasePath: n, baseUrl: s }) => {
93
+ }, q = (e, { opfBasePath: n, baseUrl: s }) => {
94
94
  const r = {
95
95
  contents: [],
96
96
  path: "",
@@ -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) => Y(c, { opfBasePath: n, baseUrl: s })
108
+ (c) => q(c, { opfBasePath: n, baseUrl: s })
109
109
  ));
110
110
  }
111
111
  return r;
@@ -114,7 +114,7 @@ const g = {
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
- (o) => r.push(Y(o, { opfBasePath: n, baseUrl: s }))
117
+ (o) => r.push(q(o, { opfBasePath: n, baseUrl: s }))
118
118
  ), r;
119
119
  }, Fe = async (e, n, { opfBasePath: s, baseUrl: r }) => {
120
120
  var a;
@@ -128,7 +128,7 @@ const g = {
128
128
  return xe(o, { opfBasePath: s, baseUrl: r });
129
129
  }
130
130
  }
131
- }, K = (e, {
131
+ }, Y = (e, {
132
132
  opfBasePath: n,
133
133
  baseUrl: s,
134
134
  prefix: r
@@ -141,14 +141,14 @@ const g = {
141
141
  contents: []
142
142
  }, i = e.childrenNamed(`${r}navPoint`);
143
143
  return i && i.length > 0 && (a.contents = i.map(
144
- (l) => K(l, { opfBasePath: n, baseUrl: s, prefix: r })
144
+ (l) => Y(l, { opfBasePath: n, baseUrl: s, prefix: r })
145
145
  )), a;
146
146
  }, Ne = (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
- (o) => r.push(K(o, { opfBasePath: n, baseUrl: s, prefix: a }))
151
+ (o) => r.push(Y(o, { opfBasePath: n, baseUrl: s, prefix: a }))
152
152
  ), r;
153
153
  }, Te = async ({
154
154
  opfData: e,
@@ -191,7 +191,7 @@ const g = {
191
191
  }
192
192
  })
193
193
  ), n;
194
- }, E = async ({
194
+ }, K = async ({
195
195
  archive: e
196
196
  }) => {
197
197
  const { data: n, basePath: s } = T(e) || {}, r = await (n == null ? void 0 : n.string());
@@ -219,7 +219,7 @@ const g = {
219
219
  (p) => p.attr.property === "rendition:flow"
220
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 = 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 E({ 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
  );
@@ -269,9 +269,9 @@ const g = {
269
269
  };
270
270
  }
271
271
  return {
272
- mediaType: Le(n)
272
+ mediaType: Ie(n)
273
273
  };
274
- }, Le = (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,7 +282,7 @@ 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
  );
@@ -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
  ];
@@ -327,7 +327,7 @@ const g = {
327
327
  } catch (a) {
328
328
  throw g.error(a), a;
329
329
  }
330
- }, qe = (e) => ({
330
+ }, Je = (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">
@@ -409,7 +409,7 @@ const g = {
409
409
  return t ? De(new y.XmlDocument(t)) : !1;
410
410
  }, Promise.resolve(!0)), je = ({ archive: e }) => async (n) => {
411
411
  if (n.renditionLayout === "reflowable" && n.spineItems.every((r) => r.renditionLayout === "reflowable")) {
412
- const r = await E({ archive: e });
412
+ const r = await K({ archive: e });
413
413
  if (await Oe(r))
414
414
  return {
415
415
  ...n,
@@ -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,7 +431,7 @@ 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(
@@ -466,7 +466,7 @@ 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
472
  Re({ archive: e, baseUrl: n }),
@@ -480,7 +480,7 @@ const g = {
480
480
  } catch (r) {
481
481
  throw g.error(r), r;
482
482
  }
483
- }, $ = (e) => e.substring(e.lastIndexOf("/") + 1) || e, q = (e) => e.endsWith("/") ? e.slice(0, -1) : e, Ye = async (e, n) => {
483
+ }, $ = (e) => e.substring(e.lastIndexOf("/") + 1) || e, J = (e) => e.endsWith("/") ? e.slice(0, -1) : e, qe = 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
- }, 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;
528
528
  n(r);
529
529
  };
530
- }), Ke = async (e, {
530
+ }), Ye = async (e, {
531
531
  mimeType: n,
532
532
  direction: s
533
533
  } = { mimeType: "text/plain" }) => {
@@ -565,16 +565,16 @@ 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
  }
572
572
  ],
573
573
  close: () => Promise.resolve()
574
574
  };
575
- }, Ee = async (e, { orderByAlpha: n, name: s } = {}) => {
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,13 +639,13 @@ 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
- L((c) => {
642
+ const s = new U(), r = new U(), t = {}, a = s.pipe(
643
+ I((c) => {
644
644
  const l = t[c];
645
645
  return !l || l.getValue().status !== "idle" ? de : (l.next({
646
646
  ...l.getValue(),
647
647
  status: "loading"
648
- }), A(e(c)).pipe(
648
+ }), L(e(c)).pipe(
649
649
  v((d) => (l.next({
650
650
  ...l.getValue(),
651
651
  archive: d,
@@ -660,12 +660,12 @@ const g = {
660
660
  })
661
661
  ));
662
662
  }),
663
- F((c) => (console.error(c), U)),
663
+ F((c) => (console.error(c), V)),
664
664
  le()
665
665
  ), i = a.pipe(
666
666
  X(({ archiveEntry: c, key: l }) => c.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;
@@ -714,13 +714,16 @@ const g = {
714
714
  };
715
715
  };
716
716
  class Be {
717
- constructor(n) {
718
- this.epubLoader = Xe(n);
717
+ constructor({
718
+ onError: n,
719
+ ...s
720
+ }) {
721
+ this.onError = (r) => new Response(String(r), { status: 500 }), this.epubLoader = Xe(s), this.onError = n ?? this.onError;
719
722
  }
720
723
  fetchManifest({ key: n, baseUrl: s }) {
721
724
  const r = this.epubLoader.access(n).pipe(
722
- L(({ archive: t, release: a }) => A(
723
- Ve(t, { baseUrl: s })
725
+ I(({ archive: t, release: a }) => L(
726
+ Ue(t, { baseUrl: s })
724
727
  ).pipe(
725
728
  v(
726
729
  (o) => new Response(JSON.stringify(o), {
@@ -731,26 +734,26 @@ class Be {
731
734
  a();
732
735
  })
733
736
  )),
734
- F((t) => G(new Response(String(t), { status: 500 })))
737
+ F((t) => E(this.onError(t)))
735
738
  );
736
- return J(r);
739
+ return G(r);
737
740
  }
738
741
  fetchResource({
739
742
  key: n,
740
743
  resourcePath: s
741
744
  }) {
742
745
  const r = this.epubLoader.access(n).pipe(
743
- L(({ archive: t, release: a }) => A(
744
- Ie(t, s)
746
+ I(({ archive: t, release: a }) => L(
747
+ Ae(t, s)
745
748
  ).pipe(
746
749
  v((o) => new Response(o.body, { status: 200 })),
747
750
  H(() => {
748
751
  a();
749
752
  })
750
753
  )),
751
- F((t) => G(new Response(String(t), { status: 500 })))
754
+ F((t) => E(this.onError(t)))
752
755
  );
753
- return J(r);
756
+ return G(r);
754
757
  }
755
758
  }
756
759
  class tt extends Be {
@@ -764,10 +767,10 @@ class tt extends Be {
764
767
  try {
765
768
  const s = this.getUriInfo(n);
766
769
  if (!s) return;
767
- const r = q(s.baseUrl), t = n.request.url.substring(
770
+ const r = J(s.baseUrl), t = n.request.url.substring(
768
771
  r.length + 1
769
- ), [a = ""] = t.split("/"), i = q(
770
- t.substring(a.length + 1)
772
+ ), [a = ""] = t.split("/"), i = decodeURIComponent(
773
+ J(t.substring(a.length + 1))
771
774
  );
772
775
  t.endsWith("/manifest") ? n.respondWith(
773
776
  this.fetchManifest({ key: a, baseUrl: `${r}/${a}/` })
@@ -782,13 +785,13 @@ export {
782
785
  Be as Streamer,
783
786
  et as configure,
784
787
  Ze as createArchiveFromArrayBufferList,
785
- Ee as createArchiveFromJszip,
788
+ Ke as createArchiveFromJszip,
786
789
  Qe as createArchiveFromLibArchive,
787
- Ke as createArchiveFromText,
788
- Ye as createArchiveFromUrls,
789
- Ve as generateManifestFromArchive,
790
- Ie as generateResourceFromArchive,
791
- qe as generateResourceFromError,
790
+ Ye as createArchiveFromText,
791
+ qe as createArchiveFromUrls,
792
+ Ue as generateManifestFromArchive,
793
+ Ae as generateResourceFromArchive,
794
+ Je as generateResourceFromError,
792
795
  T as getArchiveOpfInfo
793
796
  };
794
797
  //# sourceMappingURL=index.js.map