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