@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.
Files changed (164) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/LICENSE +21 -0
  3. package/README.md +145 -0
  4. package/bin/core.js +244 -0
  5. package/docs/BINDING_AUTHORS_GUIDE.md +41 -0
  6. package/docs/CLI.md +49 -0
  7. package/docs/ENGINE_OPTIONS.md +155 -0
  8. package/docs/I18N.md +47 -0
  9. package/docs/INTEGRATION.md +156 -0
  10. package/docs/LIMITATIONS.md +31 -0
  11. package/docs/OUTPUT_SCHEMA.md +237 -0
  12. package/docs/POLICY.md +71 -0
  13. package/docs/RULE_AUTHORING.md +375 -0
  14. package/docs/RULE_CATALOG.md +180 -0
  15. package/docs/RULE_TAXONOMY.md +145 -0
  16. package/docs/TROUBLESHOOTING.md +48 -0
  17. package/docs/WCAG_CONFORMANCE.md +49 -0
  18. package/package.json +60 -0
  19. package/src/catalogs/composites.wcag.js +490 -0
  20. package/src/checks/automatic/area-alt-present.js +225 -0
  21. package/src/checks/automatic/aria-allowed-attr.js +206 -0
  22. package/src/checks/automatic/aria-allowed-role.js +102 -0
  23. package/src/checks/automatic/aria-braille-equivalent.js +139 -0
  24. package/src/checks/automatic/aria-conditional-attr.js +110 -0
  25. package/src/checks/automatic/aria-deprecated-role.js +106 -0
  26. package/src/checks/automatic/aria-hidden-body.js +87 -0
  27. package/src/checks/automatic/aria-hidden-focus.js +480 -0
  28. package/src/checks/automatic/aria-prohibited-attr.js +156 -0
  29. package/src/checks/automatic/aria-prohibited-children.js +265 -0
  30. package/src/checks/automatic/aria-required-attr.js +154 -0
  31. package/src/checks/automatic/aria-required-children.js +274 -0
  32. package/src/checks/automatic/aria-required-parent.js +222 -0
  33. package/src/checks/automatic/aria-role-name-present.js +201 -0
  34. package/src/checks/automatic/aria-roles-valid.js +110 -0
  35. package/src/checks/automatic/aria-valid-attr-value.js +123 -0
  36. package/src/checks/automatic/aria-valid-attr.js +109 -0
  37. package/src/checks/automatic/autocomplete-valid.js +134 -0
  38. package/src/checks/automatic/avoid-inline-spacing.js +107 -0
  39. package/src/checks/automatic/binary-control-name-present.js +294 -0
  40. package/src/checks/automatic/button-name-present.js +146 -0
  41. package/src/checks/automatic/bypass-blocks-present.js +162 -0
  42. package/src/checks/automatic/canvas-text-alternative-present.js +140 -0
  43. package/src/checks/automatic/combobox-name-present.js +267 -0
  44. package/src/checks/automatic/contrast-computable.js +378 -0
  45. package/src/checks/automatic/contrast-enhanced.js +517 -0
  46. package/src/checks/automatic/contrast-minimum.js +512 -0
  47. package/src/checks/automatic/css-orientation-lock.js +206 -0
  48. package/src/checks/automatic/definition-list-children-valid.js +148 -0
  49. package/src/checks/automatic/deprecated-elements-not-used.js +91 -0
  50. package/src/checks/automatic/dialog-name-present.js +209 -0
  51. package/src/checks/automatic/dlitem-parent-valid.js +100 -0
  52. package/src/checks/automatic/duplicate-id-aria.js +126 -0
  53. package/src/checks/automatic/embed-text-alternative-present.js +190 -0
  54. package/src/checks/automatic/form-control-programmatic-label-present.js +409 -0
  55. package/src/checks/automatic/form-control-single-label.js +117 -0
  56. package/src/checks/automatic/html-xml-lang-mismatch.js +91 -0
  57. package/src/checks/automatic/iframe-focusable-content.js +141 -0
  58. package/src/checks/automatic/iframe-name-present.js +102 -0
  59. package/src/checks/automatic/iframe-title-unique.js +107 -0
  60. package/src/checks/automatic/img-alt-present.js +223 -0
  61. package/src/checks/automatic/input-image-alt-present.js +155 -0
  62. package/src/checks/automatic/label-in-name.js +326 -0
  63. package/src/checks/automatic/language-page-present.js +159 -0
  64. package/src/checks/automatic/link-in-text-block.js +218 -0
  65. package/src/checks/automatic/link-name-present.js +114 -0
  66. package/src/checks/automatic/list-children-valid.js +152 -0
  67. package/src/checks/automatic/listbox-name-present.js +236 -0
  68. package/src/checks/automatic/listitem-parent-valid.js +118 -0
  69. package/src/checks/automatic/menuitem-name-present.js +201 -0
  70. package/src/checks/automatic/meta-refresh-no-exceptions.js +105 -0
  71. package/src/checks/automatic/meta-refresh-timing-absent.js +107 -0
  72. package/src/checks/automatic/meta-viewport-zoom-enabled.js +118 -0
  73. package/src/checks/automatic/meter-name-present.js +160 -0
  74. package/src/checks/automatic/nested-interactive-controls-absent.js +135 -0
  75. package/src/checks/automatic/object-text-alternative-present.js +193 -0
  76. package/src/checks/automatic/option-name-present.js +157 -0
  77. package/src/checks/automatic/page-title-present.js +86 -0
  78. package/src/checks/automatic/progressbar-name-present.js +165 -0
  79. package/src/checks/automatic/role-img-alt-present.js +206 -0
  80. package/src/checks/automatic/searchbox-name-present.js +236 -0
  81. package/src/checks/automatic/server-side-image-map-absent.js +88 -0
  82. package/src/checks/automatic/slider-name-present.js +276 -0
  83. package/src/checks/automatic/spinbutton-name-present.js +236 -0
  84. package/src/checks/automatic/summary-name-present.js +153 -0
  85. package/src/checks/automatic/svg-image-text-alternative-present.js +220 -0
  86. package/src/checks/automatic/svg-text-alternative-present.js +298 -0
  87. package/src/checks/automatic/tab-name-present.js +200 -0
  88. package/src/checks/automatic/table-headers-attr-valid.js +122 -0
  89. package/src/checks/automatic/table-th-has-data-cells.js +117 -0
  90. package/src/checks/automatic/target-size-minimum.js +605 -0
  91. package/src/checks/automatic/td-has-header.js +151 -0
  92. package/src/checks/automatic/textbox-name-present.js +236 -0
  93. package/src/checks/automatic/tooltip-name-present.js +158 -0
  94. package/src/checks/automatic/treeitem-name-present.js +157 -0
  95. package/src/checks/automatic/valid-lang.js +100 -0
  96. package/src/checks/automatic/video-poster-text-alternative-present.js +193 -0
  97. package/src/checks/manual/accesskeys-manual.js +93 -0
  98. package/src/checks/manual/area-alt-decorative-manual.js +247 -0
  99. package/src/checks/manual/area-alt-quality-manual.js +204 -0
  100. package/src/checks/manual/aria-checked-state-mismatch-manual.js +141 -0
  101. package/src/checks/manual/aria-text-manual.js +109 -0
  102. package/src/checks/manual/canvas-text-alternative-quality-manual.js +170 -0
  103. package/src/checks/manual/css-hidden-focus.js +259 -0
  104. package/src/checks/manual/embed-text-alternative-quality-manual.js +204 -0
  105. package/src/checks/manual/empty-heading-manual.js +182 -0
  106. package/src/checks/manual/empty-table-header-manual.js +163 -0
  107. package/src/checks/manual/focus-order-semantics-manual.js +117 -0
  108. package/src/checks/manual/form-control-programmatic-label-quality-manual.js +291 -0
  109. package/src/checks/manual/heading-order-manual.js +130 -0
  110. package/src/checks/manual/identical-links-same-purpose-manual.js +142 -0
  111. package/src/checks/manual/image-redundant-alt-manual.js +118 -0
  112. package/src/checks/manual/img-alt-decorative-manual.js +148 -0
  113. package/src/checks/manual/img-alt-quality-manual.js +182 -0
  114. package/src/checks/manual/input-image-alt-decorative-manual.js +144 -0
  115. package/src/checks/manual/input-image-alt-quality-manual.js +144 -0
  116. package/src/checks/manual/label-title-only-manual.js +115 -0
  117. package/src/checks/manual/landmark-banner-is-top-level-manual.js +180 -0
  118. package/src/checks/manual/landmark-contentinfo-is-top-level-manual.js +169 -0
  119. package/src/checks/manual/landmark-main-is-top-level-manual.js +167 -0
  120. package/src/checks/manual/landmark-no-duplicate-banner-manual.js +177 -0
  121. package/src/checks/manual/landmark-no-duplicate-contentinfo-manual.js +169 -0
  122. package/src/checks/manual/landmark-no-duplicate-main-manual.js +132 -0
  123. package/src/checks/manual/landmark-one-main-manual.js +151 -0
  124. package/src/checks/manual/landmark-unique-manual.js +252 -0
  125. package/src/checks/manual/link-name-quality-manual.js +143 -0
  126. package/src/checks/manual/media-transcript-present-manual.js +373 -0
  127. package/src/checks/manual/meta-viewport-large-manual.js +119 -0
  128. package/src/checks/manual/mouse-only-event-handlers-manual.js +134 -0
  129. package/src/checks/manual/no-autoplay-audio-manual.js +116 -0
  130. package/src/checks/manual/object-text-alternative-quality-manual.js +194 -0
  131. package/src/checks/manual/p-as-heading-manual.js +163 -0
  132. package/src/checks/manual/page-has-heading-one-manual.js +110 -0
  133. package/src/checks/manual/page-title-patterns-manual.js +262 -0
  134. package/src/checks/manual/presentation-role-conflict-manual.js +159 -0
  135. package/src/checks/manual/region-manual.js +183 -0
  136. package/src/checks/manual/scope-attr-valid-manual.js +93 -0
  137. package/src/checks/manual/scrollable-region-focusable-manual.js +168 -0
  138. package/src/checks/manual/skip-link-manual.js +150 -0
  139. package/src/checks/manual/svg-text-alternative-quality-manual.js +209 -0
  140. package/src/checks/manual/tabindex-manual.js +94 -0
  141. package/src/checks/manual/table-duplicate-name-manual.js +99 -0
  142. package/src/checks/manual/table-fake-caption-manual.js +122 -0
  143. package/src/checks/manual/video-caption-manual.js +118 -0
  144. package/src/checks/manual-review.js +95 -0
  145. package/src/checks/rules-and-tags.full.csv +19 -0
  146. package/src/checks/rules-and-tags.full.json +259 -0
  147. package/src/core/aria-helpers.js +906 -0
  148. package/src/core/contrast-helpers.js +1147 -0
  149. package/src/core/dom-helpers.js +4085 -0
  150. package/src/core/dom-runner.js +627 -0
  151. package/src/core/frame-messaging.js +210 -0
  152. package/src/core/frame-scan.js +178 -0
  153. package/src/core/rollup-composites.js +135 -0
  154. package/src/core/rule-meta.js +140 -0
  155. package/src/core.js +79055 -0
  156. package/src/coverage/wcag-facets.js +1079 -0
  157. package/src/coverage/wcag-version-map.js +84 -0
  158. package/src/i18n/en.js +919 -0
  159. package/src/i18n/fr.js +527 -0
  160. package/src/index.js +4 -0
  161. package/src/policy/contracts.js +18 -0
  162. package/src/policy/resolvePolicy.js +55 -0
  163. package/src/policy/schemas/engine-options.schema.json +103 -0
  164. 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};