@beyondwork/docx-react-component 1.0.29 → 1.0.31

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