{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "latency-stream",
  "title": "Latency Stream",
  "type": "registry:component",
  "description": "Live latency line streaming from the right with an average",
  "dependencies": [],
  "files": [
    {
      "path": "src/kavyn/latency-stream.jsx",
      "type": "registry:file",
      "target": "@components/kavyn/latency-stream.jsx",
      "content": "'use client'\n\nimport { useEffect, useRef, useState } from 'react'\n\nconst N = 48\nconst next = (v) => Math.max(8, Math.min(120, v + (Math.random() - 0.5) * 18 + (38 - v) * 0.08 + (Math.random() < 0.04 ? 45 : 0)))\n\n// Live p50 latency line that streams in from the right, with a moving average.\nexport default function LatencyStream({ label = 'p50 latency', unit = 'ms', interval = 700 }) {\n  // Stable sample on server and client; live updates remain random after mounting.\n  const [pts, setPts] = useState(() => Array.from({ length: N }, (_, i) => 38 + Math.sin(i * 0.73) * 10 + Math.cos(i * 0.31) * 6))\n  const hidden = useRef(false)\n  useEffect(() => {\n    const vis = () => { hidden.current = document.hidden }\n    document.addEventListener('visibilitychange', vis)\n    const id = setInterval(() => { if (!hidden.current) setPts((p) => [...p.slice(1), next(p[p.length - 1])]) }, interval)\n    return () => { clearInterval(id); document.removeEventListener('visibilitychange', vis) }\n  }, [interval])\n  const W = 380, H = 120, max = 130\n  const xy = pts.map((v, i) => [(i / (N - 1)) * W, H - (v / max) * H])\n  const line = xy.map(([x, y], i) => `${i ? 'L' : 'M'}${x.toFixed(1)},${y.toFixed(1)}`).join('')\n  const now = pts[pts.length - 1]\n  const avg = pts.slice(-12).reduce((a, b) => a + b, 0) / 12\n  return (\n    <div className=\"w-[420px] max-w-full rounded-2xl border border-line bg-panel p-4\">\n      <div className=\"flex items-end justify-between\">\n        <div>\n          <div className=\"text-xs text-mute\">{label}</div>\n          <div className=\"mt-1 font-mono text-2xl tabular-nums tracking-tight text-tx\">{now.toFixed(0)}<span className=\"ml-1 text-sm text-faint\">{unit}</span></div>\n        </div>\n        <span className={`rounded-full px-2 py-0.5 font-mono text-[11px] ${now > avg * 1.3 ? 'bg-amber-400/15 text-amber-300' : 'bg-emerald-400/10 text-emerald-300'}`}>\n          avg {avg.toFixed(0)}{unit}\n        </span>\n      </div>\n      <svg viewBox={`0 0 ${W} ${H}`} className=\"mt-3 h-28 w-full overflow-visible\" preserveAspectRatio=\"none\">\n        <defs>\n          <linearGradient id=\"ls-fill\" x1=\"0\" x2=\"0\" y1=\"0\" y2=\"1\"><stop offset=\"0\" stopColor=\"var(--acc)\" stopOpacity=\".28\" /><stop offset=\"1\" stopColor=\"var(--acc)\" stopOpacity=\"0\" /></linearGradient>\n        </defs>\n        {[0.25, 0.5, 0.75].map((g) => <line key={g} x1=\"0\" x2={W} y1={H * g} y2={H * g} stroke=\"var(--line)\" strokeDasharray=\"3 4\" />)}\n        <path d={`${line}L${W},${H}L0,${H}Z`} fill=\"url(#ls-fill)\" />\n        <path d={line} fill=\"none\" stroke=\"var(--acc)\" strokeWidth=\"1.6\" vectorEffect=\"non-scaling-stroke\" />\n        <circle cx={W} cy={xy[xy.length - 1][1]} r=\"3.5\" fill=\"var(--acc)\" />\n        <circle cx={W} cy={xy[xy.length - 1][1]} r=\"3.5\" fill=\"none\" stroke=\"var(--acc)\" className=\"animate-ping\" style={{ transformOrigin: `${W}px ${xy[xy.length - 1][1]}px` }} />\n      </svg>\n    </div>\n  )\n}\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"
    }
  }
}
