Accessibility: reader view and full palette swaps; version v1.12.1-accessibility
- Reading mode is now a reader view (ReaderView.tsx): the page renders hidden and its headings, paragraphs, links and described pictures are written out in one column, with no header, backdrop or footer. - Color blind modes swap all three color families (teal, green, amber); palette hexes in components and CSS are now var(--pal-<family>-<shade>) so the modes reach them. - CLAUDE.md and docs/updating-data-in-code.md describe both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
420a8058b4
commit
de17da7dc8
19 changed files with 507 additions and 192 deletions
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
Dyslexia-friendly font every typeface becomes OpenDyslexic
|
||||
(self-hosted, index.css)
|
||||
Reading mode the page as plain text: one column of
|
||||
ink on white, no colors, pictures,
|
||||
cards or motion; a picture's
|
||||
description stays in its place
|
||||
Reading mode the page as text: its headings,
|
||||
paragraphs, links and described
|
||||
pictures in one column, nothing else
|
||||
(ReaderView.tsx)
|
||||
Color blind mode the palette swapped so its colors stay
|
||||
apart for that type of color blindness,
|
||||
or grays (color.ts, VISIONS)
|
||||
|
|
@ -53,7 +53,7 @@ const SETTINGS = [
|
|||
key: 'site-reading',
|
||||
on: 'on',
|
||||
label: 'Reading mode',
|
||||
help: 'The page as plain text: one column, larger type, no colors, pictures or motion.',
|
||||
help: 'The page as text: headings, paragraphs, links and pictures in one column, nothing else.',
|
||||
},
|
||||
] as const
|
||||
|
||||
|
|
@ -87,30 +87,6 @@ function apply(attribute: string, key: string, value: string | null) {
|
|||
}
|
||||
}
|
||||
|
||||
/* Reading mode hides pictures, video and maps; their descriptions
|
||||
(alt, title, aria-label) go on the parent as data-reading-alt,
|
||||
which index.css shows in their place. An attribute rather than a
|
||||
new element, so React's own nodes are left alone. */
|
||||
const DESCRIBED = 'main img[alt]:not([alt=""]), main iframe[title], main video[aria-label]'
|
||||
|
||||
function describeMedia() {
|
||||
for (const el of document.querySelectorAll(DESCRIBED)) {
|
||||
const words = el.getAttribute('alt') ?? el.getAttribute('title') ?? el.getAttribute('aria-label')
|
||||
const kind = el.tagName === 'IMG' ? 'Image' : 'Video'
|
||||
el.parentElement?.setAttribute('data-reading-alt', `${kind}: ${words}`)
|
||||
}
|
||||
}
|
||||
|
||||
function useMediaDescriptions(on: boolean) {
|
||||
useEffect(() => {
|
||||
if (!on) return undefined
|
||||
describeMedia()
|
||||
const observer = new MutationObserver(describeMedia)
|
||||
observer.observe(document.body, { childList: true, subtree: true })
|
||||
return () => observer.disconnect()
|
||||
}, [on])
|
||||
}
|
||||
|
||||
export default function AccessibilityPanel() {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [state, setState] = useState(() => Object.fromEntries(SETTINGS.map((s) => [s.key, isOn(s)])))
|
||||
|
|
@ -120,8 +96,6 @@ export default function AccessibilityPanel() {
|
|||
const firstRef = useRef<HTMLButtonElement>(null)
|
||||
const panelId = useId()
|
||||
|
||||
useMediaDescriptions(state['site-reading'])
|
||||
|
||||
useEffect(() => {
|
||||
const root = document.documentElement
|
||||
for (const { attribute, key } of PUBLIC_ONLY) {
|
||||
|
|
@ -187,7 +161,7 @@ export default function AccessibilityPanel() {
|
|||
id={panelId}
|
||||
role="region"
|
||||
aria-label="Accessibility"
|
||||
className="reading-solid absolute right-0 bottom-full mb-3 w-[min(20rem,calc(100vw-2rem))] border border-brand/20 bg-raised p-4 shadow-xl"
|
||||
className="absolute right-0 bottom-full mb-3 w-[min(20rem,calc(100vw-2rem))] border border-brand/20 bg-raised p-4 shadow-xl"
|
||||
>
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<h2 className="font-display text-base font-bold text-ink">Accessibility</h2>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue