Documentation
¶
Overview ¶
Package validation provides accessibility validation and linting tools.
Index ¶
- func ContrastRatio(fg, bg graphics.Color) float64
- func GroupByRule(results []LintResult) map[LintRule][]LintResult
- func HasErrors(results []LintResult) bool
- func HasWarnings(results []LintResult) bool
- func IsLargeText(fontSizePx float64, isBold bool) bool
- func MeetsWCAG(ratio float64, level WCAGLevel, textSize TextSize) bool
- func MeetsWCAGAA(ratio float64, largeText bool) bool
- func MeetsWCAGAAA(ratio float64, largeText bool) bool
- func SuggestForegroundColor(bg graphics.Color, targetRatio float64) graphics.Color
- type ContrastResult
- type LintOptions
- type LintResult
- type LintRule
- type Severity
- type TextSize
- type WCAGLevel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContrastRatio ¶
ContrastRatio calculates the contrast ratio between two colors according to WCAG 2.1. Returns a value between 1 and 21, where higher values indicate more contrast. A ratio of 4.5:1 is required for normal text (AA), 7:1 for enhanced (AAA). A ratio of 3:1 is required for large text (AA), 4.5:1 for enhanced (AAA).
func GroupByRule ¶
func GroupByRule(results []LintResult) map[LintRule][]LintResult
GroupByRule groups lint results by their rule.
func HasErrors ¶
func HasErrors(results []LintResult) bool
HasErrors returns true if any lint results are errors.
func HasWarnings ¶
func HasWarnings(results []LintResult) bool
HasWarnings returns true if any lint results are warnings or errors.
func IsLargeText ¶
IsLargeText determines if text at the given font size and weight is considered "large" for WCAG contrast requirements. Large text is 18pt (24px) or larger, or 14pt (18.67px) bold or larger.
func MeetsWCAG ¶
MeetsWCAG checks if a contrast ratio meets the specified WCAG level for the given text size.
func MeetsWCAGAA ¶
MeetsWCAGAA checks if a contrast ratio meets WCAG AA requirements. Pass largeText=true for text that is 18pt+ or 14pt+ bold.
func MeetsWCAGAAA ¶
MeetsWCAGAAA checks if a contrast ratio meets WCAG AAA requirements. Pass largeText=true for text that is 18pt+ or 14pt+ bold.
Types ¶
type ContrastResult ¶
type ContrastResult struct {
// Ratio is the calculated contrast ratio.
Ratio float64
// MeetsAA indicates whether the ratio meets WCAG AA.
MeetsAA bool
// MeetsAAA indicates whether the ratio meets WCAG AAA.
MeetsAAA bool
}
ContrastResult contains the result of a contrast check.
func CheckContrast ¶
func CheckContrast(fg, bg graphics.Color, largeText bool) ContrastResult
CheckContrast checks the contrast ratio between two colors and returns detailed results.
type LintOptions ¶
type LintOptions struct {
// IncludeInfo includes informational messages in results.
IncludeInfo bool
// MinTouchTargetSize is the minimum touch target size in dp.
MinTouchTargetSize float64
// DisabledRules contains rules that should be skipped.
DisabledRules map[LintRule]bool
}
LintOptions configures which lint rules to run.
func DefaultLintOptions ¶
func DefaultLintOptions() LintOptions
DefaultLintOptions returns the default lint options.
type LintResult ¶
type LintResult struct {
// NodeID is the ID of the node with the issue.
NodeID int64
// Severity indicates how serious the issue is.
Severity Severity
// Rule identifies which rule was violated.
Rule LintRule
// Message describes the issue.
Message string
// Suggestion provides guidance on how to fix the issue.
Suggestion string
}
LintResult contains the result of a lint check.
func FilterBySeverity ¶
func FilterBySeverity(results []LintResult, minSeverity Severity) []LintResult
FilterBySeverity returns results at or above the given severity level.
func LintSemanticsTree ¶
func LintSemanticsTree(root *semantics.SemanticsNode) []LintResult
LintSemanticsTree runs accessibility lint checks on a semantics tree.
func LintWithOptions ¶
func LintWithOptions(root *semantics.SemanticsNode, options LintOptions) []LintResult
LintWithOptions runs lint checks with custom options.
type LintRule ¶
type LintRule string
LintRule represents an accessibility lint rule.
const ( // LintRuleMissingLabel indicates a node is missing an accessibility label. LintRuleMissingLabel LintRule = "missing-label" // LintRuleImageMissingAlt indicates an image is missing alt text. LintRuleImageMissingAlt LintRule = "image-missing-alt" // LintRuleTouchTargetSize indicates a touch target is too small. LintRuleTouchTargetSize LintRule = "touch-target-size" // LintRuleEmptyButton indicates a button has no label. LintRuleEmptyButton LintRule = "empty-button" // LintRuleMissingValue indicates a control is missing a value. LintRuleMissingValue LintRule = "missing-value" // LintRuleMissingHint indicates an interactive element is missing a hint. LintRuleMissingHint LintRule = "missing-hint" )
type TextSize ¶
type TextSize int
TextSize indicates whether text is considered "large" for WCAG purposes.