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