{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hover-magnetic-icons",
  "type": "registry:component",
  "title": "Magnetic Icon Grid",
  "description": "A launcher grid where every icon is pulled toward the pointer by its own distance falloff and swells as it gets closer, so the grid bends like a field. The nearest icon gets a ring and a bright label.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "magnetic",
    "icons",
    "launcher",
    "grid",
    "pointer",
    "dock"
  ],
  "docs": "https://hyperblur.dev/effects/hover-magnetic-icons",
  "files": [
    {
      "path": "registry/hyperblur/hover-magnetic-icons.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/hover-magnetic-icons.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface HoverMagneticIconsItem {\n  label: string;\n  icon?: string;\n  tone?: string;\n}\n\nexport interface HoverMagneticIconsProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onSelect\"> {\n  items?: HoverMagneticIconsItem[];\n  columns?: number;\n  radius?: number;\n  strength?: number;\n  autoPlay?: boolean;\n  accent?: string;\n  onSelect?: (label: string, index: number) => void;\n}\n\nconst glyphs: Record<string, string> = {\n  calendar: \"M5 7h14v12H5zM5 10.5h14M9 4.5v4M15 4.5v4\",\n  mail: \"M4.5 7h15v10h-15zM4.5 7.5l7.5 6 7.5-6\",\n  chat: \"M5 6h14v9H11l-4 3.5V15H5z\",\n  music: \"M10 16.5V6.5l9-2v10M10 16.5a2.2 2.2 0 1 1-4.4 0 2.2 2.2 0 0 1 4.4 0zM19 14.5a2.2 2.2 0 1 1-4.4 0 2.2 2.2 0 0 1 4.4 0z\",\n  camera: \"M4.5 8.5h3l1.5-2h6l1.5 2h3v9.5h-15zM12 15.5a2.8 2.8 0 1 0 0-5.6 2.8 2.8 0 0 0 0 5.6z\",\n  map: \"M4.5 6.5l5-2 5 2 5-2v13l-5 2-5-2-5 2zM9.5 4.5v13M14.5 6.5v13\",\n  notes: \"M6.5 4.5h8l3 3v12h-11zM9 11h6M9 14h6M9 8h3\",\n  cloud: \"M7.5 17.5h9.5a3.5 3.5 0 0 0 .3-7 5 5 0 0 0-9.6-1A4 4 0 0 0 7.5 17.5z\",\n  wallet: \"M4.5 7.5h14v11h-14zM4.5 7.5l11-3v3M15 13h3.5\",\n  settings: \"M12 14.8a2.8 2.8 0 1 0 0-5.6 2.8 2.8 0 0 0 0 5.6zM12 3.8v2.4M12 17.8v2.4M3.8 12h2.4M17.8 12h2.4M6.2 6.2l1.7 1.7M16.1 16.1l1.7 1.7M6.2 17.8l1.7-1.7M16.1 7.9l1.7-1.7\",\n  photos: \"M4.5 6h15v12h-15zM4.5 15l4.5-4 4 3.5 2.5-2 4 3.5M15.5 9.5h.01\",\n  clock: \"M12 19.5a7.5 7.5 0 1 0 0-15 7.5 7.5 0 0 0 0 15zM12 8v4.5l3 2\",\n};\n\nconst defaults: HoverMagneticIconsItem[] = [\n  { label: \"Calendar\", icon: \"calendar\", tone: \"#ff6a5c\" },\n  { label: \"Mail\", icon: \"mail\", tone: \"#4c8dff\" },\n  { label: \"Messages\", icon: \"chat\", tone: \"#3ccf7a\" },\n  { label: \"Music\", icon: \"music\", tone: \"#ff4f8b\" },\n  { label: \"Camera\", icon: \"camera\", tone: \"#9aa3b2\" },\n  { label: \"Maps\", icon: \"map\", tone: \"#38c3a8\" },\n  { label: \"Notes\", icon: \"notes\", tone: \"#f5c242\" },\n  { label: \"Drive\", icon: \"cloud\", tone: \"#5fb0ff\" },\n  { label: \"Wallet\", icon: \"wallet\", tone: \"#8b6bff\" },\n  { label: \"Settings\", icon: \"settings\", tone: \"#7c8594\" },\n];\n\nconst css = `\n.hb-wg1 { --hb-wg1-accent: #2f7bff; position: relative; box-sizing: border-box; width: 100%; padding: 18px 14px; font-family: inherit; color: #ededed; isolation: isolate; touch-action: pan-y; }\n.hb-wg1 *, .hb-wg1 *::before, .hb-wg1 *::after { box-sizing: border-box; }\n.hb-wg1-field { position: absolute; left: 0; top: 0; width: 220px; height: 220px; margin: -110px 0 0 -110px; border-radius: 50%; pointer-events: none; z-index: -1; opacity: 0; background: radial-gradient(circle, color-mix(in srgb, var(--hb-wg1-accent) 22%, transparent) 0%, transparent 62%); will-change: transform, opacity; transition: opacity .4s cubic-bezier(.2,.7,.2,1); }\n.hb-wg1[data-live=\"true\"] .hb-wg1-field { opacity: 1; }\n.hb-wg1-grid { display: grid; grid-template-columns: repeat(var(--hb-wg1-cols), minmax(0, 1fr)); gap: 14px 10px; justify-items: center; }\n.hb-wg1-btn { appearance: none; border: 0; padding: 0; margin: 0; background: none; color: inherit; font: inherit; cursor: pointer; display: grid; justify-items: center; gap: 6px; outline: none; will-change: transform; -webkit-tap-highlight-color: transparent; }\n.hb-wg1-tile { position: relative; width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; background: linear-gradient(160deg, color-mix(in srgb, var(--hb-wg1-tone) 92%, #fff 8%) 0%, color-mix(in srgb, var(--hb-wg1-tone) 70%, #000 30%) 100%); box-shadow: inset 0 1px 0 rgba(255,255,255,.28), inset 0 -1px 0 rgba(0,0,0,.25), 0 6px 14px -6px color-mix(in srgb, var(--hb-wg1-tone) 70%, transparent), 0 2px 4px rgba(0,0,0,.4); transition: box-shadow .3s ease; }\n.hb-wg1-tile::after { content: \"\"; position: absolute; inset: 0; border-radius: inherit; background: linear-gradient(180deg, rgba(255,255,255,.22), rgba(255,255,255,0) 48%); pointer-events: none; }\n.hb-wg1-tile svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 1px 1px rgba(0,0,0,.25)); }\n.hb-wg1-label { font-size: 10px; line-height: 1; letter-spacing: .01em; color: #8f8f8f; white-space: nowrap; transition: color .25s ease; }\n.hb-wg1-btn[data-near=\"true\"] .hb-wg1-label { color: #ededed; }\n.hb-wg1-btn[data-near=\"true\"] .hb-wg1-tile { box-shadow: inset 0 1px 0 rgba(255,255,255,.3), 0 0 0 2px #0a0a0a, 0 0 0 3.5px var(--hb-wg1-accent), 0 12px 22px -8px color-mix(in srgb, var(--hb-wg1-tone) 80%, transparent); }\n.hb-wg1-btn:focus-visible .hb-wg1-tile { box-shadow: 0 0 0 2px #0a0a0a, 0 0 0 4px var(--hb-wg1-accent); }\n.hb-wg1-btn:active .hb-wg1-tile { filter: brightness(.88); }\n@media (prefers-reduced-motion: reduce) {\n  .hb-wg1-field { display: none; }\n  .hb-wg1-btn { transform: none !important; }\n}\n`;\n\nexport function HoverMagneticIcons({\n  items = defaults,\n  columns = 5,\n  radius = 120,\n  strength = 0.32,\n  autoPlay = true,\n  accent = \"#2f7bff\",\n  onSelect,\n  className = \"\",\n  style,\n  ...rest\n}: HoverMagneticIconsProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const fieldRef = React.useRef<HTMLSpanElement>(null);\n  const btnRefs = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const count = items.length;\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const field = fieldRef.current;\n    if (!root || !field) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const btns = btnRefs.current.slice(0, count).filter((b): b is HTMLButtonElement => !!b);\n    const state = btns.map(() => ({ x: 0, y: 0, s: 1 }));\n    let px = 0;\n    let py = 0;\n    let cx = root.clientWidth / 2;\n    let cy = root.clientHeight / 2;\n    let inside = false;\n    let mix = 0;\n    let t = 0;\n    let last = performance.now();\n    let raf = 0;\n    let visible = true;\n    let nearIdx = -1;\n\n    const frame = (now: number) => {\n      const dt = Math.min(0.05, (now - last) / 1000);\n      last = now;\n      t += dt;\n      const w = root.clientWidth;\n      const h = root.clientHeight;\n      const ax = w * (0.5 + 0.38 * Math.sin(t * 0.7));\n      const ay = h * (0.5 + 0.3 * Math.sin(t * 1.3 + 0.8));\n      mix += ((inside ? 1 : 0) - mix) * (1 - Math.exp(-dt * 6));\n      const tx = ax + (px - ax) * mix;\n      const ty = ay + (py - ay) * mix;\n      cx += (tx - cx) * (1 - Math.exp(-dt * 14));\n      cy += (ty - cy) * (1 - Math.exp(-dt * 14));\n      const live = inside || autoPlay;\n      root.dataset.live = live ? \"true\" : \"false\";\n      field.style.transform = `translate3d(${cx.toFixed(1)}px, ${cy.toFixed(1)}px, 0)`;\n      let best = -1;\n      let bestD = Infinity;\n      btns.forEach((b, i) => {\n        const bx = b.offsetLeft + b.offsetWidth / 2;\n        const by = b.offsetTop + 22;\n        const dx = cx - bx;\n        const dy = cy - by;\n        const d = Math.hypot(dx, dy);\n        const f = live ? Math.max(0, 1 - d / radius) : 0;\n        const e = f * f * (3 - 2 * f);\n        const goalX = dx * strength * e;\n        const goalY = dy * strength * e;\n        const goalS = 1 + 0.28 * e;\n        const st = state[i];\n        const k = 1 - Math.exp(-dt * 16);\n        st.x += (goalX - st.x) * k;\n        st.y += (goalY - st.y) * k;\n        st.s += (goalS - st.s) * k;\n        b.style.transform = `translate3d(${st.x.toFixed(2)}px, ${st.y.toFixed(2)}px, 0) scale(${st.s.toFixed(3)})`;\n        if (d < bestD && d < radius * 0.42) {\n          bestD = d;\n          best = i;\n        }\n      });\n      if (best !== nearIdx) {\n        if (nearIdx >= 0 && btns[nearIdx]) btns[nearIdx].dataset.near = \"false\";\n        if (best >= 0 && btns[best]) btns[best].dataset.near = \"true\";\n        nearIdx = best;\n      }\n      raf = requestAnimationFrame(frame);\n    };\n    const start = () => {\n      if (raf || !visible) return;\n      last = performance.now();\n      raf = requestAnimationFrame(frame);\n    };\n    const stop = () => {\n      if (raf) cancelAnimationFrame(raf);\n      raf = 0;\n    };\n    const locate = (e: PointerEvent) => {\n      const r = root.getBoundingClientRect();\n      const s = r.width ? root.offsetWidth / r.width : 1;\n      px = (e.clientX - r.left) * s;\n      py = (e.clientY - r.top) * s;\n    };\n    const onMove = (e: PointerEvent) => {\n      locate(e);\n      inside = true;\n    };\n    const onLeave = () => {\n      inside = false;\n    };\n    const onUp = (e: PointerEvent) => {\n      if (e.pointerType !== \"mouse\") window.setTimeout(onLeave, 900);\n    };\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerdown\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"pointerup\", onUp);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) start();\n      else stop();\n    });\n    io.observe(root);\n    start();\n    return () => {\n      stop();\n      io.disconnect();\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerdown\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      root.removeEventListener(\"pointerup\", onUp);\n    };\n  }, [count, radius, strength, autoPlay]);\n\n  const vars = { \"--hb-wg1-accent\": accent, \"--hb-wg1-cols\": Math.max(1, columns) } as React.CSSProperties;\n\n  return (\n    <div ref={rootRef} className={`hb-wg1 ${className}`} style={{ ...vars, ...style }} data-live=\"false\" {...rest}>\n      <style href=\"hb-hover-magnetic-icons\" precedence=\"default\">{css}</style>\n      <span ref={fieldRef} className=\"hb-wg1-field\" aria-hidden=\"true\" />\n      <div className=\"hb-wg1-grid\" role=\"list\">\n        {items.map((item, i) => (\n          <div role=\"listitem\" key={`${item.label}-${i}`}>\n            <button\n              ref={(el) => {\n                btnRefs.current[i] = el;\n              }}\n              type=\"button\"\n              className=\"hb-wg1-btn\"\n              data-near=\"false\"\n              aria-label={item.label}\n              onClick={() => onSelect?.(item.label, i)}\n              style={{ \"--hb-wg1-tone\": item.tone ?? \"#3a3f4b\" } as React.CSSProperties}\n            >\n              <span className=\"hb-wg1-tile\" aria-hidden=\"true\">\n                <svg viewBox=\"0 0 24 24\">\n                  <path d={glyphs[item.icon ?? \"\"] ?? glyphs.notes} />\n                </svg>\n              </span>\n              <span className=\"hb-wg1-label\">{item.label}</span>\n            </button>\n          </div>\n        ))}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}