Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed May 2, 2024
1 parent d3e5cc3 commit e29076e
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/canvas/SelectableCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,20 +568,21 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents>
}

/**
* @private
* Setup state used by the canvas to execute object transforms via the control API
* @param {Event} e Event object
* @param {FabricObject} target
* @param {boolean} [alreadySelected] pass true to setup the active control
* @param [transformContext] pass {@link FabricObject.findControl}, `{ key: 'drag' }` to setup dragging
* or undefined to block transforming
*/
setupCurrentTransform(
e: TPointerEvent,
target: FabricObject,
controlContext?:
transformContext?:
| { key: string; control: Control }
| { key: 'drag'; control?: never }
): Transform {
const key = controlContext?.key || '';
const control = controlContext?.control;
const key = transformContext?.key || '';
const control = transformContext?.control;
const action = control?.getActionName(e, control, target) ?? key,
altKey = e[this.centeredKey as ModifierKey],
origin = this._shouldCenterTransform(target, action, altKey)
Expand All @@ -604,9 +605,7 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents>
target: target,
action,
actionHandler: control
? control
.getActionHandler(e, target, controlContext.control)
?.bind(controlContext.control)
? control.getActionHandler(e, target, control)?.bind(control)
: key === 'drag'
? dragHandler
: undefined,
Expand Down Expand Up @@ -639,6 +638,28 @@ export class SelectableCanvas<EventSpec extends CanvasEvents = CanvasEvents>
return (this._currentTransform = transform);
}

/**
* @deprecated use {@link setupCurrentTransform} and fire your own `before:transform` event if you need to
* @param {Event} e Event object
* @param {FabricObject} target
* @param {boolean} [activateControl] pass true to setup the active control
*/
_setupCurrentTransform(
e: TPointerEvent,
target: FabricObject,
activateControl: boolean
) {
const transform = this.setupCurrentTransform(
e,
target,
(activateControl &&
target.findControl(this.getViewportPoint(e), isTouchEvent(e))) || {
key: 'drag',
}
);
this.fire('before:transform', { e, transform });
}

/**
* Set the cursor type of the canvas element
* @param {String} value Cursor type of the canvas element.
Expand Down

0 comments on commit e29076e

Please sign in to comment.