fabric-vectr 6.7.15 → 6.7.17
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/dist/dist/index.d.mts +13871 -0
- package/dist/dist/index.d.mts.map +1 -0
- package/dist/dist/index.mjs +26926 -0
- package/dist/dist/index.mjs.map +1 -0
- package/dist/dist/src/util/internals/cloneStyles.d.mts +2 -0
- package/dist/dist/src/util/internals/cloneStyles.d.mts.map +1 -0
- package/dist/dist/src/util/internals/cloneStyles.mjs +15 -0
- package/dist/dist/src/util/internals/cloneStyles.mjs.map +1 -0
- package/dist/extensions/aligning_guidelines/constant.js +9 -0
- package/dist/extensions/aligning_guidelines/constant.js.map +1 -0
- package/dist/extensions/aligning_guidelines/index.js +132 -0
- package/dist/extensions/aligning_guidelines/index.js.map +1 -0
- package/dist/extensions/aligning_guidelines/typedefs.js +2 -0
- package/dist/extensions/aligning_guidelines/typedefs.js.map +1 -0
- package/dist/extensions/aligning_guidelines/util/basic.js +12 -0
- package/dist/extensions/aligning_guidelines/util/basic.js.map +1 -0
- package/dist/extensions/aligning_guidelines/util/basic.spec.d.ts +2 -0
- package/dist/extensions/aligning_guidelines/util/basic.spec.d.ts.map +1 -0
- package/dist/extensions/aligning_guidelines/util/basic.spec.js +30 -0
- package/dist/extensions/aligning_guidelines/util/basic.spec.js.map +1 -0
- package/dist/extensions/aligning_guidelines/util/collect-line.js +129 -0
- package/dist/extensions/aligning_guidelines/util/collect-line.js.map +1 -0
- package/dist/extensions/aligning_guidelines/util/collect-point.js +78 -0
- package/dist/extensions/aligning_guidelines/util/collect-point.js.map +1 -0
- package/dist/extensions/aligning_guidelines/util/draw.js +67 -0
- package/dist/extensions/aligning_guidelines/util/draw.js.map +1 -0
- package/dist/extensions/aligning_guidelines/util/get-objects-by-target.js +44 -0
- package/dist/extensions/aligning_guidelines/util/get-objects-by-target.js.map +1 -0
- package/dist/extensions/data_updaters/origins/index.js +36 -0
- package/dist/extensions/data_updaters/origins/index.js.map +1 -0
- package/dist/extensions/data_updaters/origins/index.spec.d.ts +2 -0
- package/dist/extensions/data_updaters/origins/index.spec.d.ts.map +1 -0
- package/dist/extensions/data_updaters/origins/index.spec.js +94 -0
- package/dist/extensions/data_updaters/origins/index.spec.js.map +1 -0
- package/dist/extensions/index.js +3 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/fabric.js +101 -0
- package/dist/fabric.js.map +1 -0
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +6 -3
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +6 -3
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +37 -0
- package/dist/index.node.js.map +1 -0
- package/dist/index.node.mjs +6 -3
- package/dist/index.node.mjs.map +1 -1
- package/dist/package.json +178 -0
- package/dist/package.json.min.mjs +1 -1
- package/dist/package.json.mjs +1 -1
- package/dist/src/ClassRegistry.js +49 -0
- package/dist/src/ClassRegistry.js.map +1 -0
- package/dist/src/Collection.js +295 -0
- package/dist/src/Collection.js.map +1 -0
- package/dist/src/CommonMethods.js +58 -0
- package/dist/src/CommonMethods.js.map +1 -0
- package/dist/src/EventTypeDefs.js +2 -0
- package/dist/src/EventTypeDefs.js.map +1 -0
- package/dist/src/Intersection.js +250 -0
- package/dist/src/Intersection.js.map +1 -0
- package/dist/src/LayoutManager/ActiveSelectionLayoutManager.js +47 -0
- package/dist/src/LayoutManager/ActiveSelectionLayoutManager.js.map +1 -0
- package/dist/src/LayoutManager/LayoutManager.js +238 -0
- package/dist/src/LayoutManager/LayoutManager.js.map +1 -0
- package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.js +60 -0
- package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.js.map +1 -0
- package/dist/src/LayoutManager/LayoutStrategies/FitContentLayout.js +18 -0
- package/dist/src/LayoutManager/LayoutStrategies/FitContentLayout.js.map +1 -0
- package/dist/src/LayoutManager/LayoutStrategies/FixedLayout.js +17 -0
- package/dist/src/LayoutManager/LayoutStrategies/FixedLayout.js.map +1 -0
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.js +80 -0
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.js.map +1 -0
- package/dist/src/LayoutManager/LayoutStrategies/utils.js +28 -0
- package/dist/src/LayoutManager/LayoutStrategies/utils.js.map +1 -0
- package/dist/src/LayoutManager/constants.js +7 -0
- package/dist/src/LayoutManager/constants.js.map +1 -0
- package/dist/src/LayoutManager/index.js +7 -0
- package/dist/src/LayoutManager/index.js.map +1 -0
- package/dist/src/LayoutManager/types.js +2 -0
- package/dist/src/LayoutManager/types.js.map +1 -0
- package/dist/src/Observable.js +107 -0
- package/dist/src/Observable.js.map +1 -0
- package/dist/src/Pattern/Pattern.js +152 -0
- package/dist/src/Pattern/Pattern.js.map +1 -0
- package/dist/src/Pattern/index.js +3 -0
- package/dist/src/Pattern/index.js.map +1 -0
- package/dist/src/Pattern/types.js +2 -0
- package/dist/src/Pattern/types.js.map +1 -0
- package/dist/src/Point.js +330 -0
- package/dist/src/Point.js.map +1 -0
- package/dist/src/Shadow.js +125 -0
- package/dist/src/Shadow.js.map +1 -0
- package/dist/src/benchmarks/boundingBoxFromPoint.d.mts +2 -0
- package/dist/src/benchmarks/boundingBoxFromPoint.d.mts.map +1 -0
- package/dist/src/benchmarks/boundingBoxFromPoint.mjs +54 -0
- package/dist/src/benchmarks/boundingBoxFromPoint.mjs.map +1 -0
- package/dist/src/benchmarks/calcCornerCoords.d.mts +2 -0
- package/dist/src/benchmarks/calcCornerCoords.d.mts.map +1 -0
- package/dist/src/benchmarks/calcCornerCoords.mjs +78 -0
- package/dist/src/benchmarks/calcCornerCoords.mjs.map +1 -0
- package/dist/src/benchmarks/calcTransformMatrix.d.mts +2 -0
- package/dist/src/benchmarks/calcTransformMatrix.d.mts.map +1 -0
- package/dist/src/benchmarks/calcTransformMatrix.mjs +71 -0
- package/dist/src/benchmarks/calcTransformMatrix.mjs.map +1 -0
- package/dist/src/benchmarks/cloneStyles.d.mts +2 -0
- package/dist/src/benchmarks/cloneStyles.d.mts.map +1 -0
- package/dist/src/benchmarks/cloneStyles.mjs +56 -0
- package/dist/src/benchmarks/cloneStyles.mjs.map +1 -0
- package/dist/src/benchmarks/pathCloning.d.mts +2 -0
- package/dist/src/benchmarks/pathCloning.d.mts.map +1 -0
- package/dist/src/benchmarks/pathCloning.mjs +94 -0
- package/dist/src/benchmarks/pathCloning.mjs.map +1 -0
- package/dist/src/benchmarks/pathData.d.mts +3 -0
- package/dist/src/benchmarks/pathData.d.mts.map +1 -0
- package/dist/src/benchmarks/pathData.mjs +3 -0
- package/dist/src/benchmarks/pathData.mjs.map +1 -0
- package/dist/src/benchmarks/raycasting.d.mts +2 -0
- package/dist/src/benchmarks/raycasting.d.mts.map +1 -0
- package/dist/src/benchmarks/raycasting.mjs +134 -0
- package/dist/src/benchmarks/raycasting.mjs.map +1 -0
- package/dist/src/benchmarks/transformMatrixKey.d.mts +2 -0
- package/dist/src/benchmarks/transformMatrixKey.d.mts.map +1 -0
- package/dist/src/benchmarks/transformMatrixKey.mjs +81 -0
- package/dist/src/benchmarks/transformMatrixKey.mjs.map +1 -0
- package/dist/src/brushes/BaseBrush.js +121 -0
- package/dist/src/brushes/BaseBrush.js.map +1 -0
- package/dist/src/brushes/CircleBrush.js +117 -0
- package/dist/src/brushes/CircleBrush.js.map +1 -0
- package/dist/src/brushes/PatternBrush.js +49 -0
- package/dist/src/brushes/PatternBrush.js.map +1 -0
- package/dist/src/brushes/PencilBrush.js +259 -0
- package/dist/src/brushes/PencilBrush.js.map +1 -0
- package/dist/src/brushes/SprayBrush.js +174 -0
- package/dist/src/brushes/SprayBrush.js.map +1 -0
- package/dist/src/brushes/typedefs.js +2 -0
- package/dist/src/brushes/typedefs.js.map +1 -0
- package/dist/src/cache.js +69 -0
- package/dist/src/cache.js.map +1 -0
- package/dist/src/canvas/Canvas.js +1366 -0
- package/dist/src/canvas/Canvas.js.map +1 -0
- package/dist/src/canvas/CanvasOptions.js +31 -0
- package/dist/src/canvas/CanvasOptions.js.map +1 -0
- package/dist/src/canvas/DOMManagers/CanvasDOMManager.js +97 -0
- package/dist/src/canvas/DOMManagers/CanvasDOMManager.js.map +1 -0
- package/dist/src/canvas/DOMManagers/StaticCanvasDOMManager.js +63 -0
- package/dist/src/canvas/DOMManagers/StaticCanvasDOMManager.js.map +1 -0
- package/dist/src/canvas/DOMManagers/util.js +56 -0
- package/dist/src/canvas/DOMManagers/util.js.map +1 -0
- package/dist/src/canvas/SelectableCanvas.js +1141 -0
- package/dist/src/canvas/SelectableCanvas.js.map +1 -0
- package/dist/src/canvas/StaticCanvas.js +1085 -0
- package/dist/src/canvas/StaticCanvas.js.map +1 -0
- package/dist/src/canvas/StaticCanvasOptions.js +23 -0
- package/dist/src/canvas/StaticCanvasOptions.js.map +1 -0
- package/dist/src/canvas/TextEditingManager.js +54 -0
- package/dist/src/canvas/TextEditingManager.js.map +1 -0
- package/dist/src/canvas/canvas_gestures.mixin.js +181 -0
- package/dist/src/canvas/canvas_gestures.mixin.js.map +1 -0
- package/dist/src/color/Color.js +301 -0
- package/dist/src/color/Color.js.map +1 -0
- package/dist/src/color/color_map.js +155 -0
- package/dist/src/color/color_map.js.map +1 -0
- package/dist/src/color/constants.js +111 -0
- package/dist/src/color/constants.js.map +1 -0
- package/dist/src/color/typedefs.js +2 -0
- package/dist/src/color/typedefs.js.map +1 -0
- package/dist/src/color/util.js +73 -0
- package/dist/src/color/util.js.map +1 -0
- package/dist/src/config.js +140 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/constants.js +38 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/controls/Control.js +241 -0
- package/dist/src/controls/Control.js.map +1 -0
- package/dist/src/controls/changeWidth.js +31 -0
- package/dist/src/controls/changeWidth.js.map +1 -0
- package/dist/src/controls/commonControls.js +91 -0
- package/dist/src/controls/commonControls.js.map +1 -0
- package/dist/src/controls/controlRendering.js +81 -0
- package/dist/src/controls/controlRendering.js.map +1 -0
- package/dist/src/controls/drag.js +22 -0
- package/dist/src/controls/drag.js.map +1 -0
- package/dist/src/controls/fireEvent.js +9 -0
- package/dist/src/controls/fireEvent.js.map +1 -0
- package/dist/src/controls/index.js +14 -0
- package/dist/src/controls/index.js.map +1 -0
- package/dist/src/controls/pathControl.js +137 -0
- package/dist/src/controls/pathControl.js.map +1 -0
- package/dist/src/controls/polyControl.js +66 -0
- package/dist/src/controls/polyControl.js.map +1 -0
- package/dist/src/controls/rotate.js +57 -0
- package/dist/src/controls/rotate.js.map +1 -0
- package/dist/src/controls/scale.js +190 -0
- package/dist/src/controls/scale.js.map +1 -0
- package/dist/src/controls/scaleSkew.js +66 -0
- package/dist/src/controls/scaleSkew.js.map +1 -0
- package/dist/src/controls/skew.js +147 -0
- package/dist/src/controls/skew.js.map +1 -0
- package/dist/src/controls/util.js +89 -0
- package/dist/src/controls/util.js.map +1 -0
- package/dist/src/controls/wrapWithFireEvent.js +22 -0
- package/dist/src/controls/wrapWithFireEvent.js.map +1 -0
- package/dist/src/controls/wrapWithFixedAnchor.js +16 -0
- package/dist/src/controls/wrapWithFixedAnchor.js.map +1 -0
- package/dist/src/env/browser.js +18 -0
- package/dist/src/env/browser.js.map +1 -0
- package/dist/src/env/index.js +37 -0
- package/dist/src/env/index.js.map +1 -0
- package/dist/src/env/node.js +37 -0
- package/dist/src/env/node.js.map +1 -0
- package/dist/src/env/types.js +2 -0
- package/dist/src/env/types.js.map +1 -0
- package/dist/src/filters/BaseFilter.js +304 -0
- package/dist/src/filters/BaseFilter.js.map +1 -0
- package/dist/src/filters/BlendColor.js +147 -0
- package/dist/src/filters/BlendColor.js.map +1 -0
- package/dist/src/filters/BlendImage.js +149 -0
- package/dist/src/filters/BlendImage.js.map +1 -0
- package/dist/src/filters/Blur.js +167 -0
- package/dist/src/filters/Blur.js.map +1 -0
- package/dist/src/filters/Boilerplate.js +61 -0
- package/dist/src/filters/Boilerplate.js.map +1 -0
- package/dist/src/filters/Brightness.js +51 -0
- package/dist/src/filters/Brightness.js.map +1 -0
- package/dist/src/filters/Canvas2dFilterBackend.js +51 -0
- package/dist/src/filters/Canvas2dFilterBackend.js.map +1 -0
- package/dist/src/filters/ColorMatrix.js +92 -0
- package/dist/src/filters/ColorMatrix.js.map +1 -0
- package/dist/src/filters/ColorMatrixFilters.js +45 -0
- package/dist/src/filters/ColorMatrixFilters.js.map +1 -0
- package/dist/src/filters/Composed.js +55 -0
- package/dist/src/filters/Composed.js.map +1 -0
- package/dist/src/filters/Contrast.js +51 -0
- package/dist/src/filters/Contrast.js.map +1 -0
- package/dist/src/filters/Convolute.js +132 -0
- package/dist/src/filters/Convolute.js.map +1 -0
- package/dist/src/filters/FilterBackend.js +34 -0
- package/dist/src/filters/FilterBackend.js.map +1 -0
- package/dist/src/filters/GLProbes/GLProbe.js +3 -0
- package/dist/src/filters/GLProbes/GLProbe.js.map +1 -0
- package/dist/src/filters/GLProbes/NodeGLProbe.js +15 -0
- package/dist/src/filters/GLProbes/NodeGLProbe.js.map +1 -0
- package/dist/src/filters/GLProbes/WebGLProbe.js +39 -0
- package/dist/src/filters/GLProbes/WebGLProbe.js.map +1 -0
- package/dist/src/filters/Gamma.js +80 -0
- package/dist/src/filters/Gamma.js.map +1 -0
- package/dist/src/filters/Grayscale.js +69 -0
- package/dist/src/filters/Grayscale.js.map +1 -0
- package/dist/src/filters/HueRotation.js +61 -0
- package/dist/src/filters/HueRotation.js.map +1 -0
- package/dist/src/filters/Invert.js +58 -0
- package/dist/src/filters/Invert.js.map +1 -0
- package/dist/src/filters/Noise.js +54 -0
- package/dist/src/filters/Noise.js.map +1 -0
- package/dist/src/filters/Pixelate.js +66 -0
- package/dist/src/filters/Pixelate.js.map +1 -0
- package/dist/src/filters/RemoveColor.js +74 -0
- package/dist/src/filters/RemoveColor.js.map +1 -0
- package/dist/src/filters/Resize.js +399 -0
- package/dist/src/filters/Resize.js.map +1 -0
- package/dist/src/filters/Saturation.js +55 -0
- package/dist/src/filters/Saturation.js.map +1 -0
- package/dist/src/filters/Vibrance.js +57 -0
- package/dist/src/filters/Vibrance.js.map +1 -0
- package/dist/src/filters/WebGLFilterBackend.js +269 -0
- package/dist/src/filters/WebGLFilterBackend.js.map +1 -0
- package/dist/src/filters/filters.js +21 -0
- package/dist/src/filters/filters.js.map +1 -0
- package/dist/src/filters/index.js +7 -0
- package/dist/src/filters/index.js.map +1 -0
- package/dist/src/filters/shaders/baseFilter.js +16 -0
- package/dist/src/filters/shaders/baseFilter.js.map +1 -0
- package/dist/src/filters/shaders/blendColor.js +32 -0
- package/dist/src/filters/shaders/blendColor.js.map +1 -0
- package/dist/src/filters/shaders/blendImage.js +42 -0
- package/dist/src/filters/shaders/blendImage.js.map +1 -0
- package/dist/src/filters/shaders/blur.js +31 -0
- package/dist/src/filters/shaders/blur.js.map +1 -0
- package/dist/src/filters/shaders/brightness.js +12 -0
- package/dist/src/filters/shaders/brightness.js.map +1 -0
- package/dist/src/filters/shaders/colorMatrix.js +13 -0
- package/dist/src/filters/shaders/colorMatrix.js.map +1 -0
- package/dist/src/filters/shaders/constrast.js +12 -0
- package/dist/src/filters/shaders/constrast.js.map +1 -0
- package/dist/src/filters/shaders/convolute.js +155 -0
- package/dist/src/filters/shaders/convolute.js.map +1 -0
- package/dist/src/filters/shaders/gamma.js +16 -0
- package/dist/src/filters/shaders/gamma.js.map +1 -0
- package/dist/src/filters/shaders/grayscale.js +35 -0
- package/dist/src/filters/shaders/grayscale.js.map +1 -0
- package/dist/src/filters/shaders/invert.js +20 -0
- package/dist/src/filters/shaders/invert.js.map +1 -0
- package/dist/src/filters/shaders/noise.js +17 -0
- package/dist/src/filters/shaders/noise.js.map +1 -0
- package/dist/src/filters/shaders/pixelate.js +20 -0
- package/dist/src/filters/shaders/pixelate.js.map +1 -0
- package/dist/src/filters/shaders/removeColor.js +14 -0
- package/dist/src/filters/shaders/removeColor.js.map +1 -0
- package/dist/src/filters/shaders/saturation.js +16 -0
- package/dist/src/filters/shaders/saturation.js.map +1 -0
- package/dist/src/filters/shaders/vibrance.js +17 -0
- package/dist/src/filters/shaders/vibrance.js.map +1 -0
- package/dist/src/filters/typedefs.js +2 -0
- package/dist/src/filters/typedefs.js.map +1 -0
- package/dist/src/filters/utils.js +36 -0
- package/dist/src/filters/utils.js.map +1 -0
- package/dist/src/gradient/Gradient.d.ts.map +1 -1
- package/dist/src/gradient/Gradient.js +244 -0
- package/dist/src/gradient/Gradient.js.map +1 -0
- package/dist/src/gradient/Gradient.min.mjs +1 -1
- package/dist/src/gradient/Gradient.min.mjs.map +1 -1
- package/dist/src/gradient/Gradient.mjs +2 -1
- package/dist/src/gradient/Gradient.mjs.map +1 -1
- package/dist/src/gradient/constants.js +12 -0
- package/dist/src/gradient/constants.js.map +1 -0
- package/dist/src/gradient/index.js +3 -0
- package/dist/src/gradient/index.js.map +1 -0
- package/dist/src/gradient/parser/misc.js +11 -0
- package/dist/src/gradient/parser/misc.js.map +1 -0
- package/dist/src/gradient/parser/parseColorStops.js +42 -0
- package/dist/src/gradient/parser/parseColorStops.js.map +1 -0
- package/dist/src/gradient/parser/parseCoords.js +60 -0
- package/dist/src/gradient/parser/parseCoords.js.map +1 -0
- package/dist/src/gradient/typedefs.js +2 -0
- package/dist/src/gradient/typedefs.js.map +1 -0
- package/dist/src/mixins/eraser_brush.mixin.js +732 -0
- package/dist/src/mixins/eraser_brush.mixin.js.map +1 -0
- package/dist/src/parkinglot/canvas_animation.mixin.js +102 -0
- package/dist/src/parkinglot/canvas_animation.mixin.js.map +1 -0
- package/dist/src/parkinglot/straighten.js +53 -0
- package/dist/src/parkinglot/straighten.js.map +1 -0
- package/dist/src/parser/applyViewboxTransform.js +146 -0
- package/dist/src/parser/applyViewboxTransform.js.map +1 -0
- package/dist/src/parser/attributes.js +27 -0
- package/dist/src/parser/attributes.js.map +1 -0
- package/dist/src/parser/constants.js +70 -0
- package/dist/src/parser/constants.js.map +1 -0
- package/dist/src/parser/doesSomeParentMatch.js +15 -0
- package/dist/src/parser/doesSomeParentMatch.js.map +1 -0
- package/dist/src/parser/elementMatchesRule.js +15 -0
- package/dist/src/parser/elementMatchesRule.js.map +1 -0
- package/dist/src/parser/elements_parser.js +164 -0
- package/dist/src/parser/elements_parser.js.map +1 -0
- package/dist/src/parser/getCSSRules.js +62 -0
- package/dist/src/parser/getCSSRules.js.map +1 -0
- package/dist/src/parser/getGlobalStylesForElement.js +17 -0
- package/dist/src/parser/getGlobalStylesForElement.js.map +1 -0
- package/dist/src/parser/getGradientDefs.js +30 -0
- package/dist/src/parser/getGradientDefs.js.map +1 -0
- package/dist/src/parser/getMultipleNodes.js +10 -0
- package/dist/src/parser/getMultipleNodes.js.map +1 -0
- package/dist/src/parser/getPatternDefs.js +70 -0
- package/dist/src/parser/getPatternDefs.js.map +1 -0
- package/dist/src/parser/getSvgRegex.js +4 -0
- package/dist/src/parser/getSvgRegex.js.map +1 -0
- package/dist/src/parser/getTagName.js +2 -0
- package/dist/src/parser/getTagName.js.map +1 -0
- package/dist/src/parser/hasInvalidAncestor.js +17 -0
- package/dist/src/parser/hasInvalidAncestor.js.map +1 -0
- package/dist/src/parser/loadSVGFromString.js +23 -0
- package/dist/src/parser/loadSVGFromString.js.map +1 -0
- package/dist/src/parser/loadSVGFromURL.js +39 -0
- package/dist/src/parser/loadSVGFromURL.js.map +1 -0
- package/dist/src/parser/normalizeAttr.js +3 -0
- package/dist/src/parser/normalizeAttr.js.map +1 -0
- package/dist/src/parser/normalizeValue.js +79 -0
- package/dist/src/parser/normalizeValue.js.map +1 -0
- package/dist/src/parser/parseAttributes.js +66 -0
- package/dist/src/parser/parseAttributes.js.map +1 -0
- package/dist/src/parser/parseFontDeclaration.js +38 -0
- package/dist/src/parser/parseFontDeclaration.js.map +1 -0
- package/dist/src/parser/parsePointsAttribute.js +28 -0
- package/dist/src/parser/parsePointsAttribute.js.map +1 -0
- package/dist/src/parser/parseSVGDocument.js +74 -0
- package/dist/src/parser/parseSVGDocument.js.map +1 -0
- package/dist/src/parser/parseStyleAttribute.js +23 -0
- package/dist/src/parser/parseStyleAttribute.js.map +1 -0
- package/dist/src/parser/parseStyleObject.js +15 -0
- package/dist/src/parser/parseStyleObject.js.map +1 -0
- package/dist/src/parser/parseStyleString.js +18 -0
- package/dist/src/parser/parseStyleString.js.map +1 -0
- package/dist/src/parser/parseTransformAttribute.js +76 -0
- package/dist/src/parser/parseTransformAttribute.js.map +1 -0
- package/dist/src/parser/parseUseDirectives.js +76 -0
- package/dist/src/parser/parseUseDirectives.js.map +1 -0
- package/dist/src/parser/percent.js +21 -0
- package/dist/src/parser/percent.js.map +1 -0
- package/dist/src/parser/recursivelyParseGradientsXlink.js +36 -0
- package/dist/src/parser/recursivelyParseGradientsXlink.js.map +1 -0
- package/dist/src/parser/selectorMatches.js +24 -0
- package/dist/src/parser/selectorMatches.js.map +1 -0
- package/dist/src/parser/setStrokeFillOpacity.js +35 -0
- package/dist/src/parser/setStrokeFillOpacity.js.map +1 -0
- package/dist/src/parser/typedefs.js +2 -0
- package/dist/src/parser/typedefs.js.map +1 -0
- package/dist/src/shapes/ActiveSelection.js +195 -0
- package/dist/src/shapes/ActiveSelection.js.map +1 -0
- package/dist/src/shapes/Circle.js +155 -0
- package/dist/src/shapes/Circle.js.map +1 -0
- package/dist/src/shapes/Ellipse.js +120 -0
- package/dist/src/shapes/Ellipse.js.map +1 -0
- package/dist/src/shapes/Group.js +549 -0
- package/dist/src/shapes/Group.js.map +1 -0
- package/dist/src/shapes/IText/DraggableTextDelegate.js +326 -0
- package/dist/src/shapes/IText/DraggableTextDelegate.js.map +1 -0
- package/dist/src/shapes/IText/IText.js +545 -0
- package/dist/src/shapes/IText/IText.js.map +1 -0
- package/dist/src/shapes/IText/ITextBehavior.js +848 -0
- package/dist/src/shapes/IText/ITextBehavior.js.map +1 -0
- package/dist/src/shapes/IText/ITextClickBehavior.js +196 -0
- package/dist/src/shapes/IText/ITextClickBehavior.js.map +1 -0
- package/dist/src/shapes/IText/ITextKeyBehavior.js +522 -0
- package/dist/src/shapes/IText/ITextKeyBehavior.js.map +1 -0
- package/dist/src/shapes/IText/constants.js +47 -0
- package/dist/src/shapes/IText/constants.js.map +1 -0
- package/dist/src/shapes/Image.js +589 -0
- package/dist/src/shapes/Image.js.map +1 -0
- package/dist/src/shapes/Line.js +195 -0
- package/dist/src/shapes/Line.js.map +1 -0
- package/dist/src/shapes/Object/FabricObject.js +12 -0
- package/dist/src/shapes/Object/FabricObject.js.map +1 -0
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.js +255 -0
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.js.map +1 -0
- package/dist/src/shapes/Object/InteractiveObject.js +478 -0
- package/dist/src/shapes/Object/InteractiveObject.js.map +1 -0
- package/dist/src/shapes/Object/Object.js +1392 -0
- package/dist/src/shapes/Object/Object.js.map +1 -0
- package/dist/src/shapes/Object/ObjectGeometry.js +537 -0
- package/dist/src/shapes/Object/ObjectGeometry.js.map +1 -0
- package/dist/src/shapes/Object/defaultValues.js +109 -0
- package/dist/src/shapes/Object/defaultValues.js.map +1 -0
- package/dist/src/shapes/Object/types/BaseProps.js +2 -0
- package/dist/src/shapes/Object/types/BaseProps.js.map +1 -0
- package/dist/src/shapes/Object/types/BorderProps.js +2 -0
- package/dist/src/shapes/Object/types/BorderProps.js.map +1 -0
- package/dist/src/shapes/Object/types/ControlProps.js +2 -0
- package/dist/src/shapes/Object/types/ControlProps.js.map +1 -0
- package/dist/src/shapes/Object/types/FabricObjectProps.js +2 -0
- package/dist/src/shapes/Object/types/FabricObjectProps.js.map +1 -0
- package/dist/src/shapes/Object/types/FillStrokeProps.js +2 -0
- package/dist/src/shapes/Object/types/FillStrokeProps.js.map +1 -0
- package/dist/src/shapes/Object/types/LockInteractionProps.js +2 -0
- package/dist/src/shapes/Object/types/LockInteractionProps.js.map +1 -0
- package/dist/src/shapes/Object/types/ObjectProps.js +2 -0
- package/dist/src/shapes/Object/types/ObjectProps.js.map +1 -0
- package/dist/src/shapes/Object/types/ObjectTransformProps.js +2 -0
- package/dist/src/shapes/Object/types/ObjectTransformProps.js.map +1 -0
- package/dist/src/shapes/Object/types/SerializedObjectProps.js +2 -0
- package/dist/src/shapes/Object/types/SerializedObjectProps.js.map +1 -0
- package/dist/src/shapes/Object/types/index.js +2 -0
- package/dist/src/shapes/Object/types/index.js.map +1 -0
- package/dist/src/shapes/Path.js +267 -0
- package/dist/src/shapes/Path.js.map +1 -0
- package/dist/src/shapes/Polygon.js +12 -0
- package/dist/src/shapes/Polygon.js.map +1 -0
- package/dist/src/shapes/Polyline.js +307 -0
- package/dist/src/shapes/Polyline.js.map +1 -0
- package/dist/src/shapes/Rect.js +131 -0
- package/dist/src/shapes/Rect.js.map +1 -0
- package/dist/src/shapes/Text/StyledText.js +261 -0
- package/dist/src/shapes/Text/StyledText.js.map +1 -0
- package/dist/src/shapes/Text/Text.js +1258 -0
- package/dist/src/shapes/Text/Text.js.map +1 -0
- package/dist/src/shapes/Text/TextSVGExportMixin.js +339 -0
- package/dist/src/shapes/Text/TextSVGExportMixin.js.map +1 -0
- package/dist/src/shapes/Text/constants.js +94 -0
- package/dist/src/shapes/Text/constants.js.map +1 -0
- package/dist/src/shapes/Textbox.d.ts.map +1 -1
- package/dist/src/shapes/Textbox.js +910 -0
- package/dist/src/shapes/Textbox.js.map +1 -0
- package/dist/src/shapes/Textbox.min.mjs +1 -1
- package/dist/src/shapes/Textbox.min.mjs.map +1 -1
- package/dist/src/shapes/Textbox.mjs +4 -1
- package/dist/src/shapes/Textbox.mjs.map +1 -1
- package/dist/src/shapes/Triangle.js +47 -0
- package/dist/src/shapes/Triangle.js.map +1 -0
- package/dist/src/typedefs.js +2 -0
- package/dist/src/typedefs.js.map +1 -0
- package/dist/src/util/animation/AnimationBase.js +94 -0
- package/dist/src/util/animation/AnimationBase.js.map +1 -0
- package/dist/src/util/animation/AnimationFrameProvider.js +8 -0
- package/dist/src/util/animation/AnimationFrameProvider.js.map +1 -0
- package/dist/src/util/animation/AnimationRegistry.js +49 -0
- package/dist/src/util/animation/AnimationRegistry.js.map +1 -0
- package/dist/src/util/animation/ArrayAnimation.js +18 -0
- package/dist/src/util/animation/ArrayAnimation.js.map +1 -0
- package/dist/src/util/animation/ColorAnimation.js +43 -0
- package/dist/src/util/animation/ColorAnimation.js.map +1 -0
- package/dist/src/util/animation/ValueAnimation.js +18 -0
- package/dist/src/util/animation/ValueAnimation.js.map +1 -0
- package/dist/src/util/animation/animate.js +19 -0
- package/dist/src/util/animation/animate.js.map +1 -0
- package/dist/src/util/animation/easing.js +265 -0
- package/dist/src/util/animation/easing.js.map +1 -0
- package/dist/src/util/animation/index.js +3 -0
- package/dist/src/util/animation/index.js.map +1 -0
- package/dist/src/util/animation/types.js +2 -0
- package/dist/src/util/animation/types.js.map +1 -0
- package/dist/src/util/applyMixins.js +14 -0
- package/dist/src/util/applyMixins.js.map +1 -0
- package/dist/src/util/dom_event.js +21 -0
- package/dist/src/util/dom_event.js.map +1 -0
- package/dist/src/util/dom_misc.js +42 -0
- package/dist/src/util/dom_misc.js.map +1 -0
- package/dist/src/util/dom_style.js +19 -0
- package/dist/src/util/dom_style.js.map +1 -0
- package/dist/src/util/index.js +36 -0
- package/dist/src/util/index.js.map +1 -0
- package/dist/src/util/internals/applyCanvasTransform.js +15 -0
- package/dist/src/util/internals/applyCanvasTransform.js.map +1 -0
- package/dist/src/util/internals/cleanupSvgAttribute.js +8 -0
- package/dist/src/util/internals/cleanupSvgAttribute.js.map +1 -0
- package/dist/src/util/internals/cloneDeep.js +8 -0
- package/dist/src/util/internals/cloneDeep.js.map +1 -0
- package/dist/src/util/internals/cloneStyles.js +11 -0
- package/dist/src/util/internals/cloneStyles.js.map +1 -0
- package/dist/src/util/internals/console.js +14 -0
- package/dist/src/util/internals/console.js.map +1 -0
- package/dist/src/util/internals/dom_request.js +39 -0
- package/dist/src/util/internals/dom_request.js.map +1 -0
- package/dist/src/util/internals/findRight.js +9 -0
- package/dist/src/util/internals/findRight.js.map +1 -0
- package/dist/src/util/internals/getRandomInt.js +8 -0
- package/dist/src/util/internals/getRandomInt.js.map +1 -0
- package/dist/src/util/internals/ifNaN.js +10 -0
- package/dist/src/util/internals/ifNaN.js.map +1 -0
- package/dist/src/util/internals/removeFromArray.js +15 -0
- package/dist/src/util/internals/removeFromArray.js.map +1 -0
- package/dist/src/util/internals/uid.js +3 -0
- package/dist/src/util/internals/uid.js.map +1 -0
- package/dist/src/util/lang_string.js +93 -0
- package/dist/src/util/lang_string.js.map +1 -0
- package/dist/src/util/misc/boundingBoxFromPoints.js +26 -0
- package/dist/src/util/misc/boundingBoxFromPoints.js.map +1 -0
- package/dist/src/util/misc/capValue.js +2 -0
- package/dist/src/util/misc/capValue.js.map +1 -0
- package/dist/src/util/misc/cos.js +23 -0
- package/dist/src/util/misc/cos.js.map +1 -0
- package/dist/src/util/misc/dom.js +55 -0
- package/dist/src/util/misc/dom.js.map +1 -0
- package/dist/src/util/misc/findScaleTo.js +19 -0
- package/dist/src/util/misc/findScaleTo.js.map +1 -0
- package/dist/src/util/misc/groupSVGElements.js +15 -0
- package/dist/src/util/misc/groupSVGElements.js.map +1 -0
- package/dist/src/util/misc/isTransparent.js +23 -0
- package/dist/src/util/misc/isTransparent.js.map +1 -0
- package/dist/src/util/misc/matrix.js +238 -0
- package/dist/src/util/misc/matrix.js.map +1 -0
- package/dist/src/util/misc/mergeClipPaths.js +39 -0
- package/dist/src/util/misc/mergeClipPaths.js.map +1 -0
- package/dist/src/util/misc/objectEnlive.js +136 -0
- package/dist/src/util/misc/objectEnlive.js.map +1 -0
- package/dist/src/util/misc/objectTransforms.js +89 -0
- package/dist/src/util/misc/objectTransforms.js.map +1 -0
- package/dist/src/util/misc/pick.js +23 -0
- package/dist/src/util/misc/pick.js.map +1 -0
- package/dist/src/util/misc/planeChange.js +68 -0
- package/dist/src/util/misc/planeChange.js.map +1 -0
- package/dist/src/util/misc/projectStroke/StrokeLineCapProjections.js +105 -0
- package/dist/src/util/misc/projectStroke/StrokeLineCapProjections.js.map +1 -0
- package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.js +219 -0
- package/dist/src/util/misc/projectStroke/StrokeLineJoinProjections.js.map +1 -0
- package/dist/src/util/misc/projectStroke/StrokeProjectionsBase.js +42 -0
- package/dist/src/util/misc/projectStroke/StrokeProjectionsBase.js.map +1 -0
- package/dist/src/util/misc/projectStroke/index.js +61 -0
- package/dist/src/util/misc/projectStroke/index.js.map +1 -0
- package/dist/src/util/misc/projectStroke/types.js +2 -0
- package/dist/src/util/misc/projectStroke/types.js.map +1 -0
- package/dist/src/util/misc/radiansDegreesConversion.js +14 -0
- package/dist/src/util/misc/radiansDegreesConversion.js.map +1 -0
- package/dist/src/util/misc/resolveOrigin.js +17 -0
- package/dist/src/util/misc/resolveOrigin.js.map +1 -0
- package/dist/src/util/misc/rotatePoint.js +10 -0
- package/dist/src/util/misc/rotatePoint.js.map +1 -0
- package/dist/src/util/misc/sin.js +25 -0
- package/dist/src/util/misc/sin.js.map +1 -0
- package/dist/src/util/misc/svgExport.js +13 -0
- package/dist/src/util/misc/svgExport.js.map +1 -0
- package/dist/src/util/misc/svgParsing.js +129 -0
- package/dist/src/util/misc/svgParsing.js.map +1 -0
- package/dist/src/util/misc/textStyles.js +107 -0
- package/dist/src/util/misc/textStyles.js.map +1 -0
- package/dist/src/util/misc/toFixed.js +8 -0
- package/dist/src/util/misc/toFixed.js.map +1 -0
- package/dist/src/util/misc/vectors.js +77 -0
- package/dist/src/util/misc/vectors.js.map +1 -0
- package/dist/src/util/path/index.js +743 -0
- package/dist/src/util/path/index.js.map +1 -0
- package/dist/src/util/path/regex.js +33 -0
- package/dist/src/util/path/regex.js.map +1 -0
- package/dist/src/util/path/typechecks.js +67 -0
- package/dist/src/util/path/typechecks.js.map +1 -0
- package/dist/src/util/path/typedefs.js +2 -0
- package/dist/src/util/path/typedefs.js.map +1 -0
- package/dist/src/util/transform_matrix_removal.js +46 -0
- package/dist/src/util/transform_matrix_removal.js.map +1 -0
- package/dist/src/util/typeAssertions.js +21 -0
- package/dist/src/util/typeAssertions.js.map +1 -0
- package/dist-extensions/src/gradient/Gradient.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Textbox.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/gradient/Gradient.ts +5 -2
- package/src/shapes/Textbox.ts +4 -1
|
@@ -0,0 +1,732 @@
|
|
|
1
|
+
import { uid } from '../util/internals/uid';
|
|
2
|
+
(function (global) {
|
|
3
|
+
/** ERASER_START */
|
|
4
|
+
var fabric = global.fabric, __drawClipPath = fabric.Object.prototype._drawClipPath;
|
|
5
|
+
var _needsItsOwnCache = fabric.Object.prototype.needsItsOwnCache;
|
|
6
|
+
var _toObject = fabric.Object.prototype.toObject;
|
|
7
|
+
var _getSvgCommons = fabric.Object.prototype.getSvgCommons;
|
|
8
|
+
var __createBaseClipPathSVGMarkup = fabric.Object.prototype._createBaseClipPathSVGMarkup;
|
|
9
|
+
var __createBaseSVGMarkup = fabric.Object.prototype._createBaseSVGMarkup;
|
|
10
|
+
fabric.Object.prototype.cacheProperties.push('eraser');
|
|
11
|
+
fabric.Object.prototype.stateProperties.push('eraser');
|
|
12
|
+
/**
|
|
13
|
+
* @fires erasing:end
|
|
14
|
+
*/
|
|
15
|
+
fabric.util.object.extend(fabric.Object.prototype, {
|
|
16
|
+
/**
|
|
17
|
+
* Indicates whether this object can be erased by {@link fabric.EraserBrush}
|
|
18
|
+
* The `deep` option introduces fine grained control over a group's `erasable` property.
|
|
19
|
+
* When set to `deep` the eraser will erase nested objects if they are erasable, leaving the group and the other objects untouched.
|
|
20
|
+
* When set to `true` the eraser will erase the entire group. Once the group changes the eraser is propagated to its children for proper functionality.
|
|
21
|
+
* When set to `false` the eraser will leave all objects including the group untouched.
|
|
22
|
+
* @tutorial {@link http://fabricjs.com/erasing#erasable_property}
|
|
23
|
+
* @type boolean | 'deep'
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
erasable: true,
|
|
27
|
+
/**
|
|
28
|
+
* @tutorial {@link http://fabricjs.com/erasing#eraser}
|
|
29
|
+
* @type fabric.Eraser
|
|
30
|
+
*/
|
|
31
|
+
eraser: undefined,
|
|
32
|
+
/**
|
|
33
|
+
* @override
|
|
34
|
+
* @returns Boolean
|
|
35
|
+
*/
|
|
36
|
+
needsItsOwnCache: function () {
|
|
37
|
+
return _needsItsOwnCache.call(this) || !!this.eraser;
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* draw eraser above clip path
|
|
41
|
+
* @override
|
|
42
|
+
* @private
|
|
43
|
+
* @param {CanvasRenderingContext2D} ctx
|
|
44
|
+
* @param {fabric.Object} clipPath
|
|
45
|
+
*/
|
|
46
|
+
_drawClipPath: function (ctx, clipPath) {
|
|
47
|
+
__drawClipPath.call(this, ctx, clipPath);
|
|
48
|
+
if (this.eraser) {
|
|
49
|
+
// update eraser size to match instance
|
|
50
|
+
var size = this._getNonTransformedDimensions();
|
|
51
|
+
this.eraser.isType('eraser') &&
|
|
52
|
+
this.eraser.set({
|
|
53
|
+
width: size.x,
|
|
54
|
+
height: size.y,
|
|
55
|
+
});
|
|
56
|
+
__drawClipPath.call(this, ctx, this.eraser);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Returns an object representation of an instance
|
|
61
|
+
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
|
|
62
|
+
* @return {Object} Object representation of an instance
|
|
63
|
+
*/
|
|
64
|
+
toObject: function (propertiesToInclude) {
|
|
65
|
+
var object = _toObject.call(this, ['erasable'].concat(propertiesToInclude));
|
|
66
|
+
if (this.eraser && !this.eraser.excludeFromExport) {
|
|
67
|
+
object.eraser = this.eraser.toObject(propertiesToInclude);
|
|
68
|
+
}
|
|
69
|
+
return object;
|
|
70
|
+
},
|
|
71
|
+
/* _TO_SVG_START_ */
|
|
72
|
+
/**
|
|
73
|
+
* Returns id attribute for svg output
|
|
74
|
+
* @override
|
|
75
|
+
* @return {String}
|
|
76
|
+
*/
|
|
77
|
+
getSvgCommons: function () {
|
|
78
|
+
return (_getSvgCommons.call(this) +
|
|
79
|
+
(this.eraser ? 'mask="url(#' + this.eraser.clipPathId + ')" ' : ''));
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* create svg markup for eraser
|
|
83
|
+
* use <mask> to achieve erasing for svg, credit: https://travishorn.com/removing-parts-of-shapes-in-svg-b539a89e5649
|
|
84
|
+
* must be called before object markup creation as it relies on the `clipPathId` property of the mask
|
|
85
|
+
* @param {Function} [reviver]
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
_createEraserSVGMarkup: function (reviver) {
|
|
89
|
+
if (this.eraser) {
|
|
90
|
+
this.eraser.clipPathId = 'MASK_' + uid();
|
|
91
|
+
return [
|
|
92
|
+
'<mask id="',
|
|
93
|
+
this.eraser.clipPathId,
|
|
94
|
+
'" >',
|
|
95
|
+
this.eraser.toSVG(reviver),
|
|
96
|
+
'</mask>',
|
|
97
|
+
'\n',
|
|
98
|
+
].join('');
|
|
99
|
+
}
|
|
100
|
+
return '';
|
|
101
|
+
},
|
|
102
|
+
/**
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
_createBaseClipPathSVGMarkup: function (objectMarkup, options) {
|
|
106
|
+
return [
|
|
107
|
+
this._createEraserSVGMarkup(options && options.reviver),
|
|
108
|
+
__createBaseClipPathSVGMarkup.call(this, objectMarkup, options),
|
|
109
|
+
].join('');
|
|
110
|
+
},
|
|
111
|
+
/**
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
_createBaseSVGMarkup: function (objectMarkup, options) {
|
|
115
|
+
return [
|
|
116
|
+
this._createEraserSVGMarkup(options && options.reviver),
|
|
117
|
+
__createBaseSVGMarkup.call(this, objectMarkup, options),
|
|
118
|
+
].join('');
|
|
119
|
+
},
|
|
120
|
+
/* _TO_SVG_END_ */
|
|
121
|
+
});
|
|
122
|
+
fabric.util.object.extend(fabric.Group.prototype, {
|
|
123
|
+
/**
|
|
124
|
+
* @private
|
|
125
|
+
* @param {fabric.Path} path
|
|
126
|
+
* @returns {Promise<fabric.Path[]>}
|
|
127
|
+
*/
|
|
128
|
+
_addEraserPathToObjects: function (path) {
|
|
129
|
+
return Promise.all(this._objects.map(function (object) {
|
|
130
|
+
return fabric.EraserBrush.prototype._addPathToObjectEraser.call(fabric.EraserBrush.prototype, object, path);
|
|
131
|
+
}));
|
|
132
|
+
},
|
|
133
|
+
/**
|
|
134
|
+
* Applies the group's eraser to its objects
|
|
135
|
+
* @tutorial {@link http://fabricjs.com/erasing#erasable_property}
|
|
136
|
+
* @returns {Promise<fabric.Path[]|fabric.Path[][]|void>}
|
|
137
|
+
*/
|
|
138
|
+
applyEraserToObjects: function () {
|
|
139
|
+
var _this = this, eraser = this.eraser;
|
|
140
|
+
return Promise.resolve().then(function () {
|
|
141
|
+
if (eraser) {
|
|
142
|
+
delete _this.eraser;
|
|
143
|
+
var transform = _this.calcTransformMatrix();
|
|
144
|
+
return eraser.clone().then(function (eraser) {
|
|
145
|
+
var clipPath = _this.clipPath;
|
|
146
|
+
return Promise.all(eraser.getObjects('path').map(function (path) {
|
|
147
|
+
// first we transform the path from the group's coordinate system to the canvas'
|
|
148
|
+
var originalTransform = fabric.util.multiplyTransformMatrices(transform, path.calcTransformMatrix());
|
|
149
|
+
fabric.util.applyTransformToObject(path, originalTransform);
|
|
150
|
+
return clipPath
|
|
151
|
+
? clipPath.clone().then(function (_clipPath) {
|
|
152
|
+
var eraserPath = fabric.EraserBrush.prototype.applyClipPathToPath.call(fabric.EraserBrush.prototype, path, _clipPath, transform);
|
|
153
|
+
return _this._addEraserPathToObjects(eraserPath);
|
|
154
|
+
}, ['absolutePositioned', 'inverted'])
|
|
155
|
+
: _this._addEraserPathToObjects(path);
|
|
156
|
+
}));
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
/**
|
|
163
|
+
* An object's Eraser
|
|
164
|
+
* @private
|
|
165
|
+
* @class fabric.Eraser
|
|
166
|
+
* @extends fabric.Group
|
|
167
|
+
* @memberof fabric
|
|
168
|
+
*/
|
|
169
|
+
fabric.Eraser = fabric.util.createClass(fabric.Group, {
|
|
170
|
+
/**
|
|
171
|
+
* @readonly
|
|
172
|
+
* @static
|
|
173
|
+
*/
|
|
174
|
+
type: 'eraser',
|
|
175
|
+
/**
|
|
176
|
+
* @default
|
|
177
|
+
*/
|
|
178
|
+
originX: 'center',
|
|
179
|
+
/**
|
|
180
|
+
* @default
|
|
181
|
+
*/
|
|
182
|
+
originY: 'center',
|
|
183
|
+
/**
|
|
184
|
+
* eraser should retain size
|
|
185
|
+
* dimensions should not change when paths are added or removed
|
|
186
|
+
* handled by {@link fabric.Object#_drawClipPath}
|
|
187
|
+
* @override
|
|
188
|
+
* @private
|
|
189
|
+
*/
|
|
190
|
+
layout: 'fixed',
|
|
191
|
+
drawObject: function (ctx) {
|
|
192
|
+
ctx.save();
|
|
193
|
+
ctx.fillStyle = 'black';
|
|
194
|
+
ctx.fillRect(-this.width / 2, -this.height / 2, this.width, this.height);
|
|
195
|
+
ctx.restore();
|
|
196
|
+
this.callSuper('drawObject', ctx);
|
|
197
|
+
},
|
|
198
|
+
/* _TO_SVG_START_ */
|
|
199
|
+
/**
|
|
200
|
+
* Returns svg representation of an instance
|
|
201
|
+
* use <mask> to achieve erasing for svg, credit: https://travishorn.com/removing-parts-of-shapes-in-svg-b539a89e5649
|
|
202
|
+
* for masking we need to add a white rect before all paths
|
|
203
|
+
*
|
|
204
|
+
* @param {Function} [reviver] Method for further parsing of svg representation.
|
|
205
|
+
* @return {String} svg representation of an instance
|
|
206
|
+
*/
|
|
207
|
+
_toSVG: function (reviver) {
|
|
208
|
+
var svgString = ['<g ', 'COMMON_PARTS', ' >\n'];
|
|
209
|
+
var x = -this.width / 2, y = -this.height / 2;
|
|
210
|
+
var rectSvg = [
|
|
211
|
+
'<rect ',
|
|
212
|
+
'fill="white" ',
|
|
213
|
+
'x="',
|
|
214
|
+
x,
|
|
215
|
+
'" y="',
|
|
216
|
+
y,
|
|
217
|
+
'" width="',
|
|
218
|
+
this.width,
|
|
219
|
+
'" height="',
|
|
220
|
+
this.height,
|
|
221
|
+
'" />\n',
|
|
222
|
+
].join('');
|
|
223
|
+
svgString.push('\t\t', rectSvg);
|
|
224
|
+
for (var i = 0, len = this._objects.length; i < len; i++) {
|
|
225
|
+
svgString.push('\t\t', this._objects[i].toSVG(reviver));
|
|
226
|
+
}
|
|
227
|
+
svgString.push('</g>\n');
|
|
228
|
+
return svgString;
|
|
229
|
+
},
|
|
230
|
+
/* _TO_SVG_END_ */
|
|
231
|
+
});
|
|
232
|
+
/**
|
|
233
|
+
* Returns instance from an object representation
|
|
234
|
+
* @static
|
|
235
|
+
* @memberOf fabric.Eraser
|
|
236
|
+
* @param {Object} object Object to create an Eraser from
|
|
237
|
+
* @returns {Promise<fabric.Eraser>}
|
|
238
|
+
*/
|
|
239
|
+
fabric.Eraser.fromObject = function (object) {
|
|
240
|
+
var objects = object.objects || [], options = fabric.util.object.clone(object, true);
|
|
241
|
+
delete options.objects;
|
|
242
|
+
return Promise.all([
|
|
243
|
+
fabric.util.enlivenObjects(objects),
|
|
244
|
+
fabric.util.enlivenObjectEnlivables(options),
|
|
245
|
+
]).then(function (enlivedProps) {
|
|
246
|
+
return new fabric.Eraser(enlivedProps[0], Object.assign(options, enlivedProps[1]), true);
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
var __renderOverlay = fabric.Canvas.prototype._renderOverlay;
|
|
250
|
+
/**
|
|
251
|
+
* @fires erasing:start
|
|
252
|
+
* @fires erasing:end
|
|
253
|
+
*/
|
|
254
|
+
fabric.util.object.extend(fabric.Canvas.prototype, {
|
|
255
|
+
/**
|
|
256
|
+
* Used by {@link #renderAll}
|
|
257
|
+
* @returns boolean
|
|
258
|
+
*/
|
|
259
|
+
isErasing: function () {
|
|
260
|
+
return (this.isDrawingMode &&
|
|
261
|
+
this.freeDrawingBrush &&
|
|
262
|
+
this.freeDrawingBrush.type === 'eraser' &&
|
|
263
|
+
this.freeDrawingBrush._isErasing);
|
|
264
|
+
},
|
|
265
|
+
/**
|
|
266
|
+
* While erasing the brush clips out the erasing path from canvas
|
|
267
|
+
* so we need to render it on top of canvas every render
|
|
268
|
+
* @param {CanvasRenderingContext2D} ctx
|
|
269
|
+
*/
|
|
270
|
+
_renderOverlay: function (ctx) {
|
|
271
|
+
__renderOverlay.call(this, ctx);
|
|
272
|
+
this.isErasing() && this.freeDrawingBrush._render();
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
/**
|
|
276
|
+
* EraserBrush class
|
|
277
|
+
* Supports selective erasing meaning that only erasable objects are affected by the eraser brush.
|
|
278
|
+
* Supports **inverted** erasing meaning that the brush can "undo" erasing.
|
|
279
|
+
*
|
|
280
|
+
* In order to support selective erasing, the brush clips the entire canvas
|
|
281
|
+
* and then draws all non-erasable objects over the erased path using a pattern brush so to speak (masking).
|
|
282
|
+
* If brush is **inverted** there is no need to clip canvas. The brush draws all erasable objects without their eraser.
|
|
283
|
+
* This achieves the desired effect of seeming to erase or unerase only erasable objects.
|
|
284
|
+
* After erasing is done the created path is added to all intersected objects' `eraser` property.
|
|
285
|
+
*
|
|
286
|
+
* In order to update the EraserBrush call `preparePattern`.
|
|
287
|
+
* It may come in handy when canvas changes during erasing (i.e animations) and you want the eraser to reflect the changes.
|
|
288
|
+
*
|
|
289
|
+
* @tutorial {@link http://fabricjs.com/erasing}
|
|
290
|
+
* @class fabric.EraserBrush
|
|
291
|
+
* @extends fabric.PencilBrush
|
|
292
|
+
* @memberof fabric
|
|
293
|
+
*/
|
|
294
|
+
fabric.EraserBrush = fabric.util.createClass(fabric.PencilBrush,
|
|
295
|
+
/** @lends fabric.EraserBrush.prototype */ {
|
|
296
|
+
type: 'eraser',
|
|
297
|
+
/**
|
|
298
|
+
* When set to `true` the brush will create a visual effect of undoing erasing
|
|
299
|
+
* @type boolean
|
|
300
|
+
*/
|
|
301
|
+
inverted: false,
|
|
302
|
+
/**
|
|
303
|
+
* Used to fix https://github.com/fabricjs/fabric.js/issues/7984
|
|
304
|
+
* Reduces the path width while clipping the main context, resulting in a better visual overlap of both contexts
|
|
305
|
+
* @type number
|
|
306
|
+
*/
|
|
307
|
+
erasingWidthAliasing: 4,
|
|
308
|
+
/**
|
|
309
|
+
* @private
|
|
310
|
+
*/
|
|
311
|
+
_isErasing: false,
|
|
312
|
+
/**
|
|
313
|
+
*
|
|
314
|
+
* @private
|
|
315
|
+
* @param {fabric.Object} object
|
|
316
|
+
* @returns boolean
|
|
317
|
+
*/
|
|
318
|
+
_isErasable: function (object) {
|
|
319
|
+
return object.erasable !== false;
|
|
320
|
+
},
|
|
321
|
+
/**
|
|
322
|
+
* @private
|
|
323
|
+
* This is designed to support erasing a collection with both erasable and non-erasable objects while maintaining object stacking.\
|
|
324
|
+
* Iterates over collections to allow nested selective erasing.\
|
|
325
|
+
* Prepares objects before rendering the pattern brush.\
|
|
326
|
+
* If brush is **NOT** inverted render all non-erasable objects.\
|
|
327
|
+
* If brush is inverted render all objects, erasable objects without their eraser.
|
|
328
|
+
* This will render the erased parts as if they were not erased in the first place, achieving an undo effect.
|
|
329
|
+
*
|
|
330
|
+
* @param {fabric.Collection} collection
|
|
331
|
+
* @param {fabric.Object[]} objects
|
|
332
|
+
* @param {CanvasRenderingContext2D} ctx
|
|
333
|
+
* @param {{ visibility: fabric.Object[], eraser: fabric.Object[], collection: fabric.Object[] }} restorationContext
|
|
334
|
+
*/
|
|
335
|
+
_prepareCollectionTraversal: function (collection, objects, ctx, restorationContext) {
|
|
336
|
+
objects.forEach(function (obj) {
|
|
337
|
+
var dirty = false;
|
|
338
|
+
if (obj.forEachObject && obj.erasable === 'deep') {
|
|
339
|
+
// traverse
|
|
340
|
+
this._prepareCollectionTraversal(obj, obj._objects, ctx, restorationContext);
|
|
341
|
+
}
|
|
342
|
+
else if (!this.inverted && obj.erasable && obj.visible) {
|
|
343
|
+
// render only non-erasable objects
|
|
344
|
+
obj.visible = false;
|
|
345
|
+
restorationContext.visibility.push(obj);
|
|
346
|
+
dirty = true;
|
|
347
|
+
}
|
|
348
|
+
else if (this.inverted &&
|
|
349
|
+
obj.erasable &&
|
|
350
|
+
obj.eraser &&
|
|
351
|
+
obj.visible) {
|
|
352
|
+
// render all objects without eraser
|
|
353
|
+
var eraser = obj.eraser;
|
|
354
|
+
obj.eraser = undefined;
|
|
355
|
+
obj.dirty = true;
|
|
356
|
+
restorationContext.eraser.push([obj, eraser]);
|
|
357
|
+
dirty = true;
|
|
358
|
+
}
|
|
359
|
+
if (dirty && collection instanceof fabric.Object) {
|
|
360
|
+
collection.dirty = true;
|
|
361
|
+
restorationContext.collection.push(collection);
|
|
362
|
+
}
|
|
363
|
+
}, this);
|
|
364
|
+
},
|
|
365
|
+
/**
|
|
366
|
+
* Prepare the pattern for the erasing brush
|
|
367
|
+
* This pattern will be drawn on the top context after clipping the main context,
|
|
368
|
+
* achieving a visual effect of erasing only erasable objects
|
|
369
|
+
* @private
|
|
370
|
+
* @param {fabric.Object[]} [objects] override default behavior by passing objects to render on pattern
|
|
371
|
+
*/
|
|
372
|
+
preparePattern: function (objects) {
|
|
373
|
+
if (!this._patternCanvas) {
|
|
374
|
+
this._patternCanvas = fabric.util.createCanvasElement();
|
|
375
|
+
}
|
|
376
|
+
var canvas = this._patternCanvas;
|
|
377
|
+
objects =
|
|
378
|
+
objects || this.canvas._objectsToRender || this.canvas._objects;
|
|
379
|
+
canvas.width = this.canvas.width;
|
|
380
|
+
canvas.height = this.canvas.height;
|
|
381
|
+
var patternCtx = canvas.getContext('2d');
|
|
382
|
+
if (this.canvas._isRetinaScaling()) {
|
|
383
|
+
var retinaScaling = this.canvas.getRetinaScaling();
|
|
384
|
+
this.canvas.__initRetinaScaling(retinaScaling, canvas, patternCtx);
|
|
385
|
+
}
|
|
386
|
+
var backgroundImage = this.canvas.backgroundImage, bgErasable = backgroundImage && this._isErasable(backgroundImage), overlayImage = this.canvas.overlayImage, overlayErasable = overlayImage && this._isErasable(overlayImage);
|
|
387
|
+
if (!this.inverted &&
|
|
388
|
+
((backgroundImage && !bgErasable) || !!this.canvas.backgroundColor)) {
|
|
389
|
+
if (bgErasable) {
|
|
390
|
+
this.canvas.backgroundImage = undefined;
|
|
391
|
+
}
|
|
392
|
+
this.canvas._renderBackground(patternCtx);
|
|
393
|
+
if (bgErasable) {
|
|
394
|
+
this.canvas.backgroundImage = backgroundImage;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
else if (this.inverted) {
|
|
398
|
+
var eraser = backgroundImage && backgroundImage.eraser;
|
|
399
|
+
if (eraser) {
|
|
400
|
+
backgroundImage.eraser = undefined;
|
|
401
|
+
backgroundImage.dirty = true;
|
|
402
|
+
}
|
|
403
|
+
this.canvas._renderBackground(patternCtx);
|
|
404
|
+
if (eraser) {
|
|
405
|
+
backgroundImage.eraser = eraser;
|
|
406
|
+
backgroundImage.dirty = true;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
patternCtx.save();
|
|
410
|
+
patternCtx.transform.apply(patternCtx, this.canvas.viewportTransform);
|
|
411
|
+
var restorationContext = { visibility: [], eraser: [], collection: [] };
|
|
412
|
+
this._prepareCollectionTraversal(this.canvas, objects, patternCtx, restorationContext);
|
|
413
|
+
this.canvas._renderObjects(patternCtx, objects);
|
|
414
|
+
restorationContext.visibility.forEach(function (obj) {
|
|
415
|
+
obj.visible = true;
|
|
416
|
+
});
|
|
417
|
+
restorationContext.eraser.forEach(function (entry) {
|
|
418
|
+
var obj = entry[0], eraser = entry[1];
|
|
419
|
+
obj.eraser = eraser;
|
|
420
|
+
obj.dirty = true;
|
|
421
|
+
});
|
|
422
|
+
restorationContext.collection.forEach(function (obj) {
|
|
423
|
+
obj.dirty = true;
|
|
424
|
+
});
|
|
425
|
+
patternCtx.restore();
|
|
426
|
+
if (!this.inverted &&
|
|
427
|
+
((overlayImage && !overlayErasable) || !!this.canvas.overlayColor)) {
|
|
428
|
+
if (overlayErasable) {
|
|
429
|
+
this.canvas.overlayImage = undefined;
|
|
430
|
+
}
|
|
431
|
+
__renderOverlay.call(this.canvas, patternCtx);
|
|
432
|
+
if (overlayErasable) {
|
|
433
|
+
this.canvas.overlayImage = overlayImage;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
else if (this.inverted) {
|
|
437
|
+
var eraser = overlayImage && overlayImage.eraser;
|
|
438
|
+
if (eraser) {
|
|
439
|
+
overlayImage.eraser = undefined;
|
|
440
|
+
overlayImage.dirty = true;
|
|
441
|
+
}
|
|
442
|
+
__renderOverlay.call(this.canvas, patternCtx);
|
|
443
|
+
if (eraser) {
|
|
444
|
+
overlayImage.eraser = eraser;
|
|
445
|
+
overlayImage.dirty = true;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
},
|
|
449
|
+
/**
|
|
450
|
+
* Sets brush styles
|
|
451
|
+
* @private
|
|
452
|
+
* @param {CanvasRenderingContext2D} ctx
|
|
453
|
+
*/
|
|
454
|
+
_setBrushStyles: function (ctx) {
|
|
455
|
+
this.callSuper('_setBrushStyles', ctx);
|
|
456
|
+
ctx.strokeStyle = 'black';
|
|
457
|
+
},
|
|
458
|
+
/**
|
|
459
|
+
* **Customiztion**
|
|
460
|
+
*
|
|
461
|
+
* if you need the eraser to update on each render (i.e animating during erasing) override this method by **adding** the following (performance may suffer):
|
|
462
|
+
* @example
|
|
463
|
+
* ```
|
|
464
|
+
* if(ctx === this.canvas.contextTop) {
|
|
465
|
+
* this.preparePattern();
|
|
466
|
+
* }
|
|
467
|
+
* ```
|
|
468
|
+
*
|
|
469
|
+
* @override fabric.BaseBrush#_saveAndTransform
|
|
470
|
+
* @param {CanvasRenderingContext2D} ctx
|
|
471
|
+
*/
|
|
472
|
+
_saveAndTransform: function (ctx) {
|
|
473
|
+
this.callSuper('_saveAndTransform', ctx);
|
|
474
|
+
this._setBrushStyles(ctx);
|
|
475
|
+
ctx.globalCompositeOperation =
|
|
476
|
+
ctx === this.canvas.getContext()
|
|
477
|
+
? 'destination-out'
|
|
478
|
+
: 'destination-in';
|
|
479
|
+
},
|
|
480
|
+
/**
|
|
481
|
+
* We indicate {@link fabric.PencilBrush} to repaint itself if necessary
|
|
482
|
+
* @returns
|
|
483
|
+
*/
|
|
484
|
+
needsFullRender: function () {
|
|
485
|
+
return true;
|
|
486
|
+
},
|
|
487
|
+
/**
|
|
488
|
+
*
|
|
489
|
+
* @param {Point} pointer
|
|
490
|
+
* @param {fabric.IEvent} options
|
|
491
|
+
* @returns
|
|
492
|
+
*/
|
|
493
|
+
onMouseDown: function (pointer, options) {
|
|
494
|
+
if (!this.canvas._isMainEvent(options.e)) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
this._prepareForDrawing(pointer);
|
|
498
|
+
// capture coordinates immediately
|
|
499
|
+
// this allows to draw dots (when movement never occurs)
|
|
500
|
+
this._captureDrawingPath(pointer);
|
|
501
|
+
// prepare for erasing
|
|
502
|
+
this.preparePattern();
|
|
503
|
+
this._isErasing = true;
|
|
504
|
+
this.canvas.fire('erasing:start');
|
|
505
|
+
this._render();
|
|
506
|
+
},
|
|
507
|
+
/**
|
|
508
|
+
* Rendering Logic:
|
|
509
|
+
* 1. Use brush to clip canvas by rendering it on top of canvas (unnecessary if `inverted === true`)
|
|
510
|
+
* 2. Render brush with canvas pattern on top context
|
|
511
|
+
*
|
|
512
|
+
* @todo provide a better solution to https://github.com/fabricjs/fabric.js/issues/7984
|
|
513
|
+
*/
|
|
514
|
+
_render: function () {
|
|
515
|
+
var ctx, lineWidth = this.width;
|
|
516
|
+
var t = this.canvas.getRetinaScaling(), s = 1 / t;
|
|
517
|
+
// clip canvas
|
|
518
|
+
ctx = this.canvas.getContext();
|
|
519
|
+
// a hack that fixes https://github.com/fabricjs/fabric.js/issues/7984 by reducing path width
|
|
520
|
+
// the issue's cause is unknown at time of writing (@ShaMan123 06/2022)
|
|
521
|
+
if (lineWidth - this.erasingWidthAliasing > 0) {
|
|
522
|
+
this.width = lineWidth - this.erasingWidthAliasing;
|
|
523
|
+
this.callSuper('_render', ctx);
|
|
524
|
+
this.width = lineWidth;
|
|
525
|
+
}
|
|
526
|
+
// render brush and mask it with pattern
|
|
527
|
+
ctx = this.canvas.contextTop;
|
|
528
|
+
this.canvas.clearContext(ctx);
|
|
529
|
+
ctx.save();
|
|
530
|
+
ctx.scale(s, s);
|
|
531
|
+
ctx.drawImage(this._patternCanvas, 0, 0);
|
|
532
|
+
ctx.restore();
|
|
533
|
+
this.callSuper('_render', ctx);
|
|
534
|
+
},
|
|
535
|
+
/**
|
|
536
|
+
* Creates fabric.Path object
|
|
537
|
+
* @override
|
|
538
|
+
* @private
|
|
539
|
+
* @param {(string|number)[][]} pathData Path data
|
|
540
|
+
* @return {fabric.Path} Path to add on canvas
|
|
541
|
+
* @returns
|
|
542
|
+
*/
|
|
543
|
+
createPath: function (pathData) {
|
|
544
|
+
var path = this.callSuper('createPath', pathData);
|
|
545
|
+
path.globalCompositeOperation = this.inverted
|
|
546
|
+
? 'source-over'
|
|
547
|
+
: 'destination-out';
|
|
548
|
+
path.stroke = this.inverted ? 'white' : 'black';
|
|
549
|
+
return path;
|
|
550
|
+
},
|
|
551
|
+
/**
|
|
552
|
+
* Utility to apply a clip path to a path.
|
|
553
|
+
* Used to preserve clipping on eraser paths in nested objects.
|
|
554
|
+
* Called when a group has a clip path that should be applied to the path before applying erasing on the group's objects.
|
|
555
|
+
* @param {fabric.Path} path The eraser path in canvas coordinate plane
|
|
556
|
+
* @param {fabric.Object} clipPath The clipPath to apply to the path
|
|
557
|
+
* @param {number[]} clipPathContainerTransformMatrix The transform matrix of the object that the clip path belongs to
|
|
558
|
+
* @returns {fabric.Path} path with clip path
|
|
559
|
+
*/
|
|
560
|
+
applyClipPathToPath: function (path, clipPath, clipPathContainerTransformMatrix) {
|
|
561
|
+
var pathInvTransform = fabric.util.invertTransform(path.calcTransformMatrix()), clipPathTransform = clipPath.calcTransformMatrix(), transform = clipPath.absolutePositioned
|
|
562
|
+
? pathInvTransform
|
|
563
|
+
: fabric.util.multiplyTransformMatrices(pathInvTransform, clipPathContainerTransformMatrix);
|
|
564
|
+
// when passing down a clip path it becomes relative to the parent
|
|
565
|
+
// so we transform it acoordingly and set `absolutePositioned` to false
|
|
566
|
+
clipPath.absolutePositioned = false;
|
|
567
|
+
fabric.util.applyTransformToObject(clipPath, fabric.util.multiplyTransformMatrices(transform, clipPathTransform));
|
|
568
|
+
// We need to clip `path` with both `clipPath` and it's own clip path if existing (`path.clipPath`)
|
|
569
|
+
// so in turn `path` erases an object only where it overlaps with all it's clip paths, regardless of how many there are.
|
|
570
|
+
// this is done because both clip paths may have nested clip paths of their own (this method walks down a collection => this may reccur),
|
|
571
|
+
// so we can't assign one to the other's clip path property.
|
|
572
|
+
path.clipPath = path.clipPath
|
|
573
|
+
? fabric.util.mergeClipPaths(clipPath, path.clipPath)
|
|
574
|
+
: clipPath;
|
|
575
|
+
return path;
|
|
576
|
+
},
|
|
577
|
+
/**
|
|
578
|
+
* Utility to apply a clip path to a path.
|
|
579
|
+
* Used to preserve clipping on eraser paths in nested objects.
|
|
580
|
+
* Called when a group has a clip path that should be applied to the path before applying erasing on the group's objects.
|
|
581
|
+
* @param {fabric.Path} path The eraser path
|
|
582
|
+
* @param {fabric.Object} object The clipPath to apply to path belongs to object
|
|
583
|
+
* @returns {Promise<fabric.Path>}
|
|
584
|
+
*/
|
|
585
|
+
clonePathWithClipPath: function (path, object) {
|
|
586
|
+
var objTransform = object.calcTransformMatrix();
|
|
587
|
+
var clipPath = object.clipPath;
|
|
588
|
+
var _this = this;
|
|
589
|
+
return Promise.all([
|
|
590
|
+
path.clone(),
|
|
591
|
+
clipPath.clone(['absolutePositioned', 'inverted']),
|
|
592
|
+
]).then(function (clones) {
|
|
593
|
+
return _this.applyClipPathToPath(clones[0], clones[1], objTransform);
|
|
594
|
+
});
|
|
595
|
+
},
|
|
596
|
+
/**
|
|
597
|
+
* Adds path to object's eraser, walks down object's descendants if necessary
|
|
598
|
+
*
|
|
599
|
+
* @public
|
|
600
|
+
* @fires erasing:end on object
|
|
601
|
+
* @param {fabric.Object} obj
|
|
602
|
+
* @param {fabric.Path} path
|
|
603
|
+
* @param {Object} [context] context to assign erased objects to
|
|
604
|
+
* @returns {Promise<fabric.Path | fabric.Path[]>}
|
|
605
|
+
*/
|
|
606
|
+
_addPathToObjectEraser: function (obj, path, context) {
|
|
607
|
+
var _this = this;
|
|
608
|
+
// object is collection, i.e group
|
|
609
|
+
if (obj.forEachObject && obj.erasable === 'deep') {
|
|
610
|
+
var targets = obj._objects.filter(function (_obj) {
|
|
611
|
+
return _obj.erasable;
|
|
612
|
+
});
|
|
613
|
+
if (targets.length > 0 && obj.clipPath) {
|
|
614
|
+
return this.clonePathWithClipPath(path, obj).then(function (_path) {
|
|
615
|
+
return Promise.all(targets.map(function (_obj) {
|
|
616
|
+
return _this._addPathToObjectEraser(_obj, _path, context);
|
|
617
|
+
}));
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
else if (targets.length > 0) {
|
|
621
|
+
return Promise.all(targets.map(function (_obj) {
|
|
622
|
+
return _this._addPathToObjectEraser(_obj, path, context);
|
|
623
|
+
}));
|
|
624
|
+
}
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
// prepare eraser
|
|
628
|
+
var eraser = obj.eraser;
|
|
629
|
+
if (!eraser) {
|
|
630
|
+
eraser = new fabric.Eraser();
|
|
631
|
+
obj.eraser = eraser;
|
|
632
|
+
}
|
|
633
|
+
// clone and add path
|
|
634
|
+
return path.clone().then(function (path) {
|
|
635
|
+
// http://fabricjs.com/using-transformations
|
|
636
|
+
var desiredTransform = fabric.util.multiplyTransformMatrices(fabric.util.invertTransform(obj.calcTransformMatrix()), path.calcTransformMatrix());
|
|
637
|
+
fabric.util.applyTransformToObject(path, desiredTransform);
|
|
638
|
+
eraser.add(path);
|
|
639
|
+
obj.set('dirty', true);
|
|
640
|
+
obj.fire('erasing:end', {
|
|
641
|
+
path: path,
|
|
642
|
+
});
|
|
643
|
+
if (context) {
|
|
644
|
+
(obj.group ? context.subTargets : context.targets).push(obj);
|
|
645
|
+
//context.paths.set(obj, path);
|
|
646
|
+
}
|
|
647
|
+
return path;
|
|
648
|
+
});
|
|
649
|
+
},
|
|
650
|
+
/**
|
|
651
|
+
* Add the eraser path to canvas drawables' clip paths
|
|
652
|
+
*
|
|
653
|
+
* @param {fabric.Canvas} source
|
|
654
|
+
* @param {fabric.Canvas} path
|
|
655
|
+
* @param {Object} [context] context to assign erased objects to
|
|
656
|
+
* @returns {Promise<fabric.Path[]|void>} eraser paths
|
|
657
|
+
*/
|
|
658
|
+
applyEraserToCanvas: function (path, context) {
|
|
659
|
+
var canvas = this.canvas;
|
|
660
|
+
return Promise.all(['backgroundImage', 'overlayImage'].map(function (prop) {
|
|
661
|
+
var drawable = canvas[prop];
|
|
662
|
+
return (drawable &&
|
|
663
|
+
drawable.erasable &&
|
|
664
|
+
this._addPathToObjectEraser(drawable, path).then(function (path) {
|
|
665
|
+
if (context) {
|
|
666
|
+
context.drawables[prop] = drawable;
|
|
667
|
+
//context.paths.set(drawable, path);
|
|
668
|
+
}
|
|
669
|
+
return path;
|
|
670
|
+
}));
|
|
671
|
+
}, this));
|
|
672
|
+
},
|
|
673
|
+
/**
|
|
674
|
+
* On mouseup after drawing the path on contextTop canvas
|
|
675
|
+
* we use the points captured to create an new fabric path object
|
|
676
|
+
* and add it to every intersected erasable object.
|
|
677
|
+
*/
|
|
678
|
+
_finalizeAndAddPath: function () {
|
|
679
|
+
var ctx = this.canvas.contextTop, canvas = this.canvas;
|
|
680
|
+
ctx.closePath();
|
|
681
|
+
if (this.decimate) {
|
|
682
|
+
this._points = this.decimatePoints(this._points, this.decimate);
|
|
683
|
+
}
|
|
684
|
+
// clear
|
|
685
|
+
canvas.clearContext(canvas.contextTop);
|
|
686
|
+
this._isErasing = false;
|
|
687
|
+
var pathData = this._points && this._points.length > 1
|
|
688
|
+
? this.convertPointsToSVGPath(this._points)
|
|
689
|
+
: null;
|
|
690
|
+
if (!pathData || this._isEmptySVGPath(pathData)) {
|
|
691
|
+
canvas.fire('erasing:end');
|
|
692
|
+
// do not create 0 width/height paths, as they are
|
|
693
|
+
// rendered inconsistently across browsers
|
|
694
|
+
// Firefox 4, for example, renders a dot,
|
|
695
|
+
// whereas Chrome 10 renders nothing
|
|
696
|
+
canvas.requestRenderAll();
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
var path = this.createPath(pathData);
|
|
700
|
+
// needed for `intersectsWithObject`
|
|
701
|
+
path.setCoords();
|
|
702
|
+
// commense event sequence
|
|
703
|
+
canvas.fire('before:path:created', { path: path });
|
|
704
|
+
// finalize erasing
|
|
705
|
+
var _this = this;
|
|
706
|
+
var context = {
|
|
707
|
+
targets: [],
|
|
708
|
+
subTargets: [],
|
|
709
|
+
//paths: new Map(),
|
|
710
|
+
drawables: {},
|
|
711
|
+
};
|
|
712
|
+
var tasks = canvas._objects.map(function (obj) {
|
|
713
|
+
return (obj.erasable &&
|
|
714
|
+
obj.intersectsWithObject(path, true, true) &&
|
|
715
|
+
_this._addPathToObjectEraser(obj, path, context));
|
|
716
|
+
});
|
|
717
|
+
tasks.push(_this.applyEraserToCanvas(path, context));
|
|
718
|
+
return Promise.all(tasks).then(function () {
|
|
719
|
+
// fire erasing:end
|
|
720
|
+
canvas.fire('erasing:end', Object.assign(context, {
|
|
721
|
+
path: path,
|
|
722
|
+
}));
|
|
723
|
+
canvas.requestRenderAll();
|
|
724
|
+
_this._resetShadow();
|
|
725
|
+
// fire event 'path' created
|
|
726
|
+
canvas.fire('path:created', { path: path });
|
|
727
|
+
});
|
|
728
|
+
},
|
|
729
|
+
});
|
|
730
|
+
/** ERASER_END */
|
|
731
|
+
})(typeof exports !== 'undefined' ? exports : window);
|
|
732
|
+
//# sourceMappingURL=eraser_brush.mixin.js.map
|