aria-api 0.8.0 → 0.9.1

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/README.md CHANGED
@@ -14,7 +14,7 @@ complicated. This library takes care of exactly that.
14
14
  npm install aria-api
15
15
 
16
16
  This installation method works best if you use tools like webpack or
17
- browserify. There is also an UMD build included as `dist/aria.js`.
17
+ rollup. There is also an UMD build included as `dist/aria.js`.
18
18
 
19
19
  # Usage
20
20
 
package/dist/aria.js CHANGED
@@ -912,28 +912,20 @@
912
912
  }
913
913
  };
914
914
 
915
- const _getOwner = function(node, owners) {
915
+ const _getOwner = function(node) {
916
916
  if (node.nodeType === node.ELEMENT_NODE && node.id) {
917
- const selector = '[aria-owns~="' + CSS.escape(node.id) + '"]';
918
- if (owners) {
919
- for (const owner of owners) {
920
- if (owner.matches(selector)) {
921
- return owner;
922
- }
923
- }
924
- } else {
925
- return document.querySelector(selector);
926
- }
917
+ const selector = `[aria-owns~="${CSS.escape(node.id)}"]`;
918
+ return node.getRootNode().querySelector(selector);
927
919
  }
928
920
  };
929
921
 
930
- const _getParentNode = function(node, owners) {
931
- return _getOwner(node, owners) || node.parentNode;
922
+ const _getParentNode = function(node) {
923
+ return _getOwner(node) || node.parentNode || node.host;
932
924
  };
933
925
 
934
- const detectLoop = function(node, owners) {
926
+ const detectLoop = function(node) {
935
927
  const seen = [node];
936
- while ((node = _getParentNode(node, owners))) {
928
+ while ((node = _getParentNode(node))) {
937
929
  if (seen.includes(node)) {
938
930
  return true;
939
931
  }
@@ -941,27 +933,36 @@
941
933
  }
942
934
  };
943
935
 
944
- const getOwner = function(node, owners) {
945
- const owner = _getOwner(node, owners);
946
- if (owner && !detectLoop(node, owners)) {
936
+ const getOwner = function(node) {
937
+ const owner = _getOwner(node);
938
+ if (owner && !detectLoop(node)) {
947
939
  return owner;
948
940
  }
949
941
  };
950
942
 
951
- const getParentNode = function(node, owners) {
952
- return getOwner(node, owners) || node.parentNode;
943
+ const getParentNode = function(node) {
944
+ return getOwner(node) || node.parentNode || node.host;
953
945
  };
954
946
 
955
947
  const isHidden = function(node) {
956
948
  return node.nodeType === node.ELEMENT_NODE && getAttribute(node, 'hidden');
957
949
  };
958
950
 
959
- const getChildNodes = function(node, owners) {
951
+ const getChildNodes = function(node) {
960
952
  const childNodes = [];
953
+ let rawChildNodes = [];
961
954
 
962
- for (let i = 0; i < node.childNodes.length; i++) {
963
- const child = node.childNodes[i];
964
- if (!getOwner(child, owners) && !isHidden(child)) {
955
+ if (node.shadowRoot) {
956
+ rawChildNodes = node.shadowRoot.childNodes;
957
+ } else if (node.assignedNodes) {
958
+ rawChildNodes = node.assignedNodes();
959
+ } else {
960
+ rawChildNodes = node.childNodes;
961
+ }
962
+
963
+ for (let i = 0; i < rawChildNodes.length; i++) {
964
+ const child = rawChildNodes[i];
965
+ if (!getOwner(child) && !isHidden(child)) {
965
966
  childNodes.push(child);
966
967
  }
967
968
  }
@@ -969,9 +970,9 @@
969
970
  if (node.nodeType === node.ELEMENT_NODE) {
970
971
  const owns = getAttribute(node, 'owns') || [];
971
972
  for (let i = 0; i < owns.length; i++) {
972
- const child = document.getElementById(owns[i]);
973
+ const child = node.getRootNode().getElementById(owns[i]);
973
974
  // double check with getOwner for consistency
974
- if (child && getOwner(child, owners) === node && !isHidden(child)) {
975
+ if (child && getOwner(child) === node && !isHidden(child)) {
975
976
  childNodes.push(child);
976
977
  }
977
978
  }
@@ -981,12 +982,11 @@
981
982
  };
982
983
 
983
984
  const walk = function(root, fn) {
984
- const owners = document.querySelectorAll('[aria-owns]');
985
985
  let queue = [root];
986
986
  while (queue.length) {
987
987
  const item = queue.shift();
988
988
  fn(item);
989
- queue = getChildNodes(item, owners).concat(queue);
989
+ queue = getChildNodes(item).concat(queue);
990
990
  }
991
991
  };
992
992
 
@@ -1093,13 +1093,17 @@
1093
1093
  for (let i = 0; i < children.length; i++) {
1094
1094
  const node = children[i];
1095
1095
  if (node.nodeType === node.TEXT_NODE) {
1096
- const styles = window.getComputedStyle(node.parentElement);
1097
- if (styles.textTransform === 'uppercase') {
1098
- ret += node.textContent.toUpperCase();
1099
- } else if (styles.textTransform === 'lowercase') {
1100
- ret += node.textContent.toLowerCase();
1101
- } else if (styles.textTransform === 'capitalize') {
1102
- ret += node.textContent.replace(/\b\w/g, c => c.toUpperCase());
1096
+ if (node.parentElement) {
1097
+ const styles = window.getComputedStyle(node.parentElement);
1098
+ if (styles.textTransform === 'uppercase') {
1099
+ ret += node.textContent.toUpperCase();
1100
+ } else if (styles.textTransform === 'lowercase') {
1101
+ ret += node.textContent.toLowerCase();
1102
+ } else if (styles.textTransform === 'capitalize') {
1103
+ ret += node.textContent.replace(/\b\w/g, c => c.toUpperCase());
1104
+ } else {
1105
+ ret += node.textContent;
1106
+ }
1103
1107
  } else {
1104
1108
  ret += node.textContent;
1105
1109
  }
@@ -1141,7 +1145,7 @@
1141
1145
  if (!ongoingLabelledBy && el.matches('[aria-labelledby]')) {
1142
1146
  const ids = el.getAttribute('aria-labelledby').split(/\s+/);
1143
1147
  const strings = ids.map(id => {
1144
- const label = document.getElementById(id);
1148
+ const label = el.getRootNode().getElementById(id);
1145
1149
  return label ? getNameRaw(label, true, true, visited, true) : '';
1146
1150
  });
1147
1151
  ret = strings.join(' ');
@@ -1252,7 +1256,7 @@
1252
1256
  if (el.matches('[aria-describedby]')) {
1253
1257
  const ids = el.getAttribute('aria-describedby').split(/\s+/);
1254
1258
  const strings = ids.map(id => {
1255
- const label = document.getElementById(id);
1259
+ const label = el.getRootNode().getElementById(id);
1256
1260
  return label ? getNameRaw(label, true, true) : '';
1257
1261
  });
1258
1262
  ret = strings.join(' ');
package/lib/atree.js CHANGED
@@ -1,27 +1,19 @@
1
1
  import * as attrs from './attrs';
2
2
 
3
- const _getOwner = function(node, owners) {
3
+ const _getOwner = function(node) {
4
4
  if (node.nodeType === node.ELEMENT_NODE && node.id) {
5
- const selector = '[aria-owns~="' + CSS.escape(node.id) + '"]';
6
- if (owners) {
7
- for (const owner of owners) {
8
- if (owner.matches(selector)) {
9
- return owner;
10
- }
11
- }
12
- } else {
13
- return document.querySelector(selector);
14
- }
5
+ const selector = `[aria-owns~="${CSS.escape(node.id)}"]`;
6
+ return node.getRootNode().querySelector(selector);
15
7
  }
16
8
  };
17
9
 
18
- const _getParentNode = function(node, owners) {
19
- return _getOwner(node, owners) || node.parentNode;
10
+ const _getParentNode = function(node) {
11
+ return _getOwner(node) || node.parentNode || node.host;
20
12
  };
21
13
 
22
- const detectLoop = function(node, owners) {
14
+ const detectLoop = function(node) {
23
15
  const seen = [node];
24
- while ((node = _getParentNode(node, owners))) {
16
+ while ((node = _getParentNode(node))) {
25
17
  if (seen.includes(node)) {
26
18
  return true;
27
19
  }
@@ -29,27 +21,36 @@ const detectLoop = function(node, owners) {
29
21
  }
30
22
  };
31
23
 
32
- const getOwner = function(node, owners) {
33
- const owner = _getOwner(node, owners);
34
- if (owner && !detectLoop(node, owners)) {
24
+ const getOwner = function(node) {
25
+ const owner = _getOwner(node);
26
+ if (owner && !detectLoop(node)) {
35
27
  return owner;
36
28
  }
37
29
  };
38
30
 
39
- export const getParentNode = function(node, owners) {
40
- return getOwner(node, owners) || node.parentNode;
31
+ export const getParentNode = function(node) {
32
+ return getOwner(node) || node.parentNode || node.host;
41
33
  };
42
34
 
43
35
  const isHidden = function(node) {
44
36
  return node.nodeType === node.ELEMENT_NODE && attrs.getAttribute(node, 'hidden');
45
37
  };
46
38
 
47
- export const getChildNodes = function(node, owners) {
39
+ export const getChildNodes = function(node) {
48
40
  const childNodes = [];
41
+ let rawChildNodes = [];
42
+
43
+ if (node.shadowRoot) {
44
+ rawChildNodes = node.shadowRoot.childNodes;
45
+ } else if (node.assignedNodes) {
46
+ rawChildNodes = node.assignedNodes();
47
+ } else {
48
+ rawChildNodes = node.childNodes;
49
+ }
49
50
 
50
- for (let i = 0; i < node.childNodes.length; i++) {
51
- const child = node.childNodes[i];
52
- if (!getOwner(child, owners) && !isHidden(child)) {
51
+ for (let i = 0; i < rawChildNodes.length; i++) {
52
+ const child = rawChildNodes[i];
53
+ if (!getOwner(child) && !isHidden(child)) {
53
54
  childNodes.push(child);
54
55
  }
55
56
  }
@@ -57,9 +58,9 @@ export const getChildNodes = function(node, owners) {
57
58
  if (node.nodeType === node.ELEMENT_NODE) {
58
59
  const owns = attrs.getAttribute(node, 'owns') || [];
59
60
  for (let i = 0; i < owns.length; i++) {
60
- const child = document.getElementById(owns[i]);
61
+ const child = node.getRootNode().getElementById(owns[i]);
61
62
  // double check with getOwner for consistency
62
- if (child && getOwner(child, owners) === node && !isHidden(child)) {
63
+ if (child && getOwner(child) === node && !isHidden(child)) {
63
64
  childNodes.push(child);
64
65
  }
65
66
  }
@@ -69,12 +70,11 @@ export const getChildNodes = function(node, owners) {
69
70
  };
70
71
 
71
72
  export const walk = function(root, fn) {
72
- const owners = document.querySelectorAll('[aria-owns]');
73
73
  let queue = [root];
74
74
  while (queue.length) {
75
75
  const item = queue.shift();
76
76
  fn(item);
77
- queue = getChildNodes(item, owners).concat(queue);
77
+ queue = getChildNodes(item).concat(queue);
78
78
  }
79
79
  };
80
80
 
package/lib/name.js CHANGED
@@ -46,13 +46,17 @@ const getContent = function(root, ongoingLabelledBy, visited) {
46
46
  for (let i = 0; i < children.length; i++) {
47
47
  const node = children[i];
48
48
  if (node.nodeType === node.TEXT_NODE) {
49
- const styles = window.getComputedStyle(node.parentElement);
50
- if (styles.textTransform === 'uppercase') {
51
- ret += node.textContent.toUpperCase();
52
- } else if (styles.textTransform === 'lowercase') {
53
- ret += node.textContent.toLowerCase();
54
- } else if (styles.textTransform === 'capitalize') {
55
- ret += node.textContent.replace(/\b\w/g, c => c.toUpperCase());
49
+ if (node.parentElement) {
50
+ const styles = window.getComputedStyle(node.parentElement);
51
+ if (styles.textTransform === 'uppercase') {
52
+ ret += node.textContent.toUpperCase();
53
+ } else if (styles.textTransform === 'lowercase') {
54
+ ret += node.textContent.toLowerCase();
55
+ } else if (styles.textTransform === 'capitalize') {
56
+ ret += node.textContent.replace(/\b\w/g, c => c.toUpperCase());
57
+ } else {
58
+ ret += node.textContent;
59
+ }
56
60
  } else {
57
61
  ret += node.textContent;
58
62
  }
@@ -94,7 +98,7 @@ const getNameRaw = function(el, recursive, ongoingLabelledBy, visited, directRef
94
98
  if (!ongoingLabelledBy && el.matches('[aria-labelledby]')) {
95
99
  const ids = el.getAttribute('aria-labelledby').split(/\s+/);
96
100
  const strings = ids.map(id => {
97
- const label = document.getElementById(id);
101
+ const label = el.getRootNode().getElementById(id);
98
102
  return label ? getNameRaw(label, true, true, visited, true) : '';
99
103
  });
100
104
  ret = strings.join(' ');
@@ -205,7 +209,7 @@ export const getDescription = function(el) {
205
209
  if (el.matches('[aria-describedby]')) {
206
210
  const ids = el.getAttribute('aria-describedby').split(/\s+/);
207
211
  const strings = ids.map(id => {
208
- const label = document.getElementById(id);
212
+ const label = el.getRootNode().getElementById(id);
209
213
  return label ? getNameRaw(label, true, true) : '';
210
214
  });
211
215
  ret = strings.join(' ');
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "aria-api",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "Access ARIA information from JavaScript",
5
+ "main": "dist/aria.js",
5
6
  "module": "index.js",
6
7
  "keywords": [
7
8
  "aria",
@@ -12,9 +13,9 @@
12
13
  "license": "MIT",
13
14
  "devDependencies": {
14
15
  "expect": "^1.20.2",
15
- "mocha": "^10.2.0",
16
- "mocha-headless-chrome": "^4.0.0",
17
- "rollup": "^4.24.3"
16
+ "mocha": "^11.7.5",
17
+ "mocha-headless-chrome": "^5.1.0",
18
+ "rollup": "^4.57.1"
18
19
  },
19
20
  "files": [
20
21
  "index.js",