@surea11y/core 1.2.0 → 1.3.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 +37 -7
- package/LICENSE +373 -21
- package/README.md +67 -1
- package/bin/core.js +144 -19
- package/docs/API_STABILITY.md +1 -1
- package/docs/BINDING_AUTHORS_GUIDE.md +9 -9
- package/docs/CI_INTEGRATIONS.md +103 -0
- package/docs/CLI.md +54 -1
- package/docs/ENGINE_OPTIONS.md +2 -0
- package/docs/INTEGRATION.md +18 -0
- package/docs/OUTPUT_SCHEMA.md +1 -1
- package/docs/RULE_CATALOG.md +1 -1
- package/docs/SARIF.md +59 -0
- package/package.json +15 -4
- package/src/baseline.js +0 -0
- package/src/catalogs/composites.wcag.js +414 -450
- package/src/checks/automatic/area-alt-present.js +59 -25
- package/src/checks/automatic/aria-allowed-attr.js +193 -33
- package/src/checks/automatic/aria-allowed-role.js +21 -7
- package/src/checks/automatic/aria-braille-equivalent.js +32 -10
- package/src/checks/automatic/aria-conditional-attr.js +24 -7
- package/src/checks/automatic/aria-deprecated-role.js +22 -8
- package/src/checks/automatic/aria-hidden-body.js +42 -19
- package/src/checks/automatic/aria-hidden-focus.js +408 -53
- package/src/checks/automatic/aria-prohibited-attr.js +296 -22
- package/src/checks/automatic/aria-prohibited-children.js +55 -16
- package/src/checks/automatic/aria-required-attr.js +23 -8
- package/src/checks/automatic/aria-required-children.js +37 -14
- package/src/checks/automatic/aria-required-parent.js +48 -14
- package/src/checks/automatic/aria-role-name-present.js +47 -21
- package/src/checks/automatic/aria-roles-valid.js +22 -12
- package/src/checks/automatic/aria-valid-attr-value.js +28 -7
- package/src/checks/automatic/aria-valid-attr.js +17 -5
- package/src/checks/automatic/autocomplete-valid.js +74 -16
- package/src/checks/automatic/avoid-inline-spacing.js +20 -6
- package/src/checks/automatic/binary-control-name-present.js +60 -50
- package/src/checks/automatic/button-name-present.js +48 -18
- package/src/checks/automatic/bypass-blocks-present.js +42 -25
- package/src/checks/automatic/canvas-text-alternative-present.js +57 -26
- package/src/checks/automatic/combobox-name-present.js +38 -45
- package/src/checks/automatic/contrast-computable.js +361 -341
- package/src/checks/automatic/contrast-enhanced.js +487 -466
- package/src/checks/automatic/contrast-minimum.js +486 -465
- package/src/checks/automatic/css-orientation-lock.js +30 -8
- package/src/checks/automatic/definition-list-children-valid.js +40 -19
- package/src/checks/automatic/deprecated-elements-not-used.js +21 -7
- package/src/checks/automatic/dialog-name-present.js +37 -75
- package/src/checks/automatic/dlitem-parent-valid.js +23 -8
- package/src/checks/automatic/duplicate-id-aria.js +24 -6
- package/src/checks/automatic/embed-text-alternative-present.js +86 -35
- package/src/checks/automatic/form-control-programmatic-label-present.js +79 -196
- package/src/checks/automatic/form-control-single-label.js +47 -10
- package/src/checks/automatic/html-xml-lang-mismatch.js +34 -18
- package/src/checks/automatic/iframe-focusable-content.js +26 -11
- package/src/checks/automatic/iframe-name-present.js +31 -9
- package/src/checks/automatic/iframe-title-unique.js +29 -8
- package/src/checks/automatic/img-alt-present.js +47 -43
- package/src/checks/automatic/input-image-alt-present.js +143 -112
- package/src/checks/automatic/label-in-name.js +50 -22
- package/src/checks/automatic/language-page-present.js +109 -109
- package/src/checks/automatic/link-in-text-block.js +59 -19
- package/src/checks/automatic/link-name-present.js +45 -14
- package/src/checks/automatic/list-children-valid.js +26 -9
- package/src/checks/automatic/listbox-name-present.js +39 -19
- package/src/checks/automatic/listitem-parent-valid.js +18 -6
- package/src/checks/automatic/menuitem-name-present.js +39 -61
- package/src/checks/automatic/meta-refresh-no-exceptions.js +28 -7
- package/src/checks/automatic/meta-refresh-timing-absent.js +20 -6
- package/src/checks/automatic/meta-viewport-zoom-enabled.js +24 -7
- package/src/checks/automatic/meter-name-present.js +36 -33
- package/src/checks/automatic/nested-interactive-controls-absent.js +31 -10
- package/src/checks/automatic/object-text-alternative-present.js +91 -39
- package/src/checks/automatic/option-name-present.js +38 -21
- package/src/checks/automatic/page-title-present.js +17 -6
- package/src/checks/automatic/progressbar-name-present.js +41 -34
- package/src/checks/automatic/role-img-alt-present.js +209 -157
- package/src/checks/automatic/searchbox-name-present.js +39 -19
- package/src/checks/automatic/server-side-image-map-absent.js +23 -8
- package/src/checks/automatic/slider-name-present.js +40 -47
- package/src/checks/automatic/spinbutton-name-present.js +39 -19
- package/src/checks/automatic/summary-name-present.js +37 -17
- package/src/checks/automatic/svg-image-text-alternative-present.js +114 -47
- package/src/checks/automatic/svg-text-alternative-present.js +246 -226
- package/src/checks/automatic/tab-name-present.js +37 -60
- package/src/checks/automatic/table-headers-attr-valid.js +24 -8
- package/src/checks/automatic/table-th-has-data-cells.js +22 -8
- package/src/checks/automatic/target-size-minimum.js +118 -48
- package/src/checks/automatic/td-has-header.js +29 -11
- package/src/checks/automatic/textbox-name-present.js +39 -19
- package/src/checks/automatic/tooltip-name-present.js +37 -18
- package/src/checks/automatic/treeitem-name-present.js +38 -21
- package/src/checks/automatic/valid-lang.js +20 -6
- package/src/checks/automatic/video-poster-text-alternative-present.js +79 -36
- package/src/checks/manual/accesskeys-manual.js +14 -5
- package/src/checks/manual/area-alt-decorative-manual.js +192 -193
- package/src/checks/manual/area-alt-quality-manual.js +182 -141
- package/src/checks/manual/aria-checked-state-mismatch-manual.js +34 -11
- package/src/checks/manual/aria-text-manual.js +14 -6
- package/src/checks/manual/canvas-text-alternative-quality-manual.js +149 -114
- package/src/checks/manual/css-hidden-focus.js +196 -165
- package/src/checks/manual/embed-text-alternative-quality-manual.js +171 -160
- package/src/checks/manual/empty-heading-manual.js +24 -7
- package/src/checks/manual/empty-table-header-manual.js +17 -6
- package/src/checks/manual/focus-order-semantics-manual.js +45 -10
- package/src/checks/manual/form-control-programmatic-label-quality-manual.js +207 -246
- package/src/checks/manual/heading-order-manual.js +22 -7
- package/src/checks/manual/identical-links-same-purpose-manual.js +34 -12
- package/src/checks/manual/image-redundant-alt-manual.js +17 -7
- package/src/checks/manual/img-alt-decorative-manual.js +131 -96
- package/src/checks/manual/img-alt-quality-manual.js +176 -127
- package/src/checks/manual/input-image-alt-decorative-manual.js +125 -92
- package/src/checks/manual/input-image-alt-quality-manual.js +125 -92
- package/src/checks/manual/label-title-only-manual.js +14 -5
- package/src/checks/manual/landmark-banner-is-top-level-manual.js +66 -16
- package/src/checks/manual/landmark-contentinfo-is-top-level-manual.js +53 -16
- package/src/checks/manual/landmark-main-is-top-level-manual.js +35 -10
- package/src/checks/manual/landmark-no-duplicate-banner-manual.js +29 -10
- package/src/checks/manual/landmark-no-duplicate-contentinfo-manual.js +29 -10
- package/src/checks/manual/landmark-no-duplicate-main-manual.js +17 -8
- package/src/checks/manual/landmark-one-main-manual.js +26 -20
- package/src/checks/manual/landmark-unique-manual.js +41 -15
- package/src/checks/manual/link-name-quality-manual.js +43 -12
- package/src/checks/manual/media-transcript-present-manual.js +35 -22
- package/src/checks/manual/meta-viewport-large-manual.js +16 -5
- package/src/checks/manual/mouse-only-event-handlers-manual.js +38 -11
- package/src/checks/manual/no-autoplay-audio-manual.js +20 -6
- package/src/checks/manual/object-text-alternative-quality-manual.js +175 -154
- package/src/checks/manual/p-as-heading-manual.js +22 -7
- package/src/checks/manual/page-has-heading-one-manual.js +31 -22
- package/src/checks/manual/page-title-patterns-manual.js +78 -50
- package/src/checks/manual/presentation-role-conflict-manual.js +59 -19
- package/src/checks/manual/region-manual.js +241 -48
- package/src/checks/manual/scope-attr-valid-manual.js +10 -3
- package/src/checks/manual/scrollable-region-focusable-manual.js +37 -11
- package/src/checks/manual/skip-link-manual.js +35 -12
- package/src/checks/manual/svg-text-alternative-quality-manual.js +206 -165
- package/src/checks/manual/tabindex-manual.js +10 -3
- package/src/checks/manual/table-duplicate-name-manual.js +17 -7
- package/src/checks/manual/table-fake-caption-manual.js +24 -7
- package/src/checks/manual/video-caption-manual.js +15 -4
- package/src/checks/manual-review.js +56 -12
- package/src/core/aria-helpers.js +1127 -886
- package/src/core/contrast-helpers.js +1217 -1062
- package/src/core/dom-helpers.js +4175 -3917
- package/src/core/dom-runner.js +720 -604
- package/src/core/frame-messaging.js +189 -138
- package/src/core/frame-scan.js +94 -82
- package/src/core/rollup-composites.js +94 -102
- package/src/core/rule-meta.js +58 -41
- package/src/core.js +36552 -29111
- package/src/i18n/en.js +1194 -889
- package/src/i18n/fr.js +1136 -795
- package/src/policy/contracts.js +13 -13
- package/src/policy/resolvePolicy.js +48 -44
- package/src/report.js +63 -43
- package/src/sarif.js +175 -0
- package/surea11y.browser.js +36042 -0
|
@@ -3,515 +3,536 @@
|
|
|
3
3
|
const id = 'contrast-enhanced';
|
|
4
4
|
|
|
5
5
|
const meta = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
coverage: { facetsBySc: { '1.4.6': ['contrast-enhanced-text'] } }
|
|
6
|
+
title: 'Text must meet the enhanced color contrast ratio',
|
|
7
|
+
description:
|
|
8
|
+
'Checks that visible text has a contrast ratio of at least 7:1 (normal) or 4.5:1 (large), when contrast is computable from CSS.',
|
|
9
|
+
i18n: {
|
|
10
|
+
titleKey: 'contrastEnhanced_title',
|
|
11
|
+
descriptionKey: 'contrastEnhanced_description'
|
|
12
|
+
},
|
|
13
|
+
helpUrl: null,
|
|
14
|
+
tags: ['wcag2aaa', 'wcag146', 'contrast', 'color', 'structure', 'atomic', 'automatic', 'dom'],
|
|
15
|
+
wcagSc: ['1.4.6'],
|
|
16
|
+
normativeMappings: [
|
|
17
|
+
{
|
|
18
|
+
standard: 'WCAG',
|
|
19
|
+
version: '2.2',
|
|
20
|
+
requirement: '1.4.6',
|
|
21
|
+
title: 'Contrast (Enhanced)',
|
|
22
|
+
conformanceLevel: 'AAA'
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
defaultSeverity: 'serious',
|
|
26
|
+
category: 'perceivable',
|
|
27
|
+
type: 'automatic',
|
|
28
|
+
defaultConfidence: 'high',
|
|
29
|
+
coverage: { facetsBySc: { '1.4.6': ['contrast-enhanced-text'] } }
|
|
31
30
|
};
|
|
32
31
|
|
|
33
32
|
function runInPage(ctx) {
|
|
34
|
-
|
|
33
|
+
const { helpers, rule, engineOptions } = ctx;
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
35
|
+
function toElement(node) {
|
|
36
|
+
try {
|
|
37
|
+
if (!node) return null;
|
|
38
|
+
if (node.nodeType === 1) return node; // ELEMENT_NODE
|
|
39
|
+
if (node.nodeType === 3) return node.parentElement || null; // TEXT_NODE
|
|
40
|
+
return null;
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
45
43
|
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const __contrastSharedCache =
|
|
47
|
+
helpers && helpers.contrast && helpers.contrast.sharedCache
|
|
48
|
+
? helpers.contrast.sharedCache
|
|
49
|
+
: null;
|
|
50
|
+
const __elBlockerCache = __contrastSharedCache
|
|
51
|
+
? __contrastSharedCache.__elBlockerCache ||
|
|
52
|
+
(__contrastSharedCache.__elBlockerCache = new WeakMap())
|
|
53
|
+
: null;
|
|
54
|
+
|
|
55
|
+
const __elBgCache = __contrastSharedCache
|
|
56
|
+
? __contrastSharedCache.__elBgCache || (__contrastSharedCache.__elBgCache = new WeakMap())
|
|
57
|
+
: null;
|
|
58
|
+
|
|
59
|
+
const __elFgCache = __contrastSharedCache
|
|
60
|
+
? __contrastSharedCache.__elFgCache || (__contrastSharedCache.__elFgCache = new WeakMap())
|
|
61
|
+
: null;
|
|
62
|
+
|
|
63
|
+
const __elFontCache = __contrastSharedCache
|
|
64
|
+
? __contrastSharedCache.__elFontCache || (__contrastSharedCache.__elFontCache = new WeakMap())
|
|
65
|
+
: new WeakMap();
|
|
66
|
+
|
|
67
|
+
function safeComputedStyle(el) {
|
|
68
|
+
try {
|
|
69
|
+
if (!el || el.nodeType !== 1) return null;
|
|
46
70
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
71
|
+
// Prefer engine helper (matches checks/engine behavior + may be cached)
|
|
72
|
+
if (helpers && typeof helpers.computedStyle === 'function') {
|
|
73
|
+
const cs = helpers.computedStyle(el);
|
|
74
|
+
if (cs) return cs;
|
|
75
|
+
}
|
|
51
76
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
: null;
|
|
77
|
+
const view =
|
|
78
|
+
el.ownerDocument && el.ownerDocument.defaultView ? el.ownerDocument.defaultView : null;
|
|
55
79
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
80
|
+
if (view && typeof view.getComputedStyle === 'function') return view.getComputedStyle(el);
|
|
81
|
+
} catch {}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
59
84
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
85
|
+
function getFontInfo(el) {
|
|
86
|
+
try {
|
|
87
|
+
if (!el || el.nodeType !== 1) {
|
|
88
|
+
return {
|
|
89
|
+
fontSizePx: 0,
|
|
90
|
+
fontSizePt: '',
|
|
91
|
+
fontWeightNum: 400,
|
|
92
|
+
fontWeight: 'normal',
|
|
93
|
+
isBold: false,
|
|
94
|
+
isLarge: false,
|
|
95
|
+
isLargeText: false
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const cached = __elFontCache.get(el);
|
|
100
|
+
if (cached) return cached;
|
|
101
|
+
|
|
102
|
+
const cs = safeComputedStyle(el);
|
|
103
|
+
const fontSizePx = cs ? helpers.contrast.parsePx(cs.fontSize) : null;
|
|
104
|
+
const fontWeightNum = cs ? helpers.contrast.normalizeFontWeight(cs.fontWeight) : 400;
|
|
105
|
+
|
|
106
|
+
const sizePx = Number.isFinite(fontSizePx) ? fontSizePx : 0;
|
|
107
|
+
const isBold = Number.isFinite(fontWeightNum) && fontWeightNum >= 700;
|
|
108
|
+
const isLarge = helpers.contrast.isLargeText(sizePx, fontWeightNum);
|
|
109
|
+
|
|
110
|
+
const out = {
|
|
111
|
+
fontSizePx: sizePx,
|
|
112
|
+
fontSizePt: helpers.contrast.pxToPt(sizePx),
|
|
113
|
+
fontWeightNum,
|
|
114
|
+
fontWeight: helpers.contrast.fontWeightLabel(fontWeightNum),
|
|
115
|
+
isBold,
|
|
116
|
+
isLarge,
|
|
117
|
+
isLargeText: isLarge
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
__elFontCache.set(el, out);
|
|
121
|
+
return out;
|
|
122
|
+
} catch {
|
|
123
|
+
return {
|
|
124
|
+
fontSizePx: 0,
|
|
125
|
+
fontSizePt: '',
|
|
126
|
+
fontWeightNum: 400,
|
|
127
|
+
fontWeight: 'normal',
|
|
128
|
+
isBold: false,
|
|
129
|
+
isLarge: false,
|
|
130
|
+
isLargeText: false
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
63
134
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
135
|
+
const contrast =
|
|
136
|
+
engineOptions && typeof engineOptions.contrast === 'object' && engineOptions.contrast
|
|
137
|
+
? engineOptions.contrast
|
|
138
|
+
: {};
|
|
67
139
|
|
|
68
|
-
|
|
69
|
-
if (helpers && typeof helpers.computedStyle === 'function') {
|
|
70
|
-
const cs = helpers.computedStyle(el);
|
|
71
|
-
if (cs) return cs;
|
|
72
|
-
}
|
|
140
|
+
const mode = contrast.mode === 'auditorAssist' ? 'auditorAssist' : 'strictConformance';
|
|
73
141
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
142
|
+
const rootCanvasFallback =
|
|
143
|
+
typeof contrast.rootCanvasFallback === 'string' && contrast.rootCanvasFallback.trim()
|
|
144
|
+
? contrast.rootCanvasFallback.trim()
|
|
145
|
+
: '#ffffff';
|
|
77
146
|
|
|
78
|
-
|
|
79
|
-
} catch {}
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
147
|
+
const MAX_OCCURRENCES = 50;
|
|
82
148
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
fontSizePx: 0,
|
|
88
|
-
fontSizePt: '',
|
|
89
|
-
fontWeightNum: 400,
|
|
90
|
-
fontWeight: 'normal',
|
|
91
|
-
isBold: false,
|
|
92
|
-
isLarge: false,
|
|
93
|
-
isLargeText: false
|
|
94
|
-
};
|
|
95
|
-
}
|
|
149
|
+
const occurrences = [];
|
|
150
|
+
let eligibleTextCount = 0;
|
|
151
|
+
let computableTextCount = 0;
|
|
152
|
+
let failCount = 0;
|
|
96
153
|
|
|
97
|
-
|
|
98
|
-
if (cached) return cached;
|
|
99
|
-
|
|
100
|
-
const cs = safeComputedStyle(el);
|
|
101
|
-
const fontSizePx = cs ? helpers.contrast.parsePx(cs.fontSize) : null;
|
|
102
|
-
const fontWeightNum = cs ? helpers.contrast.normalizeFontWeight(cs.fontWeight) : 400;
|
|
103
|
-
|
|
104
|
-
const sizePx = Number.isFinite(fontSizePx) ? fontSizePx : 0;
|
|
105
|
-
const isBold = Number.isFinite(fontWeightNum) && fontWeightNum >= 700;
|
|
106
|
-
const isLarge = helpers.contrast.isLargeText(sizePx, fontWeightNum);
|
|
107
|
-
|
|
108
|
-
const out = {
|
|
109
|
-
fontSizePx: sizePx,
|
|
110
|
-
fontSizePt: helpers.contrast.pxToPt(sizePx),
|
|
111
|
-
fontWeightNum,
|
|
112
|
-
fontWeight: helpers.contrast.fontWeightLabel(fontWeightNum),
|
|
113
|
-
isBold,
|
|
114
|
-
isLarge,
|
|
115
|
-
isLargeText: isLarge
|
|
116
|
-
};
|
|
154
|
+
const seenFailEls = new Set();
|
|
117
155
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
156
|
+
function pushPassOccurrence(eligibleCount, computableCount) {
|
|
157
|
+
try {
|
|
158
|
+
occurrences.push({
|
|
159
|
+
selector: '',
|
|
160
|
+
summary: 'All computable text meets the enhanced (AAA) contrast threshold.',
|
|
161
|
+
hint: '',
|
|
162
|
+
html: '',
|
|
163
|
+
i18n: {
|
|
164
|
+
summaryKey: 'contrastEnhanced_pass_allAboveThreshold',
|
|
165
|
+
hintKey: '',
|
|
166
|
+
params: {
|
|
167
|
+
eligibleTextCount: String(Number(eligibleCount) || 0),
|
|
168
|
+
computableTextCount: String(Number(computableCount) || 0)
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
data: {
|
|
172
|
+
details: {
|
|
173
|
+
reasonCode: 'ALL_ABOVE_THRESHOLD',
|
|
174
|
+
eligibleTextCount: Number(eligibleCount) || 0,
|
|
175
|
+
computableTextCount: Number(computableCount) || 0,
|
|
176
|
+
metrics: {
|
|
177
|
+
eligibleTextCount: Number(eligibleCount) || 0,
|
|
178
|
+
computableTextCount: Number(computableCount) || 0
|
|
179
|
+
}
|
|
180
|
+
}
|
|
130
181
|
}
|
|
182
|
+
});
|
|
183
|
+
} catch {
|
|
184
|
+
// no-throw
|
|
131
185
|
}
|
|
186
|
+
}
|
|
132
187
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
188
|
+
function pushFailOccurrence(el, params, details) {
|
|
189
|
+
try {
|
|
190
|
+
if (!el || seenFailEls.has(el)) return;
|
|
191
|
+
if (occurrences.length >= MAX_OCCURRENCES) return;
|
|
192
|
+
|
|
193
|
+
seenFailEls.add(el);
|
|
194
|
+
|
|
195
|
+
const det = details && typeof details === 'object' ? details : { reasonCode: 'UNKNOWN' };
|
|
196
|
+
|
|
197
|
+
const occBase = {
|
|
198
|
+
selector: '',
|
|
199
|
+
html: '',
|
|
200
|
+
summary: '',
|
|
201
|
+
hint: '',
|
|
202
|
+
i18n: {
|
|
203
|
+
summaryKey: 'contrastEnhanced_fail_belowThreshold',
|
|
204
|
+
hintKey: '',
|
|
205
|
+
params: params && typeof params === 'object' ? params : {}
|
|
206
|
+
},
|
|
207
|
+
data: { details: det }
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// Bind the occurrence to an element deterministically, but still let the engine
|
|
211
|
+
// attach canonical selector + HTML snippet via reportOccurrence when available.
|
|
212
|
+
let nodeSelector = '';
|
|
213
|
+
try {
|
|
214
|
+
const elementId =
|
|
215
|
+
el && typeof el.getAttribute === 'function' ? el.getAttribute('id') || '' : '';
|
|
216
|
+
if (elementId) nodeSelector = `#${elementId}`;
|
|
217
|
+
} catch {
|
|
218
|
+
// no-throw
|
|
219
|
+
}
|
|
220
|
+
const tagName = el && el.tagName ? String(el.tagName).toLowerCase() : 'element';
|
|
221
|
+
|
|
222
|
+
let occ = { ...occBase };
|
|
223
|
+
|
|
224
|
+
// IMPORTANT: this is what populates occ.selector and occ.html (snippet)
|
|
225
|
+
if (helpers && typeof helpers.reportOccurrence === 'function') {
|
|
154
226
|
try {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
summary: 'All computable text meets the enhanced (AAA) contrast threshold.',
|
|
158
|
-
hint: '',
|
|
159
|
-
html: '',
|
|
160
|
-
i18n: {
|
|
161
|
-
summaryKey: 'contrastEnhanced_pass_allAboveThreshold',
|
|
162
|
-
hintKey: '',
|
|
163
|
-
params: {
|
|
164
|
-
eligibleTextCount: String(Number(eligibleCount) || 0),
|
|
165
|
-
computableTextCount: String(Number(computableCount) || 0)
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
data: {
|
|
169
|
-
details: {
|
|
170
|
-
reasonCode: 'ALL_ABOVE_THRESHOLD',
|
|
171
|
-
eligibleTextCount: Number(eligibleCount) || 0,
|
|
172
|
-
computableTextCount: Number(computableCount) || 0,
|
|
173
|
-
metrics: {
|
|
174
|
-
eligibleTextCount: Number(eligibleCount) || 0,
|
|
175
|
-
computableTextCount: Number(computableCount) || 0
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
});
|
|
227
|
+
const reported = helpers.reportOccurrence(el, occBase);
|
|
228
|
+
if (reported && typeof reported === 'object') occ = reported;
|
|
180
229
|
} catch {
|
|
181
|
-
|
|
230
|
+
// no-throw
|
|
182
231
|
}
|
|
183
|
-
|
|
232
|
+
}
|
|
184
233
|
|
|
185
|
-
|
|
186
|
-
try {
|
|
187
|
-
if (!el || seenFailEls.has(el)) return;
|
|
188
|
-
if (occurrences.length >= MAX_OCCURRENCES) return;
|
|
189
|
-
|
|
190
|
-
seenFailEls.add(el);
|
|
191
|
-
|
|
192
|
-
const det = details && typeof details === 'object' ? details : { reasonCode: 'UNKNOWN' };
|
|
193
|
-
|
|
194
|
-
const occBase = {
|
|
195
|
-
selector: '',
|
|
196
|
-
html: '',
|
|
197
|
-
summary: '',
|
|
198
|
-
hint: '',
|
|
199
|
-
i18n: {
|
|
200
|
-
summaryKey: 'contrastEnhanced_fail_belowThreshold',
|
|
201
|
-
hintKey: '',
|
|
202
|
-
params: params && typeof params === 'object' ? params : {}
|
|
203
|
-
},
|
|
204
|
-
data: { details: det }
|
|
205
|
-
};
|
|
234
|
+
occ.selector = occ.selector || nodeSelector || '';
|
|
206
235
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
try {
|
|
211
|
-
const elementId = el && typeof el.getAttribute === 'function' ? (el.getAttribute('id') || '') : '';
|
|
212
|
-
if (elementId) nodeSelector = `#${elementId}`;
|
|
213
|
-
} catch {
|
|
214
|
-
// no-throw
|
|
215
|
-
}
|
|
216
|
-
const tagName = el && el.tagName ? String(el.tagName).toLowerCase() : 'element';
|
|
217
|
-
|
|
218
|
-
let occ = { ...occBase };
|
|
219
|
-
|
|
220
|
-
// IMPORTANT: this is what populates occ.selector and occ.html (snippet)
|
|
221
|
-
if (helpers && typeof helpers.reportOccurrence === 'function') {
|
|
222
|
-
try {
|
|
223
|
-
const reported = helpers.reportOccurrence(el, occBase);
|
|
224
|
-
if (reported && typeof reported === 'object') occ = reported;
|
|
225
|
-
} catch {
|
|
226
|
-
// no-throw
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
occ.selector = occ.selector || nodeSelector || '';
|
|
231
|
-
|
|
232
|
-
occ.data = occ.data || {};
|
|
233
|
-
occ.data.details = occ.data.details || {};
|
|
234
|
-
occ.data.details.node = { selector: nodeSelector, tagName };
|
|
236
|
+
occ.data = occ.data || {};
|
|
237
|
+
occ.data.details = occ.data.details || {};
|
|
238
|
+
occ.data.details.node = { selector: nodeSelector, tagName };
|
|
235
239
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
+
occurrences.push(occ);
|
|
241
|
+
} catch {
|
|
242
|
+
// no-throw
|
|
240
243
|
}
|
|
244
|
+
}
|
|
241
245
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
246
|
+
// perf: per-element analysis cache (per run)
|
|
247
|
+
let __elAnalysisCache = new WeakMap();
|
|
248
|
+
if (__contrastSharedCache) {
|
|
249
|
+
try {
|
|
250
|
+
if (!__contrastSharedCache.__elAnalysisCacheAAA)
|
|
251
|
+
__contrastSharedCache.__elAnalysisCacheAAA = new WeakMap();
|
|
252
|
+
__elAnalysisCache = __contrastSharedCache.__elAnalysisCacheAAA;
|
|
253
|
+
} catch {
|
|
254
|
+
__elAnalysisCache = new WeakMap();
|
|
251
255
|
}
|
|
256
|
+
}
|
|
252
257
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
scan = helpers && helpers.contrast && typeof helpers.contrast.getTextScan === 'function'
|
|
258
|
+
// Shared deterministic text scan (computed once per run and reused across contrast checks)
|
|
259
|
+
let scan;
|
|
260
|
+
try {
|
|
261
|
+
scan =
|
|
262
|
+
helpers && helpers.contrast && typeof helpers.contrast.getTextScan === 'function'
|
|
259
263
|
? helpers.contrast.getTextScan(ctx, helpers, engineOptions)
|
|
260
264
|
: null;
|
|
261
|
-
} catch {
|
|
265
|
+
} catch {
|
|
262
266
|
scan = null;
|
|
263
|
-
}
|
|
267
|
+
}
|
|
264
268
|
|
|
265
|
-
// Walk eligible visible text nodes (counted per text node), but compute expensive analysis once per element.
|
|
266
|
-
if (scan && scan.elements && Array.isArray(scan.elements)) {
|
|
269
|
+
// Walk eligible visible text nodes (counted per text node), but compute expensive analysis once per element.
|
|
270
|
+
if (scan && scan.elements && Array.isArray(scan.elements)) {
|
|
267
271
|
try {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
fg = helpers.contrast.computeEffectiveForeground(el);
|
|
309
|
-
fg = fg || { rgba: null, alpha: 0, opacityProduct: 1 };
|
|
310
|
-
if (__elFgCache) __elFgCache.set(el, fg);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
if (!bg || bg.ok === false || !bg.rgba || !fg || !fg.rgba) {
|
|
314
|
-
analysis = { computable: false };
|
|
315
|
-
} else {
|
|
316
|
-
// Compose FG over BG if FG has alpha (effective fg may be < 1 due to opacity chain)
|
|
317
|
-
const fgOpaque = (fg.rgba.a != null && fg.rgba.a < 1)
|
|
318
|
-
? helpers.contrast.compositeRgba(fg.rgba, bg.rgba)
|
|
319
|
-
: { r: fg.rgba.r, g: fg.rgba.g, b: fg.rgba.b, a: 1 };
|
|
320
|
-
|
|
321
|
-
const bgOpaque = { r: bg.rgba.r, g: bg.rgba.g, b: bg.rgba.b, a: 1 };
|
|
322
|
-
|
|
323
|
-
const ratio = helpers.contrast.contrastRatio(fgOpaque, bgOpaque);
|
|
324
|
-
|
|
325
|
-
const font = getFontInfo(el);
|
|
326
|
-
const threshold = helpers.contrast.requiredRatio('AAA', font.isLargeText);
|
|
327
|
-
|
|
328
|
-
analysis = {
|
|
329
|
-
computable: true,
|
|
330
|
-
ratio,
|
|
331
|
-
bgAssumptionsApplied,
|
|
332
|
-
bgAssumedRootCanvasColor,
|
|
333
|
-
ratioStr: helpers.contrast.round2(ratio),
|
|
334
|
-
threshold,
|
|
335
|
-
thresholdStr: `${threshold}`,
|
|
336
|
-
font,
|
|
337
|
-
fgOpaque,
|
|
338
|
-
bgOpaque
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
__elAnalysisCache.set(el, analysis);
|
|
272
|
+
eligibleTextCount = Number(scan.eligibleTextCount) || 0;
|
|
273
|
+
|
|
274
|
+
for (const rec of scan.elements) {
|
|
275
|
+
const el = toElement(rec && rec.el);
|
|
276
|
+
const textCount = rec && Number(rec.textCount) ? Number(rec.textCount) : 0;
|
|
277
|
+
if (!el || textCount <= 0) continue;
|
|
278
|
+
|
|
279
|
+
// Computability + contrast analysis (cached per element)
|
|
280
|
+
let analysis = __elAnalysisCache.get(el);
|
|
281
|
+
if (!analysis) {
|
|
282
|
+
// Computability gate (do NOT emit cantTell here; Rule 1 is responsible for that)
|
|
283
|
+
let blocker = __elBlockerCache ? __elBlockerCache.get(el) : null;
|
|
284
|
+
if (!blocker) {
|
|
285
|
+
blocker = helpers.contrast.getComputabilityBlocker(el);
|
|
286
|
+
blocker = blocker || {
|
|
287
|
+
ok: true,
|
|
288
|
+
reasonCode: null,
|
|
289
|
+
blockerSelector: '',
|
|
290
|
+
blockerProperty: '',
|
|
291
|
+
blockerValue: ''
|
|
292
|
+
};
|
|
293
|
+
if (__elBlockerCache) __elBlockerCache.set(el, blocker);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (blocker && blocker.ok === false) {
|
|
297
|
+
analysis = { computable: false };
|
|
298
|
+
} else {
|
|
299
|
+
let bg = __elBgCache ? __elBgCache.get(el) : null;
|
|
300
|
+
if (!bg) {
|
|
301
|
+
bg = helpers.contrast.computeEffectiveBackground(el, {
|
|
302
|
+
contrast: { mode, rootCanvasFallback },
|
|
303
|
+
collectStack: false
|
|
304
|
+
});
|
|
305
|
+
bg = bg || {
|
|
306
|
+
ok: false,
|
|
307
|
+
reasonCode: 'BACKGROUND_NOT_COMPUTABLE',
|
|
308
|
+
rgba: null,
|
|
309
|
+
alpha: 0
|
|
310
|
+
};
|
|
311
|
+
if (__elBgCache) __elBgCache.set(el, bg);
|
|
343
312
|
}
|
|
344
313
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
const fgHex = (helpers.contrast.rgbToHex)
|
|
361
|
-
? helpers.contrast.rgbToHex(fgOpaque)
|
|
362
|
-
: '';
|
|
363
|
-
|
|
364
|
-
const bgHex = (helpers.contrast.rgbToHex)
|
|
365
|
-
? helpers.contrast.rgbToHex(bgOpaque)
|
|
366
|
-
: '';
|
|
367
|
-
|
|
368
|
-
const fontPxNum = font.fontSizePx ? parseFloat(font.fontSizePx) : NaN;
|
|
369
|
-
|
|
370
|
-
const fontPtStr = (helpers.contrast.pxToPt && Number.isFinite(fontPxNum))
|
|
371
|
-
? helpers.contrast.pxToPt(fontPxNum)
|
|
372
|
-
: '';
|
|
373
|
-
|
|
374
|
-
const fwNum = Number(font.fontWeightNum);
|
|
375
|
-
const fwLabel = (helpers.contrast.fontWeightLabel)
|
|
376
|
-
? helpers.contrast.fontWeightLabel(fwNum)
|
|
377
|
-
: (font.isBold ? 'bold' : 'normal');
|
|
378
|
-
|
|
379
|
-
const fgRgbaStr = helpers.contrast.rgbaToString(fgOpaque);
|
|
380
|
-
const bgRgbaStr = helpers.contrast.rgbaToString(bgOpaque);
|
|
381
|
-
|
|
382
|
-
const params = {
|
|
383
|
-
reasonCode: 'BELOW_THRESHOLD',
|
|
384
|
-
|
|
385
|
-
foreground: fgRgbaStr,
|
|
386
|
-
background: bgRgbaStr,
|
|
387
|
-
|
|
388
|
-
foregroundHex: fgHex,
|
|
389
|
-
backgroundHex: bgHex,
|
|
390
|
-
fontSizePt: fontPtStr,
|
|
391
|
-
fontWeightLabel: fwLabel,
|
|
392
|
-
|
|
393
|
-
ratio: ratioStr,
|
|
394
|
-
threshold: thresholdStr,
|
|
395
|
-
|
|
396
|
-
fontSizePx: font.fontSizePx,
|
|
397
|
-
fontWeight: font.fontWeight,
|
|
398
|
-
isBold: font.isBold,
|
|
399
|
-
isLargeText: font.isLargeText
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
const assumptionsApplied = (analysis && Array.isArray(analysis.bgAssumptionsApplied) && analysis.bgAssumptionsApplied.length)
|
|
403
|
-
? analysis.bgAssumptionsApplied.slice(0)
|
|
404
|
-
: null;
|
|
405
|
-
const assumedRootCanvasColor = (analysis && typeof analysis.bgAssumedRootCanvasColor === 'string')
|
|
406
|
-
? analysis.bgAssumedRootCanvasColor
|
|
407
|
-
: null;
|
|
408
|
-
|
|
409
|
-
const details = {
|
|
410
|
-
reasonCode: 'BELOW_THRESHOLD',
|
|
411
|
-
metrics: { ratio, threshold },
|
|
412
|
-
typography: {
|
|
413
|
-
fontSizePx: Number.isFinite(fontPxNum) ? fontPxNum : null,
|
|
414
|
-
fontSizePt: Number.isFinite(fontPxNum) ? (fontPxNum * 0.75) : null,
|
|
415
|
-
fontWeight: Number.isFinite(fwNum) ? fwNum : null,
|
|
416
|
-
fontWeightLabel: fwLabel,
|
|
417
|
-
isBold: !!font.isBold,
|
|
418
|
-
isLargeText: !!font.isLargeText
|
|
419
|
-
},
|
|
420
|
-
colors: {
|
|
421
|
-
foregroundHex: fgHex,
|
|
422
|
-
backgroundHex: bgHex,
|
|
423
|
-
foregroundRgba: fgRgbaStr,
|
|
424
|
-
backgroundRgba: bgRgbaStr
|
|
425
|
-
},
|
|
426
|
-
assumptionsApplied: assumptionsApplied,
|
|
427
|
-
assumedRootCanvasColor: assumedRootCanvasColor
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
pushFailOccurrence(el, params, details);
|
|
431
|
-
|
|
432
|
-
if (occurrences.length >= MAX_OCCURRENCES) break;
|
|
314
|
+
const bgAssumptionsApplied =
|
|
315
|
+
bg && Array.isArray(bg.assumptionsApplied) && bg.assumptionsApplied.length
|
|
316
|
+
? bg.assumptionsApplied.slice(0)
|
|
317
|
+
: null;
|
|
318
|
+
const bgAssumedRootCanvasColor =
|
|
319
|
+
bg && typeof bg.assumedRootCanvasColor === 'string'
|
|
320
|
+
? bg.assumedRootCanvasColor
|
|
321
|
+
: null;
|
|
322
|
+
|
|
323
|
+
let fg = __elFgCache ? __elFgCache.get(el) : null;
|
|
324
|
+
if (!fg) {
|
|
325
|
+
fg = helpers.contrast.computeEffectiveForeground(el);
|
|
326
|
+
fg = fg || { rgba: null, alpha: 0, opacityProduct: 1 };
|
|
327
|
+
if (__elFgCache) __elFgCache.set(el, fg);
|
|
433
328
|
}
|
|
434
|
-
}
|
|
435
|
-
} catch {
|
|
436
|
-
// No-throw: deterministic cantTell on internal failure
|
|
437
|
-
return {
|
|
438
|
-
ruleId: rule.ruleId,
|
|
439
|
-
outcome: 'cantTell',
|
|
440
|
-
severity: rule.defaultSeverity || 'serious',
|
|
441
|
-
confidence: rule.defaultConfidence || 'high',
|
|
442
|
-
occurrences: [
|
|
443
|
-
{
|
|
444
|
-
selector: '',
|
|
445
|
-
summary: '',
|
|
446
|
-
hint: '',
|
|
447
|
-
html: '',
|
|
448
|
-
i18n: {
|
|
449
|
-
summaryKey: 'contrastEnhanced_cantTell_engineFailure',
|
|
450
|
-
hintKey: '',
|
|
451
|
-
params: { reasonCode: 'ENGINE_EXCEPTION' }
|
|
452
|
-
},
|
|
453
|
-
data: { details: { reasonCode: 'ENGINE_EXCEPTION' } }
|
|
454
|
-
}
|
|
455
|
-
]
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
if (eligibleTextCount === 0) {
|
|
460
|
-
return {
|
|
461
|
-
ruleId: rule.ruleId,
|
|
462
|
-
outcome: 'notApplicable',
|
|
463
|
-
severity: rule.defaultSeverity || 'serious',
|
|
464
|
-
confidence: rule.defaultConfidence || 'high',
|
|
465
|
-
occurrences: []
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
329
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
330
|
+
if (!bg || bg.ok === false || !bg.rgba || !fg || !fg.rgba) {
|
|
331
|
+
analysis = { computable: false };
|
|
332
|
+
} else {
|
|
333
|
+
// Compose FG over BG if FG has alpha (effective fg may be < 1 due to opacity chain)
|
|
334
|
+
const fgOpaque =
|
|
335
|
+
fg.rgba.a != null && fg.rgba.a < 1
|
|
336
|
+
? helpers.contrast.compositeRgba(fg.rgba, bg.rgba)
|
|
337
|
+
: { r: fg.rgba.r, g: fg.rgba.g, b: fg.rgba.b, a: 1 };
|
|
338
|
+
|
|
339
|
+
const bgOpaque = { r: bg.rgba.r, g: bg.rgba.g, b: bg.rgba.b, a: 1 };
|
|
340
|
+
|
|
341
|
+
const ratio = helpers.contrast.contrastRatio(fgOpaque, bgOpaque);
|
|
342
|
+
|
|
343
|
+
const font = getFontInfo(el);
|
|
344
|
+
const threshold = helpers.contrast.requiredRatio('AAA', font.isLargeText);
|
|
345
|
+
|
|
346
|
+
analysis = {
|
|
347
|
+
computable: true,
|
|
348
|
+
ratio,
|
|
349
|
+
bgAssumptionsApplied,
|
|
350
|
+
bgAssumedRootCanvasColor,
|
|
351
|
+
ratioStr: helpers.contrast.round2(ratio),
|
|
352
|
+
threshold,
|
|
353
|
+
thresholdStr: `${threshold}`,
|
|
354
|
+
font,
|
|
355
|
+
fgOpaque,
|
|
356
|
+
bgOpaque
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
__elAnalysisCache.set(el, analysis);
|
|
361
|
+
}
|
|
492
362
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
363
|
+
if (!analysis || analysis.computable !== true) continue;
|
|
364
|
+
|
|
365
|
+
computableTextCount += textCount;
|
|
366
|
+
|
|
367
|
+
const ratio = analysis.ratio;
|
|
368
|
+
const font = analysis.font;
|
|
369
|
+
const threshold = analysis.threshold;
|
|
370
|
+
const ratioStr = analysis.ratioStr;
|
|
371
|
+
const thresholdStr = analysis.thresholdStr;
|
|
372
|
+
const fgOpaque = analysis.fgOpaque;
|
|
373
|
+
const bgOpaque = analysis.bgOpaque;
|
|
374
|
+
|
|
375
|
+
if (!(ratio >= threshold)) {
|
|
376
|
+
failCount += textCount;
|
|
377
|
+
|
|
378
|
+
const fgHex = helpers.contrast.rgbToHex ? helpers.contrast.rgbToHex(fgOpaque) : '';
|
|
379
|
+
|
|
380
|
+
const bgHex = helpers.contrast.rgbToHex ? helpers.contrast.rgbToHex(bgOpaque) : '';
|
|
381
|
+
|
|
382
|
+
const fontPxNum = font.fontSizePx ? parseFloat(font.fontSizePx) : NaN;
|
|
383
|
+
|
|
384
|
+
const fontPtStr =
|
|
385
|
+
helpers.contrast.pxToPt && Number.isFinite(fontPxNum)
|
|
386
|
+
? helpers.contrast.pxToPt(fontPxNum)
|
|
387
|
+
: '';
|
|
388
|
+
|
|
389
|
+
const fwNum = Number(font.fontWeightNum);
|
|
390
|
+
const fwLabel = helpers.contrast.fontWeightLabel
|
|
391
|
+
? helpers.contrast.fontWeightLabel(fwNum)
|
|
392
|
+
: font.isBold
|
|
393
|
+
? 'bold'
|
|
394
|
+
: 'normal';
|
|
395
|
+
|
|
396
|
+
const fgRgbaStr = helpers.contrast.rgbaToString(fgOpaque);
|
|
397
|
+
const bgRgbaStr = helpers.contrast.rgbaToString(bgOpaque);
|
|
398
|
+
|
|
399
|
+
const params = {
|
|
400
|
+
reasonCode: 'BELOW_THRESHOLD',
|
|
401
|
+
|
|
402
|
+
foreground: fgRgbaStr,
|
|
403
|
+
background: bgRgbaStr,
|
|
404
|
+
|
|
405
|
+
foregroundHex: fgHex,
|
|
406
|
+
backgroundHex: bgHex,
|
|
407
|
+
fontSizePt: fontPtStr,
|
|
408
|
+
fontWeightLabel: fwLabel,
|
|
409
|
+
|
|
410
|
+
ratio: ratioStr,
|
|
411
|
+
threshold: thresholdStr,
|
|
412
|
+
|
|
413
|
+
fontSizePx: font.fontSizePx,
|
|
414
|
+
fontWeight: font.fontWeight,
|
|
415
|
+
isBold: font.isBold,
|
|
416
|
+
isLargeText: font.isLargeText
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
const assumptionsApplied =
|
|
420
|
+
analysis &&
|
|
421
|
+
Array.isArray(analysis.bgAssumptionsApplied) &&
|
|
422
|
+
analysis.bgAssumptionsApplied.length
|
|
423
|
+
? analysis.bgAssumptionsApplied.slice(0)
|
|
424
|
+
: null;
|
|
425
|
+
const assumedRootCanvasColor =
|
|
426
|
+
analysis && typeof analysis.bgAssumedRootCanvasColor === 'string'
|
|
427
|
+
? analysis.bgAssumedRootCanvasColor
|
|
428
|
+
: null;
|
|
429
|
+
|
|
430
|
+
const details = {
|
|
431
|
+
reasonCode: 'BELOW_THRESHOLD',
|
|
432
|
+
metrics: { ratio, threshold },
|
|
433
|
+
typography: {
|
|
434
|
+
fontSizePx: Number.isFinite(fontPxNum) ? fontPxNum : null,
|
|
435
|
+
fontSizePt: Number.isFinite(fontPxNum) ? fontPxNum * 0.75 : null,
|
|
436
|
+
fontWeight: Number.isFinite(fwNum) ? fwNum : null,
|
|
437
|
+
fontWeightLabel: fwLabel,
|
|
438
|
+
isBold: !!font.isBold,
|
|
439
|
+
isLargeText: !!font.isLargeText
|
|
440
|
+
},
|
|
441
|
+
colors: {
|
|
442
|
+
foregroundHex: fgHex,
|
|
443
|
+
backgroundHex: bgHex,
|
|
444
|
+
foregroundRgba: fgRgbaStr,
|
|
445
|
+
backgroundRgba: bgRgbaStr
|
|
446
|
+
},
|
|
447
|
+
assumptionsApplied: assumptionsApplied,
|
|
448
|
+
assumedRootCanvasColor: assumedRootCanvasColor
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
pushFailOccurrence(el, params, details);
|
|
452
|
+
|
|
453
|
+
if (occurrences.length >= MAX_OCCURRENCES) break;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
} catch {
|
|
457
|
+
// No-throw: deterministic cantTell on internal failure
|
|
458
|
+
return {
|
|
459
|
+
ruleId: rule.ruleId,
|
|
460
|
+
outcome: 'cantTell',
|
|
461
|
+
severity: rule.defaultSeverity || 'serious',
|
|
462
|
+
confidence: rule.defaultConfidence || 'high',
|
|
463
|
+
occurrences: [
|
|
464
|
+
{
|
|
465
|
+
selector: '',
|
|
466
|
+
summary: '',
|
|
467
|
+
hint: '',
|
|
468
|
+
html: '',
|
|
469
|
+
i18n: {
|
|
470
|
+
summaryKey: 'contrastEnhanced_cantTell_engineFailure',
|
|
471
|
+
hintKey: '',
|
|
472
|
+
params: { reasonCode: 'ENGINE_EXCEPTION' }
|
|
473
|
+
},
|
|
474
|
+
data: { details: { reasonCode: 'ENGINE_EXCEPTION' } }
|
|
475
|
+
}
|
|
476
|
+
]
|
|
477
|
+
};
|
|
501
478
|
}
|
|
479
|
+
}
|
|
480
|
+
if (eligibleTextCount === 0) {
|
|
481
|
+
return {
|
|
482
|
+
ruleId: rule.ruleId,
|
|
483
|
+
outcome: 'notApplicable',
|
|
484
|
+
severity: rule.defaultSeverity || 'serious',
|
|
485
|
+
confidence: rule.defaultConfidence || 'high',
|
|
486
|
+
occurrences: []
|
|
487
|
+
};
|
|
488
|
+
}
|
|
502
489
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
490
|
+
// If eligible text exists but none is computable, stay notApplicable; Rule 1 reports cantTell.
|
|
491
|
+
if (computableTextCount === 0) {
|
|
492
|
+
return {
|
|
493
|
+
ruleId: rule.ruleId,
|
|
494
|
+
outcome: 'notApplicable',
|
|
495
|
+
severity: rule.defaultSeverity || 'serious',
|
|
496
|
+
confidence: rule.defaultConfidence || 'high',
|
|
497
|
+
occurrences: [
|
|
498
|
+
{
|
|
499
|
+
selector: '',
|
|
500
|
+
summary: '',
|
|
501
|
+
hint: '',
|
|
502
|
+
html: '',
|
|
503
|
+
i18n: {
|
|
504
|
+
summaryKey: 'contrastEnhanced_notApplicable_noComputableText',
|
|
505
|
+
hintKey: '',
|
|
506
|
+
params: { eligibleTextCount: String(eligibleTextCount) }
|
|
507
|
+
},
|
|
508
|
+
data: { details: { eligibleTextCount, computableTextCount } }
|
|
509
|
+
}
|
|
510
|
+
]
|
|
511
|
+
};
|
|
512
|
+
}
|
|
507
513
|
|
|
514
|
+
if (failCount > 0) {
|
|
508
515
|
return {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
516
|
+
ruleId: rule.ruleId,
|
|
517
|
+
outcome: 'fail',
|
|
518
|
+
severity: rule.defaultSeverity || 'serious',
|
|
519
|
+
confidence: rule.defaultConfidence || 'high',
|
|
520
|
+
occurrences
|
|
514
521
|
};
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// All computable text passed
|
|
525
|
+
if (!occurrences.length) {
|
|
526
|
+
pushPassOccurrence(eligibleTextCount, computableTextCount);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
return {
|
|
530
|
+
ruleId: rule.ruleId,
|
|
531
|
+
outcome: 'pass',
|
|
532
|
+
severity: rule.defaultSeverity || 'serious',
|
|
533
|
+
confidence: rule.defaultConfidence || 'high',
|
|
534
|
+
occurrences
|
|
535
|
+
};
|
|
515
536
|
}
|
|
516
537
|
|
|
517
|
-
module.exports = { id, meta, runInPage };
|
|
538
|
+
module.exports = { id, meta, runInPage };
|