Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/components/MaintainerAvatarImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import type { ComponentProps } from 'react'
import { twMerge } from 'tailwind-merge'

type MaintainerAvatarImageProps = Pick<
ComponentProps<'img'>,
'className' | 'width' | 'height'
> & {
src: string
alt: string
defer?: boolean
}

function revealImage(image: HTMLImageElement) {
void image.decode().then(
() => {
image.dataset.loaded = ''
},
() => {
image.dataset.failed = ''
},
)
}

function checkCachedImage(image: HTMLImageElement | null) {
if (!image?.getAttribute('src') || !image.complete) return
if (image.naturalWidth) revealImage(image)
else image.dataset.failed = ''
}

export function MaintainerAvatarImage({
src,
alt,
defer = false,
className,
width,
height,
}: MaintainerAvatarImageProps) {
return (
<>
<img
key={src}
ref={checkCachedImage}
src={defer ? undefined : src}
data-globe-src={defer ? src : undefined}
alt={alt}
width={width}
height={height}
loading="lazy"
decoding="async"
onLoad={(event) => revealImage(event.currentTarget)}
onError={(event) => {
event.currentTarget.dataset.failed = ''
}}
className={twMerge(
'peer block size-full object-cover opacity-0 transition-opacity duration-300 data-[loaded]:opacity-100 motion-reduce:transition-none [@media(scripting:none)]:opacity-100',
className,
)}
/>
<span
aria-hidden="true"
className="pointer-events-none absolute inset-0 overflow-hidden bg-ds-neutral-tint-200 transition-opacity duration-300 peer-data-[loaded]:opacity-0 motion-reduce:transition-none dark:bg-ds-neutral-tint-500 before:absolute before:inset-y-0 before:left-0 before:w-1/2 before:bg-linear-to-r before:from-transparent before:via-ds-neutral-0/40 before:to-transparent before:[transform:translateX(-100%)] dark:before:via-ds-neutral-0/20 motion-safe:peer-[[src]:not([data-loaded],[data-failed])]:before:animate-shimmer [@media(scripting:none)]:hidden"
/>
</>
)
}
20 changes: 7 additions & 13 deletions src/components/MaintainerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { useState } from 'react'
import { Link } from '@tanstack/react-router'
import { twMerge } from 'tailwind-merge'
import { MaintainerAvatarImage } from './MaintainerAvatarImage'

function RoleBadge({
maintainer,
Expand Down Expand Up @@ -265,12 +266,10 @@ export function CompactMaintainerCard({
className="group relative aspect-square block rounded-lg corner-squircle shadow-xs border border-gray-200 dark:border-gray-800 overflow-hidden"
tabIndex={0}
>
<img
<MaintainerAvatarImage
alt={`Avatar of ${maintainer.name}`}
className="absolute inset-0 w-full h-full object-cover"
className="absolute inset-0"
src={maintainer.avatar}
loading="lazy"
decoding="async"
/>
<div className="absolute inset-0 bg-linear-to-t from-black/70 via-black/20 to-transparent" />
<div className="absolute inset-0 p-3 flex flex-col justify-end">
Expand Down Expand Up @@ -308,12 +307,10 @@ export function MaintainerRowCard({
tabIndex={0}
>
<div className="relative w-16 h-16 rounded-lg corner-squircle overflow-hidden">
<img
<MaintainerAvatarImage
alt={`Avatar of ${maintainer.name}`}
className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500"
className="transition-[opacity,scale] duration-500 group-hover:scale-110"
src={maintainer.avatar}
loading="lazy"
decoding="async"
/>
<div className="absolute inset-0 bg-linear-to-t from-black/40 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-300" />
</div>
Expand Down Expand Up @@ -403,15 +400,12 @@ export function MaintainerCard({ maintainer }: MaintainerCardProps) {
target="_blank"
rel="noopener noreferrer"
aria-label={`View ${maintainer.name}'s GitHub profile`}
className="block aspect-square w-full overflow-hidden rounded-[17px] corner-squircle bg-[#d9d9d9] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-focus sm:rounded-[22px]"
className="relative block aspect-square w-full overflow-hidden rounded-[17px] corner-squircle focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-focus sm:rounded-[22px]"
tabIndex={0}
>
<img
<MaintainerAvatarImage
alt={`Avatar of ${maintainer.name}`}
className="h-full w-full object-cover"
src={maintainer.avatar}
loading="lazy"
decoding="async"
/>
</a>
<div className="flex w-full flex-col items-start gap-2 pb-[18px] pt-4 sm:pb-[27px] sm:pt-5">
Expand Down
37 changes: 12 additions & 25 deletions src/components/MaintainersMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { Maintainer } from '~/libraries/maintainers'
import type { LibraryId } from '~/libraries/types'
import { categoryOf } from '~/libraries/categories'
import { Tooltip } from '~/ui/Tooltip'
import { MaintainerAvatarImage } from './MaintainerAvatarImage'
import { createChartsGlobe, globeHaloScale } from './maintainersChartsGlobe'
import { initialMaintainersView, initialView } from './maintainersGlobeView'

Expand Down Expand Up @@ -672,27 +673,12 @@ function GlobeAvatar({
className={`relative block shrink-0 overflow-hidden rounded-full ${compact ? 'size-3 border' : 'size-5 border-2 sm:size-8'}`}
style={{ borderColor: color }}
>
<img
data-globe-src={member.avatar}
<MaintainerAvatarImage
src={member.avatar}
alt={compact ? '' : member.name}
width={compact ? 12 : 28}
height={compact ? 12 : 28}
loading="lazy"
decoding="async"
onLoad={(event) => {
const image = event.currentTarget
void image.decode().then(
() => {
image.dataset.loaded = ''
},
() => {},
)
}}
className="peer block size-full object-cover opacity-0 transition-opacity duration-300 data-[loaded]:opacity-100 motion-reduce:transition-none"
/>
<span
aria-hidden="true"
className="pointer-events-none absolute inset-0 bg-background-subtle transition-opacity duration-300 peer-data-[loaded]:opacity-0 motion-reduce:transition-none"
defer
/>
</span>
)
Expand Down Expand Up @@ -1602,13 +1588,14 @@ export function MaintainersMap({
rel="noreferrer"
className="flex min-w-0 items-center gap-3 rounded-lg p-2 hover:bg-surface-state-hover"
>
<img
src={member.avatar}
alt=""
width={36}
height={36}
className="size-9 shrink-0 rounded-full"
/>
<span className="relative block size-9 shrink-0 overflow-hidden rounded-full">
<MaintainerAvatarImage
src={member.avatar}
alt=""
width={36}
height={36}
/>
</span>
<div className="min-w-0">
<div className="text-sm font-semibold">{member.name}</div>
<div className="text-xs text-text-muted">
Expand Down
Loading