mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-22 17:25:40 +03:00
More fixes and adjustments for the avatars
This commit is contained in:
parent
e4eafd2592
commit
348ceedced
4 changed files with 55 additions and 13 deletions
|
@ -62,20 +62,24 @@
|
||||||
text-shadow: -8px 0 12px -6px var(--bg-color), 8px 0 12px -6px var(--bg-color),
|
text-shadow: -8px 0 12px -6px var(--bg-color), 8px 0 12px -6px var(--bg-color),
|
||||||
-8px 0 24px var(--header-color-3, --bg-color),
|
-8px 0 24px var(--header-color-3, --bg-color),
|
||||||
8px 0 24px var(--header-color-4, --bg-color);
|
8px 0 24px var(--header-color-4, --bg-color);
|
||||||
animation: fade-in 0.5s both ease-in-out 0.1s;
|
animation: fade-in 0.3s both ease-in-out 0.1s;
|
||||||
}
|
}
|
||||||
.account-container header .avatar {
|
.account-container header .avatar {
|
||||||
/* box-shadow: -8px 0 24px var(--header-color-3, --bg-color),
|
/* box-shadow: -8px 0 24px var(--header-color-3, --bg-color),
|
||||||
8px 0 24px var(--header-color-4, --bg-color); */
|
8px 0 24px var(--header-color-4, --bg-color); */
|
||||||
filter: drop-shadow(-8px 0 24px var(--header-color-3, --bg-color))
|
overflow: initial;
|
||||||
drop-shadow(8px 0 24px var(--header-color-4, --bg-color));
|
filter: drop-shadow(-2px 0 4px var(--header-color-3, --bg-color))
|
||||||
|
drop-shadow(2px 0 4px var(--header-color-4, --bg-color));
|
||||||
|
}
|
||||||
|
.account-container header .avatar:not(.has-alpha) img {
|
||||||
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.account-container main > *:first-child {
|
.account-container main > *:first-child {
|
||||||
animation: fade-in 0.5s both ease-in-out 0.2s;
|
animation: fade-in 0.3s both ease-in-out 0.15s;
|
||||||
}
|
}
|
||||||
.account-container main > *:first-child ~ * {
|
.account-container main > *:first-child ~ * {
|
||||||
animation: fade-in 0.5s both ease-in-out 0.3s;
|
animation: fade-in 0.3s both ease-in-out 0.2s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.account-container .note {
|
.account-container .note {
|
||||||
|
@ -165,10 +169,14 @@
|
||||||
}
|
}
|
||||||
.timeline-start .account-container header {
|
.timeline-start .account-container header {
|
||||||
padding: 16px 16px 1px;
|
padding: 16px 16px 1px;
|
||||||
|
animation: none;
|
||||||
}
|
}
|
||||||
.timeline-start .account-container main {
|
.timeline-start .account-container main {
|
||||||
padding: 1px 16px 1px;
|
padding: 1px 16px 1px;
|
||||||
}
|
}
|
||||||
|
.timeline-start .account-container main > * {
|
||||||
|
animation: none;
|
||||||
|
}
|
||||||
.timeline-start .account-container .account-block .account-block-acct {
|
.timeline-start .account-container .account-block .account-block-acct {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
@ -245,5 +253,7 @@
|
||||||
.timeline-start .account-container header .account-block .avatar {
|
.timeline-start .account-container header .account-block .avatar {
|
||||||
width: 112px !important;
|
width: 112px !important;
|
||||||
height: 112px !important;
|
height: 112px !important;
|
||||||
|
filter: drop-shadow(-8px 0 8px var(--header-color-3, --bg-color))
|
||||||
|
drop-shadow(8px 0 8px var(--header-color-4, --bg-color));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -529,14 +529,13 @@ function RelatedActions({ info, instance, authenticated }) {
|
||||||
function lightenRGB([r, g, b]) {
|
function lightenRGB([r, g, b]) {
|
||||||
const luminence = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
const luminence = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||||
console.log('luminence', luminence);
|
console.log('luminence', luminence);
|
||||||
// Follow this range
|
|
||||||
// luminence = 0, alpha = 0.01
|
|
||||||
// luminence = 220, alpha = 1
|
|
||||||
let alpha;
|
let alpha;
|
||||||
if (luminence >= 220) {
|
if (luminence >= 220) {
|
||||||
alpha = 1;
|
alpha = 1;
|
||||||
|
} else if (luminence <= 50) {
|
||||||
|
alpha = 0.1;
|
||||||
} else {
|
} else {
|
||||||
alpha = (luminence / 255) * 0.99 + 0.01;
|
alpha = luminence / 255;
|
||||||
}
|
}
|
||||||
alpha = Math.min(1, alpha);
|
alpha = Math.min(1, alpha);
|
||||||
return [r, g, b, alpha];
|
return [r, g, b, alpha];
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
.avatar.has-alpha {
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.avatar img {
|
.avatar img {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
@ -17,8 +20,8 @@
|
||||||
background-color: var(--img-bg-color);
|
background-color: var(--img-bg-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.avatar.loaded,
|
.avatar[data-loaded],
|
||||||
.avatar.loaded img {
|
.avatar[data-loaded] img {
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,15 @@ const SIZES = {
|
||||||
xxxl: 64,
|
xxxl: 64,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const alphaCache = {};
|
||||||
|
|
||||||
function Avatar({ url, size, alt = '', ...props }) {
|
function Avatar({ url, size, alt = '', ...props }) {
|
||||||
size = SIZES[size] || size || SIZES.m;
|
size = SIZES[size] || size || SIZES.m;
|
||||||
const avatarRef = useRef();
|
const avatarRef = useRef();
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
ref={avatarRef}
|
ref={avatarRef}
|
||||||
class="avatar"
|
class={`avatar ${alphaCache[url] ? 'has-alpha' : ''}`}
|
||||||
style={{
|
style={{
|
||||||
width: size,
|
width: size,
|
||||||
height: size,
|
height: size,
|
||||||
|
@ -32,8 +34,36 @@ function Avatar({ url, size, alt = '', ...props }) {
|
||||||
height={size}
|
height={size}
|
||||||
alt={alt}
|
alt={alt}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
|
crossOrigin={alphaCache[url] === undefined ? 'anonymous' : undefined}
|
||||||
|
onError={(e) => {
|
||||||
|
e.target.crossOrigin = null;
|
||||||
|
e.target.src = url;
|
||||||
|
}}
|
||||||
onLoad={(e) => {
|
onLoad={(e) => {
|
||||||
avatarRef.current.classList.add('loaded');
|
avatarRef.current.dataset.loaded = true;
|
||||||
|
try {
|
||||||
|
// Check if image has alpha channel
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
canvas.width = e.target.width;
|
||||||
|
canvas.height = e.target.height;
|
||||||
|
ctx.drawImage(e.target, 0, 0);
|
||||||
|
const allPixels = ctx.getImageData(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
canvas.width,
|
||||||
|
canvas.height,
|
||||||
|
);
|
||||||
|
const hasAlpha = allPixels.data.some((pixel, i) => {
|
||||||
|
return i % 4 === 3 && pixel !== 255;
|
||||||
|
});
|
||||||
|
if (hasAlpha) {
|
||||||
|
avatarRef.current.classList.add('has-alpha');
|
||||||
|
alphaCache[url] = true;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
Loading…
Reference in a new issue