@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,9 +1,14 @@
1
1
  import { isValidHexColor } from "../../utils/colorResolver.js";
2
- import { THEME_COLOR_TO_DRAWING_SCHEME } from "../drawingUtils.js";
2
+ import { normalizeImageLuminancePercent } from "../../utils/imageLuminance.js";
3
+ import { serializePreservedAttributes } from "../attributeRemainder.js";
4
+ import { resolveEffectExtents, resolveWrapDistances, serializeAnchorAttributes, serializeEffectExtent, serializeInlineAttributes, serializeSimplePos, serializeWrapDistances } from "../drawingAnchor.js";
5
+ import { fieldStateAttributes } from "../fieldState.js";
3
6
  import { serializeGraphicFrameLocks } from "../graphicFrameLocks.js";
4
7
  import { DECORATIVE_EXTENSION_URI, DECORATIVE_NAMESPACE } from "../imageParser.js";
5
8
  import { canReplayEditableImageRawXml } from "../imageRawXml.js";
6
9
  import { serializeNonVisualDrawingNames } from "../nonVisualDrawingProps.js";
10
+ import { runHoldsPayload } from "../runPayload.js";
11
+ import { requiredWrapPolygon, serializeWrapPolygon } from "../wrapPolygon.js";
7
12
  import { serializeParagraph } from "./paragraphSerializer.js";
8
13
  import { serializeTable } from "./tableSerializer.js";
9
14
  import { serializeTextFormatting } from "./textFormattingSerializer.js";
@@ -11,6 +16,7 @@ import { getSingularRunPropertyChange, serializeTrackedChangeAttributes } from "
11
16
  import { intAttr } from "./xmlUtils.js";
12
17
  import { panic } from "better-result";
13
18
  import { escapeXmlAttribute, escapeXmlText, requiresXmlSpacePreserve } from "@stll/docx-core";
19
+ import { SCHEME_COLOR_VALUE_BY_THEME_COLOR, knownThemeColor, presetLineDashToken } from "@stll/docx-core/model";
14
20
  //#region src/docx/serializer/runSerializer.ts
15
21
  /**
16
22
  * Run Serializer - Serialize runs to OOXML XML
@@ -41,21 +47,13 @@ function getUniqueId(id) {
41
47
  if (id !== void 0 && id !== "" && id !== 0) return String(id);
42
48
  return String(nextAutoId++);
43
49
  }
44
- function extractRPrInner(rPrXml) {
45
- if (!rPrXml.startsWith("<w:rPr>") || !rPrXml.endsWith("</w:rPr>")) return "";
46
- return rPrXml.slice(7, -8);
47
- }
48
50
  function serializeRunPropertyChange(change) {
49
51
  const previousRPrXml = serializeTextFormatting(change.previousFormatting) || "<w:rPr/>";
50
52
  return `<w:rPrChange ${serializeTrackedChangeAttributes(change.info)}>${previousRPrXml}</w:rPrChange>`;
51
53
  }
52
54
  function serializeRunProperties(formatting, propertyChanges) {
53
- const currentRPrXml = serializeTextFormatting(formatting);
54
- const currentInner = currentRPrXml ? extractRPrInner(currentRPrXml) : "";
55
55
  const propertyChange = getSingularRunPropertyChange(propertyChanges);
56
- const combined = `${currentInner}${propertyChange ? serializeRunPropertyChange(propertyChange) : ""}`;
57
- if (!combined) return "";
58
- return `<w:rPr>${combined}</w:rPr>`;
56
+ return serializeTextFormatting(formatting, propertyChange ? [["rPrChange", serializeRunPropertyChange(propertyChange)]] : []);
59
57
  }
60
58
  /**
61
59
  * Serialize text content (w:t)
@@ -103,10 +101,7 @@ function serializeNoteReference(content) {
103
101
  * Serialize field character (w:fldChar)
104
102
  */
105
103
  function serializeFieldChar(content) {
106
- const attrs = [`w:fldCharType="${content.charType}"`];
107
- if (content.fldLock) attrs.push("w:fldLock=\"true\"");
108
- if (content.dirty) attrs.push("w:dirty=\"true\"");
109
- return `<w:fldChar ${attrs.join(" ")}/>`;
104
+ return `<w:fldChar ${[`w:fldCharType="${content.charType}"`, ...fieldStateAttributes(content)].join(" ")}/>`;
110
105
  }
111
106
  /**
112
107
  * Serialize field instruction text (w:instrText)
@@ -130,8 +125,10 @@ function serializeNoBreakHyphen(_content) {
130
125
  function serializeDrawingColor(color) {
131
126
  if (!color) return "";
132
127
  if (color.rgb && isValidHexColor(color.rgb)) return `<a:srgbClr val="${escapeXmlAttribute(color.rgb.replace("#", ""))}"/>`;
133
- if (color.themeColor) {
134
- let clr = `<a:schemeClr val="${THEME_COLOR_TO_DRAWING_SCHEME[color.themeColor]}"`;
128
+ const themeColor = color.themeColor && knownThemeColor(color.themeColor);
129
+ const schemeColor = themeColor ? SCHEME_COLOR_VALUE_BY_THEME_COLOR[themeColor] : null;
130
+ if (schemeColor !== null) {
131
+ let clr = `<a:schemeClr val="${schemeColor}"`;
135
132
  if (color.themeTint) clr += `><a:tint val="${escapeXmlAttribute(color.themeTint)}"/></a:schemeClr>`;
136
133
  else if (color.themeShade) clr += `><a:shade val="${escapeXmlAttribute(color.themeShade)}"/></a:schemeClr>`;
137
134
  else clr += `/>`;
@@ -171,7 +168,7 @@ function serializeOutline(outline) {
171
168
  if (outline.cap) attrs.push(`cap="${serializeLineCap(outline.cap)}"`);
172
169
  const parts = [];
173
170
  if (outline.color) parts.push(`<a:solidFill>${serializeDrawingColor(outline.color)}</a:solidFill>`);
174
- if (outline.style) parts.push(`<a:prstDash val="${outline.style}"/>`);
171
+ if (outline.dash) parts.push(`<a:prstDash val="${escapeXmlAttribute(presetLineDashToken(outline.dash))}"/>`);
175
172
  if (outline.join === "bevel") parts.push("<a:bevel/>");
176
173
  else if (outline.join === "round") parts.push("<a:round/>");
177
174
  else if (outline.join === "miter") parts.push("<a:miter/>");
@@ -195,20 +192,77 @@ function serializePosition(pos) {
195
192
  parts.push("</wp:positionV>");
196
193
  return parts.join("");
197
194
  }
195
+ /**
196
+ * The insets each `EG_WrapType` member's own type declares.
197
+ *
198
+ * Total over the wrap kinds, so a kind added to the model has to say which of
199
+ * the four its element may carry. A key this map does not list cannot be
200
+ * written on that element without failing the schema, whatever the drawing's
201
+ * slots hold.
202
+ */
203
+ const WRAP_CHILD_DISTANCE_KEYS = {
204
+ square: [
205
+ "distT",
206
+ "distB",
207
+ "distL",
208
+ "distR"
209
+ ],
210
+ tight: ["distL", "distR"],
211
+ through: ["distL", "distR"],
212
+ topAndBottom: ["distT", "distB"],
213
+ behind: [],
214
+ inFront: [],
215
+ inline: []
216
+ };
217
+ /**
218
+ * Which `EG_WrapType` members declare a `wp:effectExtent` of their own.
219
+ *
220
+ * Total over the wrap kinds for {@link WRAP_CHILD_DISTANCE_KEYS}'s reason: a
221
+ * kind added to the model has to say whether its element may carry one, and
222
+ * writing it where the type does not declare it fails the schema.
223
+ */
224
+ const WRAP_CHILD_DECLARES_EFFECT_EXTENT = {
225
+ square: true,
226
+ tight: false,
227
+ through: false,
228
+ topAndBottom: true,
229
+ behind: false,
230
+ inFront: false,
231
+ inline: false
232
+ };
198
233
  /** Serialize wrap type to wp:wrap* element */
199
- function serializeWrap(wrap) {
234
+ function serializeWrap(wrap, effectExtent) {
200
235
  const wrapText = wrap.wrapText ? ` wrapText="${wrap.wrapText}"` : " wrapText=\"bothSides\"";
236
+ const authored = resolveWrapDistances(wrap).wrapChild;
237
+ const distances = {};
238
+ for (const key of WRAP_CHILD_DISTANCE_KEYS[wrap.type]) {
239
+ const value = authored[key];
240
+ if (value !== void 0) distances[key] = value;
241
+ }
242
+ const dist = serializeWrapDistances(distances);
243
+ const extent = effectExtent !== void 0 && WRAP_CHILD_DECLARES_EFFECT_EXTENT[wrap.type] ? serializeEffectExtent(effectExtent) : "";
201
244
  switch (wrap.type) {
202
- case "square": return `<wp:wrapSquare${wrapText}/>`;
203
- case "tight": return `<wp:wrapTight${wrapText}><wp:wrapPolygon edited="0"><wp:start x="0" y="0"/><wp:lineTo x="0" y="21600"/><wp:lineTo x="21600" y="21600"/><wp:lineTo x="21600" y="0"/><wp:lineTo x="0" y="0"/></wp:wrapPolygon></wp:wrapTight>`;
204
- case "through": return `<wp:wrapThrough${wrapText}><wp:wrapPolygon edited="0"><wp:start x="0" y="0"/><wp:lineTo x="0" y="21600"/><wp:lineTo x="21600" y="21600"/><wp:lineTo x="21600" y="0"/><wp:lineTo x="0" y="0"/></wp:wrapPolygon></wp:wrapThrough>`;
205
- case "topAndBottom": return "<wp:wrapTopAndBottom/>";
245
+ case "square": return extent ? `<wp:wrapSquare${wrapText}${dist}>${extent}</wp:wrapSquare>` : `<wp:wrapSquare${wrapText}${dist}/>`;
246
+ case "tight": return `<wp:wrapTight${wrapText}${dist}>${serializeWrapPolygon(requiredWrapPolygon(wrap.polygon))}</wp:wrapTight>`;
247
+ case "through": return `<wp:wrapThrough${wrapText}${dist}>${serializeWrapPolygon(requiredWrapPolygon(wrap.polygon))}</wp:wrapThrough>`;
248
+ case "topAndBottom": return extent ? `<wp:wrapTopAndBottom${dist}>${extent}</wp:wrapTopAndBottom>` : `<wp:wrapTopAndBottom${dist}/>`;
206
249
  case "behind":
207
250
  case "inFront": return "<wp:wrapNone/>";
208
251
  case "inline": return "<wp:wrapNone/>";
209
252
  }
210
253
  }
211
254
  /**
255
+ * `a:xfrm` attributes for an authored transform.
256
+ *
257
+ * Written iff authored: `rot="0"` and `flipH="0"` are OOXML's defaults, so a
258
+ * truthiness guard cannot tell "the author said none" from "the author said
259
+ * nothing", and a save erased an authored zero.
260
+ */
261
+ const serializeTransformAttrs = (transform) => {
262
+ if (transform === void 0) return "";
263
+ return `${transform.rotation === void 0 ? "" : ` rot="${Math.round(transform.rotation * 6e4)}"`}${transform.flipH === void 0 ? "" : ` flipH="${transform.flipH ? 1 : 0}"`}${transform.flipV === void 0 ? "" : ` flipV="${transform.flipV ? 1 : 0}"`}`;
264
+ };
265
+ /**
212
266
  * Build the common a:graphic > pic:pic element for images.
213
267
  *
214
268
  * Takes the relationship id as a separate argument so the caller has to have
@@ -220,25 +274,28 @@ function serializePicGraphic(image, imageRId, sharedId) {
220
274
  const cy = image.size.height;
221
275
  const rId = escapeXmlAttribute(imageRId);
222
276
  const id = sharedId;
223
- const name = image.filename || `image${id}`;
224
- let xfrmAttrs = "";
225
- if (image.transform?.rotation) xfrmAttrs += ` rot="${Math.round(image.transform.rotation * 6e4)}"`;
226
- if (image.transform?.flipH) xfrmAttrs += " flipH=\"1\"";
227
- if (image.transform?.flipV) xfrmAttrs += " flipV=\"1\"";
277
+ const picNames = serializeNonVisualDrawingNames({
278
+ ...image.pictureNames,
279
+ name: image.pictureNames?.name ?? image.filename ?? `image${id}`
280
+ });
281
+ const xfrmAttrs = serializeTransformAttrs(image.transform);
228
282
  const cropAttrs = [];
229
283
  if (image.crop?.left) cropAttrs.push(`l="${Math.round(image.crop.left * 1e5)}"`);
230
284
  if (image.crop?.top) cropAttrs.push(`t="${Math.round(image.crop.top * 1e5)}"`);
231
285
  if (image.crop?.right) cropAttrs.push(`r="${Math.round(image.crop.right * 1e5)}"`);
232
286
  if (image.crop?.bottom) cropAttrs.push(`b="${Math.round(image.crop.bottom * 1e5)}"`);
233
287
  const srcRectEl = cropAttrs.length > 0 ? `<a:srcRect ${cropAttrs.join(" ")}/>` : "";
234
- const alphaChild = image.opacity !== void 0 && image.opacity < 1 ? `<a:alphaModFix amt="${Math.round(Math.max(0, image.opacity) * 1e5)}"/>` : "";
235
- const blipEl = alphaChild ? `<a:blip r:embed="${rId}">${alphaChild}</a:blip>` : `<a:blip r:embed="${rId}"/>`;
288
+ const luminanceAttrs = [];
289
+ if (image.effects?.brightness !== void 0 && Number.isFinite(image.effects.brightness)) luminanceAttrs.push(`bright="${Math.round(normalizeImageLuminancePercent(image.effects.brightness) * 1e3)}"`);
290
+ if (image.effects?.contrast !== void 0 && Number.isFinite(image.effects.contrast)) luminanceAttrs.push(`contrast="${Math.round(normalizeImageLuminancePercent(image.effects.contrast) * 1e3)}"`);
291
+ const blipChildren = `${luminanceAttrs.length === 0 ? "" : `<a:lum ${luminanceAttrs.join(" ")}/>`}${image.opacity !== void 0 && image.opacity < 1 ? `<a:alphaModFix amt="${Math.round(Math.max(0, image.opacity) * 1e5)}"/>` : ""}`;
292
+ const blipEl = blipChildren ? `<a:blip r:embed="${rId}">${blipChildren}</a:blip>` : `<a:blip r:embed="${rId}"/>`;
236
293
  return [
237
294
  "<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">",
238
295
  "<a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">",
239
296
  "<pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">",
240
297
  "<pic:nvPicPr>",
241
- `<pic:cNvPr id="${id}" name="${escapeXmlAttribute(name)}"${image.alt ? ` descr="${escapeXmlAttribute(image.alt)}"` : ""}/>`,
298
+ `<pic:cNvPr id="${id}"${picNames}/>`,
242
299
  "<pic:cNvPicPr/>",
243
300
  "</pic:nvPicPr>",
244
301
  "<pic:blipFill>",
@@ -260,18 +317,6 @@ function serializePicGraphic(image, imageRId, sharedId) {
260
317
  ].join("");
261
318
  }
262
319
  /**
263
- * Serialize only authored wrap-distance attributes. OOXML defaults omitted
264
- * values to zero, but preserving absence keeps untouched models stable.
265
- */
266
- function serializeWrapDistanceAttrs(wrap) {
267
- const attrs = [];
268
- if (wrap?.distT !== void 0) attrs.push(`distT="${intAttr(wrap.distT)}"`);
269
- if (wrap?.distB !== void 0) attrs.push(`distB="${intAttr(wrap.distB)}"`);
270
- if (wrap?.distL !== void 0) attrs.push(`distL="${intAttr(wrap.distL)}"`);
271
- if (wrap?.distR !== void 0) attrs.push(`distR="${intAttr(wrap.distR)}"`);
272
- return attrs.length > 0 ? ` ${attrs.join(" ")}` : "";
273
- }
274
- /**
275
320
  * Serialize the `wp:docPr` extension list.
276
321
  *
277
322
  * The decorative flag is the one extension folio models; every other `a:ext`
@@ -285,6 +330,23 @@ function serializeDocPrExtensions(image) {
285
330
  return entries ? `<a:extLst>${entries}</a:extLst>` : "";
286
331
  }
287
332
  /**
333
+ * Serialize `wp:docPr`'s two link children, in the order the schema declares.
334
+ *
335
+ * The click element is replayed from the source while the model still names the
336
+ * target it named, which keeps `tooltip`, `tgtFrame`, `history` and the rest of
337
+ * `CT_Hyperlink` that the model has no field for. A link the editor retargeted
338
+ * no longer agrees with those bytes, so it is rebuilt from the target instead —
339
+ * the alternative is writing a tooltip that points somewhere else. The hover
340
+ * element has no modelled half to disagree with it, so it always replays.
341
+ */
342
+ function serializeDocPrLinks(image) {
343
+ const hover = image.hlinkHoverXml ?? "";
344
+ const source = image.hlinkClickSource;
345
+ if (source !== void 0 && source.rId === image.hlinkRId) return `${source.xml}${hover}`;
346
+ if (image.hlinkRId === void 0) return hover;
347
+ return `<a:hlinkClick r:id="${escapeXmlAttribute(image.hlinkRId)}"/>${hover}`;
348
+ }
349
+ /**
288
350
  * Serialize drawing/image content (w:drawing) to full DrawingML XML
289
351
  */
290
352
  function serializeDrawingContent(content) {
@@ -292,19 +354,15 @@ function serializeDrawingContent(content) {
292
354
  const isFloating = image.wrap.type !== "inline";
293
355
  const cx = image.size.width;
294
356
  const cy = image.size.height;
295
- const wrapDistanceAttrs = serializeWrapDistanceAttrs(image.wrap);
296
- const effL = image.padding?.left ?? 0;
297
- const effT = image.padding?.top ?? 0;
298
- const effR = image.padding?.right ?? 0;
299
- const effB = image.padding?.bottom ?? 0;
300
- const effectExtentEl = `<wp:effectExtent l="${intAttr(effL)}" t="${intAttr(effT)}" r="${intAttr(effR)}" b="${intAttr(effB)}"/>`;
357
+ const effectExtents = resolveEffectExtents(image.wrap, image.padding);
358
+ const effectExtentEl = serializeEffectExtent(effectExtents.drawing);
301
359
  const docPrId = getUniqueId(image.id);
302
360
  const docPrNames = serializeNonVisualDrawingNames({
303
361
  ...image.docPrName !== void 0 ? { name: image.docPrName } : {},
304
362
  ...image.alt !== void 0 ? { alt: image.alt } : {},
305
363
  ...image.title !== void 0 ? { title: image.title } : {}
306
364
  });
307
- const hlinkClick = image.hlinkRId ? `<a:hlinkClick r:id="${escapeXmlAttribute(image.hlinkRId)}"/>` : "";
365
+ const hlinkClick = serializeDocPrLinks(image);
308
366
  const docPrAttrs = `id="${docPrId}"${docPrNames}${image.hidden === void 0 ? "" : ` hidden="${image.hidden ? "1" : "0"}"`}`;
309
367
  const docPrChildren = `${hlinkClick}${serializeDocPrExtensions(image)}`;
310
368
  const docPr = docPrChildren ? `<wp:docPr ${docPrAttrs}>${docPrChildren}</wp:docPr>` : `<wp:docPr ${docPrAttrs}/>`;
@@ -312,7 +370,7 @@ function serializeDrawingContent(content) {
312
370
  const graphic = image.rId === void 0 ? "" : serializePicGraphic(image, image.rId, docPrId);
313
371
  if (!isFloating) return [
314
372
  "<w:drawing>",
315
- `<wp:inline${wrapDistanceAttrs}>`,
373
+ `<wp:inline${serializeInlineAttributes(image.wrap)}>`,
316
374
  `<wp:extent cx="${intAttr(cx)}" cy="${intAttr(cy)}"/>`,
317
375
  effectExtentEl,
318
376
  docPr,
@@ -321,13 +379,16 @@ function serializeDrawingContent(content) {
321
379
  "</wp:inline>",
322
380
  "</w:drawing>"
323
381
  ].join("");
324
- const behindDoc = image.wrap.type === "behind" ? "1" : "0";
325
382
  const position = image.position ? serializePosition(image.position) : "<wp:positionH relativeFrom=\"column\"><wp:posOffset>0</wp:posOffset></wp:positionH><wp:positionV relativeFrom=\"paragraph\"><wp:posOffset>0</wp:posOffset></wp:positionV>";
326
- const wrap = serializeWrap(image.wrap);
383
+ const wrap = serializeWrap(image.wrap, effectExtents.wrapChild);
327
384
  return [
328
385
  "<w:drawing>",
329
- `<wp:anchor${wrapDistanceAttrs} simplePos="0" relativeHeight="251658240" behindDoc="${behindDoc}" locked="0" layoutInCell="${image.layoutInCell === false ? "0" : "1"}" allowOverlap="${image.allowOverlap === false ? "0" : "1"}">`,
330
- "<wp:simplePos x=\"0\" y=\"0\"/>",
386
+ `<wp:anchor${serializeAnchorAttributes({
387
+ anchor: image.anchor,
388
+ wrap: image.wrap,
389
+ behindDoc: image.wrap.type === "behind"
390
+ })}>`,
391
+ serializeSimplePos(image.anchor),
331
392
  position,
332
393
  `<wp:extent cx="${intAttr(cx)}" cy="${intAttr(cy)}"/>`,
333
394
  effectExtentEl,
@@ -366,20 +427,16 @@ function serializeShapeContent(content) {
366
427
  const cy = shape.size.height;
367
428
  const isTextBox = shape.shapeType === "textBox";
368
429
  const isFloating = shape.wrap && shape.wrap.type !== "inline";
369
- const wrapDistances = serializeWrapDistanceAttrs(shape.wrap);
370
430
  const docPrId = getUniqueId(shape.id);
371
431
  const docPrNames = serializeNonVisualDrawingNames({
372
432
  ...shape.name !== void 0 ? { name: shape.name } : {},
373
433
  ...shape.alt !== void 0 ? { alt: shape.alt } : {},
374
434
  ...shape.title !== void 0 ? { title: shape.title } : {}
375
435
  });
376
- let xfrmAttrs = "";
377
- if (shape.transform?.rotation) xfrmAttrs += ` rot="${Math.round(shape.transform.rotation * 6e4)}"`;
378
- if (shape.transform?.flipH) xfrmAttrs += " flipH=\"1\"";
379
- if (shape.transform?.flipV) xfrmAttrs += " flipV=\"1\"";
436
+ const shapeNames = shape.shapeNames === void 0 ? "" : `<wps:cNvPr id="${docPrId}"${serializeNonVisualDrawingNames(shape.shapeNames)}/>`;
380
437
  const spPr = [
381
438
  "<wps:spPr>",
382
- `<a:xfrm${xfrmAttrs}>`,
439
+ `<a:xfrm${serializeTransformAttrs(shape.transform)}>`,
383
440
  "<a:off x=\"0\" y=\"0\"/>",
384
441
  `<a:ext cx="${intAttr(cx)}" cy="${intAttr(cy)}"/>`,
385
442
  "</a:xfrm>",
@@ -421,6 +478,7 @@ function serializeShapeContent(content) {
421
478
  "<a:graphicData uri=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">",
422
479
  [
423
480
  "<wps:wsp>",
481
+ shapeNames,
424
482
  `<wps:cNvSpPr${isTextBox ? " txBox=\"1\"" : ""}/>`,
425
483
  spPr,
426
484
  textBody === "" ? "<wps:bodyPr/>" : textBody,
@@ -429,28 +487,32 @@ function serializeShapeContent(content) {
429
487
  "</a:graphicData>",
430
488
  "</a:graphic>"
431
489
  ].join("");
490
+ const shapeEffectExtents = resolveEffectExtents(shape.wrap, shape.wrap?.effectExtentSlots?.drawing);
432
491
  if (!isFloating) return [
433
492
  "<w:drawing>",
434
- `<wp:inline${wrapDistances}>`,
493
+ `<wp:inline${serializeInlineAttributes(shape.wrap)}>`,
435
494
  `<wp:extent cx="${intAttr(cx)}" cy="${intAttr(cy)}"/>`,
436
- "<wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/>",
495
+ serializeEffectExtent(shapeEffectExtents.drawing),
437
496
  `<wp:docPr id="${docPrId}"${docPrNames}/>`,
438
497
  "<wp:cNvGraphicFramePr/>",
439
498
  graphic,
440
499
  "</wp:inline>",
441
500
  "</w:drawing>"
442
501
  ].join("");
443
- const behindDoc = shape.wrap?.type === "behind" ? "1" : "0";
444
502
  const position = shape.position ? serializePosition(shape.position) : "<wp:positionH relativeFrom=\"column\"><wp:posOffset>0</wp:posOffset></wp:positionH><wp:positionV relativeFrom=\"paragraph\"><wp:posOffset>0</wp:posOffset></wp:positionV>";
445
503
  if (!shape.wrap) panic("Floating shape must have a wrap property");
446
- const wrap = serializeWrap(shape.wrap);
504
+ const wrap = serializeWrap(shape.wrap, shapeEffectExtents.wrapChild);
447
505
  return [
448
506
  "<w:drawing>",
449
- `<wp:anchor${wrapDistances} simplePos="0" relativeHeight="251658240" behindDoc="${behindDoc}" locked="0" layoutInCell="1" allowOverlap="1">`,
450
- "<wp:simplePos x=\"0\" y=\"0\"/>",
507
+ `<wp:anchor${serializeAnchorAttributes({
508
+ anchor: shape.anchor,
509
+ wrap: shape.wrap,
510
+ behindDoc: shape.wrap.type === "behind"
511
+ })}>`,
512
+ serializeSimplePos(shape.anchor),
451
513
  position,
452
514
  `<wp:extent cx="${intAttr(cx)}" cy="${intAttr(cy)}"/>`,
453
- "<wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/>",
515
+ serializeEffectExtent(shapeEffectExtents.drawing),
454
516
  wrap,
455
517
  `<wp:docPr id="${docPrId}"${docPrNames}/>`,
456
518
  "<wp:cNvGraphicFramePr/>",
@@ -475,6 +537,7 @@ function serializeRunContent(content) {
475
537
  case "softHyphen": return serializeSoftHyphen(content);
476
538
  case "noBreakHyphen": return serializeNoBreakHyphen(content);
477
539
  case "renderedPageBreak": return "<w:lastRenderedPageBreak/>";
540
+ case "preservedXml": return content.xml;
478
541
  case "drawing":
479
542
  if (content.rawXml && canReplayEditableImageRawXml(content)) return content.rawXml;
480
543
  return serializeDrawingContent(content);
@@ -489,6 +552,7 @@ function serializeRunContent(content) {
489
552
  * @returns XML string for the run
490
553
  */
491
554
  function serializeRun(run) {
555
+ if (!runHoldsPayload(run)) return "";
492
556
  const parts = [];
493
557
  const rPrXml = serializeRunProperties(run.formatting, run.propertyChanges);
494
558
  if (rPrXml) parts.push(rPrXml);
@@ -496,7 +560,8 @@ function serializeRun(run) {
496
560
  const contentXml = serializeRunContent(content);
497
561
  if (contentXml) parts.push(contentXml);
498
562
  }
499
- return `<w:r>${parts.join("")}</w:r>`;
563
+ const attrs = serializePreservedAttributes([], run.preservedAttributes);
564
+ return `<w:r${attrs.length > 0 ? ` ${attrs.join(" ")}` : ""}>${parts.join("")}</w:r>`;
500
565
  }
501
566
  /**
502
567
  * Serialize multiple runs to OOXML XML
@@ -508,12 +573,6 @@ function serializeRuns(runs) {
508
573
  return runs.map(serializeRun).join("");
509
574
  }
510
575
  /**
511
- * Check if a run has any content
512
- */
513
- function hasRunContent(run) {
514
- return run.content.length > 0;
515
- }
516
- /**
517
576
  * Check if a run has formatting
518
577
  */
519
578
  function hasRunFormatting(run) {
@@ -571,4 +630,4 @@ function createTabRun(formatting) {
571
630
  };
572
631
  }
573
632
  //#endregion
574
- export { createBreakRun, createEmptyRun, createTabRun, createTextRun, getRunPlainText, hasRunContent, hasRunFormatting, resetAutoIdCounter, serializeRun, serializeRuns };
633
+ export { createBreakRun, createEmptyRun, createTabRun, createTextRun, getRunPlainText, hasRunFormatting, resetAutoIdCounter, serializeRun, serializeRuns };
@@ -0,0 +1,26 @@
1
+ import { document_d_exports } from "../../types/document.js";
2
+ //#region src/docx/serializer/sdtPropertiesSerializer.d.ts
3
+ /**
4
+ * `<w:sdtPr>` from the model: the modelled children, the preserved ones, in
5
+ * schema order.
6
+ *
7
+ * An empty property set is written as an empty element rather than left out.
8
+ * `<w:sdtPr/>` and no `w:sdtPr` at all are different documents — the first is
9
+ * a richText control that states nothing, the second is markup the schema does
10
+ * not admit under `w:sdt` — and folio used to write the second for both.
11
+ */
12
+ declare const serializeSdtProperties: (props: document_d_exports.SdtProperties) => string;
13
+ /**
14
+ * `w:sdtEndPr`, replayed when the parse captured it and written from the
15
+ * record otherwise.
16
+ *
17
+ * The record's presence is the element's: `<w:sdtEndPr/>` with no `w:rPr` is
18
+ * what Word writes for most controls and differs from a missing element.
19
+ */
20
+ declare const serializeSdtEndProperties: (properties: document_d_exports.SdtProperties) => string;
21
+ /** `w:sdtPr` followed by `w:sdtEndPr`, in schema order. */
22
+ declare const serializeSdtPropertyElements: (properties: document_d_exports.SdtProperties) => string;
23
+ /** The one writer of an SDT wrapper at every content-model level. */
24
+ declare const serializeSdtWrapper: (properties: document_d_exports.SdtProperties, contentXml: string) => string;
25
+ //#endregion
26
+ export { serializeSdtEndProperties, serializeSdtProperties, serializeSdtPropertyElements, serializeSdtWrapper };
@@ -0,0 +1,111 @@
1
+ import { statesControlKind } from "../sdtProperties.js";
2
+ import { withModelledControlState } from "../sdtPropertiesPatch.js";
3
+ import { serializeTextFormatting } from "./textFormattingSerializer.js";
4
+ import { isSingleWellFormedElement } from "./xmlUtils.js";
5
+ import { escapeXmlAttribute, serializeOnOffElement } from "@stll/docx-core";
6
+ import { assertSafePreservedMarkup, serializeSequenceChildren } from "@stll/docx-core/schema";
7
+ //#region src/docx/serializer/sdtPropertiesSerializer.ts
8
+ /**
9
+ * The one writer of `<w:sdtPr>`.
10
+ *
11
+ * Every content control — block, inline, row and cell — writes its property
12
+ * set here. There used to be three producers: a fallback projection on the
13
+ * block path, a second one on the inline path, and a regex pass over the
14
+ * source's captured bytes that patched an interactive change back into them.
15
+ * The three agreed on nothing in particular, and the patching pass existed
16
+ * only because the replay was the serialization source.
17
+ *
18
+ * It is not any more. `parseSdtProperties` puts every child folio does not
19
+ * model into `SdtProperties.preserved` at its `CT_SdtPr` ordinal, so the model
20
+ * holds the whole element and the writer merges its two halves back in schema
21
+ * order — which `CT_SdtPr` demands, and Word repairs a file that disregards.
22
+ */
23
+ const listElement = (name, props) => {
24
+ return `<w:${name}${props.dropdownLastValue === void 0 ? "" : ` w:lastValue="${escapeXmlAttribute(props.dropdownLastValue)}"`}>${(props.listItems ?? []).map((item) => `<w:listItem w:displayText="${escapeXmlAttribute(item.displayText)}" w:value="${escapeXmlAttribute(item.value)}"/>`).join("")}</w:${name}>`;
25
+ };
26
+ /**
27
+ * The kind marker for a control that carries none of its own.
28
+ *
29
+ * Only reached for a control built in code rather than parsed: a parsed one
30
+ * keeps the element its author wrote, in the sink, glyph elements and all.
31
+ * `richText` is the format's default and `unknown` is folio's word for a kind
32
+ * it could not read, so neither writes a marker — a bare `w:sdtPr` already
33
+ * means richText.
34
+ *
35
+ * A checkbox has no declared kind element at all: `w14:checkbox` is an
36
+ * extension the Transitional content model does not know, so it is filed
37
+ * under the slot the kind choice occupies, which is where Word writes it.
38
+ */
39
+ const synthesizedKind = (props) => {
40
+ switch (props.sdtType) {
41
+ case "plainText": return ["text", "<w:text/>"];
42
+ case "date": return ["date", `<w:date${props.dateValueISO ? ` w:fullDate="${escapeXmlAttribute(props.dateValueISO)}"` : ""}>${props.dateFormat ? `<w:dateFormat w:val="${escapeXmlAttribute(props.dateFormat)}"/>` : ""}</w:date>`];
43
+ case "dropdown": return ["dropDownList", listElement("dropDownList", props)];
44
+ case "comboBox": return ["comboBox", listElement("comboBox", props)];
45
+ case "checkbox": return ["equation", `<w14:checkbox><w14:checked w14:val="${props.checked ? "1" : "0"}"/></w14:checkbox>`];
46
+ case "picture": return ["picture", "<w:picture/>"];
47
+ case "buildingBlockGallery": return ["docPartObj", "<w:docPartObj/>"];
48
+ case "group": return ["group", "<w:group/>"];
49
+ case "richText":
50
+ case "unknown": return ["richText", ""];
51
+ default: return props.sdtType;
52
+ }
53
+ };
54
+ /**
55
+ * `<w:sdtPr>` from the model: the modelled children, the preserved ones, in
56
+ * schema order.
57
+ *
58
+ * An empty property set is written as an empty element rather than left out.
59
+ * `<w:sdtPr/>` and no `w:sdtPr` at all are different documents — the first is
60
+ * a richText control that states nothing, the second is markup the schema does
61
+ * not admit under `w:sdt` — and folio used to write the second for both.
62
+ */
63
+ const serializeSdtProperties = (props) => {
64
+ assertSafePreservedMarkup(props.preserved);
65
+ const modelled = [];
66
+ if (props.alias !== void 0) modelled.push(["alias", `<w:alias w:val="${escapeXmlAttribute(props.alias)}"/>`]);
67
+ if (props.tag !== void 0) modelled.push(["tag", `<w:tag w:val="${escapeXmlAttribute(props.tag)}"/>`]);
68
+ if (props.id !== void 0) modelled.push(["id", `<w:id w:val="${props.id}"/>`]);
69
+ if (props.lock !== void 0) modelled.push(["lock", `<w:lock w:val="${props.lock}"/>`]);
70
+ if (props.placeholder !== void 0) modelled.push(["placeholder", `<w:placeholder><w:docPart w:val="${escapeXmlAttribute(props.placeholder)}"/></w:placeholder>`]);
71
+ if (props.showingPlaceholder !== void 0) modelled.push(["showingPlcHdr", serializeOnOffElement(props.showingPlaceholder, "showingPlcHdr")]);
72
+ const captured = props.preserved?.children ?? [];
73
+ let statedKind = false;
74
+ const preserved = captured.map((child) => {
75
+ if (!statesControlKind(child.xml)) return child;
76
+ statedKind = true;
77
+ return {
78
+ index: child.index,
79
+ xml: withModelledControlState(child.xml, props)
80
+ };
81
+ });
82
+ if (!statedKind) modelled.push(synthesizedKind(props));
83
+ const body = serializeSequenceChildren({
84
+ container: "content-control-properties",
85
+ modelled,
86
+ preserved: props.preserved === void 0 ? void 0 : { children: preserved }
87
+ }).join("");
88
+ return body.length === 0 ? "<w:sdtPr/>" : `<w:sdtPr>${body}</w:sdtPr>`;
89
+ };
90
+ /**
91
+ * `w:sdtEndPr`, replayed when the parse captured it and written from the
92
+ * record otherwise.
93
+ *
94
+ * The record's presence is the element's: `<w:sdtEndPr/>` with no `w:rPr` is
95
+ * what Word writes for most controls and differs from a missing element.
96
+ */
97
+ const serializeSdtEndProperties = (properties) => {
98
+ if (properties.rawEndPropertiesXml && isSingleWellFormedElement(properties.rawEndPropertiesXml, "sdtEndPr")) return properties.rawEndPropertiesXml;
99
+ const endProperties = properties.endProperties;
100
+ if (endProperties === void 0) return "";
101
+ const runProperties = serializeTextFormatting(endProperties.runProperties);
102
+ return runProperties.length > 0 ? `<w:sdtEndPr>${runProperties}</w:sdtEndPr>` : "<w:sdtEndPr/>";
103
+ };
104
+ /** `w:sdtPr` followed by `w:sdtEndPr`, in schema order. */
105
+ const serializeSdtPropertyElements = (properties) => `${serializeSdtProperties(properties)}${serializeSdtEndProperties(properties)}`;
106
+ /** The one writer of an SDT wrapper at every content-model level. */
107
+ const serializeSdtWrapper = (properties, contentXml) => {
108
+ return `<w:sdt>${serializeSdtPropertyElements(properties)}${properties.rawSdtChildrenBeforeContent ?? ""}<w:sdtContent>${contentXml}</w:sdtContent>${properties.rawSdtChildrenAfterContent ?? ""}</w:sdt>`;
109
+ };
110
+ //#endregion
111
+ export { serializeSdtEndProperties, serializeSdtProperties, serializeSdtPropertyElements, serializeSdtWrapper };