The splash now gathers a mirrored field of shards into the mark, idles with circling shards while startup finishes, and flies through the mark's centre as before. The app icon's mark fills ~77% of the tile (was ~45%); the icon set is generated from the new app-icon.svg. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
346 lines
13 KiB
TypeScript
346 lines
13 KiB
TypeScript
import { useEffect, useRef } from 'react';
|
|
import { useSettings } from '../app/settings';
|
|
|
|
/**
|
|
* The cold-start brand sequence: a kaleidoscope. A mirrored field of shards
|
|
* turns and gathers into the mark's six facets; if startup is still going,
|
|
* small shards keep circling the mark. Once startup is ready the camera flies
|
|
* through the mark's open 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);
|
|
// 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;
|
|
const rad = (deg: number) => (deg * Math.PI) / 180;
|
|
|
|
const PALETTE = ['#C3E8D3', '#71B9B0', '#3D7C7B', '#D0A977', '#E9D8AE', '#EEF2DD'];
|
|
|
|
// The brand mark's facets, centred on its 64-unit viewport, each with the
|
|
// angle of its hexagon edge's outward normal and its centroid.
|
|
const FACETS = [
|
|
[33, 4, 55.5, 17, 42.5, 24.5, 33, 19],
|
|
[56.5, 19, 56.5, 45, 43.5, 37.5, 43.5, 26.5],
|
|
[55.5, 47, 33, 60, 33, 45, 42.5, 39.5],
|
|
[31, 60, 8.5, 47, 21.5, 39.5, 31, 45],
|
|
[7.5, 45, 7.5, 19, 20.5, 26.5, 20.5, 37.5],
|
|
[8.5, 17, 31, 4, 31, 19, 21.5, 24.5],
|
|
].map((pts, i) => {
|
|
const points: Point[] = [];
|
|
for (let k = 0; k < pts.length; k += 2) points.push({ x: pts[k] - 32, y: pts[k + 1] - 32 });
|
|
const centroid = { x: points.reduce((s, p) => s + p.x, 0) / 4, y: points.reduce((s, p) => s + p.y, 0) / 4 };
|
|
return { points, centroid, color: PALETTE[i], angle: rad(-60 + 60 * i) };
|
|
});
|
|
type Facet = (typeof FACETS)[number];
|
|
|
|
// Loose shards around each facet: angle offset from the facet's normal, starting
|
|
// radius (px), size, palette offset and how far they tumble on the way in.
|
|
const SHARDS = [
|
|
{ angle: 20, radius: 170, scale: 0.42, color: 2, spin: 1.2 },
|
|
{ angle: -20, radius: 170, scale: 0.42, color: 4, spin: -1.2 },
|
|
{ angle: 36, radius: 320, scale: 0.3, color: 3, spin: 2.1 },
|
|
{ angle: -36, radius: 320, scale: 0.3, color: 1, spin: -2.1 },
|
|
{ angle: 8, radius: 420, scale: 0.2, color: 5, spin: 3 },
|
|
{ angle: -8, radius: 420, scale: 0.2, color: 5, spin: -3 },
|
|
];
|
|
|
|
// The inner hexagon traced by the facets' inner edges: the aperture the exit flies through.
|
|
const INNER_RADIUS = 13.6;
|
|
const MARK_BOX = 140;
|
|
// Timeline (ms): the mark has formed at INTRO_END; the sequence then idles until startup is ready.
|
|
const INTRO_END = 1700;
|
|
const EXIT_MS = 640;
|
|
// The mark is larger than the old lockup, so it zooms less to end the flight at the same size.
|
|
const FLIGHT_ZOOM = 30;
|
|
|
|
const INK = '#090a0c';
|
|
const SEA_GLASS = [113, 185, 176];
|
|
const LIGHT = [238, 242, 221];
|
|
const rgba = (c: number[], a: number) => `rgba(${c[0]}, ${c[1]}, ${c[2]}, ${Math.max(0, a)})`;
|
|
|
|
/** A facet turned `rot` about the mark centre, shrunk and spun about its own centroid, then offset. */
|
|
function facetPath(ctx: CanvasRenderingContext2D, f: Facet, o: Point, unit: number, rot: number, scale: number, spin: number, offset: Point) {
|
|
const cr = Math.cos(rot);
|
|
const sr = Math.sin(rot);
|
|
const cs = Math.cos(spin);
|
|
const ss = Math.sin(spin);
|
|
f.points.forEach((p, i) => {
|
|
const rx = p.x - f.centroid.x;
|
|
const ry = p.y - f.centroid.y;
|
|
const x = f.centroid.x + (rx * cs - ry * ss) * scale;
|
|
const y = f.centroid.y + (rx * ss + ry * cs) * scale;
|
|
const px = o.x + (x * cr - y * sr) * unit + offset.x;
|
|
const py = o.y + (x * sr + y * cr) * unit + offset.y;
|
|
if (i === 0) ctx.moveTo(px, py);
|
|
else ctx.lineTo(px, py);
|
|
});
|
|
ctx.closePath();
|
|
}
|
|
|
|
/** A loose facet shape with its centroid at `pos`. */
|
|
function shardPath(ctx: CanvasRenderingContext2D, f: Facet, pos: Point, size: number, angle: number) {
|
|
const c = Math.cos(angle);
|
|
const s = Math.sin(angle);
|
|
f.points.forEach((p, i) => {
|
|
const x = p.x - f.centroid.x;
|
|
const y = p.y - f.centroid.y;
|
|
const px = pos.x + (x * c - y * s) * size;
|
|
const py = pos.y + (x * s + y * c) * size;
|
|
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 = rad(-90 + 60 * i);
|
|
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();
|
|
}
|
|
|
|
function draw(ctx: CanvasRenderingContext2D, w: number, h: number, time: number, q: number) {
|
|
const o = { x: w / 2, y: h / 2 };
|
|
ctx.clearRect(0, 0, w, h);
|
|
const zoom = q > 0 ? Math.exp(Math.log(FLIGHT_ZOOM) * Flight(q)) : 1;
|
|
const unit = (MARK_BOX / 64) * zoom;
|
|
const gather = Emphasized(phase(time, 0, 1450));
|
|
// The whole field turns a little less than half a revolution as it gathers.
|
|
const field = rad(-150) * (1 - Emphasized(phase(time, 0, 1550)));
|
|
|
|
// The surface: ink everywhere, with the aperture's centre cut away on exit.
|
|
const hole = InOut(phase(q, 0.12, 0.5));
|
|
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;
|
|
}
|
|
|
|
// The kaleidoscope's mirror lines, turning with the field.
|
|
const lines = InOut(phase(time, 0, 450)) * (1 - Standard(phase(time, 1100, 1700)));
|
|
if (lines > 0) {
|
|
ctx.lineWidth = 1;
|
|
for (let s = 0; s < 6; s++) {
|
|
const a = field + rad(-90 + 60 * s);
|
|
const end = { x: o.x + Math.cos(a) * 640, y: o.y + Math.sin(a) * 640 };
|
|
const g = ctx.createLinearGradient(o.x, o.y, end.x, end.y);
|
|
g.addColorStop(0, rgba(LIGHT, 0.2 * lines));
|
|
g.addColorStop(1, rgba(LIGHT, 0));
|
|
ctx.strokeStyle = g;
|
|
ctx.beginPath();
|
|
ctx.moveTo(o.x, o.y);
|
|
ctx.lineTo(end.x, end.y);
|
|
ctx.stroke();
|
|
}
|
|
}
|
|
|
|
const bloom = 0.09 * InOut(phase(time, 200, 1000)) * (1 - Standard(phase(time, 1500, 2600)));
|
|
if (bloom > 0.001) {
|
|
ctx.globalCompositeOperation = 'lighter';
|
|
const g = ctx.createRadialGradient(o.x, o.y, 0, o.x, o.y, 300);
|
|
g.addColorStop(0, rgba(SEA_GLASS, bloom));
|
|
g.addColorStop(0.45, rgba(SEA_GLASS, bloom * 0.3));
|
|
g.addColorStop(1, rgba(SEA_GLASS, 0));
|
|
ctx.fillStyle = g;
|
|
ctx.beginPath();
|
|
ctx.arc(o.x, o.y, 300, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
ctx.globalCompositeOperation = 'source-over';
|
|
}
|
|
|
|
// Shards spiral inward, faster than the field turns, and vanish into the centre.
|
|
ctx.globalCompositeOperation = 'screen';
|
|
const inward = Emphasized(phase(time, 0, 1350));
|
|
FACETS.forEach((f, s) => {
|
|
SHARDS.forEach((d, j) => {
|
|
const appear = Standard(phase(time, j * 50 + s * 25, j * 50 + s * 25 + 420));
|
|
const vanish = Standard(phase(time, 750 + j * 45, 1350 + j * 45));
|
|
if (appear <= 0 || vanish >= 1) return;
|
|
const a = f.angle + rad(d.angle) + field * 1.5;
|
|
const r = d.radius * (1 - 0.88 * inward);
|
|
ctx.globalAlpha = appear * (1 - vanish) * 0.9;
|
|
ctx.fillStyle = PALETTE[(s + d.color) % 6];
|
|
ctx.beginPath();
|
|
shardPath(ctx, f, { x: o.x + Math.cos(a) * r, y: o.y + Math.sin(a) * r }, unit * d.scale * (1 - 0.6 * vanish), field * 2 + d.spin * (1 - gather));
|
|
ctx.fill();
|
|
});
|
|
});
|
|
ctx.globalAlpha = 1;
|
|
ctx.globalCompositeOperation = 'source-over';
|
|
|
|
// The six facets ride in from the field and lock into the mark.
|
|
FACETS.forEach((f, s) => {
|
|
const r = 240 * (1 - gather);
|
|
const a = f.angle + field;
|
|
ctx.globalAlpha = Standard(phase(time, s * 25, s * 25 + 420));
|
|
ctx.fillStyle = f.color;
|
|
ctx.beginPath();
|
|
facetPath(ctx, f, o, unit, field, mix(0.55, 1, gather), rad(-60) * (1 - gather), { x: Math.cos(a) * r, y: Math.sin(a) * r });
|
|
ctx.fill();
|
|
});
|
|
ctx.globalAlpha = 1;
|
|
|
|
// A ring pulses out as the facets lock.
|
|
const pulse = phase(time, 1380, 2050);
|
|
if (pulse > 0 && pulse < 1) {
|
|
ctx.strokeStyle = rgba(SEA_GLASS, 0.45 * (1 - pulse));
|
|
ctx.lineWidth = 1.5;
|
|
ctx.beginPath();
|
|
hexagon(ctx, o, (30 + 24 * EmphasizedDecelerate(pulse)) * unit);
|
|
ctx.stroke();
|
|
}
|
|
|
|
// Still starting: small shards keep circling the mark.
|
|
const idle = Standard(phase(time, 2300, 2900)) * (1 - phase(q, 0, 0.25));
|
|
if (idle > 0) {
|
|
ctx.globalCompositeOperation = 'screen';
|
|
ctx.globalAlpha = 0.4 * idle;
|
|
for (let s = 0; s < 6; s++) {
|
|
for (const side of [-1, 1]) {
|
|
const a = rad(-60 + 60 * s) + side * rad(11) + (time - 2300) * 0.00032;
|
|
ctx.fillStyle = PALETTE[(s + (side > 0 ? 2 : 4)) % 6];
|
|
ctx.beginPath();
|
|
shardPath(ctx, FACETS[s], { x: o.x + Math.cos(a) * 50 * unit, y: o.y + Math.sin(a) * 50 * unit }, unit * 0.16, a * 2);
|
|
ctx.fill();
|
|
}
|
|
}
|
|
ctx.globalAlpha = 1;
|
|
ctx.globalCompositeOperation = 'source-over';
|
|
}
|
|
|
|
// A band of light crosses the settled mark, then again every few seconds while it waits.
|
|
const sheen = time < 1500 ? 0 : ((time - 1500) % 3600) / 900;
|
|
if (q === 0 && sheen > 0 && sheen < 1) {
|
|
ctx.save();
|
|
ctx.beginPath();
|
|
FACETS.forEach((f) => facetPath(ctx, f, o, unit, 0, 1, 0, { x: 0, y: 0 }));
|
|
ctx.clip();
|
|
const reach = 40 * unit;
|
|
const a = rad(36);
|
|
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();
|
|
}
|
|
}
|
|
|
|
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;
|
|
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);
|
|
|
|
let last = 0;
|
|
let time = 0;
|
|
let exitStart = 0;
|
|
const frame = (now: number) => {
|
|
if (stopped) return;
|
|
// Clamp long frames so a stall doesn't skip the gather.
|
|
time += last ? Math.min(64, now - last) : 0;
|
|
last = now;
|
|
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;
|
|
draw(ctx, window.innerWidth, window.innerHeight, time, q);
|
|
if (q >= 1) {
|
|
done.current();
|
|
return;
|
|
}
|
|
raf = requestAnimationFrame(frame);
|
|
};
|
|
// Draw the first (dark) frame at once so the app never shows through.
|
|
draw(ctx, window.innerWidth, window.innerHeight, 0, 0);
|
|
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>
|
|
);
|
|
}
|