Blend the colour wash between titles and keep full screen for the miniplayer
- The backdrop's colour wash is one layer whose corner colours are registered custom properties, so a change of title blends them instead of stacking a half-opacity layer and removing the old one (which made the colour jump). Outgoing artwork fades out before it is removed, and quick changes keep the layer that is on screen. - Going to the miniplayer no longer leaves full screen. Esc while browsing leaves full screen first, Windows' caption buttons show Exit full screen in place of maximize, closing the miniplayer keeps the window as it is, and the player's full-screen state follows changes made outside it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8755d16735
commit
b5dc5d8666
6 changed files with 135 additions and 54 deletions
|
|
@ -1,21 +1,25 @@
|
|||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useEffect, useRef, useState, type CSSProperties } from 'react';
|
||||
import type { Item } from '../plex/types';
|
||||
import { useServer } from '../app/session';
|
||||
import { useSettings } from '../app/settings';
|
||||
import { art, washGradient } from '../app/format';
|
||||
import { art, washColors } from '../app/format';
|
||||
|
||||
interface Layer {
|
||||
key: number;
|
||||
src: string;
|
||||
wash: string;
|
||||
blur: Item['ultraBlur'];
|
||||
ready: boolean;
|
||||
}
|
||||
|
||||
/** How long an outgoing layer lingers: its fade (with delay) plus a margin. */
|
||||
const LEAVE_MS = 700;
|
||||
|
||||
/**
|
||||
* Artwork-led page background. The image sits top-right and fades into the
|
||||
* page toward its left and bottom edges; the UltraBlur colour wash tints the
|
||||
* page beneath it and carries on down behind the rows. Changes crossfade; the
|
||||
* outgoing layer stays until the new image has decoded.
|
||||
* page beneath it and carries on down behind the rows. Artwork crossfades
|
||||
* once the new image has decoded, and the wash's colours blend into the new
|
||||
* title's at the same moment (registered custom properties, app.css).
|
||||
*/
|
||||
export function Backdrop({ item, className = '', width = 1600, height = 900, wash: forceWash }: { item: Item | null | undefined; className?: string; width?: number; height?: number; wash?: Item['ultraBlur'] }) {
|
||||
const server = useServer();
|
||||
|
|
@ -25,39 +29,50 @@ export function Backdrop({ item, className = '', width = 1600, height = 900, was
|
|||
const path = item ? art.backdrop(item) : '';
|
||||
const src = path ? server.image(path, width, height) : '';
|
||||
const blur = forceWash ?? item?.ultraBlur ?? null;
|
||||
const wash = colorWash && blur ? washGradient(blur) : '';
|
||||
const blurKey = blur ? `${blur.topLeft}${blur.topRight}${blur.bottomRight}${blur.bottomLeft}` : '';
|
||||
|
||||
useEffect(() => {
|
||||
if (!src && !wash) return;
|
||||
if (!src && !blur) return;
|
||||
setLayers((prev) => {
|
||||
if (prev.length && prev[prev.length - 1].src === src) {
|
||||
// Same art, maybe new wash.
|
||||
return prev.map((l, i) => (i === prev.length - 1 ? { ...l, wash } : l));
|
||||
}
|
||||
return [...prev.slice(-1), { key: ++counter.current, src, wash, ready: !src }];
|
||||
const last = prev[prev.length - 1];
|
||||
// Same art, maybe new colours: the wash blends to them in place.
|
||||
if (last && last.src === src) return prev.map((l) => (l === last ? { ...l, blur } : l));
|
||||
// Keep only what is on screen (the newest layer that has shown) under the new one.
|
||||
const shown = prev.filter((l) => l.ready).slice(-1);
|
||||
return [...shown, { key: ++counter.current, src, blur, ready: !src }];
|
||||
});
|
||||
}, [src, wash]);
|
||||
}, [src, blurKey]);
|
||||
|
||||
const onReady = (key: number) =>
|
||||
setLayers((prev) => {
|
||||
const idx = prev.findIndex((l) => l.key === key);
|
||||
if (idx < 0) return prev;
|
||||
const next = prev.map((l) => (l.key === key ? { ...l, ready: true } : l));
|
||||
// Drop older layers once the newest is visible (after its fade).
|
||||
setTimeout(() => setLayers((p) => (p.length > 1 && p[p.length - 1].key === key ? p.slice(-1) : p)), 500);
|
||||
return next;
|
||||
});
|
||||
const onReady = (key: number) => setLayers((prev) => (prev.some((l) => l.key === key && !l.ready) ? prev.map((l) => (l.key === key ? { ...l, ready: true } : l)) : prev));
|
||||
|
||||
// Once the newest layer is in, the ones beneath fade out and then go.
|
||||
const newest = layers[layers.length - 1];
|
||||
useEffect(() => {
|
||||
if (!newest?.ready || layers.length < 2) return;
|
||||
const t = setTimeout(() => setLayers((p) => (p[p.length - 1]?.key === newest.key ? p.slice(-1) : p)), LEAVE_MS);
|
||||
return () => clearTimeout(t);
|
||||
}, [newest?.key, newest?.ready, layers.length]);
|
||||
|
||||
let top = -1;
|
||||
layers.forEach((l, i) => l.ready && (top = i));
|
||||
const colors = top >= 0 ? washColors(layers[top].blur) : null;
|
||||
const washStyle = {
|
||||
'--wash-tr': colors?.topRight ?? 'transparent',
|
||||
'--wash-tl': colors?.topLeft ?? 'transparent',
|
||||
'--wash-br': colors?.bottomRight ?? 'transparent',
|
||||
'--wash-bl': colors?.bottomLeft ?? 'transparent',
|
||||
} as CSSProperties;
|
||||
|
||||
return (
|
||||
<>
|
||||
{colorWash && (
|
||||
<div className={`backdrop-tint ${className}`} aria-hidden="true">
|
||||
{layers.map((l) => l.wash && <div key={l.key} className={`backdrop-wash${l.ready ? ' ready' : ''}`} style={{ background: l.wash }} />)}
|
||||
<div className="backdrop-wash" style={washStyle} />
|
||||
</div>
|
||||
)}
|
||||
<div className={`backdrop ${className}${colorWash ? ' washed' : ''}`} aria-hidden="true">
|
||||
{layers.map((l) => (
|
||||
<div key={l.key} className={`backdrop-layer${l.ready ? ' ready' : ''}`}>
|
||||
{layers.map((l, i) => (
|
||||
<div key={l.key} className={`backdrop-layer${l.ready ? ' ready' : ''}${i < top ? ' leaving' : ''}`}>
|
||||
{l.src && <img className="backdrop-art" src={l.src} alt="" draggable={false} decoding="async" onLoad={() => onReady(l.key)} onError={() => onReady(l.key)} />}
|
||||
</div>
|
||||
))}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue