@visactor/vrender-animate
Version:
This module provides a graph-based animation system for VRender.
147 lines (137 loc) • 6.49 kB
JavaScript
import { isNil, isNumber, isValid } from "@visactor/vutils";
import { ACustomAnimate } from "./custom-animate";
import { applyAnimationFrameNumberAttributes, applyAppearStartAttributes } from "./transient";
function growWidthInIndividual(graphic, options, animationParameters) {
const attrs = graphic.getFinalAttribute(), x = attrs.x, x1 = attrs.x1, width = attrs.width;
if (options && "negative" === options.orient) {
const computedX1 = isValid(width) ? Math.max(x, x + width) : Math.max(x, x1);
return {
from: {
x: computedX1,
x1: isNil(x1) ? void 0 : computedX1,
width: isNil(width) ? void 0 : 0
},
to: {
x: x,
x1: x1,
width: width
}
};
}
const computedX = isValid(width) ? Math.min(x, x + width) : Math.min(x, x1);
return {
from: {
x: computedX,
x1: isNil(x1) ? void 0 : computedX,
width: isNil(width) ? void 0 : 0
},
to: {
x: x,
x1: x1,
width: width
}
};
}
function growWidthInOverall(graphic, options, animationParameters) {
var _a;
const attrs = graphic.getFinalAttribute(), x = attrs.x, x1 = attrs.x1, width = attrs.width;
let overallValue;
return options && "negative" === options.orient ? isNumber(options.overall) ? overallValue = options.overall : animationParameters.group ? (overallValue = null !== (_a = animationParameters.groupWidth) && void 0 !== _a ? _a : animationParameters.group.getBounds().width(),
animationParameters.groupWidth = overallValue) : overallValue = animationParameters.width : overallValue = isNumber(null == options ? void 0 : options.overall) ? null == options ? void 0 : options.overall : 0,
{
from: {
x: overallValue,
x1: isNil(x1) ? void 0 : overallValue,
width: isNil(width) ? void 0 : 0
},
to: {
x: x,
x1: x1,
width: width
}
};
}
const growWidthIn = (graphic, options, animationParameters) => {
var _a;
return !1 !== (null !== (_a = null == options ? void 0 : options.overall) && void 0 !== _a && _a) ? growWidthInOverall(graphic, options, animationParameters) : growWidthInIndividual(graphic, options, animationParameters);
};
function growWidthOutIndividual(graphic, options, animationParameters) {
const attrs = graphic.getFinalAttribute(), x = attrs.x, x1 = attrs.x1, width = attrs.width;
if (options && "negative" === options.orient) {
const computedX1 = isValid(width) ? Math.max(x, x + width) : Math.max(x, x1);
return {
to: {
x: computedX1,
x1: isNil(x1) ? void 0 : computedX1,
width: isNil(width) ? void 0 : 0
}
};
}
const computedX = isValid(width) ? Math.min(x, x + width) : Math.min(x, x1);
return {
to: {
x: computedX,
x1: isNil(x1) ? void 0 : computedX,
width: isNil(width) ? void 0 : 0
}
};
}
function growWidthOutOverall(graphic, options, animationParameters) {
var _a;
const attrs = graphic.getFinalAttribute(), x1 = attrs.x1, width = attrs.width;
let overallValue;
return options && "negative" === options.orient ? isNumber(options.overall) ? overallValue = options.overall : animationParameters.group ? (overallValue = null !== (_a = animationParameters.groupWidth) && void 0 !== _a ? _a : animationParameters.group.getBounds().width(),
animationParameters.groupWidth = overallValue) : overallValue = animationParameters.width : overallValue = isNumber(null == options ? void 0 : options.overall) ? options.overall : 0,
{
to: {
x: overallValue,
x1: isNil(x1) ? void 0 : overallValue,
width: isNil(width) ? void 0 : 0
}
};
}
export const growWidthOut = (graphic, options, animationParameters) => {
var _a;
return !1 !== (null !== (_a = null == options ? void 0 : options.overall) && void 0 !== _a && _a) ? growWidthOutOverall(graphic, options, animationParameters) : growWidthOutIndividual(graphic, options, animationParameters);
};
export class GrowWidthIn extends ACustomAnimate {
constructor(from, to, duration, easing, params) {
super(from, to, duration, easing, params);
}
onBind() {
var _a, _b, _c;
super.onBind();
const {from: from, to: to} = growWidthIn(this.target, this.params.options, this.params), fromAttrs = null !== (_b = null === (_a = this.target.context) || void 0 === _a ? void 0 : _a.lastAttrs) && void 0 !== _b ? _b : from;
this.props = to, this.propKeys = Object.keys(to).filter((key => null != to[key])),
this.from = fromAttrs, this.to = to, this.target.applyFinalAttributeToAttribute(),
!1 !== (null === (_c = this.params.controlOptions) || void 0 === _c ? void 0 : _c.immediatelyApply) && applyAppearStartAttributes(this.target, fromAttrs);
}
onEnd(cb) {
super.onEnd(cb);
}
onUpdate(end, ratio, out) {
applyAnimationFrameNumberAttributes(this.target, this.propKeys, this.from, this.to, ratio),
this.target.addUpdatePositionTag(), this.target.addUpdateShapeAndBoundsTag();
}
}
export class GrowWidthOut extends ACustomAnimate {
constructor(from, to, duration, easing, params) {
super(from, to, duration, easing, params);
}
onBind() {
super.onBind();
const {from: from, to: to} = (graphic = this.target, options = this.params.options,
animationParameters = this.params, !1 !== (null !== (_a = null == options ? void 0 : options.overall) && void 0 !== _a && _a) ? growWidthOutOverall(graphic, options, animationParameters) : growWidthOutIndividual(graphic, options, animationParameters));
var graphic, options, animationParameters, _a;
this.props = to, this.propKeys = Object.keys(to).filter((key => null != to[key])),
this.from = null != from ? from : this.target.attribute, this.to = to;
}
onEnd(cb) {
super.onEnd(cb);
}
onUpdate(end, ratio, out) {
applyAnimationFrameNumberAttributes(this.target, this.propKeys, this.from, this.to, ratio),
this.target.addUpdatePositionTag(), this.target.addUpdateShapeAndBoundsTag();
}
}
//# sourceMappingURL=growWidth.js.map