@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,376 +3,396 @@
3
3
  const id = 'contrast-computable';
4
4
 
5
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'
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'
12
34
  },
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
- }
35
+ {
36
+ standard: 'WCAG',
37
+ version: '2.2',
38
+ requirement: '1.4.6',
39
+ title: 'Contrast (Enhanced)',
40
+ conformanceLevel: 'AAA'
52
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
53
  };
54
54
 
55
55
  function runInPage(ctx) {
56
- const {helpers, rule, engineOptions} = ctx;
57
-
58
- const __contrastSharedCache = helpers && helpers.contrast && helpers.contrast.sharedCache ? helpers.contrast.sharedCache : null;
56
+ const { helpers, rule, engineOptions } = ctx;
59
57
 
60
- const contrast = engineOptions && typeof engineOptions.contrast === 'object' && engineOptions.contrast
61
- ? engineOptions.contrast
62
- : {};
58
+ const __contrastSharedCache =
59
+ helpers && helpers.contrast && helpers.contrast.sharedCache
60
+ ? helpers.contrast.sharedCache
61
+ : null;
63
62
 
64
- const mode = contrast.mode === 'auditorAssist' ? 'auditorAssist' : 'strictConformance';
63
+ const contrast =
64
+ engineOptions && typeof engineOptions.contrast === 'object' && engineOptions.contrast
65
+ ? engineOptions.contrast
66
+ : {};
65
67
 
66
- const rootCanvasFallback =
67
- typeof contrast.rootCanvasFallback === 'string' && contrast.rootCanvasFallback.trim()
68
- ? contrast.rootCanvasFallback.trim()
69
- : '#ffffff';
68
+ const mode = contrast.mode === 'auditorAssist' ? 'auditorAssist' : 'strictConformance';
70
69
 
71
- const MAX_OCCURRENCES = 50;
70
+ const rootCanvasFallback =
71
+ typeof contrast.rootCanvasFallback === 'string' && contrast.rootCanvasFallback.trim()
72
+ ? contrast.rootCanvasFallback.trim()
73
+ : '#ffffff';
72
74
 
73
- const occurrences = [];
74
- let eligibleTextCount = 0;
75
- let cantTellCount = 0;
76
- let assumptionsCount = 0;
77
- const assumptionsAppliedSet = new Set();
75
+ const MAX_OCCURRENCES = 50;
78
76
 
79
- const seenFailEls = new Set();
77
+ const occurrences = [];
78
+ let eligibleTextCount = 0;
79
+ let cantTellCount = 0;
80
+ let assumptionsCount = 0;
81
+ const assumptionsAppliedSet = new Set();
80
82
 
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
- }
83
+ const seenFailEls = new Set();
151
84
 
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;
85
+ function pushCantTellOccurrence(el, reasonCode, extraDetails) {
170
86
  try {
171
- scan = helpers && helpers.contrast && typeof helpers.contrast.getTextScan === 'function'
172
- ? helpers.contrast.getTextScan(ctx, helpers, engineOptions)
173
- : null;
87
+ if (!el || seenFailEls.has(el)) return;
88
+ if (occurrences.length >= MAX_OCCURRENCES) return;
89
+ seenFailEls.add(el);
90
+
91
+ const rc = String(reasonCode || 'UNKNOWN');
92
+
93
+ // Match test contract: choose a specific summaryKey per computability blocker.
94
+ // Fall back to the generic notComputable key.
95
+ let summaryKey = 'contrastComputable_cantTell_notComputable';
96
+ if (rc === 'BACKGROUND_IMAGE_OR_GRADIENT') {
97
+ const t =
98
+ extraDetails && typeof extraDetails === 'object'
99
+ ? String(extraDetails.backgroundFillType || '')
100
+ : '';
101
+
102
+ if (t === 'image') summaryKey = 'contrastComputable_cantTell_bgImage';
103
+ else if (t === 'gradient') summaryKey = 'contrastComputable_cantTell_bgGradient';
104
+ else if (t === 'imageAndGradient')
105
+ summaryKey = 'contrastComputable_cantTell_bgImageAndGradient';
106
+ else summaryKey = 'contrastComputable_cantTell_bgImageOrGradient';
107
+ } else if (rc === 'MIX_BLEND_MODE') summaryKey = 'contrastComputable_cantTell_mixBlendMode';
108
+ else if (rc === 'BACKGROUND_FILTER_OR_BACKDROP_FILTER') {
109
+ const bp =
110
+ extraDetails && typeof extraDetails === 'object'
111
+ ? String(extraDetails.blockerProperty || '')
112
+ : '';
113
+ if (bp === 'filter') summaryKey = 'contrastComputable_cantTell_filter';
114
+ else if (bp === 'backdrop-filter')
115
+ summaryKey = 'contrastComputable_cantTell_backdropFilter';
116
+ else summaryKey = 'contrastComputable_cantTell_filterOrBackdropFilter';
117
+ } else if (rc === 'BACKGROUND_NOT_OPAQUE_AT_ROOT')
118
+ summaryKey = 'contrastComputable_cantTell_rootNotOpaque';
119
+
120
+ const details = Object.assign(
121
+ { reasonCode: rc },
122
+ extraDetails && typeof extraDetails === 'object' ? extraDetails : {}
123
+ );
124
+
125
+ const occBase = {
126
+ selector: '',
127
+ html: '',
128
+ summary: '',
129
+ hint: '',
130
+ i18n: {
131
+ summaryKey,
132
+ hintKey: '',
133
+ params: Object.assign(
134
+ { reasonCode: rc },
135
+ details && typeof details === 'object'
136
+ ? {
137
+ blockerProperty: details.blockerProperty ? String(details.blockerProperty) : '',
138
+ blockerValue: details.blockerValue ? String(details.blockerValue) : '',
139
+ backgroundAlpha:
140
+ details.backgroundAlpha !== undefined && details.backgroundAlpha !== null
141
+ ? String(details.backgroundAlpha)
142
+ : ''
143
+ }
144
+ : {}
145
+ )
146
+ },
147
+ data: { details }
148
+ };
149
+
150
+ if (helpers && typeof helpers.reportOccurrence === 'function') {
151
+ occurrences.push(helpers.reportOccurrence(el, occBase));
152
+ } else {
153
+ // Never compute selector/snippet in the rule.
154
+ occurrences.push({ ...occBase });
155
+ }
174
156
  } catch {
175
- scan = null;
157
+ // no-throw
176
158
  }
159
+ }
160
+
161
+ // perf: cache per-element analysis so multiple text nodes in same element don't repeat expensive work
162
+ const __elBlockerCache = __contrastSharedCache
163
+ ? __contrastSharedCache.__elBlockerCache ||
164
+ (__contrastSharedCache.__elBlockerCache = new WeakMap())
165
+ : new WeakMap(); // Element -> { ok:boolean, reasonCode, blockerSelector, blockerProperty, blockerValue }
166
+ const __elBgCache = __contrastSharedCache
167
+ ? __contrastSharedCache.__elBgCache || (__contrastSharedCache.__elBgCache = new WeakMap())
168
+ : new WeakMap(); // Element -> { ok, rgba, alpha, reasonCode } (no stack)
169
+ const __elFgCache = __contrastSharedCache
170
+ ? __contrastSharedCache.__elFgCache || (__contrastSharedCache.__elFgCache = new WeakMap())
171
+ : new WeakMap(); // Element -> { rgba, alpha, opacityProduct }
172
+
173
+ // perf: fast-path memo for self-opaque background (common) to avoid ancestor walk
174
+ const __elBgSelfOpaqueCache = __contrastSharedCache
175
+ ? __contrastSharedCache.__elBgSelfOpaqueCache ||
176
+ (__contrastSharedCache.__elBgSelfOpaqueCache = new WeakMap())
177
+ : new WeakMap(); // Element -> { ok, rgba, alpha, reasonCode }
178
+
179
+ // Shared deterministic text scan (computed once per run and reused across contrast checks)
180
+ let scan;
181
+ try {
182
+ scan =
183
+ helpers && helpers.contrast && typeof helpers.contrast.getTextScan === 'function'
184
+ ? helpers.contrast.getTextScan(ctx, helpers, engineOptions)
185
+ : null;
186
+ } catch {
187
+ scan = null;
188
+ }
189
+
190
+ // Walk eligible visible text nodes (counted per text node), but compute blockers/bg/fg once per element.
191
+ if (scan && scan.elements && Array.isArray(scan.elements)) {
192
+ try {
193
+ eligibleTextCount = Number(scan.eligibleTextCount) || 0;
194
+
195
+ for (const rec of scan.elements) {
196
+ // If we're already capped on occurrences and already know the final outcome is cantTell,
197
+ // stop scanning to avoid wasting time. Deterministic: we don't randomize; we just stop
198
+ // once further work cannot change the output (cantTell + capped occurrences).
199
+ if (cantTellCount > 0 && occurrences.length >= MAX_OCCURRENCES) break;
200
+
201
+ const el = rec && rec.el;
202
+ const textCount = rec && Number(rec.textCount) ? Number(rec.textCount) : 0;
203
+ if (!el || textCount <= 0) continue;
204
+
205
+ // 1) Blockers in ancestor chain (blend/filter/bg-image/gradient)
206
+ let blocker = __elBlockerCache.get(el);
207
+ if (!blocker) {
208
+ blocker = helpers.contrast.getComputabilityBlocker(el);
209
+ // Normalize to stable shape
210
+ blocker = blocker || {
211
+ ok: true,
212
+ reasonCode: null,
213
+ blockerSelector: '',
214
+ blockerProperty: '',
215
+ blockerValue: ''
216
+ };
217
+ __elBlockerCache.set(el, blocker);
218
+ }
219
+ if (blocker && blocker.ok === false) {
220
+ cantTellCount += textCount;
221
+ // occurrence is deduped per element (seenFailEls)
222
+ pushCantTellOccurrence(el, blocker.reasonCode, {
223
+ blockerProperty: blocker.blockerProperty,
224
+ blockerValue: blocker.blockerValue,
225
+ blockerSelector: blocker.blockerSelector,
226
+ backgroundFillType: blocker.backgroundFillType
227
+ });
228
+ continue;
229
+ }
177
230
 
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: ''
231
+ // 2) Background resolution (CSS-only), strict vs. reference-engine-compatible mode
232
+ let bg = __elBgCache.get(el);
233
+ if (!bg) {
234
+ // 2a) Fast-path: if the element itself paints an opaque background-color and opacity is 1,
235
+ // then the background behind its text is computable without walking ancestors.
236
+ // This is a strict subset of the full algorithm, so it is behavior-preserving:
237
+ // if it doesn't match, we fall back to computeEffectiveBackground.
238
+ let bgSelfOpaque = __elBgSelfOpaqueCache.get(el);
239
+ if (bgSelfOpaque === undefined) {
240
+ bgSelfOpaque = null;
241
+ try {
242
+ if (
243
+ helpers &&
244
+ typeof helpers.getComputedStyle === 'function' &&
245
+ helpers.contrast &&
246
+ typeof helpers.contrast.parseCssColorToRgba === 'function'
247
+ ) {
248
+ const cs = helpers.getComputedStyle(el);
249
+ const op = Number.parseFloat(cs && cs.opacity != null ? cs.opacity : '1');
250
+ // Only treat as self-opaque if opacity is exactly 1 (string '1' or number 1)
251
+ // to avoid float/serialization quirks and preserve determinism.
252
+ if (Number.isFinite(op) && op === 1) {
253
+ const c = helpers.contrast.parseCssColorToRgba(cs && cs.backgroundColor);
254
+ if (c && typeof c.a === 'number' && c.a === 1) {
255
+ bgSelfOpaque = {
256
+ ok: true,
257
+ rgba: { r: c.r, g: c.g, b: c.b, a: 1 },
258
+ alpha: 1,
259
+ reasonCode: null
204
260
  };
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);
261
+ }
289
262
  }
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.)
263
+ }
264
+ } catch {
265
+ bgSelfOpaque = null;
301
266
  }
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
- };
267
+ __elBgSelfOpaqueCache.set(el, bgSelfOpaque);
268
+ }
269
+
270
+ if (bgSelfOpaque && bgSelfOpaque.ok === true) {
271
+ bg = bgSelfOpaque;
272
+ } else {
273
+ bg = helpers.contrast.computeEffectiveBackground(el, {
274
+ contrast: { mode, rootCanvasFallback },
275
+ collectStack: false
276
+ });
277
+ bg = bg || { ok: false, reasonCode: 'BACKGROUND_NOT_COMPUTABLE', rgba: null, alpha: 0 };
278
+ }
279
+
280
+ __elBgCache.set(el, bg);
281
+ }
282
+ if (!bg || bg.ok === false) {
283
+ cantTellCount += textCount;
284
+ pushCantTellOccurrence(el, (bg && bg.reasonCode) || 'BACKGROUND_NOT_COMPUTABLE', {
285
+ background: bg && bg.rgba ? helpers.contrast.rgbaToString(bg.rgba) : '',
286
+ backgroundAlpha:
287
+ bg && typeof bg.alpha === 'number' ? helpers.contrast.round2(bg.alpha) : ''
288
+ });
289
+ continue;
324
290
  }
325
- }
326
291
 
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
- }
292
+ // Track any explicit assumptions applied by background resolution.
293
+ try {
294
+ if (bg && Array.isArray(bg.assumptionsApplied) && bg.assumptionsApplied.length) {
295
+ assumptionsCount += textCount;
296
+ for (const a of bg.assumptionsApplied) assumptionsAppliedSet.add(String(a));
297
+ }
298
+ } catch {
299
+ /* no-throw */
300
+ }
336
301
 
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
- }
302
+ // 3) Foreground parsability (computed color should be rgb/rgba)
303
+ let fg = __elFgCache.get(el);
304
+ if (!fg) {
305
+ fg = helpers.contrast.computeEffectiveForeground(el);
306
+ fg = fg || { rgba: null, alpha: 0, opacityProduct: 1 };
307
+ __elFgCache.set(el, fg);
308
+ }
309
+ if (!fg || !fg.rgba) {
310
+ cantTellCount += textCount;
311
+ pushCantTellOccurrence(el, 'FOREGROUND_UNPARSABLE', {
312
+ background: bg && bg.rgba ? helpers.contrast.rgbaToString(bg.rgba) : '',
313
+ backgroundAlpha:
314
+ bg && typeof bg.alpha === 'number' ? helpers.contrast.round2(bg.alpha) : ''
315
+ });
316
+ continue;
317
+ }
346
318
 
347
- // All eligible text is computable
348
- return {
319
+ // If we got here, this element's eligible text is computable.
320
+ // (We intentionally do not compute contrast ratio in this gatekeeper rule.)
321
+ }
322
+ } catch {
323
+ // If scan processing fails unexpectedly, keep determinism: treat as cantTell with one occurrence
324
+ return {
349
325
  ruleId: rule.ruleId,
350
- outcome: 'pass',
326
+ outcome: 'cantTell',
351
327
  severity: rule.defaultSeverity || 'serious',
352
328
  confidence: rule.defaultConfidence || 'high',
353
329
  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
- }
330
+ {
331
+ selector: '',
332
+ summary: '',
333
+ hint: '',
334
+ html: '',
335
+ i18n: {
336
+ summaryKey: 'contrastComputable_cantTell_engineFailure',
337
+ hintKey: '',
338
+ params: { reasonCode: 'ENGINE_EXCEPTION' }
339
+ },
340
+ data: { details: { reasonCode: 'ENGINE_EXCEPTION' } }
341
+ }
374
342
  ]
343
+ };
344
+ }
345
+ }
346
+
347
+ if (eligibleTextCount === 0) {
348
+ return {
349
+ ruleId: rule.ruleId,
350
+ outcome: 'notApplicable',
351
+ severity: rule.defaultSeverity || 'serious',
352
+ confidence: rule.defaultConfidence || 'high',
353
+ occurrences: []
354
+ };
355
+ }
356
+
357
+ if (cantTellCount > 0) {
358
+ return {
359
+ ruleId: rule.ruleId,
360
+ outcome: 'cantTell',
361
+ severity: rule.defaultSeverity || 'serious',
362
+ confidence: rule.defaultConfidence || 'high',
363
+ occurrences
375
364
  };
365
+ }
366
+
367
+ // All eligible text is computable
368
+ return {
369
+ ruleId: rule.ruleId,
370
+ outcome: 'pass',
371
+ severity: rule.defaultSeverity || 'serious',
372
+ confidence: rule.defaultConfidence || 'high',
373
+ occurrences: [
374
+ {
375
+ selector: '',
376
+ summary: '',
377
+ hint: '',
378
+ html: '',
379
+ i18n: {
380
+ summaryKey: 'contrastComputable_pass_allComputable',
381
+ hintKey: '',
382
+ params: {
383
+ eligibleTextCount: String(eligibleTextCount)
384
+ }
385
+ },
386
+ data: {
387
+ details: {
388
+ eligibleTextCount,
389
+ assumptionsCount,
390
+ assumptionsApplied: Array.from(assumptionsAppliedSet).sort()
391
+ }
392
+ }
393
+ }
394
+ ]
395
+ };
376
396
  }
377
397
 
378
- module.exports = {id, meta, runInPage};
398
+ module.exports = { id, meta, runInPage };