"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index_esm = require("../../../@vant/use/dist/index.esm.js");
const dom = require("../utils/dom.js");
function scrollLeftTo(scroller, to, duration) {
  let rafId;
  let count = 0;
  const from = scroller.scrollLeft;
  const frames = duration === 0 ? 1 : Math.round(duration * 1e3 / 16);
  let scrollLeft = from;
  function cancel() {
    index_esm.cancelRaf(rafId);
  }
  function animate() {
    scrollLeft += (to - from) / frames;
    scroller.scrollLeft = scrollLeft;
    if (++count < frames) {
      rafId = index_esm.raf(animate);
    }
  }
  animate();
  return cancel;
}
function scrollTopTo(scroller, to, duration, callback) {
  let rafId;
  let current = dom.getScrollTop(scroller);
  const isDown = current < to;
  const frames = duration === 0 ? 1 : Math.round(duration * 1e3 / 16);
  const step = (to - current) / frames;
  function cancel() {
    index_esm.cancelRaf(rafId);
  }
  function animate() {
    current += step;
    if (isDown && current > to || !isDown && current < to) {
      current = to;
    }
    dom.setScrollTop(scroller, current);
    if (isDown && current < to || !isDown && current > to) {
      rafId = index_esm.raf(animate);
    } else if (callback) {
      rafId = index_esm.raf(callback);
    }
  }
  animate();
  return cancel;
}
exports.scrollLeftTo = scrollLeftTo;
exports.scrollTopTo = scrollTopTo;
