text: 'use strict';
  
  Object.defineProperty(exports, '__esModule', { value: true });
  
  var hasRAF = typeof window !== 'undefined' && window.requestAnimationFrame !== undefined;
  var prevTime = 0;
  var onNextFrame = hasRAF
      ? function (callback) { return window.requestAnimationFrame(callback); }
      : function (callback) {
          var currentTime = Date.now();
          var timeToCall = Math.max(0, 16.7 - (currentTime - prevTime));
          prevTime = currentTime + timeToCall;
          setTimeout(function () { return callback(prevTime); }, timeToCall);
      };
  
  function createRenderStep(startRenderLoop) {
      var functionsToRun = [];
      var functionsToRunNextFrame = [];
      var numThisFrame = 0;
      var isProcessing = false;
      var i = 0;
      return {
          cancel: function (callback) {
              var indexOfCallback = functionsToRunNextFrame.indexOf(callback);
              if (indexOfCallback !== -1) {
                  functionsToRunNextFrame.splice(indexOfCallback, 1);
              }
          },
          process: function () {
              isProcessing = true;
              _a = [functionsToRunNextFrame, functionsToRun], functionsToRun = _a[0], functionsToRunNextFrame = _a[1];
              functionsToRunNextFrame.length = 0;
              numThisFrame = functionsToRun.length;
              for (i = 0; i < numThisFrame; i++) {
                  functionsToRun[i]();
              }
              isProcessing = false;
              var _a;
          },
          schedule: function (callback, immediate) {
              if (immediate === void 0) { immediate = false; }
              startRenderLoop();
              var addToCurrentBuffer = immediate && isProcessing;
              var buffer = addToCurrentBuffer ? functionsToRun : functionsToRunNextFrame;
              if (buffer.indexOf(callback) === -1) {
                  buffer.push(callback);
                  if (addToCurrentBuffer) {
                      numThisFrame = functionsToRun.length;
                  }
              }
          },
      };
  }
  
  var HAS_PERFORMANCE_NOW = typeof performance !== 'undefined' && performance.now !== undefined;
  var currentTime = HAS_PERFORMANCE_NOW ? function () { return performance.now(); } : function () { return Date.now(); };
  var willRenderNextFrame = false;
  var MAX_ELAPSED = 40;
  var defaultElapsed = 16.7;
  var useDefaultElapsed = true;
  var currentFramestamp = 0;
  var elapsed = 0;
  function startRenderLoop() {
      if (willRenderNextFrame)
          return;
      willRenderNextFrame = true;
      useDefaultElapsed = true;
      onNextFrame(processFrame);
  }
  var frameStart = createRenderStep(startRenderLoop);
  var frameUpdate = createRenderStep(startRenderLoop);
  var frameRender = createRenderStep(startRenderLoop);
  var frameEnd = createRenderStep(startRenderLoop);
  function processFrame(framestamp) {
      willRenderNextFrame = false;
      elapsed = useDefaultElapsed
          ? defaultElapsed
          : Math.max(Math.min(framestamp - currentFramestamp, MAX_ELAPSED), 1);
      if (!useDefaultElapsed)
          defaultElapsed = elapsed;
      currentFramestamp = framestamp;
      frameStart.process();
      frameUpdate.process();
      frameRender.process();
      frameEnd.process();
      if (willRenderNextFrame)
          useDefaultElapsed = false;
  }
  var onFrameStart = frameStart.schedule;
  var onFrameUpdate = frameUpdate.schedule;
  var onFrameRender = frameRender.schedule;
  var onFrameEnd = frameEnd.schedule;
  var cancelOnFrameStart = frameStart.cancel;
  var cancelOnFrameUpdate = frameUpdate.cancel;
  var cancelOnFrameRender = frameRender.cancel;
  var cancelOnFrameEnd = frameEnd.cancel;
  var timeSinceLastFrame = function () { return elapsed; };
  var currentFrameTime = function () { return currentFramestamp; };
  
  exports.currentTime = currentTime;
  exports.onFrameStart = onFrameStart;
  exports.onFrameUpdate = onFrameUpdate;
  exports.onFrameRender = onFrameRender;
  exports.onFrameEnd = onFrameEnd;
  exports.cancelOnFrameStart = cancelOnFrameStart;
  exports.cancelOnFrameUpdate = cancelOnFrameUpdate;
  exports.cancelOnFrameRender = cancelOnFrameRender;
  exports.cancelOnFrameEnd = cancelOnFrameEnd;
  exports.timeSinceLastFrame = timeSinceLastFrame;
  exports.currentFrameTime = currentFrameTime;
  