@prose-reader/streamer 1.23.0 → 1.24.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 +383 -590
- package/dist/prose-streamer.js.map +1 -1
- package/dist/prose-streamer.umd.cjs +11 -716
- package/dist/prose-streamer.umd.cjs.map +1 -1
- package/package.json +3 -3
package/dist/prose-streamer.js
CHANGED
|
@@ -1,631 +1,448 @@
|
|
|
1
|
-
import { urlJoin, PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME, isXmlBasedMimeType, detectMimeTypeFromName } from "@prose-reader/shared";
|
|
2
|
-
import
|
|
3
|
-
let
|
|
4
|
-
const
|
|
5
|
-
enable: (
|
|
6
|
-
|
|
1
|
+
import { urlJoin as v, PROSE_READER_RESOURCE_ERROR_INJECTED_META_NAME as J, isXmlBasedMimeType as q, detectMimeTypeFromName as W } from "@prose-reader/shared";
|
|
2
|
+
import g from "xmldoc";
|
|
3
|
+
let b = !1;
|
|
4
|
+
const h = {
|
|
5
|
+
enable: (e) => {
|
|
6
|
+
b = e;
|
|
7
7
|
},
|
|
8
8
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
-
log: (...
|
|
10
|
-
|
|
11
|
-
console.log(`[prose-reader-streamer]`, ...data);
|
|
12
|
-
}
|
|
9
|
+
log: (...e) => {
|
|
10
|
+
b && console.log("[prose-reader-streamer]", ...e);
|
|
13
11
|
},
|
|
14
12
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
warn: (...
|
|
16
|
-
|
|
17
|
-
console.warn(`[prose-reader-streamer]`, ...data);
|
|
18
|
-
}
|
|
13
|
+
warn: (...e) => {
|
|
14
|
+
b && console.warn("[prose-reader-streamer]", ...e);
|
|
19
15
|
},
|
|
20
16
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
-
error: (...
|
|
22
|
-
console.error(...
|
|
17
|
+
error: (...e) => {
|
|
18
|
+
console.error(...e);
|
|
23
19
|
},
|
|
24
|
-
time: (
|
|
25
|
-
|
|
26
|
-
console.time(`[prose-reader-streamer] [metric] ${label}`);
|
|
27
|
-
}
|
|
20
|
+
time: (e) => {
|
|
21
|
+
b && console.time(`[prose-reader-streamer] [metric] ${e}`);
|
|
28
22
|
},
|
|
29
|
-
timeEnd: (
|
|
30
|
-
|
|
31
|
-
console.timeEnd(`[prose-reader-streamer] [metric] ${label}`);
|
|
32
|
-
}
|
|
23
|
+
timeEnd: (e) => {
|
|
24
|
+
b && console.timeEnd(`[prose-reader-streamer] [metric] ${e}`);
|
|
33
25
|
},
|
|
34
|
-
metric: (
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
console.warn(
|
|
41
|
-
`[prose-reader-streamer] [metric] `,
|
|
42
|
-
`${performanceEntry.name} took ${performanceEntry.duration}ms which is above the ${targetDuration}ms target for this function`
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
26
|
+
metric: (e, i = 1 / 0) => {
|
|
27
|
+
const a = typeof e == "number" ? e : e.duration;
|
|
28
|
+
b && (e.duration <= i ? console.log("[prose-reader-streamer] [metric] ", `${e.name} took ${a}ms`) : console.warn(
|
|
29
|
+
"[prose-reader-streamer] [metric] ",
|
|
30
|
+
`${e.name} took ${e.duration}ms which is above the ${i}ms target for this function`
|
|
31
|
+
));
|
|
46
32
|
},
|
|
47
33
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
-
measurePerformance: (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
const t1 = performance.now();
|
|
60
|
-
Report.metric({ name, duration: t1 - t0 }, targetDuration);
|
|
61
|
-
return response;
|
|
62
|
-
};
|
|
34
|
+
measurePerformance: (e, i = 10, a) => (...r) => {
|
|
35
|
+
const t = performance.now(), n = a(...r);
|
|
36
|
+
if (n && n.then)
|
|
37
|
+
return n.then((s) => {
|
|
38
|
+
const d = performance.now();
|
|
39
|
+
return h.metric({ name: e, duration: d - t }, i), s;
|
|
40
|
+
});
|
|
41
|
+
const o = performance.now();
|
|
42
|
+
return h.metric({ name: e, duration: o - t }, i), n;
|
|
63
43
|
}
|
|
64
|
-
}
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const bodyToParse = resource.body ?? await file.string();
|
|
69
|
-
const newBody = bodyToParse.replaceAll(`-webkit-writing-mode`, `writing-mode`);
|
|
44
|
+
}, Y = ({ archive: e, resourcePath: i }) => async (a) => {
|
|
45
|
+
const r = Object.values(e.files).find((t) => t.uri === i);
|
|
46
|
+
if (r != null && r.basename.endsWith(".css")) {
|
|
47
|
+
const n = (a.body ?? await r.string()).replaceAll("-webkit-writing-mode", "writing-mode");
|
|
70
48
|
return {
|
|
71
|
-
...
|
|
72
|
-
body:
|
|
49
|
+
...a,
|
|
50
|
+
body: n
|
|
73
51
|
};
|
|
74
52
|
}
|
|
75
|
-
return
|
|
76
|
-
}
|
|
77
|
-
const
|
|
78
|
-
const filesAsArray = Object.values(archive.files).filter((file2) => !file2.dir);
|
|
79
|
-
const file = filesAsArray.find((file2) => file2.uri.endsWith(`.opf`));
|
|
53
|
+
return a;
|
|
54
|
+
}, x = (e) => {
|
|
55
|
+
const a = Object.values(e.files).filter((r) => !r.dir).find((r) => r.uri.endsWith(".opf"));
|
|
80
56
|
return {
|
|
81
|
-
data:
|
|
82
|
-
basePath: (
|
|
57
|
+
data: a,
|
|
58
|
+
basePath: (a == null ? void 0 : a.uri.substring(0, a.uri.lastIndexOf("/"))) || ""
|
|
83
59
|
};
|
|
84
|
-
}
|
|
85
|
-
const
|
|
86
|
-
const chp = {
|
|
60
|
+
}, P = (e, { opfBasePath: i, baseUrl: a }) => {
|
|
61
|
+
const r = {
|
|
87
62
|
contents: [],
|
|
88
|
-
path:
|
|
89
|
-
href:
|
|
90
|
-
title:
|
|
63
|
+
path: "",
|
|
64
|
+
href: "",
|
|
65
|
+
title: ""
|
|
91
66
|
};
|
|
92
|
-
let
|
|
93
|
-
|
|
94
|
-
let
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (node === `a` && (contentNode == null ? void 0 : contentNode.attr.href)) {
|
|
102
|
-
chp.path = urlJoin(opfBasePath, contentNode.attr.href);
|
|
103
|
-
chp.href = urlJoin(baseUrl, opfBasePath, contentNode.attr.href);
|
|
67
|
+
let t = e.childNamed("span") || e.childNamed("a");
|
|
68
|
+
r.title = (t == null ? void 0 : t.attr.title) || (t == null ? void 0 : t.val.trim()) || r.title;
|
|
69
|
+
let n = t == null ? void 0 : t.name;
|
|
70
|
+
n !== "a" && (t = e.descendantWithPath(`${n}.a`), t && (n = t.name.toLowerCase())), n === "a" && (t != null && t.attr.href) && (r.path = v(i, t.attr.href), r.href = v(a, i, t.attr.href));
|
|
71
|
+
const o = e.childNamed("ol");
|
|
72
|
+
if (o) {
|
|
73
|
+
const s = o.childrenNamed("li");
|
|
74
|
+
s && s.length > 0 && (r.contents = s.map((d) => P(d, { opfBasePath: i, baseUrl: a })));
|
|
104
75
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
76
|
+
return r;
|
|
77
|
+
}, K = (e, { opfBasePath: i, baseUrl: a }) => {
|
|
78
|
+
var n, o;
|
|
79
|
+
const r = [];
|
|
80
|
+
let t;
|
|
81
|
+
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(P(s, { opfBasePath: i, baseUrl: a }))), r;
|
|
82
|
+
}, Q = async (e, i, { opfBasePath: a, baseUrl: r }) => {
|
|
83
|
+
var n;
|
|
84
|
+
const t = (n = e.childNamed("manifest")) == null ? void 0 : n.childrenNamed("item").find((o) => o.attr.properties === "nav");
|
|
85
|
+
if (t) {
|
|
86
|
+
const o = Object.values(i.files).find((s) => s.uri.endsWith(t.attr.href || ""));
|
|
87
|
+
if (o) {
|
|
88
|
+
const s = new g.XmlDocument(await o.string());
|
|
89
|
+
return K(s, { opfBasePath: a, baseUrl: r });
|
|
110
90
|
}
|
|
111
91
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (doc.descendantWithPath(`body.nav.ol`)) {
|
|
119
|
-
navDataChildren = (_a = doc.descendantWithPath(`body.nav.ol`)) == null ? void 0 : _a.children;
|
|
120
|
-
} else if (doc.descendantWithPath(`body.section.nav.ol`)) {
|
|
121
|
-
navDataChildren = (_b = doc.descendantWithPath(`body.section.nav.ol`)) == null ? void 0 : _b.children;
|
|
122
|
-
}
|
|
123
|
-
if (navDataChildren && navDataChildren.length > 0) {
|
|
124
|
-
navDataChildren.filter((li) => li.name === `li`).forEach((li) => toc.push(extractNavChapter(li, { opfBasePath, baseUrl })));
|
|
125
|
-
}
|
|
126
|
-
return toc;
|
|
127
|
-
};
|
|
128
|
-
const parseTocFromNavPath = async (opfXmlDoc, archive, { opfBasePath, baseUrl }) => {
|
|
129
|
-
var _a;
|
|
130
|
-
const navItem = (_a = opfXmlDoc.childNamed(`manifest`)) == null ? void 0 : _a.childrenNamed(`item`).find((child) => child.attr.properties === `nav`);
|
|
131
|
-
if (navItem) {
|
|
132
|
-
const tocFile = Object.values(archive.files).find((item) => item.uri.endsWith(navItem.attr.href || ``));
|
|
133
|
-
if (tocFile) {
|
|
134
|
-
const doc = new xmldoc.XmlDocument(await tocFile.string());
|
|
135
|
-
return buildTOCFromNav(doc, { opfBasePath, baseUrl });
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
const mapNcxChapter = (point, { opfBasePath, baseUrl, prefix }) => {
|
|
140
|
-
var _a, _b;
|
|
141
|
-
const src = ((_a = point == null ? void 0 : point.childNamed(`${prefix}content`)) == null ? void 0 : _a.attr.src) || ``;
|
|
142
|
-
const out = {
|
|
143
|
-
title: ((_b = point == null ? void 0 : point.descendantWithPath(`${prefix}navLabel.${prefix}text`)) == null ? void 0 : _b.val) || ``,
|
|
144
|
-
path: urlJoin(opfBasePath, src),
|
|
145
|
-
href: urlJoin(baseUrl, opfBasePath, src),
|
|
92
|
+
}, z = (e, { opfBasePath: i, baseUrl: a, prefix: r }) => {
|
|
93
|
+
var s, d;
|
|
94
|
+
const t = ((s = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : s.attr.src) || "", n = {
|
|
95
|
+
title: ((d = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : d.val) || "",
|
|
96
|
+
path: v(i, t),
|
|
97
|
+
href: v(a, i, t),
|
|
146
98
|
contents: []
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (rootTagName.indexOf(`:`) !== -1) {
|
|
160
|
-
prefix = rootTagName.split(`:`)[0] + `:`;
|
|
161
|
-
}
|
|
162
|
-
(_a = ncxData.childNamed(`${prefix}navMap`)) == null ? void 0 : _a.childrenNamed(`${prefix}navPoint`).forEach((point) => toc.push(mapNcxChapter(point, { opfBasePath, baseUrl, prefix })));
|
|
163
|
-
return toc;
|
|
164
|
-
};
|
|
165
|
-
const parseTocFromNcx = async ({
|
|
166
|
-
opfData,
|
|
167
|
-
opfBasePath,
|
|
168
|
-
baseUrl,
|
|
169
|
-
archive
|
|
99
|
+
}, o = e.childrenNamed(`${r}navPoint`);
|
|
100
|
+
return o && o.length > 0 && (n.contents = o.map((p) => z(p, { opfBasePath: i, baseUrl: a, prefix: r }))), n;
|
|
101
|
+
}, Z = (e, { opfBasePath: i, baseUrl: a }) => {
|
|
102
|
+
var o;
|
|
103
|
+
const r = [], t = e.name;
|
|
104
|
+
let n = "";
|
|
105
|
+
return t.indexOf(":") !== -1 && (n = t.split(":")[0] + ":"), (o = e.childNamed(`${n}navMap`)) == null || o.childrenNamed(`${n}navPoint`).forEach((s) => r.push(z(s, { opfBasePath: i, baseUrl: a, prefix: n }))), r;
|
|
106
|
+
}, E = async ({
|
|
107
|
+
opfData: e,
|
|
108
|
+
opfBasePath: i,
|
|
109
|
+
baseUrl: a,
|
|
110
|
+
archive: r
|
|
170
111
|
}) => {
|
|
171
|
-
var
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const ncxData = new xmldoc.XmlDocument(await file.string());
|
|
181
|
-
return buildTOCFromNCX(ncxData, { opfBasePath, baseUrl });
|
|
112
|
+
var o;
|
|
113
|
+
const t = e.childNamed("spine"), n = t && t.attr.toc;
|
|
114
|
+
if (n) {
|
|
115
|
+
const s = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((d) => d.attr.id === n);
|
|
116
|
+
if (s) {
|
|
117
|
+
const d = `${i}${i === "" ? "" : "/"}${s.attr.href}`, p = Object.values(r.files).find((m) => m.uri.endsWith(d));
|
|
118
|
+
if (p) {
|
|
119
|
+
const m = new g.XmlDocument(await p.string());
|
|
120
|
+
return Z(m, { opfBasePath: i, baseUrl: a });
|
|
182
121
|
}
|
|
183
122
|
}
|
|
184
123
|
}
|
|
185
|
-
}
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
archive,
|
|
192
|
-
baseUrl
|
|
124
|
+
}, ee = async (e, i, { baseUrl: a }) => {
|
|
125
|
+
const { basePath: r } = x(i) || {}, t = await E({
|
|
126
|
+
opfData: e,
|
|
127
|
+
opfBasePath: r,
|
|
128
|
+
archive: i,
|
|
129
|
+
baseUrl: a
|
|
193
130
|
});
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return await parseTocFromNavPath(opfXmlDoc, archive, { opfBasePath, baseUrl });
|
|
198
|
-
};
|
|
199
|
-
const extractKoboInformationFromArchive = async (archive) => {
|
|
200
|
-
const koboInformation = {
|
|
131
|
+
return t || await Q(e, i, { opfBasePath: r, baseUrl: a });
|
|
132
|
+
}, te = async (e) => {
|
|
133
|
+
const i = {
|
|
201
134
|
renditionLayout: void 0
|
|
202
135
|
};
|
|
203
|
-
await Promise.all(
|
|
204
|
-
|
|
205
|
-
var
|
|
206
|
-
if (
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
if (((_b = optionElement == null ? void 0 : optionElement.attr) == null ? void 0 : _b.name) === `fixed-layout` && optionElement.val === `true`) {
|
|
210
|
-
koboInformation.renditionLayout = `pre-paginated`;
|
|
211
|
-
}
|
|
136
|
+
return await Promise.all(
|
|
137
|
+
e.files.map(async (a) => {
|
|
138
|
+
var r, t;
|
|
139
|
+
if (a.uri.endsWith("com.kobobooks.display-options.xml")) {
|
|
140
|
+
const o = (r = new g.XmlDocument(await a.string()).childNamed("platform")) == null ? void 0 : r.childNamed("option");
|
|
141
|
+
((t = o == null ? void 0 : o.attr) == null ? void 0 : t.name) === "fixed-layout" && o.val === "true" && (i.renditionLayout = "pre-paginated");
|
|
212
142
|
}
|
|
213
143
|
})
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
const { data: opsFile, basePath: opfBasePath } = getArchiveOpfInfo(archive) || {};
|
|
219
|
-
const data = await (opsFile == null ? void 0 : opsFile.string());
|
|
220
|
-
if (!data)
|
|
144
|
+
), i;
|
|
145
|
+
}, j = async ({ archive: e }) => {
|
|
146
|
+
const { data: i, basePath: a } = x(e) || {}, r = await (i == null ? void 0 : i.string());
|
|
147
|
+
if (!r)
|
|
221
148
|
return [];
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return `${opfBasePath}/${item.attr.href}` === file.uri;
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
return archiveSpineItems;
|
|
235
|
-
};
|
|
236
|
-
const getItemsFromDoc = (doc) => {
|
|
237
|
-
var _a;
|
|
238
|
-
const manifestElm = doc.childNamed(`manifest`);
|
|
239
|
-
return ((_a = manifestElm == null ? void 0 : manifestElm.childrenNamed(`item`)) == null ? void 0 : _a.map((el) => ({
|
|
240
|
-
href: el.attr.href || ``,
|
|
241
|
-
id: el.attr.id || ``,
|
|
242
|
-
mediaType: el.attr[`media-type`]
|
|
149
|
+
const t = new g.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 || ""))) || [];
|
|
150
|
+
return e.files.filter((m) => d.find((f) => a ? `${a}/${f.attr.href}` === m.uri : `${f.attr.href}` === m.uri));
|
|
151
|
+
}, X = (e) => {
|
|
152
|
+
var a;
|
|
153
|
+
const i = e.childNamed("manifest");
|
|
154
|
+
return ((a = i == null ? void 0 : i.childrenNamed("item")) == null ? void 0 : a.map((r) => ({
|
|
155
|
+
href: r.attr.href || "",
|
|
156
|
+
id: r.attr.id || "",
|
|
157
|
+
mediaType: r.attr["media-type"]
|
|
243
158
|
}))) || [];
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
const data = await opsFile.string();
|
|
253
|
-
Report.log(data, koboInformation);
|
|
254
|
-
const opfXmlDoc = new xmldoc.XmlDocument(data);
|
|
255
|
-
const toc = await parseToc(opfXmlDoc, archive, { baseUrl }) || [];
|
|
256
|
-
const metadataElm = opfXmlDoc.childNamed(`metadata`);
|
|
257
|
-
const manifestElm = opfXmlDoc.childNamed(`manifest`);
|
|
258
|
-
const spineElm = opfXmlDoc.childNamed(`spine`);
|
|
259
|
-
const guideElm = opfXmlDoc.childNamed(`guide`);
|
|
260
|
-
const titleElm = metadataElm == null ? void 0 : metadataElm.childNamed(`dc:title`);
|
|
261
|
-
const metaElmChildren = (metadataElm == null ? void 0 : metadataElm.childrenNamed(`meta`)) || [];
|
|
262
|
-
const metaElmWithRendition = metaElmChildren.find((meta) => meta.attr.property === `rendition:layout`);
|
|
263
|
-
const metaElmWithRenditionFlow = metaElmChildren.find((meta) => meta.attr.property === `rendition:flow`);
|
|
264
|
-
const metaElmWithRenditionSpread = metaElmChildren.find((meta) => meta.attr.property === `rendition:spread`);
|
|
265
|
-
const publisherRenditionLayout = metaElmWithRendition == null ? void 0 : metaElmWithRendition.val;
|
|
266
|
-
const publisherRenditionFlow = metaElmWithRenditionFlow == null ? void 0 : metaElmWithRenditionFlow.val;
|
|
267
|
-
const renditionSpread = metaElmWithRenditionSpread == null ? void 0 : metaElmWithRenditionSpread.val;
|
|
268
|
-
const title = (titleElm == null ? void 0 : titleElm.val) || ((_a = archive.files.find(({ dir }) => dir)) == null ? void 0 : _a.basename) || ``;
|
|
269
|
-
const pageProgressionDirection = spineElm == null ? void 0 : spineElm.attr[`page-progression-direction`];
|
|
270
|
-
const archiveSpineItems = await getSpineItemFilesFromArchive({ archive });
|
|
271
|
-
const totalSize = archiveSpineItems.reduce((size, file) => file.size + size, 0);
|
|
159
|
+
}, ne = ({ archive: e, baseUrl: i }) => async (a) => {
|
|
160
|
+
var L;
|
|
161
|
+
const { data: r, basePath: t } = x(e) || {}, n = await te(e);
|
|
162
|
+
if (!r)
|
|
163
|
+
return a;
|
|
164
|
+
const o = await r.string();
|
|
165
|
+
h.log(o, n);
|
|
166
|
+
const s = new g.XmlDocument(o), d = await ee(s, e, { baseUrl: i }) || [], p = s.childNamed("metadata"), m = s.childNamed("manifest"), f = s.childNamed("spine"), F = 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"), I = $.find((l) => l.attr.property === "rendition:spread"), A = N == null ? void 0 : N.val, M = T == null ? void 0 : T.val, B = I == null ? void 0 : I.val, _ = (w == null ? void 0 : w.val) || ((L = e.files.find(({ dir: l }) => l)) == null ? void 0 : L.basename) || "", H = f == null ? void 0 : f.attr["page-progression-direction"], U = (await j({ archive: e })).reduce((l, c) => c.size + l, 0);
|
|
272
167
|
return {
|
|
273
|
-
filename:
|
|
168
|
+
filename: e.filename,
|
|
274
169
|
nav: {
|
|
275
|
-
toc
|
|
170
|
+
toc: d
|
|
276
171
|
},
|
|
277
|
-
renditionLayout:
|
|
278
|
-
renditionFlow:
|
|
279
|
-
renditionSpread,
|
|
280
|
-
title,
|
|
281
|
-
readingDirection:
|
|
282
|
-
spineItems: (
|
|
283
|
-
var
|
|
284
|
-
const
|
|
285
|
-
const href = (manifestItem == null ? void 0 : manifestItem.attr.href) || ``;
|
|
286
|
-
const properties = ((_a2 = itemrefElm == null ? void 0 : itemrefElm.attr.properties) == null ? void 0 : _a2.split(` `)) || [];
|
|
287
|
-
const itemSize = ((_b = archive.files.find((file) => file.uri.endsWith(href))) == null ? void 0 : _b.size) || 0;
|
|
288
|
-
const hrefBaseUri = baseUrl ?? "";
|
|
172
|
+
renditionLayout: A || n.renditionLayout || "reflowable",
|
|
173
|
+
renditionFlow: M || "auto",
|
|
174
|
+
renditionSpread: B,
|
|
175
|
+
title: _,
|
|
176
|
+
readingDirection: H || "ltr",
|
|
177
|
+
spineItems: (f == null ? void 0 : f.childrenNamed("itemref").map((l) => {
|
|
178
|
+
var C, R, O;
|
|
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) || "", D = ((C = l == null ? void 0 : l.attr.properties) == null ? void 0 : C.split(" ")) || [], G = ((R = e.files.find((u) => u.uri.endsWith(V))) == null ? void 0 : R.size) || 0, S = i ?? "";
|
|
289
180
|
return {
|
|
290
|
-
id: (
|
|
291
|
-
href: (
|
|
292
|
-
renditionLayout:
|
|
293
|
-
...
|
|
294
|
-
renditionLayout:
|
|
181
|
+
id: (c == null ? void 0 : c.attr.id) || "",
|
|
182
|
+
href: (O = c == null ? void 0 : c.attr.href) != null && O.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}`,
|
|
183
|
+
renditionLayout: A || "reflowable",
|
|
184
|
+
...D.find((u) => u === "rendition:layout-reflowable") && {
|
|
185
|
+
renditionLayout: "reflowable"
|
|
295
186
|
},
|
|
296
|
-
progressionWeight:
|
|
297
|
-
pageSpreadLeft:
|
|
298
|
-
pageSpreadRight:
|
|
187
|
+
progressionWeight: G / U,
|
|
188
|
+
pageSpreadLeft: D.some((u) => u === "page-spread-left") || void 0,
|
|
189
|
+
pageSpreadRight: D.some((u) => u === "page-spread-right") || void 0,
|
|
299
190
|
// size: itemSize
|
|
300
|
-
mediaType:
|
|
191
|
+
mediaType: c == null ? void 0 : c.attr["media-type"]
|
|
301
192
|
};
|
|
302
193
|
})) || [],
|
|
303
|
-
items:
|
|
304
|
-
guide:
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
};
|
|
310
|
-
})
|
|
194
|
+
items: X(s),
|
|
195
|
+
guide: F == null ? void 0 : F.childrenNamed("reference").map((l) => ({
|
|
196
|
+
href: l.attr.href || "",
|
|
197
|
+
title: l.attr.title || "",
|
|
198
|
+
type: l.attr.type
|
|
199
|
+
}))
|
|
311
200
|
};
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if (data) {
|
|
318
|
-
const opfXmlDoc = new xmldoc.XmlDocument(data);
|
|
319
|
-
const items = getItemsFromDoc(opfXmlDoc);
|
|
201
|
+
}, re = async (e, i) => {
|
|
202
|
+
var t, n;
|
|
203
|
+
const r = await ((t = x(e).data) == null ? void 0 : t.string());
|
|
204
|
+
if (r) {
|
|
205
|
+
const o = new g.XmlDocument(r);
|
|
320
206
|
return {
|
|
321
|
-
mediaType: (
|
|
207
|
+
mediaType: (n = X(o).find((d) => i.endsWith(d.href))) == null ? void 0 : n.mediaType
|
|
322
208
|
};
|
|
323
209
|
}
|
|
324
210
|
return {
|
|
325
|
-
mediaType:
|
|
211
|
+
mediaType: ae(i)
|
|
326
212
|
};
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
if (
|
|
333
|
-
return
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
const defaultHook$1 = ({ archive, resourcePath }) => async (resource) => {
|
|
346
|
-
const file = Object.values(archive.files).find((file2) => file2.uri === resourcePath);
|
|
347
|
-
if (!file)
|
|
348
|
-
return resource;
|
|
349
|
-
const metadata = await getMetadata(archive, resourcePath);
|
|
213
|
+
}, ae = (e) => {
|
|
214
|
+
if (e.endsWith(".css"))
|
|
215
|
+
return "text/css; charset=UTF-8";
|
|
216
|
+
if (e.endsWith(".jpg"))
|
|
217
|
+
return "image/jpg";
|
|
218
|
+
if (e.endsWith(".xhtml"))
|
|
219
|
+
return "application/xhtml+xml";
|
|
220
|
+
if (e.endsWith(".mp4"))
|
|
221
|
+
return "video/mp4";
|
|
222
|
+
if (e.endsWith(".svg"))
|
|
223
|
+
return "image/svg+xml";
|
|
224
|
+
}, ie = ({ archive: e, resourcePath: i }) => async (a) => {
|
|
225
|
+
const r = Object.values(e.files).find((n) => n.uri === i);
|
|
226
|
+
if (!r)
|
|
227
|
+
return a;
|
|
228
|
+
const t = await re(e, i);
|
|
350
229
|
return {
|
|
351
|
-
...
|
|
230
|
+
...a,
|
|
352
231
|
params: {
|
|
353
|
-
...
|
|
232
|
+
...a.params,
|
|
354
233
|
status: 200,
|
|
355
234
|
headers: {
|
|
356
|
-
...(
|
|
357
|
-
"Content-Type":
|
|
235
|
+
...(r == null ? void 0 : r.encodingFormat) && {
|
|
236
|
+
"Content-Type": r.encodingFormat
|
|
358
237
|
},
|
|
359
|
-
...
|
|
360
|
-
"Content-Type":
|
|
238
|
+
...t.mediaType && {
|
|
239
|
+
"Content-Type": t.mediaType
|
|
361
240
|
}
|
|
362
241
|
}
|
|
363
242
|
}
|
|
364
243
|
};
|
|
365
|
-
}
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
const defaultResource = {
|
|
244
|
+
}, ye = async (e, i) => {
|
|
245
|
+
const a = Object.values(e.files).find((n) => n.uri === i);
|
|
246
|
+
if (!a)
|
|
247
|
+
throw new Error("no file found");
|
|
248
|
+
const r = {
|
|
372
249
|
params: {
|
|
373
250
|
status: 200
|
|
374
251
|
}
|
|
375
|
-
};
|
|
376
|
-
const hooks = [defaultHook$1({ archive, resourcePath }), cssFixHook({ archive, resourcePath })];
|
|
252
|
+
}, t = [ie({ archive: e, resourcePath: i }), Y({ archive: e, resourcePath: i })];
|
|
377
253
|
try {
|
|
378
|
-
const
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
return {
|
|
383
|
-
...resource,
|
|
384
|
-
body: resource.body || await file.blob()
|
|
254
|
+
const n = await t.reduce(async (o, s) => await s(await o), Promise.resolve(r));
|
|
255
|
+
return h.log("Generated resource", i, n), {
|
|
256
|
+
...n,
|
|
257
|
+
body: n.body || await a.blob()
|
|
385
258
|
};
|
|
386
|
-
} catch (
|
|
387
|
-
|
|
388
|
-
throw e;
|
|
259
|
+
} catch (n) {
|
|
260
|
+
throw h.error(n), n;
|
|
389
261
|
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
return {
|
|
393
|
-
body: `
|
|
262
|
+
}, be = (e) => ({
|
|
263
|
+
body: `
|
|
394
264
|
<!DOCTYPE html>
|
|
395
265
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en" lang="en">
|
|
396
266
|
<head>
|
|
397
|
-
<meta name="${
|
|
267
|
+
<meta name="${J}" content="${String(e)}" />
|
|
398
268
|
</head>
|
|
399
269
|
<body>
|
|
400
|
-
<pre>${String(
|
|
270
|
+
<pre>${String(e)}</pre>
|
|
401
271
|
</body>
|
|
402
272
|
</html>
|
|
403
273
|
`,
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}
|
|
274
|
+
params: {
|
|
275
|
+
status: 500,
|
|
276
|
+
headers: {
|
|
277
|
+
"Content-Type": "text/html;charset=UTF-8"
|
|
409
278
|
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
const files = Object.values(archive.files).filter((file) => !file.dir);
|
|
279
|
+
}
|
|
280
|
+
}), oe = ({ archive: e, baseUrl: i }) => async () => {
|
|
281
|
+
var r;
|
|
282
|
+
const a = Object.values(e.files).filter((t) => !t.dir);
|
|
415
283
|
return {
|
|
416
|
-
filename:
|
|
417
|
-
title: ((
|
|
418
|
-
renditionLayout:
|
|
419
|
-
renditionSpread:
|
|
420
|
-
readingDirection:
|
|
421
|
-
spineItems:
|
|
284
|
+
filename: e.filename,
|
|
285
|
+
title: ((r = e.files.find(({ dir: t }) => t)) == null ? void 0 : r.basename.replace(/\/$/, "")) || "",
|
|
286
|
+
renditionLayout: "pre-paginated",
|
|
287
|
+
renditionSpread: "auto",
|
|
288
|
+
readingDirection: "ltr",
|
|
289
|
+
spineItems: a.map((t, n) => ({
|
|
422
290
|
// some books such as cbz can have same basename inside different sub folder
|
|
423
291
|
// we need to make sure to have unique index
|
|
424
292
|
// /chap01/01.png, /chap02/01.png, etc
|
|
425
|
-
id: `${
|
|
426
|
-
href: encodeURI(`${
|
|
427
|
-
renditionLayout:
|
|
428
|
-
progressionWeight: 1 /
|
|
293
|
+
id: `${n}.${t.basename}`,
|
|
294
|
+
href: encodeURI(`${i}${t.uri}`),
|
|
295
|
+
renditionLayout: "pre-paginated",
|
|
296
|
+
progressionWeight: 1 / a.length,
|
|
429
297
|
pageSpreadLeft: void 0,
|
|
430
298
|
pageSpreadRight: void 0,
|
|
431
|
-
mediaType:
|
|
299
|
+
mediaType: t.encodingFormat
|
|
432
300
|
})),
|
|
433
|
-
items:
|
|
434
|
-
id: `${
|
|
435
|
-
href: `${
|
|
301
|
+
items: a.map((t, n) => ({
|
|
302
|
+
id: `${n}.${t.basename}`,
|
|
303
|
+
href: `${i}${t.uri}`
|
|
436
304
|
}))
|
|
437
305
|
};
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
const content = await comicInfoFile.string();
|
|
446
|
-
const xmlDoc = new xmldoc.XmlDocument(content);
|
|
447
|
-
const mangaVal = ((_a = xmlDoc.childNamed(`Manga`)) == null ? void 0 : _a.val) || `unknown`;
|
|
306
|
+
}, se = ({ archive: e, baseUrl: i }) => async (a) => {
|
|
307
|
+
var s;
|
|
308
|
+
const r = e.files.find((d) => d.basename.toLowerCase() === "comicinfo.xml");
|
|
309
|
+
if (!r)
|
|
310
|
+
return a;
|
|
311
|
+
const t = await r.string(), o = ((s = new g.XmlDocument(t).childNamed("Manga")) == null ? void 0 : s.val) || "unknown";
|
|
448
312
|
return {
|
|
449
|
-
...
|
|
450
|
-
spineItems:
|
|
451
|
-
readingDirection:
|
|
313
|
+
...a,
|
|
314
|
+
spineItems: a.spineItems.filter((d) => d.id.toLowerCase() !== "comicinfo.xml"),
|
|
315
|
+
readingDirection: o === "YesAndRightToLeft" ? "rtl" : "ltr"
|
|
452
316
|
};
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
return
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
const file = await current.string();
|
|
470
|
-
if (!file)
|
|
471
|
-
return false;
|
|
472
|
-
return hasDocMetaViewport(new xmldoc.XmlDocument(file));
|
|
473
|
-
}, Promise.resolve(true));
|
|
474
|
-
const epubOptimizerHook = ({ archive, baseUrl }) => async (manifest) => {
|
|
475
|
-
const bookIsFullReflowable = manifest.renditionLayout === "reflowable" && manifest.spineItems.every((item) => item.renditionLayout === "reflowable");
|
|
476
|
-
if (bookIsFullReflowable) {
|
|
477
|
-
const files = await getSpineItemFilesFromArchive({ archive });
|
|
478
|
-
const hasAllViewport = await allFilesHaveViewportMeta(files);
|
|
479
|
-
if (hasAllViewport) {
|
|
317
|
+
}, ce = (e) => {
|
|
318
|
+
var a;
|
|
319
|
+
const i = (a = e.descendantWithPath("head")) == null ? void 0 : a.childrenNamed("meta").find((r) => r.attr.name === "viewport");
|
|
320
|
+
return !!(i && i.attr.name === "viewport");
|
|
321
|
+
}, de = (e) => e.reduce(async (i, a) => {
|
|
322
|
+
if (!await i || !q({
|
|
323
|
+
mimeType: a.encodingFormat,
|
|
324
|
+
uri: a.uri
|
|
325
|
+
}))
|
|
326
|
+
return !1;
|
|
327
|
+
const t = await a.string();
|
|
328
|
+
return t ? ce(new g.XmlDocument(t)) : !1;
|
|
329
|
+
}, Promise.resolve(!0)), le = ({ archive: e, baseUrl: i }) => async (a) => {
|
|
330
|
+
if (a.renditionLayout === "reflowable" && a.spineItems.every((t) => t.renditionLayout === "reflowable")) {
|
|
331
|
+
const t = await j({ archive: e });
|
|
332
|
+
if (await de(t))
|
|
480
333
|
return {
|
|
481
|
-
...
|
|
482
|
-
spineItems:
|
|
483
|
-
...
|
|
334
|
+
...a,
|
|
335
|
+
spineItems: a.spineItems.map((o) => ({
|
|
336
|
+
...o,
|
|
484
337
|
renditionLayout: "pre-paginated"
|
|
485
338
|
})),
|
|
486
339
|
renditionLayout: "pre-paginated"
|
|
487
340
|
};
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
return manifest;
|
|
491
|
-
};
|
|
492
|
-
const sortByTitleComparator = (a, b) => {
|
|
493
|
-
var _a;
|
|
494
|
-
const alist = a.split(/(\d+)/);
|
|
495
|
-
const blist = b.split(/(\d+)/);
|
|
496
|
-
for (let i = 0, len = alist.length; i < len; i++) {
|
|
497
|
-
if (alist[i] !== blist[i]) {
|
|
498
|
-
if ((_a = alist[i]) == null ? void 0 : _a.match(/\d/)) {
|
|
499
|
-
return +(alist[i] || ``) - +(blist[i] || ``);
|
|
500
|
-
} else {
|
|
501
|
-
return (alist[i] || ``).localeCompare(blist[i] || ``);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
341
|
}
|
|
342
|
+
return a;
|
|
343
|
+
}, k = (e, i) => {
|
|
344
|
+
var t;
|
|
345
|
+
const a = e.split(/(\d+)/), r = i.split(/(\d+)/);
|
|
346
|
+
for (let n = 0, o = a.length; n < o; n++)
|
|
347
|
+
if (a[n] !== r[n])
|
|
348
|
+
return (t = a[n]) != null && t.match(/\d/) ? +(a[n] || "") - +(r[n] || "") : (a[n] || "").localeCompare(r[n] || "");
|
|
505
349
|
return 1;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
const existingTocItem = acc.find(({ title }) => title === part);
|
|
520
|
-
if (existingTocItem)
|
|
521
|
-
;
|
|
522
|
-
else {
|
|
523
|
-
acc.push({
|
|
524
|
-
contents: [],
|
|
525
|
-
href: urlJoin(baseUrl, encodeURI(file.uri)).replace(/\/$/, ""),
|
|
526
|
-
path: file.uri.replace(/\/$/, ""),
|
|
527
|
-
title: parts[0] ?? ""
|
|
528
|
-
});
|
|
529
|
-
}
|
|
350
|
+
}, me = ({ archive: e, baseUrl: i }) => async (a) => {
|
|
351
|
+
if (a.nav)
|
|
352
|
+
return a;
|
|
353
|
+
const r = [...e.files].sort((n, o) => k(n.uri, o.uri)), t = Object.values(r).reduce((n, o) => {
|
|
354
|
+
const s = o.uri.split("/");
|
|
355
|
+
return !o.dir && s.length > 1 && s.forEach((p, m) => {
|
|
356
|
+
if (m === s.length - 1)
|
|
357
|
+
return;
|
|
358
|
+
n.find(({ title: w }) => w === p) || n.push({
|
|
359
|
+
contents: [],
|
|
360
|
+
href: v(i, encodeURI(o.uri)).replace(/\/$/, ""),
|
|
361
|
+
path: o.uri.replace(/\/$/, ""),
|
|
362
|
+
title: s[0] ?? ""
|
|
530
363
|
});
|
|
531
|
-
}
|
|
532
|
-
return acc;
|
|
364
|
+
}), n;
|
|
533
365
|
}, []);
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
return {
|
|
537
|
-
...manifest,
|
|
366
|
+
return t.length === 0 ? a : {
|
|
367
|
+
...a,
|
|
538
368
|
nav: {
|
|
539
|
-
toc
|
|
369
|
+
toc: t
|
|
540
370
|
}
|
|
541
371
|
};
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
filename: ``,
|
|
372
|
+
}, pe = {
|
|
373
|
+
filename: "",
|
|
545
374
|
items: [],
|
|
546
375
|
nav: {
|
|
547
376
|
toc: []
|
|
548
377
|
},
|
|
549
|
-
readingDirection:
|
|
550
|
-
renditionLayout:
|
|
551
|
-
renditionSpread:
|
|
378
|
+
readingDirection: "ltr",
|
|
379
|
+
renditionLayout: "pre-paginated",
|
|
380
|
+
renditionSpread: "auto",
|
|
552
381
|
spineItems: [],
|
|
553
|
-
title:
|
|
554
|
-
}
|
|
555
|
-
const
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
navigationFallbackHook({ archive, baseUrl })
|
|
382
|
+
title: ""
|
|
383
|
+
}, we = async (e, { baseUrl: i = "" } = {}) => {
|
|
384
|
+
const a = [
|
|
385
|
+
oe({ archive: e, baseUrl: i }),
|
|
386
|
+
ne({ archive: e, baseUrl: i }),
|
|
387
|
+
le({ archive: e, baseUrl: i }),
|
|
388
|
+
se({ archive: e, baseUrl: i }),
|
|
389
|
+
me({ archive: e, baseUrl: i })
|
|
562
390
|
];
|
|
563
391
|
try {
|
|
564
|
-
const
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
return manifest;
|
|
569
|
-
} catch (e) {
|
|
570
|
-
Report.error(e);
|
|
571
|
-
throw e;
|
|
392
|
+
const r = await a.reduce(async (t, n) => await n(await t), Promise.resolve(pe));
|
|
393
|
+
return h.log("Generated manifest", r), r;
|
|
394
|
+
} catch (r) {
|
|
395
|
+
throw h.error(r), r;
|
|
572
396
|
}
|
|
573
|
-
}
|
|
574
|
-
const
|
|
575
|
-
const createArchiveFromUrls = async (urls, options) => {
|
|
576
|
-
const opfFileData = `
|
|
397
|
+
}, y = (e) => e.substring(e.lastIndexOf("/") + 1) || e, ve = async (e, i) => {
|
|
398
|
+
const a = `
|
|
577
399
|
<?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
|
|
578
400
|
<metadata>
|
|
579
|
-
<meta property="rendition:layout">${
|
|
580
|
-
${
|
|
401
|
+
<meta property="rendition:layout">${i != null && i.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
|
|
402
|
+
${i != null && i.useRenditionFlow ? '<meta property="rendition:flow">scrolled-continuous</meta>' : ""}
|
|
581
403
|
</metadata>
|
|
582
404
|
<manifest>
|
|
583
|
-
${
|
|
405
|
+
${e.map((n) => `<item id="${y(n)}" href="${n}" media-type="${W(n)}"/>`).join(`
|
|
584
406
|
`)}
|
|
585
407
|
</manifest>
|
|
586
408
|
<spine>
|
|
587
|
-
${
|
|
409
|
+
${e.map((n) => `<itemref idref="${y(n)}" />`).join(`
|
|
588
410
|
`)}
|
|
589
411
|
</spine>
|
|
590
412
|
</package>
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
base64: async () => ``,
|
|
413
|
+
`, r = e.map((n) => ({
|
|
414
|
+
dir: !1,
|
|
415
|
+
basename: y(n),
|
|
416
|
+
encodingFormat: W(n),
|
|
417
|
+
uri: n,
|
|
418
|
+
size: 100 / e.length,
|
|
419
|
+
base64: async () => "",
|
|
599
420
|
blob: async () => new Blob(),
|
|
600
|
-
string: async () =>
|
|
421
|
+
string: async () => ""
|
|
601
422
|
}));
|
|
602
|
-
const opfFile = {
|
|
603
|
-
dir: false,
|
|
604
|
-
basename: `content.opf`,
|
|
605
|
-
uri: `content.opf`,
|
|
606
|
-
size: 0,
|
|
607
|
-
base64: async () => opfFileData,
|
|
608
|
-
blob: async () => new Blob(),
|
|
609
|
-
string: async () => opfFileData
|
|
610
|
-
};
|
|
611
423
|
return {
|
|
612
|
-
filename:
|
|
613
|
-
files: [
|
|
424
|
+
filename: "",
|
|
425
|
+
files: [{
|
|
426
|
+
dir: !1,
|
|
427
|
+
basename: "content.opf",
|
|
428
|
+
uri: "content.opf",
|
|
429
|
+
size: 0,
|
|
430
|
+
base64: async () => a,
|
|
431
|
+
blob: async () => new Blob(),
|
|
432
|
+
string: async () => a
|
|
433
|
+
}, ...r]
|
|
614
434
|
};
|
|
615
|
-
}
|
|
616
|
-
const
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
const base64data = reader.result;
|
|
621
|
-
resolve(base64data);
|
|
435
|
+
}, fe = async (e) => new Promise((i) => {
|
|
436
|
+
const a = new FileReader();
|
|
437
|
+
a.readAsDataURL(e), a.onloadend = function() {
|
|
438
|
+
const r = a.result;
|
|
439
|
+
i(r);
|
|
622
440
|
};
|
|
623
|
-
})
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
direction
|
|
441
|
+
}), Fe = async (e, {
|
|
442
|
+
mimeType: i,
|
|
443
|
+
direction: a
|
|
627
444
|
} = { mimeType: "text/plain" }) => {
|
|
628
|
-
const
|
|
445
|
+
const r = `
|
|
629
446
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
630
447
|
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="ja" prefix="rendition: http://www.idpf.org/vocab/rendition/#"
|
|
631
448
|
unique-identifier="ootuya-id">
|
|
@@ -636,110 +453,86 @@ const createArchiveFromText = async (content, {
|
|
|
636
453
|
<manifest>
|
|
637
454
|
<item id="p01" href="p01.txt" media-type="text/plain"/>
|
|
638
455
|
</manifest>
|
|
639
|
-
<spine page-progression-direction="${
|
|
456
|
+
<spine page-progression-direction="${a ?? "ltr"}">
|
|
640
457
|
<itemref idref="p01" />
|
|
641
458
|
</spine>
|
|
642
459
|
</package>
|
|
643
460
|
`;
|
|
644
|
-
|
|
645
|
-
filename:
|
|
461
|
+
return {
|
|
462
|
+
filename: "content.txt",
|
|
646
463
|
files: [
|
|
647
464
|
{
|
|
648
|
-
dir:
|
|
649
|
-
basename:
|
|
650
|
-
uri:
|
|
651
|
-
blob: async () => new Blob([
|
|
652
|
-
string: async () =>
|
|
653
|
-
base64: async () => btoa(
|
|
465
|
+
dir: !1,
|
|
466
|
+
basename: y("generated.opf"),
|
|
467
|
+
uri: "generated.opf",
|
|
468
|
+
blob: async () => new Blob([r]),
|
|
469
|
+
string: async () => r,
|
|
470
|
+
base64: async () => btoa(r),
|
|
654
471
|
size: 0
|
|
655
472
|
},
|
|
656
473
|
{
|
|
657
|
-
dir:
|
|
658
|
-
basename:
|
|
659
|
-
uri:
|
|
660
|
-
blob: async () =>
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
string: async () => {
|
|
666
|
-
if (typeof content === `string`)
|
|
667
|
-
return content;
|
|
668
|
-
return content.text();
|
|
669
|
-
},
|
|
670
|
-
base64: async () => {
|
|
671
|
-
if (typeof content === `string`)
|
|
672
|
-
return btoa(content);
|
|
673
|
-
return blobToBase64(content);
|
|
674
|
-
},
|
|
675
|
-
size: typeof content === `string` ? content.length : content.size,
|
|
676
|
-
encodingFormat: mimeType
|
|
474
|
+
dir: !1,
|
|
475
|
+
basename: y("p01.txt"),
|
|
476
|
+
uri: "p01.txt",
|
|
477
|
+
blob: async () => typeof e == "string" ? new Blob([e]) : e,
|
|
478
|
+
string: async () => typeof e == "string" ? e : e.text(),
|
|
479
|
+
base64: async () => typeof e == "string" ? btoa(e) : fe(e),
|
|
480
|
+
size: typeof e == "string" ? e.length : e.size,
|
|
481
|
+
encodingFormat: i
|
|
677
482
|
}
|
|
678
483
|
]
|
|
679
484
|
};
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
files
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
string: () => file.async(`string`),
|
|
695
|
-
base64: () => file.async(`base64`),
|
|
696
|
-
...file.internalStream && {
|
|
697
|
-
stream: file.internalStream
|
|
485
|
+
}, xe = async (e, { orderByAlpha: i, name: a } = {}) => {
|
|
486
|
+
let r = Object.values(e.files);
|
|
487
|
+
i && (r = r.sort((n, o) => k(n.name, o.name)));
|
|
488
|
+
const t = {
|
|
489
|
+
filename: a || "",
|
|
490
|
+
files: r.map((n) => ({
|
|
491
|
+
dir: n.dir,
|
|
492
|
+
basename: y(n.name),
|
|
493
|
+
uri: n.name,
|
|
494
|
+
blob: () => n.async("blob"),
|
|
495
|
+
string: () => n.async("string"),
|
|
496
|
+
base64: () => n.async("base64"),
|
|
497
|
+
...n.internalStream && {
|
|
498
|
+
stream: n.internalStream
|
|
698
499
|
},
|
|
699
500
|
// this is private API
|
|
700
501
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
701
502
|
// @ts-ignore
|
|
702
|
-
size:
|
|
503
|
+
size: n._data.uncompressedSize
|
|
703
504
|
}))
|
|
704
505
|
};
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
files: files.map((file) => ({
|
|
716
|
-
dir: file.isDir,
|
|
717
|
-
basename: getUriBasename(file.name),
|
|
718
|
-
uri: file.name,
|
|
719
|
-
blob: async () => new Blob([await file.data()]),
|
|
506
|
+
return h.log("Generated archive", t), t;
|
|
507
|
+
}, $e = async (e, { orderByAlpha: i, name: a } = {}) => {
|
|
508
|
+
let r = e;
|
|
509
|
+
return i && (r = r.sort((t, n) => k(t.name, n.name))), {
|
|
510
|
+
filename: a || "",
|
|
511
|
+
files: r.map((t) => ({
|
|
512
|
+
dir: t.isDir,
|
|
513
|
+
basename: y(t.name),
|
|
514
|
+
uri: t.name,
|
|
515
|
+
blob: async () => new Blob([await t.data()]),
|
|
720
516
|
string: async () => {
|
|
721
|
-
const
|
|
722
|
-
return String.fromCharCode.apply(null, Array.from(new Uint16Array(
|
|
517
|
+
const n = await t.data();
|
|
518
|
+
return String.fromCharCode.apply(null, Array.from(new Uint16Array(n)));
|
|
723
519
|
},
|
|
724
|
-
base64: async () =>
|
|
725
|
-
|
|
726
|
-
},
|
|
727
|
-
size: file.size
|
|
520
|
+
base64: async () => "",
|
|
521
|
+
size: t.size
|
|
728
522
|
}))
|
|
729
523
|
};
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
Report.enable(!!enableReport);
|
|
524
|
+
}, Ne = ({ enableReport: e } = {}) => {
|
|
525
|
+
h.enable(!!e);
|
|
733
526
|
};
|
|
734
527
|
export {
|
|
735
|
-
configure,
|
|
736
|
-
createArchiveFromArrayBufferList,
|
|
737
|
-
createArchiveFromJszip,
|
|
738
|
-
createArchiveFromText,
|
|
739
|
-
createArchiveFromUrls,
|
|
740
|
-
generateManifestFromArchive,
|
|
741
|
-
generateResourceFromArchive,
|
|
742
|
-
generateResourceFromError,
|
|
743
|
-
getArchiveOpfInfo
|
|
528
|
+
Ne as configure,
|
|
529
|
+
$e as createArchiveFromArrayBufferList,
|
|
530
|
+
xe as createArchiveFromJszip,
|
|
531
|
+
Fe as createArchiveFromText,
|
|
532
|
+
ve as createArchiveFromUrls,
|
|
533
|
+
we as generateManifestFromArchive,
|
|
534
|
+
ye as generateResourceFromArchive,
|
|
535
|
+
be as generateResourceFromError,
|
|
536
|
+
x as getArchiveOpfInfo
|
|
744
537
|
};
|
|
745
538
|
//# sourceMappingURL=prose-streamer.js.map
|