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