25 lines
971 B
TypeScript
25 lines
971 B
TypeScript
export function colorForUsuario(usuarioId: string | number): { color: string; glow: string } {
|
|
const str = String(usuarioId);
|
|
let hash = 0;
|
|
for (let i = 0; i < str.length; i++) {
|
|
hash = ((hash << 5) - hash + str.charCodeAt(i)) | 0;
|
|
}
|
|
hash = Math.abs(hash);
|
|
// Use a mix of GLM palette + generated HSL to avoid collisions but keep brand feel
|
|
const glmPalette = ['#6CC24A', '#4F758B', '#FF6A13', '#C4D600', '#5B7F95', '#A4D65E', '#6B8FA3'];
|
|
const idx = hash % glmPalette.length;
|
|
// If palette length covers typical usuarios (50 max) collisions low; fallback to HSL for overflow
|
|
if (hash % 2 === 0) {
|
|
return { color: glmPalette[idx], glow: glmPalette[idx] };
|
|
}
|
|
const h = hash % 360;
|
|
const s = 65 + (hash % 20);
|
|
const l = 48 + (hash % 10);
|
|
const hsl = `hsl(${h} ${s}% ${l}%)`;
|
|
return { color: hsl, glow: hsl };
|
|
}
|
|
|
|
export function markerStyleForUsuario(usuarioId: string | number): string {
|
|
return colorForUsuario(usuarioId).color;
|
|
}
|