import type { Token } from 'style-dictionary' import type { Config, NameTransform } from 'style-dictionary/types' type Transformer = NameTransform['transform'] type AnimationTokenValue = { name: string duration: string timingFunction: string delay?: string iterationCount?: string } export function filter(token: Token, options: Config): boolean { const tokenType = options.usesDtcg ? token.$type : token.type return tokenType === 'animation' } export const transform: Transformer = (token, config, options) => { const tokenValue = ( options.usesDtcg ? token.$value : token.value ) as AnimationTokenValue if (typeof tokenValue !== 'object') { // already transformed to string return tokenValue } const { name: animationName, duration, timingFunction, delay, iterationCount, } = tokenValue const animationShorthand = [duration, timingFunction] if (delay) { animationShorthand.push(delay) } if (iterationCount) { animationShorthand.push(iterationCount) } animationShorthand.push(animationName) return animationShorthand .join(' ') .replace(/\s{2,}/g, '') .trim() }