"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setTimeoutRAF = setTimeoutRAF;
// normal setTimeout seems to "never callback" when page is under high animation load
function setTimeoutRAF(system, callback, delay) {
    const { api: { animation: { requestAnimationFrame, cancelAnimationFrame }, }, } = system;
    let frame;
    const start = performance.now();
    function loop(timestamp) {
        const elapsed = timestamp - start;
        if (elapsed >= delay) {
            callback();
        }
        else {
            requestAnimationFrame(loop);
        }
    }
    frame = requestAnimationFrame(loop);
    return () => {
        cancelAnimationFrame(frame);
    };
}
//# sourceMappingURL=setTimeoutRAF.js.map