UNPKG

@visactor/vrender-animate

Version:

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

69 lines (65 loc) 3.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.AnimateExtension = void 0; const animate_1 = require("./animate"), timeline_1 = require("./timeline"), default_ticker_1 = require("./ticker/default-ticker"), animate_executor_1 = require("./executor/animate-executor"); class AnimateExtension { getAttributes(final = !1) { return final && this.finalAttribute ? this.finalAttribute : this.attribute; } animate(params) { var _a, _b, _c; const animate = new animate_1.Animate(null == params ? void 0 : params.id, null !== (_b = null !== (_a = null == params ? void 0 : params.timeline) && void 0 !== _a ? _a : this.stage && this.stage.getTimeline()) && void 0 !== _b ? _b : timeline_1.defaultTimeline, null == params ? void 0 : params.slience); if (animate.bind(this), params) { const {onStart: onStart, onEnd: onEnd, onRemove: onRemove} = params; null != onStart && animate.onStart(onStart), null != onEnd && animate.onEnd(onEnd), null != onRemove && animate.onRemove(onRemove); } return null === (_c = this.stage) || void 0 === _c || _c.ticker.start(), animate; } createTimeline() { return new timeline_1.DefaultTimeline; } createTicker(stage) { return new default_ticker_1.DefaultTicker(stage); } setFinalAttributes(finalAttribute) { this.finalAttribute || (this.finalAttribute = {}), Object.assign(this.finalAttribute, finalAttribute); } initFinalAttributes(finalAttribute) { this.finalAttribute = finalAttribute; } initAnimateExecutor() { this._animateExecutor || (this._animateExecutor = new animate_executor_1.AnimateExecutor(this)); } executeAnimation(config) { return this.initAnimateExecutor(), this._animateExecutor.execute(config), this; } executeAnimations(configs) { return this.initAnimateExecutor(), configs.forEach((config => { this._animateExecutor.execute(config); })), this; } getFinalAttribute() { return this.finalAttribute; } getGraphicAttribute(key, prev = !1) { return !prev && this.finalAttribute ? this.finalAttribute[key] : this.attribute[key]; } pauseAnimation(deep = !1) { this.animates && this.animates.forEach((animate => animate.pause())), deep && this.isContainer && this.forEachChildren((child => { child.pauseAnimation(deep); })); } resumeAnimation(deep = !1) { this.animates && this.animates.forEach((animate => animate.resume())), deep && this.isContainer && this.forEachChildren((child => { child.resumeAnimation(deep); })); } stopAnimation(deep = !1) { this.animates && this.animates.forEach((animate => animate.stop())), deep && this.isContainer && this.forEachChildren((child => { child.stopAnimation(deep); })); } } exports.AnimateExtension = AnimateExtension;