{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-hex-pulse",
  "type": "registry:component",
  "title": "Hex Pulse",
  "description": "A honeycomb grid where pulses ripple out from random cells, lighting outlines with a sharp leading edge and a slow afterglow. Moving or tapping the pointer sends a pulse from that spot.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "hexagon",
    "grid",
    "pulse",
    "canvas",
    "pointer"
  ],
  "docs": "https://hyperblur.dev/effects/bg-hex-pulse",
  "files": [
    {
      "path": "registry/hyperblur/bg-hex-pulse.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-hex-pulse.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgHexPulseProps extends React.HTMLAttributes<HTMLDivElement> {\n  color?: string;\n  accent?: string;\n  background?: string;\n  radius?: number;\n  interval?: number;\n  interactive?: boolean;\n  speed?: number;\n  children?: React.ReactNode;\n}\n\nconst css = `\n.hb-ve13 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; box-sizing: border-box; }\n.hb-ve13-c { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }\n.hb-ve13-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\ninterface Wave {\n  x: number;\n  y: number;\n  at: number;\n  power: number;\n}\n\nexport function BgHexPulse({\n  color = \"#1c2433\",\n  accent = \"#2f7bff\",\n  background = \"#05070b\",\n  radius = 18,\n  interval = 1.8,\n  interactive = true,\n  speed = 1,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: BgHexPulseProps) {\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n\n  React.useEffect(() => {\n    const wrap = wrapRef.current;\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    const host = wrap?.parentElement;\n    if (!wrap || !canvas || !ctx || !host) return;\n    const g: CanvasRenderingContext2D = ctx;\n    const el: HTMLDivElement = wrap;\n    const cv: HTMLCanvasElement = canvas;\n    const hostEl: HTMLElement = host;\n\n    const lc = rgbOf(color, [28, 36, 51]);\n    const ac = rgbOf(accent, [47, 123, 255]);\n    const LV = 9;\n    const strokes: string[] = [];\n    const fills: string[] = [];\n    for (let i = 0; i < LV; i++) {\n      const k = i / (LV - 1);\n      strokes.push(`rgba(${Math.round(lc[0] + (ac[0] - lc[0]) * k)},${Math.round(lc[1] + (ac[1] - lc[1]) * k)},${Math.round(lc[2] + (ac[2] - lc[2]) * k)},${(0.75 + k * 0.25).toFixed(2)})`);\n      fills.push(`rgba(${ac[0]},${ac[1]},${ac[2]},${(k * k * 0.32).toFixed(3)})`);\n    }\n\n    let seed = 0x4e7;\n    function rand() {\n      seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0;\n      return seed / 4294967296;\n    }\n\n    let w = 0;\n    let h = 0;\n    let t = 0;\n    let next = 0.2;\n    let lastPointer = -9;\n    let cx = new Float32Array(0);\n    let cy = new Float32Array(0);\n    let cr = 0;\n    const waves: Wave[] = [];\n\n    function setup() {\n      cr = Math.max(8, radius);\n      const hw = Math.sqrt(3) * cr;\n      const vh = 1.5 * cr;\n      const cols = Math.ceil(w / hw) + 2;\n      const rows = Math.ceil(h / vh) + 2;\n      cx = new Float32Array(cols * rows);\n      cy = new Float32Array(cols * rows);\n      let i = 0;\n      for (let r = 0; r < rows; r++) {\n        for (let c = 0; c < cols; c++) {\n          cx[i] = c * hw + (r % 2 ? hw / 2 : 0) - hw / 2;\n          cy[i] = r * vh - vh / 2;\n          i++;\n        }\n      }\n    }\n\n    function spawn(x: number, y: number, power: number) {\n      waves.push({ x, y, at: t, power });\n      if (waves.length > 10) waves.shift();\n    }\n\n    function hexPath(p: Path2D, x: number, y: number, r: number) {\n      for (let k = 0; k < 6; k++) {\n        const a = (Math.PI / 3) * k + Math.PI / 6;\n        const px = x + Math.cos(a) * r;\n        const py = y + Math.sin(a) * r;\n        if (k) p.lineTo(px, py);\n        else p.moveTo(px, py);\n      }\n      p.closePath();\n    }\n\n    function render() {\n      if (!w || !h) return;\n      if (t >= next) {\n        if (cx.length) {\n          const i = Math.floor(rand() * cx.length);\n          spawn(cx[i], cy[i], 0.75 + rand() * 0.25);\n        }\n        next = t + Math.max(0.3, interval) * (0.6 + rand() * 0.8);\n      }\n      g.fillStyle = background;\n      g.fillRect(0, 0, w, h);\n      const v = Math.max(w, h) * 0.32;\n      const band = cr * 2.6;\n      const strokeP: Path2D[] = [];\n      const fillP: Path2D[] = [];\n      for (let k = 0; k < LV; k++) {\n        strokeP.push(new Path2D());\n        fillP.push(new Path2D());\n      }\n      const inner = cr - 1.6;\n      for (let i = 0; i < cx.length; i++) {\n        let I = 0;\n        for (const wv of waves) {\n          const age = t - wv.at;\n          if (age < 0) continue;\n          const front = age * v;\n          const d = Math.hypot(cx[i] - wv.x, cy[i] - wv.y);\n          const off = (d - front) / band;\n          if (off > 1.5 || off < -3) continue;\n          const decay = Math.exp(-age * 0.9) * wv.power;\n          const lead = off > 0 ? Math.exp(-off * off * 3) : Math.exp(-off * off * 0.5);\n          I = Math.max(I, lead * decay);\n        }\n        const shimmer = 0.05 * (0.5 + 0.5 * Math.sin(t * 0.8 + cx[i] * 0.02 + cy[i] * 0.03));\n        const lvl = Math.min(LV - 1, Math.round((I + shimmer) * (LV - 1)));\n        hexPath(strokeP[lvl], cx[i], cy[i], inner);\n        if (lvl > 1) hexPath(fillP[lvl], cx[i], cy[i], inner - 1);\n      }\n      g.lineWidth = 1;\n      g.lineJoin = \"round\";\n      for (let k = 0; k < LV; k++) {\n        if (k > 1) {\n          g.fillStyle = fills[k];\n          g.fill(fillP[k]);\n        }\n        g.strokeStyle = strokes[k];\n        g.stroke(strokeP[k]);\n      }\n      while (waves.length && t - waves[0].at > 5) waves.shift();\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 still() {\n      waves.length = 0;\n      t = 0;\n      if (cx.length) spawn(w * 0.5, h * 0.5, 1);\n      t = 0.55;\n      next = 99;\n      render();\n      next = 0.2;\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      setup();\n      if (motion.matches) still();\n      else render();\n    }\n\n    function frame(now: number) {\n      const dt = Math.min(0.05, (now - prev) / 1000);\n      prev = now;\n      t += dt * speed;\n      render();\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    function poke(e: PointerEvent) {\n      if (!interactive || motion.matches) return;\n      if (e.type === \"pointermove\" && t - lastPointer < 0.45) return;\n      lastPointer = t;\n      const rect = el.getBoundingClientRect();\n      spawn(e.clientX - rect.left, e.clientY - rect.top, e.type === \"pointerdown\" ? 1 : 0.55);\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    hostEl.addEventListener(\"pointermove\", poke, { passive: true });\n    hostEl.addEventListener(\"pointerdown\", poke, { passive: true });\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      hostEl.removeEventListener(\"pointermove\", poke);\n      hostEl.removeEventListener(\"pointerdown\", poke);\n    };\n  }, [color, accent, background, radius, interval, interactive, speed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-ve13 ${className}`} style={{ background, ...style }} {...rest}>\n      <style href=\"hb-bg-hex-pulse\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-ve13-c\" aria-hidden=\"true\" />\n      {children ? <div className=\"hb-ve13-in\">{children}</div> : null}\n    </div>\n  );\n}\n"
    }
  ]
}