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,582 @@
|
|
|
1
|
+
import { EDITOR_PREFIX } from '../../../../dataset/constant/Editor'
|
|
2
|
+
import { EditorMode } from '../../../../dataset/enum/Editor'
|
|
3
|
+
import { IEditorOption } from '../../../../interface/Editor'
|
|
4
|
+
import { IElement, IElementPosition } from '../../../../interface/Element'
|
|
5
|
+
import { EventBusMap } from '../../../../interface/EventBus'
|
|
6
|
+
import {
|
|
7
|
+
IPreviewerCreateResult,
|
|
8
|
+
IPreviewerDrawOption
|
|
9
|
+
} from '../../../../interface/Previewer'
|
|
10
|
+
import { downloadFile } from '../../../../utils'
|
|
11
|
+
import { EventBus } from '../../../event/eventbus/EventBus'
|
|
12
|
+
import { Draw } from '../../Draw'
|
|
13
|
+
|
|
14
|
+
export class Previewer {
|
|
15
|
+
private container: HTMLDivElement
|
|
16
|
+
private canvas: HTMLCanvasElement
|
|
17
|
+
private draw: Draw
|
|
18
|
+
private options: Required<IEditorOption>
|
|
19
|
+
private curElement: IElement | null
|
|
20
|
+
private curElementSrc: string
|
|
21
|
+
private previewerDrawOption: IPreviewerDrawOption
|
|
22
|
+
private curPosition: IElementPosition | null
|
|
23
|
+
private eventBus: EventBus<EventBusMap>
|
|
24
|
+
// 图片列表
|
|
25
|
+
private imageList: IElement[]
|
|
26
|
+
private curShowElement: IElement | null
|
|
27
|
+
private imageCount: HTMLSpanElement | null
|
|
28
|
+
private imagePre: HTMLElement | null
|
|
29
|
+
private imageNext: HTMLElement | null
|
|
30
|
+
// 拖拽改变尺寸
|
|
31
|
+
private resizerSelection: HTMLDivElement
|
|
32
|
+
private resizerHandleList: HTMLDivElement[]
|
|
33
|
+
private resizerImageContainer: HTMLDivElement
|
|
34
|
+
private resizerImage: HTMLImageElement
|
|
35
|
+
private resizerSize: HTMLSpanElement
|
|
36
|
+
private width: number
|
|
37
|
+
private height: number
|
|
38
|
+
private mousedownX: number
|
|
39
|
+
private mousedownY: number
|
|
40
|
+
private curHandleIndex: number
|
|
41
|
+
// 预览选区
|
|
42
|
+
private previewerContainer: HTMLDivElement | null
|
|
43
|
+
private previewerImage: HTMLImageElement | null
|
|
44
|
+
|
|
45
|
+
constructor(draw: Draw) {
|
|
46
|
+
this.container = draw.getContainer()
|
|
47
|
+
this.canvas = draw.getPage()
|
|
48
|
+
this.draw = draw
|
|
49
|
+
this.options = draw.getOptions()
|
|
50
|
+
this.curElement = null
|
|
51
|
+
this.curElementSrc = ''
|
|
52
|
+
this.previewerDrawOption = {}
|
|
53
|
+
this.curPosition = null
|
|
54
|
+
this.eventBus = draw.getEventBus()
|
|
55
|
+
this.imageList = []
|
|
56
|
+
this.curShowElement = null
|
|
57
|
+
this.imageCount = null
|
|
58
|
+
this.imagePre = null
|
|
59
|
+
this.imageNext = null
|
|
60
|
+
// 图片尺寸缩放
|
|
61
|
+
const {
|
|
62
|
+
resizerSelection,
|
|
63
|
+
resizerHandleList,
|
|
64
|
+
resizerImageContainer,
|
|
65
|
+
resizerImage,
|
|
66
|
+
resizerSize
|
|
67
|
+
} = this._createResizerDom()
|
|
68
|
+
this.resizerSelection = resizerSelection
|
|
69
|
+
this.resizerHandleList = resizerHandleList
|
|
70
|
+
this.resizerImageContainer = resizerImageContainer
|
|
71
|
+
this.resizerImage = resizerImage
|
|
72
|
+
this.resizerSize = resizerSize
|
|
73
|
+
this.width = 0
|
|
74
|
+
this.height = 0
|
|
75
|
+
this.mousedownX = 0
|
|
76
|
+
this.mousedownY = 0
|
|
77
|
+
this.curHandleIndex = 0 // 默认右下角
|
|
78
|
+
this.previewerContainer = null
|
|
79
|
+
this.previewerImage = null
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private _getElementPosition(
|
|
83
|
+
element: IElement,
|
|
84
|
+
position: IElementPosition | null = null
|
|
85
|
+
): { x: number; y: number } {
|
|
86
|
+
const { scale } = this.options
|
|
87
|
+
let x = 0
|
|
88
|
+
let y = 0
|
|
89
|
+
const height = this.draw.getHeight()
|
|
90
|
+
const pageGap = this.draw.getPageGap()
|
|
91
|
+
const pageNo = position?.pageNo ?? this.draw.getPageNo()
|
|
92
|
+
const preY = pageNo * (height + pageGap)
|
|
93
|
+
// 优先使用浮动位置
|
|
94
|
+
if (element.imgFloatPosition) {
|
|
95
|
+
x = element.imgFloatPosition.x! * scale
|
|
96
|
+
y = element.imgFloatPosition.y * scale + preY
|
|
97
|
+
} else if (position) {
|
|
98
|
+
const {
|
|
99
|
+
coordinate: {
|
|
100
|
+
leftTop: [left, top]
|
|
101
|
+
},
|
|
102
|
+
ascent
|
|
103
|
+
} = position
|
|
104
|
+
x = left
|
|
105
|
+
y = top + preY + ascent
|
|
106
|
+
}
|
|
107
|
+
return { x, y }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private _createResizerDom(): IPreviewerCreateResult {
|
|
111
|
+
const { scale } = this.options
|
|
112
|
+
// 拖拽边框
|
|
113
|
+
const resizerSelection = document.createElement('div')
|
|
114
|
+
resizerSelection.classList.add(`${EDITOR_PREFIX}-resizer-selection`)
|
|
115
|
+
resizerSelection.style.display = 'none'
|
|
116
|
+
resizerSelection.style.borderColor = this.options.resizerColor
|
|
117
|
+
resizerSelection.style.borderWidth = `${scale}px`
|
|
118
|
+
// 拖拽点
|
|
119
|
+
const resizerHandleList: HTMLDivElement[] = []
|
|
120
|
+
for (let i = 0; i < 8; i++) {
|
|
121
|
+
const handleDom = document.createElement('div')
|
|
122
|
+
handleDom.style.background = this.options.resizerColor
|
|
123
|
+
handleDom.classList.add(`resizer-handle`)
|
|
124
|
+
handleDom.classList.add(`handle-${i}`)
|
|
125
|
+
handleDom.setAttribute('data-index', String(i))
|
|
126
|
+
handleDom.onmousedown = this._mousedown.bind(this)
|
|
127
|
+
resizerSelection.append(handleDom)
|
|
128
|
+
resizerHandleList.push(handleDom)
|
|
129
|
+
}
|
|
130
|
+
this.container.append(resizerSelection)
|
|
131
|
+
// 尺寸查看
|
|
132
|
+
const resizerSizeView = document.createElement('div')
|
|
133
|
+
resizerSizeView.classList.add(`${EDITOR_PREFIX}-resizer-size-view`)
|
|
134
|
+
const resizerSize = document.createElement('span')
|
|
135
|
+
resizerSizeView.append(resizerSize)
|
|
136
|
+
resizerSelection.append(resizerSizeView)
|
|
137
|
+
// 拖拽镜像
|
|
138
|
+
const resizerImageContainer = document.createElement('div')
|
|
139
|
+
resizerImageContainer.classList.add(`${EDITOR_PREFIX}-resizer-image`)
|
|
140
|
+
resizerImageContainer.style.display = 'none'
|
|
141
|
+
const resizerImage = document.createElement('img')
|
|
142
|
+
resizerImageContainer.append(resizerImage)
|
|
143
|
+
this.container.append(resizerImageContainer)
|
|
144
|
+
return {
|
|
145
|
+
resizerSelection,
|
|
146
|
+
resizerHandleList,
|
|
147
|
+
resizerImageContainer,
|
|
148
|
+
resizerImage,
|
|
149
|
+
resizerSize
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private _keydown = () => {
|
|
154
|
+
// 有键盘事件触发时,主动销毁拖拽选区
|
|
155
|
+
if (this.resizerSelection.style.display === 'block') {
|
|
156
|
+
this.clearResizer()
|
|
157
|
+
document.removeEventListener('keydown', this._keydown)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private _mousedown(evt: MouseEvent) {
|
|
162
|
+
this.canvas = this.draw.getPage()
|
|
163
|
+
if (!this.curElement) return
|
|
164
|
+
const { scale } = this.options
|
|
165
|
+
this.mousedownX = evt.x
|
|
166
|
+
this.mousedownY = evt.y
|
|
167
|
+
const target = evt.target as HTMLDivElement
|
|
168
|
+
this.curHandleIndex = Number(target.dataset.index)
|
|
169
|
+
// 改变光标
|
|
170
|
+
const cursor = window.getComputedStyle(target).cursor
|
|
171
|
+
document.body.style.cursor = cursor
|
|
172
|
+
this.canvas.style.cursor = cursor
|
|
173
|
+
// 拖拽图片镜像
|
|
174
|
+
this.resizerImage.src = this.curElementSrc
|
|
175
|
+
this.resizerImageContainer.style.display = 'block'
|
|
176
|
+
// 优先使用浮动位置信息
|
|
177
|
+
const { x: resizerLeft, y: resizerTop } = this._getElementPosition(
|
|
178
|
+
this.curElement,
|
|
179
|
+
this.curPosition
|
|
180
|
+
)
|
|
181
|
+
this.resizerImageContainer.style.left = `${resizerLeft}px`
|
|
182
|
+
this.resizerImageContainer.style.top = `${resizerTop}px`
|
|
183
|
+
this.resizerImage.style.width = `${this.curElement.width! * scale}px`
|
|
184
|
+
this.resizerImage.style.height = `${this.curElement.height! * scale}px`
|
|
185
|
+
// 追加全局事件
|
|
186
|
+
const mousemoveFn = this._mousemove.bind(this)
|
|
187
|
+
document.addEventListener('mousemove', mousemoveFn)
|
|
188
|
+
document.addEventListener(
|
|
189
|
+
'mouseup',
|
|
190
|
+
() => {
|
|
191
|
+
// 改变尺寸
|
|
192
|
+
if (this.curElement && !this.previewerDrawOption.dragDisable) {
|
|
193
|
+
this.curElement.width = this.width
|
|
194
|
+
this.curElement.height = this.height
|
|
195
|
+
this.draw.render({
|
|
196
|
+
isSetCursor: true,
|
|
197
|
+
curIndex: this.curPosition?.index
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
// 还原副作用
|
|
201
|
+
this.resizerImageContainer.style.display = 'none'
|
|
202
|
+
document.removeEventListener('mousemove', mousemoveFn)
|
|
203
|
+
document.body.style.cursor = ''
|
|
204
|
+
this.canvas.style.cursor = 'text'
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
once: true
|
|
208
|
+
}
|
|
209
|
+
)
|
|
210
|
+
evt.preventDefault()
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private _mousemove(evt: MouseEvent) {
|
|
214
|
+
if (!this.curElement || this.previewerDrawOption.dragDisable) return
|
|
215
|
+
const { scale } = this.options
|
|
216
|
+
let dx = 0
|
|
217
|
+
let dy = 0
|
|
218
|
+
switch (this.curHandleIndex) {
|
|
219
|
+
case 0:
|
|
220
|
+
{
|
|
221
|
+
const offsetX = this.mousedownX - evt.x
|
|
222
|
+
const offsetY = this.mousedownY - evt.y
|
|
223
|
+
dx = Math.cbrt(offsetX ** 3 + offsetY ** 3)
|
|
224
|
+
dy = (this.curElement.height! * dx) / this.curElement.width!
|
|
225
|
+
}
|
|
226
|
+
break
|
|
227
|
+
case 1:
|
|
228
|
+
dy = this.mousedownY - evt.y
|
|
229
|
+
break
|
|
230
|
+
case 2:
|
|
231
|
+
{
|
|
232
|
+
const offsetX = evt.x - this.mousedownX
|
|
233
|
+
const offsetY = this.mousedownY - evt.y
|
|
234
|
+
dx = Math.cbrt(offsetX ** 3 + offsetY ** 3)
|
|
235
|
+
dy = (this.curElement.height! * dx) / this.curElement.width!
|
|
236
|
+
}
|
|
237
|
+
break
|
|
238
|
+
case 4:
|
|
239
|
+
{
|
|
240
|
+
const offsetX = evt.x - this.mousedownX
|
|
241
|
+
const offsetY = evt.y - this.mousedownY
|
|
242
|
+
dx = Math.cbrt(offsetX ** 3 + offsetY ** 3)
|
|
243
|
+
dy = (this.curElement.height! * dx) / this.curElement.width!
|
|
244
|
+
}
|
|
245
|
+
break
|
|
246
|
+
case 3:
|
|
247
|
+
dx = evt.x - this.mousedownX
|
|
248
|
+
break
|
|
249
|
+
case 5:
|
|
250
|
+
dy = evt.y - this.mousedownY
|
|
251
|
+
break
|
|
252
|
+
case 6:
|
|
253
|
+
{
|
|
254
|
+
const offsetX = this.mousedownX - evt.x
|
|
255
|
+
const offsetY = evt.y - this.mousedownY
|
|
256
|
+
dx = Math.cbrt(offsetX ** 3 + offsetY ** 3)
|
|
257
|
+
dy = (this.curElement.height! * dx) / this.curElement.width!
|
|
258
|
+
}
|
|
259
|
+
break
|
|
260
|
+
case 7:
|
|
261
|
+
dx = this.mousedownX - evt.x
|
|
262
|
+
break
|
|
263
|
+
}
|
|
264
|
+
// 图片实际宽高(变化大小除掉缩放比例)
|
|
265
|
+
const dw = this.curElement.width! + dx / scale
|
|
266
|
+
const dh = this.curElement.height! + dy / scale
|
|
267
|
+
if (dw <= 0 || dh <= 0) return
|
|
268
|
+
this.width = dw
|
|
269
|
+
this.height = dh
|
|
270
|
+
// 图片显示宽高
|
|
271
|
+
const elementWidth = dw * scale
|
|
272
|
+
const elementHeight = dh * scale
|
|
273
|
+
// 更新影子图片尺寸
|
|
274
|
+
this.resizerImage.style.width = `${elementWidth}px`
|
|
275
|
+
this.resizerImage.style.height = `${elementHeight}px`
|
|
276
|
+
// 更新预览包围框尺寸
|
|
277
|
+
this._updateResizerRect(elementWidth, elementHeight)
|
|
278
|
+
// 尺寸预览
|
|
279
|
+
this._updateResizerSizeView(elementWidth, elementHeight)
|
|
280
|
+
evt.preventDefault()
|
|
281
|
+
// 图片尺寸发生改变事件
|
|
282
|
+
if (this.eventBus.isSubscribe('imageSizeChange')) {
|
|
283
|
+
this.eventBus.emit('imageSizeChange', {
|
|
284
|
+
element: this.curElement
|
|
285
|
+
})
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
private _drawPreviewer() {
|
|
290
|
+
const previewerContainer = document.createElement('div')
|
|
291
|
+
previewerContainer.classList.add(`${EDITOR_PREFIX}-image-previewer`)
|
|
292
|
+
// 关闭按钮
|
|
293
|
+
const closeBtn = document.createElement('i')
|
|
294
|
+
closeBtn.classList.add('image-close')
|
|
295
|
+
closeBtn.onclick = () => {
|
|
296
|
+
this._clearPreviewer()
|
|
297
|
+
}
|
|
298
|
+
previewerContainer.append(closeBtn)
|
|
299
|
+
// 图片
|
|
300
|
+
const imgContainer = document.createElement('div')
|
|
301
|
+
imgContainer.classList.add(`${EDITOR_PREFIX}-image-container`)
|
|
302
|
+
const img = document.createElement('img')
|
|
303
|
+
img.src = this.curElementSrc
|
|
304
|
+
img.draggable = false
|
|
305
|
+
imgContainer.append(img)
|
|
306
|
+
this.previewerImage = img
|
|
307
|
+
previewerContainer.append(imgContainer)
|
|
308
|
+
// 操作栏
|
|
309
|
+
let x = 0
|
|
310
|
+
let y = 0
|
|
311
|
+
let scaleSize = 1
|
|
312
|
+
let rotateSize = 0
|
|
313
|
+
const menuContainer = document.createElement('div')
|
|
314
|
+
menuContainer.classList.add(`${EDITOR_PREFIX}-image-menu`)
|
|
315
|
+
// 切换上下张图片
|
|
316
|
+
const navigateContainer = document.createElement('div')
|
|
317
|
+
navigateContainer.classList.add('image-navigate')
|
|
318
|
+
const imagePre = document.createElement('i')
|
|
319
|
+
imagePre.classList.add('image-pre')
|
|
320
|
+
imagePre.onclick = () => {
|
|
321
|
+
const curIndex = this.imageList.findIndex(
|
|
322
|
+
el => el.id === this.curShowElement?.id
|
|
323
|
+
)
|
|
324
|
+
if (curIndex <= 0) return
|
|
325
|
+
this.curShowElement = this.imageList[curIndex - 1]
|
|
326
|
+
img.src = this.curShowElement.value
|
|
327
|
+
this._updateImageNavigate()
|
|
328
|
+
}
|
|
329
|
+
navigateContainer.append(imagePre)
|
|
330
|
+
this.imagePre = imagePre
|
|
331
|
+
const imageCount = document.createElement('span')
|
|
332
|
+
imageCount.classList.add('image-count')
|
|
333
|
+
this.imageCount = imageCount
|
|
334
|
+
navigateContainer.append(imageCount)
|
|
335
|
+
const imageNext = document.createElement('i')
|
|
336
|
+
imageNext.classList.add('image-next')
|
|
337
|
+
imageNext.onclick = () => {
|
|
338
|
+
const curIndex = this.imageList.findIndex(
|
|
339
|
+
el => el.id === this.curShowElement?.id
|
|
340
|
+
)
|
|
341
|
+
if (curIndex >= this.imageList.length - 1) return
|
|
342
|
+
this.curShowElement = this.imageList[curIndex + 1]
|
|
343
|
+
img.src = this.curShowElement.value
|
|
344
|
+
this._updateImageNavigate()
|
|
345
|
+
}
|
|
346
|
+
this.imageNext = imageNext
|
|
347
|
+
navigateContainer.append(imageNext)
|
|
348
|
+
menuContainer.append(navigateContainer)
|
|
349
|
+
// 缩放
|
|
350
|
+
const zoomIn = document.createElement('i')
|
|
351
|
+
zoomIn.classList.add('zoom-in')
|
|
352
|
+
zoomIn.onclick = () => {
|
|
353
|
+
scaleSize += 0.1
|
|
354
|
+
this._setPreviewerTransform(scaleSize, rotateSize, x, y)
|
|
355
|
+
}
|
|
356
|
+
menuContainer.append(zoomIn)
|
|
357
|
+
const zoomOut = document.createElement('i')
|
|
358
|
+
zoomOut.onclick = () => {
|
|
359
|
+
if (scaleSize - 0.1 <= 0.1) return
|
|
360
|
+
scaleSize -= 0.1
|
|
361
|
+
this._setPreviewerTransform(scaleSize, rotateSize, x, y)
|
|
362
|
+
}
|
|
363
|
+
zoomOut.classList.add('zoom-out')
|
|
364
|
+
menuContainer.append(zoomOut)
|
|
365
|
+
// 旋转
|
|
366
|
+
const rotate = document.createElement('i')
|
|
367
|
+
rotate.classList.add('rotate')
|
|
368
|
+
rotate.onclick = () => {
|
|
369
|
+
rotateSize += 1
|
|
370
|
+
this._setPreviewerTransform(scaleSize, rotateSize, x, y)
|
|
371
|
+
}
|
|
372
|
+
menuContainer.append(rotate)
|
|
373
|
+
// 恢复原始大小
|
|
374
|
+
const originalSize = document.createElement('i')
|
|
375
|
+
originalSize.classList.add('original-size')
|
|
376
|
+
originalSize.onclick = () => {
|
|
377
|
+
x = 0
|
|
378
|
+
y = 0
|
|
379
|
+
scaleSize = 1
|
|
380
|
+
rotateSize = 0
|
|
381
|
+
this._setPreviewerTransform(scaleSize, rotateSize, x, y)
|
|
382
|
+
}
|
|
383
|
+
menuContainer.append(originalSize)
|
|
384
|
+
// 下载图片
|
|
385
|
+
const imageDownload = document.createElement('i')
|
|
386
|
+
imageDownload.classList.add('image-download')
|
|
387
|
+
imageDownload.onclick = () => {
|
|
388
|
+
const { mime } = this.previewerDrawOption
|
|
389
|
+
downloadFile(img.src, `${this.curElement?.id}.${mime || 'png'}`)
|
|
390
|
+
}
|
|
391
|
+
menuContainer.append(imageDownload)
|
|
392
|
+
previewerContainer.append(menuContainer)
|
|
393
|
+
this.previewerContainer = previewerContainer
|
|
394
|
+
document.body.append(previewerContainer)
|
|
395
|
+
// 拖拽调整位置
|
|
396
|
+
let startX = 0
|
|
397
|
+
let startY = 0
|
|
398
|
+
let isAllowDrag = false
|
|
399
|
+
img.onmousedown = evt => {
|
|
400
|
+
isAllowDrag = true
|
|
401
|
+
startX = evt.x
|
|
402
|
+
startY = evt.y
|
|
403
|
+
previewerContainer.style.cursor = 'move'
|
|
404
|
+
}
|
|
405
|
+
previewerContainer.onmousemove = (evt: MouseEvent) => {
|
|
406
|
+
if (!isAllowDrag) return
|
|
407
|
+
x += evt.x - startX
|
|
408
|
+
y += evt.y - startY
|
|
409
|
+
startX = evt.x
|
|
410
|
+
startY = evt.y
|
|
411
|
+
this._setPreviewerTransform(scaleSize, rotateSize, x, y)
|
|
412
|
+
}
|
|
413
|
+
previewerContainer.onmouseup = () => {
|
|
414
|
+
isAllowDrag = false
|
|
415
|
+
previewerContainer.style.cursor = 'auto'
|
|
416
|
+
}
|
|
417
|
+
previewerContainer.onwheel = evt => {
|
|
418
|
+
evt.preventDefault()
|
|
419
|
+
evt.stopPropagation()
|
|
420
|
+
if (evt.deltaY < 0) {
|
|
421
|
+
// 放大
|
|
422
|
+
scaleSize += 0.1
|
|
423
|
+
} else {
|
|
424
|
+
// 缩小
|
|
425
|
+
if (scaleSize - 0.1 <= 0.1) return
|
|
426
|
+
scaleSize -= 0.1
|
|
427
|
+
}
|
|
428
|
+
this._setPreviewerTransform(scaleSize, rotateSize, x, y)
|
|
429
|
+
}
|
|
430
|
+
// 更新图片索引信息
|
|
431
|
+
this._updateImageNavigate()
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
private _updateImageNavigate() {
|
|
435
|
+
// 更新当前图片位置索引
|
|
436
|
+
const currentIndex = this.imageList.findIndex(
|
|
437
|
+
el => el.id === this.curShowElement?.id
|
|
438
|
+
)
|
|
439
|
+
this.imageCount!.innerText = `${currentIndex + 1} / ${
|
|
440
|
+
this.imageList.length
|
|
441
|
+
}`
|
|
442
|
+
// 更新按钮权限
|
|
443
|
+
if (currentIndex <= 0) {
|
|
444
|
+
this.imagePre!.classList.add('disabled')
|
|
445
|
+
} else {
|
|
446
|
+
this.imagePre!.classList.remove('disabled')
|
|
447
|
+
}
|
|
448
|
+
if (currentIndex >= this.imageList.length - 1) {
|
|
449
|
+
this.imageNext!.classList.add('disabled')
|
|
450
|
+
} else {
|
|
451
|
+
this.imageNext!.classList.remove('disabled')
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
public _setPreviewerTransform(
|
|
456
|
+
scale: number,
|
|
457
|
+
rotate: number,
|
|
458
|
+
x: number,
|
|
459
|
+
y: number
|
|
460
|
+
) {
|
|
461
|
+
if (!this.previewerImage) return
|
|
462
|
+
this.previewerImage.style.left = `${x}px`
|
|
463
|
+
this.previewerImage.style.top = `${y}px`
|
|
464
|
+
this.previewerImage.style.transform = `scale(${scale}) rotate(${
|
|
465
|
+
rotate * 90
|
|
466
|
+
}deg)`
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
private _clearPreviewer() {
|
|
470
|
+
this.previewerContainer?.remove()
|
|
471
|
+
this.previewerContainer = null
|
|
472
|
+
document.body.style.overflow = 'auto'
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
public _updateResizerRect(width: number, height: number) {
|
|
476
|
+
const { resizerSize: handleSize, scale } = this.options
|
|
477
|
+
const isReadonly = this.draw.isReadonly()
|
|
478
|
+
this.resizerSelection.style.width = `${width}px`
|
|
479
|
+
this.resizerSelection.style.height = `${height}px`
|
|
480
|
+
// handle
|
|
481
|
+
for (let i = 0; i < 8; i++) {
|
|
482
|
+
const left =
|
|
483
|
+
i === 0 || i === 6 || i === 7
|
|
484
|
+
? -handleSize
|
|
485
|
+
: i === 1 || i === 5
|
|
486
|
+
? width / 2
|
|
487
|
+
: width - handleSize
|
|
488
|
+
const top =
|
|
489
|
+
i === 0 || i === 1 || i === 2
|
|
490
|
+
? -handleSize
|
|
491
|
+
: i === 3 || i === 7
|
|
492
|
+
? height / 2 - handleSize
|
|
493
|
+
: height - handleSize
|
|
494
|
+
this.resizerHandleList[i].style.transform = `scale(${scale})`
|
|
495
|
+
this.resizerHandleList[i].style.left = `${left}px`
|
|
496
|
+
this.resizerHandleList[i].style.top = `${top}px`
|
|
497
|
+
this.resizerHandleList[i].style.display = isReadonly ? 'none' : 'block'
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
public _updateResizerSizeView(width: number, height: number) {
|
|
502
|
+
this.resizerSize.innerText = `${Math.round(width)} × ${Math.round(height)}`
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
public render() {
|
|
506
|
+
// 图片工具配置禁用又非设计模式时不渲染
|
|
507
|
+
const mode = this.draw.getMode()
|
|
508
|
+
if (
|
|
509
|
+
!this.curElement ||
|
|
510
|
+
(this.curElement.imgToolDisabled && !this.draw.isDesignMode()) ||
|
|
511
|
+
(mode === EditorMode.PRINT &&
|
|
512
|
+
this.options.modeRule[EditorMode.PRINT]?.imagePreviewerDisabled) ||
|
|
513
|
+
(mode === EditorMode.READONLY &&
|
|
514
|
+
this.options.modeRule[EditorMode.READONLY]?.imagePreviewerDisabled)
|
|
515
|
+
) {
|
|
516
|
+
return
|
|
517
|
+
}
|
|
518
|
+
// 获取所有图片
|
|
519
|
+
this.imageList = this.draw.getImageParticle().getOriginalMainImageList()
|
|
520
|
+
this.curShowElement = this.curElement
|
|
521
|
+
// 渲染预览框
|
|
522
|
+
this._drawPreviewer()
|
|
523
|
+
document.body.style.overflow = 'hidden'
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
public drawResizer(
|
|
527
|
+
element: IElement,
|
|
528
|
+
position: IElementPosition | null = null,
|
|
529
|
+
options: IPreviewerDrawOption = {}
|
|
530
|
+
) {
|
|
531
|
+
// 图片工具配置禁用又非设计模式时不渲染
|
|
532
|
+
const mode = this.draw.getMode()
|
|
533
|
+
if (
|
|
534
|
+
(element.imgToolDisabled && !this.draw.isDesignMode()) ||
|
|
535
|
+
(mode === EditorMode.PRINT &&
|
|
536
|
+
this.options.modeRule[EditorMode.PRINT]?.imagePreviewerDisabled) ||
|
|
537
|
+
(mode === EditorMode.READONLY &&
|
|
538
|
+
this.options.modeRule[EditorMode.READONLY]?.imagePreviewerDisabled)
|
|
539
|
+
) {
|
|
540
|
+
return
|
|
541
|
+
}
|
|
542
|
+
// 缓存配置
|
|
543
|
+
this.previewerDrawOption = options
|
|
544
|
+
this.curElementSrc = element[options.srcKey || 'value'] || ''
|
|
545
|
+
// 更新渲染尺寸及位置
|
|
546
|
+
this.updateResizer(element, position)
|
|
547
|
+
// 监听事件
|
|
548
|
+
document.addEventListener('keydown', this._keydown)
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
public updateResizer(
|
|
552
|
+
element: IElement,
|
|
553
|
+
position: IElementPosition | null = null
|
|
554
|
+
) {
|
|
555
|
+
const { scale } = this.options
|
|
556
|
+
const elementWidth = element.width! * scale
|
|
557
|
+
const elementHeight = element.height! * scale
|
|
558
|
+
// 尺寸预览
|
|
559
|
+
this._updateResizerSizeView(elementWidth, elementHeight)
|
|
560
|
+
// 优先使用浮动位置信息
|
|
561
|
+
const { x: resizerLeft, y: resizerTop } = this._getElementPosition(
|
|
562
|
+
element,
|
|
563
|
+
position
|
|
564
|
+
)
|
|
565
|
+
this.resizerSelection.style.left = `${resizerLeft}px`
|
|
566
|
+
this.resizerSelection.style.top = `${resizerTop}px`
|
|
567
|
+
this.resizerSelection.style.borderWidth = `${scale}px`
|
|
568
|
+
// 更新预览包围框尺寸
|
|
569
|
+
this._updateResizerRect(elementWidth, elementHeight)
|
|
570
|
+
this.resizerSelection.style.display = 'block'
|
|
571
|
+
// 缓存基础信息
|
|
572
|
+
this.curElement = element
|
|
573
|
+
this.curPosition = position
|
|
574
|
+
this.width = elementWidth
|
|
575
|
+
this.height = elementHeight
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
public clearResizer() {
|
|
579
|
+
this.resizerSelection.style.display = 'none'
|
|
580
|
+
document.removeEventListener('keydown', this._keydown)
|
|
581
|
+
}
|
|
582
|
+
}
|