aria-api

access ARIA information from JavaScript
git clone https://git.ce9e.org/aria-api.git

commit
27ab3f3c4096a7a6def5e83ee7c91291f50c2f69
parent
93cef69703a8c32d1f5528f905606cbfb9681396
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2026-02-18 22:50
bump version to 0.9.0

Diffstat

M CHANGES.md 7 +++++++
M dist/aria.js 60 ++++++++++++++++++++++++++++++------------------------------
M package.json 2 +-

3 files changed, 38 insertions, 31 deletions


diff --git a/CHANGES.md b/CHANGES.md

@@ -1,3 +1,10 @@
   -1     1 0.9.0 (2026-02-18)
   -1     2 ------------------
   -1     3 
   -1     4 -	restore cjs entry point
   -1     5 -	add basic support for shadow DOM
   -1     6 
   -1     7 
    1     8 0.8.0 (2024-11-01)
    2     9 ------------------
    3    10 

diff --git a/dist/aria.js b/dist/aria.js

@@ -912,28 +912,20 @@
  912   912 		}
  913   913 	};
  914   914 
  915    -1 	const _getOwner = function(node, owners) {
   -1   915 	const _getOwner = function(node) {
  916   916 		if (node.nodeType === node.ELEMENT_NODE && node.id) {
  917    -1 			const selector = '[aria-owns~="' + CSS.escape(node.id) + '"]';
  918    -1 			if (owners) {
  919    -1 				for (const owner of owners) {
  920    -1 					if (owner.matches(selector)) {
  921    -1 						return owner;
  922    -1 					}
  923    -1 				}
  924    -1 			} else {
  925    -1 				return document.querySelector(selector);
  926    -1 			}
   -1   917 			const selector = `[aria-owns~="${CSS.escape(node.id)}"]`;
   -1   918 			return node.getRootNode().querySelector(selector);
  927   919 		}
  928   920 	};
  929   921 
  930    -1 	const _getParentNode = function(node, owners) {
  931    -1 		return _getOwner(node, owners) || node.parentNode;
   -1   922 	const _getParentNode = function(node) {
   -1   923 		return _getOwner(node) || node.parentNode || node.host;
  932   924 	};
  933   925 
  934    -1 	const detectLoop = function(node, owners) {
   -1   926 	const detectLoop = function(node) {
  935   927 		const seen = [node];
  936    -1 		while ((node = _getParentNode(node, owners))) {
   -1   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    -1 	const getOwner = function(node, owners) {
  945    -1 		const owner = _getOwner(node, owners);
  946    -1 		if (owner && !detectLoop(node, owners)) {
   -1   936 	const getOwner = function(node) {
   -1   937 		const owner = _getOwner(node);
   -1   938 		if (owner && !detectLoop(node)) {
  947   939 			return owner;
  948   940 		}
  949   941 	};
  950   942 
  951    -1 	const getParentNode = function(node, owners) {
  952    -1 		return getOwner(node, owners) || node.parentNode;
   -1   943 	const getParentNode = function(node) {
   -1   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    -1 	const getChildNodes = function(node, owners) {
   -1   951 	const getChildNodes = function(node) {
  960   952 		const childNodes = [];
   -1   953 		let rawChildNodes = [];
   -1   954 
   -1   955 		if (node.shadowRoot) {
   -1   956 			rawChildNodes = node.shadowRoot.childNodes;
   -1   957 		} else if (node.assignedNodes) {
   -1   958 			rawChildNodes = node.assignedNodes();
   -1   959 		} else {
   -1   960 			rawChildNodes = node.childNodes;
   -1   961 		}
  961   962 
  962    -1 		for (let i = 0; i < node.childNodes.length; i++) {
  963    -1 			const child = node.childNodes[i];
  964    -1 			if (!getOwner(child, owners) && !isHidden(child)) {
   -1   963 		for (let i = 0; i < rawChildNodes.length; i++) {
   -1   964 			const child = rawChildNodes[i];
   -1   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    -1 				const child = document.getElementById(owns[i]);
   -1   973 				const child = node.getRootNode().getElementById(owns[i]);
  973   974 				// double check with getOwner for consistency
  974    -1 				if (child && getOwner(child, owners) === node && !isHidden(child)) {
   -1   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    -1 		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    -1 			queue = getChildNodes(item, owners).concat(queue);
   -1   989 			queue = getChildNodes(item).concat(queue);
  990   990 		}
  991   991 	};
  992   992 
@@ -1141,7 +1141,7 @@
 1141  1141 		if (!ongoingLabelledBy && el.matches('[aria-labelledby]')) {
 1142  1142 			const ids = el.getAttribute('aria-labelledby').split(/\s+/);
 1143  1143 			const strings = ids.map(id => {
 1144    -1 				const label = document.getElementById(id);
   -1  1144 				const label = el.getRootNode().getElementById(id);
 1145  1145 				return label ? getNameRaw(label, true, true, visited, true) : '';
 1146  1146 			});
 1147  1147 			ret = strings.join(' ');
@@ -1252,7 +1252,7 @@
 1252  1252 		if (el.matches('[aria-describedby]')) {
 1253  1253 			const ids = el.getAttribute('aria-describedby').split(/\s+/);
 1254  1254 			const strings = ids.map(id => {
 1255    -1 				const label = document.getElementById(id);
   -1  1255 				const label = el.getRootNode().getElementById(id);
 1256  1256 				return label ? getNameRaw(label, true, true) : '';
 1257  1257 			});
 1258  1258 			ret = strings.join(' ');

diff --git a/package.json b/package.json

@@ -1,6 +1,6 @@
    1     1 {
    2     2   "name": "aria-api",
    3    -1   "version": "0.8.0",
   -1     3   "version": "0.9.0",
    4     4   "description": "Access ARIA information from JavaScript",
    5     5   "main": "dist/aria.js",
    6     6   "module": "index.js",