{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"weave-lines","type":"registry:ui","title":"Weave Lines","description":"Dozens of fine horizontal lines weaving into flowing silk-like waves that bulge away from the cursor. Canvas 2D.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/weave-lines.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nexport interface WeaveLinesProps {\n  /** Number of lines. */\n  count?: number;\n  /** Color of the top line; lines blend toward `colorB`. */\n  colorA?: string;\n  colorB?: string;\n  /** Wave height in px. */\n  amplitude?: number;\n  /** Animation speed multiplier. */\n  speed?: number;\n  lineWidth?: number;\n  /** Lines bulge away from the cursor. */\n  interactive?: boolean;\n  /** Bulge radius in px. */\n  bulgeRadius?: number;\n  className?: string;\n}\n\nfunction hexToRgb(hex: string) {\n  const n = parseInt(hex.replace(\"#\", \"\").padEnd(6, \"0\").slice(0, 6), 16);\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\nexport function WeaveLines({\n  count = 36,\n  colorA = \"#22d3ee\",\n  colorB = \"#a78bfa\",\n  amplitude = 48,\n  speed = 1,\n  lineWidth = 1,\n  interactive = true,\n  bulgeRadius = 140,\n  className,\n}: WeaveLinesProps) {\n  const ref = useRef<HTMLCanvasElement>(null);\n  const opts = useRef({ count, a: hexToRgb(colorA), b: hexToRgb(colorB), amplitude, speed, lineWidth, interactive, bulgeRadius });\n  const redraw = useRef<() => void>(undefined);\n\n  useEffect(() => {\n    opts.current = { count, a: hexToRgb(colorA), b: hexToRgb(colorB), amplitude, speed, lineWidth, interactive, bulgeRadius };\n    redraw.current?.();\n  }, [count, colorA, colorB, amplitude, speed, lineWidth, interactive, bulgeRadius]);\n\n  useEffect(() => {\n    const canvas = ref.current!;\n    const ctx = canvas.getContext(\"2d\");\n    if (!ctx) return;\n    const area = canvas.parentElement ?? canvas;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const mouse = { x: 0, y: 0, on: 0, target: 0 };\n    let w = 0;\n    let h = 0;\n    let t = 2;\n    let raf = 0;\n    let last = 0;\n\n    const draw = (dt: number) => {\n      const o = opts.current;\n      t += dt * o.speed;\n      mouse.on += (mouse.target - mouse.on) * (1 - Math.exp(-dt * 5));\n      const bulge = o.interactive ? mouse.on : 0;\n      const r2 = o.bulgeRadius * o.bulgeRadius;\n      const soft = r2 * 0.05;\n      const n = Math.max(2, Math.round(o.count));\n      const step = 6;\n\n      ctx.clearRect(0, 0, w, h);\n      ctx.globalCompositeOperation = \"lighter\";\n      ctx.lineWidth = o.lineWidth;\n      for (let i = 0; i < n; i++) {\n        const f = i / (n - 1);\n        const c = o.a.map((v, k) => Math.round(v + (o.b[k] - v) * f));\n        ctx.strokeStyle = `rgba(${c[0]},${c[1]},${c[2]},${0.55 + 0.35 * Math.sin(t * 0.7 + i * 0.4) ** 2})`;\n        const y0 = ((i + 0.5) / n) * h;\n        ctx.beginPath();\n        for (let x = -step; x <= w + step; x += step) {\n          let y =\n            y0 +\n            o.amplitude *\n              (Math.sin(x * 0.0055 + t * 0.8 + i * 0.21) * 0.55 +\n                Math.sin(x * 0.012 - t * 0.55 + i * 0.09) * 0.3 +\n                Math.sin(x * 0.0021 + t * 0.3 - i * 0.13) * 0.6);\n          if (bulge > 0.001) {\n            const dx = x - mouse.x;\n            const dy = y - mouse.y;\n            const d2 = dx * dx + dy * dy;\n            if (d2 < r2 * 6) y += (dy / Math.sqrt(dy * dy + soft)) * Math.exp(-d2 / r2) * o.bulgeRadius * 0.7 * bulge;\n          }\n          if (x < 0) ctx.moveTo(x, y);\n          else ctx.lineTo(x, y);\n        }\n        ctx.stroke();\n      }\n    };\n\n    const loop = (now: number) => {\n      draw(last ? Math.min((now - last) / 1000, 0.1) : 0);\n      last = now;\n      raf = requestAnimationFrame(loop);\n    };\n\n    const resize = () => {\n      const dpr = Math.min(window.devicePixelRatio || 1, 2);\n      w = canvas.offsetWidth;\n      h = canvas.offsetHeight;\n      canvas.width = w * dpr;\n      canvas.height = h * dpr;\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      draw(0);\n    };\n\n    const onMove = (e: PointerEvent) => {\n      const r = canvas.getBoundingClientRect();\n      mouse.x = e.clientX - r.left;\n      mouse.y = e.clientY - r.top;\n      mouse.target = 1;\n    };\n    const onLeave = () => {\n      mouse.target = 0;\n    };\n\n    const ro = new ResizeObserver(resize);\n    ro.observe(canvas);\n    const io = new IntersectionObserver(([e]) => {\n      cancelAnimationFrame(raf);\n      raf = 0;\n      last = 0;\n      if (e.isIntersecting && !reduced) raf = requestAnimationFrame(loop);\n    });\n    io.observe(canvas);\n    redraw.current = () => {\n      if (!raf) draw(0);\n    };\n    area.addEventListener(\"pointermove\", onMove, { passive: true });\n    area.addEventListener(\"pointerleave\", onLeave);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      redraw.current = undefined;\n      area.removeEventListener(\"pointermove\", onMove);\n      area.removeEventListener(\"pointerleave\", onLeave);\n    };\n  }, []);\n\n  return (\n    <canvas\n      ref={ref}\n      aria-hidden\n      className={className}\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        width: \"100%\",\n        height: \"100%\",\n        pointerEvents: \"none\",\n        maskImage: \"linear-gradient(to right, transparent, #000 18%, #000 82%, transparent)\",\n        WebkitMaskImage: \"linear-gradient(to right, transparent, #000 18%, #000 82%, transparent)\",\n      }}\n    />\n  );\n}\n"}]}