{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-scene-state",
  "title": "useSceneState",
  "author": "VenusUI",
  "description": "Theme color, on-screen state and reduced-motion preference for 3D scenes.",
  "files": [
    {
      "path": "registry/default/hooks/use-scene-state.ts",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nconst REDUCED_MOTION = \"(prefers-reduced-motion: reduce)\"\n\n/**\n * Converts any CSS color the browser understands (including oklch(), which\n * three.js can't parse) to an `rgb(r, g, b)` string by painting one pixel.\n */\nfunction toRgb(cssColor: string): string {\n  const canvas = document.createElement(\"canvas\")\n  canvas.width = canvas.height = 1\n  const context = canvas.getContext(\"2d\", { willReadFrequently: true })\n  if (!context) return \"rgb(255, 255, 255)\"\n  context.fillStyle = cssColor\n  context.fillRect(0, 0, 1, 1)\n  const [r, g, b] = context.getImageData(0, 0, 1, 1).data\n  return `rgb(${r}, ${g}, ${b})`\n}\n\ninterface SceneState {\n  /** The element's text color as `rgb()`, updated when the theme changes. */\n  color: string\n  /** True while the element is on screen and motion is allowed; use it to pause rendering. */\n  active: boolean\n  reducedMotion: boolean\n}\n\n/**\n * Shared state for 3D scenes: follows the CSS text color (so scenes match\n * light and dark themes), pauses when scrolled off screen, and respects the\n * user's reduced-motion setting.\n */\nexport function useSceneState<T extends HTMLElement>(ref: React.RefObject<T | null>): SceneState {\n  const [color, setColor] = React.useState(\"rgb(255, 255, 255)\")\n  const [inView, setInView] = React.useState(false)\n  const reducedMotion = React.useSyncExternalStore(\n    (onChange) => {\n      const query = window.matchMedia(REDUCED_MOTION)\n      query.addEventListener(\"change\", onChange)\n      return () => query.removeEventListener(\"change\", onChange)\n    },\n    () => window.matchMedia(REDUCED_MOTION).matches,\n    () => false\n  )\n\n  React.useEffect(() => {\n    const node = ref.current\n    if (!node) return\n    const update = () => setColor(toRgb(getComputedStyle(node).color))\n    const frame = requestAnimationFrame(update)\n    // Theme switches toggle a class on <html>; re-read the color when that happens.\n    const themeObserver = new MutationObserver(update)\n    themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: [\"class\", \"style\"] })\n    const visibility = new IntersectionObserver(([entry]) => setInView(Boolean(entry?.isIntersecting)))\n    visibility.observe(node)\n    return () => {\n      cancelAnimationFrame(frame)\n      themeObserver.disconnect()\n      visibility.disconnect()\n    }\n  }, [ref])\n\n  return { color, active: inView && !reducedMotion, reducedMotion }\n}\n",
      "type": "registry:hook"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "hooks",
    "3d"
  ],
  "type": "registry:hook"
}