{"size": 1533, "ext": "js", "max_stars_repo_path": "node_modules/axe-core/lib/rules/landmark-unique-matches.js", "max_stars_repo_name": "dillonthompson/dillonthompson.github.io", "max_stars_repo_stars_event_min_datetime": "2019-09-26T12:58:08.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T06:23:55.000Z", "max_issues_repo_path": "node_modules/axe-core/lib/rules/landmark-unique-matches.js", "max_issues_repo_name": "dillonthompson/dillonthompson.github.io", "max_issues_repo_issues_event_min_datetime": "2019-09-28T09:50:02.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T08:36:10.000Z", "max_forks_repo_path": "node_modules/axe-core/lib/rules/landmark-unique-matches.js", "max_forks_repo_name": "dillonthompson/dillonthompson.github.io", "max_forks_repo_forks_event_min_datetime": "2019-09-28T09:06:20.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-22T04:58:59.000Z"}
{"max_stars_count": 908, "max_issues_count": 89, "max_forks_count": 65, "avg_line_length": 30.0588235294, "max_line_length": 152, "alphanum_fraction": 0.6816699282}
import { findUpVirtual, isVisible } from '../commons/dom';
import { getRole } from '../commons/aria';
import { getAriaRolesByType } from '../commons/standards';
import { accessibleTextVirtual } from '../commons/text';

function landmarkUniqueMatches(node, virtualNode) {
  /*
   * Since this is a best-practice rule, we are filtering elements as dictated by ARIA 1.1 Practices regardless of treatment by browser/AT combinations.
   *
   * Info: https://www.w3.org/TR/wai-aria-practices-1.1/#aria_landmark
   */
  var excludedParentsForHeaderFooterLandmarks = [
    'article',
    'aside',
    'main',
    'nav',
    'section'
  ].join(',');
  function isHeaderFooterLandmark(headerFooterElement) {
    return !findUpVirtual(
      headerFooterElement,
      excludedParentsForHeaderFooterLandmarks
    );
  }

  function isLandmarkVirtual(virtualNode) {
    var { actualNode } = virtualNode;
    var landmarkRoles = getAriaRolesByType('landmark');
    var role = getRole(actualNode);
    if (!role) {
      return false;
    }

    var nodeName = actualNode.nodeName.toUpperCase();
    if (nodeName === 'HEADER' || nodeName === 'FOOTER') {
      return isHeaderFooterLandmark(virtualNode);
    }

    if (nodeName === 'SECTION' || nodeName === 'FORM') {
      var accessibleText = accessibleTextVirtual(virtualNode);
      return !!accessibleText;
    }

    return landmarkRoles.indexOf(role) >= 0 || role === 'region';
  }

  return isLandmarkVirtual(virtualNode) && isVisible(node, true);
}

export default landmarkUniqueMatches;
