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
|
|
@ -16,6 +16,8 @@
|
|||
request runs, instead of a loading skeleton.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { visionColor } from "./color.ts";
|
||||
|
||||
const BASE = import.meta.env?.VITE_API_BASE ?? "/api";
|
||||
const DEFAULT_TTL = 60_000;
|
||||
|
||||
|
|
@ -69,7 +71,26 @@ async function request(path, options: RequestInit = {}) {
|
|||
});
|
||||
}
|
||||
|
||||
return body;
|
||||
return recolors() ? recolor(body) : body;
|
||||
}
|
||||
|
||||
/* Colors that arrive as data (an event's, a region's) shown the way
|
||||
the visitor's color blind mode needs (color.ts, visionColor).
|
||||
Never in the admin, where a swapped color would be saved back;
|
||||
asked per request, since the site gets there without a reload. */
|
||||
const recolors = () =>
|
||||
typeof document !== "undefined" &&
|
||||
Boolean(document.documentElement.dataset.vision) &&
|
||||
!location.pathname.startsWith("/admin");
|
||||
|
||||
function recolor(value) {
|
||||
if (value == null) return value;
|
||||
if (typeof value === "string") return visionColor(value);
|
||||
if (Array.isArray(value)) return value.map(recolor);
|
||||
if (typeof value === "object") {
|
||||
for (const key of Object.keys(value)) value[key] = recolor(value[key]);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/* ── Reads ─────────────────────────────────────────────────────
|
||||
|
|
|
|||
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
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
useEvents({ status: "upcoming" }) a home page strip
|
||||
useEvents({ type: "workshop" }) one kind, wherever it is
|
||||
useEvents({ type: ["class", "workshop"] })
|
||||
useEvents({ from: "2026-09-27", to: "2026-11-07" }) a window
|
||||
useEvents({ scope: "national", past: 12 }) 12 past at most
|
||||
useEvents() everything
|
||||
|
||||
`scope` and `type` are different questions and stack rather
|
||||
|
|
@ -33,7 +35,7 @@ const NO_SCOPES: any[] = [];
|
|||
const NO_EVENTS: any[] = [];
|
||||
|
||||
/* The path for a filter, as the server reads it (routes/content.js). */
|
||||
export function eventsPath({ scope, host, status, type }: any = {}) {
|
||||
export function eventsPath({ scope, host, status, type, from, to, past }: any = {}) {
|
||||
const query = new URLSearchParams();
|
||||
if (scope) query.set("scope", scope);
|
||||
// An organization or a person slug: co-hosting puts one event on
|
||||
|
|
@ -42,15 +44,24 @@ export function eventsPath({ scope, host, status, type }: any = {}) {
|
|||
if (status) query.set("status", status);
|
||||
const types = Array.isArray(type) ? type.join(",") : type;
|
||||
if (types) query.set("type", types);
|
||||
// A date window (YYYY-MM-DD, either end optional): events with a
|
||||
// day in it, plus undated ones. The calendar asks for its grid.
|
||||
if (from) query.set("from", from);
|
||||
if (to) query.set("to", to);
|
||||
// Only the most recent `past` past events (a carousel's way back).
|
||||
if (past != null) query.set("past", String(past));
|
||||
const qs = query.toString();
|
||||
return qs ? `/events?${qs}` : "/events";
|
||||
}
|
||||
|
||||
/* A null filter fetches nothing. `ready` is whether any answer has
|
||||
arrived; on a change of filter the last answer stays until the
|
||||
new one lands, so a caller can keep it on screen meanwhile. */
|
||||
export function useEvents(filter: any = {}) {
|
||||
const { data, error, loading } = useResource(eventsPath(filter));
|
||||
const { data, error, loading } = useResource(filter ? eventsPath(filter) : null);
|
||||
const events = data?.events ?? NO_EVENTS;
|
||||
const scopes = data?.scopes ?? NO_SCOPES;
|
||||
return { events, scopes, loading, error };
|
||||
return { events, scopes, loading, error, ready: data !== undefined };
|
||||
}
|
||||
|
||||
/* Past and upcoming, split. `status` arrives already resolved, the
|
||||
|
|
|
|||
24
src/lib/focus.ts
Normal file
24
src/lib/focus.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* Moving keyboard focus for the reader, where the page changes
|
||||
under them. */
|
||||
|
||||
import { scrollBehavior } from './motion.ts'
|
||||
|
||||
/* For something that replaces the control that opened it (a
|
||||
thank-you in place of its form, a player in place of its Play
|
||||
button): as a ref, focus goes to it when it appears, so a screen
|
||||
reader reads it and Tab carries on from there. A stable function,
|
||||
so React calls it once, on mount. */
|
||||
export const focusOnMount = (el: HTMLElement | null) => el?.focus()
|
||||
|
||||
/* Go to a part of the page, as a link to #id does: scroll it into
|
||||
view and move focus there, so the next Tab carries on from it
|
||||
rather than from the link (a section that can't take focus is
|
||||
given tabindex -1 for it). False when there's no such id. */
|
||||
export function jumpTo(id: string): boolean {
|
||||
const el = document.getElementById(id)
|
||||
if (!el) return false
|
||||
if (!el.hasAttribute('tabindex')) el.setAttribute('tabindex', '-1')
|
||||
el.scrollIntoView({ behavior: scrollBehavior(), block: 'start' })
|
||||
el.focus({ preventScroll: true })
|
||||
return true
|
||||
}
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
/* Smooth scrolling, unless the visitor has asked for less motion.
|
||||
index.css covers CSS scrolling; this is for scrollIntoView and
|
||||
scrollTo calls, which don't read that setting themselves. */
|
||||
export const scrollBehavior = (): ScrollBehavior =>
|
||||
window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 'auto' : 'smooth'
|
||||
/* Less motion: the visitor's system asks for it, or the
|
||||
accessibility panel's reading mode is on. index.css covers CSS
|
||||
scrolling and animation; these are for scrollIntoView and
|
||||
scrollTo calls, and slideshows, which don't read either. */
|
||||
export const prefersLessMotion = (): boolean =>
|
||||
window.matchMedia('(prefers-reduced-motion: reduce)').matches ||
|
||||
document.documentElement.dataset.reading === 'on'
|
||||
|
||||
export const scrollBehavior = (): ScrollBehavior => (prefersLessMotion() ? 'auto' : 'smooth')
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
cards and dividers (with their color, thickness and
|
||||
spacing); a video is its still linked to the video
|
||||
|
||||
Colors are the site's palette (PALETTE) or "none"; blank is the
|
||||
Colors are the site's palette (STORED_PALETTE) or "none"; blank is the
|
||||
default. No unsubscribe link: Mailchimp adds its own to every send.
|
||||
|
||||
Email clients ignore stylesheets, CSS variables and most layout,
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@
|
|||
A path asked for before starts from its last answer (api.ts,
|
||||
peek) and isn't `loading` while it refreshes, so a page opened
|
||||
again after the TTL doesn't flash its skeleton.
|
||||
|
||||
A null path asks for nothing (data stays undefined, not loading),
|
||||
for a fetch that only some states need.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
|
@ -20,11 +23,15 @@ import { get, peek } from "./api.ts";
|
|||
|
||||
export function useResource(path, { ttl }: { ttl?: number } = {}) {
|
||||
const [state, setState] = useState<any>(() => {
|
||||
const stale = peek(path);
|
||||
return { data: stale, error: null, loading: stale === undefined };
|
||||
const stale = path ? peek(path) : undefined;
|
||||
return { data: stale, error: null, loading: Boolean(path) && stale === undefined };
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!path) {
|
||||
setState({ data: undefined, error: null, loading: false });
|
||||
return undefined;
|
||||
}
|
||||
let ignore = false;
|
||||
|
||||
const stale = peek(path);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue