fabric-vectr 6.7.16 → 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 +2 -2
- 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 +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +2 -2
- 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 +2 -2
- 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.js +910 -0
- package/dist/src/shapes/Textbox.js.map +1 -0
- 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/package.json +1 -1
- package/src/gradient/Gradient.ts +5 -2
|
@@ -0,0 +1,1392 @@
|
|
|
1
|
+
import { cache } from '../../cache';
|
|
2
|
+
import { config } from '../../config';
|
|
3
|
+
import { ALIASING_LIMIT, CENTER, iMatrix, LEFT, SCALE_X, SCALE_Y, STROKE, FILL, TOP, VERSION, } from '../../constants';
|
|
4
|
+
import { Point } from '../../Point';
|
|
5
|
+
import { Shadow } from '../../Shadow';
|
|
6
|
+
import { classRegistry } from '../../ClassRegistry';
|
|
7
|
+
import { runningAnimations } from '../../util/animation/AnimationRegistry';
|
|
8
|
+
import { capValue } from '../../util/misc/capValue';
|
|
9
|
+
import { createCanvasElement, createCanvasElementFor, toDataURL, toBlob, } from '../../util/misc/dom';
|
|
10
|
+
import { invertTransform, qrDecompose } from '../../util/misc/matrix';
|
|
11
|
+
import { enlivenObjectEnlivables } from '../../util/misc/objectEnlive';
|
|
12
|
+
import { resetObjectTransform, saveObjectTransform, } from '../../util/misc/objectTransforms';
|
|
13
|
+
import { sendObjectToPlane } from '../../util/misc/planeChange';
|
|
14
|
+
import { pick, pickBy } from '../../util/misc/pick';
|
|
15
|
+
import { toFixed } from '../../util/misc/toFixed';
|
|
16
|
+
import { StaticCanvas } from '../../canvas/StaticCanvas';
|
|
17
|
+
import { isFiller, isSerializableFiller } from '../../util/typeAssertions';
|
|
18
|
+
import { cacheProperties, fabricObjectDefaultValues, stateProperties, } from './defaultValues';
|
|
19
|
+
import { getDevicePixelRatio, getEnv } from '../../env';
|
|
20
|
+
import { log } from '../../util/internals/console';
|
|
21
|
+
import { animate, animateColor } from '../../util/animation/animate';
|
|
22
|
+
import { ObjectGeometry } from './ObjectGeometry';
|
|
23
|
+
/**
|
|
24
|
+
* Root object class from which all 2d shape classes inherit from
|
|
25
|
+
* @tutorial {@link http://fabricjs.com/fabric-intro-part-1#objects}
|
|
26
|
+
*
|
|
27
|
+
* @fires added
|
|
28
|
+
* @fires removed
|
|
29
|
+
*
|
|
30
|
+
* @fires selected
|
|
31
|
+
* @fires deselected
|
|
32
|
+
*
|
|
33
|
+
* @fires rotating
|
|
34
|
+
* @fires scaling
|
|
35
|
+
* @fires moving
|
|
36
|
+
* @fires skewing
|
|
37
|
+
* @fires modified
|
|
38
|
+
*
|
|
39
|
+
* @fires mousedown
|
|
40
|
+
* @fires mouseup
|
|
41
|
+
* @fires mouseover
|
|
42
|
+
* @fires mouseout
|
|
43
|
+
* @fires mousewheel
|
|
44
|
+
* @fires mousedblclick
|
|
45
|
+
*
|
|
46
|
+
* @fires dragover
|
|
47
|
+
* @fires dragenter
|
|
48
|
+
* @fires dragleave
|
|
49
|
+
* @fires drop
|
|
50
|
+
*/
|
|
51
|
+
export class FabricObject extends ObjectGeometry {
|
|
52
|
+
/**
|
|
53
|
+
* This list of properties is used to check if the state of an object is changed.
|
|
54
|
+
* This state change now is only used for children of groups to understand if a group
|
|
55
|
+
* needs its cache regenerated during a .set call
|
|
56
|
+
* @type Array
|
|
57
|
+
*/
|
|
58
|
+
static stateProperties = stateProperties;
|
|
59
|
+
/**
|
|
60
|
+
* List of properties to consider when checking if cache needs refresh
|
|
61
|
+
* Those properties are checked by
|
|
62
|
+
* calls to Object.set(key, value). If the key is in this list, the object is marked as dirty
|
|
63
|
+
* and refreshed at the next render
|
|
64
|
+
* @type Array
|
|
65
|
+
*/
|
|
66
|
+
static cacheProperties = cacheProperties;
|
|
67
|
+
/**
|
|
68
|
+
* Quick access for the _cacheCanvas rendering context
|
|
69
|
+
* This is part of the objectCaching feature
|
|
70
|
+
* since 1.7.0
|
|
71
|
+
* @type boolean
|
|
72
|
+
* @default undefined
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
_cacheContext = null;
|
|
76
|
+
static ownDefaults = fabricObjectDefaultValues;
|
|
77
|
+
static getDefaults() {
|
|
78
|
+
return FabricObject.ownDefaults;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The class type.
|
|
82
|
+
* This is used for serialization and deserialization purposes and internally it can be used
|
|
83
|
+
* to identify classes.
|
|
84
|
+
* When we transform a class in a plain JS object we need a way to recognize which class it was,
|
|
85
|
+
* and the type is the way we do that. It has no other purposes and you should not give one.
|
|
86
|
+
* Hard to reach on instances and please do not use to drive instance's logic (this.constructor.type).
|
|
87
|
+
* To idenfity a class use instanceof class ( instanceof Rect ).
|
|
88
|
+
* We do not do that in fabricJS code because we want to try to have code splitting possible.
|
|
89
|
+
*/
|
|
90
|
+
static type = 'FabricObject';
|
|
91
|
+
/**
|
|
92
|
+
* Legacy identifier of the class. Prefer using utils like isType or instanceOf
|
|
93
|
+
* Will be removed in fabric 7 or 8.
|
|
94
|
+
* The setter exists to avoid type errors in old code and possibly current deserialization code.
|
|
95
|
+
* DO NOT build new code around this type value
|
|
96
|
+
* @TODO add sustainable warning message
|
|
97
|
+
* @type string
|
|
98
|
+
* @deprecated
|
|
99
|
+
*/
|
|
100
|
+
get type() {
|
|
101
|
+
const name = this.constructor.type;
|
|
102
|
+
if (name === 'FabricObject') {
|
|
103
|
+
return 'object';
|
|
104
|
+
}
|
|
105
|
+
return name.toLowerCase();
|
|
106
|
+
}
|
|
107
|
+
set type(value) {
|
|
108
|
+
log('warn', 'Setting type has no effect', value);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Constructor
|
|
112
|
+
* @param {Object} [options] Options object
|
|
113
|
+
*/
|
|
114
|
+
constructor(options) {
|
|
115
|
+
super();
|
|
116
|
+
Object.assign(this, FabricObject.ownDefaults);
|
|
117
|
+
this.setOptions(options);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Create a the canvas used to keep the cached copy of the object
|
|
121
|
+
* @private
|
|
122
|
+
*/
|
|
123
|
+
_createCacheCanvas() {
|
|
124
|
+
this._cacheCanvas = createCanvasElement();
|
|
125
|
+
this._cacheContext = this._cacheCanvas.getContext('2d');
|
|
126
|
+
this._updateCacheCanvas();
|
|
127
|
+
// if canvas gets created, is empty, so dirty.
|
|
128
|
+
this.dirty = true;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Limit the cache dimensions so that X * Y do not cross config.perfLimitSizeTotal
|
|
132
|
+
* and each side do not cross fabric.cacheSideLimit
|
|
133
|
+
* those numbers are configurable so that you can get as much detail as you want
|
|
134
|
+
* making bargain with performances.
|
|
135
|
+
* @param {Object} dims
|
|
136
|
+
* @param {Object} dims.width width of canvas
|
|
137
|
+
* @param {Object} dims.height height of canvas
|
|
138
|
+
* @param {Object} dims.zoomX zoomX zoom value to unscale the canvas before drawing cache
|
|
139
|
+
* @param {Object} dims.zoomY zoomY zoom value to unscale the canvas before drawing cache
|
|
140
|
+
* @return {Object}.width width of canvas
|
|
141
|
+
* @return {Object}.height height of canvas
|
|
142
|
+
* @return {Object}.zoomX zoomX zoom value to unscale the canvas before drawing cache
|
|
143
|
+
* @return {Object}.zoomY zoomY zoom value to unscale the canvas before drawing cache
|
|
144
|
+
*/
|
|
145
|
+
_limitCacheSize(dims) {
|
|
146
|
+
const width = dims.width, height = dims.height, max = config.maxCacheSideLimit, min = config.minCacheSideLimit;
|
|
147
|
+
if (width <= max &&
|
|
148
|
+
height <= max &&
|
|
149
|
+
width * height <= config.perfLimitSizeTotal) {
|
|
150
|
+
if (width < min) {
|
|
151
|
+
dims.width = min;
|
|
152
|
+
}
|
|
153
|
+
if (height < min) {
|
|
154
|
+
dims.height = min;
|
|
155
|
+
}
|
|
156
|
+
return dims;
|
|
157
|
+
}
|
|
158
|
+
const ar = width / height, [limX, limY] = cache.limitDimsByArea(ar), x = capValue(min, limX, max), y = capValue(min, limY, max);
|
|
159
|
+
if (width > x) {
|
|
160
|
+
dims.zoomX /= width / x;
|
|
161
|
+
dims.width = x;
|
|
162
|
+
dims.capped = true;
|
|
163
|
+
}
|
|
164
|
+
if (height > y) {
|
|
165
|
+
dims.zoomY /= height / y;
|
|
166
|
+
dims.height = y;
|
|
167
|
+
dims.capped = true;
|
|
168
|
+
}
|
|
169
|
+
return dims;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Return the dimension and the zoom level needed to create a cache canvas
|
|
173
|
+
* big enough to host the object to be cached.
|
|
174
|
+
* @private
|
|
175
|
+
* @return {Object}.x width of object to be cached
|
|
176
|
+
* @return {Object}.y height of object to be cached
|
|
177
|
+
* @return {Object}.width width of canvas
|
|
178
|
+
* @return {Object}.height height of canvas
|
|
179
|
+
* @return {Object}.zoomX zoomX zoom value to unscale the canvas before drawing cache
|
|
180
|
+
* @return {Object}.zoomY zoomY zoom value to unscale the canvas before drawing cache
|
|
181
|
+
*/
|
|
182
|
+
_getCacheCanvasDimensions() {
|
|
183
|
+
const objectScale = this.getTotalObjectScaling(),
|
|
184
|
+
// calculate dimensions without skewing
|
|
185
|
+
dim = this._getTransformedDimensions({ skewX: 0, skewY: 0 }), neededX = (dim.x * objectScale.x) / this.scaleX, neededY = (dim.y * objectScale.y) / this.scaleY;
|
|
186
|
+
return {
|
|
187
|
+
// for sure this ALIASING_LIMIT is slightly creating problem
|
|
188
|
+
// in situation in which the cache canvas gets an upper limit
|
|
189
|
+
// also objectScale contains already scaleX and scaleY
|
|
190
|
+
width: Math.ceil(neededX + ALIASING_LIMIT),
|
|
191
|
+
height: Math.ceil(neededY + ALIASING_LIMIT),
|
|
192
|
+
zoomX: objectScale.x,
|
|
193
|
+
zoomY: objectScale.y,
|
|
194
|
+
x: neededX,
|
|
195
|
+
y: neededY,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Update width and height of the canvas for cache
|
|
200
|
+
* returns true or false if canvas needed resize.
|
|
201
|
+
* @private
|
|
202
|
+
* @return {Boolean} true if the canvas has been resized
|
|
203
|
+
*/
|
|
204
|
+
_updateCacheCanvas() {
|
|
205
|
+
const canvas = this._cacheCanvas, context = this._cacheContext, { width, height, zoomX, zoomY, x, y } = this._limitCacheSize(this._getCacheCanvasDimensions()), dimensionsChanged = width !== canvas.width || height !== canvas.height, zoomChanged = this.zoomX !== zoomX || this.zoomY !== zoomY;
|
|
206
|
+
if (!canvas || !context) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
const shouldRedraw = dimensionsChanged || zoomChanged;
|
|
210
|
+
if (shouldRedraw) {
|
|
211
|
+
if (width !== canvas.width || height !== canvas.height) {
|
|
212
|
+
canvas.width = width;
|
|
213
|
+
canvas.height = height;
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
217
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
218
|
+
}
|
|
219
|
+
const drawingWidth = x / 2;
|
|
220
|
+
const drawingHeight = y / 2;
|
|
221
|
+
this.cacheTranslationX =
|
|
222
|
+
Math.round(canvas.width / 2 - drawingWidth) + drawingWidth;
|
|
223
|
+
this.cacheTranslationY =
|
|
224
|
+
Math.round(canvas.height / 2 - drawingHeight) + drawingHeight;
|
|
225
|
+
context.translate(this.cacheTranslationX, this.cacheTranslationY);
|
|
226
|
+
context.scale(zoomX, zoomY);
|
|
227
|
+
this.zoomX = zoomX;
|
|
228
|
+
this.zoomY = zoomY;
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Sets object's properties from options, for class constructor only.
|
|
235
|
+
* Needs to be overridden for different defaults.
|
|
236
|
+
* @protected
|
|
237
|
+
* @param {Object} [options] Options object
|
|
238
|
+
*/
|
|
239
|
+
setOptions(options = {}) {
|
|
240
|
+
this._setOptions(options);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Transforms context when rendering an object
|
|
244
|
+
* @param {CanvasRenderingContext2D} ctx Context
|
|
245
|
+
*/
|
|
246
|
+
transform(ctx) {
|
|
247
|
+
const needFullTransform = (this.group && !this.group._transformDone) ||
|
|
248
|
+
(this.group && this.canvas && ctx === this.canvas.contextTop);
|
|
249
|
+
const m = this.calcTransformMatrix(!needFullTransform);
|
|
250
|
+
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Return the object scale factor counting also the group scaling
|
|
254
|
+
* @return {Point}
|
|
255
|
+
*/
|
|
256
|
+
getObjectScaling() {
|
|
257
|
+
// if the object is a top level one, on the canvas, we go for simple aritmetic
|
|
258
|
+
// otherwise the complex method with angles will return approximations and decimals
|
|
259
|
+
// and will likely kill the cache when not needed
|
|
260
|
+
// https://github.com/fabricjs/fabric.js/issues/7157
|
|
261
|
+
if (!this.group) {
|
|
262
|
+
return new Point(Math.abs(this.scaleX), Math.abs(this.scaleY));
|
|
263
|
+
}
|
|
264
|
+
// if we are inside a group total zoom calculation is complex, we defer to generic matrices
|
|
265
|
+
const options = qrDecompose(this.calcTransformMatrix());
|
|
266
|
+
return new Point(Math.abs(options.scaleX), Math.abs(options.scaleY));
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Return the object scale factor counting also the group scaling, zoom and retina
|
|
270
|
+
* @return {Object} object with scaleX and scaleY properties
|
|
271
|
+
*/
|
|
272
|
+
getTotalObjectScaling() {
|
|
273
|
+
const scale = this.getObjectScaling();
|
|
274
|
+
if (this.canvas) {
|
|
275
|
+
const zoom = this.canvas.getZoom();
|
|
276
|
+
const retina = this.getCanvasRetinaScaling();
|
|
277
|
+
return scale.scalarMultiply(zoom * retina);
|
|
278
|
+
}
|
|
279
|
+
return scale;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Return the object opacity counting also the group property
|
|
283
|
+
* @return {Number}
|
|
284
|
+
*/
|
|
285
|
+
getObjectOpacity() {
|
|
286
|
+
let opacity = this.opacity;
|
|
287
|
+
if (this.group) {
|
|
288
|
+
opacity *= this.group.getObjectOpacity();
|
|
289
|
+
}
|
|
290
|
+
return opacity;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Makes sure the scale is valid and modifies it if necessary
|
|
294
|
+
* @todo: this is a control action issue, not a geometry one
|
|
295
|
+
* @private
|
|
296
|
+
* @param {Number} value, unconstrained
|
|
297
|
+
* @return {Number} constrained value;
|
|
298
|
+
*/
|
|
299
|
+
_constrainScale(value) {
|
|
300
|
+
if (Math.abs(value) < this.minScaleLimit) {
|
|
301
|
+
if (value < 0) {
|
|
302
|
+
return -this.minScaleLimit;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
return this.minScaleLimit;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
else if (value === 0) {
|
|
309
|
+
return 0.0001;
|
|
310
|
+
}
|
|
311
|
+
return value;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Handles setting values on the instance and handling internal side effects
|
|
315
|
+
* @protected
|
|
316
|
+
* @param {String} key
|
|
317
|
+
* @param {*} value
|
|
318
|
+
*/
|
|
319
|
+
_set(key, value) {
|
|
320
|
+
if (key === SCALE_X || key === SCALE_Y) {
|
|
321
|
+
value = this._constrainScale(value);
|
|
322
|
+
}
|
|
323
|
+
if (key === SCALE_X && value < 0) {
|
|
324
|
+
this.flipX = !this.flipX;
|
|
325
|
+
value *= -1;
|
|
326
|
+
}
|
|
327
|
+
else if (key === 'scaleY' && value < 0) {
|
|
328
|
+
this.flipY = !this.flipY;
|
|
329
|
+
value *= -1;
|
|
330
|
+
// i don't like this automatic initialization here
|
|
331
|
+
}
|
|
332
|
+
else if (key === 'shadow' && value && !(value instanceof Shadow)) {
|
|
333
|
+
value = new Shadow(value);
|
|
334
|
+
}
|
|
335
|
+
const isChanged = this[key] !== value;
|
|
336
|
+
this[key] = value;
|
|
337
|
+
// invalidate caches
|
|
338
|
+
if (isChanged &&
|
|
339
|
+
this.constructor.cacheProperties.includes(key)) {
|
|
340
|
+
this.dirty = true;
|
|
341
|
+
}
|
|
342
|
+
// a dirty child makes the parent dirty.
|
|
343
|
+
// but a non dirty child does not make the parent not dirty.
|
|
344
|
+
// the parent could be dirty for some other reason.
|
|
345
|
+
this.parent &&
|
|
346
|
+
(this.dirty ||
|
|
347
|
+
(isChanged &&
|
|
348
|
+
this.constructor.stateProperties.includes(key))) &&
|
|
349
|
+
this.parent._set('dirty', true);
|
|
350
|
+
return this;
|
|
351
|
+
}
|
|
352
|
+
/*
|
|
353
|
+
* @private
|
|
354
|
+
* return if the object would be visible in rendering
|
|
355
|
+
* @memberOf FabricObject.prototype
|
|
356
|
+
* @return {Boolean}
|
|
357
|
+
*/
|
|
358
|
+
isNotVisible() {
|
|
359
|
+
return (this.opacity === 0 ||
|
|
360
|
+
(!this.width && !this.height && this.strokeWidth === 0) ||
|
|
361
|
+
!this.visible);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Renders an object on a specified context
|
|
365
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
366
|
+
*/
|
|
367
|
+
render(ctx) {
|
|
368
|
+
// do not render if width/height are zeros or object is not visible
|
|
369
|
+
if (this.isNotVisible()) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (this.canvas &&
|
|
373
|
+
this.canvas.skipOffscreen &&
|
|
374
|
+
!this.group &&
|
|
375
|
+
!this.isOnScreen()) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
ctx.save();
|
|
379
|
+
this._setupCompositeOperation(ctx);
|
|
380
|
+
this.drawSelectionBackground(ctx);
|
|
381
|
+
this.transform(ctx);
|
|
382
|
+
this._setOpacity(ctx);
|
|
383
|
+
this._setShadow(ctx);
|
|
384
|
+
if (this.shouldCache()) {
|
|
385
|
+
this.renderCache();
|
|
386
|
+
this.drawCacheOnCanvas(ctx);
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
this._removeCacheCanvas();
|
|
390
|
+
this.drawObject(ctx, false, {});
|
|
391
|
+
this.dirty = false;
|
|
392
|
+
}
|
|
393
|
+
ctx.restore();
|
|
394
|
+
}
|
|
395
|
+
drawSelectionBackground(_ctx) {
|
|
396
|
+
/* no op */
|
|
397
|
+
}
|
|
398
|
+
renderCache(options) {
|
|
399
|
+
options = options || {};
|
|
400
|
+
if (!this._cacheCanvas || !this._cacheContext) {
|
|
401
|
+
this._createCacheCanvas();
|
|
402
|
+
}
|
|
403
|
+
if (this.isCacheDirty() && this._cacheContext) {
|
|
404
|
+
const { zoomX, zoomY, cacheTranslationX, cacheTranslationY } = this;
|
|
405
|
+
const { width, height } = this._cacheCanvas;
|
|
406
|
+
this.drawObject(this._cacheContext, options.forClipping, {
|
|
407
|
+
zoomX,
|
|
408
|
+
zoomY,
|
|
409
|
+
cacheTranslationX,
|
|
410
|
+
cacheTranslationY,
|
|
411
|
+
width,
|
|
412
|
+
height,
|
|
413
|
+
parentClipPaths: [],
|
|
414
|
+
});
|
|
415
|
+
this.dirty = false;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Remove cacheCanvas and its dimensions from the objects
|
|
420
|
+
*/
|
|
421
|
+
_removeCacheCanvas() {
|
|
422
|
+
this._cacheCanvas = undefined;
|
|
423
|
+
this._cacheContext = null;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* return true if the object will draw a stroke
|
|
427
|
+
* Does not consider text styles. This is just a shortcut used at rendering time
|
|
428
|
+
* We want it to be an approximation and be fast.
|
|
429
|
+
* wrote to avoid extra caching, it has to return true when stroke happens,
|
|
430
|
+
* can guess when it will not happen at 100% chance, does not matter if it misses
|
|
431
|
+
* some use case where the stroke is invisible.
|
|
432
|
+
* @since 3.0.0
|
|
433
|
+
* @returns Boolean
|
|
434
|
+
*/
|
|
435
|
+
hasStroke() {
|
|
436
|
+
return (this.stroke && this.stroke !== 'transparent' && this.strokeWidth !== 0);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* return true if the object will draw a fill
|
|
440
|
+
* Does not consider text styles. This is just a shortcut used at rendering time
|
|
441
|
+
* We want it to be an approximation and be fast.
|
|
442
|
+
* wrote to avoid extra caching, it has to return true when fill happens,
|
|
443
|
+
* can guess when it will not happen at 100% chance, does not matter if it misses
|
|
444
|
+
* some use case where the fill is invisible.
|
|
445
|
+
* @since 3.0.0
|
|
446
|
+
* @returns Boolean
|
|
447
|
+
*/
|
|
448
|
+
hasFill() {
|
|
449
|
+
return this.fill && this.fill !== 'transparent';
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* When returns `true`, force the object to have its own cache, even if it is inside a group
|
|
453
|
+
* it may be needed when your object behave in a particular way on the cache and always needs
|
|
454
|
+
* its own isolated canvas to render correctly.
|
|
455
|
+
* Created to be overridden
|
|
456
|
+
* since 1.7.12
|
|
457
|
+
* @returns Boolean
|
|
458
|
+
*/
|
|
459
|
+
needsItsOwnCache() {
|
|
460
|
+
// TODO re-evaluate this shadow condition
|
|
461
|
+
if (this.paintFirst === STROKE &&
|
|
462
|
+
this.hasFill() &&
|
|
463
|
+
this.hasStroke() &&
|
|
464
|
+
!!this.shadow) {
|
|
465
|
+
return true;
|
|
466
|
+
}
|
|
467
|
+
if (this.clipPath) {
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
return false;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Decide if the object should cache or not. Create its own cache level
|
|
474
|
+
* objectCaching is a global flag, wins over everything
|
|
475
|
+
* needsItsOwnCache should be used when the object drawing method requires
|
|
476
|
+
* a cache step.
|
|
477
|
+
* Generally you do not cache objects in groups because the group outside is cached.
|
|
478
|
+
* Read as: cache if is needed, or if the feature is enabled but we are not already caching.
|
|
479
|
+
* @return {Boolean}
|
|
480
|
+
*/
|
|
481
|
+
shouldCache() {
|
|
482
|
+
this.ownCaching =
|
|
483
|
+
(this.objectCaching && (!this.parent || !this.parent.isOnACache())) ||
|
|
484
|
+
this.needsItsOwnCache();
|
|
485
|
+
return this.ownCaching;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Check if this object will cast a shadow with an offset.
|
|
489
|
+
* used by Group.shouldCache to know if child has a shadow recursively
|
|
490
|
+
* @return {Boolean}
|
|
491
|
+
* @deprecated
|
|
492
|
+
*/
|
|
493
|
+
willDrawShadow() {
|
|
494
|
+
return (!!this.shadow && (this.shadow.offsetX !== 0 || this.shadow.offsetY !== 0));
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Execute the drawing operation for an object clipPath
|
|
498
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
499
|
+
* @param {FabricObject} clipPath
|
|
500
|
+
*/
|
|
501
|
+
drawClipPathOnCache(ctx, clipPath, canvasWithClipPath) {
|
|
502
|
+
ctx.save();
|
|
503
|
+
// DEBUG: uncomment this line, comment the following
|
|
504
|
+
// ctx.globalAlpha = 0.4
|
|
505
|
+
if (clipPath.inverted) {
|
|
506
|
+
ctx.globalCompositeOperation = 'destination-out';
|
|
507
|
+
}
|
|
508
|
+
else {
|
|
509
|
+
ctx.globalCompositeOperation = 'destination-in';
|
|
510
|
+
}
|
|
511
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
512
|
+
ctx.drawImage(canvasWithClipPath, 0, 0);
|
|
513
|
+
ctx.restore();
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Execute the drawing operation for an object on a specified context
|
|
517
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
518
|
+
* @param {boolean} forClipping apply clipping styles
|
|
519
|
+
* @param {DrawContext} context additional context for rendering
|
|
520
|
+
*/
|
|
521
|
+
drawObject(ctx, forClipping, context) {
|
|
522
|
+
const originalFill = this.fill, originalStroke = this.stroke;
|
|
523
|
+
if (forClipping) {
|
|
524
|
+
this.fill = 'black';
|
|
525
|
+
this.stroke = '';
|
|
526
|
+
this._setClippingProperties(ctx);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
this._renderBackground(ctx);
|
|
530
|
+
}
|
|
531
|
+
this._render(ctx);
|
|
532
|
+
this._drawClipPath(ctx, this.clipPath, context);
|
|
533
|
+
this.fill = originalFill;
|
|
534
|
+
this.stroke = originalStroke;
|
|
535
|
+
}
|
|
536
|
+
createClipPathLayer(clipPath, context) {
|
|
537
|
+
const canvas = createCanvasElementFor(context);
|
|
538
|
+
const ctx = canvas.getContext('2d');
|
|
539
|
+
ctx.translate(context.cacheTranslationX, context.cacheTranslationY);
|
|
540
|
+
ctx.scale(context.zoomX, context.zoomY);
|
|
541
|
+
clipPath._cacheCanvas = canvas;
|
|
542
|
+
context.parentClipPaths.forEach((prevClipPath) => {
|
|
543
|
+
prevClipPath.transform(ctx);
|
|
544
|
+
});
|
|
545
|
+
context.parentClipPaths.push(clipPath);
|
|
546
|
+
if (clipPath.absolutePositioned) {
|
|
547
|
+
const m = invertTransform(this.calcTransformMatrix());
|
|
548
|
+
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
549
|
+
}
|
|
550
|
+
clipPath.transform(ctx);
|
|
551
|
+
clipPath.drawObject(ctx, true, context);
|
|
552
|
+
return canvas;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Prepare clipPath state and cache and draw it on instance's cache
|
|
556
|
+
* @param {CanvasRenderingContext2D} ctx
|
|
557
|
+
* @param {FabricObject} clipPath
|
|
558
|
+
*/
|
|
559
|
+
_drawClipPath(ctx, clipPath, context) {
|
|
560
|
+
if (!clipPath) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
// needed to setup _transformDone
|
|
564
|
+
// TODO find a better solution?
|
|
565
|
+
clipPath._transformDone = true;
|
|
566
|
+
const canvas = this.createClipPathLayer(clipPath, context);
|
|
567
|
+
this.drawClipPathOnCache(ctx, clipPath, canvas);
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Paint the cached copy of the object on the target context.
|
|
571
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
572
|
+
*/
|
|
573
|
+
drawCacheOnCanvas(ctx) {
|
|
574
|
+
ctx.scale(1 / this.zoomX, 1 / this.zoomY);
|
|
575
|
+
ctx.drawImage(this._cacheCanvas, -this.cacheTranslationX, -this.cacheTranslationY);
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Check if cache is dirty and if is dirty clear the context.
|
|
579
|
+
* This check has a big side effect, it changes the underlying cache canvas if necessary.
|
|
580
|
+
* Do not call this method on your own to check if the cache is dirty, because if it is,
|
|
581
|
+
* it is also going to wipe the cache. This is badly designed and needs to be fixed.
|
|
582
|
+
* @param {Boolean} skipCanvas skip canvas checks because this object is painted
|
|
583
|
+
* on parent canvas.
|
|
584
|
+
*/
|
|
585
|
+
isCacheDirty(skipCanvas = false) {
|
|
586
|
+
if (this.isNotVisible()) {
|
|
587
|
+
return false;
|
|
588
|
+
}
|
|
589
|
+
const canvas = this._cacheCanvas;
|
|
590
|
+
const ctx = this._cacheContext;
|
|
591
|
+
if (canvas && ctx && !skipCanvas && this._updateCacheCanvas()) {
|
|
592
|
+
// in this case the context is already cleared.
|
|
593
|
+
return true;
|
|
594
|
+
}
|
|
595
|
+
else {
|
|
596
|
+
if (this.dirty || (this.clipPath && this.clipPath.absolutePositioned)) {
|
|
597
|
+
if (canvas && ctx && !skipCanvas) {
|
|
598
|
+
ctx.save();
|
|
599
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
600
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
601
|
+
ctx.restore();
|
|
602
|
+
}
|
|
603
|
+
return true;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
return false;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Draws a background for the object big as its untransformed dimensions
|
|
610
|
+
* @private
|
|
611
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
612
|
+
*/
|
|
613
|
+
_renderBackground(ctx) {
|
|
614
|
+
if (!this.backgroundColor) {
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
const dim = this._getNonTransformedDimensions();
|
|
618
|
+
ctx.fillStyle = this.backgroundColor;
|
|
619
|
+
ctx.fillRect(-dim.x / 2, -dim.y / 2, dim.x, dim.y);
|
|
620
|
+
// if there is background color no other shadows
|
|
621
|
+
// should be casted
|
|
622
|
+
this._removeShadow(ctx);
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* @private
|
|
626
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
627
|
+
*/
|
|
628
|
+
_setOpacity(ctx) {
|
|
629
|
+
if (this.group && !this.group._transformDone) {
|
|
630
|
+
ctx.globalAlpha = this.getObjectOpacity();
|
|
631
|
+
}
|
|
632
|
+
else {
|
|
633
|
+
ctx.globalAlpha *= this.opacity;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
_setStrokeStyles(ctx, decl) {
|
|
637
|
+
const stroke = decl.stroke;
|
|
638
|
+
if (stroke) {
|
|
639
|
+
ctx.lineWidth = decl.strokeWidth;
|
|
640
|
+
ctx.lineCap = decl.strokeLineCap;
|
|
641
|
+
ctx.lineDashOffset = decl.strokeDashOffset;
|
|
642
|
+
ctx.lineJoin = decl.strokeLineJoin;
|
|
643
|
+
ctx.miterLimit = decl.strokeMiterLimit;
|
|
644
|
+
if (isFiller(stroke)) {
|
|
645
|
+
if (stroke.gradientUnits === 'percentage' ||
|
|
646
|
+
stroke.gradientTransform ||
|
|
647
|
+
stroke.patternTransform) {
|
|
648
|
+
// need to transform gradient in a pattern.
|
|
649
|
+
// this is a slow process. If you are hitting this codepath, and the object
|
|
650
|
+
// is not using caching, you should consider switching it on.
|
|
651
|
+
// we need a canvas as big as the current object caching canvas.
|
|
652
|
+
this._applyPatternForTransformedGradient(ctx, stroke);
|
|
653
|
+
}
|
|
654
|
+
else {
|
|
655
|
+
// is a simple gradient or pattern
|
|
656
|
+
ctx.strokeStyle = stroke.toLive(ctx);
|
|
657
|
+
this._applyPatternGradientTransform(ctx, stroke);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
else {
|
|
661
|
+
// is a color
|
|
662
|
+
ctx.strokeStyle = decl.stroke;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
_setFillStyles(ctx, { fill }) {
|
|
667
|
+
if (fill) {
|
|
668
|
+
if (isFiller(fill)) {
|
|
669
|
+
ctx.fillStyle = fill.toLive(ctx);
|
|
670
|
+
this._applyPatternGradientTransform(ctx, fill);
|
|
671
|
+
}
|
|
672
|
+
else {
|
|
673
|
+
ctx.fillStyle = fill;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
_setClippingProperties(ctx) {
|
|
678
|
+
ctx.globalAlpha = 1;
|
|
679
|
+
ctx.strokeStyle = 'transparent';
|
|
680
|
+
ctx.fillStyle = '#000000';
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* @private
|
|
684
|
+
* Sets line dash
|
|
685
|
+
* @param {CanvasRenderingContext2D} ctx Context to set the dash line on
|
|
686
|
+
* @param {Array} dashArray array representing dashes
|
|
687
|
+
*/
|
|
688
|
+
_setLineDash(ctx, dashArray) {
|
|
689
|
+
if (!dashArray || dashArray.length === 0) {
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
ctx.setLineDash(dashArray);
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* @private
|
|
696
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
697
|
+
*/
|
|
698
|
+
_setShadow(ctx) {
|
|
699
|
+
if (!this.shadow) {
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
const shadow = this.shadow, canvas = this.canvas, retinaScaling = this.getCanvasRetinaScaling(), [sx, , , sy] = canvas?.viewportTransform || iMatrix, multX = sx * retinaScaling, multY = sy * retinaScaling, scaling = shadow.nonScaling ? new Point(1, 1) : this.getObjectScaling();
|
|
703
|
+
ctx.shadowColor = shadow.color;
|
|
704
|
+
ctx.shadowBlur =
|
|
705
|
+
(shadow.blur *
|
|
706
|
+
config.browserShadowBlurConstant *
|
|
707
|
+
(multX + multY) *
|
|
708
|
+
(scaling.x + scaling.y)) /
|
|
709
|
+
4;
|
|
710
|
+
ctx.shadowOffsetX = shadow.offsetX * multX * scaling.x;
|
|
711
|
+
ctx.shadowOffsetY = shadow.offsetY * multY * scaling.y;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* @private
|
|
715
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
716
|
+
*/
|
|
717
|
+
_removeShadow(ctx) {
|
|
718
|
+
if (!this.shadow) {
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
ctx.shadowColor = '';
|
|
722
|
+
ctx.shadowBlur = ctx.shadowOffsetX = ctx.shadowOffsetY = 0;
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* @private
|
|
726
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
727
|
+
* @param {TFiller} filler {@link Pattern} or {@link Gradient}
|
|
728
|
+
*/
|
|
729
|
+
_applyPatternGradientTransform(ctx, filler) {
|
|
730
|
+
if (!isFiller(filler)) {
|
|
731
|
+
return { offsetX: 0, offsetY: 0 };
|
|
732
|
+
}
|
|
733
|
+
const t = filler.gradientTransform ||
|
|
734
|
+
filler.patternTransform;
|
|
735
|
+
const offsetX = -this.width / 2 + filler.offsetX || 0, offsetY = -this.height / 2 + filler.offsetY || 0;
|
|
736
|
+
if (filler.gradientUnits === 'percentage') {
|
|
737
|
+
ctx.transform(this.width, 0, 0, this.height, offsetX, offsetY);
|
|
738
|
+
}
|
|
739
|
+
else {
|
|
740
|
+
ctx.transform(1, 0, 0, 1, offsetX, offsetY);
|
|
741
|
+
}
|
|
742
|
+
if (t) {
|
|
743
|
+
ctx.transform(t[0], t[1], t[2], t[3], t[4], t[5]);
|
|
744
|
+
}
|
|
745
|
+
return { offsetX: offsetX, offsetY: offsetY };
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* @private
|
|
749
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
750
|
+
*/
|
|
751
|
+
_renderPaintInOrder(ctx) {
|
|
752
|
+
if (this.paintFirst === STROKE) {
|
|
753
|
+
this._renderStroke(ctx);
|
|
754
|
+
this._renderFill(ctx);
|
|
755
|
+
}
|
|
756
|
+
else {
|
|
757
|
+
this._renderFill(ctx);
|
|
758
|
+
this._renderStroke(ctx);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* @private
|
|
763
|
+
* function that actually render something on the context.
|
|
764
|
+
* empty here to allow Obects to work on tests to benchmark fabric functionalites
|
|
765
|
+
* not related to rendering
|
|
766
|
+
* @param {CanvasRenderingContext2D} _ctx Context to render on
|
|
767
|
+
*/
|
|
768
|
+
_render(_ctx) {
|
|
769
|
+
// placeholder to be overridden
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* @private
|
|
773
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
774
|
+
*/
|
|
775
|
+
_renderFill(ctx) {
|
|
776
|
+
if (!this.fill) {
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
ctx.save();
|
|
780
|
+
this._setFillStyles(ctx, this);
|
|
781
|
+
if (this.fillRule === 'evenodd') {
|
|
782
|
+
ctx.fill('evenodd');
|
|
783
|
+
}
|
|
784
|
+
else {
|
|
785
|
+
ctx.fill();
|
|
786
|
+
}
|
|
787
|
+
ctx.restore();
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* @private
|
|
791
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
792
|
+
*/
|
|
793
|
+
_renderStroke(ctx) {
|
|
794
|
+
if (!this.stroke || this.strokeWidth === 0) {
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
if (this.shadow && !this.shadow.affectStroke) {
|
|
798
|
+
this._removeShadow(ctx);
|
|
799
|
+
}
|
|
800
|
+
ctx.save();
|
|
801
|
+
if (this.strokeUniform) {
|
|
802
|
+
const scaling = this.getObjectScaling();
|
|
803
|
+
ctx.scale(1 / scaling.x, 1 / scaling.y);
|
|
804
|
+
}
|
|
805
|
+
this._setLineDash(ctx, this.strokeDashArray);
|
|
806
|
+
this._setStrokeStyles(ctx, this);
|
|
807
|
+
ctx.stroke();
|
|
808
|
+
ctx.restore();
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* This function try to patch the missing gradientTransform on canvas gradients.
|
|
812
|
+
* transforming a context to transform the gradient, is going to transform the stroke too.
|
|
813
|
+
* we want to transform the gradient but not the stroke operation, so we create
|
|
814
|
+
* a transformed gradient on a pattern and then we use the pattern instead of the gradient.
|
|
815
|
+
* this method has drawbacks: is slow, is in low resolution, needs a patch for when the size
|
|
816
|
+
* is limited.
|
|
817
|
+
* @private
|
|
818
|
+
* @param {CanvasRenderingContext2D} ctx Context to render on
|
|
819
|
+
* @param {Gradient} filler
|
|
820
|
+
*/
|
|
821
|
+
_applyPatternForTransformedGradient(ctx, filler) {
|
|
822
|
+
const dims = this._limitCacheSize(this._getCacheCanvasDimensions()), retinaScaling = this.getCanvasRetinaScaling(), width = dims.x / this.scaleX / retinaScaling, height = dims.y / this.scaleY / retinaScaling, pCanvas = createCanvasElementFor({
|
|
823
|
+
// in case width and height are less than 1px, we have to round up.
|
|
824
|
+
// since the pattern is no-repeat, this is fine
|
|
825
|
+
width: Math.ceil(width),
|
|
826
|
+
height: Math.ceil(height),
|
|
827
|
+
});
|
|
828
|
+
const pCtx = pCanvas.getContext('2d');
|
|
829
|
+
if (!pCtx) {
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
pCtx.beginPath();
|
|
833
|
+
pCtx.moveTo(0, 0);
|
|
834
|
+
pCtx.lineTo(width, 0);
|
|
835
|
+
pCtx.lineTo(width, height);
|
|
836
|
+
pCtx.lineTo(0, height);
|
|
837
|
+
pCtx.closePath();
|
|
838
|
+
pCtx.translate(width / 2, height / 2);
|
|
839
|
+
pCtx.scale(dims.zoomX / this.scaleX / retinaScaling, dims.zoomY / this.scaleY / retinaScaling);
|
|
840
|
+
this._applyPatternGradientTransform(pCtx, filler);
|
|
841
|
+
pCtx.fillStyle = filler.toLive(ctx);
|
|
842
|
+
pCtx.fill();
|
|
843
|
+
ctx.translate(-this.width / 2 - this.strokeWidth / 2, -this.height / 2 - this.strokeWidth / 2);
|
|
844
|
+
ctx.scale((retinaScaling * this.scaleX) / dims.zoomX, (retinaScaling * this.scaleY) / dims.zoomY);
|
|
845
|
+
ctx.strokeStyle = pCtx.createPattern(pCanvas, 'no-repeat') ?? '';
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* This function is an helper for svg import. it returns the center of the object in the svg
|
|
849
|
+
* untransformed coordinates
|
|
850
|
+
* @private
|
|
851
|
+
* @return {Point} center point from element coordinates
|
|
852
|
+
*/
|
|
853
|
+
_findCenterFromElement() {
|
|
854
|
+
return new Point(this.left + this.width / 2, this.top + this.height / 2);
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Clones an instance.
|
|
858
|
+
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
|
|
859
|
+
* @returns {Promise<FabricObject>}
|
|
860
|
+
*/
|
|
861
|
+
clone(propertiesToInclude) {
|
|
862
|
+
const objectForm = this.toObject(propertiesToInclude);
|
|
863
|
+
return this.constructor.fromObject(objectForm);
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Creates an instance of Image out of an object
|
|
867
|
+
* makes use of toCanvasElement.
|
|
868
|
+
* Once this method was based on toDataUrl and loadImage, so it also had a quality
|
|
869
|
+
* and format option. toCanvasElement is faster and produce no loss of quality.
|
|
870
|
+
* If you need to get a real Jpeg or Png from an object, using toDataURL is the right way to do it.
|
|
871
|
+
* toCanvasElement and then toBlob from the obtained canvas is also a good option.
|
|
872
|
+
* @todo fix the export type, it could not be Image but the type that getClass return for 'image'.
|
|
873
|
+
* @param {ObjectToCanvasElementOptions} [options] for clone as image, passed to toDataURL
|
|
874
|
+
* @param {Number} [options.multiplier=1] Multiplier to scale by
|
|
875
|
+
* @param {Number} [options.left] Cropping left offset. Introduced in v1.2.14
|
|
876
|
+
* @param {Number} [options.top] Cropping top offset. Introduced in v1.2.14
|
|
877
|
+
* @param {Number} [options.width] Cropping width. Introduced in v1.2.14
|
|
878
|
+
* @param {Number} [options.height] Cropping height. Introduced in v1.2.14
|
|
879
|
+
* @param {Boolean} [options.enableRetinaScaling] Enable retina scaling for clone image. Introduce in 1.6.4
|
|
880
|
+
* @param {Boolean} [options.withoutTransform] Remove current object transform ( no scale , no angle, no flip, no skew ). Introduced in 2.3.4
|
|
881
|
+
* @param {Boolean} [options.withoutShadow] Remove current object shadow. Introduced in 2.4.2
|
|
882
|
+
* @return {FabricImage} Object cloned as image.
|
|
883
|
+
*/
|
|
884
|
+
cloneAsImage(options) {
|
|
885
|
+
const canvasEl = this.toCanvasElement(options);
|
|
886
|
+
// TODO: how to import Image w/o an import cycle?
|
|
887
|
+
const ImageClass = classRegistry.getClass('image');
|
|
888
|
+
return new ImageClass(canvasEl);
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Converts an object into a HTMLCanvas element
|
|
892
|
+
* @param {ObjectToCanvasElementOptions} options Options object
|
|
893
|
+
* @param {Number} [options.multiplier=1] Multiplier to scale by
|
|
894
|
+
* @param {Number} [options.left] Cropping left offset. Introduced in v1.2.14
|
|
895
|
+
* @param {Number} [options.top] Cropping top offset. Introduced in v1.2.14
|
|
896
|
+
* @param {Number} [options.width] Cropping width. Introduced in v1.2.14
|
|
897
|
+
* @param {Number} [options.height] Cropping height. Introduced in v1.2.14
|
|
898
|
+
* @param {Boolean} [options.enableRetinaScaling] Enable retina scaling for clone image. Introduce in 1.6.4
|
|
899
|
+
* @param {Boolean} [options.withoutTransform] Remove current object transform ( no scale , no angle, no flip, no skew ). Introduced in 2.3.4
|
|
900
|
+
* @param {Boolean} [options.withoutShadow] Remove current object shadow. Introduced in 2.4.2
|
|
901
|
+
* @param {Boolean} [options.viewportTransform] Account for canvas viewport transform
|
|
902
|
+
* @param {(el?: HTMLCanvasElement) => StaticCanvas} [options.canvasProvider] Create the output canvas
|
|
903
|
+
* @return {HTMLCanvasElement} Returns DOM element <canvas> with the FabricObject
|
|
904
|
+
*/
|
|
905
|
+
toCanvasElement(options = {}) {
|
|
906
|
+
const origParams = saveObjectTransform(this), originalGroup = this.group, originalShadow = this.shadow, abs = Math.abs, retinaScaling = options.enableRetinaScaling ? getDevicePixelRatio() : 1, multiplier = (options.multiplier || 1) * retinaScaling, canvasProvider = options.canvasProvider ||
|
|
907
|
+
((el) => new StaticCanvas(el, {
|
|
908
|
+
enableRetinaScaling: false,
|
|
909
|
+
renderOnAddRemove: false,
|
|
910
|
+
skipOffscreen: false,
|
|
911
|
+
}));
|
|
912
|
+
delete this.group;
|
|
913
|
+
if (options.withoutTransform) {
|
|
914
|
+
resetObjectTransform(this);
|
|
915
|
+
}
|
|
916
|
+
if (options.withoutShadow) {
|
|
917
|
+
this.shadow = null;
|
|
918
|
+
}
|
|
919
|
+
if (options.viewportTransform) {
|
|
920
|
+
sendObjectToPlane(this, this.getViewportTransform());
|
|
921
|
+
}
|
|
922
|
+
this.setCoords();
|
|
923
|
+
const el = createCanvasElement(), boundingRect = this.getBoundingRect(), shadow = this.shadow, shadowOffset = new Point();
|
|
924
|
+
if (shadow) {
|
|
925
|
+
const shadowBlur = shadow.blur;
|
|
926
|
+
const scaling = shadow.nonScaling
|
|
927
|
+
? new Point(1, 1)
|
|
928
|
+
: this.getObjectScaling();
|
|
929
|
+
// consider non scaling shadow.
|
|
930
|
+
shadowOffset.x =
|
|
931
|
+
2 * Math.round(abs(shadow.offsetX) + shadowBlur) * abs(scaling.x);
|
|
932
|
+
shadowOffset.y =
|
|
933
|
+
2 * Math.round(abs(shadow.offsetY) + shadowBlur) * abs(scaling.y);
|
|
934
|
+
}
|
|
935
|
+
const width = boundingRect.width + shadowOffset.x, height = boundingRect.height + shadowOffset.y;
|
|
936
|
+
// if the current width/height is not an integer
|
|
937
|
+
// we need to make it so.
|
|
938
|
+
el.width = Math.ceil(width);
|
|
939
|
+
el.height = Math.ceil(height);
|
|
940
|
+
const canvas = canvasProvider(el);
|
|
941
|
+
if (options.format === 'jpeg') {
|
|
942
|
+
canvas.backgroundColor = '#fff';
|
|
943
|
+
}
|
|
944
|
+
this.setPositionByOrigin(new Point(canvas.width / 2, canvas.height / 2), CENTER, CENTER);
|
|
945
|
+
const originalCanvas = this.canvas;
|
|
946
|
+
// static canvas and canvas have both an array of InteractiveObjects
|
|
947
|
+
// @ts-expect-error this needs to be fixed somehow, or ignored globally
|
|
948
|
+
canvas._objects = [this];
|
|
949
|
+
this.set('canvas', canvas);
|
|
950
|
+
this.setCoords();
|
|
951
|
+
const canvasEl = canvas.toCanvasElement(multiplier || 1, options);
|
|
952
|
+
this.set('canvas', originalCanvas);
|
|
953
|
+
this.shadow = originalShadow;
|
|
954
|
+
if (originalGroup) {
|
|
955
|
+
this.group = originalGroup;
|
|
956
|
+
}
|
|
957
|
+
this.set(origParams);
|
|
958
|
+
this.setCoords();
|
|
959
|
+
// canvas.dispose will call image.dispose that will nullify the elements
|
|
960
|
+
// since this canvas is a simple element for the process, we remove references
|
|
961
|
+
// to objects in this way in order to avoid object trashing.
|
|
962
|
+
canvas._objects = [];
|
|
963
|
+
// since render has settled it is safe to destroy canvas
|
|
964
|
+
canvas.destroy();
|
|
965
|
+
return canvasEl;
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Converts an object into a data-url-like string
|
|
969
|
+
* @param {Object} options Options object
|
|
970
|
+
* @param {String} [options.format=png] The format of the output image. Either "jpeg" or "png"
|
|
971
|
+
* @param {Number} [options.quality=1] Quality level (0..1). Only used for jpeg.
|
|
972
|
+
* @param {Number} [options.multiplier=1] Multiplier to scale by
|
|
973
|
+
* @param {Number} [options.left] Cropping left offset. Introduced in v1.2.14
|
|
974
|
+
* @param {Number} [options.top] Cropping top offset. Introduced in v1.2.14
|
|
975
|
+
* @param {Number} [options.width] Cropping width. Introduced in v1.2.14
|
|
976
|
+
* @param {Number} [options.height] Cropping height. Introduced in v1.2.14
|
|
977
|
+
* @param {Boolean} [options.enableRetinaScaling] Enable retina scaling for clone image. Introduce in 1.6.4
|
|
978
|
+
* @param {Boolean} [options.withoutTransform] Remove current object transform ( no scale , no angle, no flip, no skew ). Introduced in 2.3.4
|
|
979
|
+
* @param {Boolean} [options.withoutShadow] Remove current object shadow. Introduced in 2.4.2
|
|
980
|
+
* @return {String} Returns a data: URL containing a representation of the object in the format specified by options.format
|
|
981
|
+
*/
|
|
982
|
+
toDataURL(options = {}) {
|
|
983
|
+
return toDataURL(this.toCanvasElement(options), options.format || 'png', options.quality || 1);
|
|
984
|
+
}
|
|
985
|
+
toBlob(options = {}) {
|
|
986
|
+
return toBlob(this.toCanvasElement(options), options.format || 'png', options.quality || 1);
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Returns true if any of the specified types is identical to the type of an instance
|
|
990
|
+
* @param {String} type Type to check against
|
|
991
|
+
* @return {Boolean}
|
|
992
|
+
*/
|
|
993
|
+
isType(...types) {
|
|
994
|
+
return (types.includes(this.constructor.type) ||
|
|
995
|
+
types.includes(this.type));
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Returns complexity of an instance
|
|
999
|
+
* @return {Number} complexity of this instance (is 1 unless subclassed)
|
|
1000
|
+
*/
|
|
1001
|
+
complexity() {
|
|
1002
|
+
return 1;
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Returns a JSON representation of an instance
|
|
1006
|
+
* @return {Object} JSON
|
|
1007
|
+
*/
|
|
1008
|
+
toJSON() {
|
|
1009
|
+
// delegate, not alias
|
|
1010
|
+
return this.toObject();
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Sets "angle" of an instance with centered rotation
|
|
1014
|
+
* @param {TDegree} angle Angle value (in degrees)
|
|
1015
|
+
*/
|
|
1016
|
+
rotate(angle) {
|
|
1017
|
+
const { centeredRotation, originX, originY } = this;
|
|
1018
|
+
if (centeredRotation) {
|
|
1019
|
+
const { x, y } = this.getRelativeCenterPoint();
|
|
1020
|
+
this.originX = CENTER;
|
|
1021
|
+
this.originY = CENTER;
|
|
1022
|
+
this.left = x;
|
|
1023
|
+
this.top = y;
|
|
1024
|
+
}
|
|
1025
|
+
this.set('angle', angle);
|
|
1026
|
+
if (centeredRotation) {
|
|
1027
|
+
const { x, y } = this.translateToOriginPoint(this.getRelativeCenterPoint(), originX, originY);
|
|
1028
|
+
this.left = x;
|
|
1029
|
+
this.top = y;
|
|
1030
|
+
this.originX = originX;
|
|
1031
|
+
this.originY = originY;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
/**
|
|
1035
|
+
* This callback function is called by the parent group of an object every
|
|
1036
|
+
* time a non-delegated property changes on the group. It is passed the key
|
|
1037
|
+
* and value as parameters. Not adding in this function's signature to avoid
|
|
1038
|
+
* Travis build error about unused variables.
|
|
1039
|
+
*/
|
|
1040
|
+
setOnGroup() {
|
|
1041
|
+
// implemented by sub-classes, as needed.
|
|
1042
|
+
}
|
|
1043
|
+
/**
|
|
1044
|
+
* Sets canvas globalCompositeOperation for specific object
|
|
1045
|
+
* custom composition operation for the particular object can be specified using globalCompositeOperation property
|
|
1046
|
+
* @param {CanvasRenderingContext2D} ctx Rendering canvas context
|
|
1047
|
+
*/
|
|
1048
|
+
_setupCompositeOperation(ctx) {
|
|
1049
|
+
if (this.globalCompositeOperation) {
|
|
1050
|
+
ctx.globalCompositeOperation = this.globalCompositeOperation;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* cancel instance's running animations
|
|
1055
|
+
* override if necessary to dispose artifacts such as `clipPath`
|
|
1056
|
+
*/
|
|
1057
|
+
dispose() {
|
|
1058
|
+
runningAnimations.cancelByTarget(this);
|
|
1059
|
+
this.off();
|
|
1060
|
+
this._set('canvas', undefined);
|
|
1061
|
+
// clear caches
|
|
1062
|
+
this._cacheCanvas && getEnv().dispose(this._cacheCanvas);
|
|
1063
|
+
this._cacheCanvas = undefined;
|
|
1064
|
+
this._cacheContext = null;
|
|
1065
|
+
}
|
|
1066
|
+
// #region Animation methods
|
|
1067
|
+
/**
|
|
1068
|
+
* List of properties to consider for animating colors.
|
|
1069
|
+
* @type String[]
|
|
1070
|
+
*/
|
|
1071
|
+
static colorProperties = [FILL, STROKE, 'backgroundColor'];
|
|
1072
|
+
/**
|
|
1073
|
+
* Animates object's properties
|
|
1074
|
+
* @param {Record<string, number | number[] | TColorArg>} animatable map of keys and end values
|
|
1075
|
+
* @param {Partial<AnimationOptions<T>>} options
|
|
1076
|
+
* @tutorial {@link http://fabricjs.com/fabric-intro-part-2#animation}
|
|
1077
|
+
* @return {Record<string, TAnimation<T>>} map of animation contexts
|
|
1078
|
+
*
|
|
1079
|
+
* As object — multiple properties
|
|
1080
|
+
*
|
|
1081
|
+
* object.animate({ left: ..., top: ... });
|
|
1082
|
+
* object.animate({ left: ..., top: ... }, { duration: ... });
|
|
1083
|
+
*/
|
|
1084
|
+
animate(animatable, options) {
|
|
1085
|
+
return Object.entries(animatable).reduce((acc, [key, endValue]) => {
|
|
1086
|
+
acc[key] = this._animate(key, endValue, options);
|
|
1087
|
+
return acc;
|
|
1088
|
+
}, {});
|
|
1089
|
+
}
|
|
1090
|
+
/**
|
|
1091
|
+
* @private
|
|
1092
|
+
* @param {String} key Property to animate
|
|
1093
|
+
* @param {String} to Value to animate to
|
|
1094
|
+
* @param {Object} [options] Options object
|
|
1095
|
+
*/
|
|
1096
|
+
_animate(key, endValue, options = {}) {
|
|
1097
|
+
const path = key.split('.');
|
|
1098
|
+
const propIsColor = this.constructor.colorProperties.includes(path[path.length - 1]);
|
|
1099
|
+
const { abort, startValue, onChange, onComplete } = options;
|
|
1100
|
+
const animationOptions = {
|
|
1101
|
+
...options,
|
|
1102
|
+
target: this,
|
|
1103
|
+
// path.reduce... is the current value in case start value isn't provided
|
|
1104
|
+
startValue: startValue ?? path.reduce((deep, key) => deep[key], this),
|
|
1105
|
+
endValue,
|
|
1106
|
+
abort: abort?.bind(this),
|
|
1107
|
+
onChange: (value, valueProgress, durationProgress) => {
|
|
1108
|
+
path.reduce((deep, key, index) => {
|
|
1109
|
+
if (index === path.length - 1) {
|
|
1110
|
+
deep[key] = value;
|
|
1111
|
+
}
|
|
1112
|
+
return deep[key];
|
|
1113
|
+
}, this);
|
|
1114
|
+
onChange &&
|
|
1115
|
+
// @ts-expect-error generic callback arg0 is wrong
|
|
1116
|
+
onChange(value, valueProgress, durationProgress);
|
|
1117
|
+
},
|
|
1118
|
+
onComplete: (value, valueProgress, durationProgress) => {
|
|
1119
|
+
this.setCoords();
|
|
1120
|
+
onComplete &&
|
|
1121
|
+
// @ts-expect-error generic callback arg0 is wrong
|
|
1122
|
+
onComplete(value, valueProgress, durationProgress);
|
|
1123
|
+
},
|
|
1124
|
+
};
|
|
1125
|
+
return (propIsColor
|
|
1126
|
+
? animateColor(animationOptions)
|
|
1127
|
+
: animate(animationOptions));
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Checks if object is descendant of target
|
|
1131
|
+
* Should be used instead of {@link Group.contains} or {@link StaticCanvas.contains} for performance reasons
|
|
1132
|
+
* @param {TAncestor} target
|
|
1133
|
+
* @returns {boolean}
|
|
1134
|
+
*/
|
|
1135
|
+
isDescendantOf(target) {
|
|
1136
|
+
const { parent, group } = this;
|
|
1137
|
+
return (parent === target ||
|
|
1138
|
+
group === target ||
|
|
1139
|
+
// walk up
|
|
1140
|
+
(!!parent && parent.isDescendantOf(target)) ||
|
|
1141
|
+
(!!group && group !== parent && group.isDescendantOf(target)));
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* @returns {Ancestors} ancestors (excluding `ActiveSelection`) from bottom to top
|
|
1145
|
+
*/
|
|
1146
|
+
getAncestors() {
|
|
1147
|
+
const ancestors = [];
|
|
1148
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
1149
|
+
let parent = this;
|
|
1150
|
+
do {
|
|
1151
|
+
parent = parent.parent;
|
|
1152
|
+
parent && ancestors.push(parent);
|
|
1153
|
+
} while (parent);
|
|
1154
|
+
return ancestors;
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* Compare ancestors
|
|
1158
|
+
*
|
|
1159
|
+
* @param {StackedObject} other
|
|
1160
|
+
* @returns {AncestryComparison} an object that represent the ancestry situation.
|
|
1161
|
+
*/
|
|
1162
|
+
findCommonAncestors(other) {
|
|
1163
|
+
if (this === other) {
|
|
1164
|
+
return {
|
|
1165
|
+
fork: [],
|
|
1166
|
+
otherFork: [],
|
|
1167
|
+
common: [this, ...this.getAncestors()],
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
const ancestors = this.getAncestors();
|
|
1171
|
+
const otherAncestors = other.getAncestors();
|
|
1172
|
+
// if `this` has no ancestors and `this` is top ancestor of `other` we must handle the following case
|
|
1173
|
+
if (ancestors.length === 0 &&
|
|
1174
|
+
otherAncestors.length > 0 &&
|
|
1175
|
+
this === otherAncestors[otherAncestors.length - 1]) {
|
|
1176
|
+
return {
|
|
1177
|
+
fork: [],
|
|
1178
|
+
otherFork: [
|
|
1179
|
+
other,
|
|
1180
|
+
...otherAncestors.slice(0, otherAncestors.length - 1),
|
|
1181
|
+
],
|
|
1182
|
+
common: [this],
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
// compare ancestors
|
|
1186
|
+
for (let i = 0, ancestor; i < ancestors.length; i++) {
|
|
1187
|
+
ancestor = ancestors[i];
|
|
1188
|
+
if (ancestor === other) {
|
|
1189
|
+
return {
|
|
1190
|
+
fork: [this, ...ancestors.slice(0, i)],
|
|
1191
|
+
otherFork: [],
|
|
1192
|
+
common: ancestors.slice(i),
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
for (let j = 0; j < otherAncestors.length; j++) {
|
|
1196
|
+
if (this === otherAncestors[j]) {
|
|
1197
|
+
return {
|
|
1198
|
+
fork: [],
|
|
1199
|
+
otherFork: [other, ...otherAncestors.slice(0, j)],
|
|
1200
|
+
common: [this, ...ancestors],
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
if (ancestor === otherAncestors[j]) {
|
|
1204
|
+
return {
|
|
1205
|
+
fork: [this, ...ancestors.slice(0, i)],
|
|
1206
|
+
otherFork: [other, ...otherAncestors.slice(0, j)],
|
|
1207
|
+
common: ancestors.slice(i),
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
// nothing shared
|
|
1213
|
+
return {
|
|
1214
|
+
fork: [this, ...ancestors],
|
|
1215
|
+
otherFork: [other, ...otherAncestors],
|
|
1216
|
+
common: [],
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
*
|
|
1221
|
+
* @param {StackedObject} other
|
|
1222
|
+
* @returns {boolean}
|
|
1223
|
+
*/
|
|
1224
|
+
hasCommonAncestors(other) {
|
|
1225
|
+
const commonAncestors = this.findCommonAncestors(other);
|
|
1226
|
+
return commonAncestors && !!commonAncestors.common.length;
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
*
|
|
1230
|
+
* @param {FabricObject} other object to compare against
|
|
1231
|
+
* @returns {boolean | undefined} if objects do not share a common ancestor or they are strictly equal it is impossible to determine which is in front of the other; in such cases the function returns `undefined`
|
|
1232
|
+
*/
|
|
1233
|
+
isInFrontOf(other) {
|
|
1234
|
+
if (this === other) {
|
|
1235
|
+
return undefined;
|
|
1236
|
+
}
|
|
1237
|
+
const ancestorData = this.findCommonAncestors(other);
|
|
1238
|
+
if (ancestorData.fork.includes(other)) {
|
|
1239
|
+
return true;
|
|
1240
|
+
}
|
|
1241
|
+
if (ancestorData.otherFork.includes(this)) {
|
|
1242
|
+
return false;
|
|
1243
|
+
}
|
|
1244
|
+
// if there isn't a common ancestor, we take the canvas.
|
|
1245
|
+
// if there is no canvas, there is nothing to compare
|
|
1246
|
+
const firstCommonAncestor = ancestorData.common[0] || this.canvas;
|
|
1247
|
+
if (!firstCommonAncestor) {
|
|
1248
|
+
return undefined;
|
|
1249
|
+
}
|
|
1250
|
+
const headOfFork = ancestorData.fork.pop(), headOfOtherFork = ancestorData.otherFork.pop(), thisIndex = firstCommonAncestor._objects.indexOf(headOfFork), otherIndex = firstCommonAncestor._objects.indexOf(headOfOtherFork);
|
|
1251
|
+
return thisIndex > -1 && thisIndex > otherIndex;
|
|
1252
|
+
}
|
|
1253
|
+
// #region Serialization
|
|
1254
|
+
/**
|
|
1255
|
+
* Define a list of custom properties that will be serialized when
|
|
1256
|
+
* instance.toObject() gets called
|
|
1257
|
+
*/
|
|
1258
|
+
static customProperties = [];
|
|
1259
|
+
/**
|
|
1260
|
+
* Returns an object representation of an instance
|
|
1261
|
+
* @param {string[]} [propertiesToInclude] Any properties that you might want to additionally include in the output
|
|
1262
|
+
* @return {Object} Object representation of an instance
|
|
1263
|
+
*/
|
|
1264
|
+
toObject(propertiesToInclude = []) {
|
|
1265
|
+
const propertiesToSerialize = propertiesToInclude.concat(FabricObject.customProperties, this.constructor.customProperties || []);
|
|
1266
|
+
let clipPathData;
|
|
1267
|
+
const NUM_FRACTION_DIGITS = config.NUM_FRACTION_DIGITS;
|
|
1268
|
+
const { clipPath, fill, stroke, shadow, strokeDashArray, left, top, originX, originY, width, height, strokeWidth, strokeLineCap, strokeDashOffset, strokeLineJoin, strokeUniform, strokeMiterLimit, scaleX, scaleY, angle, flipX, flipY, opacity, visible, backgroundColor, fillRule, paintFirst, globalCompositeOperation, skewX, skewY, } = this;
|
|
1269
|
+
if (clipPath && !clipPath.excludeFromExport) {
|
|
1270
|
+
clipPathData = clipPath.toObject(propertiesToSerialize.concat('inverted', 'absolutePositioned'));
|
|
1271
|
+
}
|
|
1272
|
+
const toFixedBound = (val) => toFixed(val, NUM_FRACTION_DIGITS);
|
|
1273
|
+
const object = {
|
|
1274
|
+
...pick(this, propertiesToSerialize),
|
|
1275
|
+
type: this.constructor.type,
|
|
1276
|
+
version: VERSION,
|
|
1277
|
+
originX,
|
|
1278
|
+
originY,
|
|
1279
|
+
left: toFixedBound(left),
|
|
1280
|
+
top: toFixedBound(top),
|
|
1281
|
+
width: toFixedBound(width),
|
|
1282
|
+
height: toFixedBound(height),
|
|
1283
|
+
fill: isSerializableFiller(fill) ? fill.toObject() : fill,
|
|
1284
|
+
stroke: isSerializableFiller(stroke) ? stroke.toObject() : stroke,
|
|
1285
|
+
strokeWidth: toFixedBound(strokeWidth),
|
|
1286
|
+
strokeDashArray: strokeDashArray
|
|
1287
|
+
? strokeDashArray.concat()
|
|
1288
|
+
: strokeDashArray,
|
|
1289
|
+
strokeLineCap,
|
|
1290
|
+
strokeDashOffset,
|
|
1291
|
+
strokeLineJoin,
|
|
1292
|
+
strokeUniform,
|
|
1293
|
+
strokeMiterLimit: toFixedBound(strokeMiterLimit),
|
|
1294
|
+
scaleX: toFixedBound(scaleX),
|
|
1295
|
+
scaleY: toFixedBound(scaleY),
|
|
1296
|
+
angle: toFixedBound(angle),
|
|
1297
|
+
flipX,
|
|
1298
|
+
flipY,
|
|
1299
|
+
opacity: toFixedBound(opacity),
|
|
1300
|
+
shadow: shadow ? shadow.toObject() : shadow,
|
|
1301
|
+
visible,
|
|
1302
|
+
backgroundColor,
|
|
1303
|
+
fillRule,
|
|
1304
|
+
paintFirst,
|
|
1305
|
+
globalCompositeOperation,
|
|
1306
|
+
skewX: toFixedBound(skewX),
|
|
1307
|
+
skewY: toFixedBound(skewY),
|
|
1308
|
+
...(clipPathData ? { clipPath: clipPathData } : null),
|
|
1309
|
+
};
|
|
1310
|
+
return !this.includeDefaultValues
|
|
1311
|
+
? this._removeDefaultValues(object)
|
|
1312
|
+
: object;
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Returns (dataless) object representation of an instance
|
|
1316
|
+
* @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output
|
|
1317
|
+
* @return {Object} Object representation of an instance
|
|
1318
|
+
*/
|
|
1319
|
+
toDatalessObject(propertiesToInclude) {
|
|
1320
|
+
// will be overwritten by subclasses
|
|
1321
|
+
return this.toObject(propertiesToInclude);
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* @private
|
|
1325
|
+
* @param {Object} object
|
|
1326
|
+
*/
|
|
1327
|
+
_removeDefaultValues(object) {
|
|
1328
|
+
// getDefaults() ( get from static ownDefaults ) should win over prototype since anyway they get assigned to instance
|
|
1329
|
+
// ownDefault vs prototype is swappable only if you change all the fabric objects consistently.
|
|
1330
|
+
const defaults = this.constructor.getDefaults();
|
|
1331
|
+
const hasStaticDefaultValues = Object.keys(defaults).length > 0;
|
|
1332
|
+
const baseValues = hasStaticDefaultValues
|
|
1333
|
+
? defaults
|
|
1334
|
+
: Object.getPrototypeOf(this);
|
|
1335
|
+
return pickBy(object, (value, key) => {
|
|
1336
|
+
if (key === LEFT || key === TOP || key === 'type') {
|
|
1337
|
+
return true;
|
|
1338
|
+
}
|
|
1339
|
+
const baseValue = baseValues[key];
|
|
1340
|
+
return (value !== baseValue &&
|
|
1341
|
+
// basically a check for [] === []
|
|
1342
|
+
!(Array.isArray(value) &&
|
|
1343
|
+
Array.isArray(baseValue) &&
|
|
1344
|
+
value.length === 0 &&
|
|
1345
|
+
baseValue.length === 0));
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* Returns a string representation of an instance
|
|
1350
|
+
* @return {String}
|
|
1351
|
+
*/
|
|
1352
|
+
toString() {
|
|
1353
|
+
return `#<${this.constructor.type}>`;
|
|
1354
|
+
}
|
|
1355
|
+
/**
|
|
1356
|
+
*
|
|
1357
|
+
* @param {Function} klass
|
|
1358
|
+
* @param {object} object
|
|
1359
|
+
* @param {object} [options]
|
|
1360
|
+
* @param {string} [options.extraParam] property to pass as first argument to the constructor
|
|
1361
|
+
* @param {AbortSignal} [options.signal] handle aborting, see https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
|
|
1362
|
+
* @returns {Promise<FabricObject>}
|
|
1363
|
+
*/
|
|
1364
|
+
static _fromObject({ type, ...serializedObjectOptions }, { extraParam, ...options } = {}) {
|
|
1365
|
+
return enlivenObjectEnlivables(serializedObjectOptions, options).then((enlivedObjectOptions) => {
|
|
1366
|
+
// from the resulting enlived options, extract options.extraParam to arg0
|
|
1367
|
+
// to avoid accidental overrides later
|
|
1368
|
+
if (extraParam) {
|
|
1369
|
+
delete enlivedObjectOptions[extraParam];
|
|
1370
|
+
return new this(serializedObjectOptions[extraParam],
|
|
1371
|
+
// @ts-expect-error different signature
|
|
1372
|
+
enlivedObjectOptions);
|
|
1373
|
+
}
|
|
1374
|
+
else {
|
|
1375
|
+
return new this(enlivedObjectOptions);
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
*
|
|
1381
|
+
* @param {object} object
|
|
1382
|
+
* @param {object} [options]
|
|
1383
|
+
* @param {AbortSignal} [options.signal] handle aborting, see https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
|
|
1384
|
+
* @returns {Promise<FabricObject>}
|
|
1385
|
+
*/
|
|
1386
|
+
static fromObject(object, options) {
|
|
1387
|
+
return this._fromObject(object, options);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
classRegistry.setClass(FabricObject);
|
|
1391
|
+
classRegistry.setClass(FabricObject, 'object');
|
|
1392
|
+
//# sourceMappingURL=Object.js.map
|