Debian Codegraph @

web/src/app/splash.js

raw
1 // Fades out and removes the static splash (see web/index.html), called once the app has mounted and
2 // its data is ready. Idempotent.
3
4 // Minimum time the splash stays up, so it doesn't flash-and-vanish on warm-cache loads.
5 const MIN_VISIBLE_MS = 1000;
6
7 // Hide in two phases: fade the logo out, then fade the background away to reveal the app.
8 // APP_FADE_MS must match the #splash opacity transition in index.html.
9 const LOGO_FADE_MS = 300;
10 const APP_FADE_MS = 100;
11
12 let removed = false;
13
14 const fadeOutAndRemove = () => {
15 const splash = document.getElementById("splash");
16 if (!splash) {
17 return;
18 }
19
20 // Phase 1: freeze the pulse at its current opacity (else stopping the animation snaps to full),
21 // then fade the logo to 0.
22 const img = splash.querySelector("img");
23 if (img) {
24 const current = getComputedStyle(img).opacity;
25 img.style.opacity = current;
26 img.style.animation = "none";
27 img.getBoundingClientRect(); // force reflow so the fade starts from `current`
28 img.style.transition = `opacity ${LOGO_FADE_MS}ms ease-out`;
29 img.style.opacity = "0";
30 }
31
32 // Phase 2: lift the background to fade the app in, then remove the node.
33 setTimeout(() => {
34 splash.classList.add("splash-hidden");
35 const remove = () => splash.remove();
36 // Ignore the logo's bubbling transitionend; only the background's own fade should remove it.
37 const onEnd = (event) => {
38 if (event.target === splash) {
39 splash.removeEventListener("transitionend", onEnd);
40 remove();
41 }
42 };
43 splash.addEventListener("transitionend", onEnd);
44 setTimeout(remove, APP_FADE_MS + 100); // fallback if transitionend never fires
45 }, LOGO_FADE_MS);
46 };
47
48 const hideSplash = () => {
49 if (removed) {
50 return;
51 }
52 removed = true;
53 // performance.now() ~= how long the splash has been visible; hold until MIN_VISIBLE_MS elapses.
54 const remaining = Math.max(0, MIN_VISIBLE_MS - performance.now());
55 setTimeout(fadeOutAndRemove, remaining);
56 };
57
58 export default hideSplash;