@prose-reader/streamer 1.120.0 → 1.122.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,32 +1,32 @@
1
- import F, { XmlDocument as de } from "xmldoc";
2
- import { urlJoin as W, isXmlBasedMimeType as le, detectMimeTypeFromName as V } from "@prose-reader/shared";
3
- import { Subject as R, mergeMap as O, EMPTY as _, pairwise as pe, filter as j, startWith as fe, from as L, tap as D, catchError as P, switchMap as S, merge as q, takeUntil as ue, map as A, ignoreElements as me, first as he, BehaviorSubject as ge, distinctUntilChanged as ye, shareReplay as be, NEVER as G, timer as we, finalize as K, of as J, lastValueFrom as Y } from "rxjs";
4
- let k = !1;
1
+ import F, { XmlDocument as le, XmlTextNode as pe, XmlElement as fe } from "xmldoc";
2
+ import { urlJoin as N, isXmlBasedMimeType as ue, detectMimeTypeFromName as V } from "@prose-reader/shared";
3
+ import { Subject as R, mergeMap as O, EMPTY as _, pairwise as me, filter as j, startWith as he, from as L, tap as D, catchError as P, switchMap as k, merge as q, takeUntil as ge, map as A, ignoreElements as ye, first as be, BehaviorSubject as we, distinctUntilChanged as ve, shareReplay as $e, NEVER as G, timer as xe, finalize as K, of as J, lastValueFrom as Y } from "rxjs";
4
+ let S = !1;
5
5
  const v = {
6
6
  enable: (e) => {
7
- k = e;
7
+ S = e;
8
8
  },
9
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
10
  log: (...e) => {
11
- k && console.log("[prose-reader-streamer]", ...e);
11
+ S && console.log("[prose-reader-streamer]", ...e);
12
12
  },
13
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
14
  warn: (...e) => {
15
- k && console.warn("[prose-reader-streamer]", ...e);
15
+ S && console.warn("[prose-reader-streamer]", ...e);
16
16
  },
17
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
18
  error: (...e) => {
19
19
  console.error(...e);
20
20
  },
21
21
  time: (e) => {
22
- k && console.time(`[prose-reader-streamer] [metric] ${e}`);
22
+ S && console.time(`[prose-reader-streamer] [metric] ${e}`);
23
23
  },
24
24
  timeEnd: (e) => {
25
- k && console.timeEnd(`[prose-reader-streamer] [metric] ${e}`);
25
+ S && console.timeEnd(`[prose-reader-streamer] [metric] ${e}`);
26
26
  },
27
27
  metric: (e, t = 1 / 0) => {
28
28
  const i = typeof e == "number" ? e : e.duration;
29
- k && (e.duration <= t ? console.log(
29
+ S && (e.duration <= t ? console.log(
30
30
  "[prose-reader-streamer] [metric] ",
31
31
  `${e.name} took ${i}ms`
32
32
  ) : console.warn(
@@ -45,23 +45,23 @@ const v = {
45
45
  const a = performance.now();
46
46
  return v.metric({ name: e, duration: a - n }, t), s;
47
47
  }
48
- }, ve = (e) => {
48
+ }, Fe = (e) => {
49
49
  var i;
50
50
  const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((r) => r.attr.name === "calibre:cover");
51
51
  return !!(t && t.attr.name === "calibre:cover");
52
- }, $e = (e) => {
52
+ }, Ae = (e) => {
53
53
  var t, i, r;
54
54
  return (r = (i = (t = e.descendantWithPath("body")) == null ? void 0 : t.descendantWithPath("div")) == null ? void 0 : i.childrenNamed("svg")) == null ? void 0 : r.find(
55
55
  (n) => n.attr.width === "100%" && n.attr.preserveAspectRatio === "none"
56
56
  );
57
- }, xe = ({ archive: e, resourcePath: t }) => async (i) => {
57
+ }, Te = ({ archive: e, resourcePath: t }) => async (i) => {
58
58
  const r = Object.values(e.files).find(
59
59
  (n) => n.uri === t
60
60
  );
61
61
  if (r != null && r.basename.endsWith(".xhtml")) {
62
- const n = i.body ?? await r.string(), s = new de(n);
63
- if (ve(s)) {
64
- const a = $e(s);
62
+ const n = i.body ?? await r.string(), s = new le(n);
63
+ if (Fe(s)) {
64
+ const a = Ae(s);
65
65
  return a && delete a.attr.preserveAspectRatio, {
66
66
  ...i,
67
67
  body: s == null ? void 0 : s.toString()
@@ -69,7 +69,7 @@ const v = {
69
69
  }
70
70
  }
71
71
  return i;
72
- }, Fe = ({ archive: e, resourcePath: t }) => async (i) => xe({ archive: e, resourcePath: t })(i), Ae = ({ archive: e, resourcePath: t }) => async (i) => {
72
+ }, Se = ({ archive: e, resourcePath: t }) => async (i) => Te({ archive: e, resourcePath: t })(i), ke = ({ archive: e, resourcePath: t }) => async (i) => {
73
73
  const r = Object.values(e.files).find(
74
74
  (n) => n.uri === t
75
75
  );
@@ -90,7 +90,10 @@ const v = {
90
90
  data: i,
91
91
  basePath: (i == null ? void 0 : i.uri.substring(0, i.uri.lastIndexOf("/"))) || ""
92
92
  };
93
- }, E = (e, { opfBasePath: t, baseUrl: i }) => {
93
+ }, E = (e) => e ? e.children.map((t) => t instanceof pe ? t.text : t instanceof fe ? E(t) : "").join("").trim() : "", T = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Q = (e) => e.endsWith("/") ? e.slice(0, -1) : e, Ne = (e) => {
94
+ const t = e.lastIndexOf("/");
95
+ return t >= 0 ? e.substring(0, t) : "";
96
+ }, ee = (e, { basePath: t, baseUrl: i }) => {
94
97
  const r = {
95
98
  contents: [],
96
99
  path: "",
@@ -98,37 +101,37 @@ const v = {
98
101
  title: ""
99
102
  };
100
103
  let n = e.childNamed("span") || e.childNamed("a");
101
- r.title = (n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || r.title;
104
+ r.title = ((n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || E(n)) ?? "";
102
105
  let s = n == null ? void 0 : n.name;
103
- s !== "a" && (n = e.descendantWithPath(`${s}.a`), n && (s = n.name.toLowerCase())), s === "a" && (n != null && n.attr.href) && (r.path = W(t, n.attr.href), r.href = W(i, t, n.attr.href));
106
+ s !== "a" && (n = e.descendantWithPath(`${s}.a`), n && (s = n.name.toLowerCase())), s === "a" && (n != null && n.attr.href) && (r.path = N(t, n.attr.href), r.href = N(i, t, n.attr.href));
104
107
  const a = e.childNamed("ol");
105
108
  if (a) {
106
109
  const o = a.childrenNamed("li");
107
110
  o && o.length > 0 && (r.contents = o.map(
108
- (d) => E(d, { opfBasePath: t, baseUrl: i })
111
+ (d) => ee(d, { basePath: t, baseUrl: i })
109
112
  ));
110
113
  }
111
114
  return r;
112
- }, Te = (e, { opfBasePath: t, baseUrl: i }) => {
115
+ }, We = (e, { basePath: t, baseUrl: i }) => {
113
116
  var s, a;
114
117
  const r = [];
115
118
  let n;
116
119
  return e.descendantWithPath("body.nav.ol") ? n = (s = e.descendantWithPath("body.nav.ol")) == null ? void 0 : s.children : e.descendantWithPath("body.section.nav.ol") && (n = (a = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : a.children), n && n.length > 0 && n.filter((o) => o.name === "li").forEach(
117
- (o) => r.push(E(o, { opfBasePath: t, baseUrl: i }))
120
+ (o) => r.push(ee(o, { basePath: t, baseUrl: i }))
118
121
  ), r;
119
- }, ke = async (e, t, { opfBasePath: i, baseUrl: r }) => {
120
- var s;
121
- const n = (s = e.childNamed("manifest")) == null ? void 0 : s.childrenNamed("item").find((a) => a.attr.properties === "nav");
122
- if (n) {
123
- const a = Object.values(t.files).find(
124
- (o) => o.uri.endsWith(n.attr.href || "")
122
+ }, Le = async (e, t, { baseUrl: i }) => {
123
+ var n;
124
+ const r = (n = e.childNamed("manifest")) == null ? void 0 : n.childrenNamed("item").find((s) => s.attr.properties === "nav");
125
+ if (r) {
126
+ const s = Object.values(t.files).find(
127
+ (a) => a.uri.endsWith(r.attr.href || "")
125
128
  );
126
- if (a) {
127
- const o = new F.XmlDocument(await a.string());
128
- return Te(o, { opfBasePath: i, baseUrl: r });
129
+ if (s) {
130
+ const a = new F.XmlDocument(await s.string()), o = Ne(s.uri);
131
+ return We(a, { basePath: o, baseUrl: i });
129
132
  }
130
133
  }
131
- }, ee = (e, {
134
+ }, te = (e, {
132
135
  opfBasePath: t,
133
136
  baseUrl: i,
134
137
  prefix: r
@@ -136,21 +139,21 @@ const v = {
136
139
  var o, d;
137
140
  const n = ((o = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : o.attr.src) || "", s = {
138
141
  title: ((d = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : d.val) || "",
139
- path: W(t, n),
140
- href: W(i, t, n),
142
+ path: N(t, n),
143
+ href: N(i, t, n),
141
144
  contents: []
142
145
  }, a = e.childrenNamed(`${r}navPoint`);
143
146
  return a && a.length > 0 && (s.contents = a.map(
144
- (p) => ee(p, { opfBasePath: t, baseUrl: i, prefix: r })
147
+ (p) => te(p, { opfBasePath: t, baseUrl: i, prefix: r })
145
148
  )), s;
146
- }, Se = (e, { opfBasePath: t, baseUrl: i }) => {
149
+ }, Pe = (e, { opfBasePath: t, baseUrl: i }) => {
147
150
  var a;
148
151
  const r = [], n = e.name;
149
152
  let s = "";
150
153
  return n.indexOf(":") !== -1 && (s = n.split(":")[0] + ":"), (a = e.childNamed(`${s}navMap`)) == null || a.childrenNamed(`${s}navPoint`).forEach(
151
- (o) => r.push(ee(o, { opfBasePath: t, baseUrl: i, prefix: s }))
154
+ (o) => r.push(te(o, { opfBasePath: t, baseUrl: i, prefix: s }))
152
155
  ), r;
153
- }, We = async ({
156
+ }, Ce = async ({
154
157
  opfData: e,
155
158
  opfBasePath: t,
156
159
  baseUrl: i,
@@ -166,19 +169,19 @@ const v = {
166
169
  );
167
170
  if (p) {
168
171
  const c = new F.XmlDocument(await p.string());
169
- return Se(c, { opfBasePath: t, baseUrl: i });
172
+ return Pe(c, { opfBasePath: t, baseUrl: i });
170
173
  }
171
174
  }
172
175
  }
173
- }, Ne = async (e, t, { baseUrl: i }) => {
174
- const { basePath: r } = C(t) || {}, n = await We({
176
+ }, Ie = async (e, t, { baseUrl: i }) => {
177
+ const { basePath: r } = C(t) || {}, n = await Ce({
175
178
  opfData: e,
176
179
  opfBasePath: r,
177
180
  archive: t,
178
181
  baseUrl: i
179
182
  });
180
- return n || await ke(e, t, { opfBasePath: r, baseUrl: i });
181
- }, Le = async (e) => {
183
+ return n || await Le(e, t, { opfBasePath: r, baseUrl: i });
184
+ }, Re = async (e) => {
182
185
  const t = {
183
186
  renditionLayout: void 0
184
187
  };
@@ -191,14 +194,14 @@ const v = {
191
194
  }
192
195
  })
193
196
  ), t;
194
- }, te = async ({
197
+ }, ne = async ({
195
198
  archive: e
196
199
  }) => {
197
200
  const { data: t, basePath: i } = C(e) || {}, r = await (t == null ? void 0 : t.string());
198
201
  if (!r) return [];
199
202
  const n = new F.XmlDocument(r), s = n.childNamed("manifest"), a = n.childNamed("spine"), o = a == null ? void 0 : a.childrenNamed("itemref").map((c) => c.attr.idref), d = (s == null ? void 0 : s.childrenNamed("item").filter((c) => o.includes(c.attr.id || ""))) || [];
200
203
  return e.files.filter((c) => d.find((l) => i ? `${i}/${l.attr.href}` === c.uri : `${l.attr.href}` === c.uri));
201
- }, ne = (e) => {
204
+ }, re = (e) => {
202
205
  var i;
203
206
  const t = e.childNamed("manifest");
204
207
  return ((i = t == null ? void 0 : t.childrenNamed("item")) == null ? void 0 : i.map((r) => ({
@@ -206,20 +209,20 @@ const v = {
206
209
  id: r.attr.id || "",
207
210
  mediaType: r.attr["media-type"]
208
211
  }))) || [];
209
- }, Pe = ({ archive: e, baseUrl: t }) => async (i) => {
212
+ }, je = ({ archive: e, baseUrl: t }) => async (i) => {
210
213
  var M;
211
- const { data: r, basePath: n } = C(e) || {}, s = await Le(e);
214
+ const { data: r, basePath: n } = C(e) || {}, s = await Re(e);
212
215
  if (!r)
213
216
  return i;
214
217
  const a = await r.string();
215
218
  v.log(a, s);
216
- const o = new F.XmlDocument(a), d = await Ne(o, e, { baseUrl: t }) || [], p = o.childNamed("metadata"), c = o.childNamed("manifest"), l = o.childNamed("spine"), u = o.childNamed("guide"), g = p == null ? void 0 : p.childNamed("dc:title"), b = (p == null ? void 0 : p.childrenNamed("meta")) || [], h = b.find(
219
+ const o = new F.XmlDocument(a), d = await Ie(o, e, { baseUrl: t }) || [], p = o.childNamed("metadata"), c = o.childNamed("manifest"), l = o.childNamed("spine"), u = o.childNamed("guide"), g = p == null ? void 0 : p.childNamed("dc:title"), b = (p == null ? void 0 : p.childrenNamed("meta")) || [], h = b.find(
217
220
  (m) => m.attr.property === "rendition:layout"
218
221
  ), x = b.find(
219
222
  (m) => m.attr.property === "rendition:flow"
220
223
  ), y = b.find(
221
224
  (m) => m.attr.property === "rendition:spread"
222
- ), w = h == null ? void 0 : h.val, N = x == null ? void 0 : x.val, re = y == null ? void 0 : y.val, se = (g == null ? void 0 : g.val) || ((M = e.files.find(({ dir: m }) => m)) == null ? void 0 : M.basename) || "", ie = l == null ? void 0 : l.attr["page-progression-direction"], ae = (await te({ archive: e })).reduce(
225
+ ), w = h == null ? void 0 : h.val, W = x == null ? void 0 : x.val, se = y == null ? void 0 : y.val, ie = (g == null ? void 0 : g.val) || ((M = e.files.find(({ dir: m }) => m)) == null ? void 0 : M.basename) || "", ae = l == null ? void 0 : l.attr["page-progression-direction"], oe = (await ne({ archive: e })).reduce(
223
226
  (m, f) => f.size + m,
224
227
  0
225
228
  );
@@ -229,49 +232,49 @@ const v = {
229
232
  toc: d
230
233
  },
231
234
  renditionLayout: w || s.renditionLayout || "reflowable",
232
- renditionFlow: N || "auto",
233
- renditionSpread: re,
234
- title: se,
235
- readingDirection: ie || "ltr",
235
+ renditionFlow: W || "auto",
236
+ renditionSpread: se,
237
+ title: ie,
238
+ readingDirection: ae || "ltr",
236
239
  spineItems: (l == null ? void 0 : l.childrenNamed("itemref").map((m) => {
237
- var X, B, H;
238
- const f = c == null ? void 0 : c.childrenNamed("item").find(($) => $.attr.id === (m == null ? void 0 : m.attr.idref)), oe = (f == null ? void 0 : f.attr.href) || "", I = ((X = m == null ? void 0 : m.attr.properties) == null ? void 0 : X.split(" ")) || [], ce = ((B = e.files.find(($) => $.uri.endsWith(oe))) == null ? void 0 : B.size) || 0, U = t ?? "";
240
+ var B, U, H;
241
+ const f = c == null ? void 0 : c.childrenNamed("item").find(($) => $.attr.id === (m == null ? void 0 : m.attr.idref)), ce = (f == null ? void 0 : f.attr.href) || "", I = ((B = m == null ? void 0 : m.attr.properties) == null ? void 0 : B.split(" ")) || [], de = ((U = e.files.find(($) => $.uri.endsWith(ce))) == null ? void 0 : U.size) || 0, X = t ?? "";
239
242
  return {
240
243
  id: (f == null ? void 0 : f.attr.id) || "",
241
- href: (H = f == null ? void 0 : f.attr.href) != null && H.startsWith("https://") ? f == null ? void 0 : f.attr.href : n ? `${U}${n}/${f == null ? void 0 : f.attr.href}` : `${U}${f == null ? void 0 : f.attr.href}`,
244
+ href: (H = f == null ? void 0 : f.attr.href) != null && H.startsWith("https://") ? f == null ? void 0 : f.attr.href : n ? `${X}${n}/${f == null ? void 0 : f.attr.href}` : `${X}${f == null ? void 0 : f.attr.href}`,
242
245
  renditionLayout: w || "reflowable",
243
246
  ...I.find(
244
247
  ($) => $ === "rendition:layout-reflowable"
245
248
  ) && {
246
249
  renditionLayout: "reflowable"
247
250
  },
248
- progressionWeight: ce / ae,
251
+ progressionWeight: de / oe,
249
252
  pageSpreadLeft: I.some(($) => $ === "page-spread-left") || void 0,
250
253
  pageSpreadRight: I.some(($) => $ === "page-spread-right") || void 0,
251
254
  // size: itemSize
252
255
  mediaType: f == null ? void 0 : f.attr["media-type"]
253
256
  };
254
257
  })) || [],
255
- items: ne(o),
258
+ items: re(o),
256
259
  guide: u == null ? void 0 : u.childrenNamed("reference").map((m) => ({
257
260
  href: m.attr.href || "",
258
261
  title: m.attr.title || "",
259
262
  type: m.attr.type
260
263
  }))
261
264
  };
262
- }, Ce = async (e, t) => {
265
+ }, De = async (e, t) => {
263
266
  var n, s;
264
267
  const r = await ((n = C(e).data) == null ? void 0 : n.string());
265
268
  if (r) {
266
269
  const a = new F.XmlDocument(r);
267
270
  return {
268
- mediaType: (s = ne(a).find((d) => t.endsWith(d.href))) == null ? void 0 : s.mediaType
271
+ mediaType: (s = re(a).find((d) => t.endsWith(d.href))) == null ? void 0 : s.mediaType
269
272
  };
270
273
  }
271
274
  return {
272
- mediaType: Ie(t)
275
+ mediaType: Oe(t)
273
276
  };
274
- }, Ie = (e) => {
277
+ }, Oe = (e) => {
275
278
  if (e.endsWith(".css"))
276
279
  return "text/css; charset=UTF-8";
277
280
  if (e.endsWith(".jpg"))
@@ -282,12 +285,12 @@ const v = {
282
285
  return "video/mp4";
283
286
  if (e.endsWith(".svg"))
284
287
  return "image/svg+xml";
285
- }, Re = ({ archive: e, resourcePath: t }) => async (i) => {
288
+ }, ze = ({ archive: e, resourcePath: t }) => async (i) => {
286
289
  const r = Object.values(e.files).find(
287
290
  (s) => s.uri === t
288
291
  );
289
292
  if (!r) return i;
290
- const n = await Ce(e, t);
293
+ const n = await De(e, t);
291
294
  return {
292
295
  ...i,
293
296
  params: {
@@ -300,7 +303,7 @@ const v = {
300
303
  }
301
304
  }
302
305
  };
303
- }, Q = [
306
+ }, Z = [
304
307
  "div",
305
308
  "span",
306
309
  "p",
@@ -351,19 +354,19 @@ const v = {
351
354
  "canvas",
352
355
  "script",
353
356
  "style"
354
- ], je = ({ archive: e, resourcePath: t }) => async (i) => {
357
+ ], Me = ({ archive: e, resourcePath: t }) => async (i) => {
355
358
  const r = Object.values(e.files).find(
356
359
  (n) => n.uri === t
357
360
  );
358
361
  if (r != null && r.basename.endsWith(".xhtml")) {
359
362
  const n = i.body ?? await r.string();
360
363
  if (!new RegExp(
361
- `<(${Q.join("|")})[\\s/>]`,
364
+ `<(${Z.join("|")})[\\s/>]`,
362
365
  "i"
363
366
  ).test(n))
364
367
  return i;
365
368
  const a = new RegExp(
366
- `<(${Q.join("|")})(\\s[^>]*)?\\s*/>`,
369
+ `<(${Z.join("|")})(\\s[^>]*)?\\s*/>`,
367
370
  "gi"
368
371
  ), o = n.replace(
369
372
  a,
@@ -375,7 +378,7 @@ const v = {
375
378
  };
376
379
  }
377
380
  return i;
378
- }, De = async (e, t) => {
381
+ }, Xe = async (e, t) => {
379
382
  const i = Object.values(e.files).find(
380
383
  (s) => s.uri === t
381
384
  );
@@ -384,10 +387,10 @@ const v = {
384
387
  const r = {
385
388
  params: {}
386
389
  }, n = [
387
- Re({ archive: e, resourcePath: t }),
388
- je({ archive: e, resourcePath: t }),
389
- Ae({ archive: e, resourcePath: t }),
390
- Fe({ archive: e, resourcePath: t })
390
+ ze({ archive: e, resourcePath: t }),
391
+ Me({ archive: e, resourcePath: t }),
392
+ ke({ archive: e, resourcePath: t }),
393
+ Se({ archive: e, resourcePath: t })
391
394
  ];
392
395
  try {
393
396
  const s = await n.reduce(async (a, o) => await o(await a), Promise.resolve(r));
@@ -398,7 +401,7 @@ const v = {
398
401
  } catch (s) {
399
402
  throw v.error(s), s;
400
403
  }
401
- }, Oe = ({ archive: e, baseUrl: t }) => async () => {
404
+ }, Be = ({ archive: e, baseUrl: t }) => async () => {
402
405
  var r;
403
406
  const i = Object.values(e.files).filter((n) => !n.dir);
404
407
  return {
@@ -424,7 +427,7 @@ const v = {
424
427
  href: `${t}${n.uri}`
425
428
  }))
426
429
  };
427
- }, ze = ({ archive: e }) => async (t) => {
430
+ }, Ue = ({ archive: e }) => async (t) => {
428
431
  var s;
429
432
  const i = e.files.find(
430
433
  (a) => a.basename.toLowerCase() === "comicinfo.xml"
@@ -448,22 +451,22 @@ const v = {
448
451
  return console.error(`Unable to parse comicinfo.xml for content
449
452
  `, n), console.error(a), r;
450
453
  }
451
- }, Me = (e) => {
454
+ }, He = (e) => {
452
455
  var i;
453
456
  const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((r) => r.attr.name === "viewport");
454
457
  return !!(t && t.attr.name === "viewport");
455
- }, Ue = (e) => e.reduce(async (t, i) => {
456
- if (!await t || !le({
458
+ }, Ve = (e) => e.reduce(async (t, i) => {
459
+ if (!await t || !ue({
457
460
  mimeType: i.encodingFormat,
458
461
  uri: i.uri
459
462
  }))
460
463
  return !1;
461
464
  const n = await i.string();
462
- return n ? Me(new F.XmlDocument(n)) : !1;
463
- }, Promise.resolve(!0)), Xe = ({ archive: e }) => async (t) => {
465
+ return n ? He(new F.XmlDocument(n)) : !1;
466
+ }, Promise.resolve(!0)), _e = ({ archive: e }) => async (t) => {
464
467
  if (t.renditionLayout === "reflowable" && t.spineItems.every((r) => r.renditionLayout === "reflowable")) {
465
- const r = await te({ archive: e });
466
- if (await Ue(r))
468
+ const r = await ne({ archive: e });
469
+ if (await Ve(r))
467
470
  return {
468
471
  ...t,
469
472
  spineItems: t.spineItems.map((s) => ({
@@ -481,7 +484,7 @@ const v = {
481
484
  if (i[s] !== r[s])
482
485
  return (n = i[s]) != null && n.match(/\d/) ? +(i[s] || "") - +(r[s] || "") : (i[s] || "").localeCompare(r[s] || "");
483
486
  return 1;
484
- }, Be = ({ archive: e, baseUrl: t }) => async (i) => {
487
+ }, qe = ({ archive: e, baseUrl: t }) => async (i) => {
485
488
  if (i.nav) return i;
486
489
  const r = [...e.files].sort(
487
490
  (o, d) => z(o.uri, d.uri)
@@ -537,7 +540,7 @@ const v = {
537
540
  if (d.dir) return o;
538
541
  const c = d.uri.split("/").slice(0, -1), [l, ...u] = c;
539
542
  if (l) {
540
- const g = W(t, encodeURI(d.uri)).replace(/\/$/, ""), b = d.uri.replace(/\/$/, "");
543
+ const g = N(t, encodeURI(d.uri)).replace(/\/$/, ""), b = d.uri.replace(/\/$/, "");
541
544
  return s(o, l, u, g, b);
542
545
  }
543
546
  return o;
@@ -550,7 +553,7 @@ const v = {
550
553
  toc: a
551
554
  }
552
555
  };
553
- }, He = {
556
+ }, Ge = {
554
557
  filename: "",
555
558
  items: [],
556
559
  nav: {
@@ -561,21 +564,21 @@ const v = {
561
564
  renditionSpread: "auto",
562
565
  spineItems: [],
563
566
  title: ""
564
- }, Ve = async (e, { baseUrl: t = "" } = {}) => {
567
+ }, Ke = async (e, { baseUrl: t = "" } = {}) => {
565
568
  const i = [
566
- Oe({ archive: e, baseUrl: t }),
567
- Pe({ archive: e, baseUrl: t }),
568
- Xe({ archive: e, baseUrl: t }),
569
- ze({ archive: e, baseUrl: t }),
570
- Be({ archive: e, baseUrl: t })
569
+ Be({ archive: e, baseUrl: t }),
570
+ je({ archive: e, baseUrl: t }),
571
+ _e({ archive: e, baseUrl: t }),
572
+ Ue({ archive: e, baseUrl: t }),
573
+ qe({ archive: e, baseUrl: t })
571
574
  ];
572
575
  try {
573
- const r = await i.reduce(async (n, s) => await s(await n), Promise.resolve(He));
576
+ const r = await i.reduce(async (n, s) => await s(await n), Promise.resolve(Ge));
574
577
  return v.log("Generated manifest", r), r;
575
578
  } catch (r) {
576
579
  throw v.error(r), r;
577
580
  }
578
- }, T = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Z = (e) => e.endsWith("/") ? e.slice(0, -1) : e, Ze = async (e, t) => {
581
+ }, nt = async (e, t) => {
579
582
  const i = `
580
583
  <?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
581
584
  <metadata>
@@ -614,7 +617,7 @@ const v = {
614
617
  }, ...r],
615
618
  close: () => Promise.resolve()
616
619
  };
617
- }, Ee = async (e, {
620
+ }, rt = async (e, {
618
621
  mimeType: t,
619
622
  direction: i
620
623
  } = { mimeType: "text/plain" }) => {
@@ -657,7 +660,7 @@ const v = {
657
660
  ],
658
661
  close: () => Promise.resolve()
659
662
  };
660
- }, et = async (e, { orderByAlpha: t, name: i } = {}) => {
663
+ }, st = async (e, { orderByAlpha: t, name: i } = {}) => {
661
664
  let r = Object.values(e.files);
662
665
  t && (r = r.slice().sort((s, a) => z(s.name, a.name)));
663
666
  const n = {
@@ -679,7 +682,7 @@ const v = {
679
682
  close: () => Promise.resolve()
680
683
  };
681
684
  return v.log("Generated archive", n), n;
682
- }, tt = async (e, { name: t } = {}) => {
685
+ }, it = async (e, { name: t } = {}) => {
683
686
  const i = await e.getFilesArray(), r = {
684
687
  close: () => e.close(),
685
688
  filename: t ?? "",
@@ -693,7 +696,7 @@ const v = {
693
696
  }))
694
697
  };
695
698
  return v.log("Generated archive", r), r;
696
- }, nt = async (e, { orderByAlpha: t, name: i } = {}) => {
699
+ }, at = async (e, { orderByAlpha: t, name: i } = {}) => {
697
700
  let r = e;
698
701
  return t && (r = r.slice().sort((n, s) => z(n.name, s.name))), {
699
702
  filename: i || "",
@@ -713,14 +716,14 @@ const v = {
713
716
  })),
714
717
  close: () => Promise.resolve()
715
718
  };
716
- }, rt = ({
719
+ }, ot = ({
717
720
  enableReport: e
718
721
  } = {}) => {
719
722
  v.enable(!!e);
720
723
  };
721
- class _e {
724
+ class Je {
722
725
  constructor(t) {
723
- this.cleanArchiveAfter = t, this.state$ = new ge({
726
+ this.cleanArchiveAfter = t, this.state$ = new we({
724
727
  status: "idle",
725
728
  locks: 0
726
729
  });
@@ -737,19 +740,19 @@ class _e {
737
740
  get isUnlocked$() {
738
741
  return this.locks$.pipe(
739
742
  A((t) => t <= 0),
740
- ye(),
741
- be()
743
+ ve(),
744
+ $e()
742
745
  );
743
746
  }
744
747
  get overTTL$() {
745
748
  return this.isUnlocked$.pipe(
746
- S(
747
- (t) => t ? this.cleanArchiveAfter === 1 / 0 ? G : we(this.cleanArchiveAfter) : G
749
+ k(
750
+ (t) => t ? this.cleanArchiveAfter === 1 / 0 ? G : xe(this.cleanArchiveAfter) : G
748
751
  )
749
752
  );
750
753
  }
751
754
  }
752
- const qe = ({
755
+ const Ye = ({
753
756
  getArchive: e,
754
757
  cleanArchiveAfter: t = 5 * 60 * 1e3
755
758
  // 5mn
@@ -760,17 +763,17 @@ const qe = ({
760
763
  if (!c || c.state.status !== "idle") return _;
761
764
  let l = !1;
762
765
  const u = (y) => {
763
- var N;
766
+ var W;
764
767
  const w = s[y];
765
- delete s[y], l || ((N = w == null ? void 0 : w.state.archive) == null || N.close(), l = !0);
768
+ delete s[y], l || ((W = w == null ? void 0 : w.state.archive) == null || W.close(), l = !0);
766
769
  };
767
770
  c.update({
768
771
  status: "loading"
769
772
  });
770
773
  const g = c.locks$, b = c.isUnlocked$, h = g.pipe(
771
- pe(),
774
+ me(),
772
775
  j(([y, w]) => w > y),
773
- fe(!0)
776
+ he(!0)
774
777
  );
775
778
  return L(e(p)).pipe(
776
779
  D((y) => {
@@ -783,10 +786,10 @@ const qe = ({
783
786
  status: "error",
784
787
  error: y
785
788
  }), _)),
786
- S(() => {
789
+ k(() => {
787
790
  const y = h.pipe(
788
- S(() => n),
789
- S(() => b),
791
+ k(() => n),
792
+ k(() => b),
790
793
  j((w) => w)
791
794
  );
792
795
  return q(y, c.overTTL$);
@@ -796,10 +799,10 @@ const qe = ({
796
799
  })
797
800
  );
798
801
  }),
799
- ue(r)
802
+ ge(r)
800
803
  ), o = (p) => {
801
804
  let c = !1;
802
- const l = s[p] ?? new _e(t);
805
+ const l = s[p] ?? new Je(t);
803
806
  s[p] = l, l.update({
804
807
  locks: l.state.locks + 1
805
808
  });
@@ -817,10 +820,10 @@ const qe = ({
817
820
  if (h)
818
821
  throw h;
819
822
  }),
820
- me()
823
+ ye()
821
824
  );
822
825
  return q(g, b).pipe(
823
- he(),
826
+ be(),
824
827
  A((h) => ({ archive: h, release: u })),
825
828
  P((h) => {
826
829
  throw u(), h;
@@ -835,13 +838,13 @@ const qe = ({
835
838
  archives: s
836
839
  };
837
840
  };
838
- class Ge {
841
+ class Qe {
839
842
  constructor({
840
843
  onError: t,
841
844
  onManifestSuccess: i,
842
845
  ...r
843
846
  }) {
844
- this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = qe(r), this.onManifestSuccess = i ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
847
+ this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = Ye(r), this.onManifestSuccess = i ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
845
848
  }
846
849
  prune() {
847
850
  this.epubLoader.purge();
@@ -857,9 +860,9 @@ class Ge {
857
860
  fetchManifest({ key: t, baseUrl: i }) {
858
861
  const r = this.accessArchive(t).pipe(
859
862
  O(({ archive: n, release: s }) => L(
860
- Ve(n, { baseUrl: i })
863
+ Ke(n, { baseUrl: i })
861
864
  ).pipe(
862
- S(
865
+ k(
863
866
  (o) => L(this.onManifestSuccess({ manifest: o, archive: n }))
864
867
  ),
865
868
  A(
@@ -881,7 +884,7 @@ class Ge {
881
884
  }) {
882
885
  const r = this.accessArchive(t).pipe(
883
886
  O(({ archive: n, release: s }) => L(
884
- De(n, i)
887
+ Xe(n, i)
885
888
  ).pipe(
886
889
  A(
887
890
  (o) => new Response(o.body, {
@@ -902,7 +905,7 @@ class Ge {
902
905
  return Y(r);
903
906
  }
904
907
  }
905
- class st extends Ge {
908
+ class ct extends Qe {
906
909
  constructor({
907
910
  getUriInfo: t,
908
911
  ...i
@@ -913,10 +916,10 @@ class st extends Ge {
913
916
  try {
914
917
  const i = this.getUriInfo(t);
915
918
  if (!i) return;
916
- const r = Z(i.baseUrl), n = t.request.url.substring(
919
+ const r = Q(i.baseUrl), n = t.request.url.substring(
917
920
  r.length + 1
918
921
  ), [s = ""] = n.split("/"), a = decodeURIComponent(
919
- Z(n.substring(s.length + 1))
922
+ Q(n.substring(s.length + 1))
920
923
  );
921
924
  n.endsWith("/manifest") ? t.respondWith(
922
925
  this.fetchManifest({ key: s, baseUrl: `${r}/${s}/` })
@@ -927,16 +930,16 @@ class st extends Ge {
927
930
  }
928
931
  }
929
932
  export {
930
- st as ServiceWorkerStreamer,
931
- Ge as Streamer,
932
- rt as configure,
933
- nt as createArchiveFromArrayBufferList,
934
- et as createArchiveFromJszip,
935
- tt as createArchiveFromLibArchive,
936
- Ee as createArchiveFromText,
937
- Ze as createArchiveFromUrls,
938
- Ve as generateManifestFromArchive,
939
- De as generateResourceFromArchive,
933
+ ct as ServiceWorkerStreamer,
934
+ Qe as Streamer,
935
+ ot as configure,
936
+ at as createArchiveFromArrayBufferList,
937
+ st as createArchiveFromJszip,
938
+ it as createArchiveFromLibArchive,
939
+ rt as createArchiveFromText,
940
+ nt as createArchiveFromUrls,
941
+ Ke as generateManifestFromArchive,
942
+ Xe as generateResourceFromArchive,
940
943
  C as getArchiveOpfInfo
941
944
  };
942
945
  //# sourceMappingURL=index.js.map