epub-codec 1.2.11 → 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 +19 -22
package/dist/xhtml/read.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_xml_node = require("../xml/node.cjs");
|
|
3
|
+
const require_util_base64 = require("../util/base64.cjs");
|
|
4
|
+
const require_xml_parse = require("../xml/parse.cjs");
|
|
5
|
+
const require_xml_build = require("../xml/build.cjs");
|
|
2
6
|
const require_diagnostics = require("../diagnostics.cjs");
|
|
3
7
|
const require_xml_entities = require("../xml/entities.cjs");
|
|
4
|
-
const require_xml_node = require("../xml/node.cjs");
|
|
5
8
|
const require_xml_query = require("../xml/query.cjs");
|
|
6
|
-
const
|
|
9
|
+
const require_xhtml_footnote = require("./footnote.cjs");
|
|
7
10
|
const require_image_dimensions = require("../image/dimensions.cjs");
|
|
8
|
-
const require_util_base64 = require("../util/base64.cjs");
|
|
9
|
-
const require_xml_build = require("../xml/build.cjs");
|
|
10
11
|
const require_xhtml_context = require("./context.cjs");
|
|
11
|
-
const require_xhtml_footnote = require("./footnote.cjs");
|
|
12
12
|
const require_xhtml_style_constants = require("./style-constants.cjs");
|
|
13
13
|
const require_xhtml_inline = require("./inline.cjs");
|
|
14
14
|
const require_xhtml_list_id = require("./list-id.cjs");
|
|
@@ -100,6 +100,19 @@ function elementsWithTagSkippingInert(nodes, tag) {
|
|
|
100
100
|
}
|
|
101
101
|
return out;
|
|
102
102
|
}
|
|
103
|
+
function scanXhtmlAnchors(xml) {
|
|
104
|
+
const nodes = require_xml_parse.parseXml(xml);
|
|
105
|
+
const html = require_xml_query.rootElement(nodes);
|
|
106
|
+
const body = html === void 0 ? void 0 : require_xml_query.findChildElement(html.children, "body");
|
|
107
|
+
if (body === void 0) return {
|
|
108
|
+
idElements: /* @__PURE__ */ new Map(),
|
|
109
|
+
anchors: []
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
idElements: buildIdElementMap(body.children),
|
|
113
|
+
anchors: elementsWithTagSkippingInert(body.children, "a").filter((anchor) => require_xml_query.attrValue(anchor, "href") !== void 0)
|
|
114
|
+
};
|
|
115
|
+
}
|
|
103
116
|
function readStyleResidue(html, context) {
|
|
104
117
|
const head = require_xml_query.findChildElement(html.children, "head");
|
|
105
118
|
if (head === void 0) return;
|
|
@@ -125,17 +138,27 @@ function readXhtmlBody(xml, options) {
|
|
|
125
138
|
source: void 0
|
|
126
139
|
};
|
|
127
140
|
const idElements = buildIdElementMap(body.children);
|
|
128
|
-
const
|
|
141
|
+
const anchorTargets = new Map(options.extraAnchorTargets);
|
|
129
142
|
for (const anchor of elementsWithTagSkippingInert(body.children, "a")) {
|
|
130
|
-
const
|
|
131
|
-
|
|
143
|
+
const fragment = require_xhtml_footnote.sameDocumentFragment(require_xml_query.attrValue(anchor, "href"));
|
|
144
|
+
const target = fragment === void 0 ? void 0 : idElements.get(fragment);
|
|
145
|
+
if (fragment === void 0 || target === void 0 || !BLOCK_LEVEL_TAGS.has(target.tag) || anchorTargets.has(fragment)) continue;
|
|
146
|
+
anchorTargets.set(fragment, {
|
|
147
|
+
anchorType: require_xhtml_footnote.isFootnoteReference(anchor, target) ? "footnote" : "bookmark",
|
|
148
|
+
name: fragment
|
|
149
|
+
});
|
|
132
150
|
}
|
|
133
151
|
const context = {
|
|
134
152
|
resolveImage: options.resolveImage,
|
|
135
153
|
sink: options.sink,
|
|
136
154
|
sourceHref: options.sourceHref,
|
|
137
155
|
idElements,
|
|
138
|
-
|
|
156
|
+
anchorTargets,
|
|
157
|
+
resolveAnchorHref: (href) => {
|
|
158
|
+
const fragment = require_xhtml_footnote.sameDocumentFragment(href);
|
|
159
|
+
if (fragment !== void 0) return anchorTargets.get(fragment);
|
|
160
|
+
return options.resolveCrossDocumentAnchorHref?.(href);
|
|
161
|
+
},
|
|
139
162
|
quoteDepth: 0
|
|
140
163
|
};
|
|
141
164
|
const state = {
|
|
@@ -208,16 +231,17 @@ function headingLevelOf(tag) {
|
|
|
208
231
|
}
|
|
209
232
|
function readBlockElement(element, state) {
|
|
210
233
|
const id = require_xml_query.attrValue(element, "id");
|
|
211
|
-
const isFootnoteTarget = id !== void 0 && state.context.footnoteTargetIds.has(id) && !require_xhtml_footnote.isFootnoteAside(element);
|
|
212
234
|
const blocks = readBlockElementInner(element, state);
|
|
213
|
-
if (
|
|
235
|
+
if (id === void 0) return blocks;
|
|
236
|
+
const target = state.context.anchorTargets.get(id);
|
|
237
|
+
if (target === void 0 || require_xhtml_footnote.isFootnoteAside(element)) return blocks;
|
|
214
238
|
return [
|
|
215
239
|
{
|
|
216
240
|
kind: "constructStart",
|
|
217
241
|
descriptor: {
|
|
218
242
|
kind: "anchor",
|
|
219
|
-
anchorType:
|
|
220
|
-
name:
|
|
243
|
+
anchorType: target.anchorType,
|
|
244
|
+
name: target.name
|
|
221
245
|
}
|
|
222
246
|
},
|
|
223
247
|
...blocks,
|
|
@@ -280,10 +304,16 @@ function readPreFlatRuns(nodes, context) {
|
|
|
280
304
|
fontFamily: require_xhtml_style_constants.MONOSPACE_FONT_FAMILY
|
|
281
305
|
}] : [];
|
|
282
306
|
}
|
|
307
|
+
function preFootnoteReferenceName(anchor, context) {
|
|
308
|
+
const href = require_xml_query.attrValue(anchor, "href");
|
|
309
|
+
if (href === void 0) return;
|
|
310
|
+
const target = context.resolveAnchorHref(href);
|
|
311
|
+
return target?.anchorType === "footnote" ? target.name : void 0;
|
|
312
|
+
}
|
|
283
313
|
function containsFootnoteReference(nodes, context) {
|
|
284
314
|
for (const node of nodes) {
|
|
285
315
|
if (node.type !== "element" || require_xhtml_context.isInertElement(node.tag)) continue;
|
|
286
|
-
if (node.tag === "a" &&
|
|
316
|
+
if (node.tag === "a" && preFootnoteReferenceName(node, context) !== void 0) return true;
|
|
287
317
|
if (containsFootnoteReference(node.children, context)) return true;
|
|
288
318
|
}
|
|
289
319
|
return false;
|
|
@@ -318,7 +348,7 @@ function readPreRuns(nodes, context) {
|
|
|
318
348
|
buffer += "\n";
|
|
319
349
|
continue;
|
|
320
350
|
}
|
|
321
|
-
const footnoteName = node.tag === "a" ?
|
|
351
|
+
const footnoteName = node.tag === "a" ? preFootnoteReferenceName(node, context) : void 0;
|
|
322
352
|
if (footnoteName === void 0 && !containsFootnoteReference([node], context)) {
|
|
323
353
|
buffer += readPreText(node.children, context);
|
|
324
354
|
continue;
|
|
@@ -659,8 +689,8 @@ function readImage(element, state) {
|
|
|
659
689
|
}
|
|
660
690
|
function readAside(element, state) {
|
|
661
691
|
if (!require_xhtml_footnote.isFootnoteAside(element)) return readContainerChildren(element.children, state);
|
|
662
|
-
const
|
|
663
|
-
if (
|
|
692
|
+
const id = require_xml_query.attrValue(element, "id");
|
|
693
|
+
if (id === void 0) {
|
|
664
694
|
state.context.sink({
|
|
665
695
|
code: require_diagnostics.EpubDiagnosticCodes.FOOTNOTE_TARGET_UNRESOLVED,
|
|
666
696
|
severity: "warning",
|
|
@@ -675,7 +705,7 @@ function readAside(element, state) {
|
|
|
675
705
|
descriptor: {
|
|
676
706
|
kind: "anchor",
|
|
677
707
|
anchorType: "footnote",
|
|
678
|
-
name
|
|
708
|
+
name: state.context.anchorTargets.get(id)?.name ?? id
|
|
679
709
|
}
|
|
680
710
|
},
|
|
681
711
|
...readContainerChildren(element.children, state),
|
|
@@ -683,4 +713,6 @@ function readAside(element, state) {
|
|
|
683
713
|
];
|
|
684
714
|
}
|
|
685
715
|
//#endregion
|
|
716
|
+
exports.BLOCK_LEVEL_TAGS = BLOCK_LEVEL_TAGS;
|
|
686
717
|
exports.readXhtmlBody = readXhtmlBody;
|
|
718
|
+
exports.scanXhtmlAnchors = scanXhtmlAnchors;
|
package/dist/xhtml/read.d.cts
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
interface ReadXhtmlBodyOptions {
|
|
4
|
-
readonly resolveImage: (href: string) => Uint8Array<ArrayBuffer> | undefined;
|
|
5
|
-
readonly sink: (diagnostic: {
|
|
6
|
-
code: string;
|
|
7
|
-
severity: "info" | "warning";
|
|
8
|
-
message: string;
|
|
9
|
-
href?: string;
|
|
10
|
-
}) => void;
|
|
11
|
-
readonly sourceHref: string;
|
|
12
|
-
readonly contentWidthPt: number;
|
|
13
|
-
}
|
|
14
|
-
interface ReadXhtmlBodyResult {
|
|
15
|
-
readonly blocks: ContentBlock[];
|
|
16
|
-
readonly source: SourceResidue | undefined;
|
|
17
|
-
}
|
|
18
|
-
declare function readXhtmlBody(xml: string, options: ReadXhtmlBodyOptions): ReadXhtmlBodyResult;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { ReadXhtmlBodyOptions, ReadXhtmlBodyResult, readXhtmlBody };
|
|
1
|
+
import { a as readXhtmlBody, i as XhtmlAnchorScan, n as ReadXhtmlBodyOptions, o as scanXhtmlAnchors, r as ReadXhtmlBodyResult, t as BLOCK_LEVEL_TAGS } from "../read-BMGq_D9y.cjs";
|
|
2
|
+
export { BLOCK_LEVEL_TAGS, ReadXhtmlBodyOptions, ReadXhtmlBodyResult, XhtmlAnchorScan, readXhtmlBody, scanXhtmlAnchors };
|
package/dist/xhtml/read.d.ts
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
interface ReadXhtmlBodyOptions {
|
|
4
|
-
readonly resolveImage: (href: string) => Uint8Array<ArrayBuffer> | undefined;
|
|
5
|
-
readonly sink: (diagnostic: {
|
|
6
|
-
code: string;
|
|
7
|
-
severity: "info" | "warning";
|
|
8
|
-
message: string;
|
|
9
|
-
href?: string;
|
|
10
|
-
}) => void;
|
|
11
|
-
readonly sourceHref: string;
|
|
12
|
-
readonly contentWidthPt: number;
|
|
13
|
-
}
|
|
14
|
-
interface ReadXhtmlBodyResult {
|
|
15
|
-
readonly blocks: ContentBlock[];
|
|
16
|
-
readonly source: SourceResidue | undefined;
|
|
17
|
-
}
|
|
18
|
-
declare function readXhtmlBody(xml: string, options: ReadXhtmlBodyOptions): ReadXhtmlBodyResult;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { ReadXhtmlBodyOptions, ReadXhtmlBodyResult, readXhtmlBody };
|
|
1
|
+
import { a as readXhtmlBody, i as XhtmlAnchorScan, n as ReadXhtmlBodyOptions, o as scanXhtmlAnchors, r as ReadXhtmlBodyResult, t as BLOCK_LEVEL_TAGS } from "../read-Czqr3aop.js";
|
|
2
|
+
export { BLOCK_LEVEL_TAGS, ReadXhtmlBodyOptions, ReadXhtmlBodyResult, XhtmlAnchorScan, readXhtmlBody, scanXhtmlAnchors };
|
package/dist/xhtml/read.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { isTextLikeNode } from "../xml/node.js";
|
|
2
|
+
import { bytesToBase64 } from "../util/base64.js";
|
|
3
|
+
import { parseXml } from "../xml/parse.js";
|
|
4
|
+
import { buildXml } from "../xml/build.js";
|
|
1
5
|
import { EpubDiagnosticCodes } from "../diagnostics.js";
|
|
2
6
|
import { decodeEntities, decodeTextLikeNode } from "../xml/entities.js";
|
|
3
|
-
import { isTextLikeNode } from "../xml/node.js";
|
|
4
7
|
import { attrValue, findChildElement, rootElement } from "../xml/query.js";
|
|
5
|
-
import {
|
|
8
|
+
import { isFootnoteAside, isFootnoteReference, sameDocumentFragment } from "./footnote.js";
|
|
6
9
|
import { POINTS_PER_PIXEL, detectImageFormat, readImageDimensions } from "../image/dimensions.js";
|
|
7
|
-
import { bytesToBase64 } from "../util/base64.js";
|
|
8
|
-
import { buildXml } from "../xml/build.js";
|
|
9
10
|
import { isInertElement, reportInertElementSkip } from "./context.js";
|
|
10
|
-
import { isFootnoteAside, isFootnoteReferenceAnchor } from "./footnote.js";
|
|
11
11
|
import { HORIZONTAL_RULE_STYLE_ID, MONOSPACE_FONT_FAMILY } from "./style-constants.js";
|
|
12
12
|
import { buildInlineRuns, rebaseConstructs } from "./inline.js";
|
|
13
13
|
import { mintListNumId } from "./list-id.js";
|
|
@@ -99,6 +99,19 @@ function elementsWithTagSkippingInert(nodes, tag) {
|
|
|
99
99
|
}
|
|
100
100
|
return out;
|
|
101
101
|
}
|
|
102
|
+
function scanXhtmlAnchors(xml) {
|
|
103
|
+
const nodes = parseXml(xml);
|
|
104
|
+
const html = rootElement(nodes);
|
|
105
|
+
const body = html === void 0 ? void 0 : findChildElement(html.children, "body");
|
|
106
|
+
if (body === void 0) return {
|
|
107
|
+
idElements: /* @__PURE__ */ new Map(),
|
|
108
|
+
anchors: []
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
idElements: buildIdElementMap(body.children),
|
|
112
|
+
anchors: elementsWithTagSkippingInert(body.children, "a").filter((anchor) => attrValue(anchor, "href") !== void 0)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
102
115
|
function readStyleResidue(html, context) {
|
|
103
116
|
const head = findChildElement(html.children, "head");
|
|
104
117
|
if (head === void 0) return;
|
|
@@ -124,17 +137,27 @@ function readXhtmlBody(xml, options) {
|
|
|
124
137
|
source: void 0
|
|
125
138
|
};
|
|
126
139
|
const idElements = buildIdElementMap(body.children);
|
|
127
|
-
const
|
|
140
|
+
const anchorTargets = new Map(options.extraAnchorTargets);
|
|
128
141
|
for (const anchor of elementsWithTagSkippingInert(body.children, "a")) {
|
|
129
|
-
const
|
|
130
|
-
|
|
142
|
+
const fragment = sameDocumentFragment(attrValue(anchor, "href"));
|
|
143
|
+
const target = fragment === void 0 ? void 0 : idElements.get(fragment);
|
|
144
|
+
if (fragment === void 0 || target === void 0 || !BLOCK_LEVEL_TAGS.has(target.tag) || anchorTargets.has(fragment)) continue;
|
|
145
|
+
anchorTargets.set(fragment, {
|
|
146
|
+
anchorType: isFootnoteReference(anchor, target) ? "footnote" : "bookmark",
|
|
147
|
+
name: fragment
|
|
148
|
+
});
|
|
131
149
|
}
|
|
132
150
|
const context = {
|
|
133
151
|
resolveImage: options.resolveImage,
|
|
134
152
|
sink: options.sink,
|
|
135
153
|
sourceHref: options.sourceHref,
|
|
136
154
|
idElements,
|
|
137
|
-
|
|
155
|
+
anchorTargets,
|
|
156
|
+
resolveAnchorHref: (href) => {
|
|
157
|
+
const fragment = sameDocumentFragment(href);
|
|
158
|
+
if (fragment !== void 0) return anchorTargets.get(fragment);
|
|
159
|
+
return options.resolveCrossDocumentAnchorHref?.(href);
|
|
160
|
+
},
|
|
138
161
|
quoteDepth: 0
|
|
139
162
|
};
|
|
140
163
|
const state = {
|
|
@@ -207,16 +230,17 @@ function headingLevelOf(tag) {
|
|
|
207
230
|
}
|
|
208
231
|
function readBlockElement(element, state) {
|
|
209
232
|
const id = attrValue(element, "id");
|
|
210
|
-
const isFootnoteTarget = id !== void 0 && state.context.footnoteTargetIds.has(id) && !isFootnoteAside(element);
|
|
211
233
|
const blocks = readBlockElementInner(element, state);
|
|
212
|
-
if (
|
|
234
|
+
if (id === void 0) return blocks;
|
|
235
|
+
const target = state.context.anchorTargets.get(id);
|
|
236
|
+
if (target === void 0 || isFootnoteAside(element)) return blocks;
|
|
213
237
|
return [
|
|
214
238
|
{
|
|
215
239
|
kind: "constructStart",
|
|
216
240
|
descriptor: {
|
|
217
241
|
kind: "anchor",
|
|
218
|
-
anchorType:
|
|
219
|
-
name:
|
|
242
|
+
anchorType: target.anchorType,
|
|
243
|
+
name: target.name
|
|
220
244
|
}
|
|
221
245
|
},
|
|
222
246
|
...blocks,
|
|
@@ -279,10 +303,16 @@ function readPreFlatRuns(nodes, context) {
|
|
|
279
303
|
fontFamily: MONOSPACE_FONT_FAMILY
|
|
280
304
|
}] : [];
|
|
281
305
|
}
|
|
306
|
+
function preFootnoteReferenceName(anchor, context) {
|
|
307
|
+
const href = attrValue(anchor, "href");
|
|
308
|
+
if (href === void 0) return;
|
|
309
|
+
const target = context.resolveAnchorHref(href);
|
|
310
|
+
return target?.anchorType === "footnote" ? target.name : void 0;
|
|
311
|
+
}
|
|
282
312
|
function containsFootnoteReference(nodes, context) {
|
|
283
313
|
for (const node of nodes) {
|
|
284
314
|
if (node.type !== "element" || isInertElement(node.tag)) continue;
|
|
285
|
-
if (node.tag === "a" &&
|
|
315
|
+
if (node.tag === "a" && preFootnoteReferenceName(node, context) !== void 0) return true;
|
|
286
316
|
if (containsFootnoteReference(node.children, context)) return true;
|
|
287
317
|
}
|
|
288
318
|
return false;
|
|
@@ -317,7 +347,7 @@ function readPreRuns(nodes, context) {
|
|
|
317
347
|
buffer += "\n";
|
|
318
348
|
continue;
|
|
319
349
|
}
|
|
320
|
-
const footnoteName = node.tag === "a" ?
|
|
350
|
+
const footnoteName = node.tag === "a" ? preFootnoteReferenceName(node, context) : void 0;
|
|
321
351
|
if (footnoteName === void 0 && !containsFootnoteReference([node], context)) {
|
|
322
352
|
buffer += readPreText(node.children, context);
|
|
323
353
|
continue;
|
|
@@ -658,8 +688,8 @@ function readImage(element, state) {
|
|
|
658
688
|
}
|
|
659
689
|
function readAside(element, state) {
|
|
660
690
|
if (!isFootnoteAside(element)) return readContainerChildren(element.children, state);
|
|
661
|
-
const
|
|
662
|
-
if (
|
|
691
|
+
const id = attrValue(element, "id");
|
|
692
|
+
if (id === void 0) {
|
|
663
693
|
state.context.sink({
|
|
664
694
|
code: EpubDiagnosticCodes.FOOTNOTE_TARGET_UNRESOLVED,
|
|
665
695
|
severity: "warning",
|
|
@@ -674,7 +704,7 @@ function readAside(element, state) {
|
|
|
674
704
|
descriptor: {
|
|
675
705
|
kind: "anchor",
|
|
676
706
|
anchorType: "footnote",
|
|
677
|
-
name
|
|
707
|
+
name: state.context.anchorTargets.get(id)?.name ?? id
|
|
678
708
|
}
|
|
679
709
|
},
|
|
680
710
|
...readContainerChildren(element.children, state),
|
|
@@ -682,4 +712,4 @@ function readAside(element, state) {
|
|
|
682
712
|
];
|
|
683
713
|
}
|
|
684
714
|
//#endregion
|
|
685
|
-
export { readXhtmlBody };
|
|
715
|
+
export { BLOCK_LEVEL_TAGS, readXhtmlBody, scanXhtmlAnchors };
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
|
|
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
|
|
1
|
+
import { a as QUOTE_STYLE_ID, i as QUOTE_INDENT_PT, n as HORIZONTAL_RULE_STYLE_ID, r as MONOSPACE_FONT_FAMILY, t as DEFINITION_BODY_INDENT_PT } from "../style-constants-RVoHdmju.cjs";
|
|
8
2
|
export { DEFINITION_BODY_INDENT_PT, HORIZONTAL_RULE_STYLE_ID, MONOSPACE_FONT_FAMILY, QUOTE_INDENT_PT, QUOTE_STYLE_ID };
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
|
|
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
|
|
1
|
+
import { a as QUOTE_STYLE_ID, i as QUOTE_INDENT_PT, n as HORIZONTAL_RULE_STYLE_ID, r as MONOSPACE_FONT_FAMILY, t as DEFINITION_BODY_INDENT_PT } from "../style-constants-RVoHdmju.js";
|
|
8
2
|
export { DEFINITION_BODY_INDENT_PT, HORIZONTAL_RULE_STYLE_ID, MONOSPACE_FONT_FAMILY, QUOTE_INDENT_PT, QUOTE_STYLE_ID };
|
package/dist/xhtml/write.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_util_base64 = require("../util/base64.cjs");
|
|
2
3
|
const require_diagnostics = require("../diagnostics.cjs");
|
|
3
4
|
const require_xml_entities = require("../xml/entities.cjs");
|
|
4
|
-
const require_util_base64 = require("../util/base64.cjs");
|
|
5
5
|
require("./style-constants.cjs");
|
|
6
6
|
const require_xhtml_list_id = require("./list-id.cjs");
|
|
7
7
|
let document_schema_js = require("document-schema.js");
|
|
@@ -93,6 +93,7 @@ function writeSectionConstructGroup(group, context) {
|
|
|
93
93
|
"epub:type": "footnote",
|
|
94
94
|
id: descriptor.name
|
|
95
95
|
}, writeSectionChildren(group.children, context))];
|
|
96
|
+
if (descriptor.kind === "anchor" && descriptor.anchorType === "bookmark") return writeBookmarkConstructGroup(descriptor.name, group, context);
|
|
96
97
|
context.sink({
|
|
97
98
|
code: require_diagnostics.EpubDiagnosticCodes.CONSTRUCT_UNREPRESENTED,
|
|
98
99
|
severity: "info",
|
|
@@ -101,6 +102,24 @@ function writeSectionConstructGroup(group, context) {
|
|
|
101
102
|
});
|
|
102
103
|
return writeSectionChildren(group.children, context);
|
|
103
104
|
}
|
|
105
|
+
function writeBookmarkConstructGroup(name, group, context) {
|
|
106
|
+
const written = writeSectionChildren(group.children, context);
|
|
107
|
+
const [only] = written;
|
|
108
|
+
if (written.length === 1 && only?.type === "element") return [{
|
|
109
|
+
...only,
|
|
110
|
+
attributes: [...only.attributes.filter((attribute) => attribute.name !== "id"), {
|
|
111
|
+
name: "id",
|
|
112
|
+
value: name
|
|
113
|
+
}]
|
|
114
|
+
}];
|
|
115
|
+
context.sink({
|
|
116
|
+
code: require_diagnostics.EpubDiagnosticCodes.CONSTRUCT_UNREPRESENTED,
|
|
117
|
+
severity: "info",
|
|
118
|
+
message: `a bookmark target ('${name}') wraps more than one written element (or none); this package's writer only restores an id attribute onto a single wrapped element, so the target's own addressability is dropped`,
|
|
119
|
+
href: context.sourceHref
|
|
120
|
+
});
|
|
121
|
+
return written;
|
|
122
|
+
}
|
|
104
123
|
function writeLeafBlock(block, context) {
|
|
105
124
|
switch (block.kind) {
|
|
106
125
|
case "paragraph": return [writeParagraph(block, context)];
|
|
@@ -139,12 +158,19 @@ function writeParagraphAsEmbeddedNodes(paragraph, context, wrapOrdinaryInParagra
|
|
|
139
158
|
const runNodes = writeRunsToNodes(paragraph.runs, paragraph.constructs, context);
|
|
140
159
|
return wrapOrdinaryInParagraph ? [element("p", {}, runNodes)] : runNodes;
|
|
141
160
|
}
|
|
142
|
-
function
|
|
143
|
-
return construct.descriptor.kind === "anchor" && construct.descriptor.anchorType === "footnote";
|
|
161
|
+
function isReferenceExtent(construct) {
|
|
162
|
+
return construct.descriptor.kind === "anchor" && construct.descriptor.anchorType === "footnote" || construct.descriptor.kind === "link" && construct.descriptor.target.kind === "internal";
|
|
163
|
+
}
|
|
164
|
+
function referenceExtentAttrs(descriptor, context) {
|
|
165
|
+
if (descriptor.kind === "anchor") return {
|
|
166
|
+
"epub:type": "noteref",
|
|
167
|
+
href: context.resolveAnchorHref(descriptor.name)
|
|
168
|
+
};
|
|
169
|
+
return { href: context.resolveAnchorHref(descriptor.target.anchor) };
|
|
144
170
|
}
|
|
145
171
|
function reportUnhandledAnchorExtents(constructs, context) {
|
|
146
172
|
for (const construct of constructs ?? []) {
|
|
147
|
-
if (construct
|
|
173
|
+
if (isReferenceExtent(construct) || construct.descriptor.kind !== "anchor") continue;
|
|
148
174
|
context.sink({
|
|
149
175
|
code: require_diagnostics.EpubDiagnosticCodes.CONSTRUCT_UNREPRESENTED,
|
|
150
176
|
severity: "info",
|
|
@@ -153,33 +179,32 @@ function reportUnhandledAnchorExtents(constructs, context) {
|
|
|
153
179
|
});
|
|
154
180
|
}
|
|
155
181
|
}
|
|
156
|
-
function
|
|
157
|
-
|
|
158
|
-
|
|
182
|
+
function referenceExtentName(descriptor) {
|
|
183
|
+
return descriptor.kind === "anchor" ? descriptor.name : descriptor.target.anchor;
|
|
184
|
+
}
|
|
185
|
+
function describeUnrepresentedReferenceExtent(extent) {
|
|
186
|
+
const kind = extent.descriptor.kind === "anchor" ? "footnote reference" : "internal link";
|
|
187
|
+
const name = referenceExtentName(extent.descriptor);
|
|
188
|
+
if (extent.endRun === extent.startRun) return `a ${kind} ('${name}') marking the boundary before run ${extent.startRun} is never reached by the write walk -- either because it sits inside another reference's own winning run range, or because its own run range falls outside this paragraph's actual runs; a point anchor wraps no run text of its own, so nothing besides this reference's own <a> link is missing from the output`;
|
|
189
|
+
return `a ${kind} ('${name}') is never reached by the write walk and cannot be represented as its own <a> element -- either because it overlaps another reference's own winning run range, or because its own run range falls outside this paragraph's actual runs; wherever an overlap is the cause, the run text underneath it is not lost, since it is still written, wrapped by whichever extent's range actually claims it, or written unwrapped past it, but this reference's own anchor link is not emitted regardless of cause`;
|
|
159
190
|
}
|
|
160
191
|
function writeRunRangeNodes(runs, constructs, renderRun, renderExtentRange, context) {
|
|
161
192
|
reportUnhandledAnchorExtents(constructs, context);
|
|
162
|
-
const
|
|
193
|
+
const referenceExtents = (constructs ?? []).filter(isReferenceExtent);
|
|
163
194
|
const emittedExtents = /* @__PURE__ */ new Set();
|
|
164
195
|
const out = [];
|
|
165
196
|
let index = 0;
|
|
166
197
|
while (index <= runs.length) {
|
|
167
|
-
const extentsHere =
|
|
198
|
+
const extentsHere = referenceExtents.filter((e) => e.startRun === index);
|
|
168
199
|
for (const point of extentsHere.filter((e) => e.endRun === e.startRun)) {
|
|
169
200
|
emittedExtents.add(point);
|
|
170
|
-
out.push(element("a",
|
|
171
|
-
"epub:type": "noteref",
|
|
172
|
-
href: `#${point.descriptor.name}`
|
|
173
|
-
}, renderExtentRange([])));
|
|
201
|
+
out.push(element("a", referenceExtentAttrs(point.descriptor, context), renderExtentRange([])));
|
|
174
202
|
}
|
|
175
203
|
const [primaryRange] = index < runs.length ? extentsHere.filter((e) => e.endRun > e.startRun) : [];
|
|
176
204
|
if (primaryRange !== void 0) {
|
|
177
205
|
emittedExtents.add(primaryRange);
|
|
178
206
|
const rangeRuns = runs.slice(primaryRange.startRun, primaryRange.endRun);
|
|
179
|
-
out.push(element("a",
|
|
180
|
-
"epub:type": "noteref",
|
|
181
|
-
href: `#${primaryRange.descriptor.name}`
|
|
182
|
-
}, renderExtentRange(rangeRuns)));
|
|
207
|
+
out.push(element("a", referenceExtentAttrs(primaryRange.descriptor, context), renderExtentRange(rangeRuns)));
|
|
183
208
|
index = primaryRange.endRun;
|
|
184
209
|
continue;
|
|
185
210
|
}
|
|
@@ -187,12 +212,12 @@ function writeRunRangeNodes(runs, constructs, renderRun, renderExtentRange, cont
|
|
|
187
212
|
if (run !== void 0) out.push(...renderRun(run));
|
|
188
213
|
index += 1;
|
|
189
214
|
}
|
|
190
|
-
for (const extent of
|
|
215
|
+
for (const extent of referenceExtents) {
|
|
191
216
|
if (emittedExtents.has(extent)) continue;
|
|
192
217
|
context.sink({
|
|
193
218
|
code: require_diagnostics.EpubDiagnosticCodes.CONSTRUCT_UNREPRESENTED,
|
|
194
219
|
severity: "info",
|
|
195
|
-
message:
|
|
220
|
+
message: describeUnrepresentedReferenceExtent(extent),
|
|
196
221
|
href: context.sourceHref
|
|
197
222
|
});
|
|
198
223
|
}
|
package/dist/xhtml/write.d.cts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { XmlElement } from "../xml/node.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
|
-
}
|
|
10
|
-
declare function writeXhtmlBody(blocks: readonly ContentBlock[], context: XhtmlWriteContext): XmlElement;
|
|
11
|
-
//#endregion
|
|
1
|
+
import { n as writeXhtmlBody, t as XhtmlWriteContext } from "../write-WSIgARHT.cjs";
|
|
12
2
|
export { XhtmlWriteContext, writeXhtmlBody };
|
package/dist/xhtml/write.d.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { XmlElement } from "../xml/node.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
|
-
}
|
|
10
|
-
declare function writeXhtmlBody(blocks: readonly ContentBlock[], context: XhtmlWriteContext): XmlElement;
|
|
11
|
-
//#endregion
|
|
1
|
+
import { n as writeXhtmlBody, t as XhtmlWriteContext } from "../write-Klo0WDhT.js";
|
|
12
2
|
export { XhtmlWriteContext, writeXhtmlBody };
|
package/dist/xhtml/write.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { base64ToBytes } from "../util/base64.js";
|
|
1
2
|
import { EpubDiagnosticCodes } from "../diagnostics.js";
|
|
2
3
|
import { encodeEntities } from "../xml/entities.js";
|
|
3
|
-
import { base64ToBytes } from "../util/base64.js";
|
|
4
4
|
import "./style-constants.js";
|
|
5
5
|
import { parseListNumId } from "./list-id.js";
|
|
6
6
|
import { isHeadingGroupNode, isListGroupNode, isSectionConstructGroupNode, isTreeBlockLeaf } from "document-schema.js";
|
|
@@ -92,6 +92,7 @@ function writeSectionConstructGroup(group, context) {
|
|
|
92
92
|
"epub:type": "footnote",
|
|
93
93
|
id: descriptor.name
|
|
94
94
|
}, writeSectionChildren(group.children, context))];
|
|
95
|
+
if (descriptor.kind === "anchor" && descriptor.anchorType === "bookmark") return writeBookmarkConstructGroup(descriptor.name, group, context);
|
|
95
96
|
context.sink({
|
|
96
97
|
code: EpubDiagnosticCodes.CONSTRUCT_UNREPRESENTED,
|
|
97
98
|
severity: "info",
|
|
@@ -100,6 +101,24 @@ function writeSectionConstructGroup(group, context) {
|
|
|
100
101
|
});
|
|
101
102
|
return writeSectionChildren(group.children, context);
|
|
102
103
|
}
|
|
104
|
+
function writeBookmarkConstructGroup(name, group, context) {
|
|
105
|
+
const written = writeSectionChildren(group.children, context);
|
|
106
|
+
const [only] = written;
|
|
107
|
+
if (written.length === 1 && only?.type === "element") return [{
|
|
108
|
+
...only,
|
|
109
|
+
attributes: [...only.attributes.filter((attribute) => attribute.name !== "id"), {
|
|
110
|
+
name: "id",
|
|
111
|
+
value: name
|
|
112
|
+
}]
|
|
113
|
+
}];
|
|
114
|
+
context.sink({
|
|
115
|
+
code: EpubDiagnosticCodes.CONSTRUCT_UNREPRESENTED,
|
|
116
|
+
severity: "info",
|
|
117
|
+
message: `a bookmark target ('${name}') wraps more than one written element (or none); this package's writer only restores an id attribute onto a single wrapped element, so the target's own addressability is dropped`,
|
|
118
|
+
href: context.sourceHref
|
|
119
|
+
});
|
|
120
|
+
return written;
|
|
121
|
+
}
|
|
103
122
|
function writeLeafBlock(block, context) {
|
|
104
123
|
switch (block.kind) {
|
|
105
124
|
case "paragraph": return [writeParagraph(block, context)];
|
|
@@ -138,12 +157,19 @@ function writeParagraphAsEmbeddedNodes(paragraph, context, wrapOrdinaryInParagra
|
|
|
138
157
|
const runNodes = writeRunsToNodes(paragraph.runs, paragraph.constructs, context);
|
|
139
158
|
return wrapOrdinaryInParagraph ? [element("p", {}, runNodes)] : runNodes;
|
|
140
159
|
}
|
|
141
|
-
function
|
|
142
|
-
return construct.descriptor.kind === "anchor" && construct.descriptor.anchorType === "footnote";
|
|
160
|
+
function isReferenceExtent(construct) {
|
|
161
|
+
return construct.descriptor.kind === "anchor" && construct.descriptor.anchorType === "footnote" || construct.descriptor.kind === "link" && construct.descriptor.target.kind === "internal";
|
|
162
|
+
}
|
|
163
|
+
function referenceExtentAttrs(descriptor, context) {
|
|
164
|
+
if (descriptor.kind === "anchor") return {
|
|
165
|
+
"epub:type": "noteref",
|
|
166
|
+
href: context.resolveAnchorHref(descriptor.name)
|
|
167
|
+
};
|
|
168
|
+
return { href: context.resolveAnchorHref(descriptor.target.anchor) };
|
|
143
169
|
}
|
|
144
170
|
function reportUnhandledAnchorExtents(constructs, context) {
|
|
145
171
|
for (const construct of constructs ?? []) {
|
|
146
|
-
if (construct
|
|
172
|
+
if (isReferenceExtent(construct) || construct.descriptor.kind !== "anchor") continue;
|
|
147
173
|
context.sink({
|
|
148
174
|
code: EpubDiagnosticCodes.CONSTRUCT_UNREPRESENTED,
|
|
149
175
|
severity: "info",
|
|
@@ -152,33 +178,32 @@ function reportUnhandledAnchorExtents(constructs, context) {
|
|
|
152
178
|
});
|
|
153
179
|
}
|
|
154
180
|
}
|
|
155
|
-
function
|
|
156
|
-
|
|
157
|
-
|
|
181
|
+
function referenceExtentName(descriptor) {
|
|
182
|
+
return descriptor.kind === "anchor" ? descriptor.name : descriptor.target.anchor;
|
|
183
|
+
}
|
|
184
|
+
function describeUnrepresentedReferenceExtent(extent) {
|
|
185
|
+
const kind = extent.descriptor.kind === "anchor" ? "footnote reference" : "internal link";
|
|
186
|
+
const name = referenceExtentName(extent.descriptor);
|
|
187
|
+
if (extent.endRun === extent.startRun) return `a ${kind} ('${name}') marking the boundary before run ${extent.startRun} is never reached by the write walk -- either because it sits inside another reference's own winning run range, or because its own run range falls outside this paragraph's actual runs; a point anchor wraps no run text of its own, so nothing besides this reference's own <a> link is missing from the output`;
|
|
188
|
+
return `a ${kind} ('${name}') is never reached by the write walk and cannot be represented as its own <a> element -- either because it overlaps another reference's own winning run range, or because its own run range falls outside this paragraph's actual runs; wherever an overlap is the cause, the run text underneath it is not lost, since it is still written, wrapped by whichever extent's range actually claims it, or written unwrapped past it, but this reference's own anchor link is not emitted regardless of cause`;
|
|
158
189
|
}
|
|
159
190
|
function writeRunRangeNodes(runs, constructs, renderRun, renderExtentRange, context) {
|
|
160
191
|
reportUnhandledAnchorExtents(constructs, context);
|
|
161
|
-
const
|
|
192
|
+
const referenceExtents = (constructs ?? []).filter(isReferenceExtent);
|
|
162
193
|
const emittedExtents = /* @__PURE__ */ new Set();
|
|
163
194
|
const out = [];
|
|
164
195
|
let index = 0;
|
|
165
196
|
while (index <= runs.length) {
|
|
166
|
-
const extentsHere =
|
|
197
|
+
const extentsHere = referenceExtents.filter((e) => e.startRun === index);
|
|
167
198
|
for (const point of extentsHere.filter((e) => e.endRun === e.startRun)) {
|
|
168
199
|
emittedExtents.add(point);
|
|
169
|
-
out.push(element("a",
|
|
170
|
-
"epub:type": "noteref",
|
|
171
|
-
href: `#${point.descriptor.name}`
|
|
172
|
-
}, renderExtentRange([])));
|
|
200
|
+
out.push(element("a", referenceExtentAttrs(point.descriptor, context), renderExtentRange([])));
|
|
173
201
|
}
|
|
174
202
|
const [primaryRange] = index < runs.length ? extentsHere.filter((e) => e.endRun > e.startRun) : [];
|
|
175
203
|
if (primaryRange !== void 0) {
|
|
176
204
|
emittedExtents.add(primaryRange);
|
|
177
205
|
const rangeRuns = runs.slice(primaryRange.startRun, primaryRange.endRun);
|
|
178
|
-
out.push(element("a",
|
|
179
|
-
"epub:type": "noteref",
|
|
180
|
-
href: `#${primaryRange.descriptor.name}`
|
|
181
|
-
}, renderExtentRange(rangeRuns)));
|
|
206
|
+
out.push(element("a", referenceExtentAttrs(primaryRange.descriptor, context), renderExtentRange(rangeRuns)));
|
|
182
207
|
index = primaryRange.endRun;
|
|
183
208
|
continue;
|
|
184
209
|
}
|
|
@@ -186,12 +211,12 @@ function writeRunRangeNodes(runs, constructs, renderRun, renderExtentRange, cont
|
|
|
186
211
|
if (run !== void 0) out.push(...renderRun(run));
|
|
187
212
|
index += 1;
|
|
188
213
|
}
|
|
189
|
-
for (const extent of
|
|
214
|
+
for (const extent of referenceExtents) {
|
|
190
215
|
if (emittedExtents.has(extent)) continue;
|
|
191
216
|
context.sink({
|
|
192
217
|
code: EpubDiagnosticCodes.CONSTRUCT_UNREPRESENTED,
|
|
193
218
|
severity: "info",
|
|
194
|
-
message:
|
|
219
|
+
message: describeUnrepresentedReferenceExtent(extent),
|
|
195
220
|
href: context.sourceHref
|
|
196
221
|
});
|
|
197
222
|
}
|
package/dist/xml/build.d.cts
CHANGED
package/dist/xml/build.d.ts
CHANGED