@surea11y/core 1.4.1 → 1.6.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 (151) hide show
  1. package/CHANGELOG.md +212 -128
  2. package/README.md +46 -9
  3. package/docs/ACT_RULE_MAPPING.md +243 -0
  4. package/docs/API_STABILITY.md +4 -4
  5. package/docs/BINDING_AUTHORS_GUIDE.md +3 -3
  6. package/docs/DESIGN_CHALLENGES.md +301 -0
  7. package/docs/ENGINE_OPTIONS.md +30 -14
  8. package/docs/I18N.md +176 -20
  9. package/docs/INTEGRATION.md +29 -7
  10. package/docs/LIMITATIONS.md +6 -4
  11. package/docs/OUTPUT_SCHEMA.md +13 -3
  12. package/docs/REPORT.md +3 -1
  13. package/docs/RULE_AUTHORING.md +104 -23
  14. package/docs/RULE_CATALOG.md +1878 -169
  15. package/docs/RULE_TAXONOMY.md +2 -2
  16. package/docs/TROUBLESHOOTING.md +4 -4
  17. package/docs/WCAG_CONFORMANCE.md +25 -9
  18. package/package.json +8 -7
  19. package/src/baseline.js +3 -3
  20. package/src/checks/automatic/area-alt-present.js +2 -2
  21. package/src/checks/automatic/aria-allowed-attr.js +95 -40
  22. package/src/checks/automatic/aria-allowed-role.js +16 -18
  23. package/src/checks/automatic/aria-braille-equivalent.js +19 -21
  24. package/src/checks/automatic/aria-conditional-attr.js +22 -24
  25. package/src/checks/automatic/aria-deprecated-role.js +63 -50
  26. package/src/checks/automatic/aria-hidden-body.js +4 -11
  27. package/src/checks/automatic/aria-hidden-focus.js +104 -23
  28. package/src/checks/automatic/aria-prohibited-attr.js +71 -72
  29. package/src/checks/automatic/aria-prohibited-children.js +154 -61
  30. package/src/checks/automatic/aria-required-attr.js +74 -29
  31. package/src/checks/automatic/aria-required-children.js +38 -34
  32. package/src/checks/automatic/aria-required-parent.js +78 -29
  33. package/src/checks/automatic/aria-role-name-present.js +36 -22
  34. package/src/checks/automatic/aria-roles-valid.js +37 -23
  35. package/src/checks/automatic/aria-valid-attr-value.js +33 -33
  36. package/src/checks/automatic/aria-valid-attr.js +15 -18
  37. package/src/checks/automatic/autocomplete-valid.js +17 -19
  38. package/src/checks/automatic/avoid-inline-spacing.js +14 -16
  39. package/src/checks/automatic/binary-control-name-present.js +46 -26
  40. package/src/checks/automatic/button-name-present.js +115 -34
  41. package/src/checks/automatic/combobox-name-present.js +40 -22
  42. package/src/checks/automatic/contrast-computable.js +32 -0
  43. package/src/checks/automatic/contrast-enhanced.js +21 -1
  44. package/src/checks/automatic/contrast-minimum.js +21 -1
  45. package/src/checks/automatic/css-orientation-lock.js +118 -41
  46. package/src/checks/automatic/definition-list-children-valid.js +25 -29
  47. package/src/checks/automatic/deprecated-elements-not-used.js +15 -17
  48. package/src/checks/automatic/dialog-name-present.js +36 -20
  49. package/src/checks/automatic/dlitem-parent-valid.js +15 -17
  50. package/src/checks/automatic/duplicate-id-aria.js +50 -40
  51. package/src/checks/automatic/duplicate-id.js +198 -0
  52. package/src/checks/automatic/embed-text-alternative-present.js +2 -2
  53. package/src/checks/automatic/form-control-programmatic-label-present.js +19 -2
  54. package/src/checks/automatic/form-control-single-label.js +39 -41
  55. package/src/checks/automatic/html-xml-lang-mismatch.js +2 -9
  56. package/src/checks/automatic/iframe-focusable-content.js +92 -38
  57. package/src/checks/automatic/iframe-name-present.js +53 -21
  58. package/src/checks/automatic/iframe-title-unique.js +19 -24
  59. package/src/checks/automatic/img-alt-present.js +12 -4
  60. package/src/checks/automatic/label-in-name.js +198 -49
  61. package/src/checks/automatic/link-in-text-block.js +29 -31
  62. package/src/checks/automatic/link-name-present.js +47 -31
  63. package/src/checks/automatic/list-children-valid.js +21 -23
  64. package/src/checks/automatic/listbox-name-present.js +42 -24
  65. package/src/checks/automatic/listitem-parent-valid.js +18 -21
  66. package/src/checks/automatic/menuitem-name-present.js +36 -20
  67. package/src/checks/automatic/meta-refresh-no-exceptions.js +39 -31
  68. package/src/checks/automatic/meta-refresh-timing-absent.js +29 -25
  69. package/src/checks/automatic/meta-viewport-zoom-enabled.js +14 -17
  70. package/src/checks/automatic/meter-name-present.js +38 -21
  71. package/src/checks/automatic/nested-interactive-controls-absent.js +22 -24
  72. package/src/checks/automatic/option-name-present.js +39 -22
  73. package/src/checks/automatic/page-title-present.js +21 -3
  74. package/src/checks/automatic/presentational-children-focusable-absent.js +330 -0
  75. package/src/checks/automatic/progressbar-name-present.js +41 -24
  76. package/src/checks/automatic/role-img-alt-present.js +64 -16
  77. package/src/checks/automatic/searchbox-name-present.js +46 -24
  78. package/src/checks/automatic/server-side-image-map-absent.js +16 -19
  79. package/src/checks/automatic/slider-name-present.js +42 -23
  80. package/src/checks/automatic/spinbutton-name-present.js +46 -24
  81. package/src/checks/automatic/summary-name-present.js +34 -20
  82. package/src/checks/automatic/svg-image-text-alternative-present.js +1 -1
  83. package/src/checks/automatic/svg-text-alternative-present.js +13 -10
  84. package/src/checks/automatic/tab-name-present.js +37 -20
  85. package/src/checks/automatic/table-headers-attr-valid.js +57 -24
  86. package/src/checks/automatic/table-th-has-data-cells.js +76 -24
  87. package/src/checks/automatic/target-size-minimum.js +172 -131
  88. package/src/checks/automatic/td-has-header.js +20 -25
  89. package/src/checks/automatic/textbox-name-present.js +42 -24
  90. package/src/checks/automatic/tooltip-name-present.js +37 -20
  91. package/src/checks/automatic/treeitem-name-present.js +39 -22
  92. package/src/checks/automatic/valid-lang.js +107 -24
  93. package/src/checks/automatic/video-poster-text-alternative-present.js +1 -1
  94. package/src/checks/manual/accesskeys-manual.js +21 -22
  95. package/src/checks/manual/area-alt-decorative-manual.js +7 -0
  96. package/src/checks/manual/area-alt-quality-manual.js +6 -0
  97. package/src/checks/manual/aria-checked-state-mismatch-manual.js +23 -26
  98. package/src/checks/manual/aria-text-manual.js +4 -4
  99. package/src/checks/manual/bypass-blocks-present-manual.js +48 -38
  100. package/src/checks/manual/canvas-text-alternative-quality-manual.js +8 -0
  101. package/src/checks/manual/css-focus-indicator-suppressed-manual.js +444 -0
  102. package/src/checks/manual/embed-text-alternative-quality-manual.js +8 -0
  103. package/src/checks/manual/empty-heading-manual.js +73 -28
  104. package/src/checks/manual/empty-table-header-manual.js +33 -36
  105. package/src/checks/manual/focus-order-semantics-manual.js +15 -15
  106. package/src/checks/manual/form-control-label-quality-manual.js +453 -0
  107. package/src/checks/manual/form-control-programmatic-label-quality-manual.js +4 -11
  108. package/src/checks/manual/heading-order-manual.js +20 -25
  109. package/src/checks/manual/heading-quality-manual.js +338 -0
  110. package/src/checks/manual/identical-links-same-purpose-manual.js +73 -12
  111. package/src/checks/manual/image-redundant-alt-manual.js +18 -21
  112. package/src/checks/manual/img-alt-decorative-manual.js +211 -52
  113. package/src/checks/manual/img-alt-quality-manual.js +7 -0
  114. package/src/checks/manual/input-image-alt-decorative-manual.js +8 -0
  115. package/src/checks/manual/input-image-alt-quality-manual.js +5 -0
  116. package/src/checks/manual/label-title-only-manual.js +19 -21
  117. package/src/checks/manual/landmark-banner-is-top-level-manual.js +21 -24
  118. package/src/checks/manual/landmark-contentinfo-is-top-level-manual.js +23 -26
  119. package/src/checks/manual/landmark-main-is-top-level-manual.js +20 -23
  120. package/src/checks/manual/landmark-no-duplicate-banner-manual.js +8 -13
  121. package/src/checks/manual/landmark-no-duplicate-contentinfo-manual.js +8 -13
  122. package/src/checks/manual/landmark-no-duplicate-main-manual.js +4 -9
  123. package/src/checks/manual/landmark-one-main-manual.js +8 -15
  124. package/src/checks/manual/landmark-unique-manual.js +31 -36
  125. package/src/checks/manual/link-name-quality-manual.js +162 -35
  126. package/src/checks/manual/media-transcript-present-manual.js +2 -3
  127. package/src/checks/manual/meta-viewport-large-manual.js +16 -19
  128. package/src/checks/manual/mouse-only-event-handlers-manual.js +26 -28
  129. package/src/checks/manual/no-autoplay-audio-manual.js +3 -3
  130. package/src/checks/manual/object-text-alternative-quality-manual.js +8 -0
  131. package/src/checks/manual/p-as-heading-manual.js +4 -4
  132. package/src/checks/manual/page-has-heading-one-manual.js +8 -15
  133. package/src/checks/manual/page-title-patterns-manual.js +26 -3
  134. package/src/checks/manual/presentation-role-conflict-manual.js +74 -46
  135. package/src/checks/manual/region-manual.js +32 -25
  136. package/src/checks/manual/scope-attr-valid-manual.js +16 -19
  137. package/src/checks/manual/scrollable-region-focusable-manual.js +7 -7
  138. package/src/checks/manual/skip-link-manual.js +44 -52
  139. package/src/checks/manual/svg-text-alternative-quality-manual.js +9 -0
  140. package/src/checks/manual/tabindex-manual.js +16 -19
  141. package/src/checks/manual/table-duplicate-name-manual.js +16 -19
  142. package/src/checks/manual/table-fake-caption-manual.js +2 -2
  143. package/src/checks/manual/video-caption-manual.js +3 -3
  144. package/src/checks/manual-review.js +17 -1
  145. package/src/core.js +13086 -5169
  146. package/src/report.js +16 -2
  147. package/surea11y.browser.js +5665 -4219
  148. package/surea11y.i18n.de.js +22 -0
  149. package/surea11y.i18n.es.js +22 -0
  150. package/surea11y.i18n.fr.js +22 -0
  151. package/bin/surea11y-core.js +0 -20
@@ -0,0 +1,198 @@
1
+ /* SPDX-License-Identifier: MPL-2.0 */
2
+
3
+ 'use strict';
4
+
5
+ /**
6
+ * @check duplicate-id
7
+ * @atomic true
8
+ * @summary Every id value must be unique within its own tree
9
+ * @standard WCAG 2.1
10
+ * @sc 4.1.1
11
+ * @applicability
12
+ * Applies to any element carrying a non-empty id attribute. Visibility
13
+ * is irrelevant. A duplicate id breaks the same lookups whether the
14
+ * element renders or not, which is why ACT 3ea0c8 evaluates hidden
15
+ * elements too.
16
+ * @expectation
17
+ * No other element in the same tree carries the same id value. Ids are
18
+ * scoped per document tree and per shadow tree, so the same id inside
19
+ * two different shadow roots is not a duplicate.
20
+ * @implementation-notes
21
+ * - WCAG-VERSION SCOPED. SC 4.1.1 Parsing was removed in WCAG 2.2, so this
22
+ * rule is tagged `wcag2a` (its 2.0/2.1 origin) plus `wcag22-removed`. A
23
+ * consumer targeting WCAG 2.2 excludes it with
24
+ * `excludeTags: ['wcag22-removed']`; one targeting 2.0 or 2.1 keeps it
25
+ * and gets a real 4.1.1 result. The alternative, dropping the SC
26
+ * mapping entirely, would have made a genuine 2.0/2.1 failure
27
+ * invisible to anyone conformance-testing against those versions. See
28
+ * `docs/ENGINE_OPTIONS.md` for the tag, and `docs/DESIGN_CHALLENGES.md`
29
+ * for the decision this reverses.
30
+ * - The defect outlives its Success Criterion: a duplicate id breaks
31
+ * `<label for>` association, fragment navigation, `getElementById`, and
32
+ * every ID-reference attribute, none of which stopped mattering when
33
+ * 4.1.1 was retired. The SC was removed because browsers recover from
34
+ * malformed markup, not because ids became free-form.
35
+ * - Scoping is per ROOT NODE, not per document: `getRootNode()` groups
36
+ * light DOM against the document and each shadow tree against itself,
37
+ * matching the DOM's own id-lookup scope. Two components that each use
38
+ * `id="title"` inside their own shadow root are correct markup and are
39
+ * not reported.
40
+ * - Overlaps `duplicate-id-aria` by design, and the two say different
41
+ * things. That rule reports a duplicate id that an ARIA attribute
42
+ * actually references, as a `cantTell` under 4.1.2, the reference
43
+ * resolves to the first match, so whether the right element was named is
44
+ * an authoring question. This one is the flat structural fact under
45
+ * 4.1.1, for every id, referenced or not.
46
+ * - Detection is document-wide while reporting follows the scanned scope,
47
+ * the same split `duplicate-id-aria` uses: a `contextSelector` narrows
48
+ * which duplicates get reported, never which ones count as duplicates.
49
+ */
50
+
51
+ const id = 'duplicate-id';
52
+
53
+ const meta = {
54
+ title: 'IDs must be unique',
55
+ description:
56
+ 'Checks that every non-empty id attribute value is unique within its own document or shadow tree (WCAG 2.0/2.1 SC 4.1.1, removed in WCAG 2.2).',
57
+ i18n: {
58
+ titleKey: 'duplicateId_title',
59
+ descriptionKey: 'duplicateId_description'
60
+ },
61
+ helpUrl: null,
62
+ tags: ['wcag2a', 'wcag411', 'wcag22-removed', 'structure', 'atomic', 'automatic'],
63
+ wcagSc: ['4.1.1'],
64
+ normativeMappings: [
65
+ {
66
+ standard: 'WCAG',
67
+ version: '2.1',
68
+ requirement: '4.1.1',
69
+ title: 'Parsing',
70
+ conformanceLevel: 'A'
71
+ }
72
+ ],
73
+ defaultSeverity: 'moderate',
74
+ category: 'robust',
75
+ type: 'automatic',
76
+ defaultConfidence: 'high',
77
+ coverage: { facetsBySc: { '4.1.1': ['id-unique-page-wide'] } }
78
+ };
79
+
80
+ function runInPage(ctx) {
81
+ const { document, helpers, rule } = ctx;
82
+
83
+ // Detection spans the whole document; see the header comment on scope.
84
+ const all = new Set();
85
+ try {
86
+ const nodes = document.querySelectorAll ? document.querySelectorAll('[id]') : [];
87
+ for (const el of nodes) all.add(el);
88
+ } catch {
89
+ // no-throw: fall through to the helper-provided set below
90
+ }
91
+
92
+ const queryAllSmart =
93
+ helpers && typeof helpers.queryAllSmart === 'function' ? helpers.queryAllSmart : null;
94
+
95
+ // queryAllSmart reaches into open shadow roots when includeShadowDom is on,
96
+ // which document.querySelectorAll never does.
97
+ let inScope = null;
98
+ if (queryAllSmart) {
99
+ try {
100
+ const scoped = queryAllSmart('[id]');
101
+ const list = Array.isArray(scoped) ? scoped : Array.from(scoped || []);
102
+ inScope = new Set(list);
103
+ for (const el of list) all.add(el);
104
+ } catch {
105
+ inScope = null;
106
+ }
107
+ }
108
+
109
+ // Ids resolve within their own tree, so group by root before comparing.
110
+ function rootOf(el) {
111
+ try {
112
+ if (typeof el.getRootNode === 'function') return el.getRootNode();
113
+ } catch {
114
+ // fall through
115
+ }
116
+ return document;
117
+ }
118
+
119
+ const byRootAndId = new Map(); // root -> Map(idValue -> element[])
120
+ let applicableCount = 0;
121
+
122
+ for (const el of all) {
123
+ if (!el || el.nodeType !== 1 || !el.getAttribute) continue;
124
+ const value = String(el.getAttribute('id') || '').trim();
125
+ if (!value) continue;
126
+
127
+ applicableCount += 1;
128
+
129
+ const root = rootOf(el);
130
+ let idMap = byRootAndId.get(root);
131
+ if (!idMap) {
132
+ idMap = new Map();
133
+ byRootAndId.set(root, idMap);
134
+ }
135
+ const bucket = idMap.get(value);
136
+ if (bucket) bucket.push(el);
137
+ else idMap.set(value, [el]);
138
+ }
139
+
140
+ if (applicableCount === 0) {
141
+ return { ruleId: rule.ruleId, outcome: 'notApplicable', severity: 'minor', occurrences: [] };
142
+ }
143
+
144
+ const occurrences = [];
145
+
146
+ for (const idMap of byRootAndId.values()) {
147
+ for (const [value, els] of idMap) {
148
+ if (els.length <= 1) continue;
149
+
150
+ for (const el of els) {
151
+ if (inScope && !inScope.has(el)) continue;
152
+
153
+ const eligInfo = helpers.getEligibilityInfo
154
+ ? (() => {
155
+ try {
156
+ return helpers.getEligibilityInfo(el, ctx, { targetSet: 'dom' });
157
+ } catch {
158
+ return null;
159
+ }
160
+ })()
161
+ : null;
162
+
163
+ occurrences.push(
164
+ helpers.reportOccurrence(el, {
165
+ summary: `The id "${value}" is used on ${els.length} elements in the same tree.`,
166
+ hint: 'Give each element its own id. A duplicate breaks <label for>, fragment links, getElementById and every ID-reference attribute, all of which resolve to the first match only.',
167
+ i18n: {
168
+ summaryKey: 'duplicateId_summary_fail',
169
+ hintKey: 'duplicateId_hint_fail',
170
+ params: { id: value, count: String(els.length) }
171
+ },
172
+ data: {
173
+ details: {
174
+ reasonCode: 'DUPLICATE_ID',
175
+ id: value,
176
+ count: els.length
177
+ },
178
+ visibilityFilter: eligInfo || { targetSet: 'dom', accEligible: null, reasons: [] }
179
+ }
180
+ })
181
+ );
182
+ }
183
+ }
184
+ }
185
+
186
+ if (occurrences.length) {
187
+ return {
188
+ ruleId: rule.ruleId,
189
+ outcome: 'fail',
190
+ severity: rule.defaultSeverity || 'moderate',
191
+ occurrences
192
+ };
193
+ }
194
+
195
+ return { ruleId: rule.ruleId, outcome: 'pass', severity: 'minor', occurrences: [] };
196
+ }
197
+
198
+ module.exports = { id, meta, runInPage };
@@ -135,8 +135,8 @@ function runInPage(ctx) {
135
135
  }
136
136
 
137
137
  // `title` is a weaker text-alternative mechanism than aria-label/
138
- // aria-labelledby — it is not reliably exposed to assistive technology
139
- // in every context (e.g. touch/mobile) — so a pass achieved only via
138
+ // aria-labelledby, it is not reliably exposed to assistive technology
139
+ // in every context (e.g. touch/mobile), so a pass achieved only via
140
140
  // `title` is reported at reduced confidence rather than the rule's
141
141
  // default `high`.
142
142
  let anyPassedViaWeakMechanism = false;
@@ -13,12 +13,29 @@
13
13
  *
14
14
  * WCAG mapping: matches technique H44 ("Using label elements to associate
15
15
  * text labels with form controls"), which WCAG's own Techniques document
16
- * lists as sufficient for 1.3.1, 3.3.2, AND 4.1.2 simultaneously — a label
16
+ * lists as sufficient for 1.3.1, 3.3.2, AND 4.1.2 simultaneously. A label
17
17
  * that programmatically associates with a control conveys the
18
18
  * relationship (1.3.1), provides the instruction (3.3.2), and exposes the
19
19
  * accessible name (4.1.2) all at once. This rule was originally only wired
20
20
  * to 4.1.2, even though its own `tags` already listed wcag131/wcag332 and
21
21
  * wcag-facets.js already had matching facet ids under those SCs.
22
+ *
23
+ * @applicability
24
+ * Applies to <input>, <select> and <textarea> elements included in the
25
+ * accessibility tree, excluding the input types hidden, submit, reset,
26
+ * button and image, which take their name from a value or alt attribute
27
+ * rather than from a label. A control carrying
28
+ * an explicit ARIA widget role is out of scope, button, checkbox,
29
+ * combobox, listbox, textbox, slider and the rest of ROLE_OWNED_ELSEWHERE
30
+ * each have a naming rule of their own, and role="presentation"/"none"
31
+ * removes a control unless it is still tabbable.
32
+ * @expectation
33
+ * Each applicable control carries a programmatic label by one of the
34
+ * mechanisms helpers.getLabelMethod resolves, in its priority order: an
35
+ * associated <label>, aria-labelledby, aria-label, title, then
36
+ * placeholder. Any of the five satisfies this rule. Whether the weaker two
37
+ * are an appropriate primary label is a separate question, asked by
38
+ * form-control-programmatic-label-quality.
22
39
  */
23
40
 
24
41
  const id = 'form-control-programmatic-label-present';
@@ -162,7 +179,7 @@ function runInPage(ctx) {
162
179
 
163
180
  // getLabelMethod is provided by the shared dom-helpers bundle that
164
181
  // dom-runner.js always constructs for every rule execution (built-in or
165
- // custom) — see createDomHelpers's own getLabelMethod, which implements
182
+ // custom), see createDomHelpers's own getLabelMethod, which implements
166
183
  // this exact <label>/aria-labelledby/aria-label/title/placeholder
167
184
  // priority order. No local reimplementation is needed as a fallback.
168
185
  function getLabelMethodSafe(el) {
@@ -13,7 +13,7 @@
13
13
  * hidden/submit/reset/button/image; select; textarea).
14
14
  * @expectation
15
15
  * At most one <label> that can contribute to the control's accessible name
16
- * is associated with it — by wrapping it, or by a <label for="..."> on its
16
+ * is associated with it, by wrapping it, or by a <label for="..."> on its
17
17
  * id (a label that both wraps and self-references via for counts once).
18
18
  * Graded by whether the surplus labels actually compete for the name:
19
19
  * - PASS when an override (aria-labelledby / aria-label) supersedes every
@@ -140,51 +140,49 @@ function runInPage(ctx) {
140
140
  : [...eligibleLabels];
141
141
 
142
142
  const tag = el.tagName.toLowerCase();
143
- const stableSelector = helpers.buildSelector ? helpers.buildSelector(el) : 'html';
144
- const html = helpers.getOuterHtmlSnippet ? helpers.getOuterHtmlSnippet(el) : el.outerHTML || '';
145
143
 
146
144
  if (contributing.length >= 2) {
147
- failOccurrences.push({
148
- selector: stableSelector,
149
- html,
150
- summary: 'This form control is associated with more than one <label>.',
151
- hint: 'Keep only one <label> per form control (either wrapping it or referencing it via for/id).',
152
- occurrenceOutcome: 'fail',
153
- i18n: {
154
- summaryKey: 'formControlSingleLabel_summary_fail',
155
- hintKey: 'formControlSingleLabel_hint_fail',
156
- params: { element: tag, labelCount: String(contributing.length) }
157
- },
158
- data: {
159
- details: {
160
- reasonCode: 'FORM_FIELD_MULTIPLE_LABELS',
161
- element: tag,
162
- labelCount: contributing.length
145
+ failOccurrences.push(
146
+ helpers.reportOccurrence(el, {
147
+ summary: 'This form control is associated with more than one <label>.',
148
+ hint: 'Keep only one <label> per form control (either wrapping it or referencing it via for/id).',
149
+ occurrenceOutcome: 'fail',
150
+ i18n: {
151
+ summaryKey: 'formControlSingleLabel_summary_fail',
152
+ hintKey: 'formControlSingleLabel_hint_fail',
153
+ params: { element: tag, labelCount: String(contributing.length) }
154
+ },
155
+ data: {
156
+ details: {
157
+ reasonCode: 'FORM_FIELD_MULTIPLE_LABELS',
158
+ element: tag,
159
+ labelCount: contributing.length
160
+ }
163
161
  }
164
- }
165
- });
162
+ })
163
+ );
166
164
  } else if (contributing.length === 1) {
167
- cantTellOccurrences.push({
168
- selector: stableSelector,
169
- html,
170
- summary:
171
- 'This form control has one labelling <label> plus an extra empty <label> association.',
172
- hint: 'Remove the redundant empty <label> so exactly one <label> is associated with the control.',
173
- occurrenceOutcome: 'cantTell',
174
- i18n: {
175
- summaryKey: 'formControlSingleLabel_summary_cantTell',
176
- hintKey: 'formControlSingleLabel_hint_cantTell',
177
- params: { element: tag, labelCount: String(eligibleLabels.size) }
178
- },
179
- data: {
180
- details: {
181
- reasonCode: 'FORM_FIELD_EXTRA_EMPTY_LABEL',
182
- element: tag,
183
- labelCount: eligibleLabels.size,
184
- contributingLabelCount: contributing.length
165
+ cantTellOccurrences.push(
166
+ helpers.reportOccurrence(el, {
167
+ summary:
168
+ 'This form control has one labelling <label> plus an extra empty <label> association.',
169
+ hint: 'Remove the redundant empty <label> so exactly one <label> is associated with the control.',
170
+ occurrenceOutcome: 'cantTell',
171
+ i18n: {
172
+ summaryKey: 'formControlSingleLabel_summary_cantTell',
173
+ hintKey: 'formControlSingleLabel_hint_cantTell',
174
+ params: { element: tag, labelCount: String(eligibleLabels.size) }
175
+ },
176
+ data: {
177
+ details: {
178
+ reasonCode: 'FORM_FIELD_EXTRA_EMPTY_LABEL',
179
+ element: tag,
180
+ labelCount: eligibleLabels.size,
181
+ contributingLabelCount: contributing.length
182
+ }
185
183
  }
186
- }
187
- });
184
+ })
185
+ );
188
186
  }
189
187
  // contributing.length === 0: no label carries text, so nothing competes
190
188
  // for the name. A control left unnamed is form-control-programmatic-
@@ -84,15 +84,8 @@ function runInPage(ctx) {
84
84
  return { ruleId: rule.ruleId, outcome: 'pass', severity: 'minor', occurrences: [] };
85
85
  }
86
86
 
87
- const stableSelector = helpers.buildSelector ? helpers.buildSelector(html) : 'html';
88
- const htmlSnippet = helpers.getOuterHtmlSnippet
89
- ? helpers.getOuterHtmlSnippet(html)
90
- : (html.outerHTML || '').slice(0, 200);
91
-
92
87
  const occurrences = [
93
- {
94
- selector: stableSelector,
95
- html: htmlSnippet,
88
+ helpers.reportOccurrence(html, {
96
89
  summary: `The lang ("${lang}") and xml:lang ("${xmlLang}") attributes declare different languages.`,
97
90
  hint: 'Make lang and xml:lang declare the same primary language, or remove the deprecated xml:lang attribute.',
98
91
  i18n: {
@@ -103,7 +96,7 @@ function runInPage(ctx) {
103
96
  data: {
104
97
  details: { reasonCode: 'HTML_XML_LANG_MISMATCH', lang, xmlLang }
105
98
  }
106
- }
99
+ })
107
100
  ];
108
101
 
109
102
  return {
@@ -11,7 +11,7 @@
11
11
  * @applicability
12
12
  * Applies to <iframe>/<frame> elements with an explicit negative
13
13
  * tabindex, whose embedded document is same-origin and reachable via
14
- * contentDocument (cross-origin/unreachable frames assert nothing — see
14
+ * contentDocument (cross-origin/unreachable frames assert nothing, see
15
15
  * implementation notes).
16
16
  * @expectation
17
17
  * The frame's embedded document contains no focusable element. Browsers
@@ -19,14 +19,26 @@
19
19
  * document: Tab can still reach focusable content inside, even though
20
20
  * the frame itself is skipped. An author who set tabindex="-1" intending
21
21
  * to remove the frame from the tab order has not actually done so if the
22
- * embedded document contains focusable content.
22
+ * embedded document contains focusable content. Exception: an iframe with
23
+ * both a `width` and `height` HTML attribute of 2px or less (a common
24
+ * "tracking pixel" pattern) cannot render any perceptible content, so
25
+ * focusable content inside it never satisfies ACT akn7bn's "visible"
26
+ * requirement and doesn't count.
23
27
  * @implementation-notes
24
- * - Deliberately scoped to same-origin, currently-accessible content only
28
+ * - Scoped to same-origin, currently-accessible content only
25
29
  * (contentDocument access is wrapped in try/catch and treated as "no
26
- * constraint asserted" — not counted as applicable — when unreachable),
30
+ * constraint asserted", not counted as applicable, when unreachable),
27
31
  * matching this engine's established scope-limiting rationale (see
28
32
  * src/core/aria-helpers.js file header) rather than guessing at
29
33
  * cross-origin content.
34
+ * - A `srcdoc` iframe's document is same-origin by definition, but some
35
+ * environments (notably jsdom, including this library's own Node/jsdom
36
+ * integration path, see docs/INTEGRATION.md) never populate
37
+ * `contentDocument` from the attribute. When the live document looks
38
+ * empty and a `srcdoc` attribute is present, its HTML string is parsed
39
+ * directly via DOMParser as a static fallback, no rendering pipeline
40
+ * needed, and a real browser's already-loaded contentDocument is always
41
+ * preferred untouched.
30
42
  * - Focusability inside the embedded document is checked with a small,
31
43
  * self-contained heuristic (native interactive tags + non-negative
32
44
  * tabindex) rather than ctx.helpers.getFocusableInfo, since that helper
@@ -67,15 +79,15 @@ function runInPage(ctx) {
67
79
  const { helpers, rule, document } = ctx;
68
80
 
69
81
  // Self-contained rendering check for the embedded document (a distinct
70
- // realm — see this rule's own header comment on why the outer
82
+ // realm, see this rule's own header comment on why the outer
71
83
  // document's shared eligibility helpers can't be reused here).
72
- // Deliberately checks only genuine non-rendering (display:none,
84
+ // Checks only genuine non-rendering (display:none,
73
85
  // visibility:hidden, the hidden attribute) via the ancestor chain, NOT
74
86
  // aria-hidden: aria-hidden alone does not remove an element from a real
75
87
  // browser's native tab order (the same anti-pattern this engine's own
76
88
  // aria-hidden-focus rule exists to catch), so an aria-hidden-but-
77
89
  // visually-rendered focusable element inside the frame is still
78
- // genuinely reachable by keyboard and must stay flagged.
90
+ // reachable by keyboard and must stay flagged.
79
91
  function isRenderedInDoc(doc, el) {
80
92
  try {
81
93
  const view = doc.defaultView;
@@ -296,6 +308,44 @@ function runInPage(ctx) {
296
308
  return !Number.isNaN(n) && n < 0;
297
309
  }
298
310
 
311
+ // A `srcdoc` iframe's embedded document is same-origin by definition, but
312
+ // some environments (jsdom, notably) never populate `contentDocument`
313
+ // from the attribute at all. Parsing the attribute's own HTML string is a
314
+ // static, deterministic fallback that needs no rendering pipeline. It
315
+ // only kicks in when the live document looks empty, so a real browser's
316
+ // already-loaded contentDocument is always preferred untouched.
317
+ function parseSrcdocFallback(el) {
318
+ try {
319
+ const raw = el.getAttribute('srcdoc');
320
+ if (raw == null) return null;
321
+ const view = el.ownerDocument && el.ownerDocument.defaultView;
322
+ const DOMParserCtor = view && view.DOMParser;
323
+ if (!DOMParserCtor) return null;
324
+ return new DOMParserCtor().parseFromString(raw, 'text/html');
325
+ } catch {
326
+ return null;
327
+ }
328
+ }
329
+
330
+ // ACT akn7bn's own Expectation only cares about focusable content that is
331
+ // also *visible*: a 1x1 (or similar tracking-pixel-sized) iframe cannot
332
+ // render any perceptible content, whatever's focusable inside it. Scoped
333
+ // to the iframe's own HTML width/height attributes, a static, always-
334
+ // readable signal, unlike computed/rendered size, which needs real
335
+ // layout jsdom doesn't have (see docs/LIMITATIONS.md).
336
+ function isIframeVisiblyTiny(el) {
337
+ try {
338
+ const wAttr = el.getAttribute('width');
339
+ const hAttr = el.getAttribute('height');
340
+ if (wAttr == null || hAttr == null) return false;
341
+ const w = Number(String(wAttr).trim());
342
+ const h = Number(String(hAttr).trim());
343
+ return Number.isFinite(w) && Number.isFinite(h) && w <= 2 && h <= 2;
344
+ } catch {
345
+ return false;
346
+ }
347
+ }
348
+
299
349
  const nodes = helpers.queryAllSmart
300
350
  ? helpers.queryAllSmart('iframe, frame')
301
351
  : helpers.queryAll('iframe, frame');
@@ -314,55 +364,59 @@ function runInPage(ctx) {
314
364
  } catch {
315
365
  contentDoc = null;
316
366
  }
367
+ const looksEmpty = !contentDoc || !contentDoc.body || !contentDoc.body.hasChildNodes();
368
+ if (looksEmpty && el.getAttribute('srcdoc') != null) {
369
+ const parsed = parseSrcdocFallback(el);
370
+ if (parsed) contentDoc = parsed;
371
+ }
317
372
  if (!contentDoc || !contentDoc.querySelectorAll) continue; // cross-origin/unreachable: no constraint asserted
318
373
 
319
374
  applicableCount += 1;
320
375
 
321
376
  const candidates = getFocusableCandidates(contentDoc);
322
377
  if (!candidates.length) continue;
378
+ if (isIframeVisiblyTiny(el)) continue; // ACT akn7bn: no visible content at all
323
379
 
324
380
  const tag = el.tagName.toLowerCase();
325
- const stableSelector = helpers.buildSelector ? helpers.buildSelector(el) : 'html';
326
- const html = helpers.getOuterHtmlSnippet ? helpers.getOuterHtmlSnippet(el) : el.outerHTML || '';
327
381
  const shouldProbe = candidates.length === 1;
328
382
  const runtimeProbe = shouldProbe
329
383
  ? probeImmediateFocusRedirect(el, contentDoc, candidates[0])
330
384
  : null;
331
385
 
332
386
  if (runtimeProbe && runtimeProbe.redirected) {
333
- cantTellOccurrences.push({
334
- selector: stableSelector,
335
- html,
336
- summary:
337
- 'This frame has tabindex="-1" and a focusable candidate, but focus moves immediately to another target. Verify keyboard reachability in a real browser.',
338
- hint: 'If this is an intentional focus handoff, ensure keyboard users cannot remain on hidden/intermediate frame content.',
339
- i18n: null,
340
- data: {
341
- details: {
342
- reasonCode: 'IFRAME_TABINDEX_NEGATIVE_CONTENT_RUNTIME_REDIRECT',
343
- element: tag,
344
- runtimeProbe
387
+ cantTellOccurrences.push(
388
+ helpers.reportOccurrence(el, {
389
+ summary:
390
+ 'This frame has tabindex="-1" and a focusable candidate, but focus moves immediately to another target. Verify keyboard reachability in a real browser.',
391
+ hint: 'If this is an intentional focus handoff, ensure keyboard users cannot remain on hidden/intermediate frame content.',
392
+ i18n: null,
393
+ data: {
394
+ details: {
395
+ reasonCode: 'IFRAME_TABINDEX_NEGATIVE_CONTENT_RUNTIME_REDIRECT',
396
+ element: tag,
397
+ runtimeProbe
398
+ }
345
399
  }
346
- }
347
- });
400
+ })
401
+ );
348
402
  continue;
349
403
  }
350
404
 
351
- failOccurrences.push({
352
- selector: stableSelector,
353
- html,
354
- summary:
355
- 'This frame has tabindex="-1" but its content contains focusable elements, which remain reachable by keyboard.',
356
- hint: 'Remove focusable content from the frame, or remove tabindex="-1" if the frame is meant to be reachable.',
357
- i18n: {
358
- summaryKey: 'iframeFocusableContent_summary_fail',
359
- hintKey: 'iframeFocusableContent_hint_fail',
360
- params: { element: tag }
361
- },
362
- data: {
363
- details: { reasonCode: 'IFRAME_TABINDEX_NEGATIVE_CONTENT_FOCUSABLE', element: tag }
364
- }
365
- });
405
+ failOccurrences.push(
406
+ helpers.reportOccurrence(el, {
407
+ summary:
408
+ 'This frame has tabindex="-1" but its content contains focusable elements, which remain reachable by keyboard.',
409
+ hint: 'Remove focusable content from the frame, or remove tabindex="-1" if the frame is meant to be reachable.',
410
+ i18n: {
411
+ summaryKey: 'iframeFocusableContent_summary_fail',
412
+ hintKey: 'iframeFocusableContent_hint_fail',
413
+ params: { element: tag }
414
+ },
415
+ data: {
416
+ details: { reasonCode: 'IFRAME_TABINDEX_NEGATIVE_CONTENT_FOCUSABLE', element: tag }
417
+ }
418
+ })
419
+ );
366
420
  }
367
421
 
368
422
  if (applicableCount === 0) {