@stll/folio-core 0.0.1-placeholder.0 → 0.1.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 (683) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE.md +29 -0
  3. package/README.md +41 -0
  4. package/dist/_virtual/_rolldown/runtime.js +13 -0
  5. package/dist/ai-edits/apply.d.ts +35 -0
  6. package/dist/ai-edits/apply.js +683 -0
  7. package/dist/ai-edits/clean-text.d.ts +28 -0
  8. package/dist/ai-edits/clean-text.js +23 -0
  9. package/dist/ai-edits/headless.d.ts +225 -0
  10. package/dist/ai-edits/headless.js +513 -0
  11. package/dist/ai-edits/index.d.ts +6 -0
  12. package/dist/ai-edits/index.js +5 -0
  13. package/dist/ai-edits/inline-emphasis.d.ts +38 -0
  14. package/dist/ai-edits/inline-emphasis.js +78 -0
  15. package/dist/ai-edits/snapshot.d.ts +9 -0
  16. package/dist/ai-edits/snapshot.js +195 -0
  17. package/dist/ai-edits/types.d.ts +156 -0
  18. package/dist/ai-edits/types.js +0 -0
  19. package/dist/ai-edits/word-diff.d.ts +20 -0
  20. package/dist/ai-edits/word-diff.js +77 -0
  21. package/dist/ai-suggestions/apply.d.ts +17 -0
  22. package/dist/ai-suggestions/apply.js +64 -0
  23. package/dist/ai-suggestions/conflict.d.ts +22 -0
  24. package/dist/ai-suggestions/conflict.js +67 -0
  25. package/dist/ai-suggestions/text-positions.d.ts +21 -0
  26. package/dist/ai-suggestions/text-positions.js +48 -0
  27. package/dist/ai-suggestions/types.d.ts +199 -0
  28. package/dist/ai-suggestions/types.js +59 -0
  29. package/dist/content-controls/errors.d.ts +52 -0
  30. package/dist/content-controls/errors.js +36 -0
  31. package/dist/content-controls/findContentControls.d.ts +55 -0
  32. package/dist/content-controls/findContentControls.js +75 -0
  33. package/dist/content-controls/index.d.ts +4 -0
  34. package/dist/content-controls/index.js +4 -0
  35. package/dist/content-controls/mutateContentControls.d.ts +51 -0
  36. package/dist/content-controls/mutateContentControls.js +377 -0
  37. package/dist/controller/folioEditor.d.ts +21 -0
  38. package/dist/controller/folioEditor.js +29 -0
  39. package/dist/controller/folioEditorEvents.d.ts +23 -0
  40. package/dist/controller/folioEditorEvents.js +24 -0
  41. package/dist/controller/hiddenEditorApi.d.ts +35 -0
  42. package/dist/controller/hiddenEditorApi.js +112 -0
  43. package/dist/controller/hiddenEditorManager.d.ts +93 -0
  44. package/dist/controller/hiddenEditorManager.js +308 -0
  45. package/dist/controller/layoutPipeline.d.ts +63 -0
  46. package/dist/controller/layoutPipeline.js +406 -0
  47. package/dist/controller/layoutScheduler.d.ts +41 -0
  48. package/dist/controller/layoutScheduler.js +59 -0
  49. package/dist/controller/layoutSession.d.ts +24 -0
  50. package/dist/controller/layoutSession.js +13 -0
  51. package/dist/docx/blockContentParser.d.ts +13 -0
  52. package/dist/docx/blockContentParser.js +289 -0
  53. package/dist/docx/bookmarkParser.d.ts +178 -0
  54. package/dist/docx/bookmarkParser.js +246 -0
  55. package/dist/docx/bookmarkPlacement.d.ts +10 -0
  56. package/dist/docx/bookmarkPlacement.js +50 -0
  57. package/dist/docx/bulletMarkers.d.ts +4 -0
  58. package/dist/docx/bulletMarkers.js +42 -0
  59. package/dist/docx/commentParser.d.ts +34 -0
  60. package/dist/docx/commentParser.js +127 -0
  61. package/dist/docx/commentReferenceNormalization.d.ts +25 -0
  62. package/dist/docx/commentReferenceNormalization.js +97 -0
  63. package/dist/docx/commentReplyMarkers.d.ts +20 -0
  64. package/dist/docx/commentReplyMarkers.js +123 -0
  65. package/dist/docx/compatibility.d.ts +12 -0
  66. package/dist/docx/compatibility.js +77 -0
  67. package/dist/docx/documentParser.d.ts +65 -0
  68. package/dist/docx/documentParser.js +209 -0
  69. package/dist/docx/drawingUtils.d.ts +56 -0
  70. package/dist/docx/drawingUtils.js +305 -0
  71. package/dist/docx/fieldParser.d.ts +228 -0
  72. package/dist/docx/fieldParser.js +559 -0
  73. package/dist/docx/footnoteParser.d.ts +109 -0
  74. package/dist/docx/footnoteParser.js +270 -0
  75. package/dist/docx/headerFooterParser.d.ts +119 -0
  76. package/dist/docx/headerFooterParser.js +266 -0
  77. package/dist/docx/headerFooterRefParser.d.ts +22 -0
  78. package/dist/docx/headerFooterRefParser.js +52 -0
  79. package/dist/docx/headerFooterReferenceNormalization.d.ts +19 -0
  80. package/dist/docx/headerFooterReferenceNormalization.js +64 -0
  81. package/dist/docx/hyperlinkParser.d.ts +108 -0
  82. package/dist/docx/hyperlinkParser.js +230 -0
  83. package/dist/docx/imageParser.d.ts +93 -0
  84. package/dist/docx/imageParser.js +522 -0
  85. package/dist/docx/mathToMathml.d.ts +15 -0
  86. package/dist/docx/mathToMathml.js +357 -0
  87. package/dist/docx/modelValidation.d.ts +13 -0
  88. package/dist/docx/modelValidation.js +21 -0
  89. package/dist/docx/normalizeBaseDirection.d.ts +12 -0
  90. package/dist/docx/normalizeBaseDirection.js +81 -0
  91. package/dist/docx/notePropertiesParser.d.ts +16 -0
  92. package/dist/docx/notePropertiesParser.js +99 -0
  93. package/dist/docx/numberingParser.d.ts +86 -0
  94. package/dist/docx/numberingParser.js +735 -0
  95. package/dist/docx/numberingReferenceNormalization.d.ts +25 -0
  96. package/dist/docx/numberingReferenceNormalization.js +22 -0
  97. package/dist/docx/paragraphParser.d.ts +86 -0
  98. package/dist/docx/paragraphParser.js +1132 -0
  99. package/dist/docx/paragraphTraversal.d.ts +19 -0
  100. package/dist/docx/paragraphTraversal.js +76 -0
  101. package/dist/docx/parser.d.ts +67 -0
  102. package/dist/docx/parser.js +391 -0
  103. package/dist/docx/parserEnums.d.ts +45 -0
  104. package/dist/docx/parserEnums.js +70 -0
  105. package/dist/docx/relsParser.d.ts +160 -0
  106. package/dist/docx/relsParser.js +235 -0
  107. package/dist/docx/replyToComment.d.ts +29 -0
  108. package/dist/docx/replyToComment.js +73 -0
  109. package/dist/docx/rezip.d.ts +166 -0
  110. package/dist/docx/rezip.js +1194 -0
  111. package/dist/docx/runConsolidator.d.ts +57 -0
  112. package/dist/docx/runConsolidator.js +224 -0
  113. package/dist/docx/runParser.d.ts +78 -0
  114. package/dist/docx/runParser.js +661 -0
  115. package/dist/docx/sdtProperties.d.ts +15 -0
  116. package/dist/docx/sdtProperties.js +290 -0
  117. package/dist/docx/sdtPropertiesPatch.d.ts +16 -0
  118. package/dist/docx/sdtPropertiesPatch.js +144 -0
  119. package/dist/docx/sectionParser.d.ts +95 -0
  120. package/dist/docx/sectionParser.js +534 -0
  121. package/dist/docx/selectiveSave.d.ts +25 -0
  122. package/dist/docx/selectiveSave.js +247 -0
  123. package/dist/docx/selectiveSaveFlags.d.ts +33 -0
  124. package/dist/docx/selectiveSaveFlags.js +11 -0
  125. package/dist/docx/selectiveSaveTripwire.d.ts +33 -0
  126. package/dist/docx/selectiveSaveTripwire.js +79 -0
  127. package/dist/docx/selectiveXmlPatch.d.ts +103 -0
  128. package/dist/docx/selectiveXmlPatch.js +493 -0
  129. package/dist/docx/serializer/blockSdtSerializer.d.ts +6 -0
  130. package/dist/docx/serializer/blockSdtSerializer.js +88 -0
  131. package/dist/docx/serializer/borderSerializer.d.ts +25 -0
  132. package/dist/docx/serializer/borderSerializer.js +44 -0
  133. package/dist/docx/serializer/commentSerializer.d.ts +31 -0
  134. package/dist/docx/serializer/commentSerializer.js +184 -0
  135. package/dist/docx/serializer/documentSerializer.d.ts +65 -0
  136. package/dist/docx/serializer/documentSerializer.js +199 -0
  137. package/dist/docx/serializer/headerFooterSerializer.d.ts +12 -0
  138. package/dist/docx/serializer/headerFooterSerializer.js +84 -0
  139. package/dist/docx/serializer/noteSerializer.d.ts +19 -0
  140. package/dist/docx/serializer/noteSerializer.js +70 -0
  141. package/dist/docx/serializer/numberingSerializer.d.ts +12 -0
  142. package/dist/docx/serializer/numberingSerializer.js +93 -0
  143. package/dist/docx/serializer/paragraphSerializer.d.ts +48 -0
  144. package/dist/docx/serializer/paragraphSerializer.js +559 -0
  145. package/dist/docx/serializer/runSerializer.d.ts +56 -0
  146. package/dist/docx/serializer/runSerializer.js +621 -0
  147. package/dist/docx/serializer/sectionPropertiesSerializer.d.ts +6 -0
  148. package/dist/docx/serializer/sectionPropertiesSerializer.js +187 -0
  149. package/dist/docx/serializer/tableSerializer.d.ts +79 -0
  150. package/dist/docx/serializer/tableSerializer.js +422 -0
  151. package/dist/docx/serializer/xmlUtils.d.ts +20 -0
  152. package/dist/docx/serializer/xmlUtils.js +25 -0
  153. package/dist/docx/settingsParser.d.ts +8 -0
  154. package/dist/docx/settingsParser.js +36 -0
  155. package/dist/docx/shapeParser.d.ts +20 -0
  156. package/dist/docx/shapeParser.js +272 -0
  157. package/dist/docx/styleParser.d.ts +50 -0
  158. package/dist/docx/styleParser.js +905 -0
  159. package/dist/docx/tableParser.d.ts +202 -0
  160. package/dist/docx/tableParser.js +811 -0
  161. package/dist/docx/textBoxParser.d.ts +117 -0
  162. package/dist/docx/textBoxParser.js +262 -0
  163. package/dist/docx/themeParser.d.ts +77 -0
  164. package/dist/docx/themeParser.js +330 -0
  165. package/dist/docx/trackedMoveRangeNormalization.d.ts +22 -0
  166. package/dist/docx/trackedMoveRangeNormalization.js +100 -0
  167. package/dist/docx/unzip.d.ts +118 -0
  168. package/dist/docx/unzip.js +383 -0
  169. package/dist/docx/vmlImageParser.d.ts +16 -0
  170. package/dist/docx/vmlImageParser.js +100 -0
  171. package/dist/docx/watermarkParser.d.ts +45 -0
  172. package/dist/docx/watermarkParser.js +348 -0
  173. package/dist/docx/wrapTypes.d.ts +29 -0
  174. package/dist/docx/wrapTypes.js +48 -0
  175. package/dist/docx/xmlParser.d.ts +297 -0
  176. package/dist/docx/xmlParser.js +527 -0
  177. package/dist/fields/bookmarkPages.d.ts +13 -0
  178. package/dist/fields/bookmarkPages.js +66 -0
  179. package/dist/fields/bookmarkText.d.ts +16 -0
  180. package/dist/fields/bookmarkText.js +61 -0
  181. package/dist/fields/evaluateField.d.ts +23 -0
  182. package/dist/fields/evaluateField.js +77 -0
  183. package/dist/fields/fieldContext.d.ts +21 -0
  184. package/dist/fields/fieldContext.js +0 -0
  185. package/dist/fields/resolveFieldValues.d.ts +44 -0
  186. package/dist/fields/resolveFieldValues.js +204 -0
  187. package/dist/fields/sectionPageCounts.d.ts +11 -0
  188. package/dist/fields/sectionPageCounts.js +16 -0
  189. package/dist/fields/seqValues.d.ts +14 -0
  190. package/dist/fields/seqValues.js +36 -0
  191. package/dist/fonts/embeddedFontTable.d.ts +42 -0
  192. package/dist/fonts/embeddedFontTable.js +80 -0
  193. package/dist/fonts/embeddedFonts.d.ts +46 -0
  194. package/dist/fonts/embeddedFonts.js +112 -0
  195. package/dist/fonts/fontDeobfuscation.d.ts +30 -0
  196. package/dist/fonts/fontDeobfuscation.js +57 -0
  197. package/dist/index.d.ts +28 -0
  198. package/dist/index.js +23 -0
  199. package/dist/layout-bridge/convert/footnoteLayout.d.ts +57 -0
  200. package/dist/layout-bridge/convert/footnoteLayout.js +316 -0
  201. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +74 -0
  202. package/dist/layout-bridge/convert/headerFooterLayout.js +432 -0
  203. package/dist/layout-bridge/convert/templatePreviewFlow.d.ts +36 -0
  204. package/dist/layout-bridge/convert/templatePreviewFlow.js +176 -0
  205. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +65 -0
  206. package/dist/layout-bridge/convert/toFlowBlocks.js +1309 -0
  207. package/dist/layout-bridge/convert/wrapEditorViewAsSurface.d.ts +17 -0
  208. package/dist/layout-bridge/convert/wrapEditorViewAsSurface.js +36 -0
  209. package/dist/layout-bridge/dom/clickToPositionDom.d.ts +66 -0
  210. package/dist/layout-bridge/dom/clickToPositionDom.js +304 -0
  211. package/dist/layout-bridge/dom/findBodyPmSpans.d.ts +7 -0
  212. package/dist/layout-bridge/dom/findBodyPmSpans.js +17 -0
  213. package/dist/layout-bridge/dom/findHfPmSpans.d.ts +62 -0
  214. package/dist/layout-bridge/dom/findHfPmSpans.js +197 -0
  215. package/dist/layout-bridge/engine/clickToPosition.d.ts +66 -0
  216. package/dist/layout-bridge/engine/clickToPosition.js +403 -0
  217. package/dist/layout-bridge/engine/hitTest.d.ts +135 -0
  218. package/dist/layout-bridge/engine/hitTest.js +375 -0
  219. package/dist/layout-bridge/engine/measuring/index.d.ts +10 -0
  220. package/dist/layout-bridge/engine/measuring/index.js +9 -0
  221. package/dist/layout-bridge/engine/selectionRects.d.ts +59 -0
  222. package/dist/layout-bridge/engine/selectionRects.js +485 -0
  223. package/dist/layout-bridge/engine/tableWidthUtils.d.ts +7 -0
  224. package/dist/layout-bridge/engine/tableWidthUtils.js +25 -0
  225. package/dist/layout-engine/index.d.ts +44 -0
  226. package/dist/layout-engine/index.js +691 -0
  227. package/dist/layout-engine/keep-together.d.ts +43 -0
  228. package/dist/layout-engine/keep-together.js +98 -0
  229. package/dist/layout-engine/layoutInstrumentation.d.ts +50 -0
  230. package/dist/layout-engine/layoutInstrumentation.js +43 -0
  231. package/dist/layout-engine/lineFlow.d.ts +8 -0
  232. package/dist/layout-engine/lineFlow.js +17 -0
  233. package/dist/layout-engine/measure/cache.d.ts +93 -0
  234. package/dist/layout-engine/measure/cache.js +245 -0
  235. package/dist/layout-engine/measure/clampFloatingWrapMargins.d.ts +20 -0
  236. package/dist/layout-engine/measure/clampFloatingWrapMargins.js +29 -0
  237. package/dist/layout-engine/measure/featureFlags.d.ts +44 -0
  238. package/dist/layout-engine/measure/featureFlags.js +19 -0
  239. package/dist/layout-engine/measure/floatingZones.d.ts +89 -0
  240. package/dist/layout-engine/measure/floatingZones.js +152 -0
  241. package/dist/layout-engine/measure/font-metrics.worker.d.ts +17 -0
  242. package/dist/layout-engine/measure/font-metrics.worker.js +104 -0
  243. package/dist/layout-engine/measure/index.d.ts +9 -0
  244. package/dist/layout-engine/measure/index.js +8 -0
  245. package/dist/layout-engine/measure/listMarkerWidth.d.ts +40 -0
  246. package/dist/layout-engine/measure/listMarkerWidth.js +76 -0
  247. package/dist/layout-engine/measure/measureBlocks.d.ts +25 -0
  248. package/dist/layout-engine/measure/measureBlocks.js +450 -0
  249. package/dist/layout-engine/measure/measureContainer.d.ts +24 -0
  250. package/dist/layout-engine/measure/measureContainer.js +280 -0
  251. package/dist/layout-engine/measure/measureHelpers.d.ts +82 -0
  252. package/dist/layout-engine/measure/measureHelpers.js +156 -0
  253. package/dist/layout-engine/measure/measureParagraph.d.ts +61 -0
  254. package/dist/layout-engine/measure/measureParagraph.js +724 -0
  255. package/dist/layout-engine/measure/measureProvider.d.ts +23 -0
  256. package/dist/layout-engine/measure/measureProvider.js +35 -0
  257. package/dist/layout-engine/measure/measureTypes.d.ts +61 -0
  258. package/dist/layout-engine/measure/measureTypes.js +0 -0
  259. package/dist/layout-engine/measure/measureWorker.d.ts +54 -0
  260. package/dist/layout-engine/measure/measureWorker.js +249 -0
  261. package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +88 -0
  262. package/dist/layout-engine/measure/measureWorkerProtocol.js +20 -0
  263. package/dist/layout-engine/measure/tableCellFloating.d.ts +26 -0
  264. package/dist/layout-engine/measure/tableCellFloating.js +99 -0
  265. package/dist/layout-engine/paginator.d.ts +84 -0
  266. package/dist/layout-engine/paginator.js +348 -0
  267. package/dist/layout-engine/paragraphFragmentRange.d.ts +9 -0
  268. package/dist/layout-engine/paragraphFragmentRange.js +40 -0
  269. package/dist/layout-engine/section-breaks.d.ts +78 -0
  270. package/dist/layout-engine/section-breaks.js +182 -0
  271. package/dist/layout-engine/tableRowBreak.d.ts +23 -0
  272. package/dist/layout-engine/tableRowBreak.js +147 -0
  273. package/dist/layout-engine/textBoxFlow.d.ts +50 -0
  274. package/dist/layout-engine/textBoxFlow.js +160 -0
  275. package/dist/layout-engine/types.d.ts +1031 -0
  276. package/dist/layout-engine/types.js +100 -0
  277. package/dist/layout-painter/documentColors.d.ts +4 -0
  278. package/dist/layout-painter/documentColors.js +40 -0
  279. package/dist/layout-painter/index.d.ts +110 -0
  280. package/dist/layout-painter/index.js +182 -0
  281. package/dist/layout-painter/registry/modules/image.d.ts +6 -0
  282. package/dist/layout-painter/registry/modules/image.js +17 -0
  283. package/dist/layout-painter/registry/modules/paragraph.d.ts +6 -0
  284. package/dist/layout-painter/registry/modules/paragraph.js +18 -0
  285. package/dist/layout-painter/registry/modules/table.d.ts +6 -0
  286. package/dist/layout-painter/registry/modules/table.js +16 -0
  287. package/dist/layout-painter/registry/modules/textBox.d.ts +6 -0
  288. package/dist/layout-painter/registry/modules/textBox.js +13 -0
  289. package/dist/layout-painter/registry/modules.d.ts +6 -0
  290. package/dist/layout-painter/registry/modules.js +26 -0
  291. package/dist/layout-painter/registry/registry.d.ts +24 -0
  292. package/dist/layout-painter/registry/registry.js +53 -0
  293. package/dist/layout-painter/registry/types.d.ts +61 -0
  294. package/dist/layout-painter/registry/types.js +0 -0
  295. package/dist/layout-painter/renderFragment.d.ts +32 -0
  296. package/dist/layout-painter/renderFragment.js +114 -0
  297. package/dist/layout-painter/renderImage.d.ts +88 -0
  298. package/dist/layout-painter/renderImage.js +130 -0
  299. package/dist/layout-painter/renderPage.d.ts +264 -0
  300. package/dist/layout-painter/renderPage.js +1795 -0
  301. package/dist/layout-painter/renderParagraph.d.ts +93 -0
  302. package/dist/layout-painter/renderParagraph.js +1300 -0
  303. package/dist/layout-painter/renderTable.d.ts +36 -0
  304. package/dist/layout-painter/renderTable.js +432 -0
  305. package/dist/layout-painter/renderTextBox.d.ts +22 -0
  306. package/dist/layout-painter/renderTextBox.js +67 -0
  307. package/dist/layout-painter/renderUtils.d.ts +42 -0
  308. package/dist/layout-painter/renderUtils.js +30 -0
  309. package/dist/layout-painter/renderWatermark.d.ts +16 -0
  310. package/dist/layout-painter/renderWatermark.js +61 -0
  311. package/dist/layout-painter/sdtBoundary.d.ts +6 -0
  312. package/dist/layout-painter/sdtBoundary.js +28 -0
  313. package/dist/managers/ContextMenuManager.d.ts +28 -0
  314. package/dist/managers/ContextMenuManager.js +48 -0
  315. package/dist/managers/DocumentLoaderManager.d.ts +47 -0
  316. package/dist/managers/DocumentLoaderManager.js +69 -0
  317. package/dist/managers/EditorModeManager.d.ts +28 -0
  318. package/dist/managers/EditorModeManager.js +50 -0
  319. package/dist/managers/ErrorManager.d.ts +26 -0
  320. package/dist/managers/ErrorManager.js +85 -0
  321. package/dist/managers/FindReplaceManager.d.ts +54 -0
  322. package/dist/managers/FindReplaceManager.js +104 -0
  323. package/dist/managers/HistoryManager.d.ts +92 -0
  324. package/dist/managers/HistoryManager.js +193 -0
  325. package/dist/managers/Subscribable.d.ts +34 -0
  326. package/dist/managers/Subscribable.js +46 -0
  327. package/dist/managers/TableSelectionManager.d.ts +74 -0
  328. package/dist/managers/TableSelectionManager.js +225 -0
  329. package/dist/managers/editorShortcuts.d.ts +42 -0
  330. package/dist/managers/editorShortcuts.js +60 -0
  331. package/dist/managers/types.d.ts +41 -0
  332. package/dist/managers/types.js +0 -0
  333. package/dist/markdown/annotations.d.ts +14 -0
  334. package/dist/markdown/annotations.js +42 -0
  335. package/dist/markdown/escape.d.ts +36 -0
  336. package/dist/markdown/escape.js +59 -0
  337. package/dist/markdown/fromMarkdown.d.ts +11 -0
  338. package/dist/markdown/fromMarkdown.js +223 -0
  339. package/dist/markdown/headings.d.ts +13 -0
  340. package/dist/markdown/headings.js +20 -0
  341. package/dist/markdown/images.d.ts +13 -0
  342. package/dist/markdown/images.js +63 -0
  343. package/dist/markdown/index.d.ts +18 -0
  344. package/dist/markdown/index.js +33 -0
  345. package/dist/markdown/internals.d.ts +15 -0
  346. package/dist/markdown/internals.js +35 -0
  347. package/dist/markdown/renderBlock.d.ts +7 -0
  348. package/dist/markdown/renderBlock.js +68 -0
  349. package/dist/markdown/renderParagraph.d.ts +11 -0
  350. package/dist/markdown/renderParagraph.js +64 -0
  351. package/dist/markdown/renderRuns.d.ts +11 -0
  352. package/dist/markdown/renderRuns.js +265 -0
  353. package/dist/markdown/renderTable.d.ts +8 -0
  354. package/dist/markdown/renderTable.js +229 -0
  355. package/dist/markdown/trailers.d.ts +13 -0
  356. package/dist/markdown/trailers.js +54 -0
  357. package/dist/markdown/types.d.ts +118 -0
  358. package/dist/markdown/types.js +0 -0
  359. package/dist/model.d.ts +13 -0
  360. package/dist/model.js +4 -0
  361. package/dist/paged-layout/LayoutSelectionGate.d.ts +80 -0
  362. package/dist/paged-layout/LayoutSelectionGate.js +131 -0
  363. package/dist/paged-layout/headerFooterMargins.d.ts +73 -0
  364. package/dist/paged-layout/headerFooterMargins.js +120 -0
  365. package/dist/paged-layout/hiddenEditorScroll.d.ts +4 -0
  366. package/dist/paged-layout/hiddenEditorScroll.js +4 -0
  367. package/dist/paged-layout/incrementalMeasure.d.ts +33 -0
  368. package/dist/paged-layout/incrementalMeasure.js +56 -0
  369. package/dist/paged-layout/rangeProjection.d.ts +51 -0
  370. package/dist/paged-layout/rangeProjection.js +153 -0
  371. package/dist/paged-layout/readOnlyEditAttempt.d.ts +5 -0
  372. package/dist/paged-layout/readOnlyEditAttempt.js +22 -0
  373. package/dist/paged-layout/scrollNavigation.d.ts +23 -0
  374. package/dist/paged-layout/scrollNavigation.js +31 -0
  375. package/dist/paged-layout/scrollPageInfo.d.ts +41 -0
  376. package/dist/paged-layout/scrollPageInfo.js +34 -0
  377. package/dist/paged-layout/scrollToPmPosition.d.ts +17 -0
  378. package/dist/paged-layout/scrollToPmPosition.js +95 -0
  379. package/dist/paged-layout/sectionBlockWidths.d.ts +35 -0
  380. package/dist/paged-layout/sectionBlockWidths.js +52 -0
  381. package/dist/paged-layout/sectionGeometry.d.ts +21 -0
  382. package/dist/paged-layout/sectionGeometry.js +36 -0
  383. package/dist/paged-layout/selectionViewportRect.d.ts +29 -0
  384. package/dist/paged-layout/selectionViewportRect.js +55 -0
  385. package/dist/paged-layout/tableColumnResize.d.ts +19 -0
  386. package/dist/paged-layout/tableColumnResize.js +28 -0
  387. package/dist/paged-layout/tableInsertButtonGeometry.d.ts +15 -0
  388. package/dist/paged-layout/tableInsertButtonGeometry.js +15 -0
  389. package/dist/paged-layout/transactionDirtyRange.d.ts +7 -0
  390. package/dist/paged-layout/transactionDirtyRange.js +27 -0
  391. package/dist/paged-layout/zoomScrollAnchor.d.ts +40 -0
  392. package/dist/paged-layout/zoomScrollAnchor.js +25 -0
  393. package/dist/prosemirror/attrs/index.d.ts +80 -0
  394. package/dist/prosemirror/attrs/index.js +1218 -0
  395. package/dist/prosemirror/autospacingBase.d.ts +11 -0
  396. package/dist/prosemirror/autospacingBase.js +16 -0
  397. package/dist/prosemirror/commands/comments.d.ts +93 -0
  398. package/dist/prosemirror/commands/comments.js +435 -0
  399. package/dist/prosemirror/commands/contentControls.d.ts +45 -0
  400. package/dist/prosemirror/commands/contentControls.js +294 -0
  401. package/dist/prosemirror/commands/contentControlsBlockFill.d.ts +15 -0
  402. package/dist/prosemirror/commands/contentControlsBlockFill.js +19 -0
  403. package/dist/prosemirror/commands/formatPainter.d.ts +31 -0
  404. package/dist/prosemirror/commands/formatPainter.js +130 -0
  405. package/dist/prosemirror/commands/formatting.d.ts +32 -0
  406. package/dist/prosemirror/commands/formatting.js +45 -0
  407. package/dist/prosemirror/commands/hyperlink.d.ts +31 -0
  408. package/dist/prosemirror/commands/hyperlink.js +79 -0
  409. package/dist/prosemirror/commands/image.d.ts +59 -0
  410. package/dist/prosemirror/commands/image.js +219 -0
  411. package/dist/prosemirror/commands/index.d.ts +13 -0
  412. package/dist/prosemirror/commands/index.js +13 -0
  413. package/dist/prosemirror/commands/pageBreak.d.ts +10 -0
  414. package/dist/prosemirror/commands/pageBreak.js +47 -0
  415. package/dist/prosemirror/commands/paragraph.d.ts +39 -0
  416. package/dist/prosemirror/commands/paragraph.js +64 -0
  417. package/dist/prosemirror/commands/pastePlainText.d.ts +39 -0
  418. package/dist/prosemirror/commands/pastePlainText.js +67 -0
  419. package/dist/prosemirror/commands/table.d.ts +83 -0
  420. package/dist/prosemirror/commands/table.js +105 -0
  421. package/dist/prosemirror/conversion/fromProseDoc.d.ts +27 -0
  422. package/dist/prosemirror/conversion/fromProseDoc.js +1550 -0
  423. package/dist/prosemirror/conversion/index.d.ts +4 -0
  424. package/dist/prosemirror/conversion/index.js +4 -0
  425. package/dist/prosemirror/conversion/runShadingMark.d.ts +16 -0
  426. package/dist/prosemirror/conversion/runShadingMark.js +39 -0
  427. package/dist/prosemirror/conversion/toProseDoc.d.ts +39 -0
  428. package/dist/prosemirror/conversion/toProseDoc.js +1404 -0
  429. package/dist/prosemirror/extensions/ExtensionManager.d.ts +43 -0
  430. package/dist/prosemirror/extensions/ExtensionManager.js +86 -0
  431. package/dist/prosemirror/extensions/StarterKit.d.ts +16 -0
  432. package/dist/prosemirror/extensions/StarterKit.js +132 -0
  433. package/dist/prosemirror/extensions/core/DocExtension.d.ts +9 -0
  434. package/dist/prosemirror/extensions/core/DocExtension.js +12 -0
  435. package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +13 -0
  436. package/dist/prosemirror/extensions/core/HistoryExtension.js +28 -0
  437. package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +25 -0
  438. package/dist/prosemirror/extensions/core/ParagraphExtension.js +619 -0
  439. package/dist/prosemirror/extensions/core/TextExtension.d.ts +9 -0
  440. package/dist/prosemirror/extensions/core/TextExtension.js +12 -0
  441. package/dist/prosemirror/extensions/create.d.ts +17 -0
  442. package/dist/prosemirror/extensions/create.js +129 -0
  443. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +23 -0
  444. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +106 -0
  445. package/dist/prosemirror/extensions/features/BaseKeymapExtension.d.ts +8 -0
  446. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +172 -0
  447. package/dist/prosemirror/extensions/features/BidiShortcutExtension.d.ts +16 -0
  448. package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +38 -0
  449. package/dist/prosemirror/extensions/features/ContentControlWidgetsExtension.d.ts +16 -0
  450. package/dist/prosemirror/extensions/features/ContentControlWidgetsExtension.js +21 -0
  451. package/dist/prosemirror/extensions/features/DropCursorExtension.d.ts +12 -0
  452. package/dist/prosemirror/extensions/features/DropCursorExtension.js +20 -0
  453. package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.d.ts +8 -0
  454. package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +44 -0
  455. package/dist/prosemirror/extensions/features/GapCursorExtension.d.ts +19 -0
  456. package/dist/prosemirror/extensions/features/GapCursorExtension.js +24 -0
  457. package/dist/prosemirror/extensions/features/ImageDragExtension.d.ts +15 -0
  458. package/dist/prosemirror/extensions/features/ImageDragExtension.js +66 -0
  459. package/dist/prosemirror/extensions/features/ImagePasteExtension.d.ts +12 -0
  460. package/dist/prosemirror/extensions/features/ImagePasteExtension.js +91 -0
  461. package/dist/prosemirror/extensions/features/ListExtension.d.ts +14 -0
  462. package/dist/prosemirror/extensions/features/ListExtension.js +340 -0
  463. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +9 -0
  464. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +60 -0
  465. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +35 -0
  466. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +188 -0
  467. package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +20 -0
  468. package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +34 -0
  469. package/dist/prosemirror/extensions/features/PasteStyleInlinerExtension.d.ts +20 -0
  470. package/dist/prosemirror/extensions/features/PasteStyleInlinerExtension.js +145 -0
  471. package/dist/prosemirror/extensions/features/SelectionTrackerExtension.d.ts +10 -0
  472. package/dist/prosemirror/extensions/features/SelectionTrackerExtension.js +17 -0
  473. package/dist/prosemirror/extensions/features/bidiShortcutController.d.ts +31 -0
  474. package/dist/prosemirror/extensions/features/bidiShortcutController.js +27 -0
  475. package/dist/prosemirror/extensions/features/pasteCleanup.d.ts +31 -0
  476. package/dist/prosemirror/extensions/features/pasteCleanup.js +159 -0
  477. package/dist/prosemirror/extensions/marks/AllCapsExtension.d.ts +9 -0
  478. package/dist/prosemirror/extensions/marks/AllCapsExtension.js +24 -0
  479. package/dist/prosemirror/extensions/marks/BoldExtension.d.ts +9 -0
  480. package/dist/prosemirror/extensions/marks/BoldExtension.js +41 -0
  481. package/dist/prosemirror/extensions/marks/CharacterSpacingExtension.d.ts +14 -0
  482. package/dist/prosemirror/extensions/marks/CharacterSpacingExtension.js +64 -0
  483. package/dist/prosemirror/extensions/marks/CharacterStyleExtension.d.ts +23 -0
  484. package/dist/prosemirror/extensions/marks/CharacterStyleExtension.js +47 -0
  485. package/dist/prosemirror/extensions/marks/CommentExtension.d.ts +12 -0
  486. package/dist/prosemirror/extensions/marks/CommentExtension.js +38 -0
  487. package/dist/prosemirror/extensions/marks/FontFamilyExtension.d.ts +9 -0
  488. package/dist/prosemirror/extensions/marks/FontFamilyExtension.js +55 -0
  489. package/dist/prosemirror/extensions/marks/FontSizeExtension.d.ts +9 -0
  490. package/dist/prosemirror/extensions/marks/FontSizeExtension.js +47 -0
  491. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.d.ts +11 -0
  492. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +92 -0
  493. package/dist/prosemirror/extensions/marks/HiddenTextExtension.d.ts +23 -0
  494. package/dist/prosemirror/extensions/marks/HiddenTextExtension.js +35 -0
  495. package/dist/prosemirror/extensions/marks/HighlightExtension.d.ts +10 -0
  496. package/dist/prosemirror/extensions/marks/HighlightExtension.js +115 -0
  497. package/dist/prosemirror/extensions/marks/HyperlinkExtension.d.ts +13 -0
  498. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +146 -0
  499. package/dist/prosemirror/extensions/marks/ItalicExtension.d.ts +9 -0
  500. package/dist/prosemirror/extensions/marks/ItalicExtension.js +34 -0
  501. package/dist/prosemirror/extensions/marks/RtlExtension.d.ts +6 -0
  502. package/dist/prosemirror/extensions/marks/RtlExtension.js +21 -0
  503. package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.d.ts +11 -0
  504. package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.js +75 -0
  505. package/dist/prosemirror/extensions/marks/RunShadingExtension.d.ts +6 -0
  506. package/dist/prosemirror/extensions/marks/RunShadingExtension.js +38 -0
  507. package/dist/prosemirror/extensions/marks/SmallCapsExtension.d.ts +9 -0
  508. package/dist/prosemirror/extensions/marks/SmallCapsExtension.js +24 -0
  509. package/dist/prosemirror/extensions/marks/StrikeExtension.d.ts +9 -0
  510. package/dist/prosemirror/extensions/marks/StrikeExtension.js +33 -0
  511. package/dist/prosemirror/extensions/marks/SubscriptExtension.d.ts +9 -0
  512. package/dist/prosemirror/extensions/marks/SubscriptExtension.js +25 -0
  513. package/dist/prosemirror/extensions/marks/SuperscriptExtension.d.ts +9 -0
  514. package/dist/prosemirror/extensions/marks/SuperscriptExtension.js +25 -0
  515. package/dist/prosemirror/extensions/marks/TextColorExtension.d.ts +9 -0
  516. package/dist/prosemirror/extensions/marks/TextColorExtension.js +50 -0
  517. package/dist/prosemirror/extensions/marks/TextEffectExtension.d.ts +6 -0
  518. package/dist/prosemirror/extensions/marks/TextEffectExtension.js +35 -0
  519. package/dist/prosemirror/extensions/marks/TextEffectsExtensions.d.ts +31 -0
  520. package/dist/prosemirror/extensions/marks/TextEffectsExtensions.js +134 -0
  521. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.d.ts +22 -0
  522. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +113 -0
  523. package/dist/prosemirror/extensions/marks/UnderlineExtension.d.ts +9 -0
  524. package/dist/prosemirror/extensions/marks/UnderlineExtension.js +60 -0
  525. package/dist/prosemirror/extensions/marks/markUtils.d.ts +34 -0
  526. package/dist/prosemirror/extensions/marks/markUtils.js +233 -0
  527. package/dist/prosemirror/extensions/nodes/BlockSdtExtension.d.ts +22 -0
  528. package/dist/prosemirror/extensions/nodes/BlockSdtExtension.js +122 -0
  529. package/dist/prosemirror/extensions/nodes/FieldExtension.d.ts +12 -0
  530. package/dist/prosemirror/extensions/nodes/FieldExtension.js +87 -0
  531. package/dist/prosemirror/extensions/nodes/HardBreakExtension.d.ts +9 -0
  532. package/dist/prosemirror/extensions/nodes/HardBreakExtension.js +38 -0
  533. package/dist/prosemirror/extensions/nodes/HorizontalRuleExtension.d.ts +9 -0
  534. package/dist/prosemirror/extensions/nodes/HorizontalRuleExtension.js +18 -0
  535. package/dist/prosemirror/extensions/nodes/ImageExtension.d.ts +9 -0
  536. package/dist/prosemirror/extensions/nodes/ImageExtension.js +132 -0
  537. package/dist/prosemirror/extensions/nodes/MathExtension.d.ts +13 -0
  538. package/dist/prosemirror/extensions/nodes/MathExtension.js +56 -0
  539. package/dist/prosemirror/extensions/nodes/PageBreakExtension.d.ts +9 -0
  540. package/dist/prosemirror/extensions/nodes/PageBreakExtension.js +20 -0
  541. package/dist/prosemirror/extensions/nodes/SdtExtension.d.ts +12 -0
  542. package/dist/prosemirror/extensions/nodes/SdtExtension.js +107 -0
  543. package/dist/prosemirror/extensions/nodes/ShapeExtension.d.ts +30 -0
  544. package/dist/prosemirror/extensions/nodes/ShapeExtension.js +502 -0
  545. package/dist/prosemirror/extensions/nodes/TabExtension.d.ts +9 -0
  546. package/dist/prosemirror/extensions/nodes/TabExtension.js +27 -0
  547. package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +34 -0
  548. package/dist/prosemirror/extensions/nodes/TableExtension.js +1972 -0
  549. package/dist/prosemirror/extensions/nodes/TextBoxExtension.d.ts +34 -0
  550. package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +150 -0
  551. package/dist/prosemirror/extensions/types.d.ts +101 -0
  552. package/dist/prosemirror/extensions/types.js +10 -0
  553. package/dist/prosemirror/findReplaceSelection.d.ts +23 -0
  554. package/dist/prosemirror/findReplaceSelection.js +86 -0
  555. package/dist/prosemirror/index.d.ts +25 -0
  556. package/dist/prosemirror/index.js +23 -0
  557. package/dist/prosemirror/insertOperations.d.ts +12 -0
  558. package/dist/prosemirror/insertOperations.js +19 -0
  559. package/dist/prosemirror/paragraphDirection.d.ts +42 -0
  560. package/dist/prosemirror/paragraphDirection.js +33 -0
  561. package/dist/prosemirror/plugins/aiCitationDecorations.d.ts +40 -0
  562. package/dist/prosemirror/plugins/aiCitationDecorations.js +90 -0
  563. package/dist/prosemirror/plugins/aiSuggestionDecorations.d.ts +42 -0
  564. package/dist/prosemirror/plugins/aiSuggestionDecorations.js +135 -0
  565. package/dist/prosemirror/plugins/anonymizationDecorations.d.ts +60 -0
  566. package/dist/prosemirror/plugins/anonymizationDecorations.js +120 -0
  567. package/dist/prosemirror/plugins/autocompleteSuggestion.d.ts +123 -0
  568. package/dist/prosemirror/plugins/autocompleteSuggestion.js +283 -0
  569. package/dist/prosemirror/plugins/contentControlWidgets.d.ts +56 -0
  570. package/dist/prosemirror/plugins/contentControlWidgets.js +192 -0
  571. package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +37 -0
  572. package/dist/prosemirror/plugins/createDocScanPlugin.js +55 -0
  573. package/dist/prosemirror/plugins/documentStyles.d.ts +18 -0
  574. package/dist/prosemirror/plugins/documentStyles.js +46 -0
  575. package/dist/prosemirror/plugins/index.d.ts +3 -0
  576. package/dist/prosemirror/plugins/index.js +3 -0
  577. package/dist/prosemirror/plugins/pmTextScan.d.ts +19 -0
  578. package/dist/prosemirror/plugins/pmTextScan.js +39 -0
  579. package/dist/prosemirror/plugins/selectionTracker.d.ts +43 -0
  580. package/dist/prosemirror/plugins/selectionTracker.js +179 -0
  581. package/dist/prosemirror/plugins/suggestionMode.d.ts +70 -0
  582. package/dist/prosemirror/plugins/suggestionMode.js +489 -0
  583. package/dist/prosemirror/plugins/templateDirectives.d.ts +25 -0
  584. package/dist/prosemirror/plugins/templateDirectives.js +67 -0
  585. package/dist/prosemirror/plugins/templatePreviewValues.d.ts +49 -0
  586. package/dist/prosemirror/plugins/templatePreviewValues.js +117 -0
  587. package/dist/prosemirror/plugins/templateSlashMenu.d.ts +57 -0
  588. package/dist/prosemirror/plugins/templateSlashMenu.js +184 -0
  589. package/dist/prosemirror/schema/index.d.ts +15 -0
  590. package/dist/prosemirror/schema/index.js +20 -0
  591. package/dist/prosemirror/schema/marks.d.ts +118 -0
  592. package/dist/prosemirror/schema/marks.js +0 -0
  593. package/dist/prosemirror/schema/nodes.d.ts +389 -0
  594. package/dist/prosemirror/schema/nodes.js +0 -0
  595. package/dist/prosemirror/selectionState.d.ts +23 -0
  596. package/dist/prosemirror/selectionState.js +111 -0
  597. package/dist/prosemirror/styles/index.d.ts +2 -0
  598. package/dist/prosemirror/styles/index.js +2 -0
  599. package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +32 -0
  600. package/dist/prosemirror/styles/resolvedStyleAttrs.js +108 -0
  601. package/dist/prosemirror/styles/styleResolver.d.ts +94 -0
  602. package/dist/prosemirror/styles/styleResolver.js +200 -0
  603. package/dist/prosemirror/utils/findParagraphByParaId.d.ts +26 -0
  604. package/dist/prosemirror/utils/findParagraphByParaId.js +37 -0
  605. package/dist/prosemirror/utils/tabCalculator.d.ts +110 -0
  606. package/dist/prosemirror/utils/tabCalculator.js +137 -0
  607. package/dist/prosemirror/validation.d.ts +20 -0
  608. package/dist/prosemirror/validation.js +177 -0
  609. package/dist/server.d.ts +7 -0
  610. package/dist/server.js +6 -0
  611. package/dist/style-engine/index.d.ts +3 -0
  612. package/dist/style-engine/index.js +2 -0
  613. package/dist/style-engine/styleEngine.d.ts +67 -0
  614. package/dist/style-engine/styleEngine.js +70 -0
  615. package/dist/types/block-id.d.ts +66 -0
  616. package/dist/types/block-id.js +73 -0
  617. package/dist/types/colors.d.ts +2 -0
  618. package/dist/types/colors.js +0 -0
  619. package/dist/types/content.d.ts +2 -0
  620. package/dist/types/content.js +0 -0
  621. package/dist/types/document.d.ts +7 -0
  622. package/dist/types/document.js +0 -0
  623. package/dist/types/documentEnumValues.d.ts +89 -0
  624. package/dist/types/documentEnumValues.js +693 -0
  625. package/dist/types/formatting.d.ts +2 -0
  626. package/dist/types/formatting.js +0 -0
  627. package/dist/types/index.d.ts +107 -0
  628. package/dist/types/index.js +0 -0
  629. package/dist/utils/authorColors.d.ts +16 -0
  630. package/dist/utils/authorColors.js +30 -0
  631. package/dist/utils/baseDirection.d.ts +23 -0
  632. package/dist/utils/baseDirection.js +34 -0
  633. package/dist/utils/clipboard.d.ts +126 -0
  634. package/dist/utils/clipboard.js +622 -0
  635. package/dist/utils/colorResolver.d.ts +158 -0
  636. package/dist/utils/colorResolver.js +557 -0
  637. package/dist/utils/createDocument.d.ts +50 -0
  638. package/dist/utils/createDocument.js +262 -0
  639. package/dist/utils/documentLoaderBehavior.d.ts +22 -0
  640. package/dist/utils/documentLoaderBehavior.js +14 -0
  641. package/dist/utils/docxInput.d.ts +22 -0
  642. package/dist/utils/docxInput.js +16 -0
  643. package/dist/utils/domGuards.d.ts +59 -0
  644. package/dist/utils/domGuards.js +82 -0
  645. package/dist/utils/fontFamilyMerge.d.ts +7 -0
  646. package/dist/utils/fontFamilyMerge.js +31 -0
  647. package/dist/utils/fontLoader.d.ts +50 -0
  648. package/dist/utils/fontLoader.js +177 -0
  649. package/dist/utils/fontResolver.d.ts +61 -0
  650. package/dist/utils/fontResolver.js +651 -0
  651. package/dist/utils/fontWeights.d.ts +4 -0
  652. package/dist/utils/fontWeights.js +4 -0
  653. package/dist/utils/formatToStyle.d.ts +103 -0
  654. package/dist/utils/formatToStyle.js +289 -0
  655. package/dist/utils/headerFooter.d.ts +74 -0
  656. package/dist/utils/headerFooter.js +257 -0
  657. package/dist/utils/headingCollector.d.ts +22 -0
  658. package/dist/utils/headingCollector.js +36 -0
  659. package/dist/utils/hexId.d.ts +33 -0
  660. package/dist/utils/hexId.js +37 -0
  661. package/dist/utils/imageValidation.d.ts +5 -0
  662. package/dist/utils/imageValidation.js +31 -0
  663. package/dist/utils/paragraphFormattingMerge.d.ts +14 -0
  664. package/dist/utils/paragraphFormattingMerge.js +68 -0
  665. package/dist/utils/replaceText.d.ts +17 -0
  666. package/dist/utils/replaceText.js +161 -0
  667. package/dist/utils/rotationBoundingBox.d.ts +12 -0
  668. package/dist/utils/rotationBoundingBox.js +36 -0
  669. package/dist/utils/scriptSegments.d.ts +36 -0
  670. package/dist/utils/scriptSegments.js +52 -0
  671. package/dist/utils/tableOperations.d.ts +87 -0
  672. package/dist/utils/tableOperations.js +259 -0
  673. package/dist/utils/textFormattingMerge.d.ts +6 -0
  674. package/dist/utils/textFormattingMerge.js +31 -0
  675. package/dist/utils/tiffConverter.d.ts +18 -0
  676. package/dist/utils/tiffConverter.js +83 -0
  677. package/dist/utils/units.d.ts +99 -0
  678. package/dist/utils/units.js +139 -0
  679. package/dist/utils/urlSecurity.d.ts +7 -0
  680. package/dist/utils/urlSecurity.js +65 -0
  681. package/dist/watermark/index.d.ts +39 -0
  682. package/dist/watermark/index.js +149 -0
  683. package/package.json +122 -2
@@ -0,0 +1,1550 @@
1
+ import { OUTLINE_STYLE_CSS_ALIASES } from "../../types/documentEnumValues.js";
2
+ import { ShapeOutlineStyleSchema, narrowEnum } from "../../docx/parserEnums.js";
3
+ import { pixelsToEmu } from "../../utils/units.js";
4
+ import { numPrEqual } from "../../docx/numberingParser.js";
5
+ import { directionToBidi } from "../paragraphDirection.js";
6
+ import { expectBlockSdtAttrs, expectCharacterSpacingMarkAttrs, expectCharacterStyleMarkAttrs, expectCommentMarkAttrs, expectEmphasisMarkAttrs, expectFieldAttrs, expectFontFamilyMarkAttrs, expectFontSizeMarkAttrs, expectFootnoteRefMarkAttrs, expectHardBreakAttrs, expectHighlightMarkAttrs, expectHyperlinkMarkAttrs, expectImageAttrs, expectMathAttrs, expectParagraphAttrs, expectRunFormattingOverrideMarkAttrs, expectRunShadingMarkAttrs, expectSdtAttrs, expectShapeAttrs, expectStrikeMarkAttrs, expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs, expectTextBoxAttrs, expectTextColorMarkAttrs, expectTextEffectMarkAttrs, expectTrackedChangeMarkAttrs, expectUnderlineMarkAttrs } from "../attrs/index.js";
7
+ import { autospacingMatchesBase, hasAutospacingBaseSide } from "../autospacingBase.js";
8
+ import { runShadingAttrsToShading } from "./runShadingMark.js";
9
+ import { assertValidProseMirrorDocument } from "../validation.js";
10
+ //#region src/prosemirror/conversion/fromProseDoc.ts
11
+ function normalizeShapeOutlineStyle(style) {
12
+ if (!style) return;
13
+ if (style in OUTLINE_STYLE_CSS_ALIASES) return OUTLINE_STYLE_CSS_ALIASES[style];
14
+ return narrowEnum(style, ShapeOutlineStyleSchema);
15
+ }
16
+ function parseTransformAttr(transformStr) {
17
+ if (!transformStr) return;
18
+ const transform = {};
19
+ const rotateMatch = /rotate\((?<deg>[-\d.]+)deg\)/u.exec(transformStr);
20
+ if (rotateMatch) {
21
+ const rotation = Number.parseFloat(rotateMatch.groups["deg"]);
22
+ if (Number.isFinite(rotation)) transform.rotation = rotation;
23
+ }
24
+ if (transformStr.includes("scaleX(-1)")) transform.flipH = true;
25
+ if (transformStr.includes("scaleY(-1)")) transform.flipV = true;
26
+ if (transform.rotation === void 0 && !transform.flipH && !transform.flipV) return;
27
+ return transform;
28
+ }
29
+ function imagePositionFromAttrs(attrs) {
30
+ const horizontalPosition = attrs?.horizontal;
31
+ const verticalPosition = attrs?.vertical;
32
+ if (!horizontalPosition || !verticalPosition) return;
33
+ const horizontal = { relativeTo: horizontalPosition.relativeTo || "column" };
34
+ if (horizontalPosition.align) horizontal.alignment = horizontalPosition.align;
35
+ if (horizontalPosition.posOffset !== void 0) horizontal.posOffset = horizontalPosition.posOffset;
36
+ const vertical = { relativeTo: verticalPosition.relativeTo || "paragraph" };
37
+ if (verticalPosition.align) vertical.alignment = verticalPosition.align;
38
+ if (verticalPosition.posOffset !== void 0) vertical.posOffset = verticalPosition.posOffset;
39
+ return {
40
+ horizontal,
41
+ vertical
42
+ };
43
+ }
44
+ function textBoxWrapFromAttrs(attrs) {
45
+ if (!(attrs.wrapType !== void 0 && attrs.wrapType !== "inline" || attrs.wrapText !== void 0 || attrs.distTop !== void 0 || attrs.distBottom !== void 0 || attrs.distLeft !== void 0 || attrs.distRight !== void 0)) return;
46
+ const wrap = { type: attrs.wrapType ?? "inline" };
47
+ if (attrs.wrapText !== void 0) wrap.wrapText = attrs.wrapText;
48
+ if (attrs.distTop !== void 0) wrap.distT = pixelsToEmu(attrs.distTop);
49
+ if (attrs.distBottom !== void 0) wrap.distB = pixelsToEmu(attrs.distBottom);
50
+ if (attrs.distLeft !== void 0) wrap.distL = pixelsToEmu(attrs.distLeft);
51
+ if (attrs.distRight !== void 0) wrap.distR = pixelsToEmu(attrs.distRight);
52
+ return wrap;
53
+ }
54
+ /**
55
+ * Convert a ProseMirror document to our Document type
56
+ */
57
+ function fromProseDoc(pmDoc, baseDocument) {
58
+ assertValidProseMirrorDocument(pmDoc, "Cannot convert invalid ProseMirror document to DOCX model");
59
+ const documentBody = { content: extractBlocks(pmDoc) };
60
+ if (baseDocument?.package.document.finalSectionProperties) documentBody.finalSectionProperties = baseDocument.package.document.finalSectionProperties;
61
+ if (baseDocument?.package.document.sections) documentBody.sections = baseDocument.package.document.sections;
62
+ if (baseDocument?.package.document.comments) documentBody.comments = baseDocument.package.document.comments;
63
+ if (baseDocument) return {
64
+ ...baseDocument,
65
+ package: {
66
+ ...baseDocument.package,
67
+ document: documentBody
68
+ }
69
+ };
70
+ return { package: { document: documentBody } };
71
+ }
72
+ /**
73
+ * Extract block content (paragraphs, tables, block SDTs) from a ProseMirror
74
+ * document.
75
+ */
76
+ function extractBlocks(pmDoc) {
77
+ const blocks = [];
78
+ const documentCounts = buildDocumentTrackedChangeCounts(pmDoc);
79
+ let pendingPageBreaks = 0;
80
+ let previousStandaloneTextBox = null;
81
+ const flushPendingPageBreaks = () => {
82
+ for (let index = 0; index < pendingPageBreaks; index += 1) blocks.push(createPageBreakParagraph());
83
+ pendingPageBreaks = 0;
84
+ };
85
+ const appendPendingPageBreaksToPreviousParagraph = () => {
86
+ const previousBlock = blocks.at(-1);
87
+ if (previousBlock?.type !== "paragraph") return false;
88
+ appendPageBreaks(previousBlock, pendingPageBreaks);
89
+ pendingPageBreaks = 0;
90
+ return true;
91
+ };
92
+ pmDoc.forEach((node) => {
93
+ if (node.type.name === "pageBreak") {
94
+ pendingPageBreaks += 1;
95
+ previousStandaloneTextBox = null;
96
+ return;
97
+ }
98
+ if (node.type.name === "paragraph") {
99
+ const paragraph = convertPMParagraph(node, documentCounts);
100
+ prependPageBreaks(paragraph, pendingPageBreaks);
101
+ pendingPageBreaks = 0;
102
+ blocks.push(paragraph);
103
+ previousStandaloneTextBox = null;
104
+ } else if (node.type.name === "table") {
105
+ if (pendingPageBreaks > 0 && !appendPendingPageBreaksToPreviousParagraph()) flushPendingPageBreaks();
106
+ blocks.push(convertPMTable(node, documentCounts));
107
+ previousStandaloneTextBox = null;
108
+ } else if (node.type.name === "textBox") {
109
+ previousStandaloneTextBox = appendTextBoxBlock(blocks, node, {
110
+ pendingPageBreaks,
111
+ previousStandaloneTextBox
112
+ });
113
+ pendingPageBreaks = 0;
114
+ } else if (node.type.name === "blockSdt") {
115
+ if (pendingPageBreaks > 0 && !appendPendingPageBreaksToPreviousParagraph()) flushPendingPageBreaks();
116
+ blocks.push(convertPMBlockSdt(node));
117
+ previousStandaloneTextBox = null;
118
+ }
119
+ });
120
+ if (pendingPageBreaks > 0 && !appendPendingPageBreaksToPreviousParagraph()) flushPendingPageBreaks();
121
+ return blocks;
122
+ }
123
+ function convertPMBlockSdt(node) {
124
+ const attrs = expectBlockSdtAttrs(node);
125
+ const properties = { sdtType: attrs.sdtType };
126
+ if (attrs.alias) properties.alias = attrs.alias;
127
+ if (attrs.tag) properties.tag = attrs.tag;
128
+ if (typeof attrs.id === "number") properties.id = attrs.id;
129
+ if (attrs.lock) properties.lock = attrs.lock;
130
+ if (attrs.placeholder) properties.placeholder = attrs.placeholder;
131
+ if (attrs.showingPlaceholder !== void 0) properties.showingPlaceholder = attrs.showingPlaceholder;
132
+ if (attrs.dateFormat) properties.dateFormat = attrs.dateFormat;
133
+ if (attrs.dateValueISO) properties.dateValueISO = attrs.dateValueISO;
134
+ if (attrs.listItems) {
135
+ const items = parseListItemsJson(attrs.listItems);
136
+ if (items) properties.listItems = items;
137
+ }
138
+ if (typeof attrs.dropdownLastValue === "string") properties.dropdownLastValue = attrs.dropdownLastValue;
139
+ if (typeof attrs.checked === "boolean") properties.checked = attrs.checked;
140
+ if (attrs.rawPropertiesXml) properties.rawPropertiesXml = attrs.rawPropertiesXml;
141
+ if (attrs.rawEndPropertiesXml) properties.rawEndPropertiesXml = attrs.rawEndPropertiesXml;
142
+ if (attrs.rawSdtChildrenBeforeContent) properties.rawSdtChildrenBeforeContent = attrs.rawSdtChildrenBeforeContent;
143
+ if (attrs.rawSdtChildrenAfterContent) properties.rawSdtChildrenAfterContent = attrs.rawSdtChildrenAfterContent;
144
+ const extracted = extractBlocks(node.type.schema.node("doc", null, node.content));
145
+ return {
146
+ type: "blockSdt",
147
+ properties,
148
+ content: attrs._originallyEmpty === true && isStillSyntheticFiller(extracted) ? [] : extracted
149
+ };
150
+ }
151
+ function isStillSyntheticFiller(blocks) {
152
+ if (blocks.length !== 1) return false;
153
+ const block = blocks[0];
154
+ if (!block || block.type !== "paragraph") return false;
155
+ if (block.content.length !== 0) return false;
156
+ if (block.formatting !== void 0) return false;
157
+ if (block.sectionProperties !== void 0) return false;
158
+ if (block.propertyChanges !== void 0) return false;
159
+ if (block.pPrMark !== void 0) return false;
160
+ return true;
161
+ }
162
+ function parseListItemsJson(raw) {
163
+ try {
164
+ const parsed = JSON.parse(raw);
165
+ if (!Array.isArray(parsed)) return;
166
+ const items = [];
167
+ for (const entry of parsed) if (entry !== null && typeof entry === "object" && "displayText" in entry && "value" in entry && typeof entry.displayText === "string" && typeof entry.value === "string") items.push(entry);
168
+ return items.length > 0 ? items : void 0;
169
+ } catch {
170
+ return;
171
+ }
172
+ }
173
+ function appendTextBoxBlock(blocks, node, options) {
174
+ const attrs = expectTextBoxAttrs(node);
175
+ const paragraph = convertPMTextBox(node);
176
+ const previousBlock = blocks.at(-1);
177
+ if (attrs._docxPlacement === "inlineWithPrevious" && previousBlock?.type === "paragraph") {
178
+ appendPageBreaks(previousBlock, options.pendingPageBreaks);
179
+ previousBlock.content.push(...paragraph.content);
180
+ return null;
181
+ }
182
+ if (attrs._docxPlacement === "standalone" && attrs._docxGroupId && options.previousStandaloneTextBox?.groupId === attrs._docxGroupId) {
183
+ options.previousStandaloneTextBox.paragraph.content.push(...paragraph.content);
184
+ return options.previousStandaloneTextBox;
185
+ }
186
+ prependPageBreaks(paragraph, options.pendingPageBreaks);
187
+ blocks.push(paragraph);
188
+ return attrs._docxPlacement === "standalone" && attrs._docxGroupId ? {
189
+ paragraph,
190
+ groupId: attrs._docxGroupId
191
+ } : null;
192
+ }
193
+ /**
194
+ * Inverse of toProseDoc's listRendering → list* attrs flattening. Markdown
195
+ * export (`toMarkdown`) and re-layout of the rebuilt Document key off
196
+ * `paragraph.listRendering`; without this, every edited document loses its
197
+ * list markers on the way out of the editor.
198
+ */
199
+ function listRenderingFromAttrs(attrs) {
200
+ const numId = attrs.numPr?.numId;
201
+ if (numId === void 0 || numId === 0) return;
202
+ if (!(attrs.listMarker != null || attrs.listIsBullet || attrs.listNumFmt != null)) return;
203
+ return {
204
+ marker: attrs.listMarker ?? "",
205
+ level: attrs.numPr?.ilvl ?? 0,
206
+ numId,
207
+ isBullet: attrs.listIsBullet ?? false,
208
+ ...attrs.listIsLegal != null && { isLegal: attrs.listIsLegal },
209
+ ...attrs.listNumFmt != null && { numFmt: attrs.listNumFmt },
210
+ ...attrs.listMarkerHidden != null && { markerHidden: attrs.listMarkerHidden },
211
+ ...attrs.listMarkerFontFamily != null && { markerFontFamily: attrs.listMarkerFontFamily },
212
+ ...attrs.listMarkerFontSize != null && { markerFontSize: attrs.listMarkerFontSize },
213
+ ...attrs.listMarkerSuffix != null && { markerSuffix: attrs.listMarkerSuffix },
214
+ ...attrs.listMarkerAllCaps != null && { markerAllCaps: attrs.listMarkerAllCaps },
215
+ ...attrs.listImplicitChildLevelAdvances != null && { implicitChildLevelAdvances: attrs.listImplicitChildLevelAdvances },
216
+ ...attrs.listMarkerSecondSlotOffsetTwips != null && { markerSecondSlotOffsetTwips: attrs.listMarkerSecondSlotOffsetTwips },
217
+ ...attrs.listLevelNumFmts != null && { levelNumFmts: attrs.listLevelNumFmts },
218
+ ...attrs.listAbstractNumId != null && { abstractNumId: attrs.listAbstractNumId },
219
+ ...attrs.listStartOverride != null && { startOverride: attrs.listStartOverride }
220
+ };
221
+ }
222
+ /**
223
+ * Create a paragraph containing only a page break run (for DOCX serialization)
224
+ */
225
+ function createPageBreakParagraph() {
226
+ return {
227
+ type: "paragraph",
228
+ content: [{
229
+ type: "run",
230
+ content: [{
231
+ type: "break",
232
+ breakType: "page"
233
+ }]
234
+ }]
235
+ };
236
+ }
237
+ function createPageBreakRun() {
238
+ return {
239
+ type: "run",
240
+ content: [{
241
+ type: "break",
242
+ breakType: "page"
243
+ }]
244
+ };
245
+ }
246
+ function prependPageBreaks(paragraph, count) {
247
+ for (let index = 0; index < count; index += 1) paragraph.content.unshift(createPageBreakRun());
248
+ }
249
+ function appendPageBreaks(paragraph, count) {
250
+ for (let index = 0; index < count; index += 1) paragraph.content.push(createPageBreakRun());
251
+ }
252
+ /**
253
+ * Convert a ProseMirror paragraph node to our Paragraph type
254
+ */
255
+ function convertPMParagraph(node, documentCounts) {
256
+ const attrs = expectParagraphAttrs(node);
257
+ let content = extractParagraphContent(node, documentCounts, attrs._emptyHyperlinks ?? void 0);
258
+ const bookmarks = attrs.bookmarks;
259
+ if (bookmarks && bookmarks.length > 0) {
260
+ const starts = bookmarks.map((b) => ({
261
+ type: "bookmarkStart",
262
+ id: b.id,
263
+ name: b.name
264
+ }));
265
+ const ends = bookmarks.map((b) => ({
266
+ type: "bookmarkEnd",
267
+ id: b.id
268
+ }));
269
+ content = [
270
+ ...starts,
271
+ ...content,
272
+ ...ends
273
+ ];
274
+ }
275
+ const paragraph = {
276
+ type: "paragraph",
277
+ content
278
+ };
279
+ if (attrs.paraId) paragraph.paraId = attrs.paraId;
280
+ if (attrs.textId) paragraph.textId = attrs.textId;
281
+ const pFormatting = paragraphAttrsToFormatting(attrs);
282
+ if (pFormatting) paragraph.formatting = pFormatting;
283
+ const listRendering = listRenderingFromAttrs(attrs);
284
+ if (listRendering) paragraph.listRendering = listRendering;
285
+ if (attrs.renderedPageBreakBefore) paragraph.renderedPageBreakBefore = true;
286
+ if (attrs._sectionProperties) paragraph.sectionProperties = attrs._sectionProperties;
287
+ else if (attrs.sectionBreakType) paragraph.sectionProperties = { sectionStart: attrs.sectionBreakType };
288
+ if (Array.isArray(attrs._propertyChanges) && attrs._propertyChanges.length > 0) paragraph.propertyChanges = [...attrs._propertyChanges];
289
+ if (attrs.pPrMark) paragraph.pPrMark = attrs.pPrMark;
290
+ return paragraph;
291
+ }
292
+ /**
293
+ * Whether the paragraph's numbering still comes verbatim from its style —
294
+ * serialize no direct `<w:numPr>` then. The moment a list command changes
295
+ * `numPr` the values diverge and the numbering serializes as direct
296
+ * formatting, so a stale provenance value can never swallow a user edit.
297
+ */
298
+ function isStyleSourcedNumPr(attrs) {
299
+ return attrs.numPrFromStyle != null && attrs.numPr != null && numPrEqual(attrs.numPr, attrs.numPrFromStyle);
300
+ }
301
+ function assignBooleanToggle(result, attrs, orig, key) {
302
+ const value = attrs[key] ?? void 0;
303
+ if (value === (orig[key] ?? void 0)) return;
304
+ if (value === void 0) Reflect.deleteProperty(result, key);
305
+ else result[key] = value;
306
+ }
307
+ function paragraphAttrsToFormatting(attrs) {
308
+ const spaceBefore = Reflect.get(attrs, "spaceBefore");
309
+ const spaceAfter = Reflect.get(attrs, "spaceAfter");
310
+ const beforeHasAutospacingBase = hasAutospacingBaseSide(attrs._autospacingBase, "before");
311
+ const afterHasAutospacingBase = hasAutospacingBaseSide(attrs._autospacingBase, "after");
312
+ const beforeOriginalAutospacing = attrs._originalFormatting?.beforeAutospacing === true;
313
+ const afterOriginalAutospacing = attrs._originalFormatting?.afterAutospacing === true;
314
+ const beforeAutospacingEdited = beforeHasAutospacingBase ? !autospacingMatchesBase(attrs._autospacingBase, "before", spaceBefore) : beforeOriginalAutospacing && attrs._autospacingBase == null;
315
+ const afterAutospacingEdited = afterHasAutospacingBase ? !autospacingMatchesBase(attrs._autospacingBase, "after", spaceAfter) : afterOriginalAutospacing && attrs._autospacingBase == null;
316
+ const shouldSerializeSpaceBefore = typeof spaceBefore === "number" && (!beforeHasAutospacingBase || beforeAutospacingEdited);
317
+ const shouldSerializeSpaceAfter = typeof spaceAfter === "number" && (!afterHasAutospacingBase || afterAutospacingEdited);
318
+ if (attrs._originalFormatting) {
319
+ const orig = attrs._originalFormatting;
320
+ const result = { ...orig };
321
+ if (beforeAutospacingEdited) {
322
+ result.beforeAutospacing = false;
323
+ if (typeof spaceBefore === "number") result.spaceBefore = spaceBefore;
324
+ else delete result.spaceBefore;
325
+ }
326
+ if (afterAutospacingEdited) {
327
+ result.afterAutospacing = false;
328
+ if (typeof spaceAfter === "number") result.spaceAfter = spaceAfter;
329
+ else delete result.spaceAfter;
330
+ }
331
+ if (attrs.alignment !== (orig.alignment ?? void 0)) if (attrs.alignment) result.alignment = attrs.alignment;
332
+ else delete result.alignment;
333
+ if (isStyleSourcedNumPr(attrs)) {
334
+ delete result.numPr;
335
+ delete result.numPrFromStyle;
336
+ } else if (attrs.numPr !== orig.numPr && !numPrEqual(attrs.numPr, orig.numPr)) {
337
+ if (attrs.numPr) result.numPr = attrs.numPr;
338
+ else delete result.numPr;
339
+ delete result.numPrFromStyle;
340
+ }
341
+ if (attrs.styleId !== (orig.styleId ?? void 0)) if (attrs.styleId) result.styleId = attrs.styleId;
342
+ else delete result.styleId;
343
+ assignBooleanToggle(result, attrs, orig, "pageBreakBefore");
344
+ if (attrs.spacingExplicit !== orig.spacingExplicit) if (attrs.spacingExplicit) result.spacingExplicit = attrs.spacingExplicit;
345
+ else delete result.spacingExplicit;
346
+ const bidi = directionToBidi(attrs.direction);
347
+ if (bidi !== (orig.bidi ?? void 0)) if (bidi === void 0) delete result.bidi;
348
+ else result.bidi = bidi;
349
+ return result;
350
+ }
351
+ const outlineLevel = Reflect.get(attrs, "outlineLevel");
352
+ const bidi = directionToBidi(attrs.direction);
353
+ if (!(attrs.alignment || shouldSerializeSpaceBefore || shouldSerializeSpaceAfter || beforeAutospacingEdited || afterAutospacingEdited || attrs.lineSpacing || attrs.indentLeft || attrs.indentRight || attrs.indentFirstLine || attrs.numPr || attrs.styleId || attrs.borders || attrs.shading || attrs.tabs || typeof outlineLevel === "number" || attrs.contextualSpacing || attrs.spacingExplicit || bidi != null || attrs.pageBreakBefore != null)) return;
354
+ const f = {};
355
+ if (attrs.alignment) f.alignment = attrs.alignment;
356
+ if (shouldSerializeSpaceBefore) f.spaceBefore = spaceBefore;
357
+ if (beforeAutospacingEdited) f.beforeAutospacing = false;
358
+ if (shouldSerializeSpaceAfter) f.spaceAfter = spaceAfter;
359
+ if (afterAutospacingEdited) f.afterAutospacing = false;
360
+ if (attrs.lineSpacing) f.lineSpacing = attrs.lineSpacing;
361
+ if (attrs.lineSpacingRule) f.lineSpacingRule = attrs.lineSpacingRule;
362
+ if (attrs.spacingExplicit) f.spacingExplicit = attrs.spacingExplicit;
363
+ if (attrs.indentLeft) f.indentLeft = attrs.indentLeft;
364
+ if (attrs.indentRight) f.indentRight = attrs.indentRight;
365
+ if (attrs.indentFirstLine) f.indentFirstLine = attrs.indentFirstLine;
366
+ if (attrs.hangingIndent) f.hangingIndent = attrs.hangingIndent;
367
+ if (attrs.numPr && !isStyleSourcedNumPr(attrs)) f.numPr = attrs.numPr;
368
+ if (attrs.styleId) f.styleId = attrs.styleId;
369
+ if (attrs.borders) f.borders = attrs.borders;
370
+ if (attrs.shading) f.shading = attrs.shading;
371
+ if (attrs.tabs) f.tabs = attrs.tabs;
372
+ if (typeof outlineLevel === "number") f.outlineLevel = outlineLevel;
373
+ if (attrs.contextualSpacing) f.contextualSpacing = attrs.contextualSpacing;
374
+ if (bidi != null) f.bidi = bidi;
375
+ if (attrs.pageBreakBefore != null) f.pageBreakBefore = attrs.pageBreakBefore;
376
+ return f;
377
+ }
378
+ /**
379
+ * Extract paragraph content (runs, hyperlinks) from ProseMirror paragraph
380
+ *
381
+ * Coalesces consecutive text with the same marks into single Runs
382
+ * for efficient DOCX representation.
383
+ */
384
+ function extractParagraphContent(paragraph, _documentCounts, emptyHyperlinks) {
385
+ const content = [];
386
+ const sortedEmptyHyperlinks = (emptyHyperlinks ?? []).map((attrs, order) => ({
387
+ attrs,
388
+ order
389
+ })).toSorted((left, right) => left.attrs.offset - right.attrs.offset || left.order - right.order);
390
+ let nextEmptyHyperlink = 0;
391
+ let currentRun = null;
392
+ let currentMarksKey = null;
393
+ let currentHyperlink = null;
394
+ let currentHyperlinkKey = null;
395
+ const openedComments = /* @__PURE__ */ new Set();
396
+ const commentLastOffset = /* @__PURE__ */ new Map();
397
+ paragraph.forEach((node, offset) => {
398
+ for (const commentId of getCommentMarkIds(node.marks)) commentLastOffset.set(commentId, offset);
399
+ });
400
+ const flushCurrentInline = () => {
401
+ if (currentRun) {
402
+ content.push(currentRun);
403
+ currentRun = null;
404
+ currentMarksKey = null;
405
+ }
406
+ if (currentHyperlink) {
407
+ content.push(currentHyperlink);
408
+ currentHyperlink = null;
409
+ currentHyperlinkKey = null;
410
+ }
411
+ };
412
+ const syncCommentRanges = (node, offset) => {
413
+ const nodeCommentIds = getCommentMarkIds(node.marks);
414
+ const toClose = [];
415
+ for (const commentId of openedComments) {
416
+ const lastOffset = commentLastOffset.get(commentId) ?? offset;
417
+ if (!nodeCommentIds.has(commentId) && lastOffset <= offset) toClose.push(commentId);
418
+ }
419
+ const toOpen = [];
420
+ for (const commentId of nodeCommentIds) if (!openedComments.has(commentId)) toOpen.push(commentId);
421
+ if (toClose.length === 0 && toOpen.length === 0) return;
422
+ flushCurrentInline();
423
+ for (const commentId of toClose.toSorted((a, b) => a - b)) {
424
+ content.push({
425
+ type: "commentRangeEnd",
426
+ id: commentId
427
+ });
428
+ openedComments.delete(commentId);
429
+ }
430
+ for (const commentId of toOpen.toSorted((a, b) => a - b)) {
431
+ content.push({
432
+ type: "commentRangeStart",
433
+ id: commentId
434
+ });
435
+ openedComments.add(commentId);
436
+ }
437
+ };
438
+ const flushEmptyHyperlinksThroughOffset = (offset) => {
439
+ while (nextEmptyHyperlink < sortedEmptyHyperlinks.length) {
440
+ const item = sortedEmptyHyperlinks[nextEmptyHyperlink];
441
+ if (!item || item.attrs.offset > offset) break;
442
+ nextEmptyHyperlink += 1;
443
+ flushCurrentInline();
444
+ content.push(createEmptyHyperlink(item.attrs));
445
+ }
446
+ };
447
+ const processInlineNode = (node, offset) => {
448
+ syncCommentRanges(node, offset);
449
+ const linkMark = node.marks.find((m) => m.type.name === "hyperlink");
450
+ const noteRefMark = node.marks.find((m) => m.type.name === "footnoteRef");
451
+ if (noteRefMark && !linkMark) {
452
+ flushCurrentInline();
453
+ content.push(createNoteReferenceRun(noteRefMark, node.marks));
454
+ return;
455
+ }
456
+ const insertionMark = node.marks.find((m) => m.type.name === "insertion");
457
+ const deletionMark = node.marks.find((m) => m.type.name === "deletion");
458
+ if (insertionMark || deletionMark) {
459
+ flushCurrentInline();
460
+ const changeMark = insertionMark ?? deletionMark;
461
+ if (!changeMark) return;
462
+ const changeAttrs = expectTrackedChangeMarkAttrs(changeMark);
463
+ const run = createTrackedChangeRun(node, node.marks.filter((m) => m.type.name !== "insertion" && m.type.name !== "deletion"));
464
+ if (!run) return;
465
+ const info = {
466
+ id: changeAttrs.revisionId,
467
+ author: changeAttrs.author || "Unknown"
468
+ };
469
+ if (changeAttrs.date) info.date = changeAttrs.date;
470
+ if (insertionMark) if (changeAttrs.moveKind === "moveTo") content.push({
471
+ type: "moveTo",
472
+ info,
473
+ content: [run]
474
+ });
475
+ else content.push({
476
+ type: "insertion",
477
+ info,
478
+ content: [run]
479
+ });
480
+ else if (changeAttrs.moveKind === "moveFrom") content.push({
481
+ type: "moveFrom",
482
+ info,
483
+ content: [run]
484
+ });
485
+ else content.push({
486
+ type: "deletion",
487
+ info,
488
+ content: [run]
489
+ });
490
+ return;
491
+ }
492
+ if (linkMark) {
493
+ const linkKey = getLinkKey(linkMark);
494
+ if (currentHyperlink && currentHyperlinkKey === linkKey) addNodeToHyperlink(currentHyperlink, node);
495
+ else {
496
+ flushCurrentInline();
497
+ currentHyperlink = createHyperlink(linkMark);
498
+ currentHyperlinkKey = linkKey;
499
+ addNodeToHyperlink(currentHyperlink, node);
500
+ }
501
+ return;
502
+ }
503
+ if (currentHyperlink) flushCurrentInline();
504
+ if (node.isText) {
505
+ const marksKey = getMarksKey(node.marks);
506
+ if (currentRun && currentMarksKey === marksKey) appendTextToRun(currentRun, node.text || "");
507
+ else {
508
+ if (currentRun) content.push(currentRun);
509
+ currentRun = createRunFromText(node.text || "", node.marks);
510
+ currentMarksKey = marksKey;
511
+ }
512
+ } else if (node.type.name === "hardBreak") {
513
+ flushCurrentInline();
514
+ content.push(createBreakRun(readHardBreakType(node)));
515
+ } else if (node.type.name === "image") {
516
+ flushCurrentInline();
517
+ content.push(createImageRun(node));
518
+ } else if (node.type.name === "shape") {
519
+ flushCurrentInline();
520
+ content.push(createShapeRun(node));
521
+ } else if (node.type.name === "tab") {
522
+ flushCurrentInline();
523
+ content.push(createTabRun());
524
+ } else if (node.type.name === "field") {
525
+ flushCurrentInline();
526
+ content.push(createFieldFromNode(node, node.marks));
527
+ } else if (node.type.name === "sdt") {
528
+ flushCurrentInline();
529
+ content.push(createInlineSdtFromNode(node));
530
+ } else if (node.type.name === "math") {
531
+ flushCurrentInline();
532
+ content.push(createMathFromNode(node));
533
+ }
534
+ };
535
+ paragraph.forEach((node, offset) => {
536
+ flushEmptyHyperlinksThroughOffset(offset);
537
+ if (node.isText && node.text) {
538
+ let consumed = 0;
539
+ const textEndOffset = offset + node.nodeSize;
540
+ while (nextEmptyHyperlink < sortedEmptyHyperlinks.length) {
541
+ const item = sortedEmptyHyperlinks[nextEmptyHyperlink];
542
+ if (!item || item.attrs.offset >= textEndOffset) break;
543
+ const splitOffset = Math.max(item.attrs.offset - offset, consumed);
544
+ const segment = node.text.slice(consumed, splitOffset);
545
+ if (segment) processInlineNode(node.type.schema.text(segment, node.marks), offset);
546
+ flushCurrentInline();
547
+ content.push(createEmptyHyperlink(item.attrs));
548
+ nextEmptyHyperlink += 1;
549
+ consumed = splitOffset;
550
+ }
551
+ const remainder = node.text.slice(consumed);
552
+ if (remainder) processInlineNode(node.type.schema.text(remainder, node.marks), offset);
553
+ return;
554
+ }
555
+ processInlineNode(node, offset);
556
+ });
557
+ flushEmptyHyperlinksThroughOffset(Number.POSITIVE_INFINITY);
558
+ flushCurrentInline();
559
+ for (const commentId of openedComments) content.push({
560
+ type: "commentRangeEnd",
561
+ id: commentId
562
+ });
563
+ return content;
564
+ }
565
+ function createTrackedChangeRun(node, marks) {
566
+ if (node.isText) {
567
+ const formatting = marksToTextFormatting(marks);
568
+ return {
569
+ type: "run",
570
+ content: node.text ? [{
571
+ type: "text",
572
+ text: node.text
573
+ }] : [],
574
+ ...Object.keys(formatting).length > 0 ? { formatting } : {}
575
+ };
576
+ }
577
+ if (node.type.name === "hardBreak") return createBreakRun(readHardBreakType(node));
578
+ if (node.type.name === "image") return createImageRun(node);
579
+ if (node.type.name === "shape") return createShapeRun(node);
580
+ if (node.type.name === "tab") return createTabRun();
581
+ return null;
582
+ }
583
+ function createEmptyHyperlink(attrs) {
584
+ const hyperlink = {
585
+ type: "hyperlink",
586
+ children: []
587
+ };
588
+ if (attrs.href !== void 0) hyperlink.href = attrs.href;
589
+ if (attrs.anchor !== void 0) hyperlink.anchor = attrs.anchor;
590
+ if (attrs.tooltip !== void 0) hyperlink.tooltip = attrs.tooltip;
591
+ if (attrs.rId !== void 0) hyperlink.rId = attrs.rId;
592
+ return hyperlink;
593
+ }
594
+ function getCommentMarkIds(marks) {
595
+ const commentIds = /* @__PURE__ */ new Set();
596
+ for (const mark of marks) if (mark.type.name === "comment") commentIds.add(expectCommentMarkAttrs(mark).commentId);
597
+ return commentIds;
598
+ }
599
+ /**
600
+ * Build document-wide tracked change counts by scanning all nodes.
601
+ * Used for cross-paragraph move pair detection (moveFrom in one paragraph,
602
+ * moveTo in another).
603
+ */
604
+ function buildDocumentTrackedChangeCounts(pmDoc) {
605
+ const insertionById = /* @__PURE__ */ new Map();
606
+ const deletionById = /* @__PURE__ */ new Map();
607
+ pmDoc.descendants((node) => {
608
+ const insertionMark = node.marks.find((m) => m.type.name === "insertion");
609
+ const deletionMark = node.marks.find((m) => m.type.name === "deletion");
610
+ if (insertionMark) {
611
+ const { revisionId } = expectTrackedChangeMarkAttrs(insertionMark);
612
+ insertionById.set(revisionId, (insertionById.get(revisionId) ?? 0) + 1);
613
+ }
614
+ if (deletionMark) {
615
+ const { revisionId } = expectTrackedChangeMarkAttrs(deletionMark);
616
+ deletionById.set(revisionId, (deletionById.get(revisionId) ?? 0) + 1);
617
+ }
618
+ });
619
+ return {
620
+ insertionById,
621
+ deletionById
622
+ };
623
+ }
624
+ /**
625
+ * Create a unique key for a link mark
626
+ */
627
+ function getLinkKey(mark) {
628
+ const attrs = expectHyperlinkMarkAttrs(mark);
629
+ return [
630
+ attrs.href,
631
+ attrs.rId ?? "",
632
+ attrs.tooltip ?? "",
633
+ attrs._docxHyperlinkIndex ?? ""
634
+ ].join("\0");
635
+ }
636
+ /**
637
+ * Create a unique key for a set of marks (excluding hyperlink)
638
+ */
639
+ function getMarksKey(marks) {
640
+ const nonLinkMarks = marks.filter((m) => m.type.name !== "hyperlink");
641
+ if (nonLinkMarks.length === 0) return "";
642
+ return nonLinkMarks.map((m) => `${m.type.name}:${JSON.stringify(m.attrs)}`).toSorted().join("|");
643
+ }
644
+ /**
645
+ * Create a Hyperlink from a link mark
646
+ */
647
+ function createHyperlink(linkMark) {
648
+ const attrs = expectHyperlinkMarkAttrs(linkMark);
649
+ const href = attrs.href;
650
+ if (href.startsWith("#")) {
651
+ const hyperlink = {
652
+ type: "hyperlink",
653
+ anchor: href.slice(1),
654
+ children: []
655
+ };
656
+ if (attrs.tooltip) hyperlink.tooltip = attrs.tooltip;
657
+ return hyperlink;
658
+ }
659
+ const hyperlink = {
660
+ type: "hyperlink",
661
+ href,
662
+ children: []
663
+ };
664
+ if (attrs.tooltip) hyperlink.tooltip = attrs.tooltip;
665
+ if (attrs.rId) hyperlink.rId = attrs.rId;
666
+ return hyperlink;
667
+ }
668
+ /**
669
+ * Add a node to a hyperlink
670
+ */
671
+ function addNodeToHyperlink(hyperlink, node) {
672
+ const noteRefMark = node.marks.find((m) => m.type.name === "footnoteRef");
673
+ if (noteRefMark) {
674
+ hyperlink.children.push(createNoteReferenceRun(noteRefMark, node.marks));
675
+ return;
676
+ }
677
+ const nonLinkMarks = node.marks.filter((m) => m.type.name !== "hyperlink");
678
+ if (node.isText && node.text) {
679
+ const run = createRunFromText(node.text, nonLinkMarks);
680
+ hyperlink.children.push(run);
681
+ return;
682
+ }
683
+ if (node.type.name === "hardBreak") {
684
+ hyperlink.children.push(createBreakRun(readHardBreakType(node), nonLinkMarks));
685
+ return;
686
+ }
687
+ if (node.type.name === "tab") {
688
+ hyperlink.children.push(createTabRun(nonLinkMarks));
689
+ return;
690
+ }
691
+ if (node.type.name === "image") {
692
+ hyperlink.children.push(createImageRun(node));
693
+ return;
694
+ }
695
+ if (node.type.name === "shape") hyperlink.children.push(createShapeRun(node));
696
+ }
697
+ function getNoteReferenceVertAlign(noteAttrs, marks) {
698
+ if (marks.some((mark) => mark.type.name === "subscript")) return "subscript";
699
+ if (marks.some((mark) => mark.type.name === "superscript")) return "superscript";
700
+ if (noteAttrs.vertAlign === "baseline" || noteAttrs.vertAlign === "superscript") return noteAttrs.vertAlign;
701
+ }
702
+ function createNoteReferenceRun(noteRefMark, marks) {
703
+ const noteAttrs = expectFootnoteRefMarkAttrs(noteRefMark);
704
+ const run = {
705
+ type: "run",
706
+ content: [{
707
+ type: noteAttrs.noteType === "endnote" ? "endnoteRef" : "footnoteRef",
708
+ id: typeof noteAttrs.id === "string" ? Number.parseInt(noteAttrs.id, 10) || 0 : noteAttrs.id
709
+ }]
710
+ };
711
+ const vertAlign = getNoteReferenceVertAlign(noteAttrs, marks);
712
+ if (vertAlign) run.formatting = { vertAlign };
713
+ return run;
714
+ }
715
+ /**
716
+ * Create a Run from text and marks
717
+ */
718
+ function createRunFromText(text, marks) {
719
+ const formatting = getRunFormattingFromMarks(marks);
720
+ const run = {
721
+ type: "run",
722
+ content: [{
723
+ type: "text",
724
+ text
725
+ }]
726
+ };
727
+ if (formatting) run.formatting = formatting;
728
+ return run;
729
+ }
730
+ function getRunFormattingFromMarks(marks) {
731
+ if (!marks || marks.length === 0) return;
732
+ const formatting = marksToTextFormatting(marks);
733
+ return Object.keys(formatting).length > 0 ? formatting : void 0;
734
+ }
735
+ /**
736
+ * Append text to an existing run
737
+ */
738
+ function appendTextToRun(run, text) {
739
+ const lastContent = run.content.at(-1);
740
+ if (lastContent && lastContent.type === "text") lastContent.text += text;
741
+ else run.content.push({
742
+ type: "text",
743
+ text
744
+ });
745
+ }
746
+ /**
747
+ * Create a Run containing a line break
748
+ */
749
+ function createBreakRun(breakType = "textWrapping", marks) {
750
+ const run = {
751
+ type: "run",
752
+ content: [{
753
+ type: "break",
754
+ breakType
755
+ }]
756
+ };
757
+ const formatting = getRunFormattingFromMarks(marks);
758
+ if (formatting) run.formatting = formatting;
759
+ return run;
760
+ }
761
+ function readHardBreakType(node) {
762
+ return expectHardBreakAttrs(node).breakType ?? "textWrapping";
763
+ }
764
+ /**
765
+ * Create a Run containing a tab
766
+ */
767
+ function createTabRun(marks) {
768
+ const run = {
769
+ type: "run",
770
+ content: [{ type: "tab" }]
771
+ };
772
+ const formatting = getRunFormattingFromMarks(marks);
773
+ if (formatting) run.formatting = formatting;
774
+ return run;
775
+ }
776
+ /**
777
+ * Create a SimpleField or ComplexField from a PM field node
778
+ */
779
+ function createFieldFromNode(node, marks) {
780
+ const attrs = expectFieldAttrs(node);
781
+ const formatting = marks && marks.length > 0 ? marksToTextFormatting(marks) : void 0;
782
+ let displayText = attrs.displayText || "";
783
+ if (!displayText) switch (attrs.fieldType) {
784
+ case "PAGE":
785
+ displayText = "1";
786
+ break;
787
+ case "NUMPAGES":
788
+ displayText = "1";
789
+ break;
790
+ default:
791
+ displayText = " ";
792
+ break;
793
+ }
794
+ const displayRun = {
795
+ type: "run",
796
+ content: [{
797
+ type: "text",
798
+ text: displayText
799
+ }],
800
+ ...formatting && Object.keys(formatting).length > 0 ? { formatting } : {}
801
+ };
802
+ if (attrs.fieldKind === "complex") {
803
+ const complex = {
804
+ type: "complexField",
805
+ instruction: attrs.instruction,
806
+ fieldType: attrs.fieldType,
807
+ fieldCode: [],
808
+ fieldResult: [displayRun]
809
+ };
810
+ if (attrs.fldLock) complex.fldLock = true;
811
+ if (attrs.dirty) complex.dirty = true;
812
+ return complex;
813
+ }
814
+ const simple = {
815
+ type: "simpleField",
816
+ instruction: attrs.instruction,
817
+ fieldType: attrs.fieldType,
818
+ content: [displayRun]
819
+ };
820
+ if (attrs.fldLock) simple.fldLock = true;
821
+ if (attrs.dirty) simple.dirty = true;
822
+ return simple;
823
+ }
824
+ /**
825
+ * Create a MathEquation from a PM math node
826
+ */
827
+ function createMathFromNode(node) {
828
+ const attrs = expectMathAttrs(node);
829
+ const math = {
830
+ type: "mathEquation",
831
+ display: attrs.display ?? "inline",
832
+ ommlXml: attrs.ommlXml
833
+ };
834
+ if (attrs.plainText) math.plainText = attrs.plainText;
835
+ return math;
836
+ }
837
+ /**
838
+ * Create an InlineSdt from a PM sdt node
839
+ */
840
+ function createInlineSdtFromNode(node) {
841
+ const attrs = expectSdtAttrs(node);
842
+ const properties = { sdtType: attrs.sdtType };
843
+ if (attrs.alias) properties.alias = attrs.alias;
844
+ if (attrs.tag) properties.tag = attrs.tag;
845
+ if (typeof attrs.id === "number") properties.id = attrs.id;
846
+ if (attrs.lock) properties.lock = attrs.lock;
847
+ if (attrs.placeholder) properties.placeholder = attrs.placeholder;
848
+ if (attrs.showingPlaceholder !== void 0) properties.showingPlaceholder = attrs.showingPlaceholder;
849
+ if (attrs.dateFormat) properties.dateFormat = attrs.dateFormat;
850
+ if (attrs.dateValueISO) properties.dateValueISO = attrs.dateValueISO;
851
+ if (attrs.listItems) properties.listItems = parseSdtListItems(attrs.listItems);
852
+ if (typeof attrs.dropdownLastValue === "string") properties.dropdownLastValue = attrs.dropdownLastValue;
853
+ if (typeof attrs.checked === "boolean") properties.checked = attrs.checked;
854
+ if (attrs.rawPropertiesXml) properties.rawPropertiesXml = attrs.rawPropertiesXml;
855
+ if (attrs.rawEndPropertiesXml) properties.rawEndPropertiesXml = attrs.rawEndPropertiesXml;
856
+ return {
857
+ type: "inlineSdt",
858
+ properties,
859
+ content: extractParagraphContent(node).filter((c) => c.type === "run" || c.type === "hyperlink" || c.type === "simpleField" || c.type === "complexField" || c.type === "inlineSdt" || c.type === "mathEquation")
860
+ };
861
+ }
862
+ function parseSdtListItems(rawItems) {
863
+ const parsed = JSON.parse(rawItems);
864
+ if (!Array.isArray(parsed)) throw new TypeError("Invalid ProseMirror sdt attrs: listItems is not an array");
865
+ return parsed.map((item) => {
866
+ if (!item || typeof item !== "object" || Array.isArray(item)) throw new TypeError("Invalid ProseMirror sdt attrs: listItems contains an invalid item");
867
+ const itemAttrs = item;
868
+ if (typeof itemAttrs.displayText !== "string" || typeof itemAttrs.value !== "string") throw new TypeError("Invalid ProseMirror sdt attrs: listItems contains an invalid item");
869
+ return {
870
+ displayText: itemAttrs.displayText,
871
+ value: itemAttrs.value
872
+ };
873
+ });
874
+ }
875
+ /**
876
+ * Create a Run containing an image
877
+ */
878
+ function createImageRun(node) {
879
+ const attrs = expectImageAttrs(node);
880
+ const wrap = { type: attrs.wrapType || "inline" };
881
+ if (attrs.distTop !== void 0) wrap.distT = pixelsToEmu(attrs.distTop);
882
+ if (attrs.distBottom !== void 0) wrap.distB = pixelsToEmu(attrs.distBottom);
883
+ if (attrs.distLeft !== void 0) wrap.distL = pixelsToEmu(attrs.distLeft);
884
+ if (attrs.distRight !== void 0) wrap.distR = pixelsToEmu(attrs.distRight);
885
+ if (attrs.wrapText) wrap.wrapText = attrs.wrapText;
886
+ const image = {
887
+ type: "image",
888
+ rId: attrs.rId || "",
889
+ src: attrs.src,
890
+ size: {
891
+ width: pixelsToEmu(attrs.width || 0),
892
+ height: pixelsToEmu(attrs.height || 0)
893
+ },
894
+ wrap
895
+ };
896
+ if (attrs.alt) image.alt = attrs.alt;
897
+ if (attrs.title) image.title = attrs.title;
898
+ const imageTransform = parseTransformAttr(attrs.transform);
899
+ if (imageTransform) image.transform = imageTransform;
900
+ if (attrs.opacity != null) image.opacity = attrs.opacity;
901
+ const imagePosition = imagePositionFromAttrs(attrs.position);
902
+ if (imagePosition) image.position = imagePosition;
903
+ if (attrs.borderWidth && attrs.borderWidth > 0) {
904
+ const outline = {
905
+ width: pixelsToEmu(attrs.borderWidth),
906
+ style: attrs.borderStyle ? {
907
+ solid: "solid",
908
+ dotted: "dot",
909
+ dashed: "dash",
910
+ double: "solid",
911
+ groove: "solid",
912
+ ridge: "solid",
913
+ inset: "solid",
914
+ outset: "solid"
915
+ }[attrs.borderStyle] || "solid" : "solid"
916
+ };
917
+ if (attrs.borderColor) outline.color = { rgb: attrs.borderColor.replace("#", "") };
918
+ image.outline = outline;
919
+ }
920
+ if (attrs.hlinkHref) image.hlinkHref = attrs.hlinkHref;
921
+ const cropTop = attrs.cropTop != null && attrs.cropTop > 0 ? attrs.cropTop : void 0;
922
+ const cropRight = attrs.cropRight != null && attrs.cropRight > 0 ? attrs.cropRight : void 0;
923
+ const cropBottom = attrs.cropBottom != null && attrs.cropBottom > 0 ? attrs.cropBottom : void 0;
924
+ const cropLeft = attrs.cropLeft != null && attrs.cropLeft > 0 ? attrs.cropLeft : void 0;
925
+ if (cropTop !== void 0 || cropRight !== void 0 || cropBottom !== void 0 || cropLeft !== void 0) {
926
+ const crop = {};
927
+ if (cropTop !== void 0) crop.top = cropTop;
928
+ if (cropRight !== void 0) crop.right = cropRight;
929
+ if (cropBottom !== void 0) crop.bottom = cropBottom;
930
+ if (cropLeft !== void 0) crop.left = cropLeft;
931
+ image.crop = crop;
932
+ }
933
+ const drawingContent = {
934
+ type: "drawing",
935
+ image
936
+ };
937
+ if (attrs._docxRawXml) drawingContent.rawXml = attrs._docxRawXml;
938
+ return {
939
+ type: "run",
940
+ content: [drawingContent]
941
+ };
942
+ }
943
+ /**
944
+ * Create a Run from a ProseMirror shape node
945
+ */
946
+ function createShapeRun(node) {
947
+ const attrs = expectShapeAttrs(node);
948
+ const shape = {
949
+ type: "shape",
950
+ shapeType: attrs.shapeType || "rect",
951
+ size: {
952
+ width: attrs.width ? pixelsToEmu(attrs.width) : 0,
953
+ height: attrs.height ? pixelsToEmu(attrs.height) : 0
954
+ }
955
+ };
956
+ if (attrs.shapeId) shape.id = attrs.shapeId;
957
+ const shapeTransform = parseTransformAttr(attrs.transform);
958
+ if (shapeTransform) shape.transform = shapeTransform;
959
+ const wrap = { type: attrs.wrapType || "inline" };
960
+ if (attrs.distTop !== void 0) wrap.distT = pixelsToEmu(attrs.distTop);
961
+ if (attrs.distBottom !== void 0) wrap.distB = pixelsToEmu(attrs.distBottom);
962
+ if (attrs.distLeft !== void 0) wrap.distL = pixelsToEmu(attrs.distLeft);
963
+ if (attrs.distRight !== void 0) wrap.distR = pixelsToEmu(attrs.distRight);
964
+ if (attrs.wrapText) wrap.wrapText = attrs.wrapText;
965
+ shape.wrap = wrap;
966
+ const shapePosition = imagePositionFromAttrs(attrs.position);
967
+ if (shapePosition) shape.position = shapePosition;
968
+ if (attrs.fillType === "gradient" && attrs.gradientStops) try {
969
+ const parsed = JSON.parse(attrs.gradientStops);
970
+ const gradient = {
971
+ type: attrs.gradientType || "linear",
972
+ stops: parsed.map((s) => ({
973
+ position: s.position,
974
+ color: { rgb: s.color.replace("#", "") }
975
+ }))
976
+ };
977
+ if (attrs.gradientAngle) gradient.angle = attrs.gradientAngle;
978
+ shape.fill = {
979
+ type: "gradient",
980
+ gradient
981
+ };
982
+ } catch {
983
+ shape.fill = {
984
+ type: "solid",
985
+ color: { rgb: (attrs.fillColor || "000000").replace("#", "") }
986
+ };
987
+ }
988
+ else if (attrs.fillColor) shape.fill = {
989
+ type: attrs.fillType ?? "solid",
990
+ color: { rgb: attrs.fillColor.replace("#", "") }
991
+ };
992
+ else if (attrs.fillType === "none") shape.fill = { type: "none" };
993
+ if (attrs.outlineStyle !== "none" && (attrs.outlineWidth !== void 0 && attrs.outlineWidth > 0 || attrs.outlineColor || attrs.outlineStyle || attrs.outlineCap || attrs.outlineHeadEnd || attrs.outlineTailEnd)) {
994
+ const shapeOutline = {};
995
+ if (attrs.outlineWidth !== void 0 && attrs.outlineWidth > 0) shapeOutline.width = pixelsToEmu(attrs.outlineWidth);
996
+ if (attrs.outlineStyle) shapeOutline.style = normalizeShapeOutlineStyle(attrs.outlineStyle) ?? "solid";
997
+ if (attrs.outlineCap) shapeOutline.cap = attrs.outlineCap;
998
+ if (attrs.outlineHeadEnd) shapeOutline.headEnd = attrs.outlineHeadEnd;
999
+ if (attrs.outlineTailEnd) shapeOutline.tailEnd = attrs.outlineTailEnd;
1000
+ if (attrs.outlineColor) shapeOutline.color = { rgb: attrs.outlineColor.replace("#", "") };
1001
+ shape.outline = shapeOutline;
1002
+ }
1003
+ return {
1004
+ type: "run",
1005
+ content: [{
1006
+ type: "shape",
1007
+ shape
1008
+ }]
1009
+ };
1010
+ }
1011
+ /**
1012
+ * Convert ProseMirror marks to TextFormatting
1013
+ */
1014
+ function marksToTextFormatting(marks) {
1015
+ const formatting = {};
1016
+ let characterStyleRPr;
1017
+ for (const mark of marks) switch (mark.type.name) {
1018
+ case "bold":
1019
+ formatting.bold = true;
1020
+ formatting.boldCs = true;
1021
+ break;
1022
+ case "italic":
1023
+ formatting.italic = true;
1024
+ formatting.italicCs = true;
1025
+ break;
1026
+ case "underline": {
1027
+ const attrs = expectUnderlineMarkAttrs(mark);
1028
+ const uline = { style: attrs.style || "single" };
1029
+ if (attrs.color) uline.color = attrs.color;
1030
+ formatting.underline = uline;
1031
+ break;
1032
+ }
1033
+ case "strike":
1034
+ if (expectStrikeMarkAttrs(mark).double) formatting.doubleStrike = true;
1035
+ else formatting.strike = true;
1036
+ break;
1037
+ case "textColor": {
1038
+ const attrs = expectTextColorMarkAttrs(mark);
1039
+ const colorVal = {};
1040
+ if (attrs.rgb) colorVal.rgb = attrs.rgb;
1041
+ if (attrs.themeColor) colorVal.themeColor = attrs.themeColor;
1042
+ if (attrs.themeTint) colorVal.themeTint = attrs.themeTint;
1043
+ if (attrs.themeShade) colorVal.themeShade = attrs.themeShade;
1044
+ formatting.color = colorVal;
1045
+ break;
1046
+ }
1047
+ case "highlight":
1048
+ formatting.highlight = expectHighlightMarkAttrs(mark).color;
1049
+ break;
1050
+ case "runShading":
1051
+ formatting.shading = runShadingAttrsToShading(expectRunShadingMarkAttrs(mark));
1052
+ break;
1053
+ case "fontSize": {
1054
+ const attrs = expectFontSizeMarkAttrs(mark);
1055
+ formatting.fontSize = attrs.size;
1056
+ formatting.fontSizeCs = attrs.size;
1057
+ break;
1058
+ }
1059
+ case "fontFamily": {
1060
+ const attrs = expectFontFamilyMarkAttrs(mark);
1061
+ const ff = {};
1062
+ if (attrs.ascii) ff.ascii = attrs.ascii;
1063
+ if (attrs.hAnsi) ff.hAnsi = attrs.hAnsi;
1064
+ if (attrs.eastAsia) ff.eastAsia = attrs.eastAsia;
1065
+ const csVal = attrs.cs || attrs.ascii;
1066
+ if (csVal) ff.cs = csVal;
1067
+ if (attrs.asciiTheme) ff.asciiTheme = attrs.asciiTheme;
1068
+ if (attrs.hAnsiTheme) ff.hAnsiTheme = attrs.hAnsiTheme;
1069
+ if (attrs.eastAsiaTheme) ff.eastAsiaTheme = attrs.eastAsiaTheme;
1070
+ if (attrs.csTheme) ff.csTheme = attrs.csTheme;
1071
+ formatting.fontFamily = ff;
1072
+ break;
1073
+ }
1074
+ case "superscript":
1075
+ formatting.vertAlign = "superscript";
1076
+ break;
1077
+ case "subscript":
1078
+ formatting.vertAlign = "subscript";
1079
+ break;
1080
+ case "allCaps":
1081
+ formatting.allCaps = true;
1082
+ break;
1083
+ case "smallCaps":
1084
+ formatting.smallCaps = true;
1085
+ break;
1086
+ case "characterSpacing": {
1087
+ const attrs = expectCharacterSpacingMarkAttrs(mark);
1088
+ if (attrs.spacing !== void 0) formatting.spacing = attrs.spacing;
1089
+ if (attrs.position !== void 0) formatting.position = attrs.position;
1090
+ if (attrs.scale !== void 0) formatting.scale = attrs.scale;
1091
+ if (attrs.kerning !== void 0) formatting.kerning = attrs.kerning;
1092
+ break;
1093
+ }
1094
+ case "emboss":
1095
+ formatting.emboss = true;
1096
+ break;
1097
+ case "imprint":
1098
+ formatting.imprint = true;
1099
+ break;
1100
+ case "hidden":
1101
+ formatting.hidden = true;
1102
+ break;
1103
+ case "textShadow":
1104
+ formatting.shadow = true;
1105
+ break;
1106
+ case "emphasisMark":
1107
+ formatting.emphasisMark = expectEmphasisMarkAttrs(mark).type || "dot";
1108
+ break;
1109
+ case "textOutline":
1110
+ formatting.outline = true;
1111
+ break;
1112
+ case "rtl":
1113
+ formatting.rtl = true;
1114
+ break;
1115
+ case "textEffect":
1116
+ formatting.effect = expectTextEffectMarkAttrs(mark).effect;
1117
+ break;
1118
+ case "runFormattingOverride":
1119
+ applyRunFormattingOverrideAttrs(formatting, expectRunFormattingOverrideMarkAttrs(mark));
1120
+ break;
1121
+ case "characterStyle": {
1122
+ const attrs = expectCharacterStyleMarkAttrs(mark);
1123
+ formatting.styleId = attrs.styleId;
1124
+ characterStyleRPr = attrs._styleRPr;
1125
+ break;
1126
+ }
1127
+ default: break;
1128
+ }
1129
+ if (characterStyleRPr) return subtractCharacterStyleFormatting(formatting, characterStyleRPr);
1130
+ return formatting;
1131
+ }
1132
+ /**
1133
+ * Negatable boolean run-property keys whose serializer emits an explicit
1134
+ * `w:val="0"` override when the value is `false` (see `serializeTextFormatting`
1135
+ * in `runSerializer.ts`). Each entry pairs a base key with the complex-script
1136
+ * mirror that `marksToTextFormatting` sets alongside it (the bold/italic marks
1137
+ * set `*Cs` too), so a negative override disables both. Keys without a complex
1138
+ * mirror use `null`.
1139
+ */
1140
+ const NEGATABLE_STYLE_KEYS = [
1141
+ ["bold", "boldCs"],
1142
+ ["italic", "italicCs"],
1143
+ ["strike", null],
1144
+ ["doubleStrike", null],
1145
+ ["allCaps", null],
1146
+ ["smallCaps", null],
1147
+ ["hidden", null],
1148
+ ["emboss", null],
1149
+ ["imprint", null],
1150
+ ["shadow", null],
1151
+ ["outline", null],
1152
+ ["rtl", null]
1153
+ ];
1154
+ /**
1155
+ * Drop run formatting values that the run's character style already provides
1156
+ * (the `w:rStyle` reference re-imposes them on load), so a styled run
1157
+ * serializes back to a style reference instead of baked direct formatting.
1158
+ *
1159
+ * `styleRPr` is the load-time snapshot from the characterStyle mark, captured
1160
+ * in the same normal form this module produces from marks, so value equality
1161
+ * is a faithful "came from the style and is unchanged" check. Values that
1162
+ * differ (user edits, direct overrides from the source document) stay as
1163
+ * direct formatting, which wins over the style per the OOXML cascade.
1164
+ *
1165
+ * When the user *removes* a boolean property the style supplied (e.g. toggling
1166
+ * off bold on text whose `w:rStyle` is bold), that key is no longer present in
1167
+ * `formatting`, so the subtraction loop above never sees it. Without a counter,
1168
+ * the run keeps the style reference and Word re-applies the removed formatting
1169
+ * on load. The second pass emits an explicit negative override (`false`) for
1170
+ * each negatable boolean the style set to `true` but the run no longer carries.
1171
+ */
1172
+ function subtractCharacterStyleFormatting(formatting, styleRPr) {
1173
+ const result = {};
1174
+ for (const key of Object.keys(formatting)) {
1175
+ const value = formatting[key];
1176
+ if (value === void 0) continue;
1177
+ const styleValue = key === "styleId" ? void 0 : styleRPr[key];
1178
+ if (styleValue !== void 0 && JSON.stringify(value) === JSON.stringify(styleValue)) continue;
1179
+ result[key] = value;
1180
+ }
1181
+ for (const [key, csKey] of NEGATABLE_STYLE_KEYS) {
1182
+ if (styleRPr[key] !== true || formatting[key] !== void 0) continue;
1183
+ result[key] = false;
1184
+ if (csKey !== null) result[csKey] = false;
1185
+ }
1186
+ return result;
1187
+ }
1188
+ function applyRunFormattingOverrideAttrs(formatting, attrs) {
1189
+ if (attrs.bold === false) formatting.bold = false;
1190
+ if (attrs.italic === false) formatting.italic = false;
1191
+ if (attrs.underline === "none") formatting.underline = { style: "none" };
1192
+ if (attrs.strike === false) formatting.strike = false;
1193
+ if (attrs.doubleStrike === false) formatting.doubleStrike = false;
1194
+ if (attrs.allCaps === false) formatting.allCaps = false;
1195
+ if (attrs.smallCaps === false) formatting.smallCaps = false;
1196
+ if (attrs.hidden === false) formatting.hidden = false;
1197
+ if (attrs.emboss === false) formatting.emboss = false;
1198
+ if (attrs.imprint === false) formatting.imprint = false;
1199
+ if (attrs.shadow === false) formatting.shadow = false;
1200
+ if (attrs.outline === false) formatting.outline = false;
1201
+ if (attrs.rtl === false) formatting.rtl = false;
1202
+ }
1203
+ /**
1204
+ * Convert a ProseMirror table node to our Table type
1205
+ */
1206
+ function inferTableBorders(rows) {
1207
+ for (const row of rows) for (const cell of row.cells) {
1208
+ const borders = cell.formatting?.borders;
1209
+ if (borders) {
1210
+ const base = borders.top || borders.left || borders.right || borders.bottom || borders.insideH || borders.insideV;
1211
+ if (!base) return;
1212
+ return {
1213
+ top: borders.top ?? base,
1214
+ bottom: borders.bottom ?? base,
1215
+ left: borders.left ?? base,
1216
+ right: borders.right ?? base,
1217
+ insideH: borders.insideH ?? borders.bottom ?? base,
1218
+ insideV: borders.insideV ?? borders.right ?? base
1219
+ };
1220
+ }
1221
+ }
1222
+ }
1223
+ function convertPMTable(node, documentCounts) {
1224
+ const attrs = expectTableAttrs(node);
1225
+ const rows = convertPMTableRows(node, documentCounts);
1226
+ const formatting = tableAttrsToFormatting(attrs) || void 0;
1227
+ if (!formatting?.borders) {
1228
+ const inferredBorders = inferTableBorders(rows);
1229
+ if (inferredBorders) if (formatting) formatting.borders = inferredBorders;
1230
+ else {
1231
+ const minTable = {
1232
+ type: "table",
1233
+ formatting: { borders: inferredBorders },
1234
+ rows
1235
+ };
1236
+ if (attrs.columnWidths) minTable.columnWidths = attrs.columnWidths;
1237
+ return minTable;
1238
+ }
1239
+ }
1240
+ const table = {
1241
+ type: "table",
1242
+ rows
1243
+ };
1244
+ if (attrs.columnWidths) table.columnWidths = attrs.columnWidths;
1245
+ if (formatting) table.formatting = formatting;
1246
+ return table;
1247
+ }
1248
+ function convertPMTableRows(node, documentCounts) {
1249
+ const rows = [];
1250
+ const activeVerticalMerges = /* @__PURE__ */ new Map();
1251
+ node.forEach((rowNode) => {
1252
+ if (rowNode.type.name === "tableRow") rows.push(convertPMTableRow(rowNode, documentCounts, activeVerticalMerges));
1253
+ });
1254
+ return rows;
1255
+ }
1256
+ /**
1257
+ * Build CellMargins from PM margin attrs (top/bottom/left/right as number|null|undefined)
1258
+ */
1259
+ function buildCellMarginsFromAttrs(m) {
1260
+ const margins = {};
1261
+ if (m.top !== null && m.top !== void 0) margins.top = {
1262
+ value: m.top,
1263
+ type: "dxa"
1264
+ };
1265
+ if (m.bottom !== null && m.bottom !== void 0) margins.bottom = {
1266
+ value: m.bottom,
1267
+ type: "dxa"
1268
+ };
1269
+ if (m.left !== null && m.left !== void 0) margins.left = {
1270
+ value: m.left,
1271
+ type: "dxa"
1272
+ };
1273
+ if (m.right !== null && m.right !== void 0) margins.right = {
1274
+ value: m.right,
1275
+ type: "dxa"
1276
+ };
1277
+ return margins;
1278
+ }
1279
+ /**
1280
+ * Convert ProseMirror table attrs to TableFormatting
1281
+ */
1282
+ function tableAttrsToFormatting(attrs) {
1283
+ if (attrs._originalFormatting) {
1284
+ const orig = attrs._originalFormatting;
1285
+ const result = { ...orig };
1286
+ if (attrs.styleId !== (orig.styleId ?? void 0)) if (attrs.styleId) result.styleId = attrs.styleId;
1287
+ else delete result.styleId;
1288
+ if (attrs.justification !== (orig.justification ?? void 0)) if (attrs.justification) result.justification = attrs.justification;
1289
+ else delete result.justification;
1290
+ if (attrs.floating !== (orig.floating ?? void 0)) if (attrs.floating) result.floating = attrs.floating;
1291
+ else delete result.floating;
1292
+ if (attrs.look !== (orig.look ?? void 0)) if (attrs.look) result.look = attrs.look;
1293
+ else delete result.look;
1294
+ if (attrs.borders !== (orig.borders ?? void 0)) if (attrs.borders) result.borders = attrs.borders;
1295
+ else delete result.borders;
1296
+ const tableWidth = attrs.width;
1297
+ const tableWidthType = attrs.widthType;
1298
+ const origWidthVal = orig.width?.value;
1299
+ const origWidthType = orig.width?.type;
1300
+ if (tableWidth !== origWidthVal || tableWidthType !== origWidthType) if (tableWidth !== void 0 || tableWidthType !== void 0) result.width = {
1301
+ value: tableWidth ?? 0,
1302
+ type: tableWidthType ?? "dxa"
1303
+ };
1304
+ else delete result.width;
1305
+ if (attrs.cellMargins) result.cellMargins = buildCellMarginsFromAttrs(attrs.cellMargins);
1306
+ return result;
1307
+ }
1308
+ const tableWidth = attrs.width;
1309
+ const tableWidthType = attrs.widthType;
1310
+ if (!(attrs.styleId || tableWidth !== void 0 || tableWidthType !== void 0 || attrs.justification || attrs.floating || attrs.cellMargins || attrs.look || attrs.borders)) return;
1311
+ const cellMargins = attrs.cellMargins ? buildCellMarginsFromAttrs(attrs.cellMargins) : void 0;
1312
+ let width;
1313
+ if (tableWidth !== void 0 || tableWidthType !== void 0) width = {
1314
+ value: tableWidth ?? 0,
1315
+ type: tableWidthType ?? "dxa"
1316
+ };
1317
+ const f = {};
1318
+ if (attrs.styleId) f.styleId = attrs.styleId;
1319
+ if (width) f.width = width;
1320
+ if (attrs.justification) f.justification = attrs.justification;
1321
+ if (attrs.floating) f.floating = attrs.floating;
1322
+ if (cellMargins) f.cellMargins = cellMargins;
1323
+ if (attrs.look) f.look = attrs.look;
1324
+ if (attrs.borders) f.borders = attrs.borders;
1325
+ return f;
1326
+ }
1327
+ /**
1328
+ * Convert a ProseMirror table row node to our TableRow type
1329
+ */
1330
+ function convertPMTableRow(node, documentCounts, activeVerticalMerges) {
1331
+ const attrs = expectTableRowAttrs(node);
1332
+ const cells = [];
1333
+ let gridColumn = 0;
1334
+ const appendActiveVerticalMerges = () => {
1335
+ if (!activeVerticalMerges) return;
1336
+ let activeMerge = activeVerticalMerges.get(gridColumn);
1337
+ while (activeMerge) {
1338
+ const preservedCell = activeMerge.continuationCells?.shift();
1339
+ cells.push(preservedCell ?? createVerticalMergeContinuationCell(activeMerge.colspan));
1340
+ activeMerge.remainingRows -= 1;
1341
+ if (activeMerge.remainingRows <= 0) activeVerticalMerges.delete(gridColumn);
1342
+ gridColumn += activeMerge.colspan;
1343
+ activeMerge = activeVerticalMerges.get(gridColumn);
1344
+ }
1345
+ };
1346
+ node.forEach((cellNode) => {
1347
+ appendActiveVerticalMerges();
1348
+ if (cellNode.type.name === "tableCell" || cellNode.type.name === "tableHeader") {
1349
+ const cellAttrs = expectTableCellAttrs(cellNode);
1350
+ const colspan = Math.max(cellAttrs.colspan, 1);
1351
+ cells.push(convertPMTableCell(cellNode, documentCounts));
1352
+ if (cellAttrs.rowspan > 1) {
1353
+ const continuationCells = cellAttrs._docxVMergeContinuationCells;
1354
+ activeVerticalMerges?.set(gridColumn, {
1355
+ remainingRows: cellAttrs.rowspan - 1,
1356
+ colspan,
1357
+ ...continuationCells ? { continuationCells: [...continuationCells] } : {}
1358
+ });
1359
+ }
1360
+ gridColumn += colspan;
1361
+ }
1362
+ });
1363
+ appendActiveVerticalMerges();
1364
+ const row = {
1365
+ type: "tableRow",
1366
+ cells
1367
+ };
1368
+ const rowFormatting = tableRowAttrsToFormatting(attrs);
1369
+ if (rowFormatting) row.formatting = rowFormatting;
1370
+ return row;
1371
+ }
1372
+ function createVerticalMergeContinuationCell(colspan) {
1373
+ const formatting = { vMerge: "continue" };
1374
+ if (colspan > 1) formatting.gridSpan = colspan;
1375
+ return {
1376
+ type: "tableCell",
1377
+ content: [{
1378
+ type: "paragraph",
1379
+ content: []
1380
+ }],
1381
+ formatting
1382
+ };
1383
+ }
1384
+ /**
1385
+ * Convert ProseMirror table row attrs to TableRowFormatting
1386
+ */
1387
+ function tableRowAttrsToFormatting(attrs) {
1388
+ if (attrs._originalFormatting) {
1389
+ const orig = attrs._originalFormatting;
1390
+ const result = { ...orig };
1391
+ if (attrs.height !== (orig.height?.value ?? void 0)) if (attrs.height) result.height = {
1392
+ value: attrs.height,
1393
+ type: "dxa"
1394
+ };
1395
+ else delete result.height;
1396
+ if (attrs.heightRule !== (orig.heightRule ?? void 0)) if (attrs.heightRule) result.heightRule = attrs.heightRule;
1397
+ else delete result.heightRule;
1398
+ if (attrs.isHeader !== (orig.header ?? void 0)) if (attrs.isHeader) result.header = attrs.isHeader;
1399
+ else delete result.header;
1400
+ return result;
1401
+ }
1402
+ if (!(attrs.height || attrs.isHeader)) return;
1403
+ const f = {};
1404
+ if (attrs.height) f.height = {
1405
+ value: attrs.height,
1406
+ type: "dxa"
1407
+ };
1408
+ if (attrs.heightRule) f.heightRule = attrs.heightRule;
1409
+ if (attrs.isHeader) f.header = attrs.isHeader;
1410
+ return f;
1411
+ }
1412
+ /**
1413
+ * Convert a ProseMirror table cell node to our TableCell type
1414
+ */
1415
+ function convertPMTableCell(node, documentCounts) {
1416
+ const attrs = expectTableCellAttrs(node);
1417
+ const content = [];
1418
+ node.forEach((contentNode) => {
1419
+ if (contentNode.type.name === "paragraph") content.push(convertPMParagraph(contentNode, documentCounts));
1420
+ else if (contentNode.type.name === "table") content.push(convertPMTable(contentNode, documentCounts));
1421
+ });
1422
+ const cell = {
1423
+ type: "tableCell",
1424
+ content
1425
+ };
1426
+ const cellFormatting = tableCellAttrsToFormatting(attrs);
1427
+ if (cellFormatting) cell.formatting = cellFormatting;
1428
+ return cell;
1429
+ }
1430
+ /**
1431
+ * Convert ProseMirror table cell attrs to TableCellFormatting
1432
+ * Borders are stored as full BorderSpec objects — no conversion needed.
1433
+ */
1434
+ function tableCellAttrsToFormatting(attrs) {
1435
+ if (attrs._originalFormatting) {
1436
+ const orig = attrs._originalFormatting;
1437
+ const result = { ...orig };
1438
+ if (attrs.colspan > 1) result.gridSpan = attrs.colspan;
1439
+ if (attrs.rowspan > 1) result.vMerge = "restart";
1440
+ else if (result.vMerge === "restart" && !attrs._preserveVMergeRestart) delete result.vMerge;
1441
+ const cellWidth = attrs.width;
1442
+ if (cellWidth !== void 0) result.width = {
1443
+ value: cellWidth,
1444
+ type: attrs.widthType ?? "dxa"
1445
+ };
1446
+ if (attrs.verticalAlign !== (orig.verticalAlign ?? void 0)) if (attrs.verticalAlign) result.verticalAlign = attrs.verticalAlign;
1447
+ else delete result.verticalAlign;
1448
+ if (attrs.backgroundColor) result.shading = { fill: { rgb: attrs.backgroundColor } };
1449
+ else if (!attrs.backgroundColor && orig.shading) delete result.shading;
1450
+ if (attrs.borders) result.borders = attrs.borders;
1451
+ if (attrs.margins) result.margins = buildCellMarginsFromAttrs(attrs.margins);
1452
+ if (attrs.textDirection !== (orig.textDirection ?? void 0)) if (attrs.textDirection) result.textDirection = attrs.textDirection;
1453
+ else delete result.textDirection;
1454
+ return result;
1455
+ }
1456
+ const cellWidth = attrs.width;
1457
+ if (!(attrs.colspan > 1 || attrs.rowspan > 1 || cellWidth !== void 0 || attrs.verticalAlign || attrs.backgroundColor || attrs.borders || attrs.margins || attrs.textDirection)) return;
1458
+ const f = {};
1459
+ if (attrs.colspan > 1) f.gridSpan = attrs.colspan;
1460
+ if (attrs.rowspan > 1) f.vMerge = "restart";
1461
+ if (cellWidth !== void 0) f.width = {
1462
+ value: cellWidth,
1463
+ type: attrs.widthType ?? "dxa"
1464
+ };
1465
+ if (attrs.verticalAlign) f.verticalAlign = attrs.verticalAlign;
1466
+ if (attrs.textDirection) f.textDirection = attrs.textDirection;
1467
+ if (attrs.backgroundColor) f.shading = { fill: { rgb: attrs.backgroundColor } };
1468
+ if (attrs.borders) f.borders = attrs.borders;
1469
+ if (attrs.margins) f.margins = buildCellMarginsFromAttrs(attrs.margins);
1470
+ return f;
1471
+ }
1472
+ /**
1473
+ * Convert a ProseMirror textBox node back to a Paragraph wrapping a ShapeContent run.
1474
+ * The text box content becomes a Shape with textBody.
1475
+ */
1476
+ function convertPMTextBox(node) {
1477
+ const attrs = expectTextBoxAttrs(node);
1478
+ const childParagraphs = [];
1479
+ node.forEach((child) => {
1480
+ if (child.type.name === "paragraph") childParagraphs.push(convertPMParagraph(child));
1481
+ });
1482
+ const shape = {
1483
+ type: "shape",
1484
+ shapeType: "textBox",
1485
+ size: {
1486
+ width: attrs.width ? pixelsToEmu(attrs.width) : 0,
1487
+ height: attrs.height ? pixelsToEmu(attrs.height) : 0
1488
+ },
1489
+ textBody: {
1490
+ content: childParagraphs.length > 0 ? childParagraphs : [{
1491
+ type: "paragraph",
1492
+ content: []
1493
+ }],
1494
+ margins: (() => {
1495
+ const m = {};
1496
+ if (typeof attrs.marginTop === "number") m.top = pixelsToEmu(attrs.marginTop);
1497
+ if (typeof attrs.marginBottom === "number") m.bottom = pixelsToEmu(attrs.marginBottom);
1498
+ if (typeof attrs.marginLeft === "number") m.left = pixelsToEmu(attrs.marginLeft);
1499
+ if (typeof attrs.marginRight === "number") m.right = pixelsToEmu(attrs.marginRight);
1500
+ return m;
1501
+ })()
1502
+ }
1503
+ };
1504
+ if (attrs.textBoxId) shape.id = attrs.textBoxId;
1505
+ if (attrs.fillColor) shape.fill = {
1506
+ type: "solid",
1507
+ color: { rgb: attrs.fillColor.replace("#", "") }
1508
+ };
1509
+ if (attrs.outlineStyle !== "none" && attrs.outlineWidth && attrs.outlineWidth > 0) {
1510
+ const tbOutline = {
1511
+ width: pixelsToEmu(attrs.outlineWidth),
1512
+ style: normalizeShapeOutlineStyle(attrs.outlineStyle) ?? "solid"
1513
+ };
1514
+ if (attrs.outlineColor) tbOutline.color = { rgb: attrs.outlineColor.replace("#", "") };
1515
+ shape.outline = tbOutline;
1516
+ }
1517
+ const wrap = textBoxWrapFromAttrs(attrs);
1518
+ if (wrap) shape.wrap = wrap;
1519
+ const position = imagePositionFromAttrs(attrs.position);
1520
+ if (position) shape.position = position;
1521
+ return {
1522
+ type: "paragraph",
1523
+ content: [{
1524
+ type: "run",
1525
+ content: [{
1526
+ type: "shape",
1527
+ shape
1528
+ }]
1529
+ }]
1530
+ };
1531
+ }
1532
+ /**
1533
+ * Update a Document with content from a ProseMirror document
1534
+ * Preserves all non-content parts of the original document
1535
+ */
1536
+ function updateDocumentContent(originalDocument, pmDoc) {
1537
+ return fromProseDoc(pmDoc, originalDocument);
1538
+ }
1539
+ /**
1540
+ * Convert a ProseMirror document back to an array of `BlockContent` blocks
1541
+ * (paragraphs, tables, and block-level content controls).
1542
+ *
1543
+ * Used for converting edited header/footer PM content back to the document
1544
+ * model.
1545
+ */
1546
+ function proseDocToBlocks(pmDoc) {
1547
+ return extractBlocks(pmDoc);
1548
+ }
1549
+ //#endregion
1550
+ export { fromProseDoc, marksToTextFormatting, proseDocToBlocks, updateDocumentContent };