@prose-reader/streamer 1.206.0 → 1.208.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,176 +1,153 @@
1
1
  import $, { XmlDocument as de, XmlTextNode as le, XmlElement as pe } from "xmldoc";
2
- import { urlJoin as k, isXmlBasedMimeType as fe, parseContentType as ue, detectMimeTypeFromName as O } from "@prose-reader/shared";
3
- import { Subject as R, mergeMap as M, EMPTY as _, pairwise as me, filter as j, startWith as he, from as P, tap as D, catchError as I, switchMap as W, merge as q, takeUntil as ge, map as F, ignoreElements as ye, first as be, BehaviorSubject as we, distinctUntilChanged as ve, shareReplay as $e, NEVER as G, timer as xe, finalize as K, of as J, lastValueFrom as Y } from "rxjs";
4
- let T = !1;
5
- const w = {
2
+ import { urlJoin as W, isXmlBasedMimeType as fe, parseContentType as ue, detectMimeTypeFromName as O } from "@prose-reader/shared";
3
+ import { Subject as R, mergeMap as M, EMPTY as _, pairwise as me, filter as D, startWith as he, from as P, tap as j, catchError as C, switchMap as L, merge as q, takeUntil as ge, map as F, ignoreElements as ye, first as be, BehaviorSubject as we, distinctUntilChanged as ve, shareReplay as $e, NEVER as G, timer as xe, finalize as K, of as J, lastValueFrom as Y } from "rxjs";
4
+ let S = !1;
5
+ const v = {
6
6
  enable: (e) => {
7
- T = e;
7
+ S = e;
8
8
  },
9
9
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
10
10
  log: (...e) => {
11
- T && console.log("[prose-reader-streamer]", ...e);
11
+ S && console.log("[prose-reader-streamer]", ...e);
12
+ },
13
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
14
+ debug: (...e) => {
15
+ S && console.debug("[prose-reader-streamer]", ...e);
12
16
  },
13
17
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
14
18
  warn: (...e) => {
15
- T && console.warn("[prose-reader-streamer]", ...e);
19
+ S && console.warn("[prose-reader-streamer]", ...e);
16
20
  },
17
21
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
18
22
  error: (...e) => {
19
23
  console.error(...e);
20
- },
21
- time: (e) => {
22
- T && console.time(`[prose-reader-streamer] [metric] ${e}`);
23
- },
24
- timeEnd: (e) => {
25
- T && console.timeEnd(`[prose-reader-streamer] [metric] ${e}`);
26
- },
27
- metric: (e, t = 1 / 0) => {
28
- const i = typeof e == "number" ? e : e.duration;
29
- T && (e.duration <= t ? console.log(
30
- "[prose-reader-streamer] [metric] ",
31
- `${e.name} took ${i}ms`
32
- ) : console.warn(
33
- "[prose-reader-streamer] [metric] ",
34
- `${e.name} took ${e.duration}ms which is above the ${t}ms target for this function`
35
- ));
36
- },
37
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
38
- measurePerformance: (e, t, i) => (...s) => {
39
- const n = performance.now(), r = i(...s);
40
- if (r != null && r.then)
41
- return r.then((a) => {
42
- const c = performance.now();
43
- return w.metric({ name: e, duration: c - n }, t), a;
44
- });
45
- const o = performance.now();
46
- return w.metric({ name: e, duration: o - n }, t), r;
47
24
  }
48
25
  }, Fe = (e) => {
49
26
  var i;
50
- const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((s) => s.attr.name === "calibre:cover");
27
+ const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((r) => r.attr.name === "calibre:cover");
51
28
  return !!(t && t.attr.name === "calibre:cover");
52
29
  }, Ae = (e) => {
53
- var t, i, s;
54
- return (s = (i = (t = e.descendantWithPath("body")) == null ? void 0 : t.descendantWithPath("div")) == null ? void 0 : i.childrenNamed("svg")) == null ? void 0 : s.find(
30
+ var t, i, r;
31
+ return (r = (i = (t = e.descendantWithPath("body")) == null ? void 0 : t.descendantWithPath("div")) == null ? void 0 : i.childrenNamed("svg")) == null ? void 0 : r.find(
55
32
  (n) => n.attr.width === "100%" && n.attr.preserveAspectRatio === "none"
56
33
  );
57
34
  }, Te = ({ archive: e, resourcePath: t }) => async (i) => {
58
- const s = Object.values(e.files).find(
35
+ const r = Object.values(e.files).find(
59
36
  (n) => n.uri === t
60
37
  );
61
- if (s != null && s.basename.endsWith(".xhtml")) {
62
- const n = i.body ?? await s.string(), r = new de(n);
63
- if (Fe(r)) {
64
- const o = Ae(r);
38
+ if (r != null && r.basename.endsWith(".xhtml")) {
39
+ const n = i.body ?? await r.string(), s = new de(n);
40
+ if (Fe(s)) {
41
+ const o = Ae(s);
65
42
  return o && delete o.attr.preserveAspectRatio, {
66
43
  ...i,
67
- body: r == null ? void 0 : r.toString()
44
+ body: s == null ? void 0 : s.toString()
68
45
  };
69
46
  }
70
47
  }
71
48
  return i;
72
49
  }, Le = ({ archive: e, resourcePath: t }) => async (i) => Te({ archive: e, resourcePath: t })(i), We = ({ archive: e, resourcePath: t }) => async (i) => {
73
- const s = Object.values(e.files).find(
50
+ const r = Object.values(e.files).find(
74
51
  (n) => n.uri === t
75
52
  );
76
- if (s != null && s.basename.endsWith(".css")) {
77
- const r = (i.body ?? await s.string()).replaceAll(
53
+ if (r != null && r.basename.endsWith(".css")) {
54
+ const s = (i.body ?? await r.string()).replaceAll(
78
55
  "-webkit-writing-mode",
79
56
  "writing-mode"
80
57
  );
81
58
  return {
82
59
  ...i,
83
- body: r
60
+ body: s
84
61
  };
85
62
  }
86
63
  return i;
87
- }, ee = (e) => e ? e.children.map((t) => t instanceof le ? t.text : t instanceof pe ? ee(t) : "").join("").trim() : "", A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Q = (e) => e.endsWith("/") ? e.slice(0, -1) : e, ke = (e) => {
64
+ }, ee = (e) => e ? e.children.map((t) => t instanceof le ? t.text : t instanceof pe ? ee(t) : "").join("").trim() : "", A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Q = (e) => e.endsWith("/") ? e.slice(0, -1) : e, Ne = (e) => {
88
65
  const t = e.lastIndexOf("/");
89
66
  return t >= 0 ? e.substring(0, t) : "";
90
67
  }, te = (e, { basePath: t, baseUrl: i }) => {
91
- const s = {
68
+ const r = {
92
69
  contents: [],
93
70
  path: "",
94
71
  href: "",
95
72
  title: ""
96
73
  };
97
74
  let n = e.childNamed("span") || e.childNamed("a");
98
- s.title = ((n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || ee(n)) ?? "";
99
- let r = n == null ? void 0 : n.name;
100
- r !== "a" && (n = e.descendantWithPath(`${r}.a`), n && (r = n.name.toLowerCase())), r === "a" && (n != null && n.attr.href) && (s.path = k(t, n.attr.href), s.href = k(i, t, n.attr.href));
75
+ r.title = ((n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || ee(n)) ?? "";
76
+ let s = n == null ? void 0 : n.name;
77
+ s !== "a" && (n = e.descendantWithPath(`${s}.a`), n && (s = n.name.toLowerCase())), s === "a" && (n != null && n.attr.href) && (r.path = W(t, n.attr.href), r.href = W(i, t, n.attr.href));
101
78
  const o = e.childNamed("ol");
102
79
  if (o) {
103
80
  const a = o.childrenNamed("li");
104
- a && a.length > 0 && (s.contents = a.map(
105
- (c) => te(c, { basePath: t, baseUrl: i })
81
+ a && a.length > 0 && (r.contents = a.map(
82
+ (d) => te(d, { basePath: t, baseUrl: i })
106
83
  ));
107
84
  }
108
- return s;
109
- }, Ne = (e, { basePath: t, baseUrl: i }) => {
110
- var r, o;
111
- const s = [];
85
+ return r;
86
+ }, ke = (e, { basePath: t, baseUrl: i }) => {
87
+ var s, o;
88
+ const r = [];
112
89
  let n;
113
- return e.descendantWithPath("body.nav.ol") ? n = (r = e.descendantWithPath("body.nav.ol")) == null ? void 0 : r.children : e.descendantWithPath("body.section.nav.ol") && (n = (o = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : o.children), n && n.length > 0 && n.filter((a) => a.name === "li").forEach(
114
- (a) => s.push(te(a, { basePath: t, baseUrl: i }))
115
- ), s;
90
+ return e.descendantWithPath("body.nav.ol") ? n = (s = e.descendantWithPath("body.nav.ol")) == null ? void 0 : s.children : e.descendantWithPath("body.section.nav.ol") && (n = (o = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : o.children), n && n.length > 0 && n.filter((a) => a.name === "li").forEach(
91
+ (a) => r.push(te(a, { basePath: t, baseUrl: i }))
92
+ ), r;
116
93
  }, Se = async (e, t, { baseUrl: i }) => {
117
94
  var n;
118
- const s = (n = e.childNamed("manifest")) == null ? void 0 : n.childrenNamed("item").find((r) => r.attr.properties === "nav");
119
- if (s) {
120
- const r = Object.values(t.files).find(
121
- (o) => o.uri.endsWith(s.attr.href || "")
95
+ const r = (n = e.childNamed("manifest")) == null ? void 0 : n.childrenNamed("item").find((s) => s.attr.properties === "nav");
96
+ if (r) {
97
+ const s = Object.values(t.files).find(
98
+ (o) => o.uri.endsWith(r.attr.href || "")
122
99
  );
123
- if (r) {
124
- const o = new $.XmlDocument(await r.string()), a = ke(r.uri);
125
- return Ne(o, { basePath: a, baseUrl: i });
100
+ if (s) {
101
+ const o = new $.XmlDocument(await s.string()), a = Ne(s.uri);
102
+ return ke(o, { basePath: a, baseUrl: i });
126
103
  }
127
104
  }
128
105
  }, ne = (e, {
129
106
  opfBasePath: t,
130
107
  baseUrl: i,
131
- prefix: s
108
+ prefix: r
132
109
  }) => {
133
- var a, c;
134
- const n = ((a = e == null ? void 0 : e.childNamed(`${s}content`)) == null ? void 0 : a.attr.src) || "", r = {
135
- title: ((c = e == null ? void 0 : e.descendantWithPath(`${s}navLabel.${s}text`)) == null ? void 0 : c.val) || "",
136
- path: k(t, n),
137
- href: k(i, t, n),
110
+ var a, d;
111
+ const n = ((a = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : a.attr.src) || "", s = {
112
+ title: ((d = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : d.val) || "",
113
+ path: W(t, n),
114
+ href: W(i, t, n),
138
115
  contents: []
139
- }, o = e.childrenNamed(`${s}navPoint`);
140
- return o && o.length > 0 && (r.contents = o.map(
141
- (l) => ne(l, { opfBasePath: t, baseUrl: i, prefix: s })
142
- )), r;
116
+ }, o = e.childrenNamed(`${r}navPoint`);
117
+ return o && o.length > 0 && (s.contents = o.map(
118
+ (l) => ne(l, { opfBasePath: t, baseUrl: i, prefix: r })
119
+ )), s;
143
120
  }, Pe = (e, { opfBasePath: t, baseUrl: i }) => {
144
121
  var o;
145
- const s = [], n = e.name;
146
- let r = "";
147
- return n.indexOf(":") !== -1 && (r = `${n.split(":")[0]}:`), (o = e.childNamed(`${r}navMap`)) == null || o.childrenNamed(`${r}navPoint`).forEach(
148
- (a) => s.push(ne(a, { opfBasePath: t, baseUrl: i, prefix: r }))
149
- ), s;
150
- }, Ie = async ({
122
+ const r = [], n = e.name;
123
+ let s = "";
124
+ return n.indexOf(":") !== -1 && (s = `${n.split(":")[0]}:`), (o = e.childNamed(`${s}navMap`)) == null || o.childrenNamed(`${s}navPoint`).forEach(
125
+ (a) => r.push(ne(a, { opfBasePath: t, baseUrl: i, prefix: s }))
126
+ ), r;
127
+ }, Ce = async ({
151
128
  opfData: e,
152
129
  opfBasePath: t,
153
130
  baseUrl: i,
154
- archive: s
131
+ archive: r
155
132
  }) => {
156
133
  var o;
157
- const n = e.childNamed("spine"), r = n == null ? void 0 : n.attr.toc;
158
- if (r) {
159
- const a = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((c) => c.attr.id === r);
134
+ const n = e.childNamed("spine"), s = n == null ? void 0 : n.attr.toc;
135
+ if (s) {
136
+ const a = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((d) => d.attr.id === s);
160
137
  if (a) {
161
- const c = `${t}${t === "" ? "" : "/"}${a.attr.href}`, l = Object.values(s.files).find(
162
- (d) => d.uri.endsWith(c)
138
+ const d = `${t}${t === "" ? "" : "/"}${a.attr.href}`, l = Object.values(r.files).find(
139
+ (c) => c.uri.endsWith(d)
163
140
  );
164
141
  if (l) {
165
- const d = new $.XmlDocument(await l.string());
166
- return Pe(d, { opfBasePath: t, baseUrl: i });
142
+ const c = new $.XmlDocument(await l.string());
143
+ return Pe(c, { opfBasePath: t, baseUrl: i });
167
144
  }
168
145
  }
169
146
  }
170
- }, Ce = async (e, t, { baseUrl: i }) => {
171
- const { basePath: s } = N(t) || {}, n = await Ie({
147
+ }, Ie = async (e, t, { baseUrl: i }) => {
148
+ const { basePath: r } = N(t) || {}, n = await Ce({
172
149
  opfData: e,
173
- opfBasePath: s,
150
+ opfBasePath: r,
174
151
  archive: t,
175
152
  baseUrl: i
176
153
  });
@@ -178,8 +155,8 @@ const w = {
178
155
  baseUrl: i
179
156
  });
180
157
  }, Re = (e) => {
181
- var s;
182
- const t = ((s = e.attr.properties) == null ? void 0 : s.split(" ")) || [];
158
+ var r;
159
+ const t = ((r = e.attr.properties) == null ? void 0 : r.split(" ")) || [];
183
160
  let i;
184
161
  return t.find((n) => n === "rendition:layout-reflowable") && (i = "reflowable"), t.find((n) => n === "rendition:layout-pre-paginated") && (i = "pre-paginated"), {
185
162
  renditionLayout: i,
@@ -187,7 +164,7 @@ const w = {
187
164
  pageSpreadRight: t.some((n) => n === "page-spread-right") || void 0
188
165
  };
189
166
  }, N = (e) => {
190
- const i = Object.values(e.files).filter((s) => !s.dir).find((s) => s.uri.endsWith(".opf"));
167
+ const i = Object.values(e.files).filter((r) => !r.dir).find((r) => r.uri.endsWith(".opf"));
191
168
  return {
192
169
  data: i,
193
170
  basePath: (i == null ? void 0 : i.uri.substring(0, i.uri.lastIndexOf("/"))) || ""
@@ -195,36 +172,36 @@ const w = {
195
172
  }, re = async ({
196
173
  archive: e
197
174
  }) => {
198
- const { data: t, basePath: i } = N(e) || {}, s = await (t == null ? void 0 : t.string());
199
- if (!s) return [];
200
- const n = new $.XmlDocument(s), r = n.childNamed("manifest"), o = n.childNamed("spine"), a = o == null ? void 0 : o.childrenNamed("itemref").map((d) => d.attr.idref), c = (r == null ? void 0 : r.childrenNamed("item").filter((d) => a.includes(d.attr.id || ""))) || [];
201
- return e.files.filter((d) => c.find((p) => i ? `${i}/${p.attr.href}` === d.uri : `${p.attr.href}` === d.uri));
202
- }, je = (e, t, i) => {
203
- const s = e.attr.href || "", n = i == null ? void 0 : i(e);
175
+ const { data: t, basePath: i } = N(e) || {}, r = await (t == null ? void 0 : t.string());
176
+ if (!r) return [];
177
+ const n = new $.XmlDocument(r), s = n.childNamed("manifest"), o = n.childNamed("spine"), a = o == null ? void 0 : o.childrenNamed("itemref").map((c) => c.attr.idref), d = (s == null ? void 0 : s.childrenNamed("item").filter((c) => a.includes(c.attr.id || ""))) || [];
178
+ return e.files.filter((c) => d.find((p) => i ? `${i}/${p.attr.href}` === c.uri : `${p.attr.href}` === c.uri));
179
+ }, De = (e, t, i) => {
180
+ const r = e.attr.href || "", n = i == null ? void 0 : i(e);
204
181
  return {
205
- href: t ? `${n}${t}/${s}` : `${n}${s}`,
182
+ href: t ? `${n}${t}/${r}` : `${n}${r}`,
206
183
  id: e.attr.id || "",
207
184
  mediaType: e.attr["media-type"]
208
185
  };
209
186
  }, se = (e, t, i) => {
210
- var r;
211
- const s = e.childNamed("manifest"), { basePath: n } = N(t) || {};
212
- return ((r = s == null ? void 0 : s.childrenNamed("item")) == null ? void 0 : r.map((o) => je(o, n, i))) || [];
213
- }, De = ({ archive: e, baseUrl: t }) => async (i) => {
187
+ var s;
188
+ const r = e.childNamed("manifest"), { basePath: n } = N(t) || {};
189
+ return ((s = r == null ? void 0 : r.childrenNamed("item")) == null ? void 0 : s.map((o) => De(o, n, i))) || [];
190
+ }, je = ({ archive: e, baseUrl: t }) => async (i) => {
214
191
  var X;
215
- const { data: s, basePath: n } = N(e) || {};
216
- if (!s)
192
+ const { data: r, basePath: n } = N(e) || {};
193
+ if (!r)
217
194
  return i;
218
- const r = await s.string();
219
- w.log("data", r);
220
- const o = new $.XmlDocument(r), a = await Ce(o, e, { baseUrl: t }) || [], c = o.childNamed("metadata"), l = o.childNamed("manifest"), d = o.childNamed("spine"), p = o.childNamed("guide"), u = c == null ? void 0 : c.childNamed("dc:title"), g = (c == null ? void 0 : c.childrenNamed("meta")) || [], b = g.find(
195
+ const s = await r.string();
196
+ v.log("data", s);
197
+ const o = new $.XmlDocument(s), a = await Ie(o, e, { baseUrl: t }) || [], d = o.childNamed("metadata"), l = o.childNamed("manifest"), c = o.childNamed("spine"), p = o.childNamed("guide"), u = d == null ? void 0 : d.childNamed("dc:title"), g = (d == null ? void 0 : d.childrenNamed("meta")) || [], b = g.find(
221
198
  (m) => m.attr.property === "rendition:layout"
222
199
  ), h = g.find(
223
200
  (m) => m.attr.property === "rendition:flow"
224
201
  ), x = g.find(
225
202
  (m) => m.attr.property === "rendition:spread"
226
- ), y = b == null ? void 0 : b.val, v = h == null ? void 0 : h.val, S = x == null ? void 0 : x.val, ie = (u == null ? void 0 : u.val) || ((X = e.files.find(({ dir: m }) => m)) == null ? void 0 : X.basename) || "", oe = d == null ? void 0 : d.attr["page-progression-direction"], ae = (await re({ archive: e })).reduce(
227
- (m, L) => L.size + m,
203
+ ), y = b == null ? void 0 : b.val, w = h == null ? void 0 : h.val, k = x == null ? void 0 : x.val, ie = (u == null ? void 0 : u.val) || ((X = e.files.find(({ dir: m }) => m)) == null ? void 0 : X.basename) || "", oe = c == null ? void 0 : c.attr["page-progression-direction"], ae = (await re({ archive: e })).reduce(
204
+ (m, T) => T.size + m,
228
205
  0
229
206
  );
230
207
  return {
@@ -233,30 +210,30 @@ const w = {
233
210
  toc: a
234
211
  },
235
212
  renditionLayout: y,
236
- renditionFlow: v || "auto",
237
- renditionSpread: S,
213
+ renditionFlow: w || "auto",
214
+ renditionSpread: k,
238
215
  title: ie,
239
216
  readingDirection: oe || "ltr",
240
217
  /**
241
218
  * @see https://www.w3.org/TR/epub/#sec-itemref-elem
242
219
  */
243
- spineItems: (d == null ? void 0 : d.childrenNamed("itemref").map((m, L) => {
244
- var V, E;
245
- const f = l == null ? void 0 : l.childrenNamed("item").find((C) => C.attr.id === (m == null ? void 0 : m.attr.idref)), U = (f == null ? void 0 : f.attr.href) || "", ce = ((V = e.files.find((C) => C.uri.endsWith(U))) == null ? void 0 : V.size) || 0, B = t || (/^https?:\/\//.test(U) ? "" : "file://"), H = Re(m);
220
+ spineItems: (c == null ? void 0 : c.childrenNamed("itemref").map((m, T) => {
221
+ var H, V;
222
+ const f = l == null ? void 0 : l.childrenNamed("item").find((I) => I.attr.id === (m == null ? void 0 : m.attr.idref)), U = (f == null ? void 0 : f.attr.href) || "", ce = ((H = e.files.find((I) => I.uri.endsWith(U))) == null ? void 0 : H.size) || 0, B = t || (/^https?:\/\//.test(U) ? "" : "file://"), E = Re(m);
246
223
  return {
247
- ...H,
224
+ ...E,
248
225
  id: (f == null ? void 0 : f.attr.id) || "",
249
- index: L,
250
- href: (E = f == null ? void 0 : f.attr.href) != null && E.startsWith("https://") ? f == null ? void 0 : f.attr.href : n ? `${B}${n}/${f == null ? void 0 : f.attr.href}` : `${B}${f == null ? void 0 : f.attr.href}`,
251
- renditionLayout: H.renditionLayout ?? y,
226
+ index: T,
227
+ href: (V = f == null ? void 0 : f.attr.href) != null && V.startsWith("https://") ? f == null ? void 0 : f.attr.href : n ? `${B}${n}/${f == null ? void 0 : f.attr.href}` : `${B}${f == null ? void 0 : f.attr.href}`,
228
+ renditionLayout: E.renditionLayout ?? y,
252
229
  progressionWeight: ce / ae,
253
230
  // size: itemSize
254
231
  mediaType: f == null ? void 0 : f.attr["media-type"]
255
232
  };
256
233
  })) || [],
257
234
  items: se(o, e, (m) => {
258
- const L = m.attr.href || "";
259
- return /^https?:\/\//.test(L) ? "" : t || "file://";
235
+ const T = m.attr.href || "";
236
+ return /^https?:\/\//.test(T) ? "" : t || "file://";
260
237
  }),
261
238
  guide: p == null ? void 0 : p.childrenNamed("reference").map((m) => ({
262
239
  href: m.attr.href || "",
@@ -265,15 +242,15 @@ const w = {
265
242
  }))
266
243
  };
267
244
  }, Oe = async (e, t) => {
268
- var n, r, o;
269
- const s = await ((n = N(e).data) == null ? void 0 : n.string());
270
- if (s) {
271
- const a = new $.XmlDocument(s), c = se(a, e, () => "");
272
- if ((r = c.find(
273
- (d) => t.endsWith(d.href)
274
- )) == null ? void 0 : r.mediaType)
245
+ var n, s, o;
246
+ const r = await ((n = N(e).data) == null ? void 0 : n.string());
247
+ if (r) {
248
+ const a = new $.XmlDocument(r), d = se(a, e, () => "");
249
+ if ((s = d.find(
250
+ (c) => t.endsWith(c.href)
251
+ )) == null ? void 0 : s.mediaType)
275
252
  return {
276
- mediaType: (o = c.find((d) => t.endsWith(d.href))) == null ? void 0 : o.mediaType
253
+ mediaType: (o = d.find((c) => t.endsWith(c.href))) == null ? void 0 : o.mediaType
277
254
  };
278
255
  }
279
256
  return {
@@ -291,17 +268,17 @@ const w = {
291
268
  if (e.endsWith(".svg"))
292
269
  return "image/svg+xml";
293
270
  }, ze = ({ archive: e, resourcePath: t }) => async (i) => {
294
- const s = Object.values(e.files).find(
295
- (r) => r.uri === t
271
+ const r = Object.values(e.files).find(
272
+ (s) => s.uri === t
296
273
  );
297
- if (!s) return i;
274
+ if (!r) return i;
298
275
  const n = await Oe(e, t);
299
276
  return {
300
277
  ...i,
301
278
  params: {
302
279
  ...i.params,
303
- ...(s == null ? void 0 : s.encodingFormat) && {
304
- contentType: s.encodingFormat
280
+ ...(r == null ? void 0 : r.encodingFormat) && {
281
+ contentType: r.encodingFormat
305
282
  },
306
283
  ...n.mediaType && {
307
284
  contentType: n.mediaType
@@ -360,11 +337,11 @@ const w = {
360
337
  "script",
361
338
  "style"
362
339
  ], Xe = ({ archive: e, resourcePath: t }) => async (i) => {
363
- const s = Object.values(e.files).find(
340
+ const r = Object.values(e.files).find(
364
341
  (n) => n.uri === t
365
342
  );
366
- if (s != null && s.basename.endsWith(".xhtml")) {
367
- const n = i.body ?? await s.string();
343
+ if (r != null && r.basename.endsWith(".xhtml")) {
344
+ const n = i.body ?? await r.string();
368
345
  if (!new RegExp(
369
346
  `<(${Z.join("|")})[\\s/>]`,
370
347
  "i"
@@ -375,7 +352,7 @@ const w = {
375
352
  "gi"
376
353
  ), a = n.replace(
377
354
  o,
378
- (c, l, d = "") => `<${l} ${d.trim()}></${l}>`
355
+ (d, l, c = "") => `<${l} ${c.trim()}></${l}>`
379
356
  );
380
357
  return {
381
358
  ...i,
@@ -385,11 +362,11 @@ const w = {
385
362
  return i;
386
363
  }, Ue = async (e, t) => {
387
364
  const i = Object.values(e.files).find(
388
- (r) => r.uri === t
365
+ (s) => s.uri === t
389
366
  );
390
367
  if (!i)
391
368
  throw new Error("no file found");
392
- const s = {
369
+ const r = {
393
370
  params: {}
394
371
  }, n = [
395
372
  ze({ archive: e, resourcePath: t }),
@@ -398,31 +375,31 @@ const w = {
398
375
  Le({ archive: e, resourcePath: t })
399
376
  ];
400
377
  try {
401
- const r = await n.reduce(async (o, a) => await a(await o), Promise.resolve(s));
402
- return w.log("Generated resource", t, r), {
403
- ...r,
404
- body: r.body ?? await i.blob()
378
+ const s = await n.reduce(async (o, a) => await a(await o), Promise.resolve(r));
379
+ return v.log("Generated resource", t, s), {
380
+ ...s,
381
+ body: s.body ?? await i.blob()
405
382
  };
406
- } catch (r) {
407
- throw w.error(r), r;
383
+ } catch (s) {
384
+ throw v.error(s), s;
408
385
  }
409
386
  }, Be = ({ archive: e, baseUrl: t }) => async () => {
410
- var s;
387
+ var r;
411
388
  const i = Object.values(e.files).filter((n) => !n.dir);
412
389
  return {
413
390
  filename: e.filename,
414
- title: ((s = e.files.find(({ dir: n }) => n)) == null ? void 0 : s.basename.replace(/\/$/, "")) || "",
391
+ title: ((r = e.files.find(({ dir: n }) => n)) == null ? void 0 : r.basename.replace(/\/$/, "")) || "",
415
392
  renditionLayout: void 0,
416
393
  renditionSpread: "auto",
417
394
  readingDirection: "ltr",
418
- spineItems: i.filter((n) => !n.basename.endsWith(".db")).map((n, r) => {
395
+ spineItems: i.filter((n) => !n.basename.endsWith(".db")).map((n, s) => {
419
396
  const o = t || (/^https?:\/\//.test(n.uri) ? "" : "file://");
420
397
  return {
421
398
  // some books such as cbz can have same basename inside different sub folder
422
399
  // we need to make sure to have unique index
423
400
  // /chap01/01.png, /chap02/01.png, etc
424
- id: `${r}.${n.basename}`,
425
- index: r,
401
+ id: `${s}.${n.basename}`,
402
+ index: s,
426
403
  href: encodeURI(`${o}${n.uri}`),
427
404
  renditionLayout: void 0,
428
405
  progressionWeight: 1 / i.length,
@@ -431,33 +408,33 @@ const w = {
431
408
  mediaType: n.encodingFormat
432
409
  };
433
410
  }),
434
- items: i.map((n, r) => ({
435
- id: `${r}.${n.basename}`,
411
+ items: i.map((n, s) => ({
412
+ id: `${s}.${n.basename}`,
436
413
  href: encodeURI(`${t}${n.uri}`)
437
414
  }))
438
415
  };
439
- }, He = async (e) => {
416
+ }, Ee = async (e) => {
440
417
  const t = {
441
418
  renditionLayout: void 0
442
419
  };
443
420
  return await Promise.all(
444
421
  e.files.map(async (i) => {
445
- var s, n;
422
+ var r, n;
446
423
  if (i.uri.endsWith("com.kobobooks.display-options.xml")) {
447
- const o = (s = new $.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : s.childNamed("option");
424
+ const o = (r = new $.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : r.childNamed("option");
448
425
  ((n = o == null ? void 0 : o.attr) == null ? void 0 : n.name) === "fixed-layout" && o.val === "true" && (t.renditionLayout = "pre-paginated");
449
426
  }
450
427
  })
451
428
  ), t;
452
- }, Ve = ({ archive: e }) => async (t) => {
453
- const i = await He(e);
429
+ }, He = ({ archive: e }) => async (t) => {
430
+ const i = await Ee(e);
454
431
  return {
455
432
  ...t,
456
433
  renditionLayout: t.renditionLayout ?? i.renditionLayout
457
434
  };
458
- }, Ee = (e) => {
435
+ }, Ve = (e) => {
459
436
  var i;
460
- const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((s) => s.attr.name === "viewport");
437
+ const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((r) => r.attr.name === "viewport");
461
438
  return !!(t && t.attr.name === "viewport");
462
439
  }, _e = (e) => e.reduce(async (t, i) => {
463
440
  if (!await t || !fe({
@@ -466,15 +443,15 @@ const w = {
466
443
  }))
467
444
  return !1;
468
445
  const n = await i.string();
469
- return n ? Ee(new $.XmlDocument(n)) : !1;
446
+ return n ? Ve(new $.XmlDocument(n)) : !1;
470
447
  }, Promise.resolve(!0)), qe = ({ archive: e }) => async (t) => {
471
- if (t.renditionLayout === "reflowable" && t.spineItems.every((s) => s.renditionLayout === "reflowable")) {
472
- const s = await re({ archive: e });
473
- if (await _e(s))
448
+ if (t.renditionLayout === "reflowable" && t.spineItems.every((r) => r.renditionLayout === "reflowable")) {
449
+ const r = await re({ archive: e });
450
+ if (await _e(r))
474
451
  return {
475
452
  ...t,
476
- spineItems: t.spineItems.map((r) => ({
477
- ...r,
453
+ spineItems: t.spineItems.map((s) => ({
454
+ ...s,
478
455
  renditionLayout: "pre-paginated"
479
456
  })),
480
457
  renditionLayout: "pre-paginated"
@@ -483,28 +460,28 @@ const w = {
483
460
  return t;
484
461
  }, z = (e, t) => {
485
462
  var n;
486
- const i = e.split(/(\d+)/), s = t.split(/(\d+)/);
487
- for (let r = 0, o = i.length; r < o; r++)
488
- if (i[r] !== s[r])
489
- return (n = i[r]) != null && n.match(/\d/) ? +(i[r] || "") - +(s[r] || "") : (i[r] || "").localeCompare(s[r] || "");
463
+ const i = e.split(/(\d+)/), r = t.split(/(\d+)/);
464
+ for (let s = 0, o = i.length; s < o; s++)
465
+ if (i[s] !== r[s])
466
+ return (n = i[s]) != null && n.match(/\d/) ? +(i[s] || "") - +(r[s] || "") : (i[s] || "").localeCompare(r[s] || "");
490
467
  return 1;
491
468
  }, Ge = ({ archive: e, baseUrl: t }) => async (i) => {
492
469
  if (i.nav) return i;
493
- const s = [...e.files].sort(
494
- (a, c) => z(a.uri, c.uri)
495
- ), n = Object.values(s), r = (a, c, l, d, p) => {
496
- const u = a.find((h) => h.title === c), [g, ...b] = l;
470
+ const r = [...e.files].sort(
471
+ (a, d) => z(a.uri, d.uri)
472
+ ), n = Object.values(r), s = (a, d, l, c, p) => {
473
+ const u = a.find((h) => h.title === d), [g, ...b] = l;
497
474
  return u ? g ? [
498
475
  ...a.filter((x) => x !== u),
499
476
  {
500
477
  ...u,
501
478
  contents: [
502
479
  ...u.contents,
503
- ...r(
480
+ ...s(
504
481
  u.contents,
505
482
  g,
506
483
  b,
507
- d,
484
+ c,
508
485
  p
509
486
  )
510
487
  ]
@@ -514,38 +491,38 @@ const w = {
514
491
  {
515
492
  ...u,
516
493
  path: p,
517
- href: d
494
+ href: c
518
495
  }
519
496
  ] : a : g ? [
520
497
  ...a,
521
498
  {
522
- contents: r(
499
+ contents: s(
523
500
  [],
524
501
  g,
525
502
  b,
526
- d,
503
+ c,
527
504
  p
528
505
  ),
529
- href: d,
506
+ href: c,
530
507
  path: p,
531
- title: c
508
+ title: d
532
509
  }
533
510
  ] : [
534
511
  ...a,
535
512
  {
536
513
  contents: [],
537
- href: d,
514
+ href: c,
538
515
  path: p,
539
- title: c
516
+ title: d
540
517
  }
541
518
  ];
542
519
  }, o = n.reduce(
543
- (a, c) => {
544
- if (c.dir) return a;
545
- const d = c.uri.split("/").slice(0, -1), [p, ...u] = d;
520
+ (a, d) => {
521
+ if (d.dir) return a;
522
+ const c = d.uri.split("/").slice(0, -1), [p, ...u] = c;
546
523
  if (p) {
547
- const g = k(t, encodeURI(c.uri)).replace(/\/$/, ""), b = c.uri.replace(/\/$/, "");
548
- return r(a, p, u, g, b);
524
+ const g = W(t, encodeURI(d.uri)).replace(/\/$/, ""), b = d.uri.replace(/\/$/, "");
525
+ return s(a, p, u, g, b);
549
526
  }
550
527
  return a;
551
528
  },
@@ -558,76 +535,76 @@ const w = {
558
535
  }
559
536
  };
560
537
  }, Ke = ({ archive: e }) => async (t) => {
561
- var r;
538
+ var s;
562
539
  const i = e.files.find(
563
540
  (o) => o.basename.toLowerCase() === "comicinfo.xml"
564
541
  );
565
542
  if (!i)
566
543
  return t;
567
- const s = {
544
+ const r = {
568
545
  ...t,
569
- spineItems: t.spineItems.filter((o) => !o.id.toLowerCase().endsWith("comicinfo.xml")).map((o, a, c) => ({
546
+ spineItems: t.spineItems.filter((o) => !o.id.toLowerCase().endsWith("comicinfo.xml")).map((o, a, d) => ({
570
547
  ...o,
571
- progressionWeight: 1 / c.length
548
+ progressionWeight: 1 / d.length
572
549
  }))
573
550
  }, n = await i.string();
574
551
  try {
575
- const a = ((r = new $.XmlDocument(n).childNamed("Manga")) == null ? void 0 : r.val) || "unknown";
552
+ const a = ((s = new $.XmlDocument(n).childNamed("Manga")) == null ? void 0 : s.val) || "unknown";
576
553
  return {
577
- ...s,
554
+ ...r,
578
555
  readingDirection: a === "YesAndRightToLeft" ? "rtl" : "ltr"
579
556
  };
580
557
  } catch (o) {
581
558
  return console.error(`Unable to parse comicinfo.xml for content
582
- `, n), console.error(o), s;
559
+ `, n), console.error(o), r;
583
560
  }
584
561
  }, Je = (e) => e.files.some((t) => t.basename.endsWith(".opf")), Ye = ({ archive: e }) => async (t) => Je(e) ? t : {
585
562
  ...t,
586
- spineItems: t.spineItems.map((s) => {
563
+ spineItems: t.spineItems.map((r) => {
587
564
  const n = e.files.find(
588
- (o) => decodeURI(s.href).endsWith(o.uri)
589
- ), r = ue((n == null ? void 0 : n.encodingFormat) ?? "") ?? O((n == null ? void 0 : n.basename) ?? "");
565
+ (o) => decodeURI(r.href).endsWith(o.uri)
566
+ ), s = ue((n == null ? void 0 : n.encodingFormat) ?? "") ?? O((n == null ? void 0 : n.basename) ?? "");
590
567
  return {
591
- ...s,
592
- renditionLayout: r != null && r.startsWith("image/") ? "pre-paginated" : s.renditionLayout
568
+ ...r,
569
+ renditionLayout: s != null && s.startsWith("image/") ? "pre-paginated" : r.renditionLayout
593
570
  };
594
571
  })
595
572
  }, Qe = ({ archive: e }) => async (t) => {
596
- var n, r;
573
+ var n, s;
597
574
  const i = e.files.find(
598
575
  (o) => o.basename.toLowerCase() === "com.apple.ibooks.display-options.xml"
599
576
  );
600
577
  if (!i)
601
578
  return t;
602
- const s = await (await i.blob()).text();
579
+ const r = await (await i.blob()).text();
603
580
  try {
604
- const a = new $.XmlDocument(s).childNamed("platform"), c = ((r = (n = a == null ? void 0 : a.childrenNamed("option")) == null ? void 0 : n.find((l) => l.attr.name === "fixed-layout")) == null ? void 0 : r.val) || "false";
581
+ const a = new $.XmlDocument(r).childNamed("platform"), d = ((s = (n = a == null ? void 0 : a.childrenNamed("option")) == null ? void 0 : n.find((l) => l.attr.name === "fixed-layout")) == null ? void 0 : s.val) || "false";
605
582
  return {
606
583
  ...t,
607
- renditionLayout: c === "true" ? "pre-paginated" : t.renditionLayout
584
+ renditionLayout: d === "true" ? "pre-paginated" : t.renditionLayout
608
585
  };
609
586
  } catch (o) {
610
587
  return console.error(
611
588
  `Unable to parse com.apple.ibooks.display-options.xml for content
612
589
  `,
613
- s
590
+ r
614
591
  ), console.error(o), t;
615
592
  }
616
593
  }, Ze = async (e, { baseUrl: t = "" } = {}) => {
617
594
  const i = [
618
- De({ archive: e, baseUrl: t }),
595
+ je({ archive: e, baseUrl: t }),
619
596
  Ke({ archive: e }),
620
597
  Qe({ archive: e }),
621
598
  Ye({ archive: e }),
622
599
  qe({ archive: e }),
623
- Ve({ archive: e }),
600
+ He({ archive: e }),
624
601
  Ge({ archive: e, baseUrl: t })
625
602
  ];
626
603
  try {
627
- const s = Be({ archive: e, baseUrl: t })(), n = await i.reduce(async (r, o) => await o(await r), s);
628
- return w.log("Generated manifest", n), n;
629
- } catch (s) {
630
- throw w.error(s), s;
604
+ const r = Be({ archive: e, baseUrl: t })(), n = await i.reduce(async (s, o) => await o(await s), r);
605
+ return v.log("Generated manifest", n), n;
606
+ } catch (r) {
607
+ throw v.error(r), r;
631
608
  }
632
609
  }, at = async (e, t) => {
633
610
  const i = `
@@ -638,22 +615,22 @@ const w = {
638
615
  </metadata>
639
616
  <manifest>
640
617
  ${e.map(
641
- (r) => `<item id="${A(r)}" href="${r}" media-type="${O(r)}"/>`
618
+ (s) => `<item id="${A(s)}" href="${s}" media-type="${O(s)}"/>`
642
619
  ).join(`
643
620
  `)}
644
621
  </manifest>
645
622
  <spine>
646
- ${e.map((r) => `<itemref idref="${A(r)}" />`).join(`
623
+ ${e.map((s) => `<itemref idref="${A(s)}" />`).join(`
647
624
  `)}
648
625
  </spine>
649
626
  </package>
650
- `, s = e.map((r) => ({
627
+ `, r = e.map((s) => ({
651
628
  dir: !1,
652
- basename: A(r),
653
- encodingFormat: O(r),
654
- uri: r,
629
+ basename: A(s),
630
+ encodingFormat: O(s),
631
+ uri: s,
655
632
  size: 100 / e.length,
656
- blob: async () => (await fetch(r)).blob(),
633
+ blob: async () => (await fetch(s)).blob(),
657
634
  string: async () => ""
658
635
  }));
659
636
  return {
@@ -665,14 +642,14 @@ const w = {
665
642
  size: 0,
666
643
  blob: async () => new Blob(),
667
644
  string: async () => i
668
- }, ...s],
645
+ }, ...r],
669
646
  close: () => Promise.resolve()
670
647
  };
671
648
  }, ct = async (e, {
672
649
  mimeType: t,
673
650
  direction: i
674
651
  } = { mimeType: "text/plain" }) => {
675
- const s = `
652
+ const r = `
676
653
  <?xml version="1.0" encoding="UTF-8"?>
677
654
  <package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="ja" prefix="rendition: http://www.idpf.org/vocab/rendition/#"
678
655
  unique-identifier="ootuya-id">
@@ -695,8 +672,8 @@ const w = {
695
672
  dir: !1,
696
673
  basename: A("generated.opf"),
697
674
  uri: "generated.opf",
698
- blob: async () => new Blob([s]),
699
- string: async () => s,
675
+ blob: async () => new Blob([r]),
676
+ string: async () => r,
700
677
  size: 0
701
678
  },
702
679
  {
@@ -712,28 +689,28 @@ const w = {
712
689
  close: () => Promise.resolve()
713
690
  };
714
691
  }, dt = async (e, { orderByAlpha: t, name: i } = {}) => {
715
- let s = Object.values(e.files);
716
- t && (s = s.slice().sort((r, o) => z(r.name, o.name)));
692
+ let r = Object.values(e.files);
693
+ t && (r = r.slice().sort((s, o) => z(s.name, o.name)));
717
694
  const n = {
718
695
  filename: i || "",
719
- files: s.map((r) => ({
720
- dir: r.dir,
721
- basename: A(r.name),
722
- uri: r.name,
723
- blob: () => r.async("blob"),
724
- string: () => r.async("string"),
725
- ...r.internalStream && {
726
- stream: r.internalStream
696
+ files: r.map((s) => ({
697
+ dir: s.dir,
698
+ basename: A(s.name),
699
+ uri: s.name,
700
+ blob: () => s.async("blob"),
701
+ string: () => s.async("string"),
702
+ ...s.internalStream && {
703
+ stream: s.internalStream
727
704
  },
728
705
  // this is private API
729
706
  // @ts-ignore
730
- size: r._data.uncompressedSize
707
+ size: s._data.uncompressedSize
731
708
  })),
732
709
  close: () => Promise.resolve()
733
710
  };
734
- return w.log("Generated archive", n), n;
711
+ return v.log("Generated archive", n), n;
735
712
  }, lt = async (e, { name: t } = {}) => {
736
- const i = await e.getFilesArray(), s = {
713
+ const i = await e.getFilesArray(), r = {
737
714
  close: () => e.close(),
738
715
  filename: t ?? "",
739
716
  files: i.map((n) => ({
@@ -745,21 +722,21 @@ const w = {
745
722
  string: async () => (await n.file.extract()).text()
746
723
  }))
747
724
  };
748
- return w.log("Generated archive", s), s;
725
+ return v.log("Generated archive", r), r;
749
726
  }, pt = async (e, { orderByAlpha: t, name: i } = {}) => {
750
- let s = e;
751
- return t && (s = s.slice().sort((n, r) => z(n.name, r.name))), {
727
+ let r = e;
728
+ return t && (r = r.slice().sort((n, s) => z(n.name, s.name))), {
752
729
  filename: i || "",
753
- files: s.map((n) => ({
730
+ files: r.map((n) => ({
754
731
  dir: n.isDir,
755
732
  basename: A(n.name),
756
733
  uri: n.name,
757
734
  blob: async () => new Blob([await n.data()]),
758
735
  string: async () => {
759
- const r = await n.data();
736
+ const s = await n.data();
760
737
  return String.fromCharCode.apply(
761
738
  null,
762
- Array.from(new Uint16Array(r))
739
+ Array.from(new Uint16Array(s))
763
740
  );
764
741
  },
765
742
  size: n.size
@@ -769,7 +746,7 @@ const w = {
769
746
  }, ft = ({
770
747
  enableReport: e
771
748
  } = {}) => {
772
- w.enable(!!e);
749
+ v.enable(!!e);
773
750
  };
774
751
  class et {
775
752
  constructor(t) {
@@ -796,7 +773,7 @@ class et {
796
773
  }
797
774
  get overTTL$() {
798
775
  return this.isUnlocked$.pipe(
799
- W(
776
+ L(
800
777
  (t) => t ? this.cleanArchiveAfter === 1 / 0 ? G : xe(this.cleanArchiveAfter) : G
801
778
  )
802
779
  );
@@ -807,66 +784,67 @@ const tt = ({
807
784
  cleanArchiveAfter: t = 5 * 60 * 1e3
808
785
  // 5mn
809
786
  }) => {
810
- const i = new R(), s = new R(), n = new R(), r = {}, o = i.pipe(
787
+ const i = new R(), r = new R(), n = new R(), s = {}, o = i.pipe(
811
788
  M((l) => {
812
- const d = r[l];
813
- if (!d || d.state.status !== "idle") return _;
789
+ const c = s[l];
790
+ if (!c || c.state.status !== "idle") return _;
814
791
  let p = !1;
815
792
  const u = (y) => {
816
- var S;
817
- const v = r[y];
818
- delete r[y], p || ((S = v == null ? void 0 : v.state.archive) == null || S.close(), p = !0);
793
+ var k;
794
+ v.debug(`Cleaning up archive with key: ${y}`);
795
+ const w = s[y];
796
+ delete s[y], p || ((k = w == null ? void 0 : w.state.archive) == null || k.close(), p = !0);
819
797
  };
820
- d.update({
798
+ c.update({
821
799
  status: "loading"
822
800
  });
823
- const g = d.locks$, b = d.isUnlocked$, h = g.pipe(
801
+ const g = c.locks$, b = c.isUnlocked$, h = g.pipe(
824
802
  me(),
825
- j(([y, v]) => v > y),
803
+ D(([y, w]) => w > y),
826
804
  he(!0)
827
805
  );
828
806
  return P(e(l)).pipe(
829
- D((y) => {
830
- d.update({
807
+ j((y) => {
808
+ c.update({
831
809
  archive: y,
832
810
  status: "success"
833
811
  });
834
812
  }),
835
- I((y) => (u(l), d.update({
813
+ C((y) => (u(l), c.update({
836
814
  status: "error",
837
815
  error: y
838
816
  }), _)),
839
- W(() => {
817
+ L(() => {
840
818
  const y = h.pipe(
841
- W(() => n),
842
- W(() => b),
843
- j((v) => v)
819
+ L(() => n),
820
+ L(() => b),
821
+ D((w) => w)
844
822
  );
845
- return q(y, d.overTTL$);
823
+ return q(y, c.overTTL$);
846
824
  }),
847
- D(() => {
825
+ j(() => {
848
826
  u(l);
849
827
  })
850
828
  );
851
829
  }),
852
- ge(s)
830
+ ge(r)
853
831
  ), a = (l) => {
854
- let d = !1;
855
- const p = r[l] ?? new et(t);
856
- r[l] = p, p.update({
832
+ let c = !1;
833
+ const p = s[l] ?? new et(t);
834
+ s[l] = p, p.update({
857
835
  locks: p.state.locks + 1
858
836
  });
859
837
  const u = () => {
860
- d || (d = !0, p.update({
838
+ c || (c = !0, p.update({
861
839
  locks: p.state.locks - 1
862
840
  }));
863
841
  };
864
842
  i.next(l);
865
843
  const g = p.state$.pipe(
866
844
  F(({ archive: h }) => h),
867
- j((h) => !!h)
845
+ D((h) => !!h)
868
846
  ), b = p.state$.pipe(
869
- D(({ error: h }) => {
847
+ j(({ error: h }) => {
870
848
  if (h)
871
849
  throw h;
872
850
  }),
@@ -875,26 +853,26 @@ const tt = ({
875
853
  return q(g, b).pipe(
876
854
  be(),
877
855
  F((h) => ({ archive: h, release: u })),
878
- I((h) => {
856
+ C((h) => {
879
857
  throw u(), h;
880
858
  })
881
859
  );
882
- }, c = () => {
860
+ }, d = () => {
883
861
  n.next();
884
862
  };
885
863
  return o.subscribe(), {
886
864
  access: a,
887
- purge: c,
888
- archives: r
865
+ purge: d,
866
+ archives: s
889
867
  };
890
868
  };
891
869
  class nt {
892
870
  constructor({
893
871
  onError: t,
894
872
  onManifestSuccess: i,
895
- ...s
873
+ ...r
896
874
  }) {
897
- this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = tt(s), this.onManifestSuccess = i ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
875
+ this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = tt(r), this.onManifestSuccess = i ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
898
876
  }
899
877
  prune() {
900
878
  this.epubLoader.purge();
@@ -904,15 +882,15 @@ class nt {
904
882
  }
905
883
  accessArchiveWithoutLock(t) {
906
884
  return this.accessArchive(t).pipe(
907
- F(({ archive: i, release: s }) => (s(), i))
885
+ F(({ archive: i, release: r }) => (r(), i))
908
886
  );
909
887
  }
910
888
  fetchManifest({ key: t, baseUrl: i }) {
911
- const s = this.accessArchive(t).pipe(
912
- M(({ archive: n, release: r }) => P(
889
+ const r = this.accessArchive(t).pipe(
890
+ M(({ archive: n, release: s }) => P(
913
891
  Ze(n, { baseUrl: i })
914
892
  ).pipe(
915
- W(
893
+ L(
916
894
  (a) => P(this.onManifestSuccess({ manifest: a, archive: n }))
917
895
  ),
918
896
  F(
@@ -921,41 +899,41 @@ class nt {
921
899
  })
922
900
  ),
923
901
  K(() => {
924
- r();
902
+ s();
925
903
  })
926
904
  )),
927
- I((n) => J(this.onError(n)))
905
+ C((n) => J(this.onError(n)))
928
906
  );
929
- return Y(s);
907
+ return Y(r);
930
908
  }
931
909
  fetchResource({
932
910
  key: t,
933
911
  resourcePath: i
934
912
  }) {
935
- const s = this.accessArchive(t).pipe(
936
- M(({ archive: n, release: r }) => {
913
+ const r = this.accessArchive(t).pipe(
914
+ M(({ archive: n, release: s }) => {
937
915
  const o = i.replaceAll("file://", "");
938
916
  return P(
939
917
  Ue(n, o)
940
918
  ).pipe(
941
919
  F(
942
- (c) => new Response(c.body, {
920
+ (d) => new Response(d.body, {
943
921
  status: 200,
944
922
  headers: {
945
- ...c.params.contentType && {
946
- "Content-Type": c.params.contentType
923
+ ...d.params.contentType && {
924
+ "Content-Type": d.params.contentType
947
925
  }
948
926
  }
949
927
  })
950
928
  ),
951
929
  K(() => {
952
- r();
930
+ s();
953
931
  })
954
932
  );
955
933
  }),
956
- I((n) => J(this.onError(n)))
934
+ C((n) => J(this.onError(n)))
957
935
  );
958
- return Y(s);
936
+ return Y(r);
959
937
  }
960
938
  }
961
939
  class ut extends nt {
@@ -969,14 +947,14 @@ class ut extends nt {
969
947
  try {
970
948
  const i = this.getUriInfo(t);
971
949
  if (!i) return;
972
- const s = Q(i.baseUrl), n = t.request.url.substring(
973
- s.length + 1
974
- ), [r = ""] = n.split("/"), o = decodeURIComponent(
975
- Q(n.substring(r.length + 1))
950
+ const r = Q(i.baseUrl), n = t.request.url.substring(
951
+ r.length + 1
952
+ ), [s = ""] = n.split("/"), o = decodeURIComponent(
953
+ Q(n.substring(s.length + 1))
976
954
  );
977
955
  n.endsWith("/manifest") ? t.respondWith(
978
- this.fetchManifest({ key: r, baseUrl: `${s}/${r}/` })
979
- ) : t.respondWith(this.fetchResource({ key: r, resourcePath: o }));
956
+ this.fetchManifest({ key: s, baseUrl: `${r}/${s}/` })
957
+ ) : t.respondWith(this.fetchResource({ key: s, resourcePath: o }));
980
958
  } catch (i) {
981
959
  t.respondWith(new Response(String(i), { status: 500 }));
982
960
  }