22import { ref , computed , shallowRef , watch } from ' vue'
33import type { VueUiXyDatasetItem } from ' vue-data-ui'
44import { VueUiXy } from ' vue-data-ui/vue-ui-xy'
5- import { useDebounceFn } from ' @vueuse/core'
5+ import { useDebounceFn , useElementSize } from ' @vueuse/core'
66
77const {
88 weeklyDownloads,
@@ -18,8 +18,10 @@ const {
1818
1919const { accentColors, selectedAccentColor } = useAccentColor ()
2020const colorMode = useColorMode ()
21-
2221const resolvedMode = ref <' light' | ' dark' >(' light' )
22+ const rootEl = shallowRef <HTMLElement | null >(null )
23+
24+ const { width } = useElementSize (rootEl )
2325
2426onMounted (() => {
2527 resolvedMode .value = colorMode .value === ' dark' ? ' dark' : ' light'
@@ -51,32 +53,13 @@ const accent = computed(() => {
5153})
5254
5355const mobileBreakpointWidth = 640
54- const isMobile = ref (false )
55-
56- let resizeObserver: ResizeObserver | null = null
5756
58- function updateIsMobileFromWidth(width : number ) {
59- isMobile .value = width < mobileBreakpointWidth
60- }
61-
62- onMounted (() => {
63- if (! import .meta .client ) return
64-
65- updateIsMobileFromWidth (window .innerWidth )
66-
67- resizeObserver = new ResizeObserver (entries => {
68- const entry = entries [0 ]
69- if (! entry ) return
70- updateIsMobileFromWidth (entry .contentRect .width )
71- })
72-
73- resizeObserver .observe (document .documentElement )
57+ const isMobile = computed (() => {
58+ return width .value > 0 && width .value < mobileBreakpointWidth
7459})
7560
76- onBeforeUnmount (() => {
77- if (! resizeObserver ) return
78- resizeObserver .disconnect ()
79- resizeObserver = null
61+ onMounted (() => {
62+ rootEl .value = document .documentElement
8063})
8164
8265type ChartTimeGranularity = ' daily' | ' weekly' | ' monthly' | ' yearly'
0 commit comments