@prose-reader/streamer 1.296.0 → 1.297.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,34 +1,34 @@
1
- import { detectMimeTypeFromName as g, Report as ue, parseContentType as k, isXmlBasedMimeType as fe, isMediaContentMimeType as he, urlJoin as F, escapeXmlAttributeValue as me } from "@prose-reader/shared";
2
- import { parseOpf as ge, APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME as Z, parseAppleDisplayOptionsXml as ye, resolveArchiveMetadata as I, COMIC_INFO_FILENAME as ee, parseComicInfo as ve, KOBO_DISPLAY_OPTIONS_FILENAME as N, parseKoboXml as be, tokenizeXmlSpaceSeparatedList as we } from "@prose-reader/archive-parser";
3
- import { XmlDocument as P, XmlTextNode as $e, XmlElement as Se } from "xmldoc";
4
- import { Subject as L, mergeMap as te, EMPTY as _, pairwise as Re, filter as T, startWith as xe, from as R, tap as E, catchError as W, switchMap as x, merge as U, first as B, takeUntil as Fe, map as S, ignoreElements as Ie, BehaviorSubject as Pe, distinctUntilChanged as Ae, shareReplay as Le, NEVER as z, timer as Te, finalize as Ee, of as Ce, lastValueFrom as We } from "rxjs";
5
- const M = (e, t) => {
6
- const s = e.split(/(\d+)/), r = t.split(/(\d+)/);
7
- for (let n = 0, i = s.length; n < i; n++)
8
- if (s[n] !== r[n])
9
- return s[n]?.match(/\d/) ? +(s[n] || "") - +(r[n] || "") : (s[n] || "").localeCompare(r[n] || "");
1
+ import { detectMimeTypeFromName as v, Report as re, isXmlBasedMimeType as se, parseContentType as G, isMediaContentMimeType as oe, urlJoin as L } from "@prose-reader/shared";
2
+ import { parseOpf as ie, APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME as K, parseAppleDisplayOptionsXml as ae, resolveArchiveMetadata as I, COMIC_INFO_FILENAME as q, parseComicInfo as ce, KOBO_DISPLAY_OPTIONS_FILENAME as N, parseKoboXml as de, tokenizeXmlSpaceSeparatedList as le } from "@prose-reader/archive-parser";
3
+ import { XmlDocument as R, XmlTextNode as pe, XmlElement as ue } from "xmldoc";
4
+ import { Subject as S, mergeMap as J, EMPTY as O, pairwise as fe, filter as k, startWith as me, from as x, tap as C, catchError as W, switchMap as A, merge as z, first as M, takeUntil as he, map as F, ignoreElements as ge, BehaviorSubject as ye, distinctUntilChanged as be, shareReplay as ve, NEVER as B, timer as we, finalize as $e, of as Fe, lastValueFrom as xe } from "rxjs";
5
+ const E = (e, t) => {
6
+ const o = e.split(/(\d+)/), r = t.split(/(\d+)/);
7
+ for (let n = 0, s = o.length; n < s; n++)
8
+ if (o[n] !== r[n])
9
+ return o[n]?.match(/\d/) ? +(o[n] || "") - +(r[n] || "") : (o[n] || "").localeCompare(r[n] || "");
10
10
  return 1;
11
- }, v = (e) => e.substring(e.lastIndexOf("/") + 1) || e, j = (e) => e.endsWith("/") ? e.slice(0, -1) : e, ke = (e) => {
11
+ }, b = (e) => e.substring(e.lastIndexOf("/") + 1) || e, j = (e) => e.endsWith("/") ? e.slice(0, -1) : e, Ae = (e) => {
12
12
  const t = e.lastIndexOf("/");
13
13
  return t >= 0 ? e.substring(0, t) : "";
14
- }, rn = async (e, { orderByAlpha: t, name: s } = {}) => {
14
+ }, Lt = async (e, { orderByAlpha: t, name: o } = {}) => {
15
15
  let r = e;
16
- return t && (r = r.slice().sort((n, i) => M(n.name, i.name))), {
17
- filename: s || "",
16
+ return t && (r = r.slice().sort((n, s) => E(n.name, s.name))), {
17
+ filename: o || "",
18
18
  records: r.map((n) => {
19
- const i = n.size, o = v(n.name);
19
+ const s = n.size, i = b(n.name);
20
20
  return n.isDir ? {
21
21
  dir: !0,
22
- basename: o,
22
+ basename: i,
23
23
  uri: n.name,
24
- size: i
24
+ size: s
25
25
  } : {
26
26
  dir: n.isDir,
27
- basename: o,
28
- encodingFormat: g(n.name),
27
+ basename: i,
28
+ encodingFormat: v(n.name),
29
29
  uri: n.name,
30
30
  blob: async () => new Blob([await n.data()], {
31
- type: g(n.name) ?? ""
31
+ type: v(n.name) ?? ""
32
32
  }),
33
33
  string: async () => {
34
34
  const a = await n.data();
@@ -37,83 +37,83 @@ const M = (e, t) => {
37
37
  Array.from(new Uint16Array(a))
38
38
  );
39
39
  },
40
- size: i
40
+ size: s
41
41
  };
42
42
  }),
43
43
  close: () => Promise.resolve()
44
44
  };
45
- }, Me = "@prose-reader/streamer", u = ue.namespace(Me, !1, {
45
+ }, Le = "@prose-reader/streamer", f = re.namespace(Le, !1, {
46
46
  color: "#ffae42"
47
- }), Oe = (e) => {
47
+ }), Ie = (e) => {
48
48
  const t = {};
49
49
  for (const r of e) {
50
50
  const n = r.split("/");
51
- let i = t;
52
- for (let o = 0; o < n.length; o++) {
53
- const a = n[o];
54
- a !== void 0 && (i[a] || (i[a] = {}), i = i[a]);
51
+ let s = t;
52
+ for (let i = 0; i < n.length; i++) {
53
+ const a = n[i];
54
+ a !== void 0 && (s[a] || (s[a] = {}), s = s[a]);
55
55
  }
56
56
  }
57
- const s = (r, n = "") => Object.keys(r).sort().map((i, o, a) => {
58
- const c = o === a.length - 1, l = n + (c ? "└── " : "├── "), p = n + (c ? " " : "│ "), f = r[i];
59
- return f && Object.keys(f).length > 0 ? `${l}${i}/
60
- ${s(f, p)}` : `${l}${i}`;
57
+ const o = (r, n = "") => Object.keys(r).sort().map((s, i, a) => {
58
+ const c = i === a.length - 1, l = n + (c ? "└── " : "├── "), p = n + (c ? " " : "│ "), u = r[s];
59
+ return u && Object.keys(u).length > 0 ? `${l}${s}/
60
+ ${o(u, p)}` : `${l}${s}`;
61
61
  }).join(`
62
62
  `);
63
- return s(t);
64
- }, sn = async (e, { orderByAlpha: t, name: s } = {}) => {
63
+ return o(t);
64
+ }, It = async (e, { orderByAlpha: t, name: o } = {}) => {
65
65
  let r = Object.values(e.files);
66
- t && (r = r.slice().sort((i, o) => M(i.name, o.name)));
66
+ t && (r = r.slice().sort((s, i) => E(s.name, i.name)));
67
67
  const n = {
68
- filename: s || "",
69
- records: r.map((i) => {
70
- const o = i._data.uncompressedSize, a = v(i.name);
71
- return i.dir ? {
68
+ filename: o || "",
69
+ records: r.map((s) => {
70
+ const i = s._data.uncompressedSize, a = b(s.name);
71
+ return s.dir ? {
72
72
  dir: !0,
73
73
  basename: a,
74
- uri: i.name,
75
- size: o
74
+ uri: s.name,
75
+ size: i
76
76
  } : {
77
77
  dir: !1,
78
- basename: v(i.name),
79
- uri: i.name,
80
- encodingFormat: g(i.name),
81
- blob: () => i.async("blob"),
82
- string: () => i.async("string"),
83
- ...i.internalStream && {
84
- stream: i.internalStream
78
+ basename: b(s.name),
79
+ uri: s.name,
80
+ encodingFormat: v(s.name),
81
+ blob: () => s.async("blob"),
82
+ string: () => s.async("string"),
83
+ ...s.internalStream && {
84
+ stream: s.internalStream
85
85
  },
86
86
  // this is private API
87
87
  // @ts-expect-error
88
- size: i._data.uncompressedSize
88
+ size: s._data.uncompressedSize
89
89
  };
90
90
  }),
91
91
  close: () => Promise.resolve()
92
92
  };
93
- if (u.log("Generated archive", n), process.env.NODE_ENV === "development" && u.isEnabled()) {
94
- const i = Oe(r.map((o) => o.name));
95
- u.groupCollapsed(...u.getGroupArgs("Archive folder structure")), u.log(`
96
- ${i}`), u.groupEnd();
93
+ if (f.log("Generated archive", n), process.env.NODE_ENV === "development" && f.isEnabled()) {
94
+ const s = Ie(r.map((i) => i.name));
95
+ f.groupCollapsed(...f.getGroupArgs("Archive folder structure")), f.log(`
96
+ ${s}`), f.groupEnd();
97
97
  }
98
98
  return n;
99
- }, on = async (e, { name: t } = {}) => {
100
- const s = await e.getFilesArray(), r = {
99
+ }, Rt = async (e, { name: t } = {}) => {
100
+ const o = await e.getFilesArray(), r = {
101
101
  close: () => e.close(),
102
102
  filename: t ?? "",
103
- records: s.map((n) => ({
103
+ records: o.map((n) => ({
104
104
  dir: !1,
105
105
  basename: n.file.name,
106
- encodingFormat: g(n.file.name),
106
+ encodingFormat: v(n.file.name),
107
107
  size: n.file.size,
108
108
  uri: `${n.path}${n.file.name}`,
109
109
  blob: async () => await n.file.extract(),
110
110
  string: async () => (await n.file.extract()).text()
111
111
  }))
112
112
  };
113
- return u.log("Generated archive", r), r;
114
- }, an = async (e, {
113
+ return f.log("Generated archive", r), r;
114
+ }, Tt = async (e, {
115
115
  mimeType: t,
116
- direction: s
116
+ direction: o
117
117
  } = { mimeType: "text/plain" }) => {
118
118
  const r = `
119
119
  <?xml version="1.0" encoding="UTF-8"?>
@@ -126,7 +126,7 @@ ${i}`), u.groupEnd();
126
126
  <manifest>
127
127
  <item id="p01" href="p01.txt" media-type="text/plain"/>
128
128
  </manifest>
129
- <spine page-progression-direction="${s ?? "ltr"}">
129
+ <spine page-progression-direction="${o ?? "ltr"}">
130
130
  <itemref idref="p01" />
131
131
  </spine>
132
132
  </package>
@@ -136,7 +136,7 @@ ${i}`), u.groupEnd();
136
136
  records: [
137
137
  {
138
138
  dir: !1,
139
- basename: v("generated.opf"),
139
+ basename: b("generated.opf"),
140
140
  uri: "generated.opf",
141
141
  blob: async () => new Blob([r]),
142
142
  string: async () => r,
@@ -144,7 +144,7 @@ ${i}`), u.groupEnd();
144
144
  },
145
145
  {
146
146
  dir: !1,
147
- basename: v("p01.txt"),
147
+ basename: b("p01.txt"),
148
148
  uri: "p01.txt",
149
149
  blob: async () => typeof e == "string" ? new Blob([e]) : e,
150
150
  string: async () => typeof e == "string" ? e : e.text(),
@@ -154,8 +154,8 @@ ${i}`), u.groupEnd();
154
154
  ],
155
155
  close: () => Promise.resolve()
156
156
  };
157
- }, cn = async (e, t) => {
158
- const s = `
157
+ }, St = async (e, t) => {
158
+ const o = `
159
159
  <?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
160
160
  <metadata>
161
161
  <meta property="rendition:layout">${t?.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
@@ -163,22 +163,22 @@ ${i}`), u.groupEnd();
163
163
  </metadata>
164
164
  <manifest>
165
165
  ${e.map(
166
- (i) => `<item id="${v(i)}" href="${i}" media-type="${g(i)}"/>`
166
+ (s) => `<item id="${b(s)}" href="${s}" media-type="${v(s)}"/>`
167
167
  ).join(`
168
168
  `)}
169
169
  </manifest>
170
170
  <spine>
171
- ${e.map((i) => `<itemref idref="${v(i)}" />`).join(`
171
+ ${e.map((s) => `<itemref idref="${b(s)}" />`).join(`
172
172
  `)}
173
173
  </spine>
174
174
  </package>
175
- `, r = e.map((i) => ({
175
+ `, r = e.map((s) => ({
176
176
  dir: !1,
177
- basename: v(i),
178
- encodingFormat: g(i),
179
- uri: i,
177
+ basename: b(s),
178
+ encodingFormat: v(s),
179
+ uri: s,
180
180
  size: 100 / e.length,
181
- blob: async () => (await fetch(i)).blob(),
181
+ blob: async () => (await fetch(s)).blob(),
182
182
  string: async () => ""
183
183
  }));
184
184
  return {
@@ -189,363 +189,232 @@ ${i}`), u.groupEnd();
189
189
  uri: "content.opf",
190
190
  size: 0,
191
191
  blob: async () => new Blob(),
192
- string: async () => s
192
+ string: async () => o
193
193
  }, ...r],
194
194
  close: () => Promise.resolve()
195
195
  };
196
- }, dn = ({
196
+ }, kt = ({
197
197
  enableReport: e
198
198
  } = {}) => {
199
- u.enable(!!e);
200
- }, O = (e) => {
201
- const s = Object.values(e.records).filter(
199
+ f.enable(!!e);
200
+ }, P = (e) => {
201
+ const o = Object.values(e.records).filter(
202
202
  (r) => !r.dir
203
203
  ).find((r) => r.uri.endsWith(".opf"));
204
204
  return {
205
- data: s,
206
- basePath: s?.uri.substring(0, s.uri.lastIndexOf("/")) || ""
207
- };
208
- }, D = (e) => e.toLowerCase().endsWith(".opf"), ne = (e) => e.records.some(
209
- (t) => !t.dir && (D(t.basename) || D(t.uri))
210
- ), re = ({
211
- baseUrl: e = "",
212
- resourcePath: t
213
- }) => {
214
- if (!e && /^https?:\/\//.test(t))
215
- return encodeURI(t);
216
- const s = e ? `${e}${e.endsWith("/") ? "" : "/"}` : "file://";
217
- return encodeURI(`${s}${t}`);
218
- }, Ne = 2e3, V = (e) => {
219
- const t = Number.parseInt(e, 10);
220
- if (Number.isFinite(t) && !(t < 0 || t > Ne))
221
- return t;
222
- }, _e = (e) => {
223
- const t = /(?:^|[\s._(-]|\[)p\s*(\d{1,5})\s*[-_]\s*(?:p\s*)?(\d{1,5})(?=$|[^\d])/i.exec(
224
- e
225
- );
226
- return t || /(?:^|[\s._(]|\[)(0\d{1,4})\s*[-_]\s*(0\d{1,4})(?=$|[^\d])/i.exec(
227
- e
228
- );
229
- }, Ue = (e) => {
230
- const t = e.replace(/\.[^.]+$/, ""), s = _e(t);
231
- if (!s) return;
232
- const [, r, n] = s;
233
- if (r === void 0 || n === void 0)
234
- return;
235
- const i = V(r), o = V(n);
236
- if (!(i === void 0 || o === void 0) && o === i + 1)
237
- return {
238
- firstPageLabel: r,
239
- secondPageLabel: n
240
- };
241
- }, se = "__prose-reader__/page-spread", ie = "application/xhtml+xml", Be = /* @__PURE__ */ new Set([
242
- "image/jpg",
243
- "image/jpeg",
244
- "image/png",
245
- "image/webp"
246
- ]), X = (e) => e === void 0 ? !1 : Be.has(e), ze = (e) => encodeURIComponent(e), je = ({
247
- cropSide: e,
248
- originalUri: t
249
- }) => `${se}/${ze(t)}/${e}.xhtml`, De = (e) => e === "left" ? { pageSpreadLeft: !0, pageSpreadRight: void 0 } : { pageSpreadLeft: void 0, pageSpreadRight: !0 }, Ve = (e) => e === "rtl" ? ["right", "left"] : ["left", "right"], H = ({
250
- baseUrl: e,
251
- cropSide: t,
252
- label: s,
253
- originalSpineItem: r,
254
- originalUri: n,
255
- progressionWeight: i
256
- }) => {
257
- const o = je({
258
- cropSide: t,
259
- originalUri: n
260
- });
261
- return {
262
- ...r,
263
- id: `${r.id}.${s}`,
264
- href: re({ baseUrl: e, resourcePath: o }),
265
- mediaType: ie,
266
- progressionWeight: i,
267
- renditionLayout: "pre-paginated",
268
- ...De(t)
269
- };
270
- }, G = ({
271
- href: e,
272
- id: t,
273
- mediaType: s
274
- }) => ({
275
- href: e,
276
- id: t,
277
- mediaType: s
278
- }), Xe = ({
279
- archive: e,
280
- baseUrl: t,
281
- spineItem: s
282
- }) => {
283
- const r = [s.href, He(s.href)], n = new Set(
284
- r.flatMap((i) => qe(i, t))
285
- );
286
- return e.records.find(
287
- (i) => !i.dir && n.has(i.uri)
288
- );
289
- }, He = (e) => {
290
- try {
291
- return decodeURI(e);
292
- } catch {
293
- return e;
294
- }
295
- }, Ge = (e) => e.endsWith("/") ? e : `${e}/`, qe = (e, t) => {
296
- const s = [e];
297
- if (e.startsWith("file://") && s.push(e.slice(7)), t) {
298
- const r = Ge(t);
299
- e.startsWith(r) && s.push(e.slice(r.length));
300
- }
301
- return s;
302
- }, Ke = (e) => k(e?.encodingFormat ?? "") || g(e?.basename ?? ""), Je = (e) => g(e.uri) || g(e.basename), Ye = (e) => {
303
- if (e === void 0 || e.dir) return !1;
304
- const t = Je(e);
305
- return X(t) ? X(Ke(e)) : !1;
306
- }, Qe = ({ archive: e, baseUrl: t }) => async (s) => {
307
- if (ne(e)) return s;
308
- const r = [], n = s.spineItems.flatMap((i) => {
309
- const o = Xe({
310
- archive: e,
311
- baseUrl: t,
312
- spineItem: i
313
- });
314
- if (!Ye(o))
315
- return [i];
316
- const a = Ue(o.basename);
317
- if (a === void 0) return [i];
318
- const [c, l] = Ve(
319
- s.readingDirection
320
- ), p = i.progressionWeight !== void 0 ? i.progressionWeight / 2 : void 0, f = H({
321
- baseUrl: t,
322
- cropSide: c,
323
- label: a.firstPageLabel,
324
- originalSpineItem: i,
325
- originalUri: o.uri,
326
- progressionWeight: p
327
- }), h = H({
328
- baseUrl: t,
329
- cropSide: l,
330
- label: a.secondPageLabel,
331
- originalSpineItem: i,
332
- originalUri: o.uri,
333
- progressionWeight: p
334
- });
335
- return r.push(
336
- G(f),
337
- G(h)
338
- ), [f, h];
339
- });
340
- return r.length === 0 ? s : {
341
- ...s,
342
- spineItems: n.map((i, o) => ({
343
- ...i,
344
- index: o
345
- })),
346
- items: [...s.items, ...r]
205
+ data: o,
206
+ basePath: o?.uri.substring(0, o.uri.lastIndexOf("/")) || ""
347
207
  };
348
208
  };
349
- async function oe(e) {
350
- const { data: t, basePath: s } = O(e) || {};
209
+ async function Y(e) {
210
+ const { data: t, basePath: o } = P(e) || {};
351
211
  if (!t || t.dir)
352
212
  return;
353
213
  const r = await t.string();
354
214
  return {
355
- opf: ge(r),
356
- basePath: s
215
+ opf: ie(r),
216
+ basePath: o
357
217
  };
358
218
  }
359
- const Ze = Z.toLowerCase(), et = ({ archive: e }) => async (t) => {
360
- const s = e.records.find(
361
- (n) => !n.dir && n.basename.toLowerCase() === Ze
219
+ const Re = K.toLowerCase(), Te = ({ archive: e }) => async (t) => {
220
+ const o = e.records.find(
221
+ (n) => !n.dir && n.basename.toLowerCase() === Re
362
222
  );
363
- if (!s || s.dir)
223
+ if (!o || o.dir)
364
224
  return t;
365
- const r = await s.string();
225
+ const r = await o.string();
366
226
  try {
367
- const n = ye(r), { renditionLayout: i } = I(n);
227
+ const n = ae(r), { renditionLayout: s } = I(n);
368
228
  return {
369
229
  ...t,
370
- renditionLayout: t.renditionLayout ?? i
230
+ renditionLayout: t.renditionLayout ?? s
371
231
  };
372
232
  } catch (n) {
373
233
  return console.error(
374
- `Unable to parse ${Z} for content
234
+ `Unable to parse ${K} for content
375
235
  `,
376
236
  r
377
237
  ), console.error(n), t;
378
238
  }
379
- }, q = ee.toLowerCase(), tt = ({ archive: e }) => async (t) => {
380
- const s = e.records.find(
381
- (i) => i.basename.toLowerCase() === q && !i.dir
239
+ }, U = q.toLowerCase(), Se = ({ archive: e }) => async (t) => {
240
+ const o = e.records.find(
241
+ (s) => s.basename.toLowerCase() === U && !s.dir
382
242
  );
383
- if (!s || s.dir)
243
+ if (!o || o.dir)
384
244
  return t;
385
245
  const r = {
386
246
  ...t,
387
247
  spineItems: t.spineItems.filter(
388
- (i) => !i.id.toLowerCase().endsWith(q)
389
- ).map((i, o, a) => ({
390
- ...i,
248
+ (s) => !s.id.toLowerCase().endsWith(U)
249
+ ).map((s, i, a) => ({
250
+ ...s,
391
251
  progressionWeight: 1 / a.length
392
252
  }))
393
- }, n = await s.string();
253
+ }, n = await o.string();
394
254
  try {
395
- const i = ve(n), o = I(i);
255
+ const s = ce(n), i = I(s);
396
256
  return {
397
257
  ...r,
398
- readingDirection: o.readingDirection ?? "ltr"
258
+ readingDirection: i.readingDirection ?? "ltr"
399
259
  };
400
- } catch (i) {
260
+ } catch (s) {
401
261
  return console.error(
402
- `Unable to parse ${ee} for content
262
+ `Unable to parse ${q} for content
403
263
  `,
404
264
  n
405
- ), console.error(i), r;
265
+ ), console.error(s), r;
406
266
  }
407
- }, nt = ({ archive: e, baseUrl: t }) => async () => {
408
- const s = Object.values(e.records).filter((r) => !r.dir);
267
+ }, ke = ({
268
+ baseUrl: e = "",
269
+ resourcePath: t
270
+ }) => {
271
+ if (!e && /^https?:\/\//.test(t))
272
+ return encodeURI(t);
273
+ const o = e ? `${e}${e.endsWith("/") ? "" : "/"}` : "file://";
274
+ return encodeURI(`${o}${t}`);
275
+ }, Ce = ({ archive: e, baseUrl: t }) => async () => {
276
+ const o = Object.values(e.records).filter((r) => !r.dir);
409
277
  return {
410
278
  filename: e.filename,
411
279
  title: e.records.find(({ dir: r }) => r)?.basename.replace(/\/$/, "") || e.filename,
412
280
  renditionLayout: void 0,
413
281
  renditionSpread: "auto",
414
282
  readingDirection: "ltr",
415
- spineItems: s.filter((r) => !r.basename.endsWith(".db")).map((r, n) => ({
283
+ spineItems: o.filter((r) => !r.basename.endsWith(".db")).map((r, n) => ({
416
284
  // some books such as cbz can have same basename inside different sub folder
417
285
  // we need to make sure to have unique index
418
286
  // /chap01/01.png, /chap02/01.png, etc
419
287
  id: `${n}.${r.basename}`,
420
288
  index: n,
421
- href: re({
289
+ href: ke({
422
290
  baseUrl: t,
423
291
  resourcePath: r.uri
424
292
  }),
425
293
  renditionLayout: void 0,
426
- progressionWeight: 1 / s.length,
294
+ progressionWeight: 1 / o.length,
427
295
  pageSpreadLeft: void 0,
428
296
  pageSpreadRight: void 0,
429
297
  mediaType: r.encodingFormat
430
298
  })),
431
- items: s.map((r, n) => ({
299
+ items: o.map((r, n) => ({
432
300
  id: `${n}.${r.basename}`,
433
301
  href: encodeURI(`${t}${r.uri}`)
434
302
  }))
435
303
  };
436
- }, ae = async ({
304
+ }, Q = async ({
437
305
  archive: e,
438
306
  archiveOpf: t
439
307
  }) => {
440
308
  if (!t) return [];
441
- const { opf: s, basePath: r } = t, { spineRows: n } = s;
442
- return e.records.filter((o) => n.find((a) => r ? `${r}/${a.href}` === o.uri : `${a.href}` === o.uri));
443
- }, ce = (e, t, s) => {
444
- const { basePath: r } = O(t) || {};
309
+ const { opf: o, basePath: r } = t, { spineRows: n } = o;
310
+ return e.records.filter((i) => n.find((a) => r ? `${r}/${a.href}` === i.uri : `${a.href}` === i.uri));
311
+ }, Z = (e, t, o) => {
312
+ const { basePath: r } = P(t) || {};
445
313
  return e.map((n) => {
446
- const i = n.href, o = s?.(i) ?? "";
314
+ const s = n.href, i = o?.(s) ?? "";
447
315
  return {
448
- href: r ? `${o}${r}/${i}` : `${o}${i}`,
316
+ href: r ? `${i}${r}/${s}` : `${i}${s}`,
449
317
  id: n.id,
450
318
  mediaType: n.mediaType
451
319
  };
452
320
  });
453
- }, rt = (e) => {
321
+ }, We = (e) => {
454
322
  const t = e?.trim();
455
323
  return t === "scrolled-continuous" || t === "scrolled-doc" || t === "paginated" || t === "auto" ? t : "auto";
456
- }, st = (e) => {
324
+ }, Ee = (e) => {
457
325
  const t = e?.trim();
458
326
  if (t === "none" || t === "landscape" || t === "portrait" || t === "both" || t === "auto")
459
327
  return t;
460
- }, it = (e) => {
328
+ }, Pe = (e) => {
461
329
  const t = e?.trim();
462
330
  if (t === "cover" || t === "title-page" || t === "copyright-page" || t === "text")
463
331
  return t;
464
- }, ot = ({
332
+ }, Ne = ({
465
333
  archive: e,
466
334
  baseUrl: t,
467
- archiveOpf: s
335
+ archiveOpf: o
468
336
  }) => async (r) => {
469
- if (!s)
337
+ if (!o)
470
338
  return r;
471
- const { opf: n, basePath: i } = s, o = I(n);
472
- u.groupCollapsed(...u.getGroupArgs("OPF parsed")), u.log("opf", n), u.groupEnd();
473
- const a = n.renditionLayoutMeta?.trim(), c = a === "reflowable" || a === "pre-paginated" ? a : o.renditionLayout, l = n.title?.trim() || e.records.find(({ dir: d }) => d)?.basename || "", p = o.readingDirection ?? "ltr", h = (await ae({
339
+ const { opf: n, basePath: s } = o, i = I(n);
340
+ f.groupCollapsed(...f.getGroupArgs("OPF parsed")), f.log("opf", n), f.groupEnd();
341
+ const a = n.renditionLayoutMeta?.trim(), c = a === "reflowable" || a === "pre-paginated" ? a : i.renditionLayout, l = n.title?.trim() || e.records.find(({ dir: d }) => d)?.basename || "", p = i.readingDirection ?? "ltr", m = (await Q({
474
342
  archive: e,
475
- archiveOpf: s
343
+ archiveOpf: o
476
344
  })).reduce(
477
345
  (d, w) => w.size + d,
478
346
  0
479
- ), y = n.guide, b = [];
480
- for (const d of y) {
481
- const w = it(d.type);
482
- w !== void 0 && b.push({ href: d.href, title: d.title, type: w });
347
+ ), h = n.guide, y = [];
348
+ for (const d of h) {
349
+ const w = Pe(d.type);
350
+ w !== void 0 && y.push({ href: d.href, title: d.title, type: w });
483
351
  }
484
352
  return {
485
353
  filename: e.filename,
486
354
  renditionLayout: c,
487
- renditionFlow: rt(n.renditionFlowMeta),
488
- renditionSpread: st(n.renditionSpreadMeta),
355
+ renditionFlow: We(n.renditionFlowMeta),
356
+ renditionSpread: Ee(n.renditionSpreadMeta),
489
357
  title: l,
490
358
  readingDirection: p,
491
359
  /**
492
360
  * @see https://www.w3.org/TR/epub/#sec-itemref-elem
493
361
  */
494
362
  spineItems: n.spineRows.map((d, w) => {
495
- const m = e.records.find((A) => A.uri.endsWith(d.href))?.size || 0, $ = t || (/^https?:\/\//.test(d.href) ? "" : "file://");
363
+ const g = e.records.find((T) => T.uri.endsWith(d.href))?.size || 0, $ = t || (/^https?:\/\//.test(d.href) ? "" : "file://");
496
364
  return {
497
365
  id: d.id,
498
366
  index: w,
499
- href: d.href.startsWith("https://") ? d.href : i ? `${$}${i}/${d.href}` : `${$}${d.href}`,
367
+ href: d.href.startsWith("https://") ? d.href : s ? `${$}${s}/${d.href}` : `${$}${d.href}`,
500
368
  renditionLayout: d.renditionLayout ?? c,
501
- progressionWeight: m / h,
369
+ ...d.renditionFlow !== void 0 ? { renditionFlow: d.renditionFlow } : {},
370
+ progressionWeight: g / m,
502
371
  pageSpreadLeft: d.pageSpreadLeft,
503
372
  pageSpreadRight: d.pageSpreadRight,
504
373
  mediaType: d.mediaType
505
374
  };
506
375
  }),
507
- items: ce(n.manifestItems, e, (d) => /^https?:\/\//.test(d) ? "" : t || "file://"),
508
- guide: b.length > 0 ? b : void 0
376
+ items: Z(n.manifestItems, e, (d) => /^https?:\/\//.test(d) ? "" : t || "file://"),
377
+ guide: y.length > 0 ? y : void 0
509
378
  };
510
- }, at = (e) => {
511
- const t = e.descendantWithPath("head")?.childrenNamed("meta").find((s) => s.attr.name === "viewport");
379
+ }, Oe = (e) => {
380
+ const t = e.descendantWithPath("head")?.childrenNamed("meta").find((o) => o.attr.name === "viewport");
512
381
  return !!(t && t.attr.name === "viewport");
513
- }, ct = (e) => e.reduce(async (t, s) => {
514
- if (!await t || !fe({
515
- mimeType: s.encodingFormat,
516
- uri: s.uri
382
+ }, ze = (e) => e.reduce(async (t, o) => {
383
+ if (!await t || !se({
384
+ mimeType: o.encodingFormat,
385
+ uri: o.uri
517
386
  }))
518
387
  return !1;
519
- const n = s.dir ? null : await s.string();
520
- return n ? at(new P(n)) : !1;
521
- }, Promise.resolve(!0)), dt = ({
388
+ const n = o.dir ? null : await o.string();
389
+ return n ? Oe(new R(n)) : !1;
390
+ }, Promise.resolve(!0)), Me = ({
522
391
  archive: e,
523
392
  archiveOpf: t
524
- }) => async (s) => {
525
- if (s.renditionLayout === "reflowable" && s.spineItems.every((n) => n.renditionLayout === "reflowable")) {
526
- const n = await ae({
393
+ }) => async (o) => {
394
+ if (o.renditionLayout === "reflowable" && o.spineItems.every((n) => n.renditionLayout === "reflowable")) {
395
+ const n = await Q({
527
396
  archive: e,
528
397
  archiveOpf: t
529
398
  });
530
- if (await ct(n))
399
+ if (await ze(n))
531
400
  return {
532
- ...s,
533
- spineItems: s.spineItems.map((o) => ({
534
- ...o,
401
+ ...o,
402
+ spineItems: o.spineItems.map((i) => ({
403
+ ...i,
535
404
  renditionLayout: "pre-paginated"
536
405
  })),
537
406
  renditionLayout: "pre-paginated"
538
407
  };
539
408
  }
540
- return s;
541
- }, lt = async (e) => {
409
+ return o;
410
+ }, Be = async (e) => {
542
411
  let t;
543
412
  return await Promise.all(
544
- e.records.map(async (s) => {
545
- if (s.dir || !s.uri.endsWith(N)) return;
546
- const r = await s.string();
413
+ e.records.map(async (o) => {
414
+ if (o.dir || !o.uri.endsWith(N)) return;
415
+ const r = await o.string();
547
416
  try {
548
- const { renditionLayout: n } = be(r);
417
+ const { renditionLayout: n } = de(r);
549
418
  n && (t = n);
550
419
  } catch (n) {
551
420
  console.error(
@@ -559,24 +428,26 @@ const Ze = Z.toLowerCase(), et = ({ archive: e }) => async (t) => {
559
428
  kind: "kobo",
560
429
  ...t !== void 0 ? { renditionLayout: t } : {}
561
430
  };
562
- }, pt = ({ archive: e }) => async (t) => {
563
- const s = await lt(e), { renditionLayout: r } = I(s);
431
+ }, je = ({ archive: e }) => async (t) => {
432
+ const o = await Be(e), { renditionLayout: r } = I(o);
564
433
  return {
565
434
  ...t,
566
435
  renditionLayout: t.renditionLayout ?? r
567
436
  };
568
- }, ut = ({ archive: e }) => async (t) => ne(e) ? t : {
437
+ }, D = (e) => e.toLowerCase().endsWith(".opf"), Ue = (e) => e.records.some(
438
+ (t) => !t.dir && (D(t.basename) || D(t.uri))
439
+ ), De = ({ archive: e }) => async (t) => Ue(e) ? t : {
569
440
  ...t,
570
441
  spineItems: t.spineItems.map((r) => {
571
442
  const n = e.records.find(
572
- (o) => decodeURI(r.href).endsWith(o.uri)
573
- ), i = k(n?.encodingFormat ?? "") || g(n?.basename ?? "");
443
+ (i) => decodeURI(r.href).endsWith(i.uri)
444
+ ), s = G(n?.encodingFormat ?? "") || v(n?.basename ?? "");
574
445
  return {
575
446
  ...r,
576
- renditionLayout: i && he(i) ? "pre-paginated" : r.renditionLayout
447
+ renditionLayout: s && oe(s) ? "pre-paginated" : r.renditionLayout
577
448
  };
578
449
  })
579
- }, de = (e) => e ? e.children.map((t) => t instanceof $e ? t.text : t instanceof Se ? de(t) : "").join("").trim() : "", ft = (e) => we(e.properties).includes("nav"), le = (e, { basePath: t, baseUrl: s }) => {
450
+ }, ee = (e) => e ? e.children.map((t) => t instanceof pe ? t.text : t instanceof ue ? ee(t) : "").join("").trim() : "", He = (e) => le(e.properties).includes("nav"), te = (e, { basePath: t, baseUrl: o }) => {
580
451
  const r = {
581
452
  contents: [],
582
453
  path: "",
@@ -584,107 +455,107 @@ const Ze = Z.toLowerCase(), et = ({ archive: e }) => async (t) => {
584
455
  title: ""
585
456
  };
586
457
  let n = e.childNamed("span") || e.childNamed("a");
587
- r.title = (n?.attr.title || n?.val.trim() || de(n)) ?? "";
588
- let i = n?.name;
589
- i !== "a" && (n = e.descendantWithPath(`${i}.a`), n && (i = n.name.toLowerCase())), i === "a" && n?.attr.href && (r.path = F(t, n.attr.href), r.href = F(s, t, n.attr.href));
590
- const o = e.childNamed("ol");
591
- if (o) {
592
- const a = o.childrenNamed("li");
458
+ r.title = (n?.attr.title || n?.val.trim() || ee(n)) ?? "";
459
+ let s = n?.name;
460
+ s !== "a" && (n = e.descendantWithPath(`${s}.a`), n && (s = n.name.toLowerCase())), s === "a" && n?.attr.href && (r.path = L(t, n.attr.href), r.href = L(o, t, n.attr.href));
461
+ const i = e.childNamed("ol");
462
+ if (i) {
463
+ const a = i.childrenNamed("li");
593
464
  a && a.length > 0 && (r.contents = a.map(
594
- (c) => le(c, { basePath: t, baseUrl: s })
465
+ (c) => te(c, { basePath: t, baseUrl: o })
595
466
  ));
596
467
  }
597
468
  return r;
598
- }, ht = (e, { basePath: t, baseUrl: s }) => {
469
+ }, _e = (e, { basePath: t, baseUrl: o }) => {
599
470
  const r = [];
600
471
  let n;
601
- return e.descendantWithPath("body.nav.ol") ? n = e.descendantWithPath("body.nav.ol")?.children : e.descendantWithPath("body.section.nav.ol") && (n = e.descendantWithPath("body.section.nav.ol")?.children), n && n.length > 0 && n.filter((i) => i.name === "li").forEach((i) => {
602
- r.push(le(i, { basePath: t, baseUrl: s }));
472
+ return e.descendantWithPath("body.nav.ol") ? n = e.descendantWithPath("body.nav.ol")?.children : e.descendantWithPath("body.section.nav.ol") && (n = e.descendantWithPath("body.section.nav.ol")?.children), n && n.length > 0 && n.filter((s) => s.name === "li").forEach((s) => {
473
+ r.push(te(s, { basePath: t, baseUrl: o }));
603
474
  }), r;
604
- }, mt = async (e, t, { baseUrl: s }) => {
605
- const r = e.manifestItems.find(ft);
475
+ }, Ve = async (e, t, { baseUrl: o }) => {
476
+ const r = e.manifestItems.find(He);
606
477
  if (r?.href) {
607
478
  const n = Object.values(t.records).find(
608
- (i) => i.uri.endsWith(r.href)
479
+ (s) => s.uri.endsWith(r.href)
609
480
  );
610
481
  if (n && !n.dir) {
611
- const i = new P(await n.string()), o = ke(n.uri);
612
- return ht(i, { basePath: o, baseUrl: s });
482
+ const s = new R(await n.string()), i = Ae(n.uri);
483
+ return _e(s, { basePath: i, baseUrl: o });
613
484
  }
614
485
  }
615
- }, pe = (e, {
486
+ }, ne = (e, {
616
487
  opfBasePath: t,
617
- baseUrl: s,
488
+ baseUrl: o,
618
489
  prefix: r
619
490
  }) => {
620
- const n = e?.childNamed(`${r}content`)?.attr.src || "", i = {
491
+ const n = e?.childNamed(`${r}content`)?.attr.src || "", s = {
621
492
  title: e?.descendantWithPath(`${r}navLabel.${r}text`)?.val || "",
622
- path: F(t, n),
623
- href: F(s, t, n),
493
+ path: L(t, n),
494
+ href: L(o, t, n),
624
495
  contents: []
625
- }, o = e.childrenNamed(`${r}navPoint`);
626
- return o && o.length > 0 && (i.contents = o.map(
627
- (a) => pe(a, { opfBasePath: t, baseUrl: s, prefix: r })
628
- )), i;
629
- }, gt = (e, { opfBasePath: t, baseUrl: s }) => {
496
+ }, i = e.childrenNamed(`${r}navPoint`);
497
+ return i && i.length > 0 && (s.contents = i.map(
498
+ (a) => ne(a, { opfBasePath: t, baseUrl: o, prefix: r })
499
+ )), s;
500
+ }, Xe = (e, { opfBasePath: t, baseUrl: o }) => {
630
501
  const r = [], n = e.name;
631
- let i = "";
632
- return n.indexOf(":") !== -1 && (i = `${n.split(":")[0]}:`), e.childNamed(`${i}navMap`)?.childrenNamed(`${i}navPoint`).forEach((o) => {
633
- r.push(pe(o, { opfBasePath: t, baseUrl: s, prefix: i }));
502
+ let s = "";
503
+ return n.indexOf(":") !== -1 && (s = `${n.split(":")[0]}:`), e.childNamed(`${s}navMap`)?.childrenNamed(`${s}navPoint`).forEach((i) => {
504
+ r.push(ne(i, { opfBasePath: t, baseUrl: o, prefix: s }));
634
505
  }), r;
635
- }, yt = async ({
506
+ }, Ge = async ({
636
507
  opf: e,
637
508
  opfBasePath: t,
638
- baseUrl: s,
509
+ baseUrl: o,
639
510
  archive: r
640
511
  }) => {
641
512
  const n = e.spineTocIdref;
642
513
  if (n) {
643
- const i = e.manifestItems.find((o) => o.id === n);
644
- if (i) {
645
- const o = `${t}${t === "" ? "" : "/"}${i.href}`, a = Object.values(r.records).find(
646
- (c) => c.uri.endsWith(o)
514
+ const s = e.manifestItems.find((i) => i.id === n);
515
+ if (s) {
516
+ const i = `${t}${t === "" ? "" : "/"}${s.href}`, a = Object.values(r.records).find(
517
+ (c) => c.uri.endsWith(i)
647
518
  );
648
519
  if (a && !a.dir) {
649
- const c = new P(await a.string());
650
- return gt(c, { opfBasePath: t, baseUrl: s });
520
+ const c = new R(await a.string());
521
+ return Xe(c, { opfBasePath: t, baseUrl: o });
651
522
  }
652
523
  }
653
524
  }
654
- }, vt = async (e, t, { baseUrl: s }) => {
655
- const { basePath: r } = O(t) || {}, n = await mt(e, t, {
656
- baseUrl: s
525
+ }, Ke = async (e, t, { baseUrl: o }) => {
526
+ const { basePath: r } = P(t) || {}, n = await Ve(e, t, {
527
+ baseUrl: o
657
528
  });
658
529
  if (n)
659
530
  return n;
660
- const i = await yt({
531
+ const s = await Ge({
661
532
  opf: e,
662
533
  opfBasePath: r ?? "",
663
534
  archive: t,
664
- baseUrl: s
535
+ baseUrl: o
665
536
  });
666
- if (i)
667
- return i;
668
- }, bt = (e) => e.replace(/\.[^.]+$/, "").replace(/[_-]/g, " ").replace(/\s+/g, " ").trim(), wt = (e, t) => {
669
- if (!(e.spineItems.length === 0 || !e.spineItems.every((r) => (k(r.mediaType ?? "") || g(r.href))?.startsWith("audio/"))))
537
+ if (s)
538
+ return s;
539
+ }, qe = (e) => e.replace(/\.[^.]+$/, "").replace(/[_-]/g, " ").replace(/\s+/g, " ").trim(), Je = (e, t) => {
540
+ if (!(e.spineItems.length === 0 || !e.spineItems.every((r) => (G(r.mediaType ?? "") || v(r.href))?.startsWith("audio/"))))
670
541
  return e.spineItems.map((r) => {
671
542
  const n = t.records.find(
672
- (i) => !i.dir && decodeURI(r.href).endsWith(i.uri)
543
+ (s) => !s.dir && decodeURI(r.href).endsWith(s.uri)
673
544
  );
674
545
  return {
675
- title: bt(n?.basename ?? r.href),
546
+ title: qe(n?.basename ?? r.href),
676
547
  href: r.href,
677
548
  path: n?.uri ?? r.href,
678
549
  contents: []
679
550
  };
680
551
  });
681
- }, $t = (e, { baseUrl: t }) => {
682
- const s = [...e.records].sort(
683
- (n, i) => M(n.uri, i.uri)
684
- ), r = (n, i, o, a, c) => {
685
- const l = n.find((h) => h.title === i), [p, ...f] = o;
552
+ }, Ye = (e, { baseUrl: t }) => {
553
+ const o = [...e.records].sort(
554
+ (n, s) => E(n.uri, s.uri)
555
+ ), r = (n, s, i, a, c) => {
556
+ const l = n.find((m) => m.title === s), [p, ...u] = i;
686
557
  return l ? p ? [
687
- ...n.filter((y) => y !== l),
558
+ ...n.filter((h) => h !== l),
688
559
  {
689
560
  ...l,
690
561
  contents: [
@@ -692,14 +563,14 @@ const Ze = Z.toLowerCase(), et = ({ archive: e }) => async (t) => {
692
563
  ...r(
693
564
  l.contents,
694
565
  p,
695
- f,
566
+ u,
696
567
  a,
697
568
  c
698
569
  )
699
570
  ]
700
571
  }
701
572
  ] : l.path.split("/").length > c.split("/").length ? [
702
- ...n.filter((y) => y !== l),
573
+ ...n.filter((h) => h !== l),
703
574
  {
704
575
  ...l,
705
576
  path: c,
@@ -711,13 +582,13 @@ const Ze = Z.toLowerCase(), et = ({ archive: e }) => async (t) => {
711
582
  contents: r(
712
583
  [],
713
584
  p,
714
- f,
585
+ u,
715
586
  a,
716
587
  c
717
588
  ),
718
589
  href: a,
719
590
  path: c,
720
- title: i
591
+ title: s
721
592
  }
722
593
  ] : [
723
594
  ...n,
@@ -725,37 +596,37 @@ const Ze = Z.toLowerCase(), et = ({ archive: e }) => async (t) => {
725
596
  contents: [],
726
597
  href: a,
727
598
  path: c,
728
- title: i
599
+ title: s
729
600
  }
730
601
  ];
731
602
  };
732
- return s.reduce((n, i) => {
733
- if (i.dir) return n;
734
- const o = i.uri.split("/").slice(0, -1), [a, ...c] = o;
603
+ return o.reduce((n, s) => {
604
+ if (s.dir) return n;
605
+ const i = s.uri.split("/").slice(0, -1), [a, ...c] = i;
735
606
  if (!a) return n;
736
- const l = F(t, encodeURI(i.uri)).replace(/\/$/, ""), p = i.uri.replace(/\/$/, "");
607
+ const l = L(t, encodeURI(s.uri)).replace(/\/$/, ""), p = s.uri.replace(/\/$/, "");
737
608
  return r(n, a, c, l, p);
738
609
  }, []);
739
- }, St = async (e, t, {
740
- baseUrl: s,
610
+ }, Qe = async (e, t, {
611
+ baseUrl: o,
741
612
  archiveOpf: r
742
613
  }) => {
743
614
  if (r)
744
- return await vt(r.opf, e, { baseUrl: s }) || [];
745
- const n = wt(t, e);
615
+ return await Ke(r.opf, e, { baseUrl: o }) || [];
616
+ const n = Je(t, e);
746
617
  if (n) return n;
747
- const i = $t(e, { baseUrl: s });
748
- if (i.length !== 0)
749
- return i;
750
- }, Rt = ({
618
+ const s = Ye(e, { baseUrl: o });
619
+ if (s.length !== 0)
620
+ return s;
621
+ }, Ze = ({
751
622
  archive: e,
752
623
  baseUrl: t,
753
- archiveOpf: s
624
+ archiveOpf: o
754
625
  }) => async (r) => {
755
626
  if (r.nav) return r;
756
- const n = await St(e, r, {
627
+ const n = await Qe(e, r, {
757
628
  baseUrl: t,
758
- archiveOpf: s
629
+ archiveOpf: o
759
630
  });
760
631
  return n ? {
761
632
  ...r,
@@ -763,199 +634,95 @@ const Ze = Z.toLowerCase(), et = ({ archive: e }) => async (t) => {
763
634
  toc: n
764
635
  }
765
636
  } : r;
766
- }, xt = (e) => e ? e.endsWith("/") ? e : `${e}/` : "", Ft = async (e, { baseUrl: t = "" } = {}) => {
767
- const s = await oe(e), r = xt(t), n = [
768
- ot({ archive: e, baseUrl: r, archiveOpf: s }),
769
- tt({ archive: e }),
770
- et({ archive: e }),
771
- ut({ archive: e }),
772
- Qe({ archive: e, baseUrl: r }),
773
- dt({ archive: e, archiveOpf: s }),
774
- pt({ archive: e }),
775
- Rt({ archive: e, baseUrl: r, archiveOpf: s })
637
+ }, et = (e) => e ? e.endsWith("/") ? e : `${e}/` : "", tt = async (e, {
638
+ baseUrl: t = "",
639
+ hooks: o = {}
640
+ } = {}) => {
641
+ const r = await Y(e), n = et(t), s = (u) => (u ?? []).map(
642
+ (m) => m({ archive: e, baseUrl: n })
643
+ ), i = [
644
+ Ne({ archive: e, baseUrl: n, archiveOpf: r }),
645
+ Se({ archive: e }),
646
+ Te({ archive: e }),
647
+ De({ archive: e }),
648
+ ...s(o.content)
649
+ ], a = s(o.spine), c = [
650
+ Me({ archive: e, archiveOpf: r }),
651
+ je({ archive: e }),
652
+ ...s(o.presentation)
653
+ ], l = [
654
+ Ze({ archive: e, baseUrl: n, archiveOpf: r }),
655
+ ...s(o.navigation)
656
+ ], p = [
657
+ ...i,
658
+ ...a,
659
+ ...c,
660
+ ...l
776
661
  ];
777
662
  try {
778
- const i = nt({
663
+ const u = Ce({
779
664
  archive: e,
780
- baseUrl: r
781
- })(), o = await n.reduce(async (a, c) => await c(await a), i);
782
- if (u.log("Generated manifest", o), process.env.NODE_ENV === "development" && u.isEnabled()) {
783
- const a = JSON.stringify(o, null, 2);
784
- u.groupCollapsed(...u.getGroupArgs("Generated manifest")), u.log(`
785
- ${a}`), u.groupEnd();
665
+ baseUrl: n
666
+ })(), m = await p.reduce(async (h, y) => await y(await h), u);
667
+ if (f.log("Generated manifest", m), process.env.NODE_ENV === "development" && f.isEnabled()) {
668
+ const h = JSON.stringify(m, null, 2);
669
+ f.groupCollapsed(...f.getGroupArgs("Generated manifest")), f.log(`
670
+ ${h}`), f.groupEnd();
786
671
  }
787
- return o;
788
- } catch (i) {
789
- throw u.error(i), i;
790
- }
791
- }, C = /* @__PURE__ */ new WeakMap(), It = (e) => {
792
- try {
793
- return decodeURIComponent(e);
794
- } catch {
795
- return;
672
+ return m;
673
+ } catch (u) {
674
+ throw f.error(u), u;
796
675
  }
797
- }, Pt = (e) => {
798
- const t = e.indexOf(`${se}/`);
799
- if (t < 0) return;
800
- const r = e.slice(t).split("/"), n = r[2], i = r[3];
801
- if (r.length !== 4 || r[0] !== "__prose-reader__" || r[1] !== "page-spread" || n === void 0 || i === void 0)
802
- return;
803
- const o = i.split(".")[0];
804
- if (o !== "left" && o !== "right") return;
805
- const a = It(n);
806
- if (a !== void 0)
807
- return {
808
- originalUri: a,
809
- cropSide: o
810
- };
811
- }, At = ({
812
- cropSide: e,
813
- imageHeight: t,
814
- imageWidth: s
815
- }) => {
816
- const r = Math.floor(s / 2), n = s - r;
817
- return e === "left" ? { x: 0, width: r, height: t } : { x: r, width: n, height: t };
818
- }, Lt = (e) => /^https?:\/\//.test(e) ? e : `../../../${encodeURI(e)}`, Tt = async (e) => {
819
- if (typeof createImageBitmap != "function")
820
- throw new Error("Page spread XHTML generation requires createImageBitmap");
821
- const t = await createImageBitmap(e);
822
- try {
823
- return {
824
- height: t.height,
825
- width: t.width
826
- };
827
- } finally {
828
- t.close();
829
- }
830
- }, Et = ({
831
- cropSide: e,
832
- imageDimensions: t,
833
- originalUri: s
834
- }) => {
835
- if (t.width < 2)
836
- throw new Error("Page spread image is too narrow to split");
837
- const r = At({
838
- cropSide: e,
839
- imageHeight: t.height,
840
- imageWidth: t.width
841
- });
842
- return `<?xml version="1.0" encoding="UTF-8"?>
843
- <html xmlns="http://www.w3.org/1999/xhtml">
844
- <head>
845
- <meta name="viewport" content="width=${r.width}, height=${r.height}" />
846
- <style>
847
- html,
848
- body {
849
- width: ${r.width}px;
850
- height: ${r.height}px;
851
- margin: 0;
852
- overflow: hidden;
853
- }
854
-
855
- img {
856
- display: block;
857
- width: ${t.width}px;
858
- height: ${t.height}px;
859
- max-width: none;
860
- transform: translateX(-${r.x}px);
861
- user-select: none;
862
- -webkit-user-drag: none;
863
- }
864
- </style>
865
- </head>
866
- <body>
867
- <img src="${me(Lt(s))}" alt="" />
868
- </body>
869
- </html>`;
870
- }, Ct = async ({
871
- archive: e,
872
- resourcePath: t
873
- }) => {
874
- const s = Pt(t);
875
- if (s === void 0) return;
876
- const r = e.records.find(
877
- (a) => a.uri === s.originalUri && !a.dir
878
- );
879
- if (r === void 0 || r.dir)
880
- throw new Error(
881
- `no source file found for virtual page spread resourcePath:${t}`
882
- );
883
- const n = C.get(e) ?? /* @__PURE__ */ new Map();
884
- C.has(e) || C.set(e, n);
885
- const i = n.get(s.originalUri) ?? await Tt(await r.blob());
886
- return n.set(s.originalUri, i), {
887
- body: Et({
888
- cropSide: s.cropSide,
889
- imageDimensions: i,
890
- originalUri: s.originalUri
891
- }),
892
- params: {
893
- contentType: ie
894
- }
895
- };
896
- }, Wt = ({ archive: e, resourcePath: t }) => async (s) => {
897
- const r = await Ct({
898
- archive: e,
899
- resourcePath: t
900
- });
901
- return r === void 0 ? s : {
902
- ...s,
903
- ...r,
904
- params: {
905
- ...s.params,
906
- ...r.params
907
- }
908
- };
909
- }, kt = (e) => {
910
- const t = e.descendantWithPath("head")?.childrenNamed("meta").find((s) => s.attr.name === "calibre:cover");
676
+ }, nt = (e) => {
677
+ const t = e.descendantWithPath("head")?.childrenNamed("meta").find((o) => o.attr.name === "calibre:cover");
911
678
  return !!(t && t.attr.name === "calibre:cover");
912
- }, Mt = (e) => e.descendantWithPath("body")?.descendantWithPath("div")?.childrenNamed("svg")?.find(
679
+ }, rt = (e) => e.descendantWithPath("body")?.descendantWithPath("div")?.childrenNamed("svg")?.find(
913
680
  (t) => t.attr.width === "100%" && t.attr.preserveAspectRatio === "none"
914
- ), Ot = ({ archive: e, resourcePath: t }) => async (s) => {
681
+ ), st = ({ archive: e, resourcePath: t }) => async (o) => {
915
682
  const r = Object.values(e.records).find(
916
683
  (n) => n.uri === t && !n.dir
917
684
  );
918
685
  if (r && !r.dir && r.basename.endsWith(".xhtml")) {
919
- const n = typeof s.body == "string" ? s.body : await r.string(), i = new P(n);
920
- if (kt(i)) {
921
- const o = Mt(i);
922
- return o && delete o.attr.preserveAspectRatio, {
923
- ...s,
924
- body: i?.toString()
686
+ const n = typeof o.body == "string" ? o.body : await r.string(), s = new R(n);
687
+ if (nt(s)) {
688
+ const i = rt(s);
689
+ return i && delete i.attr.preserveAspectRatio, {
690
+ ...o,
691
+ body: s?.toString()
925
692
  };
926
693
  }
927
694
  }
928
- return s;
929
- }, Nt = ({ archive: e, resourcePath: t }) => async (s) => Ot({ archive: e, resourcePath: t })(s), _t = ({ archive: e, resourcePath: t }) => async (s) => {
695
+ return o;
696
+ }, ot = ({ archive: e, resourcePath: t }) => async (o) => st({ archive: e, resourcePath: t })(o), it = ({ archive: e, resourcePath: t }) => async (o) => {
930
697
  const r = Object.values(e.records).find(
931
698
  (n) => n.uri === t && !n.dir
932
699
  );
933
700
  if (r && !r.dir && r.basename.endsWith(".css")) {
934
- const i = (typeof s.body == "string" ? s.body : await r.string()).replaceAll(
701
+ const s = (typeof o.body == "string" ? o.body : await r.string()).replaceAll(
935
702
  "-webkit-writing-mode",
936
703
  "writing-mode"
937
704
  );
938
705
  return {
939
- ...s,
940
- body: i
706
+ ...o,
707
+ body: s
941
708
  };
942
709
  }
943
- return s;
944
- }, Ut = async (e, t) => {
945
- const s = await oe(e);
946
- if (s) {
947
- const { opf: r } = s, n = ce(r.manifestItems, e, () => "");
710
+ return o;
711
+ }, at = async (e, t) => {
712
+ const o = await Y(e);
713
+ if (o) {
714
+ const { opf: r } = o, n = Z(r.manifestItems, e, () => "");
948
715
  if (n.find(
949
- (o) => t.endsWith(o.href)
716
+ (i) => t.endsWith(i.href)
950
717
  )?.mediaType)
951
718
  return {
952
- mediaType: n.find((o) => t.endsWith(o.href))?.mediaType
719
+ mediaType: n.find((i) => t.endsWith(i.href))?.mediaType
953
720
  };
954
721
  }
955
722
  return {
956
- mediaType: Bt(t)
723
+ mediaType: ct(t)
957
724
  };
958
- }, Bt = (e) => {
725
+ }, ct = (e) => {
959
726
  if (e.endsWith(".css"))
960
727
  return "text/css; charset=UTF-8";
961
728
  if (e.endsWith(".jpg"))
@@ -966,16 +733,16 @@ ${a}`), u.groupEnd();
966
733
  return "video/mp4";
967
734
  if (e.endsWith(".svg"))
968
735
  return "image/svg+xml";
969
- }, zt = ({ archive: e, resourcePath: t }) => async (s) => {
736
+ }, dt = ({ archive: e, resourcePath: t }) => async (o) => {
970
737
  const r = Object.values(e.records).find(
971
- (i) => i.uri === t && !i.dir
738
+ (s) => s.uri === t && !s.dir
972
739
  );
973
- if (!r || r.dir) return s;
974
- const n = await Ut(e, t);
740
+ if (!r || r.dir) return o;
741
+ const n = await at(e, t);
975
742
  return {
976
- ...s,
743
+ ...o,
977
744
  params: {
978
- ...s.params,
745
+ ...o.params,
979
746
  ...r?.encodingFormat && {
980
747
  contentType: r.encodingFormat
981
748
  },
@@ -984,7 +751,7 @@ ${a}`), u.groupEnd();
984
751
  }
985
752
  }
986
753
  };
987
- }, K = [
754
+ }, H = [
988
755
  "div",
989
756
  "span",
990
757
  "p",
@@ -1035,60 +802,60 @@ ${a}`), u.groupEnd();
1035
802
  "canvas",
1036
803
  "script",
1037
804
  "style"
1038
- ], jt = ({ archive: e, resourcePath: t }) => async (s) => {
805
+ ], lt = ({ archive: e, resourcePath: t }) => async (o) => {
1039
806
  const r = Object.values(e.records).find(
1040
807
  (n) => n.uri === t && !n.dir
1041
808
  );
1042
809
  if (r && !r.dir && r.basename.endsWith(".xhtml")) {
1043
- const n = typeof s.body == "string" ? s.body : await r.string();
810
+ const n = typeof o.body == "string" ? o.body : await r.string();
1044
811
  if (!new RegExp(
1045
- `<(${K.join("|")})[\\s/>]`,
812
+ `<(${H.join("|")})[\\s/>]`,
1046
813
  "i"
1047
814
  ).test(n))
1048
- return s;
1049
- const o = new RegExp(
1050
- `<(${K.join("|")})(\\s[^>]*)?\\s*/>`,
815
+ return o;
816
+ const i = new RegExp(
817
+ `<(${H.join("|")})(\\s[^>]*)?\\s*/>`,
1051
818
  "gi"
1052
819
  ), a = n.replace(
1053
- o,
820
+ i,
1054
821
  (c, l, p = "") => `<${l} ${p.trim()}></${l}>`
1055
822
  );
1056
823
  return {
1057
- ...s,
824
+ ...o,
1058
825
  body: a
1059
826
  };
1060
827
  }
1061
- return s;
1062
- }, Dt = async (e, t) => {
1063
- const s = {
828
+ return o;
829
+ }, pt = async (e, t, { hooks: o = [] } = {}) => {
830
+ const r = {
1064
831
  params: {}
1065
- }, r = [
1066
- Wt({ archive: e, resourcePath: t }),
1067
- zt({ archive: e, resourcePath: t }),
1068
- jt({ archive: e, resourcePath: t }),
1069
- _t({ archive: e, resourcePath: t }),
1070
- Nt({ archive: e, resourcePath: t })
832
+ }, s = [
833
+ ...o.map((i) => i({ archive: e, resourcePath: t })),
834
+ dt({ archive: e, resourcePath: t }),
835
+ lt({ archive: e, resourcePath: t }),
836
+ it({ archive: e, resourcePath: t }),
837
+ ot({ archive: e, resourcePath: t })
1071
838
  ];
1072
839
  try {
1073
- const n = await r.reduce(async (o, a) => await a(await o), Promise.resolve(s));
1074
- if (u.log("Generated resource", t, n), n.body !== void 0)
1075
- return n;
1076
- const i = Object.values(e.records).find(
1077
- (o) => o.uri === t && !o.dir
840
+ const i = await s.reduce(async (c, l) => await l(await c), Promise.resolve(r));
841
+ if (f.log("Generated resource", t, i), i.body !== void 0)
842
+ return i;
843
+ const a = Object.values(e.records).find(
844
+ (c) => c.uri === t && !c.dir
1078
845
  );
1079
- if (!i || i.dir)
846
+ if (!a || a.dir)
1080
847
  throw new Error(`no file found for resourcePath:${t}`);
1081
848
  return {
1082
- ...n,
1083
- body: await i.blob()
849
+ ...i,
850
+ body: await a.blob()
1084
851
  };
1085
- } catch (n) {
1086
- throw u.error(n), n;
852
+ } catch (i) {
853
+ throw f.error(i), i;
1087
854
  }
1088
855
  };
1089
- class Vt {
856
+ class ut {
1090
857
  constructor(t) {
1091
- this.cleanArchiveAfter = t, this.state$ = new Pe({
858
+ this.cleanArchiveAfter = t, this.state$ = new ye({
1092
859
  status: "idle",
1093
860
  locks: 0
1094
861
  });
@@ -1097,114 +864,114 @@ class Vt {
1097
864
  this.state$.next({ ...this.state$.getValue(), ...t });
1098
865
  }
1099
866
  get locks$() {
1100
- return this.state$.pipe(S(({ locks: t }) => t));
867
+ return this.state$.pipe(F(({ locks: t }) => t));
1101
868
  }
1102
869
  get state() {
1103
870
  return this.state$.getValue();
1104
871
  }
1105
872
  get isUnlocked$() {
1106
873
  return this.locks$.pipe(
1107
- S((t) => t <= 0),
1108
- Ae(),
1109
- Le()
874
+ F((t) => t <= 0),
875
+ be(),
876
+ ve()
1110
877
  );
1111
878
  }
1112
879
  get overTTL$() {
1113
880
  return this.isUnlocked$.pipe(
1114
- x(
1115
- (t) => t ? this.cleanArchiveAfter === 1 / 0 ? z : Te(this.cleanArchiveAfter) : z
881
+ A(
882
+ (t) => t ? this.cleanArchiveAfter === 1 / 0 ? B : we(this.cleanArchiveAfter) : B
1116
883
  )
1117
884
  );
1118
885
  }
1119
886
  }
1120
- const Xt = ({
887
+ const ft = ({
1121
888
  getArchive: e,
1122
889
  cleanArchiveAfter: t = 300 * 1e3
1123
890
  // 5mn
1124
891
  }) => {
1125
- const s = new L(), r = new L(), n = new L(), i = {}, o = s.pipe(
1126
- te((l) => {
1127
- const p = i[l];
1128
- if (!p || p.state.status !== "idle") return _;
1129
- let f = !1;
1130
- const h = (m) => {
1131
- u.debug(`Cleaning up archive with key: ${m}`);
1132
- const $ = i[m];
1133
- delete i[m], f || ($?.state.archive?.close(), f = !0);
892
+ const o = new S(), r = new S(), n = new S(), s = {}, i = o.pipe(
893
+ J((l) => {
894
+ const p = s[l];
895
+ if (!p || p.state.status !== "idle") return O;
896
+ let u = !1;
897
+ const m = (g) => {
898
+ f.debug(`Cleaning up archive with key: ${g}`);
899
+ const $ = s[g];
900
+ delete s[g], u || ($?.state.archive?.close(), u = !0);
1134
901
  };
1135
902
  p.update({
1136
903
  status: "loading"
1137
904
  });
1138
- const y = p.locks$, b = p.isUnlocked$, d = y.pipe(
1139
- Re(),
1140
- T(([m, $]) => $ > m),
1141
- xe(!0)
905
+ const h = p.locks$, y = p.isUnlocked$, d = h.pipe(
906
+ fe(),
907
+ k(([g, $]) => $ > g),
908
+ me(!0)
1142
909
  );
1143
- return R(e(l)).pipe(
1144
- E((m) => {
910
+ return x(e(l)).pipe(
911
+ C((g) => {
1145
912
  p.update({
1146
- archive: m,
913
+ archive: g,
1147
914
  status: "success"
1148
915
  });
1149
916
  }),
1150
- W((m) => (h(l), p.update({
917
+ W((g) => (m(l), p.update({
1151
918
  status: "error",
1152
- error: m
1153
- }), _)),
1154
- x(() => {
1155
- const m = d.pipe(
1156
- x(() => n),
1157
- x(() => b),
1158
- T((A) => A)
919
+ error: g
920
+ }), O)),
921
+ A(() => {
922
+ const g = d.pipe(
923
+ A(() => n),
924
+ A(() => y),
925
+ k((T) => T)
1159
926
  );
1160
- return U(m, p.overTTL$).pipe(
1161
- B(),
1162
- E(() => {
1163
- h(l);
927
+ return z(g, p.overTTL$).pipe(
928
+ M(),
929
+ C(() => {
930
+ m(l);
1164
931
  })
1165
932
  );
1166
933
  })
1167
934
  );
1168
935
  }),
1169
- Fe(r)
936
+ he(r)
1170
937
  ), a = (l) => {
1171
938
  let p = !1;
1172
- const f = i[l] ?? new Vt(t);
1173
- i[l] = f, f.update({
1174
- locks: f.state.locks + 1
939
+ const u = s[l] ?? new ut(t);
940
+ s[l] = u, u.update({
941
+ locks: u.state.locks + 1
1175
942
  });
1176
- const h = () => {
1177
- p || (p = !0, f.update({
1178
- locks: f.state.locks - 1
943
+ const m = () => {
944
+ p || (p = !0, u.update({
945
+ locks: u.state.locks - 1
1179
946
  }));
1180
947
  };
1181
- s.next(l);
1182
- const y = f.state$.pipe(
1183
- S(({ archive: d }) => d),
1184
- T((d) => !!d)
1185
- ), b = f.state$.pipe(
1186
- E(({ error: d }) => {
948
+ o.next(l);
949
+ const h = u.state$.pipe(
950
+ F(({ archive: d }) => d),
951
+ k((d) => !!d)
952
+ ), y = u.state$.pipe(
953
+ C(({ error: d }) => {
1187
954
  if (d)
1188
955
  throw d;
1189
956
  }),
1190
- Ie()
957
+ ge()
1191
958
  );
1192
- return U(y, b).pipe(
1193
- B(),
1194
- S((d) => ({ archive: d, release: h })),
959
+ return z(h, y).pipe(
960
+ M(),
961
+ F((d) => ({ archive: d, release: m })),
1195
962
  W((d) => {
1196
- throw h(), d;
963
+ throw m(), d;
1197
964
  })
1198
965
  );
1199
966
  }, c = () => {
1200
967
  n.next();
1201
968
  };
1202
- return o.subscribe(), {
969
+ return i.subscribe(), {
1203
970
  access: a,
1204
971
  purge: c,
1205
- _archives: i
972
+ _archives: s
1206
973
  };
1207
- }, J = (e) => e ? /^\d+$/.test(e) ? {
974
+ }, _ = (e) => e ? /^\d+$/.test(e) ? {
1208
975
  valid: !0,
1209
976
  value: Number.parseInt(e, 10)
1210
977
  } : {
@@ -1213,7 +980,7 @@ const Xt = ({
1213
980
  } : {
1214
981
  valid: !0,
1215
982
  value: void 0
1216
- }, Ht = (e) => {
983
+ }, mt = (e) => {
1217
984
  if (!e.toLowerCase().startsWith("bytes="))
1218
985
  return {
1219
986
  kind: "missing"
@@ -1227,59 +994,59 @@ const Xt = ({
1227
994
  return {
1228
995
  kind: "multi"
1229
996
  };
1230
- const s = /^(\d*)-(\d*)$/.exec(t);
1231
- if (!s)
997
+ const o = /^(\d*)-(\d*)$/.exec(t);
998
+ if (!o)
1232
999
  return {
1233
1000
  kind: "invalid"
1234
1001
  };
1235
- const [, r = "", n = ""] = s, i = J(r.trim()), o = J(n.trim());
1236
- return !i.valid || !o.valid ? {
1002
+ const [, r = "", n = ""] = o, s = _(r.trim()), i = _(n.trim());
1003
+ return !s.valid || !i.valid ? {
1237
1004
  kind: "invalid"
1238
1005
  } : {
1239
1006
  kind: "single",
1240
- start: i.value,
1241
- end: o.value
1007
+ start: s.value,
1008
+ end: i.value
1242
1009
  };
1243
- }, Gt = (e) => {
1010
+ }, ht = (e) => {
1244
1011
  if (e instanceof Blob)
1245
1012
  return {
1246
1013
  size: e.size,
1247
- slice: (s, r) => {
1248
- const n = e.slice(s, r);
1014
+ slice: (o, r) => {
1015
+ const n = e.slice(o, r);
1249
1016
  return { content: n, length: n.size };
1250
1017
  }
1251
1018
  };
1252
1019
  const t = new TextEncoder().encode(e);
1253
1020
  return {
1254
1021
  size: t.byteLength,
1255
- slice: (s, r) => {
1256
- const n = t.slice(s, r);
1022
+ slice: (o, r) => {
1023
+ const n = t.slice(o, r);
1257
1024
  return { content: n, length: n.byteLength };
1258
1025
  }
1259
1026
  };
1260
- }, qt = ({
1027
+ }, gt = ({
1261
1028
  body: e,
1262
1029
  contentType: t,
1263
- rangeHeader: s
1030
+ rangeHeader: o
1264
1031
  }) => {
1265
1032
  const r = new Headers();
1266
- if (t && r.set("Content-Type", t), r.set("Accept-Ranges", "bytes"), !s)
1033
+ if (t && r.set("Content-Type", t), r.set("Accept-Ranges", "bytes"), !o)
1267
1034
  return e instanceof Blob && r.set("Content-Length", String(e.size)), new Response(e, {
1268
1035
  status: 200,
1269
1036
  headers: r
1270
1037
  });
1271
- const n = Ht(s);
1038
+ const n = mt(o);
1272
1039
  if (n.kind === "missing" || n.kind === "multi")
1273
1040
  return e instanceof Blob && r.set("Content-Length", String(e.size)), new Response(e, {
1274
1041
  status: 200,
1275
1042
  headers: r
1276
1043
  });
1277
- const i = Gt(e), o = i.size;
1044
+ const s = ht(e), i = s.size;
1278
1045
  if (n.kind === "invalid")
1279
1046
  return new Response(null, {
1280
1047
  status: 416,
1281
1048
  headers: {
1282
- "Content-Range": `bytes */${o}`
1049
+ "Content-Range": `bytes */${i}`
1283
1050
  }
1284
1051
  });
1285
1052
  let a = n.start, c = n.end;
@@ -1287,42 +1054,43 @@ const Xt = ({
1287
1054
  return new Response(null, {
1288
1055
  status: 416,
1289
1056
  headers: {
1290
- "Content-Range": `bytes */${o}`
1057
+ "Content-Range": `bytes */${i}`
1291
1058
  }
1292
1059
  });
1293
1060
  if (a === void 0) {
1294
- const p = Math.min(c ?? 0, o);
1295
- a = Math.max(0, o - p), c = o - 1;
1296
- } else (c === void 0 || c >= o) && (c = o - 1);
1297
- if (a < 0 || c < 0 || a >= o || c >= o || a > c)
1061
+ const p = Math.min(c ?? 0, i);
1062
+ a = Math.max(0, i - p), c = i - 1;
1063
+ } else (c === void 0 || c >= i) && (c = i - 1);
1064
+ if (a < 0 || c < 0 || a >= i || c >= i || a > c)
1298
1065
  return new Response(null, {
1299
1066
  status: 416,
1300
1067
  headers: {
1301
- "Content-Range": `bytes */${o}`
1068
+ "Content-Range": `bytes */${i}`
1302
1069
  }
1303
1070
  });
1304
- const l = i.slice(a, c + 1);
1305
- return r.set("Content-Length", String(l.length)), r.set("Content-Range", `bytes ${a}-${c}/${o}`), new Response(l.content, {
1071
+ const l = s.slice(a, c + 1);
1072
+ return r.set("Content-Length", String(l.length)), r.set("Content-Range", `bytes ${a}-${c}/${i}`), new Response(l.content, {
1306
1073
  status: 206,
1307
1074
  headers: r
1308
1075
  });
1309
- }, Y = "file://", Kt = /^https?:\/\//, Jt = (e) => {
1076
+ }, V = "file://", yt = /^https?:\/\//, bt = (e) => {
1310
1077
  try {
1311
1078
  return decodeURIComponent(e);
1312
1079
  } catch {
1313
1080
  return e;
1314
1081
  }
1315
- }, Q = (e) => e.startsWith(Y) ? e.slice(Y.length) : e, Yt = (e) => {
1316
- const t = Q(e);
1317
- return Kt.test(t) ? t : Q(Jt(t));
1082
+ }, X = (e) => e.startsWith(V) ? e.slice(V.length) : e, vt = (e) => {
1083
+ const t = X(e);
1084
+ return yt.test(t) ? t : X(bt(t));
1318
1085
  };
1319
- class Qt {
1086
+ class wt {
1320
1087
  constructor({
1321
- onError: t,
1322
- onManifestSuccess: s,
1323
- ...r
1088
+ hooks: t,
1089
+ onError: o,
1090
+ onManifestSuccess: r,
1091
+ ...n
1324
1092
  }) {
1325
- this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.archiveLoader = Xt(r), this.onManifestSuccess = s ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
1093
+ this.onError = (s) => (console.error(s), new Response(String(s), { status: 500 })), this.archiveLoader = ft(n), this.hooks = t ?? {}, this.onManifestSuccess = r ?? (({ manifest: s }) => Promise.resolve(s)), this.onError = o ?? this.onError;
1326
1094
  }
1327
1095
  prune() {
1328
1096
  this.archiveLoader.purge();
@@ -1332,36 +1100,39 @@ class Qt {
1332
1100
  }
1333
1101
  accessArchiveWithoutLock(t) {
1334
1102
  return this.accessArchive(t).pipe(
1335
- S(({ archive: s, release: r }) => (r(), s))
1103
+ F(({ archive: o, release: r }) => (r(), o))
1336
1104
  );
1337
1105
  }
1338
1106
  withArchiveResponse({
1339
1107
  key: t,
1340
- getResponse: s
1108
+ getResponse: o
1341
1109
  }) {
1342
1110
  const r = this.accessArchive(t).pipe(
1343
- te(
1344
- ({ archive: n, release: i }) => R(s(n)).pipe(
1345
- Ee(() => {
1346
- i();
1111
+ J(
1112
+ ({ archive: n, release: s }) => x(o(n)).pipe(
1113
+ $e(() => {
1114
+ s();
1347
1115
  })
1348
1116
  )
1349
1117
  ),
1350
- W((n) => Ce(this.onError(n)))
1118
+ W((n) => Fe(this.onError(n)))
1351
1119
  );
1352
- return We(r);
1120
+ return xe(r);
1353
1121
  }
1354
- fetchManifest({ key: t, baseUrl: s }) {
1122
+ fetchManifest({ key: t, baseUrl: o }) {
1355
1123
  return this.withArchiveResponse({
1356
1124
  key: t,
1357
- getResponse: (r) => R(
1358
- Ft(r, { baseUrl: s })
1125
+ getResponse: (r) => x(
1126
+ tt(r, {
1127
+ baseUrl: o,
1128
+ hooks: this.hooks.manifest
1129
+ })
1359
1130
  ).pipe(
1360
- x(
1361
- (i) => R(this.onManifestSuccess({ manifest: i, archive: r }))
1131
+ A(
1132
+ (s) => x(this.onManifestSuccess({ manifest: s, archive: r }))
1362
1133
  ),
1363
- S(
1364
- (i) => new Response(JSON.stringify(i), {
1134
+ F(
1135
+ (s) => new Response(JSON.stringify(s), {
1365
1136
  status: 200
1366
1137
  })
1367
1138
  )
@@ -1370,18 +1141,20 @@ class Qt {
1370
1141
  }
1371
1142
  fetchResource({
1372
1143
  key: t,
1373
- resourcePath: s,
1144
+ resourcePath: o,
1374
1145
  request: r
1375
1146
  }) {
1376
1147
  return this.withArchiveResponse({
1377
1148
  key: t,
1378
1149
  getResponse: (n) => {
1379
- const i = Yt(s);
1380
- return R(
1381
- Dt(n, i)
1150
+ const s = vt(o);
1151
+ return x(
1152
+ pt(n, s, {
1153
+ hooks: this.hooks.resource
1154
+ })
1382
1155
  ).pipe(
1383
- S(
1384
- (a) => qt({
1156
+ F(
1157
+ (a) => gt({
1385
1158
  body: a.body ?? "",
1386
1159
  contentType: a.params.contentType,
1387
1160
  rangeHeader: r?.headers.get("range")
@@ -1392,51 +1165,51 @@ class Qt {
1392
1165
  });
1393
1166
  }
1394
1167
  }
1395
- class ln extends Qt {
1168
+ class Ct extends wt {
1396
1169
  constructor({
1397
1170
  getUriInfo: t,
1398
- ...s
1171
+ ...o
1399
1172
  }) {
1400
- super(s), this.getUriInfo = t, this.fetchEventListener = this.fetchEventListener.bind(this);
1173
+ super(o), this.getUriInfo = t, this.fetchEventListener = this.fetchEventListener.bind(this);
1401
1174
  }
1402
1175
  fetchEventListener(t) {
1403
1176
  try {
1404
- const s = this.getUriInfo(t);
1405
- if (!s) return;
1406
- const r = j(s.baseUrl), n = t.request.url.substring(
1177
+ const o = this.getUriInfo(t);
1178
+ if (!o) return;
1179
+ const r = j(o.baseUrl), n = t.request.url.substring(
1407
1180
  r.length + 1
1408
- ), [i = ""] = n.split("/"), o = j(
1409
- n.substring(i.length + 1)
1181
+ ), [s = ""] = n.split("/"), i = j(
1182
+ n.substring(s.length + 1)
1410
1183
  );
1411
1184
  n.endsWith("/manifest") ? t.respondWith(
1412
- this.fetchManifest({ key: i, baseUrl: `${r}/${i}/` })
1185
+ this.fetchManifest({ key: s, baseUrl: `${r}/${s}/` })
1413
1186
  ) : t.respondWith(
1414
1187
  this.fetchResource({
1415
- key: i,
1416
- resourcePath: o,
1188
+ key: s,
1189
+ resourcePath: i,
1417
1190
  request: t.request
1418
1191
  })
1419
1192
  );
1420
- } catch (s) {
1421
- t.respondWith(new Response(String(s), { status: 500 }));
1193
+ } catch (o) {
1194
+ t.respondWith(new Response(String(o), { status: 500 }));
1422
1195
  }
1423
1196
  }
1424
1197
  }
1425
1198
  export {
1426
- ln as ServiceWorkerStreamer,
1427
- Qt as Streamer,
1428
- dn as configure,
1429
- rn as createArchiveFromArrayBufferList,
1430
- sn as createArchiveFromJszip,
1431
- on as createArchiveFromLibArchive,
1432
- an as createArchiveFromText,
1433
- cn as createArchiveFromUrls,
1434
- Ft as generateManifestFromArchive,
1435
- Dt as generateResourceFromArchive,
1436
- O as getArchiveOpfInfo,
1437
- ke as getUriBasePath,
1438
- v as getUriBasename,
1199
+ Ct as ServiceWorkerStreamer,
1200
+ wt as Streamer,
1201
+ kt as configure,
1202
+ Lt as createArchiveFromArrayBufferList,
1203
+ It as createArchiveFromJszip,
1204
+ Rt as createArchiveFromLibArchive,
1205
+ Tt as createArchiveFromText,
1206
+ St as createArchiveFromUrls,
1207
+ tt as generateManifestFromArchive,
1208
+ pt as generateResourceFromArchive,
1209
+ P as getArchiveOpfInfo,
1210
+ Ae as getUriBasePath,
1211
+ b as getUriBasename,
1439
1212
  j as removeTrailingSlash,
1440
- M as sortByTitleComparator
1213
+ E as sortByTitleComparator
1441
1214
  };
1442
1215
  //# sourceMappingURL=index.js.map