@stll/folio-core 0.67.0 → 0.68.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 (251) hide show
  1. package/dist/ai-edits/apply.d.ts +9 -1
  2. package/dist/ai-edits/apply.js +94 -8
  3. package/dist/ai-edits/headless.d.ts +36 -21
  4. package/dist/ai-edits/headless.js +104 -34
  5. package/dist/ai-edits/index.d.ts +2 -2
  6. package/dist/ai-edits/note-references.d.ts +6 -0
  7. package/dist/ai-edits/note-references.js +7 -1
  8. package/dist/ai-edits/read.d.ts +19 -0
  9. package/dist/ai-edits/snapshot.d.ts +6 -0
  10. package/dist/ai-edits/snapshot.js +8 -3
  11. package/dist/ai-edits/types.d.ts +9 -1
  12. package/dist/ai-suggestions/apply.js +13 -4
  13. package/dist/compare/compare.js +2 -1
  14. package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
  15. package/dist/compare/inserted-resource-snapshot.js +7 -3
  16. package/dist/controller/canonicalClipboard.js +29 -12
  17. package/dist/controller/canonicalComposition.js +1 -1
  18. package/dist/controller/canonicalInlineProjection.d.ts +35 -10
  19. package/dist/controller/canonicalInlineProjection.js +192 -28
  20. package/dist/controller/canonicalInput.d.ts +2 -1
  21. package/dist/controller/canonicalInput.js +28 -1
  22. package/dist/controller/canonicalListRendering.d.ts +2 -1
  23. package/dist/controller/canonicalListRendering.js +1 -1
  24. package/dist/controller/canonicalLockGuard.d.ts +8 -0
  25. package/dist/controller/canonicalLockGuard.js +88 -0
  26. package/dist/controller/canonicalPublicOperations.d.ts +12 -4
  27. package/dist/controller/canonicalPublicOperations.js +274 -20
  28. package/dist/controller/canonicalSession.d.ts +87 -7
  29. package/dist/controller/canonicalSession.js +327 -73
  30. package/dist/controller/canonicalStoryEditor.d.ts +3 -2
  31. package/dist/controller/canonicalStoryEditor.js +4 -3
  32. package/dist/controller/canonicalStructure.d.ts +2 -1
  33. package/dist/controller/canonicalStructure.js +129 -7
  34. package/dist/controller/contentControlWidgetController.d.ts +5 -0
  35. package/dist/controller/contentControlWidgetController.js +13 -1
  36. package/dist/controller/folioEditor.js +1 -0
  37. package/dist/controller/headerFooterEditorManager.d.ts +2 -2
  38. package/dist/controller/headerFooterEditorManager.js +5 -5
  39. package/dist/controller/hiddenEditorApi.d.ts +6 -0
  40. package/dist/controller/hiddenEditorApi.js +1 -0
  41. package/dist/controller/hiddenEditorManager.d.ts +4 -3
  42. package/dist/controller/hiddenEditorManager.js +91 -37
  43. package/dist/controller/layoutPipeline.js +48 -15
  44. package/dist/controller/noteEditorManager.d.ts +2 -2
  45. package/dist/controller/noteEditorManager.js +5 -5
  46. package/dist/display-list/build/pageFurniture.js +41 -19
  47. package/dist/display-list/build/tablePrimitives.js +23 -4
  48. package/dist/display-list/dom/renderDisplayListToDom.js +4 -4
  49. package/dist/document-operations.d.ts +8 -0
  50. package/dist/document-operations.js +4 -3
  51. package/dist/docx/blockContentParser.d.ts +7 -3
  52. package/dist/docx/blockContentParser.js +2 -3
  53. package/dist/docx/blockPlainText.js +2 -0
  54. package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
  55. package/dist/docx/bookmarkRangeJoin.js +43 -0
  56. package/dist/docx/canonicalSave.js +5 -1
  57. package/dist/docx/canonicalSessionInput.d.ts +5 -1
  58. package/dist/docx/canonicalSessionInput.js +7 -2
  59. package/dist/docx/commentAnchorIndex.d.ts +21 -5
  60. package/dist/docx/commentAnchorIndex.js +39 -11
  61. package/dist/docx/commentRangeIntegrity.js +30 -24
  62. package/dist/docx/commentRangeJoin.d.ts +4 -0
  63. package/dist/docx/commentRangeJoin.js +26 -12
  64. package/dist/docx/commentReferenceCompletion.js +5 -4
  65. package/dist/docx/commentReferenceNormalization.js +40 -18
  66. package/dist/docx/compatibility.js +9 -2
  67. package/dist/docx/containerChildren.js +22 -1
  68. package/dist/docx/encryption/compoundFile.js +9 -1
  69. package/dist/docx/encryption/encryptionInfo.js +16 -2
  70. package/dist/docx/ensureParaIds.js +46 -7
  71. package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
  72. package/dist/docx/ensureUniqueControlIds.js +110 -0
  73. package/dist/docx/headerFooterVerbatim.d.ts +7 -0
  74. package/dist/docx/headerFooterVerbatim.js +13 -2
  75. package/dist/docx/hostCommentThreads.d.ts +17 -0
  76. package/dist/docx/hostCommentThreads.js +49 -0
  77. package/dist/docx/hyperlinkParser.js +9 -2
  78. package/dist/docx/inlineWrapperContent.d.ts +8 -1
  79. package/dist/docx/inlineWrapperContent.js +9 -2
  80. package/dist/docx/listMarkerComputation.d.ts +35 -1
  81. package/dist/docx/listMarkerComputation.js +39 -1
  82. package/dist/docx/listModelNormalization.d.ts +44 -1
  83. package/dist/docx/listModelNormalization.js +227 -96
  84. package/dist/docx/markupRangeMarker.d.ts +14 -0
  85. package/dist/docx/markupRangeMarker.js +15 -1
  86. package/dist/docx/metadataPrivacy.js +43 -22
  87. package/dist/docx/normalizeBaseDirection.js +3 -1
  88. package/dist/docx/paragraphParser.js +159 -48
  89. package/dist/docx/paragraphPropertySource.d.ts +7 -0
  90. package/dist/docx/paragraphPropertySource.js +22 -1
  91. package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
  92. package/dist/docx/paragraphTraversal.js +2 -0
  93. package/dist/docx/parseWarningMessage.js +2 -1
  94. package/dist/docx/parser.js +6 -0
  95. package/dist/docx/renderedPageBreakNormalization.js +1 -1
  96. package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
  97. package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
  98. package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
  99. package/dist/docx/reviewResolutionProvenance.js +110 -25
  100. package/dist/docx/rezip.d.ts +6 -0
  101. package/dist/docx/rezip.js +38 -21
  102. package/dist/docx/selectiveSave.js +6 -10
  103. package/dist/docx/selectiveXmlPatch.d.ts +5 -4
  104. package/dist/docx/selectiveXmlPatch.js +11 -7
  105. package/dist/docx/serializer/documentSerializer.js +3 -1
  106. package/dist/docx/serializer/headerFooterSerializer.js +3 -1
  107. package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
  108. package/dist/docx/serializer/markupRangeAttributes.js +6 -1
  109. package/dist/docx/serializer/noteSerializer.d.ts +17 -4
  110. package/dist/docx/serializer/noteSerializer.js +23 -16
  111. package/dist/docx/serializer/paragraphSerializer.js +56 -12
  112. package/dist/docx/serializer/runSerializer.d.ts +1 -3
  113. package/dist/docx/serializer/runSerializer.js +2 -2
  114. package/dist/docx/serializer/tableSerializer.d.ts +4 -0
  115. package/dist/docx/serializer/tableSerializer.js +4 -2
  116. package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
  117. package/dist/docx/server/createBilingualDocument.js +27 -5
  118. package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
  119. package/dist/docx/sessionListPruning.d.ts +2 -0
  120. package/dist/docx/sessionListPruning.js +50 -0
  121. package/dist/docx/splitRevisionPieces.d.ts +10 -0
  122. package/dist/docx/splitRevisionPieces.js +14 -0
  123. package/dist/docx/storyBlockReplay.js +4 -0
  124. package/dist/docx/structuralXmlPatch.js +19 -7
  125. package/dist/docx/tableParser.d.ts +6 -2
  126. package/dist/docx/tableParser.js +2 -3
  127. package/dist/docx/textBoxContentParser.d.ts +11 -0
  128. package/dist/docx/textBoxContentParser.js +51 -0
  129. package/dist/docx/textBoxParser.d.ts +0 -5
  130. package/dist/docx/textBoxParser.js +1 -23
  131. package/dist/docx/verticalMergeProjection.js +1 -1
  132. package/dist/fonts/fontsourceFaces.d.ts +2 -8
  133. package/dist/fonts/fontsourceFaces.js +1 -7
  134. package/dist/i18n/messages/ar.gen.js +2 -0
  135. package/dist/i18n/messages/catalogs.gen.d.ts +34 -0
  136. package/dist/i18n/messages/catalogs.gen.js +34 -0
  137. package/dist/i18n/messages/cs.gen.js +2 -0
  138. package/dist/i18n/messages/de.gen.js +2 -0
  139. package/dist/i18n/messages/en.gen.js +2 -0
  140. package/dist/i18n/messages/es.gen.js +2 -0
  141. package/dist/i18n/messages/et.gen.js +2 -0
  142. package/dist/i18n/messages/fr.gen.js +2 -0
  143. package/dist/i18n/messages/he.gen.js +2 -0
  144. package/dist/i18n/messages/hi.gen.js +2 -0
  145. package/dist/i18n/messages/hu.gen.js +2 -0
  146. package/dist/i18n/messages/lt.gen.js +2 -0
  147. package/dist/i18n/messages/lv.gen.js +2 -0
  148. package/dist/i18n/messages/messages.gen.d.ts +2 -0
  149. package/dist/i18n/messages/pl.gen.js +2 -0
  150. package/dist/i18n/messages/pt-BR.gen.js +2 -0
  151. package/dist/i18n/messages/sk.gen.js +2 -0
  152. package/dist/i18n/messages/tr.gen.js +2 -0
  153. package/dist/i18n/messages/zh-CN.gen.js +2 -0
  154. package/dist/internal/acceptedBlockProjection.js +2 -0
  155. package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
  156. package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
  157. package/dist/internal/revisionResolutionInline.js +1 -2
  158. package/dist/layout-bridge/convert/tableConversion.js +19 -8
  159. package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
  160. package/dist/layout-bridge/engine/blockIndex.js +12 -0
  161. package/dist/layout-bridge/engine/hitTest.js +9 -10
  162. package/dist/layout-bridge/engine/selectionRects.js +6 -6
  163. package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
  164. package/dist/layout-engine/footnoteContinuation.js +210 -0
  165. package/dist/layout-engine/index.d.ts +2 -2
  166. package/dist/layout-engine/index.js +7 -2
  167. package/dist/layout-engine/measure/cache.js +10 -5
  168. package/dist/layout-engine/measure/measureParagraph.js +1 -1
  169. package/dist/layout-engine/tableLayout.js +29 -5
  170. package/dist/layout-engine/tableRowBreak.d.ts +36 -0
  171. package/dist/layout-engine/tableRowBreak.js +43 -1
  172. package/dist/layout-engine/types.d.ts +36 -1
  173. package/dist/layout-painter/renderPage.d.ts +4 -4
  174. package/dist/layout-painter/renderPage.js +46 -17
  175. package/dist/layout-painter/renderTable.js +7 -4
  176. package/dist/managers/AutoSaveManager.d.ts +5 -1
  177. package/dist/managers/FindReplaceManager.js +3 -10
  178. package/dist/markdown/escape.d.ts +20 -1
  179. package/dist/markdown/escape.js +43 -1
  180. package/dist/markdown/renderBlock.js +4 -1
  181. package/dist/markdown/renderParagraph.js +13 -27
  182. package/dist/markdown/renderTable.js +6 -2
  183. package/dist/markdown/trailers.js +1 -0
  184. package/dist/pdf/images.d.ts +17 -1
  185. package/dist/pdf/images.js +22 -4
  186. package/dist/pdf/writePdf.js +4 -2
  187. package/dist/prosemirror/attrs/index.js +1 -0
  188. package/dist/prosemirror/canonicalCommands.d.ts +39 -1
  189. package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
  190. package/dist/prosemirror/canonicalTableCommands.js +362 -0
  191. package/dist/prosemirror/commands/comments.d.ts +25 -0
  192. package/dist/prosemirror/commands/comments.js +102 -11
  193. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  194. package/dist/prosemirror/commands/index.d.ts +1 -1
  195. package/dist/prosemirror/commentIdAllocator.js +2 -2
  196. package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
  197. package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
  198. package/dist/prosemirror/commentReferenceIntegrity.js +3 -4
  199. package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
  200. package/dist/prosemirror/conversion/fromProseDoc.js +76 -31
  201. package/dist/prosemirror/conversion/index.d.ts +1 -1
  202. package/dist/prosemirror/conversion/toProseDoc.d.ts +128 -1
  203. package/dist/prosemirror/conversion/toProseDoc.js +319 -51
  204. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  205. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  206. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
  207. package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
  208. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
  209. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +1 -1
  210. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
  211. package/dist/prosemirror/extensions/marks/CommentExtension.js +6 -3
  212. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
  213. package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
  214. package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
  215. package/dist/prosemirror/extensions/nodes/TableExtension.js +32 -31
  216. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
  217. package/dist/prosemirror/index.d.ts +2 -2
  218. package/dist/prosemirror/listLabels.js +3 -2
  219. package/dist/prosemirror/listNumbering.d.ts +6 -0
  220. package/dist/prosemirror/listNumbering.js +12 -9
  221. package/dist/prosemirror/lockedControls.d.ts +13 -0
  222. package/dist/prosemirror/lockedControls.js +106 -0
  223. package/dist/prosemirror/markupViewProjection.js +1 -1
  224. package/dist/prosemirror/noteReferenceReview.js +2 -2
  225. package/dist/prosemirror/plugins/documentNumbering.js +4 -1
  226. package/dist/prosemirror/plugins/suggestionMode.js +20 -9
  227. package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
  228. package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
  229. package/dist/prosemirror/replacedAnnotations.js +1 -0
  230. package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
  231. package/dist/prosemirror/runFormattingFromMarks.js +2 -4
  232. package/dist/prosemirror/runFormattingReconciliation.js +2 -2
  233. package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
  234. package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
  235. package/dist/prosemirror/runStyleFormatting.js +16 -13
  236. package/dist/prosemirror/schema/marks.d.ts +6 -0
  237. package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
  238. package/dist/prosemirror/validation.js +1 -0
  239. package/dist/redline.js +23 -9
  240. package/dist/server.d.ts +2 -2
  241. package/dist/style-sets/extract.js +2 -2
  242. package/dist/types/canonicalCapabilities.d.ts +29 -8
  243. package/dist/types/canonicalCapabilities.js +13 -9
  244. package/dist/utils/cssString.d.ts +7 -0
  245. package/dist/utils/cssString.js +9 -0
  246. package/dist/utils/fontResolver.js +4 -1
  247. package/dist/utils/replaceText.d.ts +11 -0
  248. package/dist/utils/replaceText.js +39 -7
  249. package/dist/version-comparison.d.ts +9 -1
  250. package/dist/version-comparison.js +11 -5
  251. package/package.json +2 -2
@@ -110,7 +110,7 @@ const HYPERLINK_CONTENT = {
110
110
  inlineWrapper: true,
111
111
  preservedInline: true,
112
112
  run: true,
113
- complexField: false,
113
+ complexField: true,
114
114
  deletion: false,
115
115
  hyperlink: false,
116
116
  inlineSdt: false,
@@ -156,6 +156,13 @@ const SIMPLE_FIELD_CONTENT = {
156
156
  simpleField: false
157
157
  };
158
158
  /**
159
+ * Every paragraph content kind is a tracked change child. The reader keeps a
160
+ * tracked change whole on this: its resolution joins describe the one wrapper.
161
+ * A model kind outside `TrackedRunContent` turns this type to `never`, so the
162
+ * build fails until reading such a change is designed.
163
+ */
164
+ const EVERY_PARAGRAPH_CONTENT_IS_TRACKED_CHILD = true;
165
+ /**
159
166
  * Whether a revision wrapper keeps this content inside itself.
160
167
  *
161
168
  * Generic in the input so a caller that has already narrowed its content
@@ -169,4 +176,4 @@ const isInlineSdtContent = (content) => INLINE_SDT_CONTENT[content.type];
169
176
  const isHyperlinkContent = (content) => HYPERLINK_CONTENT[content.type];
170
177
  /** Whether a `w:fldSimple` keeps this content inside itself. */
171
178
  const isSimpleFieldContent = (content) => SIMPLE_FIELD_CONTENT[content.type];
172
- export { HYPERLINK_CONTENT, INLINE_SDT_CONTENT, SIMPLE_FIELD_CONTENT, TRACKED_CHANGE_WRAPPER_CONTENT, isHyperlinkContent, isInlineSdtContent, isSimpleFieldContent, isTrackedChangeWrapperChild };
179
+ export { EVERY_PARAGRAPH_CONTENT_IS_TRACKED_CHILD, HYPERLINK_CONTENT, INLINE_SDT_CONTENT, SIMPLE_FIELD_CONTENT, TRACKED_CHANGE_WRAPPER_CONTENT, isHyperlinkContent, isInlineSdtContent, isSimpleFieldContent, isTrackedChangeWrapperChild };
@@ -12,4 +12,38 @@ export type ComputeListMarkerOptions = {
12
12
  restartedNumIds: Set<number>;
13
13
  previousList: PreviousListState;
14
14
  };
15
- export declare const computeListMarker: (paragraph: document_d_exports.Paragraph, { numbering, listCounters, abstractCounters, restartedNumIds, previousList }: ComputeListMarkerOptions) => void;
15
+ /**
16
+ * What each field of the marker counters depends on: the package alone, or
17
+ * the paragraphs of the story before the current one. Total over the fields:
18
+ * one added does not compile until it is placed, and the story half is what
19
+ * a snapshot copies.
20
+ */
21
+ declare const LIST_COUNTER_DEPENDENCY: {
22
+ readonly numbering: "package";
23
+ readonly listCounters: "story";
24
+ readonly abstractCounters: "story";
25
+ readonly restartedNumIds: "story";
26
+ readonly previousList: "story";
27
+ };
28
+ type CounterDependency = typeof LIST_COUNTER_DEPENDENCY;
29
+ type StoryCounterField = { [K in keyof CounterDependency]: CounterDependency[K] extends "story" ? K : never; }[keyof CounterDependency];
30
+ /**
31
+ * The story half of the marker counters at one paragraph, copied. Counter
32
+ * arrays are shared between a list instance and its abstract list, and a
33
+ * later paragraph advances the shared array, so the copy names each array by
34
+ * its index in `arrays` and keeps which entries share one.
35
+ */
36
+ export type ListCounterSnapshot = {
37
+ readonly arrays: readonly (readonly number[])[];
38
+ readonly listCounters: readonly (readonly [number, number])[];
39
+ readonly abstractCounters: readonly (readonly [number, number])[];
40
+ readonly restartedNumIds: readonly number[];
41
+ readonly previousList: Readonly<PreviousListState>;
42
+ } & Record<StoryCounterField, unknown>;
43
+ export declare const snapshotListCounters: (counters: ComputeListMarkerOptions) => ListCounterSnapshot;
44
+ /** Put the story half of `counters` back as the snapshot copied it. */
45
+ export declare const restoreListCounters: (counters: ComputeListMarkerOptions, snapshot: ListCounterSnapshot) => void;
46
+ /** Whether two snapshots hold the same counters, shared the same way, in the same order. */
47
+ export declare const sameListCounters: (left: ListCounterSnapshot, right: ListCounterSnapshot) => boolean;
48
+ export declare const computeListMarker: (paragraph: document_d_exports.Paragraph, { numbering, listCounters, abstractCounters, restartedNumIds, previousList }: ComputeListMarkerOptions) => void;
49
+ export {};
@@ -1,7 +1,45 @@
1
1
  import { bulletMarkerFontName, convertBulletToUnicode } from "./bulletMarkers.js";
2
2
  import { resolveListTemplate } from "./listTemplate.js";
3
3
  import { isNumberingReference } from "./numberingReference.js";
4
+ import { panic } from "better-result";
4
5
  // src/docx/listMarkerComputation.ts
6
+ /** Marker counters shared by parsing and canonical model normalization. */
7
+ const snapshotListCounters = (counters) => {
8
+ const indices = /* @__PURE__ */ new Map();
9
+ const arrays = [];
10
+ const indexOf = (values) => {
11
+ const known = indices.get(values);
12
+ if (known !== void 0) return known;
13
+ indices.set(values, arrays.length);
14
+ arrays.push([...values]);
15
+ return arrays.length - 1;
16
+ };
17
+ return {
18
+ listCounters: [...counters.listCounters].map(([numId, values]) => [numId, indexOf(values)]),
19
+ abstractCounters: [...counters.abstractCounters].map(([abstractNumId, values]) => [abstractNumId, indexOf(values)]),
20
+ arrays,
21
+ restartedNumIds: [...counters.restartedNumIds],
22
+ previousList: { ...counters.previousList }
23
+ };
24
+ };
25
+ /** Put the story half of `counters` back as the snapshot copied it. */
26
+ const restoreListCounters = (counters, snapshot) => {
27
+ const arrays = snapshot.arrays.map((values) => [...values]);
28
+ const arrayAt = (index) => arrays[index] ?? panic("A list counter snapshot lost an array.");
29
+ const story = {
30
+ listCounters: new Map(snapshot.listCounters.map(([numId, index]) => [numId, arrayAt(index)])),
31
+ abstractCounters: new Map(snapshot.abstractCounters.map(([abstractNumId, index]) => [abstractNumId, arrayAt(index)])),
32
+ restartedNumIds: new Set(snapshot.restartedNumIds),
33
+ previousList: { ...snapshot.previousList }
34
+ };
35
+ Object.assign(counters, story);
36
+ };
37
+ const samePairs = (left, right) => left.length === right.length && left.every(([key, index], at) => right[at]?.[0] === key && right[at]?.[1] === index);
38
+ /** Whether two snapshots hold the same counters, shared the same way, in the same order. */
39
+ const sameListCounters = (left, right) => left.previousList.abstractNumId === right.previousList.abstractNumId && left.previousList.fromStyle === right.previousList.fromStyle && left.previousList.numId === right.previousList.numId && left.restartedNumIds.length === right.restartedNumIds.length && left.restartedNumIds.every((numId, at) => right.restartedNumIds[at] === numId) && samePairs(left.listCounters, right.listCounters) && samePairs(left.abstractCounters, right.abstractCounters) && left.arrays.length === right.arrays.length && left.arrays.every((values, at) => {
40
+ const other = right.arrays[at];
41
+ return other !== void 0 && values.length === other.length && values.every((value, index) => Object.is(value, other[index]));
42
+ });
5
43
  const computeListMarker = (paragraph, { numbering, listCounters, abstractCounters, restartedNumIds, previousList }) => {
6
44
  const listRendering = paragraph.listRendering;
7
45
  if (!listRendering || !numbering) {
@@ -68,4 +106,4 @@ const computeListMarker = (paragraph, { numbering, listCounters, abstractCounter
68
106
  forceDecimal: currentLevelInfo?.isLgl === true || listRendering.isLegal === true
69
107
  });
70
108
  };
71
- export { computeListMarker };
109
+ export { computeListMarker, restoreListCounters, sameListCounters, snapshotListCounters };
@@ -1,8 +1,51 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
+ import { ComputeListMarkerOptions } from "./listMarkerComputation.js";
2
3
  import { DocumentOp } from "@stll/docx-core/ops";
3
4
  type CanonicalListNormalization = {
4
5
  document: document_d_exports.Document;
5
6
  inverse: DocumentOp[];
6
7
  };
7
- export declare const normalizeListModelRendering: (document: document_d_exports.Document) => CanonicalListNormalization;
8
+ /** The package fields a block's normalization reads; the rest of it is never read. */
9
+ type ListNormalizationPackageInputs = Pick<document_d_exports.Document["package"], "styles" | "numbering">;
10
+ /**
11
+ * Normalized blocks kept across the normalizations of one session.
12
+ *
13
+ * Normalizing a block reads the block, the package's styles and numbering,
14
+ * and the list counters the blocks before it advanced. A block an edit left
15
+ * the same object, with the same kept facts and snapshot registration, that
16
+ * normalized to itself before, normalizes to itself again from the same
17
+ * counters. So a story is normalized again from the last checkpoint before
18
+ * its first changed block, and only until the counters after its last
19
+ * changed block match those the earlier run had at that place.
20
+ */
21
+ export declare class ListNormalizationCache {
22
+ private inputs;
23
+ private runs;
24
+ private readonly spacing;
25
+ constructor({ checkpointSpacing }?: {
26
+ checkpointSpacing?: number;
27
+ });
28
+ /** Start over when the package inputs are not the ones the kept runs read. */
29
+ use(inputs: ListNormalizationPackageInputs): void;
30
+ /** The blocks of one story normalized, from `counters` as a fresh story starts them. */
31
+ story(key: string, blocks: readonly document_d_exports.BlockContent[], counters: ComputeListMarkerOptions, normalize: (block: document_d_exports.BlockContent) => {
32
+ output: document_d_exports.BlockContent;
33
+ settled: boolean;
34
+ }): document_d_exports.BlockContent[];
35
+ }
36
+ type ListNormalizationOptions = {
37
+ /**
38
+ * Whether to build the operations that undo the normalization. Only an edit
39
+ * session needs them, and they name paragraphs by identity; a save that only
40
+ * writes the normalized document must work on a package whose paragraphs
41
+ * carry none.
42
+ */
43
+ inverse?: "record" | "omit";
44
+ /**
45
+ * Blocks an earlier normalization of the same session left as they were,
46
+ * reused where the counters before them are the same.
47
+ */
48
+ cache?: ListNormalizationCache;
49
+ };
50
+ export declare const normalizeListModelRendering: (document: document_d_exports.Document, { inverse: inverseMode, cache }?: ListNormalizationOptions) => CanonicalListNormalization;
8
51
  export {};
@@ -4,19 +4,228 @@ import { listIndentationProvenancePatch } from "../prosemirror/styles/resolvedSt
4
4
  import { createStyleResolver } from "../prosemirror/styles/styleResolver.js";
5
5
  import { canonicalJson } from "../utils/canonicalJson.js";
6
6
  import { foldListNumberFields, planParagraphListNumberFold, unfoldedListNumberContent } from "./foldedListNumberFields.js";
7
- import { computeListMarker } from "./listMarkerComputation.js";
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, sameParagraphIndentationProjection } from "./paragraphPropertySource.js";
10
+ import { assignParagraphIndentationProjection, cloneParagraphWithPropertySource, paragraphFormattingWithAuthoredIndentation, paragraphPropertySourceState, sameParagraphIndentationProjection } from "./paragraphPropertySource.js";
11
11
  import { panic } from "better-result";
12
12
  import { finalizeParagraphFormatting } from "@stll/docx-core/model";
13
- import { DOCUMENT_OP_TYPES, EMPTY_PROPERTY_SETS, OP_STORIES, registerParagraphPropertySnapshot, withBodyContent } from "@stll/docx-core/ops";
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
- const normalizeListModelRendering = (document) => {
16
+ const CHECKPOINT_SPACING = 32;
17
+ const sameState = (left, right) => left.length === right.length && left.every((value, index) => value === right[index]);
18
+ const recordOf = (input, settled) => input.type === "paragraph" ? {
19
+ input,
20
+ settled,
21
+ sourceState: paragraphPropertySourceState(input),
22
+ snapshotToken: paragraphPropertySnapshotToken(input)
23
+ } : {
24
+ input,
25
+ settled,
26
+ sourceState: void 0,
27
+ snapshotToken: void 0
28
+ };
29
+ /** 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);
31
+ const storyKey = (story) => {
32
+ if (story === OP_STORIES.MAIN) return story;
33
+ return "rId" in story ? `${story.kind}:${story.rId}` : `${story.kind}:${String(story.id)}`;
34
+ };
35
+ /**
36
+ * Normalized blocks kept across the normalizations of one session.
37
+ *
38
+ * Normalizing a block reads the block, the package's styles and numbering,
39
+ * and the list counters the blocks before it advanced. A block an edit left
40
+ * the same object, with the same kept facts and snapshot registration, that
41
+ * normalized to itself before, normalizes to itself again from the same
42
+ * counters. So a story is normalized again from the last checkpoint before
43
+ * its first changed block, and only until the counters after its last
44
+ * changed block match those the earlier run had at that place.
45
+ */
46
+ var ListNormalizationCache = class {
47
+ inputs;
48
+ runs = /* @__PURE__ */ new Map();
49
+ spacing;
50
+ constructor({ checkpointSpacing = CHECKPOINT_SPACING } = {}) {
51
+ this.spacing = checkpointSpacing;
52
+ }
53
+ /** Start over when the package inputs are not the ones the kept runs read. */
54
+ use(inputs) {
55
+ if (this.inputs !== void 0 && this.inputs.styles === inputs.styles && this.inputs.numbering === inputs.numbering) return;
56
+ this.inputs = inputs;
57
+ this.runs = /* @__PURE__ */ new Map();
58
+ }
59
+ /** The blocks of one story normalized, from `counters` as a fresh story starts them. */
60
+ story(key, blocks, counters, normalize) {
61
+ const old = this.runs.get(key);
62
+ const oldRecords = old?.records ?? [];
63
+ const oldCheckpoints = old?.checkpoints ?? /* @__PURE__ */ new Map();
64
+ const length = blocks.length;
65
+ const shift = length - oldRecords.length;
66
+ const settledAt = (index, oldIndex) => {
67
+ const record = oldRecords[oldIndex];
68
+ const block = blocks[index];
69
+ return record !== void 0 && block !== void 0 && stillSettled(block, record);
70
+ };
71
+ let prefix = 0;
72
+ while (prefix < length && settledAt(prefix, prefix)) prefix += 1;
73
+ let suffix = 0;
74
+ while (suffix < length - prefix && suffix < oldRecords.length - prefix && settledAt(length - 1 - suffix, oldRecords.length - 1 - suffix)) suffix += 1;
75
+ const outputs = [];
76
+ const records = [];
77
+ const checkpoints = /* @__PURE__ */ new Map();
78
+ const keep = (from, to, offset) => {
79
+ for (let index = from; index < to; index += 1) {
80
+ const record = oldRecords[index - offset] ?? panic("A kept list normalization lost a block.");
81
+ outputs.push(record.input);
82
+ records.push(record);
83
+ }
84
+ };
85
+ let start = 0;
86
+ for (const index of oldCheckpoints.keys()) if (index <= prefix && index > start) start = index;
87
+ const resumed = oldCheckpoints.get(start);
88
+ if (start > 0 && resumed !== void 0) {
89
+ restoreListCounters(counters, resumed);
90
+ keep(0, start, 0);
91
+ for (const [index, snapshot] of oldCheckpoints) if (index <= start) checkpoints.set(index, snapshot);
92
+ } else start = 0;
93
+ for (let index = start; index < length; index += 1) {
94
+ const oldIndex = index - shift;
95
+ const earlier = index >= length - suffix ? oldCheckpoints.get(oldIndex) : void 0;
96
+ const here = earlier !== void 0 || index % this.spacing === 0 ? snapshotListCounters(counters) : void 0;
97
+ if (earlier !== void 0 && here !== void 0 && sameListCounters(earlier, here)) {
98
+ keep(index, length, shift);
99
+ for (const [at, snapshot] of oldCheckpoints) if (at >= oldIndex) checkpoints.set(at + shift, snapshot);
100
+ this.runs.set(key, {
101
+ records,
102
+ checkpoints
103
+ });
104
+ return outputs;
105
+ }
106
+ if (here !== void 0 && index % this.spacing === 0) checkpoints.set(index, here);
107
+ const block = blocks[index] ?? panic("A story lost a block.");
108
+ const { output, settled } = normalize(block);
109
+ outputs.push(output);
110
+ records.push(recordOf(block, settled));
111
+ }
112
+ this.runs.set(key, {
113
+ records,
114
+ checkpoints
115
+ });
116
+ return outputs;
117
+ }
118
+ };
119
+ /**
120
+ * One block of a story with its list rendering normalized, the counters
121
+ * advanced past it. The block is returned itself when nothing changed.
122
+ */
123
+ const normalizeBlock = (paragraph, { styles, story, recordInverse }, counters) => {
124
+ const { numbering } = counters;
125
+ if (paragraph.type !== "paragraph") return paragraph;
126
+ registerParagraphPropertySnapshot({
127
+ paragraph,
128
+ snapshot: paragraphFormattingWithAuthoredIndentation(paragraph)
129
+ });
130
+ const formatting = paragraph.formatting;
131
+ const next = cloneParagraphWithPropertySource(paragraph, {});
132
+ const styleNumbering = formatting?.styleId ? styles.resolveParagraphStyle(formatting.styleId).paragraphFormatting?.numPr : void 0;
133
+ if (styleNumbering !== void 0 && (formatting?.numPr === void 0 || formatting.numPr.kind === "levelOnly")) next.formatting = {
134
+ ...formatting,
135
+ numPrFromStyle: styleNumbering
136
+ };
137
+ if (formatting?.numPrFromStyle !== void 0 && (formatting.styleId !== void 0 && styleNumbering === void 0 || formatting.numPr?.kind === "reference" || formatting.numPr?.kind === "none")) {
138
+ next.formatting = { ...formatting };
139
+ delete next.formatting.numPrFromStyle;
140
+ }
141
+ if (canonicalJson(next.formatting?.numPrFromStyle) !== canonicalJson(formatting?.numPrFromStyle)) recordInverse(() => ({
142
+ type: DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS,
143
+ story,
144
+ blockId: paragraph.paraId ?? panic("List normalization requires paragraph identities."),
145
+ patch: { numPrFromStyle: formatting?.numPrFromStyle ?? null },
146
+ whenEmpty: formatting === void 0 ? EMPTY_PROPERTY_SETS.OMIT : EMPTY_PROPERTY_SETS.KEEP
147
+ }));
148
+ const numPr = effectiveParagraphNumberingReference(paragraphNumberingSourcesFromBoundary({
149
+ numPr: next.formatting?.numPr,
150
+ numPrFromStyle: next.formatting?.numPrFromStyle
151
+ }));
152
+ if (paragraph.listRendering === void 0 && formatting?.numPrFromStyle === void 0 && next.formatting?.numPrFromStyle === void 0 && (numPr?.kind !== "reference" || numbering === null)) {
153
+ computeListMarker(paragraph, counters);
154
+ return paragraph;
155
+ }
156
+ const definition = numPr?.kind === "reference" && numbering !== null ? computeListRendering(numPr, numbering) : null;
157
+ const cached = paragraph.listRendering;
158
+ const rendering = definition !== null && cached !== void 0 && listRenderingDefinitionsMatch(cached, definition) ? { ...cached } : definition;
159
+ const authoredFormatting = paragraphFormattingWithAuthoredIndentation(next);
160
+ const authored = paragraphIndentationFromFormatting(authoredFormatting);
161
+ const inheritance = listIndentationProvenancePatch({
162
+ direct: authored,
163
+ styleFormatting: styles.resolveParagraphStyle(next.formatting?.styleId).paragraphFormatting,
164
+ numberingSource: next.formatting?.numPr?.kind === "reference" || next.formatting?.numPrFromStyle === void 0 ? "paragraph" : "style",
165
+ numPr: numPr?.kind === "reference" ? {
166
+ numId: numPr.numId,
167
+ ilvl: numPr.ilvl ?? 0
168
+ } : void 0,
169
+ numbering
170
+ });
171
+ assignParagraphIndentationProjection({
172
+ paragraph: next,
173
+ authored: authoredFormatting,
174
+ inherited: paragraphIndentationFromFormatting(inheritance._resolvedFormatting) ?? {}
175
+ });
176
+ if (canonicalJson(paragraphIndentationFromFormatting(next.formatting)) !== canonicalJson(paragraphIndentationFromFormatting(formatting))) recordInverse(() => ({
177
+ type: DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS,
178
+ story,
179
+ blockId: paragraph.paraId ?? panic("Canonical numbering normalization requires paragraph identities."),
180
+ patch: {
181
+ indentLeft: formatting?.indentLeft ?? null,
182
+ indentRight: formatting?.indentRight ?? null,
183
+ indentFirstLine: formatting?.indentFirstLine ?? null,
184
+ hangingIndent: formatting?.hangingIndent ?? null
185
+ },
186
+ whenEmpty: formatting === void 0 ? EMPTY_PROPERTY_SETS.OMIT : EMPTY_PROPERTY_SETS.KEEP
187
+ }));
188
+ if (rendering === null) delete next.listRendering;
189
+ else {
190
+ const fields = foldListNumberFields(paragraph.content.map(unfoldedListNumberContent), () => void 0).fieldCount;
191
+ if (fields === 0) delete rendering.implicitChildLevelAdvances;
192
+ else rendering.implicitChildLevelAdvances = fields;
193
+ const template = rendering.markerTemplate ?? rendering.marker;
194
+ const fold = planParagraphListNumberFold(paragraph.content, !rendering.isBullet && template !== "" && !template.includes(" "));
195
+ if (fold.suffix === void 0) delete rendering.foldedMarkerSuffix;
196
+ else rendering.foldedMarkerSuffix = fold.suffix;
197
+ const child = numbering?.getLevel(rendering.numId, rendering.level + 1)?.pPr;
198
+ if (fold.suffix !== void 0 && child?.hangingIndent === true && child.indentFirstLine !== void 0 && child.indentFirstLine < 0) rendering.markerSecondSlotOffsetTwips = -child.indentFirstLine;
199
+ else delete rendering.markerSecondSlotOffsetTwips;
200
+ rendering.marker = rendering.foldedMarkerSuffix !== void 0 && !template.includes(" ") ? `${template}\t${rendering.foldedMarkerSuffix}` : template;
201
+ next.listRendering = rendering;
202
+ }
203
+ computeListMarker(next, counters);
204
+ registerParagraphPropertySnapshot({
205
+ paragraph: next,
206
+ snapshot: authoredFormatting
207
+ });
208
+ if (finalizeParagraphFormatting(next.formatting) === void 0) delete next.formatting;
209
+ if (finalizeParagraphFormatting(formatting) === formatting && sameParagraphIndentationProjection({
210
+ left: next,
211
+ right: paragraph
212
+ }) && canonicalJson(next.formatting) === canonicalJson(formatting) && canonicalJson(next.listRendering) === canonicalJson(cached)) return paragraph;
213
+ return next;
214
+ };
215
+ const normalizeListModelRendering = (document, { inverse: inverseMode = "record", cache } = {}) => {
17
216
  const inverse = [];
18
- const styles = createStyleResolver(document.package.styles);
19
- const numbering = document.package.numbering === void 0 ? null : getCachedNumberingMap(document.package.numbering);
217
+ let recorded = 0;
218
+ const recordInverse = (operation) => {
219
+ recorded += 1;
220
+ if (inverseMode === "record") inverse.unshift(operation());
221
+ };
222
+ const packageInputs = {
223
+ styles: document.package.styles,
224
+ numbering: document.package.numbering
225
+ };
226
+ cache?.use(packageInputs);
227
+ const styles = createStyleResolver(packageInputs.styles);
228
+ const numbering = packageInputs.numbering === void 0 ? null : getCachedNumberingMap(packageInputs.numbering);
20
229
  const normalizeBody = (body, story) => {
21
230
  const counters = {
22
231
  numbering,
@@ -29,96 +238,18 @@ const normalizeListModelRendering = (document) => {
29
238
  numId: null
30
239
  }
31
240
  };
32
- const content = body.content.map((paragraph) => {
33
- if (paragraph.type !== "paragraph") return paragraph;
34
- registerParagraphPropertySnapshot({
35
- paragraph,
36
- snapshot: paragraphFormattingWithAuthoredIndentation(paragraph)
37
- });
38
- const formatting = paragraph.formatting;
39
- const next = cloneParagraphWithPropertySource(paragraph, {});
40
- const styleNumbering = formatting?.styleId ? styles.resolveParagraphStyle(formatting.styleId).paragraphFormatting?.numPr : void 0;
41
- if (styleNumbering !== void 0 && (formatting?.numPr === void 0 || formatting.numPr.kind === "levelOnly")) next.formatting = {
42
- ...formatting,
43
- numPrFromStyle: styleNumbering
241
+ const inputs = {
242
+ styles,
243
+ story,
244
+ recordInverse
245
+ };
246
+ const content = cache === void 0 ? body.content.map((block) => normalizeBlock(block, inputs, counters)) : cache.story(storyKey(story), body.content, counters, (block) => {
247
+ const before = recorded;
248
+ const output = normalizeBlock(block, inputs, counters);
249
+ return {
250
+ output,
251
+ settled: output === block && recorded === before
44
252
  };
45
- if (formatting?.numPrFromStyle !== void 0 && (formatting.styleId !== void 0 && styleNumbering === void 0 || formatting.numPr?.kind === "reference" || formatting.numPr?.kind === "none")) {
46
- next.formatting = { ...formatting };
47
- delete next.formatting.numPrFromStyle;
48
- }
49
- if (canonicalJson(next.formatting?.numPrFromStyle) !== canonicalJson(formatting?.numPrFromStyle)) inverse.unshift({
50
- type: DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS,
51
- story,
52
- blockId: paragraph.paraId ?? panic("List normalization requires paragraph identities."),
53
- patch: { numPrFromStyle: formatting?.numPrFromStyle ?? null },
54
- whenEmpty: formatting === void 0 ? EMPTY_PROPERTY_SETS.OMIT : EMPTY_PROPERTY_SETS.KEEP
55
- });
56
- const numPr = effectiveParagraphNumberingReference(paragraphNumberingSourcesFromBoundary({
57
- numPr: next.formatting?.numPr,
58
- numPrFromStyle: next.formatting?.numPrFromStyle
59
- }));
60
- if (paragraph.listRendering === void 0 && formatting?.numPrFromStyle === void 0 && next.formatting?.numPrFromStyle === void 0 && (numPr?.kind !== "reference" || numbering === null)) {
61
- computeListMarker(paragraph, counters);
62
- return paragraph;
63
- }
64
- const definition = numPr?.kind === "reference" && numbering !== null ? computeListRendering(numPr, numbering) : null;
65
- const cached = paragraph.listRendering;
66
- const rendering = definition !== null && cached !== void 0 && listRenderingDefinitionsMatch(cached, definition) ? { ...cached } : definition;
67
- const authoredFormatting = paragraphFormattingWithAuthoredIndentation(next);
68
- const authored = paragraphIndentationFromFormatting(authoredFormatting);
69
- const inheritance = listIndentationProvenancePatch({
70
- direct: authored,
71
- styleFormatting: styles.resolveParagraphStyle(next.formatting?.styleId).paragraphFormatting,
72
- numberingSource: next.formatting?.numPr?.kind === "reference" || next.formatting?.numPrFromStyle === void 0 ? "paragraph" : "style",
73
- numPr: numPr?.kind === "reference" ? {
74
- numId: numPr.numId,
75
- ilvl: numPr.ilvl ?? 0
76
- } : void 0,
77
- numbering
78
- });
79
- assignParagraphIndentationProjection({
80
- paragraph: next,
81
- authored: authoredFormatting,
82
- inherited: paragraphIndentationFromFormatting(inheritance._resolvedFormatting) ?? {}
83
- });
84
- if (canonicalJson(paragraphIndentationFromFormatting(next.formatting)) !== canonicalJson(paragraphIndentationFromFormatting(formatting))) inverse.unshift({
85
- type: DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS,
86
- story,
87
- blockId: paragraph.paraId ?? panic("Canonical numbering normalization requires paragraph identities."),
88
- patch: {
89
- indentLeft: formatting?.indentLeft ?? null,
90
- indentRight: formatting?.indentRight ?? null,
91
- indentFirstLine: formatting?.indentFirstLine ?? null,
92
- hangingIndent: formatting?.hangingIndent ?? null
93
- },
94
- whenEmpty: formatting === void 0 ? EMPTY_PROPERTY_SETS.OMIT : EMPTY_PROPERTY_SETS.KEEP
95
- });
96
- if (rendering === null) delete next.listRendering;
97
- else {
98
- const fields = foldListNumberFields(paragraph.content.map(unfoldedListNumberContent), () => void 0).fieldCount;
99
- if (fields === 0) delete rendering.implicitChildLevelAdvances;
100
- else rendering.implicitChildLevelAdvances = fields;
101
- const template = rendering.markerTemplate ?? rendering.marker;
102
- const fold = planParagraphListNumberFold(paragraph.content, !rendering.isBullet && template !== "" && !template.includes(" "));
103
- if (fold.suffix === void 0) delete rendering.foldedMarkerSuffix;
104
- else rendering.foldedMarkerSuffix = fold.suffix;
105
- const child = numbering?.getLevel(rendering.numId, rendering.level + 1)?.pPr;
106
- if (fold.suffix !== void 0 && child?.hangingIndent === true && child.indentFirstLine !== void 0 && child.indentFirstLine < 0) rendering.markerSecondSlotOffsetTwips = -child.indentFirstLine;
107
- else delete rendering.markerSecondSlotOffsetTwips;
108
- rendering.marker = rendering.foldedMarkerSuffix !== void 0 && !template.includes(" ") ? `${template}\t${rendering.foldedMarkerSuffix}` : template;
109
- next.listRendering = rendering;
110
- }
111
- computeListMarker(next, counters);
112
- registerParagraphPropertySnapshot({
113
- paragraph: next,
114
- snapshot: authoredFormatting
115
- });
116
- if (finalizeParagraphFormatting(next.formatting) === void 0) delete next.formatting;
117
- if (finalizeParagraphFormatting(formatting) === formatting && sameParagraphIndentationProjection({
118
- left: next,
119
- right: paragraph
120
- }) && canonicalJson(next.formatting) === canonicalJson(formatting) && canonicalJson(next.listRendering) === canonicalJson(cached)) return paragraph;
121
- return next;
122
253
  });
123
254
  return content.every((paragraph, index) => paragraph === body.content[index]) ? body : {
124
255
  ...body,
@@ -166,4 +297,4 @@ const normalizeListModelRendering = (document) => {
166
297
  }
167
298
  };
168
299
  };
169
- export { normalizeListModelRendering };
300
+ export { ListNormalizationCache, normalizeListModelRendering };
@@ -27,4 +27,18 @@ type BlockMoveRangeMarkerHandlers = {
27
27
  readonly moveToRangeEnd: BlockMoveRangeMarkerHandler;
28
28
  };
29
29
  export declare const BLOCK_MOVE_RANGE_MARKER_HANDLERS: BlockMoveRangeMarkerHandlers;
30
+ type BlockCommentRangeMarkerHandler = (child: XmlElement, walk: {
31
+ modelled: document_d_exports.BlockContent[];
32
+ }) => void;
33
+ /**
34
+ * A comment's range markers between blocks, as every block container reads
35
+ * them: beside a content control (`w:displacedByCustomXml`) or between two
36
+ * paragraphs. Typed blocks, as move range and bookmark markers are, so every
37
+ * reader that pairs a comment's start with its end sees both halves.
38
+ */
39
+ type BlockCommentRangeMarkerHandlers = {
40
+ readonly commentRangeStart: BlockCommentRangeMarkerHandler;
41
+ readonly commentRangeEnd: BlockCommentRangeMarkerHandler;
42
+ };
43
+ export declare const BLOCK_COMMENT_RANGE_MARKER_HANDLERS: BlockCommentRangeMarkerHandlers;
30
44
  export {};
@@ -74,4 +74,18 @@ const BLOCK_MOVE_RANGE_MARKER_HANDLERS = {
74
74
  });
75
75
  }
76
76
  };
77
- export { BLOCK_MOVE_RANGE_MARKER_HANDLERS, parseBookmarkRangeMarker, parseCopyOriginMarker, parseMarkupRangeMarker, parseMoveBookmarkMarker };
77
+ const BLOCK_COMMENT_RANGE_MARKER_HANDLERS = {
78
+ commentRangeStart: (child, { modelled }) => {
79
+ modelled.push({
80
+ type: "commentRangeStart",
81
+ ...parseMarkupRangeMarker(child)
82
+ });
83
+ },
84
+ commentRangeEnd: (child, { modelled }) => {
85
+ modelled.push({
86
+ type: "commentRangeEnd",
87
+ ...parseMarkupRangeMarker(child)
88
+ });
89
+ }
90
+ };
91
+ export { BLOCK_COMMENT_RANGE_MARKER_HANDLERS, BLOCK_MOVE_RANGE_MARKER_HANDLERS, parseBookmarkRangeMarker, parseCopyOriginMarker, parseMarkupRangeMarker, parseMoveBookmarkMarker };