@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,153 @@
1
+ import { TRANSITIONAL_NAMESPACE_BY_STRICT_URI } from "./strictValueEncodings.gen.js";
2
+ import { captureVerbatimXml } from "./verbatimCapture.js";
3
+ import { WORDPROCESSINGML_NAMESPACE_URIS, getChildElements, getLocalName, getNamespaceUri } from "./xmlParser.js";
4
+ import { SEQUENCE_CHILDREN } from "@stll/docx-core/schema";
5
+ //#region src/docx/containerChildren.ts
6
+ /** Keep this child's markup verbatim, in place. */
7
+ const CAPTURE = "capture";
8
+ /**
9
+ * What a handler answers with: nothing when it took a typed value, and
10
+ * {@link CAPTURE} when it took none, so the child's bytes are kept instead.
11
+ *
12
+ * `<w:tblLayout/>` states no layout and `<w:jc w:val="end"/>` states a value a
13
+ * reader's enumeration does not admit. Both used to fall off the end of the
14
+ * walk, and neither can be decided by name: a map keyed by name cannot list
15
+ * the values a reader will refuse, only the names it has never heard of.
16
+ */
17
+ const keptUnless = (taken) => taken ? void 0 : CAPTURE;
18
+ const OWNED_ELSEWHERE = "owned-elsewhere";
19
+ const CLAIMS = /* @__PURE__ */ new Map();
20
+ /**
21
+ * Every owner a handler map has claimed so far.
22
+ *
23
+ * A claim is registered when `ownedElsewhere` is called, so a module that is
24
+ * never imported contributes none. The checks that read this therefore load
25
+ * the claiming modules first, by scanning the sources for the call rather than
26
+ * by keeping a list beside them.
27
+ */
28
+ const ownedElsewhereClaims = () => [...CLAIMS.values()];
29
+ /** State that another reader takes this child, and who. */
30
+ const ownedElsewhere = (claim) => {
31
+ CLAIMS.set(`${claim.container}/${claim.child}#${claim.reader}`, claim);
32
+ return {
33
+ disposition: OWNED_ELSEWHERE,
34
+ ...claim
35
+ };
36
+ };
37
+ /**
38
+ * This child goes with the wrapper folio does not keep.
39
+ *
40
+ * `w:smartTagPr` is the case: folio unwraps `w:smartTag` and splices its
41
+ * content into the paragraph, so the properties describing the wrapper have
42
+ * nothing left to describe and capturing them would put a `w:smartTagPr`
43
+ * where the schema does not admit one. The drop is stated here and recorded
44
+ * in `specifications/container-contract/contract.json`, which is the whole
45
+ * difference between this and a `default` that says nothing.
46
+ */
47
+ const DROPPED_WITH_ITS_WRAPPER = "dropped-with-its-wrapper";
48
+ /**
49
+ * The Transitional spelling of a namespace, so one disposition covers both.
50
+ *
51
+ * ISO Strict writes the same content model under its own URIs: maths is
52
+ * `purl.oclc.org/ooxml/officeDocument/math` rather than
53
+ * `schemas.openxmlformats.org/officeDocument/2006/math`. A namespace-keyed
54
+ * disposition written in Transitional would otherwise send a Strict
55
+ * document's maths to the sink, which models it as bytes instead of an
56
+ * equation. The pairs come from the generated table rather than a second list
57
+ * here, so a namespace cannot be paired in one place and forgotten in the
58
+ * other.
59
+ */
60
+ const transitionalNamespaceOf = (namespace) => TRANSITIONAL_NAMESPACE_BY_STRICT_URI.get(namespace) ?? namespace;
61
+ /**
62
+ * Walk a container's children, handing each to its handler and the rest to the
63
+ * sink.
64
+ *
65
+ * @returns the container's unmodelled markup, or `undefined` when it held
66
+ * none — an empty record is never written, so a fully modelled container
67
+ * stays byte-identical in the model.
68
+ */
69
+ const dispatchChildren = ({ element, handlers, capturePosition, undeclared, undeclaredNamespaces }) => {
70
+ const children = [];
71
+ const capture = (child) => {
72
+ children.push({
73
+ index: capturePosition(child),
74
+ xml: captureVerbatimXml(child)
75
+ });
76
+ };
77
+ const declared = new Map(Object.entries(handlers));
78
+ const byName = new Map(Object.entries(undeclared ?? {}));
79
+ const byNamespace = new Map(Object.entries(undeclaredNamespaces ?? {}));
80
+ for (const child of getChildElements(element)) {
81
+ const localName = getLocalName(child.name);
82
+ const namespace = getNamespaceUri(child);
83
+ const disposition = namespace === void 0 || WORDPROCESSINGML_NAMESPACE_URIS.has(namespace) ? declared.get(localName) ?? byName.get(localName) : byName.get(localName) ?? byNamespace.get(transitionalNamespaceOf(namespace));
84
+ if (disposition === void 0 || disposition === "capture") {
85
+ capture(child);
86
+ continue;
87
+ }
88
+ if (typeof disposition !== "function") continue;
89
+ if (disposition(child) === "capture") capture(child);
90
+ }
91
+ return children.length === 0 ? void 0 : { children };
92
+ };
93
+ /**
94
+ * Put a container's modelled children back with its preserved ones between
95
+ * them, in source position.
96
+ *
97
+ * Where the content model demands schema order the caller has already put its
98
+ * modelled children in that order; the sink's `index` then places each capture
99
+ * between the same two siblings it sat between when it was read.
100
+ *
101
+ * @param wrap turns one capture's markup into whatever the caller's list holds
102
+ */
103
+ const withPreservedChildren = (modelled, preserved, wrap) => {
104
+ const captures = preserved?.children;
105
+ if (captures === void 0 || captures.length === 0) return [...modelled];
106
+ const byIndex = /* @__PURE__ */ new Map();
107
+ for (const child of captures) {
108
+ const { index, xml } = child;
109
+ const slot = Math.min(Math.max(index, 0), modelled.length);
110
+ const bucket = byIndex.get(slot);
111
+ if (bucket) {
112
+ bucket.push(wrap(xml, child));
113
+ continue;
114
+ }
115
+ byIndex.set(slot, [wrap(xml, child)]);
116
+ }
117
+ const items = [];
118
+ for (const [index, item] of modelled.entries()) items.push(...byIndex.get(index) ?? [], item);
119
+ items.push(...byIndex.get(modelled.length) ?? []);
120
+ return items;
121
+ };
122
+ /** {@link withPreservedChildren} for a caller that already holds markup. */
123
+ const serializeWithPreservedChildren = (modelled, preserved) => withPreservedChildren(modelled, preserved, (xml) => xml).join("");
124
+ /**
125
+ * Where each child sits in a container whose content model is one flat sequence.
126
+ *
127
+ * A property set is that container: `CT_TblPr` and `CT_SectPr` are sequences
128
+ * of optional singletons, so a child's position is a property of its name and
129
+ * the generated list is the order. That is what the sink records for them,
130
+ * rather than a count of modelled siblings: the count is a mirror of whichever
131
+ * properties folio models today, and it moves under the capture the moment one
132
+ * more of them is modelled.
133
+ *
134
+ * An undeclared child — a foreign namespace, an `mc:` construct, a name a
135
+ * later revision of the format adds — has no place in the sequence, so it
136
+ * takes the place of the last declared child before it and comes back beside
137
+ * the same neighbour. One before every declared child takes position `-1`,
138
+ * ahead of the sequence's first slot.
139
+ */
140
+ const sequencePositions = (container, element) => {
141
+ const declared = SEQUENCE_CHILDREN[container];
142
+ const positions = /* @__PURE__ */ new Map();
143
+ let previous = -1;
144
+ for (const child of getChildElements(element)) {
145
+ const namespace = getNamespaceUri(child);
146
+ const at = namespace === void 0 || WORDPROCESSINGML_NAMESPACE_URIS.has(namespace) ? declared.indexOf(getLocalName(child.name)) : -1;
147
+ if (at !== -1) previous = at;
148
+ positions.set(child, at === -1 ? previous : at);
149
+ }
150
+ return (child) => positions.get(child) ?? -1;
151
+ };
152
+ //#endregion
153
+ export { CAPTURE, DROPPED_WITH_ITS_WRAPPER, dispatchChildren, keptUnless, ownedElsewhere, ownedElsewhereClaims, sequencePositions, serializeWithPreservedChildren, transitionalNamespaceOf, withPreservedChildren };
@@ -1,7 +1,19 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
2
  import { XmlElement } from "./xmlParser.js";
3
3
  //#region src/docx/diagramPreview.d.ts
4
- /** Create a deliberately simple, bounded preview; it is never an editable diagram projection. */
4
+ /**
5
+ * How many `dsp:sp` a preview describes at most.
6
+ *
7
+ * The bound is on the description rather than on any picture built from it:
8
+ * the shapes are what a backend draws, and a drawing with ten thousand of them
9
+ * is a drawing folio summarises rather than reproduces.
10
+ */
11
+ declare const MAX_PREVIEW_SHAPES = 128;
12
+ /**
13
+ * Describe a diagram drawing, without drawing it.
14
+ *
15
+ * Deliberately simple and bounded; it is never an editable diagram projection.
16
+ */
5
17
  declare const parseDiagramPreview: (drawing: XmlElement, rels: document_d_exports.RelationshipMap | undefined, media: Map<string, document_d_exports.MediaFile> | undefined) => document_d_exports.Image | null;
6
18
  //#endregion
7
- export { parseDiagramPreview };
19
+ export { MAX_PREVIEW_SHAPES, parseDiagramPreview };
@@ -1,11 +1,14 @@
1
- import { bytesToDataUrl } from "../utils/base64.js";
2
- import { PREVIEW_KINDS } from "./previewBudget.js";
3
1
  import { resolveRelationshipIdOfType, resolveRelativePath } from "./relsParser.js";
4
2
  import { OFFICE_RELATIONSHIP_NAMESPACE_URIS, findChildByNamespaceUri, getAttribute, getAttributeByNamespaceUri, getLocalName, parseNumericAttribute, parseXmlDocument } from "./xmlParser.js";
5
3
  //#region src/docx/diagramPreview.ts
4
+ /**
5
+ * How many `dsp:sp` a preview describes at most.
6
+ *
7
+ * The bound is on the description rather than on any picture built from it:
8
+ * the shapes are what a backend draws, and a drawing with ten thousand of them
9
+ * is a drawing folio summarises rather than reproduces.
10
+ */
6
11
  const MAX_PREVIEW_SHAPES = 128;
7
- const MAX_PREVIEW_PIXELS = 144e4;
8
- const MAX_PREVIEW_PAINT_PIXELS = MAX_PREVIEW_PIXELS * 4;
9
12
  const DRAWINGML_NAMESPACE_URIS = /* @__PURE__ */ new Set(["http://schemas.openxmlformats.org/drawingml/2006/main", "http://purl.oclc.org/ooxml/drawingml/main"]);
10
13
  const DIAGRAM_NAMESPACE_URIS = /* @__PURE__ */ new Set(["http://schemas.openxmlformats.org/drawingml/2006/diagram", "http://purl.oclc.org/ooxml/drawingml/diagram"]);
11
14
  const DIAGRAM_DRAWING_NAMESPACE_URIS = /* @__PURE__ */ new Set(["http://schemas.microsoft.com/office/drawing/2008/diagram"]);
@@ -13,140 +16,6 @@ const DIAGRAM_DATA_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/office
13
16
  const DIAGRAM_DRAWING_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/office/2007/relationships/diagramDrawing";
14
17
  const DOCUMENT_PART_PATH = "word/document.xml";
15
18
  const WORD_DRAWING_NAMESPACE_URIS = /* @__PURE__ */ new Set(["http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "http://purl.oclc.org/ooxml/drawingml/wordprocessingDrawing"]);
16
- /**
17
- * The preview is a megapixel raster, so both checksums run over megabytes.
18
- * `for (const byte of bytes)` drives the array iterator protocol once per
19
- * byte, which profiles as the dominant cost of parsing a SmartArt document;
20
- * indexed loops and a table-driven CRC produce the same numbers without it.
21
- */
22
- const CRC32_TABLE = (() => {
23
- const table = /* @__PURE__ */ new Uint32Array(256);
24
- for (let index = 0; index < 256; index += 1) {
25
- let value = index;
26
- for (let bit = 0; bit < 8; bit += 1) value = value >>> 1 ^ (value & 1 ? 3988292384 : 0);
27
- table[index] = value >>> 0;
28
- }
29
- return table;
30
- })();
31
- const crc32 = (bytes) => {
32
- let crc = 4294967295;
33
- for (let index = 0; index < bytes.length; index += 1) crc = crc >>> 8 ^ CRC32_TABLE[(crc ^ bytes[index]) & 255];
34
- return (crc ^ 4294967295) >>> 0;
35
- };
36
- /**
37
- * `a` and `b` stay below 2^31 for 5552 iterations from any legal state, so the
38
- * modulo runs per block rather than per byte.
39
- */
40
- const ADLER32_BLOCK = 5552;
41
- const adler32 = (bytes) => {
42
- let a = 1;
43
- let b = 0;
44
- let index = 0;
45
- while (index < bytes.length) {
46
- const end = Math.min(index + ADLER32_BLOCK, bytes.length);
47
- for (; index < end; index += 1) {
48
- a += bytes[index];
49
- b += a;
50
- }
51
- a %= 65521;
52
- b %= 65521;
53
- }
54
- return b << 16 | a;
55
- };
56
- const pngChunk = (type, data) => {
57
- const name = new TextEncoder().encode(type);
58
- const output = new Uint8Array(12 + data.length);
59
- const view = new DataView(output.buffer);
60
- view.setUint32(0, data.length);
61
- output.set(name, 4);
62
- output.set(data, 8);
63
- view.setUint32(8 + data.length, crc32(output.subarray(4, 8 + data.length)));
64
- return output;
65
- };
66
- const previewPng = (width, height, shapes) => {
67
- const scale = Math.min(1, Math.sqrt(MAX_PREVIEW_PIXELS / (width * height)));
68
- const w = Math.max(1, Math.round(width * scale));
69
- const h = Math.max(1, Math.round(height * scale));
70
- const pixels = new Uint8Array((w * 4 + 1) * h);
71
- for (let y = 0; y < h; y += 1) {
72
- const row = y * (w * 4 + 1);
73
- pixels[row] = 0;
74
- for (let x = 0; x < w; x += 1) {
75
- const index = row + 1 + x * 4;
76
- pixels[index] = 238;
77
- pixels[index + 1] = 242;
78
- pixels[index + 2] = 247;
79
- pixels[index + 3] = 255;
80
- }
81
- }
82
- let paintedPixels = 0;
83
- for (const shape of shapes) {
84
- const sx = Math.max(0, Math.round(shape.x / width * w));
85
- const sy = Math.max(0, Math.round(shape.y / height * h));
86
- const ex = Math.min(w, Math.round((shape.x + shape.width) / width * w));
87
- const ey = Math.min(h, Math.round((shape.y + shape.height) / height * h));
88
- const red = Number.parseInt(shape.color.slice(0, 2), 16) || 232;
89
- const green = Number.parseInt(shape.color.slice(2, 4), 16) || 238;
90
- const blue = Number.parseInt(shape.color.slice(4, 6), 16) || 247;
91
- const shapePixels = Math.max(0, ex - sx) * Math.max(0, ey - sy);
92
- if (paintedPixels + shapePixels > MAX_PREVIEW_PAINT_PIXELS) break;
93
- paintedPixels += shapePixels;
94
- for (let y = sy; y < ey; y += 1) {
95
- const row = y * (w * 4 + 1);
96
- for (let x = sx; x < ex; x += 1) {
97
- const index = row + 1 + x * 4;
98
- pixels[index] = red;
99
- pixels[index + 1] = green;
100
- pixels[index + 2] = blue;
101
- }
102
- }
103
- }
104
- const compressed = new Uint8Array(2 + pixels.length + Math.ceil(pixels.length / 65535) * 5 + 4);
105
- compressed[0] = 120;
106
- compressed[1] = 1;
107
- let cursor = 2;
108
- for (let offset = 0; offset < pixels.length;) {
109
- const length = Math.min(65535, pixels.length - offset);
110
- compressed[cursor++] = offset + length === pixels.length ? 1 : 0;
111
- compressed[cursor++] = length & 255;
112
- compressed[cursor++] = length >>> 8;
113
- compressed[cursor++] = ~length & 255;
114
- compressed[cursor++] = ~length >>> 8 & 255;
115
- compressed.set(pixels.subarray(offset, offset + length), cursor);
116
- cursor += length;
117
- offset += length;
118
- }
119
- new DataView(compressed.buffer).setUint32(cursor, adler32(pixels));
120
- const output = compressed;
121
- const signature = new Uint8Array([
122
- 137,
123
- 80,
124
- 78,
125
- 71,
126
- 13,
127
- 10,
128
- 26,
129
- 10
130
- ]);
131
- const header = /* @__PURE__ */ new Uint8Array(13);
132
- new DataView(header.buffer).setUint32(0, w);
133
- new DataView(header.buffer).setUint32(4, h);
134
- header[8] = 8;
135
- header[9] = 6;
136
- const chunks = [
137
- signature,
138
- pngChunk("IHDR", header),
139
- pngChunk("IDAT", output),
140
- pngChunk("IEND", /* @__PURE__ */ new Uint8Array())
141
- ];
142
- const png = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));
143
- let position = 0;
144
- for (const chunk of chunks) {
145
- png.set(chunk, position);
146
- position += chunk.length;
147
- }
148
- return png;
149
- };
150
19
  const extent = (drawing) => {
151
20
  const value = findChildByNamespaceUri(findChildByNamespaceUri(drawing, WORD_DRAWING_NAMESPACE_URIS, "inline") ?? findChildByNamespaceUri(drawing, WORD_DRAWING_NAMESPACE_URIS, "anchor"), WORD_DRAWING_NAMESPACE_URIS, "extent");
152
21
  return {
@@ -155,11 +24,47 @@ const extent = (drawing) => {
155
24
  };
156
25
  };
157
26
  /** Parse the part a relationship of the given type names, by that relationship's id. */
158
- const partByRelationshipId = ({ rels, media, rId, type }) => {
27
+ const partByRelationshipId = ({ rels, media, rId, type, cache }) => {
159
28
  const resolved = resolveRelationshipIdOfType(rels, rId ?? void 0, type);
160
29
  if (resolved.status !== "resolved" || !resolved.relationship.target) return null;
161
- const file = media.get(resolveRelativePath(DOCUMENT_PART_PATH, resolved.relationship.target));
162
- return file?.data ? parseXmlDocument(new TextDecoder().decode(file.data)) : null;
30
+ const path = resolveRelativePath(DOCUMENT_PART_PATH, resolved.relationship.target);
31
+ const cached = cache.get(path);
32
+ if (cached !== void 0) return cached;
33
+ const file = media.get(path);
34
+ const parsed = file?.data ? parseXmlDocument(new TextDecoder().decode(file.data)) : null;
35
+ cache.set(path, parsed);
36
+ return parsed;
37
+ };
38
+ const matchesNamespace = (element, namespaceUris, localName) => element.namespaceUri !== void 0 && namespaceUris.has(element.namespaceUri) && getLocalName(element.name ?? "") === localName;
39
+ /**
40
+ * Descendants in document order, stopping once `limit` of them are found.
41
+ *
42
+ * The walk used to collect every match and slice afterwards, so a drawing with
43
+ * ten thousand shapes built a ten-thousand-element array to keep a hundred and
44
+ * twenty-eight of them. The bound belongs in the walk, not after it.
45
+ */
46
+ const descendantsByNamespace = (root, namespaceUris, localName, limit) => {
47
+ const result = [];
48
+ const visit = (element) => {
49
+ if (matchesNamespace(element, namespaceUris, localName)) {
50
+ result.push(element);
51
+ return result.length < limit;
52
+ }
53
+ for (const child of element.elements ?? []) if (child.type === "element" && !visit(child)) return false;
54
+ return true;
55
+ };
56
+ visit(root);
57
+ return result;
58
+ };
59
+ /** The first match in document order, without walking the rest of the subtree. */
60
+ const firstDescendantByNamespace = (root, namespaceUris, localName) => {
61
+ if (matchesNamespace(root, namespaceUris, localName)) return root;
62
+ for (const child of root.elements ?? []) {
63
+ if (child.type !== "element") continue;
64
+ const found = firstDescendantByNamespace(child, namespaceUris, localName);
65
+ if (found) return found;
66
+ }
67
+ return null;
163
68
  };
164
69
  /**
165
70
  * The drawing cache this diagram points at, reached through its own ids.
@@ -170,25 +75,27 @@ const partByRelationshipId = ({ rels, media, rId, type }) => {
170
75
  * more than one, which is why the scan refused outright on a second match:
171
76
  * both diagrams in a two-diagram document then got no preview at all.
172
77
  */
173
- const cachedDiagramShapes = (graphicData, rels, media) => {
78
+ const cachedDiagramShapes = (graphicData, rels, media, cache) => {
174
79
  const relIds = findChildByNamespaceUri(graphicData, DIAGRAM_NAMESPACE_URIS, "relIds");
175
80
  const data = partByRelationshipId({
176
81
  rels,
177
82
  media,
83
+ cache,
178
84
  rId: getAttributeByNamespaceUri(relIds, OFFICE_RELATIONSHIP_NAMESPACE_URIS, "dm"),
179
85
  type: DIAGRAM_DATA_RELATIONSHIP_TYPE
180
86
  });
181
87
  if (!data) return [];
182
- const dataModelExt = descendantsByNamespace(data, DIAGRAM_DRAWING_NAMESPACE_URIS, "dataModelExt").at(0);
88
+ const dataModelExt = firstDescendantByNamespace(data, DIAGRAM_DRAWING_NAMESPACE_URIS, "dataModelExt");
183
89
  const root = partByRelationshipId({
184
90
  rels,
185
91
  media,
92
+ cache,
186
93
  rId: getAttribute(dataModelExt, null, "relId"),
187
94
  type: DIAGRAM_DRAWING_RELATIONSHIP_TYPE
188
95
  });
189
96
  if (!root) return [];
190
97
  const shapes = [];
191
- for (const shape of descendantsByNamespace(root, DIAGRAM_DRAWING_NAMESPACE_URIS, "sp").slice(0, MAX_PREVIEW_SHAPES)) {
98
+ for (const shape of descendantsByNamespace(root, DIAGRAM_DRAWING_NAMESPACE_URIS, "sp", 128)) {
192
99
  const properties = findChildByNamespaceUri(shape, DIAGRAM_DRAWING_NAMESPACE_URIS, "spPr");
193
100
  const transform = findChildByNamespaceUri(properties, DRAWINGML_NAMESPACE_URIS, "xfrm");
194
101
  const offset = findChildByNamespaceUri(transform, DRAWINGML_NAMESPACE_URIS, "off");
@@ -207,27 +114,28 @@ const cachedDiagramShapes = (graphicData, rels, media) => {
207
114
  }
208
115
  return shapes;
209
116
  };
210
- const matchesNamespace = (element, namespaceUris, localName) => element.namespaceUri !== void 0 && namespaceUris.has(element.namespaceUri) && getLocalName(element.name ?? "") === localName;
211
- const descendantsByNamespace = (root, namespaceUris, localName) => {
212
- const result = [];
213
- const visit = (element) => {
214
- if (matchesNamespace(element, namespaceUris, localName)) result.push(element);
215
- for (const child of element.elements ?? []) if (child.type === "element") visit(child);
216
- };
217
- visit(root);
218
- return result;
219
- };
220
- /** The first match in document order, without walking the rest of the subtree. */
221
- const firstDescendantByNamespace = (root, namespaceUris, localName) => {
222
- if (matchesNamespace(root, namespaceUris, localName)) return root;
223
- for (const child of root.elements ?? []) {
224
- if (child.type !== "element") continue;
225
- const found = firstDescendantByNamespace(child, namespaceUris, localName);
226
- if (found) return found;
227
- }
228
- return null;
117
+ /**
118
+ * The part cache, keyed by the package's own media map.
119
+ *
120
+ * The cache has to be per package: a global one would answer one document's
121
+ * `word/diagrams/data1.xml` with another's. Keying it on the media map gets
122
+ * that lifetime for free and without threading a reader through every drawing
123
+ * call site, and a weak key means the cache dies with the package rather than
124
+ * retaining its parts.
125
+ */
126
+ const PART_CACHES = /* @__PURE__ */ new WeakMap();
127
+ const partCacheFor = (media) => {
128
+ const existing = PART_CACHES.get(media);
129
+ if (existing) return existing;
130
+ const created = /* @__PURE__ */ new Map();
131
+ PART_CACHES.set(media, created);
132
+ return created;
229
133
  };
230
- /** Create a deliberately simple, bounded preview; it is never an editable diagram projection. */
134
+ /**
135
+ * Describe a diagram drawing, without drawing it.
136
+ *
137
+ * Deliberately simple and bounded; it is never an editable diagram projection.
138
+ */
231
139
  const parseDiagramPreview = (drawing, rels, media) => {
232
140
  if (!rels || !media) return null;
233
141
  const graphicData = firstDescendantByNamespace(drawing, DRAWINGML_NAMESPACE_URIS, "graphicData");
@@ -236,10 +144,14 @@ const parseDiagramPreview = (drawing, rels, media) => {
236
144
  if (width <= 0 || height <= 0) return null;
237
145
  return {
238
146
  type: "image",
239
- rId: "",
240
- src: bytesToDataUrl(previewPng(width, height, cachedDiagramShapes(graphicData, rels, media)), PREVIEW_KINDS.smartArt.mimeType),
241
- mimeType: PREVIEW_KINDS.smartArt.mimeType,
242
- filename: PREVIEW_KINDS.smartArt.filename,
147
+ preview: {
148
+ kind: "diagram",
149
+ extent: {
150
+ width,
151
+ height
152
+ },
153
+ shapes: cachedDiagramShapes(graphicData, rels, media, partCacheFor(media))
154
+ },
243
155
  size: {
244
156
  width,
245
157
  height
@@ -248,4 +160,4 @@ const parseDiagramPreview = (drawing, rels, media) => {
248
160
  };
249
161
  };
250
162
  //#endregion
251
- export { parseDiagramPreview };
163
+ export { MAX_PREVIEW_SHAPES, parseDiagramPreview };
@@ -1,7 +1,7 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
2
  import { NumberingMap } from "./numberingParser.js";
3
- import { StyleMap } from "./styleParser.js";
4
3
  import { ParseContext } from "./parseContext.js";
4
+ import { StyleMap } from "./styleParser.js";
5
5
  //#region src/docx/documentParser.d.ts
6
6
  /**
7
7
  * Extract template variables from text
@@ -49,7 +49,7 @@ function extractTableVariables(table) {
49
49
  for (const row of table.rows) for (const cell of row.cells) for (const cellContent of cell.content) if (cellContent.type === "paragraph") {
50
50
  const vars = extractTemplateVariables(getParagraphText(cellContent));
51
51
  for (const v of vars) if (!variables.includes(v)) variables.push(v);
52
- } else {
52
+ } else if (cellContent.type === "table") {
53
53
  const nestedVars = extractTableVariables(cellContent);
54
54
  for (const v of nestedVars) if (!variables.includes(v)) variables.push(v);
55
55
  }
@@ -127,7 +127,10 @@ function parseDocumentBody(xml, styles = null, theme = null, numbering = null, r
127
127
  if (!documentEl) return result;
128
128
  const bodyEl = findChild(documentEl, "w", "body");
129
129
  if (!bodyEl) return result;
130
- result.content = parseBlockContent(bodyEl, styles, theme, numbering, rels, media, { rootXmlns: collectXmlnsDeclarations(documentEl) });
130
+ result.content = parseBlockContent(bodyEl, styles, theme, numbering, rels, media, {
131
+ rootXmlns: collectXmlnsDeclarations(documentEl),
132
+ context
133
+ });
131
134
  const finalSectPr = findChild(bodyEl, "w", "sectPr");
132
135
  if (finalSectPr) result.finalSectionProperties = parseSectionProperties(finalSectPr, context);
133
136
  canonicalizeLeadingBodySectionProperties(bodyEl, result);
@@ -149,7 +152,7 @@ function getAllParagraphs(body) {
149
152
  function getTableParagraphs(table) {
150
153
  const paragraphs = [];
151
154
  for (const row of table.rows) for (const cell of row.cells) for (const content of cell.content) if (content.type === "paragraph") paragraphs.push(content);
152
- else paragraphs.push(...getTableParagraphs(content));
155
+ else if (content.type === "table") paragraphs.push(...getTableParagraphs(content));
153
156
  return paragraphs;
154
157
  }
155
158
  /**
@@ -193,7 +196,7 @@ function getTableText(table) {
193
196
  for (const cell of row.cells) {
194
197
  const cellTexts = [];
195
198
  for (const content of cell.content) if (content.type === "paragraph") cellTexts.push(getParagraphText(content));
196
- else cellTexts.push(getTableText(content));
199
+ else if (content.type === "table") cellTexts.push(getTableText(content));
197
200
  rowTexts.push(cellTexts.join("\n"));
198
201
  }
199
202
  lines.push(rowTexts.join(" "));
@@ -0,0 +1,87 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ import { XmlElement } from "./xmlParser.js";
3
+ //#region src/docx/drawingAnchor.d.ts
4
+ /** WordprocessingDrawing, Transitional and Strict (ECMA-376 Parts 1 and 4). */
5
+ declare const WORDPROCESSING_DRAWING_NAMESPACE_URIS: ReadonlySet<string>;
6
+ /** The anchor fields that are a single `ST_OnOff`-style attribute. */
7
+ type DrawingAnchorFlag = { [Key in keyof document_d_exports.DrawingAnchor]-?: NonNullable<document_d_exports.DrawingAnchor[Key]> extends boolean ? Key : never; }[keyof document_d_exports.DrawingAnchor];
8
+ /** Every boolean the anchor models, from the total map above. */
9
+ declare const DRAWING_ANCHOR_FLAG_KEYS: DrawingAnchorFlag[];
10
+ /**
11
+ * Read `CT_Anchor`'s own attributes and its `wp:simplePos` offsets.
12
+ *
13
+ * Undefined when the element states none of them: an anchor whose every
14
+ * attribute is the spec default holds nothing the model needs to remember, and
15
+ * recording an empty record would make a rebuild write values the source did
16
+ * not.
17
+ */
18
+ declare const parseDrawingAnchor: (anchorEl: XmlElement) => document_d_exports.DrawingAnchor | undefined;
19
+ /**
20
+ * The insets to write on each of the two elements that can carry them.
21
+ *
22
+ * A drawing whose slots say where its insets were authored gets each one back
23
+ * on that element, which is the only way the wrap child's own set survives a
24
+ * rebuild. A drawing with no slots, or one an editor command has moved an inset
25
+ * on, states the value in force on the drawing: that is where OOXML reads an
26
+ * inset from when the wrap child states none, so the effective value is right
27
+ * either way, and inventing a wrap-child inset from a moved value would not be.
28
+ */
29
+ declare const resolveWrapDistances: (wrap: document_d_exports.ImageWrap | undefined) => {
30
+ drawing: document_d_exports.WrapDistances;
31
+ wrapChild: document_d_exports.WrapDistances;
32
+ };
33
+ type ResolvedEffectExtents = {
34
+ /** `wp:inline` or `wp:anchor`; undefined writes the all-zero reservation. */
35
+ drawing: document_d_exports.ImagePadding | undefined;
36
+ /** `wp:wrapSquare` or `wp:wrapTopAndBottom`, which write nothing when undefined. */
37
+ wrapChild: document_d_exports.ImagePadding | undefined;
38
+ };
39
+ /**
40
+ * The `wp:effectExtent` to write on each of the two elements that carry one.
41
+ *
42
+ * {@link resolveWrapDistances}'s rule, one element over: a drawing whose slots
43
+ * say where the reservations were authored gets each one back on that element,
44
+ * which is the only way the wrap child's own survives a rebuild. Once the
45
+ * drawing's reservation has been resized the two no longer describe the same
46
+ * object, so the rebuild states the value in force on the drawing and lets
47
+ * OOXML's own default apply to the wrap — keeping a wrap reservation computed
48
+ * against the old size would flow text around a shape that is no longer there.
49
+ *
50
+ * `effective` is the reservation the model holds for the drawing itself:
51
+ * `Image.padding`. A shape and a text box have no such field — the rebuild has
52
+ * always written zeros — so they pass the drawing slot back and nothing can
53
+ * have moved a value the model cannot hold.
54
+ */
55
+ declare const resolveEffectExtents: (wrap: document_d_exports.ImageWrap | undefined, effective: document_d_exports.ImagePadding | undefined) => ResolvedEffectExtents;
56
+ /** `wp:effectExtent`, whose four sides `CT_EffectExtent` all requires. */
57
+ declare const serializeEffectExtent: (extent: document_d_exports.ImagePadding | undefined) => string;
58
+ /** The inset attributes an element states, in schema order, or nothing. */
59
+ declare const serializeWrapDistances: (distances: document_d_exports.WrapDistances) => string;
60
+ /**
61
+ * Only the wrap insets `wp:inline` or `wp:anchor` itself carries. OOXML
62
+ * defaults an omitted one to zero, so writing all four would put a value on
63
+ * every drawing that never had one.
64
+ */
65
+ declare const serializeWrapDistanceAttributes: (wrap: document_d_exports.ImageWrap | undefined) => string;
66
+ /** `wp:inline` carries the wrap insets and nothing else of `CT_Anchor`'s set. */
67
+ declare const serializeInlineAttributes: (wrap: document_d_exports.ImageWrap | undefined) => string;
68
+ type AnchorAttributesOptions = {
69
+ anchor: document_d_exports.DrawingAnchor | undefined;
70
+ wrap: document_d_exports.ImageWrap | undefined;
71
+ /** `@behindDoc`, which the wrap type decides rather than the anchor record. */
72
+ behindDoc: boolean;
73
+ };
74
+ /**
75
+ * Every attribute `CT_Anchor` declares of its own, in schema order.
76
+ *
77
+ * The walk is over {@link DRAWING_ANCHOR_FLAG_KEYS} rather than a hand-written list, so
78
+ * a flag added to the model cannot be written by the parser and forgotten here.
79
+ */
80
+ declare const serializeAnchorAttributes: ({ anchor, wrap, behindDoc }: AnchorAttributesOptions) => string;
81
+ /**
82
+ * `wp:simplePos`, which `CT_Anchor` requires whether or not `@simplePos` says to
83
+ * use it, so an anchor that authored no offsets still writes the origin.
84
+ */
85
+ declare const serializeSimplePos: (anchor: document_d_exports.DrawingAnchor | undefined) => string;
86
+ //#endregion
87
+ export { AnchorAttributesOptions, DRAWING_ANCHOR_FLAG_KEYS, ResolvedEffectExtents, WORDPROCESSING_DRAWING_NAMESPACE_URIS, parseDrawingAnchor, resolveEffectExtents, resolveWrapDistances, serializeAnchorAttributes, serializeEffectExtent, serializeInlineAttributes, serializeSimplePos, serializeWrapDistanceAttributes, serializeWrapDistances };