@stll/folio-core 0.76.0 → 0.78.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 (92) hide show
  1. package/dist/ai-edits/headless.d.ts +6 -4
  2. package/dist/ai-edits/headless.js +32 -15
  3. package/dist/ai-edits/pending-suggestions.d.ts +9 -0
  4. package/dist/ai-edits/pending-suggestions.js +11 -0
  5. package/dist/ai-edits/read.js +24 -1
  6. package/dist/ai-edits/table-geometry.js +12 -4
  7. package/dist/canonical/canonicalBatchReview.js +7 -6
  8. package/dist/canonical/canonicalInlineProjection.d.ts +2 -2
  9. package/dist/canonical/canonicalInlineProjection.js +2 -2
  10. package/dist/canonical/canonicalProjectionBlocks.d.ts +10 -1
  11. package/dist/canonical/canonicalPublicOperations.js +19 -40
  12. package/dist/canonical/canonicalSeedContent.d.ts +18 -3
  13. package/dist/canonical/canonicalSeedContent.js +28 -15
  14. package/dist/canonical/canonicalSession.d.ts +22 -12
  15. package/dist/canonical/canonicalSession.js +190 -194
  16. package/dist/compare/inline-provenance.js +8 -1
  17. package/dist/controller/canonicalClipboard.d.ts +2 -1
  18. package/dist/controller/canonicalClipboard.js +312 -47
  19. package/dist/controller/canonicalComposition.js +67 -14
  20. package/dist/controller/canonicalStoryEditor.js +2 -0
  21. package/dist/controller/hiddenEditorManager.js +2 -0
  22. package/dist/docx/importedIdCollisions.js +29 -4
  23. package/dist/docx/paragraphParser.js +1 -1
  24. package/dist/docx/reviewResolutionProvenance.d.ts +2 -0
  25. package/dist/docx/reviewResolutionProvenance.js +22 -2
  26. package/dist/docx/server/templatePlan/apply.js +47 -2
  27. package/dist/docx/server/templatePlan/blocks.d.ts +34 -7
  28. package/dist/docx/server/templatePlan/blocks.js +190 -13
  29. package/dist/docx/server/templatePlan/builders.d.ts +8 -1
  30. package/dist/docx/server/templatePlan/builders.js +21 -5
  31. package/dist/docx/server/templatePlan/emit.d.ts +2 -0
  32. package/dist/docx/server/templatePlan/emit.js +108 -6
  33. package/dist/docx/server/templatePlan/plan.d.ts +26 -1
  34. package/dist/docx/server/templatePlan/plan.js +181 -21
  35. package/dist/docx/server/templatePlan/planShape.js +15 -3
  36. package/dist/docx/server/templatePlan/revisions.d.ts +55 -0
  37. package/dist/docx/server/templatePlan/revisions.js +276 -2
  38. package/dist/docx/server/templatePlan/story.d.ts +58 -1
  39. package/dist/docx/server/templatePlan/story.js +176 -12
  40. package/dist/docx/server/templatePlan/types.d.ts +153 -1
  41. package/dist/docx/server/templatePlan/verify.js +58 -15
  42. package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
  43. package/dist/docx/tableGridXml.d.ts +3 -7
  44. package/dist/docx/tableGridXml.js +23 -15
  45. package/dist/docx/tableParser.js +3 -1
  46. package/dist/layout-bridge/convert/footnoteLayout.js +34 -8
  47. package/dist/prosemirror/canonicalMarkupDocument.d.ts +20 -0
  48. package/dist/prosemirror/canonicalMarkupDocument.js +73 -0
  49. package/dist/prosemirror/canonicalTableCommands.d.ts +1 -1
  50. package/dist/prosemirror/canonicalTableCommands.js +7 -9
  51. package/dist/prosemirror/conversion/markupViewSource.d.ts +17 -0
  52. package/dist/prosemirror/conversion/markupViewSource.js +11 -0
  53. package/dist/prosemirror/conversion/toProseDoc.d.ts +8 -0
  54. package/dist/prosemirror/conversion/toProseDoc.js +43 -19
  55. package/dist/prosemirror/independentMarkupProjection.d.ts +27 -0
  56. package/dist/prosemirror/independentMarkupProjection.js +147 -0
  57. package/dist/prosemirror/markupViewNotes.d.ts +1 -1
  58. package/dist/prosemirror/markupViewNotes.js +24 -27
  59. package/dist/prosemirror/markupViewPositionMap.d.ts +16 -0
  60. package/dist/prosemirror/markupViewPositionMap.js +316 -0
  61. package/dist/prosemirror/markupViewProjection.d.ts +3 -46
  62. package/dist/prosemirror/markupViewProjection.js +90 -17
  63. package/dist/prosemirror/replacedAnnotations.d.ts +4 -78
  64. package/dist/prosemirror/replacedAnnotations.js +11 -194
  65. package/dist/prosemirror/styles/styleResolver.d.ts +1 -0
  66. package/dist/prosemirror/styles/styleResolver.js +4 -1
  67. package/dist/server.d.ts +2 -2
  68. package/dist/types/canonicalCapabilities.d.ts +3 -10
  69. package/dist/types/canonicalCapabilities.js +3 -10
  70. package/package.json +2 -2
  71. package/dist/internal/revisionResolutionEdits.d.ts +0 -11
  72. package/dist/internal/revisionResolutionEdits.js +0 -18
  73. package/dist/internal/revisionResolutionInline.d.ts +0 -24
  74. package/dist/internal/revisionResolutionInline.js +0 -302
  75. package/dist/internal/revisionResolutionStep.d.ts +0 -3
  76. package/dist/internal/revisionResolutionStep.js +0 -113
  77. package/dist/internal/revisionResolutionTracking.d.ts +0 -9
  78. package/dist/internal/revisionResolutionTracking.js +0 -124
  79. package/dist/internal/wholeStoryRevisionResolution.d.ts +0 -56
  80. package/dist/internal/wholeStoryRevisionResolution.js +0 -783
  81. package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +0 -38
  82. package/dist/prosemirror/commands/resolveAllTableChanges.js +0 -642
  83. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +0 -13
  84. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +0 -45
  85. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +0 -8
  86. package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -56
  87. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +0 -60
  88. package/dist/prosemirror/commands/tableMergeFoldDecisions.js +0 -78
  89. package/dist/prosemirror/rejoinRunCarriers.d.ts +0 -42
  90. package/dist/prosemirror/rejoinRunCarriers.js +0 -65
  91. package/dist/prosemirror/runPropertyChangeResolution.d.ts +0 -15
  92. package/dist/prosemirror/runPropertyChangeResolution.js +0 -34
@@ -4,6 +4,54 @@ import { paraIdAttribute } from "../../paraIdAttribute.js";
4
4
  import { getLocalName } from "../../xmlParser.js";
5
5
  import { MARKUP_COMPATIBILITY_NAMESPACE, MATH_NAMESPACE, elementChildren, relationshipAttr, twipsOrNull, wAttr, wChild, wChildVal, wName } from "./xml.js";
6
6
  // src/docx/server/templatePlan/story.ts
7
+ /** What a horizontal position is counted from when it is fixed to the page
8
+ * rather than to the text the drawing is anchored in. */
9
+ const PAGE_FIXED = /* @__PURE__ */ new Set([
10
+ "page",
11
+ "margin",
12
+ "leftMargin",
13
+ "rightMargin",
14
+ "insideMargin",
15
+ "outsideMargin"
16
+ ]);
17
+ const SHAPE_GRAPHIC = "wordprocessingShape";
18
+ /** What makes a drawing more than a mark: a picture, text of its own. */
19
+ const SHAPE_CONTENT = /* @__PURE__ */ new Set([
20
+ "pic",
21
+ "blip",
22
+ "txbx",
23
+ "txbxContent",
24
+ "linkedTxbx"
25
+ ]);
26
+ /**
27
+ * Whether an object of a paragraph is a drawn shape fixed to the page: a
28
+ * single shape without a picture and without text of its own (a rule, a
29
+ * dot, a line), floating, with its horizontal place counted from the page
30
+ * or a margin. Such a mark belongs to the layout of the page it was drawn
31
+ * on: when the text around it is set anew it stands where that page had it.
32
+ * A picture, a text box, a group, a chart, an inline drawing and a shape
33
+ * that follows its column, character or paragraph are none.
34
+ */
35
+ const isPageShape = (object) => {
36
+ let anchors = 0;
37
+ let fixed = false;
38
+ let plain = true;
39
+ let shapes = 0;
40
+ const stack = [object];
41
+ for (let element = stack.pop(); element !== void 0; element = stack.pop()) {
42
+ const local = getLocalName(element.name);
43
+ if (local === "Fallback") continue;
44
+ if (local === "anchor") anchors += 1;
45
+ else if (local === "inline") plain = false;
46
+ else if (local === "positionH") fixed = PAGE_FIXED.has(String(element.attributes?.["relativeFrom"] ?? ""));
47
+ else if (local === "graphicData") {
48
+ shapes += 1;
49
+ plain &&= String(element.attributes?.["uri"] ?? "").endsWith(SHAPE_GRAPHIC);
50
+ } else if (SHAPE_CONTENT.has(local)) plain = false;
51
+ stack.push(...elementChildren(element));
52
+ }
53
+ return anchors === 1 && shapes === 1 && fixed && plain;
54
+ };
7
55
  /** The mark a footnote or endnote reference leaves in a block's text. */
8
56
  const NOTE_REFERENCE_MARK = "";
9
57
  /**
@@ -18,14 +66,16 @@ const SELF_NUMBERING_FIELDS = /* @__PURE__ */ new Set([
18
66
  ]);
19
67
  /** Whether a field kind prints a number of its own and caches no text. */
20
68
  const isSelfNumberingField = (kind) => SELF_NUMBERING_FIELDS.has(kind);
21
- const createStoryState = () => ({
69
+ const createStoryState = (options = {}) => ({
22
70
  fields: [],
23
71
  open: [],
24
72
  paragraphOrdinal: 0,
25
73
  comments: 0,
26
74
  trackedChanges: 0,
27
75
  formattingRevisions: 0,
28
- strayFieldEnds: 0
76
+ strayFieldEnds: 0,
77
+ keepsRevisions: options.keepsRevisions === true,
78
+ untaggedRevisions: 0
29
79
  });
30
80
  /** A bookmark start, with how many atoms of its paragraph come before it. */
31
81
  /**
@@ -51,6 +101,24 @@ const ownIndent = (indent) => {
51
101
  firstLine: hanging === null ? twipsOrNull(wAttr(indent, "firstLine")) : -hanging
52
102
  };
53
103
  };
104
+ const SWITCHED_ON = /* @__PURE__ */ new Set([
105
+ "1",
106
+ "true",
107
+ "on"
108
+ ]);
109
+ /**
110
+ * The space in front of a paragraph and behind it as its own `w:spacing`
111
+ * states it in twentieths of a point. A side set to follow the application
112
+ * (`beforeAutospacing`) or counted in lines (`beforeLines`) is not such a
113
+ * measure and reads as not stated.
114
+ */
115
+ const ownSpacing = (spacing) => {
116
+ const side = (name) => SWITCHED_ON.has(wAttr(spacing, `${name}Autospacing`) ?? "") || wAttr(spacing, `${name}Lines`) !== null ? null : twipsOrNull(wAttr(spacing, name));
117
+ return {
118
+ before: side("before"),
119
+ after: side("after")
120
+ };
121
+ };
54
122
  const TOGGLE_OFF = /* @__PURE__ */ new Set([
55
123
  "0",
56
124
  "false",
@@ -186,23 +254,66 @@ const beginField = (walk, instruction) => {
186
254
  read.fieldIndices.push(field.index);
187
255
  return field;
188
256
  };
189
- const readRun = (run, walk, { link }) => {
257
+ /** What a deleted run holds as text; null for content that is none. */
258
+ const deletedTextOf = (child) => {
259
+ switch (wName(child)) {
260
+ case "delText": return textOf(child);
261
+ case "tab": return " ";
262
+ case "cr": return "\n";
263
+ case "br": return wAttr(child, "type") === null ? "\n" : null;
264
+ default: return null;
265
+ }
266
+ };
267
+ /** A deleted run, read as one atom that holds what was deleted. */
268
+ const readDeletedRun = (run, walk, { link, revision }) => {
269
+ let deleted = "";
270
+ for (const child of elementChildren(run)) {
271
+ const name = wName(child);
272
+ const text = deletedTextOf(child);
273
+ if (text !== null) deleted += text;
274
+ else if (name !== "rPr" && name !== "lastRenderedPageBreak") walk.state.untaggedRevisions += 1;
275
+ }
276
+ if (deleted !== "") pushAtom(walk, {
277
+ kind: "text",
278
+ text: "",
279
+ runProperties: wChild(run, "rPr"),
280
+ link,
281
+ element: null,
282
+ revision: {
283
+ ...revision,
284
+ deleted
285
+ }
286
+ });
287
+ };
288
+ const readRun = (run, walk, context) => {
289
+ const { link, revision } = context;
190
290
  const { state, read } = walk;
191
291
  const runProperties = wChild(run, "rPr");
192
292
  if (wChild(runProperties, "rPrChange") !== null) state.formattingRevisions += 1;
293
+ if (revision?.kind === "del") {
294
+ readDeletedRun(run, walk, {
295
+ link,
296
+ revision
297
+ });
298
+ return;
299
+ }
193
300
  const atom = (kind, text, element) => {
194
301
  pushAtom(walk, {
195
302
  kind,
196
303
  text,
197
304
  runProperties,
198
305
  link,
199
- element
306
+ element,
307
+ ...revision === void 0 ? {} : { revision }
200
308
  });
201
309
  };
202
310
  const object = (element) => {
203
311
  if (inCode(state)) return;
204
312
  read.inlineObjects += 1;
205
- state.trackedChanges += countContentRevisions(element);
313
+ read.pageShapes += isPageShape(element) ? 1 : 0;
314
+ const inside = countContentRevisions(element);
315
+ state.trackedChanges += inside;
316
+ state.untaggedRevisions += state.keepsRevisions ? inside : 0;
206
317
  atom("object", "", element);
207
318
  };
208
319
  for (const child of elementChildren(run)) {
@@ -290,6 +401,15 @@ const readRun = (run, walk, { link }) => {
290
401
  }
291
402
  }
292
403
  };
404
+ /** The tag of an inline insertion or deletion; null for a move. */
405
+ const revisionOf = (element, name) => {
406
+ if (name !== "ins" && name !== "del") return null;
407
+ return {
408
+ kind: name,
409
+ author: wAttr(element, "author") ?? "",
410
+ date: wAttr(element, "date")
411
+ };
412
+ };
293
413
  const readInline = (container, walk, context) => {
294
414
  const { state, read } = walk;
295
415
  for (const child of elementChildren(container)) {
@@ -297,13 +417,16 @@ const readInline = (container, walk, context) => {
297
417
  if (name === null) {
298
418
  if (child.namespaceUri === MATH_NAMESPACE && !inCode(state) && (getLocalName(child.name) === "oMath" || getLocalName(child.name) === "oMathPara")) {
299
419
  read.inlineObjects += 1;
300
- state.trackedChanges += countContentRevisions(child);
420
+ const inside = countContentRevisions(child);
421
+ state.trackedChanges += inside;
422
+ state.untaggedRevisions += state.keepsRevisions ? inside : 0;
301
423
  pushAtom(walk, {
302
424
  kind: "object",
303
425
  text: "",
304
426
  runProperties: null,
305
427
  link: context.link,
306
- element: child
428
+ element: child,
429
+ ...context.revision === void 0 ? {} : { revision: context.revision }
307
430
  });
308
431
  } else if (!inCode(state)) read.unsupported.push(child.name ?? "");
309
432
  continue;
@@ -341,11 +464,27 @@ const readInline = (container, walk, context) => {
341
464
  element: null,
342
465
  instruction: field.instruction.trim()
343
466
  });
344
- } else if (REVISION_INCLUDED.has(name)) {
467
+ } else if (REVISION_INCLUDED.has(name) || REVISION_EXCLUDED.has(name)) {
345
468
  state.trackedChanges += 1;
346
- readInline(child, walk, context);
347
- } else if (REVISION_EXCLUDED.has(name)) state.trackedChanges += 1;
348
- else if (name === "sdt") {
469
+ const kept = state.keepsRevisions ? revisionOf(child, name) : null;
470
+ const outer = context.revision;
471
+ if (kept !== null && outer !== void 0) {
472
+ if (kept.kind === "del" && outer.kind === "ins" && !outer.within) kept.within = {
473
+ author: outer.author,
474
+ date: outer.date
475
+ };
476
+ else state.untaggedRevisions += 1;
477
+ }
478
+ if (kept !== null) {
479
+ readInline(child, walk, {
480
+ ...context,
481
+ revision: kept
482
+ });
483
+ continue;
484
+ }
485
+ state.untaggedRevisions += state.keepsRevisions ? 1 : 0;
486
+ if (REVISION_INCLUDED.has(name)) readInline(child, walk, context);
487
+ } else if (name === "sdt") {
349
488
  const content = wChild(child, "sdtContent");
350
489
  if (content !== null) readInline(content, walk, context);
351
490
  } else if (TRANSPARENT_WRAPPERS.has(name)) readInline(child, walk, context);
@@ -361,6 +500,28 @@ const readInline = (container, walk, context) => {
361
500
  else if (!IGNORED_INLINE_CHILDREN.has(name) && !inCode(state)) read.unsupported.push(name);
362
501
  }
363
502
  };
503
+ /**
504
+ * The paragraph mark's own revision, in a reading that keeps them. An
505
+ * inserted mark is an atom at the paragraph's end. A deleted one was joined
506
+ * to the next paragraph before the reading; one still here had none to join.
507
+ */
508
+ const readTrackedMark = (mark, walk) => {
509
+ const inserted = wChild(mark, "ins");
510
+ if (wChild(mark, "del") !== null) walk.state.untaggedRevisions += 1;
511
+ else if (inserted !== null) pushAtom(walk, {
512
+ kind: "text",
513
+ text: "",
514
+ runProperties: null,
515
+ link: null,
516
+ element: null,
517
+ revision: {
518
+ kind: "ins",
519
+ author: wAttr(inserted, "author") ?? "",
520
+ date: wAttr(inserted, "date"),
521
+ mark: true
522
+ }
523
+ });
524
+ };
364
525
  /** Read one `w:p`, advancing the story's field and revision state. */
365
526
  const readParagraph = (element, state) => {
366
527
  const properties = wChild(element, "pPr");
@@ -384,10 +545,12 @@ const readParagraph = (element, state) => {
384
545
  bookmarks: [],
385
546
  bookmarkEnds: [],
386
547
  inlineObjects: 0,
548
+ pageShapes: 0,
387
549
  unsupported: [],
388
550
  hasSectionBreak: wChild(properties, "sectPr") !== null,
389
551
  pageBreakBefore: toggleOf(wChild(properties, "pageBreakBefore")),
390
552
  alignment: wChildVal(properties, "jc"),
553
+ spacing: ownSpacing(wChild(properties, "spacing")),
391
554
  indent: ownIndent(wChild(properties, "ind")),
392
555
  indentInCharacters: CHARACTER_INDENTS.some((name) => {
393
556
  const value = wAttr(wChild(properties, "ind"), name);
@@ -403,6 +566,7 @@ const readParagraph = (element, state) => {
403
566
  };
404
567
  for (const open of state.open) if (open.phase === "result" && open.field.result !== "") open.field.result += "\n";
405
568
  readInline(element, walk, { link: null });
569
+ if (state.keepsRevisions) readTrackedMark(mark, walk);
406
570
  read.text = read.atoms.map(({ text }) => text).join("");
407
571
  return read;
408
572
  };
@@ -495,4 +659,4 @@ const walkBlocks = (container, visitor, depth = 0) => {
495
659
  } else if (name === null || !IGNORED_BLOCK_CHILDREN.has(name)) visitor.unread(child);
496
660
  }
497
661
  };
498
- export { NOTE_REFERENCE_MARK, createStoryState, endStory, isSelfNumberingField, readParagraph, toggleOf, walkBlocks };
662
+ export { NOTE_REFERENCE_MARK, createStoryState, endStory, isPageShape, isSelfNumberingField, readParagraph, toggleOf, walkBlocks };
@@ -29,12 +29,57 @@ export type DocxBlockNumbering = {
29
29
  */
30
30
  bulletFont?: string;
31
31
  };
32
+ /**
33
+ * A `REF` field of a paragraph (ECMA-376 Part 1, 17.16.5.52). Without a
34
+ * number switch it shows the content of the bookmark it names; with one,
35
+ * the number of the paragraph the bookmark stands in. A plan that places
36
+ * the paragraph the bookmark marks can keep the field a field: a
37
+ * `TemplatePlanReference` over its span to that paragraph, with its
38
+ * switches and its result.
39
+ */
40
+ export type DocxBlockCrossReference = {
41
+ /** The span of the paragraph's `text` the field's result takes. */
42
+ start: number;
43
+ end: number;
44
+ /** The field's code as the document states it, e.g. ` REF Annex3 \h `. */
45
+ instruction: string;
46
+ /** The bookmark the field names. */
47
+ bookmark: string;
48
+ /**
49
+ * The paragraph of the main story the bookmark starts and ends in. Null
50
+ * when no bookmark of that name does both in one paragraph: it spans
51
+ * paragraphs, stands between blocks, or is not there.
52
+ */
53
+ targetBlockId: string | null;
54
+ /**
55
+ * Whether the bookmark holds all of that paragraph's content, so that a
56
+ * field without a number switch shows the paragraph's text, which is
57
+ * what a plan's own bookmark on the paragraph holds.
58
+ */
59
+ targetWhole: boolean;
60
+ };
32
61
  export type DocxTableCell = {
33
62
  row: number;
34
63
  col: number;
35
64
  /** Ids of the blocks directly inside the cell, in order. */
36
65
  blockIds: string[];
37
66
  };
67
+ /**
68
+ * A tracked change inside a paragraph, by where it sits in the paragraph's
69
+ * `text`. An insertion spans the text it added. A deletion takes no place
70
+ * in a text read with the changes accepted: its `start` and `end` are the
71
+ * one offset it was made at. A change of the paragraph mark sits at the
72
+ * offset the mark stands or stood at.
73
+ */
74
+ export type DocxBlockRevision = {
75
+ kind: "insertion" | "deletion";
76
+ start: number;
77
+ end: number;
78
+ author: string;
79
+ date: string | null;
80
+ /** The change is of a paragraph mark, not of text. */
81
+ paragraphMark?: true;
82
+ };
38
83
  /**
39
84
  * One block of the main story. `text` is the visible text: `\t` for a tab,
40
85
  * `\n` for a line break, U+FFFC for a footnote or endnote reference mark;
@@ -61,6 +106,14 @@ export type DocxBlock = {
61
106
  paraId?: string;
62
107
  /** Drawings, pictures, embedded objects and equations anchored in the block. */
63
108
  inlineObjects: number;
109
+ /**
110
+ * How many of them are drawn shapes fixed to the page, when the block
111
+ * holds any: a single floating shape without a picture and without text
112
+ * of its own (a rule, a dot, a line) whose horizontal place is counted
113
+ * from the page or a margin. Such a mark belongs to the layout of the
114
+ * page it was drawn on; a plan may leave it out (`dropPageShapes`).
115
+ */
116
+ pageShapes?: number;
64
117
  /**
65
118
  * Page breaks among the paragraph's runs, when it holds any. A paragraph
66
119
  * without text can hold one: it is then all that starts the next page.
@@ -73,6 +126,19 @@ export type DocxBlock = {
73
126
  * offset 6 reads `Annex 1 - Summary` on the page.
74
127
  */
75
128
  selfNumbers?: number[];
129
+ /**
130
+ * The tracked changes the paragraph holds, in a manifest read with the
131
+ * changes kept (`trackedChanges: "keep"`), in the order they stand. A
132
+ * plan takes care around them: a label is not stripped across one and a
133
+ * reference is not placed on one.
134
+ */
135
+ revisions?: DocxBlockRevision[];
136
+ /**
137
+ * The cross-reference fields of the paragraph, in the order they stand:
138
+ * each `REF` field whose result lies in the paragraph's text and in no
139
+ * other field. Absent without one.
140
+ */
141
+ crossReferences?: DocxBlockCrossReference[];
76
142
  /**
77
143
  * The paragraph starts on a new page by its own formatting or its
78
144
  * style's (`w:pageBreakBefore`). A plan carries it over with an item's
@@ -91,6 +157,13 @@ export type DocxBlock = {
91
157
  * Absent when neither states one.
92
158
  */
93
159
  alignment?: string;
160
+ /**
161
+ * The space the paragraph states for itself in front of and behind it
162
+ * (`w:spacing`, `before` and `after`), in twentieths of a point. A side
163
+ * it does not state is left out; absent when it states neither. What its
164
+ * style gives is not here: this is what the document set by hand.
165
+ */
166
+ spacing?: TemplatePlanSpacing;
94
167
  /**
95
168
  * The paragraph's indent in effect, in twentieths of a point: `left` is
96
169
  * where its lines start, `firstLine` what its first line adds to that
@@ -175,6 +248,11 @@ export type DocxBlockManifest = {
175
248
  trackedChangesResolved?: DocxTrackedChanges & {
176
249
  view: TemplatePlanTrackedView;
177
250
  };
251
+ /**
252
+ * What the document tracks, on a manifest read for a plan that keeps its
253
+ * tracked changes: the blocks are the accepted view's.
254
+ */
255
+ trackedChangesKept?: DocxTrackedChanges;
178
256
  warnings: string[];
179
257
  };
180
258
  /**
@@ -182,6 +260,16 @@ export type DocxBlockManifest = {
182
260
  * change accepted, or with every change rejected.
183
261
  */
184
262
  export type TemplatePlanTrackedView = "accept" | "reject";
263
+ /**
264
+ * What a plan does with the tracked changes of its source: formats one view
265
+ * of them, or keeps them (`keep`). A plan that keeps them is made for the
266
+ * accepted view's blocks; the output shows the same insertions and
267
+ * deletions, by the same authors, and tracks nothing new. So far only
268
+ * changes inside paragraphs are kept: a source with an inserted or deleted
269
+ * paragraph mark, table row or cell, or a move, is refused as
270
+ * `tracked-changes`.
271
+ */
272
+ export type TemplatePlanTrackedChanges = TemplatePlanTrackedView | "keep";
185
273
  /** The tracked changes of a document's main story and notes, by kind. */
186
274
  export type DocxTrackedChanges = {
187
275
  insertions: number;
@@ -374,6 +462,8 @@ export type TemplatePlanNestedParagraph = {
374
462
  /** As on a source item. */
375
463
  labelAsText?: boolean;
376
464
  /** As on a source item. */
465
+ dropPageShapes?: boolean;
466
+ /** As on a source item. */
377
467
  keepNext?: boolean;
378
468
  /** As on a source item. */
379
469
  indent?: TemplatePlanIndent;
@@ -381,9 +471,19 @@ export type TemplatePlanNestedParagraph = {
381
471
  tabStops?: number[];
382
472
  /** As on a source item. */
383
473
  alignment?: TemplatePlanAlignment;
474
+ /** As on a source item. */
475
+ spacing?: TemplatePlanSpacing;
384
476
  };
385
477
  /** How a paragraph's lines are set between the margins (`w:jc`). */
386
478
  export type TemplatePlanAlignment = "left" | "center" | "right" | "both";
479
+ /**
480
+ * The space in front of a paragraph and behind it (`w:spacing`), in
481
+ * twentieths of a point: at least one side. A side left out is the style's.
482
+ */
483
+ export type TemplatePlanSpacing = {
484
+ before?: number;
485
+ after?: number;
486
+ };
387
487
  /** A page other than the template's, in twentieths of a point. */
388
488
  export type TemplatePlanSectionPage = {
389
489
  orientation: "portrait" | "landscape";
@@ -438,6 +538,14 @@ export type TemplatePlanSourceItem = {
438
538
  * bullet glyph and not a number a language spells.
439
539
  */
440
540
  labelAsText?: boolean;
541
+ /**
542
+ * Write the paragraph without its drawn shapes that are fixed to the page
543
+ * (`pageShapes` of the block): marks of the page the source was laid out
544
+ * on, which would stand at that page's places in the output. Everything
545
+ * else the paragraph holds is placed as it is. The report counts what was
546
+ * left out.
547
+ */
548
+ dropPageShapes?: boolean;
441
549
  /** Join the next item of the plan, a source paragraph, into this paragraph. */
442
550
  mergeNext?: TemplatePlanMerge;
443
551
  /**
@@ -479,6 +587,12 @@ export type TemplatePlanSourceItem = {
479
587
  * cell or a centred line under a title. Not for a table.
480
588
  */
481
589
  alignment?: TemplatePlanAlignment;
590
+ /**
591
+ * The paragraph's own space in front of it and behind it (`w:spacing`),
592
+ * over what its style states: for a line the document sets tight or
593
+ * apart by itself, such as the rows of a table. Not for a table.
594
+ */
595
+ spacing?: TemplatePlanSpacing;
482
596
  /**
483
597
  * The paragraph is the last of a section, described here: for a part of
484
598
  * the document whose page is another than the template's, such as a
@@ -499,6 +613,20 @@ export type TemplatePlanItem = {
499
613
  kind: "slot";
500
614
  templateBlockId: string;
501
615
  sourceBlockIds: string[];
616
+ /**
617
+ * A lead of the first source block that the slot does not take: the
618
+ * name of a field the template shows itself (`To:` in front of an
619
+ * addressee, where the template has a cell that says so). The block
620
+ * must start with `text`. It and the blanks behind it are dropped;
621
+ * what follows is placed word for word and must be something.
622
+ * `shownByTemplateBlockId` names the paragraph of the template that
623
+ * shows the field: one the plan keeps as it is, with text. The report
624
+ * names every lead dropped.
625
+ */
626
+ dropLead?: {
627
+ text: string;
628
+ shownByTemplateBlockId: string;
629
+ };
502
630
  };
503
631
  export type TemplatePlanNumberingPatch = {
504
632
  abstractNumId: number;
@@ -575,6 +703,14 @@ export type TemplatePlan = {
575
703
  * stands.
576
704
  */
577
705
  lastSection?: TemplatePlanSection;
706
+ /**
707
+ * Paragraphs inside kept template tables that are written without their
708
+ * text: a sample line of a header cell the document has nothing for (the
709
+ * third line of an address). The paragraph keeps its place and its
710
+ * properties. Each is a paragraph nested in a table the plan keeps, and
711
+ * none is filled by a slot.
712
+ */
713
+ emptyTemplateBlockIds?: string[];
578
714
  /**
579
715
  * The view of a source with tracked changes the plan is made for: its
580
716
  * text with every change accepted, or with every change rejected. The
@@ -582,7 +718,7 @@ export type TemplatePlan = {
582
718
  * no revision, and verification holds it to that view. Left out, a
583
719
  * source with tracked changes is refused.
584
720
  */
585
- trackedChanges?: TemplatePlanTrackedView;
721
+ trackedChanges?: TemplatePlanTrackedChanges;
586
722
  /**
587
723
  * What becomes of text effects whose values show nothing, in the parts
588
724
  * the output takes from the template: its document, numbering, styles,
@@ -607,6 +743,14 @@ export type TemplatePlanBlockResult = {
607
743
  emphasis: "identical" | "mismatch" | "omitted";
608
744
  /** What `stripLabel` removed, the following space included. */
609
745
  strippedPrefix?: string;
746
+ /**
747
+ * The lead a slot's `dropLead` took off the block, the blanks behind it
748
+ * included, and the kept paragraph of the template that shows the field.
749
+ */
750
+ droppedLead?: {
751
+ text: string;
752
+ shownByTemplateBlockId: string;
753
+ };
610
754
  /** The automatic label `labelAsText` wrote as text, without what follows it. */
611
755
  labelAsText?: string;
612
756
  /** The label the source showed: its automatic label, else the stripped one. */
@@ -673,6 +817,11 @@ export type TemplatePlanReport = {
673
817
  trackedChanges?: DocxTrackedChanges & {
674
818
  view: TemplatePlanTrackedView;
675
819
  };
820
+ /**
821
+ * What the source tracks, when the plan kept its tracked changes: the
822
+ * output shows the same insertions and deletions by the same authors.
823
+ */
824
+ trackedChangesKept?: DocxTrackedChanges;
676
825
  /** One entry per block of the source, nested ones included, in document order. */
677
826
  blocks: TemplatePlanBlockResult[];
678
827
  counts: {
@@ -737,6 +886,9 @@ export type TemplatePlanReport = {
737
886
  }[];
738
887
  internalHyperlinks: number;
739
888
  sectionBreaks: number;
889
+ /** Drawn shapes fixed to the page that placed paragraphs were written
890
+ * without, as their items asked (`dropPageShapes`). */
891
+ pageShapes: number;
740
892
  };
741
893
  /**
742
894
  * Text effects that show nothing: those of the template the output does