跳至正文
获取 Pro
业务区块B.19

节点流光拓扑

FreeRegistry
components/linyi/beam-flow.tsx
lucide-reactmotion
"use client";
 
import * as React from "react";
import { motion } from "motion/react";
import { Bot, Layers, Terminal, Sparkles, Code2 } from "lucide-react";
import { cn } from "@/lib/cn";
import { SPRING_SNAPPY } from "@/lib/motion";
import { playSound } from "@/lib/sound";
 
export interface BeamFlowProps {
speed?: number;
compact?: boolean;
className?: string;
}
 
const LEFT_NODES = [
{ id: "claude", label: "Claude", y: 24, icon: Sparkles },
{ id: "codex", label: "Codex", y: 74, icon: Terminal },
{ id: "gemini", label: "Gemini", y: 124, icon: Bot },
] as const;
 
const RIGHT_NODES = [
{ id: "ui", label: "React TSX", y: 44, icon: Code2 },
{ id: "tokens", label: "Tokens", y: 104, icon: Layers },
] as const;
 
export function BeamFlow({
speed = 2.4,
compact = false,
className,
}: BeamFlowProps) {
const [focused, setFocused] = React.useState<string | null>(null);
 
const toggleNode = (id: string) => {
playSound("tap", { volume: 0.45 });
setFocused((prev) => (prev === id ? null : id));
};
 
return (
<div
className={cn(
"relative w-full rounded-[14px] border border-line bg-surface p-3.5 select-none",
compact ? "max-w-[264px]" : "max-w-[420px] p-5",
className
)}
>
<div className="relative h-[148px] w-full">
{/* SVG Cubic Bezier Tracks + Animated Light Beams */}
<svg
viewBox="0 0 320 148"
preserveAspectRatio="none"
className="pointer-events-none absolute inset-0 h-full w-full"
aria-hidden="true"
>
{LEFT_NODES.map((node, i) => {
const d = `M 56 ${node.y} C 108 ${node.y}, 112 74, 160 74`;
const active = !focused || focused === node.id;
return (
<g key={node.id}>
<path
d={d}
fill="none"
stroke="var(--line-strong)"
strokeWidth="1.25"
opacity={active ? 0.65 : 0.2}
/>
{active && (
<motion.path
d={d}
fill="none"
stroke="var(--accent)"
strokeWidth="2"
strokeLinecap="round"
strokeDasharray="24 140"
initial={{ strokeDashoffset: 164 }}
animate={{ strokeDashoffset: 0 }}
transition={{
duration: speed,
delay: i * 0.45,
repeat: Infinity,
ease: "linear",
}}
/>
)}
</g>
);
})}
 
{RIGHT_NODES.map((node, i) => {
const d = `M 160 74 C 208 74, 212 ${node.y}, 264 ${node.y}`;
return (
<g key={node.id}>
<path
d={d}
fill="none"
stroke="var(--line-strong)"
strokeWidth="1.25"
opacity="0.65"
/>
<motion.path
d={d}
fill="none"
stroke="var(--status-success)"
strokeWidth="2"
strokeLinecap="round"
strokeDasharray="22 140"
initial={{ strokeDashoffset: 162 }}
animate={{ strokeDashoffset: 0 }}
transition={{
duration: speed,
delay: 0.35 + i * 0.55,
repeat: Infinity,
ease: "linear",
}}
/>
</g>
);
})}
</svg>
 
{/* Left Input Nodes */}
<div className="absolute inset-y-0 left-0 flex flex-col justify-between py-1">
{LEFT_NODES.map((node) => {
const Icon = node.icon;
const selected = focused === node.id;
return (
<motion.button
key={node.id}
type="button"
onClick={() => toggleNode(node.id)}
whileTap={{ scale: 0.94 }}
transition={SPRING_SNAPPY}
className="relative z-10 inline-flex h-8 items-center gap-1.5 rounded-full px-2.5 text-[11px] font-medium cursor-pointer transition-colors"
style={{
background: selected ? "var(--accent-soft)" : "var(--bg-canvas)",
color: selected ? "var(--accent)" : "var(--fg-primary)",
border: selected
? "1px solid var(--accent-border)"
: "1px solid var(--line-strong)",
}}
>
<Icon className="h-3 w-3" />
{!compact && <span>{node.label}</span>}
</motion.button>
);
})}
</div>
 
{/* Center Core Node */}
<div className="absolute top-1/2 left-1/2 z-10 -translate-x-1/2 -translate-y-1/2">
<div
className="flex h-11 w-11 items-center justify-center rounded-2xl shadow-panel"
style={{
background: "var(--bg-inverse)",
color: "var(--fg-inverse)",
border: "1px solid rgba(255,255,255,0.14)",
}}
>
<svg width="15" height="15" viewBox="0 0 14 14" fill="none" aria-hidden="true">
<path d="M3 2.5V11.5H11" stroke="currentColor" strokeWidth="1.9" strokeLinecap="square" />
<circle cx="10.2" cy="3.8" r="1.85" style={{ fill: "var(--accent)" }} />
</svg>
</div>
</div>
 
{/* Right Output Nodes */}
<div className="absolute inset-y-0 right-0 flex flex-col justify-around py-2">
{RIGHT_NODES.map((node) => {
const Icon = node.icon;
return (
<div
key={node.id}
className="relative z-10 inline-flex h-8 items-center gap-1.5 rounded-full px-2.5 text-[11px] font-medium"
style={{
background: "var(--bg-canvas)",
color: "var(--fg-primary)",
border: "1px solid var(--line-strong)",
}}
>
<Icon className="h-3 w-3" style={{ color: "var(--status-success)" }} />
{!compact && <span>{node.label}</span>}
</div>
);
})}
</div>
</div>
</div>
);
}