@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.
Files changed (143) hide show
  1. package/dist/ai-edits/headless.d.ts +8 -5
  2. package/dist/ai-edits/headless.js +49 -26
  3. package/dist/ai-edits/pending-suggestions.d.ts +9 -0
  4. package/dist/ai-edits/pending-suggestions.js +13 -3
  5. package/dist/ai-edits/read.js +33 -4
  6. package/dist/ai-edits/table-geometry.js +12 -4
  7. package/dist/ai-edits/types.d.ts +9 -4
  8. package/dist/canonical/batchCommentReferences.js +2 -1
  9. package/dist/canonical/canonicalBatchReview.js +5 -8
  10. package/dist/canonical/canonicalComments.js +8 -2
  11. package/dist/canonical/canonicalCompilerRefusal.d.ts +2 -4
  12. package/dist/canonical/canonicalCompilerRefusal.js +20 -14
  13. package/dist/canonical/canonicalInlineProjection.d.ts +2 -2
  14. package/dist/canonical/canonicalInlineProjection.js +2 -2
  15. package/dist/canonical/canonicalProjectionBlocks.d.ts +10 -1
  16. package/dist/canonical/canonicalPublicOperations.js +214 -107
  17. package/dist/canonical/canonicalSeedContent.d.ts +18 -3
  18. package/dist/canonical/canonicalSeedContent.js +28 -15
  19. package/dist/canonical/canonicalSession.d.ts +22 -12
  20. package/dist/canonical/canonicalSession.js +181 -187
  21. package/dist/controller/canonicalClipboard.d.ts +3 -2
  22. package/dist/controller/canonicalClipboard.js +377 -58
  23. package/dist/controller/canonicalComposition.js +67 -14
  24. package/dist/controller/canonicalContentControlValue.js +7 -7
  25. package/dist/controller/canonicalReview.d.ts +21 -0
  26. package/dist/controller/canonicalReview.js +44 -9
  27. package/dist/controller/canonicalStoryEditor.js +2 -0
  28. package/dist/controller/canonicalStructure.d.ts +1 -2
  29. package/dist/controller/canonicalStructure.js +51 -24
  30. package/dist/controller/fontReadiness.js +50 -23
  31. package/dist/controller/hiddenEditorManager.js +7 -20
  32. package/dist/docx/bulletMarkers.d.ts +8 -0
  33. package/dist/docx/bulletMarkers.js +9 -1
  34. package/dist/docx/canonicalSessionInput.js +25 -11
  35. package/dist/docx/ensureParaIds.d.ts +31 -0
  36. package/dist/docx/ensureParaIds.js +57 -32
  37. package/dist/docx/ensureUniqueControlIds.d.ts +13 -0
  38. package/dist/docx/ensureUniqueControlIds.js +47 -29
  39. package/dist/docx/ensureUniqueRevisionIds.d.ts +13 -0
  40. package/dist/docx/ensureUniqueRevisionIds.js +52 -29
  41. package/dist/docx/importedIdCollisions.js +29 -4
  42. package/dist/docx/server/templatePlan/apply.js +108 -9
  43. package/dist/docx/server/templatePlan/blocks.d.ts +77 -5
  44. package/dist/docx/server/templatePlan/blocks.js +281 -14
  45. package/dist/docx/server/templatePlan/builders.d.ts +22 -1
  46. package/dist/docx/server/templatePlan/builders.js +37 -3
  47. package/dist/docx/server/templatePlan/effects.d.ts +27 -0
  48. package/dist/docx/server/templatePlan/effects.js +188 -0
  49. package/dist/docx/server/templatePlan/emit.d.ts +4 -1
  50. package/dist/docx/server/templatePlan/emit.js +152 -8
  51. package/dist/docx/server/templatePlan/inspect.js +21 -1
  52. package/dist/docx/server/templatePlan/labels.js +16 -1
  53. package/dist/docx/server/templatePlan/plan.d.ts +35 -3
  54. package/dist/docx/server/templatePlan/plan.js +197 -20
  55. package/dist/docx/server/templatePlan/planShape.js +58 -22
  56. package/dist/docx/server/templatePlan/revisions.d.ts +101 -0
  57. package/dist/docx/server/templatePlan/revisions.js +681 -0
  58. package/dist/docx/server/templatePlan/story.d.ts +61 -2
  59. package/dist/docx/server/templatePlan/story.js +175 -13
  60. package/dist/docx/server/templatePlan/types.d.ts +313 -1
  61. package/dist/docx/server/templatePlan/verify.js +175 -12
  62. package/dist/docx/server/templatePlan/xml.d.ts +3 -0
  63. package/dist/docx/server/templatePlan/xml.js +4 -1
  64. package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
  65. package/dist/docx/tableGridXml.d.ts +3 -7
  66. package/dist/docx/tableGridXml.js +5 -13
  67. package/dist/layout-bridge/convert/footnoteLayout.js +34 -8
  68. package/dist/prosemirror/canonicalMarkupDocument.d.ts +20 -0
  69. package/dist/prosemirror/canonicalMarkupDocument.js +73 -0
  70. package/dist/prosemirror/canonicalTableCommands.d.ts +1 -1
  71. package/dist/prosemirror/canonicalTableCommands.js +1 -3
  72. package/dist/prosemirror/commands/comments.d.ts +6 -234
  73. package/dist/prosemirror/commands/comments.js +5 -2464
  74. package/dist/prosemirror/commands/index.d.ts +4 -2
  75. package/dist/prosemirror/commands/index.js +4 -2
  76. package/dist/prosemirror/conversion/markupViewSource.d.ts +17 -0
  77. package/dist/prosemirror/conversion/markupViewSource.js +11 -0
  78. package/dist/prosemirror/conversion/toProseDoc.d.ts +3 -0
  79. package/dist/prosemirror/conversion/toProseDoc.js +31 -14
  80. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +6 -8
  81. package/dist/prosemirror/hyperlinkRemoval.d.ts +11 -8
  82. package/dist/prosemirror/hyperlinkRemoval.js +24 -15
  83. package/dist/prosemirror/independentMarkupProjection.d.ts +27 -0
  84. package/dist/prosemirror/independentMarkupProjection.js +147 -0
  85. package/dist/prosemirror/markupViewNotes.d.ts +1 -1
  86. package/dist/prosemirror/markupViewNotes.js +24 -27
  87. package/dist/prosemirror/markupViewPositionMap.d.ts +16 -0
  88. package/dist/prosemirror/markupViewPositionMap.js +316 -0
  89. package/dist/prosemirror/markupViewProjection.d.ts +3 -46
  90. package/dist/prosemirror/markupViewProjection.js +90 -17
  91. package/dist/prosemirror/paraIds.d.ts +1 -14
  92. package/dist/prosemirror/paraIds.js +1 -14
  93. package/dist/prosemirror/paragraphMarkJoin.d.ts +0 -16
  94. package/dist/prosemirror/paragraphMarkJoin.js +3 -46
  95. package/dist/prosemirror/projectionReview.d.ts +49 -0
  96. package/dist/prosemirror/projectionReview.js +292 -0
  97. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -13
  98. package/dist/prosemirror/rebaseParagraphRunFormatting.js +1 -16
  99. package/dist/prosemirror/replacedAnnotations.d.ts +6 -83
  100. package/dist/prosemirror/replacedAnnotations.js +11 -203
  101. package/dist/prosemirror/revisionCarriers.d.ts +9 -1
  102. package/dist/prosemirror/revisionCarriers.js +15 -1
  103. package/dist/prosemirror/revisionRangeQueries.d.ts +32 -0
  104. package/dist/prosemirror/revisionRangeQueries.js +76 -0
  105. package/dist/prosemirror/runFormattingMarkNames.d.ts +1 -1
  106. package/dist/prosemirror/runFormattingMarkNames.js +1 -1
  107. package/dist/prosemirror/styles/styleResolver.d.ts +1 -0
  108. package/dist/prosemirror/styles/styleResolver.js +4 -1
  109. package/dist/prosemirror/suggestionQueries.d.ts +114 -0
  110. package/dist/prosemirror/suggestionQueries.js +320 -0
  111. package/dist/prosemirror/tableGridMutation.d.ts +1 -16
  112. package/dist/prosemirror/tableGridMutation.js +1 -78
  113. package/dist/prosemirror/tableRowRevisionOwnership.d.ts +18 -0
  114. package/dist/prosemirror/tableRowRevisionOwnership.js +7 -0
  115. package/dist/prosemirror/utils/extractTrackedChanges.js +14 -4
  116. package/dist/server.d.ts +2 -2
  117. package/dist/types/canonicalCapabilities.d.ts +4 -35
  118. package/dist/types/canonicalCapabilities.js +4 -33
  119. package/package.json +2 -2
  120. package/dist/internal/headlessRevisionResolutionGuard.d.ts +0 -3
  121. package/dist/internal/headlessRevisionResolutionGuard.js +0 -18
  122. package/dist/internal/revisionResolutionEdits.d.ts +0 -11
  123. package/dist/internal/revisionResolutionEdits.js +0 -18
  124. package/dist/internal/revisionResolutionInline.d.ts +0 -24
  125. package/dist/internal/revisionResolutionInline.js +0 -302
  126. package/dist/internal/revisionResolutionStep.d.ts +0 -32
  127. package/dist/internal/revisionResolutionStep.js +0 -282
  128. package/dist/internal/revisionResolutionTracking.d.ts +0 -9
  129. package/dist/internal/revisionResolutionTracking.js +0 -124
  130. package/dist/internal/wholeStoryRevisionResolution.d.ts +0 -56
  131. package/dist/internal/wholeStoryRevisionResolution.js +0 -783
  132. package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +0 -38
  133. package/dist/prosemirror/commands/resolveAllTableChanges.js +0 -642
  134. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +0 -13
  135. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +0 -45
  136. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +0 -18
  137. package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -207
  138. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +0 -60
  139. package/dist/prosemirror/commands/tableMergeFoldDecisions.js +0 -78
  140. package/dist/prosemirror/rejoinRunCarriers.d.ts +0 -42
  141. package/dist/prosemirror/rejoinRunCarriers.js +0 -65
  142. package/dist/prosemirror/runPropertyChangeResolution.d.ts +0 -15
  143. package/dist/prosemirror/runPropertyChangeResolution.js +0 -34
@@ -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 };
@@ -55,6 +55,8 @@ export type EmitShared = {
55
55
  /** Register a media part of the output and return its absolute target. */
56
56
  addMedia: (sourcePath: string, media: SourceMedia) => string;
57
57
  nextDrawingId: () => number;
58
+ /** A fresh id for a tracked change the output carries. */
59
+ nextRevisionId: () => number;
58
60
  };
59
61
  export type EmitContext = EmitShared & {
60
62
  prefixes: PartPrefixes;
@@ -103,7 +105,8 @@ export type TableEmit = {
103
105
  /**
104
106
  * A source table rebuilt: its grid, spans and merges, with every cell
105
107
  * paragraph placed like a body paragraph. Without a template table style the
106
- * source's borders are kept so the grid stays visible.
108
+ * source's borders are kept so the grid stays visible, and the fill of its
109
+ * cells with them: a header row, the colours of a legend.
107
110
  */
108
111
  export declare const tableXml: ({ table, styleId, paragraphOf }: TableEmit, context: EmitContext) => RunsResult;
109
112
  export type NoteEmit = {
@@ -5,6 +5,7 @@ import { appendToXmlRoot } from "../../xmlRootInsertion.js";
5
5
  import { bookmarkEndXml, bookmarkStartXml, complexFieldXml, wrapParagraphContentInBookmark } from "./builders.js";
6
6
  import { runPropertiesXml } from "./emphasis.js";
7
7
  import { paragraphPieces } from "./plan.js";
8
+ import { deletedRowMarkOf, insertedRowMarkOf, keptDeletedRowOf, rowTextOf } from "./revisions.js";
8
9
  import { TemplatePlanError } from "./types.js";
9
10
  import { MATH_NAMESPACE, elementChildren, escapeXmlAttribute, escapeXmlText, wAttr, wChild, wChildren, wName } from "./xml.js";
10
11
  import { Result, panic } from "better-result";
@@ -189,7 +190,55 @@ const wSubtreeXml = (element, prefix) => {
189
190
  const open = `<${prefix}:${name}${wAttributesXml(element, prefix)}`;
190
191
  return children === "" ? `${open}/>` : `${open}>${children}</${prefix}:${name}>`;
191
192
  };
193
+ /**
194
+ * What stands in a paragraph's runs for a deleted paragraph mark until the
195
+ * paragraph is written: the attributes of the mark between two of these. No
196
+ * run holds the character (XML text cannot).
197
+ */
198
+ const MARK_SPLIT = "\0";
199
+ /** The inserted mark of a paragraph's last piece, when it has one. */
200
+ const insertedMarkOf = (segments) => {
201
+ const last = segments.at(-1);
202
+ const revision = (last === void 0 || last.kind === "piece" ? [last?.piece] : last.pieces).at(-1)?.atom?.revision;
203
+ return revision?.mark === true ? revision : void 0;
204
+ };
205
+ /** The attributes a kept tracked change is written with: its own author and
206
+ * date, and an id of the output's. */
207
+ const revisionAttributesXml = ({ author, date }, { prefixes: { w }, nextRevisionId }) => ` ${w}:id="${String(nextRevisionId())}" ${w}:author="${escapeXmlAttribute(author)}"${date === null ? "" : ` ${w}:date="${escapeXmlAttribute(date)}"`}`;
208
+ /** Deleted text as the content of a deleted run: tabs and line breaks are
209
+ * elements, the rest is `w:delText`. */
210
+ const deletedContentXml = (deleted, w) => deleted.split(/(\t|\n)/u).map((part) => {
211
+ if (part === " ") return `<${w}:tab/>`;
212
+ if (part === "\n") return `<${w}:br/>`;
213
+ return part === "" ? "" : `<${w}:delText xml:space="preserve">${escapeXmlText(part)}</${w}:delText>`;
214
+ }).join("");
215
+ /**
216
+ * The runs of one piece. A piece of a kept tracked change is written inside
217
+ * its insertion or deletion; a deletion holds the text that was deleted and
218
+ * takes no place in the text around it.
219
+ */
192
220
  const pieceRunXml = (piece, context, linked) => {
221
+ const revision = piece.atom?.revision;
222
+ if (revision === void 0) return plainPieceRunXml(piece, context, linked);
223
+ const { w } = context.prefixes;
224
+ if (revision.mark === true) return Result.ok("");
225
+ const attributes = revisionAttributesXml(revision, context);
226
+ if (revision.deleted === "") return Result.ok(`${MARK_SPLIT}${attributes}${MARK_SPLIT}`);
227
+ if (revision.kind === "del") {
228
+ const deletion = `<${w}:del${attributes}><${w}:r>${runPropertiesXml({
229
+ prefix: w,
230
+ signature: piece.signature,
231
+ rStyle: linked ? context.styles.hyperlink : null,
232
+ escapeAttribute: escapeXmlAttribute
233
+ })}${deletedContentXml(revision.deleted ?? "", w)}</${w}:r></${w}:del>`;
234
+ return Result.ok(revision.within === void 0 ? deletion : `<${w}:ins${revisionAttributesXml({
235
+ kind: "ins",
236
+ ...revision.within
237
+ }, context)}>${deletion}</${w}:ins>`);
238
+ }
239
+ return plainPieceRunXml(piece, context, linked).map((runs) => runs === "" ? "" : `<${w}:ins${attributes}>${runs}</${w}:ins>`);
240
+ };
241
+ const plainPieceRunXml = (piece, context, linked) => {
193
242
  const { w } = context.prefixes;
194
243
  const properties = (rStyle) => runPropertiesXml({
195
244
  prefix: w,
@@ -221,6 +270,14 @@ const pieceRunXml = (piece, context, linked) => {
221
270
  const mark = `<${w}:${kind}Reference ${w}:id="${context.noteId(kind, sourceId)}"/>`;
222
271
  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
272
  }
273
+ case "selfNumber": {
274
+ const instruction = piece.atom?.instruction;
275
+ return Result.ok(instruction === void 0 ? "" : [
276
+ `<${w}:fldChar ${w}:fldCharType="begin"/>`,
277
+ `<${w}:instrText xml:space="preserve"> ${escapeXmlText(instruction)} </${w}:instrText>`,
278
+ `<${w}:fldChar ${w}:fldCharType="end"/>`
279
+ ].map((content) => run(content)).join(""));
280
+ }
224
281
  case "object": {
225
282
  const transferred = transferObject(piece, context);
226
283
  if (Result.isError(transferred)) return transferred;
@@ -234,7 +291,7 @@ const mergedPieces = (pieces) => {
234
291
  const merged = [];
235
292
  for (const piece of pieces) {
236
293
  const last = merged.at(-1);
237
- if (last !== void 0 && last.kind === "text" && piece.kind === "text" && last.signature === piece.signature && last.origin === piece.origin && sameLink(last.link, piece.link)) merged[merged.length - 1] = {
294
+ if (last !== void 0 && last.kind === "text" && piece.kind === "text" && last.signature === piece.signature && last.origin === piece.origin && last.atom?.revision === void 0 && piece.atom?.revision === void 0 && sameLink(last.link, piece.link)) merged[merged.length - 1] = {
238
295
  ...last,
239
296
  text: last.text + piece.text
240
297
  };
@@ -326,14 +383,49 @@ const paragraphXml = (emit, context) => {
326
383
  const { styleId, numbering } = emit.paragraph;
327
384
  const properties = [];
328
385
  if (styleId !== null) properties.push(`<${w}:pStyle ${w}:val="${escapeXmlAttribute(styleId)}"/>`);
386
+ if (emit.paragraph.keepNext) properties.push(`<${w}:keepNext/>`);
329
387
  if (emit.paragraph.pageBreakBefore) properties.push(`<${w}:pageBreakBefore/>`);
330
388
  if (numbering.kind === "direct") properties.push(`<${w}:numPr><${w}:ilvl ${w}:val="${numbering.ilvl}"/><${w}:numId ${w}:val="${numbering.numId}"/></${w}:numPr>`);
331
389
  else if (numbering.kind === "none" && emit.styleBindsList) properties.push(`<${w}:numPr><${w}:numId ${w}:val="${NO_LIST_NUM_ID}"/></${w}:numPr>`);
390
+ const { indent, tabStops } = emit.paragraph;
391
+ if (tabStops !== null) {
392
+ const stops = tabStops.map((stop) => `<${w}:tab ${w}:val="left" ${w}:pos="${String(stop)}"/>`).join("");
393
+ properties.push(`<${w}:tabs>${stops}</${w}:tabs>`);
394
+ }
395
+ const { spacing } = emit.paragraph;
396
+ if (spacing !== null) {
397
+ const sides = ["before", "after"].filter((side) => spacing[side] !== void 0).map((side) => ` ${w}:${side}="${String(spacing[side])}"`).join("");
398
+ properties.push(`<${w}:spacing${sides}/>`);
399
+ }
400
+ if (indent !== null) {
401
+ const sides = [
402
+ "left",
403
+ "hanging",
404
+ "firstLine"
405
+ ].filter((side) => indent[side] !== void 0).map((side) => ` ${w}:${side}="${String(indent[side])}"`).join("");
406
+ properties.push(`<${w}:ind${sides}/>`);
407
+ }
408
+ const { alignment } = emit.paragraph;
409
+ if (alignment !== null) properties.push(`<${w}:jc ${w}:val="${alignment}"/>`);
332
410
  if (emit.sectionXml !== null) properties.push(emit.sectionXml);
333
411
  const runs = segmentsRunsXml(emit.paragraph.segments, context, emit.instructionOf);
334
412
  if (Result.isError(runs)) return runs;
335
- const xml = `<${w}:p>${properties.length === 0 ? "" : `<${w}:pPr>${properties.join("")}</${w}:pPr>`}${runs.value}</${w}:p>`;
336
- if (emit.bookmark === void 0) return Result.ok(xml);
413
+ const inserted = insertedMarkOf(emit.paragraph.segments);
414
+ if (inserted !== void 0) {
415
+ const mark = `<${w}:rPr><${w}:ins${revisionAttributesXml(inserted, context)}/></${w}:rPr>`;
416
+ properties.splice(emit.sectionXml === null ? properties.length : properties.length - 1, 0, mark);
417
+ }
418
+ const pPr = properties.length === 0 ? "" : `<${w}:pPr>${properties.join("")}</${w}:pPr>`;
419
+ const [last = "", ...earlier] = runs.value.split(MARK_SPLIT).toReversed();
420
+ const halves = [];
421
+ const parted = earlier.toReversed();
422
+ for (let at = 0; at + 1 < parted.length; at += 2) {
423
+ const style = styleId === null ? "" : `<${w}:pStyle ${w}:val="${escapeXmlAttribute(styleId)}"/>`;
424
+ const list = numbering.kind === "direct" || emit.styleBindsList ? `<${w}:numPr><${w}:numId ${w}:val="${NO_LIST_NUM_ID}"/></${w}:numPr>` : "";
425
+ halves.push(`<${w}:p><${w}:pPr>${style}${list}<${w}:rPr><${w}:del${parted[at + 1] ?? ""}/></${w}:rPr></${w}:pPr>${parted[at] ?? ""}</${w}:p>`);
426
+ }
427
+ const xml = `<${w}:p>${pPr}${last}</${w}:p>`;
428
+ if (emit.bookmark === void 0) return Result.ok(`${halves.join("")}${xml}`);
337
429
  const wrapped = wrapParagraphContentInBookmark({
338
430
  paragraphXml: xml,
339
431
  prefixes: context.prefixes,
@@ -343,7 +435,7 @@ const paragraphXml = (emit, context) => {
343
435
  code: "xml-unreadable",
344
436
  message: "A reference target could not be bookmarked.",
345
437
  blockId: emit.paragraph.parts.at(0)?.block.block.id ?? ""
346
- })) : Result.ok(wrapped);
438
+ })) : Result.ok(`${halves.join("")}${wrapped}`);
347
439
  };
348
440
  const TABLE_LAYOUT_PROPERTIES = ["tblLayout", "tblLook"];
349
441
  const ROW_PROPERTIES = [
@@ -358,14 +450,63 @@ const CELL_SPAN_PROPERTIES = [
358
450
  "hMerge",
359
451
  "vMerge"
360
452
  ];
453
+ /** What a cell's fill states by itself; a theme colour is the template's. */
454
+ const SHADING_KEPT = [
455
+ "val",
456
+ "color",
457
+ "fill"
458
+ ];
459
+ /**
460
+ * The fill of a cell as its own colours state it. A theme colour would be
461
+ * read from the template's theme, which is another one; a fill stated by a
462
+ * theme colour alone is left out.
463
+ */
464
+ const cellShadingXml = (properties, prefix) => {
465
+ const shading = wChild(properties, "shd");
466
+ const fill = wAttr(shading, "fill");
467
+ if (shading === null || fill === null || fill === "auto") return "";
468
+ return `<${prefix}:shd${SHADING_KEPT.map((name) => [name, wAttr(shading, name)]).filter(([, value]) => value !== null).map(([name, value]) => ` ${prefix}:${name}="${escapeXmlAttribute(value ?? "")}"`).join("")}/>`;
469
+ };
361
470
  const keptChildrenXml = (properties, names, prefix) => names.map((name) => {
362
471
  const child = wChild(properties, name);
363
472
  return child === null ? "" : wSubtreeXml(child, prefix);
364
473
  }).join("");
474
+ /** The attributes a kept row or mark revision is written with, read off the
475
+ * source's own record. */
476
+ const markAttributesXml = (mark, context) => revisionAttributesXml({
477
+ kind: "del",
478
+ author: wAttr(mark, "author") ?? "",
479
+ date: wAttr(mark, "date")
480
+ }, context);
481
+ /**
482
+ * A row the source records as deleted, written back as one: its cells with
483
+ * their spans, and in each cell its paragraphs' text as deleted text with a
484
+ * deleted paragraph mark. The accepted view has no such row, so no plan
485
+ * places its paragraphs; they take no style of their own.
486
+ */
487
+ const deletedRowXml = (row, keepsBorders, context) => {
488
+ const { w } = context.prefixes;
489
+ const mark = deletedRowMarkOf(row);
490
+ const attributes = () => mark === null ? "" : markAttributesXml(mark, context);
491
+ const deletedParagraphXml = (text) => `<${w}:p><${w}:pPr><${w}:rPr><${w}:del${attributes()}/></${w}:rPr></${w}:pPr>${text === "" ? "" : `<${w}:del${attributes()}><${w}:r>${deletedContentXml(text, w)}</${w}:r></${w}:del>`}</${w}:p>`;
492
+ const cells = [];
493
+ const stack = [...elementChildren(row)].toReversed();
494
+ for (let next = stack.pop(); next !== void 0; next = stack.pop()) if (wName(next) === "tc") {
495
+ const properties = wChild(next, "tcPr");
496
+ const kept = `${keptChildrenXml(properties, CELL_SPAN_PROPERTIES, w)}${keepsBorders ? keptChildrenXml(properties, ["tcBorders"], w) : ""}`;
497
+ const lines = rowTextOf({
498
+ ...row,
499
+ elements: [next]
500
+ }).split("\n");
501
+ cells.push(`<${w}:tc>${kept === "" ? "" : `<${w}:tcPr>${kept}</${w}:tcPr>`}${lines.map(deletedParagraphXml).join("")}</${w}:tc>`);
502
+ } else if (wName(next) !== "trPr") stack.push(...elementChildren(next).toReversed());
503
+ return `<${w}:tr><${w}:trPr><${w}:del${attributes()}/></${w}:trPr>${cells.join("")}</${w}:tr>`;
504
+ };
365
505
  /**
366
506
  * A source table rebuilt: its grid, spans and merges, with every cell
367
507
  * paragraph placed like a body paragraph. Without a template table style the
368
- * source's borders are kept so the grid stays visible.
508
+ * source's borders are kept so the grid stays visible, and the fill of its
509
+ * cells with them: a header row, the colours of a legend.
369
510
  */
370
511
  const tableXml = ({ table, styleId, paragraphOf }, context) => {
371
512
  const { w } = context.prefixes;
@@ -395,7 +536,7 @@ const tableXml = ({ table, styleId, paragraphOf }, context) => {
395
536
  const name = wName(child);
396
537
  if (name === "tc") {
397
538
  const cellProperties = wChild(child, "tcPr");
398
- const kept = `${keptChildrenXml(cellProperties, CELL_SPAN_PROPERTIES, w)}${styleId === null ? keptChildrenXml(cellProperties, ["tcBorders"], w) : ""}${keptChildrenXml(cellProperties, ["vAlign"], w)}`;
539
+ const kept = `${keptChildrenXml(cellProperties, CELL_SPAN_PROPERTIES, w)}${styleId === null ? `${keptChildrenXml(cellProperties, ["tcBorders"], w)}${cellShadingXml(cellProperties, w)}` : ""}${keptChildrenXml(cellProperties, ["vAlign"], w)}`;
399
540
  const blocks = blocksXml(child);
400
541
  if (Result.isError(blocks)) return blocks;
401
542
  const content = blocks.value.endsWith(`</${w}:p>`) ? blocks.value : `${blocks.value}<${w}:p/>`;
@@ -417,8 +558,11 @@ const tableXml = ({ table, styleId, paragraphOf }, context) => {
417
558
  const out = [];
418
559
  for (const child of elementChildren(container)) {
419
560
  const name = wName(child);
420
- if (name === "tr") {
421
- const kept = keptChildrenXml(wChild(child, "trPr"), ROW_PROPERTIES, w);
561
+ const deleted = keptDeletedRowOf(child);
562
+ if (deleted !== null) out.push(deletedRowXml(deleted, styleId === null, context));
563
+ else if (name === "tr") {
564
+ const inserted = insertedRowMarkOf(child);
565
+ const kept = `${keptChildrenXml(wChild(child, "trPr"), ROW_PROPERTIES, w)}${inserted === null ? "" : `<${w}:ins${markAttributesXml(inserted, context)}/>`}`;
422
566
  const cells = cellsXml(child);
423
567
  if (Result.isError(cells)) return cells;
424
568
  out.push(`<${w}:tr>${kept === "" ? "" : `<${w}:trPr>${kept}</${w}:trPr>`}${cells.value}</${w}:tr>`);
@@ -1,6 +1,7 @@
1
1
  import { RELATIONSHIP_TYPES } from "../../relsParser.js";
2
2
  import { parseSectionProperties } from "../../sectionParser.js";
3
- import { analyzeDocument, statedAlignments, storySections, styleAlignment, styleOutlineLevel } from "./blocks.js";
3
+ import { analyzeDocument, statedAlignments, statedLooks, storySections, styleAlignment, styleLook, styleOutlineLevel } from "./blocks.js";
4
+ import { findInvisibleEffects } from "./effects.js";
4
5
  import { styleNumbering } from "./labels.js";
5
6
  import { guarded, readPartText } from "./package.js";
6
7
  import { createStoryState, endStory, readParagraph, walkBlocks } from "./story.js";
@@ -33,8 +34,10 @@ const NO_INDENT = {
33
34
  const inspectStyles = (analyzed) => {
34
35
  const { styles, numbering } = analyzed;
35
36
  const stated = statedAlignments(analyzed.stylesPath, analyzed.stylesXml);
37
+ const looks = statedLooks(analyzed.stylesPath, analyzed.stylesXml);
36
38
  return [...styles.values()].map((style) => {
37
39
  const bound = styleNumbering(style.styleId, styles, numbering);
40
+ const { bold, size, keepNext, indentLeft } = styleLook(style.styleId, styles, looks);
38
41
  return {
39
42
  styleId: style.styleId,
40
43
  name: style.name ?? null,
@@ -46,6 +49,10 @@ const inspectStyles = (analyzed) => {
46
49
  } : null,
47
50
  outlineLvl: styleOutlineLevel(style),
48
51
  alignment: styleAlignment(style.styleId, styles, stated),
52
+ bold,
53
+ size,
54
+ keepNext,
55
+ indentLeft,
49
56
  isDefault: style.default === true
50
57
  };
51
58
  });
@@ -176,8 +183,21 @@ const inspectAnalyzedTemplate = async (analyzed) => {
176
183
  fields.push(...partFields(part).map((field) => fieldOf(part.path, field)));
177
184
  bookmarks.push(...bookmarksOf(part));
178
185
  }
186
+ const effectParts = [
187
+ document,
188
+ ...[[analyzed.numberingPath, analyzed.numberingXml], [analyzed.stylesPath, analyzed.stylesXml]].flatMap(([path, xml]) => {
189
+ const part = path === null || xml === null ? null : readRawPart(path, xml);
190
+ return part === null ? [] : [part];
191
+ }),
192
+ ...headersAndFooters.value
193
+ ];
179
194
  return Result.ok({
180
195
  ...manifest,
196
+ invisibleEffects: effectParts.flatMap((part) => findInvisibleEffects(part).map(({ effect, owner }) => ({
197
+ part: part.path,
198
+ effect,
199
+ owner
200
+ }))),
181
201
  styles: inspectStyles(analyzed),
182
202
  numbering: inspectNumbering(analyzed),
183
203
  fields,
@@ -1,3 +1,4 @@
1
+ import { bulletMarkerFontName, bulletTextFace } from "../../bulletMarkers.js";
1
2
  import { computeListMarker } from "../../listMarkerComputation.js";
2
3
  import { resolveListTemplateWithComponents } from "../../listTemplate.js";
3
4
  import { computeListRendering } from "../../numberingParser.js";
@@ -25,6 +26,19 @@ const PLAIN_FORMATS = /* @__PURE__ */ new Set([
25
26
  "lowerLetter"
26
27
  ]);
27
28
  const LEVEL_PLACEHOLDER = /%([1-9])/gu;
29
+ /**
30
+ * What a block says of a bullet level: that it is one, and the text face its
31
+ * mark is a character of. `mark` is the level's own text, before it is read
32
+ * as the glyph it paints.
33
+ */
34
+ const bulletFacts = ({ isBullet, markerFormatting }, mark) => {
35
+ if (!isBullet) return {};
36
+ const face = bulletTextFace(mark, bulletMarkerFontName(markerFormatting));
37
+ return face === void 0 ? { bullet: true } : {
38
+ bullet: true,
39
+ bulletFont: face
40
+ };
41
+ };
28
42
  const labelAsText = ({ label, template, levelFormats, suffix, ordinalKnown }) => {
29
43
  if (label.trim() === "") return null;
30
44
  for (const [, digit] of template.matchAll(LEVEL_PLACEHOLDER)) {
@@ -206,7 +220,8 @@ const createLabelCounter = ({ numbering, styles, defaultStyleId, defaultLanguage
206
220
  const numberingInfo = abstractNumId === null ? null : {
207
221
  numId: resolved.numId,
208
222
  ilvl: resolved.ilvl,
209
- abstractNumId
223
+ abstractNumId,
224
+ ...bulletFacts(listRendering, template)
210
225
  };
211
226
  if (listRendering.markerHidden === true) return {
212
227
  ...NO_LABEL,
@@ -9,7 +9,7 @@ import { AnalyzedBlock, AnalyzedDocument } from "./blocks.js";
9
9
  import { BookmarkWrap } from "./builders.js";
10
10
  import { StoryOrigin } from "./resources.js";
11
11
  import { AtomKind, AtomLink, InlineAtom, ParagraphRead, StoryField } from "./story.js";
12
- import { TemplatePlan, TemplatePlanError, TemplatePlanOmitReason, TemplatePlanReference, TemplatePlanSection } from "./types.js";
12
+ import { TemplatePlan, TemplatePlanAlignment, TemplatePlanError, TemplatePlanIndent, TemplatePlanOmitReason, TemplatePlanReference, TemplatePlanSection, TemplatePlanSpacing } from "./types.js";
13
13
  import { Result } from "better-result";
14
14
  export type ExpectedPiece = {
15
15
  kind: AtomKind;
@@ -53,6 +53,12 @@ export type ResolvedNumbering = {
53
53
  export type ResolvedPart = {
54
54
  block: AnalyzedBlock;
55
55
  strippedPrefix: string;
56
+ /** The lead a slot dropped off the part and the template paragraph that
57
+ * shows the field, or null. */
58
+ droppedLead: {
59
+ text: string;
60
+ shownByTemplateBlockId: string;
61
+ } | null;
56
62
  /** The automatic label written as text before the part, or null. */
57
63
  labelAsText: string | null;
58
64
  };
@@ -69,6 +75,16 @@ export type ResolvedParagraph = {
69
75
  placement: "body" | "nested" | "slot";
70
76
  /** Whether the paragraph starts on a new page. */
71
77
  pageBreakBefore: boolean;
78
+ /** Whether the paragraph is kept with the one after it. */
79
+ keepNext: boolean;
80
+ /** The paragraph's own indent, or null. */
81
+ indent: TemplatePlanIndent | null;
82
+ /** The paragraph's own left tab stops, or null. */
83
+ tabStops: readonly number[] | null;
84
+ /** The paragraph's own alignment, or null. */
85
+ alignment: TemplatePlanAlignment | null;
86
+ /** The paragraph's own space in front and behind, or null. */
87
+ spacing: TemplatePlanSpacing | null;
72
88
  /** The section the paragraph is the last of, or null. */
73
89
  endsSection: TemplatePlanSection | null;
74
90
  };
@@ -101,10 +117,21 @@ export type ResolvedSlot = {
101
117
  templateBlock: AnalyzedBlock;
102
118
  paragraph: ResolvedParagraph;
103
119
  };
120
+ /**
121
+ * The run of a paragraph that holds the separator of the field the
122
+ * paragraph begins and leaves open: what follows it is the start of a result
123
+ * that goes on in later paragraphs. A field the paragraph both begins and
124
+ * ends (a page number in front of a table of contents) is not that field.
125
+ * Null when no one field is left open with its result begun, in runs of the
126
+ * paragraph itself.
127
+ */
128
+ export declare const fieldSeparatorRun: (paragraph: XmlElement) => XmlElement | null;
104
129
  export type ResolvedPlan = {
105
130
  items: ResolvedItem[];
106
131
  /** Slots that sit inside a kept template table. */
107
132
  nestedSlots: ResolvedSlot[];
133
+ /** Paragraphs of kept template tables written without their text. */
134
+ emptied: AnalyzedBlock[];
108
135
  /** The output paragraph each placed source block ends up in. */
109
136
  byBlockId: Map<string, ResolvedParagraph>;
110
137
  omitted: Map<string, TemplatePlanOmitReason>;
@@ -120,12 +147,17 @@ export type ResolvedPlan = {
120
147
  }[];
121
148
  freezeKinds: ReadonlySet<string>;
122
149
  keptTemplateBlocks: AnalyzedBlock[];
150
+ /** The paragraphs kept tables of contents begin in, written without the
151
+ * entries they cache: each with the length of the text it keeps in front
152
+ * of the field's result. */
153
+ emptiedContents: Map<AnalyzedBlock, number>;
123
154
  };
124
155
  /**
125
156
  * Whether `label` reads as a manual list label: up to three leading words
126
157
  * ("Article", "§", "Annex No.") and one designator, a number, a roman numeral
127
- * or a letter with its brackets and punctuation; or a single bullet. This is
128
- * the only text a plan may have removed.
158
+ * or a letter with its brackets and punctuation; or a single bullet; or a
159
+ * number whose parts stand apart (`1. 1.` for `1.1.`). This is the only text
160
+ * a plan may have removed.
129
161
  */
130
162
  export declare const isManualLabel: (label: string) => boolean;
131
163
  /** Whether a block holds no text and no object. */