@prose-reader/streamer 1.12.0 → 1.14.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,87 +1,87 @@
1
1
  import h from "xmldoc";
2
- import { urlJoin as w, isXmlBasedMimeType as G, detectMimeTypeFromName as P } from "@prose-reader/shared";
3
- const z = (e, { opfBasePath: i, baseUrl: r }) => {
2
+ import { urlJoin as v, isXmlBasedMimeType as G, detectMimeTypeFromName as z } from "@prose-reader/shared";
3
+ const O = (e, { opfBasePath: i, baseUrl: n }) => {
4
4
  const a = {
5
5
  contents: [],
6
6
  path: "",
7
7
  href: "",
8
8
  title: ""
9
9
  };
10
- let n = e.childNamed("span") || e.childNamed("a");
11
- a.title = (n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || a.title;
12
- let t = n == null ? void 0 : n.name;
13
- t !== "a" && (n = e.descendantWithPath(`${t}.a`), n && (t = n.name.toLowerCase())), t === "a" && (n != null && n.attr.href) && (a.path = w(i, n.attr.href), a.href = w(r, i, n.attr.href));
10
+ let t = e.childNamed("span") || e.childNamed("a");
11
+ a.title = (t == null ? void 0 : t.attr.title) || (t == null ? void 0 : t.val.trim()) || a.title;
12
+ let r = t == null ? void 0 : t.name;
13
+ r !== "a" && (t = e.descendantWithPath(`${r}.a`), t && (r = t.name.toLowerCase())), r === "a" && (t != null && t.attr.href) && (a.path = v(i, t.attr.href), a.href = v(n, i, t.attr.href));
14
14
  const o = e.childNamed("ol");
15
15
  if (o) {
16
16
  const s = o.childrenNamed("li");
17
- s && s.length > 0 && (a.contents = s.map((d) => z(d, { opfBasePath: i, baseUrl: r })));
17
+ s && s.length > 0 && (a.contents = s.map((d) => O(d, { opfBasePath: i, baseUrl: n })));
18
18
  }
19
19
  return a;
20
- }, J = (e, { opfBasePath: i, baseUrl: r }) => {
21
- var t, o;
20
+ }, J = (e, { opfBasePath: i, baseUrl: n }) => {
21
+ var r, o;
22
22
  const a = [];
23
- let n;
24
- return e.descendantWithPath("body.nav.ol") ? n = (t = e.descendantWithPath("body.nav.ol")) == null ? void 0 : t.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((s) => a.push(z(s, { opfBasePath: i, baseUrl: r }))), a;
25
- }, K = async (e, i, { opfBasePath: r, baseUrl: a }) => {
26
- var t;
27
- const n = (t = e.childNamed("manifest")) == null ? void 0 : t.childrenNamed("item").find((o) => o.attr.properties === "nav");
28
- if (n) {
29
- const o = Object.values(i.files).find((s) => s.uri.endsWith(n.attr.href || ""));
23
+ let t;
24
+ return e.descendantWithPath("body.nav.ol") ? t = (r = e.descendantWithPath("body.nav.ol")) == null ? void 0 : r.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) => a.push(O(s, { opfBasePath: i, baseUrl: n }))), a;
25
+ }, K = async (e, i, { opfBasePath: n, baseUrl: a }) => {
26
+ var r;
27
+ const t = (r = e.childNamed("manifest")) == null ? void 0 : r.childrenNamed("item").find((o) => o.attr.properties === "nav");
28
+ if (t) {
29
+ const o = Object.values(i.files).find((s) => s.uri.endsWith(t.attr.href || ""));
30
30
  if (o) {
31
31
  const s = new h.XmlDocument(await o.string());
32
- return J(s, { opfBasePath: r, baseUrl: a });
32
+ return J(s, { opfBasePath: n, baseUrl: a });
33
33
  }
34
34
  }
35
- }, O = (e, { opfBasePath: i, baseUrl: r, prefix: a }) => {
35
+ }, X = (e, { opfBasePath: i, baseUrl: n, prefix: a }) => {
36
36
  var s, d;
37
- const n = ((s = e == null ? void 0 : e.childNamed(`${a}content`)) == null ? void 0 : s.attr.src) || "", t = {
37
+ const t = ((s = e == null ? void 0 : e.childNamed(`${a}content`)) == null ? void 0 : s.attr.src) || "", r = {
38
38
  title: ((d = e == null ? void 0 : e.descendantWithPath(`${a}navLabel.${a}text`)) == null ? void 0 : d.val) || "",
39
- path: w(i, n),
40
- href: w(r, i, n),
39
+ path: v(i, t),
40
+ href: v(n, i, t),
41
41
  contents: []
42
42
  }, o = e.childrenNamed(`${a}navPoint`);
43
- return o && o.length > 0 && (t.contents = o.map((p) => O(p, { opfBasePath: i, baseUrl: r, prefix: a }))), t;
44
- }, Y = (e, { opfBasePath: i, baseUrl: r }) => {
43
+ return o && o.length > 0 && (r.contents = o.map((p) => X(p, { opfBasePath: i, baseUrl: n, prefix: a }))), r;
44
+ }, Y = (e, { opfBasePath: i, baseUrl: n }) => {
45
45
  var o;
46
- const a = [], n = e.name;
47
- let t = "";
48
- return n.indexOf(":") !== -1 && (t = n.split(":")[0] + ":"), (o = e.childNamed(`${t}navMap`)) == null || o.childrenNamed(`${t}navPoint`).forEach((s) => a.push(O(s, { opfBasePath: i, baseUrl: r, prefix: t }))), a;
46
+ const a = [], t = e.name;
47
+ let r = "";
48
+ return t.indexOf(":") !== -1 && (r = t.split(":")[0] + ":"), (o = e.childNamed(`${r}navMap`)) == null || o.childrenNamed(`${r}navPoint`).forEach((s) => a.push(X(s, { opfBasePath: i, baseUrl: n, prefix: r }))), a;
49
49
  }, Q = async ({
50
50
  opfData: e,
51
51
  opfBasePath: i,
52
- baseUrl: r,
52
+ baseUrl: n,
53
53
  archive: a
54
54
  }) => {
55
55
  var o;
56
- const n = e.childNamed("spine"), t = n && n.attr.toc;
57
- if (t) {
58
- const s = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((d) => d.attr.id === t);
56
+ const t = e.childNamed("spine"), r = t && t.attr.toc;
57
+ if (r) {
58
+ const s = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((d) => d.attr.id === r);
59
59
  if (s) {
60
60
  const d = `${i}${i === "" ? "" : "/"}${s.attr.href}`, p = Object.values(a.files).find((m) => m.uri.endsWith(d));
61
61
  if (p) {
62
62
  const m = new h.XmlDocument(await p.string());
63
- return Y(m, { opfBasePath: i, baseUrl: r });
63
+ return Y(m, { opfBasePath: i, baseUrl: n });
64
64
  }
65
65
  }
66
66
  }
67
- }, Z = async (e, i, { baseUrl: r }) => {
68
- const { basePath: a } = v(i) || {}, n = await Q({
67
+ }, Z = async (e, i, { baseUrl: n }) => {
68
+ const { basePath: a } = $(i) || {}, t = await Q({
69
69
  opfData: e,
70
70
  opfBasePath: a,
71
71
  archive: i,
72
- baseUrl: r
72
+ baseUrl: n
73
73
  });
74
- return n || await K(e, i, { opfBasePath: a, baseUrl: r });
74
+ return t || await K(e, i, { opfBasePath: a, baseUrl: n });
75
75
  }, E = async (e) => {
76
76
  const i = {
77
77
  renditionLayout: void 0
78
78
  };
79
79
  return await Promise.all(
80
- e.files.map(async (r) => {
81
- var a, n;
82
- if (r.uri.endsWith("com.kobobooks.display-options.xml")) {
83
- const o = (a = new h.XmlDocument(await r.string()).childNamed("platform")) == null ? void 0 : a.childNamed("option");
84
- ((n = o == null ? void 0 : o.attr) == null ? void 0 : n.name) === "fixed-layout" && o.val === "true" && (i.renditionLayout = "pre-paginated");
80
+ e.files.map(async (n) => {
81
+ var a, t;
82
+ if (n.uri.endsWith("com.kobobooks.display-options.xml")) {
83
+ const o = (a = new h.XmlDocument(await n.string()).childNamed("platform")) == null ? void 0 : a.childNamed("option");
84
+ ((t = o == null ? void 0 : o.attr) == null ? void 0 : t.name) === "fixed-layout" && o.val === "true" && (i.renditionLayout = "pre-paginated");
85
85
  }
86
86
  })
87
87
  ), i;
@@ -107,97 +107,97 @@ const y = {
107
107
  b && console.timeEnd(`[prose-reader-streamer] [metric] ${e}`);
108
108
  },
109
109
  metric: (e, i = 1 / 0) => {
110
- const r = typeof e == "number" ? e : e.duration;
111
- b && (e.duration <= i ? console.log("[prose-reader-streamer] [metric] ", `${e.name} took ${r}ms`) : console.warn(
110
+ const n = typeof e == "number" ? e : e.duration;
111
+ b && (e.duration <= i ? console.log("[prose-reader-streamer] [metric] ", `${e.name} took ${n}ms`) : console.warn(
112
112
  "[prose-reader-streamer] [metric] ",
113
113
  `${e.name} took ${e.duration}ms which is above the ${i}ms target for this function`
114
114
  ));
115
115
  },
116
- measurePerformance: (e, i = 10, r) => (...a) => {
117
- const n = performance.now(), t = r(...a);
118
- if (t && t.then)
119
- return t.then((s) => {
116
+ measurePerformance: (e, i = 10, n) => (...a) => {
117
+ const t = performance.now(), r = n(...a);
118
+ if (r && r.then)
119
+ return r.then((s) => {
120
120
  const d = performance.now();
121
- return y.metric({ name: e, duration: d - n }, i), s;
121
+ return y.metric({ name: e, duration: d - t }, i), s;
122
122
  });
123
123
  const o = performance.now();
124
- return y.metric({ name: e, duration: o - n }, i), t;
124
+ return y.metric({ name: e, duration: o - t }, i), r;
125
125
  }
126
- }, v = (e) => {
127
- const r = Object.values(e.files).filter((a) => !a.dir).find((a) => a.uri.endsWith(".opf"));
126
+ }, $ = (e) => {
127
+ const n = Object.values(e.files).filter((a) => !a.dir).find((a) => a.uri.endsWith(".opf"));
128
128
  return {
129
- data: r,
130
- basePath: (r == null ? void 0 : r.uri.substring(0, r.uri.lastIndexOf("/"))) || ""
129
+ data: n,
130
+ basePath: (n == null ? void 0 : n.uri.substring(0, n.uri.lastIndexOf("/"))) || ""
131
131
  };
132
- }, X = async ({ archive: e }) => {
133
- const { data: i, basePath: r } = v(e) || {}, a = await (i == null ? void 0 : i.string());
132
+ }, j = async ({ archive: e }) => {
133
+ const { data: i, basePath: n } = $(e) || {}, a = await (i == null ? void 0 : i.string());
134
134
  if (!a)
135
135
  return [];
136
- const n = new h.XmlDocument(a), t = n.childNamed("manifest"), o = n.childNamed("spine"), s = o == null ? void 0 : o.childrenNamed("itemref").map((m) => m.attr.idref), d = (t == null ? void 0 : t.childrenNamed("item").filter((m) => s.includes(m.attr.id || ""))) || [];
137
- return e.files.filter((m) => d.find((f) => r ? `${r}/${f.attr.href}` === m.uri : `${f.attr.href}` === m.uri));
138
- }, j = (e) => {
139
- var r;
136
+ const t = new h.XmlDocument(a), r = t.childNamed("manifest"), o = t.childNamed("spine"), s = o == null ? void 0 : o.childrenNamed("itemref").map((m) => m.attr.idref), d = (r == null ? void 0 : r.childrenNamed("item").filter((m) => s.includes(m.attr.id || ""))) || [];
137
+ return e.files.filter((m) => d.find((f) => n ? `${n}/${f.attr.href}` === m.uri : `${f.attr.href}` === m.uri));
138
+ }, R = (e) => {
139
+ var n;
140
140
  const i = e.childNamed("manifest");
141
- return ((r = i == null ? void 0 : i.childrenNamed("item")) == null ? void 0 : r.map((a) => ({
141
+ return ((n = i == null ? void 0 : i.childrenNamed("item")) == null ? void 0 : n.map((a) => ({
142
142
  href: a.attr.href || "",
143
143
  id: a.attr.id || "",
144
144
  mediaType: a.attr["media-type"]
145
145
  }))) || [];
146
- }, ee = ({ archive: e, baseUrl: i }) => async (r) => {
147
- var I;
148
- const { data: a, basePath: n } = v(e) || {}, t = await E(e);
146
+ }, ee = ({ archive: e, baseUrl: i }) => async (n) => {
147
+ var A;
148
+ const { data: a, basePath: t } = $(e) || {}, r = await E(e);
149
149
  if (!a)
150
- return r;
150
+ return n;
151
151
  const o = await a.string();
152
- y.log(o, t);
153
- const s = new h.XmlDocument(o), d = await Z(s, e, { baseUrl: i }) || [], p = s.childNamed("metadata"), m = s.childNamed("manifest"), f = s.childNamed("spine"), $ = s.childNamed("guide"), x = p == null ? void 0 : p.childNamed("dc:title"), F = (p == null ? void 0 : p.childrenNamed("meta")) || [], N = F.find((l) => l.attr.property === "rendition:layout"), T = F.find((l) => l.attr.property === "rendition:flow"), D = F.find((l) => l.attr.property === "rendition:spread"), A = N == null ? void 0 : N.val, M = T == null ? void 0 : T.val, B = D == null ? void 0 : D.val, H = (x == null ? void 0 : x.val) || ((I = e.files.find(({ dir: l }) => l)) == null ? void 0 : I.basename) || "", V = f == null ? void 0 : f.attr["page-progression-direction"], _ = (await X({ archive: e })).reduce((l, c) => c.size + l, 0);
152
+ y.log(o, r);
153
+ const s = new h.XmlDocument(o), d = await Z(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"), x = (p == null ? void 0 : p.childrenNamed("meta")) || [], N = x.find((l) => l.attr.property === "rendition:layout"), T = x.find((l) => l.attr.property === "rendition:flow"), I = x.find((l) => l.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, H = (w == null ? void 0 : w.val) || ((A = e.files.find(({ dir: l }) => l)) == null ? void 0 : A.basename) || "", U = f == null ? void 0 : f.attr["page-progression-direction"], V = (await j({ archive: e })).reduce((l, c) => c.size + l, 0);
154
154
  return {
155
155
  filename: e.filename,
156
156
  nav: {
157
157
  toc: d
158
158
  },
159
- renditionLayout: A || t.renditionLayout || "reflowable",
160
- renditionFlow: M || "auto",
161
- renditionSpread: B,
159
+ renditionLayout: k || r.renditionLayout || "reflowable",
160
+ renditionFlow: B || "auto",
161
+ renditionSpread: M,
162
162
  title: H,
163
- readingDirection: V || "ltr",
163
+ readingDirection: U || "ltr",
164
164
  spineItems: (f == null ? void 0 : f.childrenNamed("itemref").map((l) => {
165
- var C, S, W;
166
- const c = m == null ? void 0 : m.childrenNamed("item").find((u) => u.attr.id === (l == null ? void 0 : l.attr.idref)), U = (c == null ? void 0 : c.attr.href) || "", L = ((C = l == null ? void 0 : l.attr.properties) == null ? void 0 : C.split(" ")) || [], q = ((S = e.files.find((u) => u.uri.endsWith(U))) == null ? void 0 : S.size) || 0, k = i ?? "";
165
+ var S, W, P;
166
+ const c = m == null ? void 0 : m.childrenNamed("item").find((u) => u.attr.id === (l == null ? void 0 : l.attr.idref)), _ = (c == null ? void 0 : c.attr.href) || "", D = ((S = l == null ? void 0 : l.attr.properties) == null ? void 0 : S.split(" ")) || [], q = ((W = e.files.find((u) => u.uri.endsWith(_))) == null ? void 0 : W.size) || 0, C = i ?? "";
167
167
  return {
168
168
  id: (c == null ? void 0 : c.attr.id) || "",
169
- href: (W = c == null ? void 0 : c.attr.href) != null && W.startsWith("https://") ? c == null ? void 0 : c.attr.href : n ? `${k}${n}/${c == null ? void 0 : c.attr.href}` : `${k}${c == null ? void 0 : c.attr.href}`,
170
- renditionLayout: A || "reflowable",
171
- ...L.find((u) => u === "rendition:layout-reflowable") && {
169
+ href: (P = c == null ? void 0 : c.attr.href) != null && P.startsWith("https://") ? c == null ? void 0 : c.attr.href : t ? `${C}${t}/${c == null ? void 0 : c.attr.href}` : `${C}${c == null ? void 0 : c.attr.href}`,
170
+ renditionLayout: k || "reflowable",
171
+ ...D.find((u) => u === "rendition:layout-reflowable") && {
172
172
  renditionLayout: "reflowable"
173
173
  },
174
- progressionWeight: q / _,
175
- pageSpreadLeft: L.some((u) => u === "page-spread-left") || void 0,
176
- pageSpreadRight: L.some((u) => u === "page-spread-right") || void 0,
174
+ progressionWeight: q / V,
175
+ pageSpreadLeft: D.some((u) => u === "page-spread-left") || void 0,
176
+ pageSpreadRight: D.some((u) => u === "page-spread-right") || void 0,
177
177
  mediaType: c == null ? void 0 : c.attr["media-type"]
178
178
  };
179
179
  })) || [],
180
- items: j(s),
181
- guide: $ == null ? void 0 : $.childrenNamed("reference").map((l) => ({
180
+ items: R(s),
181
+ guide: F == null ? void 0 : F.childrenNamed("reference").map((l) => ({
182
182
  href: l.attr.href || "",
183
183
  title: l.attr.title || "",
184
184
  type: l.attr.type
185
185
  }))
186
186
  };
187
- }, fe = async (e, i) => {
188
- const r = Object.values(e.files).find((t) => t.uri === i), a = await te(e, i);
189
- if (!r)
187
+ }, ue = async (e, i) => {
188
+ const n = Object.values(e.files).find((r) => r.uri === i), a = await te(e, i);
189
+ if (!n)
190
190
  throw new Error("no file found");
191
- const n = await r.blob();
191
+ const t = await n.blob();
192
192
  return {
193
- body: n,
193
+ body: t,
194
194
  params: {
195
195
  headers: {
196
- ...n.type && {
197
- "Content-Type": n.type
196
+ ...t.type && {
197
+ "Content-Type": t.type
198
198
  },
199
- ...r.encodingFormat && {
200
- "Content-Type": r.encodingFormat
199
+ ...n.encodingFormat && {
200
+ "Content-Type": n.encodingFormat
201
201
  },
202
202
  ...a.mediaType && {
203
203
  "Content-Type": a.mediaType
@@ -206,12 +206,12 @@ const y = {
206
206
  }
207
207
  };
208
208
  }, te = async (e, i) => {
209
- var n, t;
210
- const a = await ((n = v(e).data) == null ? void 0 : n.string());
209
+ var t, r;
210
+ const a = await ((t = $(e).data) == null ? void 0 : t.string());
211
211
  if (a) {
212
212
  const o = new h.XmlDocument(a);
213
213
  return {
214
- mediaType: (t = j(o).find((d) => i.endsWith(d.href))) == null ? void 0 : t.mediaType
214
+ mediaType: (r = R(o).find((d) => i.endsWith(d.href))) == null ? void 0 : r.mediaType
215
215
  };
216
216
  }
217
217
  return {
@@ -228,70 +228,96 @@ const y = {
228
228
  return "video/mp4";
229
229
  if (e.endsWith(".svg"))
230
230
  return "image/svg+xml";
231
- }, ae = ({ archive: e, baseUrl: i }) => async (r) => {
232
- var n;
233
- const a = Object.values(e.files).filter((t) => !t.dir);
231
+ }, re = ({ archive: e, baseUrl: i }) => async () => {
232
+ var a;
233
+ const n = Object.values(e.files).filter((t) => !t.dir);
234
234
  return {
235
235
  filename: e.filename,
236
- nav: {
237
- toc: []
238
- },
239
- title: ((n = e.files.find(({ dir: t }) => t)) == null ? void 0 : n.basename.replace(/\/$/, "")) || "",
236
+ title: ((a = e.files.find(({ dir: t }) => t)) == null ? void 0 : a.basename.replace(/\/$/, "")) || "",
240
237
  renditionLayout: "pre-paginated",
241
238
  renditionSpread: "auto",
242
239
  readingDirection: "ltr",
243
- spineItems: a.map((t, o) => ({
244
- id: `${o}.${t.basename}`,
245
- href: `${i}${t.uri}`,
240
+ spineItems: n.map((t, r) => ({
241
+ id: `${r}.${t.basename}`,
242
+ href: encodeURI(`${i}${t.uri}`),
246
243
  renditionLayout: "pre-paginated",
247
- progressionWeight: 1 / a.length,
244
+ progressionWeight: 1 / n.length,
248
245
  pageSpreadLeft: void 0,
249
246
  pageSpreadRight: void 0,
250
247
  mediaType: t.encodingFormat
251
248
  })),
252
- items: a.map((t, o) => ({
253
- id: `${o}.${t.basename}`,
249
+ items: n.map((t, r) => ({
250
+ id: `${r}.${t.basename}`,
254
251
  href: `${i}${t.uri}`
255
252
  }))
256
253
  };
257
- }, re = ({ archive: e, baseUrl: i }) => async (r) => {
254
+ }, ae = ({ archive: e, baseUrl: i }) => async (n) => {
258
255
  var s;
259
256
  const a = e.files.find((d) => d.basename.toLowerCase() === "comicinfo.xml");
260
257
  if (!a)
261
- return r;
262
- const n = await a.string(), o = ((s = new h.XmlDocument(n).childNamed("Manga")) == null ? void 0 : s.val) || "unknown";
258
+ return n;
259
+ const t = await a.string(), o = ((s = new h.XmlDocument(t).childNamed("Manga")) == null ? void 0 : s.val) || "unknown";
263
260
  return {
264
- ...r,
265
- spineItems: r.spineItems.filter((d) => d.id.toLowerCase() !== "comicinfo.xml"),
261
+ ...n,
262
+ spineItems: n.spineItems.filter((d) => d.id.toLowerCase() !== "comicinfo.xml"),
266
263
  readingDirection: o === "YesAndRightToLeft" ? "rtl" : "ltr"
267
264
  };
268
265
  }, ie = (e) => {
269
- var r;
270
- const i = (r = e.descendantWithPath("head")) == null ? void 0 : r.childrenNamed("meta").find((a) => a.attr.name === "viewport");
266
+ var n;
267
+ const i = (n = e.descendantWithPath("head")) == null ? void 0 : n.childrenNamed("meta").find((a) => a.attr.name === "viewport");
271
268
  return !!(i && i.attr.name === "viewport");
272
- }, oe = (e) => e.reduce(async (i, r) => {
269
+ }, oe = (e) => e.reduce(async (i, n) => {
273
270
  if (!await i || !G({
274
- mimeType: r.encodingFormat,
275
- uri: r.uri
271
+ mimeType: n.encodingFormat,
272
+ uri: n.uri
276
273
  }))
277
274
  return !1;
278
- const n = await r.string();
279
- return n ? ie(new h.XmlDocument(n)) : !1;
280
- }, Promise.resolve(!0)), se = ({ archive: e, baseUrl: i }) => async (r) => {
281
- if (r.renditionLayout === "reflowable" && r.spineItems.every((n) => n.renditionLayout === "reflowable")) {
282
- const n = await X({ archive: e });
283
- if (await oe(n))
275
+ const t = await n.string();
276
+ return t ? ie(new h.XmlDocument(t)) : !1;
277
+ }, Promise.resolve(!0)), se = ({ archive: e, baseUrl: i }) => async (n) => {
278
+ if (n.renditionLayout === "reflowable" && n.spineItems.every((t) => t.renditionLayout === "reflowable")) {
279
+ const t = await j({ archive: e });
280
+ if (await oe(t))
284
281
  return {
285
- ...r,
286
- spineItems: r.spineItems.map((o) => ({
282
+ ...n,
283
+ spineItems: n.spineItems.map((o) => ({
287
284
  ...o,
288
285
  renditionLayout: "pre-paginated"
289
286
  })),
290
287
  renditionLayout: "pre-paginated"
291
288
  };
292
289
  }
293
- return r;
294
- }, ce = {
290
+ return n;
291
+ }, L = (e, i) => {
292
+ var t;
293
+ const n = e.split(/(\d+)/), a = i.split(/(\d+)/);
294
+ for (let r = 0, o = n.length; r < o; r++)
295
+ if (n[r] !== a[r])
296
+ return (t = n[r]) != null && t.match(/\d/) ? +(n[r] || "") - +(a[r] || "") : (n[r] || "").localeCompare(a[r] || "");
297
+ return 1;
298
+ }, ce = ({ archive: e, baseUrl: i }) => async (n) => {
299
+ if (n.nav)
300
+ return n;
301
+ const a = [...e.files].sort((r, o) => L(r.uri, o.uri)), t = Object.values(a).reduce((r, o) => {
302
+ const s = o.uri.split("/");
303
+ return !o.dir && s.length > 1 && s.forEach((p, m) => {
304
+ if (m === s.length - 1)
305
+ return;
306
+ r.find(({ title: w }) => w === p) || r.push({
307
+ contents: [],
308
+ href: v(i, encodeURI(o.uri)).replace(/\/$/, ""),
309
+ path: o.uri.replace(/\/$/, ""),
310
+ title: s[0] ?? ""
311
+ });
312
+ }), r;
313
+ }, []);
314
+ return t.length === 0 ? n : {
315
+ ...n,
316
+ nav: {
317
+ toc: t
318
+ }
319
+ };
320
+ }, de = {
295
321
  filename: "",
296
322
  items: [],
297
323
  nav: {
@@ -302,40 +328,41 @@ const y = {
302
328
  renditionSpread: "auto",
303
329
  spineItems: [],
304
330
  title: ""
305
- }, ue = async (e, { baseUrl: i = "" } = {}) => {
306
- const r = [
307
- ae({ archive: e, baseUrl: i }),
331
+ }, he = async (e, { baseUrl: i = "" } = {}) => {
332
+ const n = [
333
+ re({ archive: e, baseUrl: i }),
308
334
  ee({ archive: e, baseUrl: i }),
309
335
  se({ archive: e, baseUrl: i }),
310
- re({ archive: e, baseUrl: i })
336
+ ae({ archive: e, baseUrl: i }),
337
+ ce({ archive: e, baseUrl: i })
311
338
  ];
312
339
  try {
313
- const a = await r.reduce(async (n, t) => await t(await n), Promise.resolve(ce));
340
+ const a = await n.reduce(async (t, r) => await r(await t), Promise.resolve(de));
314
341
  return y.log("Generated manifest", a), a;
315
342
  } catch (a) {
316
343
  throw y.error(a), a;
317
344
  }
318
- }, g = (e) => e.substring(e.lastIndexOf("/") + 1) || e, he = async (e, i) => {
319
- const r = `
345
+ }, g = (e) => e.substring(e.lastIndexOf("/") + 1) || e, ge = async (e, i) => {
346
+ const n = `
320
347
  <?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
321
348
  <metadata>
322
349
  <meta property="rendition:layout">${i != null && i.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
323
350
  ${i != null && i.useRenditionFlow ? '<meta property="rendition:flow">scrolled-continuous</meta>' : ""}
324
351
  </metadata>
325
352
  <manifest>
326
- ${e.map((t) => `<item id="${g(t)}" href="${t}" media-type="${P(t)}"/>`).join(`
353
+ ${e.map((r) => `<item id="${g(r)}" href="${r}" media-type="${z(r)}"/>`).join(`
327
354
  `)}
328
355
  </manifest>
329
356
  <spine>
330
- ${e.map((t) => `<itemref idref="${g(t)}" />`).join(`
357
+ ${e.map((r) => `<itemref idref="${g(r)}" />`).join(`
331
358
  `)}
332
359
  </spine>
333
360
  </package>
334
- `, a = e.map((t) => ({
361
+ `, a = e.map((r) => ({
335
362
  dir: !1,
336
- basename: g(t),
337
- encodingFormat: P(t),
338
- uri: t,
363
+ basename: g(r),
364
+ encodingFormat: z(r),
365
+ uri: r,
339
366
  size: 100 / e.length,
340
367
  base64: async () => "",
341
368
  blob: async () => new Blob(),
@@ -348,20 +375,20 @@ const y = {
348
375
  basename: "content.opf",
349
376
  uri: "content.opf",
350
377
  size: 0,
351
- base64: async () => r,
378
+ base64: async () => n,
352
379
  blob: async () => new Blob(),
353
- string: async () => r
380
+ string: async () => n
354
381
  }, ...a]
355
382
  };
356
- }, de = async (e) => new Promise((i) => {
357
- const r = new FileReader();
358
- r.readAsDataURL(e), r.onloadend = function() {
359
- const a = r.result;
383
+ }, le = async (e) => new Promise((i) => {
384
+ const n = new FileReader();
385
+ n.readAsDataURL(e), n.onloadend = function() {
386
+ const a = n.result;
360
387
  i(a);
361
388
  };
362
- }), ge = async (e, {
389
+ }), ye = async (e, {
363
390
  mimeType: i,
364
- direction: r
391
+ direction: n
365
392
  } = { mimeType: "text/plain" }) => {
366
393
  const a = `
367
394
  <?xml version="1.0" encoding="UTF-8"?>
@@ -374,7 +401,7 @@ const y = {
374
401
  <manifest>
375
402
  <item id="p01" href="p01.txt" media-type="text/plain"/>
376
403
  </manifest>
377
- <spine page-progression-direction="${r ?? "ltr"}">
404
+ <spine page-progression-direction="${n ?? "ltr"}">
378
405
  <itemref idref="p01" />
379
406
  </spine>
380
407
  </package>
@@ -397,66 +424,59 @@ const y = {
397
424
  uri: "p01.txt",
398
425
  blob: async () => typeof e == "string" ? new Blob([e]) : e,
399
426
  string: async () => typeof e == "string" ? e : e.text(),
400
- base64: async () => typeof e == "string" ? btoa(e) : de(e),
427
+ base64: async () => typeof e == "string" ? btoa(e) : le(e),
401
428
  size: typeof e == "string" ? e.length : e.size,
402
429
  encodingFormat: i
403
430
  }
404
431
  ]
405
432
  };
406
- }, R = (e, i) => {
407
- var n;
408
- const r = e.split(/(\d+)/), a = i.split(/(\d+)/);
409
- for (let t = 0, o = r.length; t < o; t++)
410
- if (r[t] !== a[t])
411
- return (n = r[t]) != null && n.match(/\d/) ? +(r[t] || "") - +(a[t] || "") : (r[t] || "").localeCompare(a[t] || "");
412
- return 1;
413
- }, ye = async (e, { orderByAlpha: i, name: r } = {}) => {
433
+ }, be = async (e, { orderByAlpha: i, name: n } = {}) => {
414
434
  let a = Object.values(e.files);
415
- i && (a = a.sort((t, o) => R(t.name, o.name)));
416
- const n = {
417
- filename: r || "",
418
- files: a.map((t) => ({
419
- dir: t.dir,
420
- basename: g(t.name),
421
- uri: t.name,
422
- blob: () => t.async("blob"),
423
- string: () => t.async("string"),
424
- base64: () => t.async("base64"),
425
- ...t.internalStream && {
426
- stream: t.internalStream
435
+ i && (a = a.sort((r, o) => L(r.name, o.name)));
436
+ const t = {
437
+ filename: n || "",
438
+ files: a.map((r) => ({
439
+ dir: r.dir,
440
+ basename: g(r.name),
441
+ uri: r.name,
442
+ blob: () => r.async("blob"),
443
+ string: () => r.async("string"),
444
+ base64: () => r.async("base64"),
445
+ ...r.internalStream && {
446
+ stream: r.internalStream
427
447
  },
428
- size: t._data.uncompressedSize
448
+ size: r._data.uncompressedSize
429
449
  }))
430
450
  };
431
- return y.log("Generated archive", n), n;
432
- }, be = async (e, { orderByAlpha: i, name: r } = {}) => {
451
+ return y.log("Generated archive", t), t;
452
+ }, we = async (e, { orderByAlpha: i, name: n } = {}) => {
433
453
  let a = e;
434
- return i && (a = a.sort((n, t) => R(n.name, t.name))), {
435
- filename: r || "",
436
- files: a.map((n) => ({
437
- dir: n.isDir,
438
- basename: g(n.name),
439
- uri: n.name,
440
- blob: async () => new Blob([await n.data()]),
454
+ return i && (a = a.sort((t, r) => L(t.name, r.name))), {
455
+ filename: n || "",
456
+ files: a.map((t) => ({
457
+ dir: t.isDir,
458
+ basename: g(t.name),
459
+ uri: t.name,
460
+ blob: async () => new Blob([await t.data()]),
441
461
  string: async () => {
442
- const t = await n.data();
443
- return String.fromCharCode.apply(null, Array.from(new Uint16Array(t)));
462
+ const r = await t.data();
463
+ return String.fromCharCode.apply(null, Array.from(new Uint16Array(r)));
444
464
  },
445
465
  base64: async () => "",
446
- size: n.size
466
+ size: t.size
447
467
  }))
448
468
  };
449
- }, we = ({ enableReport: e } = {}) => {
469
+ }, ve = ({ enableReport: e } = {}) => {
450
470
  y.enable(!!e);
451
471
  };
452
472
  export {
453
- we as configure,
454
- be as createArchiveFromArrayBufferList,
455
- ye as createArchiveFromJszip,
456
- ge as createArchiveFromText,
457
- he as createArchiveFromUrls,
458
- ue as generateManifestFromArchive,
459
- fe as generateResourceFromArchive,
460
- v as getArchiveOpfInfo
473
+ ve as configure,
474
+ we as createArchiveFromArrayBufferList,
475
+ be as createArchiveFromJszip,
476
+ ye as createArchiveFromText,
477
+ ge as createArchiveFromUrls,
478
+ he as generateManifestFromArchive,
479
+ ue as generateResourceFromArchive,
480
+ $ as getArchiveOpfInfo
461
481
  };
462
482
  //# sourceMappingURL=prose-streamer.js.map