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