<commit_before>import {
  Scrollbar,
  ScrollToOptions,
} from '../interfaces/';

import {
  valueWithin,
} from '../utils/';

export function scrollTo(
  scrollbar: Scrollbar,
  x: number,
  y: number,
  duration = 0,
  { easing = defaultEasing, callback = null } = {} as ScrollToOptions,
) {
  const {
    options,
    offset,
    limit,
  } = scrollbar;

  if (options.renderByPixels) {
    // ensure resolved with integer
    x = Math.round(x);
    y = Math.round(y);
  }

  const startX = offset.x;
  const startY = offset.y;

  const disX = valueWithin(x, 0, limit.x) - startX;
  const disY = valueWithin(y, 0, limit.y) - startY;

  const start = Date.now();

  function scroll() {
    const elapse = Date.now() - start;
    const progress = easing(Math.min(elapse / duration, 1));

    scrollbar.setPosition(
      startX + disX * progress,
      startY + disY * progress,
    );

    if (elapse >= duration) {
      if (typeof callback === 'function') {
        callback.call(scrollbar);
      }
    } else {
      requestAnimationFrame(scroll);
    }
  }

  scroll();
}

/**
 * easeOutCubic<commit_msg>fix(scrollTo): fix duration=0<commit_after>import {
  Scrollbar,
  ScrollToOptions,
} from '../interfaces/';

import {
  valueWithin,
} from '../utils/';

export function scrollTo(
  scrollbar: Scrollbar,
  x: number,
  y: number,
  duration = 0,
  { easing = defaultEasing, callback = null } = {} as ScrollToOptions,
) {
  const {
    options,
    offset,
    limit,
  } = scrollbar;

  if (options.renderByPixels) {
    // ensure resolved with integer
    x = Math.round(x);
    y = Math.round(y);
  }

  const startX = offset.x;
  const startY = offset.y;

  const disX = valueWithin(x, 0, limit.x) - startX;
  const disY = valueWithin(y, 0, limit.y) - startY;

  const start = Date.now();

  function scroll() {
    const elapse = Date.now() - start;
    const progress = duration ? easing(Math.min(elapse / duration, 1)) : 1;

    scrollbar.setPosition(
      startX + disX * progress,
      startY + disY * progress,
    );

    if (elapse >= duration) {
      if (typeof callback === 'function') {
        callback.call(scrollbar);
      }
    } else {
      requestAnimationFrame(scroll);
    }
  }

  scroll();
}

/**
 * easeOutCubic
{'fraction_non_alphanumeric': 0.1411451398135819, 'fraction_numerical': 0.004438526409232135, 'mean_word_length': 2.594896331738437, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4091365', 'n_tokens_mistral': 803, 'n_tokens_neox': 763, 'n_words': 187}