@prose-reader/streamer 1.120.0 → 1.122.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/generators/manifest/hooks/{epub.d.ts → epub/epub.d.ts} +1 -1
- package/dist/index.js +138 -135
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +6 -6
- package/dist/index.umd.cjs.map +1 -1
- package/dist/parsers/xml.d.ts +2 -0
- package/dist/utils/uri.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import F, { XmlDocument as
|
|
2
|
-
import { urlJoin as
|
|
3
|
-
import { Subject as R, mergeMap as O, EMPTY as _, pairwise as
|
|
4
|
-
let
|
|
1
|
+
import F, { XmlDocument as le, XmlTextNode as pe, XmlElement as fe } from "xmldoc";
|
|
2
|
+
import { urlJoin as N, isXmlBasedMimeType as ue, detectMimeTypeFromName as V } from "@prose-reader/shared";
|
|
3
|
+
import { Subject as R, mergeMap as O, EMPTY as _, pairwise as me, filter as j, startWith as he, from as L, tap as D, catchError as P, switchMap as k, merge as q, takeUntil as ge, map as A, 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
5
|
const v = {
|
|
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, t = 1 / 0) => {
|
|
28
28
|
const i = typeof e == "number" ? e : e.duration;
|
|
29
|
-
|
|
29
|
+
S && (e.duration <= t ? console.log(
|
|
30
30
|
"[prose-reader-streamer] [metric] ",
|
|
31
31
|
`${e.name} took ${i}ms`
|
|
32
32
|
) : console.warn(
|
|
@@ -45,23 +45,23 @@ const v = {
|
|
|
45
45
|
const a = performance.now();
|
|
46
46
|
return v.metric({ name: e, duration: a - n }, t), s;
|
|
47
47
|
}
|
|
48
|
-
},
|
|
48
|
+
}, Fe = (e) => {
|
|
49
49
|
var i;
|
|
50
50
|
const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((r) => r.attr.name === "calibre:cover");
|
|
51
51
|
return !!(t && t.attr.name === "calibre:cover");
|
|
52
|
-
},
|
|
52
|
+
}, Ae = (e) => {
|
|
53
53
|
var t, i, r;
|
|
54
54
|
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
55
|
(n) => n.attr.width === "100%" && n.attr.preserveAspectRatio === "none"
|
|
56
56
|
);
|
|
57
|
-
},
|
|
57
|
+
}, Te = ({ archive: e, resourcePath: t }) => async (i) => {
|
|
58
58
|
const r = Object.values(e.files).find(
|
|
59
59
|
(n) => n.uri === t
|
|
60
60
|
);
|
|
61
61
|
if (r != null && r.basename.endsWith(".xhtml")) {
|
|
62
|
-
const n = i.body ?? await r.string(), s = new
|
|
63
|
-
if (
|
|
64
|
-
const a =
|
|
62
|
+
const n = i.body ?? await r.string(), s = new le(n);
|
|
63
|
+
if (Fe(s)) {
|
|
64
|
+
const a = Ae(s);
|
|
65
65
|
return a && delete a.attr.preserveAspectRatio, {
|
|
66
66
|
...i,
|
|
67
67
|
body: s == null ? void 0 : s.toString()
|
|
@@ -69,7 +69,7 @@ const v = {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
return i;
|
|
72
|
-
},
|
|
72
|
+
}, Se = ({ archive: e, resourcePath: t }) => async (i) => Te({ archive: e, resourcePath: t })(i), ke = ({ archive: e, resourcePath: t }) => async (i) => {
|
|
73
73
|
const r = Object.values(e.files).find(
|
|
74
74
|
(n) => n.uri === t
|
|
75
75
|
);
|
|
@@ -90,7 +90,10 @@ const v = {
|
|
|
90
90
|
data: i,
|
|
91
91
|
basePath: (i == null ? void 0 : i.uri.substring(0, i.uri.lastIndexOf("/"))) || ""
|
|
92
92
|
};
|
|
93
|
-
}, E = (e
|
|
93
|
+
}, E = (e) => e ? e.children.map((t) => t instanceof pe ? t.text : t instanceof fe ? E(t) : "").join("").trim() : "", T = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Q = (e) => e.endsWith("/") ? e.slice(0, -1) : e, Ne = (e) => {
|
|
94
|
+
const t = e.lastIndexOf("/");
|
|
95
|
+
return t >= 0 ? e.substring(0, t) : "";
|
|
96
|
+
}, ee = (e, { basePath: t, baseUrl: i }) => {
|
|
94
97
|
const r = {
|
|
95
98
|
contents: [],
|
|
96
99
|
path: "",
|
|
@@ -98,37 +101,37 @@ const v = {
|
|
|
98
101
|
title: ""
|
|
99
102
|
};
|
|
100
103
|
let n = e.childNamed("span") || e.childNamed("a");
|
|
101
|
-
r.title = (n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) ||
|
|
104
|
+
r.title = ((n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || E(n)) ?? "";
|
|
102
105
|
let s = n == null ? void 0 : n.name;
|
|
103
|
-
s !== "a" && (n = e.descendantWithPath(`${s}.a`), n && (s = n.name.toLowerCase())), s === "a" && (n != null && n.attr.href) && (r.path =
|
|
106
|
+
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));
|
|
104
107
|
const a = e.childNamed("ol");
|
|
105
108
|
if (a) {
|
|
106
109
|
const o = a.childrenNamed("li");
|
|
107
110
|
o && o.length > 0 && (r.contents = o.map(
|
|
108
|
-
(d) =>
|
|
111
|
+
(d) => ee(d, { basePath: t, baseUrl: i })
|
|
109
112
|
));
|
|
110
113
|
}
|
|
111
114
|
return r;
|
|
112
|
-
},
|
|
115
|
+
}, We = (e, { basePath: t, baseUrl: i }) => {
|
|
113
116
|
var s, a;
|
|
114
117
|
const r = [];
|
|
115
118
|
let n;
|
|
116
119
|
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 = (a = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : a.children), n && n.length > 0 && n.filter((o) => o.name === "li").forEach(
|
|
117
|
-
(o) => r.push(
|
|
120
|
+
(o) => r.push(ee(o, { basePath: t, baseUrl: i }))
|
|
118
121
|
), r;
|
|
119
|
-
},
|
|
120
|
-
var
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
const
|
|
124
|
-
(
|
|
122
|
+
}, Le = async (e, t, { baseUrl: i }) => {
|
|
123
|
+
var n;
|
|
124
|
+
const r = (n = e.childNamed("manifest")) == null ? void 0 : n.childrenNamed("item").find((s) => s.attr.properties === "nav");
|
|
125
|
+
if (r) {
|
|
126
|
+
const s = Object.values(t.files).find(
|
|
127
|
+
(a) => a.uri.endsWith(r.attr.href || "")
|
|
125
128
|
);
|
|
126
|
-
if (
|
|
127
|
-
const
|
|
128
|
-
return
|
|
129
|
+
if (s) {
|
|
130
|
+
const a = new F.XmlDocument(await s.string()), o = Ne(s.uri);
|
|
131
|
+
return We(a, { basePath: o, baseUrl: i });
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
|
-
},
|
|
134
|
+
}, te = (e, {
|
|
132
135
|
opfBasePath: t,
|
|
133
136
|
baseUrl: i,
|
|
134
137
|
prefix: r
|
|
@@ -136,21 +139,21 @@ const v = {
|
|
|
136
139
|
var o, d;
|
|
137
140
|
const n = ((o = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : o.attr.src) || "", s = {
|
|
138
141
|
title: ((d = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : d.val) || "",
|
|
139
|
-
path:
|
|
140
|
-
href:
|
|
142
|
+
path: N(t, n),
|
|
143
|
+
href: N(i, t, n),
|
|
141
144
|
contents: []
|
|
142
145
|
}, a = e.childrenNamed(`${r}navPoint`);
|
|
143
146
|
return a && a.length > 0 && (s.contents = a.map(
|
|
144
|
-
(p) =>
|
|
147
|
+
(p) => te(p, { opfBasePath: t, baseUrl: i, prefix: r })
|
|
145
148
|
)), s;
|
|
146
|
-
},
|
|
149
|
+
}, Pe = (e, { opfBasePath: t, baseUrl: i }) => {
|
|
147
150
|
var a;
|
|
148
151
|
const r = [], n = e.name;
|
|
149
152
|
let s = "";
|
|
150
153
|
return n.indexOf(":") !== -1 && (s = n.split(":")[0] + ":"), (a = e.childNamed(`${s}navMap`)) == null || a.childrenNamed(`${s}navPoint`).forEach(
|
|
151
|
-
(o) => r.push(
|
|
154
|
+
(o) => r.push(te(o, { opfBasePath: t, baseUrl: i, prefix: s }))
|
|
152
155
|
), r;
|
|
153
|
-
},
|
|
156
|
+
}, Ce = async ({
|
|
154
157
|
opfData: e,
|
|
155
158
|
opfBasePath: t,
|
|
156
159
|
baseUrl: i,
|
|
@@ -166,19 +169,19 @@ const v = {
|
|
|
166
169
|
);
|
|
167
170
|
if (p) {
|
|
168
171
|
const c = new F.XmlDocument(await p.string());
|
|
169
|
-
return
|
|
172
|
+
return Pe(c, { opfBasePath: t, baseUrl: i });
|
|
170
173
|
}
|
|
171
174
|
}
|
|
172
175
|
}
|
|
173
|
-
},
|
|
174
|
-
const { basePath: r } = C(t) || {}, n = await
|
|
176
|
+
}, Ie = async (e, t, { baseUrl: i }) => {
|
|
177
|
+
const { basePath: r } = C(t) || {}, n = await Ce({
|
|
175
178
|
opfData: e,
|
|
176
179
|
opfBasePath: r,
|
|
177
180
|
archive: t,
|
|
178
181
|
baseUrl: i
|
|
179
182
|
});
|
|
180
|
-
return n || await
|
|
181
|
-
},
|
|
183
|
+
return n || await Le(e, t, { opfBasePath: r, baseUrl: i });
|
|
184
|
+
}, Re = async (e) => {
|
|
182
185
|
const t = {
|
|
183
186
|
renditionLayout: void 0
|
|
184
187
|
};
|
|
@@ -191,14 +194,14 @@ const v = {
|
|
|
191
194
|
}
|
|
192
195
|
})
|
|
193
196
|
), t;
|
|
194
|
-
},
|
|
197
|
+
}, ne = async ({
|
|
195
198
|
archive: e
|
|
196
199
|
}) => {
|
|
197
200
|
const { data: t, basePath: i } = C(e) || {}, r = await (t == null ? void 0 : t.string());
|
|
198
201
|
if (!r) return [];
|
|
199
202
|
const n = new F.XmlDocument(r), s = n.childNamed("manifest"), a = n.childNamed("spine"), o = a == null ? void 0 : a.childrenNamed("itemref").map((c) => c.attr.idref), d = (s == null ? void 0 : s.childrenNamed("item").filter((c) => o.includes(c.attr.id || ""))) || [];
|
|
200
203
|
return e.files.filter((c) => d.find((l) => i ? `${i}/${l.attr.href}` === c.uri : `${l.attr.href}` === c.uri));
|
|
201
|
-
},
|
|
204
|
+
}, re = (e) => {
|
|
202
205
|
var i;
|
|
203
206
|
const t = e.childNamed("manifest");
|
|
204
207
|
return ((i = t == null ? void 0 : t.childrenNamed("item")) == null ? void 0 : i.map((r) => ({
|
|
@@ -206,20 +209,20 @@ const v = {
|
|
|
206
209
|
id: r.attr.id || "",
|
|
207
210
|
mediaType: r.attr["media-type"]
|
|
208
211
|
}))) || [];
|
|
209
|
-
},
|
|
212
|
+
}, je = ({ archive: e, baseUrl: t }) => async (i) => {
|
|
210
213
|
var M;
|
|
211
|
-
const { data: r, basePath: n } = C(e) || {}, s = await
|
|
214
|
+
const { data: r, basePath: n } = C(e) || {}, s = await Re(e);
|
|
212
215
|
if (!r)
|
|
213
216
|
return i;
|
|
214
217
|
const a = await r.string();
|
|
215
218
|
v.log(a, s);
|
|
216
|
-
const o = new F.XmlDocument(a), d = await
|
|
219
|
+
const o = new F.XmlDocument(a), d = await Ie(o, e, { baseUrl: t }) || [], p = o.childNamed("metadata"), c = o.childNamed("manifest"), l = o.childNamed("spine"), u = o.childNamed("guide"), g = p == null ? void 0 : p.childNamed("dc:title"), b = (p == null ? void 0 : p.childrenNamed("meta")) || [], h = b.find(
|
|
217
220
|
(m) => m.attr.property === "rendition:layout"
|
|
218
221
|
), x = b.find(
|
|
219
222
|
(m) => m.attr.property === "rendition:flow"
|
|
220
223
|
), y = b.find(
|
|
221
224
|
(m) => m.attr.property === "rendition:spread"
|
|
222
|
-
), w = h == null ? void 0 : h.val,
|
|
225
|
+
), w = h == null ? void 0 : h.val, W = x == null ? void 0 : x.val, se = y == null ? void 0 : y.val, ie = (g == null ? void 0 : g.val) || ((M = e.files.find(({ dir: m }) => m)) == null ? void 0 : M.basename) || "", ae = l == null ? void 0 : l.attr["page-progression-direction"], oe = (await ne({ archive: e })).reduce(
|
|
223
226
|
(m, f) => f.size + m,
|
|
224
227
|
0
|
|
225
228
|
);
|
|
@@ -229,49 +232,49 @@ const v = {
|
|
|
229
232
|
toc: d
|
|
230
233
|
},
|
|
231
234
|
renditionLayout: w || s.renditionLayout || "reflowable",
|
|
232
|
-
renditionFlow:
|
|
233
|
-
renditionSpread:
|
|
234
|
-
title:
|
|
235
|
-
readingDirection:
|
|
235
|
+
renditionFlow: W || "auto",
|
|
236
|
+
renditionSpread: se,
|
|
237
|
+
title: ie,
|
|
238
|
+
readingDirection: ae || "ltr",
|
|
236
239
|
spineItems: (l == null ? void 0 : l.childrenNamed("itemref").map((m) => {
|
|
237
|
-
var
|
|
238
|
-
const f = c == null ? void 0 : c.childrenNamed("item").find(($) => $.attr.id === (m == null ? void 0 : m.attr.idref)),
|
|
240
|
+
var B, U, H;
|
|
241
|
+
const f = c == null ? void 0 : c.childrenNamed("item").find(($) => $.attr.id === (m == null ? void 0 : m.attr.idref)), ce = (f == null ? void 0 : f.attr.href) || "", I = ((B = m == null ? void 0 : m.attr.properties) == null ? void 0 : B.split(" ")) || [], de = ((U = e.files.find(($) => $.uri.endsWith(ce))) == null ? void 0 : U.size) || 0, X = t ?? "";
|
|
239
242
|
return {
|
|
240
243
|
id: (f == null ? void 0 : f.attr.id) || "",
|
|
241
|
-
href: (H = f == null ? void 0 : f.attr.href) != null && H.startsWith("https://") ? f == null ? void 0 : f.attr.href : n ? `${
|
|
244
|
+
href: (H = f == null ? void 0 : f.attr.href) != null && H.startsWith("https://") ? f == null ? void 0 : f.attr.href : n ? `${X}${n}/${f == null ? void 0 : f.attr.href}` : `${X}${f == null ? void 0 : f.attr.href}`,
|
|
242
245
|
renditionLayout: w || "reflowable",
|
|
243
246
|
...I.find(
|
|
244
247
|
($) => $ === "rendition:layout-reflowable"
|
|
245
248
|
) && {
|
|
246
249
|
renditionLayout: "reflowable"
|
|
247
250
|
},
|
|
248
|
-
progressionWeight:
|
|
251
|
+
progressionWeight: de / oe,
|
|
249
252
|
pageSpreadLeft: I.some(($) => $ === "page-spread-left") || void 0,
|
|
250
253
|
pageSpreadRight: I.some(($) => $ === "page-spread-right") || void 0,
|
|
251
254
|
// size: itemSize
|
|
252
255
|
mediaType: f == null ? void 0 : f.attr["media-type"]
|
|
253
256
|
};
|
|
254
257
|
})) || [],
|
|
255
|
-
items:
|
|
258
|
+
items: re(o),
|
|
256
259
|
guide: u == null ? void 0 : u.childrenNamed("reference").map((m) => ({
|
|
257
260
|
href: m.attr.href || "",
|
|
258
261
|
title: m.attr.title || "",
|
|
259
262
|
type: m.attr.type
|
|
260
263
|
}))
|
|
261
264
|
};
|
|
262
|
-
},
|
|
265
|
+
}, De = async (e, t) => {
|
|
263
266
|
var n, s;
|
|
264
267
|
const r = await ((n = C(e).data) == null ? void 0 : n.string());
|
|
265
268
|
if (r) {
|
|
266
269
|
const a = new F.XmlDocument(r);
|
|
267
270
|
return {
|
|
268
|
-
mediaType: (s =
|
|
271
|
+
mediaType: (s = re(a).find((d) => t.endsWith(d.href))) == null ? void 0 : s.mediaType
|
|
269
272
|
};
|
|
270
273
|
}
|
|
271
274
|
return {
|
|
272
|
-
mediaType:
|
|
275
|
+
mediaType: Oe(t)
|
|
273
276
|
};
|
|
274
|
-
},
|
|
277
|
+
}, Oe = (e) => {
|
|
275
278
|
if (e.endsWith(".css"))
|
|
276
279
|
return "text/css; charset=UTF-8";
|
|
277
280
|
if (e.endsWith(".jpg"))
|
|
@@ -282,12 +285,12 @@ const v = {
|
|
|
282
285
|
return "video/mp4";
|
|
283
286
|
if (e.endsWith(".svg"))
|
|
284
287
|
return "image/svg+xml";
|
|
285
|
-
},
|
|
288
|
+
}, ze = ({ archive: e, resourcePath: t }) => async (i) => {
|
|
286
289
|
const r = Object.values(e.files).find(
|
|
287
290
|
(s) => s.uri === t
|
|
288
291
|
);
|
|
289
292
|
if (!r) return i;
|
|
290
|
-
const n = await
|
|
293
|
+
const n = await De(e, t);
|
|
291
294
|
return {
|
|
292
295
|
...i,
|
|
293
296
|
params: {
|
|
@@ -300,7 +303,7 @@ const v = {
|
|
|
300
303
|
}
|
|
301
304
|
}
|
|
302
305
|
};
|
|
303
|
-
},
|
|
306
|
+
}, Z = [
|
|
304
307
|
"div",
|
|
305
308
|
"span",
|
|
306
309
|
"p",
|
|
@@ -351,19 +354,19 @@ const v = {
|
|
|
351
354
|
"canvas",
|
|
352
355
|
"script",
|
|
353
356
|
"style"
|
|
354
|
-
],
|
|
357
|
+
], Me = ({ archive: e, resourcePath: t }) => async (i) => {
|
|
355
358
|
const r = Object.values(e.files).find(
|
|
356
359
|
(n) => n.uri === t
|
|
357
360
|
);
|
|
358
361
|
if (r != null && r.basename.endsWith(".xhtml")) {
|
|
359
362
|
const n = i.body ?? await r.string();
|
|
360
363
|
if (!new RegExp(
|
|
361
|
-
`<(${
|
|
364
|
+
`<(${Z.join("|")})[\\s/>]`,
|
|
362
365
|
"i"
|
|
363
366
|
).test(n))
|
|
364
367
|
return i;
|
|
365
368
|
const a = new RegExp(
|
|
366
|
-
`<(${
|
|
369
|
+
`<(${Z.join("|")})(\\s[^>]*)?\\s*/>`,
|
|
367
370
|
"gi"
|
|
368
371
|
), o = n.replace(
|
|
369
372
|
a,
|
|
@@ -375,7 +378,7 @@ const v = {
|
|
|
375
378
|
};
|
|
376
379
|
}
|
|
377
380
|
return i;
|
|
378
|
-
},
|
|
381
|
+
}, Xe = async (e, t) => {
|
|
379
382
|
const i = Object.values(e.files).find(
|
|
380
383
|
(s) => s.uri === t
|
|
381
384
|
);
|
|
@@ -384,10 +387,10 @@ const v = {
|
|
|
384
387
|
const r = {
|
|
385
388
|
params: {}
|
|
386
389
|
}, n = [
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
390
|
+
ze({ archive: e, resourcePath: t }),
|
|
391
|
+
Me({ archive: e, resourcePath: t }),
|
|
392
|
+
ke({ archive: e, resourcePath: t }),
|
|
393
|
+
Se({ archive: e, resourcePath: t })
|
|
391
394
|
];
|
|
392
395
|
try {
|
|
393
396
|
const s = await n.reduce(async (a, o) => await o(await a), Promise.resolve(r));
|
|
@@ -398,7 +401,7 @@ const v = {
|
|
|
398
401
|
} catch (s) {
|
|
399
402
|
throw v.error(s), s;
|
|
400
403
|
}
|
|
401
|
-
},
|
|
404
|
+
}, Be = ({ archive: e, baseUrl: t }) => async () => {
|
|
402
405
|
var r;
|
|
403
406
|
const i = Object.values(e.files).filter((n) => !n.dir);
|
|
404
407
|
return {
|
|
@@ -424,7 +427,7 @@ const v = {
|
|
|
424
427
|
href: `${t}${n.uri}`
|
|
425
428
|
}))
|
|
426
429
|
};
|
|
427
|
-
},
|
|
430
|
+
}, Ue = ({ archive: e }) => async (t) => {
|
|
428
431
|
var s;
|
|
429
432
|
const i = e.files.find(
|
|
430
433
|
(a) => a.basename.toLowerCase() === "comicinfo.xml"
|
|
@@ -448,22 +451,22 @@ const v = {
|
|
|
448
451
|
return console.error(`Unable to parse comicinfo.xml for content
|
|
449
452
|
`, n), console.error(a), r;
|
|
450
453
|
}
|
|
451
|
-
},
|
|
454
|
+
}, He = (e) => {
|
|
452
455
|
var i;
|
|
453
456
|
const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((r) => r.attr.name === "viewport");
|
|
454
457
|
return !!(t && t.attr.name === "viewport");
|
|
455
|
-
},
|
|
456
|
-
if (!await t || !
|
|
458
|
+
}, Ve = (e) => e.reduce(async (t, i) => {
|
|
459
|
+
if (!await t || !ue({
|
|
457
460
|
mimeType: i.encodingFormat,
|
|
458
461
|
uri: i.uri
|
|
459
462
|
}))
|
|
460
463
|
return !1;
|
|
461
464
|
const n = await i.string();
|
|
462
|
-
return n ?
|
|
463
|
-
}, Promise.resolve(!0)),
|
|
465
|
+
return n ? He(new F.XmlDocument(n)) : !1;
|
|
466
|
+
}, Promise.resolve(!0)), _e = ({ archive: e }) => async (t) => {
|
|
464
467
|
if (t.renditionLayout === "reflowable" && t.spineItems.every((r) => r.renditionLayout === "reflowable")) {
|
|
465
|
-
const r = await
|
|
466
|
-
if (await
|
|
468
|
+
const r = await ne({ archive: e });
|
|
469
|
+
if (await Ve(r))
|
|
467
470
|
return {
|
|
468
471
|
...t,
|
|
469
472
|
spineItems: t.spineItems.map((s) => ({
|
|
@@ -481,7 +484,7 @@ const v = {
|
|
|
481
484
|
if (i[s] !== r[s])
|
|
482
485
|
return (n = i[s]) != null && n.match(/\d/) ? +(i[s] || "") - +(r[s] || "") : (i[s] || "").localeCompare(r[s] || "");
|
|
483
486
|
return 1;
|
|
484
|
-
},
|
|
487
|
+
}, qe = ({ archive: e, baseUrl: t }) => async (i) => {
|
|
485
488
|
if (i.nav) return i;
|
|
486
489
|
const r = [...e.files].sort(
|
|
487
490
|
(o, d) => z(o.uri, d.uri)
|
|
@@ -537,7 +540,7 @@ const v = {
|
|
|
537
540
|
if (d.dir) return o;
|
|
538
541
|
const c = d.uri.split("/").slice(0, -1), [l, ...u] = c;
|
|
539
542
|
if (l) {
|
|
540
|
-
const g =
|
|
543
|
+
const g = N(t, encodeURI(d.uri)).replace(/\/$/, ""), b = d.uri.replace(/\/$/, "");
|
|
541
544
|
return s(o, l, u, g, b);
|
|
542
545
|
}
|
|
543
546
|
return o;
|
|
@@ -550,7 +553,7 @@ const v = {
|
|
|
550
553
|
toc: a
|
|
551
554
|
}
|
|
552
555
|
};
|
|
553
|
-
},
|
|
556
|
+
}, Ge = {
|
|
554
557
|
filename: "",
|
|
555
558
|
items: [],
|
|
556
559
|
nav: {
|
|
@@ -561,21 +564,21 @@ const v = {
|
|
|
561
564
|
renditionSpread: "auto",
|
|
562
565
|
spineItems: [],
|
|
563
566
|
title: ""
|
|
564
|
-
},
|
|
567
|
+
}, Ke = async (e, { baseUrl: t = "" } = {}) => {
|
|
565
568
|
const i = [
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
569
|
+
Be({ archive: e, baseUrl: t }),
|
|
570
|
+
je({ archive: e, baseUrl: t }),
|
|
571
|
+
_e({ archive: e, baseUrl: t }),
|
|
572
|
+
Ue({ archive: e, baseUrl: t }),
|
|
573
|
+
qe({ archive: e, baseUrl: t })
|
|
571
574
|
];
|
|
572
575
|
try {
|
|
573
|
-
const r = await i.reduce(async (n, s) => await s(await n), Promise.resolve(
|
|
576
|
+
const r = await i.reduce(async (n, s) => await s(await n), Promise.resolve(Ge));
|
|
574
577
|
return v.log("Generated manifest", r), r;
|
|
575
578
|
} catch (r) {
|
|
576
579
|
throw v.error(r), r;
|
|
577
580
|
}
|
|
578
|
-
},
|
|
581
|
+
}, nt = async (e, t) => {
|
|
579
582
|
const i = `
|
|
580
583
|
<?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
|
|
581
584
|
<metadata>
|
|
@@ -614,7 +617,7 @@ const v = {
|
|
|
614
617
|
}, ...r],
|
|
615
618
|
close: () => Promise.resolve()
|
|
616
619
|
};
|
|
617
|
-
},
|
|
620
|
+
}, rt = async (e, {
|
|
618
621
|
mimeType: t,
|
|
619
622
|
direction: i
|
|
620
623
|
} = { mimeType: "text/plain" }) => {
|
|
@@ -657,7 +660,7 @@ const v = {
|
|
|
657
660
|
],
|
|
658
661
|
close: () => Promise.resolve()
|
|
659
662
|
};
|
|
660
|
-
},
|
|
663
|
+
}, st = async (e, { orderByAlpha: t, name: i } = {}) => {
|
|
661
664
|
let r = Object.values(e.files);
|
|
662
665
|
t && (r = r.slice().sort((s, a) => z(s.name, a.name)));
|
|
663
666
|
const n = {
|
|
@@ -679,7 +682,7 @@ const v = {
|
|
|
679
682
|
close: () => Promise.resolve()
|
|
680
683
|
};
|
|
681
684
|
return v.log("Generated archive", n), n;
|
|
682
|
-
},
|
|
685
|
+
}, it = async (e, { name: t } = {}) => {
|
|
683
686
|
const i = await e.getFilesArray(), r = {
|
|
684
687
|
close: () => e.close(),
|
|
685
688
|
filename: t ?? "",
|
|
@@ -693,7 +696,7 @@ const v = {
|
|
|
693
696
|
}))
|
|
694
697
|
};
|
|
695
698
|
return v.log("Generated archive", r), r;
|
|
696
|
-
},
|
|
699
|
+
}, at = async (e, { orderByAlpha: t, name: i } = {}) => {
|
|
697
700
|
let r = e;
|
|
698
701
|
return t && (r = r.slice().sort((n, s) => z(n.name, s.name))), {
|
|
699
702
|
filename: i || "",
|
|
@@ -713,14 +716,14 @@ const v = {
|
|
|
713
716
|
})),
|
|
714
717
|
close: () => Promise.resolve()
|
|
715
718
|
};
|
|
716
|
-
},
|
|
719
|
+
}, ot = ({
|
|
717
720
|
enableReport: e
|
|
718
721
|
} = {}) => {
|
|
719
722
|
v.enable(!!e);
|
|
720
723
|
};
|
|
721
|
-
class
|
|
724
|
+
class Je {
|
|
722
725
|
constructor(t) {
|
|
723
|
-
this.cleanArchiveAfter = t, this.state$ = new
|
|
726
|
+
this.cleanArchiveAfter = t, this.state$ = new we({
|
|
724
727
|
status: "idle",
|
|
725
728
|
locks: 0
|
|
726
729
|
});
|
|
@@ -737,19 +740,19 @@ class _e {
|
|
|
737
740
|
get isUnlocked$() {
|
|
738
741
|
return this.locks$.pipe(
|
|
739
742
|
A((t) => t <= 0),
|
|
740
|
-
|
|
741
|
-
|
|
743
|
+
ve(),
|
|
744
|
+
$e()
|
|
742
745
|
);
|
|
743
746
|
}
|
|
744
747
|
get overTTL$() {
|
|
745
748
|
return this.isUnlocked$.pipe(
|
|
746
|
-
|
|
747
|
-
(t) => t ? this.cleanArchiveAfter === 1 / 0 ? G :
|
|
749
|
+
k(
|
|
750
|
+
(t) => t ? this.cleanArchiveAfter === 1 / 0 ? G : xe(this.cleanArchiveAfter) : G
|
|
748
751
|
)
|
|
749
752
|
);
|
|
750
753
|
}
|
|
751
754
|
}
|
|
752
|
-
const
|
|
755
|
+
const Ye = ({
|
|
753
756
|
getArchive: e,
|
|
754
757
|
cleanArchiveAfter: t = 5 * 60 * 1e3
|
|
755
758
|
// 5mn
|
|
@@ -760,17 +763,17 @@ const qe = ({
|
|
|
760
763
|
if (!c || c.state.status !== "idle") return _;
|
|
761
764
|
let l = !1;
|
|
762
765
|
const u = (y) => {
|
|
763
|
-
var
|
|
766
|
+
var W;
|
|
764
767
|
const w = s[y];
|
|
765
|
-
delete s[y], l || ((
|
|
768
|
+
delete s[y], l || ((W = w == null ? void 0 : w.state.archive) == null || W.close(), l = !0);
|
|
766
769
|
};
|
|
767
770
|
c.update({
|
|
768
771
|
status: "loading"
|
|
769
772
|
});
|
|
770
773
|
const g = c.locks$, b = c.isUnlocked$, h = g.pipe(
|
|
771
|
-
|
|
774
|
+
me(),
|
|
772
775
|
j(([y, w]) => w > y),
|
|
773
|
-
|
|
776
|
+
he(!0)
|
|
774
777
|
);
|
|
775
778
|
return L(e(p)).pipe(
|
|
776
779
|
D((y) => {
|
|
@@ -783,10 +786,10 @@ const qe = ({
|
|
|
783
786
|
status: "error",
|
|
784
787
|
error: y
|
|
785
788
|
}), _)),
|
|
786
|
-
|
|
789
|
+
k(() => {
|
|
787
790
|
const y = h.pipe(
|
|
788
|
-
|
|
789
|
-
|
|
791
|
+
k(() => n),
|
|
792
|
+
k(() => b),
|
|
790
793
|
j((w) => w)
|
|
791
794
|
);
|
|
792
795
|
return q(y, c.overTTL$);
|
|
@@ -796,10 +799,10 @@ const qe = ({
|
|
|
796
799
|
})
|
|
797
800
|
);
|
|
798
801
|
}),
|
|
799
|
-
|
|
802
|
+
ge(r)
|
|
800
803
|
), o = (p) => {
|
|
801
804
|
let c = !1;
|
|
802
|
-
const l = s[p] ?? new
|
|
805
|
+
const l = s[p] ?? new Je(t);
|
|
803
806
|
s[p] = l, l.update({
|
|
804
807
|
locks: l.state.locks + 1
|
|
805
808
|
});
|
|
@@ -817,10 +820,10 @@ const qe = ({
|
|
|
817
820
|
if (h)
|
|
818
821
|
throw h;
|
|
819
822
|
}),
|
|
820
|
-
|
|
823
|
+
ye()
|
|
821
824
|
);
|
|
822
825
|
return q(g, b).pipe(
|
|
823
|
-
|
|
826
|
+
be(),
|
|
824
827
|
A((h) => ({ archive: h, release: u })),
|
|
825
828
|
P((h) => {
|
|
826
829
|
throw u(), h;
|
|
@@ -835,13 +838,13 @@ const qe = ({
|
|
|
835
838
|
archives: s
|
|
836
839
|
};
|
|
837
840
|
};
|
|
838
|
-
class
|
|
841
|
+
class Qe {
|
|
839
842
|
constructor({
|
|
840
843
|
onError: t,
|
|
841
844
|
onManifestSuccess: i,
|
|
842
845
|
...r
|
|
843
846
|
}) {
|
|
844
|
-
this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader =
|
|
847
|
+
this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = Ye(r), this.onManifestSuccess = i ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
|
|
845
848
|
}
|
|
846
849
|
prune() {
|
|
847
850
|
this.epubLoader.purge();
|
|
@@ -857,9 +860,9 @@ class Ge {
|
|
|
857
860
|
fetchManifest({ key: t, baseUrl: i }) {
|
|
858
861
|
const r = this.accessArchive(t).pipe(
|
|
859
862
|
O(({ archive: n, release: s }) => L(
|
|
860
|
-
|
|
863
|
+
Ke(n, { baseUrl: i })
|
|
861
864
|
).pipe(
|
|
862
|
-
|
|
865
|
+
k(
|
|
863
866
|
(o) => L(this.onManifestSuccess({ manifest: o, archive: n }))
|
|
864
867
|
),
|
|
865
868
|
A(
|
|
@@ -881,7 +884,7 @@ class Ge {
|
|
|
881
884
|
}) {
|
|
882
885
|
const r = this.accessArchive(t).pipe(
|
|
883
886
|
O(({ archive: n, release: s }) => L(
|
|
884
|
-
|
|
887
|
+
Xe(n, i)
|
|
885
888
|
).pipe(
|
|
886
889
|
A(
|
|
887
890
|
(o) => new Response(o.body, {
|
|
@@ -902,7 +905,7 @@ class Ge {
|
|
|
902
905
|
return Y(r);
|
|
903
906
|
}
|
|
904
907
|
}
|
|
905
|
-
class
|
|
908
|
+
class ct extends Qe {
|
|
906
909
|
constructor({
|
|
907
910
|
getUriInfo: t,
|
|
908
911
|
...i
|
|
@@ -913,10 +916,10 @@ class st extends Ge {
|
|
|
913
916
|
try {
|
|
914
917
|
const i = this.getUriInfo(t);
|
|
915
918
|
if (!i) return;
|
|
916
|
-
const r =
|
|
919
|
+
const r = Q(i.baseUrl), n = t.request.url.substring(
|
|
917
920
|
r.length + 1
|
|
918
921
|
), [s = ""] = n.split("/"), a = decodeURIComponent(
|
|
919
|
-
|
|
922
|
+
Q(n.substring(s.length + 1))
|
|
920
923
|
);
|
|
921
924
|
n.endsWith("/manifest") ? t.respondWith(
|
|
922
925
|
this.fetchManifest({ key: s, baseUrl: `${r}/${s}/` })
|
|
@@ -927,16 +930,16 @@ class st extends Ge {
|
|
|
927
930
|
}
|
|
928
931
|
}
|
|
929
932
|
export {
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
933
|
+
ct as ServiceWorkerStreamer,
|
|
934
|
+
Qe as Streamer,
|
|
935
|
+
ot as configure,
|
|
936
|
+
at as createArchiveFromArrayBufferList,
|
|
937
|
+
st as createArchiveFromJszip,
|
|
938
|
+
it as createArchiveFromLibArchive,
|
|
939
|
+
rt as createArchiveFromText,
|
|
940
|
+
nt as createArchiveFromUrls,
|
|
941
|
+
Ke as generateManifestFromArchive,
|
|
942
|
+
Xe as generateResourceFromArchive,
|
|
940
943
|
C as getArchiveOpfInfo
|
|
941
944
|
};
|
|
942
945
|
//# sourceMappingURL=index.js.map
|