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