getTextDirection.js 869 B

1234567891011121314151617181920212223242526
  1. "use strict";
  2. /**
  3. * Get the declared text direction for an element.
  4. *
  5. * @param {Node} element
  6. * @returns {string|undefined}
  7. */
  8. function getTextDirection(element) {
  9. var _element;
  10. // There is another way to determine text direction using getComputedStyle(), as done here:
  11. // https://github.com/pencil-js/text-direction/blob/2a235ce95089b3185acec3b51313cbba921b3811/text-direction.js
  12. //
  13. // We do not use that approach because we are interested specifically in the _declared_ text direction.
  14. // If no text direction is declared, we have to provide our own explicit text direction so our
  15. // bidirectional CSS style sheets work.
  16. while (element && !element.dir) {
  17. // eslint-disable-next-line no-param-reassign
  18. element = element.parentNode;
  19. }
  20. return (_element = element) == null ? void 0 : _element.dir;
  21. }
  22. module.exports = getTextDirection;