{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "particle-network",
  "type": "registry:ui",
  "title": "Particle Network",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Interactive Canvas 2D proximity graph where drifting nodes dynamically connect with distance-attenuated lines whenever they pass within a threshold radius.",
  "dependencies": [
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/particle-network.tsx",
      "content": "\"use client\";\n\nimport React, { useEffect, useRef } from \"react\";\nimport { Network } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface ParticleNetworkProps {\n  /** Number of drifting nodes. Default: 55 */\n  particleCount?: number;\n  /** Maximum distance in pixels to draw a connecting edge. Default: 125 */\n  connectDistance?: number;\n  /** Drift velocity multiplier. Default: 1 */\n  speed?: number;\n  /** RGB triplet (e.g. \"255, 255, 255\") for nodes and edges. Default: \"255, 255, 255\" */\n  particleColor?: string;\n  /** Connect nodes to the user's cursor when hovering. Default: true */\n  interactive?: boolean;\n  /** Optional foreground content */\n  children?: React.ReactNode;\n  className?: string;\n}\n\ninterface NodeParticle {\n  x: number;\n  y: number;\n  vx: number;\n  vy: number;\n  r: number;\n}\n\nexport function ParticleNetwork({\n  particleCount = 55,\n  connectDistance = 125,\n  speed = 1,\n  particleColor = \"255, 255, 255\",\n  interactive = true,\n  children,\n  className,\n}: ParticleNetworkProps) {\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const mouseRef = useRef<{ x: number; y: number; active: boolean }>({\n    x: 0,\n    y: 0,\n    active: false,\n  });\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    if (!canvas) return;\n    const ctx = canvas.getContext(\"2d\");\n    if (!ctx) return;\n\n    let rafId: number;\n    let width = (canvas.width = canvas.offsetWidth || 600);\n    let height = (canvas.height = canvas.offsetHeight || 360);\n\n    const nodes: NodeParticle[] = Array.from({ length: particleCount }, () => {\n      const angle = Math.random() * Math.PI * 2;\n      const v = (18 + Math.random() * 28) * speed;\n      return {\n        x: Math.random() * width,\n        y: Math.random() * height,\n        vx: Math.cos(angle) * v,\n        vy: Math.sin(angle) * v,\n        r: 1.5 + Math.random() * 1.5,\n      };\n    });\n\n    const handleResize = () => {\n      if (!canvas) return;\n      width = canvas.width = canvas.offsetWidth || 600;\n      height = canvas.height = canvas.offsetHeight || 360;\n    };\n\n    window.addEventListener(\"resize\", handleResize);\n\n    let last = performance.now();\n    const render = (now: number) => {\n      const dt = Math.min(0.05, (now - last) / 1000);\n      last = now;\n\n      ctx.clearRect(0, 0, width, height);\n\n      for (let i = 0; i < nodes.length; i++) {\n        const n = nodes[i];\n        n.x += n.vx * dt;\n        n.y += n.vy * dt;\n\n        if (n.x < 0 || n.x > width) n.vx *= -1;\n        if (n.y < 0 || n.y > height) n.vy *= -1;\n\n        // Draw node dot\n        ctx.beginPath();\n        ctx.arc(n.x, n.y, n.r, 0, Math.PI * 2);\n        ctx.fillStyle = `rgba(${particleColor}, 0.75)`;\n        ctx.fill();\n\n        // Connect to neighbor nodes within threshold distance\n        for (let j = i + 1; j < nodes.length; j++) {\n          const m = nodes[j];\n          const dx = n.x - m.x;\n          const dy = n.y - m.y;\n          const dist = Math.hypot(dx, dy);\n\n          if (dist < connectDistance) {\n            const alpha = (1 - dist / connectDistance) * 0.42;\n            ctx.strokeStyle = `rgba(${particleColor}, ${alpha.toFixed(3)})`;\n            ctx.lineWidth = 1;\n            ctx.beginPath();\n            ctx.moveTo(n.x, n.y);\n            ctx.lineTo(m.x, m.y);\n            ctx.stroke();\n          }\n        }\n\n        // Connect to cursor if active\n        if (interactive && mouseRef.current.active) {\n          const mdx = n.x - mouseRef.current.x;\n          const mdy = n.y - mouseRef.current.y;\n          const mDist = Math.hypot(mdx, mdy);\n          const cursorThreshold = connectDistance * 1.25;\n          if (mDist < cursorThreshold) {\n            const alpha = (1 - mDist / cursorThreshold) * 0.65;\n            ctx.strokeStyle = `rgba(${particleColor}, ${alpha.toFixed(3)})`;\n            ctx.lineWidth = 1.2;\n            ctx.beginPath();\n            ctx.moveTo(n.x, n.y);\n            ctx.lineTo(mouseRef.current.x, mouseRef.current.y);\n            ctx.stroke();\n          }\n        }\n      }\n\n      rafId = requestAnimationFrame(render);\n    };\n\n    rafId = requestAnimationFrame(render);\n    return () => {\n      cancelAnimationFrame(rafId);\n      window.removeEventListener(\"resize\", handleResize);\n    };\n  }, [particleCount, connectDistance, speed, particleColor, interactive]);\n\n  return (\n    <div\n      data-fullscreen-scroll\n      onMouseMove={(e) => {\n        const rect = e.currentTarget.getBoundingClientRect();\n        mouseRef.current.x = e.clientX - rect.left;\n        mouseRef.current.y = e.clientY - rect.top;\n        mouseRef.current.active = true;\n      }}\n      onMouseLeave={() => {\n        mouseRef.current.active = false;\n      }}\n      className={cn(\n        \"relative flex min-h-[360px] w-full flex-col justify-between overflow-hidden rounded-3xl border border-neutral-800 bg-[#05070B] p-6 text-white shadow-sm\",\n        className\n      )}\n    >\n      <canvas\n        ref={canvasRef}\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0 h-full w-full\"\n      />\n\n      <div className=\"relative z-10 flex flex-1 flex-col justify-between\">\n        {children ?? (\n          <>\n            <div className=\"flex items-center justify-between gap-2\">\n              <span className=\"inline-flex items-center gap-1.5 rounded-full border border-white/15 bg-white/10 px-3 py-1 font-mono text-[11px] font-medium text-white backdrop-blur-md\">\n                <Network className=\"h-3.5 w-3.5 text-neutral-300\" />\n                Particle Network · {particleCount} Nodes\n              </span>\n              <span className=\"font-mono text-[11px] text-white/50\">\n                Radius: {connectDistance}px\n              </span>\n            </div>\n\n            <div className=\"my-auto max-w-md py-8\">\n              <h3 className=\"text-2xl font-bold tracking-tight text-white sm:text-3xl\">\n                Proximity Graph Topology\n              </h3>\n              <p className=\"mt-2 text-xs leading-relaxed text-white/75 sm:text-sm\">\n                Drifting nodes dynamically form edges whenever their Euclidean\n                distance falls below {connectDistance}px, with line opacity\n                scaling inversely with distance.\n              </p>\n            </div>\n\n            <div className=\"font-mono text-[11px] text-white/50\">\n              Hover anywhere to attract proximity edges\n            </div>\n          </>\n        )}\n      </div>\n    </div>\n  );\n}\n\nexport default ParticleNetwork;\n",
      "type": "registry:ui",
      "target": "components/ui/particle-network.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
