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.

81 lines
2.6KB

  1. export { getLocalName } from "./getRole.mjs";
  2. import getRole, { getLocalName } from "./getRole.mjs";
  3. export function isElement(node) {
  4. return node !== null && node.nodeType === node.ELEMENT_NODE;
  5. }
  6. export function isHTMLTableCaptionElement(node) {
  7. return isElement(node) && getLocalName(node) === "caption";
  8. }
  9. export function isHTMLInputElement(node) {
  10. return isElement(node) && getLocalName(node) === "input";
  11. }
  12. export function isHTMLOptGroupElement(node) {
  13. return isElement(node) && getLocalName(node) === "optgroup";
  14. }
  15. export function isHTMLSelectElement(node) {
  16. return isElement(node) && getLocalName(node) === "select";
  17. }
  18. export function isHTMLTableElement(node) {
  19. return isElement(node) && getLocalName(node) === "table";
  20. }
  21. export function isHTMLTextAreaElement(node) {
  22. return isElement(node) && getLocalName(node) === "textarea";
  23. }
  24. export function safeWindow(node) {
  25. var _ref = node.ownerDocument === null ? node : node.ownerDocument,
  26. defaultView = _ref.defaultView;
  27. if (defaultView === null) {
  28. throw new TypeError("no window available");
  29. }
  30. return defaultView;
  31. }
  32. export function isHTMLFieldSetElement(node) {
  33. return isElement(node) && getLocalName(node) === "fieldset";
  34. }
  35. export function isHTMLLegendElement(node) {
  36. return isElement(node) && getLocalName(node) === "legend";
  37. }
  38. export function isHTMLSlotElement(node) {
  39. return isElement(node) && getLocalName(node) === "slot";
  40. }
  41. export function isSVGElement(node) {
  42. return isElement(node) && node.ownerSVGElement !== undefined;
  43. }
  44. export function isSVGSVGElement(node) {
  45. return isElement(node) && getLocalName(node) === "svg";
  46. }
  47. export function isSVGTitleElement(node) {
  48. return isSVGElement(node) && getLocalName(node) === "title";
  49. }
  50. /**
  51. *
  52. * @param {Node} node -
  53. * @param {string} attributeName -
  54. * @returns {Element[]} -
  55. */
  56. export function queryIdRefs(node, attributeName) {
  57. if (isElement(node) && node.hasAttribute(attributeName)) {
  58. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- safe due to hasAttribute check
  59. var ids = node.getAttribute(attributeName).split(" ");
  60. // Browsers that don't support shadow DOM won't have getRootNode
  61. var root = node.getRootNode ? node.getRootNode() : node.ownerDocument;
  62. return ids.map(function (id) {
  63. return root.getElementById(id);
  64. }).filter(function (element) {
  65. return element !== null;
  66. }
  67. // TODO: why does this not narrow?
  68. );
  69. }
  70. return [];
  71. }
  72. export function hasAnyConcreteRoles(node, roles) {
  73. if (isElement(node)) {
  74. return roles.indexOf(getRole(node)) !== -1;
  75. }
  76. return false;
  77. }
  78. //# sourceMappingURL=util.mjs.map