{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "warp-speed",
  "type": "registry:ui",
  "title": "Warp Speed",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "3D hyperspace starfield using perspective projection (`screenX = x / z`, `screenY = y / z`), delta-time streak rendering, a cursor-following vanishing point, and a warp jump accelerator.",
  "dependencies": [
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/warp-speed.tsx",
      "content": "\"use client\";\n\nimport React, { useEffect, useRef, useState } from \"react\";\nimport { Zap } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface WarpSpeedProps {\n  /** Base forward velocity. Default: 180 */\n  speed?: number;\n  /** Number of 3D stars in the tunnel. Default: 320 */\n  starCount?: number;\n  /** Streak tail multiplier. Default: 1.4 */\n  streakLength?: number;\n  /** Engage hyperspace warp jump (ramps speed up 5x). Default: false */\n  warp?: boolean;\n  /** Normalized vanishing point { x: 0..1, y: 0..1 }. Default: { x: 0.5, y: 0.5 } */\n  center?: { x: number; y: number };\n  /** Allow vanishing point to follow the cursor. Default: true */\n  followCursor?: boolean;\n  /** Optional foreground content */\n  children?: React.ReactNode;\n  className?: string;\n}\n\ninterface Star3D {\n  x: number;\n  y: number;\n  z: number;\n  pz: number;\n}\n\nexport function WarpSpeed({\n  speed = 180,\n  starCount = 320,\n  streakLength = 1.4,\n  warp = false,\n  center = { x: 0.5, y: 0.5 },\n  followCursor = true,\n  children,\n  className,\n}: WarpSpeedProps) {\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const [isWarping, setIsWarping] = useState(warp);\n  const vanishingRef = useRef({\n    x: center.x,\n    y: center.y,\n    targetX: center.x,\n    targetY: center.y,\n  });\n\n  useEffect(() => {\n    setIsWarping(warp);\n  }, [warp]);\n\n  useEffect(() => {\n    vanishingRef.current.targetX = center.x;\n    vanishingRef.current.targetY = center.y;\n  }, [center.x, center.y]);\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    if (!canvas) return;\n    const ctx = canvas.getContext(\"2d\");\n    if (!ctx) return;\n\n    let rafId: number;\n    let width = (canvas.width = canvas.offsetWidth || 600);\n    let height = (canvas.height = canvas.offsetHeight || 360);\n    const maxDepth = 1000;\n\n    const createStar = (): Star3D => {\n      const z = Math.random() * maxDepth + 1;\n      return {\n        x: (Math.random() - 0.5) * width * 2.2,\n        y: (Math.random() - 0.5) * height * 2.2,\n        z,\n        pz: z,\n      };\n    };\n\n    const stars: Star3D[] = Array.from({ length: starCount }, createStar);\n    let currentVelocity = speed;\n\n    const handleResize = () => {\n      if (!canvas) return;\n      width = canvas.width = canvas.offsetWidth || 600;\n      height = canvas.height = canvas.offsetHeight || 360;\n    };\n\n    window.addEventListener(\"resize\", handleResize);\n\n    let last = performance.now();\n    const render = (now: number) => {\n      const dt = Math.min(0.05, (now - last) / 1000);\n      last = now;\n\n      // Smoothly ramp velocity up or down for warp jump\n      const targetVelocity = isWarping ? speed * 5.2 : speed;\n      currentVelocity += (targetVelocity - currentVelocity) * 0.08;\n\n      // Smoothly interpolate vanishing point\n      vanishingRef.current.x +=\n        (vanishingRef.current.targetX - vanishingRef.current.x) * 0.08;\n      vanishingRef.current.y +=\n        (vanishingRef.current.targetY - vanishingRef.current.y) * 0.08;\n\n      const cx = vanishingRef.current.x * width;\n      const cy = vanishingRef.current.y * height;\n      const focal = Math.min(width, height) * 0.65;\n\n      ctx.fillStyle = isWarping\n        ? \"rgba(3, 5, 12, 0.32)\"\n        : \"rgba(3, 5, 12, 0.55)\";\n      ctx.fillRect(0, 0, width, height);\n\n      for (let i = 0; i < stars.length; i++) {\n        const s = stars[i];\n        s.pz = s.z + currentVelocity * dt * streakLength * (isWarping ? 2.8 : 1);\n        s.z -= currentVelocity * dt;\n\n        if (s.z <= 2) {\n          s.x = (Math.random() - 0.5) * width * 2.2;\n          s.y = (Math.random() - 0.5) * height * 2.2;\n          s.z = maxDepth;\n          s.pz = maxDepth;\n          continue;\n        }\n\n        // 3D perspective projection: screenX = (x / z) * focal + cx\n        const sx = (s.x / s.z) * focal + cx;\n        const sy = (s.y / s.z) * focal + cy;\n        const px = (s.x / s.pz) * focal + cx;\n        const py = (s.y / s.pz) * focal + cy;\n\n        const depthRatio = 1 - s.z / maxDepth;\n        const alpha = Math.max(0.08, Math.min(1, depthRatio * 1.2));\n        const lineWidth = Math.max(0.6, depthRatio * (isWarping ? 2.8 : 2.0));\n\n        ctx.strokeStyle = isWarping\n          ? `rgba(186, 230, 253, ${alpha.toFixed(3)})`\n          : `rgba(255, 255, 255, ${alpha.toFixed(3)})`;\n        ctx.lineWidth = lineWidth;\n        ctx.lineCap = \"round\";\n        ctx.beginPath();\n        ctx.moveTo(px, py);\n        ctx.lineTo(sx, sy);\n        ctx.stroke();\n      }\n\n      rafId = requestAnimationFrame(render);\n    };\n\n    rafId = requestAnimationFrame(render);\n    return () => {\n      cancelAnimationFrame(rafId);\n      window.removeEventListener(\"resize\", handleResize);\n    };\n  }, [speed, starCount, streakLength, isWarping]);\n\n  return (\n    <div\n      data-fullscreen-scroll\n      onMouseMove={(e) => {\n        if (!followCursor) return;\n        const rect = e.currentTarget.getBoundingClientRect();\n        vanishingRef.current.targetX = (e.clientX - rect.left) / rect.width;\n        vanishingRef.current.targetY = (e.clientY - rect.top) / rect.height;\n      }}\n      onMouseLeave={() => {\n        if (!followCursor) return;\n        vanishingRef.current.targetX = center.x;\n        vanishingRef.current.targetY = center.y;\n      }}\n      className={cn(\n        \"relative flex min-h-[360px] w-full flex-col justify-between overflow-hidden rounded-3xl border border-neutral-800 bg-[#03050C] p-6 text-white shadow-sm\",\n        className\n      )}\n    >\n      <canvas\n        ref={canvasRef}\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0 h-full w-full\"\n      />\n\n      <div className=\"relative z-10 flex flex-1 flex-col justify-between\">\n        {children ?? (\n          <>\n            <div className=\"flex flex-wrap items-center justify-between gap-2\">\n              <span className=\"inline-flex items-center gap-1.5 rounded-full border border-white/15 bg-black/40 px-3 py-1 font-mono text-[11px] font-medium text-white backdrop-blur-md\">\n                <Zap className=\"h-3.5 w-3.5 text-sky-400\" />\n                Warp Speed · {isWarping ? \"HYPERSPACE\" : \"SUBLIGHT\"}\n              </span>\n\n              <button\n                type=\"button\"\n                onClick={() => setIsWarping((w) => !w)}\n                className={cn(\n                  \"inline-flex items-center gap-1.5 rounded-full border px-3.5 py-1 font-mono text-xs font-semibold transition-all active:scale-95\",\n                  isWarping\n                    ? \"border-sky-400 bg-sky-400 text-black shadow-[0_0_20px_rgba(56,189,248,0.6)]\"\n                    : \"border-white/20 bg-white/10 text-white backdrop-blur-md hover:bg-white/20\"\n                )}\n              >\n                <Zap className=\"h-3 w-3\" />\n                <span>{isWarping ? \"Disengage Warp\" : \"Engage Warp Jump\"}</span>\n              </button>\n            </div>\n\n            <div className=\"my-auto max-w-md py-8\">\n              <h3 className=\"text-2xl font-bold tracking-tight text-white sm:text-3xl\">\n                3D Hyperspace Projection\n              </h3>\n              <p className=\"mt-2 text-xs leading-relaxed text-white/75 sm:text-sm\">\n                Projects 3D star coordinates via{\" \"}\n                <code className=\"font-mono text-sky-300\">screenX = x / z</code>{\" \"}\n                with cursor-steered vanishing point and velocity streak ramps.\n              </p>\n            </div>\n\n            <div className=\"font-mono text-[11px] text-white/50\">\n              Move cursor to steer vanishing point · Click button to jump\n            </div>\n          </>\n        )}\n      </div>\n    </div>\n  );\n}\n\nexport default WarpSpeed;\n",
      "type": "registry:ui",
      "target": "components/ui/warp-speed.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
