@prose-reader/archive-parser 1.287.0 → 1.290.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 +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +269 -164
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +1 -1
- package/dist/index.umd.cjs.map +1 -1
- package/dist/opf/parse.d.ts +25 -0
- package/dist/types/archiveResolve.d.ts +54 -1
- package/dist/utils/parseW3cDtfDate.d.ts +20 -0
- package/dist/utils/parseW3cDtfDate.test.d.ts +1 -0
- package/package.json +3 -2
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.
|
package/dist/index.d.ts
CHANGED
|
@@ -18,4 +18,5 @@ export { resolveArchiveMetadata } from './resolve';
|
|
|
18
18
|
export type { ArchiveResolveResult } from './types/archiveResolve';
|
|
19
19
|
export { normalizeGtin } from './utils/normalizeGtin';
|
|
20
20
|
export { normalizeIsbn } from './utils/normalizeIsbn';
|
|
21
|
+
export { parseW3cDtfDate } from './utils/parseW3cDtfDate';
|
|
21
22
|
export { tokenizeXmlSpaceSeparatedList } from './utils/tokenizeXmlSpaceSeparatedList';
|
package/dist/index.js
CHANGED
|
@@ -1,140 +1,176 @@
|
|
|
1
|
-
import { XmlDocument as
|
|
2
|
-
const
|
|
3
|
-
name:
|
|
4
|
-
value:
|
|
5
|
-
})),
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
1
|
+
import { XmlDocument as m } from "xmldoc";
|
|
2
|
+
const fe = "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 m(e);
|
|
7
|
+
if (t.name?.toLowerCase() !== "display_options")
|
|
8
8
|
return { kind: "apple" };
|
|
9
|
-
const
|
|
9
|
+
const r = t.childNamed("platform");
|
|
10
10
|
return {
|
|
11
11
|
kind: "apple",
|
|
12
12
|
displayOptions: {
|
|
13
|
-
...
|
|
13
|
+
...r !== void 0 ? { platform: { options: Y(r) } } : {}
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
},
|
|
16
|
+
}, G = [
|
|
17
17
|
"Unknown",
|
|
18
18
|
"No",
|
|
19
19
|
"Yes",
|
|
20
20
|
"YesAndRightToLeft"
|
|
21
|
-
],
|
|
22
|
-
for (const
|
|
23
|
-
if (
|
|
21
|
+
], ve = (e) => {
|
|
22
|
+
for (const t of G)
|
|
23
|
+
if (t === e) return !0;
|
|
24
24
|
return !1;
|
|
25
|
-
},
|
|
26
|
-
const
|
|
27
|
-
return
|
|
28
|
-
},
|
|
29
|
-
let
|
|
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
30
|
try {
|
|
31
|
-
|
|
32
|
-
} catch (
|
|
33
|
-
const
|
|
34
|
-
throw new Error(`${
|
|
35
|
-
cause:
|
|
31
|
+
t = new m(e);
|
|
32
|
+
} catch (r) {
|
|
33
|
+
const n = r instanceof Error ? r.message : String(r);
|
|
34
|
+
throw new Error(`${K} is malformed: ${n}`, {
|
|
35
|
+
cause: r
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
const o = {};
|
|
39
|
-
return
|
|
40
|
-
if (
|
|
41
|
-
const
|
|
42
|
-
|
|
39
|
+
return t.eachChild((r) => {
|
|
40
|
+
if (r.type !== "element" || H.has(r.name) || U(r)) return;
|
|
41
|
+
const n = z(r);
|
|
42
|
+
n !== void 0 && o[r.name] === void 0 && (o[r.name] = n);
|
|
43
43
|
}), { kind: "comicInfo", ...o };
|
|
44
|
-
},
|
|
45
|
-
const
|
|
46
|
-
if (!
|
|
47
|
-
for (const o of
|
|
44
|
+
}, he = "com.kobobooks.display-options.xml", V = (e) => {
|
|
45
|
+
const t = e.childNamed("platform");
|
|
46
|
+
if (!t) return {};
|
|
47
|
+
for (const o of t.childrenNamed("option"))
|
|
48
48
|
if (o.attr?.name === "fixed-layout")
|
|
49
49
|
return o.val.trim().toLowerCase() === "true" ? { renditionLayout: "pre-paginated" } : {};
|
|
50
50
|
return {};
|
|
51
|
-
},
|
|
52
|
-
const
|
|
53
|
-
return
|
|
54
|
-
},
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
51
|
+
}, ye = (e) => {
|
|
52
|
+
const t = new m(e);
|
|
53
|
+
return t.name?.toLowerCase() === "display_options" ? { kind: "kobo", ...V(t) } : { kind: "kobo" };
|
|
54
|
+
}, A = (e) => e === void 0 || e.trim().length === 0 ? [] : e.trim().split(/\s+/).filter((t) => t.length > 0), $ = (e) => {
|
|
55
|
+
const t = A(e);
|
|
56
|
+
if (t.length === 0)
|
|
57
57
|
return {};
|
|
58
58
|
let o;
|
|
59
|
-
return
|
|
59
|
+
return t.includes("rendition:layout-reflowable") && (o = "reflowable"), t.includes("rendition:layout-pre-paginated") && (o = "pre-paginated"), {
|
|
60
60
|
...o !== void 0 ? { renditionLayout: o } : {},
|
|
61
|
-
...
|
|
62
|
-
...
|
|
61
|
+
...t.includes("page-spread-left") ? { pageSpreadLeft: !0 } : {},
|
|
62
|
+
...t.includes("page-spread-right") ? { pageSpreadRight: !0 } : {}
|
|
63
63
|
};
|
|
64
|
-
},
|
|
65
|
-
for (const o of
|
|
66
|
-
if (
|
|
64
|
+
}, a = (e) => e.includes(":") ? e.slice(e.lastIndexOf(":") + 1) : e, k = (e, t) => a(e).toLowerCase() === t.toLowerCase(), _ = (e) => e.type === "element", c = (e, t) => {
|
|
65
|
+
for (const o of e.children)
|
|
66
|
+
if (_(o) && k(o.name, t))
|
|
67
67
|
return o;
|
|
68
|
-
},
|
|
68
|
+
}, f = (e, t) => {
|
|
69
69
|
const o = [];
|
|
70
|
-
for (const
|
|
71
|
-
|
|
70
|
+
for (const r of e.children)
|
|
71
|
+
_(r) && k(r.name, t) && o.push(r);
|
|
72
72
|
return o;
|
|
73
|
-
},
|
|
74
|
-
const
|
|
75
|
-
return
|
|
76
|
-
if (
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
73
|
+
}, W = (e) => {
|
|
74
|
+
const t = [];
|
|
75
|
+
return e.eachChild((o) => {
|
|
76
|
+
if (a(o.name).toLowerCase() !== "identifier") return;
|
|
77
|
+
const r = o.val.trim();
|
|
78
|
+
if (r.length === 0) return;
|
|
79
79
|
const i = (o.attr["opf:scheme"] ?? o.attr["opf:Scheme"] ?? o.attr.scheme)?.trim();
|
|
80
|
-
|
|
81
|
-
value:
|
|
80
|
+
t.push({
|
|
81
|
+
value: r,
|
|
82
82
|
...i !== void 0 && i.length > 0 ? { scheme: i } : {}
|
|
83
83
|
});
|
|
84
|
-
}),
|
|
85
|
-
},
|
|
86
|
-
let
|
|
87
|
-
return
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
n
|
|
91
|
-
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
}), t;
|
|
85
|
+
}, d = (e, t) => {
|
|
86
|
+
let o;
|
|
87
|
+
return e.eachChild((r) => {
|
|
88
|
+
if (o !== void 0 || a(r.name).toLowerCase() !== t.toLowerCase())
|
|
89
|
+
return;
|
|
90
|
+
const n = r.val.trim();
|
|
91
|
+
n.length > 0 && (o = n);
|
|
92
|
+
}), o;
|
|
93
|
+
}, g = (e, t) => {
|
|
94
|
+
const o = [];
|
|
95
|
+
return e.eachChild((r) => {
|
|
96
|
+
if (a(r.name).toLowerCase() !== t.toLowerCase())
|
|
97
|
+
return;
|
|
98
|
+
const n = r.val.trim();
|
|
99
|
+
n.length > 0 && o.push(n);
|
|
100
|
+
}), o;
|
|
101
|
+
}, q = (e) => {
|
|
102
|
+
let t;
|
|
103
|
+
return e.eachChild((o) => {
|
|
104
|
+
if (t !== void 0 || a(o.name).toLowerCase() !== "meta" || o.attr.name?.toLowerCase() !== "cover") return;
|
|
105
|
+
const r = o.attr.content?.trim();
|
|
106
|
+
r !== void 0 && r.length > 0 && (t = r);
|
|
107
|
+
}), t;
|
|
108
|
+
}, J = ({
|
|
109
|
+
manifestItems: e,
|
|
110
|
+
metadataEl: t
|
|
111
|
+
}) => {
|
|
112
|
+
const o = (n) => n.mediaType?.toLowerCase().includes("image/") === !0, r = e.find((n) => o(n) ? A(n.properties).includes(
|
|
113
|
+
"cover-image"
|
|
114
|
+
) : !1);
|
|
115
|
+
if (r !== void 0) return r.href;
|
|
116
|
+
if (t !== void 0) {
|
|
117
|
+
const n = q(t);
|
|
118
|
+
if (n !== void 0) {
|
|
119
|
+
const i = e.find(
|
|
120
|
+
(s) => s.id === n && o(s)
|
|
121
|
+
);
|
|
122
|
+
if (i !== void 0) return i.href;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return e.find(
|
|
126
|
+
(n) => n.id.toLowerCase().includes("cover") && o(n)
|
|
127
|
+
)?.href;
|
|
128
|
+
}, h = (e, t) => {
|
|
129
|
+
const r = f(e, "meta").find(
|
|
130
|
+
(n) => n.attr.property === t
|
|
95
131
|
)?.val;
|
|
96
|
-
if (!(
|
|
97
|
-
return
|
|
98
|
-
},
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
132
|
+
if (!(r === void 0 || r.trim().length === 0))
|
|
133
|
+
return r;
|
|
134
|
+
}, Q = (e) => {
|
|
135
|
+
const t = c(e, "guide");
|
|
136
|
+
if (t === void 0) return [];
|
|
101
137
|
const o = [];
|
|
102
|
-
for (const
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
href:
|
|
106
|
-
title:
|
|
107
|
-
type:
|
|
138
|
+
for (const r of f(t, "reference")) {
|
|
139
|
+
const n = r.attr.href?.trim();
|
|
140
|
+
n === void 0 || n.length === 0 || o.push({
|
|
141
|
+
href: n,
|
|
142
|
+
title: r.attr.title?.trim() ?? "",
|
|
143
|
+
type: r.attr.type?.trim() ?? ""
|
|
108
144
|
});
|
|
109
145
|
}
|
|
110
146
|
return o;
|
|
111
|
-
},
|
|
112
|
-
const
|
|
113
|
-
if (
|
|
114
|
-
const
|
|
147
|
+
}, Z = (e) => {
|
|
148
|
+
const t = e.attr.id, o = e.attr.href;
|
|
149
|
+
if (t === void 0 || t.length === 0 || o === void 0 || o.length === 0) return;
|
|
150
|
+
const r = e.attr["media-type"], n = e.attr.properties?.trim();
|
|
115
151
|
return {
|
|
116
|
-
id:
|
|
152
|
+
id: t,
|
|
117
153
|
href: o,
|
|
118
|
-
...
|
|
119
|
-
...
|
|
154
|
+
...r !== void 0 && r.length > 0 ? { mediaType: r } : {},
|
|
155
|
+
...n !== void 0 && n.length > 0 ? { properties: n } : {}
|
|
120
156
|
};
|
|
121
|
-
},
|
|
122
|
-
const
|
|
123
|
-
for (const
|
|
124
|
-
const
|
|
125
|
-
|
|
157
|
+
}, ee = (e) => {
|
|
158
|
+
const t = [], o = /* @__PURE__ */ new Map();
|
|
159
|
+
for (const r of f(e, "item")) {
|
|
160
|
+
const n = Z(r);
|
|
161
|
+
n !== void 0 && (t.push(n), o.set(n.id, n));
|
|
126
162
|
}
|
|
127
|
-
return { items:
|
|
128
|
-
},
|
|
163
|
+
return { items: t, byId: o };
|
|
164
|
+
}, te = (e, t) => {
|
|
129
165
|
const o = [];
|
|
130
|
-
for (const
|
|
131
|
-
const
|
|
132
|
-
if (
|
|
133
|
-
const i =
|
|
166
|
+
for (const r of f(t, "itemref")) {
|
|
167
|
+
const n = r.attr.idref;
|
|
168
|
+
if (n === void 0 || n.trim().length === 0) continue;
|
|
169
|
+
const i = e.get(n);
|
|
134
170
|
if (i === void 0) continue;
|
|
135
|
-
const s =
|
|
171
|
+
const s = $(r.attr.properties);
|
|
136
172
|
o.push({
|
|
137
|
-
idref:
|
|
173
|
+
idref: n,
|
|
138
174
|
id: i.id,
|
|
139
175
|
href: i.href,
|
|
140
176
|
...i.mediaType !== void 0 ? { mediaType: i.mediaType } : {},
|
|
@@ -145,88 +181,157 @@ const W = "com.apple.ibooks.display-options.xml", k = (t) => t.childrenNamed("op
|
|
|
145
181
|
});
|
|
146
182
|
}
|
|
147
183
|
return o;
|
|
148
|
-
},
|
|
149
|
-
const
|
|
184
|
+
}, Le = (e) => {
|
|
185
|
+
const t = new m(e), o = c(t, "manifest"), r = c(t, "spine"), n = c(t, "metadata");
|
|
150
186
|
let i = [], s = [];
|
|
151
187
|
if (o !== void 0) {
|
|
152
|
-
const { items:
|
|
153
|
-
i =
|
|
188
|
+
const { items: B, byId: X } = ee(o);
|
|
189
|
+
i = B, r !== void 0 && (s = te(X, r));
|
|
154
190
|
}
|
|
155
|
-
const
|
|
156
|
-
let
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
const
|
|
191
|
+
const p = r?.attr["page-progression-direction"], P = p !== void 0 && p.trim().length > 0 ? p : void 0, v = r?.attr.toc, x = v !== void 0 && v.trim().length > 0 ? v.trim() : void 0;
|
|
192
|
+
let I, b, C, w, N = [], S = [], E = [], T, D, O;
|
|
193
|
+
const M = [];
|
|
194
|
+
n !== void 0 && (I = d(n, "title"), b = d(n, "publisher"), C = d(n, "rights"), w = 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"), M.push(...W(n)));
|
|
195
|
+
const R = J({
|
|
196
|
+
manifestItems: i,
|
|
197
|
+
metadataEl: n
|
|
198
|
+
}), j = Q(t);
|
|
160
199
|
return {
|
|
161
200
|
kind: "opf",
|
|
162
201
|
manifestItems: i,
|
|
163
202
|
spineRows: s,
|
|
164
|
-
spineTocIdref:
|
|
165
|
-
identifiers:
|
|
166
|
-
title:
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
203
|
+
spineTocIdref: x,
|
|
204
|
+
identifiers: M,
|
|
205
|
+
title: I,
|
|
206
|
+
creators: N,
|
|
207
|
+
publisher: b,
|
|
208
|
+
rights: C,
|
|
209
|
+
languages: S,
|
|
210
|
+
subjects: E,
|
|
211
|
+
date: w,
|
|
212
|
+
coverHref: R,
|
|
213
|
+
renditionLayoutMeta: T,
|
|
214
|
+
renditionFlowMeta: D,
|
|
215
|
+
renditionSpreadMeta: O,
|
|
216
|
+
pageProgressionDirection: P,
|
|
217
|
+
guide: j
|
|
172
218
|
};
|
|
173
|
-
},
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
219
|
+
}, oe = (e) => ({
|
|
220
|
+
gtin: void 0,
|
|
221
|
+
isbn: void 0,
|
|
222
|
+
readingDirection: void 0,
|
|
223
|
+
renditionLayout: e.displayOptions?.platform?.options?.find(
|
|
224
|
+
(r) => r.name === "fixed-layout"
|
|
225
|
+
)?.value?.trim().toLowerCase() === "true" ? "pre-paginated" : void 0,
|
|
226
|
+
title: void 0,
|
|
227
|
+
authors: void 0,
|
|
228
|
+
publisher: void 0,
|
|
229
|
+
rights: void 0,
|
|
230
|
+
languages: void 0,
|
|
231
|
+
date: void 0,
|
|
232
|
+
subjects: void 0
|
|
233
|
+
}), re = /* @__PURE__ */ new Set([8, 12, 13, 14]), F = (e) => {
|
|
234
|
+
if (e == null) return;
|
|
235
|
+
const t = String(e).replace(/\D/g, "");
|
|
236
|
+
if (!(t.length === 0 || !re.has(t.length)))
|
|
237
|
+
return t;
|
|
238
|
+
}, ne = /(?:97[89])?\d{9}[\dXx]/, u = (e) => {
|
|
239
|
+
if (e == null) return;
|
|
240
|
+
const t = String(e).trim().replace(/^urn:isbn:/i, "").replace(/^isbn[:\s-]*/i, ""), o = t.replace(/[^0-9Xx]/g, "");
|
|
188
241
|
if (o.length === 10 || o.length === 13)
|
|
189
242
|
return o.toUpperCase();
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
192
|
-
},
|
|
193
|
-
|
|
243
|
+
const r = t.match(ne);
|
|
244
|
+
if (r) return r[0].toUpperCase();
|
|
245
|
+
}, ie = (e) => e.Manga === "YesAndRightToLeft" ? "rtl" : "ltr", l = (e) => {
|
|
246
|
+
if (e === void 0) return;
|
|
247
|
+
const t = e.trim();
|
|
248
|
+
return t.length > 0 ? t : void 0;
|
|
249
|
+
}, y = (e) => e === void 0 ? [] : e.split(",").map((t) => t.trim()).filter((t) => t.length > 0), L = (e) => {
|
|
250
|
+
const t = l(e);
|
|
251
|
+
if (t === void 0 || !/^\d+$/.test(t)) return;
|
|
252
|
+
const o = Number.parseInt(t, 10);
|
|
253
|
+
return Number.isFinite(o) ? o : void 0;
|
|
254
|
+
}, se = (e) => {
|
|
255
|
+
const t = L(e.Year), o = L(e.Month), r = L(e.Day);
|
|
256
|
+
if (!(t === void 0 && o === void 0 && r === void 0))
|
|
257
|
+
return {
|
|
258
|
+
...t !== void 0 ? { year: t } : {},
|
|
259
|
+
...o !== void 0 ? { month: o } : {},
|
|
260
|
+
...r !== void 0 ? { day: r } : {}
|
|
261
|
+
};
|
|
262
|
+
}, ae = (e) => {
|
|
263
|
+
const t = e.GTIN, o = l(e.LanguageISO), r = y(e.Writer), n = [...y(e.Genre), ...y(e.Tags)];
|
|
264
|
+
return {
|
|
265
|
+
gtin: F(t),
|
|
266
|
+
isbn: u(t),
|
|
267
|
+
readingDirection: ie(e),
|
|
268
|
+
renditionLayout: void 0,
|
|
269
|
+
title: l(e.Title),
|
|
270
|
+
authors: r.length > 0 ? r : void 0,
|
|
271
|
+
publisher: l(e.Publisher),
|
|
272
|
+
rights: void 0,
|
|
273
|
+
languages: o !== void 0 ? [o] : void 0,
|
|
274
|
+
date: se(e),
|
|
275
|
+
subjects: n.length > 0 ? n : void 0
|
|
276
|
+
};
|
|
277
|
+
}, de = (e) => ({
|
|
278
|
+
gtin: void 0,
|
|
279
|
+
isbn: void 0,
|
|
280
|
+
readingDirection: void 0,
|
|
281
|
+
renditionLayout: e.renditionLayout,
|
|
282
|
+
title: void 0,
|
|
283
|
+
authors: void 0,
|
|
284
|
+
publisher: void 0,
|
|
285
|
+
rights: void 0,
|
|
286
|
+
languages: void 0,
|
|
287
|
+
date: void 0,
|
|
288
|
+
subjects: void 0
|
|
289
|
+
}), ce = (e) => {
|
|
290
|
+
if (e === void 0) return;
|
|
291
|
+
const t = e.trim().match(/^(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?/);
|
|
292
|
+
if (t === null) return;
|
|
293
|
+
const [, o, r, n] = t;
|
|
194
294
|
return {
|
|
195
|
-
...o !== void 0 ? {
|
|
196
|
-
...
|
|
197
|
-
|
|
295
|
+
...o !== void 0 ? { year: Number.parseInt(o, 10) } : {},
|
|
296
|
+
...r !== void 0 ? { month: Number.parseInt(r, 10) } : {},
|
|
297
|
+
...n !== void 0 ? { day: Number.parseInt(n, 10) } : {}
|
|
198
298
|
};
|
|
199
|
-
},
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
for (const
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (c(e.value) !== void 0) return e.value;
|
|
208
|
-
}, J = (t) => {
|
|
209
|
-
const e = t.pageProgressionDirection?.trim().toLowerCase(), o = e === "ltr" || e === "rtl" ? e : void 0, n = t.renditionLayoutMeta?.trim().toLowerCase(), r = n === "reflowable" || n === "pre-paginated" ? n : void 0, i = j(t.identifiers), s = c(i), a = C(i);
|
|
299
|
+
}, le = (e) => {
|
|
300
|
+
for (const t of e)
|
|
301
|
+
if (t.scheme !== void 0 && t.scheme.trim().toLowerCase() === "isbn" && u(t.value) !== void 0)
|
|
302
|
+
return t.value;
|
|
303
|
+
for (const t of e)
|
|
304
|
+
if (u(t.value) !== void 0) return t.value;
|
|
305
|
+
}, ue = (e) => {
|
|
306
|
+
const t = e.pageProgressionDirection?.trim().toLowerCase(), o = t === "ltr" || t === "rtl" ? t : void 0, r = e.renditionLayoutMeta?.trim().toLowerCase(), n = r === "reflowable" || r === "pre-paginated" ? r : void 0, i = le(e.identifiers);
|
|
210
307
|
return {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
308
|
+
gtin: F(i),
|
|
309
|
+
isbn: u(i),
|
|
310
|
+
readingDirection: o,
|
|
311
|
+
renditionLayout: n,
|
|
312
|
+
title: e.title,
|
|
313
|
+
authors: e.creators.length > 0 ? [...e.creators] : void 0,
|
|
314
|
+
publisher: e.publisher,
|
|
315
|
+
rights: e.rights,
|
|
316
|
+
languages: e.languages.length > 0 ? [...e.languages] : void 0,
|
|
317
|
+
date: ce(e.date),
|
|
318
|
+
subjects: e.subjects.length > 0 ? [...e.subjects] : void 0
|
|
215
319
|
};
|
|
216
|
-
},
|
|
320
|
+
}, Ie = (e) => e.kind === "comicInfo" ? ae(e) : e.kind === "kobo" ? de(e) : e.kind === "apple" ? oe(e) : ue(e);
|
|
217
321
|
export {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
322
|
+
fe as APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME,
|
|
323
|
+
K as COMIC_INFO_FILENAME,
|
|
324
|
+
G as COMIC_INFO_MANGA_VALUES,
|
|
325
|
+
he as KOBO_DISPLAY_OPTIONS_FILENAME,
|
|
326
|
+
ve as isComicInfoManga,
|
|
327
|
+
F as normalizeGtin,
|
|
328
|
+
u as normalizeIsbn,
|
|
329
|
+
pe as parseAppleDisplayOptionsXml,
|
|
330
|
+
ge as parseComicInfo,
|
|
331
|
+
ye as parseKoboXml,
|
|
332
|
+
Le as parseOpf,
|
|
333
|
+
ce as parseW3cDtfDate,
|
|
334
|
+
Ie as resolveArchiveMetadata,
|
|
335
|
+
A as tokenizeXmlSpaceSeparatedList
|
|
231
336
|
};
|
|
232
337
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/apple/parse.ts","../src/comicInfo/manga.ts","../src/comicInfo/parse.ts","../src/kobo/parse.ts","../src/utils/tokenizeXmlSpaceSeparatedList.ts","../src/opf/spineItemrefProperties.ts","../src/opf/parse.ts","../src/apple/resolve.ts","../src/utils/normalizeGtin.ts","../src/utils/normalizeIsbn.ts","../src/comicInfo/resolve.ts","../src/kobo/resolve.ts","../src/opf/resolve.ts","../src/resolve.ts"],"sourcesContent":["import type { XmlElement } from \"xmldoc\"\nimport { XmlDocument } from \"xmldoc\"\n\nexport const APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME =\n \"com.apple.ibooks.display-options.xml\"\n\nexport type AppleDisplayOption = {\n readonly name?: string\n readonly value: string\n}\n\nexport type AppleMetadata = {\n readonly kind: \"apple\"\n readonly displayOptions?: {\n readonly platform?: {\n readonly options: ReadonlyArray<AppleDisplayOption>\n }\n }\n}\n\nconst platformOptionsFromElement = (\n platform: XmlElement,\n): ReadonlyArray<AppleDisplayOption> =>\n platform.childrenNamed(\"option\").map((option) => ({\n name: option.attr?.name,\n value: option.val,\n }))\n\nexport const parseAppleDisplayOptionsXml = (xml: string): AppleMetadata => {\n const doc = new XmlDocument(xml)\n const root = doc.name?.toLowerCase()\n\n if (root !== \"display_options\") {\n return { kind: \"apple\" }\n }\n\n const platformEl = doc.childNamed(\"platform\")\n\n return {\n kind: \"apple\",\n displayOptions: {\n ...(platformEl !== undefined\n ? { platform: { options: platformOptionsFromElement(platformEl) } }\n : {}),\n },\n }\n}\n","/**\n * Allowed `Manga` element values (ComicInfo 2.0 `Manga` simpleType).\n *\n * @see https://anansi-project.github.io/docs/comicinfo/documentation#manga\n */\nexport const COMIC_INFO_MANGA_VALUES = [\n \"Unknown\",\n \"No\",\n \"Yes\",\n \"YesAndRightToLeft\",\n] as const\n\nexport type ComicInfoManga = (typeof COMIC_INFO_MANGA_VALUES)[number]\n\nexport const isComicInfoManga = (value: string): value is ComicInfoManga => {\n for (const v of COMIC_INFO_MANGA_VALUES) {\n if (v === value) return true\n }\n return false\n}\n","import type { XmlElement } from \"xmldoc\"\nimport { XmlDocument } from \"xmldoc\"\nimport type { ComicInfoManga } from \"./manga\"\n\n/** Canonical top-level filename; real archives may use any casing. */\nexport const COMIC_INFO_FILENAME = \"ComicInfo.xml\"\n\n/**\n * Parsed `ComicInfo.xml` root: one optional string property per child element,\n * using the same names as in the file (e.g. `Title`, `GTIN`, `LanguageISO`).\n * Nested blocks such as `Pages` are skipped. Other simple child elements are\n * still copied onto this object under their tag name.\n *\n * @see https://anansi-project.github.io/docs/comicinfo/intro\n * @see https://github.com/anansi-project/comicinfo/blob/main/drafts/v2.1/ComicInfo.xsd for schema\n */\nexport interface ComicInfo {\n readonly kind: \"comicInfo\"\n AgeRating?: string\n AlternateCount?: string\n AlternateNumber?: string\n AlternateSeries?: string\n BlackAndWhite?: string\n Characters?: string\n Colorist?: string\n CommunityRating?: string\n Count?: string\n CoverArtist?: string\n Day?: string\n Editor?: string\n Format?: string\n Genre?: string\n GTIN?: string\n Imprint?: string\n Inker?: string\n LanguageISO?: string\n Letterer?: string\n Locations?: string\n MainCharacterOrTeam?: string\n /** Schema literals per {@link ComicInfoManga}; files may still use other strings. */\n Manga?: ComicInfoManga | (string & {})\n Month?: string\n Notes?: string\n Number?: string\n PageCount?: string\n Penciller?: string\n Publisher?: string\n Review?: string\n ScanInformation?: string\n Series?: string\n SeriesGroup?: string\n StoryArc?: string\n StoryArcNumber?: string\n Summary?: string\n Tags?: string\n Teams?: string\n Title?: string\n Translator?: string\n Volume?: string\n Web?: string\n Writer?: string\n Year?: string\n [tag: string]: string | undefined\n}\n\nconst SKIP_ELEMENT_CHILDREN = new Set([\"Pages\", \"ComicInfo\"])\n\nconst hasNestedElement = (el: XmlElement) =>\n el.children.some((c) => c.type === \"element\")\n\nconst trimmedText = (el: XmlElement): string | undefined => {\n const t = el.val.trim()\n return t.length > 0 ? t : undefined\n}\n\n/**\n * Parse a raw `ComicInfo.xml` body. Each direct child element with plain text\n * becomes a property named after that tag. Malformed XML throws; the parser\n * error is attached as `cause`.\n */\nexport const parseComicInfo = (xml: string): ComicInfo => {\n let doc: XmlDocument\n try {\n doc = new XmlDocument(xml)\n } catch (cause) {\n const message = cause instanceof Error ? cause.message : String(cause)\n throw new Error(`${COMIC_INFO_FILENAME} is malformed: ${message}`, {\n cause,\n })\n }\n\n const fields: Record<string, string> = {}\n\n doc.eachChild((child) => {\n if (child.type !== \"element\") return\n if (SKIP_ELEMENT_CHILDREN.has(child.name)) return\n if (hasNestedElement(child)) return\n\n const text = trimmedText(child)\n if (text === undefined) return\n if (fields[child.name] !== undefined) return\n\n fields[child.name] = text\n })\n\n // `as ComicInfo`: TS cannot infer that spreading `Record<string, string>` into `{ kind }` satisfies the named optional fields plus `[tag: string]: string | undefined` on `ComicInfo`.\n return { kind: \"comicInfo\", ...fields } as ComicInfo\n}\n","import { XmlDocument } from \"xmldoc\"\n\nexport const KOBO_DISPLAY_OPTIONS_FILENAME = \"com.kobobooks.display-options.xml\"\n\n/**\n * Normalized fields from Kobo-specific XML sidecars. Grows as new Kobo\n * document kinds are supported; absent keys mean not present or unknown.\n */\nexport type KoboMetadata = {\n readonly kind: \"kobo\"\n renditionLayout?: `reflowable` | `pre-paginated`\n}\n\nconst parseKoboDisplayOptionsDocument = (\n doc: XmlDocument,\n): { renditionLayout?: \"pre-paginated\" } => {\n const platform = doc.childNamed(\"platform\")\n if (!platform) return {}\n\n for (const option of platform.childrenNamed(\"option\")) {\n if (option.attr?.name !== \"fixed-layout\") continue\n if (option.val.trim().toLowerCase() === \"true\") {\n return { renditionLayout: \"pre-paginated\" }\n }\n return {}\n }\n\n return {}\n}\n\n/**\n * Parse a Kobo-related XML document. Unsupported or unrecognized roots\n * yield an empty object. Malformed XML throws from the underlying parser.\n */\nexport const parseKoboXml = (xml: string): KoboMetadata => {\n const doc = new XmlDocument(xml)\n const root = doc.name?.toLowerCase()\n\n if (root === \"display_options\") {\n return { kind: \"kobo\", ...parseKoboDisplayOptionsDocument(doc) }\n }\n\n return { kind: \"kobo\" }\n}\n","/**\n * EPUB/XML space-separated token lists (e.g. `properties` on `item` / `itemref`).\n * Trims the raw string, splits on ASCII whitespace, drops empty segments.\n */\nexport const tokenizeXmlSpaceSeparatedList = (\n raw: string | undefined,\n): readonly string[] => {\n if (raw === undefined || raw.trim().length === 0) {\n return []\n }\n\n return raw\n .trim()\n .split(/\\s+/)\n .filter((t) => t.length > 0)\n}\n","import { tokenizeXmlSpaceSeparatedList } from \"../utils/tokenizeXmlSpaceSeparatedList\"\n\nexport type OpfItemrefLayoutHints = {\n readonly renditionLayout?: `reflowable` | `pre-paginated`\n readonly pageSpreadLeft?: true\n readonly pageSpreadRight?: true\n}\n\n/**\n * EPUB `itemref` `properties` attribute (space-separated tokens).\n *\n * @see https://www.w3.org/TR/epub/#attrdef-properties\n */\nexport const layoutHintsFromItemrefProperties = (\n properties: string | undefined,\n): OpfItemrefLayoutHints => {\n const tokens = tokenizeXmlSpaceSeparatedList(properties)\n if (tokens.length === 0) {\n return {}\n }\n\n let renditionLayout: `reflowable` | `pre-paginated` | undefined\n if (tokens.includes(`rendition:layout-reflowable`)) {\n renditionLayout = `reflowable`\n }\n if (tokens.includes(`rendition:layout-pre-paginated`)) {\n renditionLayout = `pre-paginated`\n }\n\n return {\n ...(renditionLayout !== undefined ? { renditionLayout } : {}),\n ...(tokens.includes(`page-spread-left`)\n ? { pageSpreadLeft: true as const }\n : {}),\n ...(tokens.includes(`page-spread-right`)\n ? { pageSpreadRight: true as const }\n : {}),\n }\n}\n","import type { XmlElement, XmlNodeBase } from \"xmldoc\"\nimport { XmlDocument } from \"xmldoc\"\nimport { layoutHintsFromItemrefProperties } from \"./spineItemrefProperties\"\n\nexport type OpfSpineManifestItem = {\n readonly id: string\n readonly href: string\n readonly mediaType?: string\n readonly properties?: string\n}\n\nexport type OpfIdentifier = {\n readonly value: string\n readonly scheme?: string\n}\n\nexport type OpfSpineRow = {\n readonly idref: string\n readonly id: string\n readonly href: string\n readonly mediaType?: string\n readonly properties?: string\n readonly renditionLayout?: `reflowable` | `pre-paginated`\n readonly pageSpreadLeft?: true\n readonly pageSpreadRight?: true\n}\n\nexport type OpfGuideReference = {\n readonly href: string\n readonly title: string\n readonly type: string\n}\n\nconst elementLocalName = (name: string): string =>\n name.includes(\":\") ? name.slice(name.lastIndexOf(\":\") + 1) : name\n\nconst localNameEq = (elementName: string, wantLocal: string): boolean =>\n elementLocalName(elementName).toLowerCase() === wantLocal.toLowerCase()\n\nconst isXmlElement = (node: XmlNodeBase): node is XmlElement =>\n node.type === \"element\"\n\nconst childNamedLocal = (\n parent: XmlElement,\n localName: string,\n): XmlElement | undefined => {\n for (const node of parent.children) {\n if (!isXmlElement(node)) continue\n if (localNameEq(node.name, localName)) return node\n }\n return undefined\n}\n\nconst childrenNamedLocal = (\n parent: XmlElement,\n localName: string,\n): XmlElement[] => {\n const out: XmlElement[] = []\n for (const node of parent.children) {\n if (!isXmlElement(node)) continue\n if (localNameEq(node.name, localName)) out.push(node)\n }\n return out\n}\n\nconst identifiersFromMetadata = (metadataEl: XmlElement): OpfIdentifier[] => {\n const identifiers: OpfIdentifier[] = []\n\n metadataEl.eachChild((child) => {\n if (elementLocalName(child.name).toLowerCase() !== \"identifier\") return\n\n const value = child.val.trim()\n if (value.length === 0) return\n\n const scheme =\n child.attr[\"opf:scheme\"] ?? child.attr[\"opf:Scheme\"] ?? child.attr.scheme\n const schemeTrimmed = scheme?.trim()\n\n identifiers.push({\n value,\n ...(schemeTrimmed !== undefined && schemeTrimmed.length > 0\n ? { scheme: schemeTrimmed }\n : {}),\n })\n })\n\n return identifiers\n}\n\nconst titleFromMetadata = (metadataEl: XmlElement): string | undefined => {\n let found: string | undefined\n metadataEl.eachChild((child) => {\n if (found !== undefined) return\n if (elementLocalName(child.name).toLowerCase() !== \"title\") return\n const t = child.val.trim()\n if (t.length > 0) found = t\n })\n return found\n}\n\nconst metaValByProperty = (\n metadataEl: XmlElement,\n property: string,\n): string | undefined => {\n const meta = childrenNamedLocal(metadataEl, \"meta\").find(\n (m) => m.attr.property === property,\n )\n const raw = meta?.val\n if (raw === undefined || raw.trim().length === 0) return undefined\n return raw\n}\n\nconst guideFromPackage = (doc: XmlElement): OpfGuideReference[] => {\n const guideEl = childNamedLocal(doc, \"guide\")\n if (guideEl === undefined) return []\n\n const refs: OpfGuideReference[] = []\n\n for (const ref of childrenNamedLocal(guideEl, \"reference\")) {\n const href = ref.attr.href?.trim()\n if (href === undefined || href.length === 0) continue\n refs.push({\n href,\n title: ref.attr.title?.trim() ?? ``,\n type: ref.attr.type?.trim() ?? ``,\n })\n }\n\n return refs\n}\n\nconst manifestItemFromXmlElement = (\n item: XmlElement,\n): OpfSpineManifestItem | undefined => {\n const id = item.attr.id\n const href = item.attr.href\n if (id === undefined || id.length === 0) return undefined\n if (href === undefined || href.length === 0) return undefined\n\n const mediaType = item.attr[\"media-type\"]\n const properties = item.attr.properties?.trim()\n return {\n id,\n href,\n ...(mediaType !== undefined && mediaType.length > 0 ? { mediaType } : {}),\n ...(properties !== undefined && properties.length > 0\n ? { properties }\n : {}),\n }\n}\n\nconst manifestItemsAndById = (\n manifestEl: XmlElement,\n): {\n items: OpfSpineManifestItem[]\n byId: Map<string, OpfSpineManifestItem>\n} => {\n const items: OpfSpineManifestItem[] = []\n const byId = new Map<string, OpfSpineManifestItem>()\n\n for (const el of childrenNamedLocal(manifestEl, \"item\")) {\n const parsed = manifestItemFromXmlElement(el)\n if (parsed === undefined) continue\n items.push(parsed)\n byId.set(parsed.id, parsed)\n }\n\n return { items, byId }\n}\n\nconst spineRowsFromByIdAndSpine = (\n byId: Map<string, OpfSpineManifestItem>,\n spineEl: XmlElement,\n): OpfSpineRow[] => {\n const rows: OpfSpineRow[] = []\n\n for (const itemref of childrenNamedLocal(spineEl, \"itemref\")) {\n const idref = itemref.attr.idref\n if (idref === undefined || idref.trim().length === 0) continue\n\n const manifestItem = byId.get(idref)\n if (manifestItem === undefined) continue\n\n const hints = layoutHintsFromItemrefProperties(itemref.attr.properties)\n\n rows.push({\n idref,\n id: manifestItem.id,\n href: manifestItem.href,\n ...(manifestItem.mediaType !== undefined\n ? { mediaType: manifestItem.mediaType }\n : {}),\n ...(manifestItem.properties !== undefined\n ? { properties: manifestItem.properties }\n : {}),\n ...(hints.renditionLayout !== undefined\n ? { renditionLayout: hints.renditionLayout }\n : {}),\n ...(hints.pageSpreadLeft !== undefined\n ? { pageSpreadLeft: hints.pageSpreadLeft }\n : {}),\n ...(hints.pageSpreadRight !== undefined\n ? { pageSpreadRight: hints.pageSpreadRight }\n : {}),\n })\n }\n\n return rows\n}\n\nexport type OpfMetadata = {\n readonly kind: \"opf\"\n readonly manifestItems: ReadonlyArray<OpfSpineManifestItem>\n readonly spineRows: ReadonlyArray<OpfSpineRow>\n readonly spineTocIdref: string | undefined\n readonly identifiers: ReadonlyArray<OpfIdentifier>\n readonly title: string | undefined\n readonly renditionLayoutMeta: string | undefined\n readonly renditionFlowMeta: string | undefined\n readonly renditionSpreadMeta: string | undefined\n readonly pageProgressionDirection: string | undefined\n readonly guide: ReadonlyArray<OpfGuideReference>\n}\n\n/**\n * Parses an EPUB package document (OPF) into structured metadata.\n *\n * Direct children of `package` (`metadata`, `manifest`, `spine`, `guide`) and\n * their structural children (`item`, `itemref`, `reference`, `meta`) are\n * matched by **local name** (ASCII case-insensitive), so prefixed tags such as\n * `opf:manifest` are supported the same as unprefixed `manifest`.\n *\n * Attribute names on `spine` / `itemref` are still read as emitted by xmldoc\n * (no QName normalization).\n */\nexport const parseOpf = (opfXml: string): OpfMetadata => {\n const doc = new XmlDocument(opfXml)\n const manifestEl = childNamedLocal(doc, \"manifest\")\n const spineEl = childNamedLocal(doc, \"spine\")\n const metadataEl = childNamedLocal(doc, \"metadata\")\n\n let manifestItems: OpfSpineManifestItem[] = []\n let spineRows: OpfSpineRow[] = []\n\n if (manifestEl !== undefined) {\n const { items, byId } = manifestItemsAndById(manifestEl)\n manifestItems = items\n if (spineEl !== undefined) {\n spineRows = spineRowsFromByIdAndSpine(byId, spineEl)\n }\n }\n\n const pageProgressionDirectionRaw =\n spineEl?.attr[\"page-progression-direction\"]\n const pageProgressionDirection =\n pageProgressionDirectionRaw !== undefined &&\n pageProgressionDirectionRaw.trim().length > 0\n ? pageProgressionDirectionRaw\n : undefined\n\n const spineTocRaw = spineEl?.attr.toc\n const spineTocIdref =\n spineTocRaw !== undefined && spineTocRaw.trim().length > 0\n ? spineTocRaw.trim()\n : undefined\n\n let title: string | undefined\n let renditionLayoutMeta: string | undefined\n let renditionFlowMeta: string | undefined\n let renditionSpreadMeta: string | undefined\n const identifiers: OpfIdentifier[] = []\n\n if (metadataEl !== undefined) {\n title = titleFromMetadata(metadataEl)\n renditionLayoutMeta = metaValByProperty(metadataEl, \"rendition:layout\")\n renditionFlowMeta = metaValByProperty(metadataEl, \"rendition:flow\")\n renditionSpreadMeta = metaValByProperty(metadataEl, \"rendition:spread\")\n identifiers.push(...identifiersFromMetadata(metadataEl))\n }\n\n const guide = guideFromPackage(doc)\n\n return {\n kind: \"opf\",\n manifestItems,\n spineRows,\n spineTocIdref,\n identifiers,\n title,\n renditionLayoutMeta,\n renditionFlowMeta,\n renditionSpreadMeta,\n pageProgressionDirection,\n guide,\n }\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport type { AppleMetadata } from \"./parse\"\n\nexport const resolveApple = (input: AppleMetadata): ArchiveResolveResult => {\n const fixedLayout = input.displayOptions?.platform?.options?.find(\n (o) => o.name === \"fixed-layout\",\n )?.value\n\n if (fixedLayout === undefined) return {}\n\n const renditionLayout =\n fixedLayout.trim().toLowerCase() === \"true\"\n ? (\"pre-paginated\" as const)\n : undefined\n\n return renditionLayout !== undefined ? { renditionLayout } : {}\n}\n","const GTIN_LENGTHS = new Set([8, 12, 13, 14])\n\n/**\n * Normalize a raw GTIN / EAN / UPC string to digits only when the length\n * matches a GS1 GTIN family size (8, 12, 13, or 14). Does not verify check digits.\n */\nexport const normalizeGtin = (\n raw: string | number | undefined | null,\n): string | undefined => {\n if (raw === undefined || raw === null) return undefined\n\n const digits = String(raw).replace(/\\D/g, \"\")\n if (digits.length === 0 || !GTIN_LENGTHS.has(digits.length)) return undefined\n\n return digits\n}\n","const ISBN_CANDIDATE_PATTERN = /(?:97[89])?\\d{9}[\\dXx]/\n\n/**\n * Normalize a raw ISBN-ish string into a canonical 10- or 13-character\n * form, or `undefined` when no recognisable ISBN can be recovered.\n *\n * - Strips the common `urn:isbn:` / `isbn:` prefixes.\n * - Drops everything that isn't a digit or `X`.\n * - Validates the resulting length (10 or 13).\n * - Falls back to a lax regex scan so publishers that stuff free text\n * around the number still yield a usable value.\n */\nexport const normalizeIsbn = (\n raw: string | number | undefined | null,\n): string | undefined => {\n if (raw === undefined || raw === null) return undefined\n\n const stripped = String(raw)\n .trim()\n .replace(/^urn:isbn:/i, \"\")\n .replace(/^isbn[:\\s-]*/i, \"\")\n\n const digitsOnly = stripped.replace(/[^0-9Xx]/g, \"\")\n\n if (digitsOnly.length === 10 || digitsOnly.length === 13) {\n return digitsOnly.toUpperCase()\n }\n\n const match = stripped.match(ISBN_CANDIDATE_PATTERN)\n if (match) return match[0].toUpperCase()\n\n return undefined\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport { normalizeGtin } from \"../utils/normalizeGtin\"\nimport { normalizeIsbn } from \"../utils/normalizeIsbn\"\nimport type { ComicInfo } from \"./parse\"\n\nconst readingDirection = (info: ComicInfo): \"ltr\" | \"rtl\" =>\n info.Manga === \"YesAndRightToLeft\" ? \"rtl\" : \"ltr\"\n\nexport const resolveComicInfo = (info: ComicInfo): ArchiveResolveResult => {\n const raw = info.GTIN\n const gtin = normalizeGtin(raw)\n const isbn = normalizeIsbn(raw)\n return {\n ...(gtin !== undefined ? { gtin } : {}),\n ...(isbn !== undefined ? { isbn } : {}),\n readingDirection: readingDirection(info),\n }\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport type { KoboMetadata } from \"./parse\"\n\nexport const resolveKobo = (input: KoboMetadata): ArchiveResolveResult => {\n const { renditionLayout } = input\n return renditionLayout !== undefined ? { renditionLayout } : {}\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport { normalizeGtin } from \"../utils/normalizeGtin\"\nimport { normalizeIsbn } from \"../utils/normalizeIsbn\"\nimport type { OpfIdentifier, OpfMetadata } from \"./parse\"\n\nconst rawIdentifierValueForIsbn = (\n identifiers: ReadonlyArray<OpfIdentifier>,\n): string | undefined => {\n for (const i of identifiers) {\n if (i.scheme !== undefined && i.scheme.trim().toLowerCase() === \"isbn\") {\n if (normalizeIsbn(i.value) !== undefined) return i.value\n }\n }\n\n for (const i of identifiers) {\n if (normalizeIsbn(i.value) !== undefined) return i.value\n }\n\n return undefined\n}\n\nexport const resolveOpf = (input: OpfMetadata): ArchiveResolveResult => {\n const ppd = input.pageProgressionDirection?.trim().toLowerCase()\n const readingDirection = ppd === \"ltr\" || ppd === \"rtl\" ? ppd : undefined\n\n const rl = input.renditionLayoutMeta?.trim().toLowerCase()\n const renditionLayout =\n rl === \"reflowable\" || rl === \"pre-paginated\" ? rl : undefined\n\n const raw = rawIdentifierValueForIsbn(input.identifiers)\n const isbn = normalizeIsbn(raw)\n const gtin = normalizeGtin(raw)\n\n return {\n ...(gtin !== undefined ? { gtin } : {}),\n ...(isbn !== undefined ? { isbn } : {}),\n ...(readingDirection !== undefined ? { readingDirection } : {}),\n ...(renditionLayout !== undefined ? { renditionLayout } : {}),\n }\n}\n","import type { AppleMetadata } from \"./apple/parse\"\nimport { resolveApple } from \"./apple/resolve\"\nimport type { ComicInfo } from \"./comicInfo/parse\"\nimport { resolveComicInfo } from \"./comicInfo/resolve\"\nimport type { KoboMetadata } from \"./kobo/parse\"\nimport { resolveKobo } from \"./kobo/resolve\"\nimport type { OpfMetadata } from \"./opf/parse\"\nimport { resolveOpf } from \"./opf/resolve\"\nimport type { ArchiveResolveResult } from \"./types/archiveResolve\"\n\nexport type ResolvedArchiveInput =\n | ComicInfo\n | KoboMetadata\n | AppleMetadata\n | OpfMetadata\n\nexport const resolveArchiveMetadata = (\n input: ResolvedArchiveInput,\n): ArchiveResolveResult => {\n if (input.kind === \"comicInfo\") return resolveComicInfo(input)\n if (input.kind === \"kobo\") return resolveKobo(input)\n if (input.kind === \"apple\") return resolveApple(input)\n return resolveOpf(input)\n}\n"],"names":["APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME","platformOptionsFromElement","platform","option","parseAppleDisplayOptionsXml","xml","doc","XmlDocument","platformEl","COMIC_INFO_MANGA_VALUES","isComicInfoManga","value","v","COMIC_INFO_FILENAME","SKIP_ELEMENT_CHILDREN","hasNestedElement","el","c","trimmedText","t","parseComicInfo","cause","message","fields","child","text","KOBO_DISPLAY_OPTIONS_FILENAME","parseKoboDisplayOptionsDocument","parseKoboXml","tokenizeXmlSpaceSeparatedList","raw","layoutHintsFromItemrefProperties","properties","tokens","renditionLayout","elementLocalName","name","localNameEq","elementName","wantLocal","isXmlElement","node","childNamedLocal","parent","localName","childrenNamedLocal","out","identifiersFromMetadata","metadataEl","identifiers","schemeTrimmed","titleFromMetadata","found","metaValByProperty","property","m","guideFromPackage","guideEl","refs","ref","href","manifestItemFromXmlElement","item","id","mediaType","manifestItemsAndById","manifestEl","items","byId","parsed","spineRowsFromByIdAndSpine","spineEl","rows","itemref","idref","manifestItem","hints","parseOpf","opfXml","manifestItems","spineRows","pageProgressionDirectionRaw","pageProgressionDirection","spineTocRaw","spineTocIdref","title","renditionLayoutMeta","renditionFlowMeta","renditionSpreadMeta","guide","resolveApple","input","fixedLayout","o","GTIN_LENGTHS","normalizeGtin","digits","ISBN_CANDIDATE_PATTERN","normalizeIsbn","stripped","digitsOnly","match","readingDirection","info","resolveComicInfo","gtin","isbn","resolveKobo","rawIdentifierValueForIsbn","i","resolveOpf","ppd","rl","resolveArchiveMetadata"],"mappings":";AAGO,MAAMA,IACX,wCAgBIC,IAA6B,CACjCC,MAEAA,EAAS,cAAc,QAAQ,EAAE,IAAI,CAACC,OAAY;AAAA,EAChD,MAAMA,EAAO,MAAM;AAAA,EACnB,OAAOA,EAAO;AAChB,EAAE,GAESC,IAA8B,CAACC,MAA+B;AACzE,QAAMC,IAAM,IAAIC,EAAYF,CAAG;AAG/B,MAFaC,EAAI,MAAM,YAAA,MAEV;AACX,WAAO,EAAE,MAAM,QAAA;AAGjB,QAAME,IAAaF,EAAI,WAAW,UAAU;AAE5C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,gBAAgB;AAAA,MACd,GAAIE,MAAe,SACf,EAAE,UAAU,EAAE,SAASP,EAA2BO,CAAU,EAAA,MAC5D,CAAA;AAAA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AE,KAAK,MAAM,eAAkBA,EAAE;AAIvD,GAEaC,IAAa,CAACnB,MAA6C;AACtE,QAAMoB,IAAMpB,EAAM,0BAA0B,KAAA,EAAO,YAAA,GAC7CW,IAAmBS,MAAQ,SAASA,MAAQ,QAAQA,IAAM,QAE1DC,IAAKrB,EAAM,qBAAqB,KAAA,EAAO,YAAA,GACvCzD,IACJ8E,MAAO,gBAAgBA,MAAO,kBAAkBA,IAAK,QAEjDlF,IAAM8E,EAA0BjB,EAAM,WAAW,GACjDe,IAAOR,EAAcpE,CAAG,GACxB2E,IAAOV,EAAcjE,CAAG;AAE9B,SAAO;AAAA,IACL,GAAI2E,MAAS,SAAY,EAAE,MAAAA,EAAA,IAAS,CAAA;AAAA,IACpC,GAAIC,MAAS,SAAY,EAAE,MAAAA,EAAA,IAAS,CAAA;AAAA,IACpC,GAAIJ,MAAqB,SAAY,EAAE,kBAAAA,EAAA,IAAqB,CAAA;AAAA,IAC5D,GAAIpE,MAAoB,SAAY,EAAE,iBAAAA,MAAoB,CAAA;AAAA,EAAC;AAE/D,GCvBa+E,KAAyB,CACpCtB,MAEIA,EAAM,SAAS,cAAoBa,EAAiBb,CAAK,IACzDA,EAAM,SAAS,SAAegB,EAAYhB,CAAK,IAC/CA,EAAM,SAAS,UAAgBD,EAAaC,CAAK,IAC9CmB,EAAWnB,CAAK;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/apple/parse.ts","../src/comicInfo/manga.ts","../src/comicInfo/parse.ts","../src/kobo/parse.ts","../src/utils/tokenizeXmlSpaceSeparatedList.ts","../src/opf/spineItemrefProperties.ts","../src/opf/parse.ts","../src/apple/resolve.ts","../src/utils/normalizeGtin.ts","../src/utils/normalizeIsbn.ts","../src/comicInfo/resolve.ts","../src/kobo/resolve.ts","../src/utils/parseW3cDtfDate.ts","../src/opf/resolve.ts","../src/resolve.ts"],"sourcesContent":["import type { XmlElement } from \"xmldoc\"\nimport { XmlDocument } from \"xmldoc\"\n\nexport const APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME =\n \"com.apple.ibooks.display-options.xml\"\n\nexport type AppleDisplayOption = {\n readonly name?: string\n readonly value: string\n}\n\nexport type AppleMetadata = {\n readonly kind: \"apple\"\n readonly displayOptions?: {\n readonly platform?: {\n readonly options: ReadonlyArray<AppleDisplayOption>\n }\n }\n}\n\nconst platformOptionsFromElement = (\n platform: XmlElement,\n): ReadonlyArray<AppleDisplayOption> =>\n platform.childrenNamed(\"option\").map((option) => ({\n name: option.attr?.name,\n value: option.val,\n }))\n\nexport const parseAppleDisplayOptionsXml = (xml: string): AppleMetadata => {\n const doc = new XmlDocument(xml)\n const root = doc.name?.toLowerCase()\n\n if (root !== \"display_options\") {\n return { kind: \"apple\" }\n }\n\n const platformEl = doc.childNamed(\"platform\")\n\n return {\n kind: \"apple\",\n displayOptions: {\n ...(platformEl !== undefined\n ? { platform: { options: platformOptionsFromElement(platformEl) } }\n : {}),\n },\n }\n}\n","/**\n * Allowed `Manga` element values (ComicInfo 2.0 `Manga` simpleType).\n *\n * @see https://anansi-project.github.io/docs/comicinfo/documentation#manga\n */\nexport const COMIC_INFO_MANGA_VALUES = [\n \"Unknown\",\n \"No\",\n \"Yes\",\n \"YesAndRightToLeft\",\n] as const\n\nexport type ComicInfoManga = (typeof COMIC_INFO_MANGA_VALUES)[number]\n\nexport const isComicInfoManga = (value: string): value is ComicInfoManga => {\n for (const v of COMIC_INFO_MANGA_VALUES) {\n if (v === value) return true\n }\n return false\n}\n","import type { XmlElement } from \"xmldoc\"\nimport { XmlDocument } from \"xmldoc\"\nimport type { ComicInfoManga } from \"./manga\"\n\n/** Canonical top-level filename; real archives may use any casing. */\nexport const COMIC_INFO_FILENAME = \"ComicInfo.xml\"\n\n/**\n * Parsed `ComicInfo.xml` root: one optional string property per child element,\n * using the same names as in the file (e.g. `Title`, `GTIN`, `LanguageISO`).\n * Nested blocks such as `Pages` are skipped. Other simple child elements are\n * still copied onto this object under their tag name.\n *\n * @see https://anansi-project.github.io/docs/comicinfo/intro\n * @see https://github.com/anansi-project/comicinfo/blob/main/drafts/v2.1/ComicInfo.xsd for schema\n */\nexport interface ComicInfo {\n readonly kind: \"comicInfo\"\n AgeRating?: string\n AlternateCount?: string\n AlternateNumber?: string\n AlternateSeries?: string\n BlackAndWhite?: string\n Characters?: string\n Colorist?: string\n CommunityRating?: string\n Count?: string\n CoverArtist?: string\n Day?: string\n Editor?: string\n Format?: string\n Genre?: string\n GTIN?: string\n Imprint?: string\n Inker?: string\n LanguageISO?: string\n Letterer?: string\n Locations?: string\n MainCharacterOrTeam?: string\n /** Schema literals per {@link ComicInfoManga}; files may still use other strings. */\n Manga?: ComicInfoManga | (string & {})\n Month?: string\n Notes?: string\n Number?: string\n PageCount?: string\n Penciller?: string\n Publisher?: string\n Review?: string\n ScanInformation?: string\n Series?: string\n SeriesGroup?: string\n StoryArc?: string\n StoryArcNumber?: string\n Summary?: string\n Tags?: string\n Teams?: string\n Title?: string\n Translator?: string\n Volume?: string\n Web?: string\n Writer?: string\n Year?: string\n [tag: string]: string | undefined\n}\n\nconst SKIP_ELEMENT_CHILDREN = new Set([\"Pages\", \"ComicInfo\"])\n\nconst hasNestedElement = (el: XmlElement) =>\n el.children.some((c) => c.type === \"element\")\n\nconst trimmedText = (el: XmlElement): string | undefined => {\n const t = el.val.trim()\n return t.length > 0 ? t : undefined\n}\n\n/**\n * Parse a raw `ComicInfo.xml` body. Each direct child element with plain text\n * becomes a property named after that tag. Malformed XML throws; the parser\n * error is attached as `cause`.\n */\nexport const parseComicInfo = (xml: string): ComicInfo => {\n let doc: XmlDocument\n try {\n doc = new XmlDocument(xml)\n } catch (cause) {\n const message = cause instanceof Error ? cause.message : String(cause)\n throw new Error(`${COMIC_INFO_FILENAME} is malformed: ${message}`, {\n cause,\n })\n }\n\n const fields: Record<string, string> = {}\n\n doc.eachChild((child) => {\n if (child.type !== \"element\") return\n if (SKIP_ELEMENT_CHILDREN.has(child.name)) return\n if (hasNestedElement(child)) return\n\n const text = trimmedText(child)\n if (text === undefined) return\n if (fields[child.name] !== undefined) return\n\n fields[child.name] = text\n })\n\n // `as ComicInfo`: TS cannot infer that spreading `Record<string, string>` into `{ kind }` satisfies the named optional fields plus `[tag: string]: string | undefined` on `ComicInfo`.\n return { kind: \"comicInfo\", ...fields } as ComicInfo\n}\n","import { XmlDocument } from \"xmldoc\"\n\nexport const KOBO_DISPLAY_OPTIONS_FILENAME = \"com.kobobooks.display-options.xml\"\n\n/**\n * Normalized fields from Kobo-specific XML sidecars. Grows as new Kobo\n * document kinds are supported; absent keys mean not present or unknown.\n */\nexport type KoboMetadata = {\n readonly kind: \"kobo\"\n renditionLayout?: `reflowable` | `pre-paginated`\n}\n\nconst parseKoboDisplayOptionsDocument = (\n doc: XmlDocument,\n): { renditionLayout?: \"pre-paginated\" } => {\n const platform = doc.childNamed(\"platform\")\n if (!platform) return {}\n\n for (const option of platform.childrenNamed(\"option\")) {\n if (option.attr?.name !== \"fixed-layout\") continue\n if (option.val.trim().toLowerCase() === \"true\") {\n return { renditionLayout: \"pre-paginated\" }\n }\n return {}\n }\n\n return {}\n}\n\n/**\n * Parse a Kobo-related XML document. Unsupported or unrecognized roots\n * yield an empty object. Malformed XML throws from the underlying parser.\n */\nexport const parseKoboXml = (xml: string): KoboMetadata => {\n const doc = new XmlDocument(xml)\n const root = doc.name?.toLowerCase()\n\n if (root === \"display_options\") {\n return { kind: \"kobo\", ...parseKoboDisplayOptionsDocument(doc) }\n }\n\n return { kind: \"kobo\" }\n}\n","/**\n * EPUB/XML space-separated token lists (e.g. `properties` on `item` / `itemref`).\n * Trims the raw string, splits on ASCII whitespace, drops empty segments.\n */\nexport const tokenizeXmlSpaceSeparatedList = (\n raw: string | undefined,\n): readonly string[] => {\n if (raw === undefined || raw.trim().length === 0) {\n return []\n }\n\n return raw\n .trim()\n .split(/\\s+/)\n .filter((t) => t.length > 0)\n}\n","import { tokenizeXmlSpaceSeparatedList } from \"../utils/tokenizeXmlSpaceSeparatedList\"\n\nexport type OpfItemrefLayoutHints = {\n readonly renditionLayout?: `reflowable` | `pre-paginated`\n readonly pageSpreadLeft?: true\n readonly pageSpreadRight?: true\n}\n\n/**\n * EPUB `itemref` `properties` attribute (space-separated tokens).\n *\n * @see https://www.w3.org/TR/epub/#attrdef-properties\n */\nexport const layoutHintsFromItemrefProperties = (\n properties: string | undefined,\n): OpfItemrefLayoutHints => {\n const tokens = tokenizeXmlSpaceSeparatedList(properties)\n if (tokens.length === 0) {\n return {}\n }\n\n let renditionLayout: `reflowable` | `pre-paginated` | undefined\n if (tokens.includes(`rendition:layout-reflowable`)) {\n renditionLayout = `reflowable`\n }\n if (tokens.includes(`rendition:layout-pre-paginated`)) {\n renditionLayout = `pre-paginated`\n }\n\n return {\n ...(renditionLayout !== undefined ? { renditionLayout } : {}),\n ...(tokens.includes(`page-spread-left`)\n ? { pageSpreadLeft: true as const }\n : {}),\n ...(tokens.includes(`page-spread-right`)\n ? { pageSpreadRight: true as const }\n : {}),\n }\n}\n","import type { XmlElement, XmlNodeBase } from \"xmldoc\"\nimport { XmlDocument } from \"xmldoc\"\nimport { tokenizeXmlSpaceSeparatedList } from \"../utils/tokenizeXmlSpaceSeparatedList\"\nimport { layoutHintsFromItemrefProperties } from \"./spineItemrefProperties\"\n\nexport type OpfSpineManifestItem = {\n readonly id: string\n readonly href: string\n readonly mediaType?: string\n readonly properties?: string\n}\n\nexport type OpfIdentifier = {\n readonly value: string\n readonly scheme?: string\n}\n\nexport type OpfSpineRow = {\n readonly idref: string\n readonly id: string\n readonly href: string\n readonly mediaType?: string\n readonly properties?: string\n readonly renditionLayout?: `reflowable` | `pre-paginated`\n readonly pageSpreadLeft?: true\n readonly pageSpreadRight?: true\n}\n\nexport type OpfGuideReference = {\n readonly href: string\n readonly title: string\n readonly type: string\n}\n\nconst elementLocalName = (name: string): string =>\n name.includes(\":\") ? name.slice(name.lastIndexOf(\":\") + 1) : name\n\nconst localNameEq = (elementName: string, wantLocal: string): boolean =>\n elementLocalName(elementName).toLowerCase() === wantLocal.toLowerCase()\n\nconst isXmlElement = (node: XmlNodeBase): node is XmlElement =>\n node.type === \"element\"\n\nconst childNamedLocal = (\n parent: XmlElement,\n localName: string,\n): XmlElement | undefined => {\n for (const node of parent.children) {\n if (!isXmlElement(node)) continue\n if (localNameEq(node.name, localName)) return node\n }\n return undefined\n}\n\nconst childrenNamedLocal = (\n parent: XmlElement,\n localName: string,\n): XmlElement[] => {\n const out: XmlElement[] = []\n for (const node of parent.children) {\n if (!isXmlElement(node)) continue\n if (localNameEq(node.name, localName)) out.push(node)\n }\n return out\n}\n\nconst identifiersFromMetadata = (metadataEl: XmlElement): OpfIdentifier[] => {\n const identifiers: OpfIdentifier[] = []\n\n metadataEl.eachChild((child) => {\n if (elementLocalName(child.name).toLowerCase() !== \"identifier\") return\n\n const value = child.val.trim()\n if (value.length === 0) return\n\n const scheme =\n child.attr[\"opf:scheme\"] ?? child.attr[\"opf:Scheme\"] ?? child.attr.scheme\n const schemeTrimmed = scheme?.trim()\n\n identifiers.push({\n value,\n ...(schemeTrimmed !== undefined && schemeTrimmed.length > 0\n ? { scheme: schemeTrimmed }\n : {}),\n })\n })\n\n return identifiers\n}\n\nconst firstTextByLocalName = (\n metadataEl: XmlElement,\n localName: string,\n): string | undefined => {\n let found: string | undefined\n metadataEl.eachChild((child) => {\n if (found !== undefined) return\n if (elementLocalName(child.name).toLowerCase() !== localName.toLowerCase())\n return\n const t = child.val.trim()\n if (t.length > 0) found = t\n })\n return found\n}\n\nconst textsByLocalName = (\n metadataEl: XmlElement,\n localName: string,\n): string[] => {\n const out: string[] = []\n metadataEl.eachChild((child) => {\n if (elementLocalName(child.name).toLowerCase() !== localName.toLowerCase())\n return\n const t = child.val.trim()\n if (t.length > 0) out.push(t)\n })\n return out\n}\n\nconst coverContentIdFromMetadata = (\n metadataEl: XmlElement,\n): string | undefined => {\n let coverId: string | undefined\n metadataEl.eachChild((child) => {\n if (coverId !== undefined) return\n if (elementLocalName(child.name).toLowerCase() !== \"meta\") return\n if (child.attr.name?.toLowerCase() !== \"cover\") return\n const content = child.attr.content?.trim()\n if (content !== undefined && content.length > 0) coverId = content\n })\n return coverId\n}\n\n/**\n * EPUB cover image inside the manifest. Resolution order, matching\n * what the spec lays out and what the bulk of EPUB producers in the\n * wild rely on:\n *\n * 1. EPUB 3 — the manifest item carrying the `cover-image` token in\n * its `properties` attribute (§ D.6.1).\n * 2. EPUB 2 — `<meta name=\"cover\" content=\"ID\"/>` in `metadata`,\n * resolved to the manifest item with that `id`.\n * 3. Last-resort fallback — any image manifest item whose `id`\n * contains the substring `cover` (case-insensitive); covers the\n * long tail of producers that emit neither the EPUB 3 property\n * nor the EPUB 2 meta.\n *\n * Each step requires the candidate manifest item to advertise an\n * `image/*` media type so non-image artefacts named `cover` (XHTML\n * cover pages, NCX entries) don't slip through.\n */\nconst coverHrefFromManifestAndMetadata = ({\n manifestItems,\n metadataEl,\n}: {\n manifestItems: ReadonlyArray<OpfSpineManifestItem>\n metadataEl: XmlElement | undefined\n}): string | undefined => {\n const isImage = (item: OpfSpineManifestItem): boolean =>\n item.mediaType?.toLowerCase().includes(\"image/\") === true\n\n const byCoverImageProperty = manifestItems.find((item) => {\n if (!isImage(item)) return false\n return tokenizeXmlSpaceSeparatedList(item.properties).includes(\n \"cover-image\",\n )\n })\n if (byCoverImageProperty !== undefined) return byCoverImageProperty.href\n\n if (metadataEl !== undefined) {\n const coverContentId = coverContentIdFromMetadata(metadataEl)\n if (coverContentId !== undefined) {\n const match = manifestItems.find(\n (item) => item.id === coverContentId && isImage(item),\n )\n if (match !== undefined) return match.href\n }\n }\n\n return manifestItems.find(\n (item) => item.id.toLowerCase().includes(\"cover\") && isImage(item),\n )?.href\n}\n\nconst metaValByProperty = (\n metadataEl: XmlElement,\n property: string,\n): string | undefined => {\n const meta = childrenNamedLocal(metadataEl, \"meta\").find(\n (m) => m.attr.property === property,\n )\n const raw = meta?.val\n if (raw === undefined || raw.trim().length === 0) return undefined\n return raw\n}\n\nconst guideFromPackage = (doc: XmlElement): OpfGuideReference[] => {\n const guideEl = childNamedLocal(doc, \"guide\")\n if (guideEl === undefined) return []\n\n const refs: OpfGuideReference[] = []\n\n for (const ref of childrenNamedLocal(guideEl, \"reference\")) {\n const href = ref.attr.href?.trim()\n if (href === undefined || href.length === 0) continue\n refs.push({\n href,\n title: ref.attr.title?.trim() ?? ``,\n type: ref.attr.type?.trim() ?? ``,\n })\n }\n\n return refs\n}\n\nconst manifestItemFromXmlElement = (\n item: XmlElement,\n): OpfSpineManifestItem | undefined => {\n const id = item.attr.id\n const href = item.attr.href\n if (id === undefined || id.length === 0) return undefined\n if (href === undefined || href.length === 0) return undefined\n\n const mediaType = item.attr[\"media-type\"]\n const properties = item.attr.properties?.trim()\n return {\n id,\n href,\n ...(mediaType !== undefined && mediaType.length > 0 ? { mediaType } : {}),\n ...(properties !== undefined && properties.length > 0\n ? { properties }\n : {}),\n }\n}\n\nconst manifestItemsAndById = (\n manifestEl: XmlElement,\n): {\n items: OpfSpineManifestItem[]\n byId: Map<string, OpfSpineManifestItem>\n} => {\n const items: OpfSpineManifestItem[] = []\n const byId = new Map<string, OpfSpineManifestItem>()\n\n for (const el of childrenNamedLocal(manifestEl, \"item\")) {\n const parsed = manifestItemFromXmlElement(el)\n if (parsed === undefined) continue\n items.push(parsed)\n byId.set(parsed.id, parsed)\n }\n\n return { items, byId }\n}\n\nconst spineRowsFromByIdAndSpine = (\n byId: Map<string, OpfSpineManifestItem>,\n spineEl: XmlElement,\n): OpfSpineRow[] => {\n const rows: OpfSpineRow[] = []\n\n for (const itemref of childrenNamedLocal(spineEl, \"itemref\")) {\n const idref = itemref.attr.idref\n if (idref === undefined || idref.trim().length === 0) continue\n\n const manifestItem = byId.get(idref)\n if (manifestItem === undefined) continue\n\n const hints = layoutHintsFromItemrefProperties(itemref.attr.properties)\n\n rows.push({\n idref,\n id: manifestItem.id,\n href: manifestItem.href,\n ...(manifestItem.mediaType !== undefined\n ? { mediaType: manifestItem.mediaType }\n : {}),\n ...(manifestItem.properties !== undefined\n ? { properties: manifestItem.properties }\n : {}),\n ...(hints.renditionLayout !== undefined\n ? { renditionLayout: hints.renditionLayout }\n : {}),\n ...(hints.pageSpreadLeft !== undefined\n ? { pageSpreadLeft: hints.pageSpreadLeft }\n : {}),\n ...(hints.pageSpreadRight !== undefined\n ? { pageSpreadRight: hints.pageSpreadRight }\n : {}),\n })\n }\n\n return rows\n}\n\nexport type OpfMetadata = {\n readonly kind: \"opf\"\n readonly manifestItems: ReadonlyArray<OpfSpineManifestItem>\n readonly spineRows: ReadonlyArray<OpfSpineRow>\n readonly spineTocIdref: string | undefined\n readonly identifiers: ReadonlyArray<OpfIdentifier>\n readonly title: string | undefined\n /** `dc:creator` values, in document order, trimmed; empty when none. */\n readonly creators: ReadonlyArray<string>\n /** First non-empty `dc:publisher`, trimmed. */\n readonly publisher: string | undefined\n /** First non-empty `dc:rights`, trimmed. */\n readonly rights: string | undefined\n /** `dc:language` values, in document order, trimmed; empty when none. */\n readonly languages: ReadonlyArray<string>\n /** `dc:subject` values, in document order, trimmed; empty when none. */\n readonly subjects: ReadonlyArray<string>\n /**\n * Raw `dc:date` value as authored. EPUB 3 requires W3CDTF (a profile\n * of ISO 8601), but real-world publishers also ship free text here,\n * so the value is exposed verbatim and consumers normalize as needed.\n */\n readonly date: string | undefined\n /**\n * Manifest-relative `href` of the cover image, when one can be\n * resolved from `cover-image` properties (EPUB 3), the EPUB 2\n * `<meta name=\"cover\">` convention, or an `id` that contains\n * `cover` on an image manifest item. The href is returned exactly\n * as it appears in the manifest — callers own folder-prefix\n * resolution against the OPF's location in the archive.\n */\n readonly coverHref: string | undefined\n readonly renditionLayoutMeta: string | undefined\n readonly renditionFlowMeta: string | undefined\n readonly renditionSpreadMeta: string | undefined\n readonly pageProgressionDirection: string | undefined\n readonly guide: ReadonlyArray<OpfGuideReference>\n}\n\n/**\n * Parses an EPUB package document (OPF) into structured metadata.\n *\n * Direct children of `package` (`metadata`, `manifest`, `spine`, `guide`) and\n * their structural children (`item`, `itemref`, `reference`, `meta`) are\n * matched by **local name** (ASCII case-insensitive), so prefixed tags such as\n * `opf:manifest` are supported the same as unprefixed `manifest`.\n *\n * Attribute names on `spine` / `itemref` are still read as emitted by xmldoc\n * (no QName normalization).\n */\nexport const parseOpf = (opfXml: string): OpfMetadata => {\n const doc = new XmlDocument(opfXml)\n const manifestEl = childNamedLocal(doc, \"manifest\")\n const spineEl = childNamedLocal(doc, \"spine\")\n const metadataEl = childNamedLocal(doc, \"metadata\")\n\n let manifestItems: OpfSpineManifestItem[] = []\n let spineRows: OpfSpineRow[] = []\n\n if (manifestEl !== undefined) {\n const { items, byId } = manifestItemsAndById(manifestEl)\n manifestItems = items\n if (spineEl !== undefined) {\n spineRows = spineRowsFromByIdAndSpine(byId, spineEl)\n }\n }\n\n const pageProgressionDirectionRaw =\n spineEl?.attr[\"page-progression-direction\"]\n const pageProgressionDirection =\n pageProgressionDirectionRaw !== undefined &&\n pageProgressionDirectionRaw.trim().length > 0\n ? pageProgressionDirectionRaw\n : undefined\n\n const spineTocRaw = spineEl?.attr.toc\n const spineTocIdref =\n spineTocRaw !== undefined && spineTocRaw.trim().length > 0\n ? spineTocRaw.trim()\n : undefined\n\n let title: string | undefined\n let publisher: string | undefined\n let rights: string | undefined\n let date: string | undefined\n let creators: string[] = []\n let languages: string[] = []\n let subjects: string[] = []\n let renditionLayoutMeta: string | undefined\n let renditionFlowMeta: string | undefined\n let renditionSpreadMeta: string | undefined\n const identifiers: OpfIdentifier[] = []\n\n if (metadataEl !== undefined) {\n title = firstTextByLocalName(metadataEl, \"title\")\n publisher = firstTextByLocalName(metadataEl, \"publisher\")\n rights = firstTextByLocalName(metadataEl, \"rights\")\n date = firstTextByLocalName(metadataEl, \"date\")\n creators = textsByLocalName(metadataEl, \"creator\")\n languages = textsByLocalName(metadataEl, \"language\")\n subjects = textsByLocalName(metadataEl, \"subject\")\n renditionLayoutMeta = metaValByProperty(metadataEl, \"rendition:layout\")\n renditionFlowMeta = metaValByProperty(metadataEl, \"rendition:flow\")\n renditionSpreadMeta = metaValByProperty(metadataEl, \"rendition:spread\")\n identifiers.push(...identifiersFromMetadata(metadataEl))\n }\n\n const coverHref = coverHrefFromManifestAndMetadata({\n manifestItems,\n metadataEl,\n })\n\n const guide = guideFromPackage(doc)\n\n return {\n kind: \"opf\",\n manifestItems,\n spineRows,\n spineTocIdref,\n identifiers,\n title,\n creators,\n publisher,\n rights,\n languages,\n subjects,\n date,\n coverHref,\n renditionLayoutMeta,\n renditionFlowMeta,\n renditionSpreadMeta,\n pageProgressionDirection,\n guide,\n }\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport type { AppleMetadata } from \"./parse\"\n\nexport const resolveApple = (input: AppleMetadata): ArchiveResolveResult => {\n const fixedLayout = input.displayOptions?.platform?.options?.find(\n (o) => o.name === \"fixed-layout\",\n )?.value\n\n const renditionLayout =\n fixedLayout?.trim().toLowerCase() === \"true\" ? \"pre-paginated\" : undefined\n\n return {\n gtin: undefined,\n isbn: undefined,\n readingDirection: undefined,\n renditionLayout,\n title: undefined,\n authors: undefined,\n publisher: undefined,\n rights: undefined,\n languages: undefined,\n date: undefined,\n subjects: undefined,\n }\n}\n","const GTIN_LENGTHS = new Set([8, 12, 13, 14])\n\n/**\n * Normalize a raw GTIN / EAN / UPC string to digits only when the length\n * matches a GS1 GTIN family size (8, 12, 13, or 14). Does not verify check digits.\n */\nexport const normalizeGtin = (\n raw: string | number | undefined | null,\n): string | undefined => {\n if (raw === undefined || raw === null) return undefined\n\n const digits = String(raw).replace(/\\D/g, \"\")\n if (digits.length === 0 || !GTIN_LENGTHS.has(digits.length)) return undefined\n\n return digits\n}\n","const ISBN_CANDIDATE_PATTERN = /(?:97[89])?\\d{9}[\\dXx]/\n\n/**\n * Normalize a raw ISBN-ish string into a canonical 10- or 13-character\n * form, or `undefined` when no recognisable ISBN can be recovered.\n *\n * - Strips the common `urn:isbn:` / `isbn:` prefixes.\n * - Drops everything that isn't a digit or `X`.\n * - Validates the resulting length (10 or 13).\n * - Falls back to a lax regex scan so publishers that stuff free text\n * around the number still yield a usable value.\n */\nexport const normalizeIsbn = (\n raw: string | number | undefined | null,\n): string | undefined => {\n if (raw === undefined || raw === null) return undefined\n\n const stripped = String(raw)\n .trim()\n .replace(/^urn:isbn:/i, \"\")\n .replace(/^isbn[:\\s-]*/i, \"\")\n\n const digitsOnly = stripped.replace(/[^0-9Xx]/g, \"\")\n\n if (digitsOnly.length === 10 || digitsOnly.length === 13) {\n return digitsOnly.toUpperCase()\n }\n\n const match = stripped.match(ISBN_CANDIDATE_PATTERN)\n if (match) return match[0].toUpperCase()\n\n return undefined\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport { normalizeGtin } from \"../utils/normalizeGtin\"\nimport { normalizeIsbn } from \"../utils/normalizeIsbn\"\nimport type { ComicInfo } from \"./parse\"\n\nconst readingDirection = (info: ComicInfo): \"ltr\" | \"rtl\" =>\n info.Manga === \"YesAndRightToLeft\" ? \"rtl\" : \"ltr\"\n\nconst trimToUndefined = (raw: string | undefined): string | undefined => {\n if (raw === undefined) return undefined\n const trimmed = raw.trim()\n return trimmed.length > 0 ? trimmed : undefined\n}\n\n/**\n * Split a comma-separated ComicInfo value into its individual tokens.\n * `Writer`, `Genre`, and `Tags` all follow the same de-facto convention:\n * tokens separated by `,`, with whitespace trimmed and empty tokens\n * dropped (real-world files leave trailing commas around).\n */\nconst splitCommaList = (raw: string | undefined): string[] => {\n if (raw === undefined) return []\n return raw\n .split(\",\")\n .map((token) => token.trim())\n .filter((token) => token.length > 0)\n}\n\nconst parseNonNegativeInt = (raw: string | undefined): number | undefined => {\n const trimmed = trimToUndefined(raw)\n if (trimmed === undefined) return undefined\n if (!/^\\d+$/.test(trimmed)) return undefined\n const n = Number.parseInt(trimmed, 10)\n return Number.isFinite(n) ? n : undefined\n}\n\nconst dateFromYearMonthDay = (\n info: ComicInfo,\n):\n | {\n year?: number\n month?: number\n day?: number\n }\n | undefined => {\n const year = parseNonNegativeInt(info.Year)\n const month = parseNonNegativeInt(info.Month)\n const day = parseNonNegativeInt(info.Day)\n\n if (year === undefined && month === undefined && day === undefined) {\n return undefined\n }\n\n return {\n ...(year !== undefined ? { year } : {}),\n ...(month !== undefined ? { month } : {}),\n ...(day !== undefined ? { day } : {}),\n }\n}\n\nexport const resolveComicInfo = (info: ComicInfo): ArchiveResolveResult => {\n const raw = info.GTIN\n const languageIso = trimToUndefined(info.LanguageISO)\n const authors = splitCommaList(info.Writer)\n const subjects = [...splitCommaList(info.Genre), ...splitCommaList(info.Tags)]\n\n return {\n gtin: normalizeGtin(raw),\n isbn: normalizeIsbn(raw),\n readingDirection: readingDirection(info),\n renditionLayout: undefined,\n title: trimToUndefined(info.Title),\n authors: authors.length > 0 ? authors : undefined,\n publisher: trimToUndefined(info.Publisher),\n rights: undefined,\n languages: languageIso !== undefined ? [languageIso] : undefined,\n date: dateFromYearMonthDay(info),\n subjects: subjects.length > 0 ? subjects : undefined,\n }\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport type { KoboMetadata } from \"./parse\"\n\nexport const resolveKobo = (input: KoboMetadata): ArchiveResolveResult => ({\n gtin: undefined,\n isbn: undefined,\n readingDirection: undefined,\n renditionLayout: input.renditionLayout,\n title: undefined,\n authors: undefined,\n publisher: undefined,\n rights: undefined,\n languages: undefined,\n date: undefined,\n subjects: undefined,\n})\n","/**\n * Extract the calendar components of a W3CDTF literal — the\n * date subset of ISO 8601 that EPUB 3.3 § 5.5.3.2.4 mandates for\n * `dc:date`. Accepted forms: `YYYY`, `YYYY-MM`, `YYYY-MM-DD`, and\n * any of the above followed by a `Thh:mm[:ss[.s]][TZD]` time\n * portion that we ignore.\n *\n * Components are returned as plain integers (`month` is 1-12,\n * `day` is 1-31), independent of the host timezone — using\n * `Date.parse` would shift `2011-01-01` by a day in negative-offset\n * locales, which is the exact bug this regex-based approach exists\n * to avoid. Returns `undefined` when the input doesn't even match\n * a leading 4-digit year so consumers can fall back without\n * branching on partial shapes.\n */\nexport const parseW3cDtfDate = (\n raw: string | undefined,\n):\n | {\n year?: number\n month?: number\n day?: number\n }\n | undefined => {\n if (raw === undefined) return undefined\n\n const match = raw.trim().match(/^(\\d{4})(?:-(\\d{2})(?:-(\\d{2}))?)?/)\n if (match === null) return undefined\n\n const [, yearRaw, monthRaw, dayRaw] = match\n\n return {\n ...(yearRaw !== undefined ? { year: Number.parseInt(yearRaw, 10) } : {}),\n ...(monthRaw !== undefined ? { month: Number.parseInt(monthRaw, 10) } : {}),\n ...(dayRaw !== undefined ? { day: Number.parseInt(dayRaw, 10) } : {}),\n }\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport { normalizeGtin } from \"../utils/normalizeGtin\"\nimport { normalizeIsbn } from \"../utils/normalizeIsbn\"\nimport { parseW3cDtfDate } from \"../utils/parseW3cDtfDate\"\nimport type { OpfIdentifier, OpfMetadata } from \"./parse\"\n\nconst rawIdentifierValueForIsbn = (\n identifiers: ReadonlyArray<OpfIdentifier>,\n): string | undefined => {\n for (const i of identifiers) {\n if (i.scheme !== undefined && i.scheme.trim().toLowerCase() === \"isbn\") {\n if (normalizeIsbn(i.value) !== undefined) return i.value\n }\n }\n\n for (const i of identifiers) {\n if (normalizeIsbn(i.value) !== undefined) return i.value\n }\n\n return undefined\n}\n\nexport const resolveOpf = (input: OpfMetadata): ArchiveResolveResult => {\n const ppd = input.pageProgressionDirection?.trim().toLowerCase()\n const readingDirection = ppd === \"ltr\" || ppd === \"rtl\" ? ppd : undefined\n\n const rl = input.renditionLayoutMeta?.trim().toLowerCase()\n const renditionLayout =\n rl === \"reflowable\" || rl === \"pre-paginated\" ? rl : undefined\n\n const raw = rawIdentifierValueForIsbn(input.identifiers)\n\n return {\n gtin: normalizeGtin(raw),\n isbn: normalizeIsbn(raw),\n readingDirection,\n renditionLayout,\n title: input.title,\n authors: input.creators.length > 0 ? [...input.creators] : undefined,\n publisher: input.publisher,\n rights: input.rights,\n languages: input.languages.length > 0 ? [...input.languages] : undefined,\n date: parseW3cDtfDate(input.date),\n subjects: input.subjects.length > 0 ? [...input.subjects] : undefined,\n }\n}\n","import type { AppleMetadata } from \"./apple/parse\"\nimport { resolveApple } from \"./apple/resolve\"\nimport type { ComicInfo } from \"./comicInfo/parse\"\nimport { resolveComicInfo } from \"./comicInfo/resolve\"\nimport type { KoboMetadata } from \"./kobo/parse\"\nimport { resolveKobo } from \"./kobo/resolve\"\nimport type { OpfMetadata } from \"./opf/parse\"\nimport { resolveOpf } from \"./opf/resolve\"\nimport type { ArchiveResolveResult } from \"./types/archiveResolve\"\n\nexport type ResolvedArchiveInput =\n | ComicInfo\n | KoboMetadata\n | AppleMetadata\n | OpfMetadata\n\nexport const resolveArchiveMetadata = (\n input: ResolvedArchiveInput,\n): ArchiveResolveResult => {\n if (input.kind === \"comicInfo\") return resolveComicInfo(input)\n if (input.kind === \"kobo\") return resolveKobo(input)\n if (input.kind === \"apple\") return resolveApple(input)\n return resolveOpf(input)\n}\n"],"names":["APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME","platformOptionsFromElement","platform","option","parseAppleDisplayOptionsXml","xml","doc","XmlDocument","platformEl","COMIC_INFO_MANGA_VALUES","isComicInfoManga","value","v","COMIC_INFO_FILENAME","SKIP_ELEMENT_CHILDREN","hasNestedElement","el","c","trimmedText","parseComicInfo","cause","message","fields","child","text","KOBO_DISPLAY_OPTIONS_FILENAME","parseKoboDisplayOptionsDocument","parseKoboXml","tokenizeXmlSpaceSeparatedList","raw","layoutHintsFromItemrefProperties","properties","tokens","renditionLayout","elementLocalName","name","localNameEq","elementName","wantLocal","isXmlElement","node","childNamedLocal","parent","localName","childrenNamedLocal","out","identifiersFromMetadata","metadataEl","identifiers","schemeTrimmed","firstTextByLocalName","found","t","textsByLocalName","coverContentIdFromMetadata","coverId","content","coverHrefFromManifestAndMetadata","manifestItems","isImage","item","byCoverImageProperty","coverContentId","match","metaValByProperty","property","m","guideFromPackage","guideEl","refs","ref","href","manifestItemFromXmlElement","id","mediaType","manifestItemsAndById","manifestEl","items","byId","parsed","spineRowsFromByIdAndSpine","spineEl","rows","itemref","idref","manifestItem","hints","parseOpf","opfXml","spineRows","pageProgressionDirectionRaw","pageProgressionDirection","spineTocRaw","spineTocIdref","title","publisher","rights","date","creators","languages","subjects","renditionLayoutMeta","renditionFlowMeta","renditionSpreadMeta","coverHref","guide","resolveApple","input","o","GTIN_LENGTHS","normalizeGtin","digits","ISBN_CANDIDATE_PATTERN","normalizeIsbn","stripped","digitsOnly","readingDirection","info","trimToUndefined","trimmed","splitCommaList","token","parseNonNegativeInt","n","dateFromYearMonthDay","year","month","day","resolveComicInfo","languageIso","authors","resolveKobo","parseW3cDtfDate","yearRaw","monthRaw","dayRaw","rawIdentifierValueForIsbn","i","resolveOpf","ppd","rl","resolveArchiveMetadata"],"mappings":";AAGO,MAAMA,KACX,wCAgBIC,IAA6B,CACjCC,MAEAA,EAAS,cAAc,QAAQ,EAAE,IAAI,CAACC,OAAY;AAAA,EAChD,MAAMA,EAAO,MAAM;AAAA,EACnB,OAAOA,EAAO;AAChB,EAAE,GAESC,KAA8B,CAACC,MAA+B;AACzE,QAAMC,IAAM,IAAIC,EAAYF,CAAG;AAG/B,MAFaC,EAAI,MAAM,YAAA,MAEV;AACX,WAAO,EAAE,MAAM,QAAA;AAGjB,QAAME,IAAaF,EAAI,WAAW,UAAU;AAE5C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,gBAAgB;AAAA,MACd,GAAIE,MAAe,SACf,EAAE,UAAU,EAAE,SAASP,EAA2BO,CAAU,EAAA,MAC5D,CAAA;AAAA,IAAC;AAAA,EACP;AAEJ,GCzCaC,IAA0B;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAIaC,KAAmB,CAACC,MAA2C;AAC1E,aAAWC,KAAKH;AACd,QAAIG,MAAMD,EAAO,QAAO;AAE1B,SAAO;AACT,GCdaE,IAAsB,iBA4D7B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AAQ,SAASA,MAAQ,QAAQA,IAAM,QAE1DC,IAAKjC,EAAM,qBAAqB,KAAA,EAAO,YAAA,GACvC1E,IACJ2G,MAAO,gBAAgBA,MAAO,kBAAkBA,IAAK,QAEjD/G,IAAM2G,GAA0B7B,EAAM,WAAW;AAEvD,SAAO;AAAA,IACL,MAAMG,EAAcjF,CAAG;AAAA,IACvB,MAAMoF,EAAcpF,CAAG;AAAA,IACvB,kBAAAuF;AAAA,IACA,iBAAAnF;AAAA,IACA,OAAO0E,EAAM;AAAA,IACb,SAASA,EAAM,SAAS,SAAS,IAAI,CAAC,GAAGA,EAAM,QAAQ,IAAI;AAAA,IAC3D,WAAWA,EAAM;AAAA,IACjB,QAAQA,EAAM;AAAA,IACd,WAAWA,EAAM,UAAU,SAAS,IAAI,CAAC,GAAGA,EAAM,SAAS,IAAI;AAAA,IAC/D,MAAMyB,GAAgBzB,EAAM,IAAI;AAAA,IAChC,UAAUA,EAAM,SAAS,SAAS,IAAI,CAAC,GAAGA,EAAM,QAAQ,IAAI;AAAA,EAAA;AAEhE,GC7BakC,KAAyB,CACpClC,MAEIA,EAAM,SAAS,cAAoBqB,GAAiBrB,CAAK,IACzDA,EAAM,SAAS,SAAewB,GAAYxB,CAAK,IAC/CA,EAAM,SAAS,UAAgBD,GAAaC,CAAK,IAC9C+B,GAAW/B,CAAK;"}
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(s,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("xmldoc")):typeof define=="function"&&define.amd?define(["exports","xmldoc"],d):(s=typeof globalThis<"u"?globalThis:s||self,d(s["prose-reader-archive-parser"]={},s.xmldoc))})(this,(function(s,d){"use strict";const B="com.apple.ibooks.display-options.xml",K=e=>e.childrenNamed("option").map(t=>({name:t.attr?.name,value:t.val})),Y=e=>{const t=new d.XmlDocument(e);if(t.name?.toLowerCase()!=="display_options")return{kind:"apple"};const n=t.childNamed("platform");return{kind:"apple",displayOptions:{...n!==void 0?{platform:{options:K(n)}}:{}}}},N=["Unknown","No","Yes","YesAndRightToLeft"],G=e=>{for(const t of N)if(t===e)return!0;return!1},S="ComicInfo.xml",z=new Set(["Pages","ComicInfo"]),U=e=>e.children.some(t=>t.type==="element"),H=e=>{const t=e.val.trim();return t.length>0?t:void 0},V=e=>{let t;try{t=new d.XmlDocument(e)}catch(n){const r=n instanceof Error?n.message:String(n);throw new Error(`${S} is malformed: ${r}`,{cause:n})}const o={};return t.eachChild(n=>{if(n.type!=="element"||z.has(n.name)||U(n))return;const r=H(n);r!==void 0&&o[n.name]===void 0&&(o[n.name]=r)}),{kind:"comicInfo",...o}},x="com.kobobooks.display-options.xml",W=e=>{const t=e.childNamed("platform");if(!t)return{};for(const o of t.childrenNamed("option"))if(o.attr?.name==="fixed-layout")return o.val.trim().toLowerCase()==="true"?{renditionLayout:"pre-paginated"}:{};return{}},$=e=>{const t=new d.XmlDocument(e);return t.name?.toLowerCase()==="display_options"?{kind:"kobo",...W(t)}:{kind:"kobo"}},v=e=>e===void 0||e.trim().length===0?[]:e.trim().split(/\s+/).filter(t=>t.length>0),q=e=>{const t=v(e);if(t.length===0)return{};let o;return t.includes("rendition:layout-reflowable")&&(o="reflowable"),t.includes("rendition:layout-pre-paginated")&&(o="pre-paginated"),{...o!==void 0?{renditionLayout:o}:{},...t.includes("page-spread-left")?{pageSpreadLeft:!0}:{},...t.includes("page-spread-right")?{pageSpreadRight:!0}:{}}},c=e=>e.includes(":")?e.slice(e.lastIndexOf(":")+1):e,O=(e,t)=>c(e).toLowerCase()===t.toLowerCase(),w=e=>e.type==="element",u=(e,t)=>{for(const o of e.children)if(w(o)&&O(o.name,t))return o},m=(e,t)=>{const o=[];for(const n of e.children)w(n)&&O(n.name,t)&&o.push(n);return o},J=e=>{const t=[];return e.eachChild(o=>{if(c(o.name).toLowerCase()!=="identifier")return;const n=o.val.trim();if(n.length===0)return;const i=(o.attr["opf:scheme"]??o.attr["opf:Scheme"]??o.attr.scheme)?.trim();t.push({value:n,...i!==void 0&&i.length>0?{scheme:i}:{}})}),t},f=(e,t)=>{let o;return e.eachChild(n=>{if(o!==void 0||c(n.name).toLowerCase()!==t.toLowerCase())return;const r=n.val.trim();r.length>0&&(o=r)}),o},g=(e,t)=>{const o=[];return e.eachChild(n=>{if(c(n.name).toLowerCase()!==t.toLowerCase())return;const r=n.val.trim();r.length>0&&o.push(r)}),o},Q=e=>{let t;return e.eachChild(o=>{if(t!==void 0||c(o.name).toLowerCase()!=="meta"||o.attr.name?.toLowerCase()!=="cover")return;const n=o.attr.content?.trim();n!==void 0&&n.length>0&&(t=n)}),t},Z=({manifestItems:e,metadataEl:t})=>{const o=r=>r.mediaType?.toLowerCase().includes("image/")===!0,n=e.find(r=>o(r)?v(r.properties).includes("cover-image"):!1);if(n!==void 0)return n.href;if(t!==void 0){const r=Q(t);if(r!==void 0){const i=e.find(a=>a.id===r&&o(a));if(i!==void 0)return i.href}}return e.find(r=>r.id.toLowerCase().includes("cover")&&o(r))?.href},h=(e,t)=>{const n=m(e,"meta").find(r=>r.attr.property===t)?.val;if(!(n===void 0||n.trim().length===0))return n},ee=e=>{const t=u(e,"guide");if(t===void 0)return[];const o=[];for(const n of m(t,"reference")){const r=n.attr.href?.trim();r===void 0||r.length===0||o.push({href:r,title:n.attr.title?.trim()??"",type:n.attr.type?.trim()??""})}return o},te=e=>{const t=e.attr.id,o=e.attr.href;if(t===void 0||t.length===0||o===void 0||o.length===0)return;const n=e.attr["media-type"],r=e.attr.properties?.trim();return{id:t,href:o,...n!==void 0&&n.length>0?{mediaType:n}:{},...r!==void 0&&r.length>0?{properties:r}:{}}},oe=e=>{const t=[],o=new Map;for(const n of m(e,"item")){const r=te(n);r!==void 0&&(t.push(r),o.set(r.id,r))}return{items:t,byId:o}},ne=(e,t)=>{const o=[];for(const n of m(t,"itemref")){const r=n.attr.idref;if(r===void 0||r.trim().length===0)continue;const i=e.get(r);if(i===void 0)continue;const a=q(n.attr.properties);o.push({idref:r,id:i.id,href:i.href,...i.mediaType!==void 0?{mediaType:i.mediaType}:{},...i.properties!==void 0?{properties:i.properties}:{},...a.renditionLayout!==void 0?{renditionLayout:a.renditionLayout}:{},...a.pageSpreadLeft!==void 0?{pageSpreadLeft:a.pageSpreadLeft}:{},...a.pageSpreadRight!==void 0?{pageSpreadRight:a.pageSpreadRight}:{}})}return o},re=e=>{const t=new d.XmlDocument(e),o=u(t,"manifest"),n=u(t,"spine"),r=u(t,"metadata");let i=[],a=[];if(o!==void 0){const{items:Le,byId:Ie}=oe(o);i=Le,n!==void 0&&(a=ne(Ie,n))}const b=n?.attr["page-progression-direction"],ve=b!==void 0&&b.trim().length>0?b:void 0,C=n?.attr.toc,ge=C!==void 0&&C.trim().length>0?C.trim():void 0;let A,_,D,M,T=[],P=[],F=[],k,R,X;const j=[];r!==void 0&&(A=f(r,"title"),_=f(r,"publisher"),D=f(r,"rights"),M=f(r,"date"),T=g(r,"creator"),P=g(r,"language"),F=g(r,"subject"),k=h(r,"rendition:layout"),R=h(r,"rendition:flow"),X=h(r,"rendition:spread"),j.push(...J(r)));const he=Z({manifestItems:i,metadataEl:r}),ye=ee(t);return{kind:"opf",manifestItems:i,spineRows:a,spineTocIdref:ge,identifiers:j,title:A,creators:T,publisher:_,rights:D,languages:P,subjects:F,date:M,coverHref:he,renditionLayoutMeta:k,renditionFlowMeta:R,renditionSpreadMeta:X,pageProgressionDirection:ve,guide:ye}},ie=e=>({gtin:void 0,isbn:void 0,readingDirection:void 0,renditionLayout:e.displayOptions?.platform?.options?.find(n=>n.name==="fixed-layout")?.value?.trim().toLowerCase()==="true"?"pre-paginated":void 0,title:void 0,authors:void 0,publisher:void 0,rights:void 0,languages:void 0,date:void 0,subjects:void 0}),se=new Set([8,12,13,14]),y=e=>{if(e==null)return;const t=String(e).replace(/\D/g,"");if(!(t.length===0||!se.has(t.length)))return t},ae=/(?:97[89])?\d{9}[\dXx]/,l=e=>{if(e==null)return;const t=String(e).trim().replace(/^urn:isbn:/i,"").replace(/^isbn[:\s-]*/i,""),o=t.replace(/[^0-9Xx]/g,"");if(o.length===10||o.length===13)return o.toUpperCase();const n=t.match(ae);if(n)return n[0].toUpperCase()},de=e=>e.Manga==="YesAndRightToLeft"?"rtl":"ltr",p=e=>{if(e===void 0)return;const t=e.trim();return t.length>0?t:void 0},L=e=>e===void 0?[]:e.split(",").map(t=>t.trim()).filter(t=>t.length>0),I=e=>{const t=p(e);if(t===void 0||!/^\d+$/.test(t))return;const o=Number.parseInt(t,10);return Number.isFinite(o)?o:void 0},ce=e=>{const t=I(e.Year),o=I(e.Month),n=I(e.Day);if(!(t===void 0&&o===void 0&&n===void 0))return{...t!==void 0?{year:t}:{},...o!==void 0?{month:o}:{},...n!==void 0?{day:n}:{}}},le=e=>{const t=e.GTIN,o=p(e.LanguageISO),n=L(e.Writer),r=[...L(e.Genre),...L(e.Tags)];return{gtin:y(t),isbn:l(t),readingDirection:de(e),renditionLayout:void 0,title:p(e.Title),authors:n.length>0?n:void 0,publisher:p(e.Publisher),rights:void 0,languages:o!==void 0?[o]:void 0,date:ce(e),subjects:r.length>0?r:void 0}},ue=e=>({gtin:void 0,isbn:void 0,readingDirection:void 0,renditionLayout:e.renditionLayout,title:void 0,authors:void 0,publisher:void 0,rights:void 0,languages:void 0,date:void 0,subjects:void 0}),E=e=>{if(e===void 0)return;const t=e.trim().match(/^(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?/);if(t===null)return;const[,o,n,r]=t;return{...o!==void 0?{year:Number.parseInt(o,10)}:{},...n!==void 0?{month:Number.parseInt(n,10)}:{},...r!==void 0?{day:Number.parseInt(r,10)}:{}}},me=e=>{for(const t of e)if(t.scheme!==void 0&&t.scheme.trim().toLowerCase()==="isbn"&&l(t.value)!==void 0)return t.value;for(const t of e)if(l(t.value)!==void 0)return t.value},fe=e=>{const t=e.pageProgressionDirection?.trim().toLowerCase(),o=t==="ltr"||t==="rtl"?t:void 0,n=e.renditionLayoutMeta?.trim().toLowerCase(),r=n==="reflowable"||n==="pre-paginated"?n:void 0,i=me(e.identifiers);return{gtin:y(i),isbn:l(i),readingDirection:o,renditionLayout:r,title:e.title,authors:e.creators.length>0?[...e.creators]:void 0,publisher:e.publisher,rights:e.rights,languages:e.languages.length>0?[...e.languages]:void 0,date:E(e.date),subjects:e.subjects.length>0?[...e.subjects]:void 0}},pe=e=>e.kind==="comicInfo"?le(e):e.kind==="kobo"?ue(e):e.kind==="apple"?ie(e):fe(e);s.APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME=B,s.COMIC_INFO_FILENAME=S,s.COMIC_INFO_MANGA_VALUES=N,s.KOBO_DISPLAY_OPTIONS_FILENAME=x,s.isComicInfoManga=G,s.normalizeGtin=y,s.normalizeIsbn=l,s.parseAppleDisplayOptionsXml=Y,s.parseComicInfo=V,s.parseKoboXml=$,s.parseOpf=re,s.parseW3cDtfDate=E,s.resolveArchiveMetadata=pe,s.tokenizeXmlSpaceSeparatedList=v,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|
|
2
2
|
//# sourceMappingURL=index.umd.cjs.map
|
package/dist/index.umd.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.cjs","sources":["../src/apple/parse.ts","../src/comicInfo/manga.ts","../src/comicInfo/parse.ts","../src/kobo/parse.ts","../src/utils/tokenizeXmlSpaceSeparatedList.ts","../src/opf/spineItemrefProperties.ts","../src/opf/parse.ts","../src/apple/resolve.ts","../src/utils/normalizeGtin.ts","../src/utils/normalizeIsbn.ts","../src/comicInfo/resolve.ts","../src/kobo/resolve.ts","../src/opf/resolve.ts","../src/resolve.ts"],"sourcesContent":["import type { XmlElement } from \"xmldoc\"\nimport { XmlDocument } from \"xmldoc\"\n\nexport const APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME =\n \"com.apple.ibooks.display-options.xml\"\n\nexport type AppleDisplayOption = {\n readonly name?: string\n readonly value: string\n}\n\nexport type AppleMetadata = {\n readonly kind: \"apple\"\n readonly displayOptions?: {\n readonly platform?: {\n readonly options: ReadonlyArray<AppleDisplayOption>\n }\n }\n}\n\nconst platformOptionsFromElement = (\n platform: XmlElement,\n): ReadonlyArray<AppleDisplayOption> =>\n platform.childrenNamed(\"option\").map((option) => ({\n name: option.attr?.name,\n value: option.val,\n }))\n\nexport const parseAppleDisplayOptionsXml = (xml: string): AppleMetadata => {\n const doc = new XmlDocument(xml)\n const root = doc.name?.toLowerCase()\n\n if (root !== \"display_options\") {\n return { kind: \"apple\" }\n }\n\n const platformEl = doc.childNamed(\"platform\")\n\n return {\n kind: \"apple\",\n displayOptions: {\n ...(platformEl !== undefined\n ? { platform: { options: platformOptionsFromElement(platformEl) } }\n : {}),\n },\n }\n}\n","/**\n * Allowed `Manga` element values (ComicInfo 2.0 `Manga` simpleType).\n *\n * @see https://anansi-project.github.io/docs/comicinfo/documentation#manga\n */\nexport const COMIC_INFO_MANGA_VALUES = [\n \"Unknown\",\n \"No\",\n \"Yes\",\n \"YesAndRightToLeft\",\n] as const\n\nexport type ComicInfoManga = (typeof COMIC_INFO_MANGA_VALUES)[number]\n\nexport const isComicInfoManga = (value: string): value is ComicInfoManga => {\n for (const v of COMIC_INFO_MANGA_VALUES) {\n if (v === value) return true\n }\n return false\n}\n","import type { XmlElement } from \"xmldoc\"\nimport { XmlDocument } from \"xmldoc\"\nimport type { ComicInfoManga } from \"./manga\"\n\n/** Canonical top-level filename; real archives may use any casing. */\nexport const COMIC_INFO_FILENAME = \"ComicInfo.xml\"\n\n/**\n * Parsed `ComicInfo.xml` root: one optional string property per child element,\n * using the same names as in the file (e.g. `Title`, `GTIN`, `LanguageISO`).\n * Nested blocks such as `Pages` are skipped. Other simple child elements are\n * still copied onto this object under their tag name.\n *\n * @see https://anansi-project.github.io/docs/comicinfo/intro\n * @see https://github.com/anansi-project/comicinfo/blob/main/drafts/v2.1/ComicInfo.xsd for schema\n */\nexport interface ComicInfo {\n readonly kind: \"comicInfo\"\n AgeRating?: string\n AlternateCount?: string\n AlternateNumber?: string\n AlternateSeries?: string\n BlackAndWhite?: string\n Characters?: string\n Colorist?: string\n CommunityRating?: string\n Count?: string\n CoverArtist?: string\n Day?: string\n Editor?: string\n Format?: string\n Genre?: string\n GTIN?: string\n Imprint?: string\n Inker?: string\n LanguageISO?: string\n Letterer?: string\n Locations?: string\n MainCharacterOrTeam?: string\n /** Schema literals per {@link ComicInfoManga}; files may still use other strings. */\n Manga?: ComicInfoManga | (string & {})\n Month?: string\n Notes?: string\n Number?: string\n PageCount?: string\n Penciller?: string\n Publisher?: string\n Review?: string\n ScanInformation?: string\n Series?: string\n SeriesGroup?: string\n StoryArc?: string\n StoryArcNumber?: string\n Summary?: string\n Tags?: string\n Teams?: string\n Title?: string\n Translator?: string\n Volume?: string\n Web?: string\n Writer?: string\n Year?: string\n [tag: string]: string | undefined\n}\n\nconst SKIP_ELEMENT_CHILDREN = new Set([\"Pages\", \"ComicInfo\"])\n\nconst hasNestedElement = (el: XmlElement) =>\n el.children.some((c) => c.type === \"element\")\n\nconst trimmedText = (el: XmlElement): string | undefined => {\n const t = el.val.trim()\n return t.length > 0 ? t : undefined\n}\n\n/**\n * Parse a raw `ComicInfo.xml` body. Each direct child element with plain text\n * becomes a property named after that tag. Malformed XML throws; the parser\n * error is attached as `cause`.\n */\nexport const parseComicInfo = (xml: string): ComicInfo => {\n let doc: XmlDocument\n try {\n doc = new XmlDocument(xml)\n } catch (cause) {\n const message = cause instanceof Error ? cause.message : String(cause)\n throw new Error(`${COMIC_INFO_FILENAME} is malformed: ${message}`, {\n cause,\n })\n }\n\n const fields: Record<string, string> = {}\n\n doc.eachChild((child) => {\n if (child.type !== \"element\") return\n if (SKIP_ELEMENT_CHILDREN.has(child.name)) return\n if (hasNestedElement(child)) return\n\n const text = trimmedText(child)\n if (text === undefined) return\n if (fields[child.name] !== undefined) return\n\n fields[child.name] = text\n })\n\n // `as ComicInfo`: TS cannot infer that spreading `Record<string, string>` into `{ kind }` satisfies the named optional fields plus `[tag: string]: string | undefined` on `ComicInfo`.\n return { kind: \"comicInfo\", ...fields } as ComicInfo\n}\n","import { XmlDocument } from \"xmldoc\"\n\nexport const KOBO_DISPLAY_OPTIONS_FILENAME = \"com.kobobooks.display-options.xml\"\n\n/**\n * Normalized fields from Kobo-specific XML sidecars. Grows as new Kobo\n * document kinds are supported; absent keys mean not present or unknown.\n */\nexport type KoboMetadata = {\n readonly kind: \"kobo\"\n renditionLayout?: `reflowable` | `pre-paginated`\n}\n\nconst parseKoboDisplayOptionsDocument = (\n doc: XmlDocument,\n): { renditionLayout?: \"pre-paginated\" } => {\n const platform = doc.childNamed(\"platform\")\n if (!platform) return {}\n\n for (const option of platform.childrenNamed(\"option\")) {\n if (option.attr?.name !== \"fixed-layout\") continue\n if (option.val.trim().toLowerCase() === \"true\") {\n return { renditionLayout: \"pre-paginated\" }\n }\n return {}\n }\n\n return {}\n}\n\n/**\n * Parse a Kobo-related XML document. Unsupported or unrecognized roots\n * yield an empty object. Malformed XML throws from the underlying parser.\n */\nexport const parseKoboXml = (xml: string): KoboMetadata => {\n const doc = new XmlDocument(xml)\n const root = doc.name?.toLowerCase()\n\n if (root === \"display_options\") {\n return { kind: \"kobo\", ...parseKoboDisplayOptionsDocument(doc) }\n }\n\n return { kind: \"kobo\" }\n}\n","/**\n * EPUB/XML space-separated token lists (e.g. `properties` on `item` / `itemref`).\n * Trims the raw string, splits on ASCII whitespace, drops empty segments.\n */\nexport const tokenizeXmlSpaceSeparatedList = (\n raw: string | undefined,\n): readonly string[] => {\n if (raw === undefined || raw.trim().length === 0) {\n return []\n }\n\n return raw\n .trim()\n .split(/\\s+/)\n .filter((t) => t.length > 0)\n}\n","import { tokenizeXmlSpaceSeparatedList } from \"../utils/tokenizeXmlSpaceSeparatedList\"\n\nexport type OpfItemrefLayoutHints = {\n readonly renditionLayout?: `reflowable` | `pre-paginated`\n readonly pageSpreadLeft?: true\n readonly pageSpreadRight?: true\n}\n\n/**\n * EPUB `itemref` `properties` attribute (space-separated tokens).\n *\n * @see https://www.w3.org/TR/epub/#attrdef-properties\n */\nexport const layoutHintsFromItemrefProperties = (\n properties: string | undefined,\n): OpfItemrefLayoutHints => {\n const tokens = tokenizeXmlSpaceSeparatedList(properties)\n if (tokens.length === 0) {\n return {}\n }\n\n let renditionLayout: `reflowable` | `pre-paginated` | undefined\n if (tokens.includes(`rendition:layout-reflowable`)) {\n renditionLayout = `reflowable`\n }\n if (tokens.includes(`rendition:layout-pre-paginated`)) {\n renditionLayout = `pre-paginated`\n }\n\n return {\n ...(renditionLayout !== undefined ? { renditionLayout } : {}),\n ...(tokens.includes(`page-spread-left`)\n ? { pageSpreadLeft: true as const }\n : {}),\n ...(tokens.includes(`page-spread-right`)\n ? { pageSpreadRight: true as const }\n : {}),\n }\n}\n","import type { XmlElement, XmlNodeBase } from \"xmldoc\"\nimport { XmlDocument } from \"xmldoc\"\nimport { layoutHintsFromItemrefProperties } from \"./spineItemrefProperties\"\n\nexport type OpfSpineManifestItem = {\n readonly id: string\n readonly href: string\n readonly mediaType?: string\n readonly properties?: string\n}\n\nexport type OpfIdentifier = {\n readonly value: string\n readonly scheme?: string\n}\n\nexport type OpfSpineRow = {\n readonly idref: string\n readonly id: string\n readonly href: string\n readonly mediaType?: string\n readonly properties?: string\n readonly renditionLayout?: `reflowable` | `pre-paginated`\n readonly pageSpreadLeft?: true\n readonly pageSpreadRight?: true\n}\n\nexport type OpfGuideReference = {\n readonly href: string\n readonly title: string\n readonly type: string\n}\n\nconst elementLocalName = (name: string): string =>\n name.includes(\":\") ? name.slice(name.lastIndexOf(\":\") + 1) : name\n\nconst localNameEq = (elementName: string, wantLocal: string): boolean =>\n elementLocalName(elementName).toLowerCase() === wantLocal.toLowerCase()\n\nconst isXmlElement = (node: XmlNodeBase): node is XmlElement =>\n node.type === \"element\"\n\nconst childNamedLocal = (\n parent: XmlElement,\n localName: string,\n): XmlElement | undefined => {\n for (const node of parent.children) {\n if (!isXmlElement(node)) continue\n if (localNameEq(node.name, localName)) return node\n }\n return undefined\n}\n\nconst childrenNamedLocal = (\n parent: XmlElement,\n localName: string,\n): XmlElement[] => {\n const out: XmlElement[] = []\n for (const node of parent.children) {\n if (!isXmlElement(node)) continue\n if (localNameEq(node.name, localName)) out.push(node)\n }\n return out\n}\n\nconst identifiersFromMetadata = (metadataEl: XmlElement): OpfIdentifier[] => {\n const identifiers: OpfIdentifier[] = []\n\n metadataEl.eachChild((child) => {\n if (elementLocalName(child.name).toLowerCase() !== \"identifier\") return\n\n const value = child.val.trim()\n if (value.length === 0) return\n\n const scheme =\n child.attr[\"opf:scheme\"] ?? child.attr[\"opf:Scheme\"] ?? child.attr.scheme\n const schemeTrimmed = scheme?.trim()\n\n identifiers.push({\n value,\n ...(schemeTrimmed !== undefined && schemeTrimmed.length > 0\n ? { scheme: schemeTrimmed }\n : {}),\n })\n })\n\n return identifiers\n}\n\nconst titleFromMetadata = (metadataEl: XmlElement): string | undefined => {\n let found: string | undefined\n metadataEl.eachChild((child) => {\n if (found !== undefined) return\n if (elementLocalName(child.name).toLowerCase() !== \"title\") return\n const t = child.val.trim()\n if (t.length > 0) found = t\n })\n return found\n}\n\nconst metaValByProperty = (\n metadataEl: XmlElement,\n property: string,\n): string | undefined => {\n const meta = childrenNamedLocal(metadataEl, \"meta\").find(\n (m) => m.attr.property === property,\n )\n const raw = meta?.val\n if (raw === undefined || raw.trim().length === 0) return undefined\n return raw\n}\n\nconst guideFromPackage = (doc: XmlElement): OpfGuideReference[] => {\n const guideEl = childNamedLocal(doc, \"guide\")\n if (guideEl === undefined) return []\n\n const refs: OpfGuideReference[] = []\n\n for (const ref of childrenNamedLocal(guideEl, \"reference\")) {\n const href = ref.attr.href?.trim()\n if (href === undefined || href.length === 0) continue\n refs.push({\n href,\n title: ref.attr.title?.trim() ?? ``,\n type: ref.attr.type?.trim() ?? ``,\n })\n }\n\n return refs\n}\n\nconst manifestItemFromXmlElement = (\n item: XmlElement,\n): OpfSpineManifestItem | undefined => {\n const id = item.attr.id\n const href = item.attr.href\n if (id === undefined || id.length === 0) return undefined\n if (href === undefined || href.length === 0) return undefined\n\n const mediaType = item.attr[\"media-type\"]\n const properties = item.attr.properties?.trim()\n return {\n id,\n href,\n ...(mediaType !== undefined && mediaType.length > 0 ? { mediaType } : {}),\n ...(properties !== undefined && properties.length > 0\n ? { properties }\n : {}),\n }\n}\n\nconst manifestItemsAndById = (\n manifestEl: XmlElement,\n): {\n items: OpfSpineManifestItem[]\n byId: Map<string, OpfSpineManifestItem>\n} => {\n const items: OpfSpineManifestItem[] = []\n const byId = new Map<string, OpfSpineManifestItem>()\n\n for (const el of childrenNamedLocal(manifestEl, \"item\")) {\n const parsed = manifestItemFromXmlElement(el)\n if (parsed === undefined) continue\n items.push(parsed)\n byId.set(parsed.id, parsed)\n }\n\n return { items, byId }\n}\n\nconst spineRowsFromByIdAndSpine = (\n byId: Map<string, OpfSpineManifestItem>,\n spineEl: XmlElement,\n): OpfSpineRow[] => {\n const rows: OpfSpineRow[] = []\n\n for (const itemref of childrenNamedLocal(spineEl, \"itemref\")) {\n const idref = itemref.attr.idref\n if (idref === undefined || idref.trim().length === 0) continue\n\n const manifestItem = byId.get(idref)\n if (manifestItem === undefined) continue\n\n const hints = layoutHintsFromItemrefProperties(itemref.attr.properties)\n\n rows.push({\n idref,\n id: manifestItem.id,\n href: manifestItem.href,\n ...(manifestItem.mediaType !== undefined\n ? { mediaType: manifestItem.mediaType }\n : {}),\n ...(manifestItem.properties !== undefined\n ? { properties: manifestItem.properties }\n : {}),\n ...(hints.renditionLayout !== undefined\n ? { renditionLayout: hints.renditionLayout }\n : {}),\n ...(hints.pageSpreadLeft !== undefined\n ? { pageSpreadLeft: hints.pageSpreadLeft }\n : {}),\n ...(hints.pageSpreadRight !== undefined\n ? { pageSpreadRight: hints.pageSpreadRight }\n : {}),\n })\n }\n\n return rows\n}\n\nexport type OpfMetadata = {\n readonly kind: \"opf\"\n readonly manifestItems: ReadonlyArray<OpfSpineManifestItem>\n readonly spineRows: ReadonlyArray<OpfSpineRow>\n readonly spineTocIdref: string | undefined\n readonly identifiers: ReadonlyArray<OpfIdentifier>\n readonly title: string | undefined\n readonly renditionLayoutMeta: string | undefined\n readonly renditionFlowMeta: string | undefined\n readonly renditionSpreadMeta: string | undefined\n readonly pageProgressionDirection: string | undefined\n readonly guide: ReadonlyArray<OpfGuideReference>\n}\n\n/**\n * Parses an EPUB package document (OPF) into structured metadata.\n *\n * Direct children of `package` (`metadata`, `manifest`, `spine`, `guide`) and\n * their structural children (`item`, `itemref`, `reference`, `meta`) are\n * matched by **local name** (ASCII case-insensitive), so prefixed tags such as\n * `opf:manifest` are supported the same as unprefixed `manifest`.\n *\n * Attribute names on `spine` / `itemref` are still read as emitted by xmldoc\n * (no QName normalization).\n */\nexport const parseOpf = (opfXml: string): OpfMetadata => {\n const doc = new XmlDocument(opfXml)\n const manifestEl = childNamedLocal(doc, \"manifest\")\n const spineEl = childNamedLocal(doc, \"spine\")\n const metadataEl = childNamedLocal(doc, \"metadata\")\n\n let manifestItems: OpfSpineManifestItem[] = []\n let spineRows: OpfSpineRow[] = []\n\n if (manifestEl !== undefined) {\n const { items, byId } = manifestItemsAndById(manifestEl)\n manifestItems = items\n if (spineEl !== undefined) {\n spineRows = spineRowsFromByIdAndSpine(byId, spineEl)\n }\n }\n\n const pageProgressionDirectionRaw =\n spineEl?.attr[\"page-progression-direction\"]\n const pageProgressionDirection =\n pageProgressionDirectionRaw !== undefined &&\n pageProgressionDirectionRaw.trim().length > 0\n ? pageProgressionDirectionRaw\n : undefined\n\n const spineTocRaw = spineEl?.attr.toc\n const spineTocIdref =\n spineTocRaw !== undefined && spineTocRaw.trim().length > 0\n ? spineTocRaw.trim()\n : undefined\n\n let title: string | undefined\n let renditionLayoutMeta: string | undefined\n let renditionFlowMeta: string | undefined\n let renditionSpreadMeta: string | undefined\n const identifiers: OpfIdentifier[] = []\n\n if (metadataEl !== undefined) {\n title = titleFromMetadata(metadataEl)\n renditionLayoutMeta = metaValByProperty(metadataEl, \"rendition:layout\")\n renditionFlowMeta = metaValByProperty(metadataEl, \"rendition:flow\")\n renditionSpreadMeta = metaValByProperty(metadataEl, \"rendition:spread\")\n identifiers.push(...identifiersFromMetadata(metadataEl))\n }\n\n const guide = guideFromPackage(doc)\n\n return {\n kind: \"opf\",\n manifestItems,\n spineRows,\n spineTocIdref,\n identifiers,\n title,\n renditionLayoutMeta,\n renditionFlowMeta,\n renditionSpreadMeta,\n pageProgressionDirection,\n guide,\n }\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport type { AppleMetadata } from \"./parse\"\n\nexport const resolveApple = (input: AppleMetadata): ArchiveResolveResult => {\n const fixedLayout = input.displayOptions?.platform?.options?.find(\n (o) => o.name === \"fixed-layout\",\n )?.value\n\n if (fixedLayout === undefined) return {}\n\n const renditionLayout =\n fixedLayout.trim().toLowerCase() === \"true\"\n ? (\"pre-paginated\" as const)\n : undefined\n\n return renditionLayout !== undefined ? { renditionLayout } : {}\n}\n","const GTIN_LENGTHS = new Set([8, 12, 13, 14])\n\n/**\n * Normalize a raw GTIN / EAN / UPC string to digits only when the length\n * matches a GS1 GTIN family size (8, 12, 13, or 14). Does not verify check digits.\n */\nexport const normalizeGtin = (\n raw: string | number | undefined | null,\n): string | undefined => {\n if (raw === undefined || raw === null) return undefined\n\n const digits = String(raw).replace(/\\D/g, \"\")\n if (digits.length === 0 || !GTIN_LENGTHS.has(digits.length)) return undefined\n\n return digits\n}\n","const ISBN_CANDIDATE_PATTERN = /(?:97[89])?\\d{9}[\\dXx]/\n\n/**\n * Normalize a raw ISBN-ish string into a canonical 10- or 13-character\n * form, or `undefined` when no recognisable ISBN can be recovered.\n *\n * - Strips the common `urn:isbn:` / `isbn:` prefixes.\n * - Drops everything that isn't a digit or `X`.\n * - Validates the resulting length (10 or 13).\n * - Falls back to a lax regex scan so publishers that stuff free text\n * around the number still yield a usable value.\n */\nexport const normalizeIsbn = (\n raw: string | number | undefined | null,\n): string | undefined => {\n if (raw === undefined || raw === null) return undefined\n\n const stripped = String(raw)\n .trim()\n .replace(/^urn:isbn:/i, \"\")\n .replace(/^isbn[:\\s-]*/i, \"\")\n\n const digitsOnly = stripped.replace(/[^0-9Xx]/g, \"\")\n\n if (digitsOnly.length === 10 || digitsOnly.length === 13) {\n return digitsOnly.toUpperCase()\n }\n\n const match = stripped.match(ISBN_CANDIDATE_PATTERN)\n if (match) return match[0].toUpperCase()\n\n return undefined\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport { normalizeGtin } from \"../utils/normalizeGtin\"\nimport { normalizeIsbn } from \"../utils/normalizeIsbn\"\nimport type { ComicInfo } from \"./parse\"\n\nconst readingDirection = (info: ComicInfo): \"ltr\" | \"rtl\" =>\n info.Manga === \"YesAndRightToLeft\" ? \"rtl\" : \"ltr\"\n\nexport const resolveComicInfo = (info: ComicInfo): ArchiveResolveResult => {\n const raw = info.GTIN\n const gtin = normalizeGtin(raw)\n const isbn = normalizeIsbn(raw)\n return {\n ...(gtin !== undefined ? { gtin } : {}),\n ...(isbn !== undefined ? { isbn } : {}),\n readingDirection: readingDirection(info),\n }\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport type { KoboMetadata } from \"./parse\"\n\nexport const resolveKobo = (input: KoboMetadata): ArchiveResolveResult => {\n const { renditionLayout } = input\n return renditionLayout !== undefined ? { renditionLayout } : {}\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport { normalizeGtin } from \"../utils/normalizeGtin\"\nimport { normalizeIsbn } from \"../utils/normalizeIsbn\"\nimport type { OpfIdentifier, OpfMetadata } from \"./parse\"\n\nconst rawIdentifierValueForIsbn = (\n identifiers: ReadonlyArray<OpfIdentifier>,\n): string | undefined => {\n for (const i of identifiers) {\n if (i.scheme !== undefined && i.scheme.trim().toLowerCase() === \"isbn\") {\n if (normalizeIsbn(i.value) !== undefined) return i.value\n }\n }\n\n for (const i of identifiers) {\n if (normalizeIsbn(i.value) !== undefined) return i.value\n }\n\n return undefined\n}\n\nexport const resolveOpf = (input: OpfMetadata): ArchiveResolveResult => {\n const ppd = input.pageProgressionDirection?.trim().toLowerCase()\n const readingDirection = ppd === \"ltr\" || ppd === \"rtl\" ? ppd : undefined\n\n const rl = input.renditionLayoutMeta?.trim().toLowerCase()\n const renditionLayout =\n rl === \"reflowable\" || rl === \"pre-paginated\" ? rl : undefined\n\n const raw = rawIdentifierValueForIsbn(input.identifiers)\n const isbn = normalizeIsbn(raw)\n const gtin = normalizeGtin(raw)\n\n return {\n ...(gtin !== undefined ? { gtin } : {}),\n ...(isbn !== undefined ? { isbn } : {}),\n ...(readingDirection !== undefined ? { readingDirection } : {}),\n ...(renditionLayout !== undefined ? { renditionLayout } : {}),\n }\n}\n","import type { AppleMetadata } from \"./apple/parse\"\nimport { resolveApple } from \"./apple/resolve\"\nimport type { ComicInfo } from \"./comicInfo/parse\"\nimport { resolveComicInfo } from \"./comicInfo/resolve\"\nimport type { KoboMetadata } from \"./kobo/parse\"\nimport { resolveKobo } from \"./kobo/resolve\"\nimport type { OpfMetadata } from \"./opf/parse\"\nimport { resolveOpf } from \"./opf/resolve\"\nimport type { ArchiveResolveResult } from \"./types/archiveResolve\"\n\nexport type ResolvedArchiveInput =\n | ComicInfo\n | KoboMetadata\n | AppleMetadata\n | OpfMetadata\n\nexport const resolveArchiveMetadata = (\n input: ResolvedArchiveInput,\n): ArchiveResolveResult => {\n if (input.kind === \"comicInfo\") return resolveComicInfo(input)\n if (input.kind === \"kobo\") return resolveKobo(input)\n if (input.kind === \"apple\") return resolveApple(input)\n return resolveOpf(input)\n}\n"],"names":["APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME","platformOptionsFromElement","platform","option","parseAppleDisplayOptionsXml","xml","doc","XmlDocument","platformEl","COMIC_INFO_MANGA_VALUES","isComicInfoManga","value","v","COMIC_INFO_FILENAME","SKIP_ELEMENT_CHILDREN","hasNestedElement","el","c","trimmedText","t","parseComicInfo","cause","message","fields","child","text","KOBO_DISPLAY_OPTIONS_FILENAME","parseKoboDisplayOptionsDocument","parseKoboXml","tokenizeXmlSpaceSeparatedList","raw","layoutHintsFromItemrefProperties","properties","tokens","renditionLayout","elementLocalName","name","localNameEq","elementName","wantLocal","isXmlElement","node","childNamedLocal","parent","localName","childrenNamedLocal","out","identifiersFromMetadata","metadataEl","identifiers","schemeTrimmed","titleFromMetadata","found","metaValByProperty","property","m","guideFromPackage","guideEl","refs","ref","href","manifestItemFromXmlElement","item","id","mediaType","manifestItemsAndById","manifestEl","items","byId","parsed","spineRowsFromByIdAndSpine","spineEl","rows","itemref","idref","manifestItem","hints","parseOpf","opfXml","manifestItems","spineRows","pageProgressionDirectionRaw","pageProgressionDirection","spineTocRaw","spineTocIdref","title","renditionLayoutMeta","renditionFlowMeta","renditionSpreadMeta","guide","resolveApple","input","fixedLayout","o","GTIN_LENGTHS","normalizeGtin","digits","ISBN_CANDIDATE_PATTERN","normalizeIsbn","stripped","digitsOnly","match","readingDirection","info","resolveComicInfo","gtin","isbn","resolveKobo","rawIdentifierValueForIsbn","i","resolveOpf","ppd","rl","resolveArchiveMetadata"],"mappings":"6RAGO,MAAMA,EACX,uCAgBIC,EACJC,GAEAA,EAAS,cAAc,QAAQ,EAAE,IAAKC,IAAY,CAChD,KAAMA,EAAO,MAAM,KACnB,MAAOA,EAAO,GAChB,EAAE,EAESC,EAA+BC,GAA+B,CACzE,MAAMC,EAAM,IAAIC,EAAAA,YAAYF,CAAG,EAG/B,GAFaC,EAAI,MAAM,YAAA,IAEV,kBACX,MAAO,CAAE,KAAM,OAAA,EAGjB,MAAME,EAAaF,EAAI,WAAW,UAAU,EAE5C,MAAO,CACL,KAAM,QACN,eAAgB,CACd,GAAIE,IAAe,OACf,CAAE,SAAU,CAAE,QAASP,EAA2BO,CAAU,CAAA,GAC5D,CAAA,CAAC,CACP,CAEJ,ECzCaC,EAA0B,CACrC,UACA,KACA,MACA,mBACF,EAIaC,EAAoBC,GAA2C,CAC1E,UAAWC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AM,OAAS,OAAegB,EAAYhB,CAAK,EAC/CA,EAAM,OAAS,QAAgBD,EAAaC,CAAK,EAC9CmB,EAAWnB,CAAK"}
|
|
1
|
+
{"version":3,"file":"index.umd.cjs","sources":["../src/apple/parse.ts","../src/comicInfo/manga.ts","../src/comicInfo/parse.ts","../src/kobo/parse.ts","../src/utils/tokenizeXmlSpaceSeparatedList.ts","../src/opf/spineItemrefProperties.ts","../src/opf/parse.ts","../src/apple/resolve.ts","../src/utils/normalizeGtin.ts","../src/utils/normalizeIsbn.ts","../src/comicInfo/resolve.ts","../src/kobo/resolve.ts","../src/utils/parseW3cDtfDate.ts","../src/opf/resolve.ts","../src/resolve.ts"],"sourcesContent":["import type { XmlElement } from \"xmldoc\"\nimport { XmlDocument } from \"xmldoc\"\n\nexport const APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME =\n \"com.apple.ibooks.display-options.xml\"\n\nexport type AppleDisplayOption = {\n readonly name?: string\n readonly value: string\n}\n\nexport type AppleMetadata = {\n readonly kind: \"apple\"\n readonly displayOptions?: {\n readonly platform?: {\n readonly options: ReadonlyArray<AppleDisplayOption>\n }\n }\n}\n\nconst platformOptionsFromElement = (\n platform: XmlElement,\n): ReadonlyArray<AppleDisplayOption> =>\n platform.childrenNamed(\"option\").map((option) => ({\n name: option.attr?.name,\n value: option.val,\n }))\n\nexport const parseAppleDisplayOptionsXml = (xml: string): AppleMetadata => {\n const doc = new XmlDocument(xml)\n const root = doc.name?.toLowerCase()\n\n if (root !== \"display_options\") {\n return { kind: \"apple\" }\n }\n\n const platformEl = doc.childNamed(\"platform\")\n\n return {\n kind: \"apple\",\n displayOptions: {\n ...(platformEl !== undefined\n ? { platform: { options: platformOptionsFromElement(platformEl) } }\n : {}),\n },\n }\n}\n","/**\n * Allowed `Manga` element values (ComicInfo 2.0 `Manga` simpleType).\n *\n * @see https://anansi-project.github.io/docs/comicinfo/documentation#manga\n */\nexport const COMIC_INFO_MANGA_VALUES = [\n \"Unknown\",\n \"No\",\n \"Yes\",\n \"YesAndRightToLeft\",\n] as const\n\nexport type ComicInfoManga = (typeof COMIC_INFO_MANGA_VALUES)[number]\n\nexport const isComicInfoManga = (value: string): value is ComicInfoManga => {\n for (const v of COMIC_INFO_MANGA_VALUES) {\n if (v === value) return true\n }\n return false\n}\n","import type { XmlElement } from \"xmldoc\"\nimport { XmlDocument } from \"xmldoc\"\nimport type { ComicInfoManga } from \"./manga\"\n\n/** Canonical top-level filename; real archives may use any casing. */\nexport const COMIC_INFO_FILENAME = \"ComicInfo.xml\"\n\n/**\n * Parsed `ComicInfo.xml` root: one optional string property per child element,\n * using the same names as in the file (e.g. `Title`, `GTIN`, `LanguageISO`).\n * Nested blocks such as `Pages` are skipped. Other simple child elements are\n * still copied onto this object under their tag name.\n *\n * @see https://anansi-project.github.io/docs/comicinfo/intro\n * @see https://github.com/anansi-project/comicinfo/blob/main/drafts/v2.1/ComicInfo.xsd for schema\n */\nexport interface ComicInfo {\n readonly kind: \"comicInfo\"\n AgeRating?: string\n AlternateCount?: string\n AlternateNumber?: string\n AlternateSeries?: string\n BlackAndWhite?: string\n Characters?: string\n Colorist?: string\n CommunityRating?: string\n Count?: string\n CoverArtist?: string\n Day?: string\n Editor?: string\n Format?: string\n Genre?: string\n GTIN?: string\n Imprint?: string\n Inker?: string\n LanguageISO?: string\n Letterer?: string\n Locations?: string\n MainCharacterOrTeam?: string\n /** Schema literals per {@link ComicInfoManga}; files may still use other strings. */\n Manga?: ComicInfoManga | (string & {})\n Month?: string\n Notes?: string\n Number?: string\n PageCount?: string\n Penciller?: string\n Publisher?: string\n Review?: string\n ScanInformation?: string\n Series?: string\n SeriesGroup?: string\n StoryArc?: string\n StoryArcNumber?: string\n Summary?: string\n Tags?: string\n Teams?: string\n Title?: string\n Translator?: string\n Volume?: string\n Web?: string\n Writer?: string\n Year?: string\n [tag: string]: string | undefined\n}\n\nconst SKIP_ELEMENT_CHILDREN = new Set([\"Pages\", \"ComicInfo\"])\n\nconst hasNestedElement = (el: XmlElement) =>\n el.children.some((c) => c.type === \"element\")\n\nconst trimmedText = (el: XmlElement): string | undefined => {\n const t = el.val.trim()\n return t.length > 0 ? t : undefined\n}\n\n/**\n * Parse a raw `ComicInfo.xml` body. Each direct child element with plain text\n * becomes a property named after that tag. Malformed XML throws; the parser\n * error is attached as `cause`.\n */\nexport const parseComicInfo = (xml: string): ComicInfo => {\n let doc: XmlDocument\n try {\n doc = new XmlDocument(xml)\n } catch (cause) {\n const message = cause instanceof Error ? cause.message : String(cause)\n throw new Error(`${COMIC_INFO_FILENAME} is malformed: ${message}`, {\n cause,\n })\n }\n\n const fields: Record<string, string> = {}\n\n doc.eachChild((child) => {\n if (child.type !== \"element\") return\n if (SKIP_ELEMENT_CHILDREN.has(child.name)) return\n if (hasNestedElement(child)) return\n\n const text = trimmedText(child)\n if (text === undefined) return\n if (fields[child.name] !== undefined) return\n\n fields[child.name] = text\n })\n\n // `as ComicInfo`: TS cannot infer that spreading `Record<string, string>` into `{ kind }` satisfies the named optional fields plus `[tag: string]: string | undefined` on `ComicInfo`.\n return { kind: \"comicInfo\", ...fields } as ComicInfo\n}\n","import { XmlDocument } from \"xmldoc\"\n\nexport const KOBO_DISPLAY_OPTIONS_FILENAME = \"com.kobobooks.display-options.xml\"\n\n/**\n * Normalized fields from Kobo-specific XML sidecars. Grows as new Kobo\n * document kinds are supported; absent keys mean not present or unknown.\n */\nexport type KoboMetadata = {\n readonly kind: \"kobo\"\n renditionLayout?: `reflowable` | `pre-paginated`\n}\n\nconst parseKoboDisplayOptionsDocument = (\n doc: XmlDocument,\n): { renditionLayout?: \"pre-paginated\" } => {\n const platform = doc.childNamed(\"platform\")\n if (!platform) return {}\n\n for (const option of platform.childrenNamed(\"option\")) {\n if (option.attr?.name !== \"fixed-layout\") continue\n if (option.val.trim().toLowerCase() === \"true\") {\n return { renditionLayout: \"pre-paginated\" }\n }\n return {}\n }\n\n return {}\n}\n\n/**\n * Parse a Kobo-related XML document. Unsupported or unrecognized roots\n * yield an empty object. Malformed XML throws from the underlying parser.\n */\nexport const parseKoboXml = (xml: string): KoboMetadata => {\n const doc = new XmlDocument(xml)\n const root = doc.name?.toLowerCase()\n\n if (root === \"display_options\") {\n return { kind: \"kobo\", ...parseKoboDisplayOptionsDocument(doc) }\n }\n\n return { kind: \"kobo\" }\n}\n","/**\n * EPUB/XML space-separated token lists (e.g. `properties` on `item` / `itemref`).\n * Trims the raw string, splits on ASCII whitespace, drops empty segments.\n */\nexport const tokenizeXmlSpaceSeparatedList = (\n raw: string | undefined,\n): readonly string[] => {\n if (raw === undefined || raw.trim().length === 0) {\n return []\n }\n\n return raw\n .trim()\n .split(/\\s+/)\n .filter((t) => t.length > 0)\n}\n","import { tokenizeXmlSpaceSeparatedList } from \"../utils/tokenizeXmlSpaceSeparatedList\"\n\nexport type OpfItemrefLayoutHints = {\n readonly renditionLayout?: `reflowable` | `pre-paginated`\n readonly pageSpreadLeft?: true\n readonly pageSpreadRight?: true\n}\n\n/**\n * EPUB `itemref` `properties` attribute (space-separated tokens).\n *\n * @see https://www.w3.org/TR/epub/#attrdef-properties\n */\nexport const layoutHintsFromItemrefProperties = (\n properties: string | undefined,\n): OpfItemrefLayoutHints => {\n const tokens = tokenizeXmlSpaceSeparatedList(properties)\n if (tokens.length === 0) {\n return {}\n }\n\n let renditionLayout: `reflowable` | `pre-paginated` | undefined\n if (tokens.includes(`rendition:layout-reflowable`)) {\n renditionLayout = `reflowable`\n }\n if (tokens.includes(`rendition:layout-pre-paginated`)) {\n renditionLayout = `pre-paginated`\n }\n\n return {\n ...(renditionLayout !== undefined ? { renditionLayout } : {}),\n ...(tokens.includes(`page-spread-left`)\n ? { pageSpreadLeft: true as const }\n : {}),\n ...(tokens.includes(`page-spread-right`)\n ? { pageSpreadRight: true as const }\n : {}),\n }\n}\n","import type { XmlElement, XmlNodeBase } from \"xmldoc\"\nimport { XmlDocument } from \"xmldoc\"\nimport { tokenizeXmlSpaceSeparatedList } from \"../utils/tokenizeXmlSpaceSeparatedList\"\nimport { layoutHintsFromItemrefProperties } from \"./spineItemrefProperties\"\n\nexport type OpfSpineManifestItem = {\n readonly id: string\n readonly href: string\n readonly mediaType?: string\n readonly properties?: string\n}\n\nexport type OpfIdentifier = {\n readonly value: string\n readonly scheme?: string\n}\n\nexport type OpfSpineRow = {\n readonly idref: string\n readonly id: string\n readonly href: string\n readonly mediaType?: string\n readonly properties?: string\n readonly renditionLayout?: `reflowable` | `pre-paginated`\n readonly pageSpreadLeft?: true\n readonly pageSpreadRight?: true\n}\n\nexport type OpfGuideReference = {\n readonly href: string\n readonly title: string\n readonly type: string\n}\n\nconst elementLocalName = (name: string): string =>\n name.includes(\":\") ? name.slice(name.lastIndexOf(\":\") + 1) : name\n\nconst localNameEq = (elementName: string, wantLocal: string): boolean =>\n elementLocalName(elementName).toLowerCase() === wantLocal.toLowerCase()\n\nconst isXmlElement = (node: XmlNodeBase): node is XmlElement =>\n node.type === \"element\"\n\nconst childNamedLocal = (\n parent: XmlElement,\n localName: string,\n): XmlElement | undefined => {\n for (const node of parent.children) {\n if (!isXmlElement(node)) continue\n if (localNameEq(node.name, localName)) return node\n }\n return undefined\n}\n\nconst childrenNamedLocal = (\n parent: XmlElement,\n localName: string,\n): XmlElement[] => {\n const out: XmlElement[] = []\n for (const node of parent.children) {\n if (!isXmlElement(node)) continue\n if (localNameEq(node.name, localName)) out.push(node)\n }\n return out\n}\n\nconst identifiersFromMetadata = (metadataEl: XmlElement): OpfIdentifier[] => {\n const identifiers: OpfIdentifier[] = []\n\n metadataEl.eachChild((child) => {\n if (elementLocalName(child.name).toLowerCase() !== \"identifier\") return\n\n const value = child.val.trim()\n if (value.length === 0) return\n\n const scheme =\n child.attr[\"opf:scheme\"] ?? child.attr[\"opf:Scheme\"] ?? child.attr.scheme\n const schemeTrimmed = scheme?.trim()\n\n identifiers.push({\n value,\n ...(schemeTrimmed !== undefined && schemeTrimmed.length > 0\n ? { scheme: schemeTrimmed }\n : {}),\n })\n })\n\n return identifiers\n}\n\nconst firstTextByLocalName = (\n metadataEl: XmlElement,\n localName: string,\n): string | undefined => {\n let found: string | undefined\n metadataEl.eachChild((child) => {\n if (found !== undefined) return\n if (elementLocalName(child.name).toLowerCase() !== localName.toLowerCase())\n return\n const t = child.val.trim()\n if (t.length > 0) found = t\n })\n return found\n}\n\nconst textsByLocalName = (\n metadataEl: XmlElement,\n localName: string,\n): string[] => {\n const out: string[] = []\n metadataEl.eachChild((child) => {\n if (elementLocalName(child.name).toLowerCase() !== localName.toLowerCase())\n return\n const t = child.val.trim()\n if (t.length > 0) out.push(t)\n })\n return out\n}\n\nconst coverContentIdFromMetadata = (\n metadataEl: XmlElement,\n): string | undefined => {\n let coverId: string | undefined\n metadataEl.eachChild((child) => {\n if (coverId !== undefined) return\n if (elementLocalName(child.name).toLowerCase() !== \"meta\") return\n if (child.attr.name?.toLowerCase() !== \"cover\") return\n const content = child.attr.content?.trim()\n if (content !== undefined && content.length > 0) coverId = content\n })\n return coverId\n}\n\n/**\n * EPUB cover image inside the manifest. Resolution order, matching\n * what the spec lays out and what the bulk of EPUB producers in the\n * wild rely on:\n *\n * 1. EPUB 3 — the manifest item carrying the `cover-image` token in\n * its `properties` attribute (§ D.6.1).\n * 2. EPUB 2 — `<meta name=\"cover\" content=\"ID\"/>` in `metadata`,\n * resolved to the manifest item with that `id`.\n * 3. Last-resort fallback — any image manifest item whose `id`\n * contains the substring `cover` (case-insensitive); covers the\n * long tail of producers that emit neither the EPUB 3 property\n * nor the EPUB 2 meta.\n *\n * Each step requires the candidate manifest item to advertise an\n * `image/*` media type so non-image artefacts named `cover` (XHTML\n * cover pages, NCX entries) don't slip through.\n */\nconst coverHrefFromManifestAndMetadata = ({\n manifestItems,\n metadataEl,\n}: {\n manifestItems: ReadonlyArray<OpfSpineManifestItem>\n metadataEl: XmlElement | undefined\n}): string | undefined => {\n const isImage = (item: OpfSpineManifestItem): boolean =>\n item.mediaType?.toLowerCase().includes(\"image/\") === true\n\n const byCoverImageProperty = manifestItems.find((item) => {\n if (!isImage(item)) return false\n return tokenizeXmlSpaceSeparatedList(item.properties).includes(\n \"cover-image\",\n )\n })\n if (byCoverImageProperty !== undefined) return byCoverImageProperty.href\n\n if (metadataEl !== undefined) {\n const coverContentId = coverContentIdFromMetadata(metadataEl)\n if (coverContentId !== undefined) {\n const match = manifestItems.find(\n (item) => item.id === coverContentId && isImage(item),\n )\n if (match !== undefined) return match.href\n }\n }\n\n return manifestItems.find(\n (item) => item.id.toLowerCase().includes(\"cover\") && isImage(item),\n )?.href\n}\n\nconst metaValByProperty = (\n metadataEl: XmlElement,\n property: string,\n): string | undefined => {\n const meta = childrenNamedLocal(metadataEl, \"meta\").find(\n (m) => m.attr.property === property,\n )\n const raw = meta?.val\n if (raw === undefined || raw.trim().length === 0) return undefined\n return raw\n}\n\nconst guideFromPackage = (doc: XmlElement): OpfGuideReference[] => {\n const guideEl = childNamedLocal(doc, \"guide\")\n if (guideEl === undefined) return []\n\n const refs: OpfGuideReference[] = []\n\n for (const ref of childrenNamedLocal(guideEl, \"reference\")) {\n const href = ref.attr.href?.trim()\n if (href === undefined || href.length === 0) continue\n refs.push({\n href,\n title: ref.attr.title?.trim() ?? ``,\n type: ref.attr.type?.trim() ?? ``,\n })\n }\n\n return refs\n}\n\nconst manifestItemFromXmlElement = (\n item: XmlElement,\n): OpfSpineManifestItem | undefined => {\n const id = item.attr.id\n const href = item.attr.href\n if (id === undefined || id.length === 0) return undefined\n if (href === undefined || href.length === 0) return undefined\n\n const mediaType = item.attr[\"media-type\"]\n const properties = item.attr.properties?.trim()\n return {\n id,\n href,\n ...(mediaType !== undefined && mediaType.length > 0 ? { mediaType } : {}),\n ...(properties !== undefined && properties.length > 0\n ? { properties }\n : {}),\n }\n}\n\nconst manifestItemsAndById = (\n manifestEl: XmlElement,\n): {\n items: OpfSpineManifestItem[]\n byId: Map<string, OpfSpineManifestItem>\n} => {\n const items: OpfSpineManifestItem[] = []\n const byId = new Map<string, OpfSpineManifestItem>()\n\n for (const el of childrenNamedLocal(manifestEl, \"item\")) {\n const parsed = manifestItemFromXmlElement(el)\n if (parsed === undefined) continue\n items.push(parsed)\n byId.set(parsed.id, parsed)\n }\n\n return { items, byId }\n}\n\nconst spineRowsFromByIdAndSpine = (\n byId: Map<string, OpfSpineManifestItem>,\n spineEl: XmlElement,\n): OpfSpineRow[] => {\n const rows: OpfSpineRow[] = []\n\n for (const itemref of childrenNamedLocal(spineEl, \"itemref\")) {\n const idref = itemref.attr.idref\n if (idref === undefined || idref.trim().length === 0) continue\n\n const manifestItem = byId.get(idref)\n if (manifestItem === undefined) continue\n\n const hints = layoutHintsFromItemrefProperties(itemref.attr.properties)\n\n rows.push({\n idref,\n id: manifestItem.id,\n href: manifestItem.href,\n ...(manifestItem.mediaType !== undefined\n ? { mediaType: manifestItem.mediaType }\n : {}),\n ...(manifestItem.properties !== undefined\n ? { properties: manifestItem.properties }\n : {}),\n ...(hints.renditionLayout !== undefined\n ? { renditionLayout: hints.renditionLayout }\n : {}),\n ...(hints.pageSpreadLeft !== undefined\n ? { pageSpreadLeft: hints.pageSpreadLeft }\n : {}),\n ...(hints.pageSpreadRight !== undefined\n ? { pageSpreadRight: hints.pageSpreadRight }\n : {}),\n })\n }\n\n return rows\n}\n\nexport type OpfMetadata = {\n readonly kind: \"opf\"\n readonly manifestItems: ReadonlyArray<OpfSpineManifestItem>\n readonly spineRows: ReadonlyArray<OpfSpineRow>\n readonly spineTocIdref: string | undefined\n readonly identifiers: ReadonlyArray<OpfIdentifier>\n readonly title: string | undefined\n /** `dc:creator` values, in document order, trimmed; empty when none. */\n readonly creators: ReadonlyArray<string>\n /** First non-empty `dc:publisher`, trimmed. */\n readonly publisher: string | undefined\n /** First non-empty `dc:rights`, trimmed. */\n readonly rights: string | undefined\n /** `dc:language` values, in document order, trimmed; empty when none. */\n readonly languages: ReadonlyArray<string>\n /** `dc:subject` values, in document order, trimmed; empty when none. */\n readonly subjects: ReadonlyArray<string>\n /**\n * Raw `dc:date` value as authored. EPUB 3 requires W3CDTF (a profile\n * of ISO 8601), but real-world publishers also ship free text here,\n * so the value is exposed verbatim and consumers normalize as needed.\n */\n readonly date: string | undefined\n /**\n * Manifest-relative `href` of the cover image, when one can be\n * resolved from `cover-image` properties (EPUB 3), the EPUB 2\n * `<meta name=\"cover\">` convention, or an `id` that contains\n * `cover` on an image manifest item. The href is returned exactly\n * as it appears in the manifest — callers own folder-prefix\n * resolution against the OPF's location in the archive.\n */\n readonly coverHref: string | undefined\n readonly renditionLayoutMeta: string | undefined\n readonly renditionFlowMeta: string | undefined\n readonly renditionSpreadMeta: string | undefined\n readonly pageProgressionDirection: string | undefined\n readonly guide: ReadonlyArray<OpfGuideReference>\n}\n\n/**\n * Parses an EPUB package document (OPF) into structured metadata.\n *\n * Direct children of `package` (`metadata`, `manifest`, `spine`, `guide`) and\n * their structural children (`item`, `itemref`, `reference`, `meta`) are\n * matched by **local name** (ASCII case-insensitive), so prefixed tags such as\n * `opf:manifest` are supported the same as unprefixed `manifest`.\n *\n * Attribute names on `spine` / `itemref` are still read as emitted by xmldoc\n * (no QName normalization).\n */\nexport const parseOpf = (opfXml: string): OpfMetadata => {\n const doc = new XmlDocument(opfXml)\n const manifestEl = childNamedLocal(doc, \"manifest\")\n const spineEl = childNamedLocal(doc, \"spine\")\n const metadataEl = childNamedLocal(doc, \"metadata\")\n\n let manifestItems: OpfSpineManifestItem[] = []\n let spineRows: OpfSpineRow[] = []\n\n if (manifestEl !== undefined) {\n const { items, byId } = manifestItemsAndById(manifestEl)\n manifestItems = items\n if (spineEl !== undefined) {\n spineRows = spineRowsFromByIdAndSpine(byId, spineEl)\n }\n }\n\n const pageProgressionDirectionRaw =\n spineEl?.attr[\"page-progression-direction\"]\n const pageProgressionDirection =\n pageProgressionDirectionRaw !== undefined &&\n pageProgressionDirectionRaw.trim().length > 0\n ? pageProgressionDirectionRaw\n : undefined\n\n const spineTocRaw = spineEl?.attr.toc\n const spineTocIdref =\n spineTocRaw !== undefined && spineTocRaw.trim().length > 0\n ? spineTocRaw.trim()\n : undefined\n\n let title: string | undefined\n let publisher: string | undefined\n let rights: string | undefined\n let date: string | undefined\n let creators: string[] = []\n let languages: string[] = []\n let subjects: string[] = []\n let renditionLayoutMeta: string | undefined\n let renditionFlowMeta: string | undefined\n let renditionSpreadMeta: string | undefined\n const identifiers: OpfIdentifier[] = []\n\n if (metadataEl !== undefined) {\n title = firstTextByLocalName(metadataEl, \"title\")\n publisher = firstTextByLocalName(metadataEl, \"publisher\")\n rights = firstTextByLocalName(metadataEl, \"rights\")\n date = firstTextByLocalName(metadataEl, \"date\")\n creators = textsByLocalName(metadataEl, \"creator\")\n languages = textsByLocalName(metadataEl, \"language\")\n subjects = textsByLocalName(metadataEl, \"subject\")\n renditionLayoutMeta = metaValByProperty(metadataEl, \"rendition:layout\")\n renditionFlowMeta = metaValByProperty(metadataEl, \"rendition:flow\")\n renditionSpreadMeta = metaValByProperty(metadataEl, \"rendition:spread\")\n identifiers.push(...identifiersFromMetadata(metadataEl))\n }\n\n const coverHref = coverHrefFromManifestAndMetadata({\n manifestItems,\n metadataEl,\n })\n\n const guide = guideFromPackage(doc)\n\n return {\n kind: \"opf\",\n manifestItems,\n spineRows,\n spineTocIdref,\n identifiers,\n title,\n creators,\n publisher,\n rights,\n languages,\n subjects,\n date,\n coverHref,\n renditionLayoutMeta,\n renditionFlowMeta,\n renditionSpreadMeta,\n pageProgressionDirection,\n guide,\n }\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport type { AppleMetadata } from \"./parse\"\n\nexport const resolveApple = (input: AppleMetadata): ArchiveResolveResult => {\n const fixedLayout = input.displayOptions?.platform?.options?.find(\n (o) => o.name === \"fixed-layout\",\n )?.value\n\n const renditionLayout =\n fixedLayout?.trim().toLowerCase() === \"true\" ? \"pre-paginated\" : undefined\n\n return {\n gtin: undefined,\n isbn: undefined,\n readingDirection: undefined,\n renditionLayout,\n title: undefined,\n authors: undefined,\n publisher: undefined,\n rights: undefined,\n languages: undefined,\n date: undefined,\n subjects: undefined,\n }\n}\n","const GTIN_LENGTHS = new Set([8, 12, 13, 14])\n\n/**\n * Normalize a raw GTIN / EAN / UPC string to digits only when the length\n * matches a GS1 GTIN family size (8, 12, 13, or 14). Does not verify check digits.\n */\nexport const normalizeGtin = (\n raw: string | number | undefined | null,\n): string | undefined => {\n if (raw === undefined || raw === null) return undefined\n\n const digits = String(raw).replace(/\\D/g, \"\")\n if (digits.length === 0 || !GTIN_LENGTHS.has(digits.length)) return undefined\n\n return digits\n}\n","const ISBN_CANDIDATE_PATTERN = /(?:97[89])?\\d{9}[\\dXx]/\n\n/**\n * Normalize a raw ISBN-ish string into a canonical 10- or 13-character\n * form, or `undefined` when no recognisable ISBN can be recovered.\n *\n * - Strips the common `urn:isbn:` / `isbn:` prefixes.\n * - Drops everything that isn't a digit or `X`.\n * - Validates the resulting length (10 or 13).\n * - Falls back to a lax regex scan so publishers that stuff free text\n * around the number still yield a usable value.\n */\nexport const normalizeIsbn = (\n raw: string | number | undefined | null,\n): string | undefined => {\n if (raw === undefined || raw === null) return undefined\n\n const stripped = String(raw)\n .trim()\n .replace(/^urn:isbn:/i, \"\")\n .replace(/^isbn[:\\s-]*/i, \"\")\n\n const digitsOnly = stripped.replace(/[^0-9Xx]/g, \"\")\n\n if (digitsOnly.length === 10 || digitsOnly.length === 13) {\n return digitsOnly.toUpperCase()\n }\n\n const match = stripped.match(ISBN_CANDIDATE_PATTERN)\n if (match) return match[0].toUpperCase()\n\n return undefined\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport { normalizeGtin } from \"../utils/normalizeGtin\"\nimport { normalizeIsbn } from \"../utils/normalizeIsbn\"\nimport type { ComicInfo } from \"./parse\"\n\nconst readingDirection = (info: ComicInfo): \"ltr\" | \"rtl\" =>\n info.Manga === \"YesAndRightToLeft\" ? \"rtl\" : \"ltr\"\n\nconst trimToUndefined = (raw: string | undefined): string | undefined => {\n if (raw === undefined) return undefined\n const trimmed = raw.trim()\n return trimmed.length > 0 ? trimmed : undefined\n}\n\n/**\n * Split a comma-separated ComicInfo value into its individual tokens.\n * `Writer`, `Genre`, and `Tags` all follow the same de-facto convention:\n * tokens separated by `,`, with whitespace trimmed and empty tokens\n * dropped (real-world files leave trailing commas around).\n */\nconst splitCommaList = (raw: string | undefined): string[] => {\n if (raw === undefined) return []\n return raw\n .split(\",\")\n .map((token) => token.trim())\n .filter((token) => token.length > 0)\n}\n\nconst parseNonNegativeInt = (raw: string | undefined): number | undefined => {\n const trimmed = trimToUndefined(raw)\n if (trimmed === undefined) return undefined\n if (!/^\\d+$/.test(trimmed)) return undefined\n const n = Number.parseInt(trimmed, 10)\n return Number.isFinite(n) ? n : undefined\n}\n\nconst dateFromYearMonthDay = (\n info: ComicInfo,\n):\n | {\n year?: number\n month?: number\n day?: number\n }\n | undefined => {\n const year = parseNonNegativeInt(info.Year)\n const month = parseNonNegativeInt(info.Month)\n const day = parseNonNegativeInt(info.Day)\n\n if (year === undefined && month === undefined && day === undefined) {\n return undefined\n }\n\n return {\n ...(year !== undefined ? { year } : {}),\n ...(month !== undefined ? { month } : {}),\n ...(day !== undefined ? { day } : {}),\n }\n}\n\nexport const resolveComicInfo = (info: ComicInfo): ArchiveResolveResult => {\n const raw = info.GTIN\n const languageIso = trimToUndefined(info.LanguageISO)\n const authors = splitCommaList(info.Writer)\n const subjects = [...splitCommaList(info.Genre), ...splitCommaList(info.Tags)]\n\n return {\n gtin: normalizeGtin(raw),\n isbn: normalizeIsbn(raw),\n readingDirection: readingDirection(info),\n renditionLayout: undefined,\n title: trimToUndefined(info.Title),\n authors: authors.length > 0 ? authors : undefined,\n publisher: trimToUndefined(info.Publisher),\n rights: undefined,\n languages: languageIso !== undefined ? [languageIso] : undefined,\n date: dateFromYearMonthDay(info),\n subjects: subjects.length > 0 ? subjects : undefined,\n }\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport type { KoboMetadata } from \"./parse\"\n\nexport const resolveKobo = (input: KoboMetadata): ArchiveResolveResult => ({\n gtin: undefined,\n isbn: undefined,\n readingDirection: undefined,\n renditionLayout: input.renditionLayout,\n title: undefined,\n authors: undefined,\n publisher: undefined,\n rights: undefined,\n languages: undefined,\n date: undefined,\n subjects: undefined,\n})\n","/**\n * Extract the calendar components of a W3CDTF literal — the\n * date subset of ISO 8601 that EPUB 3.3 § 5.5.3.2.4 mandates for\n * `dc:date`. Accepted forms: `YYYY`, `YYYY-MM`, `YYYY-MM-DD`, and\n * any of the above followed by a `Thh:mm[:ss[.s]][TZD]` time\n * portion that we ignore.\n *\n * Components are returned as plain integers (`month` is 1-12,\n * `day` is 1-31), independent of the host timezone — using\n * `Date.parse` would shift `2011-01-01` by a day in negative-offset\n * locales, which is the exact bug this regex-based approach exists\n * to avoid. Returns `undefined` when the input doesn't even match\n * a leading 4-digit year so consumers can fall back without\n * branching on partial shapes.\n */\nexport const parseW3cDtfDate = (\n raw: string | undefined,\n):\n | {\n year?: number\n month?: number\n day?: number\n }\n | undefined => {\n if (raw === undefined) return undefined\n\n const match = raw.trim().match(/^(\\d{4})(?:-(\\d{2})(?:-(\\d{2}))?)?/)\n if (match === null) return undefined\n\n const [, yearRaw, monthRaw, dayRaw] = match\n\n return {\n ...(yearRaw !== undefined ? { year: Number.parseInt(yearRaw, 10) } : {}),\n ...(monthRaw !== undefined ? { month: Number.parseInt(monthRaw, 10) } : {}),\n ...(dayRaw !== undefined ? { day: Number.parseInt(dayRaw, 10) } : {}),\n }\n}\n","import type { ArchiveResolveResult } from \"../types/archiveResolve\"\nimport { normalizeGtin } from \"../utils/normalizeGtin\"\nimport { normalizeIsbn } from \"../utils/normalizeIsbn\"\nimport { parseW3cDtfDate } from \"../utils/parseW3cDtfDate\"\nimport type { OpfIdentifier, OpfMetadata } from \"./parse\"\n\nconst rawIdentifierValueForIsbn = (\n identifiers: ReadonlyArray<OpfIdentifier>,\n): string | undefined => {\n for (const i of identifiers) {\n if (i.scheme !== undefined && i.scheme.trim().toLowerCase() === \"isbn\") {\n if (normalizeIsbn(i.value) !== undefined) return i.value\n }\n }\n\n for (const i of identifiers) {\n if (normalizeIsbn(i.value) !== undefined) return i.value\n }\n\n return undefined\n}\n\nexport const resolveOpf = (input: OpfMetadata): ArchiveResolveResult => {\n const ppd = input.pageProgressionDirection?.trim().toLowerCase()\n const readingDirection = ppd === \"ltr\" || ppd === \"rtl\" ? ppd : undefined\n\n const rl = input.renditionLayoutMeta?.trim().toLowerCase()\n const renditionLayout =\n rl === \"reflowable\" || rl === \"pre-paginated\" ? rl : undefined\n\n const raw = rawIdentifierValueForIsbn(input.identifiers)\n\n return {\n gtin: normalizeGtin(raw),\n isbn: normalizeIsbn(raw),\n readingDirection,\n renditionLayout,\n title: input.title,\n authors: input.creators.length > 0 ? [...input.creators] : undefined,\n publisher: input.publisher,\n rights: input.rights,\n languages: input.languages.length > 0 ? [...input.languages] : undefined,\n date: parseW3cDtfDate(input.date),\n subjects: input.subjects.length > 0 ? [...input.subjects] : undefined,\n }\n}\n","import type { AppleMetadata } from \"./apple/parse\"\nimport { resolveApple } from \"./apple/resolve\"\nimport type { ComicInfo } from \"./comicInfo/parse\"\nimport { resolveComicInfo } from \"./comicInfo/resolve\"\nimport type { KoboMetadata } from \"./kobo/parse\"\nimport { resolveKobo } from \"./kobo/resolve\"\nimport type { OpfMetadata } from \"./opf/parse\"\nimport { resolveOpf } from \"./opf/resolve\"\nimport type { ArchiveResolveResult } from \"./types/archiveResolve\"\n\nexport type ResolvedArchiveInput =\n | ComicInfo\n | KoboMetadata\n | AppleMetadata\n | OpfMetadata\n\nexport const resolveArchiveMetadata = (\n input: ResolvedArchiveInput,\n): ArchiveResolveResult => {\n if (input.kind === \"comicInfo\") return resolveComicInfo(input)\n if (input.kind === \"kobo\") return resolveKobo(input)\n if (input.kind === \"apple\") return resolveApple(input)\n return resolveOpf(input)\n}\n"],"names":["APPLE_IBOOKS_DISPLAY_OPTIONS_FILENAME","platformOptionsFromElement","platform","option","parseAppleDisplayOptionsXml","xml","doc","XmlDocument","platformEl","COMIC_INFO_MANGA_VALUES","isComicInfoManga","value","v","COMIC_INFO_FILENAME","SKIP_ELEMENT_CHILDREN","hasNestedElement","el","c","trimmedText","parseComicInfo","cause","message","fields","child","text","KOBO_DISPLAY_OPTIONS_FILENAME","parseKoboDisplayOptionsDocument","parseKoboXml","tokenizeXmlSpaceSeparatedList","raw","layoutHintsFromItemrefProperties","properties","tokens","renditionLayout","elementLocalName","name","localNameEq","elementName","wantLocal","isXmlElement","node","childNamedLocal","parent","localName","childrenNamedLocal","out","identifiersFromMetadata","metadataEl","identifiers","schemeTrimmed","firstTextByLocalName","found","t","textsByLocalName","coverContentIdFromMetadata","coverId","content","coverHrefFromManifestAndMetadata","manifestItems","isImage","item","byCoverImageProperty","coverContentId","match","metaValByProperty","property","m","guideFromPackage","guideEl","refs","ref","href","manifestItemFromXmlElement","id","mediaType","manifestItemsAndById","manifestEl","items","byId","parsed","spineRowsFromByIdAndSpine","spineEl","rows","itemref","idref","manifestItem","hints","parseOpf","opfXml","spineRows","pageProgressionDirectionRaw","pageProgressionDirection","spineTocRaw","spineTocIdref","title","publisher","rights","date","creators","languages","subjects","renditionLayoutMeta","renditionFlowMeta","renditionSpreadMeta","coverHref","guide","resolveApple","input","o","GTIN_LENGTHS","normalizeGtin","digits","ISBN_CANDIDATE_PATTERN","normalizeIsbn","stripped","digitsOnly","readingDirection","info","trimToUndefined","trimmed","splitCommaList","token","parseNonNegativeInt","n","dateFromYearMonthDay","year","month","day","resolveComicInfo","languageIso","authors","resolveKobo","parseW3cDtfDate","yearRaw","monthRaw","dayRaw","rawIdentifierValueForIsbn","i","resolveOpf","ppd","rl","resolveArchiveMetadata"],"mappings":"6RAGO,MAAMA,EACX,uCAgBIC,EACJC,GAEAA,EAAS,cAAc,QAAQ,EAAE,IAAKC,IAAY,CAChD,KAAMA,EAAO,MAAM,KACnB,MAAOA,EAAO,GAChB,EAAE,EAESC,EAA+BC,GAA+B,CACzE,MAAMC,EAAM,IAAIC,E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AEIA,EAAM,OAAS,YAAoBqB,GAAiBrB,CAAK,EACzDA,EAAM,OAAS,OAAewB,GAAYxB,CAAK,EAC/CA,EAAM,OAAS,QAAgBD,GAAaC,CAAK,EAC9C+B,GAAW/B,CAAK"}
|
package/dist/opf/parse.d.ts
CHANGED
|
@@ -30,6 +30,31 @@ export type OpfMetadata = {
|
|
|
30
30
|
readonly spineTocIdref: string | undefined;
|
|
31
31
|
readonly identifiers: ReadonlyArray<OpfIdentifier>;
|
|
32
32
|
readonly title: string | undefined;
|
|
33
|
+
/** `dc:creator` values, in document order, trimmed; empty when none. */
|
|
34
|
+
readonly creators: ReadonlyArray<string>;
|
|
35
|
+
/** First non-empty `dc:publisher`, trimmed. */
|
|
36
|
+
readonly publisher: string | undefined;
|
|
37
|
+
/** First non-empty `dc:rights`, trimmed. */
|
|
38
|
+
readonly rights: string | undefined;
|
|
39
|
+
/** `dc:language` values, in document order, trimmed; empty when none. */
|
|
40
|
+
readonly languages: ReadonlyArray<string>;
|
|
41
|
+
/** `dc:subject` values, in document order, trimmed; empty when none. */
|
|
42
|
+
readonly subjects: ReadonlyArray<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Raw `dc:date` value as authored. EPUB 3 requires W3CDTF (a profile
|
|
45
|
+
* of ISO 8601), but real-world publishers also ship free text here,
|
|
46
|
+
* so the value is exposed verbatim and consumers normalize as needed.
|
|
47
|
+
*/
|
|
48
|
+
readonly date: string | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Manifest-relative `href` of the cover image, when one can be
|
|
51
|
+
* resolved from `cover-image` properties (EPUB 3), the EPUB 2
|
|
52
|
+
* `<meta name="cover">` convention, or an `id` that contains
|
|
53
|
+
* `cover` on an image manifest item. The href is returned exactly
|
|
54
|
+
* as it appears in the manifest — callers own folder-prefix
|
|
55
|
+
* resolution against the OPF's location in the archive.
|
|
56
|
+
*/
|
|
57
|
+
readonly coverHref: string | undefined;
|
|
33
58
|
readonly renditionLayoutMeta: string | undefined;
|
|
34
59
|
readonly renditionFlowMeta: string | undefined;
|
|
35
60
|
readonly renditionSpreadMeta: string | undefined;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cross-format hints for manifest-style consumers (identifiers, reading order,
|
|
3
|
-
* fixed-layout).
|
|
3
|
+
* fixed-layout, descriptive metadata). Every field is populated by every
|
|
4
|
+
* `resolve*` — values default to `undefined` when the source format has no
|
|
5
|
+
* equivalent or the input is missing/blank, so consumers see a stable shape
|
|
6
|
+
* regardless of which container they're reading. Empty arrays/strings collapse
|
|
7
|
+
* to `undefined` so `result.field !== undefined` is a reliable presence check.
|
|
8
|
+
*
|
|
9
|
+
* Sources are container-agnostic: the same field can come from OPF Dublin
|
|
10
|
+
* Core (`dc:creator`, `dc:date`, …) or from a ComicInfo.xml element
|
|
11
|
+
* (`Writer`, `Year`/`Month`/`Day`, …).
|
|
4
12
|
*
|
|
5
13
|
* @see https://en.wikipedia.org/wiki/ISBN
|
|
6
14
|
*/
|
|
@@ -10,4 +18,49 @@ export type ArchiveResolveResult = {
|
|
|
10
18
|
isbn?: string;
|
|
11
19
|
readingDirection?: "ltr" | "rtl";
|
|
12
20
|
renditionLayout?: "reflowable" | "pre-paginated";
|
|
21
|
+
/**
|
|
22
|
+
* Human-readable title of the work. OPF: `dc:title`. ComicInfo: `Title`.
|
|
23
|
+
* Bare archive series naming (`Series` without `Title`) is left to the
|
|
24
|
+
* consumer — the resolver doesn't fall back across container fields.
|
|
25
|
+
*/
|
|
26
|
+
title?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Primary creators, in document order. OPF: every `dc:creator`.
|
|
29
|
+
* ComicInfo: `Writer`, split on commas (the de facto schema convention).
|
|
30
|
+
* Other ComicInfo roles (`Penciller`, `Inker`, …) stay on the parsed
|
|
31
|
+
* object — folding them all in here would lose role attribution.
|
|
32
|
+
*/
|
|
33
|
+
authors?: string[];
|
|
34
|
+
/** OPF: first non-empty `dc:publisher`. ComicInfo: `Publisher`. */
|
|
35
|
+
publisher?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Rights / copyright statement. OPF: first non-empty `dc:rights`.
|
|
38
|
+
* ComicInfo has no spec'd rights field, so this is OPF-only today.
|
|
39
|
+
*/
|
|
40
|
+
rights?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Language tags. OPF: every `dc:language` (BCP 47). ComicInfo:
|
|
43
|
+
* `LanguageISO` lifted into a single-entry array; the schema is
|
|
44
|
+
* single-language by design but we keep the array shape so consumers
|
|
45
|
+
* can ignore the source format.
|
|
46
|
+
*/
|
|
47
|
+
languages?: string[];
|
|
48
|
+
/**
|
|
49
|
+
* Calendar components extracted from the source date. Each component
|
|
50
|
+
* is independently optional so partial dates (year only, year+month)
|
|
51
|
+
* round-trip faithfully. OPF: `dc:date` parsed as W3CDTF. ComicInfo:
|
|
52
|
+
* `Year` / `Month` / `Day` parsed as integers.
|
|
53
|
+
*/
|
|
54
|
+
date?: {
|
|
55
|
+
year?: number;
|
|
56
|
+
month?: number;
|
|
57
|
+
day?: number;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Subject keywords. OPF: every `dc:subject`. ComicInfo: `Genre`
|
|
61
|
+
* followed by `Tags`, both split on commas, in that order. The schema
|
|
62
|
+
* assigns slightly different intents to the two ComicInfo fields, but
|
|
63
|
+
* for the cross-format "subjects" lens they're equivalent.
|
|
64
|
+
*/
|
|
65
|
+
subjects?: string[];
|
|
13
66
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract the calendar components of a W3CDTF literal — the
|
|
3
|
+
* date subset of ISO 8601 that EPUB 3.3 § 5.5.3.2.4 mandates for
|
|
4
|
+
* `dc:date`. Accepted forms: `YYYY`, `YYYY-MM`, `YYYY-MM-DD`, and
|
|
5
|
+
* any of the above followed by a `Thh:mm[:ss[.s]][TZD]` time
|
|
6
|
+
* portion that we ignore.
|
|
7
|
+
*
|
|
8
|
+
* Components are returned as plain integers (`month` is 1-12,
|
|
9
|
+
* `day` is 1-31), independent of the host timezone — using
|
|
10
|
+
* `Date.parse` would shift `2011-01-01` by a day in negative-offset
|
|
11
|
+
* locales, which is the exact bug this regex-based approach exists
|
|
12
|
+
* to avoid. Returns `undefined` when the input doesn't even match
|
|
13
|
+
* a leading 4-digit year so consumers can fall back without
|
|
14
|
+
* branching on partial shapes.
|
|
15
|
+
*/
|
|
16
|
+
export declare const parseW3cDtfDate: (raw: string | undefined) => {
|
|
17
|
+
year?: number;
|
|
18
|
+
month?: number;
|
|
19
|
+
day?: number;
|
|
20
|
+
} | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prose-reader/archive-parser",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.290.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.umd.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -28,5 +28,6 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"xmldoc": "^2.0.0"
|
|
31
|
-
}
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "6badb447dc35000fac2bed1f7a03fcd8830e0503"
|
|
32
33
|
}
|