{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gooey-tabs",
  "type": "registry:component",
  "title": "Gooey Tabs",
  "description": "Accessible tabs whose selection is a blob of liquid: it stretches toward the new tab, thins at the neck and merges when it arrives.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Navigation"
  ],
  "docs": "Installed in components/furin/gooey-tabs/. Docs, live controls and props table: https://furin.dev/components/gooey-tabs/",
  "files": [
    {
      "path": "registry/gooey-tabs/GooeyTabs.tsx",
      "content": "\"use client\";\nimport { useCallback, useEffect, useId, useRef, useState } from \"react\";\nimport type { CSSProperties, KeyboardEvent } from \"react\";\nimport \"./GooeyTabs.css\";\n\nexport type GooeyTab = string | { value: string; label: string };\n\nexport interface GooeyTabsProps {\n  /** Etiquetas de las pestañas (o { value, label }). */\n  tabs?: GooeyTab[];\n  /** Pestaña activa (modo controlado). */\n  value?: string;\n  /** Pestaña activa al inicio (modo libre). */\n  defaultValue?: string;\n  /** Color del líquido de la selección. */\n  color?: string;\n  /** Color de las pestañas inactivas. */\n  textColor?: string;\n  /** Color de la pestaña activa, sobre el líquido. */\n  activeTextColor?: string;\n  /** Qué tan pegajoso es el líquido (desenfoque del filtro). */\n  gooeyness?: number;\n  /** Segundos entre cambios automáticos (0 lo apaga); se detiene al tocar. */\n  autoplay?: number;\n  /** Se llama al cambiar de pestaña. */\n  onChange?: (value: string) => void;\n  /** Nombre accesible de la lista de pestañas. */\n  \"aria-label\"?: string;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\nconst DEFAULT_TABS = [\"Home\", \"Projects\", \"Team\", \"Contact\"];\n// Cada gota del cuerpo persigue la pestaña con un resorte distinto: la primera llega rápido y las demás se quedan estiradas atrás.\nconst STIFF = [420, 290, 200, 138];\nconst BLOBS = STIFF.length;\n\n/** Pestañas con selección de líquido: varias gotas encadenadas con resortes y un filtro SVG que las funde, con brillo especular. */\nexport function GooeyTabs({\n  tabs = DEFAULT_TABS,\n  value,\n  defaultValue,\n  color = \"#EEF1FF\",\n  textColor = \"#A8B0C6\",\n  activeTextColor = \"#0B0C12\",\n  gooeyness = 7,\n  autoplay = 0,\n  onChange,\n  \"aria-label\": ariaLabel = \"Tabs\",\n  className = \"\",\n  style,\n}: GooeyTabsProps) {\n  const uid = useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const filterId = `furin-gooey-${uid}`;\n  const items = tabs.map((t) => (typeof t === \"string\" ? { value: t, label: t } : t));\n  const controlled = value !== undefined;\n  const [inner, setInner] = useState(defaultValue ?? items[0]?.value ?? \"\");\n  const current = controlled ? value! : inner;\n  const idx = Math.max(0, items.findIndex((t) => t.value === current));\n\n  const root = useRef<HTMLDivElement>(null);\n  const tabRefs = useRef<(HTMLButtonElement | null)[]>([]);\n  const blobRefs = useRef<(HTMLSpanElement | null)[]>([]);\n  const [ready, setReady] = useState(false);\n  const touched = useRef(false);\n  const idxRef = useRef(idx);\n  idxRef.current = idx;\n  const wakeRef = useRef<() => void>(() => {});\n\n  const select = useCallback(\n    (i: number, fromUser = true) => {\n      const next = items[i];\n      if (!next) return;\n      if (fromUser) touched.current = true;\n      if (!controlled) setInner(next.value);\n      onChange?.(next.value);\n    },\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n    [controlled, onChange, items.map((t) => t.value).join(\"|\")],\n  );\n\n  const onKeyDown = (e: KeyboardEvent) => {\n    let to = -1;\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") to = (idx + 1) % items.length;\n    else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") to = (idx - 1 + items.length) % items.length;\n    else if (e.key === \"Home\") to = 0;\n    else if (e.key === \"End\") to = items.length - 1;\n    if (to < 0) return;\n    e.preventDefault();\n    select(to);\n    tabRefs.current[to]?.focus();\n  };\n\n  const key = items.map((t) => t.label).join(\"|\");\n  // Simulación de las gotas: se arma una vez y lee la pestaña objetivo de idxRef.\n  useEffect(() => {\n    const el = root.current;\n    if (!el) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const x = new Float32Array(BLOBS), vx = new Float32Array(BLOBS), w = new Float32Array(BLOBS), vw = new Float32Array(BLOBS);\n    let tx = 0, tw = 0, ty = 0, th = 0, rootW = 0, started = false;\n    let raf = 0, last = 0, visible = true;\n\n    const measure = () => {\n      const tab = tabRefs.current[idxRef.current];\n      if (!tab) return false;\n      const rr = el.getBoundingClientRect();\n      const tr = tab.getBoundingClientRect();\n      tx = tr.left - rr.left - 1; // 1 px de borde del contenedor\n      ty = tr.top - rr.top - 1;\n      tw = tr.width;\n      th = tr.height;\n      rootW = rr.width;\n      return true;\n    };\n    const paint = () => {\n      for (let j = 0; j < BLOBS; j++) {\n        const b = blobRefs.current[j];\n        if (!b) continue;\n        // las gotas rezagadas se adelgazan: así se forma el cuello del líquido\n        const lag = Math.min(1, Math.abs(x[j] - x[0]) / Math.max(tw * 1.6, 1) + Math.abs(w[j] - w[0]) / Math.max(tw * 2, 1));\n        const h = th * (1 - 0.34 * lag * (j / (BLOBS - 1)));\n        const px = Math.min(Math.max(x[j], 0), Math.max(0, rootW - 2 - w[j]));\n        b.style.transform = `translate3d(${px}px, ${ty + (th - h) / 2}px, 0)`;\n        b.style.width = `${Math.max(w[j], 1)}px`;\n        b.style.height = `${Math.max(h, 1)}px`;\n      }\n    };\n    const snap = () => {\n      if (!measure()) return;\n      for (let j = 0; j < BLOBS; j++) {\n        x[j] = tx;\n        w[j] = tw;\n        vx[j] = vw[j] = 0;\n      }\n      paint();\n    };\n    const frame = (now: number) => {\n      raf = 0;\n      const dt = Math.min(1 / 30, Math.max(0.001, (now - last) / 1000));\n      last = now;\n      measure();\n      let moving = false;\n      const sub = 3;\n      const h = dt / sub;\n      for (let s = 0; s < sub; s++) {\n        for (let j = 0; j < BLOBS; j++) {\n          const k = STIFF[j];\n          const c = 2 * Math.sqrt(k) * 0.86;\n          vx[j] += ((tx - x[j]) * k - vx[j] * c) * h;\n          x[j] += vx[j] * h;\n          vw[j] += ((tw - w[j]) * k - vw[j] * c) * h;\n          w[j] += vw[j] * h;\n        }\n      }\n      for (let j = 0; j < BLOBS; j++) {\n        if (Math.abs(tx - x[j]) > 0.06 || Math.abs(vx[j]) > 0.1 || Math.abs(tw - w[j]) > 0.06 || Math.abs(vw[j]) > 0.1) moving = true;\n      }\n      if (!moving) {\n        for (let j = 0; j < BLOBS; j++) {\n          x[j] = tx;\n          w[j] = tw;\n          vx[j] = vw[j] = 0;\n        }\n      }\n      paint();\n      if (moving && visible) raf = requestAnimationFrame(frame);\n    };\n    const wake = () => {\n      if (!started) return;\n      if (reduce) {\n        snap();\n        return;\n      }\n      if (raf || !visible) return;\n      last = performance.now();\n      raf = requestAnimationFrame(frame);\n    };\n    wakeRef.current = wake;\n\n    const start = () => {\n      if (!measure()) return;\n      snap();\n      started = true;\n      setReady(true);\n    };\n    start();\n    document.fonts?.ready.then(() => {\n      snap();\n    });\n    const ro = new ResizeObserver(() => {\n      if (!started) start();\n      else snap();\n    });\n    ro.observe(el);\n    const io = new IntersectionObserver(([en]) => {\n      visible = en.isIntersecting;\n      if (visible) wake();\n      else if (raf) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n        snap();\n      }\n    });\n    io.observe(el);\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      wakeRef.current = () => {};\n    };\n  }, [key, gooeyness]);\n\n  // La pestaña cambió: las gotas salen hacia la nueva.\n  useEffect(() => {\n    wakeRef.current();\n  }, [idx]);\n\n  // Cambio automático para la demo, hasta que alguien toque.\n  useEffect(() => {\n    if (!autoplay || autoplay <= 0 || items.length < 2) return;\n    const id = window.setInterval(() => {\n      if (touched.current || document.hidden) return;\n      select((idxRef.current + 1) % items.length, false);\n    }, autoplay * 1000);\n    return () => window.clearInterval(id);\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [autoplay, key, select]);\n\n  const sigma = Math.max(1, gooeyness);\n  const vars = { \"--furin-gt-pill\": color, \"--furin-gt-text\": textColor, \"--furin-gt-active\": activeTextColor } as CSSProperties;\n  return (\n    <div\n      ref={root}\n      className={`furin-gooey-tabs${ready ? \" is-ready\" : \"\"} ${className}`}\n      style={{ ...vars, ...style }}\n      onPointerDown={() => {\n        touched.current = true;\n      }}\n    >\n      <svg className=\"furin-gooey-tabs__svg\" aria-hidden=\"true\" focusable=\"false\">\n        <defs>\n          <filter id={filterId} x=\"-20%\" y=\"-90%\" width=\"140%\" height=\"280%\" colorInterpolationFilters=\"sRGB\">\n            <feGaussianBlur in=\"SourceGraphic\" stdDeviation={sigma} result=\"difuso\" />\n            <feColorMatrix in=\"difuso\" type=\"matrix\" values=\"1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 24 -9.5\" result=\"goo\" />\n            <feGaussianBlur in=\"goo\" stdDeviation=\"2.2\" result=\"relieve\" />\n            <feDiffuseLighting in=\"relieve\" surfaceScale=\"3.6\" diffuseConstant=\"1.22\" lightingColor=\"#ffffff\" result=\"difusa\">\n              <feDistantLight azimuth=\"240\" elevation=\"58\" />\n            </feDiffuseLighting>\n            <feComposite in=\"goo\" in2=\"difusa\" operator=\"arithmetic\" k1=\"1\" k2=\"0\" k3=\"0\" k4=\"0\" result=\"cuerpo\" />\n            <feSpecularLighting in=\"relieve\" surfaceScale=\"6\" specularConstant=\"1.1\" specularExponent=\"26\" lightingColor=\"#ffffff\" result=\"brillo\">\n              <feDistantLight azimuth=\"240\" elevation=\"50\" />\n            </feSpecularLighting>\n            <feComposite in=\"brillo\" in2=\"goo\" operator=\"in\" result=\"brilloDentro\" />\n            <feComposite in=\"cuerpo\" in2=\"brilloDentro\" operator=\"arithmetic\" k1=\"0\" k2=\"1\" k3=\"1\" k4=\"0\" />\n          </filter>\n        </defs>\n      </svg>\n      <div className=\"furin-gooey-tabs__goo\" aria-hidden=\"true\" style={{ filter: `url(#${filterId})` }}>\n        {Array.from({ length: BLOBS }, (_, j) => (\n          <span key={j} ref={(n) => { blobRefs.current[j] = n; }} className=\"furin-gooey-tabs__blob\" />\n        ))}\n      </div>\n      <div role=\"tablist\" aria-label={ariaLabel} className=\"furin-gooey-tabs__lista\" onKeyDown={onKeyDown}>\n        {items.map((t, i) => (\n          <button\n            key={t.value}\n            ref={(n) => { tabRefs.current[i] = n; }}\n            type=\"button\"\n            role=\"tab\"\n            id={`${filterId}-tab-${i}`}\n            aria-selected={i === idx}\n            tabIndex={i === idx ? 0 : -1}\n            className=\"furin-gooey-tabs__tab\"\n            onClick={() => select(i)}\n          >\n            {t.label}\n          </button>\n        ))}\n      </div>\n    </div>\n  );\n}\n\nexport default GooeyTabs;\n",
      "type": "registry:component",
      "target": "components/furin/gooey-tabs/GooeyTabs.tsx"
    },
    {
      "path": "registry/gooey-tabs/GooeyTabs.css",
      "content": ".furin-gooey-tabs {\n  position: relative;\n  display: inline-flex;\n  padding: 6px;\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.11);\n  box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.06);\n  max-width: 100%;\n  isolation: isolate;\n}\n.furin-gooey-tabs__svg { position: absolute; width: 0; height: 0; pointer-events: none; }\n.furin-gooey-tabs__goo { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; }\n.furin-gooey-tabs__blob {\n  position: absolute; left: 0; top: 0;\n  border-radius: 999px;\n  background: var(--furin-gt-pill, #eef1ff);\n  opacity: 0;\n  will-change: transform, width, height;\n}\n.furin-gooey-tabs.is-ready .furin-gooey-tabs__blob { opacity: 1; }\n.furin-gooey-tabs__lista { position: relative; z-index: 1; display: flex; gap: 0; }\n.furin-gooey-tabs__tab {\n  appearance: none; border: 0; background: transparent; margin: 0;\n  padding: 11px 20px;\n  border-radius: 999px;\n  font: 600 15px/1.2 system-ui, -apple-system, \"Segoe UI\", sans-serif;\n  letter-spacing: -0.005em;\n  color: var(--furin-gt-text, #a8b0c6);\n  cursor: pointer;\n  white-space: nowrap;\n  transition: color 0.28s ease 0.06s;\n  -webkit-tap-highlight-color: transparent;\n}\n.furin-gooey-tabs__tab:hover { color: #fff; }\n.furin-gooey-tabs__tab[aria-selected=\"true\"] { color: var(--furin-gt-active, #0b0c12); }\n.furin-gooey-tabs__tab:focus-visible { outline: 2px solid var(--furin-gt-pill, #eef1ff); outline-offset: 2px; }\n@media (prefers-reduced-motion: reduce) { .furin-gooey-tabs__tab { transition: none; } }\n",
      "type": "registry:file",
      "target": "components/furin/gooey-tabs/GooeyTabs.css"
    }
  ]
}
