{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-media-query",
  "title": "useMediaQuery",
  "description": "Reactive media query hook with Tailwind-like breakpoint syntax, built on useSyncExternalStore for SSR safety.",
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/base/hooks/use-media-query.ts",
      "content": "\"use client\"\n\nimport { useCallback, useSyncExternalStore } from \"react\"\n\nconst BREAKPOINTS = {\n  \"2xl\": 1536,\n  \"3xl\": 1600,\n  \"4xl\": 2000,\n  lg: 1024,\n  md: 800,\n  sm: 640,\n  xl: 1280,\n} as const\n\ntype Breakpoint = keyof typeof BREAKPOINTS\ntype BreakpointQuery =\n  Breakpoint | `max-${Breakpoint}` | `${Breakpoint}:max-${Breakpoint}`\n\nfunction resolveMin(value: Breakpoint | number): string {\n  const px = typeof value === \"number\" ? value : BREAKPOINTS[value]\n  return `(min-width: ${px}px)`\n}\n\nfunction resolveMax(value: Breakpoint | number): string {\n  const px = typeof value === \"number\" ? value : BREAKPOINTS[value]\n  return `(max-width: ${px - 1}px)`\n}\n\n/**\n * @internal exported for unit tests; not part of the public API.\n */\nexport function parseQuery(\n  query: BreakpointQuery | MediaQueryInput | (string & {})\n): string {\n  if (typeof query !== \"string\") {\n    const parts: string[] = []\n    if (query.min != null) parts.push(resolveMin(query.min))\n    if (query.max != null) parts.push(resolveMax(query.max))\n    if (query.pointer === \"coarse\") parts.push(\"(pointer: coarse)\")\n    if (query.pointer === \"fine\") parts.push(\"(pointer: fine)\")\n    if (parts.length === 0) return \"(min-width: 0px)\"\n    return parts.join(\" and \")\n  }\n\n  if (query.startsWith(\"(\")) return query\n\n  const parts: string[] = []\n  for (const segment of query.split(\":\")) {\n    if (segment.startsWith(\"max-\")) {\n      const bp = segment.slice(4)\n      if (bp in BREAKPOINTS) parts.push(resolveMax(bp as Breakpoint))\n    } else if (segment in BREAKPOINTS) {\n      parts.push(resolveMin(segment as Breakpoint))\n    }\n  }\n\n  return parts.length > 0 ? parts.join(\" and \") : query\n}\n\nfunction getServerSnapshot(): boolean {\n  return false\n}\n\nexport type MediaQueryInput = {\n  min?: Breakpoint | number\n  max?: Breakpoint | number\n  /** Touch-like input (finger). Use \"fine\" for mouse/trackpad. */\n  pointer?: \"coarse\" | \"fine\"\n}\n\n/** Tracks a CSS media query with Tailwind-like breakpoint syntax. Returns `false` during SSR. */\nexport function useMediaQuery(\n  query: BreakpointQuery | MediaQueryInput | (string & {})\n): boolean {\n  const mediaQuery = parseQuery(query)\n\n  const subscribe = useCallback(\n    (callback: () => void) => {\n      if (typeof window === \"undefined\") return () => {}\n      const mql = window.matchMedia(mediaQuery)\n      mql.addEventListener(\"change\", callback)\n      return () => mql.removeEventListener(\"change\", callback)\n    },\n    [mediaQuery]\n  )\n\n  const getSnapshot = useCallback(() => {\n    if (typeof window === \"undefined\") return false\n    return window.matchMedia(mediaQuery).matches\n  }, [mediaQuery])\n\n  return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)\n}\n\nexport function useIsMobile(): boolean {\n  return useMediaQuery(\"max-md\")\n}\n",
      "type": "registry:hook"
    }
  ],
  "type": "registry:hook"
}