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