{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "loader-device-scan",
  "type": "registry:component",
  "title": "Loader Device Scan",
  "description": "A half-dial sonar sweeps back and forth with a fading wake, and nearby devices light up the moment the beam crosses them. A live count shows how many have been found.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "loaders",
    "loader",
    "scan",
    "sonar",
    "pairing",
    "bluetooth",
    "svg"
  ],
  "docs": "https://hyperblur.dev/effects/loader-device-scan",
  "files": [
    {
      "path": "registry/hyperblur/loader-device-scan.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/loader-device-scan.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface LoaderDeviceScanProps extends React.HTMLAttributes<HTMLSpanElement> {\n  size?: number;\n  devices?: number;\n  color?: string;\n  accent?: string;\n  speed?: number;\n  showCount?: boolean;\n  seed?: number;\n  label?: string;\n}\n\nfunction hash(n: number) {\n  let x = (n * 2246822519 + 374761393) >>> 0;\n  x = Math.imul(x ^ (x >>> 15), 0x85ebca77) >>> 0;\n  x = Math.imul(x ^ (x >>> 13), 0xc2b2ae3d) >>> 0;\n  return ((x ^ (x >>> 16)) >>> 0) / 4294967295;\n}\n\nconst OX = 50;\nconst OY = 54;\nconst R = 46;\n\nfunction pt(r: number, phi: number): [number, number] {\n  const a = (phi * Math.PI) / 180;\n  return [OX - Math.cos(a) * r, OY - Math.sin(a) * r];\n}\n\nfunction wedge(a1: number, a2: number) {\n  const lo = Math.max(0, Math.min(a1, a2));\n  const hi = Math.min(180, Math.max(a1, a2));\n  const [x1, y1] = pt(R, lo);\n  const [x2, y2] = pt(R, hi);\n  return `M${OX} ${OY}L${x1.toFixed(2)} ${y1.toFixed(2)}A${R} ${R} 0 0 1 ${x2.toFixed(2)} ${y2.toFixed(2)}Z`;\n}\n\nconst css = `\n.hb-vk10 {\n  position: relative;\n  display: inline-flex;\n  flex-direction: column;\n  align-items: center;\n  gap: 0.55em;\n  box-sizing: border-box;\n  font-family: inherit;\n  color: #ededed;\n  vertical-align: middle;\n}\n.hb-vk10 *, .hb-vk10 *::before, .hb-vk10 *::after { box-sizing: border-box; }\n.hb-vk10-svg { display: block; width: var(--hb-vk10-s); height: calc(var(--hb-vk10-s) * 0.58); overflow: visible; flex: none; }\n.hb-vk10-grid { fill: none; stroke: #232323; stroke-width: 0.5; }\n.hb-vk10-base { stroke: #2e2e2e; stroke-width: 0.6; }\n.hb-vk10-ping {\n  fill: none;\n  stroke: var(--hb-vk10-a);\n  stroke-width: 0.6;\n  transform-origin: 50px 54px;\n  animation: hb-vk10-ping 2.6s cubic-bezier(0.2, 0.6, 0.35, 1) infinite;\n}\n.hb-vk10-beam { stroke: var(--hb-vk10-a); stroke-width: 0.7; stroke-linecap: round; filter: drop-shadow(0 0 1.5px var(--hb-vk10-a)); }\n.hb-vk10-blip { fill: var(--hb-vk10-a); }\n.hb-vk10-halo { fill: none; stroke: var(--hb-vk10-a); stroke-width: 0.5; }\n.hb-vk10-hub { fill: #0a0a0a; stroke: var(--hb-vk10-a); stroke-width: 0.8; }\n.hb-vk10-cnt {\n  font-size: 11.5px;\n  line-height: 1;\n  color: #8f8f8f;\n  font-variant-numeric: tabular-nums;\n  white-space: nowrap;\n}\n.hb-vk10-cnt b { color: #ededed; font-weight: 600; }\n.hb-vk10-l { font-size: 12px; line-height: 1.3; color: #a1a1a1; white-space: nowrap; }\n.hb-vk10-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n}\n@keyframes hb-vk10-ping {\n  0% { transform: scale(0.08); opacity: 0.9; }\n  100% { transform: scale(1); opacity: 0; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-vk10-ping { animation: none; opacity: 0; }\n}\n`;\n\ntype Frame = { phi: number; dir: number; now: number; hits: number[] };\n\nexport function LoaderDeviceScan({\n  size = 168,\n  devices = 5,\n  color = \"#2f7bff\",\n  accent = \"#7fb3ff\",\n  speed = 3.2,\n  showCount = true,\n  seed = 7,\n  label,\n  className = \"\",\n  style,\n  ...rest\n}: LoaderDeviceScanProps) {\n  const gid = React.useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const n = Math.max(0, Math.min(12, Math.round(devices)));\n  const blips = React.useMemo(\n    () =>\n      Array.from({ length: n }, (_, i) => ({\n        phi: 14 + hash(seed * 31 + i * 7) * 152,\n        r: 14 + hash(seed * 17 + i * 13 + 5) * 28,\n      })),\n    [n, seed],\n  );\n  const [frame, setFrame] = React.useState<Frame>({ phi: 90, dir: 1, now: 0, hits: [] });\n  const [still, setStill] = React.useState(false);\n\n  React.useEffect(() => {\n    let raf = 0;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) {\n      raf = requestAnimationFrame(() => setStill(true));\n      return () => cancelAnimationFrame(raf);\n    }\n    const period = Math.max(1, speed) * 1000;\n    let t0 = 0;\n    let prev = 0;\n    let hits: number[] = blips.map(() => -1e9);\n    function tick(now: number) {\n      if (!t0) t0 = now;\n      const t = (now - t0) / period;\n      const phi = 90 - 90 * Math.cos(t * Math.PI * 2);\n      if (t > 0) {\n        const lo = Math.min(prev, phi);\n        const hi = Math.max(prev, phi);\n        let changed = false;\n        const nextHits = hits.map((h, i) => {\n          if (blips[i].phi >= lo && blips[i].phi <= hi) {\n            changed = true;\n            return now;\n          }\n          return h;\n        });\n        if (changed) hits = nextHits;\n      }\n      const dir = phi >= prev ? 1 : -1;\n      prev = phi;\n      setFrame({ phi, dir, now, hits });\n      raf = requestAnimationFrame(tick);\n    }\n    raf = requestAnimationFrame(tick);\n    return () => cancelAnimationFrame(raf);\n  }, [blips, speed]);\n\n  const found = still ? n : frame.hits.filter((h) => h > 0).length;\n  const trail = 34;\n  const [bx, by] = pt(R, frame.phi);\n  const vars = {\n    \"--hb-vk10-s\": `${size}px`,\n    \"--hb-vk10-c\": color,\n    \"--hb-vk10-a\": accent,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-loader-device-scan\" precedence=\"default\">{css}</style>\n      <span role=\"status\" className={`hb-vk10 ${className}`} style={vars} {...rest}>\n        <svg className=\"hb-vk10-svg\" viewBox=\"0 0 100 58\" aria-hidden=\"true\">\n          <defs>\n            <radialGradient id={`${gid}g`} cx={OX} cy={OY} r={R} gradientUnits=\"userSpaceOnUse\">\n              <stop offset=\"0%\" stopColor={color} stopOpacity=\"0.16\" />\n              <stop offset=\"100%\" stopColor={color} stopOpacity=\"0\" />\n            </radialGradient>\n          </defs>\n          <path d={wedge(0, 180)} fill={`url(#${gid}g)`} />\n          {[0.25, 0.5, 0.75, 1].map((f) => (\n            <path key={f} className=\"hb-vk10-grid\" d={`M${OX - R * f} ${OY}A${R * f} ${R * f} 0 0 1 ${OX + R * f} ${OY}`} />\n          ))}\n          {[30, 60, 90, 120, 150].map((a) => {\n            const [x, y] = pt(R, a);\n            return <line key={a} className=\"hb-vk10-grid\" x1={OX} y1={OY} x2={x.toFixed(2)} y2={y.toFixed(2)} />;\n          })}\n          <line className=\"hb-vk10-base\" x1={OX - R - 2} y1={OY} x2={OX + R + 2} y2={OY} />\n          {!still\n            ? [0, 1].map((k) => (\n                <path\n                  key={k}\n                  className=\"hb-vk10-ping\"\n                  style={{ animationDelay: `${k * 1.3}s` }}\n                  d={`M${OX - R} ${OY}A${R} ${R} 0 0 1 ${OX + R} ${OY}`}\n                />\n              ))\n            : null}\n          {!still\n            ? Array.from({ length: 6 }, (_, k) => {\n                const a2 = frame.phi - frame.dir * (k * trail) / 6;\n                const a1 = frame.phi - frame.dir * ((k + 1) * trail) / 6;\n                return <path key={k} d={wedge(a1, a2)} fill={accent} opacity={(0.2 * (1 - k / 6)).toFixed(3)} />;\n              })\n            : null}\n          {!still ? <line className=\"hb-vk10-beam\" x1={OX} y1={OY} x2={bx.toFixed(2)} y2={by.toFixed(2)} /> : null}\n          {blips.map((b, i) => {\n            const [x, y] = pt(b.r, b.phi);\n            const age = still ? 0 : frame.now - (frame.hits[i] ?? -1e9);\n            const glow = still ? 0.85 : Math.max(0, Math.exp(-age / 1100));\n            const seen = still || (frame.hits[i] ?? -1) > 0;\n            return (\n              <g key={i}>\n                <circle\n                  className=\"hb-vk10-halo\"\n                  cx={x.toFixed(2)}\n                  cy={y.toFixed(2)}\n                  r={(1.6 + (1 - glow) * 3.2).toFixed(2)}\n                  opacity={(glow * 0.8).toFixed(3)}\n                />\n                <circle\n                  className=\"hb-vk10-blip\"\n                  cx={x.toFixed(2)}\n                  cy={y.toFixed(2)}\n                  r=\"1.25\"\n                  opacity={(seen ? 0.28 + glow * 0.72 : 0).toFixed(3)}\n                />\n              </g>\n            );\n          })}\n          <circle className=\"hb-vk10-hub\" cx={OX} cy={OY} r=\"2.2\" />\n        </svg>\n        {showCount ? (\n          <span className=\"hb-vk10-cnt\" aria-hidden=\"true\">\n            <b>{found}</b> {found === 1 ? \"device\" : \"devices\"} found\n          </span>\n        ) : null}\n        <span className={label ? \"hb-vk10-l\" : \"hb-vk10-sr\"}>{label ?? \"Scanning\"}</span>\n      </span>\n    </>\n  );\n}\n"
    }
  ]
}