{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cursor-ribbons",
  "type": "registry:component",
  "title": "Cursor Ribbons",
  "description": "Several glowing ribbons chase the pointer through spring-chained segments, taper to a point and blend where they cross.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "hover",
    "cursor",
    "ribbons",
    "trail",
    "spring",
    "glow",
    "canvas"
  ],
  "docs": "https://hyperblur.dev/effects/cursor-ribbons",
  "files": [
    {
      "path": "registry/hyperblur/cursor-ribbons.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/cursor-ribbons.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface CursorRibbonsProps extends React.HTMLAttributes<HTMLDivElement> {\n  colors?: string[];\n  count?: number;\n  length?: number;\n  width?: number;\n  idle?: boolean;\n}\n\nconst css = `\n.hb-qi5 { position: relative; width: 100%; height: 100%; overflow: hidden; box-sizing: border-box; isolation: isolate; font-family: inherit; }\n.hb-qi5 *, .hb-qi5 *::before, .hb-qi5 *::after { box-sizing: border-box; }\n.hb-qi5-canvas { position: absolute; inset: 0; z-index: 0; display: block; width: 100%; height: 100%; pointer-events: none; }\n.hb-qi5-content { position: relative; z-index: 1; width: 100%; height: 100%; }\n`;\n\nconst defaultColors = [\"#2f7bff\", \"#7fb3ff\", \"#c084fc\", \"#22d3ee\"];\n\nexport function CursorRibbons({\n  colors = defaultColors,\n  count = 4,\n  length = 26,\n  width = 7,\n  idle = true,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: CursorRibbonsProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const palette = colors.length ? colors.join(\"|\") : defaultColors.join(\"|\");\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    if (!root || !canvas || !ctx) return;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const list = palette.split(\"|\");\n    const rn = Math.max(1, Math.min(10, Math.floor(count)));\n    const len = Math.max(4, Math.min(80, Math.floor(length)));\n    const pts = Array.from({ length: rn }, () => new Float32Array(len * 2));\n    const lx = new Float32Array(len);\n    const ly = new Float32Array(len);\n    const rx = new Float32Array(len);\n    const ry = new Float32Array(len);\n    let w = 0;\n    let h = 0;\n    let px = 0;\n    let py = 0;\n    let active = false;\n    let mix = 0;\n    let raf = 0;\n    let last = 0;\n    let t = 0;\n    let visible = true;\n    let placed = false;\n\n    const step = (dt: number) => {\n      t += dt;\n      mix += ((active ? 1 : 0) - mix) * (1 - Math.exp(-dt * 3.5));\n      const ix = idle ? w * (0.5 + 0.34 * Math.sin(t * 0.62) + 0.05 * Math.sin(t * 2.1)) : px;\n      const iy = idle ? h * (0.5 + 0.28 * Math.sin(t * 1.24 + 0.3)) : py;\n      const tx = ix + (px - ix) * mix;\n      const ty = iy + (py - iy) * mix;\n      for (let r = 0; r < rn; r++) {\n        const p = pts[r];\n        const orbit = 4 + r * 5;\n        const ang = t * (2.2 + r * 0.55) + r * 1.9;\n        const hx = tx + Math.cos(ang) * orbit;\n        const hy = ty + Math.sin(ang * 1.3) * orbit;\n        const kh = 1 - Math.exp(-dt * (16 - r * 1.5));\n        p[0] += (hx - p[0]) * kh;\n        p[1] += (hy - p[1]) * kh;\n        const kf = 1 - Math.exp(-dt * (36 - r * 3));\n        for (let j = 1; j < len; j++) {\n          p[j * 2] += (p[(j - 1) * 2] - p[j * 2]) * kf;\n          p[j * 2 + 1] += (p[(j - 1) * 2 + 1] - p[j * 2 + 1]) * kf;\n        }\n      }\n    };\n\n    const ribbon = (p: Float32Array, half: number) => {\n      let nx = 0;\n      let ny = 1;\n      for (let j = 0; j < len; j++) {\n        const a = j === 0 ? 0 : j - 1;\n        const b = j === len - 1 ? len - 1 : j + 1;\n        const dx = p[b * 2] - p[a * 2];\n        const dy = p[b * 2 + 1] - p[a * 2 + 1];\n        const d = Math.hypot(dx, dy);\n        if (d > 0.0001) {\n          nx = -dy / d;\n          ny = dx / d;\n        }\n        const taper = half * Math.pow(1 - j / len, 0.9) + 0.3;\n        lx[j] = p[j * 2] + nx * taper;\n        ly[j] = p[j * 2 + 1] + ny * taper;\n        rx[j] = p[j * 2] - nx * taper;\n        ry[j] = p[j * 2 + 1] - ny * taper;\n      }\n      ctx.beginPath();\n      ctx.moveTo(lx[0], ly[0]);\n      for (let j = 1; j < len; j++) ctx.lineTo(lx[j], ly[j]);\n      for (let j = len - 1; j >= 0; j--) ctx.lineTo(rx[j], ry[j]);\n      ctx.closePath();\n      ctx.fill();\n    };\n\n    const draw = () => {\n      ctx.clearRect(0, 0, w, h);\n      ctx.globalCompositeOperation = \"lighter\";\n      for (let r = 0; r < rn; r++) {\n        const p = pts[r];\n        const g = ctx.createLinearGradient(p[0], p[1], p[(len - 1) * 2], p[(len - 1) * 2 + 1]);\n        const c = list[r % list.length];\n        g.addColorStop(0, c);\n        g.addColorStop(1, \"rgba(0,0,0,0)\");\n        const bw = width * (1 - r * 0.08);\n        ctx.fillStyle = g;\n        ctx.globalAlpha = 0.18;\n        ribbon(p, bw * 1.6);\n        ctx.globalAlpha = 0.85;\n        ribbon(p, bw * 0.5);\n        ctx.globalAlpha = 1;\n        ctx.fillStyle = c;\n        ctx.beginPath();\n        ctx.arc(p[0], p[1], bw * 0.5, 0, Math.PI * 2);\n        ctx.fill();\n      }\n      ctx.globalAlpha = 1;\n      ctx.globalCompositeOperation = \"source-over\";\n    };\n\n    const place = (x: number, y: number) => {\n      for (const p of pts) {\n        for (let j = 0; j < len; j++) {\n          p[j * 2] = x - j * 3;\n          p[j * 2 + 1] = y;\n        }\n      }\n    };\n\n    const frame = (now: number) => {\n      const dt = Math.min(0.033, Math.max(0.001, (now - last) / 1000));\n      last = now;\n      step(dt);\n      draw();\n      raf = requestAnimationFrame(frame);\n    };\n\n    const start = () => {\n      if (raf || reduced || !visible || !w) return;\n      last = performance.now();\n      raf = requestAnimationFrame(frame);\n    };\n    const stop = () => {\n      if (raf) cancelAnimationFrame(raf);\n      raf = 0;\n    };\n\n    const resize = () => {\n      const nw = root.clientWidth;\n      const nh = root.clientHeight;\n      if (!nw || !nh) return;\n      w = nw;\n      h = nh;\n      const dpr = Math.min(2, window.devicePixelRatio || 1);\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 (!placed) {\n        placed = true;\n        px = w / 2;\n        py = h / 2;\n        place(idle ? w * 0.5 : px, idle ? h * (0.5 + 0.28 * Math.sin(0.3)) : py);\n      }\n      if (reduced) {\n        if (idle) {\n          for (let i = 0; i < 80; i++) step(1 / 60);\n        }\n        draw();\n      } else {\n        start();\n      }\n    };\n\n    const onMove = (e: PointerEvent) => {\n      const r = root.getBoundingClientRect();\n      const s = r.width ? w / r.width : 1;\n      px = (e.clientX - r.left) * s;\n      py = (e.clientY - r.top) * s;\n      active = true;\n    };\n    const onLeave = () => {\n      active = false;\n    };\n    const onUp = (e: PointerEvent) => {\n      if (e.pointerType === \"touch\") onLeave();\n    };\n\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerdown\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"pointercancel\", onLeave);\n    root.addEventListener(\"pointerup\", onUp);\n    const ro = new ResizeObserver(resize);\n    ro.observe(root);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) start();\n      else stop();\n    });\n    io.observe(root);\n    resize();\n\n    return () => {\n      stop();\n      ro.disconnect();\n      io.disconnect();\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerdown\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      root.removeEventListener(\"pointercancel\", onLeave);\n      root.removeEventListener(\"pointerup\", onUp);\n    };\n  }, [palette, count, length, width, idle]);\n\n  return (\n    <div ref={rootRef} className={`hb-qi5 ${className}`} style={style} {...rest}>\n      <style href=\"hb-cursor-ribbons\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-qi5-canvas\" aria-hidden=\"true\" />\n      <div className=\"hb-qi5-content\">{children}</div>\n    </div>\n  );\n}\n"
    }
  ]
}