misc: add theme color to meta

This commit is contained in:
Xylight committed 2024-07-25 12:01:15 -07:00
1 parent 6b78827239
commit 02dcd0a06d
2 files changed
+37 -1

No files matched your search

+22
View File
@@ -57,6 +57,28 @@ export function hexToRgb(value: string) {
return `${r} ${g} ${b}`
}
export function rgbToHex(rgbString: string): string {
const rgb = rgbString.split(' ')
if (rgb.length !== 3) {
return rgbString
}
const [r, g, b] = rgb.map((val) => {
const num = parseInt(val, 10)
if (isNaN(num) || num < 0 || num > 255) {
return 0
}
return num
})
// Convert to hex and pad with zeros if necessary
const toHex = (n: number) => n.toString(16).padStart(2, '0')
// Return the hex color code
return `#${toHex(r)}${toHex(g)}${toHex(b)}`
}
function themeStore(
data: Writable<ThemeData>,
fn: (