UNPKG

maz-ui

Version:

A standalone components library for Vue.Js 3 & Nuxt.Js 3

22 lines (21 loc) 985 B
import { i as isClient } from "../chunks/isClient.WI4oSt66.js"; import { ref, onMounted, onUnmounted } from "vue"; function useWindowSize(options = {}) { const { internalWindow = isClient() ? globalThis : void 0, initialWidth = Number.POSITIVE_INFINITY, initialHeight = Number.POSITIVE_INFINITY, includeScrollbar = !0 } = options, width = ref(initialWidth), height = ref(initialHeight); function update() { internalWindow && (includeScrollbar ? (width.value = internalWindow.innerWidth, height.value = internalWindow.innerHeight) : (width.value = internalWindow.document.documentElement.clientWidth, height.value = internalWindow.document.documentElement.clientHeight)); } return update(), onMounted(() => { internalWindow && internalWindow.addEventListener("resize", update, { passive: !0 }); }), onUnmounted(() => { internalWindow && internalWindow.removeEventListener("resize", update); }), { width, height }; } export { useWindowSize };