{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "black-hole",
  "type": "registry:ui",
  "title": "Black Hole",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Interstellar-inspired gravitational lensing black hole background powered by a WebGL relativistic ray-marching shader with a pitch-black event horizon, incandescent photon ring, bent upper and lower lensing arcs, and Doppler-beamed accretion plasma.",
  "dependencies": [
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/black-hole.tsx",
      "content": "\"use client\";\n\nimport React, { useEffect, useRef, useState } from \"react\";\nimport { Orbit, Sparkles, Sliders, RotateCcw } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface BlackHoleProps {\n  /** Radius of the central event horizon void in pixels (default: 95) */\n  size?: number;\n  /** Primary color of the relativistic accretion disk (default: \"#FF7A18\") */\n  diskColor?: string;\n  /** Angular velocity multiplier for orbiting matter (default: 1.2) */\n  spinSpeed?: number;\n  /** Filament density / particle resolution in the accretion disk (default: 260) */\n  particleCount?: number;\n  /** Radial inward gravitational pull rate & spacetime curvature (default: 0.35) */\n  pull?: number;\n  /** Whether to enable full relativistic gravitational lensing ray bending (default: true) */\n  lensing?: boolean;\n  /** Optional overlay content rendered above the canvas */\n  children?: React.ReactNode;\n  /** Additional CSS classes for the root container */\n  className?: string;\n}\n\nfunction hexToNormalizedRgb(hex: string): [number, number, number] {\n  const cleaned = hex.replace(\"#\", \"\").trim();\n  const full =\n    cleaned.length === 3\n      ? cleaned\n          .split(\"\")\n          .map((c) => c + c)\n          .join(\"\")\n      : cleaned.padEnd(6, \"0\").slice(0, 6);\n  const num = parseInt(full, 16);\n  if (Number.isNaN(num)) return [1.0, 0.48, 0.09];\n  return [\n    ((num >> 16) & 255) / 255,\n    ((num >> 8) & 255) / 255,\n    (num & 255) / 255,\n  ];\n}\n\nconst VERTEX_SHADER = `\nattribute vec2 a_position;\nvoid main() {\n  gl_Position = vec4(a_position, 0.0, 1.0);\n}\n`;\n\nconst FRAGMENT_SHADER = `\nprecision highp float;\n\nuniform vec2 u_resolution;\nuniform float u_time;\nuniform float u_size;\nuniform vec3 u_diskColor;\nuniform float u_spinSpeed;\nuniform float u_density;\nuniform float u_pull;\nuniform float u_lensing;\nuniform vec2 u_pointer;\n\nfloat hash21(vec2 p) {\n  p = fract(p * vec2(234.34, 435.345));\n  p += dot(p, p + 34.23);\n  return fract(p.x * p.y);\n}\n\nfloat noise(vec2 p) {\n  vec2 i = floor(p);\n  vec2 f = fract(p);\n  vec2 u = f * f * (3.0 - 2.0 * f);\n  return mix(\n    mix(hash21(i), hash21(i + vec2(1.0, 0.0)), u.x),\n    mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), u.x),\n    u.y\n  );\n}\n\nfloat fbm(vec2 p) {\n  float v = 0.0;\n  float a = 0.5;\n  mat2 rot = mat2(0.8, -0.6, 0.6, 0.8);\n  for (int i = 0; i < 5; i++) {\n    v += a * noise(p);\n    p = rot * p * 2.02 + vec2(13.4, 7.1);\n    a *= 0.5;\n  }\n  return v;\n}\n\n// Starfield lookup on escaped ray direction\nvec3 sampleStarfield(vec3 dir, float time) {\n  vec2 uv = vec2(atan(dir.z, dir.x) * 1.5, dir.y * 3.0);\n  vec2 grid = floor(uv * 28.0);\n  vec2 f = fract(uv * 28.0) - 0.5;\n  float rnd = hash21(grid);\n  vec3 stars = vec3(0.0);\n\n  if (rnd > 0.72) {\n    vec2 offset = (vec2(hash21(grid + 1.3), hash21(grid + 7.9)) - 0.5) * 0.65;\n    float d = length(f - offset);\n    float twinkle = 0.7 + 0.3 * sin(time * (1.5 + rnd * 4.0) + rnd * 6.28);\n    float star = smoothstep(0.18 * (rnd - 0.65), 0.0, d) * twinkle;\n    float core = exp(-d * 38.0) * twinkle;\n    vec3 tint = mix(vec3(0.75, 0.88, 1.0), vec3(1.0, 0.9, 0.75), fract(rnd * 13.7));\n    stars += tint * (star * 0.65 + core * 1.25);\n  }\n\n  // Subtle deep cosmic dust nebula\n  float neb = fbm(uv * 1.6 + vec2(0.2, -0.1));\n  stars += u_diskColor * pow(max(0.0, neb - 0.35), 2.4) * 0.14;\n  return stars;\n}\n\nvoid main() {\n  float minDim = min(u_resolution.x, u_resolution.y);\n  vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / minDim;\n\n  // Map pixel size prop to normalized Schwarzschild horizon scale\n  float rScale = clamp(u_size / (minDim * 0.24), 0.45, 1.55);\n  uv /= rScale;\n\n  // Camera setup with subtle orbital tilt and roll (Interstellar Gargantua framing)\n  float rollAngle = -0.15 + u_pointer.x * 0.08;\n  float cRoll = cos(rollAngle);\n  float sRoll = sin(rollAngle);\n  uv = mat2(cRoll, -sRoll, sRoll, cRoll) * uv;\n\n  float camPitch = 0.145 + u_pointer.y * 0.06;\n  vec3 ro = vec3(0.0, sin(camPitch) * 6.2, -cos(camPitch) * 6.2);\n  vec3 forward = normalize(-ro);\n  vec3 right = normalize(cross(vec3(0.0, 1.0, 0.0), forward));\n  vec3 up = cross(forward, right);\n  vec3 rd = normalize(forward * 1.75 + right * uv.x + up * uv.y);\n\n  // Schwarzschild & Kerr relativistic ray marching parameters\n  float rs = 0.52; // Event horizon radius\n  float innerDisk = rs * 1.42; // ISCO (Innermost Stable Circular Orbit)\n  float outerDisk = rs * 6.8;\n  float gravStrength = mix(0.0, 0.195 * (0.75 + u_pull * 0.75), u_lensing);\n\n  vec3 pos = ro;\n  vec3 dir = rd;\n  vec3 accumGlow = vec3(0.0);\n  float transmittance = 1.0;\n  bool hitHorizon = false;\n  float minApproach = 100.0;\n\n  // Geodesic light-bending integration loop\n  for (int step = 0; step < 88; step++) {\n    float r = length(pos);\n    minApproach = min(minApproach, r);\n\n    if (r < rs) {\n      hitHorizon = true;\n      break;\n    }\n    if (r > 9.5 && step > 18) {\n      break;\n    }\n\n    // Adaptive step size: fine near photon sphere & equatorial plane, larger far away\n    float distPlane = abs(pos.y);\n    float dt = clamp(min(r - rs * 0.85, distPlane * 0.75 + 0.045) * 0.35, 0.025, 0.22);\n\n    // Gravitational deflection acceleration (-1.5 * rs * L^2 / r^5 approximation)\n    vec3 accel = -pos * (gravStrength / (r * r * r + 0.004));\n    vec3 nextDir = normalize(dir + accel * dt);\n    vec3 nextPos = pos + nextDir * dt;\n\n    // Check if ray crosses or grazes the equatorial accretion disk slab\n    float slabHalfHeight = 0.055 + 0.025 * smoothstep(innerDisk, outerDisk, r);\n    if (min(abs(pos.y), abs(nextPos.y)) < slabHalfHeight || pos.y * nextPos.y <= 0.0) {\n      float tCross = (pos.y * nextPos.y <= 0.0)\n        ? clamp(abs(pos.y) / (abs(pos.y - nextPos.y) + 0.0001), 0.0, 1.0)\n        : 0.5;\n      vec3 hitPos = mix(pos, nextPos, tCross);\n      float diskR = length(hitPos.xz);\n\n      if (diskR > innerDisk && diskR < outerDisk) {\n        float radialNorm = (diskR - innerDisk) / (outerDisk - innerDisk);\n        float radialProfile = smoothstep(0.0, 0.09, radialNorm) *\n                              pow(1.0 - radialNorm, 1.45);\n\n        // Relativistic differential Keplerian rotation (omega ~ r^-1.5)\n        float angle = atan(hitPos.z, hitPos.x);\n        float omega = u_spinSpeed * 1.65 / pow(diskR, 1.15);\n        float spiralPhase = angle + omega * u_time + (u_pull * 4.5) / (diskR + 0.15);\n\n        // Multi-octave spiraling plasma filaments + fine rings\n        float filamentScale = clamp(u_density / 260.0, 0.5, 2.0);\n        vec2 polarUv = vec2(diskR * 5.5 * filamentScale - u_time * u_pull * 0.8, spiralPhase * 2.0);\n        float n1 = fbm(polarUv);\n        float n2 = fbm(vec2(diskR * 14.0 * filamentScale, spiralPhase * 4.0 - n1 * 2.2));\n        float rings = 0.55 + 0.45 * sin(diskR * 36.0 * filamentScale + n1 * 5.0);\n        float plasmaDensity = radialProfile * mix(n1, n2, 0.55) * rings;\n\n        // Relativistic Doppler beaming & gravitational redshift\n        vec3 tangentVel = normalize(vec3(-hitPos.z, 0.0, hitPos.x));\n        float beta = clamp(0.52 * sqrt(rs / diskR) * clamp(u_spinSpeed, 0.2, 2.5), 0.0, 0.72);\n        float cosTheta = dot(nextDir, tangentVel);\n        float doppler = 1.0 / max(0.28, 1.0 - beta * cosTheta);\n        float beaming = pow(doppler, 2.65);\n\n        // Temperature color gradient: white-hot ISCO + Doppler blueshift vs crimson outer redshift\n        vec3 hotCore = vec3(1.0, 0.97, 0.90);\n        vec3 midTone = u_diskColor;\n        vec3 coolOuter = u_diskColor * vec3(0.65, 0.22, 0.08);\n\n        float tempFactor = clamp((1.0 - radialNorm * 0.75) * pow(doppler, 0.85), 0.0, 1.6);\n        vec3 localColor = mix(coolOuter, midTone, smoothstep(0.0, 0.65, tempFactor));\n        localColor = mix(localColor, hotCore, smoothstep(0.65, 1.35, tempFactor));\n\n        // Subtle blue-white shift on extreme approaching side\n        localColor = mix(localColor, vec3(0.82, 0.93, 1.0), smoothstep(1.3, 1.9, doppler) * 0.35);\n\n        float verticalFade = exp(-pow(hitPos.y / slabHalfHeight, 2.0) * 2.2);\n        float stepEmission = plasmaDensity * verticalFade * beaming * 1.15;\n\n        accumGlow += transmittance * localColor * stepEmission;\n        transmittance *= exp(-plasmaDensity * verticalFade * 0.65);\n      }\n    }\n\n    pos = nextPos;\n    dir = nextDir;\n  }\n\n  vec3 finalColor = vec3(0.0);\n\n  // Escaped rays sample the gravitationally lensed starfield\n  if (!hitHorizon) {\n    finalColor += transmittance * sampleStarfield(dir, u_time);\n  }\n\n  // Razor-sharp incandescent Photon Ring at the critical impact parameter\n  float photonRingDist = abs(minApproach - rs * 1.045);\n  float photonRing = exp(-photonRingDist * 46.0) * 1.35 + exp(-photonRingDist * 12.0) * 0.32;\n  vec3 photonColor = mix(u_diskColor, vec3(1.0, 0.96, 0.86), 0.72);\n  finalColor += photonColor * photonRing * (hitHorizon ? 0.45 : 1.0);\n\n  // Add accumulated volumetric accretion disk & lensed upper/lower arches\n  finalColor += accumGlow;\n\n  // Ambient relativistic corona bloom\n  float screenR = length(uv);\n  float ambientCorona = exp(-max(0.0, screenR - rs * 0.9) * 2.1) * 0.16;\n  finalColor += u_diskColor * ambientCorona;\n\n  // ACES-inspired filmic tone mapping & gamma correction\n  finalColor = (finalColor * (2.51 * finalColor + 0.03)) / (finalColor * (2.43 * finalColor + 0.59) + 0.14);\n  finalColor = pow(clamp(finalColor, 0.0, 1.0), vec3(0.92));\n\n  // Subtle dither to prevent 8-bit banding in deep space gradients\n  finalColor += (hash21(gl_FragCoord.xy + fract(u_time)) - 0.5) / 255.0;\n\n  gl_FragColor = vec4(finalColor, 1.0);\n}\n`;\n\nconst PRESETS = [\n  {\n    name: \"Gargantua\",\n    diskColor: \"#FF7A18\",\n    size: 95,\n    spinSpeed: 1.2,\n    pull: 0.35,\n    lensing: true,\n  },\n  {\n    name: \"Quasar Jet\",\n    diskColor: \"#38BDF8\",\n    size: 85,\n    spinSpeed: 1.85,\n    pull: 0.55,\n    lensing: true,\n  },\n  {\n    name: \"Crimson Singularity\",\n    diskColor: \"#F43F5E\",\n    size: 105,\n    spinSpeed: 0.9,\n    pull: 0.25,\n    lensing: true,\n  },\n] as const;\n\nexport function BlackHole({\n  size = 95,\n  diskColor = \"#FF7A18\",\n  spinSpeed = 1.2,\n  particleCount = 260,\n  pull = 0.35,\n  lensing = true,\n  children,\n  className,\n}: BlackHoleProps) {\n  const containerRef = useRef<HTMLDivElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n\n  const [activeSize, setActiveSize] = useState(size);\n  const [activeColor, setActiveColor] = useState(diskColor);\n  const [activeSpin, setActiveSpin] = useState(spinSpeed);\n  const [activePull, setActivePull] = useState(pull);\n  const [activeLensing, setActiveLensing] = useState(lensing);\n  const pointerRef = useRef<{ x: number; y: number; tx: number; ty: number }>({\n    x: 0,\n    y: 0,\n    tx: 0,\n    ty: 0,\n  });\n\n  useEffect(() => {\n    setActiveSize(size);\n  }, [size]);\n  useEffect(() => {\n    setActiveColor(diskColor);\n  }, [diskColor]);\n  useEffect(() => {\n    setActiveSpin(spinSpeed);\n  }, [spinSpeed]);\n  useEffect(() => {\n    setActivePull(pull);\n  }, [pull]);\n  useEffect(() => {\n    setActiveLensing(lensing);\n  }, [lensing]);\n\n  const paramsRef = useRef({\n    size: activeSize,\n    color: hexToNormalizedRgb(activeColor),\n    spinSpeed: activeSpin,\n    particleCount,\n    pull: activePull,\n    lensing: activeLensing ? 1.0 : 0.0,\n  });\n\n  useEffect(() => {\n    paramsRef.current = {\n      size: activeSize,\n      color: hexToNormalizedRgb(activeColor),\n      spinSpeed: activeSpin,\n      particleCount,\n      pull: activePull,\n      lensing: activeLensing ? 1.0 : 0.0,\n    };\n  }, [activeSize, activeColor, activeSpin, particleCount, activePull, activeLensing]);\n\n  useEffect(() => {\n    const container = containerRef.current;\n    const canvas = canvasRef.current;\n    if (!container || !canvas) return;\n\n    const gl = canvas.getContext(\"webgl\", {\n      alpha: false,\n      antialias: false,\n      preserveDrawingBuffer: false,\n    });\n    if (!gl) return;\n\n    const compileShader = (type: number, source: string) => {\n      const shader = gl.createShader(type);\n      if (!shader) return null;\n      gl.shaderSource(shader, source);\n      gl.compileShader(shader);\n      if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n        gl.deleteShader(shader);\n        return null;\n      }\n      return shader;\n    };\n\n    const vs = compileShader(gl.VERTEX_SHADER, VERTEX_SHADER);\n    const fs = compileShader(gl.FRAGMENT_SHADER, FRAGMENT_SHADER);\n    if (!vs || !fs) return;\n\n    const program = gl.createProgram();\n    if (!program) return;\n    gl.attachShader(program, vs);\n    gl.attachShader(program, fs);\n    gl.linkProgram(program);\n\n    if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n      gl.deleteProgram(program);\n      return;\n    }\n\n    gl.useProgram(program);\n\n    const buffer = gl.createBuffer();\n    gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\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(program, \"a_position\");\n    gl.enableVertexAttribArray(posLoc);\n    gl.vertexAttribPointer(posLoc, 2, gl.FLOAT, false, 0, 0);\n\n    const uResolution = gl.getUniformLocation(program, \"u_resolution\");\n    const uTime = gl.getUniformLocation(program, \"u_time\");\n    const uSize = gl.getUniformLocation(program, \"u_size\");\n    const uDiskColor = gl.getUniformLocation(program, \"u_diskColor\");\n    const uSpinSpeed = gl.getUniformLocation(program, \"u_spinSpeed\");\n    const uDensity = gl.getUniformLocation(program, \"u_density\");\n    const uPull = gl.getUniformLocation(program, \"u_pull\");\n    const uLensing = gl.getUniformLocation(program, \"u_lensing\");\n    const uPointer = gl.getUniformLocation(program, \"u_pointer\");\n\n    let dpr = Math.min(window.devicePixelRatio || 1, 1.75);\n    const resizeCanvas = () => {\n      if (!container || !canvas) return;\n      dpr = Math.min(window.devicePixelRatio || 1, 1.75);\n      const w = Math.max(1, Math.floor((container.clientWidth || 800) * dpr));\n      const h = Math.max(1, Math.floor((container.clientHeight || 520) * dpr));\n      canvas.width = w;\n      canvas.height = h;\n      gl.viewport(0, 0, w, h);\n    };\n\n    resizeCanvas();\n    const observer = new ResizeObserver(resizeCanvas);\n    observer.observe(container);\n\n    let rafId = 0;\n    let accumTime = 0;\n    let lastNow = performance.now();\n\n    const render = (now: number) => {\n      const dt = Math.min(0.1, (now - lastNow) * 0.001);\n      lastNow = now;\n      accumTime += dt;\n\n      const p = paramsRef.current;\n      const ptr = pointerRef.current;\n      ptr.x += (ptr.tx - ptr.x) * 0.06;\n      ptr.y += (ptr.ty - ptr.y) * 0.06;\n\n      gl.uniform2f(uResolution, canvas.width, canvas.height);\n      gl.uniform1f(uTime, accumTime);\n      gl.uniform1f(uSize, p.size * dpr);\n      gl.uniform3f(uDiskColor, p.color[0], p.color[1], p.color[2]);\n      gl.uniform1f(uSpinSpeed, p.spinSpeed);\n      gl.uniform1f(uDensity, p.particleCount);\n      gl.uniform1f(uPull, p.pull);\n      gl.uniform1f(uLensing, p.lensing);\n      gl.uniform2f(uPointer, ptr.x, ptr.y);\n\n      gl.drawArrays(gl.TRIANGLES, 0, 6);\n      rafId = requestAnimationFrame(render);\n    };\n\n    rafId = requestAnimationFrame(render);\n\n    return () => {\n      cancelAnimationFrame(rafId);\n      observer.disconnect();\n      gl.deleteBuffer(buffer);\n      gl.deleteProgram(program);\n      gl.deleteShader(vs);\n      gl.deleteShader(fs);\n    };\n  }, []);\n\n  const handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n    if (!containerRef.current) return;\n    const rect = containerRef.current.getBoundingClientRect();\n    pointerRef.current.tx = ((e.clientX - rect.left) / rect.width - 0.5) * 2;\n    pointerRef.current.ty = ((e.clientY - rect.top) / rect.height - 0.5) * 2;\n  };\n\n  const handlePointerLeave = () => {\n    pointerRef.current.tx = 0;\n    pointerRef.current.ty = 0;\n  };\n\n  return (\n    <div\n      ref={containerRef}\n      data-fullscreen-scroll\n      onPointerMove={handlePointerMove}\n      onPointerLeave={handlePointerLeave}\n      className={cn(\n        \"relative w-full min-h-[520px] overflow-hidden rounded-2xl bg-[#020308] text-white select-none\",\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      {/* Subtle radial vignette */}\n      <div\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0 bg-[radial-gradient(circle_at_center,transparent_48%,rgba(2,3,8,0.72)_100%)]\"\n      />\n\n      {children && (\n        <div className=\"relative z-10 flex min-h-[520px] w-full flex-col\">\n          {children}\n        </div>\n      )}\n    </div>\n  );\n}\n\nexport default BlackHole;\n",
      "type": "registry:ui",
      "target": "components/ui/black-hole.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"
    }
  ]
}
