"use strict";

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.raf = raf;
exports.doubleRaf = doubleRaf;
exports.cancelRaf = cancelRaf;
/**
 * requestAnimationFrame polyfill
 */

var prev = Date.now();

/* istanbul ignore next */
function fallback(fn) {
    var curr = Date.now();
    var ms = Math.max(0, 16 - (curr - prev));
    var id = setTimeout(fn, ms);
    prev = curr + ms;
    return id;
}

var iRaf = window.requestAnimationFrame || fallback;

var iCancel = window.cancelAnimationFrame || clearTimeout;

function raf(fn) {
    return iRaf(fn);
}

// double raf for animation
function doubleRaf(fn) {
    raf(function () {
        raf(fn);
    });
}

function cancelRaf(id) {
    iCancel(id);
}