{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"lava-lamp-background-with-soft-wax-rising-and-sinking-in-warm-glass","type":"registry:block","title":"Lava Lamp Wax","description":"","dependencies":[],"files":[{"path":"components/we-inc/lava-lamp-background-with-soft-wax-rising-and-sinking-in-warm-glass.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\n// The values worth changing. Colours are [red, green, blue] from 0 to 255.\nconst SETTINGS = {\n  blobs: 7, // pieces of wax in the lamp\n  hot: [255, 168, 92], // the bright middle of the wax\n  cool: [214, 72, 44], // the edge of the wax\n  glass: [34, 14, 12], // the liquid around it\n  speed: 1, // how fast the wax rises and sinks\n  cell: 4, // CSS pixels per computed sample; higher is cheaper and softer\n};\n\nconst SCENE: any = {\n  start: 12,\n  still: 12,\n  fps: 30,\n  init(ctx: any, w: any, h: any) {\n    const gw = Math.max(8, Math.ceil(w / SETTINGS.cell));\n    const gh = Math.max(8, Math.ceil(h / SETTINGS.cell));\n    const off = document.createElement(\"canvas\");\n    off.width = gw;\n    off.height = gh;\n    const octx = off.getContext(\"2d\");\n    const narrow = w < 700;\n    const blobs: any[] = [];\n    for (let i = 0; i < SETTINGS.blobs; i++) {\n      blobs.push({\n        // On wide blocks the wax stays right of the copy; on phones it lives in the lower half.\n        x: narrow ? 0.15 + Math.random() * 0.7 : 0.55 + Math.random() * 0.38,\n        r: (narrow ? 0.07 : 0.055) + Math.random() * 0.04,\n        period: 22 + Math.random() * 18,\n        phase: Math.random() * 6.28,\n        sway: 0.02 + Math.random() * 0.03,\n      });\n    }\n    return { gw, gh, off, octx, img: octx.createImageData(gw, gh), blobs, narrow };\n  },\n  draw(ctx: any, w: any, h: any, time: any, st: any) {\n    const t = time * SETTINGS.speed;\n    const { gw, gh, img, blobs, narrow } = st;\n    const aspect = gw / gh;\n    const top = narrow ? 0.5 : 0.06;\n    // Each blob rises while warm and sinks while cool: a slow, eased up-and-down loop.\n    const pos = blobs.map((b: any) => {\n      const cyc = Math.sin((t / b.period) * 6.28 + b.phase);\n      const y = top + (1 - top) * (0.5 - 0.42 * cyc);\n      const x = b.x + Math.sin(t * 0.13 + b.phase) * b.sway;\n      return [x * aspect, y, b.r * (1 + 0.12 * Math.sin(t * 0.3 + b.phase)) * (narrow ? 1 : 1)];\n    });\n    // Pools of wax resting on the bottom and clinging to the top.\n    pos.push([(narrow ? 0.5 : 0.74) * aspect, 1.08, narrow ? 0.16 : 0.12]);\n    const data = img.data;\n    const [hr, hg, hb] = SETTINGS.hot;\n    const [cr, cg, cb] = SETTINGS.cool;\n    const [gr, gg, gb] = SETTINGS.glass;\n    let o = 0;\n    for (let j = 0; j < gh; j++) {\n      const y = j / gh;\n      for (let i = 0; i < gw; i++) {\n        const x = (i / gh);\n        let f = 0;\n        for (let k = 0; k < pos.length; k++) {\n          const p = pos[k];\n          const dx = x - p[0];\n          const dy = y - p[1];\n          f += (p[2] * p[2]) / (dx * dx + dy * dy + 0.0004);\n        }\n        // Glass: dark, with a warm glow that grows near the wax.\n        const glow = Math.min(1, f * 0.22);\n        let r = gr + 120 * glow * glow;\n        let g = gg + 34 * glow * glow;\n        let b = gb + 14 * glow * glow;\n        const edge = Math.min(1, Math.max(0, (f - 0.96) / 0.08));\n        if (edge > 0) {\n          const core = Math.min(1, (f - 1) / 2.2);\n          const m = core < 0 ? 0 : core;\n          const shade = 0.82 + 0.18 * (1 - y);\n          const wr = (cr + (hr - cr) * m) * shade;\n          const wg = (cg + (hg - cg) * m) * shade;\n          const wb = (cb + (hb - cb) * m) * shade;\n          r += (wr - r) * edge;\n          g += (wg - g) * edge;\n          b += (wb - b) * edge;\n        }\n        data[o] = r;\n        data[o + 1] = g;\n        data[o + 2] = b;\n        data[o + 3] = 255;\n        o += 4;\n      }\n    }\n    st.octx.putImageData(img, 0, 0);\n    ctx.imageSmoothingEnabled = true;\n    ctx.imageSmoothingQuality = \"high\";\n    ctx.drawImage(st.off, 0, 0, w, h);\n  },\n};\n\n// Runs a scene on a canvas: sizes it to the block, pauses off screen and in hidden tabs, cleans up after itself.\nfunction runScene(root: any, canvas: any, scene: any, reduced: boolean) {\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) return () => {};\n  let w = 0;\n  let h = 0;\n  let st: any = null;\n  let raf = 0;\n  let last = 0;\n  let acc = 0;\n  let onScreen = true;\n  let time = reduced ? (scene.still ?? scene.start ?? 0) : (scene.start ?? 0);\n  const ptr: any = { x: 0, y: 0, on: false, down: 0 };\n  const step = 1 / (scene.fps || 60);\n  const resize = () => {\n    const r = root.getBoundingClientRect();\n    const nw = Math.max(1, Math.round(r.width));\n    const nh = Math.max(1, Math.round(r.height));\n    if (nw === w && nh === h && st) return;\n    w = nw;\n    h = nh;\n    // Device pixels are capped at 1.5 and scaled by the scene's own quality factor.\n    const d = Math.min(window.devicePixelRatio || 1, 1.5) * (scene.scale || 1);\n    canvas.width = Math.max(1, Math.round(w * d));\n    canvas.height = Math.max(1, Math.round(h * d));\n    ctx.setTransform(canvas.width / w, 0, 0, canvas.height / h, 0, 0);\n    st = scene.init(ctx, w, h, canvas.width / w);\n    scene.draw(ctx, w, h, time, st, ptr, 0);\n  };\n  const tick = (now: number) => {\n    raf = requestAnimationFrame(tick);\n    const dt = last ? Math.min(0.1, (now - last) / 1000) : step;\n    last = now;\n    acc += dt;\n    if (acc < step * 0.95) return;\n    const used = Math.min(acc, 0.1);\n    acc = 0;\n    time += used;\n    scene.draw(ctx, w, h, time, st, ptr, used);\n  };\n  const play = () => {\n    if (raf || reduced || !onScreen || document.hidden) return;\n    last = 0;\n    raf = requestAnimationFrame(tick);\n  };\n  const stop = () => {\n    cancelAnimationFrame(raf);\n    raf = 0;\n  };\n  const ro = new ResizeObserver(resize);\n  ro.observe(root);\n  const io = new IntersectionObserver((entries: any) => {\n    onScreen = entries[0].isIntersecting;\n    if (onScreen) play();\n    else stop();\n  });\n  io.observe(root);\n  const onVis = () => (document.hidden ? stop() : play());\n  const onMove = (e: any) => {\n    const r = root.getBoundingClientRect();\n    ptr.x = e.clientX - r.left;\n    ptr.y = e.clientY - r.top;\n    ptr.on = true;\n  };\n  const onLeave = () => {\n    ptr.on = false;\n  };\n  const onDown = (e: any) => {\n    onMove(e);\n    ptr.down += 1;\n  };\n  document.addEventListener(\"visibilitychange\", onVis);\n  root.addEventListener(\"pointermove\", onMove);\n  root.addEventListener(\"pointerleave\", onLeave);\n  root.addEventListener(\"pointerdown\", onDown);\n  resize();\n  play();\n  return () => {\n    stop();\n    ro.disconnect();\n    io.disconnect();\n    document.removeEventListener(\"visibilitychange\", onVis);\n    root.removeEventListener(\"pointermove\", onMove);\n    root.removeEventListener(\"pointerleave\", onLeave);\n    root.removeEventListener(\"pointerdown\", onDown);\n  };\n}\n\nexport default function LavaLampWaxBackground() {\n  const rootRef = useRef<HTMLElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  useEffect(() => {\n    const root = rootRef.current;\n    const canvas = canvasRef.current;\n    if (!root || !canvas) return;\n    // Visitors who prefer reduced motion get one settled frame and no loop.\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    return runScene(root, canvas, SCENE, reduced);\n  }, []);\n\n  return (\n    <section ref={rootRef} className=\"relative h-[640px] w-full overflow-hidden bg-[#220e0c] text-[#fbeee2]\">\n      <canvas ref={canvasRef} aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 block h-full w-full\" />\n      <div className=\"relative z-10 mx-auto flex h-full max-w-6xl flex-col justify-start items-start text-left px-6 py-14 sm:px-10\">\n        <div className=\"max-w-xl\">\n          <p className=\"text-xs font-semibold uppercase tracking-[0.2em] text-[#ffb27a]\">Lowtide Records</p>\n          <h2 className=\"mt-4 text-4xl font-semibold leading-[1.05] tracking-tight sm:text-5xl lg:text-6xl\">Late-night listening room and used vinyl.</h2>\n          <p className=\"mt-5 text-base leading-relaxed text-[#e8cfc0] sm:text-lg\">Pull a record from the crates, take a booth and let the needle drop. Open until one on weekends.</p>\n          <a href=\"#\" className=\"mt-8 inline-flex h-12 items-center rounded-full bg-[#ffb27a] px-6 text-sm font-semibold text-[#2a100c] transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#ffb27a] focus-visible:ring-offset-2 focus-visible:ring-offset-[#220e0c]\">See tonight’s sessions</a>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
