Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dequal from the project #554

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading