@prose-reader/streamer 1.133.0 → 1.135.0

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