From 76a1d98f2f3e1aacbd760ce738cdd4b216faf0cc Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Fri, 20 Nov 2026 06:31:35 -0500 Subject: [PATCH 01/97] Redesign foundations: tokens, motion, and the libraries the new UI reads The leaves of the media-first redesign (#76), split out so it can be reviewed in pieces. Nothing here changes how the current pages work: - styles/tokens.css: the design tokens the new shell and stage use. - motion/propflip: the shared FLIP helper for things that move between homes on the page. - lib: cast, cues, entities and transcript changes the stage and the live transcript build on. - utils/config: the config the redesign reads. - Icon, illustration and sponsor SVGs redrawn for the new palette. Co-Authored-By: Claude Opus 5.5 --- packages/starpod/src/lib/cast.ts | 227 ++++++++++- packages/starpod/src/lib/cues.ts | 17 +- packages/starpod/src/lib/entities.ts | 8 +- packages/starpod/src/lib/transcript.ts | 32 +- packages/starpod/src/motion/propflip.css | 103 +++++ packages/starpod/src/motion/propflip.ts | 428 +++++++++++++++++++++ packages/starpod/src/styles/tokens.css | 259 +++++++++++++ packages/starpod/src/svgs/404-dark.svg | 6 +- packages/starpod/src/svgs/404-light.svg | 6 +- packages/starpod/src/svgs/apple.svg | 2 +- packages/starpod/src/svgs/overcast.svg | 2 +- packages/starpod/src/svgs/pocket-casts.svg | 2 +- packages/starpod/src/svgs/spotify.svg | 2 +- packages/starpod/src/svgs/ufo-dark.svg | 14 +- packages/starpod/src/svgs/ufo-light.svg | 14 +- packages/starpod/src/svgs/youtube.svg | 4 +- packages/starpod/src/utils/config.ts | 15 +- src/img/sponsors/cascadiajs.svg | 2 +- src/img/sponsors/code-rabbit.svg | 2 +- src/img/sponsors/gitkraken.svg | 2 +- src/img/sponsors/norlan.svg | 2 +- src/img/sponsors/warp.svg | 4 +- tests/unit/cast.test.ts | 169 +++++++- tests/unit/config.test.ts | 16 + tests/unit/cues.test.ts | 14 - tests/unit/propflip.test.ts | 111 ++++++ tests/unit/transcript.test.ts | 67 +++- 27 files changed, 1440 insertions(+), 90 deletions(-) create mode 100644 packages/starpod/src/motion/propflip.css create mode 100644 packages/starpod/src/motion/propflip.ts create mode 100644 packages/starpod/src/styles/tokens.css create mode 100644 tests/unit/propflip.test.ts diff --git a/packages/starpod/src/lib/cast.ts b/packages/starpod/src/lib/cast.ts index 41ce3c3f..07a7dac1 100644 --- a/packages/starpod/src/lib/cast.ts +++ b/packages/starpod/src/lib/cast.ts @@ -54,7 +54,7 @@ const tokens = (name: string) => * start the same way ("Robbie" ~ "RobbieTheWagner"), or they share a surname * ("Chuck Carpenter" ~ "Charles William Carpenter III"). */ -function sameName(a: string, b: string) { +export function sameName(a: string, b: string) { const [aFirst = '', ...aRest] = tokens(a); const [bFirst = '', ...bRest] = tokens(b); if (aFirst.length >= 3 && bFirst.length >= 3 && (aFirst.startsWith(bFirst) || bFirst.startsWith(aFirst))) { @@ -63,29 +63,224 @@ function sameName(a: string, b: string) { return aRest.some((token) => token.length >= 4 && bRest.includes(token)); } +/** + * How surely two names are one person, 0 when they aren't: + * 4 the same name ("Shruti Kapoor"); + * 3 first names that agree and a shared surname ("Rob Wagner" ~ "Robbie + * Wagner"); + * 2 first names that agree where one name has nothing else ("Jason" ~ + * "Jason Lengstorf", "RobbieTheWagner" ~ "Robbie Wagner"); + * 1 only a shared surname ("Chuck Carpenter" ~ "Charles William Carpenter + * III"), counted only when `surnames` is on: within one episode's own cast, + * never across the site, where every Wagner would match. + * Two full names whose surnames differ ("Adam Rackis", "Adam Argyle") never + * match. + */ +function likeness(a: string, b: string, surnames: boolean) { + const [aFirst = '', ...aRest] = tokens(a); + const [bFirst = '', ...bRest] = tokens(b); + if (!aFirst || !bFirst) { + return 0; + } + if ([aFirst, ...aRest].join(' ') === [bFirst, ...bRest].join(' ')) { + return 4; + } + const firsts = + aFirst.length >= 3 && + bFirst.length >= 3 && + (aFirst.startsWith(bFirst) || bFirst.startsWith(aFirst)); + const surname = aRest.some( + (token) => token.length >= 4 && bRest.includes(token) + ); + if (firsts && surname) { + return 3; + } + if (firsts && (!aRest.length || !bRest.length)) { + return 2; + } + return surnames && surname && !firsts ? 1 : 0; +} + +/** + * Pairs each item with at most one candidate and each candidate with at most + * one item: the surest pairs first, and a pair that ties with another for + * the same item or candidate is ambiguous and goes to neither, so nothing is + * matched by a guess. + */ +function pair( + items: Array, + candidates: Array, + score: (item: T, candidate: string) => number +) { + const pairs: Array<{ item: T; candidate: string; score: number }> = []; + for (const item of items) { + for (const candidate of new Set(candidates)) { + const value = score(item, candidate); + if (value) { + pairs.push({ item, candidate, score: value }); + } + } + } + pairs.sort((a, b) => b.score - a.score); + const matched = new Map(); + const used = new Set(); + for (let start = 0; start < pairs.length; ) { + let end = start; + while (end < pairs.length && pairs[end].score === pairs[start].score) { + end++; + } + const open = pairs + .slice(start, end) + .filter( + ({ item, candidate }) => !matched.has(item) && !used.has(candidate) + ); + for (const one of open) { + const rivals = open.filter( + (other) => + other !== one && + (other.item === one.item || other.candidate === one.candidate) + ); + if (!rivals.length) { + matched.set(one.item, one.candidate); + used.add(one.candidate); + } + } + start = end; + } + return matched; +} + +/** + * Pairs each of `names` with at most one of `candidates`, and each candidate + * with at most one name, surest first (see `likeness` and `pair`). Returns + * name → candidate. Used to find who in a cast is which transcript speaker. + */ +export function matchNames( + names: Array, + candidates: Array, + { surnames = false } = {} +) { + return pair([...new Set(names)], candidates, (name, candidate) => + likeness(name, candidate, surnames) + ); +} + +/** + * Who on a page is speaking: `names` are the people a page shows (however + * each element names them), `speakers` the playing transcript's. Names that + * are surely one person ("RobbieTheWagner" on the rail, "Robbie Wagner" on a + * card) count as one, so all of them light; otherwise each speaker goes to + * at most one person, the surest, and never by a shared surname alone, so a + * host's lines light no namesake. Returns name → speaker. + */ +export function matchPageNames(names: Array, speakers: Array) { + const people: Array> = []; + for (const name of new Set(names)) { + const same = people.filter((person) => + person.some((other) => likeness(name, other, false) >= 2) + ); + // A name that could be either of two people stays on its own. + if (same.length === 1) { + same[0].push(name); + } else { + people.push([name]); + } + } + const matched = pair(people, speakers, (person, speaker) => + Math.max(...person.map((name) => likeness(name, speaker, false))) + ); + return new Map( + [...matched].flatMap(([person, speaker]) => + person.map((name) => [name, speaker] as const) + ) + ); +} + /** * Which transcript voice (0 or 1, the two most talkative speakers) a person * speaks in, so their name on the stage wears the same typeface as their - * lines. People who don't speak as one of those two, or can't be matched, get - * no voice. + * lines. Pass the episode's whole `cast` so each speaker goes to the right one + * of them (`matchNames`); people who don't speak as one of those two, or + * can't be told apart, get no voice. */ export function voiceFor( name: string, - cues: Array | null + cues: Array | null, + cast: Array = [name] ): number | undefined { if (!cues?.length) { return undefined; } - const speakers = [0, 1].map((voice) => ({ - voice, - speaker: cues.find((cue) => cue.v === voice && cue.n)?.n - })); - // An exact name wins over a loose one, whichever voice comes first. A name - // with nothing left after normalizing never matches. - const exact = tokens(name).join(' '); - const match = - (exact - ? speakers.find(({ speaker }) => speaker && tokens(speaker).join(' ') === exact) - : undefined) ?? speakers.find(({ speaker }) => speaker && sameName(name, speaker)); - return match?.voice; + const speakers = [...new Set(cues.flatMap((cue) => (cue.n ? [cue.n] : [])))]; + const speaker = matchNames(cast, speakers, { surnames: true }).get(name); + const voice = speaker ? cues.find((cue) => cue.n === speaker)?.v : undefined; + return voice === 0 || voice === 1 ? voice : undefined; +} + +/** + * Which of a transcript's speakers one name is, on its own (no cast to weigh + * it against): exact, or first names that agree (`matchNames`, without + * surname-only matches). Undefined when none matches surely. + */ +export function speakerFor(name: string, speakers: Array) { + return matchNames([name], speakers).get(name); +} + +/** 1st, 2nd, 3rd, 4th … 11th, 12th, 13th … 21st. */ +export function ordinal(n: number) { + const teen = n % 100 >= 11 && n % 100 <= 13; + const suffix = teen ? 'th' : ({ 1: 'st', 2: 'nd', 3: 'rd' }[n % 10] ?? 'th'); + return `${n}${suffix}`; +} + +/** + * The one line under a person's name that says something about them, the + * first that applies, in sentence case. On an episode (`appearance` given: + * which of their episodes this one is, oldest first): a host's tally, a + * guest's first time, or which time this is and where they first appeared. + * Anywhere else: their role and tally. + */ +export function personFact({ + appearance, + count, + first, + host +}: { + /** Which of their episodes this one is, oldest first (1-based). */ + appearance?: number; + /** How many episodes they are on. */ + count: number; + /** Their first episode, as the site labels it ("Ep 112"). */ + first?: string; + host: boolean; +}) { + const episodes = `${count} ${count === 1 ? 'episode' : 'episodes'}`; + if (host || appearance === undefined) { + return `${host ? 'Host' : 'Guest'} · ${episodes}`; + } + if (count <= 1) { + return 'First time on the show'; + } + if (appearance === 1) { + return `First of ${count} appearances`; + } + return first + ? `${ordinal(appearance)} appearance · first on ${first}` + : `${ordinal(appearance)} appearance`; +} + +/** + * Whether `personFact`'s line already says how many episodes they are on + * (a first time says it's one), so a tally beside it would repeat it. + */ +export function factGivesCount({ + appearance, + count, + host +}: { + appearance?: number; + count: number; + host: boolean; +}) { + return host || appearance === undefined || count <= 1 || appearance === 1; } diff --git a/packages/starpod/src/lib/cues.ts b/packages/starpod/src/lib/cues.ts index 921f0b0e..f98d3d7d 100644 --- a/packages/starpod/src/lib/cues.ts +++ b/packages/starpod/src/lib/cues.ts @@ -1,4 +1,3 @@ -import { decodeEntities } from './entities'; import type { Episode } from './rss'; import { fetchTranscriptText, @@ -161,16 +160,6 @@ export function jsonSegments(data: { segments?: Array } | null): Ar }); } -/** A VTT/SRT cue's text: voice and styling tags removed, references decoded. */ -export function cueText(raw: string): { text: string; speaker?: string } { - // WebVTT voice spans: text - const voice = raw.match(/^]*)?\s+([^>]+)>/); - return { - text: decodeEntities(raw.replace(/<[^>]+>/g, '')).trim(), - speaker: voice ? decodeEntities(voice[1]).trim() : undefined - }; -} - /** * Timed lines from the feed's `` (VTT/SRT cues or JSON * segments). Returns `null` when none is available. @@ -212,10 +201,8 @@ async function fetchRssCues( const segments = jsonSegments(JSON.parse(download.raw)); return segments.length ? mergeIntoLines(segments) : null; } - const cues = parseCues(download.raw).map((cue) => ({ - start: cue.start, - ...cueText(cue.text) - })); + // Plain text, with the speaker from any WebVTT voice span. + const cues = parseCues(download.raw); return cues.length ? mergeIntoLines(cues) : null; } catch { return null; diff --git a/packages/starpod/src/lib/entities.ts b/packages/starpod/src/lib/entities.ts index 38c05637..984cd714 100644 --- a/packages/starpod/src/lib/entities.ts +++ b/packages/starpod/src/lib/entities.ts @@ -2,9 +2,11 @@ const NAMED: Record = { amp: '&', apos: "'", gt: '>', + lrm: '\u200e', lt: '<', nbsp: ' ', - quot: '"' + quot: '"', + rlm: '\u200f' }; /** @@ -14,13 +16,13 @@ const NAMED: Record = { */ export function decodeEntities(value: string): string { return value.replace( - /&(?:#(\d+)|#x([\da-f]+)|(amp|apos|gt|lt|nbsp|quot));/gi, + /&(?:#(\d+)|#x([\da-f]+)|(amp|apos|gt|lrm|lt|nbsp|quot|rlm));/gi, (reference, decimal?: string, hex?: string, name?: string) => { if (name) { return NAMED[name.toLowerCase()]; } const codePoint = decimal ? Number(decimal) : parseInt(hex!, 16); - return codePoint <= 0x10ffff ? String.fromCodePoint(codePoint) : reference; + return codePoint > 0 && codePoint <= 0x10ffff ? String.fromCodePoint(codePoint) : reference; } ); } diff --git a/packages/starpod/src/lib/transcript.ts b/packages/starpod/src/lib/transcript.ts index db4df787..bff015b1 100644 --- a/packages/starpod/src/lib/transcript.ts +++ b/packages/starpod/src/lib/transcript.ts @@ -1,3 +1,4 @@ +import { decodeEntities } from './entities'; import type { Episode } from './rss'; // Roughly how many characters to accumulate before starting a new paragraph @@ -183,15 +184,27 @@ function parseTranscript( return stripped ? splitParagraphs(stripped) : null; } +// What a WebVTT cue's markup looks like: a class, italic, bold, underline, +// ruby, voice or language span (``, ``, ``…) or a +// timestamp (`<00:01:02.500>`). Anything else in angle brackets, like SRT's +// unescaped "x < 5 and y > 3", is text. +const CUE_TAG = + /<\/?(?:[cibuv]|ruby|rt|lang)(?:\.[^\s<>]*)?(?:\s[^<>]*)?>|<(?:\d+:)?\d{2}:\d{2}\.\d{3}>/g; + /** - * Parse WebVTT/SRT cue blocks into `{ start, text }` entries, preserving the - * start time (in seconds) of each cue. Blocks without a `-->` timing line - * (e.g. the `WEBVTT` header) are skipped. + * Parse WebVTT/SRT cue blocks into `{ start, text, speaker }` entries, + * preserving the start time (in seconds) of each cue. Blocks without a `-->` + * timing line (e.g. the `WEBVTT` header) are skipped. + * + * The text comes back plain, ready to render once: a WebVTT voice span + * (`…`) gives the speaker, every tag is dropped, and only then are + * character references (`&`, `<`…) decoded, so escaped text can never + * turn into a tag. */ export function parseCues( raw: string -): Array<{ text: string; start: number }> { - const cues: Array<{ text: string; start: number }> = []; +): Array<{ text: string; start: number; speaker?: string }> { + const cues: Array<{ text: string; start: number; speaker?: string }> = []; for (const block of raw.replace(/\r\n/g, '\n').split(/\n{2,}/)) { const lines = block @@ -206,9 +219,14 @@ export function parseCues( const start = parseCueStart(lines[timingIndex]); // Cue text is everything after the timing line (the numeric index and any // cue identifier come before it). - const text = lines.slice(timingIndex + 1).join(' ').trim(); + const markup = lines.slice(timingIndex + 1).join(' ').trim(); + const voice = markup.match(/^]*)?\s+([^>]+)>/)?.[1]; + const speaker = voice && decodeEntities(voice).trim(); + const text = decodeEntities(markup.replace(CUE_TAG, '')) + .replace(/\s+/g, ' ') + .trim(); if (start !== undefined && text) { - cues.push({ text, start }); + cues.push(speaker ? { text, start, speaker } : { text, start }); } } diff --git a/packages/starpod/src/motion/propflip.css b/packages/starpod/src/motion/propflip.css new file mode 100644 index 00000000..4dbeeb34 --- /dev/null +++ b/packages/starpod/src/motion/propflip.css @@ -0,0 +1,103 @@ +/* + PropFLIP: FLIP where the invert is four typed custom properties and the + play is a CSS transition. Vendored from Adam Argyle's PropFLIP kit + (https://nerdy.dev/prop-flip). The script half is ./propflip.ts. +*/ +@property --tx { syntax: ""; inherits: false; initial-value: 0; } +@property --ty { syntax: ""; inherits: false; initial-value: 0; } +/* The scale does not inherit: a tween would otherwise restyle the whole + subtree every frame. Children that un-squish read it through the relay + pair below (see UnSquish). */ +@property --sx { syntax: ""; inherits: false; initial-value: 1; } +@property --sy { syntax: ""; inherits: false; initial-value: 1; } + +/* Starpod departs from the author's kit here. The kit's un-squished + children read the parent's scale with `--sx: inherit`, but WebKit does + not restyle a child that reads a non-inheriting registered property + through `inherit` while the parent's value tweens: the child keeps the + counter-scale it was first given (the search palette's text stayed about + ten times tall, and its rows missed their clicks). Minimal repro: a + parent transitions a registered, non-inheriting --sx from 4 to 1, and its + child sets `--sx: inherit; transform: scale(calc(1 / var(--sx)))`. Chrome + follows the tween; WebKit stays at the child's first value. + + So the parent relays its scale into this inheriting pair, which its + children read, and their children reset it: a flip restyles the box, its + children and grandchildren (a handful more elements per frame than the + kit in Chrome, measured), never the whole subtree. */ +@property --kid-sx { syntax: ""; inherits: true; initial-value: 1; } +@property --kid-sy { syntax: ""; inherits: true; initial-value: 1; } + +/* Typed so they can tween alongside the flip: --r is the corner radius, + --ox/--oy are an unsquished child's offset from its parent's corner. */ +@property --r { syntax: ""; inherits: false; initial-value: 0px; } +@property --ox { syntax: ""; inherits: false; initial-value: 0px; } +@property --oy { syntax: ""; inherits: false; initial-value: 0px; } + +:root { + --flip-dx: 0.6s; + --flip-dy: 0.6s; + --flip-ds: 0.6s; + --flip-ex: ease; + --flip-ey: ease; + --flip-es: ease; + --slomo: 1; +} + +.PropFLIP { + transform: + translate(calc(var(--tx) * 1px), calc(var(--ty) * 1px)) + scale(var(--sx), var(--sy)); + transform-origin: top left; + border-radius: calc(var(--r) / var(--sx)) / calc(var(--r) / var(--sy)); + /* --also is where layout transitions join the list (width/height for the + hybrid, left/top too for a pure anchored glide). They must live in this + one list so holding the flip doesn't cancel them. */ + transition: + --tx calc(var(--flip-dx) * var(--slomo)) var(--flip-ex) calc(var(--flip-delay, 0s) * var(--slomo)), + --ty calc(var(--flip-dy) * var(--slomo)) var(--flip-ey) calc(var(--flip-delay, 0s) * var(--slomo)), + --sx calc(var(--flip-ds) * var(--slomo)) var(--flip-es) calc(var(--flip-delay, 0s) * var(--slomo)), + --sy calc(var(--flip-ds) * var(--slomo)) var(--flip-es) calc(var(--flip-delay, 0s) * var(--slomo)), + var(--also, visibility 0s); +} + +/* "turn the transition off": only the 4 props, layout transitions keep running */ +.PropFLIP.flip-hold { + transition: var(--also, visibility 0s); +} + +/* UnSquish: opted-in direct children undo the parent's scale, read through + the relay (above). Set --ox/--oy to the child's offset from the corner it + hangs off. */ +.PropFLIP:has(> [data-unsquish]) { --kid-sx: var(--sx); --kid-sy: var(--sy); } +.PropFLIP > [data-unsquish] { + transform-origin: top left; + transform: + translate(calc(var(--ox) / var(--kid-sx) - var(--ox)), calc(var(--oy) / var(--kid-sy) - var(--oy))) + scale(calc(1 / var(--kid-sx)), calc(1 / var(--kid-sy))); +} +.PropFLIP > [data-unsquish="br"] { + transform-origin: bottom right; + transform: + translate(calc(var(--ox) - var(--ox) / var(--kid-sx)), calc(var(--oy) - var(--oy) / var(--kid-sy))) + scale(calc(1 / var(--kid-sx)), calc(1 / var(--kid-sy))); +} +/* Zero specificity, so a nested box's own relay wins. */ +:where(.PropFLIP > [data-unsquish] > *) { --kid-sx: 1; --kid-sy: 1; } + +/* The post's own spelling of the two fixes, as opt-in classes: + .fix-radius keeps corners round (set --r), .fix-kids un-squishes every + direct child (set --p to the padding they sit at, 0 for a full-bleed wrapper). */ +.fix-radius { --r: 12px; } +.fix-kids { --kid-sx: var(--sx); --kid-sy: var(--sy); } +.fix-kids > * { + transform-origin: top left; + transform: + translate(calc(var(--p, 0px) / var(--kid-sx) - var(--p, 0px)), calc(var(--p, 0px) / var(--kid-sy) - var(--p, 0px))) + scale(calc(1 / var(--kid-sx)), calc(1 / var(--kid-sy))); +} +:where(.fix-kids > * > *) { --kid-sx: 1; --kid-sy: 1; } + +@media (prefers-reduced-motion: reduce) { + :root { --slomo: 0; } +} diff --git a/packages/starpod/src/motion/propflip.ts b/packages/starpod/src/motion/propflip.ts new file mode 100644 index 00000000..776f50eb --- /dev/null +++ b/packages/starpod/src/motion/propflip.ts @@ -0,0 +1,428 @@ +/** + * PropFLIP, the script half. A typed port of Adam Argyle's PropFLIP kit + * (https://nerdy.dev/prop-flip); the styles are in ./propflip.css. + * + * Elements that flip carry the `PropFLIP` class. The invert is written to + * four typed custom properties (--tx, --ty, --sx, --sy) and the play is a CSS + * transition, so a flip is interruptible and composes with any layout + * transition listed in `--also` (the anchored-auto-layout hybrid). + * + * Client-only at call time. Importing it on the server is safe. + */ + +export interface FlipProps { + tx: number; + ty: number; + sx: number; + sy: number; +} + +export interface FlipRect { + left: number; + top: number; + width: number; + height: number; +} + +export interface FlipMove { + el: HTMLElement; + first: FlipRect; + last: FlipRect; + moving?: boolean; + delay?: number; +} + +export interface FlipOptions { + /** Element to measure relative to (a counter-scaled wrapper). */ + frame?: (el: HTMLElement) => Element | null | undefined; + /** Milliseconds between each moving element. */ + stagger?: number; + /** Animate even if the layout box didn't change (a drag release). */ + force?: boolean | ((el: HTMLElement) => boolean); + /** Sort moving elements before staggering. */ + order?: (a: HTMLElement, b: HTMLElement) => number; +} + +export interface WatchJumpsOptions { + threshold?: number; + onJump?: (el: HTMLElement) => void; + /** Milliseconds after the last wake() before the watcher sleeps. */ + idle?: number; +} + +export type StopWatching = (() => void) & { wake: () => void }; + +function setProps(el: HTMLElement, { tx, ty, sx, sy }: FlipProps) { + el.style.setProperty('--tx', String(tx)); + el.style.setProperty('--ty', String(ty)); + el.style.setProperty('--sx', String(sx)); + el.style.setProperty('--sy', String(sy)); +} + +/** + * The batch from the article: measure First, hold the transition, change the + * DOM, measure, invert, release. + * + * Pass elements parents-first. "First" is the visual rect, so calling this + * mid-flight just works. The invert is measured against the layout as it is + * right after the change, so anything Anchored Auto Layout is already + * transitioning (width, height, left, top) reads as "no difference" and + * PropFLIP only animates what's left over. + */ +export function propFlip(targets: Iterable, mutate: () => void) { + const els = [...targets]; + const first = els.map((el) => el.getBoundingClientRect()); + + els.forEach((el) => el.classList.add('flip-hold')); + mutate(); + + els.forEach((el, i) => { + const f = first[i]!; + const now = el.getBoundingClientRect(); + if (!f.width || !now.width) { + return; // entering or leaving, nothing to flip + } + setProps(el, { + tx: f.left - now.left, + ty: f.top - now.top, + sx: f.width / now.width, + sy: f.height / now.height + }); + }); + + void document.body.offsetHeight; // commit the lie + + els.forEach((el) => { + el.classList.remove('flip-hold'); + setProps(el, IDENTITY); + }); +} + +const IDENTITY: FlipProps = { tx: 0, ty: 0, sx: 1, sy: 1 }; + +/** True when the visitor (or ``) asks for less motion. */ +export function reducedMotion(): boolean { + return ( + globalThis.matchMedia?.('(prefers-reduced-motion: reduce)').matches || + document.documentElement.dataset.motion === 'reduce' + ); +} + +/** The current (possibly mid-transition) values of the four props. */ +export function props(el: Element): FlipProps { + const cs = getComputedStyle(el); + const n = (k: string, d: number) => { + const v = parseFloat(cs.getPropertyValue(k)); + return Number.isFinite(v) ? v : d; + }; + return { tx: n('--tx', 0), ty: n('--ty', 0), sx: n('--sx', 1), sy: n('--sy', 1) }; +} + +function rect(el: Element, frame?: Element | null): FlipRect { + const r = el.getBoundingClientRect(); + if (!frame) { + return { left: r.left, top: r.top, width: r.width, height: r.height }; + } + const f = frame.getBoundingClientRect(); + return { left: r.left - f.left, top: r.top - f.top, width: r.width, height: r.height }; +} + +/** A visual rect minus the element's own PropFLIP transform: its layout box. */ +export function strip(v: FlipRect, p: FlipProps): FlipRect { + return { + left: v.left - p.tx, + top: v.top - p.ty, + width: v.width / p.sx, + height: v.height / p.sy + }; +} + +export function layoutRect(el: Element, frame?: Element | null): FlipRect { + return strip(rect(el, frame), props(el)); +} + +function close(a: FlipRect, b: FlipRect, eps = 0.5) { + return ( + Math.abs(a.left - b.left) < eps && + Math.abs(a.top - b.top) < eps && + Math.abs(a.width - b.width) < eps && + Math.abs(a.height - b.height) < eps + ); +} + +function inFlight(p: FlipProps) { + return ( + Math.abs(p.tx) > 0.5 || + Math.abs(p.ty) > 0.5 || + Math.abs(p.sx - 1) > 0.005 || + Math.abs(p.sy - 1) > 0.005 + ); +} + +type FlipListener = (moves: FlipMove[]) => void; +const listeners = new Set(); +const resynced = new WeakSet(); + +/** Hear about every committed flip. Returns the unsubscribe. */ +export function onFlip(fn: FlipListener) { + listeners.add(fn); + return () => listeners.delete(fn); +} + +function commit(moves: FlipMove[]) { + if (!moves.length) { + return; + } + // Hold only the flip's own four: whatever its `--also` lists (a layout + // transition the update just started) keeps running, as .flip-hold does. + for (const { el, first, last } of moves) { + el.style.transition = 'var(--also, visibility 0s)'; + setProps(el, { + tx: first.left - last.left, + ty: first.top - last.top, + sx: first.width / last.width || 1, + sy: first.height / last.height || 1 + }); + } + void document.body.offsetHeight; // commit the lie + for (const { el, delay } of moves) { + el.style.transition = ''; + el.style.setProperty('--flip-delay', `${delay || 0}ms`); + setProps(el, IDENTITY); + resynced.add(el); + } + listeners.forEach((fn) => fn(moves)); +} + +/** + * Where propFlip() cancels a running transition to measure, flip() never + * does: it reads each element's live --tx/--ty/--sx/--sy, strips that + * transform from its rect to find the layout box, then inverts from the exact + * pixels on screen. Elements already in flight never get a stagger re-applied. + */ +export function flip( + targets: Iterable, + update: () => void = () => {}, + opts: FlipOptions = {} +): FlipMove[] { + const els = [...targets].filter((el): el is HTMLElement => Boolean(el)); + if (reducedMotion()) { + update(); + els.forEach((el) => { + el.style.transition = ''; + setProps(el, IDENTITY); + }); + return []; + } + const before = els.map((el) => { + const f = opts.frame?.(el) || null; + const p = props(el); + const v = rect(el, f); + return { el, f, p, v, l: strip(v, p) }; + }); + update(); + const moves: FlipMove[] = []; + for (const b of before) { + if (!b.el.isConnected) { + continue; + } + const last = strip(rect(b.el, b.f), b.p); + if (!last.width || !last.height || !b.v.width || !b.v.height) { + continue; + } + const forced = typeof opts.force === 'function' ? opts.force(b.el) : opts.force; + if (!forced && close(b.l, last)) { + continue; + } + moves.push({ el: b.el, first: b.v, last, moving: inFlight(b.p) }); + } + if (opts.order) { + const order = opts.order; + moves.sort((a, b) => order(a.el, b.el)); + } + // Stagger only things at rest: re-delaying a box that's mid-flight would + // freeze it in place on every interrupt. + moves.forEach((m, i) => (m.delay = m.moving ? 0 : (opts.stagger || 0) * i)); + commit(moves); + return moves; +} + +/** Animate an element from an arbitrary visual rect to wherever layout has it. */ +export function flipFrom(el: HTMLElement, first: FlipRect, frame?: Element | null) { + if (reducedMotion()) { + return; + } + const last = strip(rect(el, frame), props(el)); + commit([{ el, first, last }]); +} + +/** Freeze an element where its pixels are right now (a drag pickup mid-flight). */ +export function hold(el: HTMLElement): FlipProps { + const p = props(el); + el.style.transition = 'none'; + setProps(el, p); + return p; +} + +export function nudge(el: HTMLElement, p: FlipProps) { + setProps(el, p); +} + +/** + * Watch for layout jumps nobody asked for: a position-try fallback flipping, + * the anchor changing size, a container query re-laying content. Layout is + * tracked relative to the anchor, so an anchor being dragged (the target + * following it every frame) is not a jump, but a fallback flip is. + * + * Measuring every frame is not free. Pass `idle` (ms) and the watcher sleeps + * that long after the last wake(); call wake() from whatever can cause a jump + * (a drag, a toggle, a resize). + */ +export function watchJumps( + getEl: () => HTMLElement | null | undefined, + getAnchor: () => Element | null | undefined, + { threshold = 4, onJump, idle }: WatchJumpsOptions = {} +): StopWatching { + type Snapshot = { rel: FlipRect; vis: FlipRect }; + let prev: Snapshot | null = null; + let prevEl: Element | null = null; + let stopped = false; + let until = 0; + let running = true; + + const measure = (now: number) => { + const el = getEl(); + const anchor = getAnchor(); + if (!el?.isConnected || !anchor?.isConnected) { + prev = null; + return; + } + const a = anchor.getBoundingClientRect(); + const p = props(el); + // Never fall asleep on a box that is still in flight: its pixels would be + // stale on waking. + if (inFlight(p)) { + until = now + (idle || 0); + } + const v = el.getBoundingClientRect(); + const l = strip(v, p); + const cur: Snapshot = { + rel: { left: l.left - a.left, top: l.top - a.top, width: l.width, height: l.height }, + vis: { left: v.left - a.left, top: v.top - a.top, width: v.width, height: v.height } + }; + if (el !== prevEl || resynced.has(el) || el.dataset.held != null || reducedMotion()) { + resynced.delete(el); + prevEl = el; + prev = cur; + return; + } + if (prev && !close(prev.rel, cur.rel, threshold) && l.width && l.height && prev.vis.width) { + const first = { + left: prev.vis.left + a.left, + top: prev.vis.top + a.top, + width: prev.vis.width, + height: prev.vis.height + }; + commit([{ el, first, last: l }]); + resynced.delete(el); + cur.vis = { ...prev.vis }; + onJump?.(el); + } + prev = cur; + }; + + const tick = (now: number) => { + running = false; + if (stopped) { + return; + } + measure(now); + if (!idle || now < until) { + running = true; + requestAnimationFrame(tick); + } + }; + requestAnimationFrame(tick); + + const stop = (() => { + stopped = true; + }) as StopWatching; + stop.wake = () => { + until = performance.now() + (idle || 0); + if (!running && !stopped) { + running = true; + requestAnimationFrame(tick); + } + }; + return stop; +} + +/* + Layout flips across features. A feature registers a collector for the boxes + it wants carried through any shell-level layout change (visible episode + cards, the stage frame…); whoever changes the layout (the sidebar toggle, a + view switch) wraps the change in flipLayout() and every registered box + glides to its new place. +*/ +type Collector = () => Iterable; +export interface FlipTargetOptions { + /** + * Runs after the layout change and before the new boxes are measured: the + * place for a feature to write sizes it derives from the new layout (its + * own ResizeObserver's work, done now), so the flip measures where its + * boxes will really be rather than one frame stale. + */ + settle?: () => void; + /** + * Measure this feature's boxes in the viewport, not against the frame the + * caller passes (the page column): for a feature that scrolls in settle() + * to hold the reader's place, which a frame-relative box can't see. + */ + viewport?: boolean; +} +const registrations = new Set<{ collect: Collector } & FlipTargetOptions>(); + +/** Register boxes to carry through shell-level layout changes. Returns the unregister. */ +export function registerFlipTargets(collect: Collector, opts: FlipTargetOptions = {}) { + const registration = { collect, ...opts }; + registrations.add(registration); + return () => registrations.delete(registration); +} + +/** Run a layout change and flip every registered box (plus `extra`) through it. */ +export function flipLayout( + mutate: () => void, + opts: FlipOptions & { extra?: Iterable } = {} +): FlipMove[] { + const all = [...registrations]; + const inViewport = new Set(); + const targets = all.flatMap(({ collect, viewport }) => { + const els = [...collect()]; + if (viewport) { + els.forEach((el) => inViewport.add(el)); + } + return els; + }); + return flip( + [...targets, ...(opts.extra ?? [])], + () => { + mutate(); + all.forEach(({ settle }) => settle?.()); + }, + { ...opts, frame: (el) => (inViewport.has(el) ? null : opts.frame?.(el)) } + ); +} + +/** The kit under its original name. */ +export const PropFLIP = { + reducedMotion, + props, + strip, + layoutRect, + onFlip, + flip, + flipFrom, + hold, + nudge, + watchJumps +}; diff --git a/packages/starpod/src/styles/tokens.css b/packages/starpod/src/styles/tokens.css new file mode 100644 index 00000000..e39748fc --- /dev/null +++ b/packages/starpod/src/styles/tokens.css @@ -0,0 +1,259 @@ +/* + Starpod tokens. One palette (Iris for light, Aqua for dark) and one Stage + world; DESIGN.md documents the system. All colour is OKLCH. +*/ + +@property --halo { + syntax: ''; + inherits: true; + initial-value: 0; +} + +:root { + --iris-100: oklch(95% 0.022 293); + --iris-200: oklch(86.9% 0.07 293.5); + --iris-300: oklch(77.32% 0.129 294.81); + --iris-500: oklch(59.6% 0.22 292); + --iris-700: oklch(45.5% 0.2 291); + --aqua-100: oklch(95.5% 0.03 215); + --aqua-200: oklch(91% 0.06 215); + --aqua-400: oklch(77.5% 0.13 222); + --aqua-700: oklch(48% 0.105 226); + + /* Light: daytime. */ + --ground: oklch(97.65% 0.005 274.97); + --surface: oklch(99.6% 0.002 280); + --raised: oklch(95.2% 0.01 280); + --line: oklch(90.5% 0.014 280); + --line-strong: oklch(83% 0.02 280); + --ink: oklch(24% 0.05 292); + --text: oklch(37% 0.034 288); + --muted: oklch(49% 0.026 286); + --accent: var(--iris-500); + --accent-ink: var(--iris-700); + --accent-soft: var(--iris-100); + --on-ink: oklch(98.5% 0.006 290); + --glow-a: var(--iris-200); + --glow-b: var(--iris-500); + /* Text and icons sitting on the glow gradient. */ + --on-glow: var(--ink); + --voice-0: var(--iris-700); + --voice-1: var(--aqua-700); + --media-ground: oklch(19% 0.03 280); + --shadow-soft: 0 1px 2px oklch(28% 0.05 290 / 0.06), + 0 10px 30px -12px oklch(28% 0.06 290 / 0.22); + --shadow-float: 0 2px 6px oklch(20% 0.05 290 / 0.12), + 0 24px 60px -18px oklch(20% 0.07 290 / 0.45); + + --font-ui: var(--astro-font-familjen), ui-sans-serif, system-ui, sans-serif; + --font-display: var(--font-ui); + --font-voice-0: var(--astro-font-archivo), var(--font-ui); + --font-voice-1: var(--astro-font-young-serif), ui-serif, Georgia, serif; + + --ease-out: cubic-bezier(0.16, 1, 0.3, 1); + /* The gradient outline's own curve, carried over from the original + button: a slow start, a confident middle, a soft landing. */ + --ease-halo: linear( + 0 0%, + 0.0027 3.64%, + 0.0106 7.29%, + 0.0425 14.58%, + 0.0957 21.87%, + 0.1701 29.16%, + 0.2477 35.19%, + 0.3401 41.23%, + 0.5982 55.18%, + 0.7044 61.56%, + 0.7987 68.28%, + 0.875 75%, + 0.9297 81.25%, + 0.9687 87.5%, + 0.9922 93.75%, + 1 100% + ); + --ease-spring: linear( + 0, + 0.009, + 0.035 2.1%, + 0.141 4.4%, + 0.723 12.9%, + 0.938 16.7%, + 1.017 19.4%, + 1.067, + 1.089 24.6%, + 1.085 27.1%, + 1.04 33.4%, + 1.007 41.2%, + 0.995 50.6%, + 1.001 70.4%, + 1 + ); + + --radius: 8px; + --radius-lg: 14px; + /* Component radii, nested concentrically: an inner radius is its + container's radius minus the inset between them. */ + --r-thumb: 12px; + --r-row: 16px; + --r-tile: 20px; + --r-tray: 24px; + --r-card: 28px; + /* The hairline drawn over every image and portrait, so light and dark art + meet the page with the same edge. */ + --hairline: color-mix(in oklch, var(--ink) 10%, transparent); + /* Colour and fill changes on small controls. */ + --quick: 150ms cubic-bezier(0.4, 0, 0.2, 1); + --rail-w: 0px; + --topbar-h: 60px; + --tabbar-h: calc(62px + env(safe-area-inset-bottom)); + --dock-h: 68px; + /* The page's side margin, and never less than a landscape phone's notch + or rounded corners (viewport-fit=cover runs the page under them), so + everything set in from the edges by it clears them. */ + --gutter: max( + clamp(16px, 3.2vw, 48px), + env(safe-area-inset-left), + env(safe-area-inset-right) + ); + + color-scheme: light; +} + +@media (prefers-color-scheme: dark) { + :root { + /* Dark: night. */ + --ground: oklch(13.85% 0.025 273.24); + --surface: oklch(17.4% 0.025 277); + --raised: oklch(21.57% 0.029 280.68); + --line: oklch(25.5% 0.035 272); + --line-strong: oklch(33% 0.045 274); + --ink: oklch(97.65% 0.005 274.97); + --text: oklch(83% 0.016 266); + --muted: oklch(71% 0.02 264); + --accent: var(--aqua-400); + --accent-ink: var(--aqua-200); + --accent-soft: oklch(26% 0.05 225); + --on-ink: oklch(16% 0.03 270); + --glow-a: var(--aqua-400); + --glow-b: var(--aqua-200); + --on-glow: var(--on-ink); + --voice-0: var(--iris-300); + --voice-1: var(--aqua-200); + --media-ground: oklch(9% 0.02 273); + --shadow-soft: 0 1px 2px oklch(0% 0 0 / 0.3), + 0 12px 32px -12px oklch(0% 0 0 / 0.6); + --shadow-float: 0 2px 8px oklch(0% 0 0 / 0.35), + 0 28px 70px -18px oklch(0% 0 0 / 0.75); + color-scheme: dark; + } +} + +@media (min-width: 1024px) { + :root { + --rail-w: 272px; + --dock-h: 84px; + } +} + +/* ---------- Browser surfaces ---------- */ + +html { + background: var(--ground); + scrollbar-color: var(--line-strong) transparent; + -webkit-text-size-adjust: 100%; +} + +body { + margin: 0; + background: var(--ground); + color: var(--text); + font-family: var(--font-ui); + font-size: 1rem; + line-height: 1.55; + -webkit-font-smoothing: antialiased; + caret-color: var(--accent); + font-variant-numeric: tabular-nums; +} + +::selection { + background: var(--accent); + color: var(--on-ink); +} + +:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 3px; +} + +a { + color: inherit; + text-decoration-thickness: 1px; + text-underline-offset: 0.2em; +} + +h1, +h2, +h3 { + color: var(--ink); + text-wrap: balance; +} + +p { + text-wrap: pretty; +} + +/* The original pill: a 1px gradient-ready border around a padded label. */ +.btn { + display: inline-flex; + align-items: center; + justify-content: center; + padding: 1px; + border: 1px solid transparent; + border-radius: 999px; + background: var(--surface); + background-clip: padding-box; + color: var(--ink); + font-weight: 700; + font-size: 0.875rem; + box-shadow: 0 1px 2px oklch(91.6% 0.021 250 / 0.9); + cursor: pointer; + text-decoration: none; +} + +@media (prefers-color-scheme: dark) { + .btn { + background: var(--raised); + background-clip: padding-box; + box-shadow: + 0 4px 6px -1px oklch(0% 0 0 / 0.25), + 0 2px 4px -2px oklch(0% 0 0 / 0.25); + } +} + +.sr-only { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + margin: -1px; + overflow: hidden; + clip: rect(0, 0, 0, 0); + white-space: nowrap; + border: 0; +} + +/* Reduced motion: no transitions at all. (A 1ms duration would make every + element transition every property that changes, since transition-property + defaults to all: one rail toggle made 173 transitions in Chrome and 9,778 + in WebKit.) Animations keep a 1ms run so their events still fire. */ +@media (prefers-reduced-motion: reduce) { + *, + *::before, + *::after { + animation-duration: 1ms !important; + animation-iteration-count: 1 !important; + transition-duration: 0s !important; + transition-delay: 0s !important; + scroll-behavior: auto !important; + } +} diff --git a/packages/starpod/src/svgs/404-dark.svg b/packages/starpod/src/svgs/404-dark.svg index 4d960061..ffe9ab92 100644 --- a/packages/starpod/src/svgs/404-dark.svg +++ b/packages/starpod/src/svgs/404-dark.svg @@ -13,7 +13,7 @@ - + @@ -46,7 +46,7 @@ - + @@ -76,7 +76,7 @@ - + diff --git a/packages/starpod/src/svgs/404-light.svg b/packages/starpod/src/svgs/404-light.svg index f6f93591..6410d0a1 100644 --- a/packages/starpod/src/svgs/404-light.svg +++ b/packages/starpod/src/svgs/404-light.svg @@ -13,7 +13,7 @@ - + @@ -45,7 +45,7 @@ - + @@ -75,7 +75,7 @@ - + diff --git a/packages/starpod/src/svgs/apple.svg b/packages/starpod/src/svgs/apple.svg index 562b49fa..77b22718 100644 --- a/packages/starpod/src/svgs/apple.svg +++ b/packages/starpod/src/svgs/apple.svg @@ -1,5 +1,5 @@ - + diff --git a/packages/starpod/src/svgs/overcast.svg b/packages/starpod/src/svgs/overcast.svg index b7bcc27b..c8846c22 100644 --- a/packages/starpod/src/svgs/overcast.svg +++ b/packages/starpod/src/svgs/overcast.svg @@ -1,5 +1,5 @@ - + diff --git a/packages/starpod/src/svgs/pocket-casts.svg b/packages/starpod/src/svgs/pocket-casts.svg index fc2f36da..f06bbed9 100644 --- a/packages/starpod/src/svgs/pocket-casts.svg +++ b/packages/starpod/src/svgs/pocket-casts.svg @@ -1,4 +1,4 @@ - + diff --git a/packages/starpod/src/svgs/spotify.svg b/packages/starpod/src/svgs/spotify.svg index 7ec913d5..7b5ee4f9 100644 --- a/packages/starpod/src/svgs/spotify.svg +++ b/packages/starpod/src/svgs/spotify.svg @@ -1,5 +1,5 @@ - + diff --git a/packages/starpod/src/svgs/ufo-dark.svg b/packages/starpod/src/svgs/ufo-dark.svg index 4db58984..4d737c30 100644 --- a/packages/starpod/src/svgs/ufo-dark.svg +++ b/packages/starpod/src/svgs/ufo-dark.svg @@ -1,13 +1,13 @@ - + - + @@ -22,14 +22,14 @@ - + - + @@ -53,7 +53,7 @@ - + @@ -86,7 +86,7 @@ - + @@ -94,7 +94,7 @@ - + diff --git a/packages/starpod/src/svgs/ufo-light.svg b/packages/starpod/src/svgs/ufo-light.svg index 3441d53f..e3b3c527 100644 --- a/packages/starpod/src/svgs/ufo-light.svg +++ b/packages/starpod/src/svgs/ufo-light.svg @@ -1,13 +1,13 @@ - + - + @@ -21,14 +21,14 @@ - + - + @@ -51,7 +51,7 @@ - + @@ -84,7 +84,7 @@ - + @@ -92,7 +92,7 @@ - + diff --git a/packages/starpod/src/svgs/youtube.svg b/packages/starpod/src/svgs/youtube.svg index 821248ae..d9870a56 100644 --- a/packages/starpod/src/svgs/youtube.svg +++ b/packages/starpod/src/svgs/youtube.svg @@ -1,4 +1,4 @@ - - + + diff --git a/packages/starpod/src/utils/config.ts b/packages/starpod/src/utils/config.ts index 3a4ba681..0d9361ee 100644 --- a/packages/starpod/src/utils/config.ts +++ b/packages/starpod/src/utils/config.ts @@ -4,6 +4,7 @@ import { nonEmpty, object, optional, + picklist, pipe, safeParse, string, @@ -38,6 +39,10 @@ export type Host = { website?: string; }; +/** Icons a nav link can show beside its label. */ +export const NAV_LINK_ICONS = ['external', 'heart', 'link', 'sponsor', 'store'] as const; +export type NavLinkIcon = (typeof NAV_LINK_ICONS)[number]; + export type NavLink = { /** * Link text, e.g. "Store". @@ -48,6 +53,11 @@ export type NavLink = { * custom page you added to your site's src/pages/. */ href: string; + /** + * The icon beside the label. Defaults to `external` (an outward arrow) for + * URLs and `link` for local pages. + */ + icon?: NavLinkIcon; }; export type StarpodConfig = { @@ -104,7 +114,10 @@ const HostSchema: GenericSchema = object({ const NavLinkSchema: GenericSchema = object({ label: pipe(string(), nonEmpty('every link needs a label')), - href: pipe(string(), nonEmpty('every link needs an href')) + href: pipe(string(), nonEmpty('every link needs an href')), + icon: optional( + picklist(NAV_LINK_ICONS, `link icon must be one of: ${NAV_LINK_ICONS.join(', ')}`) + ) }); const StarpodConfigSchema: GenericSchema = object({ diff --git a/src/img/sponsors/cascadiajs.svg b/src/img/sponsors/cascadiajs.svg index 6decac21..4a998585 100644 --- a/src/img/sponsors/cascadiajs.svg +++ b/src/img/sponsors/cascadiajs.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/img/sponsors/code-rabbit.svg b/src/img/sponsors/code-rabbit.svg index 7a3cc104..c2b8d09f 100644 --- a/src/img/sponsors/code-rabbit.svg +++ b/src/img/sponsors/code-rabbit.svg @@ -1,3 +1,3 @@ - + diff --git a/src/img/sponsors/gitkraken.svg b/src/img/sponsors/gitkraken.svg index fd1434ba..d9cd7962 100644 --- a/src/img/sponsors/gitkraken.svg +++ b/src/img/sponsors/gitkraken.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/img/sponsors/norlan.svg b/src/img/sponsors/norlan.svg index 2b27c894..8ec5edc1 100644 --- a/src/img/sponsors/norlan.svg +++ b/src/img/sponsors/norlan.svg @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/src/img/sponsors/warp.svg b/src/img/sponsors/warp.svg index a552468d..90311b83 100644 --- a/src/img/sponsors/warp.svg +++ b/src/img/sponsors/warp.svg @@ -1,4 +1,4 @@ - - + + diff --git a/tests/unit/cast.test.ts b/tests/unit/cast.test.ts index 8add384c..42441b2f 100644 --- a/tests/unit/cast.test.ts +++ b/tests/unit/cast.test.ts @@ -1,5 +1,14 @@ import { describe, expect, it } from 'vitest'; -import { sortCast, voiceFor } from 'starpod/src/lib/cast'; +import { + factGivesCount, + matchNames, + matchPageNames, + ordinal, + personFact, + sortCast, + speakerFor, + voiceFor +} from 'starpod/src/lib/cast'; const person = (name: string, isHost: boolean) => ({ id: name, img: null, isHost, name }); @@ -83,3 +92,161 @@ describe('voiceFor', () => { expect(voiceFor('Robbie Wagner', null)).toBeUndefined(); }); }); + +describe('ordinal', () => { + it('suffixes like English does, teens included', () => { + expect([1, 2, 3, 4, 11, 12, 13, 21, 22, 101, 111].map(ordinal)).toEqual([ + '1st', + '2nd', + '3rd', + '4th', + '11th', + '12th', + '13th', + '21st', + '22nd', + '101st', + '111th' + ]); + }); +}); + +describe('personFact', () => { + it("gives a host's tally", () => { + expect(personFact({ appearance: 40, count: 106, host: true })).toBe( + 'Host · 106 episodes' + ); + }); + + it("marks a guest's first time on the show", () => { + expect(personFact({ appearance: 1, count: 1, host: false })).toBe( + 'First time on the show' + ); + }); + + it('counts a returning guest from where they first appeared', () => { + expect( + personFact({ appearance: 3, count: 3, first: 'Ep 112', host: false }) + ).toBe('3rd appearance · first on Ep 112'); + expect(personFact({ appearance: 1, count: 3, host: false })).toBe( + 'First of 3 appearances' + ); + }); + + it('falls back to role and tally away from an episode', () => { + expect(personFact({ count: 1, host: false })).toBe('Guest · 1 episode'); + expect(personFact({ count: 106, host: true })).toBe('Host · 106 episodes'); + }); +}); + +describe('factGivesCount', () => { + it('is true wherever the fact line says how many episodes', () => { + expect(factGivesCount({ appearance: 40, count: 106, host: true })).toBe( + true + ); + expect(factGivesCount({ count: 4, host: false })).toBe(true); + expect(factGivesCount({ appearance: 1, count: 1, host: false })).toBe(true); + expect(factGivesCount({ appearance: 1, count: 3, host: false })).toBe(true); + }); + + it("is false for a returning guest's ordinal, which doesn't", () => { + expect(factGivesCount({ appearance: 3, count: 5, host: false })).toBe( + false + ); + }); +}); + +describe('speakerFor', () => { + const speakers = ['Robbie Wagner', 'Jason', 'Shruti Kapoor']; + + it("finds a host by the configured name or id the transcript doesn't use", () => { + expect(speakerFor('RobbieTheWagner', speakers)).toBe('Robbie Wagner'); + expect(speakerFor('robbiethewagner', speakers)).toBe('Robbie Wagner'); + expect(speakerFor('Jason Lengstorf', speakers)).toBe('Jason'); + }); + + it("prefers the transcript's exact label, then the closest name", () => { + expect(speakerFor('Shruti Kapoor', speakers)).toBe('Shruti Kapoor'); + expect(speakerFor('Adam Argyle', ['Adam Rackis', 'Adam Argyle'])).toBe('Adam Argyle'); + // A shared surname alone isn't enough for one name on its own. + expect(speakerFor('Chuck Carpenter', ['Charles William Carpenter III', 'Robbie Wagner'])).toBeUndefined(); + }); + + it('leaves someone who never speaks unmatched', () => { + expect(speakerFor('Dave Rupert', speakers)).toBeUndefined(); + }); +}); + +describe('matchNames', () => { + it("gives each episode's people their own speaker, not a namesake's (Ep 184, Ep 164)", () => { + const ep184 = matchNames( + ['RobbieTheWagner', 'Charles William Carpenter III', 'Travis Wagner'], + ['Travis Wagner', 'Chuck Carpenter', 'Robbie Wagner', 'Intro'], + { surnames: true } + ); + expect(Object.fromEntries(ep184)).toEqual({ + RobbieTheWagner: 'Robbie Wagner', + 'Charles William Carpenter III': 'Chuck Carpenter', + 'Travis Wagner': 'Travis Wagner' + }); + const ep164 = matchNames( + ['RobbieTheWagner', 'Charles William Carpenter III', 'Lane Wagner'], + ['Chuck Carpenter', 'Lane Wagner', 'Robbie Wagner', 'Promo'], + { surnames: true } + ); + expect(ep164.get('Lane Wagner')).toBe('Lane Wagner'); + expect(ep164.get('RobbieTheWagner')).toBe('Robbie Wagner'); + }); + + it('lights no other guest when the hosts speak, anywhere on the site', () => { + const speakers = ['Robbie Wagner', 'Adam Argyle']; + const guests = ['Travis Wagner', 'Lane Wagner', 'Adam Rackis', 'Adam Stacoviak']; + expect(matchNames(guests, speakers).size).toBe(0); + expect(matchNames(guests, speakers, { surnames: true }).size).toBe(0); + expect(Object.fromEntries(matchNames(['RobbieTheWagner', 'Adam Argyle', ...guests], speakers))).toEqual({ + RobbieTheWagner: 'Robbie Wagner', + 'Adam Argyle': 'Adam Argyle' + }); + }); + + it('refuses a guess between equals', () => { + expect(matchNames(['Adam Argyle', 'Adam Rackis'], ['Adam']).size).toBe(0); + expect(matchNames(['Adam Argyle'], ['Adam']).get('Adam Argyle')).toBe('Adam'); + }); + + it("takes the voice from the person's own speaker, given the cast", () => { + const cues = [ + { s: 0, t: 'a', n: 'Travis Wagner', v: 0 }, + { s: 1, t: 'b', n: 'Chuck Carpenter', v: 1 }, + { s: 2, t: 'c', n: 'Robbie Wagner', v: 2 } + ]; + const cast = ['RobbieTheWagner', 'Charles William Carpenter III', 'Travis Wagner']; + expect(voiceFor('Travis Wagner', cues, cast)).toBe(0); + expect(voiceFor('Charles William Carpenter III', cues, cast)).toBe(1); + expect(voiceFor('RobbieTheWagner', cues, cast)).toBeUndefined(); + }); +}); + +describe('matchPageNames', () => { + const speakers = ['Robbie Wagner', 'Adam Argyle']; + const guests = ['Travis Wagner', 'Lane Wagner', 'Adam Rackis', 'Adam Stacoviak']; + + it("lights no guest for a host's lines, on any page", () => { + expect(matchPageNames(guests, speakers).size).toBe(0); + }); + + it('lights every name a page gives the speaker, and only theirs', () => { + const names = ['RobbieTheWagner', 'Robbie Wagner', 'robbiethewagner', 'Adam Argyle', ...guests]; + expect(Object.fromEntries(matchPageNames(names, speakers))).toEqual({ + RobbieTheWagner: 'Robbie Wagner', + 'Robbie Wagner': 'Robbie Wagner', + robbiethewagner: 'Robbie Wagner', + 'Adam Argyle': 'Adam Argyle' + }); + }); + + it('keeps a first name that could be either of two people to itself', () => { + const matched = matchPageNames(['Adam Argyle', 'Adam Rackis', 'Adam'], ['Adam Argyle']); + expect(Object.fromEntries(matched)).toEqual({ 'Adam Argyle': 'Adam Argyle' }); + }); +}); diff --git a/tests/unit/config.test.ts b/tests/unit/config.test.ts index a31af246..1f72fc34 100644 --- a/tests/unit/config.test.ts +++ b/tests/unit/config.test.ts @@ -28,6 +28,22 @@ describe('defineStarpodConfig', () => { expect(config.links).toHaveLength(1); }); + it('accepts a known nav link icon and rejects an unknown one', () => { + expect( + defineStarpodConfig({ + ...validConfig, + links: [{ label: 'Sponsor', href: '/sponsor', icon: 'sponsor' }] + }).links?.[0].icon + ).toBe('sponsor'); + expect(() => + validateStarpodConfig({ + ...validConfig, + // @ts-expect-error: not one of the built-in icons + links: [{ label: 'Odd', href: '/odd', icon: 'rocket' }] + }) + ).toThrow(/link icon must be one of/); + }); + it('rejects a non-URL rssFeed and names the field', () => { expect(() => validateStarpodConfig({ ...validConfig, rssFeed: 'not a url' }) diff --git a/tests/unit/cues.test.ts b/tests/unit/cues.test.ts index dfc9b504..073312f3 100644 --- a/tests/unit/cues.test.ts +++ b/tests/unit/cues.test.ts @@ -1,6 +1,5 @@ import { describe, expect, it } from 'vitest'; import { - cueText, jsonSegments, mergeIntoLines, parseMarkdownCues @@ -79,16 +78,3 @@ describe('jsonSegments', () => { ).toEqual([{ start: 2, text: 'Hi', speaker: undefined }]); }); }); - -describe('cueText', () => { - it('takes the speaker from a voice span and decodes references once', () => { - expect(cueText('Ship it & see &lt;3')).toEqual({ - text: 'Ship it & see <3', - speaker: 'Robbie Wagner' - }); - }); - - it('strips styling tags from captions without a speaker', () => { - expect(cueText('Hello there')).toEqual({ text: 'Hello there', speaker: undefined }); - }); -}); diff --git a/tests/unit/propflip.test.ts b/tests/unit/propflip.test.ts new file mode 100644 index 00000000..5f7be542 --- /dev/null +++ b/tests/unit/propflip.test.ts @@ -0,0 +1,111 @@ +import { afterEach, describe, expect, it } from 'vitest'; +import { + flip, + flipLayout, + registerFlipTargets +} from 'starpod/src/motion/propflip'; + +// A box whose rect is whatever the test says it is right now. +function box(rect: { left: number; top: number }, log?: string[], name = '') { + const el = document.createElement('div'); + el.getBoundingClientRect = () => { + log?.push(`measure ${name}`); + return { ...rect, width: 100, height: 50 } as DOMRect; + }; + document.body.append(el); + return { el, rect }; +} + +describe('flipLayout registrations', () => { + const off: Array<() => void> = []; + afterEach(() => { + off.splice(0).forEach((unregister) => unregister()); + document.body.replaceChildren(); + }); + + it('runs a settle after the change and before the boxes are measured again', () => { + const log: string[] = []; + const card = box({ left: 0, top: 0 }, log, 'card'); + off.push( + registerFlipTargets(() => [card.el], { + settle: () => { + log.push('settle'); + // The size the feature derives from the new layout. + card.rect.top = 40; + } + }) + ); + + const moves = flipLayout(() => { + log.push('mutate'); + }); + + expect(log).toEqual(['measure card', 'mutate', 'settle', 'measure card']); + // The move is measured from the settled box, not a stale one. + expect(moves.map((m) => m.last.top)).toEqual([40]); + }); + + it('changes nothing for a registration without options', () => { + const log: string[] = []; + const card = box({ left: 0, top: 0 }, log, 'card'); + off.push(registerFlipTargets(() => [card.el])); + + const moves = flipLayout(() => { + log.push('mutate'); + card.rect.left = 30; + }); + + expect(log).toEqual(['measure card', 'mutate', 'measure card']); + expect(moves.map((m) => m.last.left)).toEqual([30]); + }); + + it("measures a viewport registration's boxes in the viewport, the rest against the frame", () => { + const frame = box({ left: 200, top: 0 }); + const inColumn = box({ left: 210, top: 0 }); + const held = box({ left: 210, top: 0 }); + off.push(registerFlipTargets(() => [inColumn.el])); + off.push(registerFlipTargets(() => [held.el], { viewport: true })); + + const moves = flipLayout( + () => { + inColumn.rect.top = 10; + held.rect.top = 10; + }, + { frame: () => frame.el } + ); + + const last = new Map(moves.map((m) => [m.el, m.last])); + expect(last.get(inColumn.el)!.left).toBe(10); + expect(last.get(held.el)!.left).toBe(210); + }); +}); + +describe('flip commit', () => { + afterEach(() => document.body.replaceChildren()); + + it('holds only the flip while it writes the lie: what --also lists keeps running', () => { + const card = box({ left: 0, top: 0 }); + // What the element's transition is each time the lie or the play is written. + const seen: Array<[string, string]> = []; + const setProperty = card.el.style.setProperty.bind(card.el.style); + card.el.style.setProperty = (name: string, value: string | null) => { + if (name === '--tx') { + seen.push([value ?? '', card.el.style.transition]); + } + setProperty(name, value); + }; + + const moves = flip([card.el], () => { + card.rect.left = 40; + }); + + expect(moves).toHaveLength(1); + // The lie (-40) is written under the element's own --also list, never + // `transition: none`, which would cancel a layout transition the update + // started; the play (0) under its full list again. + expect(seen).toEqual([ + ['-40', 'var(--also, visibility 0s)'], + ['0', ''] + ]); + }); +}); diff --git a/tests/unit/transcript.test.ts b/tests/unit/transcript.test.ts index 4481490a..2d393ae6 100644 --- a/tests/unit/transcript.test.ts +++ b/tests/unit/transcript.test.ts @@ -2,7 +2,8 @@ import { afterEach, describe, expect, it, vi } from 'vitest'; import { getRssTranscriptParagraphs, - getRssTranscriptText + getRssTranscriptText, + parseCues } from 'starpod/src/lib/transcript'; import { getRssCues } from 'starpod/src/lib/cues'; import type { Episode } from 'starpod/src/lib/rss'; @@ -128,6 +129,33 @@ describe('getRssTranscriptParagraphs', () => { ]); }); + it('decodes the character references in cue text exactly once', async () => { + // WebVTT escapes &, < and > in cue text; the page escapes its text again + // when it renders, so leaving them encoded showed "Web & Whatnot". + mockFetch({ + body: [ + 'WEBVTT', + '', + '1', + '00:00:01.000 --> 00:00:03.000', + 'Whiskey, Web & Whatnot: <b> isn't "bold" > 1', + '', + '2', + '00:00:03.000 --> 00:00:05.000', + 'Written &lt; once & done' + ].join('\n') + }); + const paragraphs = await getRssTranscriptParagraphs( + makeEpisode({ transcriptType: 'text/vtt' }) + ); + expect(paragraphs).toEqual([ + { + start: 1, + text: 'Whiskey, Web & Whatnot: isn\'t "bold" > 1 Written < once & done' + } + ]); + }); + it('parses SRT cues (comma milliseconds, HH:MM:SS) with start times', async () => { const longCue = 'word '.repeat(140).trim(); // forces a paragraph break const srt = [ @@ -281,3 +309,40 @@ describe('shared transcript download', () => { ]); }); }); + +describe('parseCues', () => { + it('takes the speaker from a WebVTT voice span and drops every tag', () => { + expect( + parseCues( + 'WEBVTT\n\n00:00:02.500 --> 00:00:04.000\nIt's 87% & rising' + ) + ).toEqual([{ start: 2.5, text: "It's 87% & rising", speaker: 'Jev' }]); + }); + + it('decodes the voice name too', () => { + expect( + parseCues('WEBVTT\n\n00:00:01.000 --> 00:00:02.000\nHi') + ).toEqual([{ start: 1, text: 'Hi', speaker: 'Tom & Jerry' }]); + }); + + it("strips only cue markup, keeping SRT's bare < and > as text", () => { + expect( + parseCues('1\n00:00:01,000 --> 00:00:02,000\nIf x < 5 and y > 3, then stop.') + ).toEqual([{ start: 1, text: 'If x < 5 and y > 3, then stop.' }]); + expect( + parseCues('WEBVTT\n\n00:00:01.000 --> 00:00:03.000\nWord<00:00:01.500> by word') + ).toEqual([{ start: 1, text: 'Word by word' }]); + }); + + it('decodes each reference once', () => { + expect( + parseCues('WEBVTT\n\n00:00:01.000 --> 00:00:02.000\nShip it & see &lt;3') + ).toEqual([{ start: 1, text: 'Ship it & see <3' }]); + }); + + it('never turns escaped text into a tag', () => { + expect( + parseCues('WEBVTT\n\n00:00:01.000 --> 00:00:02.000\n<v Mallory> hi') + ).toEqual([{ start: 1, text: ' hi' }]); + }); +}); From f880c10125ca84d14590bece159c02c7f6de4648 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Sun, 22 Nov 2026 13:18:07 -0500 Subject: [PATCH 02/97] Address CodeRabbit on the foundations - A shared middle name is no longer taken for a shared surname. - Page names group full names before short aliases, so input order can't merge two Adams. - SRT tags are stripped from timed cues. - The reduced-motion reset writes identity with transitions off. - Document that flip targets must not nest. Co-Authored-By: Claude Opus 5.5 --- packages/starpod/src/lib/cast.ts | 28 ++++++++++++++++++++----- packages/starpod/src/lib/transcript.ts | 10 ++++----- packages/starpod/src/motion/propflip.ts | 12 +++++++++-- tests/unit/cast.test.ts | 19 ++++++++++++++--- tests/unit/propflip.test.ts | 21 +++++++++++++++++++ tests/unit/transcript.test.ts | 3 +++ 6 files changed, 78 insertions(+), 15 deletions(-) diff --git a/packages/starpod/src/lib/cast.ts b/packages/starpod/src/lib/cast.ts index 07a7dac1..8a54449c 100644 --- a/packages/starpod/src/lib/cast.ts +++ b/packages/starpod/src/lib/cast.ts @@ -49,6 +49,21 @@ const tokens = (name: string) => .map((token) => token.replace(/[^\p{L}\p{N}]/gu, '')) .filter(Boolean); +const SUFFIXES = new Set(['jr', 'sr', 'ii', 'iii', 'iv']); + +/** + * Whether two names' tokens after the first share a surname: one name's last + * (suffixes like "III" aside) appears in the other's. A middle name the two + * happen to share ("Adam Michael Rackis", "Adam Michael Argyle") is not one. + */ +function shareSurname(aRest: Array, bRest: Array) { + const last = (rest: Array) => + rest.filter((token) => !SUFFIXES.has(token)).at(-1) ?? ''; + const a = last(aRest); + const b = last(bRest); + return (a.length >= 4 && bRest.includes(a)) || (b.length >= 4 && aRest.includes(b)); +} + /** * Do these two names refer to the same person? Loosely: their first names * start the same way ("Robbie" ~ "RobbieTheWagner"), or they share a surname @@ -60,7 +75,7 @@ export function sameName(a: string, b: string) { if (aFirst.length >= 3 && bFirst.length >= 3 && (aFirst.startsWith(bFirst) || bFirst.startsWith(aFirst))) { return true; } - return aRest.some((token) => token.length >= 4 && bRest.includes(token)); + return shareSurname(aRest, bRest); } /** @@ -89,9 +104,7 @@ function likeness(a: string, b: string, surnames: boolean) { aFirst.length >= 3 && bFirst.length >= 3 && (aFirst.startsWith(bFirst) || bFirst.startsWith(aFirst)); - const surname = aRest.some( - (token) => token.length >= 4 && bRest.includes(token) - ); + const surname = shareSurname(aRest, bRest); if (firsts && surname) { return 3; } @@ -175,7 +188,12 @@ export function matchNames( */ export function matchPageNames(names: Array, speakers: Array) { const people: Array> = []; - for (const name of new Set(names)) { + // Full names first, so each person is grouped before a short alias + // ("Adam") that could be either of two of them tries to join one. + const longestFirst = [...new Set(names)].sort( + (a, b) => tokens(b).length - tokens(a).length + ); + for (const name of longestFirst) { const same = people.filter((person) => person.some((other) => likeness(name, other, false) >= 2) ); diff --git a/packages/starpod/src/lib/transcript.ts b/packages/starpod/src/lib/transcript.ts index bff015b1..c45ddd43 100644 --- a/packages/starpod/src/lib/transcript.ts +++ b/packages/starpod/src/lib/transcript.ts @@ -184,12 +184,12 @@ function parseTranscript( return stripped ? splitParagraphs(stripped) : null; } -// What a WebVTT cue's markup looks like: a class, italic, bold, underline, -// ruby, voice or language span (``, ``, ``…) or a -// timestamp (`<00:01:02.500>`). Anything else in angle brackets, like SRT's -// unescaped "x < 5 and y > 3", is text. +// What a cue's markup looks like: a WebVTT class, italic, bold, underline, +// ruby, voice or language span (``, ``, ``…), SRT's +// ``, or a timestamp (`<00:01:02.500>`). Anything else in +// angle brackets, like SRT's unescaped "x < 5 and y > 3", is text. const CUE_TAG = - /<\/?(?:[cibuv]|ruby|rt|lang)(?:\.[^\s<>]*)?(?:\s[^<>]*)?>|<(?:\d+:)?\d{2}:\d{2}\.\d{3}>/g; + /<\/?(?:[cibuv]|ruby|rt|lang|font)(?:\.[^\s<>]*)?(?:\s[^<>]*)?>|<(?:\d+:)?\d{2}:\d{2}\.\d{3}>/g; /** * Parse WebVTT/SRT cue blocks into `{ start, text, speaker }` entries, diff --git a/packages/starpod/src/motion/propflip.ts b/packages/starpod/src/motion/propflip.ts index 776f50eb..78c530ef 100644 --- a/packages/starpod/src/motion/propflip.ts +++ b/packages/starpod/src/motion/propflip.ts @@ -63,7 +63,8 @@ function setProps(el: HTMLElement, { tx, ty, sx, sy }: FlipProps) { * The batch from the article: measure First, hold the transition, change the * DOM, measure, invert, release. * - * Pass elements parents-first. "First" is the visual rect, so calling this + * Targets must not nest: each is inverted on its own, so a child flipped with + * its parent would carry the parent's invert twice. "First" is the visual rect, so calling this * mid-flight just works. The invert is measured against the layout as it is * right after the change, so anything Anchored Auto Layout is already * transitioning (width, height, left, top) reads as "no difference" and @@ -199,6 +200,7 @@ function commit(moves: FlipMove[]) { * does: it reads each element's live --tx/--ty/--sx/--sy, strips that * transform from its rect to find the layout box, then inverts from the exact * pixels on screen. Elements already in flight never get a stagger re-applied. + * As with propFlip(), targets must not nest. */ export function flip( targets: Iterable, @@ -208,10 +210,16 @@ export function flip( const els = [...targets].filter((el): el is HTMLElement => Boolean(el)); if (reducedMotion()) { update(); + // Reset with transitions off: `data-motion="reduce"` alone doesn't stop + // the stylesheet's, so a held box would otherwise glide home. els.forEach((el) => { - el.style.transition = ''; + el.style.transition = 'none'; setProps(el, IDENTITY); }); + if (els.length) { + void document.body.offsetHeight; + } + els.forEach((el) => (el.style.transition = '')); return []; } const before = els.map((el) => { diff --git a/tests/unit/cast.test.ts b/tests/unit/cast.test.ts index 42441b2f..5abec09e 100644 --- a/tests/unit/cast.test.ts +++ b/tests/unit/cast.test.ts @@ -172,6 +172,11 @@ describe('speakerFor', () => { expect(speakerFor('Chuck Carpenter', ['Charles William Carpenter III', 'Robbie Wagner'])).toBeUndefined(); }); + it("doesn't take a shared middle name for a shared surname", () => { + expect(speakerFor('Adam Michael Rackis', ['Adam Michael Argyle'])).toBeUndefined(); + expect(speakerFor('Rob Wagner', ['Robbie James Wagner Jr'])).toBe('Robbie James Wagner Jr'); + }); + it('leaves someone who never speaks unmatched', () => { expect(speakerFor('Dave Rupert', speakers)).toBeUndefined(); }); @@ -245,8 +250,16 @@ describe('matchPageNames', () => { }); }); - it('keeps a first name that could be either of two people to itself', () => { - const matched = matchPageNames(['Adam Argyle', 'Adam Rackis', 'Adam'], ['Adam Argyle']); - expect(Object.fromEntries(matched)).toEqual({ 'Adam Argyle': 'Adam Argyle' }); + it('keeps a first name that could be either of two people to itself, in any order', () => { + const names = ['Adam Argyle', 'Adam Rackis', 'Adam']; + const orders = [0, 1, 2].flatMap((a) => + [0, 1, 2].flatMap((b) => + [0, 1, 2].filter((c) => new Set([a, b, c]).size === 3).map((c) => [a, b, c]) + ) + ); + for (const order of orders) { + const matched = matchPageNames(order.map((i) => names[i]), ['Adam Argyle']); + expect(Object.fromEntries(matched)).toEqual({ 'Adam Argyle': 'Adam Argyle' }); + } }); }); diff --git a/tests/unit/propflip.test.ts b/tests/unit/propflip.test.ts index 5f7be542..4f9f629a 100644 --- a/tests/unit/propflip.test.ts +++ b/tests/unit/propflip.test.ts @@ -108,4 +108,25 @@ describe('flip commit', () => { ['0', ''] ]); }); + + it('resets a held box with transitions off under data-motion="reduce"', () => { + const card = box({ left: 0, top: 0 }); + card.el.style.setProperty('--tx', '-40'); + const seen: Array<[string, string]> = []; + const setProperty = card.el.style.setProperty.bind(card.el.style); + card.el.style.setProperty = (name: string, value: string | null) => { + if (name === '--tx') { + seen.push([value ?? '', card.el.style.transition]); + } + setProperty(name, value); + }; + document.documentElement.dataset.motion = 'reduce'; + try { + expect(flip([card.el])).toEqual([]); + } finally { + delete document.documentElement.dataset.motion; + } + expect(seen).toEqual([['0', 'none']]); + expect(card.el.style.transition).toBe(''); + }); }); diff --git a/tests/unit/transcript.test.ts b/tests/unit/transcript.test.ts index 2d393ae6..e1226a87 100644 --- a/tests/unit/transcript.test.ts +++ b/tests/unit/transcript.test.ts @@ -332,6 +332,9 @@ describe('parseCues', () => { expect( parseCues('WEBVTT\n\n00:00:01.000 --> 00:00:03.000\nWord<00:00:01.500> by word') ).toEqual([{ start: 1, text: 'Word by word' }]); + expect( + parseCues('1\n00:00:01,000 --> 00:00:02,000\nHello, you') + ).toEqual([{ start: 1, text: 'Hello, you' }]); }); it('decodes each reference once', () => { From 349299100a3c03df488209705dd3232fea77439b Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Fri, 20 Nov 2026 06:40:06 -0500 Subject: [PATCH 03/97] Media engine and the player island The second slice of the media-first redesign (#76). One persistent