Site design → Style: fonts, corners, text size, shadows, page width

A new Style card in Site design (a `style` global) chooses the heading and
body fonts from 15 bundled ones, corners (sharp/soft/round), text size,
shadow strength and page width, with a live sample. The choices become
--site-* CSS variables that the @theme radius, shadow, container and font
tokens scale, so blocks keep using rounded-xl, shadow-sm, max-w-6xl and
follow the setting. Buttons and chips use rounded-button; the defaults
are the site's current look.

Fonts are @fontsource-variable packages (replacing the static DM Sans and
Playfair ones): still served by the site, and a browser downloads only
the fonts a page uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
This commit is contained in:
agent 2026-10-26 19:00:37 +00:00
parent c35f9a60cc
commit 91f6705899
29 changed files with 628 additions and 110 deletions

View file

@ -1,4 +1,4 @@
import { defaultColors, type ColorsGlobal } from './types';
import { defaultColors, defaultStyle, type ColorsGlobal, type StyleGlobal } from './types';
// Site colours (Site design → Colors) as CSS variables, rendered server-side
// into a <style> tag so pages don't flash the default colours on load.
@ -56,9 +56,68 @@ export function brandThemeVars(colors: Partial<ColorsGlobal> | null | undefined)
};
}
/** Every site colour variable — public site and the admin preview. */
export function siteThemeVars(colors: Partial<ColorsGlobal> | null | undefined): Record<string, string> {
// Fonts to pick from in Site design → Style. Each is bundled by both apps
// (src/lib/fonts.ts, @fontsource-variable packages) and a browser downloads
// only the ones a page uses. Adding one: install the package in both apps,
// import it in both fonts.ts files, add it here.
export const SITE_FONTS = [
{ id: 'playfair-display', label: 'Playfair Display', family: 'Playfair Display Variable', serif: true },
{ id: 'cormorant-garamond', label: 'Cormorant Garamond', family: 'Cormorant Garamond Variable', serif: true },
{ id: 'eb-garamond', label: 'EB Garamond', family: 'EB Garamond Variable', serif: true },
{ id: 'libre-baskerville', label: 'Libre Baskerville', family: 'Libre Baskerville Variable', serif: true },
{ id: 'lora', label: 'Lora', family: 'Lora Variable', serif: true },
{ id: 'fraunces', label: 'Fraunces', family: 'Fraunces Variable', serif: true },
{ id: 'dm-sans', label: 'DM Sans', family: 'DM Sans Variable', serif: false },
{ id: 'inter', label: 'Inter', family: 'Inter Variable', serif: false },
{ id: 'manrope', label: 'Manrope', family: 'Manrope Variable', serif: false },
{ id: 'montserrat', label: 'Montserrat', family: 'Montserrat Variable', serif: false },
{ id: 'nunito', label: 'Nunito', family: 'Nunito Variable', serif: false },
{ id: 'outfit', label: 'Outfit', family: 'Outfit Variable', serif: false },
{ id: 'raleway', label: 'Raleway', family: 'Raleway Variable', serif: false },
{ id: 'work-sans', label: 'Work Sans', family: 'Work Sans Variable', serif: false },
{ id: 'josefin-sans', label: 'Josefin Sans', family: 'Josefin Sans Variable', serif: false }
] as const;
/** CSS font-family for a SITE_FONTS id (unknown ids get `fallbackId`'s font). */
export function fontStack(id: unknown, fallbackId: string): string {
const font = SITE_FONTS.find((f) => f.id === id) ?? SITE_FONTS.find((f) => f.id === fallbackId)!;
return `'${font.family}', ${font.serif ? 'Georgia, serif' : 'ui-sans-serif, system-ui, sans-serif'}`;
}
// What each Style choice sets. The variables are read by the @theme in both
// apps' app.css (radius, shadow, container and font tokens), so every
// rounded-xl, shadow-sm, max-w-6xl… on the public site follows them.
const CORNERS = {
sharp: { scale: '0', button: '0' },
soft: { scale: '0.4', button: '0.375rem' },
round: { scale: '1', button: '9999px' }
};
const TEXT_SIZES = { small: '93.75%', normal: '100%', large: '112.5%' };
const SHADOWS = { none: '0', soft: '1', strong: '2.2' };
const WIDTHS = { narrow: '0.85', normal: '1', wide: '1.2' };
function pick<T>(table: Record<string, T>, key: unknown, fallback: string): T {
return table[String(key)] ?? table[fallback];
}
/** Site design → Style as CSS variables — public site and the admin preview. */
export function siteStyleVars(style: Partial<StyleGlobal> | null | undefined): Record<string, string> {
const corners = pick(CORNERS, style?.corners, defaultStyle.corners);
return {
'--site-font-heading': fontStack(style?.headingFont, defaultStyle.headingFont),
'--site-font-body': fontStack(style?.bodyFont, defaultStyle.bodyFont),
'--site-corners': corners.scale,
'--site-button-radius': corners.button,
'--site-text-size': pick(TEXT_SIZES, style?.textSize, defaultStyle.textSize),
'--site-shadow': pick(SHADOWS, style?.shadows, defaultStyle.shadows),
'--site-width': pick(WIDTHS, style?.width, defaultStyle.width)
};
}
/** Every site colour and style variable — public site and the admin preview. */
export function siteThemeVars(colors: Partial<ColorsGlobal> | null | undefined, style?: Partial<StyleGlobal> | null): Record<string, string> {
return {
...siteStyleVars(style),
'--color-bg': safeColor(colors?.background, defaultColors.background),
'--color-heading': safeColor(colors?.heading, defaultColors.heading),
'--color-subheading': safeColor(colors?.subheading, defaultColors.subheading),