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