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