UNPKG

@visactor/vrender-animate

Version:

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

34 lines (30 loc) 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.MotionPath = void 0; const custom_animate_1 = require("./custom-animate"), transient_1 = require("./transient"); class MotionPath extends custom_animate_1.ACustomAnimate { constructor(from, to, duration, easing, params) { var _a, _b, _c; 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.commitOnEnd = null === (_c = null !== (_b = params.commitOnEnd) && void 0 !== _b ? _b : params.saveOnEnd) || void 0 === _c || _c, 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), end && this.commitOnEnd ? this.target.setAttributes(attrs) : ((0, transient_1.applyAnimationFrameAttributes)(this.target, attrs), this.target.addUpdatePositionTag(), this.target.addUpdateShapeAndBoundsTag()); } } exports.MotionPath = MotionPath; //# sourceMappingURL=motionPath.js.map