diff --git a/flow/dequal.js b/flow/dequal.js deleted file mode 100644 index 62e7669..0000000 --- a/flow/dequal.js +++ /dev/null @@ -1,3 +0,0 @@ -declare module 'dequal/lite' { - declare export function dequal(foo: any, bar: any): boolean; -} diff --git a/package-lock.json b/package-lock.json index fba3ad0..ff999f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,9 +8,6 @@ "name": "aria-query", "version": "5.3.0", "license": "Apache-2.0", - "dependencies": { - "dequal": "^2.0.3" - }, "devDependencies": { "@babel/cli": "^7.19.3", "@babel/core": "^7.19.6", @@ -3852,14 +3849,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/dequal": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", - "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", - "engines": { - "node": ">=6" - } - }, "node_modules/detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", @@ -11795,11 +11784,6 @@ "object-keys": "^1.1.1" } }, - "dequal": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", - "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==" - }, "detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", diff --git a/package.json b/package.json index 00f04b8..5bcf86e 100644 --- a/package.json +++ b/package.json @@ -66,8 +66,5 @@ "not dead", "not op_mini all", "ie 11" - ], - "dependencies": { - "dequal": "^2.0.3" - } + ] } diff --git a/src/elementRoleMap.js b/src/elementRoleMap.js index b8df9e9..0d016a4 100644 --- a/src/elementRoleMap.js +++ b/src/elementRoleMap.js @@ -2,7 +2,6 @@ * @flow */ -import { dequal } from 'dequal/lite'; import iterationDecorator from "./util/iterationDecorator"; import rolesMap from './rolesMap'; @@ -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]]); } } } @@ -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]; }, @@ -82,6 +63,54 @@ const elementRoleMap: TAriaQueryMap< }, }; +function ariaRoleRelationConceptAttributeEquals( + a?: Array, + b?: Array, +): 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,