Skip to content

Commit

Permalink
Merge branch 'main' into wai-aria-1.3-roles
Browse files Browse the repository at this point in the history
  • Loading branch information
jlp-craigmorten authored Jul 5, 2024
2 parents d97418e + f5b8f4c commit 4dcd9be
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 44 deletions.
3 changes: 0 additions & 3 deletions flow/dequal.js

This file was deleted.

16 changes: 0 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,5 @@
"not dead",
"not op_mini all",
"ie 11"
],
"dependencies": {
"dequal": "^2.0.3"
}
]
}
71 changes: 50 additions & 21 deletions src/elementRoleMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @flow
*/

import { dequal } from 'dequal/lite';
import iterationDecorator from "./util/iterationDecorator";
import rolesMap from './rolesMap';

Expand All @@ -24,25 +23,7 @@ for (let i = 0; i < keys.length; i++) {
if (relation.module === 'HTML') {
const concept = relation.concept;
if (concept) {
const elementRoleRelation: ?ElementARIARoleRelationTuple = elementRoles.find(relation => dequal(relation, concept));
let roles: RoleSet;

if (elementRoleRelation) {
roles = elementRoleRelation[1];
} else {
roles = [];
}
let isUnique = true;
for (let i = 0; i < roles.length; i++) {
if (roles[i] === key) {
isUnique = false;
break;
}
}
if (isUnique) {
roles.push(key);
}
elementRoles.push([concept, roles]);
elementRoles.push([concept, [key]]);
}
}
}
Expand All @@ -67,7 +48,7 @@ const elementRoleMap: TAriaQueryMap<
},
get: function (key: ARIARoleRelationConcept): ?RoleSet {
const item = elementRoles.find(tuple => (
key.name === tuple[0].name && dequal(key.attributes, tuple[0].attributes)
key.name === tuple[0].name && ariaRoleRelationConceptAttributeEquals(key.attributes, tuple[0].attributes)
));
return item && item[1];
},
Expand All @@ -82,6 +63,54 @@ const elementRoleMap: TAriaQueryMap<
},
};

function ariaRoleRelationConceptAttributeEquals(
a?: Array<ARIARoleRelationConceptAttribute>,
b?: Array<ARIARoleRelationConceptAttribute>,
): boolean {

if (a === undefined && b !== undefined) {
return false;
}

if (a !== undefined && b === undefined) {
return false;
}

if (a !== undefined && b !== undefined) {
if (a.length !== b.length) {
return false;
}

for (let i = 0; i < a.length; i++) {
if (a[i].name !== b[i].name || a[i].value !== b[i].value) {
return false;
}

if (a[i].constraints === undefined && b[i].constraints !== undefined) {
return false;
}

if (a[i].constraints !== undefined && b[i].constraints === undefined) {
return false
}

if (a[i].constraints !== undefined && b[i].constraints !== undefined) {
if (a[i].constraints.length !== b[i].constraints.length) {
return false;
}

for (let j = 0; j < a[i].constraints.length; j++) {
if (a[i].constraints[j] !== b[i].constraints[j]) {
return false;
}
}
}
}
}

return true;
}

export default (
iterationDecorator(
elementRoleMap,
Expand Down

0 comments on commit 4dcd9be

Please sign in to comment.