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