@prose-reader/streamer 1.170.0 → 1.172.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -35,52 +35,52 @@ const w = {
35
35
  ));
36
36
  },
37
37
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
38
- measurePerformance: (e, t, i) => (...r) => {
39
- const n = performance.now(), s = i(...r);
40
- if (s != null && s.then)
41
- return s.then((a) => {
38
+ measurePerformance: (e, t, i) => (...s) => {
39
+ const n = performance.now(), r = i(...s);
40
+ if (r != null && r.then)
41
+ return r.then((a) => {
42
42
  const c = performance.now();
43
43
  return w.metric({ name: e, duration: c - n }, t), a;
44
44
  });
45
45
  const o = performance.now();
46
- return w.metric({ name: e, duration: o - n }, t), s;
46
+ return w.metric({ name: e, duration: o - n }, t), r;
47
47
  }
48
48
  }, Fe = (e) => {
49
49
  var i;
50
- const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((r) => r.attr.name === "calibre:cover");
50
+ const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((s) => s.attr.name === "calibre:cover");
51
51
  return !!(t && t.attr.name === "calibre:cover");
52
52
  }, Ae = (e) => {
53
- var t, i, r;
54
- return (r = (i = (t = e.descendantWithPath("body")) == null ? void 0 : t.descendantWithPath("div")) == null ? void 0 : i.childrenNamed("svg")) == null ? void 0 : r.find(
53
+ var t, i, s;
54
+ return (s = (i = (t = e.descendantWithPath("body")) == null ? void 0 : t.descendantWithPath("div")) == null ? void 0 : i.childrenNamed("svg")) == null ? void 0 : s.find(
55
55
  (n) => n.attr.width === "100%" && n.attr.preserveAspectRatio === "none"
56
56
  );
57
57
  }, Te = ({ archive: e, resourcePath: t }) => async (i) => {
58
- const r = Object.values(e.files).find(
58
+ const s = Object.values(e.files).find(
59
59
  (n) => n.uri === t
60
60
  );
61
- if (r != null && r.basename.endsWith(".xhtml")) {
62
- const n = i.body ?? await r.string(), s = new de(n);
63
- if (Fe(s)) {
64
- const o = Ae(s);
61
+ if (s != null && s.basename.endsWith(".xhtml")) {
62
+ const n = i.body ?? await s.string(), r = new de(n);
63
+ if (Fe(r)) {
64
+ const o = Ae(r);
65
65
  return o && delete o.attr.preserveAspectRatio, {
66
66
  ...i,
67
- body: s == null ? void 0 : s.toString()
67
+ body: r == null ? void 0 : r.toString()
68
68
  };
69
69
  }
70
70
  }
71
71
  return i;
72
72
  }, Le = ({ archive: e, resourcePath: t }) => async (i) => Te({ archive: e, resourcePath: t })(i), We = ({ archive: e, resourcePath: t }) => async (i) => {
73
- const r = Object.values(e.files).find(
73
+ const s = Object.values(e.files).find(
74
74
  (n) => n.uri === t
75
75
  );
76
- if (r != null && r.basename.endsWith(".css")) {
77
- const s = (i.body ?? await r.string()).replaceAll(
76
+ if (s != null && s.basename.endsWith(".css")) {
77
+ const r = (i.body ?? await s.string()).replaceAll(
78
78
  "-webkit-writing-mode",
79
79
  "writing-mode"
80
80
  );
81
81
  return {
82
82
  ...i,
83
- body: s
83
+ body: r
84
84
  };
85
85
  }
86
86
  return i;
@@ -88,77 +88,77 @@ const w = {
88
88
  const t = e.lastIndexOf("/");
89
89
  return t >= 0 ? e.substring(0, t) : "";
90
90
  }, te = (e, { basePath: t, baseUrl: i }) => {
91
- const r = {
91
+ const s = {
92
92
  contents: [],
93
93
  path: "",
94
94
  href: "",
95
95
  title: ""
96
96
  };
97
97
  let n = e.childNamed("span") || e.childNamed("a");
98
- r.title = ((n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || ee(n)) ?? "";
99
- let s = n == null ? void 0 : n.name;
100
- s !== "a" && (n = e.descendantWithPath(`${s}.a`), n && (s = n.name.toLowerCase())), s === "a" && (n != null && n.attr.href) && (r.path = k(t, n.attr.href), r.href = k(i, t, n.attr.href));
98
+ s.title = ((n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || ee(n)) ?? "";
99
+ let r = n == null ? void 0 : n.name;
100
+ r !== "a" && (n = e.descendantWithPath(`${r}.a`), n && (r = n.name.toLowerCase())), r === "a" && (n != null && n.attr.href) && (s.path = k(t, n.attr.href), s.href = k(i, t, n.attr.href));
101
101
  const o = e.childNamed("ol");
102
102
  if (o) {
103
103
  const a = o.childrenNamed("li");
104
- a && a.length > 0 && (r.contents = a.map(
104
+ a && a.length > 0 && (s.contents = a.map(
105
105
  (c) => te(c, { basePath: t, baseUrl: i })
106
106
  ));
107
107
  }
108
- return r;
108
+ return s;
109
109
  }, Ne = (e, { basePath: t, baseUrl: i }) => {
110
- var s, o;
111
- const r = [];
110
+ var r, o;
111
+ const s = [];
112
112
  let n;
113
- return e.descendantWithPath("body.nav.ol") ? n = (s = e.descendantWithPath("body.nav.ol")) == null ? void 0 : s.children : e.descendantWithPath("body.section.nav.ol") && (n = (o = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : o.children), n && n.length > 0 && n.filter((a) => a.name === "li").forEach(
114
- (a) => r.push(te(a, { basePath: t, baseUrl: i }))
115
- ), r;
113
+ return e.descendantWithPath("body.nav.ol") ? n = (r = e.descendantWithPath("body.nav.ol")) == null ? void 0 : r.children : e.descendantWithPath("body.section.nav.ol") && (n = (o = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : o.children), n && n.length > 0 && n.filter((a) => a.name === "li").forEach(
114
+ (a) => s.push(te(a, { basePath: t, baseUrl: i }))
115
+ ), s;
116
116
  }, Se = async (e, t, { baseUrl: i }) => {
117
117
  var n;
118
- const r = (n = e.childNamed("manifest")) == null ? void 0 : n.childrenNamed("item").find((s) => s.attr.properties === "nav");
119
- if (r) {
120
- const s = Object.values(t.files).find(
121
- (o) => o.uri.endsWith(r.attr.href || "")
118
+ const s = (n = e.childNamed("manifest")) == null ? void 0 : n.childrenNamed("item").find((r) => r.attr.properties === "nav");
119
+ if (s) {
120
+ const r = Object.values(t.files).find(
121
+ (o) => o.uri.endsWith(s.attr.href || "")
122
122
  );
123
- if (s) {
124
- const o = new $.XmlDocument(await s.string()), a = ke(s.uri);
123
+ if (r) {
124
+ const o = new $.XmlDocument(await r.string()), a = ke(r.uri);
125
125
  return Ne(o, { basePath: a, baseUrl: i });
126
126
  }
127
127
  }
128
128
  }, ne = (e, {
129
129
  opfBasePath: t,
130
130
  baseUrl: i,
131
- prefix: r
131
+ prefix: s
132
132
  }) => {
133
133
  var a, c;
134
- const n = ((a = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : a.attr.src) || "", s = {
135
- title: ((c = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : c.val) || "",
134
+ const n = ((a = e == null ? void 0 : e.childNamed(`${s}content`)) == null ? void 0 : a.attr.src) || "", r = {
135
+ title: ((c = e == null ? void 0 : e.descendantWithPath(`${s}navLabel.${s}text`)) == null ? void 0 : c.val) || "",
136
136
  path: k(t, n),
137
137
  href: k(i, t, n),
138
138
  contents: []
139
- }, o = e.childrenNamed(`${r}navPoint`);
140
- return o && o.length > 0 && (s.contents = o.map(
141
- (l) => ne(l, { opfBasePath: t, baseUrl: i, prefix: r })
142
- )), s;
139
+ }, o = e.childrenNamed(`${s}navPoint`);
140
+ return o && o.length > 0 && (r.contents = o.map(
141
+ (l) => ne(l, { opfBasePath: t, baseUrl: i, prefix: s })
142
+ )), r;
143
143
  }, Pe = (e, { opfBasePath: t, baseUrl: i }) => {
144
144
  var o;
145
- const r = [], n = e.name;
146
- let s = "";
147
- return n.indexOf(":") !== -1 && (s = `${n.split(":")[0]}:`), (o = e.childNamed(`${s}navMap`)) == null || o.childrenNamed(`${s}navPoint`).forEach(
148
- (a) => r.push(ne(a, { opfBasePath: t, baseUrl: i, prefix: s }))
149
- ), r;
145
+ const s = [], n = e.name;
146
+ let r = "";
147
+ return n.indexOf(":") !== -1 && (r = `${n.split(":")[0]}:`), (o = e.childNamed(`${r}navMap`)) == null || o.childrenNamed(`${r}navPoint`).forEach(
148
+ (a) => s.push(ne(a, { opfBasePath: t, baseUrl: i, prefix: r }))
149
+ ), s;
150
150
  }, Ie = async ({
151
151
  opfData: e,
152
152
  opfBasePath: t,
153
153
  baseUrl: i,
154
- archive: r
154
+ archive: s
155
155
  }) => {
156
156
  var o;
157
- const n = e.childNamed("spine"), s = n == null ? void 0 : n.attr.toc;
158
- if (s) {
159
- const a = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((c) => c.attr.id === s);
157
+ const n = e.childNamed("spine"), r = n == null ? void 0 : n.attr.toc;
158
+ if (r) {
159
+ const a = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((c) => c.attr.id === r);
160
160
  if (a) {
161
- const c = `${t}${t === "" ? "" : "/"}${a.attr.href}`, l = Object.values(r.files).find(
161
+ const c = `${t}${t === "" ? "" : "/"}${a.attr.href}`, l = Object.values(s.files).find(
162
162
  (d) => d.uri.endsWith(c)
163
163
  );
164
164
  if (l) {
@@ -168,19 +168,18 @@ const w = {
168
168
  }
169
169
  }
170
170
  }, Ce = async (e, t, { baseUrl: i }) => {
171
- const { basePath: r } = N(t), n = await Ie({
171
+ const { basePath: s } = N(t) || {}, n = await Ie({
172
172
  opfData: e,
173
- opfBasePath: r,
173
+ opfBasePath: s,
174
174
  archive: t,
175
175
  baseUrl: i
176
176
  });
177
177
  return n || await Se(e, t, {
178
- opfBasePath: r,
179
178
  baseUrl: i
180
179
  });
181
180
  }, Re = (e) => {
182
- var r;
183
- const t = ((r = e.attr.properties) == null ? void 0 : r.split(" ")) || [];
181
+ var s;
182
+ const t = ((s = e.attr.properties) == null ? void 0 : s.split(" ")) || [];
184
183
  let i;
185
184
  return t.find((n) => n === "rendition:layout-reflowable") && (i = "reflowable"), t.find((n) => n === "rendition:layout-pre-paginated") && (i = "pre-paginated"), {
186
185
  renditionLayout: i,
@@ -188,7 +187,7 @@ const w = {
188
187
  pageSpreadRight: t.some((n) => n === "page-spread-right") || void 0
189
188
  };
190
189
  }, N = (e) => {
191
- const i = Object.values(e.files).filter((r) => !r.dir).find((r) => r.uri.endsWith(".opf"));
190
+ const i = Object.values(e.files).filter((s) => !s.dir).find((s) => s.uri.endsWith(".opf"));
192
191
  return {
193
192
  data: i,
194
193
  basePath: (i == null ? void 0 : i.uri.substring(0, i.uri.lastIndexOf("/"))) || ""
@@ -196,29 +195,29 @@ const w = {
196
195
  }, re = async ({
197
196
  archive: e
198
197
  }) => {
199
- const { data: t, basePath: i } = N(e), r = await (t == null ? void 0 : t.string());
200
- if (!r) return [];
201
- const n = new $.XmlDocument(r), s = n.childNamed("manifest"), o = n.childNamed("spine"), a = o == null ? void 0 : o.childrenNamed("itemref").map((d) => d.attr.idref), c = (s == null ? void 0 : s.childrenNamed("item").filter((d) => a.includes(d.attr.id || ""))) || [];
198
+ const { data: t, basePath: i } = N(e) || {}, s = await (t == null ? void 0 : t.string());
199
+ if (!s) return [];
200
+ const n = new $.XmlDocument(s), r = n.childNamed("manifest"), o = n.childNamed("spine"), a = o == null ? void 0 : o.childrenNamed("itemref").map((d) => d.attr.idref), c = (r == null ? void 0 : r.childrenNamed("item").filter((d) => a.includes(d.attr.id || ""))) || [];
202
201
  return e.files.filter((d) => c.find((f) => i ? `${i}/${f.attr.href}` === d.uri : `${f.attr.href}` === d.uri));
203
202
  }, je = (e, t, i) => {
204
- const r = e.attr.href || "", n = i == null ? void 0 : i(e);
203
+ const s = e.attr.href || "", n = i == null ? void 0 : i(e);
205
204
  return {
206
- href: t ? `${n}${t}/${r}` : `${n}${r}`,
205
+ href: t ? `${n}${t}/${s}` : `${n}${s}`,
207
206
  id: e.attr.id || "",
208
207
  mediaType: e.attr["media-type"]
209
208
  };
210
209
  }, se = (e, t, i) => {
211
- var s;
212
- const r = e.childNamed("manifest"), { basePath: n } = N(t);
213
- return ((s = r == null ? void 0 : r.childrenNamed("item")) == null ? void 0 : s.map((o) => je(o, n, i))) || [];
210
+ var r;
211
+ const s = e.childNamed("manifest"), { basePath: n } = N(t) || {};
212
+ return ((r = s == null ? void 0 : s.childrenNamed("item")) == null ? void 0 : r.map((o) => je(o, n, i))) || [];
214
213
  }, De = ({ archive: e, baseUrl: t }) => async (i) => {
215
214
  var X;
216
- const { data: r, basePath: n } = N(e);
217
- if (!r)
215
+ const { data: s, basePath: n } = N(e) || {};
216
+ if (!s)
218
217
  return i;
219
- const s = await r.string();
220
- w.log("data", s);
221
- const o = new $.XmlDocument(s), a = await Ce(o, e, { baseUrl: t }) || [], c = o.childNamed("metadata"), l = o.childNamed("manifest"), d = o.childNamed("spine"), f = o.childNamed("guide"), u = c == null ? void 0 : c.childNamed("dc:title"), g = (c == null ? void 0 : c.childrenNamed("meta")) || [], b = g.find(
218
+ const r = await s.string();
219
+ w.log("data", r);
220
+ const o = new $.XmlDocument(r), a = await Ce(o, e, { baseUrl: t }) || [], c = o.childNamed("metadata"), l = o.childNamed("manifest"), d = o.childNamed("spine"), f = o.childNamed("guide"), u = c == null ? void 0 : c.childNamed("dc:title"), g = (c == null ? void 0 : c.childrenNamed("meta")) || [], b = g.find(
222
221
  (m) => m.attr.property === "rendition:layout"
223
222
  ), h = g.find(
224
223
  (m) => m.attr.property === "rendition:flow"
@@ -243,13 +242,13 @@ const w = {
243
242
  */
244
243
  spineItems: (d == null ? void 0 : d.childrenNamed("itemref").map((m, L) => {
245
244
  var V, E;
246
- const p = l == null ? void 0 : l.childrenNamed("item").find((C) => C.attr.id === (m == null ? void 0 : m.attr.idref)), B = (p == null ? void 0 : p.attr.href) || "", ce = ((V = e.files.find((C) => C.uri.endsWith(B))) == null ? void 0 : V.size) || 0, H = t || (/^https?:\/\//.test(B) ? "" : "file://"), U = Re(m);
245
+ const p = l == null ? void 0 : l.childrenNamed("item").find((C) => C.attr.id === (m == null ? void 0 : m.attr.idref)), U = (p == null ? void 0 : p.attr.href) || "", ce = ((V = e.files.find((C) => C.uri.endsWith(U))) == null ? void 0 : V.size) || 0, B = t || (/^https?:\/\//.test(U) ? "" : "file://"), H = Re(m);
247
246
  return {
248
- ...U,
247
+ ...H,
249
248
  id: (p == null ? void 0 : p.attr.id) || "",
250
249
  index: L,
251
- href: (E = p == null ? void 0 : p.attr.href) != null && E.startsWith("https://") ? p == null ? void 0 : p.attr.href : n ? `${H}${n}/${p == null ? void 0 : p.attr.href}` : `${H}${p == null ? void 0 : p.attr.href}`,
252
- renditionLayout: U.renditionLayout ?? y,
250
+ href: (E = p == null ? void 0 : p.attr.href) != null && E.startsWith("https://") ? p == null ? void 0 : p.attr.href : n ? `${B}${n}/${p == null ? void 0 : p.attr.href}` : `${B}${p == null ? void 0 : p.attr.href}`,
251
+ renditionLayout: H.renditionLayout ?? y,
253
252
  progressionWeight: ce / ae,
254
253
  // size: itemSize
255
254
  mediaType: p == null ? void 0 : p.attr["media-type"]
@@ -266,13 +265,13 @@ const w = {
266
265
  }))
267
266
  };
268
267
  }, Oe = async (e, t) => {
269
- var n, s, o;
270
- const r = await ((n = N(e).data) == null ? void 0 : n.string());
271
- if (r) {
272
- const a = new $.XmlDocument(r), c = se(a, e, () => "");
273
- if ((s = c.find(
268
+ var n, r, o;
269
+ const s = await ((n = N(e).data) == null ? void 0 : n.string());
270
+ if (s) {
271
+ const a = new $.XmlDocument(s), c = se(a, e, () => "");
272
+ if ((r = c.find(
274
273
  (d) => t.endsWith(d.href)
275
- )) == null ? void 0 : s.mediaType)
274
+ )) == null ? void 0 : r.mediaType)
276
275
  return {
277
276
  mediaType: (o = c.find((d) => t.endsWith(d.href))) == null ? void 0 : o.mediaType
278
277
  };
@@ -292,17 +291,17 @@ const w = {
292
291
  if (e.endsWith(".svg"))
293
292
  return "image/svg+xml";
294
293
  }, ze = ({ archive: e, resourcePath: t }) => async (i) => {
295
- const r = Object.values(e.files).find(
296
- (s) => s.uri === t
294
+ const s = Object.values(e.files).find(
295
+ (r) => r.uri === t
297
296
  );
298
- if (!r) return i;
297
+ if (!s) return i;
299
298
  const n = await Oe(e, t);
300
299
  return {
301
300
  ...i,
302
301
  params: {
303
302
  ...i.params,
304
- ...(r == null ? void 0 : r.encodingFormat) && {
305
- contentType: r.encodingFormat
303
+ ...(s == null ? void 0 : s.encodingFormat) && {
304
+ contentType: s.encodingFormat
306
305
  },
307
306
  ...n.mediaType && {
308
307
  contentType: n.mediaType
@@ -361,11 +360,11 @@ const w = {
361
360
  "script",
362
361
  "style"
363
362
  ], Xe = ({ archive: e, resourcePath: t }) => async (i) => {
364
- const r = Object.values(e.files).find(
363
+ const s = Object.values(e.files).find(
365
364
  (n) => n.uri === t
366
365
  );
367
- if (r != null && r.basename.endsWith(".xhtml")) {
368
- const n = i.body ?? await r.string();
366
+ if (s != null && s.basename.endsWith(".xhtml")) {
367
+ const n = i.body ?? await s.string();
369
368
  if (!new RegExp(
370
369
  `<(${Z.join("|")})[\\s/>]`,
371
370
  "i"
@@ -384,13 +383,13 @@ const w = {
384
383
  };
385
384
  }
386
385
  return i;
387
- }, Be = async (e, t) => {
386
+ }, Ue = async (e, t) => {
388
387
  const i = Object.values(e.files).find(
389
- (s) => s.uri === t
388
+ (r) => r.uri === t
390
389
  );
391
390
  if (!i)
392
391
  throw new Error("no file found");
393
- const r = {
392
+ const s = {
394
393
  params: {}
395
394
  }, n = [
396
395
  ze({ archive: e, resourcePath: t }),
@@ -399,29 +398,29 @@ const w = {
399
398
  Le({ archive: e, resourcePath: t })
400
399
  ];
401
400
  try {
402
- const s = await n.reduce(async (o, a) => await a(await o), Promise.resolve(r));
403
- return w.log("Generated resource", t, s), {
404
- ...s,
405
- body: s.body ?? await i.blob()
401
+ const r = await n.reduce(async (o, a) => await a(await o), Promise.resolve(s));
402
+ return w.log("Generated resource", t, r), {
403
+ ...r,
404
+ body: r.body ?? await i.blob()
406
405
  };
407
- } catch (s) {
408
- throw w.error(s), s;
406
+ } catch (r) {
407
+ throw w.error(r), r;
409
408
  }
410
- }, He = ({ archive: e, baseUrl: t }) => async () => {
411
- var r;
409
+ }, Be = ({ archive: e, baseUrl: t }) => async () => {
410
+ var s;
412
411
  const i = Object.values(e.files).filter((n) => !n.dir);
413
412
  return {
414
413
  filename: e.filename,
415
- title: ((r = e.files.find(({ dir: n }) => n)) == null ? void 0 : r.basename.replace(/\/$/, "")) || "",
414
+ title: ((s = e.files.find(({ dir: n }) => n)) == null ? void 0 : s.basename.replace(/\/$/, "")) || "",
416
415
  renditionLayout: void 0,
417
416
  renditionSpread: "auto",
418
417
  readingDirection: "ltr",
419
- spineItems: i.filter((n) => !n.basename.endsWith(".db")).map((n, s) => ({
418
+ spineItems: i.filter((n) => !n.basename.endsWith(".db")).map((n, r) => ({
420
419
  // some books such as cbz can have same basename inside different sub folder
421
420
  // we need to make sure to have unique index
422
421
  // /chap01/01.png, /chap02/01.png, etc
423
- id: `${s}.${n.basename}`,
424
- index: s,
422
+ id: `${r}.${n.basename}`,
423
+ index: r,
425
424
  href: encodeURI(`${t}${n.uri}`),
426
425
  renditionLayout: void 0,
427
426
  progressionWeight: 1 / i.length,
@@ -429,33 +428,33 @@ const w = {
429
428
  pageSpreadRight: void 0,
430
429
  mediaType: n.encodingFormat
431
430
  })),
432
- items: i.map((n, s) => ({
433
- id: `${s}.${n.basename}`,
431
+ items: i.map((n, r) => ({
432
+ id: `${r}.${n.basename}`,
434
433
  href: encodeURI(`${t}${n.uri}`)
435
434
  }))
436
435
  };
437
- }, Ue = async (e) => {
436
+ }, He = async (e) => {
438
437
  const t = {
439
438
  renditionLayout: void 0
440
439
  };
441
440
  return await Promise.all(
442
441
  e.files.map(async (i) => {
443
- var r, n;
442
+ var s, n;
444
443
  if (i.uri.endsWith("com.kobobooks.display-options.xml")) {
445
- const o = (r = new $.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : r.childNamed("option");
444
+ const o = (s = new $.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : s.childNamed("option");
446
445
  ((n = o == null ? void 0 : o.attr) == null ? void 0 : n.name) === "fixed-layout" && o.val === "true" && (t.renditionLayout = "pre-paginated");
447
446
  }
448
447
  })
449
448
  ), t;
450
449
  }, Ve = ({ archive: e }) => async (t) => {
451
- const i = await Ue(e);
450
+ const i = await He(e);
452
451
  return {
453
452
  ...t,
454
453
  renditionLayout: t.renditionLayout ?? i.renditionLayout
455
454
  };
456
455
  }, Ee = (e) => {
457
456
  var i;
458
- const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((r) => r.attr.name === "viewport");
457
+ const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((s) => s.attr.name === "viewport");
459
458
  return !!(t && t.attr.name === "viewport");
460
459
  }, _e = (e) => e.reduce(async (t, i) => {
461
460
  if (!await t || !pe({
@@ -466,13 +465,13 @@ const w = {
466
465
  const n = await i.string();
467
466
  return n ? Ee(new $.XmlDocument(n)) : !1;
468
467
  }, Promise.resolve(!0)), qe = ({ archive: e }) => async (t) => {
469
- if (t.renditionLayout === "reflowable" && t.spineItems.every((r) => r.renditionLayout === "reflowable")) {
470
- const r = await re({ archive: e });
471
- if (await _e(r))
468
+ if (t.renditionLayout === "reflowable" && t.spineItems.every((s) => s.renditionLayout === "reflowable")) {
469
+ const s = await re({ archive: e });
470
+ if (await _e(s))
472
471
  return {
473
472
  ...t,
474
- spineItems: t.spineItems.map((s) => ({
475
- ...s,
473
+ spineItems: t.spineItems.map((r) => ({
474
+ ...r,
476
475
  renditionLayout: "pre-paginated"
477
476
  })),
478
477
  renditionLayout: "pre-paginated"
@@ -481,16 +480,16 @@ const w = {
481
480
  return t;
482
481
  }, z = (e, t) => {
483
482
  var n;
484
- const i = e.split(/(\d+)/), r = t.split(/(\d+)/);
485
- for (let s = 0, o = i.length; s < o; s++)
486
- if (i[s] !== r[s])
487
- return (n = i[s]) != null && n.match(/\d/) ? +(i[s] || "") - +(r[s] || "") : (i[s] || "").localeCompare(r[s] || "");
483
+ const i = e.split(/(\d+)/), s = t.split(/(\d+)/);
484
+ for (let r = 0, o = i.length; r < o; r++)
485
+ if (i[r] !== s[r])
486
+ return (n = i[r]) != null && n.match(/\d/) ? +(i[r] || "") - +(s[r] || "") : (i[r] || "").localeCompare(s[r] || "");
488
487
  return 1;
489
488
  }, Ge = ({ archive: e, baseUrl: t }) => async (i) => {
490
489
  if (i.nav) return i;
491
- const r = [...e.files].sort(
490
+ const s = [...e.files].sort(
492
491
  (a, c) => z(a.uri, c.uri)
493
- ), n = Object.values(r), s = (a, c, l, d, f) => {
492
+ ), n = Object.values(s), r = (a, c, l, d, f) => {
494
493
  const u = a.find((h) => h.title === c), [g, ...b] = l;
495
494
  return u ? g ? [
496
495
  ...a.filter((x) => x !== u),
@@ -498,7 +497,7 @@ const w = {
498
497
  ...u,
499
498
  contents: [
500
499
  ...u.contents,
501
- ...s(
500
+ ...r(
502
501
  u.contents,
503
502
  g,
504
503
  b,
@@ -517,7 +516,7 @@ const w = {
517
516
  ] : a : g ? [
518
517
  ...a,
519
518
  {
520
- contents: s(
519
+ contents: r(
521
520
  [],
522
521
  g,
523
522
  b,
@@ -543,7 +542,7 @@ const w = {
543
542
  const d = c.uri.split("/").slice(0, -1), [f, ...u] = d;
544
543
  if (f) {
545
544
  const g = k(t, encodeURI(c.uri)).replace(/\/$/, ""), b = c.uri.replace(/\/$/, "");
546
- return s(a, f, u, g, b);
545
+ return r(a, f, u, g, b);
547
546
  }
548
547
  return a;
549
548
  },
@@ -556,13 +555,13 @@ const w = {
556
555
  }
557
556
  };
558
557
  }, Ke = ({ archive: e }) => async (t) => {
559
- var s;
558
+ var r;
560
559
  const i = e.files.find(
561
560
  (o) => o.basename.toLowerCase() === "comicinfo.xml"
562
561
  );
563
562
  if (!i)
564
563
  return t;
565
- const r = {
564
+ const s = {
566
565
  ...t,
567
566
  spineItems: t.spineItems.filter((o) => !o.id.toLowerCase().endsWith("comicinfo.xml")).map((o, a, c) => ({
568
567
  ...o,
@@ -570,36 +569,36 @@ const w = {
570
569
  }))
571
570
  }, n = await i.string();
572
571
  try {
573
- const a = ((s = new $.XmlDocument(n).childNamed("Manga")) == null ? void 0 : s.val) || "unknown";
572
+ const a = ((r = new $.XmlDocument(n).childNamed("Manga")) == null ? void 0 : r.val) || "unknown";
574
573
  return {
575
- ...r,
574
+ ...s,
576
575
  readingDirection: a === "YesAndRightToLeft" ? "rtl" : "ltr"
577
576
  };
578
577
  } catch (o) {
579
578
  return console.error(`Unable to parse comicinfo.xml for content
580
- `, n), console.error(o), r;
579
+ `, n), console.error(o), s;
581
580
  }
582
581
  }, Je = (e) => e.files.some((t) => t.basename.endsWith(".opf")), Ye = ({ archive: e }) => async (t) => Je(e) ? t : {
583
582
  ...t,
584
- spineItems: t.spineItems.map((r) => {
583
+ spineItems: t.spineItems.map((s) => {
585
584
  const n = e.files.find(
586
- (o) => decodeURI(r.href).endsWith(o.uri)
587
- ), s = ue((n == null ? void 0 : n.encodingFormat) ?? "") ?? O((n == null ? void 0 : n.basename) ?? "");
585
+ (o) => decodeURI(s.href).endsWith(o.uri)
586
+ ), r = ue((n == null ? void 0 : n.encodingFormat) ?? "") ?? O((n == null ? void 0 : n.basename) ?? "");
588
587
  return {
589
- ...r,
590
- renditionLayout: s != null && s.startsWith("image/") ? "pre-paginated" : r.renditionLayout
588
+ ...s,
589
+ renditionLayout: r != null && r.startsWith("image/") ? "pre-paginated" : s.renditionLayout
591
590
  };
592
591
  })
593
592
  }, Qe = ({ archive: e }) => async (t) => {
594
- var n, s;
593
+ var n, r;
595
594
  const i = e.files.find(
596
595
  (o) => o.basename.toLowerCase() === "com.apple.ibooks.display-options.xml"
597
596
  );
598
597
  if (!i)
599
598
  return t;
600
- const r = await (await i.blob()).text();
599
+ const s = await (await i.blob()).text();
601
600
  try {
602
- const a = new $.XmlDocument(r).childNamed("platform"), c = ((s = (n = a == null ? void 0 : a.childrenNamed("option")) == null ? void 0 : n.find((l) => l.attr.name === "fixed-layout")) == null ? void 0 : s.val) || "false";
601
+ const a = new $.XmlDocument(s).childNamed("platform"), c = ((r = (n = a == null ? void 0 : a.childrenNamed("option")) == null ? void 0 : n.find((l) => l.attr.name === "fixed-layout")) == null ? void 0 : r.val) || "false";
603
602
  return {
604
603
  ...t,
605
604
  renditionLayout: c === "true" ? "pre-paginated" : t.renditionLayout
@@ -608,24 +607,24 @@ const w = {
608
607
  return console.error(
609
608
  `Unable to parse com.apple.ibooks.display-options.xml for content
610
609
  `,
611
- r
610
+ s
612
611
  ), console.error(o), t;
613
612
  }
614
613
  }, Ze = async (e, { baseUrl: t = "" } = {}) => {
615
614
  const i = [
616
615
  De({ archive: e, baseUrl: t }),
617
- Ke({ archive: e, baseUrl: t }),
618
- Qe({ archive: e, baseUrl: t }),
619
- Ye({ archive: e, baseUrl: t }),
620
- qe({ archive: e, baseUrl: t }),
621
- Ve({ archive: e, baseUrl: t }),
616
+ Ke({ archive: e }),
617
+ Qe({ archive: e }),
618
+ Ye({ archive: e }),
619
+ qe({ archive: e }),
620
+ Ve({ archive: e }),
622
621
  Ge({ archive: e, baseUrl: t })
623
622
  ];
624
623
  try {
625
- const r = He({ archive: e, baseUrl: t })(), n = await i.reduce(async (s, o) => await o(await s), r);
624
+ const s = Be({ archive: e, baseUrl: t })(), n = await i.reduce(async (r, o) => await o(await r), s);
626
625
  return w.log("Generated manifest", n), n;
627
- } catch (r) {
628
- throw w.error(r), r;
626
+ } catch (s) {
627
+ throw w.error(s), s;
629
628
  }
630
629
  }, at = async (e, t) => {
631
630
  const i = `
@@ -636,22 +635,22 @@ const w = {
636
635
  </metadata>
637
636
  <manifest>
638
637
  ${e.map(
639
- (s) => `<item id="${A(s)}" href="${s}" media-type="${O(s)}"/>`
638
+ (r) => `<item id="${A(r)}" href="${r}" media-type="${O(r)}"/>`
640
639
  ).join(`
641
640
  `)}
642
641
  </manifest>
643
642
  <spine>
644
- ${e.map((s) => `<itemref idref="${A(s)}" />`).join(`
643
+ ${e.map((r) => `<itemref idref="${A(r)}" />`).join(`
645
644
  `)}
646
645
  </spine>
647
646
  </package>
648
- `, r = e.map((s) => ({
647
+ `, s = e.map((r) => ({
649
648
  dir: !1,
650
- basename: A(s),
651
- encodingFormat: O(s),
652
- uri: s,
649
+ basename: A(r),
650
+ encodingFormat: O(r),
651
+ uri: r,
653
652
  size: 100 / e.length,
654
- blob: async () => (await fetch(s)).blob(),
653
+ blob: async () => (await fetch(r)).blob(),
655
654
  string: async () => ""
656
655
  }));
657
656
  return {
@@ -663,14 +662,14 @@ const w = {
663
662
  size: 0,
664
663
  blob: async () => new Blob(),
665
664
  string: async () => i
666
- }, ...r],
665
+ }, ...s],
667
666
  close: () => Promise.resolve()
668
667
  };
669
668
  }, ct = async (e, {
670
669
  mimeType: t,
671
670
  direction: i
672
671
  } = { mimeType: "text/plain" }) => {
673
- const r = `
672
+ const s = `
674
673
  <?xml version="1.0" encoding="UTF-8"?>
675
674
  <package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="ja" prefix="rendition: http://www.idpf.org/vocab/rendition/#"
676
675
  unique-identifier="ootuya-id">
@@ -693,8 +692,8 @@ const w = {
693
692
  dir: !1,
694
693
  basename: A("generated.opf"),
695
694
  uri: "generated.opf",
696
- blob: async () => new Blob([r]),
697
- string: async () => r,
695
+ blob: async () => new Blob([s]),
696
+ string: async () => s,
698
697
  size: 0
699
698
  },
700
699
  {
@@ -710,28 +709,28 @@ const w = {
710
709
  close: () => Promise.resolve()
711
710
  };
712
711
  }, dt = async (e, { orderByAlpha: t, name: i } = {}) => {
713
- let r = Object.values(e.files);
714
- t && (r = r.slice().sort((s, o) => z(s.name, o.name)));
712
+ let s = Object.values(e.files);
713
+ t && (s = s.slice().sort((r, o) => z(r.name, o.name)));
715
714
  const n = {
716
715
  filename: i || "",
717
- files: r.map((s) => ({
718
- dir: s.dir,
719
- basename: A(s.name),
720
- uri: s.name,
721
- blob: () => s.async("blob"),
722
- string: () => s.async("string"),
723
- ...s.internalStream && {
724
- stream: s.internalStream
716
+ files: s.map((r) => ({
717
+ dir: r.dir,
718
+ basename: A(r.name),
719
+ uri: r.name,
720
+ blob: () => r.async("blob"),
721
+ string: () => r.async("string"),
722
+ ...r.internalStream && {
723
+ stream: r.internalStream
725
724
  },
726
725
  // this is private API
727
726
  // @ts-ignore
728
- size: s._data.uncompressedSize
727
+ size: r._data.uncompressedSize
729
728
  })),
730
729
  close: () => Promise.resolve()
731
730
  };
732
731
  return w.log("Generated archive", n), n;
733
732
  }, lt = async (e, { name: t } = {}) => {
734
- const i = await e.getFilesArray(), r = {
733
+ const i = await e.getFilesArray(), s = {
735
734
  close: () => e.close(),
736
735
  filename: t ?? "",
737
736
  files: i.map((n) => ({
@@ -743,21 +742,21 @@ const w = {
743
742
  string: async () => (await n.file.extract()).text()
744
743
  }))
745
744
  };
746
- return w.log("Generated archive", r), r;
745
+ return w.log("Generated archive", s), s;
747
746
  }, ft = async (e, { orderByAlpha: t, name: i } = {}) => {
748
- let r = e;
749
- return t && (r = r.slice().sort((n, s) => z(n.name, s.name))), {
747
+ let s = e;
748
+ return t && (s = s.slice().sort((n, r) => z(n.name, r.name))), {
750
749
  filename: i || "",
751
- files: r.map((n) => ({
750
+ files: s.map((n) => ({
752
751
  dir: n.isDir,
753
752
  basename: A(n.name),
754
753
  uri: n.name,
755
754
  blob: async () => new Blob([await n.data()]),
756
755
  string: async () => {
757
- const s = await n.data();
756
+ const r = await n.data();
758
757
  return String.fromCharCode.apply(
759
758
  null,
760
- Array.from(new Uint16Array(s))
759
+ Array.from(new Uint16Array(r))
761
760
  );
762
761
  },
763
762
  size: n.size
@@ -805,15 +804,15 @@ const tt = ({
805
804
  cleanArchiveAfter: t = 5 * 60 * 1e3
806
805
  // 5mn
807
806
  }) => {
808
- const i = new R(), r = new R(), n = new R(), s = {}, o = i.pipe(
807
+ const i = new R(), s = new R(), n = new R(), r = {}, o = i.pipe(
809
808
  M((l) => {
810
- const d = s[l];
809
+ const d = r[l];
811
810
  if (!d || d.state.status !== "idle") return _;
812
811
  let f = !1;
813
812
  const u = (y) => {
814
813
  var S;
815
- const v = s[y];
816
- delete s[y], f || ((S = v == null ? void 0 : v.state.archive) == null || S.close(), f = !0);
814
+ const v = r[y];
815
+ delete r[y], f || ((S = v == null ? void 0 : v.state.archive) == null || S.close(), f = !0);
817
816
  };
818
817
  d.update({
819
818
  status: "loading"
@@ -847,11 +846,11 @@ const tt = ({
847
846
  })
848
847
  );
849
848
  }),
850
- ge(r)
849
+ ge(s)
851
850
  ), a = (l) => {
852
851
  let d = !1;
853
- const f = s[l] ?? new et(t);
854
- s[l] = f, f.update({
852
+ const f = r[l] ?? new et(t);
853
+ r[l] = f, f.update({
855
854
  locks: f.state.locks + 1
856
855
  });
857
856
  const u = () => {
@@ -883,16 +882,16 @@ const tt = ({
883
882
  return o.subscribe(), {
884
883
  access: a,
885
884
  purge: c,
886
- archives: s
885
+ archives: r
887
886
  };
888
887
  };
889
888
  class nt {
890
889
  constructor({
891
890
  onError: t,
892
891
  onManifestSuccess: i,
893
- ...r
892
+ ...s
894
893
  }) {
895
- this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = tt(r), this.onManifestSuccess = i ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
894
+ this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = tt(s), this.onManifestSuccess = i ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
896
895
  }
897
896
  prune() {
898
897
  this.epubLoader.purge();
@@ -902,12 +901,12 @@ class nt {
902
901
  }
903
902
  accessArchiveWithoutLock(t) {
904
903
  return this.accessArchive(t).pipe(
905
- F(({ archive: i, release: r }) => (r(), i))
904
+ F(({ archive: i, release: s }) => (s(), i))
906
905
  );
907
906
  }
908
907
  fetchManifest({ key: t, baseUrl: i }) {
909
- const r = this.accessArchive(t).pipe(
910
- M(({ archive: n, release: s }) => P(
908
+ const s = this.accessArchive(t).pipe(
909
+ M(({ archive: n, release: r }) => P(
911
910
  Ze(n, { baseUrl: i })
912
911
  ).pipe(
913
912
  W(
@@ -919,22 +918,22 @@ class nt {
919
918
  })
920
919
  ),
921
920
  K(() => {
922
- s();
921
+ r();
923
922
  })
924
923
  )),
925
924
  I((n) => J(this.onError(n)))
926
925
  );
927
- return Y(r);
926
+ return Y(s);
928
927
  }
929
928
  fetchResource({
930
929
  key: t,
931
930
  resourcePath: i
932
931
  }) {
933
- const r = this.accessArchive(t).pipe(
934
- M(({ archive: n, release: s }) => {
932
+ const s = this.accessArchive(t).pipe(
933
+ M(({ archive: n, release: r }) => {
935
934
  const o = i.replaceAll("file://", "");
936
935
  return P(
937
- Be(n, o)
936
+ Ue(n, o)
938
937
  ).pipe(
939
938
  F(
940
939
  (c) => new Response(c.body, {
@@ -947,13 +946,13 @@ class nt {
947
946
  })
948
947
  ),
949
948
  K(() => {
950
- s();
949
+ r();
951
950
  })
952
951
  );
953
952
  }),
954
953
  I((n) => J(this.onError(n)))
955
954
  );
956
- return Y(r);
955
+ return Y(s);
957
956
  }
958
957
  }
959
958
  class ut extends nt {
@@ -967,14 +966,14 @@ class ut extends nt {
967
966
  try {
968
967
  const i = this.getUriInfo(t);
969
968
  if (!i) return;
970
- const r = Q(i.baseUrl), n = t.request.url.substring(
971
- r.length + 1
972
- ), [s = ""] = n.split("/"), o = decodeURIComponent(
973
- Q(n.substring(s.length + 1))
969
+ const s = Q(i.baseUrl), n = t.request.url.substring(
970
+ s.length + 1
971
+ ), [r = ""] = n.split("/"), o = decodeURIComponent(
972
+ Q(n.substring(r.length + 1))
974
973
  );
975
974
  n.endsWith("/manifest") ? t.respondWith(
976
- this.fetchManifest({ key: s, baseUrl: `${r}/${s}/` })
977
- ) : t.respondWith(this.fetchResource({ key: s, resourcePath: o }));
975
+ this.fetchManifest({ key: r, baseUrl: `${s}/${r}/` })
976
+ ) : t.respondWith(this.fetchResource({ key: r, resourcePath: o }));
978
977
  } catch (i) {
979
978
  t.respondWith(new Response(String(i), { status: 500 }));
980
979
  }
@@ -990,7 +989,7 @@ export {
990
989
  ct as createArchiveFromText,
991
990
  at as createArchiveFromUrls,
992
991
  Ze as generateManifestFromArchive,
993
- Be as generateResourceFromArchive,
992
+ Ue as generateResourceFromArchive,
994
993
  N as getArchiveOpfInfo
995
994
  };
996
995
  //# sourceMappingURL=index.js.map