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