{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-color-bends",
  "type": "registry:component",
  "title": "Color Bends",
  "description": "Saturated ribbons of color that flow across the area, twisting as they go and bending around a warp field that follows the pointer.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "ribbons",
    "gradient",
    "warp",
    "canvas",
    "pointer"
  ],
  "docs": "https://hyperblur.dev/effects/bg-color-bends",
  "files": [
    {
      "path": "registry/hyperblur/bg-color-bends.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-color-bends.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgColorBendsProps extends React.HTMLAttributes<HTMLDivElement> {\n  colors?: string[];\n  background?: string;\n  bands?: number;\n  thickness?: number;\n  warp?: number;\n  speed?: number;\n  children?: React.ReactNode;\n}\n\nconst css = `\n.hb-qp5 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; box-sizing: border-box; }\n.hb-qp5-c { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }\n.hb-qp5-in { position: relative; z-index: 1; width: 100%; height: 100%; pointer-events: auto; font-family: inherit; }\n`;\n\nconst defaultColors = [\"#ff2e88\", \"#ff7a1a\", \"#ffd60a\", \"#21e6a5\", \"#1f8bff\", \"#8b3dff\"];\n\nfunction rnd(i: number) {\n  let x = Math.imul(i ^ 0x9e3779b9, 0x85ebca6b);\n  x ^= x >>> 13;\n  x = Math.imul(x, 0xc2b2ae35);\n  x ^= x >>> 16;\n  return (x >>> 0) / 4294967296;\n}\n\nexport function BgColorBends({\n  colors = defaultColors,\n  background = \"#07070a\",\n  bands = 6,\n  thickness = 1,\n  warp = 1,\n  speed = 1,\n  children,\n  className = \"\",\n  style,\n  ...rest\n}: BgColorBendsProps) {\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const colorKey = (colors.length ? colors : defaultColors).join(\"|\");\n\n  React.useEffect(() => {\n    const wrap = wrapRef.current;\n    const host = wrap?.parentElement;\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    if (!wrap || !host || !canvas || !ctx) return;\n\n    const motion = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const palette = colorKey.split(\"|\");\n    const B = Math.max(1, Math.min(14, Math.round(bands)));\n    const SEG = 56;\n    const cxs = new Float32Array(SEG + 1);\n    const cys = new Float32Array(SEG + 1);\n    const tws = new Float32Array(SEG + 1);\n    const ex = new Float32Array((SEG + 1) * 2);\n    const ey = new Float32Array((SEG + 1) * 2);\n\n    let w = 0;\n    let h = 0;\n    let t = 0;\n    let inside = false;\n    let tx = 0;\n    let ty = 0;\n    let px = 0;\n    let py = 0;\n    let placed = false;\n    let pull = 0;\n    let visible = true;\n    let raf = 0;\n    let prev = 0;\n\n    function idleX(tt: number) {\n      return w * (0.5 + 0.34 * Math.sin(tt * 0.27 + 0.8));\n    }\n    function idleY(tt: number) {\n      return h * (0.5 + 0.28 * Math.sin(tt * 0.43 + 2.2));\n    }\n\n    function track(dt: number) {\n      const gx = inside ? tx : idleX(t);\n      const gy = inside ? ty : idleY(t);\n      if (!placed || dt === 0) {\n        px = gx;\n        py = gy;\n        placed = true;\n        pull = inside ? 1 : 0.6;\n        return;\n      }\n      const k = 1 - Math.exp(-dt * (inside ? 4.5 : 1.5));\n      px += (gx - px) * k;\n      py += (gy - py) * k;\n      pull += ((inside ? 1 : 0.6) - pull) * Math.min(1, dt * 2.5);\n    }\n\n    function draw() {\n      if (!w || !h) return;\n      ctx!.globalCompositeOperation = \"source-over\";\n      ctx!.globalAlpha = 1;\n      ctx!.fillStyle = background;\n      ctx!.fillRect(0, 0, w, h);\n\n      const span = w + 160;\n      const rad = Math.max(w, h) * 0.32;\n      const rad2 = rad * rad;\n      const strength = 1.5 * warp * pull;\n      const baseHalf = (h / (B + 1)) * 0.42 * thickness;\n\n      for (let b = 0; b < B; b++) {\n        const seed = b * 11 + 5;\n        const base = h * ((b + 1) / (B + 1)) + (rnd(seed) - 0.5) * h * 0.06;\n        const amp = h * (0.08 + 0.08 * rnd(seed + 1));\n        const fq = (1.2 + 1.4 * rnd(seed + 2)) / span;\n        const ph = rnd(seed + 3) * 6.28;\n        const tf = 0.25 + 0.35 * rnd(seed + 4);\n        const twf = (2 + 3 * rnd(seed + 5)) / span;\n        const sp = (b % 2 === 0 ? 1 : -1) * (0.3 + 0.4 * rnd(seed + 6));\n\n        for (let i = 0; i <= SEG; i++) {\n          const x = -80 + (span * i) / SEG;\n          let y =\n            base +\n            Math.sin(x * fq * 6.283 + t * tf + ph) * amp +\n            Math.sin(x * fq * 14.1 - t * tf * 1.3 + ph * 2) * amp * 0.3;\n          const dx = x - px;\n          const dy = y - py;\n          const g = Math.exp(-(dx * dx + dy * dy) / rad2);\n          const ang = g * strength * (b % 2 === 0 ? 1 : -1);\n          const ca = Math.cos(ang);\n          const sa = Math.sin(ang);\n          const rx = px + dx * ca - dy * sa;\n          y = py + dx * sa + dy * ca;\n          cxs[i] = rx;\n          cys[i] = y;\n          tws[i] = Math.cos(x * twf * 6.283 + t * sp + ph + g * 3 * warp);\n        }\n\n        for (let i = 0; i <= SEG; i++) {\n          const a = i > 0 ? i - 1 : i;\n          const c = i < SEG ? i + 1 : i;\n          let nx = -(cys[c] - cys[a]);\n          let ny = cxs[c] - cxs[a];\n          const l = Math.hypot(nx, ny) || 1;\n          nx /= l;\n          ny /= l;\n          const half = baseHalf * (0.18 + 0.82 * Math.abs(tws[i]));\n          ex[i * 2] = cxs[i] + nx * half;\n          ey[i * 2] = cys[i] + ny * half;\n          ex[i * 2 + 1] = cxs[i] - nx * half;\n          ey[i * 2 + 1] = cys[i] - ny * half;\n        }\n\n        const c0 = palette[b % palette.length];\n        const c1 = palette[(b + 1) % palette.length];\n        const c2 = palette[(b + 2) % palette.length];\n        const grad = ctx!.createLinearGradient(0, 0, w, 0);\n        grad.addColorStop(0, c0);\n        grad.addColorStop(0.55, c1);\n        grad.addColorStop(1, c2);\n\n        ctx!.globalAlpha = 0.92;\n        ctx!.fillStyle = grad;\n        ctx!.beginPath();\n        ctx!.moveTo(ex[0], ey[0]);\n        for (let i = 1; i <= SEG; i++) ctx!.lineTo(ex[i * 2], ey[i * 2]);\n        for (let i = SEG; i >= 0; i--) ctx!.lineTo(ex[i * 2 + 1], ey[i * 2 + 1]);\n        ctx!.closePath();\n        ctx!.fill();\n\n        const shadeGrad = ctx!.createLinearGradient(-80, 0, w + 80, 0);\n        const shineGrad = ctx!.createLinearGradient(-80, 0, w + 80, 0);\n        let last = 0;\n        for (let i = 0; i <= SEG; i++) {\n          const m = tws[i];\n          const am = Math.abs(m);\n          const shade = Math.min(0.72, (1 - am) * 0.62 + (m < 0 ? 0.12 : 0));\n          const shine = am > 0.86 ? Math.min(0.32, (am - 0.86) * 2.2) : 0;\n          last = Math.max(last, Math.min(1, Math.max(0, (cxs[i] + 80) / (w + 160))));\n          shadeGrad.addColorStop(last, `rgba(0,0,0,${shade.toFixed(3)})`);\n          shineGrad.addColorStop(last, `rgba(255,255,255,${shine.toFixed(3)})`);\n        }\n        ctx!.globalAlpha = 1;\n        ctx!.fillStyle = shadeGrad;\n        ctx!.fill();\n        ctx!.fillStyle = shineGrad;\n        ctx!.fill();\n      }\n\n      const vg = ctx!.createRadialGradient(w / 2, h / 2, Math.min(w, h) * 0.3, w / 2, h / 2, Math.max(w, h) * 0.75);\n      vg.addColorStop(0, \"rgba(0,0,0,0)\");\n      vg.addColorStop(1, background);\n      ctx!.globalAlpha = 0.85;\n      ctx!.fillStyle = vg;\n      ctx!.fillRect(0, 0, w, h);\n      ctx!.globalAlpha = 1;\n    }\n\n    function still() {\n      t = 5;\n      inside = false;\n      placed = false;\n      track(0);\n      draw();\n    }\n\n    function resize() {\n      if (!wrap || !canvas || !ctx) return;\n      const nw = wrap.clientWidth;\n      const nh = wrap.clientHeight;\n      if (!nw || !nh) return;\n      const dpr = Math.min(2, window.devicePixelRatio || 1);\n      w = nw;\n      h = nh;\n      canvas.width = Math.max(1, Math.round(w * dpr));\n      canvas.height = Math.max(1, Math.round(h * dpr));\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      if (motion.matches) still();\n      else {\n        track(0);\n        draw();\n      }\n    }\n\n    function frame(now: number) {\n      const dt = Math.min(0.033, (now - prev) / 1000);\n      prev = now;\n      t += dt * speed;\n      track(dt);\n      draw();\n      raf = requestAnimationFrame(frame);\n    }\n\n    function sync() {\n      const run = visible && !document.hidden && !motion.matches;\n      if (run && !raf) {\n        prev = performance.now();\n        raf = requestAnimationFrame(frame);\n      } else if (!run && raf) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n      if (motion.matches) still();\n    }\n\n    function move(e: PointerEvent) {\n      if (!host || motion.matches) return;\n      const rect = host.getBoundingClientRect();\n      const sx = rect.width ? host.clientWidth / rect.width : 1;\n      const sy = rect.height ? host.clientHeight / rect.height : 1;\n      tx = (e.clientX - rect.left) * sx;\n      ty = (e.clientY - rect.top) * sy;\n      inside = true;\n    }\n\n    function leave(e: PointerEvent) {\n      if (e.type === \"pointerup\" && e.pointerType === \"mouse\") return;\n      inside = false;\n    }\n\n    const ro = new ResizeObserver(resize);\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1].isIntersecting;\n      sync();\n    });\n    ro.observe(wrap);\n    io.observe(wrap);\n    document.addEventListener(\"visibilitychange\", sync);\n    motion.addEventListener(\"change\", sync);\n    host.addEventListener(\"pointermove\", move, { passive: true });\n    host.addEventListener(\"pointerdown\", move, { passive: true });\n    host.addEventListener(\"pointerleave\", leave);\n    host.addEventListener(\"pointerup\", leave);\n    host.addEventListener(\"pointercancel\", leave);\n    resize();\n    sync();\n\n    return () => {\n      if (raf) cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", sync);\n      motion.removeEventListener(\"change\", sync);\n      host.removeEventListener(\"pointermove\", move);\n      host.removeEventListener(\"pointerdown\", move);\n      host.removeEventListener(\"pointerleave\", leave);\n      host.removeEventListener(\"pointerup\", leave);\n      host.removeEventListener(\"pointercancel\", leave);\n    };\n  }, [colorKey, background, bands, thickness, warp, speed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-qp5 ${className}`} style={style} {...rest}>\n      <style href=\"hb-bg-color-bends\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-qp5-c\" aria-hidden=\"true\" />\n      {children ? <div className=\"hb-qp5-in\">{children}</div> : null}\n    </div>\n  );\n}\n"
    }
  ]
}