@prose-reader/archive-parser 1.303.0 → 1.305.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,351 +1,313 @@
1
- import { XmlDocument as f } from "xmldoc";
2
- const me = "com.apple.ibooks.display-options.xml", Y = (e) => e.childrenNamed("option").map((t) => ({
3
- name: t.attr?.name,
4
- value: t.val
5
- })), pe = (e) => {
6
- const t = new f(e);
7
- if (t.name?.toLowerCase() !== "display_options")
8
- return { kind: "apple" };
9
- const o = t.childNamed("platform");
10
- return {
11
- kind: "apple",
12
- displayOptions: {
13
- ...o !== void 0 ? { platform: { options: Y(o) } } : {}
14
- }
15
- };
16
- }, G = [
17
- "Unknown",
18
- "No",
19
- "Yes",
20
- "YesAndRightToLeft"
21
- ], ve = (e) => {
22
- for (const t of G)
23
- if (t === e) return !0;
24
- return !1;
25
- }, K = "ComicInfo.xml", H = /* @__PURE__ */ new Set(["Pages", "ComicInfo"]), U = (e) => e.children.some((t) => t.type === "element"), z = (e) => {
26
- const t = e.val.trim();
27
- return t.length > 0 ? t : void 0;
28
- }, ge = (e) => {
29
- let t;
30
- try {
31
- t = new f(e);
32
- } catch (o) {
33
- const n = o instanceof Error ? o.message : String(o);
34
- throw new Error(`${K} is malformed: ${n}`, {
35
- cause: o
36
- });
37
- }
38
- const r = {};
39
- return t.eachChild((o) => {
40
- if (o.type !== "element" || H.has(o.name) || U(o)) return;
41
- const n = z(o);
42
- n !== void 0 && r[o.name] === void 0 && (r[o.name] = n);
43
- }), { kind: "comicInfo", ...r };
44
- }, he = "com.kobobooks.display-options.xml", V = (e) => {
45
- const t = e.childNamed("platform");
46
- if (!t) return {};
47
- for (const r of t.childrenNamed("option"))
48
- if (r.attr?.name === "fixed-layout")
49
- return r.val.trim().toLowerCase() === "true" ? { renditionLayout: "pre-paginated" } : {};
50
- return {};
51
- }, ye = (e) => {
52
- const t = new f(e);
53
- return t.name?.toLowerCase() === "display_options" ? { kind: "kobo", ...V(t) } : { kind: "kobo" };
54
- }, M = (e) => e === void 0 || e.trim().length === 0 ? [] : e.trim().split(/\s+/).filter((t) => t.length > 0), $ = (e) => {
55
- const t = M(e);
56
- if (t.length === 0)
57
- return {};
58
- let r;
59
- t.includes("rendition:layout-reflowable") && (r = "reflowable"), t.includes("rendition:layout-pre-paginated") && (r = "pre-paginated");
60
- let o;
61
- return t.includes("rendition:flow-auto") && (o = "auto"), t.includes("rendition:flow-paginated") && (o = "paginated"), t.includes("rendition:flow-scrolled-doc") && (o = "scrolled-doc"), t.includes("rendition:flow-scrolled-continuous") && (o = "scrolled-continuous"), {
62
- ...r !== void 0 ? { renditionLayout: r } : {},
63
- ...o !== void 0 ? { renditionFlow: o } : {},
64
- ...t.includes("page-spread-left") ? { pageSpreadLeft: !0 } : {},
65
- ...t.includes("page-spread-right") ? { pageSpreadRight: !0 } : {}
66
- };
67
- }, a = (e) => e.includes(":") ? e.slice(e.lastIndexOf(":") + 1) : e, A = (e, t) => a(e).toLowerCase() === t.toLowerCase(), k = (e) => e.type === "element", c = (e, t) => {
68
- for (const r of e.children)
69
- if (k(r) && A(r.name, t))
70
- return r;
71
- }, m = (e, t) => {
72
- const r = [];
73
- for (const o of e.children)
74
- k(o) && A(o.name, t) && r.push(o);
75
- return r;
76
- }, W = (e) => {
77
- const t = [];
78
- return e.eachChild((r) => {
79
- if (a(r.name).toLowerCase() !== "identifier") return;
80
- const o = r.val.trim();
81
- if (o.length === 0) return;
82
- const i = (r.attr["opf:scheme"] ?? r.attr["opf:Scheme"] ?? r.attr.scheme)?.trim();
83
- t.push({
84
- value: o,
85
- ...i !== void 0 && i.length > 0 ? { scheme: i } : {}
86
- });
87
- }), t;
88
- }, d = (e, t) => {
89
- let r;
90
- return e.eachChild((o) => {
91
- if (r !== void 0 || a(o.name).toLowerCase() !== t.toLowerCase())
92
- return;
93
- const n = o.val.trim();
94
- n.length > 0 && (r = n);
95
- }), r;
96
- }, g = (e, t) => {
97
- const r = [];
98
- return e.eachChild((o) => {
99
- if (a(o.name).toLowerCase() !== t.toLowerCase())
100
- return;
101
- const n = o.val.trim();
102
- n.length > 0 && r.push(n);
103
- }), r;
104
- }, q = (e) => {
105
- let t;
106
- return e.eachChild((r) => {
107
- if (t !== void 0 || a(r.name).toLowerCase() !== "meta" || r.attr.name?.toLowerCase() !== "cover") return;
108
- const o = r.attr.content?.trim();
109
- o !== void 0 && o.length > 0 && (t = o);
110
- }), t;
111
- }, J = ({
112
- manifestItems: e,
113
- metadataEl: t
114
- }) => {
115
- const r = (n) => n.mediaType?.toLowerCase().includes("image/") === !0, o = e.find((n) => r(n) ? M(n.properties).includes(
116
- "cover-image"
117
- ) : !1);
118
- if (o !== void 0) return o.href;
119
- if (t !== void 0) {
120
- const n = q(t);
121
- if (n !== void 0) {
122
- const i = e.find(
123
- (s) => s.id === n && r(s)
124
- );
125
- if (i !== void 0) return i.href;
126
- }
127
- }
128
- return e.find(
129
- (n) => n.id.toLowerCase().includes("cover") && r(n)
130
- )?.href;
131
- }, h = (e, t) => {
132
- const o = m(e, "meta").find(
133
- (n) => n.attr.property === t
134
- )?.val;
135
- if (!(o === void 0 || o.trim().length === 0))
136
- return o;
137
- }, Q = (e) => {
138
- const t = c(e, "guide");
139
- if (t === void 0) return [];
140
- const r = [];
141
- for (const o of m(t, "reference")) {
142
- const n = o.attr.href?.trim();
143
- n === void 0 || n.length === 0 || r.push({
144
- href: n,
145
- title: o.attr.title?.trim() ?? "",
146
- type: o.attr.type?.trim() ?? ""
147
- });
148
- }
149
- return r;
150
- }, Z = (e) => {
151
- const t = e.attr.id, r = e.attr.href;
152
- if (t === void 0 || t.length === 0 || r === void 0 || r.length === 0) return;
153
- const o = e.attr["media-type"], n = e.attr.properties?.trim();
154
- return {
155
- id: t,
156
- href: r,
157
- ...o !== void 0 && o.length > 0 ? { mediaType: o } : {},
158
- ...n !== void 0 && n.length > 0 ? { properties: n } : {}
159
- };
160
- }, ee = (e) => {
161
- const t = [], r = /* @__PURE__ */ new Map();
162
- for (const o of m(e, "item")) {
163
- const n = Z(o);
164
- n !== void 0 && (t.push(n), r.set(n.id, n));
165
- }
166
- return { items: t, byId: r };
167
- }, te = (e, t) => {
168
- const r = [];
169
- for (const o of m(t, "itemref")) {
170
- const n = o.attr.idref;
171
- if (n === void 0 || n.trim().length === 0) continue;
172
- const i = e.get(n);
173
- if (i === void 0) continue;
174
- const s = $(o.attr.properties);
175
- r.push({
176
- idref: n,
177
- id: i.id,
178
- href: i.href,
179
- ...i.mediaType !== void 0 ? { mediaType: i.mediaType } : {},
180
- ...i.properties !== void 0 ? { properties: i.properties } : {},
181
- ...s.renditionLayout !== void 0 ? { renditionLayout: s.renditionLayout } : {},
182
- ...s.renditionFlow !== void 0 ? { renditionFlow: s.renditionFlow } : {},
183
- ...s.pageSpreadLeft !== void 0 ? { pageSpreadLeft: s.pageSpreadLeft } : {},
184
- ...s.pageSpreadRight !== void 0 ? { pageSpreadRight: s.pageSpreadRight } : {}
185
- });
186
- }
187
- return r;
188
- }, Le = (e) => {
189
- const t = new f(e), r = c(t, "manifest"), o = c(t, "spine"), n = c(t, "metadata");
190
- let i = [], s = [];
191
- if (r !== void 0) {
192
- const { items: B, byId: X } = ee(r);
193
- i = B, o !== void 0 && (s = te(X, o));
194
- }
195
- const p = o?.attr["page-progression-direction"], P = p !== void 0 && p.trim().length > 0 ? p : void 0, v = o?.attr.toc, x = v !== void 0 && v.trim().length > 0 ? v.trim() : void 0;
196
- let I, b, w, C, N = [], S = [], E = [], T, D, O;
197
- const F = [];
198
- n !== void 0 && (I = d(n, "title"), b = d(n, "publisher"), w = d(n, "rights"), C = d(n, "date"), N = g(n, "creator"), S = g(n, "language"), E = g(n, "subject"), T = h(n, "rendition:layout"), D = h(n, "rendition:flow"), O = h(n, "rendition:spread"), F.push(...W(n)));
199
- const R = J({
200
- manifestItems: i,
201
- metadataEl: n
202
- }), j = Q(t);
203
- return {
204
- kind: "opf",
205
- manifestItems: i,
206
- spineRows: s,
207
- spineTocIdref: x,
208
- identifiers: F,
209
- title: I,
210
- creators: N,
211
- publisher: b,
212
- rights: w,
213
- languages: S,
214
- subjects: E,
215
- date: C,
216
- coverHref: R,
217
- renditionLayoutMeta: T,
218
- renditionFlowMeta: D,
219
- renditionSpreadMeta: O,
220
- pageProgressionDirection: P,
221
- guide: j
222
- };
223
- }, oe = (e) => ({
224
- gtin: void 0,
225
- isbn: void 0,
226
- readingDirection: void 0,
227
- renditionLayout: e.displayOptions?.platform?.options?.find(
228
- (o) => o.name === "fixed-layout"
229
- )?.value?.trim().toLowerCase() === "true" ? "pre-paginated" : void 0,
230
- title: void 0,
231
- authors: void 0,
232
- publisher: void 0,
233
- rights: void 0,
234
- languages: void 0,
235
- date: void 0,
236
- subjects: void 0
237
- }), re = /* @__PURE__ */ new Set([8, 12, 13, 14]), _ = (e) => {
238
- if (e == null) return;
239
- const t = String(e).replace(/\D/g, "");
240
- if (!(t.length === 0 || !re.has(t.length)))
241
- return t;
242
- }, ne = /(?:97[89])?\d{9}[\dXx]/, u = (e) => {
243
- if (e == null) return;
244
- const t = String(e).trim().replace(/^urn:isbn:/i, "").replace(/^isbn[:\s-]*/i, ""), r = t.replace(/[^0-9Xx]/g, "");
245
- if (r.length === 10 || r.length === 13)
246
- return r.toUpperCase();
247
- const o = t.match(ne);
248
- if (o) return o[0].toUpperCase();
249
- }, ie = (e) => {
250
- switch (e.Manga) {
251
- case "YesAndRightToLeft":
252
- return "rtl";
253
- case "Yes":
254
- case "No":
255
- return "ltr";
256
- default:
257
- return;
258
- }
259
- }, l = (e) => {
260
- if (e === void 0) return;
261
- const t = e.trim();
262
- return t.length > 0 ? t : void 0;
263
- }, y = (e) => e === void 0 ? [] : e.split(",").map((t) => t.trim()).filter((t) => t.length > 0), L = (e) => {
264
- const t = l(e);
265
- if (t === void 0 || !/^\d+$/.test(t)) return;
266
- const r = Number.parseInt(t, 10);
267
- return Number.isFinite(r) ? r : void 0;
268
- }, se = (e) => {
269
- const t = L(e.Year), r = L(e.Month), o = L(e.Day);
270
- if (!(t === void 0 && r === void 0 && o === void 0))
271
- return {
272
- ...t !== void 0 ? { year: t } : {},
273
- ...r !== void 0 ? { month: r } : {},
274
- ...o !== void 0 ? { day: o } : {}
275
- };
276
- }, ae = (e) => {
277
- const t = e.GTIN, r = l(e.LanguageISO), o = y(e.Writer), n = [...y(e.Genre), ...y(e.Tags)];
278
- return {
279
- gtin: _(t),
280
- isbn: u(t),
281
- readingDirection: ie(e),
282
- renditionLayout: void 0,
283
- title: l(e.Title),
284
- authors: o.length > 0 ? o : void 0,
285
- publisher: l(e.Publisher),
286
- rights: void 0,
287
- languages: r !== void 0 ? [r] : void 0,
288
- date: se(e),
289
- subjects: n.length > 0 ? n : void 0
290
- };
291
- }, de = (e) => ({
292
- gtin: void 0,
293
- isbn: void 0,
294
- readingDirection: void 0,
295
- renditionLayout: e.renditionLayout,
296
- title: void 0,
297
- authors: void 0,
298
- publisher: void 0,
299
- rights: void 0,
300
- languages: void 0,
301
- date: void 0,
302
- subjects: void 0
303
- }), ce = (e) => {
304
- if (e === void 0) return;
305
- const t = e.trim().match(/^(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?/);
306
- if (t === null) return;
307
- const [, r, o, n] = t;
308
- return {
309
- ...r !== void 0 ? { year: Number.parseInt(r, 10) } : {},
310
- ...o !== void 0 ? { month: Number.parseInt(o, 10) } : {},
311
- ...n !== void 0 ? { day: Number.parseInt(n, 10) } : {}
312
- };
313
- }, le = (e) => {
314
- for (const t of e)
315
- if (t.scheme !== void 0 && t.scheme.trim().toLowerCase() === "isbn" && u(t.value) !== void 0)
316
- return t.value;
317
- for (const t of e)
318
- if (u(t.value) !== void 0) return t.value;
319
- }, ue = (e) => {
320
- const t = e.pageProgressionDirection?.trim().toLowerCase(), r = t === "ltr" || t === "rtl" ? t : void 0, o = e.renditionLayoutMeta?.trim().toLowerCase(), n = o === "reflowable" || o === "pre-paginated" ? o : void 0, i = le(e.identifiers);
321
- return {
322
- gtin: _(i),
323
- isbn: u(i),
324
- readingDirection: r,
325
- renditionLayout: n,
326
- title: e.title,
327
- authors: e.creators.length > 0 ? [...e.creators] : void 0,
328
- publisher: e.publisher,
329
- rights: e.rights,
330
- languages: e.languages.length > 0 ? [...e.languages] : void 0,
331
- date: ce(e.date),
332
- subjects: e.subjects.length > 0 ? [...e.subjects] : void 0
333
- };
334
- }, Ie = (e) => e.kind === "comicInfo" ? ae(e) : e.kind === "kobo" ? de(e) : e.kind === "apple" ? oe(e) : ue(e);
335
- export {
336
- me as APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME,
337
- K as COMIC_INFO_FILENAME,
338
- G as COMIC_INFO_MANGA_VALUES,
339
- he as KOBO_DISPLAY_OPTIONS_FILENAME,
340
- ve as isComicInfoManga,
341
- _ as normalizeGtin,
342
- u as normalizeIsbn,
343
- pe as parseAppleDisplayOptionsXml,
344
- ge as parseComicInfo,
345
- ye as parseKoboXml,
346
- Le as parseOpf,
347
- ce as parseW3cDtfDate,
348
- Ie as resolveArchiveMetadata,
349
- M as tokenizeXmlSpaceSeparatedList
350
- };
351
- //# sourceMappingURL=index.js.map
1
+ import { XmlDocument as e } from "xmldoc";
2
+ //#region src/apple/parse.ts
3
+ var t = "com.apple.ibooks.display-options.xml", n = (e) => e.childrenNamed("option").map((e) => ({
4
+ name: e.attr?.name,
5
+ value: e.val
6
+ })), r = (t) => {
7
+ let r = new e(t);
8
+ if (r.name?.toLowerCase() !== "display_options") return { kind: "apple" };
9
+ let i = r.childNamed("platform");
10
+ return {
11
+ kind: "apple",
12
+ displayOptions: { ...i === void 0 ? {} : { platform: { options: n(i) } } }
13
+ };
14
+ }, i = [
15
+ "Unknown",
16
+ "No",
17
+ "Yes",
18
+ "YesAndRightToLeft"
19
+ ], a = (e) => {
20
+ for (let t of i) if (t === e) return !0;
21
+ return !1;
22
+ }, o = "ComicInfo.xml", s = new Set(["Pages", "ComicInfo"]), c = (e) => e.children.some((e) => e.type === "element"), l = (e) => {
23
+ let t = e.val.trim();
24
+ return t.length > 0 ? t : void 0;
25
+ }, u = (t) => {
26
+ let n;
27
+ try {
28
+ n = new e(t);
29
+ } catch (e) {
30
+ let t = e instanceof Error ? e.message : String(e);
31
+ throw Error(`${o} is malformed: ${t}`, { cause: e });
32
+ }
33
+ let r = {};
34
+ return n.eachChild((e) => {
35
+ if (e.type !== "element" || s.has(e.name) || c(e)) return;
36
+ let t = l(e);
37
+ t !== void 0 && r[e.name] === void 0 && (r[e.name] = t);
38
+ }), {
39
+ kind: "comicInfo",
40
+ ...r
41
+ };
42
+ }, d = "com.kobobooks.display-options.xml", f = (e) => {
43
+ let t = e.childNamed("platform");
44
+ if (!t) return {};
45
+ for (let e of t.childrenNamed("option")) if (e.attr?.name === "fixed-layout") return e.val.trim().toLowerCase() === "true" ? { renditionLayout: "pre-paginated" } : {};
46
+ return {};
47
+ }, p = (t) => {
48
+ let n = new e(t);
49
+ return n.name?.toLowerCase() === "display_options" ? {
50
+ kind: "kobo",
51
+ ...f(n)
52
+ } : { kind: "kobo" };
53
+ }, m = (e) => e === void 0 || e.trim().length === 0 ? [] : e.trim().split(/\s+/).filter((e) => e.length > 0), h = (e) => {
54
+ let t = m(e);
55
+ if (t.length === 0) return {};
56
+ let n;
57
+ t.includes("rendition:layout-reflowable") && (n = "reflowable"), t.includes("rendition:layout-pre-paginated") && (n = "pre-paginated");
58
+ let r;
59
+ return t.includes("rendition:flow-auto") && (r = "auto"), t.includes("rendition:flow-paginated") && (r = "paginated"), t.includes("rendition:flow-scrolled-doc") && (r = "scrolled-doc"), t.includes("rendition:flow-scrolled-continuous") && (r = "scrolled-continuous"), {
60
+ ...n === void 0 ? {} : { renditionLayout: n },
61
+ ...r === void 0 ? {} : { renditionFlow: r },
62
+ ...t.includes("page-spread-left") ? { pageSpreadLeft: !0 } : {},
63
+ ...t.includes("page-spread-right") ? { pageSpreadRight: !0 } : {}
64
+ };
65
+ }, g = (e) => e.includes(":") ? e.slice(e.lastIndexOf(":") + 1) : e, _ = (e, t) => g(e).toLowerCase() === t.toLowerCase(), v = (e) => e.type === "element", y = (e, t) => {
66
+ for (let n of e.children) if (v(n) && _(n.name, t)) return n;
67
+ }, b = (e, t) => {
68
+ let n = [];
69
+ for (let r of e.children) v(r) && _(r.name, t) && n.push(r);
70
+ return n;
71
+ }, x = (e) => {
72
+ let t = [];
73
+ return e.eachChild((e) => {
74
+ if (g(e.name).toLowerCase() !== "identifier") return;
75
+ let n = e.val.trim();
76
+ if (n.length === 0) return;
77
+ let r = (e.attr["opf:scheme"] ?? e.attr["opf:Scheme"] ?? e.attr.scheme)?.trim();
78
+ t.push({
79
+ value: n,
80
+ ...r !== void 0 && r.length > 0 ? { scheme: r } : {}
81
+ });
82
+ }), t;
83
+ }, S = (e, t) => {
84
+ let n;
85
+ return e.eachChild((e) => {
86
+ if (n !== void 0 || g(e.name).toLowerCase() !== t.toLowerCase()) return;
87
+ let r = e.val.trim();
88
+ r.length > 0 && (n = r);
89
+ }), n;
90
+ }, C = (e, t) => {
91
+ let n = [];
92
+ return e.eachChild((e) => {
93
+ if (g(e.name).toLowerCase() !== t.toLowerCase()) return;
94
+ let r = e.val.trim();
95
+ r.length > 0 && n.push(r);
96
+ }), n;
97
+ }, w = (e) => {
98
+ let t;
99
+ return e.eachChild((e) => {
100
+ if (t !== void 0 || g(e.name).toLowerCase() !== "meta" || e.attr.name?.toLowerCase() !== "cover") return;
101
+ let n = e.attr.content?.trim();
102
+ n !== void 0 && n.length > 0 && (t = n);
103
+ }), t;
104
+ }, T = ({ manifestItems: e, metadataEl: t }) => {
105
+ let n = (e) => e.mediaType?.toLowerCase().includes("image/") === !0, r = e.find((e) => n(e) ? m(e.properties).includes("cover-image") : !1);
106
+ if (r !== void 0) return r.href;
107
+ if (t !== void 0) {
108
+ let r = w(t);
109
+ if (r !== void 0) {
110
+ let t = e.find((e) => e.id === r && n(e));
111
+ if (t !== void 0) return t.href;
112
+ }
113
+ }
114
+ return e.find((e) => e.id.toLowerCase().includes("cover") && n(e))?.href;
115
+ }, E = (e, t) => {
116
+ let n = b(e, "meta").find((e) => e.attr.property === t)?.val;
117
+ if (!(n === void 0 || n.trim().length === 0)) return n;
118
+ }, D = (e) => {
119
+ let t = y(e, "guide");
120
+ if (t === void 0) return [];
121
+ let n = [];
122
+ for (let e of b(t, "reference")) {
123
+ let t = e.attr.href?.trim();
124
+ t === void 0 || t.length === 0 || n.push({
125
+ href: t,
126
+ title: e.attr.title?.trim() ?? "",
127
+ type: e.attr.type?.trim() ?? ""
128
+ });
129
+ }
130
+ return n;
131
+ }, O = (e) => {
132
+ let t = e.attr.id, n = e.attr.href;
133
+ if (t === void 0 || t.length === 0 || n === void 0 || n.length === 0) return;
134
+ let r = e.attr["media-type"], i = e.attr.properties?.trim();
135
+ return {
136
+ id: t,
137
+ href: n,
138
+ ...r !== void 0 && r.length > 0 ? { mediaType: r } : {},
139
+ ...i !== void 0 && i.length > 0 ? { properties: i } : {}
140
+ };
141
+ }, k = (e) => {
142
+ let t = [], n = /* @__PURE__ */ new Map();
143
+ for (let r of b(e, "item")) {
144
+ let e = O(r);
145
+ e !== void 0 && (t.push(e), n.set(e.id, e));
146
+ }
147
+ return {
148
+ items: t,
149
+ byId: n
150
+ };
151
+ }, A = (e, t) => {
152
+ let n = [];
153
+ for (let r of b(t, "itemref")) {
154
+ let t = r.attr.idref;
155
+ if (t === void 0 || t.trim().length === 0) continue;
156
+ let i = e.get(t);
157
+ if (i === void 0) continue;
158
+ let a = h(r.attr.properties);
159
+ n.push({
160
+ idref: t,
161
+ id: i.id,
162
+ href: i.href,
163
+ ...i.mediaType === void 0 ? {} : { mediaType: i.mediaType },
164
+ ...i.properties === void 0 ? {} : { properties: i.properties },
165
+ ...a.renditionLayout === void 0 ? {} : { renditionLayout: a.renditionLayout },
166
+ ...a.renditionFlow === void 0 ? {} : { renditionFlow: a.renditionFlow },
167
+ ...a.pageSpreadLeft === void 0 ? {} : { pageSpreadLeft: a.pageSpreadLeft },
168
+ ...a.pageSpreadRight === void 0 ? {} : { pageSpreadRight: a.pageSpreadRight }
169
+ });
170
+ }
171
+ return n;
172
+ }, j = (t) => {
173
+ let n = new e(t), r = y(n, "manifest"), i = y(n, "spine"), a = y(n, "metadata"), o = [], s = [];
174
+ if (r !== void 0) {
175
+ let { items: e, byId: t } = k(r);
176
+ o = e, i !== void 0 && (s = A(t, i));
177
+ }
178
+ let c = i?.attr["page-progression-direction"], l = c !== void 0 && c.trim().length > 0 ? c : void 0, u = i?.attr.toc, d = u !== void 0 && u.trim().length > 0 ? u.trim() : void 0, f, p, m, h, g = [], _ = [], v = [], b, w, O, j = [];
179
+ a !== void 0 && (f = S(a, "title"), p = S(a, "publisher"), m = S(a, "rights"), h = S(a, "date"), g = C(a, "creator"), _ = C(a, "language"), v = C(a, "subject"), b = E(a, "rendition:layout"), w = E(a, "rendition:flow"), O = E(a, "rendition:spread"), j.push(...x(a)));
180
+ let M = T({
181
+ manifestItems: o,
182
+ metadataEl: a
183
+ }), N = D(n);
184
+ return {
185
+ kind: "opf",
186
+ manifestItems: o,
187
+ spineRows: s,
188
+ spineTocIdref: d,
189
+ identifiers: j,
190
+ title: f,
191
+ creators: g,
192
+ publisher: p,
193
+ rights: m,
194
+ languages: _,
195
+ subjects: v,
196
+ date: h,
197
+ coverHref: M,
198
+ renditionLayoutMeta: b,
199
+ renditionFlowMeta: w,
200
+ renditionSpreadMeta: O,
201
+ pageProgressionDirection: l,
202
+ guide: N
203
+ };
204
+ }, M = (e) => ({
205
+ gtin: void 0,
206
+ isbn: void 0,
207
+ readingDirection: void 0,
208
+ renditionLayout: (e.displayOptions?.platform?.options?.find((e) => e.name === "fixed-layout")?.value)?.trim().toLowerCase() === "true" ? "pre-paginated" : void 0,
209
+ title: void 0,
210
+ authors: void 0,
211
+ publisher: void 0,
212
+ rights: void 0,
213
+ languages: void 0,
214
+ date: void 0,
215
+ subjects: void 0
216
+ }), N = new Set([
217
+ 8,
218
+ 12,
219
+ 13,
220
+ 14
221
+ ]), P = (e) => {
222
+ if (e == null) return;
223
+ let t = String(e).replace(/\D/g, "");
224
+ if (!(t.length === 0 || !N.has(t.length))) return t;
225
+ }, F = /(?:97[89])?\d{9}[\dXx]/, I = (e) => {
226
+ if (e == null) return;
227
+ let t = String(e).trim().replace(/^urn:isbn:/i, "").replace(/^isbn[:\s-]*/i, ""), n = t.replace(/[^0-9Xx]/g, "");
228
+ if (n.length === 10 || n.length === 13) return n.toUpperCase();
229
+ let r = t.match(F);
230
+ if (r) return r[0].toUpperCase();
231
+ }, L = (e) => {
232
+ switch (e.Manga) {
233
+ case "YesAndRightToLeft": return "rtl";
234
+ case "Yes":
235
+ case "No": return "ltr";
236
+ default: return;
237
+ }
238
+ }, R = (e) => {
239
+ if (e === void 0) return;
240
+ let t = e.trim();
241
+ return t.length > 0 ? t : void 0;
242
+ }, z = (e) => e === void 0 ? [] : e.split(",").map((e) => e.trim()).filter((e) => e.length > 0), B = (e) => {
243
+ let t = R(e);
244
+ if (t === void 0 || !/^\d+$/.test(t)) return;
245
+ let n = Number.parseInt(t, 10);
246
+ return Number.isFinite(n) ? n : void 0;
247
+ }, V = (e) => {
248
+ let t = B(e.Year), n = B(e.Month), r = B(e.Day);
249
+ if (!(t === void 0 && n === void 0 && r === void 0)) return {
250
+ ...t === void 0 ? {} : { year: t },
251
+ ...n === void 0 ? {} : { month: n },
252
+ ...r === void 0 ? {} : { day: r }
253
+ };
254
+ }, H = (e) => {
255
+ let t = e.GTIN, n = R(e.LanguageISO), r = z(e.Writer), i = [...z(e.Genre), ...z(e.Tags)];
256
+ return {
257
+ gtin: P(t),
258
+ isbn: I(t),
259
+ readingDirection: L(e),
260
+ renditionLayout: void 0,
261
+ title: R(e.Title),
262
+ authors: r.length > 0 ? r : void 0,
263
+ publisher: R(e.Publisher),
264
+ rights: void 0,
265
+ languages: n === void 0 ? void 0 : [n],
266
+ date: V(e),
267
+ subjects: i.length > 0 ? i : void 0
268
+ };
269
+ }, U = (e) => ({
270
+ gtin: void 0,
271
+ isbn: void 0,
272
+ readingDirection: void 0,
273
+ renditionLayout: e.renditionLayout,
274
+ title: void 0,
275
+ authors: void 0,
276
+ publisher: void 0,
277
+ rights: void 0,
278
+ languages: void 0,
279
+ date: void 0,
280
+ subjects: void 0
281
+ }), W = (e) => {
282
+ if (e === void 0) return;
283
+ let t = e.trim().match(/^(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?/);
284
+ if (t === null) return;
285
+ let [, n, r, i] = t;
286
+ return {
287
+ ...n === void 0 ? {} : { year: Number.parseInt(n, 10) },
288
+ ...r === void 0 ? {} : { month: Number.parseInt(r, 10) },
289
+ ...i === void 0 ? {} : { day: Number.parseInt(i, 10) }
290
+ };
291
+ }, G = (e) => {
292
+ for (let t of e) if (t.scheme !== void 0 && t.scheme.trim().toLowerCase() === "isbn" && I(t.value) !== void 0) return t.value;
293
+ for (let t of e) if (I(t.value) !== void 0) return t.value;
294
+ }, K = (e) => {
295
+ let t = e.pageProgressionDirection?.trim().toLowerCase(), n = t === "ltr" || t === "rtl" ? t : void 0, r = e.renditionLayoutMeta?.trim().toLowerCase(), i = r === "reflowable" || r === "pre-paginated" ? r : void 0, a = G(e.identifiers);
296
+ return {
297
+ gtin: P(a),
298
+ isbn: I(a),
299
+ readingDirection: n,
300
+ renditionLayout: i,
301
+ title: e.title,
302
+ authors: e.creators.length > 0 ? [...e.creators] : void 0,
303
+ publisher: e.publisher,
304
+ rights: e.rights,
305
+ languages: e.languages.length > 0 ? [...e.languages] : void 0,
306
+ date: W(e.date),
307
+ subjects: e.subjects.length > 0 ? [...e.subjects] : void 0
308
+ };
309
+ }, q = (e) => e.kind === "comicInfo" ? H(e) : e.kind === "kobo" ? U(e) : e.kind === "apple" ? M(e) : K(e);
310
+ //#endregion
311
+ export { t as APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME, o as COMIC_INFO_FILENAME, i as COMIC_INFO_MANGA_VALUES, d as KOBO_DISPLAY_OPTIONS_FILENAME, a as isComicInfoManga, P as normalizeGtin, I as normalizeIsbn, r as parseAppleDisplayOptionsXml, u as parseComicInfo, p as parseKoboXml, j as parseOpf, W as parseW3cDtfDate, q as resolveArchiveMetadata, m as tokenizeXmlSpaceSeparatedList };
312
+
313
+ //# sourceMappingURL=index.js.map