duplicate-img-label-evaluate.js 675 B

1234567891011121314151617181920212223
  1. import { getRole } from '../../commons/aria';
  2. import { visibleVirtual, accessibleTextVirtual } from '../../commons/text';
  3. import { closest } from '../../core/utils';
  4. function duplicateImgLabelEvaluate(node, options, virtualNode) {
  5. if (['none', 'presentation'].includes(getRole(virtualNode))) {
  6. return false;
  7. }
  8. const parentVNode = closest(virtualNode, options.parentSelector);
  9. if (!parentVNode) {
  10. return false;
  11. }
  12. const visibleText = visibleVirtual(parentVNode, true).toLowerCase();
  13. if (visibleText === '') {
  14. return false;
  15. }
  16. return visibleText === accessibleTextVirtual(virtualNode).toLowerCase();
  17. }
  18. export default duplicateImgLabelEvaluate;