UNPKG

@visactor/vrender-animate

Version:

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

27 lines (25 loc) 1.5 kB
import { ACustomAnimate } from "./custom-animate"; import { applyAnimationFrameAttributes } from "./transient"; export class MotionPath extends 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) : (applyAnimationFrameAttributes(this.target, attrs), this.target.addUpdatePositionTag(), this.target.addUpdateShapeAndBoundsTag()); } } //# sourceMappingURL=motionPath.js.map