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