visual-audit
Screenshot and layout geometry audits: backdrop sampling, overlap, overflow, clipping, fixed layers, visual anomalies and a baseline diff policy in the shared finding model.
Layer L2. Audits that need a rendered page: an RGBA screenshot (pixel-diff’s
RgbaView) plus layout boxes in CSS pixels. Findings use a11y-report
(Finding, RuleRun, NotRun), so a host merges them with a11y-rules and
web-checks. The package takes data, it does not fetch it: no file system, no
clock, no browser types, #![forbid(unsafe_code)], builds for
wasm32-unknown-unknown.
Status
New, not yet released. Hosts (auditmysite, liveaudit) call
sample_backdrop, run and compare_baseline; see the host contract in the
plan. A WASM boundary (visual-wasm) is not part of this package.
The rules were calibrated on a corpus and on real pages (see Evidence); the
dev tool xtask/collect.mjs renders a page in Chromium and writes the screenshot
and boxes (node collect.mjs <url|file> --out DIR --name STEM, Node >= 22,
CHROME for the browser path). It is not part of the published crate.
Input model
VisualSnapshot { viewport, device_pixel_ratio, screenshot, boxes }.
- All
Rectvalues are CSS pixels in one coordinate system.viewportis the visible area in it; the screenshot shows exactly that area, so image pixel(0, 0)lies atviewport.x / viewport.y(for a full-page screenshot the viewport is the whole page). boxesholds only boxes that are rendered and visible. The rules do not re-checkinert,display: none,pointer-events: noneor off-screen targets; a host that filters them gets no false neighbours.VisualBoxcarries the flags from the plan (is_text,is_interactive,is_image,is_fixed_or_sticky,overflow_clips,text_color, …), thetwo_dimensionalflag (data tables, maps and the like, exempt from 1.4.10 scrolling) andtop_nodes, the paint-order signal (below). All default tofalse/NonethroughVisualBox::new. For a box that clips its content,rectis the clip edge (padding box). The fieldsin_running_text,inline_level,native_control,essentialanddestinationwere the inputs of the removed target-size rule; no rule reads them now, the collector fillsin_running_text,inline_levelanddestinationbut nevernative_controloressential. They stay for hosts that already pass them.VisualCapture(serde) is the JSON formxtask/collect.mjswrites:viewport,device_pixel_ratio,boxes;VisualCapture::snapshot(png)makes theVisualSnapshot.VisualBoxdeserializes from the same JSON (rectas{x, y, width, height},text_coloras{r, g, b, a}); the local mirrorRectDataexists becausea11y_dom::Recthas no serde.top_nodesis the result of a hit test at the centre and four inset corners of a box inside the visible area (elementsFromPoint): the ids of the boxes painted topmost there.Nonemeans unknown.
Coordinates and pixels
css_to_device_rect is the single CSS-to-device conversion. The start is
floored, the end is ceiled, so the result encloses the CSS area; then it is
clamped to the image. A tolerance of 1e-4 device pixels absorbs float noise.
Tested at dpr 1.0, 1.5 and 2.0. Invalid dpr, empty or non-finite rects and
rects entirely outside the image give None.
Backdrop sampling
sample_backdrop(view, css_rect, dpr, canvas) returns a11y_dom::Backdrop:
one WCAG relative luminance per sample, alpha composited over canvas,
row-major. A 1 device pixel inset skips border lines (not applied when
nothing would remain); large boxes are strided to at most 4096 samples
(SampleOptions). The package does not judge contrast itself: a11y-rules
judges median and 40th percentile of the ratios, and a second implementation
here would drift. Luminance, ratio and compositing come from
a11y_dom::Color.
Rules
| Rule | WCAG | Outcomes | Needs | NotRun when |
|---|---|---|---|---|
visual/text-overlap | 1.4.4, 1.4.12 | Review | boxes | no boxes: CapabilityMissing; fewer than two text boxes: NotApplicable |
visual/viewport-overflow | 1.4.10 | Fail at viewport <= 320 px; Review for images and wider viewports | boxes | no boxes: CapabilityMissing; unusable viewport: Errored |
visual/container-clipped | 1.4.4, 1.4.12 | Review | boxes | no boxes: CapabilityMissing; no text in a clipping container: NotApplicable |
visual/fixed-obscures-content | 2.4.11, 2.4.12 | Review | boxes with top_nodes | no boxes or no paint-order data: CapabilityMissing; no fixed/sticky box: NotApplicable |
visual/blank-viewport | none (best practice) | Review | screenshot | no screenshot: CapabilityMissing; unusable screenshot or dpr: Errored |
visual/broken-image-box | none (best practice) | Review | boxes, screenshot | missing input: CapabilityMissing; no image box: NotApplicable |
visual/regression | none (best practice) | Review | two screenshots | no baseline: CapabilityMissing (via baseline_report, not run) |
Every rule always appears in rule_runs. Only visual/viewport-overflow can Fail; Meta::may_fail declares it and a
test enforces it.
Details worth knowing
- Overlap: sweep-line over x with an active list, y checked only for the
active set; ancestor/descendant pairs (via
parent_id), fixed boxes and text clipped away entirely by an ancestor are skipped. An overlap over 30% of the smaller box is reported (calibrated, see below); 50% or more gets severity High. Always Review: a box is a rectangle, the text in it is not. - Viewport overflow: 1.4.10 forbids horizontal scrolling at 320 CSS px, and
allows it for two-dimensional content. Hence Fail only at <= 320 px and not
for images or
two_dimensionalboxes (data tables). Boxes inside a clipping container that ends inside the viewport, fixed boxes and children of an already reported box are not reported. 1 px tolerance. - Fixed elements: a fixed or sticky box counts as covering a box only
when that box’s
top_nodesshow the fixed box (or one of its descendants) painted topmost at a sample point. Geometry alone cannot tell whether a pinned layer paints above or below the content (z-index, stacking contexts); a pinned hero layer under a navigation produced nine false findings on a real page. Withouttop_nodesanywhere the rule isNotRun::CapabilityMissing. A layer withpointer-events: noneis never hit, so it never counts as covering. Per covered box only the strongest cover is reported; text inside a link is reported through the link. - Target size (2.5.8) is not here:
a11y-ruleshastargets/size(same circle geometry, same Inline and Equivalent exceptions, plusinert,pointer-eventsand animation handling) in its rendering tier. A second rule for the same criterion double counts in a host that runs both, so thevisual/target-size-minimumrule was removed before release. - Blank viewport: more than 98% of sampled pixels within 3 per channel of the most common colour, and no text or image box shows anything else. The second condition spares a plain page with one small heading.
- Broken image: image boxes of at least 32 x 32 CSS px, at least half inside the image, whose pixels spread at most 2 per channel. A genuinely flat placeholder triggers it too, hence Review.
Baseline policy
compare_baseline(Option<RgbaView>, RgbaView, &BaselinePolicy) returns
BaselineVerdict::{Match, Regressed { diff_ratio, ssim, clusters }, DimensionChanged { baseline, current }, MissingBaseline}; both types are
serde-capable. The verdict regresses when diff_ratio > max_diff_ratio or
ssim < min_ssim. Named IgnoreRegions apply to both measures (for the
SSIM they are painted black in copies of both images). Defaults (0.1% pixels,
SSIM 0.99, colour threshold 0.1, cluster distance 8) are a starting point.
baseline_report turns a verdict into a Report: Review finding for
Regressed and DimensionChanged, NotRun::CapabilityMissing for a missing
baseline (nothing was compared, so it is not a match). Loading and storing
baselines stays with the host.
Texts and determinism
English by default; Locale::De with feature de (default). Identifiers,
outcomes and WCAG references do not depend on the locale. Output order is
fixed (rule order, then box order); no hash-map iteration reaches the report.
Evidence: corpus, observations, calibration
Three kinds of evidence, each with a different weight:
- Corpus (
tests/corpus/): our own reduced HTML cases, rendered withxtask/collect.mjsinto<case>.<WxH>.pngand.boxes.json, with<case>.expected.json(rule, verdict, node,source).tests/corpus.rsasserts every expectation and that every rule inMETAShas a case with a finding and a clean case. Viewports 320x640 and 1280x800, dpr 1; one case at dpr 2 (clipped_tile_title). - Observations (
tests/corpus/observations.json): what the rules did on 24 real public pages at 320 and 1280 CSS px on 2026-12-03 (news, government, shop, docs, two CASOON sites). Data only (URL, date, viewport, rule, counts, verdict, note); no screenshots or HTML of those pages are stored.tests/calibration.rs(ignored) reprints the findings from a directory of captures. - Fixtures in
tests/rules.rs: unit-level geometry and pixel cases.
| Rule | Corpus case | Real observation |
|---|---|---|
visual/text-overlap | overlap_card_title_price (F104: price over title), clean overlap_ok | booksshop: 7 true positives, a title wrapping into the price line at 320 px; ikea: 3 true positives (headline covered by a price card), 1 undecidable; bild: 16 false positives (hidden headline text and 4 px slivers), filtered. All looked at in screenshots |
visual/viewport-overflow | reflow_fixed_width (auditmysite visual_reflow_fixed_width), reflow_table (Review, data table), clean reflow_ok (auditmysite visual_reflow_ok) | none: no page scrolls horizontally at 320 px (all 48 captures, scrollWidth = viewport); zero findings, so no false positives after the collector fixes, but also no real positive |
visual/container-clipped | clipped_badge, clipped_tile_title (dpr 1 and 2), clean clipped_ok, clipped_tile_ok | booksshop 20 true positives (‘Add to basket’ cut at the card edge at 320 px), spiegel 1 true positive (kicker cut); bild 82 false positives (text hidden on purpose, under a third inside the clip), filtered; wikipedia 2 false positives by geometry, 1 still reported; heise 92 false positives at 2 px removed by the tolerance, 1 left that is undecidable (unpainted area). Verified in screenshots: 15 bild crops (all alike), 7 books, spiegel, heise |
visual/fixed-obscures-content | fixed_header_covers_links (Review), clean fixed_header_ok, fixed_behind_nav (layer below the content) | 154 true positives, all cookie/consent overlays covering the first screen (bbc, bild, heise, ikea, spiegel, stackoverflow, sz); casoon.de: 9 geometry-only false positives reported by a host, removed by the paint-order signal |
visual/blank-viewport | blank_white_screen, clean blank_plain_page | one false positive (nytimes block page in an iframe), fixed; no real positive. Constructed case only |
visual/broken-image-box | image_flat_placeholder, clean image_ok | never fired on 24 pages. Constructed case only |
visual/regression | regression_card_changed (against regression_card), clean regression_card_same | not applicable to single captures |
Calibration results
- text-overlap: the 15% threshold produced 806 findings on 14 pages, almost all of them tight line spacing (adjacent line boxes overlap 17-24%), superscripts and wrapped inline text merged into one box. The collector now emits one box per line (chained, so lines and children are related) and caps the line box at 1.2 em (Noto Sans range rectangles are about 1.75 em); the rule skips text clipped away entirely and the threshold is 30%. Remaining 27 findings on 24 pages.
- hidden text: text of which a clipping container shows under a third
(
MIN_VISIBLE_SHARE) counts as hidden on purpose incontainer-clippedandtext-overlap; text boxes under half a font size high are slivers and skipped intext-overlap. Real cuts show 90 % or more. - container-clipped:
CLIP_TOLERANCE3 px (was the 1 px overflow tolerance): 92 of 93 findings on heise.de extended under 2.5 px. Ellipsis and line-clamp truncation and carousels (swiper,slick,scroll-container, …) do not count as cut text. - viewport-overflow: the rule never judged correctly on its own: boxes under
overflow-x: hiddenonbody,overflow-x: cliponmain(apple.com) or in carousels produced Fail on pages whosescrollWidthequals the viewport. Fixed in the collector (such clips clamp descendants), not in the rule: the rule has to trust the clip information it gets.two_dimensionalis new: the bare 700 px table ofvisual_reflow_okis exempt by 1.4.10 and is Review. - fixed-obscures-content: needs
top_nodes(see above). - blank-viewport, broken-image-box: severity lowered from Medium to Low; they never produced a real positive.
- text-edge-clip: removed. Its only two findings on real pages were false
positives, and it only sees a cut that passes through a glyph at the clip edge
(the corpus case had to be tuned to hit one);
container-clippedsees the same cut from the geometry. - Not changed, but unknown:
visual/regressionhas no real-page evidence; it needs two captures of the same page and is covered by the corpus only.
Fields the collector fills (and does not)
Seen filled in real runs: node_id, parent_id, rect, is_text (one box per
text line), is_interactive, is_image (img, video, canvas, and iframe,
embed, object as image-like), is_fixed_or_sticky (also for descendants of
a fixed element), overflow_clips, text_color, font_size_px, font_weight,
two_dimensional, top_nodes, in_running_text, inline_level,
destination. Not filled, always false: native_control (needs a comparison
with the default control style) and essential (a browser cannot know). The
collector sees neither iframe content nor closed shadow roots; svg is not an
image box. top_nodes samples five points per box, so a cover that misses all
of them is not seen, and a pointer-events: none layer is invisible to it.
What the package does not do
- No contrast verdict from pixels; only the samples for
a11y-rules. - No target-size rule (that is
targets/sizeina11y-rules). - No scrolling, focusing or other page interaction;
fixed-obscures-contentsees one scroll position and cannot say what a real Tab press would scroll into view. - No file, git or network logic, no PNG handling (use
pixel-diff’spngfeature in the host), no score (audit-score).