{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "animated-beam",
  "type": "registry:component",
  "title": "Animated Beam",
  "description": "An integrations diagram: sources on the left feed a central hub that sends to an output, with a light pulse running along each curved connection. Beams re-route on resize.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "motion",
    "beam",
    "integrations",
    "diagram",
    "svg",
    "flow",
    "connections"
  ],
  "docs": "https://hyperblur.dev/effects/animated-beam",
  "files": [
    {
      "path": "registry/hyperblur/animated-beam.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/animated-beam.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BeamNode {\n  icon: React.ReactNode;\n  label: string;\n}\n\nexport interface AnimatedBeamProps extends React.HTMLAttributes<HTMLDivElement> {\n  sources?: BeamNode[];\n  hub?: BeamNode;\n  output?: BeamNode;\n  curvature?: number;\n  duration?: number;\n  color?: string;\n}\n\nconst css = `\n@keyframes hb-abm-tail { from { stroke-dashoffset: 34; } to { stroke-dashoffset: -106; } }\n@keyframes hb-abm-body { from { stroke-dashoffset: 16; } to { stroke-dashoffset: -124; } }\n@keyframes hb-abm-head { from { stroke-dashoffset: 6; } to { stroke-dashoffset: -134; } }\n@keyframes hb-abm-ping {\n  0%, 100% { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1), 0 0 0 0 color-mix(in srgb, var(--hb-abm-c) 0%, transparent); }\n  50% { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hb-abm-c) 50%, transparent), 0 0 22px 2px color-mix(in srgb, var(--hb-abm-c) 40%, transparent); }\n}\n.hb-abm {\n  position: relative;\n  box-sizing: border-box;\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  width: 100%;\n  container-type: inline-size;\n  font-family: inherit;\n  color: #ededed;\n  --hb-abm-n: clamp(28px, 9cqw, 56px);\n}\n.hb-abm *, .hb-abm *::before, .hb-abm *::after { box-sizing: border-box; }\n.hb-abm-svg {\n  position: absolute;\n  inset: 0;\n  width: 100%;\n  height: 100%;\n  overflow: visible;\n  pointer-events: none;\n}\n.hb-abm-col {\n  position: relative;\n  z-index: 1;\n  display: flex;\n  flex-direction: column;\n  gap: clamp(6px, 2.4cqw, 16px);\n}\n.hb-abm-node {\n  position: relative;\n  z-index: 1;\n  display: grid;\n  place-items: center;\n  width: var(--hb-abm-n);\n  height: var(--hb-abm-n);\n  border-radius: 50%;\n  background: linear-gradient(160deg, #1b1b1e, #0d0d0f);\n  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1), 0 6px 18px -8px rgba(0, 0, 0, 0.9);\n  color: #d4d4d8;\n  transition: color .2s ease, box-shadow .2s ease;\n}\n.hb-abm-node:hover { color: #ffffff; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hb-abm-c) 60%, transparent); }\n.hb-abm-node svg { width: 46%; height: 46%; }\n.hb-abm-node[data-kind=\"hub\"] {\n  width: calc(var(--hb-abm-n) * 1.6);\n  height: calc(var(--hb-abm-n) * 1.6);\n  border-radius: 30%;\n  color: #ffffff;\n  background: radial-gradient(120% 120% at 30% 0%, color-mix(in srgb, var(--hb-abm-c) 45%, #18181b), #0d0d10 70%);\n  animation: hb-abm-ping var(--hb-abm-d) ease-in-out infinite;\n}\n.hb-abm-node[data-kind=\"output\"] {\n  width: calc(var(--hb-abm-n) * 1.15);\n  height: calc(var(--hb-abm-n) * 1.15);\n}\n.hb-abm-base { fill: none; stroke: rgba(255, 255, 255, 0.09); stroke-width: 1.5; }\n.hb-abm-pulse { fill: none; stroke-linecap: round; animation-duration: var(--hb-abm-d); animation-timing-function: cubic-bezier(.5, 0, .5, 1); animation-iteration-count: infinite; }\n.hb-abm-pulse[data-l=\"tail\"] { stroke: var(--hb-abm-c); stroke-opacity: .35; stroke-width: 2; stroke-dasharray: 34 300; animation-name: hb-abm-tail; }\n.hb-abm-pulse[data-l=\"body\"] { stroke: var(--hb-abm-c); stroke-width: 2; stroke-dasharray: 16 300; animation-name: hb-abm-body; filter: drop-shadow(0 0 3px var(--hb-abm-c)); }\n.hb-abm-pulse[data-l=\"head\"] { stroke: #ffffff; stroke-width: 2.2; stroke-dasharray: 6 300; animation-name: hb-abm-head; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-abm-pulse { animation: none; stroke-dashoffset: -40; }\n  .hb-abm-node[data-kind=\"hub\"] { animation: none; }\n}\n`;\n\nfunction Glyph({ d }: { d: string }) {\n  return (\n    <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth={1.8} strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d={d} />\n    </svg>\n  );\n}\n\nconst defaultSources: BeamNode[] = [\n  { icon: <Glyph d=\"M3 6h18v12H3zM3.5 7l8.5 6 8.5-6\" />, label: \"Email\" },\n  { icon: <Glyph d=\"M4 6h16v14H4zM4 10h16M8 3v4M16 3v4\" />, label: \"Calendar\" },\n  { icon: <Glyph d=\"M5 5h14v10h-8l-4 4v-4H5z\" />, label: \"Chat\" },\n  { icon: <Glyph d=\"M12 4c4.4 0 8 1.3 8 3s-3.6 3-8 3-8-1.3-8-3 3.6-3 8-3zM4 7v10c0 1.7 3.6 3 8 3s8-1.3 8-3V7M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3\" />, label: \"Database\" },\n];\n\nconst defaultHub: BeamNode = {\n  icon: <Glyph d=\"M13 3L5 14h6l-1 7 8-11h-6z\" />,\n  label: \"Sync engine\",\n};\n\nconst defaultOutput: BeamNode = {\n  icon: <Glyph d=\"M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4.5 20a7.5 7.5 0 0 1 15 0\" />,\n  label: \"Workspace\",\n};\n\ninterface Layout {\n  w: number;\n  h: number;\n  paths: string[];\n}\n\nfunction curve(x1: number, y1: number, x2: number, y2: number, k: number) {\n  const c = (x2 - x1) * k;\n  return `M${x1.toFixed(1)} ${y1.toFixed(1)} C${(x1 + c).toFixed(1)} ${y1.toFixed(1)} ${(x2 - c).toFixed(1)} ${y2.toFixed(1)} ${x2.toFixed(1)} ${y2.toFixed(1)}`;\n}\n\nfunction rnd(i: number) {\n  let x = Math.imul(i + 1, 2654435761) >>> 0;\n  x = Math.imul((x >>> 16) ^ x, 0x45d9f3b);\n  x = ((x >>> 16) ^ x) >>> 0;\n  return x / 4294967296;\n}\n\nexport function AnimatedBeam({\n  sources = defaultSources,\n  hub = defaultHub,\n  output = defaultOutput,\n  curvature = 0.5,\n  duration = 3,\n  color = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: AnimatedBeamProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const sourceRefs = React.useRef<(HTMLSpanElement | null)[]>([]);\n  const hubRef = React.useRef<HTMLSpanElement>(null);\n  const outRef = React.useRef<HTMLSpanElement>(null);\n  const [layout, setLayout] = React.useState<Layout | null>(null);\n  const count = sources.length;\n  const k = Math.min(1, Math.max(0, curvature));\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    if (!root) return;\n\n    const measure = () => {\n      const box = root.getBoundingClientRect();\n      const hubEl = hubRef.current;\n      const outEl = outRef.current;\n      if (!hubEl || !outEl || box.width === 0) return;\n      const rect = (el: Element) => {\n        const r = el.getBoundingClientRect();\n        return { l: r.left - box.left, r: r.right - box.left, y: r.top - box.top + r.height / 2 };\n      };\n      const h = rect(hubEl);\n      const o = rect(outEl);\n      const paths: string[] = [];\n      for (let i = 0; i < count; i++) {\n        const el = sourceRefs.current[i];\n        if (!el) continue;\n        const s = rect(el);\n        paths.push(curve(s.r, s.y, h.l, h.y, k));\n      }\n      paths.push(curve(h.r, h.y, o.l, o.y, k));\n      const next: Layout = { w: box.width, h: box.height, paths };\n      setLayout((prev) =>\n        prev && prev.w === next.w && prev.h === next.h && prev.paths.join(\"|\") === next.paths.join(\"|\") ? prev : next,\n      );\n    };\n\n    const ro = new ResizeObserver(measure);\n    ro.observe(root);\n    sourceRefs.current.forEach((el) => el && ro.observe(el));\n    if (hubRef.current) ro.observe(hubRef.current);\n    if (outRef.current) ro.observe(outRef.current);\n    return () => ro.disconnect();\n  }, [count, k]);\n\n  const d = Math.max(0.4, duration);\n  const vars = {\n    \"--hb-abm-c\": color,\n    \"--hb-abm-d\": `${d.toFixed(2)}s`,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <div ref={rootRef} className={`hb-abm ${className}`} style={vars} role=\"group\" aria-label={`${sources.map((s) => s.label).join(\", \")} connected to ${hub.label}, sent to ${output.label}`} {...rest}>\n      <style href=\"hb-animated-beam\" precedence=\"default\">{css}</style>\n      {layout && (\n        <svg className=\"hb-abm-svg\" viewBox={`0 0 ${layout.w.toFixed(1)} ${layout.h.toFixed(1)}`} aria-hidden=\"true\">\n          {layout.paths.map((p, i) => (\n            <path key={`b${i}`} className=\"hb-abm-base\" d={p} />\n          ))}\n          {layout.paths.map((p, i) => {\n            const last = i === layout.paths.length - 1;\n            const delay = last ? -d * 0.35 : -(rnd(i) * d);\n            const st = { animationDelay: `${delay.toFixed(3)}s` };\n            return (\n              <g key={`p${i}`}>\n                <path className=\"hb-abm-pulse\" data-l=\"tail\" d={p} pathLength={100} style={st} />\n                <path className=\"hb-abm-pulse\" data-l=\"body\" d={p} pathLength={100} style={st} />\n                <path className=\"hb-abm-pulse\" data-l=\"head\" d={p} pathLength={100} style={st} />\n              </g>\n            );\n          })}\n        </svg>\n      )}\n      <div className=\"hb-abm-col\">\n        {sources.map((s, i) => (\n          <span\n            key={`${s.label}-${i}`}\n            ref={(el) => {\n              sourceRefs.current[i] = el;\n            }}\n            className=\"hb-abm-node\"\n            role=\"img\"\n            aria-label={s.label}\n            title={s.label}\n          >\n            {s.icon}\n          </span>\n        ))}\n      </div>\n      <span ref={hubRef} className=\"hb-abm-node\" data-kind=\"hub\" role=\"img\" aria-label={hub.label} title={hub.label}>\n        {hub.icon}\n      </span>\n      <span ref={outRef} className=\"hb-abm-node\" data-kind=\"output\" role=\"img\" aria-label={output.label} title={output.label}>\n        {output.icon}\n      </span>\n    </div>\n  );\n}\n"
    }
  ]
}