"use client";import * as React from "react";import { AtlasEngine, buildAtlasPalette, readAtlasRgb, type AtlasHub } from "./atlas-globe";import { FooterCaption, FooterLockup, FooterNav, plateColors, resolveColor, type FooterColumn, type FooterLink } from "./footer-parts";import { useInteractionReducedMotion } from "./ui-interaction-motion";/* * A footer that ends on the curve of a dotted globe: about 6,500 points on a sphere, with * the brand's hubs marked and light running along the great circles between them. It turns * on its own; drag to spin it (it keeps its momentum), and reading a column nudges it round. */export type AtlasLink = FooterLink;export type AtlasColumn = FooterColumn;export interface AtlasFooterProps { /** Brand name: shown in the lockup. */ brand: string; /** Optional logo beside the name. */ logo?: React.ReactNode; /** One short line about the product. */ tagline?: string; /** The main action under the tagline. */ action?: AtlasLink; /** Link columns. */ columns?: AtlasColumn[]; /** Places marked on the globe and joined by arcs: your offices, regions or ports. */ hubs?: AtlasHub[]; /** "auto" follows the theme; "night" keeps the dark plate on light pages too. */ tone?: "auto" | "night"; /** The colour of the land, hubs and arcs. Any CSS colour or token. Defaults to `var(--chart-3)`. */ accent?: string; /** Copyright line. */ legal?: string; /** Small links beside the copyright. */ legalLinks?: AtlasLink[]; className?: string;}const NO_COLUMNS: AtlasColumn[] = [];const NO_LINKS: AtlasLink[] = [];const DEFAULT_HUBS: AtlasHub[] = [ { label: "SFO", lat: 37.77, lon: -122.42 }, { label: "NYC", lat: 40.71, lon: -74.01 }, { label: "LDN", lat: 51.51, lon: -0.13 }, { label: "FRA", lat: 50.11, lon: 8.68 }, { label: "BLR", lat: 12.97, lon: 77.59 }, { label: "SIN", lat: 1.35, lon: 103.82 }, { label: "TYO", lat: 35.68, lon: 139.65 },];const DEFAULT_ACCENT = "var(--chart-3, 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, var(--fp-accent) 12%, transparent)" stroke="color-mix(in oklab, var(--fp-accent) 34%, transparent)" /> <circle cx="13" cy="13" r="6.8" fill="none" stroke="currentColor" strokeOpacity="0.55" strokeWidth="1.3" /> <ellipse cx="13" cy="13" rx="3.3" ry="6.8" fill="none" stroke="var(--fp-accent)" strokeWidth="1.35" /> <path d="M6.2 13h13.6" stroke="currentColor" strokeOpacity="0.4" strokeWidth="1.2" /> </svg> );}export function AtlasFooter({ brand, logo, tagline, action, columns = NO_COLUMNS, hubs = DEFAULT_HUBS, tone = "auto", accent = DEFAULT_ACCENT, legal, legalLinks = NO_LINKS, className = "",}: AtlasFooterProps) { const reduced = useInteractionReducedMotion(); const plateRef = React.useRef<HTMLDivElement>(null); const stageRef = React.useRef<HTMLDivElement>(null); const canvasRef = React.useRef<HTMLCanvasElement>(null); const engineRef = React.useRef<AtlasEngine | null>(null); React.useEffect(() => { const plate = plateRef.current; const stage = stageRef.current; const canvas = canvasRef.current; if (!plate || !stage || !canvas) return; const ctx = canvas.getContext("2d", { alpha: false }); if (!ctx) return; const readPalette = () => { const css = getComputedStyle(plate); const bg = readAtlasRgb(css.backgroundColor, [0.03, 0.06, 0.07]); const fg = readAtlasRgb(css.color, [0.94, 0.96, 0.95]); const lum = 0.2126 * bg[0] + 0.7152 * bg[1] + 0.0722 * bg[2]; const darkSurface = tone === "night" || lum < 0.42; const accentRgb = readAtlasRgb(resolveColor(plate, "var(--fp-accent)"), darkSurface ? [0.27, 0.82, 0.66] : [0.12, 0.52, 0.44]); return buildAtlasPalette(bg, fg, accentRgb, tone === "night"); }; const engine = new AtlasEngine(readPalette(), hubs); engineRef.current = engine; let raf = 0; let visible = false; let hidden = document.hidden; let disposed = false; let lastTime = performance.now(); const measure = () => { if (disposed) return; const box = stage.getBoundingClientRect(); const w = Math.max(1, Math.round(box.width)); const h = Math.max(1, Math.round(box.height)); const dpr = Math.min(window.devicePixelRatio || 1, 2); canvas.width = Math.round(w * dpr); canvas.height = Math.round(h * dpr); engine.setFont(getComputedStyle(stage).fontFamily || "ui-monospace, SFMono-Regular, Menlo, monospace"); engine.setPalette(readPalette()); engine.resize(w, h, dpr); if (reduced) { engine.setRevealedImmediate(); engine.draw(ctx, true); } }; const loop = (now: number) => { raf = 0; if (disposed || !visible || hidden || reduced) return; const dt = (now - lastTime) / 1000; lastTime = now; engine.step(dt, now / 1000, false); engine.draw(ctx, false); raf = requestAnimationFrame(loop); }; const kick = () => { if (disposed || reduced) return; if (visible && !hidden && !raf) { lastTime = performance.now(); raf = requestAnimationFrame(loop); } }; measure(); plate.dataset.ready = ""; const ro = new ResizeObserver(() => measure()); ro.observe(stage); const io = new IntersectionObserver( ([entry]) => { visible = entry.isIntersecting; if (visible) { engine.startReveal(performance.now() / 1000); if (reduced) { engine.setRevealedImmediate(); engine.draw(ctx, true); } else { kick(); } } }, { threshold: 0.15 }, ); io.observe(plate); const onVis = () => { hidden = document.hidden; if (!hidden) kick(); }; document.addEventListener("visibilitychange", onVis); const mo = new MutationObserver(() => { engine.setPalette(readPalette()); if (reduced) engine.draw(ctx, true); }); mo.observe(document.documentElement, { attributes: true, attributeFilter: ["class", "style", "data-theme"] }); let activePointerId: number | null = null; const onDown = (e: PointerEvent) => { if (reduced) return; activePointerId = e.pointerId; stage.setPointerCapture(e.pointerId); const r = stage.getBoundingClientRect(); engine.onDragStart(e.clientX - r.left); }; const onMove = (e: PointerEvent) => { if (reduced || activePointerId !== e.pointerId) return; const r = stage.getBoundingClientRect(); engine.onDragMove(e.clientX - r.left); }; const onUp = (e: PointerEvent) => { if (activePointerId !== e.pointerId) return; activePointerId = null; if (stage.hasPointerCapture(e.pointerId)) stage.releasePointerCapture(e.pointerId); engine.onDragEnd(); }; stage.addEventListener("pointerdown", onDown); stage.addEventListener("pointermove", onMove); stage.addEventListener("pointerup", onUp); stage.addEventListener("pointercancel", onUp); return () => { disposed = true; cancelAnimationFrame(raf); raf = 0; ro.disconnect(); io.disconnect(); mo.disconnect(); document.removeEventListener("visibilitychange", onVis); stage.removeEventListener("pointerdown", onDown); stage.removeEventListener("pointermove", onMove); stage.removeEventListener("pointerup", onUp); stage.removeEventListener("pointercancel", onUp); engineRef.current = null; delete plate.dataset.ready; }; }, [hubs, tone, accent, reduced]); const nudgeColumn = (index: number) => { if (reduced || !engineRef.current) return; engineRef.current.nudgeSpin(index === 0 ? -1 : 1); }; 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 === "night", accent)}> <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={brand} tagline={tagline} action={action} /> <FooterNav columns={columns} onAim={(el, index) => el && nudgeColumn(index)} /> </div> {/* The globe; its canvas paints the plate's own colour, so there's no seam. Drag to spin. */} <div ref={stageRef} aria-hidden="true" className="relative mt-[clamp(8px,2cqi,24px)] h-[calc(clamp(220px,32cqi,375px)_+_56px)] w-full cursor-grab select-none active:cursor-grabbing" > <canvas ref={canvasRef} className="block size-full opacity-0 transition-opacity duration-500 group-data-[ready]/plate:opacity-100" /> </div> {/* The small print lies over the foot of the globe, which runs to the plate's edge. */} <FooterCaption legal={legal} links={legalLinks} className="relative -mt-[56px] min-h-[56px] px-[max(20px,5cqi)] pb-[clamp(18px,2.4cqi,26px)] pt-3 text-[color:var(--fp-muted)]" /> </div> </div> </footer> );}