{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-acid-squares",
  "type": "registry:component",
  "title": "Acid Squares",
  "description": "A grid of squares that flash neon colors in rings spreading out from the pointer. Pulses fire on their own while nobody is touching it, and a click sends a bigger wave.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "grid",
    "neon",
    "ripple",
    "pointer",
    "canvas"
  ],
  "docs": "https://hyperblur.dev/effects/bg-acid-squares",
  "files": [
    {
      "path": "registry/hyperblur/bg-acid-squares.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-acid-squares.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgAcidSquaresProps extends React.HTMLAttributes<HTMLDivElement> {\n  cellSize?: number;\n  gap?: number;\n  colors?: string[];\n  color?: string;\n  interval?: number;\n  waveSpeed?: number;\n  seed?: number;\n  speed?: number;\n}\n\nconst css = `\n.hb-qo5 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; box-sizing: border-box; }\n.hb-qo5-c { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }\n.hb-qo5-in { position: relative; z-index: 1; width: 100%; height: 100%; pointer-events: auto; font-family: inherit; }\n`;\n\nconst DEFAULT_COLORS = [\"#c6ff00\", \"#39ff88\", \"#00f0ff\", \"#ff2bd6\", \"#fff200\"];\n\nfunction hashU(n: number, s: number) {\n  let x = (Math.imul(n, 2654435761) ^ Math.imul(s + 1, 1597334677)) | 0;\n  x = Math.imul(x ^ (x >>> 15), 2246822519);\n  x = Math.imul(x ^ (x >>> 13), 3266489917);\n  return ((x ^ (x >>> 16)) >>> 0) / 4294967295;\n}\n\ninterface Ripple {\n  x: number;\n  y: number;\n  t0: number;\n  s: number;\n  c: number;\n}\n\nexport function BgAcidSquares({\n  cellSize = 18,\n  gap = 0.2,\n  colors = DEFAULT_COLORS,\n  color = \"rgba(255,255,255,0.05)\",\n  interval = 1.6,\n  waveSpeed = 200,\n  seed = 5,\n  speed = 1,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: BgAcidSquaresProps) {\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const palette = (colors.length ? colors : DEFAULT_COLORS).join(\"|\");\n\n  React.useEffect(() => {\n    const wrap = wrapRef.current;\n    const host = wrap?.parentElement;\n    const canvas = canvasRef.current;\n    const context = canvas?.getContext(\"2d\");\n    if (!wrap || !host || !canvas || !context) return;\n    const g = context;\n    const motion = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n\n    const pal = palette.split(\"|\");\n    const s0 = Math.round(seed) | 0;\n    const life = 2.6;\n    const wid = 26;\n    const vel = Math.max(40, waveSpeed);\n    let cell = Math.max(6, cellSize);\n    let w = 0;\n    let h = 0;\n    let t = 0;\n    let cols = 0;\n    let rows = 0;\n    let ox = 0;\n    let oy = 0;\n    let inside = false;\n    let px = -9999;\n    let py = -9999;\n    let lastX = -9999;\n    let lastY = -9999;\n    let lastT = -9;\n    let pulse = 0;\n    let nextIdle = 0.15;\n    let colorTurn = 0;\n    let ripples: Ripple[] = [];\n\n    const add = (x: number, y: number, s: number) => {\n      ripples.push({ x, y, t0: t, s, c: colorTurn % pal.length });\n      colorTurn++;\n      if (ripples.length > 28) ripples = ripples.slice(ripples.length - 28);\n    };\n\n    const idlePulse = () => {\n      const n = pulse++;\n      const x = w * (0.12 + 0.76 * hashU(n, s0));\n      const y = h * (0.15 + 0.7 * hashU(n + 911, s0));\n      add(x, y, 1);\n    };\n\n    const layout = () => {\n      cell = Math.max(6, cellSize);\n      while ((w / cell) * (h / cell) > 9000) cell *= 1.15;\n      cols = Math.ceil(w / cell);\n      rows = Math.ceil(h / cell);\n      ox = (w - cols * cell) / 2;\n      oy = (h - rows * cell) / 2;\n    };\n\n    const draw = () => {\n      if (!w || !h) return;\n      g.clearRect(0, 0, w, h);\n      ripples = ripples.filter((r) => t - r.t0 < life);\n      const inner = cell * (1 - Math.min(0.8, Math.max(0, gap)));\n      g.fillStyle = color;\n      g.beginPath();\n      for (let j = 0; j < rows; j++) {\n        for (let i = 0; i < cols; i++) {\n          const k = hashU(j * 4099 + i, s0);\n          const b = 0.55 + 0.45 * Math.sin(t * 1.3 + k * 6.283);\n          const sz = inner * (0.5 + 0.18 * b);\n          const cx = ox + (i + 0.5) * cell;\n          const cy = oy + (j + 0.5) * cell;\n          g.rect(cx - sz / 2, cy - sz / 2, sz, sz);\n        }\n      }\n      g.fill();\n      g.globalCompositeOperation = \"lighter\";\n      for (let j = 0; j < rows; j++) {\n        for (let i = 0; i < cols; i++) {\n          const cx = ox + (i + 0.5) * cell;\n          const cy = oy + (j + 0.5) * cell;\n          let best = 0;\n          let sum = 0;\n          let ci = 0;\n          for (let r = 0; r < ripples.length; r++) {\n            const rp = ripples[r];\n            const age = t - rp.t0;\n            const d = Math.hypot(cx - rp.x, cy - rp.y) - age * vel;\n            if (d > wid * 3 || d < -wid * 3) continue;\n            const fade = 1 - age / life;\n            const v = rp.s * Math.exp(-(d * d) / (wid * wid)) * fade * fade;\n            sum += v;\n            if (v > best) {\n              best = v;\n              ci = rp.c;\n            }\n          }\n          if (inside) {\n            const dd = Math.hypot(cx - px, cy - py);\n            const near = Math.max(0, 1 - dd / (cell * 2.6));\n            if (near > 0) {\n              sum += near * 0.55;\n              if (near * 0.55 > best) {\n                best = near * 0.55;\n                ci = (colorTurn + 1) % pal.length;\n              }\n            }\n          }\n          const I = Math.min(1, sum);\n          if (I < 0.03) continue;\n          const hue = pal[(ci + (hashU(j * 131 + i, s0 + 3) < 0.2 ? 1 : 0)) % pal.length];\n          g.fillStyle = hue;\n          const sz = inner * (0.5 + 0.5 * I);\n          g.globalAlpha = I * 0.22;\n          g.fillRect(cx - sz * 0.85, cy - sz * 0.85, sz * 1.7, sz * 1.7);\n          g.globalAlpha = Math.min(1, 0.25 + I * 0.85);\n          g.fillRect(cx - sz / 2, cy - sz / 2, sz, sz);\n        }\n      }\n      g.globalAlpha = 1;\n      g.globalCompositeOperation = \"source-over\";\n    };\n\n    const resize = () => {\n      const nw = wrap.clientWidth;\n      const nh = wrap.clientHeight;\n      if (!nw || !nh) return;\n      const dpr = Math.min(2, window.devicePixelRatio || 1);\n      w = nw;\n      h = nh;\n      canvas.width = Math.max(1, Math.round(w * dpr));\n      canvas.height = Math.max(1, Math.round(h * dpr));\n      g.setTransform(dpr, 0, 0, dpr, 0, 0);\n      layout();\n      if (motion.matches) still();\n      else draw();\n    };\n\n    let visible = true;\n    let raf = 0;\n    let prev = 0;\n\n    const still = () => {\n      inside = false;\n      ripples = [];\n      t = 0;\n      colorTurn = 0;\n      add(w * 0.3, h * 0.45, 1);\n      add(w * 0.72, h * 0.6, 1);\n      t = 0.55;\n      nextIdle = t + 0.2;\n      draw();\n    };\n\n    const frame = (now: number) => {\n      const dt = Math.min(0.033, (now - prev) / 1000);\n      prev = now;\n      t += dt * speed;\n      if (!inside && t >= nextIdle) {\n        idlePulse();\n        nextIdle = t + Math.max(0.3, interval);\n      }\n      draw();\n      raf = requestAnimationFrame(frame);\n    };\n\n    const 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 locate = (e: PointerEvent) => {\n      const rect = host.getBoundingClientRect();\n      const sx = rect.width ? host.clientWidth / rect.width : 1;\n      const sy = rect.height ? host.clientHeight / rect.height : 1;\n      px = (e.clientX - rect.left) * sx;\n      py = (e.clientY - rect.top) * sy;\n    };\n\n    const move = (e: PointerEvent) => {\n      if (motion.matches) return;\n      locate(e);\n      inside = true;\n      nextIdle = t + Math.max(0.3, interval) * 1.5;\n      const moved = Math.hypot(px - lastX, py - lastY);\n      if (moved > cell * 3 || (moved > cell * 0.8 && t - lastT > 0.22)) {\n        add(px, py, 0.6);\n        lastX = px;\n        lastY = py;\n        lastT = t;\n      }\n    };\n\n    const down = (e: PointerEvent) => {\n      if (motion.matches) return;\n      locate(e);\n      inside = true;\n      add(px, py, 1.3);\n      lastX = px;\n      lastY = py;\n      lastT = t;\n    };\n\n    const leave = (e: PointerEvent) => {\n      if (e.type === \"pointerup\" && e.pointerType === \"mouse\") return;\n      inside = false;\n      nextIdle = t + 0.6;\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(wrap);\n    io.observe(wrap);\n    document.addEventListener(\"visibilitychange\", sync);\n    motion.addEventListener(\"change\", sync);\n    host.addEventListener(\"pointermove\", move, { passive: true });\n    host.addEventListener(\"pointerdown\", down, { passive: true });\n    host.addEventListener(\"pointerleave\", leave);\n    host.addEventListener(\"pointerup\", leave);\n    host.addEventListener(\"pointercancel\", leave);\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      host.removeEventListener(\"pointermove\", move);\n      host.removeEventListener(\"pointerdown\", down);\n      host.removeEventListener(\"pointerleave\", leave);\n      host.removeEventListener(\"pointerup\", leave);\n      host.removeEventListener(\"pointercancel\", leave);\n    };\n  }, [cellSize, gap, palette, color, interval, waveSpeed, seed, speed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-qo5 ${className}`} style={style} {...rest}>\n      <style href=\"hb-bg-acid-squares\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-qo5-c\" aria-hidden=\"true\" />\n      {children != null && <div className=\"hb-qo5-in\">{children}</div>}\n    </div>\n  );\n}\n"
    }
  ]
}