import { RawValueSignature } from '@specifyapp/specify-design-token-format'; import { sizeToStyleDictionary } from './size.js'; import { colorToStyleDictionary } from './color.js'; import { fontToStyleDictionary } from './font.js'; export const textStyleToStyleDictionary = (textStyle: RawValueSignature<'textStyle'>) => { const font = textStyle.font.resolveDeepValue().mapPrimitiveValue(fontToStyleDictionary); const fontFeatures = textStyle.fontFeatures .resolveDeepValue() .mapPrimitiveValue(features => features?.map(feature => feature.resolveDeepValue().unwrapValue()), ) .unwrapValue(); const textAlignHorizontal = textStyle.textAlignHorizontal.resolveDeepValue().unwrapValue(); const textAlignVertical = textStyle.textAlignVertical.resolveDeepValue().unwrapValue(); const textDecoration = textStyle.textDecoration.resolveDeepValue().unwrapValue(); const textTransform = textStyle.textTransform.resolveDeepValue().unwrapValue(); const color = textStyle.color .resolveDeepValue() .mapPrimitiveValue(color => (color ? colorToStyleDictionary(color) : undefined)) .unwrapValue(); const letterSpacing = textStyle.letterSpacing .resolveDeepValue() .mapPrimitiveValue(size => (size ? sizeToStyleDictionary(size) : undefined)) .unwrapValue(); const lineHeight = textStyle.lineHeight .resolveDeepValue() .mapPrimitiveValue(size => (size ? sizeToStyleDictionary(size) : undefined)) .unwrapValue(); const paragraphSpacing = textStyle.paragraphSpacing .resolveDeepValue() .mapPrimitiveValue(size => (size ? sizeToStyleDictionary(size) : undefined)) .unwrapValue(); const textIndent = textStyle.textIndent .resolveDeepValue() .mapPrimitiveValue(size => (size ? sizeToStyleDictionary(size) : undefined)) .unwrapValue(); return { fontSize: textStyle.fontSize .resolveDeepValue() .mapPrimitiveValue(sizeToStyleDictionary) .unwrapValue(), ...(letterSpacing ? { letterSpacing } : {}), ...(lineHeight ? { lineHeight } : {}), ...(paragraphSpacing ? { paragraphSpacing } : {}), ...(textIndent ? { textIndent } : {}), ...(color ? { color } : {}), ...(font ? { font } : {}), ...(fontFeatures ? { fontFeatures } : {}), ...(textAlignHorizontal ? { textAlignHorizontal } : {}), ...(textAlignVertical ? { textAlignVertical } : {}), ...(textDecoration ? { textDecoration } : {}), ...(textTransform ? { textTransform } : {}), }; };