"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.animateThrottle = void 0;
const animateThrottle = (func, requestAnimationFrame, cancelAnimationFrame) => {
    let run = true;
    let frame;
    let run_last = false;
    function g(...args) {
        run = true;
        if (run_last) {
            run_last = false;
            func(...args);
        }
    }
    function f(...args) {
        if (run) {
            run = false;
            run_last = false;
            cancelAnimationFrame(frame);
            func(...args);
            frame = requestAnimationFrame(g.bind(null, ...args));
        }
        else {
            run_last = true;
        }
    }
    function abort() {
        if (frame !== undefined) {
            cancelAnimationFrame(frame);
            frame = undefined;
        }
    }
    return { f, abort };
};
exports.animateThrottle = animateThrottle;
//# sourceMappingURL=animateThrottle.js.map