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