your personal website on atproto - mirror
blento.app
1import type { Item } from '$lib/types';
2import { convertCSSToHex, hex_to_okhsv } from '@foxui/colors';
3
4export function getCSSVar(variable: string) {
5 return getComputedStyle(document.body).getPropertyValue(variable).trim();
6}
7
8/**
9 * Converts a CSS color string to a hue value in the 0-1 range
10 */
11export function colorToHue(color: string): number {
12 const hex = convertCSSToHex(color);
13 const okhsv = hex_to_okhsv(hex);
14 return okhsv.h;
15}
16
17export function getHexOfCardColor(item: Item) {
18 let color =
19 !item.color || item.color === 'transparent' || item.color === 'base' ? 'accent' : item.color;
20
21 return convertCSSToHex(getCSSVar(`--color-${color}-500`));
22}