@likecoin/epubcheck-ts 0.3.9 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,363 +1,3 @@
1
- /**
2
- * Represents a manifest item in the OPF
3
- */
4
- interface ManifestItem {
5
- /** Unique identifier for this item */
6
- id: string;
7
- /** Path relative to the OPF file */
8
- href: string;
9
- /** MIME media type */
10
- mediaType: string;
11
- /** Fallback item ID for non-standard media types */
12
- fallback?: string;
13
- /** Media overlay ID */
14
- mediaOverlay?: string;
15
- /** Item properties (EPUB 3) - e.g., 'nav', 'scripted', 'svg', 'remote-resources' */
16
- properties?: string[];
17
- }
18
- /**
19
- * Represents a spine itemref in the OPF
20
- */
21
- interface SpineItemRef {
22
- /** Optional ID attribute on the itemref element */
23
- id?: string;
24
- /** Reference to manifest item ID */
25
- idref: string;
26
- /** Whether this item is part of the linear reading order */
27
- linear: boolean;
28
- /** Itemref properties (EPUB 3) - e.g., 'page-spread-left', 'page-spread-right' */
29
- properties?: string[];
30
- }
31
- /**
32
- * Represents a guide reference (EPUB 2)
33
- */
34
- interface GuideReference {
35
- /** Type of reference (cover, toc, etc.) */
36
- type: string;
37
- /** Title for display */
38
- title?: string;
39
- /** Path to the referenced item */
40
- href: string;
41
- }
42
- /**
43
- * Dublin Core metadata element
44
- */
45
- interface DCElement {
46
- /** The element name (title, creator, identifier, etc.) */
47
- name: string;
48
- /** The text content */
49
- value: string;
50
- /** The id attribute, if any */
51
- id?: string;
52
- /** Additional attributes */
53
- attributes?: Record<string, string>;
54
- }
55
- /**
56
- * EPUB 3 meta element
57
- */
58
- interface MetaElement {
59
- /** Property name (with optional prefix) */
60
- property: string;
61
- /** The text content */
62
- value: string;
63
- /** ID of the element this meta refines */
64
- refines?: string;
65
- /** Scheme for the value */
66
- scheme?: string;
67
- /** The id attribute, if any */
68
- id?: string;
69
- }
70
- /**
71
- * EPUB 3 link element
72
- */
73
- interface LinkElement {
74
- /** Relationship type */
75
- rel: string;
76
- /** URL to the linked resource */
77
- href: string;
78
- /** Media type of the linked resource */
79
- mediaType?: string;
80
- /** ID of the element this link refines */
81
- refines?: string;
82
- /** Link properties */
83
- properties?: string[];
84
- /** The id attribute, if any */
85
- id?: string;
86
- /** Language tag for the linked resource */
87
- hreflang?: string;
88
- }
89
- /**
90
- * Parsed OPF package document
91
- */
92
- interface PackageDocument {
93
- /** EPUB version from package@version */
94
- version: EPUBVersion;
95
- /** Unique identifier reference (package@unique-identifier) */
96
- uniqueIdentifier: string;
97
- /** Package prefix declarations (EPUB 3) */
98
- prefixes?: Record<string, string>;
99
- /** Package direction (rtl, ltr, auto) */
100
- dir?: string;
101
- /** Dublin Core metadata elements */
102
- dcElements: DCElement[];
103
- /** EPUB 3 meta elements */
104
- metaElements: MetaElement[];
105
- /** EPUB 3 link elements */
106
- linkElements: LinkElement[];
107
- /** Manifest items */
108
- manifest: ManifestItem[];
109
- /** Spine item references */
110
- spine: SpineItemRef[];
111
- /** Spine toc attribute (NCX reference for EPUB 2) */
112
- spineToc?: string;
113
- /** Spine page-progression-direction */
114
- pageProgressionDirection?: 'ltr' | 'rtl' | 'default';
115
- /** Guide references (EPUB 2) */
116
- guide: GuideReference[];
117
- /** Collections (EPUB 3) */
118
- collections: Collection[];
119
- /** Whether the bindings element is present (deprecated in EPUB 3.3) */
120
- hasBindings?: boolean;
121
- /** xml:lang attribute on elements (for validation) */
122
- xmlLangs?: string[];
123
- }
124
- /**
125
- * Represents a collection in the OPF (EPUB 3)
126
- */
127
- interface Collection {
128
- /** Collection role (dictionary, index, preview, etc.) */
129
- role: string;
130
- /** Collection identifier */
131
- id?: string;
132
- /** Collection name/label */
133
- name?: string;
134
- /** Resource hrefs in this collection (from link elements) */
135
- links: string[];
136
- }
137
-
138
- /**
139
- * Severity levels for validation messages
140
- */
141
- type Severity = 'fatal' | 'error' | 'warning' | 'info' | 'usage';
142
- /**
143
- * Supported EPUB versions
144
- */
145
- type EPUBVersion = '2.0' | '3.0' | '3.1' | '3.2' | '3.3';
146
- /**
147
- * EPUB validation profiles
148
- */
149
- type EPUBProfile = 'default' | 'edupub' | 'idx' | 'dict' | 'preview';
150
- /**
151
- * Location within an EPUB file
152
- */
153
- interface EPUBLocation {
154
- /** Path to the file within the EPUB container */
155
- path: string;
156
- /** Line number (1-based), if applicable */
157
- line?: number;
158
- /** Column number (1-based), if applicable */
159
- column?: number;
160
- /** Additional context about the location */
161
- context?: string;
162
- }
163
- /**
164
- * A validation message (error, warning, etc.)
165
- */
166
- interface ValidationMessage {
167
- /** Unique message identifier */
168
- id: string;
169
- /** Severity level */
170
- severity: Severity;
171
- /** Human-readable message */
172
- message: string;
173
- /** Location where the issue was found */
174
- location?: EPUBLocation;
175
- /** Suggestion for fixing the issue */
176
- suggestion?: string;
177
- }
178
- /**
179
- * Result of EPUB validation
180
- */
181
- interface EpubCheckResult {
182
- /** Whether the EPUB is valid (no errors or fatal errors) */
183
- valid: boolean;
184
- /** All validation messages */
185
- messages: ValidationMessage[];
186
- /** Count of fatal errors */
187
- fatalCount: number;
188
- /** Count of errors */
189
- errorCount: number;
190
- /** Count of warnings */
191
- warningCount: number;
192
- /** Count of info messages */
193
- infoCount: number;
194
- /** Count of usage messages */
195
- usageCount: number;
196
- /** Detected EPUB version */
197
- version?: EPUBVersion | undefined;
198
- /** Time taken for validation in milliseconds */
199
- elapsedMs: number;
200
- }
201
- /**
202
- * Options for EpubCheck
203
- */
204
- interface EpubCheckOptions {
205
- /** EPUB version to validate against (auto-detected if not specified) */
206
- version?: EPUBVersion;
207
- /** Validation profile */
208
- profile?: EPUBProfile;
209
- /** Whether to include usage messages */
210
- includeUsage?: boolean;
211
- /** Whether to include info messages */
212
- includeInfo?: boolean;
213
- /** Maximum number of errors before stopping (0 = unlimited) */
214
- maxErrors?: number;
215
- /** Locale for messages (e.g., 'en', 'de', 'fr') */
216
- locale?: string;
217
- }
218
- /**
219
- * Internal validation context passed through the validation pipeline
220
- */
221
- interface ValidationContext {
222
- /** EPUB file data */
223
- data: Uint8Array;
224
- /** Validation options */
225
- options: Required<EpubCheckOptions>;
226
- /** Detected EPUB version */
227
- version: EPUBVersion;
228
- /** Validation messages collected so far */
229
- messages: ValidationMessage[];
230
- /** Files extracted from EPUB container */
231
- files: Map<string, Uint8Array>;
232
- /** Rootfiles found in container.xml */
233
- rootfiles: Rootfile[];
234
- /** Path to the package document (OPF) */
235
- opfPath?: string;
236
- /** Parsed package document */
237
- packageDocument?: PackageDocument;
238
- /** NCX UID for validation against OPF identifier */
239
- ncxUid?: string;
240
- /** Resources referenced in content but not declared in manifest */
241
- referencedUndeclaredResources?: Set<string>;
242
- /** TOC navigation link targets in order, for reading order validation (NAV-011) */
243
- tocLinks?: {
244
- targetResource: string;
245
- fragment?: string;
246
- location: EPUBLocation;
247
- }[];
248
- /** Media overlay text link targets in order, for reading order validation (MED-015) */
249
- overlayTextLinks?: {
250
- targetResource: string;
251
- fragment?: string;
252
- location: EPUBLocation;
253
- }[];
254
- /** OPF media:active-class value (if declared) */
255
- mediaActiveClass?: string;
256
- /** OPF media:playback-active-class value (if declared) */
257
- mediaPlaybackActiveClass?: string;
258
- /** Resources marked with IDPF font obfuscation in encryption.xml */
259
- obfuscatedResources?: Set<string>;
260
- }
261
- /**
262
- * Rootfile reference from container.xml
263
- */
264
- interface Rootfile {
265
- path: string;
266
- mediaType: string;
267
- }
268
-
269
- /**
270
- * Main EPUB validation class
271
- *
272
- * @example
273
- * ```typescript
274
- * import { EpubCheck } from 'epubcheck-ts';
275
- *
276
- * // Validate from a Uint8Array (works in Node.js and browsers)
277
- * const result = await EpubCheck.validate(epubData);
278
- *
279
- * if (result.valid) {
280
- * console.log('EPUB is valid!');
281
- * } else {
282
- * console.log(`Found ${result.errorCount} errors`);
283
- * for (const msg of result.messages) {
284
- * console.log(`${msg.severity}: ${msg.message}`);
285
- * }
286
- * }
287
- * ```
288
- */
289
- declare class EpubCheck {
290
- private readonly options;
291
- /**
292
- * Create a new EpubCheck instance with custom options
293
- */
294
- constructor(options?: EpubCheckOptions);
295
- /**
296
- * Validate an EPUB file
297
- *
298
- * @param data - The EPUB file as a Uint8Array
299
- * @returns Validation result
300
- */
301
- check(data: Uint8Array): Promise<EpubCheckResult>;
302
- /**
303
- * Static method to validate an EPUB file with default options
304
- *
305
- * @param data - The EPUB file as a Uint8Array
306
- * @param options - Optional validation options
307
- * @returns Validation result
308
- */
309
- static validate(data: Uint8Array, options?: EpubCheckOptions): Promise<EpubCheckResult>;
310
- /**
311
- * Get the current EPUB version being validated against
312
- */
313
- get version(): EPUBVersion;
314
- /**
315
- * Validate NCX navigation document (EPUB 2 always, EPUB 3 when NCX present)
316
- */
317
- private validateNCX;
318
- /**
319
- * Add a validation message to the context
320
- */
321
- protected addMessage(messages: ValidationMessage[], message: ValidationMessage): void;
322
- /**
323
- * Validate that obfuscated resources are blessed font types (PKG-026)
324
- */
325
- private validateObfuscatedResources;
326
- /**
327
- * Populate resource registry from package document manifest
328
- */
329
- private populateRegistry;
330
- /**
331
- * Check if a manifest item has a fallback chain reaching a Core Media Type
332
- */
333
- private hasCMTFallback;
334
- }
335
-
336
- /**
337
- * Build a validation result from messages
338
- */
339
- declare function buildReport(messages: ValidationMessage[], version: EPUBVersion | undefined, elapsedMs: number): EpubCheckResult;
340
- /**
341
- * Count messages by severity
342
- */
343
- declare function countBySeverity(messages: ValidationMessage[]): Record<Severity, number>;
344
- /**
345
- * Filter messages by severity
346
- */
347
- declare function filterBySeverity(messages: ValidationMessage[], severity: Severity): ValidationMessage[];
348
- /**
349
- * Filter messages by path
350
- */
351
- declare function filterByPath(messages: ValidationMessage[], path: string): ValidationMessage[];
352
- /**
353
- * Format messages as a string for display
354
- */
355
- declare function formatMessages(messages: ValidationMessage[]): string;
356
- /**
357
- * Convert result to JSON report format (compatible with EPUBCheck JSON output)
358
- */
359
- declare function toJSONReport(result: EpubCheckResult): string;
360
-
361
1
  /**
362
2
  * Message Definitions for EPUB validation errors and warnings
363
3
  *
@@ -1926,62 +1566,539 @@ interface MessageInfo {
1926
1566
  /**
1927
1567
  * Get message info by ID
1928
1568
  */
1929
- declare function getMessageInfo(id: string): MessageInfo | undefined;
1569
+ declare function getMessageInfo(id: string): MessageInfo | undefined;
1570
+ /**
1571
+ * Get default severity for a message ID
1572
+ */
1573
+ declare function getDefaultSeverity(id: string): MessageSeverity;
1574
+ /**
1575
+ * Get all message definitions as an array (for iteration/display)
1576
+ */
1577
+ declare function getAllMessages(): readonly MessageInfo[];
1578
+ /**
1579
+ * Format message list for console output
1580
+ */
1581
+ declare function formatMessageList(): string;
1582
+ /**
1583
+ * Options for creating a validation message
1584
+ */
1585
+ interface CreateMessageOptions {
1586
+ /** Message ID from MessageId enum */
1587
+ id: MessageId;
1588
+ /** Human-readable message */
1589
+ message: string;
1590
+ /** Location where the issue was found */
1591
+ location?: EPUBLocation;
1592
+ /** Suggestion for fixing the issue */
1593
+ suggestion?: string;
1594
+ /** Override the default severity (use sparingly) */
1595
+ severityOverride?: Severity;
1596
+ }
1597
+ /**
1598
+ * Create a validation message with automatic severity lookup
1599
+ *
1600
+ * @example
1601
+ * ```typescript
1602
+ * const msg = createMessage({
1603
+ * id: MessageId.PKG_006,
1604
+ * message: 'Missing mimetype file',
1605
+ * location: { path: 'mimetype' },
1606
+ * });
1607
+ * if (msg) context.messages.push(msg);
1608
+ * ```
1609
+ */
1610
+ declare function createMessage(options: CreateMessageOptions): ValidationMessage | null;
1611
+ /**
1612
+ * Create and push a validation message to the messages array.
1613
+ * Automatically handles suppressed messages by not pushing them.
1614
+ *
1615
+ * @example
1616
+ * ```typescript
1617
+ * pushMessage(context.messages, {
1618
+ * id: MessageId.PKG_006,
1619
+ * message: 'Missing mimetype file',
1620
+ * location: { path: 'mimetype' },
1621
+ * });
1622
+ * ```
1623
+ */
1624
+ declare function pushMessage(messages: ValidationMessage[], options: CreateMessageOptions): void;
1625
+ /**
1626
+ * Parse a custom messages file (TSV format compatible with Java EPUBCheck).
1627
+ *
1628
+ * Format: one override per line, tab-separated: `ID\tSEVERITY`
1629
+ * Lines starting with # are comments. A header line starting with "id" is skipped.
1630
+ *
1631
+ * @example
1632
+ * ```
1633
+ * ACC-004\tWARNING
1634
+ * ACC-005\tWARNING
1635
+ * RSC-008\tSUPPRESSED
1636
+ * ```
1637
+ */
1638
+ declare function parseCustomMessages(content: string): Map<string, MessageSeverity>;
1639
+
1640
+ /**
1641
+ * Represents a manifest item in the OPF
1642
+ */
1643
+ interface ManifestItem {
1644
+ /** Unique identifier for this item */
1645
+ id: string;
1646
+ /** Path relative to the OPF file */
1647
+ href: string;
1648
+ /** MIME media type */
1649
+ mediaType: string;
1650
+ /** Fallback item ID for non-standard media types */
1651
+ fallback?: string;
1652
+ /** Fallback stylesheet item ID (EPUB 2 only) */
1653
+ fallbackStyle?: string;
1654
+ /** Media overlay ID */
1655
+ mediaOverlay?: string;
1656
+ /** Item properties (EPUB 3) - e.g., 'nav', 'scripted', 'svg', 'remote-resources' */
1657
+ properties?: string[];
1658
+ }
1659
+ /**
1660
+ * Represents a spine itemref in the OPF
1661
+ */
1662
+ interface SpineItemRef {
1663
+ /** Optional ID attribute on the itemref element */
1664
+ id?: string;
1665
+ /** Reference to manifest item ID */
1666
+ idref: string;
1667
+ /** Whether this item is part of the linear reading order */
1668
+ linear: boolean;
1669
+ /** Itemref properties (EPUB 3) - e.g., 'page-spread-left', 'page-spread-right' */
1670
+ properties?: string[];
1671
+ }
1672
+ /**
1673
+ * Represents a guide reference (EPUB 2)
1674
+ */
1675
+ interface GuideReference {
1676
+ /** Type of reference (cover, toc, etc.) */
1677
+ type: string;
1678
+ /** Title for display */
1679
+ title?: string;
1680
+ /** Path to the referenced item */
1681
+ href: string;
1682
+ }
1683
+ /**
1684
+ * Dublin Core metadata element
1685
+ */
1686
+ interface DCElement {
1687
+ /** The element name (title, creator, identifier, etc.) */
1688
+ name: string;
1689
+ /** The text content */
1690
+ value: string;
1691
+ /** The id attribute, if any */
1692
+ id?: string;
1693
+ /** Additional attributes */
1694
+ attributes?: Record<string, string>;
1695
+ }
1696
+ /**
1697
+ * EPUB 3 meta element
1698
+ */
1699
+ interface MetaElement {
1700
+ /** Property name (with optional prefix) */
1701
+ property: string;
1702
+ /** The text content */
1703
+ value: string;
1704
+ /** ID of the element this meta refines */
1705
+ refines?: string;
1706
+ /** Scheme for the value */
1707
+ scheme?: string;
1708
+ /** The id attribute, if any */
1709
+ id?: string;
1710
+ }
1711
+ /**
1712
+ * EPUB 3 link element
1713
+ */
1714
+ interface LinkElement {
1715
+ /** Relationship type */
1716
+ rel: string;
1717
+ /** URL to the linked resource */
1718
+ href: string;
1719
+ /** Media type of the linked resource */
1720
+ mediaType?: string;
1721
+ /** ID of the element this link refines */
1722
+ refines?: string;
1723
+ /** Link properties */
1724
+ properties?: string[];
1725
+ /** The id attribute, if any */
1726
+ id?: string;
1727
+ /** Language tag for the linked resource */
1728
+ hreflang?: string;
1729
+ }
1730
+ /**
1731
+ * Parsed OPF package document
1732
+ */
1733
+ interface PackageDocument {
1734
+ /** EPUB version from package@version */
1735
+ version: EPUBVersion;
1736
+ /** Whether the package@version attribute was present in the source (omitted = true) */
1737
+ versionDeclared?: boolean;
1738
+ /** Unique identifier reference (package@unique-identifier) */
1739
+ uniqueIdentifier: string;
1740
+ /** Package prefix declarations (EPUB 3) */
1741
+ prefixes?: Record<string, string>;
1742
+ /** Package direction (rtl, ltr, auto) */
1743
+ dir?: string;
1744
+ /** Dublin Core metadata elements */
1745
+ dcElements: DCElement[];
1746
+ /** EPUB 3 meta elements */
1747
+ metaElements: MetaElement[];
1748
+ /** EPUB 3 link elements */
1749
+ linkElements: LinkElement[];
1750
+ /** Manifest items */
1751
+ manifest: ManifestItem[];
1752
+ /** Spine item references */
1753
+ spine: SpineItemRef[];
1754
+ /** Spine toc attribute (NCX reference for EPUB 2) */
1755
+ spineToc?: string;
1756
+ /** Spine page-progression-direction */
1757
+ pageProgressionDirection?: 'ltr' | 'rtl' | 'default';
1758
+ /** Guide references (EPUB 2) */
1759
+ guide: GuideReference[];
1760
+ /** Collections (EPUB 3) */
1761
+ collections: Collection[];
1762
+ /** Whether the bindings element is present (deprecated in EPUB 3.3) */
1763
+ hasBindings?: boolean;
1764
+ /** xml:lang attribute on elements (for validation) */
1765
+ xmlLangs?: string[];
1766
+ }
1767
+ /**
1768
+ * Represents a collection in the OPF (EPUB 3)
1769
+ */
1770
+ interface Collection {
1771
+ /** Collection role (dictionary, index, preview, etc.) */
1772
+ role: string;
1773
+ /** Collection identifier */
1774
+ id?: string;
1775
+ /** Collection name/label */
1776
+ name?: string;
1777
+ /** Resource hrefs in this collection (from link elements) */
1778
+ links: string[];
1779
+ /** Nested sub-collections (EPUB 3) */
1780
+ children: Collection[];
1781
+ /** Raw XML inside this collection's tags (used for targeted sub-checks) */
1782
+ innerXml?: string;
1783
+ }
1784
+
1785
+ /**
1786
+ * Severity levels for validation messages
1787
+ */
1788
+ type Severity = 'fatal' | 'error' | 'warning' | 'info' | 'usage';
1789
+ /**
1790
+ * Supported EPUB versions
1791
+ */
1792
+ declare const EPUB_VERSIONS: readonly ["2.0", "3.0", "3.1", "3.2", "3.3"];
1793
+ type EPUBVersion = (typeof EPUB_VERSIONS)[number];
1930
1794
  /**
1931
- * Get default severity for a message ID
1795
+ * EPUB validation profiles
1932
1796
  */
1933
- declare function getDefaultSeverity(id: string): MessageSeverity;
1797
+ type EPUBProfile = 'default' | 'edupub' | 'idx' | 'dict' | 'preview';
1934
1798
  /**
1935
- * Get all message definitions as an array (for iteration/display)
1799
+ * Validation modes for single-file and expanded directory validation
1936
1800
  */
1937
- declare function getAllMessages(): readonly MessageInfo[];
1801
+ type ValidationMode = 'exp' | 'opf' | 'xhtml' | 'svg' | 'nav' | 'mo';
1938
1802
  /**
1939
- * Format message list for console output
1803
+ * Location within an EPUB file
1940
1804
  */
1941
- declare function formatMessageList(): string;
1805
+ interface EPUBLocation {
1806
+ /** Path to the file within the EPUB container */
1807
+ path: string;
1808
+ /** Line number (1-based), if applicable */
1809
+ line?: number;
1810
+ /** Column number (1-based), if applicable */
1811
+ column?: number;
1812
+ /** Additional context about the location */
1813
+ context?: string;
1814
+ }
1942
1815
  /**
1943
- * Options for creating a validation message
1816
+ * A validation message (error, warning, etc.)
1944
1817
  */
1945
- interface CreateMessageOptions {
1946
- /** Message ID from MessageId enum */
1947
- id: MessageId;
1818
+ interface ValidationMessage {
1819
+ /** Unique message identifier */
1820
+ id: string;
1821
+ /** Severity level */
1822
+ severity: Severity;
1948
1823
  /** Human-readable message */
1949
1824
  message: string;
1950
1825
  /** Location where the issue was found */
1951
1826
  location?: EPUBLocation;
1952
1827
  /** Suggestion for fixing the issue */
1953
1828
  suggestion?: string;
1954
- /** Override the default severity (use sparingly) */
1955
- severityOverride?: Severity;
1956
1829
  }
1957
1830
  /**
1958
- * Create a validation message with automatic severity lookup
1959
- *
1960
- * @example
1961
- * ```typescript
1962
- * const msg = createMessage({
1963
- * id: MessageId.PKG_006,
1964
- * message: 'Missing mimetype file',
1965
- * location: { path: 'mimetype' },
1966
- * });
1967
- * if (msg) context.messages.push(msg);
1968
- * ```
1831
+ * Result of EPUB validation
1969
1832
  */
1970
- declare function createMessage(options: CreateMessageOptions): ValidationMessage | null;
1833
+ interface EpubCheckResult {
1834
+ /** Whether the EPUB is valid (no errors or fatal errors) */
1835
+ valid: boolean;
1836
+ /** All validation messages */
1837
+ messages: ValidationMessage[];
1838
+ /** Count of fatal errors */
1839
+ fatalCount: number;
1840
+ /** Count of errors */
1841
+ errorCount: number;
1842
+ /** Count of warnings */
1843
+ warningCount: number;
1844
+ /** Count of info messages */
1845
+ infoCount: number;
1846
+ /** Count of usage messages */
1847
+ usageCount: number;
1848
+ /** Detected EPUB version */
1849
+ version?: EPUBVersion | undefined;
1850
+ /** Time taken for validation in milliseconds */
1851
+ elapsedMs: number;
1852
+ }
1971
1853
  /**
1972
- * Create and push a validation message to the messages array.
1973
- * Automatically handles suppressed messages by not pushing them.
1854
+ * Options for EpubCheck
1855
+ */
1856
+ interface EpubCheckOptions {
1857
+ /** EPUB version to validate against (auto-detected if not specified) */
1858
+ version?: EPUBVersion;
1859
+ /** Validation profile */
1860
+ profile?: EPUBProfile;
1861
+ /** Validation mode for single-file or expanded directory validation */
1862
+ mode?: ValidationMode;
1863
+ /** Whether to include usage messages */
1864
+ includeUsage?: boolean;
1865
+ /** Whether to include info messages */
1866
+ includeInfo?: boolean;
1867
+ /** Maximum number of errors before stopping (0 = unlimited) */
1868
+ maxErrors?: number;
1869
+ /** Locale for messages (e.g., 'en', 'de', 'fr') */
1870
+ locale?: string;
1871
+ /** Custom message severity overrides (message ID → severity) */
1872
+ customMessages?: Map<string, MessageSeverity>;
1873
+ }
1874
+ /**
1875
+ * EpubCheckOptions with all fields required except mode (which is inherently optional)
1876
+ */
1877
+ type ResolvedEpubCheckOptions = Required<Omit<EpubCheckOptions, 'mode'>> & Pick<EpubCheckOptions, 'mode'>;
1878
+ /**
1879
+ * Internal validation context passed through the validation pipeline
1880
+ */
1881
+ interface ValidationContext {
1882
+ /** EPUB file data */
1883
+ data: Uint8Array;
1884
+ /** Validation options */
1885
+ options: ResolvedEpubCheckOptions;
1886
+ /** Detected EPUB version */
1887
+ version: EPUBVersion;
1888
+ /** Validation messages collected so far */
1889
+ messages: ValidationMessage[];
1890
+ /** Files extracted from EPUB container */
1891
+ files: Map<string, Uint8Array>;
1892
+ /** Rootfiles found in container.xml */
1893
+ rootfiles: Rootfile[];
1894
+ /** Path to the package document (OPF) */
1895
+ opfPath?: string;
1896
+ /** Parsed package document */
1897
+ packageDocument?: PackageDocument;
1898
+ /** NCX UID for validation against OPF identifier */
1899
+ ncxUid?: string;
1900
+ /** Resources referenced in content but not declared in manifest */
1901
+ referencedUndeclaredResources?: Set<string>;
1902
+ /** TOC navigation link targets in order, for reading order validation (NAV-011) */
1903
+ tocLinks?: {
1904
+ targetResource: string;
1905
+ fragment?: string;
1906
+ location: EPUBLocation;
1907
+ }[];
1908
+ /** Media overlay text link targets in order, for reading order validation (MED-015) */
1909
+ overlayTextLinks?: {
1910
+ targetResource: string;
1911
+ fragment?: string;
1912
+ location: EPUBLocation;
1913
+ }[];
1914
+ /** OPF media:active-class value (if declared) */
1915
+ mediaActiveClass?: string;
1916
+ /** OPF media:playback-active-class value (if declared) */
1917
+ mediaPlaybackActiveClass?: string;
1918
+ /** Resources marked with IDPF font obfuscation in encryption.xml */
1919
+ obfuscatedResources?: Set<string>;
1920
+ /** Feature flags collected during content validation for cross-document checks */
1921
+ contentFeatures?: {
1922
+ hasPageBreak?: boolean;
1923
+ hasPageList?: boolean;
1924
+ hasTable?: boolean;
1925
+ hasFigure?: boolean;
1926
+ hasAudio?: boolean;
1927
+ hasVideo?: boolean;
1928
+ hasDictionary?: boolean;
1929
+ hasIndex?: boolean;
1930
+ hasLOI?: boolean;
1931
+ hasLOT?: boolean;
1932
+ hasLOA?: boolean;
1933
+ hasLOV?: boolean;
1934
+ hasMicrodata?: boolean;
1935
+ hasRDFa?: boolean;
1936
+ };
1937
+ }
1938
+ /**
1939
+ * Rootfile reference from container.xml
1940
+ */
1941
+ interface Rootfile {
1942
+ path: string;
1943
+ mediaType: string;
1944
+ }
1945
+
1946
+ /**
1947
+ * Main EPUB validation class
1974
1948
  *
1975
1949
  * @example
1976
1950
  * ```typescript
1977
- * pushMessage(context.messages, {
1978
- * id: MessageId.PKG_006,
1979
- * message: 'Missing mimetype file',
1980
- * location: { path: 'mimetype' },
1981
- * });
1951
+ * import { EpubCheck } from 'epubcheck-ts';
1952
+ *
1953
+ * // Validate from a Uint8Array (works in Node.js and browsers)
1954
+ * const result = await EpubCheck.validate(epubData);
1955
+ *
1956
+ * if (result.valid) {
1957
+ * console.log('EPUB is valid!');
1958
+ * } else {
1959
+ * console.log(`Found ${result.errorCount} errors`);
1960
+ * for (const msg of result.messages) {
1961
+ * console.log(`${msg.severity}: ${msg.message}`);
1962
+ * }
1963
+ * }
1982
1964
  * ```
1983
1965
  */
1984
- declare function pushMessage(messages: ValidationMessage[], options: CreateMessageOptions): void;
1966
+ declare class EpubCheck {
1967
+ private readonly options;
1968
+ /**
1969
+ * Create a new EpubCheck instance with custom options
1970
+ */
1971
+ constructor(options?: EpubCheckOptions);
1972
+ /**
1973
+ * Validate an EPUB file
1974
+ *
1975
+ * @param data - The EPUB file as a Uint8Array
1976
+ * @param filename - Optional filename, used for file-extension checks (PKG-016/017/024)
1977
+ * @returns Validation result
1978
+ */
1979
+ check(data: Uint8Array, filename?: string): Promise<EpubCheckResult>;
1980
+ /**
1981
+ * Validate an expanded EPUB directory (pre-read file map)
1982
+ *
1983
+ * @param files - Map of relative file paths to their content
1984
+ * @returns Validation result
1985
+ */
1986
+ checkExpanded(files: Map<string, Uint8Array>): Promise<EpubCheckResult>;
1987
+ /**
1988
+ * Validate a single file (OPF, XHTML, etc.) without a full EPUB container
1989
+ *
1990
+ * @param data - The file content
1991
+ * @param filename - The filename (used for path in messages)
1992
+ * @returns Validation result
1993
+ */
1994
+ checkSingleFile(data: Uint8Array, filename: string): Promise<EpubCheckResult>;
1995
+ /**
1996
+ * Static method to validate an EPUB file with default options
1997
+ *
1998
+ * @param data - The EPUB file as a Uint8Array
1999
+ * @param options - Optional validation options
2000
+ * @param filename - Optional filename, used for file-extension checks
2001
+ * @returns Validation result
2002
+ */
2003
+ static validate(data: Uint8Array, options?: EpubCheckOptions, filename?: string): Promise<EpubCheckResult>;
2004
+ /**
2005
+ * Static method to validate an expanded EPUB (pre-read file map)
2006
+ */
2007
+ static validateExpanded(files: Map<string, Uint8Array>, options?: EpubCheckOptions): Promise<EpubCheckResult>;
2008
+ /**
2009
+ * Static method to validate a single file
2010
+ */
2011
+ static validateSingleFile(data: Uint8Array, filename: string, options?: EpubCheckOptions): Promise<EpubCheckResult>;
2012
+ /**
2013
+ * Get the current EPUB version being validated against
2014
+ */
2015
+ get version(): EPUBVersion;
2016
+ /**
2017
+ * Cross-document feature validation (Pattern B from Java EPUBCheck)
2018
+ */
2019
+ private validateCrossDocumentFeatures;
2020
+ /**
2021
+ * Validate NCX navigation document (EPUB 2 always, EPUB 3 when NCX present)
2022
+ */
2023
+ private validateNCX;
2024
+ /**
2025
+ * Add a validation message to the context
2026
+ */
2027
+ protected addMessage(messages: ValidationMessage[], message: ValidationMessage): void;
2028
+ /**
2029
+ * Validate that obfuscated resources are blessed font types (PKG-026)
2030
+ */
2031
+ private validateObfuscatedResources;
2032
+ /**
2033
+ * Populate resource registry from package document manifest
2034
+ */
2035
+ private populateRegistry;
2036
+ /**
2037
+ * Check if a manifest item has a fallback chain reaching a Core Media Type
2038
+ */
2039
+ private hasCMTFallback;
2040
+ /**
2041
+ * Shared validation pipeline (Steps 2-7) used by both check() and checkExpanded()
2042
+ */
2043
+ private runPipeline;
2044
+ /**
2045
+ * Check DOCTYPE external identifiers (OPF-073).
2046
+ *
2047
+ * Mirrors Java's DeclarationHandler: external identifiers (PUBLIC/SYSTEM)
2048
+ * must not appear in DOCTYPE declarations except for specific media-type
2049
+ * combinations (SVG 1.1, MathML 3.0, NCX 2005-1).
2050
+ */
2051
+ private checkExternalIdentifiers;
2052
+ /**
2053
+ * Check file extension for EPUB naming conventions.
2054
+ *
2055
+ * Mirrors Java's OCFExtensionChecker (src/main/java/com/adobe/epubcheck/ocf/OCFExtensionChecker.java):
2056
+ * - PKG-016 (warning): case-variant of "epub" (e.g. ".ePub", ".EPUB")
2057
+ * - PKG-017 (EPUB 2) / PKG-024 (EPUB 3): non-epub extension
2058
+ */
2059
+ private checkFilenameExtension;
2060
+ /**
2061
+ * Build a filtered report from validation context
2062
+ */
2063
+ private buildFilteredReport;
2064
+ /**
2065
+ * Validate mimetype file content for expanded EPUB (no ZIP-specific checks)
2066
+ */
2067
+ private validateExpandedMimetype;
2068
+ /**
2069
+ * Parse container.xml from context.files to find rootfiles and opfPath
2070
+ */
2071
+ private parseContainerXml;
2072
+ /**
2073
+ * Validate filenames for expanded EPUB
2074
+ */
2075
+ private validateExpandedFilenames;
2076
+ }
2077
+
2078
+ /**
2079
+ * Build a validation result from messages
2080
+ */
2081
+ declare function buildReport(messages: ValidationMessage[], version: EPUBVersion | undefined, elapsedMs: number): EpubCheckResult;
2082
+ /**
2083
+ * Count messages by severity
2084
+ */
2085
+ declare function countBySeverity(messages: ValidationMessage[]): Record<Severity, number>;
2086
+ /**
2087
+ * Filter messages by severity
2088
+ */
2089
+ declare function filterBySeverity(messages: ValidationMessage[], severity: Severity): ValidationMessage[];
2090
+ /**
2091
+ * Filter messages by path
2092
+ */
2093
+ declare function filterByPath(messages: ValidationMessage[], path: string): ValidationMessage[];
2094
+ /**
2095
+ * Format messages as a string for display
2096
+ */
2097
+ declare function formatMessages(messages: ValidationMessage[]): string;
2098
+ /**
2099
+ * Convert result to JSON report format (compatible with EPUBCheck JSON output)
2100
+ */
2101
+ declare function toJSONReport(result: EpubCheckResult): string;
1985
2102
 
1986
2103
  /**
1987
2104
  * Interface for schema validators
@@ -2001,4 +2118,4 @@ interface SchemaValidator {
2001
2118
  dispose(): void;
2002
2119
  }
2003
2120
 
2004
- export { type CreateMessageOptions, type EPUBProfile, type EPUBVersion, EpubCheck, type EpubCheckOptions, type EpubCheckResult, MessageId, type MessageInfo, type MessageSeverity, type SchemaValidator, type Severity, type ValidationContext, type ValidationMessage, buildReport, countBySeverity, createMessage, filterByPath, filterBySeverity, formatMessageList, formatMessages, getAllMessages, getDefaultSeverity, getMessageInfo, pushMessage, toJSONReport };
2121
+ export { type CreateMessageOptions, type EPUBProfile, type EPUBVersion, EPUB_VERSIONS, EpubCheck, type EpubCheckOptions, type EpubCheckResult, MessageId, type MessageInfo, type MessageSeverity, type ResolvedEpubCheckOptions, type SchemaValidator, type Severity, type ValidationContext, type ValidationMessage, type ValidationMode, buildReport, countBySeverity, createMessage, filterByPath, filterBySeverity, formatMessageList, formatMessages, getAllMessages, getDefaultSeverity, getMessageInfo, parseCustomMessages, pushMessage, toJSONReport };