var __rest = this && this.__rest || function(s, e) {
    var t = {};
    for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
    if (null != s && "function" == typeof Object.getOwnPropertySymbols) {
        var i = 0;
        for (p = Object.getOwnPropertySymbols(s); i < p.length; i++) e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
    }
    return t;
};

import { AComponentAnimate, AnimateExecutor, createComponentAnimator, IncreaseCount } from "@visactor/vrender-animate";

export class LabelUpdate extends AComponentAnimate {
    onBind() {
        const animator = createComponentAnimator(this.target);
        this._animator = animator;
        const duration = this.duration, easing = this.easing, {prevText: prevText, curText: curText, prevLabelLine: prevLabelLine, curLabelLine: curLabelLine} = this.params, diff = {};
        for (const key in curText.attribute) prevText.attribute[key] !== curText.attribute[key] && (diff[key] = curText.attribute[key]);
        const {text: text} = diff, rest = __rest(diff, [ "text" ]);
        animator.animate(prevText, {
            type: "to",
            to: rest,
            duration: duration,
            easing: easing
        }), animator.animate(prevText, {
            type: "increaseCount",
            to: {
                text: curText.attribute.text
            },
            duration: duration,
            easing: easing
        }), prevLabelLine && animator.animate(prevLabelLine, {
            type: "to",
            to: curLabelLine.attribute,
            duration: duration,
            easing: easing
        }), this.completeBind(animator);
    }
    tryPreventConflict() {}
}

export class LabelEnter extends AComponentAnimate {
    onBind() {
        const animator = createComponentAnimator(this.target);
        this._animator = animator;
        const duration = this.duration, easing = this.easing, {relatedGraphic: relatedGraphic, relatedGraphics: relatedGraphics, config: config} = this.params, {mode: mode, type: type = "fadeIn"} = config, target = this.target;
        let startTime = 0;
        "after" === mode ? relatedGraphic.animates && relatedGraphic.animates.forEach((animate => {
            startTime = Math.max(startTime, animate.getStartTime() + animate.getTotalDuration());
        })) : "after-all" === mode ? relatedGraphics && relatedGraphics.forEach((graphic => {
            graphic.animates && graphic.animates.forEach((animate => {
                startTime = Math.max(startTime, animate.getStartTime() + animate.getTotalDuration());
            }));
        })) : relatedGraphic.animates && relatedGraphic.animates.forEach((animate => {
            startTime = Math.max(startTime, animate.getStartTime());
        })), animator.animate(target, Object.assign(Object.assign({}, config), {
            duration: duration,
            easing: easing,
            startTime: startTime,
            type: type
        })), this.completeBind(animator);
    }
    tryPreventConflict() {}
}

export function registerLabelAnimate() {
    AnimateExecutor.registerBuiltInAnimate("increaseCount", IncreaseCount), AnimateExecutor.registerBuiltInAnimate("labelUpdate", LabelUpdate), 
    AnimateExecutor.registerBuiltInAnimate("labelEnter", LabelEnter);
}
//# sourceMappingURL=label-animate.js.map