{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ripple-grid",
  "type": "registry:component",
  "title": "Ripple Grid",
  "description": "A field of small tiles where a click or hover sends a radial wave that lifts, scales and lights them by distance. Ripples from the center on its own when idle.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "motion",
    "grid",
    "ripple",
    "wave",
    "background",
    "interactive",
    "dots"
  ],
  "docs": "https://hyperblur.dev/effects/ripple-grid",
  "files": [
    {
      "path": "registry/hyperblur/ripple-grid.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/ripple-grid.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface RippleGridProps extends React.HTMLAttributes<HTMLDivElement> {\n  rows?: number;\n  cols?: number;\n  shape?: \"dot\" | \"square\";\n  color?: string;\n  gap?: number;\n  autoPlay?: boolean;\n  interactive?: boolean;\n  interval?: number;\n}\n\nconst css = `\n@keyframes hb-rpg-wa {\n  0% { transform: translateY(0) scale(1); }\n  30% { transform: translateY(calc(var(--hb-rpg-a) * -18%)) scale(calc(1 + var(--hb-rpg-a) * 0.7)); }\n  100% { transform: translateY(0) scale(1); }\n}\n@keyframes hb-rpg-wb {\n  0% { transform: translateY(0) scale(1); }\n  30% { transform: translateY(calc(var(--hb-rpg-a) * -18%)) scale(calc(1 + var(--hb-rpg-a) * 0.7)); }\n  100% { transform: translateY(0) scale(1); }\n}\n@keyframes hb-rpg-la {\n  0% { opacity: 0; }\n  25% { opacity: var(--hb-rpg-a); }\n  100% { opacity: 0; }\n}\n@keyframes hb-rpg-lb {\n  0% { opacity: 0; }\n  25% { opacity: var(--hb-rpg-a); }\n  100% { opacity: 0; }\n}\n.hb-rpg {\n  position: relative;\n  box-sizing: border-box;\n  display: grid;\n  grid-template-columns: repeat(var(--hb-rpg-cols), minmax(0, 1fr));\n  grid-template-rows: repeat(var(--hb-rpg-rows), minmax(0, 1fr));\n  gap: var(--hb-rpg-gap);\n  width: 100%;\n  height: 100%;\n  min-height: 120px;\n  container-type: size;\n  touch-action: manipulation;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-rpg[data-interactive] { cursor: pointer; }\n.hb-rpg-cell {\n  display: grid;\n  place-items: center;\n  min-width: 0;\n  min-height: 0;\n  pointer-events: none;\n}\n.hb-rpg-dot {\n  position: relative;\n  --hb-rpg-cell: min(calc((100cqw - (var(--hb-rpg-cols) - 1) * var(--hb-rpg-gap)) / var(--hb-rpg-cols)), calc((100cqh - (var(--hb-rpg-rows) - 1) * var(--hb-rpg-gap)) / var(--hb-rpg-rows)));\n  width: calc(var(--hb-rpg-cell) * 0.8);\n  aspect-ratio: 1 / 1;\n  border-radius: 50%;\n  background: color-mix(in srgb, var(--hb-rpg-c) 14%, #19191c);\n  animation-duration: 1.1s;\n  animation-timing-function: cubic-bezier(.3, .7, .2, 1);\n  animation-fill-mode: both;\n  animation-delay: var(--hb-rpg-d);\n}\n.hb-rpg[data-shape=\"dot\"] .hb-rpg-dot { width: calc(var(--hb-rpg-cell) * 0.55); }\n.hb-rpg[data-shape=\"square\"] .hb-rpg-dot { border-radius: 26%; }\n.hb-rpg-dot::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  border-radius: inherit;\n  background: color-mix(in srgb, var(--hb-rpg-c) 70%, #ffffff);\n  box-shadow: 0 0 10px 1px var(--hb-rpg-c);\n  opacity: 0;\n  animation-duration: 1.1s;\n  animation-timing-function: cubic-bezier(.3, .7, .2, 1);\n  animation-fill-mode: both;\n  animation-delay: var(--hb-rpg-d);\n}\n.hb-rpg[data-wave=\"a\"] .hb-rpg-dot { animation-name: hb-rpg-wa; }\n.hb-rpg[data-wave=\"b\"] .hb-rpg-dot { animation-name: hb-rpg-wb; }\n.hb-rpg[data-wave=\"a\"] .hb-rpg-dot::after { animation-name: hb-rpg-la; }\n.hb-rpg[data-wave=\"b\"] .hb-rpg-dot::after { animation-name: hb-rpg-lb; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-rpg-dot, .hb-rpg-dot::after { animation: none !important; }\n}\n`;\n\ninterface Wave {\n  id: number;\n  r: number;\n  c: number;\n}\n\nexport function RippleGrid({\n  rows = 12,\n  cols = 20,\n  shape = \"square\",\n  color = \"#2f7bff\",\n  gap = 4,\n  autoPlay = true,\n  interactive = true,\n  interval = 3.6,\n  className = \"\",\n  style,\n  onPointerDown,\n  onPointerMove,\n  ...rest\n}: RippleGridProps) {\n  const R = Math.max(1, Math.round(rows));\n  const C = Math.max(1, Math.round(cols));\n  const ref = React.useRef<HTMLDivElement>(null);\n  const [wave, setWave] = React.useState<Wave | null>(null);\n  const lastRef = React.useRef({ t: 0, cell: -1 });\n\n  const fire = React.useCallback((r: number, c: number) => {\n    lastRef.current.t = performance.now();\n    setWave((w) => ({ id: (w ? w.id : 0) + 1, r, c }));\n  }, []);\n\n  React.useEffect(() => {\n    if (!autoPlay) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const every = Math.max(1.2, interval) * 1000;\n    const first = window.setTimeout(() => {\n      if (!document.hidden && !reduce.matches) fire((R - 1) / 2, (C - 1) / 2);\n    }, 500);\n    const id = window.setInterval(() => {\n      if (document.hidden || reduce.matches) return;\n      if (performance.now() - lastRef.current.t < every * 0.8) return;\n      fire((R - 1) / 2, (C - 1) / 2);\n    }, every);\n    return () => {\n      window.clearTimeout(first);\n      window.clearInterval(id);\n    };\n  }, [autoPlay, interval, R, C, fire]);\n\n  function cellAt(e: React.PointerEvent<HTMLDivElement>) {\n    const el = ref.current;\n    if (!el) return null;\n    const b = el.getBoundingClientRect();\n    if (b.width === 0 || b.height === 0) return null;\n    const c = Math.min(C - 1, Math.max(0, Math.floor(((e.clientX - b.left) / b.width) * C)));\n    const r = Math.min(R - 1, Math.max(0, Math.floor(((e.clientY - b.top) / b.height) * R)));\n    return { r, c };\n  }\n\n  function handleDown(e: React.PointerEvent<HTMLDivElement>) {\n    onPointerDown?.(e);\n    if (!interactive) return;\n    const p = cellAt(e);\n    if (p) fire(p.r, p.c);\n  }\n\n  function handleMove(e: React.PointerEvent<HTMLDivElement>) {\n    onPointerMove?.(e);\n    if (!interactive || e.pointerType === \"touch\") return;\n    const p = cellAt(e);\n    if (!p) return;\n    const cell = p.r * C + p.c;\n    if (cell === lastRef.current.cell) return;\n    lastRef.current.cell = cell;\n    if (performance.now() - lastRef.current.t < 650) return;\n    fire(p.r, p.c);\n  }\n\n  const maxDist = Math.hypot(Math.max(wave ? wave.r : 0, R - 1 - (wave ? wave.r : 0)), Math.max(wave ? wave.c : 0, C - 1 - (wave ? wave.c : 0))) || 1;\n\n  const cells = [];\n  for (let r = 0; r < R; r++) {\n    for (let c = 0; c < C; c++) {\n      let cellStyle: React.CSSProperties | undefined;\n      if (wave) {\n        const dist = Math.hypot(r - wave.r, c - wave.c);\n        const amp = Math.max(0.18, 1 - dist / (maxDist * 1.05));\n        cellStyle = {\n          \"--hb-rpg-d\": `${Math.round(dist * 42)}ms`,\n          \"--hb-rpg-a\": amp.toFixed(3),\n        } as React.CSSProperties;\n      }\n      cells.push(\n        <span key={r * C + c} className=\"hb-rpg-cell\">\n          <span className=\"hb-rpg-dot\" style={cellStyle} />\n        </span>,\n      );\n    }\n  }\n\n  const vars = {\n    \"--hb-rpg-rows\": R,\n    \"--hb-rpg-cols\": C,\n    \"--hb-rpg-gap\": `${Math.max(0, gap)}px`,\n    \"--hb-rpg-c\": color,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <div\n      ref={ref}\n      className={`hb-rpg ${className}`}\n      style={vars}\n      data-shape={shape}\n      data-wave={wave ? (wave.id % 2 === 0 ? \"a\" : \"b\") : undefined}\n      data-interactive={interactive ? \"\" : undefined}\n      aria-hidden=\"true\"\n      onPointerDown={handleDown}\n      onPointerMove={handleMove}\n      {...rest}\n    >\n      <style href=\"hb-ripple-grid\" precedence=\"default\">{css}</style>\n      {cells}\n    </div>\n  );\n}\n"
    }
  ]
}