@beyondwork/docx-react-component 1.0.27 → 1.0.29

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 (356) hide show
  1. package/dist/canonical-document-BLEbzL2J.d.cts +844 -0
  2. package/dist/canonical-document-BLEbzL2J.d.ts +844 -0
  3. package/dist/chunk-2FJS5GZM.js +763 -0
  4. package/dist/chunk-2FJS5GZM.js.map +1 -0
  5. package/{src/core/commands/section-layout-commands.ts → dist/chunk-2OQBZS3F.js} +106 -340
  6. package/dist/chunk-2OQBZS3F.js.map +1 -0
  7. package/dist/chunk-2S7W4KFO.js +127 -0
  8. package/dist/chunk-2S7W4KFO.js.map +1 -0
  9. package/dist/chunk-2TG72QSW.js +3874 -0
  10. package/dist/chunk-2TG72QSW.js.map +1 -0
  11. package/{src/core/commands/table-structure-commands.ts → dist/chunk-36QNIZBO.js} +126 -315
  12. package/dist/chunk-36QNIZBO.js.map +1 -0
  13. package/dist/chunk-4AQOYAW4.js +3069 -0
  14. package/dist/chunk-4AQOYAW4.js.map +1 -0
  15. package/dist/chunk-4D5EWJ3P.js +77 -0
  16. package/dist/chunk-4D5EWJ3P.js.map +1 -0
  17. package/dist/chunk-5FN54NDH.js +2257 -0
  18. package/dist/chunk-5FN54NDH.js.map +1 -0
  19. package/dist/chunk-BOYGQYRQ.js +7306 -0
  20. package/dist/chunk-BOYGQYRQ.js.map +1 -0
  21. package/dist/chunk-CN3XMECL.js +212 -0
  22. package/dist/chunk-CN3XMECL.js.map +1 -0
  23. package/dist/chunk-EBI3BX6U.js +164 -0
  24. package/dist/chunk-EBI3BX6U.js.map +1 -0
  25. package/dist/chunk-EILUG3VB.js +1275 -0
  26. package/dist/chunk-EILUG3VB.js.map +1 -0
  27. package/dist/chunk-FUDY333O.js +70 -0
  28. package/dist/chunk-FUDY333O.js.map +1 -0
  29. package/dist/chunk-GBVOWFIK.js +1237 -0
  30. package/dist/chunk-GBVOWFIK.js.map +1 -0
  31. package/dist/chunk-H4TQ3H3Y.js +262 -0
  32. package/dist/chunk-H4TQ3H3Y.js.map +1 -0
  33. package/{src/core/commands/style-commands.ts → dist/chunk-JGB3IXZO.js} +40 -113
  34. package/dist/chunk-JGB3IXZO.js.map +1 -0
  35. package/dist/chunk-KD2QRQPY.js +4342 -0
  36. package/dist/chunk-KD2QRQPY.js.map +1 -0
  37. package/dist/chunk-KLMXQVYK.js +369 -0
  38. package/dist/chunk-KLMXQVYK.js.map +1 -0
  39. package/dist/chunk-KZUG5KFQ.js +214 -0
  40. package/dist/chunk-KZUG5KFQ.js.map +1 -0
  41. package/{src/core/state/text-transaction.ts → dist/chunk-QDAQ4CJU.js} +79 -236
  42. package/dist/chunk-QDAQ4CJU.js.map +1 -0
  43. package/{src/legal/bookmarks.ts → dist/chunk-RMH72RZI.js} +44 -130
  44. package/dist/chunk-RMH72RZI.js.map +1 -0
  45. package/dist/chunk-SWKWQZXM.js +117 -0
  46. package/dist/chunk-SWKWQZXM.js.map +1 -0
  47. package/{src/core/commands/formatting-commands.ts → dist/chunk-TJBP2K4T.js} +196 -536
  48. package/dist/chunk-TJBP2K4T.js.map +1 -0
  49. package/dist/chunk-TLCEAQDQ.js +542 -0
  50. package/dist/chunk-TLCEAQDQ.js.map +1 -0
  51. package/{src/core/commands/text-commands.ts → dist/chunk-UZXBISGO.js} +86 -142
  52. package/dist/chunk-UZXBISGO.js.map +1 -0
  53. package/dist/chunk-WGBAKP3Q.js +3220 -0
  54. package/dist/chunk-WGBAKP3Q.js.map +1 -0
  55. package/dist/compare/index.cjs +5475 -0
  56. package/dist/compare/index.cjs.map +1 -0
  57. package/dist/compare/index.d.cts +114 -0
  58. package/dist/compare/index.d.ts +114 -0
  59. package/dist/compare/index.js +731 -0
  60. package/dist/compare/index.js.map +1 -0
  61. package/dist/core/commands/formatting-commands.cjs +828 -0
  62. package/dist/core/commands/formatting-commands.cjs.map +1 -0
  63. package/dist/core/commands/formatting-commands.d.cts +63 -0
  64. package/dist/core/commands/formatting-commands.d.ts +63 -0
  65. package/dist/core/commands/formatting-commands.js +37 -0
  66. package/dist/core/commands/formatting-commands.js.map +1 -0
  67. package/dist/core/commands/image-commands.cjs +2023 -0
  68. package/dist/core/commands/image-commands.cjs.map +1 -0
  69. package/dist/core/commands/image-commands.d.cts +58 -0
  70. package/dist/core/commands/image-commands.d.ts +58 -0
  71. package/dist/core/commands/image-commands.js +18 -0
  72. package/dist/core/commands/image-commands.js.map +1 -0
  73. package/dist/core/commands/section-layout-commands.cjs +477 -0
  74. package/dist/core/commands/section-layout-commands.cjs.map +1 -0
  75. package/dist/core/commands/section-layout-commands.d.cts +62 -0
  76. package/dist/core/commands/section-layout-commands.d.ts +62 -0
  77. package/dist/core/commands/section-layout-commands.js +21 -0
  78. package/dist/core/commands/section-layout-commands.js.map +1 -0
  79. package/dist/core/commands/style-commands.cjs +214 -0
  80. package/dist/core/commands/style-commands.cjs.map +1 -0
  81. package/dist/core/commands/style-commands.d.cts +13 -0
  82. package/dist/core/commands/style-commands.d.ts +13 -0
  83. package/dist/core/commands/style-commands.js +9 -0
  84. package/dist/core/commands/style-commands.js.map +1 -0
  85. package/dist/core/commands/table-structure-commands.cjs +1883 -0
  86. package/dist/core/commands/table-structure-commands.cjs.map +1 -0
  87. package/dist/core/commands/table-structure-commands.d.cts +59 -0
  88. package/dist/core/commands/table-structure-commands.d.ts +59 -0
  89. package/dist/core/commands/table-structure-commands.js +12 -0
  90. package/dist/core/commands/table-structure-commands.js.map +1 -0
  91. package/dist/core/commands/text-commands.cjs +2391 -0
  92. package/dist/core/commands/text-commands.cjs.map +1 -0
  93. package/dist/core/commands/text-commands.d.cts +24 -0
  94. package/dist/core/commands/text-commands.d.ts +24 -0
  95. package/dist/core/commands/text-commands.js +28 -0
  96. package/dist/core/commands/text-commands.js.map +1 -0
  97. package/dist/core/selection/mapping.cjs +200 -0
  98. package/dist/core/selection/mapping.cjs.map +1 -0
  99. package/dist/core/selection/mapping.d.cts +2 -0
  100. package/dist/core/selection/mapping.d.ts +2 -0
  101. package/dist/core/selection/mapping.js +31 -0
  102. package/dist/core/selection/mapping.js.map +1 -0
  103. package/dist/core/state/editor-state.cjs +2278 -0
  104. package/dist/core/state/editor-state.cjs.map +1 -0
  105. package/dist/core/state/editor-state.d.cts +2 -0
  106. package/dist/core/state/editor-state.d.ts +2 -0
  107. package/dist/core/state/editor-state.js +26 -0
  108. package/dist/core/state/editor-state.js.map +1 -0
  109. package/dist/index.cjs +38553 -0
  110. package/dist/index.cjs.map +1 -0
  111. package/dist/index.d.cts +15 -0
  112. package/dist/index.d.ts +15 -0
  113. package/dist/index.js +7856 -0
  114. package/dist/index.js.map +1 -0
  115. package/dist/io/docx-session.cjs +16236 -0
  116. package/dist/io/docx-session.cjs.map +1 -0
  117. package/dist/io/docx-session.d.cts +21 -0
  118. package/dist/io/docx-session.d.ts +21 -0
  119. package/dist/io/docx-session.js +18 -0
  120. package/dist/io/docx-session.js.map +1 -0
  121. package/dist/legal/index.cjs +3900 -0
  122. package/dist/legal/index.cjs.map +1 -0
  123. package/dist/legal/index.d.cts +86 -0
  124. package/dist/legal/index.d.ts +86 -0
  125. package/dist/legal/index.js +616 -0
  126. package/dist/legal/index.js.map +1 -0
  127. package/dist/public-types-7ZL_94cz.d.ts +1573 -0
  128. package/dist/public-types-CeMaDueh.d.cts +1573 -0
  129. package/dist/public-types.cjs +19 -0
  130. package/dist/public-types.cjs.map +1 -0
  131. package/dist/public-types.d.cts +2 -0
  132. package/dist/public-types.d.ts +2 -0
  133. package/dist/public-types.js +1 -0
  134. package/dist/public-types.js.map +1 -0
  135. package/dist/runtime/document-runtime.cjs +11140 -0
  136. package/dist/runtime/document-runtime.cjs.map +1 -0
  137. package/dist/runtime/document-runtime.d.cts +231 -0
  138. package/dist/runtime/document-runtime.d.ts +231 -0
  139. package/dist/runtime/document-runtime.js +21 -0
  140. package/dist/runtime/document-runtime.js.map +1 -0
  141. package/dist/structural-helpers-CilgOVhh.d.cts +10 -0
  142. package/dist/structural-helpers-q0Gd-eBN.d.ts +10 -0
  143. package/dist/ui-tailwind/editor-surface/search-plugin.cjs +313 -0
  144. package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +1 -0
  145. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +67 -0
  146. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +67 -0
  147. package/dist/ui-tailwind/editor-surface/search-plugin.js +23 -0
  148. package/dist/ui-tailwind/editor-surface/search-plugin.js.map +1 -0
  149. package/dist/ui-tailwind/index.cjs +4833 -0
  150. package/dist/ui-tailwind/index.cjs.map +1 -0
  151. package/dist/ui-tailwind/index.d.cts +617 -0
  152. package/dist/ui-tailwind/index.d.ts +617 -0
  153. package/dist/ui-tailwind/index.js +575 -0
  154. package/dist/ui-tailwind/index.js.map +1 -0
  155. package/package.json +64 -54
  156. package/src/README.md +0 -85
  157. package/src/api/README.md +0 -26
  158. package/src/api/public-types.ts +0 -1418
  159. package/src/api/session-state.ts +0 -60
  160. package/src/compare/diff-engine.ts +0 -623
  161. package/src/compare/export-redlines.ts +0 -280
  162. package/src/compare/index.ts +0 -25
  163. package/src/compare/snapshot.ts +0 -97
  164. package/src/component-inventory.md +0 -99
  165. package/src/core/README.md +0 -10
  166. package/src/core/commands/README.md +0 -3
  167. package/src/core/commands/image-commands.ts +0 -373
  168. package/src/core/commands/index.ts +0 -1757
  169. package/src/core/commands/list-commands.ts +0 -565
  170. package/src/core/commands/paragraph-layout-commands.ts +0 -339
  171. package/src/core/commands/review-commands.ts +0 -108
  172. package/src/core/commands/structural-helpers.ts +0 -309
  173. package/src/core/schema/README.md +0 -3
  174. package/src/core/schema/text-schema.ts +0 -516
  175. package/src/core/search/search-text.ts +0 -357
  176. package/src/core/selection/README.md +0 -3
  177. package/src/core/selection/mapping.ts +0 -289
  178. package/src/core/selection/review-anchors.ts +0 -183
  179. package/src/core/state/README.md +0 -3
  180. package/src/core/state/editor-state.ts +0 -892
  181. package/src/formats/xlsx/io/parse-shared-strings.ts +0 -41
  182. package/src/formats/xlsx/io/parse-sheet.ts +0 -459
  183. package/src/formats/xlsx/io/parse-styles.ts +0 -59
  184. package/src/formats/xlsx/io/parse-workbook.ts +0 -75
  185. package/src/formats/xlsx/io/serialize-shared-strings.ts +0 -72
  186. package/src/formats/xlsx/io/serialize-sheet.ts +0 -333
  187. package/src/formats/xlsx/io/serialize-styles.ts +0 -98
  188. package/src/formats/xlsx/io/serialize-workbook.ts +0 -429
  189. package/src/formats/xlsx/io/xlsx-session.ts +0 -314
  190. package/src/formats/xlsx/model/cell.ts +0 -189
  191. package/src/formats/xlsx/model/sheet.ts +0 -326
  192. package/src/formats/xlsx/model/styles.ts +0 -118
  193. package/src/formats/xlsx/model/workbook.ts +0 -453
  194. package/src/formats/xlsx/runtime/cell-commands.ts +0 -567
  195. package/src/formats/xlsx/runtime/sheet-commands.ts +0 -206
  196. package/src/formats/xlsx/runtime/workbook-runtime.ts +0 -177
  197. package/src/formats/xlsx/runtime/workbook-transaction.ts +0 -822
  198. package/src/index.ts +0 -101
  199. package/src/io/README.md +0 -10
  200. package/src/io/docx-session.ts +0 -2882
  201. package/src/io/export/README.md +0 -3
  202. package/src/io/export/export-session.ts +0 -220
  203. package/src/io/export/minimal-docx.ts +0 -115
  204. package/src/io/export/reattach-preserved-parts.ts +0 -54
  205. package/src/io/export/serialize-comments.ts +0 -947
  206. package/src/io/export/serialize-footnotes.ts +0 -399
  207. package/src/io/export/serialize-headers-footers.ts +0 -372
  208. package/src/io/export/serialize-main-document.ts +0 -1376
  209. package/src/io/export/serialize-numbering.ts +0 -118
  210. package/src/io/export/serialize-revisions.ts +0 -389
  211. package/src/io/export/serialize-runtime-revisions.ts +0 -269
  212. package/src/io/export/serialize-tables.ts +0 -174
  213. package/src/io/export/split-review-boundaries.ts +0 -356
  214. package/src/io/normalize/README.md +0 -3
  215. package/src/io/normalize/normalize-text.ts +0 -639
  216. package/src/io/ooxml/README.md +0 -3
  217. package/src/io/ooxml/highlight-colors.ts +0 -39
  218. package/src/io/ooxml/numbering-sentinels.ts +0 -44
  219. package/src/io/ooxml/parse-comments.ts +0 -846
  220. package/src/io/ooxml/parse-complex-content.ts +0 -287
  221. package/src/io/ooxml/parse-fields.ts +0 -834
  222. package/src/io/ooxml/parse-footnotes.ts +0 -896
  223. package/src/io/ooxml/parse-headers-footers.ts +0 -1169
  224. package/src/io/ooxml/parse-inline-media.ts +0 -461
  225. package/src/io/ooxml/parse-main-document.ts +0 -2877
  226. package/src/io/ooxml/parse-numbering.ts +0 -432
  227. package/src/io/ooxml/parse-revisions.ts +0 -931
  228. package/src/io/ooxml/parse-settings.ts +0 -184
  229. package/src/io/ooxml/parse-shapes.ts +0 -296
  230. package/src/io/ooxml/parse-styles.ts +0 -463
  231. package/src/io/ooxml/parse-tables.ts +0 -618
  232. package/src/io/ooxml/parse-theme.ts +0 -346
  233. package/src/io/ooxml/part-manifest.ts +0 -136
  234. package/src/io/ooxml/revision-boundaries.ts +0 -351
  235. package/src/io/opc/README.md +0 -3
  236. package/src/io/opc/corrupt-package.ts +0 -166
  237. package/src/io/opc/docx-package.ts +0 -74
  238. package/src/io/opc/package-reader.ts +0 -325
  239. package/src/io/opc/package-writer.ts +0 -273
  240. package/src/io/source-package-provenance.ts +0 -241
  241. package/src/legal/cross-references.ts +0 -414
  242. package/src/legal/defined-terms.ts +0 -203
  243. package/src/legal/index.ts +0 -32
  244. package/src/legal/signature-blocks.ts +0 -259
  245. package/src/model/README.md +0 -3
  246. package/src/model/canonical-document.ts +0 -2632
  247. package/src/model/cds-1.0.0.ts +0 -212
  248. package/src/model/snapshot.ts +0 -649
  249. package/src/preservation/README.md +0 -3
  250. package/src/preservation/markup-compatibility.ts +0 -48
  251. package/src/preservation/opaque-fragment-store.ts +0 -89
  252. package/src/preservation/opaque-region.ts +0 -233
  253. package/src/preservation/package-preservation.ts +0 -113
  254. package/src/preservation/preserved-part-manifest.ts +0 -56
  255. package/src/preservation/relationship-retention.ts +0 -57
  256. package/src/preservation/store.ts +0 -185
  257. package/src/review/README.md +0 -16
  258. package/src/review/store/README.md +0 -3
  259. package/src/review/store/comment-anchors.ts +0 -70
  260. package/src/review/store/comment-remapping.ts +0 -154
  261. package/src/review/store/comment-store.ts +0 -331
  262. package/src/review/store/comment-thread.ts +0 -109
  263. package/src/review/store/revision-actions.ts +0 -394
  264. package/src/review/store/revision-store.ts +0 -312
  265. package/src/review/store/revision-types.ts +0 -171
  266. package/src/review/store/runtime-comment-store.ts +0 -43
  267. package/src/runtime/README.md +0 -3
  268. package/src/runtime/ai-action-policy.ts +0 -764
  269. package/src/runtime/collab-review-sync.ts +0 -254
  270. package/src/runtime/document-layout.ts +0 -332
  271. package/src/runtime/document-navigation.ts +0 -603
  272. package/src/runtime/document-runtime.ts +0 -3159
  273. package/src/runtime/document-search.ts +0 -145
  274. package/src/runtime/numbering-prefix.ts +0 -216
  275. package/src/runtime/page-layout-estimation.ts +0 -212
  276. package/src/runtime/read-only-diagnostics-runtime.ts +0 -241
  277. package/src/runtime/review-runtime.ts +0 -44
  278. package/src/runtime/revision-runtime.ts +0 -107
  279. package/src/runtime/session-capabilities.ts +0 -192
  280. package/src/runtime/story-context.ts +0 -164
  281. package/src/runtime/story-targeting.ts +0 -162
  282. package/src/runtime/surface-projection.ts +0 -1357
  283. package/src/runtime/table-commands.ts +0 -173
  284. package/src/runtime/table-schema.ts +0 -309
  285. package/src/runtime/view-state.ts +0 -477
  286. package/src/runtime/virtualized-rendering.ts +0 -258
  287. package/src/runtime/workflow-markup.ts +0 -353
  288. package/src/ui/README.md +0 -30
  289. package/src/ui/WordReviewEditor.tsx +0 -4097
  290. package/src/ui/browser-export.ts +0 -52
  291. package/src/ui/comments/README.md +0 -3
  292. package/src/ui/compatibility/README.md +0 -3
  293. package/src/ui/editor-command-bag.ts +0 -120
  294. package/src/ui/editor-runtime-boundary.ts +0 -1457
  295. package/src/ui/editor-shell-view.tsx +0 -142
  296. package/src/ui/editor-surface/README.md +0 -3
  297. package/src/ui/editor-surface-controller.tsx +0 -63
  298. package/src/ui/headless/comment-decoration-model.ts +0 -124
  299. package/src/ui/headless/preserve-editor-selection.ts +0 -5
  300. package/src/ui/headless/revision-decoration-model.ts +0 -128
  301. package/src/ui/headless/selection-helpers.ts +0 -54
  302. package/src/ui/headless/selection-toolbar-model.ts +0 -34
  303. package/src/ui/headless/use-editor-keyboard.ts +0 -103
  304. package/src/ui/review/README.md +0 -3
  305. package/src/ui/runtime-snapshot-selectors.ts +0 -197
  306. package/src/ui/shared/revision-filters.ts +0 -31
  307. package/src/ui/status/README.md +0 -3
  308. package/src/ui/theme/README.md +0 -3
  309. package/src/ui/toolbar/README.md +0 -3
  310. package/src/ui/workflow-surface-blocked-rails.ts +0 -94
  311. package/src/ui-tailwind/chrome/tw-alert-banner.tsx +0 -64
  312. package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +0 -129
  313. package/src/ui-tailwind/chrome/tw-layout-panel.tsx +0 -114
  314. package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +0 -34
  315. package/src/ui-tailwind/chrome/tw-page-ruler.tsx +0 -386
  316. package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +0 -186
  317. package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +0 -139
  318. package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +0 -128
  319. package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +0 -58
  320. package/src/ui-tailwind/chrome/use-before-unload.ts +0 -20
  321. package/src/ui-tailwind/editor-surface/perf-probe.ts +0 -179
  322. package/src/ui-tailwind/editor-surface/pm-collab-plugins.ts +0 -40
  323. package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +0 -178
  324. package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +0 -31
  325. package/src/ui-tailwind/editor-surface/pm-decorations.ts +0 -427
  326. package/src/ui-tailwind/editor-surface/pm-position-map.ts +0 -123
  327. package/src/ui-tailwind/editor-surface/pm-schema.ts +0 -876
  328. package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +0 -504
  329. package/src/ui-tailwind/editor-surface/search-plugin.ts +0 -168
  330. package/src/ui-tailwind/editor-surface/surface-build-keys.ts +0 -61
  331. package/src/ui-tailwind/editor-surface/tw-caret.tsx +0 -12
  332. package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +0 -150
  333. package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +0 -129
  334. package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +0 -58
  335. package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +0 -151
  336. package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +0 -973
  337. package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +0 -111
  338. package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +0 -436
  339. package/src/ui-tailwind/index.ts +0 -62
  340. package/src/ui-tailwind/page-chrome-model.ts +0 -27
  341. package/src/ui-tailwind/review/tw-comment-sidebar.tsx +0 -406
  342. package/src/ui-tailwind/review/tw-health-panel.tsx +0 -149
  343. package/src/ui-tailwind/review/tw-review-rail.tsx +0 -120
  344. package/src/ui-tailwind/review/tw-revision-sidebar.tsx +0 -164
  345. package/src/ui-tailwind/status/tw-status-bar.tsx +0 -61
  346. package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +0 -52
  347. package/src/ui-tailwind/toolbar/tw-toolbar.tsx +0 -1064
  348. package/src/ui-tailwind/tw-review-workspace.tsx +0 -1417
  349. package/src/validation/README.md +0 -3
  350. package/src/validation/compatibility-engine.ts +0 -634
  351. package/src/validation/compatibility-report.ts +0 -161
  352. package/src/validation/diagnostics.ts +0 -204
  353. package/src/validation/docx-comment-proof.ts +0 -707
  354. package/src/validation/import-diagnostics.ts +0 -128
  355. package/src/validation/low-priority-word-surfaces.ts +0 -373
  356. /package/{src → dist}/ui-tailwind/theme/editor-theme.css +0 -0
@@ -1,1357 +0,0 @@
1
- import type {
2
- EditorStoryTarget,
3
- EditorSurfaceSnapshot,
4
- SecondaryStorySurface,
5
- SurfaceBlockSnapshot,
6
- SurfaceInlineSegment,
7
- SurfaceTableCellSnapshot,
8
- SurfaceTableRowSnapshot,
9
- SurfaceTextMark,
10
- } from "../api/public-types";
11
- import type {
12
- CanonicalDocumentEnvelope,
13
- SelectionSnapshot,
14
- } from "../core/state/editor-state.ts";
15
- import type {
16
- BlockNode,
17
- ChartPreviewNode,
18
- DocumentRootNode,
19
- InlineNode,
20
- MediaCatalog,
21
- ParagraphNode,
22
- SdtNode,
23
- ShapeNode,
24
- SmartArtPreviewNode,
25
- TableCellBorders,
26
- TableNode,
27
- TextMark,
28
- VmlShapeNode,
29
- WordArtNode,
30
- } from "../model/canonical-document.ts";
31
- import {
32
- describeOpaqueFragment,
33
- getOpaqueFragment,
34
- } from "../preservation/store.ts";
35
- import { getStoryBlocks } from "./story-targeting.ts";
36
- import {
37
- createNumberingPrefixResolver,
38
- type NumberingPrefixResolver,
39
- } from "./numbering-prefix.ts";
40
- import {
41
- collectSectionContexts,
42
- findHeaderFooterDocumentEntry,
43
- resolveSectionVariants,
44
- } from "./story-context.ts";
45
-
46
- interface ParagraphAccumulator {
47
- blockId: string;
48
- kind: "paragraph";
49
- from: number;
50
- to: number;
51
- styleId?: string;
52
- numbering?: ParagraphNode["numbering"];
53
- numberingPrefix?: string;
54
- numberingSuffix?: "tab" | "space" | "nothing";
55
- contextualSpacing?: boolean;
56
- segments: SurfaceInlineSegment[];
57
- }
58
-
59
- export function createEditorSurfaceSnapshot(
60
- document: CanonicalDocumentEnvelope,
61
- _selection: SelectionSnapshot,
62
- activeStory: EditorStoryTarget = { kind: "main" },
63
- ): EditorSurfaceSnapshot {
64
- const root = normalizeDocumentRoot({
65
- type: "doc",
66
- children: [...getStoryBlocks(document, activeStory)],
67
- });
68
- const blocks: SurfaceBlockSnapshot[] = [];
69
- const lockedFragmentIds: string[] = [];
70
- const numberingPrefixResolver = createNumberingPrefixResolver(document.numbering);
71
- let cursor = 0;
72
- const counters = {
73
- paragraph: 0,
74
- table: 0,
75
- opaque: 0,
76
- sdt: 0,
77
- customXml: 0,
78
- altChunk: 0,
79
- };
80
-
81
- for (let index = 0; index < root.children.length; index += 1) {
82
- const surfaceBlock = createSurfaceBlock(
83
- root.children[index],
84
- document,
85
- cursor,
86
- counters,
87
- numberingPrefixResolver,
88
- );
89
- blocks.push(surfaceBlock.block);
90
- lockedFragmentIds.push(...surfaceBlock.lockedFragmentIds);
91
- cursor = surfaceBlock.nextCursor;
92
- if (index < root.children.length - 1 && root.children[index + 1]?.type === "paragraph") {
93
- cursor += 1;
94
- }
95
- }
96
-
97
- const secondaryStories = createSecondaryStorySurfaces(document);
98
-
99
- return {
100
- storySize: cursor,
101
- plainText: createPlainText(blocks),
102
- blocks,
103
- lockedFragmentIds,
104
- secondaryStories,
105
- };
106
- }
107
-
108
- function createSurfaceBlock(
109
- block: BlockNode,
110
- document: CanonicalDocumentEnvelope,
111
- cursor: number,
112
- counters: {
113
- paragraph: number;
114
- table: number;
115
- opaque: number;
116
- sdt: number;
117
- customXml: number;
118
- altChunk: number;
119
- },
120
- numberingPrefixResolver: NumberingPrefixResolver,
121
- ): { block: SurfaceBlockSnapshot; lockedFragmentIds: string[]; nextCursor: number } {
122
- if (block.type === "opaque_block") {
123
- const fragment = getOpaqueFragment(document.preservation as never, block.fragmentId);
124
- const descriptor = fragment ? describeOpaqueFragment(fragment) : null;
125
- const blockId = `opaque-${counters.opaque}`;
126
- counters.opaque += 1;
127
- return {
128
- block: {
129
- blockId,
130
- kind: "opaque_block",
131
- from: cursor,
132
- to: cursor + 1,
133
- fragmentId: block.fragmentId,
134
- warningId: block.warningId,
135
- label: descriptor?.label ?? "Unsupported OOXML fragment",
136
- detail:
137
- descriptor?.detail ??
138
- "Locked whole-unit to keep unsupported OOXML intact through export.",
139
- state: "locked-preserve-only",
140
- },
141
- lockedFragmentIds: [block.fragmentId],
142
- nextCursor: cursor + 1,
143
- };
144
- }
145
-
146
- if (block.type === "table") {
147
- const tableIndex = counters.table;
148
- counters.table += 1;
149
- return createTableBlock(
150
- tableIndex,
151
- block,
152
- document,
153
- cursor,
154
- counters,
155
- numberingPrefixResolver,
156
- );
157
- }
158
-
159
- if (block.type === "sdt") {
160
- const sdtIndex = counters.sdt;
161
- counters.sdt += 1;
162
- return createSdtBlock(
163
- sdtIndex,
164
- block,
165
- document,
166
- cursor,
167
- counters,
168
- numberingPrefixResolver,
169
- );
170
- }
171
-
172
- if (block.type === "custom_xml") {
173
- const blockId = `custom-xml-${counters.customXml}`;
174
- counters.customXml += 1;
175
- return {
176
- block: {
177
- blockId,
178
- kind: "opaque_block",
179
- from: cursor,
180
- to: cursor + 1,
181
- fragmentId: blockId,
182
- warningId: blockId,
183
- label: "Custom XML block",
184
- detail:
185
- block.uri || block.element
186
- ? `Custom XML wrapper ${[block.element, block.uri].filter(Boolean).join(" ")} preserved as a read-only block.`
187
- : "Custom XML wrapper preserved as a read-only block.",
188
- state: "locked-preserve-only",
189
- },
190
- lockedFragmentIds: [],
191
- nextCursor: cursor + 1,
192
- };
193
- }
194
-
195
- if (block.type === "alt_chunk") {
196
- const blockId = `alt-chunk-${counters.altChunk}`;
197
- counters.altChunk += 1;
198
- return {
199
- block: {
200
- blockId,
201
- kind: "opaque_block",
202
- from: cursor,
203
- to: cursor + 1,
204
- fragmentId: blockId,
205
- warningId: blockId,
206
- label: "AltChunk import",
207
- detail: `Alternate content import remains read-only through relationship ${block.relationshipId}.`,
208
- state: "locked-preserve-only",
209
- },
210
- lockedFragmentIds: [],
211
- nextCursor: cursor + 1,
212
- };
213
- }
214
-
215
- if (block.type === "section_break") {
216
- const blockId = `section-break-${counters.opaque}`;
217
- counters.opaque += 1;
218
- return {
219
- block: {
220
- blockId,
221
- kind: "opaque_block",
222
- from: cursor,
223
- to: cursor + 1,
224
- fragmentId: blockId,
225
- warningId: blockId,
226
- label: "Section break",
227
- detail: "Section properties preserved as a read-only boundary.",
228
- state: "locked-preserve-only",
229
- },
230
- lockedFragmentIds: [],
231
- nextCursor: cursor + 1,
232
- };
233
- }
234
-
235
- const paragraphIndex = counters.paragraph;
236
- counters.paragraph += 1;
237
- return createParagraphBlock(
238
- paragraphIndex,
239
- block,
240
- document,
241
- cursor,
242
- numberingPrefixResolver,
243
- );
244
- }
245
-
246
- function createTableBlock(
247
- tableIndex: number,
248
- table: TableNode,
249
- document: CanonicalDocumentEnvelope,
250
- cursor: number,
251
- counters: {
252
- paragraph: number;
253
- table: number;
254
- opaque: number;
255
- sdt: number;
256
- customXml: number;
257
- altChunk: number;
258
- },
259
- numberingPrefixResolver: NumberingPrefixResolver,
260
- ): { block: SurfaceBlockSnapshot; lockedFragmentIds: string[]; nextCursor: number } {
261
- const lockedFragmentIds: string[] = [];
262
- let innerCursor = cursor;
263
- const rows: SurfaceTableRowSnapshot[] = [];
264
- const rowSpans = computeTableRowSpans(table);
265
-
266
- for (const [rowIndex, row] of table.rows.entries()) {
267
- const cells: SurfaceTableCellSnapshot[] = [];
268
- for (const [cellIndex, cell] of row.cells.entries()) {
269
- const cellContent: SurfaceBlockSnapshot[] = [];
270
- for (const child of cell.children) {
271
- const result = createSurfaceBlock(
272
- child,
273
- document,
274
- innerCursor,
275
- counters,
276
- numberingPrefixResolver,
277
- );
278
- cellContent.push(result.block);
279
- lockedFragmentIds.push(...result.lockedFragmentIds);
280
- innerCursor = result.nextCursor;
281
- }
282
- const cellBorders = resolveCellBorderStyles(cell.borders);
283
- cells.push({
284
- gridSpan: cell.gridSpan ?? 1,
285
- verticalMerge: cell.verticalMerge ?? null,
286
- colspan: cell.gridSpan ?? 1,
287
- rowspan: rowSpans.get(`${rowIndex}:${cellIndex}`) ?? 1,
288
- ...(cell.shading?.fill ? { backgroundColor: `#${cell.shading.fill}` } : {}),
289
- ...(cell.verticalAlign ? { verticalAlign: cell.verticalAlign } : {}),
290
- ...(cellBorders.borderTop ? { borderTop: cellBorders.borderTop } : {}),
291
- ...(cellBorders.borderRight ? { borderRight: cellBorders.borderRight } : {}),
292
- ...(cellBorders.borderBottom ? { borderBottom: cellBorders.borderBottom } : {}),
293
- ...(cellBorders.borderLeft ? { borderLeft: cellBorders.borderLeft } : {}),
294
- content: cellContent,
295
- });
296
- }
297
- rows.push({
298
- cells,
299
- ...(row.gridBefore !== undefined ? { gridBefore: row.gridBefore } : {}),
300
- ...(row.gridAfter !== undefined ? { gridAfter: row.gridAfter } : {}),
301
- ...(row.height !== undefined ? { height: row.height } : {}),
302
- ...(row.heightRule ? { heightRule: row.heightRule } : {}),
303
- ...(row.isHeader ? { isHeader: row.isHeader } : {}),
304
- });
305
- }
306
-
307
- return {
308
- block: {
309
- blockId: `table-${tableIndex}`,
310
- kind: "table",
311
- from: cursor,
312
- to: innerCursor,
313
- styleId: table.styleId,
314
- gridColumns: table.gridColumns,
315
- ...(table.alignment ? { alignment: table.alignment } : {}),
316
- ...(table.tblLook ? { tblLook: table.tblLook } : {}),
317
- rows,
318
- },
319
- lockedFragmentIds,
320
- nextCursor: innerCursor,
321
- };
322
- }
323
-
324
- function computeTableRowSpans(table: TableNode): Map<string, number> {
325
- const positionedRows = table.rows.map((row) => {
326
- let startColumn = 0;
327
-
328
- return row.cells.map((cell, cellIndex) => {
329
- const width = cell.gridSpan ?? 1;
330
- const positionedCell = {
331
- cell,
332
- cellIndex,
333
- startColumn,
334
- endColumn: startColumn + width - 1,
335
- };
336
- startColumn += width;
337
- return positionedCell;
338
- });
339
- });
340
-
341
- const rowSpans = new Map<string, number>();
342
-
343
- for (const [rowIndex, row] of positionedRows.entries()) {
344
- for (const positionedCell of row) {
345
- if (positionedCell.cell.verticalMerge !== "restart") {
346
- rowSpans.set(`${rowIndex}:${positionedCell.cellIndex}`, 1);
347
- continue;
348
- }
349
-
350
- let rowspan = 1;
351
- for (let nextRowIndex = rowIndex + 1; nextRowIndex < positionedRows.length; nextRowIndex += 1) {
352
- const continuedCell = positionedRows[nextRowIndex]?.find(
353
- (candidate) =>
354
- candidate.cell.verticalMerge === "continue" &&
355
- candidate.startColumn === positionedCell.startColumn &&
356
- candidate.endColumn === positionedCell.endColumn,
357
- );
358
-
359
- if (!continuedCell) {
360
- break;
361
- }
362
-
363
- rowspan += 1;
364
- }
365
-
366
- rowSpans.set(`${rowIndex}:${positionedCell.cellIndex}`, rowspan);
367
- }
368
- }
369
-
370
- return rowSpans;
371
- }
372
-
373
- function resolveCellBorderStyles(
374
- borders: TableCellBorders | undefined,
375
- ): { borderTop?: string; borderRight?: string; borderBottom?: string; borderLeft?: string } {
376
- if (!borders) return {};
377
- const result: { borderTop?: string; borderRight?: string; borderBottom?: string; borderLeft?: string } = {};
378
- const sides = [["top", "borderTop"], ["right", "borderRight"], ["bottom", "borderBottom"], ["left", "borderLeft"]] as const;
379
- for (const [side, key] of sides) {
380
- const spec = borders[side];
381
- if (!spec || spec.value === "none" || spec.value === "nil") continue;
382
- const width = spec.size ? `${Math.max(1, Math.round(spec.size / 8))}px` : "1px";
383
- const style = spec.value === "double" ? "double" : spec.value === "dashed" || spec.value === "dashSmallGap" ? "dashed" : spec.value === "dotted" ? "dotted" : "solid";
384
- const color = spec.color && spec.color !== "auto" ? `#${spec.color}` : "currentColor";
385
- result[key] = `${width} ${style} ${color}`;
386
- }
387
- return result;
388
- }
389
-
390
- function createSdtBlock(
391
- sdtIndex: number,
392
- block: SdtNode,
393
- document: CanonicalDocumentEnvelope,
394
- cursor: number,
395
- counters: {
396
- paragraph: number;
397
- table: number;
398
- opaque: number;
399
- sdt: number;
400
- customXml: number;
401
- altChunk: number;
402
- },
403
- numberingPrefixResolver: NumberingPrefixResolver,
404
- ): { block: SurfaceBlockSnapshot; lockedFragmentIds: string[]; nextCursor: number } {
405
- const children: SurfaceBlockSnapshot[] = [];
406
- const lockedFragmentIds: string[] = [];
407
- let innerCursor = cursor;
408
-
409
- for (const child of block.children) {
410
- const result = createSurfaceBlock(
411
- child,
412
- document,
413
- innerCursor,
414
- counters,
415
- numberingPrefixResolver,
416
- );
417
- children.push(result.block);
418
- lockedFragmentIds.push(...result.lockedFragmentIds);
419
- innerCursor = result.nextCursor;
420
- }
421
-
422
- return {
423
- block: {
424
- blockId: `sdt-${sdtIndex}`,
425
- kind: "sdt_block",
426
- from: cursor,
427
- to: innerCursor,
428
- ...(block.properties.sdtType ? { sdtType: block.properties.sdtType } : {}),
429
- ...(block.properties.alias ? { alias: block.properties.alias } : {}),
430
- ...(block.properties.tag ? { tag: block.properties.tag } : {}),
431
- ...(block.properties.lock ? { lock: block.properties.lock } : {}),
432
- ...(block.properties.checkbox ? { checkboxChecked: block.properties.checkbox.checked } : {}),
433
- ...(block.properties.datePicker?.fullDate ? { dateValue: block.properties.datePicker.fullDate } : {}),
434
- ...(block.properties.dropdownList ? { dropdownItems: block.properties.dropdownList } : {}),
435
- ...(block.properties.comboBox ? { comboBoxItems: block.properties.comboBox } : {}),
436
- ...(block.properties.showingPlcHdr ? { showingPlcHdr: true } : {}),
437
- children,
438
- },
439
- lockedFragmentIds,
440
- nextCursor: innerCursor,
441
- };
442
- }
443
-
444
- function createParagraphBlock(
445
- paragraphIndex: number,
446
- paragraph: ParagraphNode,
447
- document: CanonicalDocumentEnvelope,
448
- start: number,
449
- numberingPrefixResolver: NumberingPrefixResolver,
450
- ): {
451
- block: SurfaceBlockSnapshot;
452
- nextCursor: number;
453
- lockedFragmentIds: string[];
454
- } {
455
- const accumulator: ParagraphAccumulator = {
456
- blockId: `paragraph-${paragraphIndex}`,
457
- kind: "paragraph",
458
- from: start,
459
- to: start,
460
- ...(paragraph.styleId ? { styleId: paragraph.styleId } : {}),
461
- ...(paragraph.numbering ? { numbering: paragraph.numbering } : {}),
462
- ...(paragraph.numbering
463
- ? (() => {
464
- const detailed = numberingPrefixResolver.resolveDetailed(paragraph.numbering);
465
- return detailed
466
- ? {
467
- numberingPrefix: detailed.text,
468
- ...(detailed.suffix ? { numberingSuffix: detailed.suffix } : {}),
469
- }
470
- : {};
471
- })()
472
- : {}),
473
- ...(paragraph.alignment ? { alignment: paragraph.alignment } : {}),
474
- ...(paragraph.spacing ? { spacing: paragraph.spacing } : {}),
475
- ...(paragraph.contextualSpacing !== undefined
476
- ? { contextualSpacing: paragraph.contextualSpacing }
477
- : {}),
478
- ...(paragraph.indentation ? { indentation: paragraph.indentation } : {}),
479
- ...(paragraph.borders ? { borders: paragraph.borders } : {}),
480
- ...(paragraph.shading ? { shading: paragraph.shading } : {}),
481
- ...(paragraph.tabStops && paragraph.tabStops.length > 0
482
- ? { tabStops: paragraph.tabStops.map((tabStop) => toSurfaceTabStop(tabStop)) }
483
- : {}),
484
- ...(paragraph.keepNext ? { keepNext: true } : {}),
485
- ...(paragraph.keepLines ? { keepLines: true } : {}),
486
- ...(paragraph.pageBreakBefore ? { pageBreakBefore: true } : {}),
487
- ...(paragraph.outlineLevel !== undefined ? { outlineLevel: paragraph.outlineLevel } : {}),
488
- ...(paragraph.bidi ? { bidi: true } : {}),
489
- ...(paragraph.suppressLineNumbers ? { suppressLineNumbers: true } : {}),
490
- segments: [],
491
- };
492
- const lockedFragmentIds: string[] = [];
493
- let cursor = start;
494
- const children = Array.isArray(paragraph.children) ? paragraph.children : [];
495
-
496
- for (const child of children) {
497
- const result = appendInlineSegments(accumulator, child, document, cursor);
498
- cursor = result.nextCursor;
499
- lockedFragmentIds.push(...result.lockedFragmentIds);
500
- }
501
-
502
- accumulator.to = cursor;
503
- return {
504
- block: accumulator,
505
- nextCursor: cursor,
506
- lockedFragmentIds,
507
- };
508
- }
509
-
510
- function appendInlineSegments(
511
- paragraph: ParagraphAccumulator,
512
- node: InlineNode,
513
- document: CanonicalDocumentEnvelope,
514
- start: number,
515
- hyperlinkHref?: string,
516
- ): { nextCursor: number; lockedFragmentIds: string[] } {
517
- switch (node.type) {
518
- case "text":
519
- paragraph.segments.push({
520
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
521
- kind: "text",
522
- from: start,
523
- to: start + Array.from(node.text).length,
524
- text: node.text,
525
- ...(node.marks ? (() => {
526
- const result = cloneMarks(node.marks);
527
- return {
528
- ...(result.marks.length > 0 ? { marks: result.marks } : {}),
529
- ...(result.markAttrs ? { markAttrs: result.markAttrs } : {}),
530
- };
531
- })() : {}),
532
- ...(hyperlinkHref ? { hyperlinkHref } : {}),
533
- });
534
- return { nextCursor: start + Array.from(node.text).length, lockedFragmentIds: [] };
535
- case "tab":
536
- paragraph.segments.push({
537
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
538
- kind: "tab",
539
- from: start,
540
- to: start + 1,
541
- ...(hyperlinkHref ? { hyperlinkHref } : {}),
542
- });
543
- return { nextCursor: start + 1, lockedFragmentIds: [] };
544
- case "hard_break":
545
- paragraph.segments.push({
546
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
547
- kind: "hard_break",
548
- from: start,
549
- to: start + 1,
550
- ...(hyperlinkHref ? { hyperlinkHref } : {}),
551
- });
552
- return { nextCursor: start + 1, lockedFragmentIds: [] };
553
- case "hyperlink": {
554
- let cursor = start;
555
- for (const child of node.children) {
556
- const result = appendInlineSegments(paragraph, child, document, cursor, node.href);
557
- cursor = result.nextCursor;
558
- }
559
- return { nextCursor: cursor, lockedFragmentIds: [] };
560
- }
561
- case "image":
562
- paragraph.segments.push({
563
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
564
- kind: "image",
565
- from: start,
566
- to: start + 1,
567
- mediaId: node.mediaId,
568
- altText: node.altText,
569
- state: hasMediaItem(document.media, node.mediaId) ? "editable" : "missing",
570
- ...(node.display ? { display: node.display } : {}),
571
- detail:
572
- node.display === "floating"
573
- ? createFloatingImageDetail(node.altText, node.floating)
574
- : node.altText
575
- ? `Alt text ${node.altText}.`
576
- : "Inline image remains a whole-unit render surface.",
577
- });
578
- return { nextCursor: start + 1, lockedFragmentIds: [] };
579
- case "opaque_inline": {
580
- const fragment = getOpaqueFragment(document.preservation as never, node.fragmentId);
581
- const descriptor = fragment ? describeOpaqueFragment(fragment) : null;
582
- const preview = fragment ? describePreservedInlinePreview(fragment.payloadReference) : null;
583
- paragraph.segments.push({
584
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
585
- kind: "opaque_inline",
586
- from: start,
587
- to: start + 1,
588
- fragmentId: node.fragmentId,
589
- warningId: node.warningId,
590
- label: preview?.label ?? descriptor?.label ?? "Unsupported inline OOXML",
591
- detail:
592
- preview?.detail ??
593
- descriptor?.detail ??
594
- "Locked whole-unit to keep unsupported inline OOXML intact through export.",
595
- ...(preview?.presentation ? { presentation: preview.presentation } : {}),
596
- state: "locked-preserve-only",
597
- });
598
- return { nextCursor: start + 1, lockedFragmentIds: [node.fragmentId] };
599
- }
600
- case "chart_preview":
601
- return appendComplexPreviewSegment(paragraph, node, start, "Embedded chart", createChartDetail(node));
602
- case "smartart_preview":
603
- return appendComplexPreviewSegment(paragraph, node, start, "SmartArt diagram", createSmartArtDetail(node));
604
- case "shape":
605
- return appendComplexPreviewSegment(paragraph, node, start,
606
- node.isTextBox ? "Text box" : "Drawing shape", createShapeDetail(node));
607
- case "wordart":
608
- return appendComplexPreviewSegment(paragraph, node, start, "WordArt", createWordArtDetail(node));
609
- case "vml_shape":
610
- return appendComplexPreviewSegment(paragraph, node, start, "Legacy VML drawing", createVmlDetail(node));
611
- case "symbol":
612
- paragraph.segments.push({
613
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
614
- kind: "text",
615
- from: start,
616
- to: start + 1,
617
- text: node.char ? String.fromCodePoint(parseInt(node.char, 16)) : "\uFFFD",
618
- });
619
- return { nextCursor: start + 1, lockedFragmentIds: [] };
620
- case "column_break":
621
- paragraph.segments.push({
622
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
623
- kind: "opaque_inline",
624
- from: start,
625
- to: start + 1,
626
- fragmentId: "",
627
- warningId: "",
628
- label: "Column break",
629
- detail: "Column break marker preserved for export.",
630
- state: "locked-preserve-only",
631
- });
632
- return { nextCursor: start + 1, lockedFragmentIds: [] };
633
- case "footnote_ref":
634
- paragraph.segments.push({
635
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
636
- kind: "note_ref",
637
- from: start,
638
- to: start + 1,
639
- noteKind: node.noteKind ?? "footnote",
640
- noteId: node.noteId ?? "",
641
- label: node.noteId ?? "*",
642
- });
643
- return { nextCursor: start + 1, lockedFragmentIds: [] };
644
- case "field": {
645
- const isSupportedField =
646
- node.fieldFamily === "REF" ||
647
- node.fieldFamily === "PAGEREF" ||
648
- node.fieldFamily === "NOTEREF" ||
649
- node.fieldFamily === "TOC";
650
- if (node.children && node.children.length > 0) {
651
- let cursor = start;
652
- const lockedIds: string[] = [];
653
- for (const child of node.children) {
654
- const result = appendInlineSegments(paragraph, child, document, cursor);
655
- cursor = result.nextCursor;
656
- lockedIds.push(...result.lockedFragmentIds);
657
- }
658
- return { nextCursor: cursor, lockedFragmentIds: lockedIds };
659
- }
660
- if (isSupportedField) {
661
- // Supported field with no resolved content — show as field chip
662
- const fieldLabel =
663
- node.fieldFamily === "TOC"
664
- ? "Table of Contents"
665
- : `${node.fieldFamily ?? "Field"}: ${node.fieldTarget ?? node.instruction.trim()}`;
666
- paragraph.segments.push({
667
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
668
- kind: "field_ref",
669
- from: start,
670
- to: start + 1,
671
- fieldFamily: node.fieldFamily!,
672
- fieldTarget: node.fieldTarget,
673
- instruction: node.instruction,
674
- refreshStatus: node.refreshStatus ?? "stale",
675
- label: fieldLabel,
676
- } as SurfaceInlineSegment);
677
- return { nextCursor: start + 1, lockedFragmentIds: [] };
678
- }
679
- paragraph.segments.push({
680
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
681
- kind: "opaque_inline",
682
- from: start,
683
- to: start + 1,
684
- fragmentId: "",
685
- warningId: "",
686
- label: "Field",
687
- detail: `Preserve-only field: ${node.instruction.trim()}`,
688
- state: "locked-preserve-only",
689
- });
690
- return { nextCursor: start + 1, lockedFragmentIds: [] };
691
- }
692
- case "bookmark_start":
693
- case "bookmark_end":
694
- // Zero-width markers — no visual, no cursor advancement
695
- return { nextCursor: start, lockedFragmentIds: [] };
696
- default:
697
- return { nextCursor: start + 1, lockedFragmentIds: [] };
698
- }
699
- }
700
-
701
- function appendComplexPreviewSegment(
702
- paragraph: ParagraphAccumulator,
703
- node: { rawXml: string },
704
- start: number,
705
- label: string,
706
- detail: string,
707
- ): { nextCursor: number; lockedFragmentIds: string[] } {
708
- paragraph.segments.push({
709
- segmentId: `${paragraph.blockId}-segment-${paragraph.segments.length}`,
710
- kind: "opaque_inline",
711
- from: start,
712
- to: start + 1,
713
- fragmentId: `complex:${label.replace(/\s/g, "-").toLowerCase()}:${start}`,
714
- warningId: `warning:complex-preview:${start}`,
715
- label,
716
- detail,
717
- state: "locked-preserve-only",
718
- });
719
- return { nextCursor: start + 1, lockedFragmentIds: [] };
720
- }
721
-
722
- function createChartDetail(node: ChartPreviewNode): string {
723
- const parts = ["Embedded chart."];
724
- if (node.previewMediaId) {
725
- parts.push(`Preview available via fallback image (${node.previewMediaId}).`);
726
- } else {
727
- parts.push("No fallback preview image found; chart data preserved in package.");
728
- }
729
- parts.push("Edit in Word to modify chart data. Original DrawingML preserved for lossless export.");
730
- return parts.join(" ");
731
- }
732
-
733
- function createSmartArtDetail(node: SmartArtPreviewNode): string {
734
- const parts = ["SmartArt diagram."];
735
- if (node.previewMediaId) {
736
- parts.push(`Preview available via fallback image (${node.previewMediaId}).`);
737
- } else {
738
- parts.push("No fallback preview image found; diagram structure preserved in package.");
739
- }
740
- parts.push("Edit in Word to modify diagram layout and content. Original DrawingML preserved for lossless export.");
741
- return parts.join(" ");
742
- }
743
-
744
- function createShapeDetail(node: ShapeNode): string {
745
- if (node.isTextBox) {
746
- const parts = ["Text box."];
747
- if (node.text) parts.push(`Content: "${node.text}".`);
748
- parts.push("Text content is visible; formatting and geometry preserved for export.");
749
- return parts.join(" ");
750
- }
751
- const parts = ["Drawing shape."];
752
- if (node.geometry) parts.push(`Geometry: ${node.geometry}.`);
753
- if (node.text) parts.push(`Text content: "${node.text}".`);
754
- parts.push("Visual geometry is preview-only. Original DrawingML preserved for export.");
755
- return parts.join(" ");
756
- }
757
-
758
- function createWordArtDetail(node: WordArtNode): string {
759
- const parts = ["WordArt decorative text."];
760
- if (node.text) parts.push(`Text: "${node.text}".`);
761
- if (node.geometry) parts.push(`Effect: ${node.geometry}.`);
762
- parts.push("Text effect is preview-only. Edit in Word for full formatting. Original DrawingML preserved for export.");
763
- return parts.join(" ");
764
- }
765
-
766
- function createVmlDetail(node: VmlShapeNode): string {
767
- const parts = ["Legacy VML drawing."];
768
- if (node.shapeType) parts.push(`Type: ${node.shapeType}.`);
769
- if (node.text) parts.push(`Text content: "${node.text}".`);
770
- parts.push("VML content is preview-only. Edit in Word for full control. Original VML XML preserved for export.");
771
- return parts.join(" ");
772
- }
773
-
774
- function createPlainText(
775
- blocks: SurfaceBlockSnapshot[],
776
- ): string {
777
- const text: string[] = [];
778
- for (const block of blocks) {
779
- if (block.kind === "opaque_block") {
780
- if (block.fragmentId.startsWith("preview:")) {
781
- continue;
782
- }
783
- text.push("\uFFFA");
784
- continue;
785
- }
786
-
787
- if (block.kind === "table") {
788
- for (const row of block.rows) {
789
- for (const cell of row.cells) {
790
- text.push(createPlainText(cell.content));
791
- }
792
- }
793
- continue;
794
- }
795
-
796
- if (block.kind === "sdt_block") {
797
- text.push(createPlainText(block.children));
798
- continue;
799
- }
800
-
801
- for (const segment of block.segments) {
802
- switch (segment.kind) {
803
- case "text":
804
- text.push(segment.text);
805
- break;
806
- case "tab":
807
- text.push("\t");
808
- break;
809
- case "hard_break":
810
- text.push("\n");
811
- break;
812
- case "image":
813
- text.push("\uFFFC");
814
- break;
815
- case "opaque_inline":
816
- text.push("\uFFF9");
817
- break;
818
- }
819
- }
820
- }
821
-
822
- return text.join("");
823
- }
824
-
825
- function createSecondaryStorySurfaces(
826
- document: CanonicalDocumentEnvelope,
827
- ): SecondaryStorySurface[] {
828
- const surfaces: SecondaryStorySurface[] = [];
829
- const subParts = document.subParts;
830
- if (!subParts) {
831
- return surfaces;
832
- }
833
-
834
- const numberingPrefixResolver = createNumberingPrefixResolver(document.numbering);
835
-
836
- for (const section of collectSectionContexts(document)) {
837
- const headerVariants = resolveSectionVariants(
838
- "header",
839
- section.index,
840
- section.properties?.headerReferences,
841
- subParts.headers ?? [],
842
- );
843
- for (const headerVariant of headerVariants) {
844
- const target: EditorStoryTarget = {
845
- kind: "header",
846
- relationshipId: headerVariant.relationshipId,
847
- variant: headerVariant.variant,
848
- sectionIndex: section.index,
849
- };
850
- const header = findHeaderFooterDocumentEntry(document, target);
851
- if (!header) {
852
- continue;
853
- }
854
- surfaces.push(
855
- createStorySurface(
856
- target,
857
- `Header · ${headerVariant.variant}`,
858
- header.blocks,
859
- document,
860
- numberingPrefixResolver,
861
- ),
862
- );
863
- }
864
-
865
- const footerVariants = resolveSectionVariants(
866
- "footer",
867
- section.index,
868
- section.properties?.footerReferences,
869
- subParts.footers ?? [],
870
- );
871
- for (const footerVariant of footerVariants) {
872
- const target: EditorStoryTarget = {
873
- kind: "footer",
874
- relationshipId: footerVariant.relationshipId,
875
- variant: footerVariant.variant,
876
- sectionIndex: section.index,
877
- };
878
- const footer = findHeaderFooterDocumentEntry(document, target);
879
- if (!footer) {
880
- continue;
881
- }
882
- surfaces.push(
883
- createStorySurface(
884
- target,
885
- `Footer · ${footerVariant.variant}`,
886
- footer.blocks,
887
- document,
888
- numberingPrefixResolver,
889
- ),
890
- );
891
- }
892
- }
893
-
894
- const footnotes = Object.values(subParts.footnoteCollection?.footnotes ?? {}).sort(compareNoteIds);
895
- for (const note of footnotes) {
896
- const target: EditorStoryTarget = { kind: "footnote", noteId: note.noteId };
897
- surfaces.push(createStorySurface(target, `Footnote ${note.noteId}`, note.blocks, document, numberingPrefixResolver));
898
- }
899
-
900
- const endnotes = Object.values(subParts.footnoteCollection?.endnotes ?? {}).sort(compareNoteIds);
901
- for (const note of endnotes) {
902
- const target: EditorStoryTarget = { kind: "endnote", noteId: note.noteId };
903
- surfaces.push(createStorySurface(target, `Endnote ${note.noteId}`, note.blocks, document, numberingPrefixResolver));
904
- }
905
-
906
- return surfaces;
907
- }
908
-
909
- function createStorySurface(
910
- target: EditorStoryTarget,
911
- label: string,
912
- blocks: readonly BlockNode[],
913
- document: CanonicalDocumentEnvelope,
914
- numberingPrefixResolver: NumberingPrefixResolver,
915
- ): SecondaryStorySurface {
916
- const surfaceBlocks: SurfaceBlockSnapshot[] = [];
917
- let cursor = 0;
918
- const counters = {
919
- paragraph: 0,
920
- table: 0,
921
- opaque: 0,
922
- sdt: 0,
923
- customXml: 0,
924
- altChunk: 0,
925
- };
926
-
927
- for (let index = 0; index < blocks.length; index += 1) {
928
- const surfaceBlock = createSurfaceBlock(
929
- blocks[index],
930
- document,
931
- cursor,
932
- counters,
933
- numberingPrefixResolver,
934
- );
935
- surfaceBlocks.push(surfaceBlock.block);
936
- cursor = surfaceBlock.nextCursor;
937
- if (index < blocks.length - 1 && blocks[index + 1]?.type === "paragraph") {
938
- cursor += 1;
939
- }
940
- }
941
-
942
- return {
943
- target,
944
- label,
945
- storySize: cursor,
946
- blocks: surfaceBlocks,
947
- };
948
- }
949
-
950
- function createSecondaryStoryPreviewBlocks(
951
- document: CanonicalDocumentEnvelope,
952
- cursor: number,
953
- ): SurfaceBlockSnapshot[] {
954
- const previews: SurfaceBlockSnapshot[] = [];
955
- const subParts = document.subParts;
956
- if (!subParts) {
957
- return previews;
958
- }
959
-
960
- for (const header of subParts.headers ?? []) {
961
- previews.push(
962
- createSecondaryStoryPreviewBlock(
963
- `Header · ${header.variant}`,
964
- `header:${header.relationshipId}`,
965
- cursor,
966
- createSecondaryStoryPreviewDetail(header.partPath, header.blocks),
967
- ),
968
- );
969
- }
970
-
971
- for (const footer of subParts.footers ?? []) {
972
- previews.push(
973
- createSecondaryStoryPreviewBlock(
974
- `Footer · ${footer.variant}`,
975
- `footer:${footer.relationshipId}`,
976
- cursor,
977
- createSecondaryStoryPreviewDetail(footer.partPath, footer.blocks),
978
- ),
979
- );
980
- }
981
-
982
- const footnotes = Object.values(subParts.footnoteCollection?.footnotes ?? {}).sort(compareNoteIds);
983
- for (const note of footnotes) {
984
- previews.push(
985
- createSecondaryStoryPreviewBlock(
986
- `Footnote ${note.noteId}`,
987
- `footnote:${note.noteId}`,
988
- cursor,
989
- createSecondaryStoryPreviewDetail(`/word/footnotes.xml#${note.noteId}`, note.blocks),
990
- ),
991
- );
992
- }
993
-
994
- const endnotes = Object.values(subParts.footnoteCollection?.endnotes ?? {}).sort(compareNoteIds);
995
- for (const note of endnotes) {
996
- previews.push(
997
- createSecondaryStoryPreviewBlock(
998
- `Endnote ${note.noteId}`,
999
- `endnote:${note.noteId}`,
1000
- cursor,
1001
- createSecondaryStoryPreviewDetail(`/word/endnotes.xml#${note.noteId}`, note.blocks),
1002
- ),
1003
- );
1004
- }
1005
-
1006
- return previews;
1007
- }
1008
-
1009
- function createSecondaryStoryPreviewBlock(
1010
- label: string,
1011
- previewId: string,
1012
- cursor: number,
1013
- detail: string,
1014
- ): Extract<SurfaceBlockSnapshot, { kind: "opaque_block" }> {
1015
- return {
1016
- blockId: `secondary-story-${previewId.replace(/[^a-z0-9._:-]+/gi, "-")}`,
1017
- kind: "opaque_block",
1018
- from: cursor,
1019
- to: cursor,
1020
- fragmentId: `preview:${previewId}`,
1021
- warningId: `preview:${previewId}`,
1022
- label,
1023
- detail,
1024
- state: "locked-preserve-only",
1025
- };
1026
- }
1027
-
1028
- function createSecondaryStoryPreviewDetail(
1029
- sourceLabel: string,
1030
- blocks: readonly BlockNode[],
1031
- ): string {
1032
- const previewLines = blocks
1033
- .map((block) => summarizePreviewBlock(block))
1034
- .filter((line) => line.trim().length > 0);
1035
- const previewText = previewLines.length > 0 ? previewLines.join("\n\n") : "Empty story.";
1036
- return `Read-only preview from ${sourceLabel}.\n${previewText}`;
1037
- }
1038
-
1039
- function summarizePreviewBlock(block: BlockNode): string {
1040
- switch (block.type) {
1041
- case "paragraph": {
1042
- const text = block.children.map((child) => summarizePreviewInline(child)).join("");
1043
- return text.trim().length > 0 ? text : "¶";
1044
- }
1045
- case "table":
1046
- return "[Table preserved in secondary story]";
1047
- case "opaque_block":
1048
- return "[Locked block preserved for export]";
1049
- case "sdt":
1050
- return "[Content control preview]";
1051
- case "custom_xml":
1052
- return "[Custom XML preview]";
1053
- case "alt_chunk":
1054
- return "[AltChunk preview]";
1055
- case "section_break":
1056
- return "[Section boundary]";
1057
- }
1058
- }
1059
-
1060
- function summarizePreviewInline(node: InlineNode): string {
1061
- switch (node.type) {
1062
- case "text":
1063
- return node.text;
1064
- case "tab":
1065
- return "\t";
1066
- case "hard_break":
1067
- return "\n";
1068
- case "hyperlink":
1069
- return node.children.map((child) => summarizePreviewInline(child)).join("");
1070
- case "footnote_ref":
1071
- return node.noteKind === "footnote" ? `[fn ${node.noteId}]` : `[en ${node.noteId}]`;
1072
- case "field": {
1073
- const instruction = node.instruction.trim();
1074
- return instruction.length > 0 ? `[Field: ${instruction}]` : "[Field]";
1075
- }
1076
- case "bookmark_start":
1077
- return node.name ? `[Bookmark: ${node.name}]` : "[Bookmark]";
1078
- case "bookmark_end":
1079
- return "";
1080
- case "image":
1081
- return node.altText ? `[Image: ${node.altText}]` : "[Image]";
1082
- case "opaque_inline":
1083
- return "[Locked inline content]";
1084
- case "symbol":
1085
- return node.char ? String.fromCodePoint(parseInt(node.char, 16)) : "\uFFFD";
1086
- case "column_break":
1087
- return "[Column break]";
1088
- case "chart_preview":
1089
- return "[Embedded chart]";
1090
- case "smartart_preview":
1091
- return "[SmartArt diagram]";
1092
- case "shape":
1093
- if (node.isTextBox && node.text) return `[Text box: ${node.text}]`;
1094
- return node.text ? `[Shape: ${node.text}]` : "[Drawing shape]";
1095
- case "wordart":
1096
- return node.text ? `[WordArt: ${node.text}]` : "[WordArt]";
1097
- case "vml_shape":
1098
- return node.text ? `[VML: ${node.text}]` : "[Legacy VML drawing]";
1099
- }
1100
- }
1101
-
1102
- function compareNoteIds(
1103
- left: { noteId: string },
1104
- right: { noteId: string },
1105
- ): number {
1106
- return Number.parseInt(left.noteId, 10) - Number.parseInt(right.noteId, 10);
1107
- }
1108
-
1109
- function toSurfaceTabStop(
1110
- tabStop: NonNullable<ParagraphNode["tabStops"]>[number],
1111
- ): { pos: number; val?: string; leader?: string } {
1112
- return {
1113
- pos: tabStop.position,
1114
- ...(tabStop.align ? { val: tabStop.align } : {}),
1115
- ...(tabStop.leader ? { leader: tabStop.leader } : {}),
1116
- };
1117
- }
1118
-
1119
- function describePreservedInlinePreview(
1120
- payloadReference: string,
1121
- ): {
1122
- label: string;
1123
- detail: string;
1124
- presentation?: "inline-chip" | "quiet-marker";
1125
- } | null {
1126
- if (/\b(?:w:)?proofErr\b/u.test(payloadReference)) {
1127
- const proofType = /\bw:type="([^"]+)"/u.exec(payloadReference)?.[1];
1128
- return {
1129
- label: "Proofing marker",
1130
- detail:
1131
- proofType && proofType.trim().length > 0
1132
- ? `Word proofing marker (${proofType}) preserved for export safety.`
1133
- : "Word proofing marker preserved for export safety.",
1134
- presentation: "quiet-marker",
1135
- };
1136
- }
1137
-
1138
- if (/\b(?:w:)?lastRenderedPageBreak\b/u.test(payloadReference)) {
1139
- return {
1140
- label: "Rendered page break",
1141
- detail: "Word rendered page-break marker preserved for export safety.",
1142
- presentation: "quiet-marker",
1143
- };
1144
- }
1145
-
1146
- if (/\b(?:w:)?permStart\b/u.test(payloadReference)) {
1147
- const editorGroup = /\bw:edGrp="([^"]+)"/u.exec(payloadReference)?.[1];
1148
- return {
1149
- label: "Protected range start",
1150
- detail:
1151
- editorGroup && editorGroup.trim().length > 0
1152
- ? `Protected range start for ${editorGroup} preserved for export safety.`
1153
- : "Protected range start preserved for export safety.",
1154
- presentation: "quiet-marker",
1155
- };
1156
- }
1157
-
1158
- if (/\b(?:w:)?permEnd\b/u.test(payloadReference)) {
1159
- return {
1160
- label: "Protected range end",
1161
- detail: "Protected range end preserved for export safety.",
1162
- presentation: "quiet-marker",
1163
- };
1164
- }
1165
-
1166
- if (/\b(?:w:)?bookmarkStart\b/u.test(payloadReference)) {
1167
- const name = /\bw:name="([^"]+)"/u.exec(payloadReference)?.[1];
1168
- return {
1169
- label: name ? `Bookmark · ${name}` : "Bookmark",
1170
- detail: name
1171
- ? `Bookmark anchor \"${name}\" is preserved as a read-only inline token for export safety.`
1172
- : "Bookmark anchor is preserved as a read-only inline token for export safety.",
1173
- };
1174
- }
1175
-
1176
- if (/\b(?:w:)?bookmarkEnd\b/u.test(payloadReference)) {
1177
- return {
1178
- label: "Bookmark end",
1179
- detail: "Bookmark end marker is preserved as a read-only inline token for export safety.",
1180
- };
1181
- }
1182
-
1183
- if (/\b(?:w:)?fldSimple\b|\b(?:w:)?fldChar\b|\b(?:w:)?instrText\b/u.test(payloadReference)) {
1184
- const simpleInstruction = /\bw:instr="([^"]*)"/u.exec(payloadReference)?.[1];
1185
- const complexInstruction = [...payloadReference.matchAll(/<(?:\w+:)?instrText\b[^>]*>([\s\S]*?)<\/(?:\w+:)?instrText>/gu)]
1186
- .map((match) => decodeXmlEntities(match[1] ?? ""))
1187
- .join("")
1188
- .trim();
1189
- const instruction = (simpleInstruction ?? complexInstruction ?? "").trim();
1190
- const family = /^([A-Z]+)/i.exec(instruction)?.[1]?.toUpperCase();
1191
- const label =
1192
- family === "TOC"
1193
- ? "Table of Contents field"
1194
- : family
1195
- ? `${family} field`
1196
- : "Field";
1197
- return {
1198
- label,
1199
- detail:
1200
- instruction.length > 0
1201
- ? `Read-only field preserved for export safety. Instruction: ${instruction}.`
1202
- : "Read-only field preserved for export safety.",
1203
- };
1204
- }
1205
-
1206
- return null;
1207
- }
1208
-
1209
- function decodeXmlEntities(text: string): string {
1210
- return text
1211
- .replace(/&lt;/g, "<")
1212
- .replace(/&gt;/g, ">")
1213
- .replace(/&quot;/g, "\"")
1214
- .replace(/&apos;/g, "'")
1215
- .replace(/&amp;/g, "&");
1216
- }
1217
-
1218
- function cloneMarks(marks: TextMark[]): {
1219
- marks: SurfaceTextMark[];
1220
- markAttrs?: {
1221
- backgroundColor?: string;
1222
- charSpacing?: number;
1223
- kerning?: number;
1224
- textFill?: string;
1225
- fontFamily?: string;
1226
- fontSize?: number;
1227
- textColor?: string;
1228
- };
1229
- } {
1230
- const supported: SurfaceTextMark[] = [];
1231
- const attrs: {
1232
- backgroundColor?: string;
1233
- charSpacing?: number;
1234
- kerning?: number;
1235
- textFill?: string;
1236
- fontFamily?: string;
1237
- fontSize?: number;
1238
- textColor?: string;
1239
- } = {};
1240
- let shadingColor: string | undefined;
1241
- let highlightColor: string | undefined;
1242
- for (const mark of marks) {
1243
- switch (mark.type) {
1244
- case "bold":
1245
- case "italic":
1246
- case "underline":
1247
- case "strikethrough":
1248
- case "doubleStrikethrough":
1249
- case "vanish":
1250
- case "emboss":
1251
- case "imprint":
1252
- case "shadow":
1253
- supported.push(mark.type);
1254
- break;
1255
- case "position":
1256
- if (mark.val > 0) supported.push("superscript");
1257
- else if (mark.val < 0) supported.push("subscript");
1258
- break;
1259
- case "backgroundColor":
1260
- shadingColor = mark.color;
1261
- break;
1262
- case "highlight":
1263
- highlightColor = mark.color;
1264
- break;
1265
- case "charSpacing":
1266
- attrs.charSpacing = mark.val;
1267
- break;
1268
- case "kerning":
1269
- attrs.kerning = mark.val;
1270
- break;
1271
- case "textFill":
1272
- attrs.textFill = mark.xml;
1273
- break;
1274
- case "fontFamily":
1275
- attrs.fontFamily = mark.val;
1276
- break;
1277
- case "fontSize":
1278
- attrs.fontSize = mark.val;
1279
- break;
1280
- case "textColor":
1281
- attrs.textColor = mark.color;
1282
- break;
1283
- case "smallCaps":
1284
- supported.push("smallCaps");
1285
- break;
1286
- case "allCaps":
1287
- supported.push("allCaps");
1288
- break;
1289
- case "lang":
1290
- // no visual effect — skip
1291
- break;
1292
- }
1293
- }
1294
- if (highlightColor || shadingColor) {
1295
- attrs.backgroundColor = highlightColor ?? shadingColor;
1296
- }
1297
- const hasAttrs = Object.keys(attrs).length > 0;
1298
- return hasAttrs ? { marks: supported, markAttrs: attrs } : { marks: supported };
1299
- }
1300
-
1301
- function normalizeDocumentRoot(content: unknown): DocumentRootNode {
1302
- if (content && typeof content === "object" &&
1303
- ((content as { type?: string }).type === "doc" || (content as { type?: string }).type === "document_root")) {
1304
- return content as DocumentRootNode;
1305
- }
1306
-
1307
- if (Array.isArray(content)) {
1308
- return {
1309
- type: "doc",
1310
- children: content.filter(
1311
- (value): value is DocumentRootNode["children"][number] =>
1312
- Boolean(value) &&
1313
- typeof value === "object" &&
1314
- ((value as { type?: string }).type === "paragraph" ||
1315
- (value as { type?: string }).type === "table" ||
1316
- (value as { type?: string }).type === "sdt" ||
1317
- (value as { type?: string }).type === "custom_xml" ||
1318
- (value as { type?: string }).type === "alt_chunk" ||
1319
- (value as { type?: string }).type === "opaque_block"),
1320
- ),
1321
- };
1322
- }
1323
-
1324
- return {
1325
- type: "doc",
1326
- children: [{ type: "paragraph", children: [] }],
1327
- };
1328
- }
1329
-
1330
- function createFloatingImageDetail(
1331
- altText: string | undefined,
1332
- floating: {
1333
- horizontalPosition?: { relativeFrom?: string; align?: string; offset?: number };
1334
- verticalPosition?: { relativeFrom?: string; align?: string; offset?: number };
1335
- wrap?: string;
1336
- } | undefined,
1337
- ): string {
1338
- const parts = [altText ? `Alt text ${altText}.` : "Floating image rendered inline in the editor."];
1339
- if (floating?.wrap) {
1340
- parts.push(`Wrap ${floating.wrap}.`);
1341
- }
1342
- if (floating?.horizontalPosition?.align || floating?.horizontalPosition?.offset !== undefined) {
1343
- parts.push(
1344
- `Horizontal ${floating.horizontalPosition.align ?? floating.horizontalPosition.offset}.`,
1345
- );
1346
- }
1347
- if (floating?.verticalPosition?.align || floating?.verticalPosition?.offset !== undefined) {
1348
- parts.push(
1349
- `Vertical ${floating.verticalPosition.align ?? floating.verticalPosition.offset}.`,
1350
- );
1351
- }
1352
- return parts.join(" ");
1353
- }
1354
-
1355
- function hasMediaItem(media: MediaCatalog, mediaId: string): boolean {
1356
- return mediaId in media.items;
1357
- }