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