| 1 | // Avatar draws a mirrored 5×5 pattern from the handle: every account |
| 2 | // gets its own, and nothing is loaded from anywhere. |
| 3 | export function Avatar({ |
| 4 | handle, |
| 5 | size = 36, |
| 6 | }: { |
| 7 | handle: string |
| 8 | size?: number |
| 9 | }) { |
| 10 | let hash = 2166136261 |
| 11 | for (const c of handle) { |
| 12 | hash = Math.imul(hash ^ c.charCodeAt(0), 16777619) >>> 0 |
| 13 | } |
| 14 | const color = `oklch(0.62 0.11 ${hash % 360})` |
| 15 | const cells = [] |
| 16 | for (let i = 0; i < 15; i++) { |
| 17 | if ((hash >>> (i + 8)) & 1 || i === 7) { |
| 18 | const x = i % 3 |
| 19 | const y = Math.floor(i / 3) |
| 20 | cells.push(<rect key={i} x={x} y={y} width="1" height="1" />) |
| 21 | if (x < 2) { |
| 22 | cells.push( |
| 23 | <rect key={`m${i}`} x={4 - x} y={y} width="1" height="1" />, |
| 24 | ) |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | return ( |
| 29 | <svg |
| 30 | viewBox="-1.5 -1.5 8 8" |
| 31 | width={size} |
| 32 | height={size} |
| 33 | fill={color} |
| 34 | className="shrink-0 rounded-full" |
| 35 | style={{ background: `oklch(0.62 0.11 ${hash % 360} / 0.14)` }} |
| 36 | aria-hidden |
| 37 | > |
| 38 | {cells} |
| 39 | </svg> |
| 40 | ) |
| 41 | } |