{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "particles",
  "type": "registry:component",
  "title": "Particles",
  "description": "Drifting dots joined by faint lines when they are close, gently pushed away by the pointer. Constellation style.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "particles",
    "canvas",
    "background",
    "constellation",
    "network",
    "pointer"
  ],
  "docs": "https://hyperblur.dev/effects/particles",
  "files": [
    {
      "path": "registry/hyperblur/particles.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/particles.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ParticlesProps extends React.HTMLAttributes<HTMLDivElement> {\n  count?: number;\n  color?: string;\n  lineColor?: string;\n  linkDistance?: number;\n  speed?: number;\n  size?: number;\n  seed?: number;\n}\n\nconst css = `\n.hb-par { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }\n.hb-par-c { display: block; width: 100%; height: 100%; }\n`;\n\nfunction rnd(seed: number, i: number) {\n  let x = (Math.imul(i + 1, 0x9e3779b1) + Math.imul(seed | 0, 0x85ebca6b)) >>> 0;\n  x = Math.imul((x >>> 16) ^ x, 0x45d9f3b) >>> 0;\n  x = Math.imul((x >>> 16) ^ x, 0x45d9f3b) >>> 0;\n  x = ((x >>> 16) ^ x) >>> 0;\n  return x / 4294967296;\n}\n\nexport function Particles({\n  count = 80,\n  color = \"#ffffff\",\n  lineColor = \"#2f7bff\",\n  linkDistance = 120,\n  speed = 1,\n  size = 2,\n  seed = 1,\n  className = \"\",\n  style,\n  ...rest\n}: ParticlesProps) {\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n\n  React.useEffect(() => {\n    const wrap = wrapRef.current;\n    const host = wrap?.parentElement;\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    if (!wrap || !host || !canvas || !ctx) return;\n\n    const n = Math.max(0, Math.min(600, Math.floor(count)));\n    const TAU = Math.PI * 2;\n    const link = Math.max(1, linkDistance);\n    const link2 = link * link;\n    const reach = Math.max(80, link * 1.2);\n    const reach2 = reach * reach;\n    const nx = new Float32Array(n);\n    const ny = new Float32Array(n);\n    const bx = new Float32Array(n);\n    const by = new Float32Array(n);\n    const vx = new Float32Array(n);\n    const vy = new Float32Array(n);\n    const rad = new Float32Array(n);\n    const alpha = new Float32Array(n);\n    const px = new Float32Array(n);\n    const py = new Float32Array(n);\n\n    for (let i = 0; i < n; i++) {\n      const a = rnd(seed, i * 8 + 1) * TAU;\n      const v = 10 + rnd(seed, i * 8 + 2) * 20;\n      nx[i] = rnd(seed, i * 8 + 3);\n      ny[i] = rnd(seed, i * 8 + 4);\n      bx[i] = Math.cos(a) * v;\n      by[i] = Math.sin(a) * v;\n      vx[i] = bx[i];\n      vy[i] = by[i];\n      rad[i] = size * (0.55 + rnd(seed, i * 8 + 5) * 0.9);\n      alpha[i] = 0.4 + rnd(seed, i * 8 + 6) * 0.6;\n    }\n\n    let w = 0;\n    let h = 0;\n    let pointerOn = false;\n    let mx = 0;\n    let my = 0;\n    let placed = false;\n\n    function place() {\n      for (let i = 0; i < n; i++) {\n        px[i] = nx[i] * w;\n        py[i] = ny[i] * h;\n      }\n      placed = true;\n    }\n\n    function draw() {\n      if (!ctx || !w || !h) return;\n      ctx.clearRect(0, 0, w, h);\n      ctx.lineWidth = 1;\n      ctx.strokeStyle = lineColor;\n      for (let i = 0; i < n; i++) {\n        const x = px[i];\n        const y = py[i];\n        for (let j = i + 1; j < n; j++) {\n          const dx = px[j] - x;\n          const dy = py[j] - y;\n          const d2 = dx * dx + dy * dy;\n          if (d2 >= link2) continue;\n          const k = 1 - Math.sqrt(d2) / link;\n          ctx.globalAlpha = k * k * 0.7;\n          ctx.beginPath();\n          ctx.moveTo(x, y);\n          ctx.lineTo(px[j], py[j]);\n          ctx.stroke();\n        }\n        if (pointerOn) {\n          const dx = mx - x;\n          const dy = my - y;\n          const d2 = dx * dx + dy * dy;\n          if (d2 < link2) {\n            const k = 1 - Math.sqrt(d2) / link;\n            ctx.globalAlpha = k * k * 0.9;\n            ctx.beginPath();\n            ctx.moveTo(x, y);\n            ctx.lineTo(mx, my);\n            ctx.stroke();\n          }\n        }\n      }\n      ctx.fillStyle = color;\n      for (let i = 0; i < n; i++) {\n        ctx.globalAlpha = alpha[i];\n        ctx.beginPath();\n        ctx.arc(px[i], py[i], rad[i], 0, TAU);\n        ctx.fill();\n      }\n      ctx.globalAlpha = 1;\n    }\n\n    function step(dt: number) {\n      const relax = Math.min(1, dt * 1.5);\n      const margin = 10;\n      for (let i = 0; i < n; i++) {\n        vx[i] += (bx[i] * speed - vx[i]) * relax;\n        vy[i] += (by[i] * speed - vy[i]) * relax;\n        if (pointerOn) {\n          const dx = px[i] - mx;\n          const dy = py[i] - my;\n          const d2 = dx * dx + dy * dy;\n          if (d2 < reach2 && d2 > 0.01) {\n            const d = Math.sqrt(d2);\n            const f = (1 - d / reach) * 160 * dt;\n            vx[i] += (dx / d) * f;\n            vy[i] += (dy / d) * f;\n          }\n        }\n        let x = px[i] + vx[i] * dt;\n        let y = py[i] + vy[i] * dt;\n        if (x < -margin) x = w + margin;\n        else if (x > w + margin) x = -margin;\n        if (y < -margin) y = h + margin;\n        else if (y > h + margin) y = -margin;\n        px[i] = x;\n        py[i] = y;\n      }\n    }\n\n    function resize() {\n      if (!wrap || !canvas || !ctx) return;\n      const nw = wrap.clientWidth;\n      const nh = wrap.clientHeight;\n      if (!nw || !nh) return;\n      const dpr = Math.min(2, window.devicePixelRatio || 1);\n      if (placed && w && h) {\n        for (let i = 0; i < n; i++) {\n          px[i] = (px[i] / w) * nw;\n          py[i] = (py[i] / h) * nh;\n        }\n      }\n      w = nw;\n      h = nh;\n      canvas.width = Math.max(1, Math.round(w * dpr));\n      canvas.height = Math.max(1, Math.round(h * dpr));\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      if (!placed) place();\n      draw();\n    }\n\n    const motion = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    let visible = true;\n    let raf = 0;\n    let prev = 0;\n\n    function frame(now: number) {\n      const dt = Math.min(0.05, (now - prev) / 1000);\n      prev = now;\n      step(dt);\n      draw();\n      raf = requestAnimationFrame(frame);\n    }\n\n    function sync() {\n      const run = visible && !document.hidden && !motion.matches;\n      if (run && !raf) {\n        prev = performance.now();\n        raf = requestAnimationFrame(frame);\n      } else if (!run && raf) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n    }\n\n    function onMotion() {\n      sync();\n      draw();\n    }\n\n    function move(e: PointerEvent) {\n      if (!host) return;\n      const rect = host.getBoundingClientRect();\n      mx = e.clientX - rect.left;\n      my = e.clientY - rect.top;\n      pointerOn = !motion.matches;\n    }\n\n    function leave() {\n      pointerOn = false;\n    }\n\n    const ro = new ResizeObserver(resize);\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1].isIntersecting;\n      sync();\n    });\n    ro.observe(wrap);\n    io.observe(wrap);\n    document.addEventListener(\"visibilitychange\", sync);\n    motion.addEventListener(\"change\", onMotion);\n    host.addEventListener(\"pointermove\", move, { passive: true });\n    host.addEventListener(\"pointerleave\", leave);\n    resize();\n    sync();\n\n    return () => {\n      if (raf) cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", sync);\n      motion.removeEventListener(\"change\", onMotion);\n      host.removeEventListener(\"pointermove\", move);\n      host.removeEventListener(\"pointerleave\", leave);\n    };\n  }, [count, color, lineColor, linkDistance, speed, size, seed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-par ${className}`} style={style} aria-hidden=\"true\" {...rest}>\n      <style href=\"hb-particles\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-par-c\" />\n    </div>\n  );\n}\n"
    }
  ]
}