-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbrowserZoom.ts
More file actions
20 lines (18 loc) · 936 Bytes
/
Copy pathbrowserZoom.ts
File metadata and controls
20 lines (18 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/** Ctrl/Cmd + wheel or trackpad pinch — browser page zoom, not column scroll. */
export function isBrowserZoomWheelEvent(event: Pick<WheelEvent, "ctrlKey" | "metaKey">): boolean {
return event.ctrlKey || event.metaKey;
}
/** Pinch zoom enlarged the layout beyond 100% (visualViewport API). */
export function isBrowserPageZoomed(): boolean {
if (typeof window === "undefined") return false;
const viewport = window.visualViewport;
return viewport != null && Math.abs(viewport.scale - 1) > 0.01;
}
export function syncWebDocumentOverflowForZoom(): void {
if (typeof document === "undefined") return;
const overflow = isBrowserPageZoomed() ? "auto" : "hidden";
document.documentElement.style.overflow = overflow;
document.body.style.overflow = overflow;
const root = document.getElementById("root") ?? document.querySelector("[data-expo-root]");
if (root instanceof HTMLElement) root.style.overflow = overflow;
}