{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"wind-across-wheat-field-rows-canvas-background","type":"registry:block","title":"Wind Across a Wheat Field","description":"","dependencies":[],"files":[{"path":"components/we-inc/wind-across-wheat-field-rows-canvas-background.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\n// Rows of wheat stalks from the horizon to your feet. A gust rolls across the field, bending\n// each stalk and lifting its colour as the paler undersides turn up, then the field settles.\n// Change these: field colours (rgb), number of rows, gust speed (seconds per crossing), horizon.\nconst FAR = [216, 199, 146];\nconst NEAR = [196, 156, 84];\nconst LIGHT = [252, 241, 204];\nconst ROWS = 34;\nconst GUST_SECONDS = 7;\nconst HORIZON = 0.5; // fraction of the height\n\nexport default function WindAcrossWheatField() {\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    if (!canvas || !ctx) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let w = 0;\n    let h = 0;\n    let raf = 0;\n    let onScreen = true;\n    const born = performance.now();\n    const cleanups: (() => void)[] = [];\n\n    const draw = (t: number) => {\n      ctx.clearRect(0, 0, w, h);\n      const top = h * HORIZON;\n      const crossing = w * 1.6;\n      const gusts = [((t / GUST_SECONDS) % 1) * crossing - w * 0.3, (((t + GUST_SECONDS * 0.55) / GUST_SECONDS) % 1) * crossing - w * 0.3];\n      for (let r = 0; r < ROWS; r++) {\n        const z = (r + 1) / ROWS;\n        const base = top + (h - top + 30) * Math.pow(z, 1.7);\n        const len = 8 + 70 * Math.pow(z, 1.4);\n        const gap = 3 + 15 * z;\n        const tint = Math.pow(z, 0.8);\n        const paths = [new Path2D(), new Path2D(), new Path2D()];\n        for (let x = -20 + ((r * 7.3) % gap); x < w + 20; x += gap) {\n          let gust = 0;\n          for (const g of gusts) {\n            const d = (x - g - z * 60) / (w * (0.1 + 0.08 * z) + 40);\n            gust += Math.exp(-d * d);\n          }\n          const sway = 0.12 * Math.sin(t * 1.1 + x * 0.013 + r * 0.7) + 0.06 * Math.sin(t * 2.3 + x * 0.05);\n          const bend = 0.16 + sway + Math.min(gust, 1) * 0.5;\n          const tipX = x + Math.sin(bend) * len;\n          const tipY = base - Math.cos(bend) * len;\n          const p = paths[gust > 0.6 ? 2 : gust > 0.25 ? 1 : 0];\n          p.moveTo(x, base);\n          p.quadraticCurveTo(x + Math.sin(bend * 0.4) * len * 0.5, base - len * 0.55, tipX, tipY);\n        }\n        for (let k = 0; k < 3; k++) {\n          const lift = k * 0.3;\n          const c = FAR.map((f, i) => Math.round((f + (NEAR[i] - f) * tint) * (1 - lift) + LIGHT[i] * lift));\n          ctx.strokeStyle = \"rgb(\" + c.join(\",\") + \")\";\n          ctx.lineWidth = 0.6 + 1.8 * z;\n          ctx.stroke(paths[k]);\n        }\n      }\n    };\n    const now = () => 3 + (performance.now() - born) / 1000;\n    const frame = () => {\n      raf = 0;\n      draw(now());\n      if (onScreen && !reduce) raf = requestAnimationFrame(frame);\n    };\n    const resize = () => {\n      const r = canvas.getBoundingClientRect();\n      const dpr = Math.min(window.devicePixelRatio || 1, 1.5);\n      w = r.width;\n      h = r.height;\n      canvas.width = Math.max(1, Math.round(w * dpr));\n      canvas.height = Math.max(1, Math.round(h * dpr));\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      draw(reduce ? 3 : now());\n    };\n    const ro = new ResizeObserver(resize);\n    ro.observe(canvas);\n    resize();\n    const io = new IntersectionObserver((entries) => {\n      onScreen = entries[0].isIntersecting;\n      if (onScreen && !reduce && !raf) raf = requestAnimationFrame(frame);\n    });\n    io.observe(canvas);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      cleanups.forEach((c) => c());\n    };\n  }, []);\n  return (\n    <section className=\"relative isolate min-h-[660px] overflow-hidden bg-[#efe6cf]\">\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 -z-10\">\n        <div className=\"absolute inset-0 [background:linear-gradient(180deg,#e4e6dc_0%,#f1e8d0_42%,#e2cf9c_50%,#bf9f5c_58%,#7e5f26_100%)]\" />\n        <div className=\"absolute left-[55%] top-[22%] h-72 w-[50%] [background:radial-gradient(closest-side,rgba(255,246,222,.9),transparent)]\" />\n        <canvas ref={canvasRef} aria-hidden=\"true\" className=\"absolute inset-0 h-full w-full\" />\n      </div>\n      <div className=\"mx-auto max-w-5xl px-6 pb-[340px] pt-16 sm:pt-20\">\n        <p className=\"text-sm font-semibold uppercase tracking-[0.16em] text-[#6b4a17]\">Hartfield Mill</p>\n        <h1 className=\"mt-3 max-w-2xl text-4xl font-semibold leading-[1.08] tracking-tight text-[#2d2210] sm:text-6xl\">Stoneground flour from this summer's harvest.</h1>\n        <p className=\"mt-4 max-w-xl text-lg leading-relaxed text-[#4d3d22]\">Heritage wheat grown two fields from the mill, ground slowly and posted the same week.</p>\n        <a href=\"#\" className=\"mt-7 inline-flex h-12 items-center rounded-md bg-[#2d2210] px-7 text-sm font-semibold text-[#f6efdc] transition hover:bg-[#4a3a1e] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#2d2210] focus-visible:ring-offset-2 focus-visible:ring-offset-[#f1e8d0]\">Order a sack</a>\n      </div>\n    </section>\n  );\n}\n"}]}
