@a3s-lab/office 0.1.0

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 (463) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +470 -0
  3. package/THIRD_PARTY_NOTICES.md +33 -0
  4. package/dist/0~1403.js +245 -0
  5. package/dist/0~152.js +94 -0
  6. package/dist/0~3539.js +1856 -0
  7. package/dist/0~3557.js +179 -0
  8. package/dist/0~3635.js +302 -0
  9. package/dist/0~4595.js +1162 -0
  10. package/dist/0~5050.js +308 -0
  11. package/dist/0~6552.js +787 -0
  12. package/dist/0~7048.js +2110 -0
  13. package/dist/0~7614.js +1037 -0
  14. package/dist/0~8155.js +299 -0
  15. package/dist/0~9445.js +283 -0
  16. package/dist/0~9512.js +743 -0
  17. package/dist/0~document-editor.js +10967 -0
  18. package/dist/0~markdown-editor.js +2260 -0
  19. package/dist/0~pdf-viewer.js +2156 -0
  20. package/dist/0~presentation-editor.js +8359 -0
  21. package/dist/0~rslib-runtime.js +27 -0
  22. package/dist/0~spreadsheet-editor.js +10388 -0
  23. package/dist/0~use-office-draft.js +46 -0
  24. package/dist/0~work-document-extensions.js +2470 -0
  25. package/dist/0~work-document-links.js +14 -0
  26. package/dist/0~work-document-model-codec.js +42 -0
  27. package/dist/0~work-document-page-color.js +11 -0
  28. package/dist/0~work-document-paragraph-formatting.js +425 -0
  29. package/dist/0~work-docx-bibliography.js +347 -0
  30. package/dist/0~work-docx-export.js +1151 -0
  31. package/dist/0~work-docx-import.js +3116 -0
  32. package/dist/0~work-docx-page-color.js +42 -0
  33. package/dist/0~work-office-diagnostics.js +1377 -0
  34. package/dist/0~work-pptx-export.js +1009 -0
  35. package/dist/0~work-pptx-import.js +1138 -0
  36. package/dist/0~work-presentation-charts.js +442 -0
  37. package/dist/0~work-presentation-transition.js +38 -0
  38. package/dist/0~work-presentation-visual-scale.js +38 -0
  39. package/dist/0~work-spreadsheet-formula-support.js +9 -0
  40. package/dist/1134.js +445 -0
  41. package/dist/4104.js +5786 -0
  42. package/dist/432.js +211 -0
  43. package/dist/4704.js +1364 -0
  44. package/dist/6489.js +182 -0
  45. package/dist/8715.js +3959 -0
  46. package/dist/8728.js +723 -0
  47. package/dist/9356.js +10 -0
  48. package/dist/core.d.ts +15 -0
  49. package/dist/core.js +4 -0
  50. package/dist/index.d.ts +2 -0
  51. package/dist/index.js +5 -0
  52. package/dist/internal/design-system/primitives/button/button.d.ts +9 -0
  53. package/dist/internal/design-system/primitives/button/icon-button.d.ts +7 -0
  54. package/dist/internal/design-system/primitives/dialog/dialog.d.ts +12 -0
  55. package/dist/internal/design-system/primitives/feedback/collection-state.d.ts +9 -0
  56. package/dist/internal/design-system/primitives/feedback/inline-notice.d.ts +10 -0
  57. package/dist/internal/design-system/primitives/feedback/state-view.d.ts +13 -0
  58. package/dist/internal/design-system/primitives/form/field.d.ts +19 -0
  59. package/dist/internal/design-system/primitives/index.d.ts +14 -0
  60. package/dist/internal/design-system/primitives/layout/split-handle.d.ts +17 -0
  61. package/dist/internal/design-system/primitives/navigation/segmented-control.d.ts +19 -0
  62. package/dist/internal/design-system/primitives/navigation/tab-navigation.d.ts +13 -0
  63. package/dist/internal/design-system/primitives/navigation/tabs.d.ts +21 -0
  64. package/dist/internal/design-system/primitives/overlay/dialog-focus-scope.d.ts +17 -0
  65. package/dist/internal/design-system/primitives/overlay/popover.d.ts +34 -0
  66. package/dist/internal/design-system/primitives/overlay/portal-root.d.ts +1 -0
  67. package/dist/internal/design-system/primitives/status/status-badge.d.ts +6 -0
  68. package/dist/internal/features/work/components/work-document-pages.d.ts +4 -0
  69. package/dist/internal/features/work/components/work-editor-agent-menus.d.ts +12 -0
  70. package/dist/internal/features/work/components/work-editor-loading-state.d.ts +3 -0
  71. package/dist/internal/features/work/editors/document-changes-panel.d.ts +9 -0
  72. package/dist/internal/features/work/editors/document-citation-source-form.d.ts +33 -0
  73. package/dist/internal/features/work/editors/document-citations-panel.d.ts +8 -0
  74. package/dist/internal/features/work/editors/document-columns-panel.d.ts +5 -0
  75. package/dist/internal/features/work/editors/document-comment-composer.d.ts +13 -0
  76. package/dist/internal/features/work/editors/document-comments-panel.d.ts +17 -0
  77. package/dist/internal/features/work/editors/document-editor-focus.d.ts +1 -0
  78. package/dist/internal/features/work/editors/document-editor-pagination.d.ts +3 -0
  79. package/dist/internal/features/work/editors/document-editor-support.d.ts +34 -0
  80. package/dist/internal/features/work/editors/document-editor.d.ts +20 -0
  81. package/dist/internal/features/work/editors/document-find-highlight.d.ts +8 -0
  82. package/dist/internal/features/work/editors/document-find-replace-panel.d.ts +10 -0
  83. package/dist/internal/features/work/editors/document-formatting-options.d.ts +113 -0
  84. package/dist/internal/features/work/editors/document-home-ribbon.d.ts +9 -0
  85. package/dist/internal/features/work/editors/document-layout-panel.d.ts +10 -0
  86. package/dist/internal/features/work/editors/document-list-gallery.d.ts +4 -0
  87. package/dist/internal/features/work/editors/document-navigation-panel.d.ts +9 -0
  88. package/dist/internal/features/work/editors/document-page-chrome-editor.d.ts +39 -0
  89. package/dist/internal/features/work/editors/document-page-chrome-panel.d.ts +5 -0
  90. package/dist/internal/features/work/editors/document-page-chrome-ribbon.d.ts +10 -0
  91. package/dist/internal/features/work/editors/document-page-navigation.d.ts +14 -0
  92. package/dist/internal/features/work/editors/document-page-stack.d.ts +8 -0
  93. package/dist/internal/features/work/editors/document-pagination-popover.d.ts +4 -0
  94. package/dist/internal/features/work/editors/document-paragraph-spacing-popover.d.ts +4 -0
  95. package/dist/internal/features/work/editors/document-picture-ribbon.d.ts +4 -0
  96. package/dist/internal/features/work/editors/document-ruler-tab-stops.d.ts +12 -0
  97. package/dist/internal/features/work/editors/document-ruler.d.ts +15 -0
  98. package/dist/internal/features/work/editors/document-selection-context-menu.d.ts +22 -0
  99. package/dist/internal/features/work/editors/document-selection-toolbar.d.ts +8 -0
  100. package/dist/internal/features/work/editors/document-status-bar.d.ts +19 -0
  101. package/dist/internal/features/work/editors/document-style-gallery.d.ts +4 -0
  102. package/dist/internal/features/work/editors/document-table-insert-popover.d.ts +4 -0
  103. package/dist/internal/features/work/editors/document-table-ribbon.d.ts +7 -0
  104. package/dist/internal/features/work/editors/document-task-pane.d.ts +11 -0
  105. package/dist/internal/features/work/editors/document-toolbar.d.ts +100 -0
  106. package/dist/internal/features/work/editors/document-vertical-ruler.d.ts +6 -0
  107. package/dist/internal/features/work/editors/markdown-editor-focus.d.ts +2 -0
  108. package/dist/internal/features/work/editors/markdown-editor.d.ts +16 -0
  109. package/dist/internal/features/work/editors/markdown-insert-dialog.d.ts +19 -0
  110. package/dist/internal/features/work/editors/markdown-selection-context-menu.d.ts +14 -0
  111. package/dist/internal/features/work/editors/markdown-source-commands.d.ts +41 -0
  112. package/dist/internal/features/work/editors/markdown-status.d.ts +7 -0
  113. package/dist/internal/features/work/editors/markdown-toolbar.d.ts +22 -0
  114. package/dist/internal/features/work/editors/markdown-workspace.d.ts +26 -0
  115. package/dist/internal/features/work/editors/office-checkbox.d.ts +9 -0
  116. package/dist/internal/features/work/editors/office-color-picker.d.ts +11 -0
  117. package/dist/internal/features/work/editors/office-controls.d.ts +7 -0
  118. package/dist/internal/features/work/editors/office-dialog.d.ts +35 -0
  119. package/dist/internal/features/work/editors/office-editor-extension.d.ts +86 -0
  120. package/dist/internal/features/work/editors/office-file-data.d.ts +1 -0
  121. package/dist/internal/features/work/editors/office-font-families.d.ts +187 -0
  122. package/dist/internal/features/work/editors/office-menu-keyboard.d.ts +2 -0
  123. package/dist/internal/features/work/editors/office-number-field.d.ts +21 -0
  124. package/dist/internal/features/work/editors/office-number-normalization.d.ts +9 -0
  125. package/dist/internal/features/work/editors/office-select.d.ts +19 -0
  126. package/dist/internal/features/work/editors/office-shortcuts.d.ts +1 -0
  127. package/dist/internal/features/work/editors/office-slider.d.ts +10 -0
  128. package/dist/internal/features/work/editors/office-table-dimensions.d.ts +4 -0
  129. package/dist/internal/features/work/editors/office-table-insert-popover.d.ts +7 -0
  130. package/dist/internal/features/work/editors/office-task-pane.d.ts +7 -0
  131. package/dist/internal/features/work/editors/office-text-field.d.ts +20 -0
  132. package/dist/internal/features/work/editors/office-tiptap-extensions.d.ts +2 -0
  133. package/dist/internal/features/work/editors/pdf-annotation-controller.d.ts +23 -0
  134. package/dist/internal/features/work/editors/pdf-editor-extensions.d.ts +36 -0
  135. package/dist/internal/features/work/editors/pdf-thumbnail-rail.d.ts +26 -0
  136. package/dist/internal/features/work/editors/pdf-toolbar.d.ts +23 -0
  137. package/dist/internal/features/work/editors/pdf-viewer-controller.d.ts +48 -0
  138. package/dist/internal/features/work/editors/pdf-viewer.d.ts +11 -0
  139. package/dist/internal/features/work/editors/presentation-arrangement-controller.d.ts +19 -0
  140. package/dist/internal/features/work/editors/presentation-chart-analysis-canvas.d.ts +21 -0
  141. package/dist/internal/features/work/editors/presentation-chart-axis-canvas.d.ts +33 -0
  142. package/dist/internal/features/work/editors/presentation-chart-axis-editor.d.ts +5 -0
  143. package/dist/internal/features/work/editors/presentation-chart-canvas.d.ts +5 -0
  144. package/dist/internal/features/work/editors/presentation-chart-cartesian-canvas.d.ts +3 -0
  145. package/dist/internal/features/work/editors/presentation-chart-data-label-editor.d.ts +6 -0
  146. package/dist/internal/features/work/editors/presentation-chart-data-labels.d.ts +26 -0
  147. package/dist/internal/features/work/editors/presentation-chart-layout-editor.d.ts +5 -0
  148. package/dist/internal/features/work/editors/presentation-chart-legend-canvas.d.ts +15 -0
  149. package/dist/internal/features/work/editors/presentation-chart-panel.d.ts +7 -0
  150. package/dist/internal/features/work/editors/presentation-chart-series-analysis-editor.d.ts +6 -0
  151. package/dist/internal/features/work/editors/presentation-chart-series-canvas.d.ts +15 -0
  152. package/dist/internal/features/work/editors/presentation-command-controller.d.ts +3 -0
  153. package/dist/internal/features/work/editors/presentation-command-types.d.ts +206 -0
  154. package/dist/internal/features/work/editors/presentation-comments-panel.d.ts +9 -0
  155. package/dist/internal/features/work/editors/presentation-context-menu.d.ts +11 -0
  156. package/dist/internal/features/work/editors/presentation-design-panel.d.ts +13 -0
  157. package/dist/internal/features/work/editors/presentation-editor-focus.d.ts +12 -0
  158. package/dist/internal/features/work/editors/presentation-editor-operations.d.ts +10 -0
  159. package/dist/internal/features/work/editors/presentation-editor-types.d.ts +22 -0
  160. package/dist/internal/features/work/editors/presentation-editor.d.ts +3 -0
  161. package/dist/internal/features/work/editors/presentation-keyboard-extension.d.ts +3 -0
  162. package/dist/internal/features/work/editors/presentation-player.d.ts +7 -0
  163. package/dist/internal/features/work/editors/presentation-presenter-view.d.ts +15 -0
  164. package/dist/internal/features/work/editors/presentation-selection.d.ts +21 -0
  165. package/dist/internal/features/work/editors/presentation-slide-canvas.d.ts +26 -0
  166. package/dist/internal/features/work/editors/presentation-slide-thumbnail.d.ts +18 -0
  167. package/dist/internal/features/work/editors/presentation-status-bar.d.ts +10 -0
  168. package/dist/internal/features/work/editors/presentation-text-editor.d.ts +22 -0
  169. package/dist/internal/features/work/editors/presentation-text-formatting.d.ts +3 -0
  170. package/dist/internal/features/work/editors/presentation-thumbnail-rail.d.ts +20 -0
  171. package/dist/internal/features/work/editors/presentation-toolbar.d.ts +19 -0
  172. package/dist/internal/features/work/editors/presentation-transition-panel.d.ts +9 -0
  173. package/dist/internal/features/work/editors/presentation-workspace.d.ts +38 -0
  174. package/dist/internal/features/work/editors/spreadsheet-calculation-model.d.ts +8 -0
  175. package/dist/internal/features/work/editors/spreadsheet-calculation-projection.d.ts +32 -0
  176. package/dist/internal/features/work/editors/spreadsheet-chart-axis-editor.d.ts +9 -0
  177. package/dist/internal/features/work/editors/spreadsheet-chart-draft.d.ts +17 -0
  178. package/dist/internal/features/work/editors/spreadsheet-chart-layout-editor.d.ts +13 -0
  179. package/dist/internal/features/work/editors/spreadsheet-chart-panel.d.ts +10 -0
  180. package/dist/internal/features/work/editors/spreadsheet-chart-series-style-editor.d.ts +9 -0
  181. package/dist/internal/features/work/editors/spreadsheet-clipboard-shortcuts.d.ts +9 -0
  182. package/dist/internal/features/work/editors/spreadsheet-command-controller.d.ts +121 -0
  183. package/dist/internal/features/work/editors/spreadsheet-conditional-comparison-fields.d.ts +7 -0
  184. package/dist/internal/features/work/editors/spreadsheet-conditional-format-model.d.ts +72 -0
  185. package/dist/internal/features/work/editors/spreadsheet-conditional-format-panel.d.ts +7 -0
  186. package/dist/internal/features/work/editors/spreadsheet-conditional-threshold-fields.d.ts +10 -0
  187. package/dist/internal/features/work/editors/spreadsheet-context-menu.d.ts +36 -0
  188. package/dist/internal/features/work/editors/spreadsheet-data-label-editor.d.ts +9 -0
  189. package/dist/internal/features/work/editors/spreadsheet-editor-ribbon.d.ts +46 -0
  190. package/dist/internal/features/work/editors/spreadsheet-editor-support.d.ts +31 -0
  191. package/dist/internal/features/work/editors/spreadsheet-editor.d.ts +16 -0
  192. package/dist/internal/features/work/editors/spreadsheet-error-bar-editor.d.ts +10 -0
  193. package/dist/internal/features/work/editors/spreadsheet-find-bar.d.ts +8 -0
  194. package/dist/internal/features/work/editors/spreadsheet-find.d.ts +9 -0
  195. package/dist/internal/features/work/editors/spreadsheet-formula-panel.d.ts +10 -0
  196. package/dist/internal/features/work/editors/spreadsheet-header-footer-fields.d.ts +5 -0
  197. package/dist/internal/features/work/editors/spreadsheet-keyboard-navigation.d.ts +18 -0
  198. package/dist/internal/features/work/editors/spreadsheet-number-format.d.ts +11 -0
  199. package/dist/internal/features/work/editors/spreadsheet-pivot-panel.d.ts +10 -0
  200. package/dist/internal/features/work/editors/spreadsheet-print-settings-panel.d.ts +6 -0
  201. package/dist/internal/features/work/editors/spreadsheet-protection-panel.d.ts +7 -0
  202. package/dist/internal/features/work/editors/spreadsheet-sheet-bar.d.ts +17 -0
  203. package/dist/internal/features/work/editors/spreadsheet-sheet-model.d.ts +13 -0
  204. package/dist/internal/features/work/editors/spreadsheet-trendline-editor.d.ts +8 -0
  205. package/dist/internal/features/work/editors/spreadsheet-workbook-panel.d.ts +16 -0
  206. package/dist/internal/features/work/editors/use-document-comments.d.ts +26 -0
  207. package/dist/internal/features/work/editors/use-document-insert-commands.d.ts +19 -0
  208. package/dist/internal/features/work/editors/use-document-layout-fonts.d.ts +2 -0
  209. package/dist/internal/features/work/editors/use-document-page-chrome.d.ts +33 -0
  210. package/dist/internal/features/work/editors/use-document-pagination.d.ts +46 -0
  211. package/dist/internal/features/work/editors/use-markdown-source-history.d.ts +16 -0
  212. package/dist/internal/features/work/editors/use-office-draft.d.ts +10 -0
  213. package/dist/internal/features/work/editors/use-office-editor-keyboard-shortcuts.d.ts +9 -0
  214. package/dist/internal/features/work/editors/use-office-editor-runtime.d.ts +6 -0
  215. package/dist/internal/features/work/editors/use-office-editor-wheel-zoom.d.ts +19 -0
  216. package/dist/internal/features/work/editors/use-office-history.d.ts +10 -0
  217. package/dist/internal/features/work/editors/use-presentation-clipboard.d.ts +22 -0
  218. package/dist/internal/features/work/editors/use-presentation-design-commands.d.ts +33 -0
  219. package/dist/internal/features/work/editors/use-presentation-element-commands.d.ts +29 -0
  220. package/dist/internal/features/work/editors/use-presentation-geometry.d.ts +17 -0
  221. package/dist/internal/features/work/editors/use-presentation-history.d.ts +12 -0
  222. package/dist/internal/features/work/editors/use-presentation-review-commands.d.ts +22 -0
  223. package/dist/internal/features/work/editors/use-presentation-selection.d.ts +11 -0
  224. package/dist/internal/features/work/editors/use-presentation-slide-commands.d.ts +18 -0
  225. package/dist/internal/features/work/editors/use-presentation-thumbnail-visibility.d.ts +4 -0
  226. package/dist/internal/features/work/editors/use-presentation-thumbnail-window.d.ts +17 -0
  227. package/dist/internal/features/work/editors/use-presentation-transform.d.ts +53 -0
  228. package/dist/internal/features/work/editors/use-spreadsheet-calculation.d.ts +17 -0
  229. package/dist/internal/features/work/editors/use-spreadsheet-workbook-sync.d.ts +10 -0
  230. package/dist/internal/features/work/editors/work-office-chrome.d.ts +61 -0
  231. package/dist/internal/features/work/editors/work-office-ribbon-overflow.d.ts +18 -0
  232. package/dist/internal/features/work/work-agent-proposal-apply.d.ts +8 -0
  233. package/dist/internal/features/work/work-agent-proposal.d.ts +55 -0
  234. package/dist/internal/features/work/work-agent-request.d.ts +6 -0
  235. package/dist/internal/features/work/work-chart-series-analysis-context.d.ts +3 -0
  236. package/dist/internal/features/work/work-document-caption-nodes.d.ts +13 -0
  237. package/dist/internal/features/work/work-document-captions.d.ts +14 -0
  238. package/dist/internal/features/work/work-document-changes.d.ts +35 -0
  239. package/dist/internal/features/work/work-document-character-formatting.d.ts +13 -0
  240. package/dist/internal/features/work/work-document-citation-nodes.d.ts +25 -0
  241. package/dist/internal/features/work/work-document-citations.d.ts +21 -0
  242. package/dist/internal/features/work/work-document-columns.d.ts +15 -0
  243. package/dist/internal/features/work/work-document-comments.d.ts +48 -0
  244. package/dist/internal/features/work/work-document-extensions.d.ts +11 -0
  245. package/dist/internal/features/work/work-document-field-node.d.ts +12 -0
  246. package/dist/internal/features/work/work-document-fields.d.ts +15 -0
  247. package/dist/internal/features/work/work-document-file-io.d.ts +4 -0
  248. package/dist/internal/features/work/work-document-fonts.d.ts +16 -0
  249. package/dist/internal/features/work/work-document-image-layout.d.ts +29 -0
  250. package/dist/internal/features/work/work-document-incremental-layout.d.ts +17 -0
  251. package/dist/internal/features/work/work-document-layout.d.ts +5 -0
  252. package/dist/internal/features/work/work-document-line-measurement.d.ts +24 -0
  253. package/dist/internal/features/work/work-document-links.d.ts +2 -0
  254. package/dist/internal/features/work/work-document-lists.d.ts +25 -0
  255. package/dist/internal/features/work/work-document-model-codec.d.ts +3 -0
  256. package/dist/internal/features/work/work-document-model.d.ts +12 -0
  257. package/dist/internal/features/work/work-document-note-nodes.d.ts +11 -0
  258. package/dist/internal/features/work/work-document-notes.d.ts +18 -0
  259. package/dist/internal/features/work/work-document-outline.d.ts +14 -0
  260. package/dist/internal/features/work/work-document-page-break.d.ts +2 -0
  261. package/dist/internal/features/work/work-document-page-chrome-commands.d.ts +15 -0
  262. package/dist/internal/features/work/work-document-page-chrome.d.ts +19 -0
  263. package/dist/internal/features/work/work-document-page-color.d.ts +3 -0
  264. package/dist/internal/features/work/work-document-pages.d.ts +19 -0
  265. package/dist/internal/features/work/work-document-pagination-decorations.d.ts +3 -0
  266. package/dist/internal/features/work/work-document-pagination-dom.d.ts +35 -0
  267. package/dist/internal/features/work/work-document-pagination-measurement.d.ts +9 -0
  268. package/dist/internal/features/work/work-document-pagination-types.d.ts +88 -0
  269. package/dist/internal/features/work/work-document-pagination.d.ts +17 -0
  270. package/dist/internal/features/work/work-document-paragraph-formatting.d.ts +61 -0
  271. package/dist/internal/features/work/work-document-search.d.ts +11 -0
  272. package/dist/internal/features/work/work-document-section-editor.d.ts +20 -0
  273. package/dist/internal/features/work/work-document-section-node.d.ts +13 -0
  274. package/dist/internal/features/work/work-document-section.d.ts +34 -0
  275. package/dist/internal/features/work/work-document-selection-menu.d.ts +54 -0
  276. package/dist/internal/features/work/work-document-tab-node.d.ts +6 -0
  277. package/dist/internal/features/work/work-document-tab-stops.d.ts +29 -0
  278. package/dist/internal/features/work/work-document-table-cell-formatting.d.ts +46 -0
  279. package/dist/internal/features/work/work-document-table-commands.d.ts +17 -0
  280. package/dist/internal/features/work/work-document-table-pagination.d.ts +5 -0
  281. package/dist/internal/features/work/work-document-table-row.d.ts +37 -0
  282. package/dist/internal/features/work/work-document-table-sizing.d.ts +27 -0
  283. package/dist/internal/features/work/work-document-text-layout.d.ts +14 -0
  284. package/dist/internal/features/work/work-docx-bibliography.d.ts +12 -0
  285. package/dist/internal/features/work/work-docx-caption-diagnostics.d.ts +6 -0
  286. package/dist/internal/features/work/work-docx-caption-export.d.ts +4 -0
  287. package/dist/internal/features/work/work-docx-caption-fields.d.ts +5 -0
  288. package/dist/internal/features/work/work-docx-caption-import.d.ts +20 -0
  289. package/dist/internal/features/work/work-docx-change-import.d.ts +12 -0
  290. package/dist/internal/features/work/work-docx-citation-diagnostics.d.ts +3 -0
  291. package/dist/internal/features/work/work-docx-citation-export.d.ts +3 -0
  292. package/dist/internal/features/work/work-docx-citation-import.d.ts +23 -0
  293. package/dist/internal/features/work/work-docx-column-export.d.ts +14 -0
  294. package/dist/internal/features/work/work-docx-column-import.d.ts +2 -0
  295. package/dist/internal/features/work/work-docx-comment-import.d.ts +14 -0
  296. package/dist/internal/features/work/work-docx-export-formatting.d.ts +30 -0
  297. package/dist/internal/features/work/work-docx-export-image.d.ts +2 -0
  298. package/dist/internal/features/work/work-docx-export.d.ts +2 -0
  299. package/dist/internal/features/work/work-docx-field-export.d.ts +2 -0
  300. package/dist/internal/features/work/work-docx-field-import.d.ts +16 -0
  301. package/dist/internal/features/work/work-docx-field-instructions.d.ts +8 -0
  302. package/dist/internal/features/work/work-docx-image-layout-import.d.ts +12 -0
  303. package/dist/internal/features/work/work-docx-import.d.ts +50 -0
  304. package/dist/internal/features/work/work-docx-list-import.d.ts +14 -0
  305. package/dist/internal/features/work/work-docx-note-diagnostics.d.ts +3 -0
  306. package/dist/internal/features/work/work-docx-note-import.d.ts +3 -0
  307. package/dist/internal/features/work/work-docx-page-chrome-diagnostics.d.ts +3 -0
  308. package/dist/internal/features/work/work-docx-page-chrome-import.d.ts +11 -0
  309. package/dist/internal/features/work/work-docx-page-color.d.ts +2 -0
  310. package/dist/internal/features/work/work-docx-paragraph-alignment-import.d.ts +12 -0
  311. package/dist/internal/features/work/work-docx-paragraph-direction-import.d.ts +12 -0
  312. package/dist/internal/features/work/work-docx-paragraph-indent-import.d.ts +12 -0
  313. package/dist/internal/features/work/work-docx-paragraph-pagination-import.d.ts +12 -0
  314. package/dist/internal/features/work/work-docx-paragraph-spacing-import.d.ts +12 -0
  315. package/dist/internal/features/work/work-docx-paragraph-styles.d.ts +18 -0
  316. package/dist/internal/features/work/work-docx-run-formatting-import.d.ts +19 -0
  317. package/dist/internal/features/work/work-docx-tab-stop-import.d.ts +13 -0
  318. package/dist/internal/features/work/work-docx-table-cell-export.d.ts +4 -0
  319. package/dist/internal/features/work/work-docx-table-cell-import.d.ts +16 -0
  320. package/dist/internal/features/work/work-docx-table-row-import.d.ts +13 -0
  321. package/dist/internal/features/work/work-docx-table-sizing-export.d.ts +8 -0
  322. package/dist/internal/features/work/work-docx-table-sizing-import.d.ts +12 -0
  323. package/dist/internal/features/work/work-docx-theme.d.ts +9 -0
  324. package/dist/internal/features/work/work-file-data.d.ts +1 -0
  325. package/dist/internal/features/work/work-file-download.d.ts +3 -0
  326. package/dist/internal/features/work/work-file-io.d.ts +8 -0
  327. package/dist/internal/features/work/work-markdown-extensions.d.ts +19 -0
  328. package/dist/internal/features/work/work-markdown-file-io.d.ts +3 -0
  329. package/dist/internal/features/work/work-markdown-selection-menu.d.ts +57 -0
  330. package/dist/internal/features/work/work-office-diagnostics.d.ts +9 -0
  331. package/dist/internal/features/work/work-ooxml-package.d.ts +28 -0
  332. package/dist/internal/features/work/work-pdf-export.d.ts +23 -0
  333. package/dist/internal/features/work/work-pptx-chart-axes.d.ts +3 -0
  334. package/dist/internal/features/work/work-pptx-chart-axis-diagnostics.d.ts +5 -0
  335. package/dist/internal/features/work/work-pptx-chart-data-labels.d.ts +12 -0
  336. package/dist/internal/features/work/work-pptx-chart-import.d.ts +11 -0
  337. package/dist/internal/features/work/work-pptx-chart-layout-style.d.ts +15 -0
  338. package/dist/internal/features/work/work-pptx-chart-series-analysis.d.ts +13 -0
  339. package/dist/internal/features/work/work-pptx-chart-xy.d.ts +3 -0
  340. package/dist/internal/features/work/work-pptx-comments.d.ts +17 -0
  341. package/dist/internal/features/work/work-pptx-export.d.ts +4 -0
  342. package/dist/internal/features/work/work-pptx-groups.d.ts +19 -0
  343. package/dist/internal/features/work/work-pptx-import.d.ts +6 -0
  344. package/dist/internal/features/work/work-pptx-layout-export.d.ts +13 -0
  345. package/dist/internal/features/work/work-pptx-layout-import.d.ts +30 -0
  346. package/dist/internal/features/work/work-pptx-style.d.ts +13 -0
  347. package/dist/internal/features/work/work-pptx-transition.d.ts +13 -0
  348. package/dist/internal/features/work/work-presentation-agent-context.d.ts +6 -0
  349. package/dist/internal/features/work/work-presentation-chart-axes.d.ts +14 -0
  350. package/dist/internal/features/work/work-presentation-charts.d.ts +37 -0
  351. package/dist/internal/features/work/work-presentation-clipboard.d.ts +26 -0
  352. package/dist/internal/features/work/work-presentation-file-io.d.ts +15 -0
  353. package/dist/internal/features/work/work-presentation-groups.d.ts +17 -0
  354. package/dist/internal/features/work/work-presentation-layouts.d.ts +13 -0
  355. package/dist/internal/features/work/work-presentation-transition.d.ts +4 -0
  356. package/dist/internal/features/work/work-presentation-visual-scale.d.ts +2 -0
  357. package/dist/internal/features/work/work-repository.d.ts +4 -0
  358. package/dist/internal/features/work/work-spreadsheet-agent-context.d.ts +15 -0
  359. package/dist/internal/features/work/work-spreadsheet-chart-axis.d.ts +42 -0
  360. package/dist/internal/features/work/work-spreadsheet-chart-layout.d.ts +29 -0
  361. package/dist/internal/features/work/work-spreadsheet-chart-legend-svg.d.ts +18 -0
  362. package/dist/internal/features/work/work-spreadsheet-chart-series-layout.d.ts +24 -0
  363. package/dist/internal/features/work/work-spreadsheet-chart-series-style.d.ts +29 -0
  364. package/dist/internal/features/work/work-spreadsheet-chart-svg-utils.d.ts +7 -0
  365. package/dist/internal/features/work/work-spreadsheet-chart-svg.d.ts +3 -0
  366. package/dist/internal/features/work/work-spreadsheet-chart-types.d.ts +147 -0
  367. package/dist/internal/features/work/work-spreadsheet-chart-validation.d.ts +2 -0
  368. package/dist/internal/features/work/work-spreadsheet-charts.d.ts +17 -0
  369. package/dist/internal/features/work/work-spreadsheet-combination-chart-svg.d.ts +9 -0
  370. package/dist/internal/features/work/work-spreadsheet-comments.d.ts +7 -0
  371. package/dist/internal/features/work/work-spreadsheet-conditional-canvas.d.ts +5 -0
  372. package/dist/internal/features/work/work-spreadsheet-conditional-colors.d.ts +9 -0
  373. package/dist/internal/features/work/work-spreadsheet-conditional-comparisons.d.ts +4 -0
  374. package/dist/internal/features/work/work-spreadsheet-conditional-data-bar.d.ts +8 -0
  375. package/dist/internal/features/work/work-spreadsheet-conditional-format.d.ts +10 -0
  376. package/dist/internal/features/work/work-spreadsheet-conditional-icons.d.ts +107 -0
  377. package/dist/internal/features/work/work-spreadsheet-conditional-values.d.ts +19 -0
  378. package/dist/internal/features/work/work-spreadsheet-data-label-svg.d.ts +27 -0
  379. package/dist/internal/features/work/work-spreadsheet-error-bar-svg.d.ts +5 -0
  380. package/dist/internal/features/work/work-spreadsheet-error-bars.d.ts +8 -0
  381. package/dist/internal/features/work/work-spreadsheet-formula-analysis.d.ts +30 -0
  382. package/dist/internal/features/work/work-spreadsheet-formula-support.d.ts +1 -0
  383. package/dist/internal/features/work/work-spreadsheet-formulas.d.ts +19 -0
  384. package/dist/internal/features/work/work-spreadsheet-header-footer.d.ts +14 -0
  385. package/dist/internal/features/work/work-spreadsheet-line-chart-svg.d.ts +10 -0
  386. package/dist/internal/features/work/work-spreadsheet-page-breaks.d.ts +4 -0
  387. package/dist/internal/features/work/work-spreadsheet-page-setup.d.ts +26 -0
  388. package/dist/internal/features/work/work-spreadsheet-pivot-engine.d.ts +21 -0
  389. package/dist/internal/features/work/work-spreadsheet-pivot-values.d.ts +7 -0
  390. package/dist/internal/features/work/work-spreadsheet-pivots.d.ts +27 -0
  391. package/dist/internal/features/work/work-spreadsheet-protection.d.ts +55 -0
  392. package/dist/internal/features/work/work-spreadsheet-ranges.d.ts +25 -0
  393. package/dist/internal/features/work/work-spreadsheet-trendline-svg.d.ts +9 -0
  394. package/dist/internal/features/work/work-spreadsheet-trendlines.d.ts +11 -0
  395. package/dist/internal/features/work/work-spreadsheet-xy-chart-axes-svg.d.ts +10 -0
  396. package/dist/internal/features/work/work-templates.d.ts +4 -0
  397. package/dist/internal/features/work/work-types.d.ts +513 -0
  398. package/dist/internal/features/work/work-xlsx-chart-axes.d.ts +4 -0
  399. package/dist/internal/features/work/work-xlsx-chart-diagnostics.d.ts +3 -0
  400. package/dist/internal/features/work/work-xlsx-chart-layout.d.ts +16 -0
  401. package/dist/internal/features/work/work-xlsx-chart-series-style.d.ts +6 -0
  402. package/dist/internal/features/work/work-xlsx-chart-values.d.ts +10 -0
  403. package/dist/internal/features/work/work-xlsx-charts.d.ts +32 -0
  404. package/dist/internal/features/work/work-xlsx-conditional-format-diagnostics.d.ts +6 -0
  405. package/dist/internal/features/work/work-xlsx-conditional-format-write.d.ts +11 -0
  406. package/dist/internal/features/work/work-xlsx-conditional-format.d.ts +29 -0
  407. package/dist/internal/features/work/work-xlsx-defined-names.d.ts +4 -0
  408. package/dist/internal/features/work/work-xlsx-drawing-geometry.d.ts +27 -0
  409. package/dist/internal/features/work/work-xlsx-formula-diagnostics.d.ts +3 -0
  410. package/dist/internal/features/work/work-xlsx-formulas.d.ts +40 -0
  411. package/dist/internal/features/work/work-xlsx-header-footer.d.ts +12 -0
  412. package/dist/internal/features/work/work-xlsx-images.d.ts +17 -0
  413. package/dist/internal/features/work/work-xlsx-interop.d.ts +39 -0
  414. package/dist/internal/features/work/work-xlsx-page-breaks.d.ts +7 -0
  415. package/dist/internal/features/work/work-xlsx-page-setup-diagnostics.d.ts +2 -0
  416. package/dist/internal/features/work/work-xlsx-page-setup.d.ts +5 -0
  417. package/dist/internal/features/work/work-xlsx-pivot-diagnostics.d.ts +3 -0
  418. package/dist/internal/features/work/work-xlsx-pivot-xml.d.ts +9 -0
  419. package/dist/internal/features/work/work-xlsx-pivots.d.ts +32 -0
  420. package/dist/internal/features/work/work-xlsx-protection.d.ts +24 -0
  421. package/dist/internal/features/workspace/components/workspace-context-menu.d.ts +29 -0
  422. package/dist/internal/features/workspace/components/workspace-text-control-selection.d.ts +7 -0
  423. package/dist/internal/kernel/office-kernel-client-types.d.ts +40 -0
  424. package/dist/internal/kernel/office-kernel-client.d.ts +4 -0
  425. package/dist/internal/kernel/office-kernel-fallback.d.ts +2 -0
  426. package/dist/internal/kernel/office-kernel-presentation-fallback.d.ts +2 -0
  427. package/dist/internal/kernel/office-kernel-protocol.d.ts +229 -0
  428. package/dist/internal/kernel/office-kernel-spreadsheet-fallback-formula.d.ts +3 -0
  429. package/dist/internal/kernel/office-kernel-spreadsheet-fallback-validation.d.ts +5 -0
  430. package/dist/internal/kernel/office-kernel-spreadsheet-fallback-value.d.ts +6 -0
  431. package/dist/internal/kernel/office-kernel-spreadsheet-fallback.d.ts +2 -0
  432. package/dist/internal/kernel/office-kernel-spreadsheet-protocol.d.ts +112 -0
  433. package/dist/internal/kernel/office-kernel-spreadsheet-session-fallback.d.ts +8 -0
  434. package/dist/internal/kernel/office-kernel-text-fallback.d.ts +10 -0
  435. package/dist/internal/kernel/office-kernel-version.d.ts +1 -0
  436. package/dist/internal/kernel/office-kernel.worker.d.ts +1 -0
  437. package/dist/internal/keyboard-shortcuts.d.ts +2 -0
  438. package/dist/internal/state/app-state.d.ts +8 -0
  439. package/dist/noto-naskh-arabic-regular.ttf +0 -0
  440. package/dist/noto-naskh-arabic.LICENSE.txt +94 -0
  441. package/dist/noto-sans-hans-regular.otf +0 -0
  442. package/dist/noto-sans-hans.LICENSE.txt +94 -0
  443. package/dist/noto-sans-hebrew-regular.ttf +0 -0
  444. package/dist/noto-sans-hebrew.LICENSE.txt +94 -0
  445. package/dist/noto-sans-regular.ttf +0 -0
  446. package/dist/noto-sans.LICENSE.txt +94 -0
  447. package/dist/office-kernel.wasm +0 -0
  448. package/dist/office-kernel.worker.js +14605 -0
  449. package/dist/office-surface.d.ts +10 -0
  450. package/dist/pdfium.LICENSE.txt +196 -0
  451. package/dist/pdfium.wasm +0 -0
  452. package/dist/pptxgen.LICENSE.txt +21 -0
  453. package/dist/pptxgen.bundle.js +11244 -0
  454. package/dist/react.d.ts +51 -0
  455. package/dist/react.js +1 -0
  456. package/dist/styles.css +17435 -0
  457. package/dist/styles.js +0 -0
  458. package/dist/vue.d.ts +282 -0
  459. package/dist/vue.js +231 -0
  460. package/dist/web-component.d.ts +98 -0
  461. package/dist/web-component.js +335 -0
  462. package/docs/browser-editor-architecture.md +947 -0
  463. package/package.json +165 -0
package/dist/4704.js ADDED
@@ -0,0 +1,1364 @@
1
+ const DEFAULT_DOCUMENT_MARGINS = {
2
+ top: 25,
3
+ right: 23,
4
+ bottom: 25,
5
+ left: 23
6
+ };
7
+ function documentMargins(content) {
8
+ return {
9
+ top: validMargin(content.margins?.top, DEFAULT_DOCUMENT_MARGINS.top),
10
+ right: validMargin(content.margins?.right, DEFAULT_DOCUMENT_MARGINS.right),
11
+ bottom: validMargin(content.margins?.bottom, DEFAULT_DOCUMENT_MARGINS.bottom),
12
+ left: validMargin(content.margins?.left, DEFAULT_DOCUMENT_MARGINS.left)
13
+ };
14
+ }
15
+ function clampDocumentMargin(value) {
16
+ return Math.min(60, Math.max(5, Math.round(10 * value) / 10));
17
+ }
18
+ function millimetersToPixels(value) {
19
+ return 96 * value / 25.4;
20
+ }
21
+ function validMargin(value, fallback) {
22
+ return Number.isFinite(value) ? clampDocumentMargin(value) : fallback;
23
+ }
24
+ const CAPTION_SELECTOR = 'figcaption[data-document-caption]';
25
+ const REFERENCE_SELECTOR = 'span[data-document-cross-reference]';
26
+ function normalizeDocumentCaptionsHtml(source) {
27
+ const document = new DOMParser().parseFromString(source, 'text/html');
28
+ const targets = normalizeCaptions(document);
29
+ normalizeReferences(document, new Map(targets.map((target)=>[
30
+ target.id,
31
+ target
32
+ ])));
33
+ return document.body.innerHTML;
34
+ }
35
+ function documentCaptionKind(value) {
36
+ return 'figure' === value || 'table' === value ? value : null;
37
+ }
38
+ function documentCaptionLabel(kind) {
39
+ return 'table' === kind ? '表' : '图';
40
+ }
41
+ function documentCaptionDisplay(kind, number) {
42
+ return `${documentCaptionLabel(kind)} ${positiveInteger(number)}`;
43
+ }
44
+ function normalizeCaptions(document) {
45
+ const counters = {
46
+ figure: 0,
47
+ table: 0
48
+ };
49
+ const usedIds = new Set();
50
+ return Array.from(document.body.querySelectorAll(CAPTION_SELECTOR)).map((element, index)=>{
51
+ const kind = documentCaptionKind(element.dataset.captionKind) ?? 'figure';
52
+ counters[kind] += 1;
53
+ const number = counters[kind];
54
+ const id = uniqueCaptionId(element.dataset.captionId, kind, index + 1, usedIds);
55
+ const label = documentCaptionLabel(kind);
56
+ element.dataset.documentCaption = 'true';
57
+ element.dataset.captionId = id;
58
+ element.dataset.captionKind = kind;
59
+ element.dataset.captionNumber = String(number);
60
+ element.dataset.captionLabel = label;
61
+ element.classList.add('work-document-caption');
62
+ const title = element.textContent?.replace(/\s+/g, ' ').trim() ?? '';
63
+ const display = documentCaptionDisplay(kind, number);
64
+ element.setAttribute('aria-label', title ? `${display} ${title}` : display);
65
+ return {
66
+ id,
67
+ kind,
68
+ number,
69
+ label,
70
+ title,
71
+ display
72
+ };
73
+ });
74
+ }
75
+ function normalizeReferences(document, targets) {
76
+ for (const element of Array.from(document.body.querySelectorAll(REFERENCE_SELECTOR))){
77
+ const id = element.dataset.referenceTargetId?.trim() ?? '';
78
+ const target = targets.get(id);
79
+ element.dataset.documentCrossReference = 'true';
80
+ element.dataset.referenceTargetId = id;
81
+ element.classList.add('work-document-cross-reference');
82
+ if (!target) {
83
+ element.dataset.referenceOrphaned = 'true';
84
+ element.textContent = '引用缺失';
85
+ continue;
86
+ }
87
+ delete element.dataset.referenceOrphaned;
88
+ element.dataset.captionKind = target.kind;
89
+ element.dataset.captionNumber = String(target.number);
90
+ element.dataset.captionLabel = target.label;
91
+ element.textContent = target.display;
92
+ }
93
+ }
94
+ function uniqueCaptionId(source, kind, index, usedIds) {
95
+ const candidate = source?.trim();
96
+ if (candidate && !usedIds.has(candidate)) {
97
+ usedIds.add(candidate);
98
+ return candidate;
99
+ }
100
+ let suffix = index;
101
+ while(usedIds.has(`document-${kind}-caption-${suffix}`))suffix += 1;
102
+ const id = `document-${kind}-caption-${suffix}`;
103
+ usedIds.add(id);
104
+ return id;
105
+ }
106
+ function positiveInteger(value) {
107
+ const number = Number(value);
108
+ return Number.isSafeInteger(number) && number > 0 ? number : 1;
109
+ }
110
+ const CITATION_SELECTOR = 'span[data-document-citation]';
111
+ const BIBLIOGRAPHY_SELECTOR = 'section[data-document-bibliography]';
112
+ const STYLE_DETAILS = {
113
+ apa: {
114
+ name: 'APA',
115
+ selectedStyle: '\\APASixthEditionOfficeOnline.xsl'
116
+ },
117
+ mla: {
118
+ name: 'MLA',
119
+ selectedStyle: '\\MLASeventhEditionOfficeOnline.xsl'
120
+ },
121
+ chicago: {
122
+ name: 'Chicago',
123
+ selectedStyle: '\\CHICAGO.XSL'
124
+ },
125
+ ieee: {
126
+ name: 'IEEE',
127
+ selectedStyle: '\\IEEE.XSL'
128
+ }
129
+ };
130
+ function createDocumentBibliography(style = 'apa') {
131
+ return {
132
+ style,
133
+ styleName: STYLE_DETAILS[style].name,
134
+ selectedStyle: STYLE_DETAILS[style].selectedStyle,
135
+ sources: []
136
+ };
137
+ }
138
+ function documentCitationStyle(value) {
139
+ if ('mla' === value || 'chicago' === value || 'ieee' === value) return value;
140
+ return 'apa';
141
+ }
142
+ function documentCitationStyleDetails(style) {
143
+ return STYLE_DETAILS[style];
144
+ }
145
+ function documentCitationTagsFromInstruction(instruction) {
146
+ const primary = /^\s*CITATION\s+(?:"([^"]+)"|([^\s\\]+))/i.exec(instruction);
147
+ if (!primary) return [];
148
+ const tags = [
149
+ primary[1] || primary[2]
150
+ ];
151
+ const additional = /\\m\s+(?:"([^"]+)"|([^\s\\]+))/gi;
152
+ for (const match of instruction.matchAll(additional))tags.push(match[1] || match[2]);
153
+ return uniqueCitationTags(tags);
154
+ }
155
+ function documentCitationInstruction(tags) {
156
+ const normalized = uniqueCitationTags(tags);
157
+ if (!normalized.length) return '';
158
+ return [
159
+ 'CITATION',
160
+ citationTagInstructionValue(normalized[0]),
161
+ ...normalized.slice(1).flatMap((tag)=>[
162
+ '\\m',
163
+ citationTagInstructionValue(tag)
164
+ ]),
165
+ '\\l',
166
+ '2052'
167
+ ].join(' ');
168
+ }
169
+ function renameDocumentCitationTagInInstruction(instruction, previousTag, nextTag) {
170
+ return instruction.replace(/(^\s*CITATION\s+|\\m\s+)("[^"]+"|[^\s\\]+)/gi, (match, prefix, source)=>{
171
+ const tag = source.startsWith('"') ? source.slice(1, -1) : source;
172
+ return tag === previousTag ? `${prefix}${citationTagInstructionValue(nextTag)}` : match;
173
+ });
174
+ }
175
+ function documentCitationTags(value) {
176
+ return uniqueCitationTags((value ?? '').split(/\s+/));
177
+ }
178
+ function isValidDocumentCitationTag(value) {
179
+ return /^[A-Za-z0-9_:.+-]{1,80}$/.test(value);
180
+ }
181
+ function resolveDocumentCitation(tags, bibliography, instruction = '', cachedValue = '') {
182
+ const normalized = uniqueCitationTags(tags);
183
+ if (!normalized.length) return {
184
+ text: cachedValue || '缺失引文',
185
+ orphaned: true
186
+ };
187
+ const sources = new Map((bibliography?.sources ?? []).map((source)=>[
188
+ source.tag,
189
+ source
190
+ ]));
191
+ const missing = normalized.filter((tag)=>!sources.has(tag));
192
+ if (missing.length) return {
193
+ text: 1 === missing.length ? `缺失引文:${missing[0]}` : `缺失引文:${missing.join('、')}`,
194
+ orphaned: true
195
+ };
196
+ const selected = normalized.flatMap((tag)=>{
197
+ const source = sources.get(tag);
198
+ return source ? [
199
+ source
200
+ ] : [];
201
+ });
202
+ const style = bibliography?.style ?? 'apa';
203
+ const suppressAuthor = /(?:^|\s)\\n(?:\s|$)/i.test(instruction);
204
+ const suppressYear = /(?:^|\s)\\v(?:\s|$)/i.test(instruction);
205
+ const prefix = citationSwitch(instruction, 'f');
206
+ const suffix = citationSwitch(instruction, 'p');
207
+ const text = 'ieee' === style ? ieeeCitation(selected, bibliography?.sources ?? []) : 'mla' === style ? mlaCitation(selected, suppressAuthor) : 'chicago' === style ? chicagoCitation(selected, suppressAuthor, suppressYear) : apaCitation(selected, suppressAuthor, suppressYear);
208
+ return {
209
+ text: `${prefix}${text}${suffix}`.trim() || cachedValue || normalized.join('; '),
210
+ orphaned: false
211
+ };
212
+ }
213
+ function normalizeDocumentCitationsHtml(source, bibliography) {
214
+ const document = new DOMParser().parseFromString(source, 'text/html');
215
+ const usedIds = new Set();
216
+ for (const [index, element] of Array.from(document.body.querySelectorAll(CITATION_SELECTOR)).entries()){
217
+ const instruction = element.dataset.citationInstruction?.trim() ?? '';
218
+ const tags = documentCitationTags(element.dataset.citationTags);
219
+ const normalizedTags = tags.length ? tags : documentCitationTagsFromInstruction(instruction);
220
+ if (!normalizedTags.length) {
221
+ element.replaceWith(document.createTextNode(element.textContent ?? ''));
222
+ continue;
223
+ }
224
+ const cached = element.dataset.citationDisplay?.trim() || element.textContent?.trim() || '';
225
+ const resolved = resolveDocumentCitation(normalizedTags, bibliography, instruction, cached);
226
+ element.dataset.documentCitation = 'true';
227
+ element.dataset.citationId = uniqueCitationId(element.dataset.citationId, index + 1, usedIds);
228
+ element.dataset.citationTags = normalizedTags.join(' ');
229
+ element.dataset.citationInstruction = instruction || documentCitationInstruction(normalizedTags);
230
+ element.dataset.citationDisplay = resolved.text;
231
+ if (resolved.orphaned) element.dataset.citationOrphaned = 'true';
232
+ else delete element.dataset.citationOrphaned;
233
+ element.classList.add('work-document-citation');
234
+ element.textContent = resolved.text;
235
+ }
236
+ for (const [index, element] of Array.from(document.body.querySelectorAll(BIBLIOGRAPHY_SELECTOR)).entries()){
237
+ if (!bibliography) continue;
238
+ const replacement = createBibliographyElement(document, bibliography, element.dataset.bibliographyId || `document-bibliography-${index + 1}`);
239
+ element.replaceWith(replacement);
240
+ }
241
+ return document.body.innerHTML;
242
+ }
243
+ function renderDocumentBibliographyHtml(bibliography, id = 'document-bibliography-1') {
244
+ const document = new DOMParser().parseFromString('', 'text/html');
245
+ document.body.append(createBibliographyElement(document, bibliography, id));
246
+ return document.body.innerHTML;
247
+ }
248
+ function documentBibliographyEntry(source, bibliography, index) {
249
+ const people = primaryCitationContributor(source);
250
+ const authors = people?.corporate?.trim() || people?.people?.map((person)=>bibliographyPersonName(person, bibliography.style)).join(', ') || '未知作者';
251
+ const title = source.title.trim() || 'Untitled';
252
+ const year = source.year?.trim() || 'n.d.';
253
+ const container = citationContainer(source);
254
+ const url = source.url?.trim();
255
+ if ('ieee' === bibliography.style) return [
256
+ `[${index + 1}] ${authors}, “${title}.”`,
257
+ container ? `${container},` : '',
258
+ year ? `${year}.` : '',
259
+ url ?? ''
260
+ ].filter(Boolean).join(' ');
261
+ if ('mla' === bibliography.style) return [
262
+ `${authors}.`,
263
+ `“${title}.”`,
264
+ container ? `${container},` : '',
265
+ `${year}.`,
266
+ url ?? ''
267
+ ].filter(Boolean).join(' ');
268
+ if ('chicago' === bibliography.style) return [
269
+ `${authors}.`,
270
+ `${year}.`,
271
+ `“${title}.”`,
272
+ container ? `${container}.` : '',
273
+ url ?? ''
274
+ ].filter(Boolean).join(' ');
275
+ return [
276
+ `${authors}.`,
277
+ `(${year}).`,
278
+ `${title}.`,
279
+ container ? `${container}.` : '',
280
+ url ?? ''
281
+ ].filter(Boolean).join(' ');
282
+ }
283
+ function primaryCitationContributor(source) {
284
+ return source.contributors?.Author ?? Object.values(source.contributors ?? {})[0];
285
+ }
286
+ function createBibliographyElement(document, bibliography, id) {
287
+ const section = document.createElement('section');
288
+ section.dataset.documentBibliography = 'true';
289
+ section.dataset.bibliographyId = id;
290
+ section.dataset.bibliographyStyle = bibliography.style;
291
+ section.className = 'work-document-bibliography';
292
+ const heading = document.createElement('h2');
293
+ heading.textContent = '参考文献';
294
+ section.append(heading);
295
+ if (!bibliography.sources.length) {
296
+ const empty = document.createElement('p');
297
+ empty.dataset.bibliographyEmpty = 'true';
298
+ empty.textContent = '尚无文献源';
299
+ section.append(empty);
300
+ return section;
301
+ }
302
+ bibliography.sources.forEach((source, index)=>{
303
+ const paragraph = document.createElement('p');
304
+ paragraph.dataset.bibliographyEntry = source.tag;
305
+ paragraph.textContent = documentBibliographyEntry(source, bibliography, index);
306
+ section.append(paragraph);
307
+ });
308
+ return section;
309
+ }
310
+ function apaCitation(sources, suppressAuthor, suppressYear) {
311
+ const items = sources.map((source)=>{
312
+ const author = suppressAuthor ? '' : citationAuthor(source, '&');
313
+ const year = suppressYear ? '' : source.year?.trim() || 'n.d.';
314
+ return [
315
+ author,
316
+ year
317
+ ].filter(Boolean).join(', ');
318
+ });
319
+ return `(${items.join('; ')})`;
320
+ }
321
+ function mlaCitation(sources, suppressAuthor) {
322
+ return `(${sources.map((source)=>suppressAuthor ? source.year?.trim() || 'n.d.' : citationAuthor(source, 'and')).join('; ')})`;
323
+ }
324
+ function chicagoCitation(sources, suppressAuthor, suppressYear) {
325
+ return `(${sources.map((source)=>[
326
+ suppressAuthor ? '' : citationAuthor(source, 'and'),
327
+ suppressYear ? '' : source.year?.trim() || 'n.d.'
328
+ ].filter(Boolean).join(' ')).join('; ')})`;
329
+ }
330
+ function ieeeCitation(sources, allSources) {
331
+ const indexes = sources.map((source)=>allSources.findIndex((candidate)=>candidate.id === source.id || candidate.tag === source.tag) + 1).filter((index)=>index > 0);
332
+ return `[${indexes.join(', ')}]`;
333
+ }
334
+ function citationAuthor(source, conjunction) {
335
+ const contributor = primaryCitationContributor(source);
336
+ if (contributor?.corporate?.trim()) return contributor.corporate.trim();
337
+ const names = (contributor?.people ?? []).map((person)=>person.last.trim() || person.first.trim()).filter(Boolean);
338
+ if (!names.length) return source.title.trim() || source.tag;
339
+ if (1 === names.length) return names[0];
340
+ if (2 === names.length) return `${names[0]} ${conjunction} ${names[1]}`;
341
+ return `${names[0]} et al.`;
342
+ }
343
+ function bibliographyPersonName(person, style) {
344
+ const first = [
345
+ person.first,
346
+ person.middle
347
+ ].filter(Boolean).join(' ').trim();
348
+ const suffix = person.suffix?.trim();
349
+ if ('ieee' === style) {
350
+ const initials = [
351
+ person.first,
352
+ person.middle
353
+ ].filter(Boolean).map((value)=>`${Array.from(value ?? '')[0] ?? ''}.`).join(' ');
354
+ return [
355
+ initials,
356
+ person.last,
357
+ suffix
358
+ ].filter(Boolean).join(' ');
359
+ }
360
+ return [
361
+ person.last,
362
+ first ? `, ${first}` : '',
363
+ suffix ? `, ${suffix}` : ''
364
+ ].join('');
365
+ }
366
+ function citationContainer(source) {
367
+ return source.journalName?.trim() || source.publisher?.trim() || source.conferenceName?.trim() || source.institution?.trim() || '';
368
+ }
369
+ function citationSwitch(instruction, name) {
370
+ const expression = new RegExp(`\\\\${name}\\s+"([^"]*)"`, 'i');
371
+ return expression.exec(instruction)?.[1] ?? '';
372
+ }
373
+ function citationTagInstructionValue(tag) {
374
+ return /^[A-Za-z0-9_:.+-]+$/.test(tag) ? tag : `"${tag.replaceAll('"', '')}"`;
375
+ }
376
+ function uniqueCitationTags(tags) {
377
+ const result = [];
378
+ const seen = new Set();
379
+ for (const source of tags){
380
+ const tag = source.trim();
381
+ if (!(!tag || seen.has(tag))) {
382
+ seen.add(tag);
383
+ result.push(tag);
384
+ }
385
+ }
386
+ return result;
387
+ }
388
+ function uniqueCitationId(source, index, usedIds) {
389
+ const candidate = source?.trim();
390
+ if (candidate && !usedIds.has(candidate)) {
391
+ usedIds.add(candidate);
392
+ return candidate;
393
+ }
394
+ let suffix = index;
395
+ while(usedIds.has(`document-citation-${suffix}`))suffix += 1;
396
+ const id = `document-citation-${suffix}`;
397
+ usedIds.add(id);
398
+ return id;
399
+ }
400
+ const FIELD_SELECTOR = 'span[data-document-field]';
401
+ const FIELD_COMMANDS = {
402
+ page: 'PAGE',
403
+ numPages: 'NUMPAGES',
404
+ section: 'SECTION',
405
+ sectionPages: 'SECTIONPAGES',
406
+ date: 'DATE \\@ "yyyy年M月d日"',
407
+ time: 'TIME \\@ "HH:mm"'
408
+ };
409
+ const FIELD_LABELS = {
410
+ page: '当前页码',
411
+ numPages: '总页数',
412
+ section: '当前节号',
413
+ sectionPages: '本节页数',
414
+ date: '当前日期',
415
+ time: '当前时间'
416
+ };
417
+ function documentFieldKind(value) {
418
+ if ('page' === value || 'numPages' === value || 'section' === value || 'sectionPages' === value || 'date' === value || 'time' === value) return value;
419
+ return null;
420
+ }
421
+ function docxDocumentFieldKind(instruction) {
422
+ const command = /^\s*([a-z][a-z0-9]*)\b/i.exec(instruction)?.[1]?.toUpperCase();
423
+ if ('PAGE' === command) return 'page';
424
+ if ('NUMPAGES' === command) return 'numPages';
425
+ if ('SECTION' === command) return 'section';
426
+ if ('SECTIONPAGES' === command) return 'sectionPages';
427
+ if ('DATE' === command) return 'date';
428
+ if ('TIME' === command) return 'time';
429
+ return null;
430
+ }
431
+ function documentFieldInstruction(kind) {
432
+ return FIELD_COMMANDS[kind];
433
+ }
434
+ function documentFieldLabel(kind) {
435
+ return FIELD_LABELS[kind];
436
+ }
437
+ function documentFieldDisplay(kind, context, instruction = documentFieldInstruction(kind), cachedValue = '') {
438
+ if ('page' === kind) return String(work_document_fields_positiveInteger(context.pageNumber));
439
+ if ('numPages' === kind) return String(work_document_fields_positiveInteger(context.totalPages));
440
+ if ('section' === kind) return String(work_document_fields_positiveInteger(context.sectionNumber));
441
+ if ('sectionPages' === kind) return String(work_document_fields_positiveInteger(context.sectionPages));
442
+ const now = validDate(context.now) ?? new Date();
443
+ const format = dateFormatSwitch(instruction) ?? ('date' === kind ? 'yyyy年M月d日' : 'HH:mm');
444
+ const display = formatWordDate(now, format);
445
+ return display || cachedValue || documentFieldLabel(kind);
446
+ }
447
+ function normalizeDocumentFieldsHtml(source) {
448
+ const document = new DOMParser().parseFromString(source, 'text/html');
449
+ const usedIds = new Set();
450
+ for (const [index, element] of Array.from(document.body.querySelectorAll(FIELD_SELECTOR)).entries()){
451
+ const instruction = element.dataset.fieldInstruction?.trim() ?? '';
452
+ const kind = documentFieldKind(element.dataset.fieldKind) ?? docxDocumentFieldKind(instruction);
453
+ if (!kind) {
454
+ element.replaceWith(document.createTextNode(element.textContent ?? ''));
455
+ continue;
456
+ }
457
+ const display = element.dataset.fieldDisplay?.trim() || element.textContent?.trim() || documentFieldLabel(kind);
458
+ element.dataset.documentField = 'true';
459
+ element.dataset.fieldId = uniqueFieldId(element.dataset.fieldId, index + 1, usedIds);
460
+ element.dataset.fieldKind = kind;
461
+ element.dataset.fieldInstruction = instruction || documentFieldInstruction(kind);
462
+ element.dataset.fieldDisplay = display;
463
+ element.classList.add('work-document-field');
464
+ element.textContent = display;
465
+ }
466
+ return document.body.innerHTML;
467
+ }
468
+ function resolveDocumentFieldsHtml(source, context) {
469
+ const document = new DOMParser().parseFromString(normalizeDocumentFieldsHtml(source), 'text/html');
470
+ for (const element of Array.from(document.body.querySelectorAll(FIELD_SELECTOR))){
471
+ const kind = documentFieldKind(element.dataset.fieldKind);
472
+ if (!kind) continue;
473
+ const display = documentFieldDisplay(kind, context, element.dataset.fieldInstruction, element.dataset.fieldDisplay);
474
+ element.dataset.fieldDisplay = display;
475
+ element.textContent = display;
476
+ }
477
+ return document.body.innerHTML;
478
+ }
479
+ function uniqueFieldId(source, index, usedIds) {
480
+ const candidate = source?.trim();
481
+ if (candidate && !usedIds.has(candidate)) {
482
+ usedIds.add(candidate);
483
+ return candidate;
484
+ }
485
+ let suffix = index;
486
+ while(usedIds.has(`document-field-${suffix}`))suffix += 1;
487
+ const id = `document-field-${suffix}`;
488
+ usedIds.add(id);
489
+ return id;
490
+ }
491
+ function dateFormatSwitch(instruction) {
492
+ return /\\@\s+"([^"]+)"/i.exec(instruction)?.[1] ?? null;
493
+ }
494
+ function formatWordDate(date, format) {
495
+ const hour12 = date.getHours() % 12 || 12;
496
+ const replacements = {
497
+ 'AM/PM': date.getHours() < 12 ? 'AM' : 'PM',
498
+ 'am/pm': date.getHours() < 12 ? 'am' : 'pm',
499
+ yyyy: String(date.getFullYear()).padStart(4, '0'),
500
+ yy: String(date.getFullYear() % 100).padStart(2, '0'),
501
+ MMMM: new Intl.DateTimeFormat('zh-CN', {
502
+ month: 'long'
503
+ }).format(date),
504
+ MMM: new Intl.DateTimeFormat('zh-CN', {
505
+ month: 'short'
506
+ }).format(date),
507
+ MM: String(date.getMonth() + 1).padStart(2, '0'),
508
+ M: String(date.getMonth() + 1),
509
+ dddd: new Intl.DateTimeFormat('zh-CN', {
510
+ weekday: 'long'
511
+ }).format(date),
512
+ ddd: new Intl.DateTimeFormat('zh-CN', {
513
+ weekday: 'short'
514
+ }).format(date),
515
+ dd: String(date.getDate()).padStart(2, '0'),
516
+ d: String(date.getDate()),
517
+ HH: String(date.getHours()).padStart(2, '0'),
518
+ H: String(date.getHours()),
519
+ hh: String(hour12).padStart(2, '0'),
520
+ h: String(hour12),
521
+ mm: String(date.getMinutes()).padStart(2, '0'),
522
+ m: String(date.getMinutes()),
523
+ ss: String(date.getSeconds()).padStart(2, '0'),
524
+ s: String(date.getSeconds())
525
+ };
526
+ return format.replace(/AM\/PM|am\/pm|yyyy|MMMM|dddd|MMM|ddd|yy|MM|dd|HH|hh|mm|ss|M|d|H|h|m|s/g, (token)=>replacements[token] ?? token);
527
+ }
528
+ function work_document_fields_positiveInteger(value) {
529
+ return Number.isSafeInteger(value) && value > 0 ? value : 1;
530
+ }
531
+ function validDate(value) {
532
+ return value && Number.isFinite(value.getTime()) ? value : null;
533
+ }
534
+ const NOTE_REFERENCE_SELECTOR = 'sup[data-document-note-reference]';
535
+ const NOTE_DEFINITION_SELECTOR = 'aside[data-document-note]';
536
+ function normalizeDocumentNotesHtml(source) {
537
+ const document = new DOMParser().parseFromString(source, 'text/html');
538
+ const definitions = new Map();
539
+ for (const element of Array.from(document.body.querySelectorAll(NOTE_DEFINITION_SELECTOR))){
540
+ const kind = documentNoteKind(element.dataset.noteKind);
541
+ const id = element.dataset.noteId?.trim();
542
+ if (!kind || !id) {
543
+ element.remove();
544
+ continue;
545
+ }
546
+ const key = documentNoteKey(kind, id);
547
+ if (definitions.has(key)) {
548
+ element.remove();
549
+ continue;
550
+ }
551
+ definitions.set(key, element);
552
+ }
553
+ const counters = {
554
+ footnote: 0,
555
+ endnote: 0
556
+ };
557
+ const numbers = new Map();
558
+ const references = new Map();
559
+ for (const element of Array.from(document.body.querySelectorAll(NOTE_REFERENCE_SELECTOR))){
560
+ const kind = documentNoteKind(element.dataset.noteKind) ?? 'footnote';
561
+ const id = element.dataset.noteId?.trim() || nextDocumentNoteId(kind, counters[kind] + 1, numbers);
562
+ const key = documentNoteKey(kind, id);
563
+ let number = numbers.get(key);
564
+ if (!number) {
565
+ counters[kind] += 1;
566
+ number = counters[kind];
567
+ numbers.set(key, number);
568
+ references.set(key, element);
569
+ }
570
+ applyDocumentNoteAttributes(element, kind, id, number, true);
571
+ element.textContent = String(number);
572
+ }
573
+ for (const [key, element] of definitions){
574
+ const number = numbers.get(key);
575
+ if (!number) {
576
+ element.remove();
577
+ continue;
578
+ }
579
+ const { kind, id } = splitDocumentNoteKey(key);
580
+ applyDocumentNoteAttributes(element, kind, id, number, false);
581
+ ensureDocumentNoteBlocks(element);
582
+ }
583
+ for (const [key, number] of numbers){
584
+ if (definitions.has(key)) continue;
585
+ const { kind, id } = splitDocumentNoteKey(key);
586
+ const note = createDocumentNoteElement(document, {
587
+ id,
588
+ kind,
589
+ number,
590
+ html: '<p></p>'
591
+ });
592
+ const reference = references.get(key);
593
+ const target = 'footnote' === kind ? reference?.closest('section[data-document-section]') : document.body.querySelector('section[data-document-section]:last-of-type');
594
+ (target ?? document.body).append(note);
595
+ }
596
+ return document.body.innerHTML;
597
+ }
598
+ function collectDocumentNotes(source) {
599
+ const html = normalizeDocumentNotesHtml(source);
600
+ const document = new DOMParser().parseFromString(html, 'text/html');
601
+ const definitions = new Map();
602
+ for (const element of Array.from(document.body.querySelectorAll(NOTE_DEFINITION_SELECTOR))){
603
+ const kind = documentNoteKind(element.dataset.noteKind);
604
+ const id = element.dataset.noteId?.trim();
605
+ if (kind && id) definitions.set(documentNoteKey(kind, id), element);
606
+ }
607
+ const seen = new Set();
608
+ const notes = [];
609
+ for (const reference of Array.from(document.body.querySelectorAll(NOTE_REFERENCE_SELECTOR))){
610
+ const kind = documentNoteKind(reference.dataset.noteKind);
611
+ const id = reference.dataset.noteId?.trim();
612
+ if (!kind || !id) continue;
613
+ const key = documentNoteKey(kind, id);
614
+ if (seen.has(key)) continue;
615
+ const definition = definitions.get(key);
616
+ if (definition) {
617
+ seen.add(key);
618
+ notes.push({
619
+ id,
620
+ kind,
621
+ number: work_document_notes_positiveInteger(reference.dataset.noteNumber, notes.length + 1),
622
+ html: definition.innerHTML || '<p></p>'
623
+ });
624
+ }
625
+ }
626
+ return {
627
+ html,
628
+ notes
629
+ };
630
+ }
631
+ function documentNoteReferenceKeys(source) {
632
+ const document = new DOMParser().parseFromString(source, 'text/html');
633
+ const keys = [];
634
+ for (const reference of Array.from(document.body.querySelectorAll(NOTE_REFERENCE_SELECTOR))){
635
+ const kind = documentNoteKind(reference.dataset.noteKind);
636
+ const id = reference.dataset.noteId?.trim();
637
+ if (kind && id) keys.push(documentNoteKey(kind, id));
638
+ }
639
+ return keys;
640
+ }
641
+ function removeDocumentNoteDefinitions(source) {
642
+ const document = new DOMParser().parseFromString(source, 'text/html');
643
+ for (const note of Array.from(document.body.querySelectorAll(NOTE_DEFINITION_SELECTOR)))note.remove();
644
+ return document.body.innerHTML;
645
+ }
646
+ function createDocumentNoteElement(document, note) {
647
+ const element = document.createElement('aside');
648
+ applyDocumentNoteAttributes(element, note.kind, note.id, note.number, false);
649
+ element.innerHTML = note.html || '<p></p>';
650
+ ensureDocumentNoteBlocks(element);
651
+ return element;
652
+ }
653
+ function documentNoteKey(kind, id) {
654
+ return `${kind}:${id}`;
655
+ }
656
+ function documentNoteKind(value) {
657
+ if ('footnote' === value || 'endnote' === value) return value;
658
+ return null;
659
+ }
660
+ function applyDocumentNoteAttributes(element, kind, id, number, reference) {
661
+ element.setAttribute(reference ? 'data-document-note-reference' : 'data-document-note', 'true');
662
+ element.setAttribute('data-note-kind', kind);
663
+ element.setAttribute('data-note-id', id);
664
+ element.setAttribute('data-note-number', String(number));
665
+ }
666
+ function splitDocumentNoteKey(key) {
667
+ const separator = key.indexOf(':');
668
+ return {
669
+ kind: key.slice(0, separator),
670
+ id: key.slice(separator + 1)
671
+ };
672
+ }
673
+ function nextDocumentNoteId(kind, seed, existing) {
674
+ let suffix = seed;
675
+ while(existing.has(documentNoteKey(kind, `document-${kind}-${suffix}`)))suffix += 1;
676
+ return `document-${kind}-${suffix}`;
677
+ }
678
+ function ensureDocumentNoteBlocks(element) {
679
+ if (element.children.length) return;
680
+ const text = element.textContent ?? '';
681
+ element.replaceChildren();
682
+ const paragraph = element.ownerDocument.createElement('p');
683
+ paragraph.textContent = text;
684
+ element.append(paragraph);
685
+ }
686
+ function work_document_notes_positiveInteger(value, fallback) {
687
+ const number = Number(value);
688
+ return Number.isSafeInteger(number) && number > 0 ? number : fallback;
689
+ }
690
+ const DEFAULT_DOCUMENT_COLUMNS = {
691
+ count: 1,
692
+ spacing: 12,
693
+ separator: false
694
+ };
695
+ const MAX_COLUMNS = 6;
696
+ const MIN_COLUMN_PERCENT = 5;
697
+ function normalizeDocumentColumns(columns) {
698
+ const customCount = Array.isArray(columns?.custom) ? columns.custom.length : 0;
699
+ const count = clampInteger(columns?.count, customCount || DEFAULT_DOCUMENT_COLUMNS.count, 1, MAX_COLUMNS);
700
+ const spacing = clampNumber(columns?.spacing, DEFAULT_DOCUMENT_COLUMNS.spacing, 0, 30);
701
+ const normalized = {
702
+ count,
703
+ spacing: roundOne(spacing),
704
+ separator: Boolean(columns?.separator)
705
+ };
706
+ if (count < 2 || !customCount) return normalized;
707
+ const source = columns?.custom ?? [];
708
+ const widths = normalizedPercentages(Array.from({
709
+ length: count
710
+ }, (_, index)=>finiteNumber(source[index]?.widthPercent, 100 / count)), 100, MIN_COLUMN_PERCENT);
711
+ normalized.custom = Array.from({
712
+ length: count
713
+ }, (_, index)=>({
714
+ widthPercent: widths[index],
715
+ spacing: index === count - 1 ? 0 : roundOne(clampNumber(source[index]?.spacing, normalized.spacing, 0, 30))
716
+ }));
717
+ return normalized;
718
+ }
719
+ function serializeDocumentColumns(columns) {
720
+ return JSON.stringify(normalizeDocumentColumns(columns));
721
+ }
722
+ function parseDocumentColumns(source, legacy = {}, fallback) {
723
+ if (source?.trim()) try {
724
+ return normalizeDocumentColumns(JSON.parse(source));
725
+ } catch {}
726
+ if (void 0 !== legacy.count || void 0 !== legacy.spacing || void 0 !== legacy.separator) return normalizeDocumentColumns(legacy);
727
+ return normalizeDocumentColumns(fallback);
728
+ }
729
+ function setCustomDocumentColumns(columns, enabled) {
730
+ const normalized = normalizeDocumentColumns(columns);
731
+ if (!enabled || normalized.count < 2) return {
732
+ ...normalized,
733
+ custom: void 0
734
+ };
735
+ if (normalized.custom) return normalized;
736
+ return normalizeDocumentColumns({
737
+ ...normalized,
738
+ custom: Array.from({
739
+ length: normalized.count
740
+ }, (_, index)=>({
741
+ widthPercent: 100 / normalized.count,
742
+ spacing: index === normalized.count - 1 ? 0 : normalized.spacing
743
+ }))
744
+ });
745
+ }
746
+ function updateDocumentColumnWidth(columns, index, widthPercent) {
747
+ const normalized = setCustomDocumentColumns(columns, true);
748
+ if (!normalized.custom?.[index]) return normalized;
749
+ const maximum = 100 - MIN_COLUMN_PERCENT * (normalized.custom.length - 1);
750
+ const target = Math.min(maximum, Math.max(MIN_COLUMN_PERCENT, finiteNumber(widthPercent, 100 / normalized.count)));
751
+ const otherIndexes = normalized.custom.map((_, itemIndex)=>itemIndex).filter((itemIndex)=>itemIndex !== index);
752
+ const otherWidths = normalizedPercentages(otherIndexes.map((itemIndex)=>normalized.custom?.[itemIndex].widthPercent ?? 1), 100 - target, MIN_COLUMN_PERCENT);
753
+ const custom = normalized.custom.map((column, itemIndex)=>{
754
+ const otherIndex = otherIndexes.indexOf(itemIndex);
755
+ return {
756
+ ...column,
757
+ widthPercent: itemIndex === index ? roundOne(target) : otherWidths[otherIndex]
758
+ };
759
+ });
760
+ return {
761
+ ...normalized,
762
+ custom
763
+ };
764
+ }
765
+ function normalizedPercentages(values, total, minimum) {
766
+ if (!values.length) return [];
767
+ const result = Array(values.length).fill(0);
768
+ const remaining = new Set(values.map((_, index)=>index));
769
+ let remainingTotal = total;
770
+ while(remaining.size){
771
+ const sourceTotal = Array.from(remaining).reduce((sum, index)=>sum + Math.max(0.001, finiteNumber(values[index], 1)), 0);
772
+ const belowMinimum = Array.from(remaining).filter((index)=>Math.max(0.001, finiteNumber(values[index], 1)) / sourceTotal * remainingTotal < minimum);
773
+ if (!belowMinimum.length) {
774
+ for (const index of remaining)result[index] = Math.max(0.001, finiteNumber(values[index], 1)) / sourceTotal * remainingTotal;
775
+ break;
776
+ }
777
+ for (const index of belowMinimum){
778
+ result[index] = minimum;
779
+ remaining.delete(index);
780
+ remainingTotal -= minimum;
781
+ }
782
+ }
783
+ const rounded = result.map(roundOne);
784
+ const adjustmentIndex = rounded.indexOf(Math.max(...rounded));
785
+ rounded[adjustmentIndex] = roundOne(rounded[adjustmentIndex] + total - rounded.reduce((sum, value)=>sum + value, 0));
786
+ return rounded;
787
+ }
788
+ function clampInteger(value, fallback, minimum, maximum) {
789
+ return Math.min(maximum, Math.max(minimum, Math.round(finiteNumber(value, fallback))));
790
+ }
791
+ function clampNumber(value, fallback, minimum, maximum) {
792
+ return Math.min(maximum, Math.max(minimum, finiteNumber(value, fallback)));
793
+ }
794
+ function finiteNumber(value, fallback) {
795
+ return Number.isFinite(value) ? Number(value) : fallback;
796
+ }
797
+ function roundOne(value) {
798
+ return Math.round(10 * value) / 10;
799
+ }
800
+ const EMPTY_CONTENT = {
801
+ headerHtml: '',
802
+ footerHtml: '',
803
+ showPageNumber: false
804
+ };
805
+ const ALLOWED_TAGS = new Set([
806
+ 'a',
807
+ 'b',
808
+ 'blockquote',
809
+ 'br',
810
+ 'div',
811
+ 'em',
812
+ 'i',
813
+ 'img',
814
+ 'li',
815
+ 'ol',
816
+ 'p',
817
+ 's',
818
+ 'span',
819
+ 'strike',
820
+ 'strong',
821
+ 'sub',
822
+ 'sup',
823
+ 'table',
824
+ 'tbody',
825
+ 'td',
826
+ 'th',
827
+ 'thead',
828
+ 'tr',
829
+ 'u',
830
+ 'ul'
831
+ ]);
832
+ function normalizeDocumentPageChrome(source, legacy = {}) {
833
+ const defaultContent = normalizePageChromeContent(source?.default, {
834
+ headerHtml: plainTextToPageChromeHtml(legacy.headerText),
835
+ footerHtml: plainTextToPageChromeHtml(legacy.footerText),
836
+ showPageNumber: Boolean(legacy.showPageNumbers)
837
+ });
838
+ return {
839
+ differentFirstPage: Boolean(source?.differentFirstPage),
840
+ differentOddEvenPages: Boolean(source?.differentOddEvenPages),
841
+ default: defaultContent,
842
+ first: normalizePageChromeContent(source?.first, EMPTY_CONTENT),
843
+ even: normalizePageChromeContent(source?.even, EMPTY_CONTENT)
844
+ };
845
+ }
846
+ function serializeDocumentPageChrome(chrome) {
847
+ return JSON.stringify(normalizeDocumentPageChrome(chrome));
848
+ }
849
+ function parseDocumentPageChrome(source, legacy = {}, fallback) {
850
+ if (source?.trim()) try {
851
+ const parsed = JSON.parse(source);
852
+ return normalizeDocumentPageChrome(parsed, legacy);
853
+ } catch {}
854
+ if (legacy.headerText || legacy.footerText || void 0 !== legacy.showPageNumbers) return normalizeDocumentPageChrome(void 0, legacy);
855
+ return normalizeDocumentPageChrome(fallback);
856
+ }
857
+ function resolveDocumentPageChrome(layout, sectionPage, physicalPage) {
858
+ const chrome = normalizeDocumentPageChrome(layout.pageChrome, layout);
859
+ const variant = chrome.differentFirstPage && 1 === sectionPage ? 'first' : chrome.differentOddEvenPages && physicalPage % 2 === 0 ? 'even' : 'default';
860
+ return {
861
+ variant,
862
+ ...chrome[variant]
863
+ };
864
+ }
865
+ function documentPageChromeLegacyFields(chrome) {
866
+ const normalized = normalizeDocumentPageChrome(chrome);
867
+ return {
868
+ headerText: pageChromePlainText(normalized.default.headerHtml) || void 0,
869
+ footerText: pageChromePlainText(normalized.default.footerHtml) || void 0,
870
+ showPageNumbers: normalized.default.showPageNumber
871
+ };
872
+ }
873
+ function updateDocumentPageChromeVariant(chrome, variant, patch) {
874
+ const normalized = normalizeDocumentPageChrome(chrome);
875
+ return {
876
+ ...normalized,
877
+ [variant]: normalizePageChromeContent({
878
+ ...normalized[variant],
879
+ ...patch
880
+ }, EMPTY_CONTENT)
881
+ };
882
+ }
883
+ function pageChromePlainText(source) {
884
+ if (!source.trim()) return '';
885
+ const document = new DOMParser().parseFromString(source, 'text/html');
886
+ const blocks = Array.from(document.body.querySelectorAll('p, div, li')).map((element)=>element.textContent?.replace(/\s+/g, ' ').trim() ?? '').filter(Boolean);
887
+ return (blocks.length ? blocks.join('\n') : document.body.textContent ?? '').trim();
888
+ }
889
+ function sanitizeDocumentPageChromeHtml(source) {
890
+ if (!source?.trim()) return '';
891
+ const document = new DOMParser().parseFromString(source, 'text/html');
892
+ for (const element of Array.from(document.body.querySelectorAll("script, iframe, object, embed, link, meta")))element.remove();
893
+ for (const font of Array.from(document.body.querySelectorAll('font'))){
894
+ const span = document.createElement('span');
895
+ const color = font.getAttribute('color')?.trim();
896
+ if (font.getAttribute('style')) span.setAttribute('style', font.getAttribute('style') ?? '');
897
+ if (color && !span.style.color) span.style.color = color;
898
+ span.append(...Array.from(font.childNodes));
899
+ font.replaceWith(span);
900
+ }
901
+ for (const element of Array.from(document.body.querySelectorAll('*'))){
902
+ const tag = element.tagName.toLowerCase();
903
+ if (!ALLOWED_TAGS.has(tag)) {
904
+ element.replaceWith(...Array.from(element.childNodes));
905
+ continue;
906
+ }
907
+ sanitizeAttributes(element, tag);
908
+ }
909
+ if (!(document.body.textContent ?? '').trim() && !document.body.querySelector('img, table')) return '';
910
+ return document.body.innerHTML;
911
+ }
912
+ function plainTextToPageChromeHtml(source) {
913
+ const lines = source?.split(/\r?\n/).map((line)=>line.trim()).filter(Boolean);
914
+ if (!lines?.length) return '';
915
+ return lines.map((line)=>`<p style="text-align: center">${escapeHtml(line)}</p>`).join('');
916
+ }
917
+ function normalizePageChromeContent(source, fallback) {
918
+ return {
919
+ headerHtml: sanitizeDocumentPageChromeHtml(source?.headerHtml ?? fallback.headerHtml),
920
+ footerHtml: sanitizeDocumentPageChromeHtml(source?.footerHtml ?? fallback.footerHtml),
921
+ showPageNumber: source?.showPageNumber ?? fallback.showPageNumber
922
+ };
923
+ }
924
+ function sanitizeAttributes(element, tag) {
925
+ for (const attribute of Array.from(element.attributes))if (attribute.name.toLowerCase().startsWith('on')) element.removeAttribute(attribute.name);
926
+ const textAlign = [
927
+ 'left',
928
+ 'center',
929
+ 'right',
930
+ 'justify'
931
+ ].includes(element.style.textAlign) ? element.style.textAlign : '';
932
+ const color = element.style.color;
933
+ const direction = element.getAttribute('dir')?.trim().toLowerCase();
934
+ element.removeAttribute('style');
935
+ const styles = [
936
+ textAlign ? `text-align: ${textAlign}` : '',
937
+ color ? `color: ${color}` : ''
938
+ ].filter(Boolean);
939
+ if (styles.length) element.setAttribute('style', styles.join('; '));
940
+ if ('a' === tag) {
941
+ const href = element.getAttribute('href')?.trim() ?? '';
942
+ if (!/^(?:https?:|mailto:|#)/i.test(href)) element.removeAttribute('href');
943
+ } else if ('img' === tag) {
944
+ const source = element.getAttribute('src')?.trim() ?? '';
945
+ if (!/^(?:https?:|blob:|data:image\/)/i.test(source)) element.removeAttribute('src');
946
+ } else if ('ol' === tag) {
947
+ const start = Number(element.getAttribute('start'));
948
+ if (!Number.isSafeInteger(start) || start <= 0) element.removeAttribute('start');
949
+ const type = element.getAttribute('type');
950
+ if (type && ![
951
+ '1',
952
+ 'A',
953
+ 'a',
954
+ 'I',
955
+ 'i'
956
+ ].includes(type)) element.removeAttribute('type');
957
+ }
958
+ if ('ltr' === direction || 'rtl' === direction) element.setAttribute('dir', direction);
959
+ else element.removeAttribute('dir');
960
+ const allowed = 'a' === tag ? new Set([
961
+ 'dir',
962
+ 'href',
963
+ 'title',
964
+ 'style'
965
+ ]) : 'img' === tag ? new Set([
966
+ 'dir',
967
+ 'src',
968
+ 'alt',
969
+ 'title',
970
+ 'width',
971
+ 'height',
972
+ 'style'
973
+ ]) : 'ol' === tag ? new Set([
974
+ 'dir',
975
+ 'start',
976
+ 'style',
977
+ 'type'
978
+ ]) : new Set([
979
+ 'colspan',
980
+ 'dir',
981
+ 'rowspan',
982
+ 'style'
983
+ ]);
984
+ for (const attribute of Array.from(element.attributes))if (!allowed.has(attribute.name.toLowerCase())) element.removeAttribute(attribute.name);
985
+ }
986
+ function escapeHtml(value) {
987
+ return value.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('"', '&quot;');
988
+ }
989
+ const DOCUMENT_MODEL_SCHEMA = 'a3s.office.document';
990
+ const DOCUMENT_MODEL_VERSION = 1;
991
+ const MAX_DOCUMENT_MODEL_DEPTH = 256;
992
+ const MAX_DOCUMENT_MODEL_NODES = 100000;
993
+ const MAX_DOCUMENT_MODEL_MARKS = 500000;
994
+ const MAX_DOCUMENT_MODEL_ATTRIBUTE_VALUES = 1000000;
995
+ function createWorkDocumentModel(html, root, previous) {
996
+ return {
997
+ schema: DOCUMENT_MODEL_SCHEMA,
998
+ version: DOCUMENT_MODEL_VERSION,
999
+ revision: nextRevision(previous),
1000
+ htmlFingerprint: documentHtmlFingerprint(html),
1001
+ root
1002
+ };
1003
+ }
1004
+ function documentModelForContent(content) {
1005
+ return documentModelForHtml(content.model, content.html);
1006
+ }
1007
+ function documentModelForHtml(candidate, html) {
1008
+ if (!isRecord(candidate)) return null;
1009
+ if (candidate.schema !== DOCUMENT_MODEL_SCHEMA || candidate.version !== DOCUMENT_MODEL_VERSION || !Number.isSafeInteger(candidate.revision) || Number(candidate.revision) < 1 || candidate.htmlFingerprint !== documentHtmlFingerprint(html) || !isDocumentRoot(candidate.root)) return null;
1010
+ return candidate;
1011
+ }
1012
+ function resolveWorkDocumentEditorInput(content, fallbackHtml) {
1013
+ const model = documentModelForHtml(content.model, fallbackHtml);
1014
+ if (!model) return {
1015
+ model: null,
1016
+ source: fallbackHtml,
1017
+ sourceKey: `html:${documentHtmlFingerprint(fallbackHtml)}`,
1018
+ revision: 0
1019
+ };
1020
+ return {
1021
+ model,
1022
+ source: model.root,
1023
+ sourceKey: `model:${model.revision}:${model.htmlFingerprint}`,
1024
+ revision: model.revision
1025
+ };
1026
+ }
1027
+ function documentHtmlFingerprint(html) {
1028
+ let hash = 0x811c9dc5;
1029
+ for(let index = 0; index < html.length; index += 1){
1030
+ hash ^= html.charCodeAt(index);
1031
+ hash = Math.imul(hash, 0x01000193);
1032
+ }
1033
+ return `${html.length.toString(36)}:${(hash >>> 0).toString(36)}`;
1034
+ }
1035
+ function nextRevision(previous) {
1036
+ const revision = previous?.schema === DOCUMENT_MODEL_SCHEMA && previous.version === DOCUMENT_MODEL_VERSION && Number.isSafeInteger(previous.revision) && previous.revision > 0 ? previous.revision : 0;
1037
+ return revision >= Number.MAX_SAFE_INTEGER ? 1 : revision + 1;
1038
+ }
1039
+ function isDocumentRoot(value) {
1040
+ if (!isRecord(value) || 'doc' !== value.type) return false;
1041
+ const nodes = [
1042
+ {
1043
+ value,
1044
+ depth: 0
1045
+ }
1046
+ ];
1047
+ const seen = new WeakSet();
1048
+ let nodeCount = 0;
1049
+ let markCount = 0;
1050
+ let attributeValueCount = 0;
1051
+ while(nodes.length){
1052
+ const current = nodes.pop();
1053
+ if (!current || !isRecord(current.value)) return false;
1054
+ if (current.depth > MAX_DOCUMENT_MODEL_DEPTH || seen.has(current.value)) return false;
1055
+ seen.add(current.value);
1056
+ nodeCount += 1;
1057
+ if (nodeCount > MAX_DOCUMENT_MODEL_NODES) return false;
1058
+ if ('string' != typeof current.value.type || !current.value.type.trim() || void 0 !== current.value.text && 'string' != typeof current.value.text) return false;
1059
+ if ('text' === current.value.type && 'string' != typeof current.value.text) return false;
1060
+ if (void 0 !== current.value.attrs) {
1061
+ const result = validateAttributes(current.value.attrs, attributeValueCount);
1062
+ if (!result.valid) return false;
1063
+ attributeValueCount = result.count;
1064
+ }
1065
+ if (void 0 !== current.value.marks) {
1066
+ if (!Array.isArray(current.value.marks)) return false;
1067
+ markCount += current.value.marks.length;
1068
+ if (markCount > MAX_DOCUMENT_MODEL_MARKS) return false;
1069
+ for (const mark of current.value.marks){
1070
+ if (!isDocumentMark(mark)) return false;
1071
+ if (void 0 !== mark.attrs) {
1072
+ const result = validateAttributes(mark.attrs, attributeValueCount);
1073
+ if (!result.valid) return false;
1074
+ attributeValueCount = result.count;
1075
+ }
1076
+ }
1077
+ }
1078
+ if (void 0 !== current.value.content) {
1079
+ if (!Array.isArray(current.value.content)) return false;
1080
+ for(let index = current.value.content.length - 1; index >= 0; index -= 1)nodes.push({
1081
+ value: current.value.content[index],
1082
+ depth: current.depth + 1
1083
+ });
1084
+ }
1085
+ }
1086
+ return true;
1087
+ }
1088
+ function isDocumentMark(value) {
1089
+ return isRecord(value) && 'string' == typeof value.type && Boolean(value.type.trim()) && (void 0 === value.attrs || isRecord(value.attrs));
1090
+ }
1091
+ function validateAttributes(value, initialCount) {
1092
+ if (!isRecord(value)) return {
1093
+ valid: false,
1094
+ count: initialCount
1095
+ };
1096
+ const values = Object.values(value);
1097
+ const stack = values.map((item)=>({
1098
+ item,
1099
+ depth: 0
1100
+ }));
1101
+ const seen = new WeakSet();
1102
+ let count = initialCount;
1103
+ while(stack.length){
1104
+ const current = stack.pop();
1105
+ if (!current) break;
1106
+ count += 1;
1107
+ if (count > MAX_DOCUMENT_MODEL_ATTRIBUTE_VALUES || current.depth > 32) return {
1108
+ valid: false,
1109
+ count
1110
+ };
1111
+ if (null === current.item || 'string' == typeof current.item || 'boolean' == typeof current.item || 'number' == typeof current.item && Number.isFinite(current.item)) continue;
1112
+ if ('object' != typeof current.item) return {
1113
+ valid: false,
1114
+ count
1115
+ };
1116
+ if (seen.has(current.item)) return {
1117
+ valid: false,
1118
+ count
1119
+ };
1120
+ seen.add(current.item);
1121
+ const nested = Array.isArray(current.item) ? current.item : Object.values(current.item);
1122
+ for (const item of nested)stack.push({
1123
+ item,
1124
+ depth: current.depth + 1
1125
+ });
1126
+ }
1127
+ return {
1128
+ valid: true,
1129
+ count
1130
+ };
1131
+ }
1132
+ function isRecord(value) {
1133
+ return 'object' == typeof value && null !== value && !Array.isArray(value);
1134
+ }
1135
+ const SECTION_SELECTOR = 'section[data-document-section]';
1136
+ function documentInitialSectionLayout(content) {
1137
+ const pageChrome = normalizeDocumentPageChrome(content.pageChrome, content);
1138
+ const legacy = documentPageChromeLegacyFields(pageChrome);
1139
+ return {
1140
+ pageSize: content.pageSize,
1141
+ orientation: content.orientation ?? 'portrait',
1142
+ margins: documentMargins(content),
1143
+ columns: normalizeDocumentColumns(content.columns),
1144
+ breakAfter: 'nextPage',
1145
+ headerText: legacy.headerText,
1146
+ footerText: legacy.footerText,
1147
+ showPageNumbers: legacy.showPageNumbers,
1148
+ pageNumberStart: validPageNumber(content.pageNumberStart),
1149
+ pageChrome
1150
+ };
1151
+ }
1152
+ function normalizeDocumentHtml(content) {
1153
+ const document = new DOMParser().parseFromString(content.html, 'text/html');
1154
+ const directSections = Array.from(document.body.children).filter((element)=>element.matches(SECTION_SELECTOR));
1155
+ if (!directSections.length) {
1156
+ const section = document.createElement('section');
1157
+ applyDocumentSectionDomAttributes(section, documentInitialSectionLayout(content), 'document-section-1');
1158
+ while(document.body.firstChild)section.append(document.body.firstChild);
1159
+ if (!section.childNodes.length) section.innerHTML = '<p></p>';
1160
+ document.body.append(section);
1161
+ return normalizeDocumentSemanticHtml(document.body.innerHTML, content.bibliography);
1162
+ }
1163
+ let activeSection = directSections[0];
1164
+ for (const node of Array.from(document.body.childNodes)){
1165
+ if (node instanceof HTMLElement && node.matches(SECTION_SELECTOR)) {
1166
+ activeSection = node;
1167
+ continue;
1168
+ }
1169
+ activeSection.append(node);
1170
+ }
1171
+ let fallback = documentInitialSectionLayout(content);
1172
+ directSections.forEach((element, index)=>{
1173
+ const layout = documentSectionLayoutFromElement(element, fallback);
1174
+ applyDocumentSectionDomAttributes(element, layout, element.getAttribute('data-section-id') || `document-section-${index + 1}`);
1175
+ if (!element.childNodes.length) element.innerHTML = '<p></p>';
1176
+ fallback = layout;
1177
+ });
1178
+ return normalizeDocumentSemanticHtml(document.body.innerHTML, content.bibliography);
1179
+ }
1180
+ function documentSections(content) {
1181
+ const document = new DOMParser().parseFromString(normalizeDocumentHtml(content), 'text/html');
1182
+ let fallback = documentInitialSectionLayout(content);
1183
+ return Array.from(document.body.querySelectorAll(`:scope > ${SECTION_SELECTOR}`)).map((element, index)=>{
1184
+ const layout = documentSectionLayoutFromElement(element, fallback);
1185
+ fallback = layout;
1186
+ return {
1187
+ id: element.dataset.sectionId || `document-section-${index + 1}`,
1188
+ layout,
1189
+ html: element.innerHTML || '<p></p>'
1190
+ };
1191
+ });
1192
+ }
1193
+ function documentSectionNodeAttributes(layout, id) {
1194
+ const columns = normalizeDocumentColumns(layout.columns);
1195
+ const pageChrome = normalizeDocumentPageChrome(layout.pageChrome, layout);
1196
+ const legacy = documentPageChromeLegacyFields(pageChrome);
1197
+ return {
1198
+ id,
1199
+ pageSize: layout.pageSize,
1200
+ orientation: layout.orientation,
1201
+ marginTop: layout.margins.top,
1202
+ marginRight: layout.margins.right,
1203
+ marginBottom: layout.margins.bottom,
1204
+ marginLeft: layout.margins.left,
1205
+ columnCount: columns.count,
1206
+ columnSpacing: columns.spacing,
1207
+ columnSeparator: columns.separator,
1208
+ columnLayout: serializeDocumentColumns(columns),
1209
+ breakAfter: validBreakType(layout.breakAfter),
1210
+ headerText: legacy.headerText ?? '',
1211
+ footerText: legacy.footerText ?? '',
1212
+ showPageNumbers: Boolean(legacy.showPageNumbers),
1213
+ pageNumberStart: validPageNumber(layout.pageNumberStart) ?? null,
1214
+ pageChrome: serializeDocumentPageChrome(pageChrome)
1215
+ };
1216
+ }
1217
+ function documentSectionLayoutFromNodeAttributes(attributes, fallback) {
1218
+ const base = fallback ?? {
1219
+ pageSize: 'a4',
1220
+ orientation: 'portrait',
1221
+ margins: {
1222
+ top: 25,
1223
+ right: 23,
1224
+ bottom: 25,
1225
+ left: 23
1226
+ },
1227
+ columns: DEFAULT_DOCUMENT_COLUMNS,
1228
+ breakAfter: 'nextPage'
1229
+ };
1230
+ const pageChrome = parseDocumentPageChrome(attributes.pageChrome, {
1231
+ headerText: attributes.headerText,
1232
+ footerText: attributes.footerText,
1233
+ showPageNumbers: attributes.showPageNumbers
1234
+ }, base.pageChrome);
1235
+ const legacy = documentPageChromeLegacyFields(pageChrome);
1236
+ return {
1237
+ pageSize: 'letter' === attributes.pageSize ? 'letter' : 'a4' === attributes.pageSize ? 'a4' : base.pageSize,
1238
+ orientation: 'landscape' === attributes.orientation ? 'landscape' : 'portrait' === attributes.orientation ? 'portrait' : base.orientation,
1239
+ margins: {
1240
+ top: clampDocumentMargin(work_document_section_finiteNumber(attributes.marginTop, base.margins.top)),
1241
+ right: clampDocumentMargin(work_document_section_finiteNumber(attributes.marginRight, base.margins.right)),
1242
+ bottom: clampDocumentMargin(work_document_section_finiteNumber(attributes.marginBottom, base.margins.bottom)),
1243
+ left: clampDocumentMargin(work_document_section_finiteNumber(attributes.marginLeft, base.margins.left))
1244
+ },
1245
+ columns: parseDocumentColumns(attributes.columnLayout, {
1246
+ count: attributes.columnCount,
1247
+ spacing: attributes.columnSpacing,
1248
+ separator: attributes.columnSeparator
1249
+ }, base.columns),
1250
+ breakAfter: validBreakType(attributes.breakAfter ?? base.breakAfter),
1251
+ headerText: legacy.headerText,
1252
+ footerText: legacy.footerText,
1253
+ showPageNumbers: legacy.showPageNumbers,
1254
+ pageNumberStart: validPageNumber(attributes.pageNumberStart ?? void 0),
1255
+ pageChrome
1256
+ };
1257
+ }
1258
+ function documentSectionDomAttributes(layout, id) {
1259
+ const attributes = documentSectionNodeAttributes(layout, id);
1260
+ return {
1261
+ 'data-document-section': 'true',
1262
+ 'data-section-id': attributes.id,
1263
+ 'data-section-page-size': attributes.pageSize,
1264
+ 'data-section-orientation': attributes.orientation,
1265
+ 'data-section-margin-top': String(attributes.marginTop),
1266
+ 'data-section-margin-right': String(attributes.marginRight),
1267
+ 'data-section-margin-bottom': String(attributes.marginBottom),
1268
+ 'data-section-margin-left': String(attributes.marginLeft),
1269
+ 'data-section-column-count': String(attributes.columnCount),
1270
+ 'data-section-column-spacing': String(attributes.columnSpacing),
1271
+ 'data-section-column-separator': String(attributes.columnSeparator),
1272
+ 'data-section-column-layout': attributes.columnLayout,
1273
+ 'data-section-break-after': attributes.breakAfter,
1274
+ 'data-section-header-text': attributes.headerText,
1275
+ 'data-section-footer-text': attributes.footerText,
1276
+ 'data-section-show-page-numbers': String(attributes.showPageNumbers),
1277
+ 'data-section-page-number-start': null === attributes.pageNumberStart ? '' : String(attributes.pageNumberStart),
1278
+ 'data-section-page-chrome': attributes.pageChrome
1279
+ };
1280
+ }
1281
+ function documentSectionLayoutFromElement(element, fallback) {
1282
+ return documentSectionLayoutFromNodeAttributes({
1283
+ pageSize: element.dataset.sectionPageSize,
1284
+ orientation: element.dataset.sectionOrientation,
1285
+ marginTop: numberValue(element.dataset.sectionMarginTop),
1286
+ marginRight: numberValue(element.dataset.sectionMarginRight),
1287
+ marginBottom: numberValue(element.dataset.sectionMarginBottom),
1288
+ marginLeft: numberValue(element.dataset.sectionMarginLeft),
1289
+ columnCount: numberValue(element.dataset.sectionColumnCount),
1290
+ columnSpacing: numberValue(element.dataset.sectionColumnSpacing),
1291
+ columnSeparator: 'true' === element.dataset.sectionColumnSeparator,
1292
+ columnLayout: element.dataset.sectionColumnLayout ?? '',
1293
+ breakAfter: element.dataset.sectionBreakAfter,
1294
+ headerText: element.dataset.sectionHeaderText ?? '',
1295
+ footerText: element.dataset.sectionFooterText ?? '',
1296
+ showPageNumbers: 'true' === element.dataset.sectionShowPageNumbers,
1297
+ pageNumberStart: numberValue(element.dataset.sectionPageNumberStart) ?? null,
1298
+ pageChrome: element.dataset.sectionPageChrome ?? ''
1299
+ }, fallback);
1300
+ }
1301
+ function syncDocumentContentFromHtml(content, html) {
1302
+ const normalized = normalizeDocumentHtml({
1303
+ ...content,
1304
+ html
1305
+ });
1306
+ const first = documentSections({
1307
+ ...content,
1308
+ html: normalized
1309
+ })[0]?.layout ?? documentInitialSectionLayout(content);
1310
+ const nextContent = {
1311
+ ...content
1312
+ };
1313
+ const model = documentModelForHtml(content.model, normalized);
1314
+ if (model) nextContent.model = model;
1315
+ else delete nextContent.model;
1316
+ return {
1317
+ ...nextContent,
1318
+ html: normalized,
1319
+ pageSize: first.pageSize,
1320
+ orientation: first.orientation,
1321
+ margins: first.margins,
1322
+ columns: first.columns,
1323
+ headerText: first.headerText,
1324
+ footerText: first.footerText,
1325
+ showPageNumbers: first.showPageNumbers,
1326
+ pageNumberStart: first.pageNumberStart,
1327
+ pageChrome: first.pageChrome
1328
+ };
1329
+ }
1330
+ function documentContentLayoutProperties(layout) {
1331
+ return {
1332
+ pageSize: layout.pageSize,
1333
+ orientation: layout.orientation,
1334
+ margins: layout.margins,
1335
+ columns: layout.columns,
1336
+ headerText: layout.headerText,
1337
+ footerText: layout.footerText,
1338
+ showPageNumbers: layout.showPageNumbers,
1339
+ pageNumberStart: layout.pageNumberStart,
1340
+ pageChrome: layout.pageChrome
1341
+ };
1342
+ }
1343
+ function normalizeDocumentSemanticHtml(source, bibliography) {
1344
+ return normalizeDocumentCitationsHtml(normalizeDocumentFieldsHtml(normalizeDocumentCaptionsHtml(normalizeDocumentNotesHtml(source))), bibliography);
1345
+ }
1346
+ function applyDocumentSectionDomAttributes(element, layout, id) {
1347
+ for (const [name, value] of Object.entries(documentSectionDomAttributes(layout, id)))element.setAttribute(name, value);
1348
+ }
1349
+ function validBreakType(value) {
1350
+ if ('continuous' === value || 'evenPage' === value || 'oddPage' === value || 'nextColumn' === value) return value;
1351
+ return 'nextPage';
1352
+ }
1353
+ function validPageNumber(value) {
1354
+ return Number.isFinite(value) && Number(value) > 0 ? Math.min(9999, Math.round(Number(value))) : void 0;
1355
+ }
1356
+ function work_document_section_finiteNumber(value, fallback) {
1357
+ return Number.isFinite(value) ? Number(value) : fallback;
1358
+ }
1359
+ function numberValue(value) {
1360
+ if (!value?.trim()) return;
1361
+ const parsed = Number(value);
1362
+ return Number.isFinite(parsed) ? parsed : void 0;
1363
+ }
1364
+ export { clampDocumentMargin, collectDocumentNotes, createDocumentBibliography, createDocumentNoteElement, createWorkDocumentModel, documentCaptionDisplay, documentCaptionKind, documentCaptionLabel, documentCitationInstruction, documentCitationStyle, documentCitationStyleDetails, documentCitationTags, documentCitationTagsFromInstruction, documentContentLayoutProperties, documentFieldDisplay, documentFieldInstruction, documentFieldKind, documentFieldLabel, documentHtmlFingerprint, documentInitialSectionLayout, documentMargins, documentModelForContent, documentNoteKey, documentNoteKind, documentNoteReferenceKeys, documentPageChromeLegacyFields, documentSectionDomAttributes, documentSectionLayoutFromNodeAttributes, documentSectionNodeAttributes, documentSections, docxDocumentFieldKind, isValidDocumentCitationTag, millimetersToPixels, normalizeDocumentCaptionsHtml, normalizeDocumentCitationsHtml, normalizeDocumentColumns, normalizeDocumentFieldsHtml, normalizeDocumentHtml, normalizeDocumentNotesHtml, normalizeDocumentPageChrome, removeDocumentNoteDefinitions, renameDocumentCitationTagInInstruction, renderDocumentBibliographyHtml, resolveDocumentCitation, resolveDocumentFieldsHtml, resolveDocumentPageChrome, resolveWorkDocumentEditorInput, sanitizeDocumentPageChromeHtml, setCustomDocumentColumns, syncDocumentContentFromHtml, updateDocumentColumnWidth, updateDocumentPageChromeVariant };