{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"neon-floor","type":"registry:ui","title":"Neon Floor","description":"A neon perspective grid floor swept by a glowing scan line, with a horizon that follows the cursor.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/neon-floor.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nexport interface NeonFloorProps {\n  gridColor?: string;\n  scanColor?: string;\n  /** Grid cells per world unit; higher is denser. */\n  density?: number;\n  /** Scan sweep speed multiplier. */\n  speed?: number;\n  /** Thickness of the scanning band. */\n  scanWidth?: number;\n  /** Overall glow intensity. */\n  glow?: number;\n  className?: string;\n}\n\nconst FRAG = `\n#extension GL_OES_standard_derivatives : enable\nprecision highp float;\nfloat sq(float v) { return v * v; }\nuniform vec2 uRes;\nuniform float uTime;\nuniform vec2 uMouse;\nuniform float uHover;\nuniform vec3 uGrid;\nuniform vec3 uScan;\nuniform float uDensity;\nuniform float uScanWidth;\nuniform float uGlow;\n\nfloat gridLine(vec2 g, float width) {\n  vec2 d = abs(fract(g - 0.5) - 0.5) / max(fwidth(g), 1e-4);\n  return 1.0 - min(min(d.x, d.y) / width, 1.0);\n}\n\nvoid main() {\n  vec2 p = (gl_FragCoord.xy - 0.5 * uRes) / uRes.y;\n  vec2 m = (uMouse - 0.5) * vec2(uRes.x / uRes.y, 1.0) * uHover;\n  float horizon = 0.1 + m.y * 0.06;\n  p.x -= m.x * 0.18;\n\n  // scan sweeps from the horizon toward the viewer, speeding up as it approaches\n  float s = fract(uTime * 0.18 + 0.45);\n  float sb = mix(0.0, 0.7, s * s);\n  float sw = uScanWidth * 0.3 * sb + 0.006;\n\n  vec3 col = vec3(0.0);\n  float below = horizon - p.y;\n  if (below > 0.0) {\n    float z = 0.32 / below;\n    vec2 w = vec2(p.x * z + m.x * 1.2, z) * uDensity * 1.6;\n    float band = exp(-sq((below - sb) / sw)) * step(below, sb) + exp(-sq((below - sb) / (sw * 0.2))) * step(sb, below);\n    float ahead = exp(-sq((below - sb) / (sw * 0.12)));\n    float fog = exp(-z * 0.07);\n    float line = gridLine(w, 1.0);\n    float halo = gridLine(w, 5.0);\n    col += mix(uGrid, uScan, band * 0.6) * (line * (0.7 + 2.5 * band) + halo * 0.12 * (1.0 + 3.0 * band)) * fog;\n    col += uScan * band * band * 0.3 * fog;\n    col += uScan * (line * 1.6 + 0.35) * ahead * fog;\n    col *= smoothstep(0.0, 0.03, below);\n  }\n  // horizon glow and scan flash when the sweep starts far away\n  float hz = exp(-abs(p.y - horizon) * 14.0);\n  col += uGrid * hz * 0.35 * uGlow;\n  col += uScan * hz * 0.5 * exp(-s * 6.0);\n  col += uGrid * 0.06 * exp(-length(vec2(p.x * 0.5, p.y - horizon)) * 3.0);\n\n  col *= uGlow;\n  col = 1.0 - exp(-col * 1.2);\n  gl_FragColor = vec4(col, clamp(max(col.r, max(col.g, col.b)), 0.0, 1.0));\n}\n`;\n\nconst VERT = \"attribute vec2 p;void main(){gl_Position=vec4(p,0.,1.);}\";\n\ntype Ptr = { x: number; y: number; hover: number };\ntype Uni = (name: string) => WebGLUniformLocation | null;\n\n/** Full-screen shader canvas inside `host`: DPR-capped resize, offscreen pause, reduced motion, eased pointer. */\nfunction runShader(host: HTMLElement, frag: string, speed: () => number, update: (gl: WebGLRenderingContext, u: Uni) => 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 });\n  if (!gl) return null;\n  gl.getExtension(\"OES_standard_derivatives\");\n  const prog = gl.createProgram()!;\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    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)) {\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 u: Uni = (n) => {\n    if (!locs.has(n)) locs.set(n, gl.getUniformLocation(prog, n));\n    return locs.get(n) ?? null;\n  };\n  const zone = host.parentElement ?? host;\n  const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  const ptr: Ptr = { x: 0.5, y: 0.5, hover: 0 };\n  const goal: Ptr = { ...ptr };\n  let raf = 0;\n  let last = 0;\n  let time = 0;\n\n  const draw = () => {\n    gl.uniform2f(u(\"uRes\"), canvas.width, canvas.height);\n    gl.uniform1f(u(\"uTime\"), time);\n    gl.uniform2f(u(\"uMouse\"), ptr.x, ptr.y);\n    gl.uniform1f(u(\"uHover\"), ptr.hover);\n    update(gl, u);\n    gl.drawArrays(gl.TRIANGLES, 0, 3);\n  };\n  const loop = (now: number) => {\n    const dt = Math.min((now - last) / 1000, 0.1);\n    last = now;\n    const k = 1 - Math.exp(-dt * 4);\n    for (const key of [\"x\", \"y\", \"hover\"] as const) ptr[key] += (goal[key] - ptr[key]) * k;\n    time += dt * speed();\n    draw();\n    raf = requestAnimationFrame(loop);\n  };\n  const run = (on: boolean) => {\n    if (on && !raf && !reduced) {\n      last = performance.now();\n      raf = requestAnimationFrame(loop);\n    } else if (!on && raf) {\n      cancelAnimationFrame(raf);\n      raf = 0;\n    }\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    draw();\n  };\n  const move = (e: PointerEvent) => {\n    const r = host.getBoundingClientRect();\n    goal.x = (e.clientX - r.left) / r.width;\n    goal.y = 1 - (e.clientY - r.top) / r.height;\n    goal.hover = 1;\n  };\n  const leave = () => {\n    goal.hover = 0;\n  };\n  const ro = new ResizeObserver(resize);\n  const io = new IntersectionObserver(([e]) => run(e.isIntersecting));\n  ro.observe(host);\n  io.observe(host);\n  zone.addEventListener(\"pointermove\", move);\n  zone.addEventListener(\"pointerleave\", leave);\n  return {\n    redraw: () => {\n      if (!raf) draw();\n    },\n    dispose: () => {\n      run(false);\n      ro.disconnect();\n      io.disconnect();\n      zone.removeEventListener(\"pointermove\", move);\n      zone.removeEventListener(\"pointerleave\", leave);\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n      canvas.remove();\n    },\n  };\n}\n\nconst rgb = (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\nexport function NeonFloor({\n  gridColor = \"#8b5cf6\",\n  scanColor = \"#22d3ee\",\n  density = 1,\n  speed = 1,\n  scanWidth = 0.5,\n  glow = 1,\n  className,\n}: NeonFloorProps) {\n  const ref = useRef<HTMLDivElement>(null);\n  const opts = useRef({ gridColor, scanColor, density, speed, scanWidth, glow });\n  const redraw = useRef<(() => void) | undefined>(undefined);\n\n  useEffect(() => {\n    opts.current = { gridColor, scanColor, density, speed, scanWidth, glow };\n    redraw.current?.();\n  }, [gridColor, scanColor, density, speed, scanWidth, glow]);\n\n  useEffect(() => {\n    const r = runShader(\n      ref.current!,\n      FRAG,\n      () => opts.current.speed,\n      (gl, u) => {\n        const o = opts.current;\n        gl.uniform3fv(u(\"uGrid\"), rgb(o.gridColor));\n        gl.uniform3fv(u(\"uScan\"), rgb(o.scanColor));\n        gl.uniform1f(u(\"uDensity\"), Math.max(0.1, o.density));\n        gl.uniform1f(u(\"uScanWidth\"), Math.max(0.05, o.scanWidth));\n        gl.uniform1f(u(\"uGlow\"), o.glow);\n      },\n    );\n    redraw.current = r?.redraw;\n    return () => r?.dispose();\n  }, []);\n\n  return (\n    <div\n      ref={ref}\n      aria-hidden\n      className={className}\n      style={{ position: \"absolute\", inset: 0, overflow: \"hidden\", pointerEvents: \"none\" }}\n    />\n  );\n}\n"}]}