@stll/folio-core 0.71.1 → 0.73.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 (213) hide show
  1. package/README.md +14 -8
  2. package/dist/ai-edits/apply.d.ts +6 -114
  3. package/dist/ai-edits/apply.js +9 -131
  4. package/dist/ai-edits/applyTypes.d.ts +85 -0
  5. package/dist/ai-edits/applyTypes.js +24 -0
  6. package/dist/ai-edits/clean-text.d.ts +7 -1
  7. package/dist/ai-edits/clean-text.js +23 -2
  8. package/dist/ai-edits/finalSectionReview.d.ts +1 -1
  9. package/dist/ai-edits/headless.d.ts +29 -147
  10. package/dist/ai-edits/headless.js +213 -1634
  11. package/dist/ai-edits/index.d.ts +3 -3
  12. package/dist/ai-edits/index.js +2 -3
  13. package/dist/ai-edits/pending-suggestions.d.ts +14 -4
  14. package/dist/ai-edits/pending-suggestions.js +183 -90
  15. package/dist/ai-edits/result-validation.js +1 -1
  16. package/dist/ai-edits/retired-comment-receipts.d.ts +1 -1
  17. package/dist/ai-edits/snapshot.js +8 -3
  18. package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
  19. package/dist/ai-edits/table-cell-mutations.js +1 -1
  20. package/dist/ai-edits/table-geometry.d.ts +1 -1
  21. package/dist/ai-edits/table-geometry.js +1 -1
  22. package/dist/ai-edits/table-row-column-mutations.d.ts +1 -1
  23. package/dist/ai-edits/table-row-column-mutations.js +1 -1
  24. package/dist/ai-edits/tableNodes.d.ts +38 -0
  25. package/dist/ai-edits/tableNodes.js +86 -0
  26. package/dist/ai-edits/tracked-batch-fidelity.d.ts +1 -1
  27. package/dist/ai-edits/undefinedReferences.d.ts +7 -0
  28. package/dist/canonical/batchCommentReferences.js +1 -0
  29. package/dist/canonical/canonicalInlineProjection.js +1 -1
  30. package/dist/canonical/canonicalPublicOperations.js +228 -64
  31. package/dist/canonical/canonicalSession.d.ts +9 -1
  32. package/dist/canonical/canonicalSession.js +95 -15
  33. package/dist/compare/compare.d.ts +1 -1
  34. package/dist/compare/inline-atoms-model.d.ts +1 -1
  35. package/dist/compare/inline-atoms.d.ts +2 -2
  36. package/dist/compare/inline-provenance-model.d.ts +1 -1
  37. package/dist/compare/inline-provenance.d.ts +2 -2
  38. package/dist/compat/eigenpal.d.ts +3 -4
  39. package/dist/compat/eigenpal.js +2 -4
  40. package/dist/controller/canonicalClipboard.d.ts +13 -3
  41. package/dist/controller/canonicalClipboard.js +185 -49
  42. package/dist/controller/canonicalClipboardResources.d.ts +9 -1
  43. package/dist/controller/canonicalClipboardResources.js +22 -2
  44. package/dist/controller/canonicalReview.d.ts +1 -1
  45. package/dist/controller/canonicalReview.js +1 -1
  46. package/dist/controller/canonicalStructure.js +1 -1
  47. package/dist/controller/canonicalWatermark.d.ts +10 -0
  48. package/dist/controller/canonicalWatermark.js +37 -0
  49. package/dist/controller/canonicalYjsRoom.d.ts +1 -1
  50. package/dist/controller/headerFooterEditorManager.d.ts +11 -7
  51. package/dist/controller/headerFooterEditorManager.js +39 -151
  52. package/dist/controller/hiddenEditorApi.d.ts +1 -1
  53. package/dist/controller/hiddenEditorManager.d.ts +6 -40
  54. package/dist/controller/hiddenEditorManager.js +173 -306
  55. package/dist/controller/noteEditorManager.d.ts +3 -10
  56. package/dist/controller/noteEditorManager.js +33 -206
  57. package/dist/document-operations-apply.d.ts +15 -0
  58. package/dist/document-operations-apply.js +280 -0
  59. package/dist/document-operations.d.ts +1 -14
  60. package/dist/document-operations.js +2 -279
  61. package/dist/docx/modelValidation.js +1 -1
  62. package/dist/docx/paragraphParser.js +2 -2
  63. package/dist/docx/paragraphPropertySource.d.ts +1 -1
  64. package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
  65. package/dist/docx/reviewResolutionProvenance.js +32 -9
  66. package/dist/docx/revisionIdNormalization.js +30 -7
  67. package/dist/docx/rezip.js +1 -1
  68. package/dist/docx/serializer/borderSerializer.js +1 -1
  69. package/dist/docx/serializer/commentSerializer.js +1 -1
  70. package/dist/docx/serializer/documentSerializer.js +1 -1
  71. package/dist/docx/serializer/paragraphSerializer.js +3 -3
  72. package/dist/docx/serializer/runSerializer.js +1 -1
  73. package/dist/docx/serializer/sectionPropertiesSerializer.js +1 -1
  74. package/dist/docx/serializer/tableSerializer.js +5 -37
  75. package/dist/docx/serializer/textFormattingSerializer.js +1 -1
  76. package/dist/docx/serializer/trackedChangeAttributes.js +1 -1
  77. package/dist/docx/server/templatePlan/apply.d.ts +15 -0
  78. package/dist/docx/server/templatePlan/apply.js +600 -0
  79. package/dist/docx/server/templatePlan/blocks.d.ts +97 -0
  80. package/dist/docx/server/templatePlan/blocks.js +355 -0
  81. package/dist/docx/server/templatePlan/builders.d.ts +72 -0
  82. package/dist/docx/server/templatePlan/builders.js +237 -0
  83. package/dist/docx/server/templatePlan/emit.d.ts +118 -0
  84. package/dist/docx/server/templatePlan/emit.js +466 -0
  85. package/dist/docx/server/templatePlan/emphasis.d.ts +62 -0
  86. package/dist/docx/server/templatePlan/emphasis.js +173 -0
  87. package/dist/docx/server/templatePlan/inspect.d.ts +22 -0
  88. package/dist/docx/server/templatePlan/inspect.js +177 -0
  89. package/dist/docx/server/templatePlan/labels.d.ts +36 -0
  90. package/dist/docx/server/templatePlan/labels.js +126 -0
  91. package/dist/docx/server/templatePlan/package.d.ts +34 -0
  92. package/dist/docx/server/templatePlan/package.js +99 -0
  93. package/dist/docx/server/templatePlan/plan.d.ts +143 -0
  94. package/dist/docx/server/templatePlan/plan.js +841 -0
  95. package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
  96. package/dist/docx/server/templatePlan/planShape.js +161 -0
  97. package/dist/docx/server/templatePlan/resources.d.ts +41 -0
  98. package/dist/docx/server/templatePlan/resources.js +136 -0
  99. package/dist/docx/server/templatePlan/story.d.ts +128 -0
  100. package/dist/docx/server/templatePlan/story.js +440 -0
  101. package/dist/docx/server/templatePlan/types.d.ts +406 -0
  102. package/dist/docx/server/templatePlan/types.js +28 -0
  103. package/dist/docx/server/templatePlan/verify.d.ts +40 -0
  104. package/dist/docx/server/templatePlan/verify.js +968 -0
  105. package/dist/docx/server/templatePlan/xml.d.ts +69 -0
  106. package/dist/docx/server/templatePlan/xml.js +119 -0
  107. package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
  108. package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
  109. package/dist/docx/storyBlockReplay.js +1 -1
  110. package/dist/docx/structuralXmlPatch.js +9 -1
  111. package/dist/docx/tableGridXml.d.ts +30 -0
  112. package/dist/docx/tableGridXml.js +54 -0
  113. package/dist/docx/tableParser.js +7 -0
  114. package/dist/docx/xmlParser.js +1 -1
  115. package/dist/index.d.ts +3 -4
  116. package/dist/index.js +2 -4
  117. package/dist/internal/paragraphFormattingSerialization.js +1 -1
  118. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  119. package/dist/managers/ContextMenuManager.js +2 -1
  120. package/dist/managers/DocumentLoaderManager.d.ts +0 -4
  121. package/dist/managers/DocumentLoaderManager.js +4 -12
  122. package/dist/managers/editorShortcuts.d.ts +1 -1
  123. package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
  124. package/dist/prosemirror/canonicalCommands.d.ts +1 -1
  125. package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
  126. package/dist/prosemirror/canonicalTableCommands.js +2 -2
  127. package/dist/prosemirror/commands/comments.js +3 -3
  128. package/dist/prosemirror/commands/contentControls.d.ts +1 -1
  129. package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
  130. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  131. package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
  132. package/dist/prosemirror/commands/sectionBreak.js +1 -1
  133. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
  134. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +1 -1
  135. package/dist/prosemirror/commentRecords.d.ts +1 -1
  136. package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
  137. package/dist/prosemirror/conversion/fromProseDoc.js +1 -1
  138. package/dist/prosemirror/documentStructureCounts.d.ts +24 -0
  139. package/dist/prosemirror/documentStructureCounts.js +76 -0
  140. package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
  141. package/dist/prosemirror/extensions/StarterKit.d.ts +1 -1
  142. package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +1 -7
  143. package/dist/prosemirror/extensions/core/HistoryExtension.js +5 -13
  144. package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -1
  145. package/dist/prosemirror/extensions/core/historyCommands.d.ts +16 -0
  146. package/dist/prosemirror/extensions/core/historyCommands.js +19 -0
  147. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
  148. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +2 -35
  149. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +4 -142
  150. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +3 -87
  151. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +7 -162
  152. package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
  153. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
  154. package/dist/prosemirror/extensions/marks/markUtils.d.ts +1 -1
  155. package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
  156. package/dist/prosemirror/extensions/nodes/TableExtension.js +2 -2
  157. package/dist/prosemirror/extensions/types.d.ts +1 -1
  158. package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
  159. package/dist/prosemirror/hyperlinkRemoval.d.ts +1 -1
  160. package/dist/prosemirror/index.d.ts +1 -1
  161. package/dist/prosemirror/index.js +1 -1
  162. package/dist/prosemirror/insertionGaps.d.ts +1 -1
  163. package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
  164. package/dist/prosemirror/listNumbering.d.ts +1 -1
  165. package/dist/prosemirror/lockedControls.d.ts +1 -1
  166. package/dist/prosemirror/markupViewProjection.d.ts +1 -1
  167. package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
  168. package/dist/prosemirror/noteReferenceReview.js +1 -1
  169. package/dist/prosemirror/numberingAttr.d.ts +1 -2
  170. package/dist/prosemirror/numberingAttr.js +1 -2
  171. package/dist/prosemirror/outlineLevelAttr.d.ts +1 -2
  172. package/dist/prosemirror/outlineLevelAttr.js +1 -2
  173. package/dist/prosemirror/paraIds.d.ts +46 -0
  174. package/dist/prosemirror/paraIds.js +152 -0
  175. package/dist/prosemirror/paragraphChangeTrackerMeta.d.ts +97 -0
  176. package/dist/prosemirror/paragraphChangeTrackerMeta.js +87 -0
  177. package/dist/prosemirror/paragraphMarkJoin.d.ts +1 -1
  178. package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -1
  179. package/dist/prosemirror/pastedCommentCopies.d.ts +1 -1
  180. package/dist/prosemirror/pastedCommentCopies.js +1 -1
  181. package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
  182. package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
  183. package/dist/prosemirror/plugins/suggestionMode.d.ts +1 -1
  184. package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
  185. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
  186. package/dist/prosemirror/rebaseParagraphRuns.d.ts +1 -1
  187. package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
  188. package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
  189. package/dist/prosemirror/replacedAnnotations.js +16 -1
  190. package/dist/prosemirror/revisionCarriers.d.ts +1 -1
  191. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
  192. package/dist/prosemirror/sectionMarkEdits.d.ts +1 -1
  193. package/dist/prosemirror/selectionBounds.d.ts +10 -0
  194. package/dist/prosemirror/selectionBounds.js +22 -0
  195. package/dist/prosemirror/storyListNumbering.d.ts +1 -1
  196. package/dist/prosemirror/tableCellPaste.d.ts +1 -1
  197. package/dist/prosemirror/tableGridMutation.d.ts +1 -1
  198. package/dist/prosemirror/textInput.d.ts +1 -1
  199. package/dist/server.d.ts +7 -5
  200. package/dist/server.js +6 -4
  201. package/dist/types/canonicalCapabilities.d.ts +8 -41
  202. package/dist/types/canonicalCapabilities.js +6 -34
  203. package/package.json +4 -6
  204. package/dist/controller/collaborationModules.d.ts +0 -3
  205. package/dist/controller/collaborationModules.js +0 -14
  206. package/dist/docx/server/materializeYjsDocx.d.ts +0 -30
  207. package/dist/docx/server/materializeYjsDocx.js +0 -96
  208. package/dist/docx/server/migrateYjsAttrSchema.d.ts +0 -53
  209. package/dist/docx/server/migrateYjsAttrSchema.js +0 -111
  210. package/dist/prosemirror/plugins/derivedFields.d.ts +0 -8
  211. package/dist/prosemirror/plugins/derivedFields.js +0 -52
  212. package/dist/prosemirror/yjsDocumentMetadata.d.ts +0 -89
  213. package/dist/prosemirror/yjsDocumentMetadata.js +0 -697
@@ -0,0 +1,406 @@
1
+ import { FolioDocxConformanceIssue } from "../validateDocxConformance.js";
2
+ import { TaggedErrorClass } from "better-result";
3
+ /** Why a template plan call stopped; every refusal names one of these. */
4
+ export declare const TEMPLATE_PLAN_ERROR_CODES: readonly ["archive-unreadable", "part-missing", "xml-unreadable", "plan-invalid", "sha-mismatch", "unknown-block", "hash-mismatch", "block-unplaced", "block-placed-twice", "strip-label-mismatch", "merge-invalid", "reference-span-invalid", "reference-target-unplaced", "highlight-span-invalid", "numbering-unknown", "style-unknown", "tracked-changes", "unsupported-content", "verification-failed"];
5
+ export type TemplatePlanErrorCode = (typeof TEMPLATE_PLAN_ERROR_CODES)[number];
6
+ declare const TemplatePlanErrorBase: TaggedErrorClass<"TemplatePlanError">;
7
+ /** A refused analysis, plan or output. `report` is set for `verification-failed`. */
8
+ export declare class TemplatePlanError extends TemplatePlanErrorBase<{
9
+ message: string;
10
+ code: TemplatePlanErrorCode;
11
+ blockId?: string;
12
+ part?: string;
13
+ report?: TemplatePlanReport;
14
+ cause?: unknown;
15
+ }> {}
16
+ export type DocxBlockNumbering = {
17
+ numId: number;
18
+ ilvl: number;
19
+ abstractNumId: number;
20
+ };
21
+ export type DocxTableCell = {
22
+ row: number;
23
+ col: number;
24
+ /** Ids of the blocks directly inside the cell, in order. */
25
+ blockIds: string[];
26
+ };
27
+ /**
28
+ * One block of the main story. `text` is the visible text: `\t` for a tab,
29
+ * `\n` for a line break, U+FFFC for a footnote or endnote reference mark;
30
+ * field results are included and field instructions are not. Offsets into
31
+ * `text` are UTF-16 code units.
32
+ */
33
+ export type DocxBlock = {
34
+ /** `p<index>` for a paragraph, `t<index>` for a table. */
35
+ id: string;
36
+ /** Position among all blocks of the story in document order, nested ones included. */
37
+ index: number;
38
+ kind: "paragraph" | "table";
39
+ text: string;
40
+ /** The automatic list label as rendered, or null when the block is not numbered. */
41
+ label: string | null;
42
+ numbering: DocxBlockNumbering | null;
43
+ styleId: string | null;
44
+ styleName: string | null;
45
+ outlineLevel: number | null;
46
+ sectionIndex: number;
47
+ /** Short hash of `text` and `label`; a plan pins a block with it. */
48
+ hash: string;
49
+ /** `w14:paraId` when the package states one. Informational. */
50
+ paraId?: string;
51
+ /** Drawings, pictures, embedded objects and equations anchored in the block. */
52
+ inlineObjects: number;
53
+ /** Table only: its cells in row order. */
54
+ cells?: DocxTableCell[];
55
+ /** Table only: every block inside the table in document order. */
56
+ nested?: DocxBlock[];
57
+ };
58
+ export type DocxNote = {
59
+ id: string;
60
+ text: string;
61
+ };
62
+ export type DocxBlockManifest = {
63
+ sha256: string;
64
+ /** Top-level blocks of the main story in document order; a table is one block. */
65
+ blocks: DocxBlock[];
66
+ footnotes: DocxNote[];
67
+ endnotes: DocxNote[];
68
+ comments: number;
69
+ /** Tracked insertions, deletions and moves in the main story and its notes. */
70
+ trackedChanges: number;
71
+ warnings: string[];
72
+ };
73
+ export type DocxTemplateStyle = {
74
+ styleId: string;
75
+ name: string | null;
76
+ type: "paragraph" | "character" | "numbering" | "table";
77
+ basedOn: string | null;
78
+ /** The list the style binds its paragraphs to, inheritance resolved. */
79
+ numPr: {
80
+ numId: number;
81
+ ilvl: number;
82
+ } | null;
83
+ outlineLvl: number | null;
84
+ isDefault: boolean;
85
+ };
86
+ export type DocxTemplateNumberingLevel = {
87
+ ilvl: number;
88
+ numFmt: string;
89
+ lvlText: string;
90
+ start: number;
91
+ suff: "tab" | "space" | "nothing";
92
+ pStyle: string | null;
93
+ };
94
+ export type DocxTemplateNumbering = {
95
+ abstractNums: {
96
+ abstractNumId: number;
97
+ levels: DocxTemplateNumberingLevel[];
98
+ }[];
99
+ nums: {
100
+ numId: number;
101
+ abstractNumId: number;
102
+ overrides: {
103
+ ilvl: number;
104
+ startOverride: number | null;
105
+ }[];
106
+ }[];
107
+ };
108
+ export type DocxTemplateField = {
109
+ /** Package path of the part holding the field. */
110
+ part: string;
111
+ instruction: string;
112
+ /** The field name in upper case, e.g. `TOC`, `REF`, `FILLIN`, `DATE`. */
113
+ kind: string;
114
+ /** The cached result text. */
115
+ result: string;
116
+ /** Main story only: the top-level block the field starts in. */
117
+ blockId?: string;
118
+ /**
119
+ * Main story only: the top-level block the field ends in. A plan keeps
120
+ * every block from `blockId` to this one, or none of them.
121
+ */
122
+ endBlockId?: string;
123
+ };
124
+ export type DocxTemplateSection = {
125
+ index: number;
126
+ orientation: "portrait" | "landscape";
127
+ /** Page size and margins in twentieths of a point. */
128
+ size: {
129
+ width: number | null;
130
+ height: number | null;
131
+ };
132
+ margins: {
133
+ top: number | null;
134
+ right: number | null;
135
+ bottom: number | null;
136
+ left: number | null;
137
+ };
138
+ headers: {
139
+ type: string;
140
+ part: string | null;
141
+ }[];
142
+ footers: {
143
+ type: string;
144
+ part: string | null;
145
+ }[];
146
+ };
147
+ export type DocxTemplateBookmark = {
148
+ name: string;
149
+ id: string;
150
+ part: string;
151
+ };
152
+ export type DocxTemplateInspection = DocxBlockManifest & {
153
+ styles: DocxTemplateStyle[];
154
+ numbering: DocxTemplateNumbering;
155
+ fields: DocxTemplateField[];
156
+ sections: DocxTemplateSection[];
157
+ bookmarks: DocxTemplateBookmark[];
158
+ };
159
+ export type TemplatePlanOmitReason = "empty" | "sourceToc" | "pageArtifact" | "duplicateLabel";
160
+ /**
161
+ * The list a source paragraph joins.
162
+ *
163
+ * A number names a list of the template. `"new"` starts a list instance of
164
+ * its own over the definition `baseNumId` names, or over the list the item's
165
+ * style is bound to. Items sharing a `group` share the instance the first of
166
+ * them starts; `restartFrom` is the number that instance begins with.
167
+ */
168
+ export type TemplatePlanNumbering = {
169
+ numId: number | "new";
170
+ ilvl: number;
171
+ restartFrom?: number;
172
+ baseNumId?: number;
173
+ group?: string;
174
+ };
175
+ export type TemplatePlanMerge = "lineBreak" | "space" | "none";
176
+ export type TemplatePlanNestedParagraph = {
177
+ blockId: string;
178
+ styleId?: string;
179
+ numbering?: TemplatePlanNumbering | null;
180
+ stripLabel?: string;
181
+ };
182
+ export type TemplatePlanSourceItem = {
183
+ kind: "source";
184
+ blockId: string;
185
+ hash: string;
186
+ /** A paragraph style of the template; for a table, a table style. */
187
+ styleId?: string;
188
+ /** `null` takes the paragraph out of the list its style would put it in. */
189
+ numbering?: TemplatePlanNumbering | null;
190
+ /** The manual label at the start of the block to remove, with the space after it. */
191
+ stripLabel?: string;
192
+ /** Join the next item of the plan, a source paragraph, into this paragraph. */
193
+ mergeNext?: TemplatePlanMerge;
194
+ /** Table only: the paragraph style of its cells. */
195
+ cellStyleId?: string;
196
+ /** Table only: placement of single paragraphs inside it. */
197
+ nested?: TemplatePlanNestedParagraph[];
198
+ };
199
+ export type TemplatePlanItem = {
200
+ kind: "template";
201
+ templateBlockIds: string[];
202
+ } | TemplatePlanSourceItem | {
203
+ kind: "slot";
204
+ templateBlockId: string;
205
+ sourceBlockIds: string[];
206
+ };
207
+ export type TemplatePlanNumberingPatch = {
208
+ abstractNumId: number;
209
+ ilvl: number;
210
+ numFmt?: string;
211
+ lvlText?: string;
212
+ start?: number;
213
+ suff?: "tab" | "space" | "nothing";
214
+ };
215
+ export type TemplatePlanReference = {
216
+ blockId: string;
217
+ /** The span of the block's text the field replaces. */
218
+ start: number;
219
+ end: number;
220
+ targetBlockId: string;
221
+ /** The switches of the REF field, e.g. `\n \t \h`. */
222
+ instruction: string;
223
+ /** The cached result the field is written with. */
224
+ expectedText: string;
225
+ };
226
+ export type TemplatePlanHighlight = {
227
+ blockId: string;
228
+ start: number;
229
+ end: number;
230
+ color: string;
231
+ note?: string;
232
+ };
233
+ /** A plan carries block ids, enums and spans; the text comes from the source. */
234
+ export type TemplatePlan = {
235
+ version: 1;
236
+ sourceSha256: string;
237
+ templateSha256: string;
238
+ /** The new main story in order. */
239
+ body: TemplatePlanItem[];
240
+ omit: {
241
+ blockId: string;
242
+ reason: TemplatePlanOmitReason;
243
+ }[];
244
+ /** Applied to the output's copy of the template numbering. */
245
+ numberingPatches?: TemplatePlanNumberingPatch[];
246
+ references?: TemplatePlanReference[];
247
+ highlights?: TemplatePlanHighlight[];
248
+ fields?: {
249
+ freezeKinds?: string[];
250
+ updateOnOpen?: boolean;
251
+ };
252
+ };
253
+ export type TemplatePlanBlockResult = {
254
+ /** The source block. */
255
+ blockId: string;
256
+ /** The output block holding its text; null when the output has none. */
257
+ outputBlockId: string | null;
258
+ disposition: "placed" | "merged" | "slot" | "nested" | "omitted";
259
+ text: "identical" | "mismatch" | "omitted";
260
+ emphasis: "identical" | "mismatch" | "omitted";
261
+ /** What `stripLabel` removed, the following space included. */
262
+ strippedPrefix?: string;
263
+ /** The label the source showed: its automatic label, else the stripped one. */
264
+ sourceLabel: string | null;
265
+ /** The automatic label the output paragraph renders. */
266
+ outputLabel: string | null;
267
+ omitReason?: TemplatePlanOmitReason;
268
+ };
269
+ export type TemplatePlanReferenceResult = {
270
+ blockId: string;
271
+ targetBlockId: string;
272
+ bookmark: string;
273
+ instruction: string;
274
+ expectedText: string;
275
+ /** The result text the output field carries, or null when the field is missing. */
276
+ cachedText: string | null;
277
+ /** The source text the field replaced. */
278
+ replacedText: string;
279
+ /**
280
+ * What the target's rendered label gives for a `\n` field, or the target's
281
+ * text for a field without a number switch; null when it is not derived.
282
+ */
283
+ predictedText: string | null;
284
+ status: "ok" | "missing-field" | "missing-bookmark" | "cache-mismatch";
285
+ };
286
+ export type TemplatePlanSpanCounts = {
287
+ /** Spans in every block of the source. */
288
+ source: number;
289
+ /** Spans the output must show after the plan's strips, merges and references. */
290
+ expected: number;
291
+ /** Spans the output shows. */
292
+ output: number;
293
+ };
294
+ export type TemplatePlanNoteCounts = {
295
+ /** Notes in the source. */
296
+ source: number;
297
+ /** Notes the placed blocks refer to. */
298
+ expected: number;
299
+ /** Notes the output's placed blocks refer to. */
300
+ output: number;
301
+ identical: number;
302
+ mismatch: number;
303
+ };
304
+ export type TemplatePlanFieldLeftover = {
305
+ part: string;
306
+ kind: string;
307
+ count: number;
308
+ };
309
+ export type TemplatePlanIssue = {
310
+ code: "text-mismatch" | "emphasis-mismatch" | "note-mismatch" | "block-missing" | "reference-broken" | "bookmark-dangling" | "field-unbalanced" | "relationship-dangling" | "note-dangling" | "numbering-dangling" | "style-dangling" | "style-mismatch" | "numbering-mismatch" | "template-mismatch" | "prompting-field-left" | "field-not-frozen" | "update-fields-mismatch" | "conformance";
311
+ message: string;
312
+ blockId?: string;
313
+ part?: string;
314
+ };
315
+ export type TemplatePlanReport = {
316
+ version: 1;
317
+ /** True when no issue was found; an output is only returned when it is. */
318
+ ok: boolean;
319
+ sourceSha256: string;
320
+ templateSha256: string;
321
+ outputSha256: string;
322
+ /** One entry per block of the source, nested ones included, in document order. */
323
+ blocks: TemplatePlanBlockResult[];
324
+ counts: {
325
+ sourceBlocks: number;
326
+ placed: number;
327
+ merged: number;
328
+ omitted: number;
329
+ templateBlocksKept: number;
330
+ textIdentical: number;
331
+ textMismatch: number;
332
+ emphasisMismatch: number;
333
+ /** Placed blocks whose source label and output label differ. */
334
+ labelChanged: number;
335
+ /** Placed blocks that showed a label in the source and render none. */
336
+ labelLost: number;
337
+ };
338
+ footnotes: TemplatePlanNoteCounts;
339
+ endnotes: TemplatePlanNoteCounts;
340
+ emphasisSpans: TemplatePlanSpanCounts;
341
+ highlightSpans: TemplatePlanSpanCounts;
342
+ references: {
343
+ planned: number;
344
+ ok: number;
345
+ /** Fields whose cached text differs from the text they replaced. */
346
+ textChanging: number;
347
+ /** Fields whose cached text differs from the derived prediction. */
348
+ predictionMismatch: number;
349
+ results: TemplatePlanReferenceResult[];
350
+ };
351
+ /** What the template brought along and the plan did not replace. */
352
+ leftovers: {
353
+ /** Fields still live in the output, by part and kind. */
354
+ fields: TemplatePlanFieldLeftover[];
355
+ /** Fields the plan froze to their cached text, by part and kind. */
356
+ frozenFields: TemplatePlanFieldLeftover[];
357
+ /** The filler strings the caller named that the output still contains. */
358
+ filler: {
359
+ text: string;
360
+ part: string;
361
+ count: number;
362
+ }[];
363
+ /** Template blocks the plan kept verbatim. */
364
+ templateBlockIds: string[];
365
+ };
366
+ dropped: {
367
+ comments: number;
368
+ sourceFields: {
369
+ kind: string;
370
+ count: number;
371
+ }[];
372
+ internalHyperlinks: number;
373
+ sectionBreaks: number;
374
+ };
375
+ updateFields: "set" | "cleared" | "unchanged";
376
+ conformance: {
377
+ status: "conformant" | "invalid" | "indeterminate";
378
+ /** The template's own status; the output may not be worse. */
379
+ templateStatus: "conformant" | "invalid" | "indeterminate";
380
+ issues: FolioDocxConformanceIssue[];
381
+ };
382
+ issues: TemplatePlanIssue[];
383
+ warnings: string[];
384
+ };
385
+ export type ApplyTemplatePlanOptions = {
386
+ /** Template placeholder strings the report counts in the output. */
387
+ fillerStrings?: readonly string[];
388
+ };
389
+ export type ApplyTemplatePlanArgs = {
390
+ source: Uint8Array;
391
+ template: Uint8Array;
392
+ plan: TemplatePlan;
393
+ options?: ApplyTemplatePlanOptions;
394
+ };
395
+ export type ApplyTemplatePlanResult = {
396
+ docx: Uint8Array;
397
+ report: TemplatePlanReport;
398
+ };
399
+ export type VerifyTemplatePlanOutputArgs = {
400
+ source: Uint8Array;
401
+ template: Uint8Array;
402
+ output: Uint8Array;
403
+ plan: TemplatePlan;
404
+ options?: ApplyTemplatePlanOptions;
405
+ };
406
+ export {};
@@ -0,0 +1,28 @@
1
+ import { TaggedError } from "better-result";
2
+ // src/docx/server/templatePlan/types.ts
3
+ /** Why a template plan call stopped; every refusal names one of these. */
4
+ const TEMPLATE_PLAN_ERROR_CODES = Object.freeze([
5
+ "archive-unreadable",
6
+ "part-missing",
7
+ "xml-unreadable",
8
+ "plan-invalid",
9
+ "sha-mismatch",
10
+ "unknown-block",
11
+ "hash-mismatch",
12
+ "block-unplaced",
13
+ "block-placed-twice",
14
+ "strip-label-mismatch",
15
+ "merge-invalid",
16
+ "reference-span-invalid",
17
+ "reference-target-unplaced",
18
+ "highlight-span-invalid",
19
+ "numbering-unknown",
20
+ "style-unknown",
21
+ "tracked-changes",
22
+ "unsupported-content",
23
+ "verification-failed"
24
+ ]);
25
+ const TemplatePlanErrorBase = TaggedError("TemplatePlanError");
26
+ /** A refused analysis, plan or output. `report` is set for `verification-failed`. */
27
+ var TemplatePlanError = class extends TemplatePlanErrorBase {};
28
+ export { TEMPLATE_PLAN_ERROR_CODES, TemplatePlanError };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Verification of an applied template plan. The output package is read back
3
+ * with the same reader that analysed the source and compared, block by block,
4
+ * against what the plan resolves to from the source alone: text, stated
5
+ * emphasis, notes, references, paragraph style and list membership, and the
6
+ * integrity of every id the body uses. A kept template block must read as
7
+ * the template has it.
8
+ *
9
+ * Limits. These are not compared, so a change to them passes:
10
+ * - run formatting other than emphasis and highlight (fonts, sizes, colours)
11
+ * and paragraph formatting other than the style and the list, on placed
12
+ * and on kept blocks alike;
13
+ * - the content of headers, footers and text boxes, beyond the fields they
14
+ * carry;
15
+ * - cell spans and merges of a table;
16
+ * - levels of the numbering part the plan neither patches nor restarts;
17
+ * - what a field shows once it updates: a cached result is compared, the
18
+ * label a list will render is only predicted.
19
+ */
20
+ import { AnalyzedDocument } from "./blocks.js";
21
+ import { ResolvedPlan } from "./plan.js";
22
+ import { ApplyTemplatePlanOptions, TemplatePlan, TemplatePlanError, TemplatePlanReport, VerifyTemplatePlanOutputArgs } from "./types.js";
23
+ import { Result } from "better-result";
24
+ type ReportArgs = {
25
+ source: AnalyzedDocument;
26
+ template: AnalyzedDocument;
27
+ output: Uint8Array;
28
+ plan: TemplatePlan;
29
+ resolved: ResolvedPlan;
30
+ options: ApplyTemplatePlanOptions | undefined;
31
+ };
32
+ /** Read `output` back and report how it compares with the resolved plan. */
33
+ export declare const reportTemplatePlanOutput: ({ source, template, output, plan, resolved, options }: ReportArgs) => Promise<Result<TemplatePlanReport, TemplatePlanError>>;
34
+ /**
35
+ * Check `output` against `source`, `template` and `plan` without trusting
36
+ * whoever wrote it: every expectation is derived again from the inputs.
37
+ * A refused plan is an error; a failed check is a report with `ok: false`.
38
+ */
39
+ export declare const verifyTemplatePlanOutput: (input: VerifyTemplatePlanOutputArgs) => Promise<Result<TemplatePlanReport, TemplatePlanError>>;
40
+ export {};