{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "traffic-map",
  "title": "Traffic Map",
  "type": "registry:component",
  "description": "Dotted world map with live request arcs between edge cities",
  "dependencies": [],
  "files": [
    {
      "path": "src/kavyn/traffic-map.jsx",
      "type": "registry:file",
      "target": "@components/kavyn/traffic-map.jsx",
      "content": "'use client'\n\nimport { useEffect, useRef } from 'react'\nimport { worldDots, project, COLS, ROWS } from './world-dots'\n\n// Light or dark, read from the --bg token itself: works with a .dark class, a .light class, or neither.\nconst isLightTheme = () => {\n  const h = getComputedStyle(document.documentElement).getPropertyValue('--bg').trim().replace(/^#(.)(.)(.)$/, '#$1$1$2$2$3$3')\n  return /^#[0-9a-f]{6}/i.test(h) ? [1, 3, 5].reduce((s, i, k) => s + parseInt(h.slice(i, i + 2), 16) * [0.299, 0.587, 0.114][k], 0) > 128 : !document.documentElement.classList.contains('dark')\n}\n\nconst HUBS = [\n  { id: 'BOM', lat: 19.07, lon: 72.87 }, { id: 'FRA', lat: 50.11, lon: 8.68 }, { id: 'IAD', lat: 38.95, lon: -77.45 },\n  { id: 'SFO', lat: 37.62, lon: -122.38 }, { id: 'SIN', lat: 1.35, lon: 103.99 }, { id: 'GRU', lat: -23.43, lon: -46.47 },\n  { id: 'NRT', lat: 35.77, lon: 140.39 }, { id: 'SYD', lat: -33.94, lon: 151.18 }, { id: 'JNB', lat: -26.14, lon: 28.24 },\n  { id: 'LHR', lat: 51.47, lon: -0.45 }, { id: 'DXB', lat: 25.25, lon: 55.36 },\n]\n\n// Cloudflare-style dotted world map with live request arcs between edge locations.\nexport default function TrafficMap({ hubs = HUBS, arcs = 7, color = undefined, className = '' }) {\n  const ref = useRef(null)\n  useEffect(() => {\n    const c = ref.current\n    const ctx = c?.getContext('2d')\n    if (!ctx || !hubs?.length) return\n    const dots = worldDots()\n    let w = 0, h = 0, raf, last = performance.now()\n    const size = () => {\n      const d = Math.min(window.devicePixelRatio || 1, 2)\n      w = c.clientWidth; h = c.clientHeight\n      c.width = Math.max(1, w * d); c.height = Math.max(1, h * d); ctx.setTransform(d, 0, 0, d, 0, 0)\n    }\n    size()\n    const ro = new ResizeObserver(size); ro.observe(c)\n    const pick = () => {\n      const a = hubs[(Math.random() * hubs.length) | 0]\n      let b = a\n      while (b === a && hubs.length > 1) b = hubs[(Math.random() * hubs.length) | 0]\n      return { a, b, t: -Math.random() * 1.2, speed: 0.35 + Math.random() * 0.3 }\n    }\n    const live = Array.from({ length: arcs }, pick)\n    const flashes = []\n    const pos = (p) => project(p.lat, p.lon, w, h)\n    const bez = (A, B, t) => {\n      const mx = (A[0] + B[0]) / 2, my = (A[1] + B[1]) / 2 - Math.hypot(B[0] - A[0], B[1] - A[1]) * 0.35\n      const u = 1 - t\n      return [u * u * A[0] + 2 * u * t * mx + t * t * B[0], u * u * A[1] + 2 * u * t * my + t * t * B[1]]\n    }\n    const draw = (now) => {\n      const dt = Math.min(0.05, (now - last) / 1000); last = now\n      ctx.clearRect(0, 0, w, h)\n      const pitch = w / COLS, r = Math.max(0.6, pitch * 0.26)\n      const lite = isLightTheme()\n      const ink = color || (lite ? '29,29,31' : '245,245,247')\n      ctx.fillStyle = lite ? 'rgba(29,29,31,0.18)' : 'rgba(245,245,247,0.13)'\n      for (const d of dots) {\n        const x = (d.col + 0.5) * pitch, y = (d.row + 0.5) * (h / ROWS)\n        ctx.beginPath(); ctx.arc(x, y, r, 0, 6.283); ctx.fill()\n      }\n      for (const arc of live) {\n        arc.t += dt * arc.speed\n        if (arc.t > 1.35) { flashes.push({ p: arc.b, t: 0 }); Object.assign(arc, pick(), { t: 0 }) }\n        if (arc.t <= 0) continue\n        const A = pos(arc.a), B = pos(arc.b)\n        const head = Math.min(1, arc.t), tail = Math.max(0, Math.min(1, arc.t - 0.35))\n        ctx.lineWidth = 1.2; ctx.lineCap = 'round'\n        const steps = 24\n        for (let i = 0; i < steps; i++) {\n          const t0 = tail + ((head - tail) * i) / steps, t1 = tail + ((head - tail) * (i + 1)) / steps\n          const p0 = bez(A, B, t0), p1 = bez(A, B, t1)\n          ctx.strokeStyle = `rgba(${ink},${(i / steps) * 0.9})`\n          ctx.beginPath(); ctx.moveTo(p0[0], p0[1]); ctx.lineTo(p1[0], p1[1]); ctx.stroke()\n        }\n        if (arc.t < 1) { const p = bez(A, B, head); ctx.fillStyle = `rgb(${ink})`; ctx.beginPath(); ctx.arc(p[0], p[1], 1.8, 0, 6.283); ctx.fill() }\n      }\n      for (let i = flashes.length - 1; i >= 0; i--) {\n        const f = flashes[i]; f.t += dt * 1.4\n        if (f.t > 1) { flashes.splice(i, 1); continue }\n        const [x, y] = pos(f.p)\n        ctx.strokeStyle = `rgba(${ink},${1 - f.t})`; ctx.lineWidth = 1\n        ctx.beginPath(); ctx.arc(x, y, 2 + f.t * 14, 0, 6.283); ctx.stroke()\n      }\n      for (const hub of hubs) {\n        const [x, y] = pos(hub)\n        ctx.fillStyle = `rgba(${ink},0.25)`; ctx.beginPath(); ctx.arc(x, y, 4, 0, 6.283); ctx.fill()\n        ctx.fillStyle = `rgb(${ink})`; ctx.beginPath(); ctx.arc(x, y, 1.8, 0, 6.283); ctx.fill()\n      }\n      raf = requestAnimationFrame(draw)\n    }\n    raf = requestAnimationFrame(draw)\n    return () => { cancelAnimationFrame(raf); ro.disconnect() }\n  }, [hubs, arcs, color])\n  return (\n    <div className={`relative w-full ${className}`} style={{ aspectRatio: `${COLS} / ${ROWS}` }}>\n      <canvas ref={ref} className=\"absolute inset-0 size-full\" aria-label=\"Live traffic map\" role=\"img\" />\n    </div>\n  )\n}\n"
    },
    {
      "path": "src/kavyn/world-dots.js",
      "type": "registry:file",
      "target": "@components/kavyn/world-dots.js",
      "content": "// Land mask for the dotted world map, 2.5° grid (lat 80 to -58).\n// Each row lists runs of land as \"startCol.length\" in base 36.\n// Generated from Natural Earth 1:110m land (public domain) via the world-atlas package.\nexport const STEP = 2.5\nexport const LAT_TOP = 80\nexport const COLS = 144\nconst RLE = 'x.b,19.k,26.5,31.3|o.2,11.4,19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,3l.1|17.d,25.a,2i.2,3d.9|18.c,25.9,2i.1,3c.b|18.b,26.8,2h.2,39.f|18.9,26.8,2i.1,39.g|18.9,26.7,3a.f|17.9,27.5,3a.f|17.8,27.4,3a.4,3i.7|17.6,3j.5|17.6,3k.4|17.4,3y.1|16.5,3m.1,3w.1|16.4,3v.1|16.4|16.3|16.2|18.2|'\n\nlet cache = null\n// Returns [{ lat, lon, col, row }] for every land dot.\nexport function worldDots() {\n  if (cache) return cache\n  cache = []\n  RLE.split('|').forEach((line, row) => {\n    if (!line) return\n    line.split(',').forEach((run) => {\n      const [a, b] = run.split('.').map((v) => parseInt(v, 36))\n      for (let col = a; col < a + b; col++) cache.push({ row, col, lat: LAT_TOP - row * STEP, lon: -180 + col * STEP + STEP / 2 })\n    })\n  })\n  return cache\n}\n\nexport const ROWS = RLE.split('|').length\n\n// Equirectangular position inside a width x height box.\nexport const project = (lat, lon, w, h) => [((lon + 180) / 360) * w, ((LAT_TOP - lat) / (ROWS * STEP)) * h]\n"
    }
  ],
  "cssVars": {
    "theme": {
      "color-bg": "var(--bg)",
      "color-panel": "var(--panel)",
      "color-panel2": "var(--panel2)",
      "color-line": "var(--line)",
      "color-line2": "var(--line2)",
      "color-tx": "var(--tx)",
      "color-mute": "var(--mute)",
      "color-faint": "var(--faint)",
      "color-acc": "var(--acc)",
      "color-acc-fg": "var(--acc-fg)"
    },
    "light": {
      "bg": "#ffffff",
      "panel": "#f5f5f7",
      "panel2": "#e8e8ed",
      "line": "#e5e5ea",
      "line2": "#d2d2d7",
      "tx": "#1d1d1f",
      "mute": "#6e6e73",
      "faint": "#a1a1a6",
      "acc": "#1d1d1f",
      "acc-fg": "#ffffff"
    },
    "dark": {
      "bg": "#000000",
      "panel": "#141416",
      "panel2": "#1f1f22",
      "line": "#262628",
      "line2": "#3a3a3d",
      "tx": "#f5f5f7",
      "mute": "#a1a1a6",
      "faint": "#6e6e73",
      "acc": "#f5f5f7",
      "acc-fg": "#000000"
    }
  },
  "css": {
    ".light": {
      "--bg": "#ffffff",
      "--panel": "#f5f5f7",
      "--panel2": "#e8e8ed",
      "--line": "#e5e5ea",
      "--line2": "#d2d2d7",
      "--tx": "#1d1d1f",
      "--mute": "#6e6e73",
      "--faint": "#a1a1a6",
      "--acc": "#1d1d1f",
      "--acc-fg": "#ffffff"
    }
  }
}
