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