import { onMounted as b, nextTick as y, getCurrentScope as w, onScopeDispose as F, unref as v, getCurrentInstance as O, ref as T, readonly as g, watch as S } from "vue";
function D(e) {
  return w() ? (F(e), !0) : !1;
}
function f(e) {
  return typeof e == "function" ? e() : v(e);
}
const G = typeof window < "u" && typeof document < "u";
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
const M = (e) => e != null, j = Object.prototype.toString, k = (e) => j.call(e) === "[object Object]", p = () => {
};
function m(e, n) {
  function o(...t) {
    return new Promise((r, i) => {
      Promise.resolve(e(() => n.apply(this, t), { fn: n, thisArg: this, args: t })).then(r).catch(i);
    });
  }
  return o;
}
const d = (e) => e();
function W(e, n = {}) {
  let o, t, r = p;
  const i = (c) => {
    clearTimeout(c), r(), r = p;
  };
  return (c) => {
    const s = f(e), u = f(n.maxWait);
    return o && i(o), s <= 0 || u !== void 0 && u <= 0 ? (t && (i(t), t = null), Promise.resolve(c())) : new Promise((l, h) => {
      r = n.rejectOnCancel ? h : l, u && !t && (t = setTimeout(() => {
        o && i(o), t = null, l(c());
      }, u)), o = setTimeout(() => {
        t && i(t), t = null, l(c());
      }, s);
    });
  };
}
function x(e = d) {
  const n = T(!0);
  function o() {
    n.value = !1;
  }
  function t() {
    n.value = !0;
  }
  const r = (...i) => {
    n.value && e(...i);
  };
  return { isActive: g(n), pause: o, resume: t, eventFilter: r };
}
function C(e) {
  return e || O();
}
function I(e, n = 200, o = {}) {
  return m(
    W(n, o),
    e
  );
}
function P(e, n, o = {}) {
  const {
    eventFilter: t = d,
    ...r
  } = o;
  return S(
    e,
    m(
      t,
      n
    ),
    r
  );
}
function L(e, n, o = {}) {
  const {
    eventFilter: t,
    ...r
  } = o, { eventFilter: i, pause: a, resume: c, isActive: s } = x(t);
  return { stop: P(
    e,
    n,
    {
      ...r,
      eventFilter: i
    }
  ), pause: a, resume: c, isActive: s };
}
function N(e, n = !0, o) {
  C() ? b(e, o) : n ? e() : y(e);
}
export {
  d as bypassFilter,
  m as createFilterWrapper,
  W as debounceFilter,
  C as getLifeCycleTarget,
  G as isClient,
  k as isObject,
  p as noop,
  M as notNullish,
  x as pausableFilter,
  L as pausableWatch,
  f as toValue,
  N as tryOnMounted,
  D as tryOnScopeDispose,
  I as useDebounceFn,
  L as watchPausable,
  P as watchWithFilter
};
