1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/components/cardbuilder/cardImage.ts
scampower3 5d606021ed Backport pull request #5587 from jellyfin-web/release-10.9.z
Fix square posters

Original-merge: 9e34ae8b42

Merged-by: thornbill <thornbill@users.noreply.github.com>

Backported-by: Joshua M. Boniface <joshua@boniface.me>
2024-05-25 11:50:46 -04:00

74 lines
2.1 KiB
TypeScript

import type { BaseItemDto } from '@jellyfin/sdk/lib/generated-client/models/base-item-dto';
import { BaseItemKind } from '@jellyfin/sdk/lib/generated-client/models/base-item-kind';
import type { ApiClient } from 'jellyfin-apiclient';
import type { CardOptions } from 'types/cardOptions';
import { CardShape } from 'utils/card';
import { getCardImageUrl, getDefaultText } from './cardBuilder';
/**
* Builds an html string for a basic image only card.
*/
export function buildCardImage(
apiClient: ApiClient,
item: BaseItemDto,
options: CardOptions
): string {
let shape: CardShape = CardShape.Square;
if (item.PrimaryImageAspectRatio) {
if (item.PrimaryImageAspectRatio >= 3) {
shape = CardShape.Banner;
} else if (item.PrimaryImageAspectRatio >= 1.33) {
shape = CardShape.Backdrop;
} else if (item.PrimaryImageAspectRatio > 0.8) {
shape = CardShape.Square;
} else {
shape = CardShape.Portrait;
}
}
const image = getCardImageUrl(
item,
apiClient,
options,
shape
);
if (!image) return '';
const { blurhash, imgUrl } = image;
let cardPadderIcon = '';
// TV Channel logos are transparent so skip the placeholder to avoid overlapping
if (imgUrl && item.Type !== BaseItemKind.TvChannel) {
cardPadderIcon = getDefaultText(item, {
// Always use an icon
defaultCardImageIcon: 'folder',
...options
});
}
let blurhashAttrib = '';
if (blurhash && blurhash.length > 0) {
blurhashAttrib = `data-blurhash="${blurhash}"`;
}
return (
`<div class="card ${shape}Card">
<div class="cardBox">
<div class="cardScalable">
<div class="cardPadder cardPadder-${shape}">
${cardPadderIcon}
</div>
<div
class="cardImageContainer coveredImage cardContent lazy"
style="cursor: default;"
data-src="${imgUrl}"
${blurhashAttrib}
></div>
</div>
</div>
</div>`
);
}