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