{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pill-nav",
  "type": "registry:component",
  "title": "Pill Nav",
  "description": "Accessible tabs (tablist, arrow keys, Home and End) with a pill that slides on a spring: the leading edge arrives first and stretches the pill as it crosses.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Navigation"
  ],
  "docs": "Installed in components/furin/pill-nav/. Docs, live controls and props table: https://furin.dev/components/pill-nav/",
  "files": [
    {
      "path": "registry/pill-nav/PillNav.tsx",
      "content": "\"use client\";\nimport { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, KeyboardEvent, ReactNode } from \"react\";\nimport \"./PillNav.css\";\n\nexport interface PillNavTab {\n  /** Valor que identifica la pestaña. */\n  value: string;\n  /** Texto visible. */\n  label: string;\n  /** Insignia opcional, por ejemplo un contador. */\n  badge?: string | number;\n}\n\nexport interface PillNavProps {\n  /** Pestañas: textos o { value, label, badge }. */\n  tabs?: (string | PillNavTab)[];\n  /** Pestaña activa (modo controlado). */\n  value?: string;\n  /** Pestaña inicial (modo libre). */\n  defaultValue?: string;\n  /** Se llama al elegir otra pestaña. */\n  onChange?: (value: string) => void;\n  /** Contenido de cada panel, por valor de pestaña (opcional). */\n  panels?: Record<string, ReactNode>;\n  /** Etiqueta accesible de la lista de pestañas. */\n  label?: string;\n  /** Rigidez del resorte de la píldora: más alto es más seco. */\n  stiffness?: number;\n  /** Rebote de la píldora: 0.4 se pasa y regresa, 1 llega sin rebotar. */\n  damping?: number;\n  /** Color de la píldora. */\n  color?: string;\n  /** Color del texto sobre la píldora. */\n  activeTextColor?: string;\n  /** Segundos entre cambios automáticos (0 = apagado; se detiene al interactuar). */\n  autoplay?: number;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\nconst TABS = [\"Overview\", { value: \"Activity\", label: \"Activity\", badge: 12 }, \"Team\", \"Settings\"] as (string | PillNavTab)[];\n\nconst norm = (t: string | PillNavTab): PillNavTab => (typeof t === \"string\" ? { value: t, label: t } : t);\n\n/** Pestañas accesibles con una píldora que se desliza con resorte: el borde que avanza llega primero y el otro lo alcanza, así se estira al cruzar. */\nexport function PillNav({\n  tabs = TABS,\n  value,\n  defaultValue,\n  onChange,\n  panels,\n  label = \"Sections\",\n  stiffness = 380,\n  damping = 0.6,\n  color = \"#F3F4F7\",\n  activeTextColor = \"#0B0C0F\",\n  autoplay = 0,\n  className = \"\",\n  style,\n}: PillNavProps) {\n  const lista = tabs.map(norm);\n  const n = Math.max(lista.length, 1);\n  const uid = useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const [interno, setInterno] = useState(defaultValue ?? lista[0]?.value);\n  const actual = value ?? interno;\n  const idx = Math.max(lista.findIndex((t) => t.value === actual), 0);\n  const riel = useRef<HTMLDivElement>(null);\n  const pildora = useRef<HTMLSpanElement>(null);\n  const fantasma = useRef<HTMLSpanElement>(null);\n  const botones = useRef<(HTMLButtonElement | null)[]>([]);\n  const tocado = useRef(false);\n  const [listo, setListo] = useState(false);\n  // Borde izquierdo y derecho de la píldora: dos resortes con rigidez distinta según hacia dónde va.\n  const fis = useRef({ l: 0, r: 0, vl: 0, vr: 0, tl: 0, tr: 0, raf: 0, last: 0, dir: 1, placed: false });\n  const live = useRef({ stiffness, damping });\n  live.current = { stiffness, damping };\n\n  const elegir = useCallback(\n    (v: string) => {\n      if (value === undefined) setInterno(v);\n      onChange?.(v);\n    },\n    [value, onChange],\n  );\n\n  const pinta = useCallback(() => {\n    const p = pildora.current;\n    if (!p) return;\n    const f = fis.current;\n    const w = Math.max(f.r - f.l, 0);\n    p.style.width = `${w.toFixed(2)}px`;\n    p.style.transform = `translate3d(${f.l.toFixed(2)}px, 0, 0)`;\n  }, []);\n\n  const tick = useCallback((t: number) => {\n    const f = fis.current;\n    f.raf = 0;\n    const dt = Math.min(0.032, Math.max(0.001, (t - f.last) / 1000));\n    f.last = t;\n    const { stiffness: k0, damping: z } = live.current;\n    // El borde que va por delante es más rígido; el de atrás se queda y estira la píldora.\n    const kl = f.dir > 0 ? k0 * 0.55 : k0 * 1.1;\n    const kr = f.dir > 0 ? k0 * 1.1 : k0 * 0.55;\n    const steps = 3, h = dt / steps;\n    for (let i = 0; i < steps; i++) {\n      f.vl += (kl * (f.tl - f.l) - 2 * Math.sqrt(kl) * z * f.vl) * h;\n      f.l += f.vl * h;\n      f.vr += (kr * (f.tr - f.r) - 2 * Math.sqrt(kr) * z * f.vr) * h;\n      f.r += f.vr * h;\n    }\n    pinta();\n    const quieto = Math.abs(f.tl - f.l) < 0.05 && Math.abs(f.tr - f.r) < 0.05 && Math.abs(f.vl) < 0.1 && Math.abs(f.vr) < 0.1;\n    if (quieto) { f.l = f.tl; f.r = f.tr; f.vl = f.vr = 0; pinta(); return; }\n    f.raf = requestAnimationFrame(tick);\n  }, [pinta]);\n\n  /** Mide la pestaña activa y apunta los resortes; con `snap` salta sin animar (primer pintado, redimensionar, reduced motion). */\n  const medir = useCallback(\n    (snap: boolean) => {\n      const b = botones.current[idx];\n      const f = fis.current;\n      if (!b) return;\n      const nl = b.offsetLeft, nr = b.offsetLeft + b.offsetWidth;\n      if (Math.abs(nl - f.tl) < 0.01 && Math.abs(nr - f.tr) < 0.01 && f.placed) return;\n      f.dir = nl >= f.tl ? 1 : -1;\n      f.tl = nl;\n      f.tr = nr;\n      const quieto = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n      if (snap || quieto || !f.placed) {\n        f.l = nl; f.r = nr; f.vl = f.vr = 0; f.placed = true;\n        pinta();\n        return;\n      }\n      if (!f.raf) { f.last = performance.now(); f.raf = requestAnimationFrame(tick); }\n    },\n    [idx, pinta, tick],\n  );\n\n  useLayoutEffect(() => {\n    medir(false);\n    setListo(true);\n  }, [medir]);\n\n  useEffect(() => {\n    const r = riel.current;\n    if (!r) return;\n    const ro = new ResizeObserver(() => medir(true));\n    ro.observe(r);\n    botones.current.forEach((b) => b && ro.observe(b));\n    const fnt = (document as Document & { fonts?: FontFaceSet }).fonts;\n    void fnt?.ready.then(() => medir(true));\n    return () => ro.disconnect();\n  }, [medir, n]);\n\n  useEffect(() => () => cancelAnimationFrame(fis.current.raf), []);\n\n  // Cambio automático para la demo; se detiene en cuanto la persona toca el control.\n  useEffect(() => {\n    if (!autoplay || n < 2) return;\n    const id = window.setInterval(() => {\n      if (tocado.current || document.hidden) return;\n      elegir(lista[(idx + 1) % n].value);\n    }, autoplay * 1000);\n    return () => window.clearInterval(id);\n  });\n\n  const tecla = (e: KeyboardEvent, i: number) => {\n    let j = i;\n    if (e.key === \"ArrowRight\") j = (i + 1) % n;\n    else if (e.key === \"ArrowLeft\") j = (i - 1 + n) % n;\n    else if (e.key === \"Home\") j = 0;\n    else if (e.key === \"End\") j = n - 1;\n    else return;\n    e.preventDefault();\n    tocado.current = true;\n    elegir(lista[j].value);\n    botones.current[j]?.focus();\n  };\n\n  // Resplandor tenue que sigue al cursor sobre las pestañas.\n  const hover = (i: number | null) => {\n    const g = fantasma.current;\n    const b = i == null ? null : botones.current[i];\n    if (!g) return;\n    if (!b) { g.style.opacity = \"0\"; return; }\n    g.style.opacity = \"1\";\n    g.style.width = `${b.offsetWidth}px`;\n    g.style.transform = `translate3d(${b.offsetLeft}px, 0, 0)`;\n  };\n\n  const vars = { \"--furin-pill-nav-color\": color, \"--furin-pill-nav-active\": activeTextColor } as CSSProperties;\n  const panel = panels?.[lista[idx]?.value];\n  return (\n    <div className={`furin-pill-nav ${className}`} style={{ ...vars, ...style }}>\n      <div\n        ref={riel}\n        role=\"tablist\"\n        aria-label={label}\n        className={`furin-pill-nav__riel${listo ? \" is-listo\" : \"\"}`}\n        onPointerDown={() => { tocado.current = true; }}\n        onPointerLeave={() => hover(null)}\n      >\n        <span ref={fantasma} className=\"furin-pill-nav__fantasma\" aria-hidden=\"true\" />\n        <span ref={pildora} className=\"furin-pill-nav__pildora\" aria-hidden=\"true\" />\n        {lista.map((t, i) => (\n          <button\n            key={t.value}\n            ref={(el) => { botones.current[i] = el; }}\n            type=\"button\"\n            role=\"tab\"\n            id={`${uid}-t-${i}`}\n            aria-selected={i === idx}\n            aria-controls={panels ? `${uid}-p-${i}` : undefined}\n            tabIndex={i === idx ? 0 : -1}\n            className={`furin-pill-nav__tab${i === idx ? \" is-on\" : \"\"}`}\n            onClick={() => elegir(t.value)}\n            onKeyDown={(e) => tecla(e, i)}\n            onPointerEnter={(e) => { if (e.pointerType !== \"touch\") hover(i); }}\n            onFocus={() => hover(null)}\n          >\n            {t.label}\n            {t.badge !== undefined ? <span className=\"furin-pill-nav__insignia\">{t.badge}</span> : null}\n          </button>\n        ))}\n      </div>\n      {panels ? (\n        <div role=\"tabpanel\" id={`${uid}-p-${idx}`} aria-labelledby={`${uid}-t-${idx}`} tabIndex={0} className=\"furin-pill-nav__panel\">\n          {panel}\n        </div>\n      ) : null}\n    </div>\n  );\n}\n\nexport default PillNav;\n",
      "type": "registry:component",
      "target": "components/furin/pill-nav/PillNav.tsx"
    },
    {
      "path": "registry/pill-nav/PillNav.css",
      "content": ".furin-pill-nav {\n  --furin-pill-nav-color: #f3f4f7;\n  --furin-pill-nav-active: #0b0c0f;\n  display: grid;\n  justify-items: center;\n  gap: 16px;\n  font-family: Geist, system-ui, -apple-system, sans-serif;\n  color: #fff;\n}\n.furin-pill-nav__riel {\n  position: relative;\n  display: inline-flex;\n  align-items: stretch;\n  gap: 2px;\n  padding: 4px;\n  border-radius: 999px;\n  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.03));\n  border: 1px solid rgba(255, 255, 255, 0.1);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 12px 30px -14px rgba(0, 0, 0, 0.7);\n  -webkit-backdrop-filter: blur(14px) saturate(1.3);\n  backdrop-filter: blur(14px) saturate(1.3);\n  touch-action: manipulation;\n}\n.furin-pill-nav__pildora {\n  position: absolute;\n  left: 4px; /* el padding del riel: las posiciones se miden desde el borde del riel */\n  top: 4px; bottom: 4px;\n  margin-left: -4px;\n  width: 0;\n  border-radius: 999px;\n  pointer-events: none;\n  opacity: 0;\n  background: linear-gradient(180deg, color-mix(in srgb, var(--furin-pill-nav-color) 100%, #fff 14%), var(--furin-pill-nav-color) 55%, color-mix(in srgb, var(--furin-pill-nav-color) 88%, #000));\n  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 -1px 0 rgba(0, 0, 0, 0.12) inset, 0 8px 18px -6px rgba(0, 0, 0, 0.6), 0 2px 4px rgba(0, 0, 0, 0.3);\n  will-change: transform, width;\n}\n.furin-pill-nav__riel.is-listo .furin-pill-nav__pildora { opacity: 1; transition: opacity 0.25s; }\n.furin-pill-nav__fantasma {\n  position: absolute;\n  left: 0; top: 4px; bottom: 4px;\n  width: 0;\n  border-radius: 999px;\n  pointer-events: none;\n  opacity: 0;\n  background: rgba(255, 255, 255, 0.07);\n  transition: transform 0.34s cubic-bezier(0.22, 1, 0.36, 1), width 0.34s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s;\n}\n.furin-pill-nav__tab {\n  position: relative;\n  z-index: 1;\n  display: inline-flex;\n  align-items: center;\n  gap: 8px;\n  appearance: none;\n  border: 0;\n  background: none;\n  padding: 10px 18px;\n  border-radius: 999px;\n  font: 500 14px/1 Geist, system-ui, -apple-system, sans-serif;\n  letter-spacing: -0.005em;\n  color: rgba(255, 255, 255, 0.62);\n  cursor: pointer;\n  outline: none;\n  white-space: nowrap;\n  transition: color 0.25s;\n  -webkit-tap-highlight-color: transparent;\n}\n.furin-pill-nav__tab:hover { color: rgba(255, 255, 255, 0.92); }\n.furin-pill-nav__tab.is-on { color: var(--furin-pill-nav-active); }\n.furin-pill-nav__tab:focus-visible { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85), 0 0 0 4px rgba(124, 140, 255, 0.5); }\n.furin-pill-nav__insignia {\n  min-width: 20px;\n  padding: 3px 6px;\n  border-radius: 999px;\n  background: rgba(255, 255, 255, 0.12);\n  font: 500 11px/1 \"JetBrains Mono\", ui-monospace, \"SF Mono\", Menlo, monospace;\n  text-align: center;\n  color: inherit;\n  transition: background-color 0.25s;\n}\n.furin-pill-nav__tab.is-on .furin-pill-nav__insignia { background: rgba(11, 12, 15, 0.1); }\n.furin-pill-nav__panel { outline: none; font-size: 14px; color: rgba(255, 255, 255, 0.7); text-align: center; max-width: 36ch; }\n.furin-pill-nav__panel:focus-visible { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5); border-radius: 8px; }\n@media (prefers-reduced-motion: reduce) {\n  .furin-pill-nav__tab, .furin-pill-nav__fantasma, .furin-pill-nav__insignia { transition: none; }\n}\n",
      "type": "registry:file",
      "target": "components/furin/pill-nav/PillNav.css"
    }
  ]
}
