{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bg-glow-orbs",
  "type": "registry:component",
  "title": "Glow Orbs",
  "description": "Glossy lit spheres with halos that float on slow orbits and change depth, reflected on a dark polished floor below them.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "overlay",
    "background",
    "orbs",
    "spheres",
    "reflection",
    "canvas",
    "glow"
  ],
  "docs": "https://hyperblur.dev/effects/bg-glow-orbs",
  "files": [
    {
      "path": "registry/hyperblur/bg-glow-orbs.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/bg-glow-orbs.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface BgGlowOrbsProps extends React.HTMLAttributes<HTMLDivElement> {\n  colors?: string[];\n  background?: string;\n  floor?: boolean;\n  size?: number;\n  speed?: number;\n  children?: React.ReactNode;\n}\n\nconst css = `\n.hb-vd12 { position: absolute; inset: 0; overflow: hidden; pointer-events: none; box-sizing: border-box; }\n.hb-vd12-c { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }\n.hb-vd12-in { position: relative; z-index: 1; width: 100%; height: 100%; pointer-events: auto; font-family: inherit; }\n`;\n\nconst defaultColors = [\"#2f7bff\", \"#9b6bff\", \"#38e1c6\", \"#ff7a59\"];\n\nfunction hash(i: number) {\n  let x = Math.imul(i ^ 0x3243f6a8, 0x885a308d);\n  x ^= x >>> 15;\n  x = Math.imul(x, 0x31319812);\n  x ^= x >>> 13;\n  return (x >>> 0) / 4294967296;\n}\n\nfunction rgb(hex: string): [number, number, number] {\n  let s = hex.replace(\"#\", \"\");\n  if (s.length === 3) s = s.split(\"\").map((c) => c + c).join(\"\");\n  const n = parseInt(s.slice(0, 6), 16);\n  if (Number.isNaN(n)) return [120, 160, 255];\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\nexport function BgGlowOrbs({\n  colors = defaultColors,\n  background = \"#050509\",\n  floor = true,\n  size = 1,\n  speed = 1,\n  children,\n  className = \"\",\n  style,\n  ...rest\n}: BgGlowOrbsProps) {\n  const wrapRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const colorKey = (colors.length ? colors : defaultColors).join(\"|\");\n\n  React.useEffect(() => {\n    const wrap = wrapRef.current;\n    const canvas = canvasRef.current;\n    const context = canvas?.getContext(\"2d\");\n    if (!wrap || !canvas || !context) return;\n    const el: HTMLDivElement = wrap;\n    const cv: HTMLCanvasElement = canvas;\n    const g: CanvasRenderingContext2D = context;\n    const motion = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const palette = colorKey.split(\"|\").slice(0, 8).map(rgb);\n    const orbs = palette.map((c, i) => ({\n      c,\n      a: 0.11 + 0.08 * hash(i * 6 + 1),\n      b: 0.15 + 0.1 * hash(i * 6 + 2),\n      cz: 0.09 + 0.07 * hash(i * 6 + 3),\n      p1: hash(i * 6 + 4) * 6.28,\n      p2: hash(i * 6 + 5) * 6.28,\n      s: 0.8 + 0.4 * hash(i * 6 + 6),\n      x: 0,\n      y: 0,\n      r: 0,\n      z: 0,\n    }));\n    const tone = rgb(background);\n    const rgba = (c: [number, number, number], a: number) => `rgba(${c[0]},${c[1]},${c[2]},${a})`;\n    const shade = (c: [number, number, number], k: number): [number, number, number] => [\n      Math.round(c[0] * k),\n      Math.round(c[1] * k),\n      Math.round(c[2] * k),\n    ];\n    const tint = (c: [number, number, number], k: number): [number, number, number] => [\n      Math.round(c[0] + (255 - c[0]) * k),\n      Math.round(c[1] + (255 - c[1]) * k),\n      Math.round(c[2] + (255 - c[2]) * k),\n    ];\n    let w = 0;\n    let h = 0;\n    let t = 0;\n    let raf = 0;\n    let prev = 0;\n    let visible = true;\n\n    function place() {\n      const unit = Math.min(w, h) * 0.13 * size;\n      const n = orbs.length;\n      orbs.forEach((o, i) => {\n        const lane = n > 1 ? i / (n - 1) : 0.5;\n        o.z = 0.5 + 0.5 * Math.sin(t * o.cz + o.p2);\n        o.x = w * (0.14 + lane * 0.72 + 0.12 * Math.sin(t * o.a + o.p1));\n        o.y = h * ((floor ? 0.4 : 0.5) + 0.12 * Math.sin(t * o.b + o.p2 * 1.7));\n        o.r = unit * o.s * (0.7 + 0.5 * o.z);\n      });\n    }\n\n    function body(o: (typeof orbs)[number], x: number, y: number, r: number, alpha: number) {\n      g.globalAlpha = alpha;\n      const halo = g.createRadialGradient(x, y, r * 0.6, x, y, r * 3.2);\n      halo.addColorStop(0, rgba(o.c, 0.42));\n      halo.addColorStop(1, rgba(o.c, 0));\n      g.globalCompositeOperation = \"lighter\";\n      g.fillStyle = halo;\n      g.beginPath();\n      g.arc(x, y, r * 3.2, 0, Math.PI * 2);\n      g.fill();\n      g.globalCompositeOperation = \"source-over\";\n      const sphere = g.createRadialGradient(x - r * 0.38, y - r * 0.42, r * 0.04, x, y, r);\n      sphere.addColorStop(0, rgba(tint(o.c, 0.85), 1));\n      sphere.addColorStop(0.22, rgba(tint(o.c, 0.35), 1));\n      sphere.addColorStop(0.62, rgba(o.c, 1));\n      sphere.addColorStop(1, rgba(shade(o.c, 0.28), 1));\n      g.fillStyle = sphere;\n      g.beginPath();\n      g.arc(x, y, r, 0, Math.PI * 2);\n      g.fill();\n      const rim = g.createRadialGradient(x + r * 0.35, y + r * 0.5, r * 0.55, x, y, r * 1.02);\n      rim.addColorStop(0, rgba(o.c, 0));\n      rim.addColorStop(0.85, rgba(o.c, 0));\n      rim.addColorStop(1, rgba(tint(o.c, 0.5), 0.75));\n      g.globalCompositeOperation = \"lighter\";\n      g.fillStyle = rim;\n      g.beginPath();\n      g.arc(x, y, r, 0, Math.PI * 2);\n      g.fill();\n      g.globalAlpha = alpha * 0.85;\n      g.fillStyle = \"rgba(255,255,255,0.9)\";\n      g.beginPath();\n      g.ellipse(x - r * 0.36, y - r * 0.46, r * 0.16, r * 0.09, -0.6, 0, Math.PI * 2);\n      g.fill();\n      g.globalCompositeOperation = \"source-over\";\n    }\n\n    function draw() {\n      if (!w || !h) return;\n      place();\n      g.globalCompositeOperation = \"source-over\";\n      g.globalAlpha = 1;\n      g.fillStyle = background;\n      g.fillRect(0, 0, w, h);\n      const fy = h * 0.72;\n      const sorted = [...orbs].sort((a, b) => a.z - b.z);\n      if (floor) {\n        const sheen = g.createLinearGradient(0, fy, 0, h);\n        sheen.addColorStop(0, \"rgba(255,255,255,0.05)\");\n        sheen.addColorStop(1, \"rgba(255,255,255,0)\");\n        g.fillStyle = sheen;\n        g.fillRect(0, fy, w, h - fy);\n        g.save();\n        g.beginPath();\n        g.rect(0, fy, w, h - fy);\n        g.clip();\n        for (const o of sorted) {\n          const ry = fy + (fy - o.y) * 0.55;\n          g.save();\n          g.translate(o.x, ry);\n          g.scale(1, -0.55);\n          body(o, 0, 0, o.r, 0.32);\n          g.restore();\n        }\n        const fade = g.createLinearGradient(0, fy, 0, h);\n        fade.addColorStop(0, rgba(tone, 0.25));\n        fade.addColorStop(0.7, rgba(tone, 0.95));\n        fade.addColorStop(1, rgba(tone, 1));\n        g.globalAlpha = 1;\n        g.fillStyle = fade;\n        g.fillRect(0, fy, w, h - fy);\n        g.restore();\n        const line = g.createLinearGradient(0, 0, w, 0);\n        line.addColorStop(0, \"rgba(255,255,255,0)\");\n        line.addColorStop(0.5, \"rgba(255,255,255,0.22)\");\n        line.addColorStop(1, \"rgba(255,255,255,0)\");\n        g.fillStyle = line;\n        g.fillRect(0, fy, w, 1);\n        for (const o of sorted) {\n          const shadow = g.createRadialGradient(o.x, fy + 2, 0, o.x, fy + 2, o.r * 1.4);\n          shadow.addColorStop(0, rgba(o.c, 0.35));\n          shadow.addColorStop(1, rgba(o.c, 0));\n          g.globalCompositeOperation = \"lighter\";\n          g.fillStyle = shadow;\n          g.fillRect(o.x - o.r * 1.4, fy - o.r * 0.3, o.r * 2.8, o.r * 0.6);\n          g.globalCompositeOperation = \"source-over\";\n        }\n      }\n      for (const o of sorted) body(o, o.x, o.y, o.r, 1);\n      g.globalAlpha = 1;\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      if (motion.matches) t = 5;\n      draw();\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      draw();\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) {\n        t = 5;\n        draw();\n      }\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  }, [colorKey, background, floor, size, speed]);\n\n  return (\n    <div ref={wrapRef} className={`hb-vd12 ${className}`} style={style} {...rest}>\n      <style href=\"hb-bg-glow-orbs\" precedence=\"default\">{css}</style>\n      <canvas ref={canvasRef} className=\"hb-vd12-c\" aria-hidden=\"true\" />\n      {children ? <div className=\"hb-vd12-in\">{children}</div> : null}\n    </div>\n  );\n}\n"
    }
  ]
}