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.

103 lines
4.9KB

  1. "use strict";
  2. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  3. exports.__esModule = true;
  4. exports.hasAnyConcreteRoles = hasAnyConcreteRoles;
  5. exports.isElement = isElement;
  6. exports.isHTMLFieldSetElement = isHTMLFieldSetElement;
  7. exports.isHTMLInputElement = isHTMLInputElement;
  8. exports.isHTMLLegendElement = isHTMLLegendElement;
  9. exports.isHTMLOptGroupElement = isHTMLOptGroupElement;
  10. exports.isHTMLSelectElement = isHTMLSelectElement;
  11. exports.isHTMLSlotElement = isHTMLSlotElement;
  12. exports.isHTMLTableCaptionElement = isHTMLTableCaptionElement;
  13. exports.isHTMLTableElement = isHTMLTableElement;
  14. exports.isHTMLTextAreaElement = isHTMLTextAreaElement;
  15. exports.isSVGElement = isSVGElement;
  16. exports.isSVGSVGElement = isSVGSVGElement;
  17. exports.isSVGTitleElement = isSVGTitleElement;
  18. exports.queryIdRefs = queryIdRefs;
  19. exports.safeWindow = safeWindow;
  20. var _getRole = _interopRequireWildcard(require("./getRole"));
  21. exports.getLocalName = _getRole.getLocalName;
  22. function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
  23. function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  24. function isElement(node) {
  25. return node !== null && node.nodeType === node.ELEMENT_NODE;
  26. }
  27. function isHTMLTableCaptionElement(node) {
  28. return isElement(node) && (0, _getRole.getLocalName)(node) === "caption";
  29. }
  30. function isHTMLInputElement(node) {
  31. return isElement(node) && (0, _getRole.getLocalName)(node) === "input";
  32. }
  33. function isHTMLOptGroupElement(node) {
  34. return isElement(node) && (0, _getRole.getLocalName)(node) === "optgroup";
  35. }
  36. function isHTMLSelectElement(node) {
  37. return isElement(node) && (0, _getRole.getLocalName)(node) === "select";
  38. }
  39. function isHTMLTableElement(node) {
  40. return isElement(node) && (0, _getRole.getLocalName)(node) === "table";
  41. }
  42. function isHTMLTextAreaElement(node) {
  43. return isElement(node) && (0, _getRole.getLocalName)(node) === "textarea";
  44. }
  45. function safeWindow(node) {
  46. var _ref = node.ownerDocument === null ? node : node.ownerDocument,
  47. defaultView = _ref.defaultView;
  48. if (defaultView === null) {
  49. throw new TypeError("no window available");
  50. }
  51. return defaultView;
  52. }
  53. function isHTMLFieldSetElement(node) {
  54. return isElement(node) && (0, _getRole.getLocalName)(node) === "fieldset";
  55. }
  56. function isHTMLLegendElement(node) {
  57. return isElement(node) && (0, _getRole.getLocalName)(node) === "legend";
  58. }
  59. function isHTMLSlotElement(node) {
  60. return isElement(node) && (0, _getRole.getLocalName)(node) === "slot";
  61. }
  62. function isSVGElement(node) {
  63. return isElement(node) && node.ownerSVGElement !== undefined;
  64. }
  65. function isSVGSVGElement(node) {
  66. return isElement(node) && (0, _getRole.getLocalName)(node) === "svg";
  67. }
  68. function isSVGTitleElement(node) {
  69. return isSVGElement(node) && (0, _getRole.getLocalName)(node) === "title";
  70. }
  71. /**
  72. *
  73. * @param {Node} node -
  74. * @param {string} attributeName -
  75. * @returns {Element[]} -
  76. */
  77. function queryIdRefs(node, attributeName) {
  78. if (isElement(node) && node.hasAttribute(attributeName)) {
  79. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- safe due to hasAttribute check
  80. var ids = node.getAttribute(attributeName).split(" ");
  81. // Browsers that don't support shadow DOM won't have getRootNode
  82. var root = node.getRootNode ? node.getRootNode() : node.ownerDocument;
  83. return ids.map(function (id) {
  84. return root.getElementById(id);
  85. }).filter(function (element) {
  86. return element !== null;
  87. }
  88. // TODO: why does this not narrow?
  89. );
  90. }
  91. return [];
  92. }
  93. function hasAnyConcreteRoles(node, roles) {
  94. if (isElement(node)) {
  95. return roles.indexOf((0, _getRole.default)(node)) !== -1;
  96. }
  97. return false;
  98. }
  99. //# sourceMappingURL=util.js.map