{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"pastel-curtains","type":"registry:ui","title":"Pastel Curtains","description":"Gentle pastel aurora curtains that sway in slow vertical folds, with soft light rays. WebGL.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/pastel-curtains.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nexport interface PastelCurtainsProps {\n  /** Three curtain colors, back to front. Pastels work best. */\n  colors?: string[];\n  /** Drift speed multiplier; 0 freezes the motion. */\n  speed?: number;\n  /** Width of the folds; higher means broader, lazier curtains. */\n  scale?: number;\n  /** Overall brightness. */\n  intensity?: number;\n  className?: string;\n}\n\nconst VERT = \"attribute vec2 p;void main(){gl_Position=vec4(p,0.,1.);}\";\n\nconst FRAG = `\nprecision highp float;\nuniform vec2 uRes;\nuniform float uTime;\nuniform vec3 uC1;\nuniform vec3 uC2;\nuniform vec3 uC3;\nuniform float uScale;\nuniform float uIntensity;\n\nfloat hash(vec2 p) {\n  p = fract(p * vec2(127.1, 311.7));\n  p += dot(p, p + 34.23);\n  return fract(p.x * p.y);\n}\nfloat noise(vec2 p) {\n  vec2 i = floor(p), f = fract(p);\n  vec2 u = f * f * (3.0 - 2.0 * f);\n  return mix(mix(hash(i), hash(i + vec2(1, 0)), u.x), mix(hash(i + vec2(0, 1)), hash(i + vec2(1, 1)), u.x), u.y);\n}\nfloat fbm(vec2 p) {\n  float v = 0.0, a = 0.5;\n  for (int i = 0; i < 4; i++) { v += a * noise(p); p = p * 2.03 + vec2(17.1, 9.3); a *= 0.5; }\n  return v;\n}\n\nvec3 palette(float h) {\n  h = clamp(h, 0.0, 1.0);\n  return h < 0.5 ? mix(uC1, uC2, h * 2.0) : mix(uC2, uC3, h * 2.0 - 1.0);\n}\n\n// One curtain: a wavy lower hem with an upward fade, streaked by soft vertical rays.\n// Color follows height (first color at the hem, later colors toward the top) and drifts sideways,\n// so overlapping curtains never mix into gray.\nvec3 curtain(vec2 p, float t, float seed, float hemY) {\n  float sway = fbm(vec2(p.x * 0.35 + seed, t * 0.5)) * 2.0 - 1.0;\n  float x = p.x + sway * 0.9;\n  float hem = hemY + 0.13 * sin(x * 1.3 + t * 1.3 + seed) + 0.2 * (fbm(vec2(x * 0.9, t * 0.8 + seed)) - 0.5);\n  float d = p.y - hem;\n  float up = max(d, 0.0);\n  float body = smoothstep(-0.03, 0.05, d) * (exp(-up * 5.0) * 0.9 + exp(-up * 1.6) * 0.15);\n  float under = exp(-max(-d, 0.0) * 16.0) * 0.12;\n  float rays = noise(vec2(x * 4.0 + seed * 7.0, t * 1.1 + p.y * 0.1));\n  rays = 0.12 + 0.88 * smoothstep(0.2, 0.95, rays);\n  float gap = smoothstep(0.36, 0.68, fbm(vec2(x * 0.5 - t * 0.6, seed)));\n  float hue = smoothstep(0.2, 0.8, fbm(vec2(x * 0.25 + t * 0.4, seed + 2.0))) * 0.55 + up * 1.1;\n  return palette(hue) * (body * rays + under) * gap;\n}\n\nvoid main() {\n  vec2 p = vec2((gl_FragCoord.x - 0.5 * uRes.x) / uRes.y / uScale, gl_FragCoord.y / uRes.y);\n  float t = uTime * 0.08;\n  vec3 col = curtain(p, t, 0.0, 0.42);\n  col += curtain(p * vec2(1.4, 1.0), t * 1.15, 3.7, 0.3) * 0.8;\n  col = 1.0 - exp(-col * 1.4 * uIntensity);\n  // Premultiplied alpha so the glow sits on any background.\n  gl_FragColor = vec4(col, clamp(max(col.r, max(col.g, col.b)), 0.0, 1.0));\n}\n`;\n\nfunction rgb(hex: string) {\n  let h = (hex || \"#000\").replace(\"#\", \"\");\n  if (h.length === 3) h = h.replace(/./g, \"$&$&\");\n  const n = parseInt(h.padEnd(6, \"0\").slice(0, 6), 16) || 0;\n  return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];\n}\n\n/** Compiles a full-screen-triangle program and returns a cached uniform lookup, or null. */\nfunction fullscreen(gl: WebGLRenderingContext, frag: string) {\n  const prog = gl.createProgram();\n  if (!prog) return null;\n  for (const [type, src] of [\n    [gl.VERTEX_SHADER, VERT],\n    [gl.FRAGMENT_SHADER, frag],\n  ] as const) {\n    const sh = gl.createShader(type);\n    if (!sh) return null;\n    gl.shaderSource(sh, src);\n    gl.compileShader(sh);\n    if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) console.warn(gl.getShaderInfoLog(sh));\n    gl.attachShader(prog, sh);\n  }\n  gl.bindAttribLocation(prog, 0, \"p\");\n  gl.linkProgram(prog);\n  if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) return null;\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  const cache = new Map<string, WebGLUniformLocation | null>();\n  return (name: string) => {\n    if (!cache.has(name)) cache.set(name, gl.getUniformLocation(prog, name));\n    return cache.get(name) ?? null;\n  };\n}\n\nexport function PastelCurtains({\n  colors = [\"#6ee7b7\", \"#a78bfa\", \"#f9a8d4\"],\n  speed = 1,\n  scale = 1,\n  intensity = 1,\n  className,\n}: PastelCurtainsProps) {\n  const host = useRef<HTMLDivElement>(null);\n  const opts = useRef({ colors, speed, scale, intensity });\n  const redraw = useRef<(() => void) | null>(null);\n\n  useEffect(() => {\n    opts.current = { colors, speed, scale, intensity };\n    redraw.current?.();\n  }, [colors, speed, scale, intensity]);\n\n  useEffect(() => {\n    const el = host.current!;\n    const canvas = document.createElement(\"canvas\");\n    canvas.style.cssText = \"position:absolute;inset:0;width:100%;height:100%;display:block\";\n    el.appendChild(canvas);\n    const gl = canvas.getContext(\"webgl\", { antialias: false, powerPreference: \"low-power\" });\n    const u = gl && fullscreen(gl, FRAG);\n    if (!gl || !u) {\n      canvas.remove();\n      return;\n    }\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let raf = 0;\n    let visible = true;\n    let time = 40;\n    let last = 0;\n\n    const draw = () => {\n      const o = opts.current;\n      const c = o.colors.length ? o.colors : [\"#ffffff\"];\n      gl.uniform2f(u(\"uRes\"), canvas.width, canvas.height);\n      gl.uniform1f(u(\"uTime\"), time);\n      gl.uniform3fv(u(\"uC1\"), rgb(c[0]));\n      gl.uniform3fv(u(\"uC2\"), rgb(c[1 % c.length]));\n      gl.uniform3fv(u(\"uC3\"), rgb(c[2 % c.length]));\n      gl.uniform1f(u(\"uScale\"), Math.max(o.scale, 0.05));\n      gl.uniform1f(u(\"uIntensity\"), o.intensity);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n    };\n    const loop = (now: number) => {\n      time += (Math.min(now - last, 50) / 1000) * opts.current.speed;\n      last = now;\n      draw();\n      raf = requestAnimationFrame(loop);\n    };\n    const play = () => {\n      if (raf || !visible || reduced) return;\n      last = performance.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(el.clientWidth * dpr));\n      canvas.height = Math.max(1, Math.round(el.clientHeight * dpr));\n      gl.viewport(0, 0, canvas.width, canvas.height);\n      draw();\n    };\n\n    const ro = new ResizeObserver(resize);\n    ro.observe(el);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) play();\n      else {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n    });\n    io.observe(el);\n    redraw.current = draw;\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      redraw.current = null;\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n      canvas.remove();\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"}]}