{"version":3,"file":"useIsDarkTheme.mjs","sources":["../../src/composables/useIsDarkTheme/index.ts"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { DeepReadonly, Ref } from 'vue'\nimport { ref, readonly, watch } from 'vue'\nimport { createSharedComposable, usePreferredDark, useMutationObserver } from '@vueuse/core'\nimport { checkIfDarkTheme } from '../../functions/isDarkTheme/index.ts'\n\n/**\n * Check whether the dark theme is enabled on a specific element.\n * If you need to check an entire page, use `useIsDarkTheme` instead for better performance.\n * Reacts on element attributes change and system theme change.\n * @param el - The element to check for the dark theme enabled on (default is `document.body`)\n * @return {DeepReadonly>} - computed boolean whether the dark theme is enabled\n */\nexport function useIsDarkThemeElement(el: HTMLElement = document.body): DeepReadonly> {\n\tconst isDarkTheme = ref(checkIfDarkTheme(el))\n\tconst isDarkSystemTheme = usePreferredDark()\n\n\t/** Update the isDarkTheme */\n\tfunction updateIsDarkTheme() {\n\t\tisDarkTheme.value = checkIfDarkTheme(el)\n\t}\n\n\t// Watch for element change to handle data-theme* attributes change\n\tuseMutationObserver(el, updateIsDarkTheme, { attributes: true })\n\t// Watch for system theme change for the default theme\n\twatch(isDarkSystemTheme, updateIsDarkTheme, { immediate: true })\n\n\treturn readonly(isDarkTheme)\n}\n\n/**\n * Shared composable to check whether the dark theme is enabled on the page.\n * Reacts on body data-theme-* attributes change and system theme change.\n * @return {DeepReadonly>} - computed boolean whether the dark theme is enabled\n */\nexport const useIsDarkTheme = createSharedComposable(() => useIsDarkThemeElement())\n"],"names":[],"mappings":";;;AAiBgB,SAAA,sBAAsB,KAAkB,SAAS,MAAkC;AAClG,QAAM,cAAc,IAAI,iBAAiB,EAAE,CAAC;AAC5C,QAAM,oBAAoB;AAG1B,WAAS,oBAAoB;AAChB,gBAAA,QAAQ,iBAAiB,EAAE;AAAA,EACxC;AAGA,sBAAoB,IAAI,mBAAmB,EAAE,YAAY,KAAM,CAAA;AAE/D,QAAM,mBAAmB,mBAAmB,EAAE,WAAW,KAAM,CAAA;AAE/D,SAAO,SAAS,WAAW;AAC5B;AAOO,MAAM,iBAAiB,uBAAuB,MAAM,sBAAuB,CAAA;"}