import { computed, watchEffect } from 'vue';
import '../../utils/index.mjs';
import { canUseDom } from '../../utils/dom/canUseDom.mjs';
import { getScrollBarSize } from '../../utils/scroll/getScrollBarSize.mjs';
import { updateCSS, removeCSS } from '../../utils/dom/dynamicCSS.mjs';

const UNIQUE_ID = `vc-util-locker-${Date.now()}`;
let uuid = 0;
function isBodyOverflowing() {
  return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) && window.innerWidth > document.body.offsetWidth;
}
function useScrollLocker(lock) {
  const mergedLock = computed(() => !!lock && !!lock.value);
  uuid += 1;
  const id = `${UNIQUE_ID}_${uuid}`;
  watchEffect(
    (onClear) => {
      if (!canUseDom())
        return;
      if (mergedLock.value) {
        const scrollbarSize = getScrollBarSize();
        const isOverflow = isBodyOverflowing();
        updateCSS(
          `
html body {
  overflow-y: hidden;
  ${isOverflow ? `width: calc(100% - ${scrollbarSize}px);` : ""}
}`,
          id
        );
      } else {
        removeCSS(id);
      }
      onClear(() => {
        removeCSS(id);
      });
    },
    { flush: "post" }
  );
}

export { isBodyOverflowing, useScrollLocker };
//# sourceMappingURL=index.mjs.map
