"use strict";

exports.__esModule = true;
exports.getScrollParent = exports.getByPredicate = void 0;
var getStyleComputedProperty = element => {
  // NOTE: 1 DOM access here
  var window = element.ownerDocument.defaultView;
  // @ts-ignore
  return window.getComputedStyle(element, null);
};
var getParentNode = element => {
  if (element.nodeName === 'HTML') {
    return element;
  }
  // @ts-ignore
  return element.parentNode || element.host;
};
var getScrollParent = element => {
  // Return body, `getScroll` will take care to get the correct `scrollTop` from it
  if (!element) {
    return document.body;
  }
  switch (element.nodeName) {
    case 'HTML':
    case 'BODY':
      return element.ownerDocument.body;
    case '#document':
      // @ts-ignore
      return element.body;
    default:
  }

  // Firefox want us to check `-x` and `-y` variations as well
  var {
    overflow,
    overflowX,
    overflowY
  } = getStyleComputedProperty(element);
  if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
    return element;
  }
  return getScrollParent(getParentNode(element));
};
exports.getScrollParent = getScrollParent;
var getByPredicate = (predicate, element) => {
  if (!element) {
    return null;
  }
  if (element.nodeName === 'HTML') {
    return element;
  }
  if (predicate(element)) {
    return element;
  }
  return getByPredicate(predicate, getParentNode(element));
};
exports.getByPredicate = getByPredicate;
//# sourceMappingURL=utils.js.map