feat(hero): pick the best Jellyfin artwork for the home hero

Jellyfin stores several images per item. Ask /Items/{id}/Images for their real
sizes and use the biggest wide image (Backdrop, then Thumb) for the 16:9 hero.
Poster-only items are no longer stretched: the poster is blurred into an ambient
background with the sharp poster displayed beside the text. The slide element is
kept mounted across changes so the previous artwork stays until the next loads.
This commit is contained in:
1xDed committed 2026-11-27 09:20:26 +03:00
1 parent 3131c1f905
commit 4c9dd86962
4 files changed
+235 -33

No files matched your search

+2 -9
View File
@@ -1,4 +1,3 @@
import { motion } from "motion/react";
import React, { useCallback, useEffect, useState } from "react";
import type { Api } from "@jellyfin/sdk";
@@ -116,15 +115,9 @@ const Carousel = ({
onMouseEnter={() => setIsPaused(true)}
onMouseLeave={() => setIsPaused(false)}
>
<motion.div
key={content[currentSlide].Id}
className="hero-carousel-slide-wrapper"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 0.35, ease: "easeInOut" }}
>
<div className="hero-carousel-slide-wrapper">
<MemoizedCarouselSlide item={content[currentSlide]} />
</motion.div>
</div>
<div className="carousel-sidebar" ref={sidebarRef}>
{content.map((item, index) => (
<div
+41 -23
View File
@@ -8,9 +8,16 @@ import { green, red, yellow } from "@mui/material/colors";
import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography";
import { useNavigate } from "@tanstack/react-router";
import { useQuery } from "@tanstack/react-query";
import { motion, type Variants } from "motion/react";
import React from "react";
import { endsAt, getRuntime } from "@/utils/date/time";
import {
getHeroPosterUrl,
getItemImagesQueryOptions,
resolveHeroArtwork,
} from "@/utils/methods/heroArtwork";
import BlurhashCanvas from "../blurhash-canvas";
import { useApiInContext } from "@/utils/store/api";
import { useCarouselStore } from "@/utils/store/carousel";
@@ -25,10 +32,11 @@ const MotionTypography = motion.create(Typography);
const MotionStack = motion.create(Stack);
const textVariants: Variants = {
initial: (direction: string) => ({
x: direction === "right" ? 40 : -40,
opacity: 0,
}),
// No hidden start state: hero text must not blink on slide changes.
initial: {
x: 0,
opacity: 1,
},
animate: {
x: 0,
opacity: 1,
@@ -61,36 +69,38 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
const [animationDirection] = useCarouselStore((state) => [state.direction]);
// Hero background: a real backdrop when the item has one, otherwise fall back
// to the poster instead of a big type icon.
const heroBackgroundSrc = item.BackdropImageTags?.length
? item.ParentBackdropItemId
? `${api?.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop?quality=80`
: `${api?.basePath}/Items/${item.Id}/Images/Backdrop?quality=80&fillHeight=1400`
: item.ImageTags?.Primary
? `${api?.basePath}/Items/${item.Id}/Images/Primary?quality=80&fillHeight=1400`
: undefined;
// Jellyfin stores several images per item (poster, thumb, backdrops).
// Ask the server which ones exist and their real size, then pick the wide one.
const imageInfos = useQuery(getItemImagesQueryOptions(api, item.Id));
const heroArtwork = resolveHeroArtwork(api, item, imageInfos.data);
const heroPoster = heroArtwork?.isPortrait
? getHeroPosterUrl(api, item)
: undefined;
return (
<div className="hero-carousel-slide">
<motion.div
className="hero-carousel-background-container"
initial={{ opacity: 0 }}
initial={{ opacity: 1 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.4, ease: "easeInOut" }}
>
{heroBackgroundSrc ? (
{heroArtwork?.blurhash && (
<BlurhashCanvas
blurhashString={heroArtwork.blurhash}
width={48}
height={27}
canvasProps={{
className: "hero-carousel-background-blurhash",
}}
/>
)}
{heroArtwork ? (
<img
alt={item.Name ?? "item"}
className="hero-carousel-background-image"
src={heroBackgroundSrc}
style={{
opacity: 0,
}}
onLoad={(e) => {
e.currentTarget.style.opacity = "1";
}}
className={`hero-carousel-background-image${heroArtwork.isPortrait ? " is-poster" : ""}`}
src={heroArtwork.url}
loading="eager"
/>
) : (
@@ -98,6 +108,14 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
{getTypeIcon(item.Type ?? "Movie")}
</div>
)}
{heroPoster && (
<img
alt={item.Name ?? "poster"}
className="hero-carousel-poster"
src={heroPoster}
loading="eager"
/>
)}
</motion.div>
<motion.div
className="hero-carousel-detail"