editor-svg 1.0.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/.editorconfig +9 -0
- package/.eslintrc +46 -0
- package/.prettierrc +8 -0
- package/AGENTS.md +186 -0
- package/CHANGELOG.md +2543 -0
- package/CLAUDE.md +110 -0
- package/LICENSE +21 -0
- package/README.md +110 -0
- package/cypress/e2e/control/checkbox.cy.ts +46 -0
- package/cypress/e2e/control/select.cy.ts +56 -0
- package/cypress/e2e/control/text.cy.ts +43 -0
- package/cypress/e2e/editor.cy.ts +67 -0
- package/cypress/e2e/menus/block.cy.ts +38 -0
- package/cypress/e2e/menus/checkbox.cy.ts +33 -0
- package/cypress/e2e/menus/codeblock.cy.ts +34 -0
- package/cypress/e2e/menus/date.cy.ts +28 -0
- package/cypress/e2e/menus/format.cy.ts +40 -0
- package/cypress/e2e/menus/hyperlink.cy.ts +39 -0
- package/cypress/e2e/menus/image.cy.ts +25 -0
- package/cypress/e2e/menus/latex.cy.ts +34 -0
- package/cypress/e2e/menus/pagebreak.cy.ts +21 -0
- package/cypress/e2e/menus/painter.cy.ts +53 -0
- package/cypress/e2e/menus/print.cy.ts +25 -0
- package/cypress/e2e/menus/row.cy.ts +103 -0
- package/cypress/e2e/menus/search.cy.ts +112 -0
- package/cypress/e2e/menus/separator.cy.ts +32 -0
- package/cypress/e2e/menus/table.cy.ts +25 -0
- package/cypress/e2e/menus/text.cy.ts +304 -0
- package/cypress/e2e/menus/title.cy.ts +43 -0
- package/cypress/e2e/menus/undoRedo.cy.ts +49 -0
- package/cypress/e2e/menus/watermark.cy.ts +64 -0
- package/cypress/fixtures/example.json +3 -0
- package/cypress/fixtures/test.png +0 -0
- package/cypress/global.d.ts +13 -0
- package/cypress/support/commands.ts +5 -0
- package/cypress/support/e2e.ts +1 -0
- package/cypress/tsconfig.json +21 -0
- package/cypress.config.ts +10 -0
- package/docs/.vitepress/config.ts +191 -0
- package/docs/.vitepress/theme/components/DeepWikiBadge.vue +21 -0
- package/docs/.vitepress/theme/components/ZreadBadge.vue +21 -0
- package/docs/.vitepress/theme/index.ts +27 -0
- package/docs/en/guide/api-common.md +49 -0
- package/docs/en/guide/api-instance.md +34 -0
- package/docs/en/guide/command-execute.md +1167 -0
- package/docs/en/guide/command-get.md +355 -0
- package/docs/en/guide/contextmenu-custom.md +44 -0
- package/docs/en/guide/contextmenu-internal.md +61 -0
- package/docs/en/guide/eventbus.md +260 -0
- package/docs/en/guide/i18n.md +112 -0
- package/docs/en/guide/listener.md +126 -0
- package/docs/en/guide/option.md +214 -0
- package/docs/en/guide/override.md +57 -0
- package/docs/en/guide/plugin-custom.md +25 -0
- package/docs/en/guide/plugin-internal.md +125 -0
- package/docs/en/guide/schema.md +237 -0
- package/docs/en/guide/shortcut-custom.md +22 -0
- package/docs/en/guide/shortcut-internal.md +189 -0
- package/docs/en/guide/start.md +97 -0
- package/docs/en/index.md +43 -0
- package/docs/guide/api-common.md +49 -0
- package/docs/guide/api-instance.md +34 -0
- package/docs/guide/command-execute.md +1157 -0
- package/docs/guide/command-get.md +353 -0
- package/docs/guide/contextmenu-custom.md +44 -0
- package/docs/guide/contextmenu-internal.md +61 -0
- package/docs/guide/eventbus.md +260 -0
- package/docs/guide/i18n.md +111 -0
- package/docs/guide/listener.md +126 -0
- package/docs/guide/option.md +214 -0
- package/docs/guide/override.md +57 -0
- package/docs/guide/plugin-custom.md +25 -0
- package/docs/guide/plugin-internal.md +125 -0
- package/docs/guide/schema.md +237 -0
- package/docs/guide/shortcut-custom.md +22 -0
- package/docs/guide/shortcut-internal.md +189 -0
- package/docs/guide/start.md +97 -0
- package/docs/index.md +43 -0
- package/docs/public/favicon.png +0 -0
- package/favicon.png +0 -0
- package/index.html +435 -0
- package/package.json +55 -0
- package/pnpm-lock.yaml +4113 -0
- package/scripts/release.js +41 -0
- package/scripts/verifyCommit.js +19 -0
- package/src/assets/images/alignment.svg +1 -0
- package/src/assets/images/arrow-left.svg +1 -0
- package/src/assets/images/arrow-right.svg +1 -0
- package/src/assets/images/block.svg +1 -0
- package/src/assets/images/bold.svg +1 -0
- package/src/assets/images/catalog.svg +1 -0
- package/src/assets/images/center.svg +1 -0
- package/src/assets/images/checkbox.svg +1 -0
- package/src/assets/images/close.svg +1 -0
- package/src/assets/images/codeblock.svg +1 -0
- package/src/assets/images/color.svg +1 -0
- package/src/assets/images/control.svg +1 -0
- package/src/assets/images/date.svg +1 -0
- package/src/assets/images/exit-fullscreen.svg +1 -0
- package/src/assets/images/format.svg +1 -0
- package/src/assets/images/highlight.svg +1 -0
- package/src/assets/images/hyperlink.svg +1 -0
- package/src/assets/images/image.svg +1 -0
- package/src/assets/images/italic.svg +1 -0
- package/src/assets/images/justify.svg +7 -0
- package/src/assets/images/latex.svg +1 -0
- package/src/assets/images/left.svg +1 -0
- package/src/assets/images/line-dash-dot-dot.svg +1 -0
- package/src/assets/images/line-dash-dot.svg +1 -0
- package/src/assets/images/line-dash-large-gap.svg +1 -0
- package/src/assets/images/line-dash-small-gap.svg +1 -0
- package/src/assets/images/line-dot.svg +1 -0
- package/src/assets/images/line-double.svg +1 -0
- package/src/assets/images/line-single.svg +1 -0
- package/src/assets/images/line-wavy.svg +1 -0
- package/src/assets/images/list.svg +1 -0
- package/src/assets/images/option.svg +1 -0
- package/src/assets/images/page-break.svg +1 -0
- package/src/assets/images/page-mode.svg +1 -0
- package/src/assets/images/page-scale-add.svg +1 -0
- package/src/assets/images/page-scale-minus.svg +1 -0
- package/src/assets/images/painter.svg +1 -0
- package/src/assets/images/paper-direction.svg +1 -0
- package/src/assets/images/paper-margin.svg +1 -0
- package/src/assets/images/paper-size.svg +1 -0
- package/src/assets/images/print.svg +1 -0
- package/src/assets/images/radio.svg +4 -0
- package/src/assets/images/redo.svg +1 -0
- package/src/assets/images/request-fullscreen.svg +1 -0
- package/src/assets/images/right.svg +1 -0
- package/src/assets/images/row-margin.svg +1 -0
- package/src/assets/images/search.svg +1 -0
- package/src/assets/images/separator.svg +1 -0
- package/src/assets/images/signature-undo.svg +1 -0
- package/src/assets/images/signature.svg +1 -0
- package/src/assets/images/size-add.svg +1 -0
- package/src/assets/images/size-minus.svg +1 -0
- package/src/assets/images/strikeout.svg +1 -0
- package/src/assets/images/subscript.svg +1 -0
- package/src/assets/images/superscript.svg +1 -0
- package/src/assets/images/table.svg +1 -0
- package/src/assets/images/title.svg +1 -0
- package/src/assets/images/trash.svg +1 -0
- package/src/assets/images/underline.svg +1 -0
- package/src/assets/images/undo.svg +1 -0
- package/src/assets/images/watermark.svg +1 -0
- package/src/assets/images/word-tool.svg +1 -0
- package/src/assets/snapshots/main_v0.2.1.png +0 -0
- package/src/assets/snapshots/main_v0.2.2.png +0 -0
- package/src/assets/snapshots/main_v0.3.0.png +0 -0
- package/src/assets/snapshots/main_v0.3.1.png +0 -0
- package/src/assets/snapshots/main_v0.5.0.png +0 -0
- package/src/assets/snapshots/main_v0.5.1.png +0 -0
- package/src/assets/snapshots/main_v0.6.0.png +0 -0
- package/src/assets/snapshots/main_v0.6.1.png +0 -0
- package/src/assets/snapshots/main_v0.7.0.png +0 -0
- package/src/assets/snapshots/main_v0.7.1.png +0 -0
- package/src/assets/snapshots/main_v0.7.2.png +0 -0
- package/src/assets/snapshots/main_v0.7.3.png +0 -0
- package/src/assets/snapshots/main_v0.7.4.png +0 -0
- package/src/assets/snapshots/main_v0.7.6.png +0 -0
- package/src/assets/snapshots/main_v0.7.7.png +0 -0
- package/src/assets/snapshots/main_v0.8.0.png +0 -0
- package/src/assets/snapshots/main_v0.8.5.png +0 -0
- package/src/assets/snapshots/main_v0.8.6.png +0 -0
- package/src/assets/snapshots/main_v0.8.7.png +0 -0
- package/src/assets/snapshots/main_v0.8.8.png +0 -0
- package/src/assets/snapshots/main_v0.9.0.png +0 -0
- package/src/assets/snapshots/main_v0.9.1.png +0 -0
- package/src/assets/snapshots/main_v0.9.2.png +0 -0
- package/src/assets/snapshots/main_v0.9.23.png +0 -0
- package/src/assets/snapshots/main_v0.9.28.png +0 -0
- package/src/assets/snapshots/main_v0.9.29.png +0 -0
- package/src/assets/snapshots/main_v0.9.3.png +0 -0
- package/src/assets/snapshots/main_v0.9.30.png +0 -0
- package/src/assets/snapshots/main_v0.9.32.png +0 -0
- package/src/assets/snapshots/main_v0.9.35.png +0 -0
- package/src/assets/snapshots/main_v0.9.4.png +0 -0
- package/src/assets/snapshots/main_v0.9.5.png +0 -0
- package/src/assets/snapshots/main_v0.9.6.png +0 -0
- package/src/assets/snapshots/main_v0.9.8.png +0 -0
- package/src/components/dialog/Dialog.ts +171 -0
- package/src/components/dialog/dialog.css +131 -0
- package/src/components/signature/Signature.ts +340 -0
- package/src/components/signature/signature.css +132 -0
- package/src/editor/assets/css/block/block.css +21 -0
- package/src/editor/assets/css/contextmenu/contextmenu.css +196 -0
- package/src/editor/assets/css/control/calculator.css +85 -0
- package/src/editor/assets/css/control/select.css +44 -0
- package/src/editor/assets/css/date/datePicker.css +233 -0
- package/src/editor/assets/css/hyperlink/hyperlink.css +26 -0
- package/src/editor/assets/css/index.css +78 -0
- package/src/editor/assets/css/previewer/previewer.css +122 -0
- package/src/editor/assets/css/resizer/resizer.css +74 -0
- package/src/editor/assets/css/table/table.css +155 -0
- package/src/editor/assets/css/zone/zone.css +61 -0
- package/src/editor/assets/images/close.svg +1 -0
- package/src/editor/assets/images/delete-col.svg +1 -0
- package/src/editor/assets/images/delete-row-col.svg +1 -0
- package/src/editor/assets/images/delete-row.svg +1 -0
- package/src/editor/assets/images/delete-table.svg +1 -0
- package/src/editor/assets/images/image-change.svg +1 -0
- package/src/editor/assets/images/image-download.svg +1 -0
- package/src/editor/assets/images/image-next.svg +1 -0
- package/src/editor/assets/images/image-pre.svg +1 -0
- package/src/editor/assets/images/image.svg +1 -0
- package/src/editor/assets/images/insert-bottom-row.svg +1 -0
- package/src/editor/assets/images/insert-left-col.svg +1 -0
- package/src/editor/assets/images/insert-right-col.svg +1 -0
- package/src/editor/assets/images/insert-row-col.svg +1 -0
- package/src/editor/assets/images/insert-top-row.svg +1 -0
- package/src/editor/assets/images/merge-cancel-cell.svg +1 -0
- package/src/editor/assets/images/merge-cell.svg +1 -0
- package/src/editor/assets/images/original-size.svg +1 -0
- package/src/editor/assets/images/print.svg +1 -0
- package/src/editor/assets/images/rotate.svg +1 -0
- package/src/editor/assets/images/submenu-dropdown.svg +1 -0
- package/src/editor/assets/images/table-border-all.svg +1 -0
- package/src/editor/assets/images/table-border-dash.svg +1 -0
- package/src/editor/assets/images/table-border-empty.svg +1 -0
- package/src/editor/assets/images/table-border-external.svg +1 -0
- package/src/editor/assets/images/table-border-internal.svg +1 -0
- package/src/editor/assets/images/table-border-td-back.svg +1 -0
- package/src/editor/assets/images/table-border-td-bottom.svg +1 -0
- package/src/editor/assets/images/table-border-td-forward.svg +1 -0
- package/src/editor/assets/images/table-border-td-left.svg +1 -0
- package/src/editor/assets/images/table-border-td-right.svg +1 -0
- package/src/editor/assets/images/table-border-td-top.svg +1 -0
- package/src/editor/assets/images/table-border-td.svg +1 -0
- package/src/editor/assets/images/vertical-align-bottom.svg +1 -0
- package/src/editor/assets/images/vertical-align-middle.svg +1 -0
- package/src/editor/assets/images/vertical-align-top.svg +1 -0
- package/src/editor/assets/images/vertical-align.svg +1 -0
- package/src/editor/assets/images/zoom-in.svg +1 -0
- package/src/editor/assets/images/zoom-out.svg +1 -0
- package/src/editor/core/actuator/Actuator.ts +21 -0
- package/src/editor/core/actuator/handlers/positionContextChange.ts +13 -0
- package/src/editor/core/command/Command.ts +312 -0
- package/src/editor/core/command/CommandAdapt.ts +2733 -0
- package/src/editor/core/contextmenu/ContextMenu.ts +363 -0
- package/src/editor/core/contextmenu/menus/controlMenus.ts +25 -0
- package/src/editor/core/contextmenu/menus/globalMenus.ts +66 -0
- package/src/editor/core/contextmenu/menus/hyperlinkMenus.ts +58 -0
- package/src/editor/core/contextmenu/menus/imageMenus.ts +134 -0
- package/src/editor/core/contextmenu/menus/tableMenus.ts +331 -0
- package/src/editor/core/cursor/Cursor.ts +248 -0
- package/src/editor/core/cursor/CursorAgent.ts +75 -0
- package/src/editor/core/draw/Draw.ts +2934 -0
- package/src/editor/core/draw/control/Control.ts +1767 -0
- package/src/editor/core/draw/control/checkbox/CheckboxControl.ts +154 -0
- package/src/editor/core/draw/control/date/DateControl.ts +363 -0
- package/src/editor/core/draw/control/interactive/ControlSearch.ts +214 -0
- package/src/editor/core/draw/control/number/Calculator.ts +183 -0
- package/src/editor/core/draw/control/number/NumberControl.ts +183 -0
- package/src/editor/core/draw/control/radio/RadioControl.ts +68 -0
- package/src/editor/core/draw/control/richtext/Border.ts +52 -0
- package/src/editor/core/draw/control/select/SelectControl.ts +567 -0
- package/src/editor/core/draw/control/text/TextControl.ts +280 -0
- package/src/editor/core/draw/frame/Background.ts +117 -0
- package/src/editor/core/draw/frame/Badge.ts +88 -0
- package/src/editor/core/draw/frame/Footer.ts +155 -0
- package/src/editor/core/draw/frame/Header.ts +158 -0
- package/src/editor/core/draw/frame/LineNumber.ts +43 -0
- package/src/editor/core/draw/frame/Margin.ts +53 -0
- package/src/editor/core/draw/frame/PageBorder.ts +47 -0
- package/src/editor/core/draw/frame/PageNumber.ts +88 -0
- package/src/editor/core/draw/frame/Placeholder.ts +114 -0
- package/src/editor/core/draw/frame/Watermark.ts +188 -0
- package/src/editor/core/draw/graffiti/Graffiti.ts +125 -0
- package/src/editor/core/draw/interactive/Area.ts +312 -0
- package/src/editor/core/draw/interactive/Group.ts +198 -0
- package/src/editor/core/draw/interactive/Search.ts +527 -0
- package/src/editor/core/draw/particle/CheckboxParticle.ts +111 -0
- package/src/editor/core/draw/particle/HyperlinkParticle.ts +86 -0
- package/src/editor/core/draw/particle/ImageParticle.ts +280 -0
- package/src/editor/core/draw/particle/LabelParticle.ts +79 -0
- package/src/editor/core/draw/particle/LineBreakParticle.ts +55 -0
- package/src/editor/core/draw/particle/ListParticle.ts +255 -0
- package/src/editor/core/draw/particle/PageBreakParticle.ts +54 -0
- package/src/editor/core/draw/particle/RadioParticle.ts +99 -0
- package/src/editor/core/draw/particle/SeparatorParticle.ts +37 -0
- package/src/editor/core/draw/particle/SubscriptParticle.ts +23 -0
- package/src/editor/core/draw/particle/SuperscriptParticle.ts +23 -0
- package/src/editor/core/draw/particle/TextParticle.ts +174 -0
- package/src/editor/core/draw/particle/WhiteSpaceParticle.ts +32 -0
- package/src/editor/core/draw/particle/block/BlockParticle.ts +76 -0
- package/src/editor/core/draw/particle/block/modules/BaseBlock.ts +280 -0
- package/src/editor/core/draw/particle/block/modules/IFrameBlock.ts +47 -0
- package/src/editor/core/draw/particle/block/modules/VideoBlock.ts +61 -0
- package/src/editor/core/draw/particle/date/DateParticle.ts +111 -0
- package/src/editor/core/draw/particle/date/DatePicker.ts +577 -0
- package/src/editor/core/draw/particle/latex/LaTexParticle.ts +43 -0
- package/src/editor/core/draw/particle/latex/utils/LaTexUtils.ts +1196 -0
- package/src/editor/core/draw/particle/latex/utils/hershey.ts +1632 -0
- package/src/editor/core/draw/particle/latex/utils/symbols.ts +318 -0
- package/src/editor/core/draw/particle/previewer/Previewer.ts +582 -0
- package/src/editor/core/draw/particle/table/TableOperate.ts +988 -0
- package/src/editor/core/draw/particle/table/TableParticle.ts +558 -0
- package/src/editor/core/draw/particle/table/TableTool.ts +551 -0
- package/src/editor/core/draw/richtext/AbstractRichText.ts +59 -0
- package/src/editor/core/draw/richtext/Highlight.ts +24 -0
- package/src/editor/core/draw/richtext/Strikeout.ts +28 -0
- package/src/editor/core/draw/richtext/Underline.ts +106 -0
- package/src/editor/core/event/CanvasEvent.ts +215 -0
- package/src/editor/core/event/GlobalEvent.ts +173 -0
- package/src/editor/core/event/eventbus/EventBus.ts +50 -0
- package/src/editor/core/event/handlers/click.ts +234 -0
- package/src/editor/core/event/handlers/composition.ts +45 -0
- package/src/editor/core/event/handlers/copy.ts +72 -0
- package/src/editor/core/event/handlers/cut.ts +47 -0
- package/src/editor/core/event/handlers/drag.ts +66 -0
- package/src/editor/core/event/handlers/drop.ts +28 -0
- package/src/editor/core/event/handlers/input.ts +129 -0
- package/src/editor/core/event/handlers/keydown/backspace.ts +161 -0
- package/src/editor/core/event/handlers/keydown/delete.ts +119 -0
- package/src/editor/core/event/handlers/keydown/end.ts +69 -0
- package/src/editor/core/event/handlers/keydown/enter.ts +126 -0
- package/src/editor/core/event/handlers/keydown/home.ts +69 -0
- package/src/editor/core/event/handlers/keydown/index.ts +85 -0
- package/src/editor/core/event/handlers/keydown/left.ts +162 -0
- package/src/editor/core/event/handlers/keydown/right.ts +178 -0
- package/src/editor/core/event/handlers/keydown/tab.ts +41 -0
- package/src/editor/core/event/handlers/keydown/updown.ts +342 -0
- package/src/editor/core/event/handlers/mousedown.ts +262 -0
- package/src/editor/core/event/handlers/mouseleave.ts +14 -0
- package/src/editor/core/event/handlers/mousemove.ts +133 -0
- package/src/editor/core/event/handlers/mouseup.ts +341 -0
- package/src/editor/core/event/handlers/paste.ts +231 -0
- package/src/editor/core/history/HistoryManager.ts +61 -0
- package/src/editor/core/i18n/I18n.ts +51 -0
- package/src/editor/core/i18n/lang/en.json +92 -0
- package/src/editor/core/i18n/lang/zh-CN.json +92 -0
- package/src/editor/core/listener/Listener.ts +41 -0
- package/src/editor/core/observer/ImageObserver.ts +19 -0
- package/src/editor/core/observer/MouseObserver.ts +56 -0
- package/src/editor/core/observer/ScrollObserver.ts +88 -0
- package/src/editor/core/observer/SelectionObserver.ts +143 -0
- package/src/editor/core/override/Override.ts +14 -0
- package/src/editor/core/plugin/Plugin.ts +17 -0
- package/src/editor/core/position/Position.ts +870 -0
- package/src/editor/core/range/RangeManager.ts +723 -0
- package/src/editor/core/register/Register.ts +28 -0
- package/src/editor/core/shortcut/Shortcut.ts +80 -0
- package/src/editor/core/shortcut/keys/listKeys.ts +22 -0
- package/src/editor/core/shortcut/keys/richtextKeys.ts +102 -0
- package/src/editor/core/shortcut/keys/titleKeys.ts +62 -0
- package/src/editor/core/worker/WorkerManager.ts +96 -0
- package/src/editor/core/worker/works/catalog.ts +189 -0
- package/src/editor/core/worker/works/group.ts +34 -0
- package/src/editor/core/worker/works/value.ts +32 -0
- package/src/editor/core/worker/works/wordCount.ts +132 -0
- package/src/editor/core/zone/Zone.ts +183 -0
- package/src/editor/core/zone/ZoneTip.ts +108 -0
- package/src/editor/dataset/constant/Background.ts +10 -0
- package/src/editor/dataset/constant/Badge.ts +6 -0
- package/src/editor/dataset/constant/Checkbox.ts +12 -0
- package/src/editor/dataset/constant/Common.ts +44 -0
- package/src/editor/dataset/constant/ContextMenu.ts +61 -0
- package/src/editor/dataset/constant/Control.ts +14 -0
- package/src/editor/dataset/constant/Cursor.ts +11 -0
- package/src/editor/dataset/constant/Editor.ts +19 -0
- package/src/editor/dataset/constant/Element.ts +173 -0
- package/src/editor/dataset/constant/Footer.ts +10 -0
- package/src/editor/dataset/constant/Graffiti.ts +6 -0
- package/src/editor/dataset/constant/Group.ts +10 -0
- package/src/editor/dataset/constant/Header.ts +10 -0
- package/src/editor/dataset/constant/ImgCaption.ts +8 -0
- package/src/editor/dataset/constant/Label.ts +8 -0
- package/src/editor/dataset/constant/LineBreak.ts +7 -0
- package/src/editor/dataset/constant/LineNumber.ts +11 -0
- package/src/editor/dataset/constant/List.ts +26 -0
- package/src/editor/dataset/constant/PageBorder.ts +8 -0
- package/src/editor/dataset/constant/PageBreak.ts +7 -0
- package/src/editor/dataset/constant/PageNumber.ts +22 -0
- package/src/editor/dataset/constant/Placeholder.ts +9 -0
- package/src/editor/dataset/constant/Radio.ts +12 -0
- package/src/editor/dataset/constant/Regular.ts +23 -0
- package/src/editor/dataset/constant/Separator.ts +6 -0
- package/src/editor/dataset/constant/Shortcut.ts +3 -0
- package/src/editor/dataset/constant/Table.ts +9 -0
- package/src/editor/dataset/constant/Title.ts +38 -0
- package/src/editor/dataset/constant/Watermark.ts +17 -0
- package/src/editor/dataset/constant/WhiteSpace.ts +7 -0
- package/src/editor/dataset/constant/Zone.ts +5 -0
- package/src/editor/dataset/enum/Area.ts +5 -0
- package/src/editor/dataset/enum/Background.ts +11 -0
- package/src/editor/dataset/enum/Block.ts +4 -0
- package/src/editor/dataset/enum/Common.ts +30 -0
- package/src/editor/dataset/enum/Control.ts +39 -0
- package/src/editor/dataset/enum/Editor.ts +51 -0
- package/src/editor/dataset/enum/Element.ts +21 -0
- package/src/editor/dataset/enum/ElementStyle.ts +12 -0
- package/src/editor/dataset/enum/Event.ts +5 -0
- package/src/editor/dataset/enum/KeyMap.ts +85 -0
- package/src/editor/dataset/enum/LineNumber.ts +4 -0
- package/src/editor/dataset/enum/List.ts +23 -0
- package/src/editor/dataset/enum/Observer.ts +6 -0
- package/src/editor/dataset/enum/Row.ts +7 -0
- package/src/editor/dataset/enum/Text.ts +13 -0
- package/src/editor/dataset/enum/Title.ts +8 -0
- package/src/editor/dataset/enum/VerticalAlign.ts +5 -0
- package/src/editor/dataset/enum/Watermark.ts +4 -0
- package/src/editor/dataset/enum/table/Table.ts +19 -0
- package/src/editor/dataset/enum/table/TableTool.ts +4 -0
- package/src/editor/index.ts +241 -0
- package/src/editor/interface/Area.ts +68 -0
- package/src/editor/interface/Background.ts +9 -0
- package/src/editor/interface/Badge.ts +17 -0
- package/src/editor/interface/Block.ts +18 -0
- package/src/editor/interface/Catalog.ts +11 -0
- package/src/editor/interface/Checkbox.ts +17 -0
- package/src/editor/interface/Command.ts +3 -0
- package/src/editor/interface/Common.ts +43 -0
- package/src/editor/interface/Control.ts +250 -0
- package/src/editor/interface/Cursor.ts +7 -0
- package/src/editor/interface/Draw.ts +86 -0
- package/src/editor/interface/Editor.ts +172 -0
- package/src/editor/interface/Element.ts +273 -0
- package/src/editor/interface/Event.ts +27 -0
- package/src/editor/interface/EventBus.ts +46 -0
- package/src/editor/interface/Footer.ts +9 -0
- package/src/editor/interface/Graffiti.ts +15 -0
- package/src/editor/interface/Group.ts +8 -0
- package/src/editor/interface/Header.ts +9 -0
- package/src/editor/interface/Label.ts +8 -0
- package/src/editor/interface/LineBreak.ts +5 -0
- package/src/editor/interface/LineNumber.ts +10 -0
- package/src/editor/interface/Listener.ts +88 -0
- package/src/editor/interface/Margin.ts +1 -0
- package/src/editor/interface/PageBorder.ts +8 -0
- package/src/editor/interface/PageBreak.ts +5 -0
- package/src/editor/interface/PageNumber.ts +16 -0
- package/src/editor/interface/Placeholder.ts +7 -0
- package/src/editor/interface/Plugin.ts +8 -0
- package/src/editor/interface/Position.ts +113 -0
- package/src/editor/interface/Previewer.ts +15 -0
- package/src/editor/interface/Radio.ts +17 -0
- package/src/editor/interface/Range.ts +61 -0
- package/src/editor/interface/Row.ts +25 -0
- package/src/editor/interface/Search.ts +36 -0
- package/src/editor/interface/Separator.ts +4 -0
- package/src/editor/interface/Text.ts +15 -0
- package/src/editor/interface/Title.ts +32 -0
- package/src/editor/interface/Watermark.ts +16 -0
- package/src/editor/interface/WhiteSpace.ts +5 -0
- package/src/editor/interface/Zone.ts +3 -0
- package/src/editor/interface/contextmenu/ContextMenu.ts +76 -0
- package/src/editor/interface/i18n/I18n.ts +7 -0
- package/src/editor/interface/shortcut/Shortcut.ts +14 -0
- package/src/editor/interface/table/Colgroup.ts +4 -0
- package/src/editor/interface/table/Table.ts +9 -0
- package/src/editor/interface/table/Td.ts +36 -0
- package/src/editor/interface/table/Tr.ts +11 -0
- package/src/editor/types/index.d.ts +5 -0
- package/src/editor/utils/clipboard.ts +94 -0
- package/src/editor/utils/element.ts +1877 -0
- package/src/editor/utils/hotkey.ts +5 -0
- package/src/editor/utils/index.ts +445 -0
- package/src/editor/utils/option.ts +253 -0
- package/src/editor/utils/paragraph.ts +28 -0
- package/src/editor/utils/print.ts +99 -0
- package/src/editor/utils/ua.ts +13 -0
- package/src/main.ts +2053 -0
- package/src/mock.ts +611 -0
- package/src/plugins/copy/index.ts +30 -0
- package/src/plugins/markdown/index.ts +118 -0
- package/src/style.css +1079 -0
- package/src/utils/index.ts +45 -0
- package/src/utils/prism.ts +89 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +25 -0
- package/vite.config.ts +46 -0
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
import { IElement } from '../../../..'
|
|
2
|
+
import { EDITOR_PREFIX } from '../../../../dataset/constant/Editor'
|
|
3
|
+
import { TableOrder } from '../../../../dataset/enum/table/TableTool'
|
|
4
|
+
import { DeepRequired } from '../../../../interface/Common'
|
|
5
|
+
import { IEditorOption } from '../../../../interface/Editor'
|
|
6
|
+
import { Position } from '../../../position/Position'
|
|
7
|
+
import { RangeManager } from '../../../range/RangeManager'
|
|
8
|
+
import { Draw } from '../../Draw'
|
|
9
|
+
|
|
10
|
+
interface IAnchorMouseDown {
|
|
11
|
+
evt: MouseEvent
|
|
12
|
+
order: TableOrder
|
|
13
|
+
index: number
|
|
14
|
+
element: IElement
|
|
15
|
+
isLeftStartBorder?: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class TableTool {
|
|
19
|
+
// 单元格最小宽度
|
|
20
|
+
private readonly MIN_TD_WIDTH = 20
|
|
21
|
+
// 行列工具相对表格偏移值
|
|
22
|
+
private readonly ROW_COL_OFFSET = 18
|
|
23
|
+
// 快速添加行列工具宽度
|
|
24
|
+
private readonly ROW_COL_QUICK_WIDTH = 16
|
|
25
|
+
// 快速添加行列工具偏移值
|
|
26
|
+
private readonly ROW_COL_QUICK_OFFSET = 5
|
|
27
|
+
// 快速添加行列工具相对表格位置
|
|
28
|
+
private readonly ROW_COL_QUICK_POSITION =
|
|
29
|
+
this.ROW_COL_OFFSET + (this.ROW_COL_OFFSET - this.ROW_COL_QUICK_WIDTH) / 2
|
|
30
|
+
// 边框工具宽/高度
|
|
31
|
+
private readonly BORDER_VALUE = 4
|
|
32
|
+
// 快速选择工具偏移值
|
|
33
|
+
private readonly TABLE_SELECT_OFFSET = 20
|
|
34
|
+
|
|
35
|
+
private draw: Draw
|
|
36
|
+
private canvas: HTMLCanvasElement
|
|
37
|
+
private options: DeepRequired<IEditorOption>
|
|
38
|
+
private position: Position
|
|
39
|
+
private range: RangeManager
|
|
40
|
+
private container: HTMLDivElement
|
|
41
|
+
private toolRowContainer: HTMLDivElement | null
|
|
42
|
+
private toolRowAddBtn: HTMLDivElement | null
|
|
43
|
+
private toolColAddBtn: HTMLDivElement | null
|
|
44
|
+
private toolTableSelectBtn: HTMLDivElement | null
|
|
45
|
+
private toolColContainer: HTMLDivElement | null
|
|
46
|
+
private toolBorderContainer: HTMLDivElement | null
|
|
47
|
+
private anchorLine: HTMLDivElement | null
|
|
48
|
+
private mousedownX: number
|
|
49
|
+
private mousedownY: number
|
|
50
|
+
|
|
51
|
+
constructor(draw: Draw) {
|
|
52
|
+
this.draw = draw
|
|
53
|
+
this.canvas = draw.getPage()
|
|
54
|
+
this.options = draw.getOptions()
|
|
55
|
+
this.position = draw.getPosition()
|
|
56
|
+
this.range = draw.getRange()
|
|
57
|
+
this.container = draw.getContainer()
|
|
58
|
+
// x、y轴
|
|
59
|
+
this.toolRowContainer = null
|
|
60
|
+
this.toolRowAddBtn = null
|
|
61
|
+
this.toolColAddBtn = null
|
|
62
|
+
this.toolTableSelectBtn = null
|
|
63
|
+
this.toolColContainer = null
|
|
64
|
+
this.toolBorderContainer = null
|
|
65
|
+
this.anchorLine = null
|
|
66
|
+
this.mousedownX = 0
|
|
67
|
+
this.mousedownY = 0
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public dispose() {
|
|
71
|
+
this.toolRowContainer?.remove()
|
|
72
|
+
this.toolRowAddBtn?.remove()
|
|
73
|
+
this.toolColAddBtn?.remove()
|
|
74
|
+
this.toolTableSelectBtn?.remove()
|
|
75
|
+
this.toolColContainer?.remove()
|
|
76
|
+
this.toolBorderContainer?.remove()
|
|
77
|
+
this.toolRowContainer = null
|
|
78
|
+
this.toolRowAddBtn = null
|
|
79
|
+
this.toolColAddBtn = null
|
|
80
|
+
this.toolTableSelectBtn = null
|
|
81
|
+
this.toolColContainer = null
|
|
82
|
+
this.toolBorderContainer = null
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public render() {
|
|
86
|
+
const { isTable, index, trIndex, tdIndex } =
|
|
87
|
+
this.position.getPositionContext()
|
|
88
|
+
if (!isTable) return
|
|
89
|
+
// 销毁之前工具
|
|
90
|
+
this.dispose()
|
|
91
|
+
const elementList = this.draw.getOriginalElementList()
|
|
92
|
+
const positionList = this.position.getOriginalPositionList()
|
|
93
|
+
const element = elementList[index!]
|
|
94
|
+
// 表格工具配置禁用又非设计模式时不渲染
|
|
95
|
+
if (element.tableToolDisabled && !this.draw.isDesignMode()) return
|
|
96
|
+
// 渲染所需数据
|
|
97
|
+
const {
|
|
98
|
+
scale,
|
|
99
|
+
table: { overflow }
|
|
100
|
+
} = this.options
|
|
101
|
+
const position = positionList[index!]
|
|
102
|
+
const { colgroup, trList } = element
|
|
103
|
+
const {
|
|
104
|
+
coordinate: { leftTop }
|
|
105
|
+
} = position
|
|
106
|
+
const height = this.draw.getHeight()
|
|
107
|
+
const pageGap = this.draw.getPageGap()
|
|
108
|
+
const prePageHeight = this.draw.getPageNo() * (height + pageGap)
|
|
109
|
+
const tableX = leftTop[0]
|
|
110
|
+
const tableY = leftTop[1] + prePageHeight
|
|
111
|
+
const td = element.trList![trIndex!].tdList[tdIndex!]
|
|
112
|
+
const rowIndex = td.rowIndex
|
|
113
|
+
const colIndex = td.colIndex
|
|
114
|
+
const tableHeight = element.height! * scale
|
|
115
|
+
const tableWidth = element.width! * scale
|
|
116
|
+
// 表格选择工具
|
|
117
|
+
const tableSelectBtn = document.createElement('div')
|
|
118
|
+
tableSelectBtn.classList.add(`${EDITOR_PREFIX}-table-tool__select`)
|
|
119
|
+
tableSelectBtn.style.height = `${tableHeight * scale}`
|
|
120
|
+
tableSelectBtn.style.left = `${tableX}px`
|
|
121
|
+
tableSelectBtn.style.top = `${tableY}px`
|
|
122
|
+
tableSelectBtn.style.transform = `translate(-${
|
|
123
|
+
this.TABLE_SELECT_OFFSET * scale
|
|
124
|
+
}px, ${-this.TABLE_SELECT_OFFSET * scale}px)`
|
|
125
|
+
// 快捷全选
|
|
126
|
+
tableSelectBtn.onclick = () => {
|
|
127
|
+
this.draw.getTableOperate().tableSelectAll()
|
|
128
|
+
}
|
|
129
|
+
this.container.append(tableSelectBtn)
|
|
130
|
+
this.toolTableSelectBtn = tableSelectBtn
|
|
131
|
+
// 渲染行工具
|
|
132
|
+
const rowHeightList = trList!.map(tr => tr.height)
|
|
133
|
+
const rowContainer = document.createElement('div')
|
|
134
|
+
rowContainer.classList.add(`${EDITOR_PREFIX}-table-tool__row`)
|
|
135
|
+
rowContainer.style.transform = `translateX(-${
|
|
136
|
+
this.ROW_COL_OFFSET * scale
|
|
137
|
+
}px)`
|
|
138
|
+
for (let r = 0; r < rowHeightList.length; r++) {
|
|
139
|
+
const rowHeight = rowHeightList[r] * scale
|
|
140
|
+
const rowItem = document.createElement('div')
|
|
141
|
+
rowItem.classList.add(`${EDITOR_PREFIX}-table-tool__row__item`)
|
|
142
|
+
if (r === rowIndex) {
|
|
143
|
+
rowItem.classList.add('active')
|
|
144
|
+
}
|
|
145
|
+
// 快捷行选择
|
|
146
|
+
rowItem.onclick = () => {
|
|
147
|
+
const tdList = this.draw
|
|
148
|
+
.getTableParticle()
|
|
149
|
+
.getTdListByRowIndex(trList!, r)
|
|
150
|
+
const firstTd = tdList[0]
|
|
151
|
+
const lastTd = tdList[tdList.length - 1]
|
|
152
|
+
this.position.setPositionContext({
|
|
153
|
+
index,
|
|
154
|
+
isTable: true,
|
|
155
|
+
trIndex: firstTd.trIndex,
|
|
156
|
+
tdIndex: firstTd.tdIndex,
|
|
157
|
+
tableId: element.id
|
|
158
|
+
})
|
|
159
|
+
this.range.setRange(
|
|
160
|
+
0,
|
|
161
|
+
0,
|
|
162
|
+
element.id,
|
|
163
|
+
firstTd.tdIndex,
|
|
164
|
+
lastTd.tdIndex,
|
|
165
|
+
firstTd.trIndex,
|
|
166
|
+
lastTd.trIndex
|
|
167
|
+
)
|
|
168
|
+
this.draw.render({
|
|
169
|
+
curIndex: 0,
|
|
170
|
+
isCompute: false,
|
|
171
|
+
isSubmitHistory: false
|
|
172
|
+
})
|
|
173
|
+
this._setAnchorActive(rowContainer, r)
|
|
174
|
+
}
|
|
175
|
+
const rowItemAnchor = document.createElement('div')
|
|
176
|
+
rowItemAnchor.classList.add(`${EDITOR_PREFIX}-table-tool__anchor`)
|
|
177
|
+
// 行高度拖拽开始
|
|
178
|
+
rowItemAnchor.onmousedown = evt => {
|
|
179
|
+
this._mousedown({
|
|
180
|
+
evt,
|
|
181
|
+
element,
|
|
182
|
+
index: r,
|
|
183
|
+
order: TableOrder.ROW
|
|
184
|
+
})
|
|
185
|
+
}
|
|
186
|
+
rowItem.append(rowItemAnchor)
|
|
187
|
+
rowItem.style.height = `${rowHeight}px`
|
|
188
|
+
rowContainer.append(rowItem)
|
|
189
|
+
}
|
|
190
|
+
rowContainer.style.left = `${tableX}px`
|
|
191
|
+
rowContainer.style.top = `${tableY}px`
|
|
192
|
+
this.container.append(rowContainer)
|
|
193
|
+
this.toolRowContainer = rowContainer
|
|
194
|
+
// 添加行按钮
|
|
195
|
+
const rowAddBtn = document.createElement('div')
|
|
196
|
+
rowAddBtn.classList.add(`${EDITOR_PREFIX}-table-tool__quick__add`)
|
|
197
|
+
rowAddBtn.style.height = `${tableHeight * scale}`
|
|
198
|
+
rowAddBtn.style.left = `${tableX}px`
|
|
199
|
+
rowAddBtn.style.top = `${tableY + tableHeight}px`
|
|
200
|
+
rowAddBtn.style.transform = `translate(-${
|
|
201
|
+
this.ROW_COL_QUICK_POSITION * scale
|
|
202
|
+
}px, ${this.ROW_COL_QUICK_OFFSET * scale}px)`
|
|
203
|
+
// 快捷添加行
|
|
204
|
+
rowAddBtn.onclick = () => {
|
|
205
|
+
this.position.setPositionContext({
|
|
206
|
+
index,
|
|
207
|
+
isTable: true,
|
|
208
|
+
trIndex: trList!.length - 1,
|
|
209
|
+
tdIndex: 0,
|
|
210
|
+
tableId: element.id
|
|
211
|
+
})
|
|
212
|
+
this.draw.getTableOperate().insertTableBottomRow()
|
|
213
|
+
}
|
|
214
|
+
this.container.append(rowAddBtn)
|
|
215
|
+
this.toolRowAddBtn = rowAddBtn
|
|
216
|
+
// 渲染列工具
|
|
217
|
+
const colWidthList = colgroup!.map(col => col.width)
|
|
218
|
+
const colContainer = document.createElement('div')
|
|
219
|
+
colContainer.classList.add(`${EDITOR_PREFIX}-table-tool__col`)
|
|
220
|
+
colContainer.style.transform = `translateY(-${
|
|
221
|
+
this.ROW_COL_OFFSET * scale
|
|
222
|
+
}px)`
|
|
223
|
+
for (let c = 0; c < colWidthList.length; c++) {
|
|
224
|
+
const colWidth = colWidthList[c] * scale
|
|
225
|
+
const colItem = document.createElement('div')
|
|
226
|
+
colItem.classList.add(`${EDITOR_PREFIX}-table-tool__col__item`)
|
|
227
|
+
if (c === colIndex) {
|
|
228
|
+
colItem.classList.add('active')
|
|
229
|
+
}
|
|
230
|
+
// 快捷列选择
|
|
231
|
+
colItem.onclick = () => {
|
|
232
|
+
const tdList = this.draw
|
|
233
|
+
.getTableParticle()
|
|
234
|
+
.getTdListByColIndex(trList!, c)
|
|
235
|
+
const firstTd = tdList[0]
|
|
236
|
+
const lastTd = tdList[tdList.length - 1]
|
|
237
|
+
this.position.setPositionContext({
|
|
238
|
+
index,
|
|
239
|
+
isTable: true,
|
|
240
|
+
trIndex: firstTd.trIndex,
|
|
241
|
+
tdIndex: firstTd.tdIndex,
|
|
242
|
+
tableId: element.id
|
|
243
|
+
})
|
|
244
|
+
this.range.setRange(
|
|
245
|
+
0,
|
|
246
|
+
0,
|
|
247
|
+
element.id,
|
|
248
|
+
firstTd.tdIndex,
|
|
249
|
+
lastTd.tdIndex,
|
|
250
|
+
firstTd.trIndex,
|
|
251
|
+
lastTd.trIndex
|
|
252
|
+
)
|
|
253
|
+
this.draw.render({
|
|
254
|
+
curIndex: 0,
|
|
255
|
+
isCompute: false,
|
|
256
|
+
isSubmitHistory: false
|
|
257
|
+
})
|
|
258
|
+
this._setAnchorActive(colContainer, c)
|
|
259
|
+
}
|
|
260
|
+
const colItemAnchor = document.createElement('div')
|
|
261
|
+
colItemAnchor.classList.add(`${EDITOR_PREFIX}-table-tool__anchor`)
|
|
262
|
+
// 列高度拖拽开始
|
|
263
|
+
colItemAnchor.onmousedown = evt => {
|
|
264
|
+
this._mousedown({
|
|
265
|
+
evt,
|
|
266
|
+
element,
|
|
267
|
+
index: c,
|
|
268
|
+
order: TableOrder.COL
|
|
269
|
+
})
|
|
270
|
+
}
|
|
271
|
+
colItem.append(colItemAnchor)
|
|
272
|
+
colItem.style.width = `${colWidth}px`
|
|
273
|
+
colContainer.append(colItem)
|
|
274
|
+
}
|
|
275
|
+
colContainer.style.left = `${tableX}px`
|
|
276
|
+
colContainer.style.top = `${tableY}px`
|
|
277
|
+
this.container.append(colContainer)
|
|
278
|
+
this.toolColContainer = colContainer
|
|
279
|
+
// 添加列按钮
|
|
280
|
+
const colAddBtn = document.createElement('div')
|
|
281
|
+
colAddBtn.classList.add(`${EDITOR_PREFIX}-table-tool__quick__add`)
|
|
282
|
+
colAddBtn.style.height = `${tableHeight * scale}`
|
|
283
|
+
colAddBtn.style.left = `${tableX + tableWidth}px`
|
|
284
|
+
colAddBtn.style.top = `${tableY}px`
|
|
285
|
+
colAddBtn.style.transform = `translate(${
|
|
286
|
+
this.ROW_COL_QUICK_OFFSET * scale
|
|
287
|
+
}px, -${this.ROW_COL_QUICK_POSITION * scale}px)`
|
|
288
|
+
// 快捷添加列
|
|
289
|
+
colAddBtn.onclick = () => {
|
|
290
|
+
this.position.setPositionContext({
|
|
291
|
+
index,
|
|
292
|
+
isTable: true,
|
|
293
|
+
trIndex: 0,
|
|
294
|
+
tdIndex: trList![0].tdList.length - 1 || 0,
|
|
295
|
+
tableId: element.id
|
|
296
|
+
})
|
|
297
|
+
this.draw.getTableOperate().insertTableRightCol()
|
|
298
|
+
}
|
|
299
|
+
this.container.append(colAddBtn)
|
|
300
|
+
this.toolColAddBtn = colAddBtn
|
|
301
|
+
// 渲染单元格边框拖拽工具
|
|
302
|
+
const borderContainer = document.createElement('div')
|
|
303
|
+
borderContainer.classList.add(`${EDITOR_PREFIX}-table-tool__border`)
|
|
304
|
+
borderContainer.style.height = `${tableHeight}px`
|
|
305
|
+
borderContainer.style.width = `${tableWidth}px`
|
|
306
|
+
borderContainer.style.left = `${tableX}px`
|
|
307
|
+
borderContainer.style.top = `${tableY}px`
|
|
308
|
+
for (let r = 0; r < trList!.length; r++) {
|
|
309
|
+
const tr = trList![r]
|
|
310
|
+
for (let d = 0; d < tr.tdList.length; d++) {
|
|
311
|
+
const td = tr.tdList[d]
|
|
312
|
+
const rowBorder = document.createElement('div')
|
|
313
|
+
rowBorder.classList.add(`${EDITOR_PREFIX}-table-tool__border__row`)
|
|
314
|
+
rowBorder.style.width = `${td.width! * scale}px`
|
|
315
|
+
rowBorder.style.height = `${this.BORDER_VALUE}px`
|
|
316
|
+
rowBorder.style.top = `${
|
|
317
|
+
(td.y! + td.height!) * scale - this.BORDER_VALUE / 2
|
|
318
|
+
}px`
|
|
319
|
+
rowBorder.style.left = `${td.x! * scale}px`
|
|
320
|
+
// 行宽度拖拽开始
|
|
321
|
+
rowBorder.onmousedown = evt => {
|
|
322
|
+
this._mousedown({
|
|
323
|
+
evt,
|
|
324
|
+
element,
|
|
325
|
+
index: td.rowIndex! + td.rowspan - 1,
|
|
326
|
+
order: TableOrder.ROW
|
|
327
|
+
})
|
|
328
|
+
}
|
|
329
|
+
borderContainer.appendChild(rowBorder)
|
|
330
|
+
const colBorder = document.createElement('div')
|
|
331
|
+
colBorder.classList.add(`${EDITOR_PREFIX}-table-tool__border__col`)
|
|
332
|
+
colBorder.style.width = `${this.BORDER_VALUE}px`
|
|
333
|
+
colBorder.style.height = `${td.height! * scale}px`
|
|
334
|
+
colBorder.style.top = `${td.y! * scale}px`
|
|
335
|
+
colBorder.style.left = `${
|
|
336
|
+
(td.x! + td.width!) * scale - this.BORDER_VALUE / 2
|
|
337
|
+
}px`
|
|
338
|
+
// 列高度拖拽开始
|
|
339
|
+
colBorder.onmousedown = evt => {
|
|
340
|
+
this._mousedown({
|
|
341
|
+
evt,
|
|
342
|
+
element,
|
|
343
|
+
index: td.colIndex! + td.colspan - 1,
|
|
344
|
+
order: TableOrder.COL
|
|
345
|
+
})
|
|
346
|
+
}
|
|
347
|
+
borderContainer.appendChild(colBorder)
|
|
348
|
+
// 首列开头拖拽(配置表格可以超出正文区域宽度时)
|
|
349
|
+
if (overflow && td.colIndex === 0) {
|
|
350
|
+
const colBorder = document.createElement('div')
|
|
351
|
+
colBorder.classList.add(`${EDITOR_PREFIX}-table-tool__border__col`)
|
|
352
|
+
colBorder.style.width = `${this.BORDER_VALUE}px`
|
|
353
|
+
colBorder.style.height = `${td.height! * scale}px`
|
|
354
|
+
colBorder.style.top = `${td.y! * scale}px`
|
|
355
|
+
colBorder.style.left = `${td.x! * scale - this.BORDER_VALUE / 2}px`
|
|
356
|
+
// 首列拖拽
|
|
357
|
+
colBorder.onmousedown = evt => {
|
|
358
|
+
this._mousedown({
|
|
359
|
+
evt,
|
|
360
|
+
element,
|
|
361
|
+
index: 0,
|
|
362
|
+
isLeftStartBorder: true,
|
|
363
|
+
order: TableOrder.COL
|
|
364
|
+
})
|
|
365
|
+
}
|
|
366
|
+
borderContainer.appendChild(colBorder)
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
this.container.append(borderContainer)
|
|
371
|
+
this.toolBorderContainer = borderContainer
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
private _setAnchorActive(container: HTMLDivElement, index: number) {
|
|
375
|
+
const children = container.children
|
|
376
|
+
for (let c = 0; c < children.length; c++) {
|
|
377
|
+
const child = children[c]
|
|
378
|
+
if (c === index) {
|
|
379
|
+
child.classList.add('active')
|
|
380
|
+
} else {
|
|
381
|
+
child.classList.remove('active')
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
private _mousedown(payload: IAnchorMouseDown) {
|
|
387
|
+
const { evt, index, order, element, isLeftStartBorder } = payload
|
|
388
|
+
this.canvas = this.draw.getPage()
|
|
389
|
+
const {
|
|
390
|
+
scale,
|
|
391
|
+
table: { overflow }
|
|
392
|
+
} = this.options
|
|
393
|
+
const width = this.draw.getWidth()
|
|
394
|
+
const height = this.draw.getHeight()
|
|
395
|
+
const pageGap = this.draw.getPageGap()
|
|
396
|
+
const prePageHeight = this.draw.getPageNo() * (height + pageGap)
|
|
397
|
+
this.mousedownX = evt.x
|
|
398
|
+
this.mousedownY = evt.y
|
|
399
|
+
const target = evt.target as HTMLDivElement
|
|
400
|
+
const canvasRect = this.canvas.getBoundingClientRect()
|
|
401
|
+
// 改变光标
|
|
402
|
+
const cursor = window.getComputedStyle(target).cursor
|
|
403
|
+
document.body.style.cursor = cursor
|
|
404
|
+
this.canvas.style.cursor = cursor
|
|
405
|
+
// 拖拽线
|
|
406
|
+
let startX = 0
|
|
407
|
+
let startY = 0
|
|
408
|
+
const anchorLine = document.createElement('div')
|
|
409
|
+
anchorLine.classList.add(`${EDITOR_PREFIX}-table-anchor__line`)
|
|
410
|
+
if (order === TableOrder.ROW) {
|
|
411
|
+
anchorLine.classList.add(`${EDITOR_PREFIX}-table-anchor__line__row`)
|
|
412
|
+
anchorLine.style.width = `${width}px`
|
|
413
|
+
startX = 0
|
|
414
|
+
startY = prePageHeight + this.mousedownY - canvasRect.top
|
|
415
|
+
} else {
|
|
416
|
+
anchorLine.classList.add(`${EDITOR_PREFIX}-table-anchor__line__col`)
|
|
417
|
+
anchorLine.style.height = `${height}px`
|
|
418
|
+
startX = this.mousedownX - canvasRect.left
|
|
419
|
+
startY = prePageHeight
|
|
420
|
+
}
|
|
421
|
+
anchorLine.style.left = `${startX}px`
|
|
422
|
+
anchorLine.style.top = `${startY}px`
|
|
423
|
+
this.container.append(anchorLine)
|
|
424
|
+
this.anchorLine = anchorLine
|
|
425
|
+
// 追加全局事件
|
|
426
|
+
let dx = 0
|
|
427
|
+
let dy = 0
|
|
428
|
+
const mousemoveFn = (evt: MouseEvent) => {
|
|
429
|
+
const movePosition = this._mousemove(evt, order, startX, startY)
|
|
430
|
+
if (movePosition) {
|
|
431
|
+
dx = movePosition.dx
|
|
432
|
+
dy = movePosition.dy
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
document.addEventListener('mousemove', mousemoveFn)
|
|
436
|
+
document.addEventListener(
|
|
437
|
+
'mouseup',
|
|
438
|
+
() => {
|
|
439
|
+
let isChangeSize = false
|
|
440
|
+
// 改变尺寸
|
|
441
|
+
if (order === TableOrder.ROW) {
|
|
442
|
+
const trList = element.trList!
|
|
443
|
+
const tr = trList[index] || trList[index - 1]
|
|
444
|
+
// 最大移动高度-向上移动超出最小高度限定,则减少移动量
|
|
445
|
+
const { defaultTrMinHeight } = this.options.table
|
|
446
|
+
if (dy < 0 && tr.height + dy < defaultTrMinHeight) {
|
|
447
|
+
dy = defaultTrMinHeight - tr.height
|
|
448
|
+
}
|
|
449
|
+
if (dy) {
|
|
450
|
+
tr.height += dy
|
|
451
|
+
tr.minHeight = tr.height
|
|
452
|
+
isChangeSize = true
|
|
453
|
+
}
|
|
454
|
+
} else {
|
|
455
|
+
const { colgroup } = element
|
|
456
|
+
if (colgroup && dx) {
|
|
457
|
+
// 第一列特殊处理:更改表格宽度并移动位置
|
|
458
|
+
if (overflow && isLeftStartBorder) {
|
|
459
|
+
// 列减少宽度不能小于最小宽度
|
|
460
|
+
if (colgroup[index].width - dx / scale <= this.MIN_TD_WIDTH) {
|
|
461
|
+
dx = (colgroup[index].width - this.MIN_TD_WIDTH) * scale
|
|
462
|
+
}
|
|
463
|
+
colgroup[index].width -= dx / scale
|
|
464
|
+
element.width! -= dx / scale
|
|
465
|
+
element.translateX = (element.translateX || 0) + dx / scale
|
|
466
|
+
isChangeSize = true
|
|
467
|
+
} else {
|
|
468
|
+
// 宽度分配
|
|
469
|
+
const innerWidth = this.draw.getInnerWidth()
|
|
470
|
+
const curColWidth = colgroup[index].width
|
|
471
|
+
// 最小移动距离计算-如果向左移动:使单元格小于最小宽度,则减少移动量
|
|
472
|
+
if (dx < 0 && curColWidth + dx < this.MIN_TD_WIDTH) {
|
|
473
|
+
dx = this.MIN_TD_WIDTH - curColWidth
|
|
474
|
+
}
|
|
475
|
+
// 最大移动距离计算-如果向右移动:使后面一个单元格小于最小宽度,则减少移动量
|
|
476
|
+
const nextColWidth = colgroup[index + 1]?.width
|
|
477
|
+
if (
|
|
478
|
+
dx > 0 &&
|
|
479
|
+
nextColWidth &&
|
|
480
|
+
nextColWidth - dx < this.MIN_TD_WIDTH
|
|
481
|
+
) {
|
|
482
|
+
dx = nextColWidth - this.MIN_TD_WIDTH
|
|
483
|
+
}
|
|
484
|
+
const moveColWidth = curColWidth + dx
|
|
485
|
+
// 开始移动,只有表格的最后一列线才会改变表格的宽度,其他场景不用计算表格超出
|
|
486
|
+
if (!overflow && index === colgroup.length - 1) {
|
|
487
|
+
let moveTableWidth = 0
|
|
488
|
+
for (let c = 0; c < colgroup.length; c++) {
|
|
489
|
+
const group = colgroup[c]
|
|
490
|
+
// 下一列减去偏移量
|
|
491
|
+
if (c === index + 1) {
|
|
492
|
+
moveTableWidth -= dx
|
|
493
|
+
}
|
|
494
|
+
// 当前列加上偏移量
|
|
495
|
+
if (c === index) {
|
|
496
|
+
moveTableWidth += moveColWidth
|
|
497
|
+
}
|
|
498
|
+
if (c !== index) {
|
|
499
|
+
moveTableWidth += group.width
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (moveTableWidth > innerWidth) {
|
|
503
|
+
const tableWidth = element.width!
|
|
504
|
+
dx = innerWidth - tableWidth
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (dx) {
|
|
508
|
+
// 当前列增加,后列减少
|
|
509
|
+
if (colgroup.length - 1 !== index) {
|
|
510
|
+
colgroup[index + 1].width -= dx / scale
|
|
511
|
+
}
|
|
512
|
+
colgroup[index].width += dx / scale
|
|
513
|
+
isChangeSize = true
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
if (isChangeSize) {
|
|
519
|
+
this.draw.render({ isSetCursor: false })
|
|
520
|
+
}
|
|
521
|
+
// 还原副作用
|
|
522
|
+
anchorLine.remove()
|
|
523
|
+
document.removeEventListener('mousemove', mousemoveFn)
|
|
524
|
+
document.body.style.cursor = ''
|
|
525
|
+
this.canvas.style.cursor = 'text'
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
once: true
|
|
529
|
+
}
|
|
530
|
+
)
|
|
531
|
+
evt.preventDefault()
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
private _mousemove(
|
|
535
|
+
evt: MouseEvent,
|
|
536
|
+
tableOrder: TableOrder,
|
|
537
|
+
startX: number,
|
|
538
|
+
startY: number
|
|
539
|
+
): { dx: number; dy: number } | null {
|
|
540
|
+
if (!this.anchorLine) return null
|
|
541
|
+
const dx = evt.x - this.mousedownX
|
|
542
|
+
const dy = evt.y - this.mousedownY
|
|
543
|
+
if (tableOrder === TableOrder.ROW) {
|
|
544
|
+
this.anchorLine.style.top = `${startY + dy}px`
|
|
545
|
+
} else {
|
|
546
|
+
this.anchorLine.style.left = `${startX + dx}px`
|
|
547
|
+
}
|
|
548
|
+
evt.preventDefault()
|
|
549
|
+
return { dx, dy }
|
|
550
|
+
}
|
|
551
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { TextDecorationStyle } from '../../../dataset/enum/Text'
|
|
2
|
+
import { IElementFillRect } from '../../../interface/Element'
|
|
3
|
+
|
|
4
|
+
export abstract class AbstractRichText {
|
|
5
|
+
protected fillRect: IElementFillRect
|
|
6
|
+
protected fillColor?: string
|
|
7
|
+
protected fillDecorationStyle?: TextDecorationStyle
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
this.fillRect = this.clearFillInfo()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public clearFillInfo() {
|
|
14
|
+
this.fillColor = undefined
|
|
15
|
+
this.fillDecorationStyle = undefined
|
|
16
|
+
this.fillRect = {
|
|
17
|
+
x: 0,
|
|
18
|
+
y: 0,
|
|
19
|
+
width: 0,
|
|
20
|
+
height: 0
|
|
21
|
+
}
|
|
22
|
+
return this.fillRect
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public recordFillInfo(
|
|
26
|
+
ctx: CanvasRenderingContext2D,
|
|
27
|
+
x: number,
|
|
28
|
+
y: number,
|
|
29
|
+
width: number,
|
|
30
|
+
height?: number,
|
|
31
|
+
color?: string,
|
|
32
|
+
decorationStyle?: TextDecorationStyle
|
|
33
|
+
) {
|
|
34
|
+
const isFirstRecord = !this.fillRect.width
|
|
35
|
+
// 颜色不同时立即绘制
|
|
36
|
+
if (
|
|
37
|
+
!isFirstRecord &&
|
|
38
|
+
(this.fillColor !== color || this.fillDecorationStyle !== decorationStyle)
|
|
39
|
+
) {
|
|
40
|
+
this.render(ctx)
|
|
41
|
+
this.clearFillInfo()
|
|
42
|
+
// 重新记录
|
|
43
|
+
this.recordFillInfo(ctx, x, y, width, height, color, decorationStyle)
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
if (isFirstRecord) {
|
|
47
|
+
this.fillRect.x = x
|
|
48
|
+
this.fillRect.y = y
|
|
49
|
+
}
|
|
50
|
+
if (height && this.fillRect.height < height) {
|
|
51
|
+
this.fillRect.height = height
|
|
52
|
+
}
|
|
53
|
+
this.fillRect.width += width
|
|
54
|
+
this.fillColor = color
|
|
55
|
+
this.fillDecorationStyle = decorationStyle
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public abstract render(ctx: CanvasRenderingContext2D): void
|
|
59
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AbstractRichText } from './AbstractRichText'
|
|
2
|
+
import { IEditorOption } from '../../../interface/Editor'
|
|
3
|
+
import { Draw } from '../Draw'
|
|
4
|
+
|
|
5
|
+
export class Highlight extends AbstractRichText {
|
|
6
|
+
private options: Required<IEditorOption>
|
|
7
|
+
|
|
8
|
+
constructor(draw: Draw) {
|
|
9
|
+
super()
|
|
10
|
+
this.options = draw.getOptions()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public render(ctx: CanvasRenderingContext2D) {
|
|
14
|
+
if (!this.fillRect.width) return
|
|
15
|
+
const { highlightAlpha } = this.options
|
|
16
|
+
const { x, y, width, height } = this.fillRect
|
|
17
|
+
ctx.save()
|
|
18
|
+
ctx.globalAlpha = highlightAlpha
|
|
19
|
+
ctx.fillStyle = this.fillColor!
|
|
20
|
+
ctx.fillRect(x, y, width, height)
|
|
21
|
+
ctx.restore()
|
|
22
|
+
this.clearFillInfo()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AbstractRichText } from './AbstractRichText'
|
|
2
|
+
import { IEditorOption } from '../../../interface/Editor'
|
|
3
|
+
import { Draw } from '../Draw'
|
|
4
|
+
|
|
5
|
+
export class Strikeout extends AbstractRichText {
|
|
6
|
+
private options: Required<IEditorOption>
|
|
7
|
+
|
|
8
|
+
constructor(draw: Draw) {
|
|
9
|
+
super()
|
|
10
|
+
this.options = draw.getOptions()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public render(ctx: CanvasRenderingContext2D) {
|
|
14
|
+
if (!this.fillRect.width) return
|
|
15
|
+
const { scale, strikeoutColor } = this.options
|
|
16
|
+
const { x, y, width } = this.fillRect
|
|
17
|
+
ctx.save()
|
|
18
|
+
ctx.lineWidth = scale
|
|
19
|
+
ctx.strokeStyle = strikeoutColor
|
|
20
|
+
const adjustY = y + 0.5 // 从1处渲染,避免线宽度等于3
|
|
21
|
+
ctx.beginPath()
|
|
22
|
+
ctx.moveTo(x, adjustY)
|
|
23
|
+
ctx.lineTo(x + width, adjustY)
|
|
24
|
+
ctx.stroke()
|
|
25
|
+
ctx.restore()
|
|
26
|
+
this.clearFillInfo()
|
|
27
|
+
}
|
|
28
|
+
}
|