{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"floating-dandelion-seeds-and-pollen-particle-background","type":"registry:block","title":"Floating Dandelion Seeds and Pollen","description":"","dependencies":[],"files":[{"path":"components/we-inc/floating-dandelion-seeds-and-pollen-particle-background.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\n// Floating Dandelion Seeds and Pollen: 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 SEEDS_PER_MPX = 30; // dandelion seeds per million pixels\nconst POLLEN_PER_MPX = 200; // tiny pollen grains per million pixels\nconst FILAMENT = \"255,253,244\"; // seed fluff colour, as r,g,b (backlit, so near white)\nconst POLLEN = \"255,232,150\"; // pollen colour\nconst BREEZE = 1; // 0.5 for a still afternoon, 2 for a windy one\nconst WARMUP = 120; // 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  // One dandelion seed drawn once: a fan of fine filaments on a thin stalk.\n  const seed = document.createElement(\"canvas\");\n  seed.width = seed.height = 96;\n  const q = seed.getContext(\"2d\")!;\n  q.translate(48, 40);\n  q.lineCap = \"round\";\n  const crown = q.createRadialGradient(0, -6, 0, 0, -6, 34);\n  crown.addColorStop(0, `rgba(${FILAMENT},0.32)`);\n  crown.addColorStop(1, `rgba(${FILAMENT},0)`);\n  q.fillStyle = crown;\n  q.fillRect(-40, -40, 80, 70);\n  for (let i = 0; i < 44; i++) {\n    const a = Math.PI * 0.82 + (i / 43) * Math.PI * 1.36;\n    const len = 20 + Math.random() * 12;\n    q.strokeStyle = `rgba(${FILAMENT},0.7)`;\n    q.lineWidth = 0.7;\n    q.beginPath();\n    q.moveTo(0, 0);\n    q.quadraticCurveTo(Math.cos(a) * len * 0.5, Math.sin(a) * len * 0.4, Math.cos(a) * len, Math.sin(a) * len * 0.8);\n    q.stroke();\n    q.fillStyle = `rgba(${FILAMENT},0.9)`;\n    q.beginPath();\n    q.arc(Math.cos(a) * len, Math.sin(a) * len * 0.8, 1.1, 0, 7);\n    q.fill();\n  }\n  q.strokeStyle = \"rgba(120,104,70,0.6)\";\n  q.lineWidth = 0.9;\n  q.beginPath(); q.moveTo(0, 0); q.lineTo(0, 30); q.stroke();\n  q.fillStyle = \"rgba(110,86,52,0.85)\";\n  q.beginPath(); q.ellipse(0, 34, 1.6, 4.5, 0, 0, 7); q.fill();\n  const grain = glow(16, POLLEN, [[0, 1], [0.35, 0.8], [1, 0]]);\n  const seeds = Array.from({ length: Math.max(6, Math.round(area * SEEDS_PER_MPX)) }, () => ({\n    x: Math.random() * w, y: Math.random() * h, z: Math.random(), r: (Math.random() - 0.5) * 0.6, s: Math.random() * 99,\n  }));\n  const dust = Array.from({ length: Math.min(500, Math.round(area * POLLEN_PER_MPX)) }, () => ({\n    x: Math.random() * w, y: Math.random() * h, z: Math.random(), s: Math.random() * 99,\n  }));\n  let breeze = 0;\n  return {\n    update(dt, t) {\n      breeze = (14 + Math.sin(t * 0.17) * 10 + Math.sin(t * 0.43) * 6) * BREEZE;\n      for (const p of seeds) {\n        const k = 0.4 + p.z;\n        p.x += (breeze + Math.sin(t * 0.6 + p.s) * 8) * k * dt;\n        p.y += (-6 + Math.sin(t * 0.9 + p.s * 1.3) * 10) * k * dt;\n        p.r = Math.sin(t * 0.5 + p.s) * 0.35;\n        if (p.x > w + 80) { p.x = -80; p.y = Math.random() * h; }\n        if (p.y < -80) p.y = h + 80; else if (p.y > h + 80) p.y = -80;\n      }\n      for (const p of dust) {\n        p.x += (breeze * 0.7 + Math.sin(t + p.s) * 6) * (0.3 + p.z) * dt;\n        p.y += Math.cos(t * 0.8 + p.s) * 7 * dt - 2 * dt;\n        if (p.x > w + 10) p.x = -10;\n        if (p.y < -10) p.y = h + 10; else if (p.y > h + 10) p.y = -10;\n      }\n    },\n    draw(c, t) {\n      c.clearRect(0, 0, w, h);\n      for (const p of dust) {\n        const s = 1.5 + p.z * 3.5;\n        c.globalAlpha = (0.25 + p.z * 0.5) * (0.6 + 0.4 * Math.sin(t * 2 + p.s));\n        c.drawImage(grain, p.x - s / 2, p.y - s / 2, s, s);\n      }\n      for (const p of seeds) {\n        const s = 34 + p.z * 70;\n        c.globalAlpha = p.z > 0.85 ? 0.6 : 0.7 + p.z * 0.3;\n        c.save();\n        c.translate(p.x, p.y);\n        c.rotate(p.r);\n        c.drawImage(seed, -s / 2, -s * 0.42, s, s);\n        c.restore();\n      }\n      c.globalAlpha = 1;\n    },\n  };\n}\n\nexport default function FloatingDandelionSeedsPollen() {\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=\"sdp-bg relative isolate flex min-h-[560px] items-center overflow-hidden px-6 py-20 sm:px-12\">\n      <style>{`.sdp-bg{background:radial-gradient(60% 70% at 88% 5%, #f4e3a8 0%, rgba(244,227,168,0) 70%), linear-gradient(180deg, #c9c690 0%, #a9b47a 55%, #8b9a5e 100%)}.sdp-scrim{background:radial-gradient(52% 72% at 20% 50%, rgba(238,234,204,0.9) 0%, rgba(238,234,204,0) 78%)}`}</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=\"sdp-scrim pointer-events-none absolute inset-0 -z-10\" />\n      <div className=\"mx-auto w-full max-w-6xl\">\n        <div className=\"max-w-xl\">\n          <p className=\"text-sm font-semibold uppercase tracking-[0.14em] text-[#3f4d1f]\">Fieldnote Botanical Tea</p>\n          <h2 className=\"mt-4 text-4xl font-semibold leading-[1.08] tracking-tight text-[#26301c] sm:text-5xl\">Meadow herbs, dried slowly and blended by hand.</h2>\n          <p className=\"mt-5 text-lg leading-relaxed text-[#3b4229]\">Chamomile, nettle and lemon balm from small farms nearby, sold loose leaf and shipped in plain paper.</p>\n          <a\n            href=\"#\"\n            className=\"mt-8 inline-flex h-12 items-center rounded-full bg-[#3f5a2a] px-6 text-sm font-semibold text-[#fbf7ea] transition hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#26301c] focus-visible:ring-offset-2 focus-visible:ring-offset-[#eeeacc]\"\n          >\n            Shop the spring blends\n          </a>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
