BarrierLab

visual-wasm

The visual audit suite as WebAssembly: backdrop sampling, layout and pixel audits, baseline diffs and overlays on raw canvas RGBA.

Layer L3. visual-audit, pixel-diff and visual-evidence behind a WASM boundary for the browser, extensions and Workers. The package translates, it does not judge: flat columns and RGBA bytes go in, reports in the shared model (a11y-report) come out.

Status

New, not yet released. Crate visual-wasm and npm package @casoon/visual-wasm (built by packages/visual-wasm/build.mjs). The consumer is liveaudit, which loads the package only when the user turns the visual check on.

Structure

ImageData.data (RGBA8)

VisualScan

flat columns:

ids, parents, rects, flags

sample_backdrop_with

(number[] | null per rect)

visual_audit::run_in

compare_baseline

+ baseline_report_in

visual_evidence::draw_annotations

Report

raw RGBA

The logic sits in plain functions (Capture, build_boxes, run_audit_geometry); the wasm_bindgen wrappers only translate errors and results. Native tests cover that core.

Public surface

new VisualScan(width, height, dpr, rgba), then sampleBackdrops, runAudit, diffAgainst, renderOverlay, renderOverlayLayer; and the free function runAuditGeometry for a run without screenshot. Method names are camelCase, as in @casoon/a11y-wasm. Signatures, the flags bit layout and the coordinate systems are in the crate README; the TypeScript types of the report are hand-written to mirror a11y-report and a test compares the fields.

  • runAudit takes the columns nodeIds, parentIdx (-1 for none), rectsXywh, flags (bits: text, interactive, image, fixed/sticky, overflow clips, two-dimensional), the optional textColors and the paint-order pair topNodeCounts / topNodeIdx (per box a count, -1 for “no hit test”, and the concatenated box indices of the topmost nodes at the sample points). The fields in_running_text, inline_level, native_control, essential and destination of VisualBox have no bit or column: no rule reads them. The host computes the pair with elementsFromPoint at the centre and four inset corners of each box, as collect.mjs of visual-audit does.
  • sampleBackdrops returns luminance arrays in the shape of a11y_dom::Backdrop, or null per rect that cannot be sampled. @casoon/a11y-wasm does not take them yet; the shape is the contract for when it does.
  • diffAgainst returns { outcome, report }; an empty baseline is missing_baseline.

No PNG, no hash

The browser supplies RGBA8, so the bundle has no PNG codec and no SHA-256 (visual-evidence without hash and png, pixel-diff without png). Hosts that have PNG bytes (auditmysite) use the native crates instead.

Not run is visible

  • Without a screenshot (runAuditGeometry, for example a tainted canvas), the pixel rules appear in rule_runs with not_run: "capability_missing" and a reason.
  • Without paint-order data (topNodeCounts empty) visual/fixed-obscures-content is capability_missing.
  • Without boxes the geometry rules are not run either, and an empty baseline gives capability_missing for visual/regression.
  • Contradicting columns, unknown flag bits, a parent index out of range and non-finite numbers throw an Error; they never produce a report that looks clean.

Size

Measured on 2026-12-03 (wasm-opt after the build, gzip -9):

Value
WASM, raw221.5 KiB (226,851 bytes)
WASM, gzip -998.5 KiB (100,848 bytes)
Budget (build.mjs)103 KiB gzip

Dependencies

Downward: visual-audit (without de unless the crate feature de is on, which is the default), visual-evidence (without hash/png), pixel-diff (without png), a11y-report and a11y-dom. Upward: nobody inside this repository.

Limits

Only the colour threshold of the baseline comparison is a parameter; the remaining tolerances are the defaults of BaselinePolicy. Overlays draw frames, fills and numeric badges only. The module is single-threaded: run a large screenshot in a worker.

Edit this page on GitHub