{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"ember-glow-rising-mesh-gradient-background","type":"registry:block","title":"Ember Glow Rising Mesh","description":"","dependencies":[],"files":[{"path":"components/we-inc/ember-glow-rising-mesh-gradient-background.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\n// Ember colours as [r, g, b]; they rise and fade over the charcoal.\nconst EMBERS = [\n  [168, 64, 24],\n  [196, 98, 36],\n  [120, 36, 18],\n  [210, 128, 52],\n  [150, 52, 22],\n  [184, 82, 30],\n  [132, 44, 20],\n];\n// The charcoal behind everything.\nconst CHARCOAL = [20, 13, 11];\n// Seconds for an ember to rise the full height.\nconst RISE = 22;\n// Overall brightness of the embers (0 to 1).\nconst HEAT = 0.62;\n\nconst css = `\n.emb-grain{background-image:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url%28%23g%29'/%3E%3C/svg%3E\");mix-blend-mode:overlay;opacity:.3}\n`;\n\nexport default function EmberGlowRisingMesh() {\n  const rootRef = useRef<HTMLElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n\n  useEffect(() => {\n    const root = rootRef.current;\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    if (!root || !canvas || !ctx) return;\n    const still = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    // Drawn small and stretched smoothly by the browser.\n    const W = 110;\n    let H = 70;\n    let aspect = 1.6;\n    let img = ctx.createImageData(W, H);\n    let raf = 0;\n    let onScreen = true;\n    const embers = EMBERS.map((col, i) => ({ col, lane: 0.08 + ((i * 0.37) % 1) * 0.86, phase: i / EMBERS.length, sway: 0.5 + (i % 3) * 0.3, r: 0.16 + (i % 4) * 0.04 }));\n\n    const draw = (t: number) => {\n      const pos = embers.map((e) => {\n        const p = (t / RISE + e.phase) % 1;\n        // Bright low down, fading out as it climbs.\n        const life = Math.sin(Math.PI * Math.min(1, p * 1.15)) * (1 - p * 0.55);\n        return { x: (e.lane + 0.06 * Math.sin(t * 0.3 * e.sway + e.phase * 9)) * aspect, y: 1.15 - p * 1.35, k: 1 / (e.r * e.r), a: life * HEAT, col: e.col };\n      });\n      const d = img.data;\n      let o = 0;\n      for (let y = 0; y < H; y++) {\n        const ny = y / (H - 1);\n        // A steady glow from the coals below the frame.\n        const bed = Math.exp(-(1 - ny) * 3.2) * 0.55;\n        for (let x = 0; x < W; x++) {\n          const nx = (x / (W - 1)) * aspect;\n          let r = CHARCOAL[0] + 150 * bed, g = CHARCOAL[1] + 54 * bed, b = CHARCOAL[2] + 22 * bed;\n          for (const p of pos) {\n            const dx = nx - p.x, dy = ny - p.y;\n            const w = p.a * Math.exp(-(dx * dx + dy * dy) * p.k);\n            r += p.col[0] * w; g += p.col[1] * w; b += p.col[2] * w;\n          }\n          d[o] = r; d[o + 1] = g; d[o + 2] = b; d[o + 3] = 255;\n          o += 4;\n        }\n      }\n      ctx.putImageData(img, 0, 0);\n    };\n\n    const start = performance.now();\n    const loop = (now: number) => {\n      draw((now - start) / 1000 + 9);\n      if (onScreen && !still) raf = requestAnimationFrame(loop);\n    };\n    const resize = () => {\n      const box = root.getBoundingClientRect();\n      aspect = Math.max(0.4, box.width / Math.max(1, box.height));\n      H = Math.max(30, Math.min(180, Math.round(W / aspect)));\n      canvas.width = W; canvas.height = H;\n      img = ctx.createImageData(W, H);\n      draw((performance.now() - start) / 1000 + 9);\n    };\n    const ro = new ResizeObserver(resize);\n    ro.observe(root);\n    const io = new IntersectionObserver(([e]) => {\n      onScreen = e.isIntersecting;\n      cancelAnimationFrame(raf);\n      if (onScreen && !still) raf = requestAnimationFrame(loop);\n    });\n    io.observe(root);\n    resize();\n    return () => { cancelAnimationFrame(raf); ro.disconnect(); io.disconnect(); };\n  }, []);\n\n  return (\n    <section ref={rootRef} className=\"relative isolate flex min-h-[600px] items-center overflow-hidden bg-[#140d0b]\">\n      <style>{css}</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=\"emb-grain pointer-events-none absolute inset-0 -z-10\" />\n      <div className=\"mx-auto w-full max-w-3xl px-6 py-24 text-center sm:px-10\">\n        <p className=\"text-[13px] font-semibold uppercase tracking-[0.22em] text-[#f0b98c]\">Coalhouse &middot; Wood-fired kitchen</p>\n        <h1 className=\"mt-5 text-4xl font-semibold leading-[1.08] tracking-tight text-[#fff5ec] sm:text-6xl\">Everything on the menu meets the fire at least once.</h1>\n        <p className=\"mx-auto mt-5 max-w-[32rem] text-lg leading-relaxed text-[#ead8c9]\">Oak and cherry wood, a hearth that stays lit from noon, and a counter where you can watch it all happen.</p>\n        <a href=\"#\" className=\"mt-8 inline-flex h-12 items-center rounded-full bg-[#f6e3cf] px-7 text-[15px] font-semibold text-[#2a120a] hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#f6e3cf] focus-visible:ring-offset-2 focus-visible:ring-offset-[#140d0b]\">Book a table</a>\n      </div>\n    </section>\n  );\n}\n"}]}
