<commit_before>import viewport from './viewport';

/**
 * Find the current scroll position of a HTML Element
 * @param  {HTMLElement|window} [elm = viewport] - The HTML element to find the scrolling position from
 * @return {Object} - The current scroll information
 */
export default function scroll(elm = viewport) {
  // Take the viewport if window is the element
  if(elm === window) { elm = viewport; }

  const width = elm.offsetParent ? elm.offsetWidth : window.innerWidth;
  const height = elm.offsetParent ? elm.offsetHeight : window.innerHeight;

  return {
    top: elm.scrollTop,
    maxTop: elm.scrollHeight - height,
    left: elm.scrollLeft,
    leftMax: elm.scrollWidth - width
  };
}<commit_msg>scroll: Improve element check + include scroll position object to set the current scrolling position<commit_after>import viewport from './viewport';
import size from './size';
import isObject from './isObject';
import isWindow from './isWindow';
import isDOMElement from './isDOMElement';
import inDOM from './inDOM';

/**
 * Find the current scroll position of a HTML Element
 * @param  {HTMLElement|window} [elm = viewport] - The HTML element to find the scrolling position from
 * @return {Object} - The current scroll information
 */
export default function scroll(elm = window, scrollPos = null) {
  let isWin = isWindow(elm);

  if(!isWin) {
    if(isObject(elm)) { [elm, scrollPos] = [window, elm]; }

    if(isDOMElement(elm, 'html', 'body')) { elm = elm.ownerDocument; }
    if(typeof elm.defaultView !== 'undfined') { elm = elm.defaultView; }

    isWin = isWindow(elm);

    if(!(isDOMElement(elm) && inDOM(elm)) || isWin) { return null; }
  }

  const view = isWin ? viewport(elm) : elm;

  if(scrollPos) {
    const { byX, byY, x, y } = scrollPos;

    if(!isNaN(x)) { view.scrollTop = x; }
    else if(!isNaN(byX)) { view.scrollTop += byX; }

    if(!isNaN(y)) { view.scrollTop = y; }
    else if(!isNaN(byY)) { view.scrollTop += byY; }
  }

  const s = size(elm);

  return {
    x: view.scrollLeft,
    xMax: s.contentWidth - s.innerWidth,
    y: view.scrollTop,
    yMax: s.contentHeight - s.innerHeight
  };
}
{'fraction_non_alphanumeric': 0.13464235624123422, 'fraction_numerical': 0.0, 'mean_word_length': 3.592274678111588, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '698168', 'n_tokens_mistral': 704, 'n_tokens_neox': 684, 'n_words': 208}