@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.
18 lines (17 loc) • 608 B
JavaScript
import { addEventListener } from '@base-ui/utils/addEventListener';
import { ownerWindow } from '@base-ui/utils/owner';
// This lets us invert the scale of the cursor to match the OS scale, in which the cursor doesn't
// scale with the content on pinch-zoom.
export function subscribeToVisualViewportResize(element, visualScaleRef) {
const vV = ownerWindow(element).visualViewport;
if (!vV) {
return () => {};
}
function handleVisualResize() {
if (vV) {
visualScaleRef.current = vV.scale;
}
}
handleVisualResize();
return addEventListener(vV, 'resize', handleVisualResize);
}