Skip to main content
FIELD MANUAL // LENS-A11Y SPECIFICATION v0.1ZERO DEPENDENCIES // <15 KB GZIP // MIT

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.

01 // ISOLATION
Shadow-DOM HUD

Host CSS never leaks in. Optical filters never blur the HUD.

02 // FOOTPRINT
Zero Dependencies

Pure TypeScript + native SVG feColorMatrix. Under 15 KB.

03 // REVERSIBLE
Lossless DOM Restore

Every text node and style restores 100% cleanly on Lens.off().

04 // EASTER EGG
Press Shift + P

Triggers the Darkroom Screen-Reader Empathy Challenge.

01 / ZERO-FRICTION SETUP

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.

Option A — Declarative CDN Script Tag (Auto-Mounts HUD)
<!-- 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>
Option B — npm / pnpm / bun (ESM + TypeScript)
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",
  });
}
02 / PROGRAMMATIC CONTROL

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.

lens-controller-api.ts
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
03 / CONFIGURATION SCHEMA

`Lens.mount(options)` Reference

PropertyTypeDefaultBehavior
initialSimulationSimulationType"none"Boots immediately into a specific vision or motor filter on mount.
initialIntensitynumber (0–100)65Controls 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.
04 / CLINICAL & OPTICAL MODELS

13 Simulation Modes. Zero Guesswork.

Pass any of these mode IDs into `Lens.simulate(id)` or `data-lens="..."`:

Mode IDEngineOptical SpecificationWhat It Exposes in Your UI
"deuteranopia"Color Matrix (SVG)Machado M-Cone 5×4 MatrixMutes green wavelengths; red and green status pills collapse into the same olive tone.
"protanopia"Color Matrix (SVG)Machado L-Cone 5×4 MatrixDims red wavelengths heavily; crimson error states look dark brown or nearly black.
"tritanopia"Color Matrix (SVG)Machado S-Cone 5×4 MatrixBlue-yellow confusion; sky blues shift teal and warm yellows shift toward pale pink.
"achromatopsia"Color Matrix (SVG)Rec.709 Luminance MonochromeZero hue perception. Pure luminance vision—proves why color alone can never convey state.
"cataracts"CSS Optical FilterAdjustable Blur + Warm Sepia HazeSimulates crystalline lens clouding. Washes out faint borders and low-contrast muted text.
"low-vision"CSS Optical FilterDiopter Gaussian Blur (1.5px–8px)Tests whether your visual hierarchy survives when 12px micro-copy blurs out.
"glaucoma"Pointer Radial Mask150px Peripheral Tunnel VignetteCuts off peripheral vision. Shows why corner toast notifications go completely unnoticed.
"macular"Pointer Radial Mask135px Central Scotoma BlackoutBlocks the exact center of gaze, forcing users to read UI using peripheral sight.
"glare"CSS Optical FilterHalation Bloom (+38% Brightness)Simulates photophobia or harsh sunlight washing out subtle light-mode surfaces.
"low-contrast"CSS Optical FilterContrast Compression (-62%)Exposes trendy grey-on-grey typography that fails the moment screen contrast drops.
"dyslexia"Cognitive DOM WalkerLossless Internal Character SwapSimulates orthographic crowding fatigue while keeping a 100% reversible TextNode map.
"tremor"Motor + Bounding BoxPointer Jitter + <44px Target AuditAdds hand-tremor displacement and flags every tiny button that fails WCAG 44×44px rules.
"keyboard-path"Navigation TopologySVG Vector Polyline + Stop BadgesDraws the exact Tab-key trajectory across the live DOM so focus traps have nowhere to hide.
05 / AUTOMATED WCAG 2.1 AUDITOR

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:

L = 0.2126 × R_lin + 0.7152 × G_lin + 0.0722 × B_lin  //  Contrast Ratio = (L_brightest + 0.05) / (L_darkest + 0.05)
Rule IDWeightWCAG TargetHow Aperture Verifies It
color-contrastERROR (-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-sizeWARNING (-5 pts)>= 44×44px bounding boxMeasures live getBoundingClientRect() dimensions on every interactive button, link, and input.
button-nameERROR (-9 pts)Non-empty text or aria-labelCatches icon-only buttons that announce simply as 'button' to VoiceOver and NVDA users.
input-labelERROR (-9 pts)Associated <label> or aria-labelFlags form inputs relying solely on placeholders (which vanish the moment a user starts typing).
img-altERROR (-9 pts)Explicit alt="..." attributeEnsures every <img> either describes its content or declares alt="" for decorative graphics.
heading-orderWARNING (-5 pts)Sequential h1 → h2 → h3Flags skipped heading levels (like jumping from h1 to h4) that break screen-reader document outlines.
html-langERROR (-9 pts)Valid <html lang="...">Required so assistive speech synthesizers load the correct phonetic pronunciation rules.
landmarksWARNING (-5 pts)Present <main> or [role="main"]Ensures keyboard and screen-reader users can bypass repetitive navbars straight to primary content.
06 / EVENT TELEMETRY

Subscribe to Live HUD State

telemetry-listeners.ts
// 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,
  })));
});
07 / AUTOMATED CI GATE

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:

test/a11y-gate.test.ts
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);
  });
});