Files
linkwarden/apps/web/lib/client/oklchVariableToHex.ts
2025-04-10 18:38:59 -04:00

15 lines
444 B
TypeScript

import Color from "colorjs.io";
const oklchVariableToHex = (variable: string): string => {
const rootStyle = getComputedStyle(document.documentElement);
const rawColor = rootStyle.getPropertyValue(variable).trim();
const oklchColor = `oklch(${rawColor})`;
const hexColor = new Color(oklchColor)
.toGamut({ space: "srgb" })
.to("srgb")
.toString({ format: "hex" });
return hexColor;
};
export default oklchVariableToHex;