@prose-reader/streamer 1.207.0 → 1.209.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/archives/archiveLoader.d.ts +1 -1
- package/dist/index.js +299 -319
- 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
|
-
import
|
|
2
|
-
import { urlJoin as
|
|
3
|
-
import { Subject as R, mergeMap as M, EMPTY as _, pairwise as
|
|
4
|
-
let
|
|
1
|
+
import v, { XmlDocument as le, XmlTextNode as pe, XmlElement as fe } from "xmldoc";
|
|
2
|
+
import { urlJoin as N, isXmlBasedMimeType as ue, parseContentType as me, detectMimeTypeFromName as O } from "@prose-reader/shared";
|
|
3
|
+
import { Subject as R, mergeMap as M, EMPTY as _, pairwise as he, filter as D, startWith as ge, from as C, tap as j, catchError as P, switchMap as W, merge as q, first as G, takeUntil as ye, map as F, ignoreElements as be, BehaviorSubject as we, distinctUntilChanged as ve, shareReplay as $e, NEVER as K, timer as xe, finalize as J, of as Y, lastValueFrom as Q } from "rxjs";
|
|
4
|
+
let S = !1;
|
|
5
5
|
const w = {
|
|
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 le(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
|
-
},
|
|
64
|
+
}, te = (e) => e ? e.children.map((t) => t instanceof pe ? t.text : t instanceof fe ? te(t) : "").join("").trim() : "", A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Z = (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
|
-
},
|
|
91
|
-
const
|
|
67
|
+
}, ne = (e, { basePath: t, baseUrl: i }) => {
|
|
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()) || te(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 = N(t, n.attr.href), r.href = N(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) => ne(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(ne(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
|
|
125
|
-
return
|
|
100
|
+
if (s) {
|
|
101
|
+
const o = new v.XmlDocument(await s.string()), a = Ne(s.uri);
|
|
102
|
+
return ke(o, { basePath: a, baseUrl: i });
|
|
126
103
|
}
|
|
127
104
|
}
|
|
128
|
-
},
|
|
105
|
+
}, re = (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: N(t, n),
|
|
114
|
+
href: N(i, t, n),
|
|
138
115
|
contents: []
|
|
139
|
-
}, o = e.childrenNamed(`${
|
|
140
|
-
return o && o.length > 0 && (
|
|
141
|
-
(l) =>
|
|
142
|
-
)),
|
|
143
|
-
},
|
|
116
|
+
}, o = e.childrenNamed(`${r}navPoint`);
|
|
117
|
+
return o && o.length > 0 && (s.contents = o.map(
|
|
118
|
+
(l) => re(l, { opfBasePath: t, baseUrl: i, prefix: r })
|
|
119
|
+
)), s;
|
|
120
|
+
}, Ce = (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(re(a, { opfBasePath: t, baseUrl: i, prefix: s }))
|
|
126
|
+
), r;
|
|
127
|
+
}, Pe = 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
|
|
142
|
+
const c = new v.XmlDocument(await l.string());
|
|
143
|
+
return Ce(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 } = k(t) || {}, n = await Pe({
|
|
172
149
|
opfData: e,
|
|
173
|
-
opfBasePath:
|
|
150
|
+
opfBasePath: r,
|
|
174
151
|
archive: t,
|
|
175
152
|
baseUrl: i
|
|
176
153
|
});
|
|
@@ -178,52 +155,52 @@ 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,
|
|
186
163
|
pageSpreadLeft: t.some((n) => n === "page-spread-left") || void 0,
|
|
187
164
|
pageSpreadRight: t.some((n) => n === "page-spread-right") || void 0
|
|
188
165
|
};
|
|
189
|
-
},
|
|
190
|
-
const i = Object.values(e.files).filter((
|
|
166
|
+
}, k = (e) => {
|
|
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("/"))) || ""
|
|
194
171
|
};
|
|
195
|
-
},
|
|
172
|
+
}, se = async ({
|
|
196
173
|
archive: e
|
|
197
174
|
}) => {
|
|
198
|
-
const { data: t, basePath: i } =
|
|
199
|
-
if (!
|
|
200
|
-
const n = new
|
|
201
|
-
return e.files.filter((
|
|
202
|
-
},
|
|
203
|
-
const
|
|
175
|
+
const { data: t, basePath: i } = k(e) || {}, r = await (t == null ? void 0 : t.string());
|
|
176
|
+
if (!r) return [];
|
|
177
|
+
const n = new v.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
|
-
},
|
|
210
|
-
var
|
|
211
|
-
const
|
|
212
|
-
return ((
|
|
213
|
-
},
|
|
186
|
+
}, ie = (e, t, i) => {
|
|
187
|
+
var s;
|
|
188
|
+
const r = e.childNamed("manifest"), { basePath: n } = k(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 } = k(e) || {};
|
|
193
|
+
if (!r)
|
|
217
194
|
return i;
|
|
218
|
-
const
|
|
219
|
-
w.log("data",
|
|
220
|
-
const o = new
|
|
195
|
+
const s = await r.string();
|
|
196
|
+
w.log("data", s);
|
|
197
|
+
const o = new v.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
|
+
), $ = g.find(
|
|
225
202
|
(m) => m.attr.property === "rendition:spread"
|
|
226
|
-
), y = b == null ? void 0 : b.val,
|
|
203
|
+
), y = b == null ? void 0 : b.val, x = h == null ? void 0 : h.val, T = $ == null ? void 0 : $.val, oe = (u == null ? void 0 : u.val) || ((X = e.files.find(({ dir: m }) => m)) == null ? void 0 : X.basename) || "", ae = c == null ? void 0 : c.attr["page-progression-direction"], ce = (await se({ archive: e })).reduce(
|
|
227
204
|
(m, L) => L.size + m,
|
|
228
205
|
0
|
|
229
206
|
);
|
|
@@ -233,28 +210,28 @@ const w = {
|
|
|
233
210
|
toc: a
|
|
234
211
|
},
|
|
235
212
|
renditionLayout: y,
|
|
236
|
-
renditionFlow:
|
|
237
|
-
renditionSpread:
|
|
238
|
-
title:
|
|
239
|
-
readingDirection:
|
|
213
|
+
renditionFlow: x || "auto",
|
|
214
|
+
renditionSpread: T,
|
|
215
|
+
title: oe,
|
|
216
|
+
readingDirection: ae || "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, L) => {
|
|
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) || "", de = ((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
226
|
index: L,
|
|
250
|
-
href: (
|
|
251
|
-
renditionLayout:
|
|
252
|
-
progressionWeight:
|
|
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,
|
|
229
|
+
progressionWeight: de / ce,
|
|
253
230
|
// size: itemSize
|
|
254
231
|
mediaType: f == null ? void 0 : f.attr["media-type"]
|
|
255
232
|
};
|
|
256
233
|
})) || [],
|
|
257
|
-
items:
|
|
234
|
+
items: ie(o, e, (m) => {
|
|
258
235
|
const L = m.attr.href || "";
|
|
259
236
|
return /^https?:\/\//.test(L) ? "" : t || "file://";
|
|
260
237
|
}),
|
|
@@ -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
|
|
272
|
-
if ((
|
|
273
|
-
(
|
|
274
|
-
)) == null ? void 0 :
|
|
245
|
+
var n, s, o;
|
|
246
|
+
const r = await ((n = k(e).data) == null ? void 0 : n.string());
|
|
247
|
+
if (r) {
|
|
248
|
+
const a = new v.XmlDocument(r), d = ie(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,24 +268,24 @@ 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
|
|
308
285
|
}
|
|
309
286
|
}
|
|
310
287
|
};
|
|
311
|
-
},
|
|
288
|
+
}, ee = [
|
|
312
289
|
"div",
|
|
313
290
|
"span",
|
|
314
291
|
"p",
|
|
@@ -360,22 +337,22 @@ 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
|
+
`<(${ee.join("|")})[\\s/>]`,
|
|
370
347
|
"i"
|
|
371
348
|
).test(n))
|
|
372
349
|
return i;
|
|
373
350
|
const o = new RegExp(
|
|
374
|
-
`<(${
|
|
351
|
+
`<(${ee.join("|")})(\\s[^>]*)?\\s*/>`,
|
|
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 w.log("Generated resource", t,
|
|
403
|
-
...
|
|
404
|
-
body:
|
|
378
|
+
const s = await n.reduce(async (o, a) => await a(await o), Promise.resolve(r));
|
|
379
|
+
return w.log("Generated resource", t, s), {
|
|
380
|
+
...s,
|
|
381
|
+
body: s.body ?? await i.blob()
|
|
405
382
|
};
|
|
406
|
-
} catch (
|
|
407
|
-
throw w.error(
|
|
383
|
+
} catch (s) {
|
|
384
|
+
throw w.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,50 +408,50 @@ 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 v.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
|
-
if (!await t || !
|
|
440
|
+
if (!await t || !ue({
|
|
464
441
|
mimeType: i.encodingFormat,
|
|
465
442
|
uri: i.uri
|
|
466
443
|
}))
|
|
467
444
|
return !1;
|
|
468
445
|
const n = await i.string();
|
|
469
|
-
return n ?
|
|
446
|
+
return n ? Ve(new v.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 se({ 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,69 +460,69 @@ 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
|
-
...a.filter((
|
|
475
|
+
...a.filter(($) => $ !== 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
|
]
|
|
511
488
|
}
|
|
512
489
|
] : u.path.split("/").length > p.split("/").length ? [
|
|
513
|
-
...a.filter((
|
|
490
|
+
...a.filter(($) => $ !== u),
|
|
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 = N(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 v.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 = me((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
|
|
581
|
+
const a = new v.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
|
|
604
|
+
const r = Be({ archive: e, baseUrl: t })(), n = await i.reduce(async (s, o) => await o(await s), r);
|
|
628
605
|
return w.log("Generated manifest", n), n;
|
|
629
|
-
} catch (
|
|
630
|
-
throw w.error(
|
|
606
|
+
} catch (r) {
|
|
607
|
+
throw w.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
711
|
return w.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 w.log("Generated archive",
|
|
725
|
+
return w.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
|
|
@@ -797,7 +774,7 @@ class et {
|
|
|
797
774
|
get overTTL$() {
|
|
798
775
|
return this.isUnlocked$.pipe(
|
|
799
776
|
W(
|
|
800
|
-
(t) => t ? this.cleanArchiveAfter === 1 / 0 ?
|
|
777
|
+
(t) => t ? this.cleanArchiveAfter === 1 / 0 ? K : xe(this.cleanArchiveAfter) : K
|
|
801
778
|
)
|
|
802
779
|
);
|
|
803
780
|
}
|
|
@@ -807,32 +784,33 @@ 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 T;
|
|
794
|
+
w.debug(`Cleaning up archive with key: ${y}`);
|
|
795
|
+
const x = s[y];
|
|
796
|
+
delete s[y], p || ((T = x == null ? void 0 : x.state.archive) == null || T.close(), p = !0);
|
|
819
797
|
};
|
|
820
|
-
|
|
798
|
+
c.update({
|
|
821
799
|
status: "loading"
|
|
822
800
|
});
|
|
823
|
-
const g =
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
801
|
+
const g = c.locks$, b = c.isUnlocked$, h = g.pipe(
|
|
802
|
+
he(),
|
|
803
|
+
D(([y, x]) => x > y),
|
|
804
|
+
ge(!0)
|
|
827
805
|
);
|
|
828
|
-
return
|
|
829
|
-
|
|
830
|
-
|
|
806
|
+
return C(e(l)).pipe(
|
|
807
|
+
j((y) => {
|
|
808
|
+
c.update({
|
|
831
809
|
archive: y,
|
|
832
810
|
status: "success"
|
|
833
811
|
});
|
|
834
812
|
}),
|
|
835
|
-
|
|
813
|
+
P((y) => (u(l), c.update({
|
|
836
814
|
status: "error",
|
|
837
815
|
error: y
|
|
838
816
|
}), _)),
|
|
@@ -840,61 +818,63 @@ const tt = ({
|
|
|
840
818
|
const y = h.pipe(
|
|
841
819
|
W(() => n),
|
|
842
820
|
W(() => b),
|
|
843
|
-
|
|
821
|
+
D((T) => T)
|
|
822
|
+
);
|
|
823
|
+
return q(y, c.overTTL$).pipe(
|
|
824
|
+
G(),
|
|
825
|
+
j(() => {
|
|
826
|
+
u(l);
|
|
827
|
+
})
|
|
844
828
|
);
|
|
845
|
-
return q(y, d.overTTL$);
|
|
846
|
-
}),
|
|
847
|
-
D(() => {
|
|
848
|
-
u(l);
|
|
849
829
|
})
|
|
850
830
|
);
|
|
851
831
|
}),
|
|
852
|
-
|
|
832
|
+
ye(r)
|
|
853
833
|
), a = (l) => {
|
|
854
|
-
let
|
|
855
|
-
const p =
|
|
856
|
-
|
|
834
|
+
let c = !1;
|
|
835
|
+
const p = s[l] ?? new et(t);
|
|
836
|
+
s[l] = p, p.update({
|
|
857
837
|
locks: p.state.locks + 1
|
|
858
838
|
});
|
|
859
839
|
const u = () => {
|
|
860
|
-
|
|
840
|
+
c || (c = !0, p.update({
|
|
861
841
|
locks: p.state.locks - 1
|
|
862
842
|
}));
|
|
863
843
|
};
|
|
864
844
|
i.next(l);
|
|
865
845
|
const g = p.state$.pipe(
|
|
866
846
|
F(({ archive: h }) => h),
|
|
867
|
-
|
|
847
|
+
D((h) => !!h)
|
|
868
848
|
), b = p.state$.pipe(
|
|
869
|
-
|
|
849
|
+
j(({ error: h }) => {
|
|
870
850
|
if (h)
|
|
871
851
|
throw h;
|
|
872
852
|
}),
|
|
873
|
-
|
|
853
|
+
be()
|
|
874
854
|
);
|
|
875
855
|
return q(g, b).pipe(
|
|
876
|
-
|
|
856
|
+
G(),
|
|
877
857
|
F((h) => ({ archive: h, release: u })),
|
|
878
|
-
|
|
858
|
+
P((h) => {
|
|
879
859
|
throw u(), h;
|
|
880
860
|
})
|
|
881
861
|
);
|
|
882
|
-
},
|
|
862
|
+
}, d = () => {
|
|
883
863
|
n.next();
|
|
884
864
|
};
|
|
885
865
|
return o.subscribe(), {
|
|
886
866
|
access: a,
|
|
887
|
-
purge:
|
|
888
|
-
|
|
867
|
+
purge: d,
|
|
868
|
+
_archives: s
|
|
889
869
|
};
|
|
890
870
|
};
|
|
891
871
|
class nt {
|
|
892
872
|
constructor({
|
|
893
873
|
onError: t,
|
|
894
874
|
onManifestSuccess: i,
|
|
895
|
-
...
|
|
875
|
+
...r
|
|
896
876
|
}) {
|
|
897
|
-
this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = tt(
|
|
877
|
+
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
878
|
}
|
|
899
879
|
prune() {
|
|
900
880
|
this.epubLoader.purge();
|
|
@@ -904,58 +884,58 @@ class nt {
|
|
|
904
884
|
}
|
|
905
885
|
accessArchiveWithoutLock(t) {
|
|
906
886
|
return this.accessArchive(t).pipe(
|
|
907
|
-
F(({ archive: i, release:
|
|
887
|
+
F(({ archive: i, release: r }) => (r(), i))
|
|
908
888
|
);
|
|
909
889
|
}
|
|
910
890
|
fetchManifest({ key: t, baseUrl: i }) {
|
|
911
|
-
const
|
|
912
|
-
M(({ archive: n, release:
|
|
891
|
+
const r = this.accessArchive(t).pipe(
|
|
892
|
+
M(({ archive: n, release: s }) => C(
|
|
913
893
|
Ze(n, { baseUrl: i })
|
|
914
894
|
).pipe(
|
|
915
895
|
W(
|
|
916
|
-
(a) =>
|
|
896
|
+
(a) => C(this.onManifestSuccess({ manifest: a, archive: n }))
|
|
917
897
|
),
|
|
918
898
|
F(
|
|
919
899
|
(a) => new Response(JSON.stringify(a), {
|
|
920
900
|
status: 200
|
|
921
901
|
})
|
|
922
902
|
),
|
|
923
|
-
|
|
924
|
-
|
|
903
|
+
J(() => {
|
|
904
|
+
s();
|
|
925
905
|
})
|
|
926
906
|
)),
|
|
927
|
-
|
|
907
|
+
P((n) => Y(this.onError(n)))
|
|
928
908
|
);
|
|
929
|
-
return
|
|
909
|
+
return Q(r);
|
|
930
910
|
}
|
|
931
911
|
fetchResource({
|
|
932
912
|
key: t,
|
|
933
913
|
resourcePath: i
|
|
934
914
|
}) {
|
|
935
|
-
const
|
|
936
|
-
M(({ archive: n, release:
|
|
915
|
+
const r = this.accessArchive(t).pipe(
|
|
916
|
+
M(({ archive: n, release: s }) => {
|
|
937
917
|
const o = i.replaceAll("file://", "");
|
|
938
|
-
return
|
|
918
|
+
return C(
|
|
939
919
|
Ue(n, o)
|
|
940
920
|
).pipe(
|
|
941
921
|
F(
|
|
942
|
-
(
|
|
922
|
+
(d) => new Response(d.body, {
|
|
943
923
|
status: 200,
|
|
944
924
|
headers: {
|
|
945
|
-
...
|
|
946
|
-
"Content-Type":
|
|
925
|
+
...d.params.contentType && {
|
|
926
|
+
"Content-Type": d.params.contentType
|
|
947
927
|
}
|
|
948
928
|
}
|
|
949
929
|
})
|
|
950
930
|
),
|
|
951
|
-
|
|
952
|
-
|
|
931
|
+
J(() => {
|
|
932
|
+
s();
|
|
953
933
|
})
|
|
954
934
|
);
|
|
955
935
|
}),
|
|
956
|
-
|
|
936
|
+
P((n) => Y(this.onError(n)))
|
|
957
937
|
);
|
|
958
|
-
return
|
|
938
|
+
return Q(r);
|
|
959
939
|
}
|
|
960
940
|
}
|
|
961
941
|
class ut extends nt {
|
|
@@ -969,14 +949,14 @@ class ut extends nt {
|
|
|
969
949
|
try {
|
|
970
950
|
const i = this.getUriInfo(t);
|
|
971
951
|
if (!i) return;
|
|
972
|
-
const
|
|
973
|
-
|
|
974
|
-
), [
|
|
975
|
-
|
|
952
|
+
const r = Z(i.baseUrl), n = t.request.url.substring(
|
|
953
|
+
r.length + 1
|
|
954
|
+
), [s = ""] = n.split("/"), o = decodeURIComponent(
|
|
955
|
+
Z(n.substring(s.length + 1))
|
|
976
956
|
);
|
|
977
957
|
n.endsWith("/manifest") ? t.respondWith(
|
|
978
|
-
this.fetchManifest({ key:
|
|
979
|
-
) : t.respondWith(this.fetchResource({ key:
|
|
958
|
+
this.fetchManifest({ key: s, baseUrl: `${r}/${s}/` })
|
|
959
|
+
) : t.respondWith(this.fetchResource({ key: s, resourcePath: o }));
|
|
980
960
|
} catch (i) {
|
|
981
961
|
t.respondWith(new Response(String(i), { status: 500 }));
|
|
982
962
|
}
|
|
@@ -993,6 +973,6 @@ export {
|
|
|
993
973
|
at as createArchiveFromUrls,
|
|
994
974
|
Ze as generateManifestFromArchive,
|
|
995
975
|
Ue as generateResourceFromArchive,
|
|
996
|
-
|
|
976
|
+
k as getArchiveOpfInfo
|
|
997
977
|
};
|
|
998
978
|
//# sourceMappingURL=index.js.map
|