{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"desert-heat-haze-background-with-a-shimmering-horizon-and-mesas","type":"registry:block","title":"Desert Heat Haze Horizon","description":"","dependencies":[],"files":[{"path":"components/we-inc/desert-heat-haze-background-with-a-shimmering-horizon-and-mesas.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\n// The values worth changing.\nconst SETTINGS = {\n  horizon: 0.68, // where the land meets the sky, as a share of the height\n  shimmer: 7, // how far the hot air bends the horizon, in pixels\n  band: 90, // how tall the shimmering band is, in pixels\n  skyTop: \"#f6ead9\", // the pale sky behind the headline\n  skyLow: \"#f4c595\", // the warm glow at the horizon\n  sand: \"#d9a172\", // near dunes\n};\n\nconst SCENE: any = {\n  start: 0,\n  still: 0,\n  scale: 0.8,\n  init(ctx: any, w: any, h: any, k: any) {\n    // Paint the whole landscape once; each frame only re-draws it in thin, shifted strips.\n    const off = document.createElement(\"canvas\");\n    off.width = Math.round(w * k);\n    off.height = Math.round(h * k);\n    const c = off.getContext(\"2d\");\n    c.scale(k, k);\n    const hy = Math.round(h * SETTINGS.horizon);\n    const sky = c.createLinearGradient(0, 0, 0, hy);\n    sky.addColorStop(0, SETTINGS.skyTop);\n    sky.addColorStop(0.55, \"#f6dcbc\");\n    sky.addColorStop(1, SETTINGS.skyLow);\n    c.fillStyle = sky;\n    c.fillRect(0, 0, w, hy + 1);\n    const sx = w * (w < 700 ? 0.74 : 0.7);\n    const sun = c.createRadialGradient(sx, hy - 18, 0, sx, hy - 18, Math.max(w, h) * 0.35);\n    sun.addColorStop(0, \"rgba(255,248,232,0.95)\");\n    sun.addColorStop(0.06, \"rgba(255,240,214,0.85)\");\n    sun.addColorStop(0.07, \"rgba(255,228,190,0.45)\");\n    sun.addColorStop(1, \"rgba(255,214,170,0)\");\n    c.fillStyle = sun;\n    c.fillRect(0, 0, w, hy + 1);\n    // Two ranges of mesas, the far one paler from the haze.\n    const range = (seed: any, top: any, colour: any, rough: any) => {\n      c.beginPath();\n      c.moveTo(0, hy + 1);\n      let y = top;\n      for (let x = 0; x <= w + 8; x += 8) {\n        const n = Math.sin(x * 0.011 + seed) + Math.sin(x * 0.027 + seed * 2.1) * 0.5;\n        const flat = n > 0.55 ? -rough : n > -0.2 ? -rough * 0.35 : 0;\n        y += (hy + flat - y) * 0.35;\n        c.lineTo(x, y);\n      }\n      c.lineTo(w, hy + 1);\n      c.closePath();\n      c.fillStyle = colour;\n      c.fill();\n    };\n    range(1.3, hy, \"rgba(205,150,132,0.55)\", Math.min(46, h * 0.07));\n    range(4.1, hy, \"rgba(166,108,96,0.75)\", Math.min(26, h * 0.04));\n    const ground = c.createLinearGradient(0, hy, 0, h);\n    ground.addColorStop(0, \"#efc49a\");\n    ground.addColorStop(0.08, \"#e8b689\");\n    ground.addColorStop(1, SETTINGS.sand);\n    c.fillStyle = ground;\n    c.fillRect(0, hy, w, h - hy);\n    // A mirage: a pale strip of sky reflected just below the horizon.\n    const mir = c.createLinearGradient(0, hy, 0, hy + 22);\n    mir.addColorStop(0, \"rgba(248,214,176,0.9)\");\n    mir.addColorStop(1, \"rgba(248,214,176,0)\");\n    c.fillStyle = mir;\n    c.fillRect(0, hy, w, 22);\n    // Soft dune ridges, lighter on the lit side.\n    for (let i = 0; i < 7; i++) {\n      const y0 = hy + 30 + i * i * 7 + i * 10;\n      c.beginPath();\n      for (let x = -20; x <= w + 20; x += 10) {\n        const y = y0 + Math.sin(x * (0.004 + i * 0.0007) + i * 1.7) * (6 + i * 3);\n        if (x === -20) c.moveTo(x, y);\n        else c.lineTo(x, y);\n      }\n      c.strokeStyle = `rgba(255,236,210,${0.28 - i * 0.02})`;\n      c.lineWidth = 1.2 + i * 0.4;\n      c.stroke();\n      c.strokeStyle = `rgba(150,90,60,${0.1})`;\n      c.lineWidth = 1;\n      c.translate(0, 3 + i);\n      c.stroke();\n      c.setTransform(k, 0, 0, k, 0, 0);\n    }\n    return { off, k, hy };\n  },\n  draw(ctx: any, w: any, h: any, t: any, st: any) {\n    const { off, k, hy } = st;\n    const top = Math.max(0, hy - SETTINGS.band * 0.6);\n    const bottom = Math.min(h, hy + SETTINGS.band * 0.4);\n    ctx.drawImage(off, 0, 0, off.width, top * k, 0, 0, w, top);\n    ctx.drawImage(off, 0, bottom * k, off.width, off.height - bottom * k, 0, bottom, w, h - bottom);\n    // Hot air: each strip near the horizon slides sideways and stretches a little, strongest at the horizon itself.\n    for (let y = top; y < bottom; y += 2) {\n      const near = 1 - Math.abs(y - hy) / (SETTINGS.band * 0.6);\n      const amp = SETTINGS.shimmer * near * near;\n      const dx = amp * (Math.sin(y * 0.33 + t * 3.1) * 0.7 + Math.sin(y * 0.09 - t * 1.6) * 0.5);\n      const dy = amp * 0.3 * Math.sin(y * 0.21 + t * 2.3);\n      ctx.drawImage(off, 0, (y + dy) * k, off.width, 2 * k, dx - 8, y, w + 16, 2.2);\n    }\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 DesertHeatHazeBackground() {\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-[660px] w-full overflow-hidden bg-[#f6ead9] text-[#3a2416]\">\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-[#8c4a26]\">Saltpan Overland</p>\n          <h2 className=\"mt-4 text-4xl font-semibold leading-[1.05] tracking-tight sm:text-5xl lg:text-6xl\">Four slow days across the salt flats.</h2>\n          <p className=\"mt-5 text-base leading-relaxed text-[#5b3d2a] sm:text-lg\">Small-group crossings with camp cooks, star charts and a guide who grew up on the edge of the pan.</p>\n          <a href=\"#\" className=\"mt-8 inline-flex h-12 items-center rounded-full bg-[#3a2416] px-6 text-sm font-semibold text-[#f8efe2] transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3a2416] focus-visible:ring-offset-2 focus-visible:ring-offset-[#f6ead9]\">See departure dates</a>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
