fabric 6.0.0 → 6.0.2
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/CHANGELOG.md +12 -0
- package/README.md +8 -18
- package/dist/fabric.d.ts +4 -0
- package/dist/fabric.d.ts.map +1 -1
- package/dist/fabric.min.mjs +1 -1
- package/dist/fabric.mjs +1 -0
- package/dist/fabric.mjs.map +1 -1
- package/dist/index.js +146 -107
- 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 +146 -108
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +146 -107
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +146 -108
- 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 +2 -1
- package/dist/src/EventTypeDefs.d.ts.map +1 -1
- package/dist/src/LayoutManager/LayoutManager.d.ts.map +1 -1
- package/dist/src/LayoutManager/LayoutManager.min.mjs +1 -1
- package/dist/src/LayoutManager/LayoutManager.min.mjs.map +1 -1
- package/dist/src/LayoutManager/LayoutManager.mjs +13 -8
- package/dist/src/LayoutManager/LayoutManager.mjs.map +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.min.mjs +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.min.mjs.map +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.mjs +3 -3
- package/dist/src/LayoutManager/LayoutStrategies/ClipPathLayout.mjs.map +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.d.ts +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.d.ts.map +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.min.mjs +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.min.mjs.map +1 -1
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.mjs +15 -9
- package/dist/src/LayoutManager/LayoutStrategies/LayoutStrategy.mjs.map +1 -1
- package/dist/src/Observable.d.ts +8 -0
- package/dist/src/Observable.d.ts.map +1 -1
- package/dist/src/Observable.min.mjs.map +1 -1
- package/dist/src/Observable.mjs +8 -0
- package/dist/src/Observable.mjs.map +1 -1
- 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 +5 -5
- package/dist/src/canvas/SelectableCanvas.mjs.map +1 -1
- package/dist/src/canvas/StaticCanvas.d.ts +1 -1
- package/dist/src/constants.d.ts +16 -0
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.min.mjs +1 -1
- package/dist/src/constants.min.mjs.map +1 -1
- package/dist/src/constants.mjs +17 -1
- package/dist/src/constants.mjs.map +1 -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 +2 -1
- package/dist/src/controls/Control.mjs.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 +2 -2
- package/dist/src/controls/changeWidth.mjs.map +1 -1
- package/dist/src/controls/commonControls.d.ts.map +1 -1
- package/dist/src/controls/commonControls.min.mjs +1 -1
- package/dist/src/controls/commonControls.min.mjs.map +1 -1
- package/dist/src/controls/commonControls.mjs +4 -3
- package/dist/src/controls/commonControls.mjs.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 +3 -3
- package/dist/src/controls/controlRendering.mjs.map +1 -1
- package/dist/src/controls/drag.min.mjs +1 -1
- package/dist/src/controls/drag.min.mjs.map +1 -1
- package/dist/src/controls/drag.mjs +2 -2
- package/dist/src/controls/drag.mjs.map +1 -1
- package/dist/src/controls/polyControl.d.ts.map +1 -1
- package/dist/src/controls/polyControl.min.mjs +1 -1
- package/dist/src/controls/polyControl.min.mjs.map +1 -1
- package/dist/src/controls/polyControl.mjs +2 -1
- package/dist/src/controls/polyControl.mjs.map +1 -1
- package/dist/src/controls/rotate.d.ts.map +1 -1
- package/dist/src/controls/rotate.min.mjs +1 -1
- package/dist/src/controls/rotate.min.mjs.map +1 -1
- package/dist/src/controls/rotate.mjs +2 -1
- package/dist/src/controls/rotate.mjs.map +1 -1
- package/dist/src/controls/scale.d.ts.map +1 -1
- package/dist/src/controls/scale.min.mjs +1 -1
- package/dist/src/controls/scale.min.mjs.map +1 -1
- package/dist/src/controls/scale.mjs +8 -7
- package/dist/src/controls/scale.mjs.map +1 -1
- package/dist/src/controls/scaleSkew.d.ts.map +1 -1
- package/dist/src/controls/scaleSkew.min.mjs +1 -1
- package/dist/src/controls/scaleSkew.min.mjs.map +1 -1
- package/dist/src/controls/scaleSkew.mjs +3 -2
- package/dist/src/controls/scaleSkew.mjs.map +1 -1
- package/dist/src/controls/skew.d.ts.map +1 -1
- package/dist/src/controls/skew.min.mjs +1 -1
- package/dist/src/controls/skew.min.mjs.map +1 -1
- package/dist/src/controls/skew.mjs +7 -7
- package/dist/src/controls/skew.mjs.map +1 -1
- package/dist/src/filters/Blur.min.mjs +1 -1
- package/dist/src/filters/Blur.min.mjs.map +1 -1
- package/dist/src/filters/Blur.mjs +1 -1
- package/dist/src/filters/Blur.mjs.map +1 -1
- package/dist/src/filters/Pixelate.min.mjs +1 -1
- package/dist/src/filters/Pixelate.min.mjs.map +1 -1
- package/dist/src/filters/Pixelate.mjs +1 -1
- package/dist/src/filters/Pixelate.mjs.map +1 -1
- package/dist/src/parser/attributes.d.ts.map +1 -1
- package/dist/src/parser/attributes.min.mjs +1 -1
- package/dist/src/parser/attributes.min.mjs.map +1 -1
- package/dist/src/parser/attributes.mjs +3 -1
- package/dist/src/parser/attributes.mjs.map +1 -1
- package/dist/src/parser/elements_parser.min.mjs +1 -1
- package/dist/src/parser/elements_parser.min.mjs.map +1 -1
- package/dist/src/parser/elements_parser.mjs +3 -3
- package/dist/src/parser/elements_parser.mjs.map +1 -1
- package/dist/src/parser/normalizeValue.min.mjs +1 -1
- package/dist/src/parser/normalizeValue.min.mjs.map +1 -1
- package/dist/src/parser/normalizeValue.mjs +7 -7
- package/dist/src/parser/normalizeValue.mjs.map +1 -1
- package/dist/src/parser/parseTransformAttribute.min.mjs +1 -1
- package/dist/src/parser/parseTransformAttribute.min.mjs.map +1 -1
- package/dist/src/parser/parseTransformAttribute.mjs +5 -5
- package/dist/src/parser/parseTransformAttribute.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 +3 -2
- package/dist/src/shapes/Circle.mjs.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 +3 -3
- package/dist/src/shapes/Ellipse.mjs.map +1 -1
- package/dist/src/shapes/IText/DraggableTextDelegate.min.mjs +1 -1
- package/dist/src/shapes/IText/DraggableTextDelegate.min.mjs.map +1 -1
- package/dist/src/shapes/IText/DraggableTextDelegate.mjs +3 -3
- package/dist/src/shapes/IText/DraggableTextDelegate.mjs.map +1 -1
- package/dist/src/shapes/IText/IText.min.mjs +1 -1
- package/dist/src/shapes/IText/IText.min.mjs.map +1 -1
- package/dist/src/shapes/IText/IText.mjs +3 -3
- package/dist/src/shapes/IText/IText.mjs.map +1 -1
- package/dist/src/shapes/IText/ITextBehavior.min.mjs +1 -1
- package/dist/src/shapes/IText/ITextBehavior.min.mjs.map +1 -1
- package/dist/src/shapes/IText/ITextBehavior.mjs +2 -2
- package/dist/src/shapes/IText/ITextBehavior.mjs.map +1 -1
- package/dist/src/shapes/IText/ITextKeyBehavior.min.mjs +1 -1
- package/dist/src/shapes/IText/ITextKeyBehavior.min.mjs.map +1 -1
- package/dist/src/shapes/IText/ITextKeyBehavior.mjs +2 -2
- package/dist/src/shapes/IText/ITextKeyBehavior.mjs.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 +2 -2
- package/dist/src/shapes/Image.mjs.map +1 -1
- package/dist/src/shapes/Object/AnimatableObject.d.ts.map +1 -1
- package/dist/src/shapes/Object/AnimatableObject.min.mjs +1 -1
- package/dist/src/shapes/Object/AnimatableObject.min.mjs.map +1 -1
- package/dist/src/shapes/Object/AnimatableObject.mjs +2 -1
- package/dist/src/shapes/Object/AnimatableObject.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 +4 -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 +1 -1
- package/dist/src/shapes/Object/InteractiveObject.min.mjs.map +1 -1
- package/dist/src/shapes/Object/InteractiveObject.mjs +2 -1
- package/dist/src/shapes/Object/InteractiveObject.mjs.map +1 -1
- package/dist/src/shapes/Object/Object.d.ts +9 -7
- 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 +14 -12
- 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 +3 -3
- package/dist/src/shapes/Object/ObjectGeometry.mjs.map +1 -1
- package/dist/src/shapes/Object/defaultValues.d.ts.map +1 -1
- package/dist/src/shapes/Object/defaultValues.min.mjs +1 -1
- package/dist/src/shapes/Object/defaultValues.min.mjs.map +1 -1
- package/dist/src/shapes/Object/defaultValues.mjs +4 -4
- package/dist/src/shapes/Object/defaultValues.mjs.map +1 -1
- package/dist/src/shapes/Object/types/ControlProps.d.ts +4 -3
- package/dist/src/shapes/Object/types/ControlProps.d.ts.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 +3 -3
- package/dist/src/shapes/Polyline.mjs.map +1 -1
- package/dist/src/shapes/Text/Text.d.ts +2 -2
- package/dist/src/shapes/Text/Text.d.ts.map +1 -1
- package/dist/src/shapes/Text/Text.min.mjs +1 -1
- package/dist/src/shapes/Text/Text.min.mjs.map +1 -1
- package/dist/src/shapes/Text/Text.mjs +5 -5
- 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 +2 -1
- package/dist/src/shapes/Text/TextSVGExportMixin.mjs.map +1 -1
- package/dist/src/shapes/Text/constants.min.mjs +1 -1
- package/dist/src/shapes/Text/constants.min.mjs.map +1 -1
- package/dist/src/shapes/Text/constants.mjs +2 -2
- package/dist/src/shapes/Text/constants.mjs.map +1 -1
- package/dist/src/util/misc/objectEnlive.d.ts +1 -0
- package/dist/src/util/misc/objectEnlive.d.ts.map +1 -1
- package/dist/src/util/misc/objectEnlive.min.mjs.map +1 -1
- package/dist/src/util/misc/objectEnlive.mjs +1 -0
- package/dist/src/util/misc/objectEnlive.mjs.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 -2
- package/dist/src/util/misc/svgParsing.mjs.map +1 -1
- package/dist/src/util/transform_matrix_removal.min.mjs +1 -1
- package/dist/src/util/transform_matrix_removal.min.mjs.map +1 -1
- package/dist/src/util/transform_matrix_removal.mjs +3 -3
- package/dist/src/util/transform_matrix_removal.mjs.map +1 -1
- package/fabric.ts +4 -0
- package/package.json +1 -1
- package/src/EventTypeDefs.ts +14 -6
- package/src/LayoutManager/LayoutManager.ts +28 -19
- package/src/LayoutManager/LayoutStrategies/ClipPathLayout.ts +2 -2
- package/src/LayoutManager/LayoutStrategies/LayoutStrategy.ts +7 -7
- package/src/Observable.ts +8 -0
- package/src/canvas/SelectableCanvas.ts +25 -11
- package/src/canvas/canvas_gestures.mixin.ts +6 -5
- package/src/constants.ts +17 -0
- package/src/controls/Control.ts +2 -1
- package/src/controls/changeWidth.ts +2 -2
- package/src/controls/commonControls.ts +4 -3
- package/src/controls/controlRendering.ts +3 -3
- package/src/controls/drag.ts +2 -2
- package/src/controls/polyControl.ts +2 -1
- package/src/controls/rotate.ts +2 -1
- package/src/controls/scale.ts +8 -7
- package/src/controls/scaleSkew.ts +3 -2
- package/src/controls/skew.ts +14 -7
- package/src/filters/Blur.ts +1 -1
- package/src/filters/Pixelate.ts +1 -1
- package/src/parser/attributes.ts +4 -2
- package/src/parser/elements_parser.ts +3 -3
- package/src/parser/normalizeValue.ts +7 -7
- package/src/parser/parseTransformAttribute.ts +5 -5
- package/src/shapes/Circle.ts +3 -2
- package/src/shapes/Ellipse.ts +3 -3
- package/src/shapes/IText/DraggableTextDelegate.ts +3 -3
- package/src/shapes/IText/IText.ts +3 -3
- package/src/shapes/IText/ITextBehavior.ts +2 -2
- package/src/shapes/IText/ITextKeyBehavior.ts +2 -2
- package/src/shapes/Image.ts +2 -2
- package/src/shapes/Object/AnimatableObject.ts +2 -1
- package/src/shapes/Object/FabricObjectSVGExportMixin.ts +4 -6
- package/src/shapes/Object/InteractiveObject.ts +2 -1
- package/src/shapes/Object/Object.ts +16 -11
- package/src/shapes/Object/ObjectGeometry.ts +3 -3
- package/src/shapes/Object/defaultValues.ts +17 -8
- package/src/shapes/Object/types/ControlProps.ts +4 -3
- package/src/shapes/Polyline.spec.ts +0 -1
- package/src/shapes/Polyline.ts +12 -4
- package/src/shapes/Text/Text.ts +7 -7
- package/src/shapes/Text/TextSVGExportMixin.ts +3 -2
- package/src/shapes/Text/constants.ts +3 -3
- package/src/util/misc/objectEnlive.ts +1 -0
- package/src/util/misc/svgParsing.ts +2 -2
- package/src/util/transform_matrix_removal.ts +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polyControl.min.mjs","sources":["../../../src/controls/polyControl.ts"],"sourcesContent":["import { Point } from '../Point';\nimport { Control } from './Control';\nimport type { TMat2D } from '../typedefs';\nimport type { Polyline } from '../shapes/Polyline';\nimport { multiplyTransformMatrices } from '../util/misc/matrix';\nimport type {\n TModificationEvents,\n TPointerEvent,\n Transform,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport { wrapWithFireEvent } from './wrapWithFireEvent';\nimport { sendPointToPlane } from '../util';\n\nconst ACTION_NAME: TModificationEvents =
|
|
1
|
+
{"version":3,"file":"polyControl.min.mjs","sources":["../../../src/controls/polyControl.ts"],"sourcesContent":["import { Point } from '../Point';\nimport { Control } from './Control';\nimport type { TMat2D } from '../typedefs';\nimport type { Polyline } from '../shapes/Polyline';\nimport { multiplyTransformMatrices } from '../util/misc/matrix';\nimport type {\n TModificationEvents,\n TPointerEvent,\n Transform,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport { wrapWithFireEvent } from './wrapWithFireEvent';\nimport { sendPointToPlane } from '../util';\nimport { MODIFY_POLY } from '../constants';\n\nconst ACTION_NAME: TModificationEvents = MODIFY_POLY;\n\ntype TTransformAnchor = Transform & { pointIndex: number };\n\n/**\n * This function locates the controls.\n * It'll be used both for drawing and for interaction.\n */\nexport const createPolyPositionHandler = (pointIndex: number) => {\n return function (dim: Point, finalMatrix: TMat2D, polyObject: Polyline) {\n const { points, pathOffset } = polyObject;\n return new Point(points[pointIndex])\n .subtract(pathOffset)\n .transform(\n multiplyTransformMatrices(\n polyObject.getViewportTransform(),\n polyObject.calcTransformMatrix()\n )\n );\n };\n};\n\n/**\n * This function defines what the control does.\n * It'll be called on every mouse move after a control has been clicked and is being dragged.\n * The function receives as argument the mouse event, the current transform object\n * and the current position in canvas coordinate `transform.target` is a reference to the\n * current object being transformed.\n */\nexport const polyActionHandler = (\n eventData: TPointerEvent,\n transform: TTransformAnchor,\n x: number,\n y: number\n) => {\n const { target, pointIndex } = transform;\n const poly = target as Polyline;\n const mouseLocalPosition = sendPointToPlane(\n new Point(x, y),\n undefined,\n poly.calcOwnMatrix()\n );\n\n poly.points[pointIndex] = mouseLocalPosition.add(poly.pathOffset);\n poly.setDimensions();\n\n return true;\n};\n\n/**\n * Keep the polygon in the same position when we change its `width`/`height`/`top`/`left`.\n */\nexport const factoryPolyActionHandler = (\n pointIndex: number,\n fn: TransformActionHandler<TTransformAnchor>\n) => {\n return function (\n eventData: TPointerEvent,\n transform: Transform,\n x: number,\n y: number\n ) {\n const poly = transform.target as Polyline,\n anchorPoint = new Point(\n poly.points[(pointIndex > 0 ? pointIndex : poly.points.length) - 1]\n ),\n anchorPointInParentPlane = anchorPoint\n .subtract(poly.pathOffset)\n .transform(poly.calcOwnMatrix()),\n actionPerformed = fn(eventData, { ...transform, pointIndex }, x, y);\n\n const newAnchorPointInParentPlane = anchorPoint\n .subtract(poly.pathOffset)\n .transform(poly.calcOwnMatrix());\n\n const diff = newAnchorPointInParentPlane.subtract(anchorPointInParentPlane);\n poly.left -= diff.x;\n poly.top -= diff.y;\n\n return actionPerformed;\n };\n};\n\nexport const createPolyActionHandler = (pointIndex: number) =>\n wrapWithFireEvent(\n ACTION_NAME,\n factoryPolyActionHandler(pointIndex, polyActionHandler)\n );\n\nexport function createPolyControls(\n poly: Polyline,\n options?: Partial<Control>\n): Record<string, Control>;\nexport function createPolyControls(\n numOfControls: number,\n options?: Partial<Control>\n): Record<string, Control>;\nexport function createPolyControls(\n arg0: number | Polyline,\n options: Partial<Control> = {}\n) {\n const controls = {} as Record<string, Control>;\n for (\n let idx = 0;\n idx < (typeof arg0 === 'number' ? arg0 : arg0.points.length);\n idx++\n ) {\n controls[`p${idx}`] = new Control({\n actionName: ACTION_NAME,\n positionHandler: createPolyPositionHandler(idx),\n actionHandler: createPolyActionHandler(idx),\n ...options,\n });\n }\n return controls;\n}\n"],"names":["ACTION_NAME","MODIFY_POLY","createPolyPositionHandler","pointIndex","dim","finalMatrix","polyObject","points","pathOffset","Point","subtract","transform","multiplyTransformMatrices","getViewportTransform","calcTransformMatrix","polyActionHandler","eventData","x","y","target","poly","mouseLocalPosition","sendPointToPlane","undefined","calcOwnMatrix","add","setDimensions","factoryPolyActionHandler","fn","anchorPoint","length","anchorPointInParentPlane","actionPerformed","_objectSpread","diff","left","top","createPolyActionHandler","wrapWithFireEvent","createPolyControls","arg0","options","arguments","controls","idx","concat","Control","actionName","positionHandler","actionHandler"],"mappings":"6tBAeA,MAAMA,EAAmCC,EAQ5BC,EAA6BC,GACjC,SAAUC,EAAYC,EAAqBC,GAChD,MAAMC,OAAEA,EAAMC,WAAEA,GAAeF,EAC/B,OAAO,IAAIG,EAAMF,EAAOJ,IACrBO,SAASF,GACTG,UACCC,EACEN,EAAWO,uBACXP,EAAWQ,yBAaRC,EAAoBA,CAC/BC,EACAL,EACAM,EACAC,KAEA,MAAMC,OAAEA,EAAMhB,WAAEA,GAAeQ,EACzBS,EAAOD,EACPE,EAAqBC,EACzB,IAAIb,EAAMQ,EAAGC,QACbK,EACAH,EAAKI,iBAMP,OAHAJ,EAAKb,OAAOJ,GAAckB,EAAmBI,IAAIL,EAAKZ,YACtDY,EAAKM,iBAEE,CAAI,EAMAC,EAA2BA,CACtCxB,EACAyB,IAEO,SACLZ,EACAL,EACAM,EACAC,GAEA,MAAME,EAAOT,EAAUQ,OACrBU,EAAc,IAAIpB,EAChBW,EAAKb,QAAQJ,EAAa,EAAIA,EAAaiB,EAAKb,OAAOuB,QAAU,IAEnEC,EAA2BF,EACxBnB,SAASU,EAAKZ,YACdG,UAAUS,EAAKI,iBAClBQ,EAAkBJ,EAAGZ,EAASiB,EAAAA,EAAA,GAAOtB,GAAS,GAAA,CAAER,eAAcc,EAAGC,GAM7DgB,EAJ8BL,EACjCnB,SAASU,EAAKZ,YACdG,UAAUS,EAAKI,iBAEuBd,SAASqB,GAIlD,OAHAX,EAAKe,MAAQD,EAAKjB,EAClBG,EAAKgB,KAAOF,EAAKhB,EAEVc,GAIEK,EAA2BlC,GACtCmC,EACEtC,EACA2B,EAAyBxB,EAAYY,IAWlC,SAASwB,EACdC,GAEA,IADAC,EAAyBC,UAAAZ,OAAA,QAAAP,IAAAmB,UAAA,GAAAA,UAAA,GAAG,CAAA,EAE5B,MAAMC,EAAW,CAAA,EACjB,IACE,IAAIC,EAAM,EACVA,GAAuB,iBAATJ,EAAoBA,EAAOA,EAAKjC,OAAOuB,QACrDc,IAEAD,EAAQ,IAAAE,OAAKD,IAAS,IAAIE,EAAOb,EAAA,CAC/Bc,WAAY/C,EACZgD,gBAAiB9C,EAA0B0C,GAC3CK,cAAeZ,EAAwBO,IACpCH,IAGP,OAAOE,CACT"}
|
|
@@ -3,6 +3,7 @@ import { Point } from '../Point.mjs';
|
|
|
3
3
|
import { Control } from './Control.mjs';
|
|
4
4
|
import { multiplyTransformMatrices } from '../util/misc/matrix.mjs';
|
|
5
5
|
import { wrapWithFireEvent } from './wrapWithFireEvent.mjs';
|
|
6
|
+
import { MODIFY_POLY } from '../constants.mjs';
|
|
6
7
|
import '../util/misc/vectors.mjs';
|
|
7
8
|
import '../util/misc/projectStroke/StrokeLineJoinProjections.mjs';
|
|
8
9
|
import '../config.mjs';
|
|
@@ -13,7 +14,7 @@ import '../util/path/regex.mjs';
|
|
|
13
14
|
import '../parser/constants.mjs';
|
|
14
15
|
import '../util/animation/AnimationRegistry.mjs';
|
|
15
16
|
|
|
16
|
-
const ACTION_NAME =
|
|
17
|
+
const ACTION_NAME = MODIFY_POLY;
|
|
17
18
|
/**
|
|
18
19
|
* This function locates the controls.
|
|
19
20
|
* It'll be used both for drawing and for interaction.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polyControl.mjs","sources":["../../../src/controls/polyControl.ts"],"sourcesContent":["import { Point } from '../Point';\nimport { Control } from './Control';\nimport type { TMat2D } from '../typedefs';\nimport type { Polyline } from '../shapes/Polyline';\nimport { multiplyTransformMatrices } from '../util/misc/matrix';\nimport type {\n TModificationEvents,\n TPointerEvent,\n Transform,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport { wrapWithFireEvent } from './wrapWithFireEvent';\nimport { sendPointToPlane } from '../util';\n\nconst ACTION_NAME: TModificationEvents =
|
|
1
|
+
{"version":3,"file":"polyControl.mjs","sources":["../../../src/controls/polyControl.ts"],"sourcesContent":["import { Point } from '../Point';\nimport { Control } from './Control';\nimport type { TMat2D } from '../typedefs';\nimport type { Polyline } from '../shapes/Polyline';\nimport { multiplyTransformMatrices } from '../util/misc/matrix';\nimport type {\n TModificationEvents,\n TPointerEvent,\n Transform,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport { wrapWithFireEvent } from './wrapWithFireEvent';\nimport { sendPointToPlane } from '../util';\nimport { MODIFY_POLY } from '../constants';\n\nconst ACTION_NAME: TModificationEvents = MODIFY_POLY;\n\ntype TTransformAnchor = Transform & { pointIndex: number };\n\n/**\n * This function locates the controls.\n * It'll be used both for drawing and for interaction.\n */\nexport const createPolyPositionHandler = (pointIndex: number) => {\n return function (dim: Point, finalMatrix: TMat2D, polyObject: Polyline) {\n const { points, pathOffset } = polyObject;\n return new Point(points[pointIndex])\n .subtract(pathOffset)\n .transform(\n multiplyTransformMatrices(\n polyObject.getViewportTransform(),\n polyObject.calcTransformMatrix()\n )\n );\n };\n};\n\n/**\n * This function defines what the control does.\n * It'll be called on every mouse move after a control has been clicked and is being dragged.\n * The function receives as argument the mouse event, the current transform object\n * and the current position in canvas coordinate `transform.target` is a reference to the\n * current object being transformed.\n */\nexport const polyActionHandler = (\n eventData: TPointerEvent,\n transform: TTransformAnchor,\n x: number,\n y: number\n) => {\n const { target, pointIndex } = transform;\n const poly = target as Polyline;\n const mouseLocalPosition = sendPointToPlane(\n new Point(x, y),\n undefined,\n poly.calcOwnMatrix()\n );\n\n poly.points[pointIndex] = mouseLocalPosition.add(poly.pathOffset);\n poly.setDimensions();\n\n return true;\n};\n\n/**\n * Keep the polygon in the same position when we change its `width`/`height`/`top`/`left`.\n */\nexport const factoryPolyActionHandler = (\n pointIndex: number,\n fn: TransformActionHandler<TTransformAnchor>\n) => {\n return function (\n eventData: TPointerEvent,\n transform: Transform,\n x: number,\n y: number\n ) {\n const poly = transform.target as Polyline,\n anchorPoint = new Point(\n poly.points[(pointIndex > 0 ? pointIndex : poly.points.length) - 1]\n ),\n anchorPointInParentPlane = anchorPoint\n .subtract(poly.pathOffset)\n .transform(poly.calcOwnMatrix()),\n actionPerformed = fn(eventData, { ...transform, pointIndex }, x, y);\n\n const newAnchorPointInParentPlane = anchorPoint\n .subtract(poly.pathOffset)\n .transform(poly.calcOwnMatrix());\n\n const diff = newAnchorPointInParentPlane.subtract(anchorPointInParentPlane);\n poly.left -= diff.x;\n poly.top -= diff.y;\n\n return actionPerformed;\n };\n};\n\nexport const createPolyActionHandler = (pointIndex: number) =>\n wrapWithFireEvent(\n ACTION_NAME,\n factoryPolyActionHandler(pointIndex, polyActionHandler)\n );\n\nexport function createPolyControls(\n poly: Polyline,\n options?: Partial<Control>\n): Record<string, Control>;\nexport function createPolyControls(\n numOfControls: number,\n options?: Partial<Control>\n): Record<string, Control>;\nexport function createPolyControls(\n arg0: number | Polyline,\n options: Partial<Control> = {}\n) {\n const controls = {} as Record<string, Control>;\n for (\n let idx = 0;\n idx < (typeof arg0 === 'number' ? arg0 : arg0.points.length);\n idx++\n ) {\n controls[`p${idx}`] = new Control({\n actionName: ACTION_NAME,\n positionHandler: createPolyPositionHandler(idx),\n actionHandler: createPolyActionHandler(idx),\n ...options,\n });\n }\n return controls;\n}\n"],"names":["ACTION_NAME","MODIFY_POLY","createPolyPositionHandler","pointIndex","dim","finalMatrix","polyObject","points","pathOffset","Point","subtract","transform","multiplyTransformMatrices","getViewportTransform","calcTransformMatrix","polyActionHandler","eventData","x","y","target","poly","mouseLocalPosition","sendPointToPlane","undefined","calcOwnMatrix","add","setDimensions","factoryPolyActionHandler","fn","anchorPoint","length","anchorPointInParentPlane","actionPerformed","_objectSpread","newAnchorPointInParentPlane","diff","left","top","createPolyActionHandler","wrapWithFireEvent","createPolyControls","arg0","options","arguments","controls","idx","concat","Control","actionName","positionHandler","actionHandler"],"mappings":";;;;;;;;;;;;;;;;AAeA,MAAMA,WAAgC,GAAGC,WAAW,CAAA;AAIpD;AACA;AACA;AACA;AACaC,MAAAA,yBAAyB,GAAIC,UAAkB,IAAK;AAC/D,EAAA,OAAO,UAAUC,GAAU,EAAEC,WAAmB,EAAEC,UAAoB,EAAE;IACtE,MAAM;MAAEC,MAAM;AAAEC,MAAAA,UAAAA;AAAW,KAAC,GAAGF,UAAU,CAAA;AACzC,IAAA,OAAO,IAAIG,KAAK,CAACF,MAAM,CAACJ,UAAU,CAAC,CAAC,CACjCO,QAAQ,CAACF,UAAU,CAAC,CACpBG,SAAS,CACRC,yBAAyB,CACvBN,UAAU,CAACO,oBAAoB,EAAE,EACjCP,UAAU,CAACQ,mBAAmB,EAChC,CACF,CAAC,CAAA;GACJ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uB,CAACO,GAAG,CAAA;KACvCH,EAAAA,OAAO,CACX,CAAC,CAAA;AACJ,GAAA;AACA,EAAA,OAAOE,QAAQ,CAAA;AACjB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rotate.d.ts","sourceRoot":"","sources":["../../../src/controls/rotate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"rotate.d.ts","sourceRoot":"","sources":["../../../src/controls/rotate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;AAO1B;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,EAAE,qBASlC,CAAC;AAyDF,eAAO,MAAM,oBAAoB,8DAGhC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ROTATING as t}from"../constants.min.mjs";import{radiansToDegrees as n}from"../util/misc/radiansDegreesConversion.min.mjs";import{NOT_ALLOWED_CURSOR as o,isLocked as i}from"./util.min.mjs";import{wrapWithFireEvent as r}from"./wrapWithFireEvent.min.mjs";import{wrapWithFixedAnchor as a}from"./wrapWithFixedAnchor.min.mjs";const e=(t,n,i)=>i.lockRotation?o:n.cursorStyle,s=r(t,a(((t,o,r,a)=>{let{target:e,ex:s,ey:m,theta:l,originX:c,originY:h}=o;const p=e.translateToOriginPoint(e.getRelativeCenterPoint(),c,h);if(i(e,"lockRotation"))return!1;const g=Math.atan2(m-p.y,s-p.x),f=Math.atan2(a-p.y,r-p.x);let M=n(f-g+l);if(e.snapAngle&&e.snapAngle>0){const t=e.snapAngle,n=e.snapThreshold||t,o=Math.ceil(M/t)*t,i=Math.floor(M/t)*t;Math.abs(M-i)<n?M=i:Math.abs(M-o)<n&&(M=o)}M<0&&(M=360+M),M%=360;const j=e.angle!==M;return e.angle=M,j})));export{e as rotationStyleHandler,s as rotationWithSnapping};
|
|
2
2
|
//# sourceMappingURL=rotate.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rotate.min.mjs","sources":["../../../src/controls/rotate.ts"],"sourcesContent":["import type {\n ControlCursorCallback,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport { radiansToDegrees } from '../util/misc/radiansDegreesConversion';\nimport { isLocked, NOT_ALLOWED_CURSOR } from './util';\nimport { wrapWithFireEvent } from './wrapWithFireEvent';\nimport { wrapWithFixedAnchor } from './wrapWithFixedAnchor';\n\n/**\n * Find the correct style for the control that is used for rotation.\n * this function is very simple and it just take care of not-allowed or standard cursor\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} a valid css string for the cursor\n */\nexport const rotationStyleHandler: ControlCursorCallback = (\n eventData,\n control,\n fabricObject\n) => {\n if (fabricObject.lockRotation) {\n return NOT_ALLOWED_CURSOR;\n }\n return control.cursorStyle;\n};\n\n/**\n * Action handler for rotation and snapping, without anchor point.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 * @private\n */\nconst rotateObjectWithSnapping: TransformActionHandler = (\n eventData,\n { target, ex, ey, theta, originX, originY },\n x,\n y\n) => {\n const pivotPoint = target.translateToOriginPoint(\n target.getRelativeCenterPoint(),\n originX,\n originY\n );\n\n if (isLocked(target, 'lockRotation')) {\n return false;\n }\n\n const lastAngle = Math.atan2(ey - pivotPoint.y, ex - pivotPoint.x),\n curAngle = Math.atan2(y - pivotPoint.y, x - pivotPoint.x);\n let angle = radiansToDegrees(curAngle - lastAngle + theta);\n\n if (target.snapAngle && target.snapAngle > 0) {\n const snapAngle = target.snapAngle,\n snapThreshold = target.snapThreshold || snapAngle,\n rightAngleLocked = Math.ceil(angle / snapAngle) * snapAngle,\n leftAngleLocked = Math.floor(angle / snapAngle) * snapAngle;\n\n if (Math.abs(angle - leftAngleLocked) < snapThreshold) {\n angle = leftAngleLocked;\n } else if (Math.abs(angle - rightAngleLocked) < snapThreshold) {\n angle = rightAngleLocked;\n }\n }\n\n // normalize angle to positive value\n if (angle < 0) {\n angle = 360 + angle;\n }\n angle %= 360;\n\n const hasRotated = target.angle !== angle;\n // TODO: why aren't we using set?\n target.angle = angle;\n return hasRotated;\n};\n\nexport const rotationWithSnapping = wrapWithFireEvent(\n
|
|
1
|
+
{"version":3,"file":"rotate.min.mjs","sources":["../../../src/controls/rotate.ts"],"sourcesContent":["import type {\n ControlCursorCallback,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport { ROTATING } from '../constants';\nimport { radiansToDegrees } from '../util/misc/radiansDegreesConversion';\nimport { isLocked, NOT_ALLOWED_CURSOR } from './util';\nimport { wrapWithFireEvent } from './wrapWithFireEvent';\nimport { wrapWithFixedAnchor } from './wrapWithFixedAnchor';\n\n/**\n * Find the correct style for the control that is used for rotation.\n * this function is very simple and it just take care of not-allowed or standard cursor\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} a valid css string for the cursor\n */\nexport const rotationStyleHandler: ControlCursorCallback = (\n eventData,\n control,\n fabricObject\n) => {\n if (fabricObject.lockRotation) {\n return NOT_ALLOWED_CURSOR;\n }\n return control.cursorStyle;\n};\n\n/**\n * Action handler for rotation and snapping, without anchor point.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 * @private\n */\nconst rotateObjectWithSnapping: TransformActionHandler = (\n eventData,\n { target, ex, ey, theta, originX, originY },\n x,\n y\n) => {\n const pivotPoint = target.translateToOriginPoint(\n target.getRelativeCenterPoint(),\n originX,\n originY\n );\n\n if (isLocked(target, 'lockRotation')) {\n return false;\n }\n\n const lastAngle = Math.atan2(ey - pivotPoint.y, ex - pivotPoint.x),\n curAngle = Math.atan2(y - pivotPoint.y, x - pivotPoint.x);\n let angle = radiansToDegrees(curAngle - lastAngle + theta);\n\n if (target.snapAngle && target.snapAngle > 0) {\n const snapAngle = target.snapAngle,\n snapThreshold = target.snapThreshold || snapAngle,\n rightAngleLocked = Math.ceil(angle / snapAngle) * snapAngle,\n leftAngleLocked = Math.floor(angle / snapAngle) * snapAngle;\n\n if (Math.abs(angle - leftAngleLocked) < snapThreshold) {\n angle = leftAngleLocked;\n } else if (Math.abs(angle - rightAngleLocked) < snapThreshold) {\n angle = rightAngleLocked;\n }\n }\n\n // normalize angle to positive value\n if (angle < 0) {\n angle = 360 + angle;\n }\n angle %= 360;\n\n const hasRotated = target.angle !== angle;\n // TODO: why aren't we using set?\n target.angle = angle;\n return hasRotated;\n};\n\nexport const rotationWithSnapping = wrapWithFireEvent(\n ROTATING,\n wrapWithFixedAnchor(rotateObjectWithSnapping)\n);\n"],"names":["rotationStyleHandler","eventData","control","fabricObject","lockRotation","NOT_ALLOWED_CURSOR","cursorStyle","rotationWithSnapping","wrapWithFireEvent","ROTATING","wrapWithFixedAnchor","rotateObjectWithSnapping","_ref","x","y","target","ex","ey","theta","originX","originY","pivotPoint","translateToOriginPoint","getRelativeCenterPoint","isLocked","lastAngle","Math","atan2","curAngle","angle","radiansToDegrees","snapAngle","snapThreshold","rightAngleLocked","ceil","leftAngleLocked","floor","abs","hasRotated"],"mappings":"uUAkBO,MAAMA,EAA8CA,CACzDC,EACAC,EACAC,IAEIA,EAAaC,aACRC,EAEFH,EAAQI,YA0DJC,EAAuBC,EAClCC,EACAC,GA/CuDC,CACvDV,EAASW,EAETC,EACAC,KACG,IAHHC,OAAEA,EAAMC,GAAEA,EAAEC,GAAEA,EAAEC,MAAEA,EAAKC,QAAEA,EAAOC,QAAEA,GAASR,EAI3C,MAAMS,EAAaN,EAAOO,uBACxBP,EAAOQ,yBACPJ,EACAC,GAGF,GAAII,EAAST,EAAQ,gBACnB,OAAO,EAGT,MAAMU,EAAYC,KAAKC,MAAMV,EAAKI,EAAWP,EAAGE,EAAKK,EAAWR,GAC9De,EAAWF,KAAKC,MAAMb,EAAIO,EAAWP,EAAGD,EAAIQ,EAAWR,GACzD,IAAIgB,EAAQC,EAAiBF,EAAWH,EAAYP,GAEpD,GAAIH,EAAOgB,WAAahB,EAAOgB,UAAY,EAAG,CAC5C,MAAMA,EAAYhB,EAAOgB,UACvBC,EAAgBjB,EAAOiB,eAAiBD,EACxCE,EAAmBP,KAAKQ,KAAKL,EAAQE,GAAaA,EAClDI,EAAkBT,KAAKU,MAAMP,EAAQE,GAAaA,EAEhDL,KAAKW,IAAIR,EAAQM,GAAmBH,EACtCH,EAAQM,EACCT,KAAKW,IAAIR,EAAQI,GAAoBD,IAC9CH,EAAQI,EAEZ,CAGIJ,EAAQ,IACVA,EAAQ,IAAMA,GAEhBA,GAAS,IAET,MAAMS,EAAavB,EAAOc,QAAUA,EAGpC,OADAd,EAAOc,MAAQA,EACRS,CAAU"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ROTATING } from '../constants.mjs';
|
|
1
2
|
import { radiansToDegrees } from '../util/misc/radiansDegreesConversion.mjs';
|
|
2
3
|
import { NOT_ALLOWED_CURSOR, isLocked } from './util.mjs';
|
|
3
4
|
import { wrapWithFireEvent } from './wrapWithFireEvent.mjs';
|
|
@@ -66,7 +67,7 @@ const rotateObjectWithSnapping = (eventData, _ref, x, y) => {
|
|
|
66
67
|
target.angle = angle;
|
|
67
68
|
return hasRotated;
|
|
68
69
|
};
|
|
69
|
-
const rotationWithSnapping = wrapWithFireEvent(
|
|
70
|
+
const rotationWithSnapping = wrapWithFireEvent(ROTATING, wrapWithFixedAnchor(rotateObjectWithSnapping));
|
|
70
71
|
|
|
71
72
|
export { rotationStyleHandler, rotationWithSnapping };
|
|
72
73
|
//# sourceMappingURL=rotate.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rotate.mjs","sources":["../../../src/controls/rotate.ts"],"sourcesContent":["import type {\n ControlCursorCallback,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport { radiansToDegrees } from '../util/misc/radiansDegreesConversion';\nimport { isLocked, NOT_ALLOWED_CURSOR } from './util';\nimport { wrapWithFireEvent } from './wrapWithFireEvent';\nimport { wrapWithFixedAnchor } from './wrapWithFixedAnchor';\n\n/**\n * Find the correct style for the control that is used for rotation.\n * this function is very simple and it just take care of not-allowed or standard cursor\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} a valid css string for the cursor\n */\nexport const rotationStyleHandler: ControlCursorCallback = (\n eventData,\n control,\n fabricObject\n) => {\n if (fabricObject.lockRotation) {\n return NOT_ALLOWED_CURSOR;\n }\n return control.cursorStyle;\n};\n\n/**\n * Action handler for rotation and snapping, without anchor point.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 * @private\n */\nconst rotateObjectWithSnapping: TransformActionHandler = (\n eventData,\n { target, ex, ey, theta, originX, originY },\n x,\n y\n) => {\n const pivotPoint = target.translateToOriginPoint(\n target.getRelativeCenterPoint(),\n originX,\n originY\n );\n\n if (isLocked(target, 'lockRotation')) {\n return false;\n }\n\n const lastAngle = Math.atan2(ey - pivotPoint.y, ex - pivotPoint.x),\n curAngle = Math.atan2(y - pivotPoint.y, x - pivotPoint.x);\n let angle = radiansToDegrees(curAngle - lastAngle + theta);\n\n if (target.snapAngle && target.snapAngle > 0) {\n const snapAngle = target.snapAngle,\n snapThreshold = target.snapThreshold || snapAngle,\n rightAngleLocked = Math.ceil(angle / snapAngle) * snapAngle,\n leftAngleLocked = Math.floor(angle / snapAngle) * snapAngle;\n\n if (Math.abs(angle - leftAngleLocked) < snapThreshold) {\n angle = leftAngleLocked;\n } else if (Math.abs(angle - rightAngleLocked) < snapThreshold) {\n angle = rightAngleLocked;\n }\n }\n\n // normalize angle to positive value\n if (angle < 0) {\n angle = 360 + angle;\n }\n angle %= 360;\n\n const hasRotated = target.angle !== angle;\n // TODO: why aren't we using set?\n target.angle = angle;\n return hasRotated;\n};\n\nexport const rotationWithSnapping = wrapWithFireEvent(\n
|
|
1
|
+
{"version":3,"file":"rotate.mjs","sources":["../../../src/controls/rotate.ts"],"sourcesContent":["import type {\n ControlCursorCallback,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport { ROTATING } from '../constants';\nimport { radiansToDegrees } from '../util/misc/radiansDegreesConversion';\nimport { isLocked, NOT_ALLOWED_CURSOR } from './util';\nimport { wrapWithFireEvent } from './wrapWithFireEvent';\nimport { wrapWithFixedAnchor } from './wrapWithFixedAnchor';\n\n/**\n * Find the correct style for the control that is used for rotation.\n * this function is very simple and it just take care of not-allowed or standard cursor\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} a valid css string for the cursor\n */\nexport const rotationStyleHandler: ControlCursorCallback = (\n eventData,\n control,\n fabricObject\n) => {\n if (fabricObject.lockRotation) {\n return NOT_ALLOWED_CURSOR;\n }\n return control.cursorStyle;\n};\n\n/**\n * Action handler for rotation and snapping, without anchor point.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 * @private\n */\nconst rotateObjectWithSnapping: TransformActionHandler = (\n eventData,\n { target, ex, ey, theta, originX, originY },\n x,\n y\n) => {\n const pivotPoint = target.translateToOriginPoint(\n target.getRelativeCenterPoint(),\n originX,\n originY\n );\n\n if (isLocked(target, 'lockRotation')) {\n return false;\n }\n\n const lastAngle = Math.atan2(ey - pivotPoint.y, ex - pivotPoint.x),\n curAngle = Math.atan2(y - pivotPoint.y, x - pivotPoint.x);\n let angle = radiansToDegrees(curAngle - lastAngle + theta);\n\n if (target.snapAngle && target.snapAngle > 0) {\n const snapAngle = target.snapAngle,\n snapThreshold = target.snapThreshold || snapAngle,\n rightAngleLocked = Math.ceil(angle / snapAngle) * snapAngle,\n leftAngleLocked = Math.floor(angle / snapAngle) * snapAngle;\n\n if (Math.abs(angle - leftAngleLocked) < snapThreshold) {\n angle = leftAngleLocked;\n } else if (Math.abs(angle - rightAngleLocked) < snapThreshold) {\n angle = rightAngleLocked;\n }\n }\n\n // normalize angle to positive value\n if (angle < 0) {\n angle = 360 + angle;\n }\n angle %= 360;\n\n const hasRotated = target.angle !== angle;\n // TODO: why aren't we using set?\n target.angle = angle;\n return hasRotated;\n};\n\nexport const rotationWithSnapping = wrapWithFireEvent(\n ROTATING,\n wrapWithFixedAnchor(rotateObjectWithSnapping)\n);\n"],"names":["rotationStyleHandler","eventData","control","fabricObject","lockRotation","NOT_ALLOWED_CURSOR","cursorStyle","rotateObjectWithSnapping","_ref","x","y","target","ex","ey","theta","originX","originY","pivotPoint","translateToOriginPoint","getRelativeCenterPoint","isLocked","lastAngle","Math","atan2","curAngle","angle","radiansToDegrees","snapAngle","snapThreshold","rightAngleLocked","ceil","leftAngleLocked","floor","abs","hasRotated","rotationWithSnapping","wrapWithFireEvent","ROTATING","wrapWithFixedAnchor"],"mappings":";;;;;;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,oBAA2C,GAAGA,CACzDC,SAAS,EACTC,OAAO,EACPC,YAAY,KACT;EAC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AGE,SAAS,CAAC,GAAGA,SAAS;MAC3DI,eAAe,GAAGT,IAAI,CAACU,KAAK,CAACP,KAAK,GAAGE,SAAS,CAAC,GAAGA,SAAS,CAAA;IAE7D,IAAIL,IAAI,CAACW,GAAG,CAACR,KAAK,GAAGM,eAAe,CAAC,GAAGH,aAAa,EAAE;AACrDH,MAAAA,KAAK,GAAGM,eAAe,CAAA;AACzB,KAAC,MAAM,IAAIT,IAAI,CAACW,GAAG,CAACR,KAAK,GAAGI,gBAAgB,CAAC,GAAGD,aAAa,EAAE;AAC7DH,MAAAA,KAAK,GAAGI,gBAAgB,CAAA;AAC1B,KAAA;AACF,GAAA;;AAEA;EACA,IAAIJ,KAAK,GAAG,CAAC,EAAE;IACbA,KAAK,GAAG,GAAG,GAAGA,KAAK,CAAA;AACrB,GAAA;AACAA,EAAAA,KAAK,IAAI,GAAG,CAAA;AAEZ,EAAA,MAAMS,UAAU,GAAGvB,MAAM,CAACc,KAAK,KAAKA,KAAK,CAAA;AACzC;EACAd,MAAM,CAACc,KAAK,GAAGA,KAAK,CAAA;AACpB,EAAA,OAAOS,UAAU,CAAA;AACnB,CAAC,CAAA;AAEM,MAAMC,oBAAoB,GAAGC,iBAAiB,CACnDC,QAAQ,EACRC,mBAAmB,CAAC/B,wBAAwB,CAC9C;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scale.d.ts","sourceRoot":"","sources":["../../../src/controls/scale.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,aAAa,EACb,SAAS,EACT,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"scale.d.ts","sourceRoot":"","sources":["../../../src/controls/scale.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,aAAa,EACb,SAAS,EACT,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAczC,KAAK,cAAc,GAAG,SAAS,GAAG;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,OAAO,GAAG,KAAK,GAAG,SAAS,GAAG,EAAE,GAAG,SAAS,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,aAAa,EACxB,YAAY,EAAE,YAAY,GACzB,OAAO,CAOT;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,YAAY,EAC1B,EAAE,EAAE,OAAO,EACX,mBAAmB,EAAE,OAAO,WA0B7B;AAID;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,EAAE,qBAiBrC,CAAC;AA4GF;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,EAAE,sBAAsB,CAAC,cAAc,CAOxE,CAAC;AAsCF,eAAO,MAAM,cAAc,wCAG1B,CAAC;AAEF,eAAO,MAAM,QAAQ,wCAGpB,CAAC;AAEF,eAAO,MAAM,QAAQ,wCAGpB,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{NOT_ALLOWED_CURSOR as n,findCornerQuadrant as i,isLocked as s,getLocalPoint as e,isTransformCentered as t,invertOrigin as
|
|
1
|
+
import{NOT_ALLOWED_CURSOR as n,findCornerQuadrant as i,isLocked as s,getLocalPoint as e,isTransformCentered as t,invertOrigin as r}from"./util.min.mjs";import{wrapWithFireEvent as a}from"./wrapWithFireEvent.min.mjs";import{wrapWithFixedAnchor as c}from"./wrapWithFixedAnchor.min.mjs";import{SCALING as o,SCALE_X as l,SCALE_Y as g}from"../constants.min.mjs";function u(n,i){const s=i.canvas,e=n[s.uniScaleKey];return s.uniformScaling&&!e||!s.uniformScaling&&e}function m(n,i,e){const t=s(n,"lockScalingX"),r=s(n,"lockScalingY");if(t&&r)return!0;if(!i&&(t||r)&&e)return!0;if(t&&"x"===i)return!0;if(r&&"y"===i)return!0;const{width:a,height:c,strokeWidth:o}=n;return 0===a&&0===o&&"y"!==i||0===c&&0===o&&"x"!==i}const f=["e","se","s","sw","w","nw","n","ne","e"],y=(s,e,t)=>{const r=u(s,t);if(m(t,0!==e.x&&0===e.y?"x":0===e.x&&0!==e.y?"y":"",r))return n;const a=i(t,e);return"".concat(f[a],"-resize")};function X(n,i,a,c){let o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};const f=i.target,y=o.by,X=u(n,f);let Y,h,x,S,b,p;if(m(f,y,X))return!1;if(i.gestureScale)h=i.scaleX*i.gestureScale,x=i.scaleY*i.gestureScale;else{if(Y=e(i,i.originX,i.originY,a,c),b="y"!==y?Math.sign(Y.x||i.signX||1):1,p="x"!==y?Math.sign(Y.y||i.signY||1):1,i.signX||(i.signX=b),i.signY||(i.signY=p),s(f,"lockScalingFlip")&&(i.signX!==b||i.signY!==p))return!1;if(S=f._getTransformedDimensions(),X&&!y){const n=Math.abs(Y.x)+Math.abs(Y.y),{original:s}=i,e=n/(Math.abs(S.x*s.scaleX/f.scaleX)+Math.abs(S.y*s.scaleY/f.scaleY));h=s.scaleX*e,x=s.scaleY*e}else h=Math.abs(Y.x*f.scaleX/S.x),x=Math.abs(Y.y*f.scaleY/S.y);t(i)&&(h*=2,x*=2),i.signX!==b&&"y"!==y&&(i.originX=r(i.originX),h*=-1,i.signX=b),i.signY!==p&&"x"!==y&&(i.originY=r(i.originY),x*=-1,i.signY=p)}const M=f.scaleX,k=f.scaleY;return y?("x"===y&&f.set(l,h),"y"===y&&f.set(g,x)):(!s(f,"lockScalingX")&&f.set(l,h),!s(f,"lockScalingY")&&f.set(g,x)),M!==f.scaleX||k!==f.scaleY}const Y=(n,i,s,e)=>X(n,i,s,e),h=a(o,c(Y)),x=a(o,c(((n,i,s,e)=>X(n,i,s,e,{by:"x"})))),S=a(o,c(((n,i,s,e)=>X(n,i,s,e,{by:"y"}))));export{y as scaleCursorStyleHandler,u as scaleIsProportional,Y as scaleObjectFromCorner,h as scalingEqually,m as scalingIsForbidden,x as scalingX,S as scalingY};
|
|
2
2
|
//# sourceMappingURL=scale.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scale.min.mjs","sources":["../../../src/controls/scale.ts"],"sourcesContent":["import type {\n ControlCursorCallback,\n TPointerEvent,\n Transform,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TAxis } from '../typedefs';\nimport type { Canvas } from '../canvas/Canvas';\nimport {\n findCornerQuadrant,\n getLocalPoint,\n invertOrigin,\n isLocked,\n isTransformCentered,\n NOT_ALLOWED_CURSOR,\n} from './util';\nimport { wrapWithFireEvent } from './wrapWithFireEvent';\nimport { wrapWithFixedAnchor } from './wrapWithFixedAnchor';\n\ntype ScaleTransform = Transform & {\n gestureScale?: number;\n signX?: number;\n signY?: number;\n};\n\ntype ScaleBy = TAxis | 'equally' | '' | undefined;\n\n/**\n * Inspect event and fabricObject properties to understand if the scaling action\n * @param {Event} eventData from the user action\n * @param {FabricObject} fabricObject the fabric object about to scale\n * @return {Boolean} true if scale is proportional\n */\nexport function scaleIsProportional(\n eventData: TPointerEvent,\n fabricObject: FabricObject\n): boolean {\n const canvas = fabricObject.canvas as Canvas,\n uniformIsToggled = eventData[canvas.uniScaleKey!];\n return (\n (canvas.uniformScaling && !uniformIsToggled) ||\n (!canvas.uniformScaling && uniformIsToggled)\n );\n}\n\n/**\n * Inspect fabricObject to understand if the current scaling action is allowed\n * @param {FabricObject} fabricObject the fabric object about to scale\n * @param {String} by 'x' or 'y' or ''\n * @param {Boolean} scaleProportionally true if we are trying to scale proportionally\n * @return {Boolean} true if scaling is not allowed at current conditions\n */\nexport function scalingIsForbidden(\n fabricObject: FabricObject,\n by: ScaleBy,\n scaleProportionally: boolean\n) {\n const lockX = isLocked(fabricObject, 'lockScalingX'),\n lockY = isLocked(fabricObject, 'lockScalingY');\n if (lockX && lockY) {\n return true;\n }\n if (!by && (lockX || lockY) && scaleProportionally) {\n return true;\n }\n if (lockX && by === 'x') {\n return true;\n }\n if (lockY && by === 'y') {\n return true;\n }\n // code crashes because of a division by 0 if a 0 sized object is scaled\n // forbid to prevent scaling to happen. ISSUE-9475\n const { width, height, strokeWidth } = fabricObject;\n if (width === 0 && strokeWidth === 0 && by !== 'y') {\n return true;\n }\n if (height === 0 && strokeWidth === 0 && by !== 'x') {\n return true;\n }\n return false;\n}\n\nconst scaleMap = ['e', 'se', 's', 'sw', 'w', 'nw', 'n', 'ne', 'e'];\n\n/**\n * return the correct cursor style for the scale action\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} a valid css string for the cursor\n */\nexport const scaleCursorStyleHandler: ControlCursorCallback = (\n eventData,\n control,\n fabricObject\n) => {\n const scaleProportionally = scaleIsProportional(eventData, fabricObject),\n by =\n control.x !== 0 && control.y === 0\n ? 'x'\n : control.x === 0 && control.y !== 0\n ? 'y'\n : '';\n if (scalingIsForbidden(fabricObject, by, scaleProportionally)) {\n return NOT_ALLOWED_CURSOR;\n }\n const n = findCornerQuadrant(fabricObject, control);\n return `${scaleMap[n]}-resize`;\n};\n\n/**\n * Basic scaling logic, reused with different constrain for scaling X,Y, freely or equally.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 * @param {Object} options additional information for scaling\n * @param {String} options.by 'x', 'y', 'equally' or '' to indicate type of scaling\n * @return {Boolean} true if some change happened\n * @private\n */\nfunction scaleObject(\n eventData: TPointerEvent,\n transform: ScaleTransform,\n x: number,\n y: number,\n options: { by?: ScaleBy } = {}\n) {\n const target = transform.target,\n by = options.by,\n scaleProportionally = scaleIsProportional(eventData, target),\n forbidScaling = scalingIsForbidden(target, by, scaleProportionally);\n let newPoint, scaleX, scaleY, dim, signX, signY;\n\n if (forbidScaling) {\n return false;\n }\n if (transform.gestureScale) {\n scaleX = transform.scaleX * transform.gestureScale;\n scaleY = transform.scaleY * transform.gestureScale;\n } else {\n newPoint = getLocalPoint(\n transform,\n transform.originX,\n transform.originY,\n x,\n y\n );\n // use of sign: We use sign to detect change of direction of an action. sign usually change when\n // we cross the origin point with the mouse. So a scale flip for example. There is an issue when scaling\n // by center and scaling using one middle control ( default: mr, mt, ml, mb), the mouse movement can easily\n // cross many time the origin point and flip the object. so we need a way to filter out the noise.\n // This ternary here should be ok to filter out X scaling when we want Y only and vice versa.\n signX = by !== 'y' ? Math.sign(newPoint.x || transform.signX || 1) : 1;\n signY = by !== 'x' ? Math.sign(newPoint.y || transform.signY || 1) : 1;\n if (!transform.signX) {\n transform.signX = signX;\n }\n if (!transform.signY) {\n transform.signY = signY;\n }\n\n if (\n isLocked(target, 'lockScalingFlip') &&\n (transform.signX !== signX || transform.signY !== signY)\n ) {\n return false;\n }\n\n dim = target._getTransformedDimensions();\n // missing detection of flip and logic to switch the origin\n if (scaleProportionally && !by) {\n // uniform scaling\n const distance = Math.abs(newPoint.x) + Math.abs(newPoint.y),\n { original } = transform,\n originalDistance =\n Math.abs((dim.x * original.scaleX) / target.scaleX) +\n Math.abs((dim.y * original.scaleY) / target.scaleY),\n scale = distance / originalDistance;\n scaleX = original.scaleX * scale;\n scaleY = original.scaleY * scale;\n } else {\n scaleX = Math.abs((newPoint.x * target.scaleX) / dim.x);\n scaleY = Math.abs((newPoint.y * target.scaleY) / dim.y);\n }\n // if we are scaling by center, we need to double the scale\n if (isTransformCentered(transform)) {\n scaleX *= 2;\n scaleY *= 2;\n }\n if (transform.signX !== signX && by !== 'y') {\n transform.originX = invertOrigin(transform.originX);\n scaleX *= -1;\n transform.signX = signX;\n }\n if (transform.signY !== signY && by !== 'x') {\n transform.originY = invertOrigin(transform.originY);\n scaleY *= -1;\n transform.signY = signY;\n }\n }\n // minScale is taken care of in the setter.\n const oldScaleX = target.scaleX,\n oldScaleY = target.scaleY;\n if (!by) {\n !isLocked(target, 'lockScalingX') && target.set('scaleX', scaleX);\n !isLocked(target, 'lockScalingY') && target.set('scaleY', scaleY);\n } else {\n // forbidden cases already handled on top here.\n by === 'x' && target.set('scaleX', scaleX);\n by === 'y' && target.set('scaleY', scaleY);\n }\n return oldScaleX !== target.scaleX || oldScaleY !== target.scaleY;\n}\n\n/**\n * Generic scaling logic, to scale from corners either equally or freely.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 scaleObjectFromCorner: TransformActionHandler<ScaleTransform> = (\n eventData,\n transform,\n x,\n y\n) => {\n return scaleObject(eventData, transform, x, y);\n};\n\n/**\n * Scaling logic for the X axis.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 */\nconst scaleObjectX: TransformActionHandler<ScaleTransform> = (\n eventData,\n transform,\n x,\n y\n) => {\n return scaleObject(eventData, transform, x, y, { by: 'x' });\n};\n\n/**\n * Scaling logic for the Y axis.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 */\nconst scaleObjectY: TransformActionHandler<ScaleTransform> = (\n eventData,\n transform,\n x,\n y\n) => {\n return scaleObject(eventData, transform, x, y, { by: 'y' });\n};\n\nexport const scalingEqually = wrapWithFireEvent(\n 'scaling',\n wrapWithFixedAnchor(scaleObjectFromCorner)\n);\n\nexport const scalingX = wrapWithFireEvent(\n 'scaling',\n wrapWithFixedAnchor(scaleObjectX)\n);\n\nexport const scalingY = wrapWithFireEvent(\n 'scaling',\n wrapWithFixedAnchor(scaleObjectY)\n);\n"],"names":["scaleIsProportional","eventData","fabricObject","canvas","uniformIsToggled","uniScaleKey","uniformScaling","scalingIsForbidden","by","scaleProportionally","lockX","isLocked","lockY","width","height","strokeWidth","scaleMap","scaleCursorStyleHandler","control","x","y","NOT_ALLOWED_CURSOR","n","findCornerQuadrant","concat","scaleObject","transform","options","arguments","length","undefined","target","newPoint","scaleX","scaleY","dim","signX","signY","gestureScale","getLocalPoint","originX","originY","Math","sign","_getTransformedDimensions","distance","abs","original","scale","isTransformCentered","invertOrigin","oldScaleX","oldScaleY","set","scaleObjectFromCorner","scalingEqually","wrapWithFireEvent","wrapWithFixedAnchor","scalingX","scaleObjectX","scalingY","scaleObjectY"],"mappings":"4RAkCO,SAASA,EACdC,EACAC,GAEA,MAAMC,EAASD,EAAaC,OAC1BC,EAAmBH,EAAUE,EAAOE,aACtC,OACGF,EAAOG,iBAAmBF,IACzBD,EAAOG,gBAAkBF,CAE/B,CASO,SAASG,EACdL,EACAM,EACAC,GAEA,MAAMC,EAAQC,EAAST,EAAc,gBACnCU,EAAQD,EAAST,EAAc,gBACjC,GAAIQ,GAASE,EACX,OAAO,EAET,IAAKJ,IAAOE,GAASE,IAAUH,EAC7B,OAAO,EAET,GAAIC,GAAgB,MAAPF,EACX,OAAO,EAET,GAAII,GAAgB,MAAPJ,EACX,OAAO,EAIT,MAAMK,MAAEA,EAAKC,OAAEA,EAA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,EAAoBH,IAGTI,EAAWF,EACtB,UACAC,GAlC2DE,CAC3D1D,EACAyB,EACAP,EACAC,IAEOK,EAAYxB,EAAWyB,EAAWP,EAAGC,EAAG,CAAEZ,GAAI,SA+B1CoD,EAAWJ,EACtB,UACAC,GArB2DI,CAC3D5D,EACAyB,EACAP,EACAC,IAEOK,EAAYxB,EAAWyB,EAAWP,EAAGC,EAAG,CAAEZ,GAAI"}
|
|
1
|
+
{"version":3,"file":"scale.min.mjs","sources":["../../../src/controls/scale.ts"],"sourcesContent":["import type {\n ControlCursorCallback,\n TPointerEvent,\n Transform,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TAxis } from '../typedefs';\nimport type { Canvas } from '../canvas/Canvas';\nimport {\n findCornerQuadrant,\n getLocalPoint,\n invertOrigin,\n isLocked,\n isTransformCentered,\n NOT_ALLOWED_CURSOR,\n} from './util';\nimport { wrapWithFireEvent } from './wrapWithFireEvent';\nimport { wrapWithFixedAnchor } from './wrapWithFixedAnchor';\nimport { SCALE_X, SCALE_Y, SCALING } from '../constants';\n\ntype ScaleTransform = Transform & {\n gestureScale?: number;\n signX?: number;\n signY?: number;\n};\n\ntype ScaleBy = TAxis | 'equally' | '' | undefined;\n\n/**\n * Inspect event and fabricObject properties to understand if the scaling action\n * @param {Event} eventData from the user action\n * @param {FabricObject} fabricObject the fabric object about to scale\n * @return {Boolean} true if scale is proportional\n */\nexport function scaleIsProportional(\n eventData: TPointerEvent,\n fabricObject: FabricObject\n): boolean {\n const canvas = fabricObject.canvas as Canvas,\n uniformIsToggled = eventData[canvas.uniScaleKey!];\n return (\n (canvas.uniformScaling && !uniformIsToggled) ||\n (!canvas.uniformScaling && uniformIsToggled)\n );\n}\n\n/**\n * Inspect fabricObject to understand if the current scaling action is allowed\n * @param {FabricObject} fabricObject the fabric object about to scale\n * @param {String} by 'x' or 'y' or ''\n * @param {Boolean} scaleProportionally true if we are trying to scale proportionally\n * @return {Boolean} true if scaling is not allowed at current conditions\n */\nexport function scalingIsForbidden(\n fabricObject: FabricObject,\n by: ScaleBy,\n scaleProportionally: boolean\n) {\n const lockX = isLocked(fabricObject, 'lockScalingX'),\n lockY = isLocked(fabricObject, 'lockScalingY');\n if (lockX && lockY) {\n return true;\n }\n if (!by && (lockX || lockY) && scaleProportionally) {\n return true;\n }\n if (lockX && by === 'x') {\n return true;\n }\n if (lockY && by === 'y') {\n return true;\n }\n // code crashes because of a division by 0 if a 0 sized object is scaled\n // forbid to prevent scaling to happen. ISSUE-9475\n const { width, height, strokeWidth } = fabricObject;\n if (width === 0 && strokeWidth === 0 && by !== 'y') {\n return true;\n }\n if (height === 0 && strokeWidth === 0 && by !== 'x') {\n return true;\n }\n return false;\n}\n\nconst scaleMap = ['e', 'se', 's', 'sw', 'w', 'nw', 'n', 'ne', 'e'];\n\n/**\n * return the correct cursor style for the scale action\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} a valid css string for the cursor\n */\nexport const scaleCursorStyleHandler: ControlCursorCallback = (\n eventData,\n control,\n fabricObject\n) => {\n const scaleProportionally = scaleIsProportional(eventData, fabricObject),\n by =\n control.x !== 0 && control.y === 0\n ? 'x'\n : control.x === 0 && control.y !== 0\n ? 'y'\n : '';\n if (scalingIsForbidden(fabricObject, by, scaleProportionally)) {\n return NOT_ALLOWED_CURSOR;\n }\n const n = findCornerQuadrant(fabricObject, control);\n return `${scaleMap[n]}-resize`;\n};\n\n/**\n * Basic scaling logic, reused with different constrain for scaling X,Y, freely or equally.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 * @param {Object} options additional information for scaling\n * @param {String} options.by 'x', 'y', 'equally' or '' to indicate type of scaling\n * @return {Boolean} true if some change happened\n * @private\n */\nfunction scaleObject(\n eventData: TPointerEvent,\n transform: ScaleTransform,\n x: number,\n y: number,\n options: { by?: ScaleBy } = {}\n) {\n const target = transform.target,\n by = options.by,\n scaleProportionally = scaleIsProportional(eventData, target),\n forbidScaling = scalingIsForbidden(target, by, scaleProportionally);\n let newPoint, scaleX, scaleY, dim, signX, signY;\n\n if (forbidScaling) {\n return false;\n }\n if (transform.gestureScale) {\n scaleX = transform.scaleX * transform.gestureScale;\n scaleY = transform.scaleY * transform.gestureScale;\n } else {\n newPoint = getLocalPoint(\n transform,\n transform.originX,\n transform.originY,\n x,\n y\n );\n // use of sign: We use sign to detect change of direction of an action. sign usually change when\n // we cross the origin point with the mouse. So a scale flip for example. There is an issue when scaling\n // by center and scaling using one middle control ( default: mr, mt, ml, mb), the mouse movement can easily\n // cross many time the origin point and flip the object. so we need a way to filter out the noise.\n // This ternary here should be ok to filter out X scaling when we want Y only and vice versa.\n signX = by !== 'y' ? Math.sign(newPoint.x || transform.signX || 1) : 1;\n signY = by !== 'x' ? Math.sign(newPoint.y || transform.signY || 1) : 1;\n if (!transform.signX) {\n transform.signX = signX;\n }\n if (!transform.signY) {\n transform.signY = signY;\n }\n\n if (\n isLocked(target, 'lockScalingFlip') &&\n (transform.signX !== signX || transform.signY !== signY)\n ) {\n return false;\n }\n\n dim = target._getTransformedDimensions();\n // missing detection of flip and logic to switch the origin\n if (scaleProportionally && !by) {\n // uniform scaling\n const distance = Math.abs(newPoint.x) + Math.abs(newPoint.y),\n { original } = transform,\n originalDistance =\n Math.abs((dim.x * original.scaleX) / target.scaleX) +\n Math.abs((dim.y * original.scaleY) / target.scaleY),\n scale = distance / originalDistance;\n scaleX = original.scaleX * scale;\n scaleY = original.scaleY * scale;\n } else {\n scaleX = Math.abs((newPoint.x * target.scaleX) / dim.x);\n scaleY = Math.abs((newPoint.y * target.scaleY) / dim.y);\n }\n // if we are scaling by center, we need to double the scale\n if (isTransformCentered(transform)) {\n scaleX *= 2;\n scaleY *= 2;\n }\n if (transform.signX !== signX && by !== 'y') {\n transform.originX = invertOrigin(transform.originX);\n scaleX *= -1;\n transform.signX = signX;\n }\n if (transform.signY !== signY && by !== 'x') {\n transform.originY = invertOrigin(transform.originY);\n scaleY *= -1;\n transform.signY = signY;\n }\n }\n // minScale is taken care of in the setter.\n const oldScaleX = target.scaleX,\n oldScaleY = target.scaleY;\n if (!by) {\n !isLocked(target, 'lockScalingX') && target.set(SCALE_X, scaleX);\n !isLocked(target, 'lockScalingY') && target.set(SCALE_Y, scaleY);\n } else {\n // forbidden cases already handled on top here.\n by === 'x' && target.set(SCALE_X, scaleX);\n by === 'y' && target.set(SCALE_Y, scaleY);\n }\n return oldScaleX !== target.scaleX || oldScaleY !== target.scaleY;\n}\n\n/**\n * Generic scaling logic, to scale from corners either equally or freely.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 scaleObjectFromCorner: TransformActionHandler<ScaleTransform> = (\n eventData,\n transform,\n x,\n y\n) => {\n return scaleObject(eventData, transform, x, y);\n};\n\n/**\n * Scaling logic for the X axis.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 */\nconst scaleObjectX: TransformActionHandler<ScaleTransform> = (\n eventData,\n transform,\n x,\n y\n) => {\n return scaleObject(eventData, transform, x, y, { by: 'x' });\n};\n\n/**\n * Scaling logic for the Y axis.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 */\nconst scaleObjectY: TransformActionHandler<ScaleTransform> = (\n eventData,\n transform,\n x,\n y\n) => {\n return scaleObject(eventData, transform, x, y, { by: 'y' });\n};\n\nexport const scalingEqually = wrapWithFireEvent(\n SCALING,\n wrapWithFixedAnchor(scaleObjectFromCorner)\n);\n\nexport const scalingX = wrapWithFireEvent(\n SCALING,\n wrapWithFixedAnchor(scaleObjectX)\n);\n\nexport const scalingY = wrapWithFireEvent(\n SCALING,\n wrapWithFixedAnchor(scaleObjectY)\n);\n"],"names":["scaleIsProportional","eventData","fabricObject","canvas","uniformIsToggled","uniScaleKey","uniformScaling","scalingIsForbidden","by","scaleProportionally","lockX","isLocked","lockY","width","height","strokeWidth","scaleMap","scaleCursorStyleHandler","control","x","y","NOT_ALLOWED_CURSOR","n","findCornerQuadrant","concat","scaleObject","transform","options","arguments","length","undefined","target","newPoint","scaleX","scaleY","dim","signX","signY","gestureScale","getLocalPoint","originX","originY","Math","sign","_getTransformedDimensions","distance","abs","original","scale","isTransformCentered","invertOrigin","oldScaleX","oldScaleY","set","SCALE_X","SCALE_Y","scaleObjectFromCorner","scalingEqually","wrapWithFireEvent","SCALING","wrapWithFixedAnchor","scalingX","scaleObjectX","scalingY","scaleObjectY"],"mappings":"qWAmCO,SAASA,EACdC,EACAC,GAEA,MAAMC,EAASD,EAAaC,OAC1BC,EAAmBH,EAAUE,EAAOE,aACtC,OACGF,EAAOG,iBAAmBF,IACzBD,EAAOG,gBAAkBF,CAE/B,CASO,SAASG,EACdL,EACAM,EACAC,GAEA,MAAMC,EAAQC,EAAST,EAAc,gBACnCU,EAAQD,EAAST,EAAc,gBACjC,GAAIQ,GAASE,EACX,OAAO,EAET,IAAKJ,IAAOE,GAASE,IAAUH,EAC7B,OAAO,EAET,GAAIC,GAAgB,MAAPF,EACX,OAAO,EAET,GAAII,GAAgB,MAAPJ,EACX,OAAO,EAIT,MAAMK,MAAEA,EAAKC,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AC5BC,EACAC,EAAoBJ,IAGTK,EAAWH,EACtBC,EACAC,GAlC2DE,CAC3D7D,EACAyB,EACAP,EACAC,IAEOK,EAAYxB,EAAWyB,EAAWP,EAAGC,EAAG,CAAEZ,GAAI,SA+B1CuD,EAAWL,EACtBC,EACAC,GArB2DI,CAC3D/D,EACAyB,EACAP,EACAC,IAEOK,EAAYxB,EAAWyB,EAAWP,EAAGC,EAAG,CAAEZ,GAAI"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NOT_ALLOWED_CURSOR, findCornerQuadrant, isLocked, getLocalPoint, isTransformCentered, invertOrigin } from './util.mjs';
|
|
2
2
|
import { wrapWithFireEvent } from './wrapWithFireEvent.mjs';
|
|
3
3
|
import { wrapWithFixedAnchor } from './wrapWithFixedAnchor.mjs';
|
|
4
|
+
import { SCALING, SCALE_X, SCALE_Y } from '../constants.mjs';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Inspect event and fabricObject properties to understand if the scaling action
|
|
@@ -149,12 +150,12 @@ function scaleObject(eventData, transform, x, y) {
|
|
|
149
150
|
const oldScaleX = target.scaleX,
|
|
150
151
|
oldScaleY = target.scaleY;
|
|
151
152
|
if (!by) {
|
|
152
|
-
!isLocked(target, 'lockScalingX') && target.set(
|
|
153
|
-
!isLocked(target, 'lockScalingY') && target.set(
|
|
153
|
+
!isLocked(target, 'lockScalingX') && target.set(SCALE_X, scaleX);
|
|
154
|
+
!isLocked(target, 'lockScalingY') && target.set(SCALE_Y, scaleY);
|
|
154
155
|
} else {
|
|
155
156
|
// forbidden cases already handled on top here.
|
|
156
|
-
by === 'x' && target.set(
|
|
157
|
-
by === 'y' && target.set(
|
|
157
|
+
by === 'x' && target.set(SCALE_X, scaleX);
|
|
158
|
+
by === 'y' && target.set(SCALE_Y, scaleY);
|
|
158
159
|
}
|
|
159
160
|
return oldScaleX !== target.scaleX || oldScaleY !== target.scaleY;
|
|
160
161
|
}
|
|
@@ -201,9 +202,9 @@ const scaleObjectY = (eventData, transform, x, y) => {
|
|
|
201
202
|
by: 'y'
|
|
202
203
|
});
|
|
203
204
|
};
|
|
204
|
-
const scalingEqually = wrapWithFireEvent(
|
|
205
|
-
const scalingX = wrapWithFireEvent(
|
|
206
|
-
const scalingY = wrapWithFireEvent(
|
|
205
|
+
const scalingEqually = wrapWithFireEvent(SCALING, wrapWithFixedAnchor(scaleObjectFromCorner));
|
|
206
|
+
const scalingX = wrapWithFireEvent(SCALING, wrapWithFixedAnchor(scaleObjectX));
|
|
207
|
+
const scalingY = wrapWithFireEvent(SCALING, wrapWithFixedAnchor(scaleObjectY));
|
|
207
208
|
|
|
208
209
|
export { scaleCursorStyleHandler, scaleIsProportional, scaleObjectFromCorner, scalingEqually, scalingIsForbidden, scalingX, scalingY };
|
|
209
210
|
//# sourceMappingURL=scale.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scale.mjs","sources":["../../../src/controls/scale.ts"],"sourcesContent":["import type {\n ControlCursorCallback,\n TPointerEvent,\n Transform,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TAxis } from '../typedefs';\nimport type { Canvas } from '../canvas/Canvas';\nimport {\n findCornerQuadrant,\n getLocalPoint,\n invertOrigin,\n isLocked,\n isTransformCentered,\n NOT_ALLOWED_CURSOR,\n} from './util';\nimport { wrapWithFireEvent } from './wrapWithFireEvent';\nimport { wrapWithFixedAnchor } from './wrapWithFixedAnchor';\n\ntype ScaleTransform = Transform & {\n gestureScale?: number;\n signX?: number;\n signY?: number;\n};\n\ntype ScaleBy = TAxis | 'equally' | '' | undefined;\n\n/**\n * Inspect event and fabricObject properties to understand if the scaling action\n * @param {Event} eventData from the user action\n * @param {FabricObject} fabricObject the fabric object about to scale\n * @return {Boolean} true if scale is proportional\n */\nexport function scaleIsProportional(\n eventData: TPointerEvent,\n fabricObject: FabricObject\n): boolean {\n const canvas = fabricObject.canvas as Canvas,\n uniformIsToggled = eventData[canvas.uniScaleKey!];\n return (\n (canvas.uniformScaling && !uniformIsToggled) ||\n (!canvas.uniformScaling && uniformIsToggled)\n );\n}\n\n/**\n * Inspect fabricObject to understand if the current scaling action is allowed\n * @param {FabricObject} fabricObject the fabric object about to scale\n * @param {String} by 'x' or 'y' or ''\n * @param {Boolean} scaleProportionally true if we are trying to scale proportionally\n * @return {Boolean} true if scaling is not allowed at current conditions\n */\nexport function scalingIsForbidden(\n fabricObject: FabricObject,\n by: ScaleBy,\n scaleProportionally: boolean\n) {\n const lockX = isLocked(fabricObject, 'lockScalingX'),\n lockY = isLocked(fabricObject, 'lockScalingY');\n if (lockX && lockY) {\n return true;\n }\n if (!by && (lockX || lockY) && scaleProportionally) {\n return true;\n }\n if (lockX && by === 'x') {\n return true;\n }\n if (lockY && by === 'y') {\n return true;\n }\n // code crashes because of a division by 0 if a 0 sized object is scaled\n // forbid to prevent scaling to happen. ISSUE-9475\n const { width, height, strokeWidth } = fabricObject;\n if (width === 0 && strokeWidth === 0 && by !== 'y') {\n return true;\n }\n if (height === 0 && strokeWidth === 0 && by !== 'x') {\n return true;\n }\n return false;\n}\n\nconst scaleMap = ['e', 'se', 's', 'sw', 'w', 'nw', 'n', 'ne', 'e'];\n\n/**\n * return the correct cursor style for the scale action\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} a valid css string for the cursor\n */\nexport const scaleCursorStyleHandler: ControlCursorCallback = (\n eventData,\n control,\n fabricObject\n) => {\n const scaleProportionally = scaleIsProportional(eventData, fabricObject),\n by =\n control.x !== 0 && control.y === 0\n ? 'x'\n : control.x === 0 && control.y !== 0\n ? 'y'\n : '';\n if (scalingIsForbidden(fabricObject, by, scaleProportionally)) {\n return NOT_ALLOWED_CURSOR;\n }\n const n = findCornerQuadrant(fabricObject, control);\n return `${scaleMap[n]}-resize`;\n};\n\n/**\n * Basic scaling logic, reused with different constrain for scaling X,Y, freely or equally.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 * @param {Object} options additional information for scaling\n * @param {String} options.by 'x', 'y', 'equally' or '' to indicate type of scaling\n * @return {Boolean} true if some change happened\n * @private\n */\nfunction scaleObject(\n eventData: TPointerEvent,\n transform: ScaleTransform,\n x: number,\n y: number,\n options: { by?: ScaleBy } = {}\n) {\n const target = transform.target,\n by = options.by,\n scaleProportionally = scaleIsProportional(eventData, target),\n forbidScaling = scalingIsForbidden(target, by, scaleProportionally);\n let newPoint, scaleX, scaleY, dim, signX, signY;\n\n if (forbidScaling) {\n return false;\n }\n if (transform.gestureScale) {\n scaleX = transform.scaleX * transform.gestureScale;\n scaleY = transform.scaleY * transform.gestureScale;\n } else {\n newPoint = getLocalPoint(\n transform,\n transform.originX,\n transform.originY,\n x,\n y\n );\n // use of sign: We use sign to detect change of direction of an action. sign usually change when\n // we cross the origin point with the mouse. So a scale flip for example. There is an issue when scaling\n // by center and scaling using one middle control ( default: mr, mt, ml, mb), the mouse movement can easily\n // cross many time the origin point and flip the object. so we need a way to filter out the noise.\n // This ternary here should be ok to filter out X scaling when we want Y only and vice versa.\n signX = by !== 'y' ? Math.sign(newPoint.x || transform.signX || 1) : 1;\n signY = by !== 'x' ? Math.sign(newPoint.y || transform.signY || 1) : 1;\n if (!transform.signX) {\n transform.signX = signX;\n }\n if (!transform.signY) {\n transform.signY = signY;\n }\n\n if (\n isLocked(target, 'lockScalingFlip') &&\n (transform.signX !== signX || transform.signY !== signY)\n ) {\n return false;\n }\n\n dim = target._getTransformedDimensions();\n // missing detection of flip and logic to switch the origin\n if (scaleProportionally && !by) {\n // uniform scaling\n const distance = Math.abs(newPoint.x) + Math.abs(newPoint.y),\n { original } = transform,\n originalDistance =\n Math.abs((dim.x * original.scaleX) / target.scaleX) +\n Math.abs((dim.y * original.scaleY) / target.scaleY),\n scale = distance / originalDistance;\n scaleX = original.scaleX * scale;\n scaleY = original.scaleY * scale;\n } else {\n scaleX = Math.abs((newPoint.x * target.scaleX) / dim.x);\n scaleY = Math.abs((newPoint.y * target.scaleY) / dim.y);\n }\n // if we are scaling by center, we need to double the scale\n if (isTransformCentered(transform)) {\n scaleX *= 2;\n scaleY *= 2;\n }\n if (transform.signX !== signX && by !== 'y') {\n transform.originX = invertOrigin(transform.originX);\n scaleX *= -1;\n transform.signX = signX;\n }\n if (transform.signY !== signY && by !== 'x') {\n transform.originY = invertOrigin(transform.originY);\n scaleY *= -1;\n transform.signY = signY;\n }\n }\n // minScale is taken care of in the setter.\n const oldScaleX = target.scaleX,\n oldScaleY = target.scaleY;\n if (!by) {\n !isLocked(target, 'lockScalingX') && target.set('scaleX', scaleX);\n !isLocked(target, 'lockScalingY') && target.set('scaleY', scaleY);\n } else {\n // forbidden cases already handled on top here.\n by === 'x' && target.set('scaleX', scaleX);\n by === 'y' && target.set('scaleY', scaleY);\n }\n return oldScaleX !== target.scaleX || oldScaleY !== target.scaleY;\n}\n\n/**\n * Generic scaling logic, to scale from corners either equally or freely.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 scaleObjectFromCorner: TransformActionHandler<ScaleTransform> = (\n eventData,\n transform,\n x,\n y\n) => {\n return scaleObject(eventData, transform, x, y);\n};\n\n/**\n * Scaling logic for the X axis.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 */\nconst scaleObjectX: TransformActionHandler<ScaleTransform> = (\n eventData,\n transform,\n x,\n y\n) => {\n return scaleObject(eventData, transform, x, y, { by: 'x' });\n};\n\n/**\n * Scaling logic for the Y axis.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 */\nconst scaleObjectY: TransformActionHandler<ScaleTransform> = (\n eventData,\n transform,\n x,\n y\n) => {\n return scaleObject(eventData, transform, x, y, { by: 'y' });\n};\n\nexport const scalingEqually = wrapWithFireEvent(\n 'scaling',\n wrapWithFixedAnchor(scaleObjectFromCorner)\n);\n\nexport const scalingX = wrapWithFireEvent(\n 'scaling',\n wrapWithFixedAnchor(scaleObjectX)\n);\n\nexport const scalingY = wrapWithFireEvent(\n 'scaling',\n wrapWithFixedAnchor(scaleObjectY)\n);\n"],"names":["scaleIsProportional","eventData","fabricObject","canvas","uniformIsToggled","uniScaleKey","uniformScaling","scalingIsForbidden","by","scaleProportionally","lockX","isLocked","lockY","width","height","strokeWidth","scaleMap","scaleCursorStyleHandler","control","x","y","NOT_ALLOWED_CURSOR","n","findCornerQuadrant","concat","scaleObject","transform","options","arguments","length","undefined","target","forbidScaling","newPoint","scaleX","scaleY","dim","signX","signY","gestureScale","getLocalPoint","originX","originY","Math","sign","_getTransformedDimensions","distance","abs","original","originalDistance","scale","isTransformCentered","invertOrigin","oldScaleX","oldScaleY","set","scaleObjectFromCorner","scaleObjectX","scaleObjectY","scalingEqually","wrapWithFireEvent","wrapWithFixedAnchor","scalingX","scalingY"],"mappings":";;;;AA4BA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,mBAAmBA,CACjCC,SAAwB,EACxBC,YAA0B,EACjB;AACT,EAAA,MAAMC,MAAM,GAAGD,YAAY,CAACC,MAAgB;AAC1CC,IAAAA,gBAAgB,GAAGH,SAAS,CAACE,MAAM,CAACE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MAAM,CAACG,MAAM,IAAIoB,SAAS,KAAKvB,MAAM,CAACI,MAAM,CAAA;AACnE,CAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMqB,qBAA6D,GAAGA,CAC3EvD,SAAS,EACTyB,SAAS,EACTP,CAAC,EACDC,CAAC,KACE;EACH,OAAOK,WAAW,CAACxB,SAAS,EAAEyB,SAAS,EAAEP,CAAC,EAAEC,CAAC,CAAC,CAAA;AAChD,EAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMqC,YAAoD,GAAGA,CAC3DxD,SAAS,EACTyB,SAAS,EACTP,CAAC,EACDC,CAAC,KACE;EACH,OAAOK,WAAW,CAACxB,SAAS,EAAEyB,SAAS,EAAEP,CAAC,EAAEC,CAAC,EAAE;AAAEZ,IAAAA,EAAE,EAAE,GAAA;AAAI,GAAC,CAAC,CAAA;AAC7D,CAAC,CAAA;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMkD,YAAoD,GAAGA,CAC3DzD,SAAS,EACTyB,SAAS,EACTP,CAAC,EACDC,CAAC,KACE;EACH,OAAOK,WAAW,CAACxB,SAAS,EAAEyB,SAAS,EAAEP,CAAC,EAAEC,CAAC,EAAE;AAAEZ,IAAAA,EAAE,EAAE,GAAA;AAAI,GAAC,CAAC,CAAA;AAC7D,CAAC,CAAA;AAEM,MAAMmD,cAAc,GAAGC,iBAAiB,CAC7C,SAAS,EACTC,mBAAmB,CAACL,qBAAqB,CAC3C,EAAC;AAEM,MAAMM,QAAQ,GAAGF,iBAAiB,CACvC,SAAS,EACTC,mBAAmB,CAACJ,YAAY,CAClC,EAAC;AAEM,MAAMM,QAAQ,GAAGH,iBAAiB,CACvC,SAAS,EACTC,mBAAmB,CAACH,YAAY,CAClC;;;;"}
|
|
1
|
+
{"version":3,"file":"scale.mjs","sources":["../../../src/controls/scale.ts"],"sourcesContent":["import type {\n ControlCursorCallback,\n TPointerEvent,\n Transform,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TAxis } from '../typedefs';\nimport type { Canvas } from '../canvas/Canvas';\nimport {\n findCornerQuadrant,\n getLocalPoint,\n invertOrigin,\n isLocked,\n isTransformCentered,\n NOT_ALLOWED_CURSOR,\n} from './util';\nimport { wrapWithFireEvent } from './wrapWithFireEvent';\nimport { wrapWithFixedAnchor } from './wrapWithFixedAnchor';\nimport { SCALE_X, SCALE_Y, SCALING } from '../constants';\n\ntype ScaleTransform = Transform & {\n gestureScale?: number;\n signX?: number;\n signY?: number;\n};\n\ntype ScaleBy = TAxis | 'equally' | '' | undefined;\n\n/**\n * Inspect event and fabricObject properties to understand if the scaling action\n * @param {Event} eventData from the user action\n * @param {FabricObject} fabricObject the fabric object about to scale\n * @return {Boolean} true if scale is proportional\n */\nexport function scaleIsProportional(\n eventData: TPointerEvent,\n fabricObject: FabricObject\n): boolean {\n const canvas = fabricObject.canvas as Canvas,\n uniformIsToggled = eventData[canvas.uniScaleKey!];\n return (\n (canvas.uniformScaling && !uniformIsToggled) ||\n (!canvas.uniformScaling && uniformIsToggled)\n );\n}\n\n/**\n * Inspect fabricObject to understand if the current scaling action is allowed\n * @param {FabricObject} fabricObject the fabric object about to scale\n * @param {String} by 'x' or 'y' or ''\n * @param {Boolean} scaleProportionally true if we are trying to scale proportionally\n * @return {Boolean} true if scaling is not allowed at current conditions\n */\nexport function scalingIsForbidden(\n fabricObject: FabricObject,\n by: ScaleBy,\n scaleProportionally: boolean\n) {\n const lockX = isLocked(fabricObject, 'lockScalingX'),\n lockY = isLocked(fabricObject, 'lockScalingY');\n if (lockX && lockY) {\n return true;\n }\n if (!by && (lockX || lockY) && scaleProportionally) {\n return true;\n }\n if (lockX && by === 'x') {\n return true;\n }\n if (lockY && by === 'y') {\n return true;\n }\n // code crashes because of a division by 0 if a 0 sized object is scaled\n // forbid to prevent scaling to happen. ISSUE-9475\n const { width, height, strokeWidth } = fabricObject;\n if (width === 0 && strokeWidth === 0 && by !== 'y') {\n return true;\n }\n if (height === 0 && strokeWidth === 0 && by !== 'x') {\n return true;\n }\n return false;\n}\n\nconst scaleMap = ['e', 'se', 's', 'sw', 'w', 'nw', 'n', 'ne', 'e'];\n\n/**\n * return the correct cursor style for the scale action\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} a valid css string for the cursor\n */\nexport const scaleCursorStyleHandler: ControlCursorCallback = (\n eventData,\n control,\n fabricObject\n) => {\n const scaleProportionally = scaleIsProportional(eventData, fabricObject),\n by =\n control.x !== 0 && control.y === 0\n ? 'x'\n : control.x === 0 && control.y !== 0\n ? 'y'\n : '';\n if (scalingIsForbidden(fabricObject, by, scaleProportionally)) {\n return NOT_ALLOWED_CURSOR;\n }\n const n = findCornerQuadrant(fabricObject, control);\n return `${scaleMap[n]}-resize`;\n};\n\n/**\n * Basic scaling logic, reused with different constrain for scaling X,Y, freely or equally.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 * @param {Object} options additional information for scaling\n * @param {String} options.by 'x', 'y', 'equally' or '' to indicate type of scaling\n * @return {Boolean} true if some change happened\n * @private\n */\nfunction scaleObject(\n eventData: TPointerEvent,\n transform: ScaleTransform,\n x: number,\n y: number,\n options: { by?: ScaleBy } = {}\n) {\n const target = transform.target,\n by = options.by,\n scaleProportionally = scaleIsProportional(eventData, target),\n forbidScaling = scalingIsForbidden(target, by, scaleProportionally);\n let newPoint, scaleX, scaleY, dim, signX, signY;\n\n if (forbidScaling) {\n return false;\n }\n if (transform.gestureScale) {\n scaleX = transform.scaleX * transform.gestureScale;\n scaleY = transform.scaleY * transform.gestureScale;\n } else {\n newPoint = getLocalPoint(\n transform,\n transform.originX,\n transform.originY,\n x,\n y\n );\n // use of sign: We use sign to detect change of direction of an action. sign usually change when\n // we cross the origin point with the mouse. So a scale flip for example. There is an issue when scaling\n // by center and scaling using one middle control ( default: mr, mt, ml, mb), the mouse movement can easily\n // cross many time the origin point and flip the object. so we need a way to filter out the noise.\n // This ternary here should be ok to filter out X scaling when we want Y only and vice versa.\n signX = by !== 'y' ? Math.sign(newPoint.x || transform.signX || 1) : 1;\n signY = by !== 'x' ? Math.sign(newPoint.y || transform.signY || 1) : 1;\n if (!transform.signX) {\n transform.signX = signX;\n }\n if (!transform.signY) {\n transform.signY = signY;\n }\n\n if (\n isLocked(target, 'lockScalingFlip') &&\n (transform.signX !== signX || transform.signY !== signY)\n ) {\n return false;\n }\n\n dim = target._getTransformedDimensions();\n // missing detection of flip and logic to switch the origin\n if (scaleProportionally && !by) {\n // uniform scaling\n const distance = Math.abs(newPoint.x) + Math.abs(newPoint.y),\n { original } = transform,\n originalDistance =\n Math.abs((dim.x * original.scaleX) / target.scaleX) +\n Math.abs((dim.y * original.scaleY) / target.scaleY),\n scale = distance / originalDistance;\n scaleX = original.scaleX * scale;\n scaleY = original.scaleY * scale;\n } else {\n scaleX = Math.abs((newPoint.x * target.scaleX) / dim.x);\n scaleY = Math.abs((newPoint.y * target.scaleY) / dim.y);\n }\n // if we are scaling by center, we need to double the scale\n if (isTransformCentered(transform)) {\n scaleX *= 2;\n scaleY *= 2;\n }\n if (transform.signX !== signX && by !== 'y') {\n transform.originX = invertOrigin(transform.originX);\n scaleX *= -1;\n transform.signX = signX;\n }\n if (transform.signY !== signY && by !== 'x') {\n transform.originY = invertOrigin(transform.originY);\n scaleY *= -1;\n transform.signY = signY;\n }\n }\n // minScale is taken care of in the setter.\n const oldScaleX = target.scaleX,\n oldScaleY = target.scaleY;\n if (!by) {\n !isLocked(target, 'lockScalingX') && target.set(SCALE_X, scaleX);\n !isLocked(target, 'lockScalingY') && target.set(SCALE_Y, scaleY);\n } else {\n // forbidden cases already handled on top here.\n by === 'x' && target.set(SCALE_X, scaleX);\n by === 'y' && target.set(SCALE_Y, scaleY);\n }\n return oldScaleX !== target.scaleX || oldScaleY !== target.scaleY;\n}\n\n/**\n * Generic scaling logic, to scale from corners either equally or freely.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 scaleObjectFromCorner: TransformActionHandler<ScaleTransform> = (\n eventData,\n transform,\n x,\n y\n) => {\n return scaleObject(eventData, transform, x, y);\n};\n\n/**\n * Scaling logic for the X axis.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 */\nconst scaleObjectX: TransformActionHandler<ScaleTransform> = (\n eventData,\n transform,\n x,\n y\n) => {\n return scaleObject(eventData, transform, x, y, { by: 'x' });\n};\n\n/**\n * Scaling logic for the Y axis.\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 */\nconst scaleObjectY: TransformActionHandler<ScaleTransform> = (\n eventData,\n transform,\n x,\n y\n) => {\n return scaleObject(eventData, transform, x, y, { by: 'y' });\n};\n\nexport const scalingEqually = wrapWithFireEvent(\n SCALING,\n wrapWithFixedAnchor(scaleObjectFromCorner)\n);\n\nexport const scalingX = wrapWithFireEvent(\n SCALING,\n wrapWithFixedAnchor(scaleObjectX)\n);\n\nexport const scalingY = wrapWithFireEvent(\n SCALING,\n wrapWithFixedAnchor(scaleObjectY)\n);\n"],"names":["scaleIsProportional","eventData","fabricObject","canvas","uniformIsToggled","uniScaleKey","uniformScaling","scalingIsForbidden","by","scaleProportionally","lockX","isLocked","lockY","width","height","strokeWidth","scaleMap","scaleCursorStyleHandler","control","x","y","NOT_ALLOWED_CURSOR","n","findCornerQuadrant","concat","scaleObject","transform","options","arguments","length","undefined","target","forbidScaling","newPoint","scaleX","scaleY","dim","signX","signY","gestureScale","getLocalPoint","originX","originY","Math","sign","_getTransformedDimensions","distance","abs","original","originalDistance","scale","isTransformCentered","invertOrigin","oldScaleX","oldScaleY","set","SCALE_X","SCALE_Y","scaleObjectFromCorner","scaleObjectX","scaleObjectY","scalingEqually","wrapWithFireEvent","SCALING","wrapWithFixedAnchor","scalingX","scalingY"],"mappings":";;;;;AA6BA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,mBAAmBA,CACjCC,SAAwB,EACxBC,YAA0B,EACjB;AACT,EAAA,MAAMC,MAAM,GAAGD,YAAY,CAACC,MAAgB;AAC1CC,IAAAA,gBAAgB,GAAGH,SAAS,CAACE,MAAM,CAACE,WAAW,CAAE,CAAA;AACnD,EAAA,OACGF,MAAM,CAACG,cAAc,IAAI,CAACF,gBAAgB,IAC1C,CAACD,MAAM,CAACG,cAAc,IAAIF,gBAAiB,CAAA;AAEhD,CAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,kBAAkBA,CAChCL,YAA0B,EAC1BM,EAAW,EACXC,mBAA4B,EAC5B;AACA,EAAA,MAAMC,KAAK,GAAGC,QAAQ,CAACT,YAAY,EAAE,cAAc,CAAC;AAClDU,IAAAA,KAAK,GAAGD,QAAQ,CAACT,YAAY,EAAE,cAAc,CAAC,CAAA;EAChD,IAAIQ,KAAK,IAAIE,KAAK,EAAE;AAClB,IAAA,OAAO,IAAI,CAAA;AACb,GAAA;EACA,IAAI,CAACJ,EAAE,KAAKE,KAAK,IAAIE,KAAK,CAAC,IAAIH,mBAAmB,EAAE;AAClD,IAAA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AC,CAAA;AAC7D,CAAC,CAAA;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMoD,YAAoD,GAAGA,CAC3D3D,SAAS,EACTyB,SAAS,EACTP,CAAC,EACDC,CAAC,KACE;EACH,OAAOK,WAAW,CAACxB,SAAS,EAAEyB,SAAS,EAAEP,CAAC,EAAEC,CAAC,EAAE;AAAEZ,IAAAA,EAAE,EAAE,GAAA;AAAI,GAAC,CAAC,CAAA;AAC7D,CAAC,CAAA;AAEM,MAAMqD,cAAc,GAAGC,iBAAiB,CAC7CC,OAAO,EACPC,mBAAmB,CAACN,qBAAqB,CAC3C,EAAC;AAEM,MAAMO,QAAQ,GAAGH,iBAAiB,CACvCC,OAAO,EACPC,mBAAmB,CAACL,YAAY,CAClC,EAAC;AAEM,MAAMO,QAAQ,GAAGJ,iBAAiB,CACvCC,OAAO,EACPC,mBAAmB,CAACJ,YAAY,CAClC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaleSkew.d.ts","sourceRoot":"","sources":["../../../src/controls/scaleSkew.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EAErB,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"scaleSkew.d.ts","sourceRoot":"","sources":["../../../src/controls/scaleSkew.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EAErB,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQ5C;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,EAAE,eAAe,CACjD,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAYhC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,EAAE,qBAQzC,CAAC;AACF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,EAAE,sBAShC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,EAAE,sBAShC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{SKEW_X as t,SCALE_Y as n,SKEW_Y as r,SCALE_X as m}from"../constants.min.mjs";import{scaleCursorStyleHandler as o,scalingX as s,scalingY as e}from"./scale.min.mjs";import{skewCursorStyleHandler as i,skewHandlerY as a,skewHandlerX as c}from"./skew.min.mjs";function f(t,n){return t[n.canvas.altActionKey]}const p=(o,s,e)=>{const i=f(o,e);return 0===s.x?i?t:n:0===s.y?i?r:m:""},j=(t,n,r)=>f(t,r)?i(t,n,r):o(t,n,r),u=(t,n,r,m)=>f(t,n.target)?a(t,n,r,m):s(t,n,r,m),g=(t,n,r,m)=>f(t,n.target)?c(t,n,r,m):e(t,n,r,m);export{p as scaleOrSkewActionName,j as scaleSkewCursorStyleHandler,u as scalingXOrSkewingY,g as scalingYOrSkewingX};
|
|
2
2
|
//# sourceMappingURL=scaleSkew.min.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaleSkew.min.mjs","sources":["../../../src/controls/scaleSkew.ts"],"sourcesContent":["import type {\n ControlCallback,\n ControlCursorCallback,\n TPointerEvent,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TAxisKey } from '../typedefs';\nimport { scaleCursorStyleHandler, scalingX, scalingY } from './scale';\nimport { skewCursorStyleHandler, skewHandlerX, skewHandlerY } from './skew';\n\nfunction isAltAction(eventData: TPointerEvent, target: FabricObject) {\n return eventData[target.canvas!.altActionKey!];\n}\n\n/**\n * Inspect event, control and fabricObject to return the correct action name\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} an action name\n */\nexport const scaleOrSkewActionName: ControlCallback<\n TAxisKey<'skew' | 'scale'> | ''\n> = (eventData, control, fabricObject) => {\n const isAlternative = isAltAction(eventData, fabricObject);\n if (control.x === 0) {\n // then is scaleY or skewX\n return isAlternative ?
|
|
1
|
+
{"version":3,"file":"scaleSkew.min.mjs","sources":["../../../src/controls/scaleSkew.ts"],"sourcesContent":["import type {\n ControlCallback,\n ControlCursorCallback,\n TPointerEvent,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport { SCALE_X, SCALE_Y, SKEW_X, SKEW_Y } from '../constants';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TAxisKey } from '../typedefs';\nimport { scaleCursorStyleHandler, scalingX, scalingY } from './scale';\nimport { skewCursorStyleHandler, skewHandlerX, skewHandlerY } from './skew';\n\nfunction isAltAction(eventData: TPointerEvent, target: FabricObject) {\n return eventData[target.canvas!.altActionKey!];\n}\n\n/**\n * Inspect event, control and fabricObject to return the correct action name\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} an action name\n */\nexport const scaleOrSkewActionName: ControlCallback<\n TAxisKey<'skew' | 'scale'> | ''\n> = (eventData, control, fabricObject) => {\n const isAlternative = isAltAction(eventData, fabricObject);\n if (control.x === 0) {\n // then is scaleY or skewX\n return isAlternative ? SKEW_X : SCALE_Y;\n }\n if (control.y === 0) {\n // then is scaleY or skewX\n return isAlternative ? SKEW_Y : SCALE_X;\n }\n return '';\n};\n\n/**\n * Combine skew and scale style handlers to cover fabric standard use case\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} a valid css string for the cursor\n */\nexport const scaleSkewCursorStyleHandler: ControlCursorCallback = (\n eventData,\n control,\n fabricObject\n) => {\n return isAltAction(eventData, fabricObject)\n ? skewCursorStyleHandler(eventData, control, fabricObject)\n : scaleCursorStyleHandler(eventData, control, fabricObject);\n};\n/**\n * Composed action handler to either scale X or skew Y\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 scalingXOrSkewingY: TransformActionHandler = (\n eventData,\n transform,\n x,\n y\n) => {\n return isAltAction(eventData, transform.target)\n ? skewHandlerY(eventData, transform, x, y)\n : scalingX(eventData, transform, x, y);\n};\n\n/**\n * Composed action handler to either scale Y or skew X\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 scalingYOrSkewingX: TransformActionHandler = (\n eventData,\n transform,\n x,\n y\n) => {\n return isAltAction(eventData, transform.target)\n ? skewHandlerX(eventData, transform, x, y)\n : scalingY(eventData, transform, x, y);\n};\n"],"names":["isAltAction","eventData","target","canvas","altActionKey","scaleOrSkewActionName","control","fabricObject","isAlternative","x","SKEW_X","SCALE_Y","y","SKEW_Y","SCALE_X","scaleSkewCursorStyleHandler","skewCursorStyleHandler","scaleCursorStyleHandler","scalingXOrSkewingY","transform","skewHandlerY","scalingX","scalingYOrSkewingX","skewHandlerX","scalingY"],"mappings":"sQAYA,SAASA,EAAYC,EAA0BC,GAC7C,OAAOD,EAAUC,EAAOC,OAAQC,aAClC,CASO,MAAMC,EAETA,CAACJ,EAAWK,EAASC,KACvB,MAAMC,EAAgBR,EAAYC,EAAWM,GAC7C,OAAkB,IAAdD,EAAQG,EAEHD,EAAgBE,EAASC,EAEhB,IAAdL,EAAQM,EAEHJ,EAAgBK,EAASC,EAE3B,EAAE,EAUEC,EAAqDA,CAChEd,EACAK,EACAC,IAEOP,EAAYC,EAAWM,GAC1BS,EAAuBf,EAAWK,EAASC,GAC3CU,EAAwBhB,EAAWK,EAASC,GAWrCW,EAA6CA,CACxDjB,EACAkB,EACAV,EACAG,IAEOZ,EAAYC,EAAWkB,EAAUjB,QACpCkB,EAAanB,EAAWkB,EAAWV,EAAGG,GACtCS,EAASpB,EAAWkB,EAAWV,EAAGG,GAY3BU,EAA6CA,CACxDrB,EACAkB,EACAV,EACAG,IAEOZ,EAAYC,EAAWkB,EAAUjB,QACpCqB,EAAatB,EAAWkB,EAAWV,EAAGG,GACtCY,EAASvB,EAAWkB,EAAWV,EAAGG"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SKEW_X, SCALE_Y, SKEW_Y, SCALE_X } from '../constants.mjs';
|
|
1
2
|
import { scaleCursorStyleHandler, scalingX, scalingY } from './scale.mjs';
|
|
2
3
|
import { skewCursorStyleHandler, skewHandlerY, skewHandlerX } from './skew.mjs';
|
|
3
4
|
|
|
@@ -16,11 +17,11 @@ const scaleOrSkewActionName = (eventData, control, fabricObject) => {
|
|
|
16
17
|
const isAlternative = isAltAction(eventData, fabricObject);
|
|
17
18
|
if (control.x === 0) {
|
|
18
19
|
// then is scaleY or skewX
|
|
19
|
-
return isAlternative ?
|
|
20
|
+
return isAlternative ? SKEW_X : SCALE_Y;
|
|
20
21
|
}
|
|
21
22
|
if (control.y === 0) {
|
|
22
23
|
// then is scaleY or skewX
|
|
23
|
-
return isAlternative ?
|
|
24
|
+
return isAlternative ? SKEW_Y : SCALE_X;
|
|
24
25
|
}
|
|
25
26
|
return '';
|
|
26
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaleSkew.mjs","sources":["../../../src/controls/scaleSkew.ts"],"sourcesContent":["import type {\n ControlCallback,\n ControlCursorCallback,\n TPointerEvent,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TAxisKey } from '../typedefs';\nimport { scaleCursorStyleHandler, scalingX, scalingY } from './scale';\nimport { skewCursorStyleHandler, skewHandlerX, skewHandlerY } from './skew';\n\nfunction isAltAction(eventData: TPointerEvent, target: FabricObject) {\n return eventData[target.canvas!.altActionKey!];\n}\n\n/**\n * Inspect event, control and fabricObject to return the correct action name\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} an action name\n */\nexport const scaleOrSkewActionName: ControlCallback<\n TAxisKey<'skew' | 'scale'> | ''\n> = (eventData, control, fabricObject) => {\n const isAlternative = isAltAction(eventData, fabricObject);\n if (control.x === 0) {\n // then is scaleY or skewX\n return isAlternative ?
|
|
1
|
+
{"version":3,"file":"scaleSkew.mjs","sources":["../../../src/controls/scaleSkew.ts"],"sourcesContent":["import type {\n ControlCallback,\n ControlCursorCallback,\n TPointerEvent,\n TransformActionHandler,\n} from '../EventTypeDefs';\nimport { SCALE_X, SCALE_Y, SKEW_X, SKEW_Y } from '../constants';\nimport type { FabricObject } from '../shapes/Object/FabricObject';\nimport type { TAxisKey } from '../typedefs';\nimport { scaleCursorStyleHandler, scalingX, scalingY } from './scale';\nimport { skewCursorStyleHandler, skewHandlerX, skewHandlerY } from './skew';\n\nfunction isAltAction(eventData: TPointerEvent, target: FabricObject) {\n return eventData[target.canvas!.altActionKey!];\n}\n\n/**\n * Inspect event, control and fabricObject to return the correct action name\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} an action name\n */\nexport const scaleOrSkewActionName: ControlCallback<\n TAxisKey<'skew' | 'scale'> | ''\n> = (eventData, control, fabricObject) => {\n const isAlternative = isAltAction(eventData, fabricObject);\n if (control.x === 0) {\n // then is scaleY or skewX\n return isAlternative ? SKEW_X : SCALE_Y;\n }\n if (control.y === 0) {\n // then is scaleY or skewX\n return isAlternative ? SKEW_Y : SCALE_X;\n }\n return '';\n};\n\n/**\n * Combine skew and scale style handlers to cover fabric standard use case\n * @param {Event} eventData the javascript event that is causing the scale\n * @param {Control} control the control that is interested in the action\n * @param {FabricObject} fabricObject the fabric object that is interested in the action\n * @return {String} a valid css string for the cursor\n */\nexport const scaleSkewCursorStyleHandler: ControlCursorCallback = (\n eventData,\n control,\n fabricObject\n) => {\n return isAltAction(eventData, fabricObject)\n ? skewCursorStyleHandler(eventData, control, fabricObject)\n : scaleCursorStyleHandler(eventData, control, fabricObject);\n};\n/**\n * Composed action handler to either scale X or skew Y\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 scalingXOrSkewingY: TransformActionHandler = (\n eventData,\n transform,\n x,\n y\n) => {\n return isAltAction(eventData, transform.target)\n ? skewHandlerY(eventData, transform, x, y)\n : scalingX(eventData, transform, x, y);\n};\n\n/**\n * Composed action handler to either scale Y or skew X\n * Needs to be wrapped with `wrapWithFixedAnchor` to be effective\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 scalingYOrSkewingX: TransformActionHandler = (\n eventData,\n transform,\n x,\n y\n) => {\n return isAltAction(eventData, transform.target)\n ? skewHandlerX(eventData, transform, x, y)\n : scalingY(eventData, transform, x, y);\n};\n"],"names":["isAltAction","eventData","target","canvas","altActionKey","scaleOrSkewActionName","control","fabricObject","isAlternative","x","SKEW_X","SCALE_Y","y","SKEW_Y","SCALE_X","scaleSkewCursorStyleHandler","skewCursorStyleHandler","scaleCursorStyleHandler","scalingXOrSkewingY","transform","skewHandlerY","scalingX","scalingYOrSkewingX","skewHandlerX","scalingY"],"mappings":";;;;AAYA,SAASA,WAAWA,CAACC,SAAwB,EAAEC,MAAoB,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C,EAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMU,kBAA0C,GAAGA,CACxDrB,SAAS,EACTkB,SAAS,EACTV,CAAC,EACDG,CAAC,KACE;AACH,EAAA,OAAOZ,WAAW,CAACC,SAAS,EAAEkB,SAAS,CAACjB,MAAM,CAAC,GAC3CqB,YAAY,CAACtB,SAAS,EAAEkB,SAAS,EAAEV,CAAC,EAAEG,CAAC,CAAC,GACxCY,QAAQ,CAACvB,SAAS,EAAEkB,SAAS,EAAEV,CAAC,EAAEG,CAAC,CAAC,CAAA;AAC1C;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skew.d.ts","sourceRoot":"","sources":["../../../src/controls/skew.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EAErB,SAAS,EACT,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"skew.d.ts","sourceRoot":"","sources":["../../../src/controls/skew.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EAErB,SAAS,EACT,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;AAyB1B,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG;IAAE,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;CAAE,CAAC;AAiChE;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,EAAE,qBAapC,CAAC;AAoIF;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,EAAE,sBAO1B,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,EAAE,sBAO1B,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{objectSpread2 as e,objectWithoutProperties as i}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{resolveOrigin as n}from"../util/misc/resolveOrigin.min.mjs";import{Point as s}from"../Point.min.mjs";import{radiansToDegrees as r,degreesToRadians as t}from"../util/misc/radiansDegreesConversion.min.mjs";import{isLocked as o,NOT_ALLOWED_CURSOR as m,findCornerQuadrant as c,getLocalPoint as a}from"./util.min.mjs";import{wrapWithFireEvent as l}from"./wrapWithFireEvent.min.mjs";import{wrapWithFixedAnchor as g}from"./wrapWithFixedAnchor.min.mjs";import{CENTER as w}from"../constants.min.mjs";const
|
|
1
|
+
import{objectSpread2 as e,objectWithoutProperties as i}from"../../_virtual/_rollupPluginBabelHelpers.min.mjs";import{resolveOrigin as n}from"../util/misc/resolveOrigin.min.mjs";import{Point as s}from"../Point.min.mjs";import{radiansToDegrees as r,degreesToRadians as t}from"../util/misc/radiansDegreesConversion.min.mjs";import{isLocked as o,NOT_ALLOWED_CURSOR as m,findCornerQuadrant as c,getLocalPoint as a}from"./util.min.mjs";import{wrapWithFireEvent as l}from"./wrapWithFireEvent.min.mjs";import{wrapWithFixedAnchor as g}from"./wrapWithFixedAnchor.min.mjs";import{CENTER as w,SKEWING as f,SCALE_X as k,SKEW_X as p,SCALE_Y as u,SKEW_Y as x}from"../constants.min.mjs";const d=["target","ex","ey","skewingSide"],S={x:{counterAxis:"y",scale:k,skew:p,lockSkewing:"lockSkewingX",origin:"originX",flip:"flipX"},y:{counterAxis:"x",scale:u,skew:x,lockSkewing:"lockSkewingY",origin:"originY",flip:"flipY"}},j=["ns","nesw","ew","nwse"],X=(e,i,n)=>{if(0!==i.x&&o(n,"lockSkewingY"))return m;if(0!==i.y&&o(n,"lockSkewingX"))return m;const s=c(n,i)%4;return"".concat(j[s],"-resize")};function y(m,c,p,u,x){const{target:j}=p,{counterAxis:X,origin:y,lockSkewing:h,skew:Y,flip:_}=S[m];if(o(j,h))return!1;const{origin:v,flip:D}=S[X],b=n(p[v])*(j[D]?-1:1),A=-Math.sign(b)*(j[_]?-1:1),M=.5*-((0===j[Y]&&a(p,w,w,u,x)[m]>0||j[Y]>0?1:-1)*A)+.5,T=l(f,g(((e,n,o,c)=>function(e,n,o){let{target:m,ex:c,ey:a,skewingSide:l}=n,g=i(n,d);const{skew:w}=S[e],f=o.subtract(new s(c,a)).divide(new s(m.scaleX,m.scaleY))[e],p=m[w],u=g[w],x=Math.tan(t(u)),j="y"===e?m._getTransformedDimensions({scaleX:1,scaleY:1,skewX:0}).x:m._getTransformedDimensions({scaleX:1,scaleY:1}).y,X=2*f*l/Math.max(j,1)+x,y=r(Math.atan(X));m.set(w,y);const h=p!==m[w];if(h&&"y"===e){const{skewX:e,scaleX:i}=m,n=m._getTransformedDimensions({skewY:p}),s=m._getTransformedDimensions(),r=0!==e?n.x/s.x:1;1!==r&&m.set(k,r*i)}return h}(m,n,new s(o,c)))));return T(c,e(e({},p),{},{[y]:M,skewingSide:A}),u,x)}const h=(e,i,n,s)=>y("x",e,i,n,s),Y=(e,i,n,s)=>y("y",e,i,n,s);export{X as skewCursorStyleHandler,h as skewHandlerX,Y as skewHandlerY};
|
|
2
2
|
//# sourceMappingURL=skew.min.mjs.map
|