epub-codec 1.2.12 → 1.3.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/README.md +24 -10
- package/dist/base64--HuymRl_.d.cts +5 -0
- package/dist/base64--HuymRl_.d.ts +5 -0
- package/dist/build-B1UxbO20.d.cts +5 -0
- package/dist/build-BCUsHLYw.d.ts +5 -0
- package/dist/codec-CX2Pa6Jq.d.ts +2876 -0
- package/dist/codec-qyKMOMt6.d.cts +2876 -0
- package/dist/codec.cjs +16 -0
- package/dist/codec.d.cts +2 -2702
- package/dist/codec.d.ts +2 -2702
- package/dist/codec.js +14 -1
- package/dist/container-B6cHHiY9.d.cts +4 -0
- package/dist/container-B6cHHiY9.d.ts +4 -0
- package/dist/context-CTgx7PwU.d.ts +28 -0
- package/dist/context-CXs2Yc9w.d.cts +28 -0
- package/dist/dimensions-B7ogpvKQ.d.cts +11 -0
- package/dist/dimensions-B7ogpvKQ.d.ts +11 -0
- package/dist/entities-CfQKtI34.d.ts +7 -0
- package/dist/entities-wt9zCx5q.d.cts +7 -0
- package/dist/footnote-CxsO5tCV.d.cts +7 -0
- package/dist/footnote-iZAPC_NT.d.ts +7 -0
- package/dist/format-DxUddUPj.d.cts +6 -0
- package/dist/format-DxUddUPj.d.ts +6 -0
- package/dist/format.d.cts +1 -5
- package/dist/format.d.ts +1 -5
- package/dist/image/dimensions.d.cts +1 -10
- package/dist/image/dimensions.d.ts +1 -10
- package/dist/index.cjs +24 -8
- package/dist/index.d.cts +31 -31
- package/dist/index.d.ts +31 -31
- package/dist/index.js +13 -10
- package/dist/inline-DDj6Sl3e.d.ts +12 -0
- package/dist/inline-YZOQY2wR.d.cts +12 -0
- package/dist/list-id-BB_yxm1H.d.cts +13 -0
- package/dist/list-id-BB_yxm1H.d.ts +13 -0
- package/dist/metadata-DXto7sM6.d.cts +7 -0
- package/dist/metadata-T5V2ovtS.d.ts +7 -0
- package/dist/model/package.cjs +19 -0
- package/dist/model/package.d.cts +2 -0
- package/dist/model/package.d.ts +2 -0
- package/dist/model/package.js +15 -0
- package/dist/nav/nav3.cjs +1 -1
- package/dist/nav/nav3.d.cts +1 -3
- package/dist/nav/nav3.d.ts +1 -3
- package/dist/nav/nav3.js +1 -1
- package/dist/nav/ncx.cjs +1 -1
- package/dist/nav/ncx.d.cts +1 -3
- package/dist/nav/ncx.d.ts +1 -3
- package/dist/nav/ncx.js +1 -1
- package/dist/nav/reconcile.d.cts +1 -3
- package/dist/nav/reconcile.d.ts +1 -3
- package/dist/nav/write.cjs +1 -1
- package/dist/nav/write.d.cts +1 -9
- package/dist/nav/write.d.ts +1 -9
- package/dist/nav/write.js +1 -1
- package/dist/nav3-SbAp8zlu.d.cts +4 -0
- package/dist/nav3-SbAp8zlu.d.ts +4 -0
- package/dist/ncx-kYhlXucj.d.cts +4 -0
- package/dist/ncx-kYhlXucj.d.ts +4 -0
- package/dist/node-CJLSSs1k.d.cts +84 -0
- package/dist/node-CJLSSs1k.d.ts +84 -0
- package/dist/ocf/container.cjs +1 -1
- package/dist/ocf/container.d.cts +1 -3
- package/dist/ocf/container.d.ts +1 -3
- package/dist/ocf/container.js +1 -1
- package/dist/ocf/write.d.cts +1 -3
- package/dist/ocf/write.d.ts +1 -3
- package/dist/opf/metadata.d.cts +1 -6
- package/dist/opf/metadata.d.ts +1 -6
- package/dist/opf/parse.cjs +1 -1
- package/dist/opf/parse.d.cts +1 -5
- package/dist/opf/parse.d.ts +1 -5
- package/dist/opf/parse.js +1 -1
- package/dist/opf/types.d.cts +1 -19
- package/dist/opf/types.d.ts +1 -19
- package/dist/opf/write.cjs +1 -1
- package/dist/opf/write.d.cts +1 -11
- package/dist/opf/write.d.ts +1 -11
- package/dist/opf/write.js +1 -1
- package/dist/package-io/read.cjs +39 -0
- package/dist/package-io/read.d.cts +2 -0
- package/dist/package-io/read.d.ts +2 -0
- package/dist/package-io/read.js +37 -0
- package/dist/package-io/write.cjs +34 -0
- package/dist/package-io/write.d.cts +2 -0
- package/dist/package-io/write.d.ts +2 -0
- package/dist/package-io/write.js +32 -0
- package/dist/parse-Bkkb7qXz.d.cts +6 -0
- package/dist/parse-C5GxodcX.d.ts +6 -0
- package/dist/parse-CmCjyz8i.d.cts +5 -0
- package/dist/parse-Dc76LQIj.d.ts +5 -0
- package/dist/path-Cx8-QMD6.d.cts +5 -0
- package/dist/path-Cx8-QMD6.d.ts +5 -0
- package/dist/path.d.cts +1 -4
- package/dist/path.d.ts +1 -4
- package/dist/query-B79eElol.d.ts +12 -0
- package/dist/query-C6ftPqNQ.d.cts +12 -0
- package/dist/read-B7kc_MeO.d.cts +10 -0
- package/dist/read-BMGq_D9y.d.cts +30 -0
- package/dist/read-Czqr3aop.d.ts +30 -0
- package/dist/read-DPkpZsYG.d.ts +10 -0
- package/dist/read.cjs +51 -6
- package/dist/read.d.cts +1 -9
- package/dist/read.d.ts +1 -9
- package/dist/read.js +52 -7
- package/dist/reconcile-BHky0kta.d.cts +4 -0
- package/dist/reconcile-BHky0kta.d.ts +4 -0
- package/dist/style-constants-RVoHdmju.d.cts +8 -0
- package/dist/style-constants-RVoHdmju.d.ts +8 -0
- package/dist/types-BxmkPT_F.d.cts +20 -0
- package/dist/types-BxmkPT_F.d.ts +20 -0
- package/dist/util/base64.d.cts +1 -4
- package/dist/util/base64.d.ts +1 -4
- package/dist/write-B89sagtw.d.cts +12 -0
- package/dist/write-BQcrPQvx.d.ts +10 -0
- package/dist/write-Boxi3aK0.d.cts +10 -0
- package/dist/write-COdkb8lG.d.cts +10 -0
- package/dist/write-COdkb8lG.d.ts +10 -0
- package/dist/write-DwaEwwgZ.d.ts +12 -0
- package/dist/write-DxiR-9eH.d.cts +4 -0
- package/dist/write-DxiR-9eH.d.ts +4 -0
- package/dist/write-Klo0WDhT.d.ts +13 -0
- package/dist/write-WSIgARHT.d.cts +13 -0
- package/dist/write.cjs +28 -6
- package/dist/write.d.cts +1 -9
- package/dist/write.d.ts +1 -9
- package/dist/write.js +28 -6
- package/dist/xhtml/context.d.cts +2 -22
- package/dist/xhtml/context.d.ts +2 -22
- package/dist/xhtml/footnote.cjs +4 -8
- package/dist/xhtml/footnote.d.cts +2 -7
- package/dist/xhtml/footnote.d.ts +2 -7
- package/dist/xhtml/footnote.js +4 -8
- package/dist/xhtml/inline.cjs +13 -7
- package/dist/xhtml/inline.d.cts +1 -11
- package/dist/xhtml/inline.d.ts +1 -11
- package/dist/xhtml/inline.js +13 -7
- package/dist/xhtml/link-target.cjs +18 -0
- package/dist/xhtml/link-target.d.cts +8 -0
- package/dist/xhtml/link-target.d.ts +8 -0
- package/dist/xhtml/link-target.js +17 -0
- package/dist/xhtml/list-id.d.cts +1 -12
- package/dist/xhtml/list-id.d.ts +1 -12
- package/dist/xhtml/read.cjs +50 -18
- package/dist/xhtml/read.d.cts +2 -20
- package/dist/xhtml/read.d.ts +2 -20
- package/dist/xhtml/read.js +49 -19
- package/dist/xhtml/style-constants.d.cts +1 -7
- package/dist/xhtml/style-constants.d.ts +1 -7
- package/dist/xhtml/write.cjs +44 -19
- package/dist/xhtml/write.d.cts +1 -11
- package/dist/xhtml/write.d.ts +1 -11
- package/dist/xhtml/write.js +44 -19
- package/dist/xml/build.d.cts +1 -4
- package/dist/xml/build.d.ts +1 -4
- package/dist/xml/entities.d.cts +1 -6
- package/dist/xml/entities.d.ts +1 -6
- package/dist/xml/node.d.cts +1 -83
- package/dist/xml/node.d.ts +1 -83
- package/dist/xml/parse.d.cts +1 -4
- package/dist/xml/parse.d.ts +1 -4
- package/dist/xml/query.cjs +1 -1
- package/dist/xml/query.d.cts +1 -11
- package/dist/xml/query.d.ts +1 -11
- package/dist/xml/query.js +1 -1
- package/dist/zip-ie17sOo5.d.cts +9 -0
- package/dist/zip-ie17sOo5.d.ts +9 -0
- package/dist/zip.d.cts +1 -8
- package/dist/zip.d.ts +1 -8
- package/package.json +1 -1
|
@@ -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 { sectionTitle as n, writeNav3Document as r, NavSectionEntry as t };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { t as OpfManifestItem } from "./types-BxmkPT_F.js";
|
|
2
|
+
import { LayoutMetadata } from "document-schema.js";
|
|
3
|
+
//#region src/opf/write.d.ts
|
|
4
|
+
interface WriteOpfInput {
|
|
5
|
+
readonly metadata: LayoutMetadata;
|
|
6
|
+
readonly manifestItems: readonly OpfManifestItem[];
|
|
7
|
+
readonly spineIdrefs: readonly string[];
|
|
8
|
+
readonly identifier: string;
|
|
9
|
+
}
|
|
10
|
+
declare function writeOpf(input: WriteOpfInput): string;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { writeOpf as n, WriteOpfInput as t };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { i as EpubDiagnosticSink } from "./diagnostics-C0CRdoda.js";
|
|
2
|
+
import { l as XmlElement } from "./node-CJLSSs1k.js";
|
|
3
|
+
import { ContentBlock, ContentImageBlock } from "document-schema.js";
|
|
4
|
+
//#region src/xhtml/write.d.ts
|
|
5
|
+
interface XhtmlWriteContext {
|
|
6
|
+
readonly registerImage: (bytes: Uint8Array<ArrayBuffer>, format: ContentImageBlock["format"]) => string;
|
|
7
|
+
readonly sink: EpubDiagnosticSink;
|
|
8
|
+
readonly sourceHref: string;
|
|
9
|
+
readonly resolveAnchorHref: (name: string) => string;
|
|
10
|
+
}
|
|
11
|
+
declare function writeXhtmlBody(blocks: readonly ContentBlock[], context: XhtmlWriteContext): XmlElement;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { writeXhtmlBody as n, XhtmlWriteContext as t };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { i as EpubDiagnosticSink } from "./diagnostics-C0CRdoda.cjs";
|
|
2
|
+
import { l as XmlElement } from "./node-CJLSSs1k.cjs";
|
|
3
|
+
import { ContentBlock, ContentImageBlock } from "document-schema.js";
|
|
4
|
+
//#region src/xhtml/write.d.ts
|
|
5
|
+
interface XhtmlWriteContext {
|
|
6
|
+
readonly registerImage: (bytes: Uint8Array<ArrayBuffer>, format: ContentImageBlock["format"]) => string;
|
|
7
|
+
readonly sink: EpubDiagnosticSink;
|
|
8
|
+
readonly sourceHref: string;
|
|
9
|
+
readonly resolveAnchorHref: (name: string) => string;
|
|
10
|
+
}
|
|
11
|
+
declare function writeXhtmlBody(blocks: readonly ContentBlock[], context: XhtmlWriteContext): XmlElement;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { writeXhtmlBody as n, XhtmlWriteContext as t };
|
package/dist/write.cjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_diagnostics = require("./diagnostics.cjs");
|
|
3
|
-
const require_xml_entities = require("./xml/entities.cjs");
|
|
4
2
|
const require_xml_parse = require("./xml/parse.cjs");
|
|
3
|
+
const require_package_io_read = require("./package-io/read.cjs");
|
|
5
4
|
const require_format = require("./format.cjs");
|
|
6
5
|
const require_xml_build = require("./xml/build.cjs");
|
|
7
|
-
const
|
|
6
|
+
const require_package_io_write = require("./package-io/write.cjs");
|
|
7
|
+
const require_diagnostics = require("./diagnostics.cjs");
|
|
8
|
+
const require_xml_entities = require("./xml/entities.cjs");
|
|
8
9
|
const require_ocf_write = require("./ocf/write.cjs");
|
|
9
10
|
const require_nav_write = require("./nav/write.cjs");
|
|
10
11
|
const require_opf_write = require("./opf/write.cjs");
|
|
@@ -15,8 +16,25 @@ const OPF_DIR = "OEBPS";
|
|
|
15
16
|
const OPF_PATH = `${OPF_DIR}/content.opf`;
|
|
16
17
|
const NAV_PATH = `${OPF_DIR}/nav.xhtml`;
|
|
17
18
|
const XHTML_DOCTYPE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">";
|
|
19
|
+
function sectionFileName(index) {
|
|
20
|
+
return `section${String(index + 1)}.xhtml`;
|
|
21
|
+
}
|
|
18
22
|
function sectionXhtmlPath(index) {
|
|
19
|
-
return `${OPF_DIR}
|
|
23
|
+
return `${OPF_DIR}/${sectionFileName(index)}`;
|
|
24
|
+
}
|
|
25
|
+
function buildAnchorSectionIndex(sections) {
|
|
26
|
+
const index = /* @__PURE__ */ new Map();
|
|
27
|
+
sections.forEach((section, sectionIndex) => {
|
|
28
|
+
for (const block of section.blocks) if (block.kind === "constructStart" && block.descriptor.kind === "anchor") index.set(block.descriptor.name, sectionIndex);
|
|
29
|
+
});
|
|
30
|
+
return index;
|
|
31
|
+
}
|
|
32
|
+
function resolveAnchorHrefFor(ownIndex, anchorSectionIndex) {
|
|
33
|
+
return (name) => {
|
|
34
|
+
const targetIndex = anchorSectionIndex.get(name);
|
|
35
|
+
if (targetIndex === void 0 || targetIndex === ownIndex) return `#${name}`;
|
|
36
|
+
return `${sectionFileName(targetIndex)}#${name}`;
|
|
37
|
+
};
|
|
20
38
|
}
|
|
21
39
|
function buildHead(title, residueXml) {
|
|
22
40
|
return {
|
|
@@ -64,6 +82,7 @@ function writeEpubContent(document, options = {}) {
|
|
|
64
82
|
});
|
|
65
83
|
return href;
|
|
66
84
|
};
|
|
85
|
+
const anchorSectionIndex = buildAnchorSectionIndex(document.sections);
|
|
67
86
|
const sectionXhtml = [];
|
|
68
87
|
document.sections.forEach((section, index) => {
|
|
69
88
|
const sourceHref = sectionXhtmlPath(index);
|
|
@@ -71,7 +90,8 @@ function writeEpubContent(document, options = {}) {
|
|
|
71
90
|
const body = require_xhtml_write.writeXhtmlBody(section.blocks, {
|
|
72
91
|
registerImage,
|
|
73
92
|
sink,
|
|
74
|
-
sourceHref
|
|
93
|
+
sourceHref,
|
|
94
|
+
resolveAnchorHref: resolveAnchorHrefFor(index, anchorSectionIndex)
|
|
75
95
|
});
|
|
76
96
|
const residueXml = section.source?.format === "epub" ? section.source.xml : void 0;
|
|
77
97
|
sectionXhtml.push({
|
|
@@ -129,7 +149,9 @@ function writeEpubContent(document, options = {}) {
|
|
|
129
149
|
entries.push([sectionXhtmlPath(index), { bytes: new TextEncoder().encode(xml) }]);
|
|
130
150
|
});
|
|
131
151
|
for (const image of registeredImages) entries.push([`${OPF_DIR}/${image.href}`, { bytes: image.bytes }]);
|
|
132
|
-
|
|
152
|
+
const entryBytes = {};
|
|
153
|
+
for (const [path, entry] of entries) entryBytes[path] = entry.bytes;
|
|
154
|
+
return require_package_io_write.serializePackage(require_package_io_read.packageFromEntries(entryBytes));
|
|
133
155
|
}
|
|
134
156
|
function writeEpub(tree, options = {}) {
|
|
135
157
|
if (tree.kind !== "wordprocessing") throw new require_diagnostics.EpubUnsupportedDocumentKindError(tree.kind);
|
package/dist/write.d.cts
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ContentDocument, DocumentTree } from "document-schema.js";
|
|
3
|
-
//#region src/write.d.ts
|
|
4
|
-
interface WriteEpubOptions {
|
|
5
|
-
readonly sink?: EpubDiagnosticSink;
|
|
6
|
-
}
|
|
7
|
-
declare function writeEpubContent(document: ContentDocument, options?: WriteEpubOptions): Uint8Array<ArrayBuffer>;
|
|
8
|
-
declare function writeEpub(tree: DocumentTree, options?: WriteEpubOptions): Uint8Array<ArrayBuffer>;
|
|
9
|
-
//#endregion
|
|
1
|
+
import { n as writeEpub, r as writeEpubContent, t as WriteEpubOptions } from "./write-Boxi3aK0.cjs";
|
|
10
2
|
export { WriteEpubOptions, writeEpub, writeEpubContent };
|
package/dist/write.d.ts
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ContentDocument, DocumentTree } from "document-schema.js";
|
|
3
|
-
//#region src/write.d.ts
|
|
4
|
-
interface WriteEpubOptions {
|
|
5
|
-
readonly sink?: EpubDiagnosticSink;
|
|
6
|
-
}
|
|
7
|
-
declare function writeEpubContent(document: ContentDocument, options?: WriteEpubOptions): Uint8Array<ArrayBuffer>;
|
|
8
|
-
declare function writeEpub(tree: DocumentTree, options?: WriteEpubOptions): Uint8Array<ArrayBuffer>;
|
|
9
|
-
//#endregion
|
|
1
|
+
import { n as writeEpub, r as writeEpubContent, t as WriteEpubOptions } from "./write-BQcrPQvx.js";
|
|
10
2
|
export { WriteEpubOptions, writeEpub, writeEpubContent };
|
package/dist/write.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { EpubPackageFlattenError, EpubUnbalancedConstructMarkersError, EpubUnsupportedDocumentKindError, NOOP_EPUB_DIAGNOSTIC_SINK } from "./diagnostics.js";
|
|
2
|
-
import { encodeEntities } from "./xml/entities.js";
|
|
3
1
|
import { parseXml } from "./xml/parse.js";
|
|
2
|
+
import { packageFromEntries } from "./package-io/read.js";
|
|
4
3
|
import { EPUB_MIME_TYPE, OCF_CONTAINER_PATH, OCF_MIMETYPE_PATH } from "./format.js";
|
|
5
4
|
import { buildXml } from "./xml/build.js";
|
|
6
|
-
import {
|
|
5
|
+
import { serializePackage } from "./package-io/write.js";
|
|
6
|
+
import { EpubPackageFlattenError, EpubUnbalancedConstructMarkersError, EpubUnsupportedDocumentKindError, NOOP_EPUB_DIAGNOSTIC_SINK } from "./diagnostics.js";
|
|
7
|
+
import { encodeEntities } from "./xml/entities.js";
|
|
7
8
|
import { writeContainerXml } from "./ocf/write.js";
|
|
8
9
|
import { sectionTitle, writeNav3Document } from "./nav/write.js";
|
|
9
10
|
import { writeOpf } from "./opf/write.js";
|
|
@@ -14,8 +15,25 @@ const OPF_DIR = "OEBPS";
|
|
|
14
15
|
const OPF_PATH = `${OPF_DIR}/content.opf`;
|
|
15
16
|
const NAV_PATH = `${OPF_DIR}/nav.xhtml`;
|
|
16
17
|
const XHTML_DOCTYPE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">";
|
|
18
|
+
function sectionFileName(index) {
|
|
19
|
+
return `section${String(index + 1)}.xhtml`;
|
|
20
|
+
}
|
|
17
21
|
function sectionXhtmlPath(index) {
|
|
18
|
-
return `${OPF_DIR}
|
|
22
|
+
return `${OPF_DIR}/${sectionFileName(index)}`;
|
|
23
|
+
}
|
|
24
|
+
function buildAnchorSectionIndex(sections) {
|
|
25
|
+
const index = /* @__PURE__ */ new Map();
|
|
26
|
+
sections.forEach((section, sectionIndex) => {
|
|
27
|
+
for (const block of section.blocks) if (block.kind === "constructStart" && block.descriptor.kind === "anchor") index.set(block.descriptor.name, sectionIndex);
|
|
28
|
+
});
|
|
29
|
+
return index;
|
|
30
|
+
}
|
|
31
|
+
function resolveAnchorHrefFor(ownIndex, anchorSectionIndex) {
|
|
32
|
+
return (name) => {
|
|
33
|
+
const targetIndex = anchorSectionIndex.get(name);
|
|
34
|
+
if (targetIndex === void 0 || targetIndex === ownIndex) return `#${name}`;
|
|
35
|
+
return `${sectionFileName(targetIndex)}#${name}`;
|
|
36
|
+
};
|
|
19
37
|
}
|
|
20
38
|
function buildHead(title, residueXml) {
|
|
21
39
|
return {
|
|
@@ -63,6 +81,7 @@ function writeEpubContent(document, options = {}) {
|
|
|
63
81
|
});
|
|
64
82
|
return href;
|
|
65
83
|
};
|
|
84
|
+
const anchorSectionIndex = buildAnchorSectionIndex(document.sections);
|
|
66
85
|
const sectionXhtml = [];
|
|
67
86
|
document.sections.forEach((section, index) => {
|
|
68
87
|
const sourceHref = sectionXhtmlPath(index);
|
|
@@ -70,7 +89,8 @@ function writeEpubContent(document, options = {}) {
|
|
|
70
89
|
const body = writeXhtmlBody(section.blocks, {
|
|
71
90
|
registerImage,
|
|
72
91
|
sink,
|
|
73
|
-
sourceHref
|
|
92
|
+
sourceHref,
|
|
93
|
+
resolveAnchorHref: resolveAnchorHrefFor(index, anchorSectionIndex)
|
|
74
94
|
});
|
|
75
95
|
const residueXml = section.source?.format === "epub" ? section.source.xml : void 0;
|
|
76
96
|
sectionXhtml.push({
|
|
@@ -128,7 +148,9 @@ function writeEpubContent(document, options = {}) {
|
|
|
128
148
|
entries.push([sectionXhtmlPath(index), { bytes: new TextEncoder().encode(xml) }]);
|
|
129
149
|
});
|
|
130
150
|
for (const image of registeredImages) entries.push([`${OPF_DIR}/${image.href}`, { bytes: image.bytes }]);
|
|
131
|
-
|
|
151
|
+
const entryBytes = {};
|
|
152
|
+
for (const [path, entry] of entries) entryBytes[path] = entry.bytes;
|
|
153
|
+
return serializePackage(packageFromEntries(entryBytes));
|
|
132
154
|
}
|
|
133
155
|
function writeEpub(tree, options = {}) {
|
|
134
156
|
if (tree.kind !== "wordprocessing") throw new EpubUnsupportedDocumentKindError(tree.kind);
|
package/dist/xhtml/context.d.cts
CHANGED
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
|
|
3
|
-
//#region src/xhtml/context.d.ts
|
|
4
|
-
interface XhtmlReadContext {
|
|
5
|
-
readonly resolveImage: (href: string) => Uint8Array<ArrayBuffer> | undefined;
|
|
6
|
-
readonly sink: EpubDiagnosticSink;
|
|
7
|
-
readonly sourceHref: string;
|
|
8
|
-
readonly idElements: ReadonlyMap<string, XmlElement>;
|
|
9
|
-
readonly footnoteTargetIds: ReadonlySet<string>;
|
|
10
|
-
readonly quoteDepth: number;
|
|
11
|
-
}
|
|
12
|
-
interface InlineStyle {
|
|
13
|
-
readonly bold?: boolean;
|
|
14
|
-
readonly italic?: boolean;
|
|
15
|
-
readonly underline?: boolean;
|
|
16
|
-
readonly strike?: boolean;
|
|
17
|
-
readonly fontFamily?: string;
|
|
18
|
-
}
|
|
19
|
-
declare function isInertElement(tag: string): boolean;
|
|
20
|
-
declare function reportInertElementSkip(tag: string, context: XhtmlReadContext): void;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { InlineStyle, XhtmlReadContext, isInertElement, reportInertElementSkip };
|
|
1
|
+
import { a as reportInertElementSkip, i as isInertElement, n as ResolvedAnchorTarget, r as XhtmlReadContext, t as InlineStyle } from "../context-CXs2Yc9w.cjs";
|
|
2
|
+
export { InlineStyle, ResolvedAnchorTarget, XhtmlReadContext, isInertElement, reportInertElementSkip };
|
package/dist/xhtml/context.d.ts
CHANGED
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
|
|
3
|
-
//#region src/xhtml/context.d.ts
|
|
4
|
-
interface XhtmlReadContext {
|
|
5
|
-
readonly resolveImage: (href: string) => Uint8Array<ArrayBuffer> | undefined;
|
|
6
|
-
readonly sink: EpubDiagnosticSink;
|
|
7
|
-
readonly sourceHref: string;
|
|
8
|
-
readonly idElements: ReadonlyMap<string, XmlElement>;
|
|
9
|
-
readonly footnoteTargetIds: ReadonlySet<string>;
|
|
10
|
-
readonly quoteDepth: number;
|
|
11
|
-
}
|
|
12
|
-
interface InlineStyle {
|
|
13
|
-
readonly bold?: boolean;
|
|
14
|
-
readonly italic?: boolean;
|
|
15
|
-
readonly underline?: boolean;
|
|
16
|
-
readonly strike?: boolean;
|
|
17
|
-
readonly fontFamily?: string;
|
|
18
|
-
}
|
|
19
|
-
declare function isInertElement(tag: string): boolean;
|
|
20
|
-
declare function reportInertElementSkip(tag: string, context: XhtmlReadContext): void;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { InlineStyle, XhtmlReadContext, isInertElement, reportInertElementSkip };
|
|
1
|
+
import { a as reportInertElementSkip, i as isInertElement, n as ResolvedAnchorTarget, r as XhtmlReadContext, t as InlineStyle } from "../context-CTgx7PwU.js";
|
|
2
|
+
export { InlineStyle, ResolvedAnchorTarget, XhtmlReadContext, isInertElement, reportInertElementSkip };
|
package/dist/xhtml/footnote.cjs
CHANGED
|
@@ -14,13 +14,9 @@ function sameDocumentFragment(href) {
|
|
|
14
14
|
if (href === void 0 || !href.startsWith("#") || href.length < 2) return;
|
|
15
15
|
return href.slice(1);
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const target = idElements.get(fragment);
|
|
21
|
-
if (target === void 0) return;
|
|
22
|
-
if (epubTypeValues(anchor).some((v) => /noteref/i.test(v))) return fragment;
|
|
23
|
-
if (hasFootnoteClass(anchor) || hasFootnoteClass(target)) return fragment;
|
|
17
|
+
function isFootnoteReference(anchor, target) {
|
|
18
|
+
if (epubTypeValues(anchor).some((v) => /noteref/i.test(v))) return true;
|
|
19
|
+
return hasFootnoteClass(anchor) || hasFootnoteClass(target);
|
|
24
20
|
}
|
|
25
21
|
function isFootnoteAside(element) {
|
|
26
22
|
if (element.tag !== "aside") return false;
|
|
@@ -28,5 +24,5 @@ function isFootnoteAside(element) {
|
|
|
28
24
|
}
|
|
29
25
|
//#endregion
|
|
30
26
|
exports.isFootnoteAside = isFootnoteAside;
|
|
31
|
-
exports.
|
|
27
|
+
exports.isFootnoteReference = isFootnoteReference;
|
|
32
28
|
exports.sameDocumentFragment = sameDocumentFragment;
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function sameDocumentFragment(href: string | undefined): string | undefined;
|
|
4
|
-
declare function isFootnoteReferenceAnchor(anchor: XmlElement, idElements: ReadonlyMap<string, XmlElement>): string | undefined;
|
|
5
|
-
declare function isFootnoteAside(element: XmlElement): boolean;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { isFootnoteAside, isFootnoteReferenceAnchor, sameDocumentFragment };
|
|
1
|
+
import { n as isFootnoteReference, r as sameDocumentFragment, t as isFootnoteAside } from "../footnote-CxsO5tCV.cjs";
|
|
2
|
+
export { isFootnoteAside, isFootnoteReference, sameDocumentFragment };
|
package/dist/xhtml/footnote.d.ts
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare function sameDocumentFragment(href: string | undefined): string | undefined;
|
|
4
|
-
declare function isFootnoteReferenceAnchor(anchor: XmlElement, idElements: ReadonlyMap<string, XmlElement>): string | undefined;
|
|
5
|
-
declare function isFootnoteAside(element: XmlElement): boolean;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { isFootnoteAside, isFootnoteReferenceAnchor, sameDocumentFragment };
|
|
1
|
+
import { n as isFootnoteReference, r as sameDocumentFragment, t as isFootnoteAside } from "../footnote-iZAPC_NT.js";
|
|
2
|
+
export { isFootnoteAside, isFootnoteReference, sameDocumentFragment };
|
package/dist/xhtml/footnote.js
CHANGED
|
@@ -13,17 +13,13 @@ function sameDocumentFragment(href) {
|
|
|
13
13
|
if (href === void 0 || !href.startsWith("#") || href.length < 2) return;
|
|
14
14
|
return href.slice(1);
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const target = idElements.get(fragment);
|
|
20
|
-
if (target === void 0) return;
|
|
21
|
-
if (epubTypeValues(anchor).some((v) => /noteref/i.test(v))) return fragment;
|
|
22
|
-
if (hasFootnoteClass(anchor) || hasFootnoteClass(target)) return fragment;
|
|
16
|
+
function isFootnoteReference(anchor, target) {
|
|
17
|
+
if (epubTypeValues(anchor).some((v) => /noteref/i.test(v))) return true;
|
|
18
|
+
return hasFootnoteClass(anchor) || hasFootnoteClass(target);
|
|
23
19
|
}
|
|
24
20
|
function isFootnoteAside(element) {
|
|
25
21
|
if (element.tag !== "aside") return false;
|
|
26
22
|
return epubTypeValues(element).some((v) => /footnote|rearnote/i.test(v));
|
|
27
23
|
}
|
|
28
24
|
//#endregion
|
|
29
|
-
export { isFootnoteAside,
|
|
25
|
+
export { isFootnoteAside, isFootnoteReference, sameDocumentFragment };
|
package/dist/xhtml/inline.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_xml_node = require("../xml/node.cjs");
|
|
2
3
|
const require_diagnostics = require("../diagnostics.cjs");
|
|
3
4
|
const require_xml_entities = require("../xml/entities.cjs");
|
|
4
|
-
const require_xml_node = require("../xml/node.cjs");
|
|
5
5
|
const require_xml_query = require("../xml/query.cjs");
|
|
6
|
-
const require_xhtml_context = require("./context.cjs");
|
|
7
6
|
const require_xhtml_footnote = require("./footnote.cjs");
|
|
7
|
+
const require_xhtml_context = require("./context.cjs");
|
|
8
8
|
const require_xhtml_style_constants = require("./style-constants.cjs");
|
|
9
9
|
//#region src/xhtml/inline.ts
|
|
10
10
|
function normalizeWhitespace(text) {
|
|
@@ -118,24 +118,30 @@ function appendNested(element, style, context, runs, constructs) {
|
|
|
118
118
|
constructs.push(...rebaseConstructs(nested.constructs, offset));
|
|
119
119
|
}
|
|
120
120
|
function appendAnchor(element, style, context, runs, constructs) {
|
|
121
|
-
const
|
|
122
|
-
|
|
121
|
+
const href = require_xml_query.attrValue(element, "href");
|
|
122
|
+
const target = href === void 0 ? void 0 : context.resolveAnchorHref(href);
|
|
123
|
+
if (target !== void 0) {
|
|
123
124
|
const startRun = runs.length;
|
|
124
125
|
const nested = buildInlineRuns(element.children, style, context);
|
|
125
126
|
runs.push(...nested.runs);
|
|
126
127
|
constructs.push(...rebaseConstructs(nested.constructs, startRun));
|
|
127
128
|
constructs.push({
|
|
128
|
-
descriptor: {
|
|
129
|
+
descriptor: target.anchorType === "footnote" ? {
|
|
129
130
|
kind: "anchor",
|
|
130
131
|
anchorType: "footnote",
|
|
131
|
-
name:
|
|
132
|
+
name: target.name
|
|
133
|
+
} : {
|
|
134
|
+
kind: "link",
|
|
135
|
+
target: {
|
|
136
|
+
kind: "internal",
|
|
137
|
+
anchor: target.name
|
|
138
|
+
}
|
|
132
139
|
},
|
|
133
140
|
startRun,
|
|
134
141
|
endRun: runs.length
|
|
135
142
|
});
|
|
136
143
|
return;
|
|
137
144
|
}
|
|
138
|
-
const href = require_xml_query.attrValue(element, "href");
|
|
139
145
|
if (href === void 0 || href.length === 0) {
|
|
140
146
|
appendNested(element, style, context, runs, constructs);
|
|
141
147
|
return;
|
package/dist/xhtml/inline.d.cts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { InlineStyle, XhtmlReadContext } from "./context.cjs";
|
|
3
|
-
import { ContentRun, RunConstructExtent } from "document-schema.js";
|
|
4
|
-
//#region src/xhtml/inline.d.ts
|
|
5
|
-
interface InlineResult {
|
|
6
|
-
readonly runs: ContentRun[];
|
|
7
|
-
readonly constructs: RunConstructExtent[];
|
|
8
|
-
}
|
|
9
|
-
declare function buildInlineRuns(nodes: readonly XmlNode[], style: InlineStyle, context: XhtmlReadContext): InlineResult;
|
|
10
|
-
declare function rebaseConstructs(constructs: readonly RunConstructExtent[], offset: number): RunConstructExtent[];
|
|
11
|
-
//#endregion
|
|
1
|
+
import { n as buildInlineRuns, r as rebaseConstructs, t as InlineResult } from "../inline-YZOQY2wR.cjs";
|
|
12
2
|
export { InlineResult, buildInlineRuns, rebaseConstructs };
|
package/dist/xhtml/inline.d.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { InlineStyle, XhtmlReadContext } from "./context.js";
|
|
3
|
-
import { ContentRun, RunConstructExtent } from "document-schema.js";
|
|
4
|
-
//#region src/xhtml/inline.d.ts
|
|
5
|
-
interface InlineResult {
|
|
6
|
-
readonly runs: ContentRun[];
|
|
7
|
-
readonly constructs: RunConstructExtent[];
|
|
8
|
-
}
|
|
9
|
-
declare function buildInlineRuns(nodes: readonly XmlNode[], style: InlineStyle, context: XhtmlReadContext): InlineResult;
|
|
10
|
-
declare function rebaseConstructs(constructs: readonly RunConstructExtent[], offset: number): RunConstructExtent[];
|
|
11
|
-
//#endregion
|
|
1
|
+
import { n as buildInlineRuns, r as rebaseConstructs, t as InlineResult } from "../inline-DDj6Sl3e.js";
|
|
12
2
|
export { InlineResult, buildInlineRuns, rebaseConstructs };
|
package/dist/xhtml/inline.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { isTextLikeNode } from "../xml/node.js";
|
|
1
2
|
import { EpubDiagnosticCodes } from "../diagnostics.js";
|
|
2
3
|
import { decodeEntities, decodeTextLikeNode } from "../xml/entities.js";
|
|
3
|
-
import { isTextLikeNode } from "../xml/node.js";
|
|
4
4
|
import { attrValue } from "../xml/query.js";
|
|
5
|
+
import { sameDocumentFragment } from "./footnote.js";
|
|
5
6
|
import { isInertElement, reportInertElementSkip } from "./context.js";
|
|
6
|
-
import { isFootnoteReferenceAnchor, sameDocumentFragment } from "./footnote.js";
|
|
7
7
|
import { MONOSPACE_FONT_FAMILY } from "./style-constants.js";
|
|
8
8
|
//#region src/xhtml/inline.ts
|
|
9
9
|
function normalizeWhitespace(text) {
|
|
@@ -117,24 +117,30 @@ function appendNested(element, style, context, runs, constructs) {
|
|
|
117
117
|
constructs.push(...rebaseConstructs(nested.constructs, offset));
|
|
118
118
|
}
|
|
119
119
|
function appendAnchor(element, style, context, runs, constructs) {
|
|
120
|
-
const
|
|
121
|
-
|
|
120
|
+
const href = attrValue(element, "href");
|
|
121
|
+
const target = href === void 0 ? void 0 : context.resolveAnchorHref(href);
|
|
122
|
+
if (target !== void 0) {
|
|
122
123
|
const startRun = runs.length;
|
|
123
124
|
const nested = buildInlineRuns(element.children, style, context);
|
|
124
125
|
runs.push(...nested.runs);
|
|
125
126
|
constructs.push(...rebaseConstructs(nested.constructs, startRun));
|
|
126
127
|
constructs.push({
|
|
127
|
-
descriptor: {
|
|
128
|
+
descriptor: target.anchorType === "footnote" ? {
|
|
128
129
|
kind: "anchor",
|
|
129
130
|
anchorType: "footnote",
|
|
130
|
-
name:
|
|
131
|
+
name: target.name
|
|
132
|
+
} : {
|
|
133
|
+
kind: "link",
|
|
134
|
+
target: {
|
|
135
|
+
kind: "internal",
|
|
136
|
+
anchor: target.name
|
|
137
|
+
}
|
|
131
138
|
},
|
|
132
139
|
startRun,
|
|
133
140
|
endRun: runs.length
|
|
134
141
|
});
|
|
135
142
|
return;
|
|
136
143
|
}
|
|
137
|
-
const href = attrValue(element, "href");
|
|
138
144
|
if (href === void 0 || href.length === 0) {
|
|
139
145
|
appendNested(element, style, context, runs, constructs);
|
|
140
146
|
return;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_path = require("../path.cjs");
|
|
3
|
+
//#region src/xhtml/link-target.ts
|
|
4
|
+
const URI_SCHEME_PATTERN = /^[a-z][a-z0-9+.-]*:/iu;
|
|
5
|
+
function resolveHrefTarget(sourceHref, href) {
|
|
6
|
+
if (href.length === 0 || URI_SCHEME_PATTERN.test(href)) return;
|
|
7
|
+
const hashIndex = href.indexOf("#");
|
|
8
|
+
if (hashIndex === -1) return;
|
|
9
|
+
const fragment = href.slice(hashIndex + 1);
|
|
10
|
+
if (fragment.length === 0) return;
|
|
11
|
+
const pathPart = href.slice(0, hashIndex);
|
|
12
|
+
return {
|
|
13
|
+
targetHref: pathPart.length === 0 ? sourceHref : require_path.resolvePackagePath(require_path.dirname(sourceHref), pathPart),
|
|
14
|
+
fragment
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.resolveHrefTarget = resolveHrefTarget;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/xhtml/link-target.d.ts
|
|
2
|
+
interface HrefTarget {
|
|
3
|
+
readonly targetHref: string;
|
|
4
|
+
readonly fragment: string;
|
|
5
|
+
}
|
|
6
|
+
declare function resolveHrefTarget(sourceHref: string, href: string): HrefTarget | undefined;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { HrefTarget, resolveHrefTarget };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/xhtml/link-target.d.ts
|
|
2
|
+
interface HrefTarget {
|
|
3
|
+
readonly targetHref: string;
|
|
4
|
+
readonly fragment: string;
|
|
5
|
+
}
|
|
6
|
+
declare function resolveHrefTarget(sourceHref: string, href: string): HrefTarget | undefined;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { HrefTarget, resolveHrefTarget };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { dirname, resolvePackagePath } from "../path.js";
|
|
2
|
+
//#region src/xhtml/link-target.ts
|
|
3
|
+
const URI_SCHEME_PATTERN = /^[a-z][a-z0-9+.-]*:/iu;
|
|
4
|
+
function resolveHrefTarget(sourceHref, href) {
|
|
5
|
+
if (href.length === 0 || URI_SCHEME_PATTERN.test(href)) return;
|
|
6
|
+
const hashIndex = href.indexOf("#");
|
|
7
|
+
if (hashIndex === -1) return;
|
|
8
|
+
const fragment = href.slice(hashIndex + 1);
|
|
9
|
+
if (fragment.length === 0) return;
|
|
10
|
+
const pathPart = href.slice(0, hashIndex);
|
|
11
|
+
return {
|
|
12
|
+
targetHref: pathPart.length === 0 ? sourceHref : resolvePackagePath(dirname(sourceHref), pathPart),
|
|
13
|
+
fragment
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { resolveHrefTarget };
|
package/dist/xhtml/list-id.d.cts
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
interface ListNumIdInfo {
|
|
3
|
-
readonly type: "bullet" | "ordered";
|
|
4
|
-
readonly start?: number;
|
|
5
|
-
}
|
|
6
|
-
interface MintListNumIdOptions {
|
|
7
|
-
readonly type: "bullet" | "ordered";
|
|
8
|
-
readonly start?: number;
|
|
9
|
-
}
|
|
10
|
-
declare function mintListNumId(nextId: number, options: MintListNumIdOptions): string;
|
|
11
|
-
declare function parseListNumId(numId: string): ListNumIdInfo | undefined;
|
|
12
|
-
//#endregion
|
|
1
|
+
import { i as parseListNumId, n as MintListNumIdOptions, r as mintListNumId, t as ListNumIdInfo } from "../list-id-BB_yxm1H.cjs";
|
|
13
2
|
export { ListNumIdInfo, MintListNumIdOptions, mintListNumId, parseListNumId };
|
package/dist/xhtml/list-id.d.ts
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
interface ListNumIdInfo {
|
|
3
|
-
readonly type: "bullet" | "ordered";
|
|
4
|
-
readonly start?: number;
|
|
5
|
-
}
|
|
6
|
-
interface MintListNumIdOptions {
|
|
7
|
-
readonly type: "bullet" | "ordered";
|
|
8
|
-
readonly start?: number;
|
|
9
|
-
}
|
|
10
|
-
declare function mintListNumId(nextId: number, options: MintListNumIdOptions): string;
|
|
11
|
-
declare function parseListNumId(numId: string): ListNumIdInfo | undefined;
|
|
12
|
-
//#endregion
|
|
1
|
+
import { i as parseListNumId, n as MintListNumIdOptions, r as mintListNumId, t as ListNumIdInfo } from "../list-id-BB_yxm1H.js";
|
|
13
2
|
export { ListNumIdInfo, MintListNumIdOptions, mintListNumId, parseListNumId };
|