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