@visactor/vrender-animate
Version:
This module provides a graph-based animation system for VRender.
82 lines (77 loc) • 3.33 kB
JavaScript
import { AttributeUpdateType } from "@visactor/vrender-core/event/constant";
import { Animate } from "./animate";
import { DefaultTimeline, defaultTimeline } from "./timeline";
import { DefaultTicker } from "./ticker/default-ticker";
import { AnimateExecutor } from "./executor/animate-executor";
export 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(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 : 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 DefaultTimeline;
}
createTicker(stage) {
return new DefaultTicker(stage);
}
setFinalAttributes(finalAttribute) {
this.finalAttribute || (this.finalAttribute = {}), Object.assign(this.finalAttribute, finalAttribute);
}
initFinalAttributes(finalAttribute) {
this.finalAttribute = finalAttribute;
}
initAnimateExecutor() {
this._animateExecutor || (this._animateExecutor = new AnimateExecutor(this));
}
applyFinalAttributeToAttribute() {
const finalAttribute = this.getFinalAttribute();
if (!finalAttribute) return;
this.setAttributesAndPreventAnimate(finalAttribute, !1, {
type: AttributeUpdateType.ANIMATE_BIND
});
}
restoreStaticAttribute(excludedKeys) {
this._restoreAttributeFromStaticTruth({
type: 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);
}));
}
}