@prose-reader/streamer 1.76.0 → 1.78.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,276 +1,277 @@
1
- import { urlJoin as v, PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME as J, isXmlBasedMimeType as q, detectMimeTypeFromName as R } from "@prose-reader/shared";
2
- import g, { XmlDocument as Y } from "xmldoc";
3
- let b = !1;
4
- const u = {
1
+ import { urlJoin as N, PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME as se, isXmlBasedMimeType as ie, detectMimeTypeFromName as z } from "@prose-reader/shared";
2
+ import y, { XmlDocument as oe } from "xmldoc";
3
+ import { Subject as M, mergeMap as W, EMPTY as ce, from as A, map as v, catchError as F, NEVER as V, shareReplay as de, switchMap as B, timer as le, tap as X, merge as _, takeUntil as me, BehaviorSubject as pe, filter as fe, ignoreElements as ue, first as he, finalize as H, of as G, lastValueFrom as J } from "rxjs";
4
+ let $ = !1;
5
+ const g = {
5
6
  enable: (e) => {
6
- b = e;
7
+ $ = e;
7
8
  },
8
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
10
  log: (...e) => {
10
- b && console.log("[prose-reader-streamer]", ...e);
11
+ $ && console.log("[prose-reader-streamer]", ...e);
11
12
  },
12
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
14
  warn: (...e) => {
14
- b && console.warn("[prose-reader-streamer]", ...e);
15
+ $ && console.warn("[prose-reader-streamer]", ...e);
15
16
  },
16
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
18
  error: (...e) => {
18
19
  console.error(...e);
19
20
  },
20
21
  time: (e) => {
21
- b && console.time(`[prose-reader-streamer] [metric] ${e}`);
22
+ $ && console.time(`[prose-reader-streamer] [metric] ${e}`);
22
23
  },
23
24
  timeEnd: (e) => {
24
- b && console.timeEnd(`[prose-reader-streamer] [metric] ${e}`);
25
+ $ && console.timeEnd(`[prose-reader-streamer] [metric] ${e}`);
25
26
  },
26
- metric: (e, r = 1 / 0) => {
27
- const i = typeof e == "number" ? e : e.duration;
28
- b && (e.duration <= r ? console.log(
27
+ metric: (e, n = 1 / 0) => {
28
+ const s = typeof e == "number" ? e : e.duration;
29
+ $ && (e.duration <= n ? console.log(
29
30
  "[prose-reader-streamer] [metric] ",
30
- `${e.name} took ${i}ms`
31
+ `${e.name} took ${s}ms`
31
32
  ) : console.warn(
32
33
  "[prose-reader-streamer] [metric] ",
33
- `${e.name} took ${e.duration}ms which is above the ${r}ms target for this function`
34
+ `${e.name} took ${e.duration}ms which is above the ${n}ms target for this function`
34
35
  ));
35
36
  },
36
37
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
- measurePerformance: (e, r = 10, i) => (...n) => {
38
- const t = performance.now(), a = i(...n);
38
+ measurePerformance: (e, n = 10, s) => (...r) => {
39
+ const t = performance.now(), a = s(...r);
39
40
  if (a && a.then)
40
- return a.then((s) => {
41
- const l = performance.now();
42
- return u.metric({ name: e, duration: l - t }, r), s;
41
+ return a.then((o) => {
42
+ const c = performance.now();
43
+ return g.metric({ name: e, duration: c - t }, n), o;
43
44
  });
44
- const o = performance.now();
45
- return u.metric({ name: e, duration: o - t }, r), a;
45
+ const i = performance.now();
46
+ return g.metric({ name: e, duration: i - t }, n), a;
46
47
  }
47
- }, K = (e) => {
48
- var i;
49
- const r = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((n) => n.attr.name === "calibre:cover");
50
- return !!(r && r.attr.name === "calibre:cover");
51
- }, Q = (e) => {
52
- var r, i, n;
53
- return (n = (i = (r = e.descendantWithPath("body")) == null ? void 0 : r.descendantWithPath("div")) == null ? void 0 : i.childrenNamed("svg")) == null ? void 0 : n.find(
48
+ }, ge = (e) => {
49
+ var s;
50
+ const n = (s = e.descendantWithPath("head")) == null ? void 0 : s.childrenNamed("meta").find((r) => r.attr.name === "calibre:cover");
51
+ return !!(n && n.attr.name === "calibre:cover");
52
+ }, be = (e) => {
53
+ var n, s, r;
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(
54
55
  (t) => t.attr.width === "100%" && t.attr.preserveAspectRatio === "none"
55
56
  );
56
- }, Z = ({ archive: e, resourcePath: r }) => async (i) => {
57
- const n = Object.values(e.files).find(
58
- (t) => t.uri === r
57
+ }, ye = ({ archive: e, resourcePath: n }) => async (s) => {
58
+ const r = Object.values(e.files).find(
59
+ (t) => t.uri === n
59
60
  );
60
- if (n != null && n.basename.endsWith(".xhtml")) {
61
- const t = i.body ?? await n.string(), a = new Y(t);
62
- if (K(a)) {
63
- const o = Q(a);
64
- return o && delete o.attr.preserveAspectRatio, {
65
- ...i,
61
+ if (r != null && r.basename.endsWith(".xhtml")) {
62
+ const t = s.body ?? await r.string(), a = new oe(t);
63
+ if (ge(a)) {
64
+ const i = be(a);
65
+ return i && delete i.attr.preserveAspectRatio, {
66
+ ...s,
66
67
  body: a == null ? void 0 : a.toString()
67
68
  };
68
69
  }
69
70
  }
70
- return i;
71
- }, E = ({ archive: e, resourcePath: r }) => async (i) => Z({ archive: e, resourcePath: r })(i), ee = ({ archive: e, resourcePath: r }) => async (i) => {
72
- const n = Object.values(e.files).find(
73
- (t) => t.uri === r
71
+ return s;
72
+ }, we = ({ archive: e, resourcePath: n }) => async (s) => ye({ archive: e, resourcePath: n })(s), ve = ({ archive: e, resourcePath: n }) => async (s) => {
73
+ const r = Object.values(e.files).find(
74
+ (t) => t.uri === n
74
75
  );
75
- if (n != null && n.basename.endsWith(".css")) {
76
- const a = (i.body ?? await n.string()).replaceAll(
76
+ if (r != null && r.basename.endsWith(".css")) {
77
+ const a = (s.body ?? await r.string()).replaceAll(
77
78
  "-webkit-writing-mode",
78
79
  "writing-mode"
79
80
  );
80
81
  return {
81
- ...i,
82
+ ...s,
82
83
  body: a
83
84
  };
84
85
  }
85
- return i;
86
- }, F = (e) => {
87
- const i = Object.values(e.files).filter((n) => !n.dir).find((n) => n.uri.endsWith(".opf"));
86
+ return s;
87
+ }, S = (e) => {
88
+ const s = Object.values(e.files).filter((r) => !r.dir).find((r) => r.uri.endsWith(".opf"));
88
89
  return {
89
- data: i,
90
- basePath: (i == null ? void 0 : i.uri.substring(0, i.uri.lastIndexOf("/"))) || ""
90
+ data: s,
91
+ basePath: (s == null ? void 0 : s.uri.substring(0, s.uri.lastIndexOf("/"))) || ""
91
92
  };
92
- }, O = (e, { opfBasePath: r, baseUrl: i }) => {
93
- const n = {
93
+ }, q = (e, { opfBasePath: n, baseUrl: s }) => {
94
+ const r = {
94
95
  contents: [],
95
96
  path: "",
96
97
  href: "",
97
98
  title: ""
98
99
  };
99
100
  let t = e.childNamed("span") || e.childNamed("a");
100
- n.title = (t == null ? void 0 : t.attr.title) || (t == null ? void 0 : t.val.trim()) || n.title;
101
+ r.title = (t == null ? void 0 : t.attr.title) || (t == null ? void 0 : t.val.trim()) || r.title;
101
102
  let a = t == null ? void 0 : t.name;
102
- a !== "a" && (t = e.descendantWithPath(`${a}.a`), t && (a = t.name.toLowerCase())), a === "a" && (t != null && t.attr.href) && (n.path = v(r, t.attr.href), n.href = v(i, r, t.attr.href));
103
- const o = e.childNamed("ol");
104
- if (o) {
105
- const s = o.childrenNamed("li");
106
- s && s.length > 0 && (n.contents = s.map(
107
- (l) => O(l, { opfBasePath: r, baseUrl: i })
103
+ a !== "a" && (t = e.descendantWithPath(`${a}.a`), t && (a = t.name.toLowerCase())), a === "a" && (t != null && t.attr.href) && (r.path = N(n, t.attr.href), r.href = N(s, n, t.attr.href));
104
+ const i = e.childNamed("ol");
105
+ if (i) {
106
+ const o = i.childrenNamed("li");
107
+ o && o.length > 0 && (r.contents = o.map(
108
+ (c) => q(c, { opfBasePath: n, baseUrl: s })
108
109
  ));
109
110
  }
110
- return n;
111
- }, te = (e, { opfBasePath: r, baseUrl: i }) => {
112
- var a, o;
113
- const n = [];
111
+ return r;
112
+ }, xe = (e, { opfBasePath: n, baseUrl: s }) => {
113
+ var a, i;
114
+ const r = [];
114
115
  let t;
115
- 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 = (o = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : o.children), t && t.length > 0 && t.filter((s) => s.name === "li").forEach(
116
- (s) => n.push(O(s, { opfBasePath: r, baseUrl: i }))
117
- ), n;
118
- }, ne = async (e, r, { opfBasePath: i, baseUrl: n }) => {
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(q(o, { opfBasePath: n, baseUrl: s }))
118
+ ), r;
119
+ }, $e = async (e, n, { opfBasePath: s, baseUrl: r }) => {
119
120
  var a;
120
- const t = (a = e.childNamed("manifest")) == null ? void 0 : a.childrenNamed("item").find((o) => o.attr.properties === "nav");
121
+ const t = (a = e.childNamed("manifest")) == null ? void 0 : a.childrenNamed("item").find((i) => i.attr.properties === "nav");
121
122
  if (t) {
122
- const o = Object.values(r.files).find(
123
- (s) => s.uri.endsWith(t.attr.href || "")
123
+ const i = Object.values(n.files).find(
124
+ (o) => o.uri.endsWith(t.attr.href || "")
124
125
  );
125
- if (o) {
126
- const s = new g.XmlDocument(await o.string());
127
- return te(s, { opfBasePath: i, baseUrl: n });
126
+ if (i) {
127
+ const o = new y.XmlDocument(await i.string());
128
+ return xe(o, { opfBasePath: s, baseUrl: r });
128
129
  }
129
130
  }
130
- }, z = (e, {
131
- opfBasePath: r,
132
- baseUrl: i,
133
- prefix: n
131
+ }, Y = (e, {
132
+ opfBasePath: n,
133
+ baseUrl: s,
134
+ prefix: r
134
135
  }) => {
135
- var s, l;
136
- const t = ((s = e == null ? void 0 : e.childNamed(`${n}content`)) == null ? void 0 : s.attr.src) || "", a = {
137
- title: ((l = e == null ? void 0 : e.descendantWithPath(`${n}navLabel.${n}text`)) == null ? void 0 : l.val) || "",
138
- path: v(r, t),
139
- href: v(i, r, t),
136
+ var o, c;
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) || "",
139
+ path: N(n, t),
140
+ href: N(s, n, t),
140
141
  contents: []
141
- }, o = e.childrenNamed(`${n}navPoint`);
142
- return o && o.length > 0 && (a.contents = o.map(
143
- (f) => z(f, { opfBasePath: r, baseUrl: i, prefix: n })
142
+ }, i = e.childrenNamed(`${r}navPoint`);
143
+ return i && i.length > 0 && (a.contents = i.map(
144
+ (l) => Y(l, { opfBasePath: n, baseUrl: s, prefix: r })
144
145
  )), a;
145
- }, re = (e, { opfBasePath: r, baseUrl: i }) => {
146
- var o;
147
- const n = [], t = e.name;
146
+ }, Fe = (e, { opfBasePath: n, baseUrl: s }) => {
147
+ var i;
148
+ const r = [], t = e.name;
148
149
  let a = "";
149
- return t.indexOf(":") !== -1 && (a = t.split(":")[0] + ":"), (o = e.childNamed(`${a}navMap`)) == null || o.childrenNamed(`${a}navPoint`).forEach(
150
- (s) => n.push(z(s, { opfBasePath: r, baseUrl: i, prefix: a }))
151
- ), n;
152
- }, ae = async ({
150
+ return t.indexOf(":") !== -1 && (a = t.split(":")[0] + ":"), (i = e.childNamed(`${a}navMap`)) == null || i.childrenNamed(`${a}navPoint`).forEach(
151
+ (o) => r.push(Y(o, { opfBasePath: n, baseUrl: s, prefix: a }))
152
+ ), r;
153
+ }, Ne = async ({
153
154
  opfData: e,
154
- opfBasePath: r,
155
- baseUrl: i,
156
- archive: n
155
+ opfBasePath: n,
156
+ baseUrl: s,
157
+ archive: r
157
158
  }) => {
158
- var o;
159
+ var i;
159
160
  const t = e.childNamed("spine"), a = t && t.attr.toc;
160
161
  if (a) {
161
- const s = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((l) => l.attr.id === a);
162
- if (s) {
163
- const l = `${r}${r === "" ? "" : "/"}${s.attr.href}`, f = Object.values(n.files).find(
164
- (m) => m.uri.endsWith(l)
162
+ const o = (i = e.childNamed("manifest")) == null ? void 0 : i.childrenNamed("item").find((c) => c.attr.id === a);
163
+ if (o) {
164
+ const c = `${n}${n === "" ? "" : "/"}${o.attr.href}`, l = Object.values(r.files).find(
165
+ (d) => d.uri.endsWith(c)
165
166
  );
166
- if (f) {
167
- const m = new g.XmlDocument(await f.string());
168
- return re(m, { opfBasePath: r, baseUrl: i });
167
+ if (l) {
168
+ const d = new y.XmlDocument(await l.string());
169
+ return Fe(d, { opfBasePath: n, baseUrl: s });
169
170
  }
170
171
  }
171
172
  }
172
- }, ie = async (e, r, { baseUrl: i }) => {
173
- const { basePath: n } = F(r) || {}, t = await ae({
173
+ }, Se = async (e, n, { baseUrl: s }) => {
174
+ const { basePath: r } = S(n) || {}, t = await Ne({
174
175
  opfData: e,
175
- opfBasePath: n,
176
- archive: r,
177
- baseUrl: i
176
+ opfBasePath: r,
177
+ archive: n,
178
+ baseUrl: s
178
179
  });
179
- return t || await ne(e, r, { opfBasePath: n, baseUrl: i });
180
- }, oe = async (e) => {
181
- const r = {
180
+ return t || await $e(e, n, { opfBasePath: r, baseUrl: s });
181
+ }, Te = async (e) => {
182
+ const n = {
182
183
  renditionLayout: void 0
183
184
  };
184
185
  return await Promise.all(
185
- e.files.map(async (i) => {
186
- var n, t;
187
- if (i.uri.endsWith("com.kobobooks.display-options.xml")) {
188
- const o = (n = new g.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : n.childNamed("option");
189
- ((t = o == null ? void 0 : o.attr) == null ? void 0 : t.name) === "fixed-layout" && o.val === "true" && (r.renditionLayout = "pre-paginated");
186
+ e.files.map(async (s) => {
187
+ var r, t;
188
+ if (s.uri.endsWith("com.kobobooks.display-options.xml")) {
189
+ const i = (r = new y.XmlDocument(await s.string()).childNamed("platform")) == null ? void 0 : r.childNamed("option");
190
+ ((t = i == null ? void 0 : i.attr) == null ? void 0 : t.name) === "fixed-layout" && i.val === "true" && (n.renditionLayout = "pre-paginated");
190
191
  }
191
192
  })
192
- ), r;
193
- }, j = async ({
193
+ ), n;
194
+ }, K = async ({
194
195
  archive: e
195
196
  }) => {
196
- const { data: r, basePath: i } = F(e) || {}, n = await (r == null ? void 0 : r.string());
197
- if (!n) return [];
198
- const t = new g.XmlDocument(n), a = t.childNamed("manifest"), o = t.childNamed("spine"), s = o == null ? void 0 : o.childrenNamed("itemref").map((m) => m.attr.idref), l = (a == null ? void 0 : a.childrenNamed("item").filter((m) => s.includes(m.attr.id || ""))) || [];
199
- return e.files.filter((m) => l.find((p) => i ? `${i}/${p.attr.href}` === m.uri : `${p.attr.href}` === m.uri));
200
- }, X = (e) => {
201
- var i;
202
- const r = e.childNamed("manifest");
203
- return ((i = r == null ? void 0 : r.childrenNamed("item")) == null ? void 0 : i.map((n) => ({
204
- href: n.attr.href || "",
205
- id: n.attr.id || "",
206
- mediaType: n.attr["media-type"]
197
+ const { data: n, basePath: s } = S(e) || {}, r = await (n == null ? void 0 : n.string());
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));
201
+ }, E = (e) => {
202
+ var s;
203
+ const n = e.childNamed("manifest");
204
+ return ((s = n == null ? void 0 : n.childrenNamed("item")) == null ? void 0 : s.map((r) => ({
205
+ href: r.attr.href || "",
206
+ id: r.attr.id || "",
207
+ mediaType: r.attr["media-type"]
207
208
  }))) || [];
208
- }, se = ({ archive: e, baseUrl: r }) => async (i) => {
209
- var k;
210
- const { data: n, basePath: t } = F(e) || {}, a = await oe(e);
211
- if (!n)
212
- return i;
213
- const o = await n.string();
214
- u.log(o, a);
215
- const s = new g.XmlDocument(o), l = await ie(s, e, { baseUrl: r }) || [], f = s.childNamed("metadata"), m = s.childNamed("manifest"), p = s.childNamed("spine"), x = s.childNamed("guide"), w = f == null ? void 0 : f.childNamed("dc:title"), $ = (f == null ? void 0 : f.childrenNamed("meta")) || [], N = $.find(
216
- (d) => d.attr.property === "rendition:layout"
217
- ), T = $.find(
218
- (d) => d.attr.property === "rendition:flow"
219
- ), A = $.find(
220
- (d) => d.attr.property === "rendition:spread"
221
- ), W = N == null ? void 0 : N.val, B = T == null ? void 0 : T.val, M = A == null ? void 0 : A.val, _ = (w == null ? void 0 : w.val) || ((k = e.files.find(({ dir: d }) => d)) == null ? void 0 : k.basename) || "", H = p == null ? void 0 : p.attr["page-progression-direction"], U = (await j({ archive: e })).reduce(
222
- (d, c) => c.size + d,
209
+ }, ke = ({ archive: e, baseUrl: n }) => async (s) => {
210
+ var P;
211
+ const { data: r, basePath: t } = S(e) || {}, a = await Te(e);
212
+ if (!r)
213
+ return s;
214
+ const i = await r.string();
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")) || [], T = h.find(
217
+ (p) => p.attr.property === "rendition:layout"
218
+ ), k = h.find(
219
+ (p) => p.attr.property === "rendition:flow"
220
+ ), R = h.find(
221
+ (p) => p.attr.property === "rendition:spread"
222
+ ), C = T == null ? void 0 : T.val, Q = k == null ? void 0 : k.val, Z = R == null ? void 0 : R.val, ee = (w == null ? void 0 : w.val) || ((P = e.files.find(({ dir: p }) => p)) == null ? void 0 : P.basename) || "", te = u == null ? void 0 : u.attr["page-progression-direction"], ne = (await K({ archive: e })).reduce(
223
+ (p, m) => m.size + p,
223
224
  0
224
225
  );
225
226
  return {
226
227
  filename: e.filename,
227
228
  nav: {
228
- toc: l
229
+ toc: c
229
230
  },
230
- renditionLayout: W || a.renditionLayout || "reflowable",
231
- renditionFlow: B || "auto",
232
- renditionSpread: M,
233
- title: _,
234
- readingDirection: H || "ltr",
235
- spineItems: (p == null ? void 0 : p.childrenNamed("itemref").map((d) => {
236
- var S, P, L;
237
- const c = m == null ? void 0 : m.childrenNamed("item").find((h) => h.attr.id === (d == null ? void 0 : d.attr.idref)), V = (c == null ? void 0 : c.attr.href) || "", I = ((S = d == null ? void 0 : d.attr.properties) == null ? void 0 : S.split(" ")) || [], G = ((P = e.files.find((h) => h.uri.endsWith(V))) == null ? void 0 : P.size) || 0, D = r ?? "";
231
+ renditionLayout: C || a.renditionLayout || "reflowable",
232
+ renditionFlow: Q || "auto",
233
+ renditionSpread: Z,
234
+ title: ee,
235
+ readingDirection: te || "ltr",
236
+ spineItems: (u == null ? void 0 : u.childrenNamed("itemref").map((p) => {
237
+ var O, j, U;
238
+ const m = d == null ? void 0 : d.childrenNamed("item").find((b) => b.attr.id === (p == null ? void 0 : p.attr.idref)), re = (m == null ? void 0 : m.attr.href) || "", L = ((O = p == null ? void 0 : p.attr.properties) == null ? void 0 : O.split(" ")) || [], ae = ((j = e.files.find((b) => b.uri.endsWith(re))) == null ? void 0 : j.size) || 0, D = n ?? "";
238
239
  return {
239
- id: (c == null ? void 0 : c.attr.id) || "",
240
- href: (L = c == null ? void 0 : c.attr.href) != null && L.startsWith("https://") ? c == null ? void 0 : c.attr.href : t ? `${D}${t}/${c == null ? void 0 : c.attr.href}` : `${D}${c == null ? void 0 : c.attr.href}`,
241
- renditionLayout: W || "reflowable",
242
- ...I.find(
243
- (h) => h === "rendition:layout-reflowable"
240
+ id: (m == null ? void 0 : m.attr.id) || "",
241
+ href: (U = m == null ? void 0 : m.attr.href) != null && U.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
+ renditionLayout: C || "reflowable",
243
+ ...L.find(
244
+ (b) => b === "rendition:layout-reflowable"
244
245
  ) && {
245
246
  renditionLayout: "reflowable"
246
247
  },
247
- progressionWeight: G / U,
248
- pageSpreadLeft: I.some((h) => h === "page-spread-left") || void 0,
249
- pageSpreadRight: I.some((h) => h === "page-spread-right") || void 0,
248
+ progressionWeight: ae / ne,
249
+ pageSpreadLeft: L.some((b) => b === "page-spread-left") || void 0,
250
+ pageSpreadRight: L.some((b) => b === "page-spread-right") || void 0,
250
251
  // size: itemSize
251
- mediaType: c == null ? void 0 : c.attr["media-type"]
252
+ mediaType: m == null ? void 0 : m.attr["media-type"]
252
253
  };
253
254
  })) || [],
254
- items: X(s),
255
- guide: x == null ? void 0 : x.childrenNamed("reference").map((d) => ({
256
- href: d.attr.href || "",
257
- title: d.attr.title || "",
258
- type: d.attr.type
255
+ items: E(o),
256
+ guide: f == null ? void 0 : f.childrenNamed("reference").map((p) => ({
257
+ href: p.attr.href || "",
258
+ title: p.attr.title || "",
259
+ type: p.attr.type
259
260
  }))
260
261
  };
261
- }, ce = async (e, r) => {
262
+ }, Re = async (e, n) => {
262
263
  var t, a;
263
- const n = await ((t = F(e).data) == null ? void 0 : t.string());
264
- if (n) {
265
- const o = new g.XmlDocument(n);
264
+ const r = await ((t = S(e).data) == null ? void 0 : t.string());
265
+ if (r) {
266
+ const i = new y.XmlDocument(r);
266
267
  return {
267
- mediaType: (a = X(o).find((l) => r.endsWith(l.href))) == null ? void 0 : a.mediaType
268
+ mediaType: (a = E(i).find((c) => n.endsWith(c.href))) == null ? void 0 : a.mediaType
268
269
  };
269
270
  }
270
271
  return {
271
- mediaType: de(r)
272
+ mediaType: Le(n)
272
273
  };
273
- }, de = (e) => {
274
+ }, Le = (e) => {
274
275
  if (e.endsWith(".css"))
275
276
  return "text/css; charset=UTF-8";
276
277
  if (e.endsWith(".jpg"))
@@ -281,20 +282,20 @@ const u = {
281
282
  return "video/mp4";
282
283
  if (e.endsWith(".svg"))
283
284
  return "image/svg+xml";
284
- }, le = ({ archive: e, resourcePath: r }) => async (i) => {
285
- const n = Object.values(e.files).find(
286
- (a) => a.uri === r
285
+ }, We = ({ archive: e, resourcePath: n }) => async (s) => {
286
+ const r = Object.values(e.files).find(
287
+ (a) => a.uri === n
287
288
  );
288
- if (!n) return i;
289
- const t = await ce(e, r);
289
+ if (!r) return s;
290
+ const t = await Re(e, n);
290
291
  return {
291
- ...i,
292
+ ...s,
292
293
  params: {
293
- ...i.params,
294
+ ...s.params,
294
295
  status: 200,
295
296
  headers: {
296
- ...(n == null ? void 0 : n.encodingFormat) && {
297
- "Content-Type": n.encodingFormat
297
+ ...(r == null ? void 0 : r.encodingFormat) && {
298
+ "Content-Type": r.encodingFormat
298
299
  },
299
300
  ...t.mediaType && {
300
301
  "Content-Type": t.mediaType
@@ -302,36 +303,36 @@ const u = {
302
303
  }
303
304
  }
304
305
  };
305
- }, Fe = async (e, r) => {
306
- const i = Object.values(e.files).find(
307
- (a) => a.uri === r
306
+ }, Ae = async (e, n) => {
307
+ const s = Object.values(e.files).find(
308
+ (a) => a.uri === n
308
309
  );
309
- if (!i)
310
+ if (!s)
310
311
  throw new Error("no file found");
311
- const n = {
312
+ const r = {
312
313
  params: {
313
314
  status: 200
314
315
  }
315
316
  }, t = [
316
- le({ archive: e, resourcePath: r }),
317
- ee({ archive: e, resourcePath: r }),
318
- E({ archive: e, resourcePath: r })
317
+ We({ archive: e, resourcePath: n }),
318
+ ve({ archive: e, resourcePath: n }),
319
+ we({ archive: e, resourcePath: n })
319
320
  ];
320
321
  try {
321
- const a = await t.reduce(async (o, s) => await s(await o), Promise.resolve(n));
322
- return u.log("Generated resource", r, a), {
322
+ const a = await t.reduce(async (i, o) => await o(await i), Promise.resolve(r));
323
+ return g.log("Generated resource", n, a), {
323
324
  ...a,
324
- body: a.body || await i.blob()
325
+ body: a.body || await s.blob()
325
326
  };
326
327
  } catch (a) {
327
- throw u.error(a), a;
328
+ throw g.error(a), a;
328
329
  }
329
- }, $e = (e) => ({
330
+ }, qe = (e) => ({
330
331
  body: `
331
332
  <!DOCTYPE html>
332
333
  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
333
334
  <head>
334
- <meta name="${J}" content="${String(e)}" />
335
+ <meta name="${se}" content="${String(e)}" />
335
336
  </head>
336
337
  <body>
337
338
  <pre>${String(e)}</pre>
@@ -344,117 +345,117 @@ const u = {
344
345
  "Content-Type": "text/html;charset=UTF-8"
345
346
  }
346
347
  }
347
- }), me = ({ archive: e, baseUrl: r }) => async () => {
348
- var n;
349
- const i = Object.values(e.files).filter((t) => !t.dir);
348
+ }), Ie = ({ archive: e, baseUrl: n }) => async () => {
349
+ var r;
350
+ const s = Object.values(e.files).filter((t) => !t.dir);
350
351
  return {
351
352
  filename: e.filename,
352
- title: ((n = e.files.find(({ dir: t }) => t)) == null ? void 0 : n.basename.replace(/\/$/, "")) || "",
353
+ title: ((r = e.files.find(({ dir: t }) => t)) == null ? void 0 : r.basename.replace(/\/$/, "")) || "",
353
354
  renditionLayout: "pre-paginated",
354
355
  renditionSpread: "auto",
355
356
  readingDirection: "ltr",
356
- spineItems: i.filter((t) => !t.basename.endsWith(".db")).map((t, a) => ({
357
+ spineItems: s.filter((t) => !t.basename.endsWith(".db")).map((t, a) => ({
357
358
  // some books such as cbz can have same basename inside different sub folder
358
359
  // we need to make sure to have unique index
359
360
  // /chap01/01.png, /chap02/01.png, etc
360
361
  id: `${a}.${t.basename}`,
361
- href: encodeURI(`${r}${t.uri}`),
362
+ href: encodeURI(`${n}${t.uri}`),
362
363
  renditionLayout: "pre-paginated",
363
- progressionWeight: 1 / i.length,
364
+ progressionWeight: 1 / s.length,
364
365
  pageSpreadLeft: void 0,
365
366
  pageSpreadRight: void 0,
366
367
  mediaType: t.encodingFormat
367
368
  })),
368
- items: i.map((t, a) => ({
369
+ items: s.map((t, a) => ({
369
370
  id: `${a}.${t.basename}`,
370
- href: `${r}${t.uri}`
371
+ href: `${n}${t.uri}`
371
372
  }))
372
373
  };
373
- }, fe = ({ archive: e }) => async (r) => {
374
+ }, Ce = ({ archive: e }) => async (n) => {
374
375
  var a;
375
- const i = e.files.find(
376
- (o) => o.basename.toLowerCase() === "comicinfo.xml"
376
+ const s = e.files.find(
377
+ (i) => i.basename.toLowerCase() === "comicinfo.xml"
377
378
  );
378
- if (!i)
379
- return r;
380
- const n = {
381
- ...r,
382
- spineItems: r.spineItems.filter((o) => !o.id.toLowerCase().endsWith("comicinfo.xml")).map((o, s, l) => ({
383
- ...o,
384
- progressionWeight: 1 / l.length
379
+ if (!s)
380
+ return n;
381
+ const r = {
382
+ ...n,
383
+ spineItems: n.spineItems.filter((i) => !i.id.toLowerCase().endsWith("comicinfo.xml")).map((i, o, c) => ({
384
+ ...i,
385
+ progressionWeight: 1 / c.length
385
386
  }))
386
- }, t = await i.string();
387
+ }, t = await s.string();
387
388
  try {
388
- const s = ((a = new g.XmlDocument(t).childNamed("Manga")) == null ? void 0 : a.val) || "unknown";
389
+ const o = ((a = new y.XmlDocument(t).childNamed("Manga")) == null ? void 0 : a.val) || "unknown";
389
390
  return {
390
- ...n,
391
- readingDirection: s === "YesAndRightToLeft" ? "rtl" : "ltr"
391
+ ...r,
392
+ readingDirection: o === "YesAndRightToLeft" ? "rtl" : "ltr"
392
393
  };
393
- } catch (o) {
394
+ } catch (i) {
394
395
  return console.error(`Unable to parse comicinfo.xml for content
395
- `, t), console.error(o), n;
396
+ `, t), console.error(i), r;
396
397
  }
397
- }, pe = (e) => {
398
- var i;
399
- const r = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((n) => n.attr.name === "viewport");
400
- return !!(r && r.attr.name === "viewport");
401
- }, ue = (e) => e.reduce(async (r, i) => {
402
- if (!await r || !q({
403
- mimeType: i.encodingFormat,
404
- uri: i.uri
398
+ }, Pe = (e) => {
399
+ var s;
400
+ const n = (s = e.descendantWithPath("head")) == null ? void 0 : s.childrenNamed("meta").find((r) => r.attr.name === "viewport");
401
+ return !!(n && n.attr.name === "viewport");
402
+ }, De = (e) => e.reduce(async (n, s) => {
403
+ if (!await n || !ie({
404
+ mimeType: s.encodingFormat,
405
+ uri: s.uri
405
406
  }))
406
407
  return !1;
407
- const t = await i.string();
408
- return t ? pe(new g.XmlDocument(t)) : !1;
409
- }, Promise.resolve(!0)), he = ({ archive: e }) => async (r) => {
410
- if (r.renditionLayout === "reflowable" && r.spineItems.every((n) => n.renditionLayout === "reflowable")) {
411
- const n = await j({ archive: e });
412
- if (await ue(n))
408
+ const t = await s.string();
409
+ return t ? Pe(new y.XmlDocument(t)) : !1;
410
+ }, Promise.resolve(!0)), Oe = ({ archive: e }) => async (n) => {
411
+ if (n.renditionLayout === "reflowable" && n.spineItems.every((r) => r.renditionLayout === "reflowable")) {
412
+ const r = await K({ archive: e });
413
+ if (await De(r))
413
414
  return {
414
- ...r,
415
- spineItems: r.spineItems.map((a) => ({
415
+ ...n,
416
+ spineItems: n.spineItems.map((a) => ({
416
417
  ...a,
417
418
  renditionLayout: "pre-paginated"
418
419
  })),
419
420
  renditionLayout: "pre-paginated"
420
421
  };
421
422
  }
422
- return r;
423
- }, C = (e, r) => {
423
+ return n;
424
+ }, I = (e, n) => {
424
425
  var t;
425
- const i = e.split(/(\d+)/), n = r.split(/(\d+)/);
426
- for (let a = 0, o = i.length; a < o; a++)
427
- if (i[a] !== n[a])
428
- return (t = i[a]) != null && t.match(/\d/) ? +(i[a] || "") - +(n[a] || "") : (i[a] || "").localeCompare(n[a] || "");
426
+ const s = e.split(/(\d+)/), r = n.split(/(\d+)/);
427
+ for (let a = 0, i = s.length; a < i; a++)
428
+ if (s[a] !== r[a])
429
+ return (t = s[a]) != null && t.match(/\d/) ? +(s[a] || "") - +(r[a] || "") : (s[a] || "").localeCompare(r[a] || "");
429
430
  return 1;
430
- }, ge = ({ archive: e, baseUrl: r }) => async (i) => {
431
- if (i.nav) return i;
432
- const n = [...e.files].sort(
433
- (a, o) => C(a.uri, o.uri)
431
+ }, je = ({ archive: e, baseUrl: n }) => async (s) => {
432
+ if (s.nav) return s;
433
+ const r = [...e.files].sort(
434
+ (a, i) => I(a.uri, i.uri)
434
435
  ), t = Object.values(
435
- n
436
+ r
436
437
  ).reduce(
437
- (a, o) => {
438
- const s = o.uri.split("/");
439
- return !o.dir && s.length > 1 && s.forEach((f, m) => {
440
- if (m === s.length - 1) return;
441
- a.find(({ title: w }) => w === f) || a.push({
438
+ (a, i) => {
439
+ const o = i.uri.split("/");
440
+ return !i.dir && o.length > 1 && o.forEach((l, d) => {
441
+ if (d === o.length - 1) return;
442
+ a.find(({ title: w }) => w === l) || a.push({
442
443
  contents: [],
443
- href: v(r, encodeURI(o.uri)).replace(/\/$/, ""),
444
- path: o.uri.replace(/\/$/, ""),
445
- title: s[0] ?? ""
444
+ href: N(n, encodeURI(i.uri)).replace(/\/$/, ""),
445
+ path: i.uri.replace(/\/$/, ""),
446
+ title: o[0] ?? ""
446
447
  });
447
448
  }), a;
448
449
  },
449
450
  []
450
451
  );
451
- return t.length === 0 ? i : {
452
- ...i,
452
+ return t.length === 0 ? s : {
453
+ ...s,
453
454
  nav: {
454
455
  toc: t
455
456
  }
456
457
  };
457
- }, ye = {
458
+ }, Ue = {
458
459
  filename: "",
459
460
  items: [],
460
461
  nav: {
@@ -465,42 +466,42 @@ const u = {
465
466
  renditionSpread: "auto",
466
467
  spineItems: [],
467
468
  title: ""
468
- }, Ne = async (e, { baseUrl: r = "" } = {}) => {
469
- const i = [
470
- me({ archive: e, baseUrl: r }),
471
- se({ archive: e, baseUrl: r }),
472
- he({ archive: e, baseUrl: r }),
473
- fe({ archive: e, baseUrl: r }),
474
- ge({ archive: e, baseUrl: r })
469
+ }, ze = async (e, { baseUrl: n = "" } = {}) => {
470
+ const s = [
471
+ Ie({ archive: e, baseUrl: n }),
472
+ ke({ archive: e, baseUrl: n }),
473
+ Oe({ archive: e, baseUrl: n }),
474
+ Ce({ archive: e, baseUrl: n }),
475
+ je({ archive: e, baseUrl: n })
475
476
  ];
476
477
  try {
477
- const n = await i.reduce(async (t, a) => await a(await t), Promise.resolve(ye));
478
- return u.log("Generated manifest", n), n;
479
- } catch (n) {
480
- throw u.error(n), n;
478
+ const r = await s.reduce(async (t, a) => await a(await t), Promise.resolve(Ue));
479
+ return g.log("Generated manifest", r), r;
480
+ } catch (r) {
481
+ throw g.error(r), r;
481
482
  }
482
- }, y = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Te = async (e, r) => {
483
- const i = `
483
+ }, x = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Ye = async (e, n) => {
484
+ const s = `
484
485
  <?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
485
486
  <metadata>
486
- <meta property="rendition:layout">${r != null && r.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
487
- ${r != null && r.useRenditionFlow ? '<meta property="rendition:flow">scrolled-continuous</meta>' : ""}
487
+ <meta property="rendition:layout">${n != null && n.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
488
+ ${n != null && n.useRenditionFlow ? '<meta property="rendition:flow">scrolled-continuous</meta>' : ""}
488
489
  </metadata>
489
490
  <manifest>
490
491
  ${e.map(
491
- (a) => `<item id="${y(a)}" href="${a}" media-type="${R(a)}"/>`
492
+ (a) => `<item id="${x(a)}" href="${a}" media-type="${z(a)}"/>`
492
493
  ).join(`
493
494
  `)}
494
495
  </manifest>
495
496
  <spine>
496
- ${e.map((a) => `<itemref idref="${y(a)}" />`).join(`
497
+ ${e.map((a) => `<itemref idref="${x(a)}" />`).join(`
497
498
  `)}
498
499
  </spine>
499
500
  </package>
500
- `, n = e.map((a) => ({
501
+ `, r = e.map((a) => ({
501
502
  dir: !1,
502
- basename: y(a),
503
- encodingFormat: R(a),
503
+ basename: x(a),
504
+ encodingFormat: z(a),
504
505
  uri: a,
505
506
  size: 100 / e.length,
506
507
  base64: async () => "",
@@ -514,23 +515,23 @@ const u = {
514
515
  basename: "content.opf",
515
516
  uri: "content.opf",
516
517
  size: 0,
517
- base64: async () => i,
518
+ base64: async () => s,
518
519
  blob: async () => new Blob(),
519
- string: async () => i
520
- }, ...n],
520
+ string: async () => s
521
+ }, ...r],
521
522
  close: () => Promise.resolve()
522
523
  };
523
- }, be = async (e) => new Promise((r) => {
524
- const i = new FileReader();
525
- i.readAsDataURL(e), i.onloadend = function() {
526
- const n = i.result;
527
- r(n);
524
+ }, Me = async (e) => new Promise((n) => {
525
+ const s = new FileReader();
526
+ s.readAsDataURL(e), s.onloadend = function() {
527
+ const r = s.result;
528
+ n(r);
528
529
  };
529
- }), Ae = async (e, {
530
- mimeType: r,
531
- direction: i
530
+ }), Ke = async (e, {
531
+ mimeType: n,
532
+ direction: s
532
533
  } = { mimeType: "text/plain" }) => {
533
- const n = `
534
+ const r = `
534
535
  <?xml version="1.0" encoding="UTF-8"?>
535
536
  <package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="ja" prefix="rendition: http://www.idpf.org/vocab/rendition/#"
536
537
  unique-identifier="ootuya-id">
@@ -541,44 +542,44 @@ const u = {
541
542
  <manifest>
542
543
  <item id="p01" href="p01.txt" media-type="text/plain"/>
543
544
  </manifest>
544
- <spine page-progression-direction="${i ?? "ltr"}">
545
+ <spine page-progression-direction="${s ?? "ltr"}">
545
546
  <itemref idref="p01" />
546
547
  </spine>
547
548
  </package>
548
549
  `;
549
550
  return {
550
- filename: "content.txt",
551
+ filename: "comicinfo.xml",
551
552
  files: [
552
553
  {
553
554
  dir: !1,
554
- basename: y("generated.opf"),
555
+ basename: x("generated.opf"),
555
556
  uri: "generated.opf",
556
- blob: async () => new Blob([n]),
557
- string: async () => n,
558
- base64: async () => btoa(n),
557
+ blob: async () => new Blob([r]),
558
+ string: async () => r,
559
+ base64: async () => btoa(r),
559
560
  size: 0
560
561
  },
561
562
  {
562
563
  dir: !1,
563
- basename: y("p01.txt"),
564
- uri: "p01.txt",
564
+ basename: x("comicinfo.xml"),
565
+ uri: "comicinfo.xml",
565
566
  blob: async () => typeof e == "string" ? new Blob([e]) : e,
566
567
  string: async () => typeof e == "string" ? e : e.text(),
567
- base64: async () => typeof e == "string" ? btoa(e) : be(e),
568
+ base64: async () => typeof e == "string" ? btoa(e) : Me(e),
568
569
  size: typeof e == "string" ? e.length : e.size,
569
- encodingFormat: r
570
+ encodingFormat: n
570
571
  }
571
572
  ],
572
573
  close: () => Promise.resolve()
573
574
  };
574
- }, Ie = async (e, { orderByAlpha: r, name: i } = {}) => {
575
- let n = Object.values(e.files);
576
- r && (n = n.slice().sort((a, o) => C(a.name, o.name)));
575
+ }, Ee = async (e, { orderByAlpha: n, name: s } = {}) => {
576
+ let r = Object.values(e.files);
577
+ n && (r = r.slice().sort((a, i) => I(a.name, i.name)));
577
578
  const t = {
578
- filename: i || "",
579
- files: n.map((a) => ({
579
+ filename: s || "",
580
+ files: r.map((a) => ({
580
581
  dir: a.dir,
581
- basename: y(a.name),
582
+ basename: x(a.name),
582
583
  uri: a.name,
583
584
  blob: () => a.async("blob"),
584
585
  string: () => a.async("string"),
@@ -593,12 +594,12 @@ const u = {
593
594
  })),
594
595
  close: () => Promise.resolve()
595
596
  };
596
- return u.log("Generated archive", t), t;
597
- }, Ce = async (e, { name: r } = {}) => {
598
- const i = await e.getFilesArray(), n = {
597
+ return g.log("Generated archive", t), t;
598
+ }, Qe = async (e, { name: n } = {}) => {
599
+ const s = await e.getFilesArray(), r = {
599
600
  close: () => e.close(),
600
- filename: r ?? "",
601
- files: i.map((t) => ({
601
+ filename: n ?? "",
602
+ files: s.map((t) => ({
602
603
  dir: !1,
603
604
  basename: t.file.name,
604
605
  size: t.file.size,
@@ -608,14 +609,14 @@ const u = {
608
609
  string: async () => (await t.file.extract()).text()
609
610
  }))
610
611
  };
611
- return u.log("Generated archive", n), n;
612
- }, We = async (e, { orderByAlpha: r, name: i } = {}) => {
613
- let n = e;
614
- return r && (n = n.slice().sort((t, a) => C(t.name, a.name))), {
615
- filename: i || "",
616
- files: n.map((t) => ({
612
+ return g.log("Generated archive", r), r;
613
+ }, Ze = async (e, { orderByAlpha: n, name: s } = {}) => {
614
+ let r = e;
615
+ return n && (r = r.slice().sort((t, a) => I(t.name, a.name))), {
616
+ filename: s || "",
617
+ files: r.map((t) => ({
617
618
  dir: t.isDir,
618
- basename: y(t.name),
619
+ basename: x(t.name),
619
620
  uri: t.name,
620
621
  blob: async () => new Blob([await t.data()]),
621
622
  string: async () => {
@@ -630,21 +631,163 @@ const u = {
630
631
  })),
631
632
  close: () => Promise.resolve()
632
633
  };
633
- }, ke = ({
634
+ }, et = ({
634
635
  enableReport: e
635
636
  } = {}) => {
636
- u.enable(!!e);
637
+ g.enable(!!e);
638
+ }, Ve = ({
639
+ getArchive: e,
640
+ cleanAfter: n
641
+ }) => {
642
+ const s = new M(), r = new M(), t = {}, a = s.pipe(
643
+ W((c) => {
644
+ const l = t[c];
645
+ return !l || l.getValue().status !== "idle" ? ce : (l.next({
646
+ ...l.getValue(),
647
+ status: "loading"
648
+ }), A(e(c)).pipe(
649
+ v((d) => (l.next({
650
+ ...l.getValue(),
651
+ archive: d,
652
+ status: "success"
653
+ }), { key: c, archiveEntry: l })),
654
+ F((d) => {
655
+ throw l.next({
656
+ ...l.getValue(),
657
+ status: "error",
658
+ error: d
659
+ }), d;
660
+ })
661
+ ));
662
+ }),
663
+ F((c) => (console.error(c), V)),
664
+ de()
665
+ ), i = a.pipe(
666
+ B(({ archiveEntry: c, key: l }) => c.pipe(v(({ locks: f }) => f)).pipe(v((f) => f <= 0)).pipe(
667
+ B((f) => f ? le(n) : V),
668
+ X(() => {
669
+ var f;
670
+ delete t[l], (f = c.getValue().archive) == null || f.close();
671
+ })
672
+ ))
673
+ ), o = (c) => {
674
+ let l = !1;
675
+ const d = t[c] ?? new pe({ archive: void 0, status: "idle", locks: 0, error: void 0 });
676
+ t[c] = d, d.next({
677
+ ...d.getValue(),
678
+ locks: d.getValue().locks + 1
679
+ });
680
+ const u = () => {
681
+ l || (l = !0, d.next({
682
+ ...d.getValue(),
683
+ locks: d.getValue().locks - 1
684
+ }));
685
+ };
686
+ s.next(c);
687
+ const f = d.pipe(
688
+ v(({ archive: h }) => h),
689
+ fe((h) => !!h)
690
+ ), w = d.pipe(
691
+ X(({ error: h }) => {
692
+ if (h)
693
+ throw h;
694
+ }),
695
+ ue()
696
+ );
697
+ return _(f, w).pipe(
698
+ he(),
699
+ v((h) => ({ archive: h, release: u })),
700
+ F((h) => {
701
+ throw u(), h;
702
+ })
703
+ );
704
+ };
705
+ return _(i, a).pipe(me(r)).subscribe(), {
706
+ access: o
707
+ };
637
708
  };
709
+ class Be {
710
+ constructor(n) {
711
+ this.epubLoader = Ve(n);
712
+ }
713
+ fetchManifest({ key: n, baseUrl: s }) {
714
+ const r = this.epubLoader.access(n).pipe(
715
+ W(({ archive: t, release: a }) => A(
716
+ ze(t, { baseUrl: s })
717
+ ).pipe(
718
+ v(
719
+ (o) => new Response(JSON.stringify(o), {
720
+ status: 200
721
+ })
722
+ ),
723
+ H(() => {
724
+ a();
725
+ })
726
+ )),
727
+ F((t) => G(new Response(String(t), { status: 500 })))
728
+ );
729
+ return J(r);
730
+ }
731
+ fetchResource({
732
+ key: n,
733
+ resourcePath: s
734
+ }) {
735
+ const r = this.epubLoader.access(n).pipe(
736
+ W(({ archive: t, release: a }) => A(
737
+ Ae(t, s)
738
+ ).pipe(
739
+ v((o) => new Response(o.body, { status: 200 })),
740
+ H(() => {
741
+ a();
742
+ })
743
+ )),
744
+ F((t) => G(new Response(String(t), { status: 500 })))
745
+ );
746
+ return J(r);
747
+ }
748
+ }
749
+ const Xe = (e) => e.indexOf("/") !== -1 ? e.substring(0, e.indexOf("/")) : e;
750
+ class tt extends Be {
751
+ constructor({
752
+ getStreamerUri: n,
753
+ ...s
754
+ }) {
755
+ super(s), this.getStreamerUri = n, this.fetchEventListener = this.fetchEventListener.bind(this);
756
+ }
757
+ fetchEventListener(n) {
758
+ try {
759
+ const s = new URL(n.request.url), r = this.getStreamerUri(n), t = `/${r}`;
760
+ if (!r) return;
761
+ const a = Xe(r), o = `${s.href.substring(
762
+ 0,
763
+ s.href.length - t.length
764
+ )}/${a}/`;
765
+ if (r.endsWith("/manifest"))
766
+ n.respondWith(this.fetchManifest({ key: a, baseUrl: o }));
767
+ else {
768
+ const c = r.substring(
769
+ a.length + 1,
770
+ r.length
771
+ );
772
+ n.respondWith(this.fetchResource({ key: a, resourcePath: c }));
773
+ }
774
+ } catch (s) {
775
+ n.respondWith(new Response(String(s), { status: 500 }));
776
+ }
777
+ }
778
+ }
638
779
  export {
639
- ke as configure,
640
- We as createArchiveFromArrayBufferList,
641
- Ie as createArchiveFromJszip,
642
- Ce as createArchiveFromLibArchive,
643
- Ae as createArchiveFromText,
644
- Te as createArchiveFromUrls,
645
- Ne as generateManifestFromArchive,
646
- Fe as generateResourceFromArchive,
647
- $e as generateResourceFromError,
648
- F as getArchiveOpfInfo
780
+ tt as ServiceWorkerStreamer,
781
+ Be as Streamer,
782
+ et as configure,
783
+ Ze as createArchiveFromArrayBufferList,
784
+ Ee as createArchiveFromJszip,
785
+ Qe as createArchiveFromLibArchive,
786
+ Ke as createArchiveFromText,
787
+ Ye as createArchiveFromUrls,
788
+ ze as generateManifestFromArchive,
789
+ Ae as generateResourceFromArchive,
790
+ qe as generateResourceFromError,
791
+ S as getArchiveOpfInfo
649
792
  };
650
793
  //# sourceMappingURL=index.js.map