UNPKG

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