@prose-reader/streamer 1.95.0 → 1.96.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 +199 -195
- 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 I, mergeMap as k, EMPTY as le, from as A, map as v, catchError as T, NEVER as
|
|
3
|
+
import { Subject as I, mergeMap as k, EMPTY as le, from as A, map as v, catchError as T, NEVER as B, shareReplay as _, switchMap as C, startWith as me, distinctUntilChanged as pe, withLatestFrom as fe, timer as ue, of as P, tap as E, merge as H, 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) => {
|
|
@@ -35,133 +35,133 @@ const y = {
|
|
|
35
35
|
));
|
|
36
36
|
},
|
|
37
37
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
-
measurePerformance: (e, n = 10, a) => (...
|
|
39
|
-
const t = performance.now(),
|
|
40
|
-
if (
|
|
41
|
-
return
|
|
38
|
+
measurePerformance: (e, n = 10, a) => (...s) => {
|
|
39
|
+
const t = performance.now(), r = a(...s);
|
|
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
49
|
var a;
|
|
50
|
-
const n = (a = e.descendantWithPath("head")) == null ? void 0 : a.childrenNamed("meta").find((
|
|
50
|
+
const n = (a = e.descendantWithPath("head")) == null ? void 0 : a.childrenNamed("meta").find((s) => s.attr.name === "calibre:cover");
|
|
51
51
|
return !!(n && n.attr.name === "calibre:cover");
|
|
52
52
|
}, $e = (e) => {
|
|
53
|
-
var n, a,
|
|
54
|
-
return (
|
|
53
|
+
var n, a, s;
|
|
54
|
+
return (s = (a = (n = e.descendantWithPath("body")) == null ? void 0 : n.descendantWithPath("div")) == null ? void 0 : a.childrenNamed("svg")) == null ? void 0 : s.find(
|
|
55
55
|
(t) => t.attr.width === "100%" && t.attr.preserveAspectRatio === "none"
|
|
56
56
|
);
|
|
57
57
|
}, xe = ({ archive: e, resourcePath: n }) => async (a) => {
|
|
58
|
-
const
|
|
58
|
+
const s = Object.values(e.files).find(
|
|
59
59
|
(t) => t.uri === n
|
|
60
60
|
);
|
|
61
|
-
if (
|
|
62
|
-
const t = a.body ?? await
|
|
63
|
-
if (ve(
|
|
64
|
-
const i = $e(
|
|
61
|
+
if (s != null && s.basename.endsWith(".xhtml")) {
|
|
62
|
+
const t = a.body ?? await s.string(), r = new de(t);
|
|
63
|
+
if (ve(r)) {
|
|
64
|
+
const i = $e(r);
|
|
65
65
|
return i && delete i.attr.preserveAspectRatio, {
|
|
66
66
|
...a,
|
|
67
|
-
body:
|
|
67
|
+
body: r == null ? void 0 : r.toString()
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
return a;
|
|
72
72
|
}, Fe = ({ archive: e, resourcePath: n }) => async (a) => xe({ archive: e, resourcePath: n })(a), Ne = ({ archive: e, resourcePath: n }) => async (a) => {
|
|
73
|
-
const
|
|
73
|
+
const s = Object.values(e.files).find(
|
|
74
74
|
(t) => t.uri === n
|
|
75
75
|
);
|
|
76
|
-
if (
|
|
77
|
-
const
|
|
76
|
+
if (s != null && s.basename.endsWith(".css")) {
|
|
77
|
+
const r = (a.body ?? await s.string()).replaceAll(
|
|
78
78
|
"-webkit-writing-mode",
|
|
79
79
|
"writing-mode"
|
|
80
80
|
);
|
|
81
81
|
return {
|
|
82
82
|
...a,
|
|
83
|
-
body:
|
|
83
|
+
body: r
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
return a;
|
|
87
87
|
}, L = (e) => {
|
|
88
|
-
const a = Object.values(e.files).filter((
|
|
88
|
+
const a = Object.values(e.files).filter((s) => !s.dir).find((s) => s.uri.endsWith(".opf"));
|
|
89
89
|
return {
|
|
90
90
|
data: a,
|
|
91
91
|
basePath: (a == null ? void 0 : a.uri.substring(0, a.uri.lastIndexOf("/"))) || ""
|
|
92
92
|
};
|
|
93
93
|
}, K = (e, { opfBasePath: n, baseUrl: a }) => {
|
|
94
|
-
const
|
|
94
|
+
const s = {
|
|
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
|
+
s.title = (t == null ? void 0 : t.attr.title) || (t == null ? void 0 : t.val.trim()) || s.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) && (s.path = S(n, t.attr.href), s.href = S(a, 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 && (
|
|
107
|
+
o && o.length > 0 && (s.contents = o.map(
|
|
108
108
|
(m) => K(m, { opfBasePath: n, baseUrl: a })
|
|
109
109
|
));
|
|
110
110
|
}
|
|
111
|
-
return
|
|
111
|
+
return s;
|
|
112
112
|
}, Te = (e, { opfBasePath: n, baseUrl: a }) => {
|
|
113
|
-
var
|
|
114
|
-
const
|
|
113
|
+
var r, i;
|
|
114
|
+
const s = [];
|
|
115
115
|
let t;
|
|
116
|
-
return e.descendantWithPath("body.nav.ol") ? t = (
|
|
117
|
-
(o) =>
|
|
118
|
-
),
|
|
119
|
-
}, Se = async (e, n, { opfBasePath: a, baseUrl:
|
|
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) => s.push(K(o, { opfBasePath: n, baseUrl: a }))
|
|
118
|
+
), s;
|
|
119
|
+
}, Se = async (e, n, { opfBasePath: a, baseUrl: s }) => {
|
|
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 Te(o, { opfBasePath: a, baseUrl:
|
|
128
|
+
return Te(o, { opfBasePath: a, baseUrl: s });
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
}, Y = (e, {
|
|
132
132
|
opfBasePath: n,
|
|
133
133
|
baseUrl: a,
|
|
134
|
-
prefix:
|
|
134
|
+
prefix: s
|
|
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(`${s}content`)) == null ? void 0 : o.attr.src) || "", r = {
|
|
138
|
+
title: ((m = e == null ? void 0 : e.descendantWithPath(`${s}navLabel.${s}text`)) == null ? void 0 : m.val) || "",
|
|
139
139
|
path: S(n, t),
|
|
140
140
|
href: S(a, n, t),
|
|
141
141
|
contents: []
|
|
142
|
-
}, i = e.childrenNamed(`${
|
|
143
|
-
return i && i.length > 0 && (
|
|
144
|
-
(u) => Y(u, { opfBasePath: n, baseUrl: a, prefix:
|
|
145
|
-
)),
|
|
142
|
+
}, i = e.childrenNamed(`${s}navPoint`);
|
|
143
|
+
return i && i.length > 0 && (r.contents = i.map(
|
|
144
|
+
(u) => Y(u, { opfBasePath: n, baseUrl: a, prefix: s })
|
|
145
|
+
)), r;
|
|
146
146
|
}, Ae = (e, { opfBasePath: n, baseUrl: a }) => {
|
|
147
147
|
var i;
|
|
148
|
-
const
|
|
149
|
-
let
|
|
150
|
-
return t.indexOf(":") !== -1 && (
|
|
151
|
-
(o) =>
|
|
152
|
-
),
|
|
148
|
+
const s = [], 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) => s.push(Y(o, { opfBasePath: n, baseUrl: a, prefix: r }))
|
|
152
|
+
), s;
|
|
153
153
|
}, Le = async ({
|
|
154
154
|
opfData: e,
|
|
155
155
|
opfBasePath: n,
|
|
156
156
|
baseUrl: a,
|
|
157
|
-
archive:
|
|
157
|
+
archive: s
|
|
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}`, u = Object.values(
|
|
164
|
+
const m = `${n}${n === "" ? "" : "/"}${o.attr.href}`, u = Object.values(s.files).find(
|
|
165
165
|
(c) => c.uri.endsWith(m)
|
|
166
166
|
);
|
|
167
167
|
if (u) {
|
|
@@ -171,22 +171,22 @@ const y = {
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
}, Re = async (e, n, { baseUrl: a }) => {
|
|
174
|
-
const { basePath:
|
|
174
|
+
const { basePath: s } = L(n) || {}, t = await Le({
|
|
175
175
|
opfData: e,
|
|
176
|
-
opfBasePath:
|
|
176
|
+
opfBasePath: s,
|
|
177
177
|
archive: n,
|
|
178
178
|
baseUrl: a
|
|
179
179
|
});
|
|
180
|
-
return t || await Se(e, n, { opfBasePath:
|
|
180
|
+
return t || await Se(e, n, { opfBasePath: s, baseUrl: a });
|
|
181
181
|
}, We = 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 (a) => {
|
|
187
|
-
var
|
|
187
|
+
var s, t;
|
|
188
188
|
if (a.uri.endsWith("com.kobobooks.display-options.xml")) {
|
|
189
|
-
const i = (
|
|
189
|
+
const i = (s = new $.XmlDocument(await a.string()).childNamed("platform")) == null ? void 0 : s.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,32 +194,32 @@ const y = {
|
|
|
194
194
|
}, Q = async ({
|
|
195
195
|
archive: e
|
|
196
196
|
}) => {
|
|
197
|
-
const { data: n, basePath: a } = L(e) || {},
|
|
198
|
-
if (!
|
|
199
|
-
const t = new $.XmlDocument(
|
|
197
|
+
const { data: n, basePath: a } = L(e) || {}, s = await (n == null ? void 0 : n.string());
|
|
198
|
+
if (!s) return [];
|
|
199
|
+
const t = new $.XmlDocument(s), 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
200
|
return e.files.filter((c) => m.find((d) => a ? `${a}/${d.attr.href}` === c.uri : `${d.attr.href}` === c.uri));
|
|
201
201
|
}, Z = (e) => {
|
|
202
202
|
var a;
|
|
203
203
|
const n = e.childNamed("manifest");
|
|
204
|
-
return ((a = n == null ? void 0 : n.childrenNamed("item")) == null ? void 0 : a.map((
|
|
205
|
-
href:
|
|
206
|
-
id:
|
|
207
|
-
mediaType:
|
|
204
|
+
return ((a = n == null ? void 0 : n.childrenNamed("item")) == null ? void 0 : a.map((s) => ({
|
|
205
|
+
href: s.attr.href || "",
|
|
206
|
+
id: s.attr.id || "",
|
|
207
|
+
mediaType: s.attr["media-type"]
|
|
208
208
|
}))) || [];
|
|
209
209
|
}, Ie = ({ archive: e, baseUrl: n }) => async (a) => {
|
|
210
|
-
var
|
|
211
|
-
const { data:
|
|
212
|
-
if (!
|
|
210
|
+
var j;
|
|
211
|
+
const { data: s, basePath: t } = L(e) || {}, r = await We(e);
|
|
212
|
+
if (!s)
|
|
213
213
|
return a;
|
|
214
|
-
const i = await
|
|
215
|
-
y.log(i,
|
|
214
|
+
const i = await s.string();
|
|
215
|
+
y.log(i, r);
|
|
216
216
|
const o = new $.XmlDocument(i), m = await Re(o, e, { baseUrl: n }) || [], u = o.childNamed("metadata"), c = o.childNamed("manifest"), d = o.childNamed("spine"), p = o.childNamed("guide"), b = u == null ? void 0 : u.childNamed("dc:title"), F = (u == null ? void 0 : u.childrenNamed("meta")) || [], g = F.find(
|
|
217
217
|
(f) => f.attr.property === "rendition:layout"
|
|
218
218
|
), h = F.find(
|
|
219
219
|
(f) => f.attr.property === "rendition:flow"
|
|
220
220
|
), R = F.find(
|
|
221
221
|
(f) => f.attr.property === "rendition:spread"
|
|
222
|
-
),
|
|
222
|
+
), O = g == null ? void 0 : g.val, ee = h == null ? void 0 : h.val, te = R == null ? void 0 : R.val, ne = (b == null ? void 0 : b.val) || ((j = e.files.find(({ dir: f }) => f)) == null ? void 0 : j.basename) || "", re = d == null ? void 0 : d.attr["page-progression-direction"], se = (await Q({ archive: e })).reduce(
|
|
223
223
|
(f, l) => l.size + f,
|
|
224
224
|
0
|
|
225
225
|
);
|
|
@@ -228,18 +228,18 @@ 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
236
|
spineItems: (d == null ? void 0 : d.childrenNamed("itemref").map((f) => {
|
|
237
|
-
var
|
|
238
|
-
const l = c == null ? void 0 : c.childrenNamed("item").find((w) => w.attr.id === (f == null ? void 0 : f.attr.idref)), ae = (l == null ? void 0 : l.attr.href) || "", W = ((
|
|
237
|
+
var z, U, V;
|
|
238
|
+
const l = c == null ? void 0 : c.childrenNamed("item").find((w) => w.attr.id === (f == null ? void 0 : f.attr.idref)), ae = (l == null ? void 0 : l.attr.href) || "", W = ((z = f == null ? void 0 : f.attr.properties) == null ? void 0 : z.split(" ")) || [], ie = ((U = e.files.find((w) => w.uri.endsWith(ae))) == 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:
|
|
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
243
|
...W.find(
|
|
244
244
|
(w) => w === "rendition:layout-reflowable"
|
|
245
245
|
) && {
|
|
@@ -260,12 +260,12 @@ const y = {
|
|
|
260
260
|
}))
|
|
261
261
|
};
|
|
262
262
|
}, ke = async (e, n) => {
|
|
263
|
-
var t,
|
|
264
|
-
const
|
|
265
|
-
if (
|
|
266
|
-
const i = new $.XmlDocument(
|
|
263
|
+
var t, r;
|
|
264
|
+
const s = await ((t = L(e).data) == null ? void 0 : t.string());
|
|
265
|
+
if (s) {
|
|
266
|
+
const i = new $.XmlDocument(s);
|
|
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 {
|
|
@@ -283,10 +283,10 @@ const y = {
|
|
|
283
283
|
if (e.endsWith(".svg"))
|
|
284
284
|
return "image/svg+xml";
|
|
285
285
|
}, Pe = ({ archive: e, resourcePath: n }) => async (a) => {
|
|
286
|
-
const
|
|
287
|
-
(
|
|
286
|
+
const s = Object.values(e.files).find(
|
|
287
|
+
(r) => r.uri === n
|
|
288
288
|
);
|
|
289
|
-
if (!
|
|
289
|
+
if (!s) return a;
|
|
290
290
|
const t = await ke(e, n);
|
|
291
291
|
return {
|
|
292
292
|
...a,
|
|
@@ -294,8 +294,8 @@ const y = {
|
|
|
294
294
|
...a.params,
|
|
295
295
|
status: 200,
|
|
296
296
|
headers: {
|
|
297
|
-
...(
|
|
298
|
-
"Content-Type":
|
|
297
|
+
...(s == null ? void 0 : s.encodingFormat) && {
|
|
298
|
+
"Content-Type": s.encodingFormat
|
|
299
299
|
},
|
|
300
300
|
...t.mediaType && {
|
|
301
301
|
"Content-Type": t.mediaType
|
|
@@ -305,11 +305,11 @@ const y = {
|
|
|
305
305
|
};
|
|
306
306
|
}, De = async (e, n) => {
|
|
307
307
|
const a = Object.values(e.files).find(
|
|
308
|
-
(
|
|
308
|
+
(r) => r.uri === n
|
|
309
309
|
);
|
|
310
310
|
if (!a)
|
|
311
311
|
throw new Error("no file found");
|
|
312
|
-
const
|
|
312
|
+
const s = {
|
|
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(s));
|
|
323
|
+
return y.log("Generated resource", n, r), {
|
|
324
|
+
...r,
|
|
325
|
+
body: r.body || await a.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,19 +346,19 @@ const y = {
|
|
|
346
346
|
}
|
|
347
347
|
}
|
|
348
348
|
}), Oe = ({ archive: e, baseUrl: n }) => async () => {
|
|
349
|
-
var
|
|
349
|
+
var s;
|
|
350
350
|
const a = Object.values(e.files).filter((t) => !t.dir);
|
|
351
351
|
return {
|
|
352
352
|
filename: e.filename,
|
|
353
|
-
title: ((
|
|
353
|
+
title: ((s = e.files.find(({ dir: t }) => t)) == null ? void 0 : s.basename.replace(/\/$/, "")) || "",
|
|
354
354
|
renditionLayout: "pre-paginated",
|
|
355
355
|
renditionSpread: "auto",
|
|
356
356
|
readingDirection: "ltr",
|
|
357
|
-
spineItems: a.filter((t) => !t.basename.endsWith(".db")).map((t,
|
|
357
|
+
spineItems: a.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
364
|
progressionWeight: 1 / a.length,
|
|
@@ -366,19 +366,19 @@ const y = {
|
|
|
366
366
|
pageSpreadRight: void 0,
|
|
367
367
|
mediaType: t.encodingFormat
|
|
368
368
|
})),
|
|
369
|
-
items: a.map((t,
|
|
370
|
-
id: `${
|
|
369
|
+
items: a.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
|
|
375
|
+
var r;
|
|
376
376
|
const a = e.files.find(
|
|
377
377
|
(i) => i.basename.toLowerCase() === "comicinfo.xml"
|
|
378
378
|
);
|
|
379
379
|
if (!a)
|
|
380
380
|
return n;
|
|
381
|
-
const
|
|
381
|
+
const s = {
|
|
382
382
|
...n,
|
|
383
383
|
spineItems: n.spineItems.filter((i) => !i.id.toLowerCase().endsWith("comicinfo.xml")).map((i, o, m) => ({
|
|
384
384
|
...i,
|
|
@@ -386,18 +386,18 @@ const y = {
|
|
|
386
386
|
}))
|
|
387
387
|
}, t = await a.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
|
+
...s,
|
|
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), s;
|
|
397
397
|
}
|
|
398
398
|
}, Me = (e) => {
|
|
399
399
|
var a;
|
|
400
|
-
const n = (a = e.descendantWithPath("head")) == null ? void 0 : a.childrenNamed("meta").find((
|
|
400
|
+
const n = (a = e.descendantWithPath("head")) == null ? void 0 : a.childrenNamed("meta").find((s) => s.attr.name === "viewport");
|
|
401
401
|
return !!(n && n.attr.name === "viewport");
|
|
402
402
|
}, ze = (e) => e.reduce(async (n, a) => {
|
|
403
403
|
if (!await n || !ce({
|
|
@@ -408,44 +408,44 @@ const y = {
|
|
|
408
408
|
const t = await a.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((s) => s.renditionLayout === "reflowable")) {
|
|
412
|
+
const s = await Q({ archive: e });
|
|
413
|
+
if (await ze(s))
|
|
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 a = e.split(/(\d+)/),
|
|
427
|
-
for (let
|
|
428
|
-
if (a[
|
|
429
|
-
return (t = a[
|
|
426
|
+
const a = e.split(/(\d+)/), s = n.split(/(\d+)/);
|
|
427
|
+
for (let r = 0, i = a.length; r < i; r++)
|
|
428
|
+
if (a[r] !== s[r])
|
|
429
|
+
return (t = a[r]) != null && t.match(/\d/) ? +(a[r] || "") - +(s[r] || "") : (a[r] || "").localeCompare(s[r] || "");
|
|
430
430
|
return 1;
|
|
431
431
|
}, Ve = ({ archive: e, baseUrl: n }) => async (a) => {
|
|
432
432
|
if (a.nav) return a;
|
|
433
|
-
const
|
|
434
|
-
(
|
|
433
|
+
const s = [...e.files].sort(
|
|
434
|
+
(r, i) => D(r.uri, i.uri)
|
|
435
435
|
), t = Object.values(
|
|
436
|
-
|
|
436
|
+
s
|
|
437
437
|
).reduce(
|
|
438
|
-
(
|
|
438
|
+
(r, i) => {
|
|
439
439
|
const o = i.uri.split("/");
|
|
440
440
|
return !i.dir && o.length > 1 && o.forEach((u, c) => {
|
|
441
441
|
if (c === o.length - 1) return;
|
|
442
|
-
|
|
442
|
+
r.find(({ title: b }) => b === u) || 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
|
);
|
|
@@ -475,10 +475,10 @@ const y = {
|
|
|
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 s = await a.reduce(async (t, r) => await r(await t), Promise.resolve(Xe));
|
|
479
|
+
return y.log("Generated manifest", s), s;
|
|
480
|
+
} catch (s) {
|
|
481
|
+
throw y.error(s), s;
|
|
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
484
|
const a = `
|
|
@@ -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
|
+
`, s = 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(),
|
|
@@ -518,20 +518,20 @@ const y = {
|
|
|
518
518
|
base64: async () => a,
|
|
519
519
|
blob: async () => new Blob(),
|
|
520
520
|
string: async () => a
|
|
521
|
-
}, ...
|
|
521
|
+
}, ...s],
|
|
522
522
|
close: () => Promise.resolve()
|
|
523
523
|
};
|
|
524
524
|
}, _e = async (e) => new Promise((n) => {
|
|
525
525
|
const a = new FileReader();
|
|
526
526
|
a.readAsDataURL(e), a.onloadend = function() {
|
|
527
|
-
const
|
|
528
|
-
n(
|
|
527
|
+
const s = a.result;
|
|
528
|
+
n(s);
|
|
529
529
|
};
|
|
530
530
|
}), Ze = async (e, {
|
|
531
531
|
mimeType: n,
|
|
532
532
|
direction: a
|
|
533
533
|
} = { mimeType: "text/plain" }) => {
|
|
534
|
-
const
|
|
534
|
+
const s = `
|
|
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">
|
|
@@ -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([s]),
|
|
558
|
+
string: async () => s,
|
|
559
|
+
base64: async () => btoa(s),
|
|
560
560
|
size: 0
|
|
561
561
|
},
|
|
562
562
|
{
|
|
@@ -573,30 +573,30 @@ const y = {
|
|
|
573
573
|
close: () => Promise.resolve()
|
|
574
574
|
};
|
|
575
575
|
}, et = async (e, { orderByAlpha: n, name: a } = {}) => {
|
|
576
|
-
let
|
|
577
|
-
n && (
|
|
576
|
+
let s = Object.values(e.files);
|
|
577
|
+
n && (s = s.slice().sort((r, i) => D(r.name, i.name)));
|
|
578
578
|
const t = {
|
|
579
579
|
filename: a || "",
|
|
580
|
-
files:
|
|
581
|
-
dir:
|
|
582
|
-
basename: x(
|
|
583
|
-
uri:
|
|
584
|
-
blob: () =>
|
|
585
|
-
string: () =>
|
|
586
|
-
base64: () =>
|
|
587
|
-
...
|
|
588
|
-
stream:
|
|
580
|
+
files: s.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 a = await e.getFilesArray(),
|
|
599
|
+
const a = await e.getFilesArray(), s = {
|
|
600
600
|
close: () => e.close(),
|
|
601
601
|
filename: n ?? "",
|
|
602
602
|
files: a.map((t) => ({
|
|
@@ -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",
|
|
612
|
+
return y.log("Generated archive", s), s;
|
|
613
613
|
}, nt = async (e, { orderByAlpha: n, name: a } = {}) => {
|
|
614
|
-
let
|
|
615
|
-
return n && (
|
|
614
|
+
let s = e;
|
|
615
|
+
return n && (s = s.slice().sort((t, r) => D(t.name, r.name))), {
|
|
616
616
|
filename: a || "",
|
|
617
|
-
files:
|
|
617
|
+
files: s.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 () => "",
|
|
@@ -635,13 +635,13 @@ const y = {
|
|
|
635
635
|
enableReport: e
|
|
636
636
|
} = {}) => {
|
|
637
637
|
y.enable(!!e);
|
|
638
|
-
},
|
|
638
|
+
}, Ee = ({
|
|
639
639
|
getArchive: e,
|
|
640
640
|
cleanArchiveAfter: n
|
|
641
641
|
}) => {
|
|
642
|
-
const a = new I(),
|
|
642
|
+
const a = new I(), s = new I(), t = new I(), r = {}, i = a.pipe(
|
|
643
643
|
k((c) => {
|
|
644
|
-
const d =
|
|
644
|
+
const d = r[c];
|
|
645
645
|
return !d || d.getValue().status !== "idle" ? le : (d.next({
|
|
646
646
|
...d.getValue(),
|
|
647
647
|
status: "loading"
|
|
@@ -660,14 +660,14 @@ const y = {
|
|
|
660
660
|
})
|
|
661
661
|
));
|
|
662
662
|
}),
|
|
663
|
-
T(() =>
|
|
664
|
-
|
|
663
|
+
T(() => B),
|
|
664
|
+
_()
|
|
665
665
|
), o = i.pipe(
|
|
666
666
|
C(({ archiveEntry: c, key: d }) => {
|
|
667
667
|
const p = c.pipe(v(({ locks: g }) => g)), b = t.pipe(
|
|
668
668
|
v(() => !0),
|
|
669
669
|
me(!1),
|
|
670
|
-
|
|
670
|
+
_()
|
|
671
671
|
);
|
|
672
672
|
return p.pipe(
|
|
673
673
|
v((g) => g <= 0),
|
|
@@ -675,23 +675,23 @@ const y = {
|
|
|
675
675
|
).pipe(
|
|
676
676
|
fe(b),
|
|
677
677
|
C(
|
|
678
|
-
([g, h]) => g ?
|
|
678
|
+
([g, h]) => g ? h ? P(null) : ue(n) : B
|
|
679
679
|
),
|
|
680
|
-
|
|
680
|
+
E(() => {
|
|
681
681
|
var g;
|
|
682
|
-
console.log("ARCHIVE DELETED"), delete
|
|
682
|
+
console.log("ARCHIVE DELETED"), delete r[d], (g = c.getValue().archive) == null || g.close();
|
|
683
683
|
})
|
|
684
684
|
);
|
|
685
685
|
})
|
|
686
686
|
), m = (c) => {
|
|
687
687
|
let d = !1;
|
|
688
|
-
const p =
|
|
688
|
+
const p = r[c] ?? new ge({
|
|
689
689
|
archive: void 0,
|
|
690
690
|
status: "idle",
|
|
691
691
|
locks: 0,
|
|
692
692
|
error: void 0
|
|
693
693
|
});
|
|
694
|
-
|
|
694
|
+
r[c] = p, p.next({
|
|
695
695
|
...p.getValue(),
|
|
696
696
|
locks: p.getValue().locks + 1
|
|
697
697
|
});
|
|
@@ -706,7 +706,7 @@ const y = {
|
|
|
706
706
|
v(({ archive: h }) => h),
|
|
707
707
|
be((h) => !!h)
|
|
708
708
|
), g = p.pipe(
|
|
709
|
-
|
|
709
|
+
E(({ error: h }) => {
|
|
710
710
|
if (h)
|
|
711
711
|
throw h;
|
|
712
712
|
}),
|
|
@@ -719,26 +719,30 @@ const y = {
|
|
|
719
719
|
throw b(), h;
|
|
720
720
|
})
|
|
721
721
|
);
|
|
722
|
-
}, u = () =>
|
|
723
|
-
|
|
722
|
+
}, u = () => {
|
|
723
|
+
Object.keys(r).forEach((c) => {
|
|
724
|
+
delete r[c];
|
|
725
|
+
}), t.next();
|
|
726
|
+
};
|
|
727
|
+
return H(o, i).pipe(he(s)).subscribe(), {
|
|
724
728
|
access: m,
|
|
725
729
|
purge: u
|
|
726
730
|
};
|
|
727
731
|
};
|
|
728
|
-
class
|
|
732
|
+
class He {
|
|
729
733
|
constructor({
|
|
730
734
|
onError: n,
|
|
731
735
|
onManifestSuccess: a,
|
|
732
|
-
...
|
|
736
|
+
...s
|
|
733
737
|
}) {
|
|
734
|
-
this.onError = (t) => new Response(String(t), { status: 500 }), this.epubLoader =
|
|
738
|
+
this.onError = (t) => new Response(String(t), { status: 500 }), this.epubLoader = Ee(s), this.onManifestSuccess = a ?? (({ manifest: t }) => Promise.resolve(t)), this.onError = n ?? this.onError;
|
|
735
739
|
}
|
|
736
740
|
accessArchive(n) {
|
|
737
741
|
return this.lastAccessedKey !== n && this.epubLoader.purge(), this.lastAccessedKey = n, this.epubLoader.access(n);
|
|
738
742
|
}
|
|
739
743
|
fetchManifest({ key: n, baseUrl: a }) {
|
|
740
|
-
const
|
|
741
|
-
k(({ archive: t, release:
|
|
744
|
+
const s = this.accessArchive(n).pipe(
|
|
745
|
+
k(({ archive: t, release: r }) => A(
|
|
742
746
|
Be(t, { baseUrl: a })
|
|
743
747
|
).pipe(
|
|
744
748
|
C(
|
|
@@ -749,33 +753,33 @@ class Ee {
|
|
|
749
753
|
status: 200
|
|
750
754
|
})
|
|
751
755
|
),
|
|
752
|
-
|
|
753
|
-
|
|
756
|
+
G(() => {
|
|
757
|
+
r();
|
|
754
758
|
})
|
|
755
759
|
)),
|
|
756
|
-
T((t) =>
|
|
760
|
+
T((t) => P(this.onError(t)))
|
|
757
761
|
);
|
|
758
|
-
return J(
|
|
762
|
+
return J(s);
|
|
759
763
|
}
|
|
760
764
|
fetchResource({
|
|
761
765
|
key: n,
|
|
762
766
|
resourcePath: a
|
|
763
767
|
}) {
|
|
764
|
-
const
|
|
765
|
-
k(({ archive: t, release:
|
|
768
|
+
const s = this.accessArchive(n).pipe(
|
|
769
|
+
k(({ archive: t, release: r }) => A(
|
|
766
770
|
De(t, a)
|
|
767
771
|
).pipe(
|
|
768
772
|
v((o) => new Response(o.body, { status: 200 })),
|
|
769
|
-
|
|
770
|
-
|
|
773
|
+
G(() => {
|
|
774
|
+
r();
|
|
771
775
|
})
|
|
772
776
|
)),
|
|
773
|
-
T((t) =>
|
|
777
|
+
T((t) => P(this.onError(t)))
|
|
774
778
|
);
|
|
775
|
-
return J(
|
|
779
|
+
return J(s);
|
|
776
780
|
}
|
|
777
781
|
}
|
|
778
|
-
class st extends
|
|
782
|
+
class st extends He {
|
|
779
783
|
constructor({
|
|
780
784
|
getUriInfo: n,
|
|
781
785
|
...a
|
|
@@ -786,14 +790,14 @@ class st extends Ee {
|
|
|
786
790
|
try {
|
|
787
791
|
const a = this.getUriInfo(n);
|
|
788
792
|
if (!a) return;
|
|
789
|
-
const
|
|
790
|
-
|
|
791
|
-
), [
|
|
792
|
-
q(t.substring(
|
|
793
|
+
const s = q(a.baseUrl), t = n.request.url.substring(
|
|
794
|
+
s.length + 1
|
|
795
|
+
), [r = ""] = t.split("/"), i = decodeURIComponent(
|
|
796
|
+
q(t.substring(r.length + 1))
|
|
793
797
|
);
|
|
794
798
|
t.endsWith("/manifest") ? n.respondWith(
|
|
795
|
-
this.fetchManifest({ key:
|
|
796
|
-
) : n.respondWith(this.fetchResource({ key:
|
|
799
|
+
this.fetchManifest({ key: r, baseUrl: `${s}/${r}/` })
|
|
800
|
+
) : n.respondWith(this.fetchResource({ key: r, resourcePath: i }));
|
|
797
801
|
} catch (a) {
|
|
798
802
|
n.respondWith(new Response(String(a), { status: 500 }));
|
|
799
803
|
}
|
|
@@ -801,7 +805,7 @@ class st extends Ee {
|
|
|
801
805
|
}
|
|
802
806
|
export {
|
|
803
807
|
st as ServiceWorkerStreamer,
|
|
804
|
-
|
|
808
|
+
He as Streamer,
|
|
805
809
|
rt as configure,
|
|
806
810
|
nt as createArchiveFromArrayBufferList,
|
|
807
811
|
et as createArchiveFromJszip,
|