import { type Oklch, oklch } from "culori" import type { Config, PlatformConfig, TransformedToken } from "style-dictionary" import type { Transform } from "style-dictionary/types" import { isColor } from "../filters/isColor" import { getColorValue } from "../helpers/get" export function hexToOklchColor( token: TransformedToken, _: PlatformConfig, options: Config, ): string { const value = getColorValue(token, options) const color = oklch(value) as Oklch | undefined if (!color) { throw new Error("Invalid color value") } const l = color.l.toFixed(3) const c = color.c.toFixed(3) const h = (color.h ?? 0).toFixed(3) const result = `${l} ${c} ${h}` return result } export const oklchColorTransform: Transform = { name: "color/hex-to-oklch", type: "value", filter: isColor, transform: hexToOklchColor, }