@patreon/studio
Version:
Patreon Studio Design System
43 lines • 1.51 kB
JavaScript
import { colorSchemeModes } from '~/utilities/color-scheme';
import { LRUCache } from '~/utilities/lru';
import { generateColorZones } from './generateColorZones';
/**
* Generates a complete color palette based on an input color.
*
* @param inputColor The color to use as the base for the generated colors.
*
* @returns A object containing a set of color ramps.
*/
function uncachedGenerateColorPalette({ inputColor }) {
return colorSchemeModes.reduce((acc, mode) => {
// generate the dynamic accent ramps
acc[mode] = generateColorZones({
color: inputColor,
colorSchemeMode: mode,
});
return acc;
}, {});
}
/**
* Generates a complete color palette based on an input color.
*
* @param inputColor The color to use as the base for the generated colors.
* @param config The configuration used when generating colors.
*
* @returns A object containing a set of color ramps.
*/
export const generateColorPalette = (() => {
// its okay that this is a global cache because the output of
// `generateColorPalette` is deterministic
const cache = new LRUCache({ size: 100 });
return ({ inputColor }) => {
const cachedPalette = cache.get(inputColor);
if (cachedPalette) {
return cachedPalette;
}
const palette = uncachedGenerateColorPalette({ inputColor });
cache.set(inputColor, palette);
return palette;
};
})();
//# sourceMappingURL=generateColorPalette.js.map