{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "theme-transition",
  "title": "Theme transition",
  "description": "Switches light and dark with a rising view transition; reduced motion swaps at once.",
  "registryDependencies": [
    "@khaeli/motion"
  ],
  "files": [
    {
      "path": "registry/khaeli/lib/theme-transition.ts",
      "content": "import { flushSync } from \"react-dom\"\n\nimport { prefersReducedMotion } from \"@/lib/motion\"\n\nlet running: ViewTransition | null = null\n\n/**\n * Switches light and dark with Arc theme-switch's \"rise\" page transition\n * (the variant Arc recommends for product chrome): the next appearance rises\n * into place from the bottom edge over a view transition, timed in foundation.css\n * (`[data-theme-transition=\"rise\"]`). `apply` must change the theme, for\n * example `() => setTheme(\"dark\")` from next-themes; it runs inside\n * `flushSync` so the new class is on <html> before the new snapshot is taken.\n *\n * Without View Transitions, or with reduced motion, the theme swaps at once.\n */\nfunction runThemeTransition(apply: () => void) {\n  if (typeof document === \"undefined\") {\n    return\n  }\n  if (typeof document.startViewTransition !== \"function\" || prefersReducedMotion()) {\n    apply()\n    return\n  }\n  const root = document.documentElement\n  root.dataset.themeTransition = \"rise\"\n  // A second press mid-way skips the first transition to its end state and\n  // starts over from there; only the latest one clears the marker.\n  const transition = document.startViewTransition(() => {\n    flushSync(apply)\n  })\n  running = transition\n  void transition.finished.finally(() => {\n    if (running === transition) {\n      running = null\n      delete root.dataset.themeTransition\n    }\n  })\n}\n\nexport { runThemeTransition }\n",
      "type": "registry:lib"
    }
  ],
  "docs": "Pair with next-themes: runThemeTransition(() => setTheme(next)). The keyframes live in @khaeli/foundation.",
  "type": "registry:lib"
}