{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-liquid-chrome",
  "type": "registry:component",
  "title": "Liquid Chrome",
  "description": "A slowly warping surface of polished chrome with sky, horizon and ground reflections banded across the folds, lightly tinted by an accent color.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "chrome",
    "liquid",
    "metal",
    "canvas",
    "reflective"
  ],
  "docs": "https://hyperblur.dev/effects/bg-liquid-chrome",
  "files": [
    {
      "path": "registry/hyperblur/bg-liquid-chrome.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-liquid-chrome.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgLiquidChromeProps extends React.HTMLAttributes<HTMLDivElement> {\n  accent?: string;\n  tint?: number;\n  scale?: number;\n  turbulence?: number;\n  speed?: number;\n  children?: React.ReactNode;\n}\n\nconst css = `\n.hb-ve7 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; box-sizing: border-box; background: #0b0c10; }\n.hb-ve7-c { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }\n.hb-ve7-v { position: absolute; inset: 0; background: radial-gradient(120% 90% at 50% 40%, transparent 55%, rgba(0,0,0,0.55) 100%); }\n.hb-ve7-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\nconst STOPS: [number, number, number, number, number][] = [\n  [0, 8, 9, 12, 0],\n  [0.16, 34, 38, 48, 0.2],\n  [0.3, 120, 131, 150, 0.55],\n  [0.4, 214, 224, 238, 0.7],\n  [0.445, 250, 252, 255, 0.2],\n  [0.47, 22, 24, 30, 0],\n  [0.55, 58, 62, 72, 0],\n  [0.7, 128, 120, 112, 0.1],\n  [0.86, 206, 210, 218, 0.35],\n  [1, 255, 255, 255, 0.15],\n];\n\nexport function BgLiquidChrome({\n  accent = \"#7fb3ff\",\n  tint = 0.35,\n  scale = 1,\n  turbulence = 1,\n  speed = 1,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: BgLiquidChromeProps) {\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    if (!wrap || !canvas || !ctx) return;\n    const g: CanvasRenderingContext2D = ctx;\n    const el: HTMLDivElement = wrap;\n    const cv: HTMLCanvasElement = canvas;\n    const buf = document.createElement(\"canvas\");\n    const bctx = buf.getContext(\"2d\");\n    if (!bctx) return;\n    const b: CanvasRenderingContext2D = bctx;\n\n    const ac = rgbOf(accent, [127, 179, 255]);\n    const tk = Math.max(0, Math.min(1, tint));\n    const lut = new Uint8ClampedArray(256 * 3);\n    for (let i = 0; i < 256; i++) {\n      const v = i / 255;\n      let k = 1;\n      while (k < STOPS.length - 1 && STOPS[k][0] < v) k++;\n      const a = STOPS[k - 1];\n      const c = STOPS[k];\n      const f = (v - a[0]) / (c[0] - a[0] || 1);\n      const s = f * f * (3 - 2 * f);\n      const m = (a[4] + (c[4] - a[4]) * s) * tk;\n      for (let j = 0; j < 3; j++) {\n        const base = a[j + 1] + (c[j + 1] - a[j + 1]) * s;\n        lut[i * 3 + j] = base + (ac[j] * (base / 255) * 1.15 - base) * m;\n      }\n    }\n\n    let w = 0;\n    let h = 0;\n    let gw = 0;\n    let gh = 0;\n    let img: ImageData | null = null;\n    let t = 0;\n\n    function render() {\n      if (!img || !gw || !gh) return;\n      const d = img.data;\n      const sc = 2.6 / Math.max(0.3, scale);\n      const amp = 0.62 * Math.max(0, turbulence);\n      const asp = gw / gh;\n      let p = 0;\n      for (let y = 0; y < gh; y++) {\n        const v0 = (y / gh) * sc;\n        for (let x = 0; x < gw; x++) {\n          let u = (x / gw) * sc * asp;\n          let v = v0;\n          u += amp * Math.sin(1.7 * v + t * 0.33);\n          v += amp * Math.cos(1.3 * u - t * 0.27);\n          u += amp * 0.8 * Math.sin(2.1 * v - t * 0.21 + 1.3);\n          v += amp * 0.8 * Math.cos(1.9 * u + t * 0.19 + 0.7);\n          u += amp * 0.5 * Math.sin(3.1 * v + t * 0.41 + 2.1);\n          const val = 0.5 + 0.5 * Math.sin(u * 1.35 + v * 0.85 + 0.6 * Math.sin(v * 1.1 + t * 0.17));\n          const i = Math.min(255, Math.max(0, (val * 255) | 0)) * 3;\n          d[p] = lut[i];\n          d[p + 1] = lut[i + 1];\n          d[p + 2] = lut[i + 2];\n          d[p + 3] = 255;\n          p += 4;\n        }\n      }\n      b.putImageData(img, 0, 0);\n      g.imageSmoothingEnabled = true;\n      g.imageSmoothingQuality = \"high\";\n      g.drawImage(buf, 0, 0, w, h);\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      t = 5;\n      render();\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      const step = Math.max(2, Math.ceil(Math.sqrt((w * h) / 22000)));\n      gw = Math.max(8, Math.ceil(w / step));\n      gh = Math.max(8, Math.ceil(h / step));\n      buf.width = gw;\n      buf.height = gh;\n      img = b.createImageData(gw, gh);\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    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    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    };\n  }, [accent, tint, scale, turbulence, speed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-ve7 ${className}`} style={style} {...rest}>\n      <style href=\"hb-bg-liquid-chrome\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-ve7-c\" aria-hidden=\"true\" />\n      <div className=\"hb-ve7-v\" aria-hidden=\"true\" />\n      {children ? <div className=\"hb-ve7-in\">{children}</div> : null}\n    </div>\n  );\n}\n"
    }
  ]
}