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