UNPKG

@base-ui/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) 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getViewportRect = getViewportRect; var _owner = require("@base-ui/utils/owner"); // Calculates the bounds the virtual cursor wraps within, as absolute edge coordinates. function getViewportRect(teleportDistance, scrubAreaEl) { const win = (0, _owner.ownerWindow)(scrubAreaEl); if (teleportDistance != null) { const rect = scrubAreaEl.getBoundingClientRect(); return { left: rect.left - teleportDistance / 2, top: rect.top - teleportDistance / 2, right: rect.right + teleportDistance / 2, bottom: rect.bottom + teleportDistance / 2 }; } const vV = win.visualViewport; if (vV) { return { left: vV.offsetLeft, top: vV.offsetTop, right: vV.offsetLeft + vV.width, bottom: vV.offsetTop + vV.height }; } return { left: 0, top: 0, right: win.document.documentElement.clientWidth, bottom: win.document.documentElement.clientHeight }; }