string-to-tailwind-color
Version:
Generates a random but deterministic Tailwind CSS color and shade from a string
58 lines (51 loc) • 1.34 kB
JavaScript
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
$parcel$export(module.exports, "stringToTailwindColor", () => $53ffd25df6034fb9$export$de7a1b5ba73c33cf);
// NOTE: https://tailwindcss.com/docs/colors
const $7d6b6ade7dcb2ebf$export$f1dd60f4a4247eae = [
'red',
'orange',
'amber',
'yellow',
'lime',
'green',
'emerald',
'teal',
'cyan',
'sky',
'blue',
'indigo',
'violet',
'purple',
'fuchsia',
'pink',
'rose',
'slate',
'gray',
'zinc',
'neutral',
'stone'
];
const $7d6b6ade7dcb2ebf$export$52a0f1e305b7e872 = [
50,
100,
200,
300,
400,
500,
600,
700,
800,
900,
950
];
const $53ffd25df6034fb9$export$de7a1b5ba73c33cf = (str, options = {})=>{
const colors = options.colors ?? (0, $7d6b6ade7dcb2ebf$export$f1dd60f4a4247eae);
const shades = options.shades ?? (0, $7d6b6ade7dcb2ebf$export$52a0f1e305b7e872);
const colorPool = [];
for (const color of colors)for (const shade of shades)colorPool.push(`${color}-${shade}`);
const stringHash = Array.from(str).reduce((acc, char)=>acc + char.charCodeAt(0), 0) + (options.hashOffset || 0);
return colorPool[stringHash % colorPool.length];
};
//# sourceMappingURL=main.js.map