@visactor/vrender-animate
Version:
This module provides a graph-based animation system for VRender.
67 lines (63 loc) • 2.82 kB
JavaScript
import { Animate } from "./animate";
import { DefaultTimeline, defaultTimeline } from "./timeline";
import { DefaultTicker } from "./ticker/default-ticker";
import { AnimateExecutor } from "./executor/animate-executor";
export class AnimateExtension {
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));
}
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);
}));
}
}