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.
Files changed (170) hide show
  1. package/README.md +24 -10
  2. package/dist/base64--HuymRl_.d.cts +5 -0
  3. package/dist/base64--HuymRl_.d.ts +5 -0
  4. package/dist/build-B1UxbO20.d.cts +5 -0
  5. package/dist/build-BCUsHLYw.d.ts +5 -0
  6. package/dist/codec-CX2Pa6Jq.d.ts +2876 -0
  7. package/dist/codec-qyKMOMt6.d.cts +2876 -0
  8. package/dist/codec.cjs +16 -0
  9. package/dist/codec.d.cts +2 -2702
  10. package/dist/codec.d.ts +2 -2702
  11. package/dist/codec.js +14 -1
  12. package/dist/container-B6cHHiY9.d.cts +4 -0
  13. package/dist/container-B6cHHiY9.d.ts +4 -0
  14. package/dist/context-CTgx7PwU.d.ts +28 -0
  15. package/dist/context-CXs2Yc9w.d.cts +28 -0
  16. package/dist/dimensions-B7ogpvKQ.d.cts +11 -0
  17. package/dist/dimensions-B7ogpvKQ.d.ts +11 -0
  18. package/dist/entities-CfQKtI34.d.ts +7 -0
  19. package/dist/entities-wt9zCx5q.d.cts +7 -0
  20. package/dist/footnote-CxsO5tCV.d.cts +7 -0
  21. package/dist/footnote-iZAPC_NT.d.ts +7 -0
  22. package/dist/format-DxUddUPj.d.cts +6 -0
  23. package/dist/format-DxUddUPj.d.ts +6 -0
  24. package/dist/format.d.cts +1 -5
  25. package/dist/format.d.ts +1 -5
  26. package/dist/image/dimensions.d.cts +1 -10
  27. package/dist/image/dimensions.d.ts +1 -10
  28. package/dist/index.cjs +24 -8
  29. package/dist/index.d.cts +31 -31
  30. package/dist/index.d.ts +31 -31
  31. package/dist/index.js +13 -10
  32. package/dist/inline-DDj6Sl3e.d.ts +12 -0
  33. package/dist/inline-YZOQY2wR.d.cts +12 -0
  34. package/dist/list-id-BB_yxm1H.d.cts +13 -0
  35. package/dist/list-id-BB_yxm1H.d.ts +13 -0
  36. package/dist/metadata-DXto7sM6.d.cts +7 -0
  37. package/dist/metadata-T5V2ovtS.d.ts +7 -0
  38. package/dist/model/package.cjs +19 -0
  39. package/dist/model/package.d.cts +2 -0
  40. package/dist/model/package.d.ts +2 -0
  41. package/dist/model/package.js +15 -0
  42. package/dist/nav/nav3.cjs +1 -1
  43. package/dist/nav/nav3.d.cts +1 -3
  44. package/dist/nav/nav3.d.ts +1 -3
  45. package/dist/nav/nav3.js +1 -1
  46. package/dist/nav/ncx.cjs +1 -1
  47. package/dist/nav/ncx.d.cts +1 -3
  48. package/dist/nav/ncx.d.ts +1 -3
  49. package/dist/nav/ncx.js +1 -1
  50. package/dist/nav/reconcile.d.cts +1 -3
  51. package/dist/nav/reconcile.d.ts +1 -3
  52. package/dist/nav/write.cjs +1 -1
  53. package/dist/nav/write.d.cts +1 -9
  54. package/dist/nav/write.d.ts +1 -9
  55. package/dist/nav/write.js +1 -1
  56. package/dist/nav3-SbAp8zlu.d.cts +4 -0
  57. package/dist/nav3-SbAp8zlu.d.ts +4 -0
  58. package/dist/ncx-kYhlXucj.d.cts +4 -0
  59. package/dist/ncx-kYhlXucj.d.ts +4 -0
  60. package/dist/node-CJLSSs1k.d.cts +84 -0
  61. package/dist/node-CJLSSs1k.d.ts +84 -0
  62. package/dist/ocf/container.cjs +1 -1
  63. package/dist/ocf/container.d.cts +1 -3
  64. package/dist/ocf/container.d.ts +1 -3
  65. package/dist/ocf/container.js +1 -1
  66. package/dist/ocf/write.d.cts +1 -3
  67. package/dist/ocf/write.d.ts +1 -3
  68. package/dist/opf/metadata.d.cts +1 -6
  69. package/dist/opf/metadata.d.ts +1 -6
  70. package/dist/opf/parse.cjs +1 -1
  71. package/dist/opf/parse.d.cts +1 -5
  72. package/dist/opf/parse.d.ts +1 -5
  73. package/dist/opf/parse.js +1 -1
  74. package/dist/opf/types.d.cts +1 -19
  75. package/dist/opf/types.d.ts +1 -19
  76. package/dist/opf/write.cjs +1 -1
  77. package/dist/opf/write.d.cts +1 -11
  78. package/dist/opf/write.d.ts +1 -11
  79. package/dist/opf/write.js +1 -1
  80. package/dist/package-io/read.cjs +39 -0
  81. package/dist/package-io/read.d.cts +2 -0
  82. package/dist/package-io/read.d.ts +2 -0
  83. package/dist/package-io/read.js +37 -0
  84. package/dist/package-io/write.cjs +34 -0
  85. package/dist/package-io/write.d.cts +2 -0
  86. package/dist/package-io/write.d.ts +2 -0
  87. package/dist/package-io/write.js +32 -0
  88. package/dist/parse-Bkkb7qXz.d.cts +6 -0
  89. package/dist/parse-C5GxodcX.d.ts +6 -0
  90. package/dist/parse-CmCjyz8i.d.cts +5 -0
  91. package/dist/parse-Dc76LQIj.d.ts +5 -0
  92. package/dist/path-Cx8-QMD6.d.cts +5 -0
  93. package/dist/path-Cx8-QMD6.d.ts +5 -0
  94. package/dist/path.d.cts +1 -4
  95. package/dist/path.d.ts +1 -4
  96. package/dist/query-B79eElol.d.ts +12 -0
  97. package/dist/query-C6ftPqNQ.d.cts +12 -0
  98. package/dist/read-B7kc_MeO.d.cts +10 -0
  99. package/dist/read-BMGq_D9y.d.cts +30 -0
  100. package/dist/read-Czqr3aop.d.ts +30 -0
  101. package/dist/read-DPkpZsYG.d.ts +10 -0
  102. package/dist/read.cjs +51 -6
  103. package/dist/read.d.cts +1 -9
  104. package/dist/read.d.ts +1 -9
  105. package/dist/read.js +52 -7
  106. package/dist/reconcile-BHky0kta.d.cts +4 -0
  107. package/dist/reconcile-BHky0kta.d.ts +4 -0
  108. package/dist/style-constants-RVoHdmju.d.cts +8 -0
  109. package/dist/style-constants-RVoHdmju.d.ts +8 -0
  110. package/dist/types-BxmkPT_F.d.cts +20 -0
  111. package/dist/types-BxmkPT_F.d.ts +20 -0
  112. package/dist/util/base64.d.cts +1 -4
  113. package/dist/util/base64.d.ts +1 -4
  114. package/dist/write-B89sagtw.d.cts +12 -0
  115. package/dist/write-BQcrPQvx.d.ts +10 -0
  116. package/dist/write-Boxi3aK0.d.cts +10 -0
  117. package/dist/write-COdkb8lG.d.cts +10 -0
  118. package/dist/write-COdkb8lG.d.ts +10 -0
  119. package/dist/write-DwaEwwgZ.d.ts +12 -0
  120. package/dist/write-DxiR-9eH.d.cts +4 -0
  121. package/dist/write-DxiR-9eH.d.ts +4 -0
  122. package/dist/write-Klo0WDhT.d.ts +13 -0
  123. package/dist/write-WSIgARHT.d.cts +13 -0
  124. package/dist/write.cjs +28 -6
  125. package/dist/write.d.cts +1 -9
  126. package/dist/write.d.ts +1 -9
  127. package/dist/write.js +28 -6
  128. package/dist/xhtml/context.d.cts +2 -22
  129. package/dist/xhtml/context.d.ts +2 -22
  130. package/dist/xhtml/footnote.cjs +4 -8
  131. package/dist/xhtml/footnote.d.cts +2 -7
  132. package/dist/xhtml/footnote.d.ts +2 -7
  133. package/dist/xhtml/footnote.js +4 -8
  134. package/dist/xhtml/inline.cjs +13 -7
  135. package/dist/xhtml/inline.d.cts +1 -11
  136. package/dist/xhtml/inline.d.ts +1 -11
  137. package/dist/xhtml/inline.js +13 -7
  138. package/dist/xhtml/link-target.cjs +18 -0
  139. package/dist/xhtml/link-target.d.cts +8 -0
  140. package/dist/xhtml/link-target.d.ts +8 -0
  141. package/dist/xhtml/link-target.js +17 -0
  142. package/dist/xhtml/list-id.d.cts +1 -12
  143. package/dist/xhtml/list-id.d.ts +1 -12
  144. package/dist/xhtml/read.cjs +50 -18
  145. package/dist/xhtml/read.d.cts +2 -20
  146. package/dist/xhtml/read.d.ts +2 -20
  147. package/dist/xhtml/read.js +49 -19
  148. package/dist/xhtml/style-constants.d.cts +1 -7
  149. package/dist/xhtml/style-constants.d.ts +1 -7
  150. package/dist/xhtml/write.cjs +44 -19
  151. package/dist/xhtml/write.d.cts +1 -11
  152. package/dist/xhtml/write.d.ts +1 -11
  153. package/dist/xhtml/write.js +44 -19
  154. package/dist/xml/build.d.cts +1 -4
  155. package/dist/xml/build.d.ts +1 -4
  156. package/dist/xml/entities.d.cts +1 -6
  157. package/dist/xml/entities.d.ts +1 -6
  158. package/dist/xml/node.d.cts +1 -83
  159. package/dist/xml/node.d.ts +1 -83
  160. package/dist/xml/parse.d.cts +1 -4
  161. package/dist/xml/parse.d.ts +1 -4
  162. package/dist/xml/query.cjs +1 -1
  163. package/dist/xml/query.d.cts +1 -11
  164. package/dist/xml/query.d.ts +1 -11
  165. package/dist/xml/query.js +1 -1
  166. package/dist/zip-ie17sOo5.d.cts +9 -0
  167. package/dist/zip-ie17sOo5.d.ts +9 -0
  168. package/dist/zip.d.cts +1 -8
  169. package/dist/zip.d.ts +1 -8
  170. package/package.json +1 -1
@@ -0,0 +1,37 @@
1
+ import { bytesToBase64 } from "../util/base64.js";
2
+ import { parseXml } from "../xml/parse.js";
3
+ import { unzipPackage } from "../zip.js";
4
+ //#region src/package-io/read.ts
5
+ function parsePackage(bytes) {
6
+ return packageFromEntries(unzipPackage(bytes));
7
+ }
8
+ function packageFromEntries(entries) {
9
+ const parts = {};
10
+ for (const [path, partBytes] of Object.entries(entries)) if (looksLikeXml(partBytes)) {
11
+ const xml = new TextDecoder("utf-8").decode(partBytes);
12
+ parts[path] = {
13
+ kind: "xml",
14
+ nodes: parseXml(xml)
15
+ };
16
+ } else parts[path] = {
17
+ kind: "binary",
18
+ base64: bytesToBase64(partBytes)
19
+ };
20
+ return { parts };
21
+ }
22
+ function looksLikeXml(bytes) {
23
+ let i = 0;
24
+ if (bytes.length >= 3 && bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191) i = 3;
25
+ while (i < bytes.length) {
26
+ const b = bytes[i];
27
+ if (b === void 0) return false;
28
+ if (b === 32 || b === 9 || b === 10 || b === 13) {
29
+ i = i + 1;
30
+ continue;
31
+ }
32
+ return b === 60;
33
+ }
34
+ return false;
35
+ }
36
+ //#endregion
37
+ export { packageFromEntries, parsePackage };
@@ -0,0 +1,34 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_util_base64 = require("../util/base64.cjs");
3
+ const require_zip = require("../zip.cjs");
4
+ const require_format = require("../format.cjs");
5
+ const require_xml_build = require("../xml/build.cjs");
6
+ //#region src/package-io/write.ts
7
+ function serializePackage(pkg) {
8
+ const remaining = new Map(Object.entries(pkg.parts));
9
+ const entries = [];
10
+ const mimetype = remaining.get(require_format.OCF_MIMETYPE_PATH);
11
+ if (mimetype !== void 0) {
12
+ entries.push([require_format.OCF_MIMETYPE_PATH, {
13
+ bytes: partToBytes(mimetype),
14
+ stored: true
15
+ }]);
16
+ remaining.delete(require_format.OCF_MIMETYPE_PATH);
17
+ }
18
+ for (const [path, part] of remaining) entries.push([path, { bytes: partToBytes(part) }]);
19
+ return require_zip.zipPackage(entries);
20
+ }
21
+ function partToBytes(part) {
22
+ switch (part.kind) {
23
+ case "xml": return new TextEncoder().encode(require_xml_build.buildXml(part.nodes));
24
+ case "binary": return require_util_base64.base64ToBytes(part.base64);
25
+ }
26
+ }
27
+ function packageToEntries(pkg) {
28
+ const entries = {};
29
+ for (const [path, part] of Object.entries(pkg.parts)) entries[path] = partToBytes(part);
30
+ return entries;
31
+ }
32
+ //#endregion
33
+ exports.packageToEntries = packageToEntries;
34
+ exports.serializePackage = serializePackage;
@@ -0,0 +1,2 @@
1
+ import { c as serializePackage, s as packageToEntries } from "../codec-qyKMOMt6.cjs";
2
+ export { packageToEntries, serializePackage };
@@ -0,0 +1,2 @@
1
+ import { c as serializePackage, s as packageToEntries } from "../codec-CX2Pa6Jq.js";
2
+ export { packageToEntries, serializePackage };
@@ -0,0 +1,32 @@
1
+ import { base64ToBytes } from "../util/base64.js";
2
+ import { zipPackage } from "../zip.js";
3
+ import { OCF_MIMETYPE_PATH } from "../format.js";
4
+ import { buildXml } from "../xml/build.js";
5
+ //#region src/package-io/write.ts
6
+ function serializePackage(pkg) {
7
+ const remaining = new Map(Object.entries(pkg.parts));
8
+ const entries = [];
9
+ const mimetype = remaining.get(OCF_MIMETYPE_PATH);
10
+ if (mimetype !== void 0) {
11
+ entries.push([OCF_MIMETYPE_PATH, {
12
+ bytes: partToBytes(mimetype),
13
+ stored: true
14
+ }]);
15
+ remaining.delete(OCF_MIMETYPE_PATH);
16
+ }
17
+ for (const [path, part] of remaining) entries.push([path, { bytes: partToBytes(part) }]);
18
+ return zipPackage(entries);
19
+ }
20
+ function partToBytes(part) {
21
+ switch (part.kind) {
22
+ case "xml": return new TextEncoder().encode(buildXml(part.nodes));
23
+ case "binary": return base64ToBytes(part.base64);
24
+ }
25
+ }
26
+ function packageToEntries(pkg) {
27
+ const entries = {};
28
+ for (const [path, part] of Object.entries(pkg.parts)) entries[path] = partToBytes(part);
29
+ return entries;
30
+ }
31
+ //#endregion
32
+ export { packageToEntries, serializePackage };
@@ -0,0 +1,6 @@
1
+ import { i as EpubDiagnosticSink } from "./diagnostics-C0CRdoda.cjs";
2
+ import { n as OpfPackage } from "./types-BxmkPT_F.cjs";
3
+ //#region src/opf/parse.d.ts
4
+ declare function parseOpf(opfXml: string, sink?: EpubDiagnosticSink): OpfPackage;
5
+ //#endregion
6
+ export { parseOpf as t };
@@ -0,0 +1,6 @@
1
+ import { i as EpubDiagnosticSink } from "./diagnostics-C0CRdoda.js";
2
+ import { n as OpfPackage } from "./types-BxmkPT_F.js";
3
+ //#region src/opf/parse.d.ts
4
+ declare function parseOpf(opfXml: string, sink?: EpubDiagnosticSink): OpfPackage;
5
+ //#endregion
6
+ export { parseOpf as t };
@@ -0,0 +1,5 @@
1
+ import { d as XmlNode } from "./node-CJLSSs1k.cjs";
2
+ //#region src/xml/parse.d.ts
3
+ declare function parseXml(xml: string): XmlNode[];
4
+ //#endregion
5
+ export { parseXml as t };
@@ -0,0 +1,5 @@
1
+ import { d as XmlNode } from "./node-CJLSSs1k.js";
2
+ //#region src/xml/parse.d.ts
3
+ declare function parseXml(xml: string): XmlNode[];
4
+ //#endregion
5
+ export { parseXml as t };
@@ -0,0 +1,5 @@
1
+ //#region src/path.d.ts
2
+ declare function dirname(path: string): string;
3
+ declare function resolvePackagePath(baseDir: string, relative: string): string;
4
+ //#endregion
5
+ export { resolvePackagePath as n, dirname as t };
@@ -0,0 +1,5 @@
1
+ //#region src/path.d.ts
2
+ declare function dirname(path: string): string;
3
+ declare function resolvePackagePath(baseDir: string, relative: string): string;
4
+ //#endregion
5
+ export { resolvePackagePath as n, dirname as t };
package/dist/path.d.cts CHANGED
@@ -1,5 +1,2 @@
1
- //#region src/path.d.ts
2
- declare function dirname(path: string): string;
3
- declare function resolvePackagePath(baseDir: string, relative: string): string;
4
- //#endregion
1
+ import { n as resolvePackagePath, t as dirname } from "./path-Cx8-QMD6.cjs";
5
2
  export { dirname, resolvePackagePath };
package/dist/path.d.ts CHANGED
@@ -1,5 +1,2 @@
1
- //#region src/path.d.ts
2
- declare function dirname(path: string): string;
3
- declare function resolvePackagePath(baseDir: string, relative: string): string;
4
- //#endregion
1
+ import { n as resolvePackagePath, t as dirname } from "./path-Cx8-QMD6.js";
5
2
  export { dirname, resolvePackagePath };
@@ -0,0 +1,12 @@
1
+ import { d as XmlNode, l as XmlElement } from "./node-CJLSSs1k.js";
2
+ //#region src/xml/query.d.ts
3
+ declare function rootElement(nodes: readonly XmlNode[]): XmlElement | undefined;
4
+ declare function findChildElement(nodes: readonly XmlNode[], tag: string): XmlElement | undefined;
5
+ declare function childrenWithTag(element: XmlElement, tag: string): XmlElement[];
6
+ declare function elementsWithTag(nodes: readonly XmlNode[], tag: string): XmlElement[];
7
+ declare function findElement(nodes: readonly XmlNode[], predicate: (element: XmlElement) => boolean): XmlElement | undefined;
8
+ declare function attrValue(element: XmlElement, name: string): string | undefined;
9
+ declare function textContent(nodes: readonly XmlNode[]): string;
10
+ declare function decodedTextContent(nodes: readonly XmlNode[]): string;
11
+ //#endregion
12
+ export { findChildElement as a, textContent as c, elementsWithTag as i, childrenWithTag as n, findElement as o, decodedTextContent as r, rootElement as s, attrValue as t };
@@ -0,0 +1,12 @@
1
+ import { d as XmlNode, l as XmlElement } from "./node-CJLSSs1k.cjs";
2
+ //#region src/xml/query.d.ts
3
+ declare function rootElement(nodes: readonly XmlNode[]): XmlElement | undefined;
4
+ declare function findChildElement(nodes: readonly XmlNode[], tag: string): XmlElement | undefined;
5
+ declare function childrenWithTag(element: XmlElement, tag: string): XmlElement[];
6
+ declare function elementsWithTag(nodes: readonly XmlNode[], tag: string): XmlElement[];
7
+ declare function findElement(nodes: readonly XmlNode[], predicate: (element: XmlElement) => boolean): XmlElement | undefined;
8
+ declare function attrValue(element: XmlElement, name: string): string | undefined;
9
+ declare function textContent(nodes: readonly XmlNode[]): string;
10
+ declare function decodedTextContent(nodes: readonly XmlNode[]): string;
11
+ //#endregion
12
+ export { findChildElement as a, textContent as c, elementsWithTag as i, childrenWithTag as n, findElement as o, decodedTextContent as r, rootElement as s, attrValue as t };
@@ -0,0 +1,10 @@
1
+ import { i as EpubDiagnosticSink } from "./diagnostics-C0CRdoda.cjs";
2
+ import { ContentDocument, DocumentTree } from "document-schema.js";
3
+ //#region src/read.d.ts
4
+ interface ReadEpubOptions {
5
+ readonly sink?: EpubDiagnosticSink;
6
+ }
7
+ declare function readEpubContent(bytes: Uint8Array<ArrayBuffer>, options?: ReadEpubOptions): ContentDocument;
8
+ declare function readEpub(bytes: Uint8Array<ArrayBuffer>, options?: ReadEpubOptions): DocumentTree;
9
+ //#endregion
10
+ export { readEpub as n, readEpubContent as r, ReadEpubOptions as t };
@@ -0,0 +1,30 @@
1
+ import { l as XmlElement } from "./node-CJLSSs1k.cjs";
2
+ import { n as ResolvedAnchorTarget } from "./context-CXs2Yc9w.cjs";
3
+ import { ContentBlock, SourceResidue } from "document-schema.js";
4
+ //#region src/xhtml/read.d.ts
5
+ interface ReadXhtmlBodyOptions {
6
+ readonly resolveImage: (href: string) => Uint8Array<ArrayBuffer> | undefined;
7
+ readonly sink: (diagnostic: {
8
+ code: string;
9
+ severity: "info" | "warning";
10
+ message: string;
11
+ href?: string;
12
+ }) => void;
13
+ readonly sourceHref: string;
14
+ readonly contentWidthPt: number;
15
+ readonly extraAnchorTargets?: ReadonlyMap<string, ResolvedAnchorTarget>;
16
+ readonly resolveCrossDocumentAnchorHref?: (href: string) => ResolvedAnchorTarget | undefined;
17
+ }
18
+ interface XhtmlAnchorScan {
19
+ readonly idElements: ReadonlyMap<string, XmlElement>;
20
+ readonly anchors: readonly XmlElement[];
21
+ }
22
+ declare function scanXhtmlAnchors(xml: string): XhtmlAnchorScan;
23
+ interface ReadXhtmlBodyResult {
24
+ readonly blocks: ContentBlock[];
25
+ readonly source: SourceResidue | undefined;
26
+ }
27
+ declare function readXhtmlBody(xml: string, options: ReadXhtmlBodyOptions): ReadXhtmlBodyResult;
28
+ declare const BLOCK_LEVEL_TAGS: Set<string>;
29
+ //#endregion
30
+ export { readXhtmlBody as a, XhtmlAnchorScan as i, ReadXhtmlBodyOptions as n, scanXhtmlAnchors as o, ReadXhtmlBodyResult as r, BLOCK_LEVEL_TAGS as t };
@@ -0,0 +1,30 @@
1
+ import { l as XmlElement } from "./node-CJLSSs1k.js";
2
+ import { n as ResolvedAnchorTarget } from "./context-CTgx7PwU.js";
3
+ import { ContentBlock, SourceResidue } from "document-schema.js";
4
+ //#region src/xhtml/read.d.ts
5
+ interface ReadXhtmlBodyOptions {
6
+ readonly resolveImage: (href: string) => Uint8Array<ArrayBuffer> | undefined;
7
+ readonly sink: (diagnostic: {
8
+ code: string;
9
+ severity: "info" | "warning";
10
+ message: string;
11
+ href?: string;
12
+ }) => void;
13
+ readonly sourceHref: string;
14
+ readonly contentWidthPt: number;
15
+ readonly extraAnchorTargets?: ReadonlyMap<string, ResolvedAnchorTarget>;
16
+ readonly resolveCrossDocumentAnchorHref?: (href: string) => ResolvedAnchorTarget | undefined;
17
+ }
18
+ interface XhtmlAnchorScan {
19
+ readonly idElements: ReadonlyMap<string, XmlElement>;
20
+ readonly anchors: readonly XmlElement[];
21
+ }
22
+ declare function scanXhtmlAnchors(xml: string): XhtmlAnchorScan;
23
+ interface ReadXhtmlBodyResult {
24
+ readonly blocks: ContentBlock[];
25
+ readonly source: SourceResidue | undefined;
26
+ }
27
+ declare function readXhtmlBody(xml: string, options: ReadXhtmlBodyOptions): ReadXhtmlBodyResult;
28
+ declare const BLOCK_LEVEL_TAGS: Set<string>;
29
+ //#endregion
30
+ export { readXhtmlBody as a, XhtmlAnchorScan as i, ReadXhtmlBodyOptions as n, scanXhtmlAnchors as o, ReadXhtmlBodyResult as r, BLOCK_LEVEL_TAGS as t };
@@ -0,0 +1,10 @@
1
+ import { i as EpubDiagnosticSink } from "./diagnostics-C0CRdoda.js";
2
+ import { ContentDocument, DocumentTree } from "document-schema.js";
3
+ //#region src/read.d.ts
4
+ interface ReadEpubOptions {
5
+ readonly sink?: EpubDiagnosticSink;
6
+ }
7
+ declare function readEpubContent(bytes: Uint8Array<ArrayBuffer>, options?: ReadEpubOptions): ContentDocument;
8
+ declare function readEpub(bytes: Uint8Array<ArrayBuffer>, options?: ReadEpubOptions): DocumentTree;
9
+ //#endregion
10
+ export { readEpub as n, readEpubContent as r, ReadEpubOptions as t };
package/dist/read.cjs CHANGED
@@ -1,14 +1,18 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_package_io_read = require("./package-io/read.cjs");
3
+ require("./format.cjs");
4
+ const require_package_io_write = require("./package-io/write.cjs");
2
5
  const require_diagnostics = require("./diagnostics.cjs");
6
+ const require_xml_query = require("./xml/query.cjs");
3
7
  const require_ocf_container = require("./ocf/container.cjs");
4
- require("./format.cjs");
5
8
  const require_nav_nav3 = require("./nav/nav3.cjs");
6
9
  const require_nav_ncx = require("./nav/ncx.cjs");
7
10
  const require_nav_reconcile = require("./nav/reconcile.cjs");
8
11
  const require_opf_parse = require("./opf/parse.cjs");
12
+ const require_xhtml_footnote = require("./xhtml/footnote.cjs");
9
13
  const require_xhtml_read = require("./xhtml/read.cjs");
10
14
  const require_path = require("./path.cjs");
11
- const require_zip = require("./zip.cjs");
15
+ const require_xhtml_link_target = require("./xhtml/link-target.cjs");
12
16
  let document_schema_js = require("document-schema.js");
13
17
  //#region src/read.ts
14
18
  const A4_MARGINS = {
@@ -21,8 +25,39 @@ const CONTENT_WIDTH_PT = document_schema_js.PAGE_SIZE_A4.widthPt - A4_MARGINS.le
21
25
  function decodeText(bytes) {
22
26
  return new TextDecoder("utf-8").decode(bytes);
23
27
  }
28
+ function buildCrossDocumentAnchorRegistry(items) {
29
+ const scans = new Map(items.map((item) => [item.fullPath, require_xhtml_read.scanXhtmlAnchors(item.xml)]));
30
+ const spineHrefs = new Set(items.map((item) => item.fullPath));
31
+ const targetsByHref = /* @__PURE__ */ new Map();
32
+ for (const item of items) {
33
+ const scan = scans.get(item.fullPath);
34
+ if (scan === void 0) continue;
35
+ for (const anchor of scan.anchors) {
36
+ const href = require_xml_query.attrValue(anchor, "href");
37
+ if (href === void 0) continue;
38
+ const target = require_xhtml_link_target.resolveHrefTarget(item.fullPath, href);
39
+ if (target === void 0 || target.targetHref === item.fullPath || !spineHrefs.has(target.targetHref)) continue;
40
+ const targetElement = scans.get(target.targetHref)?.idElements.get(target.fragment);
41
+ if (targetElement === void 0 || !require_xhtml_read.BLOCK_LEVEL_TAGS.has(targetElement.tag)) continue;
42
+ const perDoc = targetsByHref.get(target.targetHref) ?? /* @__PURE__ */ new Map();
43
+ if (perDoc.get(target.fragment)?.anchorType !== "footnote") perDoc.set(target.fragment, {
44
+ anchorType: require_xhtml_footnote.isFootnoteReference(anchor, targetElement) ? "footnote" : "bookmark",
45
+ name: `${target.targetHref}#${target.fragment}`
46
+ });
47
+ targetsByHref.set(target.targetHref, perDoc);
48
+ }
49
+ }
50
+ return {
51
+ targetsByHref,
52
+ resolveHref: (sourceHref, href) => {
53
+ const target = require_xhtml_link_target.resolveHrefTarget(sourceHref, href);
54
+ if (target === void 0 || target.targetHref === sourceHref) return;
55
+ return targetsByHref.get(target.targetHref)?.get(target.fragment);
56
+ }
57
+ };
58
+ }
24
59
  function readEpubInternal(bytes, sink) {
25
- const entries = require_zip.unzipPackage(bytes);
60
+ const entries = require_package_io_write.packageToEntries(require_package_io_read.parsePackage(bytes));
26
61
  const mimetypeBytes = entries.mimetype;
27
62
  if (mimetypeBytes === void 0 || decodeText(mimetypeBytes) !== "application/epub+zip") throw new require_diagnostics.EpubInvalidMimetypeError();
28
63
  const containerBytes = entries["META-INF/container.xml"];
@@ -33,8 +68,8 @@ function readEpubInternal(bytes, sink) {
33
68
  const opfDir = require_path.dirname(opfPath);
34
69
  const opf = require_opf_parse.parseOpf(decodeText(opfBytes), sink);
35
70
  const manifestById = new Map(opf.manifest.map((item) => [item.id, item]));
36
- const sections = [];
37
71
  const spineFullPaths = [];
72
+ const resolvedItems = [];
38
73
  for (const itemref of opf.spine) {
39
74
  const manifestItem = manifestById.get(itemref.idref);
40
75
  if (manifestItem === void 0) {
@@ -57,12 +92,22 @@ function readEpubInternal(bytes, sink) {
57
92
  });
58
93
  continue;
59
94
  }
95
+ resolvedItems.push({
96
+ fullPath,
97
+ xml: decodeText(xhtmlBytes)
98
+ });
99
+ }
100
+ const anchorRegistry = buildCrossDocumentAnchorRegistry(resolvedItems);
101
+ const sections = [];
102
+ for (const { fullPath, xml } of resolvedItems) {
60
103
  const sectionDir = require_path.dirname(fullPath);
61
- const { blocks, source } = require_xhtml_read.readXhtmlBody(decodeText(xhtmlBytes), {
104
+ const { blocks, source } = require_xhtml_read.readXhtmlBody(xml, {
62
105
  resolveImage: (src) => entries[require_path.resolvePackagePath(sectionDir, src)],
63
106
  sink,
64
107
  sourceHref: fullPath,
65
- contentWidthPt: CONTENT_WIDTH_PT
108
+ contentWidthPt: CONTENT_WIDTH_PT,
109
+ extraAnchorTargets: anchorRegistry.targetsByHref.get(fullPath),
110
+ resolveCrossDocumentAnchorHref: (href) => anchorRegistry.resolveHref(fullPath, href)
66
111
  });
67
112
  sections.push({
68
113
  pageSize: document_schema_js.PAGE_SIZE_A4,
package/dist/read.d.cts CHANGED
@@ -1,10 +1,2 @@
1
- import { i as EpubDiagnosticSink } from "./diagnostics-C0CRdoda.cjs";
2
- import { ContentDocument, DocumentTree } from "document-schema.js";
3
- //#region src/read.d.ts
4
- interface ReadEpubOptions {
5
- readonly sink?: EpubDiagnosticSink;
6
- }
7
- declare function readEpubContent(bytes: Uint8Array<ArrayBuffer>, options?: ReadEpubOptions): ContentDocument;
8
- declare function readEpub(bytes: Uint8Array<ArrayBuffer>, options?: ReadEpubOptions): DocumentTree;
9
- //#endregion
1
+ import { n as readEpub, r as readEpubContent, t as ReadEpubOptions } from "./read-B7kc_MeO.cjs";
10
2
  export { ReadEpubOptions, readEpub, readEpubContent };
package/dist/read.d.ts CHANGED
@@ -1,10 +1,2 @@
1
- import { i as EpubDiagnosticSink } from "./diagnostics-C0CRdoda.js";
2
- import { ContentDocument, DocumentTree } from "document-schema.js";
3
- //#region src/read.d.ts
4
- interface ReadEpubOptions {
5
- readonly sink?: EpubDiagnosticSink;
6
- }
7
- declare function readEpubContent(bytes: Uint8Array<ArrayBuffer>, options?: ReadEpubOptions): ContentDocument;
8
- declare function readEpub(bytes: Uint8Array<ArrayBuffer>, options?: ReadEpubOptions): DocumentTree;
9
- //#endregion
1
+ import { n as readEpub, r as readEpubContent, t as ReadEpubOptions } from "./read-DPkpZsYG.js";
10
2
  export { ReadEpubOptions, readEpub, readEpubContent };
package/dist/read.js CHANGED
@@ -1,13 +1,17 @@
1
+ import { parsePackage } from "./package-io/read.js";
2
+ import "./format.js";
3
+ import { packageToEntries } from "./package-io/write.js";
1
4
  import { EpubDiagnosticCodes, EpubEmptySpineError, EpubInvalidContainerError, EpubInvalidMimetypeError, EpubInvalidOpfError, NOOP_EPUB_DIAGNOSTIC_SINK } from "./diagnostics.js";
5
+ import { attrValue } from "./xml/query.js";
2
6
  import { resolveOpfPath } from "./ocf/container.js";
3
- import "./format.js";
4
7
  import { readNav3TocHrefs } from "./nav/nav3.js";
5
8
  import { readNcxHrefs } from "./nav/ncx.js";
6
9
  import { navMatchesSpine } from "./nav/reconcile.js";
7
10
  import { parseOpf } from "./opf/parse.js";
8
- import { readXhtmlBody } from "./xhtml/read.js";
11
+ import { isFootnoteReference } from "./xhtml/footnote.js";
12
+ import { BLOCK_LEVEL_TAGS, readXhtmlBody, scanXhtmlAnchors } from "./xhtml/read.js";
9
13
  import { dirname, resolvePackagePath } from "./path.js";
10
- import { unzipPackage } from "./zip.js";
14
+ import { resolveHrefTarget } from "./xhtml/link-target.js";
11
15
  import { PAGE_SIZE_A4, assembleTree } from "document-schema.js";
12
16
  //#region src/read.ts
13
17
  const A4_MARGINS = {
@@ -20,8 +24,39 @@ const CONTENT_WIDTH_PT = PAGE_SIZE_A4.widthPt - A4_MARGINS.leftPt - A4_MARGINS.r
20
24
  function decodeText(bytes) {
21
25
  return new TextDecoder("utf-8").decode(bytes);
22
26
  }
27
+ function buildCrossDocumentAnchorRegistry(items) {
28
+ const scans = new Map(items.map((item) => [item.fullPath, scanXhtmlAnchors(item.xml)]));
29
+ const spineHrefs = new Set(items.map((item) => item.fullPath));
30
+ const targetsByHref = /* @__PURE__ */ new Map();
31
+ for (const item of items) {
32
+ const scan = scans.get(item.fullPath);
33
+ if (scan === void 0) continue;
34
+ for (const anchor of scan.anchors) {
35
+ const href = attrValue(anchor, "href");
36
+ if (href === void 0) continue;
37
+ const target = resolveHrefTarget(item.fullPath, href);
38
+ if (target === void 0 || target.targetHref === item.fullPath || !spineHrefs.has(target.targetHref)) continue;
39
+ const targetElement = scans.get(target.targetHref)?.idElements.get(target.fragment);
40
+ if (targetElement === void 0 || !BLOCK_LEVEL_TAGS.has(targetElement.tag)) continue;
41
+ const perDoc = targetsByHref.get(target.targetHref) ?? /* @__PURE__ */ new Map();
42
+ if (perDoc.get(target.fragment)?.anchorType !== "footnote") perDoc.set(target.fragment, {
43
+ anchorType: isFootnoteReference(anchor, targetElement) ? "footnote" : "bookmark",
44
+ name: `${target.targetHref}#${target.fragment}`
45
+ });
46
+ targetsByHref.set(target.targetHref, perDoc);
47
+ }
48
+ }
49
+ return {
50
+ targetsByHref,
51
+ resolveHref: (sourceHref, href) => {
52
+ const target = resolveHrefTarget(sourceHref, href);
53
+ if (target === void 0 || target.targetHref === sourceHref) return;
54
+ return targetsByHref.get(target.targetHref)?.get(target.fragment);
55
+ }
56
+ };
57
+ }
23
58
  function readEpubInternal(bytes, sink) {
24
- const entries = unzipPackage(bytes);
59
+ const entries = packageToEntries(parsePackage(bytes));
25
60
  const mimetypeBytes = entries.mimetype;
26
61
  if (mimetypeBytes === void 0 || decodeText(mimetypeBytes) !== "application/epub+zip") throw new EpubInvalidMimetypeError();
27
62
  const containerBytes = entries["META-INF/container.xml"];
@@ -32,8 +67,8 @@ function readEpubInternal(bytes, sink) {
32
67
  const opfDir = dirname(opfPath);
33
68
  const opf = parseOpf(decodeText(opfBytes), sink);
34
69
  const manifestById = new Map(opf.manifest.map((item) => [item.id, item]));
35
- const sections = [];
36
70
  const spineFullPaths = [];
71
+ const resolvedItems = [];
37
72
  for (const itemref of opf.spine) {
38
73
  const manifestItem = manifestById.get(itemref.idref);
39
74
  if (manifestItem === void 0) {
@@ -56,12 +91,22 @@ function readEpubInternal(bytes, sink) {
56
91
  });
57
92
  continue;
58
93
  }
94
+ resolvedItems.push({
95
+ fullPath,
96
+ xml: decodeText(xhtmlBytes)
97
+ });
98
+ }
99
+ const anchorRegistry = buildCrossDocumentAnchorRegistry(resolvedItems);
100
+ const sections = [];
101
+ for (const { fullPath, xml } of resolvedItems) {
59
102
  const sectionDir = dirname(fullPath);
60
- const { blocks, source } = readXhtmlBody(decodeText(xhtmlBytes), {
103
+ const { blocks, source } = readXhtmlBody(xml, {
61
104
  resolveImage: (src) => entries[resolvePackagePath(sectionDir, src)],
62
105
  sink,
63
106
  sourceHref: fullPath,
64
- contentWidthPt: CONTENT_WIDTH_PT
107
+ contentWidthPt: CONTENT_WIDTH_PT,
108
+ extraAnchorTargets: anchorRegistry.targetsByHref.get(fullPath),
109
+ resolveCrossDocumentAnchorHref: (href) => anchorRegistry.resolveHref(fullPath, href)
65
110
  });
66
111
  sections.push({
67
112
  pageSize: PAGE_SIZE_A4,
@@ -0,0 +1,4 @@
1
+ //#region src/nav/reconcile.d.ts
2
+ declare function navMatchesSpine(navHrefs: readonly string[], spineHrefs: readonly string[]): boolean;
3
+ //#endregion
4
+ export { navMatchesSpine as t };
@@ -0,0 +1,4 @@
1
+ //#region src/nav/reconcile.d.ts
2
+ declare function navMatchesSpine(navHrefs: readonly string[], spineHrefs: readonly string[]): boolean;
3
+ //#endregion
4
+ export { navMatchesSpine as t };
@@ -0,0 +1,8 @@
1
+ //#region src/xhtml/style-constants.d.ts
2
+ declare const HORIZONTAL_RULE_STYLE_ID = "HorizontalRule";
3
+ declare const QUOTE_STYLE_ID = "Quote";
4
+ declare const QUOTE_INDENT_PT = 36;
5
+ declare const MONOSPACE_FONT_FAMILY = "Courier New";
6
+ declare const DEFINITION_BODY_INDENT_PT = 36;
7
+ //#endregion
8
+ export { QUOTE_STYLE_ID as a, QUOTE_INDENT_PT as i, HORIZONTAL_RULE_STYLE_ID as n, MONOSPACE_FONT_FAMILY as r, DEFINITION_BODY_INDENT_PT as t };
@@ -0,0 +1,8 @@
1
+ //#region src/xhtml/style-constants.d.ts
2
+ declare const HORIZONTAL_RULE_STYLE_ID = "HorizontalRule";
3
+ declare const QUOTE_STYLE_ID = "Quote";
4
+ declare const QUOTE_INDENT_PT = 36;
5
+ declare const MONOSPACE_FONT_FAMILY = "Courier New";
6
+ declare const DEFINITION_BODY_INDENT_PT = 36;
7
+ //#endregion
8
+ export { QUOTE_STYLE_ID as a, QUOTE_INDENT_PT as i, HORIZONTAL_RULE_STYLE_ID as n, MONOSPACE_FONT_FAMILY as r, DEFINITION_BODY_INDENT_PT as t };
@@ -0,0 +1,20 @@
1
+ import { LayoutMetadata } from "document-schema.js";
2
+ //#region src/opf/types.d.ts
3
+ interface OpfManifestItem {
4
+ readonly id: string;
5
+ readonly href: string;
6
+ readonly mediaType: string;
7
+ readonly properties: readonly string[];
8
+ }
9
+ interface OpfSpineItemRef {
10
+ readonly idref: string;
11
+ readonly linear: boolean;
12
+ }
13
+ interface OpfPackage {
14
+ readonly metadata: LayoutMetadata;
15
+ readonly manifest: readonly OpfManifestItem[];
16
+ readonly spine: readonly OpfSpineItemRef[];
17
+ readonly ncxId: string | undefined;
18
+ }
19
+ //#endregion
20
+ export { OpfPackage as n, OpfSpineItemRef as r, OpfManifestItem as t };
@@ -0,0 +1,20 @@
1
+ import { LayoutMetadata } from "document-schema.js";
2
+ //#region src/opf/types.d.ts
3
+ interface OpfManifestItem {
4
+ readonly id: string;
5
+ readonly href: string;
6
+ readonly mediaType: string;
7
+ readonly properties: readonly string[];
8
+ }
9
+ interface OpfSpineItemRef {
10
+ readonly idref: string;
11
+ readonly linear: boolean;
12
+ }
13
+ interface OpfPackage {
14
+ readonly metadata: LayoutMetadata;
15
+ readonly manifest: readonly OpfManifestItem[];
16
+ readonly spine: readonly OpfSpineItemRef[];
17
+ readonly ncxId: string | undefined;
18
+ }
19
+ //#endregion
20
+ export { OpfPackage as n, OpfSpineItemRef as r, OpfManifestItem as t };
@@ -1,5 +1,2 @@
1
- //#region src/util/base64.d.ts
2
- declare function bytesToBase64(bytes: Uint8Array<ArrayBuffer>): string;
3
- declare function base64ToBytes(b64: string): Uint8Array<ArrayBuffer>;
4
- //#endregion
1
+ import { n as bytesToBase64, t as base64ToBytes } from "../base64--HuymRl_.cjs";
5
2
  export { base64ToBytes, bytesToBase64 };
@@ -1,5 +1,2 @@
1
- //#region src/util/base64.d.ts
2
- declare function bytesToBase64(bytes: Uint8Array<ArrayBuffer>): string;
3
- declare function base64ToBytes(b64: string): Uint8Array<ArrayBuffer>;
4
- //#endregion
1
+ import { n as bytesToBase64, t as base64ToBytes } from "../base64--HuymRl_.js";
5
2
  export { base64ToBytes, bytesToBase64 };
@@ -0,0 +1,12 @@
1
+ import { t as OpfManifestItem } from "./types-BxmkPT_F.cjs";
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,10 @@
1
+ import { i as EpubDiagnosticSink } from "./diagnostics-C0CRdoda.js";
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
10
+ export { writeEpub as n, writeEpubContent as r, WriteEpubOptions as t };
@@ -0,0 +1,10 @@
1
+ import { i as EpubDiagnosticSink } from "./diagnostics-C0CRdoda.cjs";
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
10
+ export { writeEpub as n, writeEpubContent as r, WriteEpubOptions as t };
@@ -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 };