@stll/folio-core 0.75.0 → 0.77.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.d.ts +8 -5
- package/dist/ai-edits/headless.js +49 -26
- package/dist/ai-edits/pending-suggestions.d.ts +9 -0
- package/dist/ai-edits/pending-suggestions.js +13 -3
- package/dist/ai-edits/read.js +33 -4
- package/dist/ai-edits/table-geometry.js +12 -4
- package/dist/ai-edits/types.d.ts +9 -4
- package/dist/canonical/batchCommentReferences.js +2 -1
- package/dist/canonical/canonicalBatchReview.js +5 -8
- package/dist/canonical/canonicalComments.js +8 -2
- package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
- package/dist/canonical/canonicalCompilerRefusal.js +20 -14
- package/dist/canonical/canonicalInlineProjection.d.ts +2 -2
- package/dist/canonical/canonicalInlineProjection.js +2 -2
- package/dist/canonical/canonicalProjectionBlocks.d.ts +10 -1
- package/dist/canonical/canonicalPublicOperations.js +214 -107
- package/dist/canonical/canonicalSeedContent.d.ts +18 -3
- package/dist/canonical/canonicalSeedContent.js +28 -15
- package/dist/canonical/canonicalSession.d.ts +22 -12
- package/dist/canonical/canonicalSession.js +181 -187
- package/dist/controller/canonicalClipboard.d.ts +3 -2
- package/dist/controller/canonicalClipboard.js +377 -58
- package/dist/controller/canonicalComposition.js +67 -14
- package/dist/controller/canonicalContentControlValue.js +7 -7
- package/dist/controller/canonicalReview.d.ts +21 -0
- package/dist/controller/canonicalReview.js +44 -9
- package/dist/controller/canonicalStoryEditor.js +2 -0
- package/dist/controller/canonicalStructure.d.ts +1 -2
- package/dist/controller/canonicalStructure.js +51 -24
- package/dist/controller/fontReadiness.js +50 -23
- package/dist/controller/hiddenEditorManager.js +7 -20
- package/dist/docx/bulletMarkers.d.ts +8 -0
- package/dist/docx/bulletMarkers.js +9 -1
- 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/importedIdCollisions.js +29 -4
- package/dist/docx/server/templatePlan/apply.js +108 -9
- package/dist/docx/server/templatePlan/blocks.d.ts +77 -5
- package/dist/docx/server/templatePlan/blocks.js +281 -14
- package/dist/docx/server/templatePlan/builders.d.ts +22 -1
- package/dist/docx/server/templatePlan/builders.js +37 -3
- 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 +152 -8
- package/dist/docx/server/templatePlan/inspect.js +21 -1
- package/dist/docx/server/templatePlan/labels.js +16 -1
- package/dist/docx/server/templatePlan/plan.d.ts +35 -3
- package/dist/docx/server/templatePlan/plan.js +197 -20
- package/dist/docx/server/templatePlan/planShape.js +58 -22
- package/dist/docx/server/templatePlan/revisions.d.ts +101 -0
- package/dist/docx/server/templatePlan/revisions.js +681 -0
- package/dist/docx/server/templatePlan/story.d.ts +61 -2
- package/dist/docx/server/templatePlan/story.js +175 -13
- package/dist/docx/server/templatePlan/types.d.ts +313 -1
- package/dist/docx/server/templatePlan/verify.js +175 -12
- package/dist/docx/server/templatePlan/xml.d.ts +3 -0
- package/dist/docx/server/templatePlan/xml.js +4 -1
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
- package/dist/docx/tableGridXml.d.ts +3 -7
- package/dist/docx/tableGridXml.js +5 -13
- package/dist/layout-bridge/convert/footnoteLayout.js +34 -8
- package/dist/prosemirror/canonicalMarkupDocument.d.ts +20 -0
- package/dist/prosemirror/canonicalMarkupDocument.js +73 -0
- package/dist/prosemirror/canonicalTableCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +1 -3
- 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/conversion/markupViewSource.d.ts +17 -0
- package/dist/prosemirror/conversion/markupViewSource.js +11 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +3 -0
- package/dist/prosemirror/conversion/toProseDoc.js +31 -14
- 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/independentMarkupProjection.d.ts +27 -0
- package/dist/prosemirror/independentMarkupProjection.js +147 -0
- package/dist/prosemirror/markupViewNotes.d.ts +1 -1
- package/dist/prosemirror/markupViewNotes.js +24 -27
- package/dist/prosemirror/markupViewPositionMap.d.ts +16 -0
- package/dist/prosemirror/markupViewPositionMap.js +316 -0
- package/dist/prosemirror/markupViewProjection.d.ts +3 -46
- package/dist/prosemirror/markupViewProjection.js +90 -17
- 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 +6 -83
- package/dist/prosemirror/replacedAnnotations.js +11 -203
- 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/styles/styleResolver.d.ts +1 -0
- package/dist/prosemirror/styles/styleResolver.js +4 -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 +4 -35
- package/dist/types/canonicalCapabilities.js +4 -33
- package/package.json +2 -2
- package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
- package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
- package/dist/internal/revisionResolutionEdits.d.ts +0 -11
- package/dist/internal/revisionResolutionEdits.js +0 -18
- package/dist/internal/revisionResolutionInline.d.ts +0 -24
- package/dist/internal/revisionResolutionInline.js +0 -302
- package/dist/internal/revisionResolutionStep.d.ts +0 -32
- package/dist/internal/revisionResolutionStep.js +0 -282
- package/dist/internal/revisionResolutionTracking.d.ts +0 -9
- package/dist/internal/revisionResolutionTracking.js +0 -124
- package/dist/internal/wholeStoryRevisionResolution.d.ts +0 -56
- package/dist/internal/wholeStoryRevisionResolution.js +0 -783
- package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +0 -38
- package/dist/prosemirror/commands/resolveAllTableChanges.js +0 -642
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +0 -13
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +0 -45
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +0 -18
- package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -207
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +0 -60
- package/dist/prosemirror/commands/tableMergeFoldDecisions.js +0 -78
- package/dist/prosemirror/rejoinRunCarriers.d.ts +0 -42
- package/dist/prosemirror/rejoinRunCarriers.js +0 -65
- package/dist/prosemirror/runPropertyChangeResolution.d.ts +0 -15
- package/dist/prosemirror/runPropertyChangeResolution.js +0 -34
|
@@ -5,9 +5,10 @@ import { keepsShiftReturnSpacing } from "./builders.js";
|
|
|
5
5
|
import { defaultsBaseline } from "./emphasis.js";
|
|
6
6
|
import { createLabelCounter } from "./labels.js";
|
|
7
7
|
import { guarded, loadPackage, readPartText, sha256Hex } from "./package.js";
|
|
8
|
-
import {
|
|
8
|
+
import { keptRevisionObstacles, resolveTrackedChanges, withDeletedMarksJoined } from "./revisions.js";
|
|
9
|
+
import { createStoryState, endStory, readParagraph, toggleOf, walkBlocks } from "./story.js";
|
|
9
10
|
import { TemplatePlanError } from "./types.js";
|
|
10
|
-
import { elementChildren, isW, readRawPart, wAttr, wChild, wChildVal, wChildren } from "./xml.js";
|
|
11
|
+
import { elementChildren, halfPointsOrNull, integerOrNull, isW, readRawPart, twipsOrNull, wAttr, wChild, wChildVal, wChildren } from "./xml.js";
|
|
11
12
|
import { Result } from "better-result";
|
|
12
13
|
// src/docx/server/templatePlan/blocks.ts
|
|
13
14
|
/** The block manifest of a DOCX: its main story as addressable, hash-pinned blocks. */
|
|
@@ -39,6 +40,65 @@ const sectionOf = (sectPr, index) => {
|
|
|
39
40
|
columns: properties.columnCount ?? 1
|
|
40
41
|
};
|
|
41
42
|
};
|
|
43
|
+
const NO_INDENT = {
|
|
44
|
+
left: null,
|
|
45
|
+
firstLine: null
|
|
46
|
+
};
|
|
47
|
+
const levelKey = (abstractNumId, ilvl) => `${String(abstractNumId)}:${String(ilvl)}`;
|
|
48
|
+
/** The sides a `w:ind` states; a hanging indent is a negative first line. */
|
|
49
|
+
const statedIndent = (indent) => {
|
|
50
|
+
const hanging = twipsOrNull(wAttr(indent, "hanging"));
|
|
51
|
+
return {
|
|
52
|
+
left: twipsOrNull(wAttr(indent, "left") ?? wAttr(indent, "start")),
|
|
53
|
+
firstLine: hanging === null ? twipsOrNull(wAttr(indent, "firstLine")) : -hanging
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The indent each level of a numbering part states, by list definition and
|
|
58
|
+
* level, read off the part itself. An override a list instance makes of a
|
|
59
|
+
* level is not followed.
|
|
60
|
+
*/
|
|
61
|
+
const statedLevelIndents = (numberingPath, numberingXml) => {
|
|
62
|
+
const indents = /* @__PURE__ */ new Map();
|
|
63
|
+
const part = numberingPath === null || numberingXml === null ? null : readRawPart(numberingPath, numberingXml);
|
|
64
|
+
for (const definition of wChildren(part?.root, "abstractNum")) {
|
|
65
|
+
const abstractNumId = integerOrNull(wAttr(definition, "abstractNumId"));
|
|
66
|
+
for (const level of wChildren(definition, "lvl")) {
|
|
67
|
+
const ilvl = integerOrNull(wAttr(level, "ilvl"));
|
|
68
|
+
if (abstractNumId !== null && ilvl !== null) indents.set(levelKey(abstractNumId, ilvl), statedIndent(wChild(wChild(level, "pPr"), "ind")));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return indents;
|
|
72
|
+
};
|
|
73
|
+
/** The indent the document's defaults give every paragraph. */
|
|
74
|
+
const statedDefaultIndent = (stylesPath, stylesXml) => {
|
|
75
|
+
const part = stylesPath === null || stylesXml === null ? null : readRawPart(stylesPath, stylesXml);
|
|
76
|
+
const defaults = wChild(wChild(part?.root, "docDefaults"), "pPrDefault");
|
|
77
|
+
return statedIndent(wChild(wChild(defaults, "pPr"), "ind"));
|
|
78
|
+
};
|
|
79
|
+
/** The sides a style states, as the document model holds them: a hanging
|
|
80
|
+
* indent is a negative first line. */
|
|
81
|
+
const modelIndent = (formatting) => {
|
|
82
|
+
const first = formatting?.indentFirstLine;
|
|
83
|
+
let firstLine = null;
|
|
84
|
+
if (first !== void 0) firstLine = formatting?.hangingIndent === true ? -Math.abs(first) : first;
|
|
85
|
+
return {
|
|
86
|
+
left: formatting?.indentLeft ?? null,
|
|
87
|
+
firstLine
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* The indent in effect: each side from the first of `sources` that states
|
|
92
|
+
* it. Null when none of them states a side.
|
|
93
|
+
*/
|
|
94
|
+
const indentInEffect = (...sources) => {
|
|
95
|
+
const left = sources.find((source) => source.left !== null)?.left ?? null;
|
|
96
|
+
const firstLine = sources.find((source) => source.firstLine !== null)?.firstLine ?? null;
|
|
97
|
+
return left === null && firstLine === null ? null : {
|
|
98
|
+
left: left ?? 0,
|
|
99
|
+
firstLine: firstLine ?? 0
|
|
100
|
+
};
|
|
101
|
+
};
|
|
42
102
|
/** The alignment each style of a styles part states for itself (`w:jc`). */
|
|
43
103
|
const statedAlignments = (stylesPath, stylesXml) => {
|
|
44
104
|
const alignments = /* @__PURE__ */ new Map();
|
|
@@ -62,6 +122,59 @@ const styleAlignment = (styleId, styles, stated) => {
|
|
|
62
122
|
}
|
|
63
123
|
return null;
|
|
64
124
|
};
|
|
125
|
+
const statedLook = (paragraph, run) => ({
|
|
126
|
+
bold: toggleOf(wChild(run, "b")),
|
|
127
|
+
size: halfPointsOrNull(wChildVal(run, "sz")),
|
|
128
|
+
keepNext: toggleOf(wChild(paragraph, "keepNext")),
|
|
129
|
+
indentLeft: twipsOrNull(wAttr(wChild(paragraph, "ind"), "left") ?? wAttr(wChild(paragraph, "ind"), "start"))
|
|
130
|
+
});
|
|
131
|
+
/** The look each style of the styles part states itself, by style id, and
|
|
132
|
+
* the look the document's defaults state. */
|
|
133
|
+
const statedLooks = (stylesPath, stylesXml) => {
|
|
134
|
+
const styles = /* @__PURE__ */ new Map();
|
|
135
|
+
const part = stylesPath === null || stylesXml === null ? null : readRawPart(stylesPath, stylesXml);
|
|
136
|
+
for (const style of wChildren(part?.root, "style")) {
|
|
137
|
+
const styleId = wAttr(style, "styleId");
|
|
138
|
+
if (styleId !== null) styles.set(styleId, statedLook(wChild(style, "pPr"), wChild(style, "rPr")));
|
|
139
|
+
}
|
|
140
|
+
const defaults = wChild(part?.root, "docDefaults");
|
|
141
|
+
return {
|
|
142
|
+
styles,
|
|
143
|
+
defaults: statedLook(wChild(wChild(defaults, "pPrDefault"), "pPr"), wChild(wChild(defaults, "rPrDefault"), "rPr"))
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* The look a style gives its text: each property from the nearest style in
|
|
148
|
+
* the `basedOn` chain that states it, then from the document's defaults.
|
|
149
|
+
* Without a statement text is not bold and a paragraph is not kept with the
|
|
150
|
+
* next; the size and the left indent stay null, which leaves the size to
|
|
151
|
+
* the application and the indent to a list level, if the style has one.
|
|
152
|
+
*/
|
|
153
|
+
const styleLook = (styleId, styles, { styles: stated, defaults }) => {
|
|
154
|
+
const look = {
|
|
155
|
+
bold: null,
|
|
156
|
+
size: null,
|
|
157
|
+
keepNext: null,
|
|
158
|
+
indentLeft: null
|
|
159
|
+
};
|
|
160
|
+
const seen = /* @__PURE__ */ new Set();
|
|
161
|
+
let cursor = styleId ?? void 0;
|
|
162
|
+
while (cursor !== void 0 && !seen.has(cursor)) {
|
|
163
|
+
seen.add(cursor);
|
|
164
|
+
const own = stated.get(cursor);
|
|
165
|
+
look.bold ??= own?.bold ?? null;
|
|
166
|
+
look.size ??= own?.size ?? null;
|
|
167
|
+
look.keepNext ??= own?.keepNext ?? null;
|
|
168
|
+
look.indentLeft ??= own?.indentLeft ?? null;
|
|
169
|
+
cursor = styles.get(cursor)?.basedOn;
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
bold: look.bold ?? defaults.bold ?? false,
|
|
173
|
+
size: look.size ?? defaults.size,
|
|
174
|
+
keepNext: look.keepNext ?? defaults.keepNext ?? false,
|
|
175
|
+
indentLeft: look.indentLeft ?? defaults.indentLeft
|
|
176
|
+
};
|
|
177
|
+
};
|
|
65
178
|
/**
|
|
66
179
|
* The sections of a story with what each states. A body without section
|
|
67
180
|
* properties of its own still ends in a section, which states nothing.
|
|
@@ -87,9 +200,48 @@ const storySections = ({ sections, hasBodySection }) => {
|
|
|
87
200
|
};
|
|
88
201
|
/** Page breaks among a paragraph's runs; a column break is not one. */
|
|
89
202
|
const pageBreaksOf = ({ atoms }) => atoms.filter(({ kind, element }) => kind === "pageBreak" && wAttr(element, "type") === "page").length;
|
|
203
|
+
/** Where in a paragraph's text its self-numbering fields stand. */
|
|
204
|
+
const selfNumbersOf = ({ atoms }) => {
|
|
205
|
+
const offsets = [];
|
|
206
|
+
let at = 0;
|
|
207
|
+
for (const { kind, text } of atoms) {
|
|
208
|
+
if (kind === "selfNumber") offsets.push(at);
|
|
209
|
+
at += text.length;
|
|
210
|
+
}
|
|
211
|
+
return offsets;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* The tracked changes a paragraph read with them kept holds, by where they
|
|
215
|
+
* sit in its text. Neighbouring pieces of one change are one entry.
|
|
216
|
+
*/
|
|
217
|
+
const revisionsOf = ({ atoms }) => {
|
|
218
|
+
const found = [];
|
|
219
|
+
let at = 0;
|
|
220
|
+
for (const { text, revision } of atoms) {
|
|
221
|
+
const start = at;
|
|
222
|
+
at += text.length;
|
|
223
|
+
if (revision === void 0) continue;
|
|
224
|
+
const kind = revision.kind === "ins" ? "insertion" : "deletion";
|
|
225
|
+
const paragraphMark = revision.mark === true || revision.deleted === "";
|
|
226
|
+
const last = found.at(-1);
|
|
227
|
+
if (last !== void 0 && !paragraphMark && last.paragraphMark === void 0 && last.kind === kind && last.end === start && last.author === revision.author && last.date === revision.date) {
|
|
228
|
+
last.end = at;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
found.push({
|
|
232
|
+
kind,
|
|
233
|
+
start,
|
|
234
|
+
end: at,
|
|
235
|
+
author: revision.author,
|
|
236
|
+
date: revision.date,
|
|
237
|
+
...paragraphMark ? { paragraphMark: true } : {}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
return found;
|
|
241
|
+
};
|
|
90
242
|
/** Read the blocks under `container` into ids, text, labels and hashes. */
|
|
91
|
-
const analyzeStory = ({ container, resources, counter = createLabelCounter(resources) }) => {
|
|
92
|
-
const state = createStoryState();
|
|
243
|
+
const analyzeStory = ({ container, resources, counter = createLabelCounter(resources), keepsRevisions = false }) => {
|
|
244
|
+
const state = createStoryState({ keepsRevisions });
|
|
93
245
|
const story = {
|
|
94
246
|
topLevel: [],
|
|
95
247
|
order: [],
|
|
@@ -147,10 +299,24 @@ const analyzeStory = ({ container, resources, counter = createLabelCounter(resou
|
|
|
147
299
|
};
|
|
148
300
|
const pageBreaks = pageBreaksOf(read);
|
|
149
301
|
if (pageBreaks > 0) block.pageBreaks = pageBreaks;
|
|
302
|
+
const selfNumbers = selfNumbersOf(read);
|
|
303
|
+
if (selfNumbers.length > 0) block.selfNumbers = selfNumbers;
|
|
304
|
+
const revisions = revisionsOf(read);
|
|
305
|
+
if (revisions.length > 0) block.revisions = revisions;
|
|
150
306
|
if (read.pageBreakBefore ?? style?.pPr?.pageBreakBefore === true) block.pageBreakBefore = true;
|
|
151
307
|
if (read.hasSectionBreak) block.endsSection = true;
|
|
152
308
|
const alignment = read.alignment ?? (resources.alignments === void 0 ? null : styleAlignment(styleId ?? resources.defaultStyleId, resources.styles, resources.alignments));
|
|
153
309
|
if (alignment !== null) block.alignment = alignment;
|
|
310
|
+
const { before, after } = read.spacing;
|
|
311
|
+
if (before !== null || after !== null) block.spacing = {
|
|
312
|
+
...before === null ? {} : { before },
|
|
313
|
+
...after === null ? {} : { after }
|
|
314
|
+
};
|
|
315
|
+
const ofLevel = (label.numbering === null ? void 0 : resources.levelIndents?.get(levelKey(label.numbering.abstractNumId, label.numbering.ilvl))) ?? NO_INDENT;
|
|
316
|
+
const ofStyle = modelIndent(style?.pPr);
|
|
317
|
+
const ofDefaults = resources.defaultIndent ?? NO_INDENT;
|
|
318
|
+
const indent = read.numPr === void 0 ? indentInEffect(read.indent, ofStyle, ofLevel, ofDefaults) : indentInEffect(read.indent, ofLevel, ofStyle, ofDefaults);
|
|
319
|
+
if (indent !== null && !read.indentInCharacters) block.indent = indent;
|
|
154
320
|
index += 1;
|
|
155
321
|
const analyzed = {
|
|
156
322
|
block,
|
|
@@ -259,7 +425,7 @@ const NOTE_ELEMENT = {
|
|
|
259
425
|
footnotes: "footnote",
|
|
260
426
|
endnotes: "endnote"
|
|
261
427
|
};
|
|
262
|
-
const analyzeNotes = (kind, path, xml) => {
|
|
428
|
+
const analyzeNotes = (kind, path, xml, keepsRevisions = false) => {
|
|
263
429
|
const notes = {
|
|
264
430
|
kind,
|
|
265
431
|
path,
|
|
@@ -267,7 +433,7 @@ const analyzeNotes = (kind, path, xml) => {
|
|
|
267
433
|
notes: [],
|
|
268
434
|
byId: /* @__PURE__ */ new Map(),
|
|
269
435
|
usedIds: [],
|
|
270
|
-
state: createStoryState()
|
|
436
|
+
state: createStoryState({ keepsRevisions })
|
|
271
437
|
};
|
|
272
438
|
if (path === null || xml === null) return notes;
|
|
273
439
|
const part = readRawPart(path, xml);
|
|
@@ -325,7 +491,7 @@ const countComments = (xml) => {
|
|
|
325
491
|
return part === null ? 0 : elementChildren(part.root).filter(({ name }) => (name ?? "").endsWith("comment")).length;
|
|
326
492
|
};
|
|
327
493
|
/** Open a package and analyse its main story, notes, styles and numbering. */
|
|
328
|
-
const analyzeDocument = async (bytes) => {
|
|
494
|
+
const analyzeDocument = async (bytes, { keepsRevisions = false } = {}) => {
|
|
329
495
|
const loaded = await loadPackage(bytes);
|
|
330
496
|
if (Result.isError(loaded)) return loaded;
|
|
331
497
|
const pkg = loaded.value;
|
|
@@ -386,11 +552,14 @@ const analyzeDocument = async (bytes) => {
|
|
|
386
552
|
defaultStyleId,
|
|
387
553
|
defaultLanguage: stylesPackage?.styleDefinitions.docDefaults?.rPr?.language?.val ?? null,
|
|
388
554
|
numbering,
|
|
389
|
-
alignments: statedAlignments(stylesPath, stylesXml)
|
|
390
|
-
|
|
555
|
+
alignments: statedAlignments(stylesPath, stylesXml),
|
|
556
|
+
levelIndents: statedLevelIndents(numberingPath, numberingXml),
|
|
557
|
+
defaultIndent: statedDefaultIndent(stylesPath, stylesXml)
|
|
558
|
+
},
|
|
559
|
+
keepsRevisions
|
|
391
560
|
}),
|
|
392
|
-
footnotes: analyzeNotes("footnotes", footnotesPath, footnotesXml),
|
|
393
|
-
endnotes: analyzeNotes("endnotes", endnotesPath, endnotesXml)
|
|
561
|
+
footnotes: analyzeNotes("footnotes", footnotesPath, footnotesXml, keepsRevisions),
|
|
562
|
+
endnotes: analyzeNotes("endnotes", endnotesPath, endnotesXml, keepsRevisions)
|
|
394
563
|
};
|
|
395
564
|
},
|
|
396
565
|
catch: (cause) => cause instanceof TemplatePlanError ? cause : new TemplatePlanError({
|
|
@@ -433,9 +602,107 @@ const analyzeDocument = async (bytes) => {
|
|
|
433
602
|
manifest
|
|
434
603
|
});
|
|
435
604
|
};
|
|
605
|
+
/** The view a plan states, when what was handed in is shaped like a plan
|
|
606
|
+
* at all; its shape is checked where the plan is resolved. */
|
|
607
|
+
const viewOf = (plan) => {
|
|
608
|
+
const view = typeof plan === "object" && plan !== null && "trackedChanges" in plan ? plan.trackedChanges : void 0;
|
|
609
|
+
return view === "accept" || view === "reject" || view === "keep" ? view : void 0;
|
|
610
|
+
};
|
|
611
|
+
/**
|
|
612
|
+
* A source read with its tracked changes kept: the blocks are those of the
|
|
613
|
+
* accepted view, and the atoms of an insertion or a deletion carry its tag,
|
|
614
|
+
* a paragraph mark's among them; an inserted table row keeps its record and
|
|
615
|
+
* a deleted one is set aside whole. A change that is not carried yet (a
|
|
616
|
+
* table cell, a move) or cannot be tagged is refused with what stands in the
|
|
617
|
+
* way, for the caller to offer one view instead.
|
|
618
|
+
*/
|
|
619
|
+
/**
|
|
620
|
+
* A document read with its tracked changes kept, source or output alike:
|
|
621
|
+
* deleted paragraph marks carried as deletions inside the joined paragraph,
|
|
622
|
+
* inline insertions and deletions as tagged atoms. The manifest keeps the
|
|
623
|
+
* hash of the bytes that were given.
|
|
624
|
+
*/
|
|
625
|
+
const analyzeKeptForm = async (bytes) => {
|
|
626
|
+
const joined = await withDeletedMarksJoined(bytes);
|
|
627
|
+
if (Result.isError(joined)) return joined;
|
|
628
|
+
const analyzed = await analyzeDocument(joined.value, { keepsRevisions: true });
|
|
629
|
+
if (Result.isError(analyzed)) return analyzed;
|
|
630
|
+
return Result.ok({
|
|
631
|
+
...analyzed.value,
|
|
632
|
+
manifest: {
|
|
633
|
+
...analyzed.value.manifest,
|
|
634
|
+
sha256: sha256Hex(bytes)
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
};
|
|
638
|
+
const analyzeKeeping = async (bytes) => {
|
|
639
|
+
const obstacles = await keptRevisionObstacles(bytes);
|
|
640
|
+
if (Result.isError(obstacles)) return obstacles;
|
|
641
|
+
const analyzed = await analyzeKeptForm(bytes);
|
|
642
|
+
if (Result.isError(analyzed)) return analyzed;
|
|
643
|
+
const { story, footnotes, endnotes, manifest } = analyzed.value;
|
|
644
|
+
const untagged = story.state.untaggedRevisions + footnotes.state.untaggedRevisions + endnotes.state.untaggedRevisions;
|
|
645
|
+
const { tableCells, moves } = obstacles.value.obstacles;
|
|
646
|
+
const found = [
|
|
647
|
+
[tableCells, "table cell change(s)"],
|
|
648
|
+
[moves, "move(s)"],
|
|
649
|
+
[untagged, "change(s) inside another change, a drawing or an equation, or deleted paragraph mark(s) with no paragraph to join"]
|
|
650
|
+
].flatMap(([count, what]) => typeof count === "number" && count > 0 ? [`${String(count)} ${what}`] : []);
|
|
651
|
+
if (found.length > 0) return Result.err(new TemplatePlanError({
|
|
652
|
+
code: "tracked-changes",
|
|
653
|
+
message: `The tracked changes of the source cannot be kept: ${found.join(", ")}. Format one view of it instead.`
|
|
654
|
+
}));
|
|
655
|
+
return Result.ok({
|
|
656
|
+
...analyzed.value,
|
|
657
|
+
manifest: {
|
|
658
|
+
...manifest,
|
|
659
|
+
trackedChangesKept: obstacles.value.tracked
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
};
|
|
663
|
+
/**
|
|
664
|
+
* Analyse a source in the view a caller chose of its tracked changes, or
|
|
665
|
+
* as it stands. In a view, the package that is analysed is the resolved
|
|
666
|
+
* one, while the manifest keeps the hash of the bytes that were given: a
|
|
667
|
+
* plan pins the file, not a rewriting of it. Without a view, a document
|
|
668
|
+
* that tracks changes says what it tracks.
|
|
669
|
+
*/
|
|
670
|
+
const analyzeSource = async (bytes, view) => {
|
|
671
|
+
if (view === "keep") return await analyzeKeeping(bytes);
|
|
672
|
+
if (view === void 0) {
|
|
673
|
+
const analyzed = await analyzeDocument(bytes);
|
|
674
|
+
if (Result.isError(analyzed) || analyzed.value.manifest.trackedChanges === 0) return analyzed;
|
|
675
|
+
const tracked = await resolveTrackedChanges(bytes, "accept");
|
|
676
|
+
return Result.isError(tracked) ? analyzed : Result.ok({
|
|
677
|
+
...analyzed.value,
|
|
678
|
+
manifest: {
|
|
679
|
+
...analyzed.value.manifest,
|
|
680
|
+
revisions: tracked.value.resolved
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
const resolved = await resolveTrackedChanges(bytes, view);
|
|
685
|
+
if (Result.isError(resolved)) return resolved;
|
|
686
|
+
const analyzed = await analyzeDocument(resolved.value.docx);
|
|
687
|
+
if (Result.isError(analyzed)) return analyzed;
|
|
688
|
+
return Result.ok({
|
|
689
|
+
...analyzed.value,
|
|
690
|
+
manifest: {
|
|
691
|
+
...analyzed.value.manifest,
|
|
692
|
+
sha256: sha256Hex(bytes),
|
|
693
|
+
trackedChangesResolved: {
|
|
694
|
+
view,
|
|
695
|
+
...resolved.value.resolved
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
};
|
|
436
700
|
/**
|
|
437
701
|
* Read a DOCX into the blocks a template plan addresses: ids, visible text,
|
|
438
|
-
* rendered list labels, styles and a hash per block, plus its notes.
|
|
702
|
+
* rendered list labels, styles and a hash per block, plus its notes. With
|
|
703
|
+
* `trackedChanges`, the blocks are those of that view of a document with
|
|
704
|
+
* tracked changes; with `keep`, those of the accepted view, read off the
|
|
705
|
+
* document as it stands, or the refusal a plan that keeps them would get.
|
|
439
706
|
*/
|
|
440
|
-
const analyzeDocxBlocks = async (docx) => await guarded(async () => (await
|
|
441
|
-
export { analyzeDocument, analyzeDocxBlocks, analyzeStory, blockHash, statedAlignments, storySections, styleAlignment, styleOutlineLevel };
|
|
707
|
+
const analyzeDocxBlocks = async (docx, options = {}) => await guarded(async () => (await analyzeSource(docx, options.trackedChanges)).map(({ manifest }) => manifest));
|
|
708
|
+
export { analyzeDocument, analyzeDocxBlocks, analyzeKeptForm, analyzeSource, analyzeStory, blockHash, statedAlignments, statedLooks, storySections, styleAlignment, styleLook, styleOutlineLevel, viewOf };
|
|
@@ -57,6 +57,12 @@ export declare const fieldBookmarkOf: (instruction: string) => string | null;
|
|
|
57
57
|
* place in the schema's child order. Null when the part is not a settings part.
|
|
58
58
|
*/
|
|
59
59
|
export declare const setUpdateFieldsOnOpen: (settingsXml: string, enabled: boolean) => string | null;
|
|
60
|
+
/**
|
|
61
|
+
* `settingsXml` without `w:trackRevisions`: a document that carries tracked
|
|
62
|
+
* changes of its source records no new ones until its reader switches
|
|
63
|
+
* tracking on. Null when the part is not a settings part.
|
|
64
|
+
*/
|
|
65
|
+
export declare const setTrackingOff: (settingsXml: string) => string | null;
|
|
60
66
|
/** Whether a settings part keeps the spacing of a justified line that ends
|
|
61
67
|
* in a manual line break (`w:compat/w:doNotExpandShiftReturn`). */
|
|
62
68
|
export declare const keepsShiftReturnSpacing: (settingsXml: string) => boolean;
|
|
@@ -78,14 +84,29 @@ export type SectionRewrite = {
|
|
|
78
84
|
page: TemplatePlanSectionPage | undefined;
|
|
79
85
|
/** How the section begins; null keeps what the template states. */
|
|
80
86
|
start: string | null;
|
|
87
|
+
/**
|
|
88
|
+
* Header and footer references the section takes over from the sections
|
|
89
|
+
* in front of it and does not state itself, as markup. Left out, the
|
|
90
|
+
* section is written with its own alone.
|
|
91
|
+
*/
|
|
92
|
+
inherited?: readonly string[];
|
|
81
93
|
};
|
|
94
|
+
/**
|
|
95
|
+
* The header and footer references a body's last section takes over from
|
|
96
|
+
* the sections in front of it: a section that states no header of a kind
|
|
97
|
+
* shows the one of the section before. An output built from the last
|
|
98
|
+
* section alone would lose them, so they are stated on it. Each is the
|
|
99
|
+
* reference of the nearest earlier section that states that kind, as it is
|
|
100
|
+
* written in `xml`; kinds the last section states itself are left out.
|
|
101
|
+
*/
|
|
102
|
+
export declare const inheritedReferencesXml: (xml: string, body: XmlElement, last: XmlElement) => string[];
|
|
82
103
|
/**
|
|
83
104
|
* A `w:sectPr` built from the template's: the same children in the same
|
|
84
105
|
* order, with the page, the start and the first-section properties changed
|
|
85
106
|
* as `rewrite` says. `xml` is the part `sectPr` was read from. Null when a
|
|
86
107
|
* child cannot be read back.
|
|
87
108
|
*/
|
|
88
|
-
export declare const sectionPropertiesXml: (xml: string, sectPr: XmlElement, w: string, { first, page, start }: SectionRewrite) => string | null;
|
|
109
|
+
export declare const sectionPropertiesXml: (xml: string, sectPr: XmlElement, w: string, { first, page, start, inherited }: SectionRewrite) => string | null;
|
|
89
110
|
export type FrozenFieldCount = {
|
|
90
111
|
kind: string;
|
|
91
112
|
count: number;
|
|
@@ -139,6 +139,12 @@ const fieldBookmarkOf = (instruction) => /^\s*(?:REF|PAGEREF|NOTEREF)\s+"?(?<nam
|
|
|
139
139
|
* place in the schema's child order. Null when the part is not a settings part.
|
|
140
140
|
*/
|
|
141
141
|
const setUpdateFieldsOnOpen = (settingsXml, enabled) => updateSettingsOnOffChild(settingsXml, "updateFields", enabled ? true : void 0);
|
|
142
|
+
/**
|
|
143
|
+
* `settingsXml` without `w:trackRevisions`: a document that carries tracked
|
|
144
|
+
* changes of its source records no new ones until its reader switches
|
|
145
|
+
* tracking on. Null when the part is not a settings part.
|
|
146
|
+
*/
|
|
147
|
+
const setTrackingOff = (settingsXml) => updateSettingsOnOffChild(settingsXml, "trackRevisions", void 0);
|
|
142
148
|
const SHIFT_RETURN = "doNotExpandShiftReturn";
|
|
143
149
|
/** The children of `w:compat` the schema orders in front of the setting. */
|
|
144
150
|
const COMPAT_BEFORE_SHIFT_RETURN = /* @__PURE__ */ new Set([
|
|
@@ -256,15 +262,43 @@ const MARGINS_KEPT = [
|
|
|
256
262
|
"gutter"
|
|
257
263
|
];
|
|
258
264
|
/**
|
|
265
|
+
* The header and footer references a body's last section takes over from
|
|
266
|
+
* the sections in front of it: a section that states no header of a kind
|
|
267
|
+
* shows the one of the section before. An output built from the last
|
|
268
|
+
* section alone would lose them, so they are stated on it. Each is the
|
|
269
|
+
* reference of the nearest earlier section that states that kind, as it is
|
|
270
|
+
* written in `xml`; kinds the last section states itself are left out.
|
|
271
|
+
*/
|
|
272
|
+
const inheritedReferencesXml = (xml, body, last) => {
|
|
273
|
+
const keyOf = (reference) => {
|
|
274
|
+
const name = wName(reference);
|
|
275
|
+
return name === "headerReference" || name === "footerReference" ? `${name}:${wAttr(reference, "type") ?? "default"}` : null;
|
|
276
|
+
};
|
|
277
|
+
const referencesOf = (sectPr) => elementChildren(sectPr).flatMap((child) => {
|
|
278
|
+
const key = keyOf(child);
|
|
279
|
+
return key === null ? [] : [[key, child]];
|
|
280
|
+
});
|
|
281
|
+
const inEffect = /* @__PURE__ */ new Map();
|
|
282
|
+
for (const block of elementChildren(body)) {
|
|
283
|
+
const sectPr = wName(block) === "p" ? wChild(wChild(block, "pPr"), "sectPr") : null;
|
|
284
|
+
for (const [key, reference] of referencesOf(sectPr)) inEffect.set(key, reference);
|
|
285
|
+
}
|
|
286
|
+
const own = new Set(referencesOf(last).map(([key]) => key));
|
|
287
|
+
return [...inEffect].flatMap(([key, reference]) => {
|
|
288
|
+
const range = own.has(key) ? null : rangeOf(reference);
|
|
289
|
+
return range === null ? [] : [xml.slice(range.start, range.end)];
|
|
290
|
+
});
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
259
293
|
* A `w:sectPr` built from the template's: the same children in the same
|
|
260
294
|
* order, with the page, the start and the first-section properties changed
|
|
261
295
|
* as `rewrite` says. `xml` is the part `sectPr` was read from. Null when a
|
|
262
296
|
* child cannot be read back.
|
|
263
297
|
*/
|
|
264
|
-
const sectionPropertiesXml = (xml, sectPr, w, { first, page, start }) => {
|
|
298
|
+
const sectionPropertiesXml = (xml, sectPr, w, { first, page, start, inherited = [] }) => {
|
|
265
299
|
const attributes = (element, names) => names.map((name) => [name, wAttr(element, name)]).filter(([, value]) => value !== null).map(([name, value]) => ` ${w}:${name}="${escapeXmlAttribute(value ?? "")}"`).join("");
|
|
266
300
|
const type = start === null ? "" : `<${w}:type ${w}:val="${start}"/>`;
|
|
267
|
-
const out = [];
|
|
301
|
+
const out = [...inherited];
|
|
268
302
|
let typeWritten = type === "";
|
|
269
303
|
for (const child of elementChildren(sectPr)) {
|
|
270
304
|
const name = wName(child);
|
|
@@ -425,4 +459,4 @@ const freezeFields = (part, kinds) => {
|
|
|
425
459
|
}))
|
|
426
460
|
};
|
|
427
461
|
};
|
|
428
|
-
export { applyRefCaseFormat, bookmarkEndXml, bookmarkIdsOf, bookmarkStartXml, complexFieldXml, fieldBookmarkOf, freezeFields, keepsShiftReturnSpacing, mintRefBookmarkName, refCaseFormat, refFieldInstruction, sectionPropertiesXml, setKeepShiftReturnSpacing, setUpdateFieldsOnOpen, withoutContained, wrapParagraphContentInBookmark };
|
|
462
|
+
export { applyRefCaseFormat, bookmarkEndXml, bookmarkIdsOf, bookmarkStartXml, complexFieldXml, fieldBookmarkOf, freezeFields, inheritedReferencesXml, keepsShiftReturnSpacing, mintRefBookmarkName, refCaseFormat, refFieldInstruction, sectionPropertiesXml, setKeepShiftReturnSpacing, setTrackingOff, 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
|
+
}[];
|