@prose-reader/streamer 1.81.0 → 1.83.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/ServiceWorkerStreamer.d.ts +7 -3
- package/dist/ServiceWorkerStreamer.test.d.ts +1 -0
- package/dist/archives/archiveLoader.d.ts +2 -2
- package/dist/index.js +133 -132
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +5 -5
- package/dist/index.umd.cjs.map +1 -1
- package/dist/utils/uri.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { urlJoin as N, PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME as
|
|
2
|
-
import y, { XmlDocument as
|
|
3
|
-
import { Subject as
|
|
4
|
-
let
|
|
1
|
+
import { urlJoin as N, PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME as ie, isXmlBasedMimeType as oe, detectMimeTypeFromName as M } from "@prose-reader/shared";
|
|
2
|
+
import y, { XmlDocument as ce } from "xmldoc";
|
|
3
|
+
import { Subject as V, mergeMap as L, EMPTY as de, from as A, map as v, catchError as F, NEVER as U, shareReplay as le, switchMap as X, timer as me, tap as B, merge as _, takeUntil as pe, BehaviorSubject as fe, filter as ue, ignoreElements as he, first as ge, finalize as H, of as G, lastValueFrom as J } from "rxjs";
|
|
4
|
+
let x = !1;
|
|
5
5
|
const g = {
|
|
6
6
|
enable: (e) => {
|
|
7
|
-
|
|
7
|
+
x = e;
|
|
8
8
|
},
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
10
|
log: (...e) => {
|
|
11
|
-
|
|
11
|
+
x && 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
|
+
x && 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
|
+
x && console.time(`[prose-reader-streamer] [metric] ${e}`);
|
|
23
23
|
},
|
|
24
24
|
timeEnd: (e) => {
|
|
25
|
-
|
|
25
|
+
x && console.timeEnd(`[prose-reader-streamer] [metric] ${e}`);
|
|
26
26
|
},
|
|
27
27
|
metric: (e, n = 1 / 0) => {
|
|
28
28
|
const s = typeof e == "number" ? e : e.duration;
|
|
29
|
-
|
|
29
|
+
x && (e.duration <= n ? console.log(
|
|
30
30
|
"[prose-reader-streamer] [metric] ",
|
|
31
31
|
`${e.name} took ${s}ms`
|
|
32
32
|
) : console.warn(
|
|
@@ -45,23 +45,23 @@ const g = {
|
|
|
45
45
|
const i = performance.now();
|
|
46
46
|
return g.metric({ name: e, duration: i - t }, n), a;
|
|
47
47
|
}
|
|
48
|
-
},
|
|
48
|
+
}, be = (e) => {
|
|
49
49
|
var s;
|
|
50
50
|
const n = (s = e.descendantWithPath("head")) == null ? void 0 : s.childrenNamed("meta").find((r) => r.attr.name === "calibre:cover");
|
|
51
51
|
return !!(n && n.attr.name === "calibre:cover");
|
|
52
|
-
},
|
|
52
|
+
}, ye = (e) => {
|
|
53
53
|
var n, s, r;
|
|
54
54
|
return (r = (s = (n = e.descendantWithPath("body")) == null ? void 0 : n.descendantWithPath("div")) == null ? void 0 : s.childrenNamed("svg")) == null ? void 0 : r.find(
|
|
55
55
|
(t) => t.attr.width === "100%" && t.attr.preserveAspectRatio === "none"
|
|
56
56
|
);
|
|
57
|
-
},
|
|
57
|
+
}, we = ({ archive: e, resourcePath: n }) => async (s) => {
|
|
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 = s.body ?? await r.string(), a = new
|
|
63
|
-
if (
|
|
64
|
-
const i =
|
|
62
|
+
const t = s.body ?? await r.string(), a = new ce(t);
|
|
63
|
+
if (be(a)) {
|
|
64
|
+
const i = ye(a);
|
|
65
65
|
return i && delete i.attr.preserveAspectRatio, {
|
|
66
66
|
...s,
|
|
67
67
|
body: a == null ? void 0 : a.toString()
|
|
@@ -69,7 +69,7 @@ const g = {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
return s;
|
|
72
|
-
},
|
|
72
|
+
}, ve = ({ archive: e, resourcePath: n }) => async (s) => we({ archive: e, resourcePath: n })(s), $e = ({ archive: e, resourcePath: n }) => async (s) => {
|
|
73
73
|
const r = Object.values(e.files).find(
|
|
74
74
|
(t) => t.uri === n
|
|
75
75
|
);
|
|
@@ -84,13 +84,13 @@ const g = {
|
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
return s;
|
|
87
|
-
},
|
|
87
|
+
}, T = (e) => {
|
|
88
88
|
const s = Object.values(e.files).filter((r) => !r.dir).find((r) => r.uri.endsWith(".opf"));
|
|
89
89
|
return {
|
|
90
90
|
data: s,
|
|
91
91
|
basePath: (s == null ? void 0 : s.uri.substring(0, s.uri.lastIndexOf("/"))) || ""
|
|
92
92
|
};
|
|
93
|
-
},
|
|
93
|
+
}, Y = (e, { opfBasePath: n, baseUrl: s }) => {
|
|
94
94
|
const r = {
|
|
95
95
|
contents: [],
|
|
96
96
|
path: "",
|
|
@@ -105,7 +105,7 @@ const g = {
|
|
|
105
105
|
if (i) {
|
|
106
106
|
const o = i.childrenNamed("li");
|
|
107
107
|
o && o.length > 0 && (r.contents = o.map(
|
|
108
|
-
(c) =>
|
|
108
|
+
(c) => Y(c, { opfBasePath: n, baseUrl: s })
|
|
109
109
|
));
|
|
110
110
|
}
|
|
111
111
|
return r;
|
|
@@ -114,9 +114,9 @@ const g = {
|
|
|
114
114
|
const r = [];
|
|
115
115
|
let t;
|
|
116
116
|
return e.descendantWithPath("body.nav.ol") ? t = (a = e.descendantWithPath("body.nav.ol")) == null ? void 0 : a.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(
|
|
117
|
+
(o) => r.push(Y(o, { opfBasePath: n, baseUrl: s }))
|
|
118
118
|
), r;
|
|
119
|
-
},
|
|
119
|
+
}, Fe = async (e, n, { opfBasePath: s, baseUrl: r }) => {
|
|
120
120
|
var a;
|
|
121
121
|
const t = (a = e.childNamed("manifest")) == null ? void 0 : a.childrenNamed("item").find((i) => i.attr.properties === "nav");
|
|
122
122
|
if (t) {
|
|
@@ -128,7 +128,7 @@ const g = {
|
|
|
128
128
|
return xe(o, { opfBasePath: s, baseUrl: r });
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
},
|
|
131
|
+
}, K = (e, {
|
|
132
132
|
opfBasePath: n,
|
|
133
133
|
baseUrl: s,
|
|
134
134
|
prefix: r
|
|
@@ -141,16 +141,16 @@ const g = {
|
|
|
141
141
|
contents: []
|
|
142
142
|
}, i = e.childrenNamed(`${r}navPoint`);
|
|
143
143
|
return i && i.length > 0 && (a.contents = i.map(
|
|
144
|
-
(l) =>
|
|
144
|
+
(l) => K(l, { opfBasePath: n, baseUrl: s, prefix: r })
|
|
145
145
|
)), a;
|
|
146
|
-
},
|
|
146
|
+
}, Ne = (e, { opfBasePath: n, baseUrl: s }) => {
|
|
147
147
|
var i;
|
|
148
148
|
const r = [], t = e.name;
|
|
149
149
|
let a = "";
|
|
150
150
|
return t.indexOf(":") !== -1 && (a = t.split(":")[0] + ":"), (i = e.childNamed(`${a}navMap`)) == null || i.childrenNamed(`${a}navPoint`).forEach(
|
|
151
|
-
(o) => r.push(
|
|
151
|
+
(o) => r.push(K(o, { opfBasePath: n, baseUrl: s, prefix: a }))
|
|
152
152
|
), r;
|
|
153
|
-
},
|
|
153
|
+
}, Te = async ({
|
|
154
154
|
opfData: e,
|
|
155
155
|
opfBasePath: n,
|
|
156
156
|
baseUrl: s,
|
|
@@ -166,19 +166,19 @@ const g = {
|
|
|
166
166
|
);
|
|
167
167
|
if (l) {
|
|
168
168
|
const d = new y.XmlDocument(await l.string());
|
|
169
|
-
return
|
|
169
|
+
return Ne(d, { opfBasePath: n, baseUrl: s });
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
}, Se = async (e, n, { baseUrl: s }) => {
|
|
174
|
-
const { basePath: r } =
|
|
174
|
+
const { basePath: r } = T(n) || {}, t = await Te({
|
|
175
175
|
opfData: e,
|
|
176
176
|
opfBasePath: r,
|
|
177
177
|
archive: n,
|
|
178
178
|
baseUrl: s
|
|
179
179
|
});
|
|
180
|
-
return t || await
|
|
181
|
-
},
|
|
180
|
+
return t || await Fe(e, n, { opfBasePath: r, baseUrl: s });
|
|
181
|
+
}, ke = async (e) => {
|
|
182
182
|
const n = {
|
|
183
183
|
renditionLayout: void 0
|
|
184
184
|
};
|
|
@@ -191,14 +191,14 @@ const g = {
|
|
|
191
191
|
}
|
|
192
192
|
})
|
|
193
193
|
), n;
|
|
194
|
-
},
|
|
194
|
+
}, E = async ({
|
|
195
195
|
archive: e
|
|
196
196
|
}) => {
|
|
197
|
-
const { data: n, basePath: s } =
|
|
197
|
+
const { data: n, basePath: s } = T(e) || {}, r = await (n == null ? void 0 : n.string());
|
|
198
198
|
if (!r) return [];
|
|
199
199
|
const t = new y.XmlDocument(r), a = t.childNamed("manifest"), i = t.childNamed("spine"), o = i == null ? void 0 : i.childrenNamed("itemref").map((d) => d.attr.idref), c = (a == null ? void 0 : a.childrenNamed("item").filter((d) => o.includes(d.attr.id || ""))) || [];
|
|
200
200
|
return e.files.filter((d) => c.find((u) => s ? `${s}/${u.attr.href}` === d.uri : `${u.attr.href}` === d.uri));
|
|
201
|
-
},
|
|
201
|
+
}, Q = (e) => {
|
|
202
202
|
var s;
|
|
203
203
|
const n = e.childNamed("manifest");
|
|
204
204
|
return ((s = n == null ? void 0 : n.childrenNamed("item")) == null ? void 0 : s.map((r) => ({
|
|
@@ -206,20 +206,20 @@ const g = {
|
|
|
206
206
|
id: r.attr.id || "",
|
|
207
207
|
mediaType: r.attr["media-type"]
|
|
208
208
|
}))) || [];
|
|
209
|
-
},
|
|
209
|
+
}, Re = ({ archive: e, baseUrl: n }) => async (s) => {
|
|
210
210
|
var P;
|
|
211
|
-
const { data: r, basePath: t } =
|
|
211
|
+
const { data: r, basePath: t } = T(e) || {}, a = await ke(e);
|
|
212
212
|
if (!r)
|
|
213
213
|
return s;
|
|
214
214
|
const i = await r.string();
|
|
215
215
|
g.log(i, a);
|
|
216
|
-
const o = new y.XmlDocument(i), c = await Se(o, e, { baseUrl: n }) || [], l = o.childNamed("metadata"), d = o.childNamed("manifest"), u = o.childNamed("spine"), f = o.childNamed("guide"), w = l == null ? void 0 : l.childNamed("dc:title"), h = (l == null ? void 0 : l.childrenNamed("meta")) || [],
|
|
216
|
+
const o = new y.XmlDocument(i), c = await Se(o, e, { baseUrl: n }) || [], l = o.childNamed("metadata"), d = o.childNamed("manifest"), u = o.childNamed("spine"), f = o.childNamed("guide"), w = l == null ? void 0 : l.childNamed("dc:title"), h = (l == null ? void 0 : l.childrenNamed("meta")) || [], S = h.find(
|
|
217
217
|
(p) => p.attr.property === "rendition:layout"
|
|
218
218
|
), k = h.find(
|
|
219
219
|
(p) => p.attr.property === "rendition:flow"
|
|
220
220
|
), R = h.find(
|
|
221
221
|
(p) => p.attr.property === "rendition:spread"
|
|
222
|
-
), C =
|
|
222
|
+
), C = S == null ? void 0 : S.val, Z = k == null ? void 0 : k.val, ee = R == null ? void 0 : R.val, te = (w == null ? void 0 : w.val) || ((P = e.files.find(({ dir: p }) => p)) == null ? void 0 : P.basename) || "", ne = u == null ? void 0 : u.attr["page-progression-direction"], re = (await E({ archive: e })).reduce(
|
|
223
223
|
(p, m) => m.size + p,
|
|
224
224
|
0
|
|
225
225
|
);
|
|
@@ -229,43 +229,43 @@ const g = {
|
|
|
229
229
|
toc: c
|
|
230
230
|
},
|
|
231
231
|
renditionLayout: C || a.renditionLayout || "reflowable",
|
|
232
|
-
renditionFlow:
|
|
233
|
-
renditionSpread:
|
|
234
|
-
title:
|
|
235
|
-
readingDirection:
|
|
232
|
+
renditionFlow: Z || "auto",
|
|
233
|
+
renditionSpread: ee,
|
|
234
|
+
title: te,
|
|
235
|
+
readingDirection: ne || "ltr",
|
|
236
236
|
spineItems: (u == null ? void 0 : u.childrenNamed("itemref").map((p) => {
|
|
237
|
-
var O, j,
|
|
238
|
-
const m = d == null ? void 0 : d.childrenNamed("item").find((b) => b.attr.id === (p == null ? void 0 : p.attr.idref)),
|
|
237
|
+
var O, j, z;
|
|
238
|
+
const m = d == null ? void 0 : d.childrenNamed("item").find((b) => b.attr.id === (p == null ? void 0 : p.attr.idref)), ae = (m == null ? void 0 : m.attr.href) || "", W = ((O = p == null ? void 0 : p.attr.properties) == null ? void 0 : O.split(" ")) || [], se = ((j = e.files.find((b) => b.uri.endsWith(ae))) == null ? void 0 : j.size) || 0, D = n ?? "";
|
|
239
239
|
return {
|
|
240
240
|
id: (m == null ? void 0 : m.attr.id) || "",
|
|
241
|
-
href: (
|
|
241
|
+
href: (z = m == null ? void 0 : m.attr.href) != null && z.startsWith("https://") ? m == null ? void 0 : m.attr.href : t ? `${D}${t}/${m == null ? void 0 : m.attr.href}` : `${D}${m == null ? void 0 : m.attr.href}`,
|
|
242
242
|
renditionLayout: C || "reflowable",
|
|
243
|
-
...
|
|
243
|
+
...W.find(
|
|
244
244
|
(b) => b === "rendition:layout-reflowable"
|
|
245
245
|
) && {
|
|
246
246
|
renditionLayout: "reflowable"
|
|
247
247
|
},
|
|
248
|
-
progressionWeight:
|
|
249
|
-
pageSpreadLeft:
|
|
250
|
-
pageSpreadRight:
|
|
248
|
+
progressionWeight: se / re,
|
|
249
|
+
pageSpreadLeft: W.some((b) => b === "page-spread-left") || void 0,
|
|
250
|
+
pageSpreadRight: W.some((b) => b === "page-spread-right") || void 0,
|
|
251
251
|
// size: itemSize
|
|
252
252
|
mediaType: m == null ? void 0 : m.attr["media-type"]
|
|
253
253
|
};
|
|
254
254
|
})) || [],
|
|
255
|
-
items:
|
|
255
|
+
items: Q(o),
|
|
256
256
|
guide: f == null ? void 0 : f.childrenNamed("reference").map((p) => ({
|
|
257
257
|
href: p.attr.href || "",
|
|
258
258
|
title: p.attr.title || "",
|
|
259
259
|
type: p.attr.type
|
|
260
260
|
}))
|
|
261
261
|
};
|
|
262
|
-
},
|
|
262
|
+
}, We = async (e, n) => {
|
|
263
263
|
var t, a;
|
|
264
|
-
const r = await ((t =
|
|
264
|
+
const r = await ((t = T(e).data) == null ? void 0 : t.string());
|
|
265
265
|
if (r) {
|
|
266
266
|
const i = new y.XmlDocument(r);
|
|
267
267
|
return {
|
|
268
|
-
mediaType: (a =
|
|
268
|
+
mediaType: (a = Q(i).find((c) => n.endsWith(c.href))) == null ? void 0 : a.mediaType
|
|
269
269
|
};
|
|
270
270
|
}
|
|
271
271
|
return {
|
|
@@ -282,12 +282,12 @@ const g = {
|
|
|
282
282
|
return "video/mp4";
|
|
283
283
|
if (e.endsWith(".svg"))
|
|
284
284
|
return "image/svg+xml";
|
|
285
|
-
},
|
|
285
|
+
}, Ae = ({ archive: e, resourcePath: n }) => async (s) => {
|
|
286
286
|
const r = Object.values(e.files).find(
|
|
287
287
|
(a) => a.uri === n
|
|
288
288
|
);
|
|
289
289
|
if (!r) return s;
|
|
290
|
-
const t = await
|
|
290
|
+
const t = await We(e, n);
|
|
291
291
|
return {
|
|
292
292
|
...s,
|
|
293
293
|
params: {
|
|
@@ -303,7 +303,7 @@ const g = {
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
};
|
|
306
|
-
},
|
|
306
|
+
}, Ie = async (e, n) => {
|
|
307
307
|
const s = Object.values(e.files).find(
|
|
308
308
|
(a) => a.uri === n
|
|
309
309
|
);
|
|
@@ -314,9 +314,9 @@ const g = {
|
|
|
314
314
|
status: 200
|
|
315
315
|
}
|
|
316
316
|
}, t = [
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
317
|
+
Ae({ archive: e, resourcePath: n }),
|
|
318
|
+
$e({ archive: e, resourcePath: n }),
|
|
319
|
+
ve({ archive: e, resourcePath: n })
|
|
320
320
|
];
|
|
321
321
|
try {
|
|
322
322
|
const a = await t.reduce(async (i, o) => await o(await i), Promise.resolve(r));
|
|
@@ -332,7 +332,7 @@ const g = {
|
|
|
332
332
|
<!DOCTYPE html>
|
|
333
333
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
|
|
334
334
|
<head>
|
|
335
|
-
<meta name="${
|
|
335
|
+
<meta name="${ie}" content="${String(e)}" />
|
|
336
336
|
</head>
|
|
337
337
|
<body>
|
|
338
338
|
<pre>${String(e)}</pre>
|
|
@@ -345,7 +345,7 @@ const g = {
|
|
|
345
345
|
"Content-Type": "text/html;charset=UTF-8"
|
|
346
346
|
}
|
|
347
347
|
}
|
|
348
|
-
}),
|
|
348
|
+
}), Ce = ({ archive: e, baseUrl: n }) => async () => {
|
|
349
349
|
var r;
|
|
350
350
|
const s = Object.values(e.files).filter((t) => !t.dir);
|
|
351
351
|
return {
|
|
@@ -371,7 +371,7 @@ const g = {
|
|
|
371
371
|
href: `${n}${t.uri}`
|
|
372
372
|
}))
|
|
373
373
|
};
|
|
374
|
-
},
|
|
374
|
+
}, Pe = ({ archive: e }) => async (n) => {
|
|
375
375
|
var a;
|
|
376
376
|
const s = e.files.find(
|
|
377
377
|
(i) => i.basename.toLowerCase() === "comicinfo.xml"
|
|
@@ -395,22 +395,22 @@ const g = {
|
|
|
395
395
|
return console.error(`Unable to parse comicinfo.xml for content
|
|
396
396
|
`, t), console.error(i), r;
|
|
397
397
|
}
|
|
398
|
-
},
|
|
398
|
+
}, De = (e) => {
|
|
399
399
|
var s;
|
|
400
400
|
const n = (s = e.descendantWithPath("head")) == null ? void 0 : s.childrenNamed("meta").find((r) => r.attr.name === "viewport");
|
|
401
401
|
return !!(n && n.attr.name === "viewport");
|
|
402
|
-
},
|
|
403
|
-
if (!await n || !
|
|
402
|
+
}, Oe = (e) => e.reduce(async (n, s) => {
|
|
403
|
+
if (!await n || !oe({
|
|
404
404
|
mimeType: s.encodingFormat,
|
|
405
405
|
uri: s.uri
|
|
406
406
|
}))
|
|
407
407
|
return !1;
|
|
408
408
|
const t = await s.string();
|
|
409
|
-
return t ?
|
|
410
|
-
}, Promise.resolve(!0)),
|
|
409
|
+
return t ? De(new y.XmlDocument(t)) : !1;
|
|
410
|
+
}, Promise.resolve(!0)), je = ({ archive: e }) => async (n) => {
|
|
411
411
|
if (n.renditionLayout === "reflowable" && n.spineItems.every((r) => r.renditionLayout === "reflowable")) {
|
|
412
|
-
const r = await
|
|
413
|
-
if (await
|
|
412
|
+
const r = await E({ archive: e });
|
|
413
|
+
if (await Oe(r))
|
|
414
414
|
return {
|
|
415
415
|
...n,
|
|
416
416
|
spineItems: n.spineItems.map((a) => ({
|
|
@@ -428,7 +428,7 @@ const g = {
|
|
|
428
428
|
if (s[a] !== r[a])
|
|
429
429
|
return (t = s[a]) != null && t.match(/\d/) ? +(s[a] || "") - +(r[a] || "") : (s[a] || "").localeCompare(r[a] || "");
|
|
430
430
|
return 1;
|
|
431
|
-
},
|
|
431
|
+
}, ze = ({ archive: e, baseUrl: n }) => async (s) => {
|
|
432
432
|
if (s.nav) return s;
|
|
433
433
|
const r = [...e.files].sort(
|
|
434
434
|
(a, i) => I(a.uri, i.uri)
|
|
@@ -455,7 +455,7 @@ const g = {
|
|
|
455
455
|
toc: t
|
|
456
456
|
}
|
|
457
457
|
};
|
|
458
|
-
},
|
|
458
|
+
}, Me = {
|
|
459
459
|
filename: "",
|
|
460
460
|
items: [],
|
|
461
461
|
nav: {
|
|
@@ -466,21 +466,21 @@ const g = {
|
|
|
466
466
|
renditionSpread: "auto",
|
|
467
467
|
spineItems: [],
|
|
468
468
|
title: ""
|
|
469
|
-
},
|
|
469
|
+
}, Ve = async (e, { baseUrl: n = "" } = {}) => {
|
|
470
470
|
const s = [
|
|
471
|
-
Ie({ archive: e, baseUrl: n }),
|
|
472
|
-
ke({ archive: e, baseUrl: n }),
|
|
473
|
-
Oe({ archive: e, baseUrl: n }),
|
|
474
471
|
Ce({ archive: e, baseUrl: n }),
|
|
475
|
-
|
|
472
|
+
Re({ archive: e, baseUrl: n }),
|
|
473
|
+
je({ archive: e, baseUrl: n }),
|
|
474
|
+
Pe({ archive: e, baseUrl: n }),
|
|
475
|
+
ze({ archive: e, baseUrl: n })
|
|
476
476
|
];
|
|
477
477
|
try {
|
|
478
|
-
const r = await s.reduce(async (t, a) => await a(await t), Promise.resolve(
|
|
478
|
+
const r = await s.reduce(async (t, a) => await a(await t), Promise.resolve(Me));
|
|
479
479
|
return g.log("Generated manifest", r), r;
|
|
480
480
|
} catch (r) {
|
|
481
481
|
throw g.error(r), r;
|
|
482
482
|
}
|
|
483
|
-
},
|
|
483
|
+
}, $ = (e) => e.substring(e.lastIndexOf("/") + 1) || e, q = (e) => e.endsWith("/") ? e.slice(0, -1) : e, Ye = async (e, n) => {
|
|
484
484
|
const s = `
|
|
485
485
|
<?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
|
|
486
486
|
<metadata>
|
|
@@ -489,19 +489,19 @@ const g = {
|
|
|
489
489
|
</metadata>
|
|
490
490
|
<manifest>
|
|
491
491
|
${e.map(
|
|
492
|
-
(a) => `<item id="${
|
|
492
|
+
(a) => `<item id="${$(a)}" href="${a}" media-type="${M(a)}"/>`
|
|
493
493
|
).join(`
|
|
494
494
|
`)}
|
|
495
495
|
</manifest>
|
|
496
496
|
<spine>
|
|
497
|
-
${e.map((a) => `<itemref idref="${
|
|
497
|
+
${e.map((a) => `<itemref idref="${$(a)}" />`).join(`
|
|
498
498
|
`)}
|
|
499
499
|
</spine>
|
|
500
500
|
</package>
|
|
501
501
|
`, r = e.map((a) => ({
|
|
502
502
|
dir: !1,
|
|
503
|
-
basename:
|
|
504
|
-
encodingFormat:
|
|
503
|
+
basename: $(a),
|
|
504
|
+
encodingFormat: M(a),
|
|
505
505
|
uri: a,
|
|
506
506
|
size: 100 / e.length,
|
|
507
507
|
base64: async () => "",
|
|
@@ -521,7 +521,7 @@ const g = {
|
|
|
521
521
|
}, ...r],
|
|
522
522
|
close: () => Promise.resolve()
|
|
523
523
|
};
|
|
524
|
-
},
|
|
524
|
+
}, Ue = async (e) => new Promise((n) => {
|
|
525
525
|
const s = new FileReader();
|
|
526
526
|
s.readAsDataURL(e), s.onloadend = function() {
|
|
527
527
|
const r = s.result;
|
|
@@ -548,11 +548,11 @@ const g = {
|
|
|
548
548
|
</package>
|
|
549
549
|
`;
|
|
550
550
|
return {
|
|
551
|
-
filename: "
|
|
551
|
+
filename: "content.txt",
|
|
552
552
|
files: [
|
|
553
553
|
{
|
|
554
554
|
dir: !1,
|
|
555
|
-
basename:
|
|
555
|
+
basename: $("generated.opf"),
|
|
556
556
|
uri: "generated.opf",
|
|
557
557
|
blob: async () => new Blob([r]),
|
|
558
558
|
string: async () => r,
|
|
@@ -561,11 +561,11 @@ const g = {
|
|
|
561
561
|
},
|
|
562
562
|
{
|
|
563
563
|
dir: !1,
|
|
564
|
-
basename:
|
|
565
|
-
uri: "
|
|
564
|
+
basename: $("p01.txt"),
|
|
565
|
+
uri: "p01.txt",
|
|
566
566
|
blob: async () => typeof e == "string" ? new Blob([e]) : e,
|
|
567
567
|
string: async () => typeof e == "string" ? e : e.text(),
|
|
568
|
-
base64: async () => typeof e == "string" ? btoa(e) :
|
|
568
|
+
base64: async () => typeof e == "string" ? btoa(e) : Ue(e),
|
|
569
569
|
size: typeof e == "string" ? e.length : e.size,
|
|
570
570
|
encodingFormat: n
|
|
571
571
|
}
|
|
@@ -579,7 +579,7 @@ const g = {
|
|
|
579
579
|
filename: s || "",
|
|
580
580
|
files: r.map((a) => ({
|
|
581
581
|
dir: a.dir,
|
|
582
|
-
basename:
|
|
582
|
+
basename: $(a.name),
|
|
583
583
|
uri: a.name,
|
|
584
584
|
blob: () => a.async("blob"),
|
|
585
585
|
string: () => a.async("string"),
|
|
@@ -616,7 +616,7 @@ const g = {
|
|
|
616
616
|
filename: s || "",
|
|
617
617
|
files: r.map((t) => ({
|
|
618
618
|
dir: t.isDir,
|
|
619
|
-
basename:
|
|
619
|
+
basename: $(t.name),
|
|
620
620
|
uri: t.name,
|
|
621
621
|
blob: async () => new Blob([await t.data()]),
|
|
622
622
|
string: async () => {
|
|
@@ -635,14 +635,14 @@ const g = {
|
|
|
635
635
|
enableReport: e
|
|
636
636
|
} = {}) => {
|
|
637
637
|
g.enable(!!e);
|
|
638
|
-
},
|
|
638
|
+
}, Xe = ({
|
|
639
639
|
getArchive: e,
|
|
640
|
-
|
|
640
|
+
cleanArchiveAfter: n
|
|
641
641
|
}) => {
|
|
642
|
-
const s = new
|
|
643
|
-
|
|
642
|
+
const s = new V(), r = new V(), t = {}, a = s.pipe(
|
|
643
|
+
L((c) => {
|
|
644
644
|
const l = t[c];
|
|
645
|
-
return !l || l.getValue().status !== "idle" ?
|
|
645
|
+
return !l || l.getValue().status !== "idle" ? de : (l.next({
|
|
646
646
|
...l.getValue(),
|
|
647
647
|
status: "loading"
|
|
648
648
|
}), A(e(c)).pipe(
|
|
@@ -660,19 +660,26 @@ const g = {
|
|
|
660
660
|
})
|
|
661
661
|
));
|
|
662
662
|
}),
|
|
663
|
-
F((c) => (console.error(c),
|
|
664
|
-
|
|
663
|
+
F((c) => (console.error(c), U)),
|
|
664
|
+
le()
|
|
665
665
|
), i = a.pipe(
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
666
|
+
X(({ archiveEntry: c, key: l }) => c.pipe(v(({ locks: f }) => f)).pipe(v((f) => f <= 0)).pipe(
|
|
667
|
+
X(
|
|
668
|
+
(f) => f ? me(n) : U
|
|
669
|
+
),
|
|
670
|
+
B(() => {
|
|
669
671
|
var f;
|
|
670
672
|
delete t[l], (f = c.getValue().archive) == null || f.close();
|
|
671
673
|
})
|
|
672
674
|
))
|
|
673
675
|
), o = (c) => {
|
|
674
676
|
let l = !1;
|
|
675
|
-
const d = t[c] ?? new
|
|
677
|
+
const d = t[c] ?? new fe({
|
|
678
|
+
archive: void 0,
|
|
679
|
+
status: "idle",
|
|
680
|
+
locks: 0,
|
|
681
|
+
error: void 0
|
|
682
|
+
});
|
|
676
683
|
t[c] = d, d.next({
|
|
677
684
|
...d.getValue(),
|
|
678
685
|
locks: d.getValue().locks + 1
|
|
@@ -686,34 +693,34 @@ const g = {
|
|
|
686
693
|
s.next(c);
|
|
687
694
|
const f = d.pipe(
|
|
688
695
|
v(({ archive: h }) => h),
|
|
689
|
-
|
|
696
|
+
ue((h) => !!h)
|
|
690
697
|
), w = d.pipe(
|
|
691
|
-
|
|
698
|
+
B(({ error: h }) => {
|
|
692
699
|
if (h)
|
|
693
700
|
throw h;
|
|
694
701
|
}),
|
|
695
|
-
|
|
702
|
+
he()
|
|
696
703
|
);
|
|
697
704
|
return _(f, w).pipe(
|
|
698
|
-
|
|
705
|
+
ge(),
|
|
699
706
|
v((h) => ({ archive: h, release: u })),
|
|
700
707
|
F((h) => {
|
|
701
708
|
throw u(), h;
|
|
702
709
|
})
|
|
703
710
|
);
|
|
704
711
|
};
|
|
705
|
-
return _(i, a).pipe(
|
|
712
|
+
return _(i, a).pipe(pe(r)).subscribe(), {
|
|
706
713
|
access: o
|
|
707
714
|
};
|
|
708
715
|
};
|
|
709
716
|
class Be {
|
|
710
717
|
constructor(n) {
|
|
711
|
-
this.epubLoader =
|
|
718
|
+
this.epubLoader = Xe(n);
|
|
712
719
|
}
|
|
713
720
|
fetchManifest({ key: n, baseUrl: s }) {
|
|
714
721
|
const r = this.epubLoader.access(n).pipe(
|
|
715
|
-
|
|
716
|
-
|
|
722
|
+
L(({ archive: t, release: a }) => A(
|
|
723
|
+
Ve(t, { baseUrl: s })
|
|
717
724
|
).pipe(
|
|
718
725
|
v(
|
|
719
726
|
(o) => new Response(JSON.stringify(o), {
|
|
@@ -733,8 +740,8 @@ class Be {
|
|
|
733
740
|
resourcePath: s
|
|
734
741
|
}) {
|
|
735
742
|
const r = this.epubLoader.access(n).pipe(
|
|
736
|
-
|
|
737
|
-
|
|
743
|
+
L(({ archive: t, release: a }) => A(
|
|
744
|
+
Ie(t, s)
|
|
738
745
|
).pipe(
|
|
739
746
|
v((o) => new Response(o.body, { status: 200 })),
|
|
740
747
|
H(() => {
|
|
@@ -746,31 +753,25 @@ class Be {
|
|
|
746
753
|
return J(r);
|
|
747
754
|
}
|
|
748
755
|
}
|
|
749
|
-
const Xe = (e) => e.indexOf("/") !== -1 ? e.substring(0, e.indexOf("/")) : e;
|
|
750
756
|
class tt extends Be {
|
|
751
757
|
constructor({
|
|
752
|
-
|
|
758
|
+
getUriInfo: n,
|
|
753
759
|
...s
|
|
754
760
|
}) {
|
|
755
|
-
super(s), this.
|
|
761
|
+
super(s), this.getUriInfo = n, this.fetchEventListener = this.fetchEventListener.bind(this);
|
|
756
762
|
}
|
|
757
763
|
fetchEventListener(n) {
|
|
758
764
|
try {
|
|
759
|
-
const s =
|
|
760
|
-
if (!
|
|
761
|
-
const
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
a.length + 1,
|
|
770
|
-
r.length
|
|
771
|
-
);
|
|
772
|
-
n.respondWith(this.fetchResource({ key: a, resourcePath: c }));
|
|
773
|
-
}
|
|
765
|
+
const s = this.getUriInfo(n);
|
|
766
|
+
if (!s) return;
|
|
767
|
+
const r = q(s.baseUrl), t = n.request.url.substring(
|
|
768
|
+
r.length + 1
|
|
769
|
+
), [a = ""] = t.split("/"), i = q(
|
|
770
|
+
t.substring(a.length + 1)
|
|
771
|
+
);
|
|
772
|
+
t.endsWith("/manifest") ? n.respondWith(
|
|
773
|
+
this.fetchManifest({ key: a, baseUrl: `${r}/${a}/` })
|
|
774
|
+
) : n.respondWith(this.fetchResource({ key: a, resourcePath: i }));
|
|
774
775
|
} catch (s) {
|
|
775
776
|
n.respondWith(new Response(String(s), { status: 500 }));
|
|
776
777
|
}
|
|
@@ -785,9 +786,9 @@ export {
|
|
|
785
786
|
Qe as createArchiveFromLibArchive,
|
|
786
787
|
Ke as createArchiveFromText,
|
|
787
788
|
Ye as createArchiveFromUrls,
|
|
788
|
-
|
|
789
|
-
|
|
789
|
+
Ve as generateManifestFromArchive,
|
|
790
|
+
Ie as generateResourceFromArchive,
|
|
790
791
|
qe as generateResourceFromError,
|
|
791
|
-
|
|
792
|
+
T as getArchiveOpfInfo
|
|
792
793
|
};
|
|
793
794
|
//# sourceMappingURL=index.js.map
|