@visactor/vrender-animate
Version:
This module provides a graph-based animation system for VRender.
146 lines (136 loc) • 8.32 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.ClipDirectionAnimate = exports.ClipRadiusAnimate = exports.ClipAngleAnimate = exports.ClipGraphicAnimate = void 0;
const vrender_core_1 = require("@visactor/vrender-core"), custom_animate_1 = require("./custom-animate");
class ClipGraphicAnimate extends custom_animate_1.ACustomAnimate {
constructor(from, to, duration, easing, params) {
super(null, {}, duration, easing, params), this.clipFromAttribute = from, this.clipToAttribute = to,
this._group = null == params ? void 0 : params.group, this._clipGraphic = null == params ? void 0 : params.clipGraphic;
}
onBind() {
super.onBind(), this._group && this._clipGraphic && (this._lastClip = this._group.attribute.clip,
this._lastPath = this._group.attribute.path, this._group.setAttributes({
clip: !0,
path: [ this._clipGraphic ]
}, !1, {
type: vrender_core_1.AttributeUpdateType.ANIMATE_BIND
}));
}
onEnd() {
this._group && this._group.setAttributes({
clip: this._lastClip,
path: this._lastPath
}, !1, {
type: vrender_core_1.AttributeUpdateType.ANIMATE_END
});
}
onUpdate(end, ratio, out) {
if (!this._clipGraphic) return;
const res = {};
Object.keys(this.clipFromAttribute).forEach((k => {
res[k] = this.clipFromAttribute[k] + (this.clipToAttribute[k] - this.clipFromAttribute[k]) * ratio;
})), this._clipGraphic.setAttributes(res, !1, {
type: vrender_core_1.AttributeUpdateType.ANIMATE_UPDATE,
animationState: {
ratio: ratio,
end: end
}
});
}
}
exports.ClipGraphicAnimate = ClipGraphicAnimate;
class ClipAngleAnimate extends ClipGraphicAnimate {
constructor(from, to, duration, easing, params) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
const groupAttribute = null !== (_b = null === (_a = null == params ? void 0 : params.group) || void 0 === _a ? void 0 : _a.attribute) && void 0 !== _b ? _b : {}, width = null !== (_c = groupAttribute.width) && void 0 !== _c ? _c : 0, height = null !== (_d = groupAttribute.height) && void 0 !== _d ? _d : 0, animationType = null !== (_e = null == params ? void 0 : params.animationType) && void 0 !== _e ? _e : "in", startAngle = null !== (_f = null == params ? void 0 : params.startAngle) && void 0 !== _f ? _f : 0, orient = null !== (_g = null == params ? void 0 : params.orient) && void 0 !== _g ? _g : "clockwise";
let arcStartAngle = 0, arcEndAngle = 0;
"anticlockwise" === orient ? (arcEndAngle = "in" === animationType ? startAngle + 2 * Math.PI : startAngle,
arcEndAngle = startAngle + 2 * Math.PI) : (arcStartAngle = startAngle, arcEndAngle = "out" === animationType ? startAngle + 2 * Math.PI : startAngle);
const arc = vrender_core_1.application.graphicService.creator.arc({
x: null !== (_j = null === (_h = null == params ? void 0 : params.center) || void 0 === _h ? void 0 : _h.x) && void 0 !== _j ? _j : width / 2,
y: null !== (_l = null === (_k = null == params ? void 0 : params.center) || void 0 === _k ? void 0 : _k.y) && void 0 !== _l ? _l : height / 2,
outerRadius: null !== (_m = null == params ? void 0 : params.radius) && void 0 !== _m ? _m : (width + height) / 2,
innerRadius: 0,
startAngle: arcStartAngle,
endAngle: arcEndAngle,
fill: !0
});
let fromAttributes, toAttributes;
"anticlockwise" === orient ? (fromAttributes = {
startAngle: startAngle + 2 * Math.PI
}, toAttributes = {
startAngle: startAngle
}) : (fromAttributes = {
endAngle: startAngle
}, toAttributes = {
endAngle: startAngle + 2 * Math.PI
}), super("in" === animationType ? fromAttributes : toAttributes, "in" === animationType ? toAttributes : fromAttributes, duration, easing, {
group: null == params ? void 0 : params.group,
clipGraphic: arc
});
}
}
exports.ClipAngleAnimate = ClipAngleAnimate;
class ClipRadiusAnimate extends ClipGraphicAnimate {
constructor(from, to, duration, easing, params) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
const groupAttribute = null !== (_b = null === (_a = null == params ? void 0 : params.group) || void 0 === _a ? void 0 : _a.attribute) && void 0 !== _b ? _b : {}, width = null !== (_c = groupAttribute.width) && void 0 !== _c ? _c : 0, height = null !== (_d = groupAttribute.height) && void 0 !== _d ? _d : 0, animationType = null !== (_e = null == params ? void 0 : params.animationType) && void 0 !== _e ? _e : "in", startRadius = null !== (_f = null == params ? void 0 : params.startRadius) && void 0 !== _f ? _f : 0, endRadius = null !== (_g = null == params ? void 0 : params.endRadius) && void 0 !== _g ? _g : Math.sqrt((width / 2) ** 2 + (height / 2) ** 2), arc = vrender_core_1.application.graphicService.creator.arc({
x: null !== (_j = null === (_h = null == params ? void 0 : params.center) || void 0 === _h ? void 0 : _h.x) && void 0 !== _j ? _j : width / 2,
y: null !== (_l = null === (_k = null == params ? void 0 : params.center) || void 0 === _k ? void 0 : _k.y) && void 0 !== _l ? _l : height / 2,
outerRadius: "out" === animationType ? endRadius : startRadius,
innerRadius: 0,
startAngle: 0,
endAngle: 2 * Math.PI,
fill: !0
}), fromAttributes = {
outerRadius: startRadius
}, toAttributes = {
outerRadius: endRadius
};
super("in" === animationType ? fromAttributes : toAttributes, "in" === animationType ? toAttributes : fromAttributes, duration, easing, {
group: null == params ? void 0 : params.group,
clipGraphic: arc
});
}
}
exports.ClipRadiusAnimate = ClipRadiusAnimate;
class ClipDirectionAnimate extends ClipGraphicAnimate {
constructor(from, to, duration, easing, params) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
const groupAttribute = null !== (_b = null === (_a = null == params ? void 0 : params.group) || void 0 === _a ? void 0 : _a.attribute) && void 0 !== _b ? _b : {}, width = null !== (_d = null !== (_c = null == params ? void 0 : params.width) && void 0 !== _c ? _c : groupAttribute.width) && void 0 !== _d ? _d : 0, height = null !== (_f = null !== (_e = null == params ? void 0 : params.height) && void 0 !== _e ? _e : groupAttribute.height) && void 0 !== _f ? _f : 0, animationType = null !== (_g = null == params ? void 0 : params.animationType) && void 0 !== _g ? _g : "in", direction = null !== (_h = null == params ? void 0 : params.direction) && void 0 !== _h ? _h : "x", orient = null !== (_j = null == params ? void 0 : params.orient) && void 0 !== _j ? _j : "positive", rect = vrender_core_1.application.graphicService.creator.rect({
x: 0,
y: 0,
width: "in" === animationType && "x" === direction ? 0 : width,
height: "in" === animationType && "y" === direction ? 0 : height,
fill: !0
});
let fromAttributes = {}, toAttributes = {};
"y" === direction ? "negative" === orient ? (fromAttributes = {
y: height,
height: 0
}, toAttributes = {
y: 0,
height: height
}) : (fromAttributes = {
height: 0
}, toAttributes = {
height: height
}) : "negative" === orient ? (fromAttributes = {
x: width,
width: 0
}, toAttributes = {
x: 0,
width: width
}) : (fromAttributes = {
width: 0
}, toAttributes = {
width: width
}), super("in" === animationType ? fromAttributes : toAttributes, "in" === animationType ? toAttributes : fromAttributes, duration, easing, {
group: null == params ? void 0 : params.group,
clipGraphic: rect
});
}
}
exports.ClipDirectionAnimate = ClipDirectionAnimate;
//# sourceMappingURL=clip-graphic.js.map