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