@prose-reader/streamer 1.291.0 → 1.292.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,119 +1,119 @@
1
- import { detectMimeTypeFromName as b, Report as ee, isXmlBasedMimeType as te, parseContentType as V, isMediaContentMimeType as ne, urlJoin as L } from "@prose-reader/shared";
2
- import { parseOpf as re, APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME as X, parseAppleDisplayOptionsXml as se, resolveArchiveMetadata as T, COMIC_INFO_FILENAME as G, parseComicInfo as ie, KOBO_DISPLAY_OPTIONS_FILENAME as N, parseKoboXml as oe, tokenizeXmlSpaceSeparatedList as ae } from "@prose-reader/archive-parser";
3
- import { XmlDocument as I, XmlTextNode as ce, XmlElement as de } from "xmldoc";
4
- import { Subject as R, mergeMap as H, EMPTY as O, pairwise as le, filter as C, startWith as ue, from as A, tap as E, catchError as k, switchMap as x, merge as z, first as M, takeUntil as pe, map as F, ignoreElements as fe, BehaviorSubject as me, distinctUntilChanged as he, shareReplay as ge, NEVER as B, timer as ye, finalize as be, of as ve, lastValueFrom as we } from "rxjs";
5
- const W = (n, t) => {
6
- const i = n.split(/(\d+)/), r = t.split(/(\d+)/);
7
- for (let e = 0, s = i.length; e < s; e++)
8
- if (i[e] !== r[e])
9
- return i[e]?.match(/\d/) ? +(i[e] || "") - +(r[e] || "") : (i[e] || "").localeCompare(r[e] || "");
1
+ import { detectMimeTypeFromName as g, Report as ue, parseContentType as k, isXmlBasedMimeType as fe, isMediaContentMimeType as he, urlJoin as F, escapeXmlAttributeValue as me } from "@prose-reader/shared";
2
+ import { parseOpf as ge, APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME as Z, parseAppleDisplayOptionsXml as ye, resolveArchiveMetadata as I, COMIC_INFO_FILENAME as ee, parseComicInfo as ve, KOBO_DISPLAY_OPTIONS_FILENAME as N, parseKoboXml as be, tokenizeXmlSpaceSeparatedList as we } from "@prose-reader/archive-parser";
3
+ import { XmlDocument as P, XmlTextNode as $e, XmlElement as Se } from "xmldoc";
4
+ import { Subject as L, mergeMap as te, EMPTY as _, pairwise as Re, filter as T, startWith as xe, from as R, tap as E, catchError as W, switchMap as x, merge as U, first as B, takeUntil as Fe, map as S, ignoreElements as Ie, BehaviorSubject as Pe, distinctUntilChanged as Ae, shareReplay as Le, NEVER as z, timer as Te, finalize as Ee, of as Ce, lastValueFrom as We } from "rxjs";
5
+ const M = (e, t) => {
6
+ const s = e.split(/(\d+)/), r = t.split(/(\d+)/);
7
+ for (let n = 0, i = s.length; n < i; n++)
8
+ if (s[n] !== r[n])
9
+ return s[n]?.match(/\d/) ? +(s[n] || "") - +(r[n] || "") : (s[n] || "").localeCompare(r[n] || "");
10
10
  return 1;
11
- }, y = (n) => n.substring(n.lastIndexOf("/") + 1) || n, j = (n) => n.endsWith("/") ? n.slice(0, -1) : n, $e = (n) => {
12
- const t = n.lastIndexOf("/");
13
- return t >= 0 ? n.substring(0, t) : "";
14
- }, yt = async (n, { orderByAlpha: t, name: i } = {}) => {
15
- let r = n;
16
- return t && (r = r.slice().sort((e, s) => W(e.name, s.name))), {
17
- filename: i || "",
18
- records: r.map((e) => {
19
- const s = e.size, o = y(e.name);
20
- return e.isDir ? {
11
+ }, v = (e) => e.substring(e.lastIndexOf("/") + 1) || e, j = (e) => e.endsWith("/") ? e.slice(0, -1) : e, ke = (e) => {
12
+ const t = e.lastIndexOf("/");
13
+ return t >= 0 ? e.substring(0, t) : "";
14
+ }, rn = async (e, { orderByAlpha: t, name: s } = {}) => {
15
+ let r = e;
16
+ return t && (r = r.slice().sort((n, i) => M(n.name, i.name))), {
17
+ filename: s || "",
18
+ records: r.map((n) => {
19
+ const i = n.size, o = v(n.name);
20
+ return n.isDir ? {
21
21
  dir: !0,
22
22
  basename: o,
23
- uri: e.name,
24
- size: s
23
+ uri: n.name,
24
+ size: i
25
25
  } : {
26
- dir: e.isDir,
26
+ dir: n.isDir,
27
27
  basename: o,
28
- encodingFormat: b(e.name),
29
- uri: e.name,
30
- blob: async () => new Blob([await e.data()], {
31
- type: b(e.name) ?? ""
28
+ encodingFormat: g(n.name),
29
+ uri: n.name,
30
+ blob: async () => new Blob([await n.data()], {
31
+ type: g(n.name) ?? ""
32
32
  }),
33
33
  string: async () => {
34
- const a = await e.data();
34
+ const a = await n.data();
35
35
  return String.fromCharCode.apply(
36
36
  null,
37
37
  Array.from(new Uint16Array(a))
38
38
  );
39
39
  },
40
- size: s
40
+ size: i
41
41
  };
42
42
  }),
43
43
  close: () => Promise.resolve()
44
44
  };
45
- }, Fe = "@prose-reader/streamer", p = ee.namespace(Fe, !1, {
45
+ }, Me = "@prose-reader/streamer", u = ue.namespace(Me, !1, {
46
46
  color: "#ffae42"
47
- }), Ae = (n) => {
47
+ }), Oe = (e) => {
48
48
  const t = {};
49
- for (const r of n) {
50
- const e = r.split("/");
51
- let s = t;
52
- for (let o = 0; o < e.length; o++) {
53
- const a = e[o];
54
- a !== void 0 && (s[a] || (s[a] = {}), s = s[a]);
49
+ for (const r of e) {
50
+ const n = r.split("/");
51
+ let i = t;
52
+ for (let o = 0; o < n.length; o++) {
53
+ const a = n[o];
54
+ a !== void 0 && (i[a] || (i[a] = {}), i = i[a]);
55
55
  }
56
56
  }
57
- const i = (r, e = "") => Object.keys(r).sort().map((s, o, a) => {
58
- const c = o === a.length - 1, l = e + (c ? "└── " : "├── "), u = e + (c ? " " : "│ "), f = r[s];
59
- return f && Object.keys(f).length > 0 ? `${l}${s}/
60
- ${i(f, u)}` : `${l}${s}`;
57
+ const s = (r, n = "") => Object.keys(r).sort().map((i, o, a) => {
58
+ const c = o === a.length - 1, l = n + (c ? "└── " : "├── "), p = n + (c ? " " : "│ "), f = r[i];
59
+ return f && Object.keys(f).length > 0 ? `${l}${i}/
60
+ ${s(f, p)}` : `${l}${i}`;
61
61
  }).join(`
62
62
  `);
63
- return i(t);
64
- }, bt = async (n, { orderByAlpha: t, name: i } = {}) => {
65
- let r = Object.values(n.files);
66
- t && (r = r.slice().sort((s, o) => W(s.name, o.name)));
67
- const e = {
68
- filename: i || "",
69
- records: r.map((s) => {
70
- const o = s._data.uncompressedSize, a = y(s.name);
71
- return s.dir ? {
63
+ return s(t);
64
+ }, sn = async (e, { orderByAlpha: t, name: s } = {}) => {
65
+ let r = Object.values(e.files);
66
+ t && (r = r.slice().sort((i, o) => M(i.name, o.name)));
67
+ const n = {
68
+ filename: s || "",
69
+ records: r.map((i) => {
70
+ const o = i._data.uncompressedSize, a = v(i.name);
71
+ return i.dir ? {
72
72
  dir: !0,
73
73
  basename: a,
74
- uri: s.name,
74
+ uri: i.name,
75
75
  size: o
76
76
  } : {
77
77
  dir: !1,
78
- basename: y(s.name),
79
- uri: s.name,
80
- encodingFormat: b(s.name),
81
- blob: () => s.async("blob"),
82
- string: () => s.async("string"),
83
- ...s.internalStream && {
84
- stream: s.internalStream
78
+ basename: v(i.name),
79
+ uri: i.name,
80
+ encodingFormat: g(i.name),
81
+ blob: () => i.async("blob"),
82
+ string: () => i.async("string"),
83
+ ...i.internalStream && {
84
+ stream: i.internalStream
85
85
  },
86
86
  // this is private API
87
87
  // @ts-expect-error
88
- size: s._data.uncompressedSize
88
+ size: i._data.uncompressedSize
89
89
  };
90
90
  }),
91
91
  close: () => Promise.resolve()
92
92
  };
93
- if (p.log("Generated archive", e), process.env.NODE_ENV === "development" && p.isEnabled()) {
94
- const s = Ae(r.map((o) => o.name));
95
- p.groupCollapsed(...p.getGroupArgs("Archive folder structure")), p.log(`
96
- ${s}`), p.groupEnd();
93
+ if (u.log("Generated archive", n), process.env.NODE_ENV === "development" && u.isEnabled()) {
94
+ const i = Oe(r.map((o) => o.name));
95
+ u.groupCollapsed(...u.getGroupArgs("Archive folder structure")), u.log(`
96
+ ${i}`), u.groupEnd();
97
97
  }
98
- return e;
99
- }, vt = async (n, { name: t } = {}) => {
100
- const i = await n.getFilesArray(), r = {
101
- close: () => n.close(),
98
+ return n;
99
+ }, on = async (e, { name: t } = {}) => {
100
+ const s = await e.getFilesArray(), r = {
101
+ close: () => e.close(),
102
102
  filename: t ?? "",
103
- records: i.map((e) => ({
103
+ records: s.map((n) => ({
104
104
  dir: !1,
105
- basename: e.file.name,
106
- encodingFormat: b(e.file.name),
107
- size: e.file.size,
108
- uri: `${e.path}${e.file.name}`,
109
- blob: async () => await e.file.extract(),
110
- string: async () => (await e.file.extract()).text()
105
+ basename: n.file.name,
106
+ encodingFormat: g(n.file.name),
107
+ size: n.file.size,
108
+ uri: `${n.path}${n.file.name}`,
109
+ blob: async () => await n.file.extract(),
110
+ string: async () => (await n.file.extract()).text()
111
111
  }))
112
112
  };
113
- return p.log("Generated archive", r), r;
114
- }, wt = async (n, {
113
+ return u.log("Generated archive", r), r;
114
+ }, an = async (e, {
115
115
  mimeType: t,
116
- direction: i
116
+ direction: s
117
117
  } = { mimeType: "text/plain" }) => {
118
118
  const r = `
119
119
  <?xml version="1.0" encoding="UTF-8"?>
@@ -126,7 +126,7 @@ ${s}`), p.groupEnd();
126
126
  <manifest>
127
127
  <item id="p01" href="p01.txt" media-type="text/plain"/>
128
128
  </manifest>
129
- <spine page-progression-direction="${i ?? "ltr"}">
129
+ <spine page-progression-direction="${s ?? "ltr"}">
130
130
  <itemref idref="p01" />
131
131
  </spine>
132
132
  </package>
@@ -136,7 +136,7 @@ ${s}`), p.groupEnd();
136
136
  records: [
137
137
  {
138
138
  dir: !1,
139
- basename: y("generated.opf"),
139
+ basename: v("generated.opf"),
140
140
  uri: "generated.opf",
141
141
  blob: async () => new Blob([r]),
142
142
  string: async () => r,
@@ -144,41 +144,41 @@ ${s}`), p.groupEnd();
144
144
  },
145
145
  {
146
146
  dir: !1,
147
- basename: y("p01.txt"),
147
+ basename: v("p01.txt"),
148
148
  uri: "p01.txt",
149
- blob: async () => typeof n == "string" ? new Blob([n]) : n,
150
- string: async () => typeof n == "string" ? n : n.text(),
151
- size: typeof n == "string" ? n.length : n.size,
149
+ blob: async () => typeof e == "string" ? new Blob([e]) : e,
150
+ string: async () => typeof e == "string" ? e : e.text(),
151
+ size: typeof e == "string" ? e.length : e.size,
152
152
  encodingFormat: t
153
153
  }
154
154
  ],
155
155
  close: () => Promise.resolve()
156
156
  };
157
- }, $t = async (n, t) => {
158
- const i = `
157
+ }, cn = async (e, t) => {
158
+ const s = `
159
159
  <?xml version="1.0" encoding="UTF-8"?><package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="bookid">
160
160
  <metadata>
161
161
  <meta property="rendition:layout">${t?.useRenditionFlow ? "reflowable" : "pre-paginated"}</meta>
162
162
  ${t?.useRenditionFlow ? '<meta property="rendition:flow">scrolled-continuous</meta>' : ""}
163
163
  </metadata>
164
164
  <manifest>
165
- ${n.map(
166
- (s) => `<item id="${y(s)}" href="${s}" media-type="${b(s)}"/>`
165
+ ${e.map(
166
+ (i) => `<item id="${v(i)}" href="${i}" media-type="${g(i)}"/>`
167
167
  ).join(`
168
168
  `)}
169
169
  </manifest>
170
170
  <spine>
171
- ${n.map((s) => `<itemref idref="${y(s)}" />`).join(`
171
+ ${e.map((i) => `<itemref idref="${v(i)}" />`).join(`
172
172
  `)}
173
173
  </spine>
174
174
  </package>
175
- `, r = n.map((s) => ({
175
+ `, r = e.map((i) => ({
176
176
  dir: !1,
177
- basename: y(s),
178
- encodingFormat: b(s),
179
- uri: s,
180
- size: 100 / n.length,
181
- blob: async () => (await fetch(s)).blob(),
177
+ basename: v(i),
178
+ encodingFormat: g(i),
179
+ uri: i,
180
+ size: 100 / e.length,
181
+ blob: async () => (await fetch(i)).blob(),
182
182
  string: async () => ""
183
183
  }));
184
184
  return {
@@ -189,174 +189,314 @@ ${s}`), p.groupEnd();
189
189
  uri: "content.opf",
190
190
  size: 0,
191
191
  blob: async () => new Blob(),
192
- string: async () => i
192
+ string: async () => s
193
193
  }, ...r],
194
194
  close: () => Promise.resolve()
195
195
  };
196
- }, Ft = ({
197
- enableReport: n
196
+ }, dn = ({
197
+ enableReport: e
198
198
  } = {}) => {
199
- p.enable(!!n);
200
- }, P = (n) => {
201
- const i = Object.values(n.records).filter(
199
+ u.enable(!!e);
200
+ }, O = (e) => {
201
+ const s = Object.values(e.records).filter(
202
202
  (r) => !r.dir
203
203
  ).find((r) => r.uri.endsWith(".opf"));
204
204
  return {
205
- data: i,
206
- basePath: i?.uri.substring(0, i.uri.lastIndexOf("/")) || ""
205
+ data: s,
206
+ basePath: s?.uri.substring(0, s.uri.lastIndexOf("/")) || ""
207
+ };
208
+ }, D = (e) => e.toLowerCase().endsWith(".opf"), ne = (e) => e.records.some(
209
+ (t) => !t.dir && (D(t.basename) || D(t.uri))
210
+ ), re = ({
211
+ baseUrl: e = "",
212
+ resourcePath: t
213
+ }) => {
214
+ if (!e && /^https?:\/\//.test(t))
215
+ return encodeURI(t);
216
+ const s = e ? `${e}${e.endsWith("/") ? "" : "/"}` : "file://";
217
+ return encodeURI(`${s}${t}`);
218
+ }, Ne = 2e3, V = (e) => {
219
+ const t = Number.parseInt(e, 10);
220
+ if (Number.isFinite(t) && !(t < 0 || t > Ne))
221
+ return t;
222
+ }, _e = (e) => {
223
+ const t = /(?:^|[\s._(-]|\[)p\s*(\d{1,5})\s*[-_]\s*(?:p\s*)?(\d{1,5})(?=$|[^\d])/i.exec(
224
+ e
225
+ );
226
+ return t || /(?:^|[\s._(]|\[)(0\d{1,4})\s*[-_]\s*(0\d{1,4})(?=$|[^\d])/i.exec(
227
+ e
228
+ );
229
+ }, Ue = (e) => {
230
+ const t = e.replace(/\.[^.]+$/, ""), s = _e(t);
231
+ if (!s) return;
232
+ const [, r, n] = s;
233
+ if (r === void 0 || n === void 0)
234
+ return;
235
+ const i = V(r), o = V(n);
236
+ if (!(i === void 0 || o === void 0) && o === i + 1)
237
+ return {
238
+ firstPageLabel: r,
239
+ secondPageLabel: n
240
+ };
241
+ }, se = "__prose-reader__/page-spread", ie = "application/xhtml+xml", Be = /* @__PURE__ */ new Set([
242
+ "image/jpg",
243
+ "image/jpeg",
244
+ "image/png",
245
+ "image/webp"
246
+ ]), X = (e) => e === void 0 ? !1 : Be.has(e), ze = (e) => encodeURIComponent(e), je = ({
247
+ cropSide: e,
248
+ originalUri: t
249
+ }) => `${se}/${ze(t)}/${e}.xhtml`, De = (e) => e === "left" ? { pageSpreadLeft: !0, pageSpreadRight: void 0 } : { pageSpreadLeft: void 0, pageSpreadRight: !0 }, Ve = (e) => e === "rtl" ? ["right", "left"] : ["left", "right"], H = ({
250
+ baseUrl: e,
251
+ cropSide: t,
252
+ label: s,
253
+ originalSpineItem: r,
254
+ originalUri: n,
255
+ progressionWeight: i
256
+ }) => {
257
+ const o = je({
258
+ cropSide: t,
259
+ originalUri: n
260
+ });
261
+ return {
262
+ ...r,
263
+ id: `${r.id}.${s}`,
264
+ href: re({ baseUrl: e, resourcePath: o }),
265
+ mediaType: ie,
266
+ progressionWeight: i,
267
+ renditionLayout: "pre-paginated",
268
+ ...De(t)
269
+ };
270
+ }, G = ({
271
+ href: e,
272
+ id: t,
273
+ mediaType: s
274
+ }) => ({
275
+ href: e,
276
+ id: t,
277
+ mediaType: s
278
+ }), Xe = ({
279
+ archive: e,
280
+ baseUrl: t,
281
+ spineItem: s
282
+ }) => {
283
+ const r = [s.href, He(s.href)], n = new Set(
284
+ r.flatMap((i) => qe(i, t))
285
+ );
286
+ return e.records.find(
287
+ (i) => !i.dir && n.has(i.uri)
288
+ );
289
+ }, He = (e) => {
290
+ try {
291
+ return decodeURI(e);
292
+ } catch {
293
+ return e;
294
+ }
295
+ }, Ge = (e) => e.endsWith("/") ? e : `${e}/`, qe = (e, t) => {
296
+ const s = [e];
297
+ if (e.startsWith("file://") && s.push(e.slice(7)), t) {
298
+ const r = Ge(t);
299
+ e.startsWith(r) && s.push(e.slice(r.length));
300
+ }
301
+ return s;
302
+ }, Ke = (e) => k(e?.encodingFormat ?? "") || g(e?.basename ?? ""), Je = (e) => g(e.uri) || g(e.basename), Ye = (e) => {
303
+ if (e === void 0 || e.dir) return !1;
304
+ const t = Je(e);
305
+ return X(t) ? X(Ke(e)) : !1;
306
+ }, Qe = ({ archive: e, baseUrl: t }) => async (s) => {
307
+ if (ne(e)) return s;
308
+ const r = [], n = s.spineItems.flatMap((i) => {
309
+ const o = Xe({
310
+ archive: e,
311
+ baseUrl: t,
312
+ spineItem: i
313
+ });
314
+ if (!Ye(o))
315
+ return [i];
316
+ const a = Ue(o.basename);
317
+ if (a === void 0) return [i];
318
+ const [c, l] = Ve(
319
+ s.readingDirection
320
+ ), p = i.progressionWeight !== void 0 ? i.progressionWeight / 2 : void 0, f = H({
321
+ baseUrl: t,
322
+ cropSide: c,
323
+ label: a.firstPageLabel,
324
+ originalSpineItem: i,
325
+ originalUri: o.uri,
326
+ progressionWeight: p
327
+ }), h = H({
328
+ baseUrl: t,
329
+ cropSide: l,
330
+ label: a.secondPageLabel,
331
+ originalSpineItem: i,
332
+ originalUri: o.uri,
333
+ progressionWeight: p
334
+ });
335
+ return r.push(
336
+ G(f),
337
+ G(h)
338
+ ), [f, h];
339
+ });
340
+ return r.length === 0 ? s : {
341
+ ...s,
342
+ spineItems: n.map((i, o) => ({
343
+ ...i,
344
+ index: o
345
+ })),
346
+ items: [...s.items, ...r]
207
347
  };
208
348
  };
209
- async function K(n) {
210
- const { data: t, basePath: i } = P(n) || {};
349
+ async function oe(e) {
350
+ const { data: t, basePath: s } = O(e) || {};
211
351
  if (!t || t.dir)
212
352
  return;
213
353
  const r = await t.string();
214
354
  return {
215
- opf: re(r),
216
- basePath: i
355
+ opf: ge(r),
356
+ basePath: s
217
357
  };
218
358
  }
219
- const xe = X.toLowerCase(), Le = ({ archive: n }) => async (t) => {
220
- const i = n.records.find(
221
- (e) => !e.dir && e.basename.toLowerCase() === xe
359
+ const Ze = Z.toLowerCase(), et = ({ archive: e }) => async (t) => {
360
+ const s = e.records.find(
361
+ (n) => !n.dir && n.basename.toLowerCase() === Ze
222
362
  );
223
- if (!i || i.dir)
363
+ if (!s || s.dir)
224
364
  return t;
225
- const r = await i.string();
365
+ const r = await s.string();
226
366
  try {
227
- const e = se(r), { renditionLayout: s } = T(e);
367
+ const n = ye(r), { renditionLayout: i } = I(n);
228
368
  return {
229
369
  ...t,
230
- renditionLayout: t.renditionLayout ?? s
370
+ renditionLayout: t.renditionLayout ?? i
231
371
  };
232
- } catch (e) {
372
+ } catch (n) {
233
373
  return console.error(
234
- `Unable to parse ${X} for content
374
+ `Unable to parse ${Z} for content
235
375
  `,
236
376
  r
237
- ), console.error(e), t;
377
+ ), console.error(n), t;
238
378
  }
239
- }, U = G.toLowerCase(), Te = ({ archive: n }) => async (t) => {
240
- const i = n.records.find(
241
- (s) => s.basename.toLowerCase() === U && !s.dir
379
+ }, q = ee.toLowerCase(), tt = ({ archive: e }) => async (t) => {
380
+ const s = e.records.find(
381
+ (i) => i.basename.toLowerCase() === q && !i.dir
242
382
  );
243
- if (!i || i.dir)
383
+ if (!s || s.dir)
244
384
  return t;
245
385
  const r = {
246
386
  ...t,
247
387
  spineItems: t.spineItems.filter(
248
- (s) => !s.id.toLowerCase().endsWith(U)
249
- ).map((s, o, a) => ({
250
- ...s,
388
+ (i) => !i.id.toLowerCase().endsWith(q)
389
+ ).map((i, o, a) => ({
390
+ ...i,
251
391
  progressionWeight: 1 / a.length
252
392
  }))
253
- }, e = await i.string();
393
+ }, n = await s.string();
254
394
  try {
255
- const s = ie(e), o = T(s);
395
+ const i = ve(n), o = I(i);
256
396
  return {
257
397
  ...r,
258
398
  readingDirection: o.readingDirection ?? "ltr"
259
399
  };
260
- } catch (s) {
400
+ } catch (i) {
261
401
  return console.error(
262
- `Unable to parse ${G} for content
402
+ `Unable to parse ${ee} for content
263
403
  `,
264
- e
265
- ), console.error(s), r;
404
+ n
405
+ ), console.error(i), r;
266
406
  }
267
- }, Ie = ({ archive: n, baseUrl: t }) => async () => {
268
- const i = Object.values(n.records).filter((r) => !r.dir);
407
+ }, nt = ({ archive: e, baseUrl: t }) => async () => {
408
+ const s = Object.values(e.records).filter((r) => !r.dir);
269
409
  return {
270
- filename: n.filename,
271
- title: n.records.find(({ dir: r }) => r)?.basename.replace(/\/$/, "") || n.filename,
410
+ filename: e.filename,
411
+ title: e.records.find(({ dir: r }) => r)?.basename.replace(/\/$/, "") || e.filename,
272
412
  renditionLayout: void 0,
273
413
  renditionSpread: "auto",
274
414
  readingDirection: "ltr",
275
- spineItems: i.filter((r) => !r.basename.endsWith(".db")).map((r, e) => {
276
- const s = t || (/^https?:\/\//.test(r.uri) ? "" : "file://");
277
- return {
278
- // some books such as cbz can have same basename inside different sub folder
279
- // we need to make sure to have unique index
280
- // /chap01/01.png, /chap02/01.png, etc
281
- id: `${e}.${r.basename}`,
282
- index: e,
283
- href: encodeURI(`${s}${r.uri}`),
284
- renditionLayout: void 0,
285
- progressionWeight: 1 / i.length,
286
- pageSpreadLeft: void 0,
287
- pageSpreadRight: void 0,
288
- mediaType: r.encodingFormat
289
- };
290
- }),
291
- items: i.map((r, e) => ({
292
- id: `${e}.${r.basename}`,
415
+ spineItems: s.filter((r) => !r.basename.endsWith(".db")).map((r, n) => ({
416
+ // some books such as cbz can have same basename inside different sub folder
417
+ // we need to make sure to have unique index
418
+ // /chap01/01.png, /chap02/01.png, etc
419
+ id: `${n}.${r.basename}`,
420
+ index: n,
421
+ href: re({
422
+ baseUrl: t,
423
+ resourcePath: r.uri
424
+ }),
425
+ renditionLayout: void 0,
426
+ progressionWeight: 1 / s.length,
427
+ pageSpreadLeft: void 0,
428
+ pageSpreadRight: void 0,
429
+ mediaType: r.encodingFormat
430
+ })),
431
+ items: s.map((r, n) => ({
432
+ id: `${n}.${r.basename}`,
293
433
  href: encodeURI(`${t}${r.uri}`)
294
434
  }))
295
435
  };
296
- }, q = async ({
297
- archive: n,
436
+ }, ae = async ({
437
+ archive: e,
298
438
  archiveOpf: t
299
439
  }) => {
300
440
  if (!t) return [];
301
- const { opf: i, basePath: r } = t, { spineRows: e } = i;
302
- return n.records.filter((o) => e.find((a) => r ? `${r}/${a.href}` === o.uri : `${a.href}` === o.uri));
303
- }, J = (n, t, i) => {
304
- const { basePath: r } = P(t) || {};
305
- return n.map((e) => {
306
- const s = e.href, o = i?.(s) ?? "";
441
+ const { opf: s, basePath: r } = t, { spineRows: n } = s;
442
+ return e.records.filter((o) => n.find((a) => r ? `${r}/${a.href}` === o.uri : `${a.href}` === o.uri));
443
+ }, ce = (e, t, s) => {
444
+ const { basePath: r } = O(t) || {};
445
+ return e.map((n) => {
446
+ const i = n.href, o = s?.(i) ?? "";
307
447
  return {
308
- href: r ? `${o}${r}/${s}` : `${o}${s}`,
309
- id: e.id,
310
- mediaType: e.mediaType
448
+ href: r ? `${o}${r}/${i}` : `${o}${i}`,
449
+ id: n.id,
450
+ mediaType: n.mediaType
311
451
  };
312
452
  });
313
- }, Se = (n) => {
314
- const t = n?.trim();
453
+ }, rt = (e) => {
454
+ const t = e?.trim();
315
455
  return t === "scrolled-continuous" || t === "scrolled-doc" || t === "paginated" || t === "auto" ? t : "auto";
316
- }, Re = (n) => {
317
- const t = n?.trim();
456
+ }, st = (e) => {
457
+ const t = e?.trim();
318
458
  if (t === "none" || t === "landscape" || t === "portrait" || t === "both" || t === "auto")
319
459
  return t;
320
- }, Ce = (n) => {
321
- const t = n?.trim();
460
+ }, it = (e) => {
461
+ const t = e?.trim();
322
462
  if (t === "cover" || t === "title-page" || t === "copyright-page" || t === "text")
323
463
  return t;
324
- }, Ee = ({
325
- archive: n,
464
+ }, ot = ({
465
+ archive: e,
326
466
  baseUrl: t,
327
- archiveOpf: i
467
+ archiveOpf: s
328
468
  }) => async (r) => {
329
- if (!i)
469
+ if (!s)
330
470
  return r;
331
- const { opf: e, basePath: s } = i, o = T(e);
332
- p.groupCollapsed(...p.getGroupArgs("OPF parsed")), p.log("opf", e), p.groupEnd();
333
- const a = e.renditionLayoutMeta?.trim(), c = a === "reflowable" || a === "pre-paginated" ? a : o.renditionLayout, l = e.title?.trim() || n.records.find(({ dir: d }) => d)?.basename || "", u = o.readingDirection ?? "ltr", h = (await q({
334
- archive: n,
335
- archiveOpf: i
471
+ const { opf: n, basePath: i } = s, o = I(n);
472
+ u.groupCollapsed(...u.getGroupArgs("OPF parsed")), u.log("opf", n), u.groupEnd();
473
+ const a = n.renditionLayoutMeta?.trim(), c = a === "reflowable" || a === "pre-paginated" ? a : o.renditionLayout, l = n.title?.trim() || e.records.find(({ dir: d }) => d)?.basename || "", p = o.readingDirection ?? "ltr", h = (await ae({
474
+ archive: e,
475
+ archiveOpf: s
336
476
  })).reduce(
337
477
  (d, w) => w.size + d,
338
478
  0
339
- ), g = e.guide, v = [];
340
- for (const d of g) {
341
- const w = Ce(d.type);
342
- w !== void 0 && v.push({ href: d.href, title: d.title, type: w });
479
+ ), y = n.guide, b = [];
480
+ for (const d of y) {
481
+ const w = it(d.type);
482
+ w !== void 0 && b.push({ href: d.href, title: d.title, type: w });
343
483
  }
344
484
  return {
345
- filename: n.filename,
485
+ filename: e.filename,
346
486
  renditionLayout: c,
347
- renditionFlow: Se(e.renditionFlowMeta),
348
- renditionSpread: Re(e.renditionSpreadMeta),
487
+ renditionFlow: rt(n.renditionFlowMeta),
488
+ renditionSpread: st(n.renditionSpreadMeta),
349
489
  title: l,
350
- readingDirection: u,
490
+ readingDirection: p,
351
491
  /**
352
492
  * @see https://www.w3.org/TR/epub/#sec-itemref-elem
353
493
  */
354
- spineItems: e.spineRows.map((d, w) => {
355
- const m = n.records.find((S) => S.uri.endsWith(d.href))?.size || 0, $ = t || (/^https?:\/\//.test(d.href) ? "" : "file://");
494
+ spineItems: n.spineRows.map((d, w) => {
495
+ const m = e.records.find((A) => A.uri.endsWith(d.href))?.size || 0, $ = t || (/^https?:\/\//.test(d.href) ? "" : "file://");
356
496
  return {
357
497
  id: d.id,
358
498
  index: w,
359
- href: d.href.startsWith("https://") ? d.href : s ? `${$}${s}/${d.href}` : `${$}${d.href}`,
499
+ href: d.href.startsWith("https://") ? d.href : i ? `${$}${i}/${d.href}` : `${$}${d.href}`,
360
500
  renditionLayout: d.renditionLayout ?? c,
361
501
  progressionWeight: m / h,
362
502
  pageSpreadLeft: d.pageSpreadLeft,
@@ -364,194 +504,194 @@ const xe = X.toLowerCase(), Le = ({ archive: n }) => async (t) => {
364
504
  mediaType: d.mediaType
365
505
  };
366
506
  }),
367
- items: J(e.manifestItems, n, (d) => /^https?:\/\//.test(d) ? "" : t || "file://"),
368
- guide: v.length > 0 ? v : void 0
507
+ items: ce(n.manifestItems, e, (d) => /^https?:\/\//.test(d) ? "" : t || "file://"),
508
+ guide: b.length > 0 ? b : void 0
369
509
  };
370
- }, ke = (n) => {
371
- const t = n.descendantWithPath("head")?.childrenNamed("meta").find((i) => i.attr.name === "viewport");
510
+ }, at = (e) => {
511
+ const t = e.descendantWithPath("head")?.childrenNamed("meta").find((s) => s.attr.name === "viewport");
372
512
  return !!(t && t.attr.name === "viewport");
373
- }, We = (n) => n.reduce(async (t, i) => {
374
- if (!await t || !te({
375
- mimeType: i.encodingFormat,
376
- uri: i.uri
513
+ }, ct = (e) => e.reduce(async (t, s) => {
514
+ if (!await t || !fe({
515
+ mimeType: s.encodingFormat,
516
+ uri: s.uri
377
517
  }))
378
518
  return !1;
379
- const e = i.dir ? null : await i.string();
380
- return e ? ke(new I(e)) : !1;
381
- }, Promise.resolve(!0)), Pe = ({
382
- archive: n,
519
+ const n = s.dir ? null : await s.string();
520
+ return n ? at(new P(n)) : !1;
521
+ }, Promise.resolve(!0)), dt = ({
522
+ archive: e,
383
523
  archiveOpf: t
384
- }) => async (i) => {
385
- if (i.renditionLayout === "reflowable" && i.spineItems.every((e) => e.renditionLayout === "reflowable")) {
386
- const e = await q({
387
- archive: n,
524
+ }) => async (s) => {
525
+ if (s.renditionLayout === "reflowable" && s.spineItems.every((n) => n.renditionLayout === "reflowable")) {
526
+ const n = await ae({
527
+ archive: e,
388
528
  archiveOpf: t
389
529
  });
390
- if (await We(e))
530
+ if (await ct(n))
391
531
  return {
392
- ...i,
393
- spineItems: i.spineItems.map((o) => ({
532
+ ...s,
533
+ spineItems: s.spineItems.map((o) => ({
394
534
  ...o,
395
535
  renditionLayout: "pre-paginated"
396
536
  })),
397
537
  renditionLayout: "pre-paginated"
398
538
  };
399
539
  }
400
- return i;
401
- }, Ne = async (n) => {
540
+ return s;
541
+ }, lt = async (e) => {
402
542
  let t;
403
543
  return await Promise.all(
404
- n.records.map(async (i) => {
405
- if (i.dir || !i.uri.endsWith(N)) return;
406
- const r = await i.string();
544
+ e.records.map(async (s) => {
545
+ if (s.dir || !s.uri.endsWith(N)) return;
546
+ const r = await s.string();
407
547
  try {
408
- const { renditionLayout: e } = oe(r);
409
- e && (t = e);
410
- } catch (e) {
548
+ const { renditionLayout: n } = be(r);
549
+ n && (t = n);
550
+ } catch (n) {
411
551
  console.error(
412
552
  `Unable to parse ${N} for content
413
553
  `,
414
554
  r
415
- ), console.error(e);
555
+ ), console.error(n);
416
556
  }
417
557
  })
418
558
  ), {
419
559
  kind: "kobo",
420
560
  ...t !== void 0 ? { renditionLayout: t } : {}
421
561
  };
422
- }, Oe = ({ archive: n }) => async (t) => {
423
- const i = await Ne(n), { renditionLayout: r } = T(i);
562
+ }, pt = ({ archive: e }) => async (t) => {
563
+ const s = await lt(e), { renditionLayout: r } = I(s);
424
564
  return {
425
565
  ...t,
426
566
  renditionLayout: t.renditionLayout ?? r
427
567
  };
428
- }, ze = (n) => n.records.some((t) => t.basename.endsWith(".opf")), Me = ({ archive: n }) => async (t) => ze(n) ? t : {
568
+ }, ut = ({ archive: e }) => async (t) => ne(e) ? t : {
429
569
  ...t,
430
570
  spineItems: t.spineItems.map((r) => {
431
- const e = n.records.find(
571
+ const n = e.records.find(
432
572
  (o) => decodeURI(r.href).endsWith(o.uri)
433
- ), s = V(e?.encodingFormat ?? "") || b(e?.basename ?? "");
573
+ ), i = k(n?.encodingFormat ?? "") || g(n?.basename ?? "");
434
574
  return {
435
575
  ...r,
436
- renditionLayout: s && ne(s) ? "pre-paginated" : r.renditionLayout
576
+ renditionLayout: i && he(i) ? "pre-paginated" : r.renditionLayout
437
577
  };
438
578
  })
439
- }, Y = (n) => n ? n.children.map((t) => t instanceof ce ? t.text : t instanceof de ? Y(t) : "").join("").trim() : "", Be = (n) => ae(n.properties).includes("nav"), Q = (n, { basePath: t, baseUrl: i }) => {
579
+ }, de = (e) => e ? e.children.map((t) => t instanceof $e ? t.text : t instanceof Se ? de(t) : "").join("").trim() : "", ft = (e) => we(e.properties).includes("nav"), le = (e, { basePath: t, baseUrl: s }) => {
440
580
  const r = {
441
581
  contents: [],
442
582
  path: "",
443
583
  href: "",
444
584
  title: ""
445
585
  };
446
- let e = n.childNamed("span") || n.childNamed("a");
447
- r.title = (e?.attr.title || e?.val.trim() || Y(e)) ?? "";
448
- let s = e?.name;
449
- s !== "a" && (e = n.descendantWithPath(`${s}.a`), e && (s = e.name.toLowerCase())), s === "a" && e?.attr.href && (r.path = L(t, e.attr.href), r.href = L(i, t, e.attr.href));
450
- const o = n.childNamed("ol");
586
+ let n = e.childNamed("span") || e.childNamed("a");
587
+ r.title = (n?.attr.title || n?.val.trim() || de(n)) ?? "";
588
+ let i = n?.name;
589
+ i !== "a" && (n = e.descendantWithPath(`${i}.a`), n && (i = n.name.toLowerCase())), i === "a" && n?.attr.href && (r.path = F(t, n.attr.href), r.href = F(s, t, n.attr.href));
590
+ const o = e.childNamed("ol");
451
591
  if (o) {
452
592
  const a = o.childrenNamed("li");
453
593
  a && a.length > 0 && (r.contents = a.map(
454
- (c) => Q(c, { basePath: t, baseUrl: i })
594
+ (c) => le(c, { basePath: t, baseUrl: s })
455
595
  ));
456
596
  }
457
597
  return r;
458
- }, je = (n, { basePath: t, baseUrl: i }) => {
598
+ }, ht = (e, { basePath: t, baseUrl: s }) => {
459
599
  const r = [];
460
- let e;
461
- return n.descendantWithPath("body.nav.ol") ? e = n.descendantWithPath("body.nav.ol")?.children : n.descendantWithPath("body.section.nav.ol") && (e = n.descendantWithPath("body.section.nav.ol")?.children), e && e.length > 0 && e.filter((s) => s.name === "li").forEach((s) => {
462
- r.push(Q(s, { basePath: t, baseUrl: i }));
600
+ let n;
601
+ 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((i) => i.name === "li").forEach((i) => {
602
+ r.push(le(i, { basePath: t, baseUrl: s }));
463
603
  }), r;
464
- }, Ue = async (n, t, { baseUrl: i }) => {
465
- const r = n.manifestItems.find(Be);
604
+ }, mt = async (e, t, { baseUrl: s }) => {
605
+ const r = e.manifestItems.find(ft);
466
606
  if (r?.href) {
467
- const e = Object.values(t.records).find(
468
- (s) => s.uri.endsWith(r.href)
607
+ const n = Object.values(t.records).find(
608
+ (i) => i.uri.endsWith(r.href)
469
609
  );
470
- if (e && !e.dir) {
471
- const s = new I(await e.string()), o = $e(e.uri);
472
- return je(s, { basePath: o, baseUrl: i });
610
+ if (n && !n.dir) {
611
+ const i = new P(await n.string()), o = ke(n.uri);
612
+ return ht(i, { basePath: o, baseUrl: s });
473
613
  }
474
614
  }
475
- }, Z = (n, {
615
+ }, pe = (e, {
476
616
  opfBasePath: t,
477
- baseUrl: i,
617
+ baseUrl: s,
478
618
  prefix: r
479
619
  }) => {
480
- const e = n?.childNamed(`${r}content`)?.attr.src || "", s = {
481
- title: n?.descendantWithPath(`${r}navLabel.${r}text`)?.val || "",
482
- path: L(t, e),
483
- href: L(i, t, e),
620
+ const n = e?.childNamed(`${r}content`)?.attr.src || "", i = {
621
+ title: e?.descendantWithPath(`${r}navLabel.${r}text`)?.val || "",
622
+ path: F(t, n),
623
+ href: F(s, t, n),
484
624
  contents: []
485
- }, o = n.childrenNamed(`${r}navPoint`);
486
- return o && o.length > 0 && (s.contents = o.map(
487
- (a) => Z(a, { opfBasePath: t, baseUrl: i, prefix: r })
488
- )), s;
489
- }, De = (n, { opfBasePath: t, baseUrl: i }) => {
490
- const r = [], e = n.name;
491
- let s = "";
492
- return e.indexOf(":") !== -1 && (s = `${e.split(":")[0]}:`), n.childNamed(`${s}navMap`)?.childrenNamed(`${s}navPoint`).forEach((o) => {
493
- r.push(Z(o, { opfBasePath: t, baseUrl: i, prefix: s }));
625
+ }, o = e.childrenNamed(`${r}navPoint`);
626
+ return o && o.length > 0 && (i.contents = o.map(
627
+ (a) => pe(a, { opfBasePath: t, baseUrl: s, prefix: r })
628
+ )), i;
629
+ }, gt = (e, { opfBasePath: t, baseUrl: s }) => {
630
+ const r = [], n = e.name;
631
+ let i = "";
632
+ return n.indexOf(":") !== -1 && (i = `${n.split(":")[0]}:`), e.childNamed(`${i}navMap`)?.childrenNamed(`${i}navPoint`).forEach((o) => {
633
+ r.push(pe(o, { opfBasePath: t, baseUrl: s, prefix: i }));
494
634
  }), r;
495
- }, _e = async ({
496
- opf: n,
635
+ }, yt = async ({
636
+ opf: e,
497
637
  opfBasePath: t,
498
- baseUrl: i,
638
+ baseUrl: s,
499
639
  archive: r
500
640
  }) => {
501
- const e = n.spineTocIdref;
502
- if (e) {
503
- const s = n.manifestItems.find((o) => o.id === e);
504
- if (s) {
505
- const o = `${t}${t === "" ? "" : "/"}${s.href}`, a = Object.values(r.records).find(
641
+ const n = e.spineTocIdref;
642
+ if (n) {
643
+ const i = e.manifestItems.find((o) => o.id === n);
644
+ if (i) {
645
+ const o = `${t}${t === "" ? "" : "/"}${i.href}`, a = Object.values(r.records).find(
506
646
  (c) => c.uri.endsWith(o)
507
647
  );
508
648
  if (a && !a.dir) {
509
- const c = new I(await a.string());
510
- return De(c, { opfBasePath: t, baseUrl: i });
649
+ const c = new P(await a.string());
650
+ return gt(c, { opfBasePath: t, baseUrl: s });
511
651
  }
512
652
  }
513
653
  }
514
- }, Ve = async (n, t, { baseUrl: i }) => {
515
- const { basePath: r } = P(t) || {}, e = await Ue(n, t, {
516
- baseUrl: i
654
+ }, vt = async (e, t, { baseUrl: s }) => {
655
+ const { basePath: r } = O(t) || {}, n = await mt(e, t, {
656
+ baseUrl: s
517
657
  });
518
- if (e)
519
- return e;
520
- const s = await _e({
521
- opf: n,
658
+ if (n)
659
+ return n;
660
+ const i = await yt({
661
+ opf: e,
522
662
  opfBasePath: r ?? "",
523
663
  archive: t,
524
- baseUrl: i
664
+ baseUrl: s
525
665
  });
526
- if (s)
527
- return s;
528
- }, Xe = (n) => n.replace(/\.[^.]+$/, "").replace(/[_-]/g, " ").replace(/\s+/g, " ").trim(), Ge = (n, t) => {
529
- if (!(n.spineItems.length === 0 || !n.spineItems.every((r) => (V(r.mediaType ?? "") || b(r.href))?.startsWith("audio/"))))
530
- return n.spineItems.map((r) => {
531
- const e = t.records.find(
532
- (s) => !s.dir && decodeURI(r.href).endsWith(s.uri)
666
+ if (i)
667
+ return i;
668
+ }, bt = (e) => e.replace(/\.[^.]+$/, "").replace(/[_-]/g, " ").replace(/\s+/g, " ").trim(), wt = (e, t) => {
669
+ if (!(e.spineItems.length === 0 || !e.spineItems.every((r) => (k(r.mediaType ?? "") || g(r.href))?.startsWith("audio/"))))
670
+ return e.spineItems.map((r) => {
671
+ const n = t.records.find(
672
+ (i) => !i.dir && decodeURI(r.href).endsWith(i.uri)
533
673
  );
534
674
  return {
535
- title: Xe(e?.basename ?? r.href),
675
+ title: bt(n?.basename ?? r.href),
536
676
  href: r.href,
537
- path: e?.uri ?? r.href,
677
+ path: n?.uri ?? r.href,
538
678
  contents: []
539
679
  };
540
680
  });
541
- }, He = (n, { baseUrl: t }) => {
542
- const i = [...n.records].sort(
543
- (e, s) => W(e.uri, s.uri)
544
- ), r = (e, s, o, a, c) => {
545
- const l = e.find((h) => h.title === s), [u, ...f] = o;
546
- return l ? u ? [
547
- ...e.filter((g) => g !== l),
681
+ }, $t = (e, { baseUrl: t }) => {
682
+ const s = [...e.records].sort(
683
+ (n, i) => M(n.uri, i.uri)
684
+ ), r = (n, i, o, a, c) => {
685
+ const l = n.find((h) => h.title === i), [p, ...f] = o;
686
+ return l ? p ? [
687
+ ...n.filter((y) => y !== l),
548
688
  {
549
689
  ...l,
550
690
  contents: [
551
691
  ...l.contents,
552
692
  ...r(
553
693
  l.contents,
554
- u,
694
+ p,
555
695
  f,
556
696
  a,
557
697
  c
@@ -559,170 +699,292 @@ const xe = X.toLowerCase(), Le = ({ archive: n }) => async (t) => {
559
699
  ]
560
700
  }
561
701
  ] : l.path.split("/").length > c.split("/").length ? [
562
- ...e.filter((g) => g !== l),
702
+ ...n.filter((y) => y !== l),
563
703
  {
564
704
  ...l,
565
705
  path: c,
566
706
  href: a
567
707
  }
568
- ] : e : u ? [
569
- ...e,
708
+ ] : n : p ? [
709
+ ...n,
570
710
  {
571
711
  contents: r(
572
712
  [],
573
- u,
713
+ p,
574
714
  f,
575
715
  a,
576
716
  c
577
717
  ),
578
718
  href: a,
579
719
  path: c,
580
- title: s
720
+ title: i
581
721
  }
582
722
  ] : [
583
- ...e,
723
+ ...n,
584
724
  {
585
725
  contents: [],
586
726
  href: a,
587
727
  path: c,
588
- title: s
728
+ title: i
589
729
  }
590
730
  ];
591
731
  };
592
- return i.reduce((e, s) => {
593
- if (s.dir) return e;
594
- const o = s.uri.split("/").slice(0, -1), [a, ...c] = o;
595
- if (!a) return e;
596
- const l = L(t, encodeURI(s.uri)).replace(/\/$/, ""), u = s.uri.replace(/\/$/, "");
597
- return r(e, a, c, l, u);
732
+ return s.reduce((n, i) => {
733
+ if (i.dir) return n;
734
+ const o = i.uri.split("/").slice(0, -1), [a, ...c] = o;
735
+ if (!a) return n;
736
+ const l = F(t, encodeURI(i.uri)).replace(/\/$/, ""), p = i.uri.replace(/\/$/, "");
737
+ return r(n, a, c, l, p);
598
738
  }, []);
599
- }, Ke = async (n, t, {
600
- baseUrl: i,
739
+ }, St = async (e, t, {
740
+ baseUrl: s,
601
741
  archiveOpf: r
602
742
  }) => {
603
743
  if (r)
604
- return await Ve(r.opf, n, { baseUrl: i }) || [];
605
- const e = Ge(t, n);
606
- if (e) return e;
607
- const s = He(n, { baseUrl: i });
608
- if (s.length !== 0)
609
- return s;
610
- }, qe = ({
611
- archive: n,
744
+ return await vt(r.opf, e, { baseUrl: s }) || [];
745
+ const n = wt(t, e);
746
+ if (n) return n;
747
+ const i = $t(e, { baseUrl: s });
748
+ if (i.length !== 0)
749
+ return i;
750
+ }, Rt = ({
751
+ archive: e,
612
752
  baseUrl: t,
613
- archiveOpf: i
753
+ archiveOpf: s
614
754
  }) => async (r) => {
615
755
  if (r.nav) return r;
616
- const e = await Ke(n, r, {
756
+ const n = await St(e, r, {
617
757
  baseUrl: t,
618
- archiveOpf: i
758
+ archiveOpf: s
619
759
  });
620
- return e ? {
760
+ return n ? {
621
761
  ...r,
622
762
  nav: {
623
- toc: e
763
+ toc: n
624
764
  }
625
765
  } : r;
626
- }, Je = async (n, { baseUrl: t = "" } = {}) => {
627
- const i = await K(n), r = [
628
- Ee({ archive: n, baseUrl: t, archiveOpf: i }),
629
- Te({ archive: n }),
630
- Le({ archive: n }),
631
- Me({ archive: n }),
632
- Pe({ archive: n, archiveOpf: i }),
633
- Oe({ archive: n }),
634
- qe({ archive: n, baseUrl: t, archiveOpf: i })
766
+ }, xt = (e) => e ? e.endsWith("/") ? e : `${e}/` : "", Ft = async (e, { baseUrl: t = "" } = {}) => {
767
+ const s = await oe(e), r = xt(t), n = [
768
+ ot({ archive: e, baseUrl: r, archiveOpf: s }),
769
+ tt({ archive: e }),
770
+ et({ archive: e }),
771
+ ut({ archive: e }),
772
+ Qe({ archive: e, baseUrl: r }),
773
+ dt({ archive: e, archiveOpf: s }),
774
+ pt({ archive: e }),
775
+ Rt({ archive: e, baseUrl: r, archiveOpf: s })
635
776
  ];
636
777
  try {
637
- const e = Ie({ archive: n, baseUrl: t })(), s = await r.reduce(async (o, a) => await a(await o), e);
638
- if (p.log("Generated manifest", s), process.env.NODE_ENV === "development" && p.isEnabled()) {
639
- const o = JSON.stringify(s, null, 2);
640
- p.groupCollapsed(...p.getGroupArgs("Generated manifest")), p.log(`
641
- ${o}`), p.groupEnd();
778
+ const i = nt({
779
+ archive: e,
780
+ baseUrl: r
781
+ })(), o = await n.reduce(async (a, c) => await c(await a), i);
782
+ if (u.log("Generated manifest", o), process.env.NODE_ENV === "development" && u.isEnabled()) {
783
+ const a = JSON.stringify(o, null, 2);
784
+ u.groupCollapsed(...u.getGroupArgs("Generated manifest")), u.log(`
785
+ ${a}`), u.groupEnd();
642
786
  }
643
- return s;
644
- } catch (e) {
645
- throw p.error(e), e;
787
+ return o;
788
+ } catch (i) {
789
+ throw u.error(i), i;
646
790
  }
647
- }, Ye = (n) => {
648
- const t = n.descendantWithPath("head")?.childrenNamed("meta").find((i) => i.attr.name === "calibre:cover");
791
+ }, C = /* @__PURE__ */ new WeakMap(), It = (e) => {
792
+ try {
793
+ return decodeURIComponent(e);
794
+ } catch {
795
+ return;
796
+ }
797
+ }, Pt = (e) => {
798
+ const t = e.indexOf(`${se}/`);
799
+ if (t < 0) return;
800
+ const r = e.slice(t).split("/"), n = r[2], i = r[3];
801
+ if (r.length !== 4 || r[0] !== "__prose-reader__" || r[1] !== "page-spread" || n === void 0 || i === void 0)
802
+ return;
803
+ const o = i.split(".")[0];
804
+ if (o !== "left" && o !== "right") return;
805
+ const a = It(n);
806
+ if (a !== void 0)
807
+ return {
808
+ originalUri: a,
809
+ cropSide: o
810
+ };
811
+ }, At = ({
812
+ cropSide: e,
813
+ imageHeight: t,
814
+ imageWidth: s
815
+ }) => {
816
+ const r = Math.floor(s / 2), n = s - r;
817
+ return e === "left" ? { x: 0, width: r, height: t } : { x: r, width: n, height: t };
818
+ }, Lt = (e) => /^https?:\/\//.test(e) ? e : `../../../${encodeURI(e)}`, Tt = async (e) => {
819
+ if (typeof createImageBitmap != "function")
820
+ throw new Error("Page spread XHTML generation requires createImageBitmap");
821
+ const t = await createImageBitmap(e);
822
+ try {
823
+ return {
824
+ height: t.height,
825
+ width: t.width
826
+ };
827
+ } finally {
828
+ t.close();
829
+ }
830
+ }, Et = ({
831
+ cropSide: e,
832
+ imageDimensions: t,
833
+ originalUri: s
834
+ }) => {
835
+ if (t.width < 2)
836
+ throw new Error("Page spread image is too narrow to split");
837
+ const r = At({
838
+ cropSide: e,
839
+ imageHeight: t.height,
840
+ imageWidth: t.width
841
+ });
842
+ return `<?xml version="1.0" encoding="UTF-8"?>
843
+ <html xmlns="http://www.w3.org/1999/xhtml">
844
+ <head>
845
+ <meta name="viewport" content="width=${r.width}, height=${r.height}" />
846
+ <style>
847
+ html,
848
+ body {
849
+ width: ${r.width}px;
850
+ height: ${r.height}px;
851
+ margin: 0;
852
+ overflow: hidden;
853
+ }
854
+
855
+ img {
856
+ display: block;
857
+ width: ${t.width}px;
858
+ height: ${t.height}px;
859
+ max-width: none;
860
+ transform: translateX(-${r.x}px);
861
+ user-select: none;
862
+ -webkit-user-drag: none;
863
+ }
864
+ </style>
865
+ </head>
866
+ <body>
867
+ <img src="${me(Lt(s))}" alt="" />
868
+ </body>
869
+ </html>`;
870
+ }, Ct = async ({
871
+ archive: e,
872
+ resourcePath: t
873
+ }) => {
874
+ const s = Pt(t);
875
+ if (s === void 0) return;
876
+ const r = e.records.find(
877
+ (a) => a.uri === s.originalUri && !a.dir
878
+ );
879
+ if (r === void 0 || r.dir)
880
+ throw new Error(
881
+ `no source file found for virtual page spread resourcePath:${t}`
882
+ );
883
+ const n = C.get(e) ?? /* @__PURE__ */ new Map();
884
+ C.has(e) || C.set(e, n);
885
+ const i = n.get(s.originalUri) ?? await Tt(await r.blob());
886
+ return n.set(s.originalUri, i), {
887
+ body: Et({
888
+ cropSide: s.cropSide,
889
+ imageDimensions: i,
890
+ originalUri: s.originalUri
891
+ }),
892
+ params: {
893
+ contentType: ie
894
+ }
895
+ };
896
+ }, Wt = ({ archive: e, resourcePath: t }) => async (s) => {
897
+ const r = await Ct({
898
+ archive: e,
899
+ resourcePath: t
900
+ });
901
+ return r === void 0 ? s : {
902
+ ...s,
903
+ ...r,
904
+ params: {
905
+ ...s.params,
906
+ ...r.params
907
+ }
908
+ };
909
+ }, kt = (e) => {
910
+ const t = e.descendantWithPath("head")?.childrenNamed("meta").find((s) => s.attr.name === "calibre:cover");
649
911
  return !!(t && t.attr.name === "calibre:cover");
650
- }, Qe = (n) => n.descendantWithPath("body")?.descendantWithPath("div")?.childrenNamed("svg")?.find(
912
+ }, Mt = (e) => e.descendantWithPath("body")?.descendantWithPath("div")?.childrenNamed("svg")?.find(
651
913
  (t) => t.attr.width === "100%" && t.attr.preserveAspectRatio === "none"
652
- ), Ze = ({ archive: n, resourcePath: t }) => async (i) => {
653
- const r = Object.values(n.records).find(
654
- (e) => e.uri === t && !e.dir
914
+ ), Ot = ({ archive: e, resourcePath: t }) => async (s) => {
915
+ const r = Object.values(e.records).find(
916
+ (n) => n.uri === t && !n.dir
655
917
  );
656
918
  if (r && !r.dir && r.basename.endsWith(".xhtml")) {
657
- const e = i.body ?? await r.string(), s = new I(e);
658
- if (Ye(s)) {
659
- const o = Qe(s);
919
+ const n = typeof s.body == "string" ? s.body : await r.string(), i = new P(n);
920
+ if (kt(i)) {
921
+ const o = Mt(i);
660
922
  return o && delete o.attr.preserveAspectRatio, {
661
- ...i,
662
- body: s?.toString()
923
+ ...s,
924
+ body: i?.toString()
663
925
  };
664
926
  }
665
927
  }
666
- return i;
667
- }, et = ({ archive: n, resourcePath: t }) => async (i) => Ze({ archive: n, resourcePath: t })(i), tt = ({ archive: n, resourcePath: t }) => async (i) => {
668
- const r = Object.values(n.records).find(
669
- (e) => e.uri === t && !e.dir
928
+ return s;
929
+ }, Nt = ({ archive: e, resourcePath: t }) => async (s) => Ot({ archive: e, resourcePath: t })(s), _t = ({ archive: e, resourcePath: t }) => async (s) => {
930
+ const r = Object.values(e.records).find(
931
+ (n) => n.uri === t && !n.dir
670
932
  );
671
933
  if (r && !r.dir && r.basename.endsWith(".css")) {
672
- const s = (i.body ?? await r.string()).replaceAll(
934
+ const i = (typeof s.body == "string" ? s.body : await r.string()).replaceAll(
673
935
  "-webkit-writing-mode",
674
936
  "writing-mode"
675
937
  );
676
938
  return {
677
- ...i,
678
- body: s
939
+ ...s,
940
+ body: i
679
941
  };
680
942
  }
681
- return i;
682
- }, nt = async (n, t) => {
683
- const i = await K(n);
684
- if (i) {
685
- const { opf: r } = i, e = J(r.manifestItems, n, () => "");
686
- if (e.find(
943
+ return s;
944
+ }, Ut = async (e, t) => {
945
+ const s = await oe(e);
946
+ if (s) {
947
+ const { opf: r } = s, n = ce(r.manifestItems, e, () => "");
948
+ if (n.find(
687
949
  (o) => t.endsWith(o.href)
688
950
  )?.mediaType)
689
951
  return {
690
- mediaType: e.find((o) => t.endsWith(o.href))?.mediaType
952
+ mediaType: n.find((o) => t.endsWith(o.href))?.mediaType
691
953
  };
692
954
  }
693
955
  return {
694
- mediaType: rt(t)
956
+ mediaType: Bt(t)
695
957
  };
696
- }, rt = (n) => {
697
- if (n.endsWith(".css"))
958
+ }, Bt = (e) => {
959
+ if (e.endsWith(".css"))
698
960
  return "text/css; charset=UTF-8";
699
- if (n.endsWith(".jpg"))
961
+ if (e.endsWith(".jpg"))
700
962
  return "image/jpg";
701
- if (n.endsWith(".xhtml"))
963
+ if (e.endsWith(".xhtml"))
702
964
  return "application/xhtml+xml";
703
- if (n.endsWith(".mp4"))
965
+ if (e.endsWith(".mp4"))
704
966
  return "video/mp4";
705
- if (n.endsWith(".svg"))
967
+ if (e.endsWith(".svg"))
706
968
  return "image/svg+xml";
707
- }, st = ({ archive: n, resourcePath: t }) => async (i) => {
708
- const r = Object.values(n.records).find(
709
- (s) => s.uri === t && !s.dir
969
+ }, zt = ({ archive: e, resourcePath: t }) => async (s) => {
970
+ const r = Object.values(e.records).find(
971
+ (i) => i.uri === t && !i.dir
710
972
  );
711
- if (!r || r.dir) return i;
712
- const e = await nt(n, t);
973
+ if (!r || r.dir) return s;
974
+ const n = await Ut(e, t);
713
975
  return {
714
- ...i,
976
+ ...s,
715
977
  params: {
716
- ...i.params,
978
+ ...s.params,
717
979
  ...r?.encodingFormat && {
718
980
  contentType: r.encodingFormat
719
981
  },
720
- ...e.mediaType && {
721
- contentType: e.mediaType
982
+ ...n.mediaType && {
983
+ contentType: n.mediaType
722
984
  }
723
985
  }
724
986
  };
725
- }, D = [
987
+ }, K = [
726
988
  "div",
727
989
  "span",
728
990
  "p",
@@ -773,57 +1035,60 @@ ${o}`), p.groupEnd();
773
1035
  "canvas",
774
1036
  "script",
775
1037
  "style"
776
- ], it = ({ archive: n, resourcePath: t }) => async (i) => {
777
- const r = Object.values(n.records).find(
778
- (e) => e.uri === t && !e.dir
1038
+ ], jt = ({ archive: e, resourcePath: t }) => async (s) => {
1039
+ const r = Object.values(e.records).find(
1040
+ (n) => n.uri === t && !n.dir
779
1041
  );
780
1042
  if (r && !r.dir && r.basename.endsWith(".xhtml")) {
781
- const e = i.body ?? await r.string();
1043
+ const n = typeof s.body == "string" ? s.body : await r.string();
782
1044
  if (!new RegExp(
783
- `<(${D.join("|")})[\\s/>]`,
1045
+ `<(${K.join("|")})[\\s/>]`,
784
1046
  "i"
785
- ).test(e))
786
- return i;
1047
+ ).test(n))
1048
+ return s;
787
1049
  const o = new RegExp(
788
- `<(${D.join("|")})(\\s[^>]*)?\\s*/>`,
1050
+ `<(${K.join("|")})(\\s[^>]*)?\\s*/>`,
789
1051
  "gi"
790
- ), a = e.replace(
1052
+ ), a = n.replace(
791
1053
  o,
792
- (c, l, u = "") => `<${l} ${u.trim()}></${l}>`
1054
+ (c, l, p = "") => `<${l} ${p.trim()}></${l}>`
793
1055
  );
794
1056
  return {
795
- ...i,
1057
+ ...s,
796
1058
  body: a
797
1059
  };
798
1060
  }
799
- return i;
800
- }, ot = async (n, t) => {
801
- const i = Object.values(n.records).find(
802
- (s) => s.uri === t && !s.dir
803
- );
804
- if (!i || i.dir)
805
- throw new Error(`no file found for resourcePath:${t}`);
806
- const r = {
1061
+ return s;
1062
+ }, Dt = async (e, t) => {
1063
+ const s = {
807
1064
  params: {}
808
- }, e = [
809
- st({ archive: n, resourcePath: t }),
810
- it({ archive: n, resourcePath: t }),
811
- tt({ archive: n, resourcePath: t }),
812
- et({ archive: n, resourcePath: t })
1065
+ }, r = [
1066
+ Wt({ archive: e, resourcePath: t }),
1067
+ zt({ archive: e, resourcePath: t }),
1068
+ jt({ archive: e, resourcePath: t }),
1069
+ _t({ archive: e, resourcePath: t }),
1070
+ Nt({ archive: e, resourcePath: t })
813
1071
  ];
814
1072
  try {
815
- const s = await e.reduce(async (o, a) => await a(await o), Promise.resolve(r));
816
- return p.log("Generated resource", t, s), {
817
- ...s,
818
- body: s.body ?? await i.blob()
1073
+ const n = await r.reduce(async (o, a) => await a(await o), Promise.resolve(s));
1074
+ if (u.log("Generated resource", t, n), n.body !== void 0)
1075
+ return n;
1076
+ const i = Object.values(e.records).find(
1077
+ (o) => o.uri === t && !o.dir
1078
+ );
1079
+ if (!i || i.dir)
1080
+ throw new Error(`no file found for resourcePath:${t}`);
1081
+ return {
1082
+ ...n,
1083
+ body: await i.blob()
819
1084
  };
820
- } catch (s) {
821
- throw p.error(s), s;
1085
+ } catch (n) {
1086
+ throw u.error(n), n;
822
1087
  }
823
1088
  };
824
- class at {
1089
+ class Vt {
825
1090
  constructor(t) {
826
- this.cleanArchiveAfter = t, this.state$ = new me({
1091
+ this.cleanArchiveAfter = t, this.state$ = new Pe({
827
1092
  status: "idle",
828
1093
  locks: 0
829
1094
  });
@@ -832,68 +1097,68 @@ class at {
832
1097
  this.state$.next({ ...this.state$.getValue(), ...t });
833
1098
  }
834
1099
  get locks$() {
835
- return this.state$.pipe(F(({ locks: t }) => t));
1100
+ return this.state$.pipe(S(({ locks: t }) => t));
836
1101
  }
837
1102
  get state() {
838
1103
  return this.state$.getValue();
839
1104
  }
840
1105
  get isUnlocked$() {
841
1106
  return this.locks$.pipe(
842
- F((t) => t <= 0),
843
- he(),
844
- ge()
1107
+ S((t) => t <= 0),
1108
+ Ae(),
1109
+ Le()
845
1110
  );
846
1111
  }
847
1112
  get overTTL$() {
848
1113
  return this.isUnlocked$.pipe(
849
1114
  x(
850
- (t) => t ? this.cleanArchiveAfter === 1 / 0 ? B : ye(this.cleanArchiveAfter) : B
1115
+ (t) => t ? this.cleanArchiveAfter === 1 / 0 ? z : Te(this.cleanArchiveAfter) : z
851
1116
  )
852
1117
  );
853
1118
  }
854
1119
  }
855
- const ct = ({
856
- getArchive: n,
1120
+ const Xt = ({
1121
+ getArchive: e,
857
1122
  cleanArchiveAfter: t = 300 * 1e3
858
1123
  // 5mn
859
1124
  }) => {
860
- const i = new R(), r = new R(), e = new R(), s = {}, o = i.pipe(
861
- H((l) => {
862
- const u = s[l];
863
- if (!u || u.state.status !== "idle") return O;
1125
+ const s = new L(), r = new L(), n = new L(), i = {}, o = s.pipe(
1126
+ te((l) => {
1127
+ const p = i[l];
1128
+ if (!p || p.state.status !== "idle") return _;
864
1129
  let f = !1;
865
1130
  const h = (m) => {
866
- p.debug(`Cleaning up archive with key: ${m}`);
867
- const $ = s[m];
868
- delete s[m], f || ($?.state.archive?.close(), f = !0);
1131
+ u.debug(`Cleaning up archive with key: ${m}`);
1132
+ const $ = i[m];
1133
+ delete i[m], f || ($?.state.archive?.close(), f = !0);
869
1134
  };
870
- u.update({
1135
+ p.update({
871
1136
  status: "loading"
872
1137
  });
873
- const g = u.locks$, v = u.isUnlocked$, d = g.pipe(
874
- le(),
875
- C(([m, $]) => $ > m),
876
- ue(!0)
1138
+ const y = p.locks$, b = p.isUnlocked$, d = y.pipe(
1139
+ Re(),
1140
+ T(([m, $]) => $ > m),
1141
+ xe(!0)
877
1142
  );
878
- return A(n(l)).pipe(
1143
+ return R(e(l)).pipe(
879
1144
  E((m) => {
880
- u.update({
1145
+ p.update({
881
1146
  archive: m,
882
1147
  status: "success"
883
1148
  });
884
1149
  }),
885
- k((m) => (h(l), u.update({
1150
+ W((m) => (h(l), p.update({
886
1151
  status: "error",
887
1152
  error: m
888
- }), O)),
1153
+ }), _)),
889
1154
  x(() => {
890
1155
  const m = d.pipe(
891
- x(() => e),
892
- x(() => v),
893
- C((S) => S)
1156
+ x(() => n),
1157
+ x(() => b),
1158
+ T((A) => A)
894
1159
  );
895
- return z(m, u.overTTL$).pipe(
896
- M(),
1160
+ return U(m, p.overTTL$).pipe(
1161
+ B(),
897
1162
  E(() => {
898
1163
  h(l);
899
1164
  })
@@ -901,59 +1166,59 @@ const ct = ({
901
1166
  })
902
1167
  );
903
1168
  }),
904
- pe(r)
1169
+ Fe(r)
905
1170
  ), a = (l) => {
906
- let u = !1;
907
- const f = s[l] ?? new at(t);
908
- s[l] = f, f.update({
1171
+ let p = !1;
1172
+ const f = i[l] ?? new Vt(t);
1173
+ i[l] = f, f.update({
909
1174
  locks: f.state.locks + 1
910
1175
  });
911
1176
  const h = () => {
912
- u || (u = !0, f.update({
1177
+ p || (p = !0, f.update({
913
1178
  locks: f.state.locks - 1
914
1179
  }));
915
1180
  };
916
- i.next(l);
917
- const g = f.state$.pipe(
918
- F(({ archive: d }) => d),
919
- C((d) => !!d)
920
- ), v = f.state$.pipe(
1181
+ s.next(l);
1182
+ const y = f.state$.pipe(
1183
+ S(({ archive: d }) => d),
1184
+ T((d) => !!d)
1185
+ ), b = f.state$.pipe(
921
1186
  E(({ error: d }) => {
922
1187
  if (d)
923
1188
  throw d;
924
1189
  }),
925
- fe()
1190
+ Ie()
926
1191
  );
927
- return z(g, v).pipe(
928
- M(),
929
- F((d) => ({ archive: d, release: h })),
930
- k((d) => {
1192
+ return U(y, b).pipe(
1193
+ B(),
1194
+ S((d) => ({ archive: d, release: h })),
1195
+ W((d) => {
931
1196
  throw h(), d;
932
1197
  })
933
1198
  );
934
1199
  }, c = () => {
935
- e.next();
1200
+ n.next();
936
1201
  };
937
1202
  return o.subscribe(), {
938
1203
  access: a,
939
1204
  purge: c,
940
- _archives: s
1205
+ _archives: i
941
1206
  };
942
- }, _ = (n) => n ? /^\d+$/.test(n) ? {
1207
+ }, J = (e) => e ? /^\d+$/.test(e) ? {
943
1208
  valid: !0,
944
- value: Number.parseInt(n, 10)
1209
+ value: Number.parseInt(e, 10)
945
1210
  } : {
946
1211
  valid: !1,
947
1212
  value: void 0
948
1213
  } : {
949
1214
  valid: !0,
950
1215
  value: void 0
951
- }, dt = (n) => {
952
- if (!n.toLowerCase().startsWith("bytes="))
1216
+ }, Ht = (e) => {
1217
+ if (!e.toLowerCase().startsWith("bytes="))
953
1218
  return {
954
1219
  kind: "missing"
955
1220
  };
956
- const t = n.slice(6).trim();
1221
+ const t = e.slice(6).trim();
957
1222
  if (!t)
958
1223
  return {
959
1224
  kind: "invalid"
@@ -962,62 +1227,62 @@ const ct = ({
962
1227
  return {
963
1228
  kind: "multi"
964
1229
  };
965
- const i = /^(\d*)-(\d*)$/.exec(t);
966
- if (!i)
1230
+ const s = /^(\d*)-(\d*)$/.exec(t);
1231
+ if (!s)
967
1232
  return {
968
1233
  kind: "invalid"
969
1234
  };
970
- const [, r = "", e = ""] = i, s = _(r.trim()), o = _(e.trim());
971
- return !s.valid || !o.valid ? {
1235
+ const [, r = "", n = ""] = s, i = J(r.trim()), o = J(n.trim());
1236
+ return !i.valid || !o.valid ? {
972
1237
  kind: "invalid"
973
1238
  } : {
974
1239
  kind: "single",
975
- start: s.value,
1240
+ start: i.value,
976
1241
  end: o.value
977
1242
  };
978
- }, lt = (n) => {
979
- if (n instanceof Blob)
1243
+ }, Gt = (e) => {
1244
+ if (e instanceof Blob)
980
1245
  return {
981
- size: n.size,
982
- slice: (i, r) => {
983
- const e = n.slice(i, r);
984
- return { content: e, length: e.size };
1246
+ size: e.size,
1247
+ slice: (s, r) => {
1248
+ const n = e.slice(s, r);
1249
+ return { content: n, length: n.size };
985
1250
  }
986
1251
  };
987
- const t = new TextEncoder().encode(n);
1252
+ const t = new TextEncoder().encode(e);
988
1253
  return {
989
1254
  size: t.byteLength,
990
- slice: (i, r) => {
991
- const e = t.slice(i, r);
992
- return { content: e, length: e.byteLength };
1255
+ slice: (s, r) => {
1256
+ const n = t.slice(s, r);
1257
+ return { content: n, length: n.byteLength };
993
1258
  }
994
1259
  };
995
- }, ut = ({
996
- body: n,
1260
+ }, qt = ({
1261
+ body: e,
997
1262
  contentType: t,
998
- rangeHeader: i
1263
+ rangeHeader: s
999
1264
  }) => {
1000
1265
  const r = new Headers();
1001
- if (t && r.set("Content-Type", t), r.set("Accept-Ranges", "bytes"), !i)
1002
- return n instanceof Blob && r.set("Content-Length", String(n.size)), new Response(n, {
1266
+ if (t && r.set("Content-Type", t), r.set("Accept-Ranges", "bytes"), !s)
1267
+ return e instanceof Blob && r.set("Content-Length", String(e.size)), new Response(e, {
1003
1268
  status: 200,
1004
1269
  headers: r
1005
1270
  });
1006
- const e = dt(i);
1007
- if (e.kind === "missing" || e.kind === "multi")
1008
- return n instanceof Blob && r.set("Content-Length", String(n.size)), new Response(n, {
1271
+ const n = Ht(s);
1272
+ if (n.kind === "missing" || n.kind === "multi")
1273
+ return e instanceof Blob && r.set("Content-Length", String(e.size)), new Response(e, {
1009
1274
  status: 200,
1010
1275
  headers: r
1011
1276
  });
1012
- const s = lt(n), o = s.size;
1013
- if (e.kind === "invalid")
1277
+ const i = Gt(e), o = i.size;
1278
+ if (n.kind === "invalid")
1014
1279
  return new Response(null, {
1015
1280
  status: 416,
1016
1281
  headers: {
1017
1282
  "Content-Range": `bytes */${o}`
1018
1283
  }
1019
1284
  });
1020
- let a = e.start, c = e.end;
1285
+ let a = n.start, c = n.end;
1021
1286
  if (a === void 0 && c === void 0)
1022
1287
  return new Response(null, {
1023
1288
  status: 416,
@@ -1026,8 +1291,8 @@ const ct = ({
1026
1291
  }
1027
1292
  });
1028
1293
  if (a === void 0) {
1029
- const u = Math.min(c ?? 0, o);
1030
- a = Math.max(0, o - u), c = o - 1;
1294
+ const p = Math.min(c ?? 0, o);
1295
+ a = Math.max(0, o - p), c = o - 1;
1031
1296
  } else (c === void 0 || c >= o) && (c = o - 1);
1032
1297
  if (a < 0 || c < 0 || a >= o || c >= o || a > c)
1033
1298
  return new Response(null, {
@@ -1036,19 +1301,28 @@ const ct = ({
1036
1301
  "Content-Range": `bytes */${o}`
1037
1302
  }
1038
1303
  });
1039
- const l = s.slice(a, c + 1);
1304
+ const l = i.slice(a, c + 1);
1040
1305
  return r.set("Content-Length", String(l.length)), r.set("Content-Range", `bytes ${a}-${c}/${o}`), new Response(l.content, {
1041
1306
  status: 206,
1042
1307
  headers: r
1043
1308
  });
1309
+ }, Y = "file://", Kt = /^https?:\/\//, Jt = (e) => {
1310
+ try {
1311
+ return decodeURIComponent(e);
1312
+ } catch {
1313
+ return e;
1314
+ }
1315
+ }, Q = (e) => e.startsWith(Y) ? e.slice(Y.length) : e, Yt = (e) => {
1316
+ const t = Q(e);
1317
+ return Kt.test(t) ? t : Q(Jt(t));
1044
1318
  };
1045
- class pt {
1319
+ class Qt {
1046
1320
  constructor({
1047
1321
  onError: t,
1048
- onManifestSuccess: i,
1322
+ onManifestSuccess: s,
1049
1323
  ...r
1050
1324
  }) {
1051
- this.onError = (e) => (console.error(e), new Response(String(e), { status: 500 })), this.archiveLoader = ct(r), this.onManifestSuccess = i ?? (({ manifest: e }) => Promise.resolve(e)), this.onError = t ?? this.onError;
1325
+ this.onError = (n) => (console.error(n), new Response(String(n), { status: 500 })), this.archiveLoader = Xt(r), this.onManifestSuccess = s ?? (({ manifest: n }) => Promise.resolve(n)), this.onError = t ?? this.onError;
1052
1326
  }
1053
1327
  prune() {
1054
1328
  this.archiveLoader.purge();
@@ -1058,36 +1332,36 @@ class pt {
1058
1332
  }
1059
1333
  accessArchiveWithoutLock(t) {
1060
1334
  return this.accessArchive(t).pipe(
1061
- F(({ archive: i, release: r }) => (r(), i))
1335
+ S(({ archive: s, release: r }) => (r(), s))
1062
1336
  );
1063
1337
  }
1064
1338
  withArchiveResponse({
1065
1339
  key: t,
1066
- getResponse: i
1340
+ getResponse: s
1067
1341
  }) {
1068
1342
  const r = this.accessArchive(t).pipe(
1069
- H(
1070
- ({ archive: e, release: s }) => A(i(e)).pipe(
1071
- be(() => {
1072
- s();
1343
+ te(
1344
+ ({ archive: n, release: i }) => R(s(n)).pipe(
1345
+ Ee(() => {
1346
+ i();
1073
1347
  })
1074
1348
  )
1075
1349
  ),
1076
- k((e) => ve(this.onError(e)))
1350
+ W((n) => Ce(this.onError(n)))
1077
1351
  );
1078
- return we(r);
1352
+ return We(r);
1079
1353
  }
1080
- fetchManifest({ key: t, baseUrl: i }) {
1354
+ fetchManifest({ key: t, baseUrl: s }) {
1081
1355
  return this.withArchiveResponse({
1082
1356
  key: t,
1083
- getResponse: (r) => A(
1084
- Je(r, { baseUrl: i })
1357
+ getResponse: (r) => R(
1358
+ Ft(r, { baseUrl: s })
1085
1359
  ).pipe(
1086
1360
  x(
1087
- (s) => A(this.onManifestSuccess({ manifest: s, archive: r }))
1361
+ (i) => R(this.onManifestSuccess({ manifest: i, archive: r }))
1088
1362
  ),
1089
- F(
1090
- (s) => new Response(JSON.stringify(s), {
1363
+ S(
1364
+ (i) => new Response(JSON.stringify(i), {
1091
1365
  status: 200
1092
1366
  })
1093
1367
  )
@@ -1096,18 +1370,18 @@ class pt {
1096
1370
  }
1097
1371
  fetchResource({
1098
1372
  key: t,
1099
- resourcePath: i,
1373
+ resourcePath: s,
1100
1374
  request: r
1101
1375
  }) {
1102
1376
  return this.withArchiveResponse({
1103
1377
  key: t,
1104
- getResponse: (e) => {
1105
- const s = i.replaceAll("file://", "");
1106
- return A(
1107
- ot(e, s)
1378
+ getResponse: (n) => {
1379
+ const i = Yt(s);
1380
+ return R(
1381
+ Dt(n, i)
1108
1382
  ).pipe(
1109
- F(
1110
- (a) => ut({
1383
+ S(
1384
+ (a) => qt({
1111
1385
  body: a.body ?? "",
1112
1386
  contentType: a.params.contentType,
1113
1387
  rangeHeader: r?.headers.get("range")
@@ -1118,51 +1392,51 @@ class pt {
1118
1392
  });
1119
1393
  }
1120
1394
  }
1121
- class At extends pt {
1395
+ class ln extends Qt {
1122
1396
  constructor({
1123
1397
  getUriInfo: t,
1124
- ...i
1398
+ ...s
1125
1399
  }) {
1126
- super(i), this.getUriInfo = t, this.fetchEventListener = this.fetchEventListener.bind(this);
1400
+ super(s), this.getUriInfo = t, this.fetchEventListener = this.fetchEventListener.bind(this);
1127
1401
  }
1128
1402
  fetchEventListener(t) {
1129
1403
  try {
1130
- const i = this.getUriInfo(t);
1131
- if (!i) return;
1132
- const r = j(i.baseUrl), e = t.request.url.substring(
1404
+ const s = this.getUriInfo(t);
1405
+ if (!s) return;
1406
+ const r = j(s.baseUrl), n = t.request.url.substring(
1133
1407
  r.length + 1
1134
- ), [s = ""] = e.split("/"), o = decodeURIComponent(
1135
- j(e.substring(s.length + 1))
1408
+ ), [i = ""] = n.split("/"), o = j(
1409
+ n.substring(i.length + 1)
1136
1410
  );
1137
- e.endsWith("/manifest") ? t.respondWith(
1138
- this.fetchManifest({ key: s, baseUrl: `${r}/${s}/` })
1411
+ n.endsWith("/manifest") ? t.respondWith(
1412
+ this.fetchManifest({ key: i, baseUrl: `${r}/${i}/` })
1139
1413
  ) : t.respondWith(
1140
1414
  this.fetchResource({
1141
- key: s,
1415
+ key: i,
1142
1416
  resourcePath: o,
1143
1417
  request: t.request
1144
1418
  })
1145
1419
  );
1146
- } catch (i) {
1147
- t.respondWith(new Response(String(i), { status: 500 }));
1420
+ } catch (s) {
1421
+ t.respondWith(new Response(String(s), { status: 500 }));
1148
1422
  }
1149
1423
  }
1150
1424
  }
1151
1425
  export {
1152
- At as ServiceWorkerStreamer,
1153
- pt as Streamer,
1154
- Ft as configure,
1155
- yt as createArchiveFromArrayBufferList,
1156
- bt as createArchiveFromJszip,
1157
- vt as createArchiveFromLibArchive,
1158
- wt as createArchiveFromText,
1159
- $t as createArchiveFromUrls,
1160
- Je as generateManifestFromArchive,
1161
- ot as generateResourceFromArchive,
1162
- P as getArchiveOpfInfo,
1163
- $e as getUriBasePath,
1164
- y as getUriBasename,
1426
+ ln as ServiceWorkerStreamer,
1427
+ Qt as Streamer,
1428
+ dn as configure,
1429
+ rn as createArchiveFromArrayBufferList,
1430
+ sn as createArchiveFromJszip,
1431
+ on as createArchiveFromLibArchive,
1432
+ an as createArchiveFromText,
1433
+ cn as createArchiveFromUrls,
1434
+ Ft as generateManifestFromArchive,
1435
+ Dt as generateResourceFromArchive,
1436
+ O as getArchiveOpfInfo,
1437
+ ke as getUriBasePath,
1438
+ v as getUriBasename,
1165
1439
  j as removeTrailingSlash,
1166
- W as sortByTitleComparator
1440
+ M as sortByTitleComparator
1167
1441
  };
1168
1442
  //# sourceMappingURL=index.js.map