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