"use client";import * as React from "react";import { FooterCaption, FooterLockup, FooterNav, plateColors, resolveColor, type FooterColumn, type FooterLink } from "./footer-parts";import { createMonolithRenderer, readMonolithRgb, type MonolithRenderer, type Rgb } from "./monolith-gl";import { useInteractionReducedMotion } from "./ui-interaction-motion";/* * A footer with the brand's name machined into its foot as a relief: bevelled letters * standing proud of the plate, casting real shadows. One light rakes across them; it * drifts on its own, follows the pointer, and swings to the column you're reading. */export type MonolithLink = FooterLink;export type MonolithColumn = FooterColumn;export interface MonolithFooterProps { /** Brand name: shown in the lockup and machined in relief across the foot. */ wordmark: string; /** Optional logo beside the name. */ logo?: React.ReactNode; /** One short line about the product. */ tagline?: string; /** A contact link under the tagline, e.g. an email address. */ contact?: MonolithLink; /** Link columns. */ columns?: MonolithColumn[]; /** "auto" follows the theme; "dark" keeps a dark plate on light pages too. */ tone?: "auto" | "dark"; /** The colour of the light's rim on the letters. Any CSS colour or token. Defaults to `var(--chart-2)`. */ accent?: string; /** Copyright line. */ legal?: string; /** Small links beside the copyright. */ legalLinks?: MonolithLink[]; className?: string;}const NO_COLUMNS: MonolithColumn[] = [];const NO_LINKS: MonolithLink[] = [];const DEFAULT_ACCENT = "var(--chart-2, var(--primary))";function DefaultMark() { return ( <svg viewBox="0 0 26 26" className="size-[26px] shrink-0" aria-hidden="true"> <rect x="0.5" y="0.5" width="25" height="25" rx="6.5" fill="color-mix(in oklab, currentColor 7%, transparent)" stroke="color-mix(in oklab, currentColor 22%, transparent)" /> <path d="M8 18V8h10v10Z" fill="color-mix(in oklab, currentColor 16%, transparent)" /> <path d="M8 8h10l-2.6 2.6H10.6Z" fill="currentColor" opacity="0.9" /> <path d="M8 8l2.6 2.6v4.8L8 18Z" fill="var(--fp-accent)" /> </svg> );}function drawReliefMask(ctx: CanvasRenderingContext2D, word: string, w: number, h: number, bayTop: number, bayH: number, dpr: number, family: string) { // Opaque black ground: a transparent canvas is stored premultiplied, and WebGL would lift every // faint pixel of the blurred height to full strength, flattening the bevel. ctx.globalCompositeOperation = "source-over"; ctx.fillStyle = "#000"; ctx.fillRect(0, 0, w, h); const label = word.trim() || "Monolith"; const setFont = (size: number) => { ctx.font = `750 ${size}px ${family}`; if ("letterSpacing" in ctx) { (ctx as CanvasRenderingContext2D & { letterSpacing: string }).letterSpacing = `${(-0.045 * size).toFixed(2)}px`; } }; setFont(100); const m = ctx.measureText(label); const hRatio = (m.actualBoundingBoxAscent + m.actualBoundingBoxDescent) / 100 || 0.72; const size = Math.max(24, Math.min((w * 0.9) / Math.max(0.5, m.width / 100), (bayH * 0.76) / hRatio)); setFont(size); ctx.textAlign = "center"; ctx.textBaseline = "middle"; const cx = w * 0.5; const cy = bayTop + bayH * 0.52; ctx.save(); // The blur is the chamfer: about 4% of the letter size. ctx.filter = `blur(${Math.max(3, Math.round(size * 0.04))}px)`; ctx.fillStyle = "rgb(0, 255, 0)"; ctx.fillText(label, cx, cy); ctx.restore(); ctx.save(); ctx.globalCompositeOperation = "lighter"; ctx.fillStyle = "rgb(255, 0, 0)"; ctx.fillText(label, cx, cy); ctx.restore();}export function MonolithFooter({ wordmark, logo, tagline, contact, columns = NO_COLUMNS, tone = "auto", accent = DEFAULT_ACCENT, legal, legalLinks = NO_LINKS, className = "",}: MonolithFooterProps) { const reduced = useInteractionReducedMotion(); const plateRef = React.useRef<HTMLDivElement>(null); const canvasRef = React.useRef<HTMLCanvasElement>(null); const bayRef = React.useRef<HTMLDivElement>(null); const targetLightRef = React.useRef({ x: 0.5, y: 0.65, active: false }); React.useEffect(() => { const plate = plateRef.current; const canvas = canvasRef.current; const bay = bayRef.current; if (!plate || !canvas || !bay) return; let renderer: MonolithRenderer | null = null; try { renderer = createMonolithRenderer(canvas); } catch { renderer = null; } if (!renderer) return; const gl = renderer; let raf = 0; let visible = false; let hidden = document.hidden; let disposed = false; let revealStart = -1; let born = performance.now(); let lx = 0.5; let ly = 0.65; let lActive = 0; const readColors = (): [Rgb, Rgb, Rgb, boolean] => { const css = getComputedStyle(plate); const paper = readMonolithRgb(css.backgroundColor, [0.065, 0.063, 0.06]); const fg = readMonolithRgb(css.color, [0.94, 0.93, 0.91]); const lum = 0.2126 * paper[0] + 0.7152 * paper[1] + 0.0722 * paper[2]; const isDark = tone === "dark" || lum < 0.42; const accentRgb = readMonolithRgb(resolveColor(plate, "var(--fp-accent)"), isDark ? [0.84, 0.58, 0.36] : [0.58, 0.38, 0.21]); return [paper, fg, accentRgb, isDark]; }; const measure = () => { if (disposed) return; const box = plate.getBoundingClientRect(); const bRect = bay.getBoundingClientRect(); const w = Math.max(1, box.width); const h = Math.max(1, box.height); const dpr = Math.min(window.devicePixelRatio || 1, 1.75); const W = Math.round(w * dpr); const H = Math.round(h * dpr); const topFrac = Math.max(0.05, Math.min(0.92, (bRect.top - box.top) / h)); gl.layout(W, H, dpr, topFrac); const mask = document.createElement("canvas"); mask.width = W; mask.height = H; const mctx = mask.getContext("2d"); if (mctx) { const family = getComputedStyle(plate).fontFamily || "system-ui, sans-serif"; drawReliefMask(mctx, wordmark, W, H, (bRect.top - box.top) * dpr, bRect.height * dpr, dpr, family); gl.mask(mask); } gl.colors(...readColors()); if (reduced) gl.draw(0.8, 1, 0.58, topFrac + 0.16, 1); }; const frame = (now: number) => { raf = 0; if (disposed || !visible || hidden || reduced) return; if (revealStart < 0) revealStart = now; const reveal = 1 - Math.pow(1 - Math.min(1, (now - revealStart) / 1100), 3); const t = (now - born) / 1000; const tgt = targetLightRef.current; lActive += ((tgt.active ? 1 : 0) - lActive) * 0.08; if (tgt.active) { lx += (tgt.x - lx) * 0.12; ly += (tgt.y - ly) * 0.12; } gl.draw(t, reveal, lx, ly, lActive); raf = requestAnimationFrame(frame); }; const kick = () => { if (!raf && visible && !hidden && !reduced && !disposed) raf = requestAnimationFrame(frame); }; const start = () => { if (disposed) return; born = performance.now(); measure(); plate.dataset.ready = ""; kick(); }; 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; if (visible && reduced) gl.draw(0.8, 1, 0.58, 0.68, 1); else kick(); }, { threshold: 0.12 }, ); io.observe(plate); const onVis = () => { hidden = document.hidden; if (!hidden) kick(); }; document.addEventListener("visibilitychange", onVis); const mo = new MutationObserver(() => { gl.colors(...readColors()); if (reduced) gl.draw(0.8, 1, 0.58, 0.68, 1); }); mo.observe(document.documentElement, { attributes: true, attributeFilter: ["class", "style", "data-theme"] }); const onMove = (e: PointerEvent) => { if (reduced || e.pointerType === "touch") return; const r = plate.getBoundingClientRect(); targetLightRef.current = { x: Math.max(0, Math.min(1, (e.clientX - r.left) / Math.max(1, r.width))), y: Math.max(0, Math.min(1, (e.clientY - r.top) / Math.max(1, r.height))), active: true, }; }; const onLeave = () => { targetLightRef.current = { ...targetLightRef.current, active: false }; }; plate.addEventListener("pointermove", onMove); plate.addEventListener("pointerleave", onLeave); return () => { disposed = true; cancelAnimationFrame(raf); raf = 0; ro.disconnect(); io.disconnect(); mo.disconnect(); document.removeEventListener("visibilitychange", onVis); plate.removeEventListener("pointermove", onMove); plate.removeEventListener("pointerleave", onLeave); gl.dispose(); delete plate.dataset.ready; }; }, [wordmark, tone, accent, reduced]); const aimColumn = (el: HTMLElement | null) => { const plate = plateRef.current; if (!plate || reduced) return; if (!el) { targetLightRef.current = { ...targetLightRef.current, active: false }; return; } const pr = plate.getBoundingClientRect(); const er = el.getBoundingClientRect(); targetLightRef.current = { x: Math.max(0, Math.min(1, (er.left + er.width * 0.5 - pr.left) / Math.max(1, pr.width))), y: 0.62, active: true, }; }; return ( <footer className={`w-full max-w-[1200px] ${className}`}> <div aria-hidden="true" data-natural-width className="grid h-0" style={{ gridTemplateColumns: "minmax(0, 1200px)" }} /> <div className="@container w-full"> <div ref={plateRef} className="group/plate relative isolate touch-pan-y overflow-clip rounded-[28px]" style={plateColors(tone === "dark", accent)}> <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]"> <FooterLockup logo={logo ?? <DefaultMark />} name={wordmark} tagline={tagline} contact={contact} /> <FooterNav columns={columns} onAim={aimColumn} /> </div> {/* The relief. Until WebGL is ready, and without it, the name shows as faint type. */} <div ref={bayRef} aria-hidden="true" className="relative mt-[clamp(16px,3.5cqi,44px)] h-[clamp(150px,23cqi,290px)] w-full select-none"> <p className="absolute inset-0 flex items-center justify-center text-[16cqi] font-bold tracking-[-0.045em] opacity-15 transition-opacity duration-700 group-data-[ready]/plate:opacity-0"> {wordmark} </p> </div> <FooterCaption legal={legal} links={legalLinks} className="relative px-[max(20px,5cqi)] pb-[clamp(18px,2.4cqi,26px)] pt-2 text-[color:var(--fp-muted)]" /> </div> </div> </footer> );}