img.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = getImplicitRoleForImg;
  6. var _jsxAstUtils = require("jsx-ast-utils");
  7. /**
  8. * Returns the implicit role for an img tag.
  9. */
  10. function getImplicitRoleForImg(attributes) {
  11. var _getLiteralPropValue;
  12. var alt = (0, _jsxAstUtils.getProp)(attributes, 'alt');
  13. if (alt && (0, _jsxAstUtils.getLiteralPropValue)(alt) === '') {
  14. return '';
  15. }
  16. /**
  17. * If the src attribute can be determined to be an svg, allow the role to be set to 'img'
  18. * so that VoiceOver on Safari can be better supported.
  19. *
  20. * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#identifying_svg_as_an_image
  21. * @see https://bugs.webkit.org/show_bug.cgi?id=216364
  22. */
  23. var src = (0, _jsxAstUtils.getProp)(attributes, 'src');
  24. if (src && (_getLiteralPropValue = (0, _jsxAstUtils.getLiteralPropValue)(src)) !== null && _getLiteralPropValue !== void 0 && _getLiteralPropValue.includes('.svg')) {
  25. return '';
  26. }
  27. return 'img';
  28. }
  29. module.exports = exports.default;