{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"wisp-fibers","type":"registry:ui","title":"Wisp Fibers","description":"Translucent glowing fibers that braid, drift apart and fade in and out like ghostly silk.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/wisp-fibers.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nexport interface WispFibersProps {\n  /** One color per bundle (up to three). */\n  colors?: string[];\n  /** Fibers per bundle. */\n  fibers?: number;\n  /** Halo strength around each fiber. */\n  glow?: number;\n  /** How far fibers drift apart from each other. */\n  spread?: number;\n  /** Animation speed multiplier. */\n  speed?: number;\n  className?: string;\n}\n\nconst FRAG = `\nprecision highp float;\nuniform vec2 uRes;\nuniform float uTime;\nuniform vec2 uMouse;\nuniform float uHover;\nuniform vec3 uC0;\nuniform vec3 uC1;\nuniform vec3 uC2;\nuniform float uFibers;\nuniform float uGlow;\nuniform float uSpread;\n\nfloat hash(float n) { return fract(sin(n * 91.345) * 47453.5453); }\nfloat noise(vec2 p) {\n  vec2 i = floor(p), f = fract(p);\n  f = f * f * (3.0 - 2.0 * f);\n  float n = i.x + i.y * 57.0;\n  return mix(mix(hash(n), hash(n + 1.0), f.x), mix(hash(n + 57.0), hash(n + 58.0), f.x), f.y);\n}\n\nvoid main() {\n  float asp = uRes.x / uRes.y;\n  float px = 1.0 / uRes.y;\n  mat2 tilt = mat2(0.974, 0.225, -0.225, 0.974);\n  vec2 p = tilt * (gl_FragCoord.xy / uRes.y - vec2(0.5 * asp, 0.5));\n  vec2 m = tilt * ((uMouse - 0.5) * vec2(asp, 1.0));\n  float t = uTime;\n  vec3 col = vec3(0.0);\n\n  for (int b = 0; b < 3; b++) {\n    float fb = float(b);\n    vec3 bc = b == 0 ? uC0 : (b == 1 ? uC1 : uC2);\n    float x = p.x;\n    float s1 = x * 1.3 + t * 0.35 + fb * 2.1;\n    float s2 = x * 2.9 - t * 0.27 + fb * 4.0;\n    float path = (fb - 1.0) * 0.2 * uSpread + 0.14 * sin(s1) + 0.06 * sin(s2);\n    float dpath = 0.182 * cos(s1) + 0.174 * cos(s2);\n    vec2 dm = vec2(x, path) - m;\n    path += dm.y / (abs(dm.y) + 0.05) * 0.09 * uHover * exp(-dot(dm, dm) / 0.05);\n    // bundle radius swells and pinches along its length: fibers braid together then drift apart\n    float rad = (0.02 + 0.07 * (0.5 + 0.5 * sin(x * 0.9 - t * 0.4 + fb * 1.7))) * uSpread;\n    float fk = 2.2 + 0.2 * fb;\n    for (int i = 0; i < 24; i++) {\n      float fi = float(i);\n      if (fi >= uFibers) break;\n      float ph = x * fk + t * (0.5 + 0.1 * fb) + fi * 6.2831853 / uFibers + hash(fi + fb * 7.0) * 1.3;\n      float amp = rad * (0.6 + 0.4 * hash(fi * 3.7 + fb));\n      float y = path + amp * sin(ph);\n      float dy = dpath + amp * fk * cos(ph);\n      float z = 0.5 + 0.5 * cos(ph);  // 1 = in front\n      float d = abs(p.y - y) / sqrt(1.0 + dy * dy);\n      float w = px * (0.7 + 0.9 * z);\n      float life = smoothstep(0.25, 0.75, noise(vec2(x * 0.8 - t * 0.2, fi * 3.1 + fb * 11.0)));\n      float I = exp(-d * d / (w * w)) * 0.8 + uGlow * 0.1 * exp(-d / (px * 20.0));\n      col += mix(bc, vec3(1.0), 0.25 * z) * I * life * (0.3 + 0.7 * z);\n    }\n  }\n\n  // faint haze that follows the cursor\n  col += (uC0 + uC1) * 0.06 * uHover * exp(-dot(p - m, p - m) * 6.0);\n  col += mix(uC1, uC0, gl_FragCoord.x / uRes.x) * 0.035 * exp(-p.y * p.y * 8.0);\n  float ex = gl_FragCoord.x / uRes.x;\n  col *= smoothstep(0.0, 0.15, ex) * smoothstep(1.0, 0.85, ex);\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  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 WispFibers({\n  colors = [\"#8be9fd\", \"#b69cff\", \"#ff9ad5\"],\n  fibers = 9,\n  glow = 1,\n  spread = 1,\n  speed = 1,\n  className,\n}: WispFibersProps) {\n  const ref = useRef<HTMLDivElement>(null);\n  const opts = useRef({ colors, fibers, glow, spread, speed });\n  const redraw = useRef<(() => void) | undefined>(undefined);\n\n  useEffect(() => {\n    opts.current = { colors, fibers, glow, spread, speed };\n    redraw.current?.();\n  }, [colors, fibers, glow, spread, speed]);\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        const c = o.colors.length ? o.colors : [\"#ffffff\"];\n        for (let i = 0; i < 3; i++) gl.uniform3fv(u(`uC${i}`), rgb(c[i % c.length]));\n        gl.uniform1f(u(\"uFibers\"), Math.max(1, o.fibers));\n        gl.uniform1f(u(\"uGlow\"), o.glow);\n        gl.uniform1f(u(\"uSpread\"), o.spread);\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"}]}