feat: implement caching for hash function

This commit is contained in:
Twig 2025-07-14 20:05:31 +02:00
parent bbc822604f
commit 25cd9a397e
No known key found for this signature in database

View file

@ -5,11 +5,9 @@ let h64: CallableFunction;
h64 = (await xxhash()).h64;
})();
export default (seed: string): string => {
const lightness = 50
// this should probably be cached eventually
const idHash = h64(seed)
export default (seed: string, saturation: number = 100, lightness: number = 50): string => {
const idHash = useState(`h64Hash-${seed}`, () => h64(seed))
const hashValue: bigint = idHash.value
return `hsl(${idHash % 360n}, 100%, ${lightness}%)`
return `hsl(${hashValue % 360n}, ${saturation}%, ${lightness}%)`
}