Add colour tokens, dark mode and drop gradients
- Colour tokens in index.css named by role (ink, body, muted, link, brand, action, surface, tint, danger), used everywhere instead of hex - Dark mode: follows the system, a header toggle (site and admin) overrides it and is remembered; set before first paint in index.html - Data colours go through src/lib/color.ts: withAlpha for tints, accentText (lighter on dark) for text in an accent, readableOn for text on one, so an admin's pale colour still reads - Migration 040 drops events.gradient: a card is its photo or plain, with its colour as the border; other decorative gradients are solid - The countdown and a hero event without a photo mix their colour toward ink behind white text Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ee61568911
commit
c74ad746f5
70 changed files with 829 additions and 596 deletions
39
src/lib/color.ts
Normal file
39
src/lib/color.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
COLOR
|
||||
|
||||
Two helpers for colours that arrive as data (a page's accent, an
|
||||
event's or region's colour), so they work with the theme tokens
|
||||
in index.css as well as with hex.
|
||||
|
||||
withAlpha(color, 20) is that colour at 20% opacity, for tints and
|
||||
borders. It replaces `${color}33`, which only works on hex.
|
||||
|
||||
accentText(color) is that colour as text: itself in light mode,
|
||||
mixed halfway to white in dark mode (--accent-text-mix), so an
|
||||
accent picked for a white page still reads on a dark one.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
export const withAlpha = (color: string, percent: number): string =>
|
||||
`color-mix(in srgb, ${color} ${percent}%, transparent)`
|
||||
|
||||
export const accentText = (color: string): string =>
|
||||
`color-mix(in srgb, ${color} var(--accent-text-mix), #ffffff)`
|
||||
|
||||
/* Text for on top of a colour that arrives as data: white or deep
|
||||
ink, whichever has more contrast (WCAG), so a pale colour an admin
|
||||
picks still gets readable text. Anything that isn't #rrggbb (a
|
||||
CSS variable, say) gets white, which suits the site's own dark
|
||||
accents. */
|
||||
export function readableOn(color: string): string {
|
||||
const hex = /^#([0-9a-f]{6})$/i.exec(color ?? '')?.[1]
|
||||
if (!hex) return '#ffffff'
|
||||
const channel = (i: number) => {
|
||||
const c = parseInt(hex.slice(i, i + 2), 16) / 255
|
||||
return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4
|
||||
}
|
||||
const lum = 0.2126 * channel(0) + 0.7152 * channel(2) + 0.0722 * channel(4)
|
||||
const INK_LUM = 0.0161 // #04262e
|
||||
const onWhite = 1.05 / (lum + 0.05)
|
||||
const onInk = (lum + 0.05) / (INK_LUM + 0.05)
|
||||
return onWhite >= onInk ? '#ffffff' : '#04262e'
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue