@vibecheckai/cli 3.5.0 → 3.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/registry.js +214 -237
- package/bin/runners/cli-utils.js +33 -2
- package/bin/runners/context/analyzer.js +52 -1
- package/bin/runners/context/generators/cursor.js +2 -49
- package/bin/runners/context/git-context.js +3 -1
- package/bin/runners/context/team-conventions.js +33 -7
- package/bin/runners/lib/analysis-core.js +25 -5
- package/bin/runners/lib/analyzers.js +431 -481
- package/bin/runners/lib/default-config.js +127 -0
- package/bin/runners/lib/doctor/modules/security.js +3 -1
- package/bin/runners/lib/engine/ast-cache.js +210 -0
- package/bin/runners/lib/engine/auth-extractor.js +211 -0
- package/bin/runners/lib/engine/billing-extractor.js +112 -0
- package/bin/runners/lib/engine/enforcement-extractor.js +100 -0
- package/bin/runners/lib/engine/env-extractor.js +207 -0
- package/bin/runners/lib/engine/express-extractor.js +208 -0
- package/bin/runners/lib/engine/extractors.js +849 -0
- package/bin/runners/lib/engine/index.js +207 -0
- package/bin/runners/lib/engine/repo-index.js +514 -0
- package/bin/runners/lib/engine/types.js +124 -0
- package/bin/runners/lib/engines/accessibility-engine.js +18 -218
- package/bin/runners/lib/engines/api-consistency-engine.js +30 -335
- package/bin/runners/lib/engines/cross-file-analysis-engine.js +27 -292
- package/bin/runners/lib/engines/empty-catch-engine.js +17 -127
- package/bin/runners/lib/engines/mock-data-engine.js +10 -53
- package/bin/runners/lib/engines/performance-issues-engine.js +36 -176
- package/bin/runners/lib/engines/security-vulnerabilities-engine.js +54 -382
- package/bin/runners/lib/engines/type-aware-engine.js +39 -263
- package/bin/runners/lib/engines/vibecheck-engines/index.js +13 -122
- package/bin/runners/lib/engines/vibecheck-engines/lib/ast-cache.js +164 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/code-quality-engine.js +291 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/console-logs-engine.js +83 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/dead-code-engine.js +198 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/deprecated-api-engine.js +275 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/empty-catch-engine.js +167 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/file-filter.js +217 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/hardcoded-secrets-engine.js +73 -373
- package/bin/runners/lib/engines/vibecheck-engines/lib/mock-data-engine.js +140 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/parallel-processor.js +164 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/performance-issues-engine.js +234 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/type-aware-engine.js +217 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/unsafe-regex-engine.js +78 -0
- package/bin/runners/lib/entitlements-v2.js +73 -97
- package/bin/runners/lib/error-handler.js +44 -3
- package/bin/runners/lib/error-messages.js +289 -0
- package/bin/runners/lib/evidence-pack.js +7 -1
- package/bin/runners/lib/finding-id.js +69 -0
- package/bin/runners/lib/finding-sorter.js +89 -0
- package/bin/runners/lib/html-proof-report.js +700 -350
- package/bin/runners/lib/missions/plan.js +6 -46
- package/bin/runners/lib/missions/templates.js +0 -232
- package/bin/runners/lib/next-action.js +560 -0
- package/bin/runners/lib/prerequisites.js +149 -0
- package/bin/runners/lib/route-detection.js +137 -68
- package/bin/runners/lib/scan-output.js +91 -76
- package/bin/runners/lib/scan-runner.js +135 -0
- package/bin/runners/lib/schemas/ajv-validator.js +464 -0
- package/bin/runners/lib/schemas/error-envelope.schema.json +105 -0
- package/bin/runners/lib/schemas/finding-v3.schema.json +151 -0
- package/bin/runners/lib/schemas/report-artifact.schema.json +120 -0
- package/bin/runners/lib/schemas/run-request.schema.json +108 -0
- package/bin/runners/lib/schemas/validator.js +27 -0
- package/bin/runners/lib/schemas/verdict.schema.json +140 -0
- package/bin/runners/lib/ship-output-enterprise.js +23 -23
- package/bin/runners/lib/ship-output.js +75 -31
- package/bin/runners/lib/terminal-ui.js +6 -113
- package/bin/runners/lib/truth.js +351 -10
- package/bin/runners/lib/unified-cli-output.js +430 -603
- package/bin/runners/lib/unified-output.js +13 -9
- package/bin/runners/runAIAgent.js +10 -5
- package/bin/runners/runAgent.js +0 -3
- package/bin/runners/runAllowlist.js +389 -0
- package/bin/runners/runApprove.js +0 -33
- package/bin/runners/runAuth.js +73 -45
- package/bin/runners/runCheckpoint.js +51 -11
- package/bin/runners/runClassify.js +85 -21
- package/bin/runners/runContext.js +0 -3
- package/bin/runners/runDoctor.js +41 -28
- package/bin/runners/runEvidencePack.js +362 -0
- package/bin/runners/runFirewall.js +0 -3
- package/bin/runners/runFirewallHook.js +0 -3
- package/bin/runners/runFix.js +66 -76
- package/bin/runners/runGuard.js +18 -411
- package/bin/runners/runInit.js +113 -30
- package/bin/runners/runLabs.js +424 -0
- package/bin/runners/runMcp.js +19 -25
- package/bin/runners/runPolish.js +64 -240
- package/bin/runners/runPromptFirewall.js +12 -5
- package/bin/runners/runProve.js +57 -22
- package/bin/runners/runQuickstart.js +531 -0
- package/bin/runners/runReality.js +59 -68
- package/bin/runners/runReport.js +38 -33
- package/bin/runners/runRuntime.js +8 -5
- package/bin/runners/runScan.js +1413 -190
- package/bin/runners/runShip.js +113 -719
- package/bin/runners/runTruth.js +0 -3
- package/bin/runners/runValidate.js +13 -9
- package/bin/runners/runWatch.js +23 -14
- package/bin/scan.js +6 -1
- package/bin/vibecheck.js +204 -185
- package/mcp-server/deprecation-middleware.js +282 -0
- package/mcp-server/handlers/index.ts +15 -0
- package/mcp-server/handlers/tool-handler.ts +554 -0
- package/mcp-server/index-v1.js +698 -0
- package/mcp-server/index.js +210 -238
- package/mcp-server/lib/cache-wrapper.cjs +383 -0
- package/mcp-server/lib/error-envelope.js +138 -0
- package/mcp-server/lib/executor.ts +499 -0
- package/mcp-server/lib/index.ts +19 -0
- package/mcp-server/lib/rate-limiter.js +166 -0
- package/mcp-server/lib/sandbox.test.ts +519 -0
- package/mcp-server/lib/sandbox.ts +395 -0
- package/mcp-server/lib/types.ts +267 -0
- package/mcp-server/package.json +12 -3
- package/mcp-server/registry/tool-registry.js +794 -0
- package/mcp-server/registry/tools.json +605 -0
- package/mcp-server/registry.test.ts +334 -0
- package/mcp-server/tests/tier-gating.test.js +297 -0
- package/mcp-server/tier-auth.js +378 -45
- package/mcp-server/tools-v3.js +353 -442
- package/mcp-server/tsconfig.json +37 -0
- package/mcp-server/vibecheck-2.0-tools.js +14 -1
- package/package.json +1 -1
- package/bin/runners/lib/agent-firewall/learning/learning-engine.js +0 -849
- package/bin/runners/lib/audit-logger.js +0 -532
- package/bin/runners/lib/authority/authorities/architecture.js +0 -364
- package/bin/runners/lib/authority/authorities/compliance.js +0 -341
- package/bin/runners/lib/authority/authorities/human.js +0 -343
- package/bin/runners/lib/authority/authorities/quality.js +0 -420
- package/bin/runners/lib/authority/authorities/security.js +0 -228
- package/bin/runners/lib/authority/index.js +0 -293
- package/bin/runners/lib/bundle/bundle-intelligence.js +0 -846
- package/bin/runners/lib/cli-charts.js +0 -368
- package/bin/runners/lib/cli-config-display.js +0 -405
- package/bin/runners/lib/cli-demo.js +0 -275
- package/bin/runners/lib/cli-errors.js +0 -438
- package/bin/runners/lib/cli-help-formatter.js +0 -439
- package/bin/runners/lib/cli-interactive-menu.js +0 -509
- package/bin/runners/lib/cli-prompts.js +0 -441
- package/bin/runners/lib/cli-scan-cards.js +0 -362
- package/bin/runners/lib/compliance-reporter.js +0 -710
- package/bin/runners/lib/conductor/index.js +0 -671
- package/bin/runners/lib/easy/README.md +0 -123
- package/bin/runners/lib/easy/index.js +0 -140
- package/bin/runners/lib/easy/interactive-wizard.js +0 -788
- package/bin/runners/lib/easy/one-click-firewall.js +0 -564
- package/bin/runners/lib/easy/zero-config-reality.js +0 -714
- package/bin/runners/lib/engines/async-patterns-engine.js +0 -444
- package/bin/runners/lib/engines/bundle-size-engine.js +0 -433
- package/bin/runners/lib/engines/confidence-scoring.js +0 -276
- package/bin/runners/lib/engines/context-detection.js +0 -264
- package/bin/runners/lib/engines/database-patterns-engine.js +0 -429
- package/bin/runners/lib/engines/duplicate-code-engine.js +0 -354
- package/bin/runners/lib/engines/env-variables-engine.js +0 -458
- package/bin/runners/lib/engines/error-handling-engine.js +0 -437
- package/bin/runners/lib/engines/false-positive-prevention.js +0 -630
- package/bin/runners/lib/engines/framework-adapters/index.js +0 -607
- package/bin/runners/lib/engines/framework-detection.js +0 -508
- package/bin/runners/lib/engines/import-order-engine.js +0 -429
- package/bin/runners/lib/engines/naming-conventions-engine.js +0 -544
- package/bin/runners/lib/engines/noise-reduction-engine.js +0 -452
- package/bin/runners/lib/engines/orchestrator.js +0 -334
- package/bin/runners/lib/engines/react-patterns-engine.js +0 -457
- package/bin/runners/lib/engines/vibecheck-engines/lib/ai-hallucination-engine.js +0 -806
- package/bin/runners/lib/engines/vibecheck-engines/lib/smart-fix-engine.js +0 -577
- package/bin/runners/lib/engines/vibecheck-engines/lib/vibe-score-engine.js +0 -543
- package/bin/runners/lib/engines/vibecheck-engines.js +0 -514
- package/bin/runners/lib/enhanced-features/index.js +0 -305
- package/bin/runners/lib/enhanced-output.js +0 -631
- package/bin/runners/lib/enterprise.js +0 -300
- package/bin/runners/lib/firewall/command-validator.js +0 -351
- package/bin/runners/lib/firewall/config.js +0 -341
- package/bin/runners/lib/firewall/content-validator.js +0 -519
- package/bin/runners/lib/firewall/index.js +0 -101
- package/bin/runners/lib/firewall/path-validator.js +0 -256
- package/bin/runners/lib/intelligence/cross-repo-intelligence.js +0 -817
- package/bin/runners/lib/mcp-utils.js +0 -425
- package/bin/runners/lib/output/index.js +0 -1022
- package/bin/runners/lib/policy-engine.js +0 -652
- package/bin/runners/lib/polish/autofix/accessibility-fixes.js +0 -333
- package/bin/runners/lib/polish/autofix/async-handlers.js +0 -273
- package/bin/runners/lib/polish/autofix/dead-code.js +0 -280
- package/bin/runners/lib/polish/autofix/imports-optimizer.js +0 -344
- package/bin/runners/lib/polish/autofix/index.js +0 -200
- package/bin/runners/lib/polish/autofix/remove-consoles.js +0 -209
- package/bin/runners/lib/polish/autofix/strengthen-types.js +0 -245
- package/bin/runners/lib/polish/backend-checks.js +0 -148
- package/bin/runners/lib/polish/documentation-checks.js +0 -111
- package/bin/runners/lib/polish/frontend-checks.js +0 -168
- package/bin/runners/lib/polish/index.js +0 -71
- package/bin/runners/lib/polish/infrastructure-checks.js +0 -131
- package/bin/runners/lib/polish/library-detection.js +0 -175
- package/bin/runners/lib/polish/performance-checks.js +0 -100
- package/bin/runners/lib/polish/security-checks.js +0 -148
- package/bin/runners/lib/polish/utils.js +0 -203
- package/bin/runners/lib/prompt-builder.js +0 -540
- package/bin/runners/lib/proof-certificate.js +0 -634
- package/bin/runners/lib/reality/accessibility-audit.js +0 -946
- package/bin/runners/lib/reality/api-contract-validator.js +0 -1012
- package/bin/runners/lib/reality/chaos-engineering.js +0 -1084
- package/bin/runners/lib/reality/performance-tracker.js +0 -1077
- package/bin/runners/lib/reality/scenario-generator.js +0 -1404
- package/bin/runners/lib/reality/visual-regression.js +0 -852
- package/bin/runners/lib/reality-profiler.js +0 -717
- package/bin/runners/lib/replay/flight-recorder-viewer.js +0 -1160
- package/bin/runners/lib/review/ai-code-review.js +0 -832
- package/bin/runners/lib/rules/custom-rule-engine.js +0 -985
- package/bin/runners/lib/sbom-generator.js +0 -641
- package/bin/runners/lib/scan-output-enhanced.js +0 -512
- package/bin/runners/lib/security/owasp-scanner.js +0 -939
- package/bin/runners/lib/validators/contract-validator.js +0 -283
- package/bin/runners/lib/validators/dead-export-detector.js +0 -279
- package/bin/runners/lib/validators/dep-audit.js +0 -245
- package/bin/runners/lib/validators/env-validator.js +0 -319
- package/bin/runners/lib/validators/index.js +0 -120
- package/bin/runners/lib/validators/license-checker.js +0 -252
- package/bin/runners/lib/validators/route-validator.js +0 -290
- package/bin/runners/runAuthority.js +0 -528
- package/bin/runners/runConductor.js +0 -772
- package/bin/runners/runContainer.js +0 -366
- package/bin/runners/runEasy.js +0 -410
- package/bin/runners/runIaC.js +0 -372
- package/bin/runners/runVibe.js +0 -791
- package/mcp-server/tools.js +0 -495
|
@@ -1,946 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Accessibility Audit Engine
|
|
3
|
-
*
|
|
4
|
-
* ═══════════════════════════════════════════════════════════════════════════════
|
|
5
|
-
* COMPETITIVE MOAT FEATURE - WCAG 2.1 Compliance Checking
|
|
6
|
-
* ═══════════════════════════════════════════════════════════════════════════════
|
|
7
|
-
*
|
|
8
|
-
* This engine audits web pages for accessibility issues during Reality Mode.
|
|
9
|
-
* It checks against WCAG 2.1 guidelines at levels A, AA, and AAA.
|
|
10
|
-
*
|
|
11
|
-
* Categories:
|
|
12
|
-
* - Perceivable (images, media, content structure)
|
|
13
|
-
* - Operable (keyboard, timing, navigation)
|
|
14
|
-
* - Understandable (readable, predictable, input assistance)
|
|
15
|
-
* - Robust (compatible with assistive technologies)
|
|
16
|
-
*
|
|
17
|
-
* Features:
|
|
18
|
-
* - Runtime accessibility checking
|
|
19
|
-
* - Color contrast analysis
|
|
20
|
-
* - Keyboard navigation testing
|
|
21
|
-
* - Screen reader compatibility
|
|
22
|
-
* - Focus management
|
|
23
|
-
* - ARIA validation
|
|
24
|
-
* - Form accessibility
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
"use strict";
|
|
28
|
-
|
|
29
|
-
const fs = require("fs");
|
|
30
|
-
const path = require("path");
|
|
31
|
-
|
|
32
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
33
|
-
// WCAG 2.1 RULES
|
|
34
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
35
|
-
|
|
36
|
-
const WCAG_RULES = {
|
|
37
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
38
|
-
// 1. PERCEIVABLE
|
|
39
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
40
|
-
perceivable: {
|
|
41
|
-
name: "Perceivable",
|
|
42
|
-
principle: "1",
|
|
43
|
-
rules: [
|
|
44
|
-
{
|
|
45
|
-
id: "img-alt",
|
|
46
|
-
name: "Images have alt text",
|
|
47
|
-
wcag: "1.1.1",
|
|
48
|
-
level: "A",
|
|
49
|
-
impact: "critical",
|
|
50
|
-
selector: "img",
|
|
51
|
-
check: (el) => {
|
|
52
|
-
const alt = el.getAttribute("alt");
|
|
53
|
-
const role = el.getAttribute("role");
|
|
54
|
-
|
|
55
|
-
// Decorative images can have empty alt or role="presentation"
|
|
56
|
-
if (role === "presentation" || role === "none") return true;
|
|
57
|
-
if (alt === "") return true; // Empty alt is valid for decorative
|
|
58
|
-
|
|
59
|
-
return alt !== null && alt.trim().length > 0;
|
|
60
|
-
},
|
|
61
|
-
message: "Image missing alt text",
|
|
62
|
-
fix: "Add descriptive alt attribute or alt=\"\" for decorative images"
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
id: "img-alt-quality",
|
|
66
|
-
name: "Alt text is meaningful",
|
|
67
|
-
wcag: "1.1.1",
|
|
68
|
-
level: "A",
|
|
69
|
-
impact: "moderate",
|
|
70
|
-
selector: "img[alt]",
|
|
71
|
-
check: (el) => {
|
|
72
|
-
const alt = el.getAttribute("alt");
|
|
73
|
-
if (!alt) return true;
|
|
74
|
-
|
|
75
|
-
// Check for unhelpful alt text
|
|
76
|
-
const badPatterns = [
|
|
77
|
-
/^image$/i,
|
|
78
|
-
/^img$/i,
|
|
79
|
-
/^picture$/i,
|
|
80
|
-
/^photo$/i,
|
|
81
|
-
/^icon$/i,
|
|
82
|
-
/^graphic$/i,
|
|
83
|
-
/^\d+$/,
|
|
84
|
-
/^untitled/i,
|
|
85
|
-
/^screenshot/i,
|
|
86
|
-
/\.(?:jpg|png|gif|svg|webp)$/i
|
|
87
|
-
];
|
|
88
|
-
|
|
89
|
-
return !badPatterns.some(p => p.test(alt));
|
|
90
|
-
},
|
|
91
|
-
message: "Alt text is not descriptive",
|
|
92
|
-
fix: "Provide meaningful description of the image content"
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
id: "video-captions",
|
|
96
|
-
name: "Videos have captions",
|
|
97
|
-
wcag: "1.2.2",
|
|
98
|
-
level: "A",
|
|
99
|
-
impact: "critical",
|
|
100
|
-
selector: "video",
|
|
101
|
-
check: (el) => {
|
|
102
|
-
const tracks = el.querySelectorAll("track[kind='captions'], track[kind='subtitles']");
|
|
103
|
-
return tracks.length > 0;
|
|
104
|
-
},
|
|
105
|
-
message: "Video missing captions",
|
|
106
|
-
fix: "Add <track kind=\"captions\"> element"
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
id: "audio-transcript",
|
|
110
|
-
name: "Audio has transcript",
|
|
111
|
-
wcag: "1.2.1",
|
|
112
|
-
level: "A",
|
|
113
|
-
impact: "critical",
|
|
114
|
-
selector: "audio",
|
|
115
|
-
check: (el) => {
|
|
116
|
-
// Check for nearby transcript link or content
|
|
117
|
-
const parent = el.closest("figure, div, section");
|
|
118
|
-
if (parent) {
|
|
119
|
-
const hasTranscript = parent.textContent.toLowerCase().includes("transcript") ||
|
|
120
|
-
parent.querySelector("[data-transcript], .transcript");
|
|
121
|
-
return hasTranscript;
|
|
122
|
-
}
|
|
123
|
-
return false;
|
|
124
|
-
},
|
|
125
|
-
message: "Audio content may need transcript",
|
|
126
|
-
fix: "Provide text transcript for audio content"
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
id: "color-contrast",
|
|
130
|
-
name: "Sufficient color contrast",
|
|
131
|
-
wcag: "1.4.3",
|
|
132
|
-
level: "AA",
|
|
133
|
-
impact: "serious",
|
|
134
|
-
selector: "*",
|
|
135
|
-
checkComputed: true,
|
|
136
|
-
check: (el, computedStyle) => {
|
|
137
|
-
// Only check text elements
|
|
138
|
-
if (!el.textContent.trim()) return true;
|
|
139
|
-
|
|
140
|
-
const color = computedStyle.color;
|
|
141
|
-
const bgColor = computedStyle.backgroundColor;
|
|
142
|
-
const fontSize = parseFloat(computedStyle.fontSize);
|
|
143
|
-
const fontWeight = computedStyle.fontWeight;
|
|
144
|
-
|
|
145
|
-
// Skip transparent backgrounds
|
|
146
|
-
if (bgColor === "transparent" || bgColor === "rgba(0, 0, 0, 0)") return true;
|
|
147
|
-
|
|
148
|
-
const ratio = calculateContrastRatio(color, bgColor);
|
|
149
|
-
const isLargeText = fontSize >= 18 || (fontSize >= 14 && parseInt(fontWeight) >= 700);
|
|
150
|
-
|
|
151
|
-
// WCAG AA: 4.5:1 for normal text, 3:1 for large text
|
|
152
|
-
const requiredRatio = isLargeText ? 3 : 4.5;
|
|
153
|
-
|
|
154
|
-
return ratio >= requiredRatio;
|
|
155
|
-
},
|
|
156
|
-
message: "Insufficient color contrast",
|
|
157
|
-
fix: "Increase contrast ratio to at least 4.5:1 (or 3:1 for large text)"
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
id: "text-resize",
|
|
161
|
-
name: "Text can be resized",
|
|
162
|
-
wcag: "1.4.4",
|
|
163
|
-
level: "AA",
|
|
164
|
-
impact: "moderate",
|
|
165
|
-
selector: "*",
|
|
166
|
-
checkComputed: true,
|
|
167
|
-
check: (el, computedStyle) => {
|
|
168
|
-
// Check if font size uses relative units or is at least 16px
|
|
169
|
-
const fontSize = computedStyle.fontSize;
|
|
170
|
-
return !fontSize.includes("px") || parseFloat(fontSize) >= 12;
|
|
171
|
-
},
|
|
172
|
-
message: "Text may not resize properly",
|
|
173
|
-
fix: "Use relative units (rem, em) for font sizes"
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
id: "heading-order",
|
|
177
|
-
name: "Headings in logical order",
|
|
178
|
-
wcag: "1.3.1",
|
|
179
|
-
level: "A",
|
|
180
|
-
impact: "moderate",
|
|
181
|
-
selector: "h1, h2, h3, h4, h5, h6",
|
|
182
|
-
checkAll: true,
|
|
183
|
-
check: (elements) => {
|
|
184
|
-
let lastLevel = 0;
|
|
185
|
-
for (const el of elements) {
|
|
186
|
-
const level = parseInt(el.tagName[1]);
|
|
187
|
-
if (level > lastLevel + 1) {
|
|
188
|
-
return { valid: false, element: el };
|
|
189
|
-
}
|
|
190
|
-
lastLevel = level;
|
|
191
|
-
}
|
|
192
|
-
return { valid: true };
|
|
193
|
-
},
|
|
194
|
-
message: "Heading levels skipped",
|
|
195
|
-
fix: "Use heading levels in sequential order (h1, h2, h3, etc.)"
|
|
196
|
-
}
|
|
197
|
-
]
|
|
198
|
-
},
|
|
199
|
-
|
|
200
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
201
|
-
// 2. OPERABLE
|
|
202
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
203
|
-
operable: {
|
|
204
|
-
name: "Operable",
|
|
205
|
-
principle: "2",
|
|
206
|
-
rules: [
|
|
207
|
-
{
|
|
208
|
-
id: "keyboard-accessible",
|
|
209
|
-
name: "Keyboard accessible",
|
|
210
|
-
wcag: "2.1.1",
|
|
211
|
-
level: "A",
|
|
212
|
-
impact: "critical",
|
|
213
|
-
selector: "a, button, input, select, textarea, [tabindex], [onclick]",
|
|
214
|
-
check: (el) => {
|
|
215
|
-
const tabindex = el.getAttribute("tabindex");
|
|
216
|
-
|
|
217
|
-
// Interactive elements should be focusable
|
|
218
|
-
if (tabindex === "-1" && !el.disabled) {
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// Custom interactive elements need tabindex
|
|
223
|
-
if (el.hasAttribute("onclick") && !el.hasAttribute("tabindex")) {
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return true;
|
|
228
|
-
},
|
|
229
|
-
message: "Element not keyboard accessible",
|
|
230
|
-
fix: "Ensure element can receive focus via keyboard (add tabindex=\"0\")"
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
id: "focus-visible",
|
|
234
|
-
name: "Focus indicator visible",
|
|
235
|
-
wcag: "2.4.7",
|
|
236
|
-
level: "AA",
|
|
237
|
-
impact: "serious",
|
|
238
|
-
selector: "a, button, input, select, textarea, [tabindex]:not([tabindex='-1'])",
|
|
239
|
-
checkComputed: true,
|
|
240
|
-
checkOnFocus: true,
|
|
241
|
-
check: (el, computedStyle, focusStyle) => {
|
|
242
|
-
// Check if outline is removed without replacement
|
|
243
|
-
if (focusStyle.outline === "none" || focusStyle.outline === "0") {
|
|
244
|
-
// Check for alternative focus indicators
|
|
245
|
-
const hasBorderChange = focusStyle.border !== computedStyle.border;
|
|
246
|
-
const hasBoxShadow = focusStyle.boxShadow !== "none" &&
|
|
247
|
-
focusStyle.boxShadow !== computedStyle.boxShadow;
|
|
248
|
-
const hasBgChange = focusStyle.backgroundColor !== computedStyle.backgroundColor;
|
|
249
|
-
|
|
250
|
-
return hasBorderChange || hasBoxShadow || hasBgChange;
|
|
251
|
-
}
|
|
252
|
-
return true;
|
|
253
|
-
},
|
|
254
|
-
message: "Focus indicator not visible",
|
|
255
|
-
fix: "Add visible focus styles (:focus, :focus-visible)"
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
id: "skip-link",
|
|
259
|
-
name: "Skip navigation link",
|
|
260
|
-
wcag: "2.4.1",
|
|
261
|
-
level: "A",
|
|
262
|
-
impact: "moderate",
|
|
263
|
-
checkPage: true,
|
|
264
|
-
check: (document) => {
|
|
265
|
-
const skipLinks = document.querySelectorAll(
|
|
266
|
-
"a[href^='#main'], a[href^='#content'], .skip-link, [class*='skip']"
|
|
267
|
-
);
|
|
268
|
-
return skipLinks.length > 0;
|
|
269
|
-
},
|
|
270
|
-
message: "Missing skip navigation link",
|
|
271
|
-
fix: "Add a skip link at the top of the page"
|
|
272
|
-
},
|
|
273
|
-
{
|
|
274
|
-
id: "page-title",
|
|
275
|
-
name: "Page has title",
|
|
276
|
-
wcag: "2.4.2",
|
|
277
|
-
level: "A",
|
|
278
|
-
impact: "serious",
|
|
279
|
-
checkPage: true,
|
|
280
|
-
check: (document) => {
|
|
281
|
-
const title = document.title;
|
|
282
|
-
return title && title.trim().length > 0;
|
|
283
|
-
},
|
|
284
|
-
message: "Page missing title",
|
|
285
|
-
fix: "Add descriptive <title> element"
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
id: "link-purpose",
|
|
289
|
-
name: "Link purpose clear",
|
|
290
|
-
wcag: "2.4.4",
|
|
291
|
-
level: "A",
|
|
292
|
-
impact: "moderate",
|
|
293
|
-
selector: "a",
|
|
294
|
-
check: (el) => {
|
|
295
|
-
const text = el.textContent.trim().toLowerCase();
|
|
296
|
-
const ariaLabel = el.getAttribute("aria-label");
|
|
297
|
-
|
|
298
|
-
// Check for non-descriptive links
|
|
299
|
-
const badPatterns = ["click here", "here", "read more", "more", "link"];
|
|
300
|
-
|
|
301
|
-
if (badPatterns.includes(text) && !ariaLabel) {
|
|
302
|
-
return false;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
return true;
|
|
306
|
-
},
|
|
307
|
-
message: "Link text is not descriptive",
|
|
308
|
-
fix: "Use descriptive link text or add aria-label"
|
|
309
|
-
},
|
|
310
|
-
{
|
|
311
|
-
id: "no-timing",
|
|
312
|
-
name: "No time limit or adjustable",
|
|
313
|
-
wcag: "2.2.1",
|
|
314
|
-
level: "A",
|
|
315
|
-
impact: "critical",
|
|
316
|
-
checkPage: true,
|
|
317
|
-
check: (document) => {
|
|
318
|
-
// Check for common auto-refresh patterns
|
|
319
|
-
const metaRefresh = document.querySelector("meta[http-equiv='refresh']");
|
|
320
|
-
if (metaRefresh) {
|
|
321
|
-
const content = metaRefresh.getAttribute("content");
|
|
322
|
-
if (content && !content.includes("url=")) {
|
|
323
|
-
return false; // Auto-refresh without redirect
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return true;
|
|
327
|
-
},
|
|
328
|
-
message: "Page has automatic time-based changes",
|
|
329
|
-
fix: "Remove auto-refresh or provide user control"
|
|
330
|
-
},
|
|
331
|
-
{
|
|
332
|
-
id: "no-keyboard-trap",
|
|
333
|
-
name: "No keyboard trap",
|
|
334
|
-
wcag: "2.1.2",
|
|
335
|
-
level: "A",
|
|
336
|
-
impact: "critical",
|
|
337
|
-
selector: "[tabindex], a, button, input, select, textarea",
|
|
338
|
-
checkInteractive: true,
|
|
339
|
-
check: async (el, page) => {
|
|
340
|
-
// Focus the element
|
|
341
|
-
await el.focus();
|
|
342
|
-
|
|
343
|
-
// Try to tab away
|
|
344
|
-
await page.keyboard.press("Tab");
|
|
345
|
-
const activeAfter = await page.evaluate(() => document.activeElement.outerHTML);
|
|
346
|
-
|
|
347
|
-
// Check if focus moved
|
|
348
|
-
return activeAfter !== el.outerHTML;
|
|
349
|
-
},
|
|
350
|
-
message: "Keyboard trap detected",
|
|
351
|
-
fix: "Ensure users can navigate away using Tab or Escape"
|
|
352
|
-
}
|
|
353
|
-
]
|
|
354
|
-
},
|
|
355
|
-
|
|
356
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
357
|
-
// 3. UNDERSTANDABLE
|
|
358
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
359
|
-
understandable: {
|
|
360
|
-
name: "Understandable",
|
|
361
|
-
principle: "3",
|
|
362
|
-
rules: [
|
|
363
|
-
{
|
|
364
|
-
id: "lang-attribute",
|
|
365
|
-
name: "Page language specified",
|
|
366
|
-
wcag: "3.1.1",
|
|
367
|
-
level: "A",
|
|
368
|
-
impact: "serious",
|
|
369
|
-
checkPage: true,
|
|
370
|
-
check: (document) => {
|
|
371
|
-
const html = document.documentElement;
|
|
372
|
-
const lang = html.getAttribute("lang") || html.getAttribute("xml:lang");
|
|
373
|
-
return lang && lang.length >= 2;
|
|
374
|
-
},
|
|
375
|
-
message: "Page language not specified",
|
|
376
|
-
fix: "Add lang attribute to <html> element"
|
|
377
|
-
},
|
|
378
|
-
{
|
|
379
|
-
id: "label-input",
|
|
380
|
-
name: "Form inputs have labels",
|
|
381
|
-
wcag: "3.3.2",
|
|
382
|
-
level: "A",
|
|
383
|
-
impact: "critical",
|
|
384
|
-
selector: "input:not([type='hidden']):not([type='submit']):not([type='button']), select, textarea",
|
|
385
|
-
check: (el) => {
|
|
386
|
-
// Check for explicit label
|
|
387
|
-
const id = el.getAttribute("id");
|
|
388
|
-
if (id && document.querySelector(`label[for="${id}"]`)) {
|
|
389
|
-
return true;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// Check for implicit label (wrapped)
|
|
393
|
-
if (el.closest("label")) {
|
|
394
|
-
return true;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
// Check for aria-label or aria-labelledby
|
|
398
|
-
if (el.getAttribute("aria-label") || el.getAttribute("aria-labelledby")) {
|
|
399
|
-
return true;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
// Check for title (less preferred)
|
|
403
|
-
if (el.getAttribute("title")) {
|
|
404
|
-
return true;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// Check for placeholder (not sufficient alone but may indicate intent)
|
|
408
|
-
if (el.getAttribute("placeholder")) {
|
|
409
|
-
return false; // Placeholder alone is not sufficient
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
return false;
|
|
413
|
-
},
|
|
414
|
-
message: "Form input missing label",
|
|
415
|
-
fix: "Add <label for=\"id\"> or aria-label attribute"
|
|
416
|
-
},
|
|
417
|
-
{
|
|
418
|
-
id: "error-identification",
|
|
419
|
-
name: "Error messages clear",
|
|
420
|
-
wcag: "3.3.1",
|
|
421
|
-
level: "A",
|
|
422
|
-
impact: "serious",
|
|
423
|
-
selector: "[aria-invalid='true'], .error, .invalid, [class*='error']",
|
|
424
|
-
check: (el) => {
|
|
425
|
-
// Check if error has associated description
|
|
426
|
-
const ariaDescribedBy = el.getAttribute("aria-describedby");
|
|
427
|
-
const ariaErrorMessage = el.getAttribute("aria-errormessage");
|
|
428
|
-
|
|
429
|
-
// Check for nearby error message
|
|
430
|
-
const parent = el.closest("div, fieldset, form");
|
|
431
|
-
const hasErrorText = parent?.querySelector("[class*='error'], [role='alert']");
|
|
432
|
-
|
|
433
|
-
return ariaDescribedBy || ariaErrorMessage || hasErrorText;
|
|
434
|
-
},
|
|
435
|
-
message: "Error not clearly identified",
|
|
436
|
-
fix: "Associate error message with aria-describedby"
|
|
437
|
-
},
|
|
438
|
-
{
|
|
439
|
-
id: "consistent-navigation",
|
|
440
|
-
name: "Consistent navigation",
|
|
441
|
-
wcag: "3.2.3",
|
|
442
|
-
level: "AA",
|
|
443
|
-
impact: "moderate",
|
|
444
|
-
checkPage: true,
|
|
445
|
-
check: (document) => {
|
|
446
|
-
// Check for standard navigation landmarks
|
|
447
|
-
const nav = document.querySelector("nav, [role='navigation']");
|
|
448
|
-
return nav !== null;
|
|
449
|
-
},
|
|
450
|
-
message: "No navigation landmark found",
|
|
451
|
-
fix: "Use <nav> element or role=\"navigation\""
|
|
452
|
-
},
|
|
453
|
-
{
|
|
454
|
-
id: "autocomplete",
|
|
455
|
-
name: "Autocomplete attributes",
|
|
456
|
-
wcag: "1.3.5",
|
|
457
|
-
level: "AA",
|
|
458
|
-
impact: "moderate",
|
|
459
|
-
selector: "input[type='text'], input[type='email'], input[type='tel'], input[type='password']",
|
|
460
|
-
check: (el) => {
|
|
461
|
-
const name = (el.getAttribute("name") || "").toLowerCase();
|
|
462
|
-
const id = (el.getAttribute("id") || "").toLowerCase();
|
|
463
|
-
|
|
464
|
-
// Common field patterns that should have autocomplete
|
|
465
|
-
const autocompletable = [
|
|
466
|
-
"name", "email", "phone", "tel", "address", "city", "state",
|
|
467
|
-
"zip", "postal", "country", "cc-", "card"
|
|
468
|
-
];
|
|
469
|
-
|
|
470
|
-
const shouldHaveAutocomplete = autocompletable.some(
|
|
471
|
-
pattern => name.includes(pattern) || id.includes(pattern)
|
|
472
|
-
);
|
|
473
|
-
|
|
474
|
-
if (shouldHaveAutocomplete) {
|
|
475
|
-
return el.hasAttribute("autocomplete");
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
return true;
|
|
479
|
-
},
|
|
480
|
-
message: "Input should have autocomplete attribute",
|
|
481
|
-
fix: "Add appropriate autocomplete value (e.g., autocomplete=\"email\")"
|
|
482
|
-
}
|
|
483
|
-
]
|
|
484
|
-
},
|
|
485
|
-
|
|
486
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
487
|
-
// 4. ROBUST
|
|
488
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
489
|
-
robust: {
|
|
490
|
-
name: "Robust",
|
|
491
|
-
principle: "4",
|
|
492
|
-
rules: [
|
|
493
|
-
{
|
|
494
|
-
id: "valid-html",
|
|
495
|
-
name: "Valid HTML structure",
|
|
496
|
-
wcag: "4.1.1",
|
|
497
|
-
level: "A",
|
|
498
|
-
impact: "serious",
|
|
499
|
-
checkPage: true,
|
|
500
|
-
check: (document) => {
|
|
501
|
-
// Check for duplicate IDs
|
|
502
|
-
const ids = Array.from(document.querySelectorAll("[id]"))
|
|
503
|
-
.map(el => el.id);
|
|
504
|
-
const uniqueIds = new Set(ids);
|
|
505
|
-
|
|
506
|
-
return ids.length === uniqueIds.size;
|
|
507
|
-
},
|
|
508
|
-
message: "Duplicate IDs found",
|
|
509
|
-
fix: "Ensure all ID attributes are unique"
|
|
510
|
-
},
|
|
511
|
-
{
|
|
512
|
-
id: "aria-valid",
|
|
513
|
-
name: "Valid ARIA attributes",
|
|
514
|
-
wcag: "4.1.2",
|
|
515
|
-
level: "A",
|
|
516
|
-
impact: "critical",
|
|
517
|
-
selector: "[role], [aria-label], [aria-describedby], [aria-labelledby], [aria-hidden]",
|
|
518
|
-
check: (el) => {
|
|
519
|
-
// Check role is valid
|
|
520
|
-
const role = el.getAttribute("role");
|
|
521
|
-
const validRoles = [
|
|
522
|
-
"alert", "alertdialog", "application", "article", "banner", "button",
|
|
523
|
-
"cell", "checkbox", "columnheader", "combobox", "complementary",
|
|
524
|
-
"contentinfo", "definition", "dialog", "directory", "document",
|
|
525
|
-
"feed", "figure", "form", "grid", "gridcell", "group", "heading",
|
|
526
|
-
"img", "link", "list", "listbox", "listitem", "log", "main",
|
|
527
|
-
"marquee", "math", "menu", "menubar", "menuitem", "menuitemcheckbox",
|
|
528
|
-
"menuitemradio", "navigation", "none", "note", "option", "presentation",
|
|
529
|
-
"progressbar", "radio", "radiogroup", "region", "row", "rowgroup",
|
|
530
|
-
"rowheader", "scrollbar", "search", "searchbox", "separator", "slider",
|
|
531
|
-
"spinbutton", "status", "switch", "tab", "table", "tablist", "tabpanel",
|
|
532
|
-
"term", "textbox", "timer", "toolbar", "tooltip", "tree", "treegrid", "treeitem"
|
|
533
|
-
];
|
|
534
|
-
|
|
535
|
-
if (role && !validRoles.includes(role)) {
|
|
536
|
-
return false;
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
// Check aria-labelledby/describedby targets exist
|
|
540
|
-
const labelledby = el.getAttribute("aria-labelledby");
|
|
541
|
-
if (labelledby) {
|
|
542
|
-
const ids = labelledby.split(/\s+/);
|
|
543
|
-
for (const id of ids) {
|
|
544
|
-
if (!document.getElementById(id)) {
|
|
545
|
-
return false;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
const describedby = el.getAttribute("aria-describedby");
|
|
551
|
-
if (describedby) {
|
|
552
|
-
const ids = describedby.split(/\s+/);
|
|
553
|
-
for (const id of ids) {
|
|
554
|
-
if (!document.getElementById(id)) {
|
|
555
|
-
return false;
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
return true;
|
|
561
|
-
},
|
|
562
|
-
message: "Invalid ARIA attribute or reference",
|
|
563
|
-
fix: "Fix ARIA role or ensure referenced IDs exist"
|
|
564
|
-
},
|
|
565
|
-
{
|
|
566
|
-
id: "button-name",
|
|
567
|
-
name: "Buttons have accessible name",
|
|
568
|
-
wcag: "4.1.2",
|
|
569
|
-
level: "A",
|
|
570
|
-
impact: "critical",
|
|
571
|
-
selector: "button, [role='button'], input[type='button'], input[type='submit']",
|
|
572
|
-
check: (el) => {
|
|
573
|
-
// Check for accessible name
|
|
574
|
-
const textContent = el.textContent?.trim();
|
|
575
|
-
const ariaLabel = el.getAttribute("aria-label");
|
|
576
|
-
const ariaLabelledby = el.getAttribute("aria-labelledby");
|
|
577
|
-
const title = el.getAttribute("title");
|
|
578
|
-
const value = el.getAttribute("value");
|
|
579
|
-
|
|
580
|
-
return !!(textContent || ariaLabel || ariaLabelledby || title || value);
|
|
581
|
-
},
|
|
582
|
-
message: "Button missing accessible name",
|
|
583
|
-
fix: "Add text content, aria-label, or title attribute"
|
|
584
|
-
},
|
|
585
|
-
{
|
|
586
|
-
id: "status-messages",
|
|
587
|
-
name: "Status messages use live regions",
|
|
588
|
-
wcag: "4.1.3",
|
|
589
|
-
level: "AA",
|
|
590
|
-
impact: "moderate",
|
|
591
|
-
selector: ".toast, .notification, .alert, .message, [class*='success'], [class*='error']",
|
|
592
|
-
check: (el) => {
|
|
593
|
-
const role = el.getAttribute("role");
|
|
594
|
-
const ariaLive = el.getAttribute("aria-live");
|
|
595
|
-
|
|
596
|
-
// Should have role="alert", role="status", or aria-live
|
|
597
|
-
return role === "alert" || role === "status" || ariaLive;
|
|
598
|
-
},
|
|
599
|
-
message: "Status message not announced to screen readers",
|
|
600
|
-
fix: "Add role=\"alert\" or aria-live=\"polite\""
|
|
601
|
-
}
|
|
602
|
-
]
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
607
|
-
// UTILITY FUNCTIONS
|
|
608
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
609
|
-
|
|
610
|
-
/**
|
|
611
|
-
* Parse color string to RGB
|
|
612
|
-
*/
|
|
613
|
-
function parseColor(colorStr) {
|
|
614
|
-
// Handle rgb(r, g, b) format
|
|
615
|
-
const rgbMatch = colorStr.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);
|
|
616
|
-
if (rgbMatch) {
|
|
617
|
-
return {
|
|
618
|
-
r: parseInt(rgbMatch[1]),
|
|
619
|
-
g: parseInt(rgbMatch[2]),
|
|
620
|
-
b: parseInt(rgbMatch[3])
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
// Handle rgba(r, g, b, a) format
|
|
625
|
-
const rgbaMatch = colorStr.match(/rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)/);
|
|
626
|
-
if (rgbaMatch) {
|
|
627
|
-
return {
|
|
628
|
-
r: parseInt(rgbaMatch[1]),
|
|
629
|
-
g: parseInt(rgbaMatch[2]),
|
|
630
|
-
b: parseInt(rgbaMatch[3]),
|
|
631
|
-
a: parseFloat(rgbaMatch[4])
|
|
632
|
-
};
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
return null;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
/**
|
|
639
|
-
* Calculate relative luminance
|
|
640
|
-
*/
|
|
641
|
-
function getLuminance(rgb) {
|
|
642
|
-
const rsRGB = rgb.r / 255;
|
|
643
|
-
const gsRGB = rgb.g / 255;
|
|
644
|
-
const bsRGB = rgb.b / 255;
|
|
645
|
-
|
|
646
|
-
const r = rsRGB <= 0.03928 ? rsRGB / 12.92 : Math.pow((rsRGB + 0.055) / 1.055, 2.4);
|
|
647
|
-
const g = gsRGB <= 0.03928 ? gsRGB / 12.92 : Math.pow((gsRGB + 0.055) / 1.055, 2.4);
|
|
648
|
-
const b = bsRGB <= 0.03928 ? bsRGB / 12.92 : Math.pow((bsRGB + 0.055) / 1.055, 2.4);
|
|
649
|
-
|
|
650
|
-
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
/**
|
|
654
|
-
* Calculate contrast ratio between two colors
|
|
655
|
-
*/
|
|
656
|
-
function calculateContrastRatio(color1Str, color2Str) {
|
|
657
|
-
const color1 = parseColor(color1Str);
|
|
658
|
-
const color2 = parseColor(color2Str);
|
|
659
|
-
|
|
660
|
-
if (!color1 || !color2) return 21; // Assume passing if can't parse
|
|
661
|
-
|
|
662
|
-
const l1 = getLuminance(color1);
|
|
663
|
-
const l2 = getLuminance(color2);
|
|
664
|
-
|
|
665
|
-
const lighter = Math.max(l1, l2);
|
|
666
|
-
const darker = Math.min(l1, l2);
|
|
667
|
-
|
|
668
|
-
return (lighter + 0.05) / (darker + 0.05);
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
672
|
-
// ACCESSIBILITY AUDIT ENGINE
|
|
673
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
674
|
-
|
|
675
|
-
class AccessibilityAuditEngine {
|
|
676
|
-
constructor(options = {}) {
|
|
677
|
-
this.rules = { ...WCAG_RULES };
|
|
678
|
-
this.levels = options.levels || ["A", "AA"]; // Default to AA conformance
|
|
679
|
-
this.page = null;
|
|
680
|
-
this.results = [];
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
/**
|
|
684
|
-
* Set the Playwright page
|
|
685
|
-
*/
|
|
686
|
-
setPage(page) {
|
|
687
|
-
this.page = page;
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
/**
|
|
691
|
-
* Run full accessibility audit
|
|
692
|
-
*/
|
|
693
|
-
async audit() {
|
|
694
|
-
if (!this.page) {
|
|
695
|
-
throw new Error("Page not set. Call setPage() first.");
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
this.results = [];
|
|
699
|
-
|
|
700
|
-
for (const [categoryId, category] of Object.entries(this.rules)) {
|
|
701
|
-
for (const rule of category.rules) {
|
|
702
|
-
// Skip rules above our conformance level
|
|
703
|
-
if (!this.levels.includes(rule.level)) continue;
|
|
704
|
-
|
|
705
|
-
const findings = await this.runRule(rule, categoryId, category);
|
|
706
|
-
this.results.push(...findings);
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
return this.generateReport();
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* Run a single rule
|
|
715
|
-
*/
|
|
716
|
-
async runRule(rule, categoryId, category) {
|
|
717
|
-
const findings = [];
|
|
718
|
-
|
|
719
|
-
try {
|
|
720
|
-
// Page-level check
|
|
721
|
-
if (rule.checkPage) {
|
|
722
|
-
const result = await this.page.evaluate((ruleCheck) => {
|
|
723
|
-
// This is a simplified version - full impl would serialize the check function
|
|
724
|
-
return true;
|
|
725
|
-
}, rule.check.toString());
|
|
726
|
-
|
|
727
|
-
// Run the actual check
|
|
728
|
-
const passed = await this.page.evaluate(`(${rule.check.toString()})(document)`);
|
|
729
|
-
|
|
730
|
-
if (!passed) {
|
|
731
|
-
findings.push(this.createFinding(rule, categoryId, category, null, 0));
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
// Element-level check
|
|
735
|
-
else if (rule.selector) {
|
|
736
|
-
if (rule.checkAll) {
|
|
737
|
-
// Check all elements together
|
|
738
|
-
const elements = await this.page.$$(rule.selector);
|
|
739
|
-
const result = await this.page.evaluate(
|
|
740
|
-
(selector, checkFn) => {
|
|
741
|
-
const els = document.querySelectorAll(selector);
|
|
742
|
-
const fn = new Function("elements", `return (${checkFn})(elements)`);
|
|
743
|
-
return fn(els);
|
|
744
|
-
},
|
|
745
|
-
rule.selector,
|
|
746
|
-
rule.check.toString()
|
|
747
|
-
);
|
|
748
|
-
|
|
749
|
-
if (!result.valid) {
|
|
750
|
-
findings.push(this.createFinding(rule, categoryId, category, null, 0));
|
|
751
|
-
}
|
|
752
|
-
} else {
|
|
753
|
-
// Check each element individually
|
|
754
|
-
const elements = await this.page.$$(rule.selector);
|
|
755
|
-
|
|
756
|
-
for (let i = 0; i < elements.length; i++) {
|
|
757
|
-
const el = elements[i];
|
|
758
|
-
|
|
759
|
-
let passed = true;
|
|
760
|
-
|
|
761
|
-
if (rule.checkComputed) {
|
|
762
|
-
passed = await this.page.evaluate(
|
|
763
|
-
(selector, index, checkFn) => {
|
|
764
|
-
const el = document.querySelectorAll(selector)[index];
|
|
765
|
-
const style = window.getComputedStyle(el);
|
|
766
|
-
const fn = new Function("el", "style", `return (${checkFn})(el, style)`);
|
|
767
|
-
return fn(el, style);
|
|
768
|
-
},
|
|
769
|
-
rule.selector,
|
|
770
|
-
i,
|
|
771
|
-
rule.check.toString()
|
|
772
|
-
);
|
|
773
|
-
} else {
|
|
774
|
-
passed = await this.page.evaluate(
|
|
775
|
-
(selector, index, checkFn) => {
|
|
776
|
-
const el = document.querySelectorAll(selector)[index];
|
|
777
|
-
const fn = new Function("el", `return (${checkFn})(el)`);
|
|
778
|
-
return fn(el);
|
|
779
|
-
},
|
|
780
|
-
rule.selector,
|
|
781
|
-
i,
|
|
782
|
-
rule.check.toString()
|
|
783
|
-
);
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
if (!passed) {
|
|
787
|
-
const elementInfo = await el.evaluate(el => ({
|
|
788
|
-
tagName: el.tagName,
|
|
789
|
-
id: el.id,
|
|
790
|
-
className: el.className,
|
|
791
|
-
textContent: el.textContent?.substring(0, 50)
|
|
792
|
-
}));
|
|
793
|
-
|
|
794
|
-
findings.push(this.createFinding(rule, categoryId, category, elementInfo, i));
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
} catch (error) {
|
|
800
|
-
// Log but don't fail entire audit
|
|
801
|
-
console.error(`Rule ${rule.id} failed:`, error.message);
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
return findings;
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
/**
|
|
808
|
-
* Create a finding object
|
|
809
|
-
*/
|
|
810
|
-
createFinding(rule, categoryId, category, element, index) {
|
|
811
|
-
return {
|
|
812
|
-
id: `${rule.id}-${index}`,
|
|
813
|
-
ruleId: rule.id,
|
|
814
|
-
ruleName: rule.name,
|
|
815
|
-
wcag: rule.wcag,
|
|
816
|
-
level: rule.level,
|
|
817
|
-
impact: rule.impact,
|
|
818
|
-
category: categoryId,
|
|
819
|
-
categoryName: category.name,
|
|
820
|
-
principle: category.principle,
|
|
821
|
-
message: rule.message,
|
|
822
|
-
fix: rule.fix,
|
|
823
|
-
element: element ? {
|
|
824
|
-
tagName: element.tagName,
|
|
825
|
-
id: element.id,
|
|
826
|
-
className: element.className,
|
|
827
|
-
text: element.textContent
|
|
828
|
-
} : null
|
|
829
|
-
};
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
/**
|
|
833
|
-
* Generate audit report
|
|
834
|
-
*/
|
|
835
|
-
generateReport() {
|
|
836
|
-
const byLevel = {
|
|
837
|
-
A: this.results.filter(r => r.level === "A"),
|
|
838
|
-
AA: this.results.filter(r => r.level === "AA"),
|
|
839
|
-
AAA: this.results.filter(r => r.level === "AAA")
|
|
840
|
-
};
|
|
841
|
-
|
|
842
|
-
const byImpact = {
|
|
843
|
-
critical: this.results.filter(r => r.impact === "critical"),
|
|
844
|
-
serious: this.results.filter(r => r.impact === "serious"),
|
|
845
|
-
moderate: this.results.filter(r => r.impact === "moderate"),
|
|
846
|
-
minor: this.results.filter(r => r.impact === "minor")
|
|
847
|
-
};
|
|
848
|
-
|
|
849
|
-
const byCategory = {};
|
|
850
|
-
for (const finding of this.results) {
|
|
851
|
-
if (!byCategory[finding.category]) {
|
|
852
|
-
byCategory[finding.category] = [];
|
|
853
|
-
}
|
|
854
|
-
byCategory[finding.category].push(finding);
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
// Calculate conformance
|
|
858
|
-
const conformance = {
|
|
859
|
-
A: byLevel.A.filter(r => r.impact === "critical" || r.impact === "serious").length === 0,
|
|
860
|
-
AA: byLevel.AA.filter(r => r.impact === "critical" || r.impact === "serious").length === 0 &&
|
|
861
|
-
byLevel.A.filter(r => r.impact === "critical" || r.impact === "serious").length === 0
|
|
862
|
-
};
|
|
863
|
-
|
|
864
|
-
return {
|
|
865
|
-
timestamp: new Date().toISOString(),
|
|
866
|
-
url: this.page.url(),
|
|
867
|
-
summary: {
|
|
868
|
-
total: this.results.length,
|
|
869
|
-
byLevel: {
|
|
870
|
-
A: byLevel.A.length,
|
|
871
|
-
AA: byLevel.AA.length,
|
|
872
|
-
AAA: byLevel.AAA.length
|
|
873
|
-
},
|
|
874
|
-
byImpact: {
|
|
875
|
-
critical: byImpact.critical.length,
|
|
876
|
-
serious: byImpact.serious.length,
|
|
877
|
-
moderate: byImpact.moderate.length,
|
|
878
|
-
minor: byImpact.minor.length
|
|
879
|
-
},
|
|
880
|
-
conformance
|
|
881
|
-
},
|
|
882
|
-
byCategory,
|
|
883
|
-
findings: this.results,
|
|
884
|
-
score: this.calculateScore()
|
|
885
|
-
};
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
/**
|
|
889
|
-
* Calculate accessibility score (0-100)
|
|
890
|
-
*/
|
|
891
|
-
calculateScore() {
|
|
892
|
-
if (this.results.length === 0) return 100;
|
|
893
|
-
|
|
894
|
-
// Weight by impact
|
|
895
|
-
const weights = { critical: 25, serious: 10, moderate: 5, minor: 2 };
|
|
896
|
-
let deductions = 0;
|
|
897
|
-
|
|
898
|
-
for (const finding of this.results) {
|
|
899
|
-
deductions += weights[finding.impact] || 5;
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
return Math.max(0, 100 - deductions);
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
/**
|
|
906
|
-
* Generate WCAG compliance checklist
|
|
907
|
-
*/
|
|
908
|
-
generateChecklist() {
|
|
909
|
-
const checklist = [];
|
|
910
|
-
|
|
911
|
-
for (const [categoryId, category] of Object.entries(this.rules)) {
|
|
912
|
-
for (const rule of category.rules) {
|
|
913
|
-
if (!this.levels.includes(rule.level)) continue;
|
|
914
|
-
|
|
915
|
-
const failures = this.results.filter(r => r.ruleId === rule.id);
|
|
916
|
-
|
|
917
|
-
checklist.push({
|
|
918
|
-
wcag: rule.wcag,
|
|
919
|
-
level: rule.level,
|
|
920
|
-
name: rule.name,
|
|
921
|
-
category: category.name,
|
|
922
|
-
status: failures.length === 0 ? "PASS" : "FAIL",
|
|
923
|
-
failures: failures.length
|
|
924
|
-
});
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
return checklist.sort((a, b) => {
|
|
929
|
-
// Sort by WCAG number
|
|
930
|
-
const aNum = parseFloat(a.wcag);
|
|
931
|
-
const bNum = parseFloat(b.wcag);
|
|
932
|
-
return aNum - bNum;
|
|
933
|
-
});
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
938
|
-
// EXPORTS
|
|
939
|
-
// ═══════════════════════════════════════════════════════════════════════════════
|
|
940
|
-
|
|
941
|
-
module.exports = {
|
|
942
|
-
AccessibilityAuditEngine,
|
|
943
|
-
WCAG_RULES,
|
|
944
|
-
calculateContrastRatio,
|
|
945
|
-
getLuminance
|
|
946
|
-
};
|