Skip to content

About

Check a view snapshot against a KDL profile ledger

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

License Issues

View-check

A command that checks a view snapshot against a profile ledger. CI passes a profile id and an exception file. It does not restate the rules.

People who run visual checks in a product pipeline, and people who add a profile for a new device class, use this ledger instead of copying thresholds into each host.

Table of Contents

Install

The command is a Dub executable. If DMD is not on PATH, pass --compiler=ldc2.

dub build --compiler=ldc2

Use

view-check --profile mobile-web --snapshot layout.json --exceptions view.kdl

--profiles points at the ledger directory. It defaults to profiles in the working directory.

A rendered snapshot that breaks text-edge-inset exits 1. The same snapshot with a waiver for that node exits 0. examples/host.ps1 is that host.

Flag Use

--profile ID

The ledger profile: web, mobile-web, or ipad-web.

--snapshot FILE, --snapshot-dir DIR

One snapshot, or every .json in a folder. Both repeat.

--exceptions FILE

A waiver file. Repeat it to layer built-in, site, and bridged waivers.

--strict

quality findings fail too.

--advisory, --include-advisory

Report advisory findings. They never fail.

--fail-on-stale

Fail when an active waiver cleared nothing.

--format text|json

json writes the report to stdout instead of text lines.

--json PATH

Also write the JSON report to a file.

--no-notes

Drop the note lines.

Exit codes: 0 pass, 1 a blocking finding (or a stale waiver with --fail-on-stale), 2 a usage, ledger, snapshot, or waiver error.

Tiers

Each rule in the ledger has a tier. A waiver clears any tier.

Tier Text label Fails CI Rules

broken

error

Yes

overflow-x, clipped-offscreen, target-min, header-overflow, header-breakpoint-gap, missing-h1, link-name, broken-media, mobile-input-font-size, nav-parity, contrast-aa, axe-contrast, focus-visible, link-not-distinct, near-identical-colors

standard

required

Yes

text-edge-inset, color-scheme-dual, theme-toggle, container-alignment, content-width, card-grid-consistency

quality

warning

With --strict

contrast-margin, target-comfort, text-truncation, disabled-unexplained, token-pair-drift, hover-unchanged, hard-coded-color

advisory

info

Never. Shown with --advisory

phone-header-single-row, auth-tabbed-switcher, footer-nav-hierarchy

text-edge-inset is standard on a rendered snapshot and quality on a source snapshot (source="quality"). An older ledger line with severity="error" reads as broken, and severity="warning" as quality. rendered= and source= take a tier or one of those words.

Contrast and theme checks

Colours are computed in D. The command parses #rgb, #rgba, #rrggbb, #rrggbbaa, rgb(), rgba(), hsl(), and common colour names, and paints a translucent foreground over its background first.

  • contrast-aa: WCAG 2.1 contrast. Text needs 4.5:1, large text 3:1 (24px, or 18.66px at weight 700, or isLargeText). A control boundary or an icon on a fill needs 3:1. Nodes axe reported are left to axe-contrast.

  • contrast-margin: APCA-W3 0.0.98G-4g. A pair that passes AA still needs |Lc| 60 for text, 45 for large text, and 30 for non-text.

  • axe-contrast: each axe color-contrast hit in axeHits, or in axe.

  • focus-visible: the strongest of outline, box-shadow, and border against the background needs 3:1. No indicator fails. outlineStyle: auto passes.

  • link-not-distinct: a link without an underline needs 3:1 against the body text around it.

  • near-identical-colors: two colours closer than OKLab ΔE max (0.02) where they should read apart.

  • token-pair-drift: token pairs. Text needs 4.5:1, nonText and boundary 3:1.

  • hover-unchanged, hard-coded-color: from hoverChecks and colorPairs.

  • color-scheme-dual: declaredSchemes has light and dark. Skipped when the snapshot has no declaredSchemes.

  • theme-toggle: hasHeaderThemeToggle (or themeTogglePresent) is not false.

  • target-comfort: 44px for primary mobile controls. When any node sets primary, only those are checked.

  • phone-header-single-row, auth-tabbed-switcher, footer-nav-hierarchy: read ux.singleRowPhoneHeader, ux.tabbedAuthSwitcher, and ux.footerHierarchy. ipad-web excludes the phone header rule.

A contrast finding carries fg, bg, ratio, apcaLc, and suggestedFg: the nearest colour of the same hue that reaches the floor.

Exceptions

exceptions {
    waive "contrast-*" id="skittles-novelty" scheme="skittles" reason="Skittles is an opt-in novelty theme."
    waive "*" id="legacy-light" mode="light" state="default" reason="Migration guard: light mode is in the backlog."
    waive "contrast-aa" page="docs/**" fg="#999" bg="#fff" expires="2027-03-01" reason="Muted grey goes in the next paint."
}

The first argument is a rule id, a glob such as contrast-, or . reason is required. The rest are optional:

Attribute Match

id

Names the waiver in the report. Defaults to file:N.

node, selector

Exact, /regex/, a glob with *, or a substring.

page

A glob on the snapshot page (or its file name). stays in one folder; * crosses folders.

scheme

skittles, skittles/dark, or *.

mode, state

light or dark; default, focus, hover, search-results, fixture:NAME. Globs work.

fg, bg

A colour, compared as normalized hex. Only findings with that colour match.

expires

YYYY-MM-DD. After that day the waiver clears nothing and is listed as expired.

An active waiver that clears nothing is listed as stale. --fail-on-stale fails the run on it.

ignoreRules on a node (data-view-check-ignore) and a top-level inlineIgnores list (data-contrast-check-ignore) also clear findings. Both are listed under exempted with inline:SELECTOR as the waiver id.

JSON report

--format json and --json PATH write:

  • findings[]: tier, severity, rule, page, snapshot, scheme, mode, state, selector, node, fg, bg, ratio, required, apcaLc, suggestedFg, detail, message, blocks.

  • exempted[]: waiverId, rule, page, snapshot, scheme, mode, state, selector, reason, expires.

  • staleWaivers[], expiredWaivers[]: waiverId, rule, reason, expires.

  • summary: counts for broken, standard, quality, advisory, blocking, exempted, staleWaivers, expiredWaivers, pagesChecked, and pagesFailed[].

A missing value is null. schema is view-check/report@1. pass is false when the exit code is 1.

The ledger is KDL. A child accounts for every parent rule id by inheriting it, overriding it, or excluding it with a reason. A child does not restate language. An exception file is a per-view waiver. It is not the ledger’s excludes section.

target-min follows WCAG 2.2 SC 2.5.8 (AA). A control passes at 24 x 24px, or when a 24px circle on its centre clears every other control. Inline links in prose are exempt. Axe target-size hits are reported too. 44pt (Apple) and 48dp (Material) are comfort targets for primary mobile controls, not this rule.

Check a folder of snapshots at once. Pages of one class are then compared for content-width:

view-check --profile web --snapshot-dir snapshots/desktop

Snapshot fields

A node needs id, role, x, and width. These fields are optional:

Field Use

y, height

Page position, for spacing and card rows.

visible, srOnly

Hidden and screen-reader-only nodes leave a rule and are counted in a note line.

ignoreRules, ignoreReason

From data-view-check-ignore="rule,rule" and data-view-check-reason. * ignores every rule.

interactive, disabled, opacity, hasTooltipOrHint

For target-min, clipped-offscreen, and disabled-unexplained.

tag, fontSize

For mobile-input-font-size.

clipped, scrollContainer, position, inHeader

An ancestor clips the box, or the box sits in a sideways scroller.

placeholderOverflow, truncated, scrollWidth, clientWidth

For text-truncation.

accessibleName, inlineProse

For link-name and the prose-link exemption.

naturalWidth, failedLoad

For broken-media. A top-level failedMedia list holds failed image URLs.

cardGroup, textAlign

For card-grid-consistency. From data-view-check-card-group, or a grid of similar boxed children.

region

header, main, or footer with role: region, for container rules.

fg, bg, borderColor, fontWeight, isLargeText

Colours for contrast-aa and contrast-margin. role picks the floor: text, link, control (text), control-boundary, icon, icon-on-fill (non-text).

bodyFg, underlined

For link-not-distinct on a link node.

focusIndicator

{ bg, outlineColor, outlineWidth, boxShadowColor, borderColor } for focus-visible.

hover

{ fg, bg, borderColor, changed } for hover-unchanged.

primary

A primary control, for target-comfort.

x and width default to 0, so a colour-only node needs just id and role.

A snapshot can also carry scrollWidth, clientWidth, canScrollX, h1Count, hasMenuTrigger, and pageClass.

A snapshot can also carry these. All are optional, so older snapshots still load.

Field Use

page, scheme, mode, state

Where the capture came from: docs/guide.html, skittles, light or dark, default or search-results. Waivers and the report use them.

viewport

{ width, height }. width falls back to it.

declaredSchemes

The schemes the paint declares, for color-scheme-dual.

hasHeaderThemeToggle, themeTogglePresent

Either name, for theme-toggle.

tokens, tokenPairs

[{ name, fgToken, bgToken, fg, bg, kind, fontSize, fontWeight }]. kind is text, nonText, or boundary.

axeHits

[{ selector, fg, bg, fontSize, fontWeight, isLargeText, ratio, expected, message }].

colorPairs

[{ kind, selector, fg, bg, bodyFg, underlined, fontSize, fontWeight, isLargeText }]. kind is text, control-boundary, icon-on-fill, near-identical-colors, link-not-distinct, or hard-coded-color.

focusChecks

[{ selector, bg, outline, outlineColor, outlineWidth, outlineStyle, boxShadow, boxShadowColor, border, borderColor }]. Shorthands such as 2px solid rgb(0, 95, 204) are read for their colour.

hoverChecks

[{ selector, beforeFg, beforeBg, afterFg, afterBg, changed }].

inlineIgnores

[{ selector, rules, reason }] from data-contrast-check-ignore.

ux

{ singleRowPhoneHeader, tabbedAuthSwitcher, footerHierarchy } for the advisory rules.

A snapshot can carry bars and breakpoints for header-breakpoint-gap. A bar has id, width, requiredWidth, activeMinWidth, activeMaxWidth, and breaks (overflow or wrap). A breakpoint has px, feature, edge, header, and media.

Breakpoint dead zones

A layout rule from a wide view can stop working before the next media query takes over. header-breakpoint-gap catches that from one snapshot.

  • The adapter finds each single-row header bar: the outermost display: flex, flex-wrap: nowrap row in the header with two or more visible children.

  • It shrinks that bar under the rules active now until a child overflows the bar, a control leaves it, or a child wraps. Fixed padding, borders, and the scrollbar gutter are added. The result is requiredWidth, a window width.

  • It reads every @media width in the stylesheets, including range syntax and em. The edge of a breakpoint is the narrowest pixel of the layout on its wider side: max-width: 860px has edge 861, and min-width: 900px has edge 900. Cross-origin sheets are skipped.

  • activeMinWidth is the nearest header edge at or below the window width. With no narrower header breakpoint, the rule’s min (320px) is the floor.

  • The rule fails when requiredWidth is more than activeMinWidth, and names the band: header requires ~1003px but stays in this layout down to 861px: dead zone 861-1002px.

The reference adapter also snapshots those edges, so the narrowest pixel of each layout is tested as a real view. PROBES=all (the default) probes every @media edge from 320px to 1600px. PROBES=header probes only media rules that style the header. PROBES=none keeps the fixed matrix. WIDTHS= adds desktop widths.

The fixed matrix is 360 and 390 (phones, mobile/, check with mobile-web), 768, 834, and 1024 (tablets, tablet/, check with ipad-web), and 1280 (desktop/, check with web). Probes under 600px are phones; the rest are desktop windows.

Page classes

Set data-view-check-page on the page container. Container rules depend on it.

Class Aliases Container rule

marketing

landing

None. Bands may be full-bleed.

document

article

A centred column inside the header edges.

form

auth

A centred column.

workspace

app

None. Panes may run edge to edge.

directory

feed

Fills the header width, or a centred column inside it.

content-width compares pages of the same class at the same view width. An unannotated page gets only the basic checks. text-edge-inset, overflow-x, clipped-offscreen, and target-min apply to every class.

examples/playwright/ is a reference adapter that writes these snapshots with Playwright.

Built with

Runtime
  • D and Dub

  • LDC when DMD is not installed

Changelog

About

Check a view snapshot against a KDL profile ledger

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages