import { DEFAULT_INTERVAL_MS as m, MAX_INTERVAL_MS as b } from "./constants.js";
import { clamp as A } from "../../../utils/value/number.js";
import { struct as T } from "../../../utils/struct/main.js";
import { enumerable as a } from "../../../utils/struct/property.js";
import { boolOrFalse as g } from "../../../utils/value/bool.js";
const w = (c, n = m, u = !1) => {
  let e = new AbortController(), t = A(0, ~~n, b), l = g(u);
  Number.isFinite(t) || (t = m);
  const o = document.timeline?.currentTime ?? performance.now(), f = () => {
    e?.abort(), e = void 0;
  }, d = (r) => {
    !e || e.signal.aborted || (s(r), c(r));
  }, s = (r) => {
    let i = 0;
    if (!l) {
      const p = r - o, _ = Math.round(p / t) * t;
      i = o + _ + t - performance.now();
    }
    setTimeout(() => requestAnimationFrame(d), i);
  };
  return s(o), l = !1, T({
    cancel: a(f),
    delay: a(n),
    signal: a(e.signal)
  });
};
export {
  w as createInterval
};
