2. Architecture
glance has three layers. Only the first touches the page.
page ──► collector (JS, in page) ──► snapshot buffers ──► core (Rust → wasm32) ──► raw results
▲ │
└──────── host calls (hit test, selector) ◄────┘
raw results ──► API layer (JS) ──► axe-compatible results object, messages, reporters
2.1 Collector (TypeScript, runs in the page)
One walk of the flattened tree: light DOM, open shadow roots, and slotted nodes in composed order, the same tree assistive technology sees. For each node it appends to flat, typed columns:
- structure: node kind, parent, first child, next sibling, shadow-host and slot links, owning document (for same-origin frames);
- names: tag and attribute names and values interned into one string table, so a rule compares integers, not strings;
- properties the DOM computes and markup does not show:
tabIndex,disabled,inert,checked, form-controltypeandvalue,langinheritance roots,labels; - the computed styles the rules need, read once per element through
getComputedStyle, stored as interned value ids; - layout: one border box per element, client rects for inline elements, client rects
for text nodes, and scroll extents only for elements whose overflow is not
visible.
Context selectors (include/exclude) and user selectors are resolved by the browser
(querySelectorAll) and passed as flags, so glance never needs a CSS selector engine of
its own to decide scope. The page is read once; every rule shares the read.
The collector reads, never writes. It keeps no state between runs except a WeakMap
from element to node index, rebuilt on every run.
2.2 Core (Rust, no_std + alloc, compiled to wasm32-unknown-unknown)
Pure functions over the snapshot (SBIO): no DOM, no clock, no allocator tricks.
snapshot: the arena. Struct-of-arrays over node indices; strings by id.facts: one pass computing per-node facts that many rules share: visual hiddenness, hiddenness to assistive technology, explicit and implicit role, focusable and tabbable, language. The accessible name and description are memoised and computed only when a rule asks.aria: the WAI-ARIA 1.2 and ARIA-in-HTML tables (roles, attributes, value types, allowed, required and prohibited attributes, required context and owned elements) asconstdata.rules: each rule is a definition (id, tags, impact, an applicability predicate, and its checks grouped any/all/none). Rules do not select nodes themselves: a compiled dispatcher indexes rules by tag and role, walks the nodes once and hands each node to the rules that can apply to it.paint: colour parsing, alpha compositing, relative luminance and contrast. The background of a text run comes from its ancestors' backgrounds in the snapshot; only a run whose box intersects another painted box that is not an ancestor needs a hit test.results: a compact list of (rule, node, outcome, check ids, check data) serialised as JSON for the API layer.
Host calls are the only way the core reaches back to the page, defined as a trait
(Host) and implemented by the wasm bindings with imported JS functions:
elements_from_point(x, y) for the overlap cases of colour contrast and target size, and
unique_selector(node) for result targets. Tests implement Host over a fixture
snapshot without a browser.
2.3 API layer (TypeScript)
Reproduces the reference interface (chapter 1): run, configure,
getRules, reset, setup/teardown, runPartial/finishRun, registerPlugin,
frameMessenger, reporters, version and source. It turns the core's raw results
into the results object (order, impact roll-up, failureSummary, helpUrl, target,
ancestry, xpath) with messages written for glance. Rule metadata and messages live in
one table (rules.json, the single source of truth). The Rust rule list, the TypeScript
types, getRules() and COMPAT.md are generated from it or checked against it in CI.
2.4 Builds
glance.js/glance.min.js: one self-contained script. It defineswindow.axewith the wasm module embedded as bytes. This is the string exported assource, so tools that inject the reference'ssource(such as @axe-core/playwright and Lighthouse) can inject glance unchanged.axe.js/axe.min.jsaliases inside the npm package, so path-based imports resolve.- The wasm module compiles asynchronously on first
run. The synchronous APIs (getRules,configure,reset) never need it.
2.5 Scope and failure
- Rules glance does not implement are absent from
getRules(), and COMPAT.md lists them. Naming one inrunOnlyorrulesthrows the same error the reference throws for an unknown rule. Nothing is silently reported as passing. - Custom checks and rules from
configurewhoseevaluateis a JS function run in the API layer against the real elements that the rule's selector matches, after the core pass. They are correct but not fast. - Every error from the core reaches the caller as a rejected
runpromise or the callback's error argument. Nothing is swallowed.