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