import { RtAchromatic, RtBreakpointScheme, RtFrameLayers, RtModifier, RtOperatorScheme, RtPrimitive, RtScheme, RtSizeScheme, RtTheme, RtTypescale, RtTypographyScheme, RtUse, } from '../rt-frame.types'; // eslint-disable-next-line @nx/enforce-module-boundaries import { _V_PREFIX_ } from '../../../../../../tools/constants'; export const ColorClassKeys = { modifier: `${_V_PREFIX_}-mode`, scheme: `${_V_PREFIX_}-scheme`, theme: `${_V_PREFIX_}-theme`, achromatic: `${_V_PREFIX_}-achr`, primitive: `${_V_PREFIX_}-primitive`, use: `${_V_PREFIX_}-use`, }; export const TypographyClassKeys = { typescale: `${_V_PREFIX_}-typescale`, typographyScheme: `${_V_PREFIX_}-typography-scheme`, operatorScheme: `${_V_PREFIX_}-operator`, }; export type LayerGroup = 'colors' | 'typography'; const orderedKeysOfColors: Array = [ 'use', 'modifier', 'scheme', 'theme', 'achromatic', 'primitive', ]; const abstractionsByFrameLayer: Record< keyof RtFrameLayers, Array< | RtUse | RtModifier | RtScheme | RtAchromatic | RtPrimitive | RtTheme | RtTypescale | RtBreakpointScheme | RtSizeScheme | RtTypographyScheme | RtOperatorScheme > > = { use: [ 'foggy', 'cloudy', 'ashy', 'error', 'success', 'warning', 'neutral', 'achromatic-cloudy', 'achromatic-ashy', 'notice', 'positive', 'attention', 'negative', 'primary', 'secondary', 'tertiary', 'quaternary', 'generic', ], modifier: ['base', 'mono', 'coloring', 'filling'], scheme: ['ritm'], theme: ['auto', 'dark', 'light'], achromatic: ['inverted', 'non-inverted'], primitive: ['normal', 'pastel', 'acid', 'contrast'], typographyScheme: ['primary', 'secondary', 'tertiary'], typescale: ['base', 'display'], sizeScheme: ['ritm'], breakpointScheme: ['ritm'], operatorScheme: ['ritm'], }; export const getColorClasses = ( currentAbstractions: RtFrameLayers, newAbstractions: RtFrameLayers ) => { const resultArray: string[] = []; let lastFilledChainIdx = 0; orderedKeysOfColors.forEach((key, idx) => { if (newAbstractions[key]) { lastFilledChainIdx = idx; } }); orderedKeysOfColors.forEach((key, idx) => { if (idx <= lastFilledChainIdx) { const value = currentAbstractions[key]; if (!ColorClassKeys[key as keyof typeof ColorClassKeys]) return; if (value && !abstractionsByFrameLayer[key]?.includes(value)) { resultArray.push( `${ColorClassKeys[key as keyof typeof ColorClassKeys]}-${ abstractionsByFrameLayer[key][0] }` ); } else { resultArray.push( `${ColorClassKeys[key as keyof typeof ColorClassKeys]}-${value}` ); } } }); return resultArray.join(' '); }; export const getTypographyClasses = (newAbstractions: RtFrameLayers) => { return Object.entries(newAbstractions) .filter( ([k]) => !!TypographyClassKeys[k as keyof typeof TypographyClassKeys] ) .map( ([k, value]) => TypographyClassKeys[k as keyof typeof TypographyClassKeys] + `-${value}` ) .join(' '); };