'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var raf = require('./raf.js');
var easings = require('./easings.js');
var getScroll = require('./getScroll.js');

function scrollTo(y, options = {}) {
  const { getContainer = () => window, callback, duration = 450 } = options;
  const container = getContainer();
  const scrollTop = getScroll.default(container, true);
  const startTime = Date.now();
  const frameFunc = () => {
    const timestamp = Date.now();
    const time = timestamp - startTime;
    const nextScrollTop = easings.easeInOutCubic(time > duration ? duration : time, scrollTop, y, duration);
    if (getScroll.isWindow(container))
      container.scrollTo(window.pageXOffset, nextScrollTop);
    else if (container instanceof Document || container.constructor.name === "HTMLDocument")
      container.documentElement.scrollTop = nextScrollTop;
    else
      container.scrollTop = nextScrollTop;
    if (time < duration)
      raf.default(frameFunc);
    else if (typeof callback === "function")
      callback();
  };
  raf.default(frameFunc);
}

exports.default = scrollTo;
//# sourceMappingURL=scrollTo.js.map
