@prose-reader/cbz 1.296.0 → 1.298.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/LICENCE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2021 @prose-reader/core
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1 +1,5 @@
1
- export {};
1
+ import { Reader } from '@prose-reader/core';
2
+ export type CbzEnhancerAPI = {
3
+ __PROSE_READER_ENHANCER_CBZ: true;
4
+ };
5
+ export declare const cbzEnhancer: <InheritOptions, InheritOutput extends Reader>(next: (options: InheritOptions) => InheritOutput) => (options: InheritOptions) => InheritOutput & CbzEnhancerAPI;
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js CHANGED
@@ -1,359 +1,357 @@
1
- import { detectMimeTypeFromName, parseContentType, escapeXmlAttributeValue } from "@prose-reader/shared";
2
- const MAX_DETECTED_PAGE_NUMBER = 2e3;
3
- const numberFromPageLabel = (label) => {
4
- const value = Number.parseInt(label, 10);
5
- if (!Number.isFinite(value)) return void 0;
6
- if (value < 0 || value > MAX_DETECTED_PAGE_NUMBER) return void 0;
7
- return value;
8
- };
9
- const detectPageLabelsFromBasename = (basenameWithoutExtension) => {
10
- const explicitPageRangeMatch = /(?:^|[\s._(-]|\[)p\s*(\d{1,5})\s*[-_]\s*(?:p\s*)?(\d{1,5})(?=$|[^\d])/i.exec(
11
- basenameWithoutExtension
1
+ import { updateEpubCfiSpineItemref as w, getEpubCfiSpineItemref as b } from "@prose-reader/cfi";
2
+ import { detectMimeTypeFromName as c, parseContentType as U, escapeXmlAttributeValue as $ } from "@prose-reader/shared";
3
+ const M = 2e3, m = (e) => {
4
+ const t = Number.parseInt(e, 10);
5
+ if (Number.isFinite(t) && !(t < 0 || t > M))
6
+ return t;
7
+ }, C = (e) => {
8
+ const t = /(?:^|[\s._(-]|\[)p\s*(\d{1,5})\s*[-_]\s*(?:p\s*)?(\d{1,5})(?=$|[^\d])/i.exec(
9
+ e
12
10
  );
13
- if (explicitPageRangeMatch) return explicitPageRangeMatch;
14
- return /(?:^|[\s._(]|\[)(0\d{1,4})\s*[-_]\s*(0\d{1,4})(?=$|[^\d])/i.exec(
15
- basenameWithoutExtension
11
+ return t || /(?:^|[\s._(]|\[)(0\d{1,4})\s*[-_]\s*(0\d{1,4})(?=$|[^\d])/i.exec(
12
+ e
16
13
  );
17
- };
18
- const detectPageSpreadFromBasename = (basename) => {
19
- const basenameWithoutExtension = basename.replace(/\.[^.]+$/, ``);
20
- const match = detectPageLabelsFromBasename(basenameWithoutExtension);
21
- if (!match) return void 0;
22
- const [, firstPageLabel, secondPageLabel] = match;
23
- if (firstPageLabel === void 0 || secondPageLabel === void 0) {
24
- return void 0;
25
- }
26
- const firstPageNumber = numberFromPageLabel(firstPageLabel);
27
- const secondPageNumber = numberFromPageLabel(secondPageLabel);
28
- if (firstPageNumber === void 0 || secondPageNumber === void 0) {
29
- return void 0;
30
- }
31
- if (secondPageNumber !== firstPageNumber + 1) {
32
- return void 0;
33
- }
34
- return {
35
- firstPageLabel,
36
- secondPageLabel
37
- };
38
- };
39
- const PAGE_SPREAD_RESOURCE_PREFIX = `__prose-reader__/page-spread`;
40
- const PAGE_SPREAD_SPLIT_DOCUMENT_MEDIA_TYPE = `application/xhtml+xml`;
41
- const supportedImageMediaTypes = /* @__PURE__ */ new Set([
42
- `image/jpg`,
43
- `image/jpeg`,
44
- `image/png`,
45
- `image/webp`
46
- ]);
47
- const isPageSpreadSplitSupportedImage = (mimeType) => {
48
- if (mimeType === void 0) return false;
49
- return supportedImageMediaTypes.has(mimeType);
50
- };
51
- const encodeOriginalUriSegment = (uri) => encodeURIComponent(uri);
52
- const createManifestResourceHref = ({
53
- baseUrl = ``,
54
- resourcePath
55
- }) => {
56
- if (!baseUrl && /^https?:\/\//.test(resourcePath)) {
57
- return encodeURI(resourcePath);
58
- }
59
- const hrefBaseUrl = baseUrl ? `${baseUrl}${baseUrl.endsWith(`/`) ? `` : `/`}` : `file://`;
60
- return encodeURI(`${hrefBaseUrl}${resourcePath}`);
61
- };
62
- const hasOpfExtension = (path) => path.toLowerCase().endsWith(`.opf`);
63
- const isArchiveEpub = (archive) => archive.records.some(
64
- (file) => !file.dir && (hasOpfExtension(file.basename) || hasOpfExtension(file.uri))
65
- );
66
- const buildVirtualPageSpreadResourcePath = ({
67
- cropSide,
68
- originalUri
14
+ }, A = (e) => {
15
+ const t = e.replace(/\.[^.]+$/, ""), r = C(t);
16
+ if (!r) return;
17
+ const [, i, o] = r;
18
+ if (i === void 0 || o === void 0)
19
+ return;
20
+ const n = m(i), s = m(o);
21
+ if (!(n === void 0 || s === void 0) && s === n + 1)
22
+ return {
23
+ firstPageLabel: i,
24
+ secondPageLabel: o
25
+ };
26
+ }, P = "__prose-reader__/page-spread", x = "application/xhtml+xml", T = /* @__PURE__ */ new Set([
27
+ "image/jpg",
28
+ "image/jpeg",
29
+ "image/png",
30
+ "image/webp"
31
+ ]), S = (e) => e === void 0 ? !1 : T.has(e), F = (e) => encodeURIComponent(e), O = ({
32
+ baseUrl: e = "",
33
+ resourcePath: t
69
34
  }) => {
70
- return `${PAGE_SPREAD_RESOURCE_PREFIX}/${encodeOriginalUriSegment(originalUri)}/${cropSide}.xhtml`;
71
- };
72
- const spreadPropertiesForSide = (side) => side === `left` ? { pageSpreadLeft: true, pageSpreadRight: void 0 } : { pageSpreadLeft: void 0, pageSpreadRight: true };
73
- const cropSidesInReadingOrder = (readingDirection) => readingDirection === `rtl` ? [`right`, `left`] : [`left`, `right`];
74
- const createVirtualSpineItem = ({
75
- baseUrl,
76
- cropSide,
77
- label,
78
- originalSpineItem,
79
- originalUri,
80
- progressionWeight
35
+ if (!e && /^https?:\/\//.test(t))
36
+ return encodeURI(t);
37
+ const r = e ? `${e}${e.endsWith("/") ? "" : "/"}` : "file://";
38
+ return encodeURI(`${r}${t}`);
39
+ }, v = (e) => e.toLowerCase().endsWith(".opf"), L = (e) => e.records.some(
40
+ (t) => !t.dir && (v(t.basename) || v(t.uri))
41
+ ), N = ({
42
+ cropSide: e,
43
+ originalUri: t
44
+ }) => `${P}/${F(t)}/${e}.xhtml`, W = (e) => e === "left" ? { pageSpreadLeft: !0, pageSpreadRight: void 0 } : { pageSpreadLeft: void 0, pageSpreadRight: !0 }, B = (e) => e === "rtl" ? ["right", "left"] : ["left", "right"], R = ({
45
+ baseUrl: e,
46
+ cropSide: t,
47
+ label: r,
48
+ originalSpineItem: i,
49
+ originalUri: o,
50
+ progressionWeight: n
81
51
  }) => {
82
- const resourcePath = buildVirtualPageSpreadResourcePath({
83
- cropSide,
84
- originalUri
52
+ const s = N({
53
+ cropSide: t,
54
+ originalUri: o
85
55
  });
86
56
  return {
87
- ...originalSpineItem,
88
- id: `${originalSpineItem.id}.${label}`,
89
- href: createManifestResourceHref({ baseUrl, resourcePath }),
90
- mediaType: PAGE_SPREAD_SPLIT_DOCUMENT_MEDIA_TYPE,
91
- progressionWeight,
92
- renditionLayout: `pre-paginated`,
93
- ...spreadPropertiesForSide(cropSide)
57
+ ...i,
58
+ id: `${i.id}.${r}`,
59
+ href: O({ baseUrl: e, resourcePath: s }),
60
+ mediaType: x,
61
+ progressionWeight: n,
62
+ renditionLayout: "pre-paginated",
63
+ ...W(t)
94
64
  };
95
- };
96
- const createVirtualManifestItem = ({
97
- href,
98
- id,
99
- mediaType
65
+ }, I = ({
66
+ href: e,
67
+ id: t,
68
+ mediaType: r
100
69
  }) => ({
101
- href,
102
- id,
103
- mediaType
104
- });
105
- const getArchiveRecordForManifestItem = ({
106
- archive,
107
- baseUrl,
108
- spineItem
70
+ href: e,
71
+ id: t,
72
+ mediaType: r
73
+ }), k = ({
74
+ archive: e,
75
+ baseUrl: t,
76
+ spineItem: r
109
77
  }) => {
110
- const hrefCandidates = [spineItem.href, decodeManifestHref(spineItem.href)];
111
- const resourcePathCandidates = new Set(
112
- hrefCandidates.flatMap((href) => getResourcePathCandidates(href, baseUrl))
78
+ const i = [r.href, H(r.href)], o = new Set(
79
+ i.flatMap((n) => D(n, t))
113
80
  );
114
- return archive.records.find(
115
- (item) => !item.dir && resourcePathCandidates.has(item.uri)
81
+ return e.records.find(
82
+ (n) => !n.dir && o.has(n.uri)
116
83
  );
117
- };
118
- const decodeManifestHref = (href) => {
84
+ }, H = (e) => {
119
85
  try {
120
- return decodeURI(href);
86
+ return decodeURI(e);
121
87
  } catch {
122
- return href;
88
+ return e;
123
89
  }
124
- };
125
- const normalizeBaseUrl = (baseUrl) => baseUrl.endsWith(`/`) ? baseUrl : `${baseUrl}/`;
126
- const getResourcePathCandidates = (href, baseUrl) => {
127
- const candidates = [href];
128
- if (href.startsWith(`file://`)) {
129
- candidates.push(href.slice(`file://`.length));
130
- }
131
- if (baseUrl) {
132
- const normalizedBaseUrl = normalizeBaseUrl(baseUrl);
133
- if (href.startsWith(normalizedBaseUrl)) {
134
- candidates.push(href.slice(normalizedBaseUrl.length));
135
- }
90
+ }, V = (e) => e.endsWith("/") ? e : `${e}/`, D = (e, t) => {
91
+ const r = [e];
92
+ if (e.startsWith("file://") && r.push(e.slice(7)), t) {
93
+ const i = V(t);
94
+ e.startsWith(i) && r.push(e.slice(i.length));
136
95
  }
137
- return candidates;
138
- };
139
- const mediaTypeFromArchiveRecord = (record) => parseContentType(record?.encodingFormat ?? ``) || detectMimeTypeFromName(record?.basename ?? ``);
140
- const mediaTypeFromArchiveRecordResourcePath = (record) => detectMimeTypeFromName(record.uri) || detectMimeTypeFromName(record.basename);
141
- const isPageSpreadSplitSupportedArchiveRecord = (record) => {
142
- if (record === void 0 || record.dir) return false;
143
- const resourcePathMediaType = mediaTypeFromArchiveRecordResourcePath(record);
144
- if (!isPageSpreadSplitSupportedImage(resourcePathMediaType)) return false;
145
- return isPageSpreadSplitSupportedImage(mediaTypeFromArchiveRecord(record));
146
- };
147
- const pageSpreadSplit = ({ archive, baseUrl }) => async (manifest) => {
148
- if (isArchiveEpub(archive)) return manifest;
149
- const virtualManifestItems = [];
150
- const spineItems = manifest.spineItems.flatMap((spineItem) => {
151
- const archiveRecord = getArchiveRecordForManifestItem({
152
- archive,
153
- baseUrl,
154
- spineItem
155
- });
156
- if (!isPageSpreadSplitSupportedArchiveRecord(archiveRecord)) {
157
- return [spineItem];
158
- }
159
- const detected = detectPageSpreadFromBasename(archiveRecord.basename);
160
- if (detected === void 0) return [spineItem];
161
- const [firstCropSide, secondCropSide] = cropSidesInReadingOrder(
162
- manifest.readingDirection
163
- );
164
- const splitProgressionWeight = spineItem.progressionWeight !== void 0 ? spineItem.progressionWeight / 2 : void 0;
165
- const firstSpineItem = createVirtualSpineItem({
166
- baseUrl,
167
- cropSide: firstCropSide,
168
- label: detected.firstPageLabel,
169
- originalSpineItem: spineItem,
170
- originalUri: archiveRecord.uri,
171
- progressionWeight: splitProgressionWeight
96
+ return r;
97
+ }, X = (e) => U(e?.encodingFormat ?? "") || c(e?.basename ?? ""), G = (e) => c(e.uri) || c(e.basename), z = (e) => {
98
+ if (e === void 0 || e.dir) return !1;
99
+ const t = G(e);
100
+ return S(t) ? S(X(e)) : !1;
101
+ }, j = ({ archive: e, baseUrl: t }) => async (r) => {
102
+ if (L(e)) return r;
103
+ const i = [], o = r.spineItems.flatMap((n) => {
104
+ const s = k({
105
+ archive: e,
106
+ baseUrl: t,
107
+ spineItem: n
172
108
  });
173
- const secondSpineItem = createVirtualSpineItem({
174
- baseUrl,
175
- cropSide: secondCropSide,
176
- label: detected.secondPageLabel,
177
- originalSpineItem: spineItem,
178
- originalUri: archiveRecord.uri,
179
- progressionWeight: splitProgressionWeight
109
+ if (!z(s))
110
+ return [n];
111
+ const a = A(s.basename);
112
+ if (a === void 0) return [n];
113
+ const [_, y] = B(
114
+ r.readingDirection
115
+ ), l = n.progressionWeight !== void 0 ? n.progressionWeight / 2 : void 0, h = R({
116
+ baseUrl: t,
117
+ cropSide: _,
118
+ label: a.firstPageLabel,
119
+ originalSpineItem: n,
120
+ originalUri: s.uri,
121
+ progressionWeight: l
122
+ }), f = R({
123
+ baseUrl: t,
124
+ cropSide: y,
125
+ label: a.secondPageLabel,
126
+ originalSpineItem: n,
127
+ originalUri: s.uri,
128
+ progressionWeight: l
180
129
  });
181
- virtualManifestItems.push(
182
- createVirtualManifestItem(firstSpineItem),
183
- createVirtualManifestItem(secondSpineItem)
184
- );
185
- return [firstSpineItem, secondSpineItem];
130
+ return i.push(
131
+ I(h),
132
+ I(f)
133
+ ), [h, f];
186
134
  });
187
- if (virtualManifestItems.length === 0) return manifest;
188
- return {
189
- ...manifest,
190
- spineItems: spineItems.map((spineItem, index) => ({
191
- ...spineItem,
192
- index
135
+ return i.length === 0 ? r : {
136
+ ...r,
137
+ spineItems: o.map((n, s) => ({
138
+ ...n,
139
+ index: s
193
140
  })),
194
- items: [...manifest.items, ...virtualManifestItems]
141
+ items: [...r.items, ...i]
195
142
  };
196
- };
197
- const imageDimensionsCache = /* @__PURE__ */ new WeakMap();
198
- const decodeOriginalUriSegment = (encoded) => {
143
+ }, d = /* @__PURE__ */ new WeakMap(), q = (e) => {
199
144
  try {
200
- return decodeURIComponent(encoded);
145
+ return decodeURIComponent(e);
201
146
  } catch {
202
- return void 0;
203
- }
204
- };
205
- const parseVirtualPageSpreadResourcePath = (resourcePath) => {
206
- const prefixIndex = resourcePath.indexOf(`${PAGE_SPREAD_RESOURCE_PREFIX}/`);
207
- if (prefixIndex < 0) return void 0;
208
- const virtualPath = resourcePath.slice(prefixIndex);
209
- const parts = virtualPath.split(`/`);
210
- const encodedOriginalUri = parts[2];
211
- const cropFileName = parts[3];
212
- if (parts.length !== 4 || parts[0] !== `__prose-reader__` || parts[1] !== `page-spread` || encodedOriginalUri === void 0 || cropFileName === void 0) {
213
- return void 0;
147
+ return;
214
148
  }
215
- const cropSide = cropFileName.split(`.`)[0];
216
- if (cropSide !== `left` && cropSide !== `right`) return void 0;
217
- const originalUri = decodeOriginalUriSegment(encodedOriginalUri);
218
- if (originalUri === void 0) return void 0;
219
- return {
220
- originalUri,
221
- cropSide
222
- };
223
- };
224
- const cropRectForSide = ({
225
- cropSide,
226
- imageHeight,
227
- imageWidth
149
+ }, p = (e) => {
150
+ const t = e.indexOf(`${P}/`);
151
+ if (t < 0) return;
152
+ const i = e.slice(t).split("/"), o = i[2], n = i[3];
153
+ if (i.length !== 4 || i[0] !== "__prose-reader__" || i[1] !== "page-spread" || o === void 0 || n === void 0)
154
+ return;
155
+ const s = n.split(".")[0];
156
+ if (s !== "left" && s !== "right") return;
157
+ const a = q(o);
158
+ if (a !== void 0)
159
+ return {
160
+ originalUri: a,
161
+ cropSide: s
162
+ };
163
+ }, Y = ({
164
+ cropSide: e,
165
+ imageHeight: t,
166
+ imageWidth: r
228
167
  }) => {
229
- const leftWidth = Math.floor(imageWidth / 2);
230
- const rightWidth = imageWidth - leftWidth;
231
- return cropSide === `left` ? { x: 0, width: leftWidth, height: imageHeight } : { x: leftWidth, width: rightWidth, height: imageHeight };
232
- };
233
- const getRelativeOriginalImageSrc = (originalUri) => {
234
- if (/^https?:\/\//.test(originalUri)) return originalUri;
235
- return `../../../${encodeURI(originalUri)}`;
236
- };
237
- const readImageDimensions = async (source) => {
238
- if (typeof createImageBitmap !== `function`) {
239
- throw new Error(`Page spread XHTML generation requires createImageBitmap`);
240
- }
241
- const bitmap = await createImageBitmap(source);
168
+ const i = Math.floor(r / 2), o = r - i;
169
+ return e === "left" ? { x: 0, width: i, height: t } : { x: i, width: o, height: t };
170
+ }, Z = (e) => /^https?:\/\//.test(e) ? e : `../../../${encodeURI(e)}`, J = async (e) => {
171
+ if (typeof createImageBitmap != "function")
172
+ throw new Error("Page spread XHTML generation requires createImageBitmap");
173
+ const t = await createImageBitmap(e);
242
174
  try {
243
175
  return {
244
- height: bitmap.height,
245
- width: bitmap.width
176
+ height: t.height,
177
+ width: t.width
246
178
  };
247
179
  } finally {
248
- bitmap.close();
180
+ t.close();
249
181
  }
250
- };
251
- const createPageSpreadSplitXhtml = ({
252
- cropSide,
253
- imageDimensions,
254
- originalUri
182
+ }, K = ({
183
+ cropSide: e,
184
+ imageDimensions: t,
185
+ originalUri: r
255
186
  }) => {
256
- if (imageDimensions.width < 2) {
257
- throw new Error(`Page spread image is too narrow to split`);
258
- }
259
- const crop = cropRectForSide({
260
- cropSide,
261
- imageHeight: imageDimensions.height,
262
- imageWidth: imageDimensions.width
187
+ if (t.width < 2)
188
+ throw new Error("Page spread image is too narrow to split");
189
+ const i = Y({
190
+ cropSide: e,
191
+ imageHeight: t.height,
192
+ imageWidth: t.width
263
193
  });
264
194
  return `<?xml version="1.0" encoding="UTF-8"?>
265
195
  <html xmlns="http://www.w3.org/1999/xhtml">
266
196
  <head>
267
- <meta name="viewport" content="width=${crop.width}, height=${crop.height}" />
197
+ <meta name="viewport" content="width=${i.width}, height=${i.height}" />
268
198
  <style>
269
199
  html,
270
200
  body {
271
- width: ${crop.width}px;
272
- height: ${crop.height}px;
201
+ width: ${i.width}px;
202
+ height: ${i.height}px;
273
203
  margin: 0;
274
204
  overflow: hidden;
275
205
  }
276
206
 
277
207
  img {
278
208
  display: block;
279
- width: ${imageDimensions.width}px;
280
- height: ${imageDimensions.height}px;
209
+ width: ${t.width}px;
210
+ height: ${t.height}px;
281
211
  max-width: none;
282
- transform: translateX(-${crop.x}px);
212
+ transform: translateX(-${i.x}px);
283
213
  user-select: none;
284
214
  -webkit-user-drag: none;
285
215
  }
286
216
  </style>
287
217
  </head>
288
218
  <body>
289
- <img src="${escapeXmlAttributeValue(getRelativeOriginalImageSrc(originalUri))}" alt="" />
219
+ <img src="${$(Z(r))}" alt="" />
290
220
  </body>
291
221
  </html>`;
292
- };
293
- const generatePageSpreadSplitResource = async ({
294
- archive,
295
- resourcePath
222
+ }, Q = async ({
223
+ archive: e,
224
+ resourcePath: t
296
225
  }) => {
297
- const virtualResource = parseVirtualPageSpreadResourcePath(resourcePath);
298
- if (virtualResource === void 0) return void 0;
299
- const file = archive.records.find(
300
- (file2) => file2.uri === virtualResource.originalUri && !file2.dir
226
+ const r = p(t);
227
+ if (r === void 0) return;
228
+ const i = e.records.find(
229
+ (a) => a.uri === r.originalUri && !a.dir
301
230
  );
302
- if (file === void 0 || file.dir) {
231
+ if (i === void 0 || i.dir)
303
232
  throw new Error(
304
- `no source file found for virtual page spread resourcePath:${resourcePath}`
233
+ `no source file found for virtual page spread resourcePath:${t}`
305
234
  );
306
- }
307
- const archiveCache = imageDimensionsCache.get(archive) ?? /* @__PURE__ */ new Map();
308
- if (!imageDimensionsCache.has(archive)) {
309
- imageDimensionsCache.set(archive, archiveCache);
310
- }
311
- const imageDimensions = archiveCache.get(virtualResource.originalUri) ?? await readImageDimensions(await file.blob());
312
- archiveCache.set(virtualResource.originalUri, imageDimensions);
313
- const body = createPageSpreadSplitXhtml({
314
- cropSide: virtualResource.cropSide,
315
- imageDimensions,
316
- originalUri: virtualResource.originalUri
317
- });
318
- return {
319
- body,
235
+ const o = d.get(e) ?? /* @__PURE__ */ new Map();
236
+ d.has(e) || d.set(e, o);
237
+ const n = o.get(r.originalUri) ?? await J(await i.blob());
238
+ return o.set(r.originalUri, n), {
239
+ body: K({
240
+ cropSide: r.cropSide,
241
+ imageDimensions: n,
242
+ originalUri: r.originalUri
243
+ }),
320
244
  params: {
321
- contentType: PAGE_SPREAD_SPLIT_DOCUMENT_MEDIA_TYPE
245
+ contentType: x
322
246
  }
323
247
  };
324
- };
325
- const pageSpreadSplitResourceHook = ({ archive, resourcePath }) => async (resource) => {
326
- const pageSpreadResource = await generatePageSpreadSplitResource({
327
- archive,
328
- resourcePath
248
+ }, ee = ({ archive: e, resourcePath: t }) => async (r) => {
249
+ const i = await Q({
250
+ archive: e,
251
+ resourcePath: t
329
252
  });
330
- if (pageSpreadResource === void 0) return resource;
331
- return {
332
- ...resource,
333
- ...pageSpreadResource,
253
+ return i === void 0 ? r : {
254
+ ...r,
255
+ ...i,
334
256
  params: {
335
- ...resource.params,
336
- ...pageSpreadResource.params
257
+ ...r.params,
258
+ ...i.params
337
259
  }
338
260
  };
339
- };
340
- const streamerHooks = {
261
+ }, g = "vnd.prose-reader.cbz.virtual-spine-id", E = (e) => {
262
+ try {
263
+ return decodeURIComponent(e);
264
+ } catch {
265
+ return e;
266
+ }
267
+ }, te = (e) => {
268
+ try {
269
+ return decodeURI(e);
270
+ } catch {
271
+ return e;
272
+ }
273
+ }, u = (e) => {
274
+ const t = p(e) ?? p(te(e));
275
+ if (t)
276
+ return {
277
+ ...t,
278
+ originalUri: E(t.originalUri)
279
+ };
280
+ }, re = (e, t) => {
281
+ const r = /* @__PURE__ */ new Set();
282
+ let i = 0;
283
+ for (const o of e.spineItemsManager.items) {
284
+ const n = u(o.item.href);
285
+ if (!n) {
286
+ i++;
287
+ continue;
288
+ }
289
+ if (n.originalUri === t)
290
+ return i;
291
+ r.has(n.originalUri) || (r.add(n.originalUri), i++);
292
+ }
293
+ }, ie = (e, t, r) => {
294
+ const i = u(r.href);
295
+ if (!i) return;
296
+ const o = re(
297
+ e,
298
+ i.originalUri
299
+ );
300
+ if (o !== void 0)
301
+ return w(t, {
302
+ extensions: {
303
+ [g]: encodeURIComponent(r.id)
304
+ },
305
+ spineId: i.originalUri,
306
+ spineIndex: o
307
+ });
308
+ }, ne = (e, t) => {
309
+ const r = b(t)?.extensions?.[g];
310
+ if (!r) return;
311
+ const i = e.spineItemsManager.get(
312
+ E(r)
313
+ );
314
+ if (!(!i || !u(i.item.href)))
315
+ return w(t, {
316
+ extensions: {
317
+ [g]: void 0
318
+ },
319
+ spineId: i.item.id,
320
+ spineIndex: i.item.index
321
+ });
322
+ }, ae = (e) => (t) => {
323
+ const r = e(t), i = r.hookManager.register(
324
+ "cfi.afterGenerate",
325
+ ({ cfi: s, spineItem: a }) => ie(r, s, a)
326
+ ), o = r.hookManager.register(
327
+ "cfi.beforeResolve",
328
+ ({ cfi: s }) => ne(r, s)
329
+ );
330
+ return {
331
+ ...r,
332
+ __PROSE_READER_ENHANCER_CBZ: !0,
333
+ destroy: () => {
334
+ i(), o(), r.destroy();
335
+ }
336
+ };
337
+ }, de = {
341
338
  manifest: {
342
- spine: [pageSpreadSplit]
339
+ spine: [j]
343
340
  },
344
- resource: [pageSpreadSplitResourceHook]
341
+ resource: [ee]
345
342
  };
346
343
  export {
347
- PAGE_SPREAD_RESOURCE_PREFIX,
348
- PAGE_SPREAD_SPLIT_DOCUMENT_MEDIA_TYPE,
349
- buildVirtualPageSpreadResourcePath,
350
- createPageSpreadSplitXhtml,
351
- detectPageSpreadFromBasename,
352
- isPageSpreadSplitSupportedArchiveRecord,
353
- isPageSpreadSplitSupportedImage,
354
- pageSpreadSplit,
355
- pageSpreadSplitResourceHook,
356
- parseVirtualPageSpreadResourcePath,
357
- streamerHooks
344
+ P as PAGE_SPREAD_RESOURCE_PREFIX,
345
+ x as PAGE_SPREAD_SPLIT_DOCUMENT_MEDIA_TYPE,
346
+ N as buildVirtualPageSpreadResourcePath,
347
+ ae as cbzEnhancer,
348
+ K as createPageSpreadSplitXhtml,
349
+ A as detectPageSpreadFromBasename,
350
+ z as isPageSpreadSplitSupportedArchiveRecord,
351
+ S as isPageSpreadSplitSupportedImage,
352
+ j as pageSpreadSplit,
353
+ ee as pageSpreadSplitResourceHook,
354
+ p as parseVirtualPageSpreadResourcePath,
355
+ de as streamerHooks
358
356
  };
359
357
  //# sourceMappingURL=index.js.map