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.

205 lines
6.7 KiB

  1. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  2. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  3. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  4. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  5. function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  6. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  7. // https://w3c.github.io/html-aria/#document-conformance-requirements-for-use-of-aria-attributes-in-html
  8. import { getLocalName } from "./util.mjs";
  9. var localNameToRoleMappings = {
  10. article: "article",
  11. aside: "complementary",
  12. body: "document",
  13. button: "button",
  14. datalist: "listbox",
  15. dd: "definition",
  16. details: "group",
  17. dialog: "dialog",
  18. dt: "term",
  19. fieldset: "group",
  20. figure: "figure",
  21. // WARNING: Only with an accessible name
  22. form: "form",
  23. footer: "contentinfo",
  24. h1: "heading",
  25. h2: "heading",
  26. h3: "heading",
  27. h4: "heading",
  28. h5: "heading",
  29. h6: "heading",
  30. header: "banner",
  31. hr: "separator",
  32. legend: "legend",
  33. li: "listitem",
  34. math: "math",
  35. main: "main",
  36. menu: "list",
  37. nav: "navigation",
  38. ol: "list",
  39. optgroup: "group",
  40. // WARNING: Only in certain context
  41. option: "option",
  42. output: "status",
  43. progress: "progressbar",
  44. // WARNING: Only with an accessible name
  45. section: "region",
  46. summary: "button",
  47. table: "table",
  48. tbody: "rowgroup",
  49. textarea: "textbox",
  50. tfoot: "rowgroup",
  51. // WARNING: Only in certain context
  52. td: "cell",
  53. th: "columnheader",
  54. thead: "rowgroup",
  55. tr: "row",
  56. ul: "list"
  57. };
  58. var prohibitedAttributes = {
  59. caption: new Set(["aria-label", "aria-labelledby"]),
  60. code: new Set(["aria-label", "aria-labelledby"]),
  61. deletion: new Set(["aria-label", "aria-labelledby"]),
  62. emphasis: new Set(["aria-label", "aria-labelledby"]),
  63. generic: new Set(["aria-label", "aria-labelledby", "aria-roledescription"]),
  64. insertion: new Set(["aria-label", "aria-labelledby"]),
  65. paragraph: new Set(["aria-label", "aria-labelledby"]),
  66. presentation: new Set(["aria-label", "aria-labelledby"]),
  67. strong: new Set(["aria-label", "aria-labelledby"]),
  68. subscript: new Set(["aria-label", "aria-labelledby"]),
  69. superscript: new Set(["aria-label", "aria-labelledby"])
  70. };
  71. /**
  72. *
  73. * @param element
  74. * @param role The role used for this element. This is specified to control whether you want to use the implicit or explicit role.
  75. */
  76. function hasGlobalAriaAttributes(element, role) {
  77. // https://rawgit.com/w3c/aria/stable/#global_states
  78. // commented attributes are deprecated
  79. return ["aria-atomic", "aria-busy", "aria-controls", "aria-current", "aria-describedby", "aria-details", // "disabled",
  80. "aria-dropeffect", // "errormessage",
  81. "aria-flowto", "aria-grabbed", // "haspopup",
  82. "aria-hidden", // "invalid",
  83. "aria-keyshortcuts", "aria-label", "aria-labelledby", "aria-live", "aria-owns", "aria-relevant", "aria-roledescription"].some(function (attributeName) {
  84. var _prohibitedAttributes;
  85. return element.hasAttribute(attributeName) && !((_prohibitedAttributes = prohibitedAttributes[role]) === null || _prohibitedAttributes === void 0 ? void 0 : _prohibitedAttributes.has(attributeName));
  86. });
  87. }
  88. function ignorePresentationalRole(element, implicitRole) {
  89. // https://rawgit.com/w3c/aria/stable/#conflict_resolution_presentation_none
  90. return hasGlobalAriaAttributes(element, implicitRole);
  91. }
  92. export default function getRole(element) {
  93. var explicitRole = getExplicitRole(element);
  94. if (explicitRole === null || explicitRole === "presentation") {
  95. var implicitRole = getImplicitRole(element);
  96. if (explicitRole !== "presentation" || ignorePresentationalRole(element, implicitRole || "")) {
  97. return implicitRole;
  98. }
  99. }
  100. return explicitRole;
  101. }
  102. function getImplicitRole(element) {
  103. var mappedByTag = localNameToRoleMappings[getLocalName(element)];
  104. if (mappedByTag !== undefined) {
  105. return mappedByTag;
  106. }
  107. switch (getLocalName(element)) {
  108. case "a":
  109. case "area":
  110. case "link":
  111. if (element.hasAttribute("href")) {
  112. return "link";
  113. }
  114. break;
  115. case "img":
  116. if (element.getAttribute("alt") === "" && !ignorePresentationalRole(element, "img")) {
  117. return "presentation";
  118. }
  119. return "img";
  120. case "input":
  121. {
  122. var _ref = element,
  123. type = _ref.type;
  124. switch (type) {
  125. case "button":
  126. case "image":
  127. case "reset":
  128. case "submit":
  129. return "button";
  130. case "checkbox":
  131. case "radio":
  132. return type;
  133. case "range":
  134. return "slider";
  135. case "email":
  136. case "tel":
  137. case "text":
  138. case "url":
  139. if (element.hasAttribute("list")) {
  140. return "combobox";
  141. }
  142. return "textbox";
  143. case "search":
  144. if (element.hasAttribute("list")) {
  145. return "combobox";
  146. }
  147. return "searchbox";
  148. default:
  149. return null;
  150. }
  151. }
  152. case "select":
  153. if (element.hasAttribute("multiple") || element.size > 1) {
  154. return "listbox";
  155. }
  156. return "combobox";
  157. }
  158. return null;
  159. }
  160. function getExplicitRole(element) {
  161. if (element.hasAttribute("role")) {
  162. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- safe due to hasAttribute check
  163. var _trim$split = element.getAttribute("role").trim().split(" "),
  164. _trim$split2 = _slicedToArray(_trim$split, 1),
  165. explicitRole = _trim$split2[0];
  166. if (explicitRole !== undefined && explicitRole.length > 0) {
  167. return explicitRole;
  168. }
  169. }
  170. return null;
  171. }
  172. //# sourceMappingURL=getRole.mjs.map