Video stills skip YouTube's gray placeholder; timeline back to teal dots; people rows fill
- A still that fails or comes back as YouTube's 120 x 90 "no thumbnail" image gives way to the next; with none left the player is a flat teal panel with the play button showing. - Timeline: solid teal dots, a solid teal rail and teal decade tags (still on their branch), one color throughout, until a vine or tree drawing replaces them. The leaf colors are gone. - People tiles fill each row with as many as fit (2 to 10), one fewer only when the last row would be a single tile, instead of evening rows out (8 where 6 fit had come out 4 and 4). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6506f65b1e
commit
57f8020542
11 changed files with 98 additions and 151 deletions
|
|
@ -53,9 +53,10 @@ import "./PeopleTiles.css";
|
|||
* lines of name (and two of title), so a row's cards are one
|
||||
* height. The list as a whole has the frame, not each tile.
|
||||
*
|
||||
* Rows are balanced (balancedColumns): as many tiles across as fit,
|
||||
* but never fewer than 2 or more than 10, and spread so the last
|
||||
* row isn't a lone tile. When 2 don't fit at full size they shrink.
|
||||
* Rows fill (balancedColumns): as many tiles across as fit, never
|
||||
* fewer than 2 or more than 10, one fewer when that would leave a
|
||||
* lone tile on the last row. When 2 don't fit at full size they
|
||||
* shrink.
|
||||
*
|
||||
* Details open in a panel right under the tile, over what follows
|
||||
* (flipped to end at the tile's right edge when it would run off
|
||||
|
|
@ -834,16 +835,16 @@ function Chevron() {
|
|||
/* ── Helpers ─────────────────────────────────────────────────── */
|
||||
|
||||
/* Tiles across a row: as many as fit, at least 2 and at most 10
|
||||
(never more than there are), then evened out so the rows come
|
||||
out as close to equal as they can: 5 tiles that fit 4 across go
|
||||
3 and 2, not 4 and 1. If one tile would still be left alone (3
|
||||
where only 2 fit), one more, narrower, column takes it. */
|
||||
(never more than there are). If that would leave one tile alone on
|
||||
the last row, one fewer across, so the last row has two: 7 that fit
|
||||
6 across go 5 and 2. With only 2 across, a third, narrower column
|
||||
takes the odd one instead (3 tiles on a phone go 3 across). */
|
||||
export function balancedColumns(count: number, width: number, tile: number, gap: number): number {
|
||||
if (count <= 1) return 1;
|
||||
const fit = Math.floor((width + gap) / (tile + gap));
|
||||
const most = Math.min(count, 10, Math.max(2, fit));
|
||||
const cols = Math.ceil(count / Math.ceil(count / most));
|
||||
return count % cols === 1 && cols < Math.min(count, 10) ? cols + 1 : cols;
|
||||
const cols = Math.min(count, 10, Math.max(2, fit));
|
||||
if (count % cols !== 1) return cols;
|
||||
return cols > 2 ? cols - 1 : Math.min(count, 3);
|
||||
}
|
||||
|
||||
/* A string id is a people slug; a numeric or missing one is a
|
||||
|
|
|
|||
|
|
@ -6,8 +6,10 @@
|
|||
featured cards and the video content block.
|
||||
|
||||
The still is the caller's image, else YouTube's own thumbnail
|
||||
(its 16:9 one, falling back to the 4:3 one cropped), else a plain
|
||||
dark panel. The play button shows on hover or keyboard focus, and
|
||||
(its 16:9 one, falling back to the 4:3 one cropped). Any still
|
||||
that fails, or comes back as YouTube's gray "no thumbnail"
|
||||
placeholder, gives way to the next; with none left it's a flat
|
||||
teal panel with the play button always showing. The play button shows on hover or keyboard focus, and
|
||||
always on a touch screen, which can't hover. Small rounded
|
||||
corners, as the only rounded thing besides buttons and dots. A link that embeds.ts can't turn into a
|
||||
player (not https, or not a host it knows how to frame) still
|
||||
|
|
@ -18,7 +20,7 @@ import { Play } from '@phosphor-icons/react'
|
|||
import { useState, type SyntheticEvent } from 'react'
|
||||
|
||||
import HomeLink from '../pages/sections/home/HomeLink.tsx'
|
||||
import { playingSource, videoSource, videoThumbnail } from '../lib/embeds.ts'
|
||||
import { playingSource, videoSource, videoThumbnails } from '../lib/embeds.ts'
|
||||
import { BRAND } from '../lib/color.ts'
|
||||
|
||||
|
||||
|
|
@ -35,6 +37,7 @@ export default function VideoPlayer({
|
|||
className?: string
|
||||
}) {
|
||||
const [playing, setPlaying] = useState(false)
|
||||
const [skipped, setSkipped] = useState(0)
|
||||
const source = videoSource(url)
|
||||
|
||||
if (playing && source) {
|
||||
|
|
@ -52,24 +55,36 @@ export default function VideoPlayer({
|
|||
)
|
||||
}
|
||||
|
||||
const image = still ?? videoThumbnail(url)
|
||||
const stills = [...(still ? [still] : []), ...videoThumbnails(url)]
|
||||
const image = stills[skipped] ?? null
|
||||
const next = () => setSkipped((n) => n + 1)
|
||||
|
||||
// YouTube's 16:9 still is missing for some videos; its 4:3 one never is.
|
||||
const fallBack = (event: SyntheticEvent<HTMLImageElement>) => {
|
||||
// YouTube's placeholder for a missing still is a real 120 x 90 image,
|
||||
// not an error, so it's caught by its size; wherever it came from,
|
||||
// since Fetch preview may have saved one into the library.
|
||||
const checkLoaded = (event: SyntheticEvent<HTMLImageElement>) => {
|
||||
const img = event.currentTarget
|
||||
if (img.src.endsWith('/hq720.jpg')) img.src = img.src.replace(/hq720\.jpg$/, 'hqdefault.jpg')
|
||||
if (img.naturalWidth <= 120 && img.naturalHeight <= 90) next()
|
||||
}
|
||||
|
||||
const face = (
|
||||
<span className={`relative block overflow-hidden rounded-md ${className}`}>
|
||||
{image ? (
|
||||
<img src={image} alt="" loading="lazy" onError={fallBack} className="block aspect-video w-full object-cover" />
|
||||
<img
|
||||
key={image}
|
||||
src={image}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
onError={next}
|
||||
onLoad={checkLoaded}
|
||||
className="block aspect-video w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<span className="block aspect-video w-full bg-[#004552]" />
|
||||
)}
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="video-play absolute inset-0 flex items-center justify-center transition-colors group-hover:bg-black/20 group-focus-visible:bg-black/20"
|
||||
className={`video-play ${image ? '' : 'video-play--always'} absolute inset-0 flex items-center justify-center transition-colors group-hover:bg-black/20 group-focus-visible:bg-black/20`}
|
||||
>
|
||||
<span className="flex h-16 w-16 items-center justify-center rounded-full bg-white/95 shadow-lg transition-transform group-hover:scale-105">
|
||||
<Play className="h-7 w-7" weight="fill" style={{ color: BRAND }} aria-hidden="true" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue