@tokens-studio/sd-transforms
Version:
Custom transforms for Style-Dictionary, to work with Design Tokens that are exported from Tokens Studio
19 lines (18 loc) • 897 B
JavaScript
import { usesReferences } from 'style-dictionary/utils';
import { modifyColor } from './modifyColor.js';
/**
* Helper: Transforms color tokens with tokens studio color modifiers
*/
export function transformColorModifiers(token, options) {
const modifier = token.$extensions['studio.tokens']?.modify;
// If some of the modifier props contain references or the modifier itself is a reference
// we should return undefined to manually defer this transformation until the references are resolved
// see: https://github.com/amzn/style-dictionary/blob/v4/docs/transforms.md#defer-transitive-transformation-manually
if (usesReferences(modifier) || Object.values(modifier).some(prop => usesReferences(prop))) {
return undefined;
}
if (options?.format) {
modifier.format = options.format;
}
return modifyColor(token.$value ?? token.value, modifier);
}