(null);
useGlassLight(dropletRef);
// Liquid hop between tabs: stretch along the path, squash, then settle with a spring.
useEffect(() => {
const el = dropletRef.current;
const from = prevIndex.current;
prevIndex.current = activeIndex;
if (!el || activeIndex < 0) return;
el.style.transform = `translateX(${activeIndex * 100}%)`;
el.style.opacity = "1";
if (from < 0 || from === activeIndex) return;
const dist = Math.abs(activeIndex - from);
const stretch = 1 + Math.min(0.55, dist * 0.22);
const s = springs.wobble();
el.animate(
[
{ transform: `translateX(${from * 100}%) scale(1, 1)` },
{
transform: `translateX(${((from + activeIndex) / 2) * 100}%) scale(${stretch}, ${2 - stretch})`,
offset: 0.45,
},
{ transform: `translateX(${activeIndex * 100}%) scale(1, 1)` },
],
{ duration: Math.max(420, s.duration), easing: s.easing },
);
}, [activeIndex]);
const indexAt = (clientX: number) => {
const list = listRef.current;
if (!list) return activeIndex;
const r = list.getBoundingClientRect();
const w = r.width / TABS.length;
return Math.max(
0,
Math.min(TABS.length - 1, Math.floor((clientX - r.left) / w)),
);
};
// Press and drag the droplet across the bar, like the iOS 26 tab bar.
const onPointerDown = (e: React.PointerEvent) => {
if (e.button !== 0) return;
drag.current = {
startX: e.clientX,
lastX: e.clientX,
lastT: performance.now(),
v: 0,
moved: false,
};
dropletRef.current?.style.setProperty("--press", "1");
};
const onPointerMove = (e: React.PointerEvent) => {
const d = drag.current;
const el = dropletRef.current;
const list = listRef.current;
if (!d || !el || !list) return;
if (!d.moved && Math.abs(e.clientX - d.startX) < 6) return;
if (!d.moved) {
d.moved = true;
list.setPointerCapture(e.pointerId);
el.getAnimations().forEach((a) => a.cancel());
}
const now = performance.now();
d.v =
0.8 * d.v + 0.2 * ((e.clientX - d.lastX) / Math.max(1, now - d.lastT));
d.lastX = e.clientX;
d.lastT = now;
const r = list.getBoundingClientRect();
const w = r.width / TABS.length;
const x = Math.max(0, Math.min(r.width - w, e.clientX - r.left - w / 2));
const stretch = 1 + Math.min(0.45, Math.abs(d.v) * 0.18);
el.style.opacity = "1";
el.style.transform = `translateX(${(x / w) * 100}%) scale(${stretch * 1.06}, ${(2 - stretch) * 1.06})`;
};
const onPointerUp = (e: React.PointerEvent) => {
const d = drag.current;
drag.current = null;
dropletRef.current?.style.removeProperty("--press");
if (!d?.moved) return;
const index = indexAt(e.clientX);
const el = dropletRef.current;
if (el) {
const current = el.style.transform;
const s = springs.wobble();
el.style.transform = `translateX(${index * 100}%)`;
el.animate([{ transform: current }, { transform: el.style.transform }], {
duration: s.duration,
easing: s.easing,
});
}
prevIndex.current = index;
onSelect(TABS[index]);
};
return (
{TABS.map((tab, i) => (
))}
);
}
/** Opens the command palette; its shortcut lives in the hover label and the footer. */
function SearchButton({
label,
shortcut,
onOpen,
}: {
label: string;
shortcut: string;
onOpen: () => void;
}) {
const ref = useRef(null);
useGlassLight(ref);
return (
);
}
/** Opens this page in the other language; its label is written in that language. */
function LanguageButton({ lang, path }: { lang: Locale; path: string }) {
const { nav } = useT();
const ref = useRef(null);
const other: Locale = lang === "en" ? "zh" : "en";
useGlassLight(ref);
return (
{
// Keep the home grid's view (its hash) across the switch.
e.currentTarget.href = localePath(other, path) + window.location.hash;
}}
>
{nav.switchShort}
);
}
function ThemeButton() {
const { nav } = useT();
const { resolvedTheme, setTheme } = useTheme();
const ref = useRef(null);
useGlassLight(ref);
return (
);
}