accessible-description.mjs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
  2. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  3. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  4. import { computeTextAlternative } from "./accessible-name-and-description.mjs";
  5. import { queryIdRefs } from "./util.mjs";
  6. /**
  7. * implements https://w3c.github.io/accname/#mapping_additional_nd_description
  8. * @param root
  9. * @param [options]
  10. * @parma [options.getComputedStyle] - mock window.getComputedStyle. Needs `content`, `display` and `visibility`
  11. */
  12. export function computeAccessibleDescription(root) {
  13. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  14. var description = queryIdRefs(root, "aria-describedby").map(function (element) {
  15. return computeTextAlternative(element, _objectSpread(_objectSpread({}, options), {}, {
  16. compute: "description"
  17. }));
  18. }).join(" "); // TODO: Technically we need to make sure that node wasn't used for the accessible name
  19. // This causes `description_1.0_combobox-focusable-manual` to fail
  20. //
  21. // https://www.w3.org/TR/html-aam-1.0/#accessible-name-and-description-computation
  22. // says for so many elements to use the `title` that we assume all elements are considered
  23. if (description === "") {
  24. var title = root.getAttribute("title");
  25. description = title === null ? "" : title;
  26. }
  27. return description;
  28. }
  29. //# sourceMappingURL=accessible-description.mjs.map