{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"rope-curtain","type":"registry:ui","title":"Rope Curtain","description":"A curtain of hanging verlet ropes that sway in a soft breeze and part around the cursor.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/rope-curtain.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nexport interface RopeCurtainProps {\n  /** Number of hanging strands. */\n  count?: number;\n  /** Strand length as a fraction of the container height. */\n  length?: number;\n  /** Rope segments per strand. More is smoother. */\n  segments?: number;\n  color?: string;\n  tipColor?: string;\n  /** Line width in px. */\n  thickness?: number;\n  /** Strength of the idle breeze. */\n  sway?: number;\n  /** Px around the cursor that pushes strands aside. */\n  radius?: number;\n  className?: string;\n}\n\ntype P = { x: number; y: number; px: number; py: number };\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 RopeCurtain({\n  count = 56,\n  length = 0.72,\n  segments = 20,\n  color = \"#c6ff3d\",\n  tipColor = \"#22d3ee\",\n  thickness = 1.5,\n  sway = 1,\n  radius = 90,\n  className,\n}: RopeCurtainProps) {\n  const ref = useRef<HTMLCanvasElement>(null);\n\n  useEffect(() => {\n    const canvas = ref.current!;\n    const host = canvas.parentElement ?? canvas;\n    const ctx = canvas.getContext(\"2d\")!;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let w = 0;\n    let h = 0;\n    let raf = 0;\n    let visible = true;\n    let strands: { rest: number; pts: P[] }[] = [];\n    const mouse = { x: -1e4, y: -1e4, vx: 0, vy: 0 };\n    // Per-strand length jitter, fixed for the life of the effect.\n    const jitter = Array.from({ length: count }, () => 0.72 + Math.random() * 0.28);\n\n    const build = () => {\n      strands = jitter.map((j, i) => {\n        const x = ((i + 0.5) / count) * w;\n        const rest = (h * length * j) / segments;\n        return { rest, pts: Array.from({ length: segments + 1 }, (_, k) => ({ x, y: k * rest, px: x, py: k * rest })) };\n      });\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      build();\n      if (reduced) draw();\n    };\n\n    const simulate = (t: number) => {\n      const r2 = radius * radius;\n      for (const s of strands) {\n        const anchorX = s.pts[0].x;\n        const breeze = Math.sin(t * 0.9 + anchorX * 0.012) * 0.04 * sway + Math.sin(t * 2.3 + anchorX * 0.03) * 0.015 * sway;\n        for (let k = 1; k < s.pts.length; k++) {\n          const p = s.pts[k];\n          const vx = (p.x - p.px) * 0.97;\n          const vy = (p.y - p.py) * 0.97;\n          p.px = p.x;\n          p.py = p.y;\n          p.x += vx + breeze * (k / s.pts.length);\n          p.y += vy + 0.25;\n          const dx = p.x - mouse.x;\n          const dy = p.y - mouse.y;\n          const d2 = dx * dx + dy * dy;\n          if (d2 < r2 && d2 > 0.01) {\n            // Push out of the cursor's circle and carry some of its motion along.\n            const d = Math.sqrt(d2);\n            const f = 1 - d / radius;\n            p.x += (dx / d) * f * 3 + mouse.vx * f * 0.15;\n            p.y += (dy / d) * f * 3 + mouse.vy * f * 0.15;\n          }\n        }\n        for (let it = 0; it < 4; it++) {\n          for (let k = 1; k < s.pts.length; k++) {\n            const a = s.pts[k - 1];\n            const b = s.pts[k];\n            const dx = b.x - a.x;\n            const dy = b.y - a.y;\n            const d = Math.hypot(dx, dy) || 1;\n            const diff = (d - s.rest) / d;\n            // The anchor never moves; interior pairs share the correction.\n            if (k === 1) {\n              b.x -= dx * diff;\n              b.y -= dy * diff;\n            } else {\n              a.x += dx * diff * 0.5;\n              a.y += dy * diff * 0.5;\n              b.x -= dx * diff * 0.5;\n              b.y -= dy * diff * 0.5;\n            }\n          }\n        }\n      }\n      mouse.vx *= 0.8;\n      mouse.vy *= 0.8;\n    };\n\n    const draw = () => {\n      ctx.clearRect(0, 0, w, h);\n      const grad = ctx.createLinearGradient(0, 0, 0, h * length);\n      grad.addColorStop(0, `rgba(${hexToRgb(color)},0.06)`);\n      grad.addColorStop(0.35, color);\n      grad.addColorStop(1, tipColor);\n      ctx.strokeStyle = grad;\n      ctx.lineWidth = thickness;\n      ctx.lineCap = \"round\";\n      ctx.beginPath();\n      for (const s of strands) {\n        const p = s.pts;\n        ctx.moveTo(p[0].x, p[0].y);\n        for (let k = 1; k < p.length - 1; k++) ctx.quadraticCurveTo(p[k].x, p[k].y, (p[k].x + p[k + 1].x) / 2, (p[k].y + p[k + 1].y) / 2);\n        ctx.lineTo(p[p.length - 1].x, p[p.length - 1].y);\n      }\n      ctx.stroke();\n      ctx.fillStyle = tipColor;\n      ctx.beginPath();\n      for (const s of strands) {\n        const tip = s.pts[s.pts.length - 1];\n        ctx.moveTo(tip.x + thickness * 1.6, tip.y);\n        ctx.arc(tip.x, tip.y, thickness * 1.6, 0, Math.PI * 2);\n      }\n      ctx.fill();\n    };\n\n    const loop = (now: number) => {\n      simulate(now / 1000);\n      draw();\n      raf = visible ? requestAnimationFrame(loop) : 0;\n    };\n\n    const onMove = (e: PointerEvent) => {\n      const r = canvas.getBoundingClientRect();\n      const x = e.clientX - r.left;\n      const y = e.clientY - r.top;\n      if (mouse.x > -1e3) {\n        mouse.vx = x - mouse.x;\n        mouse.vy = y - mouse.y;\n      }\n      mouse.x = x;\n      mouse.y = y;\n    };\n    const onLeave = () => {\n      mouse.x = mouse.y = -1e4;\n    };\n\n    const ro = new ResizeObserver(resize);\n    ro.observe(canvas);\n    if (reduced) return () => ro.disconnect();\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible && !raf) raf = requestAnimationFrame(loop);\n    });\n    io.observe(canvas);\n    host.addEventListener(\"pointermove\", onMove, { passive: true });\n    host.addEventListener(\"pointerleave\", onLeave);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      host.removeEventListener(\"pointermove\", onMove);\n      host.removeEventListener(\"pointerleave\", onLeave);\n    };\n  }, [count, length, segments, color, tipColor, thickness, sway, radius]);\n\n  return (\n    <canvas\n      ref={ref}\n      aria-hidden\n      className={className}\n      style={{ position: \"absolute\", inset: 0, width: \"100%\", height: \"100%\" }}\n    />\n  );\n}\n"}]}