mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-13 03:26:21 +01:00
More queueMicrotask
This commit is contained in:
parent
f645815b84
commit
7fb0044471
1 changed files with 25 additions and 22 deletions
|
@ -62,6 +62,7 @@ function Avatar({ url, size, alt = '', squircle, ...props }) {
|
||||||
if (avatarRef.current) avatarRef.current.dataset.loaded = true;
|
if (avatarRef.current) avatarRef.current.dataset.loaded = true;
|
||||||
if (alphaCache[url] !== undefined) return;
|
if (alphaCache[url] !== undefined) return;
|
||||||
if (isMissing) return;
|
if (isMissing) return;
|
||||||
|
queueMicrotask(() => {
|
||||||
try {
|
try {
|
||||||
// Check if image has alpha channel
|
// Check if image has alpha channel
|
||||||
const { width, height } = e.target;
|
const { width, height } = e.target;
|
||||||
|
@ -71,8 +72,9 @@ function Avatar({ url, size, alt = '', squircle, ...props }) {
|
||||||
const allPixels = ctx.getImageData(0, 0, width, height);
|
const allPixels = ctx.getImageData(0, 0, width, height);
|
||||||
// At least 10% of pixels have alpha <= 128
|
// At least 10% of pixels have alpha <= 128
|
||||||
const hasAlpha =
|
const hasAlpha =
|
||||||
allPixels.data.filter((pixel, i) => i % 4 === 3 && pixel <= 128)
|
allPixels.data.filter(
|
||||||
.length /
|
(pixel, i) => i % 4 === 3 && pixel <= 128,
|
||||||
|
).length /
|
||||||
(allPixels.data.length / 4) >
|
(allPixels.data.length / 4) >
|
||||||
0.1;
|
0.1;
|
||||||
if (hasAlpha) {
|
if (hasAlpha) {
|
||||||
|
@ -85,6 +87,7 @@ function Avatar({ url, size, alt = '', squircle, ...props }) {
|
||||||
// Silent fail
|
// Silent fail
|
||||||
alphaCache[url] = false;
|
alphaCache[url] = false;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
Loading…
Reference in a new issue