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