Spaces:
Sleeping
Sleeping
Andrew
commited on
Commit
·
f3975dd
1
Parent(s):
8d64b56
feat(utils): add persona color generation utility
Browse files
src/lib/utils/personaColors.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Generate a consistent color for a persona based on their ID
|
| 3 |
+
* Uses a rainbow spectrum for variety
|
| 4 |
+
*/
|
| 5 |
+
export function getPersonaColor(personaId: string): string {
|
| 6 |
+
// Simple hash function to get a number from persona ID
|
| 7 |
+
let hash = 0;
|
| 8 |
+
for (let i = 0; i < personaId.length; i++) {
|
| 9 |
+
hash = personaId.charCodeAt(i) + ((hash << 5) - hash);
|
| 10 |
+
hash = hash & hash; // Convert to 32bit integer
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
// Use hash to pick from a set of distinct colors
|
| 14 |
+
const colors = [
|
| 15 |
+
"#ef4444", // red
|
| 16 |
+
"#f97316", // orange
|
| 17 |
+
"#f59e0b", // amber
|
| 18 |
+
"#eab308", // yellow
|
| 19 |
+
"#84cc16", // lime
|
| 20 |
+
"#22c55e", // green
|
| 21 |
+
"#10b981", // emerald
|
| 22 |
+
"#14b8a6", // teal
|
| 23 |
+
"#06b6d4", // cyan
|
| 24 |
+
"#0ea5e9", // sky
|
| 25 |
+
"#3b82f6", // blue
|
| 26 |
+
"#6366f1", // indigo
|
| 27 |
+
"#8b5cf6", // violet
|
| 28 |
+
"#a855f7", // purple
|
| 29 |
+
"#d946ef", // fuchsia
|
| 30 |
+
"#ec4899", // pink
|
| 31 |
+
"#f43f5e", // rose
|
| 32 |
+
];
|
| 33 |
+
|
| 34 |
+
const index = Math.abs(hash) % colors.length;
|
| 35 |
+
return colors[index];
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* User message color
|
| 40 |
+
*/
|
| 41 |
+
export const USER_COLOR = "#9ca3af"; // gray-400
|