@prose-reader/streamer 1.62.0 → 1.64.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/createArchiveFromLibArchive.d.ts +14 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +187 -171
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +5 -5
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { urlJoin as v, PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME as J, isXmlBasedMimeType as q, detectMimeTypeFromName as
|
|
1
|
+
import { urlJoin as v, PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME as J, isXmlBasedMimeType as q, detectMimeTypeFromName as R } from "@prose-reader/shared";
|
|
2
2
|
import g, { XmlDocument as Y } from "xmldoc";
|
|
3
3
|
let b = !1;
|
|
4
|
-
const
|
|
4
|
+
const u = {
|
|
5
5
|
enable: (e) => {
|
|
6
6
|
b = e;
|
|
7
7
|
},
|
|
@@ -34,31 +34,31 @@ const h = {
|
|
|
34
34
|
));
|
|
35
35
|
},
|
|
36
36
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
-
measurePerformance: (e, r = 10, i) => (...
|
|
38
|
-
const
|
|
37
|
+
measurePerformance: (e, r = 10, i) => (...n) => {
|
|
38
|
+
const t = performance.now(), a = i(...n);
|
|
39
39
|
if (a && a.then)
|
|
40
40
|
return a.then((s) => {
|
|
41
41
|
const l = performance.now();
|
|
42
|
-
return
|
|
42
|
+
return u.metric({ name: e, duration: l - t }, r), s;
|
|
43
43
|
});
|
|
44
44
|
const o = performance.now();
|
|
45
|
-
return
|
|
45
|
+
return u.metric({ name: e, duration: o - t }, r), a;
|
|
46
46
|
}
|
|
47
47
|
}, K = (e) => {
|
|
48
48
|
var i;
|
|
49
|
-
const r = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((
|
|
49
|
+
const r = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((n) => n.attr.name === "calibre:cover");
|
|
50
50
|
return !!(r && r.attr.name === "calibre:cover");
|
|
51
51
|
}, Q = (e) => {
|
|
52
|
-
var r, i,
|
|
53
|
-
return (
|
|
54
|
-
(
|
|
52
|
+
var r, i, n;
|
|
53
|
+
return (n = (i = (r = e.descendantWithPath("body")) == null ? void 0 : r.descendantWithPath("div")) == null ? void 0 : i.childrenNamed("svg")) == null ? void 0 : n.find(
|
|
54
|
+
(t) => t.attr.width === "100%" && t.attr.preserveAspectRatio === "none"
|
|
55
55
|
);
|
|
56
56
|
}, Z = ({ archive: e, resourcePath: r }) => async (i) => {
|
|
57
|
-
const
|
|
58
|
-
(
|
|
57
|
+
const n = Object.values(e.files).find(
|
|
58
|
+
(t) => t.uri === r
|
|
59
59
|
);
|
|
60
|
-
if (
|
|
61
|
-
const
|
|
60
|
+
if (n != null && n.basename.endsWith(".xhtml")) {
|
|
61
|
+
const t = i.body ?? await n.string(), a = new Y(t);
|
|
62
62
|
if (K(a)) {
|
|
63
63
|
const o = Q(a);
|
|
64
64
|
return o && delete o.attr.preserveAspectRatio, {
|
|
@@ -69,11 +69,11 @@ const h = {
|
|
|
69
69
|
}
|
|
70
70
|
return i;
|
|
71
71
|
}, E = ({ archive: e, resourcePath: r }) => async (i) => Z({ archive: e, resourcePath: r })(i), ee = ({ archive: e, resourcePath: r }) => async (i) => {
|
|
72
|
-
const
|
|
73
|
-
(
|
|
72
|
+
const n = Object.values(e.files).find(
|
|
73
|
+
(t) => t.uri === r
|
|
74
74
|
);
|
|
75
|
-
if (
|
|
76
|
-
const a = (i.body ?? await
|
|
75
|
+
if (n != null && n.basename.endsWith(".css")) {
|
|
76
|
+
const a = (i.body ?? await n.string()).replaceAll(
|
|
77
77
|
"-webkit-writing-mode",
|
|
78
78
|
"writing-mode"
|
|
79
79
|
);
|
|
@@ -84,141 +84,141 @@ const h = {
|
|
|
84
84
|
}
|
|
85
85
|
return i;
|
|
86
86
|
}, F = (e) => {
|
|
87
|
-
const i = Object.values(e.files).filter((
|
|
87
|
+
const i = Object.values(e.files).filter((n) => !n.dir).find((n) => n.uri.endsWith(".opf"));
|
|
88
88
|
return {
|
|
89
89
|
data: i,
|
|
90
90
|
basePath: (i == null ? void 0 : i.uri.substring(0, i.uri.lastIndexOf("/"))) || ""
|
|
91
91
|
};
|
|
92
92
|
}, O = (e, { opfBasePath: r, baseUrl: i }) => {
|
|
93
|
-
const
|
|
93
|
+
const n = {
|
|
94
94
|
contents: [],
|
|
95
95
|
path: "",
|
|
96
96
|
href: "",
|
|
97
97
|
title: ""
|
|
98
98
|
};
|
|
99
|
-
let
|
|
100
|
-
|
|
101
|
-
let a =
|
|
102
|
-
a !== "a" && (
|
|
99
|
+
let t = e.childNamed("span") || e.childNamed("a");
|
|
100
|
+
n.title = (t == null ? void 0 : t.attr.title) || (t == null ? void 0 : t.val.trim()) || n.title;
|
|
101
|
+
let a = t == null ? void 0 : t.name;
|
|
102
|
+
a !== "a" && (t = e.descendantWithPath(`${a}.a`), t && (a = t.name.toLowerCase())), a === "a" && (t != null && t.attr.href) && (n.path = v(r, t.attr.href), n.href = v(i, r, t.attr.href));
|
|
103
103
|
const o = e.childNamed("ol");
|
|
104
104
|
if (o) {
|
|
105
105
|
const s = o.childrenNamed("li");
|
|
106
|
-
s && s.length > 0 && (
|
|
106
|
+
s && s.length > 0 && (n.contents = s.map(
|
|
107
107
|
(l) => O(l, { opfBasePath: r, baseUrl: i })
|
|
108
108
|
));
|
|
109
109
|
}
|
|
110
|
-
return
|
|
110
|
+
return n;
|
|
111
111
|
}, te = (e, { opfBasePath: r, baseUrl: i }) => {
|
|
112
112
|
var a, o;
|
|
113
|
-
const
|
|
114
|
-
let
|
|
115
|
-
return e.descendantWithPath("body.nav.ol") ?
|
|
116
|
-
(s) =>
|
|
117
|
-
),
|
|
118
|
-
}, ne = async (e, r, { opfBasePath: i, baseUrl:
|
|
113
|
+
const n = [];
|
|
114
|
+
let t;
|
|
115
|
+
return e.descendantWithPath("body.nav.ol") ? t = (a = e.descendantWithPath("body.nav.ol")) == null ? void 0 : a.children : e.descendantWithPath("body.section.nav.ol") && (t = (o = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : o.children), t && t.length > 0 && t.filter((s) => s.name === "li").forEach(
|
|
116
|
+
(s) => n.push(O(s, { opfBasePath: r, baseUrl: i }))
|
|
117
|
+
), n;
|
|
118
|
+
}, ne = async (e, r, { opfBasePath: i, baseUrl: n }) => {
|
|
119
119
|
var a;
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
120
|
+
const t = (a = e.childNamed("manifest")) == null ? void 0 : a.childrenNamed("item").find((o) => o.attr.properties === "nav");
|
|
121
|
+
if (t) {
|
|
122
122
|
const o = Object.values(r.files).find(
|
|
123
|
-
(s) => s.uri.endsWith(
|
|
123
|
+
(s) => s.uri.endsWith(t.attr.href || "")
|
|
124
124
|
);
|
|
125
125
|
if (o) {
|
|
126
126
|
const s = new g.XmlDocument(await o.string());
|
|
127
|
-
return te(s, { opfBasePath: i, baseUrl:
|
|
127
|
+
return te(s, { opfBasePath: i, baseUrl: n });
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
},
|
|
130
|
+
}, z = (e, {
|
|
131
131
|
opfBasePath: r,
|
|
132
132
|
baseUrl: i,
|
|
133
|
-
prefix:
|
|
133
|
+
prefix: n
|
|
134
134
|
}) => {
|
|
135
135
|
var s, l;
|
|
136
|
-
const
|
|
137
|
-
title: ((l = e == null ? void 0 : e.descendantWithPath(`${
|
|
138
|
-
path: v(r,
|
|
139
|
-
href: v(i, r,
|
|
136
|
+
const t = ((s = e == null ? void 0 : e.childNamed(`${n}content`)) == null ? void 0 : s.attr.src) || "", a = {
|
|
137
|
+
title: ((l = e == null ? void 0 : e.descendantWithPath(`${n}navLabel.${n}text`)) == null ? void 0 : l.val) || "",
|
|
138
|
+
path: v(r, t),
|
|
139
|
+
href: v(i, r, t),
|
|
140
140
|
contents: []
|
|
141
|
-
}, o = e.childrenNamed(`${
|
|
141
|
+
}, o = e.childrenNamed(`${n}navPoint`);
|
|
142
142
|
return o && o.length > 0 && (a.contents = o.map(
|
|
143
|
-
(
|
|
143
|
+
(f) => z(f, { opfBasePath: r, baseUrl: i, prefix: n })
|
|
144
144
|
)), a;
|
|
145
145
|
}, re = (e, { opfBasePath: r, baseUrl: i }) => {
|
|
146
146
|
var o;
|
|
147
|
-
const
|
|
147
|
+
const n = [], t = e.name;
|
|
148
148
|
let a = "";
|
|
149
|
-
return
|
|
150
|
-
(s) =>
|
|
151
|
-
),
|
|
149
|
+
return t.indexOf(":") !== -1 && (a = t.split(":")[0] + ":"), (o = e.childNamed(`${a}navMap`)) == null || o.childrenNamed(`${a}navPoint`).forEach(
|
|
150
|
+
(s) => n.push(z(s, { opfBasePath: r, baseUrl: i, prefix: a }))
|
|
151
|
+
), n;
|
|
152
152
|
}, ae = async ({
|
|
153
153
|
opfData: e,
|
|
154
154
|
opfBasePath: r,
|
|
155
155
|
baseUrl: i,
|
|
156
|
-
archive:
|
|
156
|
+
archive: n
|
|
157
157
|
}) => {
|
|
158
158
|
var o;
|
|
159
|
-
const
|
|
159
|
+
const t = e.childNamed("spine"), a = t && t.attr.toc;
|
|
160
160
|
if (a) {
|
|
161
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 = `${r}${r === "" ? "" : "/"}${s.attr.href}`,
|
|
163
|
+
const l = `${r}${r === "" ? "" : "/"}${s.attr.href}`, f = Object.values(n.files).find(
|
|
164
164
|
(m) => m.uri.endsWith(l)
|
|
165
165
|
);
|
|
166
|
-
if (
|
|
167
|
-
const m = new g.XmlDocument(await
|
|
166
|
+
if (f) {
|
|
167
|
+
const m = new g.XmlDocument(await f.string());
|
|
168
168
|
return re(m, { opfBasePath: r, baseUrl: i });
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
}, ie = async (e, r, { baseUrl: i }) => {
|
|
173
|
-
const { basePath:
|
|
173
|
+
const { basePath: n } = F(r) || {}, t = await ae({
|
|
174
174
|
opfData: e,
|
|
175
|
-
opfBasePath:
|
|
175
|
+
opfBasePath: n,
|
|
176
176
|
archive: r,
|
|
177
177
|
baseUrl: i
|
|
178
178
|
});
|
|
179
|
-
return
|
|
179
|
+
return t || await ne(e, r, { opfBasePath: n, baseUrl: i });
|
|
180
180
|
}, oe = async (e) => {
|
|
181
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
|
|
186
|
+
var n, t;
|
|
187
187
|
if (i.uri.endsWith("com.kobobooks.display-options.xml")) {
|
|
188
|
-
const o = (
|
|
189
|
-
((
|
|
188
|
+
const o = (n = new g.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : n.childNamed("option");
|
|
189
|
+
((t = o == null ? void 0 : o.attr) == null ? void 0 : t.name) === "fixed-layout" && o.val === "true" && (r.renditionLayout = "pre-paginated");
|
|
190
190
|
}
|
|
191
191
|
})
|
|
192
192
|
), r;
|
|
193
|
-
},
|
|
193
|
+
}, j = async ({
|
|
194
194
|
archive: e
|
|
195
195
|
}) => {
|
|
196
|
-
const { data: r, basePath: i } = F(e) || {},
|
|
197
|
-
if (!
|
|
198
|
-
const
|
|
199
|
-
return e.files.filter((m) => l.find((
|
|
196
|
+
const { data: r, basePath: i } = F(e) || {}, n = await (r == null ? void 0 : r.string());
|
|
197
|
+
if (!n) return [];
|
|
198
|
+
const t = new g.XmlDocument(n), a = t.childNamed("manifest"), o = t.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
|
+
return e.files.filter((m) => l.find((p) => i ? `${i}/${p.attr.href}` === m.uri : `${p.attr.href}` === m.uri));
|
|
200
200
|
}, X = (e) => {
|
|
201
201
|
var i;
|
|
202
202
|
const r = e.childNamed("manifest");
|
|
203
|
-
return ((i = r == null ? void 0 : r.childrenNamed("item")) == null ? void 0 : i.map((
|
|
204
|
-
href:
|
|
205
|
-
id:
|
|
206
|
-
mediaType:
|
|
203
|
+
return ((i = r == null ? void 0 : r.childrenNamed("item")) == null ? void 0 : i.map((n) => ({
|
|
204
|
+
href: n.attr.href || "",
|
|
205
|
+
id: n.attr.id || "",
|
|
206
|
+
mediaType: n.attr["media-type"]
|
|
207
207
|
}))) || [];
|
|
208
208
|
}, se = ({ archive: e, baseUrl: r }) => async (i) => {
|
|
209
209
|
var D;
|
|
210
|
-
const { data:
|
|
211
|
-
if (!
|
|
210
|
+
const { data: n, basePath: t } = F(e) || {}, a = await oe(e);
|
|
211
|
+
if (!n)
|
|
212
212
|
return i;
|
|
213
|
-
const o = await
|
|
214
|
-
|
|
215
|
-
const s = new g.XmlDocument(o), l = await ie(s, e, { baseUrl: r }) || [],
|
|
213
|
+
const o = await n.string();
|
|
214
|
+
u.log(o, a);
|
|
215
|
+
const s = new g.XmlDocument(o), l = await ie(s, e, { baseUrl: r }) || [], f = s.childNamed("metadata"), m = s.childNamed("manifest"), p = s.childNamed("spine"), x = s.childNamed("guide"), w = f == null ? void 0 : f.childNamed("dc:title"), $ = (f == null ? void 0 : f.childrenNamed("meta")) || [], N = $.find(
|
|
216
216
|
(d) => d.attr.property === "rendition:layout"
|
|
217
217
|
), T = $.find(
|
|
218
218
|
(d) => d.attr.property === "rendition:flow"
|
|
219
|
-
),
|
|
219
|
+
), A = $.find(
|
|
220
220
|
(d) => d.attr.property === "rendition:spread"
|
|
221
|
-
), k = N == null ? void 0 : N.val, B = T == null ? void 0 : T.val, M =
|
|
221
|
+
), k = 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 = p == null ? void 0 : p.attr["page-progression-direction"], U = (await j({ archive: e })).reduce(
|
|
222
222
|
(d, c) => c.size + d,
|
|
223
223
|
0
|
|
224
224
|
);
|
|
@@ -232,21 +232,21 @@ const h = {
|
|
|
232
232
|
renditionSpread: M,
|
|
233
233
|
title: _,
|
|
234
234
|
readingDirection: H || "ltr",
|
|
235
|
-
spineItems: (
|
|
236
|
-
var W, P,
|
|
237
|
-
const c = m == null ? void 0 : m.childrenNamed("item").find((
|
|
235
|
+
spineItems: (p == null ? void 0 : p.childrenNamed("itemref").map((d) => {
|
|
236
|
+
var W, P, L;
|
|
237
|
+
const c = m == null ? void 0 : m.childrenNamed("item").find((h) => h.attr.id === (d == null ? void 0 : d.attr.idref)), V = (c == null ? void 0 : c.attr.href) || "", I = ((W = d == null ? void 0 : d.attr.properties) == null ? void 0 : W.split(" ")) || [], G = ((P = e.files.find((h) => h.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: (
|
|
240
|
+
href: (L = c == null ? void 0 : c.attr.href) != null && L.startsWith("https://") ? c == null ? void 0 : c.attr.href : t ? `${S}${t}/${c == null ? void 0 : c.attr.href}` : `${S}${c == null ? void 0 : c.attr.href}`,
|
|
241
241
|
renditionLayout: k || "reflowable",
|
|
242
|
-
...
|
|
243
|
-
(
|
|
242
|
+
...I.find(
|
|
243
|
+
(h) => h === "rendition:layout-reflowable"
|
|
244
244
|
) && {
|
|
245
245
|
renditionLayout: "reflowable"
|
|
246
246
|
},
|
|
247
247
|
progressionWeight: G / U,
|
|
248
|
-
pageSpreadLeft:
|
|
249
|
-
pageSpreadRight:
|
|
248
|
+
pageSpreadLeft: I.some((h) => h === "page-spread-left") || void 0,
|
|
249
|
+
pageSpreadRight: I.some((h) => h === "page-spread-right") || void 0,
|
|
250
250
|
// size: itemSize
|
|
251
251
|
mediaType: c == null ? void 0 : c.attr["media-type"]
|
|
252
252
|
};
|
|
@@ -259,10 +259,10 @@ const h = {
|
|
|
259
259
|
}))
|
|
260
260
|
};
|
|
261
261
|
}, ce = async (e, r) => {
|
|
262
|
-
var
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
265
|
-
const o = new g.XmlDocument(
|
|
262
|
+
var t, a;
|
|
263
|
+
const n = await ((t = F(e).data) == null ? void 0 : t.string());
|
|
264
|
+
if (n) {
|
|
265
|
+
const o = new g.XmlDocument(n);
|
|
266
266
|
return {
|
|
267
267
|
mediaType: (a = X(o).find((l) => r.endsWith(l.href))) == null ? void 0 : a.mediaType
|
|
268
268
|
};
|
|
@@ -282,22 +282,22 @@ const h = {
|
|
|
282
282
|
if (e.endsWith(".svg"))
|
|
283
283
|
return "image/svg+xml";
|
|
284
284
|
}, le = ({ archive: e, resourcePath: r }) => async (i) => {
|
|
285
|
-
const
|
|
285
|
+
const n = Object.values(e.files).find(
|
|
286
286
|
(a) => a.uri === r
|
|
287
287
|
);
|
|
288
|
-
if (!
|
|
289
|
-
const
|
|
288
|
+
if (!n) return i;
|
|
289
|
+
const t = await ce(e, r);
|
|
290
290
|
return {
|
|
291
291
|
...i,
|
|
292
292
|
params: {
|
|
293
293
|
...i.params,
|
|
294
294
|
status: 200,
|
|
295
295
|
headers: {
|
|
296
|
-
...(
|
|
297
|
-
"Content-Type":
|
|
296
|
+
...(n == null ? void 0 : n.encodingFormat) && {
|
|
297
|
+
"Content-Type": n.encodingFormat
|
|
298
298
|
},
|
|
299
|
-
...
|
|
300
|
-
"Content-Type":
|
|
299
|
+
...t.mediaType && {
|
|
300
|
+
"Content-Type": t.mediaType
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
}
|
|
@@ -308,23 +308,23 @@ const h = {
|
|
|
308
308
|
);
|
|
309
309
|
if (!i)
|
|
310
310
|
throw new Error("no file found");
|
|
311
|
-
const
|
|
311
|
+
const n = {
|
|
312
312
|
params: {
|
|
313
313
|
status: 200
|
|
314
314
|
}
|
|
315
|
-
},
|
|
315
|
+
}, t = [
|
|
316
316
|
le({ archive: e, resourcePath: r }),
|
|
317
317
|
ee({ archive: e, resourcePath: r }),
|
|
318
318
|
E({ archive: e, resourcePath: r })
|
|
319
319
|
];
|
|
320
320
|
try {
|
|
321
|
-
const a = await
|
|
322
|
-
return
|
|
321
|
+
const a = await t.reduce(async (o, s) => await s(await o), Promise.resolve(n));
|
|
322
|
+
return u.log("Generated resource", r, a), {
|
|
323
323
|
...a,
|
|
324
324
|
body: a.body || await i.blob()
|
|
325
325
|
};
|
|
326
326
|
} catch (a) {
|
|
327
|
-
throw
|
|
327
|
+
throw u.error(a), a;
|
|
328
328
|
}
|
|
329
329
|
}, $e = (e) => ({
|
|
330
330
|
body: `
|
|
@@ -345,57 +345,57 @@ const h = {
|
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
347
|
}), me = ({ archive: e, baseUrl: r }) => async () => {
|
|
348
|
-
var
|
|
349
|
-
const i = Object.values(e.files).filter((
|
|
348
|
+
var n;
|
|
349
|
+
const i = Object.values(e.files).filter((t) => !t.dir);
|
|
350
350
|
return {
|
|
351
351
|
filename: e.filename,
|
|
352
|
-
title: ((
|
|
352
|
+
title: ((n = e.files.find(({ dir: t }) => t)) == null ? void 0 : n.basename.replace(/\/$/, "")) || "",
|
|
353
353
|
renditionLayout: "pre-paginated",
|
|
354
354
|
renditionSpread: "auto",
|
|
355
355
|
readingDirection: "ltr",
|
|
356
|
-
spineItems: i.filter((
|
|
356
|
+
spineItems: i.filter((t) => !t.basename.endsWith(".db")).map((t, 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: `${a}.${
|
|
361
|
-
href: encodeURI(`${r}${
|
|
360
|
+
id: `${a}.${t.basename}`,
|
|
361
|
+
href: encodeURI(`${r}${t.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: t.encodingFormat
|
|
367
367
|
})),
|
|
368
|
-
items: i.map((
|
|
369
|
-
id: `${a}.${
|
|
370
|
-
href: `${r}${
|
|
368
|
+
items: i.map((t, a) => ({
|
|
369
|
+
id: `${a}.${t.basename}`,
|
|
370
|
+
href: `${r}${t.uri}`
|
|
371
371
|
}))
|
|
372
372
|
};
|
|
373
|
-
},
|
|
373
|
+
}, fe = ({ archive: e }) => async (r) => {
|
|
374
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
379
|
return r;
|
|
380
|
-
const
|
|
380
|
+
const n = {
|
|
381
381
|
...r,
|
|
382
382
|
spineItems: r.spineItems.filter(
|
|
383
383
|
(o) => !o.id.toLowerCase().endsWith("comicinfo.xml")
|
|
384
384
|
)
|
|
385
|
-
},
|
|
385
|
+
}, t = await i.string();
|
|
386
386
|
try {
|
|
387
|
-
const s = ((a = new g.XmlDocument(
|
|
387
|
+
const s = ((a = new g.XmlDocument(t).childNamed("Manga")) == null ? void 0 : a.val) || "unknown";
|
|
388
388
|
return {
|
|
389
|
-
...
|
|
389
|
+
...n,
|
|
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
|
+
`, t), console.error(o), n;
|
|
395
395
|
}
|
|
396
|
-
},
|
|
396
|
+
}, pe = (e) => {
|
|
397
397
|
var i;
|
|
398
|
-
const r = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((
|
|
398
|
+
const r = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((n) => n.attr.name === "viewport");
|
|
399
399
|
return !!(r && r.attr.name === "viewport");
|
|
400
400
|
}, ue = (e) => e.reduce(async (r, i) => {
|
|
401
401
|
if (!await r || !q({
|
|
@@ -403,12 +403,12 @@ const h = {
|
|
|
403
403
|
uri: i.uri
|
|
404
404
|
}))
|
|
405
405
|
return !1;
|
|
406
|
-
const
|
|
407
|
-
return
|
|
406
|
+
const t = await i.string();
|
|
407
|
+
return t ? pe(new g.XmlDocument(t)) : !1;
|
|
408
408
|
}, Promise.resolve(!0)), he = ({ archive: e }) => async (r) => {
|
|
409
|
-
if (r.renditionLayout === "reflowable" && r.spineItems.every((
|
|
410
|
-
const
|
|
411
|
-
if (await ue(
|
|
409
|
+
if (r.renditionLayout === "reflowable" && r.spineItems.every((n) => n.renditionLayout === "reflowable")) {
|
|
410
|
+
const n = await j({ archive: e });
|
|
411
|
+
if (await ue(n))
|
|
412
412
|
return {
|
|
413
413
|
...r,
|
|
414
414
|
spineItems: r.spineItems.map((a) => ({
|
|
@@ -420,24 +420,24 @@ const h = {
|
|
|
420
420
|
}
|
|
421
421
|
return r;
|
|
422
422
|
}, C = (e, r) => {
|
|
423
|
-
var
|
|
424
|
-
const i = e.split(/(\d+)/),
|
|
423
|
+
var t;
|
|
424
|
+
const i = e.split(/(\d+)/), n = r.split(/(\d+)/);
|
|
425
425
|
for (let a = 0, o = i.length; a < o; a++)
|
|
426
|
-
if (i[a] !==
|
|
427
|
-
return (
|
|
426
|
+
if (i[a] !== n[a])
|
|
427
|
+
return (t = i[a]) != null && t.match(/\d/) ? +(i[a] || "") - +(n[a] || "") : (i[a] || "").localeCompare(n[a] || "");
|
|
428
428
|
return 1;
|
|
429
429
|
}, ge = ({ archive: e, baseUrl: r }) => async (i) => {
|
|
430
430
|
if (i.nav) return i;
|
|
431
|
-
const
|
|
431
|
+
const n = [...e.files].sort(
|
|
432
432
|
(a, o) => C(a.uri, o.uri)
|
|
433
|
-
),
|
|
434
|
-
|
|
433
|
+
), t = Object.values(
|
|
434
|
+
n
|
|
435
435
|
).reduce(
|
|
436
436
|
(a, o) => {
|
|
437
437
|
const s = o.uri.split("/");
|
|
438
|
-
return !o.dir && s.length > 1 && s.forEach((
|
|
438
|
+
return !o.dir && s.length > 1 && s.forEach((f, m) => {
|
|
439
439
|
if (m === s.length - 1) return;
|
|
440
|
-
a.find(({ title: w }) => w ===
|
|
440
|
+
a.find(({ title: w }) => w === f) || a.push({
|
|
441
441
|
contents: [],
|
|
442
442
|
href: v(r, encodeURI(o.uri)).replace(/\/$/, ""),
|
|
443
443
|
path: o.uri.replace(/\/$/, ""),
|
|
@@ -447,10 +447,10 @@ const h = {
|
|
|
447
447
|
},
|
|
448
448
|
[]
|
|
449
449
|
);
|
|
450
|
-
return
|
|
450
|
+
return t.length === 0 ? i : {
|
|
451
451
|
...i,
|
|
452
452
|
nav: {
|
|
453
|
-
toc:
|
|
453
|
+
toc: t
|
|
454
454
|
}
|
|
455
455
|
};
|
|
456
456
|
}, ye = {
|
|
@@ -469,14 +469,14 @@ const h = {
|
|
|
469
469
|
me({ archive: e, baseUrl: r }),
|
|
470
470
|
se({ archive: e, baseUrl: r }),
|
|
471
471
|
he({ archive: e, baseUrl: r }),
|
|
472
|
-
|
|
472
|
+
fe({ archive: e, baseUrl: r }),
|
|
473
473
|
ge({ archive: e, baseUrl: r })
|
|
474
474
|
];
|
|
475
475
|
try {
|
|
476
|
-
const
|
|
477
|
-
return
|
|
478
|
-
} catch (
|
|
479
|
-
throw
|
|
476
|
+
const n = await i.reduce(async (t, a) => await a(await t), Promise.resolve(ye));
|
|
477
|
+
return u.log("Generated manifest", n), n;
|
|
478
|
+
} catch (n) {
|
|
479
|
+
throw u.error(n), n;
|
|
480
480
|
}
|
|
481
481
|
}, y = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Te = async (e, r) => {
|
|
482
482
|
const i = `
|
|
@@ -487,7 +487,7 @@ const h = {
|
|
|
487
487
|
</metadata>
|
|
488
488
|
<manifest>
|
|
489
489
|
${e.map(
|
|
490
|
-
(a) => `<item id="${y(a)}" href="${a}" media-type="${
|
|
490
|
+
(a) => `<item id="${y(a)}" href="${a}" media-type="${R(a)}"/>`
|
|
491
491
|
).join(`
|
|
492
492
|
`)}
|
|
493
493
|
</manifest>
|
|
@@ -496,10 +496,10 @@ const h = {
|
|
|
496
496
|
`)}
|
|
497
497
|
</spine>
|
|
498
498
|
</package>
|
|
499
|
-
`,
|
|
499
|
+
`, n = e.map((a) => ({
|
|
500
500
|
dir: !1,
|
|
501
501
|
basename: y(a),
|
|
502
|
-
encodingFormat:
|
|
502
|
+
encodingFormat: R(a),
|
|
503
503
|
uri: a,
|
|
504
504
|
size: 100 / e.length,
|
|
505
505
|
base64: async () => "",
|
|
@@ -516,20 +516,20 @@ const h = {
|
|
|
516
516
|
base64: async () => i,
|
|
517
517
|
blob: async () => new Blob(),
|
|
518
518
|
string: async () => i
|
|
519
|
-
}, ...
|
|
519
|
+
}, ...n],
|
|
520
520
|
close: () => Promise.resolve()
|
|
521
521
|
};
|
|
522
522
|
}, be = async (e) => new Promise((r) => {
|
|
523
523
|
const i = new FileReader();
|
|
524
524
|
i.readAsDataURL(e), i.onloadend = function() {
|
|
525
|
-
const
|
|
526
|
-
r(
|
|
525
|
+
const n = i.result;
|
|
526
|
+
r(n);
|
|
527
527
|
};
|
|
528
|
-
}),
|
|
528
|
+
}), Ae = async (e, {
|
|
529
529
|
mimeType: r,
|
|
530
530
|
direction: i
|
|
531
531
|
} = { mimeType: "text/plain" }) => {
|
|
532
|
-
const
|
|
532
|
+
const n = `
|
|
533
533
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
534
534
|
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="ja" prefix="rendition: http://www.idpf.org/vocab/rendition/#"
|
|
535
535
|
unique-identifier="ootuya-id">
|
|
@@ -552,9 +552,9 @@ const h = {
|
|
|
552
552
|
dir: !1,
|
|
553
553
|
basename: y("generated.opf"),
|
|
554
554
|
uri: "generated.opf",
|
|
555
|
-
blob: async () => new Blob([
|
|
556
|
-
string: async () =>
|
|
557
|
-
base64: async () => btoa(
|
|
555
|
+
blob: async () => new Blob([n]),
|
|
556
|
+
string: async () => n,
|
|
557
|
+
base64: async () => btoa(n),
|
|
558
558
|
size: 0
|
|
559
559
|
},
|
|
560
560
|
{
|
|
@@ -570,12 +570,12 @@ const h = {
|
|
|
570
570
|
],
|
|
571
571
|
close: () => Promise.resolve()
|
|
572
572
|
};
|
|
573
|
-
},
|
|
574
|
-
let
|
|
575
|
-
r && (
|
|
576
|
-
const
|
|
573
|
+
}, Ie = async (e, { orderByAlpha: r, name: i } = {}) => {
|
|
574
|
+
let n = Object.values(e.files);
|
|
575
|
+
r && (n = n.slice().sort((a, o) => C(a.name, o.name)));
|
|
576
|
+
const t = {
|
|
577
577
|
filename: i || "",
|
|
578
|
-
files:
|
|
578
|
+
files: n.map((a) => ({
|
|
579
579
|
dir: a.dir,
|
|
580
580
|
basename: y(a.name),
|
|
581
581
|
uri: a.name,
|
|
@@ -592,38 +592,54 @@ const h = {
|
|
|
592
592
|
})),
|
|
593
593
|
close: () => Promise.resolve()
|
|
594
594
|
};
|
|
595
|
-
return
|
|
596
|
-
}, Ce = async (e, {
|
|
597
|
-
|
|
598
|
-
|
|
595
|
+
return u.log("Generated archive", t), t;
|
|
596
|
+
}, Ce = async (e, { name: r } = {}) => {
|
|
597
|
+
const i = await e.getFilesArray(), n = {
|
|
598
|
+
close: () => e.close(),
|
|
599
|
+
filename: r ?? "",
|
|
600
|
+
files: i.map((t) => ({
|
|
601
|
+
dir: !1,
|
|
602
|
+
basename: t.file.name,
|
|
603
|
+
size: t.file.size,
|
|
604
|
+
uri: `${t.path}${t.file.name}`,
|
|
605
|
+
base64: async () => "",
|
|
606
|
+
blob: async () => await t.file.extract(),
|
|
607
|
+
string: async () => (await t.file.extract()).text()
|
|
608
|
+
}))
|
|
609
|
+
};
|
|
610
|
+
return u.log("Generated archive", n), n;
|
|
611
|
+
}, ke = async (e, { orderByAlpha: r, name: i } = {}) => {
|
|
612
|
+
let n = e;
|
|
613
|
+
return r && (n = n.slice().sort((t, a) => C(t.name, a.name))), {
|
|
599
614
|
filename: i || "",
|
|
600
|
-
files:
|
|
601
|
-
dir:
|
|
602
|
-
basename: y(
|
|
603
|
-
uri:
|
|
604
|
-
blob: async () => new Blob([await
|
|
615
|
+
files: n.map((t) => ({
|
|
616
|
+
dir: t.isDir,
|
|
617
|
+
basename: y(t.name),
|
|
618
|
+
uri: t.name,
|
|
619
|
+
blob: async () => new Blob([await t.data()]),
|
|
605
620
|
string: async () => {
|
|
606
|
-
const a = await
|
|
621
|
+
const a = await t.data();
|
|
607
622
|
return String.fromCharCode.apply(
|
|
608
623
|
null,
|
|
609
624
|
Array.from(new Uint16Array(a))
|
|
610
625
|
);
|
|
611
626
|
},
|
|
612
627
|
base64: async () => "",
|
|
613
|
-
size:
|
|
628
|
+
size: t.size
|
|
614
629
|
})),
|
|
615
630
|
close: () => Promise.resolve()
|
|
616
631
|
};
|
|
617
|
-
},
|
|
632
|
+
}, De = ({
|
|
618
633
|
enableReport: e
|
|
619
634
|
} = {}) => {
|
|
620
|
-
|
|
635
|
+
u.enable(!!e);
|
|
621
636
|
};
|
|
622
637
|
export {
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
638
|
+
De as configure,
|
|
639
|
+
ke as createArchiveFromArrayBufferList,
|
|
640
|
+
Ie as createArchiveFromJszip,
|
|
641
|
+
Ce as createArchiveFromLibArchive,
|
|
642
|
+
Ae as createArchiveFromText,
|
|
627
643
|
Te as createArchiveFromUrls,
|
|
628
644
|
Ne as generateManifestFromArchive,
|
|
629
645
|
Fe as generateResourceFromArchive,
|