@prose-reader/streamer 1.309.0 → 1.311.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/createArchiveFromArrayBufferList.d.ts +1 -1
- package/dist/archives/createArchiveFromEntries.d.ts +29 -0
- package/dist/archives/createArchiveFromJszip/index.cjs +1 -1
- package/dist/archives/createArchiveFromJszip/index.cjs.map +1 -1
- package/dist/archives/createArchiveFromJszip/index.js +15 -28
- package/dist/archives/createArchiveFromJszip/index.js.map +1 -1
- package/dist/archives/createArchiveFromJszip.d.ts +1 -1
- package/dist/archives/createArchiveFromLibArchive/index.cjs +1 -1
- package/dist/archives/createArchiveFromLibArchive/index.cjs.map +1 -1
- package/dist/archives/createArchiveFromLibArchive/index.js +10 -15
- package/dist/archives/createArchiveFromLibArchive/index.js.map +1 -1
- package/dist/archives/createArchiveFromLibArchive.d.ts +1 -1
- package/dist/archives/createArchiveFromNodeUnrarJs/index.cjs +1 -1
- package/dist/archives/createArchiveFromNodeUnrarJs/index.cjs.map +1 -1
- package/dist/archives/createArchiveFromNodeUnrarJs/index.js +20 -32
- package/dist/archives/createArchiveFromNodeUnrarJs/index.js.map +1 -1
- package/dist/archives/createArchiveFromNodeUnrarJs.d.ts +1 -1
- package/dist/archives/createArchiveFromUnzipper/index.cjs +1 -1
- package/dist/archives/createArchiveFromUnzipper/index.cjs.map +1 -1
- package/dist/archives/createArchiveFromUnzipper/index.js +19 -31
- package/dist/archives/createArchiveFromUnzipper/index.js.map +1 -1
- package/dist/archives/createArchiveFromUnzipper.d.ts +1 -1
- 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/createArchiveFromEntries-B4KAUclj.cjs +3 -0
- package/dist/createArchiveFromEntries-B4KAUclj.cjs.map +1 -0
- package/dist/createArchiveFromEntries-BgXc4rEL.js +65 -0
- package/dist/createArchiveFromEntries-BgXc4rEL.js.map +1 -0
- package/dist/index/index.cjs +8 -8
- package/dist/index/index.cjs.map +1 -1
- package/dist/index/index.js +243 -255
- package/dist/index/index.js.map +1 -1
- package/package.json +14 -4
- package/dist/createArchive-BB7-JJjh.js +0 -35
- package/dist/createArchive-BB7-JJjh.js.map +0 -1
- package/dist/createArchive-CeuyJUIj.cjs +0 -3
- package/dist/createArchive-CeuyJUIj.cjs.map +0 -1
- package/dist/uri-DBZYnB1I.js +0 -13
- package/dist/uri-DBZYnB1I.js.map +0 -1
- package/dist/uri-DW0-P-ng.cjs +0 -2
- package/dist/uri-DW0-P-ng.cjs.map +0 -1
package/dist/index/index.js
CHANGED
|
@@ -1,34 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { BehaviorSubject as se, EMPTY as y, NEVER as b, Subject as x, catchError as S, distinctUntilChanged as ce, filter as C, finalize as le, first as w, from as T, ignoreElements as ue, lastValueFrom as de, map as E, merge as D, mergeMap as O, of as fe, pairwise as pe, shareReplay as me, startWith as he, switchMap as k, takeUntil as ge, tap as A, timer as _e } from "rxjs";
|
|
1
|
+
import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "../createArchiveFromEntries-BgXc4rEL.js";
|
|
2
|
+
import { n as s, t as c } from "../fileAccessors-etcCPnpQ.js";
|
|
3
|
+
import { detectMimeTypeFromName as l, escapeXmlAttributeValue as u, isMediaContentMimeType as d, isXmlBasedMimeType as f, parseContentType as p, urlJoin as m } from "@prose-reader/shared";
|
|
4
|
+
import { APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME as h, COMIC_INFO_FILENAME as g, KOBO_DISPLAY_OPTIONS_FILENAME as _, parseAppleDisplayOptionsXml as ee, parseComicInfo as te, parseKoboXml as ne, parseOpf as re, resolveArchiveMetadata as v, tokenizeXmlSpaceSeparatedList as ie } from "@prose-reader/archive-parser";
|
|
5
|
+
import { XmlDocument as y, XmlElement as ae, XmlTextNode as oe } from "xmldoc";
|
|
6
|
+
import { BehaviorSubject as se, EMPTY as b, NEVER as x, Subject as S, catchError as C, distinctUntilChanged as ce, filter as w, finalize as le, first as T, from as E, ignoreElements as ue, lastValueFrom as de, map as D, merge as O, mergeMap as k, of as fe, pairwise as pe, shareReplay as me, startWith as he, switchMap as A, takeUntil as ge, tap as j, timer as _e } from "rxjs";
|
|
8
7
|
//#region src/archives/createArchiveFromArrayBufferList.ts
|
|
9
|
-
var ve = async (e,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
dir: e.isDir,
|
|
22
|
-
basename: t,
|
|
23
|
-
encodingFormat: c(e.name),
|
|
24
|
-
uri: e.name,
|
|
25
|
-
size: e.size,
|
|
26
|
-
...s(e.data, c(e.name) ?? "")
|
|
27
|
-
};
|
|
28
|
-
}),
|
|
29
|
-
close: () => Promise.resolve()
|
|
30
|
-
});
|
|
31
|
-
}, ye = async (e, { mimeType: n, direction: i } = { mimeType: "text/plain" }) => {
|
|
8
|
+
var ve = async (e, t = {}) => o(e, (e) => e.isDir ? {
|
|
9
|
+
dir: !0,
|
|
10
|
+
uri: e.name
|
|
11
|
+
} : {
|
|
12
|
+
dir: !1,
|
|
13
|
+
uri: e.name,
|
|
14
|
+
size: e.size,
|
|
15
|
+
...c(e.data, l(e.name) ?? "")
|
|
16
|
+
}, {
|
|
17
|
+
...t,
|
|
18
|
+
close: () => Promise.resolve()
|
|
19
|
+
}), ye = async (e, { mimeType: t, direction: n } = { mimeType: "text/plain" }) => {
|
|
32
20
|
let a = `
|
|
33
21
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
34
22
|
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="ja" prefix="rendition: http://www.idpf.org/vocab/rendition/#"
|
|
@@ -40,87 +28,87 @@ var ve = async (e, { orderByAlpha: i, name: a, encodingFormat: o } = {}) => {
|
|
|
40
28
|
<manifest>
|
|
41
29
|
<item id="p01" href="p01.txt" media-type="text/plain"/>
|
|
42
30
|
</manifest>
|
|
43
|
-
<spine page-progression-direction="${
|
|
31
|
+
<spine page-progression-direction="${n ?? "ltr"}">
|
|
44
32
|
<itemref idref="p01" />
|
|
45
33
|
</spine>
|
|
46
34
|
</package>
|
|
47
35
|
`;
|
|
48
|
-
return
|
|
36
|
+
return r({
|
|
49
37
|
filename: "content.txt",
|
|
50
|
-
encodingFormat:
|
|
38
|
+
encodingFormat: t,
|
|
51
39
|
records: [{
|
|
52
40
|
dir: !1,
|
|
53
|
-
basename:
|
|
41
|
+
basename: i("generated.opf"),
|
|
54
42
|
uri: "generated.opf",
|
|
55
43
|
size: 0,
|
|
56
|
-
...
|
|
44
|
+
...s(async () => new Blob([a]))
|
|
57
45
|
}, {
|
|
58
46
|
dir: !1,
|
|
59
|
-
basename:
|
|
47
|
+
basename: i("p01.txt"),
|
|
60
48
|
uri: "p01.txt",
|
|
61
49
|
size: typeof e == "string" ? new Blob([e]).size : e.size,
|
|
62
|
-
encodingFormat:
|
|
63
|
-
...
|
|
50
|
+
encodingFormat: t,
|
|
51
|
+
...s(async () => typeof e == "string" ? new Blob([e]) : e)
|
|
64
52
|
}],
|
|
65
53
|
close: () => Promise.resolve()
|
|
66
54
|
});
|
|
67
|
-
}, be = /^[A-Za-z0-9_][A-Za-z0-9_.-]*$/, xe = /^[A-Za-z0-9_]/,
|
|
68
|
-
if (be.test(e) && !
|
|
69
|
-
let t = we(e), n = t && !
|
|
70
|
-
return xe.test(n) ? n : `${
|
|
71
|
-
},
|
|
72
|
-
let n =
|
|
55
|
+
}, be = /^[A-Za-z0-9_][A-Za-z0-9_.-]*$/, xe = /^[A-Za-z0-9_]/, M = /^xml/i, Se = /[^A-Za-z0-9_.-]+/g, N = "_", Ce = (e) => e.replace(/^_+|_+$/g, ""), we = (e) => Ce(e.trim().replaceAll("/", "_").replace(Se, "_")), P = (e) => {
|
|
56
|
+
if (be.test(e) && !M.test(e)) return e;
|
|
57
|
+
let t = we(e), n = t && !M.test(t) ? t : `${N}${t}`;
|
|
58
|
+
return xe.test(n) ? n : `${N}${n}`;
|
|
59
|
+
}, F = (e, t) => {
|
|
60
|
+
let n = P(e);
|
|
73
61
|
if (!t.has(n)) return t.add(n), n;
|
|
74
62
|
let r = 2, i = `${n}-${r}`;
|
|
75
63
|
for (; t.has(i);) r += 1, i = `${n}-${r}`;
|
|
76
64
|
return t.add(i), i;
|
|
77
|
-
},
|
|
65
|
+
}, I = () => {
|
|
78
66
|
let e = /* @__PURE__ */ new Set();
|
|
79
|
-
return (t) =>
|
|
80
|
-
}, Te = async (e,
|
|
81
|
-
let
|
|
82
|
-
id:
|
|
67
|
+
return (t) => F(t, e);
|
|
68
|
+
}, Te = async (e, t) => {
|
|
69
|
+
let n = I(), a = e.map((e) => ({
|
|
70
|
+
id: n(e),
|
|
83
71
|
url: e
|
|
84
|
-
})),
|
|
72
|
+
})), o = `
|
|
85
73
|
<?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
|
|
86
74
|
<metadata>
|
|
87
|
-
<meta property="rendition:layout">${
|
|
88
|
-
${
|
|
75
|
+
<meta property="rendition:layout">${t?.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
|
|
76
|
+
${t?.useRenditionFlow ? "<meta property=\"rendition:flow\">scrolled-continuous</meta>" : ""}
|
|
89
77
|
</metadata>
|
|
90
78
|
<manifest>
|
|
91
79
|
${a.map(({ id: e, url: t }) => {
|
|
92
|
-
let n =
|
|
93
|
-
return `<item id="${e}" href="${
|
|
80
|
+
let n = l(t);
|
|
81
|
+
return `<item id="${e}" href="${u(t)}" media-type="${u(n ?? "")}"/>`;
|
|
94
82
|
}).join("\n")}
|
|
95
83
|
</manifest>
|
|
96
84
|
<spine>
|
|
97
85
|
${a.map(({ id: e }) => `<itemref idref="${e}" />`).join("\n")}
|
|
98
86
|
</spine>
|
|
99
87
|
</package>
|
|
100
|
-
`,
|
|
88
|
+
`, c = e.map((e) => ({
|
|
101
89
|
dir: !1,
|
|
102
|
-
basename:
|
|
103
|
-
encodingFormat:
|
|
90
|
+
basename: i(e),
|
|
91
|
+
encodingFormat: l(e),
|
|
104
92
|
uri: e,
|
|
105
93
|
size: 0,
|
|
106
|
-
...
|
|
94
|
+
...s(async () => (await fetch(e)).blob())
|
|
107
95
|
}));
|
|
108
|
-
return
|
|
96
|
+
return r({
|
|
109
97
|
records: [{
|
|
110
98
|
dir: !1,
|
|
111
99
|
basename: "content.opf",
|
|
112
100
|
uri: "content.opf",
|
|
113
101
|
size: 0,
|
|
114
|
-
...
|
|
115
|
-
}, ...
|
|
102
|
+
...s(async () => new Blob([o]))
|
|
103
|
+
}, ...c],
|
|
116
104
|
close: () => Promise.resolve()
|
|
117
105
|
});
|
|
118
|
-
},
|
|
106
|
+
}, L = (e) => !e.dir, Ee = (e) => e.dir, R = (e, t) => {
|
|
119
107
|
let n = e.recordsByUri.get(t);
|
|
120
|
-
return n &&
|
|
121
|
-
}, De =
|
|
122
|
-
|
|
123
|
-
},
|
|
108
|
+
return n && L(n) ? n : void 0;
|
|
109
|
+
}, De = g.toLowerCase(), z = (e) => e.records.find((e) => L(e) && e.basename.toLowerCase() === De), B = async (e) => new TextDecoder().decode(await e.arrayBuffer()), Oe = ({ enableReport: e } = {}) => {
|
|
110
|
+
a.enable(!!e);
|
|
111
|
+
}, V = (e) => {
|
|
124
112
|
let t = e.records.filter((e) => !e.dir).find((e) => e.uri.endsWith(".opf"));
|
|
125
113
|
return {
|
|
126
114
|
data: t,
|
|
@@ -129,30 +117,30 @@ var ve = async (e, { orderByAlpha: i, name: a, encodingFormat: o } = {}) => {
|
|
|
129
117
|
};
|
|
130
118
|
//#endregion
|
|
131
119
|
//#region src/epubs/readArchiveOpf.ts
|
|
132
|
-
async function
|
|
133
|
-
let { data: t, basePath: n } =
|
|
120
|
+
async function H(e) {
|
|
121
|
+
let { data: t, basePath: n } = V(e) || {};
|
|
134
122
|
if (!(!t || t.dir)) return {
|
|
135
|
-
opf: re(await
|
|
123
|
+
opf: re(await B(t)),
|
|
136
124
|
basePath: n
|
|
137
125
|
};
|
|
138
126
|
}
|
|
139
127
|
//#endregion
|
|
140
128
|
//#region src/generators/manifest/hooks/apple.ts
|
|
141
|
-
var ke =
|
|
129
|
+
var ke = h.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
142
130
|
let n = e.records.find((e) => !e.dir && e.basename.toLowerCase() === ke);
|
|
143
131
|
if (!n || n.dir) return t;
|
|
144
|
-
let r = await
|
|
132
|
+
let r = await B(n);
|
|
145
133
|
try {
|
|
146
|
-
let { renditionLayout: e } =
|
|
134
|
+
let { renditionLayout: e } = v(ee(r));
|
|
147
135
|
return {
|
|
148
136
|
...t,
|
|
149
137
|
renditionLayout: t.renditionLayout ?? e
|
|
150
138
|
};
|
|
151
139
|
} catch (e) {
|
|
152
|
-
return console.error(`Unable to parse ${
|
|
140
|
+
return console.error(`Unable to parse ${h} for content\n`, r), console.error(e), t;
|
|
153
141
|
}
|
|
154
|
-
}, je =
|
|
155
|
-
let n =
|
|
142
|
+
}, je = g.toLowerCase(), Me = ({ archive: e }) => async (t) => {
|
|
143
|
+
let n = z(e);
|
|
156
144
|
if (!n) return t;
|
|
157
145
|
let r = {
|
|
158
146
|
...t,
|
|
@@ -160,22 +148,22 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
160
148
|
...e,
|
|
161
149
|
progressionWeight: 1 / n.length
|
|
162
150
|
}))
|
|
163
|
-
}, i = await
|
|
151
|
+
}, i = await B(n);
|
|
164
152
|
try {
|
|
165
|
-
let e =
|
|
153
|
+
let e = v(te(i));
|
|
166
154
|
return {
|
|
167
155
|
...r,
|
|
168
156
|
readingDirection: e.readingDirection ?? r.readingDirection
|
|
169
157
|
};
|
|
170
158
|
} catch (e) {
|
|
171
|
-
return console.error(`Unable to parse ${
|
|
159
|
+
return console.error(`Unable to parse ${g} for content\n`, i), console.error(e), r;
|
|
172
160
|
}
|
|
173
161
|
}, Ne = ({ baseUrl: e = "", resourcePath: t }) => {
|
|
174
162
|
if (!e && /^https?:\/\//.test(t)) return encodeURI(t);
|
|
175
163
|
let n = e ? `${e}${e.endsWith("/") ? "" : "/"}` : "file://";
|
|
176
164
|
return encodeURI(`${n}${t}`);
|
|
177
165
|
}, Pe = ({ archive: e, baseUrl: t }) => async () => {
|
|
178
|
-
let n = e.records.filter((e) => !e.dir), r =
|
|
166
|
+
let n = e.records.filter((e) => !e.dir), r = I(), i = n.map((e) => ({
|
|
179
167
|
file: e,
|
|
180
168
|
id: r(e.uri)
|
|
181
169
|
}));
|
|
@@ -203,12 +191,12 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
203
191
|
href: encodeURI(`${t}${e.uri}`)
|
|
204
192
|
}))
|
|
205
193
|
};
|
|
206
|
-
},
|
|
194
|
+
}, U = async ({ archive: e, archiveOpf: t }) => {
|
|
207
195
|
if (!t) return [];
|
|
208
196
|
let { opf: n, basePath: r } = t, { spineRows: i } = n;
|
|
209
197
|
return e.records.filter((e) => i.find((t) => r ? `${r}/${t.href}` === e.uri : `${t.href}` === e.uri));
|
|
210
|
-
},
|
|
211
|
-
let { basePath: r } =
|
|
198
|
+
}, W = (e, t, n) => {
|
|
199
|
+
let { basePath: r } = V(t) || {};
|
|
212
200
|
return e.map((e) => {
|
|
213
201
|
let t = e.href, i = n?.(t) ?? "";
|
|
214
202
|
return {
|
|
@@ -226,14 +214,14 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
226
214
|
}, Le = (e) => {
|
|
227
215
|
let t = e?.trim();
|
|
228
216
|
if (t === "cover" || t === "title-page" || t === "copyright-page" || t === "text") return t;
|
|
229
|
-
}, Re = ({ archive:
|
|
230
|
-
if (!
|
|
231
|
-
let { opf:
|
|
232
|
-
|
|
233
|
-
let c =
|
|
234
|
-
archive:
|
|
235
|
-
archiveOpf:
|
|
236
|
-
})).filter(
|
|
217
|
+
}, Re = ({ archive: e, baseUrl: t, archiveOpf: n }) => async (r) => {
|
|
218
|
+
if (!n) return r;
|
|
219
|
+
let { opf: i, basePath: o } = n, s = v(i);
|
|
220
|
+
a.groupCollapsed(...a.getGroupArgs("OPF parsed")), a.log("opf", i), a.groupEnd();
|
|
221
|
+
let c = i.renditionLayoutMeta?.trim(), l = c === "reflowable" || c === "pre-paginated" ? c : s.renditionLayout, u = i.title?.trim() || e.records.find(({ dir: e }) => e)?.basename || "", d = s.readingDirection ?? r.readingDirection, f = (await U({
|
|
222
|
+
archive: e,
|
|
223
|
+
archiveOpf: n
|
|
224
|
+
})).filter(L).reduce((e, t) => t.size + e, 0), p = i.guide, m = [];
|
|
237
225
|
for (let e of p) {
|
|
238
226
|
let t = Le(e.type);
|
|
239
227
|
t !== void 0 && m.push({
|
|
@@ -243,40 +231,40 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
243
231
|
});
|
|
244
232
|
}
|
|
245
233
|
return {
|
|
246
|
-
filename:
|
|
234
|
+
filename: e.filename ?? "",
|
|
247
235
|
renditionLayout: l,
|
|
248
|
-
renditionFlow: Fe(
|
|
249
|
-
renditionSpread: Ie(
|
|
236
|
+
renditionFlow: Fe(i.renditionFlowMeta),
|
|
237
|
+
renditionSpread: Ie(i.renditionSpreadMeta),
|
|
250
238
|
title: u,
|
|
251
239
|
readingDirection: d,
|
|
252
|
-
spineItems:
|
|
253
|
-
let
|
|
240
|
+
spineItems: i.spineRows.map((n, r) => {
|
|
241
|
+
let a = R(e, o ? `${o}/${n.href}` : n.href), s = a ? a.size : 0, c = t || (/^https?:\/\//.test(n.href) ? "" : "file://");
|
|
254
242
|
return {
|
|
255
|
-
id:
|
|
243
|
+
id: n.id,
|
|
256
244
|
index: r,
|
|
257
|
-
href:
|
|
258
|
-
renditionLayout:
|
|
259
|
-
...
|
|
260
|
-
progressionWeight: f > 0 ? s / f : 1 /
|
|
261
|
-
pageSpreadLeft:
|
|
262
|
-
pageSpreadRight:
|
|
263
|
-
mediaType:
|
|
245
|
+
href: n.href.startsWith("https://") ? n.href : o ? `${c}${o}/${n.href}` : `${c}${n.href}`,
|
|
246
|
+
renditionLayout: n.renditionLayout ?? l,
|
|
247
|
+
...n.renditionFlow === void 0 ? {} : { renditionFlow: n.renditionFlow },
|
|
248
|
+
progressionWeight: f > 0 ? s / f : 1 / i.spineRows.length,
|
|
249
|
+
pageSpreadLeft: n.pageSpreadLeft,
|
|
250
|
+
pageSpreadRight: n.pageSpreadRight,
|
|
251
|
+
mediaType: n.mediaType
|
|
264
252
|
};
|
|
265
253
|
}),
|
|
266
|
-
items:
|
|
254
|
+
items: W(i.manifestItems, e, (e) => /^https?:\/\//.test(e) ? "" : t || "file://"),
|
|
267
255
|
guide: m.length > 0 ? m : void 0
|
|
268
256
|
};
|
|
269
257
|
}, ze = (e) => {
|
|
270
258
|
let t = e.descendantWithPath("head")?.childrenNamed("meta").find((e) => e.attr.name === "viewport");
|
|
271
259
|
return !!(t && t.attr.name === "viewport");
|
|
272
260
|
}, Be = (e) => e.reduce(async (e, t) => {
|
|
273
|
-
if (!await e || !
|
|
274
|
-
mimeType:
|
|
261
|
+
if (!await e || !f({
|
|
262
|
+
mimeType: L(t) ? t.encodingFormat : void 0,
|
|
275
263
|
uri: t.uri
|
|
276
264
|
})) return !1;
|
|
277
|
-
let n = t.dir ? null : await
|
|
278
|
-
return n ? ze(new
|
|
279
|
-
}, Promise.resolve(!0)), Ve = ({ archive: e, archiveOpf: t }) => async (n) => n.renditionLayout === "reflowable" && n.spineItems.every((e) => e.renditionLayout === "reflowable") && await Be(await
|
|
265
|
+
let n = t.dir ? null : await B(t);
|
|
266
|
+
return n ? ze(new y(n)) : !1;
|
|
267
|
+
}, Promise.resolve(!0)), Ve = ({ archive: e, archiveOpf: t }) => async (n) => n.renditionLayout === "reflowable" && n.spineItems.every((e) => e.renditionLayout === "reflowable") && await Be(await U({
|
|
280
268
|
archive: e,
|
|
281
269
|
archiveOpf: t
|
|
282
270
|
})) ? {
|
|
@@ -292,47 +280,47 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
292
280
|
}), Ue = async (e) => {
|
|
293
281
|
let t;
|
|
294
282
|
return await Promise.all(e.records.map(async (e) => {
|
|
295
|
-
if (e.dir || !e.uri.endsWith(
|
|
296
|
-
let n = await
|
|
283
|
+
if (e.dir || !e.uri.endsWith(_)) return;
|
|
284
|
+
let n = await B(e);
|
|
297
285
|
try {
|
|
298
286
|
let { renditionLayout: e } = ne(n);
|
|
299
287
|
e && (t = e);
|
|
300
288
|
} catch (e) {
|
|
301
|
-
console.error(`Unable to parse ${
|
|
289
|
+
console.error(`Unable to parse ${_} for content\n`, n), console.error(e);
|
|
302
290
|
}
|
|
303
291
|
})), {
|
|
304
292
|
kind: "kobo",
|
|
305
293
|
...t === void 0 ? {} : { renditionLayout: t }
|
|
306
294
|
};
|
|
307
295
|
}, We = ({ archive: e }) => async (t) => {
|
|
308
|
-
let { renditionLayout: n } =
|
|
296
|
+
let { renditionLayout: n } = v(await Ue(e));
|
|
309
297
|
return {
|
|
310
298
|
...t,
|
|
311
299
|
renditionLayout: t.renditionLayout ?? n
|
|
312
300
|
};
|
|
313
|
-
},
|
|
301
|
+
}, G = (e) => e.toLowerCase().endsWith(".opf"), Ge = (e) => e.records.some((e) => !e.dir && (G(e.basename) || G(e.uri))), Ke = ({ archive: e }) => async (t) => Ge(e) ? t : {
|
|
314
302
|
...t,
|
|
315
303
|
spineItems: t.spineItems.map((t) => {
|
|
316
|
-
let n = e.records.find((e) => decodeURI(t.href).endsWith(e.uri)), r =
|
|
304
|
+
let n = e.records.find((e) => decodeURI(t.href).endsWith(e.uri)), r = p((n && L(n) ? n.encodingFormat : void 0) ?? "") || l(n?.basename ?? "");
|
|
317
305
|
return {
|
|
318
306
|
...t,
|
|
319
|
-
renditionLayout: r &&
|
|
307
|
+
renditionLayout: r && d(r) ? "pre-paginated" : t.renditionLayout
|
|
320
308
|
};
|
|
321
309
|
})
|
|
322
|
-
},
|
|
310
|
+
}, K = (e) => e ? e.children.map((e) => e instanceof oe ? e.text : e instanceof ae ? K(e) : "").join("").trim() : "", qe = (e) => ie(e.properties).includes("nav"), q = (e, { basePath: t, baseUrl: n }) => {
|
|
323
311
|
let r = {
|
|
324
312
|
contents: [],
|
|
325
313
|
path: "",
|
|
326
314
|
href: "",
|
|
327
315
|
title: ""
|
|
328
316
|
}, i = e.childNamed("span") || e.childNamed("a");
|
|
329
|
-
r.title = (i?.attr.title || i?.val.trim() ||
|
|
317
|
+
r.title = (i?.attr.title || i?.val.trim() || K(i)) ?? "";
|
|
330
318
|
let a = i?.name;
|
|
331
|
-
a !== "a" && (i = e.descendantWithPath(`${a}.a`), i && (a = i.name.toLowerCase())), a === "a" && i?.attr.href && (r.path =
|
|
319
|
+
a !== "a" && (i = e.descendantWithPath(`${a}.a`), i && (a = i.name.toLowerCase())), a === "a" && i?.attr.href && (r.path = m(t, i.attr.href), r.href = m(n, t, i.attr.href));
|
|
332
320
|
let o = e.childNamed("ol");
|
|
333
321
|
if (o) {
|
|
334
322
|
let e = o.childrenNamed("li");
|
|
335
|
-
e && e.length > 0 && (r.contents = e.map((e) =>
|
|
323
|
+
e && e.length > 0 && (r.contents = e.map((e) => q(e, {
|
|
336
324
|
basePath: t,
|
|
337
325
|
baseUrl: n
|
|
338
326
|
})));
|
|
@@ -341,28 +329,28 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
341
329
|
}, Je = (e, { basePath: t, baseUrl: n }) => {
|
|
342
330
|
let r = [], i;
|
|
343
331
|
return e.descendantWithPath("body.nav.ol") ? i = e.descendantWithPath("body.nav.ol")?.children : e.descendantWithPath("body.section.nav.ol") && (i = e.descendantWithPath("body.section.nav.ol")?.children), i && i.length > 0 && i.filter((e) => e.name === "li").forEach((e) => {
|
|
344
|
-
r.push(
|
|
332
|
+
r.push(q(e, {
|
|
345
333
|
basePath: t,
|
|
346
334
|
baseUrl: n
|
|
347
335
|
}));
|
|
348
336
|
}), r;
|
|
349
|
-
}, Ye = async (e, t, { baseUrl:
|
|
350
|
-
let
|
|
351
|
-
if (
|
|
352
|
-
let e = t.records.find((e) => e.uri.endsWith(
|
|
353
|
-
if (e && !e.dir) return Je(new
|
|
354
|
-
basePath:
|
|
355
|
-
baseUrl:
|
|
337
|
+
}, Ye = async (e, t, { baseUrl: r }) => {
|
|
338
|
+
let i = e.manifestItems.find(qe);
|
|
339
|
+
if (i?.href) {
|
|
340
|
+
let e = t.records.find((e) => e.uri.endsWith(i.href));
|
|
341
|
+
if (e && !e.dir) return Je(new y(await B(e)), {
|
|
342
|
+
basePath: n(e.uri),
|
|
343
|
+
baseUrl: r
|
|
356
344
|
});
|
|
357
345
|
}
|
|
358
|
-
},
|
|
346
|
+
}, J = (e, { opfBasePath: t, baseUrl: n, prefix: r }) => {
|
|
359
347
|
let i = e?.childNamed(`${r}content`)?.attr.src || "", a = {
|
|
360
348
|
title: e?.descendantWithPath(`${r}navLabel.${r}text`)?.val || "",
|
|
361
|
-
path:
|
|
362
|
-
href:
|
|
349
|
+
path: m(t, i),
|
|
350
|
+
href: m(n, t, i),
|
|
363
351
|
contents: []
|
|
364
352
|
}, o = e.childrenNamed(`${r}navPoint`);
|
|
365
|
-
return o && o.length > 0 && (a.contents = o.map((e) =>
|
|
353
|
+
return o && o.length > 0 && (a.contents = o.map((e) => J(e, {
|
|
366
354
|
opfBasePath: t,
|
|
367
355
|
baseUrl: n,
|
|
368
356
|
prefix: r
|
|
@@ -370,7 +358,7 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
370
358
|
}, Xe = (e, { opfBasePath: t, baseUrl: n }) => {
|
|
371
359
|
let r = [], i = e.name, a = "";
|
|
372
360
|
return i.indexOf(":") !== -1 && (a = `${i.split(":")[0]}:`), e.childNamed(`${a}navMap`)?.childrenNamed(`${a}navPoint`).forEach((e) => {
|
|
373
|
-
r.push(
|
|
361
|
+
r.push(J(e, {
|
|
374
362
|
opfBasePath: t,
|
|
375
363
|
baseUrl: n,
|
|
376
364
|
prefix: a
|
|
@@ -382,14 +370,14 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
382
370
|
let a = e.manifestItems.find((e) => e.id === i);
|
|
383
371
|
if (a) {
|
|
384
372
|
let e = `${t}${t === "" ? "" : "/"}${a.href}`, i = r.records.find((t) => t.uri.endsWith(e));
|
|
385
|
-
if (i && !i.dir) return Xe(new
|
|
373
|
+
if (i && !i.dir) return Xe(new y(await B(i)), {
|
|
386
374
|
opfBasePath: t,
|
|
387
375
|
baseUrl: n
|
|
388
376
|
});
|
|
389
377
|
}
|
|
390
378
|
}
|
|
391
379
|
}, Qe = async (e, t, { baseUrl: n }) => {
|
|
392
|
-
let { basePath: r } =
|
|
380
|
+
let { basePath: r } = V(t) || {}, i = await Ye(e, t, { baseUrl: n });
|
|
393
381
|
if (i) return i;
|
|
394
382
|
let a = await Ze({
|
|
395
383
|
opf: e,
|
|
@@ -399,7 +387,7 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
399
387
|
});
|
|
400
388
|
if (a) return a;
|
|
401
389
|
}, $e = (e) => e.replace(/\.[^.]+$/, "").replace(/[_-]/g, " ").replace(/\s+/g, " ").trim(), et = (e, t) => {
|
|
402
|
-
if (e.spineItems.length !== 0 && e.spineItems.every((e) => (
|
|
390
|
+
if (e.spineItems.length !== 0 && e.spineItems.every((e) => (p(e.mediaType ?? "") || l(e.href))?.startsWith("audio/"))) return e.spineItems.map((e) => {
|
|
403
391
|
let n = t.records.find((t) => !t.dir && decodeURI(e.href).endsWith(t.uri));
|
|
404
392
|
return {
|
|
405
393
|
title: $e(n?.basename ?? e.href),
|
|
@@ -408,8 +396,8 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
408
396
|
contents: []
|
|
409
397
|
};
|
|
410
398
|
});
|
|
411
|
-
}, tt = (
|
|
412
|
-
let r = [...
|
|
399
|
+
}, tt = (t, { baseUrl: n }) => {
|
|
400
|
+
let r = [...t.records].sort((t, n) => e(t.uri, n.uri)), i = (e, t, n, r, a) => {
|
|
413
401
|
let o = e.find((e) => e.title === t), [s, ...c] = n;
|
|
414
402
|
return o ? s ? [...e.filter((e) => e !== o), {
|
|
415
403
|
...o,
|
|
@@ -430,10 +418,10 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
430
418
|
title: t
|
|
431
419
|
}];
|
|
432
420
|
};
|
|
433
|
-
return r.reduce((e,
|
|
434
|
-
if (
|
|
435
|
-
let [r, ...a] =
|
|
436
|
-
return r ? i(e, r, a,
|
|
421
|
+
return r.reduce((e, t) => {
|
|
422
|
+
if (t.dir) return e;
|
|
423
|
+
let [r, ...a] = t.uri.split("/").slice(0, -1);
|
|
424
|
+
return r ? i(e, r, a, m(n, encodeURI(t.uri)).replace(/\/$/, ""), t.uri.replace(/\/$/, "")) : e;
|
|
437
425
|
}, []);
|
|
438
426
|
}, nt = async (e, t, { baseUrl: n, archiveOpf: r }) => {
|
|
439
427
|
if (r) return await Qe(r.opf, e, { baseUrl: n }) || [];
|
|
@@ -451,46 +439,46 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
451
439
|
...r,
|
|
452
440
|
nav: { toc: i }
|
|
453
441
|
} : r;
|
|
454
|
-
}, it = (e) => e ? e.endsWith("/") ? e : `${e}/` : "",
|
|
455
|
-
|
|
456
|
-
let
|
|
457
|
-
archive:
|
|
458
|
-
baseUrl:
|
|
442
|
+
}, it = (e) => e ? e.endsWith("/") ? e : `${e}/` : "", Y = async (e, { baseUrl: t = "", hooks: n = {} } = {}) => {
|
|
443
|
+
a.log("Generating manifest from archive", e);
|
|
444
|
+
let r = await H(e), i = it(t), o = (t) => (t ?? []).map((t) => t({
|
|
445
|
+
archive: e,
|
|
446
|
+
baseUrl: i
|
|
459
447
|
})), s = [
|
|
460
448
|
Re({
|
|
461
|
-
archive:
|
|
462
|
-
baseUrl:
|
|
463
|
-
archiveOpf:
|
|
449
|
+
archive: e,
|
|
450
|
+
baseUrl: i,
|
|
451
|
+
archiveOpf: r
|
|
464
452
|
}),
|
|
465
453
|
Me({
|
|
466
|
-
archive:
|
|
467
|
-
baseUrl:
|
|
454
|
+
archive: e,
|
|
455
|
+
baseUrl: i
|
|
468
456
|
}),
|
|
469
457
|
Ae({
|
|
470
|
-
archive:
|
|
471
|
-
baseUrl:
|
|
458
|
+
archive: e,
|
|
459
|
+
baseUrl: i
|
|
472
460
|
}),
|
|
473
461
|
Ke({
|
|
474
|
-
archive:
|
|
475
|
-
baseUrl:
|
|
462
|
+
archive: e,
|
|
463
|
+
baseUrl: i
|
|
476
464
|
}),
|
|
477
|
-
...o(
|
|
478
|
-
], c = o(
|
|
465
|
+
...o(n.content)
|
|
466
|
+
], c = o(n.spine), l = [
|
|
479
467
|
Ve({
|
|
480
|
-
archive:
|
|
481
|
-
baseUrl:
|
|
482
|
-
archiveOpf:
|
|
468
|
+
archive: e,
|
|
469
|
+
baseUrl: i,
|
|
470
|
+
archiveOpf: r
|
|
483
471
|
}),
|
|
484
472
|
We({
|
|
485
|
-
archive:
|
|
486
|
-
baseUrl:
|
|
473
|
+
archive: e,
|
|
474
|
+
baseUrl: i
|
|
487
475
|
}),
|
|
488
|
-
...o(
|
|
476
|
+
...o(n.presentation)
|
|
489
477
|
], u = [rt({
|
|
490
|
-
archive:
|
|
491
|
-
baseUrl:
|
|
492
|
-
archiveOpf:
|
|
493
|
-
}), ...o(
|
|
478
|
+
archive: e,
|
|
479
|
+
baseUrl: i,
|
|
480
|
+
archiveOpf: r
|
|
481
|
+
}), ...o(n.navigation)], d = [
|
|
494
482
|
...s,
|
|
495
483
|
...c,
|
|
496
484
|
...l,
|
|
@@ -498,25 +486,25 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
498
486
|
He()
|
|
499
487
|
];
|
|
500
488
|
try {
|
|
501
|
-
let
|
|
502
|
-
archive:
|
|
503
|
-
baseUrl:
|
|
504
|
-
})(),
|
|
505
|
-
if (
|
|
506
|
-
let
|
|
507
|
-
|
|
489
|
+
let t = Pe({
|
|
490
|
+
archive: e,
|
|
491
|
+
baseUrl: i
|
|
492
|
+
})(), n = await d.reduce(async (e, t) => await t(await e), t);
|
|
493
|
+
if (a.log("Generated manifest", n), process.env.NODE_ENV === "development" && a.isEnabled()) {
|
|
494
|
+
let e = JSON.stringify(n, null, 2);
|
|
495
|
+
a.groupCollapsed(...a.getGroupArgs("Generated manifest")), a.log(`\n${e}`), a.groupEnd();
|
|
508
496
|
}
|
|
509
|
-
return
|
|
510
|
-
} catch (
|
|
511
|
-
throw
|
|
497
|
+
return n;
|
|
498
|
+
} catch (e) {
|
|
499
|
+
throw a.error(e), e;
|
|
512
500
|
}
|
|
513
501
|
}, at = (e) => {
|
|
514
502
|
let t = e.descendantWithPath("head")?.childrenNamed("meta").find((e) => e.attr.name === "calibre:cover");
|
|
515
503
|
return !!(t && t.attr.name === "calibre:cover");
|
|
516
504
|
}, ot = (e) => e.descendantWithPath("body")?.descendantWithPath("div")?.childrenNamed("svg")?.find((e) => e.attr.width === "100%" && e.attr.preserveAspectRatio === "none"), st = ({ archive: e, resourcePath: t }) => async (n) => {
|
|
517
|
-
let r =
|
|
505
|
+
let r = R(e, t);
|
|
518
506
|
if (r?.basename.endsWith(".xhtml")) {
|
|
519
|
-
let e = new
|
|
507
|
+
let e = new y(typeof n.body == "string" ? n.body : await B(r));
|
|
520
508
|
if (at(e)) {
|
|
521
509
|
let t = ot(e);
|
|
522
510
|
return t && delete t.attr.preserveAspectRatio, {
|
|
@@ -530,9 +518,9 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
530
518
|
archive: e,
|
|
531
519
|
resourcePath: t
|
|
532
520
|
})(n), lt = ({ archive: e, resourcePath: t }) => async (n) => {
|
|
533
|
-
let r =
|
|
521
|
+
let r = R(e, t);
|
|
534
522
|
if (r?.basename.endsWith(".css")) {
|
|
535
|
-
let e = (typeof n.body == "string" ? n.body : await
|
|
523
|
+
let e = (typeof n.body == "string" ? n.body : await B(r)).replaceAll("-webkit-writing-mode", "writing-mode");
|
|
536
524
|
return {
|
|
537
525
|
...n,
|
|
538
526
|
body: e
|
|
@@ -540,9 +528,9 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
540
528
|
}
|
|
541
529
|
return n;
|
|
542
530
|
}, ut = async (e, t) => {
|
|
543
|
-
let n = await
|
|
531
|
+
let n = await H(e);
|
|
544
532
|
if (n) {
|
|
545
|
-
let { opf: r } = n, i =
|
|
533
|
+
let { opf: r } = n, i = W(r.manifestItems, e, () => "").find((e) => t.endsWith(e.href))?.mediaType;
|
|
546
534
|
if (i) return { mediaType: i };
|
|
547
535
|
}
|
|
548
536
|
return { mediaType: dt(t) };
|
|
@@ -553,7 +541,7 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
553
541
|
if (e.endsWith(".mp4")) return "video/mp4";
|
|
554
542
|
if (e.endsWith(".svg")) return "image/svg+xml";
|
|
555
543
|
}, ft = ({ archive: e, resourcePath: t }) => async (n) => {
|
|
556
|
-
let r =
|
|
544
|
+
let r = R(e, t);
|
|
557
545
|
if (!r) return n;
|
|
558
546
|
let i = await ut(e, t);
|
|
559
547
|
return {
|
|
@@ -564,52 +552,52 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
564
552
|
...i.mediaType && { contentType: i.mediaType }
|
|
565
553
|
}
|
|
566
554
|
};
|
|
567
|
-
},
|
|
568
|
-
let r =
|
|
555
|
+
}, X = /* @__PURE__ */ "div.span.p.a.li.ul.ol.h1.h2.h3.h4.h5.h6.table.tr.td.th.thead.tbody.tfoot.section.article.header.footer.nav.aside.main.figure.figcaption.blockquote.pre.code.form.textarea.select.option.button.label.fieldset.legend.caption.dl.dt.dd.iframe.video.audio.canvas.script.style".split("."), pt = ({ archive: e, resourcePath: t }) => async (n) => {
|
|
556
|
+
let r = R(e, t);
|
|
569
557
|
if (r?.basename.endsWith(".xhtml")) {
|
|
570
|
-
let e = typeof n.body == "string" ? n.body : await
|
|
571
|
-
if (!RegExp(`<(${
|
|
572
|
-
let t = RegExp(`<(${
|
|
558
|
+
let e = typeof n.body == "string" ? n.body : await B(r);
|
|
559
|
+
if (!RegExp(`<(${X.join("|")})[\\s/>]`, "i").test(e)) return n;
|
|
560
|
+
let t = RegExp(`<(${X.join("|")})(\\s[^>]*)?\\s*/>`, "gi"), i = e.replace(t, (e, t, n = "") => `<${t} ${n.trim()}></${t}>`);
|
|
573
561
|
return {
|
|
574
562
|
...n,
|
|
575
563
|
body: i
|
|
576
564
|
};
|
|
577
565
|
}
|
|
578
566
|
return n;
|
|
579
|
-
},
|
|
580
|
-
let
|
|
581
|
-
...
|
|
582
|
-
archive:
|
|
583
|
-
resourcePath:
|
|
567
|
+
}, Z = async (e, t, { hooks: n = [] } = {}) => {
|
|
568
|
+
let r = { params: {} }, i = [
|
|
569
|
+
...n.map((n) => n({
|
|
570
|
+
archive: e,
|
|
571
|
+
resourcePath: t
|
|
584
572
|
})),
|
|
585
573
|
ft({
|
|
586
|
-
archive:
|
|
587
|
-
resourcePath:
|
|
574
|
+
archive: e,
|
|
575
|
+
resourcePath: t
|
|
588
576
|
}),
|
|
589
577
|
pt({
|
|
590
|
-
archive:
|
|
591
|
-
resourcePath:
|
|
578
|
+
archive: e,
|
|
579
|
+
resourcePath: t
|
|
592
580
|
}),
|
|
593
581
|
lt({
|
|
594
|
-
archive:
|
|
595
|
-
resourcePath:
|
|
582
|
+
archive: e,
|
|
583
|
+
resourcePath: t
|
|
596
584
|
}),
|
|
597
585
|
ct({
|
|
598
|
-
archive:
|
|
599
|
-
resourcePath:
|
|
586
|
+
archive: e,
|
|
587
|
+
resourcePath: t
|
|
600
588
|
})
|
|
601
589
|
];
|
|
602
590
|
try {
|
|
603
|
-
let
|
|
604
|
-
if (
|
|
605
|
-
let o =
|
|
606
|
-
if (!o) throw Error(`no file found for resourcePath:${
|
|
591
|
+
let n = await i.reduce(async (e, t) => await t(await e), Promise.resolve(r));
|
|
592
|
+
if (a.log("Generated resource", t, n), n.body !== void 0) return n;
|
|
593
|
+
let o = R(e, t);
|
|
594
|
+
if (!o) throw Error(`no file found for resourcePath:${t}`);
|
|
607
595
|
return {
|
|
608
|
-
...
|
|
596
|
+
...n,
|
|
609
597
|
body: await o.blob()
|
|
610
598
|
};
|
|
611
|
-
} catch (
|
|
612
|
-
throw
|
|
599
|
+
} catch (e) {
|
|
600
|
+
throw a.error(e), e;
|
|
613
601
|
}
|
|
614
602
|
}, mt = class {
|
|
615
603
|
constructor(e) {
|
|
@@ -625,62 +613,62 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
625
613
|
});
|
|
626
614
|
}
|
|
627
615
|
get locks$() {
|
|
628
|
-
return this.state$.pipe(
|
|
616
|
+
return this.state$.pipe(D(({ locks: e }) => e));
|
|
629
617
|
}
|
|
630
618
|
get state() {
|
|
631
619
|
return this.state$.getValue();
|
|
632
620
|
}
|
|
633
621
|
get isUnlocked$() {
|
|
634
|
-
return this.locks$.pipe(
|
|
622
|
+
return this.locks$.pipe(D((e) => e <= 0), ce(), me());
|
|
635
623
|
}
|
|
636
624
|
get overTTL$() {
|
|
637
|
-
return this.isUnlocked$.pipe(
|
|
625
|
+
return this.isUnlocked$.pipe(A((e) => e ? this.cleanArchiveAfter === Infinity ? x : _e(this.cleanArchiveAfter) : x));
|
|
638
626
|
}
|
|
639
|
-
}, ht = ({ getArchive:
|
|
640
|
-
let
|
|
641
|
-
return
|
|
642
|
-
let
|
|
643
|
-
if (!
|
|
644
|
-
let
|
|
645
|
-
|
|
646
|
-
let
|
|
647
|
-
delete o[
|
|
627
|
+
}, ht = ({ getArchive: e, cleanArchiveAfter: t = 300 * 1e3 }) => {
|
|
628
|
+
let n = new S(), r = new S(), i = new S(), o = {};
|
|
629
|
+
return n.pipe(k((t) => {
|
|
630
|
+
let n = o[t];
|
|
631
|
+
if (!n || n.state.status !== "idle") return b;
|
|
632
|
+
let r = !1, s = (e) => {
|
|
633
|
+
a.debug(`Cleaning up archive with key: ${e}`);
|
|
634
|
+
let t = o[e];
|
|
635
|
+
delete o[e], r ||= (t?.state.archive?.close(), !0);
|
|
648
636
|
};
|
|
649
|
-
|
|
650
|
-
let c =
|
|
651
|
-
return
|
|
652
|
-
|
|
637
|
+
n.update({ status: "loading" });
|
|
638
|
+
let c = n.locks$, l = n.isUnlocked$, u = c.pipe(pe(), w(([e, t]) => t > e), he(!0));
|
|
639
|
+
return E(e(t)).pipe(j((e) => {
|
|
640
|
+
n.update({
|
|
653
641
|
archive: e,
|
|
654
642
|
status: "success"
|
|
655
643
|
});
|
|
656
|
-
}),
|
|
644
|
+
}), C((e) => (s(t), n.update({
|
|
657
645
|
status: "error",
|
|
658
646
|
error: e
|
|
659
|
-
}),
|
|
660
|
-
s(
|
|
647
|
+
}), b)), A(() => O(u.pipe(A(() => i), A(() => l), w((e) => e)), n.overTTL$).pipe(T(), j(() => {
|
|
648
|
+
s(t);
|
|
661
649
|
}))));
|
|
662
|
-
}), ge(
|
|
650
|
+
}), ge(r)).subscribe(), {
|
|
663
651
|
access: (e) => {
|
|
664
|
-
let
|
|
652
|
+
let r = !1, i = o[e] ?? new mt(t);
|
|
665
653
|
o[e] = i, i.update({ locks: i.state.locks + 1 });
|
|
666
654
|
let a = () => {
|
|
667
|
-
|
|
655
|
+
r || (r = !0, i.update({ locks: i.state.locks - 1 }));
|
|
668
656
|
};
|
|
669
|
-
return
|
|
657
|
+
return n.next(e), O(i.state$.pipe(D(({ archive: e }) => e), w((e) => !!e)), i.state$.pipe(j(({ error: e }) => {
|
|
670
658
|
if (e) throw e;
|
|
671
|
-
}), ue())).pipe(
|
|
659
|
+
}), ue())).pipe(T(), D((e) => ({
|
|
672
660
|
archive: e,
|
|
673
661
|
release: a
|
|
674
|
-
})),
|
|
662
|
+
})), C((e) => {
|
|
675
663
|
throw a(), e;
|
|
676
664
|
}));
|
|
677
665
|
},
|
|
678
666
|
purge: () => {
|
|
679
|
-
|
|
667
|
+
i.next();
|
|
680
668
|
},
|
|
681
669
|
_archives: o
|
|
682
670
|
};
|
|
683
|
-
},
|
|
671
|
+
}, Q = (e) => e ? /^\d+$/.test(e) ? {
|
|
684
672
|
valid: !0,
|
|
685
673
|
value: Number.parseInt(e, 10)
|
|
686
674
|
} : {
|
|
@@ -696,7 +684,7 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
696
684
|
if (t.includes(",")) return { kind: "multi" };
|
|
697
685
|
let n = /^(\d*)-(\d*)$/.exec(t);
|
|
698
686
|
if (!n) return { kind: "invalid" };
|
|
699
|
-
let [, r = "", i = ""] = n, a =
|
|
687
|
+
let [, r = "", i = ""] = n, a = Q(r.trim()), o = Q(i.trim());
|
|
700
688
|
return !a.valid || !o.valid ? { kind: "invalid" } : {
|
|
701
689
|
kind: "single",
|
|
702
690
|
start: a.value,
|
|
@@ -750,16 +738,16 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
750
738
|
status: 206,
|
|
751
739
|
headers: r
|
|
752
740
|
});
|
|
753
|
-
},
|
|
741
|
+
}, $ = "file://", yt = /^https?:\/\//, bt = (e) => {
|
|
754
742
|
try {
|
|
755
743
|
return decodeURIComponent(e);
|
|
756
744
|
} catch {
|
|
757
745
|
return e;
|
|
758
746
|
}
|
|
759
|
-
}, xt = (e) => e.startsWith(
|
|
747
|
+
}, xt = (e) => e.startsWith($) ? e.slice($.length) : e, St = (e) => {
|
|
760
748
|
let t = xt(e);
|
|
761
749
|
return yt.test(t) ? t : xt(bt(t));
|
|
762
|
-
},
|
|
750
|
+
}, Ct = class {
|
|
763
751
|
constructor({ hooks: e, onError: t, onManifestSuccess: n, ...r }) {
|
|
764
752
|
this.onError = (e) => (console.error(e), new Response(String(e), { status: 500 })), this.archiveLoader = ht(r), this.hooks = e ?? {}, this.onManifestSuccess = n ?? (({ manifest: e }) => Promise.resolve(e)), this.onError = t ?? this.onError;
|
|
765
753
|
}
|
|
@@ -770,47 +758,47 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
770
758
|
return this.lastAccessedKey !== void 0 && this.lastAccessedKey !== e && this.archiveLoader.purge(), this.lastAccessedKey = e, this.archiveLoader.access(e);
|
|
771
759
|
}
|
|
772
760
|
accessArchiveWithoutLock(e) {
|
|
773
|
-
return this.accessArchive(e).pipe(
|
|
761
|
+
return this.accessArchive(e).pipe(D(({ archive: e, release: t }) => (t(), e)));
|
|
774
762
|
}
|
|
775
763
|
withArchiveResponse({ key: e, getResponse: t }) {
|
|
776
|
-
return de(this.accessArchive(e).pipe(
|
|
764
|
+
return de(this.accessArchive(e).pipe(k(({ archive: e, release: n }) => E(t(e)).pipe(le(() => {
|
|
777
765
|
n();
|
|
778
|
-
}))),
|
|
766
|
+
}))), C((e) => fe(this.onError(e)))));
|
|
779
767
|
}
|
|
780
768
|
fetchManifest({ key: e, baseUrl: t }) {
|
|
781
769
|
return this.withArchiveResponse({
|
|
782
770
|
key: e,
|
|
783
|
-
getResponse: (e) =>
|
|
771
|
+
getResponse: (e) => E(Y(e, {
|
|
784
772
|
baseUrl: t,
|
|
785
773
|
hooks: this.hooks.manifest
|
|
786
|
-
})).pipe(
|
|
774
|
+
})).pipe(A((t) => E(this.onManifestSuccess({
|
|
787
775
|
manifest: t,
|
|
788
776
|
archive: e
|
|
789
|
-
}))),
|
|
777
|
+
}))), D((e) => new Response(JSON.stringify(e), { status: 200 })))
|
|
790
778
|
});
|
|
791
779
|
}
|
|
792
780
|
fetchResource({ key: e, resourcePath: t, request: n }) {
|
|
793
781
|
return this.withArchiveResponse({
|
|
794
782
|
key: e,
|
|
795
|
-
getResponse: (e) =>
|
|
783
|
+
getResponse: (e) => E(Z(e, St(t), { hooks: this.hooks.resource })).pipe(D((e) => vt({
|
|
796
784
|
body: e.body ?? "",
|
|
797
785
|
contentType: e.params.contentType,
|
|
798
786
|
rangeHeader: n?.headers.get("range")
|
|
799
787
|
})))
|
|
800
788
|
});
|
|
801
789
|
}
|
|
802
|
-
},
|
|
790
|
+
}, wt = class extends Ct {
|
|
803
791
|
constructor({ getUriInfo: e, ...t }) {
|
|
804
792
|
super(t), this.getUriInfo = e, this.fetchEventListener = this.fetchEventListener.bind(this);
|
|
805
793
|
}
|
|
806
794
|
fetchEventListener(e) {
|
|
807
795
|
try {
|
|
808
|
-
let
|
|
809
|
-
if (!
|
|
810
|
-
let
|
|
811
|
-
|
|
796
|
+
let n = this.getUriInfo(e);
|
|
797
|
+
if (!n) return;
|
|
798
|
+
let r = t(n.baseUrl), i = e.request.url.substring(r.length + 1), [a = ""] = i.split("/"), o = t(i.substring(a.length + 1));
|
|
799
|
+
i.endsWith("/manifest") ? e.respondWith(this.fetchManifest({
|
|
812
800
|
key: a,
|
|
813
|
-
baseUrl: `${
|
|
801
|
+
baseUrl: `${r}/${a}/`
|
|
814
802
|
})) : e.respondWith(this.fetchResource({
|
|
815
803
|
key: a,
|
|
816
804
|
resourcePath: o,
|
|
@@ -822,6 +810,6 @@ var ke = m.toLowerCase(), Ae = ({ archive: e }) => async (t) => {
|
|
|
822
810
|
}
|
|
823
811
|
};
|
|
824
812
|
//#endregion
|
|
825
|
-
export {
|
|
813
|
+
export { wt as ServiceWorkerStreamer, Ct as Streamer, c as arrayBufferFileAccessors, s as blobFileAccessors, Oe as configure, r as createArchive, ve as createArchiveFromArrayBufferList, ye as createArchiveFromText, Te as createArchiveFromUrls, F as createUniqueXmlSafeId, P as createXmlSafeId, I as createXmlSafeIdFactory, Y as generateManifestFromArchive, Z as generateResourceFromArchive, R as getArchiveFileRecordByUri, z as getArchiveHasComicInfo, V as getArchiveOpfInfo, n as getUriBasePath, i as getUriBasename, Ee as isDirectoryRecord, L as isFileRecord, B as readRecordAsText, t as removeTrailingSlash, e as sortByTitleComparator };
|
|
826
814
|
|
|
827
815
|
//# sourceMappingURL=index.js.map
|