@nextcloud/vue
Version:
Nextcloud vue components
37 lines (36 loc) • 1.54 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const core = require("@vueuse/core");
const Vue = require("vue");
const Functions_isDarkTheme = require("../Functions/isDarkTheme.cjs");
const constants = require("../chunks/constants-C_lA-vcp.cjs");
/*!
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
function useIsDarkThemeElement(el) {
const element = Vue.computed(() => core.toValue(el) ?? document.body);
const isDarkTheme = Vue.ref(Functions_isDarkTheme.checkIfDarkTheme(element.value));
const isDarkSystemTheme = core.usePreferredDark();
function updateIsDarkTheme() {
isDarkTheme.value = Functions_isDarkTheme.checkIfDarkTheme(element.value);
}
core.useMutationObserver(element, updateIsDarkTheme, { attributes: true });
Vue.watch(element, updateIsDarkTheme);
Vue.watch(isDarkSystemTheme, updateIsDarkTheme, { immediate: true });
return Vue.readonly(isDarkTheme);
}
const useInternalIsDarkTheme = core.createSharedComposable(() => useIsDarkThemeElement());
function useIsDarkTheme() {
const isDarkTheme = useInternalIsDarkTheme();
const enforcedTheme = Vue.inject(constants.INJECTION_KEY_THEME, void 0);
return Vue.computed(() => {
if (enforcedTheme?.value) {
return enforcedTheme.value === "dark";
}
return isDarkTheme.value;
});
}
exports.useIsDarkTheme = useIsDarkTheme;
exports.useIsDarkThemeElement = useIsDarkThemeElement;
//# sourceMappingURL=useIsDarkTheme.cjs.map
;