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