import {
  a as o
} from "./chunk-IO47FP3U.js";

// src/preview-api/modules/preview-web/render/animation-utils.ts
function c() {
  try {
    return (
      // @ts-expect-error this property exists in certain environments
      !!globalThis.__vitest_browser__ || // @ts-expect-error this property exists in certain environments
      !!globalThis.__playwright__binding__
    );
  } catch {
    return !1;
  }
}
o(c, "isTestEnvironment");
function u(e = !0) {
  if (!("document" in globalThis && "createElement" in globalThis.document))
    return () => {
    };
  let n = document.createElement("style");
  n.textContent = `*, *:before, *:after {
    animation: none !important;
  }`, document.head.appendChild(n);
  let t = document.createElement("style");
  return t.textContent = `*, *:before, *:after {
    animation-delay: 0s !important;
    animation-direction: ${e ? "reverse" : "normal"} !important;
    animation-play-state: paused !important;
    transition: none !important;
  }`, document.head.appendChild(t), document.body.clientHeight, document.head.removeChild(n), () => {
    t.parentNode?.removeChild(t);
  };
}
o(u, "pauseAnimations");
async function d(e) {
  if (!("document" in globalThis && "getAnimations" in globalThis.document && "querySelectorAll" in globalThis.document))
    return;
  let n = !1;
  await Promise.race([
    // After 50ms, retrieve any running animations and wait for them to finish
    // If new animations are created while waiting, we'll wait for them too
    new Promise((t) => {
      setTimeout(() => {
        let a = [globalThis.document, ...l(globalThis.document)], r = /* @__PURE__ */ o(async () => {
          if (n || e?.aborted)
            return;
          let s = a.flatMap((i) => i?.getAnimations?.() || []).filter((i) => i.playState === "running" && !m(i));
          s.length > 0 && (await Promise.all(s.map((i) => i.finished)), await r());
        }, "checkAnimationsFinished");
        r().then(t);
      }, 100);
    }),
    // If animations don't finish within the timeout, continue without waiting
    new Promise(
      (t) => setTimeout(() => {
        n = !0, t(void 0);
      }, 5e3)
    )
  ]);
}
o(d, "waitForAnimations");
function l(e) {
  return [e, ...e.querySelectorAll("*")].reduce((n, t) => ("shadowRoot" in t && t.shadowRoot && n.push(t.shadowRoot, ...l(t.shadowRoot)), n), []);
}
o(l, "getShadowRoots");
function m(e) {
  if (e instanceof CSSAnimation && e.effect instanceof KeyframeEffect && e.effect.target) {
    let n = getComputedStyle(e.effect.target, e.effect.pseudoElement), t = n.animationName?.split(", ").indexOf(e.animationName);
    return n.animationIterationCount.split(", ")[t] === "infinite";
  }
  return !1;
}
o(m, "isInfiniteAnimation");

export {
  c as a,
  u as b,
  d as c
};
