web 3d图形渲染器
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.

88 lines
2.8 KiB

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