UNPKG

@visactor/vrender-animate

Version:

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

82 lines (78 loc) 3.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.AnimateExtension = void 0; const constant_1 = require("@visactor/vrender-core/event/constant"), animate_1 = require("./animate"), timeline_1 = require("./timeline"), default_ticker_1 = require("./ticker/default-ticker"), animate_executor_1 = require("./executor/animate-executor"); class AnimateExtension { visitTrackedAnimates(cb) { this.forEachTrackedAnimate(cb); } 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)); } applyFinalAttributeToAttribute() { const finalAttribute = this.getFinalAttribute(); if (!finalAttribute) return; this.setAttributesAndPreventAnimate(finalAttribute, !1, { type: constant_1.AttributeUpdateType.ANIMATE_BIND }); } restoreStaticAttribute(excludedKeys) { this._restoreAttributeFromStaticTruth({ type: constant_1.AttributeUpdateType.ANIMATE_END }, excludedKeys); } executeAnimation(config) { return this.initAnimateExecutor(), this._animateExecutor.execute(config), this; } executeAnimations(configs) { return this.initAnimateExecutor(), this._animateExecutor.execute(configs), this; } getFinalAttribute() { return this.finalAttribute; } getGraphicAttribute(key, prev = !1) { return !prev && this.finalAttribute ? this.finalAttribute[key] : this.attribute[key]; } pauseAnimation(deep = !1) { this.visitTrackedAnimates((animate => animate.pause())), deep && this.isContainer && this.forEachChildren((child => { child.pauseAnimation(deep); })); } resumeAnimation(deep = !1) { this.visitTrackedAnimates((animate => animate.resume())), deep && this.isContainer && this.forEachChildren((child => { child.resumeAnimation(deep); })); } stopAnimation(deep = !1) { this.visitTrackedAnimates((animate => animate.stop())), deep && this.isContainer && this.forEachChildren((child => { child.stopAnimation(deep); })); } } exports.AnimateExtension = AnimateExtension;