{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"white-stripes","type":"registry:ui","title":"White Stripes","description":"Layers of satin-shaded diagonal stripes drift at different speeds, casting soft shadows with cursor parallax. WebGL.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/white-stripes.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nexport interface WhiteStripesProps {\n  /** Stripe color. */\n  color?: string;\n  /** Drift speed multiplier; 0 freezes the stripes. */\n  speed?: number;\n  /** Stripe density; higher means thinner, more stripes. */\n  scale?: number;\n  /** Stripe angle in degrees. */\n  angle?: number;\n  /** Overall opacity, 0 to 1. */\n  opacity?: number;\n  /** Layers shift with the cursor for a parallax effect. */\n  parallax?: boolean;\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 uColor;\nuniform float uScale;\nuniform float uAngle;\nuniform float uOpacity;\nuniform vec2 uMouse;\n\n// Coverage of one stripe layer at across-coordinate s (in periods), with soft edge width aa.\nfloat cover(float s, float w, float aa) {\n  float f = fract(s);\n  return smoothstep(0.0, aa, f) * smoothstep(w, w - aa, f);\n}\n\nvoid main() {\n  vec2 uv = gl_FragCoord.xy / uRes;\n  vec2 p = (gl_FragCoord.xy - 0.5 * uRes) / uRes.y;\n  float px = 1.0 / uRes.y;\n  float c = cos(uAngle), s = sin(uAngle);\n  vec2 q = mat2(c, -s, s, c) * p;\n  float t = uTime;\n  vec2 m = uMouse - 0.5;\n\n  vec4 acc = vec4(0.0);\n  for (int i = 0; i < 3; i++) {\n    float fi = float(i);\n    // Back layers are thinner, dimmer and slower: that difference sells the depth.\n    float freq = uScale * (7.5 - fi * 2.3);\n    float w = 0.2 + fi * 0.06;\n    float bright = 0.32 + fi * 0.32;\n    float alpha = 0.55 + fi * 0.2;\n    float x = q.x + dot(m, vec2(c, -s)) * 0.04 * (fi + 1.0);\n    x += 0.035 * (fi * 0.5 + 0.5) * sin(q.y * (1.3 - fi * 0.2) + t * 0.25 + fi * 2.0);\n    float sp = x * freq - t * (0.05 + fi * 0.045) + fi * 0.37;\n\n    // Soft drop shadow cast onto everything behind this layer.\n    float sh = cover(sp - 0.06, w, 0.12) * 0.45;\n    acc = acc * (1.0 - sh) + vec4(0.0, 0.0, 0.0, sh);\n\n    float aa = px * freq * 1.5;\n    float cov = cover(sp, w, aa);\n    float k = clamp(fract(sp) / w, 0.0, 1.0);\n    // Rounded satin profile lit from one side, plus a thin specular line.\n    float shade = 0.25 + 0.75 * pow(sin(k * 3.14159), 0.6) * (0.7 + 0.3 * (1.0 - k));\n    shade += 0.35 * exp(-pow((k - 0.28) / 0.07, 2.0));\n    float a = cov * alpha;\n    acc = acc * (1.0 - a) + vec4(uColor * shade * bright * a, a);\n  }\n\n  vec2 v = uv - 0.5;\n  acc *= uOpacity * clamp(1.0 - dot(v, v) * 1.2, 0.0, 1.0);\n  gl_FragColor = acc;\n}\n`;\n\nfunction rgb(hex: string) {\n  let h = hex.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 WhiteStripes({\n  color = \"#ffffff\",\n  speed = 1,\n  scale = 1,\n  angle = 35,\n  opacity = 0.85,\n  parallax = true,\n  className,\n}: WhiteStripesProps) {\n  const host = useRef<HTMLDivElement>(null);\n  const opts = useRef({ color, speed, scale, angle, opacity, parallax });\n  const redraw = useRef<(() => void) | null>(null);\n\n  useEffect(() => {\n    opts.current = { color, speed, scale, angle, opacity, parallax };\n    redraw.current?.();\n  }, [color, speed, scale, angle, opacity, parallax]);\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, premultipliedAlpha: true, 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    const pointer = { x: 0.5, y: 0.5, tx: 0.5, ty: 0.5 };\n    let raf = 0;\n    let visible = true;\n    let time = 5;\n    let last = 0;\n\n    const draw = () => {\n      const o = opts.current;\n      gl.uniform2f(u(\"uRes\"), canvas.width, canvas.height);\n      gl.uniform1f(u(\"uTime\"), time);\n      gl.uniform3fv(u(\"uColor\"), rgb(o.color));\n      gl.uniform1f(u(\"uScale\"), Math.max(o.scale, 0.1));\n      gl.uniform1f(u(\"uAngle\"), (o.angle * Math.PI) / 180);\n      gl.uniform1f(u(\"uOpacity\"), Math.min(Math.max(o.opacity, 0), 1));\n      gl.uniform2f(u(\"uMouse\"), o.parallax ? pointer.x : 0.5, o.parallax ? pointer.y : 0.5);\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      pointer.x += (pointer.tx - pointer.x) * 0.05;\n      pointer.y += (pointer.ty - pointer.y) * 0.05;\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    const onMove = (e: PointerEvent) => {\n      const r = el.getBoundingClientRect();\n      pointer.tx = (e.clientX - r.left) / r.width;\n      pointer.ty = 1 - (e.clientY - r.top) / r.height;\n    };\n\n    const target = el.parentElement ?? el;\n    target.addEventListener(\"pointermove\", onMove, { passive: true });\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      target.removeEventListener(\"pointermove\", onMove);\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"}]}