ding-image-editor 3.15.3
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/README.md +193 -0
- package/dist/svg/icon-a.svg +376 -0
- package/dist/svg/icon-b.svg +369 -0
- package/dist/svg/icon-c.svg +369 -0
- package/dist/svg/icon-d.svg +369 -0
- package/dist/tui-image-editor.css +6 -0
- package/dist/tui-image-editor.js +62329 -0
- package/dist/tui-image-editor.min.css +5 -0
- package/dist/tui-image-editor.min.js +15 -0
- package/index.d.ts +334 -0
- package/package.json +52 -0
- package/src/css/buttons.styl +102 -0
- package/src/css/checkbox.styl +86 -0
- package/src/css/colorpicker.styl +98 -0
- package/src/css/gridtable.styl +45 -0
- package/src/css/icon.styl +44 -0
- package/src/css/index.styl +17 -0
- package/src/css/main.styl +163 -0
- package/src/css/position.styl +309 -0
- package/src/css/range.styl +91 -0
- package/src/css/submenu.styl +168 -0
- package/src/index.js +29 -0
- package/src/js/action.js +686 -0
- package/src/js/command/addIcon.js +42 -0
- package/src/js/command/addImageObject.js +34 -0
- package/src/js/command/addObject.js +43 -0
- package/src/js/command/addShape.js +51 -0
- package/src/js/command/addText.js +73 -0
- package/src/js/command/applyFilter.js +95 -0
- package/src/js/command/changeIconColor.js +48 -0
- package/src/js/command/changeSelection.js +31 -0
- package/src/js/command/changeShape.js +84 -0
- package/src/js/command/changeText.js +44 -0
- package/src/js/command/changeTextStyle.js +80 -0
- package/src/js/command/clearObjects.js +33 -0
- package/src/js/command/flip.js +36 -0
- package/src/js/command/loadImage.js +58 -0
- package/src/js/command/removeFilter.js +38 -0
- package/src/js/command/removeObject.js +37 -0
- package/src/js/command/resize.js +41 -0
- package/src/js/command/resizeCanvasDimension.js +40 -0
- package/src/js/command/rotate.js +64 -0
- package/src/js/command/setObjectPosition.js +50 -0
- package/src/js/command/setObjectProperties.js +55 -0
- package/src/js/component/cropper.js +407 -0
- package/src/js/component/filter.js +229 -0
- package/src/js/component/flip.js +146 -0
- package/src/js/component/freeDrawing.js +144 -0
- package/src/js/component/icon.js +246 -0
- package/src/js/component/imageLoader.js +84 -0
- package/src/js/component/line.js +205 -0
- package/src/js/component/resize.js +103 -0
- package/src/js/component/rotation.js +91 -0
- package/src/js/component/shape.js +601 -0
- package/src/js/component/text.js +572 -0
- package/src/js/component/zoom.js +708 -0
- package/src/js/consts.js +404 -0
- package/src/js/drawingMode/cropper.js +35 -0
- package/src/js/drawingMode/freeDrawing.js +36 -0
- package/src/js/drawingMode/icon.js +35 -0
- package/src/js/drawingMode/lineDrawing.js +36 -0
- package/src/js/drawingMode/resize.js +35 -0
- package/src/js/drawingMode/shape.js +35 -0
- package/src/js/drawingMode/text.js +35 -0
- package/src/js/drawingMode/zoom.js +37 -0
- package/src/js/extension/arrowLine.js +172 -0
- package/src/js/extension/blur.js +29 -0
- package/src/js/extension/colorFilter.js +104 -0
- package/src/js/extension/cropzone.js +568 -0
- package/src/js/extension/emboss.js +29 -0
- package/src/js/extension/mask.js +90 -0
- package/src/js/extension/sharpen.js +29 -0
- package/src/js/factory/command.js +36 -0
- package/src/js/factory/errorMessage.js +27 -0
- package/src/js/graphics.js +1539 -0
- package/src/js/helper/imagetracer.js +1396 -0
- package/src/js/helper/selectionModifyHelper.js +86 -0
- package/src/js/helper/shapeFilterFillHelper.js +564 -0
- package/src/js/helper/shapeResizeHelper.js +237 -0
- package/src/js/imageEditor.js +1795 -0
- package/src/js/interface/command.js +131 -0
- package/src/js/interface/component.js +127 -0
- package/src/js/interface/drawingMode.js +47 -0
- package/src/js/invoker.js +292 -0
- package/src/js/polyfill.js +498 -0
- package/src/js/ui/crop.js +139 -0
- package/src/js/ui/draw.js +187 -0
- package/src/js/ui/filter.js +510 -0
- package/src/js/ui/flip.js +87 -0
- package/src/js/ui/history.js +171 -0
- package/src/js/ui/icon.js +191 -0
- package/src/js/ui/locale/locale.js +19 -0
- package/src/js/ui/mask.js +96 -0
- package/src/js/ui/panelMenu.js +130 -0
- package/src/js/ui/resize.js +241 -0
- package/src/js/ui/rotate.js +123 -0
- package/src/js/ui/shape.js +265 -0
- package/src/js/ui/submenuBase.js +122 -0
- package/src/js/ui/template/controls.js +21 -0
- package/src/js/ui/template/mainContainer.js +38 -0
- package/src/js/ui/template/style.js +146 -0
- package/src/js/ui/template/submenu/crop.js +73 -0
- package/src/js/ui/template/submenu/draw.js +42 -0
- package/src/js/ui/template/submenu/filter.js +157 -0
- package/src/js/ui/template/submenu/flip.js +41 -0
- package/src/js/ui/template/submenu/history.js +22 -0
- package/src/js/ui/template/submenu/icon.js +108 -0
- package/src/js/ui/template/submenu/mask.js +30 -0
- package/src/js/ui/template/submenu/resize.js +54 -0
- package/src/js/ui/template/submenu/rotate.js +32 -0
- package/src/js/ui/template/submenu/shape.js +45 -0
- package/src/js/ui/template/submenu/text.js +67 -0
- package/src/js/ui/template/submenu/zoom.js +41 -0
- package/src/js/ui/text.js +279 -0
- package/src/js/ui/theme/standard.js +220 -0
- package/src/js/ui/theme/theme.js +249 -0
- package/src/js/ui/tools/colorpicker.js +250 -0
- package/src/js/ui/tools/range.js +390 -0
- package/src/js/ui.js +858 -0
- package/src/js/util.js +551 -0
- package/src/svg/default.svg +335 -0
- package/src/svg/icon-a/ic-apply.svg +6 -0
- package/src/svg/icon-a/ic-cancel.svg +6 -0
- package/src/svg/icon-a/ic-color-transparent-w.svg +12 -0
- package/src/svg/icon-a/ic-crop.svg +7 -0
- package/src/svg/icon-a/ic-delete-all.svg +6 -0
- package/src/svg/icon-a/ic-delete.svg +6 -0
- package/src/svg/icon-a/ic-draw-free.svg +5 -0
- package/src/svg/icon-a/ic-draw-line.svg +5 -0
- package/src/svg/icon-a/ic-draw.svg +6 -0
- package/src/svg/icon-a/ic-filter.svg +7 -0
- package/src/svg/icon-a/ic-flip-reset.svg +7 -0
- package/src/svg/icon-a/ic-flip-x.svg +6 -0
- package/src/svg/icon-a/ic-flip-y.svg +6 -0
- package/src/svg/icon-a/ic-flip.svg +6 -0
- package/src/svg/icon-a/ic-history-check.svg +5 -0
- package/src/svg/icon-a/ic-history-crop.svg +7 -0
- package/src/svg/icon-a/ic-history-delete.svg +9 -0
- package/src/svg/icon-a/ic-history-draw.svg +7 -0
- package/src/svg/icon-a/ic-history-filter.svg +8 -0
- package/src/svg/icon-a/ic-history-flip.svg +6 -0
- package/src/svg/icon-a/ic-history-group.svg +9 -0
- package/src/svg/icon-a/ic-history-icon.svg +6 -0
- package/src/svg/icon-a/ic-history-load.svg +7 -0
- package/src/svg/icon-a/ic-history-mask.svg +9 -0
- package/src/svg/icon-a/ic-history-resize.svg +12 -0
- package/src/svg/icon-a/ic-history-rotate.svg +16 -0
- package/src/svg/icon-a/ic-history-shape.svg +7 -0
- package/src/svg/icon-a/ic-history-text.svg +8 -0
- package/src/svg/icon-a/ic-history.svg +6 -0
- package/src/svg/icon-a/ic-icon-arrow-2.svg +5 -0
- package/src/svg/icon-a/ic-icon-arrow-3.svg +5 -0
- package/src/svg/icon-a/ic-icon-arrow.svg +5 -0
- package/src/svg/icon-a/ic-icon-bubble.svg +5 -0
- package/src/svg/icon-a/ic-icon-heart.svg +5 -0
- package/src/svg/icon-a/ic-icon-load.svg +8 -0
- package/src/svg/icon-a/ic-icon-location.svg +8 -0
- package/src/svg/icon-a/ic-icon-polygon.svg +5 -0
- package/src/svg/icon-a/ic-icon-star-2.svg +5 -0
- package/src/svg/icon-a/ic-icon-star.svg +5 -0
- package/src/svg/icon-a/ic-icon.svg +5 -0
- package/src/svg/icon-a/ic-mask-load.svg +8 -0
- package/src/svg/icon-a/ic-mask.svg +6 -0
- package/src/svg/icon-a/ic-redo.svg +7 -0
- package/src/svg/icon-a/ic-reset.svg +7 -0
- package/src/svg/icon-a/ic-resize.svg +13 -0
- package/src/svg/icon-a/ic-rotate-clockwise.svg +7 -0
- package/src/svg/icon-a/ic-rotate-counterclockwise.svg +7 -0
- package/src/svg/icon-a/ic-rotate.svg +7 -0
- package/src/svg/icon-a/ic-shape-circle.svg +5 -0
- package/src/svg/icon-a/ic-shape-rectangle.svg +5 -0
- package/src/svg/icon-a/ic-shape-triangle.svg +5 -0
- package/src/svg/icon-a/ic-shape.svg +6 -0
- package/src/svg/icon-a/ic-text-align-center.svg +6 -0
- package/src/svg/icon-a/ic-text-align-left.svg +6 -0
- package/src/svg/icon-a/ic-text-align-right.svg +6 -0
- package/src/svg/icon-a/ic-text-bold.svg +7 -0
- package/src/svg/icon-a/ic-text-italic.svg +6 -0
- package/src/svg/icon-a/ic-text-underline.svg +7 -0
- package/src/svg/icon-a/ic-text.svg +7 -0
- package/src/svg/icon-a/ic-undo.svg +7 -0
- package/src/svg/icon-a/ic-zoom-hand.svg +8 -0
- package/src/svg/icon-a/ic-zoom-zoom-in.svg +10 -0
- package/src/svg/icon-a/ic-zoom-zoom-out.svg +9 -0
- package/src/svg/icon-a/img-bi.svg +5 -0
- package/src/svg/icon-b/ic-apply.svg +6 -0
- package/src/svg/icon-b/ic-cancel.svg +6 -0
- package/src/svg/icon-b/ic-crop.svg +7 -0
- package/src/svg/icon-b/ic-delete-all.svg +6 -0
- package/src/svg/icon-b/ic-delete.svg +6 -0
- package/src/svg/icon-b/ic-draw-free.svg +5 -0
- package/src/svg/icon-b/ic-draw-line.svg +5 -0
- package/src/svg/icon-b/ic-draw.svg +6 -0
- package/src/svg/icon-b/ic-filter.svg +7 -0
- package/src/svg/icon-b/ic-flip-reset.svg +7 -0
- package/src/svg/icon-b/ic-flip-x.svg +6 -0
- package/src/svg/icon-b/ic-flip-y.svg +6 -0
- package/src/svg/icon-b/ic-flip.svg +6 -0
- package/src/svg/icon-b/ic-history-check.svg +5 -0
- package/src/svg/icon-b/ic-history-crop.svg +7 -0
- package/src/svg/icon-b/ic-history-delete.svg +9 -0
- package/src/svg/icon-b/ic-history-draw.svg +7 -0
- package/src/svg/icon-b/ic-history-filter.svg +8 -0
- package/src/svg/icon-b/ic-history-flip.svg +6 -0
- package/src/svg/icon-b/ic-history-group.svg +9 -0
- package/src/svg/icon-b/ic-history-icon.svg +6 -0
- package/src/svg/icon-b/ic-history-load.svg +7 -0
- package/src/svg/icon-b/ic-history-mask.svg +9 -0
- package/src/svg/icon-b/ic-history-resize.svg +12 -0
- package/src/svg/icon-b/ic-history-rotate.svg +16 -0
- package/src/svg/icon-b/ic-history-shape.svg +7 -0
- package/src/svg/icon-b/ic-history-text.svg +8 -0
- package/src/svg/icon-b/ic-history.svg +6 -0
- package/src/svg/icon-b/ic-icon-arrow-2.svg +5 -0
- package/src/svg/icon-b/ic-icon-arrow-3.svg +5 -0
- package/src/svg/icon-b/ic-icon-arrow.svg +5 -0
- package/src/svg/icon-b/ic-icon-bubble.svg +5 -0
- package/src/svg/icon-b/ic-icon-heart.svg +5 -0
- package/src/svg/icon-b/ic-icon-load.svg +8 -0
- package/src/svg/icon-b/ic-icon-location.svg +8 -0
- package/src/svg/icon-b/ic-icon-polygon.svg +5 -0
- package/src/svg/icon-b/ic-icon-star-2.svg +5 -0
- package/src/svg/icon-b/ic-icon-star.svg +5 -0
- package/src/svg/icon-b/ic-icon.svg +5 -0
- package/src/svg/icon-b/ic-mask-load.svg +8 -0
- package/src/svg/icon-b/ic-mask.svg +6 -0
- package/src/svg/icon-b/ic-redo.svg +7 -0
- package/src/svg/icon-b/ic-reset.svg +7 -0
- package/src/svg/icon-b/ic-resize.svg +13 -0
- package/src/svg/icon-b/ic-rotate-clockwise.svg +7 -0
- package/src/svg/icon-b/ic-rotate-counterclockwise.svg +7 -0
- package/src/svg/icon-b/ic-rotate.svg +7 -0
- package/src/svg/icon-b/ic-shape-circle.svg +5 -0
- package/src/svg/icon-b/ic-shape-rectangle.svg +5 -0
- package/src/svg/icon-b/ic-shape-triangle.svg +5 -0
- package/src/svg/icon-b/ic-shape.svg +6 -0
- package/src/svg/icon-b/ic-text-align-center.svg +6 -0
- package/src/svg/icon-b/ic-text-align-left.svg +6 -0
- package/src/svg/icon-b/ic-text-align-right.svg +6 -0
- package/src/svg/icon-b/ic-text-bold.svg +7 -0
- package/src/svg/icon-b/ic-text-italic.svg +6 -0
- package/src/svg/icon-b/ic-text-underline.svg +7 -0
- package/src/svg/icon-b/ic-text.svg +7 -0
- package/src/svg/icon-b/ic-undo.svg +7 -0
- package/src/svg/icon-b/ic-zoom-hand.svg +8 -0
- package/src/svg/icon-b/ic-zoom-zoom-in.svg +12 -0
- package/src/svg/icon-b/ic-zoom-zoom-out.svg +11 -0
- package/src/svg/icon-b/img-bi.svg +5 -0
- package/src/svg/icon-c/ic-apply.svg +6 -0
- package/src/svg/icon-c/ic-cancel.svg +6 -0
- package/src/svg/icon-c/ic-crop.svg +7 -0
- package/src/svg/icon-c/ic-delete-all.svg +6 -0
- package/src/svg/icon-c/ic-delete.svg +6 -0
- package/src/svg/icon-c/ic-draw-free.svg +5 -0
- package/src/svg/icon-c/ic-draw-line.svg +5 -0
- package/src/svg/icon-c/ic-draw.svg +6 -0
- package/src/svg/icon-c/ic-filter.svg +7 -0
- package/src/svg/icon-c/ic-flip-reset.svg +7 -0
- package/src/svg/icon-c/ic-flip-x.svg +6 -0
- package/src/svg/icon-c/ic-flip-y.svg +6 -0
- package/src/svg/icon-c/ic-flip.svg +6 -0
- package/src/svg/icon-c/ic-history-check.svg +5 -0
- package/src/svg/icon-c/ic-history-crop.svg +7 -0
- package/src/svg/icon-c/ic-history-delete.svg +9 -0
- package/src/svg/icon-c/ic-history-draw.svg +7 -0
- package/src/svg/icon-c/ic-history-filter.svg +8 -0
- package/src/svg/icon-c/ic-history-flip.svg +6 -0
- package/src/svg/icon-c/ic-history-group.svg +9 -0
- package/src/svg/icon-c/ic-history-icon.svg +6 -0
- package/src/svg/icon-c/ic-history-load.svg +7 -0
- package/src/svg/icon-c/ic-history-mask.svg +9 -0
- package/src/svg/icon-c/ic-history-resize.svg +12 -0
- package/src/svg/icon-c/ic-history-rotate.svg +16 -0
- package/src/svg/icon-c/ic-history-shape.svg +7 -0
- package/src/svg/icon-c/ic-history-text.svg +8 -0
- package/src/svg/icon-c/ic-history.svg +6 -0
- package/src/svg/icon-c/ic-icon-arrow-2.svg +5 -0
- package/src/svg/icon-c/ic-icon-arrow-3.svg +5 -0
- package/src/svg/icon-c/ic-icon-arrow.svg +5 -0
- package/src/svg/icon-c/ic-icon-bubble.svg +5 -0
- package/src/svg/icon-c/ic-icon-heart.svg +5 -0
- package/src/svg/icon-c/ic-icon-load.svg +8 -0
- package/src/svg/icon-c/ic-icon-location.svg +8 -0
- package/src/svg/icon-c/ic-icon-polygon.svg +5 -0
- package/src/svg/icon-c/ic-icon-star-2.svg +5 -0
- package/src/svg/icon-c/ic-icon-star.svg +5 -0
- package/src/svg/icon-c/ic-icon.svg +5 -0
- package/src/svg/icon-c/ic-mask-load.svg +8 -0
- package/src/svg/icon-c/ic-mask.svg +6 -0
- package/src/svg/icon-c/ic-redo.svg +7 -0
- package/src/svg/icon-c/ic-reset.svg +7 -0
- package/src/svg/icon-c/ic-resize.svg +13 -0
- package/src/svg/icon-c/ic-rotate-clockwise.svg +7 -0
- package/src/svg/icon-c/ic-rotate-counterclockwise.svg +7 -0
- package/src/svg/icon-c/ic-rotate.svg +7 -0
- package/src/svg/icon-c/ic-shape-circle.svg +5 -0
- package/src/svg/icon-c/ic-shape-rectangle.svg +5 -0
- package/src/svg/icon-c/ic-shape-triangle.svg +5 -0
- package/src/svg/icon-c/ic-shape.svg +6 -0
- package/src/svg/icon-c/ic-text-align-center.svg +6 -0
- package/src/svg/icon-c/ic-text-align-left.svg +6 -0
- package/src/svg/icon-c/ic-text-align-right.svg +6 -0
- package/src/svg/icon-c/ic-text-bold.svg +7 -0
- package/src/svg/icon-c/ic-text-italic.svg +6 -0
- package/src/svg/icon-c/ic-text-underline.svg +7 -0
- package/src/svg/icon-c/ic-text.svg +7 -0
- package/src/svg/icon-c/ic-undo.svg +7 -0
- package/src/svg/icon-c/ic-zoom-hand.svg +8 -0
- package/src/svg/icon-c/ic-zoom-zoom-in.svg +12 -0
- package/src/svg/icon-c/ic-zoom-zoom-out.svg +11 -0
- package/src/svg/icon-c/img-bi.svg +5 -0
- package/src/svg/icon-d/ic-apply.svg +6 -0
- package/src/svg/icon-d/ic-cancel.svg +6 -0
- package/src/svg/icon-d/ic-crop.svg +7 -0
- package/src/svg/icon-d/ic-delete-all.svg +6 -0
- package/src/svg/icon-d/ic-delete.svg +6 -0
- package/src/svg/icon-d/ic-draw-free.svg +5 -0
- package/src/svg/icon-d/ic-draw-line.svg +5 -0
- package/src/svg/icon-d/ic-draw.svg +6 -0
- package/src/svg/icon-d/ic-filter.svg +7 -0
- package/src/svg/icon-d/ic-flip-reset.svg +7 -0
- package/src/svg/icon-d/ic-flip-x.svg +6 -0
- package/src/svg/icon-d/ic-flip-y.svg +6 -0
- package/src/svg/icon-d/ic-flip.svg +6 -0
- package/src/svg/icon-d/ic-history-check.svg +5 -0
- package/src/svg/icon-d/ic-history-crop.svg +7 -0
- package/src/svg/icon-d/ic-history-delete.svg +9 -0
- package/src/svg/icon-d/ic-history-draw.svg +7 -0
- package/src/svg/icon-d/ic-history-filter.svg +8 -0
- package/src/svg/icon-d/ic-history-flip.svg +6 -0
- package/src/svg/icon-d/ic-history-group.svg +9 -0
- package/src/svg/icon-d/ic-history-icon.svg +6 -0
- package/src/svg/icon-d/ic-history-load.svg +7 -0
- package/src/svg/icon-d/ic-history-mask.svg +9 -0
- package/src/svg/icon-d/ic-history-resize.svg +12 -0
- package/src/svg/icon-d/ic-history-rotate.svg +16 -0
- package/src/svg/icon-d/ic-history-shape.svg +7 -0
- package/src/svg/icon-d/ic-history-text.svg +8 -0
- package/src/svg/icon-d/ic-history.svg +6 -0
- package/src/svg/icon-d/ic-icon-arrow-2.svg +5 -0
- package/src/svg/icon-d/ic-icon-arrow-3.svg +5 -0
- package/src/svg/icon-d/ic-icon-arrow.svg +5 -0
- package/src/svg/icon-d/ic-icon-bubble.svg +5 -0
- package/src/svg/icon-d/ic-icon-heart.svg +5 -0
- package/src/svg/icon-d/ic-icon-load.svg +8 -0
- package/src/svg/icon-d/ic-icon-location.svg +8 -0
- package/src/svg/icon-d/ic-icon-polygon.svg +5 -0
- package/src/svg/icon-d/ic-icon-star-2.svg +5 -0
- package/src/svg/icon-d/ic-icon-star.svg +5 -0
- package/src/svg/icon-d/ic-icon.svg +5 -0
- package/src/svg/icon-d/ic-mask-load.svg +8 -0
- package/src/svg/icon-d/ic-mask.svg +6 -0
- package/src/svg/icon-d/ic-redo.svg +7 -0
- package/src/svg/icon-d/ic-reset.svg +7 -0
- package/src/svg/icon-d/ic-resize.svg +13 -0
- package/src/svg/icon-d/ic-rotate-clockwise.svg +7 -0
- package/src/svg/icon-d/ic-rotate-counterclockwise.svg +7 -0
- package/src/svg/icon-d/ic-rotate.svg +7 -0
- package/src/svg/icon-d/ic-shape-circle.svg +5 -0
- package/src/svg/icon-d/ic-shape-rectangle.svg +5 -0
- package/src/svg/icon-d/ic-shape-triangle.svg +5 -0
- package/src/svg/icon-d/ic-shape.svg +6 -0
- package/src/svg/icon-d/ic-text-align-center.svg +6 -0
- package/src/svg/icon-d/ic-text-align-left.svg +6 -0
- package/src/svg/icon-d/ic-text-align-right.svg +6 -0
- package/src/svg/icon-d/ic-text-bold.svg +7 -0
- package/src/svg/icon-d/ic-text-italic.svg +6 -0
- package/src/svg/icon-d/ic-text-underline.svg +7 -0
- package/src/svg/icon-d/ic-text.svg +7 -0
- package/src/svg/icon-d/ic-undo.svg +7 -0
- package/src/svg/icon-d/ic-zoom-hand.svg +8 -0
- package/src/svg/icon-d/ic-zoom-zoom-in.svg +12 -0
- package/src/svg/icon-d/ic-zoom-zoom-out.svg +11 -0
- package/src/svg/icon-d/img-bi.svg +5 -0
@@ -0,0 +1,708 @@
|
|
1
|
+
import { fabric } from 'fabric';
|
2
|
+
import Component from '@/interface/component';
|
3
|
+
import { clamp } from '@/util';
|
4
|
+
import { componentNames, eventNames, keyCodes, zoomModes } from '@/consts';
|
5
|
+
|
6
|
+
const MOUSE_MOVE_THRESHOLD = 10;
|
7
|
+
const DEFAULT_SCROLL_OPTION = {
|
8
|
+
left: 0,
|
9
|
+
top: 0,
|
10
|
+
width: 0,
|
11
|
+
height: 0,
|
12
|
+
stroke: '#000000',
|
13
|
+
strokeWidth: 0,
|
14
|
+
fill: '#000000',
|
15
|
+
opacity: 0.4,
|
16
|
+
evented: false,
|
17
|
+
selectable: false,
|
18
|
+
hoverCursor: 'auto',
|
19
|
+
};
|
20
|
+
const DEFAULT_VERTICAL_SCROLL_RATIO = {
|
21
|
+
SIZE: 0.0045,
|
22
|
+
MARGIN: 0.003,
|
23
|
+
BORDER_RADIUS: 0.003,
|
24
|
+
};
|
25
|
+
const DEFAULT_HORIZONTAL_SCROLL_RATIO = {
|
26
|
+
SIZE: 0.0066,
|
27
|
+
MARGIN: 0.0044,
|
28
|
+
BORDER_RADIUS: 0.003,
|
29
|
+
};
|
30
|
+
const DEFAULT_ZOOM_LEVEL = 1.0;
|
31
|
+
const {
|
32
|
+
ZOOM_CHANGED,
|
33
|
+
ADD_TEXT,
|
34
|
+
TEXT_EDITING,
|
35
|
+
OBJECT_MODIFIED,
|
36
|
+
KEY_DOWN,
|
37
|
+
KEY_UP,
|
38
|
+
HAND_STARTED,
|
39
|
+
HAND_STOPPED,
|
40
|
+
} = eventNames;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Zoom components
|
44
|
+
* @param {Graphics} graphics - Graphics instance
|
45
|
+
* @extends {Component}
|
46
|
+
* @class Zoom
|
47
|
+
* @ignore
|
48
|
+
*/
|
49
|
+
class Zoom extends Component {
|
50
|
+
constructor(graphics) {
|
51
|
+
super(componentNames.ZOOM, graphics);
|
52
|
+
|
53
|
+
/**
|
54
|
+
* zoomArea
|
55
|
+
* @type {?fabric.Rect}
|
56
|
+
* @private
|
57
|
+
*/
|
58
|
+
this.zoomArea = null;
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Start point of zoom area
|
62
|
+
* @type {?{x: number, y: number}}
|
63
|
+
*/
|
64
|
+
this._startPoint = null;
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Center point of every zoom
|
68
|
+
* @type {Array.<{prevZoomLevel: number, zoomLevel: number, x: number, y: number}>}
|
69
|
+
*/
|
70
|
+
this._centerPoints = [];
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Zoom level (default: 100%(1.0), max: 400%(4.0))
|
74
|
+
* @type {number}
|
75
|
+
*/
|
76
|
+
this.zoomLevel = DEFAULT_ZOOM_LEVEL;
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Zoom mode ('normal', 'zoom', 'hand')
|
80
|
+
* @type {string}
|
81
|
+
*/
|
82
|
+
this.zoomMode = zoomModes.DEFAULT;
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Listeners
|
86
|
+
* @type {Object.<string, Function>}
|
87
|
+
* @private
|
88
|
+
*/
|
89
|
+
this._listeners = {
|
90
|
+
startZoom: this._onMouseDownWithZoomMode.bind(this),
|
91
|
+
moveZoom: this._onMouseMoveWithZoomMode.bind(this),
|
92
|
+
stopZoom: this._onMouseUpWithZoomMode.bind(this),
|
93
|
+
startHand: this._onMouseDownWithHandMode.bind(this),
|
94
|
+
moveHand: this._onMouseMoveWithHandMode.bind(this),
|
95
|
+
stopHand: this._onMouseUpWithHandMode.bind(this),
|
96
|
+
zoomChanged: this._changeScrollState.bind(this),
|
97
|
+
keydown: this._startHandModeWithSpaceBar.bind(this),
|
98
|
+
keyup: this._endHandModeWithSpaceBar.bind(this),
|
99
|
+
};
|
100
|
+
|
101
|
+
const canvas = this.getCanvas();
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Width:Height ratio (ex. width=1.5, height=1 -> aspectRatio=1.5)
|
105
|
+
* @private
|
106
|
+
*/
|
107
|
+
this.aspectRatio = canvas.width / canvas.height;
|
108
|
+
|
109
|
+
/**
|
110
|
+
* vertical scroll bar
|
111
|
+
* @type {fabric.Rect}
|
112
|
+
* @private
|
113
|
+
*/
|
114
|
+
this._verticalScroll = new fabric.Rect(DEFAULT_SCROLL_OPTION);
|
115
|
+
|
116
|
+
/**
|
117
|
+
* horizontal scroll bar
|
118
|
+
* @type {fabric.Rect}
|
119
|
+
* @private
|
120
|
+
*/
|
121
|
+
this._horizontalScroll = new fabric.Rect(DEFAULT_SCROLL_OPTION);
|
122
|
+
|
123
|
+
canvas.on(ZOOM_CHANGED, this._listeners.zoomChanged);
|
124
|
+
|
125
|
+
this.graphics.on(ADD_TEXT, this._startTextEditingHandler.bind(this));
|
126
|
+
this.graphics.on(TEXT_EDITING, this._startTextEditingHandler.bind(this));
|
127
|
+
this.graphics.on(OBJECT_MODIFIED, this._stopTextEditingHandler.bind(this));
|
128
|
+
}
|
129
|
+
|
130
|
+
/**
|
131
|
+
* Attach zoom keyboard events
|
132
|
+
*/
|
133
|
+
attachKeyboardZoomEvents() {
|
134
|
+
fabric.util.addListener(document, KEY_DOWN, this._listeners.keydown);
|
135
|
+
fabric.util.addListener(document, KEY_UP, this._listeners.keyup);
|
136
|
+
}
|
137
|
+
|
138
|
+
/**
|
139
|
+
* Detach zoom keyboard events
|
140
|
+
*/
|
141
|
+
detachKeyboardZoomEvents() {
|
142
|
+
fabric.util.removeListener(document, KEY_DOWN, this._listeners.keydown);
|
143
|
+
fabric.util.removeListener(document, KEY_UP, this._listeners.keyup);
|
144
|
+
}
|
145
|
+
|
146
|
+
/**
|
147
|
+
* Handler when you started editing text
|
148
|
+
* @private
|
149
|
+
*/
|
150
|
+
_startTextEditingHandler() {
|
151
|
+
this.isTextEditing = true;
|
152
|
+
}
|
153
|
+
|
154
|
+
/**
|
155
|
+
* Handler when you stopped editing text
|
156
|
+
* @private
|
157
|
+
*/
|
158
|
+
_stopTextEditingHandler() {
|
159
|
+
this.isTextEditing = false;
|
160
|
+
}
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Handler who turns on hand mode when the space bar is down
|
164
|
+
* @param {KeyboardEvent} e - Event object
|
165
|
+
* @private
|
166
|
+
*/
|
167
|
+
_startHandModeWithSpaceBar(e) {
|
168
|
+
if (this.withSpace || this.isTextEditing) {
|
169
|
+
return;
|
170
|
+
}
|
171
|
+
|
172
|
+
if (e.keyCode === keyCodes.SPACE) {
|
173
|
+
this.withSpace = true;
|
174
|
+
this.startHandMode();
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
/**
|
179
|
+
* Handler who turns off hand mode when space bar is up
|
180
|
+
* @param {KeyboardEvent} e - Event object
|
181
|
+
* @private
|
182
|
+
*/
|
183
|
+
_endHandModeWithSpaceBar(e) {
|
184
|
+
if (e.keyCode === keyCodes.SPACE) {
|
185
|
+
this.withSpace = false;
|
186
|
+
this.endHandMode();
|
187
|
+
}
|
188
|
+
}
|
189
|
+
|
190
|
+
/**
|
191
|
+
* Start zoom-in mode
|
192
|
+
*/
|
193
|
+
startZoomInMode() {
|
194
|
+
if (this.zoomArea) {
|
195
|
+
return;
|
196
|
+
}
|
197
|
+
this.endHandMode();
|
198
|
+
this.zoomMode = zoomModes.ZOOM;
|
199
|
+
|
200
|
+
const canvas = this.getCanvas();
|
201
|
+
|
202
|
+
this._changeObjectsEventedState(false);
|
203
|
+
|
204
|
+
this.zoomArea = new fabric.Rect({
|
205
|
+
left: 0,
|
206
|
+
top: 0,
|
207
|
+
width: 0.5,
|
208
|
+
height: 0.5,
|
209
|
+
stroke: 'black',
|
210
|
+
strokeWidth: 1,
|
211
|
+
fill: 'transparent',
|
212
|
+
hoverCursor: 'zoom-in',
|
213
|
+
});
|
214
|
+
|
215
|
+
canvas.discardActiveObject();
|
216
|
+
canvas.add(this.zoomArea);
|
217
|
+
canvas.on('mouse:down', this._listeners.startZoom);
|
218
|
+
canvas.selection = false;
|
219
|
+
canvas.defaultCursor = 'zoom-in';
|
220
|
+
}
|
221
|
+
|
222
|
+
/**
|
223
|
+
* End zoom-in mode
|
224
|
+
*/
|
225
|
+
endZoomInMode() {
|
226
|
+
this.zoomMode = zoomModes.DEFAULT;
|
227
|
+
|
228
|
+
const canvas = this.getCanvas();
|
229
|
+
const { startZoom, moveZoom, stopZoom } = this._listeners;
|
230
|
+
|
231
|
+
canvas.selection = true;
|
232
|
+
canvas.defaultCursor = 'auto';
|
233
|
+
canvas.off({
|
234
|
+
'mouse:down': startZoom,
|
235
|
+
'mouse:move': moveZoom,
|
236
|
+
'mouse:up': stopZoom,
|
237
|
+
});
|
238
|
+
|
239
|
+
this._changeObjectsEventedState(true);
|
240
|
+
|
241
|
+
canvas.remove(this.zoomArea);
|
242
|
+
this.zoomArea = null;
|
243
|
+
}
|
244
|
+
|
245
|
+
/**
|
246
|
+
* Start zoom drawing mode
|
247
|
+
*/
|
248
|
+
start() {
|
249
|
+
this.zoomArea = null;
|
250
|
+
this._startPoint = null;
|
251
|
+
this._startHandPoint = null;
|
252
|
+
}
|
253
|
+
|
254
|
+
/**
|
255
|
+
* Stop zoom drawing mode
|
256
|
+
*/
|
257
|
+
end() {
|
258
|
+
this.endZoomInMode();
|
259
|
+
this.endHandMode();
|
260
|
+
}
|
261
|
+
|
262
|
+
/**
|
263
|
+
* Start hand mode
|
264
|
+
*/
|
265
|
+
startHandMode() {
|
266
|
+
this.endZoomInMode();
|
267
|
+
this.zoomMode = zoomModes.HAND;
|
268
|
+
|
269
|
+
const canvas = this.getCanvas();
|
270
|
+
|
271
|
+
this._changeObjectsEventedState(false);
|
272
|
+
|
273
|
+
canvas.discardActiveObject();
|
274
|
+
canvas.off('mouse:down', this._listeners.startHand);
|
275
|
+
canvas.on('mouse:down', this._listeners.startHand);
|
276
|
+
canvas.selection = false;
|
277
|
+
canvas.defaultCursor = 'grab';
|
278
|
+
|
279
|
+
canvas.fire(HAND_STARTED);
|
280
|
+
}
|
281
|
+
|
282
|
+
/**
|
283
|
+
* Stop hand mode
|
284
|
+
*/
|
285
|
+
endHandMode() {
|
286
|
+
this.zoomMode = zoomModes.DEFAULT;
|
287
|
+
const canvas = this.getCanvas();
|
288
|
+
|
289
|
+
this._changeObjectsEventedState(true);
|
290
|
+
|
291
|
+
canvas.off('mouse:down', this._listeners.startHand);
|
292
|
+
canvas.selection = true;
|
293
|
+
canvas.defaultCursor = 'auto';
|
294
|
+
|
295
|
+
this._startHandPoint = null;
|
296
|
+
|
297
|
+
canvas.fire(HAND_STOPPED);
|
298
|
+
}
|
299
|
+
|
300
|
+
/**
|
301
|
+
* onMousedown handler in fabric canvas
|
302
|
+
* @param {{target: fabric.Object, e: MouseEvent}} fEvent - Fabric event
|
303
|
+
* @private
|
304
|
+
*/
|
305
|
+
_onMouseDownWithZoomMode({ target, e }) {
|
306
|
+
if (target) {
|
307
|
+
return;
|
308
|
+
}
|
309
|
+
|
310
|
+
const canvas = this.getCanvas();
|
311
|
+
|
312
|
+
canvas.selection = false;
|
313
|
+
|
314
|
+
this._startPoint = canvas.getPointer(e);
|
315
|
+
this.zoomArea.set({ width: 0, height: 0 });
|
316
|
+
|
317
|
+
const { moveZoom, stopZoom } = this._listeners;
|
318
|
+
canvas.on({
|
319
|
+
'mouse:move': moveZoom,
|
320
|
+
'mouse:up': stopZoom,
|
321
|
+
});
|
322
|
+
}
|
323
|
+
|
324
|
+
/**
|
325
|
+
* onMousemove handler in fabric canvas
|
326
|
+
* @param {{e: MouseEvent}} fEvent - Fabric event
|
327
|
+
* @private
|
328
|
+
*/
|
329
|
+
_onMouseMoveWithZoomMode({ e }) {
|
330
|
+
const canvas = this.getCanvas();
|
331
|
+
const pointer = canvas.getPointer(e);
|
332
|
+
const { x, y } = pointer;
|
333
|
+
const { zoomArea, _startPoint } = this;
|
334
|
+
const deltaX = Math.abs(x - _startPoint.x);
|
335
|
+
const deltaY = Math.abs(y - _startPoint.y);
|
336
|
+
|
337
|
+
if (deltaX + deltaY > MOUSE_MOVE_THRESHOLD) {
|
338
|
+
canvas.remove(zoomArea);
|
339
|
+
zoomArea.set(this._calcRectDimensionFromPoint(x, y));
|
340
|
+
canvas.add(zoomArea);
|
341
|
+
}
|
342
|
+
}
|
343
|
+
|
344
|
+
/**
|
345
|
+
* Get rect dimension setting from Canvas-Mouse-Position(x, y)
|
346
|
+
* @param {number} x - Canvas-Mouse-Position x
|
347
|
+
* @param {number} y - Canvas-Mouse-Position Y
|
348
|
+
* @returns {{left: number, top: number, width: number, height: number}}
|
349
|
+
* @private
|
350
|
+
*/
|
351
|
+
_calcRectDimensionFromPoint(x, y) {
|
352
|
+
const canvas = this.getCanvas();
|
353
|
+
const canvasWidth = canvas.getWidth();
|
354
|
+
const canvasHeight = canvas.getHeight();
|
355
|
+
const { x: startX, y: startY } = this._startPoint;
|
356
|
+
const { min } = Math;
|
357
|
+
|
358
|
+
const left = min(startX, x);
|
359
|
+
const top = min(startY, y);
|
360
|
+
const width = clamp(x, startX, canvasWidth) - left; // (startX <= x(mouse) <= canvasWidth) - left
|
361
|
+
const height = clamp(y, startY, canvasHeight) - top; // (startY <= y(mouse) <= canvasHeight) - top
|
362
|
+
|
363
|
+
return { left, top, width, height };
|
364
|
+
}
|
365
|
+
|
366
|
+
/**
|
367
|
+
* onMouseup handler in fabric canvas
|
368
|
+
* @private
|
369
|
+
*/
|
370
|
+
_onMouseUpWithZoomMode() {
|
371
|
+
let { zoomLevel } = this;
|
372
|
+
const { zoomArea } = this;
|
373
|
+
const { moveZoom, stopZoom } = this._listeners;
|
374
|
+
const canvas = this.getCanvas();
|
375
|
+
const center = this._getCenterPoint();
|
376
|
+
const { x, y } = center;
|
377
|
+
|
378
|
+
if (!this._isMaxZoomLevel()) {
|
379
|
+
this._centerPoints.push({
|
380
|
+
x,
|
381
|
+
y,
|
382
|
+
prevZoomLevel: zoomLevel,
|
383
|
+
zoomLevel: zoomLevel + 1,
|
384
|
+
});
|
385
|
+
zoomLevel += 1;
|
386
|
+
canvas.zoomToPoint({ x, y }, zoomLevel);
|
387
|
+
|
388
|
+
this._fireZoomChanged(canvas, zoomLevel);
|
389
|
+
|
390
|
+
this.zoomLevel = zoomLevel;
|
391
|
+
}
|
392
|
+
|
393
|
+
canvas.off({
|
394
|
+
'mouse:move': moveZoom,
|
395
|
+
'mouse:up': stopZoom,
|
396
|
+
});
|
397
|
+
|
398
|
+
canvas.remove(zoomArea);
|
399
|
+
this._startPoint = null;
|
400
|
+
}
|
401
|
+
|
402
|
+
/**
|
403
|
+
* Get center point
|
404
|
+
* @returns {{x: number, y: number}}
|
405
|
+
* @private
|
406
|
+
*/
|
407
|
+
_getCenterPoint() {
|
408
|
+
const { left, top, width, height } = this.zoomArea;
|
409
|
+
const { x, y } = this._startPoint;
|
410
|
+
const { aspectRatio } = this;
|
411
|
+
|
412
|
+
if (width < MOUSE_MOVE_THRESHOLD && height < MOUSE_MOVE_THRESHOLD) {
|
413
|
+
return { x, y };
|
414
|
+
}
|
415
|
+
|
416
|
+
return width > height
|
417
|
+
? { x: left + (aspectRatio * height) / 2, y: top + height / 2 }
|
418
|
+
: { x: left + width / 2, y: top + width / aspectRatio / 2 };
|
419
|
+
}
|
420
|
+
|
421
|
+
/**
|
422
|
+
* Zoom the canvas
|
423
|
+
* @param {{x: number, y: number}} center - center of zoom
|
424
|
+
* @param {?number} zoomLevel - zoom level
|
425
|
+
*/
|
426
|
+
zoom({ x, y }, zoomLevel = this.zoomLevel) {
|
427
|
+
const canvas = this.getCanvas();
|
428
|
+
const centerPoints = this._centerPoints;
|
429
|
+
|
430
|
+
for (let i = centerPoints.length - 1; i >= 0; i -= 1) {
|
431
|
+
if (centerPoints[i].zoomLevel < zoomLevel) {
|
432
|
+
break;
|
433
|
+
}
|
434
|
+
|
435
|
+
const { x: prevX, y: prevY, prevZoomLevel } = centerPoints.pop();
|
436
|
+
|
437
|
+
canvas.zoomToPoint({ x: prevX, y: prevY }, prevZoomLevel);
|
438
|
+
this.zoomLevel = prevZoomLevel;
|
439
|
+
}
|
440
|
+
|
441
|
+
canvas.zoomToPoint({ x, y }, zoomLevel);
|
442
|
+
if (!this._isDefaultZoomLevel(zoomLevel)) {
|
443
|
+
this._centerPoints.push({
|
444
|
+
x,
|
445
|
+
y,
|
446
|
+
zoomLevel,
|
447
|
+
prevZoomLevel: this.zoomLevel,
|
448
|
+
});
|
449
|
+
}
|
450
|
+
this.zoomLevel = zoomLevel;
|
451
|
+
|
452
|
+
this._fireZoomChanged(canvas, zoomLevel);
|
453
|
+
}
|
454
|
+
|
455
|
+
/**
|
456
|
+
* Zoom out one step
|
457
|
+
*/
|
458
|
+
zoomOut() {
|
459
|
+
const centerPoints = this._centerPoints;
|
460
|
+
|
461
|
+
if (!centerPoints.length) {
|
462
|
+
return;
|
463
|
+
}
|
464
|
+
|
465
|
+
const canvas = this.getCanvas();
|
466
|
+
const point = centerPoints.pop();
|
467
|
+
const { x, y, prevZoomLevel } = point;
|
468
|
+
|
469
|
+
if (this._isDefaultZoomLevel(prevZoomLevel)) {
|
470
|
+
canvas.setViewportTransform([1, 0, 0, 1, 0, 0]);
|
471
|
+
} else {
|
472
|
+
canvas.zoomToPoint({ x, y }, prevZoomLevel);
|
473
|
+
}
|
474
|
+
|
475
|
+
this.zoomLevel = prevZoomLevel;
|
476
|
+
|
477
|
+
this._fireZoomChanged(canvas, this.zoomLevel);
|
478
|
+
}
|
479
|
+
|
480
|
+
/**
|
481
|
+
* Zoom reset
|
482
|
+
*/
|
483
|
+
resetZoom() {
|
484
|
+
const canvas = this.getCanvas();
|
485
|
+
|
486
|
+
canvas.setViewportTransform([1, 0, 0, 1, 0, 0]);
|
487
|
+
|
488
|
+
this.zoomLevel = DEFAULT_ZOOM_LEVEL;
|
489
|
+
this._centerPoints = [];
|
490
|
+
|
491
|
+
this._fireZoomChanged(canvas, this.zoomLevel);
|
492
|
+
}
|
493
|
+
|
494
|
+
/**
|
495
|
+
* Whether zoom level is max (5.0)
|
496
|
+
* @returns {boolean}
|
497
|
+
* @private
|
498
|
+
*/
|
499
|
+
_isMaxZoomLevel() {
|
500
|
+
return this.zoomLevel >= 5.0;
|
501
|
+
}
|
502
|
+
|
503
|
+
/**
|
504
|
+
* Move point of zoom
|
505
|
+
* @param {{x: number, y: number}} delta - move amount
|
506
|
+
* @private
|
507
|
+
*/
|
508
|
+
_movePointOfZoom({ x: deltaX, y: deltaY }) {
|
509
|
+
const centerPoints = this._centerPoints;
|
510
|
+
|
511
|
+
if (!centerPoints.length) {
|
512
|
+
return;
|
513
|
+
}
|
514
|
+
|
515
|
+
const canvas = this.getCanvas();
|
516
|
+
const { zoomLevel } = this;
|
517
|
+
|
518
|
+
const point = centerPoints.pop();
|
519
|
+
const { x: originX, y: originY, prevZoomLevel } = point;
|
520
|
+
const x = originX - deltaX;
|
521
|
+
const y = originY - deltaY;
|
522
|
+
|
523
|
+
canvas.zoomToPoint({ x: originX, y: originY }, prevZoomLevel);
|
524
|
+
canvas.zoomToPoint({ x, y }, zoomLevel);
|
525
|
+
centerPoints.push({ x, y, prevZoomLevel, zoomLevel });
|
526
|
+
|
527
|
+
this._fireZoomChanged(canvas, zoomLevel);
|
528
|
+
}
|
529
|
+
|
530
|
+
/**
|
531
|
+
* onMouseDown handler in fabric canvas
|
532
|
+
* @param {{target: fabric.Object, e: MouseEvent}} fEvent - Fabric event
|
533
|
+
* @private
|
534
|
+
*/
|
535
|
+
_onMouseDownWithHandMode({ target, e }) {
|
536
|
+
if (target) {
|
537
|
+
return;
|
538
|
+
}
|
539
|
+
|
540
|
+
const canvas = this.getCanvas();
|
541
|
+
|
542
|
+
if (this.zoomLevel <= DEFAULT_ZOOM_LEVEL) {
|
543
|
+
return;
|
544
|
+
}
|
545
|
+
|
546
|
+
canvas.selection = false;
|
547
|
+
|
548
|
+
this._startHandPoint = canvas.getPointer(e);
|
549
|
+
|
550
|
+
const { moveHand, stopHand } = this._listeners;
|
551
|
+
canvas.on({
|
552
|
+
'mouse:move': moveHand,
|
553
|
+
'mouse:up': stopHand,
|
554
|
+
});
|
555
|
+
}
|
556
|
+
|
557
|
+
/**
|
558
|
+
* onMouseMove handler in fabric canvas
|
559
|
+
* @param {{e: MouseEvent}} fEvent - Fabric event
|
560
|
+
* @private
|
561
|
+
*/
|
562
|
+
_onMouseMoveWithHandMode({ e }) {
|
563
|
+
const canvas = this.getCanvas();
|
564
|
+
const { x, y } = canvas.getPointer(e);
|
565
|
+
const deltaX = x - this._startHandPoint.x;
|
566
|
+
const deltaY = y - this._startHandPoint.y;
|
567
|
+
|
568
|
+
this._movePointOfZoom({ x: deltaX, y: deltaY });
|
569
|
+
}
|
570
|
+
|
571
|
+
/**
|
572
|
+
* onMouseUp handler in fabric canvas
|
573
|
+
* @private
|
574
|
+
*/
|
575
|
+
_onMouseUpWithHandMode() {
|
576
|
+
const canvas = this.getCanvas();
|
577
|
+
const { moveHand, stopHand } = this._listeners;
|
578
|
+
|
579
|
+
canvas.off({
|
580
|
+
'mouse:move': moveHand,
|
581
|
+
'mouse:up': stopHand,
|
582
|
+
});
|
583
|
+
|
584
|
+
this._startHandPoint = null;
|
585
|
+
}
|
586
|
+
|
587
|
+
/**
|
588
|
+
* onChangeZoom handler in fabric canvas
|
589
|
+
* @private
|
590
|
+
*/
|
591
|
+
_changeScrollState({ viewport, zoomLevel }) {
|
592
|
+
const canvas = this.getCanvas();
|
593
|
+
|
594
|
+
canvas.remove(this._verticalScroll);
|
595
|
+
canvas.remove(this._horizontalScroll);
|
596
|
+
|
597
|
+
if (this._isDefaultZoomLevel(zoomLevel)) {
|
598
|
+
return;
|
599
|
+
}
|
600
|
+
|
601
|
+
const canvasWidth = canvas.width;
|
602
|
+
const canvasHeight = canvas.height;
|
603
|
+
|
604
|
+
const { tl, tr, bl } = viewport;
|
605
|
+
const viewportWidth = tr.x - tl.x;
|
606
|
+
const viewportHeight = bl.y - tl.y;
|
607
|
+
|
608
|
+
const horizontalScrollWidth = (viewportWidth * viewportWidth) / canvasWidth;
|
609
|
+
const horizontalScrollHeight = viewportHeight * DEFAULT_HORIZONTAL_SCROLL_RATIO.SIZE;
|
610
|
+
const horizontalScrollLeft = clamp(
|
611
|
+
tl.x + (tl.x / canvasWidth) * viewportWidth,
|
612
|
+
tl.x,
|
613
|
+
tr.x - horizontalScrollWidth
|
614
|
+
);
|
615
|
+
const horizontalScrollMargin = viewportHeight * DEFAULT_HORIZONTAL_SCROLL_RATIO.MARGIN;
|
616
|
+
const horizontalScrollBorderRadius =
|
617
|
+
viewportHeight * DEFAULT_HORIZONTAL_SCROLL_RATIO.BORDER_RADIUS;
|
618
|
+
|
619
|
+
this._horizontalScroll.set({
|
620
|
+
left: horizontalScrollLeft,
|
621
|
+
top: bl.y - horizontalScrollHeight - horizontalScrollMargin,
|
622
|
+
width: horizontalScrollWidth,
|
623
|
+
height: horizontalScrollHeight,
|
624
|
+
rx: horizontalScrollBorderRadius,
|
625
|
+
ry: horizontalScrollBorderRadius,
|
626
|
+
});
|
627
|
+
|
628
|
+
const verticalScrollWidth = viewportWidth * DEFAULT_VERTICAL_SCROLL_RATIO.SIZE;
|
629
|
+
const verticalScrollHeight = (viewportHeight * viewportHeight) / canvasHeight;
|
630
|
+
const verticalScrollTop = clamp(
|
631
|
+
tl.y + (tl.y / canvasHeight) * viewportHeight,
|
632
|
+
tr.y,
|
633
|
+
bl.y - verticalScrollHeight
|
634
|
+
);
|
635
|
+
const verticalScrollMargin = viewportWidth * DEFAULT_VERTICAL_SCROLL_RATIO.MARGIN;
|
636
|
+
const verticalScrollBorderRadius = viewportWidth * DEFAULT_VERTICAL_SCROLL_RATIO.BORDER_RADIUS;
|
637
|
+
|
638
|
+
this._verticalScroll.set({
|
639
|
+
left: tr.x - verticalScrollWidth - verticalScrollMargin,
|
640
|
+
top: verticalScrollTop,
|
641
|
+
width: verticalScrollWidth,
|
642
|
+
height: verticalScrollHeight,
|
643
|
+
rx: verticalScrollBorderRadius,
|
644
|
+
ry: verticalScrollBorderRadius,
|
645
|
+
});
|
646
|
+
|
647
|
+
this._addScrollBar();
|
648
|
+
}
|
649
|
+
|
650
|
+
/**
|
651
|
+
* Change objects 'evented' state
|
652
|
+
* @param {boolean} [evented=true] - objects 'evented' state
|
653
|
+
*/
|
654
|
+
_changeObjectsEventedState(evented = true) {
|
655
|
+
const canvas = this.getCanvas();
|
656
|
+
|
657
|
+
canvas.forEachObject((obj) => {
|
658
|
+
// {@link http://fabricjs.com/docs/fabric.Object.html#evented}
|
659
|
+
obj.evented = evented;
|
660
|
+
});
|
661
|
+
}
|
662
|
+
|
663
|
+
/**
|
664
|
+
* Add scroll bar and set remove timer
|
665
|
+
*/
|
666
|
+
_addScrollBar() {
|
667
|
+
const canvas = this.getCanvas();
|
668
|
+
|
669
|
+
canvas.add(this._horizontalScroll);
|
670
|
+
canvas.add(this._verticalScroll);
|
671
|
+
|
672
|
+
if (this.scrollBarTid) {
|
673
|
+
clearTimeout(this.scrollBarTid);
|
674
|
+
}
|
675
|
+
|
676
|
+
this.scrollBarTid = setTimeout(() => {
|
677
|
+
canvas.remove(this._horizontalScroll);
|
678
|
+
canvas.remove(this._verticalScroll);
|
679
|
+
}, 3000);
|
680
|
+
}
|
681
|
+
|
682
|
+
/**
|
683
|
+
* Check zoom level is default zoom level (1.0)
|
684
|
+
* @param {number} zoomLevel - zoom level
|
685
|
+
* @returns {boolean} - whether zoom level is 1.0
|
686
|
+
*/
|
687
|
+
_isDefaultZoomLevel(zoomLevel) {
|
688
|
+
return zoomLevel === DEFAULT_ZOOM_LEVEL;
|
689
|
+
}
|
690
|
+
|
691
|
+
/**
|
692
|
+
* Fire 'zoomChanged' event
|
693
|
+
* @param {fabric.Canvas} canvas - fabric canvas
|
694
|
+
* @param {number} zoomLevel - 'zoomChanged' event params
|
695
|
+
*/
|
696
|
+
_fireZoomChanged(canvas, zoomLevel) {
|
697
|
+
canvas.fire(ZOOM_CHANGED, { viewport: canvas.calcViewportBoundaries(), zoomLevel });
|
698
|
+
}
|
699
|
+
|
700
|
+
/**
|
701
|
+
* Get zoom mode
|
702
|
+
*/
|
703
|
+
get mode() {
|
704
|
+
return this.zoomMode;
|
705
|
+
}
|
706
|
+
}
|
707
|
+
|
708
|
+
export default Zoom;
|