{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "magnetic-dock",
  "title": "Magnetic Dock",
  "description": "A macOS-style dock: icons swell under the cursor on critically damped springs.",
  "files": [
    {
      "path": "src/registry/easeout/magnetic-dock.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\n/*\n  Magnetic dock by easeout (easeoutstudio.com). Free to use, MIT.\n  Install: npx shadcn@latest add @easeout/magnetic-dock\n  Icons swell under the cursor and push their neighbours aside, each on its own critically damped spring, so it\n  tracks the pointer without overshoot. Transforms only; mouse only; off under reduced motion.\n*/\n\nexport type DockItem = { label: string; icon: React.ReactNode; onClick?: () => void; bg?: string; fg?: string }\n\nexport type MagneticDockProps = {\n  items: DockItem[]\n  /** Biggest icon scale under the cursor. */\n  max?: number\n  /** A virtual cursor sweeps across the dock until a real mouse arrives. Works on touch screens too. */\n  autoplay?: boolean\n  className?: string\n  \"aria-label\"?: string\n}\n\nexport function MagneticDock({ items, max = 1.55, autoplay = false, className, \"aria-label\": label = \"Dock\" }: MagneticDockProps) {\n  const dock = React.useRef<HTMLDivElement>(null)\n\n  React.useEffect(() => {\n    const el = dock.current\n    if (!el) return\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return\n    const fine = window.matchMedia(\"(hover: hover) and (pointer: fine)\").matches\n    if (!fine && !autoplay) return\n    const btns = Array.from(el.querySelectorAll<HTMLElement>(\"[data-dock-item]\"))\n    const tips = btns.map((b) => b.querySelector<HTMLElement>(\"[data-dock-tip]\"))\n    const K = 600\n    const C = 2 * Math.sqrt(K) // critically damped\n    const s = btns.map(() => 1)\n    const v = btns.map(() => 0)\n    let centers: number[] = []\n    let w = 54\n    let reach = 140\n    let x: number | null = null\n    let raf = 0\n    let last = 0\n    const measure = () => {\n      const left = el.getBoundingClientRect().left + el.clientLeft\n      centers = btns.map((b) => left + b.offsetLeft + b.offsetWidth / 2)\n      w = btns[0]?.offsetWidth ?? 54\n      reach = (btns.length > 1 ? centers[1] - centers[0] : w) * 2.2\n    }\n    const frame = (now: number) => {\n      const dt = Math.min(0.032, Math.max(0, (now - last) / 1000))\n      last = now\n      let moving = false\n      for (let i = 0; i < btns.length; i++) {\n        const d = x === null ? 1 : Math.abs(x - centers[i]) / reach\n        const target = 1 + (max - 1) * (d >= 1 ? 0 : (Math.cos(Math.PI * d) + 1) / 2)\n        v[i] += (K * (target - s[i]) - C * v[i]) * dt\n        s[i] += v[i] * dt\n        if (Math.abs(target - s[i]) > 0.0005 || Math.abs(v[i]) > 0.005) moving = true\n        else s[i] = target\n      }\n      const extra = s.map((k) => w * (k - 1))\n      const total = extra.reduce((a, b) => a + b, 0)\n      let acc = 0\n      btns.forEach((b, i) => {\n        const off = acc + extra[i] / 2 - total / 2\n        acc += extra[i]\n        b.style.transform = `translate3d(${off.toFixed(2)}px,0,0) scale(${s[i].toFixed(4)})`\n        const t = tips[i]\n        if (t) t.style.scale = (1 / s[i]).toFixed(4)\n      })\n      el.style.setProperty(\"--dock-grow\", (total / 2).toFixed(2) + \"px\")\n      raf = moving ? requestAnimationFrame(frame) : 0\n    }\n    const kick = () => {\n      if (raf) return\n      last = performance.now()\n      raf = requestAnimationFrame(frame)\n    }\n    // autoplay: ease a virtual cursor from end to end and back; a real mouse inside takes over\n    let mouse = false\n    let auto = 0\n    const t0 = performance.now()\n    const drive = (now: number) => {\n      if (!mouse) {\n        measure()\n        const a = centers[0] ?? 0\n        const b = centers[centers.length - 1] ?? 0\n        const k = (1 - Math.cos(((now - t0) / 3200) * Math.PI)) / 2 // 3.2s per pass, eased at the ends\n        x = a + (b - a) * k\n        kick()\n      }\n      auto = requestAnimationFrame(drive)\n    }\n    if (autoplay) auto = requestAnimationFrame(drive)\n    const onMove = (e: PointerEvent) => {\n      if (e.pointerType !== \"mouse\" || !fine) return\n      mouse = true\n      if (!centers.length) measure()\n      x = e.clientX\n      kick()\n    }\n    const onLeave = () => {\n      mouse = false\n      if (autoplay) return\n      x = null\n      kick()\n    }\n    el.addEventListener(\"pointerenter\", measure)\n    el.addEventListener(\"pointermove\", onMove)\n    el.addEventListener(\"pointerleave\", onLeave)\n    window.addEventListener(\"resize\", measure)\n    el.dataset.magnify = \"\"\n    return () => {\n      cancelAnimationFrame(raf)\n      cancelAnimationFrame(auto)\n      delete el.dataset.magnify\n      el.style.removeProperty(\"--dock-grow\")\n      el.removeEventListener(\"pointerenter\", measure)\n      el.removeEventListener(\"pointermove\", onMove)\n      el.removeEventListener(\"pointerleave\", onLeave)\n      window.removeEventListener(\"resize\", measure)\n      btns.forEach((b, i) => {\n        b.style.transform = \"\"\n        const t = tips[i]\n        if (t) t.style.scale = \"\"\n      })\n    }\n  }, [max, items.length, autoplay])\n\n  return (\n    <div\n      ref={dock}\n      role=\"group\"\n      aria-label={label}\n      className={[\n        \"relative isolate flex w-max gap-2.5 rounded-[22px] p-2.5\",\n        // the glass grows with the icons, so they never spill out of it\n        \"before:absolute before:inset-y-0 before:-left-[var(--dock-grow,0px)] before:-right-[var(--dock-grow,0px)] before:-z-10 before:rounded-[inherit] before:border before:border-border before:bg-[color-mix(in_srgb,var(--color-card)_78%,transparent)] before:shadow-[0_12px_12px_-3px_rgba(0,0,0,.06),0_20px_40px_-20px_rgba(0,0,0,.25)] before:backdrop-blur-[16px] before:content-['']\",\n        className,\n      ]\n        .filter(Boolean)\n        .join(\" \")}\n    >\n      {items.map((it, i) => (\n        <button\n          key={i}\n          type=\"button\"\n          data-dock-item=\"\"\n          aria-label={it.label}\n          onClick={it.onClick}\n          className=\"group/dk relative origin-bottom cursor-pointer border-0 bg-transparent p-0 transition-transform duration-[260ms] ease-[cubic-bezier(.23,1,.32,1)] focus-visible:outline-none in-data-[magnify]:transition-none\"\n        >\n          <span\n            className=\"grid size-[54px] place-items-center rounded-[14px] shadow-[inset_0_0_0_1px_rgba(255,255,255,.08),0_6px_14px_-6px_rgba(0,0,0,.35)] group-focus-visible/dk:outline-2 group-focus-visible/dk:outline-offset-2 group-focus-visible/dk:outline-foreground max-[640px]:size-[46px] max-[640px]:rounded-xl\"\n            style={{ background: it.bg ?? \"var(--color-secondary)\", color: it.fg ?? \"var(--color-foreground)\" }}\n          >\n            {it.icon}\n          </span>\n          <em\n            data-dock-tip=\"\"\n            className=\"pointer-events-none absolute bottom-[calc(100%+10px)] left-1/2 origin-bottom -translate-x-1/2 translate-y-1 whitespace-nowrap rounded-lg bg-foreground px-2 py-1 text-xs font-medium not-italic text-background opacity-0 transition-[opacity,translate] duration-200 ease-[cubic-bezier(.23,1,.32,1)] group-focus-visible/dk:translate-y-0 group-focus-visible/dk:opacity-100 [@media(hover:hover)]:group-hover/dk:translate-y-0 [@media(hover:hover)]:group-hover/dk:opacity-100\"\n          >\n            {it.label}\n          </em>\n        </button>\n      ))}\n    </div>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Import it with `import { MagneticDock } from \"@/components/magnetic-dock\"`. Live demo, props and a usage example: https://www.easeoutstudio.com/lab/magnetic-dock",
  "type": "registry:component"
}