@prose-reader/streamer 1.207.0 → 1.209.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
- 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;
1
+ import v, { XmlDocument as le, XmlTextNode as pe, XmlElement as fe } from "xmldoc";
2
+ import { urlJoin as N, isXmlBasedMimeType as ue, parseContentType as me, detectMimeTypeFromName as O } from "@prose-reader/shared";
3
+ import { Subject as R, mergeMap as M, EMPTY as _, pairwise as he, filter as D, startWith as ge, from as C, tap as j, catchError as P, switchMap as W, merge as q, first as G, takeUntil as ye, map as F, ignoreElements as be, BehaviorSubject as we, distinctUntilChanged as ve, shareReplay as $e, NEVER as K, timer as xe, finalize as J, of as Y, lastValueFrom as Q } from "rxjs";
4
+ let S = !1;
5
5
  const w = {
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 le(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
+ }, te = (e) => e ? e.children.map((t) => t instanceof pe ? t.text : t instanceof fe ? te(t) : "").join("").trim() : "", A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Z = (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
- }, te = (e, { basePath: t, baseUrl: i }) => {
91
- const s = {
67
+ }, ne = (e, { basePath: t, baseUrl: i }) => {
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()) || te(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 = N(t, n.attr.href), r.href = N(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) => ne(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(ne(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 v.XmlDocument(await s.string()), a = Ne(s.uri);
102
+ return ke(o, { basePath: a, baseUrl: i });
126
103
  }
127
104
  }
128
- }, ne = (e, {
105
+ }, re = (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: N(t, n),
114
+ href: N(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;
143
- }, Pe = (e, { opfBasePath: t, baseUrl: i }) => {
116
+ }, o = e.childrenNamed(`${r}navPoint`);
117
+ return o && o.length > 0 && (s.contents = o.map(
118
+ (l) => re(l, { opfBasePath: t, baseUrl: i, prefix: r })
119
+ )), s;
120
+ }, Ce = (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(re(a, { opfBasePath: t, baseUrl: i, prefix: s }))
126
+ ), r;
127
+ }, Pe = 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 v.XmlDocument(await l.string());
143
+ return Ce(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 } = k(t) || {}, n = await Pe({
172
149
  opfData: e,
173
- opfBasePath: s,
150
+ opfBasePath: r,
174
151
  archive: t,
175
152
  baseUrl: i
176
153
  });
@@ -178,52 +155,52 @@ 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,
186
163
  pageSpreadLeft: t.some((n) => n === "page-spread-left") || void 0,
187
164
  pageSpreadRight: t.some((n) => n === "page-spread-right") || void 0
188
165
  };
189
- }, N = (e) => {
190
- const i = Object.values(e.files).filter((s) => !s.dir).find((s) => s.uri.endsWith(".opf"));
166
+ }, k = (e) => {
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("/"))) || ""
194
171
  };
195
- }, re = async ({
172
+ }, se = 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 } = k(e) || {}, r = await (t == null ? void 0 : t.string());
176
+ if (!r) return [];
177
+ const n = new v.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
- }, 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) => {
186
+ }, ie = (e, t, i) => {
187
+ var s;
188
+ const r = e.childNamed("manifest"), { basePath: n } = k(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 } = k(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
+ w.log("data", s);
197
+ const o = new v.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
- ), x = g.find(
201
+ ), $ = 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(
203
+ ), y = b == null ? void 0 : b.val, x = h == null ? void 0 : h.val, T = $ == null ? void 0 : $.val, oe = (u == null ? void 0 : u.val) || ((X = e.files.find(({ dir: m }) => m)) == null ? void 0 : X.basename) || "", ae = c == null ? void 0 : c.attr["page-progression-direction"], ce = (await se({ archive: e })).reduce(
227
204
  (m, L) => L.size + m,
228
205
  0
229
206
  );
@@ -233,28 +210,28 @@ const w = {
233
210
  toc: a
234
211
  },
235
212
  renditionLayout: y,
236
- renditionFlow: v || "auto",
237
- renditionSpread: S,
238
- title: ie,
239
- readingDirection: oe || "ltr",
213
+ renditionFlow: x || "auto",
214
+ renditionSpread: T,
215
+ title: oe,
216
+ readingDirection: ae || "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, L) => {
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) || "", de = ((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
226
  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,
252
- progressionWeight: ce / ae,
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,
229
+ progressionWeight: de / ce,
253
230
  // size: itemSize
254
231
  mediaType: f == null ? void 0 : f.attr["media-type"]
255
232
  };
256
233
  })) || [],
257
- items: se(o, e, (m) => {
234
+ items: ie(o, e, (m) => {
258
235
  const L = m.attr.href || "";
259
236
  return /^https?:\/\//.test(L) ? "" : t || "file://";
260
237
  }),
@@ -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 = k(e).data) == null ? void 0 : n.string());
247
+ if (r) {
248
+ const a = new v.XmlDocument(r), d = ie(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,24 +268,24 @@ 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
308
285
  }
309
286
  }
310
287
  };
311
- }, Z = [
288
+ }, ee = [
312
289
  "div",
313
290
  "span",
314
291
  "p",
@@ -360,22 +337,22 @@ 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
- `<(${Z.join("|")})[\\s/>]`,
346
+ `<(${ee.join("|")})[\\s/>]`,
370
347
  "i"
371
348
  ).test(n))
372
349
  return i;
373
350
  const o = new RegExp(
374
- `<(${Z.join("|")})(\\s[^>]*)?\\s*/>`,
351
+ `<(${ee.join("|")})(\\s[^>]*)?\\s*/>`,
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 w.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 w.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,50 +408,50 @@ 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 v.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
- if (!await t || !fe({
440
+ if (!await t || !ue({
464
441
  mimeType: i.encodingFormat,
465
442
  uri: i.uri
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 v.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 se({ 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,69 +460,69 @@ 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
- ...a.filter((x) => x !== u),
475
+ ...a.filter(($) => $ !== 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
  ]
511
488
  }
512
489
  ] : u.path.split("/").length > p.split("/").length ? [
513
- ...a.filter((x) => x !== u),
490
+ ...a.filter(($) => $ !== u),
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 = N(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 v.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 = me((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 v.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);
604
+ const r = Be({ archive: e, baseUrl: t })(), n = await i.reduce(async (s, o) => await o(await s), r);
628
605
  return w.log("Generated manifest", n), n;
629
- } catch (s) {
630
- throw w.error(s), s;
606
+ } catch (r) {
607
+ throw w.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
711
  return w.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 w.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
@@ -797,7 +774,7 @@ class et {
797
774
  get overTTL$() {
798
775
  return this.isUnlocked$.pipe(
799
776
  W(
800
- (t) => t ? this.cleanArchiveAfter === 1 / 0 ? G : xe(this.cleanArchiveAfter) : G
777
+ (t) => t ? this.cleanArchiveAfter === 1 / 0 ? K : xe(this.cleanArchiveAfter) : K
801
778
  )
802
779
  );
803
780
  }
@@ -807,32 +784,33 @@ 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 T;
794
+ w.debug(`Cleaning up archive with key: ${y}`);
795
+ const x = s[y];
796
+ delete s[y], p || ((T = x == null ? void 0 : x.state.archive) == null || T.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(
824
- me(),
825
- j(([y, v]) => v > y),
826
- he(!0)
801
+ const g = c.locks$, b = c.isUnlocked$, h = g.pipe(
802
+ he(),
803
+ D(([y, x]) => x > y),
804
+ ge(!0)
827
805
  );
828
- return P(e(l)).pipe(
829
- D((y) => {
830
- d.update({
806
+ return C(e(l)).pipe(
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
+ P((y) => (u(l), c.update({
836
814
  status: "error",
837
815
  error: y
838
816
  }), _)),
@@ -840,61 +818,63 @@ const tt = ({
840
818
  const y = h.pipe(
841
819
  W(() => n),
842
820
  W(() => b),
843
- j((v) => v)
821
+ D((T) => T)
822
+ );
823
+ return q(y, c.overTTL$).pipe(
824
+ G(),
825
+ j(() => {
826
+ u(l);
827
+ })
844
828
  );
845
- return q(y, d.overTTL$);
846
- }),
847
- D(() => {
848
- u(l);
849
829
  })
850
830
  );
851
831
  }),
852
- ge(s)
832
+ ye(r)
853
833
  ), a = (l) => {
854
- let d = !1;
855
- const p = r[l] ?? new et(t);
856
- r[l] = p, p.update({
834
+ let c = !1;
835
+ const p = s[l] ?? new et(t);
836
+ s[l] = p, p.update({
857
837
  locks: p.state.locks + 1
858
838
  });
859
839
  const u = () => {
860
- d || (d = !0, p.update({
840
+ c || (c = !0, p.update({
861
841
  locks: p.state.locks - 1
862
842
  }));
863
843
  };
864
844
  i.next(l);
865
845
  const g = p.state$.pipe(
866
846
  F(({ archive: h }) => h),
867
- j((h) => !!h)
847
+ D((h) => !!h)
868
848
  ), b = p.state$.pipe(
869
- D(({ error: h }) => {
849
+ j(({ error: h }) => {
870
850
  if (h)
871
851
  throw h;
872
852
  }),
873
- ye()
853
+ be()
874
854
  );
875
855
  return q(g, b).pipe(
876
- be(),
856
+ G(),
877
857
  F((h) => ({ archive: h, release: u })),
878
- I((h) => {
858
+ P((h) => {
879
859
  throw u(), h;
880
860
  })
881
861
  );
882
- }, c = () => {
862
+ }, d = () => {
883
863
  n.next();
884
864
  };
885
865
  return o.subscribe(), {
886
866
  access: a,
887
- purge: c,
888
- archives: r
867
+ purge: d,
868
+ _archives: s
889
869
  };
890
870
  };
891
871
  class nt {
892
872
  constructor({
893
873
  onError: t,
894
874
  onManifestSuccess: i,
895
- ...s
875
+ ...r
896
876
  }) {
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;
877
+ 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
878
  }
899
879
  prune() {
900
880
  this.epubLoader.purge();
@@ -904,58 +884,58 @@ class nt {
904
884
  }
905
885
  accessArchiveWithoutLock(t) {
906
886
  return this.accessArchive(t).pipe(
907
- F(({ archive: i, release: s }) => (s(), i))
887
+ F(({ archive: i, release: r }) => (r(), i))
908
888
  );
909
889
  }
910
890
  fetchManifest({ key: t, baseUrl: i }) {
911
- const s = this.accessArchive(t).pipe(
912
- M(({ archive: n, release: r }) => P(
891
+ const r = this.accessArchive(t).pipe(
892
+ M(({ archive: n, release: s }) => C(
913
893
  Ze(n, { baseUrl: i })
914
894
  ).pipe(
915
895
  W(
916
- (a) => P(this.onManifestSuccess({ manifest: a, archive: n }))
896
+ (a) => C(this.onManifestSuccess({ manifest: a, archive: n }))
917
897
  ),
918
898
  F(
919
899
  (a) => new Response(JSON.stringify(a), {
920
900
  status: 200
921
901
  })
922
902
  ),
923
- K(() => {
924
- r();
903
+ J(() => {
904
+ s();
925
905
  })
926
906
  )),
927
- I((n) => J(this.onError(n)))
907
+ P((n) => Y(this.onError(n)))
928
908
  );
929
- return Y(s);
909
+ return Q(r);
930
910
  }
931
911
  fetchResource({
932
912
  key: t,
933
913
  resourcePath: i
934
914
  }) {
935
- const s = this.accessArchive(t).pipe(
936
- M(({ archive: n, release: r }) => {
915
+ const r = this.accessArchive(t).pipe(
916
+ M(({ archive: n, release: s }) => {
937
917
  const o = i.replaceAll("file://", "");
938
- return P(
918
+ return C(
939
919
  Ue(n, o)
940
920
  ).pipe(
941
921
  F(
942
- (c) => new Response(c.body, {
922
+ (d) => new Response(d.body, {
943
923
  status: 200,
944
924
  headers: {
945
- ...c.params.contentType && {
946
- "Content-Type": c.params.contentType
925
+ ...d.params.contentType && {
926
+ "Content-Type": d.params.contentType
947
927
  }
948
928
  }
949
929
  })
950
930
  ),
951
- K(() => {
952
- r();
931
+ J(() => {
932
+ s();
953
933
  })
954
934
  );
955
935
  }),
956
- I((n) => J(this.onError(n)))
936
+ P((n) => Y(this.onError(n)))
957
937
  );
958
- return Y(s);
938
+ return Q(r);
959
939
  }
960
940
  }
961
941
  class ut extends nt {
@@ -969,14 +949,14 @@ class ut extends nt {
969
949
  try {
970
950
  const i = this.getUriInfo(t);
971
951
  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))
952
+ const r = Z(i.baseUrl), n = t.request.url.substring(
953
+ r.length + 1
954
+ ), [s = ""] = n.split("/"), o = decodeURIComponent(
955
+ Z(n.substring(s.length + 1))
976
956
  );
977
957
  n.endsWith("/manifest") ? t.respondWith(
978
- this.fetchManifest({ key: r, baseUrl: `${s}/${r}/` })
979
- ) : t.respondWith(this.fetchResource({ key: r, resourcePath: o }));
958
+ this.fetchManifest({ key: s, baseUrl: `${r}/${s}/` })
959
+ ) : t.respondWith(this.fetchResource({ key: s, resourcePath: o }));
980
960
  } catch (i) {
981
961
  t.respondWith(new Response(String(i), { status: 500 }));
982
962
  }
@@ -993,6 +973,6 @@ export {
993
973
  at as createArchiveFromUrls,
994
974
  Ze as generateManifestFromArchive,
995
975
  Ue as generateResourceFromArchive,
996
- N as getArchiveOpfInfo
976
+ k as getArchiveOpfInfo
997
977
  };
998
978
  //# sourceMappingURL=index.js.map