@prose-reader/streamer 1.84.0 → 1.86.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/Streamer.test.d.ts +1 -0
- package/dist/index.js +75 -75
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +4 -4
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { urlJoin as N, PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME as ie, isXmlBasedMimeType as oe, detectMimeTypeFromName as M } from "@prose-reader/shared";
|
|
2
2
|
import y, { XmlDocument as ce } from "xmldoc";
|
|
3
|
-
import { Subject as
|
|
3
|
+
import { Subject as U, mergeMap as I, EMPTY as de, from as L, map as v, catchError as F, NEVER as V, shareReplay as le, switchMap as X, timer as me, tap as B, merge as _, takeUntil as pe, BehaviorSubject as fe, filter as ue, ignoreElements as he, first as ge, finalize as H, of as E, lastValueFrom as G } from "rxjs";
|
|
4
4
|
let x = !1;
|
|
5
5
|
const g = {
|
|
6
6
|
enable: (e) => {
|
|
@@ -39,8 +39,8 @@ const g = {
|
|
|
39
39
|
const t = performance.now(), a = s(...r);
|
|
40
40
|
if (a && a.then)
|
|
41
41
|
return a.then((o) => {
|
|
42
|
-
const
|
|
43
|
-
return g.metric({ name: e, duration:
|
|
42
|
+
const d = performance.now();
|
|
43
|
+
return g.metric({ name: e, duration: d - t }, n), o;
|
|
44
44
|
});
|
|
45
45
|
const i = performance.now();
|
|
46
46
|
return g.metric({ name: e, duration: i - t }, n), a;
|
|
@@ -105,7 +105,7 @@ const g = {
|
|
|
105
105
|
if (i) {
|
|
106
106
|
const o = i.childrenNamed("li");
|
|
107
107
|
o && o.length > 0 && (r.contents = o.map(
|
|
108
|
-
(
|
|
108
|
+
(d) => q(d, { opfBasePath: n, baseUrl: s })
|
|
109
109
|
));
|
|
110
110
|
}
|
|
111
111
|
return r;
|
|
@@ -133,9 +133,9 @@ const g = {
|
|
|
133
133
|
baseUrl: s,
|
|
134
134
|
prefix: r
|
|
135
135
|
}) => {
|
|
136
|
-
var o,
|
|
136
|
+
var o, d;
|
|
137
137
|
const t = ((o = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : o.attr.src) || "", a = {
|
|
138
|
-
title: ((
|
|
138
|
+
title: ((d = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : d.val) || "",
|
|
139
139
|
path: N(n, t),
|
|
140
140
|
href: N(s, n, t),
|
|
141
141
|
contents: []
|
|
@@ -159,14 +159,14 @@ const g = {
|
|
|
159
159
|
var i;
|
|
160
160
|
const t = e.childNamed("spine"), a = t && t.attr.toc;
|
|
161
161
|
if (a) {
|
|
162
|
-
const o = (i = e.childNamed("manifest")) == null ? void 0 : i.childrenNamed("item").find((
|
|
162
|
+
const o = (i = e.childNamed("manifest")) == null ? void 0 : i.childrenNamed("item").find((d) => d.attr.id === a);
|
|
163
163
|
if (o) {
|
|
164
|
-
const
|
|
165
|
-
(
|
|
164
|
+
const d = `${n}${n === "" ? "" : "/"}${o.attr.href}`, l = Object.values(r.files).find(
|
|
165
|
+
(c) => c.uri.endsWith(d)
|
|
166
166
|
);
|
|
167
167
|
if (l) {
|
|
168
|
-
const
|
|
169
|
-
return Ne(
|
|
168
|
+
const c = new y.XmlDocument(await l.string());
|
|
169
|
+
return Ne(c, { opfBasePath: n, baseUrl: s });
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
}
|
|
@@ -196,8 +196,8 @@ const g = {
|
|
|
196
196
|
}) => {
|
|
197
197
|
const { data: n, basePath: s } = T(e) || {}, r = await (n == null ? void 0 : n.string());
|
|
198
198
|
if (!r) return [];
|
|
199
|
-
const t = new y.XmlDocument(r), a = t.childNamed("manifest"), i = t.childNamed("spine"), o = i == null ? void 0 : i.childrenNamed("itemref").map((
|
|
200
|
-
return e.files.filter((
|
|
199
|
+
const t = new y.XmlDocument(r), a = t.childNamed("manifest"), i = t.childNamed("spine"), o = i == null ? void 0 : i.childrenNamed("itemref").map((c) => c.attr.idref), d = (a == null ? void 0 : a.childrenNamed("item").filter((c) => o.includes(c.attr.id || ""))) || [];
|
|
200
|
+
return e.files.filter((c) => d.find((u) => s ? `${s}/${u.attr.href}` === c.uri : `${u.attr.href}` === c.uri));
|
|
201
201
|
}, Q = (e) => {
|
|
202
202
|
var s;
|
|
203
203
|
const n = e.childNamed("manifest");
|
|
@@ -206,27 +206,27 @@ const g = {
|
|
|
206
206
|
id: r.attr.id || "",
|
|
207
207
|
mediaType: r.attr["media-type"]
|
|
208
208
|
}))) || [];
|
|
209
|
-
},
|
|
209
|
+
}, Re = ({ archive: e, baseUrl: n }) => async (s) => {
|
|
210
210
|
var P;
|
|
211
211
|
const { data: r, basePath: t } = T(e) || {}, a = await ke(e);
|
|
212
212
|
if (!r)
|
|
213
213
|
return s;
|
|
214
214
|
const i = await r.string();
|
|
215
215
|
g.log(i, a);
|
|
216
|
-
const o = new y.XmlDocument(i),
|
|
216
|
+
const o = new y.XmlDocument(i), d = await Se(o, e, { baseUrl: n }) || [], l = o.childNamed("metadata"), c = o.childNamed("manifest"), u = o.childNamed("spine"), f = o.childNamed("guide"), w = l == null ? void 0 : l.childNamed("dc:title"), h = (l == null ? void 0 : l.childrenNamed("meta")) || [], S = h.find(
|
|
217
217
|
(p) => p.attr.property === "rendition:layout"
|
|
218
218
|
), k = h.find(
|
|
219
219
|
(p) => p.attr.property === "rendition:flow"
|
|
220
|
-
),
|
|
220
|
+
), R = h.find(
|
|
221
221
|
(p) => p.attr.property === "rendition:spread"
|
|
222
|
-
), C = S == null ? void 0 : S.val, Z = k == null ? void 0 : k.val, ee =
|
|
222
|
+
), C = S == null ? void 0 : S.val, Z = k == null ? void 0 : k.val, ee = R == null ? void 0 : R.val, te = (w == null ? void 0 : w.val) || ((P = e.files.find(({ dir: p }) => p)) == null ? void 0 : P.basename) || "", ne = u == null ? void 0 : u.attr["page-progression-direction"], re = (await K({ archive: e })).reduce(
|
|
223
223
|
(p, m) => m.size + p,
|
|
224
224
|
0
|
|
225
225
|
);
|
|
226
226
|
return {
|
|
227
227
|
filename: e.filename,
|
|
228
228
|
nav: {
|
|
229
|
-
toc:
|
|
229
|
+
toc: d
|
|
230
230
|
},
|
|
231
231
|
renditionLayout: C || a.renditionLayout || "reflowable",
|
|
232
232
|
renditionFlow: Z || "auto",
|
|
@@ -235,19 +235,19 @@ const g = {
|
|
|
235
235
|
readingDirection: ne || "ltr",
|
|
236
236
|
spineItems: (u == null ? void 0 : u.childrenNamed("itemref").map((p) => {
|
|
237
237
|
var O, j, z;
|
|
238
|
-
const m =
|
|
238
|
+
const m = c == null ? void 0 : c.childrenNamed("item").find((b) => b.attr.id === (p == null ? void 0 : p.attr.idref)), ae = (m == null ? void 0 : m.attr.href) || "", W = ((O = p == null ? void 0 : p.attr.properties) == null ? void 0 : O.split(" ")) || [], se = ((j = e.files.find((b) => b.uri.endsWith(ae))) == null ? void 0 : j.size) || 0, D = n ?? "";
|
|
239
239
|
return {
|
|
240
240
|
id: (m == null ? void 0 : m.attr.id) || "",
|
|
241
241
|
href: (z = m == null ? void 0 : m.attr.href) != null && z.startsWith("https://") ? m == null ? void 0 : m.attr.href : t ? `${D}${t}/${m == null ? void 0 : m.attr.href}` : `${D}${m == null ? void 0 : m.attr.href}`,
|
|
242
242
|
renditionLayout: C || "reflowable",
|
|
243
|
-
...
|
|
243
|
+
...W.find(
|
|
244
244
|
(b) => b === "rendition:layout-reflowable"
|
|
245
245
|
) && {
|
|
246
246
|
renditionLayout: "reflowable"
|
|
247
247
|
},
|
|
248
248
|
progressionWeight: se / re,
|
|
249
|
-
pageSpreadLeft:
|
|
250
|
-
pageSpreadRight:
|
|
249
|
+
pageSpreadLeft: W.some((b) => b === "page-spread-left") || void 0,
|
|
250
|
+
pageSpreadRight: W.some((b) => b === "page-spread-right") || void 0,
|
|
251
251
|
// size: itemSize
|
|
252
252
|
mediaType: m == null ? void 0 : m.attr["media-type"]
|
|
253
253
|
};
|
|
@@ -259,19 +259,19 @@ const g = {
|
|
|
259
259
|
type: p.attr.type
|
|
260
260
|
}))
|
|
261
261
|
};
|
|
262
|
-
},
|
|
262
|
+
}, We = async (e, n) => {
|
|
263
263
|
var t, a;
|
|
264
264
|
const r = await ((t = T(e).data) == null ? void 0 : t.string());
|
|
265
265
|
if (r) {
|
|
266
266
|
const i = new y.XmlDocument(r);
|
|
267
267
|
return {
|
|
268
|
-
mediaType: (a = Q(i).find((
|
|
268
|
+
mediaType: (a = Q(i).find((d) => n.endsWith(d.href))) == null ? void 0 : a.mediaType
|
|
269
269
|
};
|
|
270
270
|
}
|
|
271
271
|
return {
|
|
272
|
-
mediaType:
|
|
272
|
+
mediaType: Ie(n)
|
|
273
273
|
};
|
|
274
|
-
},
|
|
274
|
+
}, Ie = (e) => {
|
|
275
275
|
if (e.endsWith(".css"))
|
|
276
276
|
return "text/css; charset=UTF-8";
|
|
277
277
|
if (e.endsWith(".jpg"))
|
|
@@ -282,12 +282,12 @@ const g = {
|
|
|
282
282
|
return "video/mp4";
|
|
283
283
|
if (e.endsWith(".svg"))
|
|
284
284
|
return "image/svg+xml";
|
|
285
|
-
},
|
|
285
|
+
}, Le = ({ archive: e, resourcePath: n }) => async (s) => {
|
|
286
286
|
const r = Object.values(e.files).find(
|
|
287
287
|
(a) => a.uri === n
|
|
288
288
|
);
|
|
289
289
|
if (!r) return s;
|
|
290
|
-
const t = await
|
|
290
|
+
const t = await We(e, n);
|
|
291
291
|
return {
|
|
292
292
|
...s,
|
|
293
293
|
params: {
|
|
@@ -303,7 +303,7 @@ const g = {
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
};
|
|
306
|
-
},
|
|
306
|
+
}, Ae = async (e, n) => {
|
|
307
307
|
const s = Object.values(e.files).find(
|
|
308
308
|
(a) => a.uri === n
|
|
309
309
|
);
|
|
@@ -314,7 +314,7 @@ const g = {
|
|
|
314
314
|
status: 200
|
|
315
315
|
}
|
|
316
316
|
}, t = [
|
|
317
|
-
|
|
317
|
+
Le({ archive: e, resourcePath: n }),
|
|
318
318
|
$e({ archive: e, resourcePath: n }),
|
|
319
319
|
ve({ archive: e, resourcePath: n })
|
|
320
320
|
];
|
|
@@ -380,9 +380,9 @@ const g = {
|
|
|
380
380
|
return n;
|
|
381
381
|
const r = {
|
|
382
382
|
...n,
|
|
383
|
-
spineItems: n.spineItems.filter((i) => !i.id.toLowerCase().endsWith("comicinfo.xml")).map((i, o,
|
|
383
|
+
spineItems: n.spineItems.filter((i) => !i.id.toLowerCase().endsWith("comicinfo.xml")).map((i, o, d) => ({
|
|
384
384
|
...i,
|
|
385
|
-
progressionWeight: 1 /
|
|
385
|
+
progressionWeight: 1 / d.length
|
|
386
386
|
}))
|
|
387
387
|
}, t = await s.string();
|
|
388
388
|
try {
|
|
@@ -421,7 +421,7 @@ const g = {
|
|
|
421
421
|
};
|
|
422
422
|
}
|
|
423
423
|
return n;
|
|
424
|
-
},
|
|
424
|
+
}, A = (e, n) => {
|
|
425
425
|
var t;
|
|
426
426
|
const s = e.split(/(\d+)/), r = n.split(/(\d+)/);
|
|
427
427
|
for (let a = 0, i = s.length; a < i; a++)
|
|
@@ -431,14 +431,14 @@ const g = {
|
|
|
431
431
|
}, ze = ({ archive: e, baseUrl: n }) => async (s) => {
|
|
432
432
|
if (s.nav) return s;
|
|
433
433
|
const r = [...e.files].sort(
|
|
434
|
-
(a, i) =>
|
|
434
|
+
(a, i) => A(a.uri, i.uri)
|
|
435
435
|
), t = Object.values(
|
|
436
436
|
r
|
|
437
437
|
).reduce(
|
|
438
438
|
(a, i) => {
|
|
439
439
|
const o = i.uri.split("/");
|
|
440
|
-
return !i.dir && o.length > 1 && o.forEach((l,
|
|
441
|
-
if (
|
|
440
|
+
return !i.dir && o.length > 1 && o.forEach((l, c) => {
|
|
441
|
+
if (c === o.length - 1) return;
|
|
442
442
|
a.find(({ title: w }) => w === l) || a.push({
|
|
443
443
|
contents: [],
|
|
444
444
|
href: N(n, encodeURI(i.uri)).replace(/\/$/, ""),
|
|
@@ -466,10 +466,10 @@ const g = {
|
|
|
466
466
|
renditionSpread: "auto",
|
|
467
467
|
spineItems: [],
|
|
468
468
|
title: ""
|
|
469
|
-
},
|
|
469
|
+
}, Ue = async (e, { baseUrl: n = "" } = {}) => {
|
|
470
470
|
const s = [
|
|
471
471
|
Ce({ archive: e, baseUrl: n }),
|
|
472
|
-
|
|
472
|
+
Re({ archive: e, baseUrl: n }),
|
|
473
473
|
je({ archive: e, baseUrl: n }),
|
|
474
474
|
Pe({ archive: e, baseUrl: n }),
|
|
475
475
|
ze({ archive: e, baseUrl: n })
|
|
@@ -521,7 +521,7 @@ const g = {
|
|
|
521
521
|
}, ...r],
|
|
522
522
|
close: () => Promise.resolve()
|
|
523
523
|
};
|
|
524
|
-
},
|
|
524
|
+
}, Ve = async (e) => new Promise((n) => {
|
|
525
525
|
const s = new FileReader();
|
|
526
526
|
s.readAsDataURL(e), s.onloadend = function() {
|
|
527
527
|
const r = s.result;
|
|
@@ -565,7 +565,7 @@ const g = {
|
|
|
565
565
|
uri: "p01.txt",
|
|
566
566
|
blob: async () => typeof e == "string" ? new Blob([e]) : e,
|
|
567
567
|
string: async () => typeof e == "string" ? e : e.text(),
|
|
568
|
-
base64: async () => typeof e == "string" ? btoa(e) :
|
|
568
|
+
base64: async () => typeof e == "string" ? btoa(e) : Ve(e),
|
|
569
569
|
size: typeof e == "string" ? e.length : e.size,
|
|
570
570
|
encodingFormat: n
|
|
571
571
|
}
|
|
@@ -574,7 +574,7 @@ const g = {
|
|
|
574
574
|
};
|
|
575
575
|
}, Ke = async (e, { orderByAlpha: n, name: s } = {}) => {
|
|
576
576
|
let r = Object.values(e.files);
|
|
577
|
-
n && (r = r.slice().sort((a, i) =>
|
|
577
|
+
n && (r = r.slice().sort((a, i) => A(a.name, i.name)));
|
|
578
578
|
const t = {
|
|
579
579
|
filename: s || "",
|
|
580
580
|
files: r.map((a) => ({
|
|
@@ -612,7 +612,7 @@ const g = {
|
|
|
612
612
|
return g.log("Generated archive", r), r;
|
|
613
613
|
}, Ze = async (e, { orderByAlpha: n, name: s } = {}) => {
|
|
614
614
|
let r = e;
|
|
615
|
-
return n && (r = r.slice().sort((t, a) =>
|
|
615
|
+
return n && (r = r.slice().sort((t, a) => A(t.name, a.name))), {
|
|
616
616
|
filename: s || "",
|
|
617
617
|
files: r.map((t) => ({
|
|
618
618
|
dir: t.isDir,
|
|
@@ -639,62 +639,62 @@ const g = {
|
|
|
639
639
|
getArchive: e,
|
|
640
640
|
cleanArchiveAfter: n
|
|
641
641
|
}) => {
|
|
642
|
-
const s = new
|
|
643
|
-
|
|
644
|
-
const l = t[
|
|
642
|
+
const s = new U(), r = new U(), t = {}, a = s.pipe(
|
|
643
|
+
I((d) => {
|
|
644
|
+
const l = t[d];
|
|
645
645
|
return !l || l.getValue().status !== "idle" ? de : (l.next({
|
|
646
646
|
...l.getValue(),
|
|
647
647
|
status: "loading"
|
|
648
|
-
}),
|
|
649
|
-
v((
|
|
648
|
+
}), L(e(d)).pipe(
|
|
649
|
+
v((c) => (l.next({
|
|
650
650
|
...l.getValue(),
|
|
651
|
-
archive:
|
|
651
|
+
archive: c,
|
|
652
652
|
status: "success"
|
|
653
|
-
}), { key:
|
|
654
|
-
F((
|
|
653
|
+
}), { key: d, archiveEntry: l })),
|
|
654
|
+
F((c) => {
|
|
655
655
|
throw l.next({
|
|
656
656
|
...l.getValue(),
|
|
657
657
|
status: "error",
|
|
658
|
-
error:
|
|
659
|
-
}),
|
|
658
|
+
error: c
|
|
659
|
+
}), c;
|
|
660
660
|
})
|
|
661
661
|
));
|
|
662
662
|
}),
|
|
663
|
-
F((
|
|
663
|
+
F(() => V),
|
|
664
664
|
le()
|
|
665
665
|
), i = a.pipe(
|
|
666
|
-
X(({ archiveEntry:
|
|
666
|
+
X(({ archiveEntry: d, key: l }) => d.pipe(v(({ locks: f }) => f)).pipe(v((f) => f <= 0)).pipe(
|
|
667
667
|
X(
|
|
668
|
-
(f) => f ? me(n) :
|
|
668
|
+
(f) => f ? me(n) : V
|
|
669
669
|
),
|
|
670
670
|
B(() => {
|
|
671
671
|
var f;
|
|
672
|
-
delete t[l], (f =
|
|
672
|
+
delete t[l], (f = d.getValue().archive) == null || f.close();
|
|
673
673
|
})
|
|
674
674
|
))
|
|
675
|
-
), o = (
|
|
675
|
+
), o = (d) => {
|
|
676
676
|
let l = !1;
|
|
677
|
-
const
|
|
677
|
+
const c = t[d] ?? new fe({
|
|
678
678
|
archive: void 0,
|
|
679
679
|
status: "idle",
|
|
680
680
|
locks: 0,
|
|
681
681
|
error: void 0
|
|
682
682
|
});
|
|
683
|
-
t[
|
|
684
|
-
...
|
|
685
|
-
locks:
|
|
683
|
+
t[d] = c, c.next({
|
|
684
|
+
...c.getValue(),
|
|
685
|
+
locks: c.getValue().locks + 1
|
|
686
686
|
});
|
|
687
687
|
const u = () => {
|
|
688
|
-
l || (l = !0,
|
|
689
|
-
...
|
|
690
|
-
locks:
|
|
688
|
+
l || (l = !0, c.next({
|
|
689
|
+
...c.getValue(),
|
|
690
|
+
locks: c.getValue().locks - 1
|
|
691
691
|
}));
|
|
692
692
|
};
|
|
693
|
-
s.next(
|
|
694
|
-
const f =
|
|
693
|
+
s.next(d);
|
|
694
|
+
const f = c.pipe(
|
|
695
695
|
v(({ archive: h }) => h),
|
|
696
696
|
ue((h) => !!h)
|
|
697
|
-
), w =
|
|
697
|
+
), w = c.pipe(
|
|
698
698
|
B(({ error: h }) => {
|
|
699
699
|
if (h)
|
|
700
700
|
throw h;
|
|
@@ -722,8 +722,8 @@ class Be {
|
|
|
722
722
|
}
|
|
723
723
|
fetchManifest({ key: n, baseUrl: s }) {
|
|
724
724
|
const r = this.epubLoader.access(n).pipe(
|
|
725
|
-
|
|
726
|
-
|
|
725
|
+
I(({ archive: t, release: a }) => L(
|
|
726
|
+
Ue(t, { baseUrl: s })
|
|
727
727
|
).pipe(
|
|
728
728
|
v(
|
|
729
729
|
(o) => new Response(JSON.stringify(o), {
|
|
@@ -743,8 +743,8 @@ class Be {
|
|
|
743
743
|
resourcePath: s
|
|
744
744
|
}) {
|
|
745
745
|
const r = this.epubLoader.access(n).pipe(
|
|
746
|
-
|
|
747
|
-
|
|
746
|
+
I(({ archive: t, release: a }) => L(
|
|
747
|
+
Ae(t, s)
|
|
748
748
|
).pipe(
|
|
749
749
|
v((o) => new Response(o.body, { status: 200 })),
|
|
750
750
|
H(() => {
|
|
@@ -769,8 +769,8 @@ class tt extends Be {
|
|
|
769
769
|
if (!s) return;
|
|
770
770
|
const r = J(s.baseUrl), t = n.request.url.substring(
|
|
771
771
|
r.length + 1
|
|
772
|
-
), [a = ""] = t.split("/"), i =
|
|
773
|
-
t.substring(a.length + 1)
|
|
772
|
+
), [a = ""] = t.split("/"), i = decodeURIComponent(
|
|
773
|
+
J(t.substring(a.length + 1))
|
|
774
774
|
);
|
|
775
775
|
t.endsWith("/manifest") ? n.respondWith(
|
|
776
776
|
this.fetchManifest({ key: a, baseUrl: `${r}/${a}/` })
|
|
@@ -789,8 +789,8 @@ export {
|
|
|
789
789
|
Qe as createArchiveFromLibArchive,
|
|
790
790
|
Ye as createArchiveFromText,
|
|
791
791
|
qe as createArchiveFromUrls,
|
|
792
|
-
|
|
793
|
-
|
|
792
|
+
Ue as generateManifestFromArchive,
|
|
793
|
+
Ae as generateResourceFromArchive,
|
|
794
794
|
Je as generateResourceFromError,
|
|
795
795
|
T as getArchiveOpfInfo
|
|
796
796
|
};
|