"use client";
import { a as u } from "./useRenderElement-DNB2vtF1.js";
import { u as h } from "./useOnMount-JHtE6teb.js";
const s = null;
let l = globalThis.requestAnimationFrame;
class o {
  /* This implementation uses an array as a backing data-structure for frame callbacks.
   * It allows `O(1)` callback cancelling by inserting a `null` in the array, though it
   * never calls the native `cancelAnimationFrame` if there are no frames left. This can
   * be much more efficient if there is a call pattern that alterns as
   * "request-cancel-request-cancel-…".
   * But in the case of "request-request-…-cancel-cancel-…", it leaves the final animation
   * frame to run anyway. We turn that frame into a `O(1)` no-op via `callbacksCount`. */
  callbacks = [];
  callbacksCount = 0;
  nextId = 1;
  startId = 1;
  isScheduled = !1;
  tick = (t) => {
    this.isScheduled = !1;
    const e = this.callbacks, i = this.callbacksCount;
    if (this.callbacks = [], this.callbacksCount = 0, this.startId = this.nextId, i > 0)
      for (let r = 0; r < e.length; r += 1)
        e[r]?.(t);
  };
  request(t) {
    const e = this.nextId;
    this.nextId += 1, this.callbacks.push(t), this.callbacksCount += 1;
    const i = process.env.NODE_ENV !== "production" && l !== requestAnimationFrame && (l = requestAnimationFrame, !0);
    return (!this.isScheduled || i) && (requestAnimationFrame(this.tick), this.isScheduled = !0), e;
  }
  cancel(t) {
    const e = t - this.startId;
    e < 0 || e >= this.callbacks.length || (this.callbacks[e] = null, this.callbacksCount -= 1);
  }
}
const c = new o();
class a {
  static create() {
    return new a();
  }
  static request(t) {
    return c.request(t);
  }
  static cancel(t) {
    return c.cancel(t);
  }
  currentId = s;
  /**
   * Executes `fn` after `delay`, clearing any previously scheduled call.
   */
  request(t) {
    this.cancel(), this.currentId = c.request(() => {
      this.currentId = s, t();
    });
  }
  cancel = () => {
    this.currentId !== s && (c.cancel(this.currentId), this.currentId = s);
  };
  disposeEffect = () => this.cancel;
}
function k() {
  const n = u(a.create).current;
  return h(n.disposeEffect), n;
}
export {
  a as A,
  k as u
};
