Accessibility Manager
Player accessibility preferences in one place (reduced motion, screen shake, flashing, high contrast, text size, colour-blind safe colours, subtitles, hold or toggle) that start from the device’s settings, are saved, and can be read out to screen readers.
Files: accessibility-manager.js (the component, no dependencies) and accessibility-manager.test.mjs (4 tests).
Copy accessibility-manager.js into your game, for example to src/components/, and import it as an ES module.
Usage
import { createAccessibility } from "./accessibility-manager.js";
const a11y = createAccessibility({ key: "my-game:a11y" });
a11y.apply(document.documentElement); // CSS classes and --text-scale for HTML menus
camera.shakeScale = a11y.get("screenShake") ? 1 : 0;
a11y.onChange((k, v) => { if (k === "screenShake") camera.shakeScale = v ? 1 : 0; });
const colors = a11y.palette(); // team or key colours that stay distinct for colour-blind players
a11y.announce("Level 2. Find the key."); // screen reader message
API
createAccessibility({ key, storage, media, doc }) → a11ya11y.get(name) / a11y.set(name, value) / a11y.all() / a11y.reset()reducedMotion (bool, starts from prefers-reduced-motion), screenShake (bool, off if reduced motion), flashing (bool, off if reduced motion), highContrast (bool, from prefers-contrast: more), textScale (0.8..2), colorVision (“normal” | “protanopia” | “deuteranopia” | “tritanopia”), subtitles (bool), holdToToggle (bool, for players who can’t hold buttons), gameSpeed (0.5..1)a11y.palette(n) → n colours; Okabe-Ito colour-blind safe set, reordered for the chosen colour visiona11y.text(px) → px × textScale, for canvas fontsa11y.announce(text, { assertive })aria-live message (needs a document)a11y.apply(root)sets classes a11y-reduced-motion, a11y-high-contrast and the –text-scale CSS variablea11y.onChange(fn) → offfn(name, value)
The device’s settings are only used for values the player hasn’t changed.
Engines
| Engine | Notes |
|---|---|
| Vanilla, Phaser, PixiJS, Three.js | yes. Read the values where effects are made: camera shake, particles, flashes, fonts, colours. |
Tests
Node tests: device settings as starting values, player choices win and are saved, ranges, palettes, text size, apply() classes, announce() with a fake document.
Run them with node --test toolkit/components/accessibility-manager/ (Node 20 or newer, nothing to install).