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