{
  "name": "use-document-visibility",
  "author": "Brendan Dash (https://shadcn-hooks.com)",
  "description": "A hook to track the document visibility state",
  "files": [
    {
      "path": "registry/hooks/use-document-visibility.ts",
      "content": "import { useSyncExternalStore } from 'react'\n\nconst DEFAULT_VISIBILITY_STATE: DocumentVisibilityState = 'visible'\n\nfunction subscribe(onStoreChange: () => void) {\n  if (typeof document === 'undefined') {\n    return () => {}\n  }\n\n  document.addEventListener('visibilitychange', onStoreChange, {\n    passive: true,\n  })\n\n  return () => {\n    document.removeEventListener('visibilitychange', onStoreChange)\n  }\n}\n\nfunction getSnapshot(): DocumentVisibilityState {\n  if (typeof document === 'undefined') {\n    return DEFAULT_VISIBILITY_STATE\n  }\n\n  return document.visibilityState\n}\n\nfunction getServerSnapshot(): DocumentVisibilityState {\n  return DEFAULT_VISIBILITY_STATE\n}\n\n/**\n * Reactively track `document.visibilityState`.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilityState\n * @returns The current document visibility state.\n */\nexport function useDocumentVisibility(): DocumentVisibilityState {\n  return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)\n}\n",
      "type": "registry:hook"
    }
  ],
  "type": "registry:hook"
}
