diff --git a/src/constants/note-width.ts b/src/constants/note-width.ts index 6d30842..19d0eec 100644 --- a/src/constants/note-width.ts +++ b/src/constants/note-width.ts @@ -1 +1,12 @@ -export const NOTE_WIDTH = 480 +let cached: number | undefined + +export const getNoteWidth = () => { + if (cached === undefined) { + cached = parseInt( + getComputedStyle(document.documentElement).getPropertyValue( + "--note-width", + ), + ) + } + return cached +} diff --git a/src/hooks/useNoteOverlay.hook.ts b/src/hooks/useNoteOverlay.hook.ts index f7c1f61..f544893 100644 --- a/src/hooks/useNoteOverlay.hook.ts +++ b/src/hooks/useNoteOverlay.hook.ts @@ -1,6 +1,6 @@ import { computed, onMounted, Ref, ref, toValue } from "vue" -import { NOTE_WIDTH } from "@/constants/note-width" +import { getNoteWidth } from "@/constants/note-width" import { useOverlay } from "@/hooks/useOverlay.hook" import { useRouteQueryStackedNotes } from "@/hooks/useRouteQueryStackedNotes.hook" @@ -20,7 +20,7 @@ export const useNoteOverlay = ( if (isMobile.value) { return y.value > valueIndex * noteHeight.value } else { - return x.value > valueIndex * NOTE_WIDTH - valueIndex * OFFSET + return x.value > valueIndex * getNoteWidth() - valueIndex * OFFSET } }) @@ -46,7 +46,7 @@ export const useNoteOverlay = ( ) satisfies NodeListOf stackedNoteContainers.forEach((stackedNote, ind) => { - stackedNote.style.right = `calc(-${NOTE_WIDTH}px + ${ + stackedNote.style.right = `calc(-${getNoteWidth()}px + ${ (stackedNotes.value.length - ind) * BOOKMARK_WIDTH }rem)` }) diff --git a/src/hooks/useResizeContainer.hook.ts b/src/hooks/useResizeContainer.hook.ts index 34428f0..5f5f8c5 100644 --- a/src/hooks/useResizeContainer.hook.ts +++ b/src/hooks/useResizeContainer.hook.ts @@ -1,6 +1,6 @@ import { onMounted, watch, type Ref } from "vue" -import { NOTE_WIDTH } from "@/constants/note-width" +import { getNoteWidth } from "@/constants/note-width" import { useOverlay } from "@/hooks/useOverlay.hook" export const useResizeContainer = ( @@ -22,7 +22,7 @@ export const useResizeContainer = ( container.style.height = `${(stackedNotes.value.length + 1) * 100}vh` } else { container.style.width = `${ - NOTE_WIDTH * (stackedNotes.value.length + 1) + getNoteWidth() * (stackedNotes.value.length + 1) }px` } } diff --git a/src/hooks/useRouteQueryStackedNotes.hook.ts b/src/hooks/useRouteQueryStackedNotes.hook.ts index 848272e..ba01399 100644 --- a/src/hooks/useRouteQueryStackedNotes.hook.ts +++ b/src/hooks/useRouteQueryStackedNotes.hook.ts @@ -2,7 +2,7 @@ import { useWindowSize } from "@vueuse/core" import { useRouteQuery } from "@vueuse/router" import { nextTick, readonly } from "vue" -import { NOTE_WIDTH } from "@/constants/note-width" +import { getNoteWidth } from "@/constants/note-width" import { useOverlay } from "@/hooks/useOverlay.hook" export const useRouteQueryStackedNotes = () => { @@ -37,7 +37,7 @@ export const useRouteQueryStackedNotes = () => { } else { if (sha) { const margin = index * 44 - const left = (index + 1) * NOTE_WIDTH - margin + const left = (index + 1) * getNoteWidth() - margin scrollToNote(left) } else { scrollToNote(0)