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