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.

125 lines
3.6 KiB

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