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