@likecoin/epubcheck-ts 0.4.0 → 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
@@ -1649,6 +1649,8 @@ interface ManifestItem {
1649
1649
  mediaType: string;
1650
1650
  /** Fallback item ID for non-standard media types */
1651
1651
  fallback?: string;
1652
+ /** Fallback stylesheet item ID (EPUB 2 only) */
1653
+ fallbackStyle?: string;
1652
1654
  /** Media overlay ID */
1653
1655
  mediaOverlay?: string;
1654
1656
  /** Item properties (EPUB 3) - e.g., 'nav', 'scripted', 'svg', 'remote-resources' */
@@ -1731,6 +1733,8 @@ interface LinkElement {
1731
1733
  interface PackageDocument {
1732
1734
  /** EPUB version from package@version */
1733
1735
  version: EPUBVersion;
1736
+ /** Whether the package@version attribute was present in the source (omitted = true) */
1737
+ versionDeclared?: boolean;
1734
1738
  /** Unique identifier reference (package@unique-identifier) */
1735
1739
  uniqueIdentifier: string;
1736
1740
  /** Package prefix declarations (EPUB 3) */
@@ -1772,6 +1776,10 @@ interface Collection {
1772
1776
  name?: string;
1773
1777
  /** Resource hrefs in this collection (from link elements) */
1774
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;
1775
1783
  }
1776
1784
 
1777
1785
  /**
@@ -1781,11 +1789,16 @@ type Severity = 'fatal' | 'error' | 'warning' | 'info' | 'usage';
1781
1789
  /**
1782
1790
  * Supported EPUB versions
1783
1791
  */
1784
- type EPUBVersion = '2.0' | '3.0' | '3.1' | '3.2' | '3.3';
1792
+ declare const EPUB_VERSIONS: readonly ["2.0", "3.0", "3.1", "3.2", "3.3"];
1793
+ type EPUBVersion = (typeof EPUB_VERSIONS)[number];
1785
1794
  /**
1786
1795
  * EPUB validation profiles
1787
1796
  */
1788
1797
  type EPUBProfile = 'default' | 'edupub' | 'idx' | 'dict' | 'preview';
1798
+ /**
1799
+ * Validation modes for single-file and expanded directory validation
1800
+ */
1801
+ type ValidationMode = 'exp' | 'opf' | 'xhtml' | 'svg' | 'nav' | 'mo';
1789
1802
  /**
1790
1803
  * Location within an EPUB file
1791
1804
  */
@@ -1845,6 +1858,8 @@ interface EpubCheckOptions {
1845
1858
  version?: EPUBVersion;
1846
1859
  /** Validation profile */
1847
1860
  profile?: EPUBProfile;
1861
+ /** Validation mode for single-file or expanded directory validation */
1862
+ mode?: ValidationMode;
1848
1863
  /** Whether to include usage messages */
1849
1864
  includeUsage?: boolean;
1850
1865
  /** Whether to include info messages */
@@ -1856,6 +1871,10 @@ interface EpubCheckOptions {
1856
1871
  /** Custom message severity overrides (message ID → severity) */
1857
1872
  customMessages?: Map<string, MessageSeverity>;
1858
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'>;
1859
1878
  /**
1860
1879
  * Internal validation context passed through the validation pipeline
1861
1880
  */
@@ -1863,7 +1882,7 @@ interface ValidationContext {
1863
1882
  /** EPUB file data */
1864
1883
  data: Uint8Array;
1865
1884
  /** Validation options */
1866
- options: Required<EpubCheckOptions>;
1885
+ options: ResolvedEpubCheckOptions;
1867
1886
  /** Detected EPUB version */
1868
1887
  version: EPUBVersion;
1869
1888
  /** Validation messages collected so far */
@@ -1954,17 +1973,42 @@ declare class EpubCheck {
1954
1973
  * Validate an EPUB file
1955
1974
  *
1956
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
1957
1984
  * @returns Validation result
1958
1985
  */
1959
- check(data: Uint8Array): Promise<EpubCheckResult>;
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>;
1960
1995
  /**
1961
1996
  * Static method to validate an EPUB file with default options
1962
1997
  *
1963
1998
  * @param data - The EPUB file as a Uint8Array
1964
1999
  * @param options - Optional validation options
2000
+ * @param filename - Optional filename, used for file-extension checks
1965
2001
  * @returns Validation result
1966
2002
  */
1967
- static validate(data: Uint8Array, options?: EpubCheckOptions): Promise<EpubCheckResult>;
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>;
1968
2012
  /**
1969
2013
  * Get the current EPUB version being validated against
1970
2014
  */
@@ -1993,6 +2037,42 @@ declare class EpubCheck {
1993
2037
  * Check if a manifest item has a fallback chain reaching a Core Media Type
1994
2038
  */
1995
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;
1996
2076
  }
1997
2077
 
1998
2078
  /**
@@ -2038,4 +2118,4 @@ interface SchemaValidator {
2038
2118
  dispose(): void;
2039
2119
  }
2040
2120
 
2041
- 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, parseCustomMessages, 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 };
package/dist/index.d.ts CHANGED
@@ -1649,6 +1649,8 @@ interface ManifestItem {
1649
1649
  mediaType: string;
1650
1650
  /** Fallback item ID for non-standard media types */
1651
1651
  fallback?: string;
1652
+ /** Fallback stylesheet item ID (EPUB 2 only) */
1653
+ fallbackStyle?: string;
1652
1654
  /** Media overlay ID */
1653
1655
  mediaOverlay?: string;
1654
1656
  /** Item properties (EPUB 3) - e.g., 'nav', 'scripted', 'svg', 'remote-resources' */
@@ -1731,6 +1733,8 @@ interface LinkElement {
1731
1733
  interface PackageDocument {
1732
1734
  /** EPUB version from package@version */
1733
1735
  version: EPUBVersion;
1736
+ /** Whether the package@version attribute was present in the source (omitted = true) */
1737
+ versionDeclared?: boolean;
1734
1738
  /** Unique identifier reference (package@unique-identifier) */
1735
1739
  uniqueIdentifier: string;
1736
1740
  /** Package prefix declarations (EPUB 3) */
@@ -1772,6 +1776,10 @@ interface Collection {
1772
1776
  name?: string;
1773
1777
  /** Resource hrefs in this collection (from link elements) */
1774
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;
1775
1783
  }
1776
1784
 
1777
1785
  /**
@@ -1781,11 +1789,16 @@ type Severity = 'fatal' | 'error' | 'warning' | 'info' | 'usage';
1781
1789
  /**
1782
1790
  * Supported EPUB versions
1783
1791
  */
1784
- type EPUBVersion = '2.0' | '3.0' | '3.1' | '3.2' | '3.3';
1792
+ declare const EPUB_VERSIONS: readonly ["2.0", "3.0", "3.1", "3.2", "3.3"];
1793
+ type EPUBVersion = (typeof EPUB_VERSIONS)[number];
1785
1794
  /**
1786
1795
  * EPUB validation profiles
1787
1796
  */
1788
1797
  type EPUBProfile = 'default' | 'edupub' | 'idx' | 'dict' | 'preview';
1798
+ /**
1799
+ * Validation modes for single-file and expanded directory validation
1800
+ */
1801
+ type ValidationMode = 'exp' | 'opf' | 'xhtml' | 'svg' | 'nav' | 'mo';
1789
1802
  /**
1790
1803
  * Location within an EPUB file
1791
1804
  */
@@ -1845,6 +1858,8 @@ interface EpubCheckOptions {
1845
1858
  version?: EPUBVersion;
1846
1859
  /** Validation profile */
1847
1860
  profile?: EPUBProfile;
1861
+ /** Validation mode for single-file or expanded directory validation */
1862
+ mode?: ValidationMode;
1848
1863
  /** Whether to include usage messages */
1849
1864
  includeUsage?: boolean;
1850
1865
  /** Whether to include info messages */
@@ -1856,6 +1871,10 @@ interface EpubCheckOptions {
1856
1871
  /** Custom message severity overrides (message ID → severity) */
1857
1872
  customMessages?: Map<string, MessageSeverity>;
1858
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'>;
1859
1878
  /**
1860
1879
  * Internal validation context passed through the validation pipeline
1861
1880
  */
@@ -1863,7 +1882,7 @@ interface ValidationContext {
1863
1882
  /** EPUB file data */
1864
1883
  data: Uint8Array;
1865
1884
  /** Validation options */
1866
- options: Required<EpubCheckOptions>;
1885
+ options: ResolvedEpubCheckOptions;
1867
1886
  /** Detected EPUB version */
1868
1887
  version: EPUBVersion;
1869
1888
  /** Validation messages collected so far */
@@ -1954,17 +1973,42 @@ declare class EpubCheck {
1954
1973
  * Validate an EPUB file
1955
1974
  *
1956
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
1957
1984
  * @returns Validation result
1958
1985
  */
1959
- check(data: Uint8Array): Promise<EpubCheckResult>;
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>;
1960
1995
  /**
1961
1996
  * Static method to validate an EPUB file with default options
1962
1997
  *
1963
1998
  * @param data - The EPUB file as a Uint8Array
1964
1999
  * @param options - Optional validation options
2000
+ * @param filename - Optional filename, used for file-extension checks
1965
2001
  * @returns Validation result
1966
2002
  */
1967
- static validate(data: Uint8Array, options?: EpubCheckOptions): Promise<EpubCheckResult>;
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>;
1968
2012
  /**
1969
2013
  * Get the current EPUB version being validated against
1970
2014
  */
@@ -1993,6 +2037,42 @@ declare class EpubCheck {
1993
2037
  * Check if a manifest item has a fallback chain reaching a Core Media Type
1994
2038
  */
1995
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;
1996
2076
  }
1997
2077
 
1998
2078
  /**
@@ -2038,4 +2118,4 @@ interface SchemaValidator {
2038
2118
  dispose(): void;
2039
2119
  }
2040
2120
 
2041
- 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, parseCustomMessages, 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 };