()
| 69 | * Firefox & Safari are NEGATED, and IE & Edge are INVERTED. |
| 70 | */ |
| 71 | export function getRtlScrollAxisType(): RtlScrollAxisType { |
| 72 | // We can't check unless we're on the browser. Just assume 'normal' if we're not. |
| 73 | if (typeof document !== 'object' || !document) { |
| 74 | return RtlScrollAxisType.NORMAL; |
| 75 | } |
| 76 | |
| 77 | if (rtlScrollAxisType == null) { |
| 78 | // Create a 1px wide scrolling container and a 2px wide content element. |
| 79 | const scrollContainer = document.createElement('div'); |
| 80 | const containerStyle = scrollContainer.style; |
| 81 | scrollContainer.dir = 'rtl'; |
| 82 | containerStyle.width = '1px'; |
| 83 | containerStyle.overflow = 'auto'; |
| 84 | containerStyle.visibility = 'hidden'; |
| 85 | containerStyle.pointerEvents = 'none'; |
| 86 | containerStyle.position = 'absolute'; |
| 87 | |
| 88 | const content = document.createElement('div'); |
| 89 | const contentStyle = content.style; |
| 90 | contentStyle.width = '2px'; |
| 91 | contentStyle.height = '1px'; |
| 92 | |
| 93 | scrollContainer.appendChild(content); |
| 94 | document.body.appendChild(scrollContainer); |
| 95 | |
| 96 | rtlScrollAxisType = RtlScrollAxisType.NORMAL; |
| 97 | |
| 98 | // The viewport starts scrolled all the way to the right in RTL mode. If we are in a NORMAL |
| 99 | // browser this would mean that the scrollLeft should be 1. If it's zero instead we know we're |
| 100 | // dealing with one of the other two types of browsers. |
| 101 | if (scrollContainer.scrollLeft === 0) { |
| 102 | // In a NEGATED browser the scrollLeft is always somewhere in [-maxScrollAmount, 0]. For an |
| 103 | // INVERTED browser it is always somewhere in [0, maxScrollAmount]. We can determine which by |
| 104 | // setting to the scrollLeft to 1. This is past the max for a NEGATED browser, so it will |
| 105 | // return 0 when we read it again. |
| 106 | scrollContainer.scrollLeft = 1; |
| 107 | rtlScrollAxisType = |
| 108 | scrollContainer.scrollLeft === 0 ? RtlScrollAxisType.NEGATED : RtlScrollAxisType.INVERTED; |
| 109 | } |
| 110 | |
| 111 | scrollContainer.remove(); |
| 112 | } |
| 113 | return rtlScrollAxisType; |
| 114 | } |
no test coverage detected
searching dependent graphs…