{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "starry-night",
  "type": "registry:ui",
  "title": "Starry Night",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Canvas 2D night sky rendering 100 to 350 depth-layered stars that twinkle via independent sine-wave phases and shift smoothly on pointer move.",
  "dependencies": [
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/starry-night.tsx",
      "content": "\"use client\";\n\nimport React, { useEffect, useRef, useState } from \"react\";\nimport { Sparkles } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface StarryNightProps {\n  /** Number of stars rendered on the canvas (100 to 350). Default: 200 */\n  density?: number;\n  /** Enable sine-wave alpha twinkling per star. Default: true */\n  twinkle?: boolean;\n  /** Mouse-move parallax shift intensity in pixels. Default: 24 */\n  parallax?: number;\n  /** Optional foreground content */\n  children?: React.ReactNode;\n  className?: string;\n}\n\ninterface StarParticle {\n  x: number;\n  y: number;\n  radius: number;\n  baseAlpha: number;\n  phase: number;\n  speed: number;\n  depth: number; // 0.2 (far) to 1.0 (near)\n}\n\nexport function StarryNight({\n  density = 200,\n  twinkle = true,\n  parallax = 24,\n  children,\n  className,\n}: StarryNightProps) {\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const pointerRef = useRef({ x: 0, y: 0, targetX: 0, targetY: 0 });\n  const [twinkleOn, setTwinkleOn] = useState(twinkle);\n\n  useEffect(() => {\n    setTwinkleOn(twinkle);\n  }, [twinkle]);\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 count = Math.max(40, Math.min(400, density));\n    const stars: StarParticle[] = Array.from({ length: count }, () => {\n      const depth = 0.2 + Math.random() * 0.8;\n      return {\n        x: Math.random() * width,\n        y: Math.random() * height,\n        radius: 0.5 + depth * 1.4,\n        baseAlpha: 0.35 + Math.random() * 0.65,\n        phase: Math.random() * Math.PI * 2,\n        speed: 1.2 + Math.random() * 2.8,\n        depth,\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    const render = (now: number) => {\n      const t = now * 0.001;\n      // Smooth lerp pointer parallax\n      pointerRef.current.x +=\n        (pointerRef.current.targetX - pointerRef.current.x) * 0.08;\n      pointerRef.current.y +=\n        (pointerRef.current.targetY - pointerRef.current.y) * 0.08;\n\n      ctx.clearRect(0, 0, width, height);\n\n      for (let i = 0; i < stars.length; i++) {\n        const s = stars[i];\n        const alpha = twinkleOn\n          ? s.baseAlpha * (0.45 + 0.55 * Math.sin(t * s.speed + s.phase))\n          : s.baseAlpha;\n\n        const drawX =\n          (s.x + pointerRef.current.x * s.depth * parallax + width) % width;\n        const drawY =\n          (s.y + pointerRef.current.y * s.depth * parallax + height) % height;\n\n        ctx.beginPath();\n        ctx.arc(drawX, drawY, s.radius, 0, Math.PI * 2);\n        ctx.fillStyle = `rgba(255, 255, 255, ${alpha.toFixed(3)})`;\n        ctx.fill();\n      }\n\n      rafId = requestAnimationFrame(render);\n    };\n\n    rafId = requestAnimationFrame(render);\n    return () => {\n      cancelAnimationFrame(rafId);\n      window.removeEventListener(\"resize\", handleResize);\n    };\n  }, [density, parallax, twinkleOn]);\n\n  return (\n    <div\n      data-fullscreen-scroll\n      onMouseMove={(e) => {\n        const rect = e.currentTarget.getBoundingClientRect();\n        const nx = ((e.clientX - rect.left) / rect.width - 0.5) * 2;\n        const ny = ((e.clientY - rect.top) / rect.height - 0.5) * 2;\n        pointerRef.current.targetX = -nx;\n        pointerRef.current.targetY = -ny;\n      }}\n      onMouseLeave={() => {\n        pointerRef.current.targetX = 0;\n        pointerRef.current.targetY = 0;\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-gradient-to-b from-[#03050C] via-[#070B19] to-[#0F172A] 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                <Sparkles className=\"h-3.5 w-3.5 text-sky-300\" />\n                Starry Night · {density} Stars\n              </span>\n\n              <button\n                type=\"button\"\n                onClick={() => setTwinkleOn((v) => !v)}\n                className=\"rounded-full border border-white/15 bg-white/10 px-3 py-1 font-mono text-[11px] text-white/85 backdrop-blur-md transition-colors hover:bg-white/20\"\n              >\n                Twinkle: {twinkleOn ? \"ON\" : \"OFF\"}\n              </button>\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                Deep Space Starfield\n              </h3>\n              <p className=\"mt-2 text-xs leading-relaxed text-white/75 sm:text-sm\">\n                Move your cursor to experience multi-plane depth parallax while\n                each star oscillates on an independent sine-wave phase.\n              </p>\n            </div>\n\n            <div className=\"font-mono text-[11px] text-white/50\">\n              Canvas 2D · Sine-Wave Alpha · 3D Depth Parallax\n            </div>\n          </>\n        )}\n      </div>\n    </div>\n  );\n}\n\nexport default StarryNight;\n",
      "type": "registry:ui",
      "target": "components/ui/starry-night.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"
    }
  ]
}
