@a3s-lab/office 0.2.2 → 0.4.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/COLLABORATION_ROADMAP.md +426 -0
- package/README.md +649 -10
- package/dist/0~1403.js +1 -1
- package/dist/0~2805.js +1279 -0
- package/dist/{0~use-office-draft.js → 0~345.js} +30 -1
- package/dist/0~3539.js +1 -1
- package/dist/0~3557.js +1 -1
- package/dist/0~3635.js +1 -1
- package/dist/0~4595.js +123 -12
- package/dist/0~4980.js +154 -0
- package/dist/0~5050.js +124 -113
- package/dist/{0~9512.js → 0~6090.js} +540 -3
- package/dist/0~7048.js +92 -66
- package/dist/0~7614.js +2 -1
- package/dist/0~7754.js +5653 -0
- package/dist/0~9445.js +1 -1
- package/dist/0~document-editor.js +4992 -3323
- package/dist/0~markdown-editor.js +250 -44
- package/dist/0~pdf-viewer.js +1016 -24
- package/dist/0~presentation-editor.js +179 -8
- package/dist/0~spreadsheet-editor.js +3371 -578
- package/dist/0~work-docx-export.js +6801 -658
- package/dist/0~work-docx-import.js +1388 -795
- package/dist/0~work-office-diagnostics.js +524 -30
- package/dist/0~work-pptx-export.js +2 -1
- package/dist/0~work-pptx-import.js +1 -2
- package/dist/0~work-presentation-charts.js +1 -1
- package/dist/2591.js +197 -0
- package/dist/3818.js +1090 -0
- package/dist/4104.js +970 -60
- package/dist/432.js +171 -14
- package/dist/4476.js +2008 -0
- package/dist/4560.js +674 -0
- package/dist/4650.js +70 -0
- package/dist/{1134.js → 5184.js} +183 -1
- package/dist/6489.js +18 -18
- package/dist/7060.js +132 -0
- package/dist/8715.js +2 -136
- package/dist/8928.js +16778 -0
- package/dist/9787.js +209 -0
- package/dist/core.d.ts +29 -9
- package/dist/core.js +10 -2
- package/dist/index.js +13 -3
- package/dist/internal/collaboration/office-collaboration-flat-json.d.ts +13 -0
- package/dist/internal/collaboration/office-collaboration-json.d.ts +4 -0
- package/dist/internal/collaboration/office-collaboration-presence.d.ts +86 -0
- package/dist/internal/collaboration/office-collaboration-transport.d.ts +42 -0
- package/dist/internal/collaboration/office-collaboration.d.ts +85 -0
- package/dist/internal/collaboration/office-document-collaboration-bibliography.d.ts +7 -0
- package/dist/internal/collaboration/office-document-collaboration-claims.d.ts +9 -0
- package/dist/internal/collaboration/office-document-collaboration-comments.d.ts +7 -0
- package/dist/internal/collaboration/office-document-collaboration-sidecar-utils.d.ts +27 -0
- package/dist/internal/collaboration/office-document-collaboration-sidecars.d.ts +16 -0
- package/dist/internal/collaboration/office-document-collaboration.d.ts +45 -0
- package/dist/internal/collaboration/office-markdown-collaboration.d.ts +31 -0
- package/dist/internal/collaboration/office-pdf-collaboration-claims.d.ts +4 -0
- package/dist/internal/collaboration/office-pdf-collaboration-conflicts.d.ts +2 -0
- package/dist/internal/collaboration/office-pdf-collaboration-model.d.ts +26 -0
- package/dist/internal/collaboration/office-pdf-collaboration-records.d.ts +21 -0
- package/dist/internal/collaboration/office-pdf-collaboration-types.d.ts +91 -0
- package/dist/internal/collaboration/office-pdf-collaboration-validation.d.ts +4 -0
- package/dist/internal/collaboration/office-pdf-collaboration.d.ts +35 -0
- package/dist/internal/collaboration/office-presentation-collaboration-model.d.ts +25 -0
- package/dist/internal/collaboration/office-presentation-collaboration-records.d.ts +22 -0
- package/dist/internal/collaboration/office-presentation-collaboration-validation.d.ts +4 -0
- package/dist/internal/collaboration/office-presentation-collaboration.d.ts +32 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-cells.d.ts +13 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-claims.d.ts +4 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-conflicts.d.ts +2 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-flat-json.d.ts +10 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-model.d.ts +31 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-records.d.ts +17 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-validation.d.ts +4 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration.d.ts +32 -0
- package/dist/internal/design-system/primitives/navigation/tabs.d.ts +3 -1
- package/dist/internal/features/work/components/work-document-page-border.d.ts +6 -0
- package/dist/internal/features/work/editors/document-command-catalog.d.ts +536 -0
- package/dist/internal/features/work/editors/document-editor-focus.d.ts +1 -1
- package/dist/internal/features/work/editors/document-editor-support.d.ts +7 -3
- package/dist/internal/features/work/editors/document-editor.d.ts +8 -2
- package/dist/internal/features/work/editors/document-external-content.d.ts +14 -0
- package/dist/internal/features/work/editors/document-format-clipboard.d.ts +6 -0
- package/dist/internal/features/work/editors/document-format-tools.d.ts +4 -0
- package/dist/internal/features/work/editors/document-layout-panel.d.ts +4 -1
- package/dist/internal/features/work/editors/document-page-chrome-wps-shortcuts.d.ts +2 -0
- package/dist/internal/features/work/editors/document-page-layout-ribbon.d.ts +14 -0
- package/dist/internal/features/work/editors/document-page-stack.d.ts +10 -1
- package/dist/internal/features/work/editors/document-page-thumbnail.d.ts +2 -0
- package/dist/internal/features/work/editors/document-pagination-run-coordinator.d.ts +26 -0
- package/dist/internal/features/work/editors/document-picture-properties-dialog-model.d.ts +20 -1
- package/dist/internal/features/work/editors/document-review-navigation.d.ts +9 -0
- package/dist/internal/features/work/editors/document-statistics-dialog.d.ts +7 -0
- package/dist/internal/features/work/editors/document-status-bar.d.ts +2 -1
- package/dist/internal/features/work/editors/document-table-properties-dialog-model.d.ts +4 -1
- package/dist/internal/features/work/editors/document-toolbar.d.ts +19 -42
- package/dist/internal/features/work/editors/document-wps-shortcuts.d.ts +12 -0
- package/dist/internal/features/work/editors/document-zoom.d.ts +17 -0
- package/dist/internal/features/work/editors/markdown-editor-focus.d.ts +1 -1
- package/dist/internal/features/work/editors/markdown-editor.d.ts +5 -1
- package/dist/internal/features/work/editors/markdown-toolbar.d.ts +2 -1
- package/dist/internal/features/work/editors/office-collaboration-participants.d.ts +3 -0
- package/dist/internal/features/work/editors/office-collaboration-presence-context.d.ts +17 -0
- package/dist/internal/features/work/editors/office-collaboration-presence-ui.d.ts +25 -0
- package/dist/internal/features/work/editors/office-editor-focus-handoff.d.ts +27 -0
- package/dist/internal/features/work/editors/pdf-annotation-controller.d.ts +5 -0
- package/dist/internal/features/work/editors/pdf-collaboration-presence.d.ts +3 -0
- package/dist/internal/features/work/editors/pdf-collaboration-projection.d.ts +10 -0
- package/dist/internal/features/work/editors/pdf-evidence-contract.d.ts +36 -0
- package/dist/internal/features/work/editors/pdf-evidence-overlay.d.ts +37 -0
- package/dist/internal/features/work/editors/pdf-toolbar.d.ts +2 -1
- package/dist/internal/features/work/editors/pdf-viewer-controller.d.ts +7 -1
- package/dist/internal/features/work/editors/pdf-viewer.d.ts +11 -1
- package/dist/internal/features/work/editors/presentation-collaboration-presence.d.ts +5 -0
- package/dist/internal/features/work/editors/presentation-editor-focus.d.ts +3 -2
- package/dist/internal/features/work/editors/presentation-editor-types.d.ts +3 -0
- package/dist/internal/features/work/editors/presentation-editor.d.ts +1 -1
- package/dist/internal/features/work/editors/spreadsheet-auto-filter.d.ts +9 -0
- package/dist/internal/features/work/editors/spreadsheet-cell-clear.d.ts +3 -0
- package/dist/internal/features/work/editors/spreadsheet-cell-merge.d.ts +12 -0
- package/dist/internal/features/work/editors/spreadsheet-clipboard-shortcuts.d.ts +3 -7
- package/dist/internal/features/work/editors/spreadsheet-collaboration-presence.d.ts +9 -0
- package/dist/internal/features/work/editors/spreadsheet-command-catalog.d.ts +464 -0
- package/dist/internal/features/work/editors/spreadsheet-command-controller.d.ts +45 -9
- package/dist/internal/features/work/editors/spreadsheet-context-menu.d.ts +2 -0
- package/dist/internal/features/work/editors/spreadsheet-editor-ribbon.d.ts +9 -28
- package/dist/internal/features/work/editors/spreadsheet-editor.d.ts +8 -2
- package/dist/internal/features/work/editors/spreadsheet-format-painter.d.ts +27 -0
- package/dist/internal/features/work/editors/spreadsheet-freeze-panes.d.ts +14 -0
- package/dist/internal/features/work/editors/use-document-insert-commands.d.ts +3 -2
- package/dist/internal/features/work/editors/use-document-pagination.d.ts +6 -1
- package/dist/internal/features/work/editors/use-document-review-conflicts.d.ts +28 -0
- package/dist/internal/features/work/editors/use-spreadsheet-auto-filter.d.ts +21 -0
- package/dist/internal/features/work/editors/use-spreadsheet-collaboration.d.ts +27 -0
- package/dist/internal/features/work/editors/use-spreadsheet-format-painter.d.ts +18 -0
- package/dist/internal/features/work/editors/work-office-chrome.d.ts +22 -3
- package/dist/internal/features/work/editors/work-office-ribbon-overflow.d.ts +2 -0
- package/dist/internal/features/work/work-document-bookmark-references.d.ts +37 -0
- package/dist/internal/features/work/work-document-bookmarks.d.ts +29 -0
- package/dist/internal/features/work/work-document-caption-nodes.d.ts +4 -1
- package/dist/internal/features/work/work-document-comments.d.ts +1 -1
- package/dist/internal/features/work/work-document-equations.d.ts +513 -0
- package/dist/internal/features/work/work-document-extensions.d.ts +1 -0
- package/dist/internal/features/work/work-document-field-identity.d.ts +2 -0
- package/dist/internal/features/work/work-document-field-node.d.ts +2 -2
- package/dist/internal/features/work/work-document-fields.d.ts +7 -0
- package/dist/internal/features/work/work-document-image-identity.d.ts +30 -0
- package/dist/internal/features/work/work-document-image-layout.d.ts +46 -1
- package/dist/internal/features/work/work-document-image-wrap-contour.d.ts +16 -0
- package/dist/internal/features/work/work-document-incremental-layout.d.ts +2 -2
- package/dist/internal/features/work/work-document-model-codec.d.ts +4 -1
- package/dist/internal/features/work/work-document-note-integrity.d.ts +2 -0
- package/dist/internal/features/work/work-document-page-borders.d.ts +25 -0
- package/dist/internal/features/work/work-document-page-capture.d.ts +8 -0
- package/dist/internal/features/work/work-document-page-frames.d.ts +15 -0
- package/dist/internal/features/work/work-document-page-margins.d.ts +56 -0
- package/dist/internal/features/work/work-document-page-size.d.ts +47 -0
- package/dist/internal/features/work/work-document-pagination-measurement.d.ts +1 -2
- package/dist/internal/features/work/work-document-pagination-types.d.ts +7 -2
- package/dist/internal/features/work/work-document-pagination.d.ts +2 -2
- package/dist/internal/features/work/work-document-paragraph-borders.d.ts +32 -0
- package/dist/internal/features/work/work-document-paragraph-identity.d.ts +26 -0
- package/dist/internal/features/work/work-document-paragraph-shading.d.ts +18 -0
- package/dist/internal/features/work/work-document-review-conflicts.d.ts +35 -0
- package/dist/internal/features/work/work-document-section.d.ts +4 -0
- package/dist/internal/features/work/work-document-snapshot.d.ts +19 -0
- package/dist/internal/features/work/work-document-source.d.ts +23 -0
- package/dist/internal/features/work/work-document-table-column-widths.d.ts +7 -0
- package/dist/internal/features/work/work-document-table-property-changes.d.ts +3 -0
- package/dist/internal/features/work/work-document-table-row-identity.d.ts +15 -0
- package/dist/internal/features/work/work-document-table-sizing.d.ts +3 -0
- package/dist/internal/features/work/work-document-text-layout.d.ts +3 -1
- package/dist/internal/features/work/work-document-word-line-metrics.d.ts +2 -0
- package/dist/internal/features/work/work-docx-bookmark-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-bookmark-import.d.ts +24 -0
- package/dist/internal/features/work/work-docx-bookmarks.d.ts +17 -0
- package/dist/internal/features/work/work-docx-comment-durable-id-preservation.d.ts +2 -0
- package/dist/internal/features/work/work-docx-comment-export.d.ts +3 -0
- package/dist/internal/features/work/work-docx-comment-metadata.d.ts +2 -0
- package/dist/internal/features/work/work-docx-drawing-extension-preservation.d.ts +4 -0
- package/dist/internal/features/work/work-docx-equation-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-equation-export.d.ts +14 -0
- package/dist/internal/features/work/work-docx-equation-import.d.ts +30 -0
- package/dist/internal/features/work/work-docx-equation-story.d.ts +9 -0
- package/dist/internal/features/work/work-docx-export-formatting.d.ts +3 -1
- package/dist/internal/features/work/work-docx-export-image.d.ts +5 -1
- package/dist/internal/features/work/work-docx-export.d.ts +1 -1
- package/dist/internal/features/work/work-docx-field-instructions.d.ts +8 -0
- package/dist/internal/features/work/work-docx-font-table-preservation.d.ts +3 -0
- package/dist/internal/features/work/work-docx-ignorable-extension-preservation.d.ts +15 -0
- package/dist/internal/features/work/work-docx-image-crop.d.ts +12 -0
- package/dist/internal/features/work/work-docx-image-identity.d.ts +17 -0
- package/dist/internal/features/work/work-docx-image-layer.d.ts +12 -0
- package/dist/internal/features/work/work-docx-image-layout-import.d.ts +14 -2
- package/dist/internal/features/work/work-docx-image-wrap.d.ts +15 -0
- package/dist/internal/features/work/work-docx-import.d.ts +13 -3
- package/dist/internal/features/work/work-docx-list-export.d.ts +18 -0
- package/dist/internal/features/work/work-docx-list-import.d.ts +14 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-block-preservation.d.ts +18 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-model.d.ts +47 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-preservation.d.ts +4 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-properties.d.ts +17 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-table-model.d.ts +17 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-xml.d.ts +14 -0
- package/dist/internal/features/work/work-docx-note-comment-extension-preservation.d.ts +2 -0
- package/dist/internal/features/work/work-docx-note-comment-hyperlink-content.d.ts +40 -0
- package/dist/internal/features/work/work-docx-note-comment-hyperlink-preservation.d.ts +5 -0
- package/dist/internal/features/work/work-docx-note-comment-hyperlink-relationships.d.ts +35 -0
- package/dist/internal/features/work/work-docx-note-comment-identity.d.ts +15 -0
- package/dist/internal/features/work/work-docx-note-comment-run-preservation.d.ts +4 -0
- package/dist/internal/features/work/work-docx-note-comment-run-properties.d.ts +2 -0
- package/dist/internal/features/work/work-docx-note-image-import.d.ts +12 -0
- package/dist/internal/features/work/work-docx-note-image-relationships.d.ts +1 -0
- package/dist/internal/features/work/work-docx-numbering-extension-preservation.d.ts +6 -0
- package/dist/internal/features/work/work-docx-numbering.d.ts +1 -0
- package/dist/internal/features/work/work-docx-page-borders-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-page-borders-import.d.ts +10 -0
- package/dist/internal/features/work/work-docx-page-margins-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-page-margins-import.d.ts +18 -0
- package/dist/internal/features/work/work-docx-page-size-diagnostics.d.ts +2 -0
- package/dist/internal/features/work/work-docx-page-size-import.d.ts +17 -0
- package/dist/internal/features/work/work-docx-paragraph-borders-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-paragraph-borders-export.d.ts +18 -0
- package/dist/internal/features/work/work-docx-paragraph-borders-import.d.ts +24 -0
- package/dist/internal/features/work/work-docx-paragraph-default-collapsed.d.ts +19 -0
- package/dist/internal/features/work/work-docx-paragraph-extension-preservation.d.ts +2 -0
- package/dist/internal/features/work/work-docx-paragraph-identity-import.d.ts +10 -0
- package/dist/internal/features/work/work-docx-paragraph-identity.d.ts +18 -0
- package/dist/internal/features/work/work-docx-paragraph-pagination-import.d.ts +6 -1
- package/dist/internal/features/work/work-docx-paragraph-shading-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-paragraph-shading-export.d.ts +5 -0
- package/dist/internal/features/work/work-docx-paragraph-shading-import.d.ts +18 -0
- package/dist/internal/features/work/work-docx-run-formatting-import.d.ts +3 -0
- package/dist/internal/features/work/work-docx-settings-preservation.d.ts +10 -0
- package/dist/internal/features/work/work-docx-settings-xml.d.ts +16 -0
- package/dist/internal/features/work/work-docx-style-extension-preservation.d.ts +2 -0
- package/dist/internal/features/work/work-docx-table-cell-export.d.ts +2 -1
- package/dist/internal/features/work/work-docx-table-cell-import.d.ts +3 -0
- package/dist/internal/features/work/work-docx-table-extension-preservation.d.ts +2 -0
- package/dist/internal/features/work/work-docx-table-row-import.d.ts +2 -0
- package/dist/internal/features/work/work-docx-table-sizing-import.d.ts +1 -0
- package/dist/internal/features/work/work-docx-theme-reference.d.ts +23 -0
- package/dist/internal/features/work/work-docx-theme.d.ts +4 -1
- package/dist/internal/features/work/work-docx-twips.d.ts +12 -0
- package/dist/internal/features/work/work-file-contract.d.ts +1 -0
- package/dist/internal/features/work/work-file-io.d.ts +1 -1
- package/dist/internal/features/work/work-markdown-extensions.d.ts +4 -1
- package/dist/internal/features/work/work-ooxml-package-preservation.d.ts +12 -0
- package/dist/internal/features/work/work-ooxml-package-security.d.ts +6 -0
- package/dist/internal/features/work/work-ooxml-relationship-preservation.d.ts +10 -0
- package/dist/internal/features/work/work-ooxml-xml.d.ts +2 -0
- package/dist/internal/features/work/work-pdf-export.d.ts +10 -0
- package/dist/internal/features/work/work-repository.d.ts +2 -0
- package/dist/internal/features/work/work-types.d.ts +15 -2
- package/dist/internal/kernel/office-kernel-client-types.d.ts +1 -0
- package/dist/internal/kernel/office-kernel-protocol.d.ts +7 -0
- package/dist/internal/kernel/office-kernel-version.d.ts +1 -1
- package/dist/office-kernel.wasm +0 -0
- package/dist/office-kernel.worker.js +93 -41
- package/dist/react.d.ts +18 -12
- package/dist/react.js +1 -1
- package/dist/styles.css +1367 -16
- package/dist/vue.d.ts +48 -5
- package/dist/vue.js +42 -3
- package/dist/web-component.d.ts +24 -2
- package/dist/web-component.js +101 -2
- package/docs/latest/en/browser-editor-architecture.md +262 -47
- package/package.json +29 -4
- package/dist/0~152.js +0 -94
- package/dist/0~2582.js +0 -485
- package/dist/0~4750.js +0 -939
- package/dist/0~5861.js +0 -596
- package/dist/0~work-document-extensions.js +0 -3045
- package/dist/0~work-document-model-codec.js +0 -42
- package/dist/0~work-docx-bibliography.js +0 -347
- package/dist/0~work-docx-page-color.js +0 -42
- package/dist/2881.js +0 -1455
- package/dist/8728.js +0 -723
package/dist/0~5861.js
DELETED
|
@@ -1,596 +0,0 @@
|
|
|
1
|
-
import { Extension } from "@tiptap/core";
|
|
2
|
-
import font_family from "@tiptap/extension-text-style/font-family";
|
|
3
|
-
import { TextStyle } from "@tiptap/extension-text-style";
|
|
4
|
-
const DOCUMENT_INDENT_STEP_PX = 24;
|
|
5
|
-
const MAX_DOCUMENT_INDENT_LEVEL = 8;
|
|
6
|
-
const MAX_DOCUMENT_INDENT_PX = DOCUMENT_INDENT_STEP_PX * MAX_DOCUMENT_INDENT_LEVEL;
|
|
7
|
-
const DOCUMENT_WORD_SINGLE_LINE_HEIGHT = 1.15;
|
|
8
|
-
const DocumentParagraphFormatting = Extension.create({
|
|
9
|
-
name: 'documentParagraphFormatting',
|
|
10
|
-
addGlobalAttributes () {
|
|
11
|
-
return [
|
|
12
|
-
{
|
|
13
|
-
types: [
|
|
14
|
-
'paragraph',
|
|
15
|
-
'heading'
|
|
16
|
-
],
|
|
17
|
-
attributes: {
|
|
18
|
-
lineHeight: {
|
|
19
|
-
default: null,
|
|
20
|
-
parseHTML: (element)=>normalizedLineHeight(element.style.lineHeight),
|
|
21
|
-
renderHTML: (attributes)=>{
|
|
22
|
-
const lineHeight = normalizedLineHeight(attributes.lineHeight);
|
|
23
|
-
return lineHeight ? {
|
|
24
|
-
style: `line-height: ${lineHeight}`
|
|
25
|
-
} : {};
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
lineRule: {
|
|
29
|
-
default: null,
|
|
30
|
-
parseHTML: (element)=>normalizedLineRule(element.dataset.officeLineRule),
|
|
31
|
-
renderHTML: (attributes)=>{
|
|
32
|
-
const lineRule = normalizedLineRule(attributes.lineRule);
|
|
33
|
-
return lineRule ? {
|
|
34
|
-
'data-office-line-rule': lineRule
|
|
35
|
-
} : {};
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
autoLineHeight: {
|
|
39
|
-
default: null,
|
|
40
|
-
parseHTML: (element)=>normalizedAutoLineHeight(element.dataset.officeAutoLineHeight),
|
|
41
|
-
renderHTML: (attributes)=>'auto' === normalizedLineRule(attributes.lineRule) ? renderDocumentAutoLineHeight(attributes.lineHeight, attributes.autoLineHeight) : {}
|
|
42
|
-
},
|
|
43
|
-
spaceBefore: pointSpacingAttribute('spaceBefore', 'officeSpaceBefore', 'data-office-space-before', 'margin-top'),
|
|
44
|
-
spaceAfter: pointSpacingAttribute('spaceAfter', 'officeSpaceAfter', 'data-office-space-after', 'margin-bottom'),
|
|
45
|
-
indentLevel: {
|
|
46
|
-
default: 0,
|
|
47
|
-
parseHTML: (element)=>parsedIndentLevel(element.dataset.officeIndentLevel, element.style.marginLeft),
|
|
48
|
-
renderHTML: (attributes)=>{
|
|
49
|
-
const indentLevel = normalizedIndentLevel(attributes.indentLevel);
|
|
50
|
-
return indentLevel ? {
|
|
51
|
-
'data-office-indent-level': String(indentLevel),
|
|
52
|
-
style: `margin-left: ${indentLevel * DOCUMENT_INDENT_STEP_PX}px`
|
|
53
|
-
} : {};
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
rightIndent: {
|
|
57
|
-
default: 0,
|
|
58
|
-
parseHTML: (element)=>parsedIndentPixels(element.dataset.officeIndentRight, element.style.marginRight),
|
|
59
|
-
renderHTML: (attributes)=>{
|
|
60
|
-
const rightIndent = normalizedIndentPixels(attributes.rightIndent);
|
|
61
|
-
return rightIndent ? {
|
|
62
|
-
'data-office-indent-right': formatPixelValue(rightIndent),
|
|
63
|
-
style: `margin-right: ${rightIndent}px`
|
|
64
|
-
} : {};
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
firstLineIndent: {
|
|
68
|
-
default: 0,
|
|
69
|
-
parseHTML: (element)=>{
|
|
70
|
-
const left = parsedIndentLevel(element.dataset.officeIndentLevel, element.style.marginLeft);
|
|
71
|
-
return normalizedFirstLineIndent(parsedSignedIndentPixels(element.dataset.officeIndentFirstLine, element.style.textIndent), left * DOCUMENT_INDENT_STEP_PX);
|
|
72
|
-
},
|
|
73
|
-
renderHTML: (attributes)=>{
|
|
74
|
-
const left = normalizedIndentLevel(attributes.indentLevel) * DOCUMENT_INDENT_STEP_PX;
|
|
75
|
-
const firstLineIndent = normalizedFirstLineIndent(attributes.firstLineIndent, left);
|
|
76
|
-
return firstLineIndent ? {
|
|
77
|
-
'data-office-indent-first-line': formatPixelValue(firstLineIndent),
|
|
78
|
-
style: `text-indent: ${firstLineIndent}px`
|
|
79
|
-
} : {};
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
keepLines: directBooleanAttribute('keepLines', 'officeKeepLines', 'data-office-keep-lines'),
|
|
83
|
-
keepWithNext: directBooleanAttribute('keepWithNext', 'officeKeepWithNext', 'data-office-keep-with-next'),
|
|
84
|
-
pageBreakBefore: directBooleanAttribute('pageBreakBefore', 'officePageBreakBefore', 'data-office-page-break-before'),
|
|
85
|
-
widowControl: directBooleanAttribute('widowControl', 'officeWidowControl', 'data-office-widow-control')
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
types: [
|
|
90
|
-
'paragraph',
|
|
91
|
-
'heading',
|
|
92
|
-
'listItem'
|
|
93
|
-
],
|
|
94
|
-
attributes: {
|
|
95
|
-
paragraphDirection: paragraphDirectionAttribute()
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
];
|
|
99
|
-
},
|
|
100
|
-
addCommands () {
|
|
101
|
-
return {
|
|
102
|
-
changeDocumentIndent: (direction)=>(props)=>changeDocumentIndentCommand(props, direction),
|
|
103
|
-
clearDocumentParagraphPagination: (options = {})=>(props)=>clearDocumentParagraphPaginationCommand(props, options),
|
|
104
|
-
clearDocumentFormatting: ()=>(props)=>clearDocumentFormattingCommand(props),
|
|
105
|
-
setDocumentIndentLevel: (indentLevel, options = {})=>(props)=>setDocumentIndentLevelCommand(props, indentLevel, options),
|
|
106
|
-
setDocumentLineHeight: (lineHeight)=>(props)=>setDocumentLineHeightCommand(props, lineHeight),
|
|
107
|
-
setDocumentParagraphDirection: (direction, options = {})=>(props)=>setDocumentParagraphDirectionCommand(props, direction, options),
|
|
108
|
-
setDocumentParagraphIndent: (indent, options = {})=>(props)=>setDocumentParagraphIndentCommand(props, indent, options),
|
|
109
|
-
setDocumentParagraphPagination: (pagination, options = {})=>(props)=>setDocumentParagraphPaginationCommand(props, pagination, options),
|
|
110
|
-
setDocumentParagraphSpacing: (spacing, options = {})=>(props)=>setDocumentParagraphSpacingCommand(props, spacing, options)
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
function canChangeDocumentIndent(editor, direction) {
|
|
115
|
-
if (editor.isActive('listItem')) {
|
|
116
|
-
const canChangeListLevel = direction > 0 ? editor.can().chain().focus().sinkListItem('listItem').run() : editor.can().chain().focus().liftListItem('listItem').run();
|
|
117
|
-
if (canChangeListLevel) return true;
|
|
118
|
-
}
|
|
119
|
-
const current = documentIndentLevel(editor);
|
|
120
|
-
return direction > 0 ? current < MAX_DOCUMENT_INDENT_LEVEL : current > 0;
|
|
121
|
-
}
|
|
122
|
-
function documentIndentLevel(editor) {
|
|
123
|
-
return documentParagraphIndent(editor).left / DOCUMENT_INDENT_STEP_PX;
|
|
124
|
-
}
|
|
125
|
-
function documentParagraphIndent(editor) {
|
|
126
|
-
const attributes = editor.isActive('heading') ? editor.getAttributes('heading') : editor.getAttributes('paragraph');
|
|
127
|
-
return normalizeDocumentParagraphIndent({
|
|
128
|
-
left: normalizedIndentLevel(attributes.indentLevel) * DOCUMENT_INDENT_STEP_PX,
|
|
129
|
-
right: normalizedIndentPixels(attributes.rightIndent),
|
|
130
|
-
firstLine: normalizedSignedIndentPixels(attributes.firstLineIndent)
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
function documentParagraphPagination(editor) {
|
|
134
|
-
const attributes = activeParagraphAttributes(editor);
|
|
135
|
-
return {
|
|
136
|
-
keepLines: directBoolean(attributes.keepLines) ?? false,
|
|
137
|
-
keepWithNext: directBoolean(attributes.keepWithNext) ?? editor.isActive('heading'),
|
|
138
|
-
pageBreakBefore: directBoolean(attributes.pageBreakBefore) ?? false,
|
|
139
|
-
widowControl: directBoolean(attributes.widowControl) ?? true
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
function documentParagraphDirection(editor) {
|
|
143
|
-
const attributes = editor.isActive('listItem') ? editor.getAttributes('listItem') : activeParagraphAttributes(editor);
|
|
144
|
-
return normalizeDocumentParagraphDirection(attributes.paragraphDirection) ?? 'ltr';
|
|
145
|
-
}
|
|
146
|
-
function documentParagraphSpacing(editor) {
|
|
147
|
-
const attributes = activeParagraphAttributes(editor);
|
|
148
|
-
return {
|
|
149
|
-
before: normalizedPointSpacing(attributes.spaceBefore),
|
|
150
|
-
after: normalizedPointSpacing(attributes.spaceAfter),
|
|
151
|
-
lineHeight: normalizedLineHeight(attributes.lineHeight),
|
|
152
|
-
lineRule: normalizedLineRule(attributes.lineRule)
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
function normalizeDocumentParagraphIndent(indent) {
|
|
156
|
-
const left = normalizedIndentLevel(indent.left / DOCUMENT_INDENT_STEP_PX) * DOCUMENT_INDENT_STEP_PX;
|
|
157
|
-
return {
|
|
158
|
-
left,
|
|
159
|
-
right: normalizedIndentPixels(indent.right),
|
|
160
|
-
firstLine: normalizedFirstLineIndent(indent.firstLine, left)
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
function normalizeDocumentParagraphDirection(value) {
|
|
164
|
-
if ('string' != typeof value) return null;
|
|
165
|
-
const normalized = value.trim().toLowerCase();
|
|
166
|
-
return 'ltr' === normalized || 'rtl' === normalized ? normalized : null;
|
|
167
|
-
}
|
|
168
|
-
function setDocumentLineHeightCommand({ chain }, lineHeight) {
|
|
169
|
-
const value = normalizedLineHeight(lineHeight);
|
|
170
|
-
const lineRule = value ? lineRuleForLineHeight(value) : null;
|
|
171
|
-
const attributes = {
|
|
172
|
-
lineHeight: value,
|
|
173
|
-
lineRule,
|
|
174
|
-
autoLineHeight: 'auto' === lineRule ? documentAutoLineHeight(value) : null
|
|
175
|
-
};
|
|
176
|
-
return chain().focus().updateAttributes('paragraph', attributes).updateAttributes('heading', attributes).run();
|
|
177
|
-
}
|
|
178
|
-
function changeDocumentIndentCommand(props, direction) {
|
|
179
|
-
const { can, chain, editor } = props;
|
|
180
|
-
if (editor.isActive('listItem')) {
|
|
181
|
-
const canChangeListLevel = direction > 0 ? can().chain().focus().sinkListItem('listItem').run() : can().chain().focus().liftListItem('listItem').run();
|
|
182
|
-
if (canChangeListLevel) return direction > 0 ? chain().focus().sinkListItem('listItem').run() : chain().focus().liftListItem('listItem').run();
|
|
183
|
-
}
|
|
184
|
-
const current = documentIndentLevel(editor);
|
|
185
|
-
const next = normalizedIndentLevel(current + direction);
|
|
186
|
-
if (next === current) return false;
|
|
187
|
-
return setDocumentIndentLevelCommand(props, next, {});
|
|
188
|
-
}
|
|
189
|
-
function setDocumentIndentLevelCommand(props, indentLevel, options) {
|
|
190
|
-
const current = documentParagraphIndent(props.editor);
|
|
191
|
-
return setDocumentParagraphIndentCommand(props, {
|
|
192
|
-
...current,
|
|
193
|
-
left: normalizedIndentLevel(indentLevel) * DOCUMENT_INDENT_STEP_PX
|
|
194
|
-
}, options);
|
|
195
|
-
}
|
|
196
|
-
function setDocumentParagraphIndentCommand({ chain, editor }, indent, options) {
|
|
197
|
-
const nodeTypes = activeParagraphNodeTypes(editor);
|
|
198
|
-
if (!nodeTypes.length) return false;
|
|
199
|
-
const normalized = normalizeDocumentParagraphIndent(indent);
|
|
200
|
-
const attributes = {
|
|
201
|
-
indentLevel: normalized.left / DOCUMENT_INDENT_STEP_PX,
|
|
202
|
-
rightIndent: normalized.right,
|
|
203
|
-
firstLineIndent: normalized.firstLine
|
|
204
|
-
};
|
|
205
|
-
let commandChain = chain();
|
|
206
|
-
if (false !== options.restoreFocus) commandChain = commandChain.focus();
|
|
207
|
-
for (const nodeType of nodeTypes)commandChain = commandChain.updateAttributes(nodeType, attributes);
|
|
208
|
-
return commandChain.run();
|
|
209
|
-
}
|
|
210
|
-
function setDocumentParagraphDirectionCommand({ chain, editor }, direction, options) {
|
|
211
|
-
const nodeTypes = activeParagraphDirectionNodeTypes(editor);
|
|
212
|
-
const value = normalizeDocumentParagraphDirection(direction);
|
|
213
|
-
if (!nodeTypes.length || !value) return false;
|
|
214
|
-
let commandChain = chain();
|
|
215
|
-
if (false !== options.restoreFocus) commandChain = commandChain.focus();
|
|
216
|
-
for (const nodeType of nodeTypes)commandChain = commandChain.updateAttributes(nodeType, {
|
|
217
|
-
paragraphDirection: value
|
|
218
|
-
});
|
|
219
|
-
return commandChain.run();
|
|
220
|
-
}
|
|
221
|
-
function setDocumentParagraphPaginationCommand({ chain, editor }, pagination, options) {
|
|
222
|
-
const nodeTypes = activeParagraphNodeTypes(editor);
|
|
223
|
-
if (!nodeTypes.length) return false;
|
|
224
|
-
const attributes = {};
|
|
225
|
-
for (const key of documentParagraphPaginationKeys)if (Object.hasOwn(pagination, key)) attributes[key] = Boolean(pagination[key]);
|
|
226
|
-
if (!Object.keys(attributes).length) return false;
|
|
227
|
-
let commandChain = chain();
|
|
228
|
-
if (false !== options.restoreFocus) commandChain = commandChain.focus();
|
|
229
|
-
for (const nodeType of nodeTypes)commandChain = commandChain.updateAttributes(nodeType, attributes);
|
|
230
|
-
return commandChain.run();
|
|
231
|
-
}
|
|
232
|
-
function clearDocumentParagraphPaginationCommand({ chain, editor }, options) {
|
|
233
|
-
const nodeTypes = activeParagraphNodeTypes(editor);
|
|
234
|
-
if (!nodeTypes.length) return false;
|
|
235
|
-
const attributes = {
|
|
236
|
-
keepLines: null,
|
|
237
|
-
keepWithNext: null,
|
|
238
|
-
pageBreakBefore: null,
|
|
239
|
-
widowControl: null
|
|
240
|
-
};
|
|
241
|
-
let commandChain = chain();
|
|
242
|
-
if (false !== options.restoreFocus) commandChain = commandChain.focus();
|
|
243
|
-
for (const nodeType of nodeTypes)commandChain = commandChain.updateAttributes(nodeType, attributes);
|
|
244
|
-
return commandChain.run();
|
|
245
|
-
}
|
|
246
|
-
function setDocumentParagraphSpacingCommand({ chain, editor }, spacing, options) {
|
|
247
|
-
const nodeTypes = activeParagraphNodeTypes(editor);
|
|
248
|
-
if (!nodeTypes.length) return false;
|
|
249
|
-
const lineHeight = normalizedLineHeight(spacing.lineHeight);
|
|
250
|
-
const lineRule = normalizedLineRule(spacing.lineRule) ?? (lineHeight ? lineRuleForLineHeight(lineHeight) : null);
|
|
251
|
-
const attributes = {
|
|
252
|
-
spaceBefore: normalizedPointSpacing(spacing.before),
|
|
253
|
-
spaceAfter: normalizedPointSpacing(spacing.after),
|
|
254
|
-
lineHeight,
|
|
255
|
-
lineRule,
|
|
256
|
-
autoLineHeight: 'auto' === lineRule ? documentAutoLineHeight(lineHeight) : null
|
|
257
|
-
};
|
|
258
|
-
let commandChain = chain();
|
|
259
|
-
if (false !== options.restoreFocus) commandChain = commandChain.focus();
|
|
260
|
-
for (const nodeType of nodeTypes)commandChain = commandChain.updateAttributes(nodeType, attributes);
|
|
261
|
-
return commandChain.run();
|
|
262
|
-
}
|
|
263
|
-
function clearDocumentFormattingCommand({ chain, editor }) {
|
|
264
|
-
let commandChain = chain().focus().unsetAllMarks();
|
|
265
|
-
if (!editor.isActive('listItem')) commandChain = commandChain.setParagraph();
|
|
266
|
-
return commandChain.unsetTextAlign().updateAttributes('paragraph', {
|
|
267
|
-
indentLevel: 0,
|
|
268
|
-
rightIndent: 0,
|
|
269
|
-
firstLineIndent: 0,
|
|
270
|
-
lineHeight: null,
|
|
271
|
-
lineRule: null,
|
|
272
|
-
autoLineHeight: null,
|
|
273
|
-
paragraphDirection: null,
|
|
274
|
-
spaceBefore: null,
|
|
275
|
-
spaceAfter: null,
|
|
276
|
-
keepLines: null,
|
|
277
|
-
keepWithNext: null,
|
|
278
|
-
pageBreakBefore: null,
|
|
279
|
-
widowControl: null,
|
|
280
|
-
tabStops: null
|
|
281
|
-
}).updateAttributes('listItem', {
|
|
282
|
-
paragraphDirection: null
|
|
283
|
-
}).run();
|
|
284
|
-
}
|
|
285
|
-
function parsedIndentLevel(dataValue, marginLeft) {
|
|
286
|
-
if (dataValue) return normalizedIndentLevel(dataValue);
|
|
287
|
-
const pixels = cssPixels(marginLeft);
|
|
288
|
-
return normalizedIndentLevel(pixels ? Math.round(pixels / DOCUMENT_INDENT_STEP_PX) : 0);
|
|
289
|
-
}
|
|
290
|
-
function normalizedIndentLevel(value) {
|
|
291
|
-
const number = Number(value);
|
|
292
|
-
if (!Number.isFinite(number)) return 0;
|
|
293
|
-
return Math.min(MAX_DOCUMENT_INDENT_LEVEL, Math.max(0, Math.round(4 * number) / 4));
|
|
294
|
-
}
|
|
295
|
-
function normalizedLineHeight(value) {
|
|
296
|
-
if ('string' != typeof value) return null;
|
|
297
|
-
const normalized = value.trim();
|
|
298
|
-
if (!normalized || 'normal' === normalized) return null;
|
|
299
|
-
return /^(?:\d+(?:\.\d+)?|\d+(?:\.\d+)?(?:px|pt|%))$/i.test(normalized) ? normalized : null;
|
|
300
|
-
}
|
|
301
|
-
function documentAutoLineHeight(value) {
|
|
302
|
-
const multiple = lineHeightMultiple(value);
|
|
303
|
-
if (null === multiple) return null;
|
|
304
|
-
return formatLineMetric(multiple * DOCUMENT_WORD_SINGLE_LINE_HEIGHT);
|
|
305
|
-
}
|
|
306
|
-
function documentAutoLineLeadingShift(value) {
|
|
307
|
-
const multiple = lineHeightMultiple(value);
|
|
308
|
-
if (null === multiple) return null;
|
|
309
|
-
return formatLineMetric((1 - multiple) * DOCUMENT_WORD_SINGLE_LINE_HEIGHT / 2);
|
|
310
|
-
}
|
|
311
|
-
function renderDocumentAutoLineHeight(lineHeight, autoLineHeight = documentAutoLineHeight(lineHeight)) {
|
|
312
|
-
const renderedLineHeight = normalizedAutoLineHeight(autoLineHeight) ?? documentAutoLineHeight(lineHeight);
|
|
313
|
-
if (null === renderedLineHeight) return {};
|
|
314
|
-
const multiple = lineHeightMultiple(lineHeight);
|
|
315
|
-
const shift = documentAutoLineLeadingShift(lineHeight);
|
|
316
|
-
return {
|
|
317
|
-
'data-office-auto-line-height': String(formatLineMetric(renderedLineHeight)),
|
|
318
|
-
style: [
|
|
319
|
-
`--work-document-office-auto-line-height: ${formatLineMetric(renderedLineHeight)}`,
|
|
320
|
-
...null === multiple ? [] : [
|
|
321
|
-
`--work-document-office-auto-line-multiple: ${formatLineMetric(multiple)}`
|
|
322
|
-
],
|
|
323
|
-
...null === shift ? [] : [
|
|
324
|
-
`--work-document-office-auto-line-shift: ${formatLineMetric(shift)}em`
|
|
325
|
-
]
|
|
326
|
-
].join('; ')
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
function lineHeightMultiple(value) {
|
|
330
|
-
const normalized = normalizedLineHeight(value);
|
|
331
|
-
if (!normalized) return null;
|
|
332
|
-
const percentage = /^(\d+(?:\.\d+)?)%$/.exec(normalized);
|
|
333
|
-
const multiple = percentage ? Number(percentage[1]) / 100 : /^\d+(?:\.\d+)?$/.test(normalized) ? Number(normalized) : NaN;
|
|
334
|
-
return Number.isFinite(multiple) && multiple > 0 ? multiple : null;
|
|
335
|
-
}
|
|
336
|
-
function normalizedAutoLineHeight(value) {
|
|
337
|
-
if (null == value || '' === value) return null;
|
|
338
|
-
const number = Number(value);
|
|
339
|
-
return Number.isFinite(number) && number > 0 && number <= 20 ? formatLineMetric(number) : null;
|
|
340
|
-
}
|
|
341
|
-
function formatLineMetric(value) {
|
|
342
|
-
return Number(value.toFixed(4));
|
|
343
|
-
}
|
|
344
|
-
function normalizedLineRule(value) {
|
|
345
|
-
if ('auto' === value || 'exact' === value || 'atLeast' === value) return value;
|
|
346
|
-
if ('exactly' === value) return 'exact';
|
|
347
|
-
return null;
|
|
348
|
-
}
|
|
349
|
-
function lineRuleForLineHeight(value) {
|
|
350
|
-
return /(?:px|pt)$/i.test(value) ? 'exact' : 'auto';
|
|
351
|
-
}
|
|
352
|
-
function pointSpacingAttribute(modelKey, datasetKey, htmlName, cssProperty) {
|
|
353
|
-
return {
|
|
354
|
-
default: null,
|
|
355
|
-
parseHTML: (element)=>parsedPointSpacing(element.dataset[datasetKey], 'margin-top' === cssProperty ? element.style.marginTop : element.style.marginBottom),
|
|
356
|
-
renderHTML: (attributes)=>{
|
|
357
|
-
const value = normalizedPointSpacing(attributes[modelKey]);
|
|
358
|
-
if (null === value) return {};
|
|
359
|
-
const formatted = formatPointValue(value);
|
|
360
|
-
return {
|
|
361
|
-
[htmlName]: formatted,
|
|
362
|
-
style: `${cssProperty}: ${formatted}pt`
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
function parsedPointSpacing(dataValue, cssValue) {
|
|
368
|
-
if (void 0 !== dataValue) return normalizedPointSpacing(dataValue);
|
|
369
|
-
const match = /^(-?\d+(?:\.\d+)?)(px|pt|mm|cm|in)?$/i.exec(cssValue.trim());
|
|
370
|
-
if (!match) return null;
|
|
371
|
-
const amount = Number(match[1]);
|
|
372
|
-
if (!Number.isFinite(amount)) return null;
|
|
373
|
-
const unit = match[2]?.toLowerCase() ?? 'px';
|
|
374
|
-
const points = 'pt' === unit ? amount : 'mm' === unit ? 72 * amount / 25.4 : 'cm' === unit ? 72 * amount / 2.54 : 'in' === unit ? 72 * amount : 0.75 * amount;
|
|
375
|
-
return normalizedPointSpacing(points);
|
|
376
|
-
}
|
|
377
|
-
function normalizedPointSpacing(value) {
|
|
378
|
-
if (null == value || '' === value) return null;
|
|
379
|
-
const number = Number(value);
|
|
380
|
-
if (!Number.isFinite(number)) return null;
|
|
381
|
-
return Math.min(720, Math.max(0, Math.round(4 * number) / 4));
|
|
382
|
-
}
|
|
383
|
-
function formatPointValue(value) {
|
|
384
|
-
return Number(value.toFixed(2)).toString();
|
|
385
|
-
}
|
|
386
|
-
function cssPixels(value) {
|
|
387
|
-
const match = /^(-?\d+(?:\.\d+)?)(px|pt)?$/i.exec(value.trim());
|
|
388
|
-
if (!match) return 0;
|
|
389
|
-
const amount = Number(match[1]);
|
|
390
|
-
if (!Number.isFinite(amount)) return 0;
|
|
391
|
-
return match[2]?.toLowerCase() === 'pt' ? amount / 0.75 : amount;
|
|
392
|
-
}
|
|
393
|
-
function parsedIndentPixels(dataValue, cssValue) {
|
|
394
|
-
return normalizedIndentPixels(void 0 === dataValue ? cssPixels(cssValue) : dataValue);
|
|
395
|
-
}
|
|
396
|
-
function parsedSignedIndentPixels(dataValue, cssValue) {
|
|
397
|
-
return normalizedSignedIndentPixels(void 0 === dataValue ? cssPixels(cssValue) : dataValue);
|
|
398
|
-
}
|
|
399
|
-
function normalizedIndentPixels(value) {
|
|
400
|
-
const number = Number(value);
|
|
401
|
-
if (!Number.isFinite(number)) return 0;
|
|
402
|
-
return Math.min(MAX_DOCUMENT_INDENT_PX, Math.max(0, Math.round(number)));
|
|
403
|
-
}
|
|
404
|
-
function normalizedSignedIndentPixels(value) {
|
|
405
|
-
const number = Number(value);
|
|
406
|
-
if (!Number.isFinite(number)) return 0;
|
|
407
|
-
return Math.min(MAX_DOCUMENT_INDENT_PX, Math.max(-MAX_DOCUMENT_INDENT_PX, Math.round(number)));
|
|
408
|
-
}
|
|
409
|
-
function normalizedFirstLineIndent(value, leftIndent) {
|
|
410
|
-
return Math.max(-leftIndent, Math.min(MAX_DOCUMENT_INDENT_PX, normalizedSignedIndentPixels(value)));
|
|
411
|
-
}
|
|
412
|
-
function formatPixelValue(value) {
|
|
413
|
-
return Number(value.toFixed(2)).toString();
|
|
414
|
-
}
|
|
415
|
-
function activeParagraphAttributes(editor) {
|
|
416
|
-
return editor.isActive('heading') ? editor.getAttributes('heading') : editor.getAttributes('paragraph');
|
|
417
|
-
}
|
|
418
|
-
function paragraphDirectionAttribute() {
|
|
419
|
-
return {
|
|
420
|
-
default: null,
|
|
421
|
-
parseHTML: (element)=>normalizeDocumentParagraphDirection(element.getAttribute('dir') ?? element.style.direction),
|
|
422
|
-
renderHTML: (attributes)=>{
|
|
423
|
-
const direction = normalizeDocumentParagraphDirection(attributes.paragraphDirection);
|
|
424
|
-
return direction ? {
|
|
425
|
-
dir: direction
|
|
426
|
-
} : {};
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
function directBooleanAttribute(modelKey, datasetKey, htmlName) {
|
|
431
|
-
return {
|
|
432
|
-
default: null,
|
|
433
|
-
parseHTML: (element)=>directBoolean(element.dataset[datasetKey]),
|
|
434
|
-
renderHTML: (attributes)=>{
|
|
435
|
-
const value = directBoolean(attributes[modelKey]);
|
|
436
|
-
return null === value ? {} : {
|
|
437
|
-
[htmlName]: String(value)
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
const documentParagraphPaginationKeys = [
|
|
443
|
-
'keepLines',
|
|
444
|
-
'keepWithNext',
|
|
445
|
-
'pageBreakBefore',
|
|
446
|
-
'widowControl'
|
|
447
|
-
];
|
|
448
|
-
function directBoolean(value) {
|
|
449
|
-
if (true === value || 'true' === value || '1' === value) return true;
|
|
450
|
-
if (false === value || 'false' === value || '0' === value) return false;
|
|
451
|
-
return null;
|
|
452
|
-
}
|
|
453
|
-
function activeParagraphNodeTypes(editor) {
|
|
454
|
-
const nodeTypes = new Set();
|
|
455
|
-
if (editor.isActive('paragraph')) nodeTypes.add('paragraph');
|
|
456
|
-
if (editor.isActive('heading')) nodeTypes.add('heading');
|
|
457
|
-
const { from, to } = editor.state.selection;
|
|
458
|
-
if (from !== to) editor.state.doc.nodesBetween(from, to, (node)=>{
|
|
459
|
-
if ('paragraph' === node.type.name) nodeTypes.add('paragraph');
|
|
460
|
-
if ('heading' === node.type.name) nodeTypes.add('heading');
|
|
461
|
-
});
|
|
462
|
-
return [
|
|
463
|
-
...nodeTypes
|
|
464
|
-
];
|
|
465
|
-
}
|
|
466
|
-
function activeParagraphDirectionNodeTypes(editor) {
|
|
467
|
-
const { from, to } = editor.state.selection;
|
|
468
|
-
if (from === to) return editor.isActive('listItem') ? [
|
|
469
|
-
'listItem'
|
|
470
|
-
] : activeParagraphNodeTypes(editor);
|
|
471
|
-
const nodeTypes = new Set();
|
|
472
|
-
editor.state.doc.nodesBetween(from, to, (node, _position, parent)=>{
|
|
473
|
-
if ('listItem' === node.type.name) nodeTypes.add('listItem');
|
|
474
|
-
if ('paragraph' === node.type.name && parent?.type.name !== 'listItem') nodeTypes.add('paragraph');
|
|
475
|
-
if ('heading' === node.type.name) nodeTypes.add('heading');
|
|
476
|
-
});
|
|
477
|
-
return [
|
|
478
|
-
...nodeTypes
|
|
479
|
-
];
|
|
480
|
-
}
|
|
481
|
-
const DOCUMENT_WORD_DEFAULT_SINGLE_LINE_HEIGHT = 1.15;
|
|
482
|
-
const DOCUMENT_WORD_LINE_HEIGHT_FACTORS = new Map([
|
|
483
|
-
[
|
|
484
|
-
'arial',
|
|
485
|
-
1.15
|
|
486
|
-
],
|
|
487
|
-
[
|
|
488
|
-
'times new roman',
|
|
489
|
-
1.15
|
|
490
|
-
],
|
|
491
|
-
[
|
|
492
|
-
'calibri',
|
|
493
|
-
1.2207
|
|
494
|
-
],
|
|
495
|
-
[
|
|
496
|
-
'segoe ui',
|
|
497
|
-
1.3301
|
|
498
|
-
],
|
|
499
|
-
[
|
|
500
|
-
'microsoft yahei',
|
|
501
|
-
1.7143
|
|
502
|
-
],
|
|
503
|
-
[
|
|
504
|
-
'microsoft yahei ui',
|
|
505
|
-
1.7143
|
|
506
|
-
],
|
|
507
|
-
[
|
|
508
|
-
'simsun',
|
|
509
|
-
1.2976
|
|
510
|
-
],
|
|
511
|
-
[
|
|
512
|
-
'simhei',
|
|
513
|
-
1.2976
|
|
514
|
-
],
|
|
515
|
-
[
|
|
516
|
-
'fangsong',
|
|
517
|
-
1.2976
|
|
518
|
-
],
|
|
519
|
-
[
|
|
520
|
-
'kaiti',
|
|
521
|
-
1.2976
|
|
522
|
-
],
|
|
523
|
-
[
|
|
524
|
-
'dengxian',
|
|
525
|
-
1.3548
|
|
526
|
-
]
|
|
527
|
-
]);
|
|
528
|
-
function documentWordLineHeightFactor(fontFamily) {
|
|
529
|
-
if ('string' != typeof fontFamily) return DOCUMENT_WORD_DEFAULT_SINGLE_LINE_HEIGHT;
|
|
530
|
-
const family = firstCssFontFamily(fontFamily).toLocaleLowerCase();
|
|
531
|
-
return DOCUMENT_WORD_LINE_HEIGHT_FACTORS.get(family) ?? DOCUMENT_WORD_DEFAULT_SINGLE_LINE_HEIGHT;
|
|
532
|
-
}
|
|
533
|
-
function normalizedDocumentWordLineHeightFactor(value) {
|
|
534
|
-
if (null == value || '' === value) return null;
|
|
535
|
-
const factor = Number(value);
|
|
536
|
-
if (!Number.isFinite(factor) || factor < 0.5 || factor > 4) return null;
|
|
537
|
-
return Number(factor.toFixed(4));
|
|
538
|
-
}
|
|
539
|
-
const DocumentTextStyle = TextStyle.extend({
|
|
540
|
-
addAttributes () {
|
|
541
|
-
return {
|
|
542
|
-
wordLineHeightFactor: {
|
|
543
|
-
default: null,
|
|
544
|
-
parseHTML: (element)=>normalizedDocumentWordLineHeightFactor(element.dataset.officeWordLineHeightFactor ?? element.style.getPropertyValue('--work-document-word-line-height-factor')),
|
|
545
|
-
renderHTML: (attributes)=>{
|
|
546
|
-
const factor = normalizedDocumentWordLineHeightFactor(attributes.wordLineHeightFactor);
|
|
547
|
-
if (null === factor) return {};
|
|
548
|
-
return {
|
|
549
|
-
'data-office-word-line-height-factor': String(factor),
|
|
550
|
-
style: `--work-document-word-line-height-factor: ${factor}`
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
},
|
|
554
|
-
wordSnapToGrid: {
|
|
555
|
-
default: null,
|
|
556
|
-
parseHTML: (element)=>normalizedBoolean(element.dataset.officeWordSnapToGrid),
|
|
557
|
-
renderHTML: (attributes)=>{
|
|
558
|
-
const value = normalizedBoolean(attributes.wordSnapToGrid);
|
|
559
|
-
return null === value ? {} : {
|
|
560
|
-
'data-office-word-snap-to-grid': String(value)
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
const DocumentFontFamily = font_family.extend({
|
|
568
|
-
addCommands () {
|
|
569
|
-
return {
|
|
570
|
-
setFontFamily: (fontFamily)=>({ chain })=>chain().setMark('textStyle', {
|
|
571
|
-
fontFamily,
|
|
572
|
-
wordLineHeightFactor: documentWordLineHeightFactor(fontFamily)
|
|
573
|
-
}).run(),
|
|
574
|
-
unsetFontFamily: ()=>({ chain })=>chain().setMark('textStyle', {
|
|
575
|
-
fontFamily: null,
|
|
576
|
-
wordLineHeightFactor: null
|
|
577
|
-
}).removeEmptyTextStyle().run()
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
function firstCssFontFamily(value) {
|
|
582
|
-
const source = value.trim();
|
|
583
|
-
if (!source) return '';
|
|
584
|
-
const quote = source[0];
|
|
585
|
-
if ('"' === quote || "'" === quote) {
|
|
586
|
-
const end = source.indexOf(quote, 1);
|
|
587
|
-
if (end > 0) return source.slice(1, end).trim();
|
|
588
|
-
}
|
|
589
|
-
return (source.split(',')[0] ?? source).trim().replace(/^(['"])(.*)\1$/, '$2');
|
|
590
|
-
}
|
|
591
|
-
function normalizedBoolean(value) {
|
|
592
|
-
if (true === value || 'true' === value || '1' === value) return true;
|
|
593
|
-
if (false === value || 'false' === value || '0' === value) return false;
|
|
594
|
-
return null;
|
|
595
|
-
}
|
|
596
|
-
export { DocumentFontFamily, DocumentParagraphFormatting, DocumentTextStyle, canChangeDocumentIndent, documentAutoLineHeight, documentParagraphDirection, documentParagraphIndent, documentParagraphPagination, documentParagraphSpacing, documentWordLineHeightFactor, normalizeDocumentParagraphIndent, renderDocumentAutoLineHeight };
|