{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-radial-grid-reveal",
  "type": "registry:component",
  "title": "Motion Radial Grid Reveal",
  "description": "A tile grid that reveals as a wavefront spreading from one point, with a glowing ring riding the edge. Far tiles arrive later, softer and fainter, and clicking any tile moves the origin there.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "motion",
    "scroll",
    "grid",
    "stagger",
    "reveal",
    "gallery",
    "ripple"
  ],
  "docs": "https://hyperblur.dev/effects/motion-radial-grid-reveal",
  "files": [
    {
      "path": "registry/hyperblur/motion-radial-grid-reveal.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/motion-radial-grid-reveal.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MotionRadialGridTile {\n  label: string;\n  from: string;\n  to: string;\n}\n\nexport interface MotionRadialGridRevealProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n  tiles?: MotionRadialGridTile[];\n  columns?: number;\n  origin?: [number, number];\n  fade?: number;\n  band?: number;\n  gap?: number;\n  accent?: string;\n  progress?: number;\n  autoPlay?: boolean;\n  duration?: number;\n  onTileClick?: (index: number, tile: MotionRadialGridTile) => void;\n}\n\nconst palette: [string, string][] = [\n  [\"#1d3b8f\", \"#5b8cff\"],\n  [\"#3a1f6e\", \"#a07bff\"],\n  [\"#0f4d47\", \"#3fd2b5\"],\n  [\"#5a2a12\", \"#ff9a5a\"],\n  [\"#2b2b2b\", \"#8a8a8a\"],\n  [\"#5b1630\", \"#ff6f9a\"],\n  [\"#173d1f\", \"#7fd67a\"],\n  [\"#4a3a10\", \"#f2c94c\"],\n];\n\nconst names = [\n  \"Dune\", \"Harbor\", \"Ember\", \"Moss\", \"Slate\", \"Coral\", \"Fern\", \"Amber\",\n  \"Tide\", \"Ash\", \"Plum\", \"Sage\", \"Rust\", \"Mist\", \"Ink\", \"Clay\",\n  \"Glow\", \"Pine\", \"Opal\", \"Iris\", \"Sand\", \"Bay\", \"Kelp\", \"Dusk\",\n  \"Frost\", \"Nova\", \"Reed\", \"Fig\", \"Loam\", \"Jade\", \"Haze\", \"Flint\",\n];\n\nfunction hash(n: number) {\n  let x = (n + 1) * 2654435761;\n  x = Math.imul(x ^ (x >>> 15), 2246822519);\n  x = Math.imul(x ^ (x >>> 13), 3266489917);\n  return (x ^ (x >>> 16)) >>> 0;\n}\n\nconst defaultTiles: MotionRadialGridTile[] = names.map((label, i) => {\n  const pair = palette[hash(i) % palette.length];\n  return { label, from: pair[0], to: pair[1] };\n});\n\nconst css = `\n.hb-wh2 {\n  --hb-wh2-a: #2f7bff;\n  --hb-wh2-p: 0;\n  position: relative;\n  width: 100%;\n  color: #ededed;\n  font-family: inherit;\n  container-type: inline-size;\n}\n.hb-wh2 *, .hb-wh2 *::before, .hb-wh2 *::after { box-sizing: border-box; }\n.hb-wh2-grid {\n  position: relative;\n  display: grid;\n  grid-template-columns: repeat(var(--hb-wh2-cols), minmax(0, 1fr));\n  gap: var(--hb-wh2-gap);\n  isolation: isolate;\n}\n.hb-wh2-ring {\n  position: absolute;\n  left: calc(var(--hb-wh2-ox) * 100%);\n  top: calc(var(--hb-wh2-oy) * 100%);\n  z-index: 2;\n  width: calc(var(--hb-wh2-w) * var(--hb-wh2-diag) * 2);\n  aspect-ratio: 1;\n  border-radius: 50%;\n  border: 1px solid color-mix(in srgb, var(--hb-wh2-a) 70%, #fff);\n  box-shadow: 0 0 24px 2px color-mix(in srgb, var(--hb-wh2-a) 45%, transparent), inset 0 0 24px 2px color-mix(in srgb, var(--hb-wh2-a) 30%, transparent);\n  transform: translate(-50%, -50%);\n  opacity: calc(clamp(0, var(--hb-wh2-p) * 12, 1) * clamp(0, (1 - var(--hb-wh2-p)) * 3.2, 1) * 0.85);\n  pointer-events: none;\n}\n.hb-wh2-tile {\n  --hb-wh2-t: clamp(0, calc((var(--hb-wh2-p) * (1 + var(--hb-wh2-band)) - var(--d)) / var(--hb-wh2-band)), 1);\n  position: relative;\n  display: flex;\n  align-items: flex-end;\n  aspect-ratio: 1;\n  min-width: 0;\n  padding: 0;\n  border: 0;\n  border-radius: clamp(4px, 1.4cqw, 14px);\n  overflow: hidden;\n  cursor: pointer;\n  font: inherit;\n  color: inherit;\n  text-align: left;\n  background: linear-gradient(145deg, var(--to), var(--from) 70%);\n  opacity: calc(var(--hb-wh2-t) * (1 - var(--d) * var(--hb-wh2-fade)));\n  transform: translate(calc((1 - var(--hb-wh2-t)) * var(--dx) * -18px), calc((1 - var(--hb-wh2-t)) * var(--dy) * -18px)) scale(calc(0.55 + var(--hb-wh2-t) * 0.45));\n  filter: blur(calc((1 - var(--hb-wh2-t)) * 6px)) saturate(calc(0.4 + var(--hb-wh2-t) * 0.6));\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), inset 0 -18px 30px -16px rgba(0, 0, 0, 0.55);\n  transition: box-shadow 0.25s ease;\n}\n.hb-wh2-tile::before {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  background:\n    radial-gradient(70% 60% at var(--gx) var(--gy), rgba(255, 255, 255, 0.32), transparent 60%),\n    repeating-linear-gradient(var(--ga), rgba(255, 255, 255, 0.05) 0 2px, transparent 2px 7px);\n  mix-blend-mode: soft-light;\n}\n.hb-wh2-tile::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  border-radius: inherit;\n  background: color-mix(in srgb, var(--hb-wh2-a) 85%, #fff);\n  opacity: calc(var(--hb-wh2-t) * (1 - var(--hb-wh2-t)) * 2.6);\n  mix-blend-mode: screen;\n  pointer-events: none;\n}\n.hb-wh2-tile:hover { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5), inset 0 -18px 30px -16px rgba(0, 0, 0, 0.55); }\n.hb-wh2-tile:focus-visible { outline: 2px solid var(--hb-wh2-a); outline-offset: 2px; }\n.hb-wh2-tile[data-origin=\"true\"] { box-shadow: inset 0 0 0 1.5px #fff, 0 0 0 3px color-mix(in srgb, var(--hb-wh2-a) 45%, transparent); }\n.hb-wh2-name {\n  position: relative;\n  z-index: 1;\n  width: 100%;\n  padding: 0 0.6em 0.5em;\n  font-size: clamp(7px, 1.25cqw, 13px);\n  font-weight: 600;\n  letter-spacing: 0.01em;\n  color: rgba(255, 255, 255, 0.92);\n  white-space: nowrap;\n  overflow: hidden;\n  text-overflow: ellipsis;\n  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);\n}\n@container (max-width: 420px) {\n  .hb-wh2-name { display: none; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-wh2-tile { transition: none; }\n  .hb-wh2-ring { display: none; }\n}\n`;\n\nfunction clamp01(x: number) {\n  return Math.min(1, Math.max(0, x));\n}\n\nfunction findScroller(el: HTMLElement): HTMLElement | null {\n  let node = el.parentElement;\n  while (node && node !== document.body && node !== document.documentElement) {\n    const oy = getComputedStyle(node).overflowY;\n    if ((oy === \"auto\" || oy === \"scroll\" || oy === \"overlay\") && node.scrollHeight > node.clientHeight + 1) return node;\n    node = node.parentElement;\n  }\n  return null;\n}\n\nfunction loopAt(ms: number, duration: number) {\n  const d = Math.max(1, duration) * 1000;\n  const out = d * 0.5;\n  const hold = 1500;\n  const t = ms % (d + hold + out + 500);\n  if (t < d) return 1 - Math.pow(1 - t / d, 2);\n  if (t < d + hold) return 1;\n  if (t < d + hold + out) return 1 - Math.pow((t - d - hold) / out, 2);\n  return 0;\n}\n\nfunction useProgress(\n  ref: React.RefObject<HTMLElement | null>,\n  apply: (p: number) => void,\n  progress: number | undefined,\n  autoPlay: boolean,\n  duration: number,\n  restart: number,\n) {\n  const applyRef = React.useRef(apply);\n  React.useLayoutEffect(() => {\n    applyRef.current = apply;\n  });\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const run = (p: number) => applyRef.current(clamp01(p));\n    if (typeof progress === \"number\") {\n      run(progress);\n      return;\n    }\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) {\n      run(1);\n      return;\n    }\n    let raf = 0;\n    if (autoPlay) {\n      let visible = true;\n      let last = 0;\n      let t = 0;\n      const io = new IntersectionObserver((entries) => {\n        visible = entries[0]?.isIntersecting ?? true;\n      });\n      io.observe(el);\n      const loop = (now: number) => {\n        const dt = last ? Math.min(64, now - last) : 0;\n        last = now;\n        if (visible) {\n          t += dt;\n          run(loopAt(t, duration));\n        }\n        raf = requestAnimationFrame(loop);\n      };\n      raf = requestAnimationFrame(loop);\n      return () => {\n        cancelAnimationFrame(raf);\n        io.disconnect();\n      };\n    }\n    const sc = findScroller(el);\n    const measure = () => {\n      raf = 0;\n      const r = el.getBoundingClientRect();\n      const top = sc ? r.top - sc.getBoundingClientRect().top : r.top;\n      const vh = sc ? sc.clientHeight : window.innerHeight;\n      run((vh - top) / (vh * 0.55 + r.height * 0.45));\n    };\n    const onScroll = () => {\n      if (!raf) raf = requestAnimationFrame(measure);\n    };\n    measure();\n    const target: HTMLElement | Window = sc ?? window;\n    target.addEventListener(\"scroll\", onScroll, { passive: true });\n    window.addEventListener(\"resize\", onScroll);\n    return () => {\n      cancelAnimationFrame(raf);\n      target.removeEventListener(\"scroll\", onScroll);\n      window.removeEventListener(\"resize\", onScroll);\n    };\n  }, [ref, progress, autoPlay, duration, restart]);\n}\n\nexport function MotionRadialGridReveal({\n  tiles = defaultTiles,\n  columns = 8,\n  origin = [0.5, 0.5],\n  fade = 0.45,\n  band = 0.35,\n  gap = 8,\n  accent = \"#2f7bff\",\n  progress,\n  autoPlay = false,\n  duration = 3.2,\n  onTileClick,\n  className,\n  style,\n  ...rest\n}: MotionRadialGridRevealProps) {\n  const ref = React.useRef<HTMLDivElement>(null);\n  const [picked, setPicked] = React.useState<number | null>(null);\n  const [restart, setRestart] = React.useState(0);\n  const cols = Math.max(1, Math.round(columns));\n  const rows = Math.max(1, Math.ceil(tiles.length / cols));\n\n  const ox = picked === null ? clamp01(origin[0]) : ((picked % cols) + 0.5) / cols;\n  const oy = picked === null ? clamp01(origin[1]) : (Math.floor(picked / cols) + 0.5) / rows;\n  const fx = Math.max(ox, 1 - ox) * cols;\n  const fy = Math.max(oy, 1 - oy) * rows;\n  const far = Math.hypot(fx, fy) || 1;\n\n  useProgress(\n    ref,\n    (p) => {\n      const el = ref.current;\n      if (!el) return;\n      el.style.setProperty(\"--hb-wh2-p\", p.toFixed(4));\n      el.style.setProperty(\"--hb-wh2-w\", (p * (1 + band)).toFixed(4));\n    },\n    progress,\n    autoPlay,\n    duration,\n    restart,\n  );\n\n  return (\n    <div\n      ref={ref}\n      className={[\"hb-wh2\", className].filter(Boolean).join(\" \")}\n      style={\n        {\n          \"--hb-wh2-a\": accent,\n          \"--hb-wh2-cols\": cols,\n          \"--hb-wh2-gap\": `${gap}px`,\n          \"--hb-wh2-fade\": clamp01(fade),\n          \"--hb-wh2-band\": Math.max(0.05, band),\n          \"--hb-wh2-ox\": ox.toFixed(4),\n          \"--hb-wh2-oy\": oy.toFixed(4),\n          \"--hb-wh2-diag\": `${(Math.hypot(Math.max(ox, 1 - ox), Math.max(oy, 1 - oy) * (rows / cols)) * 100).toFixed(2)}cqw`,\n          ...style,\n        } as React.CSSProperties\n      }\n      {...rest}\n    >\n      <style href=\"hb-motion-radial-grid-reveal\" precedence=\"default\">{css}</style>\n      <div className=\"hb-wh2-grid\">\n        <span className=\"hb-wh2-ring\" aria-hidden=\"true\" />\n        {tiles.map((tile, i) => {\n          const cx = (i % cols) + 0.5 - ox * cols;\n          const cy = Math.floor(i / cols) + 0.5 - oy * rows;\n          const len = Math.hypot(cx, cy);\n          const d = len / far;\n          const h = hash(i + 97);\n          return (\n            <button\n              key={`${tile.label}-${i}`}\n              type=\"button\"\n              className=\"hb-wh2-tile\"\n              data-origin={picked === i ? \"true\" : \"false\"}\n              aria-label={`${tile.label}, start the reveal from here`}\n              onClick={() => {\n                setPicked(i);\n                setRestart((r) => r + 1);\n                onTileClick?.(i, tile);\n              }}\n              style={\n                {\n                  \"--d\": d.toFixed(4),\n                  \"--dx\": len ? (cx / len).toFixed(3) : \"0\",\n                  \"--dy\": len ? (cy / len).toFixed(3) : \"0\",\n                  \"--from\": tile.from,\n                  \"--to\": tile.to,\n                  \"--gx\": `${20 + (h % 60)}%`,\n                  \"--gy\": `${15 + ((h >>> 8) % 50)}%`,\n                  \"--ga\": `${(h >>> 16) % 180}deg`,\n                } as React.CSSProperties\n              }\n            >\n              <span className=\"hb-wh2-name\">{tile.label}</span>\n            </button>\n          );\n        })}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}