@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.
- package/LICENSE +21 -0
- package/README.md +470 -0
- package/THIRD_PARTY_NOTICES.md +33 -0
- package/dist/0~1403.js +245 -0
- package/dist/0~152.js +94 -0
- package/dist/0~3539.js +1856 -0
- package/dist/0~3557.js +179 -0
- package/dist/0~3635.js +302 -0
- package/dist/0~4595.js +1162 -0
- package/dist/0~5050.js +308 -0
- package/dist/0~6552.js +787 -0
- package/dist/0~7048.js +2110 -0
- package/dist/0~7614.js +1037 -0
- package/dist/0~8155.js +299 -0
- package/dist/0~9445.js +283 -0
- package/dist/0~9512.js +743 -0
- package/dist/0~document-editor.js +10967 -0
- package/dist/0~markdown-editor.js +2260 -0
- package/dist/0~pdf-viewer.js +2156 -0
- package/dist/0~presentation-editor.js +8359 -0
- package/dist/0~rslib-runtime.js +27 -0
- package/dist/0~spreadsheet-editor.js +10388 -0
- package/dist/0~use-office-draft.js +46 -0
- package/dist/0~work-document-extensions.js +2470 -0
- package/dist/0~work-document-links.js +14 -0
- package/dist/0~work-document-model-codec.js +42 -0
- package/dist/0~work-document-page-color.js +11 -0
- package/dist/0~work-document-paragraph-formatting.js +425 -0
- package/dist/0~work-docx-bibliography.js +347 -0
- package/dist/0~work-docx-export.js +1151 -0
- package/dist/0~work-docx-import.js +3116 -0
- package/dist/0~work-docx-page-color.js +42 -0
- package/dist/0~work-office-diagnostics.js +1377 -0
- package/dist/0~work-pptx-export.js +1009 -0
- package/dist/0~work-pptx-import.js +1138 -0
- package/dist/0~work-presentation-charts.js +442 -0
- package/dist/0~work-presentation-transition.js +38 -0
- package/dist/0~work-presentation-visual-scale.js +38 -0
- package/dist/0~work-spreadsheet-formula-support.js +9 -0
- package/dist/1134.js +445 -0
- package/dist/4104.js +5786 -0
- package/dist/432.js +211 -0
- package/dist/4704.js +1364 -0
- package/dist/6489.js +182 -0
- package/dist/8715.js +3959 -0
- package/dist/8728.js +723 -0
- package/dist/9356.js +10 -0
- package/dist/core.d.ts +15 -0
- package/dist/core.js +4 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/internal/design-system/primitives/button/button.d.ts +9 -0
- package/dist/internal/design-system/primitives/button/icon-button.d.ts +7 -0
- package/dist/internal/design-system/primitives/dialog/dialog.d.ts +12 -0
- package/dist/internal/design-system/primitives/feedback/collection-state.d.ts +9 -0
- package/dist/internal/design-system/primitives/feedback/inline-notice.d.ts +10 -0
- package/dist/internal/design-system/primitives/feedback/state-view.d.ts +13 -0
- package/dist/internal/design-system/primitives/form/field.d.ts +19 -0
- package/dist/internal/design-system/primitives/index.d.ts +14 -0
- package/dist/internal/design-system/primitives/layout/split-handle.d.ts +17 -0
- package/dist/internal/design-system/primitives/navigation/segmented-control.d.ts +19 -0
- package/dist/internal/design-system/primitives/navigation/tab-navigation.d.ts +13 -0
- package/dist/internal/design-system/primitives/navigation/tabs.d.ts +21 -0
- package/dist/internal/design-system/primitives/overlay/dialog-focus-scope.d.ts +17 -0
- package/dist/internal/design-system/primitives/overlay/popover.d.ts +34 -0
- package/dist/internal/design-system/primitives/overlay/portal-root.d.ts +1 -0
- package/dist/internal/design-system/primitives/status/status-badge.d.ts +6 -0
- package/dist/internal/features/work/components/work-document-pages.d.ts +4 -0
- package/dist/internal/features/work/components/work-editor-agent-menus.d.ts +12 -0
- package/dist/internal/features/work/components/work-editor-loading-state.d.ts +3 -0
- package/dist/internal/features/work/editors/document-changes-panel.d.ts +9 -0
- package/dist/internal/features/work/editors/document-citation-source-form.d.ts +33 -0
- package/dist/internal/features/work/editors/document-citations-panel.d.ts +8 -0
- package/dist/internal/features/work/editors/document-columns-panel.d.ts +5 -0
- package/dist/internal/features/work/editors/document-comment-composer.d.ts +13 -0
- package/dist/internal/features/work/editors/document-comments-panel.d.ts +17 -0
- package/dist/internal/features/work/editors/document-editor-focus.d.ts +1 -0
- package/dist/internal/features/work/editors/document-editor-pagination.d.ts +3 -0
- package/dist/internal/features/work/editors/document-editor-support.d.ts +34 -0
- package/dist/internal/features/work/editors/document-editor.d.ts +20 -0
- package/dist/internal/features/work/editors/document-find-highlight.d.ts +8 -0
- package/dist/internal/features/work/editors/document-find-replace-panel.d.ts +10 -0
- package/dist/internal/features/work/editors/document-formatting-options.d.ts +113 -0
- package/dist/internal/features/work/editors/document-home-ribbon.d.ts +9 -0
- package/dist/internal/features/work/editors/document-layout-panel.d.ts +10 -0
- package/dist/internal/features/work/editors/document-list-gallery.d.ts +4 -0
- package/dist/internal/features/work/editors/document-navigation-panel.d.ts +9 -0
- package/dist/internal/features/work/editors/document-page-chrome-editor.d.ts +39 -0
- package/dist/internal/features/work/editors/document-page-chrome-panel.d.ts +5 -0
- package/dist/internal/features/work/editors/document-page-chrome-ribbon.d.ts +10 -0
- package/dist/internal/features/work/editors/document-page-navigation.d.ts +14 -0
- package/dist/internal/features/work/editors/document-page-stack.d.ts +8 -0
- package/dist/internal/features/work/editors/document-pagination-popover.d.ts +4 -0
- package/dist/internal/features/work/editors/document-paragraph-spacing-popover.d.ts +4 -0
- package/dist/internal/features/work/editors/document-picture-ribbon.d.ts +4 -0
- package/dist/internal/features/work/editors/document-ruler-tab-stops.d.ts +12 -0
- package/dist/internal/features/work/editors/document-ruler.d.ts +15 -0
- package/dist/internal/features/work/editors/document-selection-context-menu.d.ts +22 -0
- package/dist/internal/features/work/editors/document-selection-toolbar.d.ts +8 -0
- package/dist/internal/features/work/editors/document-status-bar.d.ts +19 -0
- package/dist/internal/features/work/editors/document-style-gallery.d.ts +4 -0
- package/dist/internal/features/work/editors/document-table-insert-popover.d.ts +4 -0
- package/dist/internal/features/work/editors/document-table-ribbon.d.ts +7 -0
- package/dist/internal/features/work/editors/document-task-pane.d.ts +11 -0
- package/dist/internal/features/work/editors/document-toolbar.d.ts +100 -0
- package/dist/internal/features/work/editors/document-vertical-ruler.d.ts +6 -0
- package/dist/internal/features/work/editors/markdown-editor-focus.d.ts +2 -0
- package/dist/internal/features/work/editors/markdown-editor.d.ts +16 -0
- package/dist/internal/features/work/editors/markdown-insert-dialog.d.ts +19 -0
- package/dist/internal/features/work/editors/markdown-selection-context-menu.d.ts +14 -0
- package/dist/internal/features/work/editors/markdown-source-commands.d.ts +41 -0
- package/dist/internal/features/work/editors/markdown-status.d.ts +7 -0
- package/dist/internal/features/work/editors/markdown-toolbar.d.ts +22 -0
- package/dist/internal/features/work/editors/markdown-workspace.d.ts +26 -0
- package/dist/internal/features/work/editors/office-checkbox.d.ts +9 -0
- package/dist/internal/features/work/editors/office-color-picker.d.ts +11 -0
- package/dist/internal/features/work/editors/office-controls.d.ts +7 -0
- package/dist/internal/features/work/editors/office-dialog.d.ts +35 -0
- package/dist/internal/features/work/editors/office-editor-extension.d.ts +86 -0
- package/dist/internal/features/work/editors/office-file-data.d.ts +1 -0
- package/dist/internal/features/work/editors/office-font-families.d.ts +187 -0
- package/dist/internal/features/work/editors/office-menu-keyboard.d.ts +2 -0
- package/dist/internal/features/work/editors/office-number-field.d.ts +21 -0
- package/dist/internal/features/work/editors/office-number-normalization.d.ts +9 -0
- package/dist/internal/features/work/editors/office-select.d.ts +19 -0
- package/dist/internal/features/work/editors/office-shortcuts.d.ts +1 -0
- package/dist/internal/features/work/editors/office-slider.d.ts +10 -0
- package/dist/internal/features/work/editors/office-table-dimensions.d.ts +4 -0
- package/dist/internal/features/work/editors/office-table-insert-popover.d.ts +7 -0
- package/dist/internal/features/work/editors/office-task-pane.d.ts +7 -0
- package/dist/internal/features/work/editors/office-text-field.d.ts +20 -0
- package/dist/internal/features/work/editors/office-tiptap-extensions.d.ts +2 -0
- package/dist/internal/features/work/editors/pdf-annotation-controller.d.ts +23 -0
- package/dist/internal/features/work/editors/pdf-editor-extensions.d.ts +36 -0
- package/dist/internal/features/work/editors/pdf-thumbnail-rail.d.ts +26 -0
- package/dist/internal/features/work/editors/pdf-toolbar.d.ts +23 -0
- package/dist/internal/features/work/editors/pdf-viewer-controller.d.ts +48 -0
- package/dist/internal/features/work/editors/pdf-viewer.d.ts +11 -0
- package/dist/internal/features/work/editors/presentation-arrangement-controller.d.ts +19 -0
- package/dist/internal/features/work/editors/presentation-chart-analysis-canvas.d.ts +21 -0
- package/dist/internal/features/work/editors/presentation-chart-axis-canvas.d.ts +33 -0
- package/dist/internal/features/work/editors/presentation-chart-axis-editor.d.ts +5 -0
- package/dist/internal/features/work/editors/presentation-chart-canvas.d.ts +5 -0
- package/dist/internal/features/work/editors/presentation-chart-cartesian-canvas.d.ts +3 -0
- package/dist/internal/features/work/editors/presentation-chart-data-label-editor.d.ts +6 -0
- package/dist/internal/features/work/editors/presentation-chart-data-labels.d.ts +26 -0
- package/dist/internal/features/work/editors/presentation-chart-layout-editor.d.ts +5 -0
- package/dist/internal/features/work/editors/presentation-chart-legend-canvas.d.ts +15 -0
- package/dist/internal/features/work/editors/presentation-chart-panel.d.ts +7 -0
- package/dist/internal/features/work/editors/presentation-chart-series-analysis-editor.d.ts +6 -0
- package/dist/internal/features/work/editors/presentation-chart-series-canvas.d.ts +15 -0
- package/dist/internal/features/work/editors/presentation-command-controller.d.ts +3 -0
- package/dist/internal/features/work/editors/presentation-command-types.d.ts +206 -0
- package/dist/internal/features/work/editors/presentation-comments-panel.d.ts +9 -0
- package/dist/internal/features/work/editors/presentation-context-menu.d.ts +11 -0
- package/dist/internal/features/work/editors/presentation-design-panel.d.ts +13 -0
- package/dist/internal/features/work/editors/presentation-editor-focus.d.ts +12 -0
- package/dist/internal/features/work/editors/presentation-editor-operations.d.ts +10 -0
- package/dist/internal/features/work/editors/presentation-editor-types.d.ts +22 -0
- package/dist/internal/features/work/editors/presentation-editor.d.ts +3 -0
- package/dist/internal/features/work/editors/presentation-keyboard-extension.d.ts +3 -0
- package/dist/internal/features/work/editors/presentation-player.d.ts +7 -0
- package/dist/internal/features/work/editors/presentation-presenter-view.d.ts +15 -0
- package/dist/internal/features/work/editors/presentation-selection.d.ts +21 -0
- package/dist/internal/features/work/editors/presentation-slide-canvas.d.ts +26 -0
- package/dist/internal/features/work/editors/presentation-slide-thumbnail.d.ts +18 -0
- package/dist/internal/features/work/editors/presentation-status-bar.d.ts +10 -0
- package/dist/internal/features/work/editors/presentation-text-editor.d.ts +22 -0
- package/dist/internal/features/work/editors/presentation-text-formatting.d.ts +3 -0
- package/dist/internal/features/work/editors/presentation-thumbnail-rail.d.ts +20 -0
- package/dist/internal/features/work/editors/presentation-toolbar.d.ts +19 -0
- package/dist/internal/features/work/editors/presentation-transition-panel.d.ts +9 -0
- package/dist/internal/features/work/editors/presentation-workspace.d.ts +38 -0
- package/dist/internal/features/work/editors/spreadsheet-calculation-model.d.ts +8 -0
- package/dist/internal/features/work/editors/spreadsheet-calculation-projection.d.ts +32 -0
- package/dist/internal/features/work/editors/spreadsheet-chart-axis-editor.d.ts +9 -0
- package/dist/internal/features/work/editors/spreadsheet-chart-draft.d.ts +17 -0
- package/dist/internal/features/work/editors/spreadsheet-chart-layout-editor.d.ts +13 -0
- package/dist/internal/features/work/editors/spreadsheet-chart-panel.d.ts +10 -0
- package/dist/internal/features/work/editors/spreadsheet-chart-series-style-editor.d.ts +9 -0
- package/dist/internal/features/work/editors/spreadsheet-clipboard-shortcuts.d.ts +9 -0
- package/dist/internal/features/work/editors/spreadsheet-command-controller.d.ts +121 -0
- package/dist/internal/features/work/editors/spreadsheet-conditional-comparison-fields.d.ts +7 -0
- package/dist/internal/features/work/editors/spreadsheet-conditional-format-model.d.ts +72 -0
- package/dist/internal/features/work/editors/spreadsheet-conditional-format-panel.d.ts +7 -0
- package/dist/internal/features/work/editors/spreadsheet-conditional-threshold-fields.d.ts +10 -0
- package/dist/internal/features/work/editors/spreadsheet-context-menu.d.ts +36 -0
- package/dist/internal/features/work/editors/spreadsheet-data-label-editor.d.ts +9 -0
- package/dist/internal/features/work/editors/spreadsheet-editor-ribbon.d.ts +46 -0
- package/dist/internal/features/work/editors/spreadsheet-editor-support.d.ts +31 -0
- package/dist/internal/features/work/editors/spreadsheet-editor.d.ts +16 -0
- package/dist/internal/features/work/editors/spreadsheet-error-bar-editor.d.ts +10 -0
- package/dist/internal/features/work/editors/spreadsheet-find-bar.d.ts +8 -0
- package/dist/internal/features/work/editors/spreadsheet-find.d.ts +9 -0
- package/dist/internal/features/work/editors/spreadsheet-formula-panel.d.ts +10 -0
- package/dist/internal/features/work/editors/spreadsheet-header-footer-fields.d.ts +5 -0
- package/dist/internal/features/work/editors/spreadsheet-keyboard-navigation.d.ts +18 -0
- package/dist/internal/features/work/editors/spreadsheet-number-format.d.ts +11 -0
- package/dist/internal/features/work/editors/spreadsheet-pivot-panel.d.ts +10 -0
- package/dist/internal/features/work/editors/spreadsheet-print-settings-panel.d.ts +6 -0
- package/dist/internal/features/work/editors/spreadsheet-protection-panel.d.ts +7 -0
- package/dist/internal/features/work/editors/spreadsheet-sheet-bar.d.ts +17 -0
- package/dist/internal/features/work/editors/spreadsheet-sheet-model.d.ts +13 -0
- package/dist/internal/features/work/editors/spreadsheet-trendline-editor.d.ts +8 -0
- package/dist/internal/features/work/editors/spreadsheet-workbook-panel.d.ts +16 -0
- package/dist/internal/features/work/editors/use-document-comments.d.ts +26 -0
- package/dist/internal/features/work/editors/use-document-insert-commands.d.ts +19 -0
- package/dist/internal/features/work/editors/use-document-layout-fonts.d.ts +2 -0
- package/dist/internal/features/work/editors/use-document-page-chrome.d.ts +33 -0
- package/dist/internal/features/work/editors/use-document-pagination.d.ts +46 -0
- package/dist/internal/features/work/editors/use-markdown-source-history.d.ts +16 -0
- package/dist/internal/features/work/editors/use-office-draft.d.ts +10 -0
- package/dist/internal/features/work/editors/use-office-editor-keyboard-shortcuts.d.ts +9 -0
- package/dist/internal/features/work/editors/use-office-editor-runtime.d.ts +6 -0
- package/dist/internal/features/work/editors/use-office-editor-wheel-zoom.d.ts +19 -0
- package/dist/internal/features/work/editors/use-office-history.d.ts +10 -0
- package/dist/internal/features/work/editors/use-presentation-clipboard.d.ts +22 -0
- package/dist/internal/features/work/editors/use-presentation-design-commands.d.ts +33 -0
- package/dist/internal/features/work/editors/use-presentation-element-commands.d.ts +29 -0
- package/dist/internal/features/work/editors/use-presentation-geometry.d.ts +17 -0
- package/dist/internal/features/work/editors/use-presentation-history.d.ts +12 -0
- package/dist/internal/features/work/editors/use-presentation-review-commands.d.ts +22 -0
- package/dist/internal/features/work/editors/use-presentation-selection.d.ts +11 -0
- package/dist/internal/features/work/editors/use-presentation-slide-commands.d.ts +18 -0
- package/dist/internal/features/work/editors/use-presentation-thumbnail-visibility.d.ts +4 -0
- package/dist/internal/features/work/editors/use-presentation-thumbnail-window.d.ts +17 -0
- package/dist/internal/features/work/editors/use-presentation-transform.d.ts +53 -0
- package/dist/internal/features/work/editors/use-spreadsheet-calculation.d.ts +17 -0
- package/dist/internal/features/work/editors/use-spreadsheet-workbook-sync.d.ts +10 -0
- package/dist/internal/features/work/editors/work-office-chrome.d.ts +61 -0
- package/dist/internal/features/work/editors/work-office-ribbon-overflow.d.ts +18 -0
- package/dist/internal/features/work/work-agent-proposal-apply.d.ts +8 -0
- package/dist/internal/features/work/work-agent-proposal.d.ts +55 -0
- package/dist/internal/features/work/work-agent-request.d.ts +6 -0
- package/dist/internal/features/work/work-chart-series-analysis-context.d.ts +3 -0
- package/dist/internal/features/work/work-document-caption-nodes.d.ts +13 -0
- package/dist/internal/features/work/work-document-captions.d.ts +14 -0
- package/dist/internal/features/work/work-document-changes.d.ts +35 -0
- package/dist/internal/features/work/work-document-character-formatting.d.ts +13 -0
- package/dist/internal/features/work/work-document-citation-nodes.d.ts +25 -0
- package/dist/internal/features/work/work-document-citations.d.ts +21 -0
- package/dist/internal/features/work/work-document-columns.d.ts +15 -0
- package/dist/internal/features/work/work-document-comments.d.ts +48 -0
- package/dist/internal/features/work/work-document-extensions.d.ts +11 -0
- package/dist/internal/features/work/work-document-field-node.d.ts +12 -0
- package/dist/internal/features/work/work-document-fields.d.ts +15 -0
- package/dist/internal/features/work/work-document-file-io.d.ts +4 -0
- package/dist/internal/features/work/work-document-fonts.d.ts +16 -0
- package/dist/internal/features/work/work-document-image-layout.d.ts +29 -0
- package/dist/internal/features/work/work-document-incremental-layout.d.ts +17 -0
- package/dist/internal/features/work/work-document-layout.d.ts +5 -0
- package/dist/internal/features/work/work-document-line-measurement.d.ts +24 -0
- package/dist/internal/features/work/work-document-links.d.ts +2 -0
- package/dist/internal/features/work/work-document-lists.d.ts +25 -0
- package/dist/internal/features/work/work-document-model-codec.d.ts +3 -0
- package/dist/internal/features/work/work-document-model.d.ts +12 -0
- package/dist/internal/features/work/work-document-note-nodes.d.ts +11 -0
- package/dist/internal/features/work/work-document-notes.d.ts +18 -0
- package/dist/internal/features/work/work-document-outline.d.ts +14 -0
- package/dist/internal/features/work/work-document-page-break.d.ts +2 -0
- package/dist/internal/features/work/work-document-page-chrome-commands.d.ts +15 -0
- package/dist/internal/features/work/work-document-page-chrome.d.ts +19 -0
- package/dist/internal/features/work/work-document-page-color.d.ts +3 -0
- package/dist/internal/features/work/work-document-pages.d.ts +19 -0
- package/dist/internal/features/work/work-document-pagination-decorations.d.ts +3 -0
- package/dist/internal/features/work/work-document-pagination-dom.d.ts +35 -0
- package/dist/internal/features/work/work-document-pagination-measurement.d.ts +9 -0
- package/dist/internal/features/work/work-document-pagination-types.d.ts +88 -0
- package/dist/internal/features/work/work-document-pagination.d.ts +17 -0
- package/dist/internal/features/work/work-document-paragraph-formatting.d.ts +61 -0
- package/dist/internal/features/work/work-document-search.d.ts +11 -0
- package/dist/internal/features/work/work-document-section-editor.d.ts +20 -0
- package/dist/internal/features/work/work-document-section-node.d.ts +13 -0
- package/dist/internal/features/work/work-document-section.d.ts +34 -0
- package/dist/internal/features/work/work-document-selection-menu.d.ts +54 -0
- package/dist/internal/features/work/work-document-tab-node.d.ts +6 -0
- package/dist/internal/features/work/work-document-tab-stops.d.ts +29 -0
- package/dist/internal/features/work/work-document-table-cell-formatting.d.ts +46 -0
- package/dist/internal/features/work/work-document-table-commands.d.ts +17 -0
- package/dist/internal/features/work/work-document-table-pagination.d.ts +5 -0
- package/dist/internal/features/work/work-document-table-row.d.ts +37 -0
- package/dist/internal/features/work/work-document-table-sizing.d.ts +27 -0
- package/dist/internal/features/work/work-document-text-layout.d.ts +14 -0
- package/dist/internal/features/work/work-docx-bibliography.d.ts +12 -0
- package/dist/internal/features/work/work-docx-caption-diagnostics.d.ts +6 -0
- package/dist/internal/features/work/work-docx-caption-export.d.ts +4 -0
- package/dist/internal/features/work/work-docx-caption-fields.d.ts +5 -0
- package/dist/internal/features/work/work-docx-caption-import.d.ts +20 -0
- package/dist/internal/features/work/work-docx-change-import.d.ts +12 -0
- package/dist/internal/features/work/work-docx-citation-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-citation-export.d.ts +3 -0
- package/dist/internal/features/work/work-docx-citation-import.d.ts +23 -0
- package/dist/internal/features/work/work-docx-column-export.d.ts +14 -0
- package/dist/internal/features/work/work-docx-column-import.d.ts +2 -0
- package/dist/internal/features/work/work-docx-comment-import.d.ts +14 -0
- package/dist/internal/features/work/work-docx-export-formatting.d.ts +30 -0
- package/dist/internal/features/work/work-docx-export-image.d.ts +2 -0
- package/dist/internal/features/work/work-docx-export.d.ts +2 -0
- package/dist/internal/features/work/work-docx-field-export.d.ts +2 -0
- package/dist/internal/features/work/work-docx-field-import.d.ts +16 -0
- package/dist/internal/features/work/work-docx-field-instructions.d.ts +8 -0
- package/dist/internal/features/work/work-docx-image-layout-import.d.ts +12 -0
- package/dist/internal/features/work/work-docx-import.d.ts +50 -0
- package/dist/internal/features/work/work-docx-list-import.d.ts +14 -0
- package/dist/internal/features/work/work-docx-note-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-note-import.d.ts +3 -0
- package/dist/internal/features/work/work-docx-page-chrome-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-page-chrome-import.d.ts +11 -0
- package/dist/internal/features/work/work-docx-page-color.d.ts +2 -0
- package/dist/internal/features/work/work-docx-paragraph-alignment-import.d.ts +12 -0
- package/dist/internal/features/work/work-docx-paragraph-direction-import.d.ts +12 -0
- package/dist/internal/features/work/work-docx-paragraph-indent-import.d.ts +12 -0
- package/dist/internal/features/work/work-docx-paragraph-pagination-import.d.ts +12 -0
- package/dist/internal/features/work/work-docx-paragraph-spacing-import.d.ts +12 -0
- package/dist/internal/features/work/work-docx-paragraph-styles.d.ts +18 -0
- package/dist/internal/features/work/work-docx-run-formatting-import.d.ts +19 -0
- package/dist/internal/features/work/work-docx-tab-stop-import.d.ts +13 -0
- package/dist/internal/features/work/work-docx-table-cell-export.d.ts +4 -0
- package/dist/internal/features/work/work-docx-table-cell-import.d.ts +16 -0
- package/dist/internal/features/work/work-docx-table-row-import.d.ts +13 -0
- package/dist/internal/features/work/work-docx-table-sizing-export.d.ts +8 -0
- package/dist/internal/features/work/work-docx-table-sizing-import.d.ts +12 -0
- package/dist/internal/features/work/work-docx-theme.d.ts +9 -0
- package/dist/internal/features/work/work-file-data.d.ts +1 -0
- package/dist/internal/features/work/work-file-download.d.ts +3 -0
- package/dist/internal/features/work/work-file-io.d.ts +8 -0
- package/dist/internal/features/work/work-markdown-extensions.d.ts +19 -0
- package/dist/internal/features/work/work-markdown-file-io.d.ts +3 -0
- package/dist/internal/features/work/work-markdown-selection-menu.d.ts +57 -0
- package/dist/internal/features/work/work-office-diagnostics.d.ts +9 -0
- package/dist/internal/features/work/work-ooxml-package.d.ts +28 -0
- package/dist/internal/features/work/work-pdf-export.d.ts +23 -0
- package/dist/internal/features/work/work-pptx-chart-axes.d.ts +3 -0
- package/dist/internal/features/work/work-pptx-chart-axis-diagnostics.d.ts +5 -0
- package/dist/internal/features/work/work-pptx-chart-data-labels.d.ts +12 -0
- package/dist/internal/features/work/work-pptx-chart-import.d.ts +11 -0
- package/dist/internal/features/work/work-pptx-chart-layout-style.d.ts +15 -0
- package/dist/internal/features/work/work-pptx-chart-series-analysis.d.ts +13 -0
- package/dist/internal/features/work/work-pptx-chart-xy.d.ts +3 -0
- package/dist/internal/features/work/work-pptx-comments.d.ts +17 -0
- package/dist/internal/features/work/work-pptx-export.d.ts +4 -0
- package/dist/internal/features/work/work-pptx-groups.d.ts +19 -0
- package/dist/internal/features/work/work-pptx-import.d.ts +6 -0
- package/dist/internal/features/work/work-pptx-layout-export.d.ts +13 -0
- package/dist/internal/features/work/work-pptx-layout-import.d.ts +30 -0
- package/dist/internal/features/work/work-pptx-style.d.ts +13 -0
- package/dist/internal/features/work/work-pptx-transition.d.ts +13 -0
- package/dist/internal/features/work/work-presentation-agent-context.d.ts +6 -0
- package/dist/internal/features/work/work-presentation-chart-axes.d.ts +14 -0
- package/dist/internal/features/work/work-presentation-charts.d.ts +37 -0
- package/dist/internal/features/work/work-presentation-clipboard.d.ts +26 -0
- package/dist/internal/features/work/work-presentation-file-io.d.ts +15 -0
- package/dist/internal/features/work/work-presentation-groups.d.ts +17 -0
- package/dist/internal/features/work/work-presentation-layouts.d.ts +13 -0
- package/dist/internal/features/work/work-presentation-transition.d.ts +4 -0
- package/dist/internal/features/work/work-presentation-visual-scale.d.ts +2 -0
- package/dist/internal/features/work/work-repository.d.ts +4 -0
- package/dist/internal/features/work/work-spreadsheet-agent-context.d.ts +15 -0
- package/dist/internal/features/work/work-spreadsheet-chart-axis.d.ts +42 -0
- package/dist/internal/features/work/work-spreadsheet-chart-layout.d.ts +29 -0
- package/dist/internal/features/work/work-spreadsheet-chart-legend-svg.d.ts +18 -0
- package/dist/internal/features/work/work-spreadsheet-chart-series-layout.d.ts +24 -0
- package/dist/internal/features/work/work-spreadsheet-chart-series-style.d.ts +29 -0
- package/dist/internal/features/work/work-spreadsheet-chart-svg-utils.d.ts +7 -0
- package/dist/internal/features/work/work-spreadsheet-chart-svg.d.ts +3 -0
- package/dist/internal/features/work/work-spreadsheet-chart-types.d.ts +147 -0
- package/dist/internal/features/work/work-spreadsheet-chart-validation.d.ts +2 -0
- package/dist/internal/features/work/work-spreadsheet-charts.d.ts +17 -0
- package/dist/internal/features/work/work-spreadsheet-combination-chart-svg.d.ts +9 -0
- package/dist/internal/features/work/work-spreadsheet-comments.d.ts +7 -0
- package/dist/internal/features/work/work-spreadsheet-conditional-canvas.d.ts +5 -0
- package/dist/internal/features/work/work-spreadsheet-conditional-colors.d.ts +9 -0
- package/dist/internal/features/work/work-spreadsheet-conditional-comparisons.d.ts +4 -0
- package/dist/internal/features/work/work-spreadsheet-conditional-data-bar.d.ts +8 -0
- package/dist/internal/features/work/work-spreadsheet-conditional-format.d.ts +10 -0
- package/dist/internal/features/work/work-spreadsheet-conditional-icons.d.ts +107 -0
- package/dist/internal/features/work/work-spreadsheet-conditional-values.d.ts +19 -0
- package/dist/internal/features/work/work-spreadsheet-data-label-svg.d.ts +27 -0
- package/dist/internal/features/work/work-spreadsheet-error-bar-svg.d.ts +5 -0
- package/dist/internal/features/work/work-spreadsheet-error-bars.d.ts +8 -0
- package/dist/internal/features/work/work-spreadsheet-formula-analysis.d.ts +30 -0
- package/dist/internal/features/work/work-spreadsheet-formula-support.d.ts +1 -0
- package/dist/internal/features/work/work-spreadsheet-formulas.d.ts +19 -0
- package/dist/internal/features/work/work-spreadsheet-header-footer.d.ts +14 -0
- package/dist/internal/features/work/work-spreadsheet-line-chart-svg.d.ts +10 -0
- package/dist/internal/features/work/work-spreadsheet-page-breaks.d.ts +4 -0
- package/dist/internal/features/work/work-spreadsheet-page-setup.d.ts +26 -0
- package/dist/internal/features/work/work-spreadsheet-pivot-engine.d.ts +21 -0
- package/dist/internal/features/work/work-spreadsheet-pivot-values.d.ts +7 -0
- package/dist/internal/features/work/work-spreadsheet-pivots.d.ts +27 -0
- package/dist/internal/features/work/work-spreadsheet-protection.d.ts +55 -0
- package/dist/internal/features/work/work-spreadsheet-ranges.d.ts +25 -0
- package/dist/internal/features/work/work-spreadsheet-trendline-svg.d.ts +9 -0
- package/dist/internal/features/work/work-spreadsheet-trendlines.d.ts +11 -0
- package/dist/internal/features/work/work-spreadsheet-xy-chart-axes-svg.d.ts +10 -0
- package/dist/internal/features/work/work-templates.d.ts +4 -0
- package/dist/internal/features/work/work-types.d.ts +513 -0
- package/dist/internal/features/work/work-xlsx-chart-axes.d.ts +4 -0
- package/dist/internal/features/work/work-xlsx-chart-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-xlsx-chart-layout.d.ts +16 -0
- package/dist/internal/features/work/work-xlsx-chart-series-style.d.ts +6 -0
- package/dist/internal/features/work/work-xlsx-chart-values.d.ts +10 -0
- package/dist/internal/features/work/work-xlsx-charts.d.ts +32 -0
- package/dist/internal/features/work/work-xlsx-conditional-format-diagnostics.d.ts +6 -0
- package/dist/internal/features/work/work-xlsx-conditional-format-write.d.ts +11 -0
- package/dist/internal/features/work/work-xlsx-conditional-format.d.ts +29 -0
- package/dist/internal/features/work/work-xlsx-defined-names.d.ts +4 -0
- package/dist/internal/features/work/work-xlsx-drawing-geometry.d.ts +27 -0
- package/dist/internal/features/work/work-xlsx-formula-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-xlsx-formulas.d.ts +40 -0
- package/dist/internal/features/work/work-xlsx-header-footer.d.ts +12 -0
- package/dist/internal/features/work/work-xlsx-images.d.ts +17 -0
- package/dist/internal/features/work/work-xlsx-interop.d.ts +39 -0
- package/dist/internal/features/work/work-xlsx-page-breaks.d.ts +7 -0
- package/dist/internal/features/work/work-xlsx-page-setup-diagnostics.d.ts +2 -0
- package/dist/internal/features/work/work-xlsx-page-setup.d.ts +5 -0
- package/dist/internal/features/work/work-xlsx-pivot-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-xlsx-pivot-xml.d.ts +9 -0
- package/dist/internal/features/work/work-xlsx-pivots.d.ts +32 -0
- package/dist/internal/features/work/work-xlsx-protection.d.ts +24 -0
- package/dist/internal/features/workspace/components/workspace-context-menu.d.ts +29 -0
- package/dist/internal/features/workspace/components/workspace-text-control-selection.d.ts +7 -0
- package/dist/internal/kernel/office-kernel-client-types.d.ts +40 -0
- package/dist/internal/kernel/office-kernel-client.d.ts +4 -0
- package/dist/internal/kernel/office-kernel-fallback.d.ts +2 -0
- package/dist/internal/kernel/office-kernel-presentation-fallback.d.ts +2 -0
- package/dist/internal/kernel/office-kernel-protocol.d.ts +229 -0
- package/dist/internal/kernel/office-kernel-spreadsheet-fallback-formula.d.ts +3 -0
- package/dist/internal/kernel/office-kernel-spreadsheet-fallback-validation.d.ts +5 -0
- package/dist/internal/kernel/office-kernel-spreadsheet-fallback-value.d.ts +6 -0
- package/dist/internal/kernel/office-kernel-spreadsheet-fallback.d.ts +2 -0
- package/dist/internal/kernel/office-kernel-spreadsheet-protocol.d.ts +112 -0
- package/dist/internal/kernel/office-kernel-spreadsheet-session-fallback.d.ts +8 -0
- package/dist/internal/kernel/office-kernel-text-fallback.d.ts +10 -0
- package/dist/internal/kernel/office-kernel-version.d.ts +1 -0
- package/dist/internal/kernel/office-kernel.worker.d.ts +1 -0
- package/dist/internal/keyboard-shortcuts.d.ts +2 -0
- package/dist/internal/state/app-state.d.ts +8 -0
- package/dist/noto-naskh-arabic-regular.ttf +0 -0
- package/dist/noto-naskh-arabic.LICENSE.txt +94 -0
- package/dist/noto-sans-hans-regular.otf +0 -0
- package/dist/noto-sans-hans.LICENSE.txt +94 -0
- package/dist/noto-sans-hebrew-regular.ttf +0 -0
- package/dist/noto-sans-hebrew.LICENSE.txt +94 -0
- package/dist/noto-sans-regular.ttf +0 -0
- package/dist/noto-sans.LICENSE.txt +94 -0
- package/dist/office-kernel.wasm +0 -0
- package/dist/office-kernel.worker.js +14605 -0
- package/dist/office-surface.d.ts +10 -0
- package/dist/pdfium.LICENSE.txt +196 -0
- package/dist/pdfium.wasm +0 -0
- package/dist/pptxgen.LICENSE.txt +21 -0
- package/dist/pptxgen.bundle.js +11244 -0
- package/dist/react.d.ts +51 -0
- package/dist/react.js +1 -0
- package/dist/styles.css +17435 -0
- package/dist/styles.js +0 -0
- package/dist/vue.d.ts +282 -0
- package/dist/vue.js +231 -0
- package/dist/web-component.d.ts +98 -0
- package/dist/web-component.js +335 -0
- package/docs/browser-editor-architecture.md +947 -0
- package/package.json +165 -0
|
@@ -0,0 +1,1151 @@
|
|
|
1
|
+
import { normalizeDocumentTableLayoutMode, normalizeDocumentTableRowHeightRule, normalizeTableColor, normalizeDocumentTableBorderWidth, normalizeDocumentTableVerticalAlign, normalizeDocumentTableBorderStyle } from "./0~6552.js";
|
|
2
|
+
import { documentCitationTags, documentNoteKind, documentSections, documentCaptionLabel, documentCaptionKind, collectDocumentNotes, documentNoteKey, normalizeDocumentPageChrome, normalizeDocumentColumns, documentCitationInstruction, docxDocumentFieldKind } from "./4704.js";
|
|
3
|
+
import { documentImageLayoutFromElement, normalizeDocumentTabStops } from "./0~8155.js";
|
|
4
|
+
import { patchDocxBibliography } from "./0~work-docx-bibliography.js";
|
|
5
|
+
import { patchDocxPageColor } from "./0~work-docx-page-color.js";
|
|
6
|
+
function documentTableCellDocxOptions(cell, docx) {
|
|
7
|
+
const backgroundColor = normalizeTableColor(cell.dataset.officeCellFill || cell.style.backgroundColor);
|
|
8
|
+
const verticalAlign = normalizeDocumentTableVerticalAlign(cell.dataset.officeCellVerticalAlign || cell.style.verticalAlign);
|
|
9
|
+
const borderStyle = normalizeDocumentTableBorderStyle(cell.dataset.officeCellBorderStyle || cell.style.borderStyle);
|
|
10
|
+
const borderWidth = normalizeDocumentTableBorderWidth(cell.dataset.officeCellBorderWidth || cell.style.borderWidth);
|
|
11
|
+
const borderColor = normalizeTableColor(cell.dataset.officeCellBorderColor || cell.style.borderColor);
|
|
12
|
+
const border = borderStyle ? {
|
|
13
|
+
style: docxBorderStyle(borderStyle, docx),
|
|
14
|
+
...'none' === borderStyle ? {} : {
|
|
15
|
+
color: docxColor(borderColor ?? '#cfd5df'),
|
|
16
|
+
size: Math.max(1, Math.round((borderWidth ?? 1) * 6))
|
|
17
|
+
}
|
|
18
|
+
} : null;
|
|
19
|
+
return {
|
|
20
|
+
...backgroundColor ? {
|
|
21
|
+
shading: {
|
|
22
|
+
fill: docxColor(backgroundColor),
|
|
23
|
+
type: docx.ShadingType.CLEAR
|
|
24
|
+
}
|
|
25
|
+
} : {},
|
|
26
|
+
...verticalAlign ? {
|
|
27
|
+
verticalAlign: 'middle' === verticalAlign ? docx.VerticalAlignTable.CENTER : 'bottom' === verticalAlign ? docx.VerticalAlignTable.BOTTOM : docx.VerticalAlignTable.TOP
|
|
28
|
+
} : {},
|
|
29
|
+
...border ? {
|
|
30
|
+
borders: {
|
|
31
|
+
top: border,
|
|
32
|
+
right: border,
|
|
33
|
+
bottom: border,
|
|
34
|
+
left: border
|
|
35
|
+
}
|
|
36
|
+
} : {}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function docxBorderStyle(style, docx) {
|
|
40
|
+
if ('dashed' === style) return docx.BorderStyle.DASHED;
|
|
41
|
+
if ('dotted' === style) return docx.BorderStyle.DOTTED;
|
|
42
|
+
if ('double' === style) return docx.BorderStyle.DOUBLE;
|
|
43
|
+
if ('none' === style) return docx.BorderStyle.NONE;
|
|
44
|
+
return docx.BorderStyle.SINGLE;
|
|
45
|
+
}
|
|
46
|
+
function docxColor(color) {
|
|
47
|
+
return color.replace(/^#/, '').toUpperCase();
|
|
48
|
+
}
|
|
49
|
+
const TWIPS_PER_PIXEL = 15;
|
|
50
|
+
function documentTableSizingDocxOptions(table, docx) {
|
|
51
|
+
const mode = normalizeDocumentTableLayoutMode(table.dataset.officeTableLayout);
|
|
52
|
+
const pixelWidths = documentTableColumnWidths(table);
|
|
53
|
+
const columnWidths = pixelWidths?.map(pixelsToTwips);
|
|
54
|
+
if ('contents' === mode) return {
|
|
55
|
+
layout: docx.TableLayoutType.AUTOFIT,
|
|
56
|
+
width: {
|
|
57
|
+
size: 0,
|
|
58
|
+
type: docx.WidthType.AUTO
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
if ('fixed' === mode && columnWidths?.length) return {
|
|
62
|
+
columnWidths,
|
|
63
|
+
layout: docx.TableLayoutType.FIXED,
|
|
64
|
+
width: {
|
|
65
|
+
size: columnWidths.reduce((sum, width)=>sum + width, 0),
|
|
66
|
+
type: docx.WidthType.DXA
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
layout: docx.TableLayoutType.FIXED,
|
|
71
|
+
width: {
|
|
72
|
+
size: 100,
|
|
73
|
+
type: docx.WidthType.PERCENTAGE
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function documentTableCellSizingDocxOptions(cell, docx) {
|
|
78
|
+
const widths = cellColumnWidths(cell);
|
|
79
|
+
if (!widths?.length) return {};
|
|
80
|
+
return {
|
|
81
|
+
width: {
|
|
82
|
+
size: pixelsToTwips(widths.reduce((sum, width)=>sum + width, 0)),
|
|
83
|
+
type: docx.WidthType.DXA
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function documentTableRowSizingDocxOptions(row, docx) {
|
|
88
|
+
const pixels = rowHeightPixels(row);
|
|
89
|
+
if (null === pixels) return {};
|
|
90
|
+
const rule = normalizeDocumentTableRowHeightRule(row.dataset.officeRowHeightRule);
|
|
91
|
+
return {
|
|
92
|
+
height: {
|
|
93
|
+
value: pixelsToTwips(pixels),
|
|
94
|
+
rule: 'exact' === rule ? docx.HeightRule.EXACT : docx.HeightRule.ATLEAST
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function documentTableColumnWidths(table) {
|
|
99
|
+
const row = table.rows[0];
|
|
100
|
+
if (!row) return null;
|
|
101
|
+
const widths = [];
|
|
102
|
+
for (const cell of Array.from(row.cells)){
|
|
103
|
+
const cellWidths = cellColumnWidths(cell);
|
|
104
|
+
if (!cellWidths || cellWidths.length !== cell.colSpan) return null;
|
|
105
|
+
widths.push(...cellWidths);
|
|
106
|
+
}
|
|
107
|
+
return widths.length ? widths : null;
|
|
108
|
+
}
|
|
109
|
+
function cellColumnWidths(cell) {
|
|
110
|
+
const raw = cell.getAttribute('colwidth') ?? cell.dataset.colwidth;
|
|
111
|
+
if (!raw) return null;
|
|
112
|
+
const widths = raw.split(',').map((width)=>Number(width)).filter((width)=>Number.isFinite(width) && width > 0);
|
|
113
|
+
return widths.length === cell.colSpan ? widths : null;
|
|
114
|
+
}
|
|
115
|
+
function rowHeightPixels(row) {
|
|
116
|
+
const value = Number.parseFloat(row.dataset.officeRowHeight || row.style.height);
|
|
117
|
+
return Number.isFinite(value) && value > 0 ? value : null;
|
|
118
|
+
}
|
|
119
|
+
function pixelsToTwips(pixels) {
|
|
120
|
+
return Math.max(1, Math.round(pixels * TWIPS_PER_PIXEL));
|
|
121
|
+
}
|
|
122
|
+
function docxCaptionParagraph(element, titleChildren, docx, bidirectional) {
|
|
123
|
+
const kind = documentCaptionKind(element.dataset.captionKind) ?? 'figure';
|
|
124
|
+
const number = positiveInteger(element.dataset.captionNumber);
|
|
125
|
+
const bookmarkId = docxCaptionBookmarkId(element.dataset.captionId ?? `${kind}-${number}`);
|
|
126
|
+
return new docx.Paragraph({
|
|
127
|
+
bidirectional,
|
|
128
|
+
alignment: docx.AlignmentType.CENTER,
|
|
129
|
+
spacing: {
|
|
130
|
+
after: 160,
|
|
131
|
+
line: 300
|
|
132
|
+
},
|
|
133
|
+
children: [
|
|
134
|
+
new docx.TextRun(`${documentCaptionLabel(kind)} `),
|
|
135
|
+
new docx.Bookmark({
|
|
136
|
+
id: bookmarkId,
|
|
137
|
+
children: [
|
|
138
|
+
new docx.SequentialIdentifier('table' === kind ? 'Table' : 'Figure')
|
|
139
|
+
]
|
|
140
|
+
}),
|
|
141
|
+
new docx.TextRun(' '),
|
|
142
|
+
...titleChildren
|
|
143
|
+
]
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function docxCrossReferenceRuns(element, docx) {
|
|
147
|
+
if ('true' === element.dataset.referenceOrphaned) return [
|
|
148
|
+
new docx.TextRun('引用缺失')
|
|
149
|
+
];
|
|
150
|
+
const kind = documentCaptionKind(element.dataset.captionKind) ?? 'figure';
|
|
151
|
+
const number = positiveInteger(element.dataset.captionNumber);
|
|
152
|
+
const targetId = element.dataset.referenceTargetId?.trim();
|
|
153
|
+
if (!targetId) return [
|
|
154
|
+
new docx.TextRun('引用缺失')
|
|
155
|
+
];
|
|
156
|
+
return [
|
|
157
|
+
new docx.TextRun(`${documentCaptionLabel(kind)} `),
|
|
158
|
+
new docx.NumberedItemReference(docxCaptionBookmarkId(targetId), String(number), {
|
|
159
|
+
hyperlink: true,
|
|
160
|
+
referenceFormat: docx.NumberedItemReferenceFormat.NONE
|
|
161
|
+
})
|
|
162
|
+
];
|
|
163
|
+
}
|
|
164
|
+
function docxCaptionBookmarkId(source) {
|
|
165
|
+
const safe = source.replace(/[^a-z0-9_]/gi, '_').replace(/^([^a-z_])/i, '_$1').slice(0, 18);
|
|
166
|
+
return `A3SCaption_${safe || 'item'}_${stableHash(source)}`.slice(0, 40);
|
|
167
|
+
}
|
|
168
|
+
function stableHash(source) {
|
|
169
|
+
let hash = 2166136261;
|
|
170
|
+
for(let index = 0; index < source.length; index += 1){
|
|
171
|
+
hash ^= source.charCodeAt(index);
|
|
172
|
+
hash = Math.imul(hash, 16777619);
|
|
173
|
+
}
|
|
174
|
+
return (hash >>> 0).toString(36);
|
|
175
|
+
}
|
|
176
|
+
function positiveInteger(value) {
|
|
177
|
+
const number = Number(value);
|
|
178
|
+
return Number.isSafeInteger(number) && number > 0 ? number : 1;
|
|
179
|
+
}
|
|
180
|
+
function docxCitationRun(element, docx) {
|
|
181
|
+
const tags = documentCitationTags(element.dataset.citationTags);
|
|
182
|
+
const instruction = element.dataset.citationInstruction?.trim() || documentCitationInstruction(tags);
|
|
183
|
+
const display = element.dataset.citationDisplay?.trim() || element.textContent?.trim() || '缺失引文';
|
|
184
|
+
if (!tags.length || !/^\s*CITATION\b/i.test(instruction)) return new docx.TextRun(display);
|
|
185
|
+
return new docx.SimpleField(instruction, display);
|
|
186
|
+
}
|
|
187
|
+
function docxBibliographyParagraph(element, docx, bidirectional) {
|
|
188
|
+
const instruction = element.dataset.bibliographyInstruction?.trim() || 'BIBLIOGRAPHY \\l 2052';
|
|
189
|
+
const cached = Array.from(element.querySelectorAll('[data-bibliography-entry]')).map((entry)=>entry.textContent?.trim() ?? '').filter(Boolean).join('\n');
|
|
190
|
+
return new docx.Paragraph({
|
|
191
|
+
bidirectional,
|
|
192
|
+
children: [
|
|
193
|
+
new docx.SimpleField(instruction, cached || '参考文献')
|
|
194
|
+
],
|
|
195
|
+
spacing: {
|
|
196
|
+
before: 240,
|
|
197
|
+
after: 120,
|
|
198
|
+
line: 320
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
const MIN_COLUMN_WIDTH_TWIPS = 240;
|
|
203
|
+
function docxSectionColumns(layout, pageWidth, docx) {
|
|
204
|
+
const columns = normalizeDocumentColumns(layout.columns);
|
|
205
|
+
if (!columns.custom) return {
|
|
206
|
+
count: columns.count,
|
|
207
|
+
space: millimetersToTwips(columns.spacing),
|
|
208
|
+
separate: columns.separator,
|
|
209
|
+
equalWidth: true
|
|
210
|
+
};
|
|
211
|
+
const contentWidth = Math.max(columns.count * MIN_COLUMN_WIDTH_TWIPS, pageWidth - millimetersToTwips(layout.margins.left + layout.margins.right));
|
|
212
|
+
const requestedSpaces = columns.custom.slice(0, -1).map((column)=>millimetersToTwips(column.spacing));
|
|
213
|
+
const maximumSpaceWidth = Math.max(0, contentWidth - columns.count * MIN_COLUMN_WIDTH_TWIPS);
|
|
214
|
+
const requestedSpaceWidth = requestedSpaces.reduce((total, value)=>total + value, 0);
|
|
215
|
+
const spaceScale = requestedSpaceWidth > maximumSpaceWidth ? maximumSpaceWidth / requestedSpaceWidth : 1;
|
|
216
|
+
const spaces = requestedSpaces.map((space)=>Math.round(space * spaceScale));
|
|
217
|
+
const availableWidth = contentWidth - spaces.reduce((total, value)=>total + value, 0);
|
|
218
|
+
const widths = columns.custom.map((column)=>Math.round(availableWidth * column.widthPercent / 100));
|
|
219
|
+
widths[widths.length - 1] += availableWidth - widths.reduce((total, value)=>total + value, 0);
|
|
220
|
+
return {
|
|
221
|
+
count: columns.count,
|
|
222
|
+
separate: columns.separator,
|
|
223
|
+
equalWidth: false,
|
|
224
|
+
children: columns.custom.map((_, index)=>new docx.Column({
|
|
225
|
+
width: Math.max(MIN_COLUMN_WIDTH_TWIPS, widths[index]),
|
|
226
|
+
space: index < spaces.length ? spaces[index] : void 0
|
|
227
|
+
}))
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function millimetersToTwips(value) {
|
|
231
|
+
return Math.round(1440 * value / 25.4);
|
|
232
|
+
}
|
|
233
|
+
function docxDocumentFieldRun(element, docx) {
|
|
234
|
+
const instruction = element.dataset.fieldInstruction?.trim() ?? '';
|
|
235
|
+
const display = element.dataset.fieldDisplay?.trim() || element.textContent?.trim() || '';
|
|
236
|
+
if (!docxDocumentFieldKind(instruction)) return new docx.TextRun(display);
|
|
237
|
+
return new docx.SimpleField(instruction, display);
|
|
238
|
+
}
|
|
239
|
+
function paragraphAlignment(element, docx) {
|
|
240
|
+
const alignment = element.style.textAlign;
|
|
241
|
+
if ('center' === alignment) return docx.AlignmentType.CENTER;
|
|
242
|
+
if ('right' === alignment || 'end' === alignment) return docx.AlignmentType.RIGHT;
|
|
243
|
+
if ('justify' === alignment) return docx.AlignmentType.JUSTIFIED;
|
|
244
|
+
if ('left' === alignment || 'start' === alignment) return docx.AlignmentType.LEFT;
|
|
245
|
+
}
|
|
246
|
+
function paragraphDirectionOptions(element) {
|
|
247
|
+
const bidirectional = paragraphBidirectional(element);
|
|
248
|
+
return void 0 === bidirectional ? {} : {
|
|
249
|
+
bidirectional
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function paragraphBidirectional(element) {
|
|
253
|
+
const direction = domDirection(element);
|
|
254
|
+
return void 0 === direction ? void 0 : 'rtl' === direction;
|
|
255
|
+
}
|
|
256
|
+
function domDirection(element) {
|
|
257
|
+
let current = element;
|
|
258
|
+
while(current){
|
|
259
|
+
const attribute = current.getAttribute('dir')?.trim().toLowerCase();
|
|
260
|
+
if ('ltr' === attribute || 'rtl' === attribute) return attribute;
|
|
261
|
+
if ('auto' === attribute) break;
|
|
262
|
+
const css = current.style.direction.trim().toLowerCase();
|
|
263
|
+
if ('ltr' === css || 'rtl' === css) return css;
|
|
264
|
+
current = current.parentElement;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function paragraphLineSpacing(element) {
|
|
268
|
+
const value = element.style.lineHeight.trim();
|
|
269
|
+
if (!value || 'normal' === value) return;
|
|
270
|
+
const percentage = /^(\d+(?:\.\d+)?)%$/.exec(value);
|
|
271
|
+
if (percentage) return Math.round(Number(percentage[1]) / 100 * 240);
|
|
272
|
+
const unitless = /^(\d+(?:\.\d+)?)$/.exec(value);
|
|
273
|
+
if (unitless) return Math.round(240 * Number(unitless[1]));
|
|
274
|
+
const points = cssLengthToPoints(value);
|
|
275
|
+
return points ? Math.round(20 * points) : void 0;
|
|
276
|
+
}
|
|
277
|
+
function paragraphSpacingOptions(element, heading, docx) {
|
|
278
|
+
const before = dataPointLengthToTwips(element.dataset.officeSpaceBefore) ?? cssSpacingLengthToTwips(element.style.marginTop);
|
|
279
|
+
const after = dataPointLengthToTwips(element.dataset.officeSpaceAfter) ?? cssSpacingLengthToTwips(element.style.marginBottom);
|
|
280
|
+
const lineRule = paragraphLineRule(element, docx);
|
|
281
|
+
return {
|
|
282
|
+
after: after ?? (heading ? 180 : 120),
|
|
283
|
+
...void 0 !== before ? {
|
|
284
|
+
before
|
|
285
|
+
} : {},
|
|
286
|
+
line: paragraphLineSpacing(element) ?? 320,
|
|
287
|
+
...lineRule ? {
|
|
288
|
+
lineRule
|
|
289
|
+
} : {}
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function paragraphLineRule(element, docx) {
|
|
293
|
+
if ('auto' === element.dataset.officeLineRule) return docx.LineRuleType.AUTO;
|
|
294
|
+
if ('exact' === element.dataset.officeLineRule) return docx.LineRuleType.EXACT;
|
|
295
|
+
if ('atLeast' === element.dataset.officeLineRule) return docx.LineRuleType.AT_LEAST;
|
|
296
|
+
}
|
|
297
|
+
function paragraphIndent(element, tag) {
|
|
298
|
+
const blockquoteIndent = 'blockquote' === tag ? 540 : 0;
|
|
299
|
+
const level = Number(element.dataset.officeIndentLevel);
|
|
300
|
+
const explicitIndent = Number.isFinite(level) && level > 0 ? Math.round(360 * level) : cssLengthToTwips(element.style.marginLeft);
|
|
301
|
+
const left = blockquoteIndent + explicitIndent;
|
|
302
|
+
const right = dataPixelLengthToTwips(element.dataset.officeIndentRight) ?? cssLengthToTwips(element.style.marginRight);
|
|
303
|
+
const firstLine = dataPixelLengthToTwips(element.dataset.officeIndentFirstLine, true) ?? cssSignedLengthToTwips(element.style.textIndent);
|
|
304
|
+
if (!left && !right && !firstLine) return;
|
|
305
|
+
return {
|
|
306
|
+
...left > 0 ? {
|
|
307
|
+
left
|
|
308
|
+
} : {},
|
|
309
|
+
...right > 0 ? {
|
|
310
|
+
right
|
|
311
|
+
} : {},
|
|
312
|
+
...firstLine > 0 ? {
|
|
313
|
+
firstLine
|
|
314
|
+
} : {},
|
|
315
|
+
...firstLine < 0 ? {
|
|
316
|
+
hanging: Math.abs(firstLine)
|
|
317
|
+
} : {}
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function paragraphPaginationOptions(element) {
|
|
321
|
+
return {
|
|
322
|
+
keepLines: dataBoolean(element.dataset.officeKeepLines),
|
|
323
|
+
keepNext: dataBoolean(element.dataset.officeKeepWithNext),
|
|
324
|
+
pageBreakBefore: dataBoolean(element.dataset.officePageBreakBefore),
|
|
325
|
+
widowControl: dataBoolean(element.dataset.officeWidowControl)
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function paragraphTabStops(element, docx) {
|
|
329
|
+
const tabStops = normalizeDocumentTabStops(element.dataset.officeTabStops ?? '').map((tabStop)=>({
|
|
330
|
+
type: docxTabStopType(tabStop.alignment, docx),
|
|
331
|
+
position: Math.round(15 * tabStop.position),
|
|
332
|
+
...'none' === tabStop.leader ? {} : {
|
|
333
|
+
leader: docxTabLeader(tabStop.leader, docx)
|
|
334
|
+
}
|
|
335
|
+
}));
|
|
336
|
+
return tabStops.length ? tabStops : void 0;
|
|
337
|
+
}
|
|
338
|
+
function docxTabStopType(alignment, docx) {
|
|
339
|
+
if ('center' === alignment) return docx.TabStopType.CENTER;
|
|
340
|
+
if ('right' === alignment) return docx.TabStopType.RIGHT;
|
|
341
|
+
if ('decimal' === alignment) return docx.TabStopType.DECIMAL;
|
|
342
|
+
return docx.TabStopType.LEFT;
|
|
343
|
+
}
|
|
344
|
+
function docxTabLeader(leader, docx) {
|
|
345
|
+
if ('dot' === leader) return docx.LeaderType.DOT;
|
|
346
|
+
if ('hyphen' === leader) return docx.LeaderType.HYPHEN;
|
|
347
|
+
if ('underscore' === leader) return docx.LeaderType.UNDERSCORE;
|
|
348
|
+
if ('middleDot' === leader) return docx.LeaderType.MIDDLE_DOT;
|
|
349
|
+
return docx.LeaderType.NONE;
|
|
350
|
+
}
|
|
351
|
+
function dataBoolean(value) {
|
|
352
|
+
if ('true' === value || '1' === value) return true;
|
|
353
|
+
if ('false' === value || '0' === value) return false;
|
|
354
|
+
}
|
|
355
|
+
function cssFontFamily(value) {
|
|
356
|
+
const family = value.split(',')[0]?.trim().replace(/^(['"])(.*)\1$/, '$2');
|
|
357
|
+
return family || void 0;
|
|
358
|
+
}
|
|
359
|
+
function cssFontSize(value) {
|
|
360
|
+
const points = cssLengthToPoints(value);
|
|
361
|
+
return points ? Math.max(1, Math.round(2 * points)) : void 0;
|
|
362
|
+
}
|
|
363
|
+
function cssLengthToTwips(value) {
|
|
364
|
+
const points = cssLengthToPoints(value);
|
|
365
|
+
return points ? Math.max(0, Math.round(20 * points)) : 0;
|
|
366
|
+
}
|
|
367
|
+
function cssSignedLengthToTwips(value) {
|
|
368
|
+
const match = /^(-?\d+(?:\.\d+)?)(px|pt|in|cm|mm)$/i.exec(value.trim());
|
|
369
|
+
if (!match) return 0;
|
|
370
|
+
const amount = Number(match[1]);
|
|
371
|
+
if (!Number.isFinite(amount) || !amount) return 0;
|
|
372
|
+
const unit = match[2]?.toLowerCase();
|
|
373
|
+
const points = 'px' === unit ? 0.75 * amount : 'in' === unit ? 72 * amount : 'cm' === unit ? 72 * amount / 2.54 : 'mm' === unit ? 72 * amount / 25.4 : amount;
|
|
374
|
+
return Math.round(20 * points);
|
|
375
|
+
}
|
|
376
|
+
function dataPixelLengthToTwips(value, signed = false) {
|
|
377
|
+
if (void 0 === value) return;
|
|
378
|
+
const pixels = Number(value);
|
|
379
|
+
if (!Number.isFinite(pixels)) return;
|
|
380
|
+
const twips = Math.round(15 * pixels);
|
|
381
|
+
return signed ? twips : Math.max(0, twips);
|
|
382
|
+
}
|
|
383
|
+
function dataPointLengthToTwips(value) {
|
|
384
|
+
if (void 0 === value) return;
|
|
385
|
+
const points = Number(value);
|
|
386
|
+
return Number.isFinite(points) && points >= 0 ? Math.round(20 * points) : void 0;
|
|
387
|
+
}
|
|
388
|
+
function cssSpacingLengthToTwips(value) {
|
|
389
|
+
if (!value.trim()) return;
|
|
390
|
+
if (/^0(?:\.0+)?(?:px|pt|in|cm|mm)?$/i.test(value.trim())) return 0;
|
|
391
|
+
const points = cssLengthToPoints(value);
|
|
392
|
+
return void 0 === points ? void 0 : Math.round(20 * points);
|
|
393
|
+
}
|
|
394
|
+
function cssLengthToPoints(value) {
|
|
395
|
+
const match = /^(-?\d+(?:\.\d+)?)(px|pt|in|cm|mm)$/i.exec(value.trim());
|
|
396
|
+
if (!match) return;
|
|
397
|
+
const amount = Number(match[1]);
|
|
398
|
+
if (!Number.isFinite(amount) || amount <= 0) return;
|
|
399
|
+
const unit = match[2]?.toLowerCase();
|
|
400
|
+
if ('px' === unit) return 0.75 * amount;
|
|
401
|
+
if ('in' === unit) return 72 * amount;
|
|
402
|
+
if ('cm' === unit) return 72 * amount / 2.54;
|
|
403
|
+
if ('mm' === unit) return 72 * amount / 25.4;
|
|
404
|
+
return amount;
|
|
405
|
+
}
|
|
406
|
+
function cssColorToHex(source) {
|
|
407
|
+
const value = source.trim();
|
|
408
|
+
const hex = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(value)?.[1];
|
|
409
|
+
if (hex) return (3 === hex.length ? [
|
|
410
|
+
...hex
|
|
411
|
+
].map((character)=>character.repeat(2)).join('') : hex).toUpperCase();
|
|
412
|
+
const rgb = /^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,[^)]*)?\)$/i.exec(value);
|
|
413
|
+
if (!rgb) return;
|
|
414
|
+
return rgb.slice(1, 4).map((channel)=>Math.min(255, Number(channel)).toString(16).padStart(2, '0')).join('').toUpperCase();
|
|
415
|
+
}
|
|
416
|
+
async function imageToDocx(element, docx) {
|
|
417
|
+
const source = element.getAttribute('src');
|
|
418
|
+
const alt = element.getAttribute('alt') || element.getAttribute('title') || 'Image';
|
|
419
|
+
if (!source) return new docx.TextRun(`[${alt}]`);
|
|
420
|
+
try {
|
|
421
|
+
const blob = await fetch(source).then((response)=>{
|
|
422
|
+
if (!response.ok) throw new Error(`Image request failed with HTTP ${response.status}`);
|
|
423
|
+
return response.blob();
|
|
424
|
+
});
|
|
425
|
+
const type = docxImageType(blob.type, source);
|
|
426
|
+
if (!type) return new docx.TextRun(`[${alt}]`);
|
|
427
|
+
const dimensions = element.width > 0 && element.height > 0 ? {
|
|
428
|
+
width: element.width,
|
|
429
|
+
height: element.height
|
|
430
|
+
} : await imageDimensions(blob);
|
|
431
|
+
const maximumWidth = 520;
|
|
432
|
+
const scale = Math.min(1, maximumWidth / Math.max(1, dimensions.width));
|
|
433
|
+
return new docx.ImageRun({
|
|
434
|
+
type,
|
|
435
|
+
data: await blob.arrayBuffer(),
|
|
436
|
+
transformation: {
|
|
437
|
+
width: Math.max(24, Math.round(dimensions.width * scale)),
|
|
438
|
+
height: Math.max(24, Math.round(dimensions.height * scale))
|
|
439
|
+
},
|
|
440
|
+
altText: {
|
|
441
|
+
name: alt,
|
|
442
|
+
description: alt,
|
|
443
|
+
title: alt
|
|
444
|
+
},
|
|
445
|
+
floating: documentImageFloatingOptions(element, docx)
|
|
446
|
+
});
|
|
447
|
+
} catch {
|
|
448
|
+
return new docx.TextRun(`[${alt}]`);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function documentImageFloatingOptions(element, docx) {
|
|
452
|
+
const image = documentImageLayoutFromElement(element);
|
|
453
|
+
if ('inline' === image.layout) return;
|
|
454
|
+
const distance = Math.round(36000 * image.wrapDistance);
|
|
455
|
+
const align = 'left' === image.alignment ? docx.HorizontalPositionAlign.LEFT : 'right' === image.alignment ? docx.HorizontalPositionAlign.RIGHT : docx.HorizontalPositionAlign.CENTER;
|
|
456
|
+
return {
|
|
457
|
+
horizontalPosition: {
|
|
458
|
+
relative: docx.HorizontalPositionRelativeFrom.COLUMN,
|
|
459
|
+
align
|
|
460
|
+
},
|
|
461
|
+
verticalPosition: {
|
|
462
|
+
relative: docx.VerticalPositionRelativeFrom.PARAGRAPH,
|
|
463
|
+
offset: 0
|
|
464
|
+
},
|
|
465
|
+
allowOverlap: false,
|
|
466
|
+
behindDocument: false,
|
|
467
|
+
layoutInCell: true,
|
|
468
|
+
lockAnchor: false,
|
|
469
|
+
margins: {
|
|
470
|
+
top: distance,
|
|
471
|
+
right: distance,
|
|
472
|
+
bottom: distance,
|
|
473
|
+
left: distance
|
|
474
|
+
},
|
|
475
|
+
wrap: {
|
|
476
|
+
type: 'square' === image.layout ? docx.TextWrappingType.SQUARE : docx.TextWrappingType.TOP_AND_BOTTOM,
|
|
477
|
+
...'square' === image.layout ? {
|
|
478
|
+
side: docx.TextWrappingSide.BOTH_SIDES
|
|
479
|
+
} : {}
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
function docxImageType(contentType, source) {
|
|
484
|
+
const value = `${contentType} ${source}`.toLowerCase();
|
|
485
|
+
if (value.includes('png')) return 'png';
|
|
486
|
+
if (value.includes('jpeg') || value.includes('jpg')) return 'jpg';
|
|
487
|
+
if (value.includes('gif')) return 'gif';
|
|
488
|
+
if (value.includes('bmp')) return 'bmp';
|
|
489
|
+
return null;
|
|
490
|
+
}
|
|
491
|
+
function imageDimensions(blob) {
|
|
492
|
+
return new Promise((resolve, reject)=>{
|
|
493
|
+
const url = URL.createObjectURL(blob);
|
|
494
|
+
const image = new window.Image();
|
|
495
|
+
image.addEventListener('load', ()=>{
|
|
496
|
+
URL.revokeObjectURL(url);
|
|
497
|
+
resolve({
|
|
498
|
+
width: image.naturalWidth || 640,
|
|
499
|
+
height: image.naturalHeight || 360
|
|
500
|
+
});
|
|
501
|
+
}, {
|
|
502
|
+
once: true
|
|
503
|
+
});
|
|
504
|
+
image.addEventListener('error', ()=>{
|
|
505
|
+
URL.revokeObjectURL(url);
|
|
506
|
+
reject(new Error('Image dimensions could not be read'));
|
|
507
|
+
}, {
|
|
508
|
+
once: true
|
|
509
|
+
});
|
|
510
|
+
image.src = url;
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
async function createDocxBlob(content) {
|
|
514
|
+
const docx = await import("docx");
|
|
515
|
+
const noteCollection = collectDocumentNotes(content.html);
|
|
516
|
+
const comments = anchoredDocumentComments(content);
|
|
517
|
+
const noteContext = {
|
|
518
|
+
ids: new Map(noteCollection.notes.map((note)=>[
|
|
519
|
+
documentNoteKey(note.kind, note.id),
|
|
520
|
+
note.number
|
|
521
|
+
])),
|
|
522
|
+
changeIds: new Map(),
|
|
523
|
+
nextChangeId: 1,
|
|
524
|
+
commentIds: new Map(),
|
|
525
|
+
commentRangeCounts: documentCommentRangeCounts(content.html),
|
|
526
|
+
commentRangeSeen: new Map(),
|
|
527
|
+
numbering: [],
|
|
528
|
+
nextNumberingReference: 1
|
|
529
|
+
};
|
|
530
|
+
const commentRecords = createDocxCommentRecords(comments, docx, noteContext);
|
|
531
|
+
const sections = [];
|
|
532
|
+
let usesOddEvenPageChrome = false;
|
|
533
|
+
for (const section of documentSections({
|
|
534
|
+
...content,
|
|
535
|
+
html: noteCollection.html
|
|
536
|
+
})){
|
|
537
|
+
const parsed = new DOMParser().parseFromString(section.html, 'text/html');
|
|
538
|
+
const children = [];
|
|
539
|
+
for (const node of parsed.body.children){
|
|
540
|
+
const element = node;
|
|
541
|
+
if (!element.hasAttribute('data-document-note')) children.push(...await blockToFileChildren(element, docx, noteContext));
|
|
542
|
+
}
|
|
543
|
+
if (!children.length) children.push(new docx.Paragraph(''));
|
|
544
|
+
const pageChrome = normalizeDocumentPageChrome(section.layout.pageChrome, section.layout);
|
|
545
|
+
usesOddEvenPageChrome ||= pageChrome.differentOddEvenPages;
|
|
546
|
+
const headers = await sectionHeaders(pageChrome, docx, noteContext);
|
|
547
|
+
const footers = await sectionFooters(pageChrome, docx, noteContext);
|
|
548
|
+
sections.push({
|
|
549
|
+
properties: sectionProperties(section.layout, docx),
|
|
550
|
+
headers,
|
|
551
|
+
footers,
|
|
552
|
+
children
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
const footnotes = await createNoteRecords(noteCollection.notes, 'footnote', docx, noteContext);
|
|
556
|
+
const endnotes = await createNoteRecords(noteCollection.notes, 'endnote', docx, noteContext);
|
|
557
|
+
const document = new docx.Document({
|
|
558
|
+
sections,
|
|
559
|
+
footnotes: Object.keys(footnotes).length ? footnotes : void 0,
|
|
560
|
+
endnotes: Object.keys(endnotes).length ? endnotes : void 0,
|
|
561
|
+
comments: commentRecords.length ? {
|
|
562
|
+
children: commentRecords
|
|
563
|
+
} : void 0,
|
|
564
|
+
numbering: noteContext.numbering.length ? {
|
|
565
|
+
config: noteContext.numbering
|
|
566
|
+
} : void 0,
|
|
567
|
+
evenAndOddHeaderAndFooters: usesOddEvenPageChrome,
|
|
568
|
+
features: {
|
|
569
|
+
trackRevisions: Boolean(content.trackChanges || documentHasTrackedChanges(content.html)),
|
|
570
|
+
updateFields: true
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
const packed = await docx.Packer.toBlob(document);
|
|
574
|
+
const bibliographyPatched = await patchDocxBibliography(await packed.arrayBuffer(), content.bibliography);
|
|
575
|
+
const patched = await patchDocxPageColor(bibliographyPatched, content.pageColor);
|
|
576
|
+
return new Blob([
|
|
577
|
+
patched
|
|
578
|
+
], {
|
|
579
|
+
type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
function sectionProperties(layout, docx) {
|
|
583
|
+
const landscape = 'landscape' === layout.orientation;
|
|
584
|
+
const dimensions = 'letter' === layout.pageSize ? {
|
|
585
|
+
width: landscape ? 15840 : 12240,
|
|
586
|
+
height: landscape ? 12240 : 15840
|
|
587
|
+
} : {
|
|
588
|
+
width: landscape ? 16838 : 11906,
|
|
589
|
+
height: landscape ? 11906 : 16838
|
|
590
|
+
};
|
|
591
|
+
return {
|
|
592
|
+
type: docxSectionType(layout.breakAfter, docx),
|
|
593
|
+
titlePage: normalizeDocumentPageChrome(layout.pageChrome, layout).differentFirstPage,
|
|
594
|
+
page: {
|
|
595
|
+
size: {
|
|
596
|
+
...dimensions,
|
|
597
|
+
orientation: landscape ? docx.PageOrientation.LANDSCAPE : docx.PageOrientation.PORTRAIT
|
|
598
|
+
},
|
|
599
|
+
margin: {
|
|
600
|
+
top: work_docx_export_millimetersToTwips(layout.margins.top),
|
|
601
|
+
right: work_docx_export_millimetersToTwips(layout.margins.right),
|
|
602
|
+
bottom: work_docx_export_millimetersToTwips(layout.margins.bottom),
|
|
603
|
+
left: work_docx_export_millimetersToTwips(layout.margins.left)
|
|
604
|
+
},
|
|
605
|
+
pageNumbers: layout.pageNumberStart ? {
|
|
606
|
+
start: layout.pageNumberStart
|
|
607
|
+
} : void 0
|
|
608
|
+
},
|
|
609
|
+
column: docxSectionColumns(layout, dimensions.width, docx)
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
async function sectionHeaders(chrome, docx, noteContext) {
|
|
613
|
+
const headers = {};
|
|
614
|
+
const defaultHeader = await headerFromHtml(chrome.default.headerHtml, docx, noteContext);
|
|
615
|
+
if (defaultHeader) headers.default = defaultHeader;
|
|
616
|
+
if (chrome.differentFirstPage) {
|
|
617
|
+
const firstHeader = await headerFromHtml(chrome.first.headerHtml, docx, noteContext);
|
|
618
|
+
if (firstHeader) headers.first = firstHeader;
|
|
619
|
+
}
|
|
620
|
+
if (chrome.differentOddEvenPages) {
|
|
621
|
+
const evenHeader = await headerFromHtml(chrome.even.headerHtml, docx, noteContext);
|
|
622
|
+
if (evenHeader) headers.even = evenHeader;
|
|
623
|
+
}
|
|
624
|
+
return Object.keys(headers).length ? headers : void 0;
|
|
625
|
+
}
|
|
626
|
+
async function sectionFooters(chrome, docx, noteContext) {
|
|
627
|
+
const footers = {};
|
|
628
|
+
const defaultFooter = await footerFromContent(chrome.default, docx, noteContext);
|
|
629
|
+
if (defaultFooter) footers.default = defaultFooter;
|
|
630
|
+
if (chrome.differentFirstPage) {
|
|
631
|
+
const firstFooter = await footerFromContent(chrome.first, docx, noteContext);
|
|
632
|
+
if (firstFooter) footers.first = firstFooter;
|
|
633
|
+
}
|
|
634
|
+
if (chrome.differentOddEvenPages) {
|
|
635
|
+
const evenFooter = await footerFromContent(chrome.even, docx, noteContext);
|
|
636
|
+
if (evenFooter) footers.even = evenFooter;
|
|
637
|
+
}
|
|
638
|
+
return Object.keys(footers).length ? footers : void 0;
|
|
639
|
+
}
|
|
640
|
+
async function headerFromHtml(html, docx, noteContext) {
|
|
641
|
+
const children = await pageChromeBlocks(html, docx, noteContext);
|
|
642
|
+
return children.length ? new docx.Header({
|
|
643
|
+
children
|
|
644
|
+
}) : void 0;
|
|
645
|
+
}
|
|
646
|
+
async function footerFromContent(content, docx, noteContext) {
|
|
647
|
+
const children = await pageChromeBlocks(content.footerHtml, docx, noteContext);
|
|
648
|
+
if (content.showPageNumber) children.push(new docx.Paragraph({
|
|
649
|
+
alignment: docx.AlignmentType.CENTER,
|
|
650
|
+
children: [
|
|
651
|
+
new docx.TextRun({
|
|
652
|
+
children: [
|
|
653
|
+
docx.PageNumber.CURRENT
|
|
654
|
+
]
|
|
655
|
+
})
|
|
656
|
+
]
|
|
657
|
+
}));
|
|
658
|
+
return children.length ? new docx.Footer({
|
|
659
|
+
children
|
|
660
|
+
}) : void 0;
|
|
661
|
+
}
|
|
662
|
+
function docxSectionType(type, docx) {
|
|
663
|
+
if ('continuous' === type) return docx.SectionType.CONTINUOUS;
|
|
664
|
+
if ('evenPage' === type) return docx.SectionType.EVEN_PAGE;
|
|
665
|
+
if ('oddPage' === type) return docx.SectionType.ODD_PAGE;
|
|
666
|
+
if ('nextColumn' === type) return docx.SectionType.NEXT_COLUMN;
|
|
667
|
+
return docx.SectionType.NEXT_PAGE;
|
|
668
|
+
}
|
|
669
|
+
async function blockToFileChildren(element, docx, noteContext) {
|
|
670
|
+
const tag = element.tagName.toLowerCase();
|
|
671
|
+
if (element.hasAttribute('data-page-break')) return [
|
|
672
|
+
new docx.Paragraph({
|
|
673
|
+
children: [
|
|
674
|
+
new docx.PageBreak()
|
|
675
|
+
]
|
|
676
|
+
})
|
|
677
|
+
];
|
|
678
|
+
if (element.hasAttribute('data-document-bibliography')) return [
|
|
679
|
+
docxBibliographyParagraph(element, docx, paragraphBidirectional(element))
|
|
680
|
+
];
|
|
681
|
+
if (element.hasAttribute('data-document-caption')) return [
|
|
682
|
+
docxCaptionParagraph(element, await inlineRuns(element, docx, noteContext), docx, paragraphBidirectional(element))
|
|
683
|
+
];
|
|
684
|
+
if ('table' === tag) return [
|
|
685
|
+
await tableToDocx(element, docx, noteContext)
|
|
686
|
+
];
|
|
687
|
+
if ('img' === tag) return [
|
|
688
|
+
new docx.Paragraph({
|
|
689
|
+
children: [
|
|
690
|
+
await imageToDocx(element, docx)
|
|
691
|
+
]
|
|
692
|
+
})
|
|
693
|
+
];
|
|
694
|
+
if ('ul' === tag || 'ol' === tag) return listToDocxParagraphs(element, docx, noteContext);
|
|
695
|
+
const runs = await inlineRuns(element, docx, noteContext);
|
|
696
|
+
const heading = 'h1' === tag ? docx.HeadingLevel.HEADING_1 : 'h2' === tag ? docx.HeadingLevel.HEADING_2 : 'h3' === tag ? docx.HeadingLevel.HEADING_3 : void 0;
|
|
697
|
+
return [
|
|
698
|
+
new docx.Paragraph({
|
|
699
|
+
children: runs.length ? runs : [
|
|
700
|
+
new docx.TextRun('')
|
|
701
|
+
],
|
|
702
|
+
heading,
|
|
703
|
+
alignment: paragraphAlignment(element, docx),
|
|
704
|
+
spacing: paragraphSpacingOptions(element, Boolean(heading), docx),
|
|
705
|
+
indent: paragraphIndent(element, tag),
|
|
706
|
+
tabStops: paragraphTabStops(element, docx),
|
|
707
|
+
...paragraphPaginationOptions(element),
|
|
708
|
+
...paragraphDirectionOptions(element)
|
|
709
|
+
})
|
|
710
|
+
];
|
|
711
|
+
}
|
|
712
|
+
async function listToDocxParagraphs(list, docx, noteContext, depth = 0) {
|
|
713
|
+
const paragraphs = [];
|
|
714
|
+
const level = Math.min(8, Math.max(0, depth));
|
|
715
|
+
const ordered = 'ol' === list.tagName.toLowerCase();
|
|
716
|
+
const numbering = ordered ? registerOrderedListNumbering(list, level, docx, noteContext) : registerBulletListNumbering(list, level, docx, noteContext);
|
|
717
|
+
const items = Array.from(list.children).filter((child)=>child instanceof HTMLElement && 'li' === child.tagName.toLowerCase());
|
|
718
|
+
for (const item of items){
|
|
719
|
+
const directBlocks = Array.from(item.children).filter((child)=>child instanceof HTMLElement && 'ol' !== child.tagName.toLowerCase() && 'ul' !== child.tagName.toLowerCase());
|
|
720
|
+
const contentBlocks = directBlocks.length ? directBlocks : [
|
|
721
|
+
directListItemContentRoot(item)
|
|
722
|
+
];
|
|
723
|
+
for (const [blockIndex, block] of contentBlocks.entries()){
|
|
724
|
+
const tag = block.tagName.toLowerCase();
|
|
725
|
+
const heading = 'h1' === tag ? docx.HeadingLevel.HEADING_1 : 'h2' === tag ? docx.HeadingLevel.HEADING_2 : 'h3' === tag ? docx.HeadingLevel.HEADING_3 : void 0;
|
|
726
|
+
const runs = await inlineRuns(block, docx, noteContext);
|
|
727
|
+
paragraphs.push(new docx.Paragraph({
|
|
728
|
+
children: runs.length ? runs : [
|
|
729
|
+
new docx.TextRun('')
|
|
730
|
+
],
|
|
731
|
+
heading,
|
|
732
|
+
...0 === blockIndex ? {
|
|
733
|
+
numbering
|
|
734
|
+
} : {
|
|
735
|
+
indent: paragraphIndent(block, tag) ?? {
|
|
736
|
+
left: (level + 1) * 720
|
|
737
|
+
}
|
|
738
|
+
},
|
|
739
|
+
alignment: paragraphAlignment(block, docx),
|
|
740
|
+
spacing: paragraphSpacingOptions(block, Boolean(heading), docx),
|
|
741
|
+
...0 === blockIndex ? {
|
|
742
|
+
indent: paragraphIndent(block, tag)
|
|
743
|
+
} : {},
|
|
744
|
+
tabStops: paragraphTabStops(block, docx),
|
|
745
|
+
...paragraphPaginationOptions(block),
|
|
746
|
+
...paragraphDirectionOptions(block)
|
|
747
|
+
}));
|
|
748
|
+
}
|
|
749
|
+
for (const nested of Array.from(item.children).filter((child)=>child instanceof HTMLElement && ('ol' === child.tagName.toLowerCase() || 'ul' === child.tagName.toLowerCase())))paragraphs.push(...await listToDocxParagraphs(nested, docx, noteContext, depth + 1));
|
|
750
|
+
}
|
|
751
|
+
return paragraphs;
|
|
752
|
+
}
|
|
753
|
+
function registerOrderedListNumbering(list, level, docx, noteContext) {
|
|
754
|
+
const reference = `a3s-office-list-${noteContext.nextNumberingReference}`;
|
|
755
|
+
noteContext.nextNumberingReference += 1;
|
|
756
|
+
noteContext.numbering.push({
|
|
757
|
+
reference,
|
|
758
|
+
levels: Array.from({
|
|
759
|
+
length: 9
|
|
760
|
+
}, (_, currentLevel)=>({
|
|
761
|
+
level: currentLevel,
|
|
762
|
+
format: currentLevel === level ? orderedListLevelFormat(list, currentLevel, docx) : defaultOrderedListLevelFormat(currentLevel, docx),
|
|
763
|
+
text: `%${currentLevel + 1}.`,
|
|
764
|
+
start: currentLevel === level ? orderedListStart(list) : 1,
|
|
765
|
+
suffix: docx.LevelSuffix.TAB,
|
|
766
|
+
style: {
|
|
767
|
+
paragraph: {
|
|
768
|
+
indent: {
|
|
769
|
+
left: (currentLevel + 1) * 720,
|
|
770
|
+
hanging: 360
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
}))
|
|
775
|
+
});
|
|
776
|
+
return {
|
|
777
|
+
reference,
|
|
778
|
+
level
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
function registerBulletListNumbering(list, level, docx, noteContext) {
|
|
782
|
+
const reference = `a3s-office-list-${noteContext.nextNumberingReference}`;
|
|
783
|
+
noteContext.nextNumberingReference += 1;
|
|
784
|
+
noteContext.numbering.push({
|
|
785
|
+
reference,
|
|
786
|
+
levels: Array.from({
|
|
787
|
+
length: 9
|
|
788
|
+
}, (_, currentLevel)=>({
|
|
789
|
+
level: currentLevel,
|
|
790
|
+
format: docx.LevelFormat.BULLET,
|
|
791
|
+
text: currentLevel === level ? bulletListMarker(list) : defaultBulletListMarker(currentLevel),
|
|
792
|
+
start: 1,
|
|
793
|
+
suffix: docx.LevelSuffix.TAB,
|
|
794
|
+
style: {
|
|
795
|
+
paragraph: {
|
|
796
|
+
indent: {
|
|
797
|
+
left: (currentLevel + 1) * 720,
|
|
798
|
+
hanging: 360
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}))
|
|
803
|
+
});
|
|
804
|
+
return {
|
|
805
|
+
reference,
|
|
806
|
+
level
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
function orderedListLevelFormat(list, level, docx) {
|
|
810
|
+
const type = list.getAttribute('type');
|
|
811
|
+
if ('A' === type) return docx.LevelFormat.UPPER_LETTER;
|
|
812
|
+
if ('a' === type) return docx.LevelFormat.LOWER_LETTER;
|
|
813
|
+
if ('I' === type) return docx.LevelFormat.UPPER_ROMAN;
|
|
814
|
+
if ('i' === type) return docx.LevelFormat.LOWER_ROMAN;
|
|
815
|
+
return defaultOrderedListLevelFormat(level, docx);
|
|
816
|
+
}
|
|
817
|
+
function defaultOrderedListLevelFormat(level, docx) {
|
|
818
|
+
if (level % 3 === 1) return docx.LevelFormat.LOWER_LETTER;
|
|
819
|
+
if (level % 3 === 2) return docx.LevelFormat.LOWER_ROMAN;
|
|
820
|
+
return docx.LevelFormat.DECIMAL;
|
|
821
|
+
}
|
|
822
|
+
function orderedListStart(list) {
|
|
823
|
+
const value = Number(list.getAttribute('start'));
|
|
824
|
+
return Number.isSafeInteger(value) && value > 0 ? Math.min(value, 2147483647) : 1;
|
|
825
|
+
}
|
|
826
|
+
function bulletListMarker(list) {
|
|
827
|
+
const style = list.dataset.officeBulletStyle || list.style.listStyleType || 'disc';
|
|
828
|
+
if ('circle' === style) return '○';
|
|
829
|
+
if ('square' === style) return '■';
|
|
830
|
+
return '●';
|
|
831
|
+
}
|
|
832
|
+
function defaultBulletListMarker(level) {
|
|
833
|
+
if (level % 3 === 1) return '○';
|
|
834
|
+
if (level % 3 === 2) return '■';
|
|
835
|
+
return '●';
|
|
836
|
+
}
|
|
837
|
+
function directListItemContentRoot(item) {
|
|
838
|
+
const root = item.ownerDocument.createElement('span');
|
|
839
|
+
const direction = item.getAttribute('dir');
|
|
840
|
+
if (direction) root.setAttribute('dir', direction);
|
|
841
|
+
for (const child of item.childNodes)if (!(child instanceof HTMLElement) || 'ol' !== child.tagName.toLowerCase() && 'ul' !== child.tagName.toLowerCase()) root.append(child.cloneNode(true));
|
|
842
|
+
return root;
|
|
843
|
+
}
|
|
844
|
+
function work_docx_export_millimetersToTwips(value) {
|
|
845
|
+
return Math.round(1440 * value / 25.4);
|
|
846
|
+
}
|
|
847
|
+
async function pageChromeBlocks(html, docx, noteContext) {
|
|
848
|
+
if (!html.trim()) return [];
|
|
849
|
+
const document = new DOMParser().parseFromString(html, 'text/html');
|
|
850
|
+
const children = [];
|
|
851
|
+
for (const element of Array.from(document.body.children)){
|
|
852
|
+
const blocks = await blockToFileChildren(element, docx, noteContext);
|
|
853
|
+
for (const block of blocks)if (block instanceof docx.Paragraph || block instanceof docx.Table) children.push(block);
|
|
854
|
+
}
|
|
855
|
+
if (!children.length && document.body.textContent?.trim()) children.push(new docx.Paragraph({
|
|
856
|
+
children: await inlineRuns(document.body, docx, noteContext),
|
|
857
|
+
...paragraphDirectionOptions(document.body)
|
|
858
|
+
}));
|
|
859
|
+
return children;
|
|
860
|
+
}
|
|
861
|
+
async function inlineRuns(root, docx, noteContext) {
|
|
862
|
+
const runs = [];
|
|
863
|
+
const visit = async (node, inherited = {}, revision)=>{
|
|
864
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
865
|
+
if (!node.textContent) return [];
|
|
866
|
+
if (revision?.kind === 'insertion') return [
|
|
867
|
+
new docx.InsertedTextRun({
|
|
868
|
+
...inherited,
|
|
869
|
+
id: revision.id,
|
|
870
|
+
author: revision.author,
|
|
871
|
+
date: revision.date,
|
|
872
|
+
text: node.textContent
|
|
873
|
+
})
|
|
874
|
+
];
|
|
875
|
+
if (revision?.kind === 'deletion') return [
|
|
876
|
+
new docx.DeletedTextRun({
|
|
877
|
+
...inherited,
|
|
878
|
+
id: revision.id,
|
|
879
|
+
author: revision.author,
|
|
880
|
+
date: revision.date,
|
|
881
|
+
text: node.textContent
|
|
882
|
+
})
|
|
883
|
+
];
|
|
884
|
+
return [
|
|
885
|
+
new docx.TextRun({
|
|
886
|
+
...inherited,
|
|
887
|
+
text: node.textContent
|
|
888
|
+
})
|
|
889
|
+
];
|
|
890
|
+
}
|
|
891
|
+
if (!(node instanceof HTMLElement)) return [];
|
|
892
|
+
const tag = node.tagName.toLowerCase();
|
|
893
|
+
if (node.hasAttribute('data-document-tab')) return [
|
|
894
|
+
new docx.Tab()
|
|
895
|
+
];
|
|
896
|
+
if (node.hasAttribute('data-document-citation')) return [
|
|
897
|
+
docxCitationRun(node, docx)
|
|
898
|
+
];
|
|
899
|
+
if (node.hasAttribute('data-document-field')) return [
|
|
900
|
+
docxDocumentFieldRun(node, docx)
|
|
901
|
+
];
|
|
902
|
+
if (node.hasAttribute('data-document-cross-reference')) return docxCrossReferenceRuns(node, docx);
|
|
903
|
+
if (node.hasAttribute('data-document-note-reference')) {
|
|
904
|
+
const kind = documentNoteKind(node.dataset.noteKind);
|
|
905
|
+
const id = node.dataset.noteId?.trim();
|
|
906
|
+
const noteId = kind && id ? noteContext.ids.get(documentNoteKey(kind, id)) : void 0;
|
|
907
|
+
if (!kind || !noteId) return [];
|
|
908
|
+
return [
|
|
909
|
+
'footnote' === kind ? new docx.FootnoteReferenceRun(noteId) : new docx.EndnoteReferenceRun(noteId)
|
|
910
|
+
];
|
|
911
|
+
}
|
|
912
|
+
const change = node.hasAttribute('data-document-change') ? docxTextRevision(node, 'del' === tag ? 'deletion' : 'insertion', noteContext) : revision;
|
|
913
|
+
const commentBoundary = node.hasAttribute('data-document-comment') ? nextDocxCommentBoundary(node.dataset.commentId, noteContext) : null;
|
|
914
|
+
const backgroundColor = cssColorToHex(node.style.backgroundColor);
|
|
915
|
+
const direction = domDirection(node);
|
|
916
|
+
const style = {
|
|
917
|
+
...inherited,
|
|
918
|
+
bold: inherited.bold || 'strong' === tag || 'b' === tag,
|
|
919
|
+
italics: inherited.italics || 'em' === tag || 'i' === tag,
|
|
920
|
+
underline: inherited.underline || 'u' === tag ? {} : void 0,
|
|
921
|
+
strike: inherited.strike || 's' === tag || 'strike' === tag,
|
|
922
|
+
subScript: inherited.subScript || 'sub' === tag,
|
|
923
|
+
superScript: inherited.superScript || 'sup' === tag,
|
|
924
|
+
color: cssColorToHex(node.style.color) ?? inherited.color,
|
|
925
|
+
font: cssFontFamily(node.style.fontFamily) ?? inherited.font,
|
|
926
|
+
size: cssFontSize(node.style.fontSize) ?? inherited.size,
|
|
927
|
+
shading: backgroundColor ? {
|
|
928
|
+
fill: backgroundColor
|
|
929
|
+
} : inherited.shading,
|
|
930
|
+
rightToLeft: void 0 === direction ? inherited.rightToLeft : 'rtl' === direction
|
|
931
|
+
};
|
|
932
|
+
if ('br' === tag) return [
|
|
933
|
+
new docx.TextRun({
|
|
934
|
+
...style,
|
|
935
|
+
break: 1
|
|
936
|
+
})
|
|
937
|
+
];
|
|
938
|
+
if ('img' === tag) return [
|
|
939
|
+
await imageToDocx(node, docx)
|
|
940
|
+
];
|
|
941
|
+
const children = [];
|
|
942
|
+
for (const child of node.childNodes)children.push(...await visit(child, style, change));
|
|
943
|
+
const result = 'a' === tag && node.getAttribute('href') ? [
|
|
944
|
+
new docx.ExternalHyperlink({
|
|
945
|
+
link: node.getAttribute('href') ?? '',
|
|
946
|
+
children
|
|
947
|
+
})
|
|
948
|
+
] : children;
|
|
949
|
+
if (!commentBoundary) return result;
|
|
950
|
+
return [
|
|
951
|
+
...commentBoundary.start ? [
|
|
952
|
+
new docx.CommentRangeStart(commentBoundary.id)
|
|
953
|
+
] : [],
|
|
954
|
+
...result,
|
|
955
|
+
...commentBoundary.end ? [
|
|
956
|
+
new docx.CommentRangeEnd(commentBoundary.id),
|
|
957
|
+
new docx.CommentReference(commentBoundary.id)
|
|
958
|
+
] : []
|
|
959
|
+
];
|
|
960
|
+
};
|
|
961
|
+
const direction = domDirection(root);
|
|
962
|
+
const inheritedDirection = void 0 === direction ? {} : {
|
|
963
|
+
rightToLeft: 'rtl' === direction
|
|
964
|
+
};
|
|
965
|
+
for (const node of root.childNodes)runs.push(...await visit(node, inheritedDirection));
|
|
966
|
+
return runs;
|
|
967
|
+
}
|
|
968
|
+
function docxTextRevision(element, kind, context) {
|
|
969
|
+
const key = element.dataset.changeId?.trim() || `change-${context.nextChangeId}`;
|
|
970
|
+
let id = context.changeIds.get(key);
|
|
971
|
+
if (!id) {
|
|
972
|
+
id = context.nextChangeId;
|
|
973
|
+
context.nextChangeId += 1;
|
|
974
|
+
context.changeIds.set(key, id);
|
|
975
|
+
}
|
|
976
|
+
const sourceDate = element.dataset.changeDate?.trim() ?? '';
|
|
977
|
+
const time = Date.parse(sourceDate);
|
|
978
|
+
return {
|
|
979
|
+
kind,
|
|
980
|
+
id,
|
|
981
|
+
author: element.dataset.changeAuthor?.trim() || 'A3S Work',
|
|
982
|
+
date: Number.isFinite(time) ? new Date(time).toISOString() : new Date().toISOString()
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
function documentHasTrackedChanges(html) {
|
|
986
|
+
const document = new DOMParser().parseFromString(html, 'text/html');
|
|
987
|
+
return Boolean(document.body.querySelector('ins[data-document-change], del[data-document-change]'));
|
|
988
|
+
}
|
|
989
|
+
function anchoredDocumentComments(content) {
|
|
990
|
+
const document = new DOMParser().parseFromString(content.html, 'text/html');
|
|
991
|
+
const ids = Array.from(document.body.querySelectorAll('[data-document-comment][data-comment-id]')).map((element)=>element.dataset.commentId?.trim() ?? '').filter(Boolean);
|
|
992
|
+
const stored = new Map((content.comments ?? []).map((comment)=>[
|
|
993
|
+
comment.id,
|
|
994
|
+
comment
|
|
995
|
+
]));
|
|
996
|
+
return Array.from(new Set(ids)).map((id)=>stored.get(id) ?? {
|
|
997
|
+
id,
|
|
998
|
+
author: '未知审阅者',
|
|
999
|
+
date: '',
|
|
1000
|
+
text: '此批注的内容不可用。',
|
|
1001
|
+
resolved: false
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
function documentCommentRangeCounts(html) {
|
|
1005
|
+
const document = new DOMParser().parseFromString(html, 'text/html');
|
|
1006
|
+
const counts = new Map();
|
|
1007
|
+
for (const element of Array.from(document.body.querySelectorAll('[data-document-comment][data-comment-id]'))){
|
|
1008
|
+
const id = element.dataset.commentId?.trim();
|
|
1009
|
+
if (id) counts.set(id, (counts.get(id) ?? 0) + 1);
|
|
1010
|
+
}
|
|
1011
|
+
return counts;
|
|
1012
|
+
}
|
|
1013
|
+
function createDocxCommentRecords(comments, docx, context) {
|
|
1014
|
+
const records = [];
|
|
1015
|
+
let nextId = 0;
|
|
1016
|
+
for (const comment of comments){
|
|
1017
|
+
const id = nextId;
|
|
1018
|
+
nextId += 1;
|
|
1019
|
+
context.commentIds.set(comment.id, id);
|
|
1020
|
+
records.push({
|
|
1021
|
+
id,
|
|
1022
|
+
author: comment.author || 'A3S Work',
|
|
1023
|
+
initials: commentInitials(comment.author),
|
|
1024
|
+
date: commentDate(comment.date),
|
|
1025
|
+
resolved: Boolean(comment.resolved),
|
|
1026
|
+
children: [
|
|
1027
|
+
new docx.Paragraph({
|
|
1028
|
+
text: comment.text || '(空批注)'
|
|
1029
|
+
})
|
|
1030
|
+
]
|
|
1031
|
+
});
|
|
1032
|
+
for (const reply of comment.replies ?? []){
|
|
1033
|
+
records.push({
|
|
1034
|
+
id: nextId,
|
|
1035
|
+
parentId: id,
|
|
1036
|
+
author: reply.author || 'A3S Work',
|
|
1037
|
+
initials: commentInitials(reply.author),
|
|
1038
|
+
date: commentDate(reply.date),
|
|
1039
|
+
children: [
|
|
1040
|
+
new docx.Paragraph({
|
|
1041
|
+
text: reply.text || '(空回复)'
|
|
1042
|
+
})
|
|
1043
|
+
]
|
|
1044
|
+
});
|
|
1045
|
+
nextId += 1;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return records;
|
|
1049
|
+
}
|
|
1050
|
+
function nextDocxCommentBoundary(sourceId, context) {
|
|
1051
|
+
const key = sourceId?.trim() ?? '';
|
|
1052
|
+
const id = context.commentIds.get(key);
|
|
1053
|
+
const count = context.commentRangeCounts.get(key) ?? 0;
|
|
1054
|
+
if (void 0 === id || !count) return null;
|
|
1055
|
+
const seen = (context.commentRangeSeen.get(key) ?? 0) + 1;
|
|
1056
|
+
context.commentRangeSeen.set(key, seen);
|
|
1057
|
+
return {
|
|
1058
|
+
id,
|
|
1059
|
+
start: 1 === seen,
|
|
1060
|
+
end: seen === count
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
function commentDate(value) {
|
|
1064
|
+
const time = Date.parse(value);
|
|
1065
|
+
return Number.isFinite(time) ? new Date(time) : new Date();
|
|
1066
|
+
}
|
|
1067
|
+
function commentInitials(author) {
|
|
1068
|
+
const parts = author.trim().split(/\s+/).filter(Boolean);
|
|
1069
|
+
if (!parts.length) return 'AW';
|
|
1070
|
+
return parts.slice(0, 2).map((part)=>Array.from(part)[0] ?? '').join('').toUpperCase();
|
|
1071
|
+
}
|
|
1072
|
+
async function tableToDocx(element, docx, noteContext) {
|
|
1073
|
+
const rows = [];
|
|
1074
|
+
let inferLeadingHeader = true;
|
|
1075
|
+
for (const row of Array.from(element.rows)){
|
|
1076
|
+
const cells = [];
|
|
1077
|
+
for (const cell of Array.from(row.cells)){
|
|
1078
|
+
const children = [];
|
|
1079
|
+
const blocks = Array.from(cell.children);
|
|
1080
|
+
if (blocks.length) {
|
|
1081
|
+
for (const block of blocks)for (const child of (await blockToFileChildren(block, docx, noteContext)))if (child instanceof docx.Paragraph || child instanceof docx.Table) children.push(child);
|
|
1082
|
+
} else children.push(new docx.Paragraph({
|
|
1083
|
+
children: await inlineRuns(cell, docx, noteContext),
|
|
1084
|
+
...paragraphDirectionOptions(cell)
|
|
1085
|
+
}));
|
|
1086
|
+
cells.push(new docx.TableCell({
|
|
1087
|
+
children: children.length ? children : [
|
|
1088
|
+
new docx.Paragraph('')
|
|
1089
|
+
],
|
|
1090
|
+
columnSpan: cell.colSpan > 1 ? cell.colSpan : void 0,
|
|
1091
|
+
rowSpan: cell.rowSpan > 1 ? cell.rowSpan : void 0,
|
|
1092
|
+
...documentTableCellDocxOptions(cell, docx),
|
|
1093
|
+
...documentTableCellSizingDocxOptions(cell, docx),
|
|
1094
|
+
margins: {
|
|
1095
|
+
top: 80,
|
|
1096
|
+
right: 100,
|
|
1097
|
+
bottom: 80,
|
|
1098
|
+
left: 100
|
|
1099
|
+
}
|
|
1100
|
+
}));
|
|
1101
|
+
}
|
|
1102
|
+
const explicitHeader = dataBoolean(row.dataset.officeRepeatHeader);
|
|
1103
|
+
const inferredHeader = inferLeadingHeader && row.cells.length > 0 && Array.from(row.cells).every((cell)=>'th' === cell.tagName.toLowerCase());
|
|
1104
|
+
const tableHeader = explicitHeader ?? inferredHeader;
|
|
1105
|
+
if (!tableHeader) inferLeadingHeader = false;
|
|
1106
|
+
rows.push(new docx.TableRow({
|
|
1107
|
+
children: cells,
|
|
1108
|
+
cantSplit: dataBoolean(row.dataset.officeCantSplit),
|
|
1109
|
+
tableHeader: tableHeader ? true : void 0,
|
|
1110
|
+
...documentTableRowSizingDocxOptions(row, docx)
|
|
1111
|
+
}));
|
|
1112
|
+
}
|
|
1113
|
+
return new docx.Table({
|
|
1114
|
+
rows,
|
|
1115
|
+
...documentTableSizingDocxOptions(element, docx)
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
async function createNoteRecords(notes, kind, docx, noteContext) {
|
|
1119
|
+
const records = {};
|
|
1120
|
+
for (const note of notes)if (note.kind === kind) records[String(note.number)] = {
|
|
1121
|
+
children: await noteParagraphs(note.html, docx, noteContext)
|
|
1122
|
+
};
|
|
1123
|
+
return records;
|
|
1124
|
+
}
|
|
1125
|
+
async function noteParagraphs(html, docx, noteContext) {
|
|
1126
|
+
const document = new DOMParser().parseFromString(html, 'text/html');
|
|
1127
|
+
const paragraphs = [];
|
|
1128
|
+
for (const child of Array.from(document.body.children)){
|
|
1129
|
+
const element = child;
|
|
1130
|
+
const tag = element.tagName.toLowerCase();
|
|
1131
|
+
if ('ul' === tag || 'ol' === tag) {
|
|
1132
|
+
paragraphs.push(...await listToDocxParagraphs(element, docx, noteContext));
|
|
1133
|
+
continue;
|
|
1134
|
+
}
|
|
1135
|
+
if ('table' === tag) {
|
|
1136
|
+
for (const row of Array.from(element.rows))paragraphs.push(new docx.Paragraph({
|
|
1137
|
+
text: Array.from(row.cells).map((cell)=>cell.textContent?.trim() ?? '').join(' · '),
|
|
1138
|
+
...paragraphDirectionOptions(row)
|
|
1139
|
+
}));
|
|
1140
|
+
continue;
|
|
1141
|
+
}
|
|
1142
|
+
paragraphs.push(new docx.Paragraph({
|
|
1143
|
+
children: await inlineRuns(element, docx, noteContext),
|
|
1144
|
+
...paragraphDirectionOptions(element)
|
|
1145
|
+
}));
|
|
1146
|
+
}
|
|
1147
|
+
return paragraphs.length ? paragraphs : [
|
|
1148
|
+
new docx.Paragraph('')
|
|
1149
|
+
];
|
|
1150
|
+
}
|
|
1151
|
+
export { createDocxBlob };
|