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