@prose-reader/streamer 1.134.0 → 1.135.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,8 +1,8 @@
1
- import x, { XmlDocument as de, XmlTextNode as le, XmlElement as pe } from "xmldoc";
2
- import { urlJoin as L, isXmlBasedMimeType as fe, parseContentType as ue, detectMimeTypeFromName as O } from "@prose-reader/shared";
3
- import { Subject as R, mergeMap as M, EMPTY as _, pairwise as me, filter as j, startWith as he, from as P, tap as D, catchError as I, switchMap as k, merge as q, takeUntil as ge, map as F, 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";
1
+ import $, { XmlDocument as de, XmlTextNode as le, XmlElement as pe } from "xmldoc";
2
+ import { urlJoin as k, isXmlBasedMimeType as fe, parseContentType as ue, detectMimeTypeFromName as D } from "@prose-reader/shared";
3
+ import { Subject as R, mergeMap as M, EMPTY as _, pairwise as me, filter as j, startWith as he, from as P, tap as O, catchError as I, switchMap as W, merge as q, takeUntil as ge, map as F, 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
4
  let T = !1;
5
- const v = {
5
+ const w = {
6
6
  enable: (e) => {
7
7
  T = e;
8
8
  },
@@ -39,11 +39,11 @@ const v = {
39
39
  const n = performance.now(), s = i(...r);
40
40
  if (s && s.then)
41
41
  return s.then((a) => {
42
- const d = performance.now();
43
- return v.metric({ name: e, duration: d - n }, t), a;
42
+ const c = performance.now();
43
+ return w.metric({ name: e, duration: c - n }, t), a;
44
44
  });
45
45
  const o = performance.now();
46
- return v.metric({ name: e, duration: o - n }, t), s;
46
+ return w.metric({ name: e, duration: o - n }, t), s;
47
47
  }
48
48
  }, Fe = (e) => {
49
49
  var i;
@@ -69,7 +69,7 @@ const v = {
69
69
  }
70
70
  }
71
71
  return i;
72
- }, We = ({ archive: e, resourcePath: t }) => async (i) => Te({ archive: e, resourcePath: t })(i), ke = ({ archive: e, resourcePath: t }) => async (i) => {
72
+ }, Le = ({ archive: e, resourcePath: t }) => async (i) => Te({ archive: e, resourcePath: t })(i), We = ({ archive: e, resourcePath: t }) => async (i) => {
73
73
  const r = Object.values(e.files).find(
74
74
  (n) => n.uri === t
75
75
  );
@@ -84,7 +84,7 @@ const v = {
84
84
  };
85
85
  }
86
86
  return i;
87
- }, ee = (e) => e ? e.children.map((t) => t instanceof le ? t.text : t instanceof pe ? ee(t) : "").join("").trim() : "", A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Q = (e) => e.endsWith("/") ? e.slice(0, -1) : e, Le = (e) => {
87
+ }, ee = (e) => e ? e.children.map((t) => t instanceof le ? t.text : t instanceof pe ? ee(t) : "").join("").trim() : "", A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Q = (e) => e.endsWith("/") ? e.slice(0, -1) : e, ke = (e) => {
88
88
  const t = e.lastIndexOf("/");
89
89
  return t >= 0 ? e.substring(0, t) : "";
90
90
  }, te = (e, { basePath: t, baseUrl: i }) => {
@@ -97,23 +97,23 @@ const v = {
97
97
  let n = e.childNamed("span") || e.childNamed("a");
98
98
  r.title = ((n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || ee(n)) ?? "";
99
99
  let s = n == null ? void 0 : n.name;
100
- s !== "a" && (n = e.descendantWithPath(`${s}.a`), n && (s = n.name.toLowerCase())), s === "a" && (n != null && n.attr.href) && (r.path = L(t, n.attr.href), r.href = L(i, t, n.attr.href));
100
+ s !== "a" && (n = e.descendantWithPath(`${s}.a`), n && (s = n.name.toLowerCase())), s === "a" && (n != null && n.attr.href) && (r.path = k(t, n.attr.href), r.href = k(i, t, n.attr.href));
101
101
  const o = e.childNamed("ol");
102
102
  if (o) {
103
103
  const a = o.childrenNamed("li");
104
104
  a && a.length > 0 && (r.contents = a.map(
105
- (d) => te(d, { basePath: t, baseUrl: i })
105
+ (c) => te(c, { basePath: t, baseUrl: i })
106
106
  ));
107
107
  }
108
108
  return r;
109
- }, Se = (e, { basePath: t, baseUrl: i }) => {
109
+ }, Ne = (e, { basePath: t, baseUrl: i }) => {
110
110
  var s, o;
111
111
  const r = [];
112
112
  let n;
113
113
  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 = (o = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : o.children), n && n.length > 0 && n.filter((a) => a.name === "li").forEach(
114
114
  (a) => r.push(te(a, { basePath: t, baseUrl: i }))
115
115
  ), r;
116
- }, Ne = async (e, t, { baseUrl: i }) => {
116
+ }, Se = async (e, t, { baseUrl: i }) => {
117
117
  var n;
118
118
  const r = (n = e.childNamed("manifest")) == null ? void 0 : n.childrenNamed("item").find((s) => s.attr.properties === "nav");
119
119
  if (r) {
@@ -121,8 +121,8 @@ const v = {
121
121
  (o) => o.uri.endsWith(r.attr.href || "")
122
122
  );
123
123
  if (s) {
124
- const o = new x.XmlDocument(await s.string()), a = Le(s.uri);
125
- return Se(o, { basePath: a, baseUrl: i });
124
+ const o = new $.XmlDocument(await s.string()), a = ke(s.uri);
125
+ return Ne(o, { basePath: a, baseUrl: i });
126
126
  }
127
127
  }
128
128
  }, ne = (e, {
@@ -130,15 +130,15 @@ const v = {
130
130
  baseUrl: i,
131
131
  prefix: r
132
132
  }) => {
133
- var a, d;
133
+ var a, c;
134
134
  const n = ((a = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : a.attr.src) || "", s = {
135
- title: ((d = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : d.val) || "",
136
- path: L(t, n),
137
- href: L(i, t, n),
135
+ title: ((c = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : c.val) || "",
136
+ path: k(t, n),
137
+ href: k(i, t, n),
138
138
  contents: []
139
139
  }, o = e.childrenNamed(`${r}navPoint`);
140
140
  return o && o.length > 0 && (s.contents = o.map(
141
- (p) => ne(p, { opfBasePath: t, baseUrl: i, prefix: r })
141
+ (l) => ne(l, { opfBasePath: t, baseUrl: i, prefix: r })
142
142
  )), s;
143
143
  }, Pe = (e, { opfBasePath: t, baseUrl: i }) => {
144
144
  var o;
@@ -156,25 +156,25 @@ const v = {
156
156
  var o;
157
157
  const n = e.childNamed("spine"), s = n && n.attr.toc;
158
158
  if (s) {
159
- const a = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((d) => d.attr.id === s);
159
+ const a = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((c) => c.attr.id === s);
160
160
  if (a) {
161
- const d = `${t}${t === "" ? "" : "/"}${a.attr.href}`, p = Object.values(r.files).find(
162
- (c) => c.uri.endsWith(d)
161
+ const c = `${t}${t === "" ? "" : "/"}${a.attr.href}`, l = Object.values(r.files).find(
162
+ (d) => d.uri.endsWith(c)
163
163
  );
164
- if (p) {
165
- const c = new x.XmlDocument(await p.string());
166
- return Pe(c, { opfBasePath: t, baseUrl: i });
164
+ if (l) {
165
+ const d = new $.XmlDocument(await l.string());
166
+ return Pe(d, { opfBasePath: t, baseUrl: i });
167
167
  }
168
168
  }
169
169
  }
170
170
  }, Ce = async (e, t, { baseUrl: i }) => {
171
- const { basePath: r } = S(t) || {}, n = await Ie({
171
+ const { basePath: r } = N(t) || {}, n = await Ie({
172
172
  opfData: e,
173
173
  opfBasePath: r,
174
174
  archive: t,
175
175
  baseUrl: i
176
176
  });
177
- return n || await Ne(e, t, { opfBasePath: r, baseUrl: i });
177
+ return n || await Se(e, t, { opfBasePath: r, baseUrl: i });
178
178
  }, Re = (e) => {
179
179
  var r;
180
180
  const t = ((r = e.attr.properties) == null ? void 0 : r.split(" ")) || [];
@@ -184,7 +184,7 @@ const v = {
184
184
  pageSpreadLeft: t.some((n) => n === "page-spread-left") || void 0,
185
185
  pageSpreadRight: t.some((n) => n === "page-spread-right") || void 0
186
186
  };
187
- }, S = (e) => {
187
+ }, N = (e) => {
188
188
  const i = Object.values(e.files).filter((r) => !r.dir).find((r) => r.uri.endsWith(".opf"));
189
189
  return {
190
190
  data: i,
@@ -193,10 +193,10 @@ const v = {
193
193
  }, re = async ({
194
194
  archive: e
195
195
  }) => {
196
- const { data: t, basePath: i } = S(e) || {}, r = await (t == null ? void 0 : t.string());
196
+ const { data: t, basePath: i } = N(e) || {}, r = await (t == null ? void 0 : t.string());
197
197
  if (!r) return [];
198
- const n = new x.XmlDocument(r), s = n.childNamed("manifest"), o = n.childNamed("spine"), a = o == null ? void 0 : o.childrenNamed("itemref").map((c) => c.attr.idref), d = (s == null ? void 0 : s.childrenNamed("item").filter((c) => a.includes(c.attr.id || ""))) || [];
199
- return e.files.filter((c) => d.find((l) => i ? `${i}/${l.attr.href}` === c.uri : `${l.attr.href}` === c.uri));
198
+ const n = new $.XmlDocument(r), s = n.childNamed("manifest"), o = n.childNamed("spine"), a = o == null ? void 0 : o.childrenNamed("itemref").map((d) => d.attr.idref), c = (s == null ? void 0 : s.childrenNamed("item").filter((d) => a.includes(d.attr.id || ""))) || [];
199
+ return e.files.filter((d) => c.find((p) => i ? `${i}/${p.attr.href}` === d.uri : `${p.attr.href}` === d.uri));
200
200
  }, je = (e, t, i) => {
201
201
  const r = e.attr.href || "", n = i == null ? void 0 : i(e);
202
202
  return {
@@ -206,21 +206,23 @@ const v = {
206
206
  };
207
207
  }, se = (e, t, i) => {
208
208
  var s;
209
- const r = e.childNamed("manifest"), { basePath: n } = S(t) || {};
209
+ const r = e.childNamed("manifest"), { basePath: n } = N(t) || {};
210
210
  return ((s = r == null ? void 0 : r.childrenNamed("item")) == null ? void 0 : s.map((o) => je(o, n, i))) || [];
211
- }, De = ({ archive: e, baseUrl: t }) => async (i) => {
211
+ }, Oe = ({ archive: e, baseUrl: t }) => async (i) => {
212
212
  var X;
213
- const { data: r, basePath: n } = S(e) || {};
213
+ const { data: r, basePath: n } = N(e) || {};
214
214
  if (!r)
215
215
  return i;
216
- const s = await r.string(), o = new x.XmlDocument(s), a = await Ce(o, e, { baseUrl: t }) || [], d = o.childNamed("metadata"), p = o.childNamed("manifest"), c = o.childNamed("spine"), l = o.childNamed("guide"), u = d == null ? void 0 : d.childNamed("dc:title"), g = (d == null ? void 0 : d.childrenNamed("meta")) || [], b = g.find(
216
+ const s = await r.string();
217
+ w.log("data", s);
218
+ const o = new $.XmlDocument(s), a = await Ce(o, e, { baseUrl: t }) || [], c = o.childNamed("metadata"), l = o.childNamed("manifest"), d = o.childNamed("spine"), p = o.childNamed("guide"), u = c == null ? void 0 : c.childNamed("dc:title"), g = (c == null ? void 0 : c.childrenNamed("meta")) || [], b = g.find(
217
219
  (m) => m.attr.property === "rendition:layout"
218
220
  ), h = g.find(
219
221
  (m) => m.attr.property === "rendition:flow"
220
- ), $ = g.find(
222
+ ), x = g.find(
221
223
  (m) => m.attr.property === "rendition:spread"
222
- ), y = b == null ? void 0 : b.val, w = h == null ? void 0 : h.val, N = $ == null ? void 0 : $.val, ie = (u == null ? void 0 : u.val) || ((X = e.files.find(({ dir: m }) => m)) == null ? void 0 : X.basename) || "", oe = c == null ? void 0 : c.attr["page-progression-direction"], ae = (await re({ archive: e })).reduce(
223
- (m, W) => W.size + m,
224
+ ), y = b == null ? void 0 : b.val, v = h == null ? void 0 : h.val, S = x == null ? void 0 : x.val, ie = (u == null ? void 0 : u.val) || ((X = e.files.find(({ dir: m }) => m)) == null ? void 0 : X.basename) || "", oe = d == null ? void 0 : d.attr["page-progression-direction"], ae = (await re({ archive: e })).reduce(
225
+ (m, L) => L.size + m,
224
226
  0
225
227
  );
226
228
  return {
@@ -229,20 +231,20 @@ const v = {
229
231
  toc: a
230
232
  },
231
233
  renditionLayout: y,
232
- renditionFlow: w || "auto",
233
- renditionSpread: N,
234
+ renditionFlow: v || "auto",
235
+ renditionSpread: S,
234
236
  title: ie,
235
237
  readingDirection: oe || "ltr",
236
238
  /**
237
239
  * @see https://www.w3.org/TR/epub/#sec-itemref-elem
238
240
  */
239
- spineItems: (c == null ? void 0 : c.childrenNamed("itemref").map((m, W) => {
241
+ spineItems: (d == null ? void 0 : d.childrenNamed("itemref").map((m, L) => {
240
242
  var V, E;
241
- const f = p == null ? void 0 : p.childrenNamed("item").find((C) => C.attr.id === (m == null ? void 0 : m.attr.idref)), B = (f == null ? void 0 : f.attr.href) || "", ce = ((V = e.files.find((C) => C.uri.endsWith(B))) == null ? void 0 : V.size) || 0, H = t || (/^https?:\/\//.test(B) ? "" : "file://"), U = Re(m);
243
+ const f = l == null ? void 0 : l.childrenNamed("item").find((C) => C.attr.id === (m == null ? void 0 : m.attr.idref)), B = (f == null ? void 0 : f.attr.href) || "", ce = ((V = e.files.find((C) => C.uri.endsWith(B))) == null ? void 0 : V.size) || 0, H = t || (/^https?:\/\//.test(B) ? "" : "file://"), U = Re(m);
242
244
  return {
243
245
  ...U,
244
246
  id: (f == null ? void 0 : f.attr.id) || "",
245
- index: W,
247
+ index: L,
246
248
  href: (E = f == null ? void 0 : f.attr.href) != null && E.startsWith("https://") ? f == null ? void 0 : f.attr.href : n ? `${H}${n}/${f == null ? void 0 : f.attr.href}` : `${H}${f == null ? void 0 : f.attr.href}`,
247
249
  renditionLayout: U.renditionLayout ?? y,
248
250
  progressionWeight: ce / ae,
@@ -251,25 +253,25 @@ const v = {
251
253
  };
252
254
  })) || [],
253
255
  items: se(o, e, (m) => {
254
- const W = m.attr.href || "";
255
- return /^https?:\/\//.test(W) ? "" : t || "file://";
256
+ const L = m.attr.href || "";
257
+ return /^https?:\/\//.test(L) ? "" : t || "file://";
256
258
  }),
257
- guide: l == null ? void 0 : l.childrenNamed("reference").map((m) => ({
259
+ guide: p == null ? void 0 : p.childrenNamed("reference").map((m) => ({
258
260
  href: m.attr.href || "",
259
261
  title: m.attr.title || "",
260
262
  type: m.attr.type
261
263
  }))
262
264
  };
263
- }, Oe = async (e, t) => {
265
+ }, De = async (e, t) => {
264
266
  var n, s, o;
265
- const r = await ((n = S(e).data) == null ? void 0 : n.string());
267
+ const r = await ((n = N(e).data) == null ? void 0 : n.string());
266
268
  if (r) {
267
- const a = new x.XmlDocument(r), d = se(a, e, () => "");
268
- if ((s = d.find(
269
- (c) => t.endsWith(c.href)
269
+ const a = new $.XmlDocument(r), c = se(a, e, () => "");
270
+ if ((s = c.find(
271
+ (d) => t.endsWith(d.href)
270
272
  )) == null ? void 0 : s.mediaType)
271
273
  return {
272
- mediaType: (o = d.find((c) => t.endsWith(c.href))) == null ? void 0 : o.mediaType
274
+ mediaType: (o = c.find((d) => t.endsWith(d.href))) == null ? void 0 : o.mediaType
273
275
  };
274
276
  }
275
277
  return {
@@ -291,7 +293,7 @@ const v = {
291
293
  (s) => s.uri === t
292
294
  );
293
295
  if (!r) return i;
294
- const n = await Oe(e, t);
296
+ const n = await De(e, t);
295
297
  return {
296
298
  ...i,
297
299
  params: {
@@ -371,7 +373,7 @@ const v = {
371
373
  "gi"
372
374
  ), a = n.replace(
373
375
  o,
374
- (d, p, c = "") => `<${p} ${c.trim()}></${p}>`
376
+ (c, l, d = "") => `<${l} ${d.trim()}></${l}>`
375
377
  );
376
378
  return {
377
379
  ...i,
@@ -390,17 +392,17 @@ const v = {
390
392
  }, n = [
391
393
  ze({ archive: e, resourcePath: t }),
392
394
  Xe({ archive: e, resourcePath: t }),
393
- ke({ archive: e, resourcePath: t }),
394
- We({ archive: e, resourcePath: t })
395
+ We({ archive: e, resourcePath: t }),
396
+ Le({ archive: e, resourcePath: t })
395
397
  ];
396
398
  try {
397
399
  const s = await n.reduce(async (o, a) => await a(await o), Promise.resolve(r));
398
- return v.log("Generated resource", t, s), {
400
+ return w.log("Generated resource", t, s), {
399
401
  ...s,
400
402
  body: s.body ?? await i.blob()
401
403
  };
402
404
  } catch (s) {
403
- throw v.error(s), s;
405
+ throw w.error(s), s;
404
406
  }
405
407
  }, He = ({ archive: e, baseUrl: t }) => async () => {
406
408
  var r;
@@ -437,7 +439,7 @@ const v = {
437
439
  e.files.map(async (i) => {
438
440
  var r, n;
439
441
  if (i.uri.endsWith("com.kobobooks.display-options.xml")) {
440
- const o = (r = new x.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : r.childNamed("option");
442
+ const o = (r = new $.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : r.childNamed("option");
441
443
  ((n = o == null ? void 0 : o.attr) == null ? void 0 : n.name) === "fixed-layout" && o.val === "true" && (t.renditionLayout = "pre-paginated");
442
444
  }
443
445
  })
@@ -459,7 +461,7 @@ const v = {
459
461
  }))
460
462
  return !1;
461
463
  const n = await i.string();
462
- return n ? Ee(new x.XmlDocument(n)) : !1;
464
+ return n ? Ee(new $.XmlDocument(n)) : !1;
463
465
  }, Promise.resolve(!0)), qe = ({ archive: e }) => async (t) => {
464
466
  if (t.renditionLayout === "reflowable" && t.spineItems.every((r) => r.renditionLayout === "reflowable")) {
465
467
  const r = await re({ archive: e });
@@ -484,11 +486,11 @@ const v = {
484
486
  }, Ge = ({ archive: e, baseUrl: t }) => async (i) => {
485
487
  if (i.nav) return i;
486
488
  const r = [...e.files].sort(
487
- (a, d) => z(a.uri, d.uri)
488
- ), n = Object.values(r), s = (a, d, p, c, l) => {
489
- const u = a.find((h) => h.title === d), [g, ...b] = p;
489
+ (a, c) => z(a.uri, c.uri)
490
+ ), n = Object.values(r), s = (a, c, l, d, p) => {
491
+ const u = a.find((h) => h.title === c), [g, ...b] = l;
490
492
  return u ? g ? [
491
- ...a.filter(($) => $ != u),
493
+ ...a.filter((x) => x != u),
492
494
  {
493
495
  ...u,
494
496
  contents: [
@@ -497,17 +499,17 @@ const v = {
497
499
  u.contents,
498
500
  g,
499
501
  b,
500
- c,
501
- l
502
+ d,
503
+ p
502
504
  )
503
505
  ]
504
506
  }
505
- ] : u.path.split("/").length > l.split("/").length ? [
506
- ...a.filter(($) => $ != u),
507
+ ] : u.path.split("/").length > p.split("/").length ? [
508
+ ...a.filter((x) => x != u),
507
509
  {
508
510
  ...u,
509
- path: l,
510
- href: c
511
+ path: p,
512
+ href: d
511
513
  }
512
514
  ] : a : g ? [
513
515
  ...a,
@@ -516,29 +518,29 @@ const v = {
516
518
  [],
517
519
  g,
518
520
  b,
519
- c,
520
- l
521
+ d,
522
+ p
521
523
  ),
522
- href: c,
523
- path: l,
524
- title: d
524
+ href: d,
525
+ path: p,
526
+ title: c
525
527
  }
526
528
  ] : [
527
529
  ...a,
528
530
  {
529
531
  contents: [],
530
- href: c,
531
- path: l,
532
- title: d
532
+ href: d,
533
+ path: p,
534
+ title: c
533
535
  }
534
536
  ];
535
537
  }, o = n.reduce(
536
- (a, d) => {
537
- if (d.dir) return a;
538
- const c = d.uri.split("/").slice(0, -1), [l, ...u] = c;
539
- if (l) {
540
- const g = L(t, encodeURI(d.uri)).replace(/\/$/, ""), b = d.uri.replace(/\/$/, "");
541
- return s(a, l, u, g, b);
538
+ (a, c) => {
539
+ if (c.dir) return a;
540
+ const d = c.uri.split("/").slice(0, -1), [p, ...u] = d;
541
+ if (p) {
542
+ const g = k(t, encodeURI(c.uri)).replace(/\/$/, ""), b = c.uri.replace(/\/$/, "");
543
+ return s(a, p, u, g, b);
542
544
  }
543
545
  return a;
544
546
  },
@@ -559,13 +561,13 @@ const v = {
559
561
  return t;
560
562
  const r = {
561
563
  ...t,
562
- spineItems: t.spineItems.filter((o) => !o.id.toLowerCase().endsWith("comicinfo.xml")).map((o, a, d) => ({
564
+ spineItems: t.spineItems.filter((o) => !o.id.toLowerCase().endsWith("comicinfo.xml")).map((o, a, c) => ({
563
565
  ...o,
564
- progressionWeight: 1 / d.length
566
+ progressionWeight: 1 / c.length
565
567
  }))
566
568
  }, n = await i.string();
567
569
  try {
568
- const a = ((s = new x.XmlDocument(n).childNamed("Manga")) == null ? void 0 : s.val) || "unknown";
570
+ const a = ((s = new $.XmlDocument(n).childNamed("Manga")) == null ? void 0 : s.val) || "unknown";
569
571
  return {
570
572
  ...r,
571
573
  readingDirection: a === "YesAndRightToLeft" ? "rtl" : "ltr"
@@ -579,16 +581,39 @@ const v = {
579
581
  spineItems: t.spineItems.map((r) => {
580
582
  const n = e.files.find(
581
583
  (o) => decodeURI(r.href).endsWith(o.uri)
582
- ), s = ue((n == null ? void 0 : n.encodingFormat) ?? "") ?? O((n == null ? void 0 : n.basename) ?? "");
584
+ ), s = ue((n == null ? void 0 : n.encodingFormat) ?? "") ?? D((n == null ? void 0 : n.basename) ?? "");
583
585
  return {
584
586
  ...r,
585
587
  renditionLayout: s != null && s.startsWith("image/") ? "pre-paginated" : r.renditionLayout
586
588
  };
587
589
  })
588
- }, Qe = async (e, { baseUrl: t = "" } = {}) => {
590
+ }, Qe = ({ archive: e }) => async (t) => {
591
+ var n, s;
592
+ const i = e.files.find(
593
+ (o) => o.basename.toLowerCase() === "com.apple.ibooks.display-options.xml"
594
+ );
595
+ if (!i)
596
+ return t;
597
+ const r = await (await i.blob()).text();
598
+ try {
599
+ console.log("FOOO", r);
600
+ const a = new $.XmlDocument(r).childNamed("platform"), c = ((s = (n = a == null ? void 0 : a.childrenNamed("option")) == null ? void 0 : n.find((l) => l.attr.name === "fixed-layout")) == null ? void 0 : s.val) || "false";
601
+ return {
602
+ ...t,
603
+ renditionLayout: c === "true" ? "pre-paginated" : t.renditionLayout
604
+ };
605
+ } catch (o) {
606
+ return console.error(
607
+ `Unable to parse com.apple.ibooks.display-options.xml for content
608
+ `,
609
+ r
610
+ ), console.error(o), t;
611
+ }
612
+ }, Ze = async (e, { baseUrl: t = "" } = {}) => {
589
613
  const i = [
590
- De({ archive: e, baseUrl: t }),
614
+ Oe({ archive: e, baseUrl: t }),
591
615
  Ke({ archive: e, baseUrl: t }),
616
+ Qe({ archive: e, baseUrl: t }),
592
617
  Ye({ archive: e, baseUrl: t }),
593
618
  qe({ archive: e, baseUrl: t }),
594
619
  Ve({ archive: e, baseUrl: t }),
@@ -596,11 +621,11 @@ const v = {
596
621
  ];
597
622
  try {
598
623
  const r = He({ archive: e, baseUrl: t })(), n = await i.reduce(async (s, o) => await o(await s), r);
599
- return v.log("Generated manifest", n), n;
624
+ return w.log("Generated manifest", n), n;
600
625
  } catch (r) {
601
- throw v.error(r), r;
626
+ throw w.error(r), r;
602
627
  }
603
- }, ot = async (e, t) => {
628
+ }, at = async (e, t) => {
604
629
  const i = `
605
630
  <?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
606
631
  <metadata>
@@ -609,7 +634,7 @@ const v = {
609
634
  </metadata>
610
635
  <manifest>
611
636
  ${e.map(
612
- (s) => `<item id="${A(s)}" href="${s}" media-type="${O(s)}"/>`
637
+ (s) => `<item id="${A(s)}" href="${s}" media-type="${D(s)}"/>`
613
638
  ).join(`
614
639
  `)}
615
640
  </manifest>
@@ -621,7 +646,7 @@ const v = {
621
646
  `, r = e.map((s) => ({
622
647
  dir: !1,
623
648
  basename: A(s),
624
- encodingFormat: O(s),
649
+ encodingFormat: D(s),
625
650
  uri: s,
626
651
  size: 100 / e.length,
627
652
  blob: async () => (await fetch(s)).blob(),
@@ -639,7 +664,7 @@ const v = {
639
664
  }, ...r],
640
665
  close: () => Promise.resolve()
641
666
  };
642
- }, at = async (e, {
667
+ }, ct = async (e, {
643
668
  mimeType: t,
644
669
  direction: i
645
670
  } = { mimeType: "text/plain" }) => {
@@ -682,7 +707,7 @@ const v = {
682
707
  ],
683
708
  close: () => Promise.resolve()
684
709
  };
685
- }, ct = async (e, { orderByAlpha: t, name: i } = {}) => {
710
+ }, dt = async (e, { orderByAlpha: t, name: i } = {}) => {
686
711
  let r = Object.values(e.files);
687
712
  t && (r = r.slice().sort((s, o) => z(s.name, o.name)));
688
713
  const n = {
@@ -703,8 +728,8 @@ const v = {
703
728
  })),
704
729
  close: () => Promise.resolve()
705
730
  };
706
- return v.log("Generated archive", n), n;
707
- }, dt = async (e, { name: t } = {}) => {
731
+ return w.log("Generated archive", n), n;
732
+ }, lt = async (e, { name: t } = {}) => {
708
733
  const i = await e.getFilesArray(), r = {
709
734
  close: () => e.close(),
710
735
  filename: t ?? "",
@@ -717,8 +742,8 @@ const v = {
717
742
  string: async () => (await n.file.extract()).text()
718
743
  }))
719
744
  };
720
- return v.log("Generated archive", r), r;
721
- }, lt = async (e, { orderByAlpha: t, name: i } = {}) => {
745
+ return w.log("Generated archive", r), r;
746
+ }, pt = async (e, { orderByAlpha: t, name: i } = {}) => {
722
747
  let r = e;
723
748
  return t && (r = r.slice().sort((n, s) => z(n.name, s.name))), {
724
749
  filename: i || "",
@@ -738,12 +763,12 @@ const v = {
738
763
  })),
739
764
  close: () => Promise.resolve()
740
765
  };
741
- }, pt = ({
766
+ }, ft = ({
742
767
  enableReport: e
743
768
  } = {}) => {
744
- v.enable(!!e);
769
+ w.enable(!!e);
745
770
  };
746
- class Ze {
771
+ class et {
747
772
  constructor(t) {
748
773
  this.cleanArchiveAfter = t, this.state$ = new we({
749
774
  status: "idle",
@@ -768,77 +793,77 @@ class Ze {
768
793
  }
769
794
  get overTTL$() {
770
795
  return this.isUnlocked$.pipe(
771
- k(
796
+ W(
772
797
  (t) => t ? this.cleanArchiveAfter === 1 / 0 ? G : xe(this.cleanArchiveAfter) : G
773
798
  )
774
799
  );
775
800
  }
776
801
  }
777
- const et = ({
802
+ const tt = ({
778
803
  getArchive: e,
779
804
  cleanArchiveAfter: t = 5 * 60 * 1e3
780
805
  // 5mn
781
806
  }) => {
782
807
  const i = new R(), r = new R(), n = new R(), s = {}, o = i.pipe(
783
- M((p) => {
784
- const c = s[p];
785
- if (!c || c.state.status !== "idle") return _;
786
- let l = !1;
808
+ M((l) => {
809
+ const d = s[l];
810
+ if (!d || d.state.status !== "idle") return _;
811
+ let p = !1;
787
812
  const u = (y) => {
788
- var N;
789
- const w = s[y];
790
- delete s[y], l || ((N = w == null ? void 0 : w.state.archive) == null || N.close(), l = !0);
813
+ var S;
814
+ const v = s[y];
815
+ delete s[y], p || ((S = v == null ? void 0 : v.state.archive) == null || S.close(), p = !0);
791
816
  };
792
- c.update({
817
+ d.update({
793
818
  status: "loading"
794
819
  });
795
- const g = c.locks$, b = c.isUnlocked$, h = g.pipe(
820
+ const g = d.locks$, b = d.isUnlocked$, h = g.pipe(
796
821
  me(),
797
- j(([y, w]) => w > y),
822
+ j(([y, v]) => v > y),
798
823
  he(!0)
799
824
  );
800
- return P(e(p)).pipe(
801
- D((y) => {
802
- c.update({
825
+ return P(e(l)).pipe(
826
+ O((y) => {
827
+ d.update({
803
828
  archive: y,
804
829
  status: "success"
805
830
  });
806
831
  }),
807
- I((y) => (u(p), c.update({
832
+ I((y) => (u(l), d.update({
808
833
  status: "error",
809
834
  error: y
810
835
  }), _)),
811
- k(() => {
836
+ W(() => {
812
837
  const y = h.pipe(
813
- k(() => n),
814
- k(() => b),
815
- j((w) => w)
838
+ W(() => n),
839
+ W(() => b),
840
+ j((v) => v)
816
841
  );
817
- return q(y, c.overTTL$);
842
+ return q(y, d.overTTL$);
818
843
  }),
819
- D(() => {
820
- u(p);
844
+ O(() => {
845
+ u(l);
821
846
  })
822
847
  );
823
848
  }),
824
849
  ge(r)
825
- ), a = (p) => {
826
- let c = !1;
827
- const l = s[p] ?? new Ze(t);
828
- s[p] = l, l.update({
829
- locks: l.state.locks + 1
850
+ ), a = (l) => {
851
+ let d = !1;
852
+ const p = s[l] ?? new et(t);
853
+ s[l] = p, p.update({
854
+ locks: p.state.locks + 1
830
855
  });
831
856
  const u = () => {
832
- c || (c = !0, l.update({
833
- locks: l.state.locks - 1
857
+ d || (d = !0, p.update({
858
+ locks: p.state.locks - 1
834
859
  }));
835
860
  };
836
- i.next(p);
837
- const g = l.state$.pipe(
861
+ i.next(l);
862
+ const g = p.state$.pipe(
838
863
  F(({ archive: h }) => h),
839
864
  j((h) => !!h)
840
- ), b = l.state$.pipe(
841
- D(({ error: h }) => {
865
+ ), b = p.state$.pipe(
866
+ O(({ error: h }) => {
842
867
  if (h)
843
868
  throw h;
844
869
  }),
@@ -851,22 +876,22 @@ const et = ({
851
876
  throw u(), h;
852
877
  })
853
878
  );
854
- }, d = () => {
879
+ }, c = () => {
855
880
  n.next();
856
881
  };
857
882
  return o.subscribe(), {
858
883
  access: a,
859
- purge: d,
884
+ purge: c,
860
885
  archives: s
861
886
  };
862
887
  };
863
- class tt {
888
+ class nt {
864
889
  constructor({
865
890
  onError: t,
866
891
  onManifestSuccess: i,
867
892
  ...r
868
893
  }) {
869
- this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = et(r), this.onManifestSuccess = i ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
894
+ this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = tt(r), this.onManifestSuccess = i ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
870
895
  }
871
896
  prune() {
872
897
  this.epubLoader.purge();
@@ -882,9 +907,9 @@ class tt {
882
907
  fetchManifest({ key: t, baseUrl: i }) {
883
908
  const r = this.accessArchive(t).pipe(
884
909
  M(({ archive: n, release: s }) => P(
885
- Qe(n, { baseUrl: i })
910
+ Ze(n, { baseUrl: i })
886
911
  ).pipe(
887
- k(
912
+ W(
888
913
  (a) => P(this.onManifestSuccess({ manifest: a, archive: n }))
889
914
  ),
890
915
  F(
@@ -911,11 +936,11 @@ class tt {
911
936
  Be(n, o)
912
937
  ).pipe(
913
938
  F(
914
- (d) => new Response(d.body, {
939
+ (c) => new Response(c.body, {
915
940
  status: 200,
916
941
  headers: {
917
- ...d.params.contentType && {
918
- "Content-Type": d.params.contentType
942
+ ...c.params.contentType && {
943
+ "Content-Type": c.params.contentType
919
944
  }
920
945
  }
921
946
  })
@@ -930,7 +955,7 @@ class tt {
930
955
  return Y(r);
931
956
  }
932
957
  }
933
- class ft extends tt {
958
+ class ut extends nt {
934
959
  constructor({
935
960
  getUriInfo: t,
936
961
  ...i
@@ -955,16 +980,16 @@ class ft extends tt {
955
980
  }
956
981
  }
957
982
  export {
958
- ft as ServiceWorkerStreamer,
959
- tt as Streamer,
960
- pt as configure,
961
- lt as createArchiveFromArrayBufferList,
962
- ct as createArchiveFromJszip,
963
- dt as createArchiveFromLibArchive,
964
- at as createArchiveFromText,
965
- ot as createArchiveFromUrls,
966
- Qe as generateManifestFromArchive,
983
+ ut as ServiceWorkerStreamer,
984
+ nt as Streamer,
985
+ ft as configure,
986
+ pt as createArchiveFromArrayBufferList,
987
+ dt as createArchiveFromJszip,
988
+ lt as createArchiveFromLibArchive,
989
+ ct as createArchiveFromText,
990
+ at as createArchiveFromUrls,
991
+ Ze as generateManifestFromArchive,
967
992
  Be as generateResourceFromArchive,
968
- S as getArchiveOpfInfo
993
+ N as getArchiveOpfInfo
969
994
  };
970
995
  //# sourceMappingURL=index.js.map