import { s as u } from "./string.DUgD4c9f.js";
import { B as p } from "./lit-element.jLBm65_O.js";
const f = (n) => n.nodeType === Node.ELEMENT_NODE, E = (n, t) => {
  if (!n)
    return !1;
  let e = n;
  for (; e && e.parentNode; ) {
    if (e.parentNode === t)
      return !0;
    e.parentNode.host ? e = e.parentNode.host : e = e.parentNode;
  }
  return !1;
}, m = (n = document) => {
  const t = n.activeElement;
  return t ? t.shadowRoot ? m(t.shadowRoot) : t : null;
}, C = (n, t = document.body, e = "width") => {
  const i = n?.trim();
  if (!i)
    return 0;
  const o = i.split(/\s+/)[0];
  if (o.endsWith("px"))
    return parseFloat(o);
  const s = o.startsWith("-"), r = document.createElement("div");
  r.style[e] = s ? o.substring(1) : o, r.style.position = "absolute", r.style.visibility = "hidden", t.appendChild(r);
  const a = r.getBoundingClientRect(), d = e === "width" ? a.width : a.height;
  return t.removeChild(r), s ? -d : d;
}, x = (n, t) => {
  const e = t.getBoundingClientRect(), o = (n.clientX - e.left) / e.width * 100;
  return Math.max(0, Math.min(100, o));
}, y = (n, t) => new Promise((e, i) => {
  const o = t ? t.document : document, s = o.querySelector(
    `script[src="${n}"]`
  );
  if (s) {
    if (s.getAttribute("data-loaded") === "true")
      return e();
    s.addEventListener("load", () => e()), s.addEventListener("error", (a) => i(a));
    return;
  }
  const r = o.createElement("script");
  r.src = n, r.async = !0, r.onload = () => {
    r.setAttribute("data-loaded", "true"), e();
  }, r.onerror = () => i(new Error(`Failed to load ${n}`)), o.head.appendChild(r);
});
function M(n, t = !1) {
  const [e, i, o, s] = n.split(" ").map(parseFloat), r = t ? "px" : "", a = Math.max(0, o + s - i), d = o + s + e, c = o + s + i, l = Math.max(0, o + s - e);
  return {
    paddingBottom: c + r,
    paddingLeft: l + r,
    paddingRight: d + r,
    paddingTop: a + r
  };
}
function R(n) {
  return [...n].sort((t, e) => {
    const i = t.getBoundingClientRect().top, o = e.getBoundingClientRect().top;
    return i - o;
  });
}
function T() {
  return window.StackMgr?.GetInstance()?.GetIndex() ?? 99999;
}
function B() {
  return document.getElementById("PopupLayer") || document.body;
}
function w(n) {
  const t = document.createElement("template");
  return p(n, t.content), t.content.firstElementChild;
}
function b(n) {
  const t = document.createElement("template");
  return t.innerHTML = u(n), t.content.firstElementChild;
}
function L(n, t, e = 0) {
  const i = n.getBoundingClientRect(), o = t.getBoundingClientRect();
  return Math.round(o.left) >= Math.round(i.left) - e && Math.round(o.right) <= Math.round(i.right) + e;
}
export {
  b as a,
  x as b,
  C as c,
  m as d,
  E as e,
  f,
  w as g,
  M as h,
  L as i,
  T as j,
  B as k,
  y as l,
  R as s
};
