UNPKG

@visactor/vrender-animate

Version:

This module provides a graph-based animation system for VRender.

67 lines (60 loc) 2.85 kB
import { isNumberClose, isValidNumber } from "@visactor/vutils"; import { ACustomAnimate } from "./custom-animate"; import { applyAnimationFrameAttributes, applyAppearStartAttributes } from "./transient"; export const rotateIn = (graphic, options) => { var _a; const attributeAngle = null !== (_a = graphic.getFinalAttribute().angle) && void 0 !== _a ? _a : 0; let angle = 0; return angle = isNumberClose(attributeAngle / (2 * Math.PI), 0) ? Math.round(attributeAngle / (2 * Math.PI)) * Math.PI * 2 : isValidNumber(null == options ? void 0 : options.angle) ? options.angle : "anticlockwise" === (null == options ? void 0 : options.orient) ? Math.ceil(attributeAngle / (2 * Math.PI)) * Math.PI * 2 : Math.floor(attributeAngle / (2 * Math.PI)) * Math.PI * 2, { from: { angle: angle }, to: { angle: attributeAngle } }; }; export const rotateOut = (graphic, options) => { var _a; const finalAngle = null !== (_a = graphic.getFinalAttribute().angle) && void 0 !== _a ? _a : 0; let angle = 0; return angle = isNumberClose(finalAngle / (2 * Math.PI), 0) ? Math.round(finalAngle / (2 * Math.PI)) * Math.PI * 2 : isValidNumber(null == options ? void 0 : options.angle) ? options.angle : "anticlockwise" === (null == options ? void 0 : options.orient) ? Math.ceil(finalAngle / (2 * Math.PI)) * Math.PI * 2 : Math.floor(finalAngle / (2 * Math.PI)) * Math.PI * 2, { from: { angle: finalAngle }, to: { angle: angle } }; }; export class RotateBase extends ACustomAnimate { constructor(from, to, duration, easing, params) { super(from, to, duration, easing, params); } onUpdate(end, ratio, out) { const attrs = {}; this.propKeys.forEach((key => { attrs[key] = this.from[key] + (this.to[key] - this.from[key]) * ratio; })), applyAnimationFrameAttributes(this.target, attrs), this.target.addUpdatePositionTag(), this.target.addUpdateShapeAndBoundsTag(); } } export class RotateIn extends RotateBase { onBind() { var _a; super.onBind(); const {from: from, to: to} = rotateIn(this.target, this.params.options); this.props = to, this.propKeys = [ "angle" ], this.from = from, this.to = to, this.target.applyFinalAttributeToAttribute(), !1 !== (null === (_a = this.params.controlOptions) || void 0 === _a ? void 0 : _a.immediatelyApply) && applyAppearStartAttributes(this.target, from); } } export class RotateOut extends RotateBase { onBind() { super.onBind(); const {from: from, to: to} = rotateOut(this.target, this.params.options); this.props = to, this.propKeys = [ "angle" ], this.from = from, this.to = to; } } //# sourceMappingURL=rotate.js.map