- commit
- 524601e7cf43af9465cae550128e618d58307d0e
- parent
- fb778d08cf1cad1a9e7a55e87b01987d440a6c9f
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-01-12 18:00
refactor: turn scoped into selector
Diffstat
| M | lib/attrs.js | 13 | ------------- |
| M | lib/constants.js | 22 | ++++++++++++++-------- |
2 files changed, 14 insertions, 21 deletions
diff --git a/lib/attrs.js b/lib/attrs.js
@@ -11,19 +11,6 @@ var getRole = function(el, candidates) {
11 11 return role;
12 12 }
13 13 }
14 -1
15 -1 if (!candidates ||
16 -1 candidates.includes('banner') ||
17 -1 candidates.includes('contentinfo')) {
18 -1 if (!el.matches(constants.scoped)) {
19 -1 if (el.matches('header')) {
20 -1 return 'banner';
21 -1 }
22 -1 if (el.matches('footer')) {
23 -1 return 'contentinfo';
24 -1 }
25 -1 }
26 -1 }
27 14 };
28 15
29 16 var hasRole = function(el, roles) {
diff --git a/lib/constants.js b/lib/constants.js
@@ -66,6 +66,14 @@ exports.attributeWeakMapping = {
66 66 'selected': 'selected',
67 67 };
68 68
-1 69 var scoped = [
-1 70 'main *',
-1 71 // https://www.w3.org/TR/html/dom.html#sectioning-content-2
-1 72 'article *', 'aside *', 'nav *', 'section *',
-1 73 // https://www.w3.org/TR/html/sections.html#sectioning-roots
-1 74 'blockquote *', 'details *', 'dialog *', 'fieldset *', 'figure *', 'td *',
-1 75 ].join(',');
-1 76
69 77 // https://www.w3.org/TR/html-aam-1.0/#html-element-role-mappings
70 78 // https://www.w3.org/TR/wai-aria/roles
71 79 exports.roles = {
@@ -79,6 +87,9 @@ exports.roles = {
79 87 article: {
80 88 selectors: ['article'],
81 89 },
-1 90 banner: {
-1 91 selectors: ['header:not(' + scoped + ')'],
-1 92 },
82 93 button: {
83 94 selectors: [
84 95 'button',
@@ -133,6 +144,9 @@ exports.roles = {
133 144 composite: {
134 145 childRoles: ['grid', 'select', 'spinbutton', 'tablist'],
135 146 },
-1 147 contentinfo: {
-1 148 selectors: ['footer:not(' + scoped + ')'],
-1 149 },
136 150 definition: {
137 151 selectors: ['dd'],
138 152 },
@@ -498,14 +512,6 @@ exports.roles = {
498 512 },
499 513 };
500 514
501 -1 exports.scoped = [
502 -1 'main *',
503 -1 // https://www.w3.org/TR/html/dom.html#sectioning-content-2
504 -1 'article *', 'aside *', 'nav *', 'section *',
505 -1 // https://www.w3.org/TR/html/sections.html#sectioning-roots
506 -1 'blockquote *', 'details *', 'dialog *', 'fieldset *', 'figure *', 'td *',
507 -1 ].join(',');
508 -1
509 515 var getSubRoles = function(role) {
510 516 var children = (exports.roles[role] || {}).childRoles || [];
511 517 var descendents = children.map(getSubRoles);