aria-api 0.2.7 → 0.4.2

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.
package/lib/name.js CHANGED
@@ -1,6 +1,6 @@
1
1
  var constants = require('./constants.js');
2
+ var atree = require('./atree.js');
2
3
  var query = require('./query.js');
3
- var util = require('./util.js');
4
4
 
5
5
  var getPseudoContent = function(node, selector) {
6
6
  var styles = window.getComputedStyle(node, selector);
@@ -20,24 +20,8 @@ var getPseudoContent = function(node, selector) {
20
20
  }
21
21
  };
22
22
 
23
- var getContent = function(root, referenced, owned) {
24
- var children = [];
25
-
26
- for (var i = 0; i < root.childNodes.length; i++) {
27
- var node = root.childNodes[i];
28
- if (!node.id || !document.querySelector('[aria-owns~="' + node.id + '"]')) {
29
- children.push(node);
30
- }
31
- }
32
-
33
- var owns = query.getAttribute(root, 'owns') || [];
34
- for (var i = 0; i < owns.length; i++) {
35
- var child = document.getElementById(owns[i]);
36
- if (child && child !== root && owned.indexOf(child.id) === -1) {
37
- children.push(child);
38
- owned.push(child.id);
39
- }
40
- }
23
+ var getContent = function(root, visited) {
24
+ var children = atree.getChildNodes(root);
41
25
 
42
26
  var ret = '';
43
27
  for (var i = 0; i < children.length; i++) {
@@ -50,9 +34,9 @@ var getContent = function(root, referenced, owned) {
50
34
  } else if (window.getComputedStyle(node).display.substr(0, 6) === 'inline' &&
51
35
  node.tagName.toLowerCase() !== 'input' &&
52
36
  node.tagName.toLowerCase() !== 'img') { // https://github.com/w3c/accname/issues/3
53
- ret += getName(node, true, referenced, owned);
37
+ ret += getName(node, true, visited);
54
38
  } else {
55
- ret += ' ' + getName(node, true, referenced, owned) + ' ';
39
+ ret += ' ' + getName(node, true, visited) + ' ';
56
40
  }
57
41
  }
58
42
  }
@@ -62,7 +46,7 @@ var getContent = function(root, referenced, owned) {
62
46
 
63
47
  var allowNameFromContent = function(el) {
64
48
  var role = query.getRole(el);
65
- return role && constants.nameFromContents.indexOf(role) !== -1;
49
+ return (constants.roles[role] || {}).nameFromContents;
66
50
  };
67
51
 
68
52
  var isLabelable = function(el) {
@@ -70,58 +54,46 @@ var isLabelable = function(el) {
70
54
  return el.matches(selector);
71
55
  };
72
56
 
73
- // Control.labels is part of the standard, but not supported in most browsers
74
- var getLabelNodes = function(element) {
75
- var labels = [];
76
- var labelable = constants.labelable.join(',');
77
- util.walkDOM(document.body, function(node) {
78
- if (node.tagName && node.tagName.toLowerCase() === 'label') {
79
- if (node.getAttribute('for')) {
80
- if (element.id && node.getAttribute('for') === element.id) {
81
- labels.push(node);
82
- }
83
- } else if (node.querySelector(labelable) === element) {
84
- labels.push(node);
85
- }
86
- }
87
- });
88
- return labels;
89
- };
90
-
91
57
  var isInLabelForOtherWidget = function(el) {
92
58
  var label = el.parentElement.closest('label');
93
- var ownLabels = getLabelNodes(el);
94
- return label && ownLabels.indexOf(label) === -1;
59
+ return label && !Array.prototype.includes.call(el.labels, label);
95
60
  };
96
61
 
97
- var getName = function(el, recursive, referenced, owned) {
62
+ var getName = function(el, recursive, visited, directReference) {
98
63
  var ret = '';
99
- var owned = owned || [];
100
64
 
101
- // A
102
- if (query.getAttribute(el, 'hidden', referenced)) {
103
- return '';
65
+ visited = visited || [];
66
+ if (visited.includes(el)) {
67
+ if (!directReference) {
68
+ return '';
69
+ }
70
+ } else {
71
+ visited.push(el);
104
72
  }
105
73
 
74
+ // A
75
+ // handled in atree
76
+
106
77
  // B
107
78
  if (!recursive && el.matches('[aria-labelledby]')) {
108
79
  var ids = el.getAttribute('aria-labelledby').split(/\s+/);
109
80
  var strings = ids.map(function(id) {
110
81
  var label = document.getElementById(id);
111
- return label ? getName(label, true, label, owned) : '';
82
+ return label ? getName(label, true, visited, true) : '';
112
83
  });
113
84
  ret = strings.join(' ');
114
85
  }
115
86
 
116
87
  // C
117
88
  if (!ret.trim() && el.matches('[aria-label]')) {
89
+ // FIXME: may skip to 2E
118
90
  ret = el.getAttribute('aria-label');
119
91
  }
120
92
 
121
93
  // D
122
94
  if (!ret.trim() && !recursive && isLabelable(el)) {
123
- var strings = getLabelNodes(el).map(function(label) {
124
- return getName(label, true, label, owned);
95
+ var strings = Array.prototype.map.call(el.labels, function(label) {
96
+ return getName(label, true, visited);
125
97
  });
126
98
  ret = strings.join(' ');
127
99
  }
@@ -139,7 +111,7 @@ var getName = function(el, recursive, referenced, owned) {
139
111
  if (el.matches(selector)) {
140
112
  var descendant = el.querySelector(constants.nameFromDescendant[selector]);
141
113
  if (descendant) {
142
- ret = getName(descendant, true, descendant, owned);
114
+ ret = getName(descendant, true, visited);
143
115
  }
144
116
  }
145
117
  }
@@ -153,7 +125,7 @@ var getName = function(el, recursive, referenced, owned) {
153
125
  } else if (query.matches(el, 'combobox,listbox')) {
154
126
  var selected = query.querySelector(el, ':selected') || query.querySelector(el, 'option');
155
127
  if (selected) {
156
- ret = getName(selected, recursive, referenced, owned);
128
+ ret = getName(selected, recursive, visited);
157
129
  } else {
158
130
  ret = el.value || '';
159
131
  }
@@ -166,18 +138,9 @@ var getName = function(el, recursive, referenced, owned) {
166
138
  // F
167
139
  // FIXME: menu is not mentioned in the spec
168
140
  if (!ret.trim() && (recursive || allowNameFromContent(el) || el.closest('label')) && !query.matches(el, 'menu')) {
169
- ret = getContent(el, referenced, owned);
141
+ ret = getContent(el, visited);
170
142
  }
171
143
 
172
- // TODO: G
173
- // TODO: H
174
-
175
- // FIXME: not mentioned in the spec
176
- if (!ret.trim() && query.matches(el, 'presentation')) {
177
- return getContent(el, referenced, owned);
178
- }
179
-
180
- // FIXME: not mentioned in the spec
181
144
  if (!ret.trim()) {
182
145
  for (var selector in constants.nameDefaults) {
183
146
  if (el.matches(selector)) {
@@ -186,8 +149,12 @@ var getName = function(el, recursive, referenced, owned) {
186
149
  }
187
150
  }
188
151
 
152
+ // G/H
153
+ // handled in getContent
154
+
189
155
  // I
190
- if (!ret.trim()) {
156
+ // FIXME: presentation not mentioned in the spec
157
+ if (!ret.trim() && !query.matches(el, 'presentation')) {
191
158
  ret = el.title || '';
192
159
  }
193
160
 
@@ -202,13 +169,12 @@ var getNameTrimmed = function(el) {
202
169
 
203
170
  var getDescription = function(el) {
204
171
  var ret = '';
205
- var owned = [];
206
172
 
207
173
  if (el.matches('[aria-describedby]')) {
208
174
  var ids = el.getAttribute('aria-describedby').split(/\s+/);
209
175
  var strings = ids.map(function(id) {
210
176
  var label = document.getElementById(id);
211
- return label ? getName(label, true, label, owned) : '';
177
+ return label ? getName(label, true) : '';
212
178
  });
213
179
  ret = strings.join(' ');
214
180
  } else if (el.title) {
package/lib/query.js CHANGED
@@ -1,155 +1,60 @@
1
- var constants = require('./constants.js');
2
- var util = require('./util.js');
1
+ var attrs = require('./attrs.js');
2
+ var atree = require('./atree.js');
3
3
 
4
- var getSubRoles = function(roles) {
5
- return [].concat.apply([], roles.map(function(role) {
6
- return constants.subRoles[role] || [role];
7
- }));
8
- };
9
-
10
- // candidates can be passed for performance optimization
11
- var _getRole = function(el, candidates) {
12
- if (el.hasAttribute('role')) {
13
- return el.getAttribute('role');
14
- }
15
- for (var role in constants.extraSelectors) {
16
- var selector = constants.extraSelectors[role].join(',');
17
- if ((!candidates || candidates.indexOf(role) !== -1) && el.matches(selector)) {
18
- return role;
19
- }
20
- }
21
-
22
- if (!candidates ||
23
- candidates.indexOf('banner') !== -1 ||
24
- candidates.indexOf('contentinfo') !== -1) {
25
- var scoped = el.matches(constants.scoped);
26
-
27
- if (el.matches('header') && !scoped) {
28
- return 'banner';
29
- }
30
- if (el.matches('footer') && !scoped) {
31
- return 'contentinfo';
32
- }
33
- }
34
- };
35
-
36
- var getAttribute = function(el, key, _hiddenRoot) {
37
- if (key === 'hidden' && el === _hiddenRoot) { // used for name calculation
38
- return false;
39
- }
40
-
41
- if (constants.attributeStrongMapping.hasOwnProperty(key)) {
42
- var value = el[constants.attributeStrongMapping[key]];
43
- if (value) {
44
- return value;
45
- }
46
- }
47
- if (key === 'readonly' && el.contentEditable) {
48
- return false;
49
- } else if (key === 'invalid' && el.checkValidity) {
50
- return !el.checkValidity();
51
- } else if (key === 'hidden') {
52
- var style = window.getComputedStyle(el);
53
- if (style.display === 'none' || style.visibility === 'hidden') {
54
- return true;
55
- }
56
- }
57
-
58
- var type = constants.attributes[key];
59
- var raw = el.getAttribute('aria-' + key);
60
-
61
- if (raw) {
62
- if (type === 'bool') {
63
- return raw === 'true';
64
- } else if (type === 'tristate') {
65
- return raw === 'true' ? true : raw === 'false' ? false : 'mixed';
66
- } else if (type === 'bool-undefined') {
67
- return raw === 'true' ? true : raw === 'false' ? false : undefined;
68
- } else if (type === 'id-list') {
69
- return raw.split(/\s+/);
70
- } else if (type === 'integer') {
71
- return parseInt(raw);
72
- } else if (type === 'number') {
73
- return parseFloat(raw);
74
- } else if (type === 'token-list') {
75
- return raw.split(/\s+/);
76
- } else {
77
- return raw;
78
- }
79
- }
80
-
81
- // TODO
82
- // autocomplete
83
- // contextmenu -> aria-haspopup
84
- // indeterminate -> aria-checked="mixed"
85
- // list -> aria-controls
86
-
87
- if (key === 'level') {
88
- for (var i = 1; i <= 6; i++) {
89
- if (el.tagName.toLowerCase() === 'h' + i) {
90
- return i;
91
- }
92
- }
93
- } else if (key === 'hidden') {
94
- if (el.clientHeight === 0) { // rough check for performance
95
- return el.parentNode && getAttribute(el.parentNode, 'hidden', _hiddenRoot);
96
- }
97
- } else if (constants.attributeWeakMapping.hasOwnProperty(key)) {
98
- return el[constants.attributeWeakMapping[key]];
99
- }
100
-
101
- if (type === 'bool' || type === 'tristate') {
102
- return false;
103
- }
104
- };
105
4
 
106
5
  var matches = function(el, selector) {
107
6
  var actual;
108
7
 
109
8
  if (selector.substr(0, 1) === ':') {
110
9
  var attr = selector.substr(1);
111
- return getAttribute(el, attr);
10
+ return attrs.getAttribute(el, attr);
112
11
  } else if (selector.substr(0, 1) === '[') {
113
12
  var match = /\[([a-z]+)="(.*)"\]/.exec(selector);
114
- actual = getAttribute(el, match[1]);
13
+ actual = attrs.getAttribute(el, match[1]);
115
14
  var rawValue = match[2];
116
- return actual.toString() == rawValue;
15
+ return actual.toString() === rawValue;
117
16
  } else {
118
- var candidates = getSubRoles(selector.split(','));
119
- actual = _getRole(el, candidates);
120
- return candidates.indexOf(actual) !== -1;
17
+ return attrs.hasRole(el, selector.split(','));
121
18
  }
122
19
  };
123
20
 
124
21
  var _querySelector = function(all) {
125
22
  return function(root, role) {
126
23
  var results = [];
127
- util.walkDOM(root, function(node) {
128
- if (node.nodeType === node.ELEMENT_NODE) {
129
- // FIXME: skip hidden elements
130
- if (matches(node, role)) {
131
- results.push(node);
132
- if (!all) {
133
- return false;
24
+ try {
25
+ atree.walk(root, function(node) {
26
+ if (node.nodeType === node.ELEMENT_NODE) {
27
+ // FIXME: skip hidden elements
28
+ if (matches(node, role)) {
29
+ results.push(node);
30
+ if (!all) {
31
+ throw 'StopIteration';
32
+ }
134
33
  }
135
34
  }
35
+ });
36
+ } catch (e) {
37
+ if (e !== 'StopIteration') {
38
+ throw e;
136
39
  }
137
- });
40
+ }
138
41
  return all ? results : results[0];
139
42
  };
140
43
  };
141
44
 
142
45
  var closest = function(el, selector) {
143
- return util.searchUp(el, function(candidate) {
144
- return matches(candidate, selector);
46
+ return atree.searchUp(el, function(candidate) {
47
+ if (candidate.nodeType === candidate.ELEMENT_NODE) {
48
+ return matches(candidate, selector);
49
+ }
145
50
  });
146
51
  };
147
52
 
148
53
  module.exports = {
149
54
  getRole: function(el) {
150
- return _getRole(el);
55
+ return attrs.getRole(el);
151
56
  },
152
- getAttribute: getAttribute,
57
+ getAttribute: attrs.getAttribute,
153
58
  matches: matches,
154
59
  querySelector: _querySelector(),
155
60
  querySelectorAll: _querySelector(true),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aria-api",
3
- "version": "0.2.7",
3
+ "version": "0.4.2",
4
4
  "description": "Access ARIA information from JavaScript",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -11,10 +11,11 @@
11
11
  "author": "Tobias Bengfort <tobias.bengfort@posteo.de>",
12
12
  "license": "MIT",
13
13
  "devDependencies": {
14
- "accname-test": "git+https://github.com/xi/accname-test.git",
14
+ "brfs": "^2.0.0",
15
+ "browserify": "^17.0.0",
15
16
  "expect": "^1.20.2",
16
- "mocha": "^6.0.0",
17
- "mocha-headless-chrome": "^2.0.0"
17
+ "mocha": "^9.0.1",
18
+ "mocha-headless-chrome": "^3.1.0"
18
19
  },
19
20
  "files": [
20
21
  "index.js",
package/CHANGES.md DELETED
@@ -1,102 +0,0 @@
1
- 0.2.7 (2019-03-26)
2
- ------------------
3
-
4
- - name: fix some bugs in handeling of `aria-owns`
5
- - name: various improvements
6
- - update README to be more specific about the supported specs
7
-
8
-
9
- 0.2.6 (2018-07-07)
10
- ------------------
11
-
12
- - name: return empty description if same as name
13
- - query: add support for term role
14
- - query: consider conflicts (see
15
- https://www.w3.org/TR/core-aam-1.1/#mapping_conflicts)
16
-
17
-
18
- 0.2.5 (2018-05-01)
19
- ------------------
20
-
21
- - support graphics-aria
22
- - name: various improvements
23
-
24
-
25
- 0.2.4 (2018-03-01)
26
- ------------------
27
-
28
- - I forgot to update the dist files
29
-
30
-
31
- 0.2.3 (2018-03-01)
32
- ------------------
33
-
34
- - name: add additional whitespace around `<input>` and `<img>` elements
35
- - name: treat menus like comboboxes
36
- - name: fix some cases where pseudo content was omitted
37
- - name: ignore whitespace-only names in the computations
38
- - name: ignore any non-string pseudo content (some dynamic cases like `attr()`
39
- or `conter()` are not handled correctly yet)
40
- - sections only get the implicit landmark role if they have an explicit label
41
- (same as forms)
42
-
43
-
44
- 0.2.2 (2018-02-14)
45
- ------------------
46
-
47
- - name: further improve support for embedded controls
48
- - name: use title attribute as alternative text for `<abbr>` and `<acronym>`
49
- - name: correctly handle multiple labels
50
- - name: add whitespace for `<br>` and around non non-inline elements
51
- - add some missing implicit role mappings (e.g. select)
52
-
53
-
54
- 0.2.1 (2018-02-03)
55
- ------------------
56
-
57
- - extend tests for name/description calculation and fix some bugs
58
- - case insensitive tagName matching
59
- - treat roles "presentation" and "none" as aliases for each other
60
-
61
-
62
- 0.2.0 (2017-12-29)
63
- ------------------
64
-
65
- - update role hierarchy to ARIA 1.1
66
- - add dpub-aria role support
67
- - fix readonly calculation
68
-
69
-
70
- 0.1.1 (2017-08-03)
71
- ------------------
72
-
73
- - forms only get the implicity form role if they have an explicity label
74
- - fixes to the calculation of the "hidden" property
75
-
76
-
77
- 0.1.0 (2017-07-12)
78
- ------------------
79
-
80
- - some performance optimizations
81
- - add `closest()`
82
- - allow comma separated roles in selectors
83
-
84
-
85
- 0.0.2 (2017-04-22)
86
- ------------------
87
-
88
- - name: fix syntax error in a selector
89
-
90
-
91
- 0.0.1 (2017-04-22)
92
- ------------------
93
-
94
- - role: fix implicit role detection for header and footer
95
- - name: strip quotes when including pseudo content
96
- - name: ignore label and alt on elements with role "presentational"
97
-
98
-
99
- 0.0.0 (2017-03-12)
100
- ------------------
101
-
102
- initial version
package/dist/aria.min.js DELETED
@@ -1 +0,0 @@
1
- !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).aria=e()}}(function(){return function r(a,l,s){function u(t,e){if(!l[t]){if(!a[t]){var o="function"==typeof require&&require;if(!e&&o)return o(t,!0);if(c)return c(t,!0);var i=new Error("Cannot find module '"+t+"'");throw i.code="MODULE_NOT_FOUND",i}var n=l[t]={exports:{}};a[t][0].call(n.exports,function(e){return u(a[t][1][e]||e)},n,n.exports,r,a,l,s)}return l[t].exports}for(var c="function"==typeof require&&require,e=0;e<s.length;e++)u(s[e]);return u}({1:[function(e,t,o){var i=e("./lib/query.js"),n=e("./lib/name.js");t.exports={getRole:i.getRole,getAttribute:i.getAttribute,getName:n.getName,getDescription:n.getDescription,matches:i.matches,querySelector:i.querySelector,querySelectorAll:i.querySelectorAll,closest:i.closest}},{"./lib/name.js":3,"./lib/query.js":4}],2:[function(e,t,o){o.attributes={autocomplete:"token",checked:"tristate",current:"token",disabled:"bool",expanded:"bool-undefined",haspopup:"token",hidden:"bool",invalid:"token",keyshortcuts:"string",label:"string",level:"int",modal:"bool",multiline:"bool",multiselectable:"bool",orientation:"token",placeholder:"string",pressed:"tristate",readonly:"bool",required:"bool",roledescription:"string",selected:"bool-undefined",valuemax:"number",valuemin:"number",valuenow:"number",valuetext:"string",atomic:"bool",busy:"bool",live:"token",relevant:"token-list",dropeffect:"token-list",grabbed:"bool-undefined",activedescendant:"id",colcount:"int",colindex:"int",colspan:"int",controls:"id-list",describedby:"id-list",details:"id",errormessage:"id",flowto:"id-list",labelledby:"id-list",owns:"id-list",posinset:"int",rowcount:"int",rowindex:"int",rowspan:"int",setsize:"int",sort:"token"},o.attributeStrongMapping={disabled:"disabled",hidden:"hidden",placeholder:"placeholder",readonly:"readOnly",required:"required"},o.attributeWeakMapping={checked:"checked",colspan:"colSpan",expanded:"open",multiselectable:"multiple",rowspan:"rowSpan",selected:"selected"},o.extraSelectors={article:["article"],button:["button",'input[type="button"]','input[type="image"]','input[type="reset"]','input[type="submit"]',"summary"],cell:["td"],checkbox:['input[type="checkbox"]'],combobox:["input:not([type])[list]",'input[type="email"][list]','input[type="search"][list]','input[type="tel"][list]','input[type="text"][list]','input[type="url"][list]',"select:not([size]):not([multiple])",'select[size="0"]:not([multiple])','select[size="1"]:not([multiple])'],complementary:["aside"],definition:["dd"],dialog:["dialog"],document:["body"],figure:["figure"],form:["form[aria-label]","form[aria-labelledby]"],group:["details","optgroup"],heading:["h1","h2","h3","h4","h5","h6"],img:['img:not([alt=""])',"graphics-symbol"],link:["a[href]","area[href]","link[href]"],list:["dl","ol","ul"],listbox:["select[multiple]",'select[size]:not([size="0"]):not([size="1"])'],listitem:["dt","ul > li","ol > li"],main:["main"],math:["math"],menuitemcheckbox:['menuitem[type="checkbox"]'],menuitem:['menuitem[type="command"]'],menuitemradio:['menuitem[type="radio"]'],menu:['menu[type="context"]'],navigation:["nav"],option:["option"],progressbar:["progress"],radio:['input[type="radio"]'],region:["section[aria-label]","section[aria-labelledby]","section[title]"],rowgroup:["tbody","thead","tfoot"],row:["tr"],searchbox:['input[type="search"]:not([list])'],separator:["hr"],slider:['input[type="range"]'],spinbutton:['input[type="number"]'],status:["output"],table:["table"],term:["dfn","dt"],textbox:["input:not([type]):not([list])",'input[type="email"]:not([list])','input[type="tel"]:not([list])','input[type="text"]:not([list])','input[type="url"]:not([list])',"textarea"],rowheader:['th[scope="row"]'],columnheader:['th[scope="col"]']},o.scoped=["article *","aside *","main *","nav *","section *"].join(",");var i={cell:["gridcell","rowheader"],command:["button","link","menuitem"],composite:["grid","select","spinbutton","tablist"],img:["doc-cover"],input:["checkbox","option","radio","slider","spinbutton","textbox"],landmark:["banner","complementary","contentinfo","doc-acknowledgments","doc-afterword","doc-appendix","doc-bibliography","doc-chapter","doc-conclusion","doc-credits","doc-endnotes","doc-epilogue","doc-errata","doc-foreword","doc-glossary","doc-introduction","doc-part","doc-preface","doc-prologue","form","main","navigation","region","search"],range:["progressbar","scrollbar","slider","spinbutton"],roletype:["structure","widget","window"],section:["alert","cell","definition","doc-abstract","doc-colophon","doc-credit","doc-dedication","doc-epigraph","doc-example","doc-footnote","doc-qna","figure","group","img","landmark","list","listitem","log","marquee","math","note","status","table","tabpanel","term","tooltip"],sectionhead:["columnheader","doc-subtitle","heading","rowheader","tab"],select:["combobox","listbox","menu","radiogroup","tree"],separator:["doc-pagebreak"],structure:["application","document","none","presentation","rowgroup","section","sectionhead","separator"],table:["grid"],textbox:["searchbox"],widget:["command","composite","gridcell","input","range","row","separator","tab"],window:["dialog"],alert:["alertdialog"],checkbox:["menuitemcheckbox","switch"],dialog:["alertdialog"],gridcell:["columnheader","rowheader"],menuitem:["menuitemcheckbox"],menuitemcheckbox:["menuitemradio"],option:["treeitem"],radio:["menuitemradio"],status:["timer"],grid:["treegrid"],menu:["menubar"],tree:["treegrid"],document:["article","graphics-document"],group:["row","select","toolbar","graphics-object"],link:["doc-backlink","doc-biblioref","doc-glossref","doc-noteref"],list:["directory","feed"],listitem:["doc-biblioentry","doc-endnote","treeitem"],navigation:["doc-index","doc-pagelist","doc-toc"],note:["doc-notice","doc-tip"]},n=function(e){var t=(i[e]||[]).map(n),o=[e];return t.forEach(function(e){e.forEach(function(e){-1===o.indexOf(e)&&o.push(e)})}),o};for(var r in o.subRoles={},i)o.subRoles[r]=n(r);o.subRoles.none=["none","presentation"],o.subRoles.presentation=["presentation","none"],o.nameFromContents=["button","checkbox","columnheader","doc-backlink","doc-biblioref","doc-glossref","doc-noteref","gridcell","heading","link","menuitem","menuitemcheckbox","menuitemradio","option","radio","row","rowgroup","rowheader","sectionhead","tab","tooltip","treeitem","switch"],o.nameFromDescendant={figure:"figcaption",table:"caption",fieldset:"legend"},o.nameDefaults={'input[type="submit"]':"Submit",'input[type="reset"]':"Reset",summary:"Details"},o.labelable=["button",'input:not([type="hidden"])',"keygen","meter","output","progress","select","textarea"]},{}],3:[function(e,t,o){var f=e("./constants.js"),g=e("./query.js"),n=e("./util.js"),h=function(e,t){var o=window.getComputedStyle(e,t),i=o.getPropertyValue("content"),n="inline"===o.display.substr(0,6);return i?'"'!==i.substr(0,1)?"":n?i.slice(1,-1):" "+i.slice(1,-1)+" ":""},y=function(e,t,o){for(var i=[],n=0;n<e.childNodes.length;n++){(s=e.childNodes[n]).id&&document.querySelector('[aria-owns~="'+s.id+'"]')||i.push(s)}var r=g.getAttribute(e,"owns")||[];for(n=0;n<r.length;n++){var a=document.getElementById(r[n]);a&&a!==e&&-1===o.indexOf(a.id)&&(i.push(a),o.push(a.id))}var l="";for(n=0;n<i.length;n++){var s;(s=i[n]).nodeType===s.TEXT_NODE?l+=s.textContent:s.nodeType===s.ELEMENT_NODE&&("br"===s.tagName.toLowerCase()?l+="\n":"inline"===window.getComputedStyle(s).display.substr(0,6)&&"input"!==s.tagName.toLowerCase()&&"img"!==s.tagName.toLowerCase()?l+=v(s,!0,t,o):l+=" "+v(s,!0,t,o)+" ")}return l},x=function(t){var o=[],i=f.labelable.join(",");return n.walkDOM(document.body,function(e){e.tagName&&"label"===e.tagName.toLowerCase()&&(e.getAttribute("for")?t.id&&e.getAttribute("for")===t.id&&o.push(e):e.querySelector(i)===t&&o.push(e))}),o},v=function(e,t,o,i){var n,r,a,l,s,u,c,d="";i=i||[];if(g.getAttribute(e,"hidden",o))return"";!t&&e.matches("[aria-labelledby]")&&(d=e.getAttribute("aria-labelledby").split(/\s+/).map(function(e){var t=document.getElementById(e);return t?v(t,!0,t,i):""}).join(" "));(!d.trim()&&e.matches("[aria-label]")&&(d=e.getAttribute("aria-label")),d.trim()||t||(n=e,r=f.labelable.join(","),!n.matches(r)))||(d=x(e).map(function(e){return v(e,!0,e,i)}).join(" "));if(d.trim()||(d=e.placeholder||""),d.trim()||(d=e.alt||""),!d.trim()&&e.matches("abbr,acronym")&&e.title&&(d=e.title),!d.trim())for(var p in f.nameFromDescendant)if(e.matches(p)){var m=e.querySelector(f.nameFromDescendant[p]);m&&(d=v(m,!0,m,i))}if(!d.trim()&&(t||(l=(a=e).parentElement.closest("label"),s=x(a),l&&-1===s.indexOf(l))||g.matches(e,"button"))&&g.matches(e,"textbox,button,combobox,listbox,range"))if(g.matches(e,"textbox,button"))d=e.value||e.textContent;else if(g.matches(e,"combobox,listbox")){var b=g.querySelector(e,":selected")||g.querySelector(e,"option");d=b?v(b,t,o,i):e.value||""}else g.matches(e,"range")&&(d=""+(g.getAttribute(e,"valuetext")||g.getAttribute(e,"valuenow")||e.value));if(d.trim()||!(t||(u=e,(c=g.getRole(u))&&-1!==f.nameFromContents.indexOf(c))||e.closest("label"))||g.matches(e,"menu")||(d=y(e,o,i)),!d.trim()&&g.matches(e,"presentation"))return y(e,o,i);if(!d.trim())for(var p in f.nameDefaults)e.matches(p)&&(d=f.nameDefaults[p]);return d.trim()||(d=e.title||""),h(e,":before")+d+h(e,":after")},i=function(e){return v(e).replace(/\s+/g," ").trim()};t.exports={getName:i,getDescription:function(e){var t="",o=[];e.matches("[aria-describedby]")?t=e.getAttribute("aria-describedby").split(/\s+/).map(function(e){var t=document.getElementById(e);return t?v(t,!0,t,o):""}).join(" "):e.title?t=e.title:e.placeholder&&(t=e.placeholder);return(t=(t||"").trim().replace(/\s+/g," "))===i(e)&&(t=""),t}}},{"./constants.js":2,"./query.js":4,"./util.js":5}],4:[function(e,t,o){var s=e("./constants.js"),n=e("./util.js"),u=function(e,t){if(e.hasAttribute("role"))return e.getAttribute("role");for(var o in s.extraSelectors){var i=s.extraSelectors[o].join(",");if((!t||-1!==t.indexOf(o))&&e.matches(i))return o}if(!t||-1!==t.indexOf("banner")||-1!==t.indexOf("contentinfo")){var n=e.matches(s.scoped);if(e.matches("header")&&!n)return"banner";if(e.matches("footer")&&!n)return"contentinfo"}},c=function(e,t,o){if("hidden"===t&&e===o)return!1;if(s.attributeStrongMapping.hasOwnProperty(t)){var i=e[s.attributeStrongMapping[t]];if(i)return i}if("readonly"===t&&e.contentEditable)return!1;if("invalid"===t&&e.checkValidity)return!e.checkValidity();if("hidden"===t){var n=window.getComputedStyle(e);if("none"===n.display||"hidden"===n.visibility)return!0}var r=s.attributes[t],a=e.getAttribute("aria-"+t);if(a)return"bool"===r?"true"===a:"tristate"===r?"true"===a||"false"!==a&&"mixed":"bool-undefined"===r?"true"===a||"false"!==a&&void 0:"id-list"===r?a.split(/\s+/):"integer"===r?parseInt(a):"number"===r?parseFloat(a):"token-list"===r?a.split(/\s+/):a;if("level"===t){for(var l=1;l<=6;l++)if(e.tagName.toLowerCase()==="h"+l)return l}else if("hidden"===t){if(0===e.clientHeight)return e.parentNode&&c(e.parentNode,"hidden",o)}else if(s.attributeWeakMapping.hasOwnProperty(t))return e[s.attributeWeakMapping[t]];return"bool"!==r&&"tristate"!==r&&void 0},r=function(e,t){var o;if(":"===t.substr(0,1)){var i=t.substr(1);return c(e,i)}if("["===t.substr(0,1)){var n=/\[([a-z]+)="(.*)"\]/.exec(t);o=c(e,n[1]);var r=n[2];return o.toString()==r}var a,l=(a=t.split(","),[].concat.apply([],a.map(function(e){return s.subRoles[e]||[e]})));return o=u(e,l),-1!==l.indexOf(o)},i=function(i){return function(e,t){var o=[];return n.walkDOM(e,function(e){if(e.nodeType===e.ELEMENT_NODE&&r(e,t)&&(o.push(e),!i))return!1}),i?o:o[0]}};t.exports={getRole:function(e){return u(e)},getAttribute:c,matches:r,querySelector:i(),querySelectorAll:i(!0),closest:function(e,t){return n.searchUp(e,function(e){return r(e,t)})}}},{"./constants.js":2,"./util.js":5}],5:[function(e,t,o){var i=function(e,t){if(!1===t(e))return!1;for(var o=e.firstChild;o;){if(!1===i(o,t))return!1;o=o.nextSibling}},n=function(e,t){var o=e.parentElement;if(o)return t(o)?o:n(o,t)};t.exports={walkDOM:i,searchUp:n}},{}]},{},[1])(1)});
package/lib/util.js DELETED
@@ -1,28 +0,0 @@
1
- var walkDOM = function(root, fn) {
2
- if (fn(root) === false) {
3
- return false;
4
- }
5
- var node = root.firstChild;
6
- while (node) {
7
- if (walkDOM(node, fn) === false) {
8
- return false;
9
- }
10
- node = node.nextSibling;
11
- }
12
- };
13
-
14
- var searchUp = function(el, test) {
15
- var candidate = el.parentElement;
16
- if (candidate) {
17
- if (test(candidate)) {
18
- return candidate;
19
- } else {
20
- return searchUp(candidate, test);
21
- }
22
- }
23
- };
24
-
25
- module.exports = {
26
- walkDOM: walkDOM,
27
- searchUp: searchUp,
28
- };