Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: a toast waits while the pointer is on it

A toast left after four seconds (eight for an error) whether it had been read or
not. The countdown stops while the pointer rests on it and runs on for at least
1.5 seconds after the pointer leaves.
This commit is contained in:
iris 2026-11-28 02:49:25 +01:00 • committed by mara
commit 963ec65bbc

View file

@ -20,6 +20,18 @@ export function toastDuration(tone: ToastTone): number {
return tone === "error" ? 8000 : 4000;
}
/** What is left of a toast's time after it has been up `shownMs`. */
export function timeLeft(duration: number, shownMs: number): number {
return Math.max(0, duration - shownMs);
}
/** How long a toast the pointer left has to go: its time left, but never less
* than a moment, so one let go at the last second can still be read. */
export const RESUME_FLOOR_MS = 1500;
export function resumeDelay(left: number): number {
return Math.max(RESUME_FLOOR_MS, left);
}
let toasts: Toast[] = [];
let nextId = 1;
const listeners = new Set<() => void>();