@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,7 +1,8 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
2
  import { NumberingMap } from "./numberingParser.js";
3
- import { StyleMap } from "./styleParser.js";
3
+ import { ParseContext } from "./parseContext.js";
4
4
  import { XmlElement } from "./xmlParser.js";
5
+ import { StyleMap } from "./styleParser.js";
5
6
  //#region src/docx/textBoxParser.d.ts
6
7
  /**
7
8
  * Extract raw paragraph elements from w:txbxContent
@@ -42,9 +43,10 @@ declare function isShapeTextBox(wsp: XmlElement): boolean;
42
43
  * parseTextBoxContent() separately with the required parsers.
43
44
  *
44
45
  * @param drawingEl - The w:drawing XML element
46
+ * @param context - Where an outline dash outside `ST_PresetLineDashVal` is reported
45
47
  * @returns TextBox object with placeholder content, or null if not a text box
46
48
  */
47
- declare function parseTextBox(drawingEl: XmlElement): document_d_exports.TextBox | null;
49
+ declare function parseTextBox(drawingEl: XmlElement, context?: ParseContext): document_d_exports.TextBox | null;
48
50
  /**
49
51
  * Parse text box content XML element
50
52
  * @param wsp - The wps:wsp element containing the text box
@@ -112,5 +114,28 @@ declare function resolveTextBoxOutlineColor(textBox: document_d_exports.TextBox)
112
114
  * Get outline width in pixels
113
115
  */
114
116
  declare function getTextBoxOutlineWidthPx(textBox: document_d_exports.TextBox): number;
117
+ type TextBoxRunScan = {
118
+ textBoxDrawings: XmlElement[];
119
+ vmlTextBoxes: XmlElement[];
120
+ hasNonTextBoxContent: boolean;
121
+ };
122
+ /**
123
+ * What a run's markup holds for the text-box pass, by kind.
124
+ *
125
+ * Two readers need this answer and they must not drift: the enrichment pass
126
+ * claims these elements, and `parseParagraphContents` has to keep the run they
127
+ * sit in even though the run parses to nothing until the pass fills it. It
128
+ * lives here, with `isTextBoxDrawing` and `parseTextBox`, so there is one.
129
+ */
130
+ type ScanRunForTextBoxDrawingsOptions = {
131
+ xmlRun: XmlElement;
132
+ /**
133
+ * `isVmlPictParsedByRunParser`, passed rather than imported: the run parser
134
+ * reaches this module through the image parsers, so reading it from here
135
+ * would close a cycle.
136
+ */
137
+ claimedByRunParser: (pictElement: XmlElement) => boolean;
138
+ };
139
+ declare const scanRunForTextBoxDrawings: ({ xmlRun, claimedByRunParser }: ScanRunForTextBoxDrawingsOptions) => TextBoxRunScan;
115
140
  //#endregion
116
- export { ParagraphParserFn, TableParserFn, extractTextBoxContentElements, getTextBoxContentElement, getTextBoxDimensionsPx, getTextBoxHeightPx, getTextBoxMarginsPx, getTextBoxOutlineWidthPx, getTextBoxText, getTextBoxWidthPx, hasTextBoxContent, hasTextBoxFill, hasTextBoxOutline, isFloatingTextBox, isShapeTextBox, isTextBoxDrawing, parseTextBox, parseTextBoxContent, parseTextBoxFromShape, resolveTextBoxFillColor, resolveTextBoxOutlineColor };
141
+ export { ParagraphParserFn, ScanRunForTextBoxDrawingsOptions, TableParserFn, TextBoxRunScan, extractTextBoxContentElements, getTextBoxContentElement, getTextBoxDimensionsPx, getTextBoxHeightPx, getTextBoxMarginsPx, getTextBoxOutlineWidthPx, getTextBoxText, getTextBoxWidthPx, hasTextBoxContent, hasTextBoxFill, hasTextBoxOutline, isFloatingTextBox, isShapeTextBox, isTextBoxDrawing, parseTextBox, parseTextBoxContent, parseTextBoxFromShape, resolveTextBoxFillColor, resolveTextBoxOutlineColor, scanRunForTextBoxDrawings };
@@ -1,7 +1,8 @@
1
1
  import { emuToPixels } from "../utils/units.js";
2
- import { parseAnchorPosition, parseAnchorWrap, parseFill, parseOutline, resolveColorValueToHex } from "./drawingUtils.js";
2
+ import { WORDPROCESSING_DRAWING_NAMESPACE_URIS, parseDrawingAnchor } from "./drawingAnchor.js";
3
+ import { parseAnchorPosition, parseAnchorWrap, parseFill, parseInlineWrap, parseOutline, resolveColorValueToHex } from "./drawingUtils.js";
3
4
  import { parseNonVisualDrawingNames } from "./nonVisualDrawingProps.js";
4
- import { findByFullName, findChildByLocalName, findChildByNamespaceUri, findChildrenByLocalName, findChildrenByNamespaceUri, getAttribute, getChildElements, parseNumericAttribute, parseOnOffAttribute } from "./xmlParser.js";
5
+ import { findByFullName, findChildByLocalName, findChildByNamespaceUri, findChildrenByLocalName, findChildrenByNamespaceUri, findDeep, getAttribute, getChildElements, getLocalName, parseNumericAttribute, parseOnOffAttribute } from "./xmlParser.js";
5
6
  //#region src/docx/textBoxParser.ts
6
7
  const DRAWINGML_MAIN_NAMESPACE_URIS = /* @__PURE__ */ new Set(["http://schemas.openxmlformats.org/drawingml/2006/main", "http://purl.oclc.org/ooxml/drawingml/main"]);
7
8
  const WORDPROCESSING_SHAPE_NAMESPACE_URIS = /* @__PURE__ */ new Set(["http://schemas.microsoft.com/office/word/2010/wordprocessingShape"]);
@@ -98,11 +99,17 @@ function parseTextBoxContent(txbxContent, parseParagraph, parseTable, styles, th
98
99
  return blocks;
99
100
  }
100
101
  /**
102
+ * The `wp:inline` or `wp:anchor` a drawing hangs off, resolved by namespace:
103
+ * the `wp` prefix is the producer's choice and a package free to bind the
104
+ * namespace elsewhere writes the same text box.
105
+ */
106
+ const findDrawingContainer = (drawingEl) => findChildByNamespaceUri(drawingEl, WORDPROCESSING_DRAWING_NAMESPACE_URIS, "inline") ?? findChildByNamespaceUri(drawingEl, WORDPROCESSING_DRAWING_NAMESPACE_URIS, "anchor");
107
+ /**
101
108
  * Check if a drawing element contains a text box
102
109
  * Text boxes are shapes with wps:txbx content
103
110
  */
104
111
  function isTextBoxDrawing(drawingEl) {
105
- const container = getChildElements(drawingEl).find((el) => el.name === "wp:inline" || el.name === "wp:anchor");
112
+ const container = findDrawingContainer(drawingEl);
106
113
  if (!container) return false;
107
114
  const graphic = findByFullName(container, "a:graphic");
108
115
  if (!graphic) return false;
@@ -127,12 +134,13 @@ function isShapeTextBox(wsp) {
127
134
  * parseTextBoxContent() separately with the required parsers.
128
135
  *
129
136
  * @param drawingEl - The w:drawing XML element
137
+ * @param context - Where an outline dash outside `ST_PresetLineDashVal` is reported
130
138
  * @returns TextBox object with placeholder content, or null if not a text box
131
139
  */
132
- function parseTextBox(drawingEl) {
133
- const container = getChildElements(drawingEl).find((el) => el.name === "wp:inline" || el.name === "wp:anchor");
140
+ function parseTextBox(drawingEl, context) {
141
+ const container = findDrawingContainer(drawingEl);
134
142
  if (!container) return null;
135
- const isAnchor = container.name === "wp:anchor";
143
+ const isAnchor = getLocalName(container.name) === "anchor";
136
144
  const graphic = findByFullName(container, "a:graphic");
137
145
  if (!graphic) return null;
138
146
  const graphicData = findByFullName(graphic, "a:graphicData");
@@ -151,7 +159,7 @@ function parseTextBox(drawingEl) {
151
159
  const id = docPr ? getAttribute(docPr, null, "id") ?? void 0 : void 0;
152
160
  const names = parseNonVisualDrawingNames(docPr);
153
161
  const fill = parseFill(spPr ?? null);
154
- const outline = parseOutline(spPr ?? null);
162
+ const outline = parseOutline(spPr ?? null, context);
155
163
  const bodyProps = parseBodyProperties(bodyPr ?? null);
156
164
  const textBox = {
157
165
  type: "textBox",
@@ -172,7 +180,9 @@ function parseTextBox(drawingEl) {
172
180
  if (position) textBox.position = position;
173
181
  const wrap = parseAnchorWrap(container);
174
182
  if (wrap) textBox.wrap = wrap;
175
- } else textBox.wrap = { type: "inline" };
183
+ const anchor = parseDrawingAnchor(container);
184
+ if (anchor) textBox.anchor = anchor;
185
+ } else textBox.wrap = parseInlineWrap(container);
176
186
  return textBox;
177
187
  }
178
188
  /**
@@ -290,6 +300,7 @@ const getTextBoxBlockText = (block) => {
290
300
  return runTexts.join("");
291
301
  }
292
302
  if (block.type === "table") return block.rows.map((row) => row.cells.map((cell) => cell.content.map(getTextBoxBlockText).join("\n")).join(" ")).join("\n");
303
+ if (block.type !== "blockSdt") return "";
293
304
  return block.content.map(getTextBoxBlockText).join("\n");
294
305
  };
295
306
  /**
@@ -313,5 +324,54 @@ function getTextBoxOutlineWidthPx(textBox) {
313
324
  if (!textBox.outline?.width) return 0;
314
325
  return emuToPixels(textBox.outline.width);
315
326
  }
327
+ const scanRunForTextBoxDrawings = ({ xmlRun, claimedByRunParser }) => {
328
+ const textBoxDrawings = [];
329
+ const vmlTextBoxes = [];
330
+ let hasNonTextBoxContent = false;
331
+ const visitDrawing = (drawingEl) => {
332
+ if (isTextBoxDrawing(drawingEl)) {
333
+ textBoxDrawings.push(drawingEl);
334
+ return;
335
+ }
336
+ hasNonTextBoxContent = true;
337
+ };
338
+ for (const el of getChildElements(xmlRun)) {
339
+ const name = getLocalName(el.name ?? "");
340
+ if (name === "rPr") continue;
341
+ if (name === "drawing") {
342
+ visitDrawing(el);
343
+ continue;
344
+ }
345
+ if (name === "pict") {
346
+ if (findDeep(el, "v", "textbox") && !claimedByRunParser(el)) vmlTextBoxes.push(el);
347
+ else hasNonTextBoxContent = true;
348
+ continue;
349
+ }
350
+ if (name === "AlternateContent") {
351
+ const branches = getChildElements(el);
352
+ const choice = branches.find((branch) => getLocalName(branch.name ?? "") === "Choice");
353
+ const fallback = branches.find((branch) => getLocalName(branch.name ?? "") === "Fallback");
354
+ const tryBranch = (branch) => {
355
+ if (!branch) return false;
356
+ let found = false;
357
+ for (const innerEl of getChildElements(branch)) if (getLocalName(innerEl.name ?? "") === "drawing") {
358
+ visitDrawing(innerEl);
359
+ found = true;
360
+ }
361
+ return found;
362
+ };
363
+ let foundInBranch = tryBranch(choice);
364
+ if (!foundInBranch) foundInBranch = tryBranch(fallback);
365
+ if (!foundInBranch) hasNonTextBoxContent = true;
366
+ continue;
367
+ }
368
+ hasNonTextBoxContent = true;
369
+ }
370
+ return {
371
+ textBoxDrawings,
372
+ vmlTextBoxes,
373
+ hasNonTextBoxContent
374
+ };
375
+ };
316
376
  //#endregion
317
- export { extractTextBoxContentElements, getTextBoxContentElement, getTextBoxDimensionsPx, getTextBoxHeightPx, getTextBoxMarginsPx, getTextBoxOutlineWidthPx, getTextBoxText, getTextBoxWidthPx, hasTextBoxContent, hasTextBoxFill, hasTextBoxOutline, isFloatingTextBox, isShapeTextBox, isTextBoxDrawing, parseTextBox, parseTextBoxContent, parseTextBoxFromShape, resolveTextBoxFillColor, resolveTextBoxOutlineColor };
377
+ export { extractTextBoxContentElements, getTextBoxContentElement, getTextBoxDimensionsPx, getTextBoxHeightPx, getTextBoxMarginsPx, getTextBoxOutlineWidthPx, getTextBoxText, getTextBoxWidthPx, hasTextBoxContent, hasTextBoxFill, hasTextBoxOutline, isFloatingTextBox, isShapeTextBox, isTextBoxDrawing, parseTextBox, parseTextBoxContent, parseTextBoxFromShape, resolveTextBoxFillColor, resolveTextBoxOutlineColor, scanRunForTextBoxDrawings };
@@ -0,0 +1,13 @@
1
+ import { ParseContext } from "./parseContext.js";
2
+ import { ThemeColorValue } from "@stll/docx-core/model";
3
+ //#region src/docx/themeColorAttribute.d.ts
4
+ type ThemeColorAttributeOptions = {
5
+ /** The attribute as written, or `null` when the element does not carry it. */
6
+ raw: string | null | undefined;
7
+ /** The element the attribute sits on, for the warning's location. */
8
+ element?: string | undefined;
9
+ context?: ParseContext | undefined;
10
+ };
11
+ declare const parseThemeColorAttribute: ({ raw, element, context }: ThemeColorAttributeOptions) => ThemeColorValue | undefined;
12
+ //#endregion
13
+ export { ThemeColorAttributeOptions, parseThemeColorAttribute };
@@ -0,0 +1,24 @@
1
+ import { PARSE_WARNING_CODES, readThemeColor } from "@stll/docx-core/model";
2
+ //#region src/docx/themeColorAttribute.ts
3
+ /**
4
+ * The one reader for a theme-colour attribute.
5
+ *
6
+ * `w:themeColor`, `w:themeFill` and the `w:clrSchemeMapping` values are all
7
+ * `ST_ThemeColor`. Before this the attribute was narrowed against a union that
8
+ * carried DrawingML slot names instead, so `hyperlink` — the token Word writes
9
+ * for a hyperlink's colour — failed to narrow and the attribute was dropped at
10
+ * parse time, taking it out of the next save. The enumeration is now generated
11
+ * from the schema, and a token outside it is captured rather than refused, the
12
+ * way `CT_Border/@w:val` already keeps a style outside `ST_Border`.
13
+ */
14
+ const parseThemeColorAttribute = ({ raw, element, context }) => {
15
+ const value = readThemeColor(raw);
16
+ if (value !== void 0 && typeof value !== "string") context?.warn({
17
+ code: PARSE_WARNING_CODES.unrecognisedThemeColor,
18
+ value: value.raw,
19
+ ...element === void 0 ? {} : { element }
20
+ });
21
+ return value;
22
+ };
23
+ //#endregion
24
+ export { parseThemeColorAttribute };
@@ -1,4 +1,5 @@
1
- import { InlineContentRemovals, visitDocxParagraphs, visitInlineContentSlots } from "./paragraphTraversal.js";
1
+ import { InlineContentRemovals } from "./inlineContentRemovals.js";
2
+ import { visitDocxParagraphs, visitInlineContentSlots } from "./paragraphTraversal.js";
2
3
  import { PARSE_WARNING_CODES } from "@stll/docx-core/model";
3
4
  //#region src/docx/trackedMoveRangeNormalization.ts
4
5
  /** The code this normalisation is reported under, owned here, not at the caller. */
@@ -1,6 +1,7 @@
1
1
  import { bytesToDataUrl } from "../utils/base64.js";
2
2
  import { DOCX_CONTAINER_TYPES, detectDocxContainerType } from "./encryption/containerFormat.js";
3
3
  import { openDocxBuffer } from "./encryption/openEncryptedDocx.js";
4
+ import { decodeXmlBytes } from "./xmlEncoding.js";
4
5
  import { FOLIO_XML_RESOURCE_LIMITS, assertXmlResourceLimits, createXmlPackageBudget } from "./xmlResourceLimits.js";
5
6
  import JSZip from "jszip";
6
7
  //#region src/docx/unzip.ts
@@ -161,13 +162,13 @@ async function unzipDocx(buffer, options = {}) {
161
162
  if (lowerPath.endsWith(".xml") || lowerPath.endsWith(".rels")) {
162
163
  assertEntrySize(path, declaredSize, limits.maxXmlBytes);
163
164
  if (options.extractAllXml === false && !shouldExtractXmlPart(lowerPath)) continue;
164
- extractionTasks.push(() => file.async("text").then((xmlContent) => {
165
- assertExtractedSize(path, xmlContent.length, limits.maxXmlBytes);
165
+ extractionTasks.push(() => file.async("uint8array").then((xmlBytes) => {
166
+ assertExtractedSize(path, xmlBytes.byteLength, limits.maxXmlBytes);
166
167
  return {
167
168
  type: "xml",
168
169
  path,
169
170
  lowerPath,
170
- content: xmlContent
171
+ content: decodeXmlBytes(xmlBytes)
171
172
  };
172
173
  }));
173
174
  } else if (lowerPath.startsWith("word/media/")) {
@@ -456,7 +457,7 @@ function extractFile(content, path) {
456
457
  const file = content.originalZip.file(path);
457
458
  if (!file || !isParsedDocxEntry(path)) return Promise.resolve(null);
458
459
  const lowerPath = path.toLowerCase();
459
- if (lowerPath.endsWith(".xml") || lowerPath.endsWith(".rels")) return file.async("text");
460
+ if (lowerPath.endsWith(".xml") || lowerPath.endsWith(".rels")) return file.async("uint8array").then(decodeXmlBytes);
460
461
  return file.async("arraybuffer");
461
462
  }
462
463
  /**
@@ -5,12 +5,37 @@ import { XmlElement } from "./xmlParser.js";
5
5
  * Whether a `w:pict` that resolved to no image must still be kept verbatim.
6
6
  *
7
7
  * VML has no serializer of its own, so an unresolved `w:pict` is only ever
8
- * preserved or lost. Two owners are excluded: a `v:textbox` belongs to the
9
- * text-box enrichment pass, which rebuilds it as an editable shape, and a
10
- * watermark shape belongs to watermarkParser; preserving either would emit the
11
- * same artwork twice.
8
+ * preserved or lost. One owner is excluded: a `v:textbox` belongs to the
9
+ * text-box enrichment pass, which rebuilds it as an editable shape, and
10
+ * preserving it here as well would emit the same artwork twice.
11
+ *
12
+ * A watermark shape is not a second exclusion. Declining for one was a guess
13
+ * about another module, and `watermarkParser` claims by a far narrower rule
14
+ * than `isWatermarkShape` states: a direct `v:shape` child of a `w:pict`,
15
+ * carrying a non-empty `v:textpath` or a `v:imagedata`, alone in its paragraph,
16
+ * in a header. A `v:oval`, a shape nested in a `v:group`, a shape sharing its
17
+ * paragraph with text, and every `w:pict` in a footer or in the body fall
18
+ * outside it, so their artwork was declined here and claimed by no one. The
19
+ * watermark owner removes its own artwork from the model instead, by emptying
20
+ * the paragraph it detached, so this predicate need not guess who claimed what.
12
21
  */
13
22
  declare function shouldPreserveRawVmlPict(pictElement: XmlElement): boolean;
23
+ /**
24
+ * Whether the run parser turns this `w:pict` into run content of its own.
25
+ *
26
+ * Exactly one owner may represent a `w:pict`: the run parser, whose drawing
27
+ * carries the whole element as captured XML, or the text-box enrichment pass,
28
+ * which rebuilds one `v:textbox` as an editable shape. Two owners write the
29
+ * same artwork twice, and when the pict holds text, the saved document says it
30
+ * twice.
31
+ *
32
+ * The enrichment asks this rather than re-deriving the answer from the markup:
33
+ * its own reading (`v:imagedata` present) named only the picture path, so a
34
+ * `v:group` claimed by the preview path was represented by both owners. The
35
+ * result is a pure function of the element, so asking it a second time costs
36
+ * only the work the run parser already did.
37
+ */
38
+ declare const isVmlPictParsedByRunParser: (pictElement: XmlElement, rels: document_d_exports.RelationshipMap | null, media: Map<string, document_d_exports.MediaFile> | null) => boolean;
14
39
  /**
15
40
  * Parse a `w:pict` element into an inline image, or null when it carries no
16
41
  * ordinary VML picture (no resolvable `<v:imagedata>`, or a watermark shape).
@@ -22,4 +47,4 @@ declare function shouldPreserveRawVmlPict(pictElement: XmlElement): boolean;
22
47
  */
23
48
  declare function parseVmlImageContent(pictElement: XmlElement, rels: document_d_exports.RelationshipMap | null, media: Map<string, document_d_exports.MediaFile> | null, rootXmlns?: Record<string, string>): document_d_exports.DrawingContent | null;
24
49
  //#endregion
25
- export { parseVmlImageContent, shouldPreserveRawVmlPict };
50
+ export { isVmlPictParsedByRunParser, parseVmlImageContent, shouldPreserveRawVmlPict };
@@ -1,12 +1,45 @@
1
1
  import { sanitizeImageSrc } from "../utils/sanitizeImageSrc.js";
2
2
  import { pixelsToEmu } from "../utils/units.js";
3
3
  import { resolveImageData } from "./imageParser.js";
4
+ import { imageRawXmlFingerprint } from "./imageRawXml.js";
4
5
  import { PREVIEW_KINDS } from "./previewBudget.js";
5
6
  import { captureVerbatimXml } from "./verbatimCapture.js";
6
7
  import { isValidVmlPreviewDimension, parseVmlNumber, parseVmlStyle, renderStandaloneVmlPreview, renderVmlGroupPreview, vmlCssLengthToPx, vmlSvgDataUrl } from "./vmlPreview.js";
7
8
  import { isWatermarkShape } from "./watermarkParser.js";
8
9
  import { cloneWithXmlnsDeclarations, findAllDeep, findChild, findDeep, getAttribute, getChildElements, getLocalName } from "./xmlParser.js";
10
+ import { DRAWING_RAW_XML_MODES, relationshipIdOf } from "@stll/docx-core/model";
9
11
  //#region src/docx/vmlImageParser.ts
12
+ /**
13
+ * VML image parser — legacy `w:pict` inline pictures.
14
+ *
15
+ * Older Word documents (and some exporters) embed inline pictures such as
16
+ * header logos as VML instead of DrawingML:
17
+ *
18
+ * <w:r><w:pict>
19
+ * <v:shape id="Picture 1" type="#_x0000_t75" style="width:120pt;height:40pt">
20
+ * <v:imagedata r:id="rId7" o:title="logo"/>
21
+ * </v:shape>
22
+ * </w:pict></w:r>
23
+ *
24
+ * The run parser used to drop `w:pict` entirely, so these pictures never
25
+ * rendered. This resolves `<v:imagedata r:id>` to the same media part a
26
+ * DrawingML image uses and produces the identical `DrawingContent` / `Image`
27
+ * node, so the rest of the pipeline (ProseMirror conversion, layout, painter)
28
+ * renders it through the existing inline-image path.
29
+ *
30
+ * The original VML is preserved verbatim on the returned drawing's `rawXml`:
31
+ * the serializer has no VML synthesis path (it only emits DrawingML), so
32
+ * without this a `w:pict` would round-trip as a `<w:drawing>`. Emitting the
33
+ * captured XML keeps save byte-for-byte for these runs.
34
+ *
35
+ * A watermark `watermarkParser` claimed is detached from its hosting
36
+ * paragraph, so modelling it here as well would paint it twice; the
37
+ * `isWatermarkShape` guard below keeps this reader off that shape. It does not
38
+ * decide whether the markup survives: what nothing claims is preserved
39
+ * verbatim by `shouldPreserveRawVmlPict`.
40
+ *
41
+ * Ported from eigenpal/docx-editor `vmlImageParser.ts`.
42
+ */
10
43
  const VML_POSITION_ABSOLUTE = "absolute";
11
44
  const IMAGE_WRAP_INLINE = "inline";
12
45
  const IMAGE_WRAP_BEHIND = "behind";
@@ -68,31 +101,33 @@ const previewImage = (pictElement, svg, widthPx, heightPx, style, rootXmlns) =>
68
101
  const horizontalRelative = style["mso-position-horizontal-relative"] === "page";
69
102
  const verticalRelative = style["mso-position-vertical-relative"] === "page";
70
103
  const zIndex = parseVmlNumber(style["z-index"]);
71
- return {
72
- type: "drawing",
73
- image: {
74
- type: "image",
75
- rId: "",
76
- src,
77
- mimeType: PREVIEW_KINDS.vmlShape.mimeType,
78
- filename: PREVIEW_KINDS.vmlShape.filename,
79
- size: {
80
- width: pixelsToEmu(widthPx),
81
- height: pixelsToEmu(heightPx)
104
+ const image = {
105
+ type: "image",
106
+ src,
107
+ mimeType: PREVIEW_KINDS.vmlShape.mimeType,
108
+ filename: PREVIEW_KINDS.vmlShape.filename,
109
+ size: {
110
+ width: pixelsToEmu(widthPx),
111
+ height: pixelsToEmu(heightPx)
112
+ },
113
+ wrap: { type: zIndex !== void 0 && zIndex >= 0 ? "inFront" : "behind" },
114
+ position: {
115
+ horizontal: {
116
+ relativeTo: horizontalRelative ? "page" : "character",
117
+ posOffset: pixelsToSafeEmu(leftPx) ?? 0
82
118
  },
83
- wrap: { type: zIndex !== void 0 && zIndex >= 0 ? "inFront" : "behind" },
84
- position: {
85
- horizontal: {
86
- relativeTo: horizontalRelative ? "page" : "character",
87
- posOffset: pixelsToSafeEmu(leftPx) ?? 0
88
- },
89
- vertical: {
90
- relativeTo: verticalRelative ? "page" : "paragraph",
91
- posOffset: pixelsToSafeEmu(topPx) ?? 0
92
- }
119
+ vertical: {
120
+ relativeTo: verticalRelative ? "page" : "paragraph",
121
+ posOffset: pixelsToSafeEmu(topPx) ?? 0
93
122
  }
94
- },
95
- rawXml: captureVerbatimXml(cloneWithXmlnsDeclarations(pictElement, rootXmlns))
123
+ }
124
+ };
125
+ return {
126
+ type: "drawing",
127
+ image,
128
+ rawXml: captureVerbatimXml(cloneWithXmlnsDeclarations(pictElement, rootXmlns)),
129
+ rawImageFingerprint: imageRawXmlFingerprint(image),
130
+ rawXmlMode: DRAWING_RAW_XML_MODES.PREVIEW_ONLY
96
131
  };
97
132
  };
98
133
  const previewDrawing = (pictElement, preview, rootXmlns) => {
@@ -120,17 +155,41 @@ const VML_DRAWABLE_SHAPES = [
120
155
  * Whether a `w:pict` that resolved to no image must still be kept verbatim.
121
156
  *
122
157
  * VML has no serializer of its own, so an unresolved `w:pict` is only ever
123
- * preserved or lost. Two owners are excluded: a `v:textbox` belongs to the
124
- * text-box enrichment pass, which rebuilds it as an editable shape, and a
125
- * watermark shape belongs to watermarkParser; preserving either would emit the
126
- * same artwork twice.
158
+ * preserved or lost. One owner is excluded: a `v:textbox` belongs to the
159
+ * text-box enrichment pass, which rebuilds it as an editable shape, and
160
+ * preserving it here as well would emit the same artwork twice.
161
+ *
162
+ * A watermark shape is not a second exclusion. Declining for one was a guess
163
+ * about another module, and `watermarkParser` claims by a far narrower rule
164
+ * than `isWatermarkShape` states: a direct `v:shape` child of a `w:pict`,
165
+ * carrying a non-empty `v:textpath` or a `v:imagedata`, alone in its paragraph,
166
+ * in a header. A `v:oval`, a shape nested in a `v:group`, a shape sharing its
167
+ * paragraph with text, and every `w:pict` in a footer or in the body fall
168
+ * outside it, so their artwork was declined here and claimed by no one. The
169
+ * watermark owner removes its own artwork from the model instead, by emptying
170
+ * the paragraph it detached, so this predicate need not guess who claimed what.
127
171
  */
128
172
  function shouldPreserveRawVmlPict(pictElement) {
129
173
  if (findDeep(pictElement, "v", "textbox")) return false;
130
- const shapes = VML_DRAWABLE_SHAPES.flatMap((localName) => findAllDeep(pictElement, "v", localName));
131
- return shapes.length > 0 && !shapes.some((shape) => isWatermarkShape(shape));
174
+ return VML_DRAWABLE_SHAPES.some((localName) => findDeep(pictElement, "v", localName) !== null);
132
175
  }
133
176
  /**
177
+ * Whether the run parser turns this `w:pict` into run content of its own.
178
+ *
179
+ * Exactly one owner may represent a `w:pict`: the run parser, whose drawing
180
+ * carries the whole element as captured XML, or the text-box enrichment pass,
181
+ * which rebuilds one `v:textbox` as an editable shape. Two owners write the
182
+ * same artwork twice, and when the pict holds text, the saved document says it
183
+ * twice.
184
+ *
185
+ * The enrichment asks this rather than re-deriving the answer from the markup:
186
+ * its own reading (`v:imagedata` present) named only the picture path, so a
187
+ * `v:group` claimed by the preview path was represented by both owners. The
188
+ * result is a pure function of the element, so asking it a second time costs
189
+ * only the work the run parser already did.
190
+ */
191
+ const isVmlPictParsedByRunParser = (pictElement, rels, media) => parseVmlImageContent(pictElement, rels, media) !== null || shouldPreserveRawVmlPict(pictElement);
192
+ /**
134
193
  * Read the relationship id off a `v:imagedata` element. Word writes `r:id`;
135
194
  * some legacy / third-party generators use `r:embed` or the office-namespace
136
195
  * `o:relid` instead, so fall back through those before the bare `id`.
@@ -157,8 +216,8 @@ function parseVmlImageContent(pictElement, rels, media, rootXmlns = {}) {
157
216
  for (const shape of shapes) {
158
217
  const imagedata = findChild(shape, "v", "imagedata");
159
218
  if (!imagedata) continue;
160
- const rId = readImageDataRId(imagedata);
161
- if (rId === void 0 || rId.length === 0) continue;
219
+ const rId = relationshipIdOf(readImageDataRId(imagedata));
220
+ if (rId === void 0) continue;
162
221
  if (isWatermarkShape(shape)) continue;
163
222
  const { src, mimeType, filename } = resolveImageData(rId, rels ?? void 0, media ?? void 0);
164
223
  const shapeStyle = parseVmlStyle(getAttribute(shape, null, "style"));
@@ -201,4 +260,4 @@ function parseVmlImageContent(pictElement, rels, media, rootXmlns = {}) {
201
260
  return null;
202
261
  }
203
262
  //#endregion
204
- export { parseVmlImageContent, shouldPreserveRawVmlPict };
263
+ export { isVmlPictParsedByRunParser, parseVmlImageContent, shouldPreserveRawVmlPict };
@@ -1,4 +1,4 @@
1
- import { VML_PREVIEW_DATA_URL_PREFIX } from "./previewBudget.js";
1
+ import { PREVIEW_KINDS } from "./previewBudget.js";
2
2
  import { findChild, findDeep, getAttribute, getChildElements, getLocalName } from "./xmlParser.js";
3
3
  //#region src/docx/vmlPreview.ts
4
4
  const MAX_VML_PREVIEW_DEPTH = 16;
@@ -84,7 +84,7 @@ const parseVmlNumber = (raw) => {
84
84
  /** Check a physical preview dimension against the retained SVG layout bound. */
85
85
  const isValidVmlPreviewDimension = (value) => value !== void 0 && value > 0 && value <= MAX_VML_PREVIEW_DIMENSION_PX;
86
86
  /** Encode a generated, already-sanitized SVG without exceeding its output cap. */
87
- const vmlSvgDataUrl = (svg) => svg.length <= MAX_VML_SVG_CHARACTERS ? `${VML_PREVIEW_DATA_URL_PREFIX}${encodeURIComponent(svg)}` : void 0;
87
+ const vmlSvgDataUrl = (svg) => svg.length <= MAX_VML_SVG_CHARACTERS ? `${PREVIEW_KINDS.vmlShape.srcPrefix}${encodeURIComponent(svg)}` : void 0;
88
88
  const validCoordinate = (value) => value !== void 0 && Math.abs(value) <= MAX_VML_PREVIEW_COORDINATE;
89
89
  const validExtent = (value) => value !== void 0 && value > 0 && value <= MAX_VML_PREVIEW_COORDINATE;
90
90
  const coordinatePair = (raw) => {
@@ -0,0 +1,30 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ //#region src/docx/wrapPolygon.d.ts
3
+ /**
4
+ * The polygon a `wp:wrapTight` or `wp:wrapThrough` states: the authored one, or
5
+ * the rectangle when the model holds none.
6
+ *
7
+ * An authored path is written back as it stands, including one shorter than
8
+ * `CT_WrapPath`'s two `wp:lineTo`. folio is not the validator of its input, and
9
+ * replacing a short outline with the full extent of the drawing would move text
10
+ * that the source flows through the object — the same silent substitution this
11
+ * module exists to end. The rectangle is minted only where the alternative is
12
+ * omitting a child the type requires.
13
+ */
14
+ declare const requiredWrapPolygon: (authored: document_d_exports.ImageWrapPolygon | undefined) => document_d_exports.ImageWrapPolygon;
15
+ /**
16
+ * The polygon a wrap of `type` has to state, or undefined when its type
17
+ * declares none.
18
+ *
19
+ * The editor command that changes a wrap type calls this, so a drawing that
20
+ * becomes tight or through is minted its rectangle once — at the edit, as a
21
+ * fact of the document the author can see and undo — and every save after that
22
+ * writes back what the model then holds.
23
+ */
24
+ declare const wrapPolygonFor: (type: document_d_exports.ImageWrap["type"], authored: document_d_exports.ImageWrapPolygon | undefined) => document_d_exports.ImageWrapPolygon | undefined;
25
+ /** A copy, deep enough that a ProseMirror attr cannot share a point with the model. */
26
+ declare const copiedWrapPolygon: (polygon: document_d_exports.ImageWrapPolygon | undefined) => document_d_exports.ImageWrapPolygon | undefined;
27
+ /** `wp:wrapPolygon`, written from a polygon {@link wrapPolygonFor} has approved. */
28
+ declare const serializeWrapPolygon: (polygon: document_d_exports.ImageWrapPolygon) => string;
29
+ //#endregion
30
+ export { copiedWrapPolygon, requiredWrapPolygon, serializeWrapPolygon, wrapPolygonFor };
@@ -0,0 +1,70 @@
1
+ import { intAttr } from "./serializer/xmlUtils.js";
2
+ //#region src/docx/wrapPolygon.ts
3
+ /** `CT_WrapPath` coordinates are relative to a box of this many units. */
4
+ const WRAP_PATH_EXTENT = 21600;
5
+ /**
6
+ * The whole drawing, as a closed rectangle in the path's relative space: the
7
+ * polygon that leaves text flowing exactly as the wrap's bounding box would.
8
+ * The only wrap outline folio invents.
9
+ */
10
+ const DEFAULT_WRAP_POLYGON = {
11
+ edited: false,
12
+ start: {
13
+ x: 0,
14
+ y: 0
15
+ },
16
+ lineTo: [
17
+ {
18
+ x: 0,
19
+ y: WRAP_PATH_EXTENT
20
+ },
21
+ {
22
+ x: WRAP_PATH_EXTENT,
23
+ y: WRAP_PATH_EXTENT
24
+ },
25
+ {
26
+ x: WRAP_PATH_EXTENT,
27
+ y: 0
28
+ },
29
+ {
30
+ x: 0,
31
+ y: 0
32
+ }
33
+ ]
34
+ };
35
+ /**
36
+ * The polygon a `wp:wrapTight` or `wp:wrapThrough` states: the authored one, or
37
+ * the rectangle when the model holds none.
38
+ *
39
+ * An authored path is written back as it stands, including one shorter than
40
+ * `CT_WrapPath`'s two `wp:lineTo`. folio is not the validator of its input, and
41
+ * replacing a short outline with the full extent of the drawing would move text
42
+ * that the source flows through the object — the same silent substitution this
43
+ * module exists to end. The rectangle is minted only where the alternative is
44
+ * omitting a child the type requires.
45
+ */
46
+ const requiredWrapPolygon = (authored) => authored ?? DEFAULT_WRAP_POLYGON;
47
+ /**
48
+ * The polygon a wrap of `type` has to state, or undefined when its type
49
+ * declares none.
50
+ *
51
+ * The editor command that changes a wrap type calls this, so a drawing that
52
+ * becomes tight or through is minted its rectangle once — at the edit, as a
53
+ * fact of the document the author can see and undo — and every save after that
54
+ * writes back what the model then holds.
55
+ */
56
+ const wrapPolygonFor = (type, authored) => type === "tight" || type === "through" ? requiredWrapPolygon(authored) : void 0;
57
+ /** A copy, deep enough that a ProseMirror attr cannot share a point with the model. */
58
+ const copiedWrapPolygon = (polygon) => polygon === void 0 ? void 0 : {
59
+ ...polygon,
60
+ start: { ...polygon.start },
61
+ lineTo: polygon.lineTo.map((point) => ({ ...point }))
62
+ };
63
+ /** `wp:wrapPolygon`, written from a polygon {@link wrapPolygonFor} has approved. */
64
+ const serializeWrapPolygon = (polygon) => {
65
+ const edited = polygon.edited === void 0 ? "" : ` edited="${polygon.edited ? "1" : "0"}"`;
66
+ const lineTo = polygon.lineTo.map((point) => `<wp:lineTo x="${intAttr(point.x)}" y="${intAttr(point.y)}"/>`).join("");
67
+ return `<wp:wrapPolygon${edited}><wp:start x="${intAttr(polygon.start.x)}" y="${intAttr(polygon.start.y)}"/>${lineTo}</wp:wrapPolygon>`;
68
+ };
69
+ //#endregion
70
+ export { copiedWrapPolygon, requiredWrapPolygon, serializeWrapPolygon, wrapPolygonFor };
@@ -0,0 +1,5 @@
1
+ //#region src/docx/xmlEncoding.d.ts
2
+ /** Decode the UTF-8 and UTF-16 encodings XML processors must recognize. */
3
+ declare const decodeXmlBytes: (bytes: Uint8Array) => string;
4
+ //#endregion
5
+ export { decodeXmlBytes };
@@ -0,0 +1,12 @@
1
+ //#region src/docx/xmlEncoding.ts
2
+ /** Decode the UTF-8 and UTF-16 encodings XML processors must recognize. */
3
+ const decodeXmlBytes = (bytes) => {
4
+ if (bytes[0] === 255 && bytes[1] === 254) return new TextDecoder("utf-16le").decode(bytes.subarray(2));
5
+ if (bytes[0] === 254 && bytes[1] === 255) return new TextDecoder("utf-16be").decode(bytes.subarray(2));
6
+ if (bytes[0] === 60 && bytes[1] === 0 && bytes[2] === 63 && bytes[3] === 0) return new TextDecoder("utf-16le").decode(bytes);
7
+ if (bytes[0] === 0 && bytes[1] === 60 && bytes[2] === 0 && bytes[3] === 63) return new TextDecoder("utf-16be").decode(bytes);
8
+ const utf8Offset = bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191 ? 3 : 0;
9
+ return new TextDecoder("utf-8").decode(bytes.subarray(utf8Offset));
10
+ };
11
+ //#endregion
12
+ export { decodeXmlBytes };