@patreon/studio
Version:
Patreon Studio Design System
42 lines • 1.83 kB
JavaScript
import { getCacheKey } from '~/utilities/color-system';
import { LRUCache } from '~/utilities/lru';
import { generateColorPalette } from './generateColorPalette';
/**
* Generates a token map based on a map definition and an extended color palette.
*
* @param inputColor The input color to use when generating the token map.
* @param tokenMap A JSON mapping of tokens to color ramp stops.
* @param config An optional color palette to use when generating the color palette
*
* @returns A tokens definition object with token keys and hex values
*/
function uncachedGenerateTokensDefinitionFromTokenMap({ inputColor, tokenMaps, }) {
const palette = generateColorPalette({ inputColor });
return {
dark: tokenMaps.dark(palette.dark),
light: tokenMaps.light(palette.light),
};
}
/**
* Generates a token map based on a map definition and an extended color palette.
*
* @param inputColor The input color to use when generating the token map.
* @param tokenMap A JSON mapping of tokens to color ramp stops.
* @param config An optional color palette to use when generating the color palette
*
* @returns A tokens definition object with token keys and hex values
*/
export const generateTokensDefinitionFromTokenMap = (() => {
const cache = new LRUCache({ size: 100 });
return ({ cacheKey: userCacheKey, inputColor, tokenMaps }) => {
const cacheKey = userCacheKey ?? getCacheKey({ inputColor, key: tokenMaps.key });
const cachedTokensDefintion = cache.get(cacheKey);
if (cachedTokensDefintion) {
return cachedTokensDefintion;
}
const palette = uncachedGenerateTokensDefinitionFromTokenMap({ inputColor, tokenMaps });
cache.set(cacheKey, palette);
return palette;
};
})();
//# sourceMappingURL=generateTokenMap.js.map