{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "color-reveal-grid",
  "title": "Color Reveal Grid",
  "description": "A grid of black-and-white photos where colour floods in from the exact point the pointer enters a tile, a little colour seeps into the neighbouring tiles, and it drains back out toward where the pointer leaves; captions slide up over each revealed photo.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/color-reveal-grid/color-reveal-grid.tsx",
      "content": "\"use client\";\n/* eslint-disable @next/next/no-img-element -- Registry components work in any React app. */\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface ColorRevealItem {\n  src: string;\n  alt?: string;\n  title: string;\n  /** Small mono line under the title, e.g. a place or year. */\n  meta?: string;\n  href?: string;\n}\n\nexport type ColorRevealTheme = \"dark\" | \"light\";\n\nexport interface ColorRevealGridProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"children\"> {\n  items?: ColorRevealItem[];\n  /** Most columns on wide containers; narrower containers drop to fit tiles of at least minTileWidth. */\n  columns?: number;\n  minTileWidth?: number;\n  gap?: number;\n  radius?: number;\n  /** Tile width / height. */\n  aspectRatio?: number;\n  /** Let a little colour seep into the tiles next to the hovered one. */\n  bleed?: boolean;\n  /** Reveal time in ms. */\n  duration?: number;\n  theme?: ColorRevealTheme;\n}\n\nconst ITEMS: ColorRevealItem[] = [\n  { src: \"/demo/pages/non-profit-charity/surface.webp\", title: \"Surface\", meta: \"Red Sea · 2026\" },\n  { src: \"/demo/pages/gym-fitness/recovery.webp\", title: \"Cedar heat\", meta: \"Helsinki · 2025\" },\n  { src: \"/demo/pages/digital-agency/fluid.webp\", title: \"Soft matter\", meta: \"Studio · 2026\" },\n  { src: \"/demo/blocks/ai-image-generation-grid/neon-1.webp\", title: \"After rain\", meta: \"Osaka · 2025\" },\n  { src: \"/demo/pages/wedding-planner/bosphorus.webp\", title: \"Golden hour\", meta: \"Istanbul · 2026\" },\n  { src: \"/demo/pages/law-firm/skyline.webp\", title: \"Rust\", meta: \"Chicago · 2024\" },\n  { src: \"/demo/pages/yacht-boat-rental/hero.webp\", title: \"Shallows\", meta: \"Paros · 2025\" },\n  { src: \"/demo/pages/restaurant-cafe/sourdough-toast.webp\", title: \"Morning\", meta: \"Lisbon · 2026\" },\n  { src: \"/demo/blocks/ai-image-generation-grid/glass-3.webp\", title: \"Glasshouse\", meta: \"Kew · 2025\" },\n  { src: \"/demo/pages/travel-agency/hero.webp\", title: \"Lift-off\", meta: \"Cappadocia · 2026\" },\n  { src: \"/demo/pages/hotel-booking/breakfast.webp\", title: \"Late table\", meta: \"Marseille · 2025\" },\n  { src: \"/demo/pages/drone-delivery/city-valley-night.webp\", title: \"Valley lights\", meta: \"Medellín · 2024\" },\n];\n\ntype Tile = HTMLElement & { dataset: { index: string } };\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nexport function ColorRevealGrid({\n  items = ITEMS,\n  columns = 4,\n  minTileWidth = 150,\n  gap = 10,\n  radius = 14,\n  aspectRatio = 4 / 5,\n  bleed = true,\n  duration = 700,\n  theme = \"dark\",\n  className,\n  style,\n  ...props\n}: ColorRevealGridProps) {\n  const reduce = useReducedMotion();\n  const gridRef = React.useRef<HTMLDivElement>(null);\n  const [cols, setCols] = React.useState(columns);\n  const active = React.useRef<number | null>(null);\n  const light = theme === \"light\";\n\n  React.useEffect(() => {\n    const grid = gridRef.current;\n    if (!grid) return;\n    const observer = new ResizeObserver(() => {\n      const w = grid.clientWidth;\n      setCols(Math.max(1, Math.min(columns, Math.floor((w + gap) / (minTileWidth + gap)))));\n    });\n    observer.observe(grid);\n    return () => observer.disconnect();\n  }, [columns, gap, minTileWidth]);\n\n  const tiles = () => Array.from(gridRef.current?.querySelectorAll<Tile>(\"[data-index]\") ?? []);\n  const colorLayer = (tile: Tile) => tile.querySelector<HTMLElement>(\"[data-color]\")!;\n  const bleedLayer = (tile: Tile) => tile.querySelector<HTMLElement>(\"[data-bleed]\")!;\n\n  // The seep into a neighbour is a soft radial mask that fades in, not a hard-edged circle.\n  const setBleed = (tile: Tile, x: number, y: number, r: number, on: boolean) => {\n    const layer = bleedLayer(tile);\n    if (on) {\n      layer.style.setProperty(\"--bx\", `${x}px`);\n      layer.style.setProperty(\"--by\", `${y}px`);\n      layer.style.setProperty(\"--br\", `${r}px`);\n    }\n    layer.style.opacity = on ? \"1\" : \"0\";\n  };\n\n  // Grow (or shrink) the colour circle. The position jumps first with no transition, then the radius\n  // eases, so every reveal starts exactly where the pointer crossed into the tile.\n  const setCircle = (tile: Tile, x: number, y: number, r: number, ms: number, jump: boolean) => {\n    const layer = colorLayer(tile);\n    if (jump) {\n      layer.style.transition = \"none\";\n      layer.style.clipPath = `circle(0px at ${x}px ${y}px)`;\n      void layer.offsetWidth;\n    }\n    layer.style.transition = reduce ? \"none\" : `clip-path ${ms}ms cubic-bezier(.22,1,.36,1)`;\n    layer.style.clipPath = `circle(${r}px at ${x}px ${y}px)`;\n  };\n\n  /** Local point inside a tile, in CSS pixels even under a scaled parent. */\n  const local = (tile: Tile, clientX: number, clientY: number) => {\n    const r = tile.getBoundingClientRect();\n    const scale = r.width / tile.offsetWidth || 1;\n    return { x: (clientX - r.left) / scale, y: (clientY - r.top) / scale, w: tile.offsetWidth, h: tile.offsetHeight };\n  };\n\n  const reveal = (tile: Tile, clientX: number, clientY: number) => {\n    const index = Number(tile.dataset.index);\n    if (active.current === index) return;\n    active.current = index;\n    const p = local(tile, clientX, clientY);\n    // Big enough to reach the farthest corner from the entry point.\n    const reach = Math.hypot(Math.max(p.x, p.w - p.x), Math.max(p.y, p.h - p.y)) + 2;\n    setCircle(tile, p.x, p.y, reach, duration, tile.dataset.on !== \"true\");\n    setBleed(tile, 0, 0, 0, false);\n    tile.dataset.on = \"true\";\n\n    for (const other of tiles()) {\n      if (other === tile) continue;\n      const near = bleed && isNeighbour(tile, other);\n      if (near) {\n        // A small pool of colour on the edge that faces the hovered tile, aimed at its centre.\n        const tr = tile.getBoundingClientRect();\n        const q = local(other, tr.left + tr.width / 2, tr.top + tr.height / 2);\n        const x = Math.max(0, Math.min(q.w, q.x));\n        const y = Math.max(0, Math.min(q.h, q.y));\n        if (other.dataset.on === \"true\") {\n          // A tile that was fully revealed drains away while the soft pool fades in.\n          const m = /at ([\\d.]+)px ([\\d.]+)px/.exec(colorLayer(other).style.clipPath);\n          setCircle(other, Number(m?.[1] ?? 0), Number(m?.[2] ?? 0), 0, duration * 0.7, false);\n        }\n        setBleed(other, x, y, Math.min(q.w, q.h) * 0.62, true);\n        other.dataset.on = \"bleed\";\n      } else if (other.dataset.on) {\n        setBleed(other, 0, 0, 0, false);\n        const layer = colorLayer(other);\n        const m = /at ([\\d.]+)px ([\\d.]+)px/.exec(layer.style.clipPath);\n        setCircle(other, Number(m?.[1] ?? 0), Number(m?.[2] ?? 0), 0, duration * 0.7, false);\n        delete other.dataset.on;\n      }\n    }\n  };\n\n  const conceal = (tile: Tile | null, clientX?: number, clientY?: number) => {\n    for (const t of tiles()) {\n      if (!t.dataset.on) continue;\n      setBleed(t, 0, 0, 0, false);\n      if (t === tile && clientX !== undefined && clientY !== undefined) {\n        // Collapse toward where the pointer left.\n        const p = local(t, clientX, clientY);\n        setCircle(t, Math.max(0, Math.min(p.w, p.x)), Math.max(0, Math.min(p.h, p.y)), 0, duration * 0.8, false);\n      } else {\n        const m = /at ([\\d.]+)px ([\\d.]+)px/.exec(colorLayer(t).style.clipPath);\n        setCircle(t, Number(m?.[1] ?? 0), Number(m?.[2] ?? 0), 0, duration * 0.7, false);\n      }\n      delete t.dataset.on;\n    }\n    active.current = null;\n  };\n\n  return (\n    <div\n      ref={gridRef}\n      role=\"list\"\n      className={cn(\"grid w-full\", className)}\n      style={{ gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))`, gap, ...style }}\n      onPointerLeave={(event) => {\n        if (event.pointerType === \"mouse\") conceal(null);\n      }}\n      {...props}\n    >\n      {items.map((item, i) => {\n        const Tag = item.href ? \"a\" : \"div\";\n        return (\n          <div key={item.src + i} role=\"listitem\" className=\"min-w-0\">\n            <Tag\n              {...(item.href ? { href: item.href } : { tabIndex: 0 })}\n              data-index={i}\n              aria-label={`${item.title}${item.meta ? `, ${item.meta}` : \"\"}`}\n              className=\"group/tile relative block w-full overflow-hidden outline-none select-none focus-visible:ring-2 focus-visible:ring-offset-2\"\n              style={{\n                aspectRatio,\n                borderRadius: radius,\n                background: light ? \"#dedede\" : \"#1a1a1a\",\n                [\"--tw-ring-color\" as string]: light ? \"#141414\" : \"#f4f4f2\",\n                [\"--tw-ring-offset-color\" as string]: light ? \"#f1f1ef\" : \"#0a0a0a\",\n              }}\n              onPointerEnter={(event: React.PointerEvent<HTMLElement>) => {\n                if (event.pointerType === \"mouse\") reveal(event.currentTarget as Tile, event.clientX, event.clientY);\n              }}\n              onPointerLeave={(event: React.PointerEvent<HTMLElement>) => {\n                if (event.pointerType !== \"mouse\") return;\n                const to = event.relatedTarget as Node | null;\n                // Moving across the gap to another tile is handled by that tile's enter.\n                if (!gridRef.current?.contains(to)) conceal(event.currentTarget as Tile, event.clientX, event.clientY);\n              }}\n              onPointerDown={(event: React.PointerEvent<HTMLElement>) => {\n                if (event.pointerType === \"mouse\") return;\n                const tile = event.currentTarget as Tile;\n                if (active.current === i) conceal(tile, event.clientX, event.clientY);\n                else reveal(tile, event.clientX, event.clientY);\n              }}\n              onFocus={(event: React.FocusEvent<HTMLElement>) => {\n                if (!event.currentTarget.matches(\":focus-visible\")) return;\n                const r = event.currentTarget.getBoundingClientRect();\n                reveal(event.currentTarget as Tile, r.left + r.width / 2, r.top + r.height / 2);\n              }}\n              onBlur={(event: React.FocusEvent<HTMLElement>) => {\n                if (!gridRef.current?.contains(event.relatedTarget)) conceal(null);\n              }}\n            >\n              <img src={item.src} alt=\"\" draggable={false} loading=\"lazy\" decoding=\"async\" className=\"absolute inset-0 h-full w-full object-cover\" style={{ filter: \"grayscale(1) contrast(1.08) brightness(.92)\" }} />\n              <div\n                data-bleed=\"\"\n                aria-hidden=\"true\"\n                className=\"absolute inset-0 opacity-0 transition-opacity duration-700 ease-out motion-reduce:transition-none\"\n                style={{\n                  maskImage: \"radial-gradient(circle var(--br, 0px) at var(--bx, 50%) var(--by, 50%), #000 0%, rgba(0,0,0,.55) 45%, transparent 100%)\",\n                  WebkitMaskImage: \"radial-gradient(circle var(--br, 0px) at var(--bx, 50%) var(--by, 50%), #000 0%, rgba(0,0,0,.55) 45%, transparent 100%)\",\n                }}\n              >\n                <img src={item.src} alt=\"\" draggable={false} loading=\"lazy\" decoding=\"async\" className=\"absolute inset-0 h-full w-full object-cover\" />\n              </div>\n              <div data-color=\"\" aria-hidden=\"true\" className=\"absolute inset-0\" style={{ clipPath: \"circle(0px at 50% 50%)\" }}>\n                <img src={item.src} alt={item.alt ?? \"\"} draggable={false} loading=\"lazy\" decoding=\"async\" className=\"absolute inset-0 h-full w-full object-cover transition-transform duration-700 ease-out group-data-[on=true]/tile:scale-[1.04] motion-reduce:transition-none\" />\n              </div>\n              <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-x-0 bottom-0 h-1/2 bg-gradient-to-t from-black/70 to-transparent opacity-0 transition-opacity duration-500 group-data-[on=true]/tile:opacity-100\" />\n              <div className=\"pointer-events-none absolute inset-x-0 bottom-0 translate-y-2 p-3.5 text-white opacity-0 transition-all duration-500 group-data-[on=true]/tile:translate-y-0 group-data-[on=true]/tile:opacity-100 motion-reduce:transition-none\">\n                <p className=\"text-[14px] leading-tight font-medium\">{item.title}</p>\n                {item.meta && <p className=\"mt-0.5 font-mono text-[10px] text-white/70\">{item.meta}</p>}\n              </div>\n              <span aria-hidden=\"true\" className=\"pointer-events-none absolute top-3 left-3 font-mono text-[10px] text-white/70 mix-blend-difference\">\n                {String(i + 1).padStart(2, \"0\")}\n              </span>\n            </Tag>\n          </div>\n        );\n      })}\n    </div>\n  );\n}\n\n/** Tiles that share an edge (not just a corner) with the hovered one, allowing for the gap between them. */\nfunction isNeighbour(a: HTMLElement, b: HTMLElement) {\n  const ra = a.getBoundingClientRect();\n  const rb = b.getBoundingClientRect();\n  const slack = Math.max(ra.width, ra.height) * 0.2;\n  const overlapX = Math.min(ra.right, rb.right) - Math.max(ra.left, rb.left);\n  const overlapY = Math.min(ra.bottom, rb.bottom) - Math.max(ra.top, rb.top);\n  const gapX = Math.max(rb.left - ra.right, ra.left - rb.right);\n  const gapY = Math.max(rb.top - ra.bottom, ra.top - rb.bottom);\n  return (overlapY > ra.height * 0.3 && gapX >= -1 && gapX < slack) || (overlapX > ra.width * 0.3 && gapY >= -1 && gapY < slack);\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}