{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "spotlight-shafts",
  "title": "Spotlight Shafts",
  "description": "A stage-light background shader: five spotlight beams cut through drifting haze from above, swaying slowly, with dust motes glinting only where the light catches them and a warm glow on the floor; the middle spotlight follows the pointer.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/spotlight-shafts/spotlight-shafts.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 SpotlightShaftsProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"children\"> {\n  /** Content shown on top of the background. */\n  children?: React.ReactNode;\n  /** Light colours: warm beams, cool beams, dust motes and the glow on the floor. */\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 middle spotlight swings to follow the pointer. */\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] = [\"#ffd9a0\", \"#a6c8ff\", \"#ffffff\", \"#ff9e7a\"];\nconst DEFAULT_BACKGROUND = \"#07070b\";\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  vec2 uv = gl_FragCoord.xy / uRes;\n  float ar = uRes.x / uRes.y;\n  vec2 p = vec2(uv.x * ar, uv.y);\n  float t = uTime;\n  vec3 col = uBg;\n  float haze = fbm(p * 2.2 + vec2(t * 0.05, -t * 0.03));\n  vec3 beams = vec3(0.0);\n  float lit = 0.0;\n  for (int i = 0; i < 5; i++) {\n    float fi = float(i);\n    vec2 o = vec2((0.1 + 0.2 * fi) * ar, 1.06);\n    float aim = -1.5708 + sin(t * 0.33 + fi * 1.9) * 0.22 + (fi - 2.0) * 0.08;\n    if (i == 2) {\n      vec2 tm = vec2(uMouse.x * ar, min(uMouse.y, 0.95)) - o;\n      aim = mix(aim, atan(tm.y, tm.x), uHover);\n    }\n    vec2 d = p - o;\n    float ang = atan(d.y, d.x);\n    float spread = 0.15 + 0.04 * sin(fi * 2.7 + 1.0);\n    float off = abs(ang - aim) / spread;\n    float beam = exp(-off * off * 2.6) * smoothstep(1.0, 0.6, off);\n    beam *= smoothstep(1.7, 0.0, length(d)) * (0.75 + 0.25 * sin(t * 0.9 + fi));\n    beam += exp(-length(d) * 9.0) * 0.5;\n    beams += mix(uC0, uC1, mod(fi, 2.0)) * beam;\n    lit += beam;\n  }\n  col += beams * (0.3 + 0.9 * haze * haze) * 0.66;\n\n  // Dust motes drifting slowly, only visible where a beam catches them.\n  vec2 dp = p * 34.0 + vec2(t * 0.6, t * 1.1);\n  vec2 di = floor(dp);\n  vec2 df = fract(dp) - 0.5 + (vec2(hash(di), hash(di + 3.1)) - 0.5) * 0.6;\n  float mote = step(0.9, hash(di + 7.7)) * smoothstep(0.08, 0.0, length(df));\n  col += uC2 * mote * clamp(lit, 0.0, 1.0) * 0.8;\n\n  col += uC3 * 0.18 * exp(-uv.y * 9.0) * (0.5 + 0.5 * clamp(lit, 0.0, 1.5));\n  col *= uIntensity;\n  col *= 1.0 - 0.2 * length((uv - 0.5) * vec2(1.0, 0.7));\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(\"SpotlightShafts shader:\", gl.getShaderInfoLog(shader));\n    gl.deleteShader(shader);\n    return null;\n  }\n  return shader;\n}\n\nexport function SpotlightShafts({\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}: SpotlightShaftsProps) {\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: 4, 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"
}