Uses page: - Merge "For work"/"For fun" into one Hardware list; drop the MS-01. - Gaming rig becomes the Arch "Daily driver" (9950X, Looking Glass VM); custom workstation is now the Proxmox box (5900X, 128GB, RTX 3090). - Swap MetaMCP -> ContextForge and Open WebUI -> Paseo; add Codex, OpenCode, and OpenRouter. Testimonials: - Add Douglas Wilhelm; trim all quotes to ~55-60 words of verbatim sentences so cards stay the same size. - Move above projects and restyle as a card with gold-bordered initials, inline gold quote marks, and a countdown line under the divider. - Fix carousel bugs: hooks after an early return, timer not resetting on manual navigation, layout shift between quotes of different lengths. The countdown animation now drives rotation, and hover/keyboard focus pause it. Theme: - Centralize colors and fonts as CSS variables in globals.css; the neutral-* scale reads from them, and the header's hardcoded bg is gone. - New defaults: Manrope (body), EB Garamond (display), zinc greys, gold. - Add a dev-only theme switcher for A/B-ing fonts and palettes; it is compiled out of production builds. - Remove dead runtime-built hover classes on the about page that never generated CSS. Copy: replace em dashes with plain hyphens site-wide. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
288 lines
12 KiB
TypeScript
288 lines
12 KiB
TypeScript
"use client";
|
|
|
|
// Dev-only theme switcher for A/B-ing fonts and palettes on the real pages.
|
|
// It overrides the CSS variables from app/globals.css on <html>; once a combo is
|
|
// picked, bake it into globals.css (and layout.tsx for fonts) and it ships.
|
|
// Rendered only in development, see app/layout.tsx.
|
|
|
|
import { useCallback, useEffect, useState } from "react";
|
|
import type { FontOption } from "./themeFonts";
|
|
|
|
type Config = { sans: string; serif: string; tone: string; accent: string };
|
|
type Slot = "A" | "B";
|
|
type Stored = { current: Config; A?: Config; B?: Config };
|
|
|
|
const STORAGE_KEY = "dev-theme-switcher-v2";
|
|
const DEFAULT: Config = { sans: "manrope", serif: "garamond", tone: "zinc", accent: "gold" };
|
|
|
|
// Tailwind v4 grey scales, copied from node_modules/tailwindcss/theme.css.
|
|
const TONES: Record<string, { label: string; scale: Record<string, string> }> = {
|
|
neutral: {
|
|
label: "Neutral (previous)",
|
|
scale: { "50": "oklch(98.5% 0 0)", "100": "oklch(97% 0 0)", "200": "oklch(92.2% 0 0)", "300": "oklch(87% 0 0)", "400": "oklch(70.8% 0 0)", "500": "oklch(55.6% 0 0)", "600": "oklch(43.9% 0 0)", "700": "oklch(37.1% 0 0)", "800": "oklch(26.9% 0 0)", "900": "oklch(20.5% 0 0)", "950": "oklch(14.5% 0 0)" },
|
|
},
|
|
stone: {
|
|
label: "Stone (warm)",
|
|
scale: { "50": "oklch(98.5% 0.001 106.423)", "100": "oklch(97% 0.001 106.424)", "200": "oklch(92.3% 0.003 48.717)", "300": "oklch(86.9% 0.005 56.366)", "400": "oklch(70.9% 0.01 56.259)", "500": "oklch(55.3% 0.013 58.071)", "600": "oklch(44.4% 0.011 73.639)", "700": "oklch(37.4% 0.01 67.558)", "800": "oklch(26.8% 0.007 34.298)", "900": "oklch(21.6% 0.006 56.043)", "950": "oklch(14.7% 0.004 49.25)" },
|
|
},
|
|
zinc: {
|
|
label: "Zinc (current)",
|
|
scale: { "50": "oklch(98.5% 0 0)", "100": "oklch(96.7% 0.001 286.375)", "200": "oklch(92% 0.004 286.32)", "300": "oklch(87.1% 0.006 286.286)", "400": "oklch(70.5% 0.015 286.067)", "500": "oklch(55.2% 0.016 285.938)", "600": "oklch(44.2% 0.017 285.786)", "700": "oklch(37% 0.013 285.805)", "800": "oklch(27.4% 0.006 286.033)", "900": "oklch(21% 0.006 285.885)", "950": "oklch(14.1% 0.005 285.823)" },
|
|
},
|
|
gray: {
|
|
label: "Gray (blue hint)",
|
|
scale: { "50": "oklch(98.5% 0.002 247.839)", "100": "oklch(96.7% 0.003 264.542)", "200": "oklch(92.8% 0.006 264.531)", "300": "oklch(87.2% 0.01 258.338)", "400": "oklch(70.7% 0.022 261.325)", "500": "oklch(55.1% 0.027 264.364)", "600": "oklch(44.6% 0.03 256.802)", "700": "oklch(37.3% 0.034 259.733)", "800": "oklch(27.8% 0.033 256.848)", "900": "oklch(21% 0.034 264.665)", "950": "oklch(13% 0.028 261.692)" },
|
|
},
|
|
slate: {
|
|
label: "Slate (blue)",
|
|
scale: { "50": "oklch(98.4% 0.003 247.858)", "100": "oklch(96.8% 0.007 247.896)", "200": "oklch(92.9% 0.013 255.508)", "300": "oklch(86.9% 0.022 252.894)", "400": "oklch(70.4% 0.04 256.788)", "500": "oklch(55.4% 0.046 257.417)", "600": "oklch(44.6% 0.043 257.281)", "700": "oklch(37.2% 0.044 257.287)", "800": "oklch(27.9% 0.041 260.031)", "900": "oklch(20.8% 0.042 265.755)", "950": "oklch(12.9% 0.042 264.695)" },
|
|
},
|
|
};
|
|
|
|
const ACCENTS: Record<string, { label: string; value: string; hover?: string }> = {
|
|
gold: { label: "Gold (current)", value: "#d4a24a", hover: "#e6b966" },
|
|
ember: { label: "Ember", value: "#e07b3c" },
|
|
coral: { label: "Coral", value: "#ef7a6a" },
|
|
rose: { label: "Rose", value: "#e8829f" },
|
|
sage: { label: "Sage", value: "#94b88a" },
|
|
teal: { label: "Teal", value: "#3cbfae" },
|
|
iris: { label: "Iris", value: "#8f8cf5" },
|
|
sky: { label: "Sky", value: "#5ba8f0" },
|
|
};
|
|
|
|
function readStored(): Stored | null {
|
|
try {
|
|
const raw = localStorage.getItem(STORAGE_KEY);
|
|
return raw ? (JSON.parse(raw) as Stored) : null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function writeStored(value: Stored) {
|
|
try {
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(value));
|
|
} catch {
|
|
// storage unavailable, the switcher still works for this page view
|
|
}
|
|
}
|
|
|
|
function applyConfig(cfg: Config, sans: FontOption[], serif: FontOption[]) {
|
|
const root = document.documentElement.style;
|
|
const sansOpt = sans.find((o) => o.id === cfg.sans) ?? sans[0];
|
|
const serifOpt = serif.find((o) => o.id === cfg.serif) ?? serif[0];
|
|
root.setProperty("--site-sans", `var(${sansOpt.variable})`);
|
|
root.setProperty("--site-serif", `var(${serifOpt.variable})`);
|
|
|
|
const tone = TONES[cfg.tone] ?? TONES.neutral;
|
|
for (const [step, value] of Object.entries(tone.scale)) root.setProperty(`--n-${step}`, value);
|
|
if (cfg.tone === "neutral") {
|
|
// The original site values, so "Neutral" matches the old look exactly.
|
|
root.setProperty("--background", "#0a0a0a");
|
|
root.setProperty("--foreground", "#ededed");
|
|
root.setProperty("--bg-elevated", "#1c1c1c");
|
|
} else {
|
|
root.setProperty("--background", "var(--n-950)");
|
|
root.setProperty("--foreground", "color-mix(in oklab, var(--n-100), var(--n-200) 60%)");
|
|
root.setProperty("--bg-elevated", "color-mix(in oklab, var(--n-900), var(--n-800) 30%)");
|
|
}
|
|
|
|
const accent = ACCENTS[cfg.accent] ?? ACCENTS.gold;
|
|
root.setProperty("--accent", accent.value);
|
|
root.setProperty("--accent-hover", accent.hover ?? `color-mix(in oklab, ${accent.value} 75%, white)`);
|
|
}
|
|
|
|
function describe(cfg: Config, sans: FontOption[], serif: FontOption[]) {
|
|
const strip = (s: string) => s.replace(/ \(.*\)$/, "");
|
|
return [
|
|
strip(sans.find((o) => o.id === cfg.sans)?.label ?? cfg.sans),
|
|
strip(serif.find((o) => o.id === cfg.serif)?.label ?? cfg.serif),
|
|
strip(TONES[cfg.tone]?.label ?? cfg.tone),
|
|
strip(ACCENTS[cfg.accent]?.label ?? cfg.accent),
|
|
].join(" · ");
|
|
}
|
|
|
|
// navigator.clipboard only exists on secure origins (https or localhost). The dev
|
|
// server is usually opened by LAN IP over plain http, so fall back to the old
|
|
// hidden-textarea + execCommand trick, which still works there.
|
|
async function copyText(text: string): Promise<boolean> {
|
|
try {
|
|
if (navigator.clipboard && window.isSecureContext) {
|
|
await navigator.clipboard.writeText(text);
|
|
return true;
|
|
}
|
|
} catch {
|
|
// fall through to the legacy path
|
|
}
|
|
const area = document.createElement("textarea");
|
|
area.value = text;
|
|
area.setAttribute("readonly", "");
|
|
area.style.position = "fixed";
|
|
area.style.opacity = "0";
|
|
document.body.appendChild(area);
|
|
area.select();
|
|
let ok = false;
|
|
try {
|
|
ok = document.execCommand("copy");
|
|
} catch {
|
|
ok = false;
|
|
}
|
|
area.remove();
|
|
return ok;
|
|
}
|
|
|
|
const panel: React.CSSProperties = {
|
|
fontFamily: "ui-sans-serif, system-ui, sans-serif",
|
|
background: "#111",
|
|
color: "#ddd",
|
|
border: "1px solid #333",
|
|
};
|
|
const field: React.CSSProperties = { background: "#1b1b1b", color: "#eee", border: "1px solid #333" };
|
|
|
|
export default function ThemeSwitcher({
|
|
sansOptions,
|
|
serifOptions,
|
|
}: {
|
|
sansOptions: FontOption[];
|
|
serifOptions: FontOption[];
|
|
}) {
|
|
const [open, setOpen] = useState(true);
|
|
const [stored, setStored] = useState<Stored>({ current: DEFAULT });
|
|
const [activeSlot, setActiveSlot] = useState<Slot | null>(null);
|
|
const [copied, setCopied] = useState(false);
|
|
|
|
// Restore after mount (localStorage isn't available during SSR).
|
|
useEffect(() => {
|
|
const saved = readStored();
|
|
if (saved) setStored({ ...saved, current: { ...DEFAULT, ...saved.current } });
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
applyConfig(stored.current, sansOptions, serifOptions);
|
|
writeStored(stored);
|
|
}, [stored, sansOptions, serifOptions]);
|
|
|
|
const update = (patch: Partial<Config>) => {
|
|
setActiveSlot(null);
|
|
setStored((s) => ({ ...s, current: { ...s.current, ...patch } }));
|
|
};
|
|
|
|
const save = (slot: Slot) => {
|
|
setStored((s) => ({ ...s, [slot]: s.current }));
|
|
setActiveSlot(slot);
|
|
};
|
|
|
|
const show = useCallback((slot: Slot) => {
|
|
setStored((s) => (s[slot] ? { ...s, current: s[slot]! } : s));
|
|
setActiveSlot(slot);
|
|
}, []);
|
|
|
|
// Backtick flips between A and B, unless typing in a field.
|
|
useEffect(() => {
|
|
const onKey = (e: KeyboardEvent) => {
|
|
if (e.key !== "`") return;
|
|
const tag = (e.target as HTMLElement | null)?.tagName;
|
|
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return;
|
|
if (!stored.A || !stored.B) return;
|
|
e.preventDefault();
|
|
show(activeSlot === "A" ? "B" : "A");
|
|
};
|
|
window.addEventListener("keydown", onKey);
|
|
return () => window.removeEventListener("keydown", onKey);
|
|
}, [stored.A, stored.B, activeSlot, show]);
|
|
|
|
const summary = describe(stored.current, sansOptions, serifOptions);
|
|
|
|
if (!open) {
|
|
return (
|
|
<button
|
|
type="button"
|
|
onClick={() => setOpen(true)}
|
|
className="fixed bottom-4 right-4 z-[90] rounded-full px-3 py-1.5 text-[12px] shadow-lg"
|
|
style={panel}
|
|
>
|
|
Theme{activeSlot ? ` · ${activeSlot}` : ""}
|
|
</button>
|
|
);
|
|
}
|
|
|
|
const select = (label: string, value: string, options: { id: string; label: string }[], key: keyof Config) => (
|
|
<label className="flex items-center justify-between gap-3">
|
|
<span style={{ color: "#888" }}>{label}</span>
|
|
<select
|
|
value={value}
|
|
onChange={(e) => update({ [key]: e.target.value })}
|
|
className="w-40 rounded-md px-1.5 py-1"
|
|
style={field}
|
|
>
|
|
{options.map((o) => (
|
|
<option key={o.id} value={o.id}>
|
|
{o.label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
);
|
|
|
|
const slotButton = (slot: Slot) => {
|
|
const has = Boolean(stored[slot]);
|
|
const active = activeSlot === slot;
|
|
return (
|
|
<div key={slot} className="flex flex-1 flex-col gap-1">
|
|
<button
|
|
type="button"
|
|
disabled={!has}
|
|
onClick={() => show(slot)}
|
|
className="rounded-md py-1 font-semibold disabled:opacity-40"
|
|
style={{ ...field, ...(active ? { background: "#eee", color: "#111" } : null) }}
|
|
title={has ? describe(stored[slot]!, sansOptions, serifOptions) : "Nothing saved yet"}
|
|
>
|
|
Show {slot}
|
|
</button>
|
|
<button type="button" onClick={() => save(slot)} className="rounded-md py-1" style={field}>
|
|
Save as {slot}
|
|
</button>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
return (
|
|
<div className="fixed bottom-4 right-4 z-[90] w-72 space-y-2.5 rounded-xl p-3 text-[12px] shadow-2xl" style={panel}>
|
|
<div className="flex items-center justify-between">
|
|
<span className="font-semibold">Theme (dev only)</span>
|
|
<button type="button" onClick={() => setOpen(false)} style={{ color: "#888" }} aria-label="Collapse">
|
|
Hide
|
|
</button>
|
|
</div>
|
|
|
|
{select("Body font", stored.current.sans, sansOptions, "sans")}
|
|
{select("Display font", stored.current.serif, serifOptions, "serif")}
|
|
{select("Greys", stored.current.tone, Object.entries(TONES).map(([id, t]) => ({ id, label: t.label })), "tone")}
|
|
{select("Accent", stored.current.accent, Object.entries(ACCENTS).map(([id, a]) => ({ id, label: a.label })), "accent")}
|
|
|
|
<div className="flex gap-2">{slotButton("A")}{slotButton("B")}</div>
|
|
<p style={{ color: "#777" }}>Save two combos, then press ` to flip between them.</p>
|
|
|
|
<div className="flex items-center gap-2 border-t pt-2" style={{ borderColor: "#2a2a2a" }}>
|
|
<span className="flex-1 leading-snug">{summary}</span>
|
|
<button
|
|
type="button"
|
|
onClick={async () => {
|
|
if (await copyText(summary)) {
|
|
setCopied(true);
|
|
setTimeout(() => setCopied(false), 1200);
|
|
}
|
|
}}
|
|
className="rounded-md px-2 py-1"
|
|
style={field}
|
|
>
|
|
{copied ? "Copied" : "Copy"}
|
|
</button>
|
|
<button type="button" onClick={() => update(DEFAULT)} className="rounded-md px-2 py-1" style={field}>
|
|
Reset
|
|
</button>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|