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