@visactor/vrender-animate
Version:
This module provides a graph-based animation system for VRender.
133 lines (123 loc) • 6.29 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.ScaleOut = exports.ScaleIn = void 0;
const custom_animate_1 = require("./custom-animate"), transient_1 = require("./transient");
class ScaleIn extends custom_animate_1.ACustomAnimate {
constructor(from, to, duration, easing, params) {
super(from, to, duration, easing, params);
}
onBind() {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
let from, to;
super.onBind();
const attrs = this.target.getFinalAttribute(), fromAttrs = null !== (_a = this.target.attribute) && void 0 !== _a ? _a : {}, options = null === (_b = this.params) || void 0 === _b ? void 0 : _b.options, direction = null !== (_d = null === (_c = this.params) || void 0 === _c ? void 0 : _c.direction) && void 0 !== _d ? _d : null == options ? void 0 : options.direction, fromScaleX = null !== (_j = null !== (_g = null !== (_f = null === (_e = this.params) || void 0 === _e ? void 0 : _e.fromScaleX) && void 0 !== _f ? _f : null == options ? void 0 : options.fromScaleX) && void 0 !== _g ? _g : null === (_h = this.params) || void 0 === _h ? void 0 : _h.fromScale) && void 0 !== _j ? _j : null == options ? void 0 : options.fromScale, fromScaleY = null !== (_p = null !== (_m = null !== (_l = null === (_k = this.params) || void 0 === _k ? void 0 : _k.fromScaleY) && void 0 !== _l ? _l : null == options ? void 0 : options.fromScaleY) && void 0 !== _m ? _m : null === (_o = this.params) || void 0 === _o ? void 0 : _o.fromScale) && void 0 !== _p ? _p : null == options ? void 0 : options.fromScale;
switch (direction) {
case "x":
from = {
scaleX: null !== (_q = null != fromScaleX ? fromScaleX : fromAttrs.scaleX) && void 0 !== _q ? _q : 0
}, to = {
scaleX: null !== (_r = null == attrs ? void 0 : attrs.scaleX) && void 0 !== _r ? _r : 1
}, this._updateFunction = this.updateX;
break;
case "y":
from = {
scaleY: null !== (_s = null != fromScaleY ? fromScaleY : fromAttrs.scaleY) && void 0 !== _s ? _s : 0
}, to = {
scaleY: null !== (_t = null == attrs ? void 0 : attrs.scaleY) && void 0 !== _t ? _t : 1
}, this._updateFunction = this.updateY;
break;
default:
from = {
scaleX: null !== (_u = null != fromScaleX ? fromScaleX : fromAttrs.scaleX) && void 0 !== _u ? _u : 0,
scaleY: null !== (_v = null != fromScaleY ? fromScaleY : fromAttrs.scaleY) && void 0 !== _v ? _v : 0
}, to = {
scaleX: null !== (_w = null == attrs ? void 0 : attrs.scaleX) && void 0 !== _w ? _w : 1,
scaleY: null !== (_x = null == attrs ? void 0 : attrs.scaleY) && void 0 !== _x ? _x : 1
}, this._updateFunction = this.updateXY;
}
this.target.applyFinalAttributeToAttribute(), this.props = to, this.from = from,
this.to = to, !1 !== (null === (_y = this.params.controlOptions) || void 0 === _y ? void 0 : _y.immediatelyApply) && (0,
transient_1.applyAppearStartAttributes)(this.target, from);
}
onEnd(cb) {
super.onEnd(cb);
}
updateX(ratio) {
this.applyScaleTransientAttrs(ratio, !0, !1);
}
updateY(ratio) {
this.applyScaleTransientAttrs(ratio, !1, !0);
}
updateXY(ratio) {
this.applyScaleTransientAttrs(ratio, !0, !0);
}
applyScaleTransientAttrs(ratio, scaleX, scaleY) {
const attrs = {};
scaleX && (attrs.scaleX = this.from.scaleX + (this.to.scaleX - this.from.scaleX) * ratio),
scaleY && (attrs.scaleY = this.from.scaleY + (this.to.scaleY - this.from.scaleY) * ratio),
(0, transient_1.applyAnimationFrameAttributes)(this.target, attrs);
}
deleteSelfAttr(key) {
this.deleteSelfAttrs([ key ]);
}
deleteSelfAttrs(keys) {
var _a;
super.deleteSelfAttrs(keys);
const firstKey = null === (_a = this.propKeys) || void 0 === _a ? void 0 : _a[0];
this.propKeys && this.propKeys.length > 1 ? this._updateFunction = this.updateXY : this._updateFunction = "scaleX" === firstKey ? this.updateX : "scaleY" === firstKey ? this.updateY : null;
}
onUpdate(end, ratio, out) {
this._updateFunction && (this._updateFunction(ratio), this.target.addUpdatePositionTag(),
this.target.addUpdateBoundTag());
}
}
exports.ScaleIn = ScaleIn;
class ScaleOut extends custom_animate_1.ACustomAnimate {
constructor(from, to, duration, easing, params) {
super(from, to, duration, easing, params);
}
onBind() {
var _a, _b, _c, _d, _e;
let from, to;
super.onBind();
const attrs = this.target.attribute;
switch (null === (_a = this.params) || void 0 === _a ? void 0 : _a.direction) {
case "x":
from = {
scaleX: null !== (_b = null == attrs ? void 0 : attrs.scaleX) && void 0 !== _b ? _b : 1
}, to = {
scaleX: 0
};
break;
case "y":
from = {
scaleY: null !== (_c = null == attrs ? void 0 : attrs.scaleY) && void 0 !== _c ? _c : 1
}, to = {
scaleY: 0
};
break;
default:
from = {
scaleX: null !== (_d = null == attrs ? void 0 : attrs.scaleX) && void 0 !== _d ? _d : 1,
scaleY: null !== (_e = null == attrs ? void 0 : attrs.scaleY) && void 0 !== _e ? _e : 1
}, to = {
scaleX: 0,
scaleY: 0
};
}
this.props = to, this.from = from, this.to = to;
}
onEnd(cb) {
super.onEnd(cb);
}
onUpdate(end, ratio, out) {
const attrs = {};
this.propKeys.forEach((key => {
attrs[key] = this.from[key] + (this.to[key] - this.from[key]) * ratio;
})), (0, transient_1.applyAnimationFrameAttributes)(this.target, attrs), this.target.addUpdatePositionTag(),
this.target.addUpdateBoundTag();
}
}
exports.ScaleOut = ScaleOut;
//# sourceMappingURL=scale.js.map