import { RawValueSignature, matchIsRawGradientConic, matchIsRawGradientLinear, matchIsRawGradientRadial, } from '@specifyapp/specify-design-token-format'; import { colorToStyleDictionary } from './color.js'; export const gradientToStyleDictionary = (gradient: RawValueSignature<'gradient'>) => { const colorStops = gradient.colorStops .resolveDeepValue() .unwrapValue() .flatMap(value => { const v = value.resolveDeepValue().unwrapValue(); const color = v.color .resolveDeepValue() .mapPrimitiveValue(colorToStyleDictionary) .unwrapValue(); if (!color) return []; return [ { color, position: v.position.resolveDeepValue().unwrapValue(), }, ]; }); const type = gradient.type.unwrapValue(); if (matchIsRawGradientConic(gradient)) { const angle = gradient.angle.resolveDeepValue().unwrapValue(); const position = gradient.position.resolveDeepValue().unwrapValue(); return { type, colorStops, position, angle, }; } else if (matchIsRawGradientRadial(gradient)) { const position = gradient.position.resolveDeepValue().unwrapValue(); return { type, colorStops, position, }; } else if (matchIsRawGradientLinear(gradient)) { const angle = gradient.angle.resolveDeepValue().unwrapValue(); return { type, colorStops, angle, }; } };