@prose-reader/streamer 1.13.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.
- package/dist/archives/createArchiveFromJszip.d.ts +1 -1
- package/dist/archives/types.d.ts +1 -1
- package/dist/generators/manifest/hooks/default.d.ts +1 -1
- package/dist/generators/manifest/hooks/navigationFallback.d.ts +12 -0
- package/dist/parsers/kobo.d.ts +1 -1
- package/dist/prose-streamer.js +209 -189
- package/dist/prose-streamer.js.map +1 -1
- package/dist/prose-streamer.umd.cjs +6 -6
- package/dist/prose-streamer.umd.cjs.map +1 -1
- package/package.json +5 -4
package/dist/prose-streamer.js
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
1
|
import h from "xmldoc";
|
|
2
|
-
import { urlJoin as
|
|
3
|
-
const
|
|
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
|
|
11
|
-
a.title = (
|
|
12
|
-
let
|
|
13
|
-
|
|
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) =>
|
|
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:
|
|
21
|
-
var
|
|
20
|
+
}, J = (e, { opfBasePath: i, baseUrl: n }) => {
|
|
21
|
+
var r, o;
|
|
22
22
|
const a = [];
|
|
23
|
-
let
|
|
24
|
-
return e.descendantWithPath("body.nav.ol") ?
|
|
25
|
-
}, K = async (e, i, { opfBasePath:
|
|
26
|
-
var
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
const o = Object.values(i.files).find((s) => s.uri.endsWith(
|
|
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:
|
|
32
|
+
return J(s, { opfBasePath: n, baseUrl: a });
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
},
|
|
35
|
+
}, X = (e, { opfBasePath: i, baseUrl: n, prefix: a }) => {
|
|
36
36
|
var s, d;
|
|
37
|
-
const
|
|
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:
|
|
40
|
-
href:
|
|
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 && (
|
|
44
|
-
}, Y = (e, { opfBasePath: i, baseUrl:
|
|
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 = [],
|
|
47
|
-
let
|
|
48
|
-
return
|
|
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:
|
|
52
|
+
baseUrl: n,
|
|
53
53
|
archive: a
|
|
54
54
|
}) => {
|
|
55
55
|
var o;
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
58
|
-
const s = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((d) => d.attr.id ===
|
|
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:
|
|
63
|
+
return Y(m, { opfBasePath: i, baseUrl: n });
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
}, Z = async (e, i, { baseUrl:
|
|
68
|
-
const { basePath: a } =
|
|
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:
|
|
72
|
+
baseUrl: n
|
|
73
73
|
});
|
|
74
|
-
return
|
|
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 (
|
|
81
|
-
var a,
|
|
82
|
-
if (
|
|
83
|
-
const o = (a = new h.XmlDocument(await
|
|
84
|
-
((
|
|
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
|
|
111
|
-
b && (e.duration <= i ? console.log("[prose-reader-streamer] [metric] ", `${e.name} took ${
|
|
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,
|
|
117
|
-
const
|
|
118
|
-
if (
|
|
119
|
-
return
|
|
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 -
|
|
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 -
|
|
124
|
+
return y.metric({ name: e, duration: o - t }, i), r;
|
|
125
125
|
}
|
|
126
|
-
},
|
|
127
|
-
const
|
|
126
|
+
}, $ = (e) => {
|
|
127
|
+
const n = Object.values(e.files).filter((a) => !a.dir).find((a) => a.uri.endsWith(".opf"));
|
|
128
128
|
return {
|
|
129
|
-
data:
|
|
130
|
-
basePath: (
|
|
129
|
+
data: n,
|
|
130
|
+
basePath: (n == null ? void 0 : n.uri.substring(0, n.uri.lastIndexOf("/"))) || ""
|
|
131
131
|
};
|
|
132
|
-
},
|
|
133
|
-
const { data: i, basePath:
|
|
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
|
|
137
|
-
return e.files.filter((m) => d.find((f) =>
|
|
138
|
-
},
|
|
139
|
-
var
|
|
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 ((
|
|
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 (
|
|
147
|
-
var
|
|
148
|
-
const { data: a, basePath:
|
|
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
|
|
150
|
+
return n;
|
|
151
151
|
const o = await a.string();
|
|
152
|
-
y.log(o,
|
|
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"),
|
|
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:
|
|
160
|
-
renditionFlow:
|
|
161
|
-
renditionSpread:
|
|
159
|
+
renditionLayout: k || r.renditionLayout || "reflowable",
|
|
160
|
+
renditionFlow: B || "auto",
|
|
161
|
+
renditionSpread: M,
|
|
162
162
|
title: H,
|
|
163
|
-
readingDirection:
|
|
163
|
+
readingDirection: U || "ltr",
|
|
164
164
|
spineItems: (f == null ? void 0 : f.childrenNamed("itemref").map((l) => {
|
|
165
|
-
var
|
|
166
|
-
const c = m == null ? void 0 : m.childrenNamed("item").find((u) => u.attr.id === (l == null ? void 0 : l.attr.idref)),
|
|
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: (
|
|
170
|
-
renditionLayout:
|
|
171
|
-
...
|
|
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:
|
|
176
|
-
pageSpreadRight:
|
|
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:
|
|
181
|
-
guide:
|
|
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
|
-
},
|
|
188
|
-
const
|
|
189
|
-
if (!
|
|
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
|
|
191
|
+
const t = await n.blob();
|
|
192
192
|
return {
|
|
193
|
-
body:
|
|
193
|
+
body: t,
|
|
194
194
|
params: {
|
|
195
195
|
headers: {
|
|
196
|
-
...
|
|
197
|
-
"Content-Type":
|
|
196
|
+
...t.type && {
|
|
197
|
+
"Content-Type": t.type
|
|
198
198
|
},
|
|
199
|
-
...
|
|
200
|
-
"Content-Type":
|
|
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
|
|
210
|
-
const a = await ((
|
|
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: (
|
|
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
|
-
},
|
|
232
|
-
var
|
|
233
|
-
const
|
|
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
|
-
|
|
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:
|
|
244
|
-
id: `${
|
|
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 /
|
|
244
|
+
progressionWeight: 1 / n.length,
|
|
248
245
|
pageSpreadLeft: void 0,
|
|
249
246
|
pageSpreadRight: void 0,
|
|
250
247
|
mediaType: t.encodingFormat
|
|
251
248
|
})),
|
|
252
|
-
items:
|
|
253
|
-
id: `${
|
|
249
|
+
items: n.map((t, r) => ({
|
|
250
|
+
id: `${r}.${t.basename}`,
|
|
254
251
|
href: `${i}${t.uri}`
|
|
255
252
|
}))
|
|
256
253
|
};
|
|
257
|
-
},
|
|
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
|
|
262
|
-
const
|
|
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
|
-
...
|
|
265
|
-
spineItems:
|
|
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
|
|
270
|
-
const i = (
|
|
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,
|
|
269
|
+
}, oe = (e) => e.reduce(async (i, n) => {
|
|
273
270
|
if (!await i || !G({
|
|
274
|
-
mimeType:
|
|
275
|
-
uri:
|
|
271
|
+
mimeType: n.encodingFormat,
|
|
272
|
+
uri: n.uri
|
|
276
273
|
}))
|
|
277
274
|
return !1;
|
|
278
|
-
const
|
|
279
|
-
return
|
|
280
|
-
}, Promise.resolve(!0)), se = ({ archive: e, baseUrl: i }) => async (
|
|
281
|
-
if (
|
|
282
|
-
const
|
|
283
|
-
if (await oe(
|
|
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
|
-
...
|
|
286
|
-
spineItems:
|
|
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
|
|
294
|
-
},
|
|
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
|
-
},
|
|
306
|
-
const
|
|
307
|
-
|
|
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
|
-
|
|
336
|
+
ae({ archive: e, baseUrl: i }),
|
|
337
|
+
ce({ archive: e, baseUrl: i })
|
|
311
338
|
];
|
|
312
339
|
try {
|
|
313
|
-
const a = await
|
|
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,
|
|
319
|
-
const
|
|
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((
|
|
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((
|
|
357
|
+
${e.map((r) => `<itemref idref="${g(r)}" />`).join(`
|
|
331
358
|
`)}
|
|
332
359
|
</spine>
|
|
333
360
|
</package>
|
|
334
|
-
`, a = e.map((
|
|
361
|
+
`, a = e.map((r) => ({
|
|
335
362
|
dir: !1,
|
|
336
|
-
basename: g(
|
|
337
|
-
encodingFormat:
|
|
338
|
-
uri:
|
|
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 () =>
|
|
378
|
+
base64: async () => n,
|
|
352
379
|
blob: async () => new Blob(),
|
|
353
|
-
string: async () =>
|
|
380
|
+
string: async () => n
|
|
354
381
|
}, ...a]
|
|
355
382
|
};
|
|
356
|
-
},
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
const a =
|
|
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
|
-
}),
|
|
389
|
+
}), ye = async (e, {
|
|
363
390
|
mimeType: i,
|
|
364
|
-
direction:
|
|
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="${
|
|
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) :
|
|
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
|
-
},
|
|
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((
|
|
416
|
-
const
|
|
417
|
-
filename:
|
|
418
|
-
files: a.map((
|
|
419
|
-
dir:
|
|
420
|
-
basename: g(
|
|
421
|
-
uri:
|
|
422
|
-
blob: () =>
|
|
423
|
-
string: () =>
|
|
424
|
-
base64: () =>
|
|
425
|
-
...
|
|
426
|
-
stream:
|
|
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:
|
|
448
|
+
size: r._data.uncompressedSize
|
|
429
449
|
}))
|
|
430
450
|
};
|
|
431
|
-
return y.log("Generated archive",
|
|
432
|
-
},
|
|
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((
|
|
435
|
-
filename:
|
|
436
|
-
files: a.map((
|
|
437
|
-
dir:
|
|
438
|
-
basename: g(
|
|
439
|
-
uri:
|
|
440
|
-
blob: async () => new Blob([await
|
|
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
|
|
443
|
-
return String.fromCharCode.apply(null, Array.from(new Uint16Array(
|
|
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:
|
|
466
|
+
size: t.size
|
|
447
467
|
}))
|
|
448
468
|
};
|
|
449
|
-
},
|
|
469
|
+
}, ve = ({ enableReport: e } = {}) => {
|
|
450
470
|
y.enable(!!e);
|
|
451
471
|
};
|
|
452
472
|
export {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
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
|