UNPKG

@visactor/vrender-animate

Version:

This module provides a graph-based animation system for VRender.

160 lines (147 loc) 6.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.GrowWidthOut = exports.GrowWidthIn = exports.growWidthOut = void 0; const vutils_1 = require("@visactor/vutils"), custom_animate_1 = require("./custom-animate"); 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 = (0, vutils_1.isValid)(width) ? Math.max(x, x + width) : Math.max(x, x1); return { from: { x: computedX1, x1: (0, vutils_1.isNil)(x1) ? void 0 : computedX1, width: (0, vutils_1.isNil)(width) ? void 0 : 0 }, to: { x: x, x1: x1, width: width } }; } const computedX = (0, vutils_1.isValid)(width) ? Math.min(x, x + width) : Math.min(x, x1); return { from: { x: computedX, x1: (0, vutils_1.isNil)(x1) ? void 0 : computedX, width: (0, vutils_1.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 ? (0, vutils_1.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 = (0, vutils_1.isNumber)(null == options ? void 0 : options.overall) ? null == options ? void 0 : options.overall : 0, { from: { x: overallValue, x1: (0, vutils_1.isNil)(x1) ? void 0 : overallValue, width: (0, vutils_1.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 = (0, vutils_1.isValid)(width) ? Math.max(x, x + width) : Math.max(x, x1); return { to: { x: computedX1, x1: (0, vutils_1.isNil)(x1) ? void 0 : computedX1, width: (0, vutils_1.isNil)(width) ? void 0 : 0 } }; } const computedX = (0, vutils_1.isValid)(width) ? Math.min(x, x + width) : Math.min(x, x1); return { to: { x: computedX, x1: (0, vutils_1.isNil)(x1) ? void 0 : computedX, width: (0, vutils_1.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 ? (0, vutils_1.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 = (0, vutils_1.isNumber)(null == options ? void 0 : options.overall) ? options.overall : 0, { to: { x: overallValue, x1: (0, vutils_1.isNil)(x1) ? void 0 : overallValue, width: (0, vutils_1.isNil)(width) ? void 0 : 0 } }; } 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); }; exports.growWidthOut = growWidthOut; class GrowWidthIn extends custom_animate_1.ACustomAnimate { constructor(from, to, duration, easing, params) { super(from, to, duration, easing, params); } onBind() { var _a, _b; 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; const finalAttribute = this.target.getFinalAttribute(); finalAttribute && this.target.setAttributes(finalAttribute), this.target.setAttributes(fromAttrs); } onEnd(cb) { super.onEnd(cb); } onUpdate(end, ratio, out) { const attribute = this.target.attribute; this.propKeys.forEach((key => { attribute[key] = this.from[key] + (this.to[key] - this.from[key]) * ratio; })), this.target.addUpdatePositionTag(), this.target.addUpdateShapeAndBoundsTag(); } } exports.GrowWidthIn = GrowWidthIn; class GrowWidthOut extends custom_animate_1.ACustomAnimate { constructor(from, to, duration, easing, params) { super(from, to, duration, easing, params); } onBind() { super.onBind(); const {from: from, to: to} = (0, exports.growWidthOut)(this.target, this.params.options, this.params); 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) { const attribute = this.target.attribute; this.propKeys.forEach((key => { attribute[key] = this.from[key] + (this.to[key] - this.from[key]) * ratio; })), this.target.addUpdatePositionTag(), this.target.addUpdateShapeAndBoundsTag(); } } exports.GrowWidthOut = GrowWidthOut; //# sourceMappingURL=growWidth.js.map