@prose-reader/streamer 1.133.0 → 1.134.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
@@ -1,32 +1,32 @@
1
- import F, { XmlDocument as pe, XmlTextNode as fe, XmlElement as ue } from "xmldoc";
2
- import { urlJoin as N, isXmlBasedMimeType as me, detectMimeTypeFromName as q } from "@prose-reader/shared";
3
- import { Subject as j, mergeMap as M, EMPTY as G, pairwise as he, filter as D, startWith as ge, from as I, tap as O, catchError as C, switchMap as k, merge as K, takeUntil as ye, map as A, ignoreElements as be, first as we, BehaviorSubject as ve, distinctUntilChanged as $e, shareReplay as xe, NEVER as J, timer as Fe, finalize as Y, of as E, lastValueFrom as Q } from "rxjs";
4
- let S = !1;
1
+ import x, { XmlDocument as de, XmlTextNode as le, XmlElement as pe } from "xmldoc";
2
+ import { urlJoin as L, isXmlBasedMimeType as fe, parseContentType as ue, detectMimeTypeFromName as O } from "@prose-reader/shared";
3
+ import { Subject as R, mergeMap as M, EMPTY as _, pairwise as me, filter as j, startWith as he, from as P, tap as D, catchError as I, switchMap as k, merge as q, takeUntil as ge, map as F, ignoreElements as ye, first as be, BehaviorSubject as we, distinctUntilChanged as ve, shareReplay as $e, NEVER as G, timer as xe, finalize as K, of as J, lastValueFrom as Y } from "rxjs";
4
+ let T = !1;
5
5
  const v = {
6
6
  enable: (e) => {
7
- S = e;
7
+ T = e;
8
8
  },
9
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
10
  log: (...e) => {
11
- S && console.log("[prose-reader-streamer]", ...e);
11
+ T && console.log("[prose-reader-streamer]", ...e);
12
12
  },
13
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
14
  warn: (...e) => {
15
- S && console.warn("[prose-reader-streamer]", ...e);
15
+ T && console.warn("[prose-reader-streamer]", ...e);
16
16
  },
17
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
18
  error: (...e) => {
19
19
  console.error(...e);
20
20
  },
21
21
  time: (e) => {
22
- S && console.time(`[prose-reader-streamer] [metric] ${e}`);
22
+ T && console.time(`[prose-reader-streamer] [metric] ${e}`);
23
23
  },
24
24
  timeEnd: (e) => {
25
- S && console.timeEnd(`[prose-reader-streamer] [metric] ${e}`);
25
+ T && console.timeEnd(`[prose-reader-streamer] [metric] ${e}`);
26
26
  },
27
27
  metric: (e, t = 1 / 0) => {
28
28
  const i = typeof e == "number" ? e : e.duration;
29
- S && (e.duration <= t ? console.log(
29
+ T && (e.duration <= t ? console.log(
30
30
  "[prose-reader-streamer] [metric] ",
31
31
  `${e.name} took ${i}ms`
32
32
  ) : console.warn(
@@ -35,256 +35,247 @@ const v = {
35
35
  ));
36
36
  },
37
37
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- measurePerformance: (e, t = 10, i) => (...s) => {
39
- const n = performance.now(), r = i(...s);
40
- if (r && r.then)
41
- return r.then((o) => {
38
+ measurePerformance: (e, t = 10, i) => (...r) => {
39
+ const n = performance.now(), s = i(...r);
40
+ if (s && s.then)
41
+ return s.then((a) => {
42
42
  const d = performance.now();
43
- return v.metric({ name: e, duration: d - n }, t), o;
43
+ return v.metric({ name: e, duration: d - n }, t), a;
44
44
  });
45
- const a = performance.now();
46
- return v.metric({ name: e, duration: a - n }, t), r;
45
+ const o = performance.now();
46
+ return v.metric({ name: e, duration: o - n }, t), s;
47
47
  }
48
- }, Ae = (e) => {
48
+ }, Fe = (e) => {
49
49
  var i;
50
- const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((s) => s.attr.name === "calibre:cover");
50
+ const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((r) => r.attr.name === "calibre:cover");
51
51
  return !!(t && t.attr.name === "calibre:cover");
52
- }, Te = (e) => {
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(
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(
55
55
  (n) => n.attr.width === "100%" && n.attr.preserveAspectRatio === "none"
56
56
  );
57
- }, Se = ({ archive: e, resourcePath: t }) => async (i) => {
58
- const s = Object.values(e.files).find(
57
+ }, Te = ({ archive: e, resourcePath: t }) => async (i) => {
58
+ const r = Object.values(e.files).find(
59
59
  (n) => n.uri === t
60
60
  );
61
- if (s != null && s.basename.endsWith(".xhtml")) {
62
- const n = i.body ?? await s.string(), r = new pe(n);
63
- if (Ae(r)) {
64
- const a = Te(r);
65
- return a && delete a.attr.preserveAspectRatio, {
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);
65
+ return o && delete o.attr.preserveAspectRatio, {
66
66
  ...i,
67
- body: r == null ? void 0 : r.toString()
67
+ body: s == null ? void 0 : s.toString()
68
68
  };
69
69
  }
70
70
  }
71
71
  return i;
72
- }, We = ({ archive: e, resourcePath: t }) => async (i) => Se({ archive: e, resourcePath: t })(i), ke = ({ archive: e, resourcePath: t }) => async (i) => {
73
- const s = Object.values(e.files).find(
72
+ }, We = ({ archive: e, resourcePath: t }) => async (i) => Te({ archive: e, resourcePath: t })(i), ke = ({ archive: e, resourcePath: t }) => async (i) => {
73
+ const r = Object.values(e.files).find(
74
74
  (n) => n.uri === t
75
75
  );
76
- if (s != null && s.basename.endsWith(".css")) {
77
- const r = (i.body ?? await s.string()).replaceAll(
76
+ if (r != null && r.basename.endsWith(".css")) {
77
+ const s = (i.body ?? await r.string()).replaceAll(
78
78
  "-webkit-writing-mode",
79
79
  "writing-mode"
80
80
  );
81
81
  return {
82
82
  ...i,
83
- body: r
83
+ body: s
84
84
  };
85
85
  }
86
86
  return i;
87
- }, L = (e) => {
88
- const i = Object.values(e.files).filter((s) => !s.dir).find((s) => s.uri.endsWith(".opf"));
89
- return {
90
- data: i,
91
- basePath: (i == null ? void 0 : i.uri.substring(0, i.uri.lastIndexOf("/"))) || ""
92
- };
93
- }, te = (e) => e ? e.children.map((t) => t instanceof fe ? t.text : t instanceof ue ? te(t) : "").join("").trim() : "", T = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Z = (e) => e.endsWith("/") ? e.slice(0, -1) : e, Ne = (e) => {
87
+ }, ee = (e) => e ? e.children.map((t) => t instanceof le ? t.text : t instanceof pe ? ee(t) : "").join("").trim() : "", A = (e) => e.substring(e.lastIndexOf("/") + 1) || e, Q = (e) => e.endsWith("/") ? e.slice(0, -1) : e, Le = (e) => {
94
88
  const t = e.lastIndexOf("/");
95
89
  return t >= 0 ? e.substring(0, t) : "";
96
- }, ne = (e, { basePath: t, baseUrl: i }) => {
97
- const s = {
90
+ }, te = (e, { basePath: t, baseUrl: i }) => {
91
+ const r = {
98
92
  contents: [],
99
93
  path: "",
100
94
  href: "",
101
95
  title: ""
102
96
  };
103
97
  let n = e.childNamed("span") || e.childNamed("a");
104
- s.title = ((n == null ? void 0 : n.attr.title) || (n == null ? void 0 : n.val.trim()) || te(n)) ?? "";
105
- let r = n == null ? void 0 : n.name;
106
- r !== "a" && (n = e.descendantWithPath(`${r}.a`), n && (r = n.name.toLowerCase())), r === "a" && (n != null && n.attr.href) && (s.path = N(t, n.attr.href), s.href = N(i, t, n.attr.href));
107
- const a = e.childNamed("ol");
108
- if (a) {
109
- const o = a.childrenNamed("li");
110
- o && o.length > 0 && (s.contents = o.map(
111
- (d) => ne(d, { basePath: t, baseUrl: i })
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 = L(t, n.attr.href), r.href = L(i, t, n.attr.href));
101
+ const o = e.childNamed("ol");
102
+ if (o) {
103
+ const a = o.childrenNamed("li");
104
+ a && a.length > 0 && (r.contents = a.map(
105
+ (d) => te(d, { basePath: t, baseUrl: i })
112
106
  ));
113
107
  }
114
- return s;
115
- }, Le = (e, { basePath: t, baseUrl: i }) => {
116
- var r, a;
117
- const s = [];
108
+ return r;
109
+ }, Se = (e, { basePath: t, baseUrl: i }) => {
110
+ var s, o;
111
+ const r = [];
118
112
  let n;
119
- 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 = (a = e.descendantWithPath("body.section.nav.ol")) == null ? void 0 : a.children), n && n.length > 0 && n.filter((o) => o.name === "li").forEach(
120
- (o) => s.push(ne(o, { basePath: t, baseUrl: i }))
121
- ), s;
122
- }, Pe = async (e, t, { baseUrl: i }) => {
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;
116
+ }, Ne = async (e, t, { baseUrl: i }) => {
123
117
  var n;
124
- const s = (n = e.childNamed("manifest")) == null ? void 0 : n.childrenNamed("item").find((r) => r.attr.properties === "nav");
125
- if (s) {
126
- const r = Object.values(t.files).find(
127
- (a) => a.uri.endsWith(s.attr.href || "")
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 || "")
128
122
  );
129
- if (r) {
130
- const a = new F.XmlDocument(await r.string()), o = Ne(r.uri);
131
- return Le(a, { basePath: o, baseUrl: i });
123
+ if (s) {
124
+ const o = new x.XmlDocument(await s.string()), a = Le(s.uri);
125
+ return Se(o, { basePath: a, baseUrl: i });
132
126
  }
133
127
  }
134
- }, re = (e, {
128
+ }, ne = (e, {
135
129
  opfBasePath: t,
136
130
  baseUrl: i,
137
- prefix: s
131
+ prefix: r
138
132
  }) => {
139
- var o, d;
140
- const n = ((o = e == null ? void 0 : e.childNamed(`${s}content`)) == null ? void 0 : o.attr.src) || "", r = {
141
- title: ((d = e == null ? void 0 : e.descendantWithPath(`${s}navLabel.${s}text`)) == null ? void 0 : d.val) || "",
142
- path: N(t, n),
143
- href: N(i, t, n),
133
+ var a, d;
134
+ const n = ((a = e == null ? void 0 : e.childNamed(`${r}content`)) == null ? void 0 : a.attr.src) || "", s = {
135
+ title: ((d = e == null ? void 0 : e.descendantWithPath(`${r}navLabel.${r}text`)) == null ? void 0 : d.val) || "",
136
+ path: L(t, n),
137
+ href: L(i, t, n),
144
138
  contents: []
145
- }, a = e.childrenNamed(`${s}navPoint`);
146
- return a && a.length > 0 && (r.contents = a.map(
147
- (p) => re(p, { opfBasePath: t, baseUrl: i, prefix: s })
148
- )), r;
149
- }, Ie = (e, { opfBasePath: t, baseUrl: i }) => {
150
- var a;
151
- const s = [], n = e.name;
152
- let r = "";
153
- return n.indexOf(":") !== -1 && (r = n.split(":")[0] + ":"), (a = e.childNamed(`${r}navMap`)) == null || a.childrenNamed(`${r}navPoint`).forEach(
154
- (o) => s.push(re(o, { opfBasePath: t, baseUrl: i, prefix: r }))
155
- ), s;
156
- }, Ce = async ({
139
+ }, o = e.childrenNamed(`${r}navPoint`);
140
+ return o && o.length > 0 && (s.contents = o.map(
141
+ (p) => ne(p, { opfBasePath: t, baseUrl: i, prefix: r })
142
+ )), s;
143
+ }, Pe = (e, { opfBasePath: t, baseUrl: i }) => {
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;
150
+ }, Ie = async ({
157
151
  opfData: e,
158
152
  opfBasePath: t,
159
153
  baseUrl: i,
160
- archive: s
154
+ archive: r
161
155
  }) => {
162
- var a;
163
- const n = e.childNamed("spine"), r = n && n.attr.toc;
164
- if (r) {
165
- const o = (a = e.childNamed("manifest")) == null ? void 0 : a.childrenNamed("item").find((d) => d.attr.id === r);
166
- if (o) {
167
- const d = `${t}${t === "" ? "" : "/"}${o.attr.href}`, p = Object.values(s.files).find(
156
+ var o;
157
+ const n = e.childNamed("spine"), s = n && n.attr.toc;
158
+ if (s) {
159
+ const a = (o = e.childNamed("manifest")) == null ? void 0 : o.childrenNamed("item").find((d) => d.attr.id === s);
160
+ if (a) {
161
+ const d = `${t}${t === "" ? "" : "/"}${a.attr.href}`, p = Object.values(r.files).find(
168
162
  (c) => c.uri.endsWith(d)
169
163
  );
170
164
  if (p) {
171
- const c = new F.XmlDocument(await p.string());
172
- return Ie(c, { opfBasePath: t, baseUrl: i });
165
+ const c = new x.XmlDocument(await p.string());
166
+ return Pe(c, { opfBasePath: t, baseUrl: i });
173
167
  }
174
168
  }
175
169
  }
176
- }, Re = async (e, t, { baseUrl: i }) => {
177
- const { basePath: s } = L(t) || {}, n = await Ce({
170
+ }, Ce = async (e, t, { baseUrl: i }) => {
171
+ const { basePath: r } = S(t) || {}, n = await Ie({
178
172
  opfData: e,
179
- opfBasePath: s,
173
+ opfBasePath: r,
180
174
  archive: t,
181
175
  baseUrl: i
182
176
  });
183
- return n || await Pe(e, t, { opfBasePath: s, baseUrl: i });
184
- }, je = async (e) => {
185
- const t = {
186
- renditionLayout: void 0
177
+ return n || await Ne(e, t, { opfBasePath: r, baseUrl: i });
178
+ }, Re = (e) => {
179
+ var r;
180
+ const t = ((r = e.attr.properties) == null ? void 0 : r.split(" ")) || [];
181
+ let i;
182
+ return t.find((n) => n === "rendition:layout-reflowable") && (i = "reflowable"), t.find((n) => n === "rendition:layout-pre-paginated") && (i = "pre-paginated"), {
183
+ renditionLayout: i,
184
+ pageSpreadLeft: t.some((n) => n === "page-spread-left") || void 0,
185
+ pageSpreadRight: t.some((n) => n === "page-spread-right") || void 0
187
186
  };
188
- return await Promise.all(
189
- e.files.map(async (i) => {
190
- var s, n;
191
- if (i.uri.endsWith("com.kobobooks.display-options.xml")) {
192
- const a = (s = new F.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : s.childNamed("option");
193
- ((n = a == null ? void 0 : a.attr) == null ? void 0 : n.name) === "fixed-layout" && a.val === "true" && (t.renditionLayout = "pre-paginated");
194
- }
195
- })
196
- ), t;
197
- }, se = async ({
187
+ }, S = (e) => {
188
+ const i = Object.values(e.files).filter((r) => !r.dir).find((r) => r.uri.endsWith(".opf"));
189
+ return {
190
+ data: i,
191
+ basePath: (i == null ? void 0 : i.uri.substring(0, i.uri.lastIndexOf("/"))) || ""
192
+ };
193
+ }, re = async ({
198
194
  archive: e
199
195
  }) => {
200
- const { data: t, basePath: i } = L(e) || {}, s = await (t == null ? void 0 : t.string());
201
- if (!s) return [];
202
- const n = new F.XmlDocument(s), r = n.childNamed("manifest"), a = n.childNamed("spine"), o = a == null ? void 0 : a.childrenNamed("itemref").map((c) => c.attr.idref), d = (r == null ? void 0 : r.childrenNamed("item").filter((c) => o.includes(c.attr.id || ""))) || [];
196
+ const { data: t, basePath: i } = S(e) || {}, r = await (t == null ? void 0 : t.string());
197
+ if (!r) return [];
198
+ const n = new x.XmlDocument(r), s = n.childNamed("manifest"), o = n.childNamed("spine"), a = o == null ? void 0 : o.childrenNamed("itemref").map((c) => c.attr.idref), d = (s == null ? void 0 : s.childrenNamed("item").filter((c) => a.includes(c.attr.id || ""))) || [];
203
199
  return e.files.filter((c) => d.find((l) => i ? `${i}/${l.attr.href}` === c.uri : `${l.attr.href}` === c.uri));
204
- }, De = (e, t, i) => {
205
- const s = e.attr.href || "", n = i == null ? void 0 : i(e);
200
+ }, je = (e, t, i) => {
201
+ const r = e.attr.href || "", n = i == null ? void 0 : i(e);
206
202
  return {
207
- href: t ? `${n}${t}/${s}` : `${n}${s}`,
203
+ href: t ? `${n}${t}/${r}` : `${n}${r}`,
208
204
  id: e.attr.id || "",
209
205
  mediaType: e.attr["media-type"]
210
206
  };
211
- }, ie = (e, t, i) => {
212
- var r;
213
- const s = e.childNamed("manifest"), { basePath: n } = L(t) || {};
214
- return ((r = s == null ? void 0 : s.childrenNamed("item")) == null ? void 0 : r.map((a) => De(a, n, i))) || [];
215
- }, Oe = ({ archive: e, baseUrl: t }) => async (i) => {
207
+ }, se = (e, t, i) => {
208
+ var s;
209
+ const r = e.childNamed("manifest"), { basePath: n } = S(t) || {};
210
+ return ((s = r == null ? void 0 : r.childrenNamed("item")) == null ? void 0 : s.map((o) => je(o, n, i))) || [];
211
+ }, De = ({ archive: e, baseUrl: t }) => async (i) => {
216
212
  var X;
217
- const { data: s, basePath: n } = L(e) || {}, r = await je(e);
218
- if (!s)
213
+ const { data: r, basePath: n } = S(e) || {};
214
+ if (!r)
219
215
  return i;
220
- const a = await s.string();
221
- v.log(a, r);
222
- const o = new F.XmlDocument(a), d = await Re(o, e, { baseUrl: t }) || [], p = o.childNamed("metadata"), c = o.childNamed("manifest"), l = o.childNamed("spine"), m = o.childNamed("guide"), g = p == null ? void 0 : p.childNamed("dc:title"), b = (p == null ? void 0 : p.childrenNamed("meta")) || [], h = b.find(
223
- (f) => f.attr.property === "rendition:layout"
224
- ), x = b.find(
225
- (f) => f.attr.property === "rendition:flow"
226
- ), y = b.find(
227
- (f) => f.attr.property === "rendition:spread"
228
- ), w = h == null ? void 0 : h.val, P = x == null ? void 0 : x.val, ae = y == null ? void 0 : y.val, oe = (g == null ? void 0 : g.val) || ((X = e.files.find(({ dir: f }) => f)) == null ? void 0 : X.basename) || "", ce = l == null ? void 0 : l.attr["page-progression-direction"], de = (await se({ archive: e })).reduce(
229
- (f, W) => W.size + f,
216
+ const s = await r.string(), o = new x.XmlDocument(s), a = await Ce(o, e, { baseUrl: t }) || [], d = o.childNamed("metadata"), p = o.childNamed("manifest"), c = o.childNamed("spine"), l = o.childNamed("guide"), u = d == null ? void 0 : d.childNamed("dc:title"), g = (d == null ? void 0 : d.childrenNamed("meta")) || [], b = g.find(
217
+ (m) => m.attr.property === "rendition:layout"
218
+ ), h = g.find(
219
+ (m) => m.attr.property === "rendition:flow"
220
+ ), $ = g.find(
221
+ (m) => m.attr.property === "rendition:spread"
222
+ ), y = b == null ? void 0 : b.val, w = h == null ? void 0 : h.val, N = $ == null ? void 0 : $.val, ie = (u == null ? void 0 : u.val) || ((X = e.files.find(({ dir: m }) => m)) == null ? void 0 : X.basename) || "", oe = c == null ? void 0 : c.attr["page-progression-direction"], ae = (await re({ archive: e })).reduce(
223
+ (m, W) => W.size + m,
230
224
  0
231
225
  );
232
226
  return {
233
227
  filename: e.filename,
234
228
  nav: {
235
- toc: d
229
+ toc: a
236
230
  },
237
- renditionLayout: w || r.renditionLayout || "reflowable",
238
- renditionFlow: P || "auto",
239
- renditionSpread: ae,
240
- title: oe,
241
- readingDirection: ce || "ltr",
242
- spineItems: (l == null ? void 0 : l.childrenNamed("itemref").map((f, W) => {
243
- var H, V, _;
244
- const u = c == null ? void 0 : c.childrenNamed("item").find(($) => $.attr.id === (f == null ? void 0 : f.attr.idref)), B = (u == null ? void 0 : u.attr.href) || "", R = ((H = f == null ? void 0 : f.attr.properties) == null ? void 0 : H.split(" ")) || [], le = ((V = e.files.find(($) => $.uri.endsWith(B))) == null ? void 0 : V.size) || 0, U = t || (/^https?:\/\//.test(B) ? "" : "file://");
231
+ renditionLayout: y,
232
+ renditionFlow: w || "auto",
233
+ renditionSpread: N,
234
+ title: ie,
235
+ readingDirection: oe || "ltr",
236
+ /**
237
+ * @see https://www.w3.org/TR/epub/#sec-itemref-elem
238
+ */
239
+ spineItems: (c == null ? void 0 : c.childrenNamed("itemref").map((m, W) => {
240
+ var V, E;
241
+ const f = p == null ? void 0 : p.childrenNamed("item").find((C) => C.attr.id === (m == null ? void 0 : m.attr.idref)), B = (f == null ? void 0 : f.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
242
  return {
246
- id: (u == null ? void 0 : u.attr.id) || "",
243
+ ...U,
244
+ id: (f == null ? void 0 : f.attr.id) || "",
247
245
  index: W,
248
- href: (_ = u == null ? void 0 : u.attr.href) != null && _.startsWith("https://") ? u == null ? void 0 : u.attr.href : n ? `${U}${n}/${u == null ? void 0 : u.attr.href}` : `${U}${u == null ? void 0 : u.attr.href}`,
249
- renditionLayout: w || "reflowable",
250
- ...R.find(
251
- ($) => $ === "rendition:layout-reflowable"
252
- ) && {
253
- renditionLayout: "reflowable"
254
- },
255
- progressionWeight: le / de,
256
- pageSpreadLeft: R.some(($) => $ === "page-spread-left") || void 0,
257
- pageSpreadRight: R.some(($) => $ === "page-spread-right") || void 0,
246
+ href: (E = f == null ? void 0 : f.attr.href) != null && E.startsWith("https://") ? f == null ? void 0 : f.attr.href : n ? `${H}${n}/${f == null ? void 0 : f.attr.href}` : `${H}${f == null ? void 0 : f.attr.href}`,
247
+ renditionLayout: U.renditionLayout ?? y,
248
+ progressionWeight: ce / ae,
258
249
  // size: itemSize
259
- mediaType: u == null ? void 0 : u.attr["media-type"]
250
+ mediaType: f == null ? void 0 : f.attr["media-type"]
260
251
  };
261
252
  })) || [],
262
- items: ie(o, e, (f) => {
263
- const W = f.attr.href || "";
253
+ items: se(o, e, (m) => {
254
+ const W = m.attr.href || "";
264
255
  return /^https?:\/\//.test(W) ? "" : t || "file://";
265
256
  }),
266
- guide: m == null ? void 0 : m.childrenNamed("reference").map((f) => ({
267
- href: f.attr.href || "",
268
- title: f.attr.title || "",
269
- type: f.attr.type
257
+ guide: l == null ? void 0 : l.childrenNamed("reference").map((m) => ({
258
+ href: m.attr.href || "",
259
+ title: m.attr.title || "",
260
+ type: m.attr.type
270
261
  }))
271
262
  };
272
- }, Me = async (e, t) => {
273
- var n, r, a;
274
- const s = await ((n = L(e).data) == null ? void 0 : n.string());
275
- if (s) {
276
- const o = new F.XmlDocument(s), d = ie(o, e, () => "");
277
- if ((r = d.find(
263
+ }, Oe = async (e, t) => {
264
+ var n, s, o;
265
+ const r = await ((n = S(e).data) == null ? void 0 : n.string());
266
+ if (r) {
267
+ const a = new x.XmlDocument(r), d = se(a, e, () => "");
268
+ if ((s = d.find(
278
269
  (c) => t.endsWith(c.href)
279
- )) == null ? void 0 : r.mediaType)
270
+ )) == null ? void 0 : s.mediaType)
280
271
  return {
281
- mediaType: (a = d.find((c) => t.endsWith(c.href))) == null ? void 0 : a.mediaType
272
+ mediaType: (o = d.find((c) => t.endsWith(c.href))) == null ? void 0 : o.mediaType
282
273
  };
283
274
  }
284
275
  return {
285
- mediaType: ze(t)
276
+ mediaType: Me(t)
286
277
  };
287
- }, ze = (e) => {
278
+ }, Me = (e) => {
288
279
  if (e.endsWith(".css"))
289
280
  return "text/css; charset=UTF-8";
290
281
  if (e.endsWith(".jpg"))
@@ -295,25 +286,25 @@ const v = {
295
286
  return "video/mp4";
296
287
  if (e.endsWith(".svg"))
297
288
  return "image/svg+xml";
298
- }, Xe = ({ archive: e, resourcePath: t }) => async (i) => {
299
- const s = Object.values(e.files).find(
300
- (r) => r.uri === t
289
+ }, ze = ({ archive: e, resourcePath: t }) => async (i) => {
290
+ const r = Object.values(e.files).find(
291
+ (s) => s.uri === t
301
292
  );
302
- if (!s) return i;
303
- const n = await Me(e, t);
293
+ if (!r) return i;
294
+ const n = await Oe(e, t);
304
295
  return {
305
296
  ...i,
306
297
  params: {
307
298
  ...i.params,
308
- ...(s == null ? void 0 : s.encodingFormat) && {
309
- contentType: s.encodingFormat
299
+ ...(r == null ? void 0 : r.encodingFormat) && {
300
+ contentType: r.encodingFormat
310
301
  },
311
302
  ...n.mediaType && {
312
303
  contentType: n.mediaType
313
304
  }
314
305
  }
315
306
  };
316
- }, ee = [
307
+ }, Z = [
317
308
  "div",
318
309
  "span",
319
310
  "p",
@@ -364,124 +355,119 @@ const v = {
364
355
  "canvas",
365
356
  "script",
366
357
  "style"
367
- ], Be = ({ archive: e, resourcePath: t }) => async (i) => {
368
- const s = Object.values(e.files).find(
358
+ ], Xe = ({ archive: e, resourcePath: t }) => async (i) => {
359
+ const r = Object.values(e.files).find(
369
360
  (n) => n.uri === t
370
361
  );
371
- if (s != null && s.basename.endsWith(".xhtml")) {
372
- const n = i.body ?? await s.string();
362
+ if (r != null && r.basename.endsWith(".xhtml")) {
363
+ const n = i.body ?? await r.string();
373
364
  if (!new RegExp(
374
- `<(${ee.join("|")})[\\s/>]`,
365
+ `<(${Z.join("|")})[\\s/>]`,
375
366
  "i"
376
367
  ).test(n))
377
368
  return i;
378
- const a = new RegExp(
379
- `<(${ee.join("|")})(\\s[^>]*)?\\s*/>`,
369
+ const o = new RegExp(
370
+ `<(${Z.join("|")})(\\s[^>]*)?\\s*/>`,
380
371
  "gi"
381
- ), o = n.replace(
382
- a,
372
+ ), a = n.replace(
373
+ o,
383
374
  (d, p, c = "") => `<${p} ${c.trim()}></${p}>`
384
375
  );
385
376
  return {
386
377
  ...i,
387
- body: o
378
+ body: a
388
379
  };
389
380
  }
390
381
  return i;
391
- }, Ue = async (e, t) => {
382
+ }, Be = async (e, t) => {
392
383
  const i = Object.values(e.files).find(
393
- (r) => r.uri === t
384
+ (s) => s.uri === t
394
385
  );
395
386
  if (!i)
396
387
  throw new Error("no file found");
397
- const s = {
388
+ const r = {
398
389
  params: {}
399
390
  }, n = [
391
+ ze({ archive: e, resourcePath: t }),
400
392
  Xe({ archive: e, resourcePath: t }),
401
- Be({ archive: e, resourcePath: t }),
402
393
  ke({ archive: e, resourcePath: t }),
403
394
  We({ archive: e, resourcePath: t })
404
395
  ];
405
396
  try {
406
- const r = await n.reduce(async (a, o) => await o(await a), Promise.resolve(s));
407
- return v.log("Generated resource", t, r), {
408
- ...r,
409
- body: r.body ?? await i.blob()
397
+ const s = await n.reduce(async (o, a) => await a(await o), Promise.resolve(r));
398
+ return v.log("Generated resource", t, s), {
399
+ ...s,
400
+ body: s.body ?? await i.blob()
410
401
  };
411
- } catch (r) {
412
- throw v.error(r), r;
402
+ } catch (s) {
403
+ throw v.error(s), s;
413
404
  }
414
405
  }, He = ({ archive: e, baseUrl: t }) => async () => {
415
- var s;
406
+ var r;
416
407
  const i = Object.values(e.files).filter((n) => !n.dir);
417
408
  return {
418
409
  filename: e.filename,
419
- title: ((s = e.files.find(({ dir: n }) => n)) == null ? void 0 : s.basename.replace(/\/$/, "")) || "",
420
- renditionLayout: "pre-paginated",
410
+ title: ((r = e.files.find(({ dir: n }) => n)) == null ? void 0 : r.basename.replace(/\/$/, "")) || "",
411
+ renditionLayout: void 0,
421
412
  renditionSpread: "auto",
422
413
  readingDirection: "ltr",
423
- spineItems: i.filter((n) => !n.basename.endsWith(".db")).map((n, r) => ({
414
+ spineItems: i.filter((n) => !n.basename.endsWith(".db")).map((n, s) => ({
424
415
  // some books such as cbz can have same basename inside different sub folder
425
416
  // we need to make sure to have unique index
426
417
  // /chap01/01.png, /chap02/01.png, etc
427
- id: `${r}.${n.basename}`,
428
- index: r,
418
+ id: `${s}.${n.basename}`,
419
+ index: s,
429
420
  href: encodeURI(`${t}${n.uri}`),
430
- renditionLayout: "pre-paginated",
421
+ renditionLayout: void 0,
431
422
  progressionWeight: 1 / i.length,
432
423
  pageSpreadLeft: void 0,
433
424
  pageSpreadRight: void 0,
434
425
  mediaType: n.encodingFormat
435
426
  })),
436
- items: i.map((n, r) => ({
437
- id: `${r}.${n.basename}`,
427
+ items: i.map((n, s) => ({
428
+ id: `${s}.${n.basename}`,
438
429
  href: encodeURI(`${t}${n.uri}`)
439
430
  }))
440
431
  };
432
+ }, Ue = async (e) => {
433
+ const t = {
434
+ renditionLayout: void 0
435
+ };
436
+ return await Promise.all(
437
+ e.files.map(async (i) => {
438
+ var r, n;
439
+ if (i.uri.endsWith("com.kobobooks.display-options.xml")) {
440
+ const o = (r = new x.XmlDocument(await i.string()).childNamed("platform")) == null ? void 0 : r.childNamed("option");
441
+ ((n = o == null ? void 0 : o.attr) == null ? void 0 : n.name) === "fixed-layout" && o.val === "true" && (t.renditionLayout = "pre-paginated");
442
+ }
443
+ })
444
+ ), t;
441
445
  }, Ve = ({ archive: e }) => async (t) => {
442
- var r;
443
- const i = e.files.find(
444
- (a) => a.basename.toLowerCase() === "comicinfo.xml"
445
- );
446
- if (!i)
447
- return t;
448
- const s = {
446
+ const i = await Ue(e);
447
+ return {
449
448
  ...t,
450
- spineItems: t.spineItems.filter((a) => !a.id.toLowerCase().endsWith("comicinfo.xml")).map((a, o, d) => ({
451
- ...a,
452
- progressionWeight: 1 / d.length
453
- }))
454
- }, n = await i.string();
455
- try {
456
- const o = ((r = new F.XmlDocument(n).childNamed("Manga")) == null ? void 0 : r.val) || "unknown";
457
- return {
458
- ...s,
459
- readingDirection: o === "YesAndRightToLeft" ? "rtl" : "ltr"
460
- };
461
- } catch (a) {
462
- return console.error(`Unable to parse comicinfo.xml for content
463
- `, n), console.error(a), s;
464
- }
465
- }, _e = (e) => {
449
+ renditionLayout: t.renditionLayout ?? i.renditionLayout
450
+ };
451
+ }, Ee = (e) => {
466
452
  var i;
467
- const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((s) => s.attr.name === "viewport");
453
+ const t = (i = e.descendantWithPath("head")) == null ? void 0 : i.childrenNamed("meta").find((r) => r.attr.name === "viewport");
468
454
  return !!(t && t.attr.name === "viewport");
469
- }, qe = (e) => e.reduce(async (t, i) => {
470
- if (!await t || !me({
455
+ }, _e = (e) => e.reduce(async (t, i) => {
456
+ if (!await t || !fe({
471
457
  mimeType: i.encodingFormat,
472
458
  uri: i.uri
473
459
  }))
474
460
  return !1;
475
461
  const n = await i.string();
476
- return n ? _e(new F.XmlDocument(n)) : !1;
477
- }, Promise.resolve(!0)), Ge = ({ archive: e }) => async (t) => {
478
- if (t.renditionLayout === "reflowable" && t.spineItems.every((s) => s.renditionLayout === "reflowable")) {
479
- const s = await se({ archive: e });
480
- if (await qe(s))
462
+ return n ? Ee(new x.XmlDocument(n)) : !1;
463
+ }, Promise.resolve(!0)), qe = ({ archive: e }) => async (t) => {
464
+ if (t.renditionLayout === "reflowable" && t.spineItems.every((r) => r.renditionLayout === "reflowable")) {
465
+ const r = await re({ archive: e });
466
+ if (await _e(r))
481
467
  return {
482
468
  ...t,
483
- spineItems: t.spineItems.map((r) => ({
484
- ...r,
469
+ spineItems: t.spineItems.map((s) => ({
470
+ ...s,
485
471
  renditionLayout: "pre-paginated"
486
472
  })),
487
473
  renditionLayout: "pre-paginated"
@@ -490,25 +476,25 @@ const v = {
490
476
  return t;
491
477
  }, z = (e, t) => {
492
478
  var n;
493
- const i = e.split(/(\d+)/), s = t.split(/(\d+)/);
494
- for (let r = 0, a = i.length; r < a; r++)
495
- if (i[r] !== s[r])
496
- return (n = i[r]) != null && n.match(/\d/) ? +(i[r] || "") - +(s[r] || "") : (i[r] || "").localeCompare(s[r] || "");
479
+ const i = e.split(/(\d+)/), r = t.split(/(\d+)/);
480
+ for (let s = 0, o = i.length; s < o; s++)
481
+ if (i[s] !== r[s])
482
+ return (n = i[s]) != null && n.match(/\d/) ? +(i[s] || "") - +(r[s] || "") : (i[s] || "").localeCompare(r[s] || "");
497
483
  return 1;
498
- }, Ke = ({ archive: e, baseUrl: t }) => async (i) => {
484
+ }, Ge = ({ archive: e, baseUrl: t }) => async (i) => {
499
485
  if (i.nav) return i;
500
- const s = [...e.files].sort(
501
- (o, d) => z(o.uri, d.uri)
502
- ), n = Object.values(s), r = (o, d, p, c, l) => {
503
- const m = o.find((h) => h.title === d), [g, ...b] = p;
504
- return m ? g ? [
505
- ...o.filter((x) => x != m),
486
+ const r = [...e.files].sort(
487
+ (a, d) => z(a.uri, d.uri)
488
+ ), n = Object.values(r), s = (a, d, p, c, l) => {
489
+ const u = a.find((h) => h.title === d), [g, ...b] = p;
490
+ return u ? g ? [
491
+ ...a.filter(($) => $ != u),
506
492
  {
507
- ...m,
493
+ ...u,
508
494
  contents: [
509
- ...m.contents,
510
- ...r(
511
- m.contents,
495
+ ...u.contents,
496
+ ...s(
497
+ u.contents,
512
498
  g,
513
499
  b,
514
500
  c,
@@ -516,17 +502,17 @@ const v = {
516
502
  )
517
503
  ]
518
504
  }
519
- ] : m.path.split("/").length > l.split("/").length ? [
520
- ...o.filter((x) => x != m),
505
+ ] : u.path.split("/").length > l.split("/").length ? [
506
+ ...a.filter(($) => $ != u),
521
507
  {
522
- ...m,
508
+ ...u,
523
509
  path: l,
524
510
  href: c
525
511
  }
526
- ] : o : g ? [
527
- ...o,
512
+ ] : a : g ? [
513
+ ...a,
528
514
  {
529
- contents: r(
515
+ contents: s(
530
516
  [],
531
517
  g,
532
518
  b,
@@ -538,7 +524,7 @@ const v = {
538
524
  title: d
539
525
  }
540
526
  ] : [
541
- ...o,
527
+ ...a,
542
528
  {
543
529
  contents: [],
544
530
  href: c,
@@ -546,50 +532,75 @@ const v = {
546
532
  title: d
547
533
  }
548
534
  ];
549
- }, a = n.reduce(
550
- (o, d) => {
551
- if (d.dir) return o;
552
- const c = d.uri.split("/").slice(0, -1), [l, ...m] = c;
535
+ }, o = n.reduce(
536
+ (a, d) => {
537
+ if (d.dir) return a;
538
+ const c = d.uri.split("/").slice(0, -1), [l, ...u] = c;
553
539
  if (l) {
554
- const g = N(t, encodeURI(d.uri)).replace(/\/$/, ""), b = d.uri.replace(/\/$/, "");
555
- return r(o, l, m, g, b);
540
+ const g = L(t, encodeURI(d.uri)).replace(/\/$/, ""), b = d.uri.replace(/\/$/, "");
541
+ return s(a, l, u, g, b);
556
542
  }
557
- return o;
543
+ return a;
558
544
  },
559
545
  []
560
546
  );
561
- return a.length === 0 ? i : {
547
+ return o.length === 0 ? i : {
562
548
  ...i,
563
549
  nav: {
564
- toc: a
550
+ toc: o
565
551
  }
566
552
  };
567
- }, Je = {
568
- filename: "",
569
- items: [],
570
- nav: {
571
- toc: []
572
- },
573
- readingDirection: "ltr",
574
- renditionLayout: "pre-paginated",
575
- renditionSpread: "auto",
576
- spineItems: [],
577
- title: ""
578
- }, Ye = async (e, { baseUrl: t = "" } = {}) => {
553
+ }, Ke = ({ archive: e }) => async (t) => {
554
+ var s;
555
+ const i = e.files.find(
556
+ (o) => o.basename.toLowerCase() === "comicinfo.xml"
557
+ );
558
+ if (!i)
559
+ return t;
560
+ const r = {
561
+ ...t,
562
+ spineItems: t.spineItems.filter((o) => !o.id.toLowerCase().endsWith("comicinfo.xml")).map((o, a, d) => ({
563
+ ...o,
564
+ progressionWeight: 1 / d.length
565
+ }))
566
+ }, n = await i.string();
567
+ try {
568
+ const a = ((s = new x.XmlDocument(n).childNamed("Manga")) == null ? void 0 : s.val) || "unknown";
569
+ return {
570
+ ...r,
571
+ readingDirection: a === "YesAndRightToLeft" ? "rtl" : "ltr"
572
+ };
573
+ } catch (o) {
574
+ return console.error(`Unable to parse comicinfo.xml for content
575
+ `, n), console.error(o), r;
576
+ }
577
+ }, Je = (e) => e.files.some((t) => t.basename.endsWith(".opf")), Ye = ({ archive: e }) => async (t) => Je(e) ? t : {
578
+ ...t,
579
+ spineItems: t.spineItems.map((r) => {
580
+ const n = e.files.find(
581
+ (o) => decodeURI(r.href).endsWith(o.uri)
582
+ ), s = ue((n == null ? void 0 : n.encodingFormat) ?? "") ?? O((n == null ? void 0 : n.basename) ?? "");
583
+ return {
584
+ ...r,
585
+ renditionLayout: s != null && s.startsWith("image/") ? "pre-paginated" : r.renditionLayout
586
+ };
587
+ })
588
+ }, Qe = async (e, { baseUrl: t = "" } = {}) => {
579
589
  const i = [
580
- He({ archive: e, baseUrl: t }),
581
- Oe({ archive: e, baseUrl: t }),
582
- Ge({ archive: e, baseUrl: t }),
590
+ De({ archive: e, baseUrl: t }),
591
+ Ke({ archive: e, baseUrl: t }),
592
+ Ye({ archive: e, baseUrl: t }),
593
+ qe({ archive: e, baseUrl: t }),
583
594
  Ve({ archive: e, baseUrl: t }),
584
- Ke({ archive: e, baseUrl: t })
595
+ Ge({ archive: e, baseUrl: t })
585
596
  ];
586
597
  try {
587
- const s = await i.reduce(async (n, r) => await r(await n), Promise.resolve(Je));
588
- return v.log("Generated manifest", s), s;
589
- } catch (s) {
590
- throw v.error(s), s;
598
+ const r = He({ archive: e, baseUrl: t })(), n = await i.reduce(async (s, o) => await o(await s), r);
599
+ return v.log("Generated manifest", n), n;
600
+ } catch (r) {
601
+ throw v.error(r), r;
591
602
  }
592
- }, st = async (e, t) => {
603
+ }, ot = async (e, t) => {
593
604
  const i = `
594
605
  <?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
595
606
  <metadata>
@@ -598,22 +609,22 @@ const v = {
598
609
  </metadata>
599
610
  <manifest>
600
611
  ${e.map(
601
- (r) => `<item id="${T(r)}" href="${r}" media-type="${q(r)}"/>`
612
+ (s) => `<item id="${A(s)}" href="${s}" media-type="${O(s)}"/>`
602
613
  ).join(`
603
614
  `)}
604
615
  </manifest>
605
616
  <spine>
606
- ${e.map((r) => `<itemref idref="${T(r)}" />`).join(`
617
+ ${e.map((s) => `<itemref idref="${A(s)}" />`).join(`
607
618
  `)}
608
619
  </spine>
609
620
  </package>
610
- `, s = e.map((r) => ({
621
+ `, r = e.map((s) => ({
611
622
  dir: !1,
612
- basename: T(r),
613
- encodingFormat: q(r),
614
- uri: r,
623
+ basename: A(s),
624
+ encodingFormat: O(s),
625
+ uri: s,
615
626
  size: 100 / e.length,
616
- blob: async () => (await fetch(r)).blob(),
627
+ blob: async () => (await fetch(s)).blob(),
617
628
  string: async () => ""
618
629
  }));
619
630
  return {
@@ -625,14 +636,14 @@ const v = {
625
636
  size: 0,
626
637
  blob: async () => new Blob(),
627
638
  string: async () => i
628
- }, ...s],
639
+ }, ...r],
629
640
  close: () => Promise.resolve()
630
641
  };
631
- }, it = async (e, {
642
+ }, at = async (e, {
632
643
  mimeType: t,
633
644
  direction: i
634
645
  } = { mimeType: "text/plain" }) => {
635
- const s = `
646
+ const r = `
636
647
  <?xml version="1.0" encoding="UTF-8"?>
637
648
  <package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="ja" prefix="rendition: http://www.idpf.org/vocab/rendition/#"
638
649
  unique-identifier="ootuya-id">
@@ -653,15 +664,15 @@ const v = {
653
664
  files: [
654
665
  {
655
666
  dir: !1,
656
- basename: T("generated.opf"),
667
+ basename: A("generated.opf"),
657
668
  uri: "generated.opf",
658
- blob: async () => new Blob([s]),
659
- string: async () => s,
669
+ blob: async () => new Blob([r]),
670
+ string: async () => r,
660
671
  size: 0
661
672
  },
662
673
  {
663
674
  dir: !1,
664
- basename: T("p01.txt"),
675
+ basename: A("p01.txt"),
665
676
  uri: "p01.txt",
666
677
  blob: async () => typeof e == "string" ? new Blob([e]) : e,
667
678
  string: async () => typeof e == "string" ? e : e.text(),
@@ -671,30 +682,30 @@ const v = {
671
682
  ],
672
683
  close: () => Promise.resolve()
673
684
  };
674
- }, at = async (e, { orderByAlpha: t, name: i } = {}) => {
675
- let s = Object.values(e.files);
676
- t && (s = s.slice().sort((r, a) => z(r.name, a.name)));
685
+ }, ct = async (e, { orderByAlpha: t, name: i } = {}) => {
686
+ let r = Object.values(e.files);
687
+ t && (r = r.slice().sort((s, o) => z(s.name, o.name)));
677
688
  const n = {
678
689
  filename: i || "",
679
- files: s.map((r) => ({
680
- dir: r.dir,
681
- basename: T(r.name),
682
- uri: r.name,
683
- blob: () => r.async("blob"),
684
- string: () => r.async("string"),
685
- ...r.internalStream && {
686
- stream: r.internalStream
690
+ files: r.map((s) => ({
691
+ dir: s.dir,
692
+ basename: A(s.name),
693
+ uri: s.name,
694
+ blob: () => s.async("blob"),
695
+ string: () => s.async("string"),
696
+ ...s.internalStream && {
697
+ stream: s.internalStream
687
698
  },
688
699
  // this is private API
689
700
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
690
701
  // @ts-ignore
691
- size: r._data.uncompressedSize
702
+ size: s._data.uncompressedSize
692
703
  })),
693
704
  close: () => Promise.resolve()
694
705
  };
695
706
  return v.log("Generated archive", n), n;
696
- }, ot = async (e, { name: t } = {}) => {
697
- const i = await e.getFilesArray(), s = {
707
+ }, dt = async (e, { name: t } = {}) => {
708
+ const i = await e.getFilesArray(), r = {
698
709
  close: () => e.close(),
699
710
  filename: t ?? "",
700
711
  files: i.map((n) => ({
@@ -706,35 +717,35 @@ const v = {
706
717
  string: async () => (await n.file.extract()).text()
707
718
  }))
708
719
  };
709
- return v.log("Generated archive", s), s;
710
- }, ct = async (e, { orderByAlpha: t, name: i } = {}) => {
711
- let s = e;
712
- return t && (s = s.slice().sort((n, r) => z(n.name, r.name))), {
720
+ return v.log("Generated archive", r), r;
721
+ }, lt = async (e, { orderByAlpha: t, name: i } = {}) => {
722
+ let r = e;
723
+ return t && (r = r.slice().sort((n, s) => z(n.name, s.name))), {
713
724
  filename: i || "",
714
- files: s.map((n) => ({
725
+ files: r.map((n) => ({
715
726
  dir: n.isDir,
716
- basename: T(n.name),
727
+ basename: A(n.name),
717
728
  uri: n.name,
718
729
  blob: async () => new Blob([await n.data()]),
719
730
  string: async () => {
720
- const r = await n.data();
731
+ const s = await n.data();
721
732
  return String.fromCharCode.apply(
722
733
  null,
723
- Array.from(new Uint16Array(r))
734
+ Array.from(new Uint16Array(s))
724
735
  );
725
736
  },
726
737
  size: n.size
727
738
  })),
728
739
  close: () => Promise.resolve()
729
740
  };
730
- }, dt = ({
741
+ }, pt = ({
731
742
  enableReport: e
732
743
  } = {}) => {
733
744
  v.enable(!!e);
734
745
  };
735
- class Ee {
746
+ class Ze {
736
747
  constructor(t) {
737
- this.cleanArchiveAfter = t, this.state$ = new ve({
748
+ this.cleanArchiveAfter = t, this.state$ = new we({
738
749
  status: "idle",
739
750
  locks: 0
740
751
  });
@@ -743,119 +754,119 @@ class Ee {
743
754
  this.state$.next({ ...this.state$.getValue(), ...t });
744
755
  }
745
756
  get locks$() {
746
- return this.state$.pipe(A(({ locks: t }) => t));
757
+ return this.state$.pipe(F(({ locks: t }) => t));
747
758
  }
748
759
  get state() {
749
760
  return this.state$.getValue();
750
761
  }
751
762
  get isUnlocked$() {
752
763
  return this.locks$.pipe(
753
- A((t) => t <= 0),
754
- $e(),
755
- xe()
764
+ F((t) => t <= 0),
765
+ ve(),
766
+ $e()
756
767
  );
757
768
  }
758
769
  get overTTL$() {
759
770
  return this.isUnlocked$.pipe(
760
771
  k(
761
- (t) => t ? this.cleanArchiveAfter === 1 / 0 ? J : Fe(this.cleanArchiveAfter) : J
772
+ (t) => t ? this.cleanArchiveAfter === 1 / 0 ? G : xe(this.cleanArchiveAfter) : G
762
773
  )
763
774
  );
764
775
  }
765
776
  }
766
- const Qe = ({
777
+ const et = ({
767
778
  getArchive: e,
768
779
  cleanArchiveAfter: t = 5 * 60 * 1e3
769
780
  // 5mn
770
781
  }) => {
771
- const i = new j(), s = new j(), n = new j(), r = {}, a = i.pipe(
782
+ const i = new R(), r = new R(), n = new R(), s = {}, o = i.pipe(
772
783
  M((p) => {
773
- const c = r[p];
774
- if (!c || c.state.status !== "idle") return G;
784
+ const c = s[p];
785
+ if (!c || c.state.status !== "idle") return _;
775
786
  let l = !1;
776
- const m = (y) => {
777
- var P;
778
- const w = r[y];
779
- delete r[y], l || ((P = w == null ? void 0 : w.state.archive) == null || P.close(), l = !0);
787
+ const u = (y) => {
788
+ var N;
789
+ const w = s[y];
790
+ delete s[y], l || ((N = w == null ? void 0 : w.state.archive) == null || N.close(), l = !0);
780
791
  };
781
792
  c.update({
782
793
  status: "loading"
783
794
  });
784
795
  const g = c.locks$, b = c.isUnlocked$, h = g.pipe(
785
- he(),
786
- D(([y, w]) => w > y),
787
- ge(!0)
796
+ me(),
797
+ j(([y, w]) => w > y),
798
+ he(!0)
788
799
  );
789
- return I(e(p)).pipe(
790
- O((y) => {
800
+ return P(e(p)).pipe(
801
+ D((y) => {
791
802
  c.update({
792
803
  archive: y,
793
804
  status: "success"
794
805
  });
795
806
  }),
796
- C((y) => (m(p), c.update({
807
+ I((y) => (u(p), c.update({
797
808
  status: "error",
798
809
  error: y
799
- }), G)),
810
+ }), _)),
800
811
  k(() => {
801
812
  const y = h.pipe(
802
813
  k(() => n),
803
814
  k(() => b),
804
- D((w) => w)
815
+ j((w) => w)
805
816
  );
806
- return K(y, c.overTTL$);
817
+ return q(y, c.overTTL$);
807
818
  }),
808
- O(() => {
809
- m(p);
819
+ D(() => {
820
+ u(p);
810
821
  })
811
822
  );
812
823
  }),
813
- ye(s)
814
- ), o = (p) => {
824
+ ge(r)
825
+ ), a = (p) => {
815
826
  let c = !1;
816
- const l = r[p] ?? new Ee(t);
817
- r[p] = l, l.update({
827
+ const l = s[p] ?? new Ze(t);
828
+ s[p] = l, l.update({
818
829
  locks: l.state.locks + 1
819
830
  });
820
- const m = () => {
831
+ const u = () => {
821
832
  c || (c = !0, l.update({
822
833
  locks: l.state.locks - 1
823
834
  }));
824
835
  };
825
836
  i.next(p);
826
837
  const g = l.state$.pipe(
827
- A(({ archive: h }) => h),
828
- D((h) => !!h)
838
+ F(({ archive: h }) => h),
839
+ j((h) => !!h)
829
840
  ), b = l.state$.pipe(
830
- O(({ error: h }) => {
841
+ D(({ error: h }) => {
831
842
  if (h)
832
843
  throw h;
833
844
  }),
834
- be()
845
+ ye()
835
846
  );
836
- return K(g, b).pipe(
837
- we(),
838
- A((h) => ({ archive: h, release: m })),
839
- C((h) => {
840
- throw m(), h;
847
+ return q(g, b).pipe(
848
+ be(),
849
+ F((h) => ({ archive: h, release: u })),
850
+ I((h) => {
851
+ throw u(), h;
841
852
  })
842
853
  );
843
854
  }, d = () => {
844
855
  n.next();
845
856
  };
846
- return a.subscribe(), {
847
- access: o,
857
+ return o.subscribe(), {
858
+ access: a,
848
859
  purge: d,
849
- archives: r
860
+ archives: s
850
861
  };
851
862
  };
852
- class Ze {
863
+ class tt {
853
864
  constructor({
854
865
  onError: t,
855
866
  onManifestSuccess: i,
856
- ...s
867
+ ...r
857
868
  }) {
858
- this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = Qe(s), this.onManifestSuccess = i ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
869
+ this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.epubLoader = et(r), this.onManifestSuccess = i ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
859
870
  }
860
871
  prune() {
861
872
  this.epubLoader.purge();
@@ -865,41 +876,41 @@ class Ze {
865
876
  }
866
877
  accessArchiveWithoutLock(t) {
867
878
  return this.accessArchive(t).pipe(
868
- A(({ archive: i, release: s }) => (s(), i))
879
+ F(({ archive: i, release: r }) => (r(), i))
869
880
  );
870
881
  }
871
882
  fetchManifest({ key: t, baseUrl: i }) {
872
- const s = this.accessArchive(t).pipe(
873
- M(({ archive: n, release: r }) => I(
874
- Ye(n, { baseUrl: i })
883
+ const r = this.accessArchive(t).pipe(
884
+ M(({ archive: n, release: s }) => P(
885
+ Qe(n, { baseUrl: i })
875
886
  ).pipe(
876
887
  k(
877
- (o) => I(this.onManifestSuccess({ manifest: o, archive: n }))
888
+ (a) => P(this.onManifestSuccess({ manifest: a, archive: n }))
878
889
  ),
879
- A(
880
- (o) => new Response(JSON.stringify(o), {
890
+ F(
891
+ (a) => new Response(JSON.stringify(a), {
881
892
  status: 200
882
893
  })
883
894
  ),
884
- Y(() => {
885
- r();
895
+ K(() => {
896
+ s();
886
897
  })
887
898
  )),
888
- C((n) => E(this.onError(n)))
899
+ I((n) => J(this.onError(n)))
889
900
  );
890
- return Q(s);
901
+ return Y(r);
891
902
  }
892
903
  fetchResource({
893
904
  key: t,
894
905
  resourcePath: i
895
906
  }) {
896
- const s = this.accessArchive(t).pipe(
897
- M(({ archive: n, release: r }) => {
898
- const a = i.replaceAll("file://", "");
899
- return I(
900
- Ue(n, a)
907
+ const r = this.accessArchive(t).pipe(
908
+ M(({ archive: n, release: s }) => {
909
+ const o = i.replaceAll("file://", "");
910
+ return P(
911
+ Be(n, o)
901
912
  ).pipe(
902
- A(
913
+ F(
903
914
  (d) => new Response(d.body, {
904
915
  status: 200,
905
916
  headers: {
@@ -909,17 +920,17 @@ class Ze {
909
920
  }
910
921
  })
911
922
  ),
912
- Y(() => {
913
- r();
923
+ K(() => {
924
+ s();
914
925
  })
915
926
  );
916
927
  }),
917
- C((n) => E(this.onError(n)))
928
+ I((n) => J(this.onError(n)))
918
929
  );
919
- return Q(s);
930
+ return Y(r);
920
931
  }
921
932
  }
922
- class lt extends Ze {
933
+ class ft extends tt {
923
934
  constructor({
924
935
  getUriInfo: t,
925
936
  ...i
@@ -930,30 +941,30 @@ class lt extends Ze {
930
941
  try {
931
942
  const i = this.getUriInfo(t);
932
943
  if (!i) return;
933
- const s = Z(i.baseUrl), n = t.request.url.substring(
934
- s.length + 1
935
- ), [r = ""] = n.split("/"), a = decodeURIComponent(
936
- Z(n.substring(r.length + 1))
944
+ const r = Q(i.baseUrl), n = t.request.url.substring(
945
+ r.length + 1
946
+ ), [s = ""] = n.split("/"), o = decodeURIComponent(
947
+ Q(n.substring(s.length + 1))
937
948
  );
938
949
  n.endsWith("/manifest") ? t.respondWith(
939
- this.fetchManifest({ key: r, baseUrl: `${s}/${r}/` })
940
- ) : t.respondWith(this.fetchResource({ key: r, resourcePath: a }));
950
+ this.fetchManifest({ key: s, baseUrl: `${r}/${s}/` })
951
+ ) : t.respondWith(this.fetchResource({ key: s, resourcePath: o }));
941
952
  } catch (i) {
942
953
  t.respondWith(new Response(String(i), { status: 500 }));
943
954
  }
944
955
  }
945
956
  }
946
957
  export {
947
- lt as ServiceWorkerStreamer,
948
- Ze as Streamer,
949
- dt as configure,
950
- ct as createArchiveFromArrayBufferList,
951
- at as createArchiveFromJszip,
952
- ot as createArchiveFromLibArchive,
953
- it as createArchiveFromText,
954
- st as createArchiveFromUrls,
955
- Ye as generateManifestFromArchive,
956
- Ue as generateResourceFromArchive,
957
- L as getArchiveOpfInfo
958
+ ft as ServiceWorkerStreamer,
959
+ tt as Streamer,
960
+ pt as configure,
961
+ lt as createArchiveFromArrayBufferList,
962
+ ct as createArchiveFromJszip,
963
+ dt as createArchiveFromLibArchive,
964
+ at as createArchiveFromText,
965
+ ot as createArchiveFromUrls,
966
+ Qe as generateManifestFromArchive,
967
+ Be as generateResourceFromArchive,
968
+ S as getArchiveOpfInfo
958
969
  };
959
970
  //# sourceMappingURL=index.js.map