import { offset as n } from "./dom.js";
const c = (t) => {
  if (!t || !t.parentElement || !t.offsetHeight) return;
  if (window.dialogs) {
    const s = t.closest(".ui-dialog");
    s?.getBoundingClientRect() && s?.getBoundingClientRect().bottom > document.documentElement.clientHeight && setTimeout(window.dialogs.onWindowResize);
  }
  const o = t.scrollHeight > t.offsetHeight;
  if (o ? (t.parentElement.classList.add("has_scroll_container"), t.classList.add("has_scroll")) : (t.parentElement.classList.remove("has_scroll_container"), t.classList.remove("has_scroll")), o) {
    const s = n(t).top - n(t.parentElement).top;
    t.style.setProperty("--scroll-offset-top", s + "px");
    const e = t.offsetHeight;
    t.style.setProperty("--scroll-height", e + "px"), t.scrollTop > 0 ? t.classList.add("has_scroll-started") : t.classList.remove("has_scroll-started"), t.scrollTop >= t.scrollHeight - t.offsetHeight ? t.classList.add("has_scroll-finished") : t.classList.remove("has_scroll-finished");
  }
};
let r;
window.ResizeObserver && (r = new ResizeObserver((t) => {
  t.forEach((o) => c(o.target));
}));
const l = (t) => {
  if (!t) return;
  if (Array.isArray(t)) {
    t.forEach((s) => l(s));
    return;
  }
  const o = t;
  o.dataset.scrollShadowInited || (o.dataset.scrollShadowInited = "true", o.onscroll = () => c(o), r?.observe(o));
}, h = (t) => {
  r?.unobserve(t);
}, f = () => a(), a = (t = document.documentElement) => {
  const o = t.clientHeight, s = t.scrollHeight, e = t.scrollTop;
  if (s && e && o) {
    const i = s - o;
    return Math.floor(e / i * 100);
  }
  return 100;
};
export {
  f as amountScrolled,
  l as connectScrollShadow,
  c as genHasScroll,
  a as getScrollPercent,
  h as unconnectScrollShadow
};
//# sourceMappingURL=scroll.js.map
