@stll/folio-core 0.68.0 → 0.69.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 (177) hide show
  1. package/dist/ai-edits/headless.js +2 -2
  2. package/dist/ai-edits/newListNumbering.d.ts +14 -1
  3. package/dist/ai-edits/newListNumbering.js +24 -1
  4. package/dist/ai-edits/pending-suggestions.js +2 -2
  5. package/dist/controller/canonicalClipboard.js +2 -2
  6. package/dist/controller/canonicalComposition.js +34 -5
  7. package/dist/controller/canonicalInput.js +4 -6
  8. package/dist/controller/canonicalLockGuard.d.ts +17 -2
  9. package/dist/controller/canonicalLockGuard.js +46 -1
  10. package/dist/controller/canonicalProjectionBlocks.d.ts +79 -0
  11. package/dist/controller/canonicalProjectionBlocks.js +75 -0
  12. package/dist/controller/canonicalPublicOperations.js +476 -100
  13. package/dist/controller/canonicalSeedContent.d.ts +12 -0
  14. package/dist/controller/canonicalSeedContent.js +131 -0
  15. package/dist/controller/canonicalSession.d.ts +53 -21
  16. package/dist/controller/canonicalSession.js +489 -210
  17. package/dist/controller/canonicalSourceNormalization.d.ts +21 -0
  18. package/dist/controller/canonicalSourceNormalization.js +148 -0
  19. package/dist/controller/canonicalStoryEditor.d.ts +1 -1
  20. package/dist/controller/canonicalStoryEditor.js +16 -12
  21. package/dist/controller/folioEditor.js +3 -0
  22. package/dist/controller/headerFooterEditorManager.d.ts +5 -0
  23. package/dist/controller/headerFooterEditorManager.js +7 -2
  24. package/dist/controller/hiddenEditorApi.d.ts +11 -2
  25. package/dist/controller/hiddenEditorApi.js +3 -0
  26. package/dist/controller/hiddenEditorManager.d.ts +7 -0
  27. package/dist/controller/hiddenEditorManager.js +66 -11
  28. package/dist/controller/layoutPipeline.js +2 -1
  29. package/dist/controller/layoutSession.d.ts +3 -0
  30. package/dist/controller/layoutSession.js +3 -1
  31. package/dist/controller/noteEditorManager.d.ts +5 -0
  32. package/dist/controller/noteEditorManager.js +7 -2
  33. package/dist/display-list/dom/renderDisplayListToDom.js +9 -7
  34. package/dist/document-operations.d.ts +1 -1
  35. package/dist/docx/canonicalSave.js +7 -2
  36. package/dist/docx/commentAnchorIndex.d.ts +19 -0
  37. package/dist/docx/commentAnchorIndex.js +55 -1
  38. package/dist/docx/containerChildren.js +1 -1
  39. package/dist/docx/contentTypeRegistry.js +1 -1
  40. package/dist/docx/hostCommentThreads.d.ts +11 -1
  41. package/dist/docx/hostCommentThreads.js +25 -2
  42. package/dist/docx/listModelNormalization.js +4 -5
  43. package/dist/docx/listNumberingInstances.d.ts +1 -1
  44. package/dist/docx/listNumberingInstances.js +2 -2
  45. package/dist/docx/numberingIds.d.ts +6 -0
  46. package/dist/docx/numberingIds.js +6 -1
  47. package/dist/docx/numberingReferenceNormalization.d.ts +4 -0
  48. package/dist/docx/numberingReferenceNormalization.js +12 -2
  49. package/dist/docx/paragraphPropertySource.d.ts +22 -0
  50. package/dist/docx/paragraphPropertySource.js +85 -16
  51. package/dist/docx/parser.js +2 -0
  52. package/dist/docx/removeHeaderFooterParts.js +1 -1
  53. package/dist/docx/reviewResolutionProvenance.js +72 -19
  54. package/dist/docx/serializer/documentSerializer.js +2 -1
  55. package/dist/docx/serializer/partNamespaces.d.ts +1 -1
  56. package/dist/docx/serializer/partNamespaces.js +1 -1
  57. package/dist/docx/server/build.d.ts +1 -1
  58. package/dist/docx/storyBlockReplay.js +15 -2
  59. package/dist/docx/structuralXmlPatch.js +25 -4
  60. package/dist/docx/xmlParser.d.ts +1 -1
  61. package/dist/docx/xmlParser.js +2 -3
  62. package/dist/i18n/messages/ar.gen.js +1 -0
  63. package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
  64. package/dist/i18n/messages/catalogs.gen.js +17 -0
  65. package/dist/i18n/messages/cs.gen.js +1 -0
  66. package/dist/i18n/messages/de.gen.js +1 -0
  67. package/dist/i18n/messages/en.gen.js +1 -0
  68. package/dist/i18n/messages/es.gen.js +1 -0
  69. package/dist/i18n/messages/et.gen.js +1 -0
  70. package/dist/i18n/messages/fr.gen.js +1 -0
  71. package/dist/i18n/messages/he.gen.js +1 -0
  72. package/dist/i18n/messages/hi.gen.js +1 -0
  73. package/dist/i18n/messages/hu.gen.js +1 -0
  74. package/dist/i18n/messages/lt.gen.js +1 -0
  75. package/dist/i18n/messages/lv.gen.js +1 -0
  76. package/dist/i18n/messages/messages.gen.d.ts +1 -0
  77. package/dist/i18n/messages/pl.gen.js +1 -0
  78. package/dist/i18n/messages/pt-BR.gen.js +1 -0
  79. package/dist/i18n/messages/sk.gen.js +1 -0
  80. package/dist/i18n/messages/tr.gen.js +1 -0
  81. package/dist/i18n/messages/zh-CN.gen.js +1 -0
  82. package/dist/internal/pageBreakRunDescendantIndex.d.ts +7 -2
  83. package/dist/internal/pageBreakRunDescendantIndex.js +12 -3
  84. package/dist/internal/subtreeHolds.d.ts +12 -0
  85. package/dist/internal/subtreeHolds.js +25 -0
  86. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  87. package/dist/layout-bridge/cellSelectionHighlight.js +3 -3
  88. package/dist/layout-bridge/convert/flowBlockPostprocessing.js +20 -12
  89. package/dist/layout-bridge/convert/flowConversionShared.d.ts +15 -1
  90. package/dist/layout-bridge/convert/flowConversionShared.js +9 -1
  91. package/dist/layout-bridge/convert/paragraphAttrs.d.ts +15 -4
  92. package/dist/layout-bridge/convert/paragraphAttrs.js +11 -4
  93. package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +26 -0
  94. package/dist/layout-bridge/convert/paragraphBlockCache.js +137 -0
  95. package/dist/layout-bridge/convert/paragraphConversion.d.ts +12 -2
  96. package/dist/layout-bridge/convert/paragraphConversion.js +37 -5
  97. package/dist/layout-bridge/convert/paragraphRuns.d.ts +2 -2
  98. package/dist/layout-bridge/convert/sectionBoundaries.js +16 -0
  99. package/dist/layout-bridge/convert/toFlowBlocks.js +144 -15
  100. package/dist/layout-bridge/convert/topLevelConversion.d.ts +74 -0
  101. package/dist/layout-bridge/convert/topLevelConversion.js +109 -0
  102. package/dist/layout-bridge/dom/clickToPositionDom.js +41 -40
  103. package/dist/layout-bridge/dom/findBodyPmSpans.js +4 -3
  104. package/dist/layout-bridge/dom/findHfPmSpans.js +10 -15
  105. package/dist/layout-bridge/dom/imeCaretAnchor.d.ts +8 -0
  106. package/dist/layout-bridge/dom/imeCaretAnchor.js +71 -7
  107. package/dist/layout-bridge/dom/textStreamDom.js +3 -2
  108. package/dist/layout-bridge/headerFooterLayout.js +12 -11
  109. package/dist/layout-bridge/tableInsertHover.js +2 -1
  110. package/dist/layout-engine/measure/cache.d.ts +2 -0
  111. package/dist/layout-engine/measure/cache.js +6 -1
  112. package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +8 -0
  113. package/dist/layout-engine/measure/paragraphKeyMemo.js +92 -0
  114. package/dist/layout-engine/types.d.ts +6 -0
  115. package/dist/layout-painter/imageLayout.js +2 -1
  116. package/dist/layout-painter/pageShellStyles.d.ts +10 -0
  117. package/dist/layout-painter/pageShellStyles.js +32 -0
  118. package/dist/layout-painter/reconcileRenderedContent.d.ts +19 -0
  119. package/dist/layout-painter/reconcileRenderedContent.js +117 -0
  120. package/dist/layout-painter/renderFragment.js +4 -6
  121. package/dist/layout-painter/renderImage.js +2 -2
  122. package/dist/layout-painter/renderPage.js +8 -29
  123. package/dist/layout-painter/renderParagraph.js +3 -3
  124. package/dist/layout-painter/renderTable.js +9 -12
  125. package/dist/layout-painter/renderTextBox.js +2 -2
  126. package/dist/layout-painter/sdtBoundary.js +3 -2
  127. package/dist/paged-layout/blockGeometry.js +3 -2
  128. package/dist/paged-layout/editorScrollRoot.d.ts +9 -0
  129. package/dist/paged-layout/editorScrollRoot.js +10 -1
  130. package/dist/paged-layout/rangeProjection.js +5 -4
  131. package/dist/paged-layout/scrollToPmPosition.js +3 -3
  132. package/dist/paged-layout/selectionViewportRect.d.ts +6 -0
  133. package/dist/paged-layout/selectionViewportRect.js +8 -2
  134. package/dist/prosemirror/attrs/index.js +1 -0
  135. package/dist/prosemirror/commands/comments.d.ts +5 -2
  136. package/dist/prosemirror/commands/comments.js +88 -8
  137. package/dist/prosemirror/commentRecords.d.ts +137 -0
  138. package/dist/prosemirror/commentRecords.js +400 -0
  139. package/dist/prosemirror/conversion/fromProseDoc.js +9 -3
  140. package/dist/prosemirror/conversion/index.d.ts +1 -1
  141. package/dist/prosemirror/conversion/toProseDoc.d.ts +13 -4
  142. package/dist/prosemirror/conversion/toProseDoc.js +126 -38
  143. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +22 -0
  144. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +61 -32
  145. package/dist/prosemirror/extensions/marks/CommentExtension.js +3 -1
  146. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +3 -1
  147. package/dist/prosemirror/index.d.ts +1 -1
  148. package/dist/prosemirror/nativeSelection.d.ts +33 -0
  149. package/dist/prosemirror/nativeSelection.js +74 -0
  150. package/dist/prosemirror/numberedRefFields.d.ts +2 -0
  151. package/dist/prosemirror/numberedRefFields.js +16 -5
  152. package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -8
  153. package/dist/prosemirror/paragraphMarkJoin.js +155 -16
  154. package/dist/prosemirror/plugins/contentControlWidgets.js +2 -2
  155. package/dist/prosemirror/plugins/documentNumbering.js +33 -14
  156. package/dist/prosemirror/plugins/suggestionMode.js +13 -1
  157. package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +23 -1
  158. package/dist/prosemirror/runIdentityAcrossRevisions.js +57 -8
  159. package/dist/prosemirror/schema/marks.d.ts +7 -1
  160. package/dist/prosemirror/storyListNumbering.js +7 -2
  161. package/dist/prosemirror/tableResize.d.ts +10 -9
  162. package/dist/prosemirror/tableResize.js +60 -49
  163. package/dist/prosemirror/textInput.d.ts +30 -1
  164. package/dist/prosemirror/textInput.js +144 -17
  165. package/dist/prosemirror/utils/visualLineNavigation.js +20 -18
  166. package/dist/prosemirror/validation.d.ts +19 -0
  167. package/dist/prosemirror/validation.js +78 -5
  168. package/dist/render-dom/HeaderFooterSelectionOverlay.js +5 -4
  169. package/dist/render-dom/RenderedDomContext.js +7 -6
  170. package/dist/types/canonicalCapabilities.d.ts +12 -11
  171. package/dist/types/canonicalCapabilities.js +12 -13
  172. package/dist/utils/findMatchView.js +4 -3
  173. package/dist/utils/formatToStyle.d.ts +1 -1
  174. package/dist/utils/mergeDocumentContent.js +2 -2
  175. package/dist/utils/paintedPositions.d.ts +60 -0
  176. package/dist/utils/paintedPositions.js +101 -0
  177. package/package.json +2 -3
@@ -2,6 +2,7 @@ import { writeCommentAnchorIds } from "../../render-dom/commentAnchorAttributes.
2
2
  import { bytesToDataUrl } from "../../utils/base64.js";
3
3
  import { cssString } from "../../utils/cssString.js";
4
4
  import { imageLuminanceFilter } from "../../utils/imageLuminance.js";
5
+ import { writePaintedRange } from "../../utils/paintedPositions.js";
5
6
  import { applyTextAdvanceGaps } from "../../utils/textAdvanceGapsDom.js";
6
7
  import { anchorTargetAttrs } from "../../utils/urlSecurity.js";
7
8
  import { retainObjectUrl } from "../pageResourceOwnership.js";
@@ -279,9 +280,13 @@ const applyAdjustments = (span, adjustments) => {
279
280
  */
280
281
  const applyModelRange = (span, range, purpose = "editing") => {
281
282
  if (range === void 0) return;
282
- if (purpose === "editing") span.className = "layout-run-text";
283
- span.dataset[purpose === "editing" ? "pmStart" : "decorationStart"] = String(range.start);
284
- span.dataset[purpose === "editing" ? "pmEnd" : "decorationEnd"] = String(range.end);
283
+ if (purpose === "editing") {
284
+ span.className = "layout-run-text";
285
+ writePaintedRange(span, range.start, range.end);
286
+ } else {
287
+ span.dataset["decorationStart"] = String(range.start);
288
+ span.dataset["decorationEnd"] = String(range.end);
289
+ }
285
290
  const { story } = range;
286
291
  span.dataset["story"] = story.kind;
287
292
  switch (story.kind) {
@@ -577,10 +582,7 @@ const REGION_CLASS = {
577
582
  const applyRegionModel = (element, region) => {
578
583
  const model = region.model;
579
584
  if (model === void 0) return;
580
- if (model.pmRange !== void 0) {
581
- element.dataset["pmStart"] = String(model.pmRange.start);
582
- element.dataset["pmEnd"] = String(model.pmRange.end);
583
- }
585
+ if (model.pmRange !== void 0) writePaintedRange(element, model.pmRange.start, model.pmRange.end);
584
586
  if (model.blockId !== void 0) element.dataset["blockId"] = model.blockId;
585
587
  if (model.commentIds !== void 0) writeCommentAnchorIds(element, model.commentIds);
586
588
  if (model.rowIndex !== void 0) element.dataset["rowIndex"] = String(model.rowIndex);
@@ -1,5 +1,5 @@
1
- import { NumberingIdsInUse } from "./docx/numberingIds.js";
2
1
  import { document_d_exports } from "./types/document.js";
2
+ import { NumberingIdsInUse } from "./docx/numberingIds.js";
3
3
  import { FolioTableTemplates } from "./ai-edits/table-template.js";
4
4
  import { FolioAIEditAppliedOperation, FolioAIEditApplyMode, FolioAIEditNormalization, FolioAIEditOperation, FolioAIEditPrecondition, FolioAIEditSkippedOperation, FolioAIEditSnapshot, FolioAITextRangeHandle } from "./ai-edits/types.js";
5
5
  import { FolioAIEditView, FolioReplacementBackground, FolioRevisionStamp, FolioUndefinedReferencePolicy, FolioWordDiffOptions } from "./ai-edits/apply.js";
@@ -7,7 +7,7 @@ import { getDocumentSourceBaseline } from "./headerFooterVerbatim.js";
7
7
  import { resolveSelectiveSaveFlags } from "./selectiveSaveFlags.js";
8
8
  import { withoutUnusedSessionLists } from "./sessionListPruning.js";
9
9
  import { Result, TaggedError } from "better-result";
10
- import { withoutPendingSuggestions } from "@stll/docx-core/ops";
10
+ import { idKey, packageParagraphIds, withoutPendingSuggestions } from "@stll/docx-core/ops";
11
11
  // src/docx/canonicalSave.ts
12
12
  const CanonicalSaveDiagnosticErrorBase = TaggedError("CanonicalSaveDiagnosticError");
13
13
  /** Forward a fidelity fallback through the adapters' existing error channel. */
@@ -31,6 +31,11 @@ const serializeCanonicalSave = async ({ snapshot, options, featureFlags }) => {
31
31
  diagnostic
32
32
  });
33
33
  }
34
+ const heldBack = /* @__PURE__ */ new Set();
35
+ if (withoutSuggestions.value !== snapshot.document) {
36
+ const kept = new Set(packageParagraphIds(withoutSuggestions.value.package).map(idKey));
37
+ for (const id of packageParagraphIds(snapshot.document.package)) if (!kept.has(idKey(id))) heldBack.add(idKey(id));
38
+ }
34
39
  const baseline = document.originalBuffer;
35
40
  const flags = resolveSelectiveSaveFlags(featureFlags);
36
41
  const diagnostics = [];
@@ -44,7 +49,7 @@ const serializeCanonicalSave = async ({ snapshot, options, featureFlags }) => {
44
49
  const { attemptSelectiveSave } = await import("./selectiveSave.js");
45
50
  selectiveBuffer = await attemptSelectiveSave(document, baseline, {
46
51
  bodyAuthority: "canonical",
47
- changedParaIds: new Set(snapshot.changedBlockIds),
52
+ changedParaIds: new Set(snapshot.changedBlockIds.filter((id) => !heldBack.has(idKey(id)))),
48
53
  structuralChange: snapshot.structure === "changed",
49
54
  hasUntrackedChanges: false,
50
55
  maxBytes: flags.selectiveSaveMaxBytes,
@@ -27,6 +27,25 @@ export type BlockCommentMarkerSlot = {
27
27
  };
28
28
  export type CommentMarkerSlot = InlineCommentMarkerSlot | BlockCommentMarkerSlot;
29
29
  export declare const visitCommentMarkers: (blocks: readonly document_d_exports.BlockContent[], visit: (slot: CommentMarkerSlot) => void) => void;
30
+ /** A paragraph's comment markers, in document order. */
31
+ export type ParagraphCommentMarkers = (paragraph: document_d_exports.Paragraph) => readonly CommentMarker[];
32
+ /** A paragraph's comment markers, read from all of its content. */
33
+ export declare const paragraphCommentMarkers: ParagraphCommentMarkers;
34
+ /**
35
+ * Each paragraph's comment markers, read once per paragraph object. Only for
36
+ * documents whose paragraphs are never changed in place, as a session's
37
+ * versions are: an edit replaces the paragraphs it changes.
38
+ */
39
+ export declare class CommentMarkerCache {
40
+ private readonly known;
41
+ readonly read: ParagraphCommentMarkers;
42
+ }
43
+ /**
44
+ * Every comment marker of a story's blocks in the order
45
+ * {@link visitCommentMarkers} visits them, each paragraph's read through
46
+ * `markersOf`.
47
+ */
48
+ export declare const visitCommentMarkerItems: (blocks: readonly document_d_exports.BlockContent[], markersOf: ParagraphCommentMarkers, visit: (item: CommentMarker | BlockCommentMarkerSlot["item"]) => void) => void;
30
49
  /** Remove every serialized anchor record for comments whose definitions are retired. */
31
50
  export declare const removeCommentMarkers: (blocks: readonly document_d_exports.BlockContent[], commentIds: ReadonlySet<number>) => document_d_exports.BlockContent[];
32
51
  /**
@@ -52,6 +52,60 @@ const visitCommentMarkers = (blocks, visit) => {
52
52
  };
53
53
  visitBlocks(blocks);
54
54
  };
55
+ /** A paragraph's comment markers, read from all of its content. */
56
+ const paragraphCommentMarkers = (paragraph) => {
57
+ const markers = [];
58
+ visitInlineContentSlots(paragraph, ({ item }) => {
59
+ if (item.type === "commentRangeStart" || item.type === "commentRangeEnd" || item.type === "commentReference") markers.push(item);
60
+ });
61
+ return markers;
62
+ };
63
+ /**
64
+ * Each paragraph's comment markers, read once per paragraph object. Only for
65
+ * documents whose paragraphs are never changed in place, as a session's
66
+ * versions are: an edit replaces the paragraphs it changes.
67
+ */
68
+ var CommentMarkerCache = class {
69
+ known = /* @__PURE__ */ new WeakMap();
70
+ read = (paragraph) => {
71
+ const kept = this.known.get(paragraph);
72
+ if (kept !== void 0) return kept;
73
+ const markers = paragraphCommentMarkers(paragraph);
74
+ this.known.set(paragraph, markers);
75
+ return markers;
76
+ };
77
+ };
78
+ /**
79
+ * Every comment marker of a story's blocks in the order
80
+ * {@link visitCommentMarkers} visits them, each paragraph's read through
81
+ * `markersOf`.
82
+ */
83
+ const visitCommentMarkerItems = (blocks, markersOf, visit) => {
84
+ for (const block of blocks) switch (block.type) {
85
+ case "commentRangeStart":
86
+ case "commentRangeEnd":
87
+ visit(block);
88
+ break;
89
+ case "paragraph":
90
+ for (const marker of markersOf(block)) visit(marker);
91
+ break;
92
+ case "table":
93
+ for (const row of block.rows) for (const cell of row.cells) visitCommentMarkerItems(cell.content, markersOf, visit);
94
+ break;
95
+ case "blockSdt":
96
+ case "blockCustomXml":
97
+ visitCommentMarkerItems(block.content, markersOf, visit);
98
+ break;
99
+ case "preservedBlock":
100
+ case "bookmarkStart":
101
+ case "bookmarkEnd":
102
+ case "moveFromRangeStart":
103
+ case "moveFromRangeEnd":
104
+ case "moveToRangeStart":
105
+ case "moveToRangeEnd": break;
106
+ default: return block;
107
+ }
108
+ };
55
109
  /** Remove every serialized anchor record for comments whose definitions are retired. */
56
110
  const removeCommentMarkers = (blocks, commentIds) => {
57
111
  if (commentIds.size === 0) return blocks.slice();
@@ -309,4 +363,4 @@ const rangedCommentIds = (blocks) => {
309
363
  });
310
364
  return ids;
311
365
  };
312
- export { rangedCommentIds, removeCommentMarkers, visitCommentMarkers };
366
+ export { CommentMarkerCache, paragraphCommentMarkers, rangedCommentIds, removeCommentMarkers, visitCommentMarkerItems, visitCommentMarkers };
@@ -1,7 +1,7 @@
1
1
  import { TRANSITIONAL_NAMESPACE_BY_STRICT_URI } from "./strictValueEncodings.gen.js";
2
2
  import { captureVerbatimXml } from "./verbatimCapture.js";
3
3
  import { WORDPROCESSINGML_NAMESPACE_URIS, getChildElements, getLocalName, getNamespaceUri } from "./xmlParser.js";
4
- import { OOXML_NS } from "@stll/docx-utils";
4
+ import { OOXML_NS } from "@stll/docx-core/xml/namespaces";
5
5
  import { SEQUENCE_CHILDREN } from "@stll/docx-core/schema";
6
6
  // src/docx/containerChildren.ts
7
7
  /** Keep this child's markup verbatim, in place. */
@@ -3,7 +3,7 @@ import { spliceXml } from "./selectiveXmlPatch.js";
3
3
  import { getAttribute, getLocalName, getNamespacePrefix, getNamespaceUri, parseXmlDocument } from "./xmlParser.js";
4
4
  import { panic } from "better-result";
5
5
  import { escapeXmlAttribute } from "@stll/docx-core";
6
- import { OOXML_NS } from "@stll/docx-utils";
6
+ import { OOXML_NS } from "@stll/docx-core/xml/namespaces";
7
7
  // src/docx/contentTypeRegistry.ts
8
8
  /** Register a package part without rewriting authored content-type entries. */
9
9
  const registerContentTypeParts = (xml, parts) => {
@@ -10,8 +10,18 @@ export declare function getCommentParentId(comment: Comment): number | null | un
10
10
  * whose parent chain does not reach a kept top-level comment are dropped.
11
11
  */
12
12
  export declare function pruneOrphanedComments(comments: readonly Comment[], _referencedIds?: ReadonlySet<number>): Comment[];
13
+ export type HostCommentThreadsOptions = {
14
+ /**
15
+ * The comment ids the editor's own document anchors, or `null` when the
16
+ * host has no editor document. A thread anchored there that the document
17
+ * being saved leaves out (a comment a pending suggestion proposes, which
18
+ * the save holds back with the suggestion) is left out with its replies:
19
+ * a saved thread without its anchor is a stray card on reopening.
20
+ */
21
+ anchoredInEditor: ReadonlySet<number> | null;
22
+ };
13
23
  /**
14
24
  * `document` with its body's comment threads replaced by the host's. The body
15
25
  * and package are copied, so the document passed in is left as it was.
16
26
  */
17
- export declare function withHostCommentThreads(document: document_d_exports.Document, comments: readonly Comment[]): document_d_exports.Document;
27
+ export declare function withHostCommentThreads(document: document_d_exports.Document, comments: readonly Comment[], { anchoredInEditor }: HostCommentThreadsOptions): document_d_exports.Document;
@@ -1,4 +1,5 @@
1
1
  import { setDocumentBodyComments } from "./canonicalModel.js";
2
+ import { visitCommentMarkers } from "./commentAnchorIndex.js";
2
3
  // src/docx/hostCommentThreads.ts
3
4
  function getCommentParentId(comment) {
4
5
  return comment.parentId;
@@ -31,13 +32,35 @@ function pruneOrphanedComments(comments, _referencedIds) {
31
32
  }
32
33
  return comments.filter((comment) => keptIds.has(comment.id));
33
34
  }
35
+ /** The comment ids the saved stories of `document` anchor. */
36
+ const commentIdsAnchoredIn = (document) => {
37
+ const ids = /* @__PURE__ */ new Set();
38
+ const visit = (blocks) => visitCommentMarkers(blocks, ({ item }) => {
39
+ ids.add(item.id);
40
+ });
41
+ const { package: pkg } = document;
42
+ visit(pkg.document.content);
43
+ for (const story of [
44
+ ...pkg.headers?.values() ?? [],
45
+ ...pkg.footers?.values() ?? [],
46
+ ...pkg.footnotes ?? [],
47
+ ...pkg.endnotes ?? []
48
+ ]) visit(story.content);
49
+ return ids;
50
+ };
34
51
  /**
35
52
  * `document` with its body's comment threads replaced by the host's. The body
36
53
  * and package are copied, so the document passed in is left as it was.
37
54
  */
38
- function withHostCommentThreads(document, comments) {
55
+ function withHostCommentThreads(document, comments, { anchoredInEditor }) {
39
56
  const body = { ...document.package.document };
40
- setDocumentBodyComments(body, pruneOrphanedComments(comments));
57
+ const kept = (() => {
58
+ if (anchoredInEditor === null || anchoredInEditor.size === 0) return comments;
59
+ const saved = commentIdsAnchoredIn(document);
60
+ const heldBack = new Set(comments.filter(({ id }) => anchoredInEditor.has(id) && !saved.has(id)).map(({ id }) => id));
61
+ return heldBack.size === 0 ? comments : comments.filter(({ id }) => !heldBack.has(id));
62
+ })();
63
+ setDocumentBodyComments(body, pruneOrphanedComments(kept));
41
64
  return {
42
65
  ...document,
43
66
  package: {
@@ -7,27 +7,26 @@ import { foldListNumberFields, planParagraphListNumberFold, unfoldedListNumberCo
7
7
  import { computeListMarker, restoreListCounters, sameListCounters, snapshotListCounters } from "./listMarkerComputation.js";
8
8
  import { listRenderingDefinitionsMatch } from "./listRendering.js";
9
9
  import { computeListRendering, getCachedNumberingMap } from "./numberingParser.js";
10
- import { assignParagraphIndentationProjection, cloneParagraphWithPropertySource, paragraphFormattingWithAuthoredIndentation, paragraphPropertySourceState, sameParagraphIndentationProjection } from "./paragraphPropertySource.js";
10
+ import { assignParagraphIndentationProjection, cloneParagraphWithPropertySource, paragraphFormattingWithAuthoredIndentation, paragraphPropertySourceStamp, paragraphPropertySourceStampMatches, sameParagraphIndentationProjection } from "./paragraphPropertySource.js";
11
11
  import { panic } from "better-result";
12
12
  import { finalizeParagraphFormatting } from "@stll/docx-core/model";
13
13
  import { DOCUMENT_OP_TYPES, EMPTY_PROPERTY_SETS, OP_STORIES, paragraphPropertySnapshotToken, registerParagraphPropertySnapshot, withBodyContent } from "@stll/docx-core/ops";
14
14
  // src/docx/listModelNormalization.ts
15
15
  /** Canonical edits retain authored fields; list rendering follows the current numbering. */
16
16
  const CHECKPOINT_SPACING = 32;
17
- const sameState = (left, right) => left.length === right.length && left.every((value, index) => value === right[index]);
18
17
  const recordOf = (input, settled) => input.type === "paragraph" ? {
19
18
  input,
20
19
  settled,
21
- sourceState: paragraphPropertySourceState(input),
20
+ sourceStamp: paragraphPropertySourceStamp(input),
22
21
  snapshotToken: paragraphPropertySnapshotToken(input)
23
22
  } : {
24
23
  input,
25
24
  settled,
26
- sourceState: void 0,
25
+ sourceStamp: void 0,
27
26
  snapshotToken: void 0
28
27
  };
29
28
  /** Whether normalizing `block` again would leave it, its facts and its registration as they are. */
30
- const stillSettled = (block, record) => record.settled && block === record.input && (block.type !== "paragraph" || record.sourceState !== void 0 && sameState(record.sourceState, paragraphPropertySourceState(block)) && paragraphPropertySnapshotToken(block) === record.snapshotToken);
29
+ const stillSettled = (block, record) => record.settled && block === record.input && (block.type !== "paragraph" || record.sourceStamp !== void 0 && paragraphPropertySourceStampMatches(block, record.sourceStamp) && paragraphPropertySnapshotToken(block) === record.snapshotToken);
31
30
  const storyKey = (story) => {
32
31
  if (story === OP_STORIES.MAIN) return story;
33
32
  return "rId" in story ? `${story.kind}:${story.rId}` : `${story.kind}:${String(story.id)}`;
@@ -1,5 +1,5 @@
1
- import { NumberingIdsInUse } from "./numberingIds.js";
2
1
  import { document_d_exports } from "../types/document.js";
2
+ import { NumberingIdsInUse } from "./numberingIds.js";
3
3
  /** The two kinds of list a command can create. */
4
4
  export declare const LIST_KINDS: readonly ["bullet", "numbered"];
5
5
  export type ListKind = (typeof LIST_KINDS)[number];
@@ -1,4 +1,4 @@
1
- import { createNumberingIdAllocator, mintNumberingId } from "./numberingIds.js";
1
+ import { createNumberingIdAllocator, mintNumberingId, numberingNumIdsTaken } from "./numberingIds.js";
2
2
  import { NUMBER_FORMATS } from "@stll/docx-core/model";
3
3
  // src/docx/listNumberingInstances.ts
4
4
  /**
@@ -119,7 +119,7 @@ const EMPTY_DEFINITIONS = {
119
119
  /** A fresh `w:numId` for `definitions`; zero is reserved for "no numbering". */
120
120
  const nextNumId = (definitions, elsewhere) => mintNumberingId({
121
121
  kind: "num",
122
- existingIds: [...(definitions?.nums ?? []).map(({ numId }) => numId), ...elsewhere.numIds]
122
+ existingIds: [...numberingNumIdsTaken(definitions), ...elsewhere.numIds]
123
123
  });
124
124
  /** A fresh `w:abstractNumId` for `definitions`. */
125
125
  const nextAbstractNumId = (definitions, elsewhere) => mintNumberingId({
@@ -1,3 +1,9 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ /**
3
+ * Every `w:numId` `definitions` holds: the instances it defines and the ids a
4
+ * paragraph or style names without a definition, which a new list never takes.
5
+ */
6
+ export declare const numberingNumIdsTaken: (definitions: document_d_exports.NumberingDefinitions | null | undefined) => number[];
1
7
  type NumberingKind = "num" | "abstract";
2
8
  /**
3
9
  * Numbering ids (`w:num`, `w:abstractNum`) defined outside the numbering a
@@ -1,5 +1,10 @@
1
1
  import { createNumericIdAllocator } from "./numericIdAllocator.js";
2
2
  // src/docx/numberingIds.ts
3
+ /**
4
+ * Every `w:numId` `definitions` holds: the instances it defines and the ids a
5
+ * paragraph or style names without a definition, which a new list never takes.
6
+ */
7
+ const numberingNumIdsTaken = (definitions) => [...(definitions?.nums ?? []).map(({ numId }) => numId), ...definitions?.danglingNumIds ?? []];
3
8
  const NO_NUMBERING_IDS_IN_USE = {
4
9
  numIds: /* @__PURE__ */ new Set(),
5
10
  abstractNumIds: /* @__PURE__ */ new Set()
@@ -16,4 +21,4 @@ const createNumberingIdAllocator = (kind, existingIds) => {
16
21
  const mintNumberingId = ({ kind, existingIds }) => {
17
22
  return createNumberingIdAllocator(kind, existingIds).next();
18
23
  };
19
- export { NO_NUMBERING_IDS_IN_USE, createNumberingIdAllocator, mintNumberingId };
24
+ export { NO_NUMBERING_IDS_IN_USE, createNumberingIdAllocator, mintNumberingId, numberingNumIdsTaken };
@@ -13,6 +13,8 @@ type NormalizeNumberingReferencesInput = {
13
13
  };
14
14
  type NormalizeNumberingReferencesResult = {
15
15
  unnumberedDanglingReferences: number;
16
+ /** The ids the repaired references named. */
17
+ danglingNumIds: ReadonlySet<number>;
16
18
  };
17
19
  export declare const normalizeNumberingReferences: ({ documentBody, numbering, headers, footers, footnotes, endnotes }: NormalizeNumberingReferencesInput) => NormalizeNumberingReferencesResult;
18
20
  type NormalizeStyleNumberingReferencesInput = {
@@ -22,6 +24,8 @@ type NormalizeStyleNumberingReferencesInput = {
22
24
  type NormalizeStyleNumberingReferencesResult = {
23
25
  /** Style ids whose dangling reference became the "no numbering" sentinel. */
24
26
  unnumberedStyleIds: string[];
27
+ /** The ids the repaired references named. */
28
+ danglingNumIds: ReadonlySet<number>;
25
29
  };
26
30
  export declare const normalizeStyleNumberingReferences: ({ styles, numbering }: NormalizeStyleNumberingReferencesInput) => NormalizeStyleNumberingReferencesResult;
27
31
  export {};
@@ -29,6 +29,7 @@ const UNNUMBERED_PARAGRAPH_WARNING = PARSE_WARNING_CODES.unnumberedParagraph;
29
29
  const UNNUMBERED_STYLE_WARNING = PARSE_WARNING_CODES.unnumberedStyle;
30
30
  const normalizeNumberingReferences = ({ documentBody, numbering, headers, footers, footnotes, endnotes }) => {
31
31
  let unnumberedDanglingReferences = 0;
32
+ const danglingNumIds = /* @__PURE__ */ new Set();
32
33
  visitDocxParagraphs({
33
34
  documentBody,
34
35
  headers,
@@ -39,22 +40,31 @@ const normalizeNumberingReferences = ({ documentBody, numbering, headers, footer
39
40
  const formatting = paragraph.formatting;
40
41
  const numId = paragraphNumberingReferenceId(formatting?.numPr);
41
42
  if (!formatting || numId === void 0 || resolvesNumbering(numId, numbering)) return;
43
+ danglingNumIds.add(numId);
42
44
  formatting.numPr = NO_PARAGRAPH_NUMBERING$1;
43
45
  delete formatting.numPrFromStyle;
44
46
  delete paragraph.listRendering;
45
47
  unnumberedDanglingReferences += 1;
46
48
  });
47
- return { unnumberedDanglingReferences };
49
+ return {
50
+ unnumberedDanglingReferences,
51
+ danglingNumIds
52
+ };
48
53
  };
49
54
  const normalizeStyleNumberingReferences = ({ styles, numbering }) => {
50
55
  const unnumberedStyleIds = [];
56
+ const danglingNumIds = /* @__PURE__ */ new Set();
51
57
  for (const style of styles) {
52
58
  const pPr = style.pPr;
53
59
  const numId = paragraphNumberingReferenceId(pPr?.numPr);
54
60
  if (!pPr || numId === void 0 || resolvesNumbering(numId, numbering)) continue;
61
+ danglingNumIds.add(numId);
55
62
  pPr.numPr = NO_PARAGRAPH_NUMBERING$1;
56
63
  unnumberedStyleIds.push(style.styleId);
57
64
  }
58
- return { unnumberedStyleIds };
65
+ return {
66
+ unnumberedStyleIds,
67
+ danglingNumIds
68
+ };
59
69
  };
60
70
  export { UNNUMBERED_PARAGRAPH_WARNING, UNNUMBERED_STYLE_WARNING, normalizeNumberingReferences, normalizeStyleNumberingReferences };
@@ -34,6 +34,11 @@ type AssignParagraphIndentationProjectionOptions = {
34
34
  /** Keep the model's effective indentation without making inherited values authored. */
35
35
  export declare const assignParagraphIndentationProjection: ({ paragraph, authored, inherited }: AssignParagraphIndentationProjectionOptions) => void;
36
36
  export declare const PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR = "_docxParagraphSourceToken";
37
+ /**
38
+ * Where a paragraph-mark join takes the source attributes from: the next
39
+ * paragraph, whose mark stays. The joins then record the source transfer.
40
+ */
41
+ export declare const PARAGRAPH_SOURCE_JOIN_RULES: Readonly<Record<typeof PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, "next">>;
37
42
  export declare const PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR = "_docxParagraphSourceContract";
38
43
  /** Durable identity nested inside opaque collapsed-cell ProseMirror attrs; stripped on restore. */
39
44
  export declare const TABLE_CELL_PARAGRAPH_SOURCE_BINDING_ATTR = "_docxParagraphSourceBinding";
@@ -78,6 +83,23 @@ export declare const copyDocumentParagraphPropertySourceContract: (target: docum
78
83
  * converted with.
79
84
  */
80
85
  export declare const paragraphPropertySourceState: (paragraph: document_d_exports.Paragraph) => readonly unknown[];
86
+ /**
87
+ * Where the facts `paragraphPropertySourceState` reads for a paragraph stood:
88
+ * they are keyed by the paragraph, by its formatting object, and by handles
89
+ * that are written once, when they are made. Reading it allocates; matching
90
+ * it against the paragraph does not.
91
+ */
92
+ export type ParagraphPropertySourceStamp = Readonly<{
93
+ paragraph: number | undefined;
94
+ formatting: object | undefined;
95
+ formattingStamp: number | undefined;
96
+ }>;
97
+ export declare const paragraphPropertySourceStamp: (paragraph: document_d_exports.Paragraph) => ParagraphPropertySourceStamp;
98
+ /**
99
+ * Whether no fact kept for the paragraph changed since `stamp` was read: its
100
+ * `paragraphPropertySourceState` is then the one it was.
101
+ */
102
+ export declare const paragraphPropertySourceStampMatches: (paragraph: document_d_exports.Paragraph, stamp: ParagraphPropertySourceStamp) => boolean;
81
103
  export declare const getParagraphPropertySourceToken: (paragraph: document_d_exports.Paragraph) => string | undefined;
82
104
  type ParagraphSourceIdentity = {
83
105
  type: "durable";
@@ -6,6 +6,60 @@ import { visitDocxParagraphs } from "./paragraphTraversal.js";
6
6
  import { parseXmlDocument } from "./xmlParser.js";
7
7
  import { TaggedError, panic } from "better-result";
8
8
  // src/docx/paragraphPropertySource.ts
9
+ /**
10
+ * A stamp per object, renewed whenever a fact this module keeps for it
11
+ * changes. Every table read by `paragraphPropertySourceState` writes through
12
+ * `KeptFacts` or `KeptFlags`, and every handle a paragraph carries is set
13
+ * through `keepHandle`, so an unchanged stamp means unchanged facts.
14
+ */
15
+ const factStamps = /* @__PURE__ */ new WeakMap();
16
+ let lastFactStamp = 0;
17
+ const renewFacts = (key) => {
18
+ lastFactStamp += 1;
19
+ factStamps.set(key, lastFactStamp);
20
+ };
21
+ /** A weak table whose writes renew the stamp of the key they change. */
22
+ var KeptFacts = class {
23
+ table = /* @__PURE__ */ new WeakMap();
24
+ get(key) {
25
+ return this.table.get(key);
26
+ }
27
+ has(key) {
28
+ return this.table.has(key);
29
+ }
30
+ set(key, value) {
31
+ if (this.table.has(key) && this.table.get(key) === value) return;
32
+ this.table.set(key, value);
33
+ renewFacts(key);
34
+ }
35
+ };
36
+ /** A weak set whose writes renew the stamp of the key they change. */
37
+ var KeptFlags = class {
38
+ flags = /* @__PURE__ */ new WeakSet();
39
+ has(key) {
40
+ return this.flags.has(key);
41
+ }
42
+ add(key) {
43
+ if (this.flags.has(key)) return;
44
+ this.flags.add(key);
45
+ renewFacts(key);
46
+ }
47
+ delete(key) {
48
+ if (this.flags.delete(key)) renewFacts(key);
49
+ }
50
+ };
51
+ /** Set or remove (`undefined`) the handle a paragraph carries under `key`. */
52
+ const keepHandle = (paragraph, key, descriptor) => {
53
+ const current = Object.getOwnPropertyDescriptor(paragraph, key);
54
+ if (descriptor === void 0) {
55
+ if (current === void 0) return;
56
+ Reflect.deleteProperty(paragraph, key);
57
+ } else {
58
+ if (current !== void 0 && current.value === descriptor.value) return;
59
+ Object.defineProperty(paragraph, key, descriptor);
60
+ }
61
+ renewFacts(paragraph);
62
+ };
9
63
  const paragraphPropertySourceEmissionFingerprint = Symbol("paragraphPropertySourceEmissionFingerprint");
10
64
  const paragraphPropertySourceIndentationBaseline = Symbol("paragraphPropertySourceIndentationBaseline");
11
65
  const INDENTATION_FIELDS = [
@@ -16,8 +70,8 @@ const INDENTATION_FIELDS = [
16
70
  ];
17
71
  const paragraphPropertyCapture = Symbol("paragraphPropertyCapture");
18
72
  const paragraphIndentationProjection = Symbol("paragraphIndentationProjection");
19
- const indentationProjections = /* @__PURE__ */ new WeakMap();
20
- const assignedIndentationProjections = /* @__PURE__ */ new WeakSet();
73
+ const indentationProjections = new KeptFacts();
74
+ const assignedIndentationProjections = new KeptFlags();
21
75
  const indentationProjectionFor = (paragraph) => {
22
76
  const handle = Object.getOwnPropertyDescriptor(paragraph, paragraphIndentationProjection)?.value;
23
77
  return typeof handle === "object" && handle !== null ? indentationProjections.get(handle) : void 0;
@@ -33,12 +87,12 @@ const sameParagraphIndentationProjection = ({ left, right }) => {
33
87
  const copyParagraphIndentationProjection = ({ target, source }) => {
34
88
  if (assignedIndentationProjections.has(target) || Object.hasOwn(target, paragraphIndentationProjection)) return;
35
89
  const descriptor = Object.getOwnPropertyDescriptor(source, paragraphIndentationProjection);
36
- if (descriptor && indentationProjectionFor(source)) Object.defineProperty(target, paragraphIndentationProjection, descriptor);
90
+ if (descriptor && indentationProjectionFor(source)) keepHandle(target, paragraphIndentationProjection, descriptor);
37
91
  };
38
92
  /** History restores its captured authored/effective baseline before normalization. */
39
93
  const restoreParagraphIndentationProjection = ({ target, source }) => {
40
94
  assignedIndentationProjections.delete(target);
41
- Reflect.deleteProperty(target, paragraphIndentationProjection);
95
+ keepHandle(target, paragraphIndentationProjection, void 0);
42
96
  copyParagraphIndentationProjection({
43
97
  target,
44
98
  source
@@ -70,7 +124,7 @@ const assignParagraphIndentationProjection = ({ paragraph, authored, inherited }
70
124
  };
71
125
  if (Object.keys(paragraph.formatting).length === 0) delete paragraph.formatting;
72
126
  if (Object.values(effective).every((value) => value === void 0) || getParagraphPropertySource(paragraph) === void 0 && INDENTATION_FIELDS.every((key) => effective[key] === authored?.[key])) {
73
- Reflect.deleteProperty(paragraph, paragraphIndentationProjection);
127
+ keepHandle(paragraph, paragraphIndentationProjection, void 0);
74
128
  return;
75
129
  }
76
130
  const handle = Object.freeze({});
@@ -78,14 +132,14 @@ const assignParagraphIndentationProjection = ({ paragraph, authored, inherited }
78
132
  effective: Object.freeze(indentationFields(paragraph.formatting)),
79
133
  authored: Object.freeze(indentationFields(authored))
80
134
  }));
81
- Object.defineProperty(paragraph, paragraphIndentationProjection, {
135
+ keepHandle(paragraph, paragraphIndentationProjection, {
82
136
  value: handle,
83
137
  enumerable: true,
84
138
  configurable: true
85
139
  });
86
140
  };
87
- const paragraphPropertyCaptures = /* @__PURE__ */ new WeakMap();
88
- const paragraphSourceRecordKinds = /* @__PURE__ */ new WeakMap();
141
+ const paragraphPropertyCaptures = new KeptFacts();
142
+ const paragraphSourceRecordKinds = new KeptFacts();
89
143
  const captureForParagraph = (paragraph) => {
90
144
  const handle = Object.getOwnPropertyDescriptor(paragraph, paragraphPropertyCapture)?.value;
91
145
  if (!Object.hasOwn(paragraph, paragraphPropertyCapture)) return paragraphPropertyCaptures.get(paragraph);
@@ -94,7 +148,7 @@ const captureForParagraph = (paragraph) => {
94
148
  const attachParagraphCapture = (paragraph, capture) => {
95
149
  const handle = Object.freeze({});
96
150
  paragraphPropertyCaptures.set(handle, capture);
97
- Object.defineProperty(paragraph, paragraphPropertyCapture, {
151
+ keepHandle(paragraph, paragraphPropertyCapture, {
98
152
  value: handle,
99
153
  enumerable: true,
100
154
  configurable: true
@@ -114,12 +168,17 @@ const ownedParagraphPropertySource = (paragraph, xml) => {
114
168
  });
115
169
  };
116
170
  const proseParagraphSourceOwners = /* @__PURE__ */ new WeakMap();
117
- const paragraphPropertySourceCandidates = /* @__PURE__ */ new WeakMap();
118
- const paragraphPropertySourceTransferIds = /* @__PURE__ */ new WeakMap();
119
- const paragraphPropertySourceTokens = /* @__PURE__ */ new WeakMap();
171
+ const paragraphPropertySourceCandidates = new KeptFacts();
172
+ const paragraphPropertySourceTransferIds = new KeptFacts();
173
+ const paragraphPropertySourceTokens = new KeptFacts();
120
174
  const documentParagraphPropertySourceBindingBrand = Symbol("documentParagraphPropertySourceBinding");
121
175
  const documentParagraphPropertySourceBinding = Symbol("paragraphPropertySourceBinding");
122
176
  const PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR = "_docxParagraphSourceToken";
177
+ /**
178
+ * Where a paragraph-mark join takes the source attributes from: the next
179
+ * paragraph, whose mark stays. The joins then record the source transfer.
180
+ */
181
+ const PARAGRAPH_SOURCE_JOIN_RULES = { [PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR]: "next" };
123
182
  const PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR = "_docxParagraphSourceContract";
124
183
  /** Durable identity nested inside opaque collapsed-cell ProseMirror attrs; stripped on restore. */
125
184
  const TABLE_CELL_PARAGRAPH_SOURCE_BINDING_ATTR = "_docxParagraphSourceBinding";
@@ -324,6 +383,16 @@ const paragraphPropertySourceState = (paragraph) => [
324
383
  decodedTableCellParagraphSourcePayloads.get(paragraph),
325
384
  ...paragraph.formatting === void 0 ? [] : [paragraphPropertyCaptures.get(paragraph.formatting), indentationProjections.get(paragraph.formatting)]
326
385
  ];
386
+ const paragraphPropertySourceStamp = (paragraph) => ({
387
+ paragraph: factStamps.get(paragraph),
388
+ formatting: paragraph.formatting,
389
+ formattingStamp: paragraph.formatting === void 0 ? void 0 : factStamps.get(paragraph.formatting)
390
+ });
391
+ /**
392
+ * Whether no fact kept for the paragraph changed since `stamp` was read: its
393
+ * `paragraphPropertySourceState` is then the one it was.
394
+ */
395
+ const paragraphPropertySourceStampMatches = (paragraph, stamp) => factStamps.get(paragraph) === stamp.paragraph && paragraph.formatting === stamp.formatting && (paragraph.formatting === void 0 || factStamps.get(paragraph.formatting) === stamp.formattingStamp);
327
396
  const getParagraphPropertySourceToken = (paragraph) => paragraphPropertySourceTokens.get(paragraph);
328
397
  /** Byte captures can follow derivations; only explicit copies carry durable tokens. */
329
398
  const inspectParagraphSourceIdentity = (paragraph, document) => {
@@ -360,8 +429,8 @@ const cloneParagraphWithoutPropertySource = (paragraph, overrides) => {
360
429
  ...paragraph,
361
430
  ...overrides
362
431
  };
363
- Reflect.deleteProperty(cloned, paragraphPropertyCapture);
364
- Reflect.deleteProperty(cloned, paragraphIndentationProjection);
432
+ keepHandle(cloned, paragraphPropertyCapture, void 0);
433
+ keepHandle(cloned, paragraphIndentationProjection, void 0);
365
434
  return cloned;
366
435
  };
367
436
  const paragraphsIn = (document) => {
@@ -700,7 +769,7 @@ function visitDecodedTableCellLeafBlock(block, blockType, path) {
700
769
  }
701
770
  const decodedTableCellParagraphSourcePayloadBrand = Symbol("decodedTableCellParagraphSourcePayload");
702
771
  const decodedTableCellParagraphSourcePayloadStates = /* @__PURE__ */ new WeakMap();
703
- const decodedTableCellParagraphSourcePayloads = /* @__PURE__ */ new WeakMap();
772
+ const decodedTableCellParagraphSourcePayloads = new KeptFacts();
704
773
  const decodedTableCellParagraphSourcePayloadState = (payload) => {
705
774
  const state = decodedTableCellParagraphSourcePayloadStates.get(payload);
706
775
  if (!state) panic("A collapsed-cell paragraph source payload bypassed its decoder.");
@@ -952,4 +1021,4 @@ const linkParagraphPropertySourceCandidate = (target, source) => {
952
1021
  };
953
1022
  const getParagraphPropertySourceCandidate = (paragraph) => paragraphPropertySourceCandidates.get(paragraph);
954
1023
  const getParagraphPropertySourceTransferId = (paragraph) => paragraphPropertySourceTransferIds.get(paragraph);
955
- export { PARAGRAPH_PROPERTY_SOURCE_VALIDATION_CODES, PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, ParagraphPropertySourceValidationError, TABLE_CELL_PARAGRAPH_SOURCE_BINDING_ATTR, TABLE_CELL_PARAGRAPH_SOURCE_PAYLOAD_ERROR_CLASSIFICATIONS, assignDocumentParagraphPropertySourceContract, assignParagraphIndentationProjection, assignParagraphPropertySource, cloneDocumentWithParagraphPropertySources, cloneParagraphWithPropertySource, cloneParagraphWithoutPropertySource, cloneTableCellsWithParagraphPropertyCaptures, copyDocumentParagraphPropertySourceContract, copyDocumentParagraphPropertySources, copyParagraphIndentationProjection, copyParagraphPropertyCapture, copyParagraphPropertySource, createProseParagraphWithPropertySource, decodeTableCellParagraphSourcePayload, getDocumentParagraphPropertySourceContract, getExplicitParagraphPropertySourceTransfers, getParagraphPropertySource, getParagraphPropertySourceCandidate, getParagraphPropertySourceToken, getParagraphPropertySourceTransferId, getProseDocumentParagraphPropertySourceContract, getProseParagraphPropertySourceToken, inspectParagraphSourceIdentity, isParagraphPropertySourceToken, joinProseParagraphsWithRightPropertySource, linkParagraphPropertySourceCandidate, linkProseParagraphPropertySource, markParagraphPropertySourceTransfers, paragraphFormattingWithAuthoredIndentation, paragraphPropertySourceBelongsToDocument, paragraphPropertySourceMatchesAuthoredIndentation, paragraphPropertySourceMatchesEmission, paragraphPropertySourceState, paragraphPropertySourceTokenMatchesContract, proseParagraphAttrsWithoutPropertySource, recreateProseNodeWithDetachedParagraphPropertySource, recreateProseNodeWithParagraphPropertySource, restoreParagraphIndentationProjection, restoreTableCellsWithParagraphPropertySources, sameParagraphIndentationProjection, setProseParagraphMarkupWithPropertySource, transferProseParagraphPropertySource, transportTableCellsWithParagraphPropertySources, visitDocumentStoryParagraphs, visitTableCellParagraphPropertySourceBindings };
1024
+ export { PARAGRAPH_PROPERTY_SOURCE_VALIDATION_CODES, PARAGRAPH_SOURCE_JOIN_RULES, PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, PROSE_PARAGRAPH_SOURCE_TOKEN_ATTR, ParagraphPropertySourceValidationError, TABLE_CELL_PARAGRAPH_SOURCE_BINDING_ATTR, TABLE_CELL_PARAGRAPH_SOURCE_PAYLOAD_ERROR_CLASSIFICATIONS, assignDocumentParagraphPropertySourceContract, assignParagraphIndentationProjection, assignParagraphPropertySource, cloneDocumentWithParagraphPropertySources, cloneParagraphWithPropertySource, cloneParagraphWithoutPropertySource, cloneTableCellsWithParagraphPropertyCaptures, copyDocumentParagraphPropertySourceContract, copyDocumentParagraphPropertySources, copyParagraphIndentationProjection, copyParagraphPropertyCapture, copyParagraphPropertySource, createProseParagraphWithPropertySource, decodeTableCellParagraphSourcePayload, getDocumentParagraphPropertySourceContract, getExplicitParagraphPropertySourceTransfers, getParagraphPropertySource, getParagraphPropertySourceCandidate, getParagraphPropertySourceToken, getParagraphPropertySourceTransferId, getProseDocumentParagraphPropertySourceContract, getProseParagraphPropertySourceToken, inspectParagraphSourceIdentity, isParagraphPropertySourceToken, joinProseParagraphsWithRightPropertySource, linkParagraphPropertySourceCandidate, linkProseParagraphPropertySource, markParagraphPropertySourceTransfers, paragraphFormattingWithAuthoredIndentation, paragraphPropertySourceBelongsToDocument, paragraphPropertySourceMatchesAuthoredIndentation, paragraphPropertySourceMatchesEmission, paragraphPropertySourceStamp, paragraphPropertySourceStampMatches, paragraphPropertySourceState, paragraphPropertySourceTokenMatchesContract, proseParagraphAttrsWithoutPropertySource, recreateProseNodeWithDetachedParagraphPropertySource, recreateProseNodeWithParagraphPropertySource, restoreParagraphIndentationProjection, restoreTableCellsWithParagraphPropertySources, sameParagraphIndentationProjection, setProseParagraphMarkupWithPropertySource, transferProseParagraphPropertySource, transportTableCellsWithParagraphPropertySources, visitDocumentStoryParagraphs, visitTableCellParagraphPropertySourceBindings };
@@ -363,6 +363,8 @@ async function parseDocxWithPreviewBudget(input, options, previewBudget) {
363
363
  styles: styleDefinitions?.styles ?? [],
364
364
  numbering
365
365
  });
366
+ const danglingNumIds = [.../* @__PURE__ */ new Set([...numberingReferenceNormalization.danglingNumIds, ...styleNumberingNormalization.danglingNumIds])].sort((left, right) => left - right);
367
+ if (danglingNumIds.length > 0) numbering.definitions.danglingNumIds = danglingNumIds;
366
368
  for (const styleId of styleNumberingNormalization.unnumberedStyleIds) parseContext.warn({
367
369
  code: UNNUMBERED_STYLE_WARNING,
368
370
  value: styleId,