"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.animateSimulate = void 0;
const animateSimulateTick_1 = require("./animateSimulateTick");
const animateSimulate = (system, n0, n1, ff, tf, callback) => {
    const { api: { animation: { requestAnimationFrame, cancelAnimationFrame }, }, } = system;
    let n = n0;
    let frame;
    const next = () => (frame = requestAnimationFrame(tick));
    const tick = () => {
        const _n = n1();
        const ended = (0, animateSimulateTick_1.animateSimulateTick)(n, _n, ff, tf);
        if (ended) {
            const result = callback();
            if (result === false) {
                next();
            }
        }
        else {
            next();
        }
    };
    next();
    return () => {
        if (frame !== undefined) {
            cancelAnimationFrame(frame);
            frame = undefined;
        }
    };
};
exports.animateSimulate = animateSimulate;
//# sourceMappingURL=animateSimulate.js.map