You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.7KB

  1. "use strict";
  2. exports.__esModule = true;
  3. exports.isInaccessible = isInaccessible;
  4. exports.isSubtreeInaccessible = isSubtreeInaccessible;
  5. /**
  6. * Partial implementation https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion
  7. * which should only be used for elements with a non-presentational role i.e.
  8. * `role="none"` and `role="presentation"` will not be excluded.
  9. *
  10. * Implements aria-hidden semantics (i.e. parent overrides child)
  11. * Ignores "Child Presentational: True" characteristics
  12. *
  13. * @param element
  14. * @param options
  15. * @returns {boolean} true if excluded, otherwise false
  16. */
  17. function isInaccessible(element) {
  18. var _element$ownerDocumen;
  19. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  20. var _options$getComputedS = options.getComputedStyle,
  21. getComputedStyle = _options$getComputedS === void 0 ? (_element$ownerDocumen = element.ownerDocument.defaultView) === null || _element$ownerDocumen === void 0 ? void 0 : _element$ownerDocumen.getComputedStyle : _options$getComputedS,
  22. _options$isSubtreeIna = options.isSubtreeInaccessible,
  23. isSubtreeInaccessibleImpl = _options$isSubtreeIna === void 0 ? isSubtreeInaccessible : _options$isSubtreeIna;
  24. if (typeof getComputedStyle !== "function") {
  25. throw new TypeError("Owner document of the element needs to have an associated window.");
  26. }
  27. // since visibility is inherited we can exit early
  28. if (getComputedStyle(element).visibility === "hidden") {
  29. return true;
  30. }
  31. var currentElement = element;
  32. while (currentElement) {
  33. if (isSubtreeInaccessibleImpl(currentElement, {
  34. getComputedStyle: getComputedStyle
  35. })) {
  36. return true;
  37. }
  38. currentElement = currentElement.parentElement;
  39. }
  40. return false;
  41. }
  42. /**
  43. *
  44. * @param element
  45. * @param options
  46. * @returns {boolean} - `true` if every child of the element is inaccessible
  47. */
  48. function isSubtreeInaccessible(element) {
  49. var _element$ownerDocumen2;
  50. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  51. var _options$getComputedS2 = options.getComputedStyle,
  52. getComputedStyle = _options$getComputedS2 === void 0 ? (_element$ownerDocumen2 = element.ownerDocument.defaultView) === null || _element$ownerDocumen2 === void 0 ? void 0 : _element$ownerDocumen2.getComputedStyle : _options$getComputedS2;
  53. if (typeof getComputedStyle !== "function") {
  54. throw new TypeError("Owner document of the element needs to have an associated window.");
  55. }
  56. if (element.hidden === true) {
  57. return true;
  58. }
  59. if (element.getAttribute("aria-hidden") === "true") {
  60. return true;
  61. }
  62. if (getComputedStyle(element).display === "none") {
  63. return true;
  64. }
  65. return false;
  66. }
  67. //# sourceMappingURL=is-inaccessible.js.map