<commit_before>/**
 * @module
 * @prototype {Function} scrollTo
 * @dependencies [ SmoothScrollbar, #showTrack, #hideTrack, pickInRange ]
 */

import './set_position';
import { pickInRange } from '../utils/index';
import { SmoothScrollbar } from '../smooth_scrollbar';

export { SmoothScrollbar };

/**
 * @method
 * @api
 * Scrolling scrollbar to position with transition
 *
 * @param {Number} [x]: scrollbar position in x axis
 * @param {Number} [y]: scrollbar position in y axis
 * @param {Number} [duration]: transition duration
 * @param {Function} [cb]: callback
 */
SmoothScrollbar.prototype.scrollTo = function(x = this.offset.x, y = this.offset.y, duration = 0, cb = null) {
    let { offset, limit, __timerID } = this;
    let destX = pickInRange(x, 0, limit.x);
    let destY = pickInRange(y, 0, limit.y);

    if (destX === offset.x && destY === offset.y) return;

    let frames = {
        x: this.__motionBuilder(offset.x, destX - offset.x, duration),
        y: this.__motionBuilder(offset.y, destY - offset.y, duration)
    };

    let i = 0, length = frames.x.length;

    let scroll = () => {
        if (i === length) {
            return typeof cb === 'function' && cb(this);
        }

        this.setPosition(frames.x[i], frames.y[i]);

        i++;

        __timerID.scrollAnimation = requestAnimationFrame(scroll);
    };

    scroll();
};<commit_msg>fix(scrollTo): fix callback not invoked<commit_after>/**
 * @module
 * @prototype {Function} scrollTo
 * @dependencies [ SmoothScrollbar, #showTrack, #hideTrack, pickInRange ]
 */

import './set_position';
import { pickInRange } from '../utils/index';
import { SmoothScrollbar } from '../smooth_scrollbar';

export { SmoothScrollbar };

/**
 * @method
 * @api
 * Scrolling scrollbar to position with transition
 *
 * @param {Number} [x]: scrollbar position in x axis
 * @param {Number} [y]: scrollbar position in y axis
 * @param {Number} [duration]: transition duration
 * @param {Function} [cb]: callback
 */
SmoothScrollbar.prototype.scrollTo = function(x = this.offset.x, y = this.offset.y, duration = 0, cb = null) {
    cb = typeof cb === 'function' ? cb : () => {};

    const { offset, limit, __timerID } = this;
    const destX = pickInRange(x, 0, limit.x);
    const destY = pickInRange(y, 0, limit.y);

    if (destX === offset.x && destY === offset.y) return cb(this);

    const frames = {
        x: this.__motionBuilder(offset.x, destX - offset.x, duration),
        y: this.__motionBuilder(offset.y, destY - offset.y, duration)
    };

    let i = 0, length = frames.x.length;

    let scroll = () => {
        if (i === length) {
            return cb(this);
        }

        this.setPosition(frames.x[i], frames.y[i]);

        i++;

        __timerID.scrollAnimation = requestAnimationFrame(scroll);
    };

    scroll();
};
{'fraction_non_alphanumeric': 0.1569252568189869, 'fraction_numerical': 0.0028338646829613886, 'mean_word_length': 3.0342857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '1165247', 'n_tokens_mistral': 914, 'n_tokens_neox': 878, 'n_words': 243}