{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-radar",
  "type": "registry:component",
  "title": "Radar Scope",
  "description": "A phosphor radar display with range rings, bearing ticks and a rotating sweep. Contacts flare as the beam passes and fade until the next turn, some with track labels.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "radar",
    "sweep",
    "hud",
    "canvas",
    "tracking"
  ],
  "docs": "https://hyperblur.dev/effects/bg-radar",
  "files": [
    {
      "path": "registry/hyperblur/bg-radar.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-radar.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgRadarProps extends React.HTMLAttributes<HTMLDivElement> {\n  color?: string;\n  accent?: string;\n  background?: string;\n  origin?: [number, number];\n  size?: number;\n  targets?: number;\n  labels?: boolean;\n  speed?: number;\n  children?: React.ReactNode;\n}\n\nconst css = `\n.hb-ve14 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; box-sizing: border-box; }\n.hb-ve14-c { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }\n.hb-ve14-in { position: relative; z-index: 1; width: 100%; height: 100%; pointer-events: auto; font-family: inherit; }\n`;\n\nfunction rgbOf(value: string, fallback: [number, number, number]): [number, number, number] {\n  const raw = value.trim().replace(\"#\", \"\");\n  const hex = raw.length === 3 ? raw.split(\"\").map((c) => c + c).join(\"\") : raw;\n  const n = parseInt(hex.slice(0, 6), 16);\n  if (hex.length < 6 || Number.isNaN(n)) return fallback;\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\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\nconst TAU = Math.PI * 2;\n\nexport function BgRadar({\n  color = \"#1f3a33\",\n  accent = \"#4dffb4\",\n  background = \"#030806\",\n  origin = [0.5, 0.5],\n  size = 1,\n  targets = 9,\n  labels = true,\n  speed = 1,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: BgRadarProps) {\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const ox = origin[0];\n  const oy = origin[1];\n\n  React.useEffect(() => {\n    const wrap = wrapRef.current;\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    if (!wrap || !canvas || !ctx) return;\n    const g: CanvasRenderingContext2D = ctx;\n    const el: HTMLDivElement = wrap;\n    const cv: HTMLCanvasElement = canvas;\n    const scope = document.createElement(\"canvas\");\n    const sctx = scope.getContext(\"2d\");\n    if (!sctx) return;\n    const S: CanvasRenderingContext2D = sctx;\n\n    const lc = rgbOf(color, [31, 58, 51]);\n    const ac = rgbOf(accent, [77, 255, 180]);\n    const mono = getComputedStyle(document.documentElement).getPropertyValue(\"--font-mono\").trim();\n    const family = `${mono ? mono + \", \" : \"\"}ui-monospace, SFMono-Regular, Menlo, monospace`;\n    const sprite = document.createElement(\"canvas\");\n    sprite.width = 48;\n    sprite.height = 48;\n    const spc = sprite.getContext(\"2d\");\n    if (spc) {\n      const rg = spc.createRadialGradient(24, 24, 0, 24, 24, 24);\n      rg.addColorStop(0, `rgba(${ac[0]},${ac[1]},${ac[2]},1)`);\n      rg.addColorStop(0.2, `rgba(${ac[0]},${ac[1]},${ac[2]},0.45)`);\n      rg.addColorStop(1, `rgba(${ac[0]},${ac[1]},${ac[2]},0)`);\n      spc.fillStyle = rg;\n      spc.fillRect(0, 0, 48, 48);\n    }\n\n    const nt = Math.max(0, Math.min(40, Math.round(targets)));\n    const tg = Array.from({ length: nt }, (_, i) => ({\n      r: 0.14 + rnd(i * 6 + 1) * 0.8,\n      a: rnd(i * 6 + 2) * TAU,\n      vr: (rnd(i * 6 + 3) - 0.5) * 0.006,\n      va: (rnd(i * 6 + 4) - 0.5) * 0.02,\n      id: 100 + Math.floor(rnd(i * 6 + 5) * 899),\n      hit: -99,\n      last: 0,\n    }));\n\n    let w = 0;\n    let h = 0;\n    let t = 0;\n    let cx = 0;\n    let cy = 0;\n    let R = 0;\n    let primed = false;\n\n    function paintScope(dpr: number) {\n      scope.width = Math.max(1, Math.round(w * dpr));\n      scope.height = Math.max(1, Math.round(h * dpr));\n      S.setTransform(dpr, 0, 0, dpr, 0, 0);\n      S.clearRect(0, 0, w, h);\n      const line = `rgb(${lc[0]},${lc[1]},${lc[2]})`;\n      S.strokeStyle = line;\n      S.lineWidth = 1;\n      for (let i = 1; i <= 5; i++) {\n        S.globalAlpha = i === 5 ? 1 : 0.7;\n        S.beginPath();\n        S.arc(cx, cy, (R * i) / 5, 0, TAU);\n        S.stroke();\n      }\n      S.globalAlpha = 0.5;\n      S.setLineDash([2, 4]);\n      for (let i = 0; i < 12; i++) {\n        const a = (i * TAU) / 12;\n        S.beginPath();\n        S.moveTo(cx + Math.cos(a) * R * 0.2, cy + Math.sin(a) * R * 0.2);\n        S.lineTo(cx + Math.cos(a) * R, cy + Math.sin(a) * R);\n        S.stroke();\n      }\n      S.setLineDash([]);\n      S.globalAlpha = 1;\n      for (let d = 0; d < 360; d += 2) {\n        const a = (d * Math.PI) / 180 - Math.PI / 2;\n        const major = d % 10 === 0;\n        const r0 = R * (major ? 0.965 : 0.982);\n        S.globalAlpha = major ? 0.95 : 0.5;\n        S.beginPath();\n        S.moveTo(cx + Math.cos(a) * r0, cy + Math.sin(a) * r0);\n        S.lineTo(cx + Math.cos(a) * R, cy + Math.sin(a) * R);\n        S.stroke();\n      }\n      S.globalAlpha = 0.85;\n      S.fillStyle = `rgb(${Math.min(255, lc[0] + 60)},${Math.min(255, lc[1] + 80)},${Math.min(255, lc[2] + 70)})`;\n      S.font = `500 9px ${family}`;\n      S.textAlign = \"center\";\n      S.textBaseline = \"middle\";\n      for (let d = 0; d < 360; d += 30) {\n        const a = (d * Math.PI) / 180 - Math.PI / 2;\n        S.fillText(String(d).padStart(3, \"0\"), cx + Math.cos(a) * R * 0.92, cy + Math.sin(a) * R * 0.92);\n      }\n      S.textAlign = \"left\";\n      for (let i = 1; i < 5; i++) S.fillText(`${i * 10}`, cx + 4, cy - (R * i) / 5 - 6);\n      S.globalAlpha = 1;\n    }\n\n    function render(dt: number) {\n      if (!w || !h) return;\n      g.fillStyle = background;\n      g.fillRect(0, 0, w, h);\n      const vg = g.createRadialGradient(cx, cy, 0, cx, cy, R * 1.05);\n      vg.addColorStop(0, `rgba(${ac[0]},${ac[1]},${ac[2]},0.06)`);\n      vg.addColorStop(1, \"rgba(0,0,0,0)\");\n      g.fillStyle = vg;\n      g.fillRect(0, 0, w, h);\n      g.drawImage(scope, 0, 0, w, h);\n      const sweep = (t * 0.85) % TAU;\n      const trail = 1.25;\n      if (typeof g.createConicGradient === \"function\") {\n        const grad = g.createConicGradient(sweep - trail, cx, cy);\n        const f = trail / TAU;\n        grad.addColorStop(0, `rgba(${ac[0]},${ac[1]},${ac[2]},0)`);\n        grad.addColorStop(f * 0.7, `rgba(${ac[0]},${ac[1]},${ac[2]},0.07)`);\n        grad.addColorStop(f, `rgba(${ac[0]},${ac[1]},${ac[2]},0.32)`);\n        grad.addColorStop(Math.min(1, f + 0.0005), `rgba(${ac[0]},${ac[1]},${ac[2]},0)`);\n        grad.addColorStop(1, `rgba(${ac[0]},${ac[1]},${ac[2]},0)`);\n        g.fillStyle = grad;\n        g.beginPath();\n        g.arc(cx, cy, R, 0, TAU);\n        g.fill();\n      } else {\n        for (let k = 0; k < 24; k++) {\n          const a0 = sweep - trail + (trail * k) / 24;\n          g.fillStyle = `rgba(${ac[0]},${ac[1]},${ac[2]},${((k / 24) ** 2 * 0.3).toFixed(3)})`;\n          g.beginPath();\n          g.moveTo(cx, cy);\n          g.arc(cx, cy, R, a0, a0 + trail / 24 + 0.01);\n          g.closePath();\n          g.fill();\n        }\n      }\n      g.strokeStyle = `rgba(${ac[0]},${ac[1]},${ac[2]},0.9)`;\n      g.lineWidth = 1.4;\n      g.beginPath();\n      g.moveTo(cx, cy);\n      g.lineTo(cx + Math.cos(sweep) * R, cy + Math.sin(sweep) * R);\n      g.stroke();\n      g.font = `500 9px ${family}`;\n      g.textAlign = \"left\";\n      g.textBaseline = \"middle\";\n      g.globalCompositeOperation = \"lighter\";\n      for (let i = 0; i < tg.length; i++) {\n        const o = tg[i];\n        o.r += o.vr * dt;\n        o.a += o.va * dt;\n        if (o.r < 0.12 || o.r > 0.95) o.vr = -o.vr;\n        const ang = ((o.a % TAU) + TAU) % TAU;\n        const delta = (((sweep - ang) % TAU) + TAU) % TAU;\n        if (delta < o.last && dt > 0) o.hit = t;\n        o.last = delta;\n        const age = t - o.hit;\n        const b = age >= 0 ? Math.exp(-age / 2.8) : 0;\n        if (b < 0.02) continue;\n        const x = cx + Math.cos(ang) * o.r * R;\n        const y = cy + Math.sin(ang) * o.r * R;\n        g.globalAlpha = b;\n        g.drawImage(sprite, x - 12, y - 12, 24, 24);\n        g.fillStyle = \"rgba(240,255,248,0.95)\";\n        g.fillRect(x - 1.2, y - 1.2, 2.4, 2.4);\n        if (labels && i % 3 === 0) {\n          g.globalAlpha = b * 0.85;\n          g.strokeStyle = `rgba(${ac[0]},${ac[1]},${ac[2]},0.7)`;\n          g.lineWidth = 1;\n          g.beginPath();\n          g.moveTo(x + 4, y - 4);\n          g.lineTo(x + 12, y - 12);\n          g.lineTo(x + 18, y - 12);\n          g.stroke();\n          g.fillStyle = `rgb(${ac[0]},${ac[1]},${ac[2]})`;\n          g.fillText(`TRK ${o.id} · ${(o.r * 50).toFixed(1)}`, x + 21, y - 12);\n        }\n      }\n      g.globalAlpha = 1;\n      g.globalCompositeOperation = \"source-over\";\n    }\n\n    const motion = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    let visible = true;\n    let raf = 0;\n    let prev = 0;\n\n    function prime() {\n      for (const o of tg) {\n        const back = ((((t * 0.85 - o.a) % TAU) + TAU) % TAU) / 0.85;\n        o.hit = t - back;\n        o.last = (((t * 0.85 - o.a) % TAU) + TAU) % TAU;\n      }\n    }\n\n    function still() {\n      t = 4;\n      prime();\n      render(0);\n    }\n\n    function resize() {\n      const nw = el.clientWidth;\n      const nh = el.clientHeight;\n      if (!nw || !nh) return;\n      const dpr = Math.min(2, window.devicePixelRatio || 1);\n      w = nw;\n      h = nh;\n      cv.width = Math.max(1, Math.round(w * dpr));\n      cv.height = Math.max(1, Math.round(h * dpr));\n      g.setTransform(dpr, 0, 0, dpr, 0, 0);\n      cx = w * ox;\n      cy = h * oy;\n      R = Math.max(80, Math.max(w, h) * 0.44 * size);\n      paintScope(dpr);\n      if (motion.matches) still();\n      else {\n        if (!primed) {\n          t = 4;\n          prime();\n          primed = true;\n        }\n        render(0);\n      }\n    }\n\n    function frame(now: number) {\n      const dt = Math.min(0.05, (now - prev) / 1000) * speed;\n      prev = now;\n      t += dt;\n      render(dt);\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    const ro = new ResizeObserver(resize);\n    const io = new IntersectionObserver((entries) => {\n      visible = entries[entries.length - 1].isIntersecting;\n      sync();\n    });\n    ro.observe(el);\n    io.observe(el);\n    document.addEventListener(\"visibilitychange\", sync);\n    motion.addEventListener(\"change\", sync);\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    };\n  }, [color, accent, background, ox, oy, size, targets, labels, speed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-ve14 ${className}`} style={{ background, ...style }} {...rest}>\n      <style href=\"hb-bg-radar\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-ve14-c\" aria-hidden=\"true\" />\n      {children ? <div className=\"hb-ve14-in\">{children}</div> : null}\n    </div>\n  );\n}\n"
    }
  ]
}