{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"mercury-pour-nav","type":"registry:component","title":"Mercury Pour Nav","description":"A floating nav whose current-link indicator is a capsule of mercury on two springs: it stretches thin as it pours to the next link, snaps back round, reaches toward the link you hover, and turns the labels it covers dark.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/mercury-pour-nav.tsx","content":"\"use client\";\n\nimport { useEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { CSSProperties } from \"react\";\n\n/**\n * MercuryPourNav — a floating nav whose indicator is a capsule of mercury.\n *\n * The capsule moves on two springs, one per edge: the edge in the\n * direction of travel is stiff, the trailing edge soft, so it stretches\n * thin as it pours to the next link and snaps back round. Hovering or\n * focusing another link makes it reach a quarter of the way. The chrome it\n * reflects slides with its speed, and the labels it covers turn dark,\n * clipped to it exactly. Pass `active` (for example from scroll position,\n * -1 for none) or let clicks set it.\n *\n * Part of the Liquid Chrome kit: a graphite room, a four-band chrome ramp\n * (#08090b, #4b4f58, #c9ced6, #ffffff) multiplied by a finish (chrome, gold,\n * rose, cobalt or any #rrggbb), foil colour only as a thin film. Fonts come\n * from CSS variables with Archivo and Geist fallbacks. Respects\n * prefers-reduced-motion. No dependencies beyond React. Paste it as its own\n * file: it repeats the kit's small helpers, which would clash in one module.\n */\n\nconst SANS = 'var(--font-sans, \"Geist\", \"Inter\", ui-sans-serif, system-ui, sans-serif)';\n\nconst DISPLAY = 'var(--font-display, \"Archivo\", \"Helvetica Neue\", Arial, sans-serif)';\n\nconst INK = \"rgba(244,245,247,0.94)\";\n\nconst INK_2 = \"rgba(244,245,247,0.62)\";\n\nconst LINE_2 = \"rgba(255,255,255,0.16)\";\n\nconst HEX = /^#[0-9a-fA-F]{6}$/;\n\n/** The reflected room, darkest to hottest. Every chrome surface in the kit reflects these four bands. */\nconst RAMP = [\"#08090b\", \"#4b4f58\", \"#c9ced6\", \"#ffffff\"] as const;\n\n/** Metal finishes: the colour the room is multiplied by. */\nexport const LC_FINISHES = {\n  chrome: \"#ffffff\",\n  gold: \"#f2cf92\",\n  rose: \"#f1bcb4\",\n  cobalt: \"#b9cbff\",\n} as const;\n\nfunction own<T extends object>(map: T, key: string): key is Extract<keyof T, string> {\n  return Object.prototype.hasOwnProperty.call(map, key);\n}\n\n/** A named finish or a #rrggbb tint; anything else falls back to chrome. */\nfunction finishHex(value: string): string {\n  if (own(LC_FINISHES, value)) return LC_FINISHES[value];\n  return HEX.test(value) ? value : LC_FINISHES.chrome;\n}\n\nfunction rgbOf(hex: string): [number, number, number] {\n  const n = parseInt(hex.slice(1), 16);\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\n/** A ramp colour multiplied by the finish, as rgb(). */\nfunction tinted(hex: string, tint: string): string {\n  const a = rgbOf(hex);\n  const b = rgbOf(tint);\n  return `rgb(${Math.round((a[0] * b[0]) / 255)} ${Math.round((a[1] * b[1]) / 255)} ${Math.round((a[2] * b[2]) / 255)})`;\n}\n\n/** The finished ramp as the CSS variables every chrome gradient and the focus ring read. */\nfunction finishVars(tint: string): CSSProperties {\n  return {\n    \"--lc-0\": tinted(RAMP[0], tint),\n    \"--lc-1\": tinted(RAMP[1], tint),\n    \"--lc-2\": tinted(RAMP[2], tint),\n    \"--lc-3\": tinted(RAMP[3], tint),\n  } as CSSProperties;\n}\n\n/**\n * Chrome as a CSS gradient: bright sky, a hard dark horizon, a lit floor.\n * `--lc-h` moves the horizon (0-100), so a surface can turn in the room.\n */\nconst CHROME_BG =\n  \"linear-gradient(180deg, var(--lc-3) 0%, var(--lc-2) calc(var(--lc-h, 50) * 1% - 16%), var(--lc-1) calc(var(--lc-h, 50) * 1% - 2%), var(--lc-0) calc(var(--lc-h, 50) * 1%), var(--lc-1) calc(var(--lc-h, 50) * 1% + 14%), var(--lc-2) calc(var(--lc-h, 50) * 1% + 34%), var(--lc-3) 100%)\";\n\n/** Links: strip tabs and newlines, refuse backslashes, allow http(s), mailto, tel and same-site paths. */\nfunction safeHref(raw: string): string {\n  const v = raw.replace(/[\\t\\n\\r]/g, \"\").trim();\n  if (!v || v.includes(\"\\\\\")) return \"#\";\n  if (/^(https?:|mailto:|tel:)/i.test(v)) return v;\n  if (/^[/#?]/.test(v) && !/^\\/\\//.test(v)) return v;\n  return \"#\";\n}\n\nfunction subscribeMotion(cb: () => void) {\n  const m = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  m.addEventListener(\"change\", cb);\n  return () => m.removeEventListener(\"change\", cb);\n}\n\n/** True when the visitor asked for reduced motion. False on the server. */\nfunction useReducedMotion(): boolean {\n  return useSyncExternalStore(\n    subscribeMotion,\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n// Each part carries only the CSS it needs, so any one of them works on its own.\n// Nothing is interpolated into these sheets; colours arrive as CSS variables.\n// revert-layer keeps an element's own rounded corners when a host page's focus rule flattens them.\nconst FOCUS_CSS = \".lc-scope :focus-visible,.lc-scope:focus-visible{outline:2px solid var(--lc-2);outline-offset:3px;border-radius:revert-layer}\";\n\nexport type LcLink = { label: string; href: string };\n\nexport type MercuryPourNavProps = {\n  brand: string;\n  links: LcLink[];\n  /** The current link (controlled, e.g. by scroll position; -1 for none); clicks set it when uncontrolled. */\n  active?: number;\n  onSelect?: (index: number) => void;\n  cta?: LcLink;\n  finish?: string;\n  className?: string;\n};\n\n/**\n * A floating nav whose current-link indicator is a capsule of mercury. It\n * moves on two springs, one per edge: the edge in the direction of travel is\n * stiff and the trailing edge is soft, so the capsule stretches thin as it\n * pours to the next link, then snaps back to its round length. Hovering or\n * focusing another link makes it reach toward it. The chrome it reflects\n * slides with its speed, and the labels it covers turn dark, clipped to it\n * exactly.\n */\nexport function MercuryPourNav({ brand, links, active, onSelect, cta, finish = \"chrome\", className }: MercuryPourNavProps) {\n  const tint = finishHex(finish);\n  const reduced = useReducedMotion();\n  const [picked, setPicked] = useState(0);\n  const current = active ?? picked;\n  const [lean, setLean] = useState<number | null>(null);\n  const rowRef = useRef<HTMLDivElement>(null);\n  const capRef = useRef<HTMLDivElement>(null);\n  const darkRef = useRef<HTMLDivElement>(null);\n  const spring = useRef({ l: 0, r: 0, vl: 0, vr: 0, ready: false });\n\n  useEffect(() => {\n    const row = rowRef.current;\n    const cap = capRef.current;\n    const dark = darkRef.current;\n    if (!row || !cap || !dark) return;\n    const items = Array.from(row.querySelectorAll<HTMLElement>(\"[data-lc-link]\"));\n    const box = (i: number) => {\n      const el = items[Math.max(0, Math.min(items.length - 1, i))];\n      return el ? { l: el.offsetLeft, r: el.offsetLeft + el.offsetWidth } : { l: 0, r: 0 };\n    };\n    const s = spring.current;\n    let raf = 0;\n    let last = 0;\n    const target = () => {\n      if (current < 0) {\n        // Nothing current: the capsule gathers into a bead at the first link.\n        const f = box(0);\n        const mid = (f.l + f.r) / 2;\n        return { l: mid, r: mid };\n      }\n      const a = box(current);\n      if (lean === null || lean === current) return a;\n      // Reach a quarter of the way toward the link under the pointer.\n      const b = box(lean);\n      return lean > current ? { l: a.l, r: a.r + (b.r - a.r) * 0.24 } : { l: a.l + (b.l - a.l) * 0.24, r: a.r };\n    };\n    const paint = () => {\n      const w = Math.max(0, s.r - s.l);\n      const rest = box(Math.max(0, current));\n      const stretch = Math.max(0, w / Math.max(1, rest.r - rest.l) - 1);\n      cap.style.transform = `translateX(${s.l}px) scaleY(${(1 - Math.min(0.28, stretch * 0.22)).toFixed(3)})`;\n      cap.style.width = `${w}px`;\n      cap.style.opacity = w < 6 ? \"0\" : \"1\";\n      cap.style.setProperty(\"--lc-h\", (64 + Math.max(-12, Math.min(12, (s.vl + s.vr) * 0.006))).toFixed(1));\n      dark.style.clipPath = `inset(0 ${Math.max(0, row.offsetWidth - s.r)}px 0 ${s.l}px round 999px)`;\n    };\n    const step = (now: number) => {\n      raf = 0;\n      const dt = last ? Math.min(0.032, (now - last) / 1000) : 0.016;\n      last = now;\n      const t = target();\n      const right = t.r + t.l > s.r + s.l;\n      // The leading edge is stiff, the trailing edge soft: the capsule stretches as it travels.\n      const kl = right ? 170 : 520;\n      const kr = right ? 520 : 170;\n      s.vl += ((t.l - s.l) * kl - s.vl * 2 * Math.sqrt(kl) * 0.72) * dt;\n      s.vr += ((t.r - s.r) * kr - s.vr * 2 * Math.sqrt(kr) * 0.72) * dt;\n      s.l += s.vl * dt;\n      s.r += s.vr * dt;\n      paint();\n      const moving = Math.abs(t.l - s.l) + Math.abs(t.r - s.r) + Math.abs(s.vl) * 0.01 + Math.abs(s.vr) * 0.01 > 0.1;\n      if (moving) raf = requestAnimationFrame(step);\n      else last = 0;\n    };\n    const t0 = target();\n    if (!s.ready || reduced) {\n      s.l = t0.l;\n      s.r = t0.r;\n      s.vl = s.vr = 0;\n      s.ready = true;\n      paint();\n    } else raf = requestAnimationFrame(step);\n    const ro = new ResizeObserver(() => {\n      if (reduced) {\n        const t = target();\n        s.l = t.l;\n        s.r = t.r;\n        paint();\n      } else if (!raf) raf = requestAnimationFrame(step);\n    });\n    ro.observe(row);\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n    };\n  }, [current, lean, reduced, links.length]);\n\n  const select = (i: number) => {\n    if (active === undefined) setPicked(i);\n    onSelect?.(i);\n  };\n\n  const labelCls = \"relative z-[1] shrink-0 whitespace-nowrap rounded-full px-4 py-2 text-[14px] font-medium\";\n  return (\n    <nav\n      aria-label=\"Main\"\n      className={\"lc-scope relative flex h-[52px] items-center gap-2 rounded-full pl-5 pr-1.5\" + (className ? \" \" + className : \"\")}\n      style={{\n        ...finishVars(tint),\n        fontFamily: SANS,\n        background: \"rgba(20,21,25,0.72)\",\n        WebkitBackdropFilter: \"blur(14px) saturate(140%)\",\n        backdropFilter: \"blur(14px) saturate(140%)\",\n        boxShadow: `inset 0 0 0 1px ${LINE_2}, inset 0 1px 0 rgba(255,255,255,0.08), 0 18px 40px -18px rgba(0,0,0,0.9)`,\n      }}\n    >\n      <style>{FOCUS_CSS}</style>\n      <span className=\"mr-2 shrink-0 text-[13px] uppercase tracking-[0.2em]\" style={{ fontFamily: DISPLAY, fontWeight: 700, fontStretch: \"125%\", color: INK }}>\n        {brand}\n      </span>\n      <div className=\"relative min-w-0 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\">\n        <div ref={rowRef} className=\"relative flex w-max items-center\" onPointerLeave={() => setLean(null)}>\n          <div\n            ref={capRef}\n            aria-hidden\n            className=\"pointer-events-none absolute inset-y-0 left-0 rounded-full\"\n            style={{\n              width: 0,\n              background: `radial-gradient(40% 80% at 30% 0%, rgba(255,255,255,0.9), rgba(255,255,255,0) 70%), ${CHROME_BG}`,\n              boxShadow: \"inset 0 1px 0 rgba(255,255,255,0.9), inset 0 -1px 1px rgba(0,0,0,0.45), 0 6px 16px -6px rgba(0,0,0,0.9)\",\n              transformOrigin: \"50% 50%\",\n              opacity: 0,\n              transition: \"opacity 200ms ease\",\n            }}\n          />\n          {links.map((l, i) => (\n            <a\n              key={l.label}\n              data-lc-link\n              href={safeHref(l.href)}\n              aria-current={i === current ? \"true\" : undefined}\n              onClick={() => select(i)}\n              onPointerEnter={() => setLean(i)}\n              onFocus={() => setLean(i)}\n              onBlur={() => setLean(null)}\n              className={labelCls + \" transition-colors hover:text-white\"}\n              style={{ color: INK_2 }}\n            >\n              {l.label}\n            </a>\n          ))}\n          {/* The labels again in dark ink, clipped to the capsule. */}\n          <div ref={darkRef} aria-hidden className=\"pointer-events-none absolute inset-0 z-[2] flex items-center\">\n            {links.map((l) => (\n              <span key={l.label} className={labelCls} style={{ color: \"rgba(12,13,16,0.92)\", textShadow: \"0 1px 0 rgba(255,255,255,0.45)\" }}>\n                {l.label}\n              </span>\n            ))}\n          </div>\n        </div>\n      </div>\n      {cta && (\n        <a\n          href={safeHref(cta.href)}\n          className=\"ml-auto shrink-0 rounded-full px-4 py-2 text-[14px] font-medium transition-colors hover:text-white\"\n          style={{ color: INK, boxShadow: `inset 0 0 0 1px ${LINE_2}` }}\n        >\n          {cta.label}\n        </a>\n      )}\n    </nav>\n  );\n}\n","type":"registry:component","target":"components/viberdy/mercury-pour-nav.tsx"}],"meta":{"tier":"free","tags":["navigation","navbar","indicator","spring","liquid","chrome","pointer"],"href":"https://viberdy.dev/library/mercury-pour-nav","aiPrompt":"Build a React + Tailwind nav, `MercuryPourNav({ brand, links, active, onSelect, cta, finish })`: a floating pill whose current-link indicator is a capsule of mercury.\n\nThe pill: 52px tall, translucent graphite with a 14px backdrop blur and an inset hairline, the brand in wide Archivo caps, a horizontally scrolling row of links, an optional outlined link at the end. Inside the row (w-max), an absolutely positioned capsule (chrome room gradient with a glint, inset highlight) and, above the links, a second aria-hidden copy of the labels in dark ink.\n\nOne rAF loop runs while anything moves: the target is the current link's left and right edges (a bead at the first link's centre when active is -1); if another link is hovered or focused, the leading edge reaches 24% of the way to it. Each edge is a damped spring (damping ratio 0.72); the edge in the direction of travel has stiffness 520, the trailing edge 170, so the capsule stretches while travelling. Write translateX and width, scaleY down by up to 28% in proportion to the stretch, --lc-h shifted by the edges' speed, opacity 0 below 6px, and clip the dark labels to inset(0 right 0 left round 999px). Re-measure on resize. Reduced motion jumps. Clicks set the current link when uncontrolled and call onSelect.\n\nLiquid Chrome grammar: a graphite room (ground #0c0d10, panels #141519 and #1b1c21, hairlines white 7% and 16% drawn as inset box-shadows or SVG strokes, never border colours), ink #f4f5f7 at 94/62/40%. Chrome is a reflected room, never a flat grey gradient: four bands (#08090b, #4b4f58, #c9ced6, #ffffff) arranged as a bright sky over a hard dark horizon over a lit floor, multiplied by a finish (chrome #ffffff, gold #f2cf92, rose #f1bcb4, cobalt #b9cbff, or any #rrggbb validated against /^#[0-9a-fA-F]{6}$/) and handed to CSS as --lc-0 to --lc-3 with the horizon position in --lc-h. Colour appears only as a thin film on Newton's series (silver #d8dce2, champagne #eadfc4, magenta #d68fc7, cyan #8fd6d1, green #a8d68f, gold #d6b98f, violet #b48fd6, unevenly spaced), never a hue-rotate rainbow. Chrome goes only on heavy, curved forms (display type, pills, discs), never on hairlines. Display type is Archivo at 800 with font-stretch 125% and -0.02em tracking through var(--font-display, \"Archivo\", ...); UI in Geist; captions in Geist Mono, uppercase. Pills and 26px radii. The room eases toward the pointer in about 220ms, ambient drift runs 40s or slower, presses squash about 4% in 130ms. Keyframes and a focus ring (a .lc-scope rule with border-radius: revert-layer) live in a small static <style> the component renders itself; nothing is interpolated into it. Respect prefers-reduced-motion. No dependencies beyond React.","license":"https://viberdy.dev/license"}}