@stll/folio-core 0.73.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/dist/ai-edits/headless.js +2 -5
- package/dist/ai-edits/pendingJoin.js +6 -1
- package/dist/ai-edits/result-validation.js +1 -1
- package/dist/ai-edits/snapshot.js +1 -1
- package/dist/ai-edits/table-cell-mutations.js +1 -1
- package/dist/ai-edits/tracked-batch-fidelity.js +1 -1
- 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 +6 -28
- package/dist/canonical/canonicalProjectionBlocks.d.ts +4 -4
- package/dist/canonical/canonicalPublicOperations.js +70 -27
- package/dist/canonical/canonicalSelection.js +1 -1
- package/dist/canonical/canonicalSession.js +14 -21
- package/dist/controller/autocompleteSuggestion.js +1 -1
- package/dist/controller/canonicalClipboard.js +2 -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/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/canonicalYjsRoom.js +1 -1
- package/dist/controller/hiddenEditorApi.js +2 -17
- package/dist/controller/hiddenEditorManager.js +4 -8
- package/dist/document-operations.js +1 -1
- 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/modelValidation.js +1 -1
- package/dist/docx/parser.js +1 -1
- package/dist/docx/reviewResolutionProvenance.js +1 -1
- package/dist/docx/rezip.d.ts +1 -1
- package/dist/docx/rezip.js +2 -2
- package/dist/docx/serializer/borderSerializer.js +1 -1
- package/dist/docx/serializer/commentSerializer.js +1 -1
- package/dist/docx/serializer/documentSerializer.js +1 -1
- package/dist/docx/serializer/paragraphSerializer.js +3 -3
- package/dist/docx/serializer/runSerializer.js +1 -1
- package/dist/docx/serializer/sectionPropertiesSerializer.js +1 -1
- package/dist/docx/serializer/tableSerializer.js +1 -1
- package/dist/docx/serializer/textFormattingSerializer.js +1 -1
- package/dist/docx/serializer/trackedChangeAttributes.js +1 -1
- package/dist/docx/server/templatePlan/apply.js +69 -11
- package/dist/docx/server/templatePlan/inspect.js +88 -35
- package/dist/docx/server/templatePlan/labels.d.ts +10 -1
- package/dist/docx/server/templatePlan/labels.js +31 -2
- package/dist/docx/server/templatePlan/plan.d.ts +2 -0
- package/dist/docx/server/templatePlan/plan.js +41 -7
- package/dist/docx/server/templatePlan/planShape.js +22 -3
- package/dist/docx/server/templatePlan/types.d.ts +38 -2
- package/dist/docx/server/templatePlan/types.js +1 -0
- package/dist/docx/server/templatePlan/verify.js +11 -3
- package/dist/docx/server/templatePlan/xml.d.ts +5 -0
- package/dist/docx/server/templatePlan/xml.js +7 -1
- package/dist/docx/storyBlockReplay.js +1 -1
- package/dist/docx/xmlParser.js +1 -1
- 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/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/paragraphFormattingSerialization.js +1 -1
- package/dist/internal/starterKitExtensions.d.ts +20 -0
- package/dist/internal/starterKitExtensions.js +123 -0
- package/dist/internal/wholeStoryRevisionResolution.js +2 -2
- package/dist/prosemirror/attrs/index.js +1 -1
- package/dist/prosemirror/canonicalSelectionRange.js +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +1 -1
- package/dist/prosemirror/commands/comments.js +3 -3
- package/dist/prosemirror/commands/contentControls.js +1 -1
- package/dist/prosemirror/commands/pastePlainText.js +2 -3
- package/dist/prosemirror/commands/replaceRangeText.js +1 -1
- package/dist/prosemirror/commentRecords.js +2 -2
- 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/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 +2 -2
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
- package/dist/prosemirror/extensions/features/ListExtension.js +7 -2
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
- package/dist/prosemirror/extensions/index.d.ts +2 -1
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +8 -3
- package/dist/prosemirror/extensions/nodes/TableExtension.js +7 -40
- package/dist/prosemirror/hyperlinkRemoval.js +7 -2
- package/dist/prosemirror/index.d.ts +2 -2
- package/dist/prosemirror/index.js +2 -2
- package/dist/prosemirror/keptRangeBoundaries.js +1 -1
- package/dist/prosemirror/listNumbering.js +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/pastedCommentCopies.js +1 -1
- package/dist/prosemirror/plugins/documentNumbering.js +1 -1
- package/dist/prosemirror/plugins/documentStyles.js +1 -1
- package/dist/prosemirror/replacedAnnotations.js +1 -1
- package/dist/prosemirror/suggestionCommands.d.ts +47 -0
- package/dist/prosemirror/suggestionCommands.js +31 -0
- package/dist/prosemirror/tableCellPaste.js +1 -1
- package/dist/prosemirror/tableRunIn.js +1 -1
- package/dist/prosemirror/textInput.js +1 -1
- package/dist/types/canonicalCapabilities.d.ts +6 -52
- package/dist/types/canonicalCapabilities.js +6 -52
- package/package.json +2 -2
- package/dist/ai-edits/apply.d.ts +0 -94
- package/dist/ai-edits/apply.js +0 -6637
- 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/document-operations-apply.d.ts +0 -15
- package/dist/document-operations-apply.js +0 -280
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +0 -12
- package/dist/prosemirror/extensions/core/HistoryExtension.js +0 -114
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +0 -23
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +0 -270
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +0 -51
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +0 -411
- 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
|
@@ -13,7 +13,7 @@ import { resolvePlan } from "./plan.js";
|
|
|
13
13
|
import { readStoryResources } from "./resources.js";
|
|
14
14
|
import { TemplatePlanError } from "./types.js";
|
|
15
15
|
import { reportTemplatePlanOutput } from "./verify.js";
|
|
16
|
-
import { elementChildren, escapeXmlAttribute, innerRangeOf, integerOrNull, isW, maxOf, partPrefixes, rangeOf, readRawPart, sliceWithSplices, wAttr, wChild, wChildren, wName, walkElements } from "./xml.js";
|
|
16
|
+
import { elementChildren, escapeXmlAttribute, innerRangeOf, integerOrNull, isW, maxOf, partPrefixes, rangeOf, readRawPart, sliceWithSplices, twipsOrNull, wAttr, wChild, wChildren, wName, walkElements } from "./xml.js";
|
|
17
17
|
import { Result } from "better-result";
|
|
18
18
|
import { ZipArchive } from "@stll/docx-core/zip";
|
|
19
19
|
// src/docx/server/templatePlan/apply.ts
|
|
@@ -109,6 +109,56 @@ const LEVEL_CHILD_ORDER = [
|
|
|
109
109
|
"pPr",
|
|
110
110
|
"rPr"
|
|
111
111
|
];
|
|
112
|
+
/** Children of `w:pPr` that follow `w:ind` in the schema's order. */
|
|
113
|
+
const AFTER_INDENT = [
|
|
114
|
+
"contextualSpacing",
|
|
115
|
+
"mirrorIndents",
|
|
116
|
+
"suppressOverlap",
|
|
117
|
+
"jc",
|
|
118
|
+
"textDirection",
|
|
119
|
+
"textAlignment",
|
|
120
|
+
"textboxTightWrap",
|
|
121
|
+
"outlineLvl",
|
|
122
|
+
"divId",
|
|
123
|
+
"cnfStyle",
|
|
124
|
+
"rPr",
|
|
125
|
+
"sectPr",
|
|
126
|
+
"pPrChange"
|
|
127
|
+
];
|
|
128
|
+
/**
|
|
129
|
+
* The `w:pPr` of a level with the planned indent. What the level states and
|
|
130
|
+
* the patch leaves out is kept; a hanging and a first-line indent exclude
|
|
131
|
+
* each other, and an indent counted in characters would override the planned
|
|
132
|
+
* one, so those are not carried over.
|
|
133
|
+
*/
|
|
134
|
+
const levelPropertiesXml = ({ part, level, w, indent }) => {
|
|
135
|
+
const properties = wChild(level, "pPr");
|
|
136
|
+
const existing = wChild(properties, "ind");
|
|
137
|
+
const stated = (name) => twipsOrNull(wAttr(existing, name));
|
|
138
|
+
const hanging = indent.hanging ?? (indent.firstLine === void 0 ? stated("hanging") : null);
|
|
139
|
+
const firstLine = indent.firstLine ?? (indent.hanging === void 0 ? stated("firstLine") : null);
|
|
140
|
+
const indentXml = `<${w}:ind${[
|
|
141
|
+
["left", indent.left ?? stated("left") ?? stated("start")],
|
|
142
|
+
["right", wAttr(existing, "right") ?? wAttr(existing, "end")],
|
|
143
|
+
["hanging", hanging],
|
|
144
|
+
["firstLine", firstLine]
|
|
145
|
+
].flatMap(([name, value]) => value === null ? [] : [` ${w}:${name}="${escapeXmlAttribute(String(value))}"`]).join("")}/>`;
|
|
146
|
+
const range = properties === null ? null : rangeOf(properties);
|
|
147
|
+
if (properties === null || range === null) return `<${w}:pPr>${indentXml}</${w}:pPr>`;
|
|
148
|
+
const existingRange = existing === null ? null : rangeOf(existing);
|
|
149
|
+
if (existingRange !== null) return sliceWithSplices(part.xml, range, [{
|
|
150
|
+
...existingRange,
|
|
151
|
+
newXml: indentXml
|
|
152
|
+
}]);
|
|
153
|
+
const inner = innerRangeOf(part.xml, properties);
|
|
154
|
+
if (inner === null) {
|
|
155
|
+
const name = properties.name ?? `${w}:pPr`;
|
|
156
|
+
return `${part.xml.slice(range.start, range.end - 2).trimEnd()}>${indentXml}</${name}>`;
|
|
157
|
+
}
|
|
158
|
+
const later = AFTER_INDENT.map((name) => wChild(properties, name)).find((element) => element !== null);
|
|
159
|
+
const at = (later === void 0 || later === null ? null : rangeOf(later))?.start ?? inner.end;
|
|
160
|
+
return `${part.xml.slice(range.start, at)}${indentXml}${part.xml.slice(at, range.end)}`;
|
|
161
|
+
};
|
|
112
162
|
/** The template numbering part with level patches and new list instances. */
|
|
113
163
|
const editNumbering = (part, { patches, mints }) => {
|
|
114
164
|
const prefixes = partPrefixes(part.root);
|
|
@@ -131,17 +181,25 @@ const editNumbering = (part, { patches, mints }) => {
|
|
|
131
181
|
code: "unsupported-content",
|
|
132
182
|
message: `Level ${patch.ilvl} of list definition ${patch.abstractNumId} holds markup a patch cannot change.`
|
|
133
183
|
}));
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
184
|
+
const valued = (name, value) => `<${w}:${name} ${w}:val="${escapeXmlAttribute(value)}"/>`;
|
|
185
|
+
const properties = patch.indent === void 0 ? void 0 : levelPropertiesXml({
|
|
186
|
+
part,
|
|
187
|
+
level,
|
|
188
|
+
w,
|
|
189
|
+
indent: patch.indent
|
|
190
|
+
});
|
|
191
|
+
if (properties === null) return Result.err(unreadable(part.path, "The numbering part could not be patched."));
|
|
192
|
+
const planned = {
|
|
193
|
+
...patch.start === void 0 ? {} : { start: valued("start", String(patch.start)) },
|
|
194
|
+
...patch.numFmt === void 0 ? {} : { numFmt: valued("numFmt", patch.numFmt) },
|
|
195
|
+
...patch.suff === void 0 ? {} : { suff: valued("suff", patch.suff) },
|
|
196
|
+
...patch.lvlText === void 0 ? {} : { lvlText: valued("lvlText", patch.lvlText) },
|
|
197
|
+
...properties === void 0 ? {} : { pPr: properties }
|
|
139
198
|
};
|
|
140
199
|
const inner = innerRangeOf(part.xml, level);
|
|
141
200
|
for (const [index, name] of LEVEL_CHILD_ORDER.entries()) {
|
|
142
|
-
const
|
|
143
|
-
if (
|
|
144
|
-
const xml = `<${w}:${name} ${w}:val="${escapeXmlAttribute(value)}"/>`;
|
|
201
|
+
const xml = planned[name];
|
|
202
|
+
if (xml === void 0) continue;
|
|
145
203
|
const existing = wChild(level, name);
|
|
146
204
|
const existingRange = existing === null ? null : rangeOf(existing);
|
|
147
205
|
if (existingRange !== null) {
|
|
@@ -160,8 +218,8 @@ const editNumbering = (part, { patches, mints }) => {
|
|
|
160
218
|
}
|
|
161
219
|
if (inner === null) {
|
|
162
220
|
const children = LEVEL_CHILD_ORDER.flatMap((name) => {
|
|
163
|
-
const
|
|
164
|
-
return
|
|
221
|
+
const xml = planned[name];
|
|
222
|
+
return xml === void 0 ? [] : [xml];
|
|
165
223
|
}).join("");
|
|
166
224
|
insertions.delete(levelRange.end - 2);
|
|
167
225
|
splices.push({
|
|
@@ -5,47 +5,100 @@ import { styleNumbering } from "./labels.js";
|
|
|
5
5
|
import { guarded, readPartText } from "./package.js";
|
|
6
6
|
import { createStoryState, endStory, readParagraph, walkBlocks } from "./story.js";
|
|
7
7
|
import { TemplatePlanError } from "./types.js";
|
|
8
|
-
import { isW, readRawPart, wAttr, walkElements } from "./xml.js";
|
|
8
|
+
import { integerOrNull, isW, readRawPart, twipsOrNull, wAttr, wChild, wChildVal, wChildren, walkElements } from "./xml.js";
|
|
9
9
|
import { Result } from "better-result";
|
|
10
10
|
// src/docx/server/templatePlan/inspect.ts
|
|
11
11
|
/** A template's inventory: what a plan may name when it places blocks onto it. */
|
|
12
12
|
const DEFAULT_LEVEL_START = 1;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
/** The `w:jc` each style of the styles part states itself, by style id. */
|
|
14
|
+
const statedAlignments = ({ stylesPath, stylesXml }) => {
|
|
15
|
+
const alignments = /* @__PURE__ */ new Map();
|
|
16
|
+
const part = stylesPath === null || stylesXml === null ? null : readRawPart(stylesPath, stylesXml);
|
|
17
|
+
for (const style of wChildren(part?.root, "style")) {
|
|
18
|
+
const styleId = wAttr(style, "styleId");
|
|
19
|
+
const alignment = wChildVal(wChild(style, "pPr"), "jc");
|
|
20
|
+
if (styleId !== null && alignment !== null) alignments.set(styleId, alignment);
|
|
21
|
+
}
|
|
22
|
+
return alignments;
|
|
23
|
+
};
|
|
24
|
+
/** The indent each level of the numbering part states, by definition and level. */
|
|
25
|
+
const statedIndents = ({ numberingPath, numberingXml }) => {
|
|
26
|
+
const indents = /* @__PURE__ */ new Map();
|
|
27
|
+
const part = numberingPath === null || numberingXml === null ? null : readRawPart(numberingPath, numberingXml);
|
|
28
|
+
for (const definition of wChildren(part?.root, "abstractNum")) for (const level of wChildren(definition, "lvl")) {
|
|
29
|
+
const indent = wChild(wChild(level, "pPr"), "ind");
|
|
30
|
+
const stated = (name) => twipsOrNull(wAttr(indent, name));
|
|
31
|
+
indents.set(`${String(integerOrNull(wAttr(definition, "abstractNumId")))}:${String(integerOrNull(wAttr(level, "ilvl")))}`, {
|
|
32
|
+
left: stated("left") ?? stated("start"),
|
|
33
|
+
hanging: stated("hanging"),
|
|
34
|
+
firstLine: stated("firstLine")
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return indents;
|
|
38
|
+
};
|
|
39
|
+
const NO_INDENT = {
|
|
40
|
+
left: null,
|
|
41
|
+
hanging: null,
|
|
42
|
+
firstLine: null
|
|
43
|
+
};
|
|
44
|
+
const inspectStyles = (analyzed) => {
|
|
45
|
+
const { styles, numbering } = analyzed;
|
|
46
|
+
const stated = statedAlignments(analyzed);
|
|
47
|
+
/** The alignment of the nearest style in the `basedOn` chain that states one. */
|
|
48
|
+
const alignmentOf = (styleId) => {
|
|
49
|
+
const seen = /* @__PURE__ */ new Set();
|
|
50
|
+
let cursor = styleId;
|
|
51
|
+
while (cursor !== void 0 && !seen.has(cursor)) {
|
|
52
|
+
seen.add(cursor);
|
|
53
|
+
const alignment = stated.get(cursor);
|
|
54
|
+
if (alignment !== void 0) return alignment;
|
|
55
|
+
cursor = styles.get(cursor)?.basedOn;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
26
58
|
};
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
59
|
+
return [...styles.values()].map((style) => {
|
|
60
|
+
const bound = styleNumbering(style.styleId, styles, numbering);
|
|
61
|
+
return {
|
|
62
|
+
styleId: style.styleId,
|
|
63
|
+
name: style.name ?? null,
|
|
64
|
+
type: style.type,
|
|
65
|
+
basedOn: style.basedOn ?? null,
|
|
66
|
+
numPr: bound?.kind === "reference" ? {
|
|
67
|
+
numId: bound.numId,
|
|
68
|
+
ilvl: bound.ilvl ?? 0
|
|
69
|
+
} : null,
|
|
70
|
+
outlineLvl: styleOutlineLevel(style),
|
|
71
|
+
alignment: alignmentOf(style.styleId),
|
|
72
|
+
isDefault: style.default === true
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
const inspectNumbering = (analyzed) => {
|
|
77
|
+
const { numbering } = analyzed;
|
|
78
|
+
const indents = statedIndents(analyzed);
|
|
79
|
+
return {
|
|
80
|
+
abstractNums: (numbering?.definitions.abstractNums ?? []).map(({ abstractNumId, levels }) => ({
|
|
81
|
+
abstractNumId,
|
|
82
|
+
levels: levels.map((level) => ({
|
|
83
|
+
ilvl: level.ilvl,
|
|
84
|
+
numFmt: level.numFmt,
|
|
85
|
+
lvlText: level.lvlText,
|
|
86
|
+
start: level.start ?? DEFAULT_LEVEL_START,
|
|
87
|
+
suff: level.suffix ?? "tab",
|
|
88
|
+
pStyle: level.pStyle ?? null,
|
|
89
|
+
indent: indents.get(`${String(abstractNumId)}:${String(level.ilvl)}`) ?? NO_INDENT
|
|
90
|
+
}))
|
|
91
|
+
})),
|
|
92
|
+
nums: (numbering?.definitions.nums ?? []).map(({ numId, abstractNumId, levelOverrides }) => ({
|
|
93
|
+
numId,
|
|
94
|
+
abstractNumId,
|
|
95
|
+
overrides: (levelOverrides ?? []).map(({ ilvl, startOverride }) => ({
|
|
96
|
+
ilvl,
|
|
97
|
+
startOverride: startOverride ?? null
|
|
98
|
+
}))
|
|
46
99
|
}))
|
|
47
|
-
}
|
|
48
|
-
}
|
|
100
|
+
};
|
|
101
|
+
};
|
|
49
102
|
const inspectSections = ({ story, pkg }) => story.sections.map((sectPr, index) => {
|
|
50
103
|
const properties = parseSectionProperties(sectPr);
|
|
51
104
|
const partOf = (rId) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NumberingMap } from "../../numberingParser.js";
|
|
2
2
|
import { StyleMap } from "../../styleParser.js";
|
|
3
3
|
import { DocxBlockNumbering } from "./types.js";
|
|
4
|
-
import { ParagraphNumberingOverride } from "@stll/docx-core/model";
|
|
4
|
+
import { LevelSuffix, ParagraphNumberingOverride } from "@stll/docx-core/model";
|
|
5
5
|
export type ParagraphLabel = {
|
|
6
6
|
label: string | null;
|
|
7
7
|
numbering: DocxBlockNumbering | null;
|
|
@@ -12,6 +12,15 @@ export type ParagraphLabel = {
|
|
|
12
12
|
numberOnly: string | null;
|
|
13
13
|
/** The label as a `REF \n` field shows it: without a trailing period. */
|
|
14
14
|
paragraphNumber: string | null;
|
|
15
|
+
/**
|
|
16
|
+
* The label and what its list puts after it, when the label can stand as
|
|
17
|
+
* text: it reads the same wherever the file is opened. Null for a bullet,
|
|
18
|
+
* whose glyph belongs to a font, and for a number a language spells.
|
|
19
|
+
*/
|
|
20
|
+
asText: {
|
|
21
|
+
label: string;
|
|
22
|
+
suffix: LevelSuffix;
|
|
23
|
+
} | null;
|
|
15
24
|
};
|
|
16
25
|
/**
|
|
17
26
|
* The numbering a style binds its paragraphs to. A style that names a list
|
|
@@ -12,7 +12,29 @@ const NO_LABEL = {
|
|
|
12
12
|
label: null,
|
|
13
13
|
numbering: null,
|
|
14
14
|
numberOnly: null,
|
|
15
|
-
paragraphNumber: null
|
|
15
|
+
paragraphNumber: null,
|
|
16
|
+
asText: null
|
|
17
|
+
};
|
|
18
|
+
/** Counter formats every consumer and language writes with the same characters. */
|
|
19
|
+
const PLAIN_FORMATS = /* @__PURE__ */ new Set([
|
|
20
|
+
"decimal",
|
|
21
|
+
"decimalZero",
|
|
22
|
+
"upperRoman",
|
|
23
|
+
"lowerRoman",
|
|
24
|
+
"upperLetter",
|
|
25
|
+
"lowerLetter"
|
|
26
|
+
]);
|
|
27
|
+
const LEVEL_PLACEHOLDER = /%([1-9])/gu;
|
|
28
|
+
const labelAsText = ({ label, template, levelFormats, suffix }) => {
|
|
29
|
+
if (label.trim() === "") return null;
|
|
30
|
+
for (const [, digit] of template.matchAll(LEVEL_PLACEHOLDER)) {
|
|
31
|
+
const format = levelFormats?.[Number(digit) - 1];
|
|
32
|
+
if (format === void 0 || !PLAIN_FORMATS.has(format)) return null;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
label,
|
|
36
|
+
suffix: suffix ?? "tab"
|
|
37
|
+
};
|
|
16
38
|
};
|
|
17
39
|
/**
|
|
18
40
|
* The numbering a style binds its paragraphs to. A style that names a list
|
|
@@ -108,11 +130,18 @@ const createLabelCounter = ({ numbering, styles, defaultStyleId }) => {
|
|
|
108
130
|
label,
|
|
109
131
|
numbering: numberingInfo,
|
|
110
132
|
numberOnly: null,
|
|
111
|
-
paragraphNumber: null
|
|
133
|
+
paragraphNumber: null,
|
|
134
|
+
asText: null
|
|
112
135
|
};
|
|
113
136
|
return {
|
|
114
137
|
label,
|
|
115
138
|
numbering: numberingInfo,
|
|
139
|
+
asText: labelAsText({
|
|
140
|
+
label,
|
|
141
|
+
template,
|
|
142
|
+
levelFormats: listRendering.levelNumFmts,
|
|
143
|
+
suffix: listRendering.markerSuffix
|
|
144
|
+
}),
|
|
116
145
|
paragraphNumber: stripTrailingPeriods(label.trim()),
|
|
117
146
|
numberOnly: numberOnlyLabel({
|
|
118
147
|
template,
|
|
@@ -53,6 +53,8 @@ export type ResolvedNumbering = {
|
|
|
53
53
|
export type ResolvedPart = {
|
|
54
54
|
block: AnalyzedBlock;
|
|
55
55
|
strippedPrefix: string;
|
|
56
|
+
/** The automatic label written as text before the part, or null. */
|
|
57
|
+
labelAsText: string | null;
|
|
56
58
|
};
|
|
57
59
|
export type ResolvedParagraph = {
|
|
58
60
|
parts: ResolvedPart[];
|
|
@@ -300,6 +300,21 @@ const piecesContent = (pieces) => {
|
|
|
300
300
|
signatures
|
|
301
301
|
};
|
|
302
302
|
};
|
|
303
|
+
const plainPiece = (kind, text) => ({
|
|
304
|
+
kind,
|
|
305
|
+
text,
|
|
306
|
+
signature: "",
|
|
307
|
+
link: null,
|
|
308
|
+
atom: null,
|
|
309
|
+
origin: "document"
|
|
310
|
+
});
|
|
311
|
+
/** A label written as text: the label, then what its list puts after it. */
|
|
312
|
+
const labelPieces = ({ label, suffix }) => {
|
|
313
|
+
const pieces = [plainPiece("text", label)];
|
|
314
|
+
if (suffix === "tab") pieces.push(plainPiece("tab", " "));
|
|
315
|
+
else if (suffix === "space") pieces.push(plainPiece("text", " "));
|
|
316
|
+
return pieces;
|
|
317
|
+
};
|
|
303
318
|
const SHA256 = /^[0-9a-f]{64}$/u;
|
|
304
319
|
const TRANSITIONAL_WORDPROCESSINGML = NAMESPACES.w;
|
|
305
320
|
const groupByBlock = (entries) => {
|
|
@@ -452,7 +467,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
452
467
|
if (Result.isError(resolvedNumbering)) return resolvedNumbering;
|
|
453
468
|
const segments = [];
|
|
454
469
|
const resolvedParts = [];
|
|
455
|
-
for (const [index,
|
|
470
|
+
for (const [index, planned] of parts.entries()) {
|
|
471
|
+
const { block, stripLabel } = planned;
|
|
456
472
|
const { id, text } = block.block;
|
|
457
473
|
if (block.read === null) return invalid(`Block ${id} is a table and cannot be joined or slotted.`);
|
|
458
474
|
const placedOnce = place(block);
|
|
@@ -490,10 +506,24 @@ const resolvePlan = (source, template, plan) => {
|
|
|
490
506
|
piece: separator
|
|
491
507
|
});
|
|
492
508
|
}
|
|
509
|
+
const written = planned.labelAsText ? block.label?.asText ?? null : null;
|
|
510
|
+
if (planned.labelAsText) {
|
|
511
|
+
if (written === null) return Result.err(refuse({
|
|
512
|
+
code: "label-not-writable",
|
|
513
|
+
message: `Block ${id} shows no automatic label that can be written as text.`,
|
|
514
|
+
blockId: id
|
|
515
|
+
}));
|
|
516
|
+
if (stripLabel !== void 0 || index === 0 && resolvedNumbering.value.kind !== "none") return invalid(`Block ${id} takes its label as text and can neither lose a typed label nor join a list.`);
|
|
517
|
+
segments.push(...labelPieces(written).map((piece) => ({
|
|
518
|
+
kind: "piece",
|
|
519
|
+
piece
|
|
520
|
+
})));
|
|
521
|
+
}
|
|
493
522
|
segments.push(...part.value);
|
|
494
523
|
resolvedParts.push({
|
|
495
524
|
block,
|
|
496
|
-
strippedPrefix
|
|
525
|
+
strippedPrefix,
|
|
526
|
+
labelAsText: written?.label ?? null
|
|
497
527
|
});
|
|
498
528
|
}
|
|
499
529
|
const pieces = segmentPieces(segments);
|
|
@@ -529,7 +559,7 @@ const resolvePlan = (source, template, plan) => {
|
|
|
529
559
|
};
|
|
530
560
|
const resolveTable = (block, item, tableOrdinal) => {
|
|
531
561
|
const { id } = block.block;
|
|
532
|
-
if (item.mergeNext !== void 0 || item.stripLabel !== void 0 || item.numbering !== void 0) return invalid(`Table ${id} takes a style and nested placements only.`);
|
|
562
|
+
if (item.mergeNext !== void 0 || item.stripLabel !== void 0 || item.labelAsText !== void 0 || item.numbering !== void 0) return invalid(`Table ${id} takes a style and nested placements only.`);
|
|
533
563
|
if (item.styleId !== void 0 && template.styles.get(item.styleId)?.type !== "table") return Result.err(refuse({
|
|
534
564
|
code: "style-unknown",
|
|
535
565
|
message: `The template has no table style ${item.styleId}.`,
|
|
@@ -551,7 +581,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
551
581
|
const paragraph = resolveParagraph({
|
|
552
582
|
parts: [{
|
|
553
583
|
block: nested,
|
|
554
|
-
stripLabel: override?.stripLabel
|
|
584
|
+
stripLabel: override?.stripLabel,
|
|
585
|
+
labelAsText: override?.labelAsText === true
|
|
555
586
|
}],
|
|
556
587
|
separators: [],
|
|
557
588
|
styleId: override?.styleId ?? item.cellStyleId,
|
|
@@ -624,7 +655,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
624
655
|
}
|
|
625
656
|
const parts = [{
|
|
626
657
|
block: block.value,
|
|
627
|
-
stripLabel: item.stripLabel
|
|
658
|
+
stripLabel: item.stripLabel,
|
|
659
|
+
labelAsText: item.labelAsText === true
|
|
628
660
|
}];
|
|
629
661
|
const separators = [];
|
|
630
662
|
let merge = item.mergeNext;
|
|
@@ -649,7 +681,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
649
681
|
separators.push(merge);
|
|
650
682
|
parts.push({
|
|
651
683
|
block: nextBlock.value,
|
|
652
|
-
stripLabel: next.stripLabel
|
|
684
|
+
stripLabel: next.stripLabel,
|
|
685
|
+
labelAsText: next.labelAsText === true
|
|
653
686
|
});
|
|
654
687
|
merge = next.mergeNext;
|
|
655
688
|
index += 1;
|
|
@@ -688,7 +721,8 @@ const resolvePlan = (source, template, plan) => {
|
|
|
688
721
|
if (Result.isError(block)) return block;
|
|
689
722
|
parts.push({
|
|
690
723
|
block: block.value,
|
|
691
|
-
stripLabel: void 0
|
|
724
|
+
stripLabel: void 0,
|
|
725
|
+
labelAsText: false
|
|
692
726
|
});
|
|
693
727
|
}
|
|
694
728
|
const paragraph = resolveParagraph({
|
|
@@ -29,6 +29,7 @@ const FIELD_KIND = /^[A-Z][A-Z0-9]*$/u;
|
|
|
29
29
|
const MAX_LIST_LEVEL = 8;
|
|
30
30
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31
31
|
const isString = (value) => typeof value === "string";
|
|
32
|
+
const isOptionalBoolean = (value) => value === void 0 || typeof value === "boolean";
|
|
32
33
|
const isOptionalString = (value) => value === void 0 || isString(value);
|
|
33
34
|
const isCount = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
34
35
|
/** A list id a plan may name: the first real one is 1. */
|
|
@@ -70,6 +71,7 @@ const sourceItemIssue = (item, where) => {
|
|
|
70
71
|
"cellStyleId",
|
|
71
72
|
"stripLabel"
|
|
72
73
|
]) if (!isOptionalString(item[key])) return `${where} carries a malformed ${key}.`;
|
|
74
|
+
if (!isOptionalBoolean(item["labelAsText"])) return `${where} carries a malformed labelAsText.`;
|
|
73
75
|
const merge = item["mergeNext"];
|
|
74
76
|
if (merge !== void 0 && !(isString(merge) && MERGES.has(merge))) return `${where} names an unknown merge.`;
|
|
75
77
|
const numbering = numberingIssue(item["numbering"], where);
|
|
@@ -82,7 +84,7 @@ const sourceItemIssue = (item, where) => {
|
|
|
82
84
|
if (!isObject(entry) || !isString(entry["blockId"])) return `${where} carries a nested placement without a block.`;
|
|
83
85
|
if (seen.has(entry["blockId"])) return `${where} places nested block ${entry["blockId"]} twice.`;
|
|
84
86
|
seen.add(entry["blockId"]);
|
|
85
|
-
if (!isOptionalString(entry["styleId"]) || !isOptionalString(entry["stripLabel"])) return `${where} carries a malformed nested placement.`;
|
|
87
|
+
if (!isOptionalString(entry["styleId"]) || !isOptionalString(entry["stripLabel"]) || !isOptionalBoolean(entry["labelAsText"])) return `${where} carries a malformed nested placement.`;
|
|
86
88
|
const nestedNumbering = numberingIssue(entry["numbering"], where);
|
|
87
89
|
if (nestedNumbering !== null) return nestedNumbering;
|
|
88
90
|
}
|
|
@@ -115,6 +117,23 @@ const omitIssue = (omit) => {
|
|
|
115
117
|
for (const entry of omit) if (!isObject(entry) || !isString(entry["blockId"]) || !isString(entry["reason"]) || !OMIT_REASONS.has(entry["reason"])) return "The plan omits a block without an id or for an unknown reason.";
|
|
116
118
|
return null;
|
|
117
119
|
};
|
|
120
|
+
const INDENT_KEYS = /* @__PURE__ */ new Set([
|
|
121
|
+
"left",
|
|
122
|
+
"hanging",
|
|
123
|
+
"firstLine"
|
|
124
|
+
]);
|
|
125
|
+
/** The widest indent a patch may state: the widest page WordprocessingML allows. */
|
|
126
|
+
const MAX_INDENT = 31680;
|
|
127
|
+
/**
|
|
128
|
+
* Whether `value` is a level indent a patch may state: at least one of
|
|
129
|
+
* `left`, `hanging` and `firstLine`, each a whole number of twentieths of a
|
|
130
|
+
* point, and not both a hanging and a first-line indent.
|
|
131
|
+
*/
|
|
132
|
+
const isLevelIndent = (value) => {
|
|
133
|
+
if (!isObject(value)) return false;
|
|
134
|
+
const keys = Object.keys(value);
|
|
135
|
+
return keys.length > 0 && keys.every((key) => INDENT_KEYS.has(key) && isCount(value[key]) && value[key] <= MAX_INDENT) && !(value["hanging"] !== void 0 && value["firstLine"] !== void 0);
|
|
136
|
+
};
|
|
118
137
|
const patchesIssue = (patches) => {
|
|
119
138
|
if (patches === void 0) return null;
|
|
120
139
|
if (!Array.isArray(patches)) return "The plan's numbering patches are malformed.";
|
|
@@ -124,8 +143,8 @@ const patchesIssue = (patches) => {
|
|
|
124
143
|
const key = `${String(patch["abstractNumId"])}:${String(patch["ilvl"])}`;
|
|
125
144
|
if (seen.has(key)) return `Two numbering patches change level ${String(patch["ilvl"])} of list definition ${String(patch["abstractNumId"])}.`;
|
|
126
145
|
seen.add(key);
|
|
127
|
-
const { numFmt, lvlText, start, suff } = patch;
|
|
128
|
-
if (numFmt !== void 0 && !(isString(numFmt) && NUMBER_FORMATS.has(numFmt)) || lvlText !== void 0 && !(isString(lvlText) && isPlainText(lvlText)) || start !== void 0 && !isCount(start) || suff !== void 0 && !(isString(suff) && SUFFIXES.has(suff))) return "A numbering patch carries a malformed value.";
|
|
146
|
+
const { numFmt, lvlText, start, suff, indent } = patch;
|
|
147
|
+
if (numFmt !== void 0 && !(isString(numFmt) && NUMBER_FORMATS.has(numFmt)) || lvlText !== void 0 && !(isString(lvlText) && isPlainText(lvlText)) || start !== void 0 && !isCount(start) || suff !== void 0 && !(isString(suff) && SUFFIXES.has(suff)) || indent !== void 0 && !isLevelIndent(indent)) return "A numbering patch carries a malformed value.";
|
|
129
148
|
}
|
|
130
149
|
return null;
|
|
131
150
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FolioDocxConformanceIssue } from "../validateDocxConformance.js";
|
|
2
2
|
import { TaggedErrorClass } from "better-result";
|
|
3
3
|
/** Why a template plan call stopped; every refusal names one of these. */
|
|
4
|
-
export declare const TEMPLATE_PLAN_ERROR_CODES: readonly ["archive-unreadable", "part-missing", "xml-unreadable", "plan-invalid", "sha-mismatch", "unknown-block", "hash-mismatch", "block-unplaced", "block-placed-twice", "strip-label-mismatch", "merge-invalid", "reference-span-invalid", "reference-target-unplaced", "highlight-span-invalid", "numbering-unknown", "style-unknown", "tracked-changes", "unsupported-content", "verification-failed"];
|
|
4
|
+
export declare const TEMPLATE_PLAN_ERROR_CODES: readonly ["archive-unreadable", "part-missing", "xml-unreadable", "plan-invalid", "sha-mismatch", "unknown-block", "hash-mismatch", "block-unplaced", "block-placed-twice", "strip-label-mismatch", "label-not-writable", "merge-invalid", "reference-span-invalid", "reference-target-unplaced", "highlight-span-invalid", "numbering-unknown", "style-unknown", "tracked-changes", "unsupported-content", "verification-failed"];
|
|
5
5
|
export type TemplatePlanErrorCode = (typeof TEMPLATE_PLAN_ERROR_CODES)[number];
|
|
6
6
|
declare const TemplatePlanErrorBase: TaggedErrorClass<"TemplatePlanError">;
|
|
7
7
|
/** A refused analysis, plan or output. `report` is set for `verification-failed`. */
|
|
@@ -81,6 +81,11 @@ export type DocxTemplateStyle = {
|
|
|
81
81
|
ilvl: number;
|
|
82
82
|
} | null;
|
|
83
83
|
outlineLvl: number | null;
|
|
84
|
+
/**
|
|
85
|
+
* The paragraph alignment the style states (`w:jc`), inheritance resolved;
|
|
86
|
+
* null when neither the style nor one it is based on states one.
|
|
87
|
+
*/
|
|
88
|
+
alignment: string | null;
|
|
84
89
|
isDefault: boolean;
|
|
85
90
|
};
|
|
86
91
|
export type DocxTemplateNumberingLevel = {
|
|
@@ -90,6 +95,12 @@ export type DocxTemplateNumberingLevel = {
|
|
|
90
95
|
start: number;
|
|
91
96
|
suff: "tab" | "space" | "nothing";
|
|
92
97
|
pStyle: string | null;
|
|
98
|
+
/** The level's paragraph indent in twentieths of a point; null where unstated. */
|
|
99
|
+
indent: {
|
|
100
|
+
left: number | null;
|
|
101
|
+
hanging: number | null;
|
|
102
|
+
firstLine: number | null;
|
|
103
|
+
};
|
|
93
104
|
};
|
|
94
105
|
export type DocxTemplateNumbering = {
|
|
95
106
|
abstractNums: {
|
|
@@ -178,6 +189,8 @@ export type TemplatePlanNestedParagraph = {
|
|
|
178
189
|
styleId?: string;
|
|
179
190
|
numbering?: TemplatePlanNumbering | null;
|
|
180
191
|
stripLabel?: string;
|
|
192
|
+
/** As on a source item. */
|
|
193
|
+
labelAsText?: boolean;
|
|
181
194
|
};
|
|
182
195
|
export type TemplatePlanSourceItem = {
|
|
183
196
|
kind: "source";
|
|
@@ -189,6 +202,15 @@ export type TemplatePlanSourceItem = {
|
|
|
189
202
|
numbering?: TemplatePlanNumbering | null;
|
|
190
203
|
/** The manual label at the start of the block to remove, with the space after it. */
|
|
191
204
|
stripLabel?: string;
|
|
205
|
+
/**
|
|
206
|
+
* Write the block's automatic label as text at the start of its text, with
|
|
207
|
+
* the tab or space its list puts after it: for a label no list of the
|
|
208
|
+
* template prints. The paragraph it leads must join no list
|
|
209
|
+
* (`numbering: null`). Only a label that reads the same wherever the file
|
|
210
|
+
* is opened can be written: numbers, letters and roman numerals, not a
|
|
211
|
+
* bullet glyph and not a number a language spells.
|
|
212
|
+
*/
|
|
213
|
+
labelAsText?: boolean;
|
|
192
214
|
/** Join the next item of the plan, a source paragraph, into this paragraph. */
|
|
193
215
|
mergeNext?: TemplatePlanMerge;
|
|
194
216
|
/** Table only: the paragraph style of its cells. */
|
|
@@ -211,6 +233,16 @@ export type TemplatePlanNumberingPatch = {
|
|
|
211
233
|
lvlText?: string;
|
|
212
234
|
start?: number;
|
|
213
235
|
suff?: "tab" | "space" | "nothing";
|
|
236
|
+
/**
|
|
237
|
+
* The paragraph indent the level gives, in twentieths of a point. A value
|
|
238
|
+
* left out keeps what the level states; `hanging` and `firstLine` exclude
|
|
239
|
+
* each other, so stating one drops the other.
|
|
240
|
+
*/
|
|
241
|
+
indent?: {
|
|
242
|
+
left?: number;
|
|
243
|
+
hanging?: number;
|
|
244
|
+
firstLine?: number;
|
|
245
|
+
};
|
|
214
246
|
};
|
|
215
247
|
export type TemplatePlanReference = {
|
|
216
248
|
blockId: string;
|
|
@@ -260,6 +292,8 @@ export type TemplatePlanBlockResult = {
|
|
|
260
292
|
emphasis: "identical" | "mismatch" | "omitted";
|
|
261
293
|
/** What `stripLabel` removed, the following space included. */
|
|
262
294
|
strippedPrefix?: string;
|
|
295
|
+
/** The automatic label `labelAsText` wrote as text, without what follows it. */
|
|
296
|
+
labelAsText?: string;
|
|
263
297
|
/** The label the source showed: its automatic label, else the stripped one. */
|
|
264
298
|
sourceLabel: string | null;
|
|
265
299
|
/** The automatic label the output paragraph renders. */
|
|
@@ -332,8 +366,10 @@ export type TemplatePlanReport = {
|
|
|
332
366
|
emphasisMismatch: number;
|
|
333
367
|
/** Placed blocks whose source label and output label differ. */
|
|
334
368
|
labelChanged: number;
|
|
335
|
-
/** Placed blocks that showed a label in the source and
|
|
369
|
+
/** Placed blocks that showed a label in the source and show none: neither rendered nor written as text. */
|
|
336
370
|
labelLost: number;
|
|
371
|
+
/** Placed blocks whose automatic label is written as text. */
|
|
372
|
+
labelAsText: number;
|
|
337
373
|
};
|
|
338
374
|
footnotes: TemplatePlanNoteCounts;
|
|
339
375
|
endnotes: TemplatePlanNoteCounts;
|
|
@@ -11,7 +11,7 @@ import { guarded, readPartText } from "./package.js";
|
|
|
11
11
|
import { hyperlinkFieldLink, paragraphPieces, piecesContent, resolvePlan, segmentPieces } from "./plan.js";
|
|
12
12
|
import { objectFingerprint, objectTargets, readStoryResources, relationshipIdsOf } from "./resources.js";
|
|
13
13
|
import { createStoryState, endStory, readParagraph, walkBlocks } from "./story.js";
|
|
14
|
-
import { integerOrNull, isW, readRawPart, wAttr, wChild, wChildVal, wChildren, wName, walkElements } from "./xml.js";
|
|
14
|
+
import { integerOrNull, isW, readRawPart, twipsOrNull, wAttr, wChild, wChildVal, wChildren, wName, walkElements } from "./xml.js";
|
|
15
15
|
import { Result } from "better-result";
|
|
16
16
|
// src/docx/server/templatePlan/verify.ts
|
|
17
17
|
/**
|
|
@@ -599,6 +599,9 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
|
|
|
599
599
|
lvlText: patch.lvlText
|
|
600
600
|
};
|
|
601
601
|
for (const [name, value] of Object.entries(planned)) if (value !== void 0 && wChildVal(level, name) !== value) numberingMismatch(`Level ${patch.ilvl} of list definition ${patch.abstractNumId} does not carry the planned ${name}.`);
|
|
602
|
+
const indent = wChild(wChild(level, "pPr"), "ind");
|
|
603
|
+
for (const [name, value] of Object.entries(patch.indent ?? {})) if (twipsOrNull(wAttr(indent, name)) !== value) numberingMismatch(`Level ${patch.ilvl} of list definition ${patch.abstractNumId} does not carry the planned ${name} indent.`);
|
|
604
|
+
for (const [stated, other] of [["hanging", "firstLine"], ["firstLine", "hanging"]]) if (patch.indent?.[stated] !== void 0 && wAttr(indent, other) !== null) numberingMismatch(`Level ${patch.ilvl} of list definition ${patch.abstractNumId} keeps a ${other} indent beside the planned ${stated} one.`);
|
|
602
605
|
}
|
|
603
606
|
const bookmarkNames = /* @__PURE__ */ new Map();
|
|
604
607
|
const bump = (map, key) => {
|
|
@@ -777,7 +780,8 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
|
|
|
777
780
|
textMismatch: 0,
|
|
778
781
|
emphasisMismatch: 0,
|
|
779
782
|
labelChanged: 0,
|
|
780
|
-
labelLost: 0
|
|
783
|
+
labelLost: 0,
|
|
784
|
+
labelAsText: 0
|
|
781
785
|
};
|
|
782
786
|
const tables = /* @__PURE__ */ new Map();
|
|
783
787
|
for (const block of source.story.order) {
|
|
@@ -831,7 +835,9 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
|
|
|
831
835
|
if (text === "identical") counts.textIdentical += 1;
|
|
832
836
|
else counts.textMismatch += 1;
|
|
833
837
|
if (emphasis === "mismatch") counts.emphasisMismatch += 1;
|
|
834
|
-
|
|
838
|
+
const labelAsText = part?.labelAsText ?? null;
|
|
839
|
+
if (labelAsText !== null) counts.labelAsText += 1;
|
|
840
|
+
else if (sourceLabel !== null && outputLabel === null) counts.labelLost += 1;
|
|
835
841
|
else if (sourceLabel !== null && outputLabel !== null && sourceLabel.trim() !== outputLabel.trim()) counts.labelChanged += 1;
|
|
836
842
|
let tableId = block.parentId;
|
|
837
843
|
while (tableId !== null) {
|
|
@@ -847,11 +853,13 @@ const reportTemplatePlanOutput = async ({ source, template, output, plan, resolv
|
|
|
847
853
|
text,
|
|
848
854
|
emphasis,
|
|
849
855
|
...part === void 0 || part.strippedPrefix === "" ? {} : { strippedPrefix: part.strippedPrefix },
|
|
856
|
+
...labelAsText === null ? {} : { labelAsText },
|
|
850
857
|
sourceLabel,
|
|
851
858
|
outputLabel
|
|
852
859
|
});
|
|
853
860
|
}
|
|
854
861
|
if (counts.labelLost > 0) warnings.push(`${counts.labelLost} block(s) showed a number or label in the source and render none.`);
|
|
862
|
+
if (counts.labelAsText > 0) warnings.push(`${counts.labelAsText} block(s) carry their automatic number as text.`);
|
|
855
863
|
if (counts.labelChanged > 0) warnings.push(`${counts.labelChanged} block(s) render a label that differs from the source's.`);
|
|
856
864
|
const placedReads = resolvedParagraphs.flatMap(({ parts }) => parts.flatMap(({ block }) => block.read === null ? [] : [block.read]));
|
|
857
865
|
const droppedFields = /* @__PURE__ */ new Map();
|