fabric 7.0.0 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/pre-commit +1 -0
- package/CHANGELOG.md +21 -0
- package/dist/extensions/cropping_controls/croppingControls.d.ts +16 -0
- package/dist/extensions/cropping_controls/croppingControls.d.ts.map +1 -0
- package/dist/extensions/cropping_controls/croppingHandlers.d.ts +39 -0
- package/dist/extensions/cropping_controls/croppingHandlers.d.ts.map +1 -0
- package/dist/extensions/cropping_controls/enterCropMode.d.ts +7 -0
- package/dist/extensions/cropping_controls/enterCropMode.d.ts.map +1 -0
- package/dist/extensions/cropping_controls/renderCornerControl.d.ts +14 -0
- package/dist/extensions/cropping_controls/renderCornerControl.d.ts.map +1 -0
- package/dist/extensions/index.d.ts +3 -0
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/fabric.d.ts +1 -0
- package/dist/fabric.d.ts.map +1 -1
- package/dist/index.js +628 -537
- 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 +628 -537
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +628 -537
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +628 -537
- package/dist/index.node.mjs.map +1 -1
- package/dist/package.json.min.mjs +1 -1
- package/dist/package.json.mjs +1 -1
- package/dist/src/EventTypeDefs.d.ts +5 -0
- package/dist/src/EventTypeDefs.d.ts.map +1 -1
- package/dist/src/Pattern/Pattern.d.ts.map +1 -1
- package/dist/src/Pattern/Pattern.min.mjs +1 -1
- package/dist/src/Pattern/Pattern.min.mjs.map +1 -1
- package/dist/src/Pattern/Pattern.mjs +2 -1
- package/dist/src/Pattern/Pattern.mjs.map +1 -1
- package/dist/src/Shadow.d.ts +1 -1
- package/dist/src/Shadow.d.ts.map +1 -1
- package/dist/src/Shadow.min.mjs +1 -1
- package/dist/src/Shadow.min.mjs.map +1 -1
- package/dist/src/Shadow.mjs +5 -4
- package/dist/src/Shadow.mjs.map +1 -1
- package/dist/src/canvas/CanvasOptions.d.ts.map +1 -1
- package/dist/src/canvas/CanvasOptions.min.mjs.map +1 -1
- package/dist/src/canvas/CanvasOptions.mjs.map +1 -1
- package/dist/src/canvas/SelectableCanvas.d.ts +2 -0
- package/dist/src/canvas/SelectableCanvas.d.ts.map +1 -1
- package/dist/src/canvas/SelectableCanvas.min.mjs +1 -1
- package/dist/src/canvas/SelectableCanvas.min.mjs.map +1 -1
- package/dist/src/canvas/SelectableCanvas.mjs +33 -13
- package/dist/src/canvas/SelectableCanvas.mjs.map +1 -1
- package/dist/src/canvas/StaticCanvas.d.ts.map +1 -1
- package/dist/src/canvas/StaticCanvas.min.mjs +1 -1
- package/dist/src/canvas/StaticCanvas.min.mjs.map +1 -1
- package/dist/src/canvas/StaticCanvas.mjs +3 -1
- package/dist/src/canvas/StaticCanvas.mjs.map +1 -1
- package/dist/src/canvas/StaticCanvasOptions.d.ts.map +1 -1
- package/dist/src/canvas/StaticCanvasOptions.min.mjs.map +1 -1
- package/dist/src/canvas/StaticCanvasOptions.mjs.map +1 -1
- package/dist/src/constants.d.ts +1 -0
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.min.mjs.map +1 -1
- package/dist/src/constants.mjs.map +1 -1
- package/dist/src/controls/Control.d.ts +22 -1
- package/dist/src/controls/Control.d.ts.map +1 -1
- package/dist/src/controls/Control.min.mjs +1 -1
- package/dist/src/controls/Control.min.mjs.map +1 -1
- package/dist/src/controls/Control.mjs +45 -1
- package/dist/src/controls/Control.mjs.map +1 -1
- package/dist/src/controls/changeWidth.d.ts +22 -0
- package/dist/src/controls/changeWidth.d.ts.map +1 -1
- package/dist/src/controls/changeWidth.min.mjs +1 -1
- package/dist/src/controls/changeWidth.min.mjs.map +1 -1
- package/dist/src/controls/changeWidth.mjs +46 -18
- package/dist/src/controls/changeWidth.mjs.map +1 -1
- package/dist/src/controls/controlRendering.d.ts.map +1 -1
- package/dist/src/controls/controlRendering.min.mjs +1 -1
- package/dist/src/controls/controlRendering.min.mjs.map +1 -1
- package/dist/src/controls/controlRendering.mjs +18 -34
- package/dist/src/controls/controlRendering.mjs.map +1 -1
- package/dist/src/controls/index.d.ts +2 -1
- package/dist/src/controls/index.d.ts.map +1 -1
- package/dist/src/controls/index.min.mjs +1 -1
- package/dist/src/controls/index.mjs +1 -1
- package/dist/src/gradient/Gradient.d.ts.map +1 -1
- 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 +19 -6
- package/dist/src/gradient/Gradient.mjs.map +1 -1
- package/dist/src/shapes/Circle.d.ts.map +1 -1
- package/dist/src/shapes/Circle.min.mjs +1 -1
- package/dist/src/shapes/Circle.min.mjs.map +1 -1
- package/dist/src/shapes/Circle.mjs +10 -7
- package/dist/src/shapes/Circle.mjs.map +1 -1
- package/dist/src/shapes/Ellipse.d.ts.map +1 -1
- package/dist/src/shapes/Ellipse.min.mjs +1 -1
- package/dist/src/shapes/Ellipse.min.mjs.map +1 -1
- package/dist/src/shapes/Ellipse.mjs +2 -1
- package/dist/src/shapes/Ellipse.mjs.map +1 -1
- package/dist/src/shapes/Group.d.ts.map +1 -1
- package/dist/src/shapes/Group.min.mjs +1 -1
- package/dist/src/shapes/Group.min.mjs.map +1 -1
- package/dist/src/shapes/Group.mjs +2 -1
- package/dist/src/shapes/Group.mjs.map +1 -1
- package/dist/src/shapes/IText/IText.d.ts.map +1 -1
- package/dist/src/shapes/IText/IText.min.mjs.map +1 -1
- package/dist/src/shapes/IText/IText.mjs.map +1 -1
- package/dist/src/shapes/Image.d.ts +1 -1
- package/dist/src/shapes/Image.d.ts.map +1 -1
- package/dist/src/shapes/Image.min.mjs +1 -1
- package/dist/src/shapes/Image.min.mjs.map +1 -1
- package/dist/src/shapes/Image.mjs +4 -3
- package/dist/src/shapes/Image.mjs.map +1 -1
- package/dist/src/shapes/Line.d.ts.map +1 -1
- package/dist/src/shapes/Line.min.mjs +1 -1
- package/dist/src/shapes/Line.min.mjs.map +1 -1
- package/dist/src/shapes/Line.mjs +6 -10
- package/dist/src/shapes/Line.mjs.map +1 -1
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.d.ts.map +1 -1
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.min.mjs +1 -1
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.min.mjs.map +1 -1
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.mjs +5 -4
- package/dist/src/shapes/Object/FabricObjectSVGExportMixin.mjs.map +1 -1
- package/dist/src/shapes/Object/InteractiveObject.d.ts.map +1 -1
- package/dist/src/shapes/Object/InteractiveObject.min.mjs.map +1 -1
- package/dist/src/shapes/Object/InteractiveObject.mjs.map +1 -1
- package/dist/src/shapes/Object/Object.d.ts.map +1 -1
- package/dist/src/shapes/Object/Object.min.mjs +1 -1
- package/dist/src/shapes/Object/Object.min.mjs.map +1 -1
- package/dist/src/shapes/Object/Object.mjs +3 -0
- package/dist/src/shapes/Object/Object.mjs.map +1 -1
- package/dist/src/shapes/Object/ObjectGeometry.min.mjs +1 -1
- package/dist/src/shapes/Object/ObjectGeometry.min.mjs.map +1 -1
- package/dist/src/shapes/Object/ObjectGeometry.mjs +1 -1
- package/dist/src/shapes/Object/ObjectGeometry.mjs.map +1 -1
- package/dist/src/shapes/Object/types/FabricObjectProps.d.ts.map +1 -1
- package/dist/src/shapes/Object/types/ObjectProps.d.ts.map +1 -1
- package/dist/src/shapes/Path.d.ts.map +1 -1
- package/dist/src/shapes/Path.min.mjs.map +1 -1
- package/dist/src/shapes/Path.mjs +1 -2
- package/dist/src/shapes/Path.mjs.map +1 -1
- package/dist/src/shapes/Polyline.d.ts.map +1 -1
- package/dist/src/shapes/Polyline.min.mjs +1 -1
- package/dist/src/shapes/Polyline.min.mjs.map +1 -1
- package/dist/src/shapes/Polyline.mjs +10 -6
- package/dist/src/shapes/Polyline.mjs.map +1 -1
- package/dist/src/shapes/Rect.d.ts.map +1 -1
- package/dist/src/shapes/Rect.min.mjs +1 -1
- package/dist/src/shapes/Rect.min.mjs.map +1 -1
- package/dist/src/shapes/Rect.mjs +2 -1
- package/dist/src/shapes/Rect.mjs.map +1 -1
- package/dist/src/shapes/Text/StyledText.d.ts.map +1 -1
- package/dist/src/shapes/Text/StyledText.min.mjs.map +1 -1
- package/dist/src/shapes/Text/StyledText.mjs +0 -3
- package/dist/src/shapes/Text/StyledText.mjs.map +1 -1
- package/dist/src/shapes/Text/Text.d.ts.map +1 -1
- package/dist/src/shapes/Text/Text.min.mjs.map +1 -1
- package/dist/src/shapes/Text/Text.mjs.map +1 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.d.ts.map +1 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.min.mjs +1 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.min.mjs.map +1 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.mjs +5 -6
- package/dist/src/shapes/Text/TextSVGExportMixin.mjs.map +1 -1
- package/dist/src/shapes/Textbox.d.ts.map +1 -1
- package/dist/src/shapes/Textbox.min.mjs.map +1 -1
- package/dist/src/shapes/Textbox.mjs.map +1 -1
- package/dist/src/shapes/Triangle.d.ts.map +1 -1
- package/dist/src/shapes/Triangle.min.mjs.map +1 -1
- package/dist/src/shapes/Triangle.mjs.map +1 -1
- package/dist/src/util/lang_string.d.ts +1 -1
- package/dist/src/util/lang_string.d.ts.map +1 -1
- package/dist/src/util/lang_string.min.mjs +1 -1
- package/dist/src/util/lang_string.min.mjs.map +1 -1
- package/dist/src/util/lang_string.mjs +1 -1
- package/dist/src/util/lang_string.mjs.map +1 -1
- package/dist/src/util/misc/svgParsing.d.ts.map +1 -1
- package/dist/src/util/misc/svgParsing.min.mjs +1 -1
- package/dist/src/util/misc/svgParsing.min.mjs.map +1 -1
- package/dist/src/util/misc/svgParsing.mjs +2 -1
- package/dist/src/util/misc/svgParsing.mjs.map +1 -1
- package/dist-extensions/cropping_controls/croppingControls.mjs +140 -0
- package/dist-extensions/cropping_controls/croppingControls.mjs.map +1 -0
- package/dist-extensions/cropping_controls/croppingHandlers.mjs +228 -0
- package/dist-extensions/cropping_controls/croppingHandlers.mjs.map +1 -0
- package/dist-extensions/cropping_controls/enterCropMode.mjs +38 -0
- package/dist-extensions/cropping_controls/enterCropMode.mjs.map +1 -0
- package/dist-extensions/cropping_controls/renderCornerControl.mjs +45 -0
- package/dist-extensions/cropping_controls/renderCornerControl.mjs.map +1 -0
- package/dist-extensions/extensions/cropping_controls/croppingControls.d.ts +16 -0
- package/dist-extensions/extensions/cropping_controls/croppingControls.d.ts.map +1 -0
- package/dist-extensions/extensions/cropping_controls/croppingHandlers.d.ts +39 -0
- package/dist-extensions/extensions/cropping_controls/croppingHandlers.d.ts.map +1 -0
- package/dist-extensions/extensions/cropping_controls/enterCropMode.d.ts +7 -0
- package/dist-extensions/extensions/cropping_controls/enterCropMode.d.ts.map +1 -0
- package/dist-extensions/extensions/cropping_controls/renderCornerControl.d.ts +14 -0
- package/dist-extensions/extensions/cropping_controls/renderCornerControl.d.ts.map +1 -0
- package/dist-extensions/extensions/index.d.ts +3 -0
- package/dist-extensions/extensions/index.d.ts.map +1 -1
- package/dist-extensions/fabric-extensions.min.js +1 -1
- package/dist-extensions/fabric-extensions.min.js.map +1 -1
- package/dist-extensions/fabric.d.ts +1 -0
- package/dist-extensions/fabric.d.ts.map +1 -1
- package/dist-extensions/index.mjs +3 -0
- package/dist-extensions/index.mjs.map +1 -1
- package/dist-extensions/src/EventTypeDefs.d.ts +5 -0
- package/dist-extensions/src/EventTypeDefs.d.ts.map +1 -1
- package/dist-extensions/src/Pattern/Pattern.d.ts.map +1 -1
- package/dist-extensions/src/Shadow.d.ts +1 -1
- package/dist-extensions/src/Shadow.d.ts.map +1 -1
- package/dist-extensions/src/canvas/CanvasOptions.d.ts.map +1 -1
- package/dist-extensions/src/canvas/SelectableCanvas.d.ts +2 -0
- package/dist-extensions/src/canvas/SelectableCanvas.d.ts.map +1 -1
- package/dist-extensions/src/canvas/StaticCanvas.d.ts.map +1 -1
- package/dist-extensions/src/canvas/StaticCanvasOptions.d.ts.map +1 -1
- package/dist-extensions/src/constants.d.ts +1 -0
- package/dist-extensions/src/constants.d.ts.map +1 -1
- package/dist-extensions/src/controls/Control.d.ts +22 -1
- package/dist-extensions/src/controls/Control.d.ts.map +1 -1
- package/dist-extensions/src/controls/changeWidth.d.ts +22 -0
- package/dist-extensions/src/controls/changeWidth.d.ts.map +1 -1
- package/dist-extensions/src/controls/controlRendering.d.ts.map +1 -1
- package/dist-extensions/src/controls/index.d.ts +2 -1
- package/dist-extensions/src/controls/index.d.ts.map +1 -1
- package/dist-extensions/src/gradient/Gradient.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Circle.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Ellipse.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Group.d.ts.map +1 -1
- package/dist-extensions/src/shapes/IText/IText.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Image.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Line.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Object/FabricObjectSVGExportMixin.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Object/InteractiveObject.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Object/Object.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Object/types/FabricObjectProps.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Object/types/ObjectProps.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Path.d.ts +1 -1
- package/dist-extensions/src/shapes/Path.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Polyline.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Rect.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Text/StyledText.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Text/Text.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Text/TextSVGExportMixin.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Textbox.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Triangle.d.ts.map +1 -1
- package/dist-extensions/src/util/lang_string.d.ts +1 -1
- package/dist-extensions/src/util/lang_string.d.ts.map +1 -1
- package/dist-extensions/src/util/misc/svgParsing.d.ts.map +1 -1
- package/eslint.config.mjs +2 -0
- package/extensions/cropping_controls/croppingControls.spec.ts +115 -0
- package/extensions/cropping_controls/croppingControls.ts +150 -0
- package/extensions/cropping_controls/croppingHandlers.spec.ts +579 -0
- package/extensions/cropping_controls/croppingHandlers.ts +285 -0
- package/extensions/cropping_controls/enterCropMode.ts +30 -0
- package/extensions/cropping_controls/renderCornerControl.ts +53 -0
- package/extensions/index.ts +9 -0
- package/fabric.ts +1 -0
- package/package.json +17 -8
- package/src/ClassRegistry.spec.ts +18 -19
- package/src/EventTypeDefs.ts +15 -11
- package/src/Pattern/Pattern.spec.ts +12 -0
- package/src/Pattern/Pattern.ts +3 -2
- package/src/Shadow.ts +9 -8
- package/src/brushes/PencilBrush.spec.ts +11 -11
- package/src/canvas/Canvas-dispose.spec.ts +8 -7
- package/src/canvas/Canvas.spec.ts +27 -29
- package/src/canvas/CanvasOptions.ts +2 -1
- package/src/canvas/SelectableCanvas.ts +38 -15
- package/src/canvas/StaticCanvas.spec.ts +20 -0
- package/src/canvas/StaticCanvas.ts +7 -4
- package/src/canvas/StaticCanvasOptions.ts +1 -3
- package/src/constants.ts +1 -0
- package/src/controls/Control.spec.ts +102 -0
- package/src/controls/Control.ts +71 -2
- package/src/controls/changeHeight.spec.ts +147 -0
- package/src/controls/changeWidth.ts +68 -35
- package/src/controls/controlRendering.ts +20 -48
- package/src/controls/index.ts +7 -1
- package/src/gradient/Gradient.spec.ts +101 -46
- package/src/gradient/Gradient.ts +27 -14
- package/src/shapes/Circle.spec.ts +10 -39
- package/src/shapes/Circle.ts +11 -11
- package/src/shapes/Ellipse.spec.ts +8 -37
- package/src/shapes/Ellipse.ts +7 -7
- package/src/shapes/Group.ts +3 -3
- package/src/shapes/IText/IText-click-behavior.spec.ts +36 -49
- package/src/shapes/IText/IText.ts +5 -6
- package/src/shapes/IText/ITextKeyBehavior.test.ts +0 -1
- package/src/shapes/IText/__snapshots__/ITextBehavior.test.ts.snap +6 -6
- package/src/shapes/Image.spec.ts +17 -33
- package/src/shapes/Image.ts +15 -11
- package/src/shapes/Line.spec.ts +4 -30
- package/src/shapes/Line.ts +11 -16
- package/src/shapes/Object/FabricObjectSVGExportMixin.ts +11 -4
- package/src/shapes/Object/InteractiveObject.ts +4 -4
- package/src/shapes/Object/Object.ts +6 -5
- package/src/shapes/Object/ObjectGeometry.spec.ts +15 -0
- package/src/shapes/Object/ObjectGeometry.ts +1 -1
- package/src/shapes/Object/objectSvgExport.spec.ts +112 -0
- package/src/shapes/Object/types/FabricObjectProps.ts +1 -4
- package/src/shapes/Object/types/ObjectProps.ts +1 -3
- package/src/shapes/Path.spec.ts +4 -27
- package/src/shapes/Path.ts +2 -4
- package/src/shapes/Polygon.spec.ts +4 -31
- package/src/shapes/Polyline.spec.ts +4 -31
- package/src/shapes/Polyline.ts +11 -12
- package/src/shapes/Rect.spec.ts +25 -33
- package/src/shapes/Rect.ts +7 -7
- package/src/shapes/Text/StyledText.ts +0 -3
- package/src/shapes/Text/Text.spec.ts +3 -32
- package/src/shapes/Text/Text.ts +5 -6
- package/src/shapes/Text/TextSVGExportMixin.spec.ts +9 -0
- package/src/shapes/Text/TextSVGExportMixin.ts +14 -16
- package/src/shapes/Text/__snapshots__/Text.spec.ts.snap +1 -1
- package/src/shapes/Text/__snapshots__/TextSVGExportMixin.spec.ts.snap +1 -1
- package/src/shapes/Textbox.spec.ts +5 -5
- package/src/shapes/Textbox.ts +6 -5
- package/src/shapes/Triangle.ts +4 -4
- package/src/shapes/__snapshots__/Image.spec.ts.snap +4 -4
- package/src/shapes/__snapshots__/Textbox.spec.ts.snap +5 -5
- package/src/util/lang_string.ts +3 -2
- package/src/util/misc/svgParsing.ts +2 -1
- package/tsconfig.spec.json +1 -0
- package/vitest.config.ts +12 -2
- package/vitest.extend.ts +6 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ControlActionHandler, TPointerEvent, TransformActionHandler } from '../EventTypeDefs';
|
|
2
2
|
import { Point } from '../Point';
|
|
3
3
|
import type { InteractiveFabricObject, TOCoord } from '../shapes/Object/InteractiveObject';
|
|
4
|
-
import type { TCornerPoint, TDegree, TMat2D } from '../typedefs';
|
|
4
|
+
import type { TCornerPoint, TDegree, TMat2D, TOriginX, TOriginY } from '../typedefs';
|
|
5
5
|
import type { ControlRenderingStyleOverride } from './controlRendering';
|
|
6
6
|
export declare class Control {
|
|
7
7
|
/**
|
|
@@ -111,7 +111,15 @@ export declare class Control {
|
|
|
111
111
|
* @default false
|
|
112
112
|
*/
|
|
113
113
|
withConnection: boolean;
|
|
114
|
+
transformAnchorPoint?: {
|
|
115
|
+
x: TOriginX;
|
|
116
|
+
y: TOriginY;
|
|
117
|
+
};
|
|
114
118
|
constructor(options?: Partial<Control>);
|
|
119
|
+
getTransformAnchorPoint(): {
|
|
120
|
+
x: TOriginX;
|
|
121
|
+
y: TOriginY;
|
|
122
|
+
};
|
|
115
123
|
/**
|
|
116
124
|
* The control actionHandler, provide one to handle action ( control being moved )
|
|
117
125
|
* @param {Event} eventData the native mouse event
|
|
@@ -212,6 +220,19 @@ export declare class Control {
|
|
|
212
220
|
br: Point;
|
|
213
221
|
bl: Point;
|
|
214
222
|
};
|
|
223
|
+
/**
|
|
224
|
+
* This is an helper method to prepare the canvas to render a control
|
|
225
|
+
* It detectes common control properties and sets the correct fill and
|
|
226
|
+
* stroke styles on the context. It does not execute translations or
|
|
227
|
+
* rotations since different controls need differnt combination of these.
|
|
228
|
+
*/
|
|
229
|
+
commonRenderProps(ctx: CanvasRenderingContext2D, left: number, top: number, fabricObject: InteractiveFabricObject, styleOverride?: ControlRenderingStyleOverride): {
|
|
230
|
+
stroke: boolean;
|
|
231
|
+
xSize: number;
|
|
232
|
+
ySize: number;
|
|
233
|
+
transparentCorners: boolean;
|
|
234
|
+
opName: 'stroke' | 'fill';
|
|
235
|
+
};
|
|
215
236
|
/**
|
|
216
237
|
* Render function for the control.
|
|
217
238
|
* When this function runs the context is unscaled. unrotate. Just retina scaled.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Control.d.ts","sourceRoot":"","sources":["../../../src/controls/Control.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EACb,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,OAAO,KAAK,EACV,uBAAuB,EACvB,OAAO,EACR,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Control.d.ts","sourceRoot":"","sources":["../../../src/controls/Control.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EACb,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,OAAO,KAAK,EACV,uBAAuB,EACvB,OAAO,EACR,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EACV,YAAY,EACZ,OAAO,EACP,MAAM,EACN,QAAQ,EACR,QAAQ,EACT,MAAM,aAAa,CAAC;AAQrB,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AAGxE,qBAAa,OAAO;IAClB;;;;;;;OAOG;IACH,OAAO,UAAQ;IAEf;;;;;;;;;;OAUG;IACH,UAAU,SAAS;IAEnB;;;;;;OAMG;IACH,KAAK,SAAK;IAEV;;;;;;OAMG;IACH,CAAC,SAAK;IAEN;;;;;;OAMG;IACH,CAAC,SAAK;IAEN;;;;;;;;;;;OAWG;IACH,OAAO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+1,2 @@
|
|
|
1
|
-
import{defineProperty as t}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{Intersection as
|
|
1
|
+
import{defineProperty as t}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{Intersection as r}from"../Intersection.min.mjs";import{Point as e}from"../Point.min.mjs";import{SCALE as i,STROKE as o,FILL as s}from"../constants.min.mjs";import{multiplyTransformMatrixArray as n,createTranslateMatrix as l,createRotateMatrix as a,createScaleMatrix as c}from"../util/misc/matrix.min.mjs";import{degreesToRadians as m}from"../util/misc/radiansDegreesConversion.min.mjs";import{renderSquareControl as h,renderCircleControl as u}from"./controlRendering.min.mjs";class f{constructor(r){t(this,"visible",!0),t(this,"actionName",i),t(this,"angle",0),t(this,"x",0),t(this,"y",0),t(this,"offsetX",0),t(this,"offsetY",0),t(this,"sizeX",0),t(this,"sizeY",0),t(this,"touchSizeX",0),t(this,"touchSizeY",0),t(this,"cursorStyle","crosshair"),t(this,"withConnection",!1),Object.assign(this,r)}getTransformAnchorPoint(){var t;return null!==(t=this.transformAnchorPoint)&&void 0!==t?t:new e(.5-this.x,.5-this.y)}shouldActivate(t,e,i,o){var s;let{tl:n,tr:l,br:a,bl:c}=o;return(null===(s=e.canvas)||void 0===s?void 0:s.getActiveObject())===e&&e.isControlVisible(t)&&r.isPointInPolygon(i,[n,l,a,c])}getActionHandler(t,r,e){return this.actionHandler}getMouseDownHandler(t,r,e){return this.mouseDownHandler}getMouseUpHandler(t,r,e){return this.mouseUpHandler}cursorStyleHandler(t,r,e,i){return r.cursorStyle}getActionName(t,r,e){return r.actionName}getVisibility(t,r){var e,i;return null!==(e=null===(i=t._controlsVisibility)||void 0===i?void 0:i[r])&&void 0!==e?e:this.visible}setVisibility(t,r,e){this.visible=t}positionHandler(t,r,i,o){return new e(this.x*t.x+this.offsetX,this.y*t.y+this.offsetY).transform(r)}calcCornerCoords(t,r,i,o,s,m){const h=n([l(i,o),a({angle:t}),c((s?this.touchSizeX:this.sizeX)||r,(s?this.touchSizeY:this.sizeY)||r)]);return{tl:new e(-.5,-.5).transform(h),tr:new e(.5,-.5).transform(h),br:new e(.5,.5).transform(h),bl:new e(-.5,.5).transform(h)}}commonRenderProps(t,r,e,i){let n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};const{cornerSize:l,cornerColor:a,transparentCorners:c,cornerStrokeColor:h}=n,u=l||i.cornerSize,f=this.sizeX||u,d=this.sizeY||u,p=void 0!==c?c:i.transparentCorners,v=p?o:s,g=h||i.cornerStrokeColor,y=!p&&!!g;return t.fillStyle=a||i.cornerColor||"",t.strokeStyle=g||"",t.translate(r,e),t.rotate(m(i.getTotalAngle())),{stroke:y,xSize:f,ySize:d,transparentCorners:p,opName:v}}render(t,r,e,i,o){if("circle"===((i=i||{}).cornerStyle||o.cornerStyle))u.call(this,t,r,e,i,o);else h.call(this,t,r,e,i,o)}}export{f as Control};
|
|
2
2
|
//# sourceMappingURL=Control.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Control.min.mjs","sources":["../../../src/controls/Control.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport type {\n ControlActionHandler,\n TPointerEvent,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport { Intersection } from '../Intersection';\nimport { Point } from '../Point';\nimport { SCALE } from '../constants';\nimport type {\n InteractiveFabricObject,\n TOCoord,\n} from '../shapes/Object/InteractiveObject';\nimport type { TCornerPoint, TDegree, TMat2D } from '../typedefs';\nimport {\n createRotateMatrix,\n createScaleMatrix,\n createTranslateMatrix,\n multiplyTransformMatrixArray,\n} from '../util/misc/matrix';\nimport type { ControlRenderingStyleOverride } from './controlRendering';\nimport { renderCircleControl, renderSquareControl } from './controlRendering';\n\nexport class Control {\n /**\n * keep track of control visibility.\n * mainly for backward compatibility.\n * if you do not want to see a control, you can remove it\n * from the control set.\n * @type {Boolean}\n * @default true\n */\n visible = true;\n\n /**\n * Name of the action that the control will likely execute.\n * This is optional. FabricJS uses to identify what the user is doing for some\n * extra optimizations. If you are writing a custom control and you want to know\n * somewhere else in the code what is going on, you can use this string here.\n * you can also provide a custom getActionName if your control run multiple actions\n * depending on some external state.\n * default to scale since is the most common, used on 4 corners by default\n * @type {String}\n * @default 'scale'\n */\n actionName = SCALE;\n\n /**\n * Drawing angle of the control.\n * NOT used for now, but name marked as needed for internal logic\n * example: to reuse the same drawing function for different rotated controls\n * @type {Number}\n * @default 0\n */\n angle = 0;\n\n /**\n * Relative position of the control. X\n * 0,0 is the center of the Object, while -0.5 (left) or 0.5 (right) are the extremities\n * of the bounding box.\n * @type {Number}\n * @default 0\n */\n x = 0;\n\n /**\n * Relative position of the control. Y\n * 0,0 is the center of the Object, while -0.5 (top) or 0.5 (bottom) are the extremities\n * of the bounding box.\n * @type {Number}\n * @default 0\n */\n y = 0;\n\n /**\n * Horizontal offset of the control from the defined position. In pixels\n * Positive offset moves the control to the right, negative to the left.\n * It used when you want to have position of control that does not scale with\n * the bounding box. Example: rotation control is placed at x:0, y: 0.5 on\n * the boundind box, with an offset of 30 pixels vertically. Those 30 pixels will\n * stay 30 pixels no matter how the object is big. Another example is having 2\n * controls in the corner, that stay in the same position when the object scale.\n * of the bounding box.\n * @type {Number}\n * @default 0\n */\n offsetX = 0;\n\n /**\n * Vertical offset of the control from the defined position. In pixels\n * Positive offset moves the control to the bottom, negative to the top.\n * @type {Number}\n * @default 0\n */\n offsetY = 0;\n\n /**\n * Sets the length of the control. If null, defaults to object's cornerSize.\n * Expects both sizeX and sizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n sizeX = 0;\n\n /**\n * Sets the height of the control. If null, defaults to object's cornerSize.\n * Expects both sizeX and sizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n sizeY = 0;\n\n /**\n * Sets the length of the touch area of the control. If null, defaults to object's touchCornerSize.\n * Expects both touchSizeX and touchSizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n touchSizeX = 0;\n\n /**\n * Sets the height of the touch area of the control. If null, defaults to object's touchCornerSize.\n * Expects both touchSizeX and touchSizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n touchSizeY = 0;\n\n /**\n * Css cursor style to display when the control is hovered.\n * if the method `cursorStyleHandler` is provided, this property is ignored.\n * @type {String}\n * @default 'crosshair'\n */\n cursorStyle = 'crosshair';\n\n /**\n * If controls has an offsetY or offsetX, draw a line that connects\n * the control to the bounding box\n * @type {Boolean}\n * @default false\n */\n withConnection = false;\n\n constructor(options?: Partial<Control>) {\n Object.assign(this, options);\n }\n\n /**\n * The control actionHandler, provide one to handle action ( control being moved )\n * @param {Event} eventData the native mouse event\n * @param {Transform} transformData properties of the current transform\n * @param {Number} x x position of the cursor\n * @param {Number} y y position of the cursor\n * @return {Boolean} true if the action/event modified the object\n */\n declare actionHandler: TransformActionHandler;\n\n /**\n * The control handler for mouse down, provide one to handle mouse down on control\n * @param {Event} eventData the native mouse event\n * @param {Transform} transformData properties of the current transform\n * @param {Number} x x position of the cursor\n * @param {Number} y y position of the cursor\n * @return {Boolean} true if the action/event modified the object\n */\n declare mouseDownHandler?: ControlActionHandler;\n\n /**\n * The control mouseUpHandler, provide one to handle an effect on mouse up.\n * @param {Event} eventData the native mouse event\n * @param {Transform} transformData properties of the current transform\n * @param {Number} x x position of the cursor\n * @param {Number} y y position of the cursor\n * @return {Boolean} true if the action/event modified the object\n */\n declare mouseUpHandler?: ControlActionHandler;\n\n shouldActivate(\n controlKey: string,\n fabricObject: InteractiveFabricObject,\n pointer: Point,\n { tl, tr, br, bl }: TCornerPoint,\n ) {\n // TODO: locking logic can be handled here instead of in the control handler logic\n return (\n fabricObject.canvas?.getActiveObject() === fabricObject &&\n fabricObject.isControlVisible(controlKey) &&\n Intersection.isPointInPolygon(pointer, [tl, tr, br, bl])\n );\n }\n\n /**\n * Returns control actionHandler\n * @param {Event} eventData the native mouse event\n * @param {FabricObject} fabricObject on which the control is displayed\n * @param {Control} control control for which the action handler is being asked\n * @return {Function} the action handler\n */\n getActionHandler(\n eventData: TPointerEvent,\n fabricObject: InteractiveFabricObject,\n control: Control,\n ): TransformActionHandler | undefined {\n return this.actionHandler;\n }\n\n /**\n * Returns control mouseDown handler\n * @param {Event} eventData the native mouse event\n * @param {FabricObject} fabricObject on which the control is displayed\n * @param {Control} control control for which the action handler is being asked\n * @return {Function} the action handler\n */\n getMouseDownHandler(\n eventData: TPointerEvent,\n fabricObject: InteractiveFabricObject,\n control: Control,\n ): ControlActionHandler | undefined {\n return this.mouseDownHandler;\n }\n\n /**\n * Returns control mouseUp handler.\n * During actions the fabricObject or the control can be of different obj\n * @param {Event} eventData the native mouse event\n * @param {FabricObject} fabricObject on which the control is displayed\n * @param {Control} control control for which the action handler is being asked\n * @return {Function} the action handler\n */\n getMouseUpHandler(\n eventData: TPointerEvent,\n fabricObject: InteractiveFabricObject,\n control: Control,\n ): ControlActionHandler | undefined {\n return this.mouseUpHandler;\n }\n\n /**\n * Returns control cursorStyle for css using cursorStyle. If you need a more elaborate\n * function you can pass one in the constructor\n * the cursorStyle property\n * @param {Event} eventData the native mouse event\n * @param {Control} control the current control ( likely this)\n * @param {FabricObject} object on which the control is displayed\n * @return {String}\n */\n cursorStyleHandler(\n eventData: TPointerEvent,\n control: Control,\n fabricObject: InteractiveFabricObject,\n coord: TOCoord,\n ) {\n return control.cursorStyle;\n }\n\n /**\n * Returns the action name. The basic implementation just return the actionName property.\n * @param {Event} eventData the native mouse event\n * @param {Control} control the current control ( likely this)\n * @param {FabricObject} object on which the control is displayed\n * @return {String}\n */\n getActionName(\n eventData: TPointerEvent,\n control: Control,\n fabricObject: InteractiveFabricObject,\n ) {\n return control.actionName;\n }\n\n /**\n * Returns controls visibility\n * @param {FabricObject} object on which the control is displayed\n * @param {String} controlKey key where the control is memorized on the\n * @return {Boolean}\n */\n getVisibility(fabricObject: InteractiveFabricObject, controlKey: string) {\n return fabricObject._controlsVisibility?.[controlKey] ?? this.visible;\n }\n\n /**\n * Sets controls visibility\n * @param {Boolean} visibility for the object\n * @return {Void}\n */\n setVisibility(\n visibility: boolean,\n name?: string,\n fabricObject?: InteractiveFabricObject,\n ) {\n this.visible = visibility;\n }\n\n positionHandler(\n dim: Point,\n finalMatrix: TMat2D,\n fabricObject: InteractiveFabricObject,\n currentControl: Control,\n ) {\n return new Point(\n this.x * dim.x + this.offsetX,\n this.y * dim.y + this.offsetY,\n ).transform(finalMatrix);\n }\n\n /**\n * Returns the coords for this control based on object values.\n * @param {Number} objectAngle angle from the fabric object holding the control\n * @param {Number} objectCornerSize cornerSize from the fabric object holding the control (or touchCornerSize if\n * isTouch is true)\n * @param {Number} centerX x coordinate where the control center should be\n * @param {Number} centerY y coordinate where the control center should be\n * @param {boolean} isTouch true if touch corner, false if normal corner\n */\n calcCornerCoords(\n angle: TDegree,\n objectCornerSize: number,\n centerX: number,\n centerY: number,\n isTouch: boolean,\n fabricObject: InteractiveFabricObject,\n ) {\n const t = multiplyTransformMatrixArray([\n createTranslateMatrix(centerX, centerY),\n createRotateMatrix({ angle }),\n createScaleMatrix(\n (isTouch ? this.touchSizeX : this.sizeX) || objectCornerSize,\n (isTouch ? this.touchSizeY : this.sizeY) || objectCornerSize,\n ),\n ]);\n return {\n tl: new Point(-0.5, -0.5).transform(t),\n tr: new Point(0.5, -0.5).transform(t),\n br: new Point(0.5, 0.5).transform(t),\n bl: new Point(-0.5, 0.5).transform(t),\n };\n }\n\n /**\n * Render function for the control.\n * When this function runs the context is unscaled. unrotate. Just retina scaled.\n * all the functions will have to translate to the point left,top before starting Drawing\n * if they want to draw a control where the position is detected.\n * left and top are the result of the positionHandler function\n * @param {RenderingContext2D} ctx the context where the control will be drawn\n * @param {Number} left position of the canvas where we are about to render the control.\n * @param {Number} top position of the canvas where we are about to render the control.\n * @param {Object} styleOverride\n * @param {FabricObject} fabricObject the object where the control is about to be rendered\n */\n render(\n ctx: CanvasRenderingContext2D,\n left: number,\n top: number,\n styleOverride: ControlRenderingStyleOverride | undefined,\n fabricObject: InteractiveFabricObject,\n ) {\n styleOverride = styleOverride || {};\n switch (styleOverride.cornerStyle || fabricObject.cornerStyle) {\n case 'circle':\n renderCircleControl.call(\n this,\n ctx,\n left,\n top,\n styleOverride,\n fabricObject,\n );\n break;\n default:\n renderSquareControl.call(\n this,\n ctx,\n left,\n top,\n styleOverride,\n fabricObject,\n );\n }\n }\n}\n"],"names":["Control","constructor","options","_defineProperty","SCALE","Object","assign","this","shouldActivate","controlKey","fabricObject","pointer","_ref","_fabricObject$canvas","tl","tr","br","bl","canvas","getActiveObject","isControlVisible","Intersection","isPointInPolygon","getActionHandler","eventData","control","actionHandler","getMouseDownHandler","mouseDownHandler","getMouseUpHandler","mouseUpHandler","cursorStyleHandler","coord","cursorStyle","getActionName","actionName","getVisibility","_fabricObject$_contro","_fabricObject$_contro2","_controlsVisibility","visible","setVisibility","visibility","name","positionHandler","dim","finalMatrix","currentControl","Point","x","offsetX","y","offsetY","transform","calcCornerCoords","angle","objectCornerSize","centerX","centerY","isTouch","t","multiplyTransformMatrixArray","createTranslateMatrix","createRotateMatrix","createScaleMatrix","touchSizeX","sizeX","touchSizeY","sizeY","render","ctx","left","top","styleOverride","cornerStyle","renderCircleControl","call","renderSquareControl"],"mappings":"8cAuBO,MAAMA,EAyHXC,WAAAA,CAAYC,GAxHZC,kBAQU,GAEVA,oBAWaC,GAEbD,eAOQ,GAERA,WAOI,GAEJA,WAOI,GAEJA,iBAYU,GAEVA,iBAMU,GAEVA,eAMQ,GAERA,eAMQ,GAERA,oBAMa,GAEbA,oBAMa,GAEbA,qBAMc,aAEdA,yBAMiB,GAGfE,OAAOC,OAAOC,KAAML,EACtB,CAgCAM,cAAAA,CACEC,EACAC,EACAC,EAAcC,GAEd,IAAAC,EAAA,IADAC,GAAEA,EAAEC,GAAEA,EAAEC,GAAEA,EAAEC,GAAEA,GAAkBL,EAGhC,OACqB,QAAnBC,EAAAH,EAAaQ,cAAM,IAAAL,OAAA,EAAnBA,EAAqBM,qBAAsBT,GAC3CA,EAAaU,iBAAiBX,IAC9BY,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,MAAAA,CACEC,EACAC,EACAC,EACAC,EACA/D,GAGA,GACO,aAFP+D,EAAgBA,GAAiB,CAAA,GACXC,aAAehE,EAAagE,aAE9CC,EAAoBC,KAClBrE,KACA+D,EACAC,EACAC,EACAC,EACA/D,QAIFmE,EAAoBD,KAClBrE,KACA+D,EACAC,EACAC,EACAC,EACA/D,EAGR"}
|
|
1
|
+
{"version":3,"file":"Control.min.mjs","sources":["../../../src/controls/Control.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport type {\n ControlActionHandler,\n TPointerEvent,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport { Intersection } from '../Intersection';\nimport { Point } from '../Point';\nimport { FILL, SCALE, STROKE } from '../constants';\nimport type {\n InteractiveFabricObject,\n TOCoord,\n} from '../shapes/Object/InteractiveObject';\nimport type {\n TCornerPoint,\n TDegree,\n TMat2D,\n TOriginX,\n TOriginY,\n} from '../typedefs';\nimport {\n createRotateMatrix,\n createScaleMatrix,\n createTranslateMatrix,\n multiplyTransformMatrixArray,\n} from '../util/misc/matrix';\nimport { degreesToRadians } from '../util/misc/radiansDegreesConversion';\nimport type { ControlRenderingStyleOverride } from './controlRendering';\nimport { renderCircleControl, renderSquareControl } from './controlRendering';\n\nexport class Control {\n /**\n * keep track of control visibility.\n * mainly for backward compatibility.\n * if you do not want to see a control, you can remove it\n * from the control set.\n * @type {Boolean}\n * @default true\n */\n visible = true;\n\n /**\n * Name of the action that the control will likely execute.\n * This is optional. FabricJS uses to identify what the user is doing for some\n * extra optimizations. If you are writing a custom control and you want to know\n * somewhere else in the code what is going on, you can use this string here.\n * you can also provide a custom getActionName if your control run multiple actions\n * depending on some external state.\n * default to scale since is the most common, used on 4 corners by default\n * @type {String}\n * @default 'scale'\n */\n actionName = SCALE;\n\n /**\n * Drawing angle of the control.\n * NOT used for now, but name marked as needed for internal logic\n * example: to reuse the same drawing function for different rotated controls\n * @type {Number}\n * @default 0\n */\n angle = 0;\n\n /**\n * Relative position of the control. X\n * 0,0 is the center of the Object, while -0.5 (left) or 0.5 (right) are the extremities\n * of the bounding box.\n * @type {Number}\n * @default 0\n */\n x = 0;\n\n /**\n * Relative position of the control. Y\n * 0,0 is the center of the Object, while -0.5 (top) or 0.5 (bottom) are the extremities\n * of the bounding box.\n * @type {Number}\n * @default 0\n */\n y = 0;\n\n /**\n * Horizontal offset of the control from the defined position. In pixels\n * Positive offset moves the control to the right, negative to the left.\n * It used when you want to have position of control that does not scale with\n * the bounding box. Example: rotation control is placed at x:0, y: 0.5 on\n * the boundind box, with an offset of 30 pixels vertically. Those 30 pixels will\n * stay 30 pixels no matter how the object is big. Another example is having 2\n * controls in the corner, that stay in the same position when the object scale.\n * of the bounding box.\n * @type {Number}\n * @default 0\n */\n offsetX = 0;\n\n /**\n * Vertical offset of the control from the defined position. In pixels\n * Positive offset moves the control to the bottom, negative to the top.\n * @type {Number}\n * @default 0\n */\n offsetY = 0;\n\n /**\n * Sets the length of the control. If null, defaults to object's cornerSize.\n * Expects both sizeX and sizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n sizeX = 0;\n\n /**\n * Sets the height of the control. If null, defaults to object's cornerSize.\n * Expects both sizeX and sizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n sizeY = 0;\n\n /**\n * Sets the length of the touch area of the control. If null, defaults to object's touchCornerSize.\n * Expects both touchSizeX and touchSizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n touchSizeX = 0;\n\n /**\n * Sets the height of the touch area of the control. If null, defaults to object's touchCornerSize.\n * Expects both touchSizeX and touchSizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n touchSizeY = 0;\n\n /**\n * Css cursor style to display when the control is hovered.\n * if the method `cursorStyleHandler` is provided, this property is ignored.\n * @type {String}\n * @default 'crosshair'\n */\n cursorStyle = 'crosshair';\n\n /**\n * If controls has an offsetY or offsetX, draw a line that connects\n * the control to the bounding box\n * @type {Boolean}\n * @default false\n */\n withConnection = false;\n\n declare transformAnchorPoint?: {\n x: TOriginX;\n y: TOriginY;\n };\n\n constructor(options?: Partial<Control>) {\n Object.assign(this, options);\n }\n\n getTransformAnchorPoint(): {\n x: TOriginX;\n y: TOriginY;\n } {\n return (\n // return the control transformAnchorPoint\n this.transformAnchorPoint ??\n // otherwise will return the opposite origin of where the control is located.\n new Point(-this.x + 0.5, -this.y + 0.5)\n );\n }\n\n /**\n * The control actionHandler, provide one to handle action ( control being moved )\n * @param {Event} eventData the native mouse event\n * @param {Transform} transformData properties of the current transform\n * @param {Number} x x position of the cursor\n * @param {Number} y y position of the cursor\n * @return {Boolean} true if the action/event modified the object\n */\n declare actionHandler: TransformActionHandler;\n\n /**\n * The control handler for mouse down, provide one to handle mouse down on control\n * @param {Event} eventData the native mouse event\n * @param {Transform} transformData properties of the current transform\n * @param {Number} x x position of the cursor\n * @param {Number} y y position of the cursor\n * @return {Boolean} true if the action/event modified the object\n */\n declare mouseDownHandler?: ControlActionHandler;\n\n /**\n * The control mouseUpHandler, provide one to handle an effect on mouse up.\n * @param {Event} eventData the native mouse event\n * @param {Transform} transformData properties of the current transform\n * @param {Number} x x position of the cursor\n * @param {Number} y y position of the cursor\n * @return {Boolean} true if the action/event modified the object\n */\n declare mouseUpHandler?: ControlActionHandler;\n\n shouldActivate(\n controlKey: string,\n fabricObject: InteractiveFabricObject,\n pointer: Point,\n { tl, tr, br, bl }: TCornerPoint,\n ) {\n // TODO: locking logic can be handled here instead of in the control handler logic\n return (\n fabricObject.canvas?.getActiveObject() === fabricObject &&\n fabricObject.isControlVisible(controlKey) &&\n Intersection.isPointInPolygon(pointer, [tl, tr, br, bl])\n );\n }\n\n /**\n * Returns control actionHandler\n * @param {Event} eventData the native mouse event\n * @param {FabricObject} fabricObject on which the control is displayed\n * @param {Control} control control for which the action handler is being asked\n * @return {Function} the action handler\n */\n getActionHandler(\n eventData: TPointerEvent,\n fabricObject: InteractiveFabricObject,\n control: Control,\n ): TransformActionHandler | undefined {\n return this.actionHandler;\n }\n\n /**\n * Returns control mouseDown handler\n * @param {Event} eventData the native mouse event\n * @param {FabricObject} fabricObject on which the control is displayed\n * @param {Control} control control for which the action handler is being asked\n * @return {Function} the action handler\n */\n getMouseDownHandler(\n eventData: TPointerEvent,\n fabricObject: InteractiveFabricObject,\n control: Control,\n ): ControlActionHandler | undefined {\n return this.mouseDownHandler;\n }\n\n /**\n * Returns control mouseUp handler.\n * During actions the fabricObject or the control can be of different obj\n * @param {Event} eventData the native mouse event\n * @param {FabricObject} fabricObject on which the control is displayed\n * @param {Control} control control for which the action handler is being asked\n * @return {Function} the action handler\n */\n getMouseUpHandler(\n eventData: TPointerEvent,\n fabricObject: InteractiveFabricObject,\n control: Control,\n ): ControlActionHandler | undefined {\n return this.mouseUpHandler;\n }\n\n /**\n * Returns control cursorStyle for css using cursorStyle. If you need a more elaborate\n * function you can pass one in the constructor\n * the cursorStyle property\n * @param {Event} eventData the native mouse event\n * @param {Control} control the current control ( likely this)\n * @param {FabricObject} object on which the control is displayed\n * @return {String}\n */\n cursorStyleHandler(\n eventData: TPointerEvent,\n control: Control,\n fabricObject: InteractiveFabricObject,\n coord: TOCoord,\n ) {\n return control.cursorStyle;\n }\n\n /**\n * Returns the action name. The basic implementation just return the actionName property.\n * @param {Event} eventData the native mouse event\n * @param {Control} control the current control ( likely this)\n * @param {FabricObject} object on which the control is displayed\n * @return {String}\n */\n getActionName(\n eventData: TPointerEvent,\n control: Control,\n fabricObject: InteractiveFabricObject,\n ) {\n return control.actionName;\n }\n\n /**\n * Returns controls visibility\n * @param {FabricObject} object on which the control is displayed\n * @param {String} controlKey key where the control is memorized on the\n * @return {Boolean}\n */\n getVisibility(fabricObject: InteractiveFabricObject, controlKey: string) {\n return fabricObject._controlsVisibility?.[controlKey] ?? this.visible;\n }\n\n /**\n * Sets controls visibility\n * @param {Boolean} visibility for the object\n * @return {Void}\n */\n setVisibility(\n visibility: boolean,\n name?: string,\n fabricObject?: InteractiveFabricObject,\n ) {\n this.visible = visibility;\n }\n\n positionHandler(\n dim: Point,\n finalMatrix: TMat2D,\n fabricObject: InteractiveFabricObject,\n currentControl: Control,\n ) {\n return new Point(\n this.x * dim.x + this.offsetX,\n this.y * dim.y + this.offsetY,\n ).transform(finalMatrix);\n }\n\n /**\n * Returns the coords for this control based on object values.\n * @param {Number} objectAngle angle from the fabric object holding the control\n * @param {Number} objectCornerSize cornerSize from the fabric object holding the control (or touchCornerSize if\n * isTouch is true)\n * @param {Number} centerX x coordinate where the control center should be\n * @param {Number} centerY y coordinate where the control center should be\n * @param {boolean} isTouch true if touch corner, false if normal corner\n */\n calcCornerCoords(\n angle: TDegree,\n objectCornerSize: number,\n centerX: number,\n centerY: number,\n isTouch: boolean,\n fabricObject: InteractiveFabricObject,\n ) {\n const t = multiplyTransformMatrixArray([\n createTranslateMatrix(centerX, centerY),\n createRotateMatrix({ angle }),\n createScaleMatrix(\n (isTouch ? this.touchSizeX : this.sizeX) || objectCornerSize,\n (isTouch ? this.touchSizeY : this.sizeY) || objectCornerSize,\n ),\n ]);\n return {\n tl: new Point(-0.5, -0.5).transform(t),\n tr: new Point(0.5, -0.5).transform(t),\n br: new Point(0.5, 0.5).transform(t),\n bl: new Point(-0.5, 0.5).transform(t),\n };\n }\n\n /**\n * This is an helper method to prepare the canvas to render a control\n * It detectes common control properties and sets the correct fill and\n * stroke styles on the context. It does not execute translations or\n * rotations since different controls need differnt combination of these.\n */\n commonRenderProps(\n ctx: CanvasRenderingContext2D,\n left: number,\n top: number,\n fabricObject: InteractiveFabricObject,\n styleOverride: ControlRenderingStyleOverride = {},\n ): {\n stroke: boolean;\n xSize: number;\n ySize: number;\n transparentCorners: boolean;\n opName: 'stroke' | 'fill';\n } {\n const { cornerSize, cornerColor, transparentCorners, cornerStrokeColor } =\n styleOverride,\n sizeFromProps = cornerSize || fabricObject.cornerSize,\n xSize = this.sizeX || sizeFromProps,\n ySize = this.sizeY || sizeFromProps,\n transparent =\n typeof transparentCorners !== 'undefined'\n ? transparentCorners\n : fabricObject.transparentCorners,\n opName = transparent ? STROKE : FILL,\n strokeColor = cornerStrokeColor || fabricObject.cornerStrokeColor,\n stroke = !transparent && !!strokeColor;\n ctx.fillStyle = cornerColor || fabricObject.cornerColor || '';\n ctx.strokeStyle = strokeColor || '';\n ctx.translate(left, top);\n // angle is relative to canvas plane\n ctx.rotate(degreesToRadians(fabricObject.getTotalAngle()));\n return {\n stroke,\n xSize,\n ySize,\n transparentCorners: transparent,\n opName,\n };\n }\n\n /**\n * Render function for the control.\n * When this function runs the context is unscaled. unrotate. Just retina scaled.\n * all the functions will have to translate to the point left,top before starting Drawing\n * if they want to draw a control where the position is detected.\n * left and top are the result of the positionHandler function\n * @param {RenderingContext2D} ctx the context where the control will be drawn\n * @param {Number} left position of the canvas where we are about to render the control.\n * @param {Number} top position of the canvas where we are about to render the control.\n * @param {Object} styleOverride\n * @param {FabricObject} fabricObject the object where the control is about to be rendered\n */\n render(\n ctx: CanvasRenderingContext2D,\n left: number,\n top: number,\n styleOverride: ControlRenderingStyleOverride | undefined,\n fabricObject: InteractiveFabricObject,\n ) {\n styleOverride = styleOverride || {};\n switch (styleOverride.cornerStyle || fabricObject.cornerStyle) {\n case 'circle':\n renderCircleControl.call(\n this,\n ctx,\n left,\n top,\n styleOverride,\n fabricObject,\n );\n break;\n default:\n renderSquareControl.call(\n this,\n ctx,\n left,\n top,\n styleOverride,\n fabricObject,\n );\n }\n }\n}\n"],"names":["Control","constructor","options","_defineProperty","SCALE","Object","assign","this","getTransformAnchorPoint","_this$transformAnchor","transformAnchorPoint","Point","x","y","shouldActivate","controlKey","fabricObject","pointer","_ref","_fabricObject$canvas","tl","tr","br","bl","canvas","getActiveObject","isControlVisible","Intersection","isPointInPolygon","getActionHandler","eventData","control","actionHandler","getMouseDownHandler","mouseDownHandler","getMouseUpHandler","mouseUpHandler","cursorStyleHandler","coord","cursorStyle","getActionName","actionName","getVisibility","_fabricObject$_contro","_fabricObject$_contro2","_controlsVisibility","visible","setVisibility","visibility","name","positionHandler","dim","finalMatrix","currentControl","offsetX","offsetY","transform","calcCornerCoords","angle","objectCornerSize","centerX","centerY","isTouch","t","multiplyTransformMatrixArray","createTranslateMatrix","createRotateMatrix","createScaleMatrix","touchSizeX","sizeX","touchSizeY","sizeY","commonRenderProps","ctx","left","top","styleOverride","arguments","length","undefined","cornerSize","cornerColor","transparentCorners","cornerStrokeColor","sizeFromProps","xSize","ySize","transparent","opName","STROKE","FILL","strokeColor","stroke","fillStyle","strokeStyle","translate","rotate","degreesToRadians","getTotalAngle","render","cornerStyle","renderCircleControl","call","renderSquareControl"],"mappings":"qjBA8BO,MAAMA,EA8HXC,WAAAA,CAAYC,GA7HZC,kBAQU,GAEVA,oBAWaC,GAEbD,eAOQ,GAERA,WAOI,GAEJA,WAOI,GAEJA,iBAYU,GAEVA,iBAMU,GAEVA,eAMQ,GAERA,eAMQ,GAERA,oBAMa,GAEbA,oBAMa,GAEbA,qBAMc,aAEdA,yBAMiB,GAQfE,OAAOC,OAAOC,KAAML,EACtB,CAEAM,uBAAAA,GAGE,IAAAC,EACA,OAE2B,QADzBA,EACAF,KAAKG,gCAAoBD,EAAAA,EAEzB,IAAIE,EAAgB,GAATJ,KAAKK,EAAmB,GAATL,KAAKM,EAEnC,CAgCAC,cAAAA,CACEC,EACAC,EACAC,EAAcC,GAEd,IAAAC,EAAA,IADAC,GAAEA,EAAEC,GAAEA,EAAEC,GAAEA,EAAEC,GAAEA,GAAkBL,EAGhC,OACqB,QAAnBC,EAAAH,EAAaQ,cAAM,IAAAL,OAAA,EAAnBA,EAAqBM,qBAAsBT,GAC3CA,EAAaU,iBAAiBX,IAC9BY,EAAaC,iBAAiBX,EAAS,CAACG,EAAIC,EAAIC,EAAIC,GAExD,CASAM,gBAAAA,CACEC,EACAd,EACAe,GAEA,OAAOxB,KAAKyB,aACd,CASAC,mBAAAA,CACEH,EACAd,EACAe,GAEA,OAAOxB,KAAK2B,gBACd,CAUAC,iBAAAA,CACEL,EACAd,EACAe,GAEA,OAAOxB,KAAK6B,cACd,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9E,KAAK8D,OAASe,EACtBE,EAAQ/E,KAAKgE,OAASa,EACtBG,OACgC,IAAvBL,EACHA,EACAlE,EAAakE,mBACnBM,EAASD,EAAcE,EAASC,EAChCC,EAAcR,GAAqBnE,EAAamE,kBAChDS,GAAUL,KAAiBI,EAM7B,OALAlB,EAAIoB,UAAYZ,GAAejE,EAAaiE,aAAe,GAC3DR,EAAIqB,YAAcH,GAAe,GACjClB,EAAIsB,UAAUrB,EAAMC,GAEpBF,EAAIuB,OAAOC,EAAiBjF,EAAakF,kBAClC,CACLN,SACAP,QACAC,QACAJ,mBAAoBK,EACpBC,SAEJ,CAcAW,MAAAA,CACE1B,EACAC,EACAC,EACAC,EACA5D,GAGA,GACO,aAFP4D,EAAgBA,GAAiB,CAAA,GACXwB,aAAepF,EAAaoF,aAE9CC,EAAoBC,KAClB/F,KACAkE,EACAC,EACAC,EACAC,EACA5D,QAIFuF,EAAoBD,KAClB/F,KACAkE,EACAC,EACAC,EACAC,EACA5D,EAGR"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { defineProperty as _defineProperty } from '../../_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
2
|
import { Intersection } from '../Intersection.mjs';
|
|
3
3
|
import { Point } from '../Point.mjs';
|
|
4
|
-
import { SCALE } from '../constants.mjs';
|
|
4
|
+
import { SCALE, STROKE, FILL } from '../constants.mjs';
|
|
5
5
|
import { multiplyTransformMatrixArray, createTranslateMatrix, createRotateMatrix, createScaleMatrix } from '../util/misc/matrix.mjs';
|
|
6
|
+
import { degreesToRadians } from '../util/misc/radiansDegreesConversion.mjs';
|
|
6
7
|
import { renderSquareControl, renderCircleControl } from './controlRendering.mjs';
|
|
7
8
|
|
|
8
9
|
class Control {
|
|
@@ -116,6 +117,14 @@ class Control {
|
|
|
116
117
|
_defineProperty(this, "withConnection", false);
|
|
117
118
|
Object.assign(this, options);
|
|
118
119
|
}
|
|
120
|
+
getTransformAnchorPoint() {
|
|
121
|
+
var _this$transformAnchor;
|
|
122
|
+
return (// return the control transformAnchorPoint
|
|
123
|
+
(_this$transformAnchor = this.transformAnchorPoint) !== null && _this$transformAnchor !== void 0 ? _this$transformAnchor :
|
|
124
|
+
// otherwise will return the opposite origin of where the control is located.
|
|
125
|
+
new Point(-this.x + 0.5, -this.y + 0.5)
|
|
126
|
+
);
|
|
127
|
+
}
|
|
119
128
|
|
|
120
129
|
/**
|
|
121
130
|
* The control actionHandler, provide one to handle action ( control being moved )
|
|
@@ -258,6 +267,41 @@ class Control {
|
|
|
258
267
|
};
|
|
259
268
|
}
|
|
260
269
|
|
|
270
|
+
/**
|
|
271
|
+
* This is an helper method to prepare the canvas to render a control
|
|
272
|
+
* It detectes common control properties and sets the correct fill and
|
|
273
|
+
* stroke styles on the context. It does not execute translations or
|
|
274
|
+
* rotations since different controls need differnt combination of these.
|
|
275
|
+
*/
|
|
276
|
+
commonRenderProps(ctx, left, top, fabricObject) {
|
|
277
|
+
let styleOverride = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
278
|
+
const {
|
|
279
|
+
cornerSize,
|
|
280
|
+
cornerColor,
|
|
281
|
+
transparentCorners,
|
|
282
|
+
cornerStrokeColor
|
|
283
|
+
} = styleOverride,
|
|
284
|
+
sizeFromProps = cornerSize || fabricObject.cornerSize,
|
|
285
|
+
xSize = this.sizeX || sizeFromProps,
|
|
286
|
+
ySize = this.sizeY || sizeFromProps,
|
|
287
|
+
transparent = typeof transparentCorners !== 'undefined' ? transparentCorners : fabricObject.transparentCorners,
|
|
288
|
+
opName = transparent ? STROKE : FILL,
|
|
289
|
+
strokeColor = cornerStrokeColor || fabricObject.cornerStrokeColor,
|
|
290
|
+
stroke = !transparent && !!strokeColor;
|
|
291
|
+
ctx.fillStyle = cornerColor || fabricObject.cornerColor || '';
|
|
292
|
+
ctx.strokeStyle = strokeColor || '';
|
|
293
|
+
ctx.translate(left, top);
|
|
294
|
+
// angle is relative to canvas plane
|
|
295
|
+
ctx.rotate(degreesToRadians(fabricObject.getTotalAngle()));
|
|
296
|
+
return {
|
|
297
|
+
stroke,
|
|
298
|
+
xSize,
|
|
299
|
+
ySize,
|
|
300
|
+
transparentCorners: transparent,
|
|
301
|
+
opName
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
261
305
|
/**
|
|
262
306
|
* Render function for the control.
|
|
263
307
|
* When this function runs the context is unscaled. unrotate. Just retina scaled.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Control.mjs","sources":["../../../src/controls/Control.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport type {\n ControlActionHandler,\n TPointerEvent,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport { Intersection } from '../Intersection';\nimport { Point } from '../Point';\nimport { SCALE } from '../constants';\nimport type {\n InteractiveFabricObject,\n TOCoord,\n} from '../shapes/Object/InteractiveObject';\nimport type { TCornerPoint, TDegree, TMat2D } from '../typedefs';\nimport {\n createRotateMatrix,\n createScaleMatrix,\n createTranslateMatrix,\n multiplyTransformMatrixArray,\n} from '../util/misc/matrix';\nimport type { ControlRenderingStyleOverride } from './controlRendering';\nimport { renderCircleControl, renderSquareControl } from './controlRendering';\n\nexport class Control {\n /**\n * keep track of control visibility.\n * mainly for backward compatibility.\n * if you do not want to see a control, you can remove it\n * from the control set.\n * @type {Boolean}\n * @default true\n */\n visible = true;\n\n /**\n * Name of the action that the control will likely execute.\n * This is optional. FabricJS uses to identify what the user is doing for some\n * extra optimizations. If you are writing a custom control and you want to know\n * somewhere else in the code what is going on, you can use this string here.\n * you can also provide a custom getActionName if your control run multiple actions\n * depending on some external state.\n * default to scale since is the most common, used on 4 corners by default\n * @type {String}\n * @default 'scale'\n */\n actionName = SCALE;\n\n /**\n * Drawing angle of the control.\n * NOT used for now, but name marked as needed for internal logic\n * example: to reuse the same drawing function for different rotated controls\n * @type {Number}\n * @default 0\n */\n angle = 0;\n\n /**\n * Relative position of the control. X\n * 0,0 is the center of the Object, while -0.5 (left) or 0.5 (right) are the extremities\n * of the bounding box.\n * @type {Number}\n * @default 0\n */\n x = 0;\n\n /**\n * Relative position of the control. Y\n * 0,0 is the center of the Object, while -0.5 (top) or 0.5 (bottom) are the extremities\n * of the bounding box.\n * @type {Number}\n * @default 0\n */\n y = 0;\n\n /**\n * Horizontal offset of the control from the defined position. In pixels\n * Positive offset moves the control to the right, negative to the left.\n * It used when you want to have position of control that does not scale with\n * the bounding box. Example: rotation control is placed at x:0, y: 0.5 on\n * the boundind box, with an offset of 30 pixels vertically. Those 30 pixels will\n * stay 30 pixels no matter how the object is big. Another example is having 2\n * controls in the corner, that stay in the same position when the object scale.\n * of the bounding box.\n * @type {Number}\n * @default 0\n */\n offsetX = 0;\n\n /**\n * Vertical offset of the control from the defined position. In pixels\n * Positive offset moves the control to the bottom, negative to the top.\n * @type {Number}\n * @default 0\n */\n offsetY = 0;\n\n /**\n * Sets the length of the control. If null, defaults to object's cornerSize.\n * Expects both sizeX and sizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n sizeX = 0;\n\n /**\n * Sets the height of the control. If null, defaults to object's cornerSize.\n * Expects both sizeX and sizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n sizeY = 0;\n\n /**\n * Sets the length of the touch area of the control. If null, defaults to object's touchCornerSize.\n * Expects both touchSizeX and touchSizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n touchSizeX = 0;\n\n /**\n * Sets the height of the touch area of the control. If null, defaults to object's touchCornerSize.\n * Expects both touchSizeX and touchSizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n touchSizeY = 0;\n\n /**\n * Css cursor style to display when the control is hovered.\n * if the method `cursorStyleHandler` is provided, this property is ignored.\n * @type {String}\n * @default 'crosshair'\n */\n cursorStyle = 'crosshair';\n\n /**\n * If controls has an offsetY or offsetX, draw a line that connects\n * the control to the bounding box\n * @type {Boolean}\n * @default false\n */\n withConnection = false;\n\n constructor(options?: Partial<Control>) {\n Object.assign(this, options);\n }\n\n /**\n * The control actionHandler, provide one to handle action ( control being moved )\n * @param {Event} eventData the native mouse event\n * @param {Transform} transformData properties of the current transform\n * @param {Number} x x position of the cursor\n * @param {Number} y y position of the cursor\n * @return {Boolean} true if the action/event modified the object\n */\n declare actionHandler: TransformActionHandler;\n\n /**\n * The control handler for mouse down, provide one to handle mouse down on control\n * @param {Event} eventData the native mouse event\n * @param {Transform} transformData properties of the current transform\n * @param {Number} x x position of the cursor\n * @param {Number} y y position of the cursor\n * @return {Boolean} true if the action/event modified the object\n */\n declare mouseDownHandler?: ControlActionHandler;\n\n /**\n * The control mouseUpHandler, provide one to handle an effect on mouse up.\n * @param {Event} eventData the native mouse event\n * @param {Transform} transformData properties of the current transform\n * @param {Number} x x position of the cursor\n * @param {Number} y y position of the cursor\n * @return {Boolean} true if the action/event modified the object\n */\n declare mouseUpHandler?: ControlActionHandler;\n\n shouldActivate(\n controlKey: string,\n fabricObject: InteractiveFabricObject,\n pointer: Point,\n { tl, tr, br, bl }: TCornerPoint,\n ) {\n // TODO: locking logic can be handled here instead of in the control handler logic\n return (\n fabricObject.canvas?.getActiveObject() === fabricObject &&\n fabricObject.isControlVisible(controlKey) &&\n Intersection.isPointInPolygon(pointer, [tl, tr, br, bl])\n );\n }\n\n /**\n * Returns control actionHandler\n * @param {Event} eventData the native mouse event\n * @param {FabricObject} fabricObject on which the control is displayed\n * @param {Control} control control for which the action handler is being asked\n * @return {Function} the action handler\n */\n getActionHandler(\n eventData: TPointerEvent,\n fabricObject: InteractiveFabricObject,\n control: Control,\n ): TransformActionHandler | undefined {\n return this.actionHandler;\n }\n\n /**\n * Returns control mouseDown handler\n * @param {Event} eventData the native mouse event\n * @param {FabricObject} fabricObject on which the control is displayed\n * @param {Control} control control for which the action handler is being asked\n * @return {Function} the action handler\n */\n getMouseDownHandler(\n eventData: TPointerEvent,\n fabricObject: InteractiveFabricObject,\n control: Control,\n ): ControlActionHandler | undefined {\n return this.mouseDownHandler;\n }\n\n /**\n * Returns control mouseUp handler.\n * During actions the fabricObject or the control can be of different obj\n * @param {Event} eventData the native mouse event\n * @param {FabricObject} fabricObject on which the control is displayed\n * @param {Control} control control for which the action handler is being asked\n * @return {Function} the action handler\n */\n getMouseUpHandler(\n eventData: TPointerEvent,\n fabricObject: InteractiveFabricObject,\n control: Control,\n ): ControlActionHandler | undefined {\n return this.mouseUpHandler;\n }\n\n /**\n * Returns control cursorStyle for css using cursorStyle. If you need a more elaborate\n * function you can pass one in the constructor\n * the cursorStyle property\n * @param {Event} eventData the native mouse event\n * @param {Control} control the current control ( likely this)\n * @param {FabricObject} object on which the control is displayed\n * @return {String}\n */\n cursorStyleHandler(\n eventData: TPointerEvent,\n control: Control,\n fabricObject: InteractiveFabricObject,\n coord: TOCoord,\n ) {\n return control.cursorStyle;\n }\n\n /**\n * Returns the action name. The basic implementation just return the actionName property.\n * @param {Event} eventData the native mouse event\n * @param {Control} control the current control ( likely this)\n * @param {FabricObject} object on which the control is displayed\n * @return {String}\n */\n getActionName(\n eventData: TPointerEvent,\n control: Control,\n fabricObject: InteractiveFabricObject,\n ) {\n return control.actionName;\n }\n\n /**\n * Returns controls visibility\n * @param {FabricObject} object on which the control is displayed\n * @param {String} controlKey key where the control is memorized on the\n * @return {Boolean}\n */\n getVisibility(fabricObject: InteractiveFabricObject, controlKey: string) {\n return fabricObject._controlsVisibility?.[controlKey] ?? this.visible;\n }\n\n /**\n * Sets controls visibility\n * @param {Boolean} visibility for the object\n * @return {Void}\n */\n setVisibility(\n visibility: boolean,\n name?: string,\n fabricObject?: InteractiveFabricObject,\n ) {\n this.visible = visibility;\n }\n\n positionHandler(\n dim: Point,\n finalMatrix: TMat2D,\n fabricObject: InteractiveFabricObject,\n currentControl: Control,\n ) {\n return new Point(\n this.x * dim.x + this.offsetX,\n this.y * dim.y + this.offsetY,\n ).transform(finalMatrix);\n }\n\n /**\n * Returns the coords for this control based on object values.\n * @param {Number} objectAngle angle from the fabric object holding the control\n * @param {Number} objectCornerSize cornerSize from the fabric object holding the control (or touchCornerSize if\n * isTouch is true)\n * @param {Number} centerX x coordinate where the control center should be\n * @param {Number} centerY y coordinate where the control center should be\n * @param {boolean} isTouch true if touch corner, false if normal corner\n */\n calcCornerCoords(\n angle: TDegree,\n objectCornerSize: number,\n centerX: number,\n centerY: number,\n isTouch: boolean,\n fabricObject: InteractiveFabricObject,\n ) {\n const t = multiplyTransformMatrixArray([\n createTranslateMatrix(centerX, centerY),\n createRotateMatrix({ angle }),\n createScaleMatrix(\n (isTouch ? this.touchSizeX : this.sizeX) || objectCornerSize,\n (isTouch ? this.touchSizeY : this.sizeY) || objectCornerSize,\n ),\n ]);\n return {\n tl: new Point(-0.5, -0.5).transform(t),\n tr: new Point(0.5, -0.5).transform(t),\n br: new Point(0.5, 0.5).transform(t),\n bl: new Point(-0.5, 0.5).transform(t),\n };\n }\n\n /**\n * Render function for the control.\n * When this function runs the context is unscaled. unrotate. Just retina scaled.\n * all the functions will have to translate to the point left,top before starting Drawing\n * if they want to draw a control where the position is detected.\n * left and top are the result of the positionHandler function\n * @param {RenderingContext2D} ctx the context where the control will be drawn\n * @param {Number} left position of the canvas where we are about to render the control.\n * @param {Number} top position of the canvas where we are about to render the control.\n * @param {Object} styleOverride\n * @param {FabricObject} fabricObject the object where the control is about to be rendered\n */\n render(\n ctx: CanvasRenderingContext2D,\n left: number,\n top: number,\n styleOverride: ControlRenderingStyleOverride | undefined,\n fabricObject: InteractiveFabricObject,\n ) {\n styleOverride = styleOverride || {};\n switch (styleOverride.cornerStyle || fabricObject.cornerStyle) {\n case 'circle':\n renderCircleControl.call(\n this,\n ctx,\n left,\n top,\n styleOverride,\n fabricObject,\n );\n break;\n default:\n renderSquareControl.call(\n this,\n ctx,\n left,\n top,\n styleOverride,\n fabricObject,\n );\n }\n }\n}\n"],"names":["Control","constructor","options","_defineProperty","SCALE","Object","assign","shouldActivate","controlKey","fabricObject","pointer","_ref","_fabricObject$canvas","tl","tr","br","bl","canvas","getActiveObject","isControlVisible","Intersection","isPointInPolygon","getActionHandler","eventData","control","actionHandler","getMouseDownHandler","mouseDownHandler","getMouseUpHandler","mouseUpHandler","cursorStyleHandler","coord","cursorStyle","getActionName","actionName","getVisibility","_fabricObject$_contro","_fabricObject$_contro2","_controlsVisibility","visible","setVisibility","visibility","name","positionHandler","dim","finalMatrix","currentControl","Point","x","offsetX","y","offsetY","transform","calcCornerCoords","angle","objectCornerSize","centerX","centerY","isTouch","t","multiplyTransformMatrixArray","createTranslateMatrix","createRotateMatrix","createScaleMatrix","touchSizeX","sizeX","touchSizeY","sizeY","render","ctx","left","top","styleOverride","cornerStyle","renderCircleControl","call","renderSquareControl"],"mappings":";;;;;;;AAuBO,MAAMA,OAAO,CAAC;EAyHnBC,WAAWA,CAACC,OAA0B,EAAE;AAxHxC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AAPEC,IAAAA,eAAA,kBAQU,IAAI,CAAA;AAEd;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAVEA,IAAAA,eAAA,qBAWaC,KAAK,CAAA;AAElB;AACF;AACA;AACA;AACA;AACA;AACA;AANED,IAAAA,eAAA,gBAOQ,CAAC,CAAA;AAET;AACF;AACA;AACA;AACA;AACA;AACA;AANEA,IAAAA,eAAA,YAOI,CAAC,CAAA;AAEL;AACF;AACA;AACA;AACA;AACA;AACA;AANEA,IAAAA,eAAA,YAOI,CAAC,CAAA;AAEL;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAXEA,IAAAA,eAAA,kBAYU,CAAC,CAAA;AAEX;AACF;AACA;AACA;AACA;AACA;AALEA,IAAAA,eAAA,kBAMU,CAAC,CAAA;AAEX;AACF;AACA;AACA;AACA;AACA;AALEA,IAAAA,eAAA,gBAMQ,CAAC,CAAA;AAET;AACF;AACA;AACA;AACA;AACA;AALEA,IAAAA,eAAA,gBAMQ,CAAC,CAAA;AAET;AACF;AACA;AACA;AACA;AACA;AALEA,IAAAA,eAAA,qBAMa,CAAC,CAA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,WAAW;AAC3D,MAAA,KAAK,QAAQ;AACXC,QAAAA,mBAAmB,CAACC,IAAI,CACtB,IAAI,EACJN,GAAG,EACHC,IAAI,EACJC,GAAG,EACHC,aAAa,EACb/D,YACF,CAAC;AACD,QAAA;AACF,MAAA;AACEmE,QAAAA,mBAAmB,CAACD,IAAI,CACtB,IAAI,EACJN,GAAG,EACHC,IAAI,EACJC,GAAG,EACHC,aAAa,EACb/D,YACF,CAAC;AACL;AACF,EAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"Control.mjs","sources":["../../../src/controls/Control.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport type {\n ControlActionHandler,\n TPointerEvent,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport { Intersection } from '../Intersection';\nimport { Point } from '../Point';\nimport { FILL, SCALE, STROKE } from '../constants';\nimport type {\n InteractiveFabricObject,\n TOCoord,\n} from '../shapes/Object/InteractiveObject';\nimport type {\n TCornerPoint,\n TDegree,\n TMat2D,\n TOriginX,\n TOriginY,\n} from '../typedefs';\nimport {\n createRotateMatrix,\n createScaleMatrix,\n createTranslateMatrix,\n multiplyTransformMatrixArray,\n} from '../util/misc/matrix';\nimport { degreesToRadians } from '../util/misc/radiansDegreesConversion';\nimport type { ControlRenderingStyleOverride } from './controlRendering';\nimport { renderCircleControl, renderSquareControl } from './controlRendering';\n\nexport class Control {\n /**\n * keep track of control visibility.\n * mainly for backward compatibility.\n * if you do not want to see a control, you can remove it\n * from the control set.\n * @type {Boolean}\n * @default true\n */\n visible = true;\n\n /**\n * Name of the action that the control will likely execute.\n * This is optional. FabricJS uses to identify what the user is doing for some\n * extra optimizations. If you are writing a custom control and you want to know\n * somewhere else in the code what is going on, you can use this string here.\n * you can also provide a custom getActionName if your control run multiple actions\n * depending on some external state.\n * default to scale since is the most common, used on 4 corners by default\n * @type {String}\n * @default 'scale'\n */\n actionName = SCALE;\n\n /**\n * Drawing angle of the control.\n * NOT used for now, but name marked as needed for internal logic\n * example: to reuse the same drawing function for different rotated controls\n * @type {Number}\n * @default 0\n */\n angle = 0;\n\n /**\n * Relative position of the control. X\n * 0,0 is the center of the Object, while -0.5 (left) or 0.5 (right) are the extremities\n * of the bounding box.\n * @type {Number}\n * @default 0\n */\n x = 0;\n\n /**\n * Relative position of the control. Y\n * 0,0 is the center of the Object, while -0.5 (top) or 0.5 (bottom) are the extremities\n * of the bounding box.\n * @type {Number}\n * @default 0\n */\n y = 0;\n\n /**\n * Horizontal offset of the control from the defined position. In pixels\n * Positive offset moves the control to the right, negative to the left.\n * It used when you want to have position of control that does not scale with\n * the bounding box. Example: rotation control is placed at x:0, y: 0.5 on\n * the boundind box, with an offset of 30 pixels vertically. Those 30 pixels will\n * stay 30 pixels no matter how the object is big. Another example is having 2\n * controls in the corner, that stay in the same position when the object scale.\n * of the bounding box.\n * @type {Number}\n * @default 0\n */\n offsetX = 0;\n\n /**\n * Vertical offset of the control from the defined position. In pixels\n * Positive offset moves the control to the bottom, negative to the top.\n * @type {Number}\n * @default 0\n */\n offsetY = 0;\n\n /**\n * Sets the length of the control. If null, defaults to object's cornerSize.\n * Expects both sizeX and sizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n sizeX = 0;\n\n /**\n * Sets the height of the control. If null, defaults to object's cornerSize.\n * Expects both sizeX and sizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n sizeY = 0;\n\n /**\n * Sets the length of the touch area of the control. If null, defaults to object's touchCornerSize.\n * Expects both touchSizeX and touchSizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n touchSizeX = 0;\n\n /**\n * Sets the height of the touch area of the control. If null, defaults to object's touchCornerSize.\n * Expects both touchSizeX and touchSizeY to be set when set.\n * @type {?Number}\n * @default null\n */\n touchSizeY = 0;\n\n /**\n * Css cursor style to display when the control is hovered.\n * if the method `cursorStyleHandler` is provided, this property is ignored.\n * @type {String}\n * @default 'crosshair'\n */\n cursorStyle = 'crosshair';\n\n /**\n * If controls has an offsetY or offsetX, draw a line that connects\n * the control to the bounding box\n * @type {Boolean}\n * @default false\n */\n withConnection = false;\n\n declare transformAnchorPoint?: {\n x: TOriginX;\n y: TOriginY;\n };\n\n constructor(options?: Partial<Control>) {\n Object.assign(this, options);\n }\n\n getTransformAnchorPoint(): {\n x: TOriginX;\n y: TOriginY;\n } {\n return (\n // return the control transformAnchorPoint\n this.transformAnchorPoint ??\n // otherwise will return the opposite origin of where the control is located.\n new Point(-this.x + 0.5, -this.y + 0.5)\n );\n }\n\n /**\n * The control actionHandler, provide one to handle action ( control being moved )\n * @param {Event} eventData the native mouse event\n * @param {Transform} transformData properties of the current transform\n * @param {Number} x x position of the cursor\n * @param {Number} y y position of the cursor\n * @return {Boolean} true if the action/event modified the object\n */\n declare actionHandler: TransformActionHandler;\n\n /**\n * The control handler for mouse down, provide one to handle mouse down on control\n * @param {Event} eventData the native mouse event\n * @param {Transform} transformData properties of the current transform\n * @param {Number} x x position of the cursor\n * @param {Number} y y position of the cursor\n * @return {Boolean} true if the action/event modified the object\n */\n declare mouseDownHandler?: ControlActionHandler;\n\n /**\n * The control mouseUpHandler, provide one to handle an effect on mouse up.\n * @param {Event} eventData the native mouse event\n * @param {Transform} transformData properties of the current transform\n * @param {Number} x x position of the cursor\n * @param {Number} y y position of the cursor\n * @return {Boolean} true if the action/event modified the object\n */\n declare mouseUpHandler?: ControlActionHandler;\n\n shouldActivate(\n controlKey: string,\n fabricObject: InteractiveFabricObject,\n pointer: Point,\n { tl, tr, br, bl }: TCornerPoint,\n ) {\n // TODO: locking logic can be handled here instead of in the control handler logic\n return (\n fabricObject.canvas?.getActiveObject() === fabricObject &&\n fabricObject.isControlVisible(controlKey) &&\n Intersection.isPointInPolygon(pointer, [tl, tr, br, bl])\n );\n }\n\n /**\n * Returns control actionHandler\n * @param {Event} eventData the native mouse event\n * @param {FabricObject} fabricObject on which the control is displayed\n * @param {Control} control control for which the action handler is being asked\n * @return {Function} the action handler\n */\n getActionHandler(\n eventData: TPointerEvent,\n fabricObject: InteractiveFabricObject,\n control: Control,\n ): TransformActionHandler | undefined {\n return this.actionHandler;\n }\n\n /**\n * Returns control mouseDown handler\n * @param {Event} eventData the native mouse event\n * @param {FabricObject} fabricObject on which the control is displayed\n * @param {Control} control control for which the action handler is being asked\n * @return {Function} the action handler\n */\n getMouseDownHandler(\n eventData: TPointerEvent,\n fabricObject: InteractiveFabricObject,\n control: Control,\n ): ControlActionHandler | undefined {\n return this.mouseDownHandler;\n }\n\n /**\n * Returns control mouseUp handler.\n * During actions the fabricObject or the control can be of different obj\n * @param {Event} eventData the native mouse event\n * @param {FabricObject} fabricObject on which the control is displayed\n * @param {Control} control control for which the action handler is being asked\n * @return {Function} the action handler\n */\n getMouseUpHandler(\n eventData: TPointerEvent,\n fabricObject: InteractiveFabricObject,\n control: Control,\n ): ControlActionHandler | undefined {\n return this.mouseUpHandler;\n }\n\n /**\n * Returns control cursorStyle for css using cursorStyle. If you need a more elaborate\n * function you can pass one in the constructor\n * the cursorStyle property\n * @param {Event} eventData the native mouse event\n * @param {Control} control the current control ( likely this)\n * @param {FabricObject} object on which the control is displayed\n * @return {String}\n */\n cursorStyleHandler(\n eventData: TPointerEvent,\n control: Control,\n fabricObject: InteractiveFabricObject,\n coord: TOCoord,\n ) {\n return control.cursorStyle;\n }\n\n /**\n * Returns the action name. The basic implementation just return the actionName property.\n * @param {Event} eventData the native mouse event\n * @param {Control} control the current control ( likely this)\n * @param {FabricObject} object on which the control is displayed\n * @return {String}\n */\n getActionName(\n eventData: TPointerEvent,\n control: Control,\n fabricObject: InteractiveFabricObject,\n ) {\n return control.actionName;\n }\n\n /**\n * Returns controls visibility\n * @param {FabricObject} object on which the control is displayed\n * @param {String} controlKey key where the control is memorized on the\n * @return {Boolean}\n */\n getVisibility(fabricObject: InteractiveFabricObject, controlKey: string) {\n return fabricObject._controlsVisibility?.[controlKey] ?? this.visible;\n }\n\n /**\n * Sets controls visibility\n * @param {Boolean} visibility for the object\n * @return {Void}\n */\n setVisibility(\n visibility: boolean,\n name?: string,\n fabricObject?: InteractiveFabricObject,\n ) {\n this.visible = visibility;\n }\n\n positionHandler(\n dim: Point,\n finalMatrix: TMat2D,\n fabricObject: InteractiveFabricObject,\n currentControl: Control,\n ) {\n return new Point(\n this.x * dim.x + this.offsetX,\n this.y * dim.y + this.offsetY,\n ).transform(finalMatrix);\n }\n\n /**\n * Returns the coords for this control based on object values.\n * @param {Number} objectAngle angle from the fabric object holding the control\n * @param {Number} objectCornerSize cornerSize from the fabric object holding the control (or touchCornerSize if\n * isTouch is true)\n * @param {Number} centerX x coordinate where the control center should be\n * @param {Number} centerY y coordinate where the control center should be\n * @param {boolean} isTouch true if touch corner, false if normal corner\n */\n calcCornerCoords(\n angle: TDegree,\n objectCornerSize: number,\n centerX: number,\n centerY: number,\n isTouch: boolean,\n fabricObject: InteractiveFabricObject,\n ) {\n const t = multiplyTransformMatrixArray([\n createTranslateMatrix(centerX, centerY),\n createRotateMatrix({ angle }),\n createScaleMatrix(\n (isTouch ? this.touchSizeX : this.sizeX) || objectCornerSize,\n (isTouch ? this.touchSizeY : this.sizeY) || objectCornerSize,\n ),\n ]);\n return {\n tl: new Point(-0.5, -0.5).transform(t),\n tr: new Point(0.5, -0.5).transform(t),\n br: new Point(0.5, 0.5).transform(t),\n bl: new Point(-0.5, 0.5).transform(t),\n };\n }\n\n /**\n * This is an helper method to prepare the canvas to render a control\n * It detectes common control properties and sets the correct fill and\n * stroke styles on the context. It does not execute translations or\n * rotations since different controls need differnt combination of these.\n */\n commonRenderProps(\n ctx: CanvasRenderingContext2D,\n left: number,\n top: number,\n fabricObject: InteractiveFabricObject,\n styleOverride: ControlRenderingStyleOverride = {},\n ): {\n stroke: boolean;\n xSize: number;\n ySize: number;\n transparentCorners: boolean;\n opName: 'stroke' | 'fill';\n } {\n const { cornerSize, cornerColor, transparentCorners, cornerStrokeColor } =\n styleOverride,\n sizeFromProps = cornerSize || fabricObject.cornerSize,\n xSize = this.sizeX || sizeFromProps,\n ySize = this.sizeY || sizeFromProps,\n transparent =\n typeof transparentCorners !== 'undefined'\n ? transparentCorners\n : fabricObject.transparentCorners,\n opName = transparent ? STROKE : FILL,\n strokeColor = cornerStrokeColor || fabricObject.cornerStrokeColor,\n stroke = !transparent && !!strokeColor;\n ctx.fillStyle = cornerColor || fabricObject.cornerColor || '';\n ctx.strokeStyle = strokeColor || '';\n ctx.translate(left, top);\n // angle is relative to canvas plane\n ctx.rotate(degreesToRadians(fabricObject.getTotalAngle()));\n return {\n stroke,\n xSize,\n ySize,\n transparentCorners: transparent,\n opName,\n };\n }\n\n /**\n * Render function for the control.\n * When this function runs the context is unscaled. unrotate. Just retina scaled.\n * all the functions will have to translate to the point left,top before starting Drawing\n * if they want to draw a control where the position is detected.\n * left and top are the result of the positionHandler function\n * @param {RenderingContext2D} ctx the context where the control will be drawn\n * @param {Number} left position of the canvas where we are about to render the control.\n * @param {Number} top position of the canvas where we are about to render the control.\n * @param {Object} styleOverride\n * @param {FabricObject} fabricObject the object where the control is about to be rendered\n */\n render(\n ctx: CanvasRenderingContext2D,\n left: number,\n top: number,\n styleOverride: ControlRenderingStyleOverride | undefined,\n fabricObject: InteractiveFabricObject,\n ) {\n styleOverride = styleOverride || {};\n switch (styleOverride.cornerStyle || fabricObject.cornerStyle) {\n case 'circle':\n renderCircleControl.call(\n this,\n ctx,\n left,\n top,\n styleOverride,\n fabricObject,\n );\n break;\n default:\n renderSquareControl.call(\n this,\n ctx,\n left,\n top,\n styleOverride,\n fabricObject,\n );\n }\n }\n}\n"],"names":["Control","constructor","options","_defineProperty","SCALE","Object","assign","getTransformAnchorPoint","_this$transformAnchor","transformAnchorPoint","Point","x","y","shouldActivate","controlKey","fabricObject","pointer","_ref","_fabricObject$canvas","tl","tr","br","bl","canvas","getActiveObject","isControlVisible","Intersection","isPointInPolygon","getActionHandler","eventData","control","actionHandler","getMouseDownHandler","mouseDownHandler","getMouseUpHandler","mouseUpHandler","cursorStyleHandler","coord","cursorStyle","getActionName","actionName","getVisibility","_fabricObject$_contro","_fabricObject$_contro2","_controlsVisibility","visible","setVisibility","visibility","name","positionHandler","dim","finalMatrix","currentControl","offsetX","offsetY","transform","calcCornerCoords","angle","objectCornerSize","centerX","centerY","isTouch","t","multiplyTransformMatrixArray","createTranslateMatrix","createRotateMatrix","createScaleMatrix","touchSizeX","sizeX","touchSizeY","sizeY","commonRenderProps","ctx","left","top","styleOverride","arguments","length","undefined","cornerSize","cornerColor","transparentCorners","cornerStrokeColor","sizeFromProps","xSize","ySize","transparent","opName","STROKE","FILL","strokeColor","stroke","fillStyle","strokeStyle","translate","rotate","degreesToRadians","getTotalAngle","render","cornerStyle","renderCircleControl","call","renderSquareControl"],"mappings":";;;;;;;;AA8BO,MAAMA,OAAO,CAAC;EA8HnBC,WAAWA,CAACC,OAA0B,EAAE;AA7HxC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AAPEC,IAAAA,eAAA,kBAQU,IAAI,CAAA;AAEd;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAVEA,IAAAA,eAAA,qBAWaC,KAAK,CAAA;AAElB;AACF;AACA;AACA;AACA;AACA;AACA;AANED,IAAAA,eAAA,gBAOQ,CAAC,CAAA;AAET;AACF;AACA;AACA;AACA;AACA;AACA;AANEA,IAAAA,eAAA,YAOI,CAAC,CAAA;AAEL;AACF;AACA;AACA;AACA;AACA;AACA;AANEA,IAAAA,eAAA,YAOI,CAAC,CAAA;AAEL;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAXEA,IAAAA,eAAA,kBAYU,CAAC,CAAA;AAEX;AACF;AACA;AACA;AACA;AACA;AALEA,IAAAA,eAAA,kBAMU,CAAC,CAAA;AAEX;AACF;AACA;AACA;AACA;AACA;AALEA,IAAAA,eAAA,gBAMQ,CAAC,CAAA;AAET;AACF;AACA;AACA;AACA;AACA;AALEA,IAAAA,eAAA,gBAMQ,CAAC,CAAA;AAET;AACF;AACA;AACA;AACA;AACA;AALEA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C,KAAK;AACLJ,MAAAA,kBAAkB,EAAEK,WAAW;AAC/BC,MAAAA;KACD;AACH,EAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEW,MAAMA,CACJ1B,GAA6B,EAC7BC,IAAY,EACZC,GAAW,EACXC,aAAwD,EACxD5D,YAAqC,EACrC;AACA4D,IAAAA,aAAa,GAAGA,aAAa,IAAI,EAAE;AACnC,IAAA,QAAQA,aAAa,CAACwB,WAAW,IAAIpF,YAAY,CAACoF,WAAW;AAC3D,MAAA,KAAK,QAAQ;AACXC,QAAAA,mBAAmB,CAACC,IAAI,CACtB,IAAI,EACJ7B,GAAG,EACHC,IAAI,EACJC,GAAG,EACHC,aAAa,EACb5D,YACF,CAAC;AACD,QAAA;AACF,MAAA;AACEuF,QAAAA,mBAAmB,CAACD,IAAI,CACtB,IAAI,EACJ7B,GAAG,EACHC,IAAI,EACJC,GAAG,EACHC,aAAa,EACb5D,YACF,CAAC;AACL;AACF,EAAA;AACF;;;;"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { TransformActionHandler } from '../EventTypeDefs';
|
|
2
|
+
export declare const changeObjectDimensionGen: (dimension: "width" | "height", origin: "originX" | "originY", xorY: "x" | "y", scale: "scaleX" | "scaleY") => TransformActionHandler;
|
|
2
3
|
/**
|
|
3
4
|
* Action handler to change object's width
|
|
4
5
|
* Needs to be wrapped with `wrapWithFixedAnchor` to be effective
|
|
6
|
+
* You want to use this only if you are building a new control handler and you want
|
|
7
|
+
* to reuse some logic. use "changeWidth" if you are looking to just use a control for width
|
|
5
8
|
* @param {Event} eventData javascript event that is doing the transform
|
|
6
9
|
* @param {Object} transform javascript object containing a series of information around the current transform
|
|
7
10
|
* @param {number} x current mouse x position, canvas normalized
|
|
@@ -9,5 +12,24 @@ import type { TransformActionHandler } from '../EventTypeDefs';
|
|
|
9
12
|
* @return {Boolean} true if some change happened
|
|
10
13
|
*/
|
|
11
14
|
export declare const changeObjectWidth: TransformActionHandler;
|
|
15
|
+
/**
|
|
16
|
+
* Action handler to change object's height
|
|
17
|
+
* Needs to be wrapped with `wrapWithFixedAnchor` to be effective
|
|
18
|
+
* You want to use this only if you are building a new control handler and you want
|
|
19
|
+
* to reuse some logic. use "changeHeight" if you are looking to just use a control for height
|
|
20
|
+
* @param {Event} eventData javascript event that is doing the transform
|
|
21
|
+
* @param {Object} transform javascript object containing a series of information around the current transform
|
|
22
|
+
* @param {number} x current mouse x position, canvas normalized
|
|
23
|
+
* @param {number} y current mouse y position, canvas normalized
|
|
24
|
+
* @return {Boolean} true if some change happened
|
|
25
|
+
*/
|
|
26
|
+
export declare const changeObjectHeight: TransformActionHandler;
|
|
27
|
+
/**
|
|
28
|
+
* Control handler for changing width
|
|
29
|
+
*/
|
|
12
30
|
export declare const changeWidth: TransformActionHandler<import("../EventTypeDefs").Transform>;
|
|
31
|
+
/**
|
|
32
|
+
* Control handler for changing height
|
|
33
|
+
*/
|
|
34
|
+
export declare const changeHeight: TransformActionHandler<import("../EventTypeDefs").Transform>;
|
|
13
35
|
//# sourceMappingURL=changeWidth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"changeWidth.d.ts","sourceRoot":"","sources":["../../../src/controls/changeWidth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAO/D
|
|
1
|
+
{"version":3,"file":"changeWidth.d.ts","sourceRoot":"","sources":["../../../src/controls/changeWidth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAO/D,eAAO,MAAM,wBAAwB,GAEjC,WAAW,OAAO,GAAG,QAAQ,EAC7B,QAAQ,SAAS,GAAG,SAAS,EAC7B,MAAM,GAAG,GAAG,GAAG,EACf,OAAO,QAAQ,GAAG,QAAQ,KACzB,sBA8BF,CAAC;AAEJ;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,EAAE,sBAC6B,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,EAAE,sBAC6B,CAAC;AAE/D;;GAEG;AACH,eAAO,MAAM,WAAW,8DAGvB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,8DAGxB,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{RESIZING as i
|
|
1
|
+
import{RESIZING as i}from"../constants.min.mjs";import{resolveOrigin as r}from"../util/misc/resolveOrigin.min.mjs";import{getLocalPoint as t,isTransformCentered as o}from"./util.min.mjs";import{wrapWithFireEvent as m}from"./wrapWithFireEvent.min.mjs";import{wrapWithFixedAnchor as n}from"./wrapWithFixedAnchor.min.mjs";const s=(i,m,n,s)=>(e,a,h,c)=>{const p=t(a,a.originX,a.originY,h,c)[n],f=r(a[m]);if(0===f||f>0&&p<0||f<0&&p>0){const{target:r}=a,t=r.strokeWidth/(r.strokeUniform?r[s]:1),m=o(a)?2:1,n=r[i],e=Math.abs(p*m/r[s])-t;return r.set(i,Math.max(e,1)),n!==r[i]}return!1},e=s("width","originX","x","scaleX"),a=s("height","originY","y","scaleY"),h=m(i,n(e)),c=m(i,n(a));export{c as changeHeight,s as changeObjectDimensionGen,a as changeObjectHeight,e as changeObjectWidth,h as changeWidth};
|
|
2
2
|
//# sourceMappingURL=changeWidth.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"changeWidth.min.mjs","sources":["../../../src/controls/changeWidth.ts"],"sourcesContent":["import type { TransformActionHandler } from '../EventTypeDefs';\nimport {
|
|
1
|
+
{"version":3,"file":"changeWidth.min.mjs","sources":["../../../src/controls/changeWidth.ts"],"sourcesContent":["import type { TransformActionHandler } from '../EventTypeDefs';\nimport { RESIZING } from '../constants';\nimport { resolveOrigin } from '../util/misc/resolveOrigin';\nimport { getLocalPoint, isTransformCentered } from './util';\nimport { wrapWithFireEvent } from './wrapWithFireEvent';\nimport { wrapWithFixedAnchor } from './wrapWithFixedAnchor';\n\nexport const changeObjectDimensionGen =\n (\n dimension: 'width' | 'height',\n origin: 'originX' | 'originY',\n xorY: 'x' | 'y',\n scale: 'scaleX' | 'scaleY',\n ): TransformActionHandler =>\n (eventData, transform, x, y) => {\n const localPoint = getLocalPoint(\n transform,\n transform.originX,\n transform.originY,\n x,\n y,\n );\n const localPointValue = localPoint[xorY];\n // make sure the control changes width ONLY from it's side of target\n const originValue = resolveOrigin(transform[origin]);\n if (\n originValue === 0 ||\n (originValue > 0 && localPointValue < 0) ||\n (originValue < 0 && localPointValue > 0)\n ) {\n const { target } = transform,\n strokePadding =\n target.strokeWidth / (target.strokeUniform ? target[scale] : 1),\n multiplier = isTransformCentered(transform) ? 2 : 1,\n oldWidth = target[dimension],\n newWidth =\n Math.abs((localPointValue * multiplier) / target[scale]) -\n strokePadding;\n target.set(dimension, Math.max(newWidth, 1));\n // check against actual target width in case `newWidth` was rejected\n return oldWidth !== target[dimension];\n }\n return false;\n };\n\n/**\n * Action handler to change object's width\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\n * You want to use this only if you are building a new control handler and you want\n * to reuse some logic. use \"changeWidth\" if you are looking to just use a control for width\n * @param {Event} eventData javascript event that is doing the transform\n * @param {Object} transform javascript object containing a series of information around the current transform\n * @param {number} x current mouse x position, canvas normalized\n * @param {number} y current mouse y position, canvas normalized\n * @return {Boolean} true if some change happened\n */\nexport const changeObjectWidth: TransformActionHandler =\n changeObjectDimensionGen('width', 'originX', 'x', 'scaleX');\n\n/**\n * Action handler to change object's height\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\n * You want to use this only if you are building a new control handler and you want\n * to reuse some logic. use \"changeHeight\" if you are looking to just use a control for height\n * @param {Event} eventData javascript event that is doing the transform\n * @param {Object} transform javascript object containing a series of information around the current transform\n * @param {number} x current mouse x position, canvas normalized\n * @param {number} y current mouse y position, canvas normalized\n * @return {Boolean} true if some change happened\n */\nexport const changeObjectHeight: TransformActionHandler =\n changeObjectDimensionGen('height', 'originY', 'y', 'scaleY');\n\n/**\n * Control handler for changing width\n */\nexport const changeWidth = wrapWithFireEvent(\n RESIZING,\n wrapWithFixedAnchor(changeObjectWidth),\n);\n\n/**\n * Control handler for changing height\n */\nexport const changeHeight = wrapWithFireEvent(\n RESIZING,\n wrapWithFixedAnchor(changeObjectHeight),\n);\n"],"names":["changeObjectDimensionGen","dimension","origin","xorY","scale","eventData","transform","x","y","localPointValue","getLocalPoint","originX","originY","originValue","resolveOrigin","target","strokePadding","strokeWidth","strokeUniform","multiplier","isTransformCentered","oldWidth","newWidth","Math","abs","set","max","changeObjectWidth","changeObjectHeight","changeWidth","wrapWithFireEvent","RESIZING","wrapWithFixedAnchor","changeHeight"],"mappings":"+TAOO,MAAMA,EACXA,CACEC,EACAC,EACAC,EACAC,IAEF,CAACC,EAAWC,EAAWC,EAAGC,KACxB,MAOMC,EAPaC,EACjBJ,EACAA,EAAUK,QACVL,EAAUM,QACVL,EACAC,GAEiCL,GAE7BU,EAAcC,EAAcR,EAAUJ,IAC5C,GACkB,IAAhBW,GACCA,EAAc,GAAKJ,EAAkB,GACrCI,EAAc,GAAKJ,EAAkB,EACtC,CACA,MAAMM,OAAEA,GAAWT,EACjBU,EACED,EAAOE,aAAeF,EAAOG,cAAgBH,EAAOX,GAAS,GAC/De,EAAaC,EAAoBd,GAAa,EAAI,EAClDe,EAAWN,EAAOd,GAClBqB,EACEC,KAAKC,IAAKf,EAAkBU,EAAcJ,EAAOX,IACjDY,EAGJ,OAFAD,EAAOU,IAAIxB,EAAWsB,KAAKG,IAAIJ,EAAU,IAElCD,IAAaN,EAAOd,EAC7B,CACA,OAAO,GAcE0B,EACX3B,EAAyB,QAAS,UAAW,IAAK,UAavC4B,EACX5B,EAAyB,SAAU,UAAW,IAAK,UAKxC6B,EAAcC,EACzBC,EACAC,EAAoBL,IAMTM,EAAeH,EAC1BC,EACAC,EAAoBJ"}
|
|
@@ -1,36 +1,64 @@
|
|
|
1
|
-
import { RESIZING
|
|
1
|
+
import { RESIZING } from '../constants.mjs';
|
|
2
2
|
import { resolveOrigin } from '../util/misc/resolveOrigin.mjs';
|
|
3
3
|
import { getLocalPoint, isTransformCentered } from './util.mjs';
|
|
4
4
|
import { wrapWithFireEvent } from './wrapWithFireEvent.mjs';
|
|
5
5
|
import { wrapWithFixedAnchor } from './wrapWithFixedAnchor.mjs';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
* Action handler to change object's width
|
|
9
|
-
* Needs to be wrapped with `wrapWithFixedAnchor` to be effective
|
|
10
|
-
* @param {Event} eventData javascript event that is doing the transform
|
|
11
|
-
* @param {Object} transform javascript object containing a series of information around the current transform
|
|
12
|
-
* @param {number} x current mouse x position, canvas normalized
|
|
13
|
-
* @param {number} y current mouse y position, canvas normalized
|
|
14
|
-
* @return {Boolean} true if some change happened
|
|
15
|
-
*/
|
|
16
|
-
const changeObjectWidth = (eventData, transform, x, y) => {
|
|
7
|
+
const changeObjectDimensionGen = (dimension, origin, xorY, scale) => (eventData, transform, x, y) => {
|
|
17
8
|
const localPoint = getLocalPoint(transform, transform.originX, transform.originY, x, y);
|
|
9
|
+
const localPointValue = localPoint[xorY];
|
|
18
10
|
// make sure the control changes width ONLY from it's side of target
|
|
19
|
-
|
|
11
|
+
const originValue = resolveOrigin(transform[origin]);
|
|
12
|
+
if (originValue === 0 || originValue > 0 && localPointValue < 0 || originValue < 0 && localPointValue > 0) {
|
|
20
13
|
const {
|
|
21
14
|
target
|
|
22
15
|
} = transform,
|
|
23
|
-
strokePadding = target.strokeWidth / (target.strokeUniform ? target
|
|
16
|
+
strokePadding = target.strokeWidth / (target.strokeUniform ? target[scale] : 1),
|
|
24
17
|
multiplier = isTransformCentered(transform) ? 2 : 1,
|
|
25
|
-
oldWidth = target
|
|
26
|
-
newWidth = Math.abs(
|
|
27
|
-
target.set(
|
|
18
|
+
oldWidth = target[dimension],
|
|
19
|
+
newWidth = Math.abs(localPointValue * multiplier / target[scale]) - strokePadding;
|
|
20
|
+
target.set(dimension, Math.max(newWidth, 1));
|
|
28
21
|
// check against actual target width in case `newWidth` was rejected
|
|
29
|
-
return oldWidth !== target
|
|
22
|
+
return oldWidth !== target[dimension];
|
|
30
23
|
}
|
|
31
24
|
return false;
|
|
32
25
|
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Action handler to change object's width
|
|
29
|
+
* Needs to be wrapped with `wrapWithFixedAnchor` to be effective
|
|
30
|
+
* You want to use this only if you are building a new control handler and you want
|
|
31
|
+
* to reuse some logic. use "changeWidth" if you are looking to just use a control for width
|
|
32
|
+
* @param {Event} eventData javascript event that is doing the transform
|
|
33
|
+
* @param {Object} transform javascript object containing a series of information around the current transform
|
|
34
|
+
* @param {number} x current mouse x position, canvas normalized
|
|
35
|
+
* @param {number} y current mouse y position, canvas normalized
|
|
36
|
+
* @return {Boolean} true if some change happened
|
|
37
|
+
*/
|
|
38
|
+
const changeObjectWidth = changeObjectDimensionGen('width', 'originX', 'x', 'scaleX');
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Action handler to change object's height
|
|
42
|
+
* Needs to be wrapped with `wrapWithFixedAnchor` to be effective
|
|
43
|
+
* You want to use this only if you are building a new control handler and you want
|
|
44
|
+
* to reuse some logic. use "changeHeight" if you are looking to just use a control for height
|
|
45
|
+
* @param {Event} eventData javascript event that is doing the transform
|
|
46
|
+
* @param {Object} transform javascript object containing a series of information around the current transform
|
|
47
|
+
* @param {number} x current mouse x position, canvas normalized
|
|
48
|
+
* @param {number} y current mouse y position, canvas normalized
|
|
49
|
+
* @return {Boolean} true if some change happened
|
|
50
|
+
*/
|
|
51
|
+
const changeObjectHeight = changeObjectDimensionGen('height', 'originY', 'y', 'scaleY');
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Control handler for changing width
|
|
55
|
+
*/
|
|
33
56
|
const changeWidth = wrapWithFireEvent(RESIZING, wrapWithFixedAnchor(changeObjectWidth));
|
|
34
57
|
|
|
35
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Control handler for changing height
|
|
60
|
+
*/
|
|
61
|
+
const changeHeight = wrapWithFireEvent(RESIZING, wrapWithFixedAnchor(changeObjectHeight));
|
|
62
|
+
|
|
63
|
+
export { changeHeight, changeObjectDimensionGen, changeObjectHeight, changeObjectWidth, changeWidth };
|
|
36
64
|
//# sourceMappingURL=changeWidth.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"changeWidth.mjs","sources":["../../../src/controls/changeWidth.ts"],"sourcesContent":["import type { TransformActionHandler } from '../EventTypeDefs';\nimport {
|
|
1
|
+
{"version":3,"file":"changeWidth.mjs","sources":["../../../src/controls/changeWidth.ts"],"sourcesContent":["import type { TransformActionHandler } from '../EventTypeDefs';\nimport { RESIZING } from '../constants';\nimport { resolveOrigin } from '../util/misc/resolveOrigin';\nimport { getLocalPoint, isTransformCentered } from './util';\nimport { wrapWithFireEvent } from './wrapWithFireEvent';\nimport { wrapWithFixedAnchor } from './wrapWithFixedAnchor';\n\nexport const changeObjectDimensionGen =\n (\n dimension: 'width' | 'height',\n origin: 'originX' | 'originY',\n xorY: 'x' | 'y',\n scale: 'scaleX' | 'scaleY',\n ): TransformActionHandler =>\n (eventData, transform, x, y) => {\n const localPoint = getLocalPoint(\n transform,\n transform.originX,\n transform.originY,\n x,\n y,\n );\n const localPointValue = localPoint[xorY];\n // make sure the control changes width ONLY from it's side of target\n const originValue = resolveOrigin(transform[origin]);\n if (\n originValue === 0 ||\n (originValue > 0 && localPointValue < 0) ||\n (originValue < 0 && localPointValue > 0)\n ) {\n const { target } = transform,\n strokePadding =\n target.strokeWidth / (target.strokeUniform ? target[scale] : 1),\n multiplier = isTransformCentered(transform) ? 2 : 1,\n oldWidth = target[dimension],\n newWidth =\n Math.abs((localPointValue * multiplier) / target[scale]) -\n strokePadding;\n target.set(dimension, Math.max(newWidth, 1));\n // check against actual target width in case `newWidth` was rejected\n return oldWidth !== target[dimension];\n }\n return false;\n };\n\n/**\n * Action handler to change object's width\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\n * You want to use this only if you are building a new control handler and you want\n * to reuse some logic. use \"changeWidth\" if you are looking to just use a control for width\n * @param {Event} eventData javascript event that is doing the transform\n * @param {Object} transform javascript object containing a series of information around the current transform\n * @param {number} x current mouse x position, canvas normalized\n * @param {number} y current mouse y position, canvas normalized\n * @return {Boolean} true if some change happened\n */\nexport const changeObjectWidth: TransformActionHandler =\n changeObjectDimensionGen('width', 'originX', 'x', 'scaleX');\n\n/**\n * Action handler to change object's height\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\n * You want to use this only if you are building a new control handler and you want\n * to reuse some logic. use \"changeHeight\" if you are looking to just use a control for height\n * @param {Event} eventData javascript event that is doing the transform\n * @param {Object} transform javascript object containing a series of information around the current transform\n * @param {number} x current mouse x position, canvas normalized\n * @param {number} y current mouse y position, canvas normalized\n * @return {Boolean} true if some change happened\n */\nexport const changeObjectHeight: TransformActionHandler =\n changeObjectDimensionGen('height', 'originY', 'y', 'scaleY');\n\n/**\n * Control handler for changing width\n */\nexport const changeWidth = wrapWithFireEvent(\n RESIZING,\n wrapWithFixedAnchor(changeObjectWidth),\n);\n\n/**\n * Control handler for changing height\n */\nexport const changeHeight = wrapWithFireEvent(\n RESIZING,\n wrapWithFixedAnchor(changeObjectHeight),\n);\n"],"names":["changeObjectDimensionGen","dimension","origin","xorY","scale","eventData","transform","x","y","localPoint","getLocalPoint","originX","originY","localPointValue","originValue","resolveOrigin","target","strokePadding","strokeWidth","strokeUniform","multiplier","isTransformCentered","oldWidth","newWidth","Math","abs","set","max","changeObjectWidth","changeObjectHeight","changeWidth","wrapWithFireEvent","RESIZING","wrapWithFixedAnchor","changeHeight"],"mappings":";;;;;;AAOO,MAAMA,wBAAwB,GACnCA,CACEC,SAA6B,EAC7BC,MAA6B,EAC7BC,IAAe,EACfC,KAA0B,KAE5B,CAACC,SAAS,EAAEC,SAAS,EAAEC,CAAC,EAAEC,CAA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AACA;AACA;AACA;AACA;AACA;AACO,MAAM6B,kBAA0C,GACrD7B,wBAAwB,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ;;AAE7D;AACA;AACA;AACO,MAAM8B,WAAW,GAAGC,iBAAiB,CAC1CC,QAAQ,EACRC,mBAAmB,CAACL,iBAAiB,CACvC;;AAEA;AACA;AACA;AACO,MAAMM,YAAY,GAAGH,iBAAiB,CAC3CC,QAAQ,EACRC,mBAAmB,CAACJ,kBAAkB,CACxC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controlRendering.d.ts","sourceRoot":"","sources":["../../../src/controls/controlRendering.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"controlRendering.d.ts","sourceRoot":"","sources":["../../../src/controls/controlRendering.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,MAAM,6BAA6B,GAAG,OAAO,CACjD,IAAI,CACF,uBAAuB,EACrB,aAAa,GACb,YAAY,GACZ,aAAa,GACb,mBAAmB,GACnB,iBAAiB,GACjB,oBAAoB,CACvB,CACF,CAAC;AAEF,MAAM,MAAM,eAAe,CACzB,CAAC,SAAS,uBAAuB,GAAG,uBAAuB,IACzD,CACF,GAAG,EAAE,wBAAwB,EAC7B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,6BAA6B,EAC5C,YAAY,EAAE,CAAC,KACZ,IAAI,CAAC;AAEV;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,wBAAwB,EAC7B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,6BAA6B,EAC5C,YAAY,EAAE,uBAAuB,QAyBtC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,wBAAwB,EAC7B,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,6BAA6B,EAC5C,YAAY,EAAE,uBAAuB,QAoBtC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{twoMathPi as e}from"../constants.min.mjs";function o(o,t,s,r,n){o.save();const{stroke:c,xSize:i,ySize:m,opName:a}=this.commonRenderProps(o,t,s,n,r);let p=i;i>m?o.scale(1,m/i):m>i&&(p=m,o.scale(i/m,1)),o.beginPath(),o.arc(0,0,p/2,0,e,!1),o[a](),c&&o.stroke(),o.restore()}function t(e,o,t,s,r){e.save();const{stroke:n,xSize:c,ySize:i,opName:m}=this.commonRenderProps(e,o,t,r,s),a=c/2,p=i/2;e[`${m}Rect`](-a,-p,c,i),n&&e.strokeRect(-a,-p,c,i),e.restore()}export{o as renderCircleControl,t as renderSquareControl};
|
|
2
2
|
//# sourceMappingURL=controlRendering.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controlRendering.min.mjs","sources":["../../../src/controls/controlRendering.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"controlRendering.min.mjs","sources":["../../../src/controls/controlRendering.ts"],"sourcesContent":["import { twoMathPi } from '../constants';\nimport type { InteractiveFabricObject } from '../shapes/Object/InteractiveObject';\nimport type { Control } from './Control';\n\nexport type ControlRenderingStyleOverride = Partial<\n Pick<\n InteractiveFabricObject,\n | 'cornerStyle'\n | 'cornerSize'\n | 'cornerColor'\n | 'cornerStrokeColor'\n | 'cornerDashArray'\n | 'transparentCorners'\n >\n>;\n\nexport type ControlRenderer<\n O extends InteractiveFabricObject = InteractiveFabricObject,\n> = (\n ctx: CanvasRenderingContext2D,\n left: number,\n top: number,\n styleOverride: ControlRenderingStyleOverride,\n fabricObject: O,\n) => void;\n\n/**\n * Render a round control, as per fabric features.\n * This function is written to respect object properties like transparentCorners, cornerSize\n * cornerColor, cornerStrokeColor\n * plus the addition of offsetY and offsetX.\n * @param {CanvasRenderingContext2D} ctx context to render on\n * @param {Number} left x coordinate where the control center should be\n * @param {Number} top y coordinate where the control center should be\n * @param {Object} styleOverride override for FabricObject controls style\n * @param {FabricObject} fabricObject the fabric object for which we are rendering controls\n */\nexport function renderCircleControl(\n this: Control,\n ctx: CanvasRenderingContext2D,\n left: number,\n top: number,\n styleOverride: ControlRenderingStyleOverride,\n fabricObject: InteractiveFabricObject,\n) {\n ctx.save();\n const { stroke, xSize, ySize, opName } = this.commonRenderProps(\n ctx,\n left,\n top,\n fabricObject,\n styleOverride,\n );\n let size = xSize;\n // TODO: use proper ellipse code.\n if (xSize > ySize) {\n ctx.scale(1.0, ySize / xSize);\n } else if (ySize > xSize) {\n size = ySize;\n ctx.scale(xSize / ySize, 1.0);\n }\n ctx.beginPath();\n ctx.arc(0, 0, size / 2, 0, twoMathPi, false);\n ctx[opName]();\n if (stroke) {\n ctx.stroke();\n }\n ctx.restore();\n}\n\n/**\n * Render a square control, as per fabric features.\n * This function is written to respect object properties like transparentCorners, cornerSize\n * cornerColor, cornerStrokeColor\n * plus the addition of offsetY and offsetX.\n * @param {CanvasRenderingContext2D} ctx context to render on\n * @param {Number} left x coordinate where the control center should be\n * @param {Number} top y coordinate where the control center should be\n * @param {Object} styleOverride override for FabricObject controls style\n * @param {FabricObject} fabricObject the fabric object for which we are rendering controls\n */\nexport function renderSquareControl(\n this: Control,\n ctx: CanvasRenderingContext2D,\n left: number,\n top: number,\n styleOverride: ControlRenderingStyleOverride,\n fabricObject: InteractiveFabricObject,\n) {\n ctx.save();\n const { stroke, xSize, ySize, opName } = this.commonRenderProps(\n ctx,\n left,\n top,\n fabricObject,\n styleOverride,\n ),\n xSizeBy2 = xSize / 2,\n ySizeBy2 = ySize / 2;\n // this does not work, and fixed with ( && ) does not make sense.\n // to have real transparent corners we need the controls on upperCanvas\n // transparentCorners || ctx.clearRect(-xSizeBy2, -ySizeBy2, xSize, ySize);\n ctx[`${opName}Rect`](-xSizeBy2, -ySizeBy2, xSize, ySize);\n if (stroke) {\n ctx.strokeRect(-xSizeBy2, -ySizeBy2, xSize, ySize);\n }\n ctx.restore();\n}\n"],"names":["renderCircleControl","ctx","left","top","styleOverride","fabricObject","save","stroke","xSize","ySize","opName","this","commonRenderProps","size","scale","beginPath","arc","twoMathPi","restore","renderSquareControl","xSizeBy2","ySizeBy2","strokeRect"],"mappings":"iDAqCO,SAASA,EAEdC,EACAC,EACAC,EACAC,EACAC,GAEAJ,EAAIK,OACJ,MAAMC,OAAEA,EAAMC,MAAEA,EAAKC,MAAEA,EAAKC,OAAEA,GAAWC,KAAKC,kBAC5CX,EACAC,EACAC,EACAE,EACAD,GAEF,IAAIS,EAAOL,EAEPA,EAAQC,EACVR,EAAIa,MAAM,EAAKL,EAAQD,GACdC,EAAQD,IACjBK,EAAOJ,EACPR,EAAIa,MAAMN,EAAQC,EAAO,IAE3BR,EAAIc,YACJd,EAAIe,IAAI,EAAG,EAAGH,EAAO,EAAG,EAAGI,GAAW,GACtChB,EAAIS,KACAH,GACFN,EAAIM,SAENN,EAAIiB,SACN,CAaO,SAASC,EAEdlB,EACAC,EACAC,EACAC,EACAC,GAEAJ,EAAIK,OACJ,MAAMC,OAAEA,EAAMC,MAAEA,EAAKC,MAAEA,EAAKC,OAAEA,GAAWC,KAAKC,kBAC1CX,EACAC,EACAC,EACAE,EACAD,GAEFgB,EAAWZ,EAAQ,EACnBa,EAAWZ,EAAQ,EAIrBR,EAAI,GAAGS,UAAeU,GAAWC,EAAUb,EAAOC,GAC9CF,GACFN,EAAIqB,YAAYF,GAAWC,EAAUb,EAAOC,GAE9CR,EAAIiB,SACN"}
|