import { RawValueSignature, matchIsRawColorHex, matchIsRawColorHsl, matchIsRawColorRgb, } from '@specifyapp/specify-design-token-format'; //@ts-ignore import tinycolor from 'tinycolor2'; export const colorToStyleDictionary = (color: RawValueSignature<'color'>): string | undefined => { const alpha = color.alpha.resolveDeepValue().unwrapValue(); if (matchIsRawColorHex(color)) { const tc = tinycolor(color.hex.resolveDeepValue().unwrapValue()); if (alpha === 1) { return tc.toHexString(); } tc.setAlpha(alpha); return tc.toHex8String(); } else if (matchIsRawColorRgb(color)) { return tinycolor({ r: color.red.resolveDeepValue().unwrapValue(), g: color.green.resolveDeepValue().unwrapValue(), b: color.blue.resolveDeepValue().unwrapValue(), a: alpha, }).toRgbString(); } else if (matchIsRawColorHsl(color)) { return tinycolor({ h: color.hue.resolveDeepValue().unwrapValue(), s: color.saturation.resolveDeepValue().unwrapValue(), l: color.lightness.resolveDeepValue().unwrapValue(), a: alpha, }).toHslString(); } else { return undefined; } };