@prose-reader/streamer 1.134.0 → 1.136.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generators/manifest/hooks/apple.d.ts +6 -0
- package/dist/index.js +173 -149
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +8 -7
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { urlJoin as
|
|
3
|
-
import { Subject as R, mergeMap as M, EMPTY as _, pairwise as me, filter as j, startWith as he, from as P, tap as D, catchError as I, switchMap as
|
|
1
|
+
import $, { XmlDocument as de, XmlTextNode as le, XmlElement as pe } from "xmldoc";
|
|
2
|
+
import { urlJoin as k, isXmlBasedMimeType as fe, parseContentType as ue, detectMimeTypeFromName as O } from "@prose-reader/shared";
|
|
3
|
+
import { Subject as R, mergeMap as M, EMPTY as _, pairwise as me, filter as j, startWith as he, from as P, tap as D, catchError as I, switchMap as W, merge as q, takeUntil as ge, map as F, ignoreElements as ye, first as be, BehaviorSubject as we, distinctUntilChanged as ve, shareReplay as $e, NEVER as G, timer as xe, finalize as K, of as J, lastValueFrom as Y } from "rxjs";
|
|
4
4
|
let T = !1;
|
|
5
|
-
const
|
|
5
|
+
const w = {
|
|
6
6
|
enable: (e) => {
|
|
7
7
|
T = e;
|
|
8
8
|
},
|
|
@@ -39,11 +39,11 @@ const v = {
|
|
|
39
39
|
const n = performance.now(), s = i(...r);
|
|
40
40
|
if (s && s.then)
|
|
41
41
|
return s.then((a) => {
|
|
42
|
-
const
|
|
43
|
-
return
|
|
42
|
+
const c = performance.now();
|
|
43
|
+
return w.metric({ name: e, duration: c - n }, t), a;
|
|
44
44
|
});
|
|
45
45
|
const o = performance.now();
|
|
46
|
-
return
|
|
46
|
+
return w.metric({ name: e, duration: o - n }, t), s;
|
|
47
47
|
}
|
|
48
48
|
}, Fe = (e) => {
|
|
49
49
|
var i;
|
|
@@ -69,7 +69,7 @@ const v = {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
return i;
|
|
72
|
-
},
|
|
72
|
+
}, Le = ({ archive: e, resourcePath: t }) => async (i) => Te({ archive: e, resourcePath: t })(i), We = ({ archive: e, resourcePath: t }) => async (i) => {
|
|
73
73
|
const r = Object.values(e.files).find(
|
|
74
74
|
(n) => n.uri === t
|
|
75
75
|
);
|
|
@@ -84,7 +84,7 @@ const v = {
|
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
return i;
|
|
87
|
-
}, ee = (e) => e ? e.children.map((t) => t instanceof le ? t.text : t instanceof pe ? ee(t) : "").join("").trim() : "", A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Q = (e) => e.endsWith("/") ? e.slice(0, -1) : e,
|
|
87
|
+
}, ee = (e) => e ? e.children.map((t) => t instanceof le ? t.text : t instanceof pe ? ee(t) : "").join("").trim() : "", A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Q = (e) => e.endsWith("/") ? e.slice(0, -1) : e, ke = (e) => {
|
|
88
88
|
const t = e.lastIndexOf("/");
|
|
89
89
|
return t >= 0 ? e.substring(0, t) : "";
|
|
90
90
|
}, te = (e, { basePath: t, baseUrl: i }) => {
|
|
@@ -97,23 +97,23 @@ const v = {
|
|
|
97
97
|
let n = e.childNamed("span") || e.childNamed("a");
|
|
98
98
|
r.title = ((n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || ee(n)) ?? "";
|
|
99
99
|
let s = n == null ? void 0 : n.name;
|
|
100
|
-
s !== "a" && (n = e.descendantWithPath(`${s}.a`), n && (s = n.name.toLowerCase())), s === "a" && (n != null && n.attr.href) && (r.path =
|
|
100
|
+
s !== "a" && (n = e.descendantWithPath(`${s}.a`), n && (s = n.name.toLowerCase())), s === "a" && (n != null && n.attr.href) && (r.path = k(t, n.attr.href), r.href = k(i, t, n.attr.href));
|
|
101
101
|
const o = e.childNamed("ol");
|
|
102
102
|
if (o) {
|
|
103
103
|
const a = o.childrenNamed("li");
|
|
104
104
|
a && a.length > 0 && (r.contents = a.map(
|
|
105
|
-
(
|
|
105
|
+
(c) => te(c, { basePath: t, baseUrl: i })
|
|
106
106
|
));
|
|
107
107
|
}
|
|
108
108
|
return r;
|
|
109
|
-
},
|
|
109
|
+
}, Ne = (e, { basePath: t, baseUrl: i }) => {
|
|
110
110
|
var s, o;
|
|
111
111
|
const r = [];
|
|
112
112
|
let n;
|
|
113
113
|
return e.descendantWithPath("body.nav.ol") ? n = (s = e.descendantWithPath("body.nav.ol")) == null ? void 0 : s.children : e.descendantWithPath("body.section.nav.ol") && (n = (o = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : o.children), n && n.length > 0 && n.filter((a) => a.name === "li").forEach(
|
|
114
114
|
(a) => r.push(te(a, { basePath: t, baseUrl: i }))
|
|
115
115
|
), r;
|
|
116
|
-
},
|
|
116
|
+
}, Se = async (e, t, { baseUrl: i }) => {
|
|
117
117
|
var n;
|
|
118
118
|
const r = (n = e.childNamed("manifest")) == null ? void 0 : n.childrenNamed("item").find((s) => s.attr.properties === "nav");
|
|
119
119
|
if (r) {
|
|
@@ -121,8 +121,8 @@ const v = {
|
|
|
121
121
|
(o) => o.uri.endsWith(r.attr.href || "")
|
|
122
122
|
);
|
|
123
123
|
if (s) {
|
|
124
|
-
const o = new
|
|
125
|
-
return
|
|
124
|
+
const o = new $.XmlDocument(await s.string()), a = ke(s.uri);
|
|
125
|
+
return Ne(o, { basePath: a, baseUrl: i });
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
}, ne = (e, {
|
|
@@ -130,15 +130,15 @@ const v = {
|
|
|
130
130
|
baseUrl: i,
|
|
131
131
|
prefix: r
|
|
132
132
|
}) => {
|
|
133
|
-
var a,
|
|
133
|
+
var a, c;
|
|
134
134
|
const n = ((a = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : a.attr.src) || "", s = {
|
|
135
|
-
title: ((
|
|
136
|
-
path:
|
|
137
|
-
href:
|
|
135
|
+
title: ((c = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : c.val) || "",
|
|
136
|
+
path: k(t, n),
|
|
137
|
+
href: k(i, t, n),
|
|
138
138
|
contents: []
|
|
139
139
|
}, o = e.childrenNamed(`${r}navPoint`);
|
|
140
140
|
return o && o.length > 0 && (s.contents = o.map(
|
|
141
|
-
(
|
|
141
|
+
(l) => ne(l, { opfBasePath: t, baseUrl: i, prefix: r })
|
|
142
142
|
)), s;
|
|
143
143
|
}, Pe = (e, { opfBasePath: t, baseUrl: i }) => {
|
|
144
144
|
var o;
|
|
@@ -156,25 +156,25 @@ const v = {
|
|
|
156
156
|
var o;
|
|
157
157
|
const n = e.childNamed("spine"), s = n && n.attr.toc;
|
|
158
158
|
if (s) {
|
|
159
|
-
const a = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((
|
|
159
|
+
const a = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((c) => c.attr.id === s);
|
|
160
160
|
if (a) {
|
|
161
|
-
const
|
|
162
|
-
(
|
|
161
|
+
const c = `${t}${t === "" ? "" : "/"}${a.attr.href}`, l = Object.values(r.files).find(
|
|
162
|
+
(d) => d.uri.endsWith(c)
|
|
163
163
|
);
|
|
164
|
-
if (
|
|
165
|
-
const
|
|
166
|
-
return Pe(
|
|
164
|
+
if (l) {
|
|
165
|
+
const d = new $.XmlDocument(await l.string());
|
|
166
|
+
return Pe(d, { opfBasePath: t, baseUrl: i });
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
}, Ce = async (e, t, { baseUrl: i }) => {
|
|
171
|
-
const { basePath: r } =
|
|
171
|
+
const { basePath: r } = N(t) || {}, n = await Ie({
|
|
172
172
|
opfData: e,
|
|
173
173
|
opfBasePath: r,
|
|
174
174
|
archive: t,
|
|
175
175
|
baseUrl: i
|
|
176
176
|
});
|
|
177
|
-
return n || await
|
|
177
|
+
return n || await Se(e, t, { opfBasePath: r, baseUrl: i });
|
|
178
178
|
}, Re = (e) => {
|
|
179
179
|
var r;
|
|
180
180
|
const t = ((r = e.attr.properties) == null ? void 0 : r.split(" ")) || [];
|
|
@@ -184,7 +184,7 @@ const v = {
|
|
|
184
184
|
pageSpreadLeft: t.some((n) => n === "page-spread-left") || void 0,
|
|
185
185
|
pageSpreadRight: t.some((n) => n === "page-spread-right") || void 0
|
|
186
186
|
};
|
|
187
|
-
},
|
|
187
|
+
}, N = (e) => {
|
|
188
188
|
const i = Object.values(e.files).filter((r) => !r.dir).find((r) => r.uri.endsWith(".opf"));
|
|
189
189
|
return {
|
|
190
190
|
data: i,
|
|
@@ -193,10 +193,10 @@ const v = {
|
|
|
193
193
|
}, re = async ({
|
|
194
194
|
archive: e
|
|
195
195
|
}) => {
|
|
196
|
-
const { data: t, basePath: i } =
|
|
196
|
+
const { data: t, basePath: i } = N(e) || {}, r = await (t == null ? void 0 : t.string());
|
|
197
197
|
if (!r) return [];
|
|
198
|
-
const n = new
|
|
199
|
-
return e.files.filter((
|
|
198
|
+
const n = new $.XmlDocument(r), s = n.childNamed("manifest"), o = n.childNamed("spine"), a = o == null ? void 0 : o.childrenNamed("itemref").map((d) => d.attr.idref), c = (s == null ? void 0 : s.childrenNamed("item").filter((d) => a.includes(d.attr.id || ""))) || [];
|
|
199
|
+
return e.files.filter((d) => c.find((p) => i ? `${i}/${p.attr.href}` === d.uri : `${p.attr.href}` === d.uri));
|
|
200
200
|
}, je = (e, t, i) => {
|
|
201
201
|
const r = e.attr.href || "", n = i == null ? void 0 : i(e);
|
|
202
202
|
return {
|
|
@@ -206,21 +206,23 @@ const v = {
|
|
|
206
206
|
};
|
|
207
207
|
}, se = (e, t, i) => {
|
|
208
208
|
var s;
|
|
209
|
-
const r = e.childNamed("manifest"), { basePath: n } =
|
|
209
|
+
const r = e.childNamed("manifest"), { basePath: n } = N(t) || {};
|
|
210
210
|
return ((s = r == null ? void 0 : r.childrenNamed("item")) == null ? void 0 : s.map((o) => je(o, n, i))) || [];
|
|
211
211
|
}, De = ({ archive: e, baseUrl: t }) => async (i) => {
|
|
212
212
|
var X;
|
|
213
|
-
const { data: r, basePath: n } =
|
|
213
|
+
const { data: r, basePath: n } = N(e) || {};
|
|
214
214
|
if (!r)
|
|
215
215
|
return i;
|
|
216
|
-
const s = await r.string()
|
|
216
|
+
const s = await r.string();
|
|
217
|
+
w.log("data", s);
|
|
218
|
+
const o = new $.XmlDocument(s), a = await Ce(o, e, { baseUrl: t }) || [], c = o.childNamed("metadata"), l = o.childNamed("manifest"), d = o.childNamed("spine"), p = o.childNamed("guide"), u = c == null ? void 0 : c.childNamed("dc:title"), g = (c == null ? void 0 : c.childrenNamed("meta")) || [], b = g.find(
|
|
217
219
|
(m) => m.attr.property === "rendition:layout"
|
|
218
220
|
), h = g.find(
|
|
219
221
|
(m) => m.attr.property === "rendition:flow"
|
|
220
|
-
),
|
|
222
|
+
), x = g.find(
|
|
221
223
|
(m) => m.attr.property === "rendition:spread"
|
|
222
|
-
), y = b == null ? void 0 : b.val,
|
|
223
|
-
(m,
|
|
224
|
+
), y = b == null ? void 0 : b.val, v = h == null ? void 0 : h.val, S = x == null ? void 0 : x.val, ie = (u == null ? void 0 : u.val) || ((X = e.files.find(({ dir: m }) => m)) == null ? void 0 : X.basename) || "", oe = d == null ? void 0 : d.attr["page-progression-direction"], ae = (await re({ archive: e })).reduce(
|
|
225
|
+
(m, L) => L.size + m,
|
|
224
226
|
0
|
|
225
227
|
);
|
|
226
228
|
return {
|
|
@@ -229,20 +231,20 @@ const v = {
|
|
|
229
231
|
toc: a
|
|
230
232
|
},
|
|
231
233
|
renditionLayout: y,
|
|
232
|
-
renditionFlow:
|
|
233
|
-
renditionSpread:
|
|
234
|
+
renditionFlow: v || "auto",
|
|
235
|
+
renditionSpread: S,
|
|
234
236
|
title: ie,
|
|
235
237
|
readingDirection: oe || "ltr",
|
|
236
238
|
/**
|
|
237
239
|
* @see https://www.w3.org/TR/epub/#sec-itemref-elem
|
|
238
240
|
*/
|
|
239
|
-
spineItems: (
|
|
241
|
+
spineItems: (d == null ? void 0 : d.childrenNamed("itemref").map((m, L) => {
|
|
240
242
|
var V, E;
|
|
241
|
-
const f =
|
|
243
|
+
const f = l == null ? void 0 : l.childrenNamed("item").find((C) => C.attr.id === (m == null ? void 0 : m.attr.idref)), B = (f == null ? void 0 : f.attr.href) || "", ce = ((V = e.files.find((C) => C.uri.endsWith(B))) == null ? void 0 : V.size) || 0, H = t || (/^https?:\/\//.test(B) ? "" : "file://"), U = Re(m);
|
|
242
244
|
return {
|
|
243
245
|
...U,
|
|
244
246
|
id: (f == null ? void 0 : f.attr.id) || "",
|
|
245
|
-
index:
|
|
247
|
+
index: L,
|
|
246
248
|
href: (E = f == null ? void 0 : f.attr.href) != null && E.startsWith("https://") ? f == null ? void 0 : f.attr.href : n ? `${H}${n}/${f == null ? void 0 : f.attr.href}` : `${H}${f == null ? void 0 : f.attr.href}`,
|
|
247
249
|
renditionLayout: U.renditionLayout ?? y,
|
|
248
250
|
progressionWeight: ce / ae,
|
|
@@ -251,10 +253,10 @@ const v = {
|
|
|
251
253
|
};
|
|
252
254
|
})) || [],
|
|
253
255
|
items: se(o, e, (m) => {
|
|
254
|
-
const
|
|
255
|
-
return /^https?:\/\//.test(
|
|
256
|
+
const L = m.attr.href || "";
|
|
257
|
+
return /^https?:\/\//.test(L) ? "" : t || "file://";
|
|
256
258
|
}),
|
|
257
|
-
guide:
|
|
259
|
+
guide: p == null ? void 0 : p.childrenNamed("reference").map((m) => ({
|
|
258
260
|
href: m.attr.href || "",
|
|
259
261
|
title: m.attr.title || "",
|
|
260
262
|
type: m.attr.type
|
|
@@ -262,14 +264,14 @@ const v = {
|
|
|
262
264
|
};
|
|
263
265
|
}, Oe = async (e, t) => {
|
|
264
266
|
var n, s, o;
|
|
265
|
-
const r = await ((n =
|
|
267
|
+
const r = await ((n = N(e).data) == null ? void 0 : n.string());
|
|
266
268
|
if (r) {
|
|
267
|
-
const a = new
|
|
268
|
-
if ((s =
|
|
269
|
-
(
|
|
269
|
+
const a = new $.XmlDocument(r), c = se(a, e, () => "");
|
|
270
|
+
if ((s = c.find(
|
|
271
|
+
(d) => t.endsWith(d.href)
|
|
270
272
|
)) == null ? void 0 : s.mediaType)
|
|
271
273
|
return {
|
|
272
|
-
mediaType: (o =
|
|
274
|
+
mediaType: (o = c.find((d) => t.endsWith(d.href))) == null ? void 0 : o.mediaType
|
|
273
275
|
};
|
|
274
276
|
}
|
|
275
277
|
return {
|
|
@@ -371,7 +373,7 @@ const v = {
|
|
|
371
373
|
"gi"
|
|
372
374
|
), a = n.replace(
|
|
373
375
|
o,
|
|
374
|
-
(
|
|
376
|
+
(c, l, d = "") => `<${l} ${d.trim()}></${l}>`
|
|
375
377
|
);
|
|
376
378
|
return {
|
|
377
379
|
...i,
|
|
@@ -390,17 +392,17 @@ const v = {
|
|
|
390
392
|
}, n = [
|
|
391
393
|
ze({ archive: e, resourcePath: t }),
|
|
392
394
|
Xe({ archive: e, resourcePath: t }),
|
|
393
|
-
|
|
394
|
-
|
|
395
|
+
We({ archive: e, resourcePath: t }),
|
|
396
|
+
Le({ archive: e, resourcePath: t })
|
|
395
397
|
];
|
|
396
398
|
try {
|
|
397
399
|
const s = await n.reduce(async (o, a) => await a(await o), Promise.resolve(r));
|
|
398
|
-
return
|
|
400
|
+
return w.log("Generated resource", t, s), {
|
|
399
401
|
...s,
|
|
400
402
|
body: s.body ?? await i.blob()
|
|
401
403
|
};
|
|
402
404
|
} catch (s) {
|
|
403
|
-
throw
|
|
405
|
+
throw w.error(s), s;
|
|
404
406
|
}
|
|
405
407
|
}, He = ({ archive: e, baseUrl: t }) => async () => {
|
|
406
408
|
var r;
|
|
@@ -437,7 +439,7 @@ const v = {
|
|
|
437
439
|
e.files.map(async (i) => {
|
|
438
440
|
var r, n;
|
|
439
441
|
if (i.uri.endsWith("com.kobobooks.display-options.xml")) {
|
|
440
|
-
const o = (r = new
|
|
442
|
+
const o = (r = new $.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : r.childNamed("option");
|
|
441
443
|
((n = o == null ? void 0 : o.attr) == null ? void 0 : n.name) === "fixed-layout" && o.val === "true" && (t.renditionLayout = "pre-paginated");
|
|
442
444
|
}
|
|
443
445
|
})
|
|
@@ -459,7 +461,7 @@ const v = {
|
|
|
459
461
|
}))
|
|
460
462
|
return !1;
|
|
461
463
|
const n = await i.string();
|
|
462
|
-
return n ? Ee(new
|
|
464
|
+
return n ? Ee(new $.XmlDocument(n)) : !1;
|
|
463
465
|
}, Promise.resolve(!0)), qe = ({ archive: e }) => async (t) => {
|
|
464
466
|
if (t.renditionLayout === "reflowable" && t.spineItems.every((r) => r.renditionLayout === "reflowable")) {
|
|
465
467
|
const r = await re({ archive: e });
|
|
@@ -484,11 +486,11 @@ const v = {
|
|
|
484
486
|
}, Ge = ({ archive: e, baseUrl: t }) => async (i) => {
|
|
485
487
|
if (i.nav) return i;
|
|
486
488
|
const r = [...e.files].sort(
|
|
487
|
-
(a,
|
|
488
|
-
), n = Object.values(r), s = (a,
|
|
489
|
-
const u = a.find((h) => h.title ===
|
|
489
|
+
(a, c) => z(a.uri, c.uri)
|
|
490
|
+
), n = Object.values(r), s = (a, c, l, d, p) => {
|
|
491
|
+
const u = a.find((h) => h.title === c), [g, ...b] = l;
|
|
490
492
|
return u ? g ? [
|
|
491
|
-
...a.filter((
|
|
493
|
+
...a.filter((x) => x != u),
|
|
492
494
|
{
|
|
493
495
|
...u,
|
|
494
496
|
contents: [
|
|
@@ -497,17 +499,17 @@ const v = {
|
|
|
497
499
|
u.contents,
|
|
498
500
|
g,
|
|
499
501
|
b,
|
|
500
|
-
|
|
501
|
-
|
|
502
|
+
d,
|
|
503
|
+
p
|
|
502
504
|
)
|
|
503
505
|
]
|
|
504
506
|
}
|
|
505
|
-
] : u.path.split("/").length >
|
|
506
|
-
...a.filter((
|
|
507
|
+
] : u.path.split("/").length > p.split("/").length ? [
|
|
508
|
+
...a.filter((x) => x != u),
|
|
507
509
|
{
|
|
508
510
|
...u,
|
|
509
|
-
path:
|
|
510
|
-
href:
|
|
511
|
+
path: p,
|
|
512
|
+
href: d
|
|
511
513
|
}
|
|
512
514
|
] : a : g ? [
|
|
513
515
|
...a,
|
|
@@ -516,29 +518,29 @@ const v = {
|
|
|
516
518
|
[],
|
|
517
519
|
g,
|
|
518
520
|
b,
|
|
519
|
-
|
|
520
|
-
|
|
521
|
+
d,
|
|
522
|
+
p
|
|
521
523
|
),
|
|
522
|
-
href:
|
|
523
|
-
path:
|
|
524
|
-
title:
|
|
524
|
+
href: d,
|
|
525
|
+
path: p,
|
|
526
|
+
title: c
|
|
525
527
|
}
|
|
526
528
|
] : [
|
|
527
529
|
...a,
|
|
528
530
|
{
|
|
529
531
|
contents: [],
|
|
530
|
-
href:
|
|
531
|
-
path:
|
|
532
|
-
title:
|
|
532
|
+
href: d,
|
|
533
|
+
path: p,
|
|
534
|
+
title: c
|
|
533
535
|
}
|
|
534
536
|
];
|
|
535
537
|
}, o = n.reduce(
|
|
536
|
-
(a,
|
|
537
|
-
if (
|
|
538
|
-
const
|
|
539
|
-
if (
|
|
540
|
-
const g =
|
|
541
|
-
return s(a,
|
|
538
|
+
(a, c) => {
|
|
539
|
+
if (c.dir) return a;
|
|
540
|
+
const d = c.uri.split("/").slice(0, -1), [p, ...u] = d;
|
|
541
|
+
if (p) {
|
|
542
|
+
const g = k(t, encodeURI(c.uri)).replace(/\/$/, ""), b = c.uri.replace(/\/$/, "");
|
|
543
|
+
return s(a, p, u, g, b);
|
|
542
544
|
}
|
|
543
545
|
return a;
|
|
544
546
|
},
|
|
@@ -559,13 +561,13 @@ const v = {
|
|
|
559
561
|
return t;
|
|
560
562
|
const r = {
|
|
561
563
|
...t,
|
|
562
|
-
spineItems: t.spineItems.filter((o) => !o.id.toLowerCase().endsWith("comicinfo.xml")).map((o, a,
|
|
564
|
+
spineItems: t.spineItems.filter((o) => !o.id.toLowerCase().endsWith("comicinfo.xml")).map((o, a, c) => ({
|
|
563
565
|
...o,
|
|
564
|
-
progressionWeight: 1 /
|
|
566
|
+
progressionWeight: 1 / c.length
|
|
565
567
|
}))
|
|
566
568
|
}, n = await i.string();
|
|
567
569
|
try {
|
|
568
|
-
const a = ((s = new
|
|
570
|
+
const a = ((s = new $.XmlDocument(n).childNamed("Manga")) == null ? void 0 : s.val) || "unknown";
|
|
569
571
|
return {
|
|
570
572
|
...r,
|
|
571
573
|
readingDirection: a === "YesAndRightToLeft" ? "rtl" : "ltr"
|
|
@@ -585,10 +587,32 @@ const v = {
|
|
|
585
587
|
renditionLayout: s != null && s.startsWith("image/") ? "pre-paginated" : r.renditionLayout
|
|
586
588
|
};
|
|
587
589
|
})
|
|
588
|
-
}, Qe =
|
|
590
|
+
}, Qe = ({ archive: e }) => async (t) => {
|
|
591
|
+
var n, s;
|
|
592
|
+
const i = e.files.find(
|
|
593
|
+
(o) => o.basename.toLowerCase() === "com.apple.ibooks.display-options.xml"
|
|
594
|
+
);
|
|
595
|
+
if (!i)
|
|
596
|
+
return t;
|
|
597
|
+
const r = await (await i.blob()).text();
|
|
598
|
+
try {
|
|
599
|
+
const a = new $.XmlDocument(r).childNamed("platform"), c = ((s = (n = a == null ? void 0 : a.childrenNamed("option")) == null ? void 0 : n.find((l) => l.attr.name === "fixed-layout")) == null ? void 0 : s.val) || "false";
|
|
600
|
+
return {
|
|
601
|
+
...t,
|
|
602
|
+
renditionLayout: c === "true" ? "pre-paginated" : t.renditionLayout
|
|
603
|
+
};
|
|
604
|
+
} catch (o) {
|
|
605
|
+
return console.error(
|
|
606
|
+
`Unable to parse com.apple.ibooks.display-options.xml for content
|
|
607
|
+
`,
|
|
608
|
+
r
|
|
609
|
+
), console.error(o), t;
|
|
610
|
+
}
|
|
611
|
+
}, Ze = async (e, { baseUrl: t = "" } = {}) => {
|
|
589
612
|
const i = [
|
|
590
613
|
De({ archive: e, baseUrl: t }),
|
|
591
614
|
Ke({ archive: e, baseUrl: t }),
|
|
615
|
+
Qe({ archive: e, baseUrl: t }),
|
|
592
616
|
Ye({ archive: e, baseUrl: t }),
|
|
593
617
|
qe({ archive: e, baseUrl: t }),
|
|
594
618
|
Ve({ archive: e, baseUrl: t }),
|
|
@@ -596,11 +620,11 @@ const v = {
|
|
|
596
620
|
];
|
|
597
621
|
try {
|
|
598
622
|
const r = He({ archive: e, baseUrl: t })(), n = await i.reduce(async (s, o) => await o(await s), r);
|
|
599
|
-
return
|
|
623
|
+
return w.log("Generated manifest", n), n;
|
|
600
624
|
} catch (r) {
|
|
601
|
-
throw
|
|
625
|
+
throw w.error(r), r;
|
|
602
626
|
}
|
|
603
|
-
},
|
|
627
|
+
}, at = async (e, t) => {
|
|
604
628
|
const i = `
|
|
605
629
|
<?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
|
|
606
630
|
<metadata>
|
|
@@ -639,7 +663,7 @@ const v = {
|
|
|
639
663
|
}, ...r],
|
|
640
664
|
close: () => Promise.resolve()
|
|
641
665
|
};
|
|
642
|
-
},
|
|
666
|
+
}, ct = async (e, {
|
|
643
667
|
mimeType: t,
|
|
644
668
|
direction: i
|
|
645
669
|
} = { mimeType: "text/plain" }) => {
|
|
@@ -682,7 +706,7 @@ const v = {
|
|
|
682
706
|
],
|
|
683
707
|
close: () => Promise.resolve()
|
|
684
708
|
};
|
|
685
|
-
},
|
|
709
|
+
}, dt = async (e, { orderByAlpha: t, name: i } = {}) => {
|
|
686
710
|
let r = Object.values(e.files);
|
|
687
711
|
t && (r = r.slice().sort((s, o) => z(s.name, o.name)));
|
|
688
712
|
const n = {
|
|
@@ -703,8 +727,8 @@ const v = {
|
|
|
703
727
|
})),
|
|
704
728
|
close: () => Promise.resolve()
|
|
705
729
|
};
|
|
706
|
-
return
|
|
707
|
-
},
|
|
730
|
+
return w.log("Generated archive", n), n;
|
|
731
|
+
}, lt = async (e, { name: t } = {}) => {
|
|
708
732
|
const i = await e.getFilesArray(), r = {
|
|
709
733
|
close: () => e.close(),
|
|
710
734
|
filename: t ?? "",
|
|
@@ -717,8 +741,8 @@ const v = {
|
|
|
717
741
|
string: async () => (await n.file.extract()).text()
|
|
718
742
|
}))
|
|
719
743
|
};
|
|
720
|
-
return
|
|
721
|
-
},
|
|
744
|
+
return w.log("Generated archive", r), r;
|
|
745
|
+
}, pt = async (e, { orderByAlpha: t, name: i } = {}) => {
|
|
722
746
|
let r = e;
|
|
723
747
|
return t && (r = r.slice().sort((n, s) => z(n.name, s.name))), {
|
|
724
748
|
filename: i || "",
|
|
@@ -738,12 +762,12 @@ const v = {
|
|
|
738
762
|
})),
|
|
739
763
|
close: () => Promise.resolve()
|
|
740
764
|
};
|
|
741
|
-
},
|
|
765
|
+
}, ft = ({
|
|
742
766
|
enableReport: e
|
|
743
767
|
} = {}) => {
|
|
744
|
-
|
|
768
|
+
w.enable(!!e);
|
|
745
769
|
};
|
|
746
|
-
class
|
|
770
|
+
class et {
|
|
747
771
|
constructor(t) {
|
|
748
772
|
this.cleanArchiveAfter = t, this.state$ = new we({
|
|
749
773
|
status: "idle",
|
|
@@ -768,76 +792,76 @@ class Ze {
|
|
|
768
792
|
}
|
|
769
793
|
get overTTL$() {
|
|
770
794
|
return this.isUnlocked$.pipe(
|
|
771
|
-
|
|
795
|
+
W(
|
|
772
796
|
(t) => t ? this.cleanArchiveAfter === 1 / 0 ? G : xe(this.cleanArchiveAfter) : G
|
|
773
797
|
)
|
|
774
798
|
);
|
|
775
799
|
}
|
|
776
800
|
}
|
|
777
|
-
const
|
|
801
|
+
const tt = ({
|
|
778
802
|
getArchive: e,
|
|
779
803
|
cleanArchiveAfter: t = 5 * 60 * 1e3
|
|
780
804
|
// 5mn
|
|
781
805
|
}) => {
|
|
782
806
|
const i = new R(), r = new R(), n = new R(), s = {}, o = i.pipe(
|
|
783
|
-
M((
|
|
784
|
-
const
|
|
785
|
-
if (!
|
|
786
|
-
let
|
|
807
|
+
M((l) => {
|
|
808
|
+
const d = s[l];
|
|
809
|
+
if (!d || d.state.status !== "idle") return _;
|
|
810
|
+
let p = !1;
|
|
787
811
|
const u = (y) => {
|
|
788
|
-
var
|
|
789
|
-
const
|
|
790
|
-
delete s[y],
|
|
812
|
+
var S;
|
|
813
|
+
const v = s[y];
|
|
814
|
+
delete s[y], p || ((S = v == null ? void 0 : v.state.archive) == null || S.close(), p = !0);
|
|
791
815
|
};
|
|
792
|
-
|
|
816
|
+
d.update({
|
|
793
817
|
status: "loading"
|
|
794
818
|
});
|
|
795
|
-
const g =
|
|
819
|
+
const g = d.locks$, b = d.isUnlocked$, h = g.pipe(
|
|
796
820
|
me(),
|
|
797
|
-
j(([y,
|
|
821
|
+
j(([y, v]) => v > y),
|
|
798
822
|
he(!0)
|
|
799
823
|
);
|
|
800
|
-
return P(e(
|
|
824
|
+
return P(e(l)).pipe(
|
|
801
825
|
D((y) => {
|
|
802
|
-
|
|
826
|
+
d.update({
|
|
803
827
|
archive: y,
|
|
804
828
|
status: "success"
|
|
805
829
|
});
|
|
806
830
|
}),
|
|
807
|
-
I((y) => (u(
|
|
831
|
+
I((y) => (u(l), d.update({
|
|
808
832
|
status: "error",
|
|
809
833
|
error: y
|
|
810
834
|
}), _)),
|
|
811
|
-
|
|
835
|
+
W(() => {
|
|
812
836
|
const y = h.pipe(
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
j((
|
|
837
|
+
W(() => n),
|
|
838
|
+
W(() => b),
|
|
839
|
+
j((v) => v)
|
|
816
840
|
);
|
|
817
|
-
return q(y,
|
|
841
|
+
return q(y, d.overTTL$);
|
|
818
842
|
}),
|
|
819
843
|
D(() => {
|
|
820
|
-
u(
|
|
844
|
+
u(l);
|
|
821
845
|
})
|
|
822
846
|
);
|
|
823
847
|
}),
|
|
824
848
|
ge(r)
|
|
825
|
-
), a = (
|
|
826
|
-
let
|
|
827
|
-
const
|
|
828
|
-
s[
|
|
829
|
-
locks:
|
|
849
|
+
), a = (l) => {
|
|
850
|
+
let d = !1;
|
|
851
|
+
const p = s[l] ?? new et(t);
|
|
852
|
+
s[l] = p, p.update({
|
|
853
|
+
locks: p.state.locks + 1
|
|
830
854
|
});
|
|
831
855
|
const u = () => {
|
|
832
|
-
|
|
833
|
-
locks:
|
|
856
|
+
d || (d = !0, p.update({
|
|
857
|
+
locks: p.state.locks - 1
|
|
834
858
|
}));
|
|
835
859
|
};
|
|
836
|
-
i.next(
|
|
837
|
-
const g =
|
|
860
|
+
i.next(l);
|
|
861
|
+
const g = p.state$.pipe(
|
|
838
862
|
F(({ archive: h }) => h),
|
|
839
863
|
j((h) => !!h)
|
|
840
|
-
), b =
|
|
864
|
+
), b = p.state$.pipe(
|
|
841
865
|
D(({ error: h }) => {
|
|
842
866
|
if (h)
|
|
843
867
|
throw h;
|
|
@@ -851,22 +875,22 @@ const et = ({
|
|
|
851
875
|
throw u(), h;
|
|
852
876
|
})
|
|
853
877
|
);
|
|
854
|
-
},
|
|
878
|
+
}, c = () => {
|
|
855
879
|
n.next();
|
|
856
880
|
};
|
|
857
881
|
return o.subscribe(), {
|
|
858
882
|
access: a,
|
|
859
|
-
purge:
|
|
883
|
+
purge: c,
|
|
860
884
|
archives: s
|
|
861
885
|
};
|
|
862
886
|
};
|
|
863
|
-
class
|
|
887
|
+
class nt {
|
|
864
888
|
constructor({
|
|
865
889
|
onError: t,
|
|
866
890
|
onManifestSuccess: i,
|
|
867
891
|
...r
|
|
868
892
|
}) {
|
|
869
|
-
this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader =
|
|
893
|
+
this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = tt(r), this.onManifestSuccess = i ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
|
|
870
894
|
}
|
|
871
895
|
prune() {
|
|
872
896
|
this.epubLoader.purge();
|
|
@@ -882,9 +906,9 @@ class tt {
|
|
|
882
906
|
fetchManifest({ key: t, baseUrl: i }) {
|
|
883
907
|
const r = this.accessArchive(t).pipe(
|
|
884
908
|
M(({ archive: n, release: s }) => P(
|
|
885
|
-
|
|
909
|
+
Ze(n, { baseUrl: i })
|
|
886
910
|
).pipe(
|
|
887
|
-
|
|
911
|
+
W(
|
|
888
912
|
(a) => P(this.onManifestSuccess({ manifest: a, archive: n }))
|
|
889
913
|
),
|
|
890
914
|
F(
|
|
@@ -911,11 +935,11 @@ class tt {
|
|
|
911
935
|
Be(n, o)
|
|
912
936
|
).pipe(
|
|
913
937
|
F(
|
|
914
|
-
(
|
|
938
|
+
(c) => new Response(c.body, {
|
|
915
939
|
status: 200,
|
|
916
940
|
headers: {
|
|
917
|
-
...
|
|
918
|
-
"Content-Type":
|
|
941
|
+
...c.params.contentType && {
|
|
942
|
+
"Content-Type": c.params.contentType
|
|
919
943
|
}
|
|
920
944
|
}
|
|
921
945
|
})
|
|
@@ -930,7 +954,7 @@ class tt {
|
|
|
930
954
|
return Y(r);
|
|
931
955
|
}
|
|
932
956
|
}
|
|
933
|
-
class
|
|
957
|
+
class ut extends nt {
|
|
934
958
|
constructor({
|
|
935
959
|
getUriInfo: t,
|
|
936
960
|
...i
|
|
@@ -955,16 +979,16 @@ class ft extends tt {
|
|
|
955
979
|
}
|
|
956
980
|
}
|
|
957
981
|
export {
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
982
|
+
ut as ServiceWorkerStreamer,
|
|
983
|
+
nt as Streamer,
|
|
984
|
+
ft as configure,
|
|
985
|
+
pt as createArchiveFromArrayBufferList,
|
|
986
|
+
dt as createArchiveFromJszip,
|
|
987
|
+
lt as createArchiveFromLibArchive,
|
|
988
|
+
ct as createArchiveFromText,
|
|
989
|
+
at as createArchiveFromUrls,
|
|
990
|
+
Ze as generateManifestFromArchive,
|
|
967
991
|
Be as generateResourceFromArchive,
|
|
968
|
-
|
|
992
|
+
N as getArchiveOpfInfo
|
|
969
993
|
};
|
|
970
994
|
//# sourceMappingURL=index.js.map
|