- commit
- 03b3618124f6971ddb9c252eae89ae6183bd1e69
- parent
- 5fc3becd1d2d93998edba20b18b7fa3088f0e944
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-11-01 11:57
convert to es modules
Diffstat
| M | Makefile | 2 | +- |
| M | index.js | 23 | ++++------------------- |
| M | lib/atree.js | 17 | +++++------------ |
| M | lib/attrs.js | 14 | ++++---------- |
| M | lib/constants.js | 28 | ++++++++++++++-------------- |
| M | lib/name.js | 17 | ++++++----------- |
| M | lib/query.js | 16 | ++++++---------- |
| M | package.json | 2 | +- |
8 files changed, 41 insertions, 78 deletions
diff --git a/Makefile b/Makefile
@@ -1,6 +1,6 @@ 1 1 dist/aria.js: index.js lib/*.js 2 2 mkdir -p dist3 -1 npx browserify $< -o $@ -s aria-1 3 rollup $< -o $@ -f umd -n aria 4 4 5 5 wpt-master: 6 6 wget https://github.com/web-platform-tests/wpt/archive/refs/heads/master.zip -O wpt-master.zip
diff --git a/index.js b/index.js
@@ -1,19 +1,4 @@1 -1 var query = require('./lib/query.js');2 -1 var attrs = require('./lib/attrs.js');3 -1 var name = require('./lib/name.js');4 -1 var atree = require('./lib/atree.js');5 -16 -1 module.exports = {7 -1 getRole: attrs.getRole,8 -1 getAttribute: attrs.getAttribute,9 -1 getName: name.getName,10 -1 getDescription: name.getDescription,11 -112 -1 matches: query.matches,13 -1 querySelector: query.querySelector,14 -1 querySelectorAll: query.querySelectorAll,15 -1 closest: query.closest,16 -117 -1 getParentNode: atree.getParentNode,18 -1 getChildNodes: atree.getChildNodes,19 -1 };-1 1 export { getParentNode, getChildNodes } from './lib/atree.js'; -1 2 export { getRole, getAttribute } from './lib/attrs.js'; -1 3 export { matches, querySelector, querySelectorAll, closest } from './lib/query.js'; -1 4 export { getName, getDescription } from './lib/name.js';
diff --git a/lib/atree.js b/lib/atree.js
@@ -1,4 +1,4 @@1 -1 const attrs = require('./attrs');-1 1 import * as attrs from './attrs'; 2 2 3 3 const _getOwner = function(node, owners) { 4 4 if (node.nodeType === node.ELEMENT_NODE && node.id) { @@ -36,7 +36,7 @@ const getOwner = function(node, owners) { 36 36 } 37 37 }; 38 3839 -1 const getParentNode = function(node, owners) {-1 39 export const getParentNode = function(node, owners) { 40 40 return getOwner(node, owners) || node.parentNode; 41 41 }; 42 42 @@ -44,7 +44,7 @@ const isHidden = function(node) { 44 44 return node.nodeType === node.ELEMENT_NODE && attrs.getAttribute(node, 'hidden'); 45 45 }; 46 4647 -1 const getChildNodes = function(node, owners) {-1 47 export const getChildNodes = function(node, owners) { 48 48 const childNodes = []; 49 49 50 50 for (let i = 0; i < node.childNodes.length; i++) { @@ -68,7 +68,7 @@ const getChildNodes = function(node, owners) { 68 68 return childNodes; 69 69 }; 70 7071 -1 const walk = function(root, fn) {-1 71 export const walk = function(root, fn) { 72 72 const owners = document.querySelectorAll('[aria-owns]'); 73 73 let queue = [root]; 74 74 while (queue.length) { @@ -78,7 +78,7 @@ const walk = function(root, fn) { 78 78 } 79 79 }; 80 8081 -1 const searchUp = function(node, test) {-1 81 export const searchUp = function(node, test) { 82 82 const candidate = getParentNode(node); 83 83 if (candidate) { 84 84 if (test(candidate)) { @@ -88,10 +88,3 @@ const searchUp = function(node, test) { 88 88 } 89 89 } 90 90 };91 -192 -1 module.exports = {93 -1 'getParentNode': getParentNode,94 -1 'getChildNodes': getChildNodes,95 -1 'walk': walk,96 -1 'searchUp': searchUp,97 -1 };
diff --git a/lib/attrs.js b/lib/attrs.js
@@ -1,4 +1,4 @@1 -1 const constants = require('./constants.js');-1 1 import * as constants from './constants.js'; 2 2 3 3 var unique = function(arr) { 4 4 return arr.filter((a, i) => arr.indexOf(a) === i); @@ -41,18 +41,18 @@ const getRoleRaw = function(el, candidates) { 41 41 } 42 42 }; 43 4344 -1 const getRole = function(el) {-1 44 export const getRole = function(el) { 45 45 return getRoleRaw(el); 46 46 }; 47 4748 -1 const hasRole = function(el, roles) {-1 48 export const hasRole = function(el, roles) { 49 49 const subRoles = normalizeRoles(roles, true).map(role => { 50 50 return constants.roles[role].subRoles || [role]; 51 51 }); 52 52 return !!getRoleRaw(el, unique(flatten(subRoles))); 53 53 }; 54 5455 -1 const getAttribute = function(el, key) {-1 55 export const getAttribute = function(el, key) { 56 56 if (constants.attributeStrongMapping.hasOwnProperty(key)) { 57 57 const value = el[constants.attributeStrongMapping[key]]; 58 58 if (value) { @@ -128,9 +128,3 @@ const getAttribute = function(el, key) { 128 128 return false; 129 129 } 130 130 };131 -1132 -1 module.exports = {133 -1 getRole: getRole,134 -1 hasRole: hasRole,135 -1 getAttribute: getAttribute,136 -1 };
diff --git a/lib/constants.js b/lib/constants.js
@@ -1,5 +1,5 @@ 1 1 // https://www.w3.org/TR/wai-aria/#state_prop_def2 -1 exports.attributes = {-1 2 export const attributes = { 3 3 'activedescendant': 'id', 4 4 'atomic': 'bool', 5 5 'autocomplete': 'token', @@ -55,14 +55,14 @@ exports.attributes = { 55 55 'valuetext': 'string', 56 56 }; 57 5758 -1 exports.attributeStrongMapping = {-1 58 export const attributeStrongMapping = { 59 59 'disabled': 'disabled', 60 60 'placeholder': 'placeholder', 61 61 'readonly': 'readOnly', 62 62 'required': 'required', 63 63 }; 64 6465 -1 exports.attributeWeakMapping = {-1 65 export const attributeWeakMapping = { 66 66 'checked': 'checked', 67 67 'colspan': 'colSpan', 68 68 'expanded': 'open', @@ -89,7 +89,7 @@ const svgSelectors = function(selector) { 89 89 90 90 // https://www.w3.org/TR/html-aam-1.0/#html-element-role-mappings 91 91 // https://www.w3.org/TR/wai-aria/roles92 -1 exports.roles = {-1 92 export const roles = { 93 93 alert: { 94 94 childRoles: ['alertdialog'], 95 95 defaults: { @@ -732,7 +732,7 @@ exports.roles = { 732 732 }; 733 733 734 734 const getSubRoles = function(role) {735 -1 const children = (exports.roles[role]).childRoles || [];-1 735 const children = (roles[role]).childRoles || []; 736 736 const descendents = children.map(getSubRoles); 737 737 738 738 const result = [role]; @@ -748,30 +748,30 @@ const getSubRoles = function(role) { 748 748 return result; 749 749 }; 750 750751 -1 exports.attrsWithDefaults = [];-1 751 export const attrsWithDefaults = []; 752 752753 -1 for (const role in exports.roles) {754 -1 exports.roles[role].subRoles = getSubRoles(role);755 -1 for (const key in exports.roles[role].defaults) {756 -1 if (!exports.attrsWithDefaults.includes(key)) {757 -1 exports.attrsWithDefaults.push(key);-1 753 for (const role in roles) { -1 754 roles[role].subRoles = getSubRoles(role); -1 755 for (const key in roles[role].defaults) { -1 756 if (!attrsWithDefaults.includes(key)) { -1 757 attrsWithDefaults.push(key); 758 758 } 759 759 } 760 760 } 761 761762 -1 exports.aliases = {-1 762 export const aliases = { 763 763 'presentation': 'none', 764 764 'directory': 'list', 765 765 'img': 'image', 766 766 }; 767 767768 -1 exports.nameFromDescendant = {-1 768 export const nameFromDescendant = { 769 769 'figure': 'figcaption', 770 770 'table': 'caption', 771 771 'fieldset': 'legend', 772 772 }; 773 773774 -1 exports.nameDefaults = {-1 774 export const nameDefaults = { 775 775 'input[type="submit"]': 'Submit', 776 776 'input[type="reset"]': 'Reset', 777 777 'summary': 'Details',
diff --git a/lib/name.js b/lib/name.js
@@ -1,7 +1,7 @@1 -1 const constants = require('./constants.js');2 -1 const atree = require('./atree.js');3 -1 const attrs = require('./attrs.js');4 -1 const query = require('./query.js');-1 1 import * as constants from './constants.js'; -1 2 import * as atree from './atree.js'; -1 3 import * as attrs from './attrs.js'; -1 4 import * as query from './query.js'; 5 5 6 6 const addSpaces = function(text, el, pseudoSelector) { 7 7 // https://github.com/w3c/accname/issues/3 @@ -183,14 +183,14 @@ const getNameRaw = function(el, recursive, ongoingLabelledBy, visited, directRef 183 183 return addSpaces(before + ret + after, el); 184 184 }; 185 185186 -1 const getName = function(el) {-1 186 export const getName = function(el) { 187 187 return getNameRaw(el) 188 188 .replace(/[ \n\r\t\f]+/g, ' ') 189 189 .replace(/^ /, '') 190 190 .replace(/ $/, ''); 191 191 }; 192 192193 -1 const getDescription = function(el) {-1 193 export const getDescription = function(el) { 194 194 let ret = ''; 195 195 196 196 if (el.matches('[aria-describedby]')) { @@ -222,8 +222,3 @@ const getDescription = function(el) { 222 222 223 223 return ret; 224 224 };225 -1226 -1 module.exports = {227 -1 getName: getName,228 -1 getDescription: getDescription,229 -1 };
diff --git a/lib/query.js b/lib/query.js
@@ -1,7 +1,7 @@1 -1 const attrs = require('./attrs.js');2 -1 const atree = require('./atree.js');-1 1 import * as attrs from './attrs.js'; -1 2 import * as atree from './atree.js'; 3 34 -1 const matches = function(el, selector) {-1 4 export const matches = function(el, selector) { 5 5 if (selector.substr(0, 1) === ':') { 6 6 const attr = selector.substr(1); 7 7 return attrs.getAttribute(el, attr); @@ -39,7 +39,7 @@ const _querySelector = function(all) { 39 39 }; 40 40 }; 41 4142 -1 const closest = function(el, selector) {-1 42 export const closest = function(el, selector) { 43 43 return atree.searchUp(el, candidate => { 44 44 if (candidate.nodeType === candidate.ELEMENT_NODE) { 45 45 return matches(candidate, selector); @@ -47,9 +47,5 @@ const closest = function(el, selector) { 47 47 }); 48 48 }; 49 4950 -1 module.exports = {51 -1 matches: matches,52 -1 querySelector: _querySelector(),53 -1 querySelectorAll: _querySelector(true),54 -1 closest: closest,55 -1 };-1 50 export const querySelector = _querySelector(); -1 51 export const querySelectorAll = _querySelector(true);
diff --git a/package.json b/package.json
@@ -2,7 +2,7 @@ 2 2 "name": "aria-api", 3 3 "version": "0.7.0", 4 4 "description": "Access ARIA information from JavaScript",5 -1 "main": "index.js",-1 5 "module": "index.js", 6 6 "keywords": [ 7 7 "aria", 8 8 "accessibility",