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