export function closest(node, s) {
  if (!node) {
    return null;
  }
  var el = node;
  if (!document.documentElement || !document.documentElement.contains(el)) {
    return null;
  }
  if (el.closest) {
    return el.closest(s);
  }
  do {
    var matchfn = el.matches ? el.matches : el.msMatchesSelector;
    if (matchfn && matchfn.call(el, s)) {
      // Ignored via go/ees005
      // eslint-disable-next-line @atlaskit/editor/no-as-casting
      return el;
    }
    el = el.parentElement || el.parentNode;
  } while (el !== null && el.nodeType === 1);
  return null;
}

// eslint-disable-next-line @repo/internal/deprecations/deprecation-ticket-required -- Ignored via go/ED-25883
/*
 * @deprecated - Use HTMLElement.protoype.closest instead
 */
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
export function closestElement(node, s) {
  return closest(node, s);
}
// does typescript have function templates yet?

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
export function mapElem(elem, callback) {
  var array = [];
  for (var i = 0; i < elem.childElementCount; i++) {
    array.push(callback(elem.children[i], i, elem));
  }
  return array;
}

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
export function maphElem(elem, callback) {
  return mapElem(elem, callback);
}
// eslint-disable-next-line @atlaskit/editor/no-re-export
export { walkUpTreeUntil } from './walkUpTreeUntil';
// eslint-disable-next-line @atlaskit/editor/no-re-export
export { unwrap } from './unwrap';
// eslint-disable-next-line @atlaskit/editor/no-re-export
export { removeNestedEmptyEls } from './removeNestedEmptyEls';
// eslint-disable-next-line @atlaskit/editor/no-re-export
export { containsClassName } from './containsClassName';
// eslint-disable-next-line @atlaskit/editor/no-re-export
export { parsePx } from './parsePx';