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