@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
@@ -1,161 +1,270 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/core/commands/section-layout-commands.ts
21
- var section_layout_commands_exports = {};
22
- __export(section_layout_commands_exports, {
23
- deleteSectionBreak: () => deleteSectionBreak,
24
- deleteSectionBreakAtSectionIndex: () => deleteSectionBreakAtSectionIndex,
25
- insertSectionBreak: () => insertSectionBreak,
26
- insertSectionBreakAfterSectionIndex: () => insertSectionBreakAfterSectionIndex,
27
- setHeaderFooterLinkAtSectionIndex: () => setHeaderFooterLinkAtSectionIndex,
28
- setSectionPageNumberingAtSectionIndex: () => setSectionPageNumberingAtSectionIndex,
29
- updateSectionLayout: () => updateSectionLayout,
30
- updateSectionLayoutAtSectionIndex: () => updateSectionLayoutAtSectionIndex
31
- });
32
- module.exports = __toCommonJS(section_layout_commands_exports);
33
- function insertSectionBreak(document, snapshot, breakType, _context) {
34
- const cloned = structuredClone(document);
1
+ /**
2
+ * Section layout authoring commands.
3
+ *
4
+ * Supports inserting and deleting section breaks, bounded section layout
5
+ * updates (page size, margins, gutter, orientation, columns, first-page /
6
+ * odd-even variants, page-numbering restart / format), and section break
7
+ * deletion with following-section merge semantics.
8
+ *
9
+ * All mutations are command-backed and export-safe.
10
+ */
11
+ import type {
12
+ RuntimeRenderSnapshot,
13
+ SelectionSnapshot,
14
+ } from "../../api/public-types";
15
+ import type {
16
+ CanonicalDocument as CanonicalDocumentEnvelope,
17
+ ColumnProperties,
18
+ PageMargins,
19
+ PageNumbering,
20
+ PageSize,
21
+ SectionBreakNode,
22
+ SectionProperties,
23
+ } from "../../model/canonical-document.ts";
24
+
25
+ // ---- Public types ----
26
+
27
+ export interface SectionLayoutCommandContext {
28
+ timestamp: string;
29
+ }
30
+
31
+ export interface SectionLayoutMutationResult {
32
+ document: CanonicalDocumentEnvelope;
33
+ selection: SelectionSnapshot;
34
+ changed: boolean;
35
+ }
36
+
37
+ export type SectionBreakType =
38
+ | "nextPage"
39
+ | "continuous"
40
+ | "evenPage"
41
+ | "oddPage"
42
+ | "nextColumn";
43
+
44
+ export interface SectionLayoutPatch {
45
+ pageSize?: Partial<PageSize>;
46
+ pageMargins?: Partial<PageMargins>;
47
+ columns?: Partial<ColumnProperties>;
48
+ pageNumbering?: Partial<PageNumbering>;
49
+ titlePage?: boolean;
50
+ sectionType?: SectionBreakType;
51
+ }
52
+
53
+ export interface SectionLinkPatch {
54
+ kind: "header" | "footer";
55
+ variant: "default" | "first" | "even";
56
+ linkToPrevious: boolean;
57
+ relationshipId?: string | null;
58
+ }
59
+
60
+ // ---- Insert section break ----
61
+
62
+ /**
63
+ * Insert a section break at the current selection position.
64
+ * The new section inherits properties from the section that contained the
65
+ * insertion point (the *following* section keeps its own properties).
66
+ */
67
+ export function insertSectionBreak(
68
+ document: CanonicalDocumentEnvelope,
69
+ snapshot: RuntimeRenderSnapshot,
70
+ breakType: SectionBreakType,
71
+ _context: SectionLayoutCommandContext,
72
+ ): SectionLayoutMutationResult {
73
+ const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
35
74
  const surface = snapshot.surface;
75
+
36
76
  if (!surface) {
37
77
  return noopResult(document, snapshot.selection);
38
78
  }
79
+
39
80
  const position = snapshot.selection.head;
40
81
  const blockIndex = resolveBlockIndexForPosition(surface.blocks, position);
82
+
41
83
  if (blockIndex < 0) {
42
84
  return noopResult(document, snapshot.selection);
43
85
  }
86
+
44
87
  const sectionTarget = resolveSectionTarget(cloned, surface.blocks, position);
45
88
  const inheritedProperties = cloneSectionProperties(sectionTarget?.properties);
46
- const sectionBreak = {
89
+ const sectionBreak: SectionBreakNode = {
47
90
  type: "section_break",
48
91
  sectionProperties: {
49
92
  ...inheritedProperties,
50
- sectionType: breakType
51
- }
93
+ sectionType: breakType,
94
+ },
52
95
  };
96
+
53
97
  cloned.content.children.splice(blockIndex + 1, 0, sectionBreak);
54
98
  cloned.updatedAt = _context.timestamp;
99
+
55
100
  return {
56
101
  document: cloned,
57
102
  selection: snapshot.selection,
58
- changed: true
103
+ changed: true,
59
104
  };
60
105
  }
61
- function insertSectionBreakAfterSectionIndex(document, sectionIndex, breakType, context) {
62
- const cloned = structuredClone(document);
106
+
107
+ export function insertSectionBreakAfterSectionIndex(
108
+ document: CanonicalDocumentEnvelope,
109
+ sectionIndex: number,
110
+ breakType: SectionBreakType,
111
+ context: SectionLayoutCommandContext,
112
+ ): SectionLayoutMutationResult {
113
+ const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
63
114
  const insertionIndex = findSectionInsertionIndex(cloned, sectionIndex);
64
115
  if (insertionIndex < 0) {
65
116
  return noopResult(document, createSelectionSnapshot(0, 0));
66
117
  }
118
+
67
119
  const inheritedProperties = cloneSectionProperties(
68
- getSectionPropertiesAtIndex(cloned, sectionIndex)
120
+ getSectionPropertiesAtIndex(cloned, sectionIndex),
69
121
  );
70
- const sectionBreak = {
122
+ const sectionBreak: SectionBreakNode = {
71
123
  type: "section_break",
72
124
  sectionProperties: {
73
125
  ...inheritedProperties,
74
- sectionType: breakType
75
- }
126
+ sectionType: breakType,
127
+ },
76
128
  };
129
+
77
130
  cloned.content.children.splice(insertionIndex, 0, sectionBreak);
78
131
  cloned.updatedAt = context.timestamp;
132
+
79
133
  return {
80
134
  document: cloned,
81
135
  selection: createSelectionSnapshot(0, 0),
82
- changed: true
136
+ changed: true,
83
137
  };
84
138
  }
85
- function deleteSectionBreak(document, snapshot, _context) {
86
- const cloned = structuredClone(document);
139
+
140
+ // ---- Delete section break ----
141
+
142
+ /**
143
+ * Delete the section break at or nearest to the current selection position.
144
+ * On deletion the *following* section's formatting and header/footer linkage
145
+ * are adopted (Word merge semantics).
146
+ */
147
+ export function deleteSectionBreak(
148
+ document: CanonicalDocumentEnvelope,
149
+ snapshot: RuntimeRenderSnapshot,
150
+ _context: SectionLayoutCommandContext,
151
+ ): SectionLayoutMutationResult {
152
+ const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
153
+
87
154
  const breakIndex = findNearestSectionBreak(cloned, snapshot);
88
155
  if (breakIndex < 0) {
89
156
  return noopResult(document, snapshot.selection);
90
157
  }
158
+
91
159
  const breakNode = cloned.content.children[breakIndex];
92
160
  if (!breakNode || breakNode.type !== "section_break") {
93
161
  return noopResult(document, snapshot.selection);
94
162
  }
163
+
164
+ // Remove the section break node
95
165
  cloned.content.children.splice(breakIndex, 1);
166
+
96
167
  cloned.updatedAt = _context.timestamp;
168
+
97
169
  return {
98
170
  document: cloned,
99
171
  selection: snapshot.selection,
100
- changed: true
172
+ changed: true,
101
173
  };
102
174
  }
103
- function deleteSectionBreakAtSectionIndex(document, sectionIndex, context) {
175
+
176
+ export function deleteSectionBreakAtSectionIndex(
177
+ document: CanonicalDocumentEnvelope,
178
+ sectionIndex: number,
179
+ context: SectionLayoutCommandContext,
180
+ ): SectionLayoutMutationResult {
104
181
  if (sectionIndex <= 0) {
105
182
  return noopResult(document, createSelectionSnapshot(0, 0));
106
183
  }
107
- const cloned = structuredClone(document);
184
+
185
+ const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
108
186
  const breakIndex = findSectionBreakNodeIndexForSection(cloned, sectionIndex);
109
187
  if (breakIndex < 0) {
110
188
  return noopResult(document, createSelectionSnapshot(0, 0));
111
189
  }
190
+
112
191
  cloned.content.children.splice(breakIndex, 1);
113
192
  cloned.updatedAt = context.timestamp;
193
+
114
194
  return {
115
195
  document: cloned,
116
196
  selection: createSelectionSnapshot(0, 0),
117
- changed: true
197
+ changed: true,
118
198
  };
119
199
  }
120
- function updateSectionLayout(document, snapshot, patch, _context) {
121
- const cloned = structuredClone(document);
200
+
201
+ // ---- Update section layout ----
202
+
203
+ /**
204
+ * Apply a bounded layout patch to the section containing the current selection.
205
+ * Supports: page size, margins, gutter, orientation, columns,
206
+ * first-page / odd-even variants, page-numbering restart / format.
207
+ */
208
+ export function updateSectionLayout(
209
+ document: CanonicalDocumentEnvelope,
210
+ snapshot: RuntimeRenderSnapshot,
211
+ patch: SectionLayoutPatch,
212
+ _context: SectionLayoutCommandContext,
213
+ ): SectionLayoutMutationResult {
214
+ const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
122
215
  const surface = snapshot.surface;
216
+
123
217
  if (!surface) {
124
218
  return noopResult(document, snapshot.selection);
125
219
  }
220
+
126
221
  const position = snapshot.selection.head;
127
222
  const sectionTarget = resolveSectionTarget(cloned, surface.blocks, position);
223
+
128
224
  if (!sectionTarget) {
129
225
  return noopResult(document, snapshot.selection);
130
226
  }
227
+
131
228
  const existing = sectionTarget.properties ?? {};
132
229
  const updated = applySectionLayoutPatch(existing, patch);
230
+
133
231
  if (sectionTarget.kind === "inline") {
134
232
  const breakNode = cloned.content.children[sectionTarget.blockIndex];
135
233
  if (breakNode && breakNode.type === "section_break") {
136
234
  breakNode.sectionProperties = updated;
235
+ // Clear raw XML so the structured properties are used on export
137
236
  delete breakNode.sectionPropertiesXml;
138
237
  delete breakNode.propertiesXml;
139
238
  }
140
239
  } else {
240
+ // Final section: update subParts.finalSectionProperties
141
241
  if (!cloned.subParts) {
142
242
  return noopResult(document, snapshot.selection);
143
243
  }
144
244
  cloned.subParts.finalSectionProperties = updated;
145
245
  }
246
+
146
247
  cloned.updatedAt = _context.timestamp;
248
+
147
249
  return {
148
250
  document: cloned,
149
251
  selection: snapshot.selection,
150
- changed: true
252
+ changed: true,
151
253
  };
152
254
  }
153
- function updateSectionLayoutAtSectionIndex(document, sectionIndex, patch, context) {
154
- const cloned = structuredClone(document);
255
+
256
+ export function updateSectionLayoutAtSectionIndex(
257
+ document: CanonicalDocumentEnvelope,
258
+ sectionIndex: number,
259
+ patch: SectionLayoutPatch,
260
+ context: SectionLayoutCommandContext,
261
+ ): SectionLayoutMutationResult {
262
+ const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
155
263
  const target = resolveSectionPropertiesOwner(cloned, sectionIndex);
156
264
  if (!target) {
157
265
  return noopResult(document, createSelectionSnapshot(0, 0));
158
266
  }
267
+
159
268
  const updated = applySectionLayoutPatch(target.properties ?? {}, patch);
160
269
  if (target.kind === "inline") {
161
270
  const breakNode = cloned.content.children[target.blockIndex];
@@ -166,35 +275,44 @@ function updateSectionLayoutAtSectionIndex(document, sectionIndex, patch, contex
166
275
  }
167
276
  } else {
168
277
  cloned.subParts = {
169
- ...cloned.subParts ?? {
278
+ ...(cloned.subParts ?? {
170
279
  headers: [],
171
- footers: []
172
- },
173
- finalSectionProperties: updated
280
+ footers: [],
281
+ }),
282
+ finalSectionProperties: updated,
174
283
  };
175
284
  }
285
+
176
286
  cloned.updatedAt = context.timestamp;
177
287
  return {
178
288
  document: cloned,
179
289
  selection: createSelectionSnapshot(0, 0),
180
- changed: true
290
+ changed: true,
181
291
  };
182
292
  }
183
- function setSectionPageNumberingAtSectionIndex(document, sectionIndex, pageNumbering, context) {
184
- const cloned = structuredClone(document);
293
+
294
+ export function setSectionPageNumberingAtSectionIndex(
295
+ document: CanonicalDocumentEnvelope,
296
+ sectionIndex: number,
297
+ pageNumbering: Partial<PageNumbering> | null,
298
+ context: SectionLayoutCommandContext,
299
+ ): SectionLayoutMutationResult {
300
+ const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
185
301
  const target = resolveSectionPropertiesOwner(cloned, sectionIndex);
186
302
  if (!target) {
187
303
  return noopResult(document, createSelectionSnapshot(0, 0));
188
304
  }
305
+
189
306
  const nextProperties = cloneSectionProperties(target.properties);
190
307
  if (pageNumbering === null) {
191
308
  delete nextProperties.pageNumbering;
192
309
  } else {
193
310
  nextProperties.pageNumbering = {
194
- ...target.properties?.pageNumbering ?? {},
195
- ...pageNumbering
311
+ ...(target.properties?.pageNumbering ?? {}),
312
+ ...pageNumbering,
196
313
  };
197
314
  }
315
+
198
316
  if (target.kind === "inline") {
199
317
  const breakNode = cloned.content.children[target.blockIndex];
200
318
  if (breakNode && breakNode.type === "section_break") {
@@ -204,44 +322,59 @@ function setSectionPageNumberingAtSectionIndex(document, sectionIndex, pageNumbe
204
322
  }
205
323
  } else {
206
324
  cloned.subParts = {
207
- ...cloned.subParts ?? {
325
+ ...(cloned.subParts ?? {
208
326
  headers: [],
209
- footers: []
210
- },
211
- finalSectionProperties: nextProperties
327
+ footers: [],
328
+ }),
329
+ finalSectionProperties: nextProperties,
212
330
  };
213
331
  }
332
+
214
333
  cloned.updatedAt = context.timestamp;
215
334
  return {
216
335
  document: cloned,
217
336
  selection: createSelectionSnapshot(0, 0),
218
- changed: true
337
+ changed: true,
219
338
  };
220
339
  }
221
- function setHeaderFooterLinkAtSectionIndex(document, sectionIndex, patch, context) {
222
- const cloned = structuredClone(document);
340
+
341
+ export function setHeaderFooterLinkAtSectionIndex(
342
+ document: CanonicalDocumentEnvelope,
343
+ sectionIndex: number,
344
+ patch: SectionLinkPatch,
345
+ context: SectionLayoutCommandContext,
346
+ ): SectionLayoutMutationResult {
347
+ const cloned = structuredClone(document) as CanonicalDocumentEnvelope;
223
348
  const target = resolveSectionPropertiesOwner(cloned, sectionIndex);
224
349
  if (!target) {
225
350
  return noopResult(document, createSelectionSnapshot(0, 0));
226
351
  }
227
- const referencesKey = patch.kind === "header" ? "headerReferences" : "footerReferences";
352
+
353
+ const referencesKey =
354
+ patch.kind === "header" ? "headerReferences" : "footerReferences";
228
355
  const currentProperties = cloneSectionProperties(target.properties);
229
- const currentReferences = [...currentProperties?.[referencesKey] ?? []];
356
+ const currentReferences = [...(currentProperties?.[referencesKey] ?? [])];
230
357
  const nextReferences = currentReferences.filter((entry) => entry.variant !== patch.variant);
358
+
231
359
  if (!patch.linkToPrevious) {
232
- const relationshipId = normalizeRelationshipId(patch.relationshipId) ?? resolveInheritedRelationshipId(cloned, sectionIndex, patch.kind, patch.variant);
360
+ const relationshipId =
361
+ normalizeRelationshipId(patch.relationshipId) ??
362
+ resolveInheritedRelationshipId(cloned, sectionIndex, patch.kind, patch.variant);
233
363
  if (!relationshipId) {
234
364
  return noopResult(document, createSelectionSnapshot(0, 0));
235
365
  }
366
+
236
367
  nextReferences.push({
237
368
  variant: patch.variant,
238
- relationshipId
369
+ relationshipId,
239
370
  });
240
371
  }
372
+
241
373
  const nextProperties = {
242
- ...currentProperties ?? {},
243
- [referencesKey]: nextReferences.length > 0 ? nextReferences : void 0
374
+ ...(currentProperties ?? {}),
375
+ [referencesKey]: nextReferences.length > 0 ? nextReferences : undefined,
244
376
  };
377
+
245
378
  if (target.kind === "inline") {
246
379
  const breakNode = cloned.content.children[target.blockIndex];
247
380
  if (breakNode && breakNode.type === "section_break") {
@@ -251,24 +384,32 @@ function setHeaderFooterLinkAtSectionIndex(document, sectionIndex, patch, contex
251
384
  }
252
385
  } else {
253
386
  cloned.subParts = {
254
- ...cloned.subParts ?? {
387
+ ...(cloned.subParts ?? {
255
388
  headers: [],
256
- footers: []
257
- },
258
- finalSectionProperties: nextProperties
389
+ footers: [],
390
+ }),
391
+ finalSectionProperties: nextProperties,
259
392
  };
260
393
  }
394
+
261
395
  cloned.updatedAt = context.timestamp;
262
396
  return {
263
397
  document: cloned,
264
398
  selection: createSelectionSnapshot(0, 0),
265
- changed: true
399
+ changed: true,
266
400
  };
267
401
  }
268
- function noopResult(document, selection) {
402
+
403
+ // ---- Helpers ----
404
+
405
+ function noopResult(
406
+ document: CanonicalDocumentEnvelope,
407
+ selection: SelectionSnapshot,
408
+ ): SectionLayoutMutationResult {
269
409
  return { document, selection, changed: false };
270
410
  }
271
- function createSelectionSnapshot(anchor, head) {
411
+
412
+ function createSelectionSnapshot(anchor: number, head: number): SelectionSnapshot {
272
413
  return {
273
414
  anchor,
274
415
  head,
@@ -279,12 +420,16 @@ function createSelectionSnapshot(anchor, head) {
279
420
  to: Math.max(anchor, head),
280
421
  assoc: {
281
422
  start: -1,
282
- end: 1
283
- }
284
- }
423
+ end: 1,
424
+ },
425
+ },
285
426
  };
286
427
  }
287
- function resolveBlockIndexForPosition(blocks, position) {
428
+
429
+ function resolveBlockIndexForPosition(
430
+ blocks: ReadonlyArray<{ from: number; to: number }>,
431
+ position: number,
432
+ ): number {
288
433
  for (let i = blocks.length - 1; i >= 0; i--) {
289
434
  const block = blocks[i];
290
435
  if (block && position >= block.from) {
@@ -293,10 +438,21 @@ function resolveBlockIndexForPosition(blocks, position) {
293
438
  }
294
439
  return blocks.length > 0 ? 0 : -1;
295
440
  }
296
- function findSectionBreakNodeIndexForSection(document, sectionIndex) {
441
+
442
+ interface SectionTarget {
443
+ kind: "inline" | "final";
444
+ blockIndex: number;
445
+ properties?: SectionProperties;
446
+ }
447
+
448
+ function findSectionBreakNodeIndexForSection(
449
+ document: CanonicalDocumentEnvelope,
450
+ sectionIndex: number,
451
+ ): number {
297
452
  if (sectionIndex <= 0) {
298
453
  return -1;
299
454
  }
455
+
300
456
  let currentSection = 0;
301
457
  for (let index = 0; index < document.content.children.length; index += 1) {
302
458
  const block = document.content.children[index];
@@ -308,9 +464,14 @@ function findSectionBreakNodeIndexForSection(document, sectionIndex) {
308
464
  return index;
309
465
  }
310
466
  }
467
+
311
468
  return -1;
312
469
  }
313
- function findSectionInsertionIndex(document, sectionIndex) {
470
+
471
+ function findSectionInsertionIndex(
472
+ document: CanonicalDocumentEnvelope,
473
+ sectionIndex: number,
474
+ ): number {
314
475
  let currentSection = 0;
315
476
  for (let index = 0; index < document.content.children.length; index += 1) {
316
477
  const block = document.content.children[index];
@@ -322,16 +483,26 @@ function findSectionInsertionIndex(document, sectionIndex) {
322
483
  }
323
484
  currentSection += 1;
324
485
  }
486
+
325
487
  return sectionIndex === currentSection ? document.content.children.length : -1;
326
488
  }
327
- function getSectionPropertiesAtIndex(document, sectionIndex) {
489
+
490
+ function getSectionPropertiesAtIndex(
491
+ document: CanonicalDocumentEnvelope,
492
+ sectionIndex: number,
493
+ ): SectionProperties | undefined {
328
494
  const target = resolveSectionPropertiesOwner(document, sectionIndex);
329
495
  return target?.properties;
330
496
  }
331
- function resolveSectionPropertiesOwner(document, sectionIndex) {
497
+
498
+ function resolveSectionPropertiesOwner(
499
+ document: CanonicalDocumentEnvelope,
500
+ sectionIndex: number,
501
+ ): SectionTarget | null {
332
502
  if (sectionIndex < 0) {
333
503
  return null;
334
504
  }
505
+
335
506
  let currentSection = 0;
336
507
  for (let index = 0; index < document.content.children.length; index += 1) {
337
508
  const block = document.content.children[index];
@@ -342,65 +513,94 @@ function resolveSectionPropertiesOwner(document, sectionIndex) {
342
513
  return {
343
514
  kind: "inline",
344
515
  blockIndex: index,
345
- properties: block.sectionProperties
516
+ properties: block.sectionProperties,
346
517
  };
347
518
  }
348
519
  currentSection += 1;
349
520
  }
350
- return currentSection === sectionIndex ? {
351
- kind: "final",
352
- blockIndex: document.content.children.length - 1,
353
- properties: document.subParts?.finalSectionProperties
354
- } : null;
521
+
522
+ return currentSection === sectionIndex
523
+ ? {
524
+ kind: "final",
525
+ blockIndex: document.content.children.length - 1,
526
+ properties: document.subParts?.finalSectionProperties,
527
+ }
528
+ : null;
355
529
  }
356
- function normalizeRelationshipId(value) {
530
+
531
+ function normalizeRelationshipId(value: string | null | undefined): string | undefined {
357
532
  if (typeof value !== "string") {
358
- return void 0;
533
+ return undefined;
359
534
  }
360
535
  const trimmed = value.trim();
361
- return trimmed.length > 0 ? trimmed : void 0;
536
+ return trimmed.length > 0 ? trimmed : undefined;
362
537
  }
363
- function resolveInheritedRelationshipId(document, sectionIndex, kind, variant) {
538
+
539
+ function resolveInheritedRelationshipId(
540
+ document: CanonicalDocumentEnvelope,
541
+ sectionIndex: number,
542
+ kind: "header" | "footer",
543
+ variant: "default" | "first" | "even",
544
+ ): string | undefined {
364
545
  for (let candidateIndex = sectionIndex - 1; candidateIndex >= 0; candidateIndex -= 1) {
365
546
  const properties = getSectionPropertiesAtIndex(document, candidateIndex);
366
- const references = kind === "header" ? properties?.headerReferences : properties?.footerReferences;
547
+ const references =
548
+ kind === "header" ? properties?.headerReferences : properties?.footerReferences;
367
549
  const directMatch = references?.find((entry) => entry.variant === variant);
368
550
  if (directMatch?.relationshipId) {
369
551
  return directMatch.relationshipId;
370
552
  }
371
553
  }
372
- const documents = kind === "header" ? document.subParts?.headers ?? [] : document.subParts?.footers ?? [];
554
+
555
+ const documents = kind === "header"
556
+ ? document.subParts?.headers ?? []
557
+ : document.subParts?.footers ?? [];
373
558
  return documents.find((entry) => entry.variant === variant)?.relationshipId;
374
559
  }
375
- function resolveSectionTarget(document, blocks, position) {
560
+
561
+ function resolveSectionTarget(
562
+ document: CanonicalDocumentEnvelope,
563
+ blocks: ReadonlyArray<{ from: number; to: number }>,
564
+ position: number,
565
+ ): SectionTarget | null {
376
566
  const blockIndex = resolveBlockIndexForPosition(blocks, position);
377
567
  if (blockIndex < 0) {
378
568
  return null;
379
569
  }
570
+
571
+ // Walk forward from the resolved block to find the next section break
380
572
  for (let i = blockIndex; i < document.content.children.length; i++) {
381
573
  const block = document.content.children[i];
382
574
  if (block && block.type === "section_break") {
383
575
  return {
384
576
  kind: "inline",
385
577
  blockIndex: i,
386
- properties: block.sectionProperties
578
+ properties: block.sectionProperties,
387
579
  };
388
580
  }
389
581
  }
582
+
583
+ // No section break found; this is the final section
390
584
  return {
391
585
  kind: "final",
392
586
  blockIndex: document.content.children.length - 1,
393
- properties: document.subParts?.finalSectionProperties
587
+ properties: document.subParts?.finalSectionProperties,
394
588
  };
395
589
  }
396
- function findNearestSectionBreak(document, snapshot) {
590
+
591
+ function findNearestSectionBreak(
592
+ document: CanonicalDocumentEnvelope,
593
+ snapshot: RuntimeRenderSnapshot,
594
+ ): number {
397
595
  const surface = snapshot.surface;
398
596
  if (!surface) {
399
597
  return -1;
400
598
  }
599
+
401
600
  const position = snapshot.selection.head;
402
601
  let bestIndex = -1;
403
602
  let bestDistance = Number.POSITIVE_INFINITY;
603
+
404
604
  for (let i = 0; i < document.content.children.length; i++) {
405
605
  const block = document.content.children[i];
406
606
  if (!block || block.type !== "section_break") {
@@ -412,66 +612,69 @@ function findNearestSectionBreak(document, snapshot) {
412
612
  }
413
613
  const distance = Math.min(
414
614
  Math.abs(position - surfaceBlock.from),
415
- Math.abs(position - surfaceBlock.to)
615
+ Math.abs(position - surfaceBlock.to),
416
616
  );
417
617
  if (distance < bestDistance) {
418
618
  bestDistance = distance;
419
619
  bestIndex = i;
420
620
  }
421
621
  }
622
+
422
623
  return bestIndex;
423
624
  }
424
- function applySectionLayoutPatch(existing, patch) {
425
- const result = { ...existing };
625
+
626
+ function applySectionLayoutPatch(
627
+ existing: SectionProperties,
628
+ patch: SectionLayoutPatch,
629
+ ): SectionProperties {
630
+ const result: SectionProperties = { ...existing };
631
+
426
632
  if (patch.pageSize) {
427
633
  result.pageSize = {
428
- ...existing.pageSize ?? { width: 12240, height: 15840 },
429
- ...patch.pageSize
634
+ ...(existing.pageSize ?? { width: 12240, height: 15840 }),
635
+ ...patch.pageSize,
430
636
  };
431
637
  }
638
+
432
639
  if (patch.pageMargins) {
433
640
  result.pageMargins = {
434
- ...existing.pageMargins ?? {
641
+ ...(existing.pageMargins ?? {
435
642
  top: 1440,
436
643
  right: 1440,
437
644
  bottom: 1440,
438
- left: 1440
439
- },
440
- ...patch.pageMargins
645
+ left: 1440,
646
+ }),
647
+ ...patch.pageMargins,
441
648
  };
442
649
  }
650
+
443
651
  if (patch.columns) {
444
652
  result.columns = {
445
- ...existing.columns ?? {},
446
- ...patch.columns
653
+ ...(existing.columns ?? {}),
654
+ ...patch.columns,
447
655
  };
448
656
  }
657
+
449
658
  if (patch.pageNumbering) {
450
659
  result.pageNumbering = {
451
- ...existing.pageNumbering ?? {},
452
- ...patch.pageNumbering
660
+ ...(existing.pageNumbering ?? {}),
661
+ ...patch.pageNumbering,
453
662
  };
454
663
  }
455
- if (patch.titlePage !== void 0) {
664
+
665
+ if (patch.titlePage !== undefined) {
456
666
  result.titlePage = patch.titlePage;
457
667
  }
458
- if (patch.sectionType !== void 0) {
668
+
669
+ if (patch.sectionType !== undefined) {
459
670
  result.sectionType = patch.sectionType;
460
671
  }
672
+
461
673
  return result;
462
674
  }
463
- function cloneSectionProperties(properties) {
675
+
676
+ function cloneSectionProperties(
677
+ properties: SectionProperties | undefined,
678
+ ): SectionProperties {
464
679
  return properties ? structuredClone(properties) : {};
465
680
  }
466
- // Annotate the CommonJS export names for ESM import in node:
467
- 0 && (module.exports = {
468
- deleteSectionBreak,
469
- deleteSectionBreakAtSectionIndex,
470
- insertSectionBreak,
471
- insertSectionBreakAfterSectionIndex,
472
- setHeaderFooterLinkAtSectionIndex,
473
- setSectionPageNumberingAtSectionIndex,
474
- updateSectionLayout,
475
- updateSectionLayoutAtSectionIndex
476
- });
477
- //# sourceMappingURL=section-layout-commands.cjs.map