Accessibility: reading and color blind modes, audit fixes, calendar window
- Accessibility panel: the switch knob stays in its track; the panel follows its button in the Tab order and opens on its first switch. - Reading mode is the page as plain text: one column, no colors, pictures, cards or motion; descriptions stay in place. - Color blind mode (protanopia, deuteranopia, tritanopia, monochrome): palette swaps chosen by simulation, applied to code, data and CSS colors on public pages only. The newsletter uses the stored palette. - Audit fixes: focus not hidden by the header, focus on page change and in-page jumps, focus return for the menu, day list and people details, labelled admin fields and dialogs, keyboard map tiles, scrollable tables, and more. - Calendar asks /events for its six weeks only (?from=&to=); carousels take their 12 most recent past events (?past=12). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d067c02d33
commit
b816203c0c
45 changed files with 760 additions and 208 deletions
108
src/lib/color.ts
108
src/lib/color.ts
|
|
@ -38,6 +38,91 @@ export function readableOn(color: string): string {
|
|||
return onWhite >= onInk ? '#ffffff' : '#001011'
|
||||
}
|
||||
|
||||
|
||||
/* ── The palette ─────────────────────────────────────────────────
|
||||
The site's 16 colors: four families, each [main, darkest, light,
|
||||
lightest]. The theme tokens above are chosen from these; so is
|
||||
anything drawn from the palette as data (a person's initials
|
||||
tile, the page background, the admin home's sections). Each main
|
||||
shade reads as text on white and takes white text on it (5:1 or
|
||||
better); the darkest are for text, the light and lightest for
|
||||
fills behind text. */
|
||||
/* As stored and sent: never swapped for a color blind mode. For
|
||||
colors that are saved or leave the site (the newsletter's picks);
|
||||
anything drawn on a public page uses PALETTE, below. */
|
||||
export const STORED_PALETTE = {
|
||||
teal: ['#00748a', '#003a45', '#5cd3e6', '#d6f5fa'],
|
||||
green: ['#4a7431', '#23361a', '#9cc47c', '#e6f0dd'],
|
||||
amber: ['#8f5b00', '#4a2e00', '#f0bd4f', '#fdf1d6'],
|
||||
ink: ['#3b5456', '#001011', '#a3b8b9', '#f5f9f8'],
|
||||
}
|
||||
|
||||
/* ── Color blind modes (AccessibilityPanel.tsx) ──────────────────
|
||||
<html data-vision> is set before the first paint (index.html)
|
||||
and a change reloads the page, so it's read once here.
|
||||
|
||||
Simulated with the Machado (2009) matrices, the palette's green
|
||||
and amber families blur together for protanopia and tritanopia,
|
||||
so there green becomes violet, the same four shades at the same
|
||||
contrasts (5.3:1 on white for the main one, 9:1 or better under
|
||||
ink for the light ones). For deuteranopia the palette already
|
||||
stays apart (violet or magenta would be worse), so it's kept.
|
||||
In each of the three, a color an admin picked off the palette
|
||||
snaps to the nearest palette color first, so two picked colors
|
||||
can't land on one confusable pair. Monochrome is a grayscale
|
||||
filter instead (index.css). The same swap for CSS is the
|
||||
--green-* variables in index.css. */
|
||||
export const VISIONS = [
|
||||
{ id: 'protanopia', label: 'Protanopia (red weak)' },
|
||||
{ id: 'deuteranopia', label: 'Deuteranopia (green weak)' },
|
||||
{ id: 'tritanopia', label: 'Tritanopia (blue weak)' },
|
||||
{ id: 'monochrome', label: 'Monochrome' },
|
||||
] as const
|
||||
|
||||
const VIOLET = ['#9839dc', '#4d1575', '#c9a5e3', '#f4eef9']
|
||||
const SWAPS: Record<string, Partial<Record<keyof typeof STORED_PALETTE, string[]>>> = {
|
||||
protanopia: { green: VIOLET },
|
||||
deuteranopia: {},
|
||||
tritanopia: { green: VIOLET },
|
||||
}
|
||||
|
||||
const vision = typeof document === 'undefined' ? undefined : document.documentElement.dataset.vision
|
||||
const swaps = vision ? SWAPS[vision] : undefined
|
||||
|
||||
const SHADES = Object.entries(STORED_PALETTE).flatMap(([family, shades]) =>
|
||||
shades.map((hex, i) => ({ hex, swapped: swaps?.[family as keyof typeof STORED_PALETTE]?.[i] ?? hex })),
|
||||
)
|
||||
const rgb = (hex: string) => [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16))
|
||||
|
||||
/* A #rrggbb color as the current color blind mode shows it: the
|
||||
palette's swap, or an off-palette color snapped to the nearest
|
||||
palette shade first. Anything else (a CSS variable, no mode)
|
||||
comes back as it was. */
|
||||
export function visionColor(color: string): string {
|
||||
if (!swaps || !/^#[0-9a-f]{6}$/i.test(color)) return color
|
||||
const [r, g, b] = rgb(color.toLowerCase())
|
||||
let best = SHADES[0]
|
||||
let bestDistance = Infinity
|
||||
for (const shade of SHADES) {
|
||||
const [sr, sg, sb] = rgb(shade.hex)
|
||||
// Weighted RGB ("redmean"), close enough to pick a neighbor.
|
||||
const mean = (r + sr) / 2
|
||||
const distance = (2 + mean / 256) * (r - sr) ** 2 + 4 * (g - sg) ** 2 + (2 + (255 - mean) / 256) * (b - sb) ** 2
|
||||
if (distance < bestDistance) [best, bestDistance] = [shade, distance]
|
||||
}
|
||||
return best.swapped
|
||||
}
|
||||
|
||||
export const PALETTE = Object.fromEntries(
|
||||
Object.entries(STORED_PALETTE).map(([family, shades]) => [family, shades.map(visionColor)]),
|
||||
) as { [K in keyof typeof STORED_PALETTE]: string[] }
|
||||
|
||||
/* Fills that take the page's ink text (#001011, 9:1 or better) and
|
||||
fills that take white text (5:1 or better), for things colored
|
||||
from the palette by data, like an initials tile. */
|
||||
export const PALETTE_LIGHT = ['#d6f5fa', '#e6f0dd', '#fdf1d6', '#f0bd4f', '#9cc47c', '#5cd3e6'].map(visionColor)
|
||||
export const PALETTE_DARK = ['#003a45', '#23361a', '#4a2e00', '#00748a', '#4a7431', '#8f5b00', '#3b5456'].map(visionColor)
|
||||
|
||||
/* ── The site's accents ──────────────────────────────────────────
|
||||
BRAND is the teal every page uses as its accent; it's the button
|
||||
token, so the admin's palette (Site settings → Colors) reaches it.
|
||||
|
|
@ -49,31 +134,10 @@ export const BRAND = 'var(--color-action)'
|
|||
export const ACCENTS = {
|
||||
teal: BRAND,
|
||||
deep: '#003a45',
|
||||
green: '#4a7431',
|
||||
green: visionColor('#4a7431'),
|
||||
amber: '#8f5b00',
|
||||
}
|
||||
|
||||
/* ── The palette ─────────────────────────────────────────────────
|
||||
The site's 16 colors: four families, each [main, darkest, light,
|
||||
lightest]. The theme tokens above are chosen from these; so is
|
||||
anything drawn from the palette as data (a person's initials
|
||||
tile, the page background, the admin home's sections). Each main
|
||||
shade reads as text on white and takes white text on it (5:1 or
|
||||
better); the darkest are for text, the light and lightest for
|
||||
fills behind text. */
|
||||
export const PALETTE = {
|
||||
teal: ['#00748a', '#003a45', '#5cd3e6', '#d6f5fa'],
|
||||
green: ['#4a7431', '#23361a', '#9cc47c', '#e6f0dd'],
|
||||
amber: ['#8f5b00', '#4a2e00', '#f0bd4f', '#fdf1d6'],
|
||||
ink: ['#3b5456', '#001011', '#a3b8b9', '#f5f9f8'],
|
||||
} as const
|
||||
|
||||
/* Fills that take the page's ink text (#001011, 9:1 or better) and
|
||||
fills that take white text (5:1 or better), for things colored
|
||||
from the palette by data, like an initials tile. */
|
||||
export const PALETTE_LIGHT = ['#d6f5fa', '#e6f0dd', '#fdf1d6', '#f0bd4f', '#9cc47c', '#5cd3e6'] as const
|
||||
export const PALETTE_DARK = ['#003a45', '#23361a', '#4a2e00', '#00748a', '#4a7431', '#8f5b00', '#3b5456'] as const
|
||||
|
||||
/* A palette fill for something colored by its name, like the
|
||||
initials tile of a person with no photo: the same name always gets
|
||||
the same fill, and each fill comes with its readable text (ink on
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue