UNPKG

@visactor/vrender-animate

Version:

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

56 lines (52 loc) 2.72 kB
import { AttributeUpdateType } from "@visactor/vrender-core/event/constant"; import { ACustomAnimate } from "./custom-animate"; import { applyAnimationFrameAttributes, applyAnimationTransientAttributes, applyAppearStartAttributes } from "./transient"; export class CommonIn extends ACustomAnimate { constructor(from, to, duration, easing, params) { super(from, to, duration, easing, params); } onBind() { var _a, _b, _c; super.onBind(); const attrs = this.target.getFinalAttribute(), fromAttrs = null !== (_a = this.target.attribute) && void 0 !== _a ? _a : {}, to = {}, from = null !== (_b = this.from) && void 0 !== _b ? _b : {}; this.keys.forEach((key => { var _a, _b, _c; to[key] = null !== (_a = null == attrs ? void 0 : attrs[key]) && void 0 !== _a ? _a : 1, from[key] = null !== (_c = null !== (_b = from[key]) && void 0 !== _b ? _b : fromAttrs[key]) && void 0 !== _c ? _c : 0; })), this.target.applyFinalAttributeToAttribute(), this.props = to, this.propKeys = this.keys, this.from = from, this.to = to, !1 !== (null === (_c = this.params.controlOptions) || void 0 === _c ? void 0 : _c.immediatelyApply) && applyAppearStartAttributes(this.target, from); } 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 CommonOut extends ACustomAnimate { constructor(from, to, duration, easing, params) { super(from, to, duration, easing, params); } onBind() { super.onBind(); const attrs = this.target.attribute, to = {}, from = {}; this.keys.forEach((key => { var _a; to[key] = 0, from[key] = null !== (_a = attrs[key]) && void 0 !== _a ? _a : 1; })), this.props = to, this.propKeys = this.keys, this.from = from, this.to = to, applyAnimationTransientAttributes(this.target, from, AttributeUpdateType.ANIMATE_BIND), this.target.addUpdatePositionTag(), this.target.addUpdateBoundTag(); } onEnd(cb) { super.onEnd(cb); } 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(); } } //# sourceMappingURL=common.js.map