@prose-reader/streamer 1.300.0 → 1.301.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,22 +1,22 @@
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) => {
1
+ import { detectMimeTypeFromName as b, Report as ae, escapeXmlAttributeValue as _, isXmlBasedMimeType as ce, parseContentType as J, isMediaContentMimeType as de, urlJoin as I } from "@prose-reader/shared";
2
+ import { parseOpf as le, APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME as Z, parseAppleDisplayOptionsXml as ue, resolveArchiveMetadata as S, COMIC_INFO_FILENAME as Y, parseComicInfo as pe, KOBO_DISPLAY_OPTIONS_FILENAME as N, parseKoboXml as fe, tokenizeXmlSpaceSeparatedList as me } from "@prose-reader/archive-parser";
3
+ import { XmlDocument as R, XmlTextNode as he, XmlElement as ge } from "xmldoc";
4
+ import { Subject as x, mergeMap as Q, EMPTY as z, pairwise as ye, filter as E, startWith as be, from as F, tap as k, catchError as C, switchMap as T, merge as O, first as M, takeUntil as ve, map as $, ignoreElements as we, BehaviorSubject as $e, distinctUntilChanged as Ae, shareReplay as Fe, NEVER as B, timer as Te, finalize as Ie, of as Se, lastValueFrom as Re } from "rxjs";
5
+ const W = (e, t) => {
6
6
  const o = e.split(/(\d+)/), r = t.split(/(\d+)/);
7
7
  for (let n = 0, s = o.length; n < s; n++)
8
8
  if (o[n] !== r[n])
9
9
  return o[n]?.match(/\d/) ? +(o[n] || "") - +(r[n] || "") : (o[n] || "").localeCompare(r[n] || "");
10
10
  return 1;
11
- }, b = (e) => e.substring(e.lastIndexOf("/") + 1) || e, j = (e) => e.endsWith("/") ? e.slice(0, -1) : e, Ae = (e) => {
11
+ }, A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, j = (e) => e.endsWith("/") ? e.slice(0, -1) : e, Le = (e) => {
12
12
  const t = e.lastIndexOf("/");
13
13
  return t >= 0 ? e.substring(0, t) : "";
14
- }, Lt = async (e, { orderByAlpha: t, name: o } = {}) => {
14
+ }, Nt = async (e, { orderByAlpha: t, name: o } = {}) => {
15
15
  let r = e;
16
- return t && (r = r.slice().sort((n, s) => E(n.name, s.name))), {
16
+ return t && (r = r.slice().sort((n, s) => W(n.name, s.name))), {
17
17
  filename: o || "",
18
18
  records: r.map((n) => {
19
- const s = n.size, i = b(n.name);
19
+ const s = n.size, i = A(n.name);
20
20
  return n.isDir ? {
21
21
  dir: !0,
22
22
  basename: i,
@@ -25,10 +25,10 @@ const E = (e, t) => {
25
25
  } : {
26
26
  dir: n.isDir,
27
27
  basename: i,
28
- encodingFormat: v(n.name),
28
+ encodingFormat: b(n.name),
29
29
  uri: n.name,
30
30
  blob: async () => new Blob([await n.data()], {
31
- type: v(n.name) ?? ""
31
+ type: b(n.name) ?? ""
32
32
  }),
33
33
  string: async () => {
34
34
  const a = await n.data();
@@ -42,9 +42,9 @@ const E = (e, t) => {
42
42
  }),
43
43
  close: () => Promise.resolve()
44
44
  };
45
- }, Le = "@prose-reader/streamer", f = re.namespace(Le, !1, {
45
+ }, xe = "@prose-reader/streamer", f = ae.namespace(xe, !1, {
46
46
  color: "#ffae42"
47
- }), Ie = (e) => {
47
+ }), Ee = (e) => {
48
48
  const t = {};
49
49
  for (const r of e) {
50
50
  const n = r.split("/");
@@ -55,19 +55,19 @@ const E = (e, t) => {
55
55
  }
56
56
  }
57
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}`;
58
+ const c = i === a.length - 1, d = n + (c ? "└── " : "├── "), u = n + (c ? " " : "│ "), p = r[s];
59
+ return p && Object.keys(p).length > 0 ? `${d}${s}/
60
+ ${o(p, u)}` : `${d}${s}`;
61
61
  }).join(`
62
62
  `);
63
63
  return o(t);
64
- }, It = async (e, { orderByAlpha: t, name: o } = {}) => {
64
+ }, zt = async (e, { orderByAlpha: t, name: o } = {}) => {
65
65
  let r = Object.values(e.files);
66
- t && (r = r.slice().sort((s, i) => E(s.name, i.name)));
66
+ t && (r = r.slice().sort((s, i) => W(s.name, i.name)));
67
67
  const n = {
68
68
  filename: o || "",
69
69
  records: r.map((s) => {
70
- const i = s._data.uncompressedSize, a = b(s.name);
70
+ const i = s._data.uncompressedSize, a = A(s.name);
71
71
  return s.dir ? {
72
72
  dir: !0,
73
73
  basename: a,
@@ -75,9 +75,9 @@ ${o(u, p)}` : `${l}${s}`;
75
75
  size: i
76
76
  } : {
77
77
  dir: !1,
78
- basename: b(s.name),
78
+ basename: A(s.name),
79
79
  uri: s.name,
80
- encodingFormat: v(s.name),
80
+ encodingFormat: b(s.name),
81
81
  blob: () => s.async("blob"),
82
82
  string: () => s.async("string"),
83
83
  ...s.internalStream && {
@@ -91,19 +91,19 @@ ${o(u, p)}` : `${l}${s}`;
91
91
  close: () => Promise.resolve()
92
92
  };
93
93
  if (f.log("Generated archive", n), process.env.NODE_ENV === "development" && f.isEnabled()) {
94
- const s = Ie(r.map((i) => i.name));
94
+ const s = Ee(r.map((i) => i.name));
95
95
  f.groupCollapsed(...f.getGroupArgs("Archive folder structure")), f.log(`
96
96
  ${s}`), f.groupEnd();
97
97
  }
98
98
  return n;
99
- }, Rt = async (e, { name: t } = {}) => {
99
+ }, Ot = async (e, { name: t } = {}) => {
100
100
  const o = await e.getFilesArray(), r = {
101
101
  close: () => e.close(),
102
102
  filename: t ?? "",
103
103
  records: o.map((n) => ({
104
104
  dir: !1,
105
105
  basename: n.file.name,
106
- encodingFormat: v(n.file.name),
106
+ encodingFormat: b(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(),
@@ -111,7 +111,7 @@ ${s}`), f.groupEnd();
111
111
  }))
112
112
  };
113
113
  return f.log("Generated archive", r), r;
114
- }, Tt = async (e, {
114
+ }, Mt = async (e, {
115
115
  mimeType: t,
116
116
  direction: o
117
117
  } = { mimeType: "text/plain" }) => {
@@ -136,7 +136,7 @@ ${s}`), f.groupEnd();
136
136
  records: [
137
137
  {
138
138
  dir: !1,
139
- basename: b("generated.opf"),
139
+ basename: A("generated.opf"),
140
140
  uri: "generated.opf",
141
141
  blob: async () => new Blob([r]),
142
142
  string: async () => r,
@@ -144,7 +144,7 @@ ${s}`), f.groupEnd();
144
144
  },
145
145
  {
146
146
  dir: !1,
147
- basename: b("p01.txt"),
147
+ basename: A("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,31 +154,53 @@ ${s}`), f.groupEnd();
154
154
  ],
155
155
  close: () => Promise.resolve()
156
156
  };
157
- }, St = async (e, t) => {
158
- const o = `
157
+ }, ke = /^[A-Za-z0-9_][A-Za-z0-9_.-]*$/, Ce = /^[A-Za-z0-9_]/, D = /^xml/i, We = /[^A-Za-z0-9_.-]+/g, U = "_", Pe = (e) => e.replace(/^_+|_+$/g, ""), _e = (e) => Pe(
158
+ e.trim().replaceAll("/", "_").replace(We, "_")
159
+ ), Ne = (e) => {
160
+ if (ke.test(e) && !D.test(e))
161
+ return e;
162
+ const t = _e(e), o = t && !D.test(t) ? t : `${U}${t}`;
163
+ return Ce.test(o) ? o : `${U}${o}`;
164
+ }, ze = (e, t) => {
165
+ const o = Ne(e);
166
+ if (!t.has(o))
167
+ return t.add(o), o;
168
+ let r = 2, n = `${o}-${r}`;
169
+ for (; t.has(n); )
170
+ r += 1, n = `${o}-${r}`;
171
+ return t.add(n), n;
172
+ }, ee = () => {
173
+ const e = /* @__PURE__ */ new Set();
174
+ return (t) => ze(t, e);
175
+ }, Bt = async (e, t) => {
176
+ const o = ee(), r = e.map((a) => ({
177
+ id: o(a),
178
+ url: a
179
+ })), n = `
159
180
  <?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
160
181
  <metadata>
161
182
  <meta property="rendition:layout">${t?.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
162
183
  ${t?.useRenditionFlow ? '<meta property="rendition:flow">scrolled-continuous</meta>' : ""}
163
184
  </metadata>
164
185
  <manifest>
165
- ${e.map(
166
- (s) => `<item id="${b(s)}" href="${s}" media-type="${v(s)}"/>`
167
- ).join(`
186
+ ${r.map(({ id: a, url: c }) => {
187
+ const d = b(c);
188
+ return `<item id="${a}" href="${_(c)}" media-type="${_(d ?? "")}"/>`;
189
+ }).join(`
168
190
  `)}
169
191
  </manifest>
170
192
  <spine>
171
- ${e.map((s) => `<itemref idref="${b(s)}" />`).join(`
193
+ ${r.map(({ id: a }) => `<itemref idref="${a}" />`).join(`
172
194
  `)}
173
195
  </spine>
174
196
  </package>
175
- `, r = e.map((s) => ({
197
+ `, s = e.map((a) => ({
176
198
  dir: !1,
177
- basename: b(s),
178
- encodingFormat: v(s),
179
- uri: s,
199
+ basename: A(a),
200
+ encodingFormat: b(a),
201
+ uri: a,
180
202
  size: 100 / e.length,
181
- blob: async () => (await fetch(s)).blob(),
203
+ blob: async () => (await fetch(a)).blob(),
182
204
  string: async () => ""
183
205
  }));
184
206
  return {
@@ -189,11 +211,11 @@ ${s}`), f.groupEnd();
189
211
  uri: "content.opf",
190
212
  size: 0,
191
213
  blob: async () => new Blob(),
192
- string: async () => o
193
- }, ...r],
214
+ string: async () => n
215
+ }, ...s],
194
216
  close: () => Promise.resolve()
195
217
  };
196
- }, kt = ({
218
+ }, jt = ({
197
219
  enableReport: e
198
220
  } = {}) => {
199
221
  f.enable(!!e);
@@ -206,65 +228,65 @@ ${s}`), f.groupEnd();
206
228
  basePath: o?.uri.substring(0, o.uri.lastIndexOf("/")) || ""
207
229
  };
208
230
  };
209
- async function Y(e) {
231
+ async function te(e) {
210
232
  const { data: t, basePath: o } = P(e) || {};
211
233
  if (!t || t.dir)
212
234
  return;
213
235
  const r = await t.string();
214
236
  return {
215
- opf: ie(r),
237
+ opf: le(r),
216
238
  basePath: o
217
239
  };
218
240
  }
219
- const Re = K.toLowerCase(), Te = ({ archive: e }) => async (t) => {
241
+ const Oe = Z.toLowerCase(), Me = ({ archive: e }) => async (t) => {
220
242
  const o = e.records.find(
221
- (n) => !n.dir && n.basename.toLowerCase() === Re
243
+ (n) => !n.dir && n.basename.toLowerCase() === Oe
222
244
  );
223
245
  if (!o || o.dir)
224
246
  return t;
225
247
  const r = await o.string();
226
248
  try {
227
- const n = ae(r), { renditionLayout: s } = I(n);
249
+ const n = ue(r), { renditionLayout: s } = S(n);
228
250
  return {
229
251
  ...t,
230
252
  renditionLayout: t.renditionLayout ?? s
231
253
  };
232
254
  } catch (n) {
233
255
  return console.error(
234
- `Unable to parse ${K} for content
256
+ `Unable to parse ${Z} for content
235
257
  `,
236
258
  r
237
259
  ), console.error(n), t;
238
260
  }
239
- }, U = q.toLowerCase(), Se = ({ archive: e }) => async (t) => {
261
+ }, H = Y.toLowerCase(), Be = ({ archive: e }) => async (t) => {
240
262
  const o = e.records.find(
241
- (s) => s.basename.toLowerCase() === U && !s.dir
263
+ (s) => s.basename.toLowerCase() === H && !s.dir
242
264
  );
243
265
  if (!o || o.dir)
244
266
  return t;
245
267
  const r = {
246
268
  ...t,
247
269
  spineItems: t.spineItems.filter(
248
- (s) => !s.id.toLowerCase().endsWith(U)
270
+ (s) => !s.id.toLowerCase().endsWith(H)
249
271
  ).map((s, i, a) => ({
250
272
  ...s,
251
273
  progressionWeight: 1 / a.length
252
274
  }))
253
275
  }, n = await o.string();
254
276
  try {
255
- const s = ce(n), i = I(s);
277
+ const s = pe(n), i = S(s);
256
278
  return {
257
279
  ...r,
258
280
  readingDirection: i.readingDirection ?? "ltr"
259
281
  };
260
282
  } catch (s) {
261
283
  return console.error(
262
- `Unable to parse ${q} for content
284
+ `Unable to parse ${Y} for content
263
285
  `,
264
286
  n
265
287
  ), console.error(s), r;
266
288
  }
267
- }, ke = ({
289
+ }, je = ({
268
290
  baseUrl: e = "",
269
291
  resourcePath: t
270
292
  }) => {
@@ -272,43 +294,43 @@ const Re = K.toLowerCase(), Te = ({ archive: e }) => async (t) => {
272
294
  return encodeURI(t);
273
295
  const o = e ? `${e}${e.endsWith("/") ? "" : "/"}` : "file://";
274
296
  return encodeURI(`${o}${t}`);
275
- }, Ce = ({ archive: e, baseUrl: t }) => async () => {
276
- const o = Object.values(e.records).filter((r) => !r.dir);
297
+ }, De = ({ archive: e, baseUrl: t }) => async () => {
298
+ const o = Object.values(e.records).filter((s) => !s.dir), r = ee(), n = o.map((s) => ({
299
+ file: s,
300
+ id: r(s.uri)
301
+ }));
277
302
  return {
278
303
  filename: e.filename,
279
- title: e.records.find(({ dir: r }) => r)?.basename.replace(/\/$/, "") || e.filename,
304
+ title: e.records.find(({ dir: s }) => s)?.basename.replace(/\/$/, "") || e.filename,
280
305
  renditionLayout: void 0,
281
306
  renditionSpread: "auto",
282
307
  readingDirection: "ltr",
283
- spineItems: o.filter((r) => !r.basename.endsWith(".db")).map((r, n) => ({
284
- // some books such as cbz can have same basename inside different sub folder
285
- // we need to make sure to have unique index
286
- // /chap01/01.png, /chap02/01.png, etc
287
- id: `${n}.${r.basename}`,
288
- index: n,
289
- href: ke({
308
+ spineItems: n.filter(({ file: s }) => !s.basename.endsWith(".db")).map(({ file: s, id: i }, a) => ({
309
+ id: i,
310
+ index: a,
311
+ href: je({
290
312
  baseUrl: t,
291
- resourcePath: r.uri
313
+ resourcePath: s.uri
292
314
  }),
293
315
  renditionLayout: void 0,
294
316
  progressionWeight: 1 / o.length,
295
317
  pageSpreadLeft: void 0,
296
318
  pageSpreadRight: void 0,
297
- mediaType: r.encodingFormat
319
+ mediaType: s.encodingFormat
298
320
  })),
299
- items: o.map((r, n) => ({
300
- id: `${n}.${r.basename}`,
301
- href: encodeURI(`${t}${r.uri}`)
321
+ items: n.map(({ file: s, id: i }) => ({
322
+ id: i,
323
+ href: encodeURI(`${t}${s.uri}`)
302
324
  }))
303
325
  };
304
- }, Q = async ({
326
+ }, ne = async ({
305
327
  archive: e,
306
328
  archiveOpf: t
307
329
  }) => {
308
330
  if (!t) return [];
309
331
  const { opf: o, basePath: r } = t, { spineRows: n } = o;
310
332
  return e.records.filter((i) => n.find((a) => r ? `${r}/${a.href}` === i.uri : `${a.href}` === i.uri));
311
- }, Z = (e, t, o) => {
333
+ }, re = (e, t, o) => {
312
334
  const { basePath: r } = P(t) || {};
313
335
  return e.map((n) => {
314
336
  const s = n.href, i = o?.(s) ?? "";
@@ -318,85 +340,85 @@ const Re = K.toLowerCase(), Te = ({ archive: e }) => async (t) => {
318
340
  mediaType: n.mediaType
319
341
  };
320
342
  });
321
- }, We = (e) => {
343
+ }, Ue = (e) => {
322
344
  const t = e?.trim();
323
345
  return t === "scrolled-continuous" || t === "scrolled-doc" || t === "paginated" || t === "auto" ? t : "auto";
324
- }, Ee = (e) => {
346
+ }, He = (e) => {
325
347
  const t = e?.trim();
326
348
  if (t === "none" || t === "landscape" || t === "portrait" || t === "both" || t === "auto")
327
349
  return t;
328
- }, Pe = (e) => {
350
+ }, Xe = (e) => {
329
351
  const t = e?.trim();
330
352
  if (t === "cover" || t === "title-page" || t === "copyright-page" || t === "text")
331
353
  return t;
332
- }, Ne = ({
354
+ }, Ve = ({
333
355
  archive: e,
334
356
  baseUrl: t,
335
357
  archiveOpf: o
336
358
  }) => async (r) => {
337
359
  if (!o)
338
360
  return r;
339
- const { opf: n, basePath: s } = o, i = I(n);
361
+ const { opf: n, basePath: s } = o, i = S(n);
340
362
  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({
363
+ const a = n.renditionLayoutMeta?.trim(), c = a === "reflowable" || a === "pre-paginated" ? a : i.renditionLayout, d = n.title?.trim() || e.records.find(({ dir: l }) => l)?.basename || "", u = i.readingDirection ?? "ltr", m = (await ne({
342
364
  archive: e,
343
365
  archiveOpf: o
344
366
  })).reduce(
345
- (d, w) => w.size + d,
367
+ (l, v) => v.size + l,
346
368
  0
347
369
  ), 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 });
370
+ for (const l of h) {
371
+ const v = Xe(l.type);
372
+ v !== void 0 && y.push({ href: l.href, title: l.title, type: v });
351
373
  }
352
374
  return {
353
375
  filename: e.filename,
354
376
  renditionLayout: c,
355
- renditionFlow: We(n.renditionFlowMeta),
356
- renditionSpread: Ee(n.renditionSpreadMeta),
357
- title: l,
358
- readingDirection: p,
377
+ renditionFlow: Ue(n.renditionFlowMeta),
378
+ renditionSpread: He(n.renditionSpreadMeta),
379
+ title: d,
380
+ readingDirection: u,
359
381
  /**
360
382
  * @see https://www.w3.org/TR/epub/#sec-itemref-elem
361
383
  */
362
- spineItems: n.spineRows.map((d, w) => {
363
- const g = e.records.find((T) => T.uri.endsWith(d.href))?.size || 0, $ = t || (/^https?:\/\//.test(d.href) ? "" : "file://");
384
+ spineItems: n.spineRows.map((l, v) => {
385
+ const g = e.records.find((L) => L.uri.endsWith(l.href))?.size || 0, w = t || (/^https?:\/\//.test(l.href) ? "" : "file://");
364
386
  return {
365
- id: d.id,
366
- index: w,
367
- href: d.href.startsWith("https://") ? d.href : s ? `${$}${s}/${d.href}` : `${$}${d.href}`,
368
- renditionLayout: d.renditionLayout ?? c,
369
- ...d.renditionFlow !== void 0 ? { renditionFlow: d.renditionFlow } : {},
387
+ id: l.id,
388
+ index: v,
389
+ href: l.href.startsWith("https://") ? l.href : s ? `${w}${s}/${l.href}` : `${w}${l.href}`,
390
+ renditionLayout: l.renditionLayout ?? c,
391
+ ...l.renditionFlow !== void 0 ? { renditionFlow: l.renditionFlow } : {},
370
392
  progressionWeight: g / m,
371
- pageSpreadLeft: d.pageSpreadLeft,
372
- pageSpreadRight: d.pageSpreadRight,
373
- mediaType: d.mediaType
393
+ pageSpreadLeft: l.pageSpreadLeft,
394
+ pageSpreadRight: l.pageSpreadRight,
395
+ mediaType: l.mediaType
374
396
  };
375
397
  }),
376
- items: Z(n.manifestItems, e, (d) => /^https?:\/\//.test(d) ? "" : t || "file://"),
398
+ items: re(n.manifestItems, e, (l) => /^https?:\/\//.test(l) ? "" : t || "file://"),
377
399
  guide: y.length > 0 ? y : void 0
378
400
  };
379
- }, Oe = (e) => {
401
+ }, Ge = (e) => {
380
402
  const t = e.descendantWithPath("head")?.childrenNamed("meta").find((o) => o.attr.name === "viewport");
381
403
  return !!(t && t.attr.name === "viewport");
382
- }, ze = (e) => e.reduce(async (t, o) => {
383
- if (!await t || !se({
404
+ }, Ke = (e) => e.reduce(async (t, o) => {
405
+ if (!await t || !ce({
384
406
  mimeType: o.encodingFormat,
385
407
  uri: o.uri
386
408
  }))
387
409
  return !1;
388
410
  const n = o.dir ? null : await o.string();
389
- return n ? Oe(new R(n)) : !1;
390
- }, Promise.resolve(!0)), Me = ({
411
+ return n ? Ge(new R(n)) : !1;
412
+ }, Promise.resolve(!0)), qe = ({
391
413
  archive: e,
392
414
  archiveOpf: t
393
415
  }) => async (o) => {
394
416
  if (o.renditionLayout === "reflowable" && o.spineItems.every((n) => n.renditionLayout === "reflowable")) {
395
- const n = await Q({
417
+ const n = await ne({
396
418
  archive: e,
397
419
  archiveOpf: t
398
420
  });
399
- if (await ze(n))
421
+ if (await Ke(n))
400
422
  return {
401
423
  ...o,
402
424
  spineItems: o.spineItems.map((i) => ({
@@ -407,14 +429,14 @@ const Re = K.toLowerCase(), Te = ({ archive: e }) => async (t) => {
407
429
  };
408
430
  }
409
431
  return o;
410
- }, Be = async (e) => {
432
+ }, Je = async (e) => {
411
433
  let t;
412
434
  return await Promise.all(
413
435
  e.records.map(async (o) => {
414
436
  if (o.dir || !o.uri.endsWith(N)) return;
415
437
  const r = await o.string();
416
438
  try {
417
- const { renditionLayout: n } = de(r);
439
+ const { renditionLayout: n } = fe(r);
418
440
  n && (t = n);
419
441
  } catch (n) {
420
442
  console.error(
@@ -428,26 +450,26 @@ const Re = K.toLowerCase(), Te = ({ archive: e }) => async (t) => {
428
450
  kind: "kobo",
429
451
  ...t !== void 0 ? { renditionLayout: t } : {}
430
452
  };
431
- }, je = ({ archive: e }) => async (t) => {
432
- const o = await Be(e), { renditionLayout: r } = I(o);
453
+ }, Ze = ({ archive: e }) => async (t) => {
454
+ const o = await Je(e), { renditionLayout: r } = S(o);
433
455
  return {
434
456
  ...t,
435
457
  renditionLayout: t.renditionLayout ?? r
436
458
  };
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 : {
459
+ }, X = (e) => e.toLowerCase().endsWith(".opf"), Ye = (e) => e.records.some(
460
+ (t) => !t.dir && (X(t.basename) || X(t.uri))
461
+ ), Qe = ({ archive: e }) => async (t) => Ye(e) ? t : {
440
462
  ...t,
441
463
  spineItems: t.spineItems.map((r) => {
442
464
  const n = e.records.find(
443
465
  (i) => decodeURI(r.href).endsWith(i.uri)
444
- ), s = G(n?.encodingFormat ?? "") || v(n?.basename ?? "");
466
+ ), s = J(n?.encodingFormat ?? "") || b(n?.basename ?? "");
445
467
  return {
446
468
  ...r,
447
- renditionLayout: s && oe(s) ? "pre-paginated" : r.renditionLayout
469
+ renditionLayout: s && de(s) ? "pre-paginated" : r.renditionLayout
448
470
  };
449
471
  })
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 }) => {
472
+ }, se = (e) => e ? e.children.map((t) => t instanceof he ? t.text : t instanceof ge ? se(t) : "").join("").trim() : "", et = (e) => me(e.properties).includes("nav"), oe = (e, { basePath: t, baseUrl: o }) => {
451
473
  const r = {
452
474
  contents: [],
453
475
  path: "",
@@ -455,55 +477,55 @@ const Re = K.toLowerCase(), Te = ({ archive: e }) => async (t) => {
455
477
  title: ""
456
478
  };
457
479
  let n = e.childNamed("span") || e.childNamed("a");
458
- r.title = (n?.attr.title || n?.val.trim() || ee(n)) ?? "";
480
+ r.title = (n?.attr.title || n?.val.trim() || se(n)) ?? "";
459
481
  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));
482
+ s !== "a" && (n = e.descendantWithPath(`${s}.a`), n && (s = n.name.toLowerCase())), s === "a" && n?.attr.href && (r.path = I(t, n.attr.href), r.href = I(o, t, n.attr.href));
461
483
  const i = e.childNamed("ol");
462
484
  if (i) {
463
485
  const a = i.childrenNamed("li");
464
486
  a && a.length > 0 && (r.contents = a.map(
465
- (c) => te(c, { basePath: t, baseUrl: o })
487
+ (c) => oe(c, { basePath: t, baseUrl: o })
466
488
  ));
467
489
  }
468
490
  return r;
469
- }, _e = (e, { basePath: t, baseUrl: o }) => {
491
+ }, tt = (e, { basePath: t, baseUrl: o }) => {
470
492
  const r = [];
471
493
  let n;
472
494
  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 }));
495
+ r.push(oe(s, { basePath: t, baseUrl: o }));
474
496
  }), r;
475
- }, Ve = async (e, t, { baseUrl: o }) => {
476
- const r = e.manifestItems.find(He);
497
+ }, nt = async (e, t, { baseUrl: o }) => {
498
+ const r = e.manifestItems.find(et);
477
499
  if (r?.href) {
478
500
  const n = Object.values(t.records).find(
479
501
  (s) => s.uri.endsWith(r.href)
480
502
  );
481
503
  if (n && !n.dir) {
482
- const s = new R(await n.string()), i = Ae(n.uri);
483
- return _e(s, { basePath: i, baseUrl: o });
504
+ const s = new R(await n.string()), i = Le(n.uri);
505
+ return tt(s, { basePath: i, baseUrl: o });
484
506
  }
485
507
  }
486
- }, ne = (e, {
508
+ }, ie = (e, {
487
509
  opfBasePath: t,
488
510
  baseUrl: o,
489
511
  prefix: r
490
512
  }) => {
491
513
  const n = e?.childNamed(`${r}content`)?.attr.src || "", s = {
492
514
  title: e?.descendantWithPath(`${r}navLabel.${r}text`)?.val || "",
493
- path: L(t, n),
494
- href: L(o, t, n),
515
+ path: I(t, n),
516
+ href: I(o, t, n),
495
517
  contents: []
496
518
  }, i = e.childrenNamed(`${r}navPoint`);
497
519
  return i && i.length > 0 && (s.contents = i.map(
498
- (a) => ne(a, { opfBasePath: t, baseUrl: o, prefix: r })
520
+ (a) => ie(a, { opfBasePath: t, baseUrl: o, prefix: r })
499
521
  )), s;
500
- }, Xe = (e, { opfBasePath: t, baseUrl: o }) => {
522
+ }, rt = (e, { opfBasePath: t, baseUrl: o }) => {
501
523
  const r = [], n = e.name;
502
524
  let s = "";
503
525
  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 }));
526
+ r.push(ie(i, { opfBasePath: t, baseUrl: o, prefix: s }));
505
527
  }), r;
506
- }, Ge = async ({
528
+ }, st = async ({
507
529
  opf: e,
508
530
  opfBasePath: t,
509
531
  baseUrl: o,
@@ -518,17 +540,17 @@ const Re = K.toLowerCase(), Te = ({ archive: e }) => async (t) => {
518
540
  );
519
541
  if (a && !a.dir) {
520
542
  const c = new R(await a.string());
521
- return Xe(c, { opfBasePath: t, baseUrl: o });
543
+ return rt(c, { opfBasePath: t, baseUrl: o });
522
544
  }
523
545
  }
524
546
  }
525
- }, Ke = async (e, t, { baseUrl: o }) => {
526
- const { basePath: r } = P(t) || {}, n = await Ve(e, t, {
547
+ }, ot = async (e, t, { baseUrl: o }) => {
548
+ const { basePath: r } = P(t) || {}, n = await nt(e, t, {
527
549
  baseUrl: o
528
550
  });
529
551
  if (n)
530
552
  return n;
531
- const s = await Ge({
553
+ const s = await st({
532
554
  opf: e,
533
555
  opfBasePath: r ?? "",
534
556
  archive: t,
@@ -536,53 +558,53 @@ const Re = K.toLowerCase(), Te = ({ archive: e }) => async (t) => {
536
558
  });
537
559
  if (s)
538
560
  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/"))))
561
+ }, it = (e) => e.replace(/\.[^.]+$/, "").replace(/[_-]/g, " ").replace(/\s+/g, " ").trim(), at = (e, t) => {
562
+ if (!(e.spineItems.length === 0 || !e.spineItems.every((r) => (J(r.mediaType ?? "") || b(r.href))?.startsWith("audio/"))))
541
563
  return e.spineItems.map((r) => {
542
564
  const n = t.records.find(
543
565
  (s) => !s.dir && decodeURI(r.href).endsWith(s.uri)
544
566
  );
545
567
  return {
546
- title: qe(n?.basename ?? r.href),
568
+ title: it(n?.basename ?? r.href),
547
569
  href: r.href,
548
570
  path: n?.uri ?? r.href,
549
571
  contents: []
550
572
  };
551
573
  });
552
- }, Ye = (e, { baseUrl: t }) => {
574
+ }, ct = (e, { baseUrl: t }) => {
553
575
  const o = [...e.records].sort(
554
- (n, s) => E(n.uri, s.uri)
576
+ (n, s) => W(n.uri, s.uri)
555
577
  ), r = (n, s, i, a, c) => {
556
- const l = n.find((m) => m.title === s), [p, ...u] = i;
557
- return l ? p ? [
558
- ...n.filter((h) => h !== l),
578
+ const d = n.find((m) => m.title === s), [u, ...p] = i;
579
+ return d ? u ? [
580
+ ...n.filter((h) => h !== d),
559
581
  {
560
- ...l,
582
+ ...d,
561
583
  contents: [
562
- ...l.contents,
584
+ ...d.contents,
563
585
  ...r(
564
- l.contents,
565
- p,
586
+ d.contents,
566
587
  u,
588
+ p,
567
589
  a,
568
590
  c
569
591
  )
570
592
  ]
571
593
  }
572
- ] : l.path.split("/").length > c.split("/").length ? [
573
- ...n.filter((h) => h !== l),
594
+ ] : d.path.split("/").length > c.split("/").length ? [
595
+ ...n.filter((h) => h !== d),
574
596
  {
575
- ...l,
597
+ ...d,
576
598
  path: c,
577
599
  href: a
578
600
  }
579
- ] : n : p ? [
601
+ ] : n : u ? [
580
602
  ...n,
581
603
  {
582
604
  contents: r(
583
605
  [],
584
- p,
585
606
  u,
607
+ p,
586
608
  a,
587
609
  c
588
610
  ),
@@ -604,27 +626,27 @@ const Re = K.toLowerCase(), Te = ({ archive: e }) => async (t) => {
604
626
  if (s.dir) return n;
605
627
  const i = s.uri.split("/").slice(0, -1), [a, ...c] = i;
606
628
  if (!a) return n;
607
- const l = L(t, encodeURI(s.uri)).replace(/\/$/, ""), p = s.uri.replace(/\/$/, "");
608
- return r(n, a, c, l, p);
629
+ const d = I(t, encodeURI(s.uri)).replace(/\/$/, ""), u = s.uri.replace(/\/$/, "");
630
+ return r(n, a, c, d, u);
609
631
  }, []);
610
- }, Qe = async (e, t, {
632
+ }, dt = async (e, t, {
611
633
  baseUrl: o,
612
634
  archiveOpf: r
613
635
  }) => {
614
636
  if (r)
615
- return await Ke(r.opf, e, { baseUrl: o }) || [];
616
- const n = Je(t, e);
637
+ return await ot(r.opf, e, { baseUrl: o }) || [];
638
+ const n = at(t, e);
617
639
  if (n) return n;
618
- const s = Ye(e, { baseUrl: o });
640
+ const s = ct(e, { baseUrl: o });
619
641
  if (s.length !== 0)
620
642
  return s;
621
- }, Ze = ({
643
+ }, lt = ({
622
644
  archive: e,
623
645
  baseUrl: t,
624
646
  archiveOpf: o
625
647
  }) => async (r) => {
626
648
  if (r.nav) return r;
627
- const n = await Qe(e, r, {
649
+ const n = await dt(e, r, {
628
650
  baseUrl: t,
629
651
  archiveOpf: o
630
652
  });
@@ -634,58 +656,59 @@ const Re = K.toLowerCase(), Te = ({ archive: e }) => async (t) => {
634
656
  toc: n
635
657
  }
636
658
  } : r;
637
- }, et = (e) => e ? e.endsWith("/") ? e : `${e}/` : "", tt = async (e, {
659
+ }, ut = (e) => e ? e.endsWith("/") ? e : `${e}/` : "", pt = async (e, {
638
660
  baseUrl: t = "",
639
661
  hooks: o = {}
640
662
  } = {}) => {
641
- const r = await Y(e), n = et(t), s = (u) => (u ?? []).map(
663
+ f.log("Generating manifest from archive", e);
664
+ const r = await te(e), n = ut(t), s = (p) => (p ?? []).map(
642
665
  (m) => m({ archive: e, baseUrl: n })
643
666
  ), i = [
644
- Ne({ archive: e, baseUrl: n, archiveOpf: r }),
645
- Se({ archive: e }),
646
- Te({ archive: e }),
647
- De({ archive: e }),
667
+ Ve({ archive: e, baseUrl: n, archiveOpf: r }),
668
+ Be({ archive: e }),
669
+ Me({ archive: e }),
670
+ Qe({ archive: e }),
648
671
  ...s(o.content)
649
672
  ], a = s(o.spine), c = [
650
- Me({ archive: e, archiveOpf: r }),
651
- je({ archive: e }),
673
+ qe({ archive: e, archiveOpf: r }),
674
+ Ze({ archive: e }),
652
675
  ...s(o.presentation)
653
- ], l = [
654
- Ze({ archive: e, baseUrl: n, archiveOpf: r }),
676
+ ], d = [
677
+ lt({ archive: e, baseUrl: n, archiveOpf: r }),
655
678
  ...s(o.navigation)
656
- ], p = [
679
+ ], u = [
657
680
  ...i,
658
681
  ...a,
659
682
  ...c,
660
- ...l
683
+ ...d
661
684
  ];
662
685
  try {
663
- const u = Ce({
686
+ const p = De({
664
687
  archive: e,
665
688
  baseUrl: n
666
- })(), m = await p.reduce(async (h, y) => await y(await h), u);
689
+ })(), m = await u.reduce(async (h, y) => await y(await h), p);
667
690
  if (f.log("Generated manifest", m), process.env.NODE_ENV === "development" && f.isEnabled()) {
668
691
  const h = JSON.stringify(m, null, 2);
669
692
  f.groupCollapsed(...f.getGroupArgs("Generated manifest")), f.log(`
670
693
  ${h}`), f.groupEnd();
671
694
  }
672
695
  return m;
673
- } catch (u) {
674
- throw f.error(u), u;
696
+ } catch (p) {
697
+ throw f.error(p), p;
675
698
  }
676
- }, nt = (e) => {
699
+ }, ft = (e) => {
677
700
  const t = e.descendantWithPath("head")?.childrenNamed("meta").find((o) => o.attr.name === "calibre:cover");
678
701
  return !!(t && t.attr.name === "calibre:cover");
679
- }, rt = (e) => e.descendantWithPath("body")?.descendantWithPath("div")?.childrenNamed("svg")?.find(
702
+ }, mt = (e) => e.descendantWithPath("body")?.descendantWithPath("div")?.childrenNamed("svg")?.find(
680
703
  (t) => t.attr.width === "100%" && t.attr.preserveAspectRatio === "none"
681
- ), st = ({ archive: e, resourcePath: t }) => async (o) => {
704
+ ), ht = ({ archive: e, resourcePath: t }) => async (o) => {
682
705
  const r = Object.values(e.records).find(
683
706
  (n) => n.uri === t && !n.dir
684
707
  );
685
708
  if (r && !r.dir && r.basename.endsWith(".xhtml")) {
686
709
  const n = typeof o.body == "string" ? o.body : await r.string(), s = new R(n);
687
- if (nt(s)) {
688
- const i = rt(s);
710
+ if (ft(s)) {
711
+ const i = mt(s);
689
712
  return i && delete i.attr.preserveAspectRatio, {
690
713
  ...o,
691
714
  body: s?.toString()
@@ -693,7 +716,7 @@ ${h}`), f.groupEnd();
693
716
  }
694
717
  }
695
718
  return o;
696
- }, ot = ({ archive: e, resourcePath: t }) => async (o) => st({ archive: e, resourcePath: t })(o), it = ({ archive: e, resourcePath: t }) => async (o) => {
719
+ }, gt = ({ archive: e, resourcePath: t }) => async (o) => ht({ archive: e, resourcePath: t })(o), yt = ({ archive: e, resourcePath: t }) => async (o) => {
697
720
  const r = Object.values(e.records).find(
698
721
  (n) => n.uri === t && !n.dir
699
722
  );
@@ -708,10 +731,10 @@ ${h}`), f.groupEnd();
708
731
  };
709
732
  }
710
733
  return o;
711
- }, at = async (e, t) => {
712
- const o = await Y(e);
734
+ }, bt = async (e, t) => {
735
+ const o = await te(e);
713
736
  if (o) {
714
- const { opf: r } = o, n = Z(r.manifestItems, e, () => "");
737
+ const { opf: r } = o, n = re(r.manifestItems, e, () => "");
715
738
  if (n.find(
716
739
  (i) => t.endsWith(i.href)
717
740
  )?.mediaType)
@@ -720,9 +743,9 @@ ${h}`), f.groupEnd();
720
743
  };
721
744
  }
722
745
  return {
723
- mediaType: ct(t)
746
+ mediaType: vt(t)
724
747
  };
725
- }, ct = (e) => {
748
+ }, vt = (e) => {
726
749
  if (e.endsWith(".css"))
727
750
  return "text/css; charset=UTF-8";
728
751
  if (e.endsWith(".jpg"))
@@ -733,12 +756,12 @@ ${h}`), f.groupEnd();
733
756
  return "video/mp4";
734
757
  if (e.endsWith(".svg"))
735
758
  return "image/svg+xml";
736
- }, dt = ({ archive: e, resourcePath: t }) => async (o) => {
759
+ }, wt = ({ archive: e, resourcePath: t }) => async (o) => {
737
760
  const r = Object.values(e.records).find(
738
761
  (s) => s.uri === t && !s.dir
739
762
  );
740
763
  if (!r || r.dir) return o;
741
- const n = await at(e, t);
764
+ const n = await bt(e, t);
742
765
  return {
743
766
  ...o,
744
767
  params: {
@@ -751,7 +774,7 @@ ${h}`), f.groupEnd();
751
774
  }
752
775
  }
753
776
  };
754
- }, H = [
777
+ }, V = [
755
778
  "div",
756
779
  "span",
757
780
  "p",
@@ -802,23 +825,23 @@ ${h}`), f.groupEnd();
802
825
  "canvas",
803
826
  "script",
804
827
  "style"
805
- ], lt = ({ archive: e, resourcePath: t }) => async (o) => {
828
+ ], $t = ({ archive: e, resourcePath: t }) => async (o) => {
806
829
  const r = Object.values(e.records).find(
807
830
  (n) => n.uri === t && !n.dir
808
831
  );
809
832
  if (r && !r.dir && r.basename.endsWith(".xhtml")) {
810
833
  const n = typeof o.body == "string" ? o.body : await r.string();
811
834
  if (!new RegExp(
812
- `<(${H.join("|")})[\\s/>]`,
835
+ `<(${V.join("|")})[\\s/>]`,
813
836
  "i"
814
837
  ).test(n))
815
838
  return o;
816
839
  const i = new RegExp(
817
- `<(${H.join("|")})(\\s[^>]*)?\\s*/>`,
840
+ `<(${V.join("|")})(\\s[^>]*)?\\s*/>`,
818
841
  "gi"
819
842
  ), a = n.replace(
820
843
  i,
821
- (c, l, p = "") => `<${l} ${p.trim()}></${l}>`
844
+ (c, d, u = "") => `<${d} ${u.trim()}></${d}>`
822
845
  );
823
846
  return {
824
847
  ...o,
@@ -826,18 +849,18 @@ ${h}`), f.groupEnd();
826
849
  };
827
850
  }
828
851
  return o;
829
- }, pt = async (e, t, { hooks: o = [] } = {}) => {
852
+ }, At = async (e, t, { hooks: o = [] } = {}) => {
830
853
  const r = {
831
854
  params: {}
832
855
  }, s = [
833
856
  ...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 })
857
+ wt({ archive: e, resourcePath: t }),
858
+ $t({ archive: e, resourcePath: t }),
859
+ yt({ archive: e, resourcePath: t }),
860
+ gt({ archive: e, resourcePath: t })
838
861
  ];
839
862
  try {
840
- const i = await s.reduce(async (c, l) => await l(await c), Promise.resolve(r));
863
+ const i = await s.reduce(async (c, d) => await d(await c), Promise.resolve(r));
841
864
  if (f.log("Generated resource", t, i), i.body !== void 0)
842
865
  return i;
843
866
  const a = Object.values(e.records).find(
@@ -853,9 +876,9 @@ ${h}`), f.groupEnd();
853
876
  throw f.error(i), i;
854
877
  }
855
878
  };
856
- class ut {
879
+ class Ft {
857
880
  constructor(t) {
858
- this.cleanArchiveAfter = t, this.state$ = new ye({
881
+ this.cleanArchiveAfter = t, this.state$ = new $e({
859
882
  status: "idle",
860
883
  locks: 0
861
884
  });
@@ -864,103 +887,103 @@ class ut {
864
887
  this.state$.next({ ...this.state$.getValue(), ...t });
865
888
  }
866
889
  get locks$() {
867
- return this.state$.pipe(F(({ locks: t }) => t));
890
+ return this.state$.pipe($(({ locks: t }) => t));
868
891
  }
869
892
  get state() {
870
893
  return this.state$.getValue();
871
894
  }
872
895
  get isUnlocked$() {
873
896
  return this.locks$.pipe(
874
- F((t) => t <= 0),
875
- be(),
876
- ve()
897
+ $((t) => t <= 0),
898
+ Ae(),
899
+ Fe()
877
900
  );
878
901
  }
879
902
  get overTTL$() {
880
903
  return this.isUnlocked$.pipe(
881
- A(
882
- (t) => t ? this.cleanArchiveAfter === 1 / 0 ? B : we(this.cleanArchiveAfter) : B
904
+ T(
905
+ (t) => t ? this.cleanArchiveAfter === 1 / 0 ? B : Te(this.cleanArchiveAfter) : B
883
906
  )
884
907
  );
885
908
  }
886
909
  }
887
- const ft = ({
910
+ const Tt = ({
888
911
  getArchive: e,
889
912
  cleanArchiveAfter: t = 300 * 1e3
890
913
  // 5mn
891
914
  }) => {
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;
915
+ const o = new x(), r = new x(), n = new x(), s = {}, i = o.pipe(
916
+ Q((d) => {
917
+ const u = s[d];
918
+ if (!u || u.state.status !== "idle") return z;
919
+ let p = !1;
897
920
  const m = (g) => {
898
921
  f.debug(`Cleaning up archive with key: ${g}`);
899
- const $ = s[g];
900
- delete s[g], u || ($?.state.archive?.close(), u = !0);
922
+ const w = s[g];
923
+ delete s[g], p || (w?.state.archive?.close(), p = !0);
901
924
  };
902
- p.update({
925
+ u.update({
903
926
  status: "loading"
904
927
  });
905
- const h = p.locks$, y = p.isUnlocked$, d = h.pipe(
906
- fe(),
907
- k(([g, $]) => $ > g),
908
- me(!0)
928
+ const h = u.locks$, y = u.isUnlocked$, l = h.pipe(
929
+ ye(),
930
+ E(([g, w]) => w > g),
931
+ be(!0)
909
932
  );
910
- return x(e(l)).pipe(
911
- C((g) => {
912
- p.update({
933
+ return F(e(d)).pipe(
934
+ k((g) => {
935
+ u.update({
913
936
  archive: g,
914
937
  status: "success"
915
938
  });
916
939
  }),
917
- W((g) => (m(l), p.update({
940
+ C((g) => (m(d), u.update({
918
941
  status: "error",
919
942
  error: g
920
- }), O)),
921
- A(() => {
922
- const g = d.pipe(
923
- A(() => n),
924
- A(() => y),
925
- k((T) => T)
943
+ }), z)),
944
+ T(() => {
945
+ const g = l.pipe(
946
+ T(() => n),
947
+ T(() => y),
948
+ E((L) => L)
926
949
  );
927
- return z(g, p.overTTL$).pipe(
950
+ return O(g, u.overTTL$).pipe(
928
951
  M(),
929
- C(() => {
930
- m(l);
952
+ k(() => {
953
+ m(d);
931
954
  })
932
955
  );
933
956
  })
934
957
  );
935
958
  }),
936
- he(r)
937
- ), a = (l) => {
938
- let p = !1;
939
- const u = s[l] ?? new ut(t);
940
- s[l] = u, u.update({
941
- locks: u.state.locks + 1
959
+ ve(r)
960
+ ), a = (d) => {
961
+ let u = !1;
962
+ const p = s[d] ?? new Ft(t);
963
+ s[d] = p, p.update({
964
+ locks: p.state.locks + 1
942
965
  });
943
966
  const m = () => {
944
- p || (p = !0, u.update({
945
- locks: u.state.locks - 1
967
+ u || (u = !0, p.update({
968
+ locks: p.state.locks - 1
946
969
  }));
947
970
  };
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 }) => {
954
- if (d)
955
- throw d;
971
+ o.next(d);
972
+ const h = p.state$.pipe(
973
+ $(({ archive: l }) => l),
974
+ E((l) => !!l)
975
+ ), y = p.state$.pipe(
976
+ k(({ error: l }) => {
977
+ if (l)
978
+ throw l;
956
979
  }),
957
- ge()
980
+ we()
958
981
  );
959
- return z(h, y).pipe(
982
+ return O(h, y).pipe(
960
983
  M(),
961
- F((d) => ({ archive: d, release: m })),
962
- W((d) => {
963
- throw m(), d;
984
+ $((l) => ({ archive: l, release: m })),
985
+ C((l) => {
986
+ throw m(), l;
964
987
  })
965
988
  );
966
989
  }, c = () => {
@@ -971,7 +994,7 @@ const ft = ({
971
994
  purge: c,
972
995
  _archives: s
973
996
  };
974
- }, _ = (e) => e ? /^\d+$/.test(e) ? {
997
+ }, G = (e) => e ? /^\d+$/.test(e) ? {
975
998
  valid: !0,
976
999
  value: Number.parseInt(e, 10)
977
1000
  } : {
@@ -980,7 +1003,7 @@ const ft = ({
980
1003
  } : {
981
1004
  valid: !0,
982
1005
  value: void 0
983
- }, mt = (e) => {
1006
+ }, It = (e) => {
984
1007
  if (!e.toLowerCase().startsWith("bytes="))
985
1008
  return {
986
1009
  kind: "missing"
@@ -999,7 +1022,7 @@ const ft = ({
999
1022
  return {
1000
1023
  kind: "invalid"
1001
1024
  };
1002
- const [, r = "", n = ""] = o, s = _(r.trim()), i = _(n.trim());
1025
+ const [, r = "", n = ""] = o, s = G(r.trim()), i = G(n.trim());
1003
1026
  return !s.valid || !i.valid ? {
1004
1027
  kind: "invalid"
1005
1028
  } : {
@@ -1007,7 +1030,7 @@ const ft = ({
1007
1030
  start: s.value,
1008
1031
  end: i.value
1009
1032
  };
1010
- }, ht = (e) => {
1033
+ }, St = (e) => {
1011
1034
  if (e instanceof Blob)
1012
1035
  return {
1013
1036
  size: e.size,
@@ -1024,7 +1047,7 @@ const ft = ({
1024
1047
  return { content: n, length: n.byteLength };
1025
1048
  }
1026
1049
  };
1027
- }, gt = ({
1050
+ }, Rt = ({
1028
1051
  body: e,
1029
1052
  contentType: t,
1030
1053
  rangeHeader: o
@@ -1035,13 +1058,13 @@ const ft = ({
1035
1058
  status: 200,
1036
1059
  headers: r
1037
1060
  });
1038
- const n = mt(o);
1061
+ const n = It(o);
1039
1062
  if (n.kind === "missing" || n.kind === "multi")
1040
1063
  return e instanceof Blob && r.set("Content-Length", String(e.size)), new Response(e, {
1041
1064
  status: 200,
1042
1065
  headers: r
1043
1066
  });
1044
- const s = ht(e), i = s.size;
1067
+ const s = St(e), i = s.size;
1045
1068
  if (n.kind === "invalid")
1046
1069
  return new Response(null, {
1047
1070
  status: 416,
@@ -1058,8 +1081,8 @@ const ft = ({
1058
1081
  }
1059
1082
  });
1060
1083
  if (a === void 0) {
1061
- const p = Math.min(c ?? 0, i);
1062
- a = Math.max(0, i - p), c = i - 1;
1084
+ const u = Math.min(c ?? 0, i);
1085
+ a = Math.max(0, i - u), c = i - 1;
1063
1086
  } else (c === void 0 || c >= i) && (c = i - 1);
1064
1087
  if (a < 0 || c < 0 || a >= i || c >= i || a > c)
1065
1088
  return new Response(null, {
@@ -1068,29 +1091,29 @@ const ft = ({
1068
1091
  "Content-Range": `bytes */${i}`
1069
1092
  }
1070
1093
  });
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, {
1094
+ const d = s.slice(a, c + 1);
1095
+ return r.set("Content-Length", String(d.length)), r.set("Content-Range", `bytes ${a}-${c}/${i}`), new Response(d.content, {
1073
1096
  status: 206,
1074
1097
  headers: r
1075
1098
  });
1076
- }, V = "file://", yt = /^https?:\/\//, bt = (e) => {
1099
+ }, K = "file://", Lt = /^https?:\/\//, xt = (e) => {
1077
1100
  try {
1078
1101
  return decodeURIComponent(e);
1079
1102
  } catch {
1080
1103
  return e;
1081
1104
  }
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));
1105
+ }, q = (e) => e.startsWith(K) ? e.slice(K.length) : e, Et = (e) => {
1106
+ const t = q(e);
1107
+ return Lt.test(t) ? t : q(xt(t));
1085
1108
  };
1086
- class wt {
1109
+ class kt {
1087
1110
  constructor({
1088
1111
  hooks: t,
1089
1112
  onError: o,
1090
1113
  onManifestSuccess: r,
1091
1114
  ...n
1092
1115
  }) {
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;
1116
+ this.onError = (s) => (console.error(s), new Response(String(s), { status: 500 })), this.archiveLoader = Tt(n), this.hooks = t ?? {}, this.onManifestSuccess = r ?? (({ manifest: s }) => Promise.resolve(s)), this.onError = o ?? this.onError;
1094
1117
  }
1095
1118
  prune() {
1096
1119
  this.archiveLoader.purge();
@@ -1100,7 +1123,7 @@ class wt {
1100
1123
  }
1101
1124
  accessArchiveWithoutLock(t) {
1102
1125
  return this.accessArchive(t).pipe(
1103
- F(({ archive: o, release: r }) => (r(), o))
1126
+ $(({ archive: o, release: r }) => (r(), o))
1104
1127
  );
1105
1128
  }
1106
1129
  withArchiveResponse({
@@ -1108,30 +1131,30 @@ class wt {
1108
1131
  getResponse: o
1109
1132
  }) {
1110
1133
  const r = this.accessArchive(t).pipe(
1111
- J(
1112
- ({ archive: n, release: s }) => x(o(n)).pipe(
1113
- $e(() => {
1134
+ Q(
1135
+ ({ archive: n, release: s }) => F(o(n)).pipe(
1136
+ Ie(() => {
1114
1137
  s();
1115
1138
  })
1116
1139
  )
1117
1140
  ),
1118
- W((n) => Fe(this.onError(n)))
1141
+ C((n) => Se(this.onError(n)))
1119
1142
  );
1120
- return xe(r);
1143
+ return Re(r);
1121
1144
  }
1122
1145
  fetchManifest({ key: t, baseUrl: o }) {
1123
1146
  return this.withArchiveResponse({
1124
1147
  key: t,
1125
- getResponse: (r) => x(
1126
- tt(r, {
1148
+ getResponse: (r) => F(
1149
+ pt(r, {
1127
1150
  baseUrl: o,
1128
1151
  hooks: this.hooks.manifest
1129
1152
  })
1130
1153
  ).pipe(
1131
- A(
1132
- (s) => x(this.onManifestSuccess({ manifest: s, archive: r }))
1154
+ T(
1155
+ (s) => F(this.onManifestSuccess({ manifest: s, archive: r }))
1133
1156
  ),
1134
- F(
1157
+ $(
1135
1158
  (s) => new Response(JSON.stringify(s), {
1136
1159
  status: 200
1137
1160
  })
@@ -1147,14 +1170,14 @@ class wt {
1147
1170
  return this.withArchiveResponse({
1148
1171
  key: t,
1149
1172
  getResponse: (n) => {
1150
- const s = vt(o);
1151
- return x(
1152
- pt(n, s, {
1173
+ const s = Et(o);
1174
+ return F(
1175
+ At(n, s, {
1153
1176
  hooks: this.hooks.resource
1154
1177
  })
1155
1178
  ).pipe(
1156
- F(
1157
- (a) => gt({
1179
+ $(
1180
+ (a) => Rt({
1158
1181
  body: a.body ?? "",
1159
1182
  contentType: a.params.contentType,
1160
1183
  rangeHeader: r?.headers.get("range")
@@ -1165,7 +1188,7 @@ class wt {
1165
1188
  });
1166
1189
  }
1167
1190
  }
1168
- class Ct extends wt {
1191
+ class Dt extends kt {
1169
1192
  constructor({
1170
1193
  getUriInfo: t,
1171
1194
  ...o
@@ -1196,20 +1219,23 @@ class Ct extends wt {
1196
1219
  }
1197
1220
  }
1198
1221
  export {
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,
1222
+ Dt as ServiceWorkerStreamer,
1223
+ kt as Streamer,
1224
+ jt as configure,
1225
+ Nt as createArchiveFromArrayBufferList,
1226
+ zt as createArchiveFromJszip,
1227
+ Ot as createArchiveFromLibArchive,
1228
+ Mt as createArchiveFromText,
1229
+ Bt as createArchiveFromUrls,
1230
+ ze as createUniqueXmlSafeId,
1231
+ Ne as createXmlSafeId,
1232
+ ee as createXmlSafeIdFactory,
1233
+ pt as generateManifestFromArchive,
1234
+ At as generateResourceFromArchive,
1209
1235
  P as getArchiveOpfInfo,
1210
- Ae as getUriBasePath,
1211
- b as getUriBasename,
1236
+ Le as getUriBasePath,
1237
+ A as getUriBasename,
1212
1238
  j as removeTrailingSlash,
1213
- E as sortByTitleComparator
1239
+ W as sortByTitleComparator
1214
1240
  };
1215
1241
  //# sourceMappingURL=index.js.map