"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.wrapperRaf = wrapperRaf;
const tslib_1 = require("tslib");
const raf_1 = tslib_1.__importDefault(require("raf"));
let id = 0;
const ids = {};
// Support call raf with delay specified frame
function wrapperRaf(callback, delayFrames = 1) {
    const myId = id++;
    let restFrames = delayFrames;
    function internalCallback() {
        restFrames -= 1;
        if (restFrames <= 0) {
            callback();
            delete ids[myId];
        }
        else {
            ids[myId] = (0, raf_1.default)(internalCallback);
        }
    }
    ids[myId] = (0, raf_1.default)(internalCallback);
    return myId;
}
wrapperRaf.cancel = function cancel(pid) {
    if (pid === undefined) {
        return;
    }
    raf_1.default.cancel(ids[pid]);
    delete ids[pid];
};
wrapperRaf.ids = ids; // export this for test usage
//# sourceMappingURL=raf.js.map