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