@beyondwork/docx-react-component 1.0.29 → 1.0.30

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 (381) hide show
  1. package/package.json +65 -96
  2. package/src/README.md +85 -0
  3. package/src/api/README.md +26 -0
  4. package/src/api/public-types.ts +1952 -0
  5. package/src/api/session-state.ts +62 -0
  6. package/src/compare/diff-engine.ts +623 -0
  7. package/src/compare/export-redlines.ts +280 -0
  8. package/src/compare/index.ts +25 -0
  9. package/src/compare/snapshot.ts +97 -0
  10. package/src/component-inventory.md +99 -0
  11. package/src/core/README.md +10 -0
  12. package/src/core/commands/README.md +3 -0
  13. package/{dist/chunk-TJBP2K4T.js → src/core/commands/formatting-commands.ts} +536 -196
  14. package/src/core/commands/image-commands.ts +373 -0
  15. package/src/core/commands/index.ts +1879 -0
  16. package/src/core/commands/list-commands.ts +565 -0
  17. package/src/core/commands/paragraph-layout-commands.ts +339 -0
  18. package/src/core/commands/review-commands.ts +108 -0
  19. package/{dist/core/commands/section-layout-commands.cjs → src/core/commands/section-layout-commands.ts} +340 -137
  20. package/src/core/commands/structural-helpers.ts +309 -0
  21. package/{dist/core/commands/style-commands.cjs → src/core/commands/style-commands.ts} +113 -65
  22. package/src/core/commands/table-structure-commands.ts +854 -0
  23. package/{dist/chunk-UZXBISGO.js → src/core/commands/text-commands.ts} +142 -86
  24. package/src/core/schema/README.md +3 -0
  25. package/src/core/schema/text-schema.ts +516 -0
  26. package/src/core/search/search-text.ts +357 -0
  27. package/src/core/selection/README.md +3 -0
  28. package/src/core/selection/mapping.ts +289 -0
  29. package/src/core/selection/review-anchors.ts +183 -0
  30. package/src/core/state/README.md +3 -0
  31. package/src/core/state/editor-state.ts +892 -0
  32. package/src/core/state/text-transaction.ts +869 -0
  33. package/src/formats/xlsx/io/parse-shared-strings.ts +41 -0
  34. package/src/formats/xlsx/io/parse-sheet.ts +459 -0
  35. package/src/formats/xlsx/io/parse-styles.ts +59 -0
  36. package/src/formats/xlsx/io/parse-workbook.ts +75 -0
  37. package/src/formats/xlsx/io/serialize-shared-strings.ts +72 -0
  38. package/src/formats/xlsx/io/serialize-sheet.ts +333 -0
  39. package/src/formats/xlsx/io/serialize-styles.ts +98 -0
  40. package/src/formats/xlsx/io/serialize-workbook.ts +429 -0
  41. package/src/formats/xlsx/io/xlsx-session.ts +314 -0
  42. package/src/formats/xlsx/model/cell.ts +189 -0
  43. package/src/formats/xlsx/model/sheet.ts +326 -0
  44. package/src/formats/xlsx/model/styles.ts +118 -0
  45. package/src/formats/xlsx/model/workbook.ts +453 -0
  46. package/src/formats/xlsx/runtime/cell-commands.ts +567 -0
  47. package/src/formats/xlsx/runtime/sheet-commands.ts +206 -0
  48. package/src/formats/xlsx/runtime/workbook-runtime.ts +177 -0
  49. package/src/formats/xlsx/runtime/workbook-transaction.ts +822 -0
  50. package/src/index.ts +142 -0
  51. package/src/io/README.md +10 -0
  52. package/src/io/docx-session.ts +3175 -0
  53. package/src/io/export/README.md +3 -0
  54. package/src/io/export/export-session.ts +220 -0
  55. package/src/io/export/minimal-docx.ts +115 -0
  56. package/src/io/export/reattach-preserved-parts.ts +54 -0
  57. package/src/io/export/serialize-comments.ts +947 -0
  58. package/src/io/export/serialize-footnotes.ts +394 -0
  59. package/src/io/export/serialize-headers-footers.ts +368 -0
  60. package/src/io/export/serialize-main-document.ts +1342 -0
  61. package/src/io/export/serialize-numbering.ts +218 -0
  62. package/src/io/export/serialize-revisions.ts +389 -0
  63. package/src/io/export/serialize-runtime-revisions.ts +463 -0
  64. package/src/io/export/serialize-tables.ts +174 -0
  65. package/src/io/export/split-review-boundaries.ts +356 -0
  66. package/src/io/export/split-story-blocks-for-runtime-revisions.ts +252 -0
  67. package/src/io/export/table-properties-xml.ts +318 -0
  68. package/src/io/normalize/README.md +3 -0
  69. package/src/io/normalize/normalize-text.ts +670 -0
  70. package/src/io/ooxml/README.md +3 -0
  71. package/src/io/ooxml/highlight-colors.ts +39 -0
  72. package/src/io/ooxml/numbering-sentinels.ts +44 -0
  73. package/src/io/ooxml/parse-comments.ts +852 -0
  74. package/src/io/ooxml/parse-complex-content.ts +287 -0
  75. package/src/io/ooxml/parse-fields.ts +834 -0
  76. package/src/io/ooxml/parse-footnotes.ts +952 -0
  77. package/src/io/ooxml/parse-headers-footers.ts +1212 -0
  78. package/src/io/ooxml/parse-inline-media.ts +461 -0
  79. package/src/io/ooxml/parse-main-document.ts +2947 -0
  80. package/src/io/ooxml/parse-numbering.ts +747 -0
  81. package/src/io/ooxml/parse-revisions.ts +1045 -0
  82. package/src/io/ooxml/parse-settings.ts +184 -0
  83. package/src/io/ooxml/parse-shapes.ts +296 -0
  84. package/src/io/ooxml/parse-styles.ts +639 -0
  85. package/src/io/ooxml/parse-tables.ts +627 -0
  86. package/src/io/ooxml/parse-theme.ts +346 -0
  87. package/src/io/ooxml/part-manifest.ts +136 -0
  88. package/src/io/ooxml/revision-boundaries.ts +475 -0
  89. package/src/io/ooxml/workflow-payload.ts +544 -0
  90. package/src/io/opc/README.md +3 -0
  91. package/src/io/opc/corrupt-package.ts +166 -0
  92. package/src/io/opc/docx-package.ts +74 -0
  93. package/src/io/opc/package-reader.ts +325 -0
  94. package/src/io/opc/package-writer.ts +273 -0
  95. package/src/io/source-package-provenance.ts +241 -0
  96. package/{dist/chunk-RMH72RZI.js → src/legal/bookmarks.ts} +130 -44
  97. package/src/legal/cross-references.ts +414 -0
  98. package/src/legal/defined-terms.ts +203 -0
  99. package/src/legal/index.ts +32 -0
  100. package/src/legal/signature-blocks.ts +259 -0
  101. package/src/model/README.md +3 -0
  102. package/src/model/canonical-document.ts +2722 -0
  103. package/src/model/cds-1.0.0.ts +212 -0
  104. package/src/model/snapshot.ts +760 -0
  105. package/src/preservation/README.md +3 -0
  106. package/src/preservation/markup-compatibility.ts +48 -0
  107. package/src/preservation/opaque-fragment-store.ts +89 -0
  108. package/src/preservation/opaque-region.ts +233 -0
  109. package/src/preservation/package-preservation.ts +113 -0
  110. package/src/preservation/preserved-part-manifest.ts +56 -0
  111. package/src/preservation/relationship-retention.ts +57 -0
  112. package/src/preservation/store.ts +255 -0
  113. package/src/review/README.md +16 -0
  114. package/src/review/store/README.md +3 -0
  115. package/src/review/store/comment-anchors.ts +70 -0
  116. package/src/review/store/comment-remapping.ts +154 -0
  117. package/src/review/store/comment-store.ts +349 -0
  118. package/src/review/store/comment-thread.ts +109 -0
  119. package/src/review/store/revision-actions.ts +423 -0
  120. package/src/review/store/revision-store.ts +323 -0
  121. package/src/review/store/revision-types.ts +182 -0
  122. package/src/review/store/runtime-comment-store.ts +43 -0
  123. package/src/runtime/README.md +3 -0
  124. package/src/runtime/ai-action-policy.ts +764 -0
  125. package/src/runtime/context-analytics.ts +824 -0
  126. package/src/runtime/document-layout.ts +332 -0
  127. package/src/runtime/document-locations.ts +521 -0
  128. package/src/runtime/document-navigation.ts +616 -0
  129. package/src/runtime/document-outline.ts +440 -0
  130. package/src/runtime/document-runtime.ts +4055 -0
  131. package/src/runtime/document-search.ts +145 -0
  132. package/src/runtime/event-refresh-hints.ts +137 -0
  133. package/src/runtime/numbering-prefix.ts +244 -0
  134. package/src/runtime/page-layout-estimation.ts +305 -0
  135. package/src/runtime/read-only-diagnostics-runtime.ts +241 -0
  136. package/src/runtime/resolved-numbering-geometry.ts +293 -0
  137. package/src/runtime/review-runtime.ts +44 -0
  138. package/src/runtime/revision-runtime.ts +107 -0
  139. package/src/runtime/session-capabilities.ts +192 -0
  140. package/src/runtime/story-context.ts +164 -0
  141. package/src/runtime/story-targeting.ts +162 -0
  142. package/src/runtime/suggestions-snapshot.ts +137 -0
  143. package/src/runtime/surface-projection.ts +1553 -0
  144. package/src/runtime/table-commands.ts +173 -0
  145. package/src/runtime/table-schema.ts +309 -0
  146. package/src/runtime/table-style-resolver.ts +409 -0
  147. package/src/runtime/view-state.ts +493 -0
  148. package/src/runtime/virtualized-rendering.ts +258 -0
  149. package/src/runtime/workflow-markup.ts +393 -0
  150. package/src/ui/README.md +30 -0
  151. package/src/ui/WordReviewEditor.tsx +5268 -0
  152. package/src/ui/browser-export.ts +52 -0
  153. package/src/ui/comments/README.md +3 -0
  154. package/src/ui/compatibility/README.md +3 -0
  155. package/src/ui/editor-command-bag.ts +127 -0
  156. package/src/ui/editor-runtime-boundary.ts +1558 -0
  157. package/src/ui/editor-shell-view.tsx +144 -0
  158. package/src/ui/editor-surface/README.md +3 -0
  159. package/src/ui/editor-surface-controller.tsx +66 -0
  160. package/src/ui/headless/comment-decoration-model.ts +124 -0
  161. package/src/ui/headless/preserve-editor-selection.ts +5 -0
  162. package/src/ui/headless/revision-decoration-model.ts +128 -0
  163. package/src/ui/headless/selection-helpers.ts +54 -0
  164. package/src/ui/headless/selection-tool-context.ts +19 -0
  165. package/src/ui/headless/selection-tool-resolver.ts +752 -0
  166. package/src/ui/headless/selection-tool-types.ts +129 -0
  167. package/src/ui/headless/selection-toolbar-model.ts +11 -0
  168. package/src/ui/headless/use-editor-keyboard.ts +103 -0
  169. package/src/ui/review/README.md +3 -0
  170. package/src/ui/runtime-shortcut-dispatch.ts +365 -0
  171. package/src/ui/runtime-snapshot-selectors.ts +197 -0
  172. package/src/ui/shared/revision-filters.ts +31 -0
  173. package/src/ui/status/README.md +3 -0
  174. package/src/ui/theme/README.md +3 -0
  175. package/src/ui/toolbar/README.md +3 -0
  176. package/src/ui/workflow-surface-blocked-rails.ts +94 -0
  177. package/src/ui-tailwind/chrome/chrome-preset-model.ts +107 -0
  178. package/src/ui-tailwind/chrome/chrome-preset-toolbar.tsx +15 -0
  179. package/src/ui-tailwind/chrome/review-queue-bar.tsx +97 -0
  180. package/src/ui-tailwind/chrome/tw-alert-banner.tsx +64 -0
  181. package/src/ui-tailwind/chrome/tw-context-analytics-summary.tsx +122 -0
  182. package/src/ui-tailwind/chrome/tw-image-context-toolbar.tsx +121 -0
  183. package/src/ui-tailwind/chrome/tw-layout-panel.tsx +114 -0
  184. package/src/ui-tailwind/chrome/tw-object-context-toolbar.tsx +30 -0
  185. package/src/ui-tailwind/chrome/tw-page-ruler.tsx +365 -0
  186. package/src/ui-tailwind/chrome/tw-selection-tool-blocked.tsx +23 -0
  187. package/src/ui-tailwind/chrome/tw-selection-tool-comment.tsx +35 -0
  188. package/src/ui-tailwind/chrome/tw-selection-tool-formatting.tsx +37 -0
  189. package/src/ui-tailwind/chrome/tw-selection-tool-host.tsx +298 -0
  190. package/src/ui-tailwind/chrome/tw-selection-tool-structure.tsx +116 -0
  191. package/src/ui-tailwind/chrome/tw-selection-tool-suggestion.tsx +29 -0
  192. package/src/ui-tailwind/chrome/tw-selection-tool-workflow.tsx +27 -0
  193. package/src/ui-tailwind/chrome/tw-selection-toolbar.tsx +186 -0
  194. package/src/ui-tailwind/chrome/tw-suggestion-card.tsx +139 -0
  195. package/src/ui-tailwind/chrome/tw-table-context-toolbar.tsx +200 -0
  196. package/src/ui-tailwind/chrome/tw-unsaved-modal.tsx +58 -0
  197. package/src/ui-tailwind/chrome/use-before-unload.ts +20 -0
  198. package/src/ui-tailwind/editor-surface/perf-probe.ts +179 -0
  199. package/src/ui-tailwind/editor-surface/pm-command-bridge.ts +189 -0
  200. package/src/ui-tailwind/editor-surface/pm-contextual-ui.ts +31 -0
  201. package/src/ui-tailwind/editor-surface/pm-decorations.ts +411 -0
  202. package/src/ui-tailwind/editor-surface/pm-position-map.ts +123 -0
  203. package/src/ui-tailwind/editor-surface/pm-schema.ts +927 -0
  204. package/src/ui-tailwind/editor-surface/pm-state-from-snapshot.ts +567 -0
  205. package/src/ui-tailwind/editor-surface/search-plugin.ts +168 -0
  206. package/src/ui-tailwind/editor-surface/surface-build-keys.ts +65 -0
  207. package/src/ui-tailwind/editor-surface/tw-caret.tsx +12 -0
  208. package/src/ui-tailwind/editor-surface/tw-editor-surface.tsx +150 -0
  209. package/src/ui-tailwind/editor-surface/tw-inline-token.tsx +129 -0
  210. package/src/ui-tailwind/editor-surface/tw-opaque-block.tsx +58 -0
  211. package/src/ui-tailwind/editor-surface/tw-paragraph-block.tsx +151 -0
  212. package/src/ui-tailwind/editor-surface/tw-prosemirror-surface.tsx +1047 -0
  213. package/src/ui-tailwind/editor-surface/tw-segment-view.tsx +111 -0
  214. package/src/ui-tailwind/editor-surface/tw-table-node-view.tsx +503 -0
  215. package/src/ui-tailwind/index.ts +62 -0
  216. package/src/ui-tailwind/page-chrome-model.ts +27 -0
  217. package/src/ui-tailwind/review/tw-comment-sidebar.tsx +406 -0
  218. package/src/ui-tailwind/review/tw-health-panel.tsx +149 -0
  219. package/src/ui-tailwind/review/tw-review-rail.tsx +122 -0
  220. package/src/ui-tailwind/review/tw-revision-sidebar.tsx +164 -0
  221. package/src/ui-tailwind/status/tw-status-bar.tsx +65 -0
  222. package/{dist → src}/ui-tailwind/theme/editor-theme.css +58 -40
  223. package/src/ui-tailwind/toolbar/tw-toolbar-icon-button.tsx +52 -0
  224. package/src/ui-tailwind/toolbar/tw-toolbar.tsx +1133 -0
  225. package/src/ui-tailwind/tw-review-workspace.tsx +1460 -0
  226. package/src/validation/README.md +3 -0
  227. package/src/validation/compatibility-engine.ts +878 -0
  228. package/src/validation/compatibility-report.ts +161 -0
  229. package/src/validation/diagnostics.ts +204 -0
  230. package/src/validation/docx-comment-proof.ts +720 -0
  231. package/src/validation/import-diagnostics.ts +128 -0
  232. package/src/validation/low-priority-word-surfaces.ts +373 -0
  233. package/dist/canonical-document-BLEbzL2J.d.cts +0 -844
  234. package/dist/canonical-document-BLEbzL2J.d.ts +0 -844
  235. package/dist/chunk-2FJS5GZM.js +0 -763
  236. package/dist/chunk-2FJS5GZM.js.map +0 -1
  237. package/dist/chunk-2OQBZS3F.js +0 -446
  238. package/dist/chunk-2OQBZS3F.js.map +0 -1
  239. package/dist/chunk-2S7W4KFO.js +0 -127
  240. package/dist/chunk-2S7W4KFO.js.map +0 -1
  241. package/dist/chunk-2TG72QSW.js +0 -3874
  242. package/dist/chunk-2TG72QSW.js.map +0 -1
  243. package/dist/chunk-36QNIZBO.js +0 -532
  244. package/dist/chunk-36QNIZBO.js.map +0 -1
  245. package/dist/chunk-4AQOYAW4.js +0 -3069
  246. package/dist/chunk-4AQOYAW4.js.map +0 -1
  247. package/dist/chunk-4D5EWJ3P.js +0 -77
  248. package/dist/chunk-4D5EWJ3P.js.map +0 -1
  249. package/dist/chunk-5FN54NDH.js +0 -2257
  250. package/dist/chunk-5FN54NDH.js.map +0 -1
  251. package/dist/chunk-BOYGQYRQ.js +0 -7306
  252. package/dist/chunk-BOYGQYRQ.js.map +0 -1
  253. package/dist/chunk-CN3XMECL.js +0 -212
  254. package/dist/chunk-CN3XMECL.js.map +0 -1
  255. package/dist/chunk-EBI3BX6U.js +0 -164
  256. package/dist/chunk-EBI3BX6U.js.map +0 -1
  257. package/dist/chunk-EILUG3VB.js +0 -1275
  258. package/dist/chunk-EILUG3VB.js.map +0 -1
  259. package/dist/chunk-FUDY333O.js +0 -70
  260. package/dist/chunk-FUDY333O.js.map +0 -1
  261. package/dist/chunk-GBVOWFIK.js +0 -1237
  262. package/dist/chunk-GBVOWFIK.js.map +0 -1
  263. package/dist/chunk-H4TQ3H3Y.js +0 -262
  264. package/dist/chunk-H4TQ3H3Y.js.map +0 -1
  265. package/dist/chunk-JGB3IXZO.js +0 -189
  266. package/dist/chunk-JGB3IXZO.js.map +0 -1
  267. package/dist/chunk-KD2QRQPY.js +0 -4342
  268. package/dist/chunk-KD2QRQPY.js.map +0 -1
  269. package/dist/chunk-KLMXQVYK.js +0 -369
  270. package/dist/chunk-KLMXQVYK.js.map +0 -1
  271. package/dist/chunk-KZUG5KFQ.js +0 -214
  272. package/dist/chunk-KZUG5KFQ.js.map +0 -1
  273. package/dist/chunk-QDAQ4CJU.js +0 -345
  274. package/dist/chunk-QDAQ4CJU.js.map +0 -1
  275. package/dist/chunk-RMH72RZI.js.map +0 -1
  276. package/dist/chunk-SWKWQZXM.js +0 -117
  277. package/dist/chunk-SWKWQZXM.js.map +0 -1
  278. package/dist/chunk-TJBP2K4T.js.map +0 -1
  279. package/dist/chunk-TLCEAQDQ.js +0 -542
  280. package/dist/chunk-TLCEAQDQ.js.map +0 -1
  281. package/dist/chunk-UZXBISGO.js.map +0 -1
  282. package/dist/chunk-WGBAKP3Q.js +0 -3220
  283. package/dist/chunk-WGBAKP3Q.js.map +0 -1
  284. package/dist/compare/index.cjs +0 -5475
  285. package/dist/compare/index.cjs.map +0 -1
  286. package/dist/compare/index.d.cts +0 -114
  287. package/dist/compare/index.d.ts +0 -114
  288. package/dist/compare/index.js +0 -731
  289. package/dist/compare/index.js.map +0 -1
  290. package/dist/core/commands/formatting-commands.cjs +0 -828
  291. package/dist/core/commands/formatting-commands.cjs.map +0 -1
  292. package/dist/core/commands/formatting-commands.d.cts +0 -63
  293. package/dist/core/commands/formatting-commands.d.ts +0 -63
  294. package/dist/core/commands/formatting-commands.js +0 -37
  295. package/dist/core/commands/formatting-commands.js.map +0 -1
  296. package/dist/core/commands/image-commands.cjs +0 -2023
  297. package/dist/core/commands/image-commands.cjs.map +0 -1
  298. package/dist/core/commands/image-commands.d.cts +0 -58
  299. package/dist/core/commands/image-commands.d.ts +0 -58
  300. package/dist/core/commands/image-commands.js +0 -18
  301. package/dist/core/commands/image-commands.js.map +0 -1
  302. package/dist/core/commands/section-layout-commands.cjs.map +0 -1
  303. package/dist/core/commands/section-layout-commands.d.cts +0 -62
  304. package/dist/core/commands/section-layout-commands.d.ts +0 -62
  305. package/dist/core/commands/section-layout-commands.js +0 -21
  306. package/dist/core/commands/section-layout-commands.js.map +0 -1
  307. package/dist/core/commands/style-commands.cjs.map +0 -1
  308. package/dist/core/commands/style-commands.d.cts +0 -13
  309. package/dist/core/commands/style-commands.d.ts +0 -13
  310. package/dist/core/commands/style-commands.js +0 -9
  311. package/dist/core/commands/style-commands.js.map +0 -1
  312. package/dist/core/commands/table-structure-commands.cjs +0 -1883
  313. package/dist/core/commands/table-structure-commands.cjs.map +0 -1
  314. package/dist/core/commands/table-structure-commands.d.cts +0 -59
  315. package/dist/core/commands/table-structure-commands.d.ts +0 -59
  316. package/dist/core/commands/table-structure-commands.js +0 -12
  317. package/dist/core/commands/table-structure-commands.js.map +0 -1
  318. package/dist/core/commands/text-commands.cjs +0 -2391
  319. package/dist/core/commands/text-commands.cjs.map +0 -1
  320. package/dist/core/commands/text-commands.d.cts +0 -24
  321. package/dist/core/commands/text-commands.d.ts +0 -24
  322. package/dist/core/commands/text-commands.js +0 -28
  323. package/dist/core/commands/text-commands.js.map +0 -1
  324. package/dist/core/selection/mapping.cjs +0 -200
  325. package/dist/core/selection/mapping.cjs.map +0 -1
  326. package/dist/core/selection/mapping.d.cts +0 -2
  327. package/dist/core/selection/mapping.d.ts +0 -2
  328. package/dist/core/selection/mapping.js +0 -31
  329. package/dist/core/selection/mapping.js.map +0 -1
  330. package/dist/core/state/editor-state.cjs +0 -2278
  331. package/dist/core/state/editor-state.cjs.map +0 -1
  332. package/dist/core/state/editor-state.d.cts +0 -2
  333. package/dist/core/state/editor-state.d.ts +0 -2
  334. package/dist/core/state/editor-state.js +0 -26
  335. package/dist/core/state/editor-state.js.map +0 -1
  336. package/dist/index.cjs +0 -38553
  337. package/dist/index.cjs.map +0 -1
  338. package/dist/index.d.cts +0 -15
  339. package/dist/index.d.ts +0 -15
  340. package/dist/index.js +0 -7856
  341. package/dist/index.js.map +0 -1
  342. package/dist/io/docx-session.cjs +0 -16236
  343. package/dist/io/docx-session.cjs.map +0 -1
  344. package/dist/io/docx-session.d.cts +0 -21
  345. package/dist/io/docx-session.d.ts +0 -21
  346. package/dist/io/docx-session.js +0 -18
  347. package/dist/io/docx-session.js.map +0 -1
  348. package/dist/legal/index.cjs +0 -3900
  349. package/dist/legal/index.cjs.map +0 -1
  350. package/dist/legal/index.d.cts +0 -86
  351. package/dist/legal/index.d.ts +0 -86
  352. package/dist/legal/index.js +0 -616
  353. package/dist/legal/index.js.map +0 -1
  354. package/dist/public-types-7ZL_94cz.d.ts +0 -1573
  355. package/dist/public-types-CeMaDueh.d.cts +0 -1573
  356. package/dist/public-types.cjs +0 -19
  357. package/dist/public-types.cjs.map +0 -1
  358. package/dist/public-types.d.cts +0 -2
  359. package/dist/public-types.d.ts +0 -2
  360. package/dist/public-types.js +0 -1
  361. package/dist/public-types.js.map +0 -1
  362. package/dist/runtime/document-runtime.cjs +0 -11140
  363. package/dist/runtime/document-runtime.cjs.map +0 -1
  364. package/dist/runtime/document-runtime.d.cts +0 -231
  365. package/dist/runtime/document-runtime.d.ts +0 -231
  366. package/dist/runtime/document-runtime.js +0 -21
  367. package/dist/runtime/document-runtime.js.map +0 -1
  368. package/dist/structural-helpers-CilgOVhh.d.cts +0 -10
  369. package/dist/structural-helpers-q0Gd-eBN.d.ts +0 -10
  370. package/dist/ui-tailwind/editor-surface/search-plugin.cjs +0 -313
  371. package/dist/ui-tailwind/editor-surface/search-plugin.cjs.map +0 -1
  372. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +0 -67
  373. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +0 -67
  374. package/dist/ui-tailwind/editor-surface/search-plugin.js +0 -23
  375. package/dist/ui-tailwind/editor-surface/search-plugin.js.map +0 -1
  376. package/dist/ui-tailwind/index.cjs +0 -4833
  377. package/dist/ui-tailwind/index.cjs.map +0 -1
  378. package/dist/ui-tailwind/index.d.cts +0 -617
  379. package/dist/ui-tailwind/index.d.ts +0 -617
  380. package/dist/ui-tailwind/index.js +0 -575
  381. package/dist/ui-tailwind/index.js.map +0 -1
@@ -0,0 +1,1460 @@
1
+ import React, {
2
+ type CSSProperties,
3
+ type FocusEventHandler,
4
+ type ReactNode,
5
+ type Ref,
6
+ useCallback,
7
+ useEffect,
8
+ useMemo,
9
+ useRef,
10
+ useState,
11
+ } from "react";
12
+
13
+ import * as Tooltip from "@radix-ui/react-tooltip";
14
+ import { ChevronLeft, ChevronRight, List } from "lucide-react";
15
+
16
+ import type {
17
+ ActiveListContext,
18
+ CommentSidebarThreadSnapshot,
19
+ DocumentNavigationSnapshot,
20
+ EditorViewStateSnapshot,
21
+ FormattingStateSnapshot,
22
+ FormattingAlignment,
23
+ HeaderFooterLinkPatch,
24
+ InteractionGuardSnapshot,
25
+ InsertImageOptions,
26
+ RuntimeContextAnalyticsSnapshot,
27
+ RuntimeRenderSnapshot,
28
+ ReviewQueueSnapshot,
29
+ SectionPageNumberingPatch,
30
+ SectionBreakType,
31
+ StyleCatalogSnapshot,
32
+ SurfaceBlockSnapshot,
33
+ TrackedChangeEntrySnapshot,
34
+ WordReviewEditorChromeOptions,
35
+ WordReviewEditorChromePreset,
36
+ WordReviewEditorChromeVisibility,
37
+ WorkflowScopeSnapshot,
38
+ WorkspaceMode,
39
+ ZoomLevel,
40
+ } from "../api/public-types";
41
+ import { findPageForOffset } from "../runtime/document-navigation.ts";
42
+ import {
43
+ DEFAULT_PAGE_ESTIMATE_PX_PER_TWIP,
44
+ estimateBlockHeight,
45
+ estimateParagraphLineCount,
46
+ estimateParagraphLineHeight,
47
+ getUsableColumnWidth,
48
+ } from "../runtime/page-layout-estimation.ts";
49
+ import {
50
+ incrementInvalidationCounter,
51
+ recordPerfSample,
52
+ } from "./editor-surface/perf-probe.ts";
53
+ import { computeLineMarkersIfEnabled } from "./page-chrome-model.ts";
54
+ import type { SessionCapabilities } from "../runtime/session-capabilities";
55
+ import type {
56
+ ActiveSelectionToolModel,
57
+ SelectionToolAnchor,
58
+ } from "../ui/headless/selection-tool-types";
59
+ import type { MarkupDisplay } from "../ui/headless/comment-decoration-model";
60
+ import type { EditorCommandBag } from "../ui/editor-command-bag.ts";
61
+ import { preserveEditorSelectionMouseDown } from "../ui/headless/preserve-editor-selection";
62
+ import { TwAlertBanner } from "./chrome/tw-alert-banner";
63
+ import { TwLayoutPanel } from "./chrome/tw-layout-panel";
64
+ import { TwPageRuler } from "./chrome/tw-page-ruler";
65
+ import { ChromePresetToolbar } from "./chrome/chrome-preset-toolbar";
66
+ import {
67
+ resolveChromePreset,
68
+ resolveChromePresetOptions,
69
+ resolveChromeVisibilityForPreset,
70
+ } from "./chrome/chrome-preset-model";
71
+ import { TwReviewQueueBar } from "./chrome/review-queue-bar";
72
+ import { TwSelectionToolHost } from "./chrome/tw-selection-tool-host";
73
+ import { TwReviewRail, type ReviewRailTab } from "./review/tw-review-rail";
74
+ import { TwStatusBar } from "./status/tw-status-bar";
75
+ import { type ToolbarInteractionPolicy } from "./toolbar/tw-toolbar";
76
+
77
+ export type ReviewWorkspaceChromeVisibility = WordReviewEditorChromeVisibility;
78
+
79
+ export interface TwReviewWorkspaceProps {
80
+ snapshot: RuntimeRenderSnapshot;
81
+ viewState: EditorViewStateSnapshot;
82
+ markupDisplay: MarkupDisplay;
83
+ currentUserId?: string;
84
+ capabilities?: SessionCapabilities;
85
+ reviewMode?: "editing" | "review";
86
+ document: ReactNode;
87
+ workspaceMode: WorkspaceMode;
88
+ zoomLevel?: ZoomLevel;
89
+ formattingState?: FormattingStateSnapshot;
90
+ activeListContext?: ActiveListContext | null;
91
+ styleCatalog?: StyleCatalogSnapshot;
92
+ activeRailTab: ReviewRailTab;
93
+ activeCommentId?: string;
94
+ activeRevisionId?: string;
95
+ showTrackedChanges: boolean;
96
+ workflowScopeSnapshot?: WorkflowScopeSnapshot | null;
97
+ interactionGuardSnapshot?: InteractionGuardSnapshot;
98
+ chromePreset?: WordReviewEditorChromePreset;
99
+ chromeOptions?: Partial<WordReviewEditorChromeOptions>;
100
+ reviewQueue?: ReviewQueueSnapshot;
101
+ documentContextAnalytics?: RuntimeContextAnalyticsSnapshot | null;
102
+ selectionContextAnalytics?: RuntimeContextAnalyticsSnapshot | null;
103
+ currentScopeContextAnalytics?: RuntimeContextAnalyticsSnapshot | null;
104
+ commands: EditorCommandBag;
105
+ activeSelectionTool?: ActiveSelectionToolModel | null;
106
+ selectionToolAnchor?: SelectionToolAnchor | null;
107
+ documentNavigation?: DocumentNavigationSnapshot;
108
+ onWorkspaceModeChange?: (value: WorkspaceMode) => void;
109
+ onZoomChange?: (level: ZoomLevel) => void;
110
+ onActiveRailTabChange?: (value: ReviewRailTab) => void;
111
+ onShowTrackedChangesChange?: (show: boolean) => void;
112
+ onUndo?: () => void;
113
+ onRedo?: () => void;
114
+ onSetParagraphStyle?: (styleId: string) => void;
115
+ onToggleBold?: () => void;
116
+ onToggleItalic?: () => void;
117
+ onToggleUnderline?: () => void;
118
+ onSetSelectionTextColor?: (color: string) => void;
119
+ onSetSelectionHighlightColor?: (color: string | null) => void;
120
+ onToggleStrikethrough?: () => void;
121
+ onToggleSuperscript?: () => void;
122
+ onToggleSubscript?: () => void;
123
+ onSetFontFamily?: (fontFamily: string) => void;
124
+ onSetFontSize?: (fontSize: number) => void;
125
+ onSetTextColor?: (color: string) => void;
126
+ onSetHighlightColor?: (color: string | null) => void;
127
+ onSetAlignment?: (alignment: FormattingAlignment) => void;
128
+ onToggleBulletedList?: () => void;
129
+ onToggleNumberedList?: () => void;
130
+ onOutdent?: () => void;
131
+ onIndent?: () => void;
132
+ onAddComment?: () => void;
133
+ onInsertPageBreak?: () => void;
134
+ onInsertTable?: () => void;
135
+ onInsertSectionBreak?: (type: SectionBreakType) => void;
136
+ onInsertImage?: (options: InsertImageOptions) => void;
137
+ onSetTableStyle?: (styleId: string) => void;
138
+ onAddRowBefore?: () => void;
139
+ onAddRowAfter?: () => void;
140
+ onAddColumnBefore?: () => void;
141
+ onAddColumnAfter?: () => void;
142
+ onDeleteRow?: () => void;
143
+ onDeleteColumn?: () => void;
144
+ onDeleteTable?: () => void;
145
+ onMergeCells?: () => void;
146
+ onSplitCell?: () => void;
147
+ onSetCellBackground?: (color: string) => void;
148
+ onSetImageLayout?: (
149
+ mediaId: string,
150
+ dimensions: { widthEmu: number; heightEmu: number },
151
+ ) => void;
152
+ onSetImageFrame?: (
153
+ mediaId: string,
154
+ offsets: { horizontalOffsetEmu?: number; verticalOffsetEmu?: number },
155
+ ) => void;
156
+ onDeleteSectionBreak?: (sectionIndex: number) => void;
157
+ onUpdateSectionLayout?: (
158
+ sectionIndex: number,
159
+ patch: {
160
+ pageSize?: { width?: number; height?: number; orientation?: "portrait" | "landscape" };
161
+ pageMargins?: {
162
+ top?: number;
163
+ right?: number;
164
+ bottom?: number;
165
+ left?: number;
166
+ header?: number;
167
+ footer?: number;
168
+ gutter?: number;
169
+ };
170
+ columns?: {
171
+ count?: number;
172
+ space?: number;
173
+ equalWidth?: boolean;
174
+ columns?: Array<{ width: number; space?: number }>;
175
+ separator?: boolean;
176
+ };
177
+ titlePage?: boolean;
178
+ sectionType?: SectionBreakType;
179
+ },
180
+ ) => void;
181
+ onSetSectionPageNumbering?: (
182
+ sectionIndex: number,
183
+ patch: SectionPageNumberingPatch | null,
184
+ ) => void;
185
+ onSetHeaderFooterLink?: (
186
+ sectionIndex: number,
187
+ patch: HeaderFooterLinkPatch,
188
+ ) => void;
189
+ onAddCommentFromSelection?: () => void;
190
+ onExport?: () => void;
191
+ onDismissSelectionToolbar?: () => void;
192
+ onAcceptSuggestion?: () => void;
193
+ onRejectSuggestion?: () => void;
194
+ onEditSuggestion?: () => void;
195
+ onAddCommentFromSuggestion?: () => void;
196
+ onSelectionToolbarFocusCapture?: FocusEventHandler<HTMLDivElement>;
197
+ onSelectionToolbarBlurCapture?: FocusEventHandler<HTMLDivElement>;
198
+ selectionToolbarRef?: Ref<HTMLDivElement>;
199
+ onOpenComment?: (thread: CommentSidebarThreadSnapshot) => void;
200
+ onResolveComment?: (commentId: string) => void;
201
+ onReopenComment?: (commentId: string) => void;
202
+ onAddReply?: (commentId: string, body: string) => void;
203
+ onEditBody?: (commentId: string, body: string) => void;
204
+ onOpenRevision?: (revision: TrackedChangeEntrySnapshot) => void;
205
+ onAcceptRevision?: (revisionId: string) => void;
206
+ onRejectRevision?: (revisionId: string) => void;
207
+ onAcceptAllChanges?: () => void;
208
+ onRejectAllChanges?: () => void;
209
+ onCloseStory?: () => void;
210
+ onOpenHeaderStory?: () => void;
211
+ onOpenFooterStory?: () => void;
212
+ onSetParagraphIndentation?: (indentation: {
213
+ left?: number;
214
+ right?: number;
215
+ firstLine?: number;
216
+ hanging?: number;
217
+ }) => void;
218
+ onSetParagraphTabStops?: (tabStops: Array<{ pos: number; val?: string; leader?: string }>) => void;
219
+ onRestartNumbering?: () => void;
220
+ onContinueNumbering?: () => void;
221
+ onUpdateFields?: () => void;
222
+ onUpdateTableOfContents?: () => void;
223
+ onGoToPreviousReviewItem?: () => void;
224
+ onGoToNextReviewItem?: () => void;
225
+ onMarkSectionForReview?: () => void;
226
+ onNavigateHeading?: (headingId: string) => void;
227
+ chromeVisibility?: Partial<ReviewWorkspaceChromeVisibility>;
228
+ }
229
+
230
+ export function TwReviewWorkspace(inputProps: TwReviewWorkspaceProps) {
231
+ const props = {
232
+ ...inputProps,
233
+ ...inputProps.commands,
234
+ } as TwReviewWorkspaceProps & EditorCommandBag;
235
+ const { snapshot, viewState } = props;
236
+ const selectionToolbarRootRef = useRef<HTMLDivElement>(null);
237
+ const caps = props.capabilities;
238
+ const isPageWorkspace = props.workspaceMode === "page";
239
+ const markupDisplay = props.markupDisplay;
240
+ const [navOpen, setNavOpen] = useState(false);
241
+ const [layoutToolsOpen, setLayoutToolsOpen] = useState(false);
242
+ const zoomLevel = props.zoomLevel ?? 100;
243
+ const zoomScale = typeof zoomLevel === "number" ? zoomLevel / 100 : 1;
244
+ const pageZoomBucket =
245
+ !isPageWorkspace ? undefined : zoomScale < 1 ? "low" : zoomScale > 1 ? "high" : "base";
246
+ const chromePreset = resolveChromePreset(props.chromePreset, props.reviewMode);
247
+ const chromeOptions = resolveChromePresetOptions(chromePreset, props.chromeOptions);
248
+ const preserveOnlyCount = caps?.preserveOnlyCount ??
249
+ snapshot.compatibility.featureEntries.filter(
250
+ (entry) => entry.featureClass === "preserve-only",
251
+ ).length;
252
+ const blockedReasons =
253
+ props.interactionGuardSnapshot?.blockedReasons ??
254
+ props.workflowScopeSnapshot?.blockedReasons ??
255
+ [];
256
+ const chromeVisibility = resolveChromeVisibilityForPreset({
257
+ chromePreset,
258
+ chromeOptions,
259
+ chromeVisibility: props.chromeVisibility,
260
+ });
261
+ const showReviewRail = chromeVisibility.reviewRail && (caps?.reviewRailVisible ?? true);
262
+ const headings = props.documentNavigation?.headings ?? [];
263
+ const headerVariant = snapshot.pageLayout?.headerVariants[0]?.variant ?? "default";
264
+ const footerVariant = snapshot.pageLayout?.footerVariants[0]?.variant ?? "default";
265
+ const selectionPosition =
266
+ viewState.selection.activeRange.kind === "node"
267
+ ? viewState.selection.activeRange.at
268
+ : viewState.selection.head;
269
+ const shouldResolveActiveParagraphLayout =
270
+ isPageWorkspace &&
271
+ chromeVisibility.pageChrome &&
272
+ layoutToolsOpen;
273
+ const activeParagraphLayout = useMemo(
274
+ () =>
275
+ shouldResolveActiveParagraphLayout
276
+ ? resolveActiveParagraphLayout(snapshot.surface, selectionPosition)
277
+ : null,
278
+ [selectionPosition, shouldResolveActiveParagraphLayout, snapshot.surface],
279
+ );
280
+ const pageChromeModel = useMemo(
281
+ () =>
282
+ buildPageChromeModel(
283
+ snapshot.surface,
284
+ snapshot.pageLayout,
285
+ props.documentNavigation,
286
+ snapshot.activeStory,
287
+ ),
288
+ [props.documentNavigation, snapshot.activeStory, snapshot.pageLayout, snapshot.surface],
289
+ );
290
+ const selectionToolbarPlacement = resolveSelectionToolbarPlacement(
291
+ props.selectionToolAnchor,
292
+ selectionToolbarRootRef.current,
293
+ zoomScale,
294
+ );
295
+ const effectiveSelectionMode = props.interactionGuardSnapshot?.effectiveMode ?? "edit";
296
+ const allowLocalChromeMutations = Boolean(caps?.canEdit) && effectiveSelectionMode === "edit";
297
+ const gatedSelectionTool = useMemo(() => {
298
+ if (!props.activeSelectionTool) {
299
+ return null;
300
+ }
301
+ if (props.activeSelectionTool.kind === "structure-context" && !chromeVisibility.contextToolbars) {
302
+ return null;
303
+ }
304
+ return props.activeSelectionTool;
305
+ }, [props.activeSelectionTool, chromeVisibility.contextToolbars]);
306
+ const activePage = props.documentNavigation?.pages[props.documentNavigation.activePageIndex] ?? null;
307
+ const pageShellMetrics = useMemo(
308
+ () => buildPageShellMetrics(snapshot.pageLayout),
309
+ [snapshot.pageLayout],
310
+ );
311
+ const headerBandLabel = resolvePageBandLabel("header", snapshot.activeStory);
312
+ const footerBandLabel = resolvePageBandLabel("footer", snapshot.activeStory);
313
+ const hidePageBorderForActiveEditing =
314
+ isPageWorkspace &&
315
+ snapshot.activeStory.kind === "main" &&
316
+ shouldHidePageBorderForSelection(viewState.selection);
317
+ const pageChromeReadOnly =
318
+ snapshot.readOnly ||
319
+ snapshot.activeStory.kind !== "main" ||
320
+ effectiveSelectionMode !== "edit";
321
+ const toolbarInteractionPolicy: ToolbarInteractionPolicy | undefined = caps
322
+ ? {
323
+ mode: effectiveSelectionMode,
324
+ canFormatText: caps.canEdit && effectiveSelectionMode === "edit",
325
+ canInsertStructural: caps.canEdit && effectiveSelectionMode === "edit",
326
+ canAddComment:
327
+ caps.canAddComment &&
328
+ effectiveSelectionMode !== "view" &&
329
+ effectiveSelectionMode !== "blocked",
330
+ }
331
+ : undefined;
332
+
333
+ useEffect(() => {
334
+ recordPerfSample("workspace.chrome");
335
+ incrementInvalidationCounter("workspace.chrome.recomputes");
336
+ }, [activeParagraphLayout, pageChromeModel, pageShellMetrics]);
337
+
338
+ useEffect(() => {
339
+ if (isPageWorkspace && snapshot.activeStory.kind !== "main") {
340
+ setLayoutToolsOpen(true);
341
+ }
342
+ }, [isPageWorkspace, snapshot.activeStory.kind]);
343
+
344
+ const dismissSelectionToolbar = useCallback(() => {
345
+ props.onDismissSelectionToolbar?.();
346
+ }, [props.onDismissSelectionToolbar]);
347
+
348
+ const runWithSelectionToolbarDismiss = useCallback(
349
+ (action?: () => void) => () => {
350
+ dismissSelectionToolbar();
351
+ action?.();
352
+ },
353
+ [dismissSelectionToolbar],
354
+ );
355
+
356
+ return (
357
+ <Tooltip.Provider delayDuration={400}>
358
+ <div className="flex h-full flex-col bg-canvas text-primary">
359
+ {chromeVisibility.toolbar ? (
360
+ <div className="px-3 pt-3">
361
+ <ChromePresetToolbar
362
+ chromePreset={chromePreset}
363
+ capabilities={caps}
364
+ compatibility={snapshot.compatibility}
365
+ warnings={snapshot.warnings}
366
+ blockedReasons={blockedReasons}
367
+ showDiagnosticsChrome={chromeVisibility.alerts}
368
+ interactionPolicy={toolbarInteractionPolicy}
369
+ workspaceMode={props.workspaceMode}
370
+ zoomLevel={props.zoomLevel}
371
+ formattingState={props.formattingState}
372
+ activeListContext={props.activeListContext}
373
+ styleCatalog={props.styleCatalog}
374
+ showTrackedChanges={props.showTrackedChanges}
375
+ onUndo={runWithSelectionToolbarDismiss(props.onUndo)}
376
+ onRedo={runWithSelectionToolbarDismiss(props.onRedo)}
377
+ onSetParagraphStyle={props.onSetParagraphStyle
378
+ ? (styleId) => {
379
+ dismissSelectionToolbar();
380
+ props.onSetParagraphStyle?.(styleId);
381
+ }
382
+ : undefined}
383
+ onToggleBold={runWithSelectionToolbarDismiss(props.onToggleBold)}
384
+ onToggleItalic={runWithSelectionToolbarDismiss(props.onToggleItalic)}
385
+ onToggleUnderline={runWithSelectionToolbarDismiss(props.onToggleUnderline)}
386
+ onToggleStrikethrough={runWithSelectionToolbarDismiss(props.onToggleStrikethrough)}
387
+ onToggleSuperscript={runWithSelectionToolbarDismiss(props.onToggleSuperscript)}
388
+ onToggleSubscript={runWithSelectionToolbarDismiss(props.onToggleSubscript)}
389
+ onSetFontFamily={props.onSetFontFamily
390
+ ? (fontFamily) => {
391
+ dismissSelectionToolbar();
392
+ props.onSetFontFamily?.(fontFamily);
393
+ }
394
+ : undefined}
395
+ onSetFontSize={props.onSetFontSize
396
+ ? (fontSize) => {
397
+ dismissSelectionToolbar();
398
+ props.onSetFontSize?.(fontSize);
399
+ }
400
+ : undefined}
401
+ onSetTextColor={props.onSetTextColor
402
+ ? (color) => {
403
+ dismissSelectionToolbar();
404
+ props.onSetTextColor?.(color);
405
+ }
406
+ : undefined}
407
+ onSetHighlightColor={props.onSetHighlightColor
408
+ ? (color) => {
409
+ dismissSelectionToolbar();
410
+ props.onSetHighlightColor?.(color);
411
+ }
412
+ : undefined}
413
+ onSetAlignment={props.onSetAlignment
414
+ ? (alignment) => {
415
+ dismissSelectionToolbar();
416
+ props.onSetAlignment?.(alignment);
417
+ }
418
+ : undefined}
419
+ onToggleBulletedList={runWithSelectionToolbarDismiss(props.onToggleBulletedList)}
420
+ onToggleNumberedList={runWithSelectionToolbarDismiss(props.onToggleNumberedList)}
421
+ onOutdent={runWithSelectionToolbarDismiss(props.onOutdent)}
422
+ onIndent={runWithSelectionToolbarDismiss(props.onIndent)}
423
+ onAddComment={runWithSelectionToolbarDismiss(props.onAddComment)}
424
+ onInsertPageBreak={runWithSelectionToolbarDismiss(props.onInsertPageBreak)}
425
+ onInsertTable={runWithSelectionToolbarDismiss(props.onInsertTable)}
426
+ onInsertSectionBreak={props.onInsertSectionBreak
427
+ ? (type) => {
428
+ dismissSelectionToolbar();
429
+ props.onInsertSectionBreak?.(type);
430
+ }
431
+ : undefined}
432
+ onInsertImage={props.onInsertImage
433
+ ? (options) => {
434
+ dismissSelectionToolbar();
435
+ props.onInsertImage?.(options);
436
+ }
437
+ : undefined}
438
+ onExport={runWithSelectionToolbarDismiss(props.onExport)}
439
+ activeStory={snapshot.activeStory}
440
+ onCloseStory={props.onCloseStory
441
+ ? runWithSelectionToolbarDismiss(props.onCloseStory)
442
+ : undefined}
443
+ onWorkspaceModeChange={(value) => {
444
+ dismissSelectionToolbar();
445
+ props.onWorkspaceModeChange(value);
446
+ }}
447
+ onZoomChange={props.onZoomChange
448
+ ? (level) => {
449
+ dismissSelectionToolbar();
450
+ props.onZoomChange?.(level);
451
+ }
452
+ : undefined}
453
+ onRestartNumbering={runWithSelectionToolbarDismiss(props.onRestartNumbering)}
454
+ onContinueNumbering={runWithSelectionToolbarDismiss(props.onContinueNumbering)}
455
+ onUpdateFields={runWithSelectionToolbarDismiss(props.onUpdateFields)}
456
+ onUpdateTableOfContents={runWithSelectionToolbarDismiss(props.onUpdateTableOfContents)}
457
+ onShowTrackedChangesChange={(show) => {
458
+ dismissSelectionToolbar();
459
+ props.onShowTrackedChangesChange(show);
460
+ }}
461
+ />
462
+ </div>
463
+ ) : null}
464
+
465
+ {chromePreset === "review" && chromeOptions.showReviewQueueBar && props.reviewQueue ? (
466
+ <TwReviewQueueBar
467
+ queue={props.reviewQueue}
468
+ onPrevious={props.onGoToPreviousReviewItem
469
+ ? runWithSelectionToolbarDismiss(props.onGoToPreviousReviewItem)
470
+ : undefined}
471
+ onNext={props.onGoToNextReviewItem
472
+ ? runWithSelectionToolbarDismiss(props.onGoToNextReviewItem)
473
+ : undefined}
474
+ onMarkSection={chromeOptions.showSectionTagAction && props.onMarkSectionForReview
475
+ ? runWithSelectionToolbarDismiss(props.onMarkSectionForReview)
476
+ : undefined}
477
+ />
478
+ ) : null}
479
+
480
+ {chromeVisibility.alerts ? <TwAlertBanner
481
+ snapshot={snapshot}
482
+ preserveOnlyCount={preserveOnlyCount}
483
+ workflowBlockedReasons={blockedReasons}
484
+ /> : null}
485
+
486
+ <div className="flex flex-1 min-h-0">
487
+ {/* Collapsible document navigator — page mode only */}
488
+ {isPageWorkspace && chromeVisibility.pageChrome ? (
489
+ <aside
490
+ aria-label="Document navigator"
491
+ className={`shrink-0 border-r border-border bg-surface transition-[width] duration-200 ${
492
+ navOpen ? "w-48" : "w-0"
493
+ } overflow-hidden`}
494
+ >
495
+ {navOpen ? (
496
+ <div className="flex h-full flex-col">
497
+ <div className="flex items-center justify-between px-3 py-2 border-b border-border">
498
+ <span className="text-xs font-medium text-secondary uppercase tracking-wider">Navigator</span>
499
+ <Tooltip.Root>
500
+ <Tooltip.Trigger asChild>
501
+ <button
502
+ type="button"
503
+ aria-label="Collapse navigator"
504
+ onMouseDown={preserveEditorSelectionMouseDown}
505
+ onClick={() => {
506
+ dismissSelectionToolbar();
507
+ setNavOpen(false);
508
+ }}
509
+ className="inline-flex h-6 w-6 items-center justify-center rounded-md text-secondary hover:bg-surface-hover transition-colors"
510
+ >
511
+ <ChevronLeft className="h-3.5 w-3.5" />
512
+ </button>
513
+ </Tooltip.Trigger>
514
+ <Tooltip.Portal>
515
+ <Tooltip.Content className="rounded-md bg-primary px-2 py-1 text-xs text-white shadow-md z-50" sideOffset={6}>
516
+ Collapse navigator
517
+ </Tooltip.Content>
518
+ </Tooltip.Portal>
519
+ </Tooltip.Root>
520
+ </div>
521
+ <nav className="flex-1 overflow-y-auto px-2 py-2" aria-label="Document headings">
522
+ {headings.length > 0 ? (
523
+ <ul className="space-y-0.5">
524
+ {headings.map((entry) => (
525
+ <li key={entry.headingId}>
526
+ <button
527
+ type="button"
528
+ className="block w-full truncate rounded-md px-2 py-1 text-left text-xs text-primary hover:bg-surface-hover"
529
+ style={{ paddingLeft: `${8 + (entry.level - 1) * 12}px` }}
530
+ onMouseDown={preserveEditorSelectionMouseDown}
531
+ onClick={() => {
532
+ dismissSelectionToolbar();
533
+ props.onNavigateHeading?.(entry.headingId);
534
+ setNavOpen(false);
535
+ }}
536
+ >
537
+ {entry.text}
538
+ </button>
539
+ </li>
540
+ ))}
541
+ </ul>
542
+ ) : (
543
+ <p className="px-2 py-4 text-xs text-tertiary">No headings found.</p>
544
+ )}
545
+ </nav>
546
+ </div>
547
+ ) : null}
548
+ </aside>
549
+ ) : null}
550
+
551
+ {/* Navigator expand toggle — page mode only when collapsed */}
552
+ {isPageWorkspace && chromeVisibility.pageChrome && !navOpen ? (
553
+ <div className="shrink-0 flex items-start pt-2 pl-1">
554
+ <Tooltip.Root>
555
+ <Tooltip.Trigger asChild>
556
+ <button
557
+ type="button"
558
+ aria-label="Open document navigator"
559
+ onMouseDown={preserveEditorSelectionMouseDown}
560
+ onClick={() => {
561
+ dismissSelectionToolbar();
562
+ setNavOpen(true);
563
+ }}
564
+ className="inline-flex h-7 w-7 items-center justify-center rounded-md text-secondary hover:bg-surface-hover transition-colors"
565
+ >
566
+ <List className="h-3.5 w-3.5" />
567
+ </button>
568
+ </Tooltip.Trigger>
569
+ <Tooltip.Portal>
570
+ <Tooltip.Content className="rounded-md bg-primary px-2 py-1 text-xs text-white shadow-md z-50" sideOffset={6}>
571
+ Open document navigator
572
+ </Tooltip.Content>
573
+ </Tooltip.Portal>
574
+ </Tooltip.Root>
575
+ </div>
576
+ ) : null}
577
+
578
+ {/* Document column */}
579
+ <div className="flex flex-1 flex-col min-w-0">
580
+ <div
581
+ className="flex-1 overflow-y-auto bg-surface"
582
+ data-wre-scroll-root="true"
583
+ >
584
+ <div
585
+ ref={selectionToolbarRootRef}
586
+ className={`mx-auto min-h-full w-full ${
587
+ isPageWorkspace
588
+ ? "wre-page-chrome wre-page-surface relative max-w-[840px] my-8 overflow-hidden"
589
+ : "wre-canvas-surface relative my-8 overflow-hidden"
590
+ }`}
591
+ data-zoom-bucket={pageZoomBucket}
592
+ style={isPageWorkspace && zoomScale !== 1 ? { transform: `scale(${zoomScale})`, transformOrigin: "top center" } : undefined}
593
+ >
594
+ {isPageWorkspace && chromeVisibility.pageChrome && snapshot.pageLayout ? (
595
+ <div className="border-b border-border/70 bg-surface/65 px-5 py-3" data-testid="page-context-summary">
596
+ <div className="flex flex-wrap items-center justify-between gap-2">
597
+ <div className="flex flex-wrap items-center gap-2 text-xs text-secondary">
598
+ <span className="rounded-full bg-canvas px-2 py-1 font-medium text-primary">
599
+ {activePage
600
+ ? `Page ${activePage.pageIndex + 1} of ${props.documentNavigation?.pageCount ?? 1}`
601
+ : "Page workspace"}
602
+ </span>
603
+ <span>{`Section ${snapshot.pageLayout.sectionIndex + 1}`}</span>
604
+ <span className="uppercase tracking-[0.12em] text-tertiary">
605
+ {snapshot.pageLayout.orientation}
606
+ </span>
607
+ </div>
608
+ <div className="flex items-center gap-2">
609
+ {snapshot.activeStory.kind !== "main" ? (
610
+ <button
611
+ type="button"
612
+ aria-label="Return to document body"
613
+ onMouseDown={preserveEditorSelectionMouseDown}
614
+ onClick={runWithSelectionToolbarDismiss(props.onCloseStory)}
615
+ className="inline-flex items-center gap-1 rounded-md border border-border bg-canvas px-2 py-1 text-xs font-medium text-primary transition-colors hover:bg-surface"
616
+ >
617
+ Body
618
+ </button>
619
+ ) : null}
620
+ {snapshot.activeStory.kind === "main" && snapshot.pageLayout.sectionIndex > 0 ? (
621
+ <>
622
+ <button
623
+ type="button"
624
+ aria-label="Link header to previous"
625
+ disabled={!props.onSetHeaderFooterLink || !allowLocalChromeMutations}
626
+ onMouseDown={preserveEditorSelectionMouseDown}
627
+ onClick={() => {
628
+ dismissSelectionToolbar();
629
+ props.onSetHeaderFooterLink?.(snapshot.pageLayout!.sectionIndex, {
630
+ kind: "header",
631
+ variant: headerVariant,
632
+ linkToPrevious: true,
633
+ });
634
+ }}
635
+ className="inline-flex items-center gap-1 rounded-md border border-border bg-canvas px-2 py-1 text-xs font-medium text-primary transition-colors hover:bg-surface disabled:cursor-not-allowed disabled:opacity-40"
636
+ >
637
+ Link header
638
+ </button>
639
+ <button
640
+ type="button"
641
+ aria-label="Link footer to previous"
642
+ disabled={!props.onSetHeaderFooterLink || !allowLocalChromeMutations}
643
+ onMouseDown={preserveEditorSelectionMouseDown}
644
+ onClick={() => {
645
+ dismissSelectionToolbar();
646
+ props.onSetHeaderFooterLink?.(snapshot.pageLayout!.sectionIndex, {
647
+ kind: "footer",
648
+ variant: footerVariant,
649
+ linkToPrevious: true,
650
+ });
651
+ }}
652
+ className="inline-flex items-center gap-1 rounded-md border border-border bg-canvas px-2 py-1 text-xs font-medium text-primary transition-colors hover:bg-surface disabled:cursor-not-allowed disabled:opacity-40"
653
+ >
654
+ Link footer
655
+ </button>
656
+ </>
657
+ ) : null}
658
+ <button
659
+ type="button"
660
+ aria-label="Toggle layout tools"
661
+ aria-expanded={layoutToolsOpen}
662
+ onMouseDown={preserveEditorSelectionMouseDown}
663
+ onClick={() => {
664
+ dismissSelectionToolbar();
665
+ setLayoutToolsOpen((open) => !open);
666
+ }}
667
+ className="inline-flex items-center gap-1 rounded-md border border-border bg-canvas px-2 py-1 text-xs font-medium text-primary transition-colors hover:bg-surface"
668
+ >
669
+ <ChevronRight className={`h-3.5 w-3.5 transition-transform ${layoutToolsOpen ? "rotate-90" : ""}`} />
670
+ Layout tools
671
+ </button>
672
+ </div>
673
+ </div>
674
+ </div>
675
+ ) : null}
676
+ {isPageWorkspace && chromeVisibility.pageChrome && snapshot.pageLayout && layoutToolsOpen ? (
677
+ <div className="px-5 pt-3">
678
+ <TwPageRuler
679
+ pageLayout={snapshot.pageLayout}
680
+ viewState={viewState}
681
+ paragraphLayout={activeParagraphLayout}
682
+ readOnly={pageChromeReadOnly}
683
+ onReturnToBody={props.onCloseStory
684
+ ? runWithSelectionToolbarDismiss(props.onCloseStory)
685
+ : () => undefined}
686
+ onOpenHeader={props.onOpenHeaderStory
687
+ ? runWithSelectionToolbarDismiss(props.onOpenHeaderStory)
688
+ : undefined}
689
+ onOpenFooter={props.onOpenFooterStory
690
+ ? runWithSelectionToolbarDismiss(props.onOpenFooterStory)
691
+ : undefined}
692
+ onSetIndentation={props.onSetParagraphIndentation
693
+ ? (indentation) => {
694
+ dismissSelectionToolbar();
695
+ props.onSetParagraphIndentation?.(indentation);
696
+ }
697
+ : undefined}
698
+ onSetTabStops={props.onSetParagraphTabStops
699
+ ? (tabStops) => {
700
+ dismissSelectionToolbar();
701
+ props.onSetParagraphTabStops?.(tabStops);
702
+ }
703
+ : undefined}
704
+ onRestartNumbering={props.onRestartNumbering
705
+ ? runWithSelectionToolbarDismiss(props.onRestartNumbering)
706
+ : undefined}
707
+ onContinueNumbering={props.onContinueNumbering
708
+ ? runWithSelectionToolbarDismiss(props.onContinueNumbering)
709
+ : undefined}
710
+ />
711
+ <TwLayoutPanel
712
+ pageLayout={snapshot.pageLayout}
713
+ readOnly={pageChromeReadOnly}
714
+ onInsertSectionBreak={props.onInsertSectionBreak
715
+ ? (type) => {
716
+ dismissSelectionToolbar();
717
+ props.onInsertSectionBreak?.(type);
718
+ }
719
+ : undefined}
720
+ onDeleteSectionBreak={props.onDeleteSectionBreak
721
+ ? (sectionIndex) => {
722
+ dismissSelectionToolbar();
723
+ props.onDeleteSectionBreak?.(sectionIndex);
724
+ }
725
+ : undefined}
726
+ onUpdateSectionLayout={props.onUpdateSectionLayout
727
+ ? (sectionIndex, patch) => {
728
+ dismissSelectionToolbar();
729
+ props.onUpdateSectionLayout?.(sectionIndex, patch);
730
+ }
731
+ : undefined}
732
+ onSetSectionPageNumbering={props.onSetSectionPageNumbering
733
+ ? (sectionIndex, patch) => {
734
+ dismissSelectionToolbar();
735
+ props.onSetSectionPageNumbering?.(sectionIndex, patch);
736
+ }
737
+ : undefined}
738
+ />
739
+ </div>
740
+ ) : null}
741
+ {chromeVisibility.selectionOverlay && gatedSelectionTool ? (
742
+ <TwSelectionToolHost
743
+ tool={gatedSelectionTool}
744
+ contextAnalytics={
745
+ chromeVisibility.contextAnalytics
746
+ ? props.selectionContextAnalytics
747
+ : null
748
+ }
749
+ placement={selectionToolbarPlacement}
750
+ rootRef={props.selectionToolbarRef}
751
+ onFocusCapture={props.onSelectionToolbarFocusCapture}
752
+ onBlurCapture={props.onSelectionToolbarBlurCapture}
753
+ onToggleBold={props.onToggleBold}
754
+ onToggleItalic={props.onToggleItalic}
755
+ onToggleUnderline={props.onToggleUnderline}
756
+ onSetTextColor={props.onSetSelectionTextColor}
757
+ onSetHighlightColor={props.onSetSelectionHighlightColor}
758
+ onAddComment={
759
+ gatedSelectionTool.kind === "suggestion-review"
760
+ ? (props.onAddCommentFromSuggestion ?? props.onAddComment)
761
+ : (props.onAddCommentFromSelection ?? props.onAddComment)
762
+ }
763
+ onAcceptSuggestion={props.onAcceptSuggestion}
764
+ onRejectSuggestion={props.onRejectSuggestion}
765
+ onEditSuggestion={props.onEditSuggestion}
766
+ onSetTableStyle={props.onSetTableStyle}
767
+ onAddRowBefore={props.onAddRowBefore}
768
+ onAddRowAfter={props.onAddRowAfter}
769
+ onAddColumnBefore={props.onAddColumnBefore}
770
+ onAddColumnAfter={props.onAddColumnAfter}
771
+ onDeleteRow={props.onDeleteRow}
772
+ onDeleteColumn={props.onDeleteColumn}
773
+ onDeleteTable={props.onDeleteTable}
774
+ onMergeCells={props.onMergeCells}
775
+ onSplitCell={props.onSplitCell}
776
+ onSetCellBackground={props.onSetCellBackground}
777
+ onSetImageLayout={props.onSetImageLayout}
778
+ onSetImageFrame={props.onSetImageFrame}
779
+ onRestartNumbering={props.onRestartNumbering}
780
+ onContinueNumbering={props.onContinueNumbering}
781
+ />
782
+ ) : null}
783
+ <div
784
+ className={isPageWorkspace ? "relative" : undefined}
785
+ data-line-numbering={pageChromeModel.lineNumberingEnabled ? "enabled" : "disabled"}
786
+ >
787
+ {isPageWorkspace && chromeVisibility.pageChrome && pageChromeModel.lineNumberingEnabled ? (
788
+ <div
789
+ aria-hidden="true"
790
+ className="pointer-events-none absolute inset-y-0 left-0 z-10"
791
+ data-testid="page-line-number-gutter"
792
+ style={{ width: `${pageChromeModel.gutterWidthPx}px` }}
793
+ >
794
+ {pageChromeModel.lineMarkers.map((marker) => (
795
+ <span
796
+ key={marker.id}
797
+ className="absolute right-2 font-[family-name:var(--font-legal-sans)] text-[10px] font-medium tabular-nums tracking-[0.12em] text-tertiary/80"
798
+ style={{ top: `${marker.topPx}px` }}
799
+ >
800
+ {marker.label}
801
+ </span>
802
+ ))}
803
+ </div>
804
+ ) : null}
805
+ <div
806
+ className={isPageWorkspace && chromeVisibility.pageChrome && pageChromeModel.lineNumberingEnabled ? "pl-12" : undefined}
807
+ style={isPageWorkspace ? pageShellMetrics.contentInsetStyle : undefined}
808
+ >
809
+ <div
810
+ className={isPageWorkspace ? "relative" : undefined}
811
+ data-document-grid={pageChromeModel.documentGridType}
812
+ data-page-border-display={pageChromeModel.pageBorderDisplay}
813
+ style={isPageWorkspace
814
+ ? {
815
+ ...pageChromeModel.documentGridStyle,
816
+ ...pageShellMetrics.pageFrameStyle,
817
+ }
818
+ : pageChromeModel.documentGridStyle}
819
+ >
820
+ {isPageWorkspace && chromeVisibility.pageChrome ? (
821
+ <div
822
+ data-testid="page-header-band"
823
+ className="relative z-10 flex items-center justify-between border-b border-border/50 bg-surface/45 px-4 text-[11px] text-secondary backdrop-blur-[1px]"
824
+ style={pageShellMetrics.headerBandStyle}
825
+ >
826
+ <span className="uppercase tracking-[0.12em] text-tertiary">{headerBandLabel}</span>
827
+ {snapshot.pageLayout?.headerVariants[0] ? (
828
+ <button
829
+ type="button"
830
+ aria-label="Open header story"
831
+ onClick={props.onOpenHeaderStory}
832
+ className="rounded-md px-2 py-1 text-xs font-medium text-primary transition-colors hover:bg-surface"
833
+ >
834
+ Edit header
835
+ </button>
836
+ ) : null}
837
+ </div>
838
+ ) : null}
839
+ {isPageWorkspace && chromeVisibility.pageChrome && pageChromeModel.showPageBorder && !hidePageBorderForActiveEditing ? (
840
+ <div
841
+ aria-hidden="true"
842
+ className="pointer-events-none absolute inset-0 z-0 rounded-[2px]"
843
+ data-testid="page-border-overlay"
844
+ style={pageChromeModel.pageBorderStyle}
845
+ />
846
+ ) : null}
847
+ <div className={isPageWorkspace ? "relative z-10" : undefined}>
848
+ {props.document}
849
+ </div>
850
+ {isPageWorkspace && chromeVisibility.pageChrome ? (
851
+ <div
852
+ data-testid="page-footer-band"
853
+ className="relative z-10 flex items-center justify-between border-t border-border/50 bg-surface/45 px-4 text-[11px] text-secondary backdrop-blur-[1px]"
854
+ style={pageShellMetrics.footerBandStyle}
855
+ >
856
+ <span className="uppercase tracking-[0.12em] text-tertiary">{footerBandLabel}</span>
857
+ {snapshot.pageLayout?.footerVariants[0] ? (
858
+ <button
859
+ type="button"
860
+ aria-label="Open footer story"
861
+ onClick={props.onOpenFooterStory}
862
+ className="rounded-md px-2 py-1 text-xs font-medium text-primary transition-colors hover:bg-surface"
863
+ >
864
+ Edit footer
865
+ </button>
866
+ ) : null}
867
+ </div>
868
+ ) : null}
869
+ </div>
870
+ </div>
871
+ </div>
872
+ </div>
873
+ </div>
874
+
875
+ {chromeVisibility.statusBar ? (
876
+ <TwStatusBar
877
+ isDirty={snapshot.isDirty}
878
+ isExportBlocked={snapshot.compatibility.blockExport}
879
+ preserveOnlyCount={preserveOnlyCount}
880
+ commentCount={snapshot.comments.totalCount}
881
+ changeCount={snapshot.trackedChanges.totalCount}
882
+ sessionId={snapshot.sessionId}
883
+ contextAnalytics={
884
+ chromeVisibility.contextAnalytics
885
+ ? props.documentContextAnalytics
886
+ : null
887
+ }
888
+ />
889
+ ) : null}
890
+ </div>
891
+
892
+ {/* Review rail — hidden in editing mode unless toggled */}
893
+ {showReviewRail ? <TwReviewRail
894
+ activeTab={props.activeRailTab}
895
+ currentUserId={props.currentUserId}
896
+ comments={snapshot.comments}
897
+ trackedChanges={snapshot.trackedChanges}
898
+ compatibility={snapshot.compatibility}
899
+ warnings={snapshot.warnings}
900
+ markupDisplay={markupDisplay}
901
+ contextAnalytics={
902
+ chromeVisibility.contextAnalytics
903
+ ? props.currentScopeContextAnalytics
904
+ : null
905
+ }
906
+ activeCommentId={props.activeCommentId}
907
+ activeRevisionId={props.activeRevisionId}
908
+ onActiveTabChange={props.onActiveRailTabChange}
909
+ onOpenComment={props.onOpenComment}
910
+ onResolveComment={props.onResolveComment}
911
+ onReopenComment={props.onReopenComment}
912
+ onAddReply={props.onAddReply}
913
+ onEditBody={props.onEditBody}
914
+ onOpenRevision={props.onOpenRevision}
915
+ onAcceptRevision={props.onAcceptRevision}
916
+ onRejectRevision={props.onRejectRevision}
917
+ onAcceptAllChanges={props.onAcceptAllChanges}
918
+ onRejectAllChanges={props.onRejectAllChanges}
919
+ /> : null}
920
+ </div>
921
+ </div>
922
+ </Tooltip.Provider>
923
+ );
924
+ }
925
+
926
+ function shouldHidePageBorderForSelection(
927
+ selection: EditorViewStateSnapshot["selection"],
928
+ ): boolean {
929
+ if (selection.isCollapsed) {
930
+ return false;
931
+ }
932
+
933
+ return selection.activeRange.kind === "range";
934
+ }
935
+
936
+ function resolveActiveParagraphLayout(
937
+ surface: RuntimeRenderSnapshot["surface"],
938
+ position: number,
939
+ ): {
940
+ leftIndent: number;
941
+ rightIndent: number;
942
+ firstLineOffset: number;
943
+ tabStops: Array<{ pos: number; val?: string; leader?: string }>;
944
+ indentationReadOnly?: boolean;
945
+ tabStopsReadOnly?: boolean;
946
+ } | null {
947
+ const paragraph = surface ? findActiveParagraph(surface.blocks, position) : null;
948
+ if (!paragraph) {
949
+ return null;
950
+ }
951
+ const resolvedIndentation = paragraph.resolvedNumbering?.geometry.indentation;
952
+ const resolvedTabStops = paragraph.resolvedNumbering?.geometry.tabStops;
953
+ const indentation = resolvedIndentation ?? paragraph.indentation;
954
+ const tabStops = resolvedTabStops ?? paragraph.tabStops;
955
+
956
+ return {
957
+ leftIndent: indentation?.left ?? 0,
958
+ rightIndent: indentation?.right ?? 0,
959
+ firstLineOffset:
960
+ indentation?.firstLine ??
961
+ (indentation?.hanging ? -indentation.hanging : 0),
962
+ tabStops: tabStops ? [...tabStops] : [],
963
+ indentationReadOnly:
964
+ Boolean(resolvedIndentation) &&
965
+ !areIndentationsEqual(resolvedIndentation, paragraph.indentation),
966
+ tabStopsReadOnly:
967
+ Boolean(resolvedTabStops) &&
968
+ !areTabStopsEqual(resolvedTabStops, paragraph.tabStops),
969
+ };
970
+ }
971
+
972
+ function areIndentationsEqual(
973
+ left:
974
+ | Extract<SurfaceBlockSnapshot, { kind: "paragraph" }>["indentation"]
975
+ | undefined,
976
+ right:
977
+ | Extract<SurfaceBlockSnapshot, { kind: "paragraph" }>["indentation"]
978
+ | undefined,
979
+ ): boolean {
980
+ return (
981
+ left?.left === right?.left &&
982
+ left?.right === right?.right &&
983
+ left?.firstLine === right?.firstLine &&
984
+ left?.hanging === right?.hanging
985
+ );
986
+ }
987
+
988
+ function areTabStopsEqual(
989
+ left: ReadonlyArray<{ pos: number; val?: string; leader?: string }> | undefined,
990
+ right: ReadonlyArray<{ pos: number; val?: string; leader?: string }> | undefined,
991
+ ): boolean {
992
+ if (!left?.length && !right?.length) {
993
+ return true;
994
+ }
995
+ if (!left || !right || left.length !== right.length) {
996
+ return false;
997
+ }
998
+ return left.every(
999
+ (tabStop, index) =>
1000
+ tabStop.pos === right[index]?.pos &&
1001
+ tabStop.val === right[index]?.val &&
1002
+ tabStop.leader === right[index]?.leader,
1003
+ );
1004
+ }
1005
+
1006
+ function findActiveParagraph(
1007
+ blocks: readonly SurfaceBlockSnapshot[],
1008
+ position: number,
1009
+ ): Extract<SurfaceBlockSnapshot, { kind: "paragraph" }> | null {
1010
+ for (const block of blocks) {
1011
+ if (block.kind === "paragraph" && position >= block.from && position <= block.to) {
1012
+ return block;
1013
+ }
1014
+ if (block.kind === "table") {
1015
+ for (const row of block.rows) {
1016
+ for (const cell of row.cells) {
1017
+ const paragraph = findActiveParagraph(cell.content, position);
1018
+ if (paragraph) {
1019
+ return paragraph;
1020
+ }
1021
+ }
1022
+ }
1023
+ }
1024
+ if (block.kind === "sdt_block") {
1025
+ const paragraph = findActiveParagraph(block.children, position);
1026
+ if (paragraph) {
1027
+ return paragraph;
1028
+ }
1029
+ }
1030
+ }
1031
+ return null;
1032
+ }
1033
+
1034
+ interface PageChromeModel {
1035
+ lineNumberingEnabled: boolean;
1036
+ gutterWidthPx: number;
1037
+ lineMarkers: Array<{ id: string; label: string; topPx: number }>;
1038
+ showPageBorder: boolean;
1039
+ pageBorderDisplay: string;
1040
+ pageBorderStyle: CSSProperties | undefined;
1041
+ documentGridType: string;
1042
+ documentGridStyle: CSSProperties | undefined;
1043
+ }
1044
+
1045
+ const EMPTY_PAGE_CHROME_MODEL: PageChromeModel = {
1046
+ lineNumberingEnabled: false,
1047
+ gutterWidthPx: 0,
1048
+ lineMarkers: [],
1049
+ showPageBorder: false,
1050
+ pageBorderDisplay: "none",
1051
+ pageBorderStyle: undefined,
1052
+ documentGridType: "none",
1053
+ documentGridStyle: undefined,
1054
+ };
1055
+
1056
+ const DOCUMENT_CONTENT_TOP_PADDING_PX = 40;
1057
+
1058
+ interface PageShellMetrics {
1059
+ contentInsetStyle: CSSProperties;
1060
+ pageFrameStyle: CSSProperties;
1061
+ headerBandStyle: CSSProperties;
1062
+ footerBandStyle: CSSProperties;
1063
+ }
1064
+
1065
+ function buildPageChromeModel(
1066
+ surface: RuntimeRenderSnapshot["surface"] | undefined,
1067
+ pageLayout: RuntimeRenderSnapshot["pageLayout"] | undefined,
1068
+ navigation: DocumentNavigationSnapshot | undefined,
1069
+ activeStory: RuntimeRenderSnapshot["activeStory"],
1070
+ ): PageChromeModel {
1071
+ if (!surface || !pageLayout || !navigation || activeStory.kind !== "main") {
1072
+ return EMPTY_PAGE_CHROME_MODEL;
1073
+ }
1074
+
1075
+ const lineMarkers = computeLineMarkersIfEnabled({
1076
+ pageLayout,
1077
+ surfaceBlocks: surface.blocks,
1078
+ pages: navigation.pages,
1079
+ buildLineNumberMarkers,
1080
+ });
1081
+ const lineNumberingEnabled =
1082
+ Boolean(pageLayout.lineNumbering) && lineMarkers.length > 0;
1083
+ const distance = pageLayout.lineNumbering?.distance ?? 0;
1084
+ const gutterWidthPx = lineNumberingEnabled
1085
+ ? Math.max(40, Math.min(88, 24 + Math.round(distance * DEFAULT_PAGE_ESTIMATE_PX_PER_TWIP)))
1086
+ : 0;
1087
+ const showPageBorder = shouldRenderPageBorder(pageLayout, navigation.pages, navigation.activePageIndex);
1088
+
1089
+ return {
1090
+ lineNumberingEnabled,
1091
+ gutterWidthPx,
1092
+ lineMarkers,
1093
+ showPageBorder,
1094
+ pageBorderDisplay: pageLayout.pageBorders?.display ?? "none",
1095
+ pageBorderStyle: showPageBorder ? buildPageBorderStyle(pageLayout) : undefined,
1096
+ documentGridType: pageLayout.documentGrid?.type ?? "none",
1097
+ documentGridStyle: buildDocumentGridStyle(pageLayout.documentGrid),
1098
+ };
1099
+ }
1100
+
1101
+ function buildPageShellMetrics(
1102
+ pageLayout: RuntimeRenderSnapshot["pageLayout"] | undefined,
1103
+ ): PageShellMetrics {
1104
+ if (!pageLayout) {
1105
+ return {
1106
+ contentInsetStyle: {},
1107
+ pageFrameStyle: {},
1108
+ headerBandStyle: {},
1109
+ footerBandStyle: {},
1110
+ };
1111
+ }
1112
+
1113
+ const horizontalInsetPx = Math.max(
1114
+ 24,
1115
+ Math.min(120, Math.round(pageLayout.marginLeft * DEFAULT_PAGE_ESTIMATE_PX_PER_TWIP)),
1116
+ );
1117
+ const verticalInsetPx = Math.max(
1118
+ 24,
1119
+ Math.min(140, Math.round(pageLayout.marginTop * DEFAULT_PAGE_ESTIMATE_PX_PER_TWIP)),
1120
+ );
1121
+ const headerBandHeightPx = Math.max(
1122
+ 40,
1123
+ Math.min(96, Math.round(pageLayout.headerMargin * DEFAULT_PAGE_ESTIMATE_PX_PER_TWIP + 16)),
1124
+ );
1125
+ const footerBandHeightPx = Math.max(
1126
+ 40,
1127
+ Math.min(96, Math.round(pageLayout.footerMargin * DEFAULT_PAGE_ESTIMATE_PX_PER_TWIP + 16)),
1128
+ );
1129
+
1130
+ return {
1131
+ contentInsetStyle: {
1132
+ paddingLeft: `${horizontalInsetPx}px`,
1133
+ paddingRight: `${horizontalInsetPx}px`,
1134
+ paddingTop: `${Math.max(20, verticalInsetPx - 12)}px`,
1135
+ paddingBottom: `${Math.max(20, Math.round(pageLayout.marginBottom * DEFAULT_PAGE_ESTIMATE_PX_PER_TWIP) - 12)}px`,
1136
+ },
1137
+ pageFrameStyle: {
1138
+ backgroundColor: "var(--color-page-bg)",
1139
+ borderRadius: "8px",
1140
+ boxShadow: "0 24px 48px -32px rgba(15, 23, 42, 0.38), 0 8px 20px -18px rgba(15, 23, 42, 0.22)",
1141
+ border: "1px solid rgba(148, 163, 184, 0.2)",
1142
+ },
1143
+ headerBandStyle: {
1144
+ minHeight: `${headerBandHeightPx}px`,
1145
+ },
1146
+ footerBandStyle: {
1147
+ minHeight: `${footerBandHeightPx}px`,
1148
+ },
1149
+ };
1150
+ }
1151
+
1152
+ function resolvePageBandLabel(
1153
+ region: "header" | "footer",
1154
+ activeStory: RuntimeRenderSnapshot["activeStory"],
1155
+ ): string {
1156
+ const regionLabel = region === "header" ? "header" : "footer";
1157
+ let label: string;
1158
+ if (activeStory.kind !== region) {
1159
+ label = region === "header" ? "Header" : "Footer";
1160
+ } else {
1161
+ switch (activeStory.variant) {
1162
+ case "first":
1163
+ label = `First page ${regionLabel}`;
1164
+ break;
1165
+ case "even":
1166
+ label = `Even page ${regionLabel}`;
1167
+ break;
1168
+ default:
1169
+ label = `Default ${regionLabel}`;
1170
+ break;
1171
+ }
1172
+ }
1173
+ return label;
1174
+ }
1175
+
1176
+ function buildLineNumberMarkers(
1177
+ blocks: readonly SurfaceBlockSnapshot[],
1178
+ pages: ReadonlyArray<DocumentNavigationSnapshot["pages"][number]>,
1179
+ ): Array<{ id: string; label: string; topPx: number }> {
1180
+ const markers: Array<{ id: string; label: string; topPx: number }> = [];
1181
+ if (pages.length === 0) {
1182
+ return markers;
1183
+ }
1184
+
1185
+ let currentTopTwips = 0;
1186
+ let lineNumber = 1;
1187
+ let lastPageIndex = -1;
1188
+ let lastSectionIndex = -1;
1189
+
1190
+ for (const block of blocks) {
1191
+ const pageIndex = findPageForOffset(pages, block.from);
1192
+ const page = pages[pageIndex];
1193
+ if (!page) {
1194
+ continue;
1195
+ }
1196
+
1197
+ const lineNumbering = page.layout.lineNumbering;
1198
+ const restartMode = lineNumbering?.restart ?? "newPage";
1199
+ const restartStart = lineNumbering?.start ?? 1;
1200
+ const countBy = Math.max(1, lineNumbering?.countBy ?? 1);
1201
+ const columnWidth = getUsableColumnWidth(page.layout);
1202
+
1203
+ if (pageIndex !== lastPageIndex) {
1204
+ if (restartMode === "newPage" || lastPageIndex === -1) {
1205
+ lineNumber = restartStart;
1206
+ }
1207
+ lastPageIndex = pageIndex;
1208
+ }
1209
+ if (page.sectionIndex !== lastSectionIndex) {
1210
+ if (restartMode === "newSection" || lastSectionIndex === -1) {
1211
+ lineNumber = restartStart;
1212
+ }
1213
+ lastSectionIndex = page.sectionIndex;
1214
+ }
1215
+
1216
+ if (block.kind === "paragraph" && lineNumbering) {
1217
+ const lineCount = estimateParagraphLineCount(block, columnWidth);
1218
+ const lineHeight = estimateParagraphLineHeight(block);
1219
+ const suppress = block.suppressLineNumbers === true;
1220
+ for (let lineIndex = 0; lineIndex < lineCount; lineIndex += 1) {
1221
+ if (!suppress && (lineNumber - restartStart) % countBy === 0) {
1222
+ markers.push({
1223
+ id: `${block.blockId}-${lineIndex}`,
1224
+ label: String(lineNumber),
1225
+ topPx:
1226
+ DOCUMENT_CONTENT_TOP_PADDING_PX +
1227
+ (currentTopTwips + lineIndex * lineHeight) * DEFAULT_PAGE_ESTIMATE_PX_PER_TWIP,
1228
+ });
1229
+ }
1230
+ if (!suppress) {
1231
+ lineNumber += 1;
1232
+ }
1233
+ }
1234
+ }
1235
+
1236
+ currentTopTwips += estimateBlockHeight(block, columnWidth);
1237
+ }
1238
+
1239
+ return markers;
1240
+ }
1241
+
1242
+ function shouldRenderPageBorder(
1243
+ pageLayout: RuntimeRenderSnapshot["pageLayout"],
1244
+ pages: ReadonlyArray<DocumentNavigationSnapshot["pages"][number]>,
1245
+ activePageIndex: number,
1246
+ ): boolean {
1247
+ const display = pageLayout?.pageBorders?.display ?? "allPages";
1248
+ const activePage = pages[activePageIndex];
1249
+ if (!pageLayout?.pageBorders || !activePage) {
1250
+ return false;
1251
+ }
1252
+
1253
+ switch (display) {
1254
+ case "firstPage":
1255
+ return activePage.pageInSection === 0;
1256
+ case "notFirstPage":
1257
+ return activePage.pageInSection > 0;
1258
+ default:
1259
+ return true;
1260
+ }
1261
+ }
1262
+
1263
+ function buildPageBorderStyle(
1264
+ pageLayout: NonNullable<RuntimeRenderSnapshot["pageLayout"]>,
1265
+ ): CSSProperties | undefined {
1266
+ const pageBorders = pageLayout.pageBorders;
1267
+ if (!pageBorders) {
1268
+ return undefined;
1269
+ }
1270
+
1271
+ const leftInset = createInsetValue(
1272
+ pageBorders.left?.space,
1273
+ pageBorders.offsetFrom === "text"
1274
+ ? (pageLayout.marginLeft / Math.max(1, pageLayout.pageWidth)) * 100
1275
+ : 1.25,
1276
+ );
1277
+ const rightInset = createInsetValue(
1278
+ pageBorders.right?.space,
1279
+ pageBorders.offsetFrom === "text"
1280
+ ? (pageLayout.marginRight / Math.max(1, pageLayout.pageWidth)) * 100
1281
+ : 1.25,
1282
+ );
1283
+ const topInset = createInsetValue(
1284
+ pageBorders.top?.space,
1285
+ pageBorders.offsetFrom === "text"
1286
+ ? (pageLayout.marginTop / Math.max(1, pageLayout.pageHeight)) * 100
1287
+ : 1.5,
1288
+ );
1289
+ const bottomInset = createInsetValue(
1290
+ pageBorders.bottom?.space,
1291
+ pageBorders.offsetFrom === "text"
1292
+ ? (pageLayout.marginBottom / Math.max(1, pageLayout.pageHeight)) * 100
1293
+ : 1.5,
1294
+ );
1295
+
1296
+ return {
1297
+ top: topInset,
1298
+ right: rightInset,
1299
+ bottom: bottomInset,
1300
+ left: leftInset,
1301
+ borderTop: toBorderCss(pageBorders.top),
1302
+ borderRight: toBorderCss(pageBorders.right),
1303
+ borderBottom: toBorderCss(pageBorders.bottom),
1304
+ borderLeft: toBorderCss(pageBorders.left),
1305
+ boxSizing: "border-box",
1306
+ mixBlendMode: pageBorders.zOrder === "back" ? "multiply" : undefined,
1307
+ };
1308
+ }
1309
+
1310
+ function buildDocumentGridStyle(
1311
+ documentGrid: NonNullable<RuntimeRenderSnapshot["pageLayout"]>["documentGrid"] | undefined,
1312
+ ): CSSProperties | undefined {
1313
+ if (!documentGrid || !documentGrid.type || documentGrid.type === "default") {
1314
+ return undefined;
1315
+ }
1316
+
1317
+ const linePitchPx = Math.max(
1318
+ 18,
1319
+ Math.round((documentGrid.linePitch ?? 360) * DEFAULT_PAGE_ESTIMATE_PX_PER_TWIP),
1320
+ );
1321
+ const charSpacePx = Math.max(
1322
+ 12,
1323
+ Math.round((documentGrid.charSpace ?? 204) * DEFAULT_PAGE_ESTIMATE_PX_PER_TWIP),
1324
+ );
1325
+ const gridColor = "rgba(15, 23, 42, 0.06)";
1326
+ const backgrounds: string[] = [];
1327
+
1328
+ if (
1329
+ documentGrid.type === "lines" ||
1330
+ documentGrid.type === "linesAndChars" ||
1331
+ documentGrid.type === "snapToChars"
1332
+ ) {
1333
+ backgrounds.push(
1334
+ `repeating-linear-gradient(to bottom, ${gridColor} 0, ${gridColor} 1px, transparent 1px, transparent ${linePitchPx}px)`,
1335
+ );
1336
+ }
1337
+ if (
1338
+ documentGrid.type === "linesAndChars" ||
1339
+ documentGrid.type === "snapToChars"
1340
+ ) {
1341
+ backgrounds.push(
1342
+ `repeating-linear-gradient(to right, rgba(15, 23, 42, 0.04) 0, rgba(15, 23, 42, 0.04) 1px, transparent 1px, transparent ${charSpacePx}px)`,
1343
+ );
1344
+ }
1345
+
1346
+ if (backgrounds.length === 0) {
1347
+ return undefined;
1348
+ }
1349
+
1350
+ return {
1351
+ backgroundImage: backgrounds.join(", "),
1352
+ backgroundOrigin: "content-box",
1353
+ };
1354
+ }
1355
+
1356
+ function createInsetValue(spaceTwips: number | undefined, percent: number): string {
1357
+ const spacingPx = Math.max(0, Math.round((spaceTwips ?? 0) * DEFAULT_PAGE_ESTIMATE_PX_PER_TWIP));
1358
+ return `calc(${percent.toFixed(2)}% + ${spacingPx}px)`;
1359
+ }
1360
+
1361
+ function resolveSelectionToolbarPlacement(
1362
+ anchor: SelectionToolAnchor | null | undefined,
1363
+ root: HTMLDivElement | null,
1364
+ zoomScale: number,
1365
+ ): { placement: "right" | "left" | "above" | "below"; style: CSSProperties } | null {
1366
+ if (!anchor || !root) {
1367
+ return null;
1368
+ }
1369
+
1370
+ const rootRect = root.getBoundingClientRect();
1371
+ if (rootRect.width <= 0 || rootRect.height <= 0 || zoomScale <= 0) {
1372
+ return null;
1373
+ }
1374
+
1375
+ const centerX = (anchor.left + anchor.right) / 2;
1376
+ const centerY = (anchor.top + anchor.bottom) / 2;
1377
+ const localLeftEdge = (anchor.left - rootRect.left) / zoomScale;
1378
+ const localRightEdge = (anchor.right - rootRect.left) / zoomScale;
1379
+ const localLeft = (centerX - rootRect.left) / zoomScale;
1380
+ const localCenterY = (centerY - rootRect.top) / zoomScale;
1381
+ const localTop = (anchor.top - rootRect.top) / zoomScale;
1382
+ const localBottom = (anchor.bottom - rootRect.top) / zoomScale;
1383
+ const edgePadding = 16 / zoomScale;
1384
+ const containerWidth = rootRect.width / zoomScale;
1385
+ const containerHeight = rootRect.height / zoomScale;
1386
+ const gapPx = 12 / zoomScale;
1387
+ const estimatedToolbarWidth = Math.min(260 / zoomScale, Math.max(168 / zoomScale, containerWidth * 0.32));
1388
+ const estimatedToolbarHeight = 44 / zoomScale;
1389
+ const clampedCenterLeft = Math.max(
1390
+ edgePadding,
1391
+ Math.min(localLeft, Math.max(edgePadding, containerWidth - edgePadding)),
1392
+ );
1393
+ const clampedCenterY = Math.max(
1394
+ edgePadding + estimatedToolbarHeight / 2,
1395
+ Math.min(localCenterY, Math.max(edgePadding + estimatedToolbarHeight / 2, containerHeight - edgePadding - estimatedToolbarHeight / 2)),
1396
+ );
1397
+ const rightClearance = containerWidth - localRightEdge - gapPx - edgePadding;
1398
+ const leftClearance = localLeftEdge - gapPx - edgePadding;
1399
+
1400
+ if (rightClearance >= estimatedToolbarWidth) {
1401
+ return {
1402
+ placement: "right",
1403
+ style: {
1404
+ left: `${localRightEdge}px`,
1405
+ top: `${clampedCenterY}px`,
1406
+ maxWidth: `${Math.max(220, containerWidth - edgePadding * 2)}px`,
1407
+ transform: `translate(${gapPx}px, -50%)`,
1408
+ },
1409
+ };
1410
+ }
1411
+
1412
+ if (leftClearance >= estimatedToolbarWidth) {
1413
+ return {
1414
+ placement: "left",
1415
+ style: {
1416
+ left: `${localLeftEdge}px`,
1417
+ top: `${clampedCenterY}px`,
1418
+ maxWidth: `${Math.max(220, containerWidth - edgePadding * 2)}px`,
1419
+ transform: `translate(calc(-100% - ${gapPx}px), -50%)`,
1420
+ },
1421
+ };
1422
+ }
1423
+
1424
+ const placement = localTop < estimatedToolbarHeight + gapPx + edgePadding ? "below" : "above";
1425
+
1426
+ return {
1427
+ placement,
1428
+ style: {
1429
+ left: `${clampedCenterLeft}px`,
1430
+ top: `${placement === "above" ? localTop : localBottom}px`,
1431
+ maxWidth: `${Math.max(220, containerWidth - edgePadding * 2)}px`,
1432
+ transform:
1433
+ placement === "above"
1434
+ ? `translate(-50%, calc(-100% - ${gapPx}px))`
1435
+ : `translate(-50%, ${gapPx}px)`,
1436
+ },
1437
+ };
1438
+ }
1439
+
1440
+ function toBorderCss(
1441
+ border:
1442
+ | NonNullable<NonNullable<RuntimeRenderSnapshot["pageLayout"]>["pageBorders"]>["top"]
1443
+ | undefined,
1444
+ ): string | undefined {
1445
+ if (!border || border.value === "none" || border.value === "nil") {
1446
+ return undefined;
1447
+ }
1448
+
1449
+ const width = border.size ? `${Math.max(1, Math.round(border.size / 8))}px` : "1px";
1450
+ const style =
1451
+ border.value === "double"
1452
+ ? "double"
1453
+ : border.value === "dotted"
1454
+ ? "dotted"
1455
+ : border.value === "dashed" || border.value === "dashSmallGap"
1456
+ ? "dashed"
1457
+ : "solid";
1458
+ const color = border.color && border.color !== "auto" ? `#${border.color}` : "rgba(31, 31, 31, 0.28)";
1459
+ return `${width} ${style} ${color}`;
1460
+ }