{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "solar-flare",
  "type": "registry:ui",
  "title": "Solar Flare",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Churning solar photosphere and coronal flare background powered by a custom WebGL fragment shader with domain-warped FBM plasma convection cells, magnetic sunspots, and glowing coronal prominences.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/solar-flare.tsx",
      "content": "\"use client\";\n\nimport React, { useEffect, useRef, useState } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface SolarFlareProps {\n  /** Incandescent core plasma color in hex (default: \"#FFF7CC\") */\n  coreColor?: string;\n  /** Primary coronal flare and chromosphere color in hex (default: \"#FF5500\") */\n  flareColor?: string;\n  /** Domain-warping FBM turbulence intensity (default: 1.0) */\n  turbulence?: number;\n  /** Plasma convection and flare animation speed multiplier (default: 1.0) */\n  speed?: number;\n  /** Intensity of coronal mass ejections and magnetic limb loops (default: 1.0) */\n  eruptionIntensity?: number;\n  /** Optional foreground content rendered over the solar surface */\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.33, 0.0];\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 vec3 u_coreColor;\nuniform vec3 u_flareColor;\nuniform float u_turbulence;\nuniform float u_eruption;\n\nfloat hash21(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\nvec2 hash22(vec2 p) {\n  vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));\n  p3 += dot(p3, p3.yzx + 33.33);\n  return fract((p3.xx + p3.yz) * p3.zy);\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  float a = hash21(i);\n  float b = hash21(i + vec2(1.0, 0.0));\n  float c = hash21(i + vec2(0.0, 1.0));\n  float d = hash21(i + vec2(1.0, 1.0));\n  return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);\n}\n\nfloat fbm(vec2 p) {\n  float value = 0.0;\n  float amp = 0.5;\n  mat2 rot = mat2(0.8, -0.6, 0.6, 0.8);\n  for (int i = 0; i < 5; i++) {\n    value += amp * noise(p);\n    p = rot * p * 2.03 + vec2(1.7, 9.2);\n    amp *= 0.5;\n  }\n  return value;\n}\n\n// Voronoi cellular distance for realistic solar photosphere granulation\nvec2 voronoiGranules(vec2 x, float time) {\n  vec2 n = floor(x);\n  vec2 f = fract(x);\n  float d1 = 8.0;\n  float d2 = 8.0;\n  for (int j = -1; j <= 1; j++) {\n    for (int i = -1; i <= 1; i++) {\n      vec2 g = vec2(float(i), float(j));\n      vec2 o = hash22(n + g);\n      o = 0.5 + 0.42 * sin(time * 0.85 + 6.2831 * o);\n      vec2 r = g + o - f;\n      float d = dot(r, r);\n      if (d < d1) {\n        d2 = d1;\n        d1 = d;\n      } else if (d < d2) {\n        d2 = d;\n      }\n    }\n  }\n  return vec2(sqrt(d1), sqrt(d2));\n}\n\n// Compute a realistic sunspot with dark umbra, radial penumbra fibrils, and bright surrounding faculae\nvec3 evaluateSunspot(vec2 sphereUv, vec2 spotCenter, float radius, float time) {\n  vec2 delta = sphereUv - spotCenter;\n  float dist = length(delta);\n  float angle = atan(delta.y, delta.x);\n  // Irregular warped boundary\n  float warp = (noise(vec2(angle * 3.0, time * 0.15)) - 0.5) * radius * 0.28;\n  float r = dist + warp;\n\n  // Inner dark magnetic umbra\n  float umbra = 1.0 - smoothstep(radius * 0.28, radius * 0.52, r);\n  // Radial penumbra filaments surrounding umbra\n  float fibrils = 0.5 + 0.5 * sin(angle * 28.0 + noise(delta * 18.0) * 4.5);\n  float penumbraMask = smoothstep(radius * 0.35, radius * 0.55, r) *\n                       (1.0 - smoothstep(radius * 0.65, radius * 1.15, r));\n  float penumbra = penumbraMask * (0.45 + 0.45 * fibrils);\n\n  // Bright magnetic plage / faculae ring outside penumbra\n  float faculae = smoothstep(radius * 0.85, radius * 1.25, r) *\n                  (1.0 - smoothstep(radius * 1.25, radius * 2.1, r)) *\n                  fbm(sphereUv * 6.0);\n\n  return vec3(umbra, penumbra, faculae);\n}\n\nvoid main() {\n  vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / min(u_resolution.x, u_resolution.y);\n\n  // Position solar sphere slightly below center for dramatic coronal prominence headroom\n  vec2 center = vec2(0.0, -0.05);\n  vec2 p = uv - center;\n  float r = length(p);\n  float sunRadius = 0.37;\n  float angle = atan(p.y, p.x);\n\n  vec3 col = vec3(0.008, 0.009, 0.018);\n\n  if (r < sunRadius) {\n    // 3D Spherical normal projection of the solar photosphere\n    float z = sqrt(max(0.0, sunRadius * sunRadius - r * r));\n    vec3 normal = normalize(vec3(p.x, p.y, z));\n\n    // Spherical latitude-longitude coordinates with differential solar rotation\n    float lon = atan(normal.x, normal.z) + u_time * 0.095;\n    float lat = asin(clamp(normal.y, -1.0, 1.0));\n    vec2 sphereUv = vec2(lon, lat) * 3.2;\n\n    // 1. Domain-Warped FBM + Voronoi Cellular Solar Granulation\n    vec2 q = vec2(\n      fbm(sphereUv + vec2(0.0, u_time * 0.2)),\n      fbm(sphereUv + vec2(5.2, 1.3 - u_time * 0.16))\n    );\n    vec2 warpedUv = sphereUv + 1.35 * u_turbulence * (q - 0.5);\n\n    vec2 vor = voronoiGranules(warpedUv * 4.2, u_time);\n    // Bright convex granule centers separated by darker intergranular convection lanes\n    float granuleCell = smoothstep(0.0, 0.22, vor.y - vor.x);\n    float plasmaFbm = fbm(warpedUv * 2.4 + vec2(u_time * 0.12, -u_time * 0.08));\n    float convection = mix(granuleCell, plasmaFbm, 0.52);\n\n    // 2. Active Region Magnetic Sunspots (Umbra + Radial Penumbra Fibrils + Bright Faculae)\n    vec3 spot1 = evaluateSunspot(warpedUv, vec2(0.45 + u_time * 0.095, 0.28), 0.42, u_time);\n    vec3 spot2 = evaluateSunspot(warpedUv, vec2(-0.85 + u_time * 0.095, -0.35), 0.32, u_time);\n    vec3 spot3 = evaluateSunspot(warpedUv, vec2(1.65 + u_time * 0.095, -0.18), 0.36, u_time);\n\n    float totalUmbra = clamp(spot1.x + spot2.x + spot3.x, 0.0, 1.0);\n    float totalPenumbra = clamp(spot1.y + spot2.y + spot3.y, 0.0, 1.0);\n    float totalFaculae = clamp(spot1.z + spot2.z + spot3.z, 0.0, 1.0);\n\n    // 3. Physical Eddington Spherical Limb Darkening & Chromospheric Rim Spicules\n    float mu = clamp(normal.z, 0.0, 1.0);\n    float limbDarkening = 0.32 + 0.68 * pow(mu, 0.48);\n    float limbRimBoost = pow(1.0 - mu, 2.75);\n\n    // Photosphere temperature color ramp\n    vec3 deepChromosphere = u_flareColor * 0.22;\n    vec3 midPhotosphere = u_flareColor * 1.05;\n    vec3 brightGranule = u_coreColor * 1.25;\n\n    vec3 surfaceCol = mix(deepChromosphere, midPhotosphere, smoothstep(0.12, 0.58, convection));\n    surfaceCol = mix(surfaceCol, brightGranule, smoothstep(0.55, 0.92, convection * limbDarkening));\n\n    // Apply physical limb darkening across the disc\n    surfaceCol *= limbDarkening;\n\n    // Brighten magnetic faculae networks (especially visible near the solar limb)\n    float faculaeBoost = totalFaculae * (0.65 + 1.15 * (1.0 - mu));\n    surfaceCol += u_coreColor * faculaeBoost * 0.85;\n\n    // Darken radial penumbra filaments & deep magnetic umbra cores\n    surfaceCol = mix(surfaceCol, u_flareColor * 0.32, totalPenumbra * 0.72);\n    surfaceCol = mix(surfaceCol, vec3(0.03, 0.01, 0.005), totalUmbra * 0.92);\n\n    // Incandescent chromospheric spicules & magnetic filaments right along the limb edge\n    float spiculeNoise = fbm(vec2(angle * 24.0, u_time * 0.45));\n    surfaceCol += mix(u_flareColor, u_coreColor, 0.65) * limbRimBoost * (0.45 + 0.55 * spiculeNoise);\n\n    col = surfaceCol;\n  } else {\n    // 4. Exterior Coronal Magnetic Loops, Arched Prominences & Solar Wind Streamers\n    float distFromLimb = r - sunRadius;\n\n    // Arched magnetic flux loop geometry around the solar limb\n    float loopFreq = angle * 5.0 + sin(distFromLimb * 18.0 - u_time * 0.9) * 0.45;\n    float archEnvelope = pow(max(0.0, sin(loopFreq)), 3.0) * exp(-distFromLimb * 11.5);\n    // Hollow magnetic arch core (bright along the loop arch, darker inside the arch)\n    float archRing = exp(-pow((distFromLimb - 0.038 * (0.6 + 0.4 * sin(angle * 3.0 + u_time * 0.3))) * 28.0, 2.0));\n    float magneticLoop = archEnvelope * (0.45 + 0.95 * archRing);\n\n    // Turbulent plasma eruptions & coronal mass ejection plumes\n    vec2 coronaCoord = vec2(angle * 3.8, distFromLimb * 8.5 - u_time * 0.62);\n    float loopNoise = fbm(coronaCoord * u_turbulence);\n    float loopArch = fbm(vec2(angle * 7.5 + sin(distFromLimb * 15.0), distFromLimb * 5.8 - u_time * 0.42));\n\n    float prominence = (pow(max(0.0, loopNoise * loopArch * 1.72), 1.75) + magneticLoop * loopNoise * 1.4) * u_eruption;\n    float falloff = exp(-distFromLimb * 6.8);\n    float innerChromosphereRim = exp(-distFromLimb * 38.0);\n\n    // Fine radial coronal helmet streamers extending into deep space\n    float streamerNoise = fbm(vec2(angle * 16.0, distFromLimb * 1.8 - u_time * 0.2));\n    float rays = pow(streamerNoise, 0.6) * exp(-distFromLimb * 3.6) * 0.55 * u_eruption;\n\n    vec3 coronaGlow = u_flareColor * (falloff * 0.88 + prominence * falloff * 2.85 + rays);\n    coronaGlow += u_coreColor * (innerChromosphereRim * 1.15 + prominence * exp(-distFromLimb * 13.0) * 1.45);\n\n    col += coronaGlow;\n  }\n\n  // HDR ACES-inspired filmic tone mapping & anti-banding dither\n  col = (col * (2.1 * col + 0.03)) / (col * (2.3 * col + 0.29) + 0.04);\n  col = pow(clamp(col, 0.0, 1.0), vec3(0.92));\n  col += (hash21(gl_FragCoord.xy + fract(u_time)) - 0.5) / 255.0;\n\n  gl_FragColor = vec4(col, 1.0);\n}\n`;\n\n\n\nexport function SolarFlare({\n  coreColor = \"#FFF7CC\",\n  flareColor = \"#FF5500\",\n  turbulence = 1.0,\n  speed = 1.0,\n  eruptionIntensity = 1.0,\n  children,\n  className,\n}: SolarFlareProps) {\n  const containerRef = useRef<HTMLDivElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n\n  const [activeCore, setActiveCore] = useState(coreColor);\n  const [activeFlare, setActiveFlare] = useState(flareColor);\n  const [activeTurb, setActiveTurb] = useState(turbulence);\n  const [activeSpeed, setActiveSpeed] = useState(speed);\n  const [activeEruption, setActiveEruption] = useState(eruptionIntensity);\n  useEffect(() => {\n    setActiveCore(coreColor);\n  }, [coreColor]);\n  useEffect(() => {\n    setActiveFlare(flareColor);\n  }, [flareColor]);\n  useEffect(() => {\n    setActiveTurb(turbulence);\n  }, [turbulence]);\n  useEffect(() => {\n    setActiveSpeed(speed);\n  }, [speed]);\n  useEffect(() => {\n    setActiveEruption(eruptionIntensity);\n  }, [eruptionIntensity]);\n\n  const paramsRef = useRef({\n    core: hexToNormalizedRgb(activeCore),\n    flare: hexToNormalizedRgb(activeFlare),\n    turbulence: activeTurb,\n    speed: activeSpeed,\n    eruption: activeEruption,\n  });\n\n  useEffect(() => {\n    paramsRef.current = {\n      core: hexToNormalizedRgb(activeCore),\n      flare: hexToNormalizedRgb(activeFlare),\n      turbulence: activeTurb,\n      speed: activeSpeed,\n      eruption: activeEruption,\n    };\n  }, [activeCore, activeFlare, activeTurb, activeSpeed, activeEruption]);\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\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 uCoreColor = gl.getUniformLocation(program, \"u_coreColor\");\n    const uFlareColor = gl.getUniformLocation(program, \"u_flareColor\");\n    const uTurbulence = gl.getUniformLocation(program, \"u_turbulence\");\n    const uEruption = gl.getUniformLocation(program, \"u_eruption\");\n\n    const resize = () => {\n      if (!container || !canvas) return;\n      const 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    resize();\n    const observer = new ResizeObserver(resize);\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      const p = paramsRef.current;\n      accumTime += dt * p.speed;\n\n      gl.uniform2f(uResolution, canvas.width, canvas.height);\n      gl.uniform1f(uTime, accumTime);\n      gl.uniform3f(uCoreColor, p.core[0], p.core[1], p.core[2]);\n      gl.uniform3f(uFlareColor, p.flare[0], p.flare[1], p.flare[2]);\n      gl.uniform1f(uTurbulence, p.turbulence);\n      gl.uniform1f(uEruption, p.eruption);\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  return (\n    <div\n      ref={containerRef}\n      data-fullscreen-scroll\n      className={cn(\n        \"relative w-full min-h-[520px] overflow-hidden rounded-2xl bg-[#040308] 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      {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 SolarFlare;\n",
      "type": "registry:ui",
      "target": "components/ui/solar-flare.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"
    }
  ]
}
