const w = (t, n) => {
  let e = () => {
  };
  const o = setTimeout(() => {
    const l = t();
    l != null && (e = l);
  }, n);
  return () => {
    clearTimeout(o), e();
  };
}, x = (t, n) => {
  let e = () => {
  };
  const o = setInterval(() => {
    const l = t();
    l != null && (e = l);
  }, n);
  return () => {
    clearInterval(o), e();
  };
};
function p(t, n, e = {}) {
  const { noTrailing: o = !1, noLeading: l = !1, debounceMode: u } = e;
  let i, f = !1, a = 0;
  function m() {
    i && clearTimeout(i);
  }
  function g(s) {
    const { upcomingOnly: r = !1 } = s || {};
    m(), f = !r;
  }
  function d(...s) {
    if (f) return;
    const r = this, T = Date.now() - a;
    function c() {
      a = Date.now(), n.apply(r, s);
    }
    function v() {
      i = void 0;
    }
    !l && u && !i && c(), m(), u === void 0 && T > t ? l ? (a = Date.now(), o || (i = setTimeout(u ? v : c, t))) : c() : o || (i = setTimeout(
      u ? v : c,
      u === void 0 ? Math.max(0, t - T) : t
    ));
  }
  return d.cancel = g, d;
}
function A(t, n, { atBegin: e = !1 } = {}) {
  return p(t, n, { debounceMode: e !== !1 });
}
const D = (t) => {
  let n = null;
  const e = (o) => {
    n = null, t(o);
  };
  return n == null && (n = requestAnimationFrame(e)), () => {
    n != null && (cancelAnimationFrame(n), n = null);
  };
};
export {
  w as I,
  x as T,
  D as g,
  A as x
};
