UNPKG

@visactor/vrender-animate

Version:

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

42 lines (39 loc) 2.02 kB
import { AttributeUpdateType } from "@visactor/vrender-core/event/constant"; import { ACustomAnimate } from "./custom-animate"; import { applyAnimationTransientAttributes } from "./transient"; export class FromTo extends ACustomAnimate { constructor(from, to, duration, easing, params) { super(from, to, duration, easing, params), this.from = null != from ? from : {}; } applyTransientFromAttributes() { applyAnimationTransientAttributes(this.target, this.from, AttributeUpdateType.ANIMATE_START); } onBind() { var _a, _b, _c; super.onBind(), Object.keys(this.from).forEach((key => { null == this.props[key] && (this.props[key] = this.target.getGraphicAttribute(key)); })), "appear" === (null === (_a = this.target.context) || void 0 === _a ? void 0 : _a.animationState) && this.target.applyFinalAttributeToAttribute(), !1 !== (null === (_c = null === (_b = this.params) || void 0 === _b ? void 0 : _b.controlOptions) || void 0 === _c ? void 0 : _c.immediatelyApply) && this.applyTransientFromAttributes(); } onFirstRun() { this.from = Object.assign(Object.assign({}, this.getLastProps()), this.from); const startProps = this.animate.getStartProps(); this.propKeys && this.propKeys.forEach((key => { var _a; this.from[key] = null !== (_a = this.from[key]) && void 0 !== _a ? _a : startProps[key]; })), this.applyTransientFromAttributes(); } deleteSelfAttr(key) { this.deleteSelfAttrs([ key ]); } deleteSelfAttrs(keys) { super.deleteSelfAttrs(keys), this.from = this.removeKeysFromRecord(this.from, keys); } update(end, ratio, out) { if (this.onStart(), !this.props || !this.propKeys) return; const easedRatio = this.easing(ratio); this.runInterpolateUpdate(this.from, this.props, easedRatio), this.onUpdate(end, easedRatio, out), this.syncAttributeUpdate(); } } //# sourceMappingURL=fromTo.js.map