@prose-reader/streamer 1.134.0 → 1.135.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 +184 -159
- 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
|
|
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 D } 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 O, 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
|
+
}, Oe = ({ 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,25 +253,25 @@ 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
|
|
261
263
|
}))
|
|
262
264
|
};
|
|
263
|
-
},
|
|
265
|
+
}, De = 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 {
|
|
@@ -291,7 +293,7 @@ const v = {
|
|
|
291
293
|
(s) => s.uri === t
|
|
292
294
|
);
|
|
293
295
|
if (!r) return i;
|
|
294
|
-
const n = await
|
|
296
|
+
const n = await De(e, t);
|
|
295
297
|
return {
|
|
296
298
|
...i,
|
|
297
299
|
params: {
|
|
@@ -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"
|
|
@@ -579,16 +581,39 @@ const v = {
|
|
|
579
581
|
spineItems: t.spineItems.map((r) => {
|
|
580
582
|
const n = e.files.find(
|
|
581
583
|
(o) => decodeURI(r.href).endsWith(o.uri)
|
|
582
|
-
), s = ue((n == null ? void 0 : n.encodingFormat) ?? "") ??
|
|
584
|
+
), s = ue((n == null ? void 0 : n.encodingFormat) ?? "") ?? D((n == null ? void 0 : n.basename) ?? "");
|
|
583
585
|
return {
|
|
584
586
|
...r,
|
|
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
|
+
console.log("FOOO", r);
|
|
600
|
+
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";
|
|
601
|
+
return {
|
|
602
|
+
...t,
|
|
603
|
+
renditionLayout: c === "true" ? "pre-paginated" : t.renditionLayout
|
|
604
|
+
};
|
|
605
|
+
} catch (o) {
|
|
606
|
+
return console.error(
|
|
607
|
+
`Unable to parse com.apple.ibooks.display-options.xml for content
|
|
608
|
+
`,
|
|
609
|
+
r
|
|
610
|
+
), console.error(o), t;
|
|
611
|
+
}
|
|
612
|
+
}, Ze = async (e, { baseUrl: t = "" } = {}) => {
|
|
589
613
|
const i = [
|
|
590
|
-
|
|
614
|
+
Oe({ archive: e, baseUrl: t }),
|
|
591
615
|
Ke({ archive: e, baseUrl: t }),
|
|
616
|
+
Qe({ archive: e, baseUrl: t }),
|
|
592
617
|
Ye({ archive: e, baseUrl: t }),
|
|
593
618
|
qe({ archive: e, baseUrl: t }),
|
|
594
619
|
Ve({ archive: e, baseUrl: t }),
|
|
@@ -596,11 +621,11 @@ const v = {
|
|
|
596
621
|
];
|
|
597
622
|
try {
|
|
598
623
|
const r = He({ archive: e, baseUrl: t })(), n = await i.reduce(async (s, o) => await o(await s), r);
|
|
599
|
-
return
|
|
624
|
+
return w.log("Generated manifest", n), n;
|
|
600
625
|
} catch (r) {
|
|
601
|
-
throw
|
|
626
|
+
throw w.error(r), r;
|
|
602
627
|
}
|
|
603
|
-
},
|
|
628
|
+
}, at = async (e, t) => {
|
|
604
629
|
const i = `
|
|
605
630
|
<?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
|
|
606
631
|
<metadata>
|
|
@@ -609,7 +634,7 @@ const v = {
|
|
|
609
634
|
</metadata>
|
|
610
635
|
<manifest>
|
|
611
636
|
${e.map(
|
|
612
|
-
(s) => `<item id="${A(s)}" href="${s}" media-type="${
|
|
637
|
+
(s) => `<item id="${A(s)}" href="${s}" media-type="${D(s)}"/>`
|
|
613
638
|
).join(`
|
|
614
639
|
`)}
|
|
615
640
|
</manifest>
|
|
@@ -621,7 +646,7 @@ const v = {
|
|
|
621
646
|
`, r = e.map((s) => ({
|
|
622
647
|
dir: !1,
|
|
623
648
|
basename: A(s),
|
|
624
|
-
encodingFormat:
|
|
649
|
+
encodingFormat: D(s),
|
|
625
650
|
uri: s,
|
|
626
651
|
size: 100 / e.length,
|
|
627
652
|
blob: async () => (await fetch(s)).blob(),
|
|
@@ -639,7 +664,7 @@ const v = {
|
|
|
639
664
|
}, ...r],
|
|
640
665
|
close: () => Promise.resolve()
|
|
641
666
|
};
|
|
642
|
-
},
|
|
667
|
+
}, ct = async (e, {
|
|
643
668
|
mimeType: t,
|
|
644
669
|
direction: i
|
|
645
670
|
} = { mimeType: "text/plain" }) => {
|
|
@@ -682,7 +707,7 @@ const v = {
|
|
|
682
707
|
],
|
|
683
708
|
close: () => Promise.resolve()
|
|
684
709
|
};
|
|
685
|
-
},
|
|
710
|
+
}, dt = async (e, { orderByAlpha: t, name: i } = {}) => {
|
|
686
711
|
let r = Object.values(e.files);
|
|
687
712
|
t && (r = r.slice().sort((s, o) => z(s.name, o.name)));
|
|
688
713
|
const n = {
|
|
@@ -703,8 +728,8 @@ const v = {
|
|
|
703
728
|
})),
|
|
704
729
|
close: () => Promise.resolve()
|
|
705
730
|
};
|
|
706
|
-
return
|
|
707
|
-
},
|
|
731
|
+
return w.log("Generated archive", n), n;
|
|
732
|
+
}, lt = async (e, { name: t } = {}) => {
|
|
708
733
|
const i = await e.getFilesArray(), r = {
|
|
709
734
|
close: () => e.close(),
|
|
710
735
|
filename: t ?? "",
|
|
@@ -717,8 +742,8 @@ const v = {
|
|
|
717
742
|
string: async () => (await n.file.extract()).text()
|
|
718
743
|
}))
|
|
719
744
|
};
|
|
720
|
-
return
|
|
721
|
-
},
|
|
745
|
+
return w.log("Generated archive", r), r;
|
|
746
|
+
}, pt = async (e, { orderByAlpha: t, name: i } = {}) => {
|
|
722
747
|
let r = e;
|
|
723
748
|
return t && (r = r.slice().sort((n, s) => z(n.name, s.name))), {
|
|
724
749
|
filename: i || "",
|
|
@@ -738,12 +763,12 @@ const v = {
|
|
|
738
763
|
})),
|
|
739
764
|
close: () => Promise.resolve()
|
|
740
765
|
};
|
|
741
|
-
},
|
|
766
|
+
}, ft = ({
|
|
742
767
|
enableReport: e
|
|
743
768
|
} = {}) => {
|
|
744
|
-
|
|
769
|
+
w.enable(!!e);
|
|
745
770
|
};
|
|
746
|
-
class
|
|
771
|
+
class et {
|
|
747
772
|
constructor(t) {
|
|
748
773
|
this.cleanArchiveAfter = t, this.state$ = new we({
|
|
749
774
|
status: "idle",
|
|
@@ -768,77 +793,77 @@ class Ze {
|
|
|
768
793
|
}
|
|
769
794
|
get overTTL$() {
|
|
770
795
|
return this.isUnlocked$.pipe(
|
|
771
|
-
|
|
796
|
+
W(
|
|
772
797
|
(t) => t ? this.cleanArchiveAfter === 1 / 0 ? G : xe(this.cleanArchiveAfter) : G
|
|
773
798
|
)
|
|
774
799
|
);
|
|
775
800
|
}
|
|
776
801
|
}
|
|
777
|
-
const
|
|
802
|
+
const tt = ({
|
|
778
803
|
getArchive: e,
|
|
779
804
|
cleanArchiveAfter: t = 5 * 60 * 1e3
|
|
780
805
|
// 5mn
|
|
781
806
|
}) => {
|
|
782
807
|
const i = new R(), r = new R(), n = new R(), s = {}, o = i.pipe(
|
|
783
|
-
M((
|
|
784
|
-
const
|
|
785
|
-
if (!
|
|
786
|
-
let
|
|
808
|
+
M((l) => {
|
|
809
|
+
const d = s[l];
|
|
810
|
+
if (!d || d.state.status !== "idle") return _;
|
|
811
|
+
let p = !1;
|
|
787
812
|
const u = (y) => {
|
|
788
|
-
var
|
|
789
|
-
const
|
|
790
|
-
delete s[y],
|
|
813
|
+
var S;
|
|
814
|
+
const v = s[y];
|
|
815
|
+
delete s[y], p || ((S = v == null ? void 0 : v.state.archive) == null || S.close(), p = !0);
|
|
791
816
|
};
|
|
792
|
-
|
|
817
|
+
d.update({
|
|
793
818
|
status: "loading"
|
|
794
819
|
});
|
|
795
|
-
const g =
|
|
820
|
+
const g = d.locks$, b = d.isUnlocked$, h = g.pipe(
|
|
796
821
|
me(),
|
|
797
|
-
j(([y,
|
|
822
|
+
j(([y, v]) => v > y),
|
|
798
823
|
he(!0)
|
|
799
824
|
);
|
|
800
|
-
return P(e(
|
|
801
|
-
|
|
802
|
-
|
|
825
|
+
return P(e(l)).pipe(
|
|
826
|
+
O((y) => {
|
|
827
|
+
d.update({
|
|
803
828
|
archive: y,
|
|
804
829
|
status: "success"
|
|
805
830
|
});
|
|
806
831
|
}),
|
|
807
|
-
I((y) => (u(
|
|
832
|
+
I((y) => (u(l), d.update({
|
|
808
833
|
status: "error",
|
|
809
834
|
error: y
|
|
810
835
|
}), _)),
|
|
811
|
-
|
|
836
|
+
W(() => {
|
|
812
837
|
const y = h.pipe(
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
j((
|
|
838
|
+
W(() => n),
|
|
839
|
+
W(() => b),
|
|
840
|
+
j((v) => v)
|
|
816
841
|
);
|
|
817
|
-
return q(y,
|
|
842
|
+
return q(y, d.overTTL$);
|
|
818
843
|
}),
|
|
819
|
-
|
|
820
|
-
u(
|
|
844
|
+
O(() => {
|
|
845
|
+
u(l);
|
|
821
846
|
})
|
|
822
847
|
);
|
|
823
848
|
}),
|
|
824
849
|
ge(r)
|
|
825
|
-
), a = (
|
|
826
|
-
let
|
|
827
|
-
const
|
|
828
|
-
s[
|
|
829
|
-
locks:
|
|
850
|
+
), a = (l) => {
|
|
851
|
+
let d = !1;
|
|
852
|
+
const p = s[l] ?? new et(t);
|
|
853
|
+
s[l] = p, p.update({
|
|
854
|
+
locks: p.state.locks + 1
|
|
830
855
|
});
|
|
831
856
|
const u = () => {
|
|
832
|
-
|
|
833
|
-
locks:
|
|
857
|
+
d || (d = !0, p.update({
|
|
858
|
+
locks: p.state.locks - 1
|
|
834
859
|
}));
|
|
835
860
|
};
|
|
836
|
-
i.next(
|
|
837
|
-
const g =
|
|
861
|
+
i.next(l);
|
|
862
|
+
const g = p.state$.pipe(
|
|
838
863
|
F(({ archive: h }) => h),
|
|
839
864
|
j((h) => !!h)
|
|
840
|
-
), b =
|
|
841
|
-
|
|
865
|
+
), b = p.state$.pipe(
|
|
866
|
+
O(({ error: h }) => {
|
|
842
867
|
if (h)
|
|
843
868
|
throw h;
|
|
844
869
|
}),
|
|
@@ -851,22 +876,22 @@ const et = ({
|
|
|
851
876
|
throw u(), h;
|
|
852
877
|
})
|
|
853
878
|
);
|
|
854
|
-
},
|
|
879
|
+
}, c = () => {
|
|
855
880
|
n.next();
|
|
856
881
|
};
|
|
857
882
|
return o.subscribe(), {
|
|
858
883
|
access: a,
|
|
859
|
-
purge:
|
|
884
|
+
purge: c,
|
|
860
885
|
archives: s
|
|
861
886
|
};
|
|
862
887
|
};
|
|
863
|
-
class
|
|
888
|
+
class nt {
|
|
864
889
|
constructor({
|
|
865
890
|
onError: t,
|
|
866
891
|
onManifestSuccess: i,
|
|
867
892
|
...r
|
|
868
893
|
}) {
|
|
869
|
-
this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader =
|
|
894
|
+
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
895
|
}
|
|
871
896
|
prune() {
|
|
872
897
|
this.epubLoader.purge();
|
|
@@ -882,9 +907,9 @@ class tt {
|
|
|
882
907
|
fetchManifest({ key: t, baseUrl: i }) {
|
|
883
908
|
const r = this.accessArchive(t).pipe(
|
|
884
909
|
M(({ archive: n, release: s }) => P(
|
|
885
|
-
|
|
910
|
+
Ze(n, { baseUrl: i })
|
|
886
911
|
).pipe(
|
|
887
|
-
|
|
912
|
+
W(
|
|
888
913
|
(a) => P(this.onManifestSuccess({ manifest: a, archive: n }))
|
|
889
914
|
),
|
|
890
915
|
F(
|
|
@@ -911,11 +936,11 @@ class tt {
|
|
|
911
936
|
Be(n, o)
|
|
912
937
|
).pipe(
|
|
913
938
|
F(
|
|
914
|
-
(
|
|
939
|
+
(c) => new Response(c.body, {
|
|
915
940
|
status: 200,
|
|
916
941
|
headers: {
|
|
917
|
-
...
|
|
918
|
-
"Content-Type":
|
|
942
|
+
...c.params.contentType && {
|
|
943
|
+
"Content-Type": c.params.contentType
|
|
919
944
|
}
|
|
920
945
|
}
|
|
921
946
|
})
|
|
@@ -930,7 +955,7 @@ class tt {
|
|
|
930
955
|
return Y(r);
|
|
931
956
|
}
|
|
932
957
|
}
|
|
933
|
-
class
|
|
958
|
+
class ut extends nt {
|
|
934
959
|
constructor({
|
|
935
960
|
getUriInfo: t,
|
|
936
961
|
...i
|
|
@@ -955,16 +980,16 @@ class ft extends tt {
|
|
|
955
980
|
}
|
|
956
981
|
}
|
|
957
982
|
export {
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
983
|
+
ut as ServiceWorkerStreamer,
|
|
984
|
+
nt as Streamer,
|
|
985
|
+
ft as configure,
|
|
986
|
+
pt as createArchiveFromArrayBufferList,
|
|
987
|
+
dt as createArchiveFromJszip,
|
|
988
|
+
lt as createArchiveFromLibArchive,
|
|
989
|
+
ct as createArchiveFromText,
|
|
990
|
+
at as createArchiveFromUrls,
|
|
991
|
+
Ze as generateManifestFromArchive,
|
|
967
992
|
Be as generateResourceFromArchive,
|
|
968
|
-
|
|
993
|
+
N as getArchiveOpfInfo
|
|
969
994
|
};
|
|
970
995
|
//# sourceMappingURL=index.js.map
|