Skip to content

Commit 456d087

Browse files
committed
fix: tweak pulse colour
1 parent b72ed99 commit 456d087

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

app/components/PackageWeeklyDownloadStats.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ const accent = computed(() => {
4646
return id ? (oklchToHex(accentColorValueById.value[id]!) ?? '#8A8A8A') : '#8A8A8A'
4747
})
4848
49-
const pulseColor = computed(() => (selectedAccentColor.value ? accent.value : '#8A8A8A'))
49+
const pulseColor = computed(() => {
50+
if (!selectedAccentColor.value) {
51+
return isDarkMode.value ? '#BFBFBF' : '#E0E0E0'
52+
}
53+
return isDarkMode.value ? accent.value : lightenHex(accent.value, 0.5)
54+
})
5055
5156
const weeklyDownloads = ref<WeeklyDownloadPoint[]>([])
5257
@@ -105,7 +110,7 @@ const config = computed(() => {
105110
color: isDarkMode.value ? '#8a8a8a' : '#696969',
106111
},
107112
line: {
108-
color: '#696969',
113+
color: isDarkMode.value ? '#4a4a4a' : '#525252',
109114
pulse: {
110115
show: true,
111116
loop: true, // runs only once if false
@@ -125,7 +130,7 @@ const config = computed(() => {
125130
title: {
126131
text: lastDatapoint.value,
127132
fontSize: 12,
128-
color: '#8a8a8a',
133+
color: isDarkMode.value ? '#8a8a8a' : '#696969',
129134
bold: false,
130135
},
131136
verticalIndicator: {

app/utils/colors.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
11
// Vue Data UI does not support CSS vars nor OKLCH for now
2+
3+
/**
4+
* Converts a hex color to RGB components
5+
*/
6+
function hexToRgb(hex: string): [number, number, number] | null {
7+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
8+
return result
9+
? [parseInt(result[1]!, 16), parseInt(result[2]!, 16), parseInt(result[3]!, 16)]
10+
: null
11+
}
12+
13+
/**
14+
* Converts RGB components to hex color
15+
*/
16+
function rgbToHex(r: number, g: number, b: number): string {
17+
const toHex = (value: number): string =>
18+
Math.round(Math.min(Math.max(0, value), 255))
19+
.toString(16)
20+
.padStart(2, '0')
21+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`
22+
}
23+
24+
/**
25+
* Lightens a hex color by mixing it with white.
26+
* Used to create light tints of accent colors for better visibility in light mode.
27+
* @param hex - The hex color to lighten (e.g., "#ff0000")
28+
* @param factor - Lighten factor from 0 to 1 (0.5 = 50% lighter, mixed with white)
29+
*/
30+
export function lightenHex(hex: string, factor: number = 0.5): string {
31+
const rgb = hexToRgb(hex)
32+
if (!rgb) return hex
33+
34+
// Lighten by mixing with white (255, 255, 255)
35+
const lightened = rgb.map(c => Math.round(c + (255 - c) * factor)) as [number, number, number]
36+
return rgbToHex(...lightened)
37+
}
38+
239
export function oklchToHex(color: string | undefined | null): string | undefined | null {
340
if (color == null) return color
441

0 commit comments

Comments
 (0)