"use client";import * as React from "react";import { createTide, readColor, Ripples, type Rgb, type Tide } from "./tide-water";import { INTERACTION_FOCUS, useInteractionReducedMotion } from "./ui-interaction-motion";/* ───────────────────────────────────────────────────────── * TIDE FOOTER: the whole footer is one engraved seascape * * plate one surface, like a print: your line and the * links in the sky, your name standing on the * horizon, its reflection in the sea, the small print * as the caption under the picture; text and letters * share the same side margins * swell left alone the sea breathes: a drop somewhere * every second or so, a fine rain of small ones, a * slow swell that sways the reflection * mirror the reflection is drawn into the lines; every ring * bends and tears it * wake the pointer drags a wake through the water (harder * the faster it moves); over the letters it ripples * their reflection; a click or a tap drops a splash; * on phones a sideways drag does the same * engraved the water is rows of fine ink lines in your theme's * colours, in perspective, lifted by the waves, tinted * --primary on the crests, fading out at the bottom * * Plain links in a labelled nav; the picture is decoration. * ───────────────────────────────────────────────────────── */export interface TideLink { label: string; href: string;}export interface TideColumn { title: string; links: TideLink[];}export interface TideFooterProps { /** The name: beside the logo, and standing on the horizon. */ wordmark: string; /** Your logo mark, shown beside the name (about 32px). */ logo?: React.ReactNode; /** A short description under the name. */ tagline?: string; /** One way to reach you under the description: an email or a contact page. */ contact?: TideLink; columns?: TideColumn[]; /** The small print: "© 2026 Northwind Labs". */ legal?: string; /** Links beside the small print: privacy, terms. */ legalLinks?: TideLink[]; className?: string;}const NO_COLUMNS: TideColumn[] = [];const NO_LINKS: TideLink[] = [];const mix = (color: string, amount: number, into = "transparent") => `color-mix(in oklab, ${color} ${amount}%, ${into})`;// The one lit surface: paper with a little of the primary in it, a hairline ring and a lit top edge.const PLATE: React.CSSProperties = { backgroundColor: mix("var(--card)", 96, "var(--primary)"), boxShadow: `0 0 0 1px var(--border), inset 0 1px 0 ${mix("var(--background)", 70)}`,};const lerp = (a: Rgb, b: Rgb, t: number): Rgb => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];function themeColors(el: HTMLElement): [Rgb, Rgb, Rgb] { const css = getComputedStyle(el); const card = readColor(css.getPropertyValue("--card").trim(), [1, 1, 1]); const fg = readColor(css.getPropertyValue("--foreground").trim(), [0.1, 0.1, 0.12]); const primary = readColor(css.getPropertyValue("--primary").trim(), [0.19, 0.36, 0.87]); // The paper is the plate's own background, so the picture and the page around the text are one surface. return [readColor(css.backgroundColor, lerp(card, primary, 0.04)), lerp(fg, primary, 0.3), primary];}/** * Draws the mask: the wordmark with its lowest ink on the baseline (red), a rim of paper round it (green) * and a low sun behind it (blue). Returns where the word starts and ends, as fractions of the width. */function letters(ctx: CanvasRenderingContext2D, word: string, w: number, baseline: number, tall: number, family: string) { ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); const set = (size: number) => { ctx.font = `650 ${size}px ${family}`; if ("letterSpacing" in ctx) (ctx as CanvasRenderingContext2D & { letterSpacing: string }).letterSpacing = `${(-0.045 * size).toFixed(2)}px`; }; set(100); const m = ctx.measureText(word); const ratio = (m.actualBoundingBoxAscent + m.actualBoundingBoxDescent) / 100 || 0.72; const size = Math.min((w * 0.9) / Math.max(1, m.width / 100), tall / ratio); set(size); const mm = ctx.measureText(word); const x = (w - mm.width) / 2; const y = baseline - mm.actualBoundingBoxDescent; ctx.lineJoin = "round"; ctx.lineWidth = size * 0.08; ctx.strokeStyle = "rgb(0, 255, 0)"; ctx.strokeText(word, x, y); ctx.globalCompositeOperation = "lighter"; ctx.fillStyle = "rgb(255, 0, 0)"; ctx.fillText(word, x, y); ctx.fillStyle = "rgb(0, 0, 255)"; ctx.beginPath(); ctx.arc(w * 0.6, baseline - tall * 0.42, tall * 0.62, 0, Math.PI * 2); ctx.fill(); ctx.globalCompositeOperation = "source-over"; return { from: x / w, to: (x + mm.width) / w };}export function TideFooter({ wordmark, logo, tagline, contact, columns = NO_COLUMNS, legal, legalLinks = NO_LINKS, className = "" }: TideFooterProps) { const reduced = useInteractionReducedMotion(); const plateRef = React.useRef<HTMLDivElement>(null); const canvasRef = React.useRef<HTMLCanvasElement>(null); const markRef = React.useRef<HTMLDivElement>(null); const seaRef = React.useRef<HTMLDivElement>(null); React.useEffect(() => { const plate = plateRef.current; const canvas = canvasRef.current; const mark = markRef.current; const seaBand = seaRef.current; if (!plate || !canvas || !mark || !seaBand) return; let tide: Tide | null = null; try { tide = createTide(canvas); } catch { tide = null; } if (!tide) return; const water = tide; let ripples: Ripples | null = null; let raf = 0; let visible = false; let disposed = false; // The plate's width, the horizon and the sea's depth in CSS px from its top, how far the letters sink // before they surface (a fraction of the plate's height) and where the word starts and ends. let geo = { w: 1, horizon: 0, sea: 1, sink: 0, from: 0, to: 1 }; let nextDrop = 0; let last = { x: 0, y: 0, t: 0 }; // When the name started to surface (0: not yet, still under water). let surfaced = 0; let lastLink: Element | null = null; const measure = () => { const box = plate.getBoundingClientRect(); const markBox = mark.getBoundingClientRect(); const w = Math.max(1, box.width); const h = Math.max(1, box.height); const horizon = markBox.bottom - box.top; const sea = Math.max(1, seaBand.getBoundingClientRect().height); const dpr = Math.min(window.devicePixelRatio || 1, 2); const W = Math.round(w * dpr); const H = Math.round(h * dpr); water.layout(W, H, dpr, Math.round(sea / 4.6), horizon / h, (horizon + sea) / h); const family = getComputedStyle(mark).fontFamily || "system-ui, sans-serif"; // The letters at the canvas's size, with their rim, standing on the horizon. const mask = document.createElement("canvas"); mask.width = W; mask.height = H; const mctx = mask.getContext("2d"); const word = mctx ? letters(mctx, wordmark, W, horizon * dpr, markBox.height * dpr * 0.94, family) : { from: 0, to: 1 }; water.mask(mask); geo = { w, horizon, sea, sink: (markBox.height * 1.02) / h, ...word }; // The sea's grid: about 4.5px a column, and rows in perspective (more of them, bunched at the horizon). const gw = Math.max(90, Math.min(300, Math.round(w / 4.5))); const gh = Math.max(24, Math.min(140, Math.round((2.2 * gw * sea) / w))); ripples = new Ripples(gw, gh); water.colors(...themeColors(plate)); if (reduced) still(); else draw(); }; // How far under the water the letters are: all the way until they surface, then up over 1.5s with a small bob. const depthOfName = (now: number) => { if (reduced) return 0; if (!surfaced) return 1; const t = Math.min(1, (now - surfaced) / 1500) - 1; return -(t * t * (1.9 * t + 0.9)); }; const born = performance.now(); const draw = (now = born) => ripples && water.draw(ripples.encode(), ripples.w, ripples.h, (now - born) / 1000, depthOfName(now) * geo.sink); // Reduced motion: a few rings, settled a little, drawn once. const still = () => { if (!ripples) return; for (const [fx, fy] of [[0.18, 0.4], [0.52, 0.2], [0.84, 0.55]]) ripples.drop(fx * ripples.w, fy * ripples.h, 3, 1.4); for (let i = 0; i < 70; i++) ripples.step(); draw(); }; const frame = (now: number) => { raf = 0; if (!visible || disposed || !ripples) return; // The swell: a drop every second or so, and a fine rain of small ones. if (now > nextDrop) { ripples.drop(Math.random() * ripples.w, (0.1 + Math.random() * 0.85) * ripples.h, 2.6, 0.65); nextDrop = now + 700 + Math.random() * 900; } if (Math.random() < 0.25) ripples.drop(Math.random() * ripples.w, Math.random() * ripples.h, 1, 0.07); // While the name surfaces, water streams off the letters at the waterline. if (surfaced && now - surfaced < 1100) { for (let i = 0; i < 2; i++) ripples.drop((geo.from + Math.random() * (geo.to - geo.from)) * ripples.w, 1.5, 2, 0.3); } ripples.step(); draw(now); raf = requestAnimationFrame(frame); }; const run = () => { if (!raf && visible && !reduced) raf = requestAnimationFrame(frame); }; // A point on the sea's grid, or null away from the water. Over the letters it lands in their // reflection (the same distance below the horizon), so touching a letter ripples its mirror image. const cell = (e: PointerEvent) => { if (!ripples) return null; const box = plate.getBoundingClientRect(); const depth = Math.abs(e.clientY - box.top - geo.horizon) / geo.sea; if (depth > 1) return null; return { x: ((e.clientX - box.left) / geo.w) * ripples.w, y: Math.max(1.5, Math.pow(depth, 0.68) * ripples.h) }; }; // The wake: drops along the path the pointer moved, harder the faster it went. const onMove = (e: PointerEvent) => { if (reduced || (e.pointerType === "touch" && e.buttons === 0)) return; const p = cell(e); if (!p || !ripples) { last = { ...last, t: 0 }; return; } const dt = Math.max(8, e.timeStamp - last.t); const speed = Math.hypot(p.x - last.x, p.y - last.y) / dt; if (e.timeStamp - last.t < 120) { const steps = Math.min(6, Math.ceil(Math.hypot(p.x - last.x, p.y - last.y) / 2)); for (let i = 1; i <= steps; i++) ripples.drop(last.x + ((p.x - last.x) * i) / steps, last.y + ((p.y - last.y) * i) / steps, 2.2, Math.min(0.9, 0.12 + speed * 2.4) / steps); } last = { x: p.x, y: p.y, t: e.timeStamp }; }; const onDown = (e: PointerEvent) => { if (reduced || (e.target instanceof Element && e.target.closest("a"))) return; const p = cell(e); if (!p || !ripples) return; ripples.drop(p.x, p.y, 3.8, 3); last = { x: p.x, y: p.y, t: e.timeStamp }; }; // Reaching a link (pointer or keyboard) sends a ring across the sea below it. const ring = (link: Element) => { if (reduced || !ripples || link === lastLink) return; lastLink = link; const box = plate.getBoundingClientRect(); const r = link.getBoundingClientRect(); ripples.drop(((r.left + r.width / 2 - box.left) / geo.w) * ripples.w, ripples.h * 0.22, 3, 1.1); }; const onOver = (e: PointerEvent) => { const link = e.target instanceof Element ? e.target.closest("a") : null; if (link) ring(link); else lastLink = null; }; const onFocus = (e: FocusEvent) => { if (e.target instanceof Element && e.target.closest("a")) ring(e.target); }; // The name surfaces once, when most of it is on screen; it breaks the water along its width. const surface = new IntersectionObserver( ([entry]) => { if (!entry.isIntersecting || surfaced || reduced || !ripples) return; surfaced = performance.now(); for (let x = geo.from * ripples.w; x <= geo.to * ripples.w; x += 3) ripples.drop(x, 1.5, 2.4, 0.7); surface.disconnect(); }, { threshold: 0.6 }, ); const start = () => { if (disposed) return; measure(); plate.dataset.ready = ""; surface.observe(mark); run(); }; if (document.fonts?.status === "loaded") start(); else document.fonts.ready.then(start, start); const ro = new ResizeObserver(() => !disposed && plate.dataset.ready !== undefined && measure()); ro.observe(plate); const io = new IntersectionObserver(([entry]) => { visible = entry.isIntersecting; run(); }); io.observe(plate); const mo = new MutationObserver(() => { water.colors(...themeColors(plate)); if (reduced) draw(); }); mo.observe(document.documentElement, { attributes: true, attributeFilter: ["class", "style", "data-theme"] }); plate.addEventListener("pointermove", onMove); plate.addEventListener("pointerdown", onDown); plate.addEventListener("pointerover", onOver); plate.addEventListener("focusin", onFocus); return () => { disposed = true; cancelAnimationFrame(raf); ro.disconnect(); io.disconnect(); mo.disconnect(); surface.disconnect(); plate.removeEventListener("pointermove", onMove); plate.removeEventListener("pointerdown", onDown); plate.removeEventListener("pointerover", onOver); plate.removeEventListener("focusin", onFocus); water.dispose(); delete plate.dataset.ready; }; }, [wordmark, reduced]); return ( <footer className={`w-full max-w-[1200px] ${className}`}> {/* Its natural width where the parent sizes to its content, without forcing it on narrow screens. */} <div aria-hidden="true" data-natural-width className="grid h-0" style={{ gridTemplateColumns: "minmax(0, 1200px)" }} /> <div className="@container w-full"> {/* One plate: the picture is drawn behind everything, and the text sits on the same margins as the letters. */} <div ref={plateRef} className="group/plate relative isolate touch-pan-y overflow-clip rounded-[28px] text-card-foreground" style={PLATE}> <canvas ref={canvasRef} aria-hidden="true" className="pointer-events-none absolute inset-0 -z-10 size-full opacity-0 transition-opacity duration-700 group-data-[ready]/plate:opacity-100" /> <div className="grid grid-cols-1 gap-x-10 gap-y-9 px-[max(20px,5cqi)] pt-[clamp(28px,4.5cqi,56px)] @[700px]:grid-cols-[minmax(0,1fr)_auto]"> <div className="flex max-w-[34ch] flex-col items-start gap-3.5"> <div className="flex items-center gap-2.5"> {logo} <p className="text-[17px] font-semibold tracking-[-0.02em]">{wordmark}</p> </div> {tagline && <p className="text-pretty text-[14px] leading-6 text-muted-foreground">{tagline}</p>} {contact && ( <a href={contact.href} className={`group/contact mt-1 inline-flex cursor-pointer items-center gap-1.5 rounded-sm text-[14px] font-medium ${INTERACTION_FOCUS}`} > <span className="underline decoration-border underline-offset-[5px] transition-colors group-hover/contact:decoration-primary">{contact.label}</span> <span aria-hidden="true" className="transition-transform duration-200 group-hover/contact:translate-x-0.5"> → </span> </a> )} </div> {columns.length > 0 && ( <nav aria-label="Footer" className="grid grid-cols-3 gap-x-[clamp(14px,4cqi,56px)] gap-y-7"> {columns.map((col) => ( <div key={col.title} className="flex min-w-0 flex-col gap-2.5"> <p className="text-[12px] text-muted-foreground">{col.title}</p> <ul className="flex flex-col gap-1.5"> {col.links.map((l) => ( <li key={l.label}> <a href={l.href} className={`cursor-pointer rounded-sm text-[13.5px] transition-colors hover:text-primary @[480px]:text-[14px] ${INTERACTION_FOCUS}`}> {l.label} </a> </li> ))} </ul> </div> ))} </nav> )} </div> {/* The name stands on the bottom of this band (the horizon); until the water is ready, and without WebGL, it shows as type. */} <div ref={markRef} aria-hidden="true" className="relative mt-[clamp(36px,7cqi,96px)] h-[16cqi] select-none"> <p className="absolute inset-x-0 bottom-0 text-center text-[17.5cqi] font-semibold leading-[0.72] tracking-[-0.045em] transition-opacity duration-700 group-data-[ready]/plate:opacity-0" style={{ color: mix("var(--foreground)", 70, "var(--primary)") }} > {wordmark} </p> </div> {/* The sea and the reflection. */} <div ref={seaRef} aria-hidden="true" className="h-[max(104px,19cqi)]" /> {(legal || legalLinks.length > 0) && ( <div className="flex flex-wrap items-center justify-between gap-x-6 gap-y-2 px-[max(20px,5cqi)] pb-[clamp(18px,2.5cqi,28px)] pt-2 text-[12.5px] text-muted-foreground"> {legal && <p>{legal}</p>} {legalLinks.length > 0 && ( <ul className="flex flex-wrap gap-x-5 gap-y-1"> {legalLinks.map((l) => ( <li key={l.label}> <a href={l.href} className={`cursor-pointer rounded-sm transition-colors hover:text-foreground ${INTERACTION_FOCUS}`}> {l.label} </a> </li> ))} </ul> )} </div> )} </div> </div> </footer> );}