{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"smoke-column","type":"registry:ui","title":"Smoke Column","description":"A tall column of light filled with slowly swirling volumetric smoke. WebGL.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/smoke-column.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nexport interface SmokeColumnProps {\n  topColor?: string;\n  bottomColor?: string;\n  /** Pillar width as a fraction of the container height. */\n  width?: number;\n  intensity?: number;\n  /** Animation speed multiplier. */\n  speed?: number;\n  /** How strongly the inner smoke swirls around the axis. */\n  twist?: number;\n  /** Rotation of the pillar in degrees. */\n  angle?: number;\n  className?: string;\n}\n\nconst FRAG = `precision highp float;\nuniform vec2 uRes;\nuniform float uTime;\nuniform vec3 uTop;\nuniform vec3 uBottom;\nuniform float uWidth;\nuniform float uIntensity;\nuniform float uTwist;\nuniform float uAngle;\n\nfloat h3(vec3 p){ p = fract(p * 0.3183099 + 0.1); p *= 17.0; return fract(p.x * p.y * p.z * (p.x + p.y + p.z)); }\nfloat n3(vec3 x){\n  vec3 i = floor(x), f = fract(x);\n  f = f * f * (3.0 - 2.0 * f);\n  return mix(\n    mix(mix(h3(i), h3(i + vec3(1, 0, 0)), f.x), mix(h3(i + vec3(0, 1, 0)), h3(i + vec3(1, 1, 0)), f.x), f.y),\n    mix(mix(h3(i + vec3(0, 0, 1)), h3(i + vec3(1, 0, 1)), f.x), mix(h3(i + vec3(0, 1, 1)), h3(i + vec3(1, 1, 1)), f.x), f.y),\n    f.z);\n}\nfloat fbm(vec3 p){ return n3(p) * 0.55 + n3(p * 2.03 + 7.1) * 0.3 + n3(p * 4.1 + 3.3) * 0.15; }\n\nvoid main(){\n  vec2 p = (gl_FragCoord.xy - 0.5 * uRes) / uRes.y;\n  float c = cos(uAngle), s = sin(uAngle);\n  p = vec2(c * p.x - s * p.y, s * p.x + c * p.y);\n  float t = uTime;\n  float R = uWidth * 0.5;\n  float ax = abs(p.x);\n\n  // March through the cylinder along the view ray and gather swirling smoke.\n  float dens = 0.0;\n  if (ax < R) {\n    float hz = sqrt(R * R - p.x * p.x);\n    for (int i = 0; i < 14; i++) {\n      float z = mix(-hz, hz, (float(i) + 0.5) / 14.0);\n      float a = t * 0.5 + p.y * uTwist;\n      float ca = cos(a), sa = sin(a);\n      vec3 q = vec3(ca * p.x - sa * z, p.y, sa * p.x + ca * z) / R;\n      q.y = q.y * 0.35 - t * 0.35;\n      float n = fbm(q * 2.2);\n      dens += smoothstep(0.38, 0.82, n);\n    }\n    dens /= 14.0;\n    float e = hz * hz / (R * R);\n    dens *= e * e; // fade smoothly to nothing at the rim\n  }\n\n  float x = ax / R;\n  float core = exp(-x * x * 8.0) * 0.6 + exp(-x * x * 90.0) * 0.7;\n  float halo = exp(-x * 1.6) * 0.35 + exp(-x * 0.55) * 0.08;\n  float ends = smoothstep(0.62, 0.05, abs(p.y)) * 0.6 + 0.4;\n  float I = (dens * 2.2 + core * 0.6 + halo) * ends * uIntensity;\n\n  float g = clamp(p.y + 0.5 + (dens - 0.3) * 0.25, 0.0, 1.0);\n  vec3 tint = mix(uBottom, uTop, smoothstep(0.0, 1.0, g));\n  vec3 col = tint * I + vec3(1.0) * pow(core * dens * uIntensity, 2.0) * 0.6;\n  col += (fract(sin(dot(gl_FragCoord.xy, vec2(12.9898, 78.233))) * 43758.5453) - 0.5) / 255.0;\n  col = clamp(col, 0.0, 1.0);\n  gl_FragColor = vec4(col, max(col.r, max(col.g, col.b)));\n}`;\n\nfunction hexToRgb(hex: string) {\n  const n = parseInt(hex.replace(\"#\", \"\").padEnd(6, \"0\").slice(0, 6), 16);\n  return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];\n}\n\ntype SetUniform = (name: string, v: number | number[], size?: number) => void;\n\n/** Full-screen-triangle WebGL runner: sizes to its host, pauses offscreen, one static frame under reduced motion. */\nfunction mountShader(host: HTMLElement, frag: string, frame: (set: SetUniform, dt: number) => void) {\n  const canvas = document.createElement(\"canvas\");\n  canvas.style.cssText = \"position:absolute;inset:0;width:100%;height:100%;display:block\";\n  const gl = canvas.getContext(\"webgl\", { antialias: false, premultipliedAlpha: true });\n  if (!gl) return null;\n  const prog = gl.createProgram()!;\n  const stages: [number, string][] = [\n    [gl.VERTEX_SHADER, \"attribute vec2 p;void main(){gl_Position=vec4(p,0.,1.);}\"],\n    [gl.FRAGMENT_SHADER, frag],\n  ];\n  for (const [type, src] of stages) {\n    const s = gl.createShader(type)!;\n    gl.shaderSource(s, src);\n    gl.compileShader(s);\n    if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) console.warn(gl.getShaderInfoLog(s));\n    gl.attachShader(prog, s);\n  }\n  gl.bindAttribLocation(prog, 0, \"p\");\n  gl.linkProgram(prog);\n  if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) {\n    gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n    return null;\n  }\n  gl.useProgram(prog);\n  gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());\n  gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);\n  gl.enableVertexAttribArray(0);\n  gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n  host.appendChild(canvas);\n\n  const locs = new Map<string, WebGLUniformLocation | null>();\n  const setters = [gl.uniform1fv, gl.uniform2fv, gl.uniform3fv, gl.uniform4fv];\n  const set: SetUniform = (name, v, size) => {\n    if (!locs.has(name)) locs.set(name, gl.getUniformLocation(prog, name));\n    const arr = typeof v === \"number\" ? [v] : v;\n    setters[(size ?? arr.length) - 1].call(gl, locs.get(name)!, arr);\n  };\n\n  const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  let raf = 0;\n  let last = 0;\n  const render = (dt: number) => {\n    set(\"uRes\", [canvas.width, canvas.height]);\n    frame(set, dt);\n    gl.drawArrays(gl.TRIANGLES, 0, 3);\n  };\n  const loop = (now: number) => {\n    render(last ? Math.min((now - last) / 1000, 0.1) : 0);\n    last = now;\n    raf = requestAnimationFrame(loop);\n  };\n  const resize = () => {\n    const dpr = Math.min(window.devicePixelRatio || 1, 2);\n    canvas.width = Math.max(1, Math.round(host.clientWidth * dpr));\n    canvas.height = Math.max(1, Math.round(host.clientHeight * dpr));\n    gl.viewport(0, 0, canvas.width, canvas.height);\n    render(0);\n  };\n  const ro = new ResizeObserver(resize);\n  ro.observe(host);\n  const io = new IntersectionObserver(([e]) => {\n    cancelAnimationFrame(raf);\n    raf = 0;\n    last = 0;\n    if (e.isIntersecting && !reduced) raf = requestAnimationFrame(loop);\n  });\n  io.observe(host);\n\n  return {\n    redraw: () => {\n      if (!raf) render(0);\n    },\n    destroy: () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n      canvas.remove();\n    },\n  };\n}\n\nexport function SmokeColumn({\n  topColor = \"#a78bfa\",\n  bottomColor = \"#22d3ee\",\n  width = 0.32,\n  intensity = 1,\n  speed = 1,\n  twist = 2.5,\n  angle = 0,\n  className,\n}: SmokeColumnProps) {\n  const host = useRef<HTMLDivElement>(null);\n  const opts = useRef({ top: hexToRgb(topColor), bottom: hexToRgb(bottomColor), width, intensity, speed, twist, angle });\n  const redraw = useRef<() => void>(undefined);\n\n  useEffect(() => {\n    opts.current = { top: hexToRgb(topColor), bottom: hexToRgb(bottomColor), width, intensity, speed, twist, angle };\n    redraw.current?.();\n  }, [topColor, bottomColor, width, intensity, speed, twist, angle]);\n\n  useEffect(() => {\n    let t = 3;\n    const shader = mountShader(host.current!, FRAG, (set, dt) => {\n      const o = opts.current;\n      t += dt * o.speed;\n      set(\"uTime\", t);\n      set(\"uTop\", o.top);\n      set(\"uBottom\", o.bottom);\n      set(\"uWidth\", Math.max(o.width, 0.02));\n      set(\"uIntensity\", o.intensity);\n      set(\"uTwist\", o.twist);\n      set(\"uAngle\", (o.angle * Math.PI) / 180);\n    });\n    if (!shader) return;\n    redraw.current = shader.redraw;\n    return () => {\n      redraw.current = undefined;\n      shader.destroy();\n    };\n  }, []);\n\n  return (\n    <div\n      ref={host}\n      aria-hidden\n      className={className}\n      style={{ position: \"absolute\", inset: 0, overflow: \"hidden\", pointerEvents: \"none\" }}\n    />\n  );\n}\n"}]}