@prose-reader/streamer 1.22.0 → 1.24.0

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