From f52f2bf21482f2bb2335a6a747214b06d48e72d9 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 27 Nov 2023 17:31:39 +0100
Subject: [PATCH 01/93] feat: add test.sh
A simplistic test to test aria.js output.
Runs respec before and after copying aria.js changes.
NOTE: Assumes there's a copy of w3c/aria in ../aria/
---
test.sh | 14 ++++++++++++++
1 file changed, 14 insertions(+)
create mode 100644 test.sh
diff --git a/test.sh b/test.sh
new file mode 100644
index 0000000..6531754
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+# NOTE: Assumes there's a copy of w3c/aria in ../aria/
+
+echo "Run respec on ../aria/index.html to generate 'before.html'"
+npx respec --src ../aria/index.html --out before.html
+echo "Copy ./script/aria.js to ../aria/common/script/"
+cp ./script/aria.js ../aria/common/script/.
+echo "Run respec on ../aria/index.html to generate 'after.html'"
+npx respec --src ../aria/index.html --out after.html
+echo "Run diff on 'before.html' and 'after.html'"
+diff before.html after.html
+echo "Clean up aria spec"
+git -C ../aria/ checkout ./common/script/aria.js
From 110b6cf30cfd277b11bcbbd8992dad2932fc2919 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 27 Nov 2023 20:24:55 +0100
Subject: [PATCH 02/93] refactor(aria.js): var => const/let
A simplistic first step.
Running test.sh was clean.
---
script/aria.js | 208 ++++++++++++++++++++++++-------------------------
1 file changed, 104 insertions(+), 104 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 67d6a62..b0242ac 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -7,14 +7,14 @@
* localprops: local properties and states
*/
-var roleInfo = {};
+const roleInfo = {};
function ariaAttributeReferences() {
- var propList = {};
- var globalSP = [];
+ const propList = {};
+ const globalSP = [];
- var skipIndex = 0;
- var myURL = document.URL;
+ let skipIndex = 0;
+ const myURL = document.URL;
if (myURL.match(/\?fast/)) {
skipIndex = 1;
}
@@ -24,11 +24,11 @@ function ariaAttributeReferences() {
Array.prototype.slice
.call(document.querySelectorAll("pdef, sdef"))
.forEach(function (item) {
- var type = item.localName === "pdef" ? "property" : "state";
- var container = item.parentNode;
- var content = item.innerHTML;
- var sp = document.createElement("span");
- var title = item.getAttribute("title");
+ const type = item.localName === "pdef" ? "property" : "state";
+ const container = item.parentNode;
+ const content = item.innerHTML;
+ const sp = document.createElement("span");
+ let title = item.getAttribute("title");
if (!title) {
title = content;
}
@@ -41,11 +41,11 @@ function ariaAttributeReferences() {
type +
"";
sp.setAttribute("aria-describedby", "desc-" + title);
- var dRef = item.nextElementSibling;
- var desc = cloneWithoutIds(dRef.firstElementChild).innerHTML;
+ const dRef = item.nextElementSibling;
+ const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML;
dRef.id = "desc-" + title;
dRef.setAttribute("role", "definition");
- var heading = document.createElement("h4");
+ const heading = document.createElement("h4");
heading.appendChild(sp);
container.replaceChild(heading, item);
// add this item to the index
@@ -56,7 +56,7 @@ function ariaAttributeReferences() {
desc: desc,
roles: [],
};
- var abstract = container.querySelector(
+ const abstract = container.querySelector(
"." + type + "-applicability"
);
if (
@@ -100,14 +100,14 @@ function ariaAttributeReferences() {
if (container.nodeName.toLowerCase() == "div") {
// change the enclosing DIV to a section with notoc
- var sec = document.createElement("section");
+ const sec = document.createElement("section");
Array.prototype.slice
.call(container.attributes)
.forEach(function (attr) {
sec.setAttribute(attr.name, attr.value);
});
sec.classList.add("notoc");
- var theContents = container.innerHTML;
+ const theContents = container.innerHTML;
sec.innerHTML = theContents;
container.parentNode.replaceChild(sec, container);
}
@@ -116,16 +116,16 @@ function ariaAttributeReferences() {
if (!skipIndex) {
// we have all the properties and states - spit out the
// index
- var propIndex = "";
- var sortedList = [];
+ let propIndex = "";
+ let sortedList = [];
Object.keys(propList).forEach(function (key) {
sortedList.push(key);
});
sortedList = sortedList.sort();
- for (var i = 0; i < sortedList.length; i++) {
- var item = propList[sortedList[i]];
+ for (let i = 0; i < sortedList.length; i++) {
+ const item = propList[sortedList[i]];
propIndex +=
'\n";
propIndex += "" + item.desc + "\n";
}
- var node = document.getElementById("index_state_prop");
- var parentNode = node.parentNode;
- var l = document.createElement("dl");
+ let node = document.getElementById("index_state_prop");
+ parentNode = node.parentNode;
+ let l = document.createElement("dl");
l.id = "index_state_prop";
l.className = "compact";
l.innerHTML = propIndex;
parentNode.replaceChild(l, node);
- var globalSPIndex = "";
+ let globalSPIndex = "";
sortedList = globalSP.sort(function (a, b) {
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
});
for (i = 0; i < sortedList.length; i++) {
- var lItem = sortedList[i];
+ const lItem = sortedList[i];
globalSPIndex += "";
if (lItem.is === "state") {
globalSPIndex +=
@@ -213,32 +213,32 @@ function ariaAttributeReferences() {
// 4. grab any local states and properties so we can hand those down to the children
//
- var subRoles = [];
- var roleIndex = "";
- var fromAuthor = "";
- var fromHeading = "";
- var fromContent = "";
- var fromProhibited = "";
+ const subRoles = [];
+ let roleIndex = "";
+ let fromAuthor = "";
+ let fromHeading = "";
+ let fromContent = "";
+ let fromProhibited = "";
Array.prototype.slice
.call(document.querySelectorAll("rdef"))
.forEach(function (item) {
- var container = item.parentNode;
- var content = item.innerHTML;
- var sp = document.createElement("h4");
- var title = item.getAttribute("title");
+ const container = item.parentNode;
+ const content = item.innerHTML;
+ const sp = document.createElement("h4");
+ let title = item.getAttribute("title");
if (!title) {
title = content;
}
- var pnID = title;
+ const pnID = title;
container.id = pnID;
sp.className = "role-name";
sp.title = title;
// is this a role or an abstract role
- var type = "role";
- var isAbstract = false;
- var abstract = container.querySelectorAll(".role-abstract");
+ let type = "role";
+ let isAbstract = false;
+ const abstract = container.querySelectorAll(".role-abstract");
if (abstract.innerText === "True") {
type = "abstract role";
isAbstract = true;
@@ -251,8 +251,8 @@ function ariaAttributeReferences() {
"";
// sp.id = title;
sp.setAttribute("aria-describedby", "desc-" + title);
- var dRef = item.nextElementSibling;
- var desc = cloneWithoutIds(dRef.firstElementChild).innerHTML;
+ const dRef = item.nextElementSibling;
+ const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML;
dRef.id = "desc-" + title;
dRef.setAttribute("role", "definition");
container.replaceChild(sp, item);
@@ -267,12 +267,12 @@ function ariaAttributeReferences() {
roleIndex += "" + desc + "\n";
// grab info about this role
// do we have a parent class? if so, put us in that parents list
- var node = Array.prototype.slice.call(
+ const node = Array.prototype.slice.call(
container.querySelectorAll(".role-parent rref")
);
// s will hold the name of the parent role if any
- var s = null;
- var parentRoles = [];
+ let s = null;
+ const parentRoles = [];
if (node.length) {
node.forEach(function (roleref) {
s = roleref.textContent || roleref.innerText;
@@ -286,7 +286,7 @@ function ariaAttributeReferences() {
});
}
// are there supported states / properties in this role?
- var attrs = [];
+ const attrs = [];
Array.prototype.slice
.call(
container.querySelectorAll(
@@ -303,20 +303,20 @@ function ariaAttributeReferences() {
Array.prototype.slice
.call(node.querySelectorAll("pref,sref"))
.forEach(function (item) {
- var name = item.getAttribute("title");
+ let name = item.getAttribute("title");
if (!name) {
name = item.textContent || item.innerText;
}
- var type =
+ const type =
item.localName === "pref"
? "property"
: "state";
- var req = node.classList.contains(
+ const req = node.classList.contains(
"role-required-properties"
);
- var dis =
+ const dis =
node.classList.contains("role-disallowed");
- var dep = item.hasAttribute("data-deprecated");
+ const dep = item.hasAttribute("data-deprecated");
attrs.push({
is: type,
name: name,
@@ -344,9 +344,9 @@ function ariaAttributeReferences() {
Array.prototype.slice
.call(container.querySelectorAll(".role-namefrom"))
.forEach(function (node) {
- var reqRef =
+ const reqRef =
container.querySelector(".role-namerequired");
- var req = "";
+ let req = "";
if (reqRef && reqRef.innerText === "True") {
req = " (name required)";
}
@@ -398,7 +398,7 @@ function ariaAttributeReferences() {
}
if (container.nodeName.toLowerCase() == "div") {
// change the enclosing DIV to a section with notoc
- var sec = document.createElement("section");
+ const sec = document.createElement("section");
Array.prototype.slice
.call(container.attributes)
.forEach(function (attr) {
@@ -406,24 +406,24 @@ function ariaAttributeReferences() {
});
sec.classList.add("notoc");
- var theContents = container.innerHTML;
+ const theContents = container.innerHTML;
sec.innerHTML = theContents;
container.parentNode.replaceChild(sec, container);
}
});
- var getStates = function (role) {
- var ref = roleInfo[role];
+ const getStates = function (role) {
+ const ref = roleInfo[role];
if (!ref) {
msg.pub("error", "No role definition for " + role);
} else if (ref.allprops) {
return ref.allprops;
} else {
- var myList = ref.localprops;
+ let myList = ref.localprops;
Array.prototype.slice
.call(ref.parentRoles)
.forEach(function (item) {
- var pList = getStates(item);
+ const pList = getStates(item);
myList = myList.concat(pList);
});
ref.allprops = myList;
@@ -436,20 +436,20 @@ function ariaAttributeReferences() {
// build up the complete inherited SP lists for each role
// however, if the role already specifies an item, do not include it
Object.entries(roleInfo).forEach(function (index) {
- var item = index[1];
- var output = "";
- var placeholder = document.querySelector(
+ const item = index[1];
+ let output = "";
+ const placeholder = document.querySelector(
"#" + item.fragID + " .role-inherited"
);
if (placeholder) {
- var myList = [];
+ let myList = [];
item.parentRoles.forEach(function (role) {
myList = myList.concat(getStates(role));
});
// strip out any items that we have locally
if (item.localprops.length && myList.length) {
- for (var j = myList.length - 1; j >= 0; j--) {
+ for (let j = myList.length - 1; j >= 0; j--) {
item.localprops.forEach(function (x) {
if (x.name == myList[j].name) {
myList.splice(j, 1);
@@ -458,13 +458,13 @@ function ariaAttributeReferences() {
}
}
- var reducedList = myList.reduce((uniqueList, item) => {
+ const reducedList = myList.reduce((uniqueList, item) => {
return uniqueList.includes(item)
? uniqueList
: [...uniqueList, item];
}, []);
- var sortedList = reducedList.sort((a, b) => {
+ const sortedList = reducedList.sort((a, b) => {
if (a.name == b.name) {
// Ensure deprecated false properties occur first
if (a.deprecated !== b.deprecated) {
@@ -474,11 +474,11 @@ function ariaAttributeReferences() {
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
}, []);
- var prev;
- for (var k = 0; k < sortedList.length; k++) {
- var property = sortedList[k];
- var req = "";
- var dep = "";
+ let prev;
+ for (let k = 0; k < sortedList.length; k++) {
+ const property = sortedList[k];
+ let req = "";
+ let dep = "";
if (property.required) {
req = " (required)";
}
@@ -515,15 +515,15 @@ function ariaAttributeReferences() {
});
// Update state and property role references
- var getAllSubRoles = function (role) {
- var ref = subRoles[role];
+ const getAllSubRoles = function (role) {
+ const ref = subRoles[role];
if (ref && ref.length) {
- var myList = [];
+ let myList = [];
ref.forEach(function (item) {
if (!myList.item) {
myList[item] = 1;
myList.push(item);
- var childList = getAllSubRoles(item);
+ const childList = getAllSubRoles(item);
myList = myList.concat(childList);
}
});
@@ -534,10 +534,10 @@ function ariaAttributeReferences() {
};
Object.entries(propList).forEach(function (index) {
- var output = "";
- var item = index[1];
- var section = document.querySelector("#" + item.name);
- var placeholder = section.querySelector(
+ let output = "";
+ const item = index[1];
+ const section = document.querySelector("#" + item.name);
+ let placeholder = section.querySelector(
".state-applicability, .property-applicability"
);
if (
@@ -547,9 +547,9 @@ function ariaAttributeReferences() {
item.roles.length
) {
// update the used in roles list
- var sortedList = [];
+ let sortedList = [];
sortedList = item.roles.sort();
- for (var j = 0; j < sortedList.length; j++) {
+ for (let j = 0; j < sortedList.length; j++) {
output += "" + sortedList[j] + "\n";
}
if (output !== "") {
@@ -557,9 +557,9 @@ function ariaAttributeReferences() {
}
placeholder.innerHTML = output;
// also update any inherited roles
- var myList = [];
+ let myList = [];
item.roles.forEach(function (role) {
- var children = getAllSubRoles(role);
+ let children = getAllSubRoles(role);
// Some subroles have required properties which are also required by the superclass.
// Example: The checked state of radio, which is also required by superclass checkbox.
// We only want to include these one time, so filter out the subroles.
@@ -576,8 +576,8 @@ function ariaAttributeReferences() {
if (placeholder && myList.length) {
sortedList = myList.sort();
output = "";
- var last = "";
- for (j = 0; j < sortedList.length; j++) {
+ let last = "";
+ for (let j = 0; j < sortedList.length; j++) {
var sItem = sortedList[j];
if (last != sItem) {
output += "" + sItem + "\n";
@@ -596,7 +596,7 @@ function ariaAttributeReferences() {
item.roles.length
) {
// update the used in roles list
- var sortedList = [];
+ let sortedList = [];
sortedList = item.roles.sort();
//remove roletype from the sorted list
const index = sortedList.indexOf("roletype");
@@ -604,7 +604,7 @@ function ariaAttributeReferences() {
sortedList.splice(index, 1);
}
- for (var j = 0; j < sortedList.length; j++) {
+ for (let j = 0; j < sortedList.length; j++) {
output += "" + sortedList[j] + "\n";
}
if (output !== "") {
@@ -612,9 +612,9 @@ function ariaAttributeReferences() {
}
placeholder.innerHTML = output;
// also update any inherited roles
- var myList = [];
+ let myList = [];
item.roles.forEach(function (role) {
- var children = getAllSubRoles(role);
+ let children = getAllSubRoles(role);
// Some subroles have required properties which are also required by the superclass.
// Example: The checked state of radio, which is also required by superclass checkbox.
// We only want to include these one time, so filter out the subroles.
@@ -629,11 +629,11 @@ function ariaAttributeReferences() {
".state-descendants, .property-descendants"
);
if (placeholder && myList.length) {
- sortedList = myList.sort();
- output = "";
- var last = "";
+ let sortedList = myList.sort();
+ let output = "";
+ let last = "";
for (j = 0; j < sortedList.length; j++) {
- var sItem = sortedList[j];
+ const sItem = sortedList[j];
if (last != sItem) {
output += "" + sItem + "\n";
last = sItem;
@@ -651,7 +651,7 @@ function ariaAttributeReferences() {
item.roles.length
) {
// for prohibited roles the roles list just includes those roles which are prohibited... weird I know but it is what it is
- var sortedList = [];
+ let sortedList = [];
sortedList = item.roles.sort();
//remove roletype from the sorted list
const index = sortedList.indexOf("roletype");
@@ -660,7 +660,7 @@ function ariaAttributeReferences() {
}
output +=
"All elements of the base markup except for the following roles: ";
- for (var j = 0; j < sortedList.length - 1; j++) {
+ for (let j = 0; j < sortedList.length - 1; j++) {
output += "" + sortedList[j] + ", ";
}
output +=
@@ -670,9 +670,9 @@ function ariaAttributeReferences() {
});
// spit out the index
- var node = document.getElementById("index_role");
- var parentNode = node.parentNode;
- var list = document.createElement("dl");
+ let node = document.getElementById("index_role");
+ let parentNode = node.parentNode;
+ let list = document.createElement("dl");
list.id = "index_role";
list.className = "compact";
list.innerHTML = roleIndex;
@@ -719,20 +719,20 @@ function ariaAttributeReferences() {
parentNode.replaceChild(list, node);
}
// assuming we found some parent roles, update those parents with their children
- for (var i = 0; i < subRoles.length; i++) {
- var item = subRoles[subRoles[i]];
- var sortedList = item.sort(function (a, b) {
+ for (let i = 0; i < subRoles.length; i++) {
+ const item = subRoles[subRoles[i]];
+ const sortedList = item.sort(function (a, b) {
return a < b ? -1 : a > b ? 1 : 0;
});
- var output = "\n";
- for (var j = 0; j < sortedList.length; j++) {
+ let output = "\n";
+ for (let j = 0; j < sortedList.length; j++) {
output += "- " + sortedList[j] + "
\n";
}
output += "
\n";
// put it somewhere
- var subRolesContainer = document.querySelector("#" + subRoles[i]);
+ const subRolesContainer = document.querySelector("#" + subRoles[i]);
if (subRolesContainer) {
- var subRolesListContainer =
+ const subRolesListContainer =
subRolesContainer.querySelector(".role-children");
if (subRolesListContainer) {
subRolesListContainer.innerHTML = output;
From de585f05f5671fb6929fd73009038385ead1cd23 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 27 Nov 2023 20:50:20 +0100
Subject: [PATCH 03/93] refactor(aria.js): replace Array.prototype.slice
test.sh run was 'clean'.
---
script/aria.js | 35 ++++++++++-------------------------
1 file changed, 10 insertions(+), 25 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index b0242ac..8fcd184 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -21,8 +21,7 @@ function ariaAttributeReferences() {
// process the document before anything else is done
// first get the properties
- Array.prototype.slice
- .call(document.querySelectorAll("pdef, sdef"))
+ document.querySelectorAll("pdef, sdef")
.forEach(function (item) {
const type = item.localName === "pdef" ? "property" : "state";
const container = item.parentNode;
@@ -101,8 +100,7 @@ function ariaAttributeReferences() {
if (container.nodeName.toLowerCase() == "div") {
// change the enclosing DIV to a section with notoc
const sec = document.createElement("section");
- Array.prototype.slice
- .call(container.attributes)
+ [...container.attributes]
.forEach(function (attr) {
sec.setAttribute(attr.name, attr.value);
});
@@ -220,8 +218,7 @@ function ariaAttributeReferences() {
let fromContent = "";
let fromProhibited = "";
- Array.prototype.slice
- .call(document.querySelectorAll("rdef"))
+ document.querySelectorAll("rdef")
.forEach(function (item) {
const container = item.parentNode;
const content = item.innerHTML;
@@ -267,9 +264,7 @@ function ariaAttributeReferences() {
roleIndex += "- " + desc + "
\n";
// grab info about this role
// do we have a parent class? if so, put us in that parents list
- const node = Array.prototype.slice.call(
- container.querySelectorAll(".role-parent rref")
- );
+ const node = container.querySelectorAll(".role-parent rref");
// s will hold the name of the parent role if any
let s = null;
const parentRoles = [];
@@ -287,11 +282,8 @@ function ariaAttributeReferences() {
}
// are there supported states / properties in this role?
const attrs = [];
- Array.prototype.slice
- .call(
- container.querySelectorAll(
+ container.querySelectorAll(
".role-properties, .role-required-properties, .role-disallowed"
- )
)
.forEach(function (node) {
if (
@@ -300,8 +292,7 @@ function ariaAttributeReferences() {
(node.innerText && node.innerText.length !== 1))
) {
// looks like we do
- Array.prototype.slice
- .call(node.querySelectorAll("pref,sref"))
+ node.querySelectorAll("pref,sref")
.forEach(function (item) {
let name = item.getAttribute("title");
if (!name) {
@@ -341,8 +332,7 @@ function ariaAttributeReferences() {
// is there a namefrom indication? If so, add this one to
// the list
if (!isAbstract) {
- Array.prototype.slice
- .call(container.querySelectorAll(".role-namefrom"))
+ container.querySelectorAll(".role-namefrom")
.forEach(function (node) {
const reqRef =
container.querySelector(".role-namerequired");
@@ -399,8 +389,7 @@ function ariaAttributeReferences() {
if (container.nodeName.toLowerCase() == "div") {
// change the enclosing DIV to a section with notoc
const sec = document.createElement("section");
- Array.prototype.slice
- .call(container.attributes)
+ [...container.attributes]
.forEach(function (attr) {
sec.setAttribute(attr.name, attr.value);
});
@@ -420,8 +409,7 @@ function ariaAttributeReferences() {
return ref.allprops;
} else {
let myList = ref.localprops;
- Array.prototype.slice
- .call(ref.parentRoles)
+ ref.parentRoles
.forEach(function (item) {
const pList = getStates(item);
myList = myList.concat(pList);
@@ -742,11 +730,8 @@ function ariaAttributeReferences() {
}
// prune out unused rows throughout the document
- Array.prototype.slice
- .call(
- document.querySelectorAll(
+ document.querySelectorAll(
".role-abstract, .role-parent, .role-base, .role-related, .role-scope, .role-mustcontain, .role-required-properties, .role-properties, .role-namefrom, .role-namerequired, .role-namerequired-inherited, .role-childpresentational, .role-presentational-inherited, .state-related, .property-related,.role-inherited, .role-children, .property-descendants, .state-descendants, .implicit-values"
- )
)
.forEach(function (item) {
var content = item.innerText;
From 4a2985f72d8adcdfbd72f9652ca3c4b0161dc7f9 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 27 Nov 2023 20:54:39 +0100
Subject: [PATCH 04/93] chore(aria.js): formatting
---
script/aria.js | 526 ++++++++++++++++++++++++-------------------------
1 file changed, 259 insertions(+), 267 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 8fcd184..558a9d5 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -21,95 +21,91 @@ function ariaAttributeReferences() {
// process the document before anything else is done
// first get the properties
- document.querySelectorAll("pdef, sdef")
- .forEach(function (item) {
- const type = item.localName === "pdef" ? "property" : "state";
- const container = item.parentNode;
- const content = item.innerHTML;
- const sp = document.createElement("span");
- let title = item.getAttribute("title");
- if (!title) {
- title = content;
- }
- sp.className = type + "-name";
- sp.title = title;
- sp.innerHTML =
- "" +
- content +
- '
' +
- type +
- "";
- sp.setAttribute("aria-describedby", "desc-" + title);
- const dRef = item.nextElementSibling;
- const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML;
- dRef.id = "desc-" + title;
- dRef.setAttribute("role", "definition");
- const heading = document.createElement("h4");
- heading.appendChild(sp);
- container.replaceChild(heading, item);
- // add this item to the index
- propList[title] = {
+ document.querySelectorAll("pdef, sdef").forEach(function (item) {
+ const type = item.localName === "pdef" ? "property" : "state";
+ const container = item.parentNode;
+ const content = item.innerHTML;
+ const sp = document.createElement("span");
+ let title = item.getAttribute("title");
+ if (!title) {
+ title = content;
+ }
+ sp.className = type + "-name";
+ sp.title = title;
+ sp.innerHTML =
+ "" +
+ content +
+ '
' +
+ type +
+ "";
+ sp.setAttribute("aria-describedby", "desc-" + title);
+ const dRef = item.nextElementSibling;
+ const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML;
+ dRef.id = "desc-" + title;
+ dRef.setAttribute("role", "definition");
+ const heading = document.createElement("h4");
+ heading.appendChild(sp);
+ container.replaceChild(heading, item);
+ // add this item to the index
+ propList[title] = {
+ is: type,
+ title: title,
+ name: content,
+ desc: desc,
+ roles: [],
+ };
+ const abstract = container.querySelector("." + type + "-applicability");
+ if (
+ (abstract.textContent || abstract.innerText) ===
+ "All elements of the base markup"
+ ) {
+ globalSP.push({
is: type,
title: title,
name: content,
desc: desc,
- roles: [],
- };
- const abstract = container.querySelector(
- "." + type + "-applicability"
- );
- if (
- (abstract.textContent || abstract.innerText) ===
- "All elements of the base markup"
- ) {
- globalSP.push({
- is: type,
- title: title,
- name: content,
- desc: desc,
- prohibited: false,
- deprecated: false,
- });
- } else if (
- (abstract.textContent || abstract.innerText) ===
- "All elements of the base markup except for some roles or elements that prohibit its use"
- ) {
- globalSP.push({
- is: type,
- title: title,
- name: content,
- desc: desc,
- prohibited: true,
- deprecated: false,
- });
- } else if (
- (abstract.textContent || abstract.innerText) ===
- "Use as a global deprecated in ARIA 1.2"
- ) {
- globalSP.push({
- is: type,
- title: title,
- name: content,
- desc: desc,
- prohibited: false,
- deprecated: true,
- });
- }
- // the rdef is gone. if we are in a div, convert that div to a section
-
- if (container.nodeName.toLowerCase() == "div") {
- // change the enclosing DIV to a section with notoc
- const sec = document.createElement("section");
- [...container.attributes]
- .forEach(function (attr) {
- sec.setAttribute(attr.name, attr.value);
- });
- sec.classList.add("notoc");
- const theContents = container.innerHTML;
- sec.innerHTML = theContents;
- container.parentNode.replaceChild(sec, container);
- }
- });
+ prohibited: false,
+ deprecated: false,
+ });
+ } else if (
+ (abstract.textContent || abstract.innerText) ===
+ "All elements of the base markup except for some roles or elements that prohibit its use"
+ ) {
+ globalSP.push({
+ is: type,
+ title: title,
+ name: content,
+ desc: desc,
+ prohibited: true,
+ deprecated: false,
+ });
+ } else if (
+ (abstract.textContent || abstract.innerText) ===
+ "Use as a global deprecated in ARIA 1.2"
+ ) {
+ globalSP.push({
+ is: type,
+ title: title,
+ name: content,
+ desc: desc,
+ prohibited: false,
+ deprecated: true,
+ });
+ }
+ // the rdef is gone. if we are in a div, convert that div to a section
+
+ if (container.nodeName.toLowerCase() == "div") {
+ // change the enclosing DIV to a section with notoc
+ const sec = document.createElement("section");
+ [...container.attributes].forEach(function (attr) {
+ sec.setAttribute(attr.name, attr.value);
+ });
+ sec.classList.add("notoc");
+ const theContents = container.innerHTML;
+ sec.innerHTML = theContents;
+ container.parentNode.replaceChild(sec, container);
+ }
+ });
if (!skipIndex) {
// we have all the properties and states - spit out the
@@ -218,188 +214,184 @@ function ariaAttributeReferences() {
let fromContent = "";
let fromProhibited = "";
- document.querySelectorAll("rdef")
- .forEach(function (item) {
- const container = item.parentNode;
- const content = item.innerHTML;
- const sp = document.createElement("h4");
- let title = item.getAttribute("title");
- if (!title) {
- title = content;
- }
+ document.querySelectorAll("rdef").forEach(function (item) {
+ const container = item.parentNode;
+ const content = item.innerHTML;
+ const sp = document.createElement("h4");
+ let title = item.getAttribute("title");
+ if (!title) {
+ title = content;
+ }
- const pnID = title;
- container.id = pnID;
- sp.className = "role-name";
- sp.title = title;
- // is this a role or an abstract role
- let type = "role";
- let isAbstract = false;
- const abstract = container.querySelectorAll(".role-abstract");
- if (abstract.innerText === "True") {
- type = "abstract role";
- isAbstract = true;
- }
- sp.innerHTML =
- "" +
- content +
- '
' +
- type +
- "";
- // sp.id = title;
- sp.setAttribute("aria-describedby", "desc-" + title);
- const dRef = item.nextElementSibling;
- const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML;
- dRef.id = "desc-" + title;
- dRef.setAttribute("role", "definition");
- container.replaceChild(sp, item);
- roleIndex +=
- '' +
- content +
- "
" +
- (isAbstract ? " (abstract role) " : "") +
- " \n";
- roleIndex += "- " + desc + "
\n";
- // grab info about this role
- // do we have a parent class? if so, put us in that parents list
- const node = container.querySelectorAll(".role-parent rref");
- // s will hold the name of the parent role if any
- let s = null;
- const parentRoles = [];
- if (node.length) {
- node.forEach(function (roleref) {
- s = roleref.textContent || roleref.innerText;
-
- if (!subRoles[s]) {
- subRoles.push(s);
- subRoles[s] = [];
- }
- subRoles[s].push(title);
- parentRoles.push(s);
- });
- }
- // are there supported states / properties in this role?
- const attrs = [];
- container.querySelectorAll(
- ".role-properties, .role-required-properties, .role-disallowed"
- )
+ const pnID = title;
+ container.id = pnID;
+ sp.className = "role-name";
+ sp.title = title;
+ // is this a role or an abstract role
+ let type = "role";
+ let isAbstract = false;
+ const abstract = container.querySelectorAll(".role-abstract");
+ if (abstract.innerText === "True") {
+ type = "abstract role";
+ isAbstract = true;
+ }
+ sp.innerHTML =
+ "" +
+ content +
+ '
' +
+ type +
+ "";
+ // sp.id = title;
+ sp.setAttribute("aria-describedby", "desc-" + title);
+ const dRef = item.nextElementSibling;
+ const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML;
+ dRef.id = "desc-" + title;
+ dRef.setAttribute("role", "definition");
+ container.replaceChild(sp, item);
+ roleIndex +=
+ '' +
+ content +
+ "
" +
+ (isAbstract ? " (abstract role) " : "") +
+ " \n";
+ roleIndex += "- " + desc + "
\n";
+ // grab info about this role
+ // do we have a parent class? if so, put us in that parents list
+ const node = container.querySelectorAll(".role-parent rref");
+ // s will hold the name of the parent role if any
+ let s = null;
+ const parentRoles = [];
+ if (node.length) {
+ node.forEach(function (roleref) {
+ s = roleref.textContent || roleref.innerText;
+
+ if (!subRoles[s]) {
+ subRoles.push(s);
+ subRoles[s] = [];
+ }
+ subRoles[s].push(title);
+ parentRoles.push(s);
+ });
+ }
+ // are there supported states / properties in this role?
+ const attrs = [];
+ container
+ .querySelectorAll(
+ ".role-properties, .role-required-properties, .role-disallowed"
+ )
+ .forEach(function (node) {
+ if (
+ node &&
+ ((node.textContent && node.textContent.length !== 1) ||
+ (node.innerText && node.innerText.length !== 1))
+ ) {
+ // looks like we do
+ node.querySelectorAll("pref,sref").forEach(function (item) {
+ let name = item.getAttribute("title");
+ if (!name) {
+ name = item.textContent || item.innerText;
+ }
+ const type =
+ item.localName === "pref" ? "property" : "state";
+ const req = node.classList.contains(
+ "role-required-properties"
+ );
+ const dis = node.classList.contains("role-disallowed");
+ const dep = item.hasAttribute("data-deprecated");
+ attrs.push({
+ is: type,
+ name: name,
+ required: req,
+ disallowed: dis,
+ deprecated: dep,
+ });
+
+ // remember that the state or property is
+ // referenced by this role
+ propList[name].roles.push(title);
+ });
+ }
+ });
+ roleInfo[title] = {
+ name: title,
+ fragID: pnID,
+ parentRoles: parentRoles,
+ localprops: attrs,
+ };
+
+ // is there a namefrom indication? If so, add this one to
+ // the list
+ if (!isAbstract) {
+ container
+ .querySelectorAll(".role-namefrom")
.forEach(function (node) {
+ const reqRef =
+ container.querySelector(".role-namerequired");
+ let req = "";
+ if (reqRef && reqRef.innerText === "True") {
+ req = " (name required)";
+ }
+
+ if (node.textContent.indexOf("author") !== -1) {
+ fromAuthor +=
+ '' +
+ content +
+ "
" +
+ req +
+ " ";
+ }
+ if (node.textContent.indexOf("heading") !== -1) {
+ fromHeading +=
+ '' +
+ content +
+ "
" +
+ req +
+ " ";
+ }
if (
- node &&
- ((node.textContent && node.textContent.length !== 1) ||
- (node.innerText && node.innerText.length !== 1))
+ !isAbstract &&
+ node.textContent.indexOf("content") !== -1
) {
- // looks like we do
- node.querySelectorAll("pref,sref")
- .forEach(function (item) {
- let name = item.getAttribute("title");
- if (!name) {
- name = item.textContent || item.innerText;
- }
- const type =
- item.localName === "pref"
- ? "property"
- : "state";
- const req = node.classList.contains(
- "role-required-properties"
- );
- const dis =
- node.classList.contains("role-disallowed");
- const dep = item.hasAttribute("data-deprecated");
- attrs.push({
- is: type,
- name: name,
- required: req,
- disallowed: dis,
- deprecated: dep,
- });
-
- // remember that the state or property is
- // referenced by this role
- propList[name].roles.push(title);
- });
+ fromContent +=
+ '' +
+ content +
+ "
" +
+ req +
+ " ";
+ }
+ if (node.textContent.indexOf("prohibited") !== -1) {
+ fromProhibited +=
+ '' +
+ content +
+ "
" +
+ req +
+ " ";
}
});
- roleInfo[title] = {
- name: title,
- fragID: pnID,
- parentRoles: parentRoles,
- localprops: attrs,
- };
-
- // is there a namefrom indication? If so, add this one to
- // the list
- if (!isAbstract) {
- container.querySelectorAll(".role-namefrom")
- .forEach(function (node) {
- const reqRef =
- container.querySelector(".role-namerequired");
- let req = "";
- if (reqRef && reqRef.innerText === "True") {
- req = " (name required)";
- }
-
- if (node.textContent.indexOf("author") !== -1) {
- fromAuthor +=
- '' +
- content +
- "
" +
- req +
- " ";
- }
- if (node.textContent.indexOf("heading") !== -1) {
- fromHeading +=
- '' +
- content +
- "
" +
- req +
- " ";
- }
- if (
- !isAbstract &&
- node.textContent.indexOf("content") !== -1
- ) {
- fromContent +=
- '' +
- content +
- "
" +
- req +
- " ";
- }
- if (node.textContent.indexOf("prohibited") !== -1) {
- fromProhibited +=
- '' +
- content +
- "
" +
- req +
- " ";
- }
- });
- }
- if (container.nodeName.toLowerCase() == "div") {
- // change the enclosing DIV to a section with notoc
- const sec = document.createElement("section");
- [...container.attributes]
- .forEach(function (attr) {
- sec.setAttribute(attr.name, attr.value);
- });
+ }
+ if (container.nodeName.toLowerCase() == "div") {
+ // change the enclosing DIV to a section with notoc
+ const sec = document.createElement("section");
+ [...container.attributes].forEach(function (attr) {
+ sec.setAttribute(attr.name, attr.value);
+ });
- sec.classList.add("notoc");
- const theContents = container.innerHTML;
- sec.innerHTML = theContents;
- container.parentNode.replaceChild(sec, container);
- }
- });
+ sec.classList.add("notoc");
+ const theContents = container.innerHTML;
+ sec.innerHTML = theContents;
+ container.parentNode.replaceChild(sec, container);
+ }
+ });
const getStates = function (role) {
const ref = roleInfo[role];
@@ -409,11 +401,10 @@ function ariaAttributeReferences() {
return ref.allprops;
} else {
let myList = ref.localprops;
- ref.parentRoles
- .forEach(function (item) {
- const pList = getStates(item);
- myList = myList.concat(pList);
- });
+ ref.parentRoles.forEach(function (item) {
+ const pList = getStates(item);
+ myList = myList.concat(pList);
+ });
ref.allprops = myList;
return myList;
}
@@ -730,8 +721,9 @@ function ariaAttributeReferences() {
}
// prune out unused rows throughout the document
- document.querySelectorAll(
- ".role-abstract, .role-parent, .role-base, .role-related, .role-scope, .role-mustcontain, .role-required-properties, .role-properties, .role-namefrom, .role-namerequired, .role-namerequired-inherited, .role-childpresentational, .role-presentational-inherited, .state-related, .property-related,.role-inherited, .role-children, .property-descendants, .state-descendants, .implicit-values"
+ document
+ .querySelectorAll(
+ ".role-abstract, .role-parent, .role-base, .role-related, .role-scope, .role-mustcontain, .role-required-properties, .role-properties, .role-namefrom, .role-namerequired, .role-namerequired-inherited, .role-childpresentational, .role-presentational-inherited, .state-related, .property-related,.role-inherited, .role-children, .property-descendants, .state-descendants, .implicit-values"
)
.forEach(function (item) {
var content = item.innerText;
From b240708bbac7dfa3b7789876f04e56fd625cd3f1 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 27 Nov 2023 21:07:43 +0100
Subject: [PATCH 05/93] refactor(aria.js): minor simplification
test.sh runs clean.
---
script/aria.js | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 558a9d5..c234191 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -26,10 +26,7 @@ function ariaAttributeReferences() {
const container = item.parentNode;
const content = item.innerHTML;
const sp = document.createElement("span");
- let title = item.getAttribute("title");
- if (!title) {
- title = content;
- }
+ const title = item.getAttribute("title") || content;
sp.className = type + "-name";
sp.title = title;
sp.innerHTML =
@@ -522,7 +519,7 @@ function ariaAttributeReferences() {
if (
placeholder &&
(placeholder.textContent || placeholder.innerText) ===
- "Placeholder" &&
+ "Placeholder" &&
item.roles.length
) {
// update the used in roles list
@@ -571,7 +568,7 @@ function ariaAttributeReferences() {
} else if (
placeholder &&
(placeholder.textContent || placeholder.innerText) ===
- "Use as a global deprecated in ARIA 1.2" &&
+ "Use as a global deprecated in ARIA 1.2" &&
item.roles.length
) {
// update the used in roles list
@@ -626,7 +623,7 @@ function ariaAttributeReferences() {
} else if (
placeholder &&
(placeholder.textContent || placeholder.innerText) ===
- "All elements of the base markup except for some roles or elements that prohibit its use" &&
+ "All elements of the base markup except for some roles or elements that prohibit its use" &&
item.roles.length
) {
// for prohibited roles the roles list just includes those roles which are prohibited... weird I know but it is what it is
From 1ba5d9905b2359c1063863cc0e15284adb8b88c1 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 27 Nov 2023 21:20:46 +0100
Subject: [PATCH 06/93] refactor(aria.js): minor simplification
Revises pdef/sdef HTML-ification.
Switches to template string.
Moves this until after populating propList for future re-organization.
test.sh run is clean.
---
script/aria.js | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index c234191..c33adbb 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -25,24 +25,11 @@ function ariaAttributeReferences() {
const type = item.localName === "pdef" ? "property" : "state";
const container = item.parentNode;
const content = item.innerHTML;
- const sp = document.createElement("span");
const title = item.getAttribute("title") || content;
- sp.className = type + "-name";
- sp.title = title;
- sp.innerHTML =
- "" +
- content +
- '
' +
- type +
- "";
- sp.setAttribute("aria-describedby", "desc-" + title);
const dRef = item.nextElementSibling;
const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML;
dRef.id = "desc-" + title;
dRef.setAttribute("role", "definition");
- const heading = document.createElement("h4");
- heading.appendChild(sp);
- container.replaceChild(heading, item);
// add this item to the index
propList[title] = {
is: type,
@@ -51,6 +38,9 @@ function ariaAttributeReferences() {
desc: desc,
roles: [],
};
+ // Replace pdef/sdef with HTML
+ item.insertAdjacentHTML('afterend', `${content}
${type}
`)
+ item.remove();
const abstract = container.querySelector("." + type + "-applicability");
if (
(abstract.textContent || abstract.innerText) ===
From 22ae040eed61e64f95fcc8f58a162cefc13e3dd6 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 27 Nov 2023 21:40:57 +0100
Subject: [PATCH 07/93] refactor(aria.js): minor simplification
Revises pdef/sdef populating globalSP.
DRYs else-if clauses
test.sh run is clean.
---
script/aria.js | 40 +++++++++-------------------------------
1 file changed, 9 insertions(+), 31 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index c33adbb..aa36747 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -41,42 +41,20 @@ function ariaAttributeReferences() {
// Replace pdef/sdef with HTML
item.insertAdjacentHTML('afterend', `${content}
${type}
`)
item.remove();
- const abstract = container.querySelector("." + type + "-applicability");
- if (
- (abstract.textContent || abstract.innerText) ===
- "All elements of the base markup"
- ) {
+ // Populate globalSP
+ const applicabilityText = container.querySelector("." + type + "-applicability").innerText;
+ const isDefault = (applicabilityText === "All elements of the base markup");
+ const isProhibited = (applicabilityText === "All elements of the base markup except for some roles or elements that prohibit its use");
+ const isDeprecated = (applicabilityText === "Use as a global deprecated in ARIA 1.2");
+ // NOTE: the only other value for applicabilityText appears to be "Placeholder"
+ if (isDefault || isProhibited || isDeprecated) {
globalSP.push({
is: type,
title: title,
name: content,
desc: desc,
- prohibited: false,
- deprecated: false,
- });
- } else if (
- (abstract.textContent || abstract.innerText) ===
- "All elements of the base markup except for some roles or elements that prohibit its use"
- ) {
- globalSP.push({
- is: type,
- title: title,
- name: content,
- desc: desc,
- prohibited: true,
- deprecated: false,
- });
- } else if (
- (abstract.textContent || abstract.innerText) ===
- "Use as a global deprecated in ARIA 1.2"
- ) {
- globalSP.push({
- is: type,
- title: title,
- name: content,
- desc: desc,
- prohibited: false,
- deprecated: true,
+ prohibited: isProhibited,
+ deprecated: isDeprecated,
});
}
// the rdef is gone. if we are in a div, convert that div to a section
From 32cfdc7778da6242ecfb4dce9b666845a6659cfe Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 27 Nov 2023 21:48:03 +0100
Subject: [PATCH 08/93] chore(aria.js): add TODO for pdef/sdef container
---
script/aria.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/script/aria.js b/script/aria.js
index aa36747..5e5c6bc 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -57,8 +57,11 @@ function ariaAttributeReferences() {
deprecated: isDeprecated,
});
}
- // the rdef is gone. if we are in a div, convert that div to a section
+ // if we are in a div, convert that div to a section
+ // TODO:
+ // a) seems to be always the case.
+ // b) Why don't we author the spec this way?
if (container.nodeName.toLowerCase() == "div") {
// change the enclosing DIV to a section with notoc
const sec = document.createElement("section");
From 4b6c31609887540adc6052d3e3fba8317b2eddb0 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 27 Nov 2023 21:49:33 +0100
Subject: [PATCH 09/93] chore(aria.js): appease eslint
---
script/aria.js | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 5e5c6bc..c770452 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -39,13 +39,22 @@ function ariaAttributeReferences() {
roles: [],
};
// Replace pdef/sdef with HTML
- item.insertAdjacentHTML('afterend', `${content}
${type}
`)
+ item.insertAdjacentHTML(
+ "afterend",
+ `${content}
${type}
`
+ );
item.remove();
// Populate globalSP
- const applicabilityText = container.querySelector("." + type + "-applicability").innerText;
- const isDefault = (applicabilityText === "All elements of the base markup");
- const isProhibited = (applicabilityText === "All elements of the base markup except for some roles or elements that prohibit its use");
- const isDeprecated = (applicabilityText === "Use as a global deprecated in ARIA 1.2");
+ const applicabilityText = container.querySelector(
+ "." + type + "-applicability"
+ ).innerText;
+ const isDefault =
+ applicabilityText === "All elements of the base markup";
+ const isProhibited =
+ applicabilityText ===
+ "All elements of the base markup except for some roles or elements that prohibit its use";
+ const isDeprecated =
+ applicabilityText === "Use as a global deprecated in ARIA 1.2";
// NOTE: the only other value for applicabilityText appears to be "Placeholder"
if (isDefault || isProhibited || isDeprecated) {
globalSP.push({
@@ -59,8 +68,8 @@ function ariaAttributeReferences() {
}
// if we are in a div, convert that div to a section
- // TODO:
- // a) seems to be always the case.
+ // TODO:
+ // a) seems to be always the case.
// b) Why don't we author the spec this way?
if (container.nodeName.toLowerCase() == "div") {
// change the enclosing DIV to a section with notoc
@@ -490,7 +499,7 @@ function ariaAttributeReferences() {
if (
placeholder &&
(placeholder.textContent || placeholder.innerText) ===
- "Placeholder" &&
+ "Placeholder" &&
item.roles.length
) {
// update the used in roles list
@@ -539,7 +548,7 @@ function ariaAttributeReferences() {
} else if (
placeholder &&
(placeholder.textContent || placeholder.innerText) ===
- "Use as a global deprecated in ARIA 1.2" &&
+ "Use as a global deprecated in ARIA 1.2" &&
item.roles.length
) {
// update the used in roles list
@@ -594,7 +603,7 @@ function ariaAttributeReferences() {
} else if (
placeholder &&
(placeholder.textContent || placeholder.innerText) ===
- "All elements of the base markup except for some roles or elements that prohibit its use" &&
+ "All elements of the base markup except for some roles or elements that prohibit its use" &&
item.roles.length
) {
// for prohibited roles the roles list just includes those roles which are prohibited... weird I know but it is what it is
From fe4cccabf65361fe0272ceed69ddaeba4ff2d1e1 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 28 Nov 2023 06:59:16 +0100
Subject: [PATCH 10/93] refactor(aria.js): simplify "propList to HTML"
Simplifies first use of "sortedList" by
a) realizing that propList is already sorted since the spec is.
b) iterating over propList's values
test.sh run is clean.
---
script/aria.js | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index c770452..1e051d6 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -90,13 +90,7 @@ function ariaAttributeReferences() {
let propIndex = "";
let sortedList = [];
- Object.keys(propList).forEach(function (key) {
- sortedList.push(key);
- });
- sortedList = sortedList.sort();
-
- for (let i = 0; i < sortedList.length; i++) {
- const item = propList[sortedList[i]];
+ for (let item of Object.values(propList)) {
propIndex +=
'- b.name ? 1 : 0;
- });
- for (i = 0; i < sortedList.length; i++) {
- const lItem = sortedList[i];
+ for (let lItem of globalSP) {
globalSPIndex += "
- ";
if (lItem.is === "state") {
globalSPIndex +=
From ae43f638fae90c1f5480fd31cc3ab6b8783618d8 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 28 Nov 2023 11:11:08 +0100
Subject: [PATCH 12/93] refactor(aria.js): revise "propList to HTML"
Revises "proplist to HTML" aka generating the index of states and
properties.
* replaces loop of string concatenation with map and join
* switch to template strings
* switch to insertAdjanceHTML & remove
test.sh run is clean.
---
script/aria.js | 36 ++++++++++++++----------------------
1 file changed, 14 insertions(+), 22 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 0ad35db..385411e 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -85,28 +85,20 @@ function ariaAttributeReferences() {
});
if (!skipIndex) {
- // we have all the properties and states - spit out the
- // index
- let propIndex = "";
-
- for (let item of Object.values(propList)) {
- propIndex +=
- '
- ' +
- item.name +
- "
\n";
- propIndex += "- " + item.desc + "
\n";
- }
- let node = document.getElementById("index_state_prop");
- parentNode = node.parentNode;
- let l = document.createElement("dl");
- l.id = "index_state_prop";
- l.className = "compact";
- l.innerHTML = propIndex;
- parentNode.replaceChild(l, node);
+ // Generate index of states and properties
+ const indexStatePropPlaceholder =
+ document.getElementById("index_state_prop");
+ const indexStatePropContent = Object.values(propList)
+ .map(
+ (item) =>
+ `- ${item.name}
\n- ${item.desc}
\n`
+ )
+ .join("");
+ indexStatePropPlaceholder.insertAdjacentHTML(
+ "afterend",
+ `${indexStatePropContent}
`
+ );
+ indexStatePropPlaceholder.remove();
let globalSPIndex = "";
for (let lItem of globalSP) {
From da3b556bfd33f566644a623bf46f0e907be95677 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 28 Nov 2023 11:53:22 +0100
Subject: [PATCH 13/93] refactor(aria.js): revise "globalSP to HTML"
Revises "globalSP to HTML" aka generating the list of globabl states
and properties.
* replaces loop of string concatenation with map and join
* switch to template strings (a bit messy but see TODO comment)
* switch to insertAdjanceHTML & remove
* adjust roletype below (ahead of cleanup there)
test.sh run is clean.
---
script/aria.js | 69 +++++++++++++++++++++-----------------------------
1 file changed, 29 insertions(+), 40 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 385411e..40606b8 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -100,45 +100,34 @@ function ariaAttributeReferences() {
);
indexStatePropPlaceholder.remove();
- let globalSPIndex = "";
- for (let lItem of globalSP) {
- globalSPIndex += "- ";
- if (lItem.is === "state") {
- globalSPIndex +=
- "' +
- lItem.name +
- " (state)";
- } else {
- globalSPIndex +=
- "" +
- lItem.name +
- "";
- }
- if (lItem.prohibited) {
- globalSPIndex += " (Except where prohibited)";
- }
- if (lItem.deprecated) {
- globalSPIndex += " (Global use deprecated in ARIA 1.2)";
- }
- globalSPIndex += "
\n";
- }
- parentNode = document.querySelector("#global_states");
- if (parentNode) {
- node = parentNode.querySelector(".placeholder");
- if (node) {
- l = document.createElement("ul");
- l.innerHTML = globalSPIndex;
- parentNode.replaceChild(l, node);
- }
- }
+ // Generate index of global states and properties
+ // TODO: consider moving "(state)" out of sref/pref; then maybe remove title attr for sref (after checking resolveReferences interference)
+ const globalStatesPropertiesContent = globalSP
+ .map((item) => {
+ const isState = item.is === "state";
+ const tagName = isState ? "sref" : "pref";
+ return `- <${tagName} ${
+ item.prohibited ? "data-prohibited " : ""
+ }${item.deprecated ? "data-deprecated " : ""}${
+ isState ? `title="${item.name}"` : ""
+ }>${item.name}${isState ? " (state)" : ""}${tagName}>${
+ item.prohibited ? " (Except where prohibited)" : ""
+ }${
+ item.deprecated
+ ? " (Global use deprecated in ARIA 1.2)"
+ : ""
+ }
\n`;
+ })
+ .join("");
+ const globalStatesPropertiesPlaceholder = document.querySelector(
+ "#global_states .placeholder"
+ );
+ globalStatesPropertiesPlaceholder.insertAdjacentHTML(
+ "afterend",
+ `${globalStatesPropertiesContent}
`
+ );
+ globalStatesPropertiesPlaceholder.remove();
+
// there is only one role that uses the global properties
parentNode = document.querySelector(
"#roletype td.role-properties span.placeholder"
@@ -150,7 +139,7 @@ function ariaAttributeReferences() {
"Placeholder for global states and properties"
) {
l = document.createElement("ul");
- l.innerHTML = globalSPIndex;
+ l.innerHTML = globalStatesPropertiesContent;
node.replaceChild(l, parentNode);
}
}
From 0996f4e267fd2c1304ad2eb69645aac4659fda20 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 28 Nov 2023 11:57:59 +0100
Subject: [PATCH 14/93] refactor(aria.js): revise roletype props insertion
Revises how global states&properties are added to role=roletype.
* remove superfluous if checks
* switch to template strings (a bit messy but see TODO comment)
* switch to insertAdjanceHTML & remove
test.sh run is clean.
---
script/aria.js | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 40606b8..bce4244 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -128,21 +128,15 @@ function ariaAttributeReferences() {
);
globalStatesPropertiesPlaceholder.remove();
- // there is only one role that uses the global properties
- parentNode = document.querySelector(
+ // Populate role=roletype properties with global properties
+ const roletypePropsPlaceholder = document.querySelector(
"#roletype td.role-properties span.placeholder"
);
- if (parentNode) {
- node = parentNode.parentNode;
- if (
- (parentNode.textContent || parentNode.innerText) ===
- "Placeholder for global states and properties"
- ) {
- l = document.createElement("ul");
- l.innerHTML = globalStatesPropertiesContent;
- node.replaceChild(l, parentNode);
- }
- }
+ roletypePropsPlaceholder.insertAdjacentHTML(
+ "afterend",
+ `${globalStatesPropertiesContent}
`
+ );
+ roletypePropsPlaceholder.remove();
}
// what about roles?
From d6cbf20a0e8445a098e5b5d427b7aacde981f043 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Sat, 9 Dec 2023 17:41:16 +0100
Subject: [PATCH 15/93] refactor(aria.js): move cloneWithoutIds()
Moves cloneWithoutIds() to global scope;
prepares for moving loop functions to global scope.
test.sh run is clean.
---
script/aria.js | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index bce4244..59a9e2c 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -1,3 +1,17 @@
+
+/**
+ * Clones a node but strips IDs
+ * @param {HTMLElement} node - an element node
+ * @returns {HTMLElement} - cloned node without IDs
+ */
+function cloneWithoutIds(node) {
+ const clone = node.cloneNode(true);
+ for (const elementWithId of clone.querySelectorAll("[id]")) {
+ elementWithId.removeAttribute("id");
+ }
+ return clone;
+}
+
/**
* roleInfo is structured like this:
*
@@ -684,14 +698,6 @@ function ariaAttributeReferences() {
});
updateReferences(document);
-
- function cloneWithoutIds(node) {
- const clone = node.cloneNode(true);
- for (const elementWithId of clone.querySelectorAll("[id]")) {
- elementWithId.removeAttribute("id");
- }
- return clone;
- }
}
require(["core/pubsubhub"], function (respecEvents) {
From 14104711b9f0286799925a2d066bd7084d63f079 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Sat, 9 Dec 2023 17:47:38 +0100
Subject: [PATCH 16/93] refactor(aria.js): refactor pdef/sdef loop function
Moves pdef/sdef loop function to global scope;
prepares more refactoring.
test.sh run is clean.
---
script/aria.js | 133 ++++++++++++++++++++++++++-----------------------
1 file changed, 71 insertions(+), 62 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 59a9e2c..4258543 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -23,6 +23,74 @@ function cloneWithoutIds(node) {
const roleInfo = {};
+/**
+ * temporary refactoring to keep things legible
+ * @param {Object} propList -
+ * @param {Object} globalSP -
+ * @param {HTMLElement} item - from nodeList.forEach
+ */
+const handleStatesAndProperties = function (propList, globalSP, item) {
+ const type = item.localName === "pdef" ? "property" : "state";
+ const container = item.parentNode;
+ const content = item.innerHTML;
+ const title = item.getAttribute("title") || content;
+ const dRef = item.nextElementSibling;
+ const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML;
+ dRef.id = "desc-" + title;
+ dRef.setAttribute("role", "definition");
+ // add this item to the index
+ propList[title] = {
+ is: type,
+ title: title,
+ name: content,
+ desc: desc,
+ roles: [],
+ };
+ // Replace pdef/sdef with HTML
+ item.insertAdjacentHTML(
+ "afterend",
+ `${content}
${type}
`
+ );
+ item.remove();
+ // Populate globalSP
+ const applicabilityText = container.querySelector(
+ "." + type + "-applicability"
+ ).innerText;
+ const isDefault = applicabilityText === "All elements of the base markup";
+ const isProhibited =
+ applicabilityText ===
+ "All elements of the base markup except for some roles or elements that prohibit its use";
+ const isDeprecated =
+ applicabilityText === "Use as a global deprecated in ARIA 1.2";
+ // NOTE: the only other value for applicabilityText appears to be "Placeholder"
+ if (isDefault || isProhibited || isDeprecated) {
+ globalSP.push({
+ is: type,
+ title: title,
+ name: content,
+ desc: desc,
+ prohibited: isProhibited,
+ deprecated: isDeprecated,
+ });
+ }
+
+ // if we are in a div, convert that div to a section
+ // TODO:
+ // a) seems to be always the case.
+ // b) Why don't we author the spec this way?
+ if (container.nodeName.toLowerCase() == "div") {
+ // change the enclosing DIV to a section with notoc
+ const sec = document.createElement("section");
+ [...container.attributes].forEach(function (attr) {
+ sec.setAttribute(attr.name, attr.value);
+ });
+ sec.classList.add("notoc");
+ const theContents = container.innerHTML;
+ sec.innerHTML = theContents;
+ container.parentNode.replaceChild(sec, container);
+ }
+};
+
function ariaAttributeReferences() {
const propList = {};
const globalSP = [];
@@ -35,68 +103,9 @@ function ariaAttributeReferences() {
// process the document before anything else is done
// first get the properties
- document.querySelectorAll("pdef, sdef").forEach(function (item) {
- const type = item.localName === "pdef" ? "property" : "state";
- const container = item.parentNode;
- const content = item.innerHTML;
- const title = item.getAttribute("title") || content;
- const dRef = item.nextElementSibling;
- const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML;
- dRef.id = "desc-" + title;
- dRef.setAttribute("role", "definition");
- // add this item to the index
- propList[title] = {
- is: type,
- title: title,
- name: content,
- desc: desc,
- roles: [],
- };
- // Replace pdef/sdef with HTML
- item.insertAdjacentHTML(
- "afterend",
- `${content}
${type}
`
- );
- item.remove();
- // Populate globalSP
- const applicabilityText = container.querySelector(
- "." + type + "-applicability"
- ).innerText;
- const isDefault =
- applicabilityText === "All elements of the base markup";
- const isProhibited =
- applicabilityText ===
- "All elements of the base markup except for some roles or elements that prohibit its use";
- const isDeprecated =
- applicabilityText === "Use as a global deprecated in ARIA 1.2";
- // NOTE: the only other value for applicabilityText appears to be "Placeholder"
- if (isDefault || isProhibited || isDeprecated) {
- globalSP.push({
- is: type,
- title: title,
- name: content,
- desc: desc,
- prohibited: isProhibited,
- deprecated: isDeprecated,
- });
- }
-
- // if we are in a div, convert that div to a section
- // TODO:
- // a) seems to be always the case.
- // b) Why don't we author the spec this way?
- if (container.nodeName.toLowerCase() == "div") {
- // change the enclosing DIV to a section with notoc
- const sec = document.createElement("section");
- [...container.attributes].forEach(function (attr) {
- sec.setAttribute(attr.name, attr.value);
- });
- sec.classList.add("notoc");
- const theContents = container.innerHTML;
- sec.innerHTML = theContents;
- container.parentNode.replaceChild(sec, container);
- }
- });
+ document
+ .querySelectorAll("pdef, sdef")
+ .forEach(handleStatesAndProperties.bind(null, propList, globalSP));
if (!skipIndex) {
// Generate index of states and properties
From 574fc0c660f79891fa44a78cbe281b95395f0c1e Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Sat, 9 Dec 2023 17:47:59 +0100
Subject: [PATCH 17/93] chore: appease eslint
---
script/aria.js | 1 -
1 file changed, 1 deletion(-)
diff --git a/script/aria.js b/script/aria.js
index 4258543..5e8e260 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -1,4 +1,3 @@
-
/**
* Clones a node but strips IDs
* @param {HTMLElement} node - an element node
From 1cea626a7565d6086f061dbc1dc3641d233036c8 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Sat, 9 Dec 2023 18:16:36 +0100
Subject: [PATCH 18/93] refactor(aria.js): refactor states&props index creation
Moves it to a function in the global scope, part of splitting out chunks.
test.sh run is clean.
---
script/aria.js | 34 +++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 5e8e260..adccfc7 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -90,6 +90,26 @@ const handleStatesAndProperties = function (propList, globalSP, item) {
}
};
+/**
+ * Generate index of states and properties
+ * @param {Object} propList
+ */
+const generateIndexStatesAndProperties = (propList) => {
+ const indexStatePropPlaceholder =
+ document.getElementById("index_state_prop");
+ const indexStatePropContent = Object.values(propList)
+ .map(
+ (item) =>
+ `- ${item.name}
\n- ${item.desc}
\n`
+ )
+ .join("");
+ indexStatePropPlaceholder.insertAdjacentHTML(
+ "afterend",
+ `${indexStatePropContent}
`
+ );
+ indexStatePropPlaceholder.remove();
+};
+
function ariaAttributeReferences() {
const propList = {};
const globalSP = [];
@@ -108,19 +128,7 @@ function ariaAttributeReferences() {
if (!skipIndex) {
// Generate index of states and properties
- const indexStatePropPlaceholder =
- document.getElementById("index_state_prop");
- const indexStatePropContent = Object.values(propList)
- .map(
- (item) =>
- `- ${item.name}
\n- ${item.desc}
\n`
- )
- .join("");
- indexStatePropPlaceholder.insertAdjacentHTML(
- "afterend",
- `${indexStatePropContent}
`
- );
- indexStatePropPlaceholder.remove();
+ generateIndexStatesAndProperties(propList);
// Generate index of global states and properties
// TODO: consider moving "(state)" out of sref/pref; then maybe remove title attr for sref (after checking resolveReferences interference)
From a6ffa1ad09ec3557fed2b34685f0e7af7b52f109 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Sat, 9 Dec 2023 18:24:58 +0100
Subject: [PATCH 19/93] refactor(aria.js): refactor global states&props index
creation
Moves it to a function in the global scope; part of splitting out chunks.
test.sh run is clean.
---
script/aria.js | 79 +++++++++++++++++++++++++++-----------------------
1 file changed, 43 insertions(+), 36 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index adccfc7..0042955 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -110,6 +110,48 @@ const generateIndexStatesAndProperties = (propList) => {
indexStatePropPlaceholder.remove();
};
+/**
+ * Generate index of global states and properties
+ * @param {Object} globalSP
+ */
+const generateIndexGlobalStatesAndProperties = (globalSP) => {
+ const globalStatesPropertiesContent = globalSP
+ .map((item) => {
+ const isState = item.is === "state";
+ const tagName = isState ? "sref" : "pref";
+ return `- <${tagName} ${
+ item.prohibited ? "data-prohibited " : ""
+ }${item.deprecated ? "data-deprecated " : ""}${
+ isState ? `title="${item.name}"` : ""
+ }>${item.name}${isState ? " (state)" : ""}${tagName}>${
+ // TODO: consider moving "(state)" out of sref/pref tag; then maybe remove title attr for sref (after checking resolveReferences interference)
+
+ item.prohibited ? " (Except where prohibited)" : ""
+ }${
+ item.deprecated ? " (Global use deprecated in ARIA 1.2)" : ""
+ }
\n`;
+ })
+ .join("");
+ const globalStatesPropertiesPlaceholder = document.querySelector(
+ "#global_states .placeholder"
+ );
+ globalStatesPropertiesPlaceholder.insertAdjacentHTML(
+ "afterend",
+ `${globalStatesPropertiesContent}
`
+ );
+ globalStatesPropertiesPlaceholder.remove();
+
+ // Populate role=roletype properties with global properties
+ const roletypePropsPlaceholder = document.querySelector(
+ "#roletype td.role-properties span.placeholder"
+ );
+ roletypePropsPlaceholder.insertAdjacentHTML(
+ "afterend",
+ `${globalStatesPropertiesContent}
`
+ );
+ roletypePropsPlaceholder.remove();
+};
+
function ariaAttributeReferences() {
const propList = {};
const globalSP = [];
@@ -131,42 +173,7 @@ function ariaAttributeReferences() {
generateIndexStatesAndProperties(propList);
// Generate index of global states and properties
- // TODO: consider moving "(state)" out of sref/pref; then maybe remove title attr for sref (after checking resolveReferences interference)
- const globalStatesPropertiesContent = globalSP
- .map((item) => {
- const isState = item.is === "state";
- const tagName = isState ? "sref" : "pref";
- return `- <${tagName} ${
- item.prohibited ? "data-prohibited " : ""
- }${item.deprecated ? "data-deprecated " : ""}${
- isState ? `title="${item.name}"` : ""
- }>${item.name}${isState ? " (state)" : ""}${tagName}>${
- item.prohibited ? " (Except where prohibited)" : ""
- }${
- item.deprecated
- ? " (Global use deprecated in ARIA 1.2)"
- : ""
- }
\n`;
- })
- .join("");
- const globalStatesPropertiesPlaceholder = document.querySelector(
- "#global_states .placeholder"
- );
- globalStatesPropertiesPlaceholder.insertAdjacentHTML(
- "afterend",
- `${globalStatesPropertiesContent}
`
- );
- globalStatesPropertiesPlaceholder.remove();
-
- // Populate role=roletype properties with global properties
- const roletypePropsPlaceholder = document.querySelector(
- "#roletype td.role-properties span.placeholder"
- );
- roletypePropsPlaceholder.insertAdjacentHTML(
- "afterend",
- `${globalStatesPropertiesContent}
`
- );
- roletypePropsPlaceholder.remove();
+ generateIndexGlobalStatesAndProperties(globalSP);
}
// what about roles?
From ca33c43a202dac255a5d2d7eb592ffa1bfad289d Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Sat, 9 Dec 2023 20:10:48 +0100
Subject: [PATCH 20/93] refactor(aria.js): extract pdef/sdef container rewrite
Moves it to a function in the global scope; part of splitting out chunks.
Also repares separating sdef/pdef HTML creation.
test.sh run is clean.
---
script/aria.js | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 0042955..79c3c78 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -72,7 +72,13 @@ const handleStatesAndProperties = function (propList, globalSP, item) {
deprecated: isDeprecated,
});
}
+};
+/**
+ *
+ * @param {HTMLElement} container - parent of sdef or pdef
+ */
+const rewriteStatesAndPropertiesContainer = (container) => {
// if we are in a div, convert that div to a section
// TODO:
// a) seems to be always the case.
@@ -164,9 +170,15 @@ function ariaAttributeReferences() {
// process the document before anything else is done
// first get the properties
- document
- .querySelectorAll("pdef, sdef")
- .forEach(handleStatesAndProperties.bind(null, propList, globalSP));
+ const pdefsAndsdefs = document.querySelectorAll("pdef, sdef");
+ const pdefsAndsdefsContainer = [...pdefsAndsdefs].map(
+ (node) => node.parentNode
+ );
+
+ pdefsAndsdefs.forEach(
+ handleStatesAndProperties.bind(null, propList, globalSP)
+ );
+ pdefsAndsdefsContainer.forEach(rewriteStatesAndPropertiesContainer);
if (!skipIndex) {
// Generate index of states and properties
From 113b0485a0546c8694db27aa60986c2e72c01a2c Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Sat, 9 Dec 2023 20:20:49 +0100
Subject: [PATCH 21/93] refactor(aria.js): extract pdef/sdef HTML rewrite
Moves it to a function in the global scope; part of splitting out chunks.
Needs to run before container-rewrite so that it can reuse the querySelectorAll.
test.sh run is clean.
---
script/aria.js | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 79c3c78..eb5c580 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -45,12 +45,6 @@ const handleStatesAndProperties = function (propList, globalSP, item) {
desc: desc,
roles: [],
};
- // Replace pdef/sdef with HTML
- item.insertAdjacentHTML(
- "afterend",
- `${content}
${type}
`
- );
- item.remove();
// Populate globalSP
const applicabilityText = container.querySelector(
"." + type + "-applicability"
@@ -96,6 +90,22 @@ const rewriteStatesAndPropertiesContainer = (container) => {
}
};
+/**
+ * Replaces sdef/pdef with desired HTML
+ * @param {Object} propList -
+ * @param {HTMLElement} item - sdef or pdef, from nodeList.forEach
+ */
+const generateHTMLStatesAndProperties = function (propList, item) {
+ const title = item.getAttribute("title") || item.innerHTML;
+ const itemEntry = propList[title];
+ // Replace pdef/sdef with HTML
+ item.insertAdjacentHTML(
+ "afterend",
+ `${itemEntry.name}
${itemEntry.is}
`
+ );
+ item.remove();
+};
+
/**
* Generate index of states and properties
* @param {Object} propList
@@ -178,6 +188,7 @@ function ariaAttributeReferences() {
pdefsAndsdefs.forEach(
handleStatesAndProperties.bind(null, propList, globalSP)
);
+ pdefsAndsdefs.forEach(generateHTMLStatesAndProperties.bind(null, propList));
pdefsAndsdefsContainer.forEach(rewriteStatesAndPropertiesContainer);
if (!skipIndex) {
From eb1f003bccdd01f1973e6842b93dcd8f84ebfc10 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Sat, 9 Dec 2023 21:23:01 +0100
Subject: [PATCH 22/93] refactor(aria.js): split up populating propList and
globalSP
Splits the temporary handleStatesAndProperties() into
populatePropList() and populateGlobalSP().
Note. Slightly changes globalSP by re-using all of the propList entry,
more specifically the (at this point still empty) array in the role property of each propList entry.
test.sh run is clean.
---
script/aria.js | 46 ++++++++++++++++++++++++++--------------------
1 file changed, 26 insertions(+), 20 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index eb5c580..1960c42 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -23,21 +23,18 @@ function cloneWithoutIds(node) {
const roleInfo = {};
/**
- * temporary refactoring to keep things legible
+ * Populates propList for given sdef/pdef
* @param {Object} propList -
- * @param {Object} globalSP -
* @param {HTMLElement} item - from nodeList.forEach
*/
-const handleStatesAndProperties = function (propList, globalSP, item) {
+const populatePropList = function (propList, item) {
const type = item.localName === "pdef" ? "property" : "state";
- const container = item.parentNode;
const content = item.innerHTML;
const title = item.getAttribute("title") || content;
const dRef = item.nextElementSibling;
const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML;
- dRef.id = "desc-" + title;
- dRef.setAttribute("role", "definition");
- // add this item to the index
+ dRef.id = "desc-" + title; // TODO: side-effect; to be extracted
+ dRef.setAttribute("role", "definition"); // TODO: extract
propList[title] = {
is: type,
title: title,
@@ -45,9 +42,21 @@ const handleStatesAndProperties = function (propList, globalSP, item) {
desc: desc,
roles: [],
};
- // Populate globalSP
+};
+
+/**
+ * Populates globalSP for given sdef/pdef
+ * @param {Object} propList -
+ * @param {Object} globalSP -
+ * @param {HTMLElement} item - from nodeList.forEach
+ */
+const populateGlobalSP = function (propList, globalSP, item) {
+ const title = item.getAttribute("title") || item.innerHTML;
+ const container = item.parentElement;
+ const itemEntry = propList[title];
+
const applicabilityText = container.querySelector(
- "." + type + "-applicability"
+ "." + itemEntry.is + "-applicability"
).innerText;
const isDefault = applicabilityText === "All elements of the base markup";
const isProhibited =
@@ -57,14 +66,12 @@ const handleStatesAndProperties = function (propList, globalSP, item) {
applicabilityText === "Use as a global deprecated in ARIA 1.2";
// NOTE: the only other value for applicabilityText appears to be "Placeholder"
if (isDefault || isProhibited || isDeprecated) {
- globalSP.push({
- is: type,
- title: title,
- name: content,
- desc: desc,
- prohibited: isProhibited,
- deprecated: isDeprecated,
- });
+ globalSP.push(
+ Object.assign(itemEntry, {
+ prohibited: isProhibited,
+ deprecated: isDeprecated,
+ })
+ );
}
};
@@ -185,9 +192,8 @@ function ariaAttributeReferences() {
(node) => node.parentNode
);
- pdefsAndsdefs.forEach(
- handleStatesAndProperties.bind(null, propList, globalSP)
- );
+ pdefsAndsdefs.forEach(populatePropList.bind(null, propList));
+ pdefsAndsdefs.forEach(populateGlobalSP.bind(null, propList, globalSP));
pdefsAndsdefs.forEach(generateHTMLStatesAndProperties.bind(null, propList));
pdefsAndsdefsContainer.forEach(rewriteStatesAndPropertiesContainer);
From 9e45d8d049c91bfa173a7c6a22b7ba3218b48eac Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Sun, 10 Dec 2023 09:54:14 +0100
Subject: [PATCH 23/93] docs: add todo note for globalSP
---
script/aria.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/script/aria.js b/script/aria.js
index 1960c42..4443f4f 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -140,6 +140,7 @@ const generateIndexStatesAndProperties = (propList) => {
const generateIndexGlobalStatesAndProperties = (globalSP) => {
const globalStatesPropertiesContent = globalSP
.map((item) => {
+ // TODO: This is the only use of globalSP - why does it not just consist of the markup we create here in this loop?
const isState = item.is === "state";
const tagName = isState ? "sref" : "pref";
return `- <${tagName} ${
From 2b1ebe26b7fd6e720b3f4956a742b2e8d3c34ac2 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Sun, 10 Dec 2023 10:12:03 +0100
Subject: [PATCH 24/93] docs: add todo note for s/p/rdef title
---
script/aria.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/script/aria.js b/script/aria.js
index 4443f4f..17cef25 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -226,7 +226,7 @@ function ariaAttributeReferences() {
const container = item.parentNode;
const content = item.innerHTML;
const sp = document.createElement("h4");
- let title = item.getAttribute("title");
+ let title = item.getAttribute("title"); // TODO: no rdef has title (same for sdef, pdef)
if (!title) {
title = content;
}
From 9f3871013071e15164706227653ed33ba0934d40 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Sun, 10 Dec 2023 10:30:44 +0100
Subject: [PATCH 25/93] docs: add todo for "desc" selection
---
script/aria.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/script/aria.js b/script/aria.js
index 17cef25..43c712e 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -252,7 +252,7 @@ function ariaAttributeReferences() {
// sp.id = title;
sp.setAttribute("aria-describedby", "desc-" + title);
const dRef = item.nextElementSibling;
- const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML;
+ const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML; // TODO: should the spec markup provide something more robust than "next sibling first child"? [same for sdef/pdef "desc"]
dRef.id = "desc-" + title;
dRef.setAttribute("role", "definition");
container.replaceChild(sp, item);
From dbcf2d5f53067d8a147aa37e55441d5001585458 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Sun, 10 Dec 2023 10:47:45 +0100
Subject: [PATCH 26/93] docs: add note for #105
---
script/aria.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/script/aria.js b/script/aria.js
index 43c712e..1347e15 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -238,7 +238,7 @@ function ariaAttributeReferences() {
// is this a role or an abstract role
let type = "role";
let isAbstract = false;
- const abstract = container.querySelectorAll(".role-abstract");
+ const abstract = container.querySelectorAll(".role-abstract");//TODO: maybe #105
if (abstract.innerText === "True") {
type = "abstract role";
isAbstract = true;
From 1c9b00d328e6a62b4129eb1c4c67751bbc5be482 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Sun, 10 Dec 2023 11:13:46 +0100
Subject: [PATCH 27/93] chore: appease eslint
---
script/aria.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/script/aria.js b/script/aria.js
index 1347e15..438a433 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -238,7 +238,7 @@ function ariaAttributeReferences() {
// is this a role or an abstract role
let type = "role";
let isAbstract = false;
- const abstract = container.querySelectorAll(".role-abstract");//TODO: maybe #105
+ const abstract = container.querySelectorAll(".role-abstract"); //TODO: maybe #105
if (abstract.innerText === "True") {
type = "abstract role";
isAbstract = true;
From 634cdb2457e5eed55ba5c1a79d055f4f8c0b7167 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 11 Dec 2023 10:50:20 +0100
Subject: [PATCH 28/93] refactor(aria.js): extract container rewrite from rdef
loop
Extracts the container rewrite and re-uses the (now renamed) helper from sdef/pdef loop.
test.sh run is clean.
---
script/aria.js | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 438a433..995bba5 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -77,9 +77,9 @@ const populateGlobalSP = function (propList, globalSP, item) {
/**
*
- * @param {HTMLElement} container - parent of sdef or pdef
+ * @param {HTMLElement} container - parent of sdef or pdef or rdef
*/
-const rewriteStatesAndPropertiesContainer = (container) => {
+const rewriteContainer = (container) => {
// if we are in a div, convert that div to a section
// TODO:
// a) seems to be always the case.
@@ -196,7 +196,7 @@ function ariaAttributeReferences() {
pdefsAndsdefs.forEach(populatePropList.bind(null, propList));
pdefsAndsdefs.forEach(populateGlobalSP.bind(null, propList, globalSP));
pdefsAndsdefs.forEach(generateHTMLStatesAndProperties.bind(null, propList));
- pdefsAndsdefsContainer.forEach(rewriteStatesAndPropertiesContainer);
+ pdefsAndsdefsContainer.forEach(rewriteContainer);
if (!skipIndex) {
// Generate index of states and properties
@@ -222,7 +222,10 @@ function ariaAttributeReferences() {
let fromContent = "";
let fromProhibited = "";
- document.querySelectorAll("rdef").forEach(function (item) {
+ const rdefs = document.querySelectorAll("rdef");
+ const rdefsContainer = [...rdefs].map((node) => node.parentNode);
+
+ rdefs.forEach(function (item) {
const container = item.parentNode;
const content = item.innerHTML;
const sp = document.createElement("h4");
@@ -387,20 +390,10 @@ function ariaAttributeReferences() {
}
});
}
- if (container.nodeName.toLowerCase() == "div") {
- // change the enclosing DIV to a section with notoc
- const sec = document.createElement("section");
- [...container.attributes].forEach(function (attr) {
- sec.setAttribute(attr.name, attr.value);
- });
-
- sec.classList.add("notoc");
- const theContents = container.innerHTML;
- sec.innerHTML = theContents;
- container.parentNode.replaceChild(sec, container);
- }
});
+ rdefsContainer.forEach(rewriteContainer);
+
const getStates = function (role) {
const ref = roleInfo[role];
if (!ref) {
From ec635d44630b3de9db637633dfbc78d024039d9e Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 11 Dec 2023 11:36:52 +0100
Subject: [PATCH 29/93] refactor(aria.js): move description side-effect around
Sets id and role for the description in HTML creation instead of propList creation. At least setting the ID makes sense here.
test.sh run is clean.
---
script/aria.js | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 995bba5..b14e577 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -33,8 +33,6 @@ const populatePropList = function (propList, item) {
const title = item.getAttribute("title") || content;
const dRef = item.nextElementSibling;
const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML;
- dRef.id = "desc-" + title; // TODO: side-effect; to be extracted
- dRef.setAttribute("role", "definition"); // TODO: extract
propList[title] = {
is: type,
title: title,
@@ -105,6 +103,9 @@ const rewriteContainer = (container) => {
const generateHTMLStatesAndProperties = function (propList, item) {
const title = item.getAttribute("title") || item.innerHTML;
const itemEntry = propList[title];
+ const dRef = item.nextElementSibling;
+ dRef.id = "desc-" + title; // TODO: too much of a side-effect?
+ dRef.setAttribute("role", "definition"); // TODO: ditto?
// Replace pdef/sdef with HTML
item.insertAdjacentHTML(
"afterend",
From 5ba419adbf9521f3988b9328a794e5600a6edf41 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 11 Dec 2023 11:38:16 +0100
Subject: [PATCH 30/93] refactor(aria.js): rename rewriteContainer =>
rewriteDefContainer
test.sh run is clean.
---
script/aria.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index b14e577..ba4363c 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -77,7 +77,7 @@ const populateGlobalSP = function (propList, globalSP, item) {
*
* @param {HTMLElement} container - parent of sdef or pdef or rdef
*/
-const rewriteContainer = (container) => {
+const rewriteDefContainer = (container) => {
// if we are in a div, convert that div to a section
// TODO:
// a) seems to be always the case.
@@ -197,7 +197,7 @@ function ariaAttributeReferences() {
pdefsAndsdefs.forEach(populatePropList.bind(null, propList));
pdefsAndsdefs.forEach(populateGlobalSP.bind(null, propList, globalSP));
pdefsAndsdefs.forEach(generateHTMLStatesAndProperties.bind(null, propList));
- pdefsAndsdefsContainer.forEach(rewriteContainer);
+ pdefsAndsdefsContainer.forEach(rewriteDefContainer);
if (!skipIndex) {
// Generate index of states and properties
@@ -393,7 +393,7 @@ function ariaAttributeReferences() {
}
});
- rdefsContainer.forEach(rewriteContainer);
+ rdefsContainer.forEach(rewriteDefContainer);
const getStates = function (role) {
const ref = roleInfo[role];
From 48523a76131e4e057e48db61aeab081be6b55296 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 11 Dec 2023 11:54:25 +0100
Subject: [PATCH 31/93] refactor(aria.js): extract rdef rewrite from rdef loop
Extracts the rdef rewrite to function in global scope.
Unfortunately we cannot re-use the sdef/pdef setup since it
creates different HTML (and also #105).
test.sh run is clean.
---
script/aria.js | 40 +++++++++++++++++++++++++---------------
1 file changed, 25 insertions(+), 15 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index ba4363c..05717b7 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -95,6 +95,29 @@ const rewriteDefContainer = (container) => {
}
};
+/**
+ *
+ * @param {HTMLElement} item - rdef element
+ */
+const rewriteRdef = function (item) {
+ // TODO: merge with generateHTMLStatesAndProperties() but that creates different HTML
+ const content = item.innerHTML;
+ let title = item.getAttribute("title") || content;
+ let type = "role";
+ const abstract = item.parentNode.querySelectorAll(".role-abstract"); //TODO: maybe #105
+ if (abstract.innerText === "True") {
+ type = "abstract role";
+ }
+ const dRef = item.nextElementSibling;
+ dRef.id = "desc-" + title;
+ dRef.setAttribute("role", "definition");
+ item.insertAdjacentHTML(
+ "afterend",
+ `
${content}
${type}`
+ );
+ item.remove();
+};
+
/**
* Replaces sdef/pdef with desired HTML
* @param {Object} propList -
@@ -229,16 +252,12 @@ function ariaAttributeReferences() {
rdefs.forEach(function (item) {
const container = item.parentNode;
const content = item.innerHTML;
- const sp = document.createElement("h4");
let title = item.getAttribute("title"); // TODO: no rdef has title (same for sdef, pdef)
if (!title) {
title = content;
}
-
const pnID = title;
container.id = pnID;
- sp.className = "role-name";
- sp.title = title;
// is this a role or an abstract role
let type = "role";
let isAbstract = false;
@@ -247,19 +266,8 @@ function ariaAttributeReferences() {
type = "abstract role";
isAbstract = true;
}
- sp.innerHTML =
- "" +
- content +
- '
' +
- type +
- "";
- // sp.id = title;
- sp.setAttribute("aria-describedby", "desc-" + title);
const dRef = item.nextElementSibling;
const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML; // TODO: should the spec markup provide something more robust than "next sibling first child"? [same for sdef/pdef "desc"]
- dRef.id = "desc-" + title;
- dRef.setAttribute("role", "definition");
- container.replaceChild(sp, item);
roleIndex +=
'${content}
${
+ isAbstract ? " (abstract role) " : ""
+ } \n- ${desc}
\n`;
+};
+
function ariaAttributeReferences() {
const propList = {};
const globalSP = [];
@@ -240,7 +268,6 @@ function ariaAttributeReferences() {
//
const subRoles = [];
- let roleIndex = "";
let fromAuthor = "";
let fromHeading = "";
let fromContent = "";
@@ -249,6 +276,7 @@ function ariaAttributeReferences() {
const rdefs = document.querySelectorAll("rdef");
const rdefsContainer = [...rdefs].map((node) => node.parentNode);
+ const roleIndex = [...rdefs].map(generateHTMLRoleIndexEntry).join("");
rdefs.forEach(function (item) {
const container = item.parentNode;
const content = item.innerHTML;
@@ -259,24 +287,11 @@ function ariaAttributeReferences() {
const pnID = title;
container.id = pnID;
// is this a role or an abstract role
- let type = "role";
let isAbstract = false;
const abstract = container.querySelectorAll(".role-abstract"); //TODO: maybe #105
if (abstract.innerText === "True") {
- type = "abstract role";
isAbstract = true;
}
- const dRef = item.nextElementSibling;
- const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML; // TODO: should the spec markup provide something more robust than "next sibling first child"? [same for sdef/pdef "desc"]
- roleIndex +=
- '' +
- content +
- "
" +
- (isAbstract ? " (abstract role) " : "") +
- " \n";
- roleIndex += "- " + desc + "
\n";
// grab info about this role
// do we have a parent class? if so, put us in that parents list
const node = container.querySelectorAll(".role-parent rref");
From b7492716f11d6c269b5685f3001acb1d6af8b79f Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 11:24:48 +0100
Subject: [PATCH 33/93] refactor(aria.js): improve parentRoles, subRoles
* Renames node => rrefs
* moves parentRoles generation out of inner loop
* prepares for more work on populating subRoles
test.sh run is clean.
---
script/aria.js | 27 +++++++++++----------------
1 file changed, 11 insertions(+), 16 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index cc77f21..749573d 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -292,24 +292,19 @@ function ariaAttributeReferences() {
if (abstract.innerText === "True") {
isAbstract = true;
}
+
// grab info about this role
// do we have a parent class? if so, put us in that parents list
- const node = container.querySelectorAll(".role-parent rref");
- // s will hold the name of the parent role if any
- let s = null;
- const parentRoles = [];
- if (node.length) {
- node.forEach(function (roleref) {
- s = roleref.textContent || roleref.innerText;
-
- if (!subRoles[s]) {
- subRoles.push(s);
- subRoles[s] = [];
- }
- subRoles[s].push(title);
- parentRoles.push(s);
- });
- }
+ const rrefs = container.querySelectorAll(".role-parent rref");
+ const parentRoles = [...rrefs].map((rref) => rref.innerText);
+ rrefs.forEach(function (roleref) {
+ const s = roleref.innerText;
+ if (!subRoles[s]) {
+ subRoles.push(s);
+ subRoles[s] = [];
+ }
+ subRoles[s].push(title);
+ });
// are there supported states / properties in this role?
const attrs = [];
container
From 0f4331538a86c30a30ff9fe586b940e274546167 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 11:34:17 +0100
Subject: [PATCH 34/93] refactor(aria.js): refactor populating subRoles
Extracts populating of subRoles object into globa scope.
Adds todos.
test.sh run is clean.
---
script/aria.js | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 749573d..c41eb48 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -228,6 +228,26 @@ const generateHTMLRoleIndexEntry = function (item) {
} \n- ${desc}
\n`;
};
+/**
+ * Generates subrole information
+ * @param {Object} subRoles - the subRoles "array" (overloaded)
+ * @param {HTMLement} rdef - rdef element node
+ */
+const populateSubRoles = (subRoles, rdef) => {
+ const title = rdef.innerHTML;
+ rdef.parentNode
+ .querySelectorAll(".role-parent rref")
+ .forEach(function (roleref) {
+ const s = roleref.innerText;
+ // TODO: this overloading seems weird
+ if (!subRoles[s]) {
+ subRoles.push(s);
+ subRoles[s] = []; // TODO: should this be a set?
+ }
+ subRoles[s].push(title); // TODO: should this be a set?
+ });
+};
+
function ariaAttributeReferences() {
const propList = {};
const globalSP = [];
@@ -276,6 +296,7 @@ function ariaAttributeReferences() {
const rdefs = document.querySelectorAll("rdef");
const rdefsContainer = [...rdefs].map((node) => node.parentNode);
+ rdefs.forEach(populateSubRoles.bind(null, subRoles));
const roleIndex = [...rdefs].map(generateHTMLRoleIndexEntry).join("");
rdefs.forEach(function (item) {
const container = item.parentNode;
@@ -297,14 +318,6 @@ function ariaAttributeReferences() {
// do we have a parent class? if so, put us in that parents list
const rrefs = container.querySelectorAll(".role-parent rref");
const parentRoles = [...rrefs].map((rref) => rref.innerText);
- rrefs.forEach(function (roleref) {
- const s = roleref.innerText;
- if (!subRoles[s]) {
- subRoles.push(s);
- subRoles[s] = [];
- }
- subRoles[s].push(title);
- });
// are there supported states / properties in this role?
const attrs = [];
container
From 45e5e1790aa651438e7c60647fea6470caaf678a Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 11:45:50 +0100
Subject: [PATCH 35/93] feat(eslintrc.json): bump ecmaVersion to latest
aria-common only needs to run in the latest user agents engines.
---
.eslintrc.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.eslintrc.json b/.eslintrc.json
index 7afe928..c368dda 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -8,7 +8,7 @@
},
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"parserOptions": {
- "ecmaVersion": 6
+ "ecmaVersion": "latest"
},
"rules": {
"no-unused-vars": "off",
From 1c94d3cf1f32f91b536f68997d4220e1ae091577 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 11:48:11 +0100
Subject: [PATCH 36/93] refactor(aria.js): simplify innerText checks
Removes almost all textContent in favor of innerText (since IE8 is no longer relevant).
Also simplifies content checks using optional chaining
test.sh run is clean.
---
script/aria.js | 21 +++++----------------
1 file changed, 5 insertions(+), 16 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index c41eb48..988336d 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -325,16 +325,12 @@ function ariaAttributeReferences() {
".role-properties, .role-required-properties, .role-disallowed"
)
.forEach(function (node) {
- if (
- node &&
- ((node.textContent && node.textContent.length !== 1) ||
- (node.innerText && node.innerText.length !== 1))
- ) {
+ if (node.innerText.length !== 1) {
// looks like we do
node.querySelectorAll("pref,sref").forEach(function (item) {
let name = item.getAttribute("title");
if (!name) {
- name = item.textContent || item.innerText;
+ name = item.innerText;
}
const type =
item.localName === "pref" ? "property" : "state";
@@ -554,12 +550,7 @@ function ariaAttributeReferences() {
let placeholder = section.querySelector(
".state-applicability, .property-applicability"
);
- if (
- placeholder &&
- (placeholder.textContent || placeholder.innerText) ===
- "Placeholder" &&
- item.roles.length
- ) {
+ if (placeholder?.innerText === "Placeholder" && item.roles.length) {
// update the used in roles list
let sortedList = [];
sortedList = item.roles.sort();
@@ -604,8 +595,7 @@ function ariaAttributeReferences() {
placeholder.innerHTML = output;
}
} else if (
- placeholder &&
- (placeholder.textContent || placeholder.innerText) ===
+ placeholder?.innerText ===
"Use as a global deprecated in ARIA 1.2" &&
item.roles.length
) {
@@ -659,8 +649,7 @@ function ariaAttributeReferences() {
placeholder.innerHTML = output;
}
} else if (
- placeholder &&
- (placeholder.textContent || placeholder.innerText) ===
+ placeholder?.innerText ===
"All elements of the base markup except for some roles or elements that prohibit its use" &&
item.roles.length
) {
From 91d38b4a873fe9237f7c9101340827e34e53c183 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 11:53:40 +0100
Subject: [PATCH 37/93] refactor(aria.js): simplify generateHTMLRoleIndexEntry
Resolves TODO item by replacing title, pnId with content.
Also replaces innerHTML with innerText because it is more sensible for use as ID.
test.sh run is clean.
---
script/aria.js | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 988336d..a4c2e63 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -206,13 +206,8 @@ const generateIndexGlobalStatesAndProperties = (globalSP) => {
*/
const generateHTMLRoleIndexEntry = function (item) {
const container = item.parentNode;
- const content = item.innerHTML;
- let title = item.getAttribute("title"); // TODO: no rdef has title (same for sdef, pdef)
- if (!title) {
- title = content;
- }
- const pnID = title;
- container.id = pnID;
+ const content = item.innerText;
+ container.id = content;
// is this a role or an abstract role
let type = "role";
let isAbstract = false;
@@ -223,7 +218,7 @@ const generateHTMLRoleIndexEntry = function (item) {
}
const dRef = item.nextElementSibling;
const desc = cloneWithoutIds(dRef.firstElementChild).innerHTML; // TODO: should the spec markup provide something more robust than "next sibling first child"? [same for sdef/pdef "desc"]
- return `${content}
${
+ return `${content}
${
isAbstract ? " (abstract role) " : ""
} \n- ${desc}
\n`;
};
From b15ab4fed7ff7dcb17e10e2167841ecf5f58a082 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 11:57:15 +0100
Subject: [PATCH 38/93] refactor(aria.js): simplify rdef loop
Resolves TODO item by replacing title and pnId with content.
Also replaces innerHTML with innerText because it is more sensible for use as ID.
test.sh run is clean.
---
script/aria.js | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index a4c2e63..d40128b 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -295,13 +295,8 @@ function ariaAttributeReferences() {
const roleIndex = [...rdefs].map(generateHTMLRoleIndexEntry).join("");
rdefs.forEach(function (item) {
const container = item.parentNode;
- const content = item.innerHTML;
- let title = item.getAttribute("title"); // TODO: no rdef has title (same for sdef, pdef)
- if (!title) {
- title = content;
- }
- const pnID = title;
- container.id = pnID;
+ const content = item.innerText;
+ container.id = content;
// is this a role or an abstract role
let isAbstract = false;
const abstract = container.querySelectorAll(".role-abstract"); //TODO: maybe #105
@@ -344,13 +339,13 @@ function ariaAttributeReferences() {
// remember that the state or property is
// referenced by this role
- propList[name].roles.push(title);
+ propList[name].roles.push(content);
});
}
});
- roleInfo[title] = {
- name: title,
- fragID: pnID,
+ roleInfo[content] = {
+ name: content,
+ fragID: content,
parentRoles: parentRoles,
localprops: attrs,
};
@@ -371,7 +366,7 @@ function ariaAttributeReferences() {
if (node.textContent.indexOf("author") !== -1) {
fromAuthor +=
'' +
content +
"
" +
@@ -381,7 +376,7 @@ function ariaAttributeReferences() {
if (node.textContent.indexOf("heading") !== -1) {
fromHeading +=
'' +
content +
"
" +
@@ -394,7 +389,7 @@ function ariaAttributeReferences() {
) {
fromContent +=
'' +
content +
"
" +
@@ -404,7 +399,7 @@ function ariaAttributeReferences() {
if (node.textContent.indexOf("prohibited") !== -1) {
fromProhibited +=
'' +
content +
"
" +
From 77a3472974d0bdb01022dc15f609a66e9e9bf66c Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 12:05:06 +0100
Subject: [PATCH 39/93] refactor(aria.js): minor tweak
Tightens declaration and adds TODO.
test.sh run is clean.
---
script/aria.js | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index d40128b..a6d9e06 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -318,10 +318,8 @@ function ariaAttributeReferences() {
if (node.innerText.length !== 1) {
// looks like we do
node.querySelectorAll("pref,sref").forEach(function (item) {
- let name = item.getAttribute("title");
- if (!name) {
- name = item.innerText;
- }
+ const name =
+ item.getAttribute("title") || item.innerText; // TODO: tests indicate both are needed but why?
const type =
item.localName === "pref" ? "property" : "state";
const req = node.classList.contains(
From 1ed03b9fffd62ec563f0a83f131c2072fb395bf0 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 12:16:02 +0100
Subject: [PATCH 40/93] refactor(aria.js): minor tweak
Drops unnecessary if check.
test.sh run is clean.
---
script/aria.js | 45 +++++++++++++++++++++------------------------
1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index a6d9e06..dca62c1 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -315,31 +315,28 @@ function ariaAttributeReferences() {
".role-properties, .role-required-properties, .role-disallowed"
)
.forEach(function (node) {
- if (node.innerText.length !== 1) {
- // looks like we do
- node.querySelectorAll("pref,sref").forEach(function (item) {
- const name =
- item.getAttribute("title") || item.innerText; // TODO: tests indicate both are needed but why?
- const type =
- item.localName === "pref" ? "property" : "state";
- const req = node.classList.contains(
- "role-required-properties"
- );
- const dis = node.classList.contains("role-disallowed");
- const dep = item.hasAttribute("data-deprecated");
- attrs.push({
- is: type,
- name: name,
- required: req,
- disallowed: dis,
- deprecated: dep,
- });
-
- // remember that the state or property is
- // referenced by this role
- propList[name].roles.push(content);
+ // looks like we do
+ node.querySelectorAll("pref,sref").forEach(function (item) {
+ const name = item.getAttribute("title") || item.innerText; // TODO: tests indicate both are needed but why?
+ const type =
+ item.localName === "pref" ? "property" : "state";
+ const req = node.classList.contains(
+ "role-required-properties"
+ );
+ const dis = node.classList.contains("role-disallowed");
+ const dep = item.hasAttribute("data-deprecated");
+ attrs.push({
+ is: type,
+ name: name,
+ required: req,
+ disallowed: dis,
+ deprecated: dep,
});
- }
+
+ // remember that the state or property is
+ // referenced by this role
+ propList[name].roles.push(content);
+ });
});
roleInfo[content] = {
name: content,
From e4146cb586179f2ae2eb88e47994347dc4979e16 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 12:25:42 +0100
Subject: [PATCH 41/93] refactor(aria.js): improve rdef loop
Move propList modifications out of "attrs loop".
test.sh run is clean.
---
script/aria.js | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index dca62c1..31352bc 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -332,12 +332,20 @@ function ariaAttributeReferences() {
disallowed: dis,
deprecated: dep,
});
-
- // remember that the state or property is
- // referenced by this role
- propList[name].roles.push(content);
});
});
+ // remember that the state or property is
+ // referenced by this role
+ container
+ .querySelectorAll(
+ `:is(.role-properties, .role-required-properties, .role-disallowed) :is(pref, sref)`
+ )
+ .forEach((node) =>
+ propList[
+ node.getAttribute("title") || node.innerText
+ ].roles.push(content)
+ );
+
roleInfo[content] = {
name: content,
fragID: content,
From 9e95d925213d0d418c8b28f565ccdc457a1d1350 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 12:48:07 +0100
Subject: [PATCH 42/93] refactor(aria.js): improve rdef loop
Refactor "attrs loop" to select sdef/rdef and lookup req/dis.
test.sh run is clean.
---
script/aria.js | 32 +++++++++++++-------------------
1 file changed, 13 insertions(+), 19 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 31352bc..268f6c7 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -312,26 +312,20 @@ function ariaAttributeReferences() {
const attrs = [];
container
.querySelectorAll(
- ".role-properties, .role-required-properties, .role-disallowed"
+ `:is(.role-properties, .role-required-properties, .role-disallowed) :is(pref, sref)`
)
- .forEach(function (node) {
- // looks like we do
- node.querySelectorAll("pref,sref").forEach(function (item) {
- const name = item.getAttribute("title") || item.innerText; // TODO: tests indicate both are needed but why?
- const type =
- item.localName === "pref" ? "property" : "state";
- const req = node.classList.contains(
- "role-required-properties"
- );
- const dis = node.classList.contains("role-disallowed");
- const dep = item.hasAttribute("data-deprecated");
- attrs.push({
- is: type,
- name: name,
- required: req,
- disallowed: dis,
- deprecated: dep,
- });
+ .forEach(function (item) {
+ const name = item.getAttribute("title") || item.innerText; // TODO: tests indicate both are needed but why?
+ const type = item.localName === "pref" ? "property" : "state";
+ const req = item.closest(".role-required-properties");
+ const dis = item.closest(".role-disallowed");
+ const dep = item.hasAttribute("data-deprecated");
+ attrs.push({
+ is: type,
+ name: name,
+ required: req,
+ disallowed: dis,
+ deprecated: dep,
});
});
// remember that the state or property is
From 65d3cd097383c98758c3f8526ba7582007051675 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 12:49:38 +0100
Subject: [PATCH 43/93] refactor(aria.js): improve rdef loop
Re-use querySelectorAll.
test.sh run is clean.
---
script/aria.js | 45 ++++++++++++++++++++-------------------------
1 file changed, 20 insertions(+), 25 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 268f6c7..ee07768 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -310,35 +310,30 @@ function ariaAttributeReferences() {
const parentRoles = [...rrefs].map((rref) => rref.innerText);
// are there supported states / properties in this role?
const attrs = [];
- container
- .querySelectorAll(
- `:is(.role-properties, .role-required-properties, .role-disallowed) :is(pref, sref)`
- )
- .forEach(function (item) {
- const name = item.getAttribute("title") || item.innerText; // TODO: tests indicate both are needed but why?
- const type = item.localName === "pref" ? "property" : "state";
- const req = item.closest(".role-required-properties");
- const dis = item.closest(".role-disallowed");
- const dep = item.hasAttribute("data-deprecated");
- attrs.push({
- is: type,
- name: name,
- required: req,
- disallowed: dis,
- deprecated: dep,
- });
+ const PSDefs = container.querySelectorAll(
+ `:is(.role-properties, .role-required-properties, .role-disallowed) :is(pref, sref)`
+ );
+ PSDefs.forEach(function (item) {
+ const name = item.getAttribute("title") || item.innerText; // TODO: tests indicate both are needed but why?
+ const type = item.localName === "pref" ? "property" : "state";
+ const req = item.closest(".role-required-properties");
+ const dis = item.closest(".role-disallowed");
+ const dep = item.hasAttribute("data-deprecated");
+ attrs.push({
+ is: type,
+ name: name,
+ required: req,
+ disallowed: dis,
+ deprecated: dep,
});
+ });
// remember that the state or property is
// referenced by this role
- container
- .querySelectorAll(
- `:is(.role-properties, .role-required-properties, .role-disallowed) :is(pref, sref)`
+ PSDefs.forEach((node) =>
+ propList[node.getAttribute("title") || node.innerText].roles.push(
+ content
)
- .forEach((node) =>
- propList[
- node.getAttribute("title") || node.innerText
- ].roles.push(content)
- );
+ );
roleInfo[content] = {
name: content,
From b6551d0c4530ec37de95d4dfcbc58e60b1e93392 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 12:51:26 +0100
Subject: [PATCH 44/93] refactor(aria.js): improve rdef loop
Calculate attrs via map.
test.sh run is clean.
---
script/aria.js | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index ee07768..ee666a3 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -309,23 +309,22 @@ function ariaAttributeReferences() {
const rrefs = container.querySelectorAll(".role-parent rref");
const parentRoles = [...rrefs].map((rref) => rref.innerText);
// are there supported states / properties in this role?
- const attrs = [];
const PSDefs = container.querySelectorAll(
`:is(.role-properties, .role-required-properties, .role-disallowed) :is(pref, sref)`
);
- PSDefs.forEach(function (item) {
+ const attrs = [...PSDefs].map(function (item) {
const name = item.getAttribute("title") || item.innerText; // TODO: tests indicate both are needed but why?
const type = item.localName === "pref" ? "property" : "state";
const req = item.closest(".role-required-properties");
const dis = item.closest(".role-disallowed");
const dep = item.hasAttribute("data-deprecated");
- attrs.push({
+ return {
is: type,
name: name,
required: req,
disallowed: dis,
deprecated: dep,
- });
+ };
});
// remember that the state or property is
// referenced by this role
From 5c40cc617ec845b2fd898b1ad14a9b89e33cffd8 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 12:55:31 +0100
Subject: [PATCH 45/93] refactor(aria.js): rdef loop states&props extraction as
function
Moves function used for attrs creation into global scope.
test.sh run is clean.
---
script/aria.js | 35 +++++++++++++++++++++--------------
1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index ee666a3..536f1b4 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -243,6 +243,26 @@ const populateSubRoles = (subRoles, rdef) => {
});
};
+/**
+ *
+ * @param {HTMLElement} item - sdef or pdef inside rdef Characteristics table
+ * @returns
+ */
+const extractStatesProperties = function (item) {
+ const name = item.getAttribute("title") || item.innerText; // TODO: tests indicate both are needed but why?
+ const type = item.localName === "pref" ? "property" : "state";
+ const req = item.closest(".role-required-properties");
+ const dis = item.closest(".role-disallowed");
+ const dep = item.hasAttribute("data-deprecated");
+ return {
+ is: type,
+ name: name,
+ required: req,
+ disallowed: dis,
+ deprecated: dep,
+ };
+};
+
function ariaAttributeReferences() {
const propList = {};
const globalSP = [];
@@ -312,20 +332,7 @@ function ariaAttributeReferences() {
const PSDefs = container.querySelectorAll(
`:is(.role-properties, .role-required-properties, .role-disallowed) :is(pref, sref)`
);
- const attrs = [...PSDefs].map(function (item) {
- const name = item.getAttribute("title") || item.innerText; // TODO: tests indicate both are needed but why?
- const type = item.localName === "pref" ? "property" : "state";
- const req = item.closest(".role-required-properties");
- const dis = item.closest(".role-disallowed");
- const dep = item.hasAttribute("data-deprecated");
- return {
- is: type,
- name: name,
- required: req,
- disallowed: dis,
- deprecated: dep,
- };
- });
+ const attrs = [...PSDefs].map(extractStatesProperties);
// remember that the state or property is
// referenced by this role
PSDefs.forEach((node) =>
From fd67862099fb02cfa90c7ab24142d50623e5b680 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 13:14:03 +0100
Subject: [PATCH 46/93] refactor(aria.js): improve rdef loop
Prepare "name from" loop for extraction
* make "is required" check self-contained
* DRY the html string
* add TODO
test.sh run is clean.
---
script/aria.js | 52 +++++++++++++-------------------------------------
1 file changed, 13 insertions(+), 39 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 536f1b4..6d825da 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -354,56 +354,30 @@ function ariaAttributeReferences() {
container
.querySelectorAll(".role-namefrom")
.forEach(function (node) {
- const reqRef =
- container.querySelector(".role-namerequired");
- let req = "";
- if (reqRef && reqRef.innerText === "True") {
- req = " (name required)";
- }
-
+ const isRequired =
+ node
+ .closest("table")
+ .querySelector(".role-namerequired")?.innerText ===
+ "True";
+ const liString = `${content}
${
+ isRequired ? " (name required)" : ""
+ } `;
if (node.textContent.indexOf("author") !== -1) {
- fromAuthor +=
- '' +
- content +
- "
" +
- req +
- " ";
+ fromAuthor += liString;
}
if (node.textContent.indexOf("heading") !== -1) {
- fromHeading +=
- '' +
- content +
- "
" +
- req +
- " ";
+ fromHeading += liString;
}
if (
!isAbstract &&
node.textContent.indexOf("content") !== -1
) {
- fromContent +=
- '' +
- content +
- "
" +
- req +
- " ";
+ fromContent += liString;
}
if (node.textContent.indexOf("prohibited") !== -1) {
- fromProhibited +=
- '' +
- content +
- "
" +
- req +
- " ";
+ fromProhibited += liString;
}
+ // TODO: Above: `textContent.indexOf` feels brittle; right now it's either the exact string or proper list markup with LI with exact strin
});
}
});
From 5b0e99eed3187077216758598d56eea5667bfb50 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 14:45:43 +0100
Subject: [PATCH 47/93] refactor(aria.js): improve rdef loop
Remove unecessary loop for "name from";
there should only be at most 1 name from table cell
test.sh run is clean.
---
script/aria.js | 54 +++++++++++++++++++++++---------------------------
1 file changed, 25 insertions(+), 29 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 6d825da..b3e6282 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -350,35 +350,31 @@ function ariaAttributeReferences() {
// is there a namefrom indication? If so, add this one to
// the list
- if (!isAbstract) {
- container
- .querySelectorAll(".role-namefrom")
- .forEach(function (node) {
- const isRequired =
- node
- .closest("table")
- .querySelector(".role-namerequired")?.innerText ===
- "True";
- const liString = `${content}
${
- isRequired ? " (name required)" : ""
- } `;
- if (node.textContent.indexOf("author") !== -1) {
- fromAuthor += liString;
- }
- if (node.textContent.indexOf("heading") !== -1) {
- fromHeading += liString;
- }
- if (
- !isAbstract &&
- node.textContent.indexOf("content") !== -1
- ) {
- fromContent += liString;
- }
- if (node.textContent.indexOf("prohibited") !== -1) {
- fromProhibited += liString;
- }
- // TODO: Above: `textContent.indexOf` feels brittle; right now it's either the exact string or proper list markup with LI with exact strin
- });
+ const roleFromNode = container.querySelector(".role-namefrom");
+ if (!isAbstract && roleFromNode) {
+ const isRequired =
+ roleFromNode
+ .closest("table")
+ .querySelector(".role-namerequired")?.innerText === "True";
+ const liString = `${content}
${
+ isRequired ? " (name required)" : ""
+ } `;
+ if (roleFromNode.textContent.indexOf("author") !== -1) {
+ fromAuthor += liString;
+ }
+ if (roleFromNode.textContent.indexOf("heading") !== -1) {
+ fromHeading += liString;
+ }
+ if (
+ !isAbstract &&
+ roleFromNode.textContent.indexOf("content") !== -1
+ ) {
+ fromContent += liString;
+ }
+ if (roleFromNode.textContent.indexOf("prohibited") !== -1) {
+ fromProhibited += liString;
+ }
+ // TODO: Above: `textContent.indexOf` feels brittle; right now it's either the exact string or proper list markup with LI with exact string
}
});
From 44fc130a2bb6d531e8ecb2d79d3ac4b8308b7a1d Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 14:46:41 +0100
Subject: [PATCH 48/93] refactor(aria.js): improve rdef loop "name from"
Move isAbstract calculation to "name from".
test.sh run is clean.
---
script/aria.js | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index b3e6282..cf2a54b 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -317,12 +317,6 @@ function ariaAttributeReferences() {
const container = item.parentNode;
const content = item.innerText;
container.id = content;
- // is this a role or an abstract role
- let isAbstract = false;
- const abstract = container.querySelectorAll(".role-abstract"); //TODO: maybe #105
- if (abstract.innerText === "True") {
- isAbstract = true;
- }
// grab info about this role
// do we have a parent class? if so, put us in that parents list
@@ -351,6 +345,12 @@ function ariaAttributeReferences() {
// is there a namefrom indication? If so, add this one to
// the list
const roleFromNode = container.querySelector(".role-namefrom");
+ // is this a role or an abstract role
+ let isAbstract = false;
+ const abstract = container.querySelectorAll(".role-abstract"); //TODO: maybe #105
+ if (abstract.innerText === "True") {
+ isAbstract = true;
+ }
if (!isAbstract && roleFromNode) {
const isRequired =
roleFromNode
From d279f599c15afbab7fdfb1b67bba87caebedf1a8 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 16:05:14 +0100
Subject: [PATCH 49/93] refactor(aria.js): extract nameFrom indices
Moves LI string generation into a function in the main scope;
minor tweaks to use rdef instead of container.
Builds nameFrom indices with map+join.
test.sh run is clean.
---
script/aria.js | 81 ++++++++++++++++++++++++++------------------------
1 file changed, 42 insertions(+), 39 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index cf2a54b..1963c7f 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -263,6 +263,34 @@ const extractStatesProperties = function (item) {
};
};
+/**
+ *
+ * @param {String} indexTest - string to decide if this index needs it
+ * @param {HTMLElement} rdef - rdef node
+ */
+const generateHTMLNameFromIndices = (indexTest, rdef) => {
+ const container = rdef.parentNode;
+ // is there a namefrom indication? If so, add this one to
+ // the list
+ const roleFromNode = container.querySelector(".role-namefrom");
+ // is this a role or an abstract role
+ let isAbstract = false;
+ const abstract = container.querySelectorAll(".role-abstract"); //TODO: maybe #105
+ if (abstract.innerText === "True") {
+ isAbstract = true;
+ }
+ if (!isAbstract && roleFromNode) {
+ const content = rdef.innerText;
+ const isRequired =
+ roleFromNode.closest("table").querySelector(".role-namerequired")
+ ?.innerText === "True";
+ if (roleFromNode.textContent.indexOf(indexTest) !== -1)
+ return `${content}
${
+ isRequired ? " (name required)" : ""
+ } `; // TODO: `textContent.indexOf` feels brittle; right now it's either the exact string or proper list markup with LI with exact string
+ }
+};
+
function ariaAttributeReferences() {
const propList = {};
const globalSP = [];
@@ -303,15 +331,25 @@ function ariaAttributeReferences() {
//
const subRoles = [];
- let fromAuthor = "";
- let fromHeading = "";
- let fromContent = "";
- let fromProhibited = "";
const rdefs = document.querySelectorAll("rdef");
const rdefsContainer = [...rdefs].map((node) => node.parentNode);
rdefs.forEach(populateSubRoles.bind(null, subRoles));
+
+ let fromAuthor = [...rdefs]
+ .map(generateHTMLNameFromIndices.bind(null, "author"))
+ .join("");
+ let fromHeading = [...rdefs]
+ .map(generateHTMLNameFromIndices.bind(null, "heading"))
+ .join("");
+ let fromContent = [...rdefs]
+ .map(generateHTMLNameFromIndices.bind(null, "content"))
+ .join("");
+ let fromProhibited = [...rdefs]
+ .map(generateHTMLNameFromIndices.bind(null, "prohibited"))
+ .join("");
+
const roleIndex = [...rdefs].map(generateHTMLRoleIndexEntry).join("");
rdefs.forEach(function (item) {
const container = item.parentNode;
@@ -341,41 +379,6 @@ function ariaAttributeReferences() {
parentRoles: parentRoles,
localprops: attrs,
};
-
- // is there a namefrom indication? If so, add this one to
- // the list
- const roleFromNode = container.querySelector(".role-namefrom");
- // is this a role or an abstract role
- let isAbstract = false;
- const abstract = container.querySelectorAll(".role-abstract"); //TODO: maybe #105
- if (abstract.innerText === "True") {
- isAbstract = true;
- }
- if (!isAbstract && roleFromNode) {
- const isRequired =
- roleFromNode
- .closest("table")
- .querySelector(".role-namerequired")?.innerText === "True";
- const liString = `${content}
${
- isRequired ? " (name required)" : ""
- } `;
- if (roleFromNode.textContent.indexOf("author") !== -1) {
- fromAuthor += liString;
- }
- if (roleFromNode.textContent.indexOf("heading") !== -1) {
- fromHeading += liString;
- }
- if (
- !isAbstract &&
- roleFromNode.textContent.indexOf("content") !== -1
- ) {
- fromContent += liString;
- }
- if (roleFromNode.textContent.indexOf("prohibited") !== -1) {
- fromProhibited += liString;
- }
- // TODO: Above: `textContent.indexOf` feels brittle; right now it's either the exact string or proper list markup with LI with exact string
- }
});
rdefs.forEach(rewriteRdef);
From 10a65a56030259c0d33c1fa011402073cf2a1983 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 16:46:00 +0100
Subject: [PATCH 50/93] refactor(aria.js): extract rest of rdef loop (roleInfo,
propList)
Moves remaining rdef loop into a function in the main scope.
test.sh run is clean.
---
script/aria.js | 67 ++++++++++++++++++++++++++++----------------------
1 file changed, 38 insertions(+), 29 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 1963c7f..0ba881b 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -291,6 +291,43 @@ const generateHTMLNameFromIndices = (indexTest, rdef) => {
}
};
+/**
+ * Populates roleInfo and updates proplist alongside it
+ * TODO: separate out propList updates
+ * @param {Object} roleInfo - the roleInfo object
+ * @param {Object} propList - the "list" of properties
+ * @param {HTMLElement} item - an rdef node
+ */
+const populateRoleInfoPropList = function (roleInfo, propList, item) {
+ const container = item.parentNode;
+ const content = item.innerText;
+ container.id = content;
+
+ // grab info about this role
+ // do we have a parent class? if so, put us in that parents list
+ const rrefs = container.querySelectorAll(".role-parent rref");
+ const parentRoles = [...rrefs].map((rref) => rref.innerText);
+ // are there supported states / properties in this role?
+ const PSDefs = container.querySelectorAll(
+ `:is(.role-properties, .role-required-properties, .role-disallowed) :is(pref, sref)`
+ );
+ const attrs = [...PSDefs].map(extractStatesProperties);
+ // remember that the state or property is
+ // referenced by this role
+ PSDefs.forEach((node) =>
+ propList[node.getAttribute("title") || node.innerText].roles.push(
+ content
+ )
+ );
+
+ roleInfo[content] = {
+ name: content,
+ fragID: content,
+ parentRoles: parentRoles,
+ localprops: attrs,
+ };
+};
+
function ariaAttributeReferences() {
const propList = {};
const globalSP = [];
@@ -351,35 +388,7 @@ function ariaAttributeReferences() {
.join("");
const roleIndex = [...rdefs].map(generateHTMLRoleIndexEntry).join("");
- rdefs.forEach(function (item) {
- const container = item.parentNode;
- const content = item.innerText;
- container.id = content;
-
- // grab info about this role
- // do we have a parent class? if so, put us in that parents list
- const rrefs = container.querySelectorAll(".role-parent rref");
- const parentRoles = [...rrefs].map((rref) => rref.innerText);
- // are there supported states / properties in this role?
- const PSDefs = container.querySelectorAll(
- `:is(.role-properties, .role-required-properties, .role-disallowed) :is(pref, sref)`
- );
- const attrs = [...PSDefs].map(extractStatesProperties);
- // remember that the state or property is
- // referenced by this role
- PSDefs.forEach((node) =>
- propList[node.getAttribute("title") || node.innerText].roles.push(
- content
- )
- );
-
- roleInfo[content] = {
- name: content,
- fragID: content,
- parentRoles: parentRoles,
- localprops: attrs,
- };
- });
+ rdefs.forEach(populateRoleInfoPropList.bind(null, roleInfo, propList));
rdefs.forEach(rewriteRdef);
From 75a9833fc73c0dcccb4a726e8f35ecfd050958ee Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 16:47:38 +0100
Subject: [PATCH 51/93] fix(test.sh): clear before/after html at start
---
test.sh | 1 +
1 file changed, 1 insertion(+)
diff --git a/test.sh b/test.sh
index 6531754..aa27850 100644
--- a/test.sh
+++ b/test.sh
@@ -2,6 +2,7 @@
# NOTE: Assumes there's a copy of w3c/aria in ../aria/
+rm before.html after.html
echo "Run respec on ../aria/index.html to generate 'before.html'"
npx respec --src ../aria/index.html --out before.html
echo "Copy ./script/aria.js to ../aria/common/script/"
From 9790d41a7bd680014ff33593b5a5e54233168e30 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 16:51:40 +0100
Subject: [PATCH 52/93] refactor(aria.js): move getStates() to global scope
Also adds TODO note.
test.sh run is clean.
---
script/aria.js | 39 ++++++++++++++++++++++-----------------
1 file changed, 22 insertions(+), 17 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 0ba881b..bc627b2 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -328,6 +328,28 @@ const populateRoleInfoPropList = function (roleInfo, propList, item) {
};
};
+/**
+ * TODO: depends on global roleInfo object
+ * @param {string} role - name of a role
+ * @returns
+ */
+const getStates = function (role) {
+ const ref = roleInfo[role];
+ if (!ref) {
+ msg.pub("error", "No role definition for " + role);
+ } else if (ref.allprops) {
+ return ref.allprops;
+ } else {
+ let myList = ref.localprops;
+ ref.parentRoles.forEach(function (item) {
+ const pList = getStates(item);
+ myList = myList.concat(pList);
+ });
+ ref.allprops = myList;
+ return myList;
+ }
+};
+
function ariaAttributeReferences() {
const propList = {};
const globalSP = [];
@@ -394,23 +416,6 @@ function ariaAttributeReferences() {
rdefsContainer.forEach(rewriteDefContainer);
- const getStates = function (role) {
- const ref = roleInfo[role];
- if (!ref) {
- msg.pub("error", "No role definition for " + role);
- } else if (ref.allprops) {
- return ref.allprops;
- } else {
- let myList = ref.localprops;
- ref.parentRoles.forEach(function (item) {
- const pList = getStates(item);
- myList = myList.concat(pList);
- });
- ref.allprops = myList;
- return myList;
- }
- };
-
// TODO: test this on a page where `skipIndex` is truthy
if (!skipIndex) {
// build up the complete inherited SP lists for each role
From b0ae5220f179597c8656ef9e2f69fb65b97cc6b0 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 17:12:36 +0100
Subject: [PATCH 53/93] refactor(aria.js): extract roleInfo's inherited
State&Props
Straight forward extraction.
test.sh run is clean.
---
script/aria.js | 159 ++++++++++++++++++++++++-------------------------
1 file changed, 79 insertions(+), 80 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index bc627b2..7596486 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -350,6 +350,84 @@ const getStates = function (role) {
}
};
+/**
+ * Builds up the complete inherited SP lists for each role
+ * However, if the role already specifies an item, do not include it
+ * @param {Object} index - key value pair from Object.entries(roleInfo)
+ */
+const buildInheritedStatesProperties = function (index) {
+ const item = index[1];
+ let output = "";
+ const placeholder = document.querySelector(
+ "#" + item.fragID + " .role-inherited"
+ );
+
+ if (placeholder) {
+ let myList = [];
+ item.parentRoles.forEach(function (role) {
+ myList = myList.concat(getStates(role));
+ });
+ // strip out any items that we have locally
+ if (item.localprops.length && myList.length) {
+ for (let j = myList.length - 1; j >= 0; j--) {
+ item.localprops.forEach(function (x) {
+ if (x.name == myList[j].name) {
+ myList.splice(j, 1);
+ }
+ });
+ }
+ }
+
+ const reducedList = myList.reduce((uniqueList, item) => {
+ return uniqueList.includes(item)
+ ? uniqueList
+ : [...uniqueList, item];
+ }, []);
+
+ const sortedList = reducedList.sort((a, b) => {
+ if (a.name == b.name) {
+ // Ensure deprecated false properties occur first
+ if (a.deprecated !== b.deprecated) {
+ return a.deprecated ? 1 : b.deprecated ? -1 : 0;
+ }
+ }
+ return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
+ }, []);
+
+ let prev;
+ for (let k = 0; k < sortedList.length; k++) {
+ const property = sortedList[k];
+ let req = "";
+ let dep = "";
+ if (property.required) {
+ req = " (required)";
+ }
+ if (property.deprecated) {
+ dep = " (deprecated on this role in ARIA 1.2)";
+ }
+ if (prev != property.name) {
+ output += "- ";
+ if (property.is === "state") {
+ output +=
+ "" +
+ property.name +
+ " (state)" +
+ req +
+ dep;
+ } else {
+ output += "" + property.name + "" + req + dep;
+ }
+ output += "
\n";
+ prev = property.name;
+ }
+ }
+ if (output !== "") {
+ output = "\n";
+ placeholder.innerHTML = output;
+ }
+ }
+};
+
function ariaAttributeReferences() {
const propList = {};
const globalSP = [];
@@ -418,86 +496,7 @@ function ariaAttributeReferences() {
// TODO: test this on a page where `skipIndex` is truthy
if (!skipIndex) {
- // build up the complete inherited SP lists for each role
- // however, if the role already specifies an item, do not include it
- Object.entries(roleInfo).forEach(function (index) {
- const item = index[1];
- let output = "";
- const placeholder = document.querySelector(
- "#" + item.fragID + " .role-inherited"
- );
-
- if (placeholder) {
- let myList = [];
- item.parentRoles.forEach(function (role) {
- myList = myList.concat(getStates(role));
- });
- // strip out any items that we have locally
- if (item.localprops.length && myList.length) {
- for (let j = myList.length - 1; j >= 0; j--) {
- item.localprops.forEach(function (x) {
- if (x.name == myList[j].name) {
- myList.splice(j, 1);
- }
- });
- }
- }
-
- const reducedList = myList.reduce((uniqueList, item) => {
- return uniqueList.includes(item)
- ? uniqueList
- : [...uniqueList, item];
- }, []);
-
- const sortedList = reducedList.sort((a, b) => {
- if (a.name == b.name) {
- // Ensure deprecated false properties occur first
- if (a.deprecated !== b.deprecated) {
- return a.deprecated ? 1 : b.deprecated ? -1 : 0;
- }
- }
- return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
- }, []);
-
- let prev;
- for (let k = 0; k < sortedList.length; k++) {
- const property = sortedList[k];
- let req = "";
- let dep = "";
- if (property.required) {
- req = " (required)";
- }
- if (property.deprecated) {
- dep =
- " (deprecated on this role in ARIA 1.2)";
- }
- if (prev != property.name) {
- output += "- ";
- if (property.is === "state") {
- output +=
- "" +
- property.name +
- " (state)" +
- req +
- dep;
- } else {
- output +=
- "" +
- property.name +
- "" +
- req +
- dep;
- }
- output += "
\n";
- prev = property.name;
- }
- }
- if (output !== "") {
- output = "\n";
- placeholder.innerHTML = output;
- }
- }
- });
+ Object.entries(roleInfo).forEach(buildInheritedStatesProperties);
// Update state and property role references
const getAllSubRoles = function (role) {
From e21855ef9e70354aa9376d2b001182cad725a0cd Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 18:04:40 +0100
Subject: [PATCH 54/93] refactor(aria.js): revise
buildInheritedStatesProperties
Return early.
test.sh run is clean.
---
script/aria.js | 109 +++++++++++++++++++++++--------------------------
1 file changed, 51 insertions(+), 58 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 7596486..ec18915 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -361,70 +361,63 @@ const buildInheritedStatesProperties = function (index) {
const placeholder = document.querySelector(
"#" + item.fragID + " .role-inherited"
);
+ if (!placeholder) return;
- if (placeholder) {
- let myList = [];
- item.parentRoles.forEach(function (role) {
- myList = myList.concat(getStates(role));
- });
- // strip out any items that we have locally
- if (item.localprops.length && myList.length) {
- for (let j = myList.length - 1; j >= 0; j--) {
- item.localprops.forEach(function (x) {
- if (x.name == myList[j].name) {
- myList.splice(j, 1);
- }
- });
- }
+ let myList = [];
+ item.parentRoles.forEach(function (role) {
+ myList = myList.concat(getStates(role));
+ });
+ // strip out any items that we have locally
+ if (item.localprops.length && myList.length) {
+ for (let j = myList.length - 1; j >= 0; j--) {
+ item.localprops.forEach(function (x) {
+ if (x.name == myList[j].name) {
+ myList.splice(j, 1);
+ }
+ });
}
+ }
- const reducedList = myList.reduce((uniqueList, item) => {
- return uniqueList.includes(item)
- ? uniqueList
- : [...uniqueList, item];
- }, []);
-
- const sortedList = reducedList.sort((a, b) => {
- if (a.name == b.name) {
- // Ensure deprecated false properties occur first
- if (a.deprecated !== b.deprecated) {
- return a.deprecated ? 1 : b.deprecated ? -1 : 0;
- }
- }
- return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
- }, []);
-
- let prev;
- for (let k = 0; k < sortedList.length; k++) {
- const property = sortedList[k];
- let req = "";
- let dep = "";
- if (property.required) {
- req = " (required)";
- }
- if (property.deprecated) {
- dep = " (deprecated on this role in ARIA 1.2)";
- }
- if (prev != property.name) {
- output += "- ";
- if (property.is === "state") {
- output +=
- "" +
- property.name +
- " (state)" +
- req +
- dep;
- } else {
- output += "" + property.name + "" + req + dep;
- }
- output += "
\n";
- prev = property.name;
+ const reducedList = myList.reduce((uniqueList, item) => {
+ return uniqueList.includes(item) ? uniqueList : [...uniqueList, item];
+ }, []);
+
+ const sortedList = reducedList.sort((a, b) => {
+ if (a.name == b.name) {
+ // Ensure deprecated false properties occur first
+ if (a.deprecated !== b.deprecated) {
+ return a.deprecated ? 1 : b.deprecated ? -1 : 0;
}
}
- if (output !== "") {
- output = "\n";
- placeholder.innerHTML = output;
+ return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
+ }, []);
+
+ let prev;
+ for (let k = 0; k < sortedList.length; k++) {
+ const property = sortedList[k];
+ let req = "";
+ let dep = "";
+ if (property.required) {
+ req = " (required)";
+ }
+ if (property.deprecated) {
+ dep = " (deprecated on this role in ARIA 1.2)";
}
+ if (prev != property.name) {
+ output += "- ";
+ if (property.is === "state") {
+ output +=
+ "" + property.name + " (state)" + req + dep;
+ } else {
+ output += "" + property.name + "" + req + dep;
+ }
+ output += "
\n";
+ prev = property.name;
+ }
+ }
+ if (output !== "") {
+ output = "\n";
+ placeholder.innerHTML = output;
}
};
From 574ddfc1180525a4d22bd92acb1e84e20b505fc1 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 18:07:42 +0100
Subject: [PATCH 55/93] refactor(aria.js): revise
buildInheritedStatesProperties
Switch to Object.values since we do not use the key.
test.sh run is clean.
---
script/aria.js | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index ec18915..8865454 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -353,10 +353,9 @@ const getStates = function (role) {
/**
* Builds up the complete inherited SP lists for each role
* However, if the role already specifies an item, do not include it
- * @param {Object} index - key value pair from Object.entries(roleInfo)
+ * @param {Object} item - value from Object.values(roleInfo)
*/
-const buildInheritedStatesProperties = function (index) {
- const item = index[1];
+const buildInheritedStatesProperties = function (item) {
let output = "";
const placeholder = document.querySelector(
"#" + item.fragID + " .role-inherited"
@@ -489,7 +488,7 @@ function ariaAttributeReferences() {
// TODO: test this on a page where `skipIndex` is truthy
if (!skipIndex) {
- Object.entries(roleInfo).forEach(buildInheritedStatesProperties);
+ Object.values(roleInfo).forEach(buildInheritedStatesProperties);
// Update state and property role references
const getAllSubRoles = function (role) {
From f712c3524445289e21ba9d32196f9ee7005321bd Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 18:44:22 +0100
Subject: [PATCH 56/93] refactor(aria.js): revise
buildInheritedStatesProperties
Reduce using Set.
test.sh run is clean.
---
script/aria.js | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 8865454..080a1a0 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -377,9 +377,7 @@ const buildInheritedStatesProperties = function (item) {
}
}
- const reducedList = myList.reduce((uniqueList, item) => {
- return uniqueList.includes(item) ? uniqueList : [...uniqueList, item];
- }, []);
+ const reducedList = [...new Set(myList)];
const sortedList = reducedList.sort((a, b) => {
if (a.name == b.name) {
From 3de2e06724894412383e5afc54e2716843f8c0f1 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 18:50:39 +0100
Subject: [PATCH 57/93] refactor(aria.js): revise
buildInheritedStatesProperties
Begin refactoring output loop.
test.sh run is clean.
---
script/aria.js | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 080a1a0..7ccf956 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -390,8 +390,7 @@ const buildInheritedStatesProperties = function (item) {
}, []);
let prev;
- for (let k = 0; k < sortedList.length; k++) {
- const property = sortedList[k];
+ sortedList.forEach((property) => {
let req = "";
let dep = "";
if (property.required) {
@@ -411,7 +410,7 @@ const buildInheritedStatesProperties = function (item) {
output += " \n";
prev = property.name;
}
- }
+ });
if (output !== "") {
output = "\n";
placeholder.innerHTML = output;
From ec02902d5953157287210f6c90f703c98f5d3422 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 20:59:47 +0100
Subject: [PATCH 58/93] refactor(aria.js): revise
buildInheritedStatesProperties
Switch output creation to template strings and use map+join.
test.sh run is clean.
---
script/aria.js | 42 ++++++++++++++++++------------------------
1 file changed, 18 insertions(+), 24 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 7ccf956..e1ab01d 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -356,12 +356,12 @@ const getStates = function (role) {
* @param {Object} item - value from Object.values(roleInfo)
*/
const buildInheritedStatesProperties = function (item) {
- let output = "";
const placeholder = document.querySelector(
"#" + item.fragID + " .role-inherited"
);
if (!placeholder) return;
+ // TODO: simplify (from here until sortedList)
let myList = [];
item.parentRoles.forEach(function (role) {
myList = myList.concat(getStates(role));
@@ -389,31 +389,25 @@ const buildInheritedStatesProperties = function (item) {
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
}, []);
- let prev;
- sortedList.forEach((property) => {
- let req = "";
- let dep = "";
- if (property.required) {
- req = " (required)";
- }
- if (property.deprecated) {
- dep = " (deprecated on this role in ARIA 1.2)";
- }
- if (prev != property.name) {
- output += "- ";
- if (property.is === "state") {
- output +=
- "" + property.name + " (state)" + req + dep;
- } else {
- output += "" + property.name + "" + req + dep;
- }
- output += "
\n";
+ let prev; //TODO: get rid of "prev"
+ const output = sortedList
+ .map((property) => {
+ if (prev === property.name) return "";
prev = property.name;
- }
- });
+
+ const isState = property.is === "state";
+ const suffix = isState ? " (state)" : "";
+ const tag = isState ? "sref" : "pref";
+ const req = property.required ? " (required)" : "";
+ const dep = property.deprecated
+ ? " (deprecated on this role in ARIA 1.2)"
+ : "";
+
+ return `- <${tag}>${property.name}${tag}>${suffix}${req}${dep}
\n`;
+ })
+ .join("");
if (output !== "") {
- output = "\n";
- placeholder.innerHTML = output;
+ placeholder.innerHTML = `\n`;
}
};
From 91028b367954c8c478ad5144c40bd1cbe7788e55 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Tue, 12 Dec 2023 21:27:24 +0100
Subject: [PATCH 59/93] refactor(aria.js): improve propList loop
Starts from the end and tightens up HTML generation for the
last variation of placeholder.
test.sh run is clean.
---
script/aria.js | 23 ++++++++---------------
1 file changed, 8 insertions(+), 15 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index e1ab01d..09f0ac5 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -611,21 +611,14 @@ function ariaAttributeReferences() {
item.roles.length
) {
// for prohibited roles the roles list just includes those roles which are prohibited... weird I know but it is what it is
- let sortedList = [];
- sortedList = item.roles.sort();
- //remove roletype from the sorted list
- const index = sortedList.indexOf("roletype");
- if (index > -1) {
- sortedList.splice(index, 1);
- }
- output +=
- "All elements of the base markup except for the following roles: ";
- for (let j = 0; j < sortedList.length - 1; j++) {
- output += "" + sortedList[j] + ", ";
- }
- output +=
- "" + sortedList[sortedList.length - 1] + "";
- placeholder.innerHTML = output;
+ // exclude roletype from the sorted list
+ const sortedList = item.roles
+ .sort()
+ .filter((role) => role !== "roletype");
+
+ placeholder.innerHTML = `All elements of the base markup except for the following roles: ${sortedList
+ .map((role) => `${role}`)
+ .join(", ")}`;
}
});
From ff0d34d8efd191e6fa46df33b60755fc90363e8b Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 10:37:02 +0100
Subject: [PATCH 60/93] refactor(aria.js): improve propList loop
Continues from the end.
* Tightens up HTML generation for the (first part of the)
"deprecated in 1.2" placeholder.
* Since that identified a bad change (filter vs slice), fixes the
last placeholder back to changing item.roles in place.
test.sh run is clean.
---
script/aria.js | 27 ++++++++-------------------
1 file changed, 8 insertions(+), 19 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 09f0ac5..4580e06 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -556,22 +556,13 @@ function ariaAttributeReferences() {
"Use as a global deprecated in ARIA 1.2" &&
item.roles.length
) {
- // update the used in roles list
- let sortedList = [];
- sortedList = item.roles.sort();
- //remove roletype from the sorted list
- const index = sortedList.indexOf("roletype");
- if (index > -1) {
- sortedList.splice(index, 1);
- }
+ // update roles list (sort, remove roletype)
+ item.roles.sort().splice(item.roles.indexOf("roletype"), 1);
+ placeholder.innerHTML = `\n${item.roles
+ .map((role) => `- ${role}
\n`)
+ .join("")}
\n`;
- for (let j = 0; j < sortedList.length; j++) {
- output += "- " + sortedList[j] + "
\n";
- }
- if (output !== "") {
- output = "\n";
- }
- placeholder.innerHTML = output;
+ // BREAK -- different placeholder coming up
// also update any inherited roles
let myList = [];
item.roles.forEach(function (role) {
@@ -612,11 +603,9 @@ function ariaAttributeReferences() {
) {
// for prohibited roles the roles list just includes those roles which are prohibited... weird I know but it is what it is
// exclude roletype from the sorted list
- const sortedList = item.roles
- .sort()
- .filter((role) => role !== "roletype");
+ item.roles.sort().splice(item.roles.indexOf("roletype"), 1);
- placeholder.innerHTML = `All elements of the base markup except for the following roles: ${sortedList
+ placeholder.innerHTML = `All elements of the base markup except for the following roles: ${item.roles
.map((role) => `${role}`)
.join(", ")}`;
}
From 937c0a3ffee7948842007d1b4d04179a1035dafe Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 10:54:57 +0100
Subject: [PATCH 61/93] refactor(aria.js): improve propList loop
Continues from the end.
* Tightens up HTML generation for the second part of the
"deprecated in 1.2" placeholder.
* adds TODO for later
test.sh run is clean.
---
script/aria.js | 31 +++++++++++--------------------
1 file changed, 11 insertions(+), 20 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 4580e06..498cdb5 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -562,10 +562,13 @@ function ariaAttributeReferences() {
.map((role) => `- ${role}
\n`)
.join("")}
\n`;
- // BREAK -- different placeholder coming up
// also update any inherited roles
+ const placeholderInheritedRoles = section.querySelector(
+ ".state-descendants, .property-descendants"
+ );
let myList = [];
item.roles.forEach(function (role) {
+ // TODO: can we simplify this?
let children = getAllSubRoles(role);
// Some subroles have required properties which are also required by the superclass.
// Example: The checked state of radio, which is also required by superclass checkbox.
@@ -577,25 +580,13 @@ function ariaAttributeReferences() {
});
myList = myList.concat(children);
});
- placeholder = section.querySelector(
- ".state-descendants, .property-descendants"
- );
- if (placeholder && myList.length) {
- let sortedList = myList.sort();
- let output = "";
- let last = "";
- for (j = 0; j < sortedList.length; j++) {
- const sItem = sortedList[j];
- if (last != sItem) {
- output += "" + sItem + "\n";
- last = sItem;
- }
- }
- if (output !== "") {
- output = "\n";
- }
- placeholder.innerHTML = output;
- }
+ const output = [...new Set(myList)]
+ .sort()
+ .map((role) => `${role}\n`)
+ .join("");
+
+ if (output !== "")
+ placeholderInheritedRoles.innerHTML = `\n`;
} else if (
placeholder?.innerText ===
"All elements of the base markup except for some roles or elements that prohibit its use" &&
From 9dd9e0469ee1fbe723073e75b3c28e4308bf4458 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 12:05:06 +0100
Subject: [PATCH 62/93] refactor(aria.js): improve propList loop
* Tightens up HTML generation for the initial case "Placeholder"
* adds TODO for later
test.sh run is clean.
---
script/aria.js | 45 +++++++++++++++++----------------------------
1 file changed, 17 insertions(+), 28 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 498cdb5..860b22e 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -507,20 +507,21 @@ function ariaAttributeReferences() {
let placeholder = section.querySelector(
".state-applicability, .property-applicability"
);
+ // TODO: all three cases are near-identical. Can we do more?
if (placeholder?.innerText === "Placeholder" && item.roles.length) {
// update the used in roles list
- let sortedList = [];
- sortedList = item.roles.sort();
- for (let j = 0; j < sortedList.length; j++) {
- output += "" + sortedList[j] + "\n";
- }
- if (output !== "") {
- output = "\n";
- }
- placeholder.innerHTML = output;
+ item.roles.sort();
+ placeholder.innerHTML = `\n${item.roles
+ .map((role) => `- ${role}
\n`)
+ .join("")}
\n`;
+
// also update any inherited roles
+ const placeholderInheritedRoles = section.querySelector(
+ ".state-descendants, .property-descendants"
+ );
let myList = [];
item.roles.forEach(function (role) {
+ // TODO: can we simplify this?
let children = getAllSubRoles(role);
// Some subroles have required properties which are also required by the superclass.
// Example: The checked state of radio, which is also required by superclass checkbox.
@@ -532,25 +533,13 @@ function ariaAttributeReferences() {
});
myList = myList.concat(children);
});
- placeholder = section.querySelector(
- ".state-descendants, .property-descendants"
- );
- if (placeholder && myList.length) {
- sortedList = myList.sort();
- output = "";
- let last = "";
- for (let j = 0; j < sortedList.length; j++) {
- var sItem = sortedList[j];
- if (last != sItem) {
- output += "" + sItem + "\n";
- last = sItem;
- }
- }
- if (output !== "") {
- output = "\n";
- }
- placeholder.innerHTML = output;
- }
+ const output = [...new Set(myList)]
+ .sort()
+ .map((role) => `${role}\n`)
+ .join("");
+
+ if (output !== "")
+ placeholderInheritedRoles.innerHTML = `\n`;
} else if (
placeholder?.innerText ===
"Use as a global deprecated in ARIA 1.2" &&
From f490ec9c37f76dc8d4669e845eb9216bfd0ec4c1 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 12:06:43 +0100
Subject: [PATCH 63/93] refactor(aria.js): improve propList loop
* switch from Object.entries to .values (and adjust)
* remove now unused output variable.
test.sh run is clean.
---
script/aria.js | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 860b22e..ab77c06 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -500,9 +500,7 @@ function ariaAttributeReferences() {
}
};
- Object.entries(propList).forEach(function (index) {
- let output = "";
- const item = index[1];
+ Object.values(propList).forEach(function (item) {
const section = document.querySelector("#" + item.name);
let placeholder = section.querySelector(
".state-applicability, .property-applicability"
From 80bbb0783105f164ef082f2f821ad63b5d0d6268 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 12:23:09 +0100
Subject: [PATCH 64/93] refactor(aria.js): improve propList loop
Remove some unnecessary if-checks; there should always be
some roles and thus output.
test.sh run is clean.
---
script/aria.js | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index ab77c06..46f332f 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -506,7 +506,7 @@ function ariaAttributeReferences() {
".state-applicability, .property-applicability"
);
// TODO: all three cases are near-identical. Can we do more?
- if (placeholder?.innerText === "Placeholder" && item.roles.length) {
+ if (placeholder?.innerText === "Placeholder") {
// update the used in roles list
item.roles.sort();
placeholder.innerHTML = `\n${item.roles
@@ -531,17 +531,16 @@ function ariaAttributeReferences() {
});
myList = myList.concat(children);
});
- const output = [...new Set(myList)]
+
+ placeholderInheritedRoles.innerHTML = `\n${[
+ ...new Set(myList),
+ ]
.sort()
.map((role) => `- ${role}
\n`)
- .join("");
-
- if (output !== "")
- placeholderInheritedRoles.innerHTML = `\n`;
+ .join("")}
\n`;
} else if (
placeholder?.innerText ===
- "Use as a global deprecated in ARIA 1.2" &&
- item.roles.length
+ "Use as a global deprecated in ARIA 1.2"
) {
// update roles list (sort, remove roletype)
item.roles.sort().splice(item.roles.indexOf("roletype"), 1);
@@ -567,17 +566,15 @@ function ariaAttributeReferences() {
});
myList = myList.concat(children);
});
- const output = [...new Set(myList)]
+ placeholderInheritedRoles.innerHTML = `\n${[
+ ...new Set(myList),
+ ]
.sort()
.map((role) => `- ${role}
\n`)
- .join("");
-
- if (output !== "")
- placeholderInheritedRoles.innerHTML = `\n`;
+ .join("")}
\n`;
} else if (
placeholder?.innerText ===
- "All elements of the base markup except for some roles or elements that prohibit its use" &&
- item.roles.length
+ "All elements of the base markup except for some roles or elements that prohibit its use"
) {
// for prohibited roles the roles list just includes those roles which are prohibited... weird I know but it is what it is
// exclude roletype from the sorted list
From 0ff45982d9296808a1c6eb7bf2d509d71144fb4e Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 12:25:30 +0100
Subject: [PATCH 65/93] refactor(aria.js): improve propList loop
Move tweaking of roles list to top.
test.sh run is clean.
---
script/aria.js | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 46f332f..2eda00f 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -505,10 +505,12 @@ function ariaAttributeReferences() {
let placeholder = section.querySelector(
".state-applicability, .property-applicability"
);
+ // update roles list: sort, maybe remove roletype
+ item.roles.sort();
+ if (placeholder.innerText !== "Placeholder")
+ item.roles.splice(item.roles.indexOf("roletype"), 1);
// TODO: all three cases are near-identical. Can we do more?
if (placeholder?.innerText === "Placeholder") {
- // update the used in roles list
- item.roles.sort();
placeholder.innerHTML = `\n${item.roles
.map((role) => `- ${role}
\n`)
.join("")}
\n`;
@@ -542,8 +544,6 @@ function ariaAttributeReferences() {
placeholder?.innerText ===
"Use as a global deprecated in ARIA 1.2"
) {
- // update roles list (sort, remove roletype)
- item.roles.sort().splice(item.roles.indexOf("roletype"), 1);
placeholder.innerHTML = `\n${item.roles
.map((role) => `- ${role}
\n`)
.join("")}
\n`;
@@ -577,8 +577,6 @@ function ariaAttributeReferences() {
"All elements of the base markup except for some roles or elements that prohibit its use"
) {
// for prohibited roles the roles list just includes those roles which are prohibited... weird I know but it is what it is
- // exclude roletype from the sorted list
- item.roles.sort().splice(item.roles.indexOf("roletype"), 1);
placeholder.innerHTML = `All elements of the base markup except for the following roles: ${item.roles
.map((role) => `${role}`)
From 06530f4687aa07990fb89023eed8b265a9a0658c Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 12:28:03 +0100
Subject: [PATCH 66/93] refactor(aria.js): improve propList loop
Extract placeholder text and remove unnecessary optional chaining.
test.sh run is clean.
---
script/aria.js | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 2eda00f..3754926 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -505,12 +505,13 @@ function ariaAttributeReferences() {
let placeholder = section.querySelector(
".state-applicability, .property-applicability"
);
+ const placeholderText = placeholder.innerText;
// update roles list: sort, maybe remove roletype
item.roles.sort();
- if (placeholder.innerText !== "Placeholder")
+ if (placeholderText !== "Placeholder")
item.roles.splice(item.roles.indexOf("roletype"), 1);
// TODO: all three cases are near-identical. Can we do more?
- if (placeholder?.innerText === "Placeholder") {
+ if (placeholderText === "Placeholder") {
placeholder.innerHTML = `\n${item.roles
.map((role) => `- ${role}
\n`)
.join("")}
\n`;
@@ -541,8 +542,7 @@ function ariaAttributeReferences() {
.map((role) => `- ${role}
\n`)
.join("")}
\n`;
} else if (
- placeholder?.innerText ===
- "Use as a global deprecated in ARIA 1.2"
+ placeholderText === "Use as a global deprecated in ARIA 1.2"
) {
placeholder.innerHTML = `\n${item.roles
.map((role) => `- ${role}
\n`)
@@ -573,7 +573,7 @@ function ariaAttributeReferences() {
.map((role) => `- ${role}
\n`)
.join("")}
\n`;
} else if (
- placeholder?.innerText ===
+ placeholderText ===
"All elements of the base markup except for some roles or elements that prohibit its use"
) {
// for prohibited roles the roles list just includes those roles which are prohibited... weird I know but it is what it is
From 4aaa99f7f7724a4f54e90034d5f8b0b6e479e00f Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 12:47:10 +0100
Subject: [PATCH 67/93] refactor(aria.js): improve propList loop
Re-arrange to unify two cases.
* document possible placeholder values
* return early on generic case
* move case "partially prohibited" to top (and return early)
* de-duplicate the other two cases
test.sh run is clean.
---
script/aria.js | 107 ++++++++++++++++++++-----------------------------
1 file changed, 44 insertions(+), 63 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 3754926..f87f41c 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -506,73 +506,23 @@ function ariaAttributeReferences() {
".state-applicability, .property-applicability"
);
const placeholderText = placeholder.innerText;
- // update roles list: sort, maybe remove roletype
+ // Current values for placeholderText:
+ // * "All elements of the base markup"
+ // * "Placeholder"
+ // * "Use as a global deprecated in ARIA 1.2"
+ // * "All elements of the base markup except for some roles or elements that prohibit its use"
+ // TODO: Maybe use a data attribute instead?
+
+ // Case: nothing to od
+ if (placeholderText === "All elements of the base markup") return;
+
+ // update roles list: sort & maybe remove roletype
item.roles.sort();
if (placeholderText !== "Placeholder")
item.roles.splice(item.roles.indexOf("roletype"), 1);
- // TODO: all three cases are near-identical. Can we do more?
- if (placeholderText === "Placeholder") {
- placeholder.innerHTML = `\n${item.roles
- .map((role) => `- ${role}
\n`)
- .join("")}
\n`;
-
- // also update any inherited roles
- const placeholderInheritedRoles = section.querySelector(
- ".state-descendants, .property-descendants"
- );
- let myList = [];
- item.roles.forEach(function (role) {
- // TODO: can we simplify this?
- let children = getAllSubRoles(role);
- // Some subroles have required properties which are also required by the superclass.
- // Example: The checked state of radio, which is also required by superclass checkbox.
- // We only want to include these one time, so filter out the subroles.
- children = children.filter(function (subrole) {
- return (
- subrole.indexOf(propList[item.name].roles) === -1
- );
- });
- myList = myList.concat(children);
- });
- placeholderInheritedRoles.innerHTML = `\n${[
- ...new Set(myList),
- ]
- .sort()
- .map((role) => `- ${role}
\n`)
- .join("")}
\n`;
- } else if (
- placeholderText === "Use as a global deprecated in ARIA 1.2"
- ) {
- placeholder.innerHTML = `\n${item.roles
- .map((role) => `- ${role}
\n`)
- .join("")}
\n`;
-
- // also update any inherited roles
- const placeholderInheritedRoles = section.querySelector(
- ".state-descendants, .property-descendants"
- );
- let myList = [];
- item.roles.forEach(function (role) {
- // TODO: can we simplify this?
- let children = getAllSubRoles(role);
- // Some subroles have required properties which are also required by the superclass.
- // Example: The checked state of radio, which is also required by superclass checkbox.
- // We only want to include these one time, so filter out the subroles.
- children = children.filter(function (subrole) {
- return (
- subrole.indexOf(propList[item.name].roles) === -1
- );
- });
- myList = myList.concat(children);
- });
- placeholderInheritedRoles.innerHTML = `\n${[
- ...new Set(myList),
- ]
- .sort()
- .map((role) => `- ${role}
\n`)
- .join("")}
\n`;
- } else if (
+ // Case: partially prohibited
+ if (
placeholderText ===
"All elements of the base markup except for some roles or elements that prohibit its use"
) {
@@ -581,7 +531,38 @@ function ariaAttributeReferences() {
placeholder.innerHTML = `All elements of the base markup except for the following roles: ${item.roles
.map((role) => `${role}`)
.join(", ")}`;
+ return;
}
+
+ // Otherwise, i.e.,
+ // Cases: placeholderText "Placeholder" or "Use as a global deprecated in ARIA 1.2"
+
+ // populate placeholder
+ placeholder.innerHTML = `\n${item.roles
+ .map((role) => `- ${role}
\n`)
+ .join("")}
\n`;
+
+ // also update any inherited roles
+ const placeholderInheritedRoles = section.querySelector(
+ ".state-descendants, .property-descendants"
+ );
+ let myList = [];
+ item.roles.forEach(function (role) {
+ // TODO: can we simplify this?
+ let children = getAllSubRoles(role);
+ // Some subroles have required properties which are also required by the superclass.
+ // Example: The checked state of radio, which is also required by superclass checkbox.
+ // We only want to include these one time, so filter out the subroles.
+ children = children.filter(function (subrole) {
+ return subrole.indexOf(propList[item.name].roles) === -1;
+ });
+ myList = myList.concat(children);
+ });
+
+ placeholderInheritedRoles.innerHTML = `\n${[...new Set(myList)]
+ .sort()
+ .map((role) => `- ${role}
\n`)
+ .join("")}
\n`;
});
// spit out the index
From 2f97b038546901146a7238ffa5516679e788a608 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 13:05:43 +0100
Subject: [PATCH 68/93] refactor(aria.js): indices creation
Switches to template strings and outerHTML.
Adds TODO for name-from-heading
test.sh run is clean.
---
script/aria.js | 66 ++++++++++++++------------------------------------
1 file changed, 18 insertions(+), 48 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index f87f41c..50fb59a 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -565,55 +565,25 @@ function ariaAttributeReferences() {
.join("")}\n`;
});
- // spit out the index
- let node = document.getElementById("index_role");
- let parentNode = node.parentNode;
- let list = document.createElement("dl");
- list.id = "index_role";
- list.className = "compact";
- list.innerHTML = roleIndex;
- parentNode.replaceChild(list, node);
-
- // and the namefrom lists
- node = document.getElementById("index_fromauthor");
- if (node) {
- parentNode = node.parentNode;
- list = document.createElement("ul");
- list.id = "index_fromauthor";
- list.className = "compact";
- list.innerHTML = fromAuthor;
- parentNode.replaceChild(list, node);
- }
-
- node = document.getElementById("index_fromheading");
- if (node) {
- parentNode = node.parentNode;
- list = document.createElement("ul");
- list.id = "index_fromheading";
- list.className = "compact";
- list.innerHTML = fromHeading;
- parentNode.replaceChild(list, node);
- }
+ // spit out the indices
+ document.getElementById(
+ "index_role"
+ ).outerHTML = `${roleIndex}
`;
+ document.getElementById(
+ "index_fromauthor"
+ ).outerHTML = ``;
+ document.getElementById(
+ "index_fromcontent"
+ ).outerHTML = ``;
+ document.getElementById(
+ "index_fromprohibited"
+ ).outerHTML = ``;
+ // TODO: remove if-check after w3c/aria#1860
+ if (document.getElementById("index_fromheading"))
+ document.getElementById(
+ "index_fromheading"
+ ).outerHTML = ``;
- node = document.getElementById("index_fromcontent");
- if (node) {
- parentNode = node.parentNode;
- list = document.createElement("ul");
- list.id = "index_fromcontent";
- list.className = "compact";
- list.innerHTML = fromContent;
- parentNode.replaceChild(list, node);
- }
-
- node = document.getElementById("index_fromprohibited");
- if (node) {
- parentNode = node.parentNode;
- list = document.createElement("ul");
- list.id = "index_fromprohibited";
- list.className = "compact";
- list.innerHTML = fromProhibited;
- parentNode.replaceChild(list, node);
- }
// assuming we found some parent roles, update those parents with their children
for (let i = 0; i < subRoles.length; i++) {
const item = subRoles[subRoles[i]];
From e8f147242b05ab87c7194d63e7eddecb2434156b Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 13:08:55 +0100
Subject: [PATCH 69/93] refactor(aria.js): child roles generation
Begin refactor by dropping unnecessary filter function.
test.sh run is clean.
---
script/aria.js | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 50fb59a..84d2390 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -587,9 +587,7 @@ function ariaAttributeReferences() {
// assuming we found some parent roles, update those parents with their children
for (let i = 0; i < subRoles.length; i++) {
const item = subRoles[subRoles[i]];
- const sortedList = item.sort(function (a, b) {
- return a < b ? -1 : a > b ? 1 : 0;
- });
+ const sortedList = item.sort();
let output = "\n";
for (let j = 0; j < sortedList.length; j++) {
output += "- " + sortedList[j] + "
\n";
From 4d5b37bb8324bca2f979ee4ee8adbee6215c7f3b Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 13:10:08 +0100
Subject: [PATCH 70/93] refactor(aria.js): child roles generation
Drop even more unnecessary filtering.
test.sh run is clean.
---
script/aria.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/script/aria.js b/script/aria.js
index 84d2390..8166800 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -587,7 +587,7 @@ function ariaAttributeReferences() {
// assuming we found some parent roles, update those parents with their children
for (let i = 0; i < subRoles.length; i++) {
const item = subRoles[subRoles[i]];
- const sortedList = item.sort();
+ const sortedList = item;
let output = "\n";
for (let j = 0; j < sortedList.length; j++) {
output += "- " + sortedList[j] + "
\n";
From 22aac2ae8c8a52e8614bd4dcc394b9a0675e157e Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 13:31:52 +0100
Subject: [PATCH 71/93] refactor(aria.js): child roles generation
Refactor into forEach + map + template strings.
test.sh run is clean.
---
script/aria.js | 26 ++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 8166800..2b03021 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -585,24 +585,14 @@ function ariaAttributeReferences() {
).outerHTML = ``;
// assuming we found some parent roles, update those parents with their children
- for (let i = 0; i < subRoles.length; i++) {
- const item = subRoles[subRoles[i]];
- const sortedList = item;
- let output = "\n";
- for (let j = 0; j < sortedList.length; j++) {
- output += "- " + sortedList[j] + "
\n";
- }
- output += "
\n";
- // put it somewhere
- const subRolesContainer = document.querySelector("#" + subRoles[i]);
- if (subRolesContainer) {
- const subRolesListContainer =
- subRolesContainer.querySelector(".role-children");
- if (subRolesListContainer) {
- subRolesListContainer.innerHTML = output;
- }
- }
- }
+ subRoles.forEach((role) => {
+ const item = subRoles[role]; //TODO: cf. populateSubRoles overloading
+ document.querySelector(
+ `#${role} .role-children`
+ ).innerHTML = `\n${item
+ .map((subrole) => `- ${subrole}
\n`)
+ .join("")}
\n`;
+ });
}
// prune out unused rows throughout the document
From 72781f9fcc07cfba70a22dc629da490a6402d7ae Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 16:08:31 +0100
Subject: [PATCH 72/93] refactor(aria.js): move cleanup into main scope
Note: removes skipindex check during cleanup.
test.sh run is clean.
---
script/aria.js | 48 +++++++++++++++++++++++++++---------------------
1 file changed, 27 insertions(+), 21 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 2b03021..88a4279 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -411,6 +411,32 @@ const buildInheritedStatesProperties = function (item) {
}
};
+/**
+ * prune out unused rows throughout the document
+ *
+ */
+const pruneUnusedRows = () => {
+ document
+ .querySelectorAll(
+ ".role-abstract, .role-parent, .role-base, .role-related, .role-scope, .role-mustcontain, .role-required-properties, .role-properties, .role-namefrom, .role-namerequired, .role-namerequired-inherited, .role-childpresentational, .role-presentational-inherited, .state-related, .property-related,.role-inherited, .role-children, .property-descendants, .state-descendants, .implicit-values"
+ )
+ .forEach(function (item) {
+ var content = item.innerText;
+ if (content.length === 1 || content.length === 0) {
+ // there is no item - remove the row
+ item.parentNode.parentNode.removeChild(item.parentNode);
+ } else if (
+ content === "Placeholder" &&
+ (item.className === "role-inherited" ||
+ item.className === "role-children" ||
+ item.className === "property-descendants" ||
+ item.className === "state-descendants")
+ ) {
+ item.parentNode.remove();
+ }
+ });
+};
+
function ariaAttributeReferences() {
const propList = {};
const globalSP = [];
@@ -595,27 +621,7 @@ function ariaAttributeReferences() {
});
}
- // prune out unused rows throughout the document
- document
- .querySelectorAll(
- ".role-abstract, .role-parent, .role-base, .role-related, .role-scope, .role-mustcontain, .role-required-properties, .role-properties, .role-namefrom, .role-namerequired, .role-namerequired-inherited, .role-childpresentational, .role-presentational-inherited, .state-related, .property-related,.role-inherited, .role-children, .property-descendants, .state-descendants, .implicit-values"
- )
- .forEach(function (item) {
- var content = item.innerText;
- if (content.length === 1 || content.length === 0) {
- // there is no item - remove the row
- item.parentNode.parentNode.removeChild(item.parentNode);
- } else if (
- content === "Placeholder" &&
- !skipIndex &&
- (item.className === "role-inherited" ||
- item.className === "role-children" ||
- item.className === "property-descendants" ||
- item.className === "state-descendants")
- ) {
- item.parentNode.remove();
- }
- });
+ pruneUnusedRows();
updateReferences(document);
}
From e5e7c88e73bd97b59c57aab3c6f877a5ef890857 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 16:13:05 +0100
Subject: [PATCH 73/93] refactor(aria.js): re-arrange indices handling
Prepares for more.
test.sh run is clean.
---
script/aria.js | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 88a4279..fa90970 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -497,6 +497,25 @@ function ariaAttributeReferences() {
.join("");
const roleIndex = [...rdefs].map(generateHTMLRoleIndexEntry).join("");
+
+ // spit out the indices
+ document.getElementById(
+ "index_role"
+ ).outerHTML = `${roleIndex}
`;
+ document.getElementById(
+ "index_fromauthor"
+ ).outerHTML = ``;
+ document.getElementById(
+ "index_fromcontent"
+ ).outerHTML = ``;
+ document.getElementById(
+ "index_fromprohibited"
+ ).outerHTML = ``;
+ // TODO: remove if-check after w3c/aria#1860
+ if (document.getElementById("index_fromheading"))
+ document.getElementById(
+ "index_fromheading"
+ ).outerHTML = ``;
rdefs.forEach(populateRoleInfoPropList.bind(null, roleInfo, propList));
rdefs.forEach(rewriteRdef);
@@ -591,25 +610,6 @@ function ariaAttributeReferences() {
.join("")}
\n`;
});
- // spit out the indices
- document.getElementById(
- "index_role"
- ).outerHTML = `${roleIndex}
`;
- document.getElementById(
- "index_fromauthor"
- ).outerHTML = ``;
- document.getElementById(
- "index_fromcontent"
- ).outerHTML = ``;
- document.getElementById(
- "index_fromprohibited"
- ).outerHTML = ``;
- // TODO: remove if-check after w3c/aria#1860
- if (document.getElementById("index_fromheading"))
- document.getElementById(
- "index_fromheading"
- ).outerHTML = ``;
-
// assuming we found some parent roles, update those parents with their children
subRoles.forEach((role) => {
const item = subRoles[role]; //TODO: cf. populateSubRoles overloading
From 485bdb595c3d5548808fb13cf2d114d6d672ab5c Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 16:18:58 +0100
Subject: [PATCH 74/93] refactor(aria.js): extract HTML creation for indices
Moves everything related to HTML for indices into function in global scope.
test.sh run is clean.
---
script/aria.js | 73 ++++++++++++++++++++++++++++----------------------
1 file changed, 41 insertions(+), 32 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index fa90970..fc14995 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -437,6 +437,46 @@ const pruneUnusedRows = () => {
});
};
+/**
+ * Generates the HTML for various indices in the spec
+ * @param {NodeList} rdefs - all the rdefs
+ */
+const generateHTMLIndices = (rdefs) => {
+ let fromAuthor = [...rdefs]
+ .map(generateHTMLNameFromIndices.bind(null, "author"))
+ .join("");
+ let fromHeading = [...rdefs]
+ .map(generateHTMLNameFromIndices.bind(null, "heading"))
+ .join("");
+ let fromContent = [...rdefs]
+ .map(generateHTMLNameFromIndices.bind(null, "content"))
+ .join("");
+ let fromProhibited = [...rdefs]
+ .map(generateHTMLNameFromIndices.bind(null, "prohibited"))
+ .join("");
+
+ const roleIndex = [...rdefs].map(generateHTMLRoleIndexEntry).join("");
+
+ // spit out the indices
+ document.getElementById(
+ "index_role"
+ ).outerHTML = `${roleIndex}
`;
+ document.getElementById(
+ "index_fromauthor"
+ ).outerHTML = ``;
+ document.getElementById(
+ "index_fromcontent"
+ ).outerHTML = ``;
+ document.getElementById(
+ "index_fromprohibited"
+ ).outerHTML = ``;
+ // TODO: remove if-check after w3c/aria#1860
+ if (document.getElementById("index_fromheading"))
+ document.getElementById(
+ "index_fromheading"
+ ).outerHTML = ``;
+};
+
function ariaAttributeReferences() {
const propList = {};
const globalSP = [];
@@ -483,39 +523,8 @@ function ariaAttributeReferences() {
rdefs.forEach(populateSubRoles.bind(null, subRoles));
- let fromAuthor = [...rdefs]
- .map(generateHTMLNameFromIndices.bind(null, "author"))
- .join("");
- let fromHeading = [...rdefs]
- .map(generateHTMLNameFromIndices.bind(null, "heading"))
- .join("");
- let fromContent = [...rdefs]
- .map(generateHTMLNameFromIndices.bind(null, "content"))
- .join("");
- let fromProhibited = [...rdefs]
- .map(generateHTMLNameFromIndices.bind(null, "prohibited"))
- .join("");
-
- const roleIndex = [...rdefs].map(generateHTMLRoleIndexEntry).join("");
+ generateHTMLIndices(rdefs);
- // spit out the indices
- document.getElementById(
- "index_role"
- ).outerHTML = `${roleIndex}
`;
- document.getElementById(
- "index_fromauthor"
- ).outerHTML = ``;
- document.getElementById(
- "index_fromcontent"
- ).outerHTML = ``;
- document.getElementById(
- "index_fromprohibited"
- ).outerHTML = ``;
- // TODO: remove if-check after w3c/aria#1860
- if (document.getElementById("index_fromheading"))
- document.getElementById(
- "index_fromheading"
- ).outerHTML = ``;
rdefs.forEach(populateRoleInfoPropList.bind(null, roleInfo, propList));
rdefs.forEach(rewriteRdef);
From 44b01348d3799909f702216cb463c41d9622ef61 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 16:26:40 +0100
Subject: [PATCH 75/93] refactor(aria.js): use outerHTML more often
Crude but direct.
test.sh run is clean.
---
script/aria.js | 30 +++++-------------------------
1 file changed, 5 insertions(+), 25 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index fc14995..c1674ee 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -111,11 +111,7 @@ const rewriteRdef = function (item) {
const dRef = item.nextElementSibling;
dRef.id = "desc-" + title;
dRef.setAttribute("role", "definition");
- item.insertAdjacentHTML(
- "afterend",
- `${content}
${type}`
- );
- item.remove();
+ item.outerHTML = `${content}
${type}`;
};
/**
@@ -130,11 +126,7 @@ const generateHTMLStatesAndProperties = function (propList, item) {
dRef.id = "desc-" + title; // TODO: too much of a side-effect?
dRef.setAttribute("role", "definition"); // TODO: ditto?
// Replace pdef/sdef with HTML
- item.insertAdjacentHTML(
- "afterend",
- `${itemEntry.name}
${itemEntry.is}
`
- );
- item.remove();
+ item.outerHTML = `${itemEntry.name}
${itemEntry.is}
`;
};
/**
@@ -150,11 +142,7 @@ const generateIndexStatesAndProperties = (propList) => {
`- ${item.name}
\n- ${item.desc}
\n`
)
.join("");
- indexStatePropPlaceholder.insertAdjacentHTML(
- "afterend",
- `${indexStatePropContent}
`
- );
- indexStatePropPlaceholder.remove();
+ indexStatePropPlaceholder.outerHTML = `${indexStatePropContent}
`;
};
/**
@@ -183,21 +171,13 @@ const generateIndexGlobalStatesAndProperties = (globalSP) => {
const globalStatesPropertiesPlaceholder = document.querySelector(
"#global_states .placeholder"
);
- globalStatesPropertiesPlaceholder.insertAdjacentHTML(
- "afterend",
- `${globalStatesPropertiesContent}
`
- );
- globalStatesPropertiesPlaceholder.remove();
+ globalStatesPropertiesPlaceholder.outerHTML = `${globalStatesPropertiesContent}
`;
// Populate role=roletype properties with global properties
const roletypePropsPlaceholder = document.querySelector(
"#roletype td.role-properties span.placeholder"
);
- roletypePropsPlaceholder.insertAdjacentHTML(
- "afterend",
- `${globalStatesPropertiesContent}
`
- );
- roletypePropsPlaceholder.remove();
+ roletypePropsPlaceholder.outerHTML = `${globalStatesPropertiesContent}
`;
};
/**
From 7e444ad41f570ea84fbc5c4dd002880046764944 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 16:38:07 +0100
Subject: [PATCH 76/93] fix(aria.js): regressions in roleInfo output
Ensures some values are Boolean.
test.sh run is clean.
---
script/aria.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index c1674ee..fcd4414 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -231,8 +231,8 @@ const populateSubRoles = (subRoles, rdef) => {
const extractStatesProperties = function (item) {
const name = item.getAttribute("title") || item.innerText; // TODO: tests indicate both are needed but why?
const type = item.localName === "pref" ? "property" : "state";
- const req = item.closest(".role-required-properties");
- const dis = item.closest(".role-disallowed");
+ const req = new Boolean(item.closest(".role-required-properties"));
+ const dis = new Boolean(item.closest(".role-disallowed"));
const dep = item.hasAttribute("data-deprecated");
return {
is: type,
From c619ee2d9c359ab02c30961283e66a107512f391 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 18:08:43 +0100
Subject: [PATCH 77/93] fix(aria.js): regression from fixing roleInfo
Fixes the HTML output.
test.sh run is clean.
---
script/aria.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index fcd4414..933b84f 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -231,8 +231,8 @@ const populateSubRoles = (subRoles, rdef) => {
const extractStatesProperties = function (item) {
const name = item.getAttribute("title") || item.innerText; // TODO: tests indicate both are needed but why?
const type = item.localName === "pref" ? "property" : "state";
- const req = new Boolean(item.closest(".role-required-properties"));
- const dis = new Boolean(item.closest(".role-disallowed"));
+ const req = !!item.closest(".role-required-properties");
+ const dis = !!item.closest(".role-disallowed");
const dep = item.hasAttribute("data-deprecated");
return {
is: type,
From 2455b8893d12eb6fbd54a8a177fb91b10648da4a Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 18:18:41 +0100
Subject: [PATCH 78/93] refactor(aria.js): add createDescendantRoles
Adds createDescendantRoles() which encapsulates the getAllSubRoles() to allow for extraction of propList loop.
test.sh run is clean.
---
script/aria.js | 44 ++++++++++++++++++++++++++------------------
1 file changed, 26 insertions(+), 18 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 933b84f..545d5f9 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -515,24 +515,32 @@ function ariaAttributeReferences() {
if (!skipIndex) {
Object.values(roleInfo).forEach(buildInheritedStatesProperties);
- // Update state and property role references
- const getAllSubRoles = function (role) {
- const ref = subRoles[role];
- if (ref && ref.length) {
- let myList = [];
- ref.forEach(function (item) {
- if (!myList.item) {
- myList[item] = 1;
- myList.push(item);
- const childList = getAllSubRoles(item);
- myList = myList.concat(childList);
- }
- });
- return myList;
- } else {
- return [];
- }
+ const createDescendantRoles = (subRoles) => {
+ const descendantRoles = {};
+ // Update state and property role references
+ const getAllSubRoles = function (role) {
+ const ref = subRoles[role];
+ if (ref && ref.length) {
+ let myList = [];
+ ref.forEach(function (item) {
+ if (!myList.item) {
+ myList[item] = 1;
+ myList.push(item);
+ const childList = getAllSubRoles(item);
+ myList = myList.concat(childList);
+ }
+ });
+ return myList;
+ } else {
+ return [];
+ }
+ };
+ subRoles.forEach(
+ (item) => (descendantRoles[item] = getAllSubRoles(item))
+ );
+ return descendantRoles;
};
+ const descendantRoles = createDescendantRoles(subRoles);
Object.values(propList).forEach(function (item) {
const section = document.querySelector("#" + item.name);
@@ -583,7 +591,7 @@ function ariaAttributeReferences() {
let myList = [];
item.roles.forEach(function (role) {
// TODO: can we simplify this?
- let children = getAllSubRoles(role);
+ let children = descendantRoles[role] || [];
// Some subroles have required properties which are also required by the superclass.
// Example: The checked state of radio, which is also required by superclass checkbox.
// We only want to include these one time, so filter out the subroles.
From 46b23321f45e417940c369e04645dd346b6a4918 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 18:28:40 +0100
Subject: [PATCH 79/93] refactor(aria.js): extract propList loop
Extracts the loop into a function in the global scope;
not pretty but hopefully better than before.
test.sh run is clean.
---
script/aria.js | 139 ++++++++++++++++++++++++++-----------------------
1 file changed, 75 insertions(+), 64 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 545d5f9..a1aec6e 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -457,6 +457,78 @@ const generateHTMLIndices = (rdefs) => {
).outerHTML = ``;
};
+/**
+ * The propList loop.
+ * @param {Object} propList - the propList
+ * @param {Object} descendantRoles - the list of "descendant" roles
+ * @param {Object} item - value from object.values(propList)
+ * @returns
+ */
+const propListLoop = function (propList, descendantRoles, item) {
+ const section = document.querySelector("#" + item.name);
+ let placeholder = section.querySelector(
+ ".state-applicability, .property-applicability"
+ );
+ const placeholderText = placeholder.innerText;
+ // Current values for placeholderText:
+ // * "All elements of the base markup"
+ // * "Placeholder"
+ // * "Use as a global deprecated in ARIA 1.2"
+ // * "All elements of the base markup except for some roles or elements that prohibit its use"
+ // TODO: Maybe use a data attribute instead?
+
+ // Case: nothing to od
+ if (placeholderText === "All elements of the base markup") return;
+
+ // update roles list: sort & maybe remove roletype
+ item.roles.sort();
+ if (placeholderText !== "Placeholder")
+ item.roles.splice(item.roles.indexOf("roletype"), 1);
+
+ // Case: partially prohibited
+ if (
+ placeholderText ===
+ "All elements of the base markup except for some roles or elements that prohibit its use"
+ ) {
+ // for prohibited roles the roles list just includes those roles which are prohibited... weird I know but it is what it is
+
+ placeholder.innerHTML = `All elements of the base markup except for the following roles: ${item.roles
+ .map((role) => `${role}`)
+ .join(", ")}`;
+ return;
+ }
+
+ // Otherwise, i.e.,
+ // Cases: placeholderText "Placeholder" or "Use as a global deprecated in ARIA 1.2"
+
+ // populate placeholder
+ placeholder.innerHTML = `\n${item.roles
+ .map((role) => `- ${role}
\n`)
+ .join("")}
\n`;
+
+ // also update any inherited roles
+ const placeholderInheritedRoles = section.querySelector(
+ ".state-descendants, .property-descendants"
+ );
+ let myList = [];
+ item.roles.forEach(function (role) {
+ // TODO: can we simplify this?
+ let children = descendantRoles[role] || [];
+ // Some subroles have required properties which are also required by the superclass.
+ // Example: The checked state of radio, which is also required by superclass checkbox.
+ // We only want to include these one time, so filter out the subroles.
+ children = children.filter(function (subrole) {
+ return subrole.indexOf(propList[item.name].roles) === -1;
+ });
+ myList = myList.concat(children);
+ });
+
+ placeholderInheritedRoles.innerHTML = `\n${[...new Set(myList)]
+ .sort()
+ .map((role) => `- ${role}
\n`)
+ .join("")}
\n`;
+};
+
function ariaAttributeReferences() {
const propList = {};
const globalSP = [];
@@ -542,70 +614,9 @@ function ariaAttributeReferences() {
};
const descendantRoles = createDescendantRoles(subRoles);
- Object.values(propList).forEach(function (item) {
- const section = document.querySelector("#" + item.name);
- let placeholder = section.querySelector(
- ".state-applicability, .property-applicability"
- );
- const placeholderText = placeholder.innerText;
- // Current values for placeholderText:
- // * "All elements of the base markup"
- // * "Placeholder"
- // * "Use as a global deprecated in ARIA 1.2"
- // * "All elements of the base markup except for some roles or elements that prohibit its use"
- // TODO: Maybe use a data attribute instead?
-
- // Case: nothing to od
- if (placeholderText === "All elements of the base markup") return;
-
- // update roles list: sort & maybe remove roletype
- item.roles.sort();
- if (placeholderText !== "Placeholder")
- item.roles.splice(item.roles.indexOf("roletype"), 1);
-
- // Case: partially prohibited
- if (
- placeholderText ===
- "All elements of the base markup except for some roles or elements that prohibit its use"
- ) {
- // for prohibited roles the roles list just includes those roles which are prohibited... weird I know but it is what it is
-
- placeholder.innerHTML = `All elements of the base markup except for the following roles: ${item.roles
- .map((role) => `${role}`)
- .join(", ")}`;
- return;
- }
-
- // Otherwise, i.e.,
- // Cases: placeholderText "Placeholder" or "Use as a global deprecated in ARIA 1.2"
-
- // populate placeholder
- placeholder.innerHTML = `\n${item.roles
- .map((role) => `- ${role}
\n`)
- .join("")}
\n`;
-
- // also update any inherited roles
- const placeholderInheritedRoles = section.querySelector(
- ".state-descendants, .property-descendants"
- );
- let myList = [];
- item.roles.forEach(function (role) {
- // TODO: can we simplify this?
- let children = descendantRoles[role] || [];
- // Some subroles have required properties which are also required by the superclass.
- // Example: The checked state of radio, which is also required by superclass checkbox.
- // We only want to include these one time, so filter out the subroles.
- children = children.filter(function (subrole) {
- return subrole.indexOf(propList[item.name].roles) === -1;
- });
- myList = myList.concat(children);
- });
-
- placeholderInheritedRoles.innerHTML = `\n${[...new Set(myList)]
- .sort()
- .map((role) => `- ${role}
\n`)
- .join("")}
\n`;
- });
+ Object.values(propList).forEach(
+ propListLoop.bind(null, propList, descendantRoles)
+ );
// assuming we found some parent roles, update those parents with their children
subRoles.forEach((role) => {
From c95148200616f5fff827cb7637f17af879c4eb4f Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 18:30:39 +0100
Subject: [PATCH 80/93] refactor(aria.js): extract createDescendantRoles()
Moves it into the global scope.
test.sh run is clean.
---
script/aria.js | 58 +++++++++++++++++++++++++++-----------------------
1 file changed, 31 insertions(+), 27 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index a1aec6e..b86296e 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -458,11 +458,40 @@ const generateHTMLIndices = (rdefs) => {
};
/**
- * The propList loop.
+ * Creates dictionary of "descendant" roles
+ * @param {Object} subRoles - the subroles collection
+ * @returns
+ */
+const createDescendantRoles = (subRoles) => {
+ const descendantRoles = {};
+ // Update state and property role references
+ const getAllSubRoles = function (role) {
+ const ref = subRoles[role];
+ if (ref && ref.length) {
+ let myList = [];
+ ref.forEach(function (item) {
+ if (!myList.item) {
+ myList[item] = 1;
+ myList.push(item);
+ const childList = getAllSubRoles(item);
+ myList = myList.concat(childList);
+ }
+ });
+ return myList;
+ } else {
+ return [];
+ }
+ };
+ subRoles.forEach((item) => (descendantRoles[item] = getAllSubRoles(item)));
+ return descendantRoles;
+};
+
+/**
+ * The propList loop.
* @param {Object} propList - the propList
* @param {Object} descendantRoles - the list of "descendant" roles
* @param {Object} item - value from object.values(propList)
- * @returns
+ * @returns
*/
const propListLoop = function (propList, descendantRoles, item) {
const section = document.querySelector("#" + item.name);
@@ -587,31 +616,6 @@ function ariaAttributeReferences() {
if (!skipIndex) {
Object.values(roleInfo).forEach(buildInheritedStatesProperties);
- const createDescendantRoles = (subRoles) => {
- const descendantRoles = {};
- // Update state and property role references
- const getAllSubRoles = function (role) {
- const ref = subRoles[role];
- if (ref && ref.length) {
- let myList = [];
- ref.forEach(function (item) {
- if (!myList.item) {
- myList[item] = 1;
- myList.push(item);
- const childList = getAllSubRoles(item);
- myList = myList.concat(childList);
- }
- });
- return myList;
- } else {
- return [];
- }
- };
- subRoles.forEach(
- (item) => (descendantRoles[item] = getAllSubRoles(item))
- );
- return descendantRoles;
- };
const descendantRoles = createDescendantRoles(subRoles);
Object.values(propList).forEach(
From 90d51fd85f1d69c01eaf21f51eb5ff0c98620d2b Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Wed, 13 Dec 2023 18:36:40 +0100
Subject: [PATCH 81/93] refactor(aria.js): extract generateHTMLRoleChildren()
Moves child role HTML generation into
generateHTMLRoleChildren() in global scope.
test.sh run is clean.
---
script/aria.js | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index b86296e..8233ba5 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -558,6 +558,19 @@ const propListLoop = function (propList, descendantRoles, item) {
.join("")}
\n`;
};
+/**
+ * In forEach loop, generates HTML for child role entries
+ * @param {String} role - subRoles array entry
+ * @param {Number} index - subRoles array index
+ * @param {Object} subRoles - overloaded subRoles array
+ */
+const generateHTMLRoleChildren = (role, index, subRoles) => {
+ const item = subRoles[role]; //TODO: cf. populateSubRoles overloading
+ document.querySelector(`#${role} .role-children`).innerHTML = `\n${item
+ .map((subrole) => `- ${subrole}
\n`)
+ .join("")}
\n`;
+};
+
function ariaAttributeReferences() {
const propList = {};
const globalSP = [];
@@ -623,14 +636,7 @@ function ariaAttributeReferences() {
);
// assuming we found some parent roles, update those parents with their children
- subRoles.forEach((role) => {
- const item = subRoles[role]; //TODO: cf. populateSubRoles overloading
- document.querySelector(
- `#${role} .role-children`
- ).innerHTML = `\n${item
- .map((subrole) => `- ${subrole}
\n`)
- .join("")}
\n`;
- });
+ subRoles.forEach(generateHTMLRoleChildren);
}
pruneUnusedRows();
From 52c228443ed18025b02664adabee9c0647f3c0d0 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Fri, 15 Dec 2023 13:33:25 +0100
Subject: [PATCH 82/93] refactor(aria.js): review and improve TODO comments
---
script/aria.js | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 8233ba5..c389dc6 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -161,6 +161,7 @@ const generateIndexGlobalStatesAndProperties = (globalSP) => {
isState ? `title="${item.name}"` : ""
}>${item.name}${isState ? " (state)" : ""}${tagName}>${
// TODO: consider moving "(state)" out of sref/pref tag; then maybe remove title attr for sref (after checking resolveReferences interference)
+ // TODO: cf. extractStatesProperties() and populateRoleInfoPropList() which have extra logic for title set here)
item.prohibited ? " (Except where prohibited)" : ""
}${
@@ -214,7 +215,7 @@ const populateSubRoles = (subRoles, rdef) => {
.querySelectorAll(".role-parent rref")
.forEach(function (roleref) {
const s = roleref.innerText;
- // TODO: this overloading seems weird
+ // SUPERTODO: this overloading seems weird
if (!subRoles[s]) {
subRoles.push(s);
subRoles[s] = []; // TODO: should this be a set?
@@ -229,7 +230,7 @@ const populateSubRoles = (subRoles, rdef) => {
* @returns
*/
const extractStatesProperties = function (item) {
- const name = item.getAttribute("title") || item.innerText; // TODO: tests indicate both are needed but why?
+ const name = item.getAttribute("title") || item.innerText; // TODO: raw HTML doesn't have sref/pref with title attributes but generateIndexGlobalStatesAndProperties() creates them
const type = item.localName === "pref" ? "property" : "state";
const req = !!item.closest(".role-required-properties");
const dis = !!item.closest(".role-disallowed");
@@ -295,7 +296,7 @@ const populateRoleInfoPropList = function (roleInfo, propList, item) {
// remember that the state or property is
// referenced by this role
PSDefs.forEach((node) =>
- propList[node.getAttribute("title") || node.innerText].roles.push(
+ propList[node.getAttribute("title") || node.innerText].roles.push( // TODO: cf. generateIndexGlobalStatesAndProperties() TODO for simplifying title || node.innerText
content
)
);
@@ -341,7 +342,7 @@ const buildInheritedStatesProperties = function (item) {
);
if (!placeholder) return;
- // TODO: simplify (from here until sortedList)
+ // SUPERTODO: simplify (from here until sortedList)
let myList = [];
item.parentRoles.forEach(function (role) {
myList = myList.concat(getStates(role));
@@ -369,7 +370,7 @@ const buildInheritedStatesProperties = function (item) {
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
}, []);
- let prev; //TODO: get rid of "prev"
+ let prev; //SUPERTODO: get rid of "prev"
const output = sortedList
.map((property) => {
if (prev === property.name) return "";
@@ -506,7 +507,7 @@ const propListLoop = function (propList, descendantRoles, item) {
// * "All elements of the base markup except for some roles or elements that prohibit its use"
// TODO: Maybe use a data attribute instead?
- // Case: nothing to od
+ // Case: nothing to do
if (placeholderText === "All elements of the base markup") return;
// update roles list: sort & maybe remove roletype
@@ -541,7 +542,7 @@ const propListLoop = function (propList, descendantRoles, item) {
);
let myList = [];
item.roles.forEach(function (role) {
- // TODO: can we simplify this?
+ // SUPERTODO: can we simplify this?
let children = descendantRoles[role] || [];
// Some subroles have required properties which are also required by the superclass.
// Example: The checked state of radio, which is also required by superclass checkbox.
From 1e29ec2edeb3bb6378bf0c82e50ed467a50f8b47 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Fri, 15 Dec 2023 17:29:12 +0100
Subject: [PATCH 83/93] refactor(aria.js): change subRoles to simple object
Changes subRoles to a simple object of sets (instead of an overloaded array).
* createDescendantRoles(): populate subRoles with sets
* createDescendantRoles(): adjust to new subRoles structure; also adds TODO
* generateHTMLRoleChildren()
* change signature to work in Object.entries loop
* adjust to new subRoles structure
* ariaAttributeReferences()
* change subRoles to object
* adjust loop to iterate over entries.
test.sh run is clean.
---
script/aria.js | 63 +++++++++++++++++++++++---------------------------
1 file changed, 29 insertions(+), 34 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index c389dc6..d297a9c 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -214,13 +214,9 @@ const populateSubRoles = (subRoles, rdef) => {
rdef.parentNode
.querySelectorAll(".role-parent rref")
.forEach(function (roleref) {
- const s = roleref.innerText;
- // SUPERTODO: this overloading seems weird
- if (!subRoles[s]) {
- subRoles.push(s);
- subRoles[s] = []; // TODO: should this be a set?
- }
- subRoles[s].push(title); // TODO: should this be a set?
+ const parentRole = roleref.innerText;
+ const parentChildrenRoles = (subRoles[parentRole] ??= new Set());
+ parentChildrenRoles.add(title);
});
};
@@ -296,7 +292,8 @@ const populateRoleInfoPropList = function (roleInfo, propList, item) {
// remember that the state or property is
// referenced by this role
PSDefs.forEach((node) =>
- propList[node.getAttribute("title") || node.innerText].roles.push( // TODO: cf. generateIndexGlobalStatesAndProperties() TODO for simplifying title || node.innerText
+ propList[node.getAttribute("title") || node.innerText].roles.push(
+ // TODO: cf. generateIndexGlobalStatesAndProperties() TODO for simplifying title || node.innerText
content
)
);
@@ -465,25 +462,24 @@ const generateHTMLIndices = (rdefs) => {
*/
const createDescendantRoles = (subRoles) => {
const descendantRoles = {};
- // Update state and property role references
- const getAllSubRoles = function (role) {
- const ref = subRoles[role];
- if (ref && ref.length) {
- let myList = [];
- ref.forEach(function (item) {
- if (!myList.item) {
- myList[item] = 1;
- myList.push(item);
- const childList = getAllSubRoles(item);
- myList = myList.concat(childList);
- }
- });
- return myList;
- } else {
- return [];
- }
+ const getAllSubRoles = function (key) {
+ if (!subRoles[key]) return []; // NOTE: recursion end
+ const ref = [...subRoles[key]];
+ // SUPERTODO: refactor the rest here:
+ let myList = [];
+ ref.forEach(function (item) {
+ if (!myList.item) {
+ myList[item] = 1;
+ myList.push(item);
+ const childList = getAllSubRoles(item);
+ myList = myList.concat(childList);
+ }
+ });
+ return myList;
};
- subRoles.forEach((item) => (descendantRoles[item] = getAllSubRoles(item)));
+ Object.keys(subRoles).forEach(
+ (item) => (descendantRoles[item] = getAllSubRoles(item))
+ );
return descendantRoles;
};
@@ -560,13 +556,12 @@ const propListLoop = function (propList, descendantRoles, item) {
};
/**
- * In forEach loop, generates HTML for child role entries
- * @param {String} role - subRoles array entry
- * @param {Number} index - subRoles array index
- * @param {Object} subRoles - overloaded subRoles array
+ * In Object.entries loop, generates HTML for child role entries
+ * @param {String} role - subRoles key
+ * @param {Object} subRolesSet - subRoles value
*/
-const generateHTMLRoleChildren = (role, index, subRoles) => {
- const item = subRoles[role]; //TODO: cf. populateSubRoles overloading
+const generateHTMLRoleChildren = ([role, subroleSet]) => {
+ const item = [...subroleSet];
document.querySelector(`#${role} .role-children`).innerHTML = `\n${item
.map((subrole) => `- ${subrole}
\n`)
.join("")}
\n`;
@@ -611,7 +606,7 @@ function ariaAttributeReferences() {
// 4. grab any local states and properties so we can hand those down to the children
//
- const subRoles = [];
+ const subRoles = {};
const rdefs = document.querySelectorAll("rdef");
const rdefsContainer = [...rdefs].map((node) => node.parentNode);
@@ -637,7 +632,7 @@ function ariaAttributeReferences() {
);
// assuming we found some parent roles, update those parents with their children
- subRoles.forEach(generateHTMLRoleChildren);
+ Object.entries(subRoles).forEach(generateHTMLRoleChildren);
}
pruneUnusedRows();
From 460c92d3688057b345ae098e12bc9c54c719d37a Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Fri, 15 Dec 2023 17:36:36 +0100
Subject: [PATCH 84/93] refactor(aria.js): replace populateSubRoles() with
generateSubRoles()
Instead of declaring subRoles and populating it, generateSubRoles takes rdefs and returns subRoles.
* generateSubRoles(): creates subRoles object and loops over given rdefs to populate it
* ariaAttributeReferences(): replace populateSubRoles() with generateSubRoles()
test.sh run is clean.
---
script/aria.js | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index d297a9c..867da5c 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -206,18 +206,22 @@ const generateHTMLRoleIndexEntry = function (item) {
/**
* Generates subrole information
- * @param {Object} subRoles - the subRoles "array" (overloaded)
- * @param {HTMLement} rdef - rdef element node
+ * @param {NodeList} rdefs - rdefs
*/
-const populateSubRoles = (subRoles, rdef) => {
- const title = rdef.innerHTML;
- rdef.parentNode
- .querySelectorAll(".role-parent rref")
- .forEach(function (roleref) {
- const parentRole = roleref.innerText;
- const parentChildrenRoles = (subRoles[parentRole] ??= new Set());
- parentChildrenRoles.add(title);
- });
+const generateSubRoles = (rdefs) => {
+ const subRoles = {};
+ rdefs.forEach((rdef) => {
+ const title = rdef.innerHTML;
+ rdef.parentNode
+ .querySelectorAll(".role-parent rref")
+ .forEach(function (roleref) {
+ const parentRole = roleref.innerText;
+ const parentChildrenRoles = (subRoles[parentRole] ??=
+ new Set());
+ parentChildrenRoles.add(title);
+ });
+ });
+ return subRoles;
};
/**
@@ -606,12 +610,10 @@ function ariaAttributeReferences() {
// 4. grab any local states and properties so we can hand those down to the children
//
- const subRoles = {};
-
const rdefs = document.querySelectorAll("rdef");
const rdefsContainer = [...rdefs].map((node) => node.parentNode);
- rdefs.forEach(populateSubRoles.bind(null, subRoles));
+ const subRoles = generateSubRoles(rdefs);
generateHTMLIndices(rdefs);
From f50851ba4fa2f50ec483f6c7ba774e4a811912e3 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Fri, 15 Dec 2023 18:12:39 +0100
Subject: [PATCH 85/93] refactor(aria.js): rewrite getAllSubRoles() //
descendantRoles to use sets
* createDescendantRoles(): rewrite getAllSubRoles() to produce sets as values in descendantRoles
* propListLoop(): adjust to new descendantRoles structure
test.sh run is clean.
---
script/aria.js | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 867da5c..1698f18 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -467,19 +467,15 @@ const generateHTMLIndices = (rdefs) => {
const createDescendantRoles = (subRoles) => {
const descendantRoles = {};
const getAllSubRoles = function (key) {
- if (!subRoles[key]) return []; // NOTE: recursion end
- const ref = [...subRoles[key]];
- // SUPERTODO: refactor the rest here:
- let myList = [];
- ref.forEach(function (item) {
- if (!myList.item) {
- myList[item] = 1;
- myList.push(item);
- const childList = getAllSubRoles(item);
- myList = myList.concat(childList);
- }
+ const subroleSet = new Set();
+ if (!subRoles[key]) return subroleSet; // NOTE: recursion end
+ const childRoles = [...subRoles[key]];
+ childRoles.forEach(function (childRole) {
+ subroleSet.add(childRole);
+ const descendantRolesSet = getAllSubRoles(childRole);
+ [...descendantRolesSet].forEach((role) => subroleSet.add(role));
});
- return myList;
+ return subroleSet;
};
Object.keys(subRoles).forEach(
(item) => (descendantRoles[item] = getAllSubRoles(item))
@@ -543,11 +539,12 @@ const propListLoop = function (propList, descendantRoles, item) {
let myList = [];
item.roles.forEach(function (role) {
// SUPERTODO: can we simplify this?
- let children = descendantRoles[role] || [];
+ let children = descendantRoles[role];
+ if (!children) return;
// Some subroles have required properties which are also required by the superclass.
// Example: The checked state of radio, which is also required by superclass checkbox.
// We only want to include these one time, so filter out the subroles.
- children = children.filter(function (subrole) {
+ children = [...children].filter(function (subrole) {
return subrole.indexOf(propList[item.name].roles) === -1;
});
myList = myList.concat(children);
From bb33ac0c7fc8324ae1b1f5546c0b89681898d995 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Fri, 15 Dec 2023 19:33:27 +0100
Subject: [PATCH 86/93] refactor(aria.js): improve propListLoop's HTML
generation for inheritedRoles)
Hopefully simplifies this. But also a big TODO question.
test.sh run is clean.
---
script/aria.js | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 1698f18..ccb4791 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -536,21 +536,24 @@ const propListLoop = function (propList, descendantRoles, item) {
const placeholderInheritedRoles = section.querySelector(
".state-descendants, .property-descendants"
);
- let myList = [];
+ let inheritedRoles = new Set();
item.roles.forEach(function (role) {
- // SUPERTODO: can we simplify this?
- let children = descendantRoles[role];
- if (!children) return;
// Some subroles have required properties which are also required by the superclass.
// Example: The checked state of radio, which is also required by superclass checkbox.
// We only want to include these one time, so filter out the subroles.
- children = [...children].filter(function (subrole) {
- return subrole.indexOf(propList[item.name].roles) === -1;
+ if (!descendantRoles[role]) return;
+ descendantRoles[role].forEach((subrole) => {
+ if (subrole.indexOf(propList[item.name].roles) === -1)
+ inheritedRoles.add(subrole);
+ // TODO: the if-check doesn't make sense
+ // Should it be the other way around? I.e.
+ // if (propList[item.name].roles.indexOf(subrole) === -1)
+ // inheritedRoles.add(subrole);
+ // But this changes the spec, adding some, removing other entries
});
- myList = myList.concat(children);
});
- placeholderInheritedRoles.innerHTML = `\n${[...new Set(myList)]
+ placeholderInheritedRoles.innerHTML = `\n${[...inheritedRoles]
.sort()
.map((role) => `- ${role}
\n`)
.join("")}
\n`;
From 51e0fdebf795efa5cce1ea289dd34779f82d08e7 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Fri, 15 Dec 2023 19:34:56 +0100
Subject: [PATCH 87/93] refactor(aria.js): improve createDescendantRoles()
Remove some unnecessary spread operations.
test.sh run is clean.
---
script/aria.js | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index ccb4791..9bb0b5f 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -469,11 +469,10 @@ const createDescendantRoles = (subRoles) => {
const getAllSubRoles = function (key) {
const subroleSet = new Set();
if (!subRoles[key]) return subroleSet; // NOTE: recursion end
- const childRoles = [...subRoles[key]];
- childRoles.forEach(function (childRole) {
+ subRoles[key].forEach(function (childRole) {
subroleSet.add(childRole);
const descendantRolesSet = getAllSubRoles(childRole);
- [...descendantRolesSet].forEach((role) => subroleSet.add(role));
+ descendantRolesSet.forEach((role) => subroleSet.add(role));
});
return subroleSet;
};
From e005eae1fbb6d0c80315cd1ea5b2900c055caabb Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 18 Dec 2023 12:04:42 +0100
Subject: [PATCH 88/93] refactor(aria.js): improve
buildInheritedStatesProperties()
Simplify sortedList and add TODO / note on bug.
test.sh run is clean.
---
script/aria.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/script/aria.js b/script/aria.js
index 9bb0b5f..d804f38 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -363,12 +363,13 @@ const buildInheritedStatesProperties = function (item) {
const sortedList = reducedList.sort((a, b) => {
if (a.name == b.name) {
+ //TODO: BUG: deprecated states&props do not actually appear at end
// Ensure deprecated false properties occur first
if (a.deprecated !== b.deprecated) {
return a.deprecated ? 1 : b.deprecated ? -1 : 0;
}
}
- return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
+ return a.name.localeCompare(b.name);
}, []);
let prev; //SUPERTODO: get rid of "prev"
From 35ffe779521f4d86a5961b75b74654c532a913ee Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 18 Dec 2023 12:12:24 +0100
Subject: [PATCH 89/93] refactor(aria.js): improve
buildInheritedStatesProperties()
Get rid of placeholder variable by moving the querySelector to its only use.
Note: if the placeholder doesn't exist, we should fix something.
test.sh run is clean.
---
script/aria.js | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index d804f38..38e0423 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -312,6 +312,7 @@ const populateRoleInfoPropList = function (roleInfo, propList, item) {
/**
* TODO: depends on global roleInfo object
+ * Generats `allprops` array for a role entry in roleInfo
* @param {string} role - name of a role
* @returns
*/
@@ -338,10 +339,6 @@ const getStates = function (role) {
* @param {Object} item - value from Object.values(roleInfo)
*/
const buildInheritedStatesProperties = function (item) {
- const placeholder = document.querySelector(
- "#" + item.fragID + " .role-inherited"
- );
- if (!placeholder) return;
// SUPERTODO: simplify (from here until sortedList)
let myList = [];
@@ -390,7 +387,9 @@ const buildInheritedStatesProperties = function (item) {
})
.join("");
if (output !== "") {
- placeholder.innerHTML = `\n`;
+ document.querySelector(
+ "#" + item.fragID + " .role-inherited"
+ ).innerHTML = `\n`;
}
};
From 684b6868fd85f128eb6b08ca457fc215bc1347ed Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 18 Dec 2023 17:26:24 +0100
Subject: [PATCH 90/93] refactor(aria.js): improve
buildInheritedStatesProperties()
Get rid of the prev variable; hopefully makes it clearer what we're doing.
Also adds more TODOs for additional clarifications in the future.
test.sh run is clean. roleInfo exports identically.
---
script/aria.js | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 38e0423..ec52f01 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -369,12 +369,12 @@ const buildInheritedStatesProperties = function (item) {
return a.name.localeCompare(b.name);
}, []);
- let prev; //SUPERTODO: get rid of "prev"
- const output = sortedList
- .map((property) => {
- if (prev === property.name) return "";
- prev = property.name;
-
+ const uniquePropNames = new Set(sortedList.map(prop => prop.name))
+ // NOTE: uniquePropNames is needed because sortedList can have duplicates, in particular with different deprecation states. E.g., treeitem inherits aria-disabled from option but also as deprecated-in-1.2 from listitem.
+ // TODO: is it just luck that the not-deprecated state is listed first? (see same comment below)
+ const output = [...uniquePropNames]
+ .map((propName) => {
+ const property = sortedList.find(p => p.name === propName); // TODO: is it just luck that the not-deprecated state is listed first?
const isState = property.is === "state";
const suffix = isState ? " (state)" : "";
const tag = isState ? "sref" : "pref";
From e89df4d49a2f1ef7bad06635f2d5257ae1382987 Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 18 Dec 2023 17:30:36 +0100
Subject: [PATCH 91/93] refactor(aria.js): write up TODOs for
buildInheritedStatesProperties()
Replaces super-todo with several questions.
Also adds a TODO to the main function just before
buildInheritedStatesProperties()
test.sh run is clean. roleInfo export is clean.
---
script/aria.js | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index ec52f01..384ae4a 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -317,6 +317,7 @@ const populateRoleInfoPropList = function (roleInfo, propList, item) {
* @returns
*/
const getStates = function (role) {
+ // TODO: pkra would like to use sets here but allprops part of roleInfo serializaton
const ref = roleInfo[role];
if (!ref) {
msg.pub("error", "No role definition for " + role);
@@ -340,12 +341,19 @@ const getStates = function (role) {
*/
const buildInheritedStatesProperties = function (item) {
- // SUPERTODO: simplify (from here until sortedList)
+ // BEGIN TODO: why can't we do, e.g.,
+ // 1. in the main function: Object.keys(roleInfo).forEach(role=> getStates(role)); (see also TODO: near where buildInheritedStatesProperties() is called)
+ // - Then: let myList = item.allprops; (instead of myList = myList.concat(getStates(role)))
+ // - NOTE: the HTML stays the same but the exported roleInfo isn't.
+ // - TODO: BUG? in the existing roleInfo allprops only occurs 30 times
let myList = [];
item.parentRoles.forEach(function (role) {
myList = myList.concat(getStates(role));
});
+ // END TODO
// strip out any items that we have locally
+ // BEGIN TODO: why can't we do myList.filter( inherited => item.localprops.includes(local => local.name === inherited.name))?
+ // or do something else to simplify this
if (item.localprops.length && myList.length) {
for (let j = myList.length - 1; j >= 0; j--) {
item.localprops.forEach(function (x) {
@@ -355,12 +363,13 @@ const buildInheritedStatesProperties = function (item) {
});
}
}
-
+
const reducedList = [...new Set(myList)];
const sortedList = reducedList.sort((a, b) => {
if (a.name == b.name) {
//TODO: BUG: deprecated states&props do not actually appear at end
+ // NOTE: removing if (a.deprecated !== b.deprecated) seems to fix this
// Ensure deprecated false properties occur first
if (a.deprecated !== b.deprecated) {
return a.deprecated ? 1 : b.deprecated ? -1 : 0;
@@ -624,6 +633,7 @@ function ariaAttributeReferences() {
// TODO: test this on a page where `skipIndex` is truthy
if (!skipIndex) {
+ // TODO: why not run `Object.keys(roleInfo).forEach(role=> getStates(role))` here? (cf. TODO: in buildInheritedStatesProperties )
Object.values(roleInfo).forEach(buildInheritedStatesProperties);
const descendantRoles = createDescendantRoles(subRoles);
From c934495e70284b6fabb88d8e18ebd9497312410f Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 18 Dec 2023 17:31:10 +0100
Subject: [PATCH 92/93] fix(text.sh): checkout aria.js at start
---
test.sh | 1 +
1 file changed, 1 insertion(+)
diff --git a/test.sh b/test.sh
index aa27850..3b2fda1 100644
--- a/test.sh
+++ b/test.sh
@@ -3,6 +3,7 @@
# NOTE: Assumes there's a copy of w3c/aria in ../aria/
rm before.html after.html
+git -C ../aria/ checkout ./common/script/aria.js
echo "Run respec on ../aria/index.html to generate 'before.html'"
npx respec --src ../aria/index.html --out before.html
echo "Copy ./script/aria.js to ../aria/common/script/"
From 30d08944f698ac9345f55089c5e719c8c8c6075c Mon Sep 17 00:00:00 2001
From: Peter Krautzberger
Date: Mon, 18 Dec 2023 18:11:11 +0100
Subject: [PATCH 93/93] chore(aria.js): appease eslint
---
script/aria.js | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/script/aria.js b/script/aria.js
index 384ae4a..68ad486 100644
--- a/script/aria.js
+++ b/script/aria.js
@@ -340,11 +340,10 @@ const getStates = function (role) {
* @param {Object} item - value from Object.values(roleInfo)
*/
const buildInheritedStatesProperties = function (item) {
-
// BEGIN TODO: why can't we do, e.g.,
// 1. in the main function: Object.keys(roleInfo).forEach(role=> getStates(role)); (see also TODO: near where buildInheritedStatesProperties() is called)
// - Then: let myList = item.allprops; (instead of myList = myList.concat(getStates(role)))
- // - NOTE: the HTML stays the same but the exported roleInfo isn't.
+ // - NOTE: the HTML stays the same but the exported roleInfo isn't.
// - TODO: BUG? in the existing roleInfo allprops only occurs 30 times
let myList = [];
item.parentRoles.forEach(function (role) {
@@ -352,7 +351,7 @@ const buildInheritedStatesProperties = function (item) {
});
// END TODO
// strip out any items that we have locally
- // BEGIN TODO: why can't we do myList.filter( inherited => item.localprops.includes(local => local.name === inherited.name))?
+ // BEGIN TODO: why can't we do myList.filter( inherited => item.localprops.includes(local => local.name === inherited.name))?
// or do something else to simplify this
if (item.localprops.length && myList.length) {
for (let j = myList.length - 1; j >= 0; j--) {
@@ -363,12 +362,12 @@ const buildInheritedStatesProperties = function (item) {
});
}
}
-
+
const reducedList = [...new Set(myList)];
const sortedList = reducedList.sort((a, b) => {
if (a.name == b.name) {
- //TODO: BUG: deprecated states&props do not actually appear at end
+ //TODO: BUG: deprecated states&props do not actually appear at end
// NOTE: removing if (a.deprecated !== b.deprecated) seems to fix this
// Ensure deprecated false properties occur first
if (a.deprecated !== b.deprecated) {
@@ -378,12 +377,12 @@ const buildInheritedStatesProperties = function (item) {
return a.name.localeCompare(b.name);
}, []);
- const uniquePropNames = new Set(sortedList.map(prop => prop.name))
+ const uniquePropNames = new Set(sortedList.map((prop) => prop.name));
// NOTE: uniquePropNames is needed because sortedList can have duplicates, in particular with different deprecation states. E.g., treeitem inherits aria-disabled from option but also as deprecated-in-1.2 from listitem.
// TODO: is it just luck that the not-deprecated state is listed first? (see same comment below)
const output = [...uniquePropNames]
.map((propName) => {
- const property = sortedList.find(p => p.name === propName); // TODO: is it just luck that the not-deprecated state is listed first?
+ const property = sortedList.find((p) => p.name === propName); // TODO: is it just luck that the not-deprecated state is listed first?
const isState = property.is === "state";
const suffix = isState ? " (state)" : "";
const tag = isState ? "sref" : "pref";