@prose-reader/streamer 1.209.0 → 1.210.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 v, { XmlDocument as le, XmlTextNode as pe, XmlElement as fe } from "xmldoc";
2
- import { urlJoin as N, isXmlBasedMimeType as ue, parseContentType as me, detectMimeTypeFromName as O } from "@prose-reader/shared";
3
- import { Subject as R, mergeMap as M, EMPTY as _, pairwise as he, filter as D, startWith as ge, from as C, tap as j, catchError as P, switchMap as W, merge as q, first as G, takeUntil as ye, map as F, ignoreElements as be, BehaviorSubject as we, distinctUntilChanged as ve, shareReplay as $e, NEVER as K, timer as xe, finalize as J, of as Y, lastValueFrom as Q } from "rxjs";
1
+ import { XmlDocument as w, XmlTextNode as le, XmlElement as pe } from "xmldoc";
2
+ import { urlJoin as N, isXmlBasedMimeType as fe, parseContentType as ue, detectMimeTypeFromName as M } from "@prose-reader/shared";
3
+ import { Subject as R, mergeMap as z, EMPTY as _, pairwise as he, filter as j, startWith as me, from as C, tap as O, catchError as P, switchMap as W, merge as q, first as G, takeUntil as ge, map as F, ignoreElements as ye, BehaviorSubject as be, distinctUntilChanged as we, shareReplay as ve, NEVER as K, timer as $e, finalize as J, of as Y, lastValueFrom as Q } from "rxjs";
4
4
  let S = !1;
5
- const w = {
5
+ const v = {
6
6
  enable: (e) => {
7
7
  S = e;
8
8
  },
@@ -22,31 +22,31 @@ const w = {
22
22
  error: (...e) => {
23
23
  console.error(...e);
24
24
  }
25
- }, Fe = (e) => {
25
+ }, xe = (e) => {
26
26
  var i;
27
27
  const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((r) => r.attr.name === "calibre:cover");
28
28
  return !!(t && t.attr.name === "calibre:cover");
29
- }, Ae = (e) => {
29
+ }, Fe = (e) => {
30
30
  var t, i, r;
31
31
  return (r = (i = (t = e.descendantWithPath("body")) == null ? void 0 : t.descendantWithPath("div")) == null ? void 0 : i.childrenNamed("svg")) == null ? void 0 : r.find(
32
32
  (n) => n.attr.width === "100%" && n.attr.preserveAspectRatio === "none"
33
33
  );
34
- }, Te = ({ archive: e, resourcePath: t }) => async (i) => {
34
+ }, Ae = ({ archive: e, resourcePath: t }) => async (i) => {
35
35
  const r = Object.values(e.files).find(
36
36
  (n) => n.uri === t
37
37
  );
38
38
  if (r != null && r.basename.endsWith(".xhtml")) {
39
- const n = i.body ?? await r.string(), s = new le(n);
40
- if (Fe(s)) {
41
- const o = Ae(s);
42
- return o && delete o.attr.preserveAspectRatio, {
39
+ const n = i.body ?? await r.string(), s = new w(n);
40
+ if (xe(s)) {
41
+ const a = Fe(s);
42
+ return a && delete a.attr.preserveAspectRatio, {
43
43
  ...i,
44
44
  body: s == null ? void 0 : s.toString()
45
45
  };
46
46
  }
47
47
  }
48
48
  return i;
49
- }, Le = ({ archive: e, resourcePath: t }) => async (i) => Te({ archive: e, resourcePath: t })(i), We = ({ archive: e, resourcePath: t }) => async (i) => {
49
+ }, Te = ({ archive: e, resourcePath: t }) => async (i) => Ae({ archive: e, resourcePath: t })(i), Le = ({ archive: e, resourcePath: t }) => async (i) => {
50
50
  const r = Object.values(e.files).find(
51
51
  (n) => n.uri === t
52
52
  );
@@ -61,10 +61,23 @@ const w = {
61
61
  };
62
62
  }
63
63
  return i;
64
- }, te = (e) => e ? e.children.map((t) => t instanceof pe ? t.text : t instanceof fe ? te(t) : "").join("").trim() : "", A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Z = (e) => e.endsWith("/") ? e.slice(0, -1) : e, Ne = (e) => {
64
+ }, k = (e) => {
65
+ const i = Object.values(e.files).filter((r) => !r.dir).find((r) => r.uri.endsWith(".opf"));
66
+ return {
67
+ data: i,
68
+ basePath: (i == null ? void 0 : i.uri.substring(0, i.uri.lastIndexOf("/"))) || ""
69
+ };
70
+ }, te = async ({
71
+ archive: e
72
+ }) => {
73
+ const { data: t, basePath: i } = k(e) || {}, r = await (t == null ? void 0 : t.string());
74
+ if (!r) return [];
75
+ const n = new w(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 || ""))) || [];
76
+ return e.files.filter((c) => d.find((p) => i ? `${i}/${p.attr.href}` === c.uri : `${p.attr.href}` === c.uri));
77
+ }, A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Z = (e) => e.endsWith("/") ? e.slice(0, -1) : e, We = (e) => {
65
78
  const t = e.lastIndexOf("/");
66
79
  return t >= 0 ? e.substring(0, t) : "";
67
- }, ne = (e, { basePath: t, baseUrl: i }) => {
80
+ }, ne = (e) => e ? e.children.map((t) => t instanceof le ? t.text : t instanceof pe ? ne(t) : "").join("").trim() : "", re = (e, { basePath: t, baseUrl: i }) => {
68
81
  const r = {
69
82
  contents: [],
70
83
  path: "",
@@ -72,89 +85,89 @@ const w = {
72
85
  title: ""
73
86
  };
74
87
  let n = e.childNamed("span") || e.childNamed("a");
75
- r.title = ((n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || te(n)) ?? "";
88
+ r.title = ((n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || ne(n)) ?? "";
76
89
  let s = n == null ? void 0 : n.name;
77
90
  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));
78
- const o = e.childNamed("ol");
79
- if (o) {
80
- const a = o.childrenNamed("li");
81
- a && a.length > 0 && (r.contents = a.map(
82
- (d) => ne(d, { basePath: t, baseUrl: i })
91
+ const a = e.childNamed("ol");
92
+ if (a) {
93
+ const o = a.childrenNamed("li");
94
+ o && o.length > 0 && (r.contents = o.map(
95
+ (d) => re(d, { basePath: t, baseUrl: i })
83
96
  ));
84
97
  }
85
98
  return r;
86
- }, ke = (e, { basePath: t, baseUrl: i }) => {
87
- var s, o;
99
+ }, Ne = (e, { basePath: t, baseUrl: i }) => {
100
+ var s, a;
88
101
  const r = [];
89
102
  let n;
90
- 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(
91
- (a) => r.push(ne(a, { basePath: t, baseUrl: i }))
103
+ 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(
104
+ (o) => r.push(re(o, { basePath: t, baseUrl: i }))
92
105
  ), r;
93
- }, Se = async (e, t, { baseUrl: i }) => {
106
+ }, ke = async (e, t, { baseUrl: i }) => {
94
107
  var n;
95
108
  const r = (n = e.childNamed("manifest")) == null ? void 0 : n.childrenNamed("item").find((s) => s.attr.properties === "nav");
96
109
  if (r) {
97
110
  const s = Object.values(t.files).find(
98
- (o) => o.uri.endsWith(r.attr.href || "")
111
+ (a) => a.uri.endsWith(r.attr.href || "")
99
112
  );
100
113
  if (s) {
101
- const o = new v.XmlDocument(await s.string()), a = Ne(s.uri);
102
- return ke(o, { basePath: a, baseUrl: i });
114
+ const a = new w(await s.string()), o = We(s.uri);
115
+ return Ne(a, { basePath: o, baseUrl: i });
103
116
  }
104
117
  }
105
- }, re = (e, {
118
+ }, se = (e, {
106
119
  opfBasePath: t,
107
120
  baseUrl: i,
108
121
  prefix: r
109
122
  }) => {
110
- var a, d;
111
- const n = ((a = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : a.attr.src) || "", s = {
123
+ var o, d;
124
+ const n = ((o = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : o.attr.src) || "", s = {
112
125
  title: ((d = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : d.val) || "",
113
126
  path: N(t, n),
114
127
  href: N(i, t, n),
115
128
  contents: []
116
- }, o = e.childrenNamed(`${r}navPoint`);
117
- return o && o.length > 0 && (s.contents = o.map(
118
- (l) => re(l, { opfBasePath: t, baseUrl: i, prefix: r })
129
+ }, a = e.childrenNamed(`${r}navPoint`);
130
+ return a && a.length > 0 && (s.contents = a.map(
131
+ (l) => se(l, { opfBasePath: t, baseUrl: i, prefix: r })
119
132
  )), s;
120
- }, Ce = (e, { opfBasePath: t, baseUrl: i }) => {
121
- var o;
133
+ }, Se = (e, { opfBasePath: t, baseUrl: i }) => {
134
+ var a;
122
135
  const r = [], n = e.name;
123
136
  let s = "";
124
- return n.indexOf(":") !== -1 && (s = `${n.split(":")[0]}:`), (o = e.childNamed(`${s}navMap`)) == null || o.childrenNamed(`${s}navPoint`).forEach(
125
- (a) => r.push(re(a, { opfBasePath: t, baseUrl: i, prefix: s }))
137
+ return n.indexOf(":") !== -1 && (s = `${n.split(":")[0]}:`), (a = e.childNamed(`${s}navMap`)) == null || a.childrenNamed(`${s}navPoint`).forEach(
138
+ (o) => r.push(se(o, { opfBasePath: t, baseUrl: i, prefix: s }))
126
139
  ), r;
127
- }, Pe = async ({
140
+ }, Ce = async ({
128
141
  opfData: e,
129
142
  opfBasePath: t,
130
143
  baseUrl: i,
131
144
  archive: r
132
145
  }) => {
133
- var o;
146
+ var a;
134
147
  const n = e.childNamed("spine"), s = n == null ? void 0 : n.attr.toc;
135
148
  if (s) {
136
- const a = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((d) => d.attr.id === s);
137
- if (a) {
138
- const d = `${t}${t === "" ? "" : "/"}${a.attr.href}`, l = Object.values(r.files).find(
149
+ const o = (a = e.childNamed("manifest")) == null ? void 0 : a.childrenNamed("item").find((d) => d.attr.id === s);
150
+ if (o) {
151
+ const d = `${t}${t === "" ? "" : "/"}${o.attr.href}`, l = Object.values(r.files).find(
139
152
  (c) => c.uri.endsWith(d)
140
153
  );
141
154
  if (l) {
142
- const c = new v.XmlDocument(await l.string());
143
- return Ce(c, { opfBasePath: t, baseUrl: i });
155
+ const c = new w(await l.string());
156
+ return Se(c, { opfBasePath: t, baseUrl: i });
144
157
  }
145
158
  }
146
159
  }
147
- }, Ie = async (e, t, { baseUrl: i }) => {
148
- const { basePath: r } = k(t) || {}, n = await Pe({
160
+ }, Pe = async (e, t, { baseUrl: i }) => {
161
+ const { basePath: r } = k(t) || {}, n = await Ce({
149
162
  opfData: e,
150
163
  opfBasePath: r,
151
164
  archive: t,
152
165
  baseUrl: i
153
166
  });
154
- return n || await Se(e, t, {
167
+ return n || await ke(e, t, {
155
168
  baseUrl: i
156
169
  });
157
- }, Re = (e) => {
170
+ }, Ie = (e) => {
158
171
  var r;
159
172
  const t = ((r = e.attr.properties) == null ? void 0 : r.split(" ")) || [];
160
173
  let i;
@@ -163,20 +176,7 @@ const w = {
163
176
  pageSpreadLeft: t.some((n) => n === "page-spread-left") || void 0,
164
177
  pageSpreadRight: t.some((n) => n === "page-spread-right") || void 0
165
178
  };
166
- }, k = (e) => {
167
- const i = Object.values(e.files).filter((r) => !r.dir).find((r) => r.uri.endsWith(".opf"));
168
- return {
169
- data: i,
170
- basePath: (i == null ? void 0 : i.uri.substring(0, i.uri.lastIndexOf("/"))) || ""
171
- };
172
- }, se = async ({
173
- archive: e
174
- }) => {
175
- const { data: t, basePath: i } = k(e) || {}, r = await (t == null ? void 0 : t.string());
176
- if (!r) return [];
177
- const n = new v.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 || ""))) || [];
178
- return e.files.filter((c) => d.find((p) => i ? `${i}/${p.attr.href}` === c.uri : `${p.attr.href}` === c.uri));
179
- }, De = (e, t, i) => {
179
+ }, Re = (e, t, i) => {
180
180
  const r = e.attr.href || "", n = i == null ? void 0 : i(e);
181
181
  return {
182
182
  href: t ? `${n}${t}/${r}` : `${n}${r}`,
@@ -186,71 +186,71 @@ const w = {
186
186
  }, ie = (e, t, i) => {
187
187
  var s;
188
188
  const r = e.childNamed("manifest"), { basePath: n } = k(t) || {};
189
- return ((s = r == null ? void 0 : r.childrenNamed("item")) == null ? void 0 : s.map((o) => De(o, n, i))) || [];
189
+ return ((s = r == null ? void 0 : r.childrenNamed("item")) == null ? void 0 : s.map((a) => Re(a, n, i))) || [];
190
190
  }, je = ({ archive: e, baseUrl: t }) => async (i) => {
191
- var X;
191
+ var U;
192
192
  const { data: r, basePath: n } = k(e) || {};
193
193
  if (!r)
194
194
  return i;
195
195
  const s = await r.string();
196
- w.log("data", s);
197
- const o = new v.XmlDocument(s), a = await Ie(o, e, { baseUrl: t }) || [], d = o.childNamed("metadata"), l = o.childNamed("manifest"), c = o.childNamed("spine"), p = o.childNamed("guide"), u = d == null ? void 0 : d.childNamed("dc:title"), g = (d == null ? void 0 : d.childrenNamed("meta")) || [], b = g.find(
198
- (m) => m.attr.property === "rendition:layout"
199
- ), h = g.find(
200
- (m) => m.attr.property === "rendition:flow"
196
+ v.log("data", s);
197
+ const a = new w(s), o = await Pe(a, e, { baseUrl: t }) || [], d = a.childNamed("metadata"), l = a.childNamed("manifest"), c = a.childNamed("spine"), p = a.childNamed("guide"), u = d == null ? void 0 : d.childNamed("dc:title"), g = (d == null ? void 0 : d.childrenNamed("meta")) || [], b = g.find(
198
+ (h) => h.attr.property === "rendition:layout"
199
+ ), m = g.find(
200
+ (h) => h.attr.property === "rendition:flow"
201
201
  ), $ = g.find(
202
- (m) => m.attr.property === "rendition:spread"
203
- ), y = b == null ? void 0 : b.val, x = h == null ? void 0 : h.val, T = $ == null ? void 0 : $.val, oe = (u == null ? void 0 : u.val) || ((X = e.files.find(({ dir: m }) => m)) == null ? void 0 : X.basename) || "", ae = c == null ? void 0 : c.attr["page-progression-direction"], ce = (await se({ archive: e })).reduce(
204
- (m, L) => L.size + m,
202
+ (h) => h.attr.property === "rendition:spread"
203
+ ), y = b == null ? void 0 : b.val, x = m == null ? void 0 : m.val, T = $ == null ? void 0 : $.val, ae = (u == null ? void 0 : u.val) || ((U = e.files.find(({ dir: h }) => h)) == null ? void 0 : U.basename) || "", oe = c == null ? void 0 : c.attr["page-progression-direction"], ce = (await te({ archive: e })).reduce(
204
+ (h, L) => L.size + h,
205
205
  0
206
206
  );
207
207
  return {
208
208
  filename: e.filename,
209
209
  nav: {
210
- toc: a
210
+ toc: o
211
211
  },
212
212
  renditionLayout: y,
213
213
  renditionFlow: x || "auto",
214
214
  renditionSpread: T,
215
- title: oe,
216
- readingDirection: ae || "ltr",
215
+ title: ae,
216
+ readingDirection: oe || "ltr",
217
217
  /**
218
218
  * @see https://www.w3.org/TR/epub/#sec-itemref-elem
219
219
  */
220
- spineItems: (c == null ? void 0 : c.childrenNamed("itemref").map((m, L) => {
221
- var H, V;
222
- const f = l == null ? void 0 : l.childrenNamed("item").find((I) => I.attr.id === (m == null ? void 0 : m.attr.idref)), U = (f == null ? void 0 : f.attr.href) || "", de = ((H = e.files.find((I) => I.uri.endsWith(U))) == null ? void 0 : H.size) || 0, B = t || (/^https?:\/\//.test(U) ? "" : "file://"), E = Re(m);
220
+ spineItems: (c == null ? void 0 : c.childrenNamed("itemref").map((h, L) => {
221
+ var V, X;
222
+ const f = l == null ? void 0 : l.childrenNamed("item").find((I) => I.attr.id === (h == null ? void 0 : h.attr.idref)), B = (f == null ? void 0 : f.attr.href) || "", de = ((V = e.files.find((I) => I.uri.endsWith(B))) == null ? void 0 : V.size) || 0, E = t || (/^https?:\/\//.test(B) ? "" : "file://"), H = Ie(h);
223
223
  return {
224
- ...E,
224
+ ...H,
225
225
  id: (f == null ? void 0 : f.attr.id) || "",
226
226
  index: L,
227
- href: (V = f == null ? void 0 : f.attr.href) != null && V.startsWith("https://") ? f == null ? void 0 : f.attr.href : n ? `${B}${n}/${f == null ? void 0 : f.attr.href}` : `${B}${f == null ? void 0 : f.attr.href}`,
228
- renditionLayout: E.renditionLayout ?? y,
227
+ href: (X = f == null ? void 0 : f.attr.href) != null && X.startsWith("https://") ? f == null ? void 0 : f.attr.href : n ? `${E}${n}/${f == null ? void 0 : f.attr.href}` : `${E}${f == null ? void 0 : f.attr.href}`,
228
+ renditionLayout: H.renditionLayout ?? y,
229
229
  progressionWeight: de / ce,
230
230
  // size: itemSize
231
231
  mediaType: f == null ? void 0 : f.attr["media-type"]
232
232
  };
233
233
  })) || [],
234
- items: ie(o, e, (m) => {
235
- const L = m.attr.href || "";
234
+ items: ie(a, e, (h) => {
235
+ const L = h.attr.href || "";
236
236
  return /^https?:\/\//.test(L) ? "" : t || "file://";
237
237
  }),
238
- guide: p == null ? void 0 : p.childrenNamed("reference").map((m) => ({
239
- href: m.attr.href || "",
240
- title: m.attr.title || "",
241
- type: m.attr.type
238
+ guide: p == null ? void 0 : p.childrenNamed("reference").map((h) => ({
239
+ href: h.attr.href || "",
240
+ title: h.attr.title || "",
241
+ type: h.attr.type
242
242
  }))
243
243
  };
244
244
  }, Oe = async (e, t) => {
245
- var n, s, o;
245
+ var n, s, a;
246
246
  const r = await ((n = k(e).data) == null ? void 0 : n.string());
247
247
  if (r) {
248
- const a = new v.XmlDocument(r), d = ie(a, e, () => "");
248
+ const o = new w(r), d = ie(o, e, () => "");
249
249
  if ((s = d.find(
250
250
  (c) => t.endsWith(c.href)
251
251
  )) == null ? void 0 : s.mediaType)
252
252
  return {
253
- mediaType: (o = d.find((c) => t.endsWith(c.href))) == null ? void 0 : o.mediaType
253
+ mediaType: (a = d.find((c) => t.endsWith(c.href))) == null ? void 0 : a.mediaType
254
254
  };
255
255
  }
256
256
  return {
@@ -336,7 +336,7 @@ const w = {
336
336
  "canvas",
337
337
  "script",
338
338
  "style"
339
- ], Xe = ({ archive: e, resourcePath: t }) => async (i) => {
339
+ ], De = ({ archive: e, resourcePath: t }) => async (i) => {
340
340
  const r = Object.values(e.files).find(
341
341
  (n) => n.uri === t
342
342
  );
@@ -347,16 +347,16 @@ const w = {
347
347
  "i"
348
348
  ).test(n))
349
349
  return i;
350
- const o = new RegExp(
350
+ const a = new RegExp(
351
351
  `<(${ee.join("|")})(\\s[^>]*)?\\s*/>`,
352
352
  "gi"
353
- ), a = n.replace(
354
- o,
353
+ ), o = n.replace(
354
+ a,
355
355
  (d, l, c = "") => `<${l} ${c.trim()}></${l}>`
356
356
  );
357
357
  return {
358
358
  ...i,
359
- body: a
359
+ body: o
360
360
  };
361
361
  }
362
362
  return i;
@@ -370,18 +370,18 @@ const w = {
370
370
  params: {}
371
371
  }, n = [
372
372
  ze({ archive: e, resourcePath: t }),
373
- Xe({ archive: e, resourcePath: t }),
374
- We({ archive: e, resourcePath: t }),
375
- Le({ archive: e, resourcePath: t })
373
+ De({ archive: e, resourcePath: t }),
374
+ Le({ archive: e, resourcePath: t }),
375
+ Te({ archive: e, resourcePath: t })
376
376
  ];
377
377
  try {
378
- const s = await n.reduce(async (o, a) => await a(await o), Promise.resolve(r));
379
- return w.log("Generated resource", t, s), {
378
+ const s = await n.reduce(async (a, o) => await o(await a), Promise.resolve(r));
379
+ return v.log("Generated resource", t, s), {
380
380
  ...s,
381
381
  body: s.body ?? await i.blob()
382
382
  };
383
383
  } catch (s) {
384
- throw w.error(s), s;
384
+ throw v.error(s), s;
385
385
  }
386
386
  }, Be = ({ archive: e, baseUrl: t }) => async () => {
387
387
  var r;
@@ -393,14 +393,14 @@ const w = {
393
393
  renditionSpread: "auto",
394
394
  readingDirection: "ltr",
395
395
  spineItems: i.filter((n) => !n.basename.endsWith(".db")).map((n, s) => {
396
- const o = t || (/^https?:\/\//.test(n.uri) ? "" : "file://");
396
+ const a = t || (/^https?:\/\//.test(n.uri) ? "" : "file://");
397
397
  return {
398
398
  // some books such as cbz can have same basename inside different sub folder
399
399
  // we need to make sure to have unique index
400
400
  // /chap01/01.png, /chap02/01.png, etc
401
401
  id: `${s}.${n.basename}`,
402
402
  index: s,
403
- href: encodeURI(`${o}${n.uri}`),
403
+ href: encodeURI(`${a}${n.uri}`),
404
404
  renditionLayout: void 0,
405
405
  progressionWeight: 1 / i.length,
406
406
  pageSpreadLeft: void 0,
@@ -421,8 +421,8 @@ const w = {
421
421
  e.files.map(async (i) => {
422
422
  var r, n;
423
423
  if (i.uri.endsWith("com.kobobooks.display-options.xml")) {
424
- const o = (r = new v.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : r.childNamed("option");
425
- ((n = o == null ? void 0 : o.attr) == null ? void 0 : n.name) === "fixed-layout" && o.val === "true" && (t.renditionLayout = "pre-paginated");
424
+ const a = (r = new w(await i.string()).childNamed("platform")) == null ? void 0 : r.childNamed("option");
425
+ ((n = a == null ? void 0 : a.attr) == null ? void 0 : n.name) === "fixed-layout" && a.val === "true" && (t.renditionLayout = "pre-paginated");
426
426
  }
427
427
  })
428
428
  ), t;
@@ -436,18 +436,18 @@ const w = {
436
436
  var i;
437
437
  const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((r) => r.attr.name === "viewport");
438
438
  return !!(t && t.attr.name === "viewport");
439
- }, _e = (e) => e.reduce(async (t, i) => {
440
- if (!await t || !ue({
439
+ }, Xe = (e) => e.reduce(async (t, i) => {
440
+ if (!await t || !fe({
441
441
  mimeType: i.encodingFormat,
442
442
  uri: i.uri
443
443
  }))
444
444
  return !1;
445
445
  const n = await i.string();
446
- return n ? Ve(new v.XmlDocument(n)) : !1;
447
- }, Promise.resolve(!0)), qe = ({ archive: e }) => async (t) => {
446
+ return n ? Ve(new w(n)) : !1;
447
+ }, Promise.resolve(!0)), _e = ({ archive: e }) => async (t) => {
448
448
  if (t.renditionLayout === "reflowable" && t.spineItems.every((r) => r.renditionLayout === "reflowable")) {
449
- const r = await se({ archive: e });
450
- if (await _e(r))
449
+ const r = await te({ archive: e });
450
+ if (await Xe(r))
451
451
  return {
452
452
  ...t,
453
453
  spineItems: t.spineItems.map((s) => ({
@@ -458,21 +458,21 @@ const w = {
458
458
  };
459
459
  }
460
460
  return t;
461
- }, z = (e, t) => {
461
+ }, D = (e, t) => {
462
462
  var n;
463
463
  const i = e.split(/(\d+)/), r = t.split(/(\d+)/);
464
- for (let s = 0, o = i.length; s < o; s++)
464
+ for (let s = 0, a = i.length; s < a; s++)
465
465
  if (i[s] !== r[s])
466
466
  return (n = i[s]) != null && n.match(/\d/) ? +(i[s] || "") - +(r[s] || "") : (i[s] || "").localeCompare(r[s] || "");
467
467
  return 1;
468
- }, Ge = ({ archive: e, baseUrl: t }) => async (i) => {
468
+ }, qe = ({ archive: e, baseUrl: t }) => async (i) => {
469
469
  if (i.nav) return i;
470
470
  const r = [...e.files].sort(
471
- (a, d) => z(a.uri, d.uri)
472
- ), n = Object.values(r), s = (a, d, l, c, p) => {
473
- const u = a.find((h) => h.title === d), [g, ...b] = l;
471
+ (o, d) => D(o.uri, d.uri)
472
+ ), n = Object.values(r), s = (o, d, l, c, p) => {
473
+ const u = o.find((m) => m.title === d), [g, ...b] = l;
474
474
  return u ? g ? [
475
- ...a.filter(($) => $ !== u),
475
+ ...o.filter(($) => $ !== u),
476
476
  {
477
477
  ...u,
478
478
  contents: [
@@ -487,14 +487,14 @@ const w = {
487
487
  ]
488
488
  }
489
489
  ] : u.path.split("/").length > p.split("/").length ? [
490
- ...a.filter(($) => $ !== u),
490
+ ...o.filter(($) => $ !== u),
491
491
  {
492
492
  ...u,
493
493
  path: p,
494
494
  href: c
495
495
  }
496
- ] : a : g ? [
497
- ...a,
496
+ ] : o : g ? [
497
+ ...o,
498
498
  {
499
499
  contents: s(
500
500
  [],
@@ -508,7 +508,7 @@ const w = {
508
508
  title: d
509
509
  }
510
510
  ] : [
511
- ...a,
511
+ ...o,
512
512
  {
513
513
  contents: [],
514
514
  href: c,
@@ -516,95 +516,95 @@ const w = {
516
516
  title: d
517
517
  }
518
518
  ];
519
- }, o = n.reduce(
520
- (a, d) => {
521
- if (d.dir) return a;
519
+ }, a = n.reduce(
520
+ (o, d) => {
521
+ if (d.dir) return o;
522
522
  const c = d.uri.split("/").slice(0, -1), [p, ...u] = c;
523
523
  if (p) {
524
524
  const g = N(t, encodeURI(d.uri)).replace(/\/$/, ""), b = d.uri.replace(/\/$/, "");
525
- return s(a, p, u, g, b);
525
+ return s(o, p, u, g, b);
526
526
  }
527
- return a;
527
+ return o;
528
528
  },
529
529
  []
530
530
  );
531
- return o.length === 0 ? i : {
531
+ return a.length === 0 ? i : {
532
532
  ...i,
533
533
  nav: {
534
- toc: o
534
+ toc: a
535
535
  }
536
536
  };
537
- }, Ke = ({ archive: e }) => async (t) => {
537
+ }, Ge = ({ archive: e }) => async (t) => {
538
538
  var s;
539
539
  const i = e.files.find(
540
- (o) => o.basename.toLowerCase() === "comicinfo.xml"
540
+ (a) => a.basename.toLowerCase() === "comicinfo.xml"
541
541
  );
542
542
  if (!i)
543
543
  return t;
544
544
  const r = {
545
545
  ...t,
546
- spineItems: t.spineItems.filter((o) => !o.id.toLowerCase().endsWith("comicinfo.xml")).map((o, a, d) => ({
547
- ...o,
546
+ spineItems: t.spineItems.filter((a) => !a.id.toLowerCase().endsWith("comicinfo.xml")).map((a, o, d) => ({
547
+ ...a,
548
548
  progressionWeight: 1 / d.length
549
549
  }))
550
550
  }, n = await i.string();
551
551
  try {
552
- const a = ((s = new v.XmlDocument(n).childNamed("Manga")) == null ? void 0 : s.val) || "unknown";
552
+ const o = ((s = new w(n).childNamed("Manga")) == null ? void 0 : s.val) || "unknown";
553
553
  return {
554
554
  ...r,
555
- readingDirection: a === "YesAndRightToLeft" ? "rtl" : "ltr"
555
+ readingDirection: o === "YesAndRightToLeft" ? "rtl" : "ltr"
556
556
  };
557
- } catch (o) {
557
+ } catch (a) {
558
558
  return console.error(`Unable to parse comicinfo.xml for content
559
- `, n), console.error(o), r;
559
+ `, n), console.error(a), r;
560
560
  }
561
- }, Je = (e) => e.files.some((t) => t.basename.endsWith(".opf")), Ye = ({ archive: e }) => async (t) => Je(e) ? t : {
561
+ }, Ke = (e) => e.files.some((t) => t.basename.endsWith(".opf")), Je = ({ archive: e }) => async (t) => Ke(e) ? t : {
562
562
  ...t,
563
563
  spineItems: t.spineItems.map((r) => {
564
564
  const n = e.files.find(
565
- (o) => decodeURI(r.href).endsWith(o.uri)
566
- ), s = me((n == null ? void 0 : n.encodingFormat) ?? "") ?? O((n == null ? void 0 : n.basename) ?? "");
565
+ (a) => decodeURI(r.href).endsWith(a.uri)
566
+ ), s = ue((n == null ? void 0 : n.encodingFormat) ?? "") ?? M((n == null ? void 0 : n.basename) ?? "");
567
567
  return {
568
568
  ...r,
569
569
  renditionLayout: s != null && s.startsWith("image/") ? "pre-paginated" : r.renditionLayout
570
570
  };
571
571
  })
572
- }, Qe = ({ archive: e }) => async (t) => {
572
+ }, Ye = ({ archive: e }) => async (t) => {
573
573
  var n, s;
574
574
  const i = e.files.find(
575
- (o) => o.basename.toLowerCase() === "com.apple.ibooks.display-options.xml"
575
+ (a) => a.basename.toLowerCase() === "com.apple.ibooks.display-options.xml"
576
576
  );
577
577
  if (!i)
578
578
  return t;
579
579
  const r = await (await i.blob()).text();
580
580
  try {
581
- const a = new v.XmlDocument(r).childNamed("platform"), d = ((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";
581
+ const o = new w(r).childNamed("platform"), d = ((s = (n = o == null ? void 0 : o.childrenNamed("option")) == null ? void 0 : n.find((l) => l.attr.name === "fixed-layout")) == null ? void 0 : s.val) || "false";
582
582
  return {
583
583
  ...t,
584
584
  renditionLayout: d === "true" ? "pre-paginated" : t.renditionLayout
585
585
  };
586
- } catch (o) {
586
+ } catch (a) {
587
587
  return console.error(
588
588
  `Unable to parse com.apple.ibooks.display-options.xml for content
589
589
  `,
590
590
  r
591
- ), console.error(o), t;
591
+ ), console.error(a), t;
592
592
  }
593
- }, Ze = async (e, { baseUrl: t = "" } = {}) => {
593
+ }, Qe = async (e, { baseUrl: t = "" } = {}) => {
594
594
  const i = [
595
595
  je({ archive: e, baseUrl: t }),
596
- Ke({ archive: e }),
597
- Qe({ archive: e }),
596
+ Ge({ archive: e }),
598
597
  Ye({ archive: e }),
599
- qe({ archive: e }),
598
+ Je({ archive: e }),
599
+ _e({ archive: e }),
600
600
  He({ archive: e }),
601
- Ge({ archive: e, baseUrl: t })
601
+ qe({ archive: e, baseUrl: t })
602
602
  ];
603
603
  try {
604
- const r = Be({ archive: e, baseUrl: t })(), n = await i.reduce(async (s, o) => await o(await s), r);
605
- return w.log("Generated manifest", n), n;
604
+ const r = Be({ archive: e, baseUrl: t })(), n = await i.reduce(async (s, a) => await a(await s), r);
605
+ return v.log("Generated manifest", n), n;
606
606
  } catch (r) {
607
- throw w.error(r), r;
607
+ throw v.error(r), r;
608
608
  }
609
609
  }, at = async (e, t) => {
610
610
  const i = `
@@ -615,7 +615,7 @@ const w = {
615
615
  </metadata>
616
616
  <manifest>
617
617
  ${e.map(
618
- (s) => `<item id="${A(s)}" href="${s}" media-type="${O(s)}"/>`
618
+ (s) => `<item id="${A(s)}" href="${s}" media-type="${M(s)}"/>`
619
619
  ).join(`
620
620
  `)}
621
621
  </manifest>
@@ -627,7 +627,7 @@ const w = {
627
627
  `, r = e.map((s) => ({
628
628
  dir: !1,
629
629
  basename: A(s),
630
- encodingFormat: O(s),
630
+ encodingFormat: M(s),
631
631
  uri: s,
632
632
  size: 100 / e.length,
633
633
  blob: async () => (await fetch(s)).blob(),
@@ -645,7 +645,7 @@ const w = {
645
645
  }, ...r],
646
646
  close: () => Promise.resolve()
647
647
  };
648
- }, ct = async (e, {
648
+ }, ot = async (e, {
649
649
  mimeType: t,
650
650
  direction: i
651
651
  } = { mimeType: "text/plain" }) => {
@@ -688,9 +688,9 @@ const w = {
688
688
  ],
689
689
  close: () => Promise.resolve()
690
690
  };
691
- }, dt = async (e, { orderByAlpha: t, name: i } = {}) => {
691
+ }, ct = async (e, { orderByAlpha: t, name: i } = {}) => {
692
692
  let r = Object.values(e.files);
693
- t && (r = r.slice().sort((s, o) => z(s.name, o.name)));
693
+ t && (r = r.slice().sort((s, a) => D(s.name, a.name)));
694
694
  const n = {
695
695
  filename: i || "",
696
696
  files: r.map((s) => ({
@@ -708,8 +708,8 @@ const w = {
708
708
  })),
709
709
  close: () => Promise.resolve()
710
710
  };
711
- return w.log("Generated archive", n), n;
712
- }, lt = async (e, { name: t } = {}) => {
711
+ return v.log("Generated archive", n), n;
712
+ }, dt = async (e, { name: t } = {}) => {
713
713
  const i = await e.getFilesArray(), r = {
714
714
  close: () => e.close(),
715
715
  filename: t ?? "",
@@ -722,10 +722,10 @@ const w = {
722
722
  string: async () => (await n.file.extract()).text()
723
723
  }))
724
724
  };
725
- return w.log("Generated archive", r), r;
726
- }, pt = async (e, { orderByAlpha: t, name: i } = {}) => {
725
+ return v.log("Generated archive", r), r;
726
+ }, lt = async (e, { orderByAlpha: t, name: i } = {}) => {
727
727
  let r = e;
728
- return t && (r = r.slice().sort((n, s) => z(n.name, s.name))), {
728
+ return t && (r = r.slice().sort((n, s) => D(n.name, s.name))), {
729
729
  filename: i || "",
730
730
  files: r.map((n) => ({
731
731
  dir: n.isDir,
@@ -743,14 +743,14 @@ const w = {
743
743
  })),
744
744
  close: () => Promise.resolve()
745
745
  };
746
- }, ft = ({
746
+ }, pt = ({
747
747
  enableReport: e
748
748
  } = {}) => {
749
- w.enable(!!e);
749
+ v.enable(!!e);
750
750
  };
751
- class et {
751
+ class Ze {
752
752
  constructor(t) {
753
- this.cleanArchiveAfter = t, this.state$ = new we({
753
+ this.cleanArchiveAfter = t, this.state$ = new be({
754
754
  status: "idle",
755
755
  locks: 0
756
756
  });
@@ -767,44 +767,44 @@ class et {
767
767
  get isUnlocked$() {
768
768
  return this.locks$.pipe(
769
769
  F((t) => t <= 0),
770
- ve(),
771
- $e()
770
+ we(),
771
+ ve()
772
772
  );
773
773
  }
774
774
  get overTTL$() {
775
775
  return this.isUnlocked$.pipe(
776
776
  W(
777
- (t) => t ? this.cleanArchiveAfter === 1 / 0 ? K : xe(this.cleanArchiveAfter) : K
777
+ (t) => t ? this.cleanArchiveAfter === 1 / 0 ? K : $e(this.cleanArchiveAfter) : K
778
778
  )
779
779
  );
780
780
  }
781
781
  }
782
- const tt = ({
782
+ const et = ({
783
783
  getArchive: e,
784
784
  cleanArchiveAfter: t = 5 * 60 * 1e3
785
785
  // 5mn
786
786
  }) => {
787
- const i = new R(), r = new R(), n = new R(), s = {}, o = i.pipe(
788
- M((l) => {
787
+ const i = new R(), r = new R(), n = new R(), s = {}, a = i.pipe(
788
+ z((l) => {
789
789
  const c = s[l];
790
790
  if (!c || c.state.status !== "idle") return _;
791
791
  let p = !1;
792
792
  const u = (y) => {
793
793
  var T;
794
- w.debug(`Cleaning up archive with key: ${y}`);
794
+ v.debug(`Cleaning up archive with key: ${y}`);
795
795
  const x = s[y];
796
796
  delete s[y], p || ((T = x == null ? void 0 : x.state.archive) == null || T.close(), p = !0);
797
797
  };
798
798
  c.update({
799
799
  status: "loading"
800
800
  });
801
- const g = c.locks$, b = c.isUnlocked$, h = g.pipe(
801
+ const g = c.locks$, b = c.isUnlocked$, m = g.pipe(
802
802
  he(),
803
- D(([y, x]) => x > y),
804
- ge(!0)
803
+ j(([y, x]) => x > y),
804
+ me(!0)
805
805
  );
806
806
  return C(e(l)).pipe(
807
- j((y) => {
807
+ O((y) => {
808
808
  c.update({
809
809
  archive: y,
810
810
  status: "success"
@@ -815,24 +815,24 @@ const tt = ({
815
815
  error: y
816
816
  }), _)),
817
817
  W(() => {
818
- const y = h.pipe(
818
+ const y = m.pipe(
819
819
  W(() => n),
820
820
  W(() => b),
821
- D((T) => T)
821
+ j((T) => T)
822
822
  );
823
823
  return q(y, c.overTTL$).pipe(
824
824
  G(),
825
- j(() => {
825
+ O(() => {
826
826
  u(l);
827
827
  })
828
828
  );
829
829
  })
830
830
  );
831
831
  }),
832
- ye(r)
833
- ), a = (l) => {
832
+ ge(r)
833
+ ), o = (l) => {
834
834
  let c = !1;
835
- const p = s[l] ?? new et(t);
835
+ const p = s[l] ?? new Ze(t);
836
836
  s[l] = p, p.update({
837
837
  locks: p.state.locks + 1
838
838
  });
@@ -843,38 +843,38 @@ const tt = ({
843
843
  };
844
844
  i.next(l);
845
845
  const g = p.state$.pipe(
846
- F(({ archive: h }) => h),
847
- D((h) => !!h)
846
+ F(({ archive: m }) => m),
847
+ j((m) => !!m)
848
848
  ), b = p.state$.pipe(
849
- j(({ error: h }) => {
850
- if (h)
851
- throw h;
849
+ O(({ error: m }) => {
850
+ if (m)
851
+ throw m;
852
852
  }),
853
- be()
853
+ ye()
854
854
  );
855
855
  return q(g, b).pipe(
856
856
  G(),
857
- F((h) => ({ archive: h, release: u })),
858
- P((h) => {
859
- throw u(), h;
857
+ F((m) => ({ archive: m, release: u })),
858
+ P((m) => {
859
+ throw u(), m;
860
860
  })
861
861
  );
862
862
  }, d = () => {
863
863
  n.next();
864
864
  };
865
- return o.subscribe(), {
866
- access: a,
865
+ return a.subscribe(), {
866
+ access: o,
867
867
  purge: d,
868
868
  _archives: s
869
869
  };
870
870
  };
871
- class nt {
871
+ class tt {
872
872
  constructor({
873
873
  onError: t,
874
874
  onManifestSuccess: i,
875
875
  ...r
876
876
  }) {
877
- 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;
877
+ 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;
878
878
  }
879
879
  prune() {
880
880
  this.epubLoader.purge();
@@ -889,14 +889,14 @@ class nt {
889
889
  }
890
890
  fetchManifest({ key: t, baseUrl: i }) {
891
891
  const r = this.accessArchive(t).pipe(
892
- M(({ archive: n, release: s }) => C(
893
- Ze(n, { baseUrl: i })
892
+ z(({ archive: n, release: s }) => C(
893
+ Qe(n, { baseUrl: i })
894
894
  ).pipe(
895
895
  W(
896
- (a) => C(this.onManifestSuccess({ manifest: a, archive: n }))
896
+ (o) => C(this.onManifestSuccess({ manifest: o, archive: n }))
897
897
  ),
898
898
  F(
899
- (a) => new Response(JSON.stringify(a), {
899
+ (o) => new Response(JSON.stringify(o), {
900
900
  status: 200
901
901
  })
902
902
  ),
@@ -913,10 +913,10 @@ class nt {
913
913
  resourcePath: i
914
914
  }) {
915
915
  const r = this.accessArchive(t).pipe(
916
- M(({ archive: n, release: s }) => {
917
- const o = i.replaceAll("file://", "");
916
+ z(({ archive: n, release: s }) => {
917
+ const a = i.replaceAll("file://", "");
918
918
  return C(
919
- Ue(n, o)
919
+ Ue(n, a)
920
920
  ).pipe(
921
921
  F(
922
922
  (d) => new Response(d.body, {
@@ -938,7 +938,7 @@ class nt {
938
938
  return Q(r);
939
939
  }
940
940
  }
941
- class ut extends nt {
941
+ class ft extends tt {
942
942
  constructor({
943
943
  getUriInfo: t,
944
944
  ...i
@@ -951,27 +951,27 @@ class ut extends nt {
951
951
  if (!i) return;
952
952
  const r = Z(i.baseUrl), n = t.request.url.substring(
953
953
  r.length + 1
954
- ), [s = ""] = n.split("/"), o = decodeURIComponent(
954
+ ), [s = ""] = n.split("/"), a = decodeURIComponent(
955
955
  Z(n.substring(s.length + 1))
956
956
  );
957
957
  n.endsWith("/manifest") ? t.respondWith(
958
958
  this.fetchManifest({ key: s, baseUrl: `${r}/${s}/` })
959
- ) : t.respondWith(this.fetchResource({ key: s, resourcePath: o }));
959
+ ) : t.respondWith(this.fetchResource({ key: s, resourcePath: a }));
960
960
  } catch (i) {
961
961
  t.respondWith(new Response(String(i), { status: 500 }));
962
962
  }
963
963
  }
964
964
  }
965
965
  export {
966
- ut as ServiceWorkerStreamer,
967
- nt as Streamer,
968
- ft as configure,
969
- pt as createArchiveFromArrayBufferList,
970
- dt as createArchiveFromJszip,
971
- lt as createArchiveFromLibArchive,
972
- ct as createArchiveFromText,
966
+ ft as ServiceWorkerStreamer,
967
+ tt as Streamer,
968
+ pt as configure,
969
+ lt as createArchiveFromArrayBufferList,
970
+ ct as createArchiveFromJszip,
971
+ dt as createArchiveFromLibArchive,
972
+ ot as createArchiveFromText,
973
973
  at as createArchiveFromUrls,
974
- Ze as generateManifestFromArchive,
974
+ Qe as generateManifestFromArchive,
975
975
  Ue as generateResourceFromArchive,
976
976
  k as getArchiveOpfInfo
977
977
  };