{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "plasma-cloud",
  "title": "Plasma Cloud",
  "description": "A glowing plasma cloud shader that folds in on itself like coloured smoke, built from layered domain-warped noise; the pointer stirs a slow swirl into it, and anything you place inside sits on top.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/plasma-cloud/plasma-cloud.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface PlasmaCloudProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"children\"> {\n  /** Content shown on top of the background. */\n  children?: React.ReactNode;\n  /** Plasma colours: main body, deep folds, warm streaks and the hot highlights. */\n  colors?: [string, string, string, string];\n  /** Base colour behind the effect. */\n  background?: string;\n  /** Animation speed multiplier. */\n  speed?: number;\n  /** Overall brightness of the effect. */\n  intensity?: number;\n  /** The pointer stirs the plasma into a slow swirl around it. */\n  interactive?: boolean;\n  /** Render scale: 1 is full resolution, lower values are cheaper on very large screens. */\n  resolution?: number;\n  /** Freeze the animation on its current frame. */\n  paused?: boolean;\n}\n\nconst DEFAULT_COLORS: [string, string, string, string] = [\"#ff3d7f\", \"#3a1cff\", \"#ff9a3d\", \"#ffe3f2\"];\nconst DEFAULT_BACKGROUND = \"#07030f\";\n\nconst VERTEX = `attribute vec2 aPos;\nvoid main() { gl_Position = vec4(aPos, 0.0, 1.0); }`;\n\nconst FRAGMENT = `#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nuniform vec2 uRes;\nuniform float uTime;\nuniform vec2 uMouse;\nuniform float uHover;\nuniform float uIntensity;\nuniform vec3 uBg;\nuniform vec3 uC0;\nuniform vec3 uC1;\nuniform vec3 uC2;\nuniform vec3 uC3;\n\nfloat 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}\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(mix(hash(i), hash(i + vec2(1.0, 0.0)), u.x), mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x), u.y);\n}\nfloat fbm(vec2 p) {\n  float v = 0.0;\n  float a = 0.5;\n  for (int i = 0; i < 5; i++) {\n    v += a * noise(p);\n    p = p * 2.03 + vec2(1.7, 9.2);\n    a *= 0.5;\n  }\n  return v;\n}\nvoid main() {\n  float ar = uRes.x / uRes.y;\n  vec2 p = (gl_FragCoord.xy - 0.5 * uRes) / uRes.y * 1.7;\n  vec2 m = (uMouse - 0.5) * vec2(ar, 1.0) * 1.7;\n  float t = uTime * 0.11;\n\n  // Stir: rotate space around the pointer, most strongly close to it.\n  vec2 dm = p - m;\n  float swirl = exp(-dot(dm, dm) * 2.2) * uHover * 1.6;\n  float cs = cos(swirl);\n  float sn = sin(swirl);\n  p = m + mat2(cs, -sn, sn, cs) * dm;\n\n  // Domain warping: noise feeding noise, which is what makes it fold like smoke.\n  vec2 q = vec2(fbm(p + vec2(0.0, t)), fbm(p + vec2(5.2, 1.3) - t));\n  vec2 r = vec2(fbm(p + 3.8 * q + vec2(1.7, 9.2) + t * 1.4), fbm(p + 3.8 * q + vec2(8.3, 2.8) - t * 1.1));\n  float f = fbm(p + 3.8 * r);\n\n  vec3 col = mix(uBg, uC0, clamp(f * f * 2.4, 0.0, 1.0));\n  col = mix(col, uC1, clamp(length(q) * 0.85 - 0.15, 0.0, 1.0));\n  col = mix(col, uC2, clamp(r.x * r.x * 1.3, 0.0, 1.0) * 0.75);\n  col += uC3 * pow(f, 4.0) * 1.5;\n  col *= (0.55 + 0.7 * f) * uIntensity;\n  col *= 1.0 - 0.35 * dot(p * 0.32, p * 0.32);\n  gl_FragColor = vec4(col, 1.0);\n}`;\n\nconst UNIFORMS = [\"uRes\", \"uTime\", \"uMouse\", \"uHover\", \"uIntensity\", \"uBg\", \"uC0\", \"uC1\", \"uC2\", \"uC3\"] as const;\n\nfunction rgb(hex: string): [number, number, number] {\n  const h = hex.replace(\"#\", \"\");\n  const full =\n    h.length === 3\n      ? h\n          .split(\"\")\n          .map((c) => c + c)\n          .join(\"\")\n      : h.slice(0, 6);\n  const n = parseInt(full, 16) || 0;\n  return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];\n}\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nfunction compile(gl: WebGLRenderingContext, 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    console.warn(\"PlasmaCloud shader:\", gl.getShaderInfoLog(shader));\n    gl.deleteShader(shader);\n    return null;\n  }\n  return shader;\n}\n\nexport function PlasmaCloud({\n  children,\n  colors = DEFAULT_COLORS,\n  background = DEFAULT_BACKGROUND,\n  speed = 1,\n  intensity = 1,\n  interactive = true,\n  resolution = 1,\n  paused = false,\n  className,\n  style,\n  onPointerMove,\n  onPointerEnter,\n  onPointerLeave,\n  onPointerDown,\n  onPointerUp,\n  ...props\n}: PlasmaCloudProps) {\n  const reduce = useReducedMotion();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const [failed, setFailed] = React.useState(false);\n  // The render loop reads the latest props from here, so changing a prop never rebuilds WebGL.\n  const live = React.useRef({ colors, background, speed, intensity, interactive, resolution, still: paused || reduce });\n  const kick = React.useRef<() => void>(() => {});\n  // Pointer state in 0..1 (y up, like gl_FragCoord), eased toward its target every frame.\n  const input = React.useRef({ x: 0.5, y: 0.5, tx: 0.5, ty: 0.5, hover: 0, thover: 0, down: false, clickX: 0.5, clickY: 0.5, clicks: 0 });\n\n  React.useEffect(() => {\n    live.current = { colors, background, speed, intensity, interactive, resolution, still: paused || reduce };\n    kick.current();\n  }, [colors, background, speed, intensity, interactive, resolution, paused, reduce]);\n\n  React.useEffect(() => {\n    const canvas = canvasRef.current;\n    const root = rootRef.current;\n    if (!canvas || !root) return;\n    const gl = canvas.getContext(\"webgl\", { antialias: false, alpha: false, preserveDrawingBuffer: true, powerPreference: \"low-power\" });\n    const fail = () => requestAnimationFrame(() => setFailed(true));\n    if (!gl) {\n      fail();\n      return;\n    }\n    const vs = compile(gl, gl.VERTEX_SHADER, VERTEX);\n    const fs = compile(gl, gl.FRAGMENT_SHADER, FRAGMENT);\n    const program = gl.createProgram();\n    if (!vs || !fs || !program) {\n      fail();\n      return;\n    }\n    gl.attachShader(program, vs);\n    gl.attachShader(program, fs);\n    gl.linkProgram(program);\n    if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n      fail();\n      return;\n    }\n    gl.useProgram(program);\n    const buffer = gl.createBuffer();\n    gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);\n    const aPos = gl.getAttribLocation(program, \"aPos\");\n    gl.enableVertexAttribArray(aPos);\n    gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);\n    const u = Object.fromEntries(UNIFORMS.map((name) => [name, gl.getUniformLocation(program, name)])) as Record<(typeof UNIFORMS)[number], WebGLUniformLocation | null>;\n\n    const state = { time: 5, last: 0 };\n    let raf = 0;\n    let visible = true;\n\n    const resize = () => {\n      const dpr = Math.min(window.devicePixelRatio || 1, 1.5) * Math.max(0.25, Math.min(1, live.current.resolution));\n      const w = Math.max(1, Math.round(root.clientWidth * dpr));\n      const h = Math.max(1, Math.round(root.clientHeight * dpr));\n      if (canvas.width !== w || canvas.height !== h) {\n        canvas.width = w;\n        canvas.height = h;\n        gl.viewport(0, 0, w, h);\n      }\n    };\n\n    const draw = (dt: number) => {\n      const L = live.current;\n      const inp = input.current;\n      const ease = 1 - Math.exp(-dt * 5);\n      inp.x += (inp.tx - inp.x) * ease;\n      inp.y += (inp.ty - inp.y) * ease;\n      inp.hover += ((L.interactive ? inp.thover : 0) - inp.hover) * (1 - Math.exp(-dt * 3));\n      const step = L.still ? 0 : dt * L.speed;\n      state.time += step;\n\n      const [c0, c1, c2, c3] = L.colors;\n      gl.uniform2f(u.uRes, canvas.width, canvas.height);\n      gl.uniform1f(u.uTime, state.time);\n      gl.uniform2f(u.uMouse, inp.x, inp.y);\n      gl.uniform1f(u.uHover, inp.hover);\n      gl.uniform1f(u.uIntensity, L.intensity);\n      gl.uniform3fv(u.uBg, rgb(L.background));\n      gl.uniform3fv(u.uC0, rgb(c0));\n      gl.uniform3fv(u.uC1, rgb(c1));\n      gl.uniform3fv(u.uC2, rgb(c2));\n      gl.uniform3fv(u.uC3, rgb(c3));\n      gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);\n    };\n\n    const frame = (now: number) => {\n      const dt = Math.min(0.05, state.last ? (now - state.last) / 1000 : 1 / 60);\n      state.last = now;\n      resize();\n      draw(dt);\n      // Keep running while visible and moving; a still background draws once and waits for a kick.\n      if (visible && !document.hidden && !live.current.still) raf = requestAnimationFrame(frame);\n      else state.last = 0;\n    };\n    const start = () => {\n      cancelAnimationFrame(raf);\n      raf = requestAnimationFrame(frame);\n    };\n    kick.current = start;\n\n    const ro = new ResizeObserver(start);\n    ro.observe(root);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) start();\n    });\n    io.observe(root);\n    const onVisibility = () => !document.hidden && start();\n    document.addEventListener(\"visibilitychange\", onVisibility);\n    const onLost = (event: Event) => {\n      event.preventDefault();\n      setFailed(true);\n    };\n    canvas.addEventListener(\"webglcontextlost\", onLost);\n    start();\n\n    return () => {\n      cancelAnimationFrame(raf);\n      kick.current = () => {};\n      ro.disconnect();\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", onVisibility);\n      canvas.removeEventListener(\"webglcontextlost\", onLost);\n      gl.deleteBuffer(buffer);\n      gl.deleteProgram(program);\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n    };\n  }, []);\n\n  const point = (event: React.PointerEvent<HTMLDivElement>) => {\n    const r = event.currentTarget.getBoundingClientRect();\n    const inp = input.current;\n    inp.tx = (event.clientX - r.left) / Math.max(1, r.width);\n    inp.ty = 1 - (event.clientY - r.top) / Math.max(1, r.height);\n  };\n\n  return (\n    <div\n      ref={rootRef}\n      className={cn(\"relative isolate overflow-hidden\", className)}\n      style={{ background, ...style }}\n      onPointerMove={(event) => {\n        point(event);\n        onPointerMove?.(event);\n      }}\n      onPointerEnter={(event) => {\n        point(event);\n        input.current.thover = 1;\n        onPointerEnter?.(event);\n      }}\n      onPointerLeave={(event) => {\n        input.current.thover = 0;\n        input.current.down = false;\n        onPointerLeave?.(event);\n      }}\n      onPointerDown={(event) => {\n        point(event);\n        const inp = input.current;\n        inp.down = true;\n        inp.clickX = inp.tx;\n        inp.clickY = inp.ty;\n        inp.clicks += 1;\n        onPointerDown?.(event);\n      }}\n      onPointerUp={(event) => {\n        input.current.down = false;\n        onPointerUp?.(event);\n      }}\n      {...props}\n    >\n      <canvas ref={canvasRef} aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 -z-10 h-full w-full\" />\n      {failed && (\n        <div\n          aria-hidden=\"true\"\n          className=\"absolute inset-0 -z-10\"\n          style={{ background: `radial-gradient(120% 90% at 50% 0%, ${colors[1]}55, transparent 60%), radial-gradient(90% 70% at 50% 100%, ${colors[0]}33, transparent 70%), ${background}` }}\n        />\n      )}\n      {children}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}