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