-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(): BREAKING Animation removing byValue, removing fxStraigthe…
…nand '+=' syntax (#8547) Co-authored-by: ShaMan123 <[email protected]>
- Loading branch information
Showing
17 changed files
with
274 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// @ts-nocheck | ||
import { noop } from '../constants'; | ||
import { FabricObject } from '../shapes/Object/FabricObject'; | ||
import { TDegree } from '../typedefs'; | ||
import { animate } from '../util/animation/animate'; | ||
|
||
Object.assign(FabricObject.prototype, { | ||
/** | ||
* @private | ||
* @return {Number} angle value | ||
*/ | ||
_getAngleValueForStraighten(this: FabricObject) { | ||
const angle = this.angle % 360; | ||
if (angle > 0) { | ||
return Math.round((angle - 1) / 90) * 90; | ||
} | ||
return Math.round(angle / 90) * 90; | ||
}, | ||
|
||
/** | ||
* Straightens an object (rotating it from current angle to one of 0, 90, 180, 270, etc. depending on which is closer) | ||
*/ | ||
straighten(this: FabricObject) { | ||
this.rotate(this._getAngleValueForStraighten()); | ||
}, | ||
|
||
/** | ||
* Same as {@link straighten} but with animation | ||
* @param {Object} callbacks Object with callback functions | ||
* @param {Function} [callbacks.onComplete] Invoked on completion | ||
* @param {Function} [callbacks.onChange] Invoked on every step of animation | ||
*/ | ||
fxStraighten( | ||
this: FabricObject, | ||
callbacks: { | ||
onChange?(value: TDegree): any; | ||
onComplete?(): any; | ||
} = {} | ||
) { | ||
const onComplete = callbacks.onComplete || noop, | ||
onChange = callbacks.onChange || noop; | ||
|
||
return animate({ | ||
target: this, | ||
startValue: this.angle, | ||
endValue: this._getAngleValueForStraighten(), | ||
duration: this.FX_DURATION, | ||
onChange: (value: TDegree) => { | ||
this.rotate(value); | ||
onChange(value); | ||
}, | ||
onComplete: () => { | ||
this.setCoords(); | ||
onComplete(); | ||
}, | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.