@prose-reader/streamer 1.276.0 → 1.277.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/printTree.d.ts +1 -0
- package/dist/generators/manifest/hooks/toc.d.ts +10 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +749 -733
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +24 -20
- package/dist/index.umd.cjs.map +1 -1
- package/dist/report.d.ts +2 -7
- package/package.json +3 -3
- package/dist/generators/manifest/hooks/navigationFallback.d.ts +0 -12
- /package/dist/generators/manifest/hooks/{navigationFallback.test.d.ts → toc.test.d.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,279 +1,653 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Subject as
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
1
|
+
import { Report as se, detectMimeTypeFromName as j, isXmlBasedMimeType as ie, parseContentType as ae, urlJoin as I } from "@prose-reader/shared";
|
|
2
|
+
import { XmlDocument as y, XmlTextNode as ce, XmlElement as de } from "xmldoc";
|
|
3
|
+
import { Subject as C, mergeMap as O, EMPTY as B, pairwise as le, filter as R, startWith as pe, from as T, tap as P, catchError as W, switchMap as A, merge as X, first as V, takeUntil as me, map as v, ignoreElements as fe, BehaviorSubject as ue, distinctUntilChanged as he, shareReplay as ge, NEVER as H, timer as ye, finalize as _, of as G, lastValueFrom as q } from "rxjs";
|
|
4
|
+
const D = (n, e) => {
|
|
5
|
+
const s = n.split(/(\d+)/), r = e.split(/(\d+)/);
|
|
6
|
+
for (let t = 0, o = s.length; t < o; t++)
|
|
7
|
+
if (s[t] !== r[t])
|
|
8
|
+
return s[t]?.match(/\d/) ? +(s[t] || "") - +(r[t] || "") : (s[t] || "").localeCompare(r[t] || "");
|
|
9
|
+
return 1;
|
|
10
|
+
}, $ = (n) => n.substring(n.lastIndexOf("/") + 1) || n, J = (n) => n.endsWith("/") ? n.slice(0, -1) : n, be = (n) => {
|
|
11
|
+
const e = n.lastIndexOf("/");
|
|
12
|
+
return e >= 0 ? n.substring(0, e) : "";
|
|
13
|
+
}, it = async (n, { orderByAlpha: e, name: s } = {}) => {
|
|
14
|
+
let r = n;
|
|
15
|
+
return e && (r = r.slice().sort((t, o) => D(t.name, o.name))), {
|
|
16
|
+
filename: s || "",
|
|
17
|
+
records: r.map((t) => ({
|
|
18
|
+
dir: t.isDir,
|
|
19
|
+
basename: $(t.name),
|
|
20
|
+
uri: t.name,
|
|
21
|
+
blob: async () => new Blob([await t.data()]),
|
|
22
|
+
string: async () => {
|
|
23
|
+
const o = await t.data();
|
|
24
|
+
return String.fromCharCode.apply(
|
|
25
|
+
null,
|
|
26
|
+
Array.from(new Uint16Array(o))
|
|
27
|
+
);
|
|
28
|
+
},
|
|
29
|
+
size: t.size
|
|
30
|
+
})),
|
|
31
|
+
close: () => Promise.resolve()
|
|
32
|
+
};
|
|
33
|
+
}, we = "@prose-reader/streamer", m = se.namespace(we, !1, {
|
|
34
|
+
color: "#ffae42"
|
|
35
|
+
}), ve = (n) => {
|
|
36
|
+
const e = {};
|
|
37
|
+
for (const r of n) {
|
|
38
|
+
const t = r.split("/");
|
|
39
|
+
let o = e;
|
|
40
|
+
for (let i = 0; i < t.length; i++) {
|
|
41
|
+
const a = t[i];
|
|
42
|
+
a !== void 0 && (o[a] || (o[a] = {}), o = o[a]);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
const s = (r, t = "") => Object.keys(r).sort().map((o, i, a) => {
|
|
46
|
+
const l = i === a.length - 1, c = t + (l ? "└── " : "├── "), d = t + (l ? " " : "│ "), p = r[o];
|
|
47
|
+
return p && Object.keys(p).length > 0 ? `${c}${o}/
|
|
48
|
+
${s(p, d)}` : `${c}${o}`;
|
|
49
|
+
}).join(`
|
|
50
|
+
`);
|
|
51
|
+
return s(e);
|
|
52
|
+
}, at = async (n, { orderByAlpha: e, name: s } = {}) => {
|
|
53
|
+
let r = Object.values(n.files);
|
|
54
|
+
e && (r = r.slice().sort((o, i) => D(o.name, i.name)));
|
|
55
|
+
const t = {
|
|
56
|
+
filename: s || "",
|
|
57
|
+
records: r.map((o) => ({
|
|
58
|
+
dir: o.dir,
|
|
59
|
+
basename: $(o.name),
|
|
60
|
+
uri: o.name,
|
|
61
|
+
blob: () => o.async("blob"),
|
|
62
|
+
string: () => o.async("string"),
|
|
63
|
+
...o.internalStream && {
|
|
64
|
+
stream: o.internalStream
|
|
65
|
+
},
|
|
66
|
+
// this is private API
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
size: o._data.uncompressedSize
|
|
69
|
+
})),
|
|
70
|
+
close: () => Promise.resolve()
|
|
71
|
+
};
|
|
72
|
+
if (m.log("Generated archive", t), process.env.NODE_ENV === "development" && m.isEnabled()) {
|
|
73
|
+
const o = ve(r.map((i) => i.name));
|
|
74
|
+
m.groupCollapsed(...m.getGroupArgs("Archive folder structure")), m.log(`
|
|
75
|
+
${o}`), m.groupEnd();
|
|
76
|
+
}
|
|
77
|
+
return t;
|
|
78
|
+
}, ct = async (n, { name: e } = {}) => {
|
|
79
|
+
const s = await n.getFilesArray(), r = {
|
|
80
|
+
close: () => n.close(),
|
|
81
|
+
filename: e ?? "",
|
|
82
|
+
records: s.map((t) => ({
|
|
83
|
+
dir: !1,
|
|
84
|
+
basename: t.file.name,
|
|
85
|
+
size: t.file.size,
|
|
86
|
+
uri: `${t.path}${t.file.name}`,
|
|
87
|
+
blob: async () => await t.file.extract(),
|
|
88
|
+
string: async () => (await t.file.extract()).text()
|
|
89
|
+
}))
|
|
90
|
+
};
|
|
91
|
+
return m.log("Generated archive", r), r;
|
|
92
|
+
}, dt = async (n, {
|
|
93
|
+
mimeType: e,
|
|
94
|
+
direction: s
|
|
95
|
+
} = { mimeType: "text/plain" }) => {
|
|
96
|
+
const r = `
|
|
97
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
98
|
+
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="ja" prefix="rendition: http://www.idpf.org/vocab/rendition/#"
|
|
99
|
+
unique-identifier="ootuya-id">
|
|
100
|
+
<metadata xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/"
|
|
101
|
+
xmlns:dcterms="http://purl.org/dc/terms/">
|
|
102
|
+
<meta property="rendition:layout">reflowable</meta>
|
|
103
|
+
</metadata>
|
|
104
|
+
<manifest>
|
|
105
|
+
<item id="p01" href="p01.txt" media-type="text/plain"/>
|
|
106
|
+
</manifest>
|
|
107
|
+
<spine page-progression-direction="${s ?? "ltr"}">
|
|
108
|
+
<itemref idref="p01" />
|
|
109
|
+
</spine>
|
|
110
|
+
</package>
|
|
111
|
+
`;
|
|
112
|
+
return {
|
|
113
|
+
filename: "content.txt",
|
|
114
|
+
records: [
|
|
115
|
+
{
|
|
116
|
+
dir: !1,
|
|
117
|
+
basename: $("generated.opf"),
|
|
118
|
+
uri: "generated.opf",
|
|
119
|
+
blob: async () => new Blob([r]),
|
|
120
|
+
string: async () => r,
|
|
121
|
+
size: 0
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
dir: !1,
|
|
125
|
+
basename: $("p01.txt"),
|
|
126
|
+
uri: "p01.txt",
|
|
127
|
+
blob: async () => typeof n == "string" ? new Blob([n]) : n,
|
|
128
|
+
string: async () => typeof n == "string" ? n : n.text(),
|
|
129
|
+
size: typeof n == "string" ? n.length : n.size,
|
|
130
|
+
encodingFormat: e
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
close: () => Promise.resolve()
|
|
134
|
+
};
|
|
135
|
+
}, lt = async (n, e) => {
|
|
136
|
+
const s = `
|
|
137
|
+
<?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
|
|
138
|
+
<metadata>
|
|
139
|
+
<meta property="rendition:layout">${e?.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
|
|
140
|
+
${e?.useRenditionFlow ? '<meta property="rendition:flow">scrolled-continuous</meta>' : ""}
|
|
141
|
+
</metadata>
|
|
142
|
+
<manifest>
|
|
143
|
+
${n.map(
|
|
144
|
+
(o) => `<item id="${$(o)}" href="${o}" media-type="${j(o)}"/>`
|
|
145
|
+
).join(`
|
|
146
|
+
`)}
|
|
147
|
+
</manifest>
|
|
148
|
+
<spine>
|
|
149
|
+
${n.map((o) => `<itemref idref="${$(o)}" />`).join(`
|
|
150
|
+
`)}
|
|
151
|
+
</spine>
|
|
152
|
+
</package>
|
|
153
|
+
`, r = n.map((o) => ({
|
|
154
|
+
dir: !1,
|
|
155
|
+
basename: $(o),
|
|
156
|
+
encodingFormat: j(o),
|
|
157
|
+
uri: o,
|
|
158
|
+
size: 100 / n.length,
|
|
159
|
+
blob: async () => (await fetch(o)).blob(),
|
|
160
|
+
string: async () => ""
|
|
161
|
+
}));
|
|
162
|
+
return {
|
|
163
|
+
filename: "",
|
|
164
|
+
records: [{
|
|
165
|
+
dir: !1,
|
|
166
|
+
basename: "content.opf",
|
|
167
|
+
uri: "content.opf",
|
|
168
|
+
size: 0,
|
|
169
|
+
blob: async () => new Blob(),
|
|
170
|
+
string: async () => s
|
|
171
|
+
}, ...r],
|
|
172
|
+
close: () => Promise.resolve()
|
|
173
|
+
};
|
|
174
|
+
}, pt = ({
|
|
175
|
+
enableReport: n
|
|
176
|
+
} = {}) => {
|
|
177
|
+
m.enable(!!n);
|
|
178
|
+
}, F = (n) => {
|
|
179
|
+
const s = Object.values(n.records).filter(
|
|
180
|
+
(r) => !r.dir
|
|
181
|
+
).find((r) => r.uri.endsWith(".opf"));
|
|
182
|
+
return {
|
|
183
|
+
data: s,
|
|
184
|
+
basePath: s?.uri.substring(0, s.uri.lastIndexOf("/")) || ""
|
|
185
|
+
};
|
|
186
|
+
}, $e = ({ archive: n }) => async (e) => {
|
|
187
|
+
const s = n.records.find(
|
|
188
|
+
(t) => t.basename.toLowerCase() === "com.apple.ibooks.display-options.xml"
|
|
48
189
|
);
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
);
|
|
190
|
+
if (!s || s.dir)
|
|
191
|
+
return e;
|
|
192
|
+
const r = await (await s.blob()).text();
|
|
193
|
+
try {
|
|
194
|
+
const i = new y(r).childNamed("platform")?.childrenNamed("option")?.find((a) => a.attr.name === "fixed-layout")?.val || "false";
|
|
54
195
|
return {
|
|
55
|
-
...
|
|
56
|
-
|
|
196
|
+
...e,
|
|
197
|
+
renditionLayout: i === "true" ? "pre-paginated" : e.renditionLayout
|
|
57
198
|
};
|
|
199
|
+
} catch (t) {
|
|
200
|
+
return console.error(
|
|
201
|
+
`Unable to parse com.apple.ibooks.display-options.xml for content
|
|
202
|
+
`,
|
|
203
|
+
r
|
|
204
|
+
), console.error(t), e;
|
|
58
205
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
206
|
+
}, xe = async (n) => {
|
|
207
|
+
const e = {
|
|
208
|
+
renditionLayout: void 0
|
|
209
|
+
};
|
|
210
|
+
return await Promise.all(
|
|
211
|
+
n.records.map(async (s) => {
|
|
212
|
+
if (s.uri.endsWith("com.kobobooks.display-options.xml") && !s.dir) {
|
|
213
|
+
const t = new y(await s.string()).childNamed("platform")?.childNamed("option");
|
|
214
|
+
t?.attr?.name === "fixed-layout" && t.val === "true" && (e.renditionLayout = "pre-paginated");
|
|
215
|
+
}
|
|
216
|
+
})
|
|
217
|
+
), e;
|
|
218
|
+
}, Fe = ({ archive: n }) => async (e) => {
|
|
219
|
+
const s = await xe(n);
|
|
220
|
+
return {
|
|
221
|
+
...e,
|
|
222
|
+
renditionLayout: e.renditionLayout ?? s.renditionLayout
|
|
223
|
+
};
|
|
224
|
+
}, Ee = ({ archive: n, baseUrl: e }) => async () => {
|
|
225
|
+
const s = Object.values(n.records).filter((r) => !r.dir);
|
|
64
226
|
return {
|
|
65
|
-
|
|
66
|
-
|
|
227
|
+
filename: n.filename,
|
|
228
|
+
title: n.records.find(({ dir: r }) => r)?.basename.replace(/\/$/, "") || n.filename,
|
|
229
|
+
renditionLayout: void 0,
|
|
230
|
+
renditionSpread: "auto",
|
|
231
|
+
readingDirection: "ltr",
|
|
232
|
+
spineItems: s.filter((r) => !r.basename.endsWith(".db")).map((r, t) => {
|
|
233
|
+
const o = e || (/^https?:\/\//.test(r.uri) ? "" : "file://");
|
|
234
|
+
return {
|
|
235
|
+
// some books such as cbz can have same basename inside different sub folder
|
|
236
|
+
// we need to make sure to have unique index
|
|
237
|
+
// /chap01/01.png, /chap02/01.png, etc
|
|
238
|
+
id: `${t}.${r.basename}`,
|
|
239
|
+
index: t,
|
|
240
|
+
href: encodeURI(`${o}${r.uri}`),
|
|
241
|
+
renditionLayout: void 0,
|
|
242
|
+
progressionWeight: 1 / s.length,
|
|
243
|
+
pageSpreadLeft: void 0,
|
|
244
|
+
pageSpreadRight: void 0,
|
|
245
|
+
mediaType: r.encodingFormat
|
|
246
|
+
};
|
|
247
|
+
}),
|
|
248
|
+
items: s.map((r, t) => ({
|
|
249
|
+
id: `${t}.${r.basename}`,
|
|
250
|
+
href: encodeURI(`${e}${r.uri}`)
|
|
251
|
+
}))
|
|
67
252
|
};
|
|
68
|
-
},
|
|
69
|
-
archive:
|
|
253
|
+
}, Y = async ({
|
|
254
|
+
archive: n
|
|
70
255
|
}) => {
|
|
71
|
-
const { data:
|
|
256
|
+
const { data: e, basePath: s } = F(n) || {}, r = await e?.string();
|
|
72
257
|
if (!r) return [];
|
|
73
|
-
const
|
|
74
|
-
return
|
|
75
|
-
},
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
258
|
+
const t = new y(r), o = t.childNamed("manifest"), a = t.childNamed("spine")?.childrenNamed("itemref").map((d) => d.attr.idref), l = o?.childrenNamed("item").filter((d) => a.includes(d.attr.id || "")) || [];
|
|
259
|
+
return n.records.filter((d) => l.find((p) => s ? `${s}/${p.attr.href}` === d.uri : `${p.attr.href}` === d.uri));
|
|
260
|
+
}, Ne = (n) => {
|
|
261
|
+
const e = n.attr.properties?.split(" ") || [];
|
|
262
|
+
let s;
|
|
263
|
+
return e.find((r) => r === "rendition:layout-reflowable") && (s = "reflowable"), e.find((r) => r === "rendition:layout-pre-paginated") && (s = "pre-paginated"), {
|
|
264
|
+
renditionLayout: s,
|
|
265
|
+
pageSpreadLeft: e.some((r) => r === "page-spread-left") || void 0,
|
|
266
|
+
pageSpreadRight: e.some((r) => r === "page-spread-right") || void 0
|
|
267
|
+
};
|
|
268
|
+
}, Ae = (n, e, s) => {
|
|
269
|
+
const r = n.attr.href || "", t = s?.(n);
|
|
270
|
+
return {
|
|
271
|
+
href: e ? `${t}${e}/${r}` : `${t}${r}`,
|
|
272
|
+
id: n.attr.id || "",
|
|
273
|
+
mediaType: n.attr["media-type"]
|
|
274
|
+
};
|
|
275
|
+
}, Q = (n, e, s) => {
|
|
276
|
+
const r = n.childNamed("manifest"), { basePath: t } = F(e) || {};
|
|
277
|
+
return r?.childrenNamed("item")?.map((o) => Ae(o, t, s)) || [];
|
|
278
|
+
}, Ie = ({ archive: n, baseUrl: e }) => async (s) => {
|
|
279
|
+
const { data: r, basePath: t } = F(n) || {};
|
|
280
|
+
if (!r)
|
|
281
|
+
return s;
|
|
282
|
+
const o = await r.string();
|
|
283
|
+
m.groupCollapsed(...m.getGroupArgs("OPF data")), m.log("data", o), m.groupEnd();
|
|
284
|
+
const i = new y(o), a = i.childNamed("metadata"), l = i.childNamed("manifest"), c = i.childNamed("spine"), d = i.childNamed("guide"), p = a?.childNamed("dc:title"), g = a?.childrenNamed("meta") || [], b = g.find(
|
|
285
|
+
(f) => f.attr.property === "rendition:layout"
|
|
286
|
+
), E = g.find(
|
|
287
|
+
(f) => f.attr.property === "rendition:flow"
|
|
288
|
+
), u = g.find(
|
|
289
|
+
(f) => f.attr.property === "rendition:spread"
|
|
290
|
+
), L = b?.val, h = E?.val, x = u?.val, S = p?.val || n.records.find(({ dir: f }) => f)?.basename || "", ne = c?.attr["page-progression-direction"], re = (await Y({ archive: n })).reduce(
|
|
291
|
+
(f, N) => N.size + f,
|
|
292
|
+
0
|
|
293
|
+
);
|
|
294
|
+
return {
|
|
295
|
+
filename: n.filename,
|
|
296
|
+
renditionLayout: L,
|
|
297
|
+
renditionFlow: h || "auto",
|
|
298
|
+
renditionSpread: x,
|
|
299
|
+
title: S,
|
|
300
|
+
readingDirection: ne || "ltr",
|
|
301
|
+
/**
|
|
302
|
+
* @see https://www.w3.org/TR/epub/#sec-itemref-elem
|
|
303
|
+
*/
|
|
304
|
+
spineItems: c?.childrenNamed("itemref").map((f, N) => {
|
|
305
|
+
const w = l?.childrenNamed("item").find((k) => k.attr.id === f?.attr.idref), M = w?.attr.href || "", oe = n.records.find((k) => k.uri.endsWith(M))?.size || 0, U = e || (/^https?:\/\//.test(M) ? "" : "file://"), z = Ne(f);
|
|
306
|
+
return {
|
|
307
|
+
...z,
|
|
308
|
+
id: w?.attr.id || "",
|
|
309
|
+
index: N,
|
|
310
|
+
href: w?.attr.href?.startsWith("https://") ? w?.attr.href : t ? `${U}${t}/${w?.attr.href}` : `${U}${w?.attr.href}`,
|
|
311
|
+
renditionLayout: z.renditionLayout ?? L,
|
|
312
|
+
progressionWeight: oe / re,
|
|
313
|
+
// size: itemSize
|
|
314
|
+
mediaType: w?.attr["media-type"]
|
|
315
|
+
};
|
|
316
|
+
}) || [],
|
|
317
|
+
items: Q(i, n, (f) => {
|
|
318
|
+
const N = f.attr.href || "";
|
|
319
|
+
return /^https?:\/\//.test(N) ? "" : e || "file://";
|
|
320
|
+
}),
|
|
321
|
+
guide: d?.childrenNamed("reference").map((f) => ({
|
|
322
|
+
href: f.attr.href || "",
|
|
323
|
+
title: f.attr.title || "",
|
|
324
|
+
type: f.attr.type
|
|
325
|
+
}))
|
|
326
|
+
};
|
|
327
|
+
}, Te = (n) => {
|
|
328
|
+
const e = n.descendantWithPath("head")?.childrenNamed("meta").find((s) => s.attr.name === "viewport");
|
|
329
|
+
return !!(e && e.attr.name === "viewport");
|
|
330
|
+
}, We = (n) => n.reduce(async (e, s) => {
|
|
331
|
+
if (!await e || !ie({
|
|
332
|
+
mimeType: s.encodingFormat,
|
|
333
|
+
uri: s.uri
|
|
334
|
+
}))
|
|
335
|
+
return !1;
|
|
336
|
+
const t = s.dir ? null : await s.string();
|
|
337
|
+
return t ? Te(new y(t)) : !1;
|
|
338
|
+
}, Promise.resolve(!0)), Le = ({ archive: n }) => async (e) => {
|
|
339
|
+
if (e.renditionLayout === "reflowable" && e.spineItems.every((r) => r.renditionLayout === "reflowable")) {
|
|
340
|
+
const r = await Y({ archive: n });
|
|
341
|
+
if (await We(r))
|
|
342
|
+
return {
|
|
343
|
+
...e,
|
|
344
|
+
spineItems: e.spineItems.map((o) => ({
|
|
345
|
+
...o,
|
|
346
|
+
renditionLayout: "pre-paginated"
|
|
347
|
+
})),
|
|
348
|
+
renditionLayout: "pre-paginated"
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
return e;
|
|
352
|
+
}, Se = ({ archive: n }) => async (e) => {
|
|
353
|
+
const s = n.records.find(
|
|
354
|
+
(o) => o.basename.toLowerCase() === "comicinfo.xml" && !o.dir
|
|
355
|
+
);
|
|
356
|
+
if (!s || s.dir)
|
|
357
|
+
return e;
|
|
358
|
+
const r = {
|
|
359
|
+
...e,
|
|
360
|
+
spineItems: e.spineItems.filter((o) => !o.id.toLowerCase().endsWith("comicinfo.xml")).map((o, i, a) => ({
|
|
361
|
+
...o,
|
|
362
|
+
progressionWeight: 1 / a.length
|
|
363
|
+
}))
|
|
364
|
+
}, t = await s.string();
|
|
365
|
+
try {
|
|
366
|
+
const i = new y(t).childNamed("Manga")?.val || "unknown";
|
|
367
|
+
return {
|
|
368
|
+
...r,
|
|
369
|
+
readingDirection: i === "YesAndRightToLeft" ? "rtl" : "ltr"
|
|
370
|
+
};
|
|
371
|
+
} catch (o) {
|
|
372
|
+
return console.error(`Unable to parse comicinfo.xml for content
|
|
373
|
+
`, t), console.error(o), r;
|
|
374
|
+
}
|
|
375
|
+
}, ke = (n) => n.records.some((e) => e.basename.endsWith(".opf")), Ce = ({ archive: n }) => async (e) => ke(n) ? e : {
|
|
376
|
+
...e,
|
|
377
|
+
spineItems: e.spineItems.map((r) => {
|
|
378
|
+
const t = n.records.find(
|
|
379
|
+
(i) => decodeURI(r.href).endsWith(i.uri)
|
|
380
|
+
), o = ae(t?.encodingFormat ?? "") ?? j(t?.basename ?? "");
|
|
381
|
+
return {
|
|
382
|
+
...r,
|
|
383
|
+
renditionLayout: o?.startsWith("image/") ? "pre-paginated" : r.renditionLayout
|
|
384
|
+
};
|
|
385
|
+
})
|
|
386
|
+
}, Z = (n) => n ? n.children.map((e) => e instanceof ce ? e.text : e instanceof de ? Z(e) : "").join("").trim() : "", ee = (n, { basePath: e, baseUrl: s }) => {
|
|
79
387
|
const r = {
|
|
80
388
|
contents: [],
|
|
81
389
|
path: "",
|
|
82
390
|
href: "",
|
|
83
391
|
title: ""
|
|
84
392
|
};
|
|
85
|
-
let
|
|
86
|
-
r.title = (
|
|
87
|
-
let
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
91
|
-
const a =
|
|
393
|
+
let t = n.childNamed("span") || n.childNamed("a");
|
|
394
|
+
r.title = (t?.attr.title || t?.val.trim() || Z(t)) ?? "";
|
|
395
|
+
let o = t?.name;
|
|
396
|
+
o !== "a" && (t = n.descendantWithPath(`${o}.a`), t && (o = t.name.toLowerCase())), o === "a" && t?.attr.href && (r.path = I(e, t.attr.href), r.href = I(s, e, t.attr.href));
|
|
397
|
+
const i = n.childNamed("ol");
|
|
398
|
+
if (i) {
|
|
399
|
+
const a = i.childrenNamed("li");
|
|
92
400
|
a && a.length > 0 && (r.contents = a.map(
|
|
93
|
-
(
|
|
401
|
+
(l) => ee(l, { basePath: e, baseUrl: s })
|
|
94
402
|
));
|
|
95
403
|
}
|
|
96
404
|
return r;
|
|
97
|
-
},
|
|
405
|
+
}, Re = (n, { basePath: e, baseUrl: s }) => {
|
|
98
406
|
const r = [];
|
|
99
|
-
let
|
|
100
|
-
return
|
|
101
|
-
r.push(ee(
|
|
407
|
+
let t;
|
|
408
|
+
return n.descendantWithPath("body.nav.ol") ? t = n.descendantWithPath("body.nav.ol")?.children : n.descendantWithPath("body.section.nav.ol") && (t = n.descendantWithPath("body.section.nav.ol")?.children), t && t.length > 0 && t.filter((o) => o.name === "li").forEach((o) => {
|
|
409
|
+
r.push(ee(o, { basePath: e, baseUrl: s }));
|
|
102
410
|
}), r;
|
|
103
|
-
},
|
|
104
|
-
const r =
|
|
411
|
+
}, Pe = async (n, e, { baseUrl: s }) => {
|
|
412
|
+
const r = n.childNamed("manifest")?.childrenNamed("item").find((t) => t.attr.properties === "nav");
|
|
105
413
|
if (r) {
|
|
106
|
-
const
|
|
107
|
-
(
|
|
414
|
+
const t = Object.values(e.records).find(
|
|
415
|
+
(o) => o.uri.endsWith(r.attr.href || "")
|
|
108
416
|
);
|
|
109
|
-
if (
|
|
110
|
-
const
|
|
111
|
-
return
|
|
417
|
+
if (t && !t.dir) {
|
|
418
|
+
const o = new y(await t.string()), i = be(t.uri);
|
|
419
|
+
return Re(o, { basePath: i, baseUrl: s });
|
|
112
420
|
}
|
|
113
421
|
}
|
|
114
|
-
}, te = (
|
|
115
|
-
opfBasePath:
|
|
116
|
-
baseUrl:
|
|
422
|
+
}, te = (n, {
|
|
423
|
+
opfBasePath: e,
|
|
424
|
+
baseUrl: s,
|
|
117
425
|
prefix: r
|
|
118
426
|
}) => {
|
|
119
|
-
const
|
|
120
|
-
title:
|
|
121
|
-
path:
|
|
122
|
-
href:
|
|
427
|
+
const t = n?.childNamed(`${r}content`)?.attr.src || "", o = {
|
|
428
|
+
title: n?.descendantWithPath(`${r}navLabel.${r}text`)?.val || "",
|
|
429
|
+
path: I(e, t),
|
|
430
|
+
href: I(s, e, t),
|
|
123
431
|
contents: []
|
|
124
|
-
},
|
|
125
|
-
return
|
|
126
|
-
(a) => te(a, { opfBasePath:
|
|
127
|
-
)),
|
|
128
|
-
},
|
|
129
|
-
const r = [],
|
|
130
|
-
let
|
|
131
|
-
return
|
|
132
|
-
r.push(te(
|
|
432
|
+
}, i = n.childrenNamed(`${r}navPoint`);
|
|
433
|
+
return i && i.length > 0 && (o.contents = i.map(
|
|
434
|
+
(a) => te(a, { opfBasePath: e, baseUrl: s, prefix: r })
|
|
435
|
+
)), o;
|
|
436
|
+
}, je = (n, { opfBasePath: e, baseUrl: s }) => {
|
|
437
|
+
const r = [], t = n.name;
|
|
438
|
+
let o = "";
|
|
439
|
+
return t.indexOf(":") !== -1 && (o = `${t.split(":")[0]}:`), n.childNamed(`${o}navMap`)?.childrenNamed(`${o}navPoint`).forEach((i) => {
|
|
440
|
+
r.push(te(i, { opfBasePath: e, baseUrl: s, prefix: o }));
|
|
133
441
|
}), r;
|
|
134
|
-
},
|
|
135
|
-
opfData:
|
|
136
|
-
opfBasePath:
|
|
137
|
-
baseUrl:
|
|
442
|
+
}, Oe = async ({
|
|
443
|
+
opfData: n,
|
|
444
|
+
opfBasePath: e,
|
|
445
|
+
baseUrl: s,
|
|
138
446
|
archive: r
|
|
139
447
|
}) => {
|
|
140
|
-
const
|
|
141
|
-
if (
|
|
142
|
-
const
|
|
143
|
-
if (
|
|
144
|
-
const a = `${
|
|
145
|
-
(
|
|
448
|
+
const o = n.childNamed("spine")?.attr.toc;
|
|
449
|
+
if (o) {
|
|
450
|
+
const i = n.childNamed("manifest")?.childrenNamed("item").find((a) => a.attr.id === o);
|
|
451
|
+
if (i) {
|
|
452
|
+
const a = `${e}${e === "" ? "" : "/"}${i.attr.href}`, l = Object.values(r.records).find(
|
|
453
|
+
(c) => c.uri.endsWith(a)
|
|
146
454
|
);
|
|
147
|
-
if (
|
|
148
|
-
const
|
|
149
|
-
return
|
|
455
|
+
if (l && !l.dir) {
|
|
456
|
+
const c = new y(await l.string());
|
|
457
|
+
return je(c, { opfBasePath: e, baseUrl: s });
|
|
150
458
|
}
|
|
151
459
|
}
|
|
152
460
|
}
|
|
153
|
-
},
|
|
154
|
-
const { basePath: r } =
|
|
155
|
-
|
|
156
|
-
opfBasePath: r,
|
|
157
|
-
archive: t,
|
|
158
|
-
baseUrl: i
|
|
461
|
+
}, De = async (n, e, { baseUrl: s }) => {
|
|
462
|
+
const { basePath: r } = F(e) || {}, t = await Pe(n, e, {
|
|
463
|
+
baseUrl: s
|
|
159
464
|
});
|
|
160
|
-
|
|
161
|
-
|
|
465
|
+
if (t)
|
|
466
|
+
return t;
|
|
467
|
+
const o = await Oe({
|
|
468
|
+
opfData: n,
|
|
469
|
+
opfBasePath: r,
|
|
470
|
+
archive: e,
|
|
471
|
+
baseUrl: s
|
|
162
472
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
473
|
+
if (o)
|
|
474
|
+
return o;
|
|
475
|
+
}, Me = (n, { baseUrl: e }) => {
|
|
476
|
+
const s = [...n.records].sort(
|
|
477
|
+
(t, o) => D(t.uri, o.uri)
|
|
478
|
+
), r = (t, o, i, a, l) => {
|
|
479
|
+
const c = t.find((g) => g.title === o), [d, ...p] = i;
|
|
480
|
+
return c ? d ? [
|
|
481
|
+
...t.filter((b) => b !== c),
|
|
482
|
+
{
|
|
483
|
+
...c,
|
|
484
|
+
contents: [
|
|
485
|
+
...c.contents,
|
|
486
|
+
...r(
|
|
487
|
+
c.contents,
|
|
488
|
+
d,
|
|
489
|
+
p,
|
|
490
|
+
a,
|
|
491
|
+
l
|
|
492
|
+
)
|
|
493
|
+
]
|
|
494
|
+
}
|
|
495
|
+
] : c.path.split("/").length > l.split("/").length ? [
|
|
496
|
+
...t.filter((b) => b !== c),
|
|
497
|
+
{
|
|
498
|
+
...c,
|
|
499
|
+
path: l,
|
|
500
|
+
href: a
|
|
501
|
+
}
|
|
502
|
+
] : t : d ? [
|
|
503
|
+
...t,
|
|
504
|
+
{
|
|
505
|
+
contents: r(
|
|
506
|
+
[],
|
|
507
|
+
d,
|
|
508
|
+
p,
|
|
509
|
+
a,
|
|
510
|
+
l
|
|
511
|
+
),
|
|
512
|
+
href: a,
|
|
513
|
+
path: l,
|
|
514
|
+
title: o
|
|
515
|
+
}
|
|
516
|
+
] : [
|
|
517
|
+
...t,
|
|
518
|
+
{
|
|
519
|
+
contents: [],
|
|
520
|
+
href: a,
|
|
521
|
+
path: l,
|
|
522
|
+
title: o
|
|
523
|
+
}
|
|
524
|
+
];
|
|
177
525
|
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
);
|
|
197
|
-
return {
|
|
198
|
-
|
|
526
|
+
return s.reduce((t, o) => {
|
|
527
|
+
if (o.dir) return t;
|
|
528
|
+
const i = o.uri.split("/").slice(0, -1), [a, ...l] = i;
|
|
529
|
+
if (!a) return t;
|
|
530
|
+
const c = I(e, encodeURI(o.uri)).replace(/\/$/, ""), d = o.uri.replace(/\/$/, "");
|
|
531
|
+
return r(t, a, l, c, d);
|
|
532
|
+
}, []);
|
|
533
|
+
}, Ue = async (n, { baseUrl: e }) => {
|
|
534
|
+
const { data: s } = F(n) || {};
|
|
535
|
+
if (s && !s.dir) {
|
|
536
|
+
const t = new y(await s.string());
|
|
537
|
+
return await De(t, n, { baseUrl: e }) || [];
|
|
538
|
+
}
|
|
539
|
+
const r = Me(n, { baseUrl: e });
|
|
540
|
+
if (r.length !== 0)
|
|
541
|
+
return r;
|
|
542
|
+
}, ze = ({ archive: n, baseUrl: e }) => async (s) => {
|
|
543
|
+
if (s.nav) return s;
|
|
544
|
+
const r = await Ue(n, { baseUrl: e });
|
|
545
|
+
return r ? {
|
|
546
|
+
...s,
|
|
199
547
|
nav: {
|
|
200
|
-
toc:
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
548
|
+
toc: r
|
|
549
|
+
}
|
|
550
|
+
} : s;
|
|
551
|
+
}, Be = async (n, { baseUrl: e = "" } = {}) => {
|
|
552
|
+
const s = [
|
|
553
|
+
Ie({ archive: n, baseUrl: e }),
|
|
554
|
+
Se({ archive: n }),
|
|
555
|
+
$e({ archive: n }),
|
|
556
|
+
Ce({ archive: n }),
|
|
557
|
+
Le({ archive: n }),
|
|
558
|
+
Fe({ archive: n }),
|
|
559
|
+
ze({ archive: n, baseUrl: e })
|
|
560
|
+
];
|
|
561
|
+
try {
|
|
562
|
+
const r = Ee({ archive: n, baseUrl: e })(), t = await s.reduce(async (o, i) => await i(await o), r);
|
|
563
|
+
if (m.log("Generated manifest", t), process.env.NODE_ENV === "development" && m.isEnabled()) {
|
|
564
|
+
const o = JSON.stringify(t, null, 2);
|
|
565
|
+
m.groupCollapsed(...m.getGroupArgs("Generated manifest")), m.log(`
|
|
566
|
+
${o}`), m.groupEnd();
|
|
567
|
+
}
|
|
568
|
+
return t;
|
|
569
|
+
} catch (r) {
|
|
570
|
+
throw m.error(r), r;
|
|
571
|
+
}
|
|
572
|
+
}, Xe = (n) => {
|
|
573
|
+
const e = n.descendantWithPath("head")?.childrenNamed("meta").find((s) => s.attr.name === "calibre:cover");
|
|
574
|
+
return !!(e && e.attr.name === "calibre:cover");
|
|
575
|
+
}, Ve = (n) => n.descendantWithPath("body")?.descendantWithPath("div")?.childrenNamed("svg")?.find(
|
|
576
|
+
(e) => e.attr.width === "100%" && e.attr.preserveAspectRatio === "none"
|
|
577
|
+
), He = ({ archive: n, resourcePath: e }) => async (s) => {
|
|
578
|
+
const r = Object.values(n.records).find(
|
|
579
|
+
(t) => t.uri === e && !t.dir
|
|
580
|
+
);
|
|
581
|
+
if (r && !r.dir && r.basename.endsWith(".xhtml")) {
|
|
582
|
+
const t = s.body ?? await r.string(), o = new y(t);
|
|
583
|
+
if (Xe(o)) {
|
|
584
|
+
const i = Ve(o);
|
|
585
|
+
return i && delete i.attr.preserveAspectRatio, {
|
|
586
|
+
...s,
|
|
587
|
+
body: o?.toString()
|
|
221
588
|
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
return s;
|
|
592
|
+
}, _e = ({ archive: n, resourcePath: e }) => async (s) => He({ archive: n, resourcePath: e })(s), Ge = ({ archive: n, resourcePath: e }) => async (s) => {
|
|
593
|
+
const r = Object.values(n.records).find(
|
|
594
|
+
(t) => t.uri === e && !t.dir
|
|
595
|
+
);
|
|
596
|
+
if (r && !r.dir && r.basename.endsWith(".css")) {
|
|
597
|
+
const o = (s.body ?? await r.string()).replaceAll(
|
|
598
|
+
"-webkit-writing-mode",
|
|
599
|
+
"writing-mode"
|
|
600
|
+
);
|
|
601
|
+
return {
|
|
602
|
+
...s,
|
|
603
|
+
body: o
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
return s;
|
|
607
|
+
}, qe = async (n, e) => {
|
|
608
|
+
const r = await F(n).data?.string();
|
|
235
609
|
if (r) {
|
|
236
|
-
const
|
|
237
|
-
if (
|
|
238
|
-
(a) =>
|
|
610
|
+
const t = new y(r), o = Q(t, n, () => "");
|
|
611
|
+
if (o.find(
|
|
612
|
+
(a) => e.endsWith(a.href)
|
|
239
613
|
)?.mediaType)
|
|
240
614
|
return {
|
|
241
|
-
mediaType:
|
|
615
|
+
mediaType: o.find((a) => e.endsWith(a.href))?.mediaType
|
|
242
616
|
};
|
|
243
617
|
}
|
|
244
618
|
return {
|
|
245
|
-
mediaType:
|
|
619
|
+
mediaType: Je(e)
|
|
246
620
|
};
|
|
247
|
-
},
|
|
248
|
-
if (
|
|
621
|
+
}, Je = (n) => {
|
|
622
|
+
if (n.endsWith(".css"))
|
|
249
623
|
return "text/css; charset=UTF-8";
|
|
250
|
-
if (
|
|
624
|
+
if (n.endsWith(".jpg"))
|
|
251
625
|
return "image/jpg";
|
|
252
|
-
if (
|
|
626
|
+
if (n.endsWith(".xhtml"))
|
|
253
627
|
return "application/xhtml+xml";
|
|
254
|
-
if (
|
|
628
|
+
if (n.endsWith(".mp4"))
|
|
255
629
|
return "video/mp4";
|
|
256
|
-
if (
|
|
630
|
+
if (n.endsWith(".svg"))
|
|
257
631
|
return "image/svg+xml";
|
|
258
|
-
},
|
|
259
|
-
const r = Object.values(
|
|
260
|
-
(
|
|
632
|
+
}, Ke = ({ archive: n, resourcePath: e }) => async (s) => {
|
|
633
|
+
const r = Object.values(n.records).find(
|
|
634
|
+
(o) => o.uri === e && !o.dir
|
|
261
635
|
);
|
|
262
|
-
if (!r || r.dir) return
|
|
263
|
-
const
|
|
636
|
+
if (!r || r.dir) return s;
|
|
637
|
+
const t = await qe(n, e);
|
|
264
638
|
return {
|
|
265
|
-
...
|
|
639
|
+
...s,
|
|
266
640
|
params: {
|
|
267
|
-
...
|
|
641
|
+
...s.params,
|
|
268
642
|
...r?.encodingFormat && {
|
|
269
643
|
contentType: r.encodingFormat
|
|
270
644
|
},
|
|
271
|
-
...
|
|
272
|
-
contentType:
|
|
645
|
+
...t.mediaType && {
|
|
646
|
+
contentType: t.mediaType
|
|
273
647
|
}
|
|
274
648
|
}
|
|
275
649
|
};
|
|
276
|
-
},
|
|
650
|
+
}, K = [
|
|
277
651
|
"div",
|
|
278
652
|
"span",
|
|
279
653
|
"p",
|
|
@@ -324,640 +698,282 @@ const w = {
|
|
|
324
698
|
"canvas",
|
|
325
699
|
"script",
|
|
326
700
|
"style"
|
|
327
|
-
],
|
|
328
|
-
const r = Object.values(
|
|
329
|
-
(
|
|
701
|
+
], Ye = ({ archive: n, resourcePath: e }) => async (s) => {
|
|
702
|
+
const r = Object.values(n.records).find(
|
|
703
|
+
(t) => t.uri === e && !t.dir
|
|
330
704
|
);
|
|
331
705
|
if (r && !r.dir && r.basename.endsWith(".xhtml")) {
|
|
332
|
-
const
|
|
706
|
+
const t = s.body ?? await r.string();
|
|
333
707
|
if (!new RegExp(
|
|
334
|
-
`<(${
|
|
708
|
+
`<(${K.join("|")})[\\s/>]`,
|
|
335
709
|
"i"
|
|
336
|
-
).test(
|
|
337
|
-
return
|
|
338
|
-
const
|
|
339
|
-
`<(${
|
|
710
|
+
).test(t))
|
|
711
|
+
return s;
|
|
712
|
+
const i = new RegExp(
|
|
713
|
+
`<(${K.join("|")})(\\s[^>]*)?\\s*/>`,
|
|
340
714
|
"gi"
|
|
341
|
-
), a =
|
|
342
|
-
|
|
343
|
-
(
|
|
715
|
+
), a = t.replace(
|
|
716
|
+
i,
|
|
717
|
+
(l, c, d = "") => `<${c} ${d.trim()}></${c}>`
|
|
344
718
|
);
|
|
345
719
|
return {
|
|
346
|
-
...
|
|
720
|
+
...s,
|
|
347
721
|
body: a
|
|
348
722
|
};
|
|
349
723
|
}
|
|
350
|
-
return
|
|
351
|
-
},
|
|
352
|
-
const
|
|
353
|
-
(
|
|
724
|
+
return s;
|
|
725
|
+
}, Qe = async (n, e) => {
|
|
726
|
+
const s = Object.values(n.records).find(
|
|
727
|
+
(o) => o.uri === e && !o.dir
|
|
354
728
|
);
|
|
355
|
-
if (!
|
|
356
|
-
throw new Error(`no file found for resourcePath:${
|
|
729
|
+
if (!s || s.dir)
|
|
730
|
+
throw new Error(`no file found for resourcePath:${e}`);
|
|
357
731
|
const r = {
|
|
358
732
|
params: {}
|
|
359
|
-
},
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
733
|
+
}, t = [
|
|
734
|
+
Ke({ archive: n, resourcePath: e }),
|
|
735
|
+
Ye({ archive: n, resourcePath: e }),
|
|
736
|
+
Ge({ archive: n, resourcePath: e }),
|
|
737
|
+
_e({ archive: n, resourcePath: e })
|
|
364
738
|
];
|
|
365
739
|
try {
|
|
366
|
-
const
|
|
367
|
-
return
|
|
368
|
-
...
|
|
369
|
-
body:
|
|
370
|
-
};
|
|
371
|
-
} catch (s) {
|
|
372
|
-
throw w.error(s), s;
|
|
373
|
-
}
|
|
374
|
-
}, De = ({ archive: e }) => async (t) => {
|
|
375
|
-
const i = e.records.find(
|
|
376
|
-
(n) => n.basename.toLowerCase() === "com.apple.ibooks.display-options.xml"
|
|
377
|
-
);
|
|
378
|
-
if (!i || i.dir)
|
|
379
|
-
return t;
|
|
380
|
-
const r = await (await i.blob()).text();
|
|
381
|
-
try {
|
|
382
|
-
const o = new b(r).childNamed("platform")?.childrenNamed("option")?.find((a) => a.attr.name === "fixed-layout")?.val || "false";
|
|
383
|
-
return {
|
|
384
|
-
...t,
|
|
385
|
-
renditionLayout: o === "true" ? "pre-paginated" : t.renditionLayout
|
|
386
|
-
};
|
|
387
|
-
} catch (n) {
|
|
388
|
-
return console.error(
|
|
389
|
-
`Unable to parse com.apple.ibooks.display-options.xml for content
|
|
390
|
-
`,
|
|
391
|
-
r
|
|
392
|
-
), console.error(n), t;
|
|
393
|
-
}
|
|
394
|
-
}, Me = async (e) => {
|
|
395
|
-
const t = {
|
|
396
|
-
renditionLayout: void 0
|
|
397
|
-
};
|
|
398
|
-
return await Promise.all(
|
|
399
|
-
e.records.map(async (i) => {
|
|
400
|
-
if (i.uri.endsWith("com.kobobooks.display-options.xml") && !i.dir) {
|
|
401
|
-
const n = new b(await i.string()).childNamed("platform")?.childNamed("option");
|
|
402
|
-
n?.attr?.name === "fixed-layout" && n.val === "true" && (t.renditionLayout = "pre-paginated");
|
|
403
|
-
}
|
|
404
|
-
})
|
|
405
|
-
), t;
|
|
406
|
-
}, Ue = ({ archive: e }) => async (t) => {
|
|
407
|
-
const i = await Me(e);
|
|
408
|
-
return {
|
|
409
|
-
...t,
|
|
410
|
-
renditionLayout: t.renditionLayout ?? i.renditionLayout
|
|
411
|
-
};
|
|
412
|
-
}, ze = ({ archive: e, baseUrl: t }) => async () => {
|
|
413
|
-
const i = Object.values(e.records).filter((r) => !r.dir);
|
|
414
|
-
return {
|
|
415
|
-
filename: e.filename,
|
|
416
|
-
title: e.records.find(({ dir: r }) => r)?.basename.replace(/\/$/, "") || e.filename,
|
|
417
|
-
renditionLayout: void 0,
|
|
418
|
-
renditionSpread: "auto",
|
|
419
|
-
readingDirection: "ltr",
|
|
420
|
-
spineItems: i.filter((r) => !r.basename.endsWith(".db")).map((r, n) => {
|
|
421
|
-
const s = t || (/^https?:\/\//.test(r.uri) ? "" : "file://");
|
|
422
|
-
return {
|
|
423
|
-
// some books such as cbz can have same basename inside different sub folder
|
|
424
|
-
// we need to make sure to have unique index
|
|
425
|
-
// /chap01/01.png, /chap02/01.png, etc
|
|
426
|
-
id: `${n}.${r.basename}`,
|
|
427
|
-
index: n,
|
|
428
|
-
href: encodeURI(`${s}${r.uri}`),
|
|
429
|
-
renditionLayout: void 0,
|
|
430
|
-
progressionWeight: 1 / i.length,
|
|
431
|
-
pageSpreadLeft: void 0,
|
|
432
|
-
pageSpreadRight: void 0,
|
|
433
|
-
mediaType: r.encodingFormat
|
|
434
|
-
};
|
|
435
|
-
}),
|
|
436
|
-
items: i.map((r, n) => ({
|
|
437
|
-
id: `${n}.${r.basename}`,
|
|
438
|
-
href: encodeURI(`${t}${r.uri}`)
|
|
439
|
-
}))
|
|
440
|
-
};
|
|
441
|
-
}, Be = (e) => {
|
|
442
|
-
const t = e.descendantWithPath("head")?.childrenNamed("meta").find((i) => i.attr.name === "viewport");
|
|
443
|
-
return !!(t && t.attr.name === "viewport");
|
|
444
|
-
}, Xe = (e) => e.reduce(async (t, i) => {
|
|
445
|
-
if (!await t || !de({
|
|
446
|
-
mimeType: i.encodingFormat,
|
|
447
|
-
uri: i.uri
|
|
448
|
-
}))
|
|
449
|
-
return !1;
|
|
450
|
-
const n = i.dir ? null : await i.string();
|
|
451
|
-
return n ? Be(new b(n)) : !1;
|
|
452
|
-
}, Promise.resolve(!0)), He = ({ archive: e }) => async (t) => {
|
|
453
|
-
if (t.renditionLayout === "reflowable" && t.spineItems.every((r) => r.renditionLayout === "reflowable")) {
|
|
454
|
-
const r = await Q({ archive: e });
|
|
455
|
-
if (await Xe(r))
|
|
456
|
-
return {
|
|
457
|
-
...t,
|
|
458
|
-
spineItems: t.spineItems.map((s) => ({
|
|
459
|
-
...s,
|
|
460
|
-
renditionLayout: "pre-paginated"
|
|
461
|
-
})),
|
|
462
|
-
renditionLayout: "pre-paginated"
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
return t;
|
|
466
|
-
}, Ve = ({ archive: e }) => async (t) => {
|
|
467
|
-
const i = e.records.find(
|
|
468
|
-
(s) => s.basename.toLowerCase() === "comicinfo.xml" && !s.dir
|
|
469
|
-
);
|
|
470
|
-
if (!i || i.dir)
|
|
471
|
-
return t;
|
|
472
|
-
const r = {
|
|
473
|
-
...t,
|
|
474
|
-
spineItems: t.spineItems.filter((s) => !s.id.toLowerCase().endsWith("comicinfo.xml")).map((s, o, a) => ({
|
|
475
|
-
...s,
|
|
476
|
-
progressionWeight: 1 / a.length
|
|
477
|
-
}))
|
|
478
|
-
}, n = await i.string();
|
|
479
|
-
try {
|
|
480
|
-
const o = new b(n).childNamed("Manga")?.val || "unknown";
|
|
481
|
-
return {
|
|
482
|
-
...r,
|
|
483
|
-
readingDirection: o === "YesAndRightToLeft" ? "rtl" : "ltr"
|
|
484
|
-
};
|
|
485
|
-
} catch (s) {
|
|
486
|
-
return console.error(`Unable to parse comicinfo.xml for content
|
|
487
|
-
`, n), console.error(s), r;
|
|
488
|
-
}
|
|
489
|
-
}, M = (e, t) => {
|
|
490
|
-
const i = e.split(/(\d+)/), r = t.split(/(\d+)/);
|
|
491
|
-
for (let n = 0, s = i.length; n < s; n++)
|
|
492
|
-
if (i[n] !== r[n])
|
|
493
|
-
return i[n]?.match(/\d/) ? +(i[n] || "") - +(r[n] || "") : (i[n] || "").localeCompare(r[n] || "");
|
|
494
|
-
return 1;
|
|
495
|
-
}, _e = ({ archive: e, baseUrl: t }) => async (i) => {
|
|
496
|
-
if (i.nav) return i;
|
|
497
|
-
const r = [...e.records].sort(
|
|
498
|
-
(a, d) => M(a.uri, d.uri)
|
|
499
|
-
), n = Object.values(r), s = (a, d, p, c, l) => {
|
|
500
|
-
const m = a.find((u) => u.title === d), [h, ...y] = p;
|
|
501
|
-
return m ? h ? [
|
|
502
|
-
...a.filter((F) => F !== m),
|
|
503
|
-
{
|
|
504
|
-
...m,
|
|
505
|
-
contents: [
|
|
506
|
-
...m.contents,
|
|
507
|
-
...s(
|
|
508
|
-
m.contents,
|
|
509
|
-
h,
|
|
510
|
-
y,
|
|
511
|
-
c,
|
|
512
|
-
l
|
|
513
|
-
)
|
|
514
|
-
]
|
|
515
|
-
}
|
|
516
|
-
] : m.path.split("/").length > l.split("/").length ? [
|
|
517
|
-
...a.filter((F) => F !== m),
|
|
518
|
-
{
|
|
519
|
-
...m,
|
|
520
|
-
path: l,
|
|
521
|
-
href: c
|
|
522
|
-
}
|
|
523
|
-
] : a : h ? [
|
|
524
|
-
...a,
|
|
525
|
-
{
|
|
526
|
-
contents: s(
|
|
527
|
-
[],
|
|
528
|
-
h,
|
|
529
|
-
y,
|
|
530
|
-
c,
|
|
531
|
-
l
|
|
532
|
-
),
|
|
533
|
-
href: c,
|
|
534
|
-
path: l,
|
|
535
|
-
title: d
|
|
536
|
-
}
|
|
537
|
-
] : [
|
|
538
|
-
...a,
|
|
539
|
-
{
|
|
540
|
-
contents: [],
|
|
541
|
-
href: c,
|
|
542
|
-
path: l,
|
|
543
|
-
title: d
|
|
544
|
-
}
|
|
545
|
-
];
|
|
546
|
-
}, o = n.reduce(
|
|
547
|
-
(a, d) => {
|
|
548
|
-
if (d.dir) return a;
|
|
549
|
-
const c = d.uri.split("/").slice(0, -1), [l, ...m] = c;
|
|
550
|
-
if (l) {
|
|
551
|
-
const h = W(t, encodeURI(d.uri)).replace(/\/$/, ""), y = d.uri.replace(/\/$/, "");
|
|
552
|
-
return s(a, l, m, h, y);
|
|
553
|
-
}
|
|
554
|
-
return a;
|
|
555
|
-
},
|
|
556
|
-
[]
|
|
557
|
-
);
|
|
558
|
-
return o.length === 0 ? i : {
|
|
559
|
-
...i,
|
|
560
|
-
nav: {
|
|
561
|
-
toc: o
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
}, qe = (e) => e.records.some((t) => t.basename.endsWith(".opf")), Ge = ({ archive: e }) => async (t) => qe(e) ? t : {
|
|
565
|
-
...t,
|
|
566
|
-
spineItems: t.spineItems.map((r) => {
|
|
567
|
-
const n = e.records.find(
|
|
568
|
-
(o) => decodeURI(r.href).endsWith(o.uri)
|
|
569
|
-
), s = le(n?.encodingFormat ?? "") ?? O(n?.basename ?? "");
|
|
570
|
-
return {
|
|
571
|
-
...r,
|
|
572
|
-
renditionLayout: s?.startsWith("image/") ? "pre-paginated" : r.renditionLayout
|
|
740
|
+
const o = await t.reduce(async (i, a) => await a(await i), Promise.resolve(r));
|
|
741
|
+
return m.log("Generated resource", e, o), {
|
|
742
|
+
...o,
|
|
743
|
+
body: o.body ?? await s.blob()
|
|
573
744
|
};
|
|
574
|
-
})
|
|
575
|
-
|
|
576
|
-
const i = [
|
|
577
|
-
ke({ archive: e, baseUrl: t }),
|
|
578
|
-
Ve({ archive: e }),
|
|
579
|
-
De({ archive: e }),
|
|
580
|
-
Ge({ archive: e }),
|
|
581
|
-
He({ archive: e }),
|
|
582
|
-
Ue({ archive: e }),
|
|
583
|
-
_e({ archive: e, baseUrl: t })
|
|
584
|
-
];
|
|
585
|
-
try {
|
|
586
|
-
const r = ze({ archive: e, baseUrl: t })(), n = await i.reduce(async (s, o) => await o(await s), r);
|
|
587
|
-
return w.log("Generated manifest", n), n;
|
|
588
|
-
} catch (r) {
|
|
589
|
-
throw w.error(r), r;
|
|
745
|
+
} catch (o) {
|
|
746
|
+
throw m.error(o), o;
|
|
590
747
|
}
|
|
591
|
-
}, rt = async (e, t) => {
|
|
592
|
-
const i = `
|
|
593
|
-
<?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
|
|
594
|
-
<metadata>
|
|
595
|
-
<meta property="rendition:layout">${t?.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
|
|
596
|
-
${t?.useRenditionFlow ? '<meta property="rendition:flow">scrolled-continuous</meta>' : ""}
|
|
597
|
-
</metadata>
|
|
598
|
-
<manifest>
|
|
599
|
-
${e.map(
|
|
600
|
-
(s) => `<item id="${x(s)}" href="${s}" media-type="${O(s)}"/>`
|
|
601
|
-
).join(`
|
|
602
|
-
`)}
|
|
603
|
-
</manifest>
|
|
604
|
-
<spine>
|
|
605
|
-
${e.map((s) => `<itemref idref="${x(s)}" />`).join(`
|
|
606
|
-
`)}
|
|
607
|
-
</spine>
|
|
608
|
-
</package>
|
|
609
|
-
`, r = e.map((s) => ({
|
|
610
|
-
dir: !1,
|
|
611
|
-
basename: x(s),
|
|
612
|
-
encodingFormat: O(s),
|
|
613
|
-
uri: s,
|
|
614
|
-
size: 100 / e.length,
|
|
615
|
-
blob: async () => (await fetch(s)).blob(),
|
|
616
|
-
string: async () => ""
|
|
617
|
-
}));
|
|
618
|
-
return {
|
|
619
|
-
filename: "",
|
|
620
|
-
records: [{
|
|
621
|
-
dir: !1,
|
|
622
|
-
basename: "content.opf",
|
|
623
|
-
uri: "content.opf",
|
|
624
|
-
size: 0,
|
|
625
|
-
blob: async () => new Blob(),
|
|
626
|
-
string: async () => i
|
|
627
|
-
}, ...r],
|
|
628
|
-
close: () => Promise.resolve()
|
|
629
|
-
};
|
|
630
|
-
}, it = async (e, {
|
|
631
|
-
mimeType: t,
|
|
632
|
-
direction: i
|
|
633
|
-
} = { mimeType: "text/plain" }) => {
|
|
634
|
-
const r = `
|
|
635
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
636
|
-
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="ja" prefix="rendition: http://www.idpf.org/vocab/rendition/#"
|
|
637
|
-
unique-identifier="ootuya-id">
|
|
638
|
-
<metadata xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/"
|
|
639
|
-
xmlns:dcterms="http://purl.org/dc/terms/">
|
|
640
|
-
<meta property="rendition:layout">reflowable</meta>
|
|
641
|
-
</metadata>
|
|
642
|
-
<manifest>
|
|
643
|
-
<item id="p01" href="p01.txt" media-type="text/plain"/>
|
|
644
|
-
</manifest>
|
|
645
|
-
<spine page-progression-direction="${i ?? "ltr"}">
|
|
646
|
-
<itemref idref="p01" />
|
|
647
|
-
</spine>
|
|
648
|
-
</package>
|
|
649
|
-
`;
|
|
650
|
-
return {
|
|
651
|
-
filename: "content.txt",
|
|
652
|
-
records: [
|
|
653
|
-
{
|
|
654
|
-
dir: !1,
|
|
655
|
-
basename: x("generated.opf"),
|
|
656
|
-
uri: "generated.opf",
|
|
657
|
-
blob: async () => new Blob([r]),
|
|
658
|
-
string: async () => r,
|
|
659
|
-
size: 0
|
|
660
|
-
},
|
|
661
|
-
{
|
|
662
|
-
dir: !1,
|
|
663
|
-
basename: x("p01.txt"),
|
|
664
|
-
uri: "p01.txt",
|
|
665
|
-
blob: async () => typeof e == "string" ? new Blob([e]) : e,
|
|
666
|
-
string: async () => typeof e == "string" ? e : e.text(),
|
|
667
|
-
size: typeof e == "string" ? e.length : e.size,
|
|
668
|
-
encodingFormat: t
|
|
669
|
-
}
|
|
670
|
-
],
|
|
671
|
-
close: () => Promise.resolve()
|
|
672
|
-
};
|
|
673
|
-
}, st = async (e, { orderByAlpha: t, name: i } = {}) => {
|
|
674
|
-
let r = Object.values(e.files);
|
|
675
|
-
t && (r = r.slice().sort((s, o) => M(s.name, o.name)));
|
|
676
|
-
const n = {
|
|
677
|
-
filename: i || "",
|
|
678
|
-
records: r.map((s) => ({
|
|
679
|
-
dir: s.dir,
|
|
680
|
-
basename: x(s.name),
|
|
681
|
-
uri: s.name,
|
|
682
|
-
blob: () => s.async("blob"),
|
|
683
|
-
string: () => s.async("string"),
|
|
684
|
-
...s.internalStream && {
|
|
685
|
-
stream: s.internalStream
|
|
686
|
-
},
|
|
687
|
-
// this is private API
|
|
688
|
-
// @ts-expect-error
|
|
689
|
-
size: s._data.uncompressedSize
|
|
690
|
-
})),
|
|
691
|
-
close: () => Promise.resolve()
|
|
692
|
-
};
|
|
693
|
-
return w.log("Generated archive", n), n;
|
|
694
|
-
}, ot = async (e, { name: t } = {}) => {
|
|
695
|
-
const i = await e.getFilesArray(), r = {
|
|
696
|
-
close: () => e.close(),
|
|
697
|
-
filename: t ?? "",
|
|
698
|
-
records: i.map((n) => ({
|
|
699
|
-
dir: !1,
|
|
700
|
-
basename: n.file.name,
|
|
701
|
-
size: n.file.size,
|
|
702
|
-
uri: `${n.path}${n.file.name}`,
|
|
703
|
-
blob: async () => await n.file.extract(),
|
|
704
|
-
string: async () => (await n.file.extract()).text()
|
|
705
|
-
}))
|
|
706
|
-
};
|
|
707
|
-
return w.log("Generated archive", r), r;
|
|
708
|
-
}, at = async (e, { orderByAlpha: t, name: i } = {}) => {
|
|
709
|
-
let r = e;
|
|
710
|
-
return t && (r = r.slice().sort((n, s) => M(n.name, s.name))), {
|
|
711
|
-
filename: i || "",
|
|
712
|
-
records: r.map((n) => ({
|
|
713
|
-
dir: n.isDir,
|
|
714
|
-
basename: x(n.name),
|
|
715
|
-
uri: n.name,
|
|
716
|
-
blob: async () => new Blob([await n.data()]),
|
|
717
|
-
string: async () => {
|
|
718
|
-
const s = await n.data();
|
|
719
|
-
return String.fromCharCode.apply(
|
|
720
|
-
null,
|
|
721
|
-
Array.from(new Uint16Array(s))
|
|
722
|
-
);
|
|
723
|
-
},
|
|
724
|
-
size: n.size
|
|
725
|
-
})),
|
|
726
|
-
close: () => Promise.resolve()
|
|
727
|
-
};
|
|
728
|
-
}, ct = ({
|
|
729
|
-
enableReport: e
|
|
730
|
-
} = {}) => {
|
|
731
|
-
w.enable(!!e);
|
|
732
748
|
};
|
|
733
|
-
class
|
|
734
|
-
constructor(
|
|
735
|
-
this.cleanArchiveAfter =
|
|
749
|
+
class Ze {
|
|
750
|
+
constructor(e) {
|
|
751
|
+
this.cleanArchiveAfter = e, this.state$ = new ue({
|
|
736
752
|
status: "idle",
|
|
737
753
|
locks: 0
|
|
738
754
|
});
|
|
739
755
|
}
|
|
740
|
-
update(
|
|
741
|
-
this.state$.next({ ...this.state$.getValue(), ...
|
|
756
|
+
update(e) {
|
|
757
|
+
this.state$.next({ ...this.state$.getValue(), ...e });
|
|
742
758
|
}
|
|
743
759
|
get locks$() {
|
|
744
|
-
return this.state$.pipe(
|
|
760
|
+
return this.state$.pipe(v(({ locks: e }) => e));
|
|
745
761
|
}
|
|
746
762
|
get state() {
|
|
747
763
|
return this.state$.getValue();
|
|
748
764
|
}
|
|
749
765
|
get isUnlocked$() {
|
|
750
766
|
return this.locks$.pipe(
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
767
|
+
v((e) => e <= 0),
|
|
768
|
+
he(),
|
|
769
|
+
ge()
|
|
754
770
|
);
|
|
755
771
|
}
|
|
756
772
|
get overTTL$() {
|
|
757
773
|
return this.isUnlocked$.pipe(
|
|
758
|
-
|
|
759
|
-
(
|
|
774
|
+
A(
|
|
775
|
+
(e) => e ? this.cleanArchiveAfter === 1 / 0 ? H : ye(this.cleanArchiveAfter) : H
|
|
760
776
|
)
|
|
761
777
|
);
|
|
762
778
|
}
|
|
763
779
|
}
|
|
764
|
-
const
|
|
765
|
-
getArchive:
|
|
766
|
-
cleanArchiveAfter:
|
|
780
|
+
const et = ({
|
|
781
|
+
getArchive: n,
|
|
782
|
+
cleanArchiveAfter: e = 300 * 1e3
|
|
767
783
|
// 5mn
|
|
768
784
|
}) => {
|
|
769
|
-
const
|
|
770
|
-
|
|
771
|
-
const
|
|
772
|
-
if (!
|
|
773
|
-
let
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
const
|
|
777
|
-
delete
|
|
785
|
+
const s = new C(), r = new C(), t = new C(), o = {}, i = s.pipe(
|
|
786
|
+
O((c) => {
|
|
787
|
+
const d = o[c];
|
|
788
|
+
if (!d || d.state.status !== "idle") return B;
|
|
789
|
+
let p = !1;
|
|
790
|
+
const g = (h) => {
|
|
791
|
+
m.debug(`Cleaning up archive with key: ${h}`);
|
|
792
|
+
const x = o[h];
|
|
793
|
+
delete o[h], p || (x?.state.archive?.close(), p = !0);
|
|
778
794
|
};
|
|
779
|
-
|
|
795
|
+
d.update({
|
|
780
796
|
status: "loading"
|
|
781
797
|
});
|
|
782
|
-
const
|
|
783
|
-
|
|
784
|
-
R(([
|
|
785
|
-
|
|
798
|
+
const b = d.locks$, E = d.isUnlocked$, u = b.pipe(
|
|
799
|
+
le(),
|
|
800
|
+
R(([h, x]) => x > h),
|
|
801
|
+
pe(!0)
|
|
786
802
|
);
|
|
787
|
-
return
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
archive:
|
|
803
|
+
return T(n(c)).pipe(
|
|
804
|
+
P((h) => {
|
|
805
|
+
d.update({
|
|
806
|
+
archive: h,
|
|
791
807
|
status: "success"
|
|
792
808
|
});
|
|
793
809
|
}),
|
|
794
|
-
|
|
810
|
+
W((h) => (g(c), d.update({
|
|
795
811
|
status: "error",
|
|
796
|
-
error:
|
|
797
|
-
}),
|
|
798
|
-
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
R((
|
|
812
|
+
error: h
|
|
813
|
+
}), B)),
|
|
814
|
+
A(() => {
|
|
815
|
+
const h = u.pipe(
|
|
816
|
+
A(() => t),
|
|
817
|
+
A(() => E),
|
|
818
|
+
R((S) => S)
|
|
803
819
|
);
|
|
804
|
-
return
|
|
820
|
+
return X(h, d.overTTL$).pipe(
|
|
805
821
|
V(),
|
|
806
|
-
|
|
807
|
-
|
|
822
|
+
P(() => {
|
|
823
|
+
g(c);
|
|
808
824
|
})
|
|
809
825
|
);
|
|
810
826
|
})
|
|
811
827
|
);
|
|
812
828
|
}),
|
|
813
|
-
|
|
814
|
-
), a = (
|
|
815
|
-
let
|
|
816
|
-
const
|
|
817
|
-
|
|
818
|
-
locks:
|
|
829
|
+
me(r)
|
|
830
|
+
), a = (c) => {
|
|
831
|
+
let d = !1;
|
|
832
|
+
const p = o[c] ?? new Ze(e);
|
|
833
|
+
o[c] = p, p.update({
|
|
834
|
+
locks: p.state.locks + 1
|
|
819
835
|
});
|
|
820
|
-
const
|
|
821
|
-
|
|
822
|
-
locks:
|
|
836
|
+
const g = () => {
|
|
837
|
+
d || (d = !0, p.update({
|
|
838
|
+
locks: p.state.locks - 1
|
|
823
839
|
}));
|
|
824
840
|
};
|
|
825
|
-
|
|
826
|
-
const
|
|
827
|
-
|
|
841
|
+
s.next(c);
|
|
842
|
+
const b = p.state$.pipe(
|
|
843
|
+
v(({ archive: u }) => u),
|
|
828
844
|
R((u) => !!u)
|
|
829
|
-
),
|
|
830
|
-
|
|
845
|
+
), E = p.state$.pipe(
|
|
846
|
+
P(({ error: u }) => {
|
|
831
847
|
if (u)
|
|
832
848
|
throw u;
|
|
833
849
|
}),
|
|
834
|
-
|
|
850
|
+
fe()
|
|
835
851
|
);
|
|
836
|
-
return
|
|
852
|
+
return X(b, E).pipe(
|
|
837
853
|
V(),
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
throw
|
|
854
|
+
v((u) => ({ archive: u, release: g })),
|
|
855
|
+
W((u) => {
|
|
856
|
+
throw g(), u;
|
|
841
857
|
})
|
|
842
858
|
);
|
|
843
|
-
},
|
|
844
|
-
|
|
859
|
+
}, l = () => {
|
|
860
|
+
t.next();
|
|
845
861
|
};
|
|
846
|
-
return
|
|
862
|
+
return i.subscribe(), {
|
|
847
863
|
access: a,
|
|
848
|
-
purge:
|
|
849
|
-
_archives:
|
|
864
|
+
purge: l,
|
|
865
|
+
_archives: o
|
|
850
866
|
};
|
|
851
867
|
};
|
|
852
|
-
class
|
|
868
|
+
class tt {
|
|
853
869
|
constructor({
|
|
854
|
-
onError:
|
|
855
|
-
onManifestSuccess:
|
|
870
|
+
onError: e,
|
|
871
|
+
onManifestSuccess: s,
|
|
856
872
|
...r
|
|
857
873
|
}) {
|
|
858
|
-
this.onError = (
|
|
874
|
+
this.onError = (t) => (console.error(t), new Response(String(t), { status: 500 })), this.epubLoader = et(r), this.onManifestSuccess = s ?? (({ manifest: t }) => Promise.resolve(t)), this.onError = e ?? this.onError;
|
|
859
875
|
}
|
|
860
876
|
prune() {
|
|
861
877
|
this.epubLoader.purge();
|
|
862
878
|
}
|
|
863
|
-
accessArchive(
|
|
864
|
-
return this.lastAccessedKey !== void 0 && this.lastAccessedKey !==
|
|
879
|
+
accessArchive(e) {
|
|
880
|
+
return this.lastAccessedKey !== void 0 && this.lastAccessedKey !== e && this.epubLoader.purge(), this.lastAccessedKey = e, this.epubLoader.access(e);
|
|
865
881
|
}
|
|
866
|
-
accessArchiveWithoutLock(
|
|
867
|
-
return this.accessArchive(
|
|
868
|
-
|
|
882
|
+
accessArchiveWithoutLock(e) {
|
|
883
|
+
return this.accessArchive(e).pipe(
|
|
884
|
+
v(({ archive: s, release: r }) => (r(), s))
|
|
869
885
|
);
|
|
870
886
|
}
|
|
871
|
-
fetchManifest({ key:
|
|
872
|
-
const r = this.accessArchive(
|
|
873
|
-
|
|
874
|
-
|
|
887
|
+
fetchManifest({ key: e, baseUrl: s }) {
|
|
888
|
+
const r = this.accessArchive(e).pipe(
|
|
889
|
+
O(({ archive: t, release: o }) => T(
|
|
890
|
+
Be(t, { baseUrl: s })
|
|
875
891
|
).pipe(
|
|
876
|
-
|
|
877
|
-
(a) =>
|
|
892
|
+
A(
|
|
893
|
+
(a) => T(this.onManifestSuccess({ manifest: a, archive: t }))
|
|
878
894
|
),
|
|
879
|
-
|
|
895
|
+
v(
|
|
880
896
|
(a) => new Response(JSON.stringify(a), {
|
|
881
897
|
status: 200
|
|
882
898
|
})
|
|
883
899
|
),
|
|
884
|
-
|
|
885
|
-
|
|
900
|
+
_(() => {
|
|
901
|
+
o();
|
|
886
902
|
})
|
|
887
903
|
)),
|
|
888
|
-
|
|
904
|
+
W((t) => G(this.onError(t)))
|
|
889
905
|
);
|
|
890
|
-
return
|
|
906
|
+
return q(r);
|
|
891
907
|
}
|
|
892
908
|
fetchResource({
|
|
893
|
-
key:
|
|
894
|
-
resourcePath:
|
|
909
|
+
key: e,
|
|
910
|
+
resourcePath: s
|
|
895
911
|
}) {
|
|
896
|
-
const r = this.accessArchive(
|
|
897
|
-
|
|
898
|
-
const
|
|
899
|
-
return
|
|
900
|
-
|
|
912
|
+
const r = this.accessArchive(e).pipe(
|
|
913
|
+
O(({ archive: t, release: o }) => {
|
|
914
|
+
const i = s.replaceAll("file://", "");
|
|
915
|
+
return T(
|
|
916
|
+
Qe(t, i)
|
|
901
917
|
).pipe(
|
|
902
|
-
|
|
903
|
-
(
|
|
918
|
+
v(
|
|
919
|
+
(l) => new Response(l.body, {
|
|
904
920
|
status: 200,
|
|
905
921
|
headers: {
|
|
906
|
-
...
|
|
907
|
-
"Content-Type":
|
|
922
|
+
...l.params.contentType && {
|
|
923
|
+
"Content-Type": l.params.contentType
|
|
908
924
|
}
|
|
909
925
|
}
|
|
910
926
|
})
|
|
911
927
|
),
|
|
912
|
-
|
|
913
|
-
|
|
928
|
+
_(() => {
|
|
929
|
+
o();
|
|
914
930
|
})
|
|
915
931
|
);
|
|
916
932
|
}),
|
|
917
|
-
|
|
933
|
+
W((t) => G(this.onError(t)))
|
|
918
934
|
);
|
|
919
|
-
return
|
|
935
|
+
return q(r);
|
|
920
936
|
}
|
|
921
937
|
}
|
|
922
|
-
class
|
|
938
|
+
class mt extends tt {
|
|
923
939
|
constructor({
|
|
924
|
-
getUriInfo:
|
|
925
|
-
...
|
|
940
|
+
getUriInfo: e,
|
|
941
|
+
...s
|
|
926
942
|
}) {
|
|
927
|
-
super(
|
|
943
|
+
super(s), this.getUriInfo = e, this.fetchEventListener = this.fetchEventListener.bind(this);
|
|
928
944
|
}
|
|
929
|
-
fetchEventListener(
|
|
945
|
+
fetchEventListener(e) {
|
|
930
946
|
try {
|
|
931
|
-
const
|
|
932
|
-
if (!
|
|
933
|
-
const r = J(
|
|
947
|
+
const s = this.getUriInfo(e);
|
|
948
|
+
if (!s) return;
|
|
949
|
+
const r = J(s.baseUrl), t = e.request.url.substring(
|
|
934
950
|
r.length + 1
|
|
935
|
-
), [
|
|
936
|
-
J(
|
|
951
|
+
), [o = ""] = t.split("/"), i = decodeURIComponent(
|
|
952
|
+
J(t.substring(o.length + 1))
|
|
937
953
|
);
|
|
938
|
-
|
|
939
|
-
this.fetchManifest({ key:
|
|
940
|
-
) :
|
|
941
|
-
} catch (
|
|
942
|
-
|
|
954
|
+
t.endsWith("/manifest") ? e.respondWith(
|
|
955
|
+
this.fetchManifest({ key: o, baseUrl: `${r}/${o}/` })
|
|
956
|
+
) : e.respondWith(this.fetchResource({ key: o, resourcePath: i }));
|
|
957
|
+
} catch (s) {
|
|
958
|
+
e.respondWith(new Response(String(s), { status: 500 }));
|
|
943
959
|
}
|
|
944
960
|
}
|
|
945
961
|
}
|
|
946
962
|
export {
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
963
|
+
mt as ServiceWorkerStreamer,
|
|
964
|
+
tt as Streamer,
|
|
965
|
+
pt as configure,
|
|
966
|
+
it as createArchiveFromArrayBufferList,
|
|
967
|
+
at as createArchiveFromJszip,
|
|
968
|
+
ct as createArchiveFromLibArchive,
|
|
969
|
+
dt as createArchiveFromText,
|
|
970
|
+
lt as createArchiveFromUrls,
|
|
971
|
+
Be as generateManifestFromArchive,
|
|
972
|
+
Qe as generateResourceFromArchive,
|
|
973
|
+
F as getArchiveOpfInfo,
|
|
974
|
+
be as getUriBasePath,
|
|
975
|
+
$ as getUriBasename,
|
|
960
976
|
J as removeTrailingSlash,
|
|
961
|
-
|
|
977
|
+
D as sortByTitleComparator
|
|
962
978
|
};
|
|
963
979
|
//# sourceMappingURL=index.js.map
|