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
8export function getHexCSSVar(variable: string) {
9 return convertCSSToHex(getCSSVar(variable));
10}
11
12/**
13 * Converts a CSS color string to a hue value in the 0-1 range
14 */
15export function colorToHue(color: string): number {
16 const hex = convertCSSToHex(color);
17 const okhsv = hex_to_okhsv(hex);
18 return okhsv.h;
19}
20
21export function getHexOfCardColor(item: Item) {
22 const color =
23 !item.color || item.color === 'transparent' || item.color === 'base' ? 'accent' : item.color;
24
25 return convertCSSToHex(getCSSVar(`--color-${color}-500`));
26}