- commit
- ae46457df52900a932a4c44a1e5f3f54cf3c8488
- parent
- 6177f20ae6ca5c8d4d8b77055649ad3fe760b723
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-06-21 15:51
add svg-aam selectors
Diffstat
| M | lib/constants.js | 45 | +++++++++++++++++++++++++++++++++++++++++---- |
1 files changed, 41 insertions, 4 deletions
diff --git a/lib/constants.js b/lib/constants.js
@@ -69,6 +69,19 @@ exports.attributeWeakMapping = {
69 69 // https://www.w3.org/TR/html/dom.html#sectioning-content-2
70 70 const scoped = ['article *', 'aside *', 'nav *', 'section *'].join(',');
71 71
-1 72 const svgSelectors = function(selector) {
-1 73 return [
-1 74 `${selector}:has(> title:not(:empty))`,
-1 75 `${selector}:has(> desc:not(:empty))`,
-1 76 `${selector}[aria-label]`,
-1 77 `${selector}[aria-roledescription]`,
-1 78 `${selector}[aria-labelledby]`,
-1 79 `${selector}[aria-describedby]`,
-1 80 `${selector}[tabindex]`,
-1 81 `${selector}[role]`,
-1 82 ];
-1 83 };
-1 84
72 85 // https://www.w3.org/TR/html-aam-1.0/#html-element-role-mappings
73 86 // https://www.w3.org/TR/wai-aria/roles
74 87 exports.roles = {
@@ -265,8 +278,23 @@ exports.roles = {
265 278 'graphics-document': {
266 279 selectors: ['svg'],
267 280 },
268 -1 'graphics-object': {},
269 -1 'graphics-symbol': {},
-1 281 'graphics-object': {
-1 282 selectors: [
-1 283 ...svgSelectors('symbol'),
-1 284 ...svgSelectors('use'),
-1 285 ],
-1 286 },
-1 287 'graphics-symbol': {
-1 288 selectors: [
-1 289 ...svgSelectors('circle'),
-1 290 ...svgSelectors('ellipse'),
-1 291 ...svgSelectors('line'),
-1 292 ...svgSelectors('path'),
-1 293 ...svgSelectors('polygon'),
-1 294 ...svgSelectors('polyline'),
-1 295 ...svgSelectors('rect'),
-1 296 ],
-1 297 },
270 298 grid: {
271 299 childRoles: ['treegrid'],
272 300 },
@@ -281,7 +309,11 @@ exports.roles = {
281 309 'fieldset',
282 310 'hgroup',
283 311 'optgroup',
-1 312 ...svgSelectors('foreignObject'),
-1 313 ...svgSelectors('g'),
284 314 'text',
-1 315 ...svgSelectors('textPath'),
-1 316 ...svgSelectors('tspan'),
285 317 ],
286 318 childRoles: ['row', 'select', 'toolbar', 'graphics-object'],
287 319 },
@@ -293,7 +325,12 @@ exports.roles = {
293 325 },
294 326 },
295 327 img: {
296 -1 selectors: ['img:not([alt=""])', 'graphics-symbol'],
-1 328 selectors: [
-1 329 'img:not([alt=""])',
-1 330 'graphics-symbol',
-1 331 ...svgSelectors('image'),
-1 332 ...svgSelectors('mesh'),
-1 333 ],
297 334 childRoles: ['doc-cover'],
298 335 },
299 336 input: {
@@ -341,7 +378,7 @@ exports.roles = {
341 378 ],
342 379 },
343 380 link: {
344 -1 selectors: ['a[href]', 'area[href]'],
-1 381 selectors: ['a[href]', 'area[href]', 'a[xlink\\:href]'],
345 382 childRoles: ['doc-backlink', 'doc-biblioref', 'doc-glossref', 'doc-noteref'],
346 383 nameFromContents: true,
347 384 },