(str: string)
| 8 | } |
| 9 | } |
| 10 | export function stringToColor(str: string): string { |
| 11 | // Generate hash from string |
| 12 | let hash = 0; |
| 13 | for (let i = 0; i < str.length; i++) { |
| 14 | hash = str.charCodeAt(i) + ((hash << 5) - hash); |
| 15 | } |
| 16 | |
| 17 | // Convert to HSL for theme-appropriate colors |
| 18 | const h = Math.abs(hash) % 360; // Hue: 0-360 |
| 19 | const s = 50 + (Math.abs(hash >> 8) % 30); // Saturation: 50-80% |
| 20 | const l = 25 + (Math.abs(hash >> 16) % 20); // Lightness: 25-45% for dark backgrounds |
| 21 | |
| 22 | // Add secondary hue rotation for more variation |
| 23 | const h2 = (h + 137) % 360; // Golden angle rotation |
| 24 | const finalHue = hash % 2 === 0 ? h : h2; |
| 25 | |
| 26 | return `hsl(${finalHue}, ${s}%, ${l}%)`; |
| 27 | } |
| 28 | |
| 29 | // Get contrasting text color for a background |
| 30 | export function getContrastTextColor(backgroundColor: string): string { |
nothing calls this directly
no outgoing calls
no test coverage detected