@prose-reader/streamer 1.206.0 → 1.208.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 +279 -301
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +8 -8
- package/dist/index.umd.cjs.map +1 -1
- package/dist/report.d.ts +1 -7
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,176 +1,153 @@
|
|
|
1
1
|
import $, { XmlDocument as de, XmlTextNode as le, XmlElement as pe } from "xmldoc";
|
|
2
|
-
import { urlJoin as
|
|
3
|
-
import { Subject as R, mergeMap as M, EMPTY as _, pairwise as me, filter as
|
|
4
|
-
let
|
|
5
|
-
const
|
|
2
|
+
import { urlJoin as W, isXmlBasedMimeType as fe, parseContentType as ue, detectMimeTypeFromName as O } from "@prose-reader/shared";
|
|
3
|
+
import { Subject as R, mergeMap as M, EMPTY as _, pairwise as me, filter as D, startWith as he, from as P, tap as j, catchError as C, switchMap as L, merge as q, takeUntil as ge, map as F, ignoreElements as ye, first as be, BehaviorSubject as we, distinctUntilChanged as ve, shareReplay as $e, NEVER as G, timer as xe, finalize as K, of as J, lastValueFrom as Y } from "rxjs";
|
|
4
|
+
let S = !1;
|
|
5
|
+
const v = {
|
|
6
6
|
enable: (e) => {
|
|
7
|
-
|
|
7
|
+
S = e;
|
|
8
8
|
},
|
|
9
9
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
10
10
|
log: (...e) => {
|
|
11
|
-
|
|
11
|
+
S && console.log("[prose-reader-streamer]", ...e);
|
|
12
|
+
},
|
|
13
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
14
|
+
debug: (...e) => {
|
|
15
|
+
S && console.debug("[prose-reader-streamer]", ...e);
|
|
12
16
|
},
|
|
13
17
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
14
18
|
warn: (...e) => {
|
|
15
|
-
|
|
19
|
+
S && console.warn("[prose-reader-streamer]", ...e);
|
|
16
20
|
},
|
|
17
21
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
18
22
|
error: (...e) => {
|
|
19
23
|
console.error(...e);
|
|
20
|
-
},
|
|
21
|
-
time: (e) => {
|
|
22
|
-
T && console.time(`[prose-reader-streamer] [metric] ${e}`);
|
|
23
|
-
},
|
|
24
|
-
timeEnd: (e) => {
|
|
25
|
-
T && console.timeEnd(`[prose-reader-streamer] [metric] ${e}`);
|
|
26
|
-
},
|
|
27
|
-
metric: (e, t = 1 / 0) => {
|
|
28
|
-
const i = typeof e == "number" ? e : e.duration;
|
|
29
|
-
T && (e.duration <= t ? console.log(
|
|
30
|
-
"[prose-reader-streamer] [metric] ",
|
|
31
|
-
`${e.name} took ${i}ms`
|
|
32
|
-
) : console.warn(
|
|
33
|
-
"[prose-reader-streamer] [metric] ",
|
|
34
|
-
`${e.name} took ${e.duration}ms which is above the ${t}ms target for this function`
|
|
35
|
-
));
|
|
36
|
-
},
|
|
37
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
38
|
-
measurePerformance: (e, t, i) => (...s) => {
|
|
39
|
-
const n = performance.now(), r = i(...s);
|
|
40
|
-
if (r != null && r.then)
|
|
41
|
-
return r.then((a) => {
|
|
42
|
-
const c = performance.now();
|
|
43
|
-
return w.metric({ name: e, duration: c - n }, t), a;
|
|
44
|
-
});
|
|
45
|
-
const o = performance.now();
|
|
46
|
-
return w.metric({ name: e, duration: o - n }, t), r;
|
|
47
24
|
}
|
|
48
25
|
}, Fe = (e) => {
|
|
49
26
|
var i;
|
|
50
|
-
const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((
|
|
27
|
+
const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((r) => r.attr.name === "calibre:cover");
|
|
51
28
|
return !!(t && t.attr.name === "calibre:cover");
|
|
52
29
|
}, Ae = (e) => {
|
|
53
|
-
var t, i,
|
|
54
|
-
return (
|
|
30
|
+
var t, i, r;
|
|
31
|
+
return (r = (i = (t = e.descendantWithPath("body")) == null ? void 0 : t.descendantWithPath("div")) == null ? void 0 : i.childrenNamed("svg")) == null ? void 0 : r.find(
|
|
55
32
|
(n) => n.attr.width === "100%" && n.attr.preserveAspectRatio === "none"
|
|
56
33
|
);
|
|
57
34
|
}, Te = ({ archive: e, resourcePath: t }) => async (i) => {
|
|
58
|
-
const
|
|
35
|
+
const r = Object.values(e.files).find(
|
|
59
36
|
(n) => n.uri === t
|
|
60
37
|
);
|
|
61
|
-
if (
|
|
62
|
-
const n = i.body ?? await
|
|
63
|
-
if (Fe(
|
|
64
|
-
const o = Ae(
|
|
38
|
+
if (r != null && r.basename.endsWith(".xhtml")) {
|
|
39
|
+
const n = i.body ?? await r.string(), s = new de(n);
|
|
40
|
+
if (Fe(s)) {
|
|
41
|
+
const o = Ae(s);
|
|
65
42
|
return o && delete o.attr.preserveAspectRatio, {
|
|
66
43
|
...i,
|
|
67
|
-
body:
|
|
44
|
+
body: s == null ? void 0 : s.toString()
|
|
68
45
|
};
|
|
69
46
|
}
|
|
70
47
|
}
|
|
71
48
|
return i;
|
|
72
49
|
}, Le = ({ archive: e, resourcePath: t }) => async (i) => Te({ archive: e, resourcePath: t })(i), We = ({ archive: e, resourcePath: t }) => async (i) => {
|
|
73
|
-
const
|
|
50
|
+
const r = Object.values(e.files).find(
|
|
74
51
|
(n) => n.uri === t
|
|
75
52
|
);
|
|
76
|
-
if (
|
|
77
|
-
const
|
|
53
|
+
if (r != null && r.basename.endsWith(".css")) {
|
|
54
|
+
const s = (i.body ?? await r.string()).replaceAll(
|
|
78
55
|
"-webkit-writing-mode",
|
|
79
56
|
"writing-mode"
|
|
80
57
|
);
|
|
81
58
|
return {
|
|
82
59
|
...i,
|
|
83
|
-
body:
|
|
60
|
+
body: s
|
|
84
61
|
};
|
|
85
62
|
}
|
|
86
63
|
return i;
|
|
87
|
-
}, ee = (e) => e ? e.children.map((t) => t instanceof le ? t.text : t instanceof pe ? ee(t) : "").join("").trim() : "", A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Q = (e) => e.endsWith("/") ? e.slice(0, -1) : e,
|
|
64
|
+
}, ee = (e) => e ? e.children.map((t) => t instanceof le ? t.text : t instanceof pe ? ee(t) : "").join("").trim() : "", A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Q = (e) => e.endsWith("/") ? e.slice(0, -1) : e, Ne = (e) => {
|
|
88
65
|
const t = e.lastIndexOf("/");
|
|
89
66
|
return t >= 0 ? e.substring(0, t) : "";
|
|
90
67
|
}, te = (e, { basePath: t, baseUrl: i }) => {
|
|
91
|
-
const
|
|
68
|
+
const r = {
|
|
92
69
|
contents: [],
|
|
93
70
|
path: "",
|
|
94
71
|
href: "",
|
|
95
72
|
title: ""
|
|
96
73
|
};
|
|
97
74
|
let n = e.childNamed("span") || e.childNamed("a");
|
|
98
|
-
|
|
99
|
-
let
|
|
100
|
-
|
|
75
|
+
r.title = ((n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || ee(n)) ?? "";
|
|
76
|
+
let s = n == null ? void 0 : n.name;
|
|
77
|
+
s !== "a" && (n = e.descendantWithPath(`${s}.a`), n && (s = n.name.toLowerCase())), s === "a" && (n != null && n.attr.href) && (r.path = W(t, n.attr.href), r.href = W(i, t, n.attr.href));
|
|
101
78
|
const o = e.childNamed("ol");
|
|
102
79
|
if (o) {
|
|
103
80
|
const a = o.childrenNamed("li");
|
|
104
|
-
a && a.length > 0 && (
|
|
105
|
-
(
|
|
81
|
+
a && a.length > 0 && (r.contents = a.map(
|
|
82
|
+
(d) => te(d, { basePath: t, baseUrl: i })
|
|
106
83
|
));
|
|
107
84
|
}
|
|
108
|
-
return
|
|
109
|
-
},
|
|
110
|
-
var
|
|
111
|
-
const
|
|
85
|
+
return r;
|
|
86
|
+
}, ke = (e, { basePath: t, baseUrl: i }) => {
|
|
87
|
+
var s, o;
|
|
88
|
+
const r = [];
|
|
112
89
|
let n;
|
|
113
|
-
return e.descendantWithPath("body.nav.ol") ? n = (
|
|
114
|
-
(a) =>
|
|
115
|
-
),
|
|
90
|
+
return e.descendantWithPath("body.nav.ol") ? n = (s = e.descendantWithPath("body.nav.ol")) == null ? void 0 : s.children : e.descendantWithPath("body.section.nav.ol") && (n = (o = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : o.children), n && n.length > 0 && n.filter((a) => a.name === "li").forEach(
|
|
91
|
+
(a) => r.push(te(a, { basePath: t, baseUrl: i }))
|
|
92
|
+
), r;
|
|
116
93
|
}, Se = async (e, t, { baseUrl: i }) => {
|
|
117
94
|
var n;
|
|
118
|
-
const
|
|
119
|
-
if (
|
|
120
|
-
const
|
|
121
|
-
(o) => o.uri.endsWith(
|
|
95
|
+
const r = (n = e.childNamed("manifest")) == null ? void 0 : n.childrenNamed("item").find((s) => s.attr.properties === "nav");
|
|
96
|
+
if (r) {
|
|
97
|
+
const s = Object.values(t.files).find(
|
|
98
|
+
(o) => o.uri.endsWith(r.attr.href || "")
|
|
122
99
|
);
|
|
123
|
-
if (
|
|
124
|
-
const o = new $.XmlDocument(await
|
|
125
|
-
return
|
|
100
|
+
if (s) {
|
|
101
|
+
const o = new $.XmlDocument(await s.string()), a = Ne(s.uri);
|
|
102
|
+
return ke(o, { basePath: a, baseUrl: i });
|
|
126
103
|
}
|
|
127
104
|
}
|
|
128
105
|
}, ne = (e, {
|
|
129
106
|
opfBasePath: t,
|
|
130
107
|
baseUrl: i,
|
|
131
|
-
prefix:
|
|
108
|
+
prefix: r
|
|
132
109
|
}) => {
|
|
133
|
-
var a,
|
|
134
|
-
const n = ((a = e == null ? void 0 : e.childNamed(`${
|
|
135
|
-
title: ((
|
|
136
|
-
path:
|
|
137
|
-
href:
|
|
110
|
+
var a, d;
|
|
111
|
+
const n = ((a = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : a.attr.src) || "", s = {
|
|
112
|
+
title: ((d = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : d.val) || "",
|
|
113
|
+
path: W(t, n),
|
|
114
|
+
href: W(i, t, n),
|
|
138
115
|
contents: []
|
|
139
|
-
}, o = e.childrenNamed(`${
|
|
140
|
-
return o && o.length > 0 && (
|
|
141
|
-
(l) => ne(l, { opfBasePath: t, baseUrl: i, prefix:
|
|
142
|
-
)),
|
|
116
|
+
}, o = e.childrenNamed(`${r}navPoint`);
|
|
117
|
+
return o && o.length > 0 && (s.contents = o.map(
|
|
118
|
+
(l) => ne(l, { opfBasePath: t, baseUrl: i, prefix: r })
|
|
119
|
+
)), s;
|
|
143
120
|
}, Pe = (e, { opfBasePath: t, baseUrl: i }) => {
|
|
144
121
|
var o;
|
|
145
|
-
const
|
|
146
|
-
let
|
|
147
|
-
return n.indexOf(":") !== -1 && (
|
|
148
|
-
(a) =>
|
|
149
|
-
),
|
|
150
|
-
},
|
|
122
|
+
const r = [], n = e.name;
|
|
123
|
+
let s = "";
|
|
124
|
+
return n.indexOf(":") !== -1 && (s = `${n.split(":")[0]}:`), (o = e.childNamed(`${s}navMap`)) == null || o.childrenNamed(`${s}navPoint`).forEach(
|
|
125
|
+
(a) => r.push(ne(a, { opfBasePath: t, baseUrl: i, prefix: s }))
|
|
126
|
+
), r;
|
|
127
|
+
}, Ce = async ({
|
|
151
128
|
opfData: e,
|
|
152
129
|
opfBasePath: t,
|
|
153
130
|
baseUrl: i,
|
|
154
|
-
archive:
|
|
131
|
+
archive: r
|
|
155
132
|
}) => {
|
|
156
133
|
var o;
|
|
157
|
-
const n = e.childNamed("spine"),
|
|
158
|
-
if (
|
|
159
|
-
const a = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((
|
|
134
|
+
const n = e.childNamed("spine"), s = n == null ? void 0 : n.attr.toc;
|
|
135
|
+
if (s) {
|
|
136
|
+
const a = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((d) => d.attr.id === s);
|
|
160
137
|
if (a) {
|
|
161
|
-
const
|
|
162
|
-
(
|
|
138
|
+
const d = `${t}${t === "" ? "" : "/"}${a.attr.href}`, l = Object.values(r.files).find(
|
|
139
|
+
(c) => c.uri.endsWith(d)
|
|
163
140
|
);
|
|
164
141
|
if (l) {
|
|
165
|
-
const
|
|
166
|
-
return Pe(
|
|
142
|
+
const c = new $.XmlDocument(await l.string());
|
|
143
|
+
return Pe(c, { opfBasePath: t, baseUrl: i });
|
|
167
144
|
}
|
|
168
145
|
}
|
|
169
146
|
}
|
|
170
|
-
},
|
|
171
|
-
const { basePath:
|
|
147
|
+
}, Ie = async (e, t, { baseUrl: i }) => {
|
|
148
|
+
const { basePath: r } = N(t) || {}, n = await Ce({
|
|
172
149
|
opfData: e,
|
|
173
|
-
opfBasePath:
|
|
150
|
+
opfBasePath: r,
|
|
174
151
|
archive: t,
|
|
175
152
|
baseUrl: i
|
|
176
153
|
});
|
|
@@ -178,8 +155,8 @@ const w = {
|
|
|
178
155
|
baseUrl: i
|
|
179
156
|
});
|
|
180
157
|
}, Re = (e) => {
|
|
181
|
-
var
|
|
182
|
-
const t = ((
|
|
158
|
+
var r;
|
|
159
|
+
const t = ((r = e.attr.properties) == null ? void 0 : r.split(" ")) || [];
|
|
183
160
|
let i;
|
|
184
161
|
return t.find((n) => n === "rendition:layout-reflowable") && (i = "reflowable"), t.find((n) => n === "rendition:layout-pre-paginated") && (i = "pre-paginated"), {
|
|
185
162
|
renditionLayout: i,
|
|
@@ -187,7 +164,7 @@ const w = {
|
|
|
187
164
|
pageSpreadRight: t.some((n) => n === "page-spread-right") || void 0
|
|
188
165
|
};
|
|
189
166
|
}, N = (e) => {
|
|
190
|
-
const i = Object.values(e.files).filter((
|
|
167
|
+
const i = Object.values(e.files).filter((r) => !r.dir).find((r) => r.uri.endsWith(".opf"));
|
|
191
168
|
return {
|
|
192
169
|
data: i,
|
|
193
170
|
basePath: (i == null ? void 0 : i.uri.substring(0, i.uri.lastIndexOf("/"))) || ""
|
|
@@ -195,36 +172,36 @@ const w = {
|
|
|
195
172
|
}, re = async ({
|
|
196
173
|
archive: e
|
|
197
174
|
}) => {
|
|
198
|
-
const { data: t, basePath: i } = N(e) || {},
|
|
199
|
-
if (!
|
|
200
|
-
const n = new $.XmlDocument(
|
|
201
|
-
return e.files.filter((
|
|
202
|
-
},
|
|
203
|
-
const
|
|
175
|
+
const { data: t, basePath: i } = N(e) || {}, r = await (t == null ? void 0 : t.string());
|
|
176
|
+
if (!r) return [];
|
|
177
|
+
const n = new $.XmlDocument(r), s = n.childNamed("manifest"), o = n.childNamed("spine"), a = o == null ? void 0 : o.childrenNamed("itemref").map((c) => c.attr.idref), d = (s == null ? void 0 : s.childrenNamed("item").filter((c) => a.includes(c.attr.id || ""))) || [];
|
|
178
|
+
return e.files.filter((c) => d.find((p) => i ? `${i}/${p.attr.href}` === c.uri : `${p.attr.href}` === c.uri));
|
|
179
|
+
}, De = (e, t, i) => {
|
|
180
|
+
const r = e.attr.href || "", n = i == null ? void 0 : i(e);
|
|
204
181
|
return {
|
|
205
|
-
href: t ? `${n}${t}/${
|
|
182
|
+
href: t ? `${n}${t}/${r}` : `${n}${r}`,
|
|
206
183
|
id: e.attr.id || "",
|
|
207
184
|
mediaType: e.attr["media-type"]
|
|
208
185
|
};
|
|
209
186
|
}, se = (e, t, i) => {
|
|
210
|
-
var
|
|
211
|
-
const
|
|
212
|
-
return ((
|
|
213
|
-
},
|
|
187
|
+
var s;
|
|
188
|
+
const r = e.childNamed("manifest"), { basePath: n } = N(t) || {};
|
|
189
|
+
return ((s = r == null ? void 0 : r.childrenNamed("item")) == null ? void 0 : s.map((o) => De(o, n, i))) || [];
|
|
190
|
+
}, je = ({ archive: e, baseUrl: t }) => async (i) => {
|
|
214
191
|
var X;
|
|
215
|
-
const { data:
|
|
216
|
-
if (!
|
|
192
|
+
const { data: r, basePath: n } = N(e) || {};
|
|
193
|
+
if (!r)
|
|
217
194
|
return i;
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
const o = new $.XmlDocument(
|
|
195
|
+
const s = await r.string();
|
|
196
|
+
v.log("data", s);
|
|
197
|
+
const o = new $.XmlDocument(s), a = await Ie(o, e, { baseUrl: t }) || [], d = o.childNamed("metadata"), l = o.childNamed("manifest"), c = o.childNamed("spine"), p = o.childNamed("guide"), u = d == null ? void 0 : d.childNamed("dc:title"), g = (d == null ? void 0 : d.childrenNamed("meta")) || [], b = g.find(
|
|
221
198
|
(m) => m.attr.property === "rendition:layout"
|
|
222
199
|
), h = g.find(
|
|
223
200
|
(m) => m.attr.property === "rendition:flow"
|
|
224
201
|
), x = g.find(
|
|
225
202
|
(m) => m.attr.property === "rendition:spread"
|
|
226
|
-
), y = b == null ? void 0 : b.val,
|
|
227
|
-
(m,
|
|
203
|
+
), y = b == null ? void 0 : b.val, w = h == null ? void 0 : h.val, k = x == null ? void 0 : x.val, ie = (u == null ? void 0 : u.val) || ((X = e.files.find(({ dir: m }) => m)) == null ? void 0 : X.basename) || "", oe = c == null ? void 0 : c.attr["page-progression-direction"], ae = (await re({ archive: e })).reduce(
|
|
204
|
+
(m, T) => T.size + m,
|
|
228
205
|
0
|
|
229
206
|
);
|
|
230
207
|
return {
|
|
@@ -233,30 +210,30 @@ const w = {
|
|
|
233
210
|
toc: a
|
|
234
211
|
},
|
|
235
212
|
renditionLayout: y,
|
|
236
|
-
renditionFlow:
|
|
237
|
-
renditionSpread:
|
|
213
|
+
renditionFlow: w || "auto",
|
|
214
|
+
renditionSpread: k,
|
|
238
215
|
title: ie,
|
|
239
216
|
readingDirection: oe || "ltr",
|
|
240
217
|
/**
|
|
241
218
|
* @see https://www.w3.org/TR/epub/#sec-itemref-elem
|
|
242
219
|
*/
|
|
243
|
-
spineItems: (
|
|
244
|
-
var
|
|
245
|
-
const f = l == null ? void 0 : l.childrenNamed("item").find((
|
|
220
|
+
spineItems: (c == null ? void 0 : c.childrenNamed("itemref").map((m, T) => {
|
|
221
|
+
var H, V;
|
|
222
|
+
const f = l == null ? void 0 : l.childrenNamed("item").find((I) => I.attr.id === (m == null ? void 0 : m.attr.idref)), U = (f == null ? void 0 : f.attr.href) || "", ce = ((H = e.files.find((I) => I.uri.endsWith(U))) == null ? void 0 : H.size) || 0, B = t || (/^https?:\/\//.test(U) ? "" : "file://"), E = Re(m);
|
|
246
223
|
return {
|
|
247
|
-
...
|
|
224
|
+
...E,
|
|
248
225
|
id: (f == null ? void 0 : f.attr.id) || "",
|
|
249
|
-
index:
|
|
250
|
-
href: (
|
|
251
|
-
renditionLayout:
|
|
226
|
+
index: T,
|
|
227
|
+
href: (V = f == null ? void 0 : f.attr.href) != null && V.startsWith("https://") ? f == null ? void 0 : f.attr.href : n ? `${B}${n}/${f == null ? void 0 : f.attr.href}` : `${B}${f == null ? void 0 : f.attr.href}`,
|
|
228
|
+
renditionLayout: E.renditionLayout ?? y,
|
|
252
229
|
progressionWeight: ce / ae,
|
|
253
230
|
// size: itemSize
|
|
254
231
|
mediaType: f == null ? void 0 : f.attr["media-type"]
|
|
255
232
|
};
|
|
256
233
|
})) || [],
|
|
257
234
|
items: se(o, e, (m) => {
|
|
258
|
-
const
|
|
259
|
-
return /^https?:\/\//.test(
|
|
235
|
+
const T = m.attr.href || "";
|
|
236
|
+
return /^https?:\/\//.test(T) ? "" : t || "file://";
|
|
260
237
|
}),
|
|
261
238
|
guide: p == null ? void 0 : p.childrenNamed("reference").map((m) => ({
|
|
262
239
|
href: m.attr.href || "",
|
|
@@ -265,15 +242,15 @@ const w = {
|
|
|
265
242
|
}))
|
|
266
243
|
};
|
|
267
244
|
}, Oe = async (e, t) => {
|
|
268
|
-
var n,
|
|
269
|
-
const
|
|
270
|
-
if (
|
|
271
|
-
const a = new $.XmlDocument(
|
|
272
|
-
if ((
|
|
273
|
-
(
|
|
274
|
-
)) == null ? void 0 :
|
|
245
|
+
var n, s, o;
|
|
246
|
+
const r = await ((n = N(e).data) == null ? void 0 : n.string());
|
|
247
|
+
if (r) {
|
|
248
|
+
const a = new $.XmlDocument(r), d = se(a, e, () => "");
|
|
249
|
+
if ((s = d.find(
|
|
250
|
+
(c) => t.endsWith(c.href)
|
|
251
|
+
)) == null ? void 0 : s.mediaType)
|
|
275
252
|
return {
|
|
276
|
-
mediaType: (o =
|
|
253
|
+
mediaType: (o = d.find((c) => t.endsWith(c.href))) == null ? void 0 : o.mediaType
|
|
277
254
|
};
|
|
278
255
|
}
|
|
279
256
|
return {
|
|
@@ -291,17 +268,17 @@ const w = {
|
|
|
291
268
|
if (e.endsWith(".svg"))
|
|
292
269
|
return "image/svg+xml";
|
|
293
270
|
}, ze = ({ archive: e, resourcePath: t }) => async (i) => {
|
|
294
|
-
const
|
|
295
|
-
(
|
|
271
|
+
const r = Object.values(e.files).find(
|
|
272
|
+
(s) => s.uri === t
|
|
296
273
|
);
|
|
297
|
-
if (!
|
|
274
|
+
if (!r) return i;
|
|
298
275
|
const n = await Oe(e, t);
|
|
299
276
|
return {
|
|
300
277
|
...i,
|
|
301
278
|
params: {
|
|
302
279
|
...i.params,
|
|
303
|
-
...(
|
|
304
|
-
contentType:
|
|
280
|
+
...(r == null ? void 0 : r.encodingFormat) && {
|
|
281
|
+
contentType: r.encodingFormat
|
|
305
282
|
},
|
|
306
283
|
...n.mediaType && {
|
|
307
284
|
contentType: n.mediaType
|
|
@@ -360,11 +337,11 @@ const w = {
|
|
|
360
337
|
"script",
|
|
361
338
|
"style"
|
|
362
339
|
], Xe = ({ archive: e, resourcePath: t }) => async (i) => {
|
|
363
|
-
const
|
|
340
|
+
const r = Object.values(e.files).find(
|
|
364
341
|
(n) => n.uri === t
|
|
365
342
|
);
|
|
366
|
-
if (
|
|
367
|
-
const n = i.body ?? await
|
|
343
|
+
if (r != null && r.basename.endsWith(".xhtml")) {
|
|
344
|
+
const n = i.body ?? await r.string();
|
|
368
345
|
if (!new RegExp(
|
|
369
346
|
`<(${Z.join("|")})[\\s/>]`,
|
|
370
347
|
"i"
|
|
@@ -375,7 +352,7 @@ const w = {
|
|
|
375
352
|
"gi"
|
|
376
353
|
), a = n.replace(
|
|
377
354
|
o,
|
|
378
|
-
(
|
|
355
|
+
(d, l, c = "") => `<${l} ${c.trim()}></${l}>`
|
|
379
356
|
);
|
|
380
357
|
return {
|
|
381
358
|
...i,
|
|
@@ -385,11 +362,11 @@ const w = {
|
|
|
385
362
|
return i;
|
|
386
363
|
}, Ue = async (e, t) => {
|
|
387
364
|
const i = Object.values(e.files).find(
|
|
388
|
-
(
|
|
365
|
+
(s) => s.uri === t
|
|
389
366
|
);
|
|
390
367
|
if (!i)
|
|
391
368
|
throw new Error("no file found");
|
|
392
|
-
const
|
|
369
|
+
const r = {
|
|
393
370
|
params: {}
|
|
394
371
|
}, n = [
|
|
395
372
|
ze({ archive: e, resourcePath: t }),
|
|
@@ -398,31 +375,31 @@ const w = {
|
|
|
398
375
|
Le({ archive: e, resourcePath: t })
|
|
399
376
|
];
|
|
400
377
|
try {
|
|
401
|
-
const
|
|
402
|
-
return
|
|
403
|
-
...
|
|
404
|
-
body:
|
|
378
|
+
const s = await n.reduce(async (o, a) => await a(await o), Promise.resolve(r));
|
|
379
|
+
return v.log("Generated resource", t, s), {
|
|
380
|
+
...s,
|
|
381
|
+
body: s.body ?? await i.blob()
|
|
405
382
|
};
|
|
406
|
-
} catch (
|
|
407
|
-
throw
|
|
383
|
+
} catch (s) {
|
|
384
|
+
throw v.error(s), s;
|
|
408
385
|
}
|
|
409
386
|
}, Be = ({ archive: e, baseUrl: t }) => async () => {
|
|
410
|
-
var
|
|
387
|
+
var r;
|
|
411
388
|
const i = Object.values(e.files).filter((n) => !n.dir);
|
|
412
389
|
return {
|
|
413
390
|
filename: e.filename,
|
|
414
|
-
title: ((
|
|
391
|
+
title: ((r = e.files.find(({ dir: n }) => n)) == null ? void 0 : r.basename.replace(/\/$/, "")) || "",
|
|
415
392
|
renditionLayout: void 0,
|
|
416
393
|
renditionSpread: "auto",
|
|
417
394
|
readingDirection: "ltr",
|
|
418
|
-
spineItems: i.filter((n) => !n.basename.endsWith(".db")).map((n,
|
|
395
|
+
spineItems: i.filter((n) => !n.basename.endsWith(".db")).map((n, s) => {
|
|
419
396
|
const o = t || (/^https?:\/\//.test(n.uri) ? "" : "file://");
|
|
420
397
|
return {
|
|
421
398
|
// some books such as cbz can have same basename inside different sub folder
|
|
422
399
|
// we need to make sure to have unique index
|
|
423
400
|
// /chap01/01.png, /chap02/01.png, etc
|
|
424
|
-
id: `${
|
|
425
|
-
index:
|
|
401
|
+
id: `${s}.${n.basename}`,
|
|
402
|
+
index: s,
|
|
426
403
|
href: encodeURI(`${o}${n.uri}`),
|
|
427
404
|
renditionLayout: void 0,
|
|
428
405
|
progressionWeight: 1 / i.length,
|
|
@@ -431,33 +408,33 @@ const w = {
|
|
|
431
408
|
mediaType: n.encodingFormat
|
|
432
409
|
};
|
|
433
410
|
}),
|
|
434
|
-
items: i.map((n,
|
|
435
|
-
id: `${
|
|
411
|
+
items: i.map((n, s) => ({
|
|
412
|
+
id: `${s}.${n.basename}`,
|
|
436
413
|
href: encodeURI(`${t}${n.uri}`)
|
|
437
414
|
}))
|
|
438
415
|
};
|
|
439
|
-
},
|
|
416
|
+
}, Ee = async (e) => {
|
|
440
417
|
const t = {
|
|
441
418
|
renditionLayout: void 0
|
|
442
419
|
};
|
|
443
420
|
return await Promise.all(
|
|
444
421
|
e.files.map(async (i) => {
|
|
445
|
-
var
|
|
422
|
+
var r, n;
|
|
446
423
|
if (i.uri.endsWith("com.kobobooks.display-options.xml")) {
|
|
447
|
-
const o = (
|
|
424
|
+
const o = (r = new $.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : r.childNamed("option");
|
|
448
425
|
((n = o == null ? void 0 : o.attr) == null ? void 0 : n.name) === "fixed-layout" && o.val === "true" && (t.renditionLayout = "pre-paginated");
|
|
449
426
|
}
|
|
450
427
|
})
|
|
451
428
|
), t;
|
|
452
|
-
},
|
|
453
|
-
const i = await
|
|
429
|
+
}, He = ({ archive: e }) => async (t) => {
|
|
430
|
+
const i = await Ee(e);
|
|
454
431
|
return {
|
|
455
432
|
...t,
|
|
456
433
|
renditionLayout: t.renditionLayout ?? i.renditionLayout
|
|
457
434
|
};
|
|
458
|
-
},
|
|
435
|
+
}, Ve = (e) => {
|
|
459
436
|
var i;
|
|
460
|
-
const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((
|
|
437
|
+
const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((r) => r.attr.name === "viewport");
|
|
461
438
|
return !!(t && t.attr.name === "viewport");
|
|
462
439
|
}, _e = (e) => e.reduce(async (t, i) => {
|
|
463
440
|
if (!await t || !fe({
|
|
@@ -466,15 +443,15 @@ const w = {
|
|
|
466
443
|
}))
|
|
467
444
|
return !1;
|
|
468
445
|
const n = await i.string();
|
|
469
|
-
return n ?
|
|
446
|
+
return n ? Ve(new $.XmlDocument(n)) : !1;
|
|
470
447
|
}, Promise.resolve(!0)), qe = ({ archive: e }) => async (t) => {
|
|
471
|
-
if (t.renditionLayout === "reflowable" && t.spineItems.every((
|
|
472
|
-
const
|
|
473
|
-
if (await _e(
|
|
448
|
+
if (t.renditionLayout === "reflowable" && t.spineItems.every((r) => r.renditionLayout === "reflowable")) {
|
|
449
|
+
const r = await re({ archive: e });
|
|
450
|
+
if (await _e(r))
|
|
474
451
|
return {
|
|
475
452
|
...t,
|
|
476
|
-
spineItems: t.spineItems.map((
|
|
477
|
-
...
|
|
453
|
+
spineItems: t.spineItems.map((s) => ({
|
|
454
|
+
...s,
|
|
478
455
|
renditionLayout: "pre-paginated"
|
|
479
456
|
})),
|
|
480
457
|
renditionLayout: "pre-paginated"
|
|
@@ -483,28 +460,28 @@ const w = {
|
|
|
483
460
|
return t;
|
|
484
461
|
}, z = (e, t) => {
|
|
485
462
|
var n;
|
|
486
|
-
const i = e.split(/(\d+)/),
|
|
487
|
-
for (let
|
|
488
|
-
if (i[
|
|
489
|
-
return (n = i[
|
|
463
|
+
const i = e.split(/(\d+)/), r = t.split(/(\d+)/);
|
|
464
|
+
for (let s = 0, o = i.length; s < o; s++)
|
|
465
|
+
if (i[s] !== r[s])
|
|
466
|
+
return (n = i[s]) != null && n.match(/\d/) ? +(i[s] || "") - +(r[s] || "") : (i[s] || "").localeCompare(r[s] || "");
|
|
490
467
|
return 1;
|
|
491
468
|
}, Ge = ({ archive: e, baseUrl: t }) => async (i) => {
|
|
492
469
|
if (i.nav) return i;
|
|
493
|
-
const
|
|
494
|
-
(a,
|
|
495
|
-
), n = Object.values(
|
|
496
|
-
const u = a.find((h) => h.title ===
|
|
470
|
+
const r = [...e.files].sort(
|
|
471
|
+
(a, d) => z(a.uri, d.uri)
|
|
472
|
+
), n = Object.values(r), s = (a, d, l, c, p) => {
|
|
473
|
+
const u = a.find((h) => h.title === d), [g, ...b] = l;
|
|
497
474
|
return u ? g ? [
|
|
498
475
|
...a.filter((x) => x !== u),
|
|
499
476
|
{
|
|
500
477
|
...u,
|
|
501
478
|
contents: [
|
|
502
479
|
...u.contents,
|
|
503
|
-
...
|
|
480
|
+
...s(
|
|
504
481
|
u.contents,
|
|
505
482
|
g,
|
|
506
483
|
b,
|
|
507
|
-
|
|
484
|
+
c,
|
|
508
485
|
p
|
|
509
486
|
)
|
|
510
487
|
]
|
|
@@ -514,38 +491,38 @@ const w = {
|
|
|
514
491
|
{
|
|
515
492
|
...u,
|
|
516
493
|
path: p,
|
|
517
|
-
href:
|
|
494
|
+
href: c
|
|
518
495
|
}
|
|
519
496
|
] : a : g ? [
|
|
520
497
|
...a,
|
|
521
498
|
{
|
|
522
|
-
contents:
|
|
499
|
+
contents: s(
|
|
523
500
|
[],
|
|
524
501
|
g,
|
|
525
502
|
b,
|
|
526
|
-
|
|
503
|
+
c,
|
|
527
504
|
p
|
|
528
505
|
),
|
|
529
|
-
href:
|
|
506
|
+
href: c,
|
|
530
507
|
path: p,
|
|
531
|
-
title:
|
|
508
|
+
title: d
|
|
532
509
|
}
|
|
533
510
|
] : [
|
|
534
511
|
...a,
|
|
535
512
|
{
|
|
536
513
|
contents: [],
|
|
537
|
-
href:
|
|
514
|
+
href: c,
|
|
538
515
|
path: p,
|
|
539
|
-
title:
|
|
516
|
+
title: d
|
|
540
517
|
}
|
|
541
518
|
];
|
|
542
519
|
}, o = n.reduce(
|
|
543
|
-
(a,
|
|
544
|
-
if (
|
|
545
|
-
const
|
|
520
|
+
(a, d) => {
|
|
521
|
+
if (d.dir) return a;
|
|
522
|
+
const c = d.uri.split("/").slice(0, -1), [p, ...u] = c;
|
|
546
523
|
if (p) {
|
|
547
|
-
const g =
|
|
548
|
-
return
|
|
524
|
+
const g = W(t, encodeURI(d.uri)).replace(/\/$/, ""), b = d.uri.replace(/\/$/, "");
|
|
525
|
+
return s(a, p, u, g, b);
|
|
549
526
|
}
|
|
550
527
|
return a;
|
|
551
528
|
},
|
|
@@ -558,76 +535,76 @@ const w = {
|
|
|
558
535
|
}
|
|
559
536
|
};
|
|
560
537
|
}, Ke = ({ archive: e }) => async (t) => {
|
|
561
|
-
var
|
|
538
|
+
var s;
|
|
562
539
|
const i = e.files.find(
|
|
563
540
|
(o) => o.basename.toLowerCase() === "comicinfo.xml"
|
|
564
541
|
);
|
|
565
542
|
if (!i)
|
|
566
543
|
return t;
|
|
567
|
-
const
|
|
544
|
+
const r = {
|
|
568
545
|
...t,
|
|
569
|
-
spineItems: t.spineItems.filter((o) => !o.id.toLowerCase().endsWith("comicinfo.xml")).map((o, a,
|
|
546
|
+
spineItems: t.spineItems.filter((o) => !o.id.toLowerCase().endsWith("comicinfo.xml")).map((o, a, d) => ({
|
|
570
547
|
...o,
|
|
571
|
-
progressionWeight: 1 /
|
|
548
|
+
progressionWeight: 1 / d.length
|
|
572
549
|
}))
|
|
573
550
|
}, n = await i.string();
|
|
574
551
|
try {
|
|
575
|
-
const a = ((
|
|
552
|
+
const a = ((s = new $.XmlDocument(n).childNamed("Manga")) == null ? void 0 : s.val) || "unknown";
|
|
576
553
|
return {
|
|
577
|
-
...
|
|
554
|
+
...r,
|
|
578
555
|
readingDirection: a === "YesAndRightToLeft" ? "rtl" : "ltr"
|
|
579
556
|
};
|
|
580
557
|
} catch (o) {
|
|
581
558
|
return console.error(`Unable to parse comicinfo.xml for content
|
|
582
|
-
`, n), console.error(o),
|
|
559
|
+
`, n), console.error(o), r;
|
|
583
560
|
}
|
|
584
561
|
}, Je = (e) => e.files.some((t) => t.basename.endsWith(".opf")), Ye = ({ archive: e }) => async (t) => Je(e) ? t : {
|
|
585
562
|
...t,
|
|
586
|
-
spineItems: t.spineItems.map((
|
|
563
|
+
spineItems: t.spineItems.map((r) => {
|
|
587
564
|
const n = e.files.find(
|
|
588
|
-
(o) => decodeURI(
|
|
589
|
-
),
|
|
565
|
+
(o) => decodeURI(r.href).endsWith(o.uri)
|
|
566
|
+
), s = ue((n == null ? void 0 : n.encodingFormat) ?? "") ?? O((n == null ? void 0 : n.basename) ?? "");
|
|
590
567
|
return {
|
|
591
|
-
...
|
|
592
|
-
renditionLayout:
|
|
568
|
+
...r,
|
|
569
|
+
renditionLayout: s != null && s.startsWith("image/") ? "pre-paginated" : r.renditionLayout
|
|
593
570
|
};
|
|
594
571
|
})
|
|
595
572
|
}, Qe = ({ archive: e }) => async (t) => {
|
|
596
|
-
var n,
|
|
573
|
+
var n, s;
|
|
597
574
|
const i = e.files.find(
|
|
598
575
|
(o) => o.basename.toLowerCase() === "com.apple.ibooks.display-options.xml"
|
|
599
576
|
);
|
|
600
577
|
if (!i)
|
|
601
578
|
return t;
|
|
602
|
-
const
|
|
579
|
+
const r = await (await i.blob()).text();
|
|
603
580
|
try {
|
|
604
|
-
const a = new $.XmlDocument(
|
|
581
|
+
const a = new $.XmlDocument(r).childNamed("platform"), d = ((s = (n = a == null ? void 0 : a.childrenNamed("option")) == null ? void 0 : n.find((l) => l.attr.name === "fixed-layout")) == null ? void 0 : s.val) || "false";
|
|
605
582
|
return {
|
|
606
583
|
...t,
|
|
607
|
-
renditionLayout:
|
|
584
|
+
renditionLayout: d === "true" ? "pre-paginated" : t.renditionLayout
|
|
608
585
|
};
|
|
609
586
|
} catch (o) {
|
|
610
587
|
return console.error(
|
|
611
588
|
`Unable to parse com.apple.ibooks.display-options.xml for content
|
|
612
589
|
`,
|
|
613
|
-
|
|
590
|
+
r
|
|
614
591
|
), console.error(o), t;
|
|
615
592
|
}
|
|
616
593
|
}, Ze = async (e, { baseUrl: t = "" } = {}) => {
|
|
617
594
|
const i = [
|
|
618
|
-
|
|
595
|
+
je({ archive: e, baseUrl: t }),
|
|
619
596
|
Ke({ archive: e }),
|
|
620
597
|
Qe({ archive: e }),
|
|
621
598
|
Ye({ archive: e }),
|
|
622
599
|
qe({ archive: e }),
|
|
623
|
-
|
|
600
|
+
He({ archive: e }),
|
|
624
601
|
Ge({ archive: e, baseUrl: t })
|
|
625
602
|
];
|
|
626
603
|
try {
|
|
627
|
-
const
|
|
628
|
-
return
|
|
629
|
-
} catch (
|
|
630
|
-
throw
|
|
604
|
+
const r = Be({ archive: e, baseUrl: t })(), n = await i.reduce(async (s, o) => await o(await s), r);
|
|
605
|
+
return v.log("Generated manifest", n), n;
|
|
606
|
+
} catch (r) {
|
|
607
|
+
throw v.error(r), r;
|
|
631
608
|
}
|
|
632
609
|
}, at = async (e, t) => {
|
|
633
610
|
const i = `
|
|
@@ -638,22 +615,22 @@ const w = {
|
|
|
638
615
|
</metadata>
|
|
639
616
|
<manifest>
|
|
640
617
|
${e.map(
|
|
641
|
-
(
|
|
618
|
+
(s) => `<item id="${A(s)}" href="${s}" media-type="${O(s)}"/>`
|
|
642
619
|
).join(`
|
|
643
620
|
`)}
|
|
644
621
|
</manifest>
|
|
645
622
|
<spine>
|
|
646
|
-
${e.map((
|
|
623
|
+
${e.map((s) => `<itemref idref="${A(s)}" />`).join(`
|
|
647
624
|
`)}
|
|
648
625
|
</spine>
|
|
649
626
|
</package>
|
|
650
|
-
`,
|
|
627
|
+
`, r = e.map((s) => ({
|
|
651
628
|
dir: !1,
|
|
652
|
-
basename: A(
|
|
653
|
-
encodingFormat: O(
|
|
654
|
-
uri:
|
|
629
|
+
basename: A(s),
|
|
630
|
+
encodingFormat: O(s),
|
|
631
|
+
uri: s,
|
|
655
632
|
size: 100 / e.length,
|
|
656
|
-
blob: async () => (await fetch(
|
|
633
|
+
blob: async () => (await fetch(s)).blob(),
|
|
657
634
|
string: async () => ""
|
|
658
635
|
}));
|
|
659
636
|
return {
|
|
@@ -665,14 +642,14 @@ const w = {
|
|
|
665
642
|
size: 0,
|
|
666
643
|
blob: async () => new Blob(),
|
|
667
644
|
string: async () => i
|
|
668
|
-
}, ...
|
|
645
|
+
}, ...r],
|
|
669
646
|
close: () => Promise.resolve()
|
|
670
647
|
};
|
|
671
648
|
}, ct = async (e, {
|
|
672
649
|
mimeType: t,
|
|
673
650
|
direction: i
|
|
674
651
|
} = { mimeType: "text/plain" }) => {
|
|
675
|
-
const
|
|
652
|
+
const r = `
|
|
676
653
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
677
654
|
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="ja" prefix="rendition: http://www.idpf.org/vocab/rendition/#"
|
|
678
655
|
unique-identifier="ootuya-id">
|
|
@@ -695,8 +672,8 @@ const w = {
|
|
|
695
672
|
dir: !1,
|
|
696
673
|
basename: A("generated.opf"),
|
|
697
674
|
uri: "generated.opf",
|
|
698
|
-
blob: async () => new Blob([
|
|
699
|
-
string: async () =>
|
|
675
|
+
blob: async () => new Blob([r]),
|
|
676
|
+
string: async () => r,
|
|
700
677
|
size: 0
|
|
701
678
|
},
|
|
702
679
|
{
|
|
@@ -712,28 +689,28 @@ const w = {
|
|
|
712
689
|
close: () => Promise.resolve()
|
|
713
690
|
};
|
|
714
691
|
}, dt = async (e, { orderByAlpha: t, name: i } = {}) => {
|
|
715
|
-
let
|
|
716
|
-
t && (
|
|
692
|
+
let r = Object.values(e.files);
|
|
693
|
+
t && (r = r.slice().sort((s, o) => z(s.name, o.name)));
|
|
717
694
|
const n = {
|
|
718
695
|
filename: i || "",
|
|
719
|
-
files:
|
|
720
|
-
dir:
|
|
721
|
-
basename: A(
|
|
722
|
-
uri:
|
|
723
|
-
blob: () =>
|
|
724
|
-
string: () =>
|
|
725
|
-
...
|
|
726
|
-
stream:
|
|
696
|
+
files: r.map((s) => ({
|
|
697
|
+
dir: s.dir,
|
|
698
|
+
basename: A(s.name),
|
|
699
|
+
uri: s.name,
|
|
700
|
+
blob: () => s.async("blob"),
|
|
701
|
+
string: () => s.async("string"),
|
|
702
|
+
...s.internalStream && {
|
|
703
|
+
stream: s.internalStream
|
|
727
704
|
},
|
|
728
705
|
// this is private API
|
|
729
706
|
// @ts-ignore
|
|
730
|
-
size:
|
|
707
|
+
size: s._data.uncompressedSize
|
|
731
708
|
})),
|
|
732
709
|
close: () => Promise.resolve()
|
|
733
710
|
};
|
|
734
|
-
return
|
|
711
|
+
return v.log("Generated archive", n), n;
|
|
735
712
|
}, lt = async (e, { name: t } = {}) => {
|
|
736
|
-
const i = await e.getFilesArray(),
|
|
713
|
+
const i = await e.getFilesArray(), r = {
|
|
737
714
|
close: () => e.close(),
|
|
738
715
|
filename: t ?? "",
|
|
739
716
|
files: i.map((n) => ({
|
|
@@ -745,21 +722,21 @@ const w = {
|
|
|
745
722
|
string: async () => (await n.file.extract()).text()
|
|
746
723
|
}))
|
|
747
724
|
};
|
|
748
|
-
return
|
|
725
|
+
return v.log("Generated archive", r), r;
|
|
749
726
|
}, pt = async (e, { orderByAlpha: t, name: i } = {}) => {
|
|
750
|
-
let
|
|
751
|
-
return t && (
|
|
727
|
+
let r = e;
|
|
728
|
+
return t && (r = r.slice().sort((n, s) => z(n.name, s.name))), {
|
|
752
729
|
filename: i || "",
|
|
753
|
-
files:
|
|
730
|
+
files: r.map((n) => ({
|
|
754
731
|
dir: n.isDir,
|
|
755
732
|
basename: A(n.name),
|
|
756
733
|
uri: n.name,
|
|
757
734
|
blob: async () => new Blob([await n.data()]),
|
|
758
735
|
string: async () => {
|
|
759
|
-
const
|
|
736
|
+
const s = await n.data();
|
|
760
737
|
return String.fromCharCode.apply(
|
|
761
738
|
null,
|
|
762
|
-
Array.from(new Uint16Array(
|
|
739
|
+
Array.from(new Uint16Array(s))
|
|
763
740
|
);
|
|
764
741
|
},
|
|
765
742
|
size: n.size
|
|
@@ -769,7 +746,7 @@ const w = {
|
|
|
769
746
|
}, ft = ({
|
|
770
747
|
enableReport: e
|
|
771
748
|
} = {}) => {
|
|
772
|
-
|
|
749
|
+
v.enable(!!e);
|
|
773
750
|
};
|
|
774
751
|
class et {
|
|
775
752
|
constructor(t) {
|
|
@@ -796,7 +773,7 @@ class et {
|
|
|
796
773
|
}
|
|
797
774
|
get overTTL$() {
|
|
798
775
|
return this.isUnlocked$.pipe(
|
|
799
|
-
|
|
776
|
+
L(
|
|
800
777
|
(t) => t ? this.cleanArchiveAfter === 1 / 0 ? G : xe(this.cleanArchiveAfter) : G
|
|
801
778
|
)
|
|
802
779
|
);
|
|
@@ -807,66 +784,67 @@ const tt = ({
|
|
|
807
784
|
cleanArchiveAfter: t = 5 * 60 * 1e3
|
|
808
785
|
// 5mn
|
|
809
786
|
}) => {
|
|
810
|
-
const i = new R(),
|
|
787
|
+
const i = new R(), r = new R(), n = new R(), s = {}, o = i.pipe(
|
|
811
788
|
M((l) => {
|
|
812
|
-
const
|
|
813
|
-
if (!
|
|
789
|
+
const c = s[l];
|
|
790
|
+
if (!c || c.state.status !== "idle") return _;
|
|
814
791
|
let p = !1;
|
|
815
792
|
const u = (y) => {
|
|
816
|
-
var
|
|
817
|
-
|
|
818
|
-
|
|
793
|
+
var k;
|
|
794
|
+
v.debug(`Cleaning up archive with key: ${y}`);
|
|
795
|
+
const w = s[y];
|
|
796
|
+
delete s[y], p || ((k = w == null ? void 0 : w.state.archive) == null || k.close(), p = !0);
|
|
819
797
|
};
|
|
820
|
-
|
|
798
|
+
c.update({
|
|
821
799
|
status: "loading"
|
|
822
800
|
});
|
|
823
|
-
const g =
|
|
801
|
+
const g = c.locks$, b = c.isUnlocked$, h = g.pipe(
|
|
824
802
|
me(),
|
|
825
|
-
|
|
803
|
+
D(([y, w]) => w > y),
|
|
826
804
|
he(!0)
|
|
827
805
|
);
|
|
828
806
|
return P(e(l)).pipe(
|
|
829
|
-
|
|
830
|
-
|
|
807
|
+
j((y) => {
|
|
808
|
+
c.update({
|
|
831
809
|
archive: y,
|
|
832
810
|
status: "success"
|
|
833
811
|
});
|
|
834
812
|
}),
|
|
835
|
-
|
|
813
|
+
C((y) => (u(l), c.update({
|
|
836
814
|
status: "error",
|
|
837
815
|
error: y
|
|
838
816
|
}), _)),
|
|
839
|
-
|
|
817
|
+
L(() => {
|
|
840
818
|
const y = h.pipe(
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
819
|
+
L(() => n),
|
|
820
|
+
L(() => b),
|
|
821
|
+
D((w) => w)
|
|
844
822
|
);
|
|
845
|
-
return q(y,
|
|
823
|
+
return q(y, c.overTTL$);
|
|
846
824
|
}),
|
|
847
|
-
|
|
825
|
+
j(() => {
|
|
848
826
|
u(l);
|
|
849
827
|
})
|
|
850
828
|
);
|
|
851
829
|
}),
|
|
852
|
-
ge(
|
|
830
|
+
ge(r)
|
|
853
831
|
), a = (l) => {
|
|
854
|
-
let
|
|
855
|
-
const p =
|
|
856
|
-
|
|
832
|
+
let c = !1;
|
|
833
|
+
const p = s[l] ?? new et(t);
|
|
834
|
+
s[l] = p, p.update({
|
|
857
835
|
locks: p.state.locks + 1
|
|
858
836
|
});
|
|
859
837
|
const u = () => {
|
|
860
|
-
|
|
838
|
+
c || (c = !0, p.update({
|
|
861
839
|
locks: p.state.locks - 1
|
|
862
840
|
}));
|
|
863
841
|
};
|
|
864
842
|
i.next(l);
|
|
865
843
|
const g = p.state$.pipe(
|
|
866
844
|
F(({ archive: h }) => h),
|
|
867
|
-
|
|
845
|
+
D((h) => !!h)
|
|
868
846
|
), b = p.state$.pipe(
|
|
869
|
-
|
|
847
|
+
j(({ error: h }) => {
|
|
870
848
|
if (h)
|
|
871
849
|
throw h;
|
|
872
850
|
}),
|
|
@@ -875,26 +853,26 @@ const tt = ({
|
|
|
875
853
|
return q(g, b).pipe(
|
|
876
854
|
be(),
|
|
877
855
|
F((h) => ({ archive: h, release: u })),
|
|
878
|
-
|
|
856
|
+
C((h) => {
|
|
879
857
|
throw u(), h;
|
|
880
858
|
})
|
|
881
859
|
);
|
|
882
|
-
},
|
|
860
|
+
}, d = () => {
|
|
883
861
|
n.next();
|
|
884
862
|
};
|
|
885
863
|
return o.subscribe(), {
|
|
886
864
|
access: a,
|
|
887
|
-
purge:
|
|
888
|
-
archives:
|
|
865
|
+
purge: d,
|
|
866
|
+
archives: s
|
|
889
867
|
};
|
|
890
868
|
};
|
|
891
869
|
class nt {
|
|
892
870
|
constructor({
|
|
893
871
|
onError: t,
|
|
894
872
|
onManifestSuccess: i,
|
|
895
|
-
...
|
|
873
|
+
...r
|
|
896
874
|
}) {
|
|
897
|
-
this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = tt(
|
|
875
|
+
this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = tt(r), this.onManifestSuccess = i ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
|
|
898
876
|
}
|
|
899
877
|
prune() {
|
|
900
878
|
this.epubLoader.purge();
|
|
@@ -904,15 +882,15 @@ class nt {
|
|
|
904
882
|
}
|
|
905
883
|
accessArchiveWithoutLock(t) {
|
|
906
884
|
return this.accessArchive(t).pipe(
|
|
907
|
-
F(({ archive: i, release:
|
|
885
|
+
F(({ archive: i, release: r }) => (r(), i))
|
|
908
886
|
);
|
|
909
887
|
}
|
|
910
888
|
fetchManifest({ key: t, baseUrl: i }) {
|
|
911
|
-
const
|
|
912
|
-
M(({ archive: n, release:
|
|
889
|
+
const r = this.accessArchive(t).pipe(
|
|
890
|
+
M(({ archive: n, release: s }) => P(
|
|
913
891
|
Ze(n, { baseUrl: i })
|
|
914
892
|
).pipe(
|
|
915
|
-
|
|
893
|
+
L(
|
|
916
894
|
(a) => P(this.onManifestSuccess({ manifest: a, archive: n }))
|
|
917
895
|
),
|
|
918
896
|
F(
|
|
@@ -921,41 +899,41 @@ class nt {
|
|
|
921
899
|
})
|
|
922
900
|
),
|
|
923
901
|
K(() => {
|
|
924
|
-
|
|
902
|
+
s();
|
|
925
903
|
})
|
|
926
904
|
)),
|
|
927
|
-
|
|
905
|
+
C((n) => J(this.onError(n)))
|
|
928
906
|
);
|
|
929
|
-
return Y(
|
|
907
|
+
return Y(r);
|
|
930
908
|
}
|
|
931
909
|
fetchResource({
|
|
932
910
|
key: t,
|
|
933
911
|
resourcePath: i
|
|
934
912
|
}) {
|
|
935
|
-
const
|
|
936
|
-
M(({ archive: n, release:
|
|
913
|
+
const r = this.accessArchive(t).pipe(
|
|
914
|
+
M(({ archive: n, release: s }) => {
|
|
937
915
|
const o = i.replaceAll("file://", "");
|
|
938
916
|
return P(
|
|
939
917
|
Ue(n, o)
|
|
940
918
|
).pipe(
|
|
941
919
|
F(
|
|
942
|
-
(
|
|
920
|
+
(d) => new Response(d.body, {
|
|
943
921
|
status: 200,
|
|
944
922
|
headers: {
|
|
945
|
-
...
|
|
946
|
-
"Content-Type":
|
|
923
|
+
...d.params.contentType && {
|
|
924
|
+
"Content-Type": d.params.contentType
|
|
947
925
|
}
|
|
948
926
|
}
|
|
949
927
|
})
|
|
950
928
|
),
|
|
951
929
|
K(() => {
|
|
952
|
-
|
|
930
|
+
s();
|
|
953
931
|
})
|
|
954
932
|
);
|
|
955
933
|
}),
|
|
956
|
-
|
|
934
|
+
C((n) => J(this.onError(n)))
|
|
957
935
|
);
|
|
958
|
-
return Y(
|
|
936
|
+
return Y(r);
|
|
959
937
|
}
|
|
960
938
|
}
|
|
961
939
|
class ut extends nt {
|
|
@@ -969,14 +947,14 @@ class ut extends nt {
|
|
|
969
947
|
try {
|
|
970
948
|
const i = this.getUriInfo(t);
|
|
971
949
|
if (!i) return;
|
|
972
|
-
const
|
|
973
|
-
|
|
974
|
-
), [
|
|
975
|
-
Q(n.substring(
|
|
950
|
+
const r = Q(i.baseUrl), n = t.request.url.substring(
|
|
951
|
+
r.length + 1
|
|
952
|
+
), [s = ""] = n.split("/"), o = decodeURIComponent(
|
|
953
|
+
Q(n.substring(s.length + 1))
|
|
976
954
|
);
|
|
977
955
|
n.endsWith("/manifest") ? t.respondWith(
|
|
978
|
-
this.fetchManifest({ key:
|
|
979
|
-
) : t.respondWith(this.fetchResource({ key:
|
|
956
|
+
this.fetchManifest({ key: s, baseUrl: `${r}/${s}/` })
|
|
957
|
+
) : t.respondWith(this.fetchResource({ key: s, resourcePath: o }));
|
|
980
958
|
} catch (i) {
|
|
981
959
|
t.respondWith(new Response(String(i), { status: 500 }));
|
|
982
960
|
}
|