Handle tiny images & fix layout

Honestly there's just too many possibilities
This commit is contained in:
Lim Chee Aun 2024-06-11 14:46:29 +08:00
parent 17a3939061
commit c0c7fdd6e1
2 changed files with 37 additions and 19 deletions

View file

@ -362,21 +362,29 @@ function Media({
naturalWidth && naturalWidth &&
naturalHeight naturalHeight
) { ) {
const naturalAspectRatio = ( const minDimension = 88;
naturalWidth / naturalHeight
).toFixed(2);
const displayAspectRatio = (
clientWidth / clientHeight
).toFixed(2);
const similarThreshold = 0.05;
if ( if (
naturalAspectRatio === displayAspectRatio || naturalWidth < minDimension ||
Math.abs(naturalAspectRatio - displayAspectRatio) < naturalHeight < minDimension
similarThreshold
) { ) {
$media.dataset.hasNaturalAspectRatio = true; $media.dataset.hasSmallDimension = true;
} else {
const naturalAspectRatio = (
naturalWidth / naturalHeight
).toFixed(2);
const displayAspectRatio = (
clientWidth / clientHeight
).toFixed(2);
const similarThreshold = 0.05;
if (
naturalAspectRatio === displayAspectRatio ||
Math.abs(naturalAspectRatio - displayAspectRatio) <
similarThreshold
) {
$media.dataset.hasNaturalAspectRatio = true;
}
// $media.dataset.aspectRatios = `${naturalAspectRatio} ${displayAspectRatio}`;
} }
// $media.dataset.aspectRatios = `${naturalAspectRatio} ${displayAspectRatio}`;
} }
} }
}} }}

View file

@ -1074,6 +1074,11 @@
&[data-has-natural-aspect-ratio] { &[data-has-natural-aspect-ratio] {
--media-radius: 4px; --media-radius: 4px;
} }
&[data-has-small-dimension] img {
object-fit: contain;
image-rendering: pixelated;
}
} }
.status .media-container.media-eq1 .media[data-orientation='portrait'] { .status .media-container.media-eq1 .media[data-orientation='portrait'] {
/* width: auto; /* width: auto;
@ -1349,22 +1354,27 @@ body:has(#modal-container .carousel) .status .media img:hover {
background-color: var(--outline-color); background-color: var(--outline-color);
} }
.status.large .media-large-container { .status .media-large-container {
width: 100%; width: 100%;
max-width: 100%; max-width: 100%;
display: inline-flex; display: inline-flex;
flex-direction: column; flex-direction: row;
align-items: center; /* align-items: center;
justify-content: center; justify-content: center; */
column-gap: 8px; column-gap: 8px;
flex-wrap: wrap; flex-wrap: wrap;
text-align: center;
.media[data-has-small-dimension] {
width: auto !important;
}
figure { figure {
justify-content: center; flex-direction: column;
figcaption { figcaption {
text-align: center; flex-grow: 0 !important;
flex-basis: auto !important;
align-self: flex-start !important;
} }
} }
} }