UNPKG

@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.

25 lines (24 loc) 776 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.subscribeToVisualViewportResize = subscribeToVisualViewportResize; var _owner = require("@base-ui-components/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. function subscribeToVisualViewportResize(element, visualScaleRef) { const vV = (0, _owner.ownerWindow)(element).visualViewport; if (!vV) { return () => {}; } function handleVisualResize() { if (vV) { visualScaleRef.current = vV.scale; } } handleVisualResize(); vV.addEventListener('resize', handleVisualResize); return () => { vV.removeEventListener('resize', handleVisualResize); }; }