Ship interfaces that don't gatekeep.
Most accessibility tools feel like a 2008 enterprise spreadsheet. Aperture (`lens-a11y`) is built for design engineers who care about craft: a precision optical instrument that lets you experience your live DOM through 13 clinical vision, cognitive, and motor models—and catches WCAG violations before they hit production.
Host CSS never leaks in. Optical filters never blur the HUD.
Pure TypeScript + native SVG feColorMatrix. Under 15 KB.
Every text node and style restores 100% cleanly on Lens.off().
Triggers the Darkroom Screen-Reader Empathy Challenge.
One line for script tags. Typed ESM for modern stacks.
Whether you're prototyping a static HTML file or shipping a Next.js 15 monorepo, Aperture mounts in milliseconds with zero provider boilerplate.
<!-- Drop anywhere in <head> or <body> -->
<script
src="https://cdn.jsdelivr.net/npm/lens-a11y@0.1/dist/lens.min.js"
data-lens="deuteranopia"
></script>pnpm add lens-a11y
import { Lens } from "lens-a11y";
// Mount the floating viewfinder HUD in your dev environment
if (process.env.NODE_ENV === "development") {
Lens.mount({
position: "bottom-right",
theme: "auto",
});
}The `Lens`Singleton API
Every capability inside the floating HUD is exposed programmatically on the `Lens` controller—so you can bind simulations to your own keyboard shortcuts, Storybook toolbars, or automated test runners.
import { Lens, runDomAudit, getContrastRatio, parseColor } from "lens-a11y";
// 1. Mount the Shadow-DOM HUD
Lens.mount({
initialSimulation: "none",
initialIntensity: 65,
position: "bottom-right",
theme: "auto",
});
// 2. Trigger any vision, cognitive, motor, or keyboard topology mode
Lens.simulate("cataracts", 80); // Second arg sets diopter intensity (0..100)
Lens.simulate("glaucoma"); // Pointer-following peripheral tunnel mask
Lens.simulate("dyslexia"); // Reversible orthographic letter swap
// 3. Adjust intensity dynamically on active filter
Lens.setIntensity(45);
// 4. Run the 8-rule WCAG 2.1 scanner on the full document (or a scoped HTMLElement)
const report = Lens.audit();
console.log(report.score); // e.g. 100
console.log(report.issues); // Array of AuditIssue objects with CSS selectors & fixes
// 5. Inspect current state or cleanly tear down
const state = Lens.getState(); // { mounted, activeSimulation, intensity, lastAudit }
Lens.off(); // Restores all DOM text/styles & unmounts HUD`Lens.mount(options)` Reference
| Property | Type | Default | Behavior |
|---|---|---|---|
| initialSimulation | SimulationType | "none" | Boots immediately into a specific vision or motor filter on mount. |
| initialIntensity | number (0–100) | 65 | Controls diopter blur and opacity strength for `low-vision` and `cataracts`. |
| position | "bottom-right" | "bottom-left" | "top-right" | "top-left" | "bottom-right" | Initial anchor corner. User can freely drag via pointer or Arrow keys. |
| theme | "auto" | "light" | "dark" | "contrast" | "auto" | Synchronizes with the host page's `data-theme` attribute via MutationObserver. |
13 Simulation Modes. Zero Guesswork.
Pass any of these mode IDs into `Lens.simulate(id)` or `data-lens="..."`:
| Mode ID | Engine | Optical Specification | What It Exposes in Your UI |
|---|---|---|---|
| "deuteranopia" | Color Matrix (SVG) | Machado M-Cone 5×4 Matrix | Mutes green wavelengths; red and green status pills collapse into the same olive tone. |
| "protanopia" | Color Matrix (SVG) | Machado L-Cone 5×4 Matrix | Dims red wavelengths heavily; crimson error states look dark brown or nearly black. |
| "tritanopia" | Color Matrix (SVG) | Machado S-Cone 5×4 Matrix | Blue-yellow confusion; sky blues shift teal and warm yellows shift toward pale pink. |
| "achromatopsia" | Color Matrix (SVG) | Rec.709 Luminance Monochrome | Zero hue perception. Pure luminance vision—proves why color alone can never convey state. |
| "cataracts" | CSS Optical Filter | Adjustable Blur + Warm Sepia Haze | Simulates crystalline lens clouding. Washes out faint borders and low-contrast muted text. |
| "low-vision" | CSS Optical Filter | Diopter Gaussian Blur (1.5px–8px) | Tests whether your visual hierarchy survives when 12px micro-copy blurs out. |
| "glaucoma" | Pointer Radial Mask | 150px Peripheral Tunnel Vignette | Cuts off peripheral vision. Shows why corner toast notifications go completely unnoticed. |
| "macular" | Pointer Radial Mask | 135px Central Scotoma Blackout | Blocks the exact center of gaze, forcing users to read UI using peripheral sight. |
| "glare" | CSS Optical Filter | Halation Bloom (+38% Brightness) | Simulates photophobia or harsh sunlight washing out subtle light-mode surfaces. |
| "low-contrast" | CSS Optical Filter | Contrast Compression (-62%) | Exposes trendy grey-on-grey typography that fails the moment screen contrast drops. |
| "dyslexia" | Cognitive DOM Walker | Lossless Internal Character Swap | Simulates orthographic crowding fatigue while keeping a 100% reversible TextNode map. |
| "tremor" | Motor + Bounding Box | Pointer Jitter + <44px Target Audit | Adds hand-tremor displacement and flags every tiny button that fails WCAG 44×44px rules. |
| "keyboard-path" | Navigation Topology | SVG Vector Polyline + Stop Badges | Draws the exact Tab-key trajectory across the live DOM so focus traps have nowhere to hide. |
Real Luminance Math. Not Regex Approximations.
When you call `Lens.audit()`, Aperture walks the live DOM, resolves `getComputedStyle()` colors across semi-transparent parent surfaces using alpha compositing, linearizes sRGB channels, and evaluates the W3C relative luminance equation:
| Rule ID | Weight | WCAG Target | How Aperture Verifies It |
|---|---|---|---|
| color-contrast | ERROR (-9 pts) | 4.5:1 (Normal) / 3.0:1 (Large) | Walks up the DOM tree, alpha-blends semi-transparent layers, and computes exact W3C relative luminance. |
| target-size | WARNING (-5 pts) | >= 44×44px bounding box | Measures live getBoundingClientRect() dimensions on every interactive button, link, and input. |
| button-name | ERROR (-9 pts) | Non-empty text or aria-label | Catches icon-only buttons that announce simply as 'button' to VoiceOver and NVDA users. |
| input-label | ERROR (-9 pts) | Associated <label> or aria-label | Flags form inputs relying solely on placeholders (which vanish the moment a user starts typing). |
| img-alt | ERROR (-9 pts) | Explicit alt="..." attribute | Ensures every <img> either describes its content or declares alt="" for decorative graphics. |
| heading-order | WARNING (-5 pts) | Sequential h1 → h2 → h3 | Flags skipped heading levels (like jumping from h1 to h4) that break screen-reader document outlines. |
| html-lang | ERROR (-9 pts) | Valid <html lang="..."> | Required so assistive speech synthesizers load the correct phonetic pronunciation rules. |
| landmarks | WARNING (-5 pts) | Present <main> or [role="main"] | Ensures keyboard and screen-reader users can bypass repetitive navbars straight to primary content. |
Subscribe to Live HUD State
// Fires whenever the active simulation or intensity slider changes
window.addEventListener("lens:change", (event: Event) => {
const { simulation, intensity } = (event as CustomEvent).detail;
console.log(`[Aperture] Mode: ${simulation} @ ${intensity}%`);
});
// Fires whenever Lens.audit() completes a scan
window.addEventListener("lens:audit", (event: Event) => {
const report = (event as CustomEvent).detail;
console.table(report.issues.map((i: any) => ({
rule: i.ruleId,
title: i.title,
selector: i.selector,
})));
});Block Inaccessible PRs in GitHub Actions
Aperture dogfoods its own contrast and DOM auditor in CI. Import the pure math and scanner helpers directly inside Vitest or Playwright to guarantee your design tokens never regress below WCAG AA/AAA:
import { describe, expect, it } from "vitest";
import { getContrastRatio, parseColor, runDomAudit } from "lens-a11y";
describe("Design System Accessibility Gate", () => {
it("enforces >= 4.5:1 WCAG AA contrast on all theme tokens", () => {
const surface = parseColor("#121217")!;
const primaryText = parseColor("#f2f2f5")!;
const mutedText = parseColor("#a0a0ad")!;
expect(getContrastRatio(primaryText, surface)).toBeGreaterThanOrEqual(7.0); // AAA
expect(getContrastRatio(mutedText, surface)).toBeGreaterThanOrEqual(4.5); // AA
});
it("requires a 100/100 DOM audit score on core templates", () => {
const report = runDomAudit(document);
expect(report.issues).toEqual([]);
expect(report.score).toBe(100);
});
});