{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "galaxy-nebula",
  "type": "registry:ui",
  "title": "Galaxy & Nebula",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Real-time WebGL fragment shader rendering a rotating spiral galaxy and cosmic dust nebula using 5-octave Fractional Brownian Motion (FBM) noise.",
  "dependencies": [
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/galaxy-nebula.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 GalaxyNebulaProps {\n  /** Animation speed multiplier. Default: 1 */\n  speed?: number;\n  /** Spiral rotation speed. Default: 0.25 */\n  rotationSpeed?: number;\n  /** Primary nebula core hex color. Default: \"#8B5CF6\" */\n  primaryColor?: string;\n  /** Secondary outer dust hex color. Default: \"#06B6D4\" */\n  secondaryColor?: string;\n  /** Optional foreground content */\n  children?: React.ReactNode;\n  className?: string;\n}\n\nfunction hexToRgbNormalized(hex: string): [number, number, number] {\n  const clean = hex.replace(\"#\", \"\");\n  const num = parseInt(clean.length === 3 ? clean.replace(/(.)/g, \"$1$1\") : clean, 16) || 0;\n  return [((num >> 16) & 255) / 255, ((num >> 8) & 255) / 255, (num & 255) / 255];\n}\n\nconst VERTEX_SHADER = `\n  attribute vec2 position;\n  void main() {\n    gl_Position = vec4(position, 0.0, 1.0);\n  }\n`;\n\nconst FRAGMENT_SHADER = `\n  precision mediump float;\n  uniform vec2 u_resolution;\n  uniform float u_time;\n  uniform float u_rotSpeed;\n  uniform vec3 u_color1;\n  uniform vec3 u_color2;\n\n  float hash(vec2 p) {\n    p = fract(p * vec2(123.34, 456.21));\n    p += dot(p, p + 45.32);\n    return fract(p.x * p.y);\n  }\n\n  float noise(vec2 p) {\n    vec2 i = floor(p);\n    vec2 f = fract(p);\n    f = f * f * (3.0 - 2.0 * f);\n    float a = hash(i);\n    float b = hash(i + vec2(1.0, 0.0));\n    float c = hash(i + vec2(0.0, 1.0));\n    float d = hash(i + vec2(1.0, 1.0));\n    return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);\n  }\n\n  float fbm(vec2 p) {\n    float v = 0.0;\n    float a = 0.5;\n    mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.5));\n    for (int i = 0; i < 5; i++) {\n      v += a * noise(p);\n      p = rot * p * 2.02 + vec2(100.0);\n      a *= 0.5;\n    }\n    return v;\n  }\n\n  void main() {\n    vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / min(u_resolution.x, u_resolution.y);\n    float r = length(uv);\n    float angle = atan(uv.y, uv.x);\n\n    // Spiral arm twist + slow rotation\n    float swirl = angle + r * 3.2 - u_time * u_rotSpeed;\n    vec2 spiralUv = vec2(cos(swirl), sin(swirl)) * r * 2.4;\n\n    float n1 = fbm(spiralUv + u_time * 0.08);\n    float n2 = fbm(spiralUv * 1.8 - u_time * 0.05 + n1);\n\n    float nebulaMask = smoothstep(0.95, 0.05, r) * (n1 * 0.65 + n2 * 0.55);\n    float coreGlow = exp(-r * 4.2);\n\n    vec3 col = mix(vec3(0.02, 0.02, 0.05), u_color2, nebulaMask);\n    col = mix(col, u_color1, clamp(n2 * nebulaMask * 1.4, 0.0, 1.0));\n    col += vec3(1.0, 0.96, 0.9) * coreGlow * 0.85;\n\n    gl_FragColor = vec4(col, 1.0);\n  }\n`;\n\nexport function GalaxyNebula({\n  speed = 1,\n  rotationSpeed = 0.25,\n  primaryColor = \"#8B5CF6\",\n  secondaryColor = \"#06B6D4\",\n  children,\n  className,\n}: GalaxyNebulaProps) {\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const [preset, setPreset] = useState<\"Andromeda\" | \"Orion\" | \"Supernova\">(\n    \"Andromeda\"\n  );\n\n  const palettes = {\n    Andromeda: { c1: primaryColor, c2: secondaryColor },\n    Orion: { c1: \"#EC4899\", c2: \"#6366F1\" },\n    Supernova: { c1: \"#F97316\", c2: \"#8B5CF6\" },\n  };\n\n  const activePalette = palettes[preset];\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    if (!canvas) return;\n    const gl = canvas.getContext(\"webgl\");\n    if (!gl) return;\n\n    const compile = (type: number, src: string) => {\n      const sh = gl.createShader(type);\n      if (!sh) return null;\n      gl.shaderSource(sh, src);\n      gl.compileShader(sh);\n      return sh;\n    };\n\n    const vs = compile(gl.VERTEX_SHADER, VERTEX_SHADER);\n    const fs = compile(gl.FRAGMENT_SHADER, FRAGMENT_SHADER);\n    if (!vs || !fs) return;\n\n    const prog = gl.createProgram();\n    if (!prog) return;\n    gl.attachShader(prog, vs);\n    gl.attachShader(prog, fs);\n    gl.linkProgram(prog);\n    gl.useProgram(prog);\n\n    const buf = gl.createBuffer();\n    gl.bindBuffer(gl.ARRAY_BUFFER, buf);\n    gl.bufferData(\n      gl.ARRAY_BUFFER,\n      new Float32Array([-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1]),\n      gl.STATIC_DRAW\n    );\n\n    const posLoc = gl.getAttribLocation(prog, \"position\");\n    gl.enableVertexAttribArray(posLoc);\n    gl.vertexAttribPointer(posLoc, 2, gl.FLOAT, false, 0, 0);\n\n    const uRes = gl.getUniformLocation(prog, \"u_resolution\");\n    const uTime = gl.getUniformLocation(prog, \"u_time\");\n    const uRot = gl.getUniformLocation(prog, \"u_rotSpeed\");\n    const uCol1 = gl.getUniformLocation(prog, \"u_color1\");\n    const uCol2 = gl.getUniformLocation(prog, \"u_color2\");\n\n    const rgb1 = hexToRgbNormalized(activePalette.c1);\n    const rgb2 = hexToRgbNormalized(activePalette.c2);\n\n    let rafId: number;\n    const start = performance.now();\n\n    const render = (now: number) => {\n      const w = (canvas.width = canvas.offsetWidth || 600);\n      const h = (canvas.height = canvas.offsetHeight || 360);\n      gl.viewport(0, 0, w, h);\n\n      gl.uniform2f(uRes, w, h);\n      gl.uniform1f(uTime, ((now - start) * 0.001) * speed);\n      gl.uniform1f(uRot, rotationSpeed);\n      gl.uniform3f(uCol1, rgb1[0], rgb1[1], rgb1[2]);\n      gl.uniform3f(uCol2, rgb2[0], rgb2[1], rgb2[2]);\n\n      gl.drawArrays(gl.TRIANGLES, 0, 6);\n      rafId = requestAnimationFrame(render);\n    };\n\n    rafId = requestAnimationFrame(render);\n    return () => cancelAnimationFrame(rafId);\n  }, [speed, rotationSpeed, activePalette.c1, activePalette.c2]);\n\n  return (\n    <div\n      data-fullscreen-scroll\n      className={cn(\n        \"relative flex min-h-[360px] w-full flex-col justify-between overflow-hidden rounded-3xl border border-neutral-800 bg-[#05050D] 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 flex-wrap items-center justify-between gap-2\">\n              <span className=\"inline-flex items-center gap-1.5 rounded-full border border-white/15 bg-black/40 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-violet-300\" />\n                WebGL FBM Nebula\n              </span>\n\n              <div className=\"flex items-center gap-1 rounded-full border border-white/15 bg-black/40 p-1 backdrop-blur-md\">\n                {([\"Andromeda\", \"Orion\", \"Supernova\"] as const).map((name) => (\n                  <button\n                    key={name}\n                    type=\"button\"\n                    onClick={() => setPreset(name)}\n                    className={cn(\n                      \"rounded-full px-2.5 py-0.5 font-mono text-[10px] font-semibold transition-colors\",\n                      preset === name\n                        ? \"bg-white text-black\"\n                        : \"text-white/75 hover:text-white\"\n                    )}\n                  >\n                    {name}\n                  </button>\n                ))}\n              </div>\n            </div>\n\n            <div className=\"my-auto max-w-md py-8\">\n              <h3 className=\"text-2xl font-bold tracking-tight text-white drop-shadow-sm sm:text-3xl\">\n                Spiral Galaxy & FBM Nebula\n              </h3>\n              <p className=\"mt-2 text-xs leading-relaxed text-white/80 sm:text-sm\">\n                Real-time WebGL fragment shader computing 5-octave Fractional\n                Brownian Motion (<code className=\"font-mono\">fbm</code>) with\n                polar spiral distortion.\n              </p>\n            </div>\n\n            <div className=\"font-mono text-[11px] text-white/55\">\n              GLSL Fragment Shader · 5-Octave FBM Noise · Spiral Swirl\n            </div>\n          </>\n        )}\n      </div>\n    </div>\n  );\n}\n\nexport default GalaxyNebula;\n",
      "type": "registry:ui",
      "target": "components/ui/galaxy-nebula.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"
    }
  ]
}
