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