@stll/folio-core 0.72.0 → 0.74.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/README.md +12 -6
  2. package/dist/ai-edits/applyTypes.d.ts +85 -0
  3. package/dist/ai-edits/applyTypes.js +24 -0
  4. package/dist/ai-edits/clean-text.d.ts +7 -1
  5. package/dist/ai-edits/clean-text.js +23 -2
  6. package/dist/ai-edits/finalSectionReview.d.ts +1 -1
  7. package/dist/ai-edits/headless.d.ts +29 -147
  8. package/dist/ai-edits/headless.js +215 -1639
  9. package/dist/ai-edits/index.d.ts +3 -3
  10. package/dist/ai-edits/index.js +2 -3
  11. package/dist/ai-edits/pending-suggestions.d.ts +14 -4
  12. package/dist/ai-edits/pending-suggestions.js +183 -90
  13. package/dist/ai-edits/pendingJoin.js +6 -1
  14. package/dist/ai-edits/retired-comment-receipts.d.ts +1 -1
  15. package/dist/ai-edits/snapshot.js +9 -4
  16. package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
  17. package/dist/ai-edits/table-cell-mutations.js +2 -2
  18. package/dist/ai-edits/table-geometry.d.ts +1 -1
  19. package/dist/ai-edits/table-geometry.js +1 -1
  20. package/dist/ai-edits/table-row-column-mutations.d.ts +1 -1
  21. package/dist/ai-edits/table-row-column-mutations.js +1 -1
  22. package/dist/ai-edits/tableNodes.d.ts +38 -0
  23. package/dist/ai-edits/tableNodes.js +86 -0
  24. package/dist/ai-edits/tracked-batch-fidelity.d.ts +1 -1
  25. package/dist/ai-edits/tracked-batch-fidelity.js +1 -1
  26. package/dist/ai-edits/undefinedReferences.d.ts +7 -0
  27. package/dist/canonical/batchCommentReferences.js +1 -0
  28. package/dist/canonical/canonicalInlineGaps.d.ts +56 -0
  29. package/dist/canonical/canonicalInlineGaps.js +118 -0
  30. package/dist/canonical/canonicalInlineProjection.d.ts +4 -13
  31. package/dist/canonical/canonicalInlineProjection.js +5 -27
  32. package/dist/canonical/canonicalProjectionBlocks.d.ts +4 -4
  33. package/dist/canonical/canonicalPublicOperations.js +282 -75
  34. package/dist/canonical/canonicalSelection.js +1 -1
  35. package/dist/canonical/canonicalSession.d.ts +9 -1
  36. package/dist/canonical/canonicalSession.js +106 -33
  37. package/dist/compare/compare.d.ts +1 -1
  38. package/dist/compare/inline-atoms-model.d.ts +1 -1
  39. package/dist/compare/inline-atoms.d.ts +2 -2
  40. package/dist/compare/inline-provenance-model.d.ts +1 -1
  41. package/dist/compare/inline-provenance.d.ts +2 -2
  42. package/dist/compat/eigenpal.d.ts +3 -3
  43. package/dist/compat/eigenpal.js +2 -3
  44. package/dist/controller/autocompleteSuggestion.js +1 -1
  45. package/dist/controller/canonicalClipboard.d.ts +13 -3
  46. package/dist/controller/canonicalClipboard.js +186 -50
  47. package/dist/controller/canonicalClipboardResources.d.ts +9 -1
  48. package/dist/controller/canonicalClipboardResources.js +22 -2
  49. package/dist/controller/canonicalComposition.js +1 -1
  50. package/dist/controller/canonicalInput.js +1 -1
  51. package/dist/controller/canonicalPresence.js +1 -1
  52. package/dist/controller/canonicalReview.d.ts +1 -1
  53. package/dist/controller/canonicalReview.js +1 -1
  54. package/dist/controller/canonicalRoomAuthority.js +1 -1
  55. package/dist/controller/canonicalRoomWire.js +1 -1
  56. package/dist/controller/canonicalStructure.js +1 -1
  57. package/dist/controller/canonicalTabRoom.js +1 -1
  58. package/dist/controller/canonicalWatermark.d.ts +10 -0
  59. package/dist/controller/canonicalWatermark.js +37 -0
  60. package/dist/controller/canonicalYjsRoom.js +1 -1
  61. package/dist/controller/hiddenEditorApi.d.ts +1 -1
  62. package/dist/controller/hiddenEditorApi.js +2 -17
  63. package/dist/controller/hiddenEditorManager.d.ts +4 -3
  64. package/dist/controller/hiddenEditorManager.js +79 -23
  65. package/dist/document-operations.d.ts +1 -14
  66. package/dist/document-operations.js +1 -278
  67. package/dist/docx/canonicalSave.d.ts +1 -1
  68. package/dist/docx/canonicalSave.js +1 -1
  69. package/dist/docx/canonicalSessionInput.js +1 -1
  70. package/dist/docx/containerChildren.js +1 -1
  71. package/dist/docx/createDocx.d.ts +4 -0
  72. package/dist/docx/createDocx.js +6 -0
  73. package/dist/docx/paragraphParser.js +2 -2
  74. package/dist/docx/paragraphPropertySource.d.ts +1 -1
  75. package/dist/docx/parser.js +1 -1
  76. package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
  77. package/dist/docx/reviewResolutionProvenance.js +31 -8
  78. package/dist/docx/revisionIdNormalization.js +30 -7
  79. package/dist/docx/rezip.d.ts +1 -1
  80. package/dist/docx/rezip.js +1 -1
  81. package/dist/docx/serializer/tableSerializer.js +4 -36
  82. package/dist/docx/server/templatePlan/apply.d.ts +15 -0
  83. package/dist/docx/server/templatePlan/apply.js +658 -0
  84. package/dist/docx/server/templatePlan/blocks.d.ts +97 -0
  85. package/dist/docx/server/templatePlan/blocks.js +355 -0
  86. package/dist/docx/server/templatePlan/builders.d.ts +72 -0
  87. package/dist/docx/server/templatePlan/builders.js +237 -0
  88. package/dist/docx/server/templatePlan/emit.d.ts +118 -0
  89. package/dist/docx/server/templatePlan/emit.js +466 -0
  90. package/dist/docx/server/templatePlan/emphasis.d.ts +62 -0
  91. package/dist/docx/server/templatePlan/emphasis.js +173 -0
  92. package/dist/docx/server/templatePlan/inspect.d.ts +22 -0
  93. package/dist/docx/server/templatePlan/inspect.js +230 -0
  94. package/dist/docx/server/templatePlan/labels.d.ts +45 -0
  95. package/dist/docx/server/templatePlan/labels.js +155 -0
  96. package/dist/docx/server/templatePlan/package.d.ts +34 -0
  97. package/dist/docx/server/templatePlan/package.js +99 -0
  98. package/dist/docx/server/templatePlan/plan.d.ts +145 -0
  99. package/dist/docx/server/templatePlan/plan.js +875 -0
  100. package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
  101. package/dist/docx/server/templatePlan/planShape.js +180 -0
  102. package/dist/docx/server/templatePlan/resources.d.ts +41 -0
  103. package/dist/docx/server/templatePlan/resources.js +136 -0
  104. package/dist/docx/server/templatePlan/story.d.ts +128 -0
  105. package/dist/docx/server/templatePlan/story.js +440 -0
  106. package/dist/docx/server/templatePlan/types.d.ts +442 -0
  107. package/dist/docx/server/templatePlan/types.js +29 -0
  108. package/dist/docx/server/templatePlan/verify.d.ts +40 -0
  109. package/dist/docx/server/templatePlan/verify.js +976 -0
  110. package/dist/docx/server/templatePlan/xml.d.ts +74 -0
  111. package/dist/docx/server/templatePlan/xml.js +125 -0
  112. package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
  113. package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
  114. package/dist/docx/structuralXmlPatch.js +9 -1
  115. package/dist/docx/tableGridXml.d.ts +30 -0
  116. package/dist/docx/tableGridXml.js +54 -0
  117. package/dist/docx/tableParser.js +7 -0
  118. package/dist/i18n/loadMessages.d.ts +5 -0
  119. package/dist/i18n/loadMessages.js +46 -0
  120. package/dist/i18n/locales.d.ts +3 -0
  121. package/dist/i18n/locales.js +17 -0
  122. package/dist/i18n/messages.d.ts +3 -2
  123. package/dist/i18n/messages.js +4 -16
  124. package/dist/index.d.ts +3 -3
  125. package/dist/index.js +2 -3
  126. package/dist/internal/clipboardTransformPlugin.d.ts +3 -0
  127. package/dist/internal/clipboardTransformPlugin.js +13 -0
  128. package/dist/internal/extensionRuntime.d.ts +7 -0
  129. package/dist/internal/extensionRuntime.js +28 -0
  130. package/dist/internal/starterKitExtensions.d.ts +20 -0
  131. package/dist/internal/starterKitExtensions.js +123 -0
  132. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  133. package/dist/managers/ContextMenuManager.js +2 -1
  134. package/dist/managers/editorShortcuts.d.ts +1 -1
  135. package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
  136. package/dist/prosemirror/attrs/index.js +1 -1
  137. package/dist/prosemirror/canonicalCommands.d.ts +1 -1
  138. package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
  139. package/dist/prosemirror/canonicalSelectionRange.js +1 -1
  140. package/dist/prosemirror/canonicalTableCommands.js +3 -3
  141. package/dist/prosemirror/commands/comments.js +4 -4
  142. package/dist/prosemirror/commands/contentControls.d.ts +1 -1
  143. package/dist/prosemirror/commands/contentControls.js +1 -1
  144. package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
  145. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  146. package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
  147. package/dist/prosemirror/commands/pastePlainText.js +2 -3
  148. package/dist/prosemirror/commands/replaceRangeText.js +1 -1
  149. package/dist/prosemirror/commands/sectionBreak.js +1 -1
  150. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
  151. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +1 -1
  152. package/dist/prosemirror/commentRecords.d.ts +1 -1
  153. package/dist/prosemirror/commentRecords.js +2 -2
  154. package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
  155. package/dist/prosemirror/conversion/fromProseDoc.d.ts +0 -5
  156. package/dist/prosemirror/conversion/fromProseDoc.js +2 -9
  157. package/dist/prosemirror/conversion/index.d.ts +2 -2
  158. package/dist/prosemirror/conversion/index.js +2 -2
  159. package/dist/prosemirror/documentStructureCounts.d.ts +24 -0
  160. package/dist/prosemirror/documentStructureCounts.js +76 -0
  161. package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
  162. package/dist/prosemirror/extensions/ExtensionManager.js +4 -22
  163. package/dist/prosemirror/extensions/StarterKit.d.ts +4 -27
  164. package/dist/prosemirror/extensions/StarterKit.js +29 -115
  165. package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -1
  166. package/dist/prosemirror/extensions/core/historyCommands.d.ts +16 -0
  167. package/dist/prosemirror/extensions/core/historyCommands.js +19 -0
  168. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
  169. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
  170. package/dist/prosemirror/extensions/features/ListExtension.js +7 -2
  171. package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
  172. package/dist/prosemirror/extensions/index.d.ts +2 -1
  173. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +8 -3
  174. package/dist/prosemirror/extensions/marks/markUtils.d.ts +1 -1
  175. package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
  176. package/dist/prosemirror/extensions/nodes/TableExtension.js +8 -41
  177. package/dist/prosemirror/extensions/types.d.ts +1 -1
  178. package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
  179. package/dist/prosemirror/hyperlinkRemoval.d.ts +1 -1
  180. package/dist/prosemirror/hyperlinkRemoval.js +7 -2
  181. package/dist/prosemirror/index.d.ts +3 -3
  182. package/dist/prosemirror/index.js +3 -3
  183. package/dist/prosemirror/insertionGaps.d.ts +1 -1
  184. package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
  185. package/dist/prosemirror/keptRangeBoundaries.js +1 -1
  186. package/dist/prosemirror/listNumbering.d.ts +1 -1
  187. package/dist/prosemirror/listNumbering.js +1 -1
  188. package/dist/prosemirror/lockedControls.d.ts +1 -1
  189. package/dist/prosemirror/markupViewProjection.d.ts +1 -1
  190. package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
  191. package/dist/prosemirror/noteReferenceOccurrences.js +1 -1
  192. package/dist/prosemirror/noteReferenceReview.d.ts +2 -56
  193. package/dist/prosemirror/noteReferenceReview.js +2 -243
  194. package/dist/prosemirror/{extensions/features/ParaIdAllocatorExtension.d.ts → paraIds.d.ts} +13 -23
  195. package/dist/prosemirror/paraIds.js +152 -0
  196. package/dist/prosemirror/paragraphChangeTrackerMeta.d.ts +97 -0
  197. package/dist/prosemirror/paragraphChangeTrackerMeta.js +87 -0
  198. package/dist/prosemirror/paragraphMarkJoin.d.ts +1 -1
  199. package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -1
  200. package/dist/prosemirror/pastedCommentCopies.d.ts +1 -1
  201. package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
  202. package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
  203. package/dist/prosemirror/plugins/documentNumbering.js +1 -1
  204. package/dist/prosemirror/plugins/documentStyles.js +1 -1
  205. package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
  206. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
  207. package/dist/prosemirror/rebaseParagraphRuns.d.ts +1 -1
  208. package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
  209. package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
  210. package/dist/prosemirror/replacedAnnotations.js +17 -2
  211. package/dist/prosemirror/revisionCarriers.d.ts +1 -1
  212. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
  213. package/dist/prosemirror/sectionMarkEdits.d.ts +1 -1
  214. package/dist/prosemirror/selectionBounds.d.ts +10 -0
  215. package/dist/prosemirror/selectionBounds.js +22 -0
  216. package/dist/prosemirror/storyListNumbering.d.ts +1 -1
  217. package/dist/prosemirror/suggestionCommands.d.ts +47 -0
  218. package/dist/prosemirror/suggestionCommands.js +31 -0
  219. package/dist/prosemirror/tableCellPaste.d.ts +1 -1
  220. package/dist/prosemirror/tableCellPaste.js +1 -1
  221. package/dist/prosemirror/tableGridMutation.d.ts +1 -1
  222. package/dist/prosemirror/tableRunIn.js +1 -1
  223. package/dist/prosemirror/textInput.d.ts +1 -1
  224. package/dist/prosemirror/textInput.js +1 -1
  225. package/dist/server.d.ts +7 -2
  226. package/dist/server.js +6 -1
  227. package/dist/types/canonicalCapabilities.d.ts +13 -92
  228. package/dist/types/canonicalCapabilities.js +11 -85
  229. package/package.json +4 -4
  230. package/dist/ai-edits/apply.d.ts +0 -202
  231. package/dist/ai-edits/apply.js +0 -6759
  232. package/dist/ai-edits/note-story-inventory.d.ts +0 -5
  233. package/dist/ai-edits/note-story-inventory.js +0 -10
  234. package/dist/ai-edits/revisionStretches.d.ts +0 -32
  235. package/dist/ai-edits/revisionStretches.js +0 -147
  236. package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +0 -18
  237. package/dist/prosemirror/extensions/core/HistoryExtension.js +0 -122
  238. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +0 -408
  239. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +0 -135
  240. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +0 -566
  241. package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -92
  242. package/dist/prosemirror/plugins/suggestionMode.js +0 -1515
  243. package/dist/prosemirror/tablePositionedBookmarks.d.ts +0 -8
  244. package/dist/prosemirror/tablePositionedBookmarks.js +0 -80
@@ -4,7 +4,7 @@ import { getAttributeByNamespaceUri } from "./xmlParser.js";
4
4
  import { Result, TaggedError, panic } from "better-result";
5
5
  import { escapeXmlAttribute } from "@stll/docx-core";
6
6
  import { MAX_REVISION_ID } from "@stll/docx-core/model";
7
- import { isCopyOriginAncestors, isKeptCut } from "@stll/docx-core/ops";
7
+ import { isCopyOriginAncestors, isKeptCut, isKeptCutPiece } from "@stll/docx-core/ops";
8
8
  // src/docx/reviewResolutionProvenance.ts
9
9
  const NAMESPACES = /* @__PURE__ */ new Set([FOLIO_REVIEW_HISTORY_NAMESPACE]);
10
10
  /**
@@ -67,6 +67,10 @@ const PARAGRAPH_MARK_FIELDS = {
67
67
  type: "private",
68
68
  attribute: "rejectionSurvivor"
69
69
  },
70
+ takenOverMark: {
71
+ type: "private",
72
+ attribute: "rejectionSurvivor"
73
+ },
70
74
  splitDate: {
71
75
  type: "private",
72
76
  attribute: "splitDate"
@@ -322,12 +326,29 @@ const storedKeptCut = (value) => {
322
326
  const { depth: _ignored, ...cut } = value;
323
327
  return cut;
324
328
  };
325
- const isStoredKeptCut = (value) => isKeptCut(storedKeptCut(value));
329
+ const LEGACY_KEPT_CUT_PIECES = /* @__PURE__ */ new WeakMap();
330
+ const legacyKeptCutPiece = (cut) => LEGACY_KEPT_CUT_PIECES.get(cut);
331
+ const legacyStoredKeptCut = (value) => {
332
+ if (!record(value)) return void 0;
333
+ const { piece, ...cut } = value;
334
+ return isKeptCutPiece(piece) && isKeptCut(cut) && cut.holders === void 0 ? {
335
+ cut,
336
+ piece
337
+ } : void 0;
338
+ };
339
+ const isStoredKeptCut = (value) => {
340
+ const cut = storedKeptCut(value);
341
+ return isKeptCut(cut) || legacyStoredKeptCut(cut) !== void 0;
342
+ };
326
343
  /** The cut a kept range marker stands in (`folio:keptCut`). */
327
344
  const parseKeptCut = (node) => {
328
345
  const decoded = decodeAttribute(node, "keptCut", isStoredKeptCut);
329
346
  const cut = storedKeptCut(decoded?.value);
330
- return isKeptCut(cut) ? cut : void 0;
347
+ if (isKeptCut(cut)) return cut;
348
+ const legacy = legacyStoredKeptCut(cut);
349
+ if (legacy === void 0) return void 0;
350
+ LEGACY_KEPT_CUT_PIECES.set(legacy.cut, legacy.piece);
351
+ return legacy.cut;
331
352
  };
332
353
  const serializeKeptCut = (value) => encodeAttribute({
333
354
  attribute: "keptCut",
@@ -349,7 +370,8 @@ const serializeCopyOriginAncestors = (value) => encodeAttribute({
349
370
  value,
350
371
  valid: isCopyOriginAncestors
351
372
  });
352
- const isParagraphMarkSurvivor = (value) => value === "first";
373
+ const isStoredRejectionSurvivor = (value) => record(value) && Object.keys(value).length === 1 && (value["takenOverMark"] === null || isRevisionId(value["takenOverMark"]));
374
+ const isParagraphMarkSurvivor = (value) => value === "first" || isStoredRejectionSurvivor(value);
353
375
  const isParagraphMarkSplitDate = (value) => typeof value === "string";
354
376
  /**
355
377
  * A paragraph mark's private review provenance: its rejection join depth
@@ -375,14 +397,15 @@ const parseParagraphMarkResolutionJoin = (node) => {
375
397
  });
376
398
  return {
377
399
  ...value === void 0 ? {} : { resolutionJoin: value === null ? void 0 : value },
378
- ...survivor === void 0 ? {} : { survivor },
400
+ ...survivor === void 0 ? {} : { survivor: "first" },
401
+ ...survivor === void 0 || survivor === "first" || survivor.takenOverMark === null ? {} : { takenOverMark: survivor.takenOverMark },
379
402
  ...splitDate === void 0 ? {} : { splitDate }
380
403
  };
381
404
  };
382
405
  const paragraphMarkSurvivorOptions = (mark) => ({
383
406
  attribute: PARAGRAPH_MARK_FIELDS.survivor.attribute,
384
- value: mark.survivor,
385
- valid: isParagraphMarkSurvivor
407
+ value: mark.survivor === void 0 ? void 0 : { takenOverMark: mark.takenOverMark ?? null },
408
+ valid: isStoredRejectionSurvivor
386
409
  });
387
410
  const paragraphMarkSplitDateOptions = (mark) => ({
388
411
  attribute: PARAGRAPH_MARK_FIELDS.splitDate.attribute,
@@ -490,4 +513,4 @@ const reviewProvenanceIssue = (attribute, encoded) => {
490
513
  const decoded = decodeProvenance(encoded, shape);
491
514
  return decoded.status === "dropped" ? decoded.reason : void 0;
492
515
  };
493
- export { REVIEW_HISTORY_VERSION, ReviewResolutionProvenanceError, isBoundaryJoins, isParagraphMarkResolutionJoin, isResolutionJoins, isSplitResolutionPiece, paragraphMarkResolutionJoinAttributes, parseBoundaryJoins, parseCopyOriginAncestors, parseKeptCut, parseParagraphMarkResolutionJoin, parseParagraphPropertyChangeOwner, parseResolutionJoins, parseSplitResolutionPiece, reviewProvenanceIssue, serializeBoundaryJoins, serializeCopyOriginAncestors, serializeKeptCut, serializeParagraphMarkResolutionJoin, serializeParagraphPropertyChangeOwner, serializeResolutionJoins, serializeSplitResolutionPiece, versionOneKeptMarkers };
516
+ export { REVIEW_HISTORY_VERSION, ReviewResolutionProvenanceError, isBoundaryJoins, isParagraphMarkResolutionJoin, isResolutionJoins, isSplitResolutionPiece, legacyKeptCutPiece, paragraphMarkResolutionJoinAttributes, parseBoundaryJoins, parseCopyOriginAncestors, parseKeptCut, parseParagraphMarkResolutionJoin, parseParagraphPropertyChangeOwner, parseResolutionJoins, parseSplitResolutionPiece, reviewProvenanceIssue, serializeBoundaryJoins, serializeCopyOriginAncestors, serializeKeptCut, serializeParagraphMarkResolutionJoin, serializeParagraphPropertyChangeOwner, serializeResolutionJoins, serializeSplitResolutionPiece, versionOneKeptMarkers };
@@ -1,6 +1,7 @@
1
+ import { parseParagraphMarkResolutionJoin } from "./reviewResolutionProvenance.js";
1
2
  import { WORDPROCESSINGML_NAMESPACE_URIS, findAttributeByNamespaceUri, getLocalName, getNamespaceUri } from "./xmlParser.js";
2
3
  import { TaggedError } from "better-result";
3
- import { rewriteStreamingXmlDecimalAttributes } from "@stll/docx-core/xml";
4
+ import { rewriteStreamingXmlDecimalAttributes, scanStreamingXmlElements } from "@stll/docx-core/xml";
4
5
  import { XmlResourceLimitError, assertXmlResourceLimits } from "@stll/docx-core/xml/limits";
5
6
  // src/docx/revisionIdNormalization.ts
6
7
  const RevisionIdCollisionErrorBase = TaggedError("RevisionIdCollisionError");
@@ -116,6 +117,8 @@ const revisionAttribute = (element) => {
116
117
  const normalizeRevisionIdsInXmlParts = (parts) => {
117
118
  const candidates = [...parts].filter(([, xml]) => REVISION_ELEMENT_CANDIDATE.test(xml));
118
119
  const occurrencesByPath = /* @__PURE__ */ new Map();
120
+ const paragraphMarks = /* @__PURE__ */ new Map();
121
+ const takenOverMarks = /* @__PURE__ */ new Set();
119
122
  const reserved = /* @__PURE__ */ new Set();
120
123
  for (const [path, xml] of candidates) {
121
124
  assertXmlResourceLimits({
@@ -123,10 +126,22 @@ const normalizeRevisionIdsInXmlParts = (parts) => {
123
126
  partPath: path
124
127
  });
125
128
  const ids = [];
126
- if (rewriteStreamingXmlDecimalAttributes(xml, (element) => {
129
+ const paragraphMarkProperties = /* @__PURE__ */ new WeakSet();
130
+ if (scanStreamingXmlElements(xml, ({ element, parent }) => {
131
+ if (parent?.name !== void 0 && element.name !== void 0 && getLocalName(parent.name) === "pPr" && getLocalName(element.name) === "rPr" && WORDPROCESSINGML_NAMESPACE_URIS.has(getNamespaceUri(parent) ?? "") && WORDPROCESSINGML_NAMESPACE_URIS.has(getNamespaceUri(element) ?? "")) paragraphMarkProperties.add(element);
127
132
  const identified = identifiedElement(element);
128
133
  if (identified === null) return null;
129
- if (identified.kind === ID_KINDS.revision) ids.push(identified.id);
134
+ if (identified.kind === ID_KINDS.revision) {
135
+ if (parent !== void 0 && paragraphMarkProperties.has(parent)) {
136
+ if (!paragraphMarks.has(identified.id)) paragraphMarks.set(identified.id, {
137
+ path,
138
+ ordinal: ids.length
139
+ });
140
+ const { takenOverMark } = parseParagraphMarkResolutionJoin(element);
141
+ if (takenOverMark !== void 0) takenOverMarks.add(takenOverMark);
142
+ }
143
+ ids.push(identified.id);
144
+ }
130
145
  reserved.add(identified.id);
131
146
  return null;
132
147
  }).status === "unsupported") throw new XmlResourceLimitError({
@@ -139,8 +154,12 @@ const normalizeRevisionIdsInXmlParts = (parts) => {
139
154
  }
140
155
  const repeatedPaths = /* @__PURE__ */ new Set();
141
156
  const firstSeen = /* @__PURE__ */ new Set();
142
- for (const [path, ids] of occurrencesByPath) for (const id of ids) if (firstSeen.has(id)) repeatedPaths.add(path);
143
- else firstSeen.add(id);
157
+ const repeated = /* @__PURE__ */ new Set();
158
+ for (const [path, ids] of occurrencesByPath) for (const id of ids) if (firstSeen.has(id)) {
159
+ repeatedPaths.add(path);
160
+ repeated.add(id);
161
+ } else firstSeen.add(id);
162
+ const hasPreferredDuplicate = (ids) => ids.some((id) => repeated.has(id) && takenOverMarks.has(id) && paragraphMarks.has(id));
144
163
  if (repeatedPaths.size > 0) for (const [path, xml] of parts) {
145
164
  if (occurrencesByPath.has(path) || !ANNOTATION_ELEMENT_CANDIDATE.test(xml)) continue;
146
165
  assertXmlResourceLimits({
@@ -179,14 +198,18 @@ const normalizeRevisionIdsInXmlParts = (parts) => {
179
198
  });
180
199
  seen.add(id);
181
200
  };
182
- if (!repeatedPaths.has(path) && ids.every((id) => !seen.has(id))) {
201
+ if (!repeatedPaths.has(path) && !hasPreferredDuplicate(ids) && ids.every((id) => !seen.has(id))) {
183
202
  for (const id of ids) claim(id);
184
203
  continue;
185
204
  }
205
+ let ordinal = 0;
186
206
  const rewritten = rewriteStreamingXmlDecimalAttributes(xml, (element) => {
187
207
  const attribute = revisionAttribute(element);
188
208
  if (!attribute) return null;
189
- if (!seen.has(attribute.id)) {
209
+ const preferred = takenOverMarks.has(attribute.id) ? paragraphMarks.get(attribute.id) : void 0;
210
+ const at = ordinal;
211
+ ordinal += 1;
212
+ if (!seen.has(attribute.id) && (preferred === void 0 || preferred.path === path && preferred.ordinal === at)) {
190
213
  claim(attribute.id);
191
214
  return null;
192
215
  }
@@ -61,7 +61,7 @@ export declare function readRelsOrStub(zip: ZipArchive, relsPath: string): Promi
61
61
  declare const CanonicalImageRelationshipRefusalErrorBase: TaggedErrorClass<"CanonicalImageRelationshipRefusalError">;
62
62
  export declare class CanonicalImageRelationshipRefusalError extends CanonicalImageRelationshipRefusalErrorBase<{
63
63
  message: string;
64
- gap: typeof CANONICAL_GAP.save;
64
+ gap: typeof CANONICAL_GAP.saveSerialization;
65
65
  part: string;
66
66
  relationshipId: string;
67
67
  reason: "conflict" | "unresolved" | "missingMedia" | "unsafeTarget";
@@ -531,7 +531,7 @@ const publishCanonicalImageResources = async ({ document, zip, compressionLevel
531
531
  const refuse = (reason, message) => {
532
532
  throw new CanonicalImageRelationshipRefusalError({
533
533
  message,
534
- gap: CANONICAL_GAP.save,
534
+ gap: CANONICAL_GAP.saveSerialization,
535
535
  part: relsPath,
536
536
  relationshipId: id,
537
537
  reason
@@ -3,6 +3,7 @@ import { isValidHexColor } from "../../utils/colorResolver.js";
3
3
  import { serializePreservedAttributes } from "../attributeRemainder.js";
4
4
  import { withPreservedChildren } from "../containerChildren.js";
5
5
  import { TRANSITIONAL_NAME_BY_STRICT_NAME } from "../strictNames.gen.js";
6
+ import { gridColumnCount, modelTableGrid } from "../tableGridXml.js";
6
7
  import { TABLE_LOOK_FLAGS } from "../tableLook.js";
7
8
  import { parseTableCellProperties, parseTableGrid, parseTableGridChange, parseTableProperties, parseTablePropertyExceptions, parseTableRowProperties } from "../tableParser.js";
8
9
  import { serializeEmptyRowProperties } from "../tableRowPropertyPresence.js";
@@ -430,25 +431,8 @@ function serializeTableCellPropertyChange(change) {
430
431
  return `<w:tcPrChange ${attrs}>${previousTcPrInner.length > 0 ? `<w:tcPr>${previousTcPrInner}</w:tcPr>` : "<w:tcPr/>"}</w:tcPrChange>`;
431
432
  }
432
433
  /**
433
- * Columns the grid has to declare: the widest row's total of skipped columns
434
- * and spans, because a grid narrower than a row leaves cells with no column
435
- * to sit in.
436
- */
437
- function gridColumnCount(table) {
438
- let widest = 0;
439
- for (const row of table.rows) {
440
- let columns = (row.formatting?.gridBefore ?? 0) + (row.formatting?.gridAfter ?? 0);
441
- for (const cell of row.cells) columns += cell.formatting?.gridSpan ?? 1;
442
- widest = Math.max(widest, columns);
443
- }
444
- return widest;
445
- }
446
- /**
447
- * Serialize table grid (w:tblGrid).
448
- *
449
- * `w:tblGrid` is required on every `w:tbl` and `w:w` is optional on a
450
- * `w:gridCol`, so a table whose column widths were never measured — one the
451
- * comparison creates, say — still declares a grid, just without widths.
434
+ * Serialize table grid (w:tblGrid): the grid as it arrived, while it still
435
+ * states the widths the model holds, otherwise the model's grid.
452
436
  */
453
437
  function serializeTableGrid(table) {
454
438
  const columnWidths = table.columnWidths;
@@ -458,24 +442,8 @@ function serializeTableGrid(table) {
458
442
  const declared = element === null ? 0 : findChildren(element, "w", "gridCol").length;
459
443
  if (canonicalJson(parseTableGrid(element)) === canonicalJson(columnWidths) && declared === (columnWidths?.length || gridColumnCount(table)) && canonicalJson(element === null ? void 0 : parseTableGridChange(element)) === canonicalJson(table.formatting?.gridChange)) return gridSourceXml;
460
444
  }
461
- const change = table.formatting?.gridChange;
462
- const gridChange = change === void 0 ? "" : serializeTableGridChange(change);
463
- if (columnWidths && columnWidths.length > 0) return `<w:tblGrid>${columnWidths.map((w) => `<w:gridCol w:w="${intAttr(w)}"/>`).join("")}${gridChange}</w:tblGrid>`;
464
- const columns = gridColumnCount(table);
465
- return columns === 0 && gridChange === "" ? "<w:tblGrid/>" : `<w:tblGrid>${"<w:gridCol/>".repeat(columns)}${gridChange}</w:tblGrid>`;
445
+ return modelTableGrid(table);
466
446
  }
467
- /**
468
- * Serialize `w:tblGridChange`: the grid a reviewer replaced, from the change's
469
- * own record rather than from the bytes it arrived as.
470
- *
471
- * `w:w` is optional on a `w:gridCol`, so a column the snapshot recorded no
472
- * measure for is written back without one; spelling it as a zero would claim a
473
- * width the source never stated.
474
- */
475
- const serializeTableGridChange = ({ id, columnWidths }) => {
476
- const columns = columnWidths.map((width) => width === void 0 ? "<w:gridCol/>" : `<w:gridCol w:w="${intAttr(width)}"/>`).join("");
477
- return `<w:tblGridChange w:id="${intAttr(id)}"><w:tblGrid>${columns}</w:tblGrid></w:tblGridChange>`;
478
- };
479
447
  const tableCarrierKey = (carrier) => carrier.type === "customXml" ? `customXml:${String(carrier.wrapper.id)}` : `sdt:${canonicalJson(carrier.properties)}`;
480
448
  const serializeTableCarriers = (children, depth = 0) => {
481
449
  const parts = [];
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Apply a source document onto a template from a plan: the output is the
3
+ * template's own package with a new main story. Parts the plan does not
4
+ * touch keep their bytes; the ones it does are spliced, not re-serialized.
5
+ */
6
+ import { ApplyTemplatePlanArgs, ApplyTemplatePlanResult, TemplatePlanError } from "./types.js";
7
+ import { Result } from "better-result";
8
+ /**
9
+ * Apply `source` onto `template` as `plan` says and verify the result.
10
+ *
11
+ * The plan names blocks by id and pins them by hash; the text itself always
12
+ * comes from the source. The output is refused, with the report attached,
13
+ * unless every placed block reads back identical.
14
+ */
15
+ export declare const applyTemplatePlan: (input: ApplyTemplatePlanArgs) => Promise<Result<ApplyTemplatePlanResult, TemplatePlanError>>;