function f(l) {
  if (c()) l.focus({
    preventScroll: !0
  });
  else {
    let e = n(l);
    l.focus(), s(e);
  }
}
let r = null;
function c() {
  if (r == null) {
    r = !1;
    try {
      document.createElement("div").focus({
        get preventScroll() {
          return r = !0, !0;
        }
      });
    } catch {
    }
  }
  return r;
}
function n(l) {
  let e = l.parentNode, o = [], t = document.scrollingElement || document.documentElement;
  for (; e instanceof HTMLElement && e !== t; )
    (e.offsetHeight < e.scrollHeight || e.offsetWidth < e.scrollWidth) && o.push({
      element: e,
      scrollTop: e.scrollTop,
      scrollLeft: e.scrollLeft
    }), e = e.parentNode;
  return t instanceof HTMLElement && o.push({
    element: t,
    scrollTop: t.scrollTop,
    scrollLeft: t.scrollLeft
  }), o;
}
function s(l) {
  for (let { element: e, scrollTop: o, scrollLeft: t } of l)
    e.scrollTop = o, e.scrollLeft = t;
}
export {
  f as focusWithoutScrolling
};
