@prose-reader/streamer 1.3.0 → 1.4.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/archives/createArchiveFromText.d.ts +3 -2
- package/dist/archives/getArchiveOpfInfo.d.ts +1 -1
- package/dist/archives/types.d.ts +1 -1
- package/dist/configure.d.ts +3 -0
- package/dist/epub/getSpineItemFilesFromArchive.d.ts +1 -1
- package/dist/generators/manifest/{comicInfo.d.ts → hooks/comicInfo.d.ts} +2 -2
- package/dist/generators/manifest/{default.d.ts → hooks/default.d.ts} +2 -2
- package/dist/generators/manifest/{epub.d.ts → hooks/epub.d.ts} +2 -2
- package/dist/generators/manifest/hooks/epubOptimizer.d.ts +6 -0
- package/dist/generators/manifest/index.d.ts +3 -2
- package/dist/generators/resources.d.ts +8 -1
- package/dist/index.d.ts +5 -7
- package/dist/prose-streamer.js +207 -182
- package/dist/prose-streamer.js.map +1 -1
- package/dist/prose-streamer.umd.cjs +8 -8
- package/dist/prose-streamer.umd.cjs.map +1 -1
- package/package.json +3 -3
package/dist/prose-streamer.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const O = (e, { opfBasePath: n, baseUrl: i }) => {
|
|
1
|
+
import h from "xmldoc";
|
|
2
|
+
import { isXmlBasedMimeType as G, detectMimeTypeFromName as W } from "@prose-reader/shared";
|
|
3
|
+
const z = (e, { opfBasePath: a, baseUrl: i }) => {
|
|
5
4
|
const r = {
|
|
6
5
|
contents: [],
|
|
7
6
|
path: "",
|
|
@@ -10,119 +9,119 @@ const O = (e, { opfBasePath: n, baseUrl: i }) => {
|
|
|
10
9
|
};
|
|
11
10
|
let t = e.childNamed("span") || e.childNamed("a");
|
|
12
11
|
r.title = (t == null ? void 0 : t.attr.title) || (t == null ? void 0 : t.val.trim()) || r.title;
|
|
13
|
-
let
|
|
14
|
-
|
|
12
|
+
let n = t == null ? void 0 : t.name;
|
|
13
|
+
n !== "a" && (t = e.descendantWithPath(`${n}.a`), t && (n = t.name.toLowerCase())), n === "a" && (t != null && t.attr.href) && (r.path = a ? `${a}/${t.attr.href}` : `${t.attr.href}`, r.href = a ? `${i}/${a}/${t.attr.href}` : `${i}/${t.attr.href}`);
|
|
15
14
|
const o = e.childNamed("ol");
|
|
16
15
|
if (o) {
|
|
17
16
|
const s = o.childrenNamed("li");
|
|
18
|
-
s && s.length > 0 && (r.contents = s.map((d) =>
|
|
17
|
+
s && s.length > 0 && (r.contents = s.map((d) => z(d, { opfBasePath: a, baseUrl: i })));
|
|
19
18
|
}
|
|
20
19
|
return r;
|
|
21
|
-
}, J = (e, { opfBasePath:
|
|
22
|
-
var
|
|
20
|
+
}, J = (e, { opfBasePath: a, baseUrl: i }) => {
|
|
21
|
+
var n, o;
|
|
23
22
|
const r = [];
|
|
24
23
|
let t;
|
|
25
|
-
return e.descendantWithPath("body.nav.ol") ? t = (
|
|
26
|
-
},
|
|
27
|
-
var
|
|
28
|
-
const t = (
|
|
24
|
+
return e.descendantWithPath("body.nav.ol") ? t = (n = e.descendantWithPath("body.nav.ol")) == null ? void 0 : n.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(z(s, { opfBasePath: a, baseUrl: i }))), r;
|
|
25
|
+
}, K = async (e, a, { opfBasePath: i, baseUrl: r }) => {
|
|
26
|
+
var n;
|
|
27
|
+
const t = (n = e.childNamed("manifest")) == null ? void 0 : n.childrenNamed("item").find((o) => o.attr.properties === "nav");
|
|
29
28
|
if (t) {
|
|
30
|
-
const o = Object.values(
|
|
29
|
+
const o = Object.values(a.files).find((s) => s.uri.endsWith(t.attr.href || ""));
|
|
31
30
|
if (o) {
|
|
32
|
-
const s = new
|
|
31
|
+
const s = new h.XmlDocument(await o.string());
|
|
33
32
|
return J(s, { opfBasePath: i, baseUrl: r });
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
|
-
},
|
|
35
|
+
}, O = (e, { opfBasePath: a, baseUrl: i, prefix: r }) => {
|
|
37
36
|
var s, d;
|
|
38
|
-
const t = ((s = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : s.attr.src) || "",
|
|
37
|
+
const t = ((s = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : s.attr.src) || "", n = {
|
|
39
38
|
title: ((d = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : d.val) || "",
|
|
40
|
-
path:
|
|
41
|
-
href:
|
|
39
|
+
path: a ? `${a}/${t}` : `${t}`,
|
|
40
|
+
href: a ? `${i}/${a}/${t}` : `${i}/${t}`,
|
|
42
41
|
contents: []
|
|
43
42
|
}, o = e.childrenNamed(`${r}navPoint`);
|
|
44
|
-
return o && o.length > 0 && (
|
|
45
|
-
},
|
|
43
|
+
return o && o.length > 0 && (n.contents = o.map((f) => O(f, { opfBasePath: a, baseUrl: i, prefix: r }))), n;
|
|
44
|
+
}, U = (e, { opfBasePath: a, baseUrl: i }) => {
|
|
46
45
|
var o;
|
|
47
46
|
const r = [], t = e.name;
|
|
48
|
-
let
|
|
49
|
-
return t.indexOf(":") !== -1 && (
|
|
50
|
-
},
|
|
47
|
+
let n = "";
|
|
48
|
+
return t.indexOf(":") !== -1 && (n = t.split(":")[0] + ":"), (o = e.childNamed(`${n}navMap`)) == null || o.childrenNamed(`${n}navPoint`).forEach((s) => r.push(O(s, { opfBasePath: a, baseUrl: i, prefix: n }))), r;
|
|
49
|
+
}, Y = async ({
|
|
51
50
|
opfData: e,
|
|
52
|
-
opfBasePath:
|
|
51
|
+
opfBasePath: a,
|
|
53
52
|
baseUrl: i,
|
|
54
53
|
archive: r
|
|
55
54
|
}) => {
|
|
56
55
|
var o;
|
|
57
|
-
const t = e.childNamed("spine"),
|
|
58
|
-
if (
|
|
59
|
-
const s = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((d) => d.attr.id ===
|
|
56
|
+
const t = e.childNamed("spine"), n = t && t.attr.toc;
|
|
57
|
+
if (n) {
|
|
58
|
+
const s = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((d) => d.attr.id === n);
|
|
60
59
|
if (s) {
|
|
61
|
-
const d = `${
|
|
62
|
-
if (
|
|
63
|
-
const m = new
|
|
64
|
-
return
|
|
60
|
+
const d = `${a}${a === "" ? "" : "/"}${s.attr.href}`, f = Object.values(r.files).find((m) => m.uri.endsWith(d));
|
|
61
|
+
if (f) {
|
|
62
|
+
const m = new h.XmlDocument(await f.string());
|
|
63
|
+
return U(m, { opfBasePath: a, baseUrl: i });
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
|
-
},
|
|
69
|
-
const { basePath: r } = w(
|
|
67
|
+
}, Q = async (e, a, { baseUrl: i }) => {
|
|
68
|
+
const { basePath: r } = w(a) || {}, t = await Y({
|
|
70
69
|
opfData: e,
|
|
71
70
|
opfBasePath: r,
|
|
72
|
-
archive:
|
|
71
|
+
archive: a,
|
|
73
72
|
baseUrl: i
|
|
74
73
|
});
|
|
75
|
-
return t || await
|
|
76
|
-
},
|
|
77
|
-
const
|
|
74
|
+
return t || await K(e, a, { opfBasePath: r, baseUrl: i });
|
|
75
|
+
}, Z = async (e) => {
|
|
76
|
+
const a = {
|
|
78
77
|
renditionLayout: void 0
|
|
79
78
|
};
|
|
80
79
|
return await Promise.all(
|
|
81
80
|
e.files.map(async (i) => {
|
|
82
81
|
var r, t;
|
|
83
82
|
if (i.uri.endsWith("com.kobobooks.display-options.xml")) {
|
|
84
|
-
const o = (r = new
|
|
85
|
-
((t = o == null ? void 0 : o.attr) == null ? void 0 : t.name) === "fixed-layout" && o.val === "true" && (
|
|
83
|
+
const o = (r = new h.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : r.childNamed("option");
|
|
84
|
+
((t = o == null ? void 0 : o.attr) == null ? void 0 : t.name) === "fixed-layout" && o.val === "true" && (a.renditionLayout = "pre-paginated");
|
|
86
85
|
}
|
|
87
86
|
})
|
|
88
|
-
),
|
|
87
|
+
), a;
|
|
89
88
|
};
|
|
90
|
-
let
|
|
91
|
-
const
|
|
89
|
+
let b = !1;
|
|
90
|
+
const y = {
|
|
92
91
|
enable: (e) => {
|
|
93
|
-
|
|
92
|
+
b = e;
|
|
94
93
|
},
|
|
95
94
|
log: (...e) => {
|
|
96
|
-
|
|
95
|
+
b && console.log("[prose-reader-streamer]", ...e);
|
|
97
96
|
},
|
|
98
97
|
warn: (...e) => {
|
|
99
|
-
|
|
98
|
+
b && console.warn("[prose-reader-streamer]", ...e);
|
|
100
99
|
},
|
|
101
100
|
error: (...e) => {
|
|
102
101
|
console.error(...e);
|
|
103
102
|
},
|
|
104
103
|
time: (e) => {
|
|
105
|
-
|
|
104
|
+
b && console.time(`[prose-reader-streamer] [metric] ${e}`);
|
|
106
105
|
},
|
|
107
106
|
timeEnd: (e) => {
|
|
108
|
-
|
|
107
|
+
b && console.timeEnd(`[prose-reader-streamer] [metric] ${e}`);
|
|
109
108
|
},
|
|
110
|
-
metric: (e,
|
|
109
|
+
metric: (e, a = 1 / 0) => {
|
|
111
110
|
const i = typeof e == "number" ? e : e.duration;
|
|
112
|
-
|
|
111
|
+
b && (e.duration <= a ? console.log("[prose-reader-streamer] [metric] ", `${e.name} took ${i}ms`) : console.warn(
|
|
113
112
|
"[prose-reader-streamer] [metric] ",
|
|
114
|
-
`${e.name} took ${e.duration}ms which is above the ${
|
|
113
|
+
`${e.name} took ${e.duration}ms which is above the ${a}ms target for this function`
|
|
115
114
|
));
|
|
116
115
|
},
|
|
117
|
-
measurePerformance: (e,
|
|
118
|
-
const t = performance.now(),
|
|
119
|
-
if (
|
|
120
|
-
return
|
|
116
|
+
measurePerformance: (e, a = 10, i) => (...r) => {
|
|
117
|
+
const t = performance.now(), n = i(...r);
|
|
118
|
+
if (n && n.then)
|
|
119
|
+
return n.then((s) => {
|
|
121
120
|
const d = performance.now();
|
|
122
|
-
return
|
|
121
|
+
return y.metric({ name: e, duration: d - t }, a), s;
|
|
123
122
|
});
|
|
124
123
|
const o = performance.now();
|
|
125
|
-
return
|
|
124
|
+
return y.metric({ name: e, duration: o - t }, a), n;
|
|
126
125
|
}
|
|
127
126
|
}, w = (e) => {
|
|
128
127
|
const i = Object.values(e.files).filter((r) => !r.dir).find((r) => r.uri.endsWith(".opf"));
|
|
@@ -130,93 +129,95 @@ const b = {
|
|
|
130
129
|
data: i,
|
|
131
130
|
basePath: (i == null ? void 0 : i.uri.substring(0, i.uri.lastIndexOf("/"))) || ""
|
|
132
131
|
};
|
|
133
|
-
},
|
|
134
|
-
const { data:
|
|
132
|
+
}, X = async ({ archive: e }) => {
|
|
133
|
+
const { data: a, basePath: i } = w(e) || {}, r = await (a == null ? void 0 : a.string());
|
|
135
134
|
if (!r)
|
|
136
135
|
return [];
|
|
137
|
-
const t = new
|
|
138
|
-
return e.files.filter((m) => d.find((
|
|
139
|
-
},
|
|
136
|
+
const t = new h.XmlDocument(r), n = t.childNamed("manifest"), o = t.childNamed("spine"), s = o == null ? void 0 : o.childrenNamed("itemref").map((m) => m.attr.idref), d = (n == null ? void 0 : n.childrenNamed("item").filter((m) => s.includes(m.attr.id || ""))) || [];
|
|
137
|
+
return e.files.filter((m) => d.find((p) => i ? `${i}/${p.attr.href}` === m.uri : `${p.attr.href}` === m.uri));
|
|
138
|
+
}, P = (e) => {
|
|
140
139
|
var i;
|
|
141
|
-
const
|
|
142
|
-
return ((i =
|
|
140
|
+
const a = e.childNamed("manifest");
|
|
141
|
+
return ((i = a == null ? void 0 : a.childrenNamed("item")) == null ? void 0 : i.map((r) => ({
|
|
143
142
|
href: r.attr.href || "",
|
|
144
143
|
id: r.attr.id || "",
|
|
145
144
|
mediaType: r.attr["media-type"]
|
|
146
145
|
}))) || [];
|
|
147
|
-
},
|
|
148
|
-
var
|
|
149
|
-
const { data: r, basePath: t } = w(e) || {},
|
|
146
|
+
}, E = ({ archive: e, baseUrl: a }) => async (i) => {
|
|
147
|
+
var A;
|
|
148
|
+
const { data: r, basePath: t } = w(e) || {}, n = await Z(e);
|
|
150
149
|
if (!r)
|
|
151
150
|
return i;
|
|
152
151
|
const o = await r.string();
|
|
153
|
-
|
|
154
|
-
const s = new
|
|
152
|
+
y.log(o, n);
|
|
153
|
+
const s = new h.XmlDocument(o), d = await Q(s, e, { baseUrl: a }) || [], f = s.childNamed("metadata"), m = s.childNamed("manifest"), p = s.childNamed("spine"), $ = s.childNamed("guide"), v = f == null ? void 0 : f.childNamed("dc:title"), x = (f == null ? void 0 : f.childrenNamed("meta")) || [], F = x.find((l) => l.attr.property === "rendition:layout"), N = x.find((l) => l.attr.property === "rendition:flow"), T = x.find((l) => l.attr.property === "rendition:spread"), L = F == null ? void 0 : F.val, R = N == null ? void 0 : N.val, M = T == null ? void 0 : T.val, H = (v == null ? void 0 : v.val) || ((A = e.files.find(({ dir: l }) => l)) == null ? void 0 : A.basename) || "", V = p == null ? void 0 : p.attr["page-progression-direction"], B = (await X({ archive: e })).reduce((l, c) => c.size + l, 0);
|
|
155
154
|
return {
|
|
156
155
|
filename: e.filename,
|
|
157
156
|
nav: {
|
|
158
157
|
toc: d
|
|
159
158
|
},
|
|
160
|
-
renditionLayout:
|
|
159
|
+
renditionLayout: L || n.renditionLayout || "reflowable",
|
|
161
160
|
renditionFlow: R || "auto",
|
|
162
|
-
renditionSpread:
|
|
163
|
-
title:
|
|
164
|
-
readingDirection:
|
|
165
|
-
spineItems: (
|
|
166
|
-
var
|
|
167
|
-
const c = m == null ? void 0 : m.childrenNamed("item").find((u) => u.attr.id === (l == null ? void 0 : l.attr.idref)),
|
|
161
|
+
renditionSpread: M,
|
|
162
|
+
title: H,
|
|
163
|
+
readingDirection: V || "ltr",
|
|
164
|
+
spineItems: (p == null ? void 0 : p.childrenNamed("itemref").map((l) => {
|
|
165
|
+
var C, I, S;
|
|
166
|
+
const c = m == null ? void 0 : m.childrenNamed("item").find((u) => u.attr.id === (l == null ? void 0 : l.attr.idref)), _ = (c == null ? void 0 : c.attr.href) || "", D = ((C = l == null ? void 0 : l.attr.properties) == null ? void 0 : C.split(" ")) || [], q = ((I = e.files.find((u) => u.uri.endsWith(_))) == null ? void 0 : I.size) || 0, k = a ?? "";
|
|
168
167
|
return {
|
|
169
168
|
id: (c == null ? void 0 : c.attr.id) || "",
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
renditionLayout: C || "reflowable",
|
|
169
|
+
href: (S = c == null ? void 0 : c.attr.href) != null && S.startsWith("https://") ? c == null ? void 0 : c.attr.href : t ? `${k}${t}/${c == null ? void 0 : c.attr.href}` : `${k}${c == null ? void 0 : c.attr.href}`,
|
|
170
|
+
renditionLayout: L || "reflowable",
|
|
173
171
|
...D.find((u) => u === "rendition:layout-reflowable") && {
|
|
174
172
|
renditionLayout: "reflowable"
|
|
175
173
|
},
|
|
176
|
-
progressionWeight:
|
|
174
|
+
progressionWeight: q / B,
|
|
177
175
|
pageSpreadLeft: D.some((u) => u === "page-spread-left") || void 0,
|
|
178
176
|
pageSpreadRight: D.some((u) => u === "page-spread-right") || void 0,
|
|
179
177
|
mediaType: c == null ? void 0 : c.attr["media-type"]
|
|
180
178
|
};
|
|
181
179
|
})) || [],
|
|
182
|
-
items:
|
|
180
|
+
items: P(s),
|
|
183
181
|
guide: $ == null ? void 0 : $.childrenNamed("reference").map((l) => ({
|
|
184
182
|
href: l.attr.href || "",
|
|
185
183
|
title: l.attr.title || "",
|
|
186
184
|
type: l.attr.type
|
|
187
185
|
}))
|
|
188
186
|
};
|
|
189
|
-
},
|
|
190
|
-
const i = Object.values(e.files).find((
|
|
187
|
+
}, fe = async (e, a) => {
|
|
188
|
+
const i = Object.values(e.files).find((n) => n.uri === a), r = await ee(e, a);
|
|
191
189
|
if (!i)
|
|
192
190
|
throw new Error("no file found");
|
|
193
191
|
const t = await i.blob();
|
|
194
|
-
return
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
192
|
+
return {
|
|
193
|
+
body: t,
|
|
194
|
+
params: {
|
|
195
|
+
headers: {
|
|
196
|
+
...t.type && {
|
|
197
|
+
"Content-Type": t.type
|
|
198
|
+
},
|
|
199
|
+
...i.encodingFormat && {
|
|
200
|
+
"Content-Type": i.encodingFormat
|
|
201
|
+
},
|
|
202
|
+
...r.mediaType && {
|
|
203
|
+
"Content-Type": r.mediaType
|
|
204
|
+
}
|
|
204
205
|
}
|
|
205
206
|
}
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
var t,
|
|
207
|
+
};
|
|
208
|
+
}, ee = async (e, a) => {
|
|
209
|
+
var t, n;
|
|
209
210
|
const r = await ((t = w(e).data) == null ? void 0 : t.string());
|
|
210
211
|
if (r) {
|
|
211
|
-
const o = new
|
|
212
|
+
const o = new h.XmlDocument(r);
|
|
212
213
|
return {
|
|
213
|
-
mediaType: (
|
|
214
|
+
mediaType: (n = P(o).find((d) => a.endsWith(d.href))) == null ? void 0 : n.mediaType
|
|
214
215
|
};
|
|
215
216
|
}
|
|
216
217
|
return {
|
|
217
|
-
mediaType:
|
|
218
|
+
mediaType: te(a)
|
|
218
219
|
};
|
|
219
|
-
},
|
|
220
|
+
}, te = (e) => {
|
|
220
221
|
if (e.endsWith(".css"))
|
|
221
222
|
return "text/css; charset=UTF-8";
|
|
222
223
|
if (e.endsWith(".jpg"))
|
|
@@ -227,45 +228,62 @@ const b = {
|
|
|
227
228
|
return "video/mp4";
|
|
228
229
|
if (e.endsWith(".svg"))
|
|
229
230
|
return "image/svg+xml";
|
|
230
|
-
},
|
|
231
|
-
var s;
|
|
232
|
-
const r = e.files.find((d) => d.basename.toLowerCase() === "comicinfo.xml");
|
|
233
|
-
if (!r)
|
|
234
|
-
return i;
|
|
235
|
-
const t = await r.string(), o = ((s = new g.XmlDocument(t).childNamed("Manga")) == null ? void 0 : s.val) || "unknown";
|
|
236
|
-
return {
|
|
237
|
-
...i,
|
|
238
|
-
spineItems: i.spineItems.filter((d) => d.id.toLowerCase() !== "comicinfo.xml"),
|
|
239
|
-
readingDirection: o === "YesAndRightToLeft" ? "rtl" : "ltr"
|
|
240
|
-
};
|
|
241
|
-
}, te = ({ archive: e, baseUrl: n }) => async (i) => {
|
|
231
|
+
}, ne = ({ archive: e, baseUrl: a }) => async (i) => {
|
|
242
232
|
var t;
|
|
243
|
-
const r = Object.values(e.files).filter((
|
|
233
|
+
const r = Object.values(e.files).filter((n) => !n.dir);
|
|
244
234
|
return {
|
|
245
235
|
filename: e.filename,
|
|
246
236
|
nav: {
|
|
247
237
|
toc: []
|
|
248
238
|
},
|
|
249
|
-
title: ((t = e.files.find(({ dir:
|
|
239
|
+
title: ((t = e.files.find(({ dir: n }) => n)) == null ? void 0 : t.basename.replace(/\/$/, "")) || "",
|
|
250
240
|
renditionLayout: "pre-paginated",
|
|
251
241
|
renditionSpread: "auto",
|
|
252
242
|
readingDirection: "ltr",
|
|
253
|
-
spineItems: r.map((
|
|
254
|
-
id:
|
|
255
|
-
|
|
256
|
-
href: n ? `${n}/${a.uri}` : a.uri,
|
|
243
|
+
spineItems: r.map((n) => ({
|
|
244
|
+
id: n.basename,
|
|
245
|
+
href: `${a}${n.uri}`,
|
|
257
246
|
renditionLayout: "pre-paginated",
|
|
258
247
|
progressionWeight: 1 / r.length,
|
|
259
248
|
pageSpreadLeft: void 0,
|
|
260
249
|
pageSpreadRight: void 0,
|
|
261
|
-
mediaType:
|
|
250
|
+
mediaType: n.encodingFormat
|
|
262
251
|
})),
|
|
263
|
-
items: r.map((
|
|
264
|
-
id:
|
|
265
|
-
href:
|
|
252
|
+
items: r.map((n) => ({
|
|
253
|
+
id: n.basename,
|
|
254
|
+
href: `${a}${n.uri}`
|
|
266
255
|
}))
|
|
267
256
|
};
|
|
268
|
-
},
|
|
257
|
+
}, re = ({ archive: e, baseUrl: a }) => async (i) => {
|
|
258
|
+
var s;
|
|
259
|
+
const r = e.files.find((d) => d.basename.toLowerCase() === "comicinfo.xml");
|
|
260
|
+
if (!r)
|
|
261
|
+
return i;
|
|
262
|
+
const t = await r.string(), o = ((s = new h.XmlDocument(t).childNamed("Manga")) == null ? void 0 : s.val) || "unknown";
|
|
263
|
+
return {
|
|
264
|
+
...i,
|
|
265
|
+
spineItems: i.spineItems.filter((d) => d.id.toLowerCase() !== "comicinfo.xml"),
|
|
266
|
+
readingDirection: o === "YesAndRightToLeft" ? "rtl" : "ltr"
|
|
267
|
+
};
|
|
268
|
+
}, ae = (e) => {
|
|
269
|
+
const a = e.descendantWithPath("head.meta");
|
|
270
|
+
return !!(a && a.attr.name === "viewport");
|
|
271
|
+
}, ie = (e) => e.reduce(async (a, i) => {
|
|
272
|
+
if (!await a || !G({ mimeType: i.encodingFormat, uri: i.uri }))
|
|
273
|
+
return !1;
|
|
274
|
+
const t = await i.string();
|
|
275
|
+
return t ? ae(new h.XmlDocument(t)) : !1;
|
|
276
|
+
}, Promise.resolve(!0)), oe = ({ archive: e, baseUrl: a }) => async (i) => {
|
|
277
|
+
if (i.renditionLayout === "reflowable" && i.spineItems.every((t) => t.renditionLayout === "reflowable")) {
|
|
278
|
+
const t = await X({ archive: e });
|
|
279
|
+
if (await ie(t))
|
|
280
|
+
return {
|
|
281
|
+
...i,
|
|
282
|
+
renditionLayout: "pre-paginated"
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
return i;
|
|
286
|
+
}, se = {
|
|
269
287
|
filename: "",
|
|
270
288
|
items: [],
|
|
271
289
|
nav: {
|
|
@@ -276,39 +294,40 @@ const b = {
|
|
|
276
294
|
renditionSpread: "auto",
|
|
277
295
|
spineItems: [],
|
|
278
296
|
title: ""
|
|
279
|
-
},
|
|
297
|
+
}, pe = async (e, { baseUrl: a = "" } = {}) => {
|
|
280
298
|
const i = [
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
299
|
+
ne({ archive: e, baseUrl: a }),
|
|
300
|
+
E({ archive: e, baseUrl: a }),
|
|
301
|
+
oe({ archive: e, baseUrl: a }),
|
|
302
|
+
re({ archive: e, baseUrl: a })
|
|
284
303
|
];
|
|
285
304
|
try {
|
|
286
|
-
const r = await i.reduce(async (
|
|
287
|
-
return
|
|
305
|
+
const r = await i.reduce(async (t, n) => await n(await t), Promise.resolve(se));
|
|
306
|
+
return y.log("Generated manifest", r), r;
|
|
288
307
|
} catch (r) {
|
|
289
|
-
|
|
308
|
+
throw y.error(r), r;
|
|
290
309
|
}
|
|
291
|
-
},
|
|
310
|
+
}, g = (e) => e.substring(e.lastIndexOf("/") + 1) || e, ue = async (e, a) => {
|
|
292
311
|
const i = `
|
|
293
312
|
<?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
|
|
294
313
|
<metadata>
|
|
295
|
-
<meta property="rendition:layout">${
|
|
296
|
-
${
|
|
314
|
+
<meta property="rendition:layout">${a != null && a.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
|
|
315
|
+
${a != null && a.useRenditionFlow ? '<meta property="rendition:flow">scrolled-continuous</meta>' : ""}
|
|
297
316
|
</metadata>
|
|
298
317
|
<manifest>
|
|
299
|
-
${e.map((
|
|
318
|
+
${e.map((n) => `<item id="${g(n)}" href="${n}" media-type="${W(n)}"/>`).join(`
|
|
300
319
|
`)}
|
|
301
320
|
</manifest>
|
|
302
321
|
<spine>
|
|
303
|
-
${e.map((
|
|
322
|
+
${e.map((n) => `<itemref idref="${g(n)}" />`).join(`
|
|
304
323
|
`)}
|
|
305
324
|
</spine>
|
|
306
325
|
</package>
|
|
307
|
-
`, r = e.map((
|
|
326
|
+
`, r = e.map((n) => ({
|
|
308
327
|
dir: !1,
|
|
309
|
-
basename:
|
|
310
|
-
encodingFormat:
|
|
311
|
-
uri:
|
|
328
|
+
basename: g(n),
|
|
329
|
+
encodingFormat: W(n),
|
|
330
|
+
uri: n,
|
|
312
331
|
size: 100 / e.length,
|
|
313
332
|
base64: async () => "",
|
|
314
333
|
blob: async () => new Blob(),
|
|
@@ -326,14 +345,17 @@ const b = {
|
|
|
326
345
|
string: async () => i
|
|
327
346
|
}, ...r]
|
|
328
347
|
};
|
|
329
|
-
},
|
|
348
|
+
}, ce = async (e) => new Promise((a) => {
|
|
330
349
|
const i = new FileReader();
|
|
331
350
|
i.readAsDataURL(e), i.onloadend = function() {
|
|
332
351
|
const r = i.result;
|
|
333
|
-
|
|
352
|
+
a(r);
|
|
334
353
|
};
|
|
335
|
-
}),
|
|
336
|
-
|
|
354
|
+
}), he = async (e, {
|
|
355
|
+
mimeType: a,
|
|
356
|
+
direction: i
|
|
357
|
+
} = { mimeType: "text/plain" }) => {
|
|
358
|
+
const r = `
|
|
337
359
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
338
360
|
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="ja" prefix="rendition: http://www.idpf.org/vocab/rendition/#"
|
|
339
361
|
unique-identifier="ootuya-id">
|
|
@@ -344,7 +366,7 @@ const b = {
|
|
|
344
366
|
<manifest>
|
|
345
367
|
<item id="p01" href="p01.txt" media-type="text/plain"/>
|
|
346
368
|
</manifest>
|
|
347
|
-
<spine page-progression-direction="${
|
|
369
|
+
<spine page-progression-direction="${i ?? "ltr"}">
|
|
348
370
|
<itemref idref="p01" />
|
|
349
371
|
</spine>
|
|
350
372
|
</package>
|
|
@@ -354,76 +376,79 @@ const b = {
|
|
|
354
376
|
files: [
|
|
355
377
|
{
|
|
356
378
|
dir: !1,
|
|
357
|
-
basename:
|
|
379
|
+
basename: g("generated.opf"),
|
|
358
380
|
uri: "generated.opf",
|
|
359
|
-
blob: async () => new Blob([
|
|
360
|
-
string: async () =>
|
|
361
|
-
base64: async () => btoa(
|
|
381
|
+
blob: async () => new Blob([r]),
|
|
382
|
+
string: async () => r,
|
|
383
|
+
base64: async () => btoa(r),
|
|
362
384
|
size: 0
|
|
363
385
|
},
|
|
364
386
|
{
|
|
365
387
|
dir: !1,
|
|
366
|
-
basename:
|
|
388
|
+
basename: g("p01.txt"),
|
|
367
389
|
uri: "p01.txt",
|
|
368
390
|
blob: async () => typeof e == "string" ? new Blob([e]) : e,
|
|
369
391
|
string: async () => typeof e == "string" ? e : e.text(),
|
|
370
|
-
base64: async () => typeof e == "string" ? btoa(e) :
|
|
392
|
+
base64: async () => typeof e == "string" ? btoa(e) : ce(e),
|
|
371
393
|
size: typeof e == "string" ? e.length : e.size,
|
|
372
|
-
encodingFormat:
|
|
394
|
+
encodingFormat: a
|
|
373
395
|
}
|
|
374
396
|
]
|
|
375
397
|
};
|
|
376
|
-
}, j = (e,
|
|
398
|
+
}, j = (e, a) => {
|
|
377
399
|
var t;
|
|
378
|
-
const i = e.split(/(\d+)/), r =
|
|
379
|
-
for (let
|
|
380
|
-
if (i[
|
|
381
|
-
return (t = i[
|
|
400
|
+
const i = e.split(/(\d+)/), r = a.split(/(\d+)/);
|
|
401
|
+
for (let n = 0, o = i.length; n < o; n++)
|
|
402
|
+
if (i[n] !== r[n])
|
|
403
|
+
return (t = i[n]) != null && t.match(/\d/) ? +(i[n] || "") - +(r[n] || "") : (i[n] || "").localeCompare(r[n] || "");
|
|
382
404
|
return 1;
|
|
383
|
-
},
|
|
405
|
+
}, ge = async (e, { orderByAlpha: a, name: i } = {}) => {
|
|
384
406
|
let r = Object.values(e.files);
|
|
385
|
-
|
|
407
|
+
a && (r = r.sort((n, o) => j(n.name, o.name)));
|
|
408
|
+
const t = {
|
|
386
409
|
filename: i || "",
|
|
387
|
-
files: r.map((
|
|
388
|
-
dir:
|
|
389
|
-
basename:
|
|
390
|
-
uri:
|
|
391
|
-
blob: () =>
|
|
392
|
-
string: () =>
|
|
393
|
-
base64: () =>
|
|
394
|
-
...
|
|
395
|
-
stream:
|
|
410
|
+
files: r.map((n) => ({
|
|
411
|
+
dir: n.dir,
|
|
412
|
+
basename: g(n.name),
|
|
413
|
+
uri: n.name,
|
|
414
|
+
blob: () => n.async("blob"),
|
|
415
|
+
string: () => n.async("string"),
|
|
416
|
+
base64: () => n.async("base64"),
|
|
417
|
+
...n.internalStream && {
|
|
418
|
+
stream: n.internalStream
|
|
396
419
|
},
|
|
397
|
-
size:
|
|
420
|
+
size: n._data.uncompressedSize
|
|
398
421
|
}))
|
|
399
422
|
};
|
|
400
|
-
|
|
423
|
+
return y.log("Generated archive", t), t;
|
|
424
|
+
}, ye = async (e, { orderByAlpha: a, name: i } = {}) => {
|
|
401
425
|
let r = e;
|
|
402
|
-
return
|
|
426
|
+
return a && (r = r.sort((t, n) => j(t.name, n.name))), {
|
|
403
427
|
filename: i || "",
|
|
404
428
|
files: r.map((t) => ({
|
|
405
429
|
dir: t.isDir,
|
|
406
|
-
basename:
|
|
430
|
+
basename: g(t.name),
|
|
407
431
|
uri: t.name,
|
|
408
432
|
blob: async () => new Blob([await t.data()]),
|
|
409
433
|
string: async () => {
|
|
410
|
-
const
|
|
411
|
-
return String.fromCharCode.apply(null, Array.from(new Uint16Array(
|
|
434
|
+
const n = await t.data();
|
|
435
|
+
return String.fromCharCode.apply(null, Array.from(new Uint16Array(n)));
|
|
412
436
|
},
|
|
413
437
|
base64: async () => "",
|
|
414
438
|
size: t.size
|
|
415
439
|
}))
|
|
416
440
|
};
|
|
441
|
+
}, be = ({ enableReport: e } = {}) => {
|
|
442
|
+
y.enable(!!e);
|
|
417
443
|
};
|
|
418
444
|
export {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
he as xmldoc
|
|
445
|
+
be as configure,
|
|
446
|
+
ye as createArchiveFromArrayBufferList,
|
|
447
|
+
ge as createArchiveFromJszip,
|
|
448
|
+
he as createArchiveFromText,
|
|
449
|
+
ue as createArchiveFromUrls,
|
|
450
|
+
pe as generateManifestFromArchive,
|
|
451
|
+
fe as generateResourceFromArchive,
|
|
452
|
+
w as getArchiveOpfInfo
|
|
428
453
|
};
|
|
429
454
|
//# sourceMappingURL=prose-streamer.js.map
|