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