@stll/folio-core 0.72.0 → 0.74.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 +12 -6
- package/dist/ai-edits/applyTypes.d.ts +85 -0
- package/dist/ai-edits/applyTypes.js +24 -0
- package/dist/ai-edits/clean-text.d.ts +7 -1
- package/dist/ai-edits/clean-text.js +23 -2
- package/dist/ai-edits/finalSectionReview.d.ts +1 -1
- package/dist/ai-edits/headless.d.ts +29 -147
- package/dist/ai-edits/headless.js +215 -1639
- package/dist/ai-edits/index.d.ts +3 -3
- package/dist/ai-edits/index.js +2 -3
- package/dist/ai-edits/pending-suggestions.d.ts +14 -4
- package/dist/ai-edits/pending-suggestions.js +183 -90
- package/dist/ai-edits/pendingJoin.js +6 -1
- package/dist/ai-edits/retired-comment-receipts.d.ts +1 -1
- package/dist/ai-edits/snapshot.js +9 -4
- package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
- package/dist/ai-edits/table-cell-mutations.js +2 -2
- package/dist/ai-edits/table-geometry.d.ts +1 -1
- package/dist/ai-edits/table-geometry.js +1 -1
- package/dist/ai-edits/table-row-column-mutations.d.ts +1 -1
- package/dist/ai-edits/table-row-column-mutations.js +1 -1
- package/dist/ai-edits/tableNodes.d.ts +38 -0
- package/dist/ai-edits/tableNodes.js +86 -0
- package/dist/ai-edits/tracked-batch-fidelity.d.ts +1 -1
- package/dist/ai-edits/tracked-batch-fidelity.js +1 -1
- package/dist/ai-edits/undefinedReferences.d.ts +7 -0
- package/dist/canonical/batchCommentReferences.js +1 -0
- package/dist/canonical/canonicalInlineGaps.d.ts +56 -0
- package/dist/canonical/canonicalInlineGaps.js +118 -0
- package/dist/canonical/canonicalInlineProjection.d.ts +4 -13
- package/dist/canonical/canonicalInlineProjection.js +5 -27
- package/dist/canonical/canonicalProjectionBlocks.d.ts +4 -4
- package/dist/canonical/canonicalPublicOperations.js +282 -75
- package/dist/canonical/canonicalSelection.js +1 -1
- package/dist/canonical/canonicalSession.d.ts +9 -1
- package/dist/canonical/canonicalSession.js +106 -33
- package/dist/compare/compare.d.ts +1 -1
- package/dist/compare/inline-atoms-model.d.ts +1 -1
- package/dist/compare/inline-atoms.d.ts +2 -2
- package/dist/compare/inline-provenance-model.d.ts +1 -1
- package/dist/compare/inline-provenance.d.ts +2 -2
- package/dist/compat/eigenpal.d.ts +3 -3
- package/dist/compat/eigenpal.js +2 -3
- package/dist/controller/autocompleteSuggestion.js +1 -1
- package/dist/controller/canonicalClipboard.d.ts +13 -3
- package/dist/controller/canonicalClipboard.js +186 -50
- package/dist/controller/canonicalClipboardResources.d.ts +9 -1
- package/dist/controller/canonicalClipboardResources.js +22 -2
- package/dist/controller/canonicalComposition.js +1 -1
- package/dist/controller/canonicalInput.js +1 -1
- package/dist/controller/canonicalPresence.js +1 -1
- package/dist/controller/canonicalReview.d.ts +1 -1
- package/dist/controller/canonicalReview.js +1 -1
- package/dist/controller/canonicalRoomAuthority.js +1 -1
- package/dist/controller/canonicalRoomWire.js +1 -1
- package/dist/controller/canonicalStructure.js +1 -1
- package/dist/controller/canonicalTabRoom.js +1 -1
- package/dist/controller/canonicalWatermark.d.ts +10 -0
- package/dist/controller/canonicalWatermark.js +37 -0
- package/dist/controller/canonicalYjsRoom.js +1 -1
- package/dist/controller/hiddenEditorApi.d.ts +1 -1
- package/dist/controller/hiddenEditorApi.js +2 -17
- package/dist/controller/hiddenEditorManager.d.ts +4 -3
- package/dist/controller/hiddenEditorManager.js +79 -23
- package/dist/document-operations.d.ts +1 -14
- package/dist/document-operations.js +1 -278
- package/dist/docx/canonicalSave.d.ts +1 -1
- package/dist/docx/canonicalSave.js +1 -1
- package/dist/docx/canonicalSessionInput.js +1 -1
- package/dist/docx/containerChildren.js +1 -1
- package/dist/docx/createDocx.d.ts +4 -0
- package/dist/docx/createDocx.js +6 -0
- package/dist/docx/paragraphParser.js +2 -2
- package/dist/docx/paragraphPropertySource.d.ts +1 -1
- package/dist/docx/parser.js +1 -1
- package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
- package/dist/docx/reviewResolutionProvenance.js +31 -8
- package/dist/docx/revisionIdNormalization.js +30 -7
- package/dist/docx/rezip.d.ts +1 -1
- package/dist/docx/rezip.js +1 -1
- package/dist/docx/serializer/tableSerializer.js +4 -36
- package/dist/docx/server/templatePlan/apply.d.ts +15 -0
- package/dist/docx/server/templatePlan/apply.js +658 -0
- package/dist/docx/server/templatePlan/blocks.d.ts +97 -0
- package/dist/docx/server/templatePlan/blocks.js +355 -0
- package/dist/docx/server/templatePlan/builders.d.ts +72 -0
- package/dist/docx/server/templatePlan/builders.js +237 -0
- package/dist/docx/server/templatePlan/emit.d.ts +118 -0
- package/dist/docx/server/templatePlan/emit.js +466 -0
- package/dist/docx/server/templatePlan/emphasis.d.ts +62 -0
- package/dist/docx/server/templatePlan/emphasis.js +173 -0
- package/dist/docx/server/templatePlan/inspect.d.ts +22 -0
- package/dist/docx/server/templatePlan/inspect.js +230 -0
- package/dist/docx/server/templatePlan/labels.d.ts +45 -0
- package/dist/docx/server/templatePlan/labels.js +155 -0
- package/dist/docx/server/templatePlan/package.d.ts +34 -0
- package/dist/docx/server/templatePlan/package.js +99 -0
- package/dist/docx/server/templatePlan/plan.d.ts +145 -0
- package/dist/docx/server/templatePlan/plan.js +875 -0
- package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
- package/dist/docx/server/templatePlan/planShape.js +180 -0
- package/dist/docx/server/templatePlan/resources.d.ts +41 -0
- package/dist/docx/server/templatePlan/resources.js +136 -0
- package/dist/docx/server/templatePlan/story.d.ts +128 -0
- package/dist/docx/server/templatePlan/story.js +440 -0
- package/dist/docx/server/templatePlan/types.d.ts +442 -0
- package/dist/docx/server/templatePlan/types.js +29 -0
- package/dist/docx/server/templatePlan/verify.d.ts +40 -0
- package/dist/docx/server/templatePlan/verify.js +976 -0
- package/dist/docx/server/templatePlan/xml.d.ts +74 -0
- package/dist/docx/server/templatePlan/xml.js +125 -0
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
- package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
- package/dist/docx/structuralXmlPatch.js +9 -1
- package/dist/docx/tableGridXml.d.ts +30 -0
- package/dist/docx/tableGridXml.js +54 -0
- package/dist/docx/tableParser.js +7 -0
- package/dist/i18n/loadMessages.d.ts +5 -0
- package/dist/i18n/loadMessages.js +46 -0
- package/dist/i18n/locales.d.ts +3 -0
- package/dist/i18n/locales.js +17 -0
- package/dist/i18n/messages.d.ts +3 -2
- package/dist/i18n/messages.js +4 -16
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -3
- package/dist/internal/clipboardTransformPlugin.d.ts +3 -0
- package/dist/internal/clipboardTransformPlugin.js +13 -0
- package/dist/internal/extensionRuntime.d.ts +7 -0
- package/dist/internal/extensionRuntime.js +28 -0
- package/dist/internal/starterKitExtensions.d.ts +20 -0
- package/dist/internal/starterKitExtensions.js +123 -0
- package/dist/internal/wholeStoryRevisionResolution.js +1 -1
- package/dist/managers/ContextMenuManager.js +2 -1
- package/dist/managers/editorShortcuts.d.ts +1 -1
- package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
- package/dist/prosemirror/attrs/index.js +1 -1
- package/dist/prosemirror/canonicalCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
- package/dist/prosemirror/canonicalSelectionRange.js +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +3 -3
- package/dist/prosemirror/commands/comments.js +4 -4
- package/dist/prosemirror/commands/contentControls.d.ts +1 -1
- package/dist/prosemirror/commands/contentControls.js +1 -1
- package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
- package/dist/prosemirror/commands/pastePlainText.js +2 -3
- package/dist/prosemirror/commands/replaceRangeText.js +1 -1
- package/dist/prosemirror/commands/sectionBreak.js +1 -1
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +1 -1
- package/dist/prosemirror/commentRecords.d.ts +1 -1
- package/dist/prosemirror/commentRecords.js +2 -2
- package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +0 -5
- package/dist/prosemirror/conversion/fromProseDoc.js +2 -9
- package/dist/prosemirror/conversion/index.d.ts +2 -2
- package/dist/prosemirror/conversion/index.js +2 -2
- package/dist/prosemirror/documentStructureCounts.d.ts +24 -0
- package/dist/prosemirror/documentStructureCounts.js +76 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
- package/dist/prosemirror/extensions/ExtensionManager.js +4 -22
- package/dist/prosemirror/extensions/StarterKit.d.ts +4 -27
- package/dist/prosemirror/extensions/StarterKit.js +29 -115
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -1
- package/dist/prosemirror/extensions/core/historyCommands.d.ts +16 -0
- package/dist/prosemirror/extensions/core/historyCommands.js +19 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
- package/dist/prosemirror/extensions/features/ListExtension.js +7 -2
- package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
- package/dist/prosemirror/extensions/index.d.ts +2 -1
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +8 -3
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +8 -41
- package/dist/prosemirror/extensions/types.d.ts +1 -1
- package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
- package/dist/prosemirror/hyperlinkRemoval.d.ts +1 -1
- package/dist/prosemirror/hyperlinkRemoval.js +7 -2
- package/dist/prosemirror/index.d.ts +3 -3
- package/dist/prosemirror/index.js +3 -3
- package/dist/prosemirror/insertionGaps.d.ts +1 -1
- package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
- package/dist/prosemirror/keptRangeBoundaries.js +1 -1
- package/dist/prosemirror/listNumbering.d.ts +1 -1
- package/dist/prosemirror/listNumbering.js +1 -1
- package/dist/prosemirror/lockedControls.d.ts +1 -1
- package/dist/prosemirror/markupViewProjection.d.ts +1 -1
- package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
- package/dist/prosemirror/noteReferenceOccurrences.js +1 -1
- package/dist/prosemirror/noteReferenceReview.d.ts +2 -56
- package/dist/prosemirror/noteReferenceReview.js +2 -243
- package/dist/prosemirror/{extensions/features/ParaIdAllocatorExtension.d.ts → paraIds.d.ts} +13 -23
- package/dist/prosemirror/paraIds.js +152 -0
- package/dist/prosemirror/paragraphChangeTrackerMeta.d.ts +97 -0
- package/dist/prosemirror/paragraphChangeTrackerMeta.js +87 -0
- package/dist/prosemirror/paragraphMarkJoin.d.ts +1 -1
- package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -1
- package/dist/prosemirror/pastedCommentCopies.d.ts +1 -1
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
- package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
- package/dist/prosemirror/plugins/documentNumbering.js +1 -1
- package/dist/prosemirror/plugins/documentStyles.js +1 -1
- package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
- package/dist/prosemirror/rebaseParagraphRuns.d.ts +1 -1
- package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.js +17 -2
- package/dist/prosemirror/revisionCarriers.d.ts +1 -1
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
- package/dist/prosemirror/sectionMarkEdits.d.ts +1 -1
- package/dist/prosemirror/selectionBounds.d.ts +10 -0
- package/dist/prosemirror/selectionBounds.js +22 -0
- package/dist/prosemirror/storyListNumbering.d.ts +1 -1
- package/dist/prosemirror/suggestionCommands.d.ts +47 -0
- package/dist/prosemirror/suggestionCommands.js +31 -0
- package/dist/prosemirror/tableCellPaste.d.ts +1 -1
- package/dist/prosemirror/tableCellPaste.js +1 -1
- package/dist/prosemirror/tableGridMutation.d.ts +1 -1
- package/dist/prosemirror/tableRunIn.js +1 -1
- package/dist/prosemirror/textInput.d.ts +1 -1
- package/dist/prosemirror/textInput.js +1 -1
- package/dist/server.d.ts +7 -2
- package/dist/server.js +6 -1
- package/dist/types/canonicalCapabilities.d.ts +13 -92
- package/dist/types/canonicalCapabilities.js +11 -85
- package/package.json +4 -4
- package/dist/ai-edits/apply.d.ts +0 -202
- package/dist/ai-edits/apply.js +0 -6759
- package/dist/ai-edits/note-story-inventory.d.ts +0 -5
- package/dist/ai-edits/note-story-inventory.js +0 -10
- package/dist/ai-edits/revisionStretches.d.ts +0 -32
- package/dist/ai-edits/revisionStretches.js +0 -147
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +0 -18
- package/dist/prosemirror/extensions/core/HistoryExtension.js +0 -122
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +0 -408
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +0 -135
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +0 -566
- package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -92
- package/dist/prosemirror/plugins/suggestionMode.js +0 -1515
- package/dist/prosemirror/tablePositionedBookmarks.d.ts +0 -8
- package/dist/prosemirror/tablePositionedBookmarks.js +0 -80
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
import { RELATIONSHIP_TYPES, parseRelationships } from "../../relsParser.js";
|
|
2
|
+
import { captureVerbatimXml } from "../../verbatimCapture.js";
|
|
3
|
+
import { OFFICE_RELATIONSHIP_NAMESPACE_URIS, WORDPROCESSINGML_NAMESPACE_URIS, cloneElement, getLocalName, parseXmlDocument } from "../../xmlParser.js";
|
|
4
|
+
import { appendToXmlRoot } from "../../xmlRootInsertion.js";
|
|
5
|
+
import { bookmarkEndXml, bookmarkStartXml, complexFieldXml, wrapParagraphContentInBookmark } from "./builders.js";
|
|
6
|
+
import { runPropertiesXml } from "./emphasis.js";
|
|
7
|
+
import { paragraphPieces } from "./plan.js";
|
|
8
|
+
import { TemplatePlanError } from "./types.js";
|
|
9
|
+
import { MATH_NAMESPACE, elementChildren, escapeXmlAttribute, escapeXmlText, wAttr, wChild, wChildren, wName } from "./xml.js";
|
|
10
|
+
import { Result, panic } from "better-result";
|
|
11
|
+
import { resolveNamespaceUri } from "@stll/docx-core/xml/namespaces";
|
|
12
|
+
// src/docx/server/templatePlan/emit.ts
|
|
13
|
+
/**
|
|
14
|
+
* The markup of what a resolved plan places: paragraphs, tables and notes
|
|
15
|
+
* rebuilt from source content in the template's own spelling. Text, tabs,
|
|
16
|
+
* breaks, note references, links and stated emphasis travel; fonts, sizes,
|
|
17
|
+
* colours and direct paragraph formatting stay behind.
|
|
18
|
+
*/
|
|
19
|
+
const PACKAGE_RELATIONSHIPS_NAMESPACE = "http://schemas.openxmlformats.org/package/2006/relationships";
|
|
20
|
+
/**
|
|
21
|
+
* An editor over a relationships part that may not exist yet. Null when the
|
|
22
|
+
* part exists and its root is not a relationships root.
|
|
23
|
+
*/
|
|
24
|
+
const createRelationshipsEditor = (path, existing) => {
|
|
25
|
+
const source = existing ?? `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="${PACKAGE_RELATIONSHIPS_NAMESPACE}"></Relationships>`;
|
|
26
|
+
const known = parseRelationships(source);
|
|
27
|
+
const reserved = new Set(known.keys());
|
|
28
|
+
let next = 1;
|
|
29
|
+
for (const id of reserved) {
|
|
30
|
+
const number = /^rId(?<number>\d{1,15})$/u.exec(id)?.groups?.["number"];
|
|
31
|
+
if (number !== void 0) next = Math.max(next, Number(number) + 1);
|
|
32
|
+
}
|
|
33
|
+
const added = /* @__PURE__ */ new Map();
|
|
34
|
+
const markup = [];
|
|
35
|
+
const root = parseXmlDocument(source);
|
|
36
|
+
if (root?.name === void 0 || getLocalName(root.name) !== "Relationships" || root.namespaceUri !== PACKAGE_RELATIONSHIPS_NAMESPACE) return null;
|
|
37
|
+
const rootName = root.name;
|
|
38
|
+
const colon = rootName.indexOf(":");
|
|
39
|
+
const elementName = colon === -1 ? "Relationship" : `${rootName.slice(0, colon)}:Relationship`;
|
|
40
|
+
return {
|
|
41
|
+
path,
|
|
42
|
+
add: ({ type, target, external }) => {
|
|
43
|
+
const key = `${type}\u0000${target}\u0000${external ? "1" : "0"}`;
|
|
44
|
+
const reused = added.get(key);
|
|
45
|
+
if (reused !== void 0) return reused;
|
|
46
|
+
let id = `rId${next}`;
|
|
47
|
+
while (reserved.has(id)) {
|
|
48
|
+
next += 1;
|
|
49
|
+
id = `rId${next}`;
|
|
50
|
+
}
|
|
51
|
+
next += 1;
|
|
52
|
+
reserved.add(id);
|
|
53
|
+
added.set(key, id);
|
|
54
|
+
markup.push(`<${elementName} Id="${id}" Type="${escapeXmlAttribute(type)}" Target="${escapeXmlAttribute(target)}"${external ? " TargetMode=\"External\"" : ""}/>`);
|
|
55
|
+
return id;
|
|
56
|
+
},
|
|
57
|
+
xml: () => markup.length === 0 ? null : appendToXmlRoot(source, {
|
|
58
|
+
rootName,
|
|
59
|
+
markup: markup.join("")
|
|
60
|
+
})
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
const styleNamed = ({ styles }, type, name) => [...styles.values()].find((style) => style.type === type && style.name?.toLowerCase() === name)?.styleId ?? null;
|
|
64
|
+
/** The template styles conventional marks and note text are written with. */
|
|
65
|
+
const templateCharacterStyles = (template) => ({
|
|
66
|
+
hyperlink: styleNamed(template, "character", "hyperlink"),
|
|
67
|
+
footnoteReference: styleNamed(template, "character", "footnote reference"),
|
|
68
|
+
endnoteReference: styleNamed(template, "character", "endnote reference"),
|
|
69
|
+
footnoteText: styleNamed(template, "paragraph", "footnote text"),
|
|
70
|
+
endnoteText: styleNamed(template, "paragraph", "endnote text")
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* The external address a link leads to, or null for a link the output cannot
|
|
74
|
+
* carry: one to a bookmark of the source, or one whose relationship is
|
|
75
|
+
* missing or does not name an external address.
|
|
76
|
+
*/
|
|
77
|
+
const linkAddress = (link, relationships) => {
|
|
78
|
+
if (link === null) return null;
|
|
79
|
+
switch (link.kind) {
|
|
80
|
+
case "url": return {
|
|
81
|
+
url: link.url,
|
|
82
|
+
anchor: link.anchor
|
|
83
|
+
};
|
|
84
|
+
case "relationship": {
|
|
85
|
+
const relationship = relationships.get(link.relationshipId);
|
|
86
|
+
return relationship === void 0 || relationship.type !== RELATIONSHIP_TYPES.hyperlink || relationship.targetMode !== "External" ? null : {
|
|
87
|
+
url: relationship.target,
|
|
88
|
+
anchor: link.anchor
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
case "anchor": return null;
|
|
92
|
+
default: return link;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
/** One string per address, for comparing what a link leads to. */
|
|
96
|
+
const linkAddressKey = (address) => address === null ? "" : `${address.url}${address.anchor === null ? "" : `#${address.anchor}`}`;
|
|
97
|
+
const linkTargetOf = ({ link, origin }, context) => {
|
|
98
|
+
const address = linkAddress(link, context.sourceRelationships[origin]);
|
|
99
|
+
return address === null ? null : {
|
|
100
|
+
relationshipId: context.relationships.add({
|
|
101
|
+
type: RELATIONSHIP_TYPES.hyperlink,
|
|
102
|
+
target: address.url,
|
|
103
|
+
external: true
|
|
104
|
+
}),
|
|
105
|
+
anchor: address.anchor
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
const sameLink = (left, right) => {
|
|
109
|
+
if (left === null || right === null) return left === right;
|
|
110
|
+
if (left.kind === "relationship" && right.kind === "relationship") return left.relationshipId === right.relationshipId && left.anchor === right.anchor;
|
|
111
|
+
if (left.kind === "url" && right.kind === "url") return left.url === right.url && left.anchor === right.anchor;
|
|
112
|
+
return left.kind === "anchor" && right.kind === "anchor" && left.anchor === right.anchor;
|
|
113
|
+
};
|
|
114
|
+
/** An object of the source with its relationships and drawing ids re-homed. */
|
|
115
|
+
const transferObject = ({ atom, origin }, context) => {
|
|
116
|
+
const element = atom?.element;
|
|
117
|
+
if (element === void 0 || element === null) return Result.ok("");
|
|
118
|
+
let refusal = null;
|
|
119
|
+
const mapRelationship = (id) => {
|
|
120
|
+
const relationship = context.sourceRelationships[origin].get(id);
|
|
121
|
+
if (relationship === void 0) {
|
|
122
|
+
refusal ??= new TemplatePlanError({
|
|
123
|
+
code: "unsupported-content",
|
|
124
|
+
message: `An object refers to the missing relationship ${id}.`
|
|
125
|
+
});
|
|
126
|
+
return id;
|
|
127
|
+
}
|
|
128
|
+
const external = relationship.targetMode === "External";
|
|
129
|
+
if (relationship.type === RELATIONSHIP_TYPES.hyperlink && !external) {
|
|
130
|
+
refusal ??= new TemplatePlanError({
|
|
131
|
+
code: "unsupported-content",
|
|
132
|
+
message: "An object links to a part of the source package."
|
|
133
|
+
});
|
|
134
|
+
return id;
|
|
135
|
+
}
|
|
136
|
+
if (external) return context.relationships.add({
|
|
137
|
+
type: relationship.type,
|
|
138
|
+
target: relationship.target,
|
|
139
|
+
external
|
|
140
|
+
});
|
|
141
|
+
const path = context.resolveSourceTarget(origin, relationship.target);
|
|
142
|
+
const media = context.sourceMedia.get(path);
|
|
143
|
+
if (relationship.type !== RELATIONSHIP_TYPES.image || media === void 0) {
|
|
144
|
+
refusal ??= new TemplatePlanError({
|
|
145
|
+
code: "unsupported-content",
|
|
146
|
+
message: "An embedded object other than a picture cannot be moved onto a template."
|
|
147
|
+
});
|
|
148
|
+
return id;
|
|
149
|
+
}
|
|
150
|
+
return context.relationships.add({
|
|
151
|
+
type: RELATIONSHIP_TYPES.image,
|
|
152
|
+
target: context.addMedia(path, media),
|
|
153
|
+
external: false
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
const rehome = (node) => {
|
|
157
|
+
if (node.type !== "element") return node;
|
|
158
|
+
const attributes = { ...node.attributes };
|
|
159
|
+
for (const [name, value] of Object.entries(node.attributes ?? {})) {
|
|
160
|
+
const colon = name.indexOf(":");
|
|
161
|
+
if (value === void 0 || colon === -1 || name.startsWith("xmlns:")) continue;
|
|
162
|
+
const uri = resolveNamespaceUri(node.namespaceScope, name.slice(0, colon));
|
|
163
|
+
if (OFFICE_RELATIONSHIP_NAMESPACE_URIS.has(uri ?? "")) attributes[name] = mapRelationship(String(value));
|
|
164
|
+
}
|
|
165
|
+
if (getLocalName(node.name) === "docPr" && attributes["id"] !== void 0) attributes["id"] = String(context.nextDrawingId());
|
|
166
|
+
return cloneElement(node, {
|
|
167
|
+
attributes,
|
|
168
|
+
...node.elements === void 0 ? {} : { elements: node.elements.map(rehome) }
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
const xml = captureVerbatimXml(rehome(element));
|
|
172
|
+
return refusal === null ? Result.ok(xml) : Result.err(refusal);
|
|
173
|
+
};
|
|
174
|
+
const wAttributesXml = (element, prefix) => Object.entries(element.attributes ?? {}).map(([name, value]) => {
|
|
175
|
+
const colon = name.indexOf(":");
|
|
176
|
+
if (value === void 0 || colon === -1 || name.startsWith("xmlns:")) return "";
|
|
177
|
+
const uri = resolveNamespaceUri(element.namespaceScope, name.slice(0, colon));
|
|
178
|
+
return WORDPROCESSINGML_NAMESPACE_URIS.has(uri ?? "") ? ` ${prefix}:${name.slice(colon + 1)}="${escapeXmlAttribute(String(value))}"` : "";
|
|
179
|
+
}).join("");
|
|
180
|
+
/**
|
|
181
|
+
* A WordprocessingML subtree re-spelled under `prefix`. Elements and
|
|
182
|
+
* attributes of other namespaces are left out: this copies structure such as
|
|
183
|
+
* a table grid, never content.
|
|
184
|
+
*/
|
|
185
|
+
const wSubtreeXml = (element, prefix) => {
|
|
186
|
+
const name = wName(element);
|
|
187
|
+
if (name === null) return "";
|
|
188
|
+
const children = elementChildren(element).map((child) => wSubtreeXml(child, prefix)).join("");
|
|
189
|
+
const open = `<${prefix}:${name}${wAttributesXml(element, prefix)}`;
|
|
190
|
+
return children === "" ? `${open}/>` : `${open}>${children}</${prefix}:${name}>`;
|
|
191
|
+
};
|
|
192
|
+
const pieceRunXml = (piece, context, linked) => {
|
|
193
|
+
const { w } = context.prefixes;
|
|
194
|
+
const properties = (rStyle) => runPropertiesXml({
|
|
195
|
+
prefix: w,
|
|
196
|
+
signature: piece.signature,
|
|
197
|
+
rStyle,
|
|
198
|
+
escapeAttribute: escapeXmlAttribute
|
|
199
|
+
});
|
|
200
|
+
const run = (content, rStyle = null) => `<${w}:r>${properties(rStyle ?? (linked ? context.styles.hyperlink : null))}${content}</${w}:r>`;
|
|
201
|
+
switch (piece.kind) {
|
|
202
|
+
case "text": return Result.ok(piece.text === "" ? "" : run(`<${w}:t xml:space="preserve">${escapeXmlText(piece.text)}</${w}:t>`));
|
|
203
|
+
case "tab": return Result.ok(run(`<${w}:tab/>`));
|
|
204
|
+
case "lineBreak": return Result.ok(run(`<${w}:br/>`));
|
|
205
|
+
case "pageBreak": {
|
|
206
|
+
const type = wAttr(piece.atom?.element, "type") ?? "page";
|
|
207
|
+
return Result.ok(run(`<${w}:br ${w}:type="${escapeXmlAttribute(type)}"/>`));
|
|
208
|
+
}
|
|
209
|
+
case "noBreakHyphen": return Result.ok(run(`<${w}:noBreakHyphen/>`));
|
|
210
|
+
case "softHyphen": return Result.ok(run(`<${w}:softHyphen/>`));
|
|
211
|
+
case "symbol": {
|
|
212
|
+
const element = piece.atom?.element;
|
|
213
|
+
return Result.ok(element === void 0 || element === null ? "" : run(wSubtreeXml(element, w)));
|
|
214
|
+
}
|
|
215
|
+
case "footnoteReference":
|
|
216
|
+
case "endnoteReference": {
|
|
217
|
+
const kind = piece.kind === "footnoteReference" ? "footnote" : "endnote";
|
|
218
|
+
const sourceId = wAttr(piece.atom?.element, "id");
|
|
219
|
+
if (sourceId === null) return Result.ok("");
|
|
220
|
+
const style = kind === "footnote" ? context.styles.footnoteReference : context.styles.endnoteReference;
|
|
221
|
+
const mark = `<${w}:${kind}Reference ${w}:id="${context.noteId(kind, sourceId)}"/>`;
|
|
222
|
+
return Result.ok(style === null ? `<${w}:r><${w}:rPr><${w}:vertAlign ${w}:val="superscript"/></${w}:rPr>${mark}</${w}:r>` : `<${w}:r><${w}:rPr><${w}:rStyle ${w}:val="${escapeXmlAttribute(style)}"/></${w}:rPr>${mark}</${w}:r>`);
|
|
223
|
+
}
|
|
224
|
+
case "object": {
|
|
225
|
+
const transferred = transferObject(piece, context);
|
|
226
|
+
if (Result.isError(transferred)) return transferred;
|
|
227
|
+
return Result.ok(piece.atom?.element?.namespaceUri === MATH_NAMESPACE ? transferred.value : run(transferred.value));
|
|
228
|
+
}
|
|
229
|
+
default: return piece.kind;
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
/** Adjacent text pieces that state the same emphasis and link become one run. */
|
|
233
|
+
const mergedPieces = (pieces) => {
|
|
234
|
+
const merged = [];
|
|
235
|
+
for (const piece of pieces) {
|
|
236
|
+
const last = merged.at(-1);
|
|
237
|
+
if (last !== void 0 && last.kind === "text" && piece.kind === "text" && last.signature === piece.signature && last.origin === piece.origin && sameLink(last.link, piece.link)) merged[merged.length - 1] = {
|
|
238
|
+
...last,
|
|
239
|
+
text: last.text + piece.text
|
|
240
|
+
};
|
|
241
|
+
else merged.push(piece);
|
|
242
|
+
}
|
|
243
|
+
return merged;
|
|
244
|
+
};
|
|
245
|
+
const piecesRunsXml = (pieces, context) => {
|
|
246
|
+
const { w, r } = context.prefixes;
|
|
247
|
+
const out = [];
|
|
248
|
+
let group = null;
|
|
249
|
+
const flush = () => {
|
|
250
|
+
if (group === null) return;
|
|
251
|
+
out.push(`<${w}:hyperlink${context.prefixes.rDeclaration} ${r}:id="${escapeXmlAttribute(group.relationshipId)}"${group.anchor === null ? "" : ` ${w}:anchor="${escapeXmlAttribute(group.anchor)}"`} ${w}:history="1">${group.runs.join("")}</${w}:hyperlink>`);
|
|
252
|
+
group = null;
|
|
253
|
+
};
|
|
254
|
+
for (const piece of mergedPieces(pieces)) {
|
|
255
|
+
const target = linkTargetOf(piece, context);
|
|
256
|
+
if (group !== null && (target === null || !sameLink(group.link, piece.link))) flush();
|
|
257
|
+
const run = pieceRunXml(piece, context, target !== null);
|
|
258
|
+
if (Result.isError(run)) return run;
|
|
259
|
+
if (target === null || piece.link === null) {
|
|
260
|
+
out.push(run.value);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
group ??= {
|
|
264
|
+
...target,
|
|
265
|
+
link: piece.link,
|
|
266
|
+
runs: []
|
|
267
|
+
};
|
|
268
|
+
group.runs.push(run.value);
|
|
269
|
+
}
|
|
270
|
+
flush();
|
|
271
|
+
return Result.ok(out.join(""));
|
|
272
|
+
};
|
|
273
|
+
/** The runs of a segment list, references written as complex REF fields. */
|
|
274
|
+
const segmentsRunsXml = (segments, context, instructionOf) => {
|
|
275
|
+
const out = [];
|
|
276
|
+
let plain = [];
|
|
277
|
+
const flush = () => {
|
|
278
|
+
if (plain.length === 0) return Result.ok(void 0);
|
|
279
|
+
const runs = piecesRunsXml(plain, context);
|
|
280
|
+
plain = [];
|
|
281
|
+
if (Result.isError(runs)) return runs;
|
|
282
|
+
out.push(runs.value);
|
|
283
|
+
return Result.ok(void 0);
|
|
284
|
+
};
|
|
285
|
+
for (const segment of segments) {
|
|
286
|
+
if (segment.kind === "piece") {
|
|
287
|
+
plain.push(segment.piece);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
const flushed = flush();
|
|
291
|
+
if (Result.isError(flushed)) return flushed;
|
|
292
|
+
const result = piecesRunsXml(segment.pieces, context);
|
|
293
|
+
if (Result.isError(result)) return result;
|
|
294
|
+
const instruction = instructionOf(segment) ?? panic("A resolved reference must carry its field instruction.");
|
|
295
|
+
out.push(complexFieldXml({
|
|
296
|
+
prefix: context.prefixes.w,
|
|
297
|
+
instruction,
|
|
298
|
+
resultRunsXml: result.value,
|
|
299
|
+
runPropertiesXml: runPropertiesXml({
|
|
300
|
+
prefix: context.prefixes.w,
|
|
301
|
+
signature: segment.pieces.at(0)?.signature ?? "",
|
|
302
|
+
escapeAttribute: escapeXmlAttribute
|
|
303
|
+
})
|
|
304
|
+
}));
|
|
305
|
+
}
|
|
306
|
+
const flushed = flush();
|
|
307
|
+
return Result.isError(flushed) ? flushed : Result.ok(out.join(""));
|
|
308
|
+
};
|
|
309
|
+
/** Runs of a placed paragraph, inside its bookmark when it is a reference target. */
|
|
310
|
+
const paragraphContentXml = ({ paragraph, bookmark, instructionOf }, context) => {
|
|
311
|
+
const runs = segmentsRunsXml(paragraph.segments, context, instructionOf);
|
|
312
|
+
if (Result.isError(runs) || bookmark === void 0) return runs;
|
|
313
|
+
const { w } = context.prefixes;
|
|
314
|
+
return Result.ok(`${bookmarkStartXml({
|
|
315
|
+
prefix: w,
|
|
316
|
+
...bookmark
|
|
317
|
+
})}${runs.value}${bookmarkEndXml({
|
|
318
|
+
prefix: w,
|
|
319
|
+
id: bookmark.id
|
|
320
|
+
})}`);
|
|
321
|
+
};
|
|
322
|
+
const NO_LIST_NUM_ID = 0;
|
|
323
|
+
/** A whole `w:p` for a placed source paragraph. */
|
|
324
|
+
const paragraphXml = (emit, context) => {
|
|
325
|
+
const { w } = context.prefixes;
|
|
326
|
+
const { styleId, numbering } = emit.paragraph;
|
|
327
|
+
const properties = [];
|
|
328
|
+
if (styleId !== null) properties.push(`<${w}:pStyle ${w}:val="${escapeXmlAttribute(styleId)}"/>`);
|
|
329
|
+
if (numbering.kind === "direct") properties.push(`<${w}:numPr><${w}:ilvl ${w}:val="${numbering.ilvl}"/><${w}:numId ${w}:val="${numbering.numId}"/></${w}:numPr>`);
|
|
330
|
+
else if (numbering.kind === "none" && emit.styleBindsList) properties.push(`<${w}:numPr><${w}:numId ${w}:val="${NO_LIST_NUM_ID}"/></${w}:numPr>`);
|
|
331
|
+
const runs = segmentsRunsXml(emit.paragraph.segments, context, emit.instructionOf);
|
|
332
|
+
if (Result.isError(runs)) return runs;
|
|
333
|
+
const xml = `<${w}:p>${properties.length === 0 ? "" : `<${w}:pPr>${properties.join("")}</${w}:pPr>`}${runs.value}</${w}:p>`;
|
|
334
|
+
if (emit.bookmark === void 0) return Result.ok(xml);
|
|
335
|
+
const wrapped = wrapParagraphContentInBookmark({
|
|
336
|
+
paragraphXml: xml,
|
|
337
|
+
prefixes: context.prefixes,
|
|
338
|
+
...emit.bookmark
|
|
339
|
+
});
|
|
340
|
+
return wrapped === null ? Result.err(new TemplatePlanError({
|
|
341
|
+
code: "xml-unreadable",
|
|
342
|
+
message: "A reference target could not be bookmarked.",
|
|
343
|
+
blockId: emit.paragraph.parts.at(0)?.block.block.id ?? ""
|
|
344
|
+
})) : Result.ok(wrapped);
|
|
345
|
+
};
|
|
346
|
+
const TABLE_LAYOUT_PROPERTIES = ["tblLayout", "tblLook"];
|
|
347
|
+
const ROW_PROPERTIES = [
|
|
348
|
+
"gridBefore",
|
|
349
|
+
"gridAfter",
|
|
350
|
+
"cantSplit",
|
|
351
|
+
"tblHeader"
|
|
352
|
+
];
|
|
353
|
+
const CELL_SPAN_PROPERTIES = [
|
|
354
|
+
"tcW",
|
|
355
|
+
"gridSpan",
|
|
356
|
+
"hMerge",
|
|
357
|
+
"vMerge"
|
|
358
|
+
];
|
|
359
|
+
const keptChildrenXml = (properties, names, prefix) => names.map((name) => {
|
|
360
|
+
const child = wChild(properties, name);
|
|
361
|
+
return child === null ? "" : wSubtreeXml(child, prefix);
|
|
362
|
+
}).join("");
|
|
363
|
+
/**
|
|
364
|
+
* A source table rebuilt: its grid, spans and merges, with every cell
|
|
365
|
+
* paragraph placed like a body paragraph. Without a template table style the
|
|
366
|
+
* source's borders are kept so the grid stays visible.
|
|
367
|
+
*/
|
|
368
|
+
const tableXml = ({ table, styleId, paragraphOf }, context) => {
|
|
369
|
+
const { w } = context.prefixes;
|
|
370
|
+
const blocksXml = (container) => {
|
|
371
|
+
const out = [];
|
|
372
|
+
for (const child of elementChildren(container)) {
|
|
373
|
+
const name = wName(child);
|
|
374
|
+
let result = Result.ok("");
|
|
375
|
+
if (name === "p") result = paragraphOf(child);
|
|
376
|
+
else if (name === "tbl") result = tableXml({
|
|
377
|
+
table: child,
|
|
378
|
+
styleId,
|
|
379
|
+
paragraphOf
|
|
380
|
+
}, context);
|
|
381
|
+
else if (name === "sdt") {
|
|
382
|
+
const content = wChild(child, "sdtContent");
|
|
383
|
+
result = content === null ? Result.ok("") : blocksXml(content);
|
|
384
|
+
} else if (name === "customXml") result = blocksXml(child);
|
|
385
|
+
if (Result.isError(result)) return result;
|
|
386
|
+
out.push(result.value);
|
|
387
|
+
}
|
|
388
|
+
return Result.ok(out.join(""));
|
|
389
|
+
};
|
|
390
|
+
const cellsXml = (container) => {
|
|
391
|
+
const out = [];
|
|
392
|
+
for (const child of elementChildren(container)) {
|
|
393
|
+
const name = wName(child);
|
|
394
|
+
if (name === "tc") {
|
|
395
|
+
const cellProperties = wChild(child, "tcPr");
|
|
396
|
+
const kept = `${keptChildrenXml(cellProperties, CELL_SPAN_PROPERTIES, w)}${styleId === null ? keptChildrenXml(cellProperties, ["tcBorders"], w) : ""}${keptChildrenXml(cellProperties, ["vAlign"], w)}`;
|
|
397
|
+
const blocks = blocksXml(child);
|
|
398
|
+
if (Result.isError(blocks)) return blocks;
|
|
399
|
+
const content = blocks.value.endsWith(`</${w}:p>`) ? blocks.value : `${blocks.value}<${w}:p/>`;
|
|
400
|
+
out.push(`<${w}:tc>${kept === "" ? "" : `<${w}:tcPr>${kept}</${w}:tcPr>`}${content}</${w}:tc>`);
|
|
401
|
+
} else if (name === "sdt") {
|
|
402
|
+
const content = wChild(child, "sdtContent");
|
|
403
|
+
const inner = content === null ? Result.ok("") : cellsXml(content);
|
|
404
|
+
if (Result.isError(inner)) return inner;
|
|
405
|
+
out.push(inner.value);
|
|
406
|
+
} else if (name === "customXml") {
|
|
407
|
+
const inner = cellsXml(child);
|
|
408
|
+
if (Result.isError(inner)) return inner;
|
|
409
|
+
out.push(inner.value);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return Result.ok(out.join(""));
|
|
413
|
+
};
|
|
414
|
+
const rowsXml = (container) => {
|
|
415
|
+
const out = [];
|
|
416
|
+
for (const child of elementChildren(container)) {
|
|
417
|
+
const name = wName(child);
|
|
418
|
+
if (name === "tr") {
|
|
419
|
+
const kept = keptChildrenXml(wChild(child, "trPr"), ROW_PROPERTIES, w);
|
|
420
|
+
const cells = cellsXml(child);
|
|
421
|
+
if (Result.isError(cells)) return cells;
|
|
422
|
+
out.push(`<${w}:tr>${kept === "" ? "" : `<${w}:trPr>${kept}</${w}:trPr>`}${cells.value}</${w}:tr>`);
|
|
423
|
+
} else if (name === "sdt") {
|
|
424
|
+
const content = wChild(child, "sdtContent");
|
|
425
|
+
const inner = content === null ? Result.ok("") : rowsXml(content);
|
|
426
|
+
if (Result.isError(inner)) return inner;
|
|
427
|
+
out.push(inner.value);
|
|
428
|
+
} else if (name === "customXml") {
|
|
429
|
+
const inner = rowsXml(child);
|
|
430
|
+
if (Result.isError(inner)) return inner;
|
|
431
|
+
out.push(inner.value);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return Result.ok(out.join(""));
|
|
435
|
+
};
|
|
436
|
+
const tableProperties = wChild(table, "tblPr");
|
|
437
|
+
const properties = `${styleId === null ? "" : `<${w}:tblStyle ${w}:val="${escapeXmlAttribute(styleId)}"/>`}${keptChildrenXml(tableProperties, ["tblW"], w)}${styleId === null ? keptChildrenXml(tableProperties, ["tblBorders"], w) : ""}${keptChildrenXml(tableProperties, TABLE_LAYOUT_PROPERTIES, w)}`;
|
|
438
|
+
const columns = wChildren(wChild(table, "tblGrid"), "gridCol").map((column) => wSubtreeXml(column, w)).join("");
|
|
439
|
+
const gridXml = columns === "" ? "" : `<${w}:tblGrid>${columns}</${w}:tblGrid>`;
|
|
440
|
+
const rows = rowsXml(table);
|
|
441
|
+
if (Result.isError(rows)) return rows;
|
|
442
|
+
return Result.ok(`<${w}:tbl><${w}:tblPr>${properties}</${w}:tblPr>${gridXml}${rows.value}</${w}:tbl>`);
|
|
443
|
+
};
|
|
444
|
+
/** A source note under its new id, its paragraphs in the template's note style. */
|
|
445
|
+
const noteXml = ({ kind, id, note, source, fields }, context) => {
|
|
446
|
+
const { w } = context.prefixes;
|
|
447
|
+
const textStyle = kind === "footnote" ? context.styles.footnoteText : context.styles.endnoteText;
|
|
448
|
+
const referenceStyle = kind === "footnote" ? context.styles.footnoteReference : context.styles.endnoteReference;
|
|
449
|
+
const origin = kind === "footnote" ? "footnotes" : "endnotes";
|
|
450
|
+
const pPr = textStyle === null ? "" : `<${w}:pPr><${w}:pStyle ${w}:val="${escapeXmlAttribute(textStyle)}"/></${w}:pPr>`;
|
|
451
|
+
const mark = `<${w}:r><${w}:rPr>${referenceStyle === null ? `<${w}:vertAlign ${w}:val="superscript"/>` : `<${w}:rStyle ${w}:val="${escapeXmlAttribute(referenceStyle)}"/>`}</${w}:rPr><${w}:${kind}Ref/></${w}:r>`;
|
|
452
|
+
const paragraphs = [];
|
|
453
|
+
for (const [index, read] of note.paragraphs.entries()) {
|
|
454
|
+
const runs = piecesRunsXml(paragraphPieces({
|
|
455
|
+
read,
|
|
456
|
+
context: source,
|
|
457
|
+
origin,
|
|
458
|
+
fields
|
|
459
|
+
}), context);
|
|
460
|
+
if (Result.isError(runs)) return runs;
|
|
461
|
+
paragraphs.push(`<${w}:p>${pPr}${index === 0 ? mark : ""}${runs.value}</${w}:p>`);
|
|
462
|
+
}
|
|
463
|
+
if (paragraphs.length === 0) paragraphs.push(`<${w}:p>${pPr}${mark}</${w}:p>`);
|
|
464
|
+
return Result.ok(`<${w}:${kind} ${w}:id="${id}">${paragraphs.join("")}</${w}:${kind}>`);
|
|
465
|
+
};
|
|
466
|
+
export { createRelationshipsEditor, linkAddress, linkAddressKey, noteXml, paragraphContentXml, paragraphXml, segmentsRunsXml, tableXml, templateCharacterStyles, wSubtreeXml };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Character emphasis as a reader sees it, and the part of it a run states over
|
|
3
|
+
* its paragraph's style. Only that part travels onto a template: fonts, sizes
|
|
4
|
+
* and colours are the template's to decide.
|
|
5
|
+
*/
|
|
6
|
+
import { document_d_exports } from "../../../types/document.js";
|
|
7
|
+
import { XmlElement } from "../../xmlParser.js";
|
|
8
|
+
/**
|
|
9
|
+
* In `CT_RPr` order. Bold and italic for complex scripts are properties of
|
|
10
|
+
* their own: a run may state one and not the other.
|
|
11
|
+
*/
|
|
12
|
+
declare const TOGGLES: readonly ["b", "bCs", "i", "iCs", "caps", "smallCaps", "strike", "dstrike", "vanish"];
|
|
13
|
+
type Toggle = (typeof TOGGLES)[number];
|
|
14
|
+
export type Emphasis = Record<Toggle, boolean> & {
|
|
15
|
+
u: string | null;
|
|
16
|
+
vertAlign: "superscript" | "subscript" | null;
|
|
17
|
+
highlight: string | null;
|
|
18
|
+
};
|
|
19
|
+
/** What a run states: a toggle on or off, a value, or `null` for "cleared". */
|
|
20
|
+
export type EmphasisOverride = Partial<Record<Toggle, boolean>> & {
|
|
21
|
+
u?: string | null;
|
|
22
|
+
vertAlign?: "superscript" | "subscript" | null;
|
|
23
|
+
highlight?: string | null;
|
|
24
|
+
};
|
|
25
|
+
export declare const NO_EMPHASIS: Emphasis;
|
|
26
|
+
type RunFormatting = document_d_exports.Style["rPr"];
|
|
27
|
+
/** The emphasis the document defaults give every run. */
|
|
28
|
+
export declare const defaultsBaseline: (rPr: RunFormatting) => Emphasis;
|
|
29
|
+
/**
|
|
30
|
+
* The emphasis every run of a paragraph starts from: the document defaults
|
|
31
|
+
* under the paragraph's style.
|
|
32
|
+
*/
|
|
33
|
+
export declare const paragraphBaseline: (style: document_d_exports.Style | undefined, defaults: Emphasis) => Emphasis;
|
|
34
|
+
/** `base` under a character style. */
|
|
35
|
+
export declare const withCharacterStyle: (base: Emphasis, style: document_d_exports.Style | undefined) => Emphasis;
|
|
36
|
+
/** What a `w:rPr` states directly. */
|
|
37
|
+
export declare const readDirectEmphasis: (rPr: XmlElement | null | undefined) => EmphasisOverride;
|
|
38
|
+
export declare const withOverride: (base: Emphasis, override: EmphasisOverride) => Emphasis;
|
|
39
|
+
/** The part of `effective` that differs from `baseline`, stated explicitly. */
|
|
40
|
+
export declare const emphasisDeviation: (effective: Emphasis, baseline: Emphasis) => EmphasisOverride;
|
|
41
|
+
/** One canonical string per override; the empty string states nothing. */
|
|
42
|
+
export declare const emphasisSignature: (override: EmphasisOverride) => string;
|
|
43
|
+
/** The highlight a signature states, or null when it states none. */
|
|
44
|
+
export declare const signatureHighlight: (signature: string) => string | null;
|
|
45
|
+
/** A signature without its highlight entry. */
|
|
46
|
+
export declare const signatureWithoutHighlight: (signature: string) => string;
|
|
47
|
+
/** Whether a signature states anything besides a highlight. */
|
|
48
|
+
export declare const signatureHasEmphasis: (signature: string) => boolean;
|
|
49
|
+
export declare const withSignatureHighlight: (signature: string, color: string) => string;
|
|
50
|
+
export type RunPropertiesXmlOptions = {
|
|
51
|
+
prefix: string;
|
|
52
|
+
signature: string;
|
|
53
|
+
/** A character style of the template, written first. */
|
|
54
|
+
rStyle?: string | null;
|
|
55
|
+
escapeAttribute: (value: string) => string;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* The `w:rPr` for a signature, children in `CT_RPr` order; the empty string
|
|
59
|
+
* when there is nothing to state.
|
|
60
|
+
*/
|
|
61
|
+
export declare const runPropertiesXml: ({ prefix, signature, rStyle, escapeAttribute }: RunPropertiesXmlOptions) => string;
|
|
62
|
+
export {};
|