@stll/folio-core 0.45.0 → 0.47.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 (451) hide show
  1. package/dist/ai-edits/apply.js +85 -43
  2. package/dist/ai-edits/headless.js +2 -2
  3. package/dist/ai-edits/read.d.ts +1 -0
  4. package/dist/ai-edits/read.js +1 -0
  5. package/dist/ai-edits/snapshot.js +32 -27
  6. package/dist/ai-edits/table-cell-mutations.js +15 -7
  7. package/dist/ai-edits/table-geometry.js +21 -18
  8. package/dist/ai-edits/table-template.js +2 -2
  9. package/dist/compare/compare.js +2 -5
  10. package/dist/compare/content-alignment.js +108 -12
  11. package/dist/compare/content-types.d.ts +8 -2
  12. package/dist/compare/content.js +2 -11
  13. package/dist/compare/plan.js +7 -4
  14. package/dist/compare/scenario.js +2 -5
  15. package/dist/compare/section-boundary-properties.js +1 -2
  16. package/dist/compare/types.d.ts +9 -1
  17. package/dist/compare/types.js +12 -1
  18. package/dist/compat/eigenpal.d.ts +2 -1
  19. package/dist/compat/eigenpal.js +2 -1
  20. package/dist/content-controls/checkboxDisplay.d.ts +17 -0
  21. package/dist/content-controls/checkboxDisplay.js +46 -0
  22. package/dist/content-controls/findContentControls.js +3 -1
  23. package/dist/content-controls/mutateContentControls.js +57 -43
  24. package/dist/controller/contentControlWidgetController.d.ts +1 -0
  25. package/dist/controller/contentControlWidgetController.js +3 -0
  26. package/dist/controller/hiddenEditorApi.js +3 -1
  27. package/dist/controller/hiddenEditorManager.d.ts +1 -1
  28. package/dist/controller/hiddenEditorManager.js +6 -3
  29. package/dist/controller/layoutPipeline.js +8 -3
  30. package/dist/display-list/build/buildDisplayList.js +20 -1
  31. package/dist/display-list/build/imagePrimitives.d.ts +4 -4
  32. package/dist/display-list/build/imagePrimitives.js +38 -18
  33. package/dist/display-list/build/pageBorderPrimitives.js +2 -1
  34. package/dist/display-list/build/paragraphPrimitives.js +113 -14
  35. package/dist/display-list/build/previewPrimitives.d.ts +10 -0
  36. package/dist/display-list/build/previewPrimitives.js +89 -0
  37. package/dist/display-list/build/strokes.d.ts +177 -8
  38. package/dist/display-list/build/strokes.js +167 -47
  39. package/dist/display-list/build/tablePrimitives.js +4 -2
  40. package/dist/display-list/build/textBoxPrimitives.js +6 -4
  41. package/dist/display-list/build/textDecorations.d.ts +15 -1
  42. package/dist/display-list/build/textDecorations.js +15 -1
  43. package/dist/display-list/dom/renderDisplayListToDom.js +11 -21
  44. package/dist/display-list/primitives.d.ts +13 -2
  45. package/dist/display-list/primitives.js +36 -1
  46. package/dist/display-list/types.d.ts +17 -0
  47. package/dist/document-operations.js +2 -1
  48. package/dist/docx/attributeRemainder.d.ts +76 -0
  49. package/dist/docx/attributeRemainder.js +111 -0
  50. package/dist/docx/blockContentParser.d.ts +3 -1
  51. package/dist/docx/blockContentParser.js +102 -106
  52. package/dist/docx/blockPlainText.d.ts +3 -4
  53. package/dist/docx/blockPlainText.js +3 -0
  54. package/dist/docx/borderParser.js +26 -11
  55. package/dist/docx/builtInStyles.d.ts +8 -16
  56. package/dist/docx/builtInStyles.js +54 -17
  57. package/dist/docx/commentAnchorIndex.d.ts +30 -0
  58. package/dist/docx/commentAnchorIndex.js +50 -0
  59. package/dist/docx/commentParser.d.ts +1 -1
  60. package/dist/docx/commentParser.js +56 -39
  61. package/dist/docx/commentRangeIntegrity.d.ts +16 -1
  62. package/dist/docx/commentRangeIntegrity.js +42 -1
  63. package/dist/docx/commentRangeJoin.d.ts +9 -0
  64. package/dist/docx/commentRangeJoin.js +33 -0
  65. package/dist/docx/commentReferenceCompletion.d.ts +9 -0
  66. package/dist/docx/commentReferenceCompletion.js +47 -0
  67. package/dist/docx/commentReferenceNormalization.js +3 -1
  68. package/dist/docx/commentReplyMarkers.js +11 -19
  69. package/dist/docx/compatibility.js +56 -41
  70. package/dist/docx/containerChildren.d.ts +208 -0
  71. package/dist/docx/containerChildren.gen.d.ts +43 -0
  72. package/dist/docx/containerChildren.gen.js +263 -0
  73. package/dist/docx/containerChildren.js +153 -0
  74. package/dist/docx/diagramPreview.d.ts +14 -2
  75. package/dist/docx/diagramPreview.js +81 -169
  76. package/dist/docx/documentParser.d.ts +1 -1
  77. package/dist/docx/documentParser.js +7 -4
  78. package/dist/docx/drawingAnchor.d.ts +87 -0
  79. package/dist/docx/drawingAnchor.js +201 -0
  80. package/dist/docx/drawingUtils.d.ts +43 -38
  81. package/dist/docx/drawingUtils.js +205 -118
  82. package/dist/docx/ensureParaIds.js +17 -7
  83. package/dist/docx/fieldParser.d.ts +1 -1
  84. package/dist/docx/fieldParser.js +4 -4
  85. package/dist/docx/fieldState.d.ts +26 -0
  86. package/dist/docx/fieldState.js +53 -0
  87. package/dist/docx/fontTableParser.js +102 -41
  88. package/dist/docx/footnoteParser.d.ts +1 -1
  89. package/dist/docx/footnoteParser.js +10 -6
  90. package/dist/docx/graphicFrameLocks.d.ts +16 -4
  91. package/dist/docx/graphicFrameLocks.js +19 -6
  92. package/dist/docx/groupDrawingParser.js +4 -3
  93. package/dist/docx/headerFooterParser.js +1 -1
  94. package/dist/docx/headerFooterReferenceNormalization.js +1 -0
  95. package/dist/docx/hyperlinkParser.d.ts +66 -9
  96. package/dist/docx/hyperlinkParser.js +153 -26
  97. package/dist/docx/imageParser.js +160 -115
  98. package/dist/docx/index.d.ts +2 -1
  99. package/dist/docx/index.js +2 -1
  100. package/dist/docx/inlineContentRemovals.d.ts +28 -0
  101. package/dist/docx/inlineContentRemovals.js +46 -0
  102. package/dist/docx/inlineWrapperContent.d.ts +166 -0
  103. package/dist/docx/inlineWrapperContent.js +165 -0
  104. package/dist/docx/inlineWrapperParser.d.ts +11 -0
  105. package/dist/docx/inlineWrapperParser.js +60 -0
  106. package/dist/docx/nonVisualDrawingProps.d.ts +5 -13
  107. package/dist/docx/normalizeBaseDirection.js +12 -1
  108. package/dist/docx/numberingParser.d.ts +25 -2
  109. package/dist/docx/numberingParser.js +264 -361
  110. package/dist/docx/numberingReference.d.ts +9 -16
  111. package/dist/docx/numberingReference.js +17 -16
  112. package/dist/docx/numberingReferenceNormalization.js +7 -7
  113. package/dist/docx/ooxmlCounterFormatter.d.ts +1 -1
  114. package/dist/docx/ooxmlCounterFormatter.js +4 -1
  115. package/dist/docx/paraIdAttribute.d.ts +111 -0
  116. package/dist/docx/paraIdAttribute.js +142 -0
  117. package/dist/docx/paragraphParser.d.ts +10 -25
  118. package/dist/docx/paragraphParser.js +421 -496
  119. package/dist/docx/paragraphProperties.d.ts +23 -0
  120. package/dist/docx/paragraphProperties.js +279 -0
  121. package/dist/docx/paragraphPropertySource.js +7 -1
  122. package/dist/docx/paragraphTextBoxEnrichment.d.ts +3 -2
  123. package/dist/docx/paragraphTextBoxEnrichment.js +20 -59
  124. package/dist/docx/paragraphTraversal.d.ts +14 -10
  125. package/dist/docx/paragraphTraversal.js +53 -52
  126. package/dist/docx/parseWarningMessage.js +5 -1
  127. package/dist/docx/parserEnums.d.ts +6 -8
  128. package/dist/docx/parserEnums.js +4 -6
  129. package/dist/docx/preservedRunContent.d.ts +32 -0
  130. package/dist/docx/preservedRunContent.js +96 -0
  131. package/dist/docx/previewBudget.d.ts +44 -23
  132. package/dist/docx/previewBudget.js +61 -30
  133. package/dist/docx/propertyElementAttributes.d.ts +178 -0
  134. package/dist/docx/propertyElementAttributes.js +114 -0
  135. package/dist/docx/renderedPageBreakNormalization.js +4 -6
  136. package/dist/docx/rezip.d.ts +28 -2
  137. package/dist/docx/rezip.js +152 -27
  138. package/dist/docx/runConsolidator.d.ts +42 -2
  139. package/dist/docx/runConsolidator.js +60 -6
  140. package/dist/docx/runParser.d.ts +55 -19
  141. package/dist/docx/runParser.js +394 -306
  142. package/dist/docx/runPayload.d.ts +5 -0
  143. package/dist/docx/runPayload.js +4 -0
  144. package/dist/docx/sdtProperties.d.ts +39 -5
  145. package/dist/docx/sdtProperties.js +205 -84
  146. package/dist/docx/sdtPropertiesPatch.d.ts +5 -9
  147. package/dist/docx/sdtPropertiesPatch.js +68 -112
  148. package/dist/docx/sectionParser.d.ts +1 -2
  149. package/dist/docx/sectionParser.js +241 -238
  150. package/dist/docx/selectiveSave.js +3 -2
  151. package/dist/docx/selectiveXmlPatch.d.ts +66 -3
  152. package/dist/docx/selectiveXmlPatch.js +276 -133
  153. package/dist/docx/serializer/blockSdtSerializer.js +2 -96
  154. package/dist/docx/serializer/borderSerializer.d.ts +5 -5
  155. package/dist/docx/serializer/borderSerializer.js +12 -10
  156. package/dist/docx/serializer/commentSerializer.js +5 -7
  157. package/dist/docx/serializer/documentSerializer.js +11 -11
  158. package/dist/docx/serializer/fontTableSerializer.js +31 -3
  159. package/dist/docx/serializer/headerFooterSerializer.js +10 -9
  160. package/dist/docx/serializer/markupRangeAttributes.d.ts +9 -1
  161. package/dist/docx/serializer/markupRangeAttributes.js +9 -1
  162. package/dist/docx/serializer/noteSerializer.js +11 -8
  163. package/dist/docx/serializer/numberingSerializer.d.ts +1 -6
  164. package/dist/docx/serializer/numberingSerializer.js +81 -79
  165. package/dist/docx/serializer/paragraphSerializer.d.ts +1 -9
  166. package/dist/docx/serializer/paragraphSerializer.js +156 -236
  167. package/dist/docx/serializer/runSerializer.d.ts +1 -5
  168. package/dist/docx/serializer/runSerializer.js +134 -75
  169. package/dist/docx/serializer/sdtPropertiesSerializer.d.ts +26 -0
  170. package/dist/docx/serializer/sdtPropertiesSerializer.js +111 -0
  171. package/dist/docx/serializer/sectionPropertiesSerializer.js +42 -49
  172. package/dist/docx/serializer/settingsSerializer.js +6 -4
  173. package/dist/docx/serializer/stylesSerializer.js +8 -11
  174. package/dist/docx/serializer/tableSerializer.js +283 -105
  175. package/dist/docx/serializer/textFormattingSerializer.d.ts +28 -4
  176. package/dist/docx/serializer/textFormattingSerializer.js +111 -101
  177. package/dist/docx/serializer/xmlUtils.d.ts +1 -1
  178. package/dist/docx/serializer/xmlUtils.js +1 -1
  179. package/dist/docx/server/createBilingualDocument.js +20 -16
  180. package/dist/docx/server/materializeYjsDocx.d.ts +1 -1
  181. package/dist/docx/server/materializeYjsDocx.js +9 -1
  182. package/dist/docx/server/migrateYjsAttrSchema.d.ts +55 -0
  183. package/dist/docx/server/migrateYjsAttrSchema.js +95 -0
  184. package/dist/docx/settingsParser.js +7 -4
  185. package/dist/docx/shadingParser.d.ts +2 -1
  186. package/dist/docx/shadingParser.js +43 -7
  187. package/dist/docx/shapeParser.js +13 -8
  188. package/dist/docx/strictNames.d.ts +11 -0
  189. package/dist/docx/strictNames.gen.d.ts +45 -0
  190. package/dist/docx/strictNames.gen.js +50 -0
  191. package/dist/docx/strictNames.js +43 -0
  192. package/dist/docx/strictValueEncodings.gen.js +133 -131
  193. package/dist/docx/styleParser.js +17 -349
  194. package/dist/docx/tableParser.d.ts +11 -2
  195. package/dist/docx/tableParser.js +665 -220
  196. package/dist/docx/textBoxParser.d.ts +28 -3
  197. package/dist/docx/textBoxParser.js +69 -9
  198. package/dist/docx/themeColorAttribute.d.ts +13 -0
  199. package/dist/docx/themeColorAttribute.js +24 -0
  200. package/dist/docx/trackedMoveRangeNormalization.js +2 -1
  201. package/dist/docx/unzip.js +5 -4
  202. package/dist/docx/vmlImageParser.d.ts +30 -5
  203. package/dist/docx/vmlImageParser.js +91 -32
  204. package/dist/docx/vmlPreview.js +2 -2
  205. package/dist/docx/wrapPolygon.d.ts +30 -0
  206. package/dist/docx/wrapPolygon.js +70 -0
  207. package/dist/docx/xmlEncoding.d.ts +5 -0
  208. package/dist/docx/xmlEncoding.js +12 -0
  209. package/dist/docx/xmlParser.d.ts +23 -1
  210. package/dist/docx/xmlParser.js +31 -2
  211. package/dist/fonts/embeddedFonts.js +3 -3
  212. package/dist/headless-layout.js +12 -1
  213. package/dist/i18n/messages/catalogs.gen.d.ts +68 -0
  214. package/dist/i18n/messages/catalogs.gen.js +102 -34
  215. package/dist/i18n/messages/messages.gen.d.ts +4 -0
  216. package/dist/index.d.ts +2 -1
  217. package/dist/index.js +2 -1
  218. package/dist/internal/headlessRevisionResolution.js +9 -0
  219. package/dist/internal/pageBreakRunSourceDescendantIndex.js +7 -2
  220. package/dist/internal/paragraphFormattingSerialization.d.ts +20 -9
  221. package/dist/internal/paragraphFormattingSerialization.js +118 -83
  222. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  223. package/dist/layout-bridge/convert/footnoteLayout.js +1 -0
  224. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  225. package/dist/layout-bridge/convert/headerFooterLayout.js +2 -0
  226. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +17 -12
  227. package/dist/layout-bridge/convert/toFlowBlocks.js +267 -101
  228. package/dist/layout-engine/index.d.ts +2 -2
  229. package/dist/layout-engine/index.js +53 -17
  230. package/dist/layout-engine/measure/measureBlocks.d.ts +3 -0
  231. package/dist/layout-engine/measure/measureBlocks.js +6 -10
  232. package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
  233. package/dist/layout-engine/measure/tableCellFloating.js +2 -0
  234. package/dist/layout-engine/measure/tableCellGrid.js +2 -1
  235. package/dist/layout-engine/measure/tableFragmentBorderGeometry.js +2 -1
  236. package/dist/layout-engine/measure/tableInlinePlacement.js +2 -5
  237. package/dist/layout-engine/paragraphSequence.js +3 -2
  238. package/dist/layout-engine/renderedBreakReconciliation.js +2 -1
  239. package/dist/layout-engine/section-breaks.d.ts +49 -2
  240. package/dist/layout-engine/section-breaks.js +55 -4
  241. package/dist/layout-engine/types.d.ts +69 -17
  242. package/dist/layout-engine/types.js +16 -1
  243. package/dist/layout-painter/borderStroke.d.ts +18 -4
  244. package/dist/layout-painter/renderImage.d.ts +5 -1
  245. package/dist/layout-painter/renderImage.js +10 -3
  246. package/dist/layout-painter/renderPage.d.ts +2 -0
  247. package/dist/layout-painter/renderPage.js +10 -4
  248. package/dist/layout-painter/renderParagraph.d.ts +14 -1
  249. package/dist/layout-painter/renderParagraph.js +34 -28
  250. package/dist/layout-painter/renderTable.d.ts +4 -1
  251. package/dist/layout-painter/renderTable.js +22 -22
  252. package/dist/layout-painter/renderTextBox.js +5 -3
  253. package/dist/managers/autoSaveCodec.d.ts +9 -1
  254. package/dist/managers/autoSaveCodec.js +12 -4
  255. package/dist/markdown/renderBlock.js +3 -0
  256. package/dist/markdown/renderRuns.d.ts +1 -1
  257. package/dist/markdown/renderRuns.js +34 -6
  258. package/dist/markdown/renderTable.js +24 -6
  259. package/dist/markdown/trailers.js +4 -1
  260. package/dist/model.d.ts +3 -3
  261. package/dist/model.js +2 -2
  262. package/dist/paged-layout/sectionBlockWidths.d.ts +3 -0
  263. package/dist/paged-layout/sectionBlockWidths.js +26 -4
  264. package/dist/pdf/images.js +142 -6
  265. package/dist/prosemirror/attrs/index.d.ts +34 -5
  266. package/dist/prosemirror/attrs/index.js +639 -48
  267. package/dist/prosemirror/authoredTransformAttrs.d.ts +28 -0
  268. package/dist/prosemirror/authoredTransformAttrs.js +64 -0
  269. package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +9 -1
  270. package/dist/prosemirror/bookmarkBoundaryAttrs.js +22 -3
  271. package/dist/prosemirror/commands/comments.js +68 -53
  272. package/dist/prosemirror/commands/contentControls.js +33 -20
  273. package/dist/prosemirror/commands/image.d.ts +10 -3
  274. package/dist/prosemirror/commands/image.js +46 -29
  275. package/dist/prosemirror/commands/pageBreak.js +1 -1
  276. package/dist/prosemirror/commands/paragraph.d.ts +2 -1
  277. package/dist/prosemirror/commands/propertyChangeScope.d.ts +12 -4
  278. package/dist/prosemirror/commands/propertyChangeScope.js +22 -4
  279. package/dist/prosemirror/commands/sectionBreak.d.ts +33 -1
  280. package/dist/prosemirror/commands/sectionBreak.js +187 -11
  281. package/dist/prosemirror/commentReferenceAttrs.d.ts +8 -0
  282. package/dist/prosemirror/commentReferenceAttrs.js +33 -0
  283. package/dist/prosemirror/commentReferenceIntegrity.d.ts +47 -0
  284. package/dist/prosemirror/commentReferenceIntegrity.js +43 -0
  285. package/dist/prosemirror/conversion/fromProseDoc.d.ts +17 -12
  286. package/dist/prosemirror/conversion/fromProseDoc.js +553 -207
  287. package/dist/prosemirror/conversion/index.d.ts +2 -2
  288. package/dist/prosemirror/conversion/preservedSinkCarriers.d.ts +39 -0
  289. package/dist/prosemirror/conversion/preservedSinkCarriers.js +19 -0
  290. package/dist/prosemirror/conversion/runShadingMark.js +14 -1
  291. package/dist/prosemirror/conversion/sdtAttrs.d.ts +10 -1
  292. package/dist/prosemirror/conversion/sdtAttrs.js +19 -5
  293. package/dist/prosemirror/conversion/toProseDoc.d.ts +7 -9
  294. package/dist/prosemirror/conversion/toProseDoc.js +801 -411
  295. package/dist/prosemirror/emptyRangeAnchor.d.ts +53 -0
  296. package/dist/prosemirror/emptyRangeAnchor.js +158 -0
  297. package/dist/prosemirror/extensions/StarterKit.js +14 -58
  298. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  299. package/dist/prosemirror/extensions/core/ParagraphExtension.js +21 -16
  300. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +48 -29
  301. package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +3 -1
  302. package/dist/prosemirror/extensions/features/ImagePasteExtension.js +5 -3
  303. package/dist/prosemirror/extensions/features/ListExtension.js +43 -24
  304. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +1 -0
  305. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +4 -3
  306. package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +3 -3
  307. package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +5 -5
  308. package/dist/prosemirror/extensions/features/pasteCleanup.d.ts +3 -1
  309. package/dist/prosemirror/extensions/features/pasteCleanup.js +56 -2
  310. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +5 -4
  311. package/dist/prosemirror/extensions/markRegistry.d.ts +65 -0
  312. package/dist/prosemirror/extensions/markRegistry.js +138 -0
  313. package/dist/prosemirror/extensions/marks/InlineWrapperExtension.d.ts +18 -0
  314. package/dist/prosemirror/extensions/marks/InlineWrapperExtension.js +77 -0
  315. package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +26 -0
  316. package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +134 -0
  317. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +2 -1
  318. package/dist/prosemirror/extensions/marks/UnderlineExtension.js +12 -18
  319. package/dist/prosemirror/extensions/marks/markUtils.d.ts +2 -1
  320. package/dist/prosemirror/extensions/marks/markUtils.js +49 -5
  321. package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.d.ts +29 -0
  322. package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.js +46 -0
  323. package/dist/prosemirror/extensions/nodes/BlockSdtExtension.d.ts +4 -3
  324. package/dist/prosemirror/extensions/nodes/BlockSdtExtension.js +18 -13
  325. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +28 -53
  326. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.d.ts +11 -0
  327. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +97 -0
  328. package/dist/prosemirror/extensions/nodes/FieldExtension.js +9 -7
  329. package/dist/prosemirror/extensions/nodes/ImageExtension.js +24 -1
  330. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.d.ts +11 -0
  331. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +43 -0
  332. package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.d.ts +32 -0
  333. package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.js +67 -0
  334. package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.d.ts +16 -0
  335. package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.js +60 -0
  336. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.d.ts +13 -0
  337. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +65 -0
  338. package/dist/prosemirror/extensions/nodes/SdtExtension.d.ts +3 -1
  339. package/dist/prosemirror/extensions/nodes/SdtExtension.js +22 -16
  340. package/dist/prosemirror/extensions/nodes/ShapeExtension.js +7 -0
  341. package/dist/prosemirror/extensions/nodes/TableExtension.js +142 -123
  342. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +9 -1
  343. package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.d.ts +23 -0
  344. package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.js +57 -0
  345. package/dist/prosemirror/extensions/types.d.ts +12 -3
  346. package/dist/prosemirror/index.d.ts +4 -2
  347. package/dist/prosemirror/index.js +2 -1
  348. package/dist/prosemirror/inlineWrapperStack.d.ts +39 -0
  349. package/dist/prosemirror/inlineWrapperStack.js +92 -0
  350. package/dist/prosemirror/listMarker.d.ts +2 -2
  351. package/dist/prosemirror/listMarker.js +7 -8
  352. package/dist/prosemirror/listRenderingAttrs.js +11 -1
  353. package/dist/prosemirror/listState.d.ts +62 -0
  354. package/dist/prosemirror/listState.js +49 -0
  355. package/dist/prosemirror/moveRangeBoundaryAttrs.d.ts +13 -0
  356. package/dist/prosemirror/moveRangeBoundaryAttrs.js +114 -0
  357. package/dist/prosemirror/numberedRefFields.js +4 -4
  358. package/dist/prosemirror/numberingAttr.d.ts +55 -0
  359. package/dist/prosemirror/numberingAttr.js +74 -0
  360. package/dist/prosemirror/outlineLevelAttr.d.ts +29 -0
  361. package/dist/prosemirror/outlineLevelAttr.js +42 -0
  362. package/dist/prosemirror/pageBreakRunProjection.d.ts +17 -7
  363. package/dist/prosemirror/pageBreakRunProjection.js +19 -9
  364. package/dist/prosemirror/paragraphFormattingProvenance.d.ts +9 -0
  365. package/dist/prosemirror/paragraphFormattingProvenance.js +4 -1
  366. package/dist/prosemirror/plugins/selectionTracker.d.ts +3 -6
  367. package/dist/prosemirror/plugins/selectionTracker.js +3 -10
  368. package/dist/prosemirror/rangeAnchorAttrs.d.ts +14 -0
  369. package/dist/prosemirror/rangeAnchorAttrs.js +101 -0
  370. package/dist/prosemirror/replacedAnnotations.d.ts +59 -0
  371. package/dist/prosemirror/replacedAnnotations.js +183 -0
  372. package/dist/prosemirror/revisionCarriers.d.ts +86 -2
  373. package/dist/prosemirror/revisionCarriers.js +86 -60
  374. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +5 -1
  375. package/dist/prosemirror/runFormattingInlineCarriers.js +7 -1
  376. package/dist/prosemirror/runIdentity.d.ts +28 -0
  377. package/dist/prosemirror/runIdentity.js +36 -0
  378. package/dist/prosemirror/runStyleFormatting.js +1 -1
  379. package/dist/prosemirror/schema/index.d.ts +3 -3
  380. package/dist/prosemirror/schema/marks.d.ts +47 -4
  381. package/dist/prosemirror/schema/nodes.d.ts +309 -26
  382. package/dist/prosemirror/schema/nodes.js +16 -1
  383. package/dist/prosemirror/sectionCarrier.d.ts +37 -0
  384. package/dist/prosemirror/sectionCarrier.js +40 -0
  385. package/dist/prosemirror/selectionState.d.ts +3 -0
  386. package/dist/prosemirror/selectionState.js +4 -1
  387. package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +5 -4
  388. package/dist/prosemirror/styles/resolvedStyleAttrs.js +15 -13
  389. package/dist/prosemirror/tableResize.js +5 -6
  390. package/dist/prosemirror/trackedRunInlineAtoms.d.ts +4 -0
  391. package/dist/prosemirror/trackedRunInlineAtoms.js +4 -0
  392. package/dist/prosemirror/utils/extractTrackedChanges.d.ts +10 -11
  393. package/dist/prosemirror/utils/extractTrackedChanges.js +109 -92
  394. package/dist/prosemirror/validation.js +31 -6
  395. package/dist/prosemirror/yjsDocumentMetadata.d.ts +73 -0
  396. package/dist/prosemirror/yjsDocumentMetadata.js +592 -0
  397. package/dist/prosemirror/zeroWidthAnchors.js +6 -0
  398. package/dist/render-dom/commentAnchorAttributes.d.ts +37 -0
  399. package/dist/render-dom/commentAnchorAttributes.js +54 -0
  400. package/dist/server.d.ts +3 -1
  401. package/dist/server.js +3 -1
  402. package/dist/style-sets/extract.js +4 -4
  403. package/dist/style-sets/stellaStyle.js +36 -23
  404. package/dist/types/colors.d.ts +2 -2
  405. package/dist/types/content.d.ts +2 -2
  406. package/dist/types/documentEnumValues.d.ts +53 -26
  407. package/dist/types/documentEnumValues.js +72 -174
  408. package/dist/types/formatting.d.ts +2 -2
  409. package/dist/types/index.d.ts +9 -2
  410. package/dist/utils/borderCss.d.ts +246 -0
  411. package/dist/utils/borderCss.js +325 -0
  412. package/dist/utils/clipboard.d.ts +9 -1
  413. package/dist/utils/clipboard.js +27 -1
  414. package/dist/utils/colorResolver.d.ts +4 -3
  415. package/dist/utils/colorResolver.js +45 -76
  416. package/dist/utils/createDocument.js +24 -6
  417. package/dist/utils/findReplace.js +52 -10
  418. package/dist/utils/formatToStyle.d.ts +84 -2
  419. package/dist/utils/formatToStyle.js +133 -52
  420. package/dist/utils/headingCollector.js +3 -2
  421. package/dist/utils/imageLuminance.d.ts +15 -0
  422. package/dist/utils/imageLuminance.js +32 -0
  423. package/dist/utils/mergeDocumentContent.js +12 -20
  424. package/dist/utils/paragraphFormattingMerge.js +27 -6
  425. package/dist/utils/replaceText.js +1 -0
  426. package/dist/utils/tableOperations.d.ts +5 -3
  427. package/dist/utils/tableOperations.js +14 -1
  428. package/dist/utils/tablePlacement.d.ts +7 -0
  429. package/dist/utils/tablePlacement.js +14 -0
  430. package/dist/utils/textDirectionFlow.d.ts +15 -0
  431. package/dist/utils/textDirectionFlow.js +38 -0
  432. package/dist/utils/textFormattingMerge.js +16 -4
  433. package/package.json +10 -10
  434. package/dist/ai-edits/__fixtures__/paragraphs.d.ts +0 -17
  435. package/dist/ai-edits/__fixtures__/paragraphs.js +0 -33
  436. package/dist/compare/__fixtures__/body-sequence.d.ts +0 -119
  437. package/dist/compare/__fixtures__/body-sequence.js +0 -225
  438. package/dist/compare/__fixtures__/nested-table.d.ts +0 -16
  439. package/dist/compare/__fixtures__/nested-table.js +0 -50
  440. package/dist/compare/__fixtures__/numbered-list.d.ts +0 -34
  441. package/dist/compare/__fixtures__/numbered-list.js +0 -85
  442. package/dist/docx/blockRangeMarkers.d.ts +0 -36
  443. package/dist/docx/blockRangeMarkers.js +0 -59
  444. package/dist/docx/bookmarkPlacement.d.ts +0 -9
  445. package/dist/docx/bookmarkPlacement.js +0 -50
  446. package/dist/fonts/embeddedFontTable.d.ts +0 -45
  447. package/dist/fonts/embeddedFontTable.js +0 -80
  448. package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.d.ts +0 -13
  449. package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.js +0 -39
  450. package/dist/prosemirror/yjsParagraphSourceContract.d.ts +0 -9
  451. package/dist/prosemirror/yjsParagraphSourceContract.js +0 -26
@@ -1,14 +1,19 @@
1
1
  import { canonicalJson } from "../../utils/canonicalJson.js";
2
2
  import { isValidHexColor } from "../../utils/colorResolver.js";
3
- import { withBlockRangeMarkers } from "../blockRangeMarkers.js";
3
+ import { serializePreservedAttributes } from "../attributeRemainder.js";
4
+ import { withPreservedChildren } from "../containerChildren.js";
5
+ import { TRANSITIONAL_NAME_BY_STRICT_NAME } from "../strictNames.gen.js";
4
6
  import { TABLE_LOOK_FLAGS } from "../tableLook.js";
5
- import { parseTableCellProperties, parseTableGrid, parseTableProperties, parseTableRowProperties } from "../tableParser.js";
6
- import { sanitizeCapturedXmlElement } from "../verbatimCapture.js";
7
- import { NAMESPACES, OOXML_NAMESPACE_SCOPE, parseXml } from "../xmlParser.js";
7
+ import { parseTableCellProperties, parseTableGrid, parseTableProperties, parseTablePropertyExceptions, parseTableRowProperties } from "../tableParser.js";
8
+ import { OOXML_NAMESPACE_SCOPE, parseXml } from "../xmlParser.js";
8
9
  import { serializeBorder } from "./borderSerializer.js";
10
+ import { serializeBookmarkMarker } from "./markupRangeAttributes.js";
11
+ import { serializeSdtWrapper } from "./sdtPropertiesSerializer.js";
9
12
  import { serializeTrackedChangeAttributes } from "./trackedChangeAttributes.js";
10
13
  import { intAttr } from "./xmlUtils.js";
11
- import { escapeXmlAttribute } from "@stll/docx-core";
14
+ import { escapeXmlAttribute, serializeOnOffElement } from "@stll/docx-core";
15
+ import { themeColorToken } from "@stll/docx-core/model";
16
+ import { serializeSequenceChildren } from "@stll/docx-core/schema";
12
17
  //#region src/docx/serializer/tableSerializer.ts
13
18
  /**
14
19
  * The captured element with the revision children written back into it.
@@ -29,20 +34,36 @@ const withRevisionChildren = (sourceXml, revisions) => {
29
34
  };
30
35
  /** `w:trPr/w:ins` | `w:trPr/w:del`, the row's own structural revision. */
31
36
  const rowStructuralChangeXml = (change) => {
32
- if (change?.type === "tableRowInsertion") return [`<w:ins ${serializeTrackedChangeAttributes(change.info)}/>`];
33
- if (change?.type === "tableRowDeletion") return [`<w:del ${serializeTrackedChangeAttributes(change.info)}/>`];
34
- return [];
37
+ if (change?.type === "tableRowInsertion") return {
38
+ name: "ins",
39
+ xml: `<w:ins ${serializeTrackedChangeAttributes(change.info)}/>`
40
+ };
41
+ if (change?.type === "tableRowDeletion") return {
42
+ name: "del",
43
+ xml: `<w:del ${serializeTrackedChangeAttributes(change.info)}/>`
44
+ };
35
45
  };
36
46
  /** `w:tcPr/w:cellIns` | `w:cellDel` | `w:cellMerge`, the cell's own. */
37
47
  const cellStructuralChangeXml = (change) => {
38
- if (change?.type === "tableCellInsertion") return [`<w:cellIns ${serializeTrackedChangeAttributes(change.info)}/>`];
39
- if (change?.type === "tableCellDeletion") return [`<w:cellDel ${serializeTrackedChangeAttributes(change.info)}/>`];
40
- if (change?.type !== "tableCellMerge") return [];
48
+ if (change?.type === "tableCellInsertion") return {
49
+ name: "cellIns",
50
+ xml: `<w:cellIns ${serializeTrackedChangeAttributes(change.info)}/>`
51
+ };
52
+ if (change?.type === "tableCellDeletion") return {
53
+ name: "cellDel",
54
+ xml: `<w:cellDel ${serializeTrackedChangeAttributes(change.info)}/>`
55
+ };
56
+ if (change?.type !== "tableCellMerge") return;
41
57
  const attrs = [serializeTrackedChangeAttributes(change.info)];
42
58
  if (change.verticalMerge) attrs.push(`w:vMerge="${change.verticalMerge === "continue" ? "cont" : "rest"}"`);
43
59
  if (change.verticalMergeOriginal) attrs.push(`w:vMergeOrig="${change.verticalMergeOriginal === "continue" ? "cont" : "rest"}"`);
44
- return [`<w:cellMerge ${attrs.join(" ")}/>`];
60
+ return {
61
+ name: "cellMerge",
62
+ xml: `<w:cellMerge ${attrs.join(" ")}/>`
63
+ };
45
64
  };
65
+ /** The one structural revision a property set carries, as a modelled entry. */
66
+ const structuralChangeEntry = (name, change) => [name, change?.name === name ? change.xml : ""];
46
67
  /**
47
68
  * A property set without the elements kept beside it. Only the typed values
48
69
  * decide whether a capture still describes the node; the captures themselves
@@ -81,6 +102,16 @@ function serializeMeasurement(measurement, elementName) {
81
102
  return `<w:${elementName} ${[`w:w="${intAttr(measurement.value)}"`, `w:type="${measurement.type}"`].join(" ")}/>`;
82
103
  }
83
104
  /**
105
+ * The side names folio writes, from the table the census reads.
106
+ *
107
+ * A Strict producer spells these `w:start` and `w:end`; folio rebuilds every
108
+ * package as Transitional and writes one spelling, and taking it from the
109
+ * generated table is what keeps the writer and the survival law's equivalence
110
+ * from drifting apart.
111
+ */
112
+ const BORDER_LEFT = TRANSITIONAL_NAME_BY_STRICT_NAME["CT_Border start"];
113
+ const BORDER_RIGHT = TRANSITIONAL_NAME_BY_STRICT_NAME["CT_Border end"];
114
+ /**
84
115
  * Serialize table borders (w:tblBorders or w:tcBorders)
85
116
  */
86
117
  function serializeTableBorderParts(borders) {
@@ -90,9 +121,9 @@ function serializeTableBorderParts(borders) {
90
121
  if (xml) parts.push(xml);
91
122
  };
92
123
  appendBorder(borders.top, "top");
93
- appendBorder(borders.left, "left");
124
+ appendBorder(borders.left, BORDER_LEFT);
94
125
  appendBorder(borders.bottom, "bottom");
95
- appendBorder(borders.right, "right");
126
+ appendBorder(borders.right, BORDER_RIGHT);
96
127
  appendBorder(borders.insideH, "insideH");
97
128
  appendBorder(borders.insideV, "insideV");
98
129
  return parts;
@@ -112,6 +143,9 @@ function serializeTableCellBorders(borders) {
112
143
  if (topRightToBottomLeft) parts.push(topRightToBottomLeft);
113
144
  return parts.length > 0 ? `<w:tcBorders>${parts.join("")}</w:tcBorders>` : "";
114
145
  }
146
+ /** The same rename one type over: a cell margin is a `CT_TblWidth`. */
147
+ const MARGIN_LEFT = TRANSITIONAL_NAME_BY_STRICT_NAME["CT_TblWidth start"];
148
+ const MARGIN_RIGHT = TRANSITIONAL_NAME_BY_STRICT_NAME["CT_TblWidth end"];
115
149
  /**
116
150
  * Serialize cell margins (w:tblCellMar or w:tcMar)
117
151
  */
@@ -119,9 +153,9 @@ function serializeCellMargins(margins, elementName) {
119
153
  if (!margins) return "";
120
154
  const parts = [];
121
155
  if (margins.top) parts.push(serializeMeasurement(margins.top, "top"));
122
- if (margins.left) parts.push(serializeMeasurement(margins.left, "left"));
156
+ if (margins.left) parts.push(serializeMeasurement(margins.left, MARGIN_LEFT));
123
157
  if (margins.bottom) parts.push(serializeMeasurement(margins.bottom, "bottom"));
124
- if (margins.right) parts.push(serializeMeasurement(margins.right, "right"));
158
+ if (margins.right) parts.push(serializeMeasurement(margins.right, MARGIN_RIGHT));
125
159
  if (parts.length === 0) return "";
126
160
  return `<w:${elementName}>${parts.join("")}</w:${elementName}>`;
127
161
  }
@@ -135,9 +169,12 @@ function serializeShading(shading) {
135
169
  else attrs.push("w:val=\"clear\"");
136
170
  if (shading.color?.rgb && isValidHexColor(shading.color.rgb)) attrs.push(`w:color="${escapeXmlAttribute(shading.color.rgb)}"`);
137
171
  else if (shading.color?.auto) attrs.push("w:color=\"auto\"");
172
+ if (shading.color?.themeColor) attrs.push(`w:themeColor="${escapeXmlAttribute(themeColorToken(shading.color.themeColor))}"`);
173
+ if (shading.color?.themeTint) attrs.push(`w:themeTint="${escapeXmlAttribute(shading.color.themeTint)}"`);
174
+ if (shading.color?.themeShade) attrs.push(`w:themeShade="${escapeXmlAttribute(shading.color.themeShade)}"`);
138
175
  if (shading.fill?.rgb && isValidHexColor(shading.fill.rgb)) attrs.push(`w:fill="${escapeXmlAttribute(shading.fill.rgb)}"`);
139
176
  else if (shading.fill?.auto) attrs.push("w:fill=\"auto\"");
140
- if (shading.fill?.themeColor) attrs.push(`w:themeFill="${escapeXmlAttribute(shading.fill.themeColor)}"`);
177
+ if (shading.fill?.themeColor) attrs.push(`w:themeFill="${escapeXmlAttribute(themeColorToken(shading.fill.themeColor))}"`);
141
178
  if (shading.fill?.themeTint) attrs.push(`w:themeFillTint="${escapeXmlAttribute(shading.fill.themeTint)}"`);
142
179
  if (shading.fill?.themeShade) attrs.push(`w:themeFillShade="${escapeXmlAttribute(shading.fill.themeShade)}"`);
143
180
  if (attrs.length === 0) return "";
@@ -182,37 +219,39 @@ function serializeFloatingTableProperties(floating) {
182
219
  if (attrs.length === 0) return "";
183
220
  return `<w:tblpPr ${attrs.join(" ")}/>`;
184
221
  }
222
+ /** `<w:name w:val="…"/>`, or nothing when the model holds no value. */
223
+ const tagWithVal = (name, value) => value === void 0 ? "" : `<w:${name} w:val="${escapeXmlAttribute(value)}"/>`;
224
+ const numberTag = (name, value) => value === void 0 ? "" : `<w:${name} w:val="${intAttr(value)}"/>`;
185
225
  /**
186
226
  * Serialize table formatting properties (w:tblPr)
187
227
  */
188
228
  function serializeTableFormatting(formatting, propertyChanges) {
189
229
  const tableSource = verifiedSourceXml(formatting, parseTableProperties);
190
230
  if (tableSource !== null) return withRevisionChildren(tableSource, (propertyChanges ?? []).map((change) => serializeTablePropertyChange(change)));
191
- const parts = [];
192
- if (formatting) {
193
- if (formatting.styleId) parts.push(`<w:tblStyle w:val="${escapeXmlAttribute(formatting.styleId)}"/>`);
194
- const floatingXml = serializeFloatingTableProperties(formatting.floating);
195
- if (floatingXml) parts.push(floatingXml);
196
- if (formatting.overlap) parts.push(`<w:tblOverlap w:val="${formatting.overlap}"/>`);
197
- if (formatting.bidi !== void 0) parts.push(formatting.bidi ? "<w:bidiVisual/>" : "<w:bidiVisual w:val=\"0\"/>");
198
- const widthXml = serializeMeasurement(formatting.width, "tblW");
199
- if (widthXml) parts.push(widthXml);
200
- if (formatting.justification) parts.push(`<w:jc w:val="${formatting.justification}"/>`);
201
- const cellSpacingXml = serializeMeasurement(formatting.cellSpacing, "tblCellSpacing");
202
- if (cellSpacingXml) parts.push(cellSpacingXml);
203
- const indentXml = serializeMeasurement(formatting.indent, "tblInd");
204
- if (indentXml) parts.push(indentXml);
205
- const bordersXml = serializeTableBorders(formatting.borders, "tblBorders");
206
- if (bordersXml) parts.push(bordersXml);
207
- const shadingXml = serializeShading(formatting.shading);
208
- if (shadingXml) parts.push(shadingXml);
209
- if (formatting.layout) parts.push(`<w:tblLayout w:type="${formatting.layout}"/>`);
210
- const marginsXml = serializeCellMargins(formatting.cellMargins, "tblCellMar");
211
- if (marginsXml) parts.push(marginsXml);
212
- const lookXml = serializeTableLook(formatting.look);
213
- if (lookXml) parts.push(lookXml);
214
- }
215
- if (propertyChanges && propertyChanges.length > 0) parts.push(...propertyChanges.map((change) => serializeTablePropertyChange(change)));
231
+ const parts = serializeSequenceChildren({
232
+ container: "table-properties",
233
+ modelled: [
234
+ ["tblStyle", formatting?.styleId ? tagWithVal("tblStyle", formatting.styleId) : ""],
235
+ ["tblpPr", serializeFloatingTableProperties(formatting?.floating)],
236
+ ["tblOverlap", formatting?.overlap ? `<w:tblOverlap w:val="${formatting.overlap}"/>` : ""],
237
+ ["bidiVisual", serializeOnOffElement(formatting?.bidi, "bidiVisual")],
238
+ ["tblStyleRowBandSize", numberTag("tblStyleRowBandSize", formatting?.rowBandSize)],
239
+ ["tblStyleColBandSize", numberTag("tblStyleColBandSize", formatting?.columnBandSize)],
240
+ ["tblW", serializeMeasurement(formatting?.width, "tblW")],
241
+ ["jc", formatting?.justification ? `<w:jc w:val="${formatting.justification}"/>` : ""],
242
+ ["tblCellSpacing", serializeMeasurement(formatting?.cellSpacing, "tblCellSpacing")],
243
+ ["tblInd", serializeMeasurement(formatting?.indent, "tblInd")],
244
+ ["tblBorders", serializeTableBorders(formatting?.borders, "tblBorders")],
245
+ ["shd", serializeShading(formatting?.shading)],
246
+ ["tblLayout", formatting?.layout ? `<w:tblLayout w:type="${formatting.layout}"/>` : ""],
247
+ ["tblCellMar", serializeCellMargins(formatting?.cellMargins, "tblCellMar")],
248
+ ["tblLook", serializeTableLook(formatting?.look)],
249
+ ["tblCaption", tagWithVal("tblCaption", formatting?.caption)],
250
+ ["tblDescription", tagWithVal("tblDescription", formatting?.description)],
251
+ ["tblPrChange", (propertyChanges ?? []).map((change) => serializeTablePropertyChange(change)).join("")]
252
+ ],
253
+ preserved: formatting?.preserved
254
+ });
216
255
  if (parts.length === 0) return "";
217
256
  return `<w:tblPr>${parts.join("")}</w:tblPr>`;
218
257
  }
@@ -226,32 +265,73 @@ function serializeTablePropertyChange(change) {
226
265
  return `<w:tblPrChange ${attrs}>${previousTblPrInner.length > 0 ? `<w:tblPr>${previousTblPrInner}</w:tblPr>` : "<w:tblPr/>"}</w:tblPrChange>`;
227
266
  }
228
267
  /**
268
+ * Serialize a row's table property exceptions (w:tblPrEx).
269
+ *
270
+ * `CT_TblPrEx` is a sequence like `CT_TblPr`, and the nine children it shares
271
+ * with it are written by the same statements: the modelled half is keyed by
272
+ * element name and `serializeSequenceChildren` puts it in the generated order,
273
+ * so the exception and the property it overrides cannot come out spelled two
274
+ * different ways.
275
+ */
276
+ function serializeTablePropertyExceptions(exceptions, propertyChanges) {
277
+ if (exceptions === void 0 && (propertyChanges ?? []).length === 0) return "";
278
+ const exceptionSource = verifiedSourceXml(exceptions, parseTablePropertyExceptions);
279
+ if (exceptionSource !== null) return withRevisionChildren(exceptionSource, (propertyChanges ?? []).map((change) => serializeTablePropertyExceptionChange(change)));
280
+ const parts = serializeSequenceChildren({
281
+ container: "table-property-exceptions",
282
+ modelled: [
283
+ ["tblW", serializeMeasurement(exceptions?.width, "tblW")],
284
+ ["jc", exceptions?.justification ? `<w:jc w:val="${exceptions.justification}"/>` : ""],
285
+ ["tblCellSpacing", serializeMeasurement(exceptions?.cellSpacing, "tblCellSpacing")],
286
+ ["tblInd", serializeMeasurement(exceptions?.indent, "tblInd")],
287
+ ["tblBorders", serializeTableBorders(exceptions?.borders, "tblBorders")],
288
+ ["shd", serializeShading(exceptions?.shading)],
289
+ ["tblLayout", exceptions?.layout ? `<w:tblLayout w:type="${exceptions.layout}"/>` : ""],
290
+ ["tblCellMar", serializeCellMargins(exceptions?.cellMargins, "tblCellMar")],
291
+ ["tblLook", serializeTableLook(exceptions?.look)],
292
+ ["tblPrExChange", (propertyChanges ?? []).map((change) => serializeTablePropertyExceptionChange(change)).join("")]
293
+ ],
294
+ preserved: exceptions?.preserved
295
+ });
296
+ return parts.length === 0 ? "<w:tblPrEx/>" : `<w:tblPrEx>${parts.join("")}</w:tblPrEx>`;
297
+ }
298
+ function serializeTablePropertyExceptionChange(change) {
299
+ return `<w:tblPrExChange ${serializeTrackedChangeAttributes(change.info)}>${serializeTablePropertyExceptions(change.previousFormatting) || "<w:tblPrEx/>"}</w:tblPrExChange>`;
300
+ }
301
+ /** `w:trHeight`, whose value rides `w:val` rather than `w:w`. */
302
+ const serializeRowHeight = (formatting) => {
303
+ if (!formatting?.height) return "";
304
+ const attrs = [`w:val="${intAttr(formatting.height.value)}"`];
305
+ if (formatting.heightRule) attrs.push(`w:hRule="${formatting.heightRule}"`);
306
+ return `<w:trHeight ${attrs.join(" ")}/>`;
307
+ };
308
+ /**
229
309
  * Serialize table row formatting properties (w:trPr)
230
310
  */
231
311
  function serializeTableRowFormatting(formatting, propertyChanges, structuralChange) {
312
+ const rowStructuralChange = rowStructuralChangeXml(structuralChange);
232
313
  const rowSource = verifiedSourceXml(formatting, parseTableRowProperties);
233
- if (rowSource !== null) return withRevisionChildren(rowSource, [...rowStructuralChangeXml(structuralChange), ...(propertyChanges ?? []).map((change) => serializeTableRowPropertyChange(change))]);
234
- const parts = [];
235
- if (formatting) {
236
- const cnfStyleXml = serializeConditionalFormatStyle(formatting.conditionalFormat);
237
- if (cnfStyleXml) parts.push(cnfStyleXml);
238
- if (formatting.gridBefore) parts.push(`<w:gridBefore w:val="${intAttr(formatting.gridBefore)}"/>`);
239
- if (formatting.widthBefore) parts.push(`<w:wBefore w:w="${intAttr(formatting.widthBefore.value)}" w:type="${formatting.widthBefore.type}"/>`);
240
- if (formatting.gridAfter) parts.push(`<w:gridAfter w:val="${intAttr(formatting.gridAfter)}"/>`);
241
- if (formatting.widthAfter) parts.push(`<w:wAfter w:w="${intAttr(formatting.widthAfter.value)}" w:type="${formatting.widthAfter.type}"/>`);
242
- if (formatting.cantSplit) parts.push("<w:cantSplit/>");
243
- if (formatting.header) parts.push("<w:tblHeader/>");
244
- if (formatting.height) {
245
- const attrs = [`w:val="${intAttr(formatting.height.value)}"`];
246
- if (formatting.heightRule) attrs.push(`w:hRule="${formatting.heightRule}"`);
247
- parts.push(`<w:trHeight ${attrs.join(" ")}/>`);
248
- }
249
- if (formatting.justification) parts.push(`<w:jc w:val="${formatting.justification}"/>`);
250
- if (formatting.hidden) parts.push("<w:hidden/>");
251
- }
252
- parts.push(...rowStructuralChangeXml(structuralChange));
253
- if (propertyChanges && propertyChanges.length > 0) parts.push(...propertyChanges.map((change) => serializeTableRowPropertyChange(change)));
254
- if (parts.length === 0) return "";
314
+ if (rowSource !== null) return withRevisionChildren(rowSource, [...rowStructuralChange ? [rowStructuralChange.xml] : [], ...(propertyChanges ?? []).map((change) => serializeTableRowPropertyChange(change))]);
315
+ const parts = serializeSequenceChildren({
316
+ container: "row-properties",
317
+ modelled: [
318
+ ["cnfStyle", serializeConditionalFormatStyle(formatting?.conditionalFormat)],
319
+ ["gridBefore", formatting?.gridBefore ? `<w:gridBefore w:val="${intAttr(formatting.gridBefore)}"/>` : ""],
320
+ ["gridAfter", formatting?.gridAfter ? `<w:gridAfter w:val="${intAttr(formatting.gridAfter)}"/>` : ""],
321
+ ["wBefore", serializeMeasurement(formatting?.widthBefore, "wBefore")],
322
+ ["wAfter", serializeMeasurement(formatting?.widthAfter, "wAfter")],
323
+ ["cantSplit", serializeOnOffElement(formatting?.cantSplit, "cantSplit")],
324
+ ["trHeight", serializeRowHeight(formatting)],
325
+ ["tblHeader", serializeOnOffElement(formatting?.header, "tblHeader")],
326
+ ["jc", formatting?.justification ? `<w:jc w:val="${formatting.justification}"/>` : ""],
327
+ ["hidden", serializeOnOffElement(formatting?.hidden, "hidden")],
328
+ structuralChangeEntry("ins", rowStructuralChange),
329
+ structuralChangeEntry("del", rowStructuralChange),
330
+ ["trPrChange", (propertyChanges ?? []).map((change) => serializeTableRowPropertyChange(change)).join("")]
331
+ ],
332
+ preserved: formatting?.preserved
333
+ });
334
+ if (parts.length === 0) return formatting === void 0 ? "" : "<w:trPr/>";
255
335
  return `<w:trPr>${parts.join("")}</w:trPr>`;
256
336
  }
257
337
  function extractTrPrInner(trPrXml) {
@@ -285,37 +365,41 @@ function serializeConditionalFormatStyle(style) {
285
365
  if (val === "000000000000") return "";
286
366
  return `<w:cnfStyle w:val="${val}"/>`;
287
367
  }
368
+ /** `w:vMerge`: no `w:val` is the continuation, so only a restart states one. */
369
+ const serializeVerticalMerge = (vMerge) => {
370
+ if (vMerge === void 0) return "";
371
+ return vMerge === "restart" ? "<w:vMerge w:val=\"restart\"/>" : "<w:vMerge/>";
372
+ };
288
373
  /**
289
374
  * Serialize table cell formatting properties (w:tcPr)
290
375
  */
291
376
  function serializeTableCellFormatting(formatting, propertyChanges, structuralChange) {
377
+ const cellStructuralChange = cellStructuralChangeXml(structuralChange);
292
378
  const cellSource = verifiedSourceXml(formatting, parseTableCellProperties);
293
- if (cellSource !== null) return withRevisionChildren(cellSource, [...cellStructuralChangeXml(structuralChange), ...(propertyChanges ?? []).map((change) => serializeTableCellPropertyChange(change))]);
294
- const parts = [];
295
- if (formatting) {
296
- const cnfStyleXml = serializeConditionalFormatStyle(formatting.conditionalFormat);
297
- if (cnfStyleXml) parts.push(cnfStyleXml);
298
- const widthXml = serializeMeasurement(formatting.width, "tcW");
299
- if (widthXml) parts.push(widthXml);
300
- if (formatting.gridSpan && formatting.gridSpan > 1) parts.push(`<w:gridSpan w:val="${intAttr(formatting.gridSpan)}"/>`);
301
- if (formatting.vMerge) if (formatting.vMerge === "restart") parts.push("<w:vMerge w:val=\"restart\"/>");
302
- else parts.push("<w:vMerge/>");
303
- const bordersXml = serializeTableCellBorders(formatting.borders);
304
- if (bordersXml) parts.push(bordersXml);
305
- const shadingXml = serializeShading(formatting.shading);
306
- if (shadingXml) parts.push(shadingXml);
307
- if (formatting.noWrap) parts.push("<w:noWrap/>");
308
- const marginsXml = serializeCellMargins(formatting.margins, "tcMar");
309
- if (marginsXml) parts.push(marginsXml);
310
- if (formatting.textDirection) parts.push(`<w:textDirection w:val="${formatting.textDirection}"/>`);
311
- if (formatting.fitText) parts.push("<w:tcFitText/>");
312
- if (formatting.verticalAlign) parts.push(`<w:vAlign w:val="${formatting.verticalAlign}"/>`);
313
- if (formatting.hideMark === true) parts.push("<w:hideMark/>");
314
- else if (formatting.hideMark === false) parts.push("<w:hideMark w:val=\"off\"/>");
315
- }
316
- parts.push(...cellStructuralChangeXml(structuralChange));
317
- if (propertyChanges && propertyChanges.length > 0) parts.push(...propertyChanges.map((change) => serializeTableCellPropertyChange(change)));
318
- if (parts.length === 0) return "";
379
+ if (cellSource !== null) return withRevisionChildren(cellSource, [...cellStructuralChange ? [cellStructuralChange.xml] : [], ...(propertyChanges ?? []).map((change) => serializeTableCellPropertyChange(change))]);
380
+ const parts = serializeSequenceChildren({
381
+ container: "cell-properties",
382
+ modelled: [
383
+ ["cnfStyle", serializeConditionalFormatStyle(formatting?.conditionalFormat)],
384
+ ["tcW", serializeMeasurement(formatting?.width, "tcW")],
385
+ ["gridSpan", formatting?.gridSpan && formatting.gridSpan > 1 ? `<w:gridSpan w:val="${intAttr(formatting.gridSpan)}"/>` : ""],
386
+ ["vMerge", serializeVerticalMerge(formatting?.vMerge)],
387
+ ["tcBorders", serializeTableCellBorders(formatting?.borders)],
388
+ ["shd", serializeShading(formatting?.shading)],
389
+ ["noWrap", serializeOnOffElement(formatting?.noWrap, "noWrap")],
390
+ ["tcMar", serializeCellMargins(formatting?.margins, "tcMar")],
391
+ ["textDirection", formatting?.textDirection ? `<w:textDirection w:val="${formatting.textDirection}"/>` : ""],
392
+ ["tcFitText", serializeOnOffElement(formatting?.fitText, "tcFitText")],
393
+ ["vAlign", formatting?.verticalAlign ? `<w:vAlign w:val="${formatting.verticalAlign}"/>` : ""],
394
+ ["hideMark", serializeOnOffElement(formatting?.hideMark, "hideMark")],
395
+ structuralChangeEntry("cellIns", cellStructuralChange),
396
+ structuralChangeEntry("cellDel", cellStructuralChange),
397
+ structuralChangeEntry("cellMerge", cellStructuralChange),
398
+ ["tcPrChange", (propertyChanges ?? []).map((change) => serializeTableCellPropertyChange(change)).join("")]
399
+ ],
400
+ preserved: formatting?.preserved
401
+ });
402
+ if (parts.length === 0) return formatting === void 0 ? "" : "<w:tcPr/>";
319
403
  return `<w:tcPr>${parts.join("")}</w:tcPr>`;
320
404
  }
321
405
  function extractTcPrInner(tcPrXml) {
@@ -324,7 +408,7 @@ function extractTcPrInner(tcPrXml) {
324
408
  }
325
409
  function serializeTableCellPropertyChange(change) {
326
410
  const attrs = serializeTrackedChangeAttributes(change.info);
327
- const previousTcPrInner = extractTcPrInner(serializeTableCellFormatting(change.previousFormatting) || "<w:tcPr/>");
411
+ const previousTcPrInner = extractTcPrInner(serializeTableCellFormatting(change.previousFormatting, void 0, change.previousStructuralChange) || "<w:tcPr/>");
328
412
  return `<w:tcPrChange ${attrs}>${previousTcPrInner.length > 0 ? `<w:tcPr>${previousTcPrInner}</w:tcPr>` : "<w:tcPr/>"}</w:tcPrChange>`;
329
413
  }
330
414
  /**
@@ -353,24 +437,90 @@ function serializeTableGrid(table) {
353
437
  if (gridSourceXml !== void 0) {
354
438
  if (canonicalJson(parseTableGrid(parseXml(gridSourceXml, OOXML_NAMESPACE_SCOPE).elements?.[0] ?? null)) === canonicalJson(columnWidths)) return gridSourceXml;
355
439
  }
356
- const gridChange = replayableGridChangeXml(table.formatting?.gridChangeXml) ?? "";
440
+ const change = table.formatting?.gridChange;
441
+ const gridChange = change === void 0 ? "" : serializeTableGridChange(change);
357
442
  if (columnWidths && columnWidths.length > 0) return `<w:tblGrid>${columnWidths.map((w) => `<w:gridCol w:w="${intAttr(w)}"/>`).join("")}${gridChange}</w:tblGrid>`;
358
443
  const columns = gridColumnCount(table);
359
444
  return columns === 0 && gridChange === "" ? "<w:tblGrid/>" : `<w:tblGrid>${"<w:gridCol/>".repeat(columns)}${gridChange}</w:tblGrid>`;
360
445
  }
361
- const GRID_CHANGE_ROOT_NAME = /* @__PURE__ */ new Set(["tblGridChange"]);
362
- const WORDPROCESSINGML_NAMESPACE = /* @__PURE__ */ new Set([NAMESPACES.w]);
363
- const replayableGridChangeXml = (gridChangeXml) => sanitizeCapturedXmlElement(gridChangeXml, {
364
- allowedLocalNames: GRID_CHANGE_ROOT_NAME,
365
- allowedNamespaceUris: WORDPROCESSINGML_NAMESPACE,
366
- inheritedNamespaceScope: OOXML_NAMESPACE_SCOPE
446
+ /**
447
+ * Serialize `w:tblGridChange`: the grid a reviewer replaced, from the change's
448
+ * own record rather than from the bytes it arrived as.
449
+ *
450
+ * `w:w` is optional on a `w:gridCol`, so a column the snapshot recorded no
451
+ * measure for is written back without one; spelling it as a zero would claim a
452
+ * width the source never stated.
453
+ */
454
+ const serializeTableGridChange = ({ id, columnWidths }) => {
455
+ const columns = columnWidths.map((width) => width === void 0 ? "<w:gridCol/>" : `<w:gridCol w:w="${intAttr(width)}"/>`).join("");
456
+ return `<w:tblGridChange w:id="${intAttr(id)}"><w:tblGrid>${columns}</w:tblGrid></w:tblGridChange>`;
457
+ };
458
+ /**
459
+ * What makes two rows members of the same control.
460
+ *
461
+ * The control's record is on every child it held, so the wrapper is rebuilt
462
+ * by grouping consecutive children that name the same control. Equality is
463
+ * the record's canonical spelling rather than object identity, because the
464
+ * editor carries these records through JSON — a Yjs sync, a snapshot, a
465
+ * structured clone — and hands back an equal record rather than the same one.
466
+ * A wrapper that split in two there would mint a second `w:id` for one
467
+ * control, which is the defect, not the fix.
468
+ *
469
+ * The cost is the other direction: two adjacent rows the author put in two
470
+ * separate but identically spelled controls come back as one. Word mints a
471
+ * distinct `w:id` per control, so that needs a producer that writes none; the
472
+ * inline wrapper stack makes the same trade for the same reason.
473
+ */
474
+ const contentControlKey = (properties) => canonicalJson(properties);
475
+ /**
476
+ * Re-open each control around the run of children that named it, outermost
477
+ * first.
478
+ *
479
+ * @param depth which layer of the stack this call is opening
480
+ */
481
+ const serializeControlledChildren = (children, depth) => {
482
+ const parts = [];
483
+ let index = 0;
484
+ while (index < children.length) {
485
+ const child = children[index];
486
+ const control = child.controls[depth];
487
+ if (control === void 0) {
488
+ parts.push(child.xml);
489
+ index += 1;
490
+ continue;
491
+ }
492
+ const key = contentControlKey(control);
493
+ let end = index + 1;
494
+ while (end < children.length) {
495
+ const next = children[end]?.controls[depth];
496
+ if (next === void 0 || contentControlKey(next) !== key) break;
497
+ end += 1;
498
+ }
499
+ const inner = serializeControlledChildren(children.slice(index, end), depth + 1);
500
+ parts.push(serializeSdtWrapper(control, inner));
501
+ index = end;
502
+ }
503
+ return parts.join("");
504
+ };
505
+ /** A capture from the sink, with the controls it sat inside when parsed. */
506
+ const preservedChild = (xml, child) => ({
507
+ controls: child.contentControls ?? [],
508
+ xml
367
509
  });
368
510
  /**
369
511
  * Serialize cell content (paragraphs, nested tables)
370
512
  */
371
513
  function serializeCellContent(content, serializeParagraph) {
372
- const parts = [];
373
- for (const item of content) parts.push(withBlockRangeMarkers(item, item.type === "paragraph" ? serializeParagraph(item) : serializeTable(item, serializeParagraph)));
514
+ const parts = content.map((block) => {
515
+ switch (block.type) {
516
+ case "paragraph": return serializeParagraph(block);
517
+ case "table": return serializeTable(block, serializeParagraph);
518
+ case "preservedBlock": return block.xml;
519
+ case "bookmarkStart":
520
+ case "bookmarkEnd": return serializeBookmarkMarker(block);
521
+ default: return block;
522
+ }
523
+ });
374
524
  if (parts.length === 0) parts.push("<w:p/>");
375
525
  return parts.join("");
376
526
  }
@@ -385,14 +535,37 @@ function serializeTableCell(cell, serializeParagraph) {
385
535
  return `<w:tc>${parts.join("")}</w:tc>`;
386
536
  }
387
537
  /**
538
+ * A container's verbatim sink and its bookmark markers, as one positioned list.
539
+ *
540
+ * Both stand between the same two modelled children and both record where by
541
+ * counting the ones before them, so one writer puts both back. Two entries
542
+ * recorded at the same index keep their group's order, with the sink's first;
543
+ * the source order between a capture and a bookmark sharing a slot is the one
544
+ * thing an index cannot say, and it changes nothing a reader can see.
545
+ */
546
+ const positionedChildren = (preserved, bookmarks) => {
547
+ if (bookmarks === void 0 || bookmarks.length === 0) return preserved;
548
+ return { children: [...preserved?.children ?? [], ...bookmarks.map(({ index, marker, contentControls }) => ({
549
+ index,
550
+ xml: serializeBookmarkMarker(marker),
551
+ ...contentControls === void 0 ? {} : { contentControls }
552
+ }))] };
553
+ };
554
+ /**
388
555
  * Serialize a table row (w:tr)
389
556
  */
390
557
  function serializeTableRow(row, serializeParagraph) {
391
558
  const parts = [];
559
+ const tblPrExXml = serializeTablePropertyExceptions(row.tablePropertyExceptions, row.tablePropertyExceptionChanges);
560
+ if (tblPrExXml) parts.push(tblPrExXml);
392
561
  const trPrXml = serializeTableRowFormatting(row.formatting, row.propertyChanges, row.structuralChange);
393
562
  if (trPrXml) parts.push(trPrXml);
394
- for (const cell of row.cells) parts.push(serializeTableCell(cell, serializeParagraph));
395
- return `<w:tr>${parts.join("")}</w:tr>`;
563
+ parts.push(serializeControlledChildren(withPreservedChildren(row.cells.map((cell) => ({
564
+ controls: cell.contentControls ?? [],
565
+ xml: serializeTableCell(cell, serializeParagraph)
566
+ })), positionedChildren(row.preserved, row.bookmarks), preservedChild), 0));
567
+ const attrs = serializePreservedAttributes([], row.preservedAttributes);
568
+ return `<w:tr${attrs.length > 0 ? ` ${attrs.join(" ")}` : ""}>${parts.join("")}</w:tr>`;
396
569
  }
397
570
  /**
398
571
  * Serialize a table to OOXML XML (w:tbl)
@@ -401,9 +574,14 @@ function serializeTableRow(row, serializeParagraph) {
401
574
  * @returns XML string for the table
402
575
  */
403
576
  function serializeTable(table, serializeParagraph) {
404
- const parts = [serializeTableFormatting(table.formatting, table.propertyChanges) || "<w:tblPr/>", serializeTableGrid(table)];
405
- for (const row of table.rows) parts.push(serializeTableRow(row, serializeParagraph));
406
- return `<w:tbl>${parts.join("")}</w:tbl>`;
577
+ return `<w:tbl>${[
578
+ serializeTableFormatting(table.formatting, table.propertyChanges) || "<w:tblPr/>",
579
+ serializeTableGrid(table),
580
+ serializeControlledChildren(withPreservedChildren(table.rows.map((row) => ({
581
+ controls: row.contentControls ?? [],
582
+ xml: serializeTableRow(row, serializeParagraph)
583
+ })), positionedChildren(table.preserved, table.bookmarks), preservedChild), 0)
584
+ ].join("")}</w:tbl>`;
407
585
  }
408
586
  /**
409
587
  * Serialize multiple tables to OOXML XML
@@ -1,16 +1,40 @@
1
1
  import { document_d_exports } from "../../types/document.js";
2
+ import { DeclaredChild } from "../containerChildren.gen.js";
2
3
  //#region src/docx/serializer/textFormattingSerializer.d.ts
3
- type ClassifiedShadingField = "color" | "fill" | "pattern";
4
+ type ClassifiedShadingField = "color" | "fill" | "pattern" | "preservedAttributes";
4
5
  type ExhaustiveShadingProperties = document_d_exports.ExhaustiveFields<document_d_exports.ShadingProperties, ClassifiedShadingField>;
5
- type ClassifiedTextFormattingField = "bold" | "boldCs" | "italic" | "italicCs" | "underline" | "strike" | "doubleStrike" | "vertAlign" | "smallCaps" | "allCaps" | "hidden" | "noProof" | "color" | "highlight" | "shading" | "fontSize" | "fontSizeCs" | "fontFamily" | "language" | "spacing" | "position" | "scale" | "kerning" | "effect" | "emphasisMark" | "emboss" | "imprint" | "outline" | "shadow" | "rtl" | "cs" | "styleId";
6
+ type ClassifiedTextFormattingField = "bold" | "boldCs" | "italic" | "italicCs" | "underline" | "strike" | "doubleStrike" | "vertAlign" | "smallCaps" | "allCaps" | "hidden" | "noProof" | "color" | "highlight" | "shading" | "fontSize" | "fontSizeCs" | "fontFamily" | "language" | "spacing" | "position" | "scale" | "kerning" | "effect" | "emphasisMark" | "emboss" | "imprint" | "outline" | "shadow" | "rtl" | "cs" | "styleId" | "preserved";
6
7
  type ExhaustiveTextFormatting = document_d_exports.ExhaustiveFields<document_d_exports.TextFormatting, ClassifiedTextFormattingField>;
8
+ /**
9
+ * A child of this `w:rPr` that another record owns, named by its declared
10
+ * child so the sequence places it.
11
+ *
12
+ * A run's `w:rPrChange` and the paragraph mark's revision and `w:specVanish`
13
+ * are read by the run's and the paragraph's own records, so they arrive here
14
+ * as markup rather than as a field. Naming each one means the schema decides
15
+ * where it goes, exactly as it does for the modelled children.
16
+ */
17
+ type OwnedRunPropertyChild = readonly [name: DeclaredChild<"run-properties">, xml: string];
7
18
  /**
8
19
  * Serialize shading properties (w:shd)
9
20
  */
10
21
  declare function serializeShading(shading: ExhaustiveShadingProperties | undefined): string;
11
22
  /**
12
- * Serialize text formatting properties to w:rPr XML
23
+ * The single `w:rPr` writer.
24
+ *
25
+ * A run, the paragraph mark, a style, a numbering level and the snapshot
26
+ * inside either kind of `w:rPrChange` all write their run properties through
27
+ * here, so none of them can grow its own order or its own idea of which
28
+ * children exist. `EG_RPrBase` is an `xsd:choice` referenced
29
+ * `maxOccurs="unbounded"`, so a `w:rPr` in any order is valid and the order
30
+ * below is a canonical form rather than a validity rule: it is the one Word
31
+ * writes, and writing it from the generated declared-child list is what stops
32
+ * two of folio's serializers from disagreeing. The restatement is what
33
+ * drifted, and it is why folio wrote `w:vanish` before `w:noProof` while the
34
+ * schema declares the reverse.
35
+ *
36
+ * @param owned children a sibling record holds; see {@link OwnedRunPropertyChild}
13
37
  */
14
- declare function serializeTextFormatting(input: ExhaustiveTextFormatting | undefined): string;
38
+ declare function serializeTextFormatting(input: ExhaustiveTextFormatting | undefined, owned?: readonly OwnedRunPropertyChild[]): string;
15
39
  //#endregion
16
40
  export { serializeShading, serializeTextFormatting };