epub-codec 0.0.0 → 1.0.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/LICENSE +21 -0
- package/README.md +184 -0
- package/dist/codec.cjs +28 -0
- package/dist/codec.d.cts +2308 -0
- package/dist/codec.d.ts +2308 -0
- package/dist/codec.js +25 -0
- package/dist/diagnostics-Ee4kG7mw.d.cts +60 -0
- package/dist/diagnostics-Ee4kG7mw.d.ts +60 -0
- package/dist/diagnostics.cjs +96 -0
- package/dist/diagnostics.d.cts +2 -0
- package/dist/diagnostics.d.ts +2 -0
- package/dist/diagnostics.js +85 -0
- package/dist/format.cjs +9 -0
- package/dist/format.d.cts +6 -0
- package/dist/format.d.ts +6 -0
- package/dist/format.js +6 -0
- package/dist/image/dimensions.cjs +82 -0
- package/dist/image/dimensions.d.cts +11 -0
- package/dist/image/dimensions.d.ts +11 -0
- package/dist/image/dimensions.js +79 -0
- package/dist/index.cjs +105 -0
- package/dist/index.d.cts +32 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +32 -0
- package/dist/nav/nav3.cjs +19 -0
- package/dist/nav/nav3.d.cts +4 -0
- package/dist/nav/nav3.d.ts +4 -0
- package/dist/nav/nav3.js +18 -0
- package/dist/nav/ncx.cjs +17 -0
- package/dist/nav/ncx.d.cts +4 -0
- package/dist/nav/ncx.d.ts +4 -0
- package/dist/nav/ncx.js +16 -0
- package/dist/nav/reconcile.cjs +8 -0
- package/dist/nav/reconcile.d.cts +4 -0
- package/dist/nav/reconcile.d.ts +4 -0
- package/dist/nav/reconcile.js +7 -0
- package/dist/nav/write.cjs +39 -0
- package/dist/nav/write.d.cts +10 -0
- package/dist/nav/write.d.ts +10 -0
- package/dist/nav/write.js +37 -0
- package/dist/ocf/container.cjs +20 -0
- package/dist/ocf/container.d.cts +4 -0
- package/dist/ocf/container.d.ts +4 -0
- package/dist/ocf/container.js +19 -0
- package/dist/ocf/write.cjs +13 -0
- package/dist/ocf/write.d.cts +4 -0
- package/dist/ocf/write.d.ts +4 -0
- package/dist/ocf/write.js +12 -0
- package/dist/opf/metadata.cjs +51 -0
- package/dist/opf/metadata.d.cts +7 -0
- package/dist/opf/metadata.d.ts +7 -0
- package/dist/opf/metadata.js +50 -0
- package/dist/opf/parse.cjs +47 -0
- package/dist/opf/parse.d.cts +6 -0
- package/dist/opf/parse.d.ts +6 -0
- package/dist/opf/parse.js +46 -0
- package/dist/opf/types.cjs +0 -0
- package/dist/opf/types.d.cts +20 -0
- package/dist/opf/types.d.ts +20 -0
- package/dist/opf/types.js +0 -0
- package/dist/opf/write.cjs +55 -0
- package/dist/opf/write.d.cts +12 -0
- package/dist/opf/write.d.ts +12 -0
- package/dist/opf/write.js +54 -0
- package/dist/path.cjs +22 -0
- package/dist/path.d.cts +5 -0
- package/dist/path.d.ts +5 -0
- package/dist/path.js +20 -0
- package/dist/read.cjs +166 -0
- package/dist/read.d.cts +10 -0
- package/dist/read.d.ts +10 -0
- package/dist/read.js +164 -0
- package/dist/util/base64.cjs +51 -0
- package/dist/util/base64.d.cts +5 -0
- package/dist/util/base64.d.ts +5 -0
- package/dist/util/base64.js +49 -0
- package/dist/write.cjs +136 -0
- package/dist/write.d.cts +10 -0
- package/dist/write.d.ts +10 -0
- package/dist/write.js +134 -0
- package/dist/xhtml/context.cjs +0 -0
- package/dist/xhtml/context.d.cts +20 -0
- package/dist/xhtml/context.d.ts +20 -0
- package/dist/xhtml/context.js +0 -0
- package/dist/xhtml/footnote.cjs +32 -0
- package/dist/xhtml/footnote.d.cts +7 -0
- package/dist/xhtml/footnote.d.ts +7 -0
- package/dist/xhtml/footnote.js +29 -0
- package/dist/xhtml/inline.cjs +128 -0
- package/dist/xhtml/inline.d.cts +11 -0
- package/dist/xhtml/inline.d.ts +11 -0
- package/dist/xhtml/inline.js +127 -0
- package/dist/xhtml/list-id.cjs +22 -0
- package/dist/xhtml/list-id.d.cts +13 -0
- package/dist/xhtml/list-id.d.ts +13 -0
- package/dist/xhtml/list-id.js +20 -0
- package/dist/xhtml/read.cjs +423 -0
- package/dist/xhtml/read.d.cts +20 -0
- package/dist/xhtml/read.d.ts +20 -0
- package/dist/xhtml/read.js +422 -0
- package/dist/xhtml/style-constants.cjs +13 -0
- package/dist/xhtml/style-constants.d.cts +8 -0
- package/dist/xhtml/style-constants.d.ts +8 -0
- package/dist/xhtml/style-constants.js +8 -0
- package/dist/xhtml/write.cjs +183 -0
- package/dist/xhtml/write.d.cts +12 -0
- package/dist/xhtml/write.d.ts +12 -0
- package/dist/xhtml/write.js +182 -0
- package/dist/xml/build.cjs +46 -0
- package/dist/xml/build.d.cts +5 -0
- package/dist/xml/build.d.ts +5 -0
- package/dist/xml/build.js +46 -0
- package/dist/xml/entities.cjs +20 -0
- package/dist/xml/entities.d.cts +5 -0
- package/dist/xml/entities.d.ts +5 -0
- package/dist/xml/entities.js +18 -0
- package/dist/xml/node.cjs +67 -0
- package/dist/xml/node.d.cts +83 -0
- package/dist/xml/node.d.ts +83 -0
- package/dist/xml/node.js +58 -0
- package/dist/xml/parse.cjs +88 -0
- package/dist/xml/parse.d.cts +5 -0
- package/dist/xml/parse.d.ts +5 -0
- package/dist/xml/parse.js +88 -0
- package/dist/xml/query.cjs +44 -0
- package/dist/xml/query.d.cts +11 -0
- package/dist/xml/query.d.ts +11 -0
- package/dist/xml/query.js +37 -0
- package/dist/zip.cjs +19 -0
- package/dist/zip.d.cts +9 -0
- package/dist/zip.d.ts +9 -0
- package/dist/zip.js +17 -0
- package/package.json +95 -2
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { EpubBytesSchema, epubCodec, epubContentCodec } from "./codec.cjs";
|
|
2
|
+
import { a as EpubEmptySpineError, c as EpubInvalidOpfError, d as EpubUnbalancedConstructMarkersError, f as EpubUnsupportedDocumentKindError, i as EpubDiagnosticSink, l as EpubPackageFlattenError, m as NOOP_EPUB_DIAGNOSTIC_SINK, n as EpubDiagnosticCodes, o as EpubInvalidContainerError, p as EpubWriteError, r as EpubDiagnosticSeverity, s as EpubInvalidMimetypeError, t as EpubDiagnostic, u as EpubParseError } from "./diagnostics-Ee4kG7mw.cjs";
|
|
3
|
+
import { EPUB_MIME_TYPE, OCF_CONTAINER_PATH, OCF_MIMETYPE_PATH } from "./format.cjs";
|
|
4
|
+
import { EpubImageFormat, ImageDimensions, POINTS_PER_PIXEL, detectImageFormat, readImageDimensions } from "./image/dimensions.cjs";
|
|
5
|
+
import { ZipEntry, unzipPackage, zipPackage } from "./zip.cjs";
|
|
6
|
+
import { resolveOpfPath } from "./ocf/container.cjs";
|
|
7
|
+
import { OpfManifestItem, OpfPackage, OpfSpineItemRef } from "./opf/types.cjs";
|
|
8
|
+
import { Attribute, AttributeSchema, XmlCdata, XmlCdataSchema, XmlComment, XmlCommentSchema, XmlDeclaration, XmlDeclarationSchema, XmlElement, XmlElementSchema, XmlNode, XmlNodeSchema, XmlPi, XmlPiSchema, XmlText, XmlTextSchema, isXmlNode } from "./xml/node.cjs";
|
|
9
|
+
import { readOpfMetadata } from "./opf/metadata.cjs";
|
|
10
|
+
import { parseOpf } from "./opf/parse.cjs";
|
|
11
|
+
import { WriteOpfInput, writeOpf } from "./opf/write.cjs";
|
|
12
|
+
import { base64ToBytes, bytesToBase64 } from "./util/base64.cjs";
|
|
13
|
+
import { InlineStyle, XhtmlReadContext } from "./xhtml/context.cjs";
|
|
14
|
+
import { isFootnoteAside, isFootnoteReferenceAnchor, sameDocumentFragment } from "./xhtml/footnote.cjs";
|
|
15
|
+
import { InlineResult, buildInlineRuns } from "./xhtml/inline.cjs";
|
|
16
|
+
import { ListNumIdInfo, MintListNumIdOptions, mintListNumId, parseListNumId } from "./xhtml/list-id.cjs";
|
|
17
|
+
import { ReadXhtmlBodyOptions, ReadXhtmlBodyResult, readXhtmlBody } from "./xhtml/read.cjs";
|
|
18
|
+
import { DEFINITION_BODY_INDENT_PT, HORIZONTAL_RULE_STYLE_ID, MONOSPACE_FONT_FAMILY, QUOTE_INDENT_PT, QUOTE_STYLE_ID } from "./xhtml/style-constants.cjs";
|
|
19
|
+
import { XhtmlWriteContext, writeXhtmlBody } from "./xhtml/write.cjs";
|
|
20
|
+
import { readNav3TocHrefs } from "./nav/nav3.cjs";
|
|
21
|
+
import { readNcxHrefs } from "./nav/ncx.cjs";
|
|
22
|
+
import { navMatchesSpine } from "./nav/reconcile.cjs";
|
|
23
|
+
import { NavSectionEntry, sectionTitle, writeNav3Document } from "./nav/write.cjs";
|
|
24
|
+
import { writeContainerXml } from "./ocf/write.cjs";
|
|
25
|
+
import { dirname, resolvePackagePath } from "./path.cjs";
|
|
26
|
+
import { ReadEpubOptions, readEpub, readEpubContent } from "./read.cjs";
|
|
27
|
+
import { WriteEpubOptions, writeEpub, writeEpubContent } from "./write.cjs";
|
|
28
|
+
import { parseXml } from "./xml/parse.cjs";
|
|
29
|
+
import { buildXml } from "./xml/build.cjs";
|
|
30
|
+
import { attrValue, childrenWithTag, elementsWithTag, findChildElement, findElement, rootElement, textContent } from "./xml/query.cjs";
|
|
31
|
+
import { decodeEntities, encodeEntities } from "./xml/entities.cjs";
|
|
32
|
+
export { Attribute, AttributeSchema, DEFINITION_BODY_INDENT_PT, EPUB_MIME_TYPE, EpubBytesSchema, EpubDiagnostic, EpubDiagnosticCodes, EpubDiagnosticSeverity, EpubDiagnosticSink, EpubEmptySpineError, EpubImageFormat, EpubInvalidContainerError, EpubInvalidMimetypeError, EpubInvalidOpfError, EpubPackageFlattenError, EpubParseError, EpubUnbalancedConstructMarkersError, EpubUnsupportedDocumentKindError, EpubWriteError, HORIZONTAL_RULE_STYLE_ID, ImageDimensions, InlineResult, InlineStyle, ListNumIdInfo, MONOSPACE_FONT_FAMILY, MintListNumIdOptions, NOOP_EPUB_DIAGNOSTIC_SINK, NavSectionEntry, OCF_CONTAINER_PATH, OCF_MIMETYPE_PATH, OpfManifestItem, OpfPackage, OpfSpineItemRef, POINTS_PER_PIXEL, QUOTE_INDENT_PT, QUOTE_STYLE_ID, ReadEpubOptions, ReadXhtmlBodyOptions, ReadXhtmlBodyResult, WriteEpubOptions, WriteOpfInput, XhtmlReadContext, XhtmlWriteContext, XmlCdata, XmlCdataSchema, XmlComment, XmlCommentSchema, XmlDeclaration, XmlDeclarationSchema, XmlElement, XmlElementSchema, XmlNode, XmlNodeSchema, XmlPi, XmlPiSchema, XmlText, XmlTextSchema, ZipEntry, attrValue, base64ToBytes, buildInlineRuns, buildXml, bytesToBase64, childrenWithTag, decodeEntities, detectImageFormat, dirname, elementsWithTag, encodeEntities, epubCodec, epubContentCodec, findChildElement, findElement, isFootnoteAside, isFootnoteReferenceAnchor, isXmlNode, mintListNumId, navMatchesSpine, parseListNumId, parseOpf, parseXml, readEpub, readEpubContent, readImageDimensions, readNav3TocHrefs, readNcxHrefs, readOpfMetadata, readXhtmlBody, resolveOpfPath, resolvePackagePath, rootElement, sameDocumentFragment, sectionTitle, textContent, unzipPackage, writeContainerXml, writeEpub, writeEpubContent, writeNav3Document, writeOpf, writeXhtmlBody, zipPackage };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { EpubBytesSchema, epubCodec, epubContentCodec } from "./codec.js";
|
|
2
|
+
import { a as EpubEmptySpineError, c as EpubInvalidOpfError, d as EpubUnbalancedConstructMarkersError, f as EpubUnsupportedDocumentKindError, i as EpubDiagnosticSink, l as EpubPackageFlattenError, m as NOOP_EPUB_DIAGNOSTIC_SINK, n as EpubDiagnosticCodes, o as EpubInvalidContainerError, p as EpubWriteError, r as EpubDiagnosticSeverity, s as EpubInvalidMimetypeError, t as EpubDiagnostic, u as EpubParseError } from "./diagnostics-Ee4kG7mw.js";
|
|
3
|
+
import { EPUB_MIME_TYPE, OCF_CONTAINER_PATH, OCF_MIMETYPE_PATH } from "./format.js";
|
|
4
|
+
import { EpubImageFormat, ImageDimensions, POINTS_PER_PIXEL, detectImageFormat, readImageDimensions } from "./image/dimensions.js";
|
|
5
|
+
import { ZipEntry, unzipPackage, zipPackage } from "./zip.js";
|
|
6
|
+
import { resolveOpfPath } from "./ocf/container.js";
|
|
7
|
+
import { OpfManifestItem, OpfPackage, OpfSpineItemRef } from "./opf/types.js";
|
|
8
|
+
import { Attribute, AttributeSchema, XmlCdata, XmlCdataSchema, XmlComment, XmlCommentSchema, XmlDeclaration, XmlDeclarationSchema, XmlElement, XmlElementSchema, XmlNode, XmlNodeSchema, XmlPi, XmlPiSchema, XmlText, XmlTextSchema, isXmlNode } from "./xml/node.js";
|
|
9
|
+
import { readOpfMetadata } from "./opf/metadata.js";
|
|
10
|
+
import { parseOpf } from "./opf/parse.js";
|
|
11
|
+
import { WriteOpfInput, writeOpf } from "./opf/write.js";
|
|
12
|
+
import { base64ToBytes, bytesToBase64 } from "./util/base64.js";
|
|
13
|
+
import { InlineStyle, XhtmlReadContext } from "./xhtml/context.js";
|
|
14
|
+
import { isFootnoteAside, isFootnoteReferenceAnchor, sameDocumentFragment } from "./xhtml/footnote.js";
|
|
15
|
+
import { InlineResult, buildInlineRuns } from "./xhtml/inline.js";
|
|
16
|
+
import { ListNumIdInfo, MintListNumIdOptions, mintListNumId, parseListNumId } from "./xhtml/list-id.js";
|
|
17
|
+
import { ReadXhtmlBodyOptions, ReadXhtmlBodyResult, readXhtmlBody } from "./xhtml/read.js";
|
|
18
|
+
import { DEFINITION_BODY_INDENT_PT, HORIZONTAL_RULE_STYLE_ID, MONOSPACE_FONT_FAMILY, QUOTE_INDENT_PT, QUOTE_STYLE_ID } from "./xhtml/style-constants.js";
|
|
19
|
+
import { XhtmlWriteContext, writeXhtmlBody } from "./xhtml/write.js";
|
|
20
|
+
import { readNav3TocHrefs } from "./nav/nav3.js";
|
|
21
|
+
import { readNcxHrefs } from "./nav/ncx.js";
|
|
22
|
+
import { navMatchesSpine } from "./nav/reconcile.js";
|
|
23
|
+
import { NavSectionEntry, sectionTitle, writeNav3Document } from "./nav/write.js";
|
|
24
|
+
import { writeContainerXml } from "./ocf/write.js";
|
|
25
|
+
import { dirname, resolvePackagePath } from "./path.js";
|
|
26
|
+
import { ReadEpubOptions, readEpub, readEpubContent } from "./read.js";
|
|
27
|
+
import { WriteEpubOptions, writeEpub, writeEpubContent } from "./write.js";
|
|
28
|
+
import { parseXml } from "./xml/parse.js";
|
|
29
|
+
import { buildXml } from "./xml/build.js";
|
|
30
|
+
import { attrValue, childrenWithTag, elementsWithTag, findChildElement, findElement, rootElement, textContent } from "./xml/query.js";
|
|
31
|
+
import { decodeEntities, encodeEntities } from "./xml/entities.js";
|
|
32
|
+
export { Attribute, AttributeSchema, DEFINITION_BODY_INDENT_PT, EPUB_MIME_TYPE, EpubBytesSchema, EpubDiagnostic, EpubDiagnosticCodes, EpubDiagnosticSeverity, EpubDiagnosticSink, EpubEmptySpineError, EpubImageFormat, EpubInvalidContainerError, EpubInvalidMimetypeError, EpubInvalidOpfError, EpubPackageFlattenError, EpubParseError, EpubUnbalancedConstructMarkersError, EpubUnsupportedDocumentKindError, EpubWriteError, HORIZONTAL_RULE_STYLE_ID, ImageDimensions, InlineResult, InlineStyle, ListNumIdInfo, MONOSPACE_FONT_FAMILY, MintListNumIdOptions, NOOP_EPUB_DIAGNOSTIC_SINK, NavSectionEntry, OCF_CONTAINER_PATH, OCF_MIMETYPE_PATH, OpfManifestItem, OpfPackage, OpfSpineItemRef, POINTS_PER_PIXEL, QUOTE_INDENT_PT, QUOTE_STYLE_ID, ReadEpubOptions, ReadXhtmlBodyOptions, ReadXhtmlBodyResult, WriteEpubOptions, WriteOpfInput, XhtmlReadContext, XhtmlWriteContext, XmlCdata, XmlCdataSchema, XmlComment, XmlCommentSchema, XmlDeclaration, XmlDeclarationSchema, XmlElement, XmlElementSchema, XmlNode, XmlNodeSchema, XmlPi, XmlPiSchema, XmlText, XmlTextSchema, ZipEntry, attrValue, base64ToBytes, buildInlineRuns, buildXml, bytesToBase64, childrenWithTag, decodeEntities, detectImageFormat, dirname, elementsWithTag, encodeEntities, epubCodec, epubContentCodec, findChildElement, findElement, isFootnoteAside, isFootnoteReferenceAnchor, isXmlNode, mintListNumId, navMatchesSpine, parseListNumId, parseOpf, parseXml, readEpub, readEpubContent, readImageDimensions, readNav3TocHrefs, readNcxHrefs, readOpfMetadata, readXhtmlBody, resolveOpfPath, resolvePackagePath, rootElement, sameDocumentFragment, sectionTitle, textContent, unzipPackage, writeContainerXml, writeEpub, writeEpubContent, writeNav3Document, writeOpf, writeXhtmlBody, zipPackage };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { EpubDiagnosticCodes, EpubEmptySpineError, EpubInvalidContainerError, EpubInvalidMimetypeError, EpubInvalidOpfError, EpubPackageFlattenError, EpubParseError, EpubUnbalancedConstructMarkersError, EpubUnsupportedDocumentKindError, EpubWriteError, NOOP_EPUB_DIAGNOSTIC_SINK } from "./diagnostics.js";
|
|
2
|
+
import { attrValue, childrenWithTag, elementsWithTag, findChildElement, findElement, rootElement, textContent } from "./xml/query.js";
|
|
3
|
+
import { parseXml } from "./xml/parse.js";
|
|
4
|
+
import { resolveOpfPath } from "./ocf/container.js";
|
|
5
|
+
import { EPUB_MIME_TYPE, OCF_CONTAINER_PATH, OCF_MIMETYPE_PATH } from "./format.js";
|
|
6
|
+
import { readNav3TocHrefs } from "./nav/nav3.js";
|
|
7
|
+
import { readNcxHrefs } from "./nav/ncx.js";
|
|
8
|
+
import { navMatchesSpine } from "./nav/reconcile.js";
|
|
9
|
+
import { decodeEntities, encodeEntities } from "./xml/entities.js";
|
|
10
|
+
import { readOpfMetadata } from "./opf/metadata.js";
|
|
11
|
+
import { parseOpf } from "./opf/parse.js";
|
|
12
|
+
import { POINTS_PER_PIXEL, detectImageFormat, readImageDimensions } from "./image/dimensions.js";
|
|
13
|
+
import { base64ToBytes, bytesToBase64 } from "./util/base64.js";
|
|
14
|
+
import { buildXml } from "./xml/build.js";
|
|
15
|
+
import { isFootnoteAside, isFootnoteReferenceAnchor, sameDocumentFragment } from "./xhtml/footnote.js";
|
|
16
|
+
import { DEFINITION_BODY_INDENT_PT, HORIZONTAL_RULE_STYLE_ID, MONOSPACE_FONT_FAMILY, QUOTE_INDENT_PT, QUOTE_STYLE_ID } from "./xhtml/style-constants.js";
|
|
17
|
+
import { buildInlineRuns } from "./xhtml/inline.js";
|
|
18
|
+
import { mintListNumId, parseListNumId } from "./xhtml/list-id.js";
|
|
19
|
+
import { readXhtmlBody } from "./xhtml/read.js";
|
|
20
|
+
import { dirname, resolvePackagePath } from "./path.js";
|
|
21
|
+
import { unzipPackage, zipPackage } from "./zip.js";
|
|
22
|
+
import { readEpub, readEpubContent } from "./read.js";
|
|
23
|
+
import { writeContainerXml } from "./ocf/write.js";
|
|
24
|
+
import { sectionTitle, writeNav3Document } from "./nav/write.js";
|
|
25
|
+
import { writeOpf } from "./opf/write.js";
|
|
26
|
+
import { writeXhtmlBody } from "./xhtml/write.js";
|
|
27
|
+
import { writeEpub, writeEpubContent } from "./write.js";
|
|
28
|
+
import { EpubBytesSchema, epubCodec, epubContentCodec } from "./codec.js";
|
|
29
|
+
import "./opf/types.js";
|
|
30
|
+
import "./xhtml/context.js";
|
|
31
|
+
import { AttributeSchema, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPiSchema, XmlTextSchema, isXmlNode } from "./xml/node.js";
|
|
32
|
+
export { AttributeSchema, DEFINITION_BODY_INDENT_PT, EPUB_MIME_TYPE, EpubBytesSchema, EpubDiagnosticCodes, EpubEmptySpineError, EpubInvalidContainerError, EpubInvalidMimetypeError, EpubInvalidOpfError, EpubPackageFlattenError, EpubParseError, EpubUnbalancedConstructMarkersError, EpubUnsupportedDocumentKindError, EpubWriteError, HORIZONTAL_RULE_STYLE_ID, MONOSPACE_FONT_FAMILY, NOOP_EPUB_DIAGNOSTIC_SINK, OCF_CONTAINER_PATH, OCF_MIMETYPE_PATH, POINTS_PER_PIXEL, QUOTE_INDENT_PT, QUOTE_STYLE_ID, XmlCdataSchema, XmlCommentSchema, XmlDeclarationSchema, XmlElementSchema, XmlNodeSchema, XmlPiSchema, XmlTextSchema, attrValue, base64ToBytes, buildInlineRuns, buildXml, bytesToBase64, childrenWithTag, decodeEntities, detectImageFormat, dirname, elementsWithTag, encodeEntities, epubCodec, epubContentCodec, findChildElement, findElement, isFootnoteAside, isFootnoteReferenceAnchor, isXmlNode, mintListNumId, navMatchesSpine, parseListNumId, parseOpf, parseXml, readEpub, readEpubContent, readImageDimensions, readNav3TocHrefs, readNcxHrefs, readOpfMetadata, readXhtmlBody, resolveOpfPath, resolvePackagePath, rootElement, sameDocumentFragment, sectionTitle, textContent, unzipPackage, writeContainerXml, writeEpub, writeEpubContent, writeNav3Document, writeOpf, writeXhtmlBody, zipPackage };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_xml_query = require("../xml/query.cjs");
|
|
3
|
+
const require_xml_parse = require("../xml/parse.cjs");
|
|
4
|
+
//#region src/nav/nav3.ts
|
|
5
|
+
function readNav3TocHrefs(navXhtml) {
|
|
6
|
+
const nodes = require_xml_parse.parseXml(navXhtml);
|
|
7
|
+
const html = require_xml_query.rootElement(nodes);
|
|
8
|
+
const body = html === void 0 ? void 0 : require_xml_query.findChildElement(html.children, "body");
|
|
9
|
+
if (body === void 0) return;
|
|
10
|
+
const tocNav = require_xml_query.findElement(body.children, (element) => element.tag === "nav" && (require_xml_query.attrValue(element, "epub:type") ?? "").split(/\s+/u).includes("toc"));
|
|
11
|
+
if (tocNav === void 0) return;
|
|
12
|
+
return require_xml_query.elementsWithTag(tocNav.children, "a").map((a) => require_xml_query.attrValue(a, "href")).filter((href) => href !== void 0).map(stripFragment);
|
|
13
|
+
}
|
|
14
|
+
function stripFragment(href) {
|
|
15
|
+
const index = href.indexOf("#");
|
|
16
|
+
return index === -1 ? href : href.slice(0, index);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.readNav3TocHrefs = readNav3TocHrefs;
|
package/dist/nav/nav3.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { attrValue, elementsWithTag, findChildElement, findElement, rootElement } from "../xml/query.js";
|
|
2
|
+
import { parseXml } from "../xml/parse.js";
|
|
3
|
+
//#region src/nav/nav3.ts
|
|
4
|
+
function readNav3TocHrefs(navXhtml) {
|
|
5
|
+
const nodes = parseXml(navXhtml);
|
|
6
|
+
const html = rootElement(nodes);
|
|
7
|
+
const body = html === void 0 ? void 0 : findChildElement(html.children, "body");
|
|
8
|
+
if (body === void 0) return;
|
|
9
|
+
const tocNav = findElement(body.children, (element) => element.tag === "nav" && (attrValue(element, "epub:type") ?? "").split(/\s+/u).includes("toc"));
|
|
10
|
+
if (tocNav === void 0) return;
|
|
11
|
+
return elementsWithTag(tocNav.children, "a").map((a) => attrValue(a, "href")).filter((href) => href !== void 0).map(stripFragment);
|
|
12
|
+
}
|
|
13
|
+
function stripFragment(href) {
|
|
14
|
+
const index = href.indexOf("#");
|
|
15
|
+
return index === -1 ? href : href.slice(0, index);
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { readNav3TocHrefs };
|
package/dist/nav/ncx.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_xml_query = require("../xml/query.cjs");
|
|
3
|
+
const require_xml_parse = require("../xml/parse.cjs");
|
|
4
|
+
//#region src/nav/ncx.ts
|
|
5
|
+
function readNcxHrefs(ncxXml) {
|
|
6
|
+
const nodes = require_xml_parse.parseXml(ncxXml);
|
|
7
|
+
const root = require_xml_query.rootElement(nodes);
|
|
8
|
+
const navMap = root === void 0 ? void 0 : require_xml_query.findChildElement(root.children, "navMap");
|
|
9
|
+
if (navMap === void 0) return;
|
|
10
|
+
return require_xml_query.elementsWithTag(navMap.children, "content").map((el) => require_xml_query.attrValue(el, "src")).filter((src) => src !== void 0).map(stripFragment);
|
|
11
|
+
}
|
|
12
|
+
function stripFragment(href) {
|
|
13
|
+
const index = href.indexOf("#");
|
|
14
|
+
return index === -1 ? href : href.slice(0, index);
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.readNcxHrefs = readNcxHrefs;
|
package/dist/nav/ncx.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { attrValue, elementsWithTag, findChildElement, rootElement } from "../xml/query.js";
|
|
2
|
+
import { parseXml } from "../xml/parse.js";
|
|
3
|
+
//#region src/nav/ncx.ts
|
|
4
|
+
function readNcxHrefs(ncxXml) {
|
|
5
|
+
const nodes = parseXml(ncxXml);
|
|
6
|
+
const root = rootElement(nodes);
|
|
7
|
+
const navMap = root === void 0 ? void 0 : findChildElement(root.children, "navMap");
|
|
8
|
+
if (navMap === void 0) return;
|
|
9
|
+
return elementsWithTag(navMap.children, "content").map((el) => attrValue(el, "src")).filter((src) => src !== void 0).map(stripFragment);
|
|
10
|
+
}
|
|
11
|
+
function stripFragment(href) {
|
|
12
|
+
const index = href.indexOf("#");
|
|
13
|
+
return index === -1 ? href : href.slice(0, index);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { readNcxHrefs };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/nav/reconcile.ts
|
|
3
|
+
function navMatchesSpine(navHrefs, spineHrefs) {
|
|
4
|
+
if (navHrefs.length !== spineHrefs.length) return false;
|
|
5
|
+
return navHrefs.every((href, index) => href === spineHrefs[index]);
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.navMatchesSpine = navMatchesSpine;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_xml_entities = require("../xml/entities.cjs");
|
|
3
|
+
const require_xml_build = require("../xml/build.cjs");
|
|
4
|
+
//#region src/nav/write.ts
|
|
5
|
+
function element(tag, attrs = {}, children = []) {
|
|
6
|
+
return {
|
|
7
|
+
type: "element",
|
|
8
|
+
tag,
|
|
9
|
+
attributes: Object.entries(attrs).map(([name, value]) => ({
|
|
10
|
+
name,
|
|
11
|
+
value
|
|
12
|
+
})),
|
|
13
|
+
children
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function text(value) {
|
|
17
|
+
return {
|
|
18
|
+
type: "text",
|
|
19
|
+
value: require_xml_entities.encodeEntities(value)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function sectionTitle(section, index) {
|
|
23
|
+
for (const block of section.blocks) if (block.kind === "paragraph" && block.headingLevel !== void 0) {
|
|
24
|
+
const label = block.runs.map((run) => run.text).join("");
|
|
25
|
+
if (label.trim().length > 0) return label;
|
|
26
|
+
}
|
|
27
|
+
return `Section ${String(index + 1)}`;
|
|
28
|
+
}
|
|
29
|
+
function writeNav3Document(entries) {
|
|
30
|
+
const items = entries.map((entry, index) => element("li", {}, [element("a", { href: entry.href }, [text(sectionTitle(entry.section, index))])]));
|
|
31
|
+
const html = element("html", {
|
|
32
|
+
xmlns: "http://www.w3.org/1999/xhtml",
|
|
33
|
+
"xmlns:epub": "http://www.idpf.org/2007/ops"
|
|
34
|
+
}, [element("body", {}, [element("nav", { "epub:type": "toc" }, [element("h1", {}, [text("Table of Contents")]), element("ol", {}, items)])])]);
|
|
35
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n${require_xml_build.buildXml([html])}`;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.sectionTitle = sectionTitle;
|
|
39
|
+
exports.writeNav3Document = writeNav3Document;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ContentSection } from "document-schema.js";
|
|
2
|
+
//#region src/nav/write.d.ts
|
|
3
|
+
interface NavSectionEntry {
|
|
4
|
+
readonly href: string;
|
|
5
|
+
readonly section: ContentSection;
|
|
6
|
+
}
|
|
7
|
+
declare function sectionTitle(section: ContentSection, index: number): string;
|
|
8
|
+
declare function writeNav3Document(entries: readonly NavSectionEntry[]): string;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { NavSectionEntry, sectionTitle, writeNav3Document };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ContentSection } from "document-schema.js";
|
|
2
|
+
//#region src/nav/write.d.ts
|
|
3
|
+
interface NavSectionEntry {
|
|
4
|
+
readonly href: string;
|
|
5
|
+
readonly section: ContentSection;
|
|
6
|
+
}
|
|
7
|
+
declare function sectionTitle(section: ContentSection, index: number): string;
|
|
8
|
+
declare function writeNav3Document(entries: readonly NavSectionEntry[]): string;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { NavSectionEntry, sectionTitle, writeNav3Document };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { encodeEntities } from "../xml/entities.js";
|
|
2
|
+
import { buildXml } from "../xml/build.js";
|
|
3
|
+
//#region src/nav/write.ts
|
|
4
|
+
function element(tag, attrs = {}, children = []) {
|
|
5
|
+
return {
|
|
6
|
+
type: "element",
|
|
7
|
+
tag,
|
|
8
|
+
attributes: Object.entries(attrs).map(([name, value]) => ({
|
|
9
|
+
name,
|
|
10
|
+
value
|
|
11
|
+
})),
|
|
12
|
+
children
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function text(value) {
|
|
16
|
+
return {
|
|
17
|
+
type: "text",
|
|
18
|
+
value: encodeEntities(value)
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function sectionTitle(section, index) {
|
|
22
|
+
for (const block of section.blocks) if (block.kind === "paragraph" && block.headingLevel !== void 0) {
|
|
23
|
+
const label = block.runs.map((run) => run.text).join("");
|
|
24
|
+
if (label.trim().length > 0) return label;
|
|
25
|
+
}
|
|
26
|
+
return `Section ${String(index + 1)}`;
|
|
27
|
+
}
|
|
28
|
+
function writeNav3Document(entries) {
|
|
29
|
+
const items = entries.map((entry, index) => element("li", {}, [element("a", { href: entry.href }, [text(sectionTitle(entry.section, index))])]));
|
|
30
|
+
const html = element("html", {
|
|
31
|
+
xmlns: "http://www.w3.org/1999/xhtml",
|
|
32
|
+
"xmlns:epub": "http://www.idpf.org/2007/ops"
|
|
33
|
+
}, [element("body", {}, [element("nav", { "epub:type": "toc" }, [element("h1", {}, [text("Table of Contents")]), element("ol", {}, items)])])]);
|
|
34
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n${buildXml([html])}`;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { sectionTitle, writeNav3Document };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_diagnostics = require("../diagnostics.cjs");
|
|
3
|
+
const require_xml_query = require("../xml/query.cjs");
|
|
4
|
+
const require_xml_parse = require("../xml/parse.cjs");
|
|
5
|
+
//#region src/ocf/container.ts
|
|
6
|
+
const OPF_MEDIA_TYPE = "application/oebps-package+xml";
|
|
7
|
+
function resolveOpfPath(containerXml) {
|
|
8
|
+
const nodes = require_xml_parse.parseXml(containerXml);
|
|
9
|
+
const root = require_xml_query.rootElement(nodes);
|
|
10
|
+
if (root?.tag !== "container") throw new require_diagnostics.EpubInvalidContainerError("META-INF/container.xml has no <container> root element");
|
|
11
|
+
const rootfiles = require_xml_query.findChildElement(root.children, "rootfiles");
|
|
12
|
+
if (rootfiles === void 0) throw new require_diagnostics.EpubInvalidContainerError("META-INF/container.xml has no <rootfiles> element");
|
|
13
|
+
const entries = require_xml_query.childrenWithTag(rootfiles, "rootfile");
|
|
14
|
+
const opfEntry = entries.find((entry) => require_xml_query.attrValue(entry, "media-type") === OPF_MEDIA_TYPE) ?? entries[0];
|
|
15
|
+
const fullPath = opfEntry === void 0 ? void 0 : require_xml_query.attrValue(opfEntry, "full-path");
|
|
16
|
+
if (fullPath === void 0) throw new require_diagnostics.EpubInvalidContainerError("META-INF/container.xml names no rootfile with a full-path attribute");
|
|
17
|
+
return fullPath;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.resolveOpfPath = resolveOpfPath;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EpubInvalidContainerError } from "../diagnostics.js";
|
|
2
|
+
import { attrValue, childrenWithTag, findChildElement, rootElement } from "../xml/query.js";
|
|
3
|
+
import { parseXml } from "../xml/parse.js";
|
|
4
|
+
//#region src/ocf/container.ts
|
|
5
|
+
const OPF_MEDIA_TYPE = "application/oebps-package+xml";
|
|
6
|
+
function resolveOpfPath(containerXml) {
|
|
7
|
+
const nodes = parseXml(containerXml);
|
|
8
|
+
const root = rootElement(nodes);
|
|
9
|
+
if (root?.tag !== "container") throw new EpubInvalidContainerError("META-INF/container.xml has no <container> root element");
|
|
10
|
+
const rootfiles = findChildElement(root.children, "rootfiles");
|
|
11
|
+
if (rootfiles === void 0) throw new EpubInvalidContainerError("META-INF/container.xml has no <rootfiles> element");
|
|
12
|
+
const entries = childrenWithTag(rootfiles, "rootfile");
|
|
13
|
+
const opfEntry = entries.find((entry) => attrValue(entry, "media-type") === OPF_MEDIA_TYPE) ?? entries[0];
|
|
14
|
+
const fullPath = opfEntry === void 0 ? void 0 : attrValue(opfEntry, "full-path");
|
|
15
|
+
if (fullPath === void 0) throw new EpubInvalidContainerError("META-INF/container.xml names no rootfile with a full-path attribute");
|
|
16
|
+
return fullPath;
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { resolveOpfPath };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/ocf/write.ts
|
|
3
|
+
function writeContainerXml(opfPath) {
|
|
4
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
5
|
+
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
|
|
6
|
+
<rootfiles>
|
|
7
|
+
<rootfile full-path="${opfPath}" media-type="application/oebps-package+xml"/>
|
|
8
|
+
</rootfiles>
|
|
9
|
+
</container>
|
|
10
|
+
`;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.writeContainerXml = writeContainerXml;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/ocf/write.ts
|
|
2
|
+
function writeContainerXml(opfPath) {
|
|
3
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
4
|
+
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
|
|
5
|
+
<rootfiles>
|
|
6
|
+
<rootfile full-path="${opfPath}" media-type="application/oebps-package+xml"/>
|
|
7
|
+
</rootfiles>
|
|
8
|
+
</container>
|
|
9
|
+
`;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { writeContainerXml };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_diagnostics = require("../diagnostics.cjs");
|
|
3
|
+
const require_xml_query = require("../xml/query.cjs");
|
|
4
|
+
const require_xml_entities = require("../xml/entities.cjs");
|
|
5
|
+
//#region src/opf/metadata.ts
|
|
6
|
+
const UNMAPPED_DC_TAGS = [
|
|
7
|
+
"dc:publisher",
|
|
8
|
+
"dc:contributor",
|
|
9
|
+
"dc:rights"
|
|
10
|
+
];
|
|
11
|
+
function readOpfMetadata(metadataElement, sink) {
|
|
12
|
+
const metadata = {};
|
|
13
|
+
for (const tag of UNMAPPED_DC_TAGS) if (require_xml_query.childrenWithTag(metadataElement, tag).length > 0) sink({
|
|
14
|
+
code: require_diagnostics.EpubDiagnosticCodes.METADATA_FIELD_UNMAPPED,
|
|
15
|
+
severity: "info",
|
|
16
|
+
message: `<${tag}> has no document-schema.js LayoutMetadata field to carry it; dropped`
|
|
17
|
+
});
|
|
18
|
+
const title = firstElementText(metadataElement, "dc:title");
|
|
19
|
+
if (title !== void 0) metadata.title = title;
|
|
20
|
+
const creators = require_xml_query.childrenWithTag(metadataElement, "dc:creator").map((element) => require_xml_entities.decodeEntities(require_xml_query.textContent(element.children)).trim()).filter((value) => value.length > 0);
|
|
21
|
+
if (creators.length > 0) metadata.author = creators.join("; ");
|
|
22
|
+
const subjects = require_xml_query.childrenWithTag(metadataElement, "dc:subject").map((element) => require_xml_entities.decodeEntities(require_xml_query.textContent(element.children)).trim()).filter((value) => value.length > 0);
|
|
23
|
+
if (subjects.length > 0) metadata.keywords = subjects;
|
|
24
|
+
const language = firstElementText(metadataElement, "dc:language");
|
|
25
|
+
if (language !== void 0) metadata.language = language;
|
|
26
|
+
const date = firstElementText(metadataElement, "dc:date");
|
|
27
|
+
if (date !== void 0) metadata.createdIso = date;
|
|
28
|
+
const modified = dctermsModified(metadataElement);
|
|
29
|
+
if (modified !== void 0) metadata.modifiedIso = modified;
|
|
30
|
+
return metadata;
|
|
31
|
+
}
|
|
32
|
+
function firstElementText(parent, tag) {
|
|
33
|
+
const element = require_xml_query.childrenWithTag(parent, tag)[0];
|
|
34
|
+
if (element === void 0) return;
|
|
35
|
+
const text = require_xml_entities.decodeEntities(require_xml_query.textContent(element.children)).trim();
|
|
36
|
+
return text.length > 0 ? text : void 0;
|
|
37
|
+
}
|
|
38
|
+
function dctermsModified(metadataElement) {
|
|
39
|
+
for (const meta of require_xml_query.childrenWithTag(metadataElement, "meta")) {
|
|
40
|
+
if (require_xml_query.attrValue(meta, "property") === "dcterms:modified") {
|
|
41
|
+
const text = require_xml_entities.decodeEntities(require_xml_query.textContent(meta.children)).trim();
|
|
42
|
+
if (text.length > 0) return text;
|
|
43
|
+
}
|
|
44
|
+
if (require_xml_query.attrValue(meta, "name") === "dcterms:modified") {
|
|
45
|
+
const content = require_xml_query.attrValue(meta, "content");
|
|
46
|
+
if (content !== void 0 && content.trim().length > 0) return content.trim();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
exports.readOpfMetadata = readOpfMetadata;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { i as EpubDiagnosticSink } from "../diagnostics-Ee4kG7mw.cjs";
|
|
2
|
+
import { XmlElement } from "../xml/node.cjs";
|
|
3
|
+
import { LayoutMetadata } from "document-schema.js";
|
|
4
|
+
//#region src/opf/metadata.d.ts
|
|
5
|
+
declare function readOpfMetadata(metadataElement: XmlElement, sink: EpubDiagnosticSink): LayoutMetadata;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { readOpfMetadata };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { i as EpubDiagnosticSink } from "../diagnostics-Ee4kG7mw.js";
|
|
2
|
+
import { XmlElement } from "../xml/node.js";
|
|
3
|
+
import { LayoutMetadata } from "document-schema.js";
|
|
4
|
+
//#region src/opf/metadata.d.ts
|
|
5
|
+
declare function readOpfMetadata(metadataElement: XmlElement, sink: EpubDiagnosticSink): LayoutMetadata;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { readOpfMetadata };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { EpubDiagnosticCodes } from "../diagnostics.js";
|
|
2
|
+
import { attrValue, childrenWithTag, textContent } from "../xml/query.js";
|
|
3
|
+
import { decodeEntities } from "../xml/entities.js";
|
|
4
|
+
//#region src/opf/metadata.ts
|
|
5
|
+
const UNMAPPED_DC_TAGS = [
|
|
6
|
+
"dc:publisher",
|
|
7
|
+
"dc:contributor",
|
|
8
|
+
"dc:rights"
|
|
9
|
+
];
|
|
10
|
+
function readOpfMetadata(metadataElement, sink) {
|
|
11
|
+
const metadata = {};
|
|
12
|
+
for (const tag of UNMAPPED_DC_TAGS) if (childrenWithTag(metadataElement, tag).length > 0) sink({
|
|
13
|
+
code: EpubDiagnosticCodes.METADATA_FIELD_UNMAPPED,
|
|
14
|
+
severity: "info",
|
|
15
|
+
message: `<${tag}> has no document-schema.js LayoutMetadata field to carry it; dropped`
|
|
16
|
+
});
|
|
17
|
+
const title = firstElementText(metadataElement, "dc:title");
|
|
18
|
+
if (title !== void 0) metadata.title = title;
|
|
19
|
+
const creators = childrenWithTag(metadataElement, "dc:creator").map((element) => decodeEntities(textContent(element.children)).trim()).filter((value) => value.length > 0);
|
|
20
|
+
if (creators.length > 0) metadata.author = creators.join("; ");
|
|
21
|
+
const subjects = childrenWithTag(metadataElement, "dc:subject").map((element) => decodeEntities(textContent(element.children)).trim()).filter((value) => value.length > 0);
|
|
22
|
+
if (subjects.length > 0) metadata.keywords = subjects;
|
|
23
|
+
const language = firstElementText(metadataElement, "dc:language");
|
|
24
|
+
if (language !== void 0) metadata.language = language;
|
|
25
|
+
const date = firstElementText(metadataElement, "dc:date");
|
|
26
|
+
if (date !== void 0) metadata.createdIso = date;
|
|
27
|
+
const modified = dctermsModified(metadataElement);
|
|
28
|
+
if (modified !== void 0) metadata.modifiedIso = modified;
|
|
29
|
+
return metadata;
|
|
30
|
+
}
|
|
31
|
+
function firstElementText(parent, tag) {
|
|
32
|
+
const element = childrenWithTag(parent, tag)[0];
|
|
33
|
+
if (element === void 0) return;
|
|
34
|
+
const text = decodeEntities(textContent(element.children)).trim();
|
|
35
|
+
return text.length > 0 ? text : void 0;
|
|
36
|
+
}
|
|
37
|
+
function dctermsModified(metadataElement) {
|
|
38
|
+
for (const meta of childrenWithTag(metadataElement, "meta")) {
|
|
39
|
+
if (attrValue(meta, "property") === "dcterms:modified") {
|
|
40
|
+
const text = decodeEntities(textContent(meta.children)).trim();
|
|
41
|
+
if (text.length > 0) return text;
|
|
42
|
+
}
|
|
43
|
+
if (attrValue(meta, "name") === "dcterms:modified") {
|
|
44
|
+
const content = attrValue(meta, "content");
|
|
45
|
+
if (content !== void 0 && content.trim().length > 0) return content.trim();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { readOpfMetadata };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_diagnostics = require("../diagnostics.cjs");
|
|
3
|
+
const require_xml_query = require("../xml/query.cjs");
|
|
4
|
+
const require_xml_parse = require("../xml/parse.cjs");
|
|
5
|
+
const require_opf_metadata = require("./metadata.cjs");
|
|
6
|
+
//#region src/opf/parse.ts
|
|
7
|
+
function parseOpf(opfXml, sink = require_diagnostics.NOOP_EPUB_DIAGNOSTIC_SINK) {
|
|
8
|
+
const nodes = require_xml_parse.parseXml(opfXml);
|
|
9
|
+
const root = require_xml_query.rootElement(nodes);
|
|
10
|
+
if (root?.tag !== "package") throw new require_diagnostics.EpubInvalidOpfError("the OPF document has no <package> root element");
|
|
11
|
+
const metadataElement = require_xml_query.findChildElement(root.children, "metadata");
|
|
12
|
+
const metadata = metadataElement === void 0 ? {} : require_opf_metadata.readOpfMetadata(metadataElement, sink);
|
|
13
|
+
const manifestElement = require_xml_query.findChildElement(root.children, "manifest");
|
|
14
|
+
if (manifestElement === void 0) throw new require_diagnostics.EpubInvalidOpfError("the OPF document has no <manifest> element");
|
|
15
|
+
const manifest = require_xml_query.childrenWithTag(manifestElement, "item").map(parseManifestItem).filter((item) => item !== void 0);
|
|
16
|
+
const spineElement = require_xml_query.findChildElement(root.children, "spine");
|
|
17
|
+
if (spineElement === void 0) throw new require_diagnostics.EpubInvalidOpfError("the OPF document has no <spine> element");
|
|
18
|
+
return {
|
|
19
|
+
metadata,
|
|
20
|
+
manifest,
|
|
21
|
+
spine: require_xml_query.childrenWithTag(spineElement, "itemref").map(parseSpineItemRef).filter((item) => item !== void 0),
|
|
22
|
+
ncxId: require_xml_query.attrValue(spineElement, "toc")
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function parseManifestItem(element) {
|
|
26
|
+
const id = require_xml_query.attrValue(element, "id");
|
|
27
|
+
const href = require_xml_query.attrValue(element, "href");
|
|
28
|
+
const mediaType = require_xml_query.attrValue(element, "media-type");
|
|
29
|
+
if (id === void 0 || href === void 0 || mediaType === void 0) return;
|
|
30
|
+
const properties = require_xml_query.attrValue(element, "properties");
|
|
31
|
+
return {
|
|
32
|
+
id,
|
|
33
|
+
href,
|
|
34
|
+
mediaType,
|
|
35
|
+
properties: properties === void 0 ? [] : properties.split(/\s+/u).filter((p) => p.length > 0)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function parseSpineItemRef(element) {
|
|
39
|
+
const idref = require_xml_query.attrValue(element, "idref");
|
|
40
|
+
if (idref === void 0) return;
|
|
41
|
+
return {
|
|
42
|
+
idref,
|
|
43
|
+
linear: require_xml_query.attrValue(element, "linear") !== "no"
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
exports.parseOpf = parseOpf;
|