0597a30e2073a9e550f92907f7e5852dc16811679c699c84ffaf50951a95df74cb6281088aa6738d1d64ff489a89f5f3159994004538f6fc8afa714e10eebc 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { ref, getCurrentInstance, inject, computed, unref } from 'vue';
  2. import { isNumber } from '../../utils/types.mjs';
  3. import { isClient } from '@vueuse/core';
  4. const initial = {
  5. current: 0
  6. };
  7. const zIndex = ref(0);
  8. const defaultInitialZIndex = 2e3;
  9. const ZINDEX_INJECTION_KEY = Symbol("elZIndexContextKey");
  10. const zIndexContextKey = Symbol("zIndexContextKey");
  11. const useZIndex = (zIndexOverrides) => {
  12. const increasingInjection = getCurrentInstance() ? inject(ZINDEX_INJECTION_KEY, initial) : initial;
  13. const zIndexInjection = zIndexOverrides || (getCurrentInstance() ? inject(zIndexContextKey, void 0) : void 0);
  14. const initialZIndex = computed(() => {
  15. const zIndexFromInjection = unref(zIndexInjection);
  16. return isNumber(zIndexFromInjection) ? zIndexFromInjection : defaultInitialZIndex;
  17. });
  18. const currentZIndex = computed(() => initialZIndex.value + zIndex.value);
  19. const nextZIndex = () => {
  20. increasingInjection.current++;
  21. zIndex.value = increasingInjection.current;
  22. return currentZIndex.value;
  23. };
  24. if (!isClient && !inject(ZINDEX_INJECTION_KEY)) ;
  25. return {
  26. initialZIndex,
  27. currentZIndex,
  28. nextZIndex
  29. };
  30. };
  31. export { ZINDEX_INJECTION_KEY, defaultInitialZIndex, useZIndex, zIndexContextKey };
  32. //# sourceMappingURL=index.mjs.map