{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"out-of-focus-bokeh-lights-particle-background","type":"registry:block","title":"Out-of-Focus Bokeh Lights","description":"","dependencies":[],"files":[{"path":"components/we-inc/out-of-focus-bokeh-lights-particle-background.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\n// Out-of-Focus Bokeh Lights: a canvas 2D particle background behind a small hero.\n// Sprites are drawn once to small offscreen canvases, motion is scaled by frame\n// time, the loop stops off screen, and reduced motion gets one settled frame.\n// Values worth changing:\nconst LIGHTS_PER_MPX = 48; // out-of-focus lights per million pixels\nconst COLOURS = [\"255,186,104\", \"255,226,182\", \"238,142,118\", \"150,196,214\"]; // light colours, as r,g,b\nconst DRIFT = 1; // how fast the lights float\nconst FOCUS_BREATH = 1; // how much the lens seems to breathe in and out of focus\nconst WARMUP = 1; // frames simulated before the first paint\n\ntype Ptr = { x: number; y: number; on: boolean };\ntype Scene = { update: (dt: number, t: number) => void; draw: (c: CanvasRenderingContext2D, t: number) => void };\n\nfunction glow(size: number, rgb: string, stops: number[][]): HTMLCanvasElement {\n  const c = document.createElement(\"canvas\");\n  c.width = c.height = size;\n  const g = c.getContext(\"2d\")!;\n  const r = size / 2;\n  const grd = g.createRadialGradient(r, r, 0, r, r, r);\n  for (const [o, a] of stops) grd.addColorStop(o, `rgba(${rgb},${a})`);\n  g.fillStyle = grd;\n  g.fillRect(0, 0, size, size);\n  return c;\n}\n\nfunction mount(canvas: HTMLCanvasElement, root: HTMLElement): () => void {\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) return () => {};\n  const still = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  const ptr: Ptr = { x: -1e4, y: -1e4, on: false };\n  let w = 0, h = 0, t = 0, last = 0, raf = 0, seen = true;\n  let scene: Scene | null = null;\n  const fit = () => {\n    const r = canvas.getBoundingClientRect();\n    if (scene && Math.abs(r.width - w) < 1 && Math.abs(r.height - h) < 1) return;\n    const dpr = Math.min(window.devicePixelRatio || 1, 1.5);\n    w = Math.max(1, r.width);\n    h = Math.max(1, r.height);\n    canvas.width = Math.round(w * dpr);\n    canvas.height = Math.round(h * dpr);\n    ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n    scene = createScene(w, h, ptr);\n    for (let i = 0; i < WARMUP; i++) { t += 1 / 30; scene.update(1 / 30, t); }\n    scene.draw(ctx, t);\n  };\n  const frame = (now: number) => {\n    const dt = Math.min(0.05, Math.max(0, (now - last) / 1000));\n    last = now;\n    t += dt;\n    if (scene) { scene.update(dt, t); scene.draw(ctx, t); }\n    raf = requestAnimationFrame(frame);\n  };\n  const run = () => {\n    cancelAnimationFrame(raf);\n    raf = 0;\n    if (!still && seen && !document.hidden) { last = performance.now(); raf = requestAnimationFrame(frame); }\n  };\n  const ro = new ResizeObserver(fit);\n  ro.observe(canvas);\n  const io = new IntersectionObserver((es) => { seen = es[es.length - 1].isIntersecting; run(); });\n  io.observe(canvas);\n  document.addEventListener(\"visibilitychange\", run);\n  fit();\n  run();\n  return () => {\n    cancelAnimationFrame(raf);\n    ro.disconnect();\n    io.disconnect();\n    document.removeEventListener(\"visibilitychange\", run);\n  };\n}\n\nfunction createScene(w: number, h: number, _ptr: Ptr): Scene {\n  const area = (w * h) / 1e6;\n  // Real lens bokeh is a flat disc with a slightly brighter rim, not a soft blob.\n  const disc = (rgb: string, edge: number) => {\n    const c = document.createElement(\"canvas\");\n    c.width = c.height = 128;\n    const g = c.getContext(\"2d\")!;\n    const grd = g.createRadialGradient(64, 64, 0, 64, 64, 62);\n    grd.addColorStop(0, `rgba(${rgb},0.30)`);\n    grd.addColorStop(0.78, `rgba(${rgb},0.36)`);\n    grd.addColorStop(0.93 - edge, `rgba(${rgb},0.62)`);\n    grd.addColorStop(1, `rgba(${rgb},0)`);\n    g.fillStyle = grd;\n    g.beginPath(); g.arc(64, 64, 62, 0, 7); g.fill();\n    return c;\n  };\n  const sharp = COLOURS.map((rgb) => disc(rgb, 0));\n  const soft = COLOURS.map((rgb) => glow(128, rgb, [[0, 0.3], [0.6, 0.22], [1, 0]]));\n  const ps = Array.from({ length: Math.max(14, Math.min(90, Math.round(area * LIGHTS_PER_MPX))) }, () => {\n    const z = Math.random();\n    return { x: Math.random() * w, y: h * (0.15 + Math.random() * 0.9), z, k: Math.floor(Math.random() * COLOURS.length), s: Math.random() * 99, a: 0.35 + Math.random() * 0.55 };\n  }).sort((a, b) => a.z - b.z);\n  return {\n    update(dt, t) {\n      for (const p of ps) {\n        p.x += (3 + p.z * 9) * DRIFT * dt;\n        p.y += Math.sin(t * 0.2 + p.s) * 3 * DRIFT * dt;\n        if (p.x > w + 120) { p.x = -120; p.y = h * (0.15 + Math.random() * 0.9); }\n      }\n    },\n    draw(c, t) {\n      c.clearRect(0, 0, w, h);\n      c.globalCompositeOperation = \"lighter\";\n      const focus = Math.sin(t * 0.18) * FOCUS_BREATH;\n      for (const p of ps) {\n        const s = (24 + p.z * 120) * (1 + focus * 0.1 * p.z);\n        c.globalAlpha = p.a * (0.55 + 0.45 * Math.sin(t * 0.5 + p.s)) * (1 - p.z * 0.35);\n        c.drawImage(p.z > 0.7 ? soft[p.k] : sharp[p.k], p.x - s / 2, p.y - s / 2, s, s);\n      }\n      c.globalAlpha = 1;\n      c.globalCompositeOperation = \"source-over\";\n    },\n  };\n}\n\nexport default function OutOfFocusBokehLights() {\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const rootRef = useRef<HTMLElement>(null);\n\n  useEffect(() => {\n    if (!canvasRef.current || !rootRef.current) return;\n    return mount(canvasRef.current, rootRef.current);\n  }, []);\n\n  return (\n    <section ref={rootRef} className=\"bkh-bg relative isolate flex min-h-[560px] items-center overflow-hidden px-6 py-20 sm:px-12\">\n      <style>{`.bkh-bg{background:radial-gradient(80% 60% at 50% 120%, #3a2a20 0%, rgba(58,42,32,0) 70%), linear-gradient(180deg, #0c131d 0%, #141c28 55%, #1d1c22 100%)}.bkh-scrim{background:radial-gradient(45% 55% at 50% 50%, rgba(12,19,29,0.6) 0%, rgba(12,19,29,0) 80%)}`}</style>\n      <canvas ref={canvasRef} aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 -z-10 h-full w-full\" />\n      <div aria-hidden=\"true\" className=\"bkh-scrim pointer-events-none absolute inset-0 -z-10\" />\n      <div className=\"mx-auto w-full max-w-6xl\">\n        <div className=\"mx-auto max-w-2xl text-center\">\n          <p className=\"text-sm font-semibold uppercase tracking-[0.14em] text-[#f0c992]\">Lamplight Wedding Films</p>\n          <h2 className=\"mt-4 text-4xl font-semibold leading-[1.08] tracking-tight text-[#fdf3e7] sm:text-5xl\">The first dance, the toasts and the light after sunset.</h2>\n          <p className=\"mt-5 text-lg leading-relaxed text-[#dccab6]\">Two filmmakers, natural sound and a finished film you will want to watch again every anniversary.</p>\n          <a\n            href=\"#\"\n            className=\"mt-8 inline-flex h-12 items-center rounded-full bg-[#f3c68b] px-6 text-sm font-semibold text-[#1d140c] transition hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#fdf3e7] focus-visible:ring-offset-2 focus-visible:ring-offset-[#141b26]\"\n          >\n            Check our availability\n          </a>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
