@korzun/epubcheck-ts 0.1.0-beta.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/ATTRIBUTION.md +26 -0
- package/LICENSE +28 -0
- package/README.md +191 -0
- package/dist/index.cjs +1471 -0
- package/dist/index.d.cts +214 -0
- package/dist/index.d.ts +214 -0
- package/dist/index.js +1427 -0
- package/package.json +50 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
//#region src/messages/catalog.d.ts
|
|
2
|
+
type Severity = 'FATAL' | 'ERROR' | 'WARNING' | 'INFO' | 'USAGE';
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/messages/format.d.ts
|
|
5
|
+
interface Location {
|
|
6
|
+
path: string;
|
|
7
|
+
line?: number;
|
|
8
|
+
column?: number;
|
|
9
|
+
}
|
|
10
|
+
interface Message {
|
|
11
|
+
id: string;
|
|
12
|
+
severity: Severity;
|
|
13
|
+
message: string;
|
|
14
|
+
location?: Location;
|
|
15
|
+
suggestion?: string;
|
|
16
|
+
}
|
|
17
|
+
declare function msg(id: string, location: Location | undefined, ...args: unknown[]): Message;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/report.d.ts
|
|
20
|
+
interface Report {
|
|
21
|
+
messages: Message[];
|
|
22
|
+
epubVersion?: '2.0' | '3.0';
|
|
23
|
+
counts: Record<Severity, number>;
|
|
24
|
+
fatal: boolean;
|
|
25
|
+
valid: boolean;
|
|
26
|
+
}
|
|
27
|
+
declare function buildReport(messages: Message[], epubVersion?: '2.0' | '3.0'): Report;
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/validate.d.ts
|
|
30
|
+
interface ValidateOptions {
|
|
31
|
+
version?: '2.0' | '3.0';
|
|
32
|
+
}
|
|
33
|
+
declare function validateEpub(input: Uint8Array | ArrayBuffer | ReadableStream<Uint8Array>, options?: ValidateOptions): Promise<Report>;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/io/zip.d.ts
|
|
36
|
+
interface Resource {
|
|
37
|
+
path: string;
|
|
38
|
+
bytes: Uint8Array;
|
|
39
|
+
compression: 'stored' | 'deflate';
|
|
40
|
+
mediaType?: string;
|
|
41
|
+
}
|
|
42
|
+
interface EpubContainer {
|
|
43
|
+
resources: Map<string, Resource>;
|
|
44
|
+
rootfiles: string[];
|
|
45
|
+
hasEncryption: boolean;
|
|
46
|
+
}
|
|
47
|
+
declare function openEpub(input: Uint8Array | ArrayBuffer | ReadableStream<Uint8Array>): Promise<EpubContainer>;
|
|
48
|
+
declare function getResource(container: EpubContainer, path: string): Resource | undefined;
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/io/xml.d.ts
|
|
51
|
+
interface XmlNode {
|
|
52
|
+
type: 'element' | 'text';
|
|
53
|
+
name?: string;
|
|
54
|
+
ns?: string;
|
|
55
|
+
attrs?: Record<string, string>;
|
|
56
|
+
children?: XmlNode[];
|
|
57
|
+
text?: string;
|
|
58
|
+
loc: Location;
|
|
59
|
+
}
|
|
60
|
+
declare function parseXml(bytes: Uint8Array, path: string): {
|
|
61
|
+
root?: XmlNode;
|
|
62
|
+
messages: Message[];
|
|
63
|
+
};
|
|
64
|
+
/** Element children of a node (text nodes filtered out). */
|
|
65
|
+
declare function childElements(node: XmlNode): XmlNode[];
|
|
66
|
+
/** All descendant elements (any depth) whose local name matches. */
|
|
67
|
+
declare function findDescendants(node: XmlNode, localName: string): XmlNode[];
|
|
68
|
+
/** All descendant text content of a node, concatenated (not trimmed). */
|
|
69
|
+
declare function textContent(node: XmlNode): string;
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/checks/ocf.d.ts
|
|
72
|
+
declare function validateOcf(container: EpubContainer): Message[];
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/parse/opf.d.ts
|
|
75
|
+
interface DcIdentifier {
|
|
76
|
+
id?: string;
|
|
77
|
+
value: string;
|
|
78
|
+
}
|
|
79
|
+
interface Metadata {
|
|
80
|
+
identifiers: DcIdentifier[];
|
|
81
|
+
titles: string[];
|
|
82
|
+
languages: string[];
|
|
83
|
+
modifiedCount: number;
|
|
84
|
+
}
|
|
85
|
+
interface ManifestItem {
|
|
86
|
+
id?: string;
|
|
87
|
+
href?: string;
|
|
88
|
+
mediaType?: string;
|
|
89
|
+
properties: string[];
|
|
90
|
+
fallback?: string;
|
|
91
|
+
loc: Location;
|
|
92
|
+
}
|
|
93
|
+
interface SpineItem {
|
|
94
|
+
idref?: string;
|
|
95
|
+
linear: boolean;
|
|
96
|
+
properties: string[];
|
|
97
|
+
loc: Location;
|
|
98
|
+
}
|
|
99
|
+
interface PackageDocument {
|
|
100
|
+
path: string;
|
|
101
|
+
version?: string;
|
|
102
|
+
uniqueIdentifier?: string;
|
|
103
|
+
metadata: Metadata;
|
|
104
|
+
manifest: ManifestItem[];
|
|
105
|
+
spinePresent: boolean;
|
|
106
|
+
spine: SpineItem[];
|
|
107
|
+
loc: Location;
|
|
108
|
+
}
|
|
109
|
+
declare function parseOpf(container: EpubContainer): {
|
|
110
|
+
pkg?: PackageDocument;
|
|
111
|
+
messages: Message[];
|
|
112
|
+
};
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/checks/opf.d.ts
|
|
115
|
+
declare function validateOpf(pkg: PackageDocument, container: EpubContainer): Message[];
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/parse/nav.d.ts
|
|
118
|
+
interface NavSection {
|
|
119
|
+
types: string[];
|
|
120
|
+
node: XmlNode;
|
|
121
|
+
loc: Location;
|
|
122
|
+
}
|
|
123
|
+
interface NavDocument {
|
|
124
|
+
path: string;
|
|
125
|
+
root: XmlNode;
|
|
126
|
+
sections: NavSection[];
|
|
127
|
+
loc: Location;
|
|
128
|
+
}
|
|
129
|
+
declare function parseNav(navItem: ManifestItem, container: EpubContainer): {
|
|
130
|
+
nav?: NavDocument;
|
|
131
|
+
messages: Message[];
|
|
132
|
+
};
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/checks/nav.d.ts
|
|
135
|
+
declare function validateNav(nav: NavDocument, pkg: PackageDocument, container: EpubContainer): Message[];
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/parse/content.d.ts
|
|
138
|
+
type RefType = 'hyperlink' | 'image' | 'audio' | 'video' | 'stylesheet' | 'generic' | 'cite' | 'track';
|
|
139
|
+
interface ContentRef {
|
|
140
|
+
url: string;
|
|
141
|
+
type: RefType;
|
|
142
|
+
loc: Location;
|
|
143
|
+
/**
|
|
144
|
+
* True when the referencing context itself supplies a fallback (e.g. an
|
|
145
|
+
* <img> inside <picture>, a <source> inside <audio>, an <object> with
|
|
146
|
+
* fallback content). Used to suppress RSC-032.
|
|
147
|
+
*/
|
|
148
|
+
hasIntrinsicFallback: boolean;
|
|
149
|
+
}
|
|
150
|
+
interface InlineStyle {
|
|
151
|
+
context: 'stylesheet' | 'declarationList';
|
|
152
|
+
text: string;
|
|
153
|
+
loc: Location;
|
|
154
|
+
}
|
|
155
|
+
interface ContentDocument {
|
|
156
|
+
path: string;
|
|
157
|
+
root: XmlNode;
|
|
158
|
+
refs: ContentRef[];
|
|
159
|
+
ids: Set<string>;
|
|
160
|
+
/** id attribute value → 1-based ordinal among id-bearing elements in document order (first occurrence wins). */
|
|
161
|
+
idPositions: Map<string, number>;
|
|
162
|
+
inlineStyles: InlineStyle[];
|
|
163
|
+
}
|
|
164
|
+
declare function parseContent(item: ManifestItem, container: EpubContainer): {
|
|
165
|
+
doc?: ContentDocument;
|
|
166
|
+
messages: Message[];
|
|
167
|
+
};
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/checks/content.d.ts
|
|
170
|
+
declare function validateContentDocs(pkg: PackageDocument, container: EpubContainer): Message[];
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/parse/css.d.ts
|
|
173
|
+
type CssRefType = 'generic' | 'font' | 'import';
|
|
174
|
+
interface CssRef {
|
|
175
|
+
url: string;
|
|
176
|
+
type: CssRefType;
|
|
177
|
+
loc: Location;
|
|
178
|
+
}
|
|
179
|
+
interface CssDeclaration {
|
|
180
|
+
property: string;
|
|
181
|
+
value: string;
|
|
182
|
+
loc: Location;
|
|
183
|
+
}
|
|
184
|
+
interface FontFace {
|
|
185
|
+
declarationCount: number;
|
|
186
|
+
loc: Location;
|
|
187
|
+
}
|
|
188
|
+
interface CssDocument {
|
|
189
|
+
path: string;
|
|
190
|
+
refs: CssRef[];
|
|
191
|
+
declarations: CssDeclaration[];
|
|
192
|
+
fontFaces: FontFace[];
|
|
193
|
+
}
|
|
194
|
+
interface CssAnalysis {
|
|
195
|
+
parsed: boolean;
|
|
196
|
+
refs: CssRef[];
|
|
197
|
+
declarations: CssDeclaration[];
|
|
198
|
+
fontFaces: FontFace[];
|
|
199
|
+
messages: Message[];
|
|
200
|
+
}
|
|
201
|
+
declare function analyzeCss(text: string, path: string, context: 'stylesheet' | 'declarationList'): CssAnalysis;
|
|
202
|
+
declare function parseCss(item: ManifestItem, container: EpubContainer): {
|
|
203
|
+
css?: CssDocument;
|
|
204
|
+
messages: Message[];
|
|
205
|
+
};
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/checks/css.d.ts
|
|
208
|
+
declare function validateCss(css: CssDocument, container: EpubContainer, manifest: Map<string, ManifestItem>): Message[];
|
|
209
|
+
declare function validateCssDocs(pkg: PackageDocument, container: EpubContainer): Message[];
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/index.d.ts
|
|
212
|
+
declare const VERSION: string;
|
|
213
|
+
//#endregion
|
|
214
|
+
export { type ContentDocument, type ContentRef, type CssAnalysis, type CssDeclaration, type CssDocument, type CssRef, type CssRefType, type DcIdentifier, type EpubContainer, type FontFace, type InlineStyle, type Location, type ManifestItem, type Message, type Metadata, type NavDocument, type NavSection, type PackageDocument, type RefType, type Report, type Resource, type Severity, type SpineItem, VERSION, type ValidateOptions, type XmlNode, analyzeCss, buildReport, childElements, findDescendants, getResource, msg, openEpub, parseContent, parseCss, parseNav, parseOpf, parseXml, textContent, validateContentDocs, validateCss, validateCssDocs, validateEpub, validateNav, validateOcf, validateOpf };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
//#region src/messages/catalog.d.ts
|
|
2
|
+
type Severity = 'FATAL' | 'ERROR' | 'WARNING' | 'INFO' | 'USAGE';
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/messages/format.d.ts
|
|
5
|
+
interface Location {
|
|
6
|
+
path: string;
|
|
7
|
+
line?: number;
|
|
8
|
+
column?: number;
|
|
9
|
+
}
|
|
10
|
+
interface Message {
|
|
11
|
+
id: string;
|
|
12
|
+
severity: Severity;
|
|
13
|
+
message: string;
|
|
14
|
+
location?: Location;
|
|
15
|
+
suggestion?: string;
|
|
16
|
+
}
|
|
17
|
+
declare function msg(id: string, location: Location | undefined, ...args: unknown[]): Message;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/report.d.ts
|
|
20
|
+
interface Report {
|
|
21
|
+
messages: Message[];
|
|
22
|
+
epubVersion?: '2.0' | '3.0';
|
|
23
|
+
counts: Record<Severity, number>;
|
|
24
|
+
fatal: boolean;
|
|
25
|
+
valid: boolean;
|
|
26
|
+
}
|
|
27
|
+
declare function buildReport(messages: Message[], epubVersion?: '2.0' | '3.0'): Report;
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/validate.d.ts
|
|
30
|
+
interface ValidateOptions {
|
|
31
|
+
version?: '2.0' | '3.0';
|
|
32
|
+
}
|
|
33
|
+
declare function validateEpub(input: Uint8Array | ArrayBuffer | ReadableStream<Uint8Array>, options?: ValidateOptions): Promise<Report>;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/io/zip.d.ts
|
|
36
|
+
interface Resource {
|
|
37
|
+
path: string;
|
|
38
|
+
bytes: Uint8Array;
|
|
39
|
+
compression: 'stored' | 'deflate';
|
|
40
|
+
mediaType?: string;
|
|
41
|
+
}
|
|
42
|
+
interface EpubContainer {
|
|
43
|
+
resources: Map<string, Resource>;
|
|
44
|
+
rootfiles: string[];
|
|
45
|
+
hasEncryption: boolean;
|
|
46
|
+
}
|
|
47
|
+
declare function openEpub(input: Uint8Array | ArrayBuffer | ReadableStream<Uint8Array>): Promise<EpubContainer>;
|
|
48
|
+
declare function getResource(container: EpubContainer, path: string): Resource | undefined;
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/io/xml.d.ts
|
|
51
|
+
interface XmlNode {
|
|
52
|
+
type: 'element' | 'text';
|
|
53
|
+
name?: string;
|
|
54
|
+
ns?: string;
|
|
55
|
+
attrs?: Record<string, string>;
|
|
56
|
+
children?: XmlNode[];
|
|
57
|
+
text?: string;
|
|
58
|
+
loc: Location;
|
|
59
|
+
}
|
|
60
|
+
declare function parseXml(bytes: Uint8Array, path: string): {
|
|
61
|
+
root?: XmlNode;
|
|
62
|
+
messages: Message[];
|
|
63
|
+
};
|
|
64
|
+
/** Element children of a node (text nodes filtered out). */
|
|
65
|
+
declare function childElements(node: XmlNode): XmlNode[];
|
|
66
|
+
/** All descendant elements (any depth) whose local name matches. */
|
|
67
|
+
declare function findDescendants(node: XmlNode, localName: string): XmlNode[];
|
|
68
|
+
/** All descendant text content of a node, concatenated (not trimmed). */
|
|
69
|
+
declare function textContent(node: XmlNode): string;
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/checks/ocf.d.ts
|
|
72
|
+
declare function validateOcf(container: EpubContainer): Message[];
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/parse/opf.d.ts
|
|
75
|
+
interface DcIdentifier {
|
|
76
|
+
id?: string;
|
|
77
|
+
value: string;
|
|
78
|
+
}
|
|
79
|
+
interface Metadata {
|
|
80
|
+
identifiers: DcIdentifier[];
|
|
81
|
+
titles: string[];
|
|
82
|
+
languages: string[];
|
|
83
|
+
modifiedCount: number;
|
|
84
|
+
}
|
|
85
|
+
interface ManifestItem {
|
|
86
|
+
id?: string;
|
|
87
|
+
href?: string;
|
|
88
|
+
mediaType?: string;
|
|
89
|
+
properties: string[];
|
|
90
|
+
fallback?: string;
|
|
91
|
+
loc: Location;
|
|
92
|
+
}
|
|
93
|
+
interface SpineItem {
|
|
94
|
+
idref?: string;
|
|
95
|
+
linear: boolean;
|
|
96
|
+
properties: string[];
|
|
97
|
+
loc: Location;
|
|
98
|
+
}
|
|
99
|
+
interface PackageDocument {
|
|
100
|
+
path: string;
|
|
101
|
+
version?: string;
|
|
102
|
+
uniqueIdentifier?: string;
|
|
103
|
+
metadata: Metadata;
|
|
104
|
+
manifest: ManifestItem[];
|
|
105
|
+
spinePresent: boolean;
|
|
106
|
+
spine: SpineItem[];
|
|
107
|
+
loc: Location;
|
|
108
|
+
}
|
|
109
|
+
declare function parseOpf(container: EpubContainer): {
|
|
110
|
+
pkg?: PackageDocument;
|
|
111
|
+
messages: Message[];
|
|
112
|
+
};
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/checks/opf.d.ts
|
|
115
|
+
declare function validateOpf(pkg: PackageDocument, container: EpubContainer): Message[];
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/parse/nav.d.ts
|
|
118
|
+
interface NavSection {
|
|
119
|
+
types: string[];
|
|
120
|
+
node: XmlNode;
|
|
121
|
+
loc: Location;
|
|
122
|
+
}
|
|
123
|
+
interface NavDocument {
|
|
124
|
+
path: string;
|
|
125
|
+
root: XmlNode;
|
|
126
|
+
sections: NavSection[];
|
|
127
|
+
loc: Location;
|
|
128
|
+
}
|
|
129
|
+
declare function parseNav(navItem: ManifestItem, container: EpubContainer): {
|
|
130
|
+
nav?: NavDocument;
|
|
131
|
+
messages: Message[];
|
|
132
|
+
};
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/checks/nav.d.ts
|
|
135
|
+
declare function validateNav(nav: NavDocument, pkg: PackageDocument, container: EpubContainer): Message[];
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/parse/content.d.ts
|
|
138
|
+
type RefType = 'hyperlink' | 'image' | 'audio' | 'video' | 'stylesheet' | 'generic' | 'cite' | 'track';
|
|
139
|
+
interface ContentRef {
|
|
140
|
+
url: string;
|
|
141
|
+
type: RefType;
|
|
142
|
+
loc: Location;
|
|
143
|
+
/**
|
|
144
|
+
* True when the referencing context itself supplies a fallback (e.g. an
|
|
145
|
+
* <img> inside <picture>, a <source> inside <audio>, an <object> with
|
|
146
|
+
* fallback content). Used to suppress RSC-032.
|
|
147
|
+
*/
|
|
148
|
+
hasIntrinsicFallback: boolean;
|
|
149
|
+
}
|
|
150
|
+
interface InlineStyle {
|
|
151
|
+
context: 'stylesheet' | 'declarationList';
|
|
152
|
+
text: string;
|
|
153
|
+
loc: Location;
|
|
154
|
+
}
|
|
155
|
+
interface ContentDocument {
|
|
156
|
+
path: string;
|
|
157
|
+
root: XmlNode;
|
|
158
|
+
refs: ContentRef[];
|
|
159
|
+
ids: Set<string>;
|
|
160
|
+
/** id attribute value → 1-based ordinal among id-bearing elements in document order (first occurrence wins). */
|
|
161
|
+
idPositions: Map<string, number>;
|
|
162
|
+
inlineStyles: InlineStyle[];
|
|
163
|
+
}
|
|
164
|
+
declare function parseContent(item: ManifestItem, container: EpubContainer): {
|
|
165
|
+
doc?: ContentDocument;
|
|
166
|
+
messages: Message[];
|
|
167
|
+
};
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/checks/content.d.ts
|
|
170
|
+
declare function validateContentDocs(pkg: PackageDocument, container: EpubContainer): Message[];
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/parse/css.d.ts
|
|
173
|
+
type CssRefType = 'generic' | 'font' | 'import';
|
|
174
|
+
interface CssRef {
|
|
175
|
+
url: string;
|
|
176
|
+
type: CssRefType;
|
|
177
|
+
loc: Location;
|
|
178
|
+
}
|
|
179
|
+
interface CssDeclaration {
|
|
180
|
+
property: string;
|
|
181
|
+
value: string;
|
|
182
|
+
loc: Location;
|
|
183
|
+
}
|
|
184
|
+
interface FontFace {
|
|
185
|
+
declarationCount: number;
|
|
186
|
+
loc: Location;
|
|
187
|
+
}
|
|
188
|
+
interface CssDocument {
|
|
189
|
+
path: string;
|
|
190
|
+
refs: CssRef[];
|
|
191
|
+
declarations: CssDeclaration[];
|
|
192
|
+
fontFaces: FontFace[];
|
|
193
|
+
}
|
|
194
|
+
interface CssAnalysis {
|
|
195
|
+
parsed: boolean;
|
|
196
|
+
refs: CssRef[];
|
|
197
|
+
declarations: CssDeclaration[];
|
|
198
|
+
fontFaces: FontFace[];
|
|
199
|
+
messages: Message[];
|
|
200
|
+
}
|
|
201
|
+
declare function analyzeCss(text: string, path: string, context: 'stylesheet' | 'declarationList'): CssAnalysis;
|
|
202
|
+
declare function parseCss(item: ManifestItem, container: EpubContainer): {
|
|
203
|
+
css?: CssDocument;
|
|
204
|
+
messages: Message[];
|
|
205
|
+
};
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/checks/css.d.ts
|
|
208
|
+
declare function validateCss(css: CssDocument, container: EpubContainer, manifest: Map<string, ManifestItem>): Message[];
|
|
209
|
+
declare function validateCssDocs(pkg: PackageDocument, container: EpubContainer): Message[];
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/index.d.ts
|
|
212
|
+
declare const VERSION: string;
|
|
213
|
+
//#endregion
|
|
214
|
+
export { type ContentDocument, type ContentRef, type CssAnalysis, type CssDeclaration, type CssDocument, type CssRef, type CssRefType, type DcIdentifier, type EpubContainer, type FontFace, type InlineStyle, type Location, type ManifestItem, type Message, type Metadata, type NavDocument, type NavSection, type PackageDocument, type RefType, type Report, type Resource, type Severity, type SpineItem, VERSION, type ValidateOptions, type XmlNode, analyzeCss, buildReport, childElements, findDescendants, getResource, msg, openEpub, parseContent, parseCss, parseNav, parseOpf, parseXml, textContent, validateContentDocs, validateCss, validateCssDocs, validateEpub, validateNav, validateOcf, validateOpf };
|