@prose-reader/archive-reader 1.320.0 → 1.322.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/README.md +9 -10
- package/dist/archives/createArchive.d.ts +4 -0
- package/dist/archives/createArchiveFromArrayBufferList.d.ts +11 -0
- package/dist/archives/createArchiveFromEntries.d.ts +16 -0
- package/dist/archives/createArchiveFromJszip/index.cjs +2 -0
- package/dist/archives/createArchiveFromJszip/index.cjs.map +1 -0
- package/dist/archives/createArchiveFromJszip/index.js +19 -0
- package/dist/archives/createArchiveFromJszip/index.js.map +1 -0
- package/dist/archives/createArchiveFromJszip.d.ts +7 -0
- package/dist/archives/createArchiveFromLibArchive/index.cjs +2 -0
- package/dist/archives/createArchiveFromLibArchive/index.cjs.map +1 -0
- package/dist/archives/createArchiveFromLibArchive/index.js +16 -0
- package/dist/archives/createArchiveFromLibArchive/index.js.map +1 -0
- package/dist/archives/createArchiveFromLibArchive.d.ts +7 -0
- package/dist/archives/createArchiveFromNodeUnrarJs/index.cjs +2 -0
- package/dist/archives/createArchiveFromNodeUnrarJs/index.cjs.map +1 -0
- package/dist/archives/createArchiveFromNodeUnrarJs/index.js +27 -0
- package/dist/archives/createArchiveFromNodeUnrarJs/index.js.map +1 -0
- package/dist/archives/createArchiveFromNodeUnrarJs.d.ts +7 -0
- package/dist/archives/createArchiveFromText.d.ts +4 -0
- package/dist/archives/createArchiveFromUnzipper/index.cjs +2 -0
- package/dist/archives/createArchiveFromUnzipper/index.cjs.map +1 -0
- package/dist/archives/createArchiveFromUnzipper/index.js +23 -0
- package/dist/archives/createArchiveFromUnzipper/index.js.map +1 -0
- package/dist/archives/createArchiveFromUnzipper.d.ts +7 -0
- package/dist/archives/createArchiveFromUrls.d.ts +4 -0
- package/dist/archives/createArchiveFromZipJs/index.cjs +2 -0
- package/dist/archives/createArchiveFromZipJs/index.cjs.map +1 -0
- package/dist/archives/createArchiveFromZipJs/index.js +20 -0
- package/dist/archives/createArchiveFromZipJs/index.js.map +1 -0
- package/dist/archives/createArchiveFromZipJs.d.ts +7 -0
- package/dist/archives/fileAccessors.d.ts +5 -0
- package/dist/archives/printTree.d.ts +1 -0
- package/dist/archives/readRecordAsText.d.ts +2 -0
- package/dist/archives/types.d.ts +25 -0
- package/dist/comicInfo/getArchiveHasComicInfo.d.ts +2 -0
- package/dist/createArchiveFromEntries-Bal1_O58.js +58 -0
- package/dist/createArchiveFromEntries-Bal1_O58.js.map +1 -0
- package/dist/createArchiveFromEntries-Du93RwlN.cjs +3 -0
- package/dist/createArchiveFromEntries-Du93RwlN.cjs.map +1 -0
- package/dist/fileAccessors-DWVChFUB.cjs +2 -0
- package/dist/fileAccessors-DWVChFUB.cjs.map +1 -0
- package/dist/fileAccessors-etcCPnpQ.js +12 -0
- package/dist/fileAccessors-etcCPnpQ.js.map +1 -0
- package/dist/index/index.cjs +32 -0
- package/dist/index/index.cjs.map +1 -0
- package/dist/index/index.js +519 -0
- package/dist/index/index.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/opf/getArchiveOpfInfo.d.ts +5 -0
- package/dist/opf/getSpineItemFilesFromArchive.d.ts +6 -0
- package/dist/opf/isArchiveEpub.d.ts +2 -0
- package/dist/opf/readArchiveOpf.d.ts +7 -0
- package/dist/report.d.ts +2 -0
- package/dist/toc/folders.d.ts +3 -0
- package/dist/toc/nav.d.ts +4 -0
- package/dist/toc/ncx.d.ts +8 -0
- package/dist/toc/resolveArchiveToc.d.ts +6 -0
- package/dist/toc/resolveArchiveToc.test.d.ts +1 -0
- package/dist/toc/types.d.ts +6 -0
- package/dist/utils/getXmlElementInnerText.d.ts +2 -0
- package/package.json +70 -6
- package/dist/index.js +0 -313
- package/dist/index.js.map +0 -1
- package/dist/index.umd.cjs +0 -2
- package/dist/index.umd.cjs.map +0 -1
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
import { n as e, t } from "../createArchiveFromEntries-Bal1_O58.js";
|
|
2
|
+
import { n, t as r } from "../fileAccessors-etcCPnpQ.js";
|
|
3
|
+
import { XmlDocument as i, XmlElement as a, XmlTextNode as o } from "xmldoc";
|
|
4
|
+
import { createXmlSafeIdFactory as s, detectMimeTypeFromName as c, escapeXmlAttributeValue as l, getUriBasePath as u, getUriBasename as d, sortByTitleComparator as f, urlJoin as p } from "@prose-reader/shared";
|
|
5
|
+
//#region src/apple/parse.ts
|
|
6
|
+
var m = "com.apple.ibooks.display-options.xml", h = (e) => e.childrenNamed("option").map((e) => ({
|
|
7
|
+
name: e.attr?.name,
|
|
8
|
+
value: e.val
|
|
9
|
+
})), g = (e) => {
|
|
10
|
+
let t = new i(e);
|
|
11
|
+
if (t.name?.toLowerCase() !== "display_options") return { kind: "apple" };
|
|
12
|
+
let n = t.childNamed("platform");
|
|
13
|
+
return {
|
|
14
|
+
kind: "apple",
|
|
15
|
+
displayOptions: { ...n === void 0 ? {} : { platform: { options: h(n) } } }
|
|
16
|
+
};
|
|
17
|
+
}, _ = async (e, n = {}) => t(e, (e) => e.isDir ? {
|
|
18
|
+
dir: !0,
|
|
19
|
+
uri: e.name
|
|
20
|
+
} : {
|
|
21
|
+
dir: !1,
|
|
22
|
+
uri: e.name,
|
|
23
|
+
size: e.size,
|
|
24
|
+
...r(e.data, c(e.name) ?? "")
|
|
25
|
+
}, {
|
|
26
|
+
...n,
|
|
27
|
+
close: () => Promise.resolve()
|
|
28
|
+
}), v = async (t, { mimeType: r, direction: i } = { mimeType: "text/plain" }) => {
|
|
29
|
+
let a = `
|
|
30
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
31
|
+
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="ja" prefix="rendition: http://www.idpf.org/vocab/rendition/#"
|
|
32
|
+
unique-identifier="ootuya-id">
|
|
33
|
+
<metadata xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/"
|
|
34
|
+
xmlns:dcterms="http://purl.org/dc/terms/">
|
|
35
|
+
<meta property="rendition:layout">reflowable</meta>
|
|
36
|
+
</metadata>
|
|
37
|
+
<manifest>
|
|
38
|
+
<item id="p01" href="p01.txt" media-type="text/plain"/>
|
|
39
|
+
</manifest>
|
|
40
|
+
<spine page-progression-direction="${i ?? "ltr"}">
|
|
41
|
+
<itemref idref="p01" />
|
|
42
|
+
</spine>
|
|
43
|
+
</package>
|
|
44
|
+
`;
|
|
45
|
+
return e({
|
|
46
|
+
filename: "content.txt",
|
|
47
|
+
encodingFormat: r,
|
|
48
|
+
records: [{
|
|
49
|
+
dir: !1,
|
|
50
|
+
basename: d("generated.opf"),
|
|
51
|
+
uri: "generated.opf",
|
|
52
|
+
size: 0,
|
|
53
|
+
...n(async () => new Blob([a]))
|
|
54
|
+
}, {
|
|
55
|
+
dir: !1,
|
|
56
|
+
basename: d("p01.txt"),
|
|
57
|
+
uri: "p01.txt",
|
|
58
|
+
size: typeof t == "string" ? new Blob([t]).size : t.size,
|
|
59
|
+
encodingFormat: r,
|
|
60
|
+
...n(async () => typeof t == "string" ? new Blob([t]) : t)
|
|
61
|
+
}],
|
|
62
|
+
close: () => Promise.resolve()
|
|
63
|
+
});
|
|
64
|
+
}, y = async (t, r) => {
|
|
65
|
+
let i = s(), a = t.map((e) => ({
|
|
66
|
+
id: i(e),
|
|
67
|
+
url: e
|
|
68
|
+
})), o = `
|
|
69
|
+
<?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
|
|
70
|
+
<metadata>
|
|
71
|
+
<meta property="rendition:layout">${r?.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
|
|
72
|
+
${r?.useRenditionFlow ? "<meta property=\"rendition:flow\">scrolled-continuous</meta>" : ""}
|
|
73
|
+
</metadata>
|
|
74
|
+
<manifest>
|
|
75
|
+
${a.map(({ id: e, url: t }) => {
|
|
76
|
+
let n = c(t);
|
|
77
|
+
return `<item id="${e}" href="${l(t)}" media-type="${l(n ?? "")}"/>`;
|
|
78
|
+
}).join("\n")}
|
|
79
|
+
</manifest>
|
|
80
|
+
<spine>
|
|
81
|
+
${a.map(({ id: e }) => `<itemref idref="${e}" />`).join("\n")}
|
|
82
|
+
</spine>
|
|
83
|
+
</package>
|
|
84
|
+
`, u = t.map((e) => ({
|
|
85
|
+
dir: !1,
|
|
86
|
+
basename: d(e),
|
|
87
|
+
encodingFormat: c(e),
|
|
88
|
+
uri: e,
|
|
89
|
+
size: 0,
|
|
90
|
+
...n(async () => (await fetch(e)).blob())
|
|
91
|
+
}));
|
|
92
|
+
return e({
|
|
93
|
+
records: [{
|
|
94
|
+
dir: !1,
|
|
95
|
+
basename: "content.opf",
|
|
96
|
+
uri: "content.opf",
|
|
97
|
+
size: 0,
|
|
98
|
+
...n(async () => new Blob([o]))
|
|
99
|
+
}, ...u],
|
|
100
|
+
close: () => Promise.resolve()
|
|
101
|
+
});
|
|
102
|
+
}, b = async (e) => new TextDecoder().decode(await e.arrayBuffer()), x = (e) => !e.dir, S = (e) => e.dir, C = (e, t) => {
|
|
103
|
+
let n = e.recordsByUri.get(t);
|
|
104
|
+
return n && x(n) ? n : void 0;
|
|
105
|
+
}, w = "ComicInfo.xml", ee = /* @__PURE__ */ new Set(["Pages", "ComicInfo"]), te = (e) => e.children.some((e) => e.type === "element"), ne = (e) => {
|
|
106
|
+
let t = e.val.trim();
|
|
107
|
+
return t.length > 0 ? t : void 0;
|
|
108
|
+
}, re = (e) => {
|
|
109
|
+
let t;
|
|
110
|
+
try {
|
|
111
|
+
t = new i(e);
|
|
112
|
+
} catch (e) {
|
|
113
|
+
let t = e instanceof Error ? e.message : String(e);
|
|
114
|
+
throw Error(`${w} is malformed: ${t}`, { cause: e });
|
|
115
|
+
}
|
|
116
|
+
let n = {};
|
|
117
|
+
return t.eachChild((e) => {
|
|
118
|
+
if (e.type !== "element" || ee.has(e.name) || te(e)) return;
|
|
119
|
+
let t = ne(e);
|
|
120
|
+
t !== void 0 && n[e.name] === void 0 && (n[e.name] = t);
|
|
121
|
+
}), {
|
|
122
|
+
kind: "comicInfo",
|
|
123
|
+
...n
|
|
124
|
+
};
|
|
125
|
+
}, ie = w.toLowerCase(), ae = (e) => e.records.find((e) => x(e) && e.basename.toLowerCase() === ie), T = [
|
|
126
|
+
"Unknown",
|
|
127
|
+
"No",
|
|
128
|
+
"Yes",
|
|
129
|
+
"YesAndRightToLeft"
|
|
130
|
+
], E = (e) => {
|
|
131
|
+
for (let t of T) if (t === e) return !0;
|
|
132
|
+
return !1;
|
|
133
|
+
}, oe = "com.kobobooks.display-options.xml", se = (e) => {
|
|
134
|
+
let t = e.childNamed("platform");
|
|
135
|
+
if (!t) return {};
|
|
136
|
+
for (let e of t.childrenNamed("option")) if (e.attr?.name === "fixed-layout") return e.val.trim().toLowerCase() === "true" ? { renditionLayout: "pre-paginated" } : {};
|
|
137
|
+
return {};
|
|
138
|
+
}, ce = (e) => {
|
|
139
|
+
let t = new i(e);
|
|
140
|
+
return t.name?.toLowerCase() === "display_options" ? {
|
|
141
|
+
kind: "kobo",
|
|
142
|
+
...se(t)
|
|
143
|
+
} : { kind: "kobo" };
|
|
144
|
+
}, D = (e) => {
|
|
145
|
+
let t = e.records.filter((e) => !e.dir).find((e) => e.uri.endsWith(".opf"));
|
|
146
|
+
return {
|
|
147
|
+
data: t,
|
|
148
|
+
basePath: t?.uri.substring(0, t.uri.lastIndexOf("/")) || ""
|
|
149
|
+
};
|
|
150
|
+
}, le = async ({ archive: e, archiveOpf: t }) => {
|
|
151
|
+
if (!t) return [];
|
|
152
|
+
let { opf: n, basePath: r } = t, { spineRows: i } = n;
|
|
153
|
+
return e.records.filter((e) => i.find((t) => r ? `${r}/${t.href}` === e.uri : `${t.href}` === e.uri));
|
|
154
|
+
}, O = (e) => e.toLowerCase().endsWith(".opf"), ue = (e) => e.records.some((e) => !e.dir && (O(e.basename) || O(e.uri))), k = (e) => e === void 0 || e.trim().length === 0 ? [] : e.trim().split(/\s+/).filter((e) => e.length > 0), A = (e) => {
|
|
155
|
+
let t = k(e);
|
|
156
|
+
if (t.length === 0) return {};
|
|
157
|
+
let n;
|
|
158
|
+
t.includes("rendition:layout-reflowable") && (n = "reflowable"), t.includes("rendition:layout-pre-paginated") && (n = "pre-paginated");
|
|
159
|
+
let r;
|
|
160
|
+
return t.includes("rendition:flow-auto") && (r = "auto"), t.includes("rendition:flow-paginated") && (r = "paginated"), t.includes("rendition:flow-scrolled-doc") && (r = "scrolled-doc"), t.includes("rendition:flow-scrolled-continuous") && (r = "scrolled-continuous"), {
|
|
161
|
+
...n === void 0 ? {} : { renditionLayout: n },
|
|
162
|
+
...r === void 0 ? {} : { renditionFlow: r },
|
|
163
|
+
...t.includes("page-spread-left") ? { pageSpreadLeft: !0 } : {},
|
|
164
|
+
...t.includes("page-spread-right") ? { pageSpreadRight: !0 } : {}
|
|
165
|
+
};
|
|
166
|
+
}, j = (e) => e.includes(":") ? e.slice(e.lastIndexOf(":") + 1) : e, M = (e, t) => j(e).toLowerCase() === t.toLowerCase(), N = (e) => e.type === "element", P = (e, t) => {
|
|
167
|
+
for (let n of e.children) if (N(n) && M(n.name, t)) return n;
|
|
168
|
+
}, F = (e, t) => {
|
|
169
|
+
let n = [];
|
|
170
|
+
for (let r of e.children) N(r) && M(r.name, t) && n.push(r);
|
|
171
|
+
return n;
|
|
172
|
+
}, de = (e) => {
|
|
173
|
+
let t = [];
|
|
174
|
+
return e.eachChild((e) => {
|
|
175
|
+
if (j(e.name).toLowerCase() !== "identifier") return;
|
|
176
|
+
let n = e.val.trim();
|
|
177
|
+
if (n.length === 0) return;
|
|
178
|
+
let r = (e.attr["opf:scheme"] ?? e.attr["opf:Scheme"] ?? e.attr.scheme)?.trim();
|
|
179
|
+
t.push({
|
|
180
|
+
value: n,
|
|
181
|
+
...r !== void 0 && r.length > 0 ? { scheme: r } : {}
|
|
182
|
+
});
|
|
183
|
+
}), t;
|
|
184
|
+
}, I = (e, t) => {
|
|
185
|
+
let n;
|
|
186
|
+
return e.eachChild((e) => {
|
|
187
|
+
if (n !== void 0 || j(e.name).toLowerCase() !== t.toLowerCase()) return;
|
|
188
|
+
let r = e.val.trim();
|
|
189
|
+
r.length > 0 && (n = r);
|
|
190
|
+
}), n;
|
|
191
|
+
}, L = (e, t) => {
|
|
192
|
+
let n = [];
|
|
193
|
+
return e.eachChild((e) => {
|
|
194
|
+
if (j(e.name).toLowerCase() !== t.toLowerCase()) return;
|
|
195
|
+
let r = e.val.trim();
|
|
196
|
+
r.length > 0 && n.push(r);
|
|
197
|
+
}), n;
|
|
198
|
+
}, R = (e) => {
|
|
199
|
+
let t;
|
|
200
|
+
return e.eachChild((e) => {
|
|
201
|
+
if (t !== void 0 || j(e.name).toLowerCase() !== "meta" || e.attr.name?.toLowerCase() !== "cover") return;
|
|
202
|
+
let n = e.attr.content?.trim();
|
|
203
|
+
n !== void 0 && n.length > 0 && (t = n);
|
|
204
|
+
}), t;
|
|
205
|
+
}, z = ({ manifestItems: e, metadataEl: t }) => {
|
|
206
|
+
let n = (e) => e.mediaType?.toLowerCase().includes("image/") === !0, r = e.find((e) => n(e) ? k(e.properties).includes("cover-image") : !1);
|
|
207
|
+
if (r !== void 0) return r.href;
|
|
208
|
+
if (t !== void 0) {
|
|
209
|
+
let r = R(t);
|
|
210
|
+
if (r !== void 0) {
|
|
211
|
+
let t = e.find((e) => e.id === r && n(e));
|
|
212
|
+
if (t !== void 0) return t.href;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return e.find((e) => e.id.toLowerCase().includes("cover") && n(e))?.href;
|
|
216
|
+
}, B = (e, t) => {
|
|
217
|
+
let n = F(e, "meta").find((e) => e.attr.property === t)?.val;
|
|
218
|
+
if (!(n === void 0 || n.trim().length === 0)) return n;
|
|
219
|
+
}, V = (e) => {
|
|
220
|
+
let t = P(e, "guide");
|
|
221
|
+
if (t === void 0) return [];
|
|
222
|
+
let n = [];
|
|
223
|
+
for (let e of F(t, "reference")) {
|
|
224
|
+
let t = e.attr.href?.trim();
|
|
225
|
+
t === void 0 || t.length === 0 || n.push({
|
|
226
|
+
href: t,
|
|
227
|
+
title: e.attr.title?.trim() ?? "",
|
|
228
|
+
type: e.attr.type?.trim() ?? ""
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return n;
|
|
232
|
+
}, H = (e) => {
|
|
233
|
+
let t = e.attr.id, n = e.attr.href;
|
|
234
|
+
if (t === void 0 || t.length === 0 || n === void 0 || n.length === 0) return;
|
|
235
|
+
let r = e.attr["media-type"], i = e.attr.properties?.trim();
|
|
236
|
+
return {
|
|
237
|
+
id: t,
|
|
238
|
+
href: n,
|
|
239
|
+
...r !== void 0 && r.length > 0 ? { mediaType: r } : {},
|
|
240
|
+
...i !== void 0 && i.length > 0 ? { properties: i } : {}
|
|
241
|
+
};
|
|
242
|
+
}, fe = (e) => {
|
|
243
|
+
let t = [], n = /* @__PURE__ */ new Map();
|
|
244
|
+
for (let r of F(e, "item")) {
|
|
245
|
+
let e = H(r);
|
|
246
|
+
e !== void 0 && (t.push(e), n.set(e.id, e));
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
items: t,
|
|
250
|
+
byId: n
|
|
251
|
+
};
|
|
252
|
+
}, pe = (e, t) => {
|
|
253
|
+
let n = [];
|
|
254
|
+
for (let r of F(t, "itemref")) {
|
|
255
|
+
let t = r.attr.idref;
|
|
256
|
+
if (t === void 0 || t.trim().length === 0) continue;
|
|
257
|
+
let i = e.get(t);
|
|
258
|
+
if (i === void 0) continue;
|
|
259
|
+
let a = A(r.attr.properties);
|
|
260
|
+
n.push({
|
|
261
|
+
idref: t,
|
|
262
|
+
id: i.id,
|
|
263
|
+
href: i.href,
|
|
264
|
+
...i.mediaType === void 0 ? {} : { mediaType: i.mediaType },
|
|
265
|
+
...i.properties === void 0 ? {} : { properties: i.properties },
|
|
266
|
+
...a.renditionLayout === void 0 ? {} : { renditionLayout: a.renditionLayout },
|
|
267
|
+
...a.renditionFlow === void 0 ? {} : { renditionFlow: a.renditionFlow },
|
|
268
|
+
...a.pageSpreadLeft === void 0 ? {} : { pageSpreadLeft: a.pageSpreadLeft },
|
|
269
|
+
...a.pageSpreadRight === void 0 ? {} : { pageSpreadRight: a.pageSpreadRight }
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
return n;
|
|
273
|
+
}, U = (e) => {
|
|
274
|
+
let t = new i(e), n = P(t, "manifest"), r = P(t, "spine"), a = P(t, "metadata"), o = [], s = [];
|
|
275
|
+
if (n !== void 0) {
|
|
276
|
+
let { items: e, byId: t } = fe(n);
|
|
277
|
+
o = e, r !== void 0 && (s = pe(t, r));
|
|
278
|
+
}
|
|
279
|
+
let c = r?.attr["page-progression-direction"], l = c !== void 0 && c.trim().length > 0 ? c : void 0, u = r?.attr.toc, d = u !== void 0 && u.trim().length > 0 ? u.trim() : void 0, f, p, m, h, g = [], _ = [], v = [], y, b, x, S = [];
|
|
280
|
+
a !== void 0 && (f = I(a, "title"), p = I(a, "publisher"), m = I(a, "rights"), h = I(a, "date"), g = L(a, "creator"), _ = L(a, "language"), v = L(a, "subject"), y = B(a, "rendition:layout"), b = B(a, "rendition:flow"), x = B(a, "rendition:spread"), S.push(...de(a)));
|
|
281
|
+
let C = z({
|
|
282
|
+
manifestItems: o,
|
|
283
|
+
metadataEl: a
|
|
284
|
+
}), w = V(t);
|
|
285
|
+
return {
|
|
286
|
+
kind: "opf",
|
|
287
|
+
manifestItems: o,
|
|
288
|
+
spineRows: s,
|
|
289
|
+
spineTocIdref: d,
|
|
290
|
+
identifiers: S,
|
|
291
|
+
title: f,
|
|
292
|
+
creators: g,
|
|
293
|
+
publisher: p,
|
|
294
|
+
rights: m,
|
|
295
|
+
languages: _,
|
|
296
|
+
subjects: v,
|
|
297
|
+
date: h,
|
|
298
|
+
coverHref: C,
|
|
299
|
+
renditionLayoutMeta: y,
|
|
300
|
+
renditionFlowMeta: b,
|
|
301
|
+
renditionSpreadMeta: x,
|
|
302
|
+
pageProgressionDirection: l,
|
|
303
|
+
guide: w
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/opf/readArchiveOpf.ts
|
|
308
|
+
async function W(e) {
|
|
309
|
+
let { data: t, basePath: n } = D(e) || {};
|
|
310
|
+
if (!(!t || t.dir)) return {
|
|
311
|
+
opf: U(await b(t)),
|
|
312
|
+
basePath: n
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/apple/resolve.ts
|
|
317
|
+
var me = (e) => ({
|
|
318
|
+
gtin: void 0,
|
|
319
|
+
isbn: void 0,
|
|
320
|
+
readingDirection: void 0,
|
|
321
|
+
renditionLayout: (e.displayOptions?.platform?.options?.find((e) => e.name === "fixed-layout")?.value)?.trim().toLowerCase() === "true" ? "pre-paginated" : void 0,
|
|
322
|
+
title: void 0,
|
|
323
|
+
authors: void 0,
|
|
324
|
+
publisher: void 0,
|
|
325
|
+
rights: void 0,
|
|
326
|
+
languages: void 0,
|
|
327
|
+
date: void 0,
|
|
328
|
+
subjects: void 0
|
|
329
|
+
}), he = /* @__PURE__ */ new Set([
|
|
330
|
+
8,
|
|
331
|
+
12,
|
|
332
|
+
13,
|
|
333
|
+
14
|
|
334
|
+
]), G = (e) => {
|
|
335
|
+
if (e == null) return;
|
|
336
|
+
let t = String(e).replace(/\D/g, "");
|
|
337
|
+
if (!(t.length === 0 || !he.has(t.length))) return t;
|
|
338
|
+
}, ge = /(?:97[89])?\d{9}[\dXx]/, K = (e) => {
|
|
339
|
+
if (e == null) return;
|
|
340
|
+
let t = String(e).trim().replace(/^urn:isbn:/i, "").replace(/^isbn[:\s-]*/i, ""), n = t.replace(/[^0-9Xx]/g, "");
|
|
341
|
+
if (n.length === 10 || n.length === 13) return n.toUpperCase();
|
|
342
|
+
let r = t.match(ge);
|
|
343
|
+
if (r) return r[0].toUpperCase();
|
|
344
|
+
}, _e = (e) => {
|
|
345
|
+
switch (e.Manga) {
|
|
346
|
+
case "YesAndRightToLeft": return "rtl";
|
|
347
|
+
case "Yes":
|
|
348
|
+
case "No": return "ltr";
|
|
349
|
+
default: return;
|
|
350
|
+
}
|
|
351
|
+
}, q = (e) => {
|
|
352
|
+
if (e === void 0) return;
|
|
353
|
+
let t = e.trim();
|
|
354
|
+
return t.length > 0 ? t : void 0;
|
|
355
|
+
}, J = (e) => e === void 0 ? [] : e.split(",").map((e) => e.trim()).filter((e) => e.length > 0), Y = (e) => {
|
|
356
|
+
let t = q(e);
|
|
357
|
+
if (t === void 0 || !/^\d+$/.test(t)) return;
|
|
358
|
+
let n = Number.parseInt(t, 10);
|
|
359
|
+
return Number.isFinite(n) ? n : void 0;
|
|
360
|
+
}, ve = (e) => {
|
|
361
|
+
let t = Y(e.Year), n = Y(e.Month), r = Y(e.Day);
|
|
362
|
+
if (!(t === void 0 && n === void 0 && r === void 0)) return {
|
|
363
|
+
...t === void 0 ? {} : { year: t },
|
|
364
|
+
...n === void 0 ? {} : { month: n },
|
|
365
|
+
...r === void 0 ? {} : { day: r }
|
|
366
|
+
};
|
|
367
|
+
}, ye = (e) => {
|
|
368
|
+
let t = e.GTIN, n = q(e.LanguageISO), r = J(e.Writer), i = [...J(e.Genre), ...J(e.Tags)];
|
|
369
|
+
return {
|
|
370
|
+
gtin: G(t),
|
|
371
|
+
isbn: K(t),
|
|
372
|
+
readingDirection: _e(e),
|
|
373
|
+
renditionLayout: void 0,
|
|
374
|
+
title: q(e.Title),
|
|
375
|
+
authors: r.length > 0 ? r : void 0,
|
|
376
|
+
publisher: q(e.Publisher),
|
|
377
|
+
rights: void 0,
|
|
378
|
+
languages: n === void 0 ? void 0 : [n],
|
|
379
|
+
date: ve(e),
|
|
380
|
+
subjects: i.length > 0 ? i : void 0
|
|
381
|
+
};
|
|
382
|
+
}, be = (e) => ({
|
|
383
|
+
gtin: void 0,
|
|
384
|
+
isbn: void 0,
|
|
385
|
+
readingDirection: void 0,
|
|
386
|
+
renditionLayout: e.renditionLayout,
|
|
387
|
+
title: void 0,
|
|
388
|
+
authors: void 0,
|
|
389
|
+
publisher: void 0,
|
|
390
|
+
rights: void 0,
|
|
391
|
+
languages: void 0,
|
|
392
|
+
date: void 0,
|
|
393
|
+
subjects: void 0
|
|
394
|
+
}), X = (e) => {
|
|
395
|
+
if (e === void 0) return;
|
|
396
|
+
let t = e.trim().match(/^(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?/);
|
|
397
|
+
if (t === null) return;
|
|
398
|
+
let [, n, r, i] = t;
|
|
399
|
+
return {
|
|
400
|
+
...n === void 0 ? {} : { year: Number.parseInt(n, 10) },
|
|
401
|
+
...r === void 0 ? {} : { month: Number.parseInt(r, 10) },
|
|
402
|
+
...i === void 0 ? {} : { day: Number.parseInt(i, 10) }
|
|
403
|
+
};
|
|
404
|
+
}, xe = (e) => {
|
|
405
|
+
for (let t of e) if (t.scheme !== void 0 && t.scheme.trim().toLowerCase() === "isbn" && K(t.value) !== void 0) return t.value;
|
|
406
|
+
for (let t of e) if (K(t.value) !== void 0) return t.value;
|
|
407
|
+
}, Se = (e) => {
|
|
408
|
+
let t = e.pageProgressionDirection?.trim().toLowerCase(), n = t === "ltr" || t === "rtl" ? t : void 0, r = e.renditionLayoutMeta?.trim().toLowerCase(), i = r === "reflowable" || r === "pre-paginated" ? r : void 0, a = xe(e.identifiers);
|
|
409
|
+
return {
|
|
410
|
+
gtin: G(a),
|
|
411
|
+
isbn: K(a),
|
|
412
|
+
readingDirection: n,
|
|
413
|
+
renditionLayout: i,
|
|
414
|
+
title: e.title,
|
|
415
|
+
authors: e.creators.length > 0 ? [...e.creators] : void 0,
|
|
416
|
+
publisher: e.publisher,
|
|
417
|
+
rights: e.rights,
|
|
418
|
+
languages: e.languages.length > 0 ? [...e.languages] : void 0,
|
|
419
|
+
date: X(e.date),
|
|
420
|
+
subjects: e.subjects.length > 0 ? [...e.subjects] : void 0
|
|
421
|
+
};
|
|
422
|
+
}, Ce = (e) => e.kind === "comicInfo" ? ye(e) : e.kind === "kobo" ? be(e) : e.kind === "apple" ? me(e) : Se(e), we = (e) => {
|
|
423
|
+
let t = [...e.records].sort((e, t) => f(e.uri, t.uri)), n = (e, t, r, i, a) => {
|
|
424
|
+
let o = e.find((e) => e.title === t), [s, ...c] = r;
|
|
425
|
+
return o ? s ? [...e.filter((e) => e !== o), {
|
|
426
|
+
...o,
|
|
427
|
+
contents: n(o.contents, s, c, i, a)
|
|
428
|
+
}] : o.path.split("/").length > a.split("/").length ? [...e.filter((e) => e !== o), {
|
|
429
|
+
...o,
|
|
430
|
+
path: a,
|
|
431
|
+
containerHref: i
|
|
432
|
+
}] : e : s ? [...e, {
|
|
433
|
+
contents: n([], s, c, i, a),
|
|
434
|
+
containerHref: i,
|
|
435
|
+
path: a,
|
|
436
|
+
title: t
|
|
437
|
+
}] : [...e, {
|
|
438
|
+
contents: [],
|
|
439
|
+
containerHref: i,
|
|
440
|
+
path: a,
|
|
441
|
+
title: t
|
|
442
|
+
}];
|
|
443
|
+
};
|
|
444
|
+
return t.reduce((e, t) => {
|
|
445
|
+
if (t.dir) return e;
|
|
446
|
+
let [r, ...i] = t.uri.split("/").slice(0, -1);
|
|
447
|
+
if (!r) return e;
|
|
448
|
+
let a = encodeURI(t.uri).replace(/#/g, "%23").replace(/\?/g, "%3F").replace(/\/$/, ""), o = t.uri.replace(/\/$/, "");
|
|
449
|
+
return n(e, r, i, a, o);
|
|
450
|
+
}, []);
|
|
451
|
+
}, Z = (e) => e ? e.children.map((e) => e instanceof o ? e.text : e instanceof a ? Z(e) : "").join("").trim() : "", Te = (e) => k(e.properties).includes("nav"), Q = (e, { basePath: t }) => {
|
|
452
|
+
let n = {
|
|
453
|
+
contents: [],
|
|
454
|
+
path: "",
|
|
455
|
+
containerHref: "",
|
|
456
|
+
title: ""
|
|
457
|
+
}, r = e.childNamed("span") || e.childNamed("a");
|
|
458
|
+
n.title = (r?.attr.title || r?.val.trim() || Z(r)) ?? "";
|
|
459
|
+
let i = r?.name;
|
|
460
|
+
i !== "a" && (r = e.descendantWithPath(`${i}.a`), r && (i = r.name.toLowerCase())), i === "a" && r?.attr.href && (n.path = p(t, r.attr.href), n.containerHref = n.path);
|
|
461
|
+
let a = e.childNamed("ol");
|
|
462
|
+
if (a) {
|
|
463
|
+
let e = a.childrenNamed("li");
|
|
464
|
+
e && e.length > 0 && (n.contents = e.map((e) => Q(e, { basePath: t })));
|
|
465
|
+
}
|
|
466
|
+
return n;
|
|
467
|
+
}, Ee = (e, { basePath: t }) => {
|
|
468
|
+
let n = [], r;
|
|
469
|
+
return e.descendantWithPath("body.nav.ol") ? r = e.descendantWithPath("body.nav.ol")?.children : e.descendantWithPath("body.section.nav.ol") && (r = e.descendantWithPath("body.section.nav.ol")?.children), r && r.length > 0 && r.filter((e) => e instanceof a && e.name === "li").forEach((e) => {
|
|
470
|
+
n.push(Q(e, { basePath: t }));
|
|
471
|
+
}), n;
|
|
472
|
+
}, De = async (e, t) => {
|
|
473
|
+
let n = e.manifestItems.find(Te);
|
|
474
|
+
if (n?.href) {
|
|
475
|
+
let e = t.records.find((e) => e.uri.endsWith(n.href));
|
|
476
|
+
if (e && !e.dir) return Ee(new i(await b(e)), { basePath: u(e.uri) });
|
|
477
|
+
}
|
|
478
|
+
}, $ = (e, { opfBasePath: t, prefix: n }) => {
|
|
479
|
+
let r = p(t, e?.childNamed(`${n}content`)?.attr.src || ""), i = {
|
|
480
|
+
title: e?.descendantWithPath(`${n}navLabel.${n}text`)?.val || "",
|
|
481
|
+
path: r,
|
|
482
|
+
containerHref: r,
|
|
483
|
+
contents: []
|
|
484
|
+
}, a = e.childrenNamed(`${n}navPoint`);
|
|
485
|
+
return a && a.length > 0 && (i.contents = a.map((e) => $(e, {
|
|
486
|
+
opfBasePath: t,
|
|
487
|
+
prefix: n
|
|
488
|
+
}))), i;
|
|
489
|
+
}, Oe = (e, { opfBasePath: t }) => {
|
|
490
|
+
let n = [], r = e.name, i = "";
|
|
491
|
+
return r.indexOf(":") !== -1 && (i = `${r.split(":")[0]}:`), e.childNamed(`${i}navMap`)?.childrenNamed(`${i}navPoint`).forEach((e) => {
|
|
492
|
+
n.push($(e, {
|
|
493
|
+
opfBasePath: t,
|
|
494
|
+
prefix: i
|
|
495
|
+
}));
|
|
496
|
+
}), n;
|
|
497
|
+
}, ke = async ({ opf: e, opfBasePath: t, archive: n }) => {
|
|
498
|
+
let r = e.spineTocIdref;
|
|
499
|
+
if (r) {
|
|
500
|
+
let a = e.manifestItems.find((e) => e.id === r);
|
|
501
|
+
if (a) {
|
|
502
|
+
let e = `${t}${t === "" ? "" : "/"}${a.href}`, r = n.records.find((t) => t.uri.endsWith(e));
|
|
503
|
+
if (r && !r.dir) return Oe(new i(await b(r)), { opfBasePath: t });
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}, Ae = async (e, { opf: t } = {}) => {
|
|
507
|
+
let n = t ?? await W(e);
|
|
508
|
+
if (n) return await De(n.opf, e) || await ke({
|
|
509
|
+
opf: n.opf,
|
|
510
|
+
opfBasePath: n.basePath,
|
|
511
|
+
archive: e
|
|
512
|
+
}) || [];
|
|
513
|
+
let r = we(e);
|
|
514
|
+
return r.length === 0 ? void 0 : r;
|
|
515
|
+
};
|
|
516
|
+
//#endregion
|
|
517
|
+
export { m as APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME, w as COMIC_INFO_FILENAME, T as COMIC_INFO_MANGA_VALUES, oe as KOBO_DISPLAY_OPTIONS_FILENAME, r as arrayBufferFileAccessors, n as blobFileAccessors, e as createArchive, _ as createArchiveFromArrayBufferList, t as createArchiveFromEntries, v as createArchiveFromText, y as createArchiveFromUrls, C as getArchiveFileRecordByUri, ae as getArchiveHasComicInfo, D as getArchiveOpfInfo, le as getSpineItemFilesFromArchive, ue as isArchiveEpub, E as isComicInfoManga, S as isDirectoryRecord, x as isFileRecord, G as normalizeGtin, K as normalizeIsbn, g as parseAppleDisplayOptionsXml, re as parseComicInfo, ce as parseKoboXml, U as parseOpf, X as parseW3cDtfDate, W as readArchiveOpf, b as readRecordAsText, Ce as resolveArchiveMetadata, Ae as resolveArchiveToc, k as tokenizeXmlSpaceSeparatedList };
|
|
518
|
+
|
|
519
|
+
//# sourceMappingURL=index.js.map
|