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