{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"updraft-dust","type":"registry:ui","title":"Updraft Dust","description":"Weightless glowing dust that drifts upward and curls away from the cursor.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/updraft-dust.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nexport interface UpdraftDustProps {\n  /** Number of particles. */\n  count?: number;\n  /** 6-digit hex. */\n  color?: string;\n  /** Upward drift multiplier. */\n  speed?: number;\n  /** Px radius the cursor disturbs. */\n  radius?: number;\n  /** How hard the cursor swirls particles away. */\n  swirl?: number;\n  /** Largest particle radius in px. */\n  size?: number;\n  className?: string;\n}\n\ntype P = { x: number; y: number; vx: number; vy: number; z: number; phase: number };\n\nexport function UpdraftDust({\n  count = 600,\n  color = \"#c6ff3d\",\n  speed = 1,\n  radius = 160,\n  swirl = 1,\n  size = 3,\n  className,\n}: UpdraftDustProps) {\n  const ref = useRef<HTMLCanvasElement>(null);\n\n  useEffect(() => {\n    const canvas = ref.current!;\n    const host = canvas.parentElement!;\n    const ctx = canvas.getContext(\"2d\")!;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let w = 0;\n    let h = 0;\n    let raf = 0;\n    let visible = true;\n    let last = 0;\n    const mouse = { x: -9999, y: -9999, vx: 0, vy: 0, in: false };\n\n    // Pre-render one glowing dot and stamp it; far cheaper than a gradient per particle.\n    const sprite = document.createElement(\"canvas\");\n    sprite.width = sprite.height = 64;\n    const sctx = sprite.getContext(\"2d\")!;\n    const g = sctx.createRadialGradient(32, 32, 0, 32, 32, 32);\n    g.addColorStop(0, \"#fff\");\n    g.addColorStop(0.18, color);\n    g.addColorStop(0.45, color + \"44\");\n    g.addColorStop(1, color + \"00\");\n    sctx.fillStyle = g;\n    sctx.fillRect(0, 0, 64, 64);\n\n    const pts: P[] = Array.from({ length: count }, () => ({\n      x: Math.random(),\n      y: Math.random(),\n      vx: 0,\n      vy: 0,\n      z: 0.25 + Math.random() ** 2 * 0.75,\n      phase: Math.random() * Math.PI * 2,\n    }));\n    let placed = false;\n\n    const frame = (now: number) => {\n      const dt = Math.min((now - (last || now)) / 16.67, 3);\n      last = now;\n      const t = now / 1000;\n      const r2 = radius * radius;\n      ctx.clearRect(0, 0, w, h);\n      ctx.globalCompositeOperation = \"lighter\";\n      for (const p of pts) {\n        let boost = 0;\n        if (!reduced) {\n          const dx = p.x - mouse.x;\n          const dy = p.y - mouse.y;\n          const d2 = dx * dx + dy * dy;\n          if (d2 < r2 && d2 > 1) {\n            const d = Math.sqrt(d2);\n            const f = (1 - d / radius) ** 2 * swirl * dt;\n            const nx = dx / d;\n            const ny = dy / d;\n            // Outward push plus a tangential kick makes the dust curl around the pointer.\n            p.vx += (nx * 0.5 - ny * 1.1) * f + mouse.vx * f * 0.06;\n            p.vy += (ny * 0.5 + nx * 1.1) * f + mouse.vy * f * 0.06;\n            boost = f;\n          }\n          const damp = Math.pow(0.95, dt);\n          p.vx *= damp;\n          p.vy *= damp;\n          p.x += (p.vx + Math.sin(t * 0.7 + p.phase) * 0.25 * p.z) * dt;\n          p.y += (p.vy - speed * (0.25 + p.z * 0.7)) * dt;\n          if (p.y < -20) {\n            p.y = h + 20;\n            p.x = Math.random() * w;\n            p.vx = p.vy = 0;\n          } else if (p.y > h + 20) p.y = -20;\n          if (p.x < -20) p.x += w + 40;\n          else if (p.x > w + 20) p.x -= w + 40;\n        }\n        // Fade in from the bottom edge and out toward the top.\n        const edge = Math.min(1, (p.y + 20) / (h * 0.25), (h + 20 - p.y) / (h * 0.15));\n        const s = size * p.z * 6 * (1 + boost * 2);\n        ctx.globalAlpha = Math.max(0, edge) * (0.35 + p.z * 0.65);\n        ctx.drawImage(sprite, p.x - s / 2, p.y - s / 2, s, s);\n      }\n      ctx.globalAlpha = 1;\n      ctx.globalCompositeOperation = \"source-over\";\n      mouse.vx *= 0.8;\n      mouse.vy *= 0.8;\n    };\n\n    const loop = (now: number) => {\n      frame(now);\n      raf = visible && !reduced ? requestAnimationFrame(loop) : 0;\n    };\n\n    const resize = () => {\n      const dpr = Math.min(window.devicePixelRatio || 1, 2);\n      w = canvas.offsetWidth;\n      h = canvas.offsetHeight;\n      canvas.width = w * dpr;\n      canvas.height = h * dpr;\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      if (!placed && w) {\n        for (const p of pts) {\n          p.x *= w;\n          p.y *= h;\n        }\n        placed = true;\n      }\n      if (reduced) frame(performance.now());\n    };\n\n    const onMove = (e: PointerEvent) => {\n      const r = canvas.getBoundingClientRect();\n      const x = e.clientX - r.left;\n      const y = e.clientY - r.top;\n      if (mouse.in) {\n        mouse.vx = x - mouse.x;\n        mouse.vy = y - mouse.y;\n      }\n      mouse.x = x;\n      mouse.y = y;\n      mouse.in = true;\n    };\n    const onLeave = () => {\n      mouse.in = false;\n      mouse.x = mouse.y = -9999;\n    };\n\n    const ro = new ResizeObserver(resize);\n    ro.observe(canvas);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible && !raf && !reduced) raf = requestAnimationFrame(loop);\n    });\n    io.observe(canvas);\n    host.addEventListener(\"pointermove\", onMove, { passive: true });\n    host.addEventListener(\"pointerleave\", onLeave);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      host.removeEventListener(\"pointermove\", onMove);\n      host.removeEventListener(\"pointerleave\", onLeave);\n    };\n  }, [count, color, speed, radius, swirl, size]);\n\n  return (\n    <canvas\n      ref={ref}\n      aria-hidden\n      className={className}\n      style={{ position: \"absolute\", inset: 0, width: \"100%\", height: \"100%\", pointerEvents: \"none\" }}\n    />\n  );\n}\n"}]}