maz-ui
Version:
A standalone components library for Vue.Js 3 & Nuxt.Js 3
22 lines (21 loc) • 966 B
JavaScript
import { e } from "../chunks/isClient.8V3qjGdO.js";
import { ref, onMounted, onUnmounted } from "vue";
function useWindowSize(options = {}) {
const {
internalWindow = e() ? 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
};