@visactor/vrender-animate
Version:
This module provides a graph-based animation system for VRender.
71 lines (58 loc) • 2.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.applyAppearStartAttributes = exports.applyAnimationTransientAttributes = exports.applyAnimationFrameNumberAttributes = exports.applyAnimationFrameAttributes = void 0;
const constant_1 = require("@visactor/vrender-core/event/constant"), animateUpdateContext = {
type: constant_1.AttributeUpdateType.ANIMATE_UPDATE
}, animateBindContext = {
type: constant_1.AttributeUpdateType.ANIMATE_BIND
}, animateStartContext = {
type: constant_1.AttributeUpdateType.ANIMATE_START
};
function getAnimationContext(type) {
switch (type) {
case constant_1.AttributeUpdateType.ANIMATE_UPDATE:
return animateUpdateContext;
case constant_1.AttributeUpdateType.ANIMATE_BIND:
return animateBindContext;
case constant_1.AttributeUpdateType.ANIMATE_START:
return animateStartContext;
default:
return {
type: type
};
}
}
function prepareAnimationFrameAttribute(target) {
const transientTarget = target;
return transientTarget.attribute || (transientTarget.attribute = {}), transientTarget.attribute === transientTarget.baseAttributes && transientTarget.detachAttributeFromBaseAttributes(),
transientTarget.attributeMayContainTransientAttrs = !0, transientTarget.attribute;
}
function commitAnimationFrameAttribute(target) {
target.onAttributeUpdate(animateUpdateContext);
}
function applyAnimationFrameAttributes(target, attributes) {
if (!attributes) return;
const targetAttribute = prepareAnimationFrameAttribute(target);
for (const key in attributes) Object.prototype.hasOwnProperty.call(attributes, key) && (targetAttribute[key] = attributes[key]);
commitAnimationFrameAttribute(target);
}
function applyAnimationFrameNumberAttributes(target, keys, from, to, ratio) {
const targetAttribute = prepareAnimationFrameAttribute(target);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
targetAttribute[key] = from[key] + (to[key] - from[key]) * ratio;
}
commitAnimationFrameAttribute(target);
}
function applyAnimationTransientAttributes(target, attributes, type = constant_1.AttributeUpdateType.ANIMATE_UPDATE) {
if (!attributes) return;
const context = getAnimationContext(type);
target.applyAnimationTransientAttributes(attributes, !1, context);
}
function applyAppearStartAttributes(target, attributes) {
applyAnimationTransientAttributes(target, attributes, constant_1.AttributeUpdateType.ANIMATE_BIND);
}
exports.applyAnimationFrameAttributes = applyAnimationFrameAttributes, exports.applyAnimationFrameNumberAttributes = applyAnimationFrameNumberAttributes,
exports.applyAnimationTransientAttributes = applyAnimationTransientAttributes, exports.applyAppearStartAttributes = applyAppearStartAttributes;
//# sourceMappingURL=transient.js.map