UNPKG

@nextcloud/vue

Version:
37 lines (36 loc) 1.42 kB
import { createSharedComposable, usePreferredDark, useMutationObserver } from "@vueuse/core"; import { computed, toValue, ref, watch, readonly, inject } from "vue"; import { checkIfDarkTheme } from "../../functions/isDarkTheme/index.mjs"; import { I as INJECTION_KEY_THEME } from "../../chunks/constants-Bls5liKo.mjs"; /*! * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ function useIsDarkThemeElement(el) { const element = computed(() => toValue(el) ?? document.body); const isDarkTheme = ref(checkIfDarkTheme(element.value)); const isDarkSystemTheme = usePreferredDark(); function updateIsDarkTheme() { isDarkTheme.value = checkIfDarkTheme(element.value); } useMutationObserver(element, updateIsDarkTheme, { attributes: true }); watch(element, updateIsDarkTheme); watch(isDarkSystemTheme, updateIsDarkTheme, { immediate: true }); return readonly(isDarkTheme); } const useInternalIsDarkTheme = createSharedComposable(() => useIsDarkThemeElement()); function useIsDarkTheme() { const isDarkTheme = useInternalIsDarkTheme(); const enforcedTheme = inject(INJECTION_KEY_THEME, void 0); return computed(() => { if (enforcedTheme?.value) { return enforcedTheme.value === "dark"; } return isDarkTheme.value; }); } export { useIsDarkTheme, useIsDarkThemeElement }; //# sourceMappingURL=index.mjs.map