{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hyperspeed",
  "type": "registry:component",
  "title": "Hyperspeed",
  "description": "A starfield tunnel: stars streak out from a vanishing point with blurred trails, and accelerate on press or boost.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "stars",
    "warp",
    "space",
    "tunnel",
    "canvas",
    "speed"
  ],
  "docs": "https://hyperblur.dev/effects/hyperspeed",
  "files": [
    {
      "path": "registry/hyperblur/hyperspeed.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/hyperspeed.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface HyperspeedProps extends React.HTMLAttributes<HTMLDivElement> {\n  color?: string;\n  accent?: string;\n  count?: number;\n  speed?: number;\n  boost?: boolean;\n  seed?: number;\n}\n\nconst css = `\n.hb-hsp { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }\n.hb-hsp-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }\n`;\n\nfunction rnd(i: number, salt: number, seed: number) {\n  let x = (Math.imul(i + 1, 2654435761) + Math.imul(salt + 1, 40503) + Math.imul(seed | 0, 2246822519)) >>> 0;\n  x = Math.imul((x >>> 16) ^ x, 0x45d9f3b);\n  x = Math.imul((x >>> 16) ^ x, 0x45d9f3b);\n  x = ((x >>> 16) ^ x) >>> 0;\n  return x / 4294967296;\n}\n\nfunction parseColor(ctx: CanvasRenderingContext2D, value: string): [number, number, number] {\n  ctx.fillStyle = \"#ffffff\";\n  ctx.fillStyle = value;\n  const s = String(ctx.fillStyle);\n  if (s[0] === \"#\") {\n    const n = parseInt(s.slice(1), 16);\n    return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n  }\n  const m = s.match(/[\\d.]+/g);\n  return m && m.length >= 3 ? [Math.round(+m[0]), Math.round(+m[1]), Math.round(+m[2])] : [255, 255, 255];\n}\n\nexport function Hyperspeed({\n  color = \"#ffffff\",\n  accent = \"#2f7bff\",\n  count = 300,\n  speed = 1,\n  boost = false,\n  seed = 1,\n  className = \"\",\n  style,\n  ...rest\n}: HyperspeedProps) {\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const boostRef = React.useRef(boost);\n  const speedRef = React.useRef(speed);\n\n  React.useEffect(() => {\n    boostRef.current = boost;\n    speedRef.current = speed;\n  }, [boost, speed]);\n\n  React.useEffect(() => {\n    const wrap = wrapRef.current;\n    const canvas = canvasRef.current;\n    const ctx = canvas ? canvas.getContext(\"2d\") : null;\n    if (!wrap || !canvas || !ctx) return;\n\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const total = Math.max(1, Math.round(count));\n    const main = parseColor(ctx, color);\n    const acc = parseColor(ctx, accent);\n    const palette = [`rgb(${main[0]},${main[1]},${main[2]})`, `rgb(${acc[0]},${acc[1]},${acc[2]})`];\n\n    const cosA = new Float32Array(total);\n    const sinA = new Float32Array(total);\n    const dist = new Float32Array(total);\n    const depth = new Float32Array(total);\n    const pace = new Float32Array(total);\n    const tint = new Uint8Array(total);\n\n    let spawned = 0;\n    const place = (i: number, fresh: boolean) => {\n      const n = fresh ? i : total + spawned++;\n      const a = rnd(n, 11, seed) * Math.PI * 2;\n      cosA[i] = Math.cos(a);\n      sinA[i] = Math.sin(a);\n      dist[i] = 0.2 + 0.8 * Math.sqrt(rnd(n, 12, seed));\n      pace[i] = 0.6 + 0.8 * rnd(n, 13, seed);\n      tint[i] = rnd(n, 14, seed) < 0.25 ? 1 : 0;\n      depth[i] = fresh ? 0.04 + 0.96 * rnd(n, 15, seed) : 1;\n    };\n\n    for (let i = 0; i < total; i++) place(i, true);\n\n    let w = 1;\n    let h = 1;\n    let dpr = 1;\n    let diag = 1;\n    let raf = 0;\n    let last = 0;\n    let visible = true;\n    let pressed = false;\n    let glow: CanvasGradient | null = null;\n    let cur = reduce.matches ? 2 : 1;\n\n    const draw = (dt: number) => {\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      ctx.clearRect(0, 0, w, h);\n      ctx.globalCompositeOperation = \"lighter\";\n      ctx.lineCap = \"round\";\n\n      const base = speedRef.current;\n      const target = boostRef.current || pressed ? 5 : 1;\n      cur += (target - cur) * (1 - Math.exp(-dt * 2.5));\n\n      const cx = w / 2;\n      const cy = h / 2;\n      const scale = diag * 0.04;\n      const reach = diag * 0.5;\n      const trail = 0.07;\n\n      if (glow) {\n        ctx.globalAlpha = Math.min(0.6, 0.14 + 0.12 * (cur - 1));\n        ctx.fillStyle = glow;\n        ctx.fillRect(0, 0, w, h);\n      }\n\n      let lastTint = -1;\n      for (let i = 0; i < total; i++) {\n        const rate = pace[i] * 0.32 * base * cur;\n        depth[i] -= rate * dt;\n        let z = depth[i];\n        let r = (dist[i] * scale) / z;\n        if (z <= 0.02 || r > reach) {\n          place(i, false);\n          z = depth[i];\n          r = (dist[i] * scale) / z;\n        }\n        const zp = Math.min(1.6, z + Math.max(0.01, rate * trail));\n        const rp = (dist[i] * scale) / zp;\n        const near = 1 - z;\n        const ca = cosA[i];\n        const sa = sinA[i];\n\n        if (tint[i] !== lastTint) {\n          lastTint = tint[i];\n          ctx.strokeStyle = palette[lastTint];\n        }\n        const alpha = Math.min(1, 0.15 + near * 1.1);\n        const lw = 0.5 + near * 1.6;\n        ctx.beginPath();\n        ctx.moveTo(cx + ca * rp, cy + sa * rp);\n        ctx.lineTo(cx + ca * r, cy + sa * r);\n        ctx.globalAlpha = alpha * 0.25;\n        ctx.lineWidth = lw * 3;\n        ctx.stroke();\n        ctx.globalAlpha = alpha;\n        ctx.lineWidth = lw;\n        ctx.stroke();\n      }\n\n      ctx.globalAlpha = 1;\n      ctx.globalCompositeOperation = \"source-over\";\n    };\n\n    const active = () => visible && !document.hidden && !reduce.matches;\n\n    const frame = (now: number) => {\n      raf = 0;\n      const dt = Math.min(0.05, (now - last) / 1000);\n      last = now;\n      draw(dt);\n      if (active()) raf = requestAnimationFrame(frame);\n    };\n\n    const sync = () => {\n      if (active()) {\n        if (!raf) {\n          last = performance.now();\n          raf = requestAnimationFrame(frame);\n        }\n      } else {\n        cancelAnimationFrame(raf);\n        raf = 0;\n        draw(0);\n      }\n    };\n\n    const resize = () => {\n      w = Math.max(1, wrap.clientWidth);\n      h = Math.max(1, wrap.clientHeight);\n      dpr = Math.min(2, window.devicePixelRatio || 1);\n      diag = Math.hypot(w, h);\n      canvas.width = Math.round(w * dpr);\n      canvas.height = Math.round(h * dpr);\n      const g = ctx.createRadialGradient(w / 2, h / 2, 0, w / 2, h / 2, diag * 0.35);\n      g.addColorStop(0, `rgba(${acc[0]},${acc[1]},${acc[2]},0.5)`);\n      g.addColorStop(0.4, `rgba(${acc[0]},${acc[1]},${acc[2]},0.12)`);\n      g.addColorStop(1, `rgba(${acc[0]},${acc[1]},${acc[2]},0)`);\n      glow = g;\n      draw(0);\n    };\n\n    const down = () => {\n      pressed = true;\n    };\n    const up = () => {\n      pressed = false;\n    };\n\n    const host = wrap.parentElement;\n    const ro = new ResizeObserver(resize);\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1].isIntersecting;\n      sync();\n    });\n\n    ro.observe(wrap);\n    io.observe(wrap);\n    document.addEventListener(\"visibilitychange\", sync);\n    reduce.addEventListener(\"change\", sync);\n    if (host) host.addEventListener(\"pointerdown\", down);\n    window.addEventListener(\"pointerup\", up);\n    window.addEventListener(\"pointercancel\", up);\n    resize();\n    sync();\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", sync);\n      reduce.removeEventListener(\"change\", sync);\n      if (host) host.removeEventListener(\"pointerdown\", down);\n      window.removeEventListener(\"pointerup\", up);\n      window.removeEventListener(\"pointercancel\", up);\n    };\n  }, [color, accent, count, seed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-hsp ${className}`} style={style} aria-hidden=\"true\" {...rest}>\n      <style href=\"hb-hyperspeed\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-hsp-canvas\" />\n    </div>\n  );\n}\n"
    }
  ]
}