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