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