11<script setup lang="ts">
2+ import { ACCENT_COLOR_TOKENS } from ' #shared/utils/constants'
3+
24const props = defineProps <{
35 packageName: string
46 resolvedVersion: string
@@ -9,24 +11,12 @@ const props = defineProps<{
911const { origin } = useRequestURL ()
1012const colorMode = useColorMode ()
1113const theme = computed (() => (colorMode .value === ' dark' ? ' dark' : ' light' ))
12- const { selectedAccentColor, accentColors } = useAccentColor ()
13-
14- function resolveColorToHex(color : string ): string {
15- const canvas = document .createElement (' canvas' )
16- canvas .width = canvas .height = 1
17- const ctx = canvas .getContext (' 2d' )!
18- ctx .fillStyle = color
19- ctx .fillRect (0 , 0 , 1 , 1 )
20- const [r, g, b] = ctx .getImageData (0 , 0 , 1 , 1 ).data
21- return ` #${r ! .toString (16 ).padStart (2 , ' 0' )}${g ! .toString (16 ).padStart (2 , ' 0' )}${b ! .toString (16 ).padStart (2 , ' 0' )} `
22- }
14+ const { selectedAccentColor } = useAccentColor ()
2315
2416const colorParam = computed (() => {
25- const id = selectedAccentColor .value
26- if (! id ) return ' '
27- const colorValue = accentColors .value .find (c => c .id === id )?.value
28- if (! colorValue ) return ' '
29- const hex = resolveColorToHex (colorValue )
17+ const id = selectedAccentColor .value as keyof typeof ACCENT_COLOR_TOKENS
18+ if (! id || ! (id in ACCENT_COLOR_TOKENS )) return ' '
19+ const hex = ACCENT_COLOR_TOKENS [id ][theme .value ].hex
3020 return ` &color=${encodeURIComponent (hex )} `
3121})
3222
0 commit comments