@base-ui-components/react
Version:
Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
35 lines (34 loc) • 984 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getViewportRect = getViewportRect;
var _owner = require("@base-ui-components/utils/owner");
// Calculates the viewport rect for the virtual cursor.
function getViewportRect(teleportDistance, scrubAreaEl) {
const win = (0, _owner.ownerWindow)(scrubAreaEl);
const rect = scrubAreaEl.getBoundingClientRect();
if (rect && teleportDistance != null) {
return {
x: rect.left - teleportDistance / 2,
y: rect.top - teleportDistance / 2,
width: rect.right + teleportDistance / 2,
height: rect.bottom + teleportDistance / 2
};
}
const vV = win.visualViewport;
if (vV) {
return {
x: vV.offsetLeft,
y: vV.offsetTop,
width: vV.offsetLeft + vV.width,
height: vV.offsetTop + vV.height
};
}
return {
x: 0,
y: 0,
width: win.document.documentElement.clientWidth,
height: win.document.documentElement.clientHeight
};
}