'use strict';

var rigMath = require('./rigMath.js');

/** Easing functions (t in [0..1]). */
const ease = {
    /** Smoothstep-like ease in-out. */
    inOut: (t) => t * t * (3 - 2 * t),
    /** Fast-in, slow-out. */
    outCubic: (t) => 1 - Math.pow(1 - t, 3),
    /** Slow-in, fast-out. */
    inCubic: (t) => t * t * t,
};
/** Blend two poses by factor t (0..1). */
function blendPose(a, b, t) {
    const out = {};
    const keys = new Set([
        ...Object.keys(a),
        ...Object.keys(b),
    ]);
    keys.forEach((k) => {
        var _a, _b;
        const av = (_a = a[k]) !== null && _a !== void 0 ? _a : b[k];
        const bv = (_b = b[k]) !== null && _b !== void 0 ? _b : a[k];
        if (typeof av === "number" && typeof bv === "number")
            out[k] = rigMath.lerpAngle(av, bv, t);
    });
    return out;
}
/** Tween helper driven by requestAnimationFrame. */
function tweenPose(from, to, durationMs, set, easing = ease.inOut) {
    const start = performance.now();
    return new Promise((resolve) => {
        const frame = () => {
            const t = Math.min(1, (performance.now() - start) / Math.max(1, durationMs));
            set(blendPose(from, to, easing(t)));
            if (t < 1)
                requestAnimationFrame(frame);
            else
                resolve();
        };
        requestAnimationFrame(frame);
    });
}

exports.blendPose = blendPose;
exports.ease = ease;
exports.tweenPose = tweenPose;
//# sourceMappingURL=poseOps.js.map
