@prose-reader/streamer 1.319.0 → 1.320.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.
@@ -1,7 +1,7 @@
1
1
  import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "../createArchiveFromEntries-CNz716dm.js";
2
2
  import { n as s, t as c } from "../fileAccessors-etcCPnpQ.js";
3
3
  import { detectMimeTypeFromName as l, escapeXmlAttributeValue as u, isMediaContentMimeType as d, isXmlBasedMimeType as f, parseContentType as p, urlJoin as m } from "@prose-reader/shared";
4
- import { APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME as h, COMIC_INFO_FILENAME as g, KOBO_DISPLAY_OPTIONS_FILENAME as _, parseAppleDisplayOptionsXml as ee, parseComicInfo as te, parseKoboXml as ne, parseOpf as re, resolveArchiveMetadata as v, tokenizeXmlSpaceSeparatedList as ie } from "@prose-reader/archive-parser";
4
+ import { APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME as h, COMIC_INFO_FILENAME as g, KOBO_DISPLAY_OPTIONS_FILENAME as _, parseAppleDisplayOptionsXml as ee, parseComicInfo as te, parseKoboXml as ne, parseOpf as re, resolveArchiveMetadata as v, tokenizeXmlSpaceSeparatedList as ie } from "@prose-reader/archive-reader";
5
5
  import { XmlDocument as y, XmlElement as ae, XmlTextNode as oe } from "xmldoc";
6
6
  import { BehaviorSubject as se, EMPTY as b, NEVER as x, Subject as S, catchError as C, distinctUntilChanged as ce, filter as w, finalize as le, first as T, from as E, ignoreElements as ue, lastValueFrom as de, map as D, merge as O, mergeMap as k, of as fe, pairwise as pe, shareReplay as me, startWith as he, switchMap as A, takeUntil as ge, tap as j, timer as _e } from "rxjs";
7
7
  //#region src/archives/createArchiveFromArrayBufferList.ts
@@ -158,11 +158,11 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
158
158
  } catch (e) {
159
159
  return console.error(`Unable to parse ${g} for content\n`, i), console.error(e), r;
160
160
  }
161
- }, Ne = ({ baseUrl: e = "", resourcePath: t }) => {
161
+ }, U = ({ baseUrl: e = "", resourcePath: t }) => {
162
162
  if (!e && /^https?:\/\//.test(t)) return encodeURI(t);
163
163
  let n = e ? `${e}${e.endsWith("/") ? "" : "/"}` : "file://";
164
164
  return encodeURI(`${n}${t}`);
165
- }, Pe = ({ archive: e, baseUrl: t }) => async () => {
165
+ }, Ne = ({ archive: e, baseUrl: t }) => async () => {
166
166
  let n = e.records.filter((e) => !e.dir), r = I(), i = n.map((e) => ({
167
167
  file: e,
168
168
  id: r(e.uri)
@@ -176,7 +176,7 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
176
176
  spineItems: i.filter(({ file: e }) => !e.basename.endsWith(".db")).map(({ file: e, id: r }, i) => ({
177
177
  id: r,
178
178
  index: i,
179
- href: Ne({
179
+ href: U({
180
180
  baseUrl: t,
181
181
  resourcePath: e.uri
182
182
  }),
@@ -191,11 +191,11 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
191
191
  href: encodeURI(`${t}${e.uri}`)
192
192
  }))
193
193
  };
194
- }, U = async ({ archive: e, archiveOpf: t }) => {
194
+ }, W = async ({ archive: e, archiveOpf: t }) => {
195
195
  if (!t) return [];
196
196
  let { opf: n, basePath: r } = t, { spineRows: i } = n;
197
197
  return e.records.filter((e) => i.find((t) => r ? `${r}/${t.href}` === e.uri : `${t.href}` === e.uri));
198
- }, W = (e, t, n) => {
198
+ }, G = (e, t, n) => {
199
199
  let { basePath: r } = V(t) || {};
200
200
  return e.map((e) => {
201
201
  let t = e.href, i = n?.(t) ?? "";
@@ -205,25 +205,25 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
205
205
  mediaType: e.mediaType
206
206
  };
207
207
  });
208
- }, Fe = (e) => {
208
+ }, Pe = (e) => {
209
209
  let t = e?.trim();
210
210
  return t === "scrolled-continuous" || t === "scrolled-doc" || t === "paginated" || t === "auto" ? t : "auto";
211
- }, Ie = (e) => {
211
+ }, Fe = (e) => {
212
212
  let t = e?.trim();
213
213
  if (t === "none" || t === "landscape" || t === "portrait" || t === "both" || t === "auto") return t;
214
- }, Le = (e) => {
214
+ }, Ie = (e) => {
215
215
  let t = e?.trim();
216
216
  if (t === "cover" || t === "title-page" || t === "copyright-page" || t === "text") return t;
217
- }, Re = ({ archive: e, baseUrl: t, archiveOpf: n }) => async (r) => {
217
+ }, Le = ({ archive: e, baseUrl: t, archiveOpf: n }) => async (r) => {
218
218
  if (!n) return r;
219
219
  let { opf: i, basePath: o } = n, s = v(i);
220
220
  a.groupCollapsed(...a.getGroupArgs("OPF parsed")), a.log("opf", i), a.groupEnd();
221
- let c = i.renditionLayoutMeta?.trim(), l = c === "reflowable" || c === "pre-paginated" ? c : s.renditionLayout, u = i.title?.trim() || e.records.find(({ dir: e }) => e)?.basename || "", d = s.readingDirection ?? r.readingDirection, f = (await U({
221
+ let c = i.renditionLayoutMeta?.trim(), l = c === "reflowable" || c === "pre-paginated" ? c : s.renditionLayout, u = i.title?.trim() || e.records.find(({ dir: e }) => e)?.basename || "", d = s.readingDirection ?? r.readingDirection, f = (await W({
222
222
  archive: e,
223
223
  archiveOpf: n
224
224
  })).filter(L).reduce((e, t) => t.size + e, 0), p = i.guide, m = [];
225
225
  for (let e of p) {
226
- let t = Le(e.type);
226
+ let t = Ie(e.type);
227
227
  t !== void 0 && m.push({
228
228
  href: e.href,
229
229
  title: e.title,
@@ -233,8 +233,8 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
233
233
  return {
234
234
  filename: e.filename ?? "",
235
235
  renditionLayout: l,
236
- renditionFlow: Fe(i.renditionFlowMeta),
237
- renditionSpread: Ie(i.renditionSpreadMeta),
236
+ renditionFlow: Pe(i.renditionFlowMeta),
237
+ renditionSpread: Fe(i.renditionSpreadMeta),
238
238
  title: u,
239
239
  readingDirection: d,
240
240
  spineItems: i.spineRows.map((n, r) => {
@@ -251,20 +251,20 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
251
251
  mediaType: n.mediaType
252
252
  };
253
253
  }),
254
- items: W(i.manifestItems, e, (e) => /^https?:\/\//.test(e) ? "" : t || "file://"),
254
+ items: G(i.manifestItems, e, (e) => /^https?:\/\//.test(e) ? "" : t || "file://"),
255
255
  guide: m.length > 0 ? m : void 0
256
256
  };
257
- }, ze = (e) => {
257
+ }, Re = (e) => {
258
258
  let t = e.descendantWithPath("head")?.childrenNamed("meta").find((e) => e.attr.name === "viewport");
259
259
  return !!(t && t.attr.name === "viewport");
260
- }, Be = (e) => e.reduce(async (e, t) => {
260
+ }, ze = (e) => e.reduce(async (e, t) => {
261
261
  if (!await e || !f({
262
262
  mimeType: L(t) ? t.encodingFormat : void 0,
263
263
  uri: t.uri
264
264
  })) return !1;
265
265
  let n = t.dir ? null : await B(t);
266
- return n ? ze(new y(n)) : !1;
267
- }, Promise.resolve(!0)), Ve = ({ archive: e, archiveOpf: t }) => async (n) => n.renditionLayout === "reflowable" && n.spineItems.every((e) => e.renditionLayout === "reflowable") && await Be(await U({
266
+ return n ? Re(new y(n)) : !1;
267
+ }, Promise.resolve(!0)), Be = ({ archive: e, archiveOpf: t }) => async (n) => n.renditionLayout === "reflowable" && n.spineItems.every((e) => e.renditionLayout === "reflowable") && await ze(await W({
268
268
  archive: e,
269
269
  archiveOpf: t
270
270
  })) ? {
@@ -274,10 +274,10 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
274
274
  renditionLayout: "pre-paginated"
275
275
  })),
276
276
  renditionLayout: "pre-paginated"
277
- } : n, He = () => (e) => ({
277
+ } : n, Ve = () => (e) => ({
278
278
  ...e,
279
279
  readingDirection: e.readingDirection ?? "ltr"
280
- }), Ue = async (e) => {
280
+ }), He = async (e) => {
281
281
  let t;
282
282
  return await Promise.all(e.records.map(async (e) => {
283
283
  if (e.dir || !e.uri.endsWith(_)) return;
@@ -292,13 +292,13 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
292
292
  kind: "kobo",
293
293
  ...t === void 0 ? {} : { renditionLayout: t }
294
294
  };
295
- }, We = ({ archive: e }) => async (t) => {
296
- let { renditionLayout: n } = v(await Ue(e));
295
+ }, Ue = ({ archive: e }) => async (t) => {
296
+ let { renditionLayout: n } = v(await He(e));
297
297
  return {
298
298
  ...t,
299
299
  renditionLayout: t.renditionLayout ?? n
300
300
  };
301
- }, G = (e) => e.toLowerCase().endsWith(".opf"), Ge = (e) => e.records.some((e) => !e.dir && (G(e.basename) || G(e.uri))), Ke = ({ archive: e }) => async (t) => Ge(e) ? t : {
301
+ }, K = (e) => e.toLowerCase().endsWith(".opf"), We = (e) => e.records.some((e) => !e.dir && (K(e.basename) || K(e.uri))), Ge = ({ archive: e }) => async (t) => We(e) ? t : {
302
302
  ...t,
303
303
  spineItems: t.spineItems.map((t) => {
304
304
  let n = e.records.find((e) => decodeURI(t.href).endsWith(e.uri)), r = p((n && L(n) ? n.encodingFormat : void 0) ?? "") || l(n?.basename ?? "");
@@ -307,96 +307,96 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
307
307
  renditionLayout: r && d(r) ? "pre-paginated" : t.renditionLayout
308
308
  };
309
309
  })
310
- }, K = (e) => e ? e.children.map((e) => e instanceof oe ? e.text : e instanceof ae ? K(e) : "").join("").trim() : "", qe = (e) => ie(e.properties).includes("nav"), q = (e, { basePath: t, baseUrl: n }) => {
310
+ }, q = (e) => e ? e.children.map((e) => e instanceof oe ? e.text : e instanceof ae ? q(e) : "").join("").trim() : "", Ke = (e) => ie(e.properties).includes("nav"), J = (e, { basePath: t, baseUrl: n }) => {
311
311
  let r = {
312
312
  contents: [],
313
313
  path: "",
314
314
  href: "",
315
315
  title: ""
316
316
  }, i = e.childNamed("span") || e.childNamed("a");
317
- r.title = (i?.attr.title || i?.val.trim() || K(i)) ?? "";
317
+ r.title = (i?.attr.title || i?.val.trim() || q(i)) ?? "";
318
318
  let a = i?.name;
319
319
  a !== "a" && (i = e.descendantWithPath(`${a}.a`), i && (a = i.name.toLowerCase())), a === "a" && i?.attr.href && (r.path = m(t, i.attr.href), r.href = m(n, t, i.attr.href));
320
320
  let o = e.childNamed("ol");
321
321
  if (o) {
322
322
  let e = o.childrenNamed("li");
323
- e && e.length > 0 && (r.contents = e.map((e) => q(e, {
323
+ e && e.length > 0 && (r.contents = e.map((e) => J(e, {
324
324
  basePath: t,
325
325
  baseUrl: n
326
326
  })));
327
327
  }
328
328
  return r;
329
- }, Je = (e, { basePath: t, baseUrl: n }) => {
329
+ }, qe = (e, { basePath: t, baseUrl: n }) => {
330
330
  let r = [], i;
331
331
  return e.descendantWithPath("body.nav.ol") ? i = e.descendantWithPath("body.nav.ol")?.children : e.descendantWithPath("body.section.nav.ol") && (i = e.descendantWithPath("body.section.nav.ol")?.children), i && i.length > 0 && i.filter((e) => e.name === "li").forEach((e) => {
332
- r.push(q(e, {
332
+ r.push(J(e, {
333
333
  basePath: t,
334
334
  baseUrl: n
335
335
  }));
336
336
  }), r;
337
- }, Ye = async (e, t, { baseUrl: r }) => {
338
- let i = e.manifestItems.find(qe);
337
+ }, Je = async (e, t, { baseUrl: r }) => {
338
+ let i = e.manifestItems.find(Ke);
339
339
  if (i?.href) {
340
340
  let e = t.records.find((e) => e.uri.endsWith(i.href));
341
- if (e && !e.dir) return Je(new y(await B(e)), {
341
+ if (e && !e.dir) return qe(new y(await B(e)), {
342
342
  basePath: n(e.uri),
343
343
  baseUrl: r
344
344
  });
345
345
  }
346
- }, J = (e, { opfBasePath: t, baseUrl: n, prefix: r }) => {
346
+ }, Y = (e, { opfBasePath: t, baseUrl: n, prefix: r }) => {
347
347
  let i = e?.childNamed(`${r}content`)?.attr.src || "", a = {
348
348
  title: e?.descendantWithPath(`${r}navLabel.${r}text`)?.val || "",
349
349
  path: m(t, i),
350
350
  href: m(n, t, i),
351
351
  contents: []
352
352
  }, o = e.childrenNamed(`${r}navPoint`);
353
- return o && o.length > 0 && (a.contents = o.map((e) => J(e, {
353
+ return o && o.length > 0 && (a.contents = o.map((e) => Y(e, {
354
354
  opfBasePath: t,
355
355
  baseUrl: n,
356
356
  prefix: r
357
357
  }))), a;
358
- }, Xe = (e, { opfBasePath: t, baseUrl: n }) => {
358
+ }, Ye = (e, { opfBasePath: t, baseUrl: n }) => {
359
359
  let r = [], i = e.name, a = "";
360
360
  return i.indexOf(":") !== -1 && (a = `${i.split(":")[0]}:`), e.childNamed(`${a}navMap`)?.childrenNamed(`${a}navPoint`).forEach((e) => {
361
- r.push(J(e, {
361
+ r.push(Y(e, {
362
362
  opfBasePath: t,
363
363
  baseUrl: n,
364
364
  prefix: a
365
365
  }));
366
366
  }), r;
367
- }, Ze = async ({ opf: e, opfBasePath: t, baseUrl: n, archive: r }) => {
367
+ }, Xe = async ({ opf: e, opfBasePath: t, baseUrl: n, archive: r }) => {
368
368
  let i = e.spineTocIdref;
369
369
  if (i) {
370
370
  let a = e.manifestItems.find((e) => e.id === i);
371
371
  if (a) {
372
372
  let e = `${t}${t === "" ? "" : "/"}${a.href}`, i = r.records.find((t) => t.uri.endsWith(e));
373
- if (i && !i.dir) return Xe(new y(await B(i)), {
373
+ if (i && !i.dir) return Ye(new y(await B(i)), {
374
374
  opfBasePath: t,
375
375
  baseUrl: n
376
376
  });
377
377
  }
378
378
  }
379
- }, Qe = async (e, t, { baseUrl: n }) => {
380
- let { basePath: r } = V(t) || {}, i = await Ye(e, t, { baseUrl: n });
379
+ }, Ze = async (e, t, { baseUrl: n }) => {
380
+ let { basePath: r } = V(t) || {}, i = await Je(e, t, { baseUrl: n });
381
381
  if (i) return i;
382
- let a = await Ze({
382
+ let a = await Xe({
383
383
  opf: e,
384
384
  opfBasePath: r ?? "",
385
385
  archive: t,
386
386
  baseUrl: n
387
387
  });
388
388
  if (a) return a;
389
- }, $e = (e) => e.replace(/\.[^.]+$/, "").replace(/[_-]/g, " ").replace(/\s+/g, " ").trim(), et = (e, t) => {
389
+ }, Qe = (e) => e.replace(/\.[^.]+$/, "").replace(/[_-]/g, " ").replace(/\s+/g, " ").trim(), $e = (e, t) => {
390
390
  if (e.spineItems.length !== 0 && e.spineItems.every((e) => (p(e.mediaType ?? "") || l(e.href))?.startsWith("audio/"))) return e.spineItems.map((e) => {
391
391
  let n = t.records.find((t) => !t.dir && decodeURI(e.href).endsWith(t.uri));
392
392
  return {
393
- title: $e(n?.basename ?? e.href),
393
+ title: Qe(n?.basename ?? e.href),
394
394
  href: e.href,
395
395
  path: n?.uri ?? e.href,
396
396
  contents: []
397
397
  };
398
398
  });
399
- }, tt = (t, { baseUrl: n }) => {
399
+ }, et = (t, { baseUrl: n }) => {
400
400
  let r = [...t.records].sort((t, n) => e(t.uri, n.uri)), i = (e, t, n, r, a) => {
401
401
  let o = e.find((e) => e.title === t), [s, ...c] = n;
402
402
  return o ? s ? [...e.filter((e) => e !== o), {
@@ -425,15 +425,15 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
425
425
  let o = m(n, encodeURI(t.uri)).replace(/\/$/, ""), s = t.uri.replace(/\/$/, "");
426
426
  return i(e, r, a, o, s);
427
427
  }, []);
428
- }, nt = async (e, t, { baseUrl: n, archiveOpf: r }) => {
429
- if (r) return await Qe(r.opf, e, { baseUrl: n }) || [];
430
- let i = et(t, e);
428
+ }, tt = async (e, t, { baseUrl: n, archiveOpf: r }) => {
429
+ if (r) return await Ze(r.opf, e, { baseUrl: n }) || [];
430
+ let i = $e(t, e);
431
431
  if (i) return i;
432
- let a = tt(e, { baseUrl: n });
432
+ let a = et(e, { baseUrl: n });
433
433
  if (a.length !== 0) return a;
434
- }, rt = ({ archive: e, baseUrl: t, archiveOpf: n }) => async (r) => {
434
+ }, nt = ({ archive: e, baseUrl: t, archiveOpf: n }) => async (r) => {
435
435
  if (r.nav) return r;
436
- let i = await nt(e, r, {
436
+ let i = await tt(e, r, {
437
437
  baseUrl: t,
438
438
  archiveOpf: n
439
439
  });
@@ -441,13 +441,13 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
441
441
  ...r,
442
442
  nav: { toc: i }
443
443
  } : r;
444
- }, it = (e) => e ? e.endsWith("/") ? e : `${e}/` : "", Y = async (e, { baseUrl: t = "", hooks: n = {} } = {}) => {
444
+ }, rt = (e) => e ? e.endsWith("/") ? e : `${e}/` : "", X = async (e, { baseUrl: t = "", hooks: n = {} } = {}) => {
445
445
  a.log("Generating manifest from archive", e);
446
- let r = await H(e), i = it(t), o = (t) => (t ?? []).map((t) => t({
446
+ let r = await H(e), i = rt(t), o = (t) => (t ?? []).map((t) => t({
447
447
  archive: e,
448
448
  baseUrl: i
449
449
  })), s = [
450
- Re({
450
+ Le({
451
451
  archive: e,
452
452
  baseUrl: i,
453
453
  archiveOpf: r
@@ -460,23 +460,23 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
460
460
  archive: e,
461
461
  baseUrl: i
462
462
  }),
463
- Ke({
463
+ Ge({
464
464
  archive: e,
465
465
  baseUrl: i
466
466
  }),
467
467
  ...o(n.content)
468
468
  ], c = o(n.spine), l = [
469
- Ve({
469
+ Be({
470
470
  archive: e,
471
471
  baseUrl: i,
472
472
  archiveOpf: r
473
473
  }),
474
- We({
474
+ Ue({
475
475
  archive: e,
476
476
  baseUrl: i
477
477
  }),
478
478
  ...o(n.presentation)
479
- ], u = [rt({
479
+ ], u = [nt({
480
480
  archive: e,
481
481
  baseUrl: i,
482
482
  archiveOpf: r
@@ -485,10 +485,10 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
485
485
  ...c,
486
486
  ...l,
487
487
  ...u,
488
- He()
488
+ Ve()
489
489
  ];
490
490
  try {
491
- let t = Pe({
491
+ let t = Ne({
492
492
  archive: e,
493
493
  baseUrl: i
494
494
  })(), n = await d.reduce(async (e, t) => await t(await e), t);
@@ -500,15 +500,15 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
500
500
  } catch (e) {
501
501
  throw a.error(e), e;
502
502
  }
503
- }, at = (e) => {
503
+ }, it = (e) => {
504
504
  let t = e.descendantWithPath("head")?.childrenNamed("meta").find((e) => e.attr.name === "calibre:cover");
505
505
  return !!(t && t.attr.name === "calibre:cover");
506
- }, ot = (e) => e.descendantWithPath("body")?.descendantWithPath("div")?.childrenNamed("svg")?.find((e) => e.attr.width === "100%" && e.attr.preserveAspectRatio === "none"), st = ({ archive: e, resourcePath: t }) => async (n) => {
506
+ }, at = (e) => e.descendantWithPath("body")?.descendantWithPath("div")?.childrenNamed("svg")?.find((e) => e.attr.width === "100%" && e.attr.preserveAspectRatio === "none"), ot = ({ archive: e, resourcePath: t }) => async (n) => {
507
507
  let r = R(e, t);
508
508
  if (r?.basename.endsWith(".xhtml")) {
509
509
  let e = new y(typeof n.body == "string" ? n.body : await B(r));
510
- if (at(e)) {
511
- let t = ot(e);
510
+ if (it(e)) {
511
+ let t = at(e);
512
512
  return t && delete t.attr.preserveAspectRatio, {
513
513
  ...n,
514
514
  body: e?.toString()
@@ -516,10 +516,10 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
516
516
  }
517
517
  }
518
518
  return n;
519
- }, ct = ({ archive: e, resourcePath: t }) => async (n) => st({
519
+ }, st = ({ archive: e, resourcePath: t }) => async (n) => ot({
520
520
  archive: e,
521
521
  resourcePath: t
522
- })(n), lt = ({ archive: e, resourcePath: t }) => async (n) => {
522
+ })(n), ct = ({ archive: e, resourcePath: t }) => async (n) => {
523
523
  let r = R(e, t);
524
524
  if (r?.basename.endsWith(".css")) {
525
525
  let e = (typeof n.body == "string" ? n.body : await B(r)).replaceAll("-webkit-writing-mode", "writing-mode");
@@ -529,23 +529,23 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
529
529
  };
530
530
  }
531
531
  return n;
532
- }, ut = async (e, t) => {
532
+ }, lt = async (e, t) => {
533
533
  let n = await H(e);
534
534
  if (n) {
535
- let { opf: r } = n, i = W(r.manifestItems, e, () => "").find((e) => t.endsWith(e.href))?.mediaType;
535
+ let { opf: r } = n, i = G(r.manifestItems, e, () => "").find((e) => t.endsWith(e.href))?.mediaType;
536
536
  if (i) return { mediaType: i };
537
537
  }
538
- return { mediaType: dt(t) };
539
- }, dt = (e) => {
538
+ return { mediaType: ut(t) };
539
+ }, ut = (e) => {
540
540
  if (e.endsWith(".css")) return "text/css; charset=UTF-8";
541
541
  if (e.endsWith(".jpg")) return "image/jpg";
542
542
  if (e.endsWith(".xhtml")) return "application/xhtml+xml";
543
543
  if (e.endsWith(".mp4")) return "video/mp4";
544
544
  if (e.endsWith(".svg")) return "image/svg+xml";
545
- }, ft = ({ archive: e, resourcePath: t }) => async (n) => {
545
+ }, dt = ({ archive: e, resourcePath: t }) => async (n) => {
546
546
  let r = R(e, t);
547
547
  if (!r) return n;
548
- let i = await ut(e, t);
548
+ let i = await lt(e, t);
549
549
  return {
550
550
  ...n,
551
551
  params: {
@@ -554,37 +554,37 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
554
554
  ...i.mediaType && { contentType: i.mediaType }
555
555
  }
556
556
  };
557
- }, X = /* @__PURE__ */ "div.span.p.a.li.ul.ol.h1.h2.h3.h4.h5.h6.table.tr.td.th.thead.tbody.tfoot.section.article.header.footer.nav.aside.main.figure.figcaption.blockquote.pre.code.form.textarea.select.option.button.label.fieldset.legend.caption.dl.dt.dd.iframe.video.audio.canvas.script.style".split("."), pt = ({ archive: e, resourcePath: t }) => async (n) => {
557
+ }, Z = /* @__PURE__ */ "div.span.p.a.li.ul.ol.h1.h2.h3.h4.h5.h6.table.tr.td.th.thead.tbody.tfoot.section.article.header.footer.nav.aside.main.figure.figcaption.blockquote.pre.code.form.textarea.select.option.button.label.fieldset.legend.caption.dl.dt.dd.iframe.video.audio.canvas.script.style".split("."), ft = ({ archive: e, resourcePath: t }) => async (n) => {
558
558
  let r = R(e, t);
559
559
  if (r?.basename.endsWith(".xhtml")) {
560
560
  let e = typeof n.body == "string" ? n.body : await B(r);
561
- if (!RegExp(`<(${X.join("|")})[\\s/>]`, "i").test(e)) return n;
562
- let t = RegExp(`<(${X.join("|")})(\\s[^>]*)?\\s*/>`, "gi"), i = e.replace(t, (e, t, n = "") => `<${t} ${n.trim()}></${t}>`);
561
+ if (!RegExp(`<(${Z.join("|")})[\\s/>]`, "i").test(e)) return n;
562
+ let t = RegExp(`<(${Z.join("|")})(\\s[^>]*)?\\s*/>`, "gi"), i = e.replace(t, (e, t, n = "") => `<${t} ${n.trim()}></${t}>`);
563
563
  return {
564
564
  ...n,
565
565
  body: i
566
566
  };
567
567
  }
568
568
  return n;
569
- }, Z = async (e, t, { hooks: n = [] } = {}) => {
569
+ }, Q = async (e, t, { hooks: n = [] } = {}) => {
570
570
  let r = { params: {} }, i = [
571
571
  ...n.map((n) => n({
572
572
  archive: e,
573
573
  resourcePath: t
574
574
  })),
575
- ft({
575
+ dt({
576
576
  archive: e,
577
577
  resourcePath: t
578
578
  }),
579
- pt({
579
+ ft({
580
580
  archive: e,
581
581
  resourcePath: t
582
582
  }),
583
- lt({
583
+ ct({
584
584
  archive: e,
585
585
  resourcePath: t
586
586
  }),
587
- ct({
587
+ st({
588
588
  archive: e,
589
589
  resourcePath: t
590
590
  })
@@ -601,7 +601,7 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
601
601
  } catch (e) {
602
602
  throw a.error(e), e;
603
603
  }
604
- }, mt = class {
604
+ }, pt = class {
605
605
  constructor(e) {
606
606
  this.cleanArchiveAfter = e, this.state$ = new se({
607
607
  status: "idle",
@@ -626,7 +626,7 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
626
626
  get overTTL$() {
627
627
  return this.isUnlocked$.pipe(A((e) => e ? this.cleanArchiveAfter === Infinity ? x : _e(this.cleanArchiveAfter) : x));
628
628
  }
629
- }, ht = ({ getArchive: e, cleanArchiveAfter: t = 300 * 1e3 }) => {
629
+ }, mt = ({ getArchive: e, cleanArchiveAfter: t = 300 * 1e3 }) => {
630
630
  let n = new S(), r = new S(), i = new S(), o = {};
631
631
  return n.pipe(k((t) => {
632
632
  let n = o[t];
@@ -651,7 +651,7 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
651
651
  }))));
652
652
  }), ge(r)).subscribe(), {
653
653
  access: (e) => {
654
- let r = !1, i = o[e] ?? new mt(t);
654
+ let r = !1, i = o[e] ?? new pt(t);
655
655
  o[e] = i, i.update({ locks: i.state.locks + 1 });
656
656
  let a = () => {
657
657
  r || (r = !0, i.update({ locks: i.state.locks - 1 }));
@@ -670,7 +670,7 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
670
670
  },
671
671
  _archives: o
672
672
  };
673
- }, Q = (e) => e ? /^\d+$/.test(e) ? {
673
+ }, $ = (e) => e ? /^\d+$/.test(e) ? {
674
674
  valid: !0,
675
675
  value: Number.parseInt(e, 10)
676
676
  } : {
@@ -679,20 +679,20 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
679
679
  } : {
680
680
  valid: !0,
681
681
  value: void 0
682
- }, gt = (e) => {
682
+ }, ht = (e) => {
683
683
  if (!e.toLowerCase().startsWith("bytes=")) return { kind: "missing" };
684
684
  let t = e.slice(6).trim();
685
685
  if (!t) return { kind: "invalid" };
686
686
  if (t.includes(",")) return { kind: "multi" };
687
687
  let n = /^(\d*)-(\d*)$/.exec(t);
688
688
  if (!n) return { kind: "invalid" };
689
- let [, r = "", i = ""] = n, a = Q(r.trim()), o = Q(i.trim());
689
+ let [, r = "", i = ""] = n, a = $(r.trim()), o = $(i.trim());
690
690
  return !a.valid || !o.valid ? { kind: "invalid" } : {
691
691
  kind: "single",
692
692
  start: a.value,
693
693
  end: o.value
694
694
  };
695
- }, _t = (e) => {
695
+ }, gt = (e) => {
696
696
  if (e instanceof Blob) return {
697
697
  size: e.size,
698
698
  slice: (t, n) => {
@@ -714,18 +714,18 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
714
714
  };
715
715
  }
716
716
  };
717
- }, vt = ({ body: e, contentType: t, rangeHeader: n }) => {
717
+ }, _t = ({ body: e, contentType: t, rangeHeader: n }) => {
718
718
  let r = new Headers();
719
719
  if (t && r.set("Content-Type", t), r.set("Accept-Ranges", "bytes"), !n) return e instanceof Blob && r.set("Content-Length", String(e.size)), new Response(e, {
720
720
  status: 200,
721
721
  headers: r
722
722
  });
723
- let i = gt(n);
723
+ let i = ht(n);
724
724
  if (i.kind === "missing" || i.kind === "multi") return e instanceof Blob && r.set("Content-Length", String(e.size)), new Response(e, {
725
725
  status: 200,
726
726
  headers: r
727
727
  });
728
- let a = _t(e), o = a.size;
728
+ let a = gt(e), o = a.size;
729
729
  if (i.kind === "invalid") return new Response(null, {
730
730
  status: 416,
731
731
  headers: { "Content-Range": `bytes */${o}` }
@@ -740,18 +740,18 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
740
740
  status: 206,
741
741
  headers: r
742
742
  });
743
- }, $ = "file://", yt = /^https?:\/\//, bt = (e) => {
743
+ }, vt = "file://", yt = /^https?:\/\//, bt = (e) => {
744
744
  try {
745
745
  return decodeURIComponent(e);
746
746
  } catch {
747
747
  return e;
748
748
  }
749
- }, xt = (e) => e.startsWith($) ? e.slice($.length) : e, St = (e) => {
749
+ }, xt = (e) => e.startsWith(vt) ? e.slice(vt.length) : e, St = (e) => {
750
750
  let t = xt(e);
751
751
  return yt.test(t) ? t : xt(bt(t));
752
752
  }, Ct = class {
753
753
  constructor({ hooks: e, onError: t, onManifestSuccess: n, ...r }) {
754
- this.onError = (e) => (console.error(e), new Response(String(e), { status: 500 })), this.archiveLoader = ht(r), this.hooks = e ?? {}, this.onManifestSuccess = n ?? (({ manifest: e }) => Promise.resolve(e)), this.onError = t ?? this.onError;
754
+ this.onError = (e) => (console.error(e), new Response(String(e), { status: 500 })), this.archiveLoader = mt(r), this.hooks = e ?? {}, this.onManifestSuccess = n ?? (({ manifest: e }) => Promise.resolve(e)), this.onError = t ?? this.onError;
755
755
  }
756
756
  prune() {
757
757
  this.archiveLoader.purge();
@@ -770,7 +770,7 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
770
770
  fetchManifest({ key: e, baseUrl: t }) {
771
771
  return this.withArchiveResponse({
772
772
  key: e,
773
- getResponse: (e) => E(Y(e, {
773
+ getResponse: (e) => E(X(e, {
774
774
  baseUrl: t,
775
775
  hooks: this.hooks.manifest
776
776
  })).pipe(A((t) => E(this.onManifestSuccess({
@@ -782,7 +782,7 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
782
782
  fetchResource({ key: e, resourcePath: t, request: n }) {
783
783
  return this.withArchiveResponse({
784
784
  key: e,
785
- getResponse: (e) => E(Z(e, St(t), { hooks: this.hooks.resource })).pipe(D((e) => vt({
785
+ getResponse: (e) => E(Q(e, St(t), { hooks: this.hooks.resource })).pipe(D((e) => _t({
786
786
  body: e.body ?? "",
787
787
  contentType: e.params.contentType,
788
788
  rangeHeader: n?.headers.get("range")
@@ -812,6 +812,6 @@ var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
812
812
  }
813
813
  };
814
814
  //#endregion
815
- export { wt as ServiceWorkerStreamer, Ct as Streamer, c as arrayBufferFileAccessors, s as blobFileAccessors, Oe as configure, r as createArchive, ve as createArchiveFromArrayBufferList, o as createArchiveFromEntries, ye as createArchiveFromText, Te as createArchiveFromUrls, F as createUniqueXmlSafeId, P as createXmlSafeId, I as createXmlSafeIdFactory, Y as generateManifestFromArchive, Z as generateResourceFromArchive, R as getArchiveFileRecordByUri, z as getArchiveHasComicInfo, V as getArchiveOpfInfo, n as getUriBasePath, i as getUriBasename, Ee as isDirectoryRecord, L as isFileRecord, B as readRecordAsText, t as removeTrailingSlash, e as sortByTitleComparator };
815
+ export { wt as ServiceWorkerStreamer, Ct as Streamer, c as arrayBufferFileAccessors, s as blobFileAccessors, Oe as configure, r as createArchive, ve as createArchiveFromArrayBufferList, o as createArchiveFromEntries, ye as createArchiveFromText, Te as createArchiveFromUrls, U as createManifestResourceHref, F as createUniqueXmlSafeId, P as createXmlSafeId, I as createXmlSafeIdFactory, X as generateManifestFromArchive, Q as generateResourceFromArchive, R as getArchiveFileRecordByUri, z as getArchiveHasComicInfo, V as getArchiveOpfInfo, n as getUriBasePath, i as getUriBasename, Ee as isDirectoryRecord, L as isFileRecord, B as readRecordAsText, t as removeTrailingSlash, e as sortByTitleComparator };
816
816
 
817
817
  //# sourceMappingURL=index.js.map