@stll/folio-core 0.74.0 → 0.76.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/dist/ai-edits/clean-text.d.ts +4 -1
- package/dist/ai-edits/clean-text.js +21 -7
- package/dist/ai-edits/headless.d.ts +7 -3
- package/dist/ai-edits/headless.js +36 -21
- package/dist/ai-edits/note-references.d.ts +1 -1
- package/dist/ai-edits/note-references.js +1 -1
- package/dist/ai-edits/pending-suggestions.d.ts +9 -7
- package/dist/ai-edits/pending-suggestions.js +135 -90
- package/dist/ai-edits/pendingJoin.d.ts +5 -1
- package/dist/ai-edits/pendingJoin.js +6 -2
- package/dist/ai-edits/read.js +9 -3
- package/dist/ai-edits/retired-comment-receipts.d.ts +2 -2
- package/dist/ai-edits/retired-comment-receipts.js +3 -18
- package/dist/ai-edits/tracked-batch-fidelity.d.ts +6 -10
- package/dist/ai-edits/tracked-batch-fidelity.js +3 -182
- package/dist/ai-edits/types.d.ts +9 -4
- package/dist/canonical/batchCommentReferences.js +2 -1
- package/dist/canonical/canonicalBatchReview.d.ts +4 -1
- package/dist/canonical/canonicalBatchReview.js +37 -22
- package/dist/canonical/canonicalComments.d.ts +6 -2
- package/dist/canonical/canonicalComments.js +16 -6
- package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
- package/dist/canonical/canonicalCompilerRefusal.js +20 -14
- package/dist/canonical/canonicalPublicOperations.js +231 -79
- package/dist/canonical/canonicalRefusalGrounds.d.ts +4 -0
- package/dist/canonical/canonicalRefusalGrounds.js +56 -0
- package/dist/canonical/canonicalSession.d.ts +12 -6
- package/dist/canonical/canonicalSession.js +119 -122
- package/dist/canonical/canonicalTrackedBatchFidelity.js +3 -3
- package/dist/compare/inline-atoms.d.ts +35 -41
- package/dist/compare/inline-atoms.js +2 -465
- package/dist/compare/section-boundary-properties.d.ts +3 -30
- package/dist/compare/section-boundary-properties.js +4 -72
- package/dist/controller/canonicalClipboard.d.ts +1 -1
- package/dist/controller/canonicalClipboard.js +110 -55
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +5 -5
- package/dist/controller/canonicalContentControlValue.js +7 -7
- package/dist/controller/canonicalInput.d.ts +4 -2
- package/dist/controller/canonicalInput.js +33 -16
- package/dist/controller/canonicalReview.d.ts +21 -0
- package/dist/controller/canonicalReview.js +44 -9
- package/dist/controller/canonicalStoryEditor.d.ts +2 -3
- package/dist/controller/canonicalStoryEditor.js +43 -25
- package/dist/controller/canonicalStructure.d.ts +19 -3
- package/dist/controller/canonicalStructure.js +182 -58
- package/dist/controller/deferredDisplayListPainter.d.ts +8 -0
- package/dist/controller/deferredDisplayListPainter.js +34 -0
- package/dist/controller/folioEditor.js +4 -2
- package/dist/controller/fontReadiness.js +50 -23
- package/dist/controller/headerFooterEditorManager.js +3 -17
- package/dist/controller/hiddenEditorApi.d.ts +24 -3
- package/dist/controller/hiddenEditorApi.js +2 -0
- package/dist/controller/hiddenEditorManager.js +135 -207
- package/dist/controller/layoutPipeline.d.ts +4 -86
- package/dist/controller/layoutPipeline.js +8 -727
- package/dist/controller/layoutPipelineExecution.d.ts +94 -0
- package/dist/controller/layoutPipelineExecution.js +730 -0
- package/dist/controller/noteEditorManager.js +3 -16
- package/dist/docx/blockContentParser.d.ts +1 -3
- package/dist/docx/blockContentParser.js +3 -10
- package/dist/docx/bulletMarkers.d.ts +8 -0
- package/dist/docx/bulletMarkers.js +9 -1
- package/dist/docx/canonicalSave.d.ts +4 -3
- package/dist/docx/canonicalSave.js +4 -3
- package/dist/docx/canonicalSessionInput.js +25 -11
- package/dist/docx/ensureParaIds.d.ts +31 -0
- package/dist/docx/ensureParaIds.js +57 -32
- package/dist/docx/ensureUniqueControlIds.d.ts +13 -0
- package/dist/docx/ensureUniqueControlIds.js +47 -29
- package/dist/docx/ensureUniqueRevisionIds.d.ts +13 -0
- package/dist/docx/ensureUniqueRevisionIds.js +52 -29
- package/dist/docx/listMarkerComputation.d.ts +24 -17
- package/dist/docx/listMarkerComputation.js +31 -60
- package/dist/docx/listModelNormalization.js +8 -15
- package/dist/docx/rezip.d.ts +16 -3
- package/dist/docx/rezip.js +35 -9
- package/dist/docx/selectiveSave.js +13 -5
- package/dist/docx/server/templatePlan/apply.js +96 -7
- package/dist/docx/server/templatePlan/blocks.d.ts +70 -3
- package/dist/docx/server/templatePlan/blocks.js +272 -10
- package/dist/docx/server/templatePlan/builders.d.ts +52 -2
- package/dist/docx/server/templatePlan/builders.js +224 -5
- package/dist/docx/server/templatePlan/effects.d.ts +27 -0
- package/dist/docx/server/templatePlan/effects.js +188 -0
- package/dist/docx/server/templatePlan/emit.d.ts +4 -1
- package/dist/docx/server/templatePlan/emit.js +46 -2
- package/dist/docx/server/templatePlan/inspect.js +39 -52
- package/dist/docx/server/templatePlan/labels.d.ts +7 -2
- package/dist/docx/server/templatePlan/labels.js +120 -23
- package/dist/docx/server/templatePlan/plan.d.ts +24 -3
- package/dist/docx/server/templatePlan/plan.js +54 -15
- package/dist/docx/server/templatePlan/planShape.js +76 -22
- package/dist/docx/server/templatePlan/revisions.d.ts +46 -0
- package/dist/docx/server/templatePlan/revisions.js +407 -0
- package/dist/docx/server/templatePlan/story.d.ts +23 -1
- package/dist/docx/server/templatePlan/story.js +60 -2
- package/dist/docx/server/templatePlan/types.d.ts +354 -16
- package/dist/docx/server/templatePlan/verify.js +164 -14
- package/dist/docx/server/templatePlan/xml.d.ts +3 -0
- package/dist/docx/server/templatePlan/xml.js +4 -1
- package/dist/i18n/messages/ar.gen.js +1 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
- package/dist/i18n/messages/catalogs.gen.js +17 -0
- package/dist/i18n/messages/cs.gen.js +1 -0
- package/dist/i18n/messages/de.gen.js +1 -0
- package/dist/i18n/messages/en.gen.js +1 -0
- package/dist/i18n/messages/es.gen.js +1 -0
- package/dist/i18n/messages/et.gen.js +1 -0
- package/dist/i18n/messages/fr.gen.js +1 -0
- package/dist/i18n/messages/he.gen.js +1 -0
- package/dist/i18n/messages/hi.gen.js +1 -0
- package/dist/i18n/messages/hu.gen.js +1 -0
- package/dist/i18n/messages/lt.gen.js +1 -0
- package/dist/i18n/messages/lv.gen.js +1 -0
- package/dist/i18n/messages/messages.gen.d.ts +1 -0
- package/dist/i18n/messages/pl.gen.js +1 -0
- package/dist/i18n/messages/pt-BR.gen.js +1 -0
- package/dist/i18n/messages/sk.gen.js +1 -0
- package/dist/i18n/messages/tr.gen.js +1 -0
- package/dist/i18n/messages/zh-CN.gen.js +1 -0
- package/dist/internal/revisionResolutionStep.d.ts +2 -31
- package/dist/internal/revisionResolutionStep.js +2 -171
- package/dist/layout-bridge/convert/toFlowBlocks.js +0 -12
- package/dist/layout-bridge/convert/topLevelConversion.js +1 -10
- package/dist/prosemirror/commands/comments.d.ts +6 -234
- package/dist/prosemirror/commands/comments.js +5 -2464
- package/dist/prosemirror/commands/index.d.ts +4 -2
- package/dist/prosemirror/commands/index.js +4 -2
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -11
- package/dist/prosemirror/commands/tableCellMergeResolution.js +3 -154
- package/dist/prosemirror/extensions/features/ImagePasteExtension.js +1 -1
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +6 -8
- package/dist/prosemirror/hyperlinkRemoval.d.ts +11 -8
- package/dist/prosemirror/hyperlinkRemoval.js +24 -15
- package/dist/prosemirror/listMarker.d.ts +1 -6
- package/dist/prosemirror/listMarker.js +4 -56
- package/dist/prosemirror/paraIds.d.ts +1 -14
- package/dist/prosemirror/paraIds.js +1 -14
- package/dist/prosemirror/paragraphMarkJoin.d.ts +0 -16
- package/dist/prosemirror/paragraphMarkJoin.js +3 -46
- package/dist/prosemirror/projectionReview.d.ts +49 -0
- package/dist/prosemirror/projectionReview.js +292 -0
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -13
- package/dist/prosemirror/rebaseParagraphRunFormatting.js +1 -16
- package/dist/prosemirror/replacedAnnotations.d.ts +2 -5
- package/dist/prosemirror/replacedAnnotations.js +1 -10
- package/dist/prosemirror/revisionCarriers.d.ts +9 -1
- package/dist/prosemirror/revisionCarriers.js +15 -1
- package/dist/prosemirror/revisionRangeQueries.d.ts +32 -0
- package/dist/prosemirror/revisionRangeQueries.js +76 -0
- package/dist/prosemirror/runFormattingMarkNames.d.ts +1 -1
- package/dist/prosemirror/runFormattingMarkNames.js +1 -1
- package/dist/prosemirror/suggestionQueries.d.ts +114 -0
- package/dist/prosemirror/suggestionQueries.js +320 -0
- package/dist/prosemirror/tableGridMutation.d.ts +1 -16
- package/dist/prosemirror/tableGridMutation.js +1 -78
- package/dist/prosemirror/tableRowRevisionOwnership.d.ts +18 -0
- package/dist/prosemirror/tableRowRevisionOwnership.js +7 -0
- package/dist/prosemirror/utils/extractTrackedChanges.js +14 -4
- package/dist/server.d.ts +2 -2
- package/dist/types/canonicalCapabilities.d.ts +40 -69
- package/dist/types/canonicalCapabilities.js +51 -65
- package/dist/types/canonicalComments.d.ts +2 -2
- package/dist/types/canonicalSections.d.ts +2 -2
- package/dist/utils/clipboard.d.ts +2 -28
- package/dist/utils/clipboard.js +1 -96
- package/dist/utils/clipboardFiles.d.ts +27 -0
- package/dist/utils/clipboardFiles.js +98 -0
- package/dist/utils/rulerControl.d.ts +1 -0
- package/dist/utils/rulerControl.js +2 -1
- package/package.json +2 -2
- package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
- package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { XmlSplice } from "../../selectiveXmlPatch.js";
|
|
2
2
|
import { XmlElement } from "../../xmlParser.js";
|
|
3
|
+
import { TemplatePlanSectionPage } from "./types.js";
|
|
3
4
|
import { PartPrefixes, RawPart } from "./xml.js";
|
|
4
5
|
/**
|
|
5
6
|
* A hidden bookmark name in the form a cross-reference target takes: `_Ref`
|
|
@@ -39,9 +40,14 @@ type ComplexFieldOptions = {
|
|
|
39
40
|
};
|
|
40
41
|
/** A complex field: begin, instruction, separate, the cached result, end. */
|
|
41
42
|
export declare const complexFieldXml: ({ prefix, instruction, resultRunsXml, runPropertiesXml }: ComplexFieldOptions) => string;
|
|
43
|
+
/** The letter case a REF instruction asks for its result in, or null. */
|
|
44
|
+
export declare const refCaseFormat: (instruction: string) => "lower" | "upper" | "firstcap" | null;
|
|
45
|
+
/** `text` in the letter case a `\*` switch names, as a field result has it. */
|
|
46
|
+
export declare const applyRefCaseFormat: (text: string, format: ReturnType<typeof refCaseFormat>) => string;
|
|
42
47
|
/**
|
|
43
|
-
* The field code of a REF to `bookmark` with `switches` (`\n \t \h
|
|
44
|
-
* when the switches hold anything but
|
|
48
|
+
* The field code of a REF to `bookmark` with `switches` (`\n \t \h`,
|
|
49
|
+
* `\n \* lower \h`). Null when the switches hold anything but
|
|
50
|
+
* single-letter switches and one letter-case format.
|
|
45
51
|
*/
|
|
46
52
|
export declare const refFieldInstruction: (bookmark: string, switches: string) => string | null;
|
|
47
53
|
/** The bookmark a REF, PAGEREF or NOTEREF instruction names. */
|
|
@@ -51,6 +57,50 @@ export declare const fieldBookmarkOf: (instruction: string) => string | null;
|
|
|
51
57
|
* place in the schema's child order. Null when the part is not a settings part.
|
|
52
58
|
*/
|
|
53
59
|
export declare const setUpdateFieldsOnOpen: (settingsXml: string, enabled: boolean) => string | null;
|
|
60
|
+
/** Whether a settings part keeps the spacing of a justified line that ends
|
|
61
|
+
* in a manual line break (`w:compat/w:doNotExpandShiftReturn`). */
|
|
62
|
+
export declare const keepsShiftReturnSpacing: (settingsXml: string) => boolean;
|
|
63
|
+
/**
|
|
64
|
+
* `settingsXml` with `w:doNotExpandShiftReturn` switched on in `w:compat`,
|
|
65
|
+
* each at its place in the schema's child order; every other byte of the
|
|
66
|
+
* part stays. Null when the part is not a settings part or gives the setting
|
|
67
|
+
* no certain place.
|
|
68
|
+
*/
|
|
69
|
+
export declare const setKeepShiftReturnSpacing: (settingsXml: string) => string | null;
|
|
70
|
+
export type SectionRewrite = {
|
|
71
|
+
/**
|
|
72
|
+
* Whether the section begins the document. Every later one loses the
|
|
73
|
+
* first-page header and a page-number start: they belong to the
|
|
74
|
+
* document's first page, not to each part of it.
|
|
75
|
+
*/
|
|
76
|
+
first: boolean;
|
|
77
|
+
/** The page to put in place of the template's, or undefined. */
|
|
78
|
+
page: TemplatePlanSectionPage | undefined;
|
|
79
|
+
/** How the section begins; null keeps what the template states. */
|
|
80
|
+
start: string | null;
|
|
81
|
+
/**
|
|
82
|
+
* Header and footer references the section takes over from the sections
|
|
83
|
+
* in front of it and does not state itself, as markup. Left out, the
|
|
84
|
+
* section is written with its own alone.
|
|
85
|
+
*/
|
|
86
|
+
inherited?: readonly string[];
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* The header and footer references a body's last section takes over from
|
|
90
|
+
* the sections in front of it: a section that states no header of a kind
|
|
91
|
+
* shows the one of the section before. An output built from the last
|
|
92
|
+
* section alone would lose them, so they are stated on it. Each is the
|
|
93
|
+
* reference of the nearest earlier section that states that kind, as it is
|
|
94
|
+
* written in `xml`; kinds the last section states itself are left out.
|
|
95
|
+
*/
|
|
96
|
+
export declare const inheritedReferencesXml: (xml: string, body: XmlElement, last: XmlElement) => string[];
|
|
97
|
+
/**
|
|
98
|
+
* A `w:sectPr` built from the template's: the same children in the same
|
|
99
|
+
* order, with the page, the start and the first-section properties changed
|
|
100
|
+
* as `rewrite` says. `xml` is the part `sectPr` was read from. Null when a
|
|
101
|
+
* child cannot be read back.
|
|
102
|
+
*/
|
|
103
|
+
export declare const sectionPropertiesXml: (xml: string, sectPr: XmlElement, w: string, { first, page, start, inherited }: SectionRewrite) => string | null;
|
|
54
104
|
export type FrozenFieldCount = {
|
|
55
105
|
kind: string;
|
|
56
106
|
count: number;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { sliceText } from "../../../utils/sliceText.js";
|
|
1
2
|
import { spliceXml } from "../../selectiveXmlPatch.js";
|
|
2
3
|
import { updateSettingsOnOffChild } from "../../settingsHeaderFooterUpdate.js";
|
|
3
4
|
import { sha256Hex } from "./package.js";
|
|
4
|
-
import { elementChildren, escapeXmlAttribute, escapeXmlText, innerRangeOf, isW, rangeOf, readRawPart, wAttr, wChild, wName, walkElements } from "./xml.js";
|
|
5
|
+
import { elementChildren, escapeXmlAttribute, escapeXmlText, innerRangeOf, isW, partPrefixes, rangeOf, readRawPart, wAttr, wChild, wName, walkElements } from "./xml.js";
|
|
6
|
+
import { SETTINGS_CHILDREN } from "@stll/docx-core/schema";
|
|
5
7
|
// src/docx/server/templatePlan/builders.ts
|
|
6
8
|
/**
|
|
7
9
|
* Raw OOXML builders a template plan is applied with: a hidden bookmark around
|
|
@@ -88,13 +90,47 @@ const complexFieldXml = ({ prefix, instruction, resultRunsXml, runPropertiesXml
|
|
|
88
90
|
};
|
|
89
91
|
/** The REF switches that take no argument. */
|
|
90
92
|
const REF_SWITCH = /^\\[fhnprtw]$/u;
|
|
93
|
+
/** The general format switch and the letter cases it may name. */
|
|
94
|
+
const FORMAT_SWITCH = "\\*";
|
|
95
|
+
const CASE_FORMAT = /^(?:lower|upper|firstcap)$/iu;
|
|
96
|
+
/** The letter case a REF instruction asks for its result in, or null. */
|
|
97
|
+
const refCaseFormat = (instruction) => {
|
|
98
|
+
const name = /\\\*\s*(?<name>lower|upper|firstcap)\b/iu.exec(instruction)?.groups?.["name"]?.toLowerCase();
|
|
99
|
+
return name === "lower" || name === "upper" || name === "firstcap" ? name : null;
|
|
100
|
+
};
|
|
101
|
+
/** `text` in the letter case a `\*` switch names, as a field result has it. */
|
|
102
|
+
const applyRefCaseFormat = (text, format) => {
|
|
103
|
+
switch (format) {
|
|
104
|
+
case "lower": return text.toLowerCase();
|
|
105
|
+
case "upper": return text.toUpperCase();
|
|
106
|
+
case "firstcap": {
|
|
107
|
+
const initial = sliceText({
|
|
108
|
+
text,
|
|
109
|
+
units: "graphemes",
|
|
110
|
+
end: 1
|
|
111
|
+
});
|
|
112
|
+
return initial.toUpperCase() + text.slice(initial.length);
|
|
113
|
+
}
|
|
114
|
+
case null: return text;
|
|
115
|
+
default: return format;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
91
118
|
/**
|
|
92
|
-
* The field code of a REF to `bookmark` with `switches` (`\n \t \h
|
|
93
|
-
* when the switches hold anything but
|
|
119
|
+
* The field code of a REF to `bookmark` with `switches` (`\n \t \h`,
|
|
120
|
+
* `\n \* lower \h`). Null when the switches hold anything but
|
|
121
|
+
* single-letter switches and one letter-case format.
|
|
94
122
|
*/
|
|
95
123
|
const refFieldInstruction = (bookmark, switches) => {
|
|
96
124
|
const parts = switches.trim().split(/\s+/u).filter(Boolean);
|
|
97
|
-
|
|
125
|
+
let formats = 0;
|
|
126
|
+
for (const [index, part] of parts.entries()) {
|
|
127
|
+
const afterFormat = parts[index - 1] === FORMAT_SWITCH;
|
|
128
|
+
if (part === FORMAT_SWITCH) {
|
|
129
|
+
formats += 1;
|
|
130
|
+
if (formats > 1 || !CASE_FORMAT.test(parts[index + 1] ?? "")) return null;
|
|
131
|
+
} else if (!afterFormat && !REF_SWITCH.test(part)) return null;
|
|
132
|
+
}
|
|
133
|
+
return ` REF ${bookmark} ${parts.join(" ")}${parts.length === 0 ? "" : " "}`;
|
|
98
134
|
};
|
|
99
135
|
/** The bookmark a REF, PAGEREF or NOTEREF instruction names. */
|
|
100
136
|
const fieldBookmarkOf = (instruction) => /^\s*(?:REF|PAGEREF|NOTEREF)\s+"?(?<name>[^\s"\\]+)/iu.exec(instruction)?.groups?.["name"] ?? null;
|
|
@@ -103,6 +139,189 @@ const fieldBookmarkOf = (instruction) => /^\s*(?:REF|PAGEREF|NOTEREF)\s+"?(?<nam
|
|
|
103
139
|
* place in the schema's child order. Null when the part is not a settings part.
|
|
104
140
|
*/
|
|
105
141
|
const setUpdateFieldsOnOpen = (settingsXml, enabled) => updateSettingsOnOffChild(settingsXml, "updateFields", enabled ? true : void 0);
|
|
142
|
+
const SHIFT_RETURN = "doNotExpandShiftReturn";
|
|
143
|
+
/** The children of `w:compat` the schema orders in front of the setting. */
|
|
144
|
+
const COMPAT_BEFORE_SHIFT_RETURN = /* @__PURE__ */ new Set([
|
|
145
|
+
"useSingleBorderforContiguousCells",
|
|
146
|
+
"wpJustification",
|
|
147
|
+
"noTabHangInd",
|
|
148
|
+
"noLeading",
|
|
149
|
+
"spaceForUL",
|
|
150
|
+
"noColumnBalance",
|
|
151
|
+
"balanceSingleByteDoubleByteWidth",
|
|
152
|
+
"noExtraLineSpacing",
|
|
153
|
+
"doNotLeaveBackslashAlone",
|
|
154
|
+
"ulTrailSpace"
|
|
155
|
+
]);
|
|
156
|
+
const SWITCHED_OFF = /* @__PURE__ */ new Set([
|
|
157
|
+
"0",
|
|
158
|
+
"false",
|
|
159
|
+
"off"
|
|
160
|
+
]);
|
|
161
|
+
const SETTINGS_CHILD_ORDINALS = new Map(SETTINGS_CHILDREN.map((name, index) => [name, index]));
|
|
162
|
+
const settingsRoot = (settingsXml) => {
|
|
163
|
+
const part = readRawPart("word/settings.xml", settingsXml);
|
|
164
|
+
return part !== null && isW(part.root, "settings") ? part : null;
|
|
165
|
+
};
|
|
166
|
+
/** Whether a settings part keeps the spacing of a justified line that ends
|
|
167
|
+
* in a manual line break (`w:compat/w:doNotExpandShiftReturn`). */
|
|
168
|
+
const keepsShiftReturnSpacing = (settingsXml) => {
|
|
169
|
+
const setting = wChild(wChild(settingsRoot(settingsXml)?.root, "compat"), SHIFT_RETURN);
|
|
170
|
+
return setting !== null && !SWITCHED_OFF.has(wAttr(setting, "val") ?? "1");
|
|
171
|
+
};
|
|
172
|
+
/** An element of the part's WordprocessingML namespace, bound by the
|
|
173
|
+
* root's prefix or, under a default namespace, by one of its own. */
|
|
174
|
+
const settingsElement = (root, localName, inner) => {
|
|
175
|
+
const prefixes = partPrefixes(root);
|
|
176
|
+
const name = prefixes === null ? `folioW:${localName}` : `${prefixes.w}:${localName}`;
|
|
177
|
+
const binding = prefixes === null ? ` xmlns:folioW="${escapeXmlAttribute(root.namespaceUri ?? "")}"` : "";
|
|
178
|
+
return inner === null ? `<${name}${binding}/>` : `<${name}${binding}>${inner}</${name}>`;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* `settingsXml` with `w:doNotExpandShiftReturn` switched on in `w:compat`,
|
|
182
|
+
* each at its place in the schema's child order; every other byte of the
|
|
183
|
+
* part stays. Null when the part is not a settings part or gives the setting
|
|
184
|
+
* no certain place.
|
|
185
|
+
*/
|
|
186
|
+
const setKeepShiftReturnSpacing = (settingsXml) => {
|
|
187
|
+
const part = settingsRoot(settingsXml);
|
|
188
|
+
if (part === null) return null;
|
|
189
|
+
if (keepsShiftReturnSpacing(settingsXml)) return settingsXml;
|
|
190
|
+
const { root } = part;
|
|
191
|
+
const setting = settingsElement(root, SHIFT_RETURN, null);
|
|
192
|
+
const compat = wChild(root, "compat");
|
|
193
|
+
if (compat === null) {
|
|
194
|
+
const compatOrder = SETTINGS_CHILD_ORDINALS.get("compat") ?? 0;
|
|
195
|
+
const wrapper = settingsElement(root, "compat", setting);
|
|
196
|
+
const inner = innerRangeOf(settingsXml, root);
|
|
197
|
+
if (inner === null) {
|
|
198
|
+
const range = rangeOf(root);
|
|
199
|
+
return range === null || root.name === void 0 ? null : spliceXml(settingsXml, [{
|
|
200
|
+
start: range.end - 2,
|
|
201
|
+
end: range.end,
|
|
202
|
+
newXml: `>${wrapper}</${root.name}>`
|
|
203
|
+
}]);
|
|
204
|
+
}
|
|
205
|
+
const following = elementChildren(root).find((child) => {
|
|
206
|
+
const name = wName(child);
|
|
207
|
+
return name === null || (SETTINGS_CHILD_ORDINALS.get(name) ?? -1) > compatOrder;
|
|
208
|
+
});
|
|
209
|
+
const at = following === void 0 ? inner.end : rangeOf(following)?.start;
|
|
210
|
+
return at === void 0 ? null : spliceXml(settingsXml, [{
|
|
211
|
+
start: at,
|
|
212
|
+
end: at,
|
|
213
|
+
newXml: wrapper
|
|
214
|
+
}]);
|
|
215
|
+
}
|
|
216
|
+
const range = rangeOf(compat);
|
|
217
|
+
const inner = innerRangeOf(settingsXml, compat);
|
|
218
|
+
if (range === null) return null;
|
|
219
|
+
if (inner === null) return spliceXml(settingsXml, [{
|
|
220
|
+
start: range.start,
|
|
221
|
+
end: range.end,
|
|
222
|
+
newXml: settingsElement(root, "compat", setting)
|
|
223
|
+
}]);
|
|
224
|
+
const stated = wChild(compat, SHIFT_RETURN);
|
|
225
|
+
const statedRange = stated === null ? null : rangeOf(stated);
|
|
226
|
+
if (statedRange !== null) return spliceXml(settingsXml, [{
|
|
227
|
+
...statedRange,
|
|
228
|
+
newXml: setting
|
|
229
|
+
}]);
|
|
230
|
+
const following = elementChildren(compat).find((child) => {
|
|
231
|
+
const name = wName(child);
|
|
232
|
+
return name === null || !COMPAT_BEFORE_SHIFT_RETURN.has(name);
|
|
233
|
+
});
|
|
234
|
+
const at = following === void 0 ? inner.end : rangeOf(following)?.start;
|
|
235
|
+
return at === void 0 ? null : spliceXml(settingsXml, [{
|
|
236
|
+
start: at,
|
|
237
|
+
end: at,
|
|
238
|
+
newXml: setting
|
|
239
|
+
}]);
|
|
240
|
+
};
|
|
241
|
+
/** The children of `w:sectPr` the schema orders in front of `w:type`. */
|
|
242
|
+
const SECTION_BEFORE_TYPE = /* @__PURE__ */ new Set([
|
|
243
|
+
"headerReference",
|
|
244
|
+
"footerReference",
|
|
245
|
+
"footnotePr",
|
|
246
|
+
"endnotePr"
|
|
247
|
+
]);
|
|
248
|
+
const PAGE_NUMBER_KEPT = [
|
|
249
|
+
"fmt",
|
|
250
|
+
"chapStyle",
|
|
251
|
+
"chapSep"
|
|
252
|
+
];
|
|
253
|
+
const MARGINS_KEPT = [
|
|
254
|
+
"header",
|
|
255
|
+
"footer",
|
|
256
|
+
"gutter"
|
|
257
|
+
];
|
|
258
|
+
/**
|
|
259
|
+
* The header and footer references a body's last section takes over from
|
|
260
|
+
* the sections in front of it: a section that states no header of a kind
|
|
261
|
+
* shows the one of the section before. An output built from the last
|
|
262
|
+
* section alone would lose them, so they are stated on it. Each is the
|
|
263
|
+
* reference of the nearest earlier section that states that kind, as it is
|
|
264
|
+
* written in `xml`; kinds the last section states itself are left out.
|
|
265
|
+
*/
|
|
266
|
+
const inheritedReferencesXml = (xml, body, last) => {
|
|
267
|
+
const keyOf = (reference) => {
|
|
268
|
+
const name = wName(reference);
|
|
269
|
+
return name === "headerReference" || name === "footerReference" ? `${name}:${wAttr(reference, "type") ?? "default"}` : null;
|
|
270
|
+
};
|
|
271
|
+
const referencesOf = (sectPr) => elementChildren(sectPr).flatMap((child) => {
|
|
272
|
+
const key = keyOf(child);
|
|
273
|
+
return key === null ? [] : [[key, child]];
|
|
274
|
+
});
|
|
275
|
+
const inEffect = /* @__PURE__ */ new Map();
|
|
276
|
+
for (const block of elementChildren(body)) {
|
|
277
|
+
const sectPr = wName(block) === "p" ? wChild(wChild(block, "pPr"), "sectPr") : null;
|
|
278
|
+
for (const [key, reference] of referencesOf(sectPr)) inEffect.set(key, reference);
|
|
279
|
+
}
|
|
280
|
+
const own = new Set(referencesOf(last).map(([key]) => key));
|
|
281
|
+
return [...inEffect].flatMap(([key, reference]) => {
|
|
282
|
+
const range = own.has(key) ? null : rangeOf(reference);
|
|
283
|
+
return range === null ? [] : [xml.slice(range.start, range.end)];
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* A `w:sectPr` built from the template's: the same children in the same
|
|
288
|
+
* order, with the page, the start and the first-section properties changed
|
|
289
|
+
* as `rewrite` says. `xml` is the part `sectPr` was read from. Null when a
|
|
290
|
+
* child cannot be read back.
|
|
291
|
+
*/
|
|
292
|
+
const sectionPropertiesXml = (xml, sectPr, w, { first, page, start, inherited = [] }) => {
|
|
293
|
+
const attributes = (element, names) => names.map((name) => [name, wAttr(element, name)]).filter(([, value]) => value !== null).map(([name, value]) => ` ${w}:${name}="${escapeXmlAttribute(value ?? "")}"`).join("");
|
|
294
|
+
const type = start === null ? "" : `<${w}:type ${w}:val="${start}"/>`;
|
|
295
|
+
const out = [...inherited];
|
|
296
|
+
let typeWritten = type === "";
|
|
297
|
+
for (const child of elementChildren(sectPr)) {
|
|
298
|
+
const name = wName(child);
|
|
299
|
+
if (!typeWritten && (name === null || !SECTION_BEFORE_TYPE.has(name))) {
|
|
300
|
+
out.push(type);
|
|
301
|
+
typeWritten = true;
|
|
302
|
+
}
|
|
303
|
+
if (name === "sectPrChange" || name === "type" && start !== null || name === "titlePg" && !first) continue;
|
|
304
|
+
if (name === "pgSz" && page !== void 0) {
|
|
305
|
+
out.push(`<${w}:pgSz ${w}:w="${page.width}" ${w}:h="${page.height}"${page.orientation === "landscape" ? ` ${w}:orient="landscape"` : ""}/>`);
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (name === "pgMar" && page?.margins !== void 0) {
|
|
309
|
+
const { top, right, bottom, left } = page.margins;
|
|
310
|
+
out.push(`<${w}:pgMar ${w}:top="${top}" ${w}:right="${right}" ${w}:bottom="${bottom}" ${w}:left="${left}"${attributes(child, MARGINS_KEPT)}/>`);
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (name === "pgNumType" && !first) {
|
|
314
|
+
const kept = attributes(child, PAGE_NUMBER_KEPT);
|
|
315
|
+
if (kept !== "") out.push(`<${w}:pgNumType${kept}/>`);
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
const range = rangeOf(child);
|
|
319
|
+
if (range === null) return null;
|
|
320
|
+
out.push(xml.slice(range.start, range.end));
|
|
321
|
+
}
|
|
322
|
+
if (!typeWritten) out.push(type);
|
|
323
|
+
return `<${w}:sectPr>${out.join("")}</${w}:sectPr>`;
|
|
324
|
+
};
|
|
106
325
|
const fieldKindOfInstruction = (instruction) => /^\s*\\?(?<name>[A-Za-z][A-Za-z0-9]*)/u.exec(instruction)?.groups?.["name"]?.toUpperCase() ?? "";
|
|
107
326
|
const textOf = (element) => (element.elements ?? []).map((child) => child.type === "text" ? String(child.text ?? "") : "").join("");
|
|
108
327
|
/** Drop splices that lie inside an earlier one, so none overlap. */
|
|
@@ -234,4 +453,4 @@ const freezeFields = (part, kinds) => {
|
|
|
234
453
|
}))
|
|
235
454
|
};
|
|
236
455
|
};
|
|
237
|
-
export { bookmarkEndXml, bookmarkIdsOf, bookmarkStartXml, complexFieldXml, fieldBookmarkOf, freezeFields, mintRefBookmarkName, refFieldInstruction, setUpdateFieldsOnOpen, withoutContained, wrapParagraphContentInBookmark };
|
|
456
|
+
export { applyRefCaseFormat, bookmarkEndXml, bookmarkIdsOf, bookmarkStartXml, complexFieldXml, fieldBookmarkOf, freezeFields, inheritedReferencesXml, keepsShiftReturnSpacing, mintRefBookmarkName, refCaseFormat, refFieldInstruction, sectionPropertiesXml, setKeepShiftReturnSpacing, setUpdateFieldsOnOpen, withoutContained, wrapParagraphContentInBookmark };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DocxTextEffect, DocxTextEffectOwner } from "./types.js";
|
|
2
|
+
import { RawPart, XmlRange } from "./xml.js";
|
|
3
|
+
export type TextEffect = DocxTextEffect;
|
|
4
|
+
export type TextEffectOwner = DocxTextEffectOwner;
|
|
5
|
+
export declare const TEXT_EFFECTS: readonly TextEffect[];
|
|
6
|
+
export type InvisibleEffect = {
|
|
7
|
+
effect: TextEffect;
|
|
8
|
+
owner: TextEffectOwner;
|
|
9
|
+
range: XmlRange;
|
|
10
|
+
};
|
|
11
|
+
/** Every text effect of a part that shows nothing, in document order. */
|
|
12
|
+
export declare const findInvisibleEffects: ({ root }: RawPart) => InvisibleEffect[];
|
|
13
|
+
/**
|
|
14
|
+
* `part` without its text effects that show nothing; every other byte
|
|
15
|
+
* stays. `xml` is the part as it stands when nothing qualifies. Null when
|
|
16
|
+
* the part cannot be rewritten.
|
|
17
|
+
*/
|
|
18
|
+
export declare const removeInvisibleEffects: (part: RawPart) => {
|
|
19
|
+
xml: string;
|
|
20
|
+
removed: InvisibleEffect[];
|
|
21
|
+
} | null;
|
|
22
|
+
/** How many of each effect a part lost, for a report. */
|
|
23
|
+
export declare const countEffects: (part: string, effects: readonly InvisibleEffect[]) => {
|
|
24
|
+
part: string;
|
|
25
|
+
effect: TextEffect;
|
|
26
|
+
count: number;
|
|
27
|
+
}[];
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { spliceXml } from "../../selectiveXmlPatch.js";
|
|
2
|
+
import { getLocalName } from "../../xmlParser.js";
|
|
3
|
+
import { elementChildren, integerOrNull, isW, rangeOf, wAttr, wChild } from "./xml.js";
|
|
4
|
+
// src/docx/server/templatePlan/effects.ts
|
|
5
|
+
/**
|
|
6
|
+
* Text effects that show nothing.
|
|
7
|
+
*
|
|
8
|
+
* A run's properties can carry text effects of the `w14` extension (`w14:glow`,
|
|
9
|
+
* `w14:shadow`, `w14:reflection`, `w14:textOutline`, `w14:textFill`,
|
|
10
|
+
* `w14:scene3d`, `w14:props3d`). An effect whose values make it invisible
|
|
11
|
+
* still changes how some consumers treat the text: a run with a 3-D scene,
|
|
12
|
+
* even the default one, is drawn as a picture, so its text cannot be found,
|
|
13
|
+
* copied or read aloud in the exported document. Each rule here names the
|
|
14
|
+
* values that make one effect invisible; an effect that meets no rule is
|
|
15
|
+
* left alone.
|
|
16
|
+
*/
|
|
17
|
+
const WORD_2010_NAMESPACE = "http://schemas.microsoft.com/office/word/2010/wordml";
|
|
18
|
+
const TEXT_EFFECTS = [
|
|
19
|
+
"glow",
|
|
20
|
+
"shadow",
|
|
21
|
+
"reflection",
|
|
22
|
+
"textOutline",
|
|
23
|
+
"textFill",
|
|
24
|
+
"scene3d",
|
|
25
|
+
"props3d"
|
|
26
|
+
];
|
|
27
|
+
const isEffect = (element, effect) => element.type === "element" && element.namespaceUri === WORD_2010_NAMESPACE && getLocalName(element.name) === effect;
|
|
28
|
+
const effectChild = (element, name) => elementChildren(element).find((child) => isEffect(child, name)) ?? null;
|
|
29
|
+
/** An attribute of an effect element by its local name, whatever prefix
|
|
30
|
+
* the part binds the namespace to. */
|
|
31
|
+
const effectAttr = (element, name) => {
|
|
32
|
+
for (const [key, value] of Object.entries(element.attributes ?? {})) if (value !== void 0 && (key === name || key.endsWith(`:${name}`))) return String(value);
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
/** Whether every named attribute is stated and zero. */
|
|
36
|
+
const allZero = (element, names) => names.every((name) => Number(effectAttr(element, name) ?? NaN) === 0);
|
|
37
|
+
/** Whether a named attribute is zero, or left to its default of zero. */
|
|
38
|
+
const zeroOrAbsent = (element, name) => {
|
|
39
|
+
const value = effectAttr(element, name);
|
|
40
|
+
return value === null || Number(value) === 0;
|
|
41
|
+
};
|
|
42
|
+
const FULLY_TRANSPARENT = 1e5;
|
|
43
|
+
/**
|
|
44
|
+
* Whether the colour an effect is drawn in is fully transparent. `alpha`
|
|
45
|
+
* states transparency here, in thousandths of a percent: the whole of it
|
|
46
|
+
* leaves nothing of the effect.
|
|
47
|
+
*/
|
|
48
|
+
const drawnTransparent = (element) => elementChildren(element).some((colour) => {
|
|
49
|
+
const alpha = isEffect(colour, "srgbClr") || isEffect(colour, "schemeClr") ? effectChild(colour, "alpha") : null;
|
|
50
|
+
return alpha !== null && Number(effectAttr(alpha, "val")) === FULLY_TRANSPARENT;
|
|
51
|
+
});
|
|
52
|
+
/** Blur, distance and both scales at zero: nothing is drawn, whatever the
|
|
53
|
+
* colour, the direction or the skew. */
|
|
54
|
+
const ZERO_SIZE = [
|
|
55
|
+
"blurRad",
|
|
56
|
+
"dist",
|
|
57
|
+
"sx",
|
|
58
|
+
"sy"
|
|
59
|
+
];
|
|
60
|
+
/** No depth, no contour and no bevel: nothing for a 3-D scene to light. */
|
|
61
|
+
const flatProperties = (props3d) => zeroOrAbsent(props3d, "extrusionH") && zeroOrAbsent(props3d, "contourW") && effectChild(props3d, "bevelT") === null && effectChild(props3d, "bevelB") === null;
|
|
62
|
+
/** The camera every flat text has: straight on, not turned. */
|
|
63
|
+
const defaultCamera = (scene3d) => {
|
|
64
|
+
const camera = effectChild(scene3d, "camera");
|
|
65
|
+
const rotation = camera === null ? null : effectChild(camera, "rot");
|
|
66
|
+
return camera !== null && effectAttr(camera, "prst") === "orthographicFront" && (rotation === null || allZero(rotation, [
|
|
67
|
+
"lat",
|
|
68
|
+
"lon",
|
|
69
|
+
"rev"
|
|
70
|
+
]));
|
|
71
|
+
};
|
|
72
|
+
const HEX_COLOUR = /^[0-9a-f]{6}$/iu;
|
|
73
|
+
/** A solid fill in exactly the colour the run states for its text. */
|
|
74
|
+
const fillIsRunColour = (textFill, runProperties) => {
|
|
75
|
+
const solid = elementChildren(textFill).length === 1 ? effectChild(textFill, "solidFill") : null;
|
|
76
|
+
const colour = (solid === null ? [] : elementChildren(solid)).length === 1 ? effectChild(solid ?? textFill, "srgbClr") : null;
|
|
77
|
+
const stated = wChild(runProperties, "color");
|
|
78
|
+
const filled = colour === null ? null : effectAttr(colour, "val");
|
|
79
|
+
const run = wAttr(stated, "val");
|
|
80
|
+
return colour !== null && elementChildren(colour).length === 0 && filled !== null && run !== null && wAttr(stated, "themeColor") === null && HEX_COLOUR.test(filled) && filled.toLowerCase() === run.toLowerCase();
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Whether an effect of `runProperties` shows nothing. One rule per effect:
|
|
84
|
+
*
|
|
85
|
+
* - `glow`: radius zero, or a fully transparent colour.
|
|
86
|
+
* - `shadow`: blur, distance and both scales zero, or a fully transparent
|
|
87
|
+
* colour. A shadow of full size straight under the text is not one: its
|
|
88
|
+
* edge shows around the glyphs.
|
|
89
|
+
* - `reflection`: blur, distance and both scales zero.
|
|
90
|
+
* - `textOutline`: no fill, a width of zero, or a fully transparent solid
|
|
91
|
+
* fill.
|
|
92
|
+
* - `textFill`: a plain solid fill in the colour the run states. A
|
|
93
|
+
* transparent fill is the opposite of nothing: it hides the text.
|
|
94
|
+
* - `props3d`: no extrusion, no contour, no bevel.
|
|
95
|
+
* - `scene3d`: the default camera, not turned, and nothing 3-D beside it.
|
|
96
|
+
*/
|
|
97
|
+
const showsNothing = (effect, element, runProperties) => {
|
|
98
|
+
switch (effect) {
|
|
99
|
+
case "glow": return allZero(element, ["rad"]) || drawnTransparent(element);
|
|
100
|
+
case "shadow": return allZero(element, ZERO_SIZE) || drawnTransparent(element);
|
|
101
|
+
case "reflection": return allZero(element, ZERO_SIZE);
|
|
102
|
+
case "textOutline": {
|
|
103
|
+
const solid = effectChild(element, "solidFill");
|
|
104
|
+
return allZero(element, ["w"]) || solid !== null && drawnTransparent(solid) || effectChild(element, "noFill") !== null && solid === null && effectChild(element, "gradFill") === null;
|
|
105
|
+
}
|
|
106
|
+
case "textFill": return fillIsRunColour(element, runProperties);
|
|
107
|
+
case "props3d": return flatProperties(element);
|
|
108
|
+
case "scene3d": {
|
|
109
|
+
const props3d = effectChild(runProperties, "props3d");
|
|
110
|
+
return defaultCamera(element) && (props3d === null || flatProperties(props3d));
|
|
111
|
+
}
|
|
112
|
+
default: return effect;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const ownerOf = (element, owner) => {
|
|
116
|
+
if (isW(element, "abstractNum")) return {
|
|
117
|
+
kind: "level",
|
|
118
|
+
abstractNumId: integerOrNull(wAttr(element, "abstractNumId")),
|
|
119
|
+
ilvl: null
|
|
120
|
+
};
|
|
121
|
+
if (isW(element, "lvl")) return {
|
|
122
|
+
kind: "level",
|
|
123
|
+
abstractNumId: owner.kind === "level" ? owner.abstractNumId : null,
|
|
124
|
+
ilvl: integerOrNull(wAttr(element, "ilvl"))
|
|
125
|
+
};
|
|
126
|
+
if (isW(element, "style")) return {
|
|
127
|
+
kind: "style",
|
|
128
|
+
styleId: wAttr(element, "styleId")
|
|
129
|
+
};
|
|
130
|
+
return isW(element, "docDefaults") ? { kind: "defaults" } : owner;
|
|
131
|
+
};
|
|
132
|
+
/** Every text effect of a part that shows nothing, in document order. */
|
|
133
|
+
const findInvisibleEffects = ({ root }) => {
|
|
134
|
+
const found = [];
|
|
135
|
+
const stack = [{
|
|
136
|
+
element: root,
|
|
137
|
+
owner: { kind: "text" }
|
|
138
|
+
}];
|
|
139
|
+
for (let next = stack.pop(); next !== void 0; next = stack.pop()) {
|
|
140
|
+
const { element } = next;
|
|
141
|
+
const owner = ownerOf(element, next.owner);
|
|
142
|
+
const children = elementChildren(element);
|
|
143
|
+
if (isW(element, "rPr")) for (const effect of TEXT_EFFECTS) {
|
|
144
|
+
const stated = effectChild(element, effect);
|
|
145
|
+
const range = stated === null ? null : rangeOf(stated);
|
|
146
|
+
if (stated !== null && range !== null && showsNothing(effect, stated, element)) found.push({
|
|
147
|
+
effect,
|
|
148
|
+
owner,
|
|
149
|
+
range
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
for (let index = children.length - 1; index >= 0; index -= 1) {
|
|
153
|
+
const child = children[index];
|
|
154
|
+
if (child !== void 0) stack.push({
|
|
155
|
+
element: child,
|
|
156
|
+
owner
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return found.toSorted((left, right) => left.range.start - right.range.start);
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* `part` without its text effects that show nothing; every other byte
|
|
164
|
+
* stays. `xml` is the part as it stands when nothing qualifies. Null when
|
|
165
|
+
* the part cannot be rewritten.
|
|
166
|
+
*/
|
|
167
|
+
const removeInvisibleEffects = (part) => {
|
|
168
|
+
const removed = findInvisibleEffects(part);
|
|
169
|
+
if (removed.length === 0) return {
|
|
170
|
+
xml: part.xml,
|
|
171
|
+
removed
|
|
172
|
+
};
|
|
173
|
+
const xml = spliceXml(part.xml, removed.map(({ range }) => ({
|
|
174
|
+
...range,
|
|
175
|
+
newXml: ""
|
|
176
|
+
})));
|
|
177
|
+
return xml === null ? null : {
|
|
178
|
+
xml,
|
|
179
|
+
removed
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
/** How many of each effect a part lost, for a report. */
|
|
183
|
+
const countEffects = (part, effects) => TEXT_EFFECTS.map((effect) => ({
|
|
184
|
+
part,
|
|
185
|
+
effect,
|
|
186
|
+
count: effects.filter((found) => found.effect === effect).length
|
|
187
|
+
})).filter(({ count }) => count > 0);
|
|
188
|
+
export { TEXT_EFFECTS, countEffects, findInvisibleEffects, removeInvisibleEffects };
|
|
@@ -87,6 +87,8 @@ export type ParagraphEmit = {
|
|
|
87
87
|
instructionOf: (segment: ExpectedSegment) => string | null;
|
|
88
88
|
/** Whether the paragraph's style binds a list that `numbering: null` must cancel. */
|
|
89
89
|
styleBindsList: boolean;
|
|
90
|
+
/** The `w:sectPr` of the section the paragraph is the last of, or null. */
|
|
91
|
+
sectionXml: string | null;
|
|
90
92
|
};
|
|
91
93
|
/** Runs of a placed paragraph, inside its bookmark when it is a reference target. */
|
|
92
94
|
export declare const paragraphContentXml: ({ paragraph, bookmark, instructionOf }: ParagraphEmit, context: EmitContext) => RunsResult;
|
|
@@ -101,7 +103,8 @@ export type TableEmit = {
|
|
|
101
103
|
/**
|
|
102
104
|
* A source table rebuilt: its grid, spans and merges, with every cell
|
|
103
105
|
* paragraph placed like a body paragraph. Without a template table style the
|
|
104
|
-
* source's borders are kept so the grid stays visible
|
|
106
|
+
* source's borders are kept so the grid stays visible, and the fill of its
|
|
107
|
+
* cells with them: a header row, the colours of a legend.
|
|
105
108
|
*/
|
|
106
109
|
export declare const tableXml: ({ table, styleId, paragraphOf }: TableEmit, context: EmitContext) => RunsResult;
|
|
107
110
|
export type NoteEmit = {
|
|
@@ -221,6 +221,14 @@ const pieceRunXml = (piece, context, linked) => {
|
|
|
221
221
|
const mark = `<${w}:${kind}Reference ${w}:id="${context.noteId(kind, sourceId)}"/>`;
|
|
222
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
223
|
}
|
|
224
|
+
case "selfNumber": {
|
|
225
|
+
const instruction = piece.atom?.instruction;
|
|
226
|
+
return Result.ok(instruction === void 0 ? "" : [
|
|
227
|
+
`<${w}:fldChar ${w}:fldCharType="begin"/>`,
|
|
228
|
+
`<${w}:instrText xml:space="preserve"> ${escapeXmlText(instruction)} </${w}:instrText>`,
|
|
229
|
+
`<${w}:fldChar ${w}:fldCharType="end"/>`
|
|
230
|
+
].map((content) => run(content)).join(""));
|
|
231
|
+
}
|
|
224
232
|
case "object": {
|
|
225
233
|
const transferred = transferObject(piece, context);
|
|
226
234
|
if (Result.isError(transferred)) return transferred;
|
|
@@ -326,8 +334,26 @@ const paragraphXml = (emit, context) => {
|
|
|
326
334
|
const { styleId, numbering } = emit.paragraph;
|
|
327
335
|
const properties = [];
|
|
328
336
|
if (styleId !== null) properties.push(`<${w}:pStyle ${w}:val="${escapeXmlAttribute(styleId)}"/>`);
|
|
337
|
+
if (emit.paragraph.keepNext) properties.push(`<${w}:keepNext/>`);
|
|
338
|
+
if (emit.paragraph.pageBreakBefore) properties.push(`<${w}:pageBreakBefore/>`);
|
|
329
339
|
if (numbering.kind === "direct") properties.push(`<${w}:numPr><${w}:ilvl ${w}:val="${numbering.ilvl}"/><${w}:numId ${w}:val="${numbering.numId}"/></${w}:numPr>`);
|
|
330
340
|
else if (numbering.kind === "none" && emit.styleBindsList) properties.push(`<${w}:numPr><${w}:numId ${w}:val="${NO_LIST_NUM_ID}"/></${w}:numPr>`);
|
|
341
|
+
const { indent, tabStops } = emit.paragraph;
|
|
342
|
+
if (tabStops !== null) {
|
|
343
|
+
const stops = tabStops.map((stop) => `<${w}:tab ${w}:val="left" ${w}:pos="${String(stop)}"/>`).join("");
|
|
344
|
+
properties.push(`<${w}:tabs>${stops}</${w}:tabs>`);
|
|
345
|
+
}
|
|
346
|
+
if (indent !== null) {
|
|
347
|
+
const sides = [
|
|
348
|
+
"left",
|
|
349
|
+
"hanging",
|
|
350
|
+
"firstLine"
|
|
351
|
+
].filter((side) => indent[side] !== void 0).map((side) => ` ${w}:${side}="${String(indent[side])}"`).join("");
|
|
352
|
+
properties.push(`<${w}:ind${sides}/>`);
|
|
353
|
+
}
|
|
354
|
+
const { alignment } = emit.paragraph;
|
|
355
|
+
if (alignment !== null) properties.push(`<${w}:jc ${w}:val="${alignment}"/>`);
|
|
356
|
+
if (emit.sectionXml !== null) properties.push(emit.sectionXml);
|
|
331
357
|
const runs = segmentsRunsXml(emit.paragraph.segments, context, emit.instructionOf);
|
|
332
358
|
if (Result.isError(runs)) return runs;
|
|
333
359
|
const xml = `<${w}:p>${properties.length === 0 ? "" : `<${w}:pPr>${properties.join("")}</${w}:pPr>`}${runs.value}</${w}:p>`;
|
|
@@ -356,6 +382,23 @@ const CELL_SPAN_PROPERTIES = [
|
|
|
356
382
|
"hMerge",
|
|
357
383
|
"vMerge"
|
|
358
384
|
];
|
|
385
|
+
/** What a cell's fill states by itself; a theme colour is the template's. */
|
|
386
|
+
const SHADING_KEPT = [
|
|
387
|
+
"val",
|
|
388
|
+
"color",
|
|
389
|
+
"fill"
|
|
390
|
+
];
|
|
391
|
+
/**
|
|
392
|
+
* The fill of a cell as its own colours state it. A theme colour would be
|
|
393
|
+
* read from the template's theme, which is another one; a fill stated by a
|
|
394
|
+
* theme colour alone is left out.
|
|
395
|
+
*/
|
|
396
|
+
const cellShadingXml = (properties, prefix) => {
|
|
397
|
+
const shading = wChild(properties, "shd");
|
|
398
|
+
const fill = wAttr(shading, "fill");
|
|
399
|
+
if (shading === null || fill === null || fill === "auto") return "";
|
|
400
|
+
return `<${prefix}:shd${SHADING_KEPT.map((name) => [name, wAttr(shading, name)]).filter(([, value]) => value !== null).map(([name, value]) => ` ${prefix}:${name}="${escapeXmlAttribute(value ?? "")}"`).join("")}/>`;
|
|
401
|
+
};
|
|
359
402
|
const keptChildrenXml = (properties, names, prefix) => names.map((name) => {
|
|
360
403
|
const child = wChild(properties, name);
|
|
361
404
|
return child === null ? "" : wSubtreeXml(child, prefix);
|
|
@@ -363,7 +406,8 @@ const keptChildrenXml = (properties, names, prefix) => names.map((name) => {
|
|
|
363
406
|
/**
|
|
364
407
|
* A source table rebuilt: its grid, spans and merges, with every cell
|
|
365
408
|
* paragraph placed like a body paragraph. Without a template table style the
|
|
366
|
-
* source's borders are kept so the grid stays visible
|
|
409
|
+
* source's borders are kept so the grid stays visible, and the fill of its
|
|
410
|
+
* cells with them: a header row, the colours of a legend.
|
|
367
411
|
*/
|
|
368
412
|
const tableXml = ({ table, styleId, paragraphOf }, context) => {
|
|
369
413
|
const { w } = context.prefixes;
|
|
@@ -393,7 +437,7 @@ const tableXml = ({ table, styleId, paragraphOf }, context) => {
|
|
|
393
437
|
const name = wName(child);
|
|
394
438
|
if (name === "tc") {
|
|
395
439
|
const cellProperties = wChild(child, "tcPr");
|
|
396
|
-
const kept = `${keptChildrenXml(cellProperties, CELL_SPAN_PROPERTIES, w)}${styleId === null ? keptChildrenXml(cellProperties, ["tcBorders"], w) : ""}${keptChildrenXml(cellProperties, ["vAlign"], w)}`;
|
|
440
|
+
const kept = `${keptChildrenXml(cellProperties, CELL_SPAN_PROPERTIES, w)}${styleId === null ? `${keptChildrenXml(cellProperties, ["tcBorders"], w)}${cellShadingXml(cellProperties, w)}` : ""}${keptChildrenXml(cellProperties, ["vAlign"], w)}`;
|
|
397
441
|
const blocks = blocksXml(child);
|
|
398
442
|
if (Result.isError(blocks)) return blocks;
|
|
399
443
|
const content = blocks.value.endsWith(`</${w}:p>`) ? blocks.value : `${blocks.value}<${w}:p/>`;
|