@popperjs/core
Version:
Tooltip and Popover Positioning Engine
33 lines (30 loc) • 1.48 kB
JavaScript
import getBorders from "./getBorders.js";
import getNodeName from "./getNodeName.js";
import getWindow from "./getWindow.js";
import getWindowScrollBarX from "./getWindowScrollBarX.js"; // Borders + scrollbars
export default function getDecorations(element) {
var win = getWindow(element);
var borders = getBorders(element);
var isHTML = getNodeName(element) === 'html';
var winScrollBarX = getWindowScrollBarX(element);
var x = element.clientWidth + borders.right;
var y = element.clientHeight + borders.bottom; // HACK:
// document.documentElement.clientHeight on iOS reports the height of the
// viewport including the bottom bar, even if the bottom bar isn't visible.
// If the difference between window innerHeight and html clientHeight is more
// than 50, we assume it's a mobile bottom bar and ignore scrollbars.
// * A 50px thick scrollbar is likely non-existent (macOS is 15px and Windows
// is about 17px)
// * The mobile bar is 114px tall
if (isHTML && win.innerHeight - element.clientHeight > 50) {
y = win.innerHeight - borders.bottom;
}
return {
top: isHTML ? 0 : element.clientTop,
right: // RTL scrollbar (scrolling containers only)
element.clientLeft > borders.left ? borders.right : // LTR scrollbar
isHTML ? win.innerWidth - x - winScrollBarX : element.offsetWidth - x,
bottom: isHTML ? win.innerHeight - y : element.offsetHeight - y,
left: isHTML ? winScrollBarX : element.clientLeft
};
}