@prose-reader/streamer 1.35.0 → 1.36.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/prose-streamer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { urlJoin as v, PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME as J, isXmlBasedMimeType as q, detectMimeTypeFromName as
|
|
2
|
-
import g from "xmldoc";
|
|
1
|
+
import { urlJoin as v, PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME as J, isXmlBasedMimeType as q, detectMimeTypeFromName as O } from "@prose-reader/shared";
|
|
2
|
+
import g, { XmlDocument as Y } from "xmldoc";
|
|
3
3
|
let b = !1;
|
|
4
4
|
const h = {
|
|
5
5
|
enable: (e) => {
|
|
@@ -24,40 +24,60 @@ const h = {
|
|
|
24
24
|
b && console.timeEnd(`[prose-reader-streamer] [metric] ${e}`);
|
|
25
25
|
},
|
|
26
26
|
metric: (e, i = 1 / 0) => {
|
|
27
|
-
const
|
|
28
|
-
b && (e.duration <= i ? console.log("[prose-reader-streamer] [metric] ", `${e.name} took ${
|
|
27
|
+
const n = typeof e == "number" ? e : e.duration;
|
|
28
|
+
b && (e.duration <= i ? console.log("[prose-reader-streamer] [metric] ", `${e.name} took ${n}ms`) : console.warn(
|
|
29
29
|
"[prose-reader-streamer] [metric] ",
|
|
30
30
|
`${e.name} took ${e.duration}ms which is above the ${i}ms target for this function`
|
|
31
31
|
));
|
|
32
32
|
},
|
|
33
33
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
-
measurePerformance: (e, i = 10,
|
|
35
|
-
const t = performance.now(),
|
|
36
|
-
if (
|
|
37
|
-
return
|
|
34
|
+
measurePerformance: (e, i = 10, n) => (...r) => {
|
|
35
|
+
const t = performance.now(), a = n(...r);
|
|
36
|
+
if (a && a.then)
|
|
37
|
+
return a.then((s) => {
|
|
38
38
|
const d = performance.now();
|
|
39
39
|
return h.metric({ name: e, duration: d - t }, i), s;
|
|
40
40
|
});
|
|
41
41
|
const o = performance.now();
|
|
42
|
-
return h.metric({ name: e, duration: o - t }, i),
|
|
42
|
+
return h.metric({ name: e, duration: o - t }, i), a;
|
|
43
43
|
}
|
|
44
|
-
},
|
|
44
|
+
}, K = (e) => {
|
|
45
|
+
var n;
|
|
46
|
+
const i = (n = e.descendantWithPath("head")) == null ? void 0 : n.childrenNamed("meta").find((r) => r.attr.name === "calibre:cover");
|
|
47
|
+
return !!(i && i.attr.name === "calibre:cover");
|
|
48
|
+
}, Q = (e) => {
|
|
49
|
+
var i, n, r;
|
|
50
|
+
return (r = (n = (i = e.descendantWithPath("body")) == null ? void 0 : i.descendantWithPath("div")) == null ? void 0 : n.childrenNamed("svg")) == null ? void 0 : r.find((t) => t.attr.width === "100%" && t.attr.preserveAspectRatio === "none");
|
|
51
|
+
}, Z = ({ archive: e, resourcePath: i }) => async (n) => {
|
|
52
|
+
const r = Object.values(e.files).find((t) => t.uri === i);
|
|
53
|
+
if (r != null && r.basename.endsWith(".xhtml")) {
|
|
54
|
+
const t = n.body ?? await r.string(), a = new Y(t);
|
|
55
|
+
if (K(a)) {
|
|
56
|
+
const o = Q(a);
|
|
57
|
+
return o && delete o.attr.preserveAspectRatio, {
|
|
58
|
+
...n,
|
|
59
|
+
body: a == null ? void 0 : a.toString()
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return n;
|
|
64
|
+
}, E = ({ archive: e, resourcePath: i }) => async (n) => Z({ archive: e, resourcePath: i })(n), ee = ({ archive: e, resourcePath: i }) => async (n) => {
|
|
45
65
|
const r = Object.values(e.files).find((t) => t.uri === i);
|
|
46
66
|
if (r != null && r.basename.endsWith(".css")) {
|
|
47
|
-
const
|
|
67
|
+
const a = (n.body ?? await r.string()).replaceAll("-webkit-writing-mode", "writing-mode");
|
|
48
68
|
return {
|
|
49
|
-
...
|
|
50
|
-
body:
|
|
69
|
+
...n,
|
|
70
|
+
body: a
|
|
51
71
|
};
|
|
52
72
|
}
|
|
53
|
-
return
|
|
54
|
-
},
|
|
55
|
-
const
|
|
73
|
+
return n;
|
|
74
|
+
}, F = (e) => {
|
|
75
|
+
const n = Object.values(e.files).filter((r) => !r.dir).find((r) => r.uri.endsWith(".opf"));
|
|
56
76
|
return {
|
|
57
|
-
data:
|
|
58
|
-
basePath: (
|
|
77
|
+
data: n,
|
|
78
|
+
basePath: (n == null ? void 0 : n.uri.substring(0, n.uri.lastIndexOf("/"))) || ""
|
|
59
79
|
};
|
|
60
|
-
}, P = (e, { opfBasePath: i, baseUrl:
|
|
80
|
+
}, P = (e, { opfBasePath: i, baseUrl: n }) => {
|
|
61
81
|
const r = {
|
|
62
82
|
contents: [],
|
|
63
83
|
path: "",
|
|
@@ -66,151 +86,151 @@ const h = {
|
|
|
66
86
|
};
|
|
67
87
|
let t = e.childNamed("span") || e.childNamed("a");
|
|
68
88
|
r.title = (t == null ? void 0 : t.attr.title) || (t == null ? void 0 : t.val.trim()) || r.title;
|
|
69
|
-
let
|
|
70
|
-
|
|
89
|
+
let a = t == null ? void 0 : t.name;
|
|
90
|
+
a !== "a" && (t = e.descendantWithPath(`${a}.a`), t && (a = t.name.toLowerCase())), a === "a" && (t != null && t.attr.href) && (r.path = v(i, t.attr.href), r.href = v(n, i, t.attr.href));
|
|
71
91
|
const o = e.childNamed("ol");
|
|
72
92
|
if (o) {
|
|
73
93
|
const s = o.childrenNamed("li");
|
|
74
|
-
s && s.length > 0 && (r.contents = s.map((d) => P(d, { opfBasePath: i, baseUrl:
|
|
94
|
+
s && s.length > 0 && (r.contents = s.map((d) => P(d, { opfBasePath: i, baseUrl: n })));
|
|
75
95
|
}
|
|
76
96
|
return r;
|
|
77
|
-
},
|
|
78
|
-
var
|
|
97
|
+
}, te = (e, { opfBasePath: i, baseUrl: n }) => {
|
|
98
|
+
var a, o;
|
|
79
99
|
const r = [];
|
|
80
100
|
let t;
|
|
81
|
-
return e.descendantWithPath("body.nav.ol") ? t = (
|
|
82
|
-
},
|
|
83
|
-
var
|
|
84
|
-
const t = (
|
|
101
|
+
return e.descendantWithPath("body.nav.ol") ? t = (a = e.descendantWithPath("body.nav.ol")) == null ? void 0 : a.children : e.descendantWithPath("body.section.nav.ol") && (t = (o = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : o.children), t && t.length > 0 && t.filter((s) => s.name === "li").forEach((s) => r.push(P(s, { opfBasePath: i, baseUrl: n }))), r;
|
|
102
|
+
}, ne = async (e, i, { opfBasePath: n, baseUrl: r }) => {
|
|
103
|
+
var a;
|
|
104
|
+
const t = (a = e.childNamed("manifest")) == null ? void 0 : a.childrenNamed("item").find((o) => o.attr.properties === "nav");
|
|
85
105
|
if (t) {
|
|
86
106
|
const o = Object.values(i.files).find((s) => s.uri.endsWith(t.attr.href || ""));
|
|
87
107
|
if (o) {
|
|
88
108
|
const s = new g.XmlDocument(await o.string());
|
|
89
|
-
return
|
|
109
|
+
return te(s, { opfBasePath: n, baseUrl: r });
|
|
90
110
|
}
|
|
91
111
|
}
|
|
92
|
-
},
|
|
112
|
+
}, j = (e, { opfBasePath: i, baseUrl: n, prefix: r }) => {
|
|
93
113
|
var s, d;
|
|
94
|
-
const t = ((s = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : s.attr.src) || "",
|
|
114
|
+
const t = ((s = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : s.attr.src) || "", a = {
|
|
95
115
|
title: ((d = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : d.val) || "",
|
|
96
116
|
path: v(i, t),
|
|
97
|
-
href: v(
|
|
117
|
+
href: v(n, i, t),
|
|
98
118
|
contents: []
|
|
99
119
|
}, o = e.childrenNamed(`${r}navPoint`);
|
|
100
|
-
return o && o.length > 0 && (
|
|
101
|
-
},
|
|
120
|
+
return o && o.length > 0 && (a.contents = o.map((p) => j(p, { opfBasePath: i, baseUrl: n, prefix: r }))), a;
|
|
121
|
+
}, re = (e, { opfBasePath: i, baseUrl: n }) => {
|
|
102
122
|
var o;
|
|
103
123
|
const r = [], t = e.name;
|
|
104
|
-
let
|
|
105
|
-
return t.indexOf(":") !== -1 && (
|
|
106
|
-
},
|
|
124
|
+
let a = "";
|
|
125
|
+
return t.indexOf(":") !== -1 && (a = t.split(":")[0] + ":"), (o = e.childNamed(`${a}navMap`)) == null || o.childrenNamed(`${a}navPoint`).forEach((s) => r.push(j(s, { opfBasePath: i, baseUrl: n, prefix: a }))), r;
|
|
126
|
+
}, ae = async ({
|
|
107
127
|
opfData: e,
|
|
108
128
|
opfBasePath: i,
|
|
109
|
-
baseUrl:
|
|
129
|
+
baseUrl: n,
|
|
110
130
|
archive: r
|
|
111
131
|
}) => {
|
|
112
132
|
var o;
|
|
113
|
-
const t = e.childNamed("spine"),
|
|
114
|
-
if (
|
|
115
|
-
const s = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((d) => d.attr.id ===
|
|
133
|
+
const t = e.childNamed("spine"), a = t && t.attr.toc;
|
|
134
|
+
if (a) {
|
|
135
|
+
const s = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((d) => d.attr.id === a);
|
|
116
136
|
if (s) {
|
|
117
137
|
const d = `${i}${i === "" ? "" : "/"}${s.attr.href}`, p = Object.values(r.files).find((m) => m.uri.endsWith(d));
|
|
118
138
|
if (p) {
|
|
119
139
|
const m = new g.XmlDocument(await p.string());
|
|
120
|
-
return
|
|
140
|
+
return re(m, { opfBasePath: i, baseUrl: n });
|
|
121
141
|
}
|
|
122
142
|
}
|
|
123
143
|
}
|
|
124
|
-
},
|
|
125
|
-
const { basePath: r } =
|
|
144
|
+
}, ie = async (e, i, { baseUrl: n }) => {
|
|
145
|
+
const { basePath: r } = F(i) || {}, t = await ae({
|
|
126
146
|
opfData: e,
|
|
127
147
|
opfBasePath: r,
|
|
128
148
|
archive: i,
|
|
129
|
-
baseUrl:
|
|
149
|
+
baseUrl: n
|
|
130
150
|
});
|
|
131
|
-
return t || await
|
|
132
|
-
},
|
|
151
|
+
return t || await ne(e, i, { opfBasePath: r, baseUrl: n });
|
|
152
|
+
}, oe = async (e) => {
|
|
133
153
|
const i = {
|
|
134
154
|
renditionLayout: void 0
|
|
135
155
|
};
|
|
136
156
|
return await Promise.all(
|
|
137
|
-
e.files.map(async (
|
|
157
|
+
e.files.map(async (n) => {
|
|
138
158
|
var r, t;
|
|
139
|
-
if (
|
|
140
|
-
const o = (r = new g.XmlDocument(await
|
|
159
|
+
if (n.uri.endsWith("com.kobobooks.display-options.xml")) {
|
|
160
|
+
const o = (r = new g.XmlDocument(await n.string()).childNamed("platform")) == null ? void 0 : r.childNamed("option");
|
|
141
161
|
((t = o == null ? void 0 : o.attr) == null ? void 0 : t.name) === "fixed-layout" && o.val === "true" && (i.renditionLayout = "pre-paginated");
|
|
142
162
|
}
|
|
143
163
|
})
|
|
144
164
|
), i;
|
|
145
|
-
},
|
|
146
|
-
const { data: i, basePath:
|
|
165
|
+
}, z = async ({ archive: e }) => {
|
|
166
|
+
const { data: i, basePath: n } = F(e) || {}, r = await (i == null ? void 0 : i.string());
|
|
147
167
|
if (!r)
|
|
148
168
|
return [];
|
|
149
|
-
const t = new g.XmlDocument(r),
|
|
150
|
-
return e.files.filter((m) => d.find((f) =>
|
|
169
|
+
const t = new g.XmlDocument(r), a = t.childNamed("manifest"), o = t.childNamed("spine"), s = o == null ? void 0 : o.childrenNamed("itemref").map((m) => m.attr.idref), d = (a == null ? void 0 : a.childrenNamed("item").filter((m) => s.includes(m.attr.id || ""))) || [];
|
|
170
|
+
return e.files.filter((m) => d.find((f) => n ? `${n}/${f.attr.href}` === m.uri : `${f.attr.href}` === m.uri));
|
|
151
171
|
}, X = (e) => {
|
|
152
|
-
var
|
|
172
|
+
var n;
|
|
153
173
|
const i = e.childNamed("manifest");
|
|
154
|
-
return ((
|
|
174
|
+
return ((n = i == null ? void 0 : i.childrenNamed("item")) == null ? void 0 : n.map((r) => ({
|
|
155
175
|
href: r.attr.href || "",
|
|
156
176
|
id: r.attr.id || "",
|
|
157
177
|
mediaType: r.attr["media-type"]
|
|
158
178
|
}))) || [];
|
|
159
|
-
},
|
|
160
|
-
var
|
|
161
|
-
const { data: r, basePath: t } =
|
|
179
|
+
}, se = ({ archive: e, baseUrl: i }) => async (n) => {
|
|
180
|
+
var D;
|
|
181
|
+
const { data: r, basePath: t } = F(e) || {}, a = await oe(e);
|
|
162
182
|
if (!r)
|
|
163
|
-
return
|
|
183
|
+
return n;
|
|
164
184
|
const o = await r.string();
|
|
165
|
-
h.log(o,
|
|
166
|
-
const s = new g.XmlDocument(o), d = await
|
|
185
|
+
h.log(o, a);
|
|
186
|
+
const s = new g.XmlDocument(o), d = await ie(s, e, { baseUrl: i }) || [], p = s.childNamed("metadata"), m = s.childNamed("manifest"), f = s.childNamed("spine"), x = s.childNamed("guide"), w = p == null ? void 0 : p.childNamed("dc:title"), $ = (p == null ? void 0 : p.childrenNamed("meta")) || [], N = $.find((l) => l.attr.property === "rendition:layout"), T = $.find((l) => l.attr.property === "rendition:flow"), A = $.find((l) => l.attr.property === "rendition:spread"), C = N == null ? void 0 : N.val, B = T == null ? void 0 : T.val, M = A == null ? void 0 : A.val, _ = (w == null ? void 0 : w.val) || ((D = e.files.find(({ dir: l }) => l)) == null ? void 0 : D.basename) || "", H = f == null ? void 0 : f.attr["page-progression-direction"], U = (await z({ archive: e })).reduce((l, c) => c.size + l, 0);
|
|
167
187
|
return {
|
|
168
188
|
filename: e.filename,
|
|
169
189
|
nav: {
|
|
170
190
|
toc: d
|
|
171
191
|
},
|
|
172
|
-
renditionLayout:
|
|
173
|
-
renditionFlow:
|
|
174
|
-
renditionSpread:
|
|
192
|
+
renditionLayout: C || a.renditionLayout || "reflowable",
|
|
193
|
+
renditionFlow: B || "auto",
|
|
194
|
+
renditionSpread: M,
|
|
175
195
|
title: _,
|
|
176
196
|
readingDirection: H || "ltr",
|
|
177
197
|
spineItems: (f == null ? void 0 : f.childrenNamed("itemref").map((l) => {
|
|
178
|
-
var
|
|
179
|
-
const c = m == null ? void 0 : m.childrenNamed("item").find((u) => u.attr.id === (l == null ? void 0 : l.attr.idref)), V = (c == null ? void 0 : c.attr.href) || "",
|
|
198
|
+
var R, L, W;
|
|
199
|
+
const c = m == null ? void 0 : m.childrenNamed("item").find((u) => u.attr.id === (l == null ? void 0 : l.attr.idref)), V = (c == null ? void 0 : c.attr.href) || "", I = ((R = l == null ? void 0 : l.attr.properties) == null ? void 0 : R.split(" ")) || [], G = ((L = e.files.find((u) => u.uri.endsWith(V))) == null ? void 0 : L.size) || 0, S = i ?? "";
|
|
180
200
|
return {
|
|
181
201
|
id: (c == null ? void 0 : c.attr.id) || "",
|
|
182
|
-
href: (
|
|
183
|
-
renditionLayout:
|
|
184
|
-
...
|
|
202
|
+
href: (W = c == null ? void 0 : c.attr.href) != null && W.startsWith("https://") ? c == null ? void 0 : c.attr.href : t ? `${S}${t}/${c == null ? void 0 : c.attr.href}` : `${S}${c == null ? void 0 : c.attr.href}`,
|
|
203
|
+
renditionLayout: C || "reflowable",
|
|
204
|
+
...I.find((u) => u === "rendition:layout-reflowable") && {
|
|
185
205
|
renditionLayout: "reflowable"
|
|
186
206
|
},
|
|
187
207
|
progressionWeight: G / U,
|
|
188
|
-
pageSpreadLeft:
|
|
189
|
-
pageSpreadRight:
|
|
208
|
+
pageSpreadLeft: I.some((u) => u === "page-spread-left") || void 0,
|
|
209
|
+
pageSpreadRight: I.some((u) => u === "page-spread-right") || void 0,
|
|
190
210
|
// size: itemSize
|
|
191
211
|
mediaType: c == null ? void 0 : c.attr["media-type"]
|
|
192
212
|
};
|
|
193
213
|
})) || [],
|
|
194
214
|
items: X(s),
|
|
195
|
-
guide:
|
|
215
|
+
guide: x == null ? void 0 : x.childrenNamed("reference").map((l) => ({
|
|
196
216
|
href: l.attr.href || "",
|
|
197
217
|
title: l.attr.title || "",
|
|
198
218
|
type: l.attr.type
|
|
199
219
|
}))
|
|
200
220
|
};
|
|
201
|
-
},
|
|
202
|
-
var t,
|
|
203
|
-
const r = await ((t =
|
|
221
|
+
}, ce = async (e, i) => {
|
|
222
|
+
var t, a;
|
|
223
|
+
const r = await ((t = F(e).data) == null ? void 0 : t.string());
|
|
204
224
|
if (r) {
|
|
205
225
|
const o = new g.XmlDocument(r);
|
|
206
226
|
return {
|
|
207
|
-
mediaType: (
|
|
227
|
+
mediaType: (a = X(o).find((d) => i.endsWith(d.href))) == null ? void 0 : a.mediaType
|
|
208
228
|
};
|
|
209
229
|
}
|
|
210
230
|
return {
|
|
211
|
-
mediaType:
|
|
231
|
+
mediaType: de(i)
|
|
212
232
|
};
|
|
213
|
-
},
|
|
233
|
+
}, de = (e) => {
|
|
214
234
|
if (e.endsWith(".css"))
|
|
215
235
|
return "text/css; charset=UTF-8";
|
|
216
236
|
if (e.endsWith(".jpg"))
|
|
@@ -221,15 +241,15 @@ const h = {
|
|
|
221
241
|
return "video/mp4";
|
|
222
242
|
if (e.endsWith(".svg"))
|
|
223
243
|
return "image/svg+xml";
|
|
224
|
-
},
|
|
225
|
-
const r = Object.values(e.files).find((
|
|
244
|
+
}, le = ({ archive: e, resourcePath: i }) => async (n) => {
|
|
245
|
+
const r = Object.values(e.files).find((a) => a.uri === i);
|
|
226
246
|
if (!r)
|
|
227
|
-
return
|
|
228
|
-
const t = await
|
|
247
|
+
return n;
|
|
248
|
+
const t = await ce(e, i);
|
|
229
249
|
return {
|
|
230
|
-
...
|
|
250
|
+
...n,
|
|
231
251
|
params: {
|
|
232
|
-
...
|
|
252
|
+
...n.params,
|
|
233
253
|
status: 200,
|
|
234
254
|
headers: {
|
|
235
255
|
...(r == null ? void 0 : r.encodingFormat) && {
|
|
@@ -241,25 +261,29 @@ const h = {
|
|
|
241
261
|
}
|
|
242
262
|
}
|
|
243
263
|
};
|
|
244
|
-
},
|
|
245
|
-
const
|
|
246
|
-
if (!
|
|
264
|
+
}, Fe = async (e, i) => {
|
|
265
|
+
const n = Object.values(e.files).find((a) => a.uri === i);
|
|
266
|
+
if (!n)
|
|
247
267
|
throw new Error("no file found");
|
|
248
268
|
const r = {
|
|
249
269
|
params: {
|
|
250
270
|
status: 200
|
|
251
271
|
}
|
|
252
|
-
}, t = [
|
|
272
|
+
}, t = [
|
|
273
|
+
le({ archive: e, resourcePath: i }),
|
|
274
|
+
ee({ archive: e, resourcePath: i }),
|
|
275
|
+
E({ archive: e, resourcePath: i })
|
|
276
|
+
];
|
|
253
277
|
try {
|
|
254
|
-
const
|
|
255
|
-
return h.log("Generated resource", i,
|
|
256
|
-
...
|
|
257
|
-
body:
|
|
278
|
+
const a = await t.reduce(async (o, s) => await s(await o), Promise.resolve(r));
|
|
279
|
+
return h.log("Generated resource", i, a), {
|
|
280
|
+
...a,
|
|
281
|
+
body: a.body || await n.blob()
|
|
258
282
|
};
|
|
259
|
-
} catch (
|
|
260
|
-
throw h.error(
|
|
283
|
+
} catch (a) {
|
|
284
|
+
throw h.error(a), a;
|
|
261
285
|
}
|
|
262
|
-
},
|
|
286
|
+
}, $e = (e) => ({
|
|
263
287
|
body: `
|
|
264
288
|
<!DOCTYPE html>
|
|
265
289
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
|
|
@@ -277,99 +301,99 @@ const h = {
|
|
|
277
301
|
"Content-Type": "text/html;charset=UTF-8"
|
|
278
302
|
}
|
|
279
303
|
}
|
|
280
|
-
}),
|
|
304
|
+
}), me = ({ archive: e, baseUrl: i }) => async () => {
|
|
281
305
|
var r;
|
|
282
|
-
const
|
|
306
|
+
const n = Object.values(e.files).filter((t) => !t.dir);
|
|
283
307
|
return {
|
|
284
308
|
filename: e.filename,
|
|
285
309
|
title: ((r = e.files.find(({ dir: t }) => t)) == null ? void 0 : r.basename.replace(/\/$/, "")) || "",
|
|
286
310
|
renditionLayout: "pre-paginated",
|
|
287
311
|
renditionSpread: "auto",
|
|
288
312
|
readingDirection: "ltr",
|
|
289
|
-
spineItems:
|
|
313
|
+
spineItems: n.map((t, a) => ({
|
|
290
314
|
// some books such as cbz can have same basename inside different sub folder
|
|
291
315
|
// we need to make sure to have unique index
|
|
292
316
|
// /chap01/01.png, /chap02/01.png, etc
|
|
293
|
-
id: `${
|
|
317
|
+
id: `${a}.${t.basename}`,
|
|
294
318
|
href: encodeURI(`${i}${t.uri}`),
|
|
295
319
|
renditionLayout: "pre-paginated",
|
|
296
|
-
progressionWeight: 1 /
|
|
320
|
+
progressionWeight: 1 / n.length,
|
|
297
321
|
pageSpreadLeft: void 0,
|
|
298
322
|
pageSpreadRight: void 0,
|
|
299
323
|
mediaType: t.encodingFormat
|
|
300
324
|
})),
|
|
301
|
-
items:
|
|
302
|
-
id: `${
|
|
325
|
+
items: n.map((t, a) => ({
|
|
326
|
+
id: `${a}.${t.basename}`,
|
|
303
327
|
href: `${i}${t.uri}`
|
|
304
328
|
}))
|
|
305
329
|
};
|
|
306
|
-
},
|
|
330
|
+
}, pe = ({ archive: e, baseUrl: i }) => async (n) => {
|
|
307
331
|
var s;
|
|
308
332
|
const r = e.files.find((d) => d.basename.toLowerCase() === "comicinfo.xml");
|
|
309
333
|
if (!r)
|
|
310
|
-
return
|
|
334
|
+
return n;
|
|
311
335
|
const t = await r.string(), o = ((s = new g.XmlDocument(t).childNamed("Manga")) == null ? void 0 : s.val) || "unknown";
|
|
312
336
|
return {
|
|
313
|
-
...
|
|
314
|
-
spineItems:
|
|
337
|
+
...n,
|
|
338
|
+
spineItems: n.spineItems.filter((d) => d.id.toLowerCase() !== "comicinfo.xml"),
|
|
315
339
|
readingDirection: o === "YesAndRightToLeft" ? "rtl" : "ltr"
|
|
316
340
|
};
|
|
317
|
-
},
|
|
318
|
-
var
|
|
319
|
-
const i = (
|
|
341
|
+
}, fe = (e) => {
|
|
342
|
+
var n;
|
|
343
|
+
const i = (n = e.descendantWithPath("head")) == null ? void 0 : n.childrenNamed("meta").find((r) => r.attr.name === "viewport");
|
|
320
344
|
return !!(i && i.attr.name === "viewport");
|
|
321
|
-
},
|
|
345
|
+
}, ue = (e) => e.reduce(async (i, n) => {
|
|
322
346
|
if (!await i || !q({
|
|
323
|
-
mimeType:
|
|
324
|
-
uri:
|
|
347
|
+
mimeType: n.encodingFormat,
|
|
348
|
+
uri: n.uri
|
|
325
349
|
}))
|
|
326
350
|
return !1;
|
|
327
|
-
const t = await
|
|
328
|
-
return t ?
|
|
329
|
-
}, Promise.resolve(!0)),
|
|
330
|
-
if (
|
|
331
|
-
const t = await
|
|
332
|
-
if (await
|
|
351
|
+
const t = await n.string();
|
|
352
|
+
return t ? fe(new g.XmlDocument(t)) : !1;
|
|
353
|
+
}, Promise.resolve(!0)), he = ({ archive: e, baseUrl: i }) => async (n) => {
|
|
354
|
+
if (n.renditionLayout === "reflowable" && n.spineItems.every((t) => t.renditionLayout === "reflowable")) {
|
|
355
|
+
const t = await z({ archive: e });
|
|
356
|
+
if (await ue(t))
|
|
333
357
|
return {
|
|
334
|
-
...
|
|
335
|
-
spineItems:
|
|
358
|
+
...n,
|
|
359
|
+
spineItems: n.spineItems.map((o) => ({
|
|
336
360
|
...o,
|
|
337
361
|
renditionLayout: "pre-paginated"
|
|
338
362
|
})),
|
|
339
363
|
renditionLayout: "pre-paginated"
|
|
340
364
|
};
|
|
341
365
|
}
|
|
342
|
-
return
|
|
366
|
+
return n;
|
|
343
367
|
}, k = (e, i) => {
|
|
344
368
|
var t;
|
|
345
|
-
const
|
|
346
|
-
for (let
|
|
347
|
-
if (a
|
|
348
|
-
return (t = a
|
|
369
|
+
const n = e.split(/(\d+)/), r = i.split(/(\d+)/);
|
|
370
|
+
for (let a = 0, o = n.length; a < o; a++)
|
|
371
|
+
if (n[a] !== r[a])
|
|
372
|
+
return (t = n[a]) != null && t.match(/\d/) ? +(n[a] || "") - +(r[a] || "") : (n[a] || "").localeCompare(r[a] || "");
|
|
349
373
|
return 1;
|
|
350
|
-
},
|
|
351
|
-
if (
|
|
352
|
-
return
|
|
353
|
-
const r = [...e.files].sort((
|
|
374
|
+
}, ge = ({ archive: e, baseUrl: i }) => async (n) => {
|
|
375
|
+
if (n.nav)
|
|
376
|
+
return n;
|
|
377
|
+
const r = [...e.files].sort((a, o) => k(a.uri, o.uri)), t = Object.values(r).reduce((a, o) => {
|
|
354
378
|
const s = o.uri.split("/");
|
|
355
379
|
return !o.dir && s.length > 1 && s.forEach((p, m) => {
|
|
356
380
|
if (m === s.length - 1)
|
|
357
381
|
return;
|
|
358
|
-
|
|
382
|
+
a.find(({ title: w }) => w === p) || a.push({
|
|
359
383
|
contents: [],
|
|
360
384
|
href: v(i, encodeURI(o.uri)).replace(/\/$/, ""),
|
|
361
385
|
path: o.uri.replace(/\/$/, ""),
|
|
362
386
|
title: s[0] ?? ""
|
|
363
387
|
});
|
|
364
|
-
}),
|
|
388
|
+
}), a;
|
|
365
389
|
}, []);
|
|
366
|
-
return t.length === 0 ?
|
|
367
|
-
...
|
|
390
|
+
return t.length === 0 ? n : {
|
|
391
|
+
...n,
|
|
368
392
|
nav: {
|
|
369
393
|
toc: t
|
|
370
394
|
}
|
|
371
395
|
};
|
|
372
|
-
},
|
|
396
|
+
}, ye = {
|
|
373
397
|
filename: "",
|
|
374
398
|
items: [],
|
|
375
399
|
nav: {
|
|
@@ -380,41 +404,41 @@ const h = {
|
|
|
380
404
|
renditionSpread: "auto",
|
|
381
405
|
spineItems: [],
|
|
382
406
|
title: ""
|
|
383
|
-
},
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
ne({ archive: e, baseUrl: i }),
|
|
387
|
-
le({ archive: e, baseUrl: i }),
|
|
407
|
+
}, Ne = async (e, { baseUrl: i = "" } = {}) => {
|
|
408
|
+
const n = [
|
|
409
|
+
me({ archive: e, baseUrl: i }),
|
|
388
410
|
se({ archive: e, baseUrl: i }),
|
|
389
|
-
|
|
411
|
+
he({ archive: e, baseUrl: i }),
|
|
412
|
+
pe({ archive: e, baseUrl: i }),
|
|
413
|
+
ge({ archive: e, baseUrl: i })
|
|
390
414
|
];
|
|
391
415
|
try {
|
|
392
|
-
const r = await
|
|
416
|
+
const r = await n.reduce(async (t, a) => await a(await t), Promise.resolve(ye));
|
|
393
417
|
return h.log("Generated manifest", r), r;
|
|
394
418
|
} catch (r) {
|
|
395
419
|
throw h.error(r), r;
|
|
396
420
|
}
|
|
397
|
-
}, y = (e) => e.substring(e.lastIndexOf("/") + 1) || e,
|
|
398
|
-
const
|
|
421
|
+
}, y = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Te = async (e, i) => {
|
|
422
|
+
const n = `
|
|
399
423
|
<?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
|
|
400
424
|
<metadata>
|
|
401
425
|
<meta property="rendition:layout">${i != null && i.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
|
|
402
426
|
${i != null && i.useRenditionFlow ? '<meta property="rendition:flow">scrolled-continuous</meta>' : ""}
|
|
403
427
|
</metadata>
|
|
404
428
|
<manifest>
|
|
405
|
-
${e.map((
|
|
429
|
+
${e.map((a) => `<item id="${y(a)}" href="${a}" media-type="${O(a)}"/>`).join(`
|
|
406
430
|
`)}
|
|
407
431
|
</manifest>
|
|
408
432
|
<spine>
|
|
409
|
-
${e.map((
|
|
433
|
+
${e.map((a) => `<itemref idref="${y(a)}" />`).join(`
|
|
410
434
|
`)}
|
|
411
435
|
</spine>
|
|
412
436
|
</package>
|
|
413
|
-
`, r = e.map((
|
|
437
|
+
`, r = e.map((a) => ({
|
|
414
438
|
dir: !1,
|
|
415
|
-
basename: y(
|
|
416
|
-
encodingFormat:
|
|
417
|
-
uri:
|
|
439
|
+
basename: y(a),
|
|
440
|
+
encodingFormat: O(a),
|
|
441
|
+
uri: a,
|
|
418
442
|
size: 100 / e.length,
|
|
419
443
|
base64: async () => "",
|
|
420
444
|
blob: async () => new Blob(),
|
|
@@ -427,20 +451,20 @@ const h = {
|
|
|
427
451
|
basename: "content.opf",
|
|
428
452
|
uri: "content.opf",
|
|
429
453
|
size: 0,
|
|
430
|
-
base64: async () =>
|
|
454
|
+
base64: async () => n,
|
|
431
455
|
blob: async () => new Blob(),
|
|
432
|
-
string: async () =>
|
|
456
|
+
string: async () => n
|
|
433
457
|
}, ...r]
|
|
434
458
|
};
|
|
435
|
-
},
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
const r =
|
|
459
|
+
}, be = async (e) => new Promise((i) => {
|
|
460
|
+
const n = new FileReader();
|
|
461
|
+
n.readAsDataURL(e), n.onloadend = function() {
|
|
462
|
+
const r = n.result;
|
|
439
463
|
i(r);
|
|
440
464
|
};
|
|
441
|
-
}),
|
|
465
|
+
}), Ae = async (e, {
|
|
442
466
|
mimeType: i,
|
|
443
|
-
direction:
|
|
467
|
+
direction: n
|
|
444
468
|
} = { mimeType: "text/plain" }) => {
|
|
445
469
|
const r = `
|
|
446
470
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -453,7 +477,7 @@ const h = {
|
|
|
453
477
|
<manifest>
|
|
454
478
|
<item id="p01" href="p01.txt" media-type="text/plain"/>
|
|
455
479
|
</manifest>
|
|
456
|
-
<spine page-progression-direction="${
|
|
480
|
+
<spine page-progression-direction="${n ?? "ltr"}">
|
|
457
481
|
<itemref idref="p01" />
|
|
458
482
|
</spine>
|
|
459
483
|
</package>
|
|
@@ -476,63 +500,63 @@ const h = {
|
|
|
476
500
|
uri: "p01.txt",
|
|
477
501
|
blob: async () => typeof e == "string" ? new Blob([e]) : e,
|
|
478
502
|
string: async () => typeof e == "string" ? e : e.text(),
|
|
479
|
-
base64: async () => typeof e == "string" ? btoa(e) :
|
|
503
|
+
base64: async () => typeof e == "string" ? btoa(e) : be(e),
|
|
480
504
|
size: typeof e == "string" ? e.length : e.size,
|
|
481
505
|
encodingFormat: i
|
|
482
506
|
}
|
|
483
507
|
]
|
|
484
508
|
};
|
|
485
|
-
},
|
|
509
|
+
}, Ie = async (e, { orderByAlpha: i, name: n } = {}) => {
|
|
486
510
|
let r = Object.values(e.files);
|
|
487
|
-
i && (r = r.sort((
|
|
511
|
+
i && (r = r.sort((a, o) => k(a.name, o.name)));
|
|
488
512
|
const t = {
|
|
489
|
-
filename:
|
|
490
|
-
files: r.map((
|
|
491
|
-
dir:
|
|
492
|
-
basename: y(
|
|
493
|
-
uri:
|
|
494
|
-
blob: () =>
|
|
495
|
-
string: () =>
|
|
496
|
-
base64: () =>
|
|
497
|
-
...
|
|
498
|
-
stream:
|
|
513
|
+
filename: n || "",
|
|
514
|
+
files: r.map((a) => ({
|
|
515
|
+
dir: a.dir,
|
|
516
|
+
basename: y(a.name),
|
|
517
|
+
uri: a.name,
|
|
518
|
+
blob: () => a.async("blob"),
|
|
519
|
+
string: () => a.async("string"),
|
|
520
|
+
base64: () => a.async("base64"),
|
|
521
|
+
...a.internalStream && {
|
|
522
|
+
stream: a.internalStream
|
|
499
523
|
},
|
|
500
524
|
// this is private API
|
|
501
525
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
502
526
|
// @ts-ignore
|
|
503
|
-
size:
|
|
527
|
+
size: a._data.uncompressedSize
|
|
504
528
|
}))
|
|
505
529
|
};
|
|
506
530
|
return h.log("Generated archive", t), t;
|
|
507
|
-
},
|
|
531
|
+
}, ke = async (e, { orderByAlpha: i, name: n } = {}) => {
|
|
508
532
|
let r = e;
|
|
509
|
-
return i && (r = r.sort((t,
|
|
510
|
-
filename:
|
|
533
|
+
return i && (r = r.sort((t, a) => k(t.name, a.name))), {
|
|
534
|
+
filename: n || "",
|
|
511
535
|
files: r.map((t) => ({
|
|
512
536
|
dir: t.isDir,
|
|
513
537
|
basename: y(t.name),
|
|
514
538
|
uri: t.name,
|
|
515
539
|
blob: async () => new Blob([await t.data()]),
|
|
516
540
|
string: async () => {
|
|
517
|
-
const
|
|
518
|
-
return String.fromCharCode.apply(null, Array.from(new Uint16Array(
|
|
541
|
+
const a = await t.data();
|
|
542
|
+
return String.fromCharCode.apply(null, Array.from(new Uint16Array(a)));
|
|
519
543
|
},
|
|
520
544
|
base64: async () => "",
|
|
521
545
|
size: t.size
|
|
522
546
|
}))
|
|
523
547
|
};
|
|
524
|
-
},
|
|
548
|
+
}, Ce = ({ enableReport: e } = {}) => {
|
|
525
549
|
h.enable(!!e);
|
|
526
550
|
};
|
|
527
551
|
export {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
552
|
+
Ce as configure,
|
|
553
|
+
ke as createArchiveFromArrayBufferList,
|
|
554
|
+
Ie as createArchiveFromJszip,
|
|
555
|
+
Ae as createArchiveFromText,
|
|
556
|
+
Te as createArchiveFromUrls,
|
|
557
|
+
Ne as generateManifestFromArchive,
|
|
558
|
+
Fe as generateResourceFromArchive,
|
|
559
|
+
$e as generateResourceFromError,
|
|
560
|
+
F as getArchiveOpfInfo
|
|
537
561
|
};
|
|
538
562
|
//# sourceMappingURL=prose-streamer.js.map
|