973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 1 | <script lang="ts"> |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 2 | import { mediaUrl } from './api'; |
05a48e9e7942 | atagen | 2026-10-24 09:32 UTC | 3 | import { initialsOf, senderHue } from './format'; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 4 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 5 | export let mxc: string | null; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 6 | export let label: string; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 7 | export let size = 34; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 8 | /** 'circle' for people, 'rounded' for rooms/spaces */ |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 9 | export let shape: 'circle' | 'rounded' = 'circle'; |
05a48e9e7942 | atagen | 2026-10-24 09:32 UTC | 10 | export let seed: string | null = null; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 11 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 12 | $: src = mediaUrl(mxc); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 13 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 14 | let failed = false; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 15 | $: if (mxc) failed = false; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 16 | $: px = `${size}px`; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 17 | $: fontPx = `${Math.max(10, Math.round(size * 0.36))}px`; |
05a48e9e7942 | atagen | 2026-10-24 09:32 UTC | 18 | $: hue = senderHue(seed ?? label ?? '#'); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 19 | </script> |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 20 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 21 | {#if src && !failed} |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 22 | <img |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 23 | {src} |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 24 | alt="" |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 25 | aria-hidden="true" |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 26 | width={size} |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 27 | height={size} |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 28 | loading="lazy" |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 29 | class="mxc-avatar" |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 30 | class:circle={shape === 'circle'} |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 31 | style={`width:${px};height:${px};`} |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 32 | on:error={() => (failed = true)} |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 33 | /> |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 34 | {:else} |
05a48e9e7942 | atagen | 2026-10-24 09:32 UTC | 35 | <span class="mxc-fallback" class:circle={shape === 'circle'} aria-hidden="true" style={`width:${px};height:${px};font-size:${fontPx};background:hsl(${hue} 32% 30%);`}> |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 36 | {initialsOf(label || '#')} |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 37 | </span> |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 38 | {/if} |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 39 | |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 40 | <style> |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 41 | .mxc-avatar { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 42 | flex: none; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 43 | object-fit: cover; |
05a48e9e7942 | atagen | 2026-10-24 09:32 UTC | 44 | border-radius: var(--r-md); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 45 | background: var(--bg-soft); |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 46 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 47 | .mxc-avatar.circle { border-radius: 50%; } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 48 | .mxc-fallback { |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 49 | flex: none; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 50 | display: inline-grid; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 51 | place-items: center; |
05a48e9e7942 | atagen | 2026-10-24 09:32 UTC | 52 | border-radius: var(--r-md); |
05a48e9e7942 | atagen | 2026-10-24 09:32 UTC | 53 | color: #fff; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 54 | font-weight: 700; |
05a48e9e7942 | atagen | 2026-10-24 09:32 UTC | 55 | letter-spacing: 0.02em; |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 56 | } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 57 | .mxc-fallback.circle { border-radius: 50%; } |
973f8fbdaf80 | atagen | 2026-09-28 09:10 UTC | 58 | </style> |