import { u as i } from "./useRenderElement.js";
import { t as l } from "./useOnMount.js";
var s = null;
globalThis.requestAnimationFrame;
var u = class {
  callbacks = [];
  callbacksCount = 0;
  nextId = 1;
  startId = 1;
  isScheduled = !1;
  tick = (e) => {
    this.isScheduled = !1;
    const t = this.callbacks, n = this.callbacksCount;
    if (this.callbacks = [], this.callbacksCount = 0, this.startId = this.nextId, n > 0) for (let a = 0; a < t.length; a += 1) t[a]?.(e);
  };
  request(e) {
    const t = this.nextId;
    return this.nextId += 1, this.callbacks.push(e), this.callbacksCount += 1, this.isScheduled || (requestAnimationFrame(this.tick), this.isScheduled = !0), t;
  }
  cancel(e) {
    const t = e - this.startId;
    t < 0 || t >= this.callbacks.length || (this.callbacks[t] = null, this.callbacksCount -= 1);
  }
}, c = new u(), h = class r {
  static create() {
    return new r();
  }
  static request(t) {
    return c.request(t);
  }
  static cancel(t) {
    return c.cancel(t);
  }
  currentId = s;
  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 f() {
  const e = i(h.create).current;
  return l(e.disposeEffect), e;
}
export {
  f as n,
  h as t
};

//# sourceMappingURL=useAnimationFrame.js.map