UNPKG

@visactor/vrender-animate

Version:

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

31 lines (27 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.MotionPath = void 0; const custom_animate_1 = require("./custom-animate"); class MotionPath extends custom_animate_1.ACustomAnimate { constructor(from, to, duration, easing, params) { var _a; super(from, to, duration, easing, params), params && (this.pathLength = params.path.getLength(), this.path = params.path, this.distance = params.distance, this.totalLength = this.distance * this.pathLength, this.initAngle = null !== (_a = params.initAngle) && void 0 !== _a ? _a : 0, this.changeAngle = !!params.changeAngle, this.cb = params.cb); } onBind() { this.from = { x: 0, y: 0 }, this.to = this.path.getAttrAt(this.totalLength).pos, this.props = this.to; } onUpdate(end, ratio, out) { const attrs = {}, at = this.totalLength * ratio, {pos: pos, angle: angle} = this.path.getAttrAt(at); attrs.x = pos.x, attrs.y = pos.y, this.changeAngle && (attrs.angle = angle + this.initAngle), this.cb && this.cb(this.from, this.to, ratio, this.target), this.target.setAttributes(attrs); } } exports.MotionPath = MotionPath; //# sourceMappingURL=motionPath.js.map