@prose-reader/streamer 1.60.0 → 1.62.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
@@ -23,51 +23,63 @@ const h = {
23
23
  timeEnd: (e) => {
24
24
  b && console.timeEnd(`[prose-reader-streamer] [metric] ${e}`);
25
25
  },
26
- metric: (e, n = 1 / 0) => {
26
+ metric: (e, r = 1 / 0) => {
27
27
  const i = typeof e == "number" ? e : e.duration;
28
- b && (e.duration <= n ? console.log("[prose-reader-streamer] [metric] ", `${e.name} took ${i}ms`) : console.warn(
28
+ b && (e.duration <= r ? console.log(
29
29
  "[prose-reader-streamer] [metric] ",
30
- `${e.name} took ${e.duration}ms which is above the ${n}ms target for this function`
30
+ `${e.name} took ${i}ms`
31
+ ) : console.warn(
32
+ "[prose-reader-streamer] [metric] ",
33
+ `${e.name} took ${e.duration}ms which is above the ${r}ms target for this function`
31
34
  ));
32
35
  },
33
36
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
- measurePerformance: (e, n = 10, i) => (...t) => {
35
- const a = performance.now(), r = i(...t);
36
- if (r && r.then)
37
- return r.then((s) => {
37
+ measurePerformance: (e, r = 10, i) => (...t) => {
38
+ const n = performance.now(), a = i(...t);
39
+ if (a && a.then)
40
+ return a.then((s) => {
38
41
  const l = performance.now();
39
- return h.metric({ name: e, duration: l - a }, n), s;
42
+ return h.metric({ name: e, duration: l - n }, r), s;
40
43
  });
41
44
  const o = performance.now();
42
- return h.metric({ name: e, duration: o - a }, n), r;
45
+ return h.metric({ name: e, duration: o - n }, r), a;
43
46
  }
44
47
  }, K = (e) => {
45
48
  var i;
46
- const n = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((t) => t.attr.name === "calibre:cover");
47
- return !!(n && n.attr.name === "calibre:cover");
49
+ const r = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((t) => t.attr.name === "calibre:cover");
50
+ return !!(r && r.attr.name === "calibre:cover");
48
51
  }, Q = (e) => {
49
- var n, i, t;
50
- return (t = (i = (n = e.descendantWithPath("body")) == null ? void 0 : n.descendantWithPath("div")) == null ? void 0 : i.childrenNamed("svg")) == null ? void 0 : t.find((a) => a.attr.width === "100%" && a.attr.preserveAspectRatio === "none");
51
- }, Z = ({ archive: e, resourcePath: n }) => async (i) => {
52
- const t = Object.values(e.files).find((a) => a.uri === n);
52
+ var r, i, t;
53
+ return (t = (i = (r = e.descendantWithPath("body")) == null ? void 0 : r.descendantWithPath("div")) == null ? void 0 : i.childrenNamed("svg")) == null ? void 0 : t.find(
54
+ (n) => n.attr.width === "100%" && n.attr.preserveAspectRatio === "none"
55
+ );
56
+ }, Z = ({ archive: e, resourcePath: r }) => async (i) => {
57
+ const t = Object.values(e.files).find(
58
+ (n) => n.uri === r
59
+ );
53
60
  if (t != null && t.basename.endsWith(".xhtml")) {
54
- const a = i.body ?? await t.string(), r = new Y(a);
55
- if (K(r)) {
56
- const o = Q(r);
61
+ const n = i.body ?? await t.string(), a = new Y(n);
62
+ if (K(a)) {
63
+ const o = Q(a);
57
64
  return o && delete o.attr.preserveAspectRatio, {
58
65
  ...i,
59
- body: r == null ? void 0 : r.toString()
66
+ body: a == null ? void 0 : a.toString()
60
67
  };
61
68
  }
62
69
  }
63
70
  return i;
64
- }, E = ({ archive: e, resourcePath: n }) => async (i) => Z({ archive: e, resourcePath: n })(i), ee = ({ archive: e, resourcePath: n }) => async (i) => {
65
- const t = Object.values(e.files).find((a) => a.uri === n);
71
+ }, E = ({ archive: e, resourcePath: r }) => async (i) => Z({ archive: e, resourcePath: r })(i), ee = ({ archive: e, resourcePath: r }) => async (i) => {
72
+ const t = Object.values(e.files).find(
73
+ (n) => n.uri === r
74
+ );
66
75
  if (t != null && t.basename.endsWith(".css")) {
67
- const r = (i.body ?? await t.string()).replaceAll("-webkit-writing-mode", "writing-mode");
76
+ const a = (i.body ?? await t.string()).replaceAll(
77
+ "-webkit-writing-mode",
78
+ "writing-mode"
79
+ );
68
80
  return {
69
81
  ...i,
70
- body: r
82
+ body: a
71
83
  };
72
84
  }
73
85
  return i;
@@ -77,130 +89,159 @@ const h = {
77
89
  data: i,
78
90
  basePath: (i == null ? void 0 : i.uri.substring(0, i.uri.lastIndexOf("/"))) || ""
79
91
  };
80
- }, O = (e, { opfBasePath: n, baseUrl: i }) => {
92
+ }, O = (e, { opfBasePath: r, baseUrl: i }) => {
81
93
  const t = {
82
94
  contents: [],
83
95
  path: "",
84
96
  href: "",
85
97
  title: ""
86
98
  };
87
- let a = e.childNamed("span") || e.childNamed("a");
88
- t.title = (a == null ? void 0 : a.attr.title) || (a == null ? void 0 : a.val.trim()) || t.title;
89
- let r = a == null ? void 0 : a.name;
90
- r !== "a" && (a = e.descendantWithPath(`${r}.a`), a && (r = a.name.toLowerCase())), r === "a" && (a != null && a.attr.href) && (t.path = v(n, a.attr.href), t.href = v(i, n, a.attr.href));
99
+ let n = e.childNamed("span") || e.childNamed("a");
100
+ t.title = (n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || t.title;
101
+ let a = n == null ? void 0 : n.name;
102
+ a !== "a" && (n = e.descendantWithPath(`${a}.a`), n && (a = n.name.toLowerCase())), a === "a" && (n != null && n.attr.href) && (t.path = v(r, n.attr.href), t.href = v(i, r, n.attr.href));
91
103
  const o = e.childNamed("ol");
92
104
  if (o) {
93
105
  const s = o.childrenNamed("li");
94
- s && s.length > 0 && (t.contents = s.map((l) => O(l, { opfBasePath: n, baseUrl: i })));
106
+ s && s.length > 0 && (t.contents = s.map(
107
+ (l) => O(l, { opfBasePath: r, baseUrl: i })
108
+ ));
95
109
  }
96
110
  return t;
97
- }, te = (e, { opfBasePath: n, baseUrl: i }) => {
98
- var r, o;
111
+ }, te = (e, { opfBasePath: r, baseUrl: i }) => {
112
+ var a, o;
99
113
  const t = [];
100
- let a;
101
- return e.descendantWithPath("body.nav.ol") ? a = (r = e.descendantWithPath("body.nav.ol")) == null ? void 0 : r.children : e.descendantWithPath("body.section.nav.ol") && (a = (o = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : o.children), a && a.length > 0 && a.filter((s) => s.name === "li").forEach((s) => t.push(O(s, { opfBasePath: n, baseUrl: i }))), t;
102
- }, ne = async (e, n, { opfBasePath: i, baseUrl: t }) => {
103
- var r;
104
- const a = (r = e.childNamed("manifest")) == null ? void 0 : r.childrenNamed("item").find((o) => o.attr.properties === "nav");
105
- if (a) {
106
- const o = Object.values(n.files).find((s) => s.uri.endsWith(a.attr.href || ""));
114
+ let n;
115
+ return e.descendantWithPath("body.nav.ol") ? n = (a = e.descendantWithPath("body.nav.ol")) == null ? void 0 : a.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((s) => s.name === "li").forEach(
116
+ (s) => t.push(O(s, { opfBasePath: r, baseUrl: i }))
117
+ ), t;
118
+ }, ne = async (e, r, { opfBasePath: i, baseUrl: t }) => {
119
+ var a;
120
+ const n = (a = e.childNamed("manifest")) == null ? void 0 : a.childrenNamed("item").find((o) => o.attr.properties === "nav");
121
+ if (n) {
122
+ const o = Object.values(r.files).find(
123
+ (s) => s.uri.endsWith(n.attr.href || "")
124
+ );
107
125
  if (o) {
108
126
  const s = new g.XmlDocument(await o.string());
109
127
  return te(s, { opfBasePath: i, baseUrl: t });
110
128
  }
111
129
  }
112
- }, j = (e, { opfBasePath: n, baseUrl: i, prefix: t }) => {
130
+ }, j = (e, {
131
+ opfBasePath: r,
132
+ baseUrl: i,
133
+ prefix: t
134
+ }) => {
113
135
  var s, l;
114
- const a = ((s = e == null ? void 0 : e.childNamed(`${t}content`)) == null ? void 0 : s.attr.src) || "", r = {
136
+ const n = ((s = e == null ? void 0 : e.childNamed(`${t}content`)) == null ? void 0 : s.attr.src) || "", a = {
115
137
  title: ((l = e == null ? void 0 : e.descendantWithPath(`${t}navLabel.${t}text`)) == null ? void 0 : l.val) || "",
116
- path: v(n, a),
117
- href: v(i, n, a),
138
+ path: v(r, n),
139
+ href: v(i, r, n),
118
140
  contents: []
119
141
  }, o = e.childrenNamed(`${t}navPoint`);
120
- return o && o.length > 0 && (r.contents = o.map((p) => j(p, { opfBasePath: n, baseUrl: i, prefix: t }))), r;
121
- }, re = (e, { opfBasePath: n, baseUrl: i }) => {
142
+ return o && o.length > 0 && (a.contents = o.map(
143
+ (p) => j(p, { opfBasePath: r, baseUrl: i, prefix: t })
144
+ )), a;
145
+ }, re = (e, { opfBasePath: r, baseUrl: i }) => {
122
146
  var o;
123
- const t = [], a = e.name;
124
- let r = "";
125
- return a.indexOf(":") !== -1 && (r = a.split(":")[0] + ":"), (o = e.childNamed(`${r}navMap`)) == null || o.childrenNamed(`${r}navPoint`).forEach((s) => t.push(j(s, { opfBasePath: n, baseUrl: i, prefix: r }))), t;
147
+ const t = [], n = e.name;
148
+ let a = "";
149
+ return n.indexOf(":") !== -1 && (a = n.split(":")[0] + ":"), (o = e.childNamed(`${a}navMap`)) == null || o.childrenNamed(`${a}navPoint`).forEach(
150
+ (s) => t.push(j(s, { opfBasePath: r, baseUrl: i, prefix: a }))
151
+ ), t;
126
152
  }, ae = async ({
127
153
  opfData: e,
128
- opfBasePath: n,
154
+ opfBasePath: r,
129
155
  baseUrl: i,
130
156
  archive: t
131
157
  }) => {
132
158
  var o;
133
- const a = e.childNamed("spine"), r = a && a.attr.toc;
134
- if (r) {
135
- const s = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((l) => l.attr.id === r);
159
+ const n = e.childNamed("spine"), a = n && n.attr.toc;
160
+ if (a) {
161
+ const s = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((l) => l.attr.id === a);
136
162
  if (s) {
137
- const l = `${n}${n === "" ? "" : "/"}${s.attr.href}`, p = Object.values(t.files).find((m) => m.uri.endsWith(l));
163
+ const l = `${r}${r === "" ? "" : "/"}${s.attr.href}`, p = Object.values(t.files).find(
164
+ (m) => m.uri.endsWith(l)
165
+ );
138
166
  if (p) {
139
167
  const m = new g.XmlDocument(await p.string());
140
- return re(m, { opfBasePath: n, baseUrl: i });
168
+ return re(m, { opfBasePath: r, baseUrl: i });
141
169
  }
142
170
  }
143
171
  }
144
- }, ie = async (e, n, { baseUrl: i }) => {
145
- const { basePath: t } = F(n) || {}, a = await ae({
172
+ }, ie = async (e, r, { baseUrl: i }) => {
173
+ const { basePath: t } = F(r) || {}, n = await ae({
146
174
  opfData: e,
147
175
  opfBasePath: t,
148
- archive: n,
176
+ archive: r,
149
177
  baseUrl: i
150
178
  });
151
- return a || await ne(e, n, { opfBasePath: t, baseUrl: i });
179
+ return n || await ne(e, r, { opfBasePath: t, baseUrl: i });
152
180
  }, oe = async (e) => {
153
- const n = {
181
+ const r = {
154
182
  renditionLayout: void 0
155
183
  };
156
184
  return await Promise.all(
157
185
  e.files.map(async (i) => {
158
- var t, a;
186
+ var t, n;
159
187
  if (i.uri.endsWith("com.kobobooks.display-options.xml")) {
160
188
  const o = (t = new g.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : t.childNamed("option");
161
- ((a = o == null ? void 0 : o.attr) == null ? void 0 : a.name) === "fixed-layout" && o.val === "true" && (n.renditionLayout = "pre-paginated");
189
+ ((n = o == null ? void 0 : o.attr) == null ? void 0 : n.name) === "fixed-layout" && o.val === "true" && (r.renditionLayout = "pre-paginated");
162
190
  }
163
191
  })
164
- ), n;
165
- }, z = async ({ archive: e }) => {
166
- const { data: n, basePath: i } = F(e) || {}, t = await (n == null ? void 0 : n.string());
192
+ ), r;
193
+ }, z = async ({
194
+ archive: e
195
+ }) => {
196
+ const { data: r, basePath: i } = F(e) || {}, t = await (r == null ? void 0 : r.string());
167
197
  if (!t) return [];
168
- const a = new g.XmlDocument(t), r = a.childNamed("manifest"), o = a.childNamed("spine"), s = o == null ? void 0 : o.childrenNamed("itemref").map((m) => m.attr.idref), l = (r == null ? void 0 : r.childrenNamed("item").filter((m) => s.includes(m.attr.id || ""))) || [];
198
+ const n = new g.XmlDocument(t), a = n.childNamed("manifest"), o = n.childNamed("spine"), s = o == null ? void 0 : o.childrenNamed("itemref").map((m) => m.attr.idref), l = (a == null ? void 0 : a.childrenNamed("item").filter((m) => s.includes(m.attr.id || ""))) || [];
169
199
  return e.files.filter((m) => l.find((f) => i ? `${i}/${f.attr.href}` === m.uri : `${f.attr.href}` === m.uri));
170
200
  }, X = (e) => {
171
201
  var i;
172
- const n = e.childNamed("manifest");
173
- return ((i = n == null ? void 0 : n.childrenNamed("item")) == null ? void 0 : i.map((t) => ({
202
+ const r = e.childNamed("manifest");
203
+ return ((i = r == null ? void 0 : r.childrenNamed("item")) == null ? void 0 : i.map((t) => ({
174
204
  href: t.attr.href || "",
175
205
  id: t.attr.id || "",
176
206
  mediaType: t.attr["media-type"]
177
207
  }))) || [];
178
- }, se = ({ archive: e, baseUrl: n }) => async (i) => {
208
+ }, se = ({ archive: e, baseUrl: r }) => async (i) => {
179
209
  var D;
180
- const { data: t, basePath: a } = F(e) || {}, r = await oe(e);
210
+ const { data: t, basePath: n } = F(e) || {}, a = await oe(e);
181
211
  if (!t)
182
212
  return i;
183
213
  const o = await t.string();
184
- h.log(o, r);
185
- const s = new g.XmlDocument(o), l = await ie(s, e, { baseUrl: n }) || [], p = s.childNamed("metadata"), m = s.childNamed("manifest"), f = s.childNamed("spine"), x = s.childNamed("guide"), w = p == null ? void 0 : p.childNamed("dc:title"), $ = (p == null ? void 0 : p.childrenNamed("meta")) || [], N = $.find((d) => d.attr.property === "rendition:layout"), T = $.find((d) => d.attr.property === "rendition:flow"), I = $.find((d) => d.attr.property === "rendition:spread"), k = N == null ? void 0 : N.val, B = T == null ? void 0 : T.val, M = I == null ? void 0 : I.val, _ = (w == null ? void 0 : w.val) || ((D = e.files.find(({ dir: d }) => d)) == null ? void 0 : D.basename) || "", H = f == null ? void 0 : f.attr["page-progression-direction"], U = (await z({ archive: e })).reduce((d, c) => c.size + d, 0);
214
+ h.log(o, a);
215
+ const s = new g.XmlDocument(o), l = await ie(s, e, { baseUrl: r }) || [], p = s.childNamed("metadata"), m = s.childNamed("manifest"), f = s.childNamed("spine"), x = s.childNamed("guide"), w = p == null ? void 0 : p.childNamed("dc:title"), $ = (p == null ? void 0 : p.childrenNamed("meta")) || [], N = $.find(
216
+ (d) => d.attr.property === "rendition:layout"
217
+ ), T = $.find(
218
+ (d) => d.attr.property === "rendition:flow"
219
+ ), I = $.find(
220
+ (d) => d.attr.property === "rendition:spread"
221
+ ), k = N == null ? void 0 : N.val, B = T == null ? void 0 : T.val, M = I == null ? void 0 : I.val, _ = (w == null ? void 0 : w.val) || ((D = e.files.find(({ dir: d }) => d)) == null ? void 0 : D.basename) || "", H = f == null ? void 0 : f.attr["page-progression-direction"], U = (await z({ archive: e })).reduce(
222
+ (d, c) => c.size + d,
223
+ 0
224
+ );
186
225
  return {
187
226
  filename: e.filename,
188
227
  nav: {
189
228
  toc: l
190
229
  },
191
- renditionLayout: k || r.renditionLayout || "reflowable",
230
+ renditionLayout: k || a.renditionLayout || "reflowable",
192
231
  renditionFlow: B || "auto",
193
232
  renditionSpread: M,
194
233
  title: _,
195
234
  readingDirection: H || "ltr",
196
235
  spineItems: (f == null ? void 0 : f.childrenNamed("itemref").map((d) => {
197
- var P, W, R;
198
- const c = m == null ? void 0 : m.childrenNamed("item").find((u) => u.attr.id === (d == null ? void 0 : d.attr.idref)), V = (c == null ? void 0 : c.attr.href) || "", A = ((P = d == null ? void 0 : d.attr.properties) == null ? void 0 : P.split(" ")) || [], G = ((W = e.files.find((u) => u.uri.endsWith(V))) == null ? void 0 : W.size) || 0, S = n ?? "";
236
+ var W, P, R;
237
+ const c = m == null ? void 0 : m.childrenNamed("item").find((u) => u.attr.id === (d == null ? void 0 : d.attr.idref)), V = (c == null ? void 0 : c.attr.href) || "", A = ((W = d == null ? void 0 : d.attr.properties) == null ? void 0 : W.split(" ")) || [], G = ((P = e.files.find((u) => u.uri.endsWith(V))) == null ? void 0 : P.size) || 0, S = r ?? "";
199
238
  return {
200
239
  id: (c == null ? void 0 : c.attr.id) || "",
201
- href: (R = c == null ? void 0 : c.attr.href) != null && R.startsWith("https://") ? c == null ? void 0 : c.attr.href : a ? `${S}${a}/${c == null ? void 0 : c.attr.href}` : `${S}${c == null ? void 0 : c.attr.href}`,
240
+ href: (R = c == null ? void 0 : c.attr.href) != null && R.startsWith("https://") ? c == null ? void 0 : c.attr.href : n ? `${S}${n}/${c == null ? void 0 : c.attr.href}` : `${S}${c == null ? void 0 : c.attr.href}`,
202
241
  renditionLayout: k || "reflowable",
203
- ...A.find((u) => u === "rendition:layout-reflowable") && {
242
+ ...A.find(
243
+ (u) => u === "rendition:layout-reflowable"
244
+ ) && {
204
245
  renditionLayout: "reflowable"
205
246
  },
206
247
  progressionWeight: G / U,
@@ -217,17 +258,17 @@ const h = {
217
258
  type: d.attr.type
218
259
  }))
219
260
  };
220
- }, ce = async (e, n) => {
221
- var a, r;
222
- const t = await ((a = F(e).data) == null ? void 0 : a.string());
261
+ }, ce = async (e, r) => {
262
+ var n, a;
263
+ const t = await ((n = F(e).data) == null ? void 0 : n.string());
223
264
  if (t) {
224
265
  const o = new g.XmlDocument(t);
225
266
  return {
226
- mediaType: (r = X(o).find((l) => n.endsWith(l.href))) == null ? void 0 : r.mediaType
267
+ mediaType: (a = X(o).find((l) => r.endsWith(l.href))) == null ? void 0 : a.mediaType
227
268
  };
228
269
  }
229
270
  return {
230
- mediaType: de(n)
271
+ mediaType: de(r)
231
272
  };
232
273
  }, de = (e) => {
233
274
  if (e.endsWith(".css"))
@@ -240,10 +281,12 @@ const h = {
240
281
  return "video/mp4";
241
282
  if (e.endsWith(".svg"))
242
283
  return "image/svg+xml";
243
- }, le = ({ archive: e, resourcePath: n }) => async (i) => {
244
- const t = Object.values(e.files).find((r) => r.uri === n);
284
+ }, le = ({ archive: e, resourcePath: r }) => async (i) => {
285
+ const t = Object.values(e.files).find(
286
+ (a) => a.uri === r
287
+ );
245
288
  if (!t) return i;
246
- const a = await ce(e, n);
289
+ const n = await ce(e, r);
247
290
  return {
248
291
  ...i,
249
292
  params: {
@@ -253,33 +296,35 @@ const h = {
253
296
  ...(t == null ? void 0 : t.encodingFormat) && {
254
297
  "Content-Type": t.encodingFormat
255
298
  },
256
- ...a.mediaType && {
257
- "Content-Type": a.mediaType
299
+ ...n.mediaType && {
300
+ "Content-Type": n.mediaType
258
301
  }
259
302
  }
260
303
  }
261
304
  };
262
- }, Fe = async (e, n) => {
263
- const i = Object.values(e.files).find((r) => r.uri === n);
305
+ }, Fe = async (e, r) => {
306
+ const i = Object.values(e.files).find(
307
+ (a) => a.uri === r
308
+ );
264
309
  if (!i)
265
310
  throw new Error("no file found");
266
311
  const t = {
267
312
  params: {
268
313
  status: 200
269
314
  }
270
- }, a = [
271
- le({ archive: e, resourcePath: n }),
272
- ee({ archive: e, resourcePath: n }),
273
- E({ archive: e, resourcePath: n })
315
+ }, n = [
316
+ le({ archive: e, resourcePath: r }),
317
+ ee({ archive: e, resourcePath: r }),
318
+ E({ archive: e, resourcePath: r })
274
319
  ];
275
320
  try {
276
- const r = await a.reduce(async (o, s) => await s(await o), Promise.resolve(t));
277
- return h.log("Generated resource", n, r), {
278
- ...r,
279
- body: r.body || await i.blob()
321
+ const a = await n.reduce(async (o, s) => await s(await o), Promise.resolve(t));
322
+ return h.log("Generated resource", r, a), {
323
+ ...a,
324
+ body: a.body || await i.blob()
280
325
  };
281
- } catch (r) {
282
- throw h.error(r), r;
326
+ } catch (a) {
327
+ throw h.error(a), a;
283
328
  }
284
329
  }, $e = (e) => ({
285
330
  body: `
@@ -299,105 +344,113 @@ const h = {
299
344
  "Content-Type": "text/html;charset=UTF-8"
300
345
  }
301
346
  }
302
- }), me = ({ archive: e, baseUrl: n }) => async () => {
347
+ }), me = ({ archive: e, baseUrl: r }) => async () => {
303
348
  var t;
304
- const i = Object.values(e.files).filter((a) => !a.dir);
349
+ const i = Object.values(e.files).filter((n) => !n.dir);
305
350
  return {
306
351
  filename: e.filename,
307
- title: ((t = e.files.find(({ dir: a }) => a)) == null ? void 0 : t.basename.replace(/\/$/, "")) || "",
352
+ title: ((t = e.files.find(({ dir: n }) => n)) == null ? void 0 : t.basename.replace(/\/$/, "")) || "",
308
353
  renditionLayout: "pre-paginated",
309
354
  renditionSpread: "auto",
310
355
  readingDirection: "ltr",
311
- spineItems: i.map((a, r) => ({
356
+ spineItems: i.filter((n) => !n.basename.endsWith(".db")).map((n, a) => ({
312
357
  // some books such as cbz can have same basename inside different sub folder
313
358
  // we need to make sure to have unique index
314
359
  // /chap01/01.png, /chap02/01.png, etc
315
- id: `${r}.${a.basename}`,
316
- href: encodeURI(`${n}${a.uri}`),
360
+ id: `${a}.${n.basename}`,
361
+ href: encodeURI(`${r}${n.uri}`),
317
362
  renditionLayout: "pre-paginated",
318
363
  progressionWeight: 1 / i.length,
319
364
  pageSpreadLeft: void 0,
320
365
  pageSpreadRight: void 0,
321
- mediaType: a.encodingFormat
366
+ mediaType: n.encodingFormat
322
367
  })),
323
- items: i.map((a, r) => ({
324
- id: `${r}.${a.basename}`,
325
- href: `${n}${a.uri}`
368
+ items: i.map((n, a) => ({
369
+ id: `${a}.${n.basename}`,
370
+ href: `${r}${n.uri}`
326
371
  }))
327
372
  };
328
- }, pe = ({ archive: e }) => async (n) => {
329
- var r;
330
- const i = e.files.find((o) => o.basename.toLowerCase() === "comicinfo.xml");
373
+ }, pe = ({ archive: e }) => async (r) => {
374
+ var a;
375
+ const i = e.files.find(
376
+ (o) => o.basename.toLowerCase() === "comicinfo.xml"
377
+ );
331
378
  if (!i)
332
- return n;
379
+ return r;
333
380
  const t = {
334
- ...n,
335
- spineItems: n.spineItems.filter((o) => !o.id.toLowerCase().endsWith("comicinfo.xml"))
336
- }, a = await i.string();
381
+ ...r,
382
+ spineItems: r.spineItems.filter(
383
+ (o) => !o.id.toLowerCase().endsWith("comicinfo.xml")
384
+ )
385
+ }, n = await i.string();
337
386
  try {
338
- const s = ((r = new g.XmlDocument(a).childNamed("Manga")) == null ? void 0 : r.val) || "unknown";
387
+ const s = ((a = new g.XmlDocument(n).childNamed("Manga")) == null ? void 0 : a.val) || "unknown";
339
388
  return {
340
389
  ...t,
341
390
  readingDirection: s === "YesAndRightToLeft" ? "rtl" : "ltr"
342
391
  };
343
392
  } catch (o) {
344
393
  return console.error(`Unable to parse comicinfo.xml for content
345
- `, a), console.error(o), t;
394
+ `, n), console.error(o), t;
346
395
  }
347
396
  }, fe = (e) => {
348
397
  var i;
349
- const n = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((t) => t.attr.name === "viewport");
350
- return !!(n && n.attr.name === "viewport");
351
- }, ue = (e) => e.reduce(async (n, i) => {
352
- if (!await n || !q({
398
+ const r = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((t) => t.attr.name === "viewport");
399
+ return !!(r && r.attr.name === "viewport");
400
+ }, ue = (e) => e.reduce(async (r, i) => {
401
+ if (!await r || !q({
353
402
  mimeType: i.encodingFormat,
354
403
  uri: i.uri
355
404
  }))
356
405
  return !1;
357
- const a = await i.string();
358
- return a ? fe(new g.XmlDocument(a)) : !1;
359
- }, Promise.resolve(!0)), he = ({ archive: e }) => async (n) => {
360
- if (n.renditionLayout === "reflowable" && n.spineItems.every((t) => t.renditionLayout === "reflowable")) {
406
+ const n = await i.string();
407
+ return n ? fe(new g.XmlDocument(n)) : !1;
408
+ }, Promise.resolve(!0)), he = ({ archive: e }) => async (r) => {
409
+ if (r.renditionLayout === "reflowable" && r.spineItems.every((t) => t.renditionLayout === "reflowable")) {
361
410
  const t = await z({ archive: e });
362
411
  if (await ue(t))
363
412
  return {
364
- ...n,
365
- spineItems: n.spineItems.map((r) => ({
366
- ...r,
413
+ ...r,
414
+ spineItems: r.spineItems.map((a) => ({
415
+ ...a,
367
416
  renditionLayout: "pre-paginated"
368
417
  })),
369
418
  renditionLayout: "pre-paginated"
370
419
  };
371
420
  }
372
- return n;
373
- }, C = (e, n) => {
374
- var a;
375
- const i = e.split(/(\d+)/), t = n.split(/(\d+)/);
376
- for (let r = 0, o = i.length; r < o; r++)
377
- if (i[r] !== t[r])
378
- return (a = i[r]) != null && a.match(/\d/) ? +(i[r] || "") - +(t[r] || "") : (i[r] || "").localeCompare(t[r] || "");
421
+ return r;
422
+ }, C = (e, r) => {
423
+ var n;
424
+ const i = e.split(/(\d+)/), t = r.split(/(\d+)/);
425
+ for (let a = 0, o = i.length; a < o; a++)
426
+ if (i[a] !== t[a])
427
+ return (n = i[a]) != null && n.match(/\d/) ? +(i[a] || "") - +(t[a] || "") : (i[a] || "").localeCompare(t[a] || "");
379
428
  return 1;
380
- }, ge = ({ archive: e, baseUrl: n }) => async (i) => {
429
+ }, ge = ({ archive: e, baseUrl: r }) => async (i) => {
381
430
  if (i.nav) return i;
382
- const t = [...e.files].sort((r, o) => C(r.uri, o.uri)), a = Object.values(t).reduce(
383
- (r, o) => {
431
+ const t = [...e.files].sort(
432
+ (a, o) => C(a.uri, o.uri)
433
+ ), n = Object.values(
434
+ t
435
+ ).reduce(
436
+ (a, o) => {
384
437
  const s = o.uri.split("/");
385
438
  return !o.dir && s.length > 1 && s.forEach((p, m) => {
386
439
  if (m === s.length - 1) return;
387
- r.find(({ title: w }) => w === p) || r.push({
440
+ a.find(({ title: w }) => w === p) || a.push({
388
441
  contents: [],
389
- href: v(n, encodeURI(o.uri)).replace(/\/$/, ""),
442
+ href: v(r, encodeURI(o.uri)).replace(/\/$/, ""),
390
443
  path: o.uri.replace(/\/$/, ""),
391
444
  title: s[0] ?? ""
392
445
  });
393
- }), r;
446
+ }), a;
394
447
  },
395
448
  []
396
449
  );
397
- return a.length === 0 ? i : {
450
+ return n.length === 0 ? i : {
398
451
  ...i,
399
452
  nav: {
400
- toc: a
453
+ toc: n
401
454
  }
402
455
  };
403
456
  }, ye = {
@@ -411,41 +464,43 @@ const h = {
411
464
  renditionSpread: "auto",
412
465
  spineItems: [],
413
466
  title: ""
414
- }, Ne = async (e, { baseUrl: n = "" } = {}) => {
467
+ }, Ne = async (e, { baseUrl: r = "" } = {}) => {
415
468
  const i = [
416
- me({ archive: e, baseUrl: n }),
417
- se({ archive: e, baseUrl: n }),
418
- he({ archive: e, baseUrl: n }),
419
- pe({ archive: e, baseUrl: n }),
420
- ge({ archive: e, baseUrl: n })
469
+ me({ archive: e, baseUrl: r }),
470
+ se({ archive: e, baseUrl: r }),
471
+ he({ archive: e, baseUrl: r }),
472
+ pe({ archive: e, baseUrl: r }),
473
+ ge({ archive: e, baseUrl: r })
421
474
  ];
422
475
  try {
423
- const t = await i.reduce(async (a, r) => await r(await a), Promise.resolve(ye));
476
+ const t = await i.reduce(async (n, a) => await a(await n), Promise.resolve(ye));
424
477
  return h.log("Generated manifest", t), t;
425
478
  } catch (t) {
426
479
  throw h.error(t), t;
427
480
  }
428
- }, y = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Te = async (e, n) => {
481
+ }, y = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Te = async (e, r) => {
429
482
  const i = `
430
483
  <?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
431
484
  <metadata>
432
- <meta property="rendition:layout">${n != null && n.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
433
- ${n != null && n.useRenditionFlow ? '<meta property="rendition:flow">scrolled-continuous</meta>' : ""}
485
+ <meta property="rendition:layout">${r != null && r.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
486
+ ${r != null && r.useRenditionFlow ? '<meta property="rendition:flow">scrolled-continuous</meta>' : ""}
434
487
  </metadata>
435
488
  <manifest>
436
- ${e.map((r) => `<item id="${y(r)}" href="${r}" media-type="${L(r)}"/>`).join(`
489
+ ${e.map(
490
+ (a) => `<item id="${y(a)}" href="${a}" media-type="${L(a)}"/>`
491
+ ).join(`
437
492
  `)}
438
493
  </manifest>
439
494
  <spine>
440
- ${e.map((r) => `<itemref idref="${y(r)}" />`).join(`
495
+ ${e.map((a) => `<itemref idref="${y(a)}" />`).join(`
441
496
  `)}
442
497
  </spine>
443
498
  </package>
444
- `, t = e.map((r) => ({
499
+ `, t = e.map((a) => ({
445
500
  dir: !1,
446
- basename: y(r),
447
- encodingFormat: L(r),
448
- uri: r,
501
+ basename: y(a),
502
+ encodingFormat: L(a),
503
+ uri: a,
449
504
  size: 100 / e.length,
450
505
  base64: async () => "",
451
506
  blob: async () => new Blob(),
@@ -464,14 +519,14 @@ const h = {
464
519
  }, ...t],
465
520
  close: () => Promise.resolve()
466
521
  };
467
- }, be = async (e) => new Promise((n) => {
522
+ }, be = async (e) => new Promise((r) => {
468
523
  const i = new FileReader();
469
524
  i.readAsDataURL(e), i.onloadend = function() {
470
525
  const t = i.result;
471
- n(t);
526
+ r(t);
472
527
  };
473
528
  }), Ie = async (e, {
474
- mimeType: n,
529
+ mimeType: r,
475
530
  direction: i
476
531
  } = { mimeType: "text/plain" }) => {
477
532
  const t = `
@@ -510,53 +565,58 @@ const h = {
510
565
  string: async () => typeof e == "string" ? e : e.text(),
511
566
  base64: async () => typeof e == "string" ? btoa(e) : be(e),
512
567
  size: typeof e == "string" ? e.length : e.size,
513
- encodingFormat: n
568
+ encodingFormat: r
514
569
  }
515
570
  ],
516
571
  close: () => Promise.resolve()
517
572
  };
518
- }, Ae = async (e, { orderByAlpha: n, name: i } = {}) => {
573
+ }, Ae = async (e, { orderByAlpha: r, name: i } = {}) => {
519
574
  let t = Object.values(e.files);
520
- n && (t = t.slice().sort((r, o) => C(r.name, o.name)));
521
- const a = {
575
+ r && (t = t.slice().sort((a, o) => C(a.name, o.name)));
576
+ const n = {
522
577
  filename: i || "",
523
- files: t.map((r) => ({
524
- dir: r.dir,
525
- basename: y(r.name),
526
- uri: r.name,
527
- blob: () => r.async("blob"),
528
- string: () => r.async("string"),
529
- base64: () => r.async("base64"),
530
- ...r.internalStream && {
531
- stream: r.internalStream
578
+ files: t.map((a) => ({
579
+ dir: a.dir,
580
+ basename: y(a.name),
581
+ uri: a.name,
582
+ blob: () => a.async("blob"),
583
+ string: () => a.async("string"),
584
+ base64: () => a.async("base64"),
585
+ ...a.internalStream && {
586
+ stream: a.internalStream
532
587
  },
533
588
  // this is private API
534
589
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
535
590
  // @ts-ignore
536
- size: r._data.uncompressedSize
591
+ size: a._data.uncompressedSize
537
592
  })),
538
593
  close: () => Promise.resolve()
539
594
  };
540
- return h.log("Generated archive", a), a;
541
- }, Ce = async (e, { orderByAlpha: n, name: i } = {}) => {
595
+ return h.log("Generated archive", n), n;
596
+ }, Ce = async (e, { orderByAlpha: r, name: i } = {}) => {
542
597
  let t = e;
543
- return n && (t = t.slice().sort((a, r) => C(a.name, r.name))), {
598
+ return r && (t = t.slice().sort((n, a) => C(n.name, a.name))), {
544
599
  filename: i || "",
545
- files: t.map((a) => ({
546
- dir: a.isDir,
547
- basename: y(a.name),
548
- uri: a.name,
549
- blob: async () => new Blob([await a.data()]),
600
+ files: t.map((n) => ({
601
+ dir: n.isDir,
602
+ basename: y(n.name),
603
+ uri: n.name,
604
+ blob: async () => new Blob([await n.data()]),
550
605
  string: async () => {
551
- const r = await a.data();
552
- return String.fromCharCode.apply(null, Array.from(new Uint16Array(r)));
606
+ const a = await n.data();
607
+ return String.fromCharCode.apply(
608
+ null,
609
+ Array.from(new Uint16Array(a))
610
+ );
553
611
  },
554
612
  base64: async () => "",
555
- size: a.size
613
+ size: n.size
556
614
  })),
557
615
  close: () => Promise.resolve()
558
616
  };
559
- }, ke = ({ enableReport: e } = {}) => {
617
+ }, ke = ({
618
+ enableReport: e
619
+ } = {}) => {
560
620
  h.enable(!!e);
561
621
  };
562
622
  export {