@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
@@ -0,0 +1,5 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ //#region src/docx/runPayload.d.ts
3
+ declare const runHoldsPayload: (run: document_d_exports.Run) => boolean;
4
+ //#endregion
5
+ export { runHoldsPayload };
@@ -0,0 +1,4 @@
1
+ //#region src/docx/runPayload.ts
2
+ const runHoldsPayload = (run) => run.content.length > 0;
3
+ //#endregion
4
+ export { runHoldsPayload };
@@ -1,14 +1,48 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
2
  import { XmlElement } from "./xmlParser.js";
3
3
  //#region src/docx/sdtProperties.d.ts
4
+ /**
5
+ * One preserved `w:sdtPr` child by local name, as the source wrote it.
6
+ *
7
+ * The name is resolved, never a spelling: a producer may bind the w14 URI to
8
+ * any prefix, and the local name is what tells `w14:checkbox` from a run's
9
+ * `w:color`, because `CT_SdtPr` declares neither name twice.
10
+ */
11
+ declare const preservedSdtChild: (preserved: document_d_exports.PreservedMarkup | undefined, localName: string) => string | undefined;
12
+ /** The same set without that child, or `undefined` when nothing is left. */
13
+ declare const withoutPreservedSdtChild: (preserved: document_d_exports.PreservedMarkup | undefined, localName: string) => document_d_exports.PreservedMarkup | undefined;
14
+ /**
15
+ * Whether one preserved child is the element that states the control kind.
16
+ *
17
+ * The writer synthesises a kind marker only when the sink holds none, so a
18
+ * control folio parsed keeps the one its author wrote and a control built in
19
+ * code still gets one; and it is this child, not the whole set, that the
20
+ * modelled interactive state is written back into.
21
+ */
22
+ declare const statesControlKind: (xml: string) => boolean;
23
+ /**
24
+ * Direct children of `w:sdt` that sit outside `w:sdtContent`, split by side.
25
+ *
26
+ * Word writes range markers there. A same-named element from another
27
+ * namespace is not one of the structural WordprocessingML children, so it is
28
+ * captured rather than mistaken for `w:sdtPr`, `w:sdtEndPr`, or
29
+ * `w:sdtContent`.
30
+ */
31
+ declare const captureSdtSiblingMarkers: (sdt: XmlElement) => {
32
+ before: string;
33
+ after: string;
34
+ };
4
35
  /**
5
36
  * Parse `<w:sdtPr>` (and optional `<w:sdtEndPr>`) into {@link SdtProperties}.
6
37
  *
7
- * Modeled fields drive addressing / template tooling; `rawPropertiesXml`
8
- * and `rawEndPropertiesXml` carry the original bytes for the serializer to
9
- * replay unchanged, so the projection only needs to handle what we
10
- * actually consume — unmodeled markers are not silently dropped.
38
+ * Modelled fields drive addressing and template tooling. Everything else —
39
+ * the control-kind element, `w:dataBinding`, `w:label`, `w:tabIndex`,
40
+ * `w:temporary`, `w:rPr`, and every extension-namespace child — lands in
41
+ * {@link SdtProperties.preserved} at its schema ordinal. A modelled child
42
+ * whose value the reader refuses lands there too: `keptUnless` decides by the
43
+ * outcome, because a map keyed by name cannot list the values a reader will
44
+ * not admit.
11
45
  */
12
46
  declare function parseSdtProperties(sdtPr: XmlElement | null | undefined, sdtEndPr?: XmlElement | null | undefined): document_d_exports.SdtProperties;
13
47
  //#endregion
14
- export { parseSdtProperties };
48
+ export { captureSdtSiblingMarkers, parseSdtProperties, preservedSdtChild, statesControlKind, withoutPreservedSdtChild };
@@ -1,6 +1,8 @@
1
+ import { CAPTURE, dispatchChildren, keptUnless, sequencePositions } from "./containerChildren.js";
1
2
  import { SdtLockSchema, narrowEnum } from "./parserEnums.js";
3
+ import { RUN_PROPERTY_OWNERS, parseRunProperties } from "./runParser.js";
2
4
  import { captureVerbatimXml } from "./verbatimCapture.js";
3
- import { findChild, getAttributeAnyPrefix, getLocalName, parseBooleanElement } from "./xmlParser.js";
5
+ import { WORDPROCESSINGML_NAMESPACE_URIS, findChild, findChildByLocalName, getAttributeAnyPrefix, getLocalName, parseBooleanElement } from "./xmlParser.js";
4
6
  //#region src/docx/sdtProperties.ts
5
7
  function parseListItems(el) {
6
8
  const items = [];
@@ -192,100 +194,219 @@ function rewriteOpenTagAttrPrefixes(raw, canonical, local) {
192
194
  return pieces.join("");
193
195
  }
194
196
  /**
197
+ * The `w:sdtPr` children that state which kind of control this is.
198
+ *
199
+ * They are the choice that closes `CT_SdtPr`, so at most one may appear, and
200
+ * every one of them is kept as bytes rather than rebuilt: `w:date` carries a
201
+ * calendar and a locale, `w:docPartObj` a gallery and a category, `w:text` a
202
+ * `@w:multiLine`, and `w14:checkbox` its two glyph elements — none of which
203
+ * {@link SdtProperties} has a field for. The handler reads the projection
204
+ * folio does model off the element and hands the element itself back, so the
205
+ * kind survives an edit whole.
206
+ *
207
+ * `checkbox` is `w14:` and the Transitional graph does not declare it, so it
208
+ * is listed separately: the dispatcher reaches it through `undeclared` and it
209
+ * cannot be bound to the generated child set.
210
+ */
211
+ const CONTROL_KIND_CHILDREN = [
212
+ "equation",
213
+ "comboBox",
214
+ "date",
215
+ "docPartObj",
216
+ "docPartList",
217
+ "dropDownList",
218
+ "picture",
219
+ "richText",
220
+ "text",
221
+ "citation",
222
+ "group",
223
+ "bibliography"
224
+ ];
225
+ const CHECKBOX_CHILD = "checkbox";
226
+ /**
227
+ * The local name of a captured fragment's root element.
228
+ *
229
+ * The fragments in the sink are folio's own output — `captureVerbatimXml`
230
+ * serialises one element and materialises its namespace bindings — so the
231
+ * start tag is the first thing in the string and reading its name off the
232
+ * front is exact rather than a guess about arbitrary markup.
233
+ */
234
+ const capturedRootName = (xml) => /^<(?:[\w.-]+:)?(?<local>[\w.-]+)/u.exec(xml)?.groups?.["local"];
235
+ /**
236
+ * One preserved `w:sdtPr` child by local name, as the source wrote it.
237
+ *
238
+ * The name is resolved, never a spelling: a producer may bind the w14 URI to
239
+ * any prefix, and the local name is what tells `w14:checkbox` from a run's
240
+ * `w:color`, because `CT_SdtPr` declares neither name twice.
241
+ */
242
+ const preservedSdtChild = (preserved, localName) => preserved?.children?.find(({ xml }) => capturedRootName(xml) === localName)?.xml;
243
+ /** The same set without that child, or `undefined` when nothing is left. */
244
+ const withoutPreservedSdtChild = (preserved, localName) => {
245
+ const children = (preserved?.children ?? []).filter(({ xml }) => capturedRootName(xml) !== localName);
246
+ return children.length === 0 ? void 0 : { children };
247
+ };
248
+ /**
249
+ * Whether one preserved child is the element that states the control kind.
250
+ *
251
+ * The writer synthesises a kind marker only when the sink holds none, so a
252
+ * control folio parsed keeps the one its author wrote and a control built in
253
+ * code still gets one; and it is this child, not the whole set, that the
254
+ * modelled interactive state is written back into.
255
+ */
256
+ const statesControlKind = (xml) => {
257
+ const root = capturedRootName(xml);
258
+ return root !== void 0 && (root === CHECKBOX_CHILD || CONTROL_KIND_CHILDREN.some((name) => name === root));
259
+ };
260
+ /**
261
+ * Direct children of `w:sdt` that sit outside `w:sdtContent`, split by side.
262
+ *
263
+ * Word writes range markers there. A same-named element from another
264
+ * namespace is not one of the structural WordprocessingML children, so it is
265
+ * captured rather than mistaken for `w:sdtPr`, `w:sdtEndPr`, or
266
+ * `w:sdtContent`.
267
+ */
268
+ const captureSdtSiblingMarkers = (sdt) => {
269
+ const beforeParts = [];
270
+ const afterParts = [];
271
+ let sawContent = false;
272
+ for (const child of sdt.elements ?? []) {
273
+ if (child.type !== "element" || !child.name) continue;
274
+ const local = getLocalName(child.name);
275
+ const isWordprocessingChild = WORDPROCESSINGML_NAMESPACE_URIS.has(child.namespaceUri ?? "");
276
+ if (isWordprocessingChild && (local === "sdtPr" || local === "sdtEndPr")) continue;
277
+ if (isWordprocessingChild && local === "sdtContent") {
278
+ sawContent = true;
279
+ continue;
280
+ }
281
+ const xml = captureVerbatimXml(child);
282
+ if (sawContent) afterParts.push(xml);
283
+ else beforeParts.push(xml);
284
+ }
285
+ return {
286
+ before: beforeParts.join(""),
287
+ after: afterParts.join("")
288
+ };
289
+ };
290
+ /**
195
291
  * Parse `<w:sdtPr>` (and optional `<w:sdtEndPr>`) into {@link SdtProperties}.
196
292
  *
197
- * Modeled fields drive addressing / template tooling; `rawPropertiesXml`
198
- * and `rawEndPropertiesXml` carry the original bytes for the serializer to
199
- * replay unchanged, so the projection only needs to handle what we
200
- * actually consume — unmodeled markers are not silently dropped.
293
+ * Modelled fields drive addressing and template tooling. Everything else —
294
+ * the control-kind element, `w:dataBinding`, `w:label`, `w:tabIndex`,
295
+ * `w:temporary`, `w:rPr`, and every extension-namespace child — lands in
296
+ * {@link SdtProperties.preserved} at its schema ordinal. A modelled child
297
+ * whose value the reader refuses lands there too: `keptUnless` decides by the
298
+ * outcome, because a map keyed by name cannot list the values a reader will
299
+ * not admit.
201
300
  */
202
301
  function parseSdtProperties(sdtPr, sdtEndPr) {
203
302
  const props = { sdtType: "richText" };
204
303
  if (sdtPr) {
205
- props.rawPropertiesXml = normalizeWordPrefix(captureVerbatimXml(sdtPr), sdtPr);
206
- for (const el of sdtPr.elements ?? []) {
207
- if (el.type !== "element") continue;
208
- const name = el.name ? getLocalName(el.name) : "";
209
- switch (name) {
210
- case "id": {
211
- const raw = getAttributeAnyPrefix(el, "val");
212
- if (raw !== null) {
213
- const n = Number.parseInt(raw, 10);
214
- if (!Number.isNaN(n)) props.id = n;
215
- }
216
- break;
217
- }
218
- case "alias": {
219
- const aliasVal = getAttributeAnyPrefix(el, "val");
220
- if (aliasVal !== null) props.alias = aliasVal;
221
- break;
222
- }
223
- case "tag": {
224
- const tagVal = getAttributeAnyPrefix(el, "val");
225
- if (tagVal !== null) props.tag = tagVal;
226
- break;
227
- }
228
- case "lock":
229
- props.lock = narrowEnum(getAttributeAnyPrefix(el, "val"), SdtLockSchema) ?? "unlocked";
230
- break;
231
- case "placeholder": {
232
- const docPart = findChild(el, "w", "docPart");
233
- if (docPart) {
234
- const phVal = getAttributeAnyPrefix(docPart, "val");
235
- if (phVal !== null) props.placeholder = phVal;
236
- }
237
- break;
238
- }
239
- case "showingPlcHdr":
240
- props.showingPlaceholder = parseBooleanElement(el, "w");
241
- break;
242
- case "text":
243
- props.sdtType = "plainText";
244
- break;
245
- case "date": {
304
+ /** Read a projection off a control-kind element, and keep the element. */
305
+ const kind = (read) => (element) => {
306
+ read(element);
307
+ return CAPTURE;
308
+ };
309
+ const preserved = dispatchChildren({
310
+ element: sdtPr,
311
+ container: "content-control-properties",
312
+ handlers: {
313
+ rPr: CAPTURE,
314
+ alias: (element) => {
315
+ const value = getAttributeAnyPrefix(element, "val");
316
+ if (value !== null) props.alias = value;
317
+ return keptUnless(value !== null);
318
+ },
319
+ tag: (element) => {
320
+ const value = getAttributeAnyPrefix(element, "val");
321
+ if (value !== null) props.tag = value;
322
+ return keptUnless(value !== null);
323
+ },
324
+ id: (element) => {
325
+ const raw = getAttributeAnyPrefix(element, "val");
326
+ const value = raw === null ? NaN : Number.parseInt(raw, 10);
327
+ if (!Number.isNaN(value)) props.id = value;
328
+ return keptUnless(!Number.isNaN(value));
329
+ },
330
+ lock: (element) => {
331
+ const value = narrowEnum(getAttributeAnyPrefix(element, "val"), SdtLockSchema);
332
+ if (value !== void 0) props.lock = value;
333
+ return keptUnless(value !== void 0);
334
+ },
335
+ placeholder: (element) => {
336
+ const value = getAttributeAnyPrefix(findChild(element, "w", "docPart"), "val");
337
+ if (value !== null) props.placeholder = value;
338
+ return keptUnless(value !== null);
339
+ },
340
+ temporary: CAPTURE,
341
+ showingPlcHdr: (element) => {
342
+ props.showingPlaceholder = parseBooleanElement(element, "w");
343
+ },
344
+ dataBinding: CAPTURE,
345
+ label: CAPTURE,
346
+ tabIndex: CAPTURE,
347
+ equation: kind(() => {}),
348
+ comboBox: kind((element) => {
349
+ props.sdtType = "comboBox";
350
+ props.listItems = parseListItems(element);
351
+ readLastValue(element, props);
352
+ }),
353
+ date: kind((element) => {
246
354
  props.sdtType = "date";
247
- const dateFormatEl = findChild(el, "w", "dateFormat");
248
- if (dateFormatEl) {
249
- const fmt = getAttributeAnyPrefix(dateFormatEl, "val");
250
- if (fmt !== null) props.dateFormat = fmt;
251
- }
252
- const fullDate = getAttributeAnyPrefix(el, "fullDate");
355
+ const format = getAttributeAnyPrefix(findChild(element, "w", "dateFormat"), "val");
356
+ if (format !== null) props.dateFormat = format;
357
+ const fullDate = getAttributeAnyPrefix(element, "fullDate");
253
358
  if (fullDate !== null) props.dateValueISO = fullDate;
254
- break;
255
- }
256
- case "dropDownList":
257
- case "comboBox": {
258
- props.sdtType = name === "dropDownList" ? "dropdown" : "comboBox";
259
- props.listItems = parseListItems(el);
260
- const lastValue = getAttributeAnyPrefix(el, "lastValue");
261
- if (lastValue !== null) props.dropdownLastValue = lastValue;
262
- break;
263
- }
264
- case "checkbox": {
265
- props.sdtType = "checkbox";
266
- const checked14 = findChild(el, "w14", "checked");
267
- const checkedW = findChild(el, "w", "checked");
268
- if (checked14) props.checked = parseBooleanElement(checked14, "w14");
269
- else if (checkedW) props.checked = parseBooleanElement(checkedW, "w");
270
- else props.checked = false;
271
- break;
272
- }
273
- case "picture":
274
- props.sdtType = "picture";
275
- break;
276
- case "docPartObj":
277
- case "docPartList":
359
+ }),
360
+ docPartObj: kind(() => {
361
+ props.sdtType = "buildingBlockGallery";
362
+ }),
363
+ docPartList: kind(() => {
278
364
  props.sdtType = "buildingBlockGallery";
279
- break;
280
- case "group":
365
+ }),
366
+ dropDownList: kind((element) => {
367
+ props.sdtType = "dropdown";
368
+ props.listItems = parseListItems(element);
369
+ readLastValue(element, props);
370
+ }),
371
+ picture: kind(() => {
372
+ props.sdtType = "picture";
373
+ }),
374
+ richText: kind(() => {}),
375
+ text: kind(() => {
376
+ props.sdtType = "plainText";
377
+ }),
378
+ citation: kind(() => {}),
379
+ group: kind(() => {
281
380
  props.sdtType = "group";
282
- break;
283
- default: break;
284
- }
285
- }
381
+ }),
382
+ bibliography: kind(() => {})
383
+ },
384
+ capturePosition: sequencePositions("content-control-properties", sdtPr),
385
+ undeclared: { [CHECKBOX_CHILD]: kind((element) => {
386
+ props.sdtType = "checkbox";
387
+ const state = findChild(element, "w14", "checked") ?? findChild(element, "w", "checked");
388
+ props.checked = state === null ? false : parseBooleanElement(state, "w14");
389
+ }) }
390
+ });
391
+ if (preserved !== void 0) props.preserved = preserved;
392
+ }
393
+ if (sdtEndPr) {
394
+ props.rawEndPropertiesXml = normalizeWordPrefix(captureVerbatimXml(sdtEndPr), sdtEndPr);
395
+ const runProperties = parseRunProperties(findChildByLocalName(sdtEndPr, "rPr"), null, RUN_PROPERTY_OWNERS.standalone);
396
+ props.endProperties = runProperties === void 0 ? {} : { runProperties };
286
397
  }
287
- if (sdtEndPr) props.rawEndPropertiesXml = normalizeWordPrefix(captureVerbatimXml(sdtEndPr), sdtEndPr);
288
398
  return props;
289
399
  }
400
+ /**
401
+ * The value a producer last chose, from the list element's `@w:lastValue`.
402
+ *
403
+ * `""` is a value a producer can author, so presence is the test rather than
404
+ * truthiness: "never selected", "cleared" and "selected" are three states and
405
+ * the body's display text is evidence for none of them.
406
+ */
407
+ function readLastValue(element, props) {
408
+ const lastValue = getAttributeAnyPrefix(element, "lastValue");
409
+ if (lastValue !== null) props.dropdownLastValue = lastValue;
410
+ }
290
411
  //#endregion
291
- export { parseSdtProperties };
412
+ export { captureSdtSiblingMarkers, parseSdtProperties, preservedSdtChild, statesControlKind, withoutPreservedSdtChild };
@@ -1,15 +1,11 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
2
  //#region src/docx/sdtPropertiesPatch.d.ts
3
3
  /**
4
- * Rewrite the relevant child elements of `<w:sdtPr>` so the modeled
5
- * properties (checked / dateFormat / fullDate / lastValue / showingPlcHdr)
6
- * agree with the raw XML before it is replayed by the serializer.
4
+ * The control-kind element with the modelled interactive state written in.
7
5
  *
8
- * Pure: returns a new string; the input is not modified.
6
+ * Pure: returns a new string; the input is not modified. A kind the model
7
+ * states nothing interactive about comes back unchanged.
9
8
  */
10
- declare function reconcileRawSdtPr(raw: string, props: document_d_exports.SdtProperties, options?: {
11
- dateFullDate?: string;
12
- dropdownLastValue?: string;
13
- }): string;
9
+ declare const withModelledControlState: (xml: string, props: document_d_exports.SdtProperties) => string;
14
10
  //#endregion
15
- export { reconcileRawSdtPr };
11
+ export { withModelledControlState };
@@ -1,39 +1,32 @@
1
1
  import { escapeXmlAttribute } from "@stll/docx-core";
2
2
  //#region src/docx/sdtPropertiesPatch.ts
3
3
  /**
4
- * Surgical patches for the captured `<w:sdtPr>` XML string.
4
+ * The modelled interactive state, written into the control-kind element.
5
5
  *
6
- * Background. The block-SDT serializer (commit 3) replays
7
- * `properties.rawPropertiesXml` verbatim so unmodeled OOXML markers
8
- * (`w:dataBinding`, `w15:repeatingSection`, custom XML mappings) survive
9
- * a round trip. That replay is correct for unchanged controls but goes
10
- * stale the moment the editor mutates a modeled property: a user
11
- * toggling a checkbox, picking a date, or choosing a dropdown value
12
- * updates `properties.checked` / `dateFormat` / etc., but the raw
13
- * `w14:checked w14:val="0"` already encoded by the source DOCX stays
14
- * in `rawPropertiesXml` and gets written back on save — Word reopens
15
- * the document with the user's interactive change discarded.
6
+ * `w:date`, `w:dropDownList`, `w:comboBox` and `w14:checkbox` are kept as
7
+ * bytes: each carries children and attributes {@link SdtProperties} has no
8
+ * field for — a calendar and a locale, a gallery, the two checkbox glyphs —
9
+ * and rebuilding one from the model would drop them. But four of their values
10
+ * *are* modelled, because a user changes them: the checkbox state, the bound
11
+ * date, the display format and the chosen list value. The model wins for
12
+ * those four; the element keeps everything else.
16
13
  *
17
- * `reconcileRawSdtPr` walks every modeled field that has an OOXML
18
- * representation inside `<w:sdtPr>` and, if the field is set on the
19
- * model, rewrites the matching element in the raw string. Unmodeled
20
- * markers are untouched, so dataBinding / repeatingSection round-trip
21
- * stays lossless even after the user has mutated the control.
22
- *
23
- * Picked up from upstream eigenpal/docx-editor#661.
14
+ * This is the one place the two halves meet, and it runs inside the one
15
+ * `w:sdtPr` writer rather than beside it.
24
16
  */
25
17
  /**
26
- * Drop any `*:lastValue="…"` attribute (any namespace prefix, or
27
- * unprefixed) from an attribute-list string. We avoid a single greedy
28
- * regex with `\s+` (which lint flags as backtracking-risky) and instead
29
- * scan character-by-character against `lastValue=` while accepting any
30
- * preceding `prefix:`. Without prefix tolerance, a source DOCX that
31
- * binds the Word namespace under a non-`w` prefix
32
- * (`<ns0:dropDownList ns0:lastValue="old">`) would keep the stale
33
- * attribute alongside our freshly-emitted `w:lastValue` on save.
18
+ * Drop one attribute by local name (any namespace prefix, or unprefixed) from
19
+ * an attribute-list string, leaving every other attribute alone.
20
+ *
21
+ * A scan rather than one greedy regex, which lint flags as backtracking-risky.
22
+ * Two things make the rest of the list worth keeping rather than rebuilding:
23
+ * a source that binds the Word namespace under `ns0` writes `ns0:lastValue`,
24
+ * and keeping it beside a freshly emitted one would leave the element with
25
+ * two; and a captured element carries the `xmlns:*` declarations that make it
26
+ * replayable on its own, which a rebuilt attribute list would throw away.
34
27
  */
35
- function stripLastValueAttr(attrs) {
36
- const SUFFIX = "lastValue=";
28
+ function withoutAttr(attrs, localName) {
29
+ const SUFFIX = `${localName}=`;
37
30
  let out = attrs;
38
31
  let searchFrom = 0;
39
32
  while (searchFrom < out.length) {
@@ -46,13 +39,13 @@ function stripLastValueAttr(attrs) {
46
39
  while (nameStart > 0 && /[A-Za-z0-9_-]/u.test(out[nameStart - 1] ?? "")) nameStart -= 1;
47
40
  }
48
41
  if (nameStart === 0 || !/\s/u.test(out[nameStart - 1] ?? "")) {
49
- searchFrom = hitIdx + 10;
42
+ searchFrom = hitIdx + SUFFIX.length;
50
43
  continue;
51
44
  }
52
- const quoteIdx = hitIdx + 10;
45
+ const quoteIdx = hitIdx + SUFFIX.length;
53
46
  const quote = out[quoteIdx];
54
47
  if (quote !== "\"" && quote !== "'") {
55
- searchFrom = hitIdx + 10;
48
+ searchFrom = hitIdx + SUFFIX.length;
56
49
  continue;
57
50
  }
58
51
  const closeIdx = out.indexOf(quote, quoteIdx + 1);
@@ -62,89 +55,52 @@ function stripLastValueAttr(attrs) {
62
55
  }
63
56
  return out;
64
57
  }
58
+ const withCheckedState = (xml, checked) => {
59
+ const val = checked ? "1" : "0";
60
+ const opened = /<(?<prefix>\w+):checked\b[^>]*>[\s\S]*?<\/\w+:checked>/giu;
61
+ if (/<\w+:checked\b[^>]*>[\s\S]*?<\/\w+:checked>/iu.test(xml)) return xml.replaceAll(opened, (_match, prefix) => `<${prefix}:checked ${prefix}:val="${val}"/>`);
62
+ if (/<\w+:checked\b[^>]*\/>/iu.test(xml)) return xml.replaceAll(/<(?<prefix>\w+):checked\b[^>]*\/>/giu, (_match, prefix) => `<${prefix}:checked ${prefix}:val="${val}"/>`);
63
+ return xml.replace(/<(?<prefix>\w+):checkbox\b[^>]*>/iu, (match, prefix) => `${match}<${prefix}:checked ${prefix}:val="${val}"/>`);
64
+ };
65
+ const withDateState = (xml, props) => {
66
+ const fullDate = props.dateValueISO;
67
+ const format = props.dateFormat;
68
+ if (fullDate === void 0 && format === void 0) return xml;
69
+ const attributes = (prefix, matched) => fullDate === void 0 ? matched : `${withoutAttr(matched, "fullDate")} ${prefix}:fullDate="${escapeXmlAttribute(fullDate)}"`;
70
+ const formatChild = (prefix) => format === void 0 ? "" : `<${prefix}:dateFormat ${prefix}:val="${escapeXmlAttribute(format)}"/>`;
71
+ const opened = /<(?<prefix>\w+):date\b(?<attrs>[^>]*)>(?<inner>[\s\S]*?)<\/\w+:date>/iu;
72
+ if (opened.test(xml)) return xml.replace(opened, (_match, prefix, matchedAttrs, inner) => {
73
+ const body = inner.replaceAll(/<\w+:dateFormat\b[^>]*(?:\/>|>[\s\S]*?<\/\w+:dateFormat>)/giu, "");
74
+ return `<${prefix}:date${attributes(prefix, matchedAttrs)}>${formatChild(prefix)}${body}</${prefix}:date>`;
75
+ });
76
+ return xml.replace(/<(?<prefix>\w+):date\b(?<attrs>[^/>]*)\/>/iu, (_match, prefix, matchedAttrs) => `<${prefix}:date${attributes(prefix, matchedAttrs)}>${formatChild(prefix)}</${prefix}:date>`);
77
+ };
78
+ const withLastValue = (xml, lastValue) => {
79
+ const escaped = escapeXmlAttribute(lastValue);
80
+ const opened = /<(?<prefix>\w+):(?<name>dropDownList|comboBox)\b(?<attrs>[^>]*)>(?<inner>[\s\S]*?)<\/\w+:(?:dropDownList|comboBox)>/iu;
81
+ if (opened.test(xml)) return xml.replace(opened, (_match, prefix, name, attrs, inner) => `<${prefix}:${name}${withoutAttr(attrs, "lastValue")} ${prefix}:lastValue="${escaped}">${inner}</${prefix}:${name}>`);
82
+ return xml.replace(/<(?<prefix>\w+):(?<name>dropDownList|comboBox)\b(?<attrs>[^/>]*)\/>/iu, (_match, prefix, name, attrs) => `<${prefix}:${name}${withoutAttr(attrs, "lastValue")} ${prefix}:lastValue="${escaped}"/>`);
83
+ };
65
84
  /**
66
- * Replace or insert a child element inside `<w:sdtPr>...</w:sdtPr>`.
85
+ * The control-kind element with the modelled interactive state written in.
67
86
  *
68
- * - If a matching child already exists (by local name), the whole element
69
- * is replaced verbatim by `replacement` (so attributes / payload come
70
- * from the caller).
71
- * - Otherwise `replacement` is injected just before `</w:sdtPr>` so the
72
- * element ends up as a child of sdtPr, not after it.
87
+ * Pure: returns a new string; the input is not modified. A kind the model
88
+ * states nothing interactive about comes back unchanged.
73
89
  */
74
- function upsertSdtPrChild(raw, localName, replacement) {
75
- const escaped = localName.replaceAll(/[$()*+./?[\\\]^{|}]/gu, "\\$&");
76
- const selfClosing = new RegExp(`<\\w+:${escaped}\\b[^>]*\\/>`, "iu");
77
- const opened = new RegExp(`<\\w+:${escaped}\\b[^>]*>[\\s\\S]*?<\\/\\w+:${escaped}>`, "iu");
78
- if (selfClosing.test(raw)) return raw.replace(selfClosing, replacement);
79
- if (opened.test(raw)) return raw.replace(opened, replacement);
80
- const closing = /<\/(?<prefix>\w+):sdtPr>/iu;
81
- const closingMatch = closing.exec(raw);
82
- if (closingMatch) {
83
- const closingPrefix = closingMatch.groups?.["prefix"];
84
- return raw.replace(closing, `${replacement}</${closingPrefix}:sdtPr>`);
85
- }
86
- const selfClosingPr = /<(?<prefix>\w+):sdtPr(?<attrs>[^/>]*)\/>/iu;
87
- if (selfClosingPr.test(raw)) return raw.replace(selfClosingPr, (_match, prefix, attrs) => `<${prefix}:sdtPr${attrs}>${replacement}</${prefix}:sdtPr>`);
88
- return raw;
89
- }
90
- function setOrRemove(raw, localName, replacementWhenSet) {
91
- if (replacementWhenSet === null) {
92
- const escaped = localName.replaceAll(/[$()*+./?[\\\]^{|}]/gu, "\\$&");
93
- const selfClosing = new RegExp(`<\\w+:${escaped}\\b[^>]*\\/>`, "igu");
94
- const opened = new RegExp(`<\\w+:${escaped}\\b[^>]*>[\\s\\S]*?<\\/\\w+:${escaped}>`, "igu");
95
- return raw.replaceAll(selfClosing, "").replaceAll(opened, "");
90
+ const withModelledControlState = (xml, props) => {
91
+ switch (props.sdtType) {
92
+ case "checkbox": return typeof props.checked === "boolean" ? withCheckedState(xml, props.checked) : xml;
93
+ case "date": return withDateState(xml, props);
94
+ case "dropdown":
95
+ case "comboBox": return props.dropdownLastValue === void 0 ? xml : withLastValue(xml, props.dropdownLastValue);
96
+ case "richText":
97
+ case "plainText":
98
+ case "picture":
99
+ case "buildingBlockGallery":
100
+ case "group":
101
+ case "unknown": return xml;
102
+ default: return props.sdtType;
96
103
  }
97
- return upsertSdtPrChild(raw, localName, replacementWhenSet);
98
- }
99
- /**
100
- * Rewrite the relevant child elements of `<w:sdtPr>` so the modeled
101
- * properties (checked / dateFormat / fullDate / lastValue / showingPlcHdr)
102
- * agree with the raw XML before it is replayed by the serializer.
103
- *
104
- * Pure: returns a new string; the input is not modified.
105
- */
106
- function reconcileRawSdtPr(raw, props, options = {}) {
107
- let next = raw;
108
- if (props.showingPlaceholder === true) next = setOrRemove(next, "showingPlcHdr", "<w:showingPlcHdr/>");
109
- else if (props.showingPlaceholder === false) next = setOrRemove(next, "showingPlcHdr", null);
110
- if (props.sdtType === "checkbox" && typeof props.checked === "boolean") {
111
- const val = props.checked ? "1" : "0";
112
- const checkedOpened = /<(?:\w+):checked\b[^>]*>[\s\S]*?<\/\w+:checked>/iu;
113
- const checkedSelfClosing = /<(?:\w+):checked\b[^>]*\/>/iu;
114
- if (checkedOpened.test(next)) next = next.replaceAll(/<(?<prefix>\w+):checked\b[^>]*>[\s\S]*?<\/\w+:checked>/giu, (_match, prefix) => `<${prefix}:checked ${prefix}:val="${val}"/>`);
115
- else if (checkedSelfClosing.test(next)) next = next.replaceAll(/<(?<prefix>\w+):checked\b[^>]*\/>/giu, (_match, prefix) => `<${prefix}:checked ${prefix}:val="${val}"/>`);
116
- else if (/<\w+:checkbox\b[^>]*>/iu.test(next)) next = next.replace(/<(?<prefix>\w+):checkbox\b[^>]*>/iu, (match, prefix) => `${match}<${prefix}:checked ${prefix}:val="${val}"/>`);
117
- else next = upsertSdtPrChild(next, "checkbox", `<w14:checkbox><w14:checked w14:val="${val}"/></w14:checkbox>`);
118
- }
119
- if (props.sdtType === "date") {
120
- const fullDate = options.dateFullDate;
121
- const dateFormat = props.dateFormat;
122
- if (fullDate !== void 0 || dateFormat !== void 0) {
123
- const wDate = /<(?<prefix>\w+):date\b(?<attrs>[^>]*)>(?<inner>[\s\S]*?)<\/\w+:date>/iu;
124
- const wDateSelf = /<(?<prefix>\w+):date\b(?<attrs>[^/>]*)\/>/iu;
125
- const fullDateAttr = fullDate !== void 0 ? ` w:fullDate="${escapeXmlAttribute(fullDate)}"` : "";
126
- const formatChild = dateFormat !== void 0 ? `<w:dateFormat w:val="${escapeXmlAttribute(dateFormat)}"/>` : "";
127
- if (wDate.test(next)) next = next.replace(wDate, (_match, prefix, matchedAttrs, inner) => {
128
- let body = inner.replaceAll(/<\w+:dateFormat\b[^>]*(?:\/>|>[\s\S]*?<\/\w+:dateFormat>)/giu, "");
129
- if (formatChild) body = `${formatChild}${body}`;
130
- return `<${prefix}:date${fullDate !== void 0 ? fullDateAttr : matchedAttrs}>${body}</${prefix}:date>`;
131
- });
132
- else if (wDateSelf.test(next)) next = next.replace(wDateSelf, (_match, prefix) => `<${prefix}:date${fullDateAttr}>${formatChild}</${prefix}:date>`);
133
- else next = upsertSdtPrChild(next, "date", `<w:date${fullDateAttr}>${formatChild}</w:date>`);
134
- }
135
- }
136
- if ((props.sdtType === "dropdown" || props.sdtType === "comboBox") && options.dropdownLastValue !== void 0) {
137
- const escapedValue = escapeXmlAttribute(options.dropdownLastValue);
138
- const opened = /<(?<prefix>\w+):(?<name>dropDownList|comboBox)\b(?<attrs>[^>]*)>(?<inner>[\s\S]*?)<\/\w+:(?:dropDownList|comboBox)>/iu;
139
- const selfClosing = /<(?<prefix>\w+):(?<name>dropDownList|comboBox)\b(?<attrs>[^/>]*)\/>/iu;
140
- if (opened.test(next)) next = next.replace(opened, (_match, prefix, name, attrs, inner) => {
141
- return `<${prefix}:${name}${stripLastValueAttr(attrs)} ${prefix}:lastValue="${escapedValue}">${inner}</${prefix}:${name}>`;
142
- });
143
- else if (selfClosing.test(next)) next = next.replace(selfClosing, (_match, prefix, name, attrs) => {
144
- return `<${prefix}:${name}${stripLastValueAttr(attrs)} ${prefix}:lastValue="${escapedValue}"/>`;
145
- });
146
- }
147
- return next;
148
- }
104
+ };
149
105
  //#endregion
150
- export { reconcileRawSdtPr };
106
+ export { withModelledControlState };
@@ -2,7 +2,6 @@ import { document_d_exports } from "../types/document.js";
2
2
  import { ParseContext } from "./parseContext.js";
3
3
  import { XmlElement } from "./xmlParser.js";
4
4
  //#region src/docx/sectionParser.d.ts
5
- declare function getUnserializedSectionPropertyChildNames(props: document_d_exports.SectionProperties): readonly string[] | undefined;
6
5
  /**
7
6
  * Parse section properties (w:sectPr)
8
7
  *
@@ -92,4 +91,4 @@ declare function getDefaultSectionProperties(): document_d_exports.SectionProper
92
91
  */
93
92
  declare function mergeSectionProperties(base: document_d_exports.SectionProperties, override: document_d_exports.SectionProperties): document_d_exports.SectionProperties;
94
93
  //#endregion
95
- export { getColumnCount, getContentHeightPixels, getContentWidthPixels, getDefaultSectionProperties, getMarginsPixels, getPageHeightPixels, getPageWidthPixels, getUnserializedSectionPropertyChildNames, hasDifferentFirstPage, hasDifferentOddEven, hasLineNumbers, hasPageBorders, isLandscape, mergeSectionProperties, parseSectionProperties };
94
+ export { getColumnCount, getContentHeightPixels, getContentWidthPixels, getDefaultSectionProperties, getMarginsPixels, getPageHeightPixels, getPageWidthPixels, hasDifferentFirstPage, hasDifferentOddEven, hasLineNumbers, hasPageBorders, isLandscape, mergeSectionProperties, parseSectionProperties };