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