{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"layered-sea-swell-waves-hero-with-foam-line","type":"registry:block","title":"Layered Sea Swell Waves with Foam Line","description":"Free CSS wave animation: four layered sea swells roll along the bottom of a hero with a broken foam line. React, Tailwind and plain HTML, no canvas.","dependencies":[],"files":[{"path":"components/we-inc/layered-sea-swell-waves-hero-with-foam-line.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\n// Four swell layers, back to front. Each SVG is twice the width of the hero and slides left by\n// half of itself, which is exactly one wave period, so the loop never shows a seam.\n// Change a colour pair or a duration (seconds) here.\nconst SWELLS = [\n  { base: 62, harm: [[3,6,0.3],[2,11,1]], top: \"#b7cfc9\", bottom: \"#9dbdb6\", seconds: 60 },\n  { base: 108, harm: [[7,5,2.1,2],[3,9,0.2]], top: \"#8bb0aa\", bottom: \"#6a9893\", seconds: 40 },\n  { base: 166, harm: [[11,4,1,2.2],[4,7,2.6]], top: \"#558690\", bottom: \"#3a6b72\", seconds: 28 },\n  { base: 232, harm: [[16,3,0.7,2.4],[5,6,1.9]], top: \"#25525a\", bottom: \"#12313a\", seconds: 19 },\n];\nconst FOAM = \"#f1f6f3\";\n\n// One wave edge across 2880 units: two copies of a 1440-unit period, so sliding the SVG left by\n// half its width loops with no seam. Each harm entry is [amplitude, waves per period, phase,\n// sharpness?]; with a sharpness the crests come to narrow peaks over broad troughs, like real swell.\nfunction wavePath(base: number, harm: number[][], h: number, close: \"bottom\" | \"top\" | \"none\" = \"bottom\", step = 36, env?: [number, number]) {\n  const pts: number[][] = [];\n  for (let x = -step; x <= 2880 + step; x += step) {\n    const e = env ? 1 - env[0] + env[0] * Math.abs(Math.sin((Math.PI * env[1] * x) / 1440)) : 1;\n    let y = base;\n    for (const [a, c, ph, k] of harm) {\n      const t = (2 * Math.PI * c * x) / 1440 + ph;\n      y += k ? e * (a - 2 * a * Math.pow((1 + Math.cos(t)) / 2, k)) : a * e * Math.sin(t);\n    }\n    pts.push([x, y]);\n  }\n  const r = (n: number) => Math.round(n * 10) / 10;\n  let d = \"M0 \" + r(pts[1][1]);\n  for (let i = 1; i < pts.length - 2; i++) {\n    const [p0, p1, p2, p3] = [pts[i - 1], pts[i], pts[i + 1], pts[i + 2]];\n    d += \"C\" + r(p1[0] + (p2[0] - p0[0]) / 6) + \" \" + r(p1[1] + (p2[1] - p0[1]) / 6) + \" \" + r(p2[0] - (p3[0] - p1[0]) / 6) + \" \" + r(p2[1] - (p3[1] - p1[1]) / 6) + \" \" + r(p2[0]) + \" \" + r(p2[1]);\n  }\n  if (close === \"bottom\") d += \"L2880 \" + h + \"L0 \" + h + \"Z\";\n  if (close === \"top\") d += \"L2880 0L0 0Z\";\n  return d;\n}\n\nfunction useOnScreen<T extends Element>() {\n  const ref = useRef<T>(null);\n  const [onScreen, setOnScreen] = useState(true);\n  useEffect(() => {\n    const el = ref.current;\n    if (!el || !(\"IntersectionObserver\" in window)) return;\n    const io = new IntersectionObserver(([e]) => setOnScreen(e.isIntersecting));\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n  return [ref, onScreen] as const;\n}\n\nconst css = `\n@keyframes sswv-slide { from { transform: translate3d(0,0,0); } to { transform: translate3d(-50%,0,0); } }\n@keyframes sswv-bob { 0%,100% { transform: translate3d(0,0,0); } 50% { transform: translate3d(0,7px,0); } }\n.sswv-slide { animation: sswv-slide linear infinite; will-change: transform; }\n.sswv-bob { animation: sswv-bob 7s ease-in-out infinite; }\n.sswv-root[data-paused=\"true\"] .sswv-slide, .sswv-root[data-paused=\"true\"] .sswv-bob { animation-play-state: paused; }\n@media (prefers-reduced-motion: reduce) { .sswv-slide, .sswv-bob { animation: none !important; } }\n`;\n\nexport default function LayeredSeaSwellHero() {\n  const [ref, onScreen] = useOnScreen<HTMLElement>();\n  return (\n    <section ref={ref} data-paused={!onScreen} className=\"sswv-root relative isolate min-h-[640px] overflow-hidden bg-[#dfe8e5]\">\n      <style>{css}</style>\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 -z-10\">\n        <div className=\"absolute inset-0 [background:linear-gradient(180deg,#eef3f1_0%,#e2eae7_40%,#cbdcd7_62%,#b9cfc9_100%)]\" />\n        <div className=\"absolute left-[30%] top-[30%] h-64 w-[70%] [background:radial-gradient(closest-side,rgba(255,255,255,.6),transparent)]\" />\n        <div className=\"absolute inset-x-0 bottom-0 h-[44%] min-h-[220px]\">\n          {SWELLS.map((s, i) => (\n            <div key={i} className=\"sswv-bob absolute inset-0\" style={{ animationDelay: `${-i * 1.7}s` }}>\n              <svg className=\"sswv-slide absolute bottom-0 left-0 h-full w-[200%] min-w-[1800px]\" style={{ animationDuration: `${s.seconds}s` }} viewBox=\"0 0 2880 320\" preserveAspectRatio=\"none\">\n                <defs>\n                  <linearGradient id={`sswv-g${i}`} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n                    <stop offset=\"0\" stopColor={s.top} />\n                    <stop offset=\"1\" stopColor={s.bottom} />\n                  </linearGradient>\n                </defs>\n                <path d={wavePath(s.base, s.harm, 320)} fill={`url(#sswv-g${i})`} />\n                {i > 0 && i < SWELLS.length - 1 && <path d={wavePath(s.base, s.harm, 320, \"none\")} fill=\"none\" stroke=\"#ffffff\" strokeOpacity=\".22\" strokeWidth=\"1\" vectorEffect=\"non-scaling-stroke\" />}\n                {i === SWELLS.length - 1 && (\n                  <>\n                    <path d={wavePath(s.base + 2, s.harm, 320, \"none\")} fill=\"none\" stroke={FOAM} strokeOpacity=\".16\" strokeWidth=\"8\" vectorEffect=\"non-scaling-stroke\" />\n                    <path d={wavePath(s.base, s.harm, 320, \"none\")} fill=\"none\" stroke={FOAM} strokeOpacity=\".75\" strokeWidth=\"1.6\" strokeDasharray=\"220 5 60 9 140 4\" vectorEffect=\"non-scaling-stroke\" />\n                  </>\n                )}\n              </svg>\n            </div>\n          ))}\n        </div>\n      </div>\n      <div className=\"mx-auto max-w-5xl px-6 pb-[300px] pt-20 sm:pt-28\">\n        <p className=\"text-sm font-semibold uppercase tracking-[0.16em] text-[#2c4e53]\">Saltmarsh Swim School</p>\n        <h1 className=\"mt-4 max-w-2xl text-4xl font-semibold leading-[1.08] tracking-tight text-[#0f262b] sm:text-6xl\">Learn the open water at your own pace.</h1>\n        <p className=\"mt-5 max-w-xl text-lg leading-relaxed text-[#31474b]\">Small-group sea lessons every weekend from May to September, wetsuits included.</p>\n        <a href=\"#\" className=\"mt-8 inline-flex h-12 items-center rounded-full bg-[#0f262b] px-7 text-sm font-semibold text-white transition hover:bg-[#1d4249] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#0f262b] focus-visible:ring-offset-2 focus-visible:ring-offset-[#e2eae7]\">Book a trial swim</a>\n      </div>\n    </section>\n  );\n}\n"}]}
