@stll/folio-core 0.46.0 → 0.47.1

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 (370) hide show
  1. package/dist/ai-edits/apply.d.ts +17 -1
  2. package/dist/ai-edits/apply.js +31 -27
  3. package/dist/ai-edits/headless.d.ts +9 -2
  4. package/dist/ai-edits/headless.js +5 -3
  5. package/dist/ai-edits/read.d.ts +1 -0
  6. package/dist/ai-edits/read.js +1 -0
  7. package/dist/ai-edits/snapshot.js +32 -27
  8. package/dist/ai-edits/table-cell-mutations.js +15 -7
  9. package/dist/ai-edits/table-geometry.js +21 -18
  10. package/dist/ai-edits/table-template.js +2 -2
  11. package/dist/compare/compare.js +2 -1
  12. package/dist/compare/content-alignment.js +192 -46
  13. package/dist/compare/content-types.d.ts +8 -2
  14. package/dist/compare/content.js +2 -11
  15. package/dist/compare/plan.js +7 -4
  16. package/dist/compare/section-boundary-properties.js +1 -2
  17. package/dist/content-controls/checkboxDisplay.d.ts +8 -2
  18. package/dist/content-controls/checkboxDisplay.js +11 -5
  19. package/dist/content-controls/mutateContentControls.js +41 -42
  20. package/dist/controller/layoutPipeline.js +8 -3
  21. package/dist/display-list/build/buildDisplayList.js +7 -7
  22. package/dist/display-list/build/imagePrimitives.d.ts +4 -4
  23. package/dist/display-list/build/imagePrimitives.js +38 -20
  24. package/dist/display-list/build/pageBorderPrimitives.js +2 -1
  25. package/dist/display-list/build/paragraphPrimitives.js +93 -13
  26. package/dist/display-list/build/previewPrimitives.d.ts +10 -0
  27. package/dist/display-list/build/previewPrimitives.js +89 -0
  28. package/dist/display-list/build/strokes.d.ts +177 -8
  29. package/dist/display-list/build/strokes.js +167 -47
  30. package/dist/display-list/build/tablePrimitives.js +4 -2
  31. package/dist/display-list/build/textBoxPrimitives.js +6 -4
  32. package/dist/display-list/build/textDecorations.d.ts +15 -1
  33. package/dist/display-list/build/textDecorations.js +15 -1
  34. package/dist/display-list/dom/renderDisplayListToDom.js +1 -19
  35. package/dist/display-list/primitives.d.ts +13 -2
  36. package/dist/display-list/primitives.js +36 -1
  37. package/dist/document-operations.d.ts +9 -2
  38. package/dist/document-operations.js +5 -3
  39. package/dist/docx/attributeRemainder.d.ts +34 -1
  40. package/dist/docx/attributeRemainder.js +49 -3
  41. package/dist/docx/blockContentParser.d.ts +2 -0
  42. package/dist/docx/blockContentParser.js +39 -67
  43. package/dist/docx/blockPlainText.js +3 -1
  44. package/dist/docx/borderParser.js +26 -11
  45. package/dist/docx/builtInStyles.d.ts +8 -16
  46. package/dist/docx/builtInStyles.js +54 -17
  47. package/dist/docx/commentAnchorIndex.js +1 -1
  48. package/dist/docx/commentParser.js +3 -3
  49. package/dist/docx/commentRangeIntegrity.js +1 -1
  50. package/dist/docx/commentRangeJoin.js +1 -1
  51. package/dist/docx/commentReferenceNormalization.js +3 -2
  52. package/dist/docx/commentReplyMarkers.js +1 -1
  53. package/dist/docx/compatibility.js +56 -42
  54. package/dist/docx/containerChildren.d.ts +110 -13
  55. package/dist/docx/containerChildren.gen.d.ts +16 -1
  56. package/dist/docx/containerChildren.gen.js +18 -1
  57. package/dist/docx/containerChildren.js +63 -13
  58. package/dist/docx/diagramPreview.d.ts +14 -2
  59. package/dist/docx/diagramPreview.js +81 -169
  60. package/dist/docx/documentParser.js +4 -1
  61. package/dist/docx/drawingAnchor.d.ts +87 -0
  62. package/dist/docx/drawingAnchor.js +201 -0
  63. package/dist/docx/drawingUtils.d.ts +43 -38
  64. package/dist/docx/drawingUtils.js +205 -118
  65. package/dist/docx/fontTableParser.js +102 -41
  66. package/dist/docx/footnoteParser.js +10 -6
  67. package/dist/docx/groupDrawingParser.js +4 -3
  68. package/dist/docx/headerFooterReferenceNormalization.js +1 -1
  69. package/dist/docx/hyperlinkParser.d.ts +45 -7
  70. package/dist/docx/hyperlinkParser.js +126 -57
  71. package/dist/docx/imageParser.js +127 -107
  72. package/dist/docx/index.d.ts +2 -1
  73. package/dist/docx/index.js +2 -1
  74. package/dist/docx/inlineContentRemovals.d.ts +28 -0
  75. package/dist/docx/inlineContentRemovals.js +46 -0
  76. package/dist/docx/inlineWrapperContent.d.ts +84 -3
  77. package/dist/docx/inlineWrapperContent.js +85 -4
  78. package/dist/docx/inlineWrapperParser.d.ts +11 -0
  79. package/dist/docx/inlineWrapperParser.js +60 -0
  80. package/dist/docx/nonVisualDrawingProps.d.ts +5 -13
  81. package/dist/docx/normalizeBaseDirection.js +4 -2
  82. package/dist/docx/numberingParser.d.ts +25 -2
  83. package/dist/docx/numberingParser.js +264 -361
  84. package/dist/docx/numberingReference.d.ts +9 -16
  85. package/dist/docx/numberingReference.js +17 -16
  86. package/dist/docx/numberingReferenceNormalization.js +7 -7
  87. package/dist/docx/ooxmlCounterFormatter.d.ts +1 -1
  88. package/dist/docx/ooxmlCounterFormatter.js +4 -1
  89. package/dist/docx/paraIdAttribute.d.ts +91 -1
  90. package/dist/docx/paraIdAttribute.js +79 -1
  91. package/dist/docx/paragraphParser.d.ts +9 -24
  92. package/dist/docx/paragraphParser.js +212 -396
  93. package/dist/docx/paragraphProperties.d.ts +23 -0
  94. package/dist/docx/paragraphProperties.js +279 -0
  95. package/dist/docx/paragraphPropertySource.js +2 -0
  96. package/dist/docx/paragraphTextBoxEnrichment.d.ts +2 -1
  97. package/dist/docx/paragraphTextBoxEnrichment.js +14 -7
  98. package/dist/docx/paragraphTraversal.d.ts +14 -10
  99. package/dist/docx/paragraphTraversal.js +47 -49
  100. package/dist/docx/parseWarningMessage.js +3 -0
  101. package/dist/docx/parserEnums.d.ts +6 -8
  102. package/dist/docx/parserEnums.js +4 -6
  103. package/dist/docx/preservedRunContent.js +16 -6
  104. package/dist/docx/previewBudget.d.ts +44 -23
  105. package/dist/docx/previewBudget.js +61 -30
  106. package/dist/docx/propertyElementAttributes.d.ts +178 -0
  107. package/dist/docx/propertyElementAttributes.js +114 -0
  108. package/dist/docx/renderedPageBreakNormalization.js +2 -2
  109. package/dist/docx/rezip.d.ts +28 -2
  110. package/dist/docx/rezip.js +78 -9
  111. package/dist/docx/runConsolidator.d.ts +42 -2
  112. package/dist/docx/runConsolidator.js +60 -6
  113. package/dist/docx/runParser.d.ts +54 -18
  114. package/dist/docx/runParser.js +379 -295
  115. package/dist/docx/runPayload.d.ts +5 -0
  116. package/dist/docx/runPayload.js +4 -0
  117. package/dist/docx/sdtProperties.d.ts +39 -5
  118. package/dist/docx/sdtProperties.js +205 -84
  119. package/dist/docx/sdtPropertiesPatch.d.ts +5 -9
  120. package/dist/docx/sdtPropertiesPatch.js +68 -112
  121. package/dist/docx/sectionParser.d.ts +1 -2
  122. package/dist/docx/sectionParser.js +236 -240
  123. package/dist/docx/selectiveSave.js +3 -2
  124. package/dist/docx/selectiveXmlPatch.d.ts +21 -2
  125. package/dist/docx/selectiveXmlPatch.js +195 -99
  126. package/dist/docx/serializer/blockSdtSerializer.js +2 -96
  127. package/dist/docx/serializer/borderSerializer.d.ts +5 -5
  128. package/dist/docx/serializer/borderSerializer.js +10 -8
  129. package/dist/docx/serializer/documentSerializer.js +3 -0
  130. package/dist/docx/serializer/fontTableSerializer.js +31 -3
  131. package/dist/docx/serializer/headerFooterSerializer.js +3 -0
  132. package/dist/docx/serializer/markupRangeAttributes.d.ts +9 -1
  133. package/dist/docx/serializer/markupRangeAttributes.js +9 -1
  134. package/dist/docx/serializer/noteSerializer.js +3 -0
  135. package/dist/docx/serializer/numberingSerializer.d.ts +1 -6
  136. package/dist/docx/serializer/numberingSerializer.js +81 -79
  137. package/dist/docx/serializer/paragraphSerializer.d.ts +1 -9
  138. package/dist/docx/serializer/paragraphSerializer.js +88 -188
  139. package/dist/docx/serializer/runSerializer.d.ts +1 -5
  140. package/dist/docx/serializer/runSerializer.js +109 -59
  141. package/dist/docx/serializer/sdtPropertiesSerializer.d.ts +26 -0
  142. package/dist/docx/serializer/sdtPropertiesSerializer.js +111 -0
  143. package/dist/docx/serializer/sectionPropertiesSerializer.js +34 -45
  144. package/dist/docx/serializer/settingsSerializer.js +6 -4
  145. package/dist/docx/serializer/stylesSerializer.js +8 -11
  146. package/dist/docx/serializer/tableSerializer.js +268 -100
  147. package/dist/docx/serializer/textFormattingSerializer.d.ts +28 -4
  148. package/dist/docx/serializer/textFormattingSerializer.js +111 -101
  149. package/dist/docx/serializer/xmlUtils.d.ts +1 -1
  150. package/dist/docx/serializer/xmlUtils.js +1 -1
  151. package/dist/docx/server/createBilingualDocument.js +18 -16
  152. package/dist/docx/server/migrateYjsAttrSchema.js +3 -3
  153. package/dist/docx/settingsParser.js +7 -4
  154. package/dist/docx/shadingParser.d.ts +2 -1
  155. package/dist/docx/shadingParser.js +43 -7
  156. package/dist/docx/shapeParser.js +8 -3
  157. package/dist/docx/strictNames.d.ts +11 -0
  158. package/dist/docx/strictNames.gen.d.ts +45 -0
  159. package/dist/docx/strictNames.gen.js +50 -0
  160. package/dist/docx/strictNames.js +43 -0
  161. package/dist/docx/strictValueEncodings.gen.js +133 -131
  162. package/dist/docx/styleParser.js +17 -349
  163. package/dist/docx/tableParser.d.ts +10 -1
  164. package/dist/docx/tableParser.js +505 -181
  165. package/dist/docx/textBoxParser.d.ts +3 -1
  166. package/dist/docx/textBoxParser.js +18 -8
  167. package/dist/docx/themeColorAttribute.d.ts +13 -0
  168. package/dist/docx/themeColorAttribute.js +24 -0
  169. package/dist/docx/trackedMoveRangeNormalization.js +2 -1
  170. package/dist/docx/vmlImageParser.d.ts +13 -4
  171. package/dist/docx/vmlImageParser.js +74 -31
  172. package/dist/docx/vmlPreview.js +2 -2
  173. package/dist/docx/wrapPolygon.d.ts +30 -0
  174. package/dist/docx/wrapPolygon.js +70 -0
  175. package/dist/docx/xmlParser.d.ts +14 -1
  176. package/dist/docx/xmlParser.js +18 -2
  177. package/dist/fonts/embeddedFonts.js +3 -3
  178. package/dist/headless-layout.js +2 -0
  179. package/dist/i18n/messages/catalogs.gen.d.ts +68 -0
  180. package/dist/i18n/messages/catalogs.gen.js +102 -34
  181. package/dist/i18n/messages/messages.gen.d.ts +4 -0
  182. package/dist/internal/headlessRevisionResolution.js +9 -0
  183. package/dist/internal/pageBreakRunSourceDescendantIndex.js +3 -1
  184. package/dist/internal/paragraphFormattingSerialization.d.ts +20 -9
  185. package/dist/internal/paragraphFormattingSerialization.js +118 -83
  186. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  187. package/dist/layout-bridge/convert/footnoteLayout.js +1 -0
  188. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  189. package/dist/layout-bridge/convert/headerFooterLayout.js +2 -0
  190. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +17 -12
  191. package/dist/layout-bridge/convert/toFlowBlocks.js +177 -101
  192. package/dist/layout-engine/index.d.ts +2 -2
  193. package/dist/layout-engine/index.js +53 -17
  194. package/dist/layout-engine/measure/measureBlocks.d.ts +3 -0
  195. package/dist/layout-engine/measure/measureBlocks.js +6 -10
  196. package/dist/layout-engine/measure/tableCellGrid.js +2 -1
  197. package/dist/layout-engine/measure/tableFragmentBorderGeometry.js +2 -1
  198. package/dist/layout-engine/measure/tableInlinePlacement.js +2 -5
  199. package/dist/layout-engine/paragraphSequence.js +3 -2
  200. package/dist/layout-engine/renderedBreakReconciliation.js +2 -1
  201. package/dist/layout-engine/section-breaks.d.ts +49 -2
  202. package/dist/layout-engine/section-breaks.js +55 -4
  203. package/dist/layout-engine/types.d.ts +47 -17
  204. package/dist/layout-engine/types.js +16 -1
  205. package/dist/layout-painter/borderStroke.d.ts +18 -4
  206. package/dist/layout-painter/renderPage.js +6 -4
  207. package/dist/layout-painter/renderParagraph.d.ts +2 -1
  208. package/dist/layout-painter/renderParagraph.js +13 -26
  209. package/dist/layout-painter/renderTable.d.ts +4 -1
  210. package/dist/layout-painter/renderTable.js +22 -22
  211. package/dist/layout-painter/renderTextBox.js +5 -3
  212. package/dist/markdown/renderBlock.js +3 -1
  213. package/dist/markdown/renderRuns.js +7 -2
  214. package/dist/markdown/renderTable.js +2 -1
  215. package/dist/model.d.ts +3 -3
  216. package/dist/model.js +2 -2
  217. package/dist/paged-layout/sectionBlockWidths.d.ts +3 -0
  218. package/dist/paged-layout/sectionBlockWidths.js +26 -4
  219. package/dist/prosemirror/attrs/index.d.ts +22 -4
  220. package/dist/prosemirror/attrs/index.js +498 -60
  221. package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +9 -1
  222. package/dist/prosemirror/bookmarkBoundaryAttrs.js +22 -3
  223. package/dist/prosemirror/commands/comments.js +68 -53
  224. package/dist/prosemirror/commands/contentControls.js +24 -19
  225. package/dist/prosemirror/commands/image.d.ts +1 -1
  226. package/dist/prosemirror/commands/image.js +4 -1
  227. package/dist/prosemirror/commands/paragraph.d.ts +2 -1
  228. package/dist/prosemirror/commands/propertyChangeScope.d.ts +12 -4
  229. package/dist/prosemirror/commands/propertyChangeScope.js +22 -4
  230. package/dist/prosemirror/commands/sectionBreak.d.ts +33 -1
  231. package/dist/prosemirror/commands/sectionBreak.js +187 -11
  232. package/dist/prosemirror/conversion/fromProseDoc.d.ts +18 -2
  233. package/dist/prosemirror/conversion/fromProseDoc.js +330 -183
  234. package/dist/prosemirror/conversion/index.d.ts +2 -2
  235. package/dist/prosemirror/conversion/preservedSinkCarriers.d.ts +39 -0
  236. package/dist/prosemirror/conversion/preservedSinkCarriers.js +19 -0
  237. package/dist/prosemirror/conversion/runShadingMark.js +14 -1
  238. package/dist/prosemirror/conversion/sdtAttrs.d.ts +10 -1
  239. package/dist/prosemirror/conversion/sdtAttrs.js +19 -5
  240. package/dist/prosemirror/conversion/toProseDoc.js +371 -141
  241. package/dist/prosemirror/emptyRangeAnchor.d.ts +53 -0
  242. package/dist/prosemirror/emptyRangeAnchor.js +158 -0
  243. package/dist/prosemirror/extensions/StarterKit.js +8 -2
  244. package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
  245. package/dist/prosemirror/extensions/core/ParagraphExtension.js +19 -15
  246. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
  247. package/dist/prosemirror/extensions/features/ListExtension.js +43 -24
  248. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +4 -3
  249. package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +3 -3
  250. package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +5 -5
  251. package/dist/prosemirror/extensions/features/pasteCleanup.d.ts +3 -1
  252. package/dist/prosemirror/extensions/features/pasteCleanup.js +56 -2
  253. package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +5 -4
  254. package/dist/prosemirror/extensions/markRegistry.d.ts +26 -2
  255. package/dist/prosemirror/extensions/markRegistry.js +73 -10
  256. package/dist/prosemirror/extensions/marks/InlineWrapperExtension.js +17 -3
  257. package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +26 -0
  258. package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +134 -0
  259. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +2 -1
  260. package/dist/prosemirror/extensions/marks/UnderlineExtension.js +12 -18
  261. package/dist/prosemirror/extensions/marks/markUtils.js +2 -1
  262. package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.d.ts +29 -0
  263. package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.js +46 -0
  264. package/dist/prosemirror/extensions/nodes/BlockSdtExtension.d.ts +4 -3
  265. package/dist/prosemirror/extensions/nodes/BlockSdtExtension.js +18 -13
  266. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +28 -53
  267. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +10 -0
  268. package/dist/prosemirror/extensions/nodes/ImageExtension.js +8 -1
  269. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.d.ts +11 -0
  270. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +43 -0
  271. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.d.ts +13 -0
  272. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +65 -0
  273. package/dist/prosemirror/extensions/nodes/SdtExtension.d.ts +3 -1
  274. package/dist/prosemirror/extensions/nodes/SdtExtension.js +22 -16
  275. package/dist/prosemirror/extensions/nodes/ShapeExtension.js +4 -0
  276. package/dist/prosemirror/extensions/nodes/TableExtension.js +141 -123
  277. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +4 -0
  278. package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.d.ts +23 -0
  279. package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.js +57 -0
  280. package/dist/prosemirror/extensions/types.d.ts +12 -3
  281. package/dist/prosemirror/index.d.ts +4 -2
  282. package/dist/prosemirror/index.js +2 -1
  283. package/dist/prosemirror/inlineWrapperStack.js +20 -3
  284. package/dist/prosemirror/listMarker.d.ts +2 -2
  285. package/dist/prosemirror/listMarker.js +7 -8
  286. package/dist/prosemirror/listRenderingAttrs.js +11 -1
  287. package/dist/prosemirror/listState.d.ts +62 -0
  288. package/dist/prosemirror/listState.js +49 -0
  289. package/dist/prosemirror/moveRangeBoundaryAttrs.d.ts +13 -0
  290. package/dist/prosemirror/moveRangeBoundaryAttrs.js +114 -0
  291. package/dist/prosemirror/numberedRefFields.js +4 -4
  292. package/dist/prosemirror/numberingAttr.d.ts +55 -0
  293. package/dist/prosemirror/numberingAttr.js +74 -0
  294. package/dist/prosemirror/outlineLevelAttr.d.ts +29 -0
  295. package/dist/prosemirror/outlineLevelAttr.js +42 -0
  296. package/dist/prosemirror/paragraphFormattingProvenance.d.ts +9 -0
  297. package/dist/prosemirror/paragraphFormattingProvenance.js +4 -1
  298. package/dist/prosemirror/plugins/selectionTracker.d.ts +3 -6
  299. package/dist/prosemirror/plugins/selectionTracker.js +3 -10
  300. package/dist/prosemirror/rangeAnchorAttrs.d.ts +14 -0
  301. package/dist/prosemirror/rangeAnchorAttrs.js +101 -0
  302. package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
  303. package/dist/prosemirror/replacedAnnotations.js +24 -6
  304. package/dist/prosemirror/revisionCarriers.d.ts +86 -2
  305. package/dist/prosemirror/revisionCarriers.js +86 -60
  306. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +2 -0
  307. package/dist/prosemirror/runFormattingInlineCarriers.js +2 -0
  308. package/dist/prosemirror/runIdentity.d.ts +28 -0
  309. package/dist/prosemirror/runIdentity.js +36 -0
  310. package/dist/prosemirror/runStyleFormatting.js +1 -1
  311. package/dist/prosemirror/schema/index.d.ts +2 -2
  312. package/dist/prosemirror/schema/marks.d.ts +23 -4
  313. package/dist/prosemirror/schema/nodes.d.ts +220 -24
  314. package/dist/prosemirror/sectionCarrier.d.ts +37 -0
  315. package/dist/prosemirror/sectionCarrier.js +40 -0
  316. package/dist/prosemirror/selectionState.d.ts +3 -0
  317. package/dist/prosemirror/selectionState.js +4 -1
  318. package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +5 -4
  319. package/dist/prosemirror/styles/resolvedStyleAttrs.js +15 -13
  320. package/dist/prosemirror/tableResize.js +5 -6
  321. package/dist/prosemirror/trackedRunInlineAtoms.d.ts +2 -0
  322. package/dist/prosemirror/trackedRunInlineAtoms.js +2 -0
  323. package/dist/prosemirror/utils/extractTrackedChanges.d.ts +10 -11
  324. package/dist/prosemirror/utils/extractTrackedChanges.js +109 -92
  325. package/dist/prosemirror/validation.js +17 -6
  326. package/dist/prosemirror/yjsDocumentMetadata.d.ts +2 -2
  327. package/dist/prosemirror/yjsDocumentMetadata.js +428 -7
  328. package/dist/prosemirror/zeroWidthAnchors.js +4 -0
  329. package/dist/style-sets/extract.js +4 -4
  330. package/dist/style-sets/stellaStyle.js +36 -23
  331. package/dist/types/colors.d.ts +2 -2
  332. package/dist/types/content.d.ts +2 -2
  333. package/dist/types/documentEnumValues.d.ts +53 -26
  334. package/dist/types/documentEnumValues.js +72 -174
  335. package/dist/types/formatting.d.ts +2 -2
  336. package/dist/types/index.d.ts +9 -2
  337. package/dist/utils/borderCss.d.ts +246 -0
  338. package/dist/utils/borderCss.js +325 -0
  339. package/dist/utils/colorResolver.d.ts +4 -3
  340. package/dist/utils/colorResolver.js +45 -76
  341. package/dist/utils/createDocument.js +24 -6
  342. package/dist/utils/findReplace.js +52 -10
  343. package/dist/utils/formatToStyle.d.ts +84 -2
  344. package/dist/utils/formatToStyle.js +133 -52
  345. package/dist/utils/headingCollector.js +3 -2
  346. package/dist/utils/mergeDocumentContent.js +5 -3
  347. package/dist/utils/paragraphFormattingMerge.js +27 -6
  348. package/dist/utils/replaceText.js +1 -1
  349. package/dist/utils/tableOperations.d.ts +5 -3
  350. package/dist/utils/tableOperations.js +14 -1
  351. package/dist/utils/tablePlacement.d.ts +7 -0
  352. package/dist/utils/tablePlacement.js +14 -0
  353. package/dist/utils/textDirectionFlow.d.ts +15 -0
  354. package/dist/utils/textDirectionFlow.js +38 -0
  355. package/dist/utils/textFormattingMerge.js +16 -4
  356. package/package.json +10 -10
  357. package/dist/ai-edits/__fixtures__/paragraphs.d.ts +0 -17
  358. package/dist/ai-edits/__fixtures__/paragraphs.js +0 -33
  359. package/dist/compare/__fixtures__/body-sequence.d.ts +0 -119
  360. package/dist/compare/__fixtures__/body-sequence.js +0 -225
  361. package/dist/compare/__fixtures__/nested-table.d.ts +0 -16
  362. package/dist/compare/__fixtures__/nested-table.js +0 -50
  363. package/dist/compare/__fixtures__/numbered-list.d.ts +0 -34
  364. package/dist/compare/__fixtures__/numbered-list.js +0 -85
  365. package/dist/docx/bookmarkPlacement.d.ts +0 -9
  366. package/dist/docx/bookmarkPlacement.js +0 -52
  367. package/dist/fonts/embeddedFontTable.d.ts +0 -45
  368. package/dist/fonts/embeddedFontTable.js +0 -80
  369. package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.d.ts +0 -13
  370. package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.js +0 -39
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/folio-core",
3
- "version": "0.46.0",
3
+ "version": "0.47.1",
4
4
  "description": "Headless, framework-neutral core of folio: the OOXML (.docx) parser, document model, ProseMirror integration, and page-layout engine. No React.",
5
5
  "keywords": [
6
6
  "document-model",
@@ -24,6 +24,13 @@
24
24
  "url": "https://github.com/stella/folio.git",
25
25
  "directory": "packages/core"
26
26
  },
27
+ "files": [
28
+ "dist",
29
+ "skills",
30
+ "README.md",
31
+ "LICENSE",
32
+ "NOTICE.md"
33
+ ],
27
34
  "type": "module",
28
35
  "sideEffects": false,
29
36
  "exports": {
@@ -121,7 +128,7 @@
121
128
  "perf": "bun scripts/profile-editor.ts"
122
129
  },
123
130
  "dependencies": {
124
- "@stll/docx-core": "^0.24.0",
131
+ "@stll/docx-core": "^0.25.0",
125
132
  "@stll/docx-utils": "^0.1.0",
126
133
  "@stll/template-conditions": ">=0.4.0 <1.0.0",
127
134
  "better-result": "3.0.1",
@@ -152,12 +159,5 @@
152
159
  "@types/hyphen": "1.14.0"
153
160
  },
154
161
  "main": "./dist/index.js",
155
- "types": "./dist/index.d.ts",
156
- "files": [
157
- "dist",
158
- "skills",
159
- "README.md",
160
- "LICENSE",
161
- "NOTICE.md"
162
- ]
162
+ "types": "./dist/index.d.ts"
163
163
  }
@@ -1,17 +0,0 @@
1
- //#region src/ai-edits/__fixtures__/paragraphs.d.ts
2
- /**
3
- * The smallest `.docx` that carries a list of paragraphs, generated rather
4
- * than committed as bytes so a test's input is legible in its own diff.
5
- */
6
- type ParagraphsDocxOptions = {
7
- /**
8
- * Wrap the paragraphs in a single table cell, followed by one body
9
- * paragraph. The cell's last paragraph then has a sibling in the document
10
- * and none in its own container, which is the case a paragraph-mark
11
- * deletion must refuse.
12
- */
13
- inTableCell?: boolean;
14
- };
15
- declare const buildParagraphsDocx: (paragraphs: readonly string[], { inTableCell }?: ParagraphsDocxOptions) => Promise<ArrayBuffer>;
16
- //#endregion
17
- export { ParagraphsDocxOptions, buildParagraphsDocx };
@@ -1,33 +0,0 @@
1
- import { escapeXmlText } from "@stll/docx-core";
2
- import JSZip from "jszip";
3
- //#region src/ai-edits/__fixtures__/paragraphs.ts
4
- /**
5
- * The smallest `.docx` that carries a list of paragraphs, generated rather
6
- * than committed as bytes so a test's input is legible in its own diff.
7
- */
8
- const NAMESPACE = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
9
- const RELATIONSHIPS = "http://schemas.openxmlformats.org/package/2006/relationships";
10
- const OFFICE_RELATIONSHIPS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
11
- const WORDPROCESSING = "application/vnd.openxmlformats-officedocument.wordprocessingml";
12
- /** Pinned, with no folder entries, so two builds produce identical bytes. */
13
- const ZIP_ENTRY_OPTIONS = {
14
- date: new Date(Date.UTC(2e3, 0, 1)),
15
- createFolders: false
16
- };
17
- const paragraphXml = (text) => `<w:p><w:r><w:t xml:space="preserve">${escapeXmlText(text)}</w:t></w:r></w:p>`;
18
- const buildParagraphsDocx = async (paragraphs, { inTableCell } = {}) => {
19
- const paragraphsXml = paragraphs.map(paragraphXml).join("");
20
- const body = inTableCell ? `<w:tbl><w:tblPr><w:tblW w:w="0" w:type="auto"/></w:tblPr><w:tblGrid><w:gridCol w:w="9360"/></w:tblGrid><w:tr><w:tc><w:tcPr><w:tcW w:w="9360" w:type="dxa"/></w:tcPr>${paragraphsXml}</w:tc></w:tr></w:tbl>` + paragraphXml("After the table.") : paragraphsXml;
21
- const parts = {
22
- "[Content_Types].xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/word/document.xml" ContentType="${WORDPROCESSING}.document.main+xml"/><Override PartName="/word/styles.xml" ContentType="${WORDPROCESSING}.styles+xml"/></Types>`,
23
- "_rels/.rels": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="${RELATIONSHIPS}"><Relationship Id="rId1" Type="${OFFICE_RELATIONSHIPS}/officeDocument" Target="word/document.xml"/></Relationships>`,
24
- "word/_rels/document.xml.rels": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="${RELATIONSHIPS}"><Relationship Id="rId1" Type="${OFFICE_RELATIONSHIPS}/styles" Target="styles.xml"/></Relationships>`,
25
- "word/styles.xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:styles xmlns:w="${NAMESPACE}"><w:style w:type="paragraph" w:default="1" w:styleId="Normal"><w:name w:val="Normal"/></w:style></w:styles>`,
26
- "word/document.xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:document xmlns:w="${NAMESPACE}"><w:body>${body}<w:sectPr><w:pgSz w:w="12240" w:h="15840"/></w:sectPr></w:body></w:document>`
27
- };
28
- const zip = new JSZip();
29
- for (const name of Object.keys(parts).toSorted()) zip.file(name, parts[name] ?? "", ZIP_ENTRY_OPTIONS);
30
- return await zip.generateAsync({ type: "arraybuffer" });
31
- };
32
- //#endregion
33
- export { buildParagraphsDocx };
@@ -1,119 +0,0 @@
1
- //#region src/compare/__fixtures__/body-sequence.d.ts
2
- /**
3
- * A document body written from a sequence of paragraphs and tables.
4
- *
5
- * The edit-script DSL can move words and rows but cannot append a table, so a
6
- * pair whose difference is "a paragraph AND a table were added after the last
7
- * one" has to be authored as two packages. Generating both from one description
8
- * keeps the difference visible in the diff instead of hidden in bytes.
9
- */
10
- /**
11
- * One cell's content: a line of text, or a sequence of its own — which is how
12
- * a nested table, a blank line inside a cell, or a cell that ends with a table
13
- * gets written.
14
- */
15
- type CellContent = string | readonly BodyItem[];
16
- /** `w:tcPr` children a fixture can author, each named after the element. */
17
- type CellProperties = {
18
- /** `w:gridSpan`: grid columns this cell occupies. */
19
- gridSpan?: number;
20
- /** `w:vMerge`: the cell starts a vertical merge, or continues one. */
21
- verticalMerge?: "restart" | "continue";
22
- /** `w:tcW` in twips. */
23
- width?: number;
24
- /** `w:shd` fill colour, as six hex digits. */
25
- shadingFill?: string;
26
- /** `w:vAlign`. */
27
- verticalAlign?: "top" | "center" | "bottom";
28
- /** `w:tcBorders`, single style on all four sides, in eighths of a point. */
29
- borderSize?: number;
30
- /** `w:tcMar`, the same margin on all four sides, in twips. */
31
- margin?: number;
32
- };
33
- /** A cell: its content alone, or its content and its own `w:tcPr`. */
34
- type Cell = CellContent | ({
35
- content: CellContent;
36
- } & CellProperties);
37
- /** A row: its cells alone, or its cells and its own `w:trPr`. */
38
- type TableRow = readonly Cell[] | {
39
- cells: readonly Cell[];
40
- /** `w:trHeight` in twips. */
41
- height?: number;
42
- /** `w:tblHeader`: the row repeats at the top of every page. */
43
- header?: boolean;
44
- /** `w:jc` on the row. */
45
- justification?: "left" | "center" | "right";
46
- };
47
- /** `w:tblPr` children a fixture can author, each named after the element. */
48
- type TableProperties = {
49
- /** `w:tblStyle`. */
50
- styleId?: string;
51
- /** `w:tblW`. */
52
- width?: {
53
- value: number;
54
- type: "auto" | "dxa" | "pct";
55
- };
56
- /** `w:bidiVisual`. */
57
- bidi?: boolean;
58
- /** `w:jc` on the table. */
59
- justification?: "left" | "center" | "right";
60
- /** `w:tblInd` in twips. */
61
- indent?: number;
62
- /** `w:tblCellSpacing` in twips. */
63
- cellSpacing?: number;
64
- /** `w:tblBorders`, single style on every side, in eighths of a point. */
65
- borderSize?: number;
66
- /** `w:shd` fill colour on the table, as six hex digits. */
67
- shadingFill?: string;
68
- /** `w:tblLayout`. */
69
- layout?: "fixed" | "autofit";
70
- /** `w:tblCellMar`, the same margin on all four sides, in twips. */
71
- cellMargin?: number;
72
- /** `w:tblLook` value, as four hex digits. */
73
- look?: string;
74
- };
75
- /**
76
- * One inline of a paragraph: plain text, or text carrying an external
77
- * hyperlink. A link is the case where a revision wrapper and the linked runs
78
- * have to nest one inside the other, so the fixture has to be able to author
79
- * one.
80
- */
81
- type ParagraphInline = string | {
82
- text: string;
83
- href: string;
84
- };
85
- /** One body-level item: a paragraph, or a table given row by row. */
86
- type BodyItem = {
87
- kind: "paragraph";
88
- text: string | readonly ParagraphInline[];
89
- styleId?: string;
90
- /**
91
- * An authored `w14:paraId`, for a package whose ids a producer wrote
92
- * without respecting the 31-bit bound the schema puts on them.
93
- */
94
- paraId?: string;
95
- } | {
96
- kind: "table";
97
- rows: readonly TableRow[];
98
- /** `w:tblPr` children, written in the order the schema requires. */
99
- properties?: TableProperties;
100
- /** `w:tblGrid` column widths, in twips. One per grid column. */
101
- columnWidths?: readonly number[];
102
- /**
103
- * Rows a package hides with `w:hidden`. The snapshot skips their whole
104
- * subtree, so a document that has one is the case where the snapshot
105
- * walk and the live walk could disagree.
106
- */
107
- hiddenRows?: readonly number[];
108
- };
109
- type BodySequenceOptions = {
110
- /**
111
- * A default header part, written as its own sequence. A header is a story of
112
- * its own: it ends with its own paragraph, and a comparison writes it with
113
- * its own revision ids.
114
- */
115
- header?: readonly BodyItem[];
116
- };
117
- declare const buildBodySequenceDocx: (items: readonly BodyItem[], { header }?: BodySequenceOptions) => Promise<ArrayBuffer>;
118
- //#endregion
119
- export { BodyItem, BodySequenceOptions, Cell, CellContent, CellProperties, ParagraphInline, TableProperties, TableRow, buildBodySequenceDocx };
@@ -1,225 +0,0 @@
1
- import JSZip from "jszip";
2
- //#region src/compare/__fixtures__/body-sequence.ts
3
- /**
4
- * A document body written from a sequence of paragraphs and tables.
5
- *
6
- * The edit-script DSL can move words and rows but cannot append a table, so a
7
- * pair whose difference is "a paragraph AND a table were added after the last
8
- * one" has to be authored as two packages. Generating both from one description
9
- * keeps the difference visible in the diff instead of hidden in bytes.
10
- */
11
- const NAMESPACE = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
12
- const RELATIONSHIPS = "http://schemas.openxmlformats.org/package/2006/relationships";
13
- const OFFICE_RELATIONSHIPS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
14
- const WORDPROCESSING = "application/vnd.openxmlformats-officedocument.wordprocessingml";
15
- const MARKUP_COMPATIBILITY = "http://schemas.openxmlformats.org/markup-compatibility/2006";
16
- const PACKAGE_RELATIONSHIPS = "http://schemas.openxmlformats.org/package/2006";
17
- const CORE_PROPERTIES_TYPE = "application/vnd.openxmlformats-package.core-properties+xml";
18
- const EXTENDED_PROPERTIES = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties";
19
- const EXTENDED_PROPERTIES_TYPE = "application/vnd.openxmlformats-officedocument.extended-properties+xml";
20
- const WORDML_2010 = "http://schemas.microsoft.com/office/word/2010/wordml";
21
- /**
22
- * `createFolders: false` because JSZip stamps the folder entries it
23
- * synthesizes with `new Date()`, which the fixed date above does not reach.
24
- */
25
- const ZIP_ENTRY_OPTIONS = {
26
- date: new Date(Date.UTC(2e3, 0, 1)),
27
- createFolders: false
28
- };
29
- const isRowOptions = (row) => "cells" in row;
30
- const isCellSpec = (cell) => typeof cell === "object" && "content" in cell;
31
- const rowCells = (row) => isRowOptions(row) ? row.cells : row;
32
- const rowOptions = (row) => isRowOptions(row) ? row : {};
33
- const cellContent = (cell) => isCellSpec(cell) ? cell.content : cell;
34
- const cellProperties = (cell) => isCellSpec(cell) ? cell : {};
35
- /**
36
- * A paragraph's id is derived from its own content, not from its position.
37
- *
38
- * Two packages authored from two descriptions are a base and a target, and a
39
- * paragraph that appears in both is the same paragraph. Numbering the ids in
40
- * document order would instead give the same id to the paragraph that happens
41
- * to sit at the same index, which is how the fixture would tell a comparison
42
- * that a removed paragraph was a rewrite of the one after it.
43
- */
44
- const createParaIdAllocator = () => {
45
- const taken = /* @__PURE__ */ new Set();
46
- return (content) => {
47
- let hash = 2166136261;
48
- for (let index = 0; index < content.length; index += 1) hash = Math.imul(hash ^ content.charCodeAt(index), 16777619) >>> 0;
49
- let candidate = hash % 2147483646;
50
- while (taken.has((candidate + 1).toString(16).toUpperCase().padStart(8, "0"))) candidate = (candidate + 1) % 2147483646;
51
- const paraId = (candidate + 1).toString(16).toUpperCase().padStart(8, "0");
52
- taken.add(paraId);
53
- return paraId;
54
- };
55
- };
56
- const run = (text) => `<w:r><w:t xml:space="preserve">${text}</w:t></w:r>`;
57
- const inlineXml = (inline, { links }) => typeof inline === "string" ? run(inline) : `<w:hyperlink r:id="${links.get(inline.href) ?? ""}">${run(inline.text)}</w:hyperlink>`;
58
- /**
59
- * An empty paragraph is a `w:p` with no run at all, which is what a package
60
- * holds for a blank line or an empty cell. It is not the same thing as a
61
- * paragraph whose run carries an empty string, and both shapes occur.
62
- */
63
- /** A blank line carries no run at all, so an empty string is no inline. */
64
- const nonEmptyInlines = (text) => text.length === 0 ? [] : [text];
65
- const paragraph = (text, context, { styleId, paraId } = {}) => {
66
- const properties = styleId === void 0 ? "" : `<w:pPr><w:pStyle w:val="${styleId}"/></w:pPr>`;
67
- const inlines = typeof text === "string" ? nonEmptyInlines(text) : text;
68
- const content = inlines.map((inline) => typeof inline === "string" ? inline : inline.text).join("");
69
- const id = paraId ?? context.paraId(`${styleId ?? ""}|${content}`);
70
- return `<w:p w14:paraId="${id}" w14:textId="${id}">${properties}${inlines.map((inline) => inlineXml(inline, context)).join("")}</w:p>`;
71
- };
72
- /** Every href the body carries, in document order, so the ids are stable. */
73
- const collectHrefs = (items, hrefs) => {
74
- for (const item of items) {
75
- if (item.kind === "paragraph") {
76
- if (typeof item.text === "string") continue;
77
- for (const inline of item.text) if (typeof inline !== "string" && !hrefs.includes(inline.href)) hrefs.push(inline.href);
78
- continue;
79
- }
80
- for (const row of item.rows) for (const cell of rowCells(row)) {
81
- const content = cellContent(cell);
82
- if (typeof content !== "string") collectHrefs(content, hrefs);
83
- }
84
- }
85
- };
86
- const EMPTY_PARAGRAPH = {
87
- kind: "paragraph",
88
- text: ""
89
- };
90
- /**
91
- * Most fixtures add a paragraph after a table so later paragraph insertions
92
- * have an explicit anchor. Tests for a schema-valid terminal table remove that
93
- * convenience paragraph deliberately.
94
- */
95
- const closedSequence = (items) => {
96
- const last = items.at(-1);
97
- return last === void 0 || last.kind === "table" ? [...items, EMPTY_PARAGRAPH] : items;
98
- };
99
- /** A cell must also contain a paragraph, which the empty sequence supplies. */
100
- const cellXml = (content, context) => typeof content === "string" ? paragraph(content, context) : itemsXml(closedSequence(content), context);
101
- /** `w:tbl` is `w:tblPr, w:tblGrid, rows`: a fixture without the grid is not one. */
102
- const tableGrid = (item) => {
103
- if (item.columnWidths) return `<w:tblGrid>${item.columnWidths.map((width) => `<w:gridCol w:w="${String(width)}"/>`).join("")}</w:tblGrid>`;
104
- let columns = 0;
105
- for (const row of item.rows) {
106
- let spanned = 0;
107
- for (const cell of rowCells(row)) spanned += cellProperties(cell).gridSpan ?? 1;
108
- columns = Math.max(columns, spanned);
109
- }
110
- return `<w:tblGrid>${`<w:gridCol w:w="2000"/>`.repeat(columns)}</w:tblGrid>`;
111
- };
112
- const BORDER_SIDES = [
113
- "top",
114
- "left",
115
- "bottom",
116
- "right",
117
- "insideH",
118
- "insideV"
119
- ];
120
- const CELL_BORDER_SIDES = [
121
- "top",
122
- "left",
123
- "bottom",
124
- "right"
125
- ];
126
- const MARGIN_SIDES = [
127
- "top",
128
- "left",
129
- "bottom",
130
- "right"
131
- ];
132
- const borders = (element, sides, size) => `<w:${element}>${sides.map((side) => `<w:${side} w:val="single" w:sz="${String(size)}" w:space="0" w:color="000000"/>`).join("")}</w:${element}>`;
133
- const margins = (element, value) => `<w:${element}>${MARGIN_SIDES.map((side) => `<w:${side} w:w="${String(value)}" w:type="dxa"/>`).join("")}</w:${element}>`;
134
- /**
135
- * `w:tblPr` children in the order CT_TblPrBase declares: tblStyle, bidiVisual,
136
- * tblW, jc, tblCellSpacing, tblInd, tblBorders, shd, tblLayout, tblCellMar,
137
- * tblLook. `w:tblW` is always written.
138
- */
139
- const tableProperties = ({ properties }) => {
140
- const width = properties?.width ?? {
141
- value: 0,
142
- type: "auto"
143
- };
144
- return `<w:tblPr>${[
145
- ...properties?.styleId === void 0 ? [] : [`<w:tblStyle w:val="${properties.styleId}"/>`],
146
- ...properties?.bidi === void 0 ? [] : [properties.bidi ? "<w:bidiVisual/>" : "<w:bidiVisual w:val=\"0\"/>"],
147
- `<w:tblW w:w="${String(width.value)}" w:type="${width.type}"/>`,
148
- ...properties?.justification === void 0 ? [] : [`<w:jc w:val="${properties.justification}"/>`],
149
- ...properties?.cellSpacing === void 0 ? [] : [`<w:tblCellSpacing w:w="${String(properties.cellSpacing)}" w:type="dxa"/>`],
150
- ...properties?.indent === void 0 ? [] : [`<w:tblInd w:w="${String(properties.indent)}" w:type="dxa"/>`],
151
- ...properties?.borderSize === void 0 ? [] : [borders("tblBorders", BORDER_SIDES, properties.borderSize)],
152
- ...properties?.shadingFill === void 0 ? [] : [`<w:shd w:val="clear" w:color="auto" w:fill="${properties.shadingFill}"/>`],
153
- ...properties?.layout === void 0 ? [] : [`<w:tblLayout w:type="${properties.layout}"/>`],
154
- ...properties?.cellMargin === void 0 ? [] : [margins("tblCellMar", properties.cellMargin)],
155
- ...properties?.look === void 0 ? [] : [`<w:tblLook w:val="${properties.look}"/>`]
156
- ].join("")}</w:tblPr>`;
157
- };
158
- /**
159
- * `w:trPr` children. `CT_TrPrBase` is a repeated choice rather than a
160
- * sequence, so the order here is the readable one rather than a required one.
161
- */
162
- const rowProperties = (row, hidden) => {
163
- const { header, height, justification } = rowOptions(row);
164
- const parts = [
165
- ...height === void 0 ? [] : [`<w:trHeight w:val="${String(height)}"/>`],
166
- ...header === true ? ["<w:tblHeader/>"] : [],
167
- ...justification === void 0 ? [] : [`<w:jc w:val="${justification}"/>`],
168
- ...hidden ? ["<w:hidden/>"] : []
169
- ];
170
- return parts.length === 0 ? "" : `<w:trPr>${parts.join("")}</w:trPr>`;
171
- };
172
- /** `w:tcPr` children in schema order; `w:tcW` is always written. */
173
- const cellPropertiesXml = (cell) => {
174
- const properties = cellProperties(cell);
175
- return `<w:tcPr>${[
176
- `<w:tcW w:w="${String(properties.width ?? 2e3)}" w:type="dxa"/>`,
177
- ...properties.gridSpan === void 0 ? [] : [`<w:gridSpan w:val="${String(properties.gridSpan)}"/>`],
178
- ...properties.verticalMerge === void 0 ? [] : [properties.verticalMerge === "restart" ? `<w:vMerge w:val="restart"/>` : `<w:vMerge/>`],
179
- ...properties.borderSize === void 0 ? [] : [borders("tcBorders", CELL_BORDER_SIDES, properties.borderSize)],
180
- ...properties.shadingFill === void 0 ? [] : [`<w:shd w:val="clear" w:color="auto" w:fill="${properties.shadingFill}"/>`],
181
- ...properties.margin === void 0 ? [] : [margins("tcMar", properties.margin)],
182
- ...properties.verticalAlign === void 0 ? [] : [`<w:vAlign w:val="${properties.verticalAlign}"/>`]
183
- ].join("")}</w:tcPr>`;
184
- };
185
- const table = (item, context) => {
186
- const hidden = new Set(item.hiddenRows ?? []);
187
- return `<w:tbl>${tableProperties(item)}` + tableGrid(item) + item.rows.map((row, rowIndex) => `<w:tr>${rowProperties(row, hidden.has(rowIndex))}${rowCells(row).map((cell) => `<w:tc>${cellPropertiesXml(cell)}${cellXml(cellContent(cell), context)}</w:tc>`).join("")}</w:tr>`).join("") + `</w:tbl>`;
188
- };
189
- const itemsXml = (items, context) => items.map((item) => item.kind === "paragraph" ? paragraph(item.text, context, {
190
- ...item.styleId === void 0 ? {} : { styleId: item.styleId },
191
- ...item.paraId === void 0 ? {} : { paraId: item.paraId }
192
- }) : table(item, context)).join("");
193
- const bodyXml = (items, context) => itemsXml(closedSequence(items), context);
194
- /** The relationship id the default header takes when a fixture asks for one. */
195
- const HEADER_RELATIONSHIP_ID = "rId2";
196
- const buildBodySequenceDocx = async (items, { header } = {}) => {
197
- const hrefs = [];
198
- collectHrefs(closedSequence(items), hrefs);
199
- collectHrefs(closedSequence(header ?? []), hrefs);
200
- const firstLinkRelationship = header ? 3 : 2;
201
- const links = new Map(hrefs.map((href, index) => [href, `rId${index + firstLinkRelationship}`]));
202
- const linkRelationships = hrefs.map((href, index) => `<Relationship Id="rId${index + firstLinkRelationship}" Type="${OFFICE_RELATIONSHIPS}/hyperlink" Target="${href}" TargetMode="External"/>`).join("");
203
- const paraId = createParaIdAllocator();
204
- const parts = {
205
- "[Content_Types].xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/word/document.xml" ContentType="${WORDPROCESSING}.document.main+xml"/><Override PartName="/word/styles.xml" ContentType="${WORDPROCESSING}.styles+xml"/>` + (header ? `<Override PartName="/word/header1.xml" ContentType="${WORDPROCESSING}.header+xml"/>` : "") + `<Override PartName="/docProps/core.xml" ContentType="${CORE_PROPERTIES_TYPE}"/><Override PartName="/docProps/app.xml" ContentType="${EXTENDED_PROPERTIES_TYPE}"/></Types>`,
206
- "_rels/.rels": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="${RELATIONSHIPS}"><Relationship Id="rId1" Type="${OFFICE_RELATIONSHIPS}/officeDocument" Target="word/document.xml"/><Relationship Id="rId2" Type="${PACKAGE_RELATIONSHIPS}/metadata/core-properties" Target="docProps/core.xml"/><Relationship Id="rId3" Type="${OFFICE_RELATIONSHIPS}/extended-properties" Target="docProps/app.xml"/></Relationships>`,
207
- "docProps/core.xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><cp:coreProperties xmlns:cp="${PACKAGE_RELATIONSHIPS}/metadata/core-properties" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dcterms:created xsi:type="dcterms:W3CDTF">2000-01-01T00:00:00Z</dcterms:created><dcterms:modified xsi:type="dcterms:W3CDTF">2000-01-01T00:00:00Z</dcterms:modified></cp:coreProperties>`,
208
- "docProps/app.xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Properties xmlns="${EXTENDED_PROPERTIES}"><AppVersion>1.0.0</AppVersion></Properties>`,
209
- "word/_rels/document.xml.rels": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="${RELATIONSHIPS}"><Relationship Id="rId1" Type="${OFFICE_RELATIONSHIPS}/styles" Target="styles.xml"/>` + (header ? `<Relationship Id="${HEADER_RELATIONSHIP_ID}" Type="${OFFICE_RELATIONSHIPS}/header" Target="header1.xml"/>` : "") + linkRelationships + `</Relationships>`,
210
- "word/styles.xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:styles xmlns:w="${NAMESPACE}"><w:style w:type="paragraph" w:default="1" w:styleId="Normal"><w:name w:val="Normal"/></w:style><w:style w:type="paragraph" w:styleId="Heading1"><w:name w:val="heading 1"/></w:style></w:styles>`,
211
- "word/document.xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:document xmlns:w="${NAMESPACE}" xmlns:r="${OFFICE_RELATIONSHIPS}" xmlns:mc="${MARKUP_COMPATIBILITY}" xmlns:w14="${WORDML_2010}" mc:Ignorable="w14"><w:body>` + bodyXml(items, {
212
- links,
213
- paraId
214
- }) + `<w:sectPr>` + (header ? `<w:headerReference w:type="default" r:id="${HEADER_RELATIONSHIP_ID}"/>` : "") + "<w:pgSz w:w=\"12240\" w:h=\"15840\"/><w:pgMar w:top=\"1440\" w:right=\"1440\" w:bottom=\"1440\" w:left=\"1440\"/></w:sectPr></w:body></w:document>",
215
- ...header ? { "word/header1.xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:hdr xmlns:w="${NAMESPACE}" xmlns:r="${OFFICE_RELATIONSHIPS}" xmlns:mc="${MARKUP_COMPATIBILITY}" xmlns:w14="${WORDML_2010}" mc:Ignorable="w14">${itemsXml(closedSequence(header), {
216
- links,
217
- paraId
218
- })}</w:hdr>` } : {}
219
- };
220
- const zip = new JSZip();
221
- for (const name of Object.keys(parts).toSorted()) zip.file(name, parts[name] ?? "", ZIP_ENTRY_OPTIONS);
222
- return await zip.generateAsync({ type: "arraybuffer" });
223
- };
224
- //#endregion
225
- export { buildBodySequenceDocx };
@@ -1,16 +0,0 @@
1
- //#region src/compare/__fixtures__/nested-table.d.ts
2
- /**
3
- * A document that ends with a table whose last cell holds another table.
4
- *
5
- * The shape matters because the story's last block is then two levels deep,
6
- * and a paragraph appended after the whole table has no block to anchor to
7
- * that is not inside a cell. Authored here rather than committed as bytes so
8
- * the structure under test is legible in the diff.
9
- */
10
- type NestedTableDocxOptions = {
11
- /** Appended after the outer table, at body level, when set. */
12
- trailingParagraph?: string;
13
- };
14
- declare const buildNestedTableDocx: ({ trailingParagraph }?: NestedTableDocxOptions) => Promise<ArrayBuffer>;
15
- //#endregion
16
- export { NestedTableDocxOptions, buildNestedTableDocx };
@@ -1,50 +0,0 @@
1
- import JSZip from "jszip";
2
- //#region src/compare/__fixtures__/nested-table.ts
3
- /**
4
- * A document that ends with a table whose last cell holds another table.
5
- *
6
- * The shape matters because the story's last block is then two levels deep,
7
- * and a paragraph appended after the whole table has no block to anchor to
8
- * that is not inside a cell. Authored here rather than committed as bytes so
9
- * the structure under test is legible in the diff.
10
- */
11
- const NAMESPACE = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
12
- const RELATIONSHIPS = "http://schemas.openxmlformats.org/package/2006/relationships";
13
- const OFFICE_RELATIONSHIPS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
14
- const WORDPROCESSING = "application/vnd.openxmlformats-officedocument.wordprocessingml";
15
- /**
16
- * `createFolders: false` because JSZip stamps the folder entries it
17
- * synthesizes with `new Date()`, which the fixed date above does not reach.
18
- */
19
- const ZIP_ENTRY_OPTIONS = {
20
- date: new Date(Date.UTC(2e3, 0, 1)),
21
- createFolders: false
22
- };
23
- const paragraph = (text) => text.length === 0 ? `<w:p/>` : `<w:p><w:r><w:t xml:space="preserve">${text}</w:t></w:r></w:p>`;
24
- /**
25
- * A table may not be the last child of a body or a cell, so every container
26
- * that ends with one is closed by a paragraph. Word writes that paragraph and
27
- * usually leaves it empty; a fixture that omits it is malformed, and the
28
- * comparison should be exercised against the shape real packages have.
29
- */
30
- const closingParagraph = paragraph("");
31
- const cell = (inner) => `<w:tc><w:tcPr><w:tcW w:w="4680" w:type="dxa"/></w:tcPr>${inner}</w:tc>`;
32
- const table = (rows) => `<w:tbl><w:tblPr><w:tblW w:w="0" w:type="auto"/></w:tblPr><w:tblGrid><w:gridCol w:w="4680"/><w:gridCol w:w="4680"/></w:tblGrid>${rows.join("")}</w:tbl>`;
33
- /** The nested table sits in the outer table's last cell, deep in the story. */
34
- const NESTED_TABLE = table([`<w:tr>${cell(`${paragraph("The nested schedule lists the delivery dates.")}${closingParagraph}`)}</w:tr>`]);
35
- const OUTER_TABLE = table([`<w:tr>${cell(paragraph("Obligations of the supplier."))}${cell(paragraph("Obligations of the buyer."))}</w:tr>`, `<w:tr>${cell(paragraph("Deliver the goods to the named place."))}${cell(`${paragraph("See the schedule below.")}${NESTED_TABLE}${closingParagraph}`)}</w:tr>`]);
36
- const buildNestedTableDocx = async ({ trailingParagraph } = {}) => {
37
- const body = paragraph("This agreement is made between the parties named below.") + OUTER_TABLE + (trailingParagraph === void 0 ? closingParagraph : `${paragraph(trailingParagraph)}${closingParagraph}`);
38
- const parts = {
39
- "[Content_Types].xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/word/document.xml" ContentType="${WORDPROCESSING}.document.main+xml"/><Override PartName="/word/styles.xml" ContentType="${WORDPROCESSING}.styles+xml"/></Types>`,
40
- "_rels/.rels": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="${RELATIONSHIPS}"><Relationship Id="rId1" Type="${OFFICE_RELATIONSHIPS}/officeDocument" Target="word/document.xml"/></Relationships>`,
41
- "word/_rels/document.xml.rels": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="${RELATIONSHIPS}"><Relationship Id="rId1" Type="${OFFICE_RELATIONSHIPS}/styles" Target="styles.xml"/></Relationships>`,
42
- "word/styles.xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:styles xmlns:w="${NAMESPACE}"><w:style w:type="paragraph" w:default="1" w:styleId="Normal"><w:name w:val="Normal"/></w:style></w:styles>`,
43
- "word/document.xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:document xmlns:w="${NAMESPACE}"><w:body>${body}<w:sectPr><w:pgSz w:w="12240" w:h="15840"/><w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440"/></w:sectPr></w:body></w:document>`
44
- };
45
- const zip = new JSZip();
46
- for (const name of Object.keys(parts).toSorted()) zip.file(name, parts[name] ?? "", ZIP_ENTRY_OPTIONS);
47
- return await zip.generateAsync({ type: "arraybuffer" });
48
- };
49
- //#endregion
50
- export { buildNestedTableDocx };
@@ -1,34 +0,0 @@
1
- //#region src/compare/__fixtures__/numbered-list.d.ts
2
- /**
3
- * A small multi-level numbered list, authored here rather than committed as
4
- * bytes.
5
- *
6
- * The corpus fixtures carry no numbering at all, so a probe that says "an added
7
- * list item" while editing an unnumbered paragraph is testing something else
8
- * and saying it is testing numbering. Generating the package keeps its content
9
- * legible in the diff and keeps the provenance trivial.
10
- */
11
- /**
12
- * One item: its indent level and its text. `null` is a paragraph that keeps
13
- * the list style and carries no numbering.
14
- */
15
- type NumberedListItem = {
16
- level: number | null;
17
- text: string;
18
- };
19
- declare const NUMBERED_LIST_ITEMS: readonly NumberedListItem[];
20
- /** The same list with one item demoted one level: a level change and no text change. */
21
- declare const withItemDemoted: (items: readonly NumberedListItem[], index: number) => NumberedListItem[];
22
- /**
23
- * The same list with one item no longer numbered: the paragraph keeps every
24
- * word and stops being a list item, which is the edit a level change cannot
25
- * express.
26
- */
27
- declare const withItemUnnumbered: (items: readonly NumberedListItem[], index: number) => NumberedListItem[];
28
- type NumberedListDocxOptions = {
29
- /** `w:numFmt` for the top level. Default `"decimal"`. */
30
- format?: string;
31
- };
32
- declare const buildNumberedListDocx: (items?: readonly NumberedListItem[], { format }?: NumberedListDocxOptions) => Promise<ArrayBuffer>;
33
- //#endregion
34
- export { NUMBERED_LIST_ITEMS, NumberedListDocxOptions, NumberedListItem, buildNumberedListDocx, withItemDemoted, withItemUnnumbered };
@@ -1,85 +0,0 @@
1
- import JSZip from "jszip";
2
- //#region src/compare/__fixtures__/numbered-list.ts
3
- /**
4
- * A small multi-level numbered list, authored here rather than committed as
5
- * bytes.
6
- *
7
- * The corpus fixtures carry no numbering at all, so a probe that says "an added
8
- * list item" while editing an unnumbered paragraph is testing something else
9
- * and saying it is testing numbering. Generating the package keeps its content
10
- * legible in the diff and keeps the provenance trivial.
11
- */
12
- const NAMESPACE = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
13
- const RELATIONSHIPS = "http://schemas.openxmlformats.org/package/2006/relationships";
14
- const OFFICE_RELATIONSHIPS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
15
- const WORDPROCESSING = "application/vnd.openxmlformats-officedocument.wordprocessingml";
16
- /**
17
- * `createFolders: false` because JSZip stamps the folder entries it
18
- * synthesizes with `new Date()`, which the fixed date above does not reach.
19
- */
20
- const ZIP_ENTRY_OPTIONS = {
21
- date: new Date(Date.UTC(2e3, 0, 1)),
22
- createFolders: false
23
- };
24
- const LIST_LEVELS = 3;
25
- const abstractLevels = (topLevelFormat) => Array.from({ length: LIST_LEVELS }, (_unused, level) => {
26
- return `<w:lvl w:ilvl="${String(level)}"><w:start w:val="1"/><w:numFmt w:val="${level === 0 ? topLevelFormat : "lowerLetter"}"/><w:lvlText w:val="%${String(level + 1)}."/><w:lvlJc w:val="left"/></w:lvl>`;
27
- }).join("");
28
- const listParagraph = (level, text) => {
29
- return `<w:p><w:pPr><w:pStyle w:val="ListParagraph"/>${level === null ? "" : `<w:numPr><w:ilvl w:val="${String(level)}"/><w:numId w:val="1"/></w:numPr>`}</w:pPr><w:r><w:t xml:space="preserve">${text}</w:t></w:r></w:p>`;
30
- };
31
- const NUMBERED_LIST_ITEMS = Object.freeze([
32
- {
33
- level: 0,
34
- text: "The supplier shall deliver the goods to the named place."
35
- },
36
- {
37
- level: 1,
38
- text: "Delivery is complete on unloading at that place."
39
- },
40
- {
41
- level: 1,
42
- text: "Risk passes to the buyer on completion of delivery."
43
- },
44
- {
45
- level: 0,
46
- text: "The buyer shall pay within thirty days of the invoice date."
47
- },
48
- {
49
- level: 1,
50
- text: "Late payment carries interest at the statutory rate."
51
- },
52
- {
53
- level: 0,
54
- text: "Either party may terminate for material breach."
55
- }
56
- ]);
57
- /** The same list with one item demoted one level: a level change and no text change. */
58
- const withItemDemoted = (items, index) => items.map((item, at) => at === index ? {
59
- level: Math.min(LIST_LEVELS - 1, (item.level ?? 0) + 1),
60
- text: item.text
61
- } : item);
62
- /**
63
- * The same list with one item no longer numbered: the paragraph keeps every
64
- * word and stops being a list item, which is the edit a level change cannot
65
- * express.
66
- */
67
- const withItemUnnumbered = (items, index) => items.map((item, at) => at === index ? {
68
- level: null,
69
- text: item.text
70
- } : item);
71
- const buildNumberedListDocx = async (items = NUMBERED_LIST_ITEMS, { format = "decimal" } = {}) => {
72
- const parts = {
73
- "[Content_Types].xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/word/document.xml" ContentType="${WORDPROCESSING}.document.main+xml"/><Override PartName="/word/styles.xml" ContentType="${WORDPROCESSING}.styles+xml"/><Override PartName="/word/numbering.xml" ContentType="${WORDPROCESSING}.numbering+xml"/></Types>`,
74
- "_rels/.rels": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="${RELATIONSHIPS}"><Relationship Id="rId1" Type="${OFFICE_RELATIONSHIPS}/officeDocument" Target="word/document.xml"/></Relationships>`,
75
- "word/_rels/document.xml.rels": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="${RELATIONSHIPS}"><Relationship Id="rId1" Type="${OFFICE_RELATIONSHIPS}/styles" Target="styles.xml"/><Relationship Id="rId2" Type="${OFFICE_RELATIONSHIPS}/numbering" Target="numbering.xml"/></Relationships>`,
76
- "word/styles.xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:styles xmlns:w="${NAMESPACE}"><w:style w:type="paragraph" w:default="1" w:styleId="Normal"><w:name w:val="Normal"/></w:style><w:style w:type="paragraph" w:styleId="ListParagraph"><w:name w:val="List Paragraph"/></w:style></w:styles>`,
77
- "word/numbering.xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:numbering xmlns:w="${NAMESPACE}"><w:abstractNum w:abstractNumId="0">${abstractLevels(format)}</w:abstractNum><w:num w:numId="1"><w:abstractNumId w:val="0"/></w:num></w:numbering>`,
78
- "word/document.xml": `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:document xmlns:w="${NAMESPACE}"><w:body>` + items.map(({ level, text }) => listParagraph(level, text)).join("") + "<w:sectPr><w:pgSz w:w=\"12240\" w:h=\"15840\"/><w:pgMar w:top=\"1440\" w:right=\"1440\" w:bottom=\"1440\" w:left=\"1440\"/></w:sectPr></w:body></w:document>"
79
- };
80
- const zip = new JSZip();
81
- for (const name of Object.keys(parts).toSorted()) zip.file(name, parts[name] ?? "", ZIP_ENTRY_OPTIONS);
82
- return await zip.generateAsync({ type: "arraybuffer" });
83
- };
84
- //#endregion
85
- export { NUMBERED_LIST_ITEMS, buildNumberedListDocx, withItemDemoted, withItemUnnumbered };