From cd6c14c1d9b064bd74d47696becddcb7e85a3853 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Mon, 13 Mar 2023 10:10:21 +0800 Subject: [PATCH] Embrace non-circle avatars --- src/components/account-info.css | 8 +++++--- src/components/account-info.jsx | 14 +++++++++++++- src/components/avatar.css | 6 ++++++ src/components/avatar.jsx | 15 ++++++++++++++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/components/account-info.css b/src/components/account-info.css index 40afca88..c8222709 100644 --- a/src/components/account-info.css +++ b/src/components/account-info.css @@ -58,8 +58,10 @@ 8px 0 24px var(--header-color-4, --bg-color); } .account-container header .avatar { - box-shadow: -8px 0 24px var(--header-color-3, --bg-color), - 8px 0 24px var(--header-color-4, --bg-color); + /* box-shadow: -8px 0 24px var(--header-color-3, --bg-color), + 8px 0 24px var(--header-color-4, --bg-color); */ + filter: drop-shadow(-8px 0 24px var(--header-color-3, --bg-color)) + drop-shadow(8px 0 24px var(--header-color-4, --bg-color)); } .account-container .note { @@ -222,7 +224,7 @@ font-size: 175%; margin-bottom: -8px; line-height: 1.1; - letter-spacing: -1px; + letter-spacing: -0.5px; mix-blend-mode: multiply; gap: 12px; } diff --git a/src/components/account-info.jsx b/src/components/account-info.jsx index 82002287..4cabd657 100644 --- a/src/components/account-info.jsx +++ b/src/components/account-info.jsx @@ -164,7 +164,8 @@ function AccountInfo({ ).data, ]; const rgbColors = colors.map((color) => { - return `rgb(${color[0]}, ${color[1]}, ${color[2]}, 0.3)`; + const [r, g, b, a] = lightenRGB(color); + return `rgba(${r}, ${g}, ${b}, ${a})`; }); setHeaderCornerColors(rgbColors); console.log({ colors, rgbColors }); @@ -482,4 +483,15 @@ function RelatedActions({ info, instance, authenticated }) { ); } +// Apply more alpha if high luminence +function lightenRGB([r, g, b]) { + const luminence = 0.2126 * r + 0.7152 * g + 0.0722 * b; + console.log('luminence', luminence); + // Follow this range + // luminence = 0, alpha = 0.05 + // luminence = 220, alpha = 1 + const alpha = Math.min(1, (luminence / 220) * 0.95 + 0.05); + return [r, g, b, alpha]; +} + export default AccountInfo; diff --git a/src/components/avatar.css b/src/components/avatar.css index 411407a6..3066d643 100644 --- a/src/components/avatar.css +++ b/src/components/avatar.css @@ -16,3 +16,9 @@ object-fit: cover; background-color: var(--img-bg-color); } + +.avatar.loaded, +.avatar.loaded img { + box-shadow: none; + background-color: transparent; +} diff --git a/src/components/avatar.jsx b/src/components/avatar.jsx index 1ceb7fe4..7af25995 100644 --- a/src/components/avatar.jsx +++ b/src/components/avatar.jsx @@ -1,5 +1,7 @@ import './avatar.css'; +import { useRef } from 'preact/hooks'; + const SIZES = { s: 16, m: 20, @@ -11,8 +13,10 @@ const SIZES = { function Avatar({ url, size, alt = '', ...props }) { size = SIZES[size] || size || SIZES.m; + const avatarRef = useRef(); return ( {!!url && ( - {alt} + {alt} { + avatarRef.current.classList.add('loaded'); + }} + /> )} );