UNPKG

@visactor/vrender-animate

Version:

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

45 lines (41 loc) 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.FromTo = void 0; const custom_animate_1 = require("./custom-animate"); class FromTo extends custom_animate_1.ACustomAnimate { constructor(from, to, duration, easing, params) { super(from, to, duration, easing, params), this.from = null != from ? from : {}; } onBind() { var _a, _b; super.onBind(), Object.keys(this.from).forEach((key => { null == this.props[key] && (this.props[key] = this.target.getGraphicAttribute(key)); })); const finalAttribute = this.target.getFinalAttribute(); "appear" === (null === (_a = this.target.context) || void 0 === _a ? void 0 : _a.animationState) && finalAttribute && this.target.setAttributes(finalAttribute), !1 !== (null === (_b = this.params.controlOptions) || void 0 === _b ? void 0 : _b.immediatelyApply) && this.target.setAttributes(this.from); } 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.target.setAttributes(this.from); } deleteSelfAttr(key) { super.deleteSelfAttr(key), delete this.from[key]; } update(end, ratio, out) { if (this.onStart(), !this.props || !this.propKeys) return; const easedRatio = this.easing(ratio); this.animate.interpolateUpdateFunction ? this.animate.interpolateUpdateFunction(this.from, this.props, easedRatio, this, this.target) : this.interpolateUpdateFunctions.forEach(((func, index) => { if (!this.animate.validAttr(this.propKeys[index])) return; const key = this.propKeys[index]; func(key, this.from[key], this.props[key], easedRatio, this, this.target); })), this.onUpdate(end, easedRatio, out), this.syncAttributeUpdate(); } } exports.FromTo = FromTo; //# sourceMappingURL=fromTo.js.map