@surea11y/core 1.0.0
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/CHANGELOG.md +49 -0
- package/LICENSE +21 -0
- package/README.md +145 -0
- package/bin/core.js +244 -0
- package/docs/BINDING_AUTHORS_GUIDE.md +41 -0
- package/docs/CLI.md +49 -0
- package/docs/ENGINE_OPTIONS.md +155 -0
- package/docs/I18N.md +47 -0
- package/docs/INTEGRATION.md +156 -0
- package/docs/LIMITATIONS.md +31 -0
- package/docs/OUTPUT_SCHEMA.md +237 -0
- package/docs/POLICY.md +71 -0
- package/docs/RULE_AUTHORING.md +375 -0
- package/docs/RULE_CATALOG.md +180 -0
- package/docs/RULE_TAXONOMY.md +145 -0
- package/docs/TROUBLESHOOTING.md +48 -0
- package/docs/WCAG_CONFORMANCE.md +49 -0
- package/package.json +60 -0
- package/src/catalogs/composites.wcag.js +490 -0
- package/src/checks/automatic/area-alt-present.js +225 -0
- package/src/checks/automatic/aria-allowed-attr.js +206 -0
- package/src/checks/automatic/aria-allowed-role.js +102 -0
- package/src/checks/automatic/aria-braille-equivalent.js +139 -0
- package/src/checks/automatic/aria-conditional-attr.js +110 -0
- package/src/checks/automatic/aria-deprecated-role.js +106 -0
- package/src/checks/automatic/aria-hidden-body.js +87 -0
- package/src/checks/automatic/aria-hidden-focus.js +480 -0
- package/src/checks/automatic/aria-prohibited-attr.js +156 -0
- package/src/checks/automatic/aria-prohibited-children.js +265 -0
- package/src/checks/automatic/aria-required-attr.js +154 -0
- package/src/checks/automatic/aria-required-children.js +274 -0
- package/src/checks/automatic/aria-required-parent.js +222 -0
- package/src/checks/automatic/aria-role-name-present.js +201 -0
- package/src/checks/automatic/aria-roles-valid.js +110 -0
- package/src/checks/automatic/aria-valid-attr-value.js +123 -0
- package/src/checks/automatic/aria-valid-attr.js +109 -0
- package/src/checks/automatic/autocomplete-valid.js +134 -0
- package/src/checks/automatic/avoid-inline-spacing.js +107 -0
- package/src/checks/automatic/binary-control-name-present.js +294 -0
- package/src/checks/automatic/button-name-present.js +146 -0
- package/src/checks/automatic/bypass-blocks-present.js +162 -0
- package/src/checks/automatic/canvas-text-alternative-present.js +140 -0
- package/src/checks/automatic/combobox-name-present.js +267 -0
- package/src/checks/automatic/contrast-computable.js +378 -0
- package/src/checks/automatic/contrast-enhanced.js +517 -0
- package/src/checks/automatic/contrast-minimum.js +512 -0
- package/src/checks/automatic/css-orientation-lock.js +206 -0
- package/src/checks/automatic/definition-list-children-valid.js +148 -0
- package/src/checks/automatic/deprecated-elements-not-used.js +91 -0
- package/src/checks/automatic/dialog-name-present.js +209 -0
- package/src/checks/automatic/dlitem-parent-valid.js +100 -0
- package/src/checks/automatic/duplicate-id-aria.js +126 -0
- package/src/checks/automatic/embed-text-alternative-present.js +190 -0
- package/src/checks/automatic/form-control-programmatic-label-present.js +409 -0
- package/src/checks/automatic/form-control-single-label.js +117 -0
- package/src/checks/automatic/html-xml-lang-mismatch.js +91 -0
- package/src/checks/automatic/iframe-focusable-content.js +141 -0
- package/src/checks/automatic/iframe-name-present.js +102 -0
- package/src/checks/automatic/iframe-title-unique.js +107 -0
- package/src/checks/automatic/img-alt-present.js +223 -0
- package/src/checks/automatic/input-image-alt-present.js +155 -0
- package/src/checks/automatic/label-in-name.js +326 -0
- package/src/checks/automatic/language-page-present.js +159 -0
- package/src/checks/automatic/link-in-text-block.js +218 -0
- package/src/checks/automatic/link-name-present.js +114 -0
- package/src/checks/automatic/list-children-valid.js +152 -0
- package/src/checks/automatic/listbox-name-present.js +236 -0
- package/src/checks/automatic/listitem-parent-valid.js +118 -0
- package/src/checks/automatic/menuitem-name-present.js +201 -0
- package/src/checks/automatic/meta-refresh-no-exceptions.js +105 -0
- package/src/checks/automatic/meta-refresh-timing-absent.js +107 -0
- package/src/checks/automatic/meta-viewport-zoom-enabled.js +118 -0
- package/src/checks/automatic/meter-name-present.js +160 -0
- package/src/checks/automatic/nested-interactive-controls-absent.js +135 -0
- package/src/checks/automatic/object-text-alternative-present.js +193 -0
- package/src/checks/automatic/option-name-present.js +157 -0
- package/src/checks/automatic/page-title-present.js +86 -0
- package/src/checks/automatic/progressbar-name-present.js +165 -0
- package/src/checks/automatic/role-img-alt-present.js +206 -0
- package/src/checks/automatic/searchbox-name-present.js +236 -0
- package/src/checks/automatic/server-side-image-map-absent.js +88 -0
- package/src/checks/automatic/slider-name-present.js +276 -0
- package/src/checks/automatic/spinbutton-name-present.js +236 -0
- package/src/checks/automatic/summary-name-present.js +153 -0
- package/src/checks/automatic/svg-image-text-alternative-present.js +220 -0
- package/src/checks/automatic/svg-text-alternative-present.js +298 -0
- package/src/checks/automatic/tab-name-present.js +200 -0
- package/src/checks/automatic/table-headers-attr-valid.js +122 -0
- package/src/checks/automatic/table-th-has-data-cells.js +117 -0
- package/src/checks/automatic/target-size-minimum.js +605 -0
- package/src/checks/automatic/td-has-header.js +151 -0
- package/src/checks/automatic/textbox-name-present.js +236 -0
- package/src/checks/automatic/tooltip-name-present.js +158 -0
- package/src/checks/automatic/treeitem-name-present.js +157 -0
- package/src/checks/automatic/valid-lang.js +100 -0
- package/src/checks/automatic/video-poster-text-alternative-present.js +193 -0
- package/src/checks/manual/accesskeys-manual.js +93 -0
- package/src/checks/manual/area-alt-decorative-manual.js +247 -0
- package/src/checks/manual/area-alt-quality-manual.js +204 -0
- package/src/checks/manual/aria-checked-state-mismatch-manual.js +141 -0
- package/src/checks/manual/aria-text-manual.js +109 -0
- package/src/checks/manual/canvas-text-alternative-quality-manual.js +170 -0
- package/src/checks/manual/css-hidden-focus.js +259 -0
- package/src/checks/manual/embed-text-alternative-quality-manual.js +204 -0
- package/src/checks/manual/empty-heading-manual.js +182 -0
- package/src/checks/manual/empty-table-header-manual.js +163 -0
- package/src/checks/manual/focus-order-semantics-manual.js +117 -0
- package/src/checks/manual/form-control-programmatic-label-quality-manual.js +291 -0
- package/src/checks/manual/heading-order-manual.js +130 -0
- package/src/checks/manual/identical-links-same-purpose-manual.js +142 -0
- package/src/checks/manual/image-redundant-alt-manual.js +118 -0
- package/src/checks/manual/img-alt-decorative-manual.js +148 -0
- package/src/checks/manual/img-alt-quality-manual.js +182 -0
- package/src/checks/manual/input-image-alt-decorative-manual.js +144 -0
- package/src/checks/manual/input-image-alt-quality-manual.js +144 -0
- package/src/checks/manual/label-title-only-manual.js +115 -0
- package/src/checks/manual/landmark-banner-is-top-level-manual.js +180 -0
- package/src/checks/manual/landmark-contentinfo-is-top-level-manual.js +169 -0
- package/src/checks/manual/landmark-main-is-top-level-manual.js +167 -0
- package/src/checks/manual/landmark-no-duplicate-banner-manual.js +177 -0
- package/src/checks/manual/landmark-no-duplicate-contentinfo-manual.js +169 -0
- package/src/checks/manual/landmark-no-duplicate-main-manual.js +132 -0
- package/src/checks/manual/landmark-one-main-manual.js +151 -0
- package/src/checks/manual/landmark-unique-manual.js +252 -0
- package/src/checks/manual/link-name-quality-manual.js +143 -0
- package/src/checks/manual/media-transcript-present-manual.js +373 -0
- package/src/checks/manual/meta-viewport-large-manual.js +119 -0
- package/src/checks/manual/mouse-only-event-handlers-manual.js +134 -0
- package/src/checks/manual/no-autoplay-audio-manual.js +116 -0
- package/src/checks/manual/object-text-alternative-quality-manual.js +194 -0
- package/src/checks/manual/p-as-heading-manual.js +163 -0
- package/src/checks/manual/page-has-heading-one-manual.js +110 -0
- package/src/checks/manual/page-title-patterns-manual.js +262 -0
- package/src/checks/manual/presentation-role-conflict-manual.js +159 -0
- package/src/checks/manual/region-manual.js +183 -0
- package/src/checks/manual/scope-attr-valid-manual.js +93 -0
- package/src/checks/manual/scrollable-region-focusable-manual.js +168 -0
- package/src/checks/manual/skip-link-manual.js +150 -0
- package/src/checks/manual/svg-text-alternative-quality-manual.js +209 -0
- package/src/checks/manual/tabindex-manual.js +94 -0
- package/src/checks/manual/table-duplicate-name-manual.js +99 -0
- package/src/checks/manual/table-fake-caption-manual.js +122 -0
- package/src/checks/manual/video-caption-manual.js +118 -0
- package/src/checks/manual-review.js +95 -0
- package/src/checks/rules-and-tags.full.csv +19 -0
- package/src/checks/rules-and-tags.full.json +259 -0
- package/src/core/aria-helpers.js +906 -0
- package/src/core/contrast-helpers.js +1147 -0
- package/src/core/dom-helpers.js +4085 -0
- package/src/core/dom-runner.js +627 -0
- package/src/core/frame-messaging.js +210 -0
- package/src/core/frame-scan.js +178 -0
- package/src/core/rollup-composites.js +135 -0
- package/src/core/rule-meta.js +140 -0
- package/src/core.js +79055 -0
- package/src/coverage/wcag-facets.js +1079 -0
- package/src/coverage/wcag-version-map.js +84 -0
- package/src/i18n/en.js +919 -0
- package/src/i18n/fr.js +527 -0
- package/src/index.js +4 -0
- package/src/policy/contracts.js +18 -0
- package/src/policy/resolvePolicy.js +55 -0
- package/src/policy/schemas/engine-options.schema.json +103 -0
- package/src/policy/schemas/policy-contract.schema.json +40 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const id = 'contrast-computable';
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Color contrast is computable for rendered text',
|
|
7
|
+
description:
|
|
8
|
+
'Determines whether sufficient information is available to compute WCAG color contrast for visible text (e.g., no gradients/images/blend modes that make background indeterminate).',
|
|
9
|
+
i18n: {
|
|
10
|
+
titleKey: 'contrastComputable_title',
|
|
11
|
+
descriptionKey: 'contrastComputable_description'
|
|
12
|
+
},
|
|
13
|
+
helpUrl: null,
|
|
14
|
+
tags: [
|
|
15
|
+
'wcag2aa',
|
|
16
|
+
'wcag2aaa',
|
|
17
|
+
'wcag143',
|
|
18
|
+
'wcag146',
|
|
19
|
+
'contrast',
|
|
20
|
+
'color',
|
|
21
|
+
'structure',
|
|
22
|
+
'atomic',
|
|
23
|
+
'automatic',
|
|
24
|
+
'dom'
|
|
25
|
+
],
|
|
26
|
+
wcagSc: ['1.4.3', '1.4.6'],
|
|
27
|
+
normativeMappings: [
|
|
28
|
+
{
|
|
29
|
+
standard: 'WCAG',
|
|
30
|
+
version: '2.2',
|
|
31
|
+
requirement: '1.4.3',
|
|
32
|
+
title: 'Contrast (Minimum)',
|
|
33
|
+
conformanceLevel: 'AA'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
standard: 'WCAG',
|
|
37
|
+
version: '2.2',
|
|
38
|
+
requirement: '1.4.6',
|
|
39
|
+
title: 'Contrast (Enhanced)',
|
|
40
|
+
conformanceLevel: 'AAA'
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
defaultSeverity: 'serious',
|
|
44
|
+
category: 'perceivable',
|
|
45
|
+
type: 'automatic',
|
|
46
|
+
defaultConfidence: 'high',
|
|
47
|
+
coverage: {
|
|
48
|
+
facetsBySc: {
|
|
49
|
+
'1.4.3': ['contrast-computability-143'],
|
|
50
|
+
'1.4.6': ['contrast-computability-146']
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function runInPage(ctx) {
|
|
56
|
+
const {helpers, rule, engineOptions} = ctx;
|
|
57
|
+
|
|
58
|
+
const __contrastSharedCache = helpers && helpers.contrast && helpers.contrast.sharedCache ? helpers.contrast.sharedCache : null;
|
|
59
|
+
|
|
60
|
+
const contrast = engineOptions && typeof engineOptions.contrast === 'object' && engineOptions.contrast
|
|
61
|
+
? engineOptions.contrast
|
|
62
|
+
: {};
|
|
63
|
+
|
|
64
|
+
const mode = contrast.mode === 'auditorAssist' ? 'auditorAssist' : 'strictConformance';
|
|
65
|
+
|
|
66
|
+
const rootCanvasFallback =
|
|
67
|
+
typeof contrast.rootCanvasFallback === 'string' && contrast.rootCanvasFallback.trim()
|
|
68
|
+
? contrast.rootCanvasFallback.trim()
|
|
69
|
+
: '#ffffff';
|
|
70
|
+
|
|
71
|
+
const MAX_OCCURRENCES = 50;
|
|
72
|
+
|
|
73
|
+
const occurrences = [];
|
|
74
|
+
let eligibleTextCount = 0;
|
|
75
|
+
let cantTellCount = 0;
|
|
76
|
+
let assumptionsCount = 0;
|
|
77
|
+
const assumptionsAppliedSet = new Set();
|
|
78
|
+
|
|
79
|
+
const seenFailEls = new Set();
|
|
80
|
+
|
|
81
|
+
function pushCantTellOccurrence(el, reasonCode, extraDetails) {
|
|
82
|
+
try {
|
|
83
|
+
if (!el || seenFailEls.has(el)) return;
|
|
84
|
+
if (occurrences.length >= MAX_OCCURRENCES) return;
|
|
85
|
+
seenFailEls.add(el);
|
|
86
|
+
|
|
87
|
+
const rc = String(reasonCode || 'UNKNOWN');
|
|
88
|
+
|
|
89
|
+
// Match test contract: choose a specific summaryKey per computability blocker.
|
|
90
|
+
// Fall back to the generic notComputable key.
|
|
91
|
+
let summaryKey = 'contrastComputable_cantTell_notComputable';
|
|
92
|
+
if (rc === 'BACKGROUND_IMAGE_OR_GRADIENT') {
|
|
93
|
+
const t =
|
|
94
|
+
extraDetails && typeof extraDetails === 'object'
|
|
95
|
+
? String(extraDetails.backgroundFillType || '')
|
|
96
|
+
: '';
|
|
97
|
+
|
|
98
|
+
if (t === 'image') summaryKey = 'contrastComputable_cantTell_bgImage';
|
|
99
|
+
else if (t === 'gradient') summaryKey = 'contrastComputable_cantTell_bgGradient';
|
|
100
|
+
else if (t === 'imageAndGradient') summaryKey = 'contrastComputable_cantTell_bgImageAndGradient';
|
|
101
|
+
else summaryKey = 'contrastComputable_cantTell_bgImageOrGradient';
|
|
102
|
+
} else if (rc === 'MIX_BLEND_MODE') summaryKey = 'contrastComputable_cantTell_mixBlendMode';
|
|
103
|
+
else if (rc === 'BACKGROUND_FILTER_OR_BACKDROP_FILTER') {
|
|
104
|
+
const bp = extraDetails && typeof extraDetails === 'object' ? String(extraDetails.blockerProperty || '') : '';
|
|
105
|
+
if (bp === 'filter') summaryKey = 'contrastComputable_cantTell_filter';
|
|
106
|
+
else if (bp === 'backdrop-filter') summaryKey = 'contrastComputable_cantTell_backdropFilter';
|
|
107
|
+
else summaryKey = 'contrastComputable_cantTell_filterOrBackdropFilter';
|
|
108
|
+
} else if (rc === 'BACKGROUND_NOT_OPAQUE_AT_ROOT') summaryKey = 'contrastComputable_cantTell_rootNotOpaque';
|
|
109
|
+
|
|
110
|
+
const details =
|
|
111
|
+
Object.assign(
|
|
112
|
+
{reasonCode: rc},
|
|
113
|
+
extraDetails && typeof extraDetails === 'object' ? extraDetails : {}
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const occBase = {
|
|
117
|
+
selector: '',
|
|
118
|
+
html: '',
|
|
119
|
+
summary: '',
|
|
120
|
+
hint: '',
|
|
121
|
+
i18n: {
|
|
122
|
+
summaryKey,
|
|
123
|
+
hintKey: '',
|
|
124
|
+
params: Object.assign(
|
|
125
|
+
{reasonCode: rc},
|
|
126
|
+
(details && typeof details === 'object')
|
|
127
|
+
? {
|
|
128
|
+
blockerProperty: details.blockerProperty ? String(details.blockerProperty) : '',
|
|
129
|
+
blockerValue: details.blockerValue ? String(details.blockerValue) : '',
|
|
130
|
+
backgroundAlpha:
|
|
131
|
+
(details.backgroundAlpha !== undefined && details.backgroundAlpha !== null)
|
|
132
|
+
? String(details.backgroundAlpha)
|
|
133
|
+
: ''
|
|
134
|
+
}
|
|
135
|
+
: {}
|
|
136
|
+
)
|
|
137
|
+
},
|
|
138
|
+
data: {details}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
if (helpers && typeof helpers.reportOccurrence === 'function') {
|
|
142
|
+
occurrences.push(helpers.reportOccurrence(el, occBase));
|
|
143
|
+
} else {
|
|
144
|
+
// Never compute selector/snippet in the rule.
|
|
145
|
+
occurrences.push({...occBase});
|
|
146
|
+
}
|
|
147
|
+
} catch {
|
|
148
|
+
// no-throw
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// perf: cache per-element analysis so multiple text nodes in same element don't repeat expensive work
|
|
153
|
+
const __elBlockerCache = __contrastSharedCache
|
|
154
|
+
? (__contrastSharedCache.__elBlockerCache || (__contrastSharedCache.__elBlockerCache = new WeakMap()))
|
|
155
|
+
: new WeakMap(); // Element -> { ok:boolean, reasonCode, blockerSelector, blockerProperty, blockerValue }
|
|
156
|
+
const __elBgCache = __contrastSharedCache
|
|
157
|
+
? (__contrastSharedCache.__elBgCache || (__contrastSharedCache.__elBgCache = new WeakMap()))
|
|
158
|
+
: new WeakMap(); // Element -> { ok, rgba, alpha, reasonCode } (no stack)
|
|
159
|
+
const __elFgCache = __contrastSharedCache
|
|
160
|
+
? (__contrastSharedCache.__elFgCache || (__contrastSharedCache.__elFgCache = new WeakMap()))
|
|
161
|
+
: new WeakMap(); // Element -> { rgba, alpha, opacityProduct }
|
|
162
|
+
|
|
163
|
+
// perf: fast-path memo for self-opaque background (common) to avoid ancestor walk
|
|
164
|
+
const __elBgSelfOpaqueCache = __contrastSharedCache
|
|
165
|
+
? (__contrastSharedCache.__elBgSelfOpaqueCache || (__contrastSharedCache.__elBgSelfOpaqueCache = new WeakMap()))
|
|
166
|
+
: new WeakMap(); // Element -> { ok, rgba, alpha, reasonCode }
|
|
167
|
+
|
|
168
|
+
// Shared deterministic text scan (computed once per run and reused across contrast checks)
|
|
169
|
+
let scan = null;
|
|
170
|
+
try {
|
|
171
|
+
scan = helpers && helpers.contrast && typeof helpers.contrast.getTextScan === 'function'
|
|
172
|
+
? helpers.contrast.getTextScan(ctx, helpers, engineOptions)
|
|
173
|
+
: null;
|
|
174
|
+
} catch {
|
|
175
|
+
scan = null;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Walk eligible visible text nodes (counted per text node), but compute blockers/bg/fg once per element.
|
|
179
|
+
if (scan && scan.elements && Array.isArray(scan.elements)) {
|
|
180
|
+
try {
|
|
181
|
+
eligibleTextCount = Number(scan.eligibleTextCount) || 0;
|
|
182
|
+
|
|
183
|
+
for (const rec of scan.elements) {
|
|
184
|
+
// If we're already capped on occurrences and already know the final outcome is cantTell,
|
|
185
|
+
// stop scanning to avoid wasting time. Deterministic: we don't randomize; we just stop
|
|
186
|
+
// once further work cannot change the output (cantTell + capped occurrences).
|
|
187
|
+
if (cantTellCount > 0 && occurrences.length >= MAX_OCCURRENCES) break;
|
|
188
|
+
|
|
189
|
+
const el = rec && rec.el;
|
|
190
|
+
const textCount = rec && Number(rec.textCount) ? Number(rec.textCount) : 0;
|
|
191
|
+
if (!el || textCount <= 0) continue;
|
|
192
|
+
|
|
193
|
+
// 1) Blockers in ancestor chain (blend/filter/bg-image/gradient)
|
|
194
|
+
let blocker = __elBlockerCache.get(el);
|
|
195
|
+
if (!blocker) {
|
|
196
|
+
blocker = helpers.contrast.getComputabilityBlocker(el);
|
|
197
|
+
// Normalize to stable shape
|
|
198
|
+
blocker = blocker || {
|
|
199
|
+
ok: true,
|
|
200
|
+
reasonCode: null,
|
|
201
|
+
blockerSelector: '',
|
|
202
|
+
blockerProperty: '',
|
|
203
|
+
blockerValue: ''
|
|
204
|
+
};
|
|
205
|
+
__elBlockerCache.set(el, blocker);
|
|
206
|
+
}
|
|
207
|
+
if (blocker && blocker.ok === false) {
|
|
208
|
+
cantTellCount += textCount;
|
|
209
|
+
// occurrence is deduped per element (seenFailEls)
|
|
210
|
+
pushCantTellOccurrence(el, blocker.reasonCode, {
|
|
211
|
+
blockerProperty: blocker.blockerProperty,
|
|
212
|
+
blockerValue: blocker.blockerValue,
|
|
213
|
+
blockerSelector: blocker.blockerSelector,
|
|
214
|
+
backgroundFillType: blocker.backgroundFillType
|
|
215
|
+
});
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// 2) Background resolution (CSS-only), strict vs. reference-engine-compatible mode
|
|
220
|
+
let bg = __elBgCache.get(el);
|
|
221
|
+
if (!bg) {
|
|
222
|
+
// 2a) Fast-path: if the element itself paints an opaque background-color and opacity is 1,
|
|
223
|
+
// then the background behind its text is computable without walking ancestors.
|
|
224
|
+
// This is a strict subset of the full algorithm, so it is behavior-preserving:
|
|
225
|
+
// if it doesn't match, we fall back to computeEffectiveBackground.
|
|
226
|
+
let bgSelfOpaque = __elBgSelfOpaqueCache.get(el);
|
|
227
|
+
if (bgSelfOpaque === undefined) {
|
|
228
|
+
bgSelfOpaque = null;
|
|
229
|
+
try {
|
|
230
|
+
if (helpers && typeof helpers.getComputedStyle === 'function' && helpers.contrast && typeof helpers.contrast.parseCssColorToRgba === 'function') {
|
|
231
|
+
const cs = helpers.getComputedStyle(el);
|
|
232
|
+
const op = Number.parseFloat(cs && cs.opacity != null ? cs.opacity : '1');
|
|
233
|
+
// Only treat as self-opaque if opacity is exactly 1 (string '1' or number 1)
|
|
234
|
+
// to avoid float/serialization quirks and preserve determinism.
|
|
235
|
+
if (Number.isFinite(op) && op === 1) {
|
|
236
|
+
const c = helpers.contrast.parseCssColorToRgba(cs && cs.backgroundColor);
|
|
237
|
+
if (c && typeof c.a === 'number' && c.a === 1) {
|
|
238
|
+
bgSelfOpaque = {
|
|
239
|
+
ok: true,
|
|
240
|
+
rgba: {r: c.r, g: c.g, b: c.b, a: 1},
|
|
241
|
+
alpha: 1,
|
|
242
|
+
reasonCode: null
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
} catch {
|
|
248
|
+
bgSelfOpaque = null;
|
|
249
|
+
}
|
|
250
|
+
__elBgSelfOpaqueCache.set(el, bgSelfOpaque);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (bgSelfOpaque && bgSelfOpaque.ok === true) {
|
|
254
|
+
bg = bgSelfOpaque;
|
|
255
|
+
} else {
|
|
256
|
+
bg = helpers.contrast.computeEffectiveBackground(el, {
|
|
257
|
+
contrast: {mode, rootCanvasFallback},
|
|
258
|
+
collectStack: false
|
|
259
|
+
});
|
|
260
|
+
bg = bg || {ok: false, reasonCode: 'BACKGROUND_NOT_COMPUTABLE', rgba: null, alpha: 0};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
__elBgCache.set(el, bg);
|
|
264
|
+
}
|
|
265
|
+
if (!bg || bg.ok === false) {
|
|
266
|
+
cantTellCount += textCount;
|
|
267
|
+
pushCantTellOccurrence(el, (bg && bg.reasonCode) || 'BACKGROUND_NOT_COMPUTABLE', {
|
|
268
|
+
background: bg && bg.rgba ? helpers.contrast.rgbaToString(bg.rgba) : '',
|
|
269
|
+
backgroundAlpha: bg && typeof bg.alpha === 'number' ? helpers.contrast.round2(bg.alpha) : ''
|
|
270
|
+
});
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Track any explicit assumptions applied by background resolution.
|
|
275
|
+
try {
|
|
276
|
+
if (bg && Array.isArray(bg.assumptionsApplied) && bg.assumptionsApplied.length) {
|
|
277
|
+
assumptionsCount += textCount;
|
|
278
|
+
for (const a of bg.assumptionsApplied) assumptionsAppliedSet.add(String(a));
|
|
279
|
+
}
|
|
280
|
+
} catch { /* no-throw */
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// 3) Foreground parsability (computed color should be rgb/rgba)
|
|
284
|
+
let fg = __elFgCache.get(el);
|
|
285
|
+
if (!fg) {
|
|
286
|
+
fg = helpers.contrast.computeEffectiveForeground(el);
|
|
287
|
+
fg = fg || {rgba: null, alpha: 0, opacityProduct: 1};
|
|
288
|
+
__elFgCache.set(el, fg);
|
|
289
|
+
}
|
|
290
|
+
if (!fg || !fg.rgba) {
|
|
291
|
+
cantTellCount += textCount;
|
|
292
|
+
pushCantTellOccurrence(el, 'FOREGROUND_UNPARSABLE', {
|
|
293
|
+
background: bg && bg.rgba ? helpers.contrast.rgbaToString(bg.rgba) : '',
|
|
294
|
+
backgroundAlpha: bg && typeof bg.alpha === 'number' ? helpers.contrast.round2(bg.alpha) : ''
|
|
295
|
+
});
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// If we got here, this element's eligible text is computable.
|
|
300
|
+
// (We intentionally do not compute contrast ratio in this gatekeeper rule.)
|
|
301
|
+
}
|
|
302
|
+
} catch {
|
|
303
|
+
// If scan processing fails unexpectedly, keep determinism: treat as cantTell with one occurrence
|
|
304
|
+
return {
|
|
305
|
+
ruleId: rule.ruleId,
|
|
306
|
+
outcome: 'cantTell',
|
|
307
|
+
severity: rule.defaultSeverity || 'serious',
|
|
308
|
+
confidence: rule.defaultConfidence || 'high',
|
|
309
|
+
occurrences: [
|
|
310
|
+
{
|
|
311
|
+
selector: '',
|
|
312
|
+
summary: '',
|
|
313
|
+
hint: '',
|
|
314
|
+
html: '',
|
|
315
|
+
i18n: {
|
|
316
|
+
summaryKey: 'contrastComputable_cantTell_engineFailure',
|
|
317
|
+
hintKey: '',
|
|
318
|
+
params: {reasonCode: 'ENGINE_EXCEPTION'}
|
|
319
|
+
},
|
|
320
|
+
data: {details: {reasonCode: 'ENGINE_EXCEPTION'}}
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (eligibleTextCount === 0) {
|
|
328
|
+
return {
|
|
329
|
+
ruleId: rule.ruleId,
|
|
330
|
+
outcome: 'notApplicable',
|
|
331
|
+
severity: rule.defaultSeverity || 'serious',
|
|
332
|
+
confidence: rule.defaultConfidence || 'high',
|
|
333
|
+
occurrences: []
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (cantTellCount > 0) {
|
|
338
|
+
return {
|
|
339
|
+
ruleId: rule.ruleId,
|
|
340
|
+
outcome: 'cantTell',
|
|
341
|
+
severity: rule.defaultSeverity || 'serious',
|
|
342
|
+
confidence: rule.defaultConfidence || 'high',
|
|
343
|
+
occurrences
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// All eligible text is computable
|
|
348
|
+
return {
|
|
349
|
+
ruleId: rule.ruleId,
|
|
350
|
+
outcome: 'pass',
|
|
351
|
+
severity: rule.defaultSeverity || 'serious',
|
|
352
|
+
confidence: rule.defaultConfidence || 'high',
|
|
353
|
+
occurrences: [
|
|
354
|
+
{
|
|
355
|
+
selector: '',
|
|
356
|
+
summary: '',
|
|
357
|
+
hint: '',
|
|
358
|
+
html: '',
|
|
359
|
+
i18n: {
|
|
360
|
+
summaryKey: 'contrastComputable_pass_allComputable',
|
|
361
|
+
hintKey: '',
|
|
362
|
+
params: {
|
|
363
|
+
eligibleTextCount: String(eligibleTextCount)
|
|
364
|
+
}
|
|
365
|
+
},
|
|
366
|
+
data: {
|
|
367
|
+
details: {
|
|
368
|
+
eligibleTextCount,
|
|
369
|
+
assumptionsCount,
|
|
370
|
+
assumptionsApplied: Array.from(assumptionsAppliedSet).sort()
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
]
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
module.exports = {id, meta, runInPage};
|