"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var useAnimationTick_exports = {};
__export(useAnimationTick_exports, {
  useAnimationTick: () => useAnimationTick
});
module.exports = __toCommonJS(useAnimationTick_exports);
var import_react = require("react");
const DEFAULT_INTERVAL_MS = 80;
let tick = 0;
let interval = null;
let intervalMs = DEFAULT_INTERVAL_MS;
const listeners = /* @__PURE__ */ new Set();
function start() {
  if (interval) return;
  interval = setInterval(() => {
    tick = (tick + 1) % 1e6;
    for (const listener of listeners) listener();
  }, intervalMs);
}
function stop() {
  if (!interval) return;
  clearInterval(interval);
  interval = null;
}
function subscribe(listener) {
  listeners.add(listener);
  start();
  return () => {
    listeners.delete(listener);
    if (listeners.size === 0) {
      stop();
    }
  };
}
function getSnapshot() {
  return tick;
}
function useAnimationTick(options) {
  const enabled = options?.enabled ?? true;
  const nextIntervalMs = options?.intervalMs ?? DEFAULT_INTERVAL_MS;
  if (nextIntervalMs < intervalMs) {
    intervalMs = nextIntervalMs;
    if (interval) {
      stop();
      start();
    }
  }
  return (0, import_react.useSyncExternalStore)(enabled ? subscribe : () => () => {
  }, getSnapshot, getSnapshot);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useAnimationTick
});
