Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b00f93d262 | ||
|
|
4c9dd86962 |
No files matched your search
@@ -5,15 +5,20 @@ import { useBackdropStore } from "@/utils/store/backdrop";
|
|||||||
import BlurhashCanvas from "../blurhash-canvas";
|
import BlurhashCanvas from "../blurhash-canvas";
|
||||||
|
|
||||||
export default function Backdrop() {
|
export default function Backdrop() {
|
||||||
// const [backdropLoading, setBackdropLoading] = useState(true);
|
|
||||||
|
|
||||||
const { backdropHash } = useBackdropStore(
|
const { backdropHash } = useBackdropStore(
|
||||||
useShallow((state) => ({
|
useShallow((state) => ({
|
||||||
backdropHash: state.backdropHash,
|
backdropHash: state.backdropHash,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!backdropHash) {
|
// Routes clear the backdrop when they mount ("") and some set it later.
|
||||||
|
// Keep the last non-empty hash so the app background never blanks out
|
||||||
|
// (which looked like a flash on every page open).
|
||||||
|
const lastHash = React.useRef<string | undefined>(undefined);
|
||||||
|
if (backdropHash) lastHash.current = backdropHash;
|
||||||
|
const hash = backdropHash || lastHash.current;
|
||||||
|
|
||||||
|
if (!hash) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,16 +27,16 @@ export default function Backdrop() {
|
|||||||
<motion.div
|
<motion.div
|
||||||
initial={{ opacity: 0 }}
|
initial={{ opacity: 0 }}
|
||||||
animate={{ opacity: 1 }}
|
animate={{ opacity: 1 }}
|
||||||
key={backdropHash}
|
key={hash}
|
||||||
exit={{ opacity: 0 }}
|
exit={{ opacity: 0 }}
|
||||||
transition={{
|
transition={{
|
||||||
duration: 2,
|
duration: 0.45,
|
||||||
ease: "easeInOut",
|
ease: "easeInOut",
|
||||||
}}
|
}}
|
||||||
className="app-backdrop-container"
|
className="app-backdrop-container"
|
||||||
>
|
>
|
||||||
<BlurhashCanvas
|
<BlurhashCanvas
|
||||||
blurhashString={backdropHash}
|
blurhashString={hash}
|
||||||
width={300}
|
width={300}
|
||||||
height={150}
|
height={150}
|
||||||
canvasProps={{
|
canvasProps={{
|
||||||
@@ -47,4 +52,4 @@ export default function Backdrop() {
|
|||||||
</motion.div>
|
</motion.div>
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
transition: all $transition-time-fast;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ const CardContent = ({
|
|||||||
? getTypeIcon(overrideIcon)
|
? getTypeIcon(overrideIcon)
|
||||||
: getTypeIcon(item.Type ?? "universal")}
|
: getTypeIcon(item.Type ?? "universal")}
|
||||||
</div>
|
</div>
|
||||||
{inView && image && (
|
{image && (
|
||||||
<img
|
<img
|
||||||
alt={item.Name ?? "blink"}
|
alt={item.Name ?? "blink"}
|
||||||
src={
|
src={
|
||||||
@@ -128,14 +128,9 @@ const CardContent = ({
|
|||||||
style={{
|
style={{
|
||||||
height: "100%",
|
height: "100%",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
opacity: 0,
|
|
||||||
display: "block",
|
display: "block",
|
||||||
transition: "opacity 0.3s ease-in-out",
|
|
||||||
}}
|
}}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
onLoad={(e) => {
|
|
||||||
e.currentTarget.style.opacity = "1";
|
|
||||||
}}
|
|
||||||
className="card-image"
|
className="card-image"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { motion } from "motion/react";
|
|
||||||
import React, { useCallback, useEffect, useState } from "react";
|
import React, { useCallback, useEffect, useState } from "react";
|
||||||
import type { Api } from "@jellyfin/sdk";
|
import type { Api } from "@jellyfin/sdk";
|
||||||
|
|
||||||
@@ -116,15 +115,9 @@ const Carousel = ({
|
|||||||
onMouseEnter={() => setIsPaused(true)}
|
onMouseEnter={() => setIsPaused(true)}
|
||||||
onMouseLeave={() => setIsPaused(false)}
|
onMouseLeave={() => setIsPaused(false)}
|
||||||
>
|
>
|
||||||
<motion.div
|
<div className="hero-carousel-slide-wrapper">
|
||||||
key={content[currentSlide].Id}
|
|
||||||
className="hero-carousel-slide-wrapper"
|
|
||||||
initial={{ opacity: 0 }}
|
|
||||||
animate={{ opacity: 1 }}
|
|
||||||
transition={{ duration: 0.35, ease: "easeInOut" }}
|
|
||||||
>
|
|
||||||
<MemoizedCarouselSlide item={content[currentSlide]} />
|
<MemoizedCarouselSlide item={content[currentSlide]} />
|
||||||
</motion.div>
|
</div>
|
||||||
<div className="carousel-sidebar" ref={sidebarRef}>
|
<div className="carousel-sidebar" ref={sidebarRef}>
|
||||||
{content.map((item, index) => (
|
{content.map((item, index) => (
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -8,9 +8,16 @@ import { green, red, yellow } from "@mui/material/colors";
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import { useNavigate } from "@tanstack/react-router";
|
import { useNavigate } from "@tanstack/react-router";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { motion, type Variants } from "motion/react";
|
import { motion, type Variants } from "motion/react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { endsAt, getRuntime } from "@/utils/date/time";
|
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 { useApiInContext } from "@/utils/store/api";
|
||||||
import { useCarouselStore } from "@/utils/store/carousel";
|
import { useCarouselStore } from "@/utils/store/carousel";
|
||||||
@@ -25,10 +32,11 @@ const MotionTypography = motion.create(Typography);
|
|||||||
const MotionStack = motion.create(Stack);
|
const MotionStack = motion.create(Stack);
|
||||||
|
|
||||||
const textVariants: Variants = {
|
const textVariants: Variants = {
|
||||||
initial: (direction: string) => ({
|
// No hidden start state: hero text must not blink on slide changes.
|
||||||
x: direction === "right" ? 40 : -40,
|
initial: {
|
||||||
opacity: 0,
|
x: 0,
|
||||||
}),
|
opacity: 1,
|
||||||
|
},
|
||||||
animate: {
|
animate: {
|
||||||
x: 0,
|
x: 0,
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
@@ -61,36 +69,38 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
|||||||
|
|
||||||
const [animationDirection] = useCarouselStore((state) => [state.direction]);
|
const [animationDirection] = useCarouselStore((state) => [state.direction]);
|
||||||
|
|
||||||
// Hero background: a real backdrop when the item has one, otherwise fall back
|
// Jellyfin stores several images per item (poster, thumb, backdrops).
|
||||||
// to the poster instead of a big type icon.
|
// Ask the server which ones exist and their real size, then pick the wide one.
|
||||||
const heroBackgroundSrc = item.BackdropImageTags?.length
|
const imageInfos = useQuery(getItemImagesQueryOptions(api, item.Id));
|
||||||
? item.ParentBackdropItemId
|
const heroArtwork = resolveHeroArtwork(api, item, imageInfos.data);
|
||||||
? `${api?.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop?quality=80`
|
const heroPoster = heroArtwork?.isPortrait
|
||||||
: `${api?.basePath}/Items/${item.Id}/Images/Backdrop?quality=80&fillHeight=1400`
|
? getHeroPosterUrl(api, item)
|
||||||
: item.ImageTags?.Primary
|
: undefined;
|
||||||
? `${api?.basePath}/Items/${item.Id}/Images/Primary?quality=80&fillHeight=1400`
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="hero-carousel-slide">
|
<div className="hero-carousel-slide">
|
||||||
<motion.div
|
<motion.div
|
||||||
className="hero-carousel-background-container"
|
className="hero-carousel-background-container"
|
||||||
initial={{ opacity: 0 }}
|
initial={{ opacity: 1 }}
|
||||||
animate={{ opacity: 1 }}
|
animate={{ opacity: 1 }}
|
||||||
exit={{ opacity: 0 }}
|
exit={{ opacity: 0 }}
|
||||||
transition={{ duration: 0.4, ease: "easeInOut" }}
|
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
|
<img
|
||||||
alt={item.Name ?? "item"}
|
alt={item.Name ?? "item"}
|
||||||
className="hero-carousel-background-image"
|
className={`hero-carousel-background-image${heroArtwork.isPortrait ? " is-poster" : ""}`}
|
||||||
src={heroBackgroundSrc}
|
src={heroArtwork.url}
|
||||||
style={{
|
|
||||||
opacity: 0,
|
|
||||||
}}
|
|
||||||
onLoad={(e) => {
|
|
||||||
e.currentTarget.style.opacity = "1";
|
|
||||||
}}
|
|
||||||
loading="eager"
|
loading="eager"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -98,6 +108,14 @@ const CarouselSlide = ({ item }: { item: BaseItemDto }) => {
|
|||||||
{getTypeIcon(item.Type ?? "Movie")}
|
{getTypeIcon(item.Type ?? "Movie")}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{heroPoster && (
|
||||||
|
<img
|
||||||
|
alt={item.Name ?? "poster"}
|
||||||
|
className="hero-carousel-poster"
|
||||||
|
src={heroPoster}
|
||||||
|
loading="eager"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</motion.div>
|
</motion.div>
|
||||||
<motion.div
|
<motion.div
|
||||||
className="hero-carousel-detail"
|
className="hero-carousel-detail"
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ interface ItemBackdropProps {
|
|||||||
const MotionImg = motion.img;
|
const MotionImg = motion.img;
|
||||||
|
|
||||||
const animationProps = {
|
const animationProps = {
|
||||||
initial: { opacity: 0 },
|
// Do not fade in from black on every navigation: cached artwork should be
|
||||||
|
// visible immediately (a fade here reads as a flash).
|
||||||
|
initial: { opacity: 1 },
|
||||||
animate: { opacity: 1 },
|
animate: { opacity: 1 },
|
||||||
exit: { opacity: 0 },
|
exit: { opacity: 0 },
|
||||||
transition: { duration: 0.5 },
|
transition: { duration: 0.3 },
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,6 +115,9 @@ export function ItemBackdrop({
|
|||||||
alt={alt}
|
alt={alt}
|
||||||
src={src}
|
src={src}
|
||||||
className={className ?? "item-hero-backdrop"}
|
className={className ?? "item-hero-backdrop"}
|
||||||
|
ref={(el) => {
|
||||||
|
if (el?.complete && el.naturalWidth > 0) el.style.opacity = "1";
|
||||||
|
}}
|
||||||
onLoad={(e) => {
|
onLoad={(e) => {
|
||||||
e.currentTarget.style.opacity = "1";
|
e.currentTarget.style.opacity = "1";
|
||||||
onLoad?.(e);
|
onLoad?.(e);
|
||||||
|
|||||||
@@ -101,8 +101,6 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
opacity: 0;
|
|
||||||
transition: opacity $transition-time-default;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
|||||||
@@ -77,9 +77,6 @@ const ItemHeader = ({
|
|||||||
tag: logoTag,
|
tag: logoTag,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
onLoad={(e) => {
|
|
||||||
e.currentTarget.style.opacity = "1";
|
|
||||||
}}
|
|
||||||
className="item-hero-logo"
|
className="item-hero-logo"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -143,9 +140,6 @@ const ItemHeader = ({
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onLoad={(e) => {
|
|
||||||
e.currentTarget.style.opacity = "1";
|
|
||||||
}}
|
|
||||||
className="item-hero-image"
|
className="item-hero-image"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -12,10 +12,8 @@ $cardWidth: 18%;
|
|||||||
grid-template-columns: $cardWidth 1fr;
|
grid-template-columns: $cardWidth 1fr;
|
||||||
grid-template-rows: 1fr auto;
|
grid-template-rows: 1fr auto;
|
||||||
&-image {
|
&-image {
|
||||||
opacity: 0;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
transition: opacity $transition-time-default;
|
|
||||||
&-container {
|
&-container {
|
||||||
height: fit-content;
|
height: fit-content;
|
||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
@@ -47,8 +45,6 @@ $cardWidth: 18%;
|
|||||||
&-logo {
|
&-logo {
|
||||||
max-width: 34rem;
|
max-width: 34rem;
|
||||||
max-height: 10rem;
|
max-height: 10rem;
|
||||||
opacity: 0;
|
|
||||||
transition: opacity $transition-time-default;
|
|
||||||
object-position: bottom;
|
object-position: bottom;
|
||||||
margin-bottom: 2em;
|
margin-bottom: 2em;
|
||||||
}
|
}
|
||||||
@@ -74,11 +70,9 @@ $cardWidth: 18%;
|
|||||||
height: 100vh;
|
height: 100vh;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
object-position: top;
|
object-position: top;
|
||||||
opacity: 0;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
transition: opacity $transition-time-default;
|
|
||||||
&-container {
|
&-container {
|
||||||
filter: brightness(0.8);
|
filter: brightness(0.8);
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
import { CircularProgress } from "@mui/material";
|
import { CircularProgress } from "@mui/material";
|
||||||
import { useRouterState } from "@tanstack/react-router";
|
import { useRouterState } from "@tanstack/react-router";
|
||||||
import React from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
/** Only show the full-screen loader for genuinely slow navigations. */
|
||||||
|
const SHOW_DELAY_MS = 250;
|
||||||
|
|
||||||
export default function RouterLoading() {
|
export default function RouterLoading() {
|
||||||
const routeLoading = useRouterState().isLoading;
|
const routeLoading = useRouterState().isLoading;
|
||||||
if (!routeLoading) return null;
|
const [visible, setVisible] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!routeLoading) {
|
||||||
|
setVisible(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const timer = setTimeout(() => setVisible(true), SHOW_DELAY_MS);
|
||||||
|
return () => clearTimeout(timer);
|
||||||
|
}, [routeLoading]);
|
||||||
|
|
||||||
|
if (!visible) return null;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@@ -21,4 +35,4 @@ export default function RouterLoading() {
|
|||||||
<CircularProgress size={72} thickness={2} />
|
<CircularProgress size={72} thickness={2} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
+1
-1
@@ -43,7 +43,7 @@ const router = createRouter({
|
|||||||
},
|
},
|
||||||
defaultPreload: false,
|
defaultPreload: false,
|
||||||
defaultPreloadStaleTime: 0,
|
defaultPreloadStaleTime: 0,
|
||||||
defaultViewTransition: true,
|
defaultViewTransition: false,
|
||||||
scrollRestoration: true,
|
scrollRestoration: true,
|
||||||
scrollRestorationBehavior: "auto",
|
scrollRestorationBehavior: "auto",
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -57,7 +57,22 @@
|
|||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
transition: opacity 0.5s;
|
|
||||||
|
// Poster-only item: never stretch/crop a 2:3 poster across 16:9.
|
||||||
|
// Blur it into an ambient background and show the sharp poster on top.
|
||||||
|
&.is-poster {
|
||||||
|
filter: blur(36px) saturate(1.6) brightness(0.65);
|
||||||
|
transform: scale(1.25);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-blurhash {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
width: 100% !important;
|
||||||
|
height: 100% !important;
|
||||||
|
z-index: 0;
|
||||||
|
filter: blur(30px) saturate(1.4);
|
||||||
}
|
}
|
||||||
|
|
||||||
&-icon-container {
|
&-icon-container {
|
||||||
@@ -101,6 +116,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&-poster {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 3;
|
||||||
|
right: 7%;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
height: 66%;
|
||||||
|
max-width: 26%;
|
||||||
|
object-fit: contain;
|
||||||
|
border-radius: 14px;
|
||||||
|
box-shadow: 0 24px 60px rgb(0 0 0 / 0.65), 0 0 0 1px rgb(255 255 255 / 0.08);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
&-overview {
|
&-overview {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
margin-bottom: 0.5em;
|
margin-bottom: 0.5em;
|
||||||
@@ -152,6 +181,10 @@
|
|||||||
min-height: 430px;
|
min-height: 430px;
|
||||||
}
|
}
|
||||||
.hero-carousel {
|
.hero-carousel {
|
||||||
|
&-poster {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
&-detail {
|
&-detail {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 3rem;
|
padding: 3rem;
|
||||||
|
|||||||
@@ -142,19 +142,20 @@ function HomeContent({ api, user }: { api: Api; user: UserDto }) {
|
|||||||
|
|
||||||
const setBackdropForItem = useCallback(
|
const setBackdropForItem = useCallback(
|
||||||
(item: BaseItemDto) => {
|
(item: BaseItemDto) => {
|
||||||
if (item?.ParentBackdropImageTags) {
|
// Use the wide artwork when present, otherwise the poster's BlurHash as
|
||||||
setBackdrop(
|
// an ambient background (poster-only items would otherwise leave it dark).
|
||||||
item.ImageBlurHashes?.Backdrop?.[item.ParentBackdropImageTags[0]],
|
const backdropTag =
|
||||||
);
|
item.ParentBackdropImageTags?.[0] ?? item.BackdropImageTags?.[0];
|
||||||
} else {
|
if (backdropTag) {
|
||||||
if (!item?.BackdropImageTags) {
|
setBackdrop(item.ImageBlurHashes?.Backdrop?.[backdropTag] ?? undefined);
|
||||||
setBackdrop(undefined);
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
setBackdrop(
|
|
||||||
item.ImageBlurHashes?.Backdrop?.[item.BackdropImageTags[0]],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
const primaryTag = item.ImageTags?.Primary;
|
||||||
|
setBackdrop(
|
||||||
|
primaryTag
|
||||||
|
? (item.ImageBlurHashes?.Primary?.[primaryTag] ?? undefined)
|
||||||
|
: undefined,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
[setBackdrop],
|
[setBackdrop],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,158 @@
|
|||||||
|
import type { Api } from "@jellyfin/sdk";
|
||||||
|
import type {
|
||||||
|
BaseItemDto,
|
||||||
|
ImageInfo,
|
||||||
|
ImageType,
|
||||||
|
} from "@jellyfin/sdk/lib/generated-client";
|
||||||
|
import { getImageApi } from "@jellyfin/sdk/lib/utils/api/image-api";
|
||||||
|
import { queryOptions } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
export type HeroArtwork = {
|
||||||
|
url: string;
|
||||||
|
/** Primary (poster) is portrait; it must not be cropped into a 16:9 hero. */
|
||||||
|
isPortrait: boolean;
|
||||||
|
/** BlurHash for the chosen image, used as an instant placeholder. */
|
||||||
|
blurhash?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** All images Jellyfin actually stores for an item (with real resolutions). */
|
||||||
|
export const getItemImagesQueryOptions = (
|
||||||
|
api: Api | null | undefined,
|
||||||
|
itemId: string | undefined | null,
|
||||||
|
) =>
|
||||||
|
queryOptions({
|
||||||
|
queryKey: ["item", "images", itemId],
|
||||||
|
queryFn: async () => {
|
||||||
|
if (!api || !itemId) return [];
|
||||||
|
const result = await getImageApi(api).getItemImageInfos({ itemId });
|
||||||
|
return result.data;
|
||||||
|
},
|
||||||
|
enabled: Boolean(api && itemId),
|
||||||
|
staleTime: 30 * 60_000,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** Prefer the biggest wide image Jellyfin has; Backdrop wins ties over Thumb. */
|
||||||
|
const pickWideImage = (images: ImageInfo[]): ImageInfo | undefined => {
|
||||||
|
const wide = images.filter((image) => {
|
||||||
|
if (image.ImageType !== "Backdrop" && image.ImageType !== "Thumb") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const width = image.Width ?? 0;
|
||||||
|
const height = image.Height ?? 0;
|
||||||
|
return height > 0 && width / height >= 1.3;
|
||||||
|
});
|
||||||
|
wide.sort((a, b) => {
|
||||||
|
const area = (i: ImageInfo) => (i.Width ?? 0) * (i.Height ?? 0);
|
||||||
|
const diff = area(b) - area(a);
|
||||||
|
if (diff !== 0) return diff;
|
||||||
|
return a.ImageType === "Backdrop" ? -1 : 1;
|
||||||
|
});
|
||||||
|
return wide[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
const imageUrl = (
|
||||||
|
api: Api,
|
||||||
|
itemId: string,
|
||||||
|
type: ImageType,
|
||||||
|
tag: string | null | undefined,
|
||||||
|
params: { maxWidth?: number; maxHeight?: number },
|
||||||
|
) => {
|
||||||
|
const query = new URLSearchParams();
|
||||||
|
if (tag) query.set("tag", tag);
|
||||||
|
if (params.maxWidth) query.set("maxWidth", String(params.maxWidth));
|
||||||
|
if (params.maxHeight) query.set("maxHeight", String(params.maxHeight));
|
||||||
|
query.set("quality", "90");
|
||||||
|
return `${api.basePath}/Items/${itemId}/Images/${type}?${query.toString()}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const blurhashFor = (
|
||||||
|
item: BaseItemDto,
|
||||||
|
type: ImageType,
|
||||||
|
tag: string | null | undefined,
|
||||||
|
) => (tag ? item.ImageBlurHashes?.[type]?.[tag] ?? undefined : undefined);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Best artwork for the home hero (a wide 16:9 area).
|
||||||
|
*
|
||||||
|
* Jellyfin usually stores several images per item; the player/hero should use
|
||||||
|
* a wide one: Backdrop, then Thumb (often a 4K still). A Primary poster is 2:3,
|
||||||
|
* so it is only used when nothing wide exists, and the caller renders it as a
|
||||||
|
* poster on a blurred background instead of stretching it.
|
||||||
|
*/
|
||||||
|
export const resolveHeroArtwork = (
|
||||||
|
api: Api | undefined,
|
||||||
|
item: BaseItemDto | undefined | null,
|
||||||
|
images: ImageInfo[] | undefined,
|
||||||
|
): HeroArtwork | undefined => {
|
||||||
|
if (!api || !item?.Id) return undefined;
|
||||||
|
|
||||||
|
const wide = images?.length ? pickWideImage(images) : undefined;
|
||||||
|
if (wide) {
|
||||||
|
return {
|
||||||
|
url: imageUrl(api, item.Id, wide.ImageType as ImageType, wide.ImageTag, {
|
||||||
|
maxWidth: 1920,
|
||||||
|
}),
|
||||||
|
isPortrait: false,
|
||||||
|
blurhash: blurhashFor(item, wide.ImageType as ImageType, wide.ImageTag),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to tags while /Images is still loading (or for servers that
|
||||||
|
// don't return image infos).
|
||||||
|
if (item.BackdropImageTags?.length) {
|
||||||
|
return {
|
||||||
|
url: imageUrl(api, item.Id, "Backdrop", item.BackdropImageTags[0], {
|
||||||
|
maxWidth: 1920,
|
||||||
|
}),
|
||||||
|
isPortrait: false,
|
||||||
|
blurhash: blurhashFor(item, "Backdrop", item.BackdropImageTags[0]),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (item.ImageTags?.Thumb) {
|
||||||
|
return {
|
||||||
|
url: imageUrl(api, item.Id, "Thumb", item.ImageTags.Thumb, {
|
||||||
|
maxWidth: 1920,
|
||||||
|
}),
|
||||||
|
isPortrait: false,
|
||||||
|
blurhash: blurhashFor(item, "Thumb", item.ImageTags.Thumb),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (item.ImageTags?.Primary) {
|
||||||
|
return {
|
||||||
|
url: imageUrl(api, item.Id, "Primary", item.ImageTags.Primary, {
|
||||||
|
maxHeight: 1400,
|
||||||
|
}),
|
||||||
|
isPortrait: true,
|
||||||
|
blurhash: blurhashFor(item, "Primary", item.ImageTags.Primary),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (item.ParentBackdropItemId && item.ParentBackdropImageTags?.length) {
|
||||||
|
return {
|
||||||
|
url: imageUrl(
|
||||||
|
api,
|
||||||
|
item.ParentBackdropItemId,
|
||||||
|
"Backdrop",
|
||||||
|
item.ParentBackdropImageTags[0],
|
||||||
|
{ maxWidth: 1920 },
|
||||||
|
),
|
||||||
|
isPortrait: false,
|
||||||
|
blurhash: blurhashFor(
|
||||||
|
item,
|
||||||
|
"Backdrop",
|
||||||
|
item.ParentBackdropImageTags[0],
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Sharp poster URL for the poster-on-blurred-background hero treatment. */
|
||||||
|
export const getHeroPosterUrl = (
|
||||||
|
api: Api | undefined,
|
||||||
|
item: BaseItemDto | undefined | null,
|
||||||
|
) => {
|
||||||
|
if (!api || !item?.Id || !item.ImageTags?.Primary) return undefined;
|
||||||
|
return imageUrl(api, item.Id, "Primary", item.ImageTags.Primary, {
|
||||||
|
maxHeight: 900,
|
||||||
|
});
|
||||||
|
};
|
||||||
Reference in new issue
Block a user