@prose-reader/streamer 1.124.0 → 1.126.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 +289 -287
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +6 -6
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import F, { XmlDocument as
|
|
2
|
-
import { urlJoin as N, isXmlBasedMimeType as
|
|
3
|
-
import { Subject as
|
|
1
|
+
import F, { XmlDocument as pe, XmlTextNode as fe, XmlElement as ue } from "xmldoc";
|
|
2
|
+
import { urlJoin as N, isXmlBasedMimeType as me, detectMimeTypeFromName as _ } from "@prose-reader/shared";
|
|
3
|
+
import { Subject as j, mergeMap as z, EMPTY as q, pairwise as he, filter as D, startWith as ge, from as L, tap as O, catchError as P, switchMap as k, merge as G, takeUntil as ye, map as A, ignoreElements as be, first as we, BehaviorSubject as ve, distinctUntilChanged as $e, shareReplay as xe, NEVER as K, timer as Fe, finalize as J, of as Y, lastValueFrom as Q } from "rxjs";
|
|
4
4
|
let S = !1;
|
|
5
5
|
const v = {
|
|
6
6
|
enable: (e) => {
|
|
@@ -35,195 +35,195 @@ const v = {
|
|
|
35
35
|
));
|
|
36
36
|
},
|
|
37
37
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
-
measurePerformance: (e, t = 10, i) => (...
|
|
39
|
-
const n = performance.now(),
|
|
40
|
-
if (
|
|
41
|
-
return
|
|
38
|
+
measurePerformance: (e, t = 10, i) => (...s) => {
|
|
39
|
+
const n = performance.now(), r = i(...s);
|
|
40
|
+
if (r && r.then)
|
|
41
|
+
return r.then((o) => {
|
|
42
42
|
const d = performance.now();
|
|
43
43
|
return v.metric({ name: e, duration: d - n }, t), o;
|
|
44
44
|
});
|
|
45
45
|
const a = performance.now();
|
|
46
|
-
return v.metric({ name: e, duration: a - n }, t),
|
|
46
|
+
return v.metric({ name: e, duration: a - n }, t), r;
|
|
47
47
|
}
|
|
48
|
-
},
|
|
48
|
+
}, Ae = (e) => {
|
|
49
49
|
var i;
|
|
50
|
-
const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((
|
|
50
|
+
const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((s) => s.attr.name === "calibre:cover");
|
|
51
51
|
return !!(t && t.attr.name === "calibre:cover");
|
|
52
|
-
},
|
|
53
|
-
var t, i,
|
|
54
|
-
return (
|
|
52
|
+
}, Te = (e) => {
|
|
53
|
+
var t, i, s;
|
|
54
|
+
return (s = (i = (t = e.descendantWithPath("body")) == null ? void 0 : t.descendantWithPath("div")) == null ? void 0 : i.childrenNamed("svg")) == null ? void 0 : s.find(
|
|
55
55
|
(n) => n.attr.width === "100%" && n.attr.preserveAspectRatio === "none"
|
|
56
56
|
);
|
|
57
|
-
},
|
|
58
|
-
const
|
|
57
|
+
}, Se = ({ archive: e, resourcePath: t }) => async (i) => {
|
|
58
|
+
const s = Object.values(e.files).find(
|
|
59
59
|
(n) => n.uri === t
|
|
60
60
|
);
|
|
61
|
-
if (
|
|
62
|
-
const n = i.body ?? await
|
|
63
|
-
if (
|
|
64
|
-
const a =
|
|
61
|
+
if (s != null && s.basename.endsWith(".xhtml")) {
|
|
62
|
+
const n = i.body ?? await s.string(), r = new pe(n);
|
|
63
|
+
if (Ae(r)) {
|
|
64
|
+
const a = Te(r);
|
|
65
65
|
return a && delete a.attr.preserveAspectRatio, {
|
|
66
66
|
...i,
|
|
67
|
-
body:
|
|
67
|
+
body: r == null ? void 0 : r.toString()
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
return i;
|
|
72
|
-
},
|
|
73
|
-
const
|
|
72
|
+
}, ke = ({ archive: e, resourcePath: t }) => async (i) => Se({ archive: e, resourcePath: t })(i), Ne = ({ archive: e, resourcePath: t }) => async (i) => {
|
|
73
|
+
const s = Object.values(e.files).find(
|
|
74
74
|
(n) => n.uri === t
|
|
75
75
|
);
|
|
76
|
-
if (
|
|
77
|
-
const
|
|
76
|
+
if (s != null && s.basename.endsWith(".css")) {
|
|
77
|
+
const r = (i.body ?? await s.string()).replaceAll(
|
|
78
78
|
"-webkit-writing-mode",
|
|
79
79
|
"writing-mode"
|
|
80
80
|
);
|
|
81
81
|
return {
|
|
82
82
|
...i,
|
|
83
|
-
body:
|
|
83
|
+
body: r
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
return i;
|
|
87
87
|
}, C = (e) => {
|
|
88
|
-
const i = Object.values(e.files).filter((
|
|
88
|
+
const i = Object.values(e.files).filter((s) => !s.dir).find((s) => s.uri.endsWith(".opf"));
|
|
89
89
|
return {
|
|
90
90
|
data: i,
|
|
91
91
|
basePath: (i == null ? void 0 : i.uri.substring(0, i.uri.lastIndexOf("/"))) || ""
|
|
92
92
|
};
|
|
93
|
-
},
|
|
93
|
+
}, ee = (e) => e ? e.children.map((t) => t instanceof fe ? t.text : t instanceof ue ? ee(t) : "").join("").trim() : "", T = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Z = (e) => e.endsWith("/") ? e.slice(0, -1) : e, We = (e) => {
|
|
94
94
|
const t = e.lastIndexOf("/");
|
|
95
95
|
return t >= 0 ? e.substring(0, t) : "";
|
|
96
|
-
},
|
|
97
|
-
const
|
|
96
|
+
}, te = (e, { basePath: t, baseUrl: i }) => {
|
|
97
|
+
const s = {
|
|
98
98
|
contents: [],
|
|
99
99
|
path: "",
|
|
100
100
|
href: "",
|
|
101
101
|
title: ""
|
|
102
102
|
};
|
|
103
103
|
let n = e.childNamed("span") || e.childNamed("a");
|
|
104
|
-
|
|
105
|
-
let
|
|
106
|
-
|
|
104
|
+
s.title = ((n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || ee(n)) ?? "";
|
|
105
|
+
let r = n == null ? void 0 : n.name;
|
|
106
|
+
r !== "a" && (n = e.descendantWithPath(`${r}.a`), n && (r = n.name.toLowerCase())), r === "a" && (n != null && n.attr.href) && (s.path = N(t, n.attr.href), s.href = N(i, t, n.attr.href));
|
|
107
107
|
const a = e.childNamed("ol");
|
|
108
108
|
if (a) {
|
|
109
109
|
const o = a.childrenNamed("li");
|
|
110
|
-
o && o.length > 0 && (
|
|
111
|
-
(d) =>
|
|
110
|
+
o && o.length > 0 && (s.contents = o.map(
|
|
111
|
+
(d) => te(d, { basePath: t, baseUrl: i })
|
|
112
112
|
));
|
|
113
113
|
}
|
|
114
|
-
return
|
|
115
|
-
},
|
|
116
|
-
var
|
|
117
|
-
const
|
|
114
|
+
return s;
|
|
115
|
+
}, Le = (e, { basePath: t, baseUrl: i }) => {
|
|
116
|
+
var r, a;
|
|
117
|
+
const s = [];
|
|
118
118
|
let n;
|
|
119
|
-
return e.descendantWithPath("body.nav.ol") ? n = (
|
|
120
|
-
(o) =>
|
|
121
|
-
),
|
|
122
|
-
},
|
|
119
|
+
return e.descendantWithPath("body.nav.ol") ? n = (r = e.descendantWithPath("body.nav.ol")) == null ? void 0 : r.children : e.descendantWithPath("body.section.nav.ol") && (n = (a = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : a.children), n && n.length > 0 && n.filter((o) => o.name === "li").forEach(
|
|
120
|
+
(o) => s.push(te(o, { basePath: t, baseUrl: i }))
|
|
121
|
+
), s;
|
|
122
|
+
}, Pe = async (e, t, { baseUrl: i }) => {
|
|
123
123
|
var n;
|
|
124
|
-
const
|
|
125
|
-
if (
|
|
126
|
-
const
|
|
127
|
-
(a) => a.uri.endsWith(
|
|
124
|
+
const s = (n = e.childNamed("manifest")) == null ? void 0 : n.childrenNamed("item").find((r) => r.attr.properties === "nav");
|
|
125
|
+
if (s) {
|
|
126
|
+
const r = Object.values(t.files).find(
|
|
127
|
+
(a) => a.uri.endsWith(s.attr.href || "")
|
|
128
128
|
);
|
|
129
|
-
if (
|
|
130
|
-
const a = new F.XmlDocument(await
|
|
131
|
-
return
|
|
129
|
+
if (r) {
|
|
130
|
+
const a = new F.XmlDocument(await r.string()), o = We(r.uri);
|
|
131
|
+
return Le(a, { basePath: o, baseUrl: i });
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
},
|
|
134
|
+
}, ne = (e, {
|
|
135
135
|
opfBasePath: t,
|
|
136
136
|
baseUrl: i,
|
|
137
|
-
prefix:
|
|
137
|
+
prefix: s
|
|
138
138
|
}) => {
|
|
139
139
|
var o, d;
|
|
140
|
-
const n = ((o = e == null ? void 0 : e.childNamed(`${
|
|
141
|
-
title: ((d = e == null ? void 0 : e.descendantWithPath(`${
|
|
140
|
+
const n = ((o = e == null ? void 0 : e.childNamed(`${s}content`)) == null ? void 0 : o.attr.src) || "", r = {
|
|
141
|
+
title: ((d = e == null ? void 0 : e.descendantWithPath(`${s}navLabel.${s}text`)) == null ? void 0 : d.val) || "",
|
|
142
142
|
path: N(t, n),
|
|
143
143
|
href: N(i, t, n),
|
|
144
144
|
contents: []
|
|
145
|
-
}, a = e.childrenNamed(`${
|
|
146
|
-
return a && a.length > 0 && (
|
|
147
|
-
(p) =>
|
|
148
|
-
)),
|
|
149
|
-
},
|
|
145
|
+
}, a = e.childrenNamed(`${s}navPoint`);
|
|
146
|
+
return a && a.length > 0 && (r.contents = a.map(
|
|
147
|
+
(p) => ne(p, { opfBasePath: t, baseUrl: i, prefix: s })
|
|
148
|
+
)), r;
|
|
149
|
+
}, Ce = (e, { opfBasePath: t, baseUrl: i }) => {
|
|
150
150
|
var a;
|
|
151
|
-
const
|
|
152
|
-
let
|
|
153
|
-
return n.indexOf(":") !== -1 && (
|
|
154
|
-
(o) =>
|
|
155
|
-
),
|
|
156
|
-
},
|
|
151
|
+
const s = [], n = e.name;
|
|
152
|
+
let r = "";
|
|
153
|
+
return n.indexOf(":") !== -1 && (r = n.split(":")[0] + ":"), (a = e.childNamed(`${r}navMap`)) == null || a.childrenNamed(`${r}navPoint`).forEach(
|
|
154
|
+
(o) => s.push(ne(o, { opfBasePath: t, baseUrl: i, prefix: r }))
|
|
155
|
+
), s;
|
|
156
|
+
}, Ie = async ({
|
|
157
157
|
opfData: e,
|
|
158
158
|
opfBasePath: t,
|
|
159
159
|
baseUrl: i,
|
|
160
|
-
archive:
|
|
160
|
+
archive: s
|
|
161
161
|
}) => {
|
|
162
162
|
var a;
|
|
163
|
-
const n = e.childNamed("spine"),
|
|
164
|
-
if (
|
|
165
|
-
const o = (a = e.childNamed("manifest")) == null ? void 0 : a.childrenNamed("item").find((d) => d.attr.id ===
|
|
163
|
+
const n = e.childNamed("spine"), r = n && n.attr.toc;
|
|
164
|
+
if (r) {
|
|
165
|
+
const o = (a = e.childNamed("manifest")) == null ? void 0 : a.childrenNamed("item").find((d) => d.attr.id === r);
|
|
166
166
|
if (o) {
|
|
167
|
-
const d = `${t}${t === "" ? "" : "/"}${o.attr.href}`, p = Object.values(
|
|
167
|
+
const d = `${t}${t === "" ? "" : "/"}${o.attr.href}`, p = Object.values(s.files).find(
|
|
168
168
|
(c) => c.uri.endsWith(d)
|
|
169
169
|
);
|
|
170
170
|
if (p) {
|
|
171
171
|
const c = new F.XmlDocument(await p.string());
|
|
172
|
-
return
|
|
172
|
+
return Ce(c, { opfBasePath: t, baseUrl: i });
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
-
},
|
|
177
|
-
const { basePath:
|
|
176
|
+
}, Re = async (e, t, { baseUrl: i }) => {
|
|
177
|
+
const { basePath: s } = C(t) || {}, n = await Ie({
|
|
178
178
|
opfData: e,
|
|
179
|
-
opfBasePath:
|
|
179
|
+
opfBasePath: s,
|
|
180
180
|
archive: t,
|
|
181
181
|
baseUrl: i
|
|
182
182
|
});
|
|
183
|
-
return n || await
|
|
184
|
-
},
|
|
183
|
+
return n || await Pe(e, t, { opfBasePath: s, baseUrl: i });
|
|
184
|
+
}, je = async (e) => {
|
|
185
185
|
const t = {
|
|
186
186
|
renditionLayout: void 0
|
|
187
187
|
};
|
|
188
188
|
return await Promise.all(
|
|
189
189
|
e.files.map(async (i) => {
|
|
190
|
-
var
|
|
190
|
+
var s, n;
|
|
191
191
|
if (i.uri.endsWith("com.kobobooks.display-options.xml")) {
|
|
192
|
-
const a = (
|
|
192
|
+
const a = (s = new F.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : s.childNamed("option");
|
|
193
193
|
((n = a == null ? void 0 : a.attr) == null ? void 0 : n.name) === "fixed-layout" && a.val === "true" && (t.renditionLayout = "pre-paginated");
|
|
194
194
|
}
|
|
195
195
|
})
|
|
196
196
|
), t;
|
|
197
|
-
},
|
|
197
|
+
}, re = async ({
|
|
198
198
|
archive: e
|
|
199
199
|
}) => {
|
|
200
|
-
const { data: t, basePath: i } = C(e) || {},
|
|
201
|
-
if (!
|
|
202
|
-
const n = new F.XmlDocument(
|
|
200
|
+
const { data: t, basePath: i } = C(e) || {}, s = await (t == null ? void 0 : t.string());
|
|
201
|
+
if (!s) return [];
|
|
202
|
+
const n = new F.XmlDocument(s), r = n.childNamed("manifest"), a = n.childNamed("spine"), o = a == null ? void 0 : a.childrenNamed("itemref").map((c) => c.attr.idref), d = (r == null ? void 0 : r.childrenNamed("item").filter((c) => o.includes(c.attr.id || ""))) || [];
|
|
203
203
|
return e.files.filter((c) => d.find((l) => i ? `${i}/${l.attr.href}` === c.uri : `${l.attr.href}` === c.uri));
|
|
204
|
-
},
|
|
204
|
+
}, se = (e) => {
|
|
205
205
|
var i;
|
|
206
206
|
const t = e.childNamed("manifest");
|
|
207
|
-
return ((i = t == null ? void 0 : t.childrenNamed("item")) == null ? void 0 : i.map((
|
|
208
|
-
href:
|
|
209
|
-
id:
|
|
210
|
-
mediaType:
|
|
207
|
+
return ((i = t == null ? void 0 : t.childrenNamed("item")) == null ? void 0 : i.map((s) => ({
|
|
208
|
+
href: s.attr.href || "",
|
|
209
|
+
id: s.attr.id || "",
|
|
210
|
+
mediaType: s.attr["media-type"]
|
|
211
211
|
}))) || [];
|
|
212
|
-
},
|
|
213
|
-
var
|
|
214
|
-
const { data:
|
|
215
|
-
if (!
|
|
212
|
+
}, De = ({ archive: e, baseUrl: t }) => async (i) => {
|
|
213
|
+
var X;
|
|
214
|
+
const { data: s, basePath: n } = C(e) || {}, r = await je(e);
|
|
215
|
+
if (!s)
|
|
216
216
|
return i;
|
|
217
|
-
const a = await
|
|
218
|
-
v.log(a,
|
|
219
|
-
const o = new F.XmlDocument(a), d = await
|
|
217
|
+
const a = await s.string();
|
|
218
|
+
v.log(a, r);
|
|
219
|
+
const o = new F.XmlDocument(a), d = await Re(o, e, { baseUrl: t }) || [], p = o.childNamed("metadata"), c = o.childNamed("manifest"), l = o.childNamed("spine"), u = o.childNamed("guide"), g = p == null ? void 0 : p.childNamed("dc:title"), b = (p == null ? void 0 : p.childrenNamed("meta")) || [], h = b.find(
|
|
220
220
|
(m) => m.attr.property === "rendition:layout"
|
|
221
221
|
), x = b.find(
|
|
222
222
|
(m) => m.attr.property === "rendition:flow"
|
|
223
223
|
), y = b.find(
|
|
224
224
|
(m) => m.attr.property === "rendition:spread"
|
|
225
|
-
), w = h == null ? void 0 : h.val, W = x == null ? void 0 : x.val,
|
|
226
|
-
(m,
|
|
225
|
+
), w = h == null ? void 0 : h.val, W = x == null ? void 0 : x.val, ie = y == null ? void 0 : y.val, ae = (g == null ? void 0 : g.val) || ((X = e.files.find(({ dir: m }) => m)) == null ? void 0 : X.basename) || "", oe = l == null ? void 0 : l.attr["page-progression-direction"], ce = (await re({ archive: e })).reduce(
|
|
226
|
+
(m, I) => I.size + m,
|
|
227
227
|
0
|
|
228
228
|
);
|
|
229
229
|
return {
|
|
@@ -231,50 +231,51 @@ const v = {
|
|
|
231
231
|
nav: {
|
|
232
232
|
toc: d
|
|
233
233
|
},
|
|
234
|
-
renditionLayout: w ||
|
|
234
|
+
renditionLayout: w || r.renditionLayout || "reflowable",
|
|
235
235
|
renditionFlow: W || "auto",
|
|
236
|
-
renditionSpread:
|
|
237
|
-
title:
|
|
238
|
-
readingDirection:
|
|
239
|
-
spineItems: (l == null ? void 0 : l.childrenNamed("itemref").map((m) => {
|
|
240
|
-
var
|
|
241
|
-
const f = c == null ? void 0 : c.childrenNamed("item").find(($) => $.attr.id === (m == null ? void 0 : m.attr.idref)),
|
|
236
|
+
renditionSpread: ie,
|
|
237
|
+
title: ae,
|
|
238
|
+
readingDirection: oe || "ltr",
|
|
239
|
+
spineItems: (l == null ? void 0 : l.childrenNamed("itemref").map((m, I) => {
|
|
240
|
+
var U, H, V;
|
|
241
|
+
const f = c == null ? void 0 : c.childrenNamed("item").find(($) => $.attr.id === (m == null ? void 0 : m.attr.idref)), de = (f == null ? void 0 : f.attr.href) || "", R = ((U = m == null ? void 0 : m.attr.properties) == null ? void 0 : U.split(" ")) || [], le = ((H = e.files.find(($) => $.uri.endsWith(de))) == null ? void 0 : H.size) || 0, B = t ?? "";
|
|
242
242
|
return {
|
|
243
243
|
id: (f == null ? void 0 : f.attr.id) || "",
|
|
244
|
-
|
|
244
|
+
index: I,
|
|
245
|
+
href: (V = f == null ? void 0 : f.attr.href) != null && V.startsWith("https://") ? f == null ? void 0 : f.attr.href : n ? `${B}${n}/${f == null ? void 0 : f.attr.href}` : `${B}${f == null ? void 0 : f.attr.href}`,
|
|
245
246
|
renditionLayout: w || "reflowable",
|
|
246
|
-
...
|
|
247
|
+
...R.find(
|
|
247
248
|
($) => $ === "rendition:layout-reflowable"
|
|
248
249
|
) && {
|
|
249
250
|
renditionLayout: "reflowable"
|
|
250
251
|
},
|
|
251
|
-
progressionWeight:
|
|
252
|
-
pageSpreadLeft:
|
|
253
|
-
pageSpreadRight:
|
|
252
|
+
progressionWeight: le / ce,
|
|
253
|
+
pageSpreadLeft: R.some(($) => $ === "page-spread-left") || void 0,
|
|
254
|
+
pageSpreadRight: R.some(($) => $ === "page-spread-right") || void 0,
|
|
254
255
|
// size: itemSize
|
|
255
256
|
mediaType: f == null ? void 0 : f.attr["media-type"]
|
|
256
257
|
};
|
|
257
258
|
})) || [],
|
|
258
|
-
items:
|
|
259
|
+
items: se(o),
|
|
259
260
|
guide: u == null ? void 0 : u.childrenNamed("reference").map((m) => ({
|
|
260
261
|
href: m.attr.href || "",
|
|
261
262
|
title: m.attr.title || "",
|
|
262
263
|
type: m.attr.type
|
|
263
264
|
}))
|
|
264
265
|
};
|
|
265
|
-
},
|
|
266
|
-
var n,
|
|
267
|
-
const
|
|
268
|
-
if (
|
|
269
|
-
const a = new F.XmlDocument(
|
|
266
|
+
}, Oe = async (e, t) => {
|
|
267
|
+
var n, r;
|
|
268
|
+
const s = await ((n = C(e).data) == null ? void 0 : n.string());
|
|
269
|
+
if (s) {
|
|
270
|
+
const a = new F.XmlDocument(s);
|
|
270
271
|
return {
|
|
271
|
-
mediaType: (
|
|
272
|
+
mediaType: (r = se(a).find((d) => t.endsWith(d.href))) == null ? void 0 : r.mediaType
|
|
272
273
|
};
|
|
273
274
|
}
|
|
274
275
|
return {
|
|
275
|
-
mediaType:
|
|
276
|
+
mediaType: ze(t)
|
|
276
277
|
};
|
|
277
|
-
},
|
|
278
|
+
}, ze = (e) => {
|
|
278
279
|
if (e.endsWith(".css"))
|
|
279
280
|
return "text/css; charset=UTF-8";
|
|
280
281
|
if (e.endsWith(".jpg"))
|
|
@@ -285,25 +286,25 @@ const v = {
|
|
|
285
286
|
return "video/mp4";
|
|
286
287
|
if (e.endsWith(".svg"))
|
|
287
288
|
return "image/svg+xml";
|
|
288
|
-
},
|
|
289
|
-
const
|
|
290
|
-
(
|
|
289
|
+
}, Me = ({ archive: e, resourcePath: t }) => async (i) => {
|
|
290
|
+
const s = Object.values(e.files).find(
|
|
291
|
+
(r) => r.uri === t
|
|
291
292
|
);
|
|
292
|
-
if (!
|
|
293
|
-
const n = await
|
|
293
|
+
if (!s) return i;
|
|
294
|
+
const n = await Oe(e, t);
|
|
294
295
|
return {
|
|
295
296
|
...i,
|
|
296
297
|
params: {
|
|
297
298
|
...i.params,
|
|
298
|
-
...(
|
|
299
|
-
contentType:
|
|
299
|
+
...(s == null ? void 0 : s.encodingFormat) && {
|
|
300
|
+
contentType: s.encodingFormat
|
|
300
301
|
},
|
|
301
302
|
...n.mediaType && {
|
|
302
303
|
contentType: n.mediaType
|
|
303
304
|
}
|
|
304
305
|
}
|
|
305
306
|
};
|
|
306
|
-
},
|
|
307
|
+
}, E = [
|
|
307
308
|
"div",
|
|
308
309
|
"span",
|
|
309
310
|
"p",
|
|
@@ -354,19 +355,19 @@ const v = {
|
|
|
354
355
|
"canvas",
|
|
355
356
|
"script",
|
|
356
357
|
"style"
|
|
357
|
-
],
|
|
358
|
-
const
|
|
358
|
+
], Xe = ({ archive: e, resourcePath: t }) => async (i) => {
|
|
359
|
+
const s = Object.values(e.files).find(
|
|
359
360
|
(n) => n.uri === t
|
|
360
361
|
);
|
|
361
|
-
if (
|
|
362
|
-
const n = i.body ?? await
|
|
362
|
+
if (s != null && s.basename.endsWith(".xhtml")) {
|
|
363
|
+
const n = i.body ?? await s.string();
|
|
363
364
|
if (!new RegExp(
|
|
364
|
-
`<(${
|
|
365
|
+
`<(${E.join("|")})[\\s/>]`,
|
|
365
366
|
"i"
|
|
366
367
|
).test(n))
|
|
367
368
|
return i;
|
|
368
369
|
const a = new RegExp(
|
|
369
|
-
`<(${
|
|
370
|
+
`<(${E.join("|")})(\\s[^>]*)?\\s*/>`,
|
|
370
371
|
"gi"
|
|
371
372
|
), o = n.replace(
|
|
372
373
|
a,
|
|
@@ -378,43 +379,44 @@ const v = {
|
|
|
378
379
|
};
|
|
379
380
|
}
|
|
380
381
|
return i;
|
|
381
|
-
},
|
|
382
|
+
}, Be = async (e, t) => {
|
|
382
383
|
const i = Object.values(e.files).find(
|
|
383
|
-
(
|
|
384
|
+
(r) => r.uri === t
|
|
384
385
|
);
|
|
385
386
|
if (!i)
|
|
386
387
|
throw new Error("no file found");
|
|
387
|
-
const
|
|
388
|
+
const s = {
|
|
388
389
|
params: {}
|
|
389
390
|
}, n = [
|
|
390
|
-
ze({ archive: e, resourcePath: t }),
|
|
391
391
|
Me({ archive: e, resourcePath: t }),
|
|
392
|
-
|
|
393
|
-
|
|
392
|
+
Xe({ archive: e, resourcePath: t }),
|
|
393
|
+
Ne({ archive: e, resourcePath: t }),
|
|
394
|
+
ke({ archive: e, resourcePath: t })
|
|
394
395
|
];
|
|
395
396
|
try {
|
|
396
|
-
const
|
|
397
|
-
return v.log("Generated resource", t,
|
|
398
|
-
...
|
|
399
|
-
body:
|
|
397
|
+
const r = await n.reduce(async (a, o) => await o(await a), Promise.resolve(s));
|
|
398
|
+
return v.log("Generated resource", t, r), {
|
|
399
|
+
...r,
|
|
400
|
+
body: r.body ?? await i.blob()
|
|
400
401
|
};
|
|
401
|
-
} catch (
|
|
402
|
-
throw v.error(
|
|
402
|
+
} catch (r) {
|
|
403
|
+
throw v.error(r), r;
|
|
403
404
|
}
|
|
404
|
-
},
|
|
405
|
-
var
|
|
405
|
+
}, Ue = ({ archive: e, baseUrl: t }) => async () => {
|
|
406
|
+
var s;
|
|
406
407
|
const i = Object.values(e.files).filter((n) => !n.dir);
|
|
407
408
|
return {
|
|
408
409
|
filename: e.filename,
|
|
409
|
-
title: ((
|
|
410
|
+
title: ((s = e.files.find(({ dir: n }) => n)) == null ? void 0 : s.basename.replace(/\/$/, "")) || "",
|
|
410
411
|
renditionLayout: "pre-paginated",
|
|
411
412
|
renditionSpread: "auto",
|
|
412
413
|
readingDirection: "ltr",
|
|
413
|
-
spineItems: i.filter((n) => !n.basename.endsWith(".db")).map((n,
|
|
414
|
+
spineItems: i.filter((n) => !n.basename.endsWith(".db")).map((n, r) => ({
|
|
414
415
|
// some books such as cbz can have same basename inside different sub folder
|
|
415
416
|
// we need to make sure to have unique index
|
|
416
417
|
// /chap01/01.png, /chap02/01.png, etc
|
|
417
|
-
id: `${
|
|
418
|
+
id: `${r}.${n.basename}`,
|
|
419
|
+
index: r,
|
|
418
420
|
href: encodeURI(`${t}${n.uri}`),
|
|
419
421
|
renditionLayout: "pre-paginated",
|
|
420
422
|
progressionWeight: 1 / i.length,
|
|
@@ -422,19 +424,19 @@ const v = {
|
|
|
422
424
|
pageSpreadRight: void 0,
|
|
423
425
|
mediaType: n.encodingFormat
|
|
424
426
|
})),
|
|
425
|
-
items: i.map((n,
|
|
426
|
-
id: `${
|
|
427
|
+
items: i.map((n, r) => ({
|
|
428
|
+
id: `${r}.${n.basename}`,
|
|
427
429
|
href: `${t}${n.uri}`
|
|
428
430
|
}))
|
|
429
431
|
};
|
|
430
|
-
},
|
|
431
|
-
var
|
|
432
|
+
}, He = ({ archive: e }) => async (t) => {
|
|
433
|
+
var r;
|
|
432
434
|
const i = e.files.find(
|
|
433
435
|
(a) => a.basename.toLowerCase() === "comicinfo.xml"
|
|
434
436
|
);
|
|
435
437
|
if (!i)
|
|
436
438
|
return t;
|
|
437
|
-
const
|
|
439
|
+
const s = {
|
|
438
440
|
...t,
|
|
439
441
|
spineItems: t.spineItems.filter((a) => !a.id.toLowerCase().endsWith("comicinfo.xml")).map((a, o, d) => ({
|
|
440
442
|
...a,
|
|
@@ -442,53 +444,53 @@ const v = {
|
|
|
442
444
|
}))
|
|
443
445
|
}, n = await i.string();
|
|
444
446
|
try {
|
|
445
|
-
const o = ((
|
|
447
|
+
const o = ((r = new F.XmlDocument(n).childNamed("Manga")) == null ? void 0 : r.val) || "unknown";
|
|
446
448
|
return {
|
|
447
|
-
...
|
|
449
|
+
...s,
|
|
448
450
|
readingDirection: o === "YesAndRightToLeft" ? "rtl" : "ltr"
|
|
449
451
|
};
|
|
450
452
|
} catch (a) {
|
|
451
453
|
return console.error(`Unable to parse comicinfo.xml for content
|
|
452
|
-
`, n), console.error(a),
|
|
454
|
+
`, n), console.error(a), s;
|
|
453
455
|
}
|
|
454
|
-
},
|
|
456
|
+
}, Ve = (e) => {
|
|
455
457
|
var i;
|
|
456
|
-
const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((
|
|
458
|
+
const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((s) => s.attr.name === "viewport");
|
|
457
459
|
return !!(t && t.attr.name === "viewport");
|
|
458
|
-
},
|
|
459
|
-
if (!await t || !
|
|
460
|
+
}, _e = (e) => e.reduce(async (t, i) => {
|
|
461
|
+
if (!await t || !me({
|
|
460
462
|
mimeType: i.encodingFormat,
|
|
461
463
|
uri: i.uri
|
|
462
464
|
}))
|
|
463
465
|
return !1;
|
|
464
466
|
const n = await i.string();
|
|
465
|
-
return n ?
|
|
466
|
-
}, Promise.resolve(!0)),
|
|
467
|
-
if (t.renditionLayout === "reflowable" && t.spineItems.every((
|
|
468
|
-
const
|
|
469
|
-
if (await
|
|
467
|
+
return n ? Ve(new F.XmlDocument(n)) : !1;
|
|
468
|
+
}, Promise.resolve(!0)), qe = ({ archive: e }) => async (t) => {
|
|
469
|
+
if (t.renditionLayout === "reflowable" && t.spineItems.every((s) => s.renditionLayout === "reflowable")) {
|
|
470
|
+
const s = await re({ archive: e });
|
|
471
|
+
if (await _e(s))
|
|
470
472
|
return {
|
|
471
473
|
...t,
|
|
472
|
-
spineItems: t.spineItems.map((
|
|
473
|
-
...
|
|
474
|
+
spineItems: t.spineItems.map((r) => ({
|
|
475
|
+
...r,
|
|
474
476
|
renditionLayout: "pre-paginated"
|
|
475
477
|
})),
|
|
476
478
|
renditionLayout: "pre-paginated"
|
|
477
479
|
};
|
|
478
480
|
}
|
|
479
481
|
return t;
|
|
480
|
-
},
|
|
482
|
+
}, M = (e, t) => {
|
|
481
483
|
var n;
|
|
482
|
-
const i = e.split(/(\d+)/),
|
|
483
|
-
for (let
|
|
484
|
-
if (i[
|
|
485
|
-
return (n = i[
|
|
484
|
+
const i = e.split(/(\d+)/), s = t.split(/(\d+)/);
|
|
485
|
+
for (let r = 0, a = i.length; r < a; r++)
|
|
486
|
+
if (i[r] !== s[r])
|
|
487
|
+
return (n = i[r]) != null && n.match(/\d/) ? +(i[r] || "") - +(s[r] || "") : (i[r] || "").localeCompare(s[r] || "");
|
|
486
488
|
return 1;
|
|
487
|
-
},
|
|
489
|
+
}, Ge = ({ archive: e, baseUrl: t }) => async (i) => {
|
|
488
490
|
if (i.nav) return i;
|
|
489
|
-
const
|
|
490
|
-
(o, d) =>
|
|
491
|
-
), n = Object.values(
|
|
491
|
+
const s = [...e.files].sort(
|
|
492
|
+
(o, d) => M(o.uri, d.uri)
|
|
493
|
+
), n = Object.values(s), r = (o, d, p, c, l) => {
|
|
492
494
|
const u = o.find((h) => h.title === d), [g, ...b] = p;
|
|
493
495
|
return u ? g ? [
|
|
494
496
|
...o.filter((x) => x != u),
|
|
@@ -496,7 +498,7 @@ const v = {
|
|
|
496
498
|
...u,
|
|
497
499
|
contents: [
|
|
498
500
|
...u.contents,
|
|
499
|
-
...
|
|
501
|
+
...r(
|
|
500
502
|
u.contents,
|
|
501
503
|
g,
|
|
502
504
|
b,
|
|
@@ -515,7 +517,7 @@ const v = {
|
|
|
515
517
|
] : o : g ? [
|
|
516
518
|
...o,
|
|
517
519
|
{
|
|
518
|
-
contents:
|
|
520
|
+
contents: r(
|
|
519
521
|
[],
|
|
520
522
|
g,
|
|
521
523
|
b,
|
|
@@ -541,7 +543,7 @@ const v = {
|
|
|
541
543
|
const c = d.uri.split("/").slice(0, -1), [l, ...u] = c;
|
|
542
544
|
if (l) {
|
|
543
545
|
const g = N(t, encodeURI(d.uri)).replace(/\/$/, ""), b = d.uri.replace(/\/$/, "");
|
|
544
|
-
return
|
|
546
|
+
return r(o, l, u, g, b);
|
|
545
547
|
}
|
|
546
548
|
return o;
|
|
547
549
|
},
|
|
@@ -553,7 +555,7 @@ const v = {
|
|
|
553
555
|
toc: a
|
|
554
556
|
}
|
|
555
557
|
};
|
|
556
|
-
},
|
|
558
|
+
}, Ke = {
|
|
557
559
|
filename: "",
|
|
558
560
|
items: [],
|
|
559
561
|
nav: {
|
|
@@ -564,21 +566,21 @@ const v = {
|
|
|
564
566
|
renditionSpread: "auto",
|
|
565
567
|
spineItems: [],
|
|
566
568
|
title: ""
|
|
567
|
-
},
|
|
569
|
+
}, Je = async (e, { baseUrl: t = "" } = {}) => {
|
|
568
570
|
const i = [
|
|
569
|
-
Be({ archive: e, baseUrl: t }),
|
|
570
|
-
je({ archive: e, baseUrl: t }),
|
|
571
|
-
_e({ archive: e, baseUrl: t }),
|
|
572
571
|
Ue({ archive: e, baseUrl: t }),
|
|
573
|
-
|
|
572
|
+
De({ archive: e, baseUrl: t }),
|
|
573
|
+
qe({ archive: e, baseUrl: t }),
|
|
574
|
+
He({ archive: e, baseUrl: t }),
|
|
575
|
+
Ge({ archive: e, baseUrl: t })
|
|
574
576
|
];
|
|
575
577
|
try {
|
|
576
|
-
const
|
|
577
|
-
return v.log("Generated manifest",
|
|
578
|
-
} catch (
|
|
579
|
-
throw v.error(
|
|
578
|
+
const s = await i.reduce(async (n, r) => await r(await n), Promise.resolve(Ke));
|
|
579
|
+
return v.log("Generated manifest", s), s;
|
|
580
|
+
} catch (s) {
|
|
581
|
+
throw v.error(s), s;
|
|
580
582
|
}
|
|
581
|
-
},
|
|
583
|
+
}, rt = async (e, t) => {
|
|
582
584
|
const i = `
|
|
583
585
|
<?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
|
|
584
586
|
<metadata>
|
|
@@ -587,22 +589,22 @@ const v = {
|
|
|
587
589
|
</metadata>
|
|
588
590
|
<manifest>
|
|
589
591
|
${e.map(
|
|
590
|
-
(
|
|
592
|
+
(r) => `<item id="${T(r)}" href="${r}" media-type="${_(r)}"/>`
|
|
591
593
|
).join(`
|
|
592
594
|
`)}
|
|
593
595
|
</manifest>
|
|
594
596
|
<spine>
|
|
595
|
-
${e.map((
|
|
597
|
+
${e.map((r) => `<itemref idref="${T(r)}" />`).join(`
|
|
596
598
|
`)}
|
|
597
599
|
</spine>
|
|
598
600
|
</package>
|
|
599
|
-
`,
|
|
601
|
+
`, s = e.map((r) => ({
|
|
600
602
|
dir: !1,
|
|
601
|
-
basename: T(
|
|
602
|
-
encodingFormat:
|
|
603
|
-
uri:
|
|
603
|
+
basename: T(r),
|
|
604
|
+
encodingFormat: _(r),
|
|
605
|
+
uri: r,
|
|
604
606
|
size: 100 / e.length,
|
|
605
|
-
blob: async () => (await fetch(
|
|
607
|
+
blob: async () => (await fetch(r)).blob(),
|
|
606
608
|
string: async () => ""
|
|
607
609
|
}));
|
|
608
610
|
return {
|
|
@@ -614,14 +616,14 @@ const v = {
|
|
|
614
616
|
size: 0,
|
|
615
617
|
blob: async () => new Blob(),
|
|
616
618
|
string: async () => i
|
|
617
|
-
}, ...
|
|
619
|
+
}, ...s],
|
|
618
620
|
close: () => Promise.resolve()
|
|
619
621
|
};
|
|
620
|
-
},
|
|
622
|
+
}, st = async (e, {
|
|
621
623
|
mimeType: t,
|
|
622
624
|
direction: i
|
|
623
625
|
} = { mimeType: "text/plain" }) => {
|
|
624
|
-
const
|
|
626
|
+
const s = `
|
|
625
627
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
626
628
|
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="ja" prefix="rendition: http://www.idpf.org/vocab/rendition/#"
|
|
627
629
|
unique-identifier="ootuya-id">
|
|
@@ -644,8 +646,8 @@ const v = {
|
|
|
644
646
|
dir: !1,
|
|
645
647
|
basename: T("generated.opf"),
|
|
646
648
|
uri: "generated.opf",
|
|
647
|
-
blob: async () => new Blob([
|
|
648
|
-
string: async () =>
|
|
649
|
+
blob: async () => new Blob([s]),
|
|
650
|
+
string: async () => s,
|
|
649
651
|
size: 0
|
|
650
652
|
},
|
|
651
653
|
{
|
|
@@ -660,30 +662,30 @@ const v = {
|
|
|
660
662
|
],
|
|
661
663
|
close: () => Promise.resolve()
|
|
662
664
|
};
|
|
663
|
-
},
|
|
664
|
-
let
|
|
665
|
-
t && (
|
|
665
|
+
}, it = async (e, { orderByAlpha: t, name: i } = {}) => {
|
|
666
|
+
let s = Object.values(e.files);
|
|
667
|
+
t && (s = s.slice().sort((r, a) => M(r.name, a.name)));
|
|
666
668
|
const n = {
|
|
667
669
|
filename: i || "",
|
|
668
|
-
files:
|
|
669
|
-
dir:
|
|
670
|
-
basename: T(
|
|
671
|
-
uri:
|
|
672
|
-
blob: () =>
|
|
673
|
-
string: () =>
|
|
674
|
-
...
|
|
675
|
-
stream:
|
|
670
|
+
files: s.map((r) => ({
|
|
671
|
+
dir: r.dir,
|
|
672
|
+
basename: T(r.name),
|
|
673
|
+
uri: r.name,
|
|
674
|
+
blob: () => r.async("blob"),
|
|
675
|
+
string: () => r.async("string"),
|
|
676
|
+
...r.internalStream && {
|
|
677
|
+
stream: r.internalStream
|
|
676
678
|
},
|
|
677
679
|
// this is private API
|
|
678
680
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
679
681
|
// @ts-ignore
|
|
680
|
-
size:
|
|
682
|
+
size: r._data.uncompressedSize
|
|
681
683
|
})),
|
|
682
684
|
close: () => Promise.resolve()
|
|
683
685
|
};
|
|
684
686
|
return v.log("Generated archive", n), n;
|
|
685
|
-
},
|
|
686
|
-
const i = await e.getFilesArray(),
|
|
687
|
+
}, at = async (e, { name: t } = {}) => {
|
|
688
|
+
const i = await e.getFilesArray(), s = {
|
|
687
689
|
close: () => e.close(),
|
|
688
690
|
filename: t ?? "",
|
|
689
691
|
files: i.map((n) => ({
|
|
@@ -695,35 +697,35 @@ const v = {
|
|
|
695
697
|
string: async () => (await n.file.extract()).text()
|
|
696
698
|
}))
|
|
697
699
|
};
|
|
698
|
-
return v.log("Generated archive",
|
|
699
|
-
},
|
|
700
|
-
let
|
|
701
|
-
return t && (
|
|
700
|
+
return v.log("Generated archive", s), s;
|
|
701
|
+
}, ot = async (e, { orderByAlpha: t, name: i } = {}) => {
|
|
702
|
+
let s = e;
|
|
703
|
+
return t && (s = s.slice().sort((n, r) => M(n.name, r.name))), {
|
|
702
704
|
filename: i || "",
|
|
703
|
-
files:
|
|
705
|
+
files: s.map((n) => ({
|
|
704
706
|
dir: n.isDir,
|
|
705
707
|
basename: T(n.name),
|
|
706
708
|
uri: n.name,
|
|
707
709
|
blob: async () => new Blob([await n.data()]),
|
|
708
710
|
string: async () => {
|
|
709
|
-
const
|
|
711
|
+
const r = await n.data();
|
|
710
712
|
return String.fromCharCode.apply(
|
|
711
713
|
null,
|
|
712
|
-
Array.from(new Uint16Array(
|
|
714
|
+
Array.from(new Uint16Array(r))
|
|
713
715
|
);
|
|
714
716
|
},
|
|
715
717
|
size: n.size
|
|
716
718
|
})),
|
|
717
719
|
close: () => Promise.resolve()
|
|
718
720
|
};
|
|
719
|
-
},
|
|
721
|
+
}, ct = ({
|
|
720
722
|
enableReport: e
|
|
721
723
|
} = {}) => {
|
|
722
724
|
v.enable(!!e);
|
|
723
725
|
};
|
|
724
|
-
class
|
|
726
|
+
class Ye {
|
|
725
727
|
constructor(t) {
|
|
726
|
-
this.cleanArchiveAfter = t, this.state$ = new
|
|
728
|
+
this.cleanArchiveAfter = t, this.state$ = new ve({
|
|
727
729
|
status: "idle",
|
|
728
730
|
locks: 0
|
|
729
731
|
});
|
|
@@ -740,43 +742,43 @@ class Je {
|
|
|
740
742
|
get isUnlocked$() {
|
|
741
743
|
return this.locks$.pipe(
|
|
742
744
|
A((t) => t <= 0),
|
|
743
|
-
|
|
744
|
-
|
|
745
|
+
$e(),
|
|
746
|
+
xe()
|
|
745
747
|
);
|
|
746
748
|
}
|
|
747
749
|
get overTTL$() {
|
|
748
750
|
return this.isUnlocked$.pipe(
|
|
749
751
|
k(
|
|
750
|
-
(t) => t ? this.cleanArchiveAfter === 1 / 0 ?
|
|
752
|
+
(t) => t ? this.cleanArchiveAfter === 1 / 0 ? K : Fe(this.cleanArchiveAfter) : K
|
|
751
753
|
)
|
|
752
754
|
);
|
|
753
755
|
}
|
|
754
756
|
}
|
|
755
|
-
const
|
|
757
|
+
const Qe = ({
|
|
756
758
|
getArchive: e,
|
|
757
759
|
cleanArchiveAfter: t = 5 * 60 * 1e3
|
|
758
760
|
// 5mn
|
|
759
761
|
}) => {
|
|
760
|
-
const i = new
|
|
761
|
-
|
|
762
|
-
const c =
|
|
763
|
-
if (!c || c.state.status !== "idle") return
|
|
762
|
+
const i = new j(), s = new j(), n = new j(), r = {}, a = i.pipe(
|
|
763
|
+
z((p) => {
|
|
764
|
+
const c = r[p];
|
|
765
|
+
if (!c || c.state.status !== "idle") return q;
|
|
764
766
|
let l = !1;
|
|
765
767
|
const u = (y) => {
|
|
766
768
|
var W;
|
|
767
|
-
const w =
|
|
768
|
-
delete
|
|
769
|
+
const w = r[y];
|
|
770
|
+
delete r[y], l || ((W = w == null ? void 0 : w.state.archive) == null || W.close(), l = !0);
|
|
769
771
|
};
|
|
770
772
|
c.update({
|
|
771
773
|
status: "loading"
|
|
772
774
|
});
|
|
773
775
|
const g = c.locks$, b = c.isUnlocked$, h = g.pipe(
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
776
|
+
he(),
|
|
777
|
+
D(([y, w]) => w > y),
|
|
778
|
+
ge(!0)
|
|
777
779
|
);
|
|
778
780
|
return L(e(p)).pipe(
|
|
779
|
-
|
|
781
|
+
O((y) => {
|
|
780
782
|
c.update({
|
|
781
783
|
archive: y,
|
|
782
784
|
status: "success"
|
|
@@ -785,25 +787,25 @@ const Ye = ({
|
|
|
785
787
|
P((y) => (u(p), c.update({
|
|
786
788
|
status: "error",
|
|
787
789
|
error: y
|
|
788
|
-
}),
|
|
790
|
+
}), q)),
|
|
789
791
|
k(() => {
|
|
790
792
|
const y = h.pipe(
|
|
791
793
|
k(() => n),
|
|
792
794
|
k(() => b),
|
|
793
|
-
|
|
795
|
+
D((w) => w)
|
|
794
796
|
);
|
|
795
|
-
return
|
|
797
|
+
return G(y, c.overTTL$);
|
|
796
798
|
}),
|
|
797
|
-
|
|
799
|
+
O(() => {
|
|
798
800
|
u(p);
|
|
799
801
|
})
|
|
800
802
|
);
|
|
801
803
|
}),
|
|
802
|
-
|
|
804
|
+
ye(s)
|
|
803
805
|
), o = (p) => {
|
|
804
806
|
let c = !1;
|
|
805
|
-
const l =
|
|
806
|
-
|
|
807
|
+
const l = r[p] ?? new Ye(t);
|
|
808
|
+
r[p] = l, l.update({
|
|
807
809
|
locks: l.state.locks + 1
|
|
808
810
|
});
|
|
809
811
|
const u = () => {
|
|
@@ -814,16 +816,16 @@ const Ye = ({
|
|
|
814
816
|
i.next(p);
|
|
815
817
|
const g = l.state$.pipe(
|
|
816
818
|
A(({ archive: h }) => h),
|
|
817
|
-
|
|
819
|
+
D((h) => !!h)
|
|
818
820
|
), b = l.state$.pipe(
|
|
819
|
-
|
|
821
|
+
O(({ error: h }) => {
|
|
820
822
|
if (h)
|
|
821
823
|
throw h;
|
|
822
824
|
}),
|
|
823
|
-
|
|
825
|
+
be()
|
|
824
826
|
);
|
|
825
|
-
return
|
|
826
|
-
|
|
827
|
+
return G(g, b).pipe(
|
|
828
|
+
we(),
|
|
827
829
|
A((h) => ({ archive: h, release: u })),
|
|
828
830
|
P((h) => {
|
|
829
831
|
throw u(), h;
|
|
@@ -835,16 +837,16 @@ const Ye = ({
|
|
|
835
837
|
return a.subscribe(), {
|
|
836
838
|
access: o,
|
|
837
839
|
purge: d,
|
|
838
|
-
archives:
|
|
840
|
+
archives: r
|
|
839
841
|
};
|
|
840
842
|
};
|
|
841
|
-
class
|
|
843
|
+
class Ze {
|
|
842
844
|
constructor({
|
|
843
845
|
onError: t,
|
|
844
846
|
onManifestSuccess: i,
|
|
845
|
-
...
|
|
847
|
+
...s
|
|
846
848
|
}) {
|
|
847
|
-
this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader =
|
|
849
|
+
this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = Qe(s), this.onManifestSuccess = i ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
|
|
848
850
|
}
|
|
849
851
|
prune() {
|
|
850
852
|
this.epubLoader.purge();
|
|
@@ -854,13 +856,13 @@ class Qe {
|
|
|
854
856
|
}
|
|
855
857
|
accessArchiveWithoutLock(t) {
|
|
856
858
|
return this.accessArchive(t).pipe(
|
|
857
|
-
A(({ archive: i, release:
|
|
859
|
+
A(({ archive: i, release: s }) => (s(), i))
|
|
858
860
|
);
|
|
859
861
|
}
|
|
860
862
|
fetchManifest({ key: t, baseUrl: i }) {
|
|
861
|
-
const
|
|
862
|
-
|
|
863
|
-
|
|
863
|
+
const s = this.accessArchive(t).pipe(
|
|
864
|
+
z(({ archive: n, release: r }) => L(
|
|
865
|
+
Je(n, { baseUrl: i })
|
|
864
866
|
).pipe(
|
|
865
867
|
k(
|
|
866
868
|
(o) => L(this.onManifestSuccess({ manifest: o, archive: n }))
|
|
@@ -870,21 +872,21 @@ class Qe {
|
|
|
870
872
|
status: 200
|
|
871
873
|
})
|
|
872
874
|
),
|
|
873
|
-
|
|
874
|
-
|
|
875
|
+
J(() => {
|
|
876
|
+
r();
|
|
875
877
|
})
|
|
876
878
|
)),
|
|
877
|
-
P((n) =>
|
|
879
|
+
P((n) => Y(this.onError(n)))
|
|
878
880
|
);
|
|
879
|
-
return
|
|
881
|
+
return Q(s);
|
|
880
882
|
}
|
|
881
883
|
fetchResource({
|
|
882
884
|
key: t,
|
|
883
885
|
resourcePath: i
|
|
884
886
|
}) {
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
|
|
887
|
+
const s = this.accessArchive(t).pipe(
|
|
888
|
+
z(({ archive: n, release: r }) => L(
|
|
889
|
+
Be(n, i)
|
|
888
890
|
).pipe(
|
|
889
891
|
A(
|
|
890
892
|
(o) => new Response(o.body, {
|
|
@@ -896,16 +898,16 @@ class Qe {
|
|
|
896
898
|
}
|
|
897
899
|
})
|
|
898
900
|
),
|
|
899
|
-
|
|
900
|
-
|
|
901
|
+
J(() => {
|
|
902
|
+
r();
|
|
901
903
|
})
|
|
902
904
|
)),
|
|
903
|
-
P((n) =>
|
|
905
|
+
P((n) => Y(this.onError(n)))
|
|
904
906
|
);
|
|
905
|
-
return
|
|
907
|
+
return Q(s);
|
|
906
908
|
}
|
|
907
909
|
}
|
|
908
|
-
class
|
|
910
|
+
class dt extends Ze {
|
|
909
911
|
constructor({
|
|
910
912
|
getUriInfo: t,
|
|
911
913
|
...i
|
|
@@ -916,30 +918,30 @@ class ct extends Qe {
|
|
|
916
918
|
try {
|
|
917
919
|
const i = this.getUriInfo(t);
|
|
918
920
|
if (!i) return;
|
|
919
|
-
const
|
|
920
|
-
|
|
921
|
-
), [
|
|
922
|
-
|
|
921
|
+
const s = Z(i.baseUrl), n = t.request.url.substring(
|
|
922
|
+
s.length + 1
|
|
923
|
+
), [r = ""] = n.split("/"), a = decodeURIComponent(
|
|
924
|
+
Z(n.substring(r.length + 1))
|
|
923
925
|
);
|
|
924
926
|
n.endsWith("/manifest") ? t.respondWith(
|
|
925
|
-
this.fetchManifest({ key:
|
|
926
|
-
) : t.respondWith(this.fetchResource({ key:
|
|
927
|
+
this.fetchManifest({ key: r, baseUrl: `${s}/${r}/` })
|
|
928
|
+
) : t.respondWith(this.fetchResource({ key: r, resourcePath: a }));
|
|
927
929
|
} catch (i) {
|
|
928
930
|
t.respondWith(new Response(String(i), { status: 500 }));
|
|
929
931
|
}
|
|
930
932
|
}
|
|
931
933
|
}
|
|
932
934
|
export {
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
935
|
+
dt as ServiceWorkerStreamer,
|
|
936
|
+
Ze as Streamer,
|
|
937
|
+
ct as configure,
|
|
938
|
+
ot as createArchiveFromArrayBufferList,
|
|
939
|
+
it as createArchiveFromJszip,
|
|
940
|
+
at as createArchiveFromLibArchive,
|
|
941
|
+
st as createArchiveFromText,
|
|
942
|
+
rt as createArchiveFromUrls,
|
|
943
|
+
Je as generateManifestFromArchive,
|
|
944
|
+
Be as generateResourceFromArchive,
|
|
943
945
|
C as getArchiveOpfInfo
|
|
944
946
|
};
|
|
945
947
|
//# sourceMappingURL=index.js.map
|