Kaleido-Desktop/src/screens/Splash.tsx
Elijah 43c168da95 Address the first beta's bugs and requested changes
Startup now uses the Android iris animation, and playback can continue
in a corner miniplayer while browsing (the video is drawn into a corner
rectangle beneath a matching hole in the page). The player keeps the
window controls, hides its chrome when the pointer leaves, and gains
audio/subtitle tracks, audio sync, source bitrate and playback details
in its options. Subtitles can be styled in Settings with a live preview.
Categories replace Collections, the A–Z rail magnifies, descriptions
expand in place, downloads can be removed in bulk, and search keeps its
results while typing.

Fixes scroll jank from per-card and scrolling backdrop blurs, the hidden
colour wash, the cubic volume curve, loud theme music, the search focus
ring, a stray nav indicator, Continue Watching previews and the TV Shows
header overlap. Removes the star rating, the duplicate Settings menu
entry and the server settings' Show advanced switch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 18:06:54 -07:00

407 lines
15 KiB
TypeScript

import { useEffect, useRef } from 'react';
import { useSettings } from '../app/settings';
/**
* The cold-start brand sequence, the same as Kaleido for TV: a closed iris lit
* from behind twists open, light catches the facets and the wordmark slides out
* of the mark. Once startup is ready the camera flies through the aperture's
* dark centre, revealing the app drawn beneath (which settles from a slight
* zoom, `html.splash-arrival`).
*/
type Point = { x: number; y: number };
/** CSS-style cubic-bezier easing (x → y). */
function bezier(x1: number, y1: number, x2: number, y2: number) {
const cx = 3 * x1;
const bx = 3 * (x2 - x1) - cx;
const ax = 1 - cx - bx;
const cy = 3 * y1;
const by = 3 * (y2 - y1) - cy;
const ay = 1 - cy - by;
const sx = (t: number) => ((ax * t + bx) * t + cx) * t;
const sy = (t: number) => ((ay * t + by) * t + cy) * t;
const dx = (t: number) => (3 * ax * t + 2 * bx) * t + cx;
return (x: number) => {
if (x <= 0) return 0;
if (x >= 1) return 1;
let t = x;
for (let i = 0; i < 8; i++) {
const err = sx(t) - x;
const d = dx(t);
if (Math.abs(err) < 1e-5 || Math.abs(d) < 1e-6) break;
t -= err / d;
}
t = Math.min(1, Math.max(0, t));
return sy(t);
};
}
const Emphasized = bezier(0.2, 0, 0, 1);
const EmphasizedDecelerate = bezier(0.05, 0.7, 0.1, 1);
const Standard = bezier(0.4, 0, 0.2, 1);
const InOut = bezier(0.45, 0, 0.55, 1);
// A mechanical iris: the blades gather, snap open and overshoot slightly as they lock.
const IrisOpen = bezier(0.55, 0, 0.15, 1);
const IrisTwist = bezier(0.5, 0, 0.18, 1.1);
// Applied in log space: a brief pull back, then an accelerating flight.
const Flight = bezier(0.55, -0.06, 0.8, 0.36);
const phase = (time: number, start: number, end: number) => Math.min(1, Math.max(0, (time - start) / (end - start)));
const mix = (from: number, to: number, amount: number) => from + (to - from) * amount;
// The brand mark's facets, centred on its 64-unit viewport, each with the
// outward normal of its hexagon edge for the iris motion.
const FACETS = (
[
[[33, 4, 55.5, 17, 42.5, 24.5, 33, 19], '#C3E8D3'],
[[56.5, 19, 56.5, 45, 43.5, 37.5, 43.5, 26.5], '#71B9B0'],
[[55.5, 47, 33, 60, 33, 45, 42.5, 39.5], '#3D7C7B'],
[[31, 60, 8.5, 47, 21.5, 39.5, 31, 45], '#D0A977'],
[[7.5, 45, 7.5, 19, 20.5, 26.5, 20.5, 37.5], '#E9D8AE'],
[[8.5, 17, 31, 4, 31, 19, 21.5, 24.5], '#EEF2DD'],
] as [number[], string][]
).map(([pts, color], i) => {
const angle = ((-60 + 60 * i) * Math.PI) / 180;
const points: Point[] = [];
for (let k = 0; k < pts.length; k += 2) points.push({ x: pts[k] - 32, y: pts[k + 1] - 32 });
return { points, color, normal: { x: Math.cos(angle), y: Math.sin(angle) } };
});
// The inner hexagon traced by the facets' inner edges: the aperture the exit flies through.
const INNER_RADIUS = 13.6;
const INNER_APOTHEM = 11.8;
const INTRO_BOX = 132;
// The settled lockup is the header brand scaled up, so it reads as the same mark.
const LOCK_SCALE = 2.75;
const LOCK_BOX = 29 * LOCK_SCALE;
const LOCK_GAP = 7 * LOCK_SCALE;
// Timeline (ms): held at GATHER_END until startup is ready (at most HOLD_MAX),
// complete at INTRO_END; the slow settle runs on to TIMELINE_END.
const GATHER_END = 260;
const INTRO_END = 2260;
const TIMELINE_END = 2900;
const HOLD_MAX = 700;
const EXIT_MS = 640;
const INK = '#090a0c';
const WORDMARK = '#F1F1F1';
const SEA_GLASS = [113, 185, 176];
const rgba = (c: number[], a: number) => `rgba(${c[0]}, ${c[1]}, ${c[2]}, ${Math.max(0, a)})`;
interface Iris {
inward: number;
theta: number;
grow: number;
}
function irisAt(time: number): Iris {
const p = phase(time, 140, 1180);
return { inward: INNER_APOTHEM * (1 - IrisOpen(p)), theta: ((-44 * (1 - IrisTwist(p))) * Math.PI) / 180, grow: mix(0.64, 1, Emphasized(p)) };
}
function facetPath(ctx: CanvasRenderingContext2D, facet: (typeof FACETS)[number], iris: Iris, unit: number, o: Point) {
const c = Math.cos(iris.theta);
const s = Math.sin(iris.theta);
const k = unit * iris.grow;
facet.points.forEach((p, i) => {
const x = p.x - facet.normal.x * iris.inward;
const y = p.y - facet.normal.y * iris.inward;
const px = o.x + (x * c - y * s) * k;
const py = o.y + (x * s + y * c) * k;
if (i === 0) ctx.moveTo(px, py);
else ctx.lineTo(px, py);
});
ctx.closePath();
}
function hexagon(ctx: CanvasRenderingContext2D, o: Point, radius: number) {
for (let i = 0; i < 6; i++) {
const a = ((-90 + 60 * i) * Math.PI) / 180;
const x = o.x + Math.cos(a) * radius;
const y = o.y + Math.sin(a) * radius;
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.closePath();
}
interface Letters {
font: string;
chars: string[];
x: number[];
width: number;
cap: number;
}
function draw(ctx: CanvasRenderingContext2D, w: number, h: number, time: number, q: number, letters: Letters) {
const center = { x: w / 2, y: h / 2 };
ctx.clearRect(0, 0, w, h);
const lockup = Emphasized(phase(time, 1250, 2000));
const lockWidth = LOCK_BOX + LOCK_GAP + letters.width;
const box = mix(INTRO_BOX, LOCK_BOX, lockup);
// A slow push-in keeps the settled frame alive.
const drift = 1 + 0.025 * InOut(phase(time, 1900, 2900));
let cx = mix(center.x, center.x - lockWidth / 2 + LOCK_BOX / 2, lockup);
let cy = center.y;
let zoom = 1;
let textAlpha = 1;
let textShift = 0;
let hole = 0;
if (q > 0) {
zoom = Math.exp(Math.log(52) * Flight(q));
const recenter = Standard(Math.min(1, q / 0.75));
cx = mix(cx, center.x, recenter);
cy = mix(cy, center.y, recenter);
textAlpha = 1 - Standard(phase(q, 0, 0.4));
textShift = -14 * Standard(phase(q, 0, 0.4));
hole = InOut(phase(q, 0.12, 0.5));
}
const unit = (box / 64) * drift * zoom;
const o = { x: cx, y: cy };
// The surface: ink everywhere, with the aperture's centre cut away on exit.
ctx.globalCompositeOperation = 'source-over';
ctx.globalAlpha = 1;
ctx.fillStyle = INK;
ctx.beginPath();
ctx.rect(0, 0, w, h);
if (hole > 0) hexagon(ctx, o, INNER_RADIUS * unit);
ctx.fill('evenodd');
if (hole > 0 && hole < 1) {
ctx.globalAlpha = 1 - hole;
ctx.beginPath();
hexagon(ctx, o, INNER_RADIUS * unit);
ctx.fill();
ctx.globalAlpha = 1;
}
const iris = irisAt(time);
const lightUp = EmphasizedDecelerate(phase(time, 0, 620));
const light = lightUp * (1 - Standard(phase(time, 620, 1250)));
const ambient = 0.03 * InOut(phase(time, 300, 900)) * (1 - Standard(phase(time, 1500, 2300)));
// Light behind the blades: a soft bloom, a hot core, and rays leaking
// through the six gaps while the iris turns.
if (light > 0.001 || ambient > 0.001) {
ctx.globalCompositeOperation = 'lighter';
const bloom = 250;
let g = ctx.createRadialGradient(o.x, o.y, 0, o.x, o.y, bloom);
g.addColorStop(0, rgba(SEA_GLASS, 0.16 * light + ambient));
g.addColorStop(0.45, rgba(SEA_GLASS, 0.04 * light + ambient * 0.3));
g.addColorStop(1, rgba(SEA_GLASS, 0));
ctx.fillStyle = g;
ctx.beginPath();
ctx.arc(o.x, o.y, bloom, 0, Math.PI * 2);
ctx.fill();
if (light > 0.001) {
const core = ((26 * unit) / 2.0625) * mix(0.6, 1, light);
g = ctx.createRadialGradient(o.x, o.y, 0, o.x, o.y, core);
g.addColorStop(0, `rgba(255, 250, 236, ${0.95 * light})`);
g.addColorStop(0.35, `rgba(238, 242, 221, ${0.55 * light})`);
g.addColorStop(1, 'rgba(238, 242, 221, 0)');
ctx.fillStyle = g;
ctx.beginPath();
ctx.arc(o.x, o.y, core, 0, Math.PI * 2);
ctx.fill();
const rays = light * Math.min(1, IrisOpen(phase(time, 140, 1180)) * 2.5);
for (let i = 0; i < 6; i++) {
const angle = ((-90 + 60 * i) * Math.PI) / 180 + iris.theta;
const length = mix(40, 250, lightUp) * (0.75 + 0.25 * Math.sin(i * 2.1 + 1));
const end = { x: o.x + Math.cos(angle) * length, y: o.y + Math.sin(angle) * length };
g = ctx.createLinearGradient(o.x, o.y, end.x, end.y);
g.addColorStop(0, `rgba(255, 248, 230, ${0.42 * rays})`);
g.addColorStop(0.25, `rgba(214, 236, 226, ${0.12 * rays})`);
g.addColorStop(1, 'rgba(214, 236, 226, 0)');
ctx.fillStyle = g;
ctx.beginPath();
ctx.moveTo(o.x, o.y);
ctx.lineTo(o.x + Math.cos(angle - 0.014) * length, o.y + Math.sin(angle - 0.014) * length);
ctx.lineTo(o.x + Math.cos(angle + 0.014) * length, o.y + Math.sin(angle + 0.014) * length);
ctx.closePath();
ctx.fill();
}
}
ctx.globalCompositeOperation = 'source-over';
}
// Facets. Short echoes of earlier frames act as motion blur while the
// blades turn; they disappear beneath the facets once the iris is still.
const facetAlpha = (i: number) => EmphasizedDecelerate(phase(time, 40 + i * 34, 380 + i * 34));
if (time < 1400) {
for (const [delay, alpha] of [
[84, 0.07],
[56, 0.12],
[28, 0.2],
]) {
const echo = irisAt(time - delay);
FACETS.forEach((f, i) => {
ctx.globalAlpha = alpha * facetAlpha(i);
ctx.fillStyle = f.color;
ctx.beginPath();
facetPath(ctx, f, echo, unit, o);
ctx.fill();
});
}
}
FACETS.forEach((f, i) => {
ctx.globalAlpha = facetAlpha(i);
ctx.fillStyle = f.color;
ctx.beginPath();
facetPath(ctx, f, iris, unit, o);
ctx.fill();
});
ctx.globalAlpha = 1;
const sheen = phase(time, 980, 1560);
if (light > 0.01 || (sheen > 0 && sheen < 1)) {
ctx.save();
ctx.beginPath();
FACETS.forEach((f) => facetPath(ctx, f, iris, unit, o));
ctx.clip();
// Backlight tints the blades while the core is hot, so they read as glass.
if (light > 0.01) {
const radius = (36 * unit) / 2.0625;
const g = ctx.createRadialGradient(o.x, o.y, 0, o.x, o.y, radius);
g.addColorStop(0, `rgba(255, 252, 240, ${0.26 * light})`);
g.addColorStop(1, 'rgba(255, 252, 240, 0)');
ctx.fillStyle = g;
ctx.fillRect(o.x - radius, o.y - radius, radius * 2, radius * 2);
}
// One diagonal band of light crosses the settled mark.
if (sheen > 0 && sheen < 1) {
const reach = 34 * unit;
const a = (36 * Math.PI) / 180;
const d = { x: Math.cos(a), y: Math.sin(a) };
const pos = mix(-1.25, 1.25, InOut(sheen)) * reach;
const width = 10 * unit;
const peak = 0.42 * Math.sin(Math.min(1, sheen * 1.1) * Math.PI);
const g = ctx.createLinearGradient(o.x + d.x * (pos - width), o.y + d.y * (pos - width), o.x + d.x * (pos + width), o.y + d.y * (pos + width));
g.addColorStop(0, 'rgba(255, 255, 255, 0)');
g.addColorStop(0.5, `rgba(255, 255, 255, ${peak})`);
g.addColorStop(1, 'rgba(255, 255, 255, 0)');
ctx.fillStyle = g;
ctx.fillRect(o.x - reach, o.y - reach, reach * 2, reach * 2);
}
ctx.restore();
}
// The wordmark slides out from behind the mark as it moves into the lockup.
if (time >= 1400 && textAlpha > 0) {
const scale = (box / LOCK_BOX) * drift;
const textLeft = cx - (box * drift) / 2 + (LOCK_BOX + LOCK_GAP) * scale;
const slide = EmphasizedDecelerate(phase(time, 1400, 2050));
const baseline = cy + (letters.cap / 2) * scale;
ctx.save();
ctx.beginPath();
const clipLeft = cx + 24.5 * unit + 2 * scale;
ctx.rect(clipLeft, 0, w - clipLeft, h);
ctx.clip();
ctx.font = letters.font;
ctx.fillStyle = WORDMARK;
ctx.textBaseline = 'alphabetic';
letters.chars.forEach((ch, i) => {
const start = 1460 + i * 45;
const reveal = Standard(phase(time, start, start + 320));
if (reveal <= 0) return;
ctx.save();
ctx.globalAlpha = reveal * textAlpha;
ctx.translate(textLeft + (letters.x[i] - (1 - slide) * letters.width * 0.42) * scale + textShift, baseline);
ctx.scale(scale, scale);
ctx.fillText(ch, 0, 0);
ctx.restore();
});
ctx.restore();
}
}
async function measureLetters(): Promise<Letters> {
const size = 19 * LOCK_SCALE;
const font = `700 ${size}px 'Inter Variable', 'Segoe UI', sans-serif`;
await document.fonts?.load(font).catch(() => {});
const ctx = document.createElement('canvas').getContext('2d')!;
ctx.font = font;
const tracking = 1.4 * LOCK_SCALE;
const chars = 'KALEIDO'.split('');
const x: number[] = [];
let at = 0;
for (const ch of chars) {
x.push(at);
at += ctx.measureText(ch).width + tracking;
}
return { font, chars, x, width: at - tracking, cap: size * 0.711 };
}
export function Splash({ ready, onDone }: { ready: boolean; onDone: () => void }) {
const reduced = useSettings((s) => s.reducedMotion);
const canvas = useRef<HTMLCanvasElement>(null);
const readyRef = useRef(ready);
readyRef.current = ready;
const done = useRef(onDone);
done.current = onDone;
useEffect(() => {
const el = canvas.current;
if (!el) return;
if (reduced) {
// No sequence: wait for startup, then hand straight over.
const t = setInterval(() => readyRef.current && (clearInterval(t), done.current()), 50);
return () => clearInterval(t);
}
const ctx = el.getContext('2d')!;
let raf = 0;
let stopped = false;
let letters: Letters | null = null;
const size = () => {
const dpr = window.devicePixelRatio || 1;
el.width = Math.round(window.innerWidth * dpr);
el.height = Math.round(window.innerHeight * dpr);
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
};
size();
window.addEventListener('resize', size);
// Timeline time advances with the clock, except while held at GATHER_END.
let last = 0;
let time = 0;
let held = 0;
let exitStart = 0;
const frame = (now: number) => {
if (stopped) return;
const dt = last ? Math.min(64, now - last) : 0;
last = now;
if (time < GATHER_END) time = Math.min(GATHER_END, time + dt);
else if (time === GATHER_END && !readyRef.current && held < HOLD_MAX) held += dt;
else time = Math.min(TIMELINE_END, time + dt);
if (!exitStart && time >= INTRO_END && readyRef.current) {
exitStart = now;
document.documentElement.classList.add('splash-arrival');
}
const q = exitStart ? Math.min(1, (now - exitStart) / EXIT_MS) : 0;
if (letters) draw(ctx, window.innerWidth, window.innerHeight, time, q, letters);
if (q >= 1) {
done.current();
return;
}
raf = requestAnimationFrame(frame);
};
// Draw the first (dark) frame at once; start the clock once the wordmark's font is ready.
ctx.fillStyle = INK;
ctx.fillRect(0, 0, window.innerWidth, window.innerHeight);
measureLetters().then((l) => {
letters = l;
if (!stopped) raf = requestAnimationFrame(frame);
});
return () => {
stopped = true;
cancelAnimationFrame(raf);
window.removeEventListener('resize', size);
// Let the arrival settle finish after the splash is gone.
setTimeout(() => document.documentElement.classList.remove('splash-arrival'), 700);
};
}, [reduced]);
return (
<div className="splash" data-tauri-drag-region aria-label="Kaleido starting" role="img">
<canvas ref={canvas} />
</div>
);
}