static fade animation

This commit is contained in:
Nate 2025-07-19 14:10:34 -07:00
parent 81453481d2
commit c5b20f2ae3

View file

@ -29,8 +29,119 @@ const SPINNER_DOUBLE_BARS = [
"▃▁",
"▂▁",
];
const SPINNER_SHADES = "░▒▓█▓▒░";
const SPINNER_RINGS = "○◔◑◕●◐◓◑◒";
const SPINNER_SPARKLES = "✢✣✤✥✦✧✬✱✲✳✴✵✶✷✸";
const SPINNER_PULSE = "·∙●⬤●∙·";
const MITOSIS_FRAMES = [
"●",
"●●",
"● ●", // regular space
"●\u2004●", // 1/3 em space
"●\u2002●", // 1/2 em space
"● ●", // regular space
"●●",
"●",
];
const SPINNER: string | string[] = SPINNER_CORNERS;
const DANCING_NOTES_FRAMES = [
"♪ ",
"♫ ",
"♪ ♫ ",
"♫ ♪ ",
"♬ ♩ ",
"♩ ♬ ",
"♫ ♪ ",
"♪ ♫ ",
"♫ ",
"♪ ",
];
const MITOSIS_2 = [
"⚬ ",
"⚭ ",
"⚮ ",
"⚯ ",
"○ ○",
"⚯ ",
"⚮ ",
"⚭ ",
"⚬ ",
];
// Generate all possible Braille characters (from U+2800 to U+28FF)
const BRAILLE_CHARS = Array.from({ length: 256 }, (_, i) =>
String.fromCharCode(0x2800 + i)
);
const BRAILLE_BY_DENSITY: { [key: number]: string[] } = {
0: ["⠀"], // No dots
1: ["⠁", "⠂", "⠄", "⠈", "⠐", "⠠", "⡀", "⢀"], // 1 dot
2: ["⠃", "⠅", "⠉", "⠑", "⠡", "⠊", "⠒", "⠔"], // 2 dots
3: ["⠇", "⠋", "⠍", "⠕", "⠣", "⠱", "⠪", "⠜"], // 3 dots
4: ["⠏", "⠗", "⠛", "⠝", "⠧", "⠯", "⠳", "⠵"], // 4 dots
5: ["⠟", "⠫", "⠭", "⠷", "⠽", "⠾", "⠻", "⠺"], // 5 dots
6: ["⠿", "⡷", "⡾", "⡻", "⡯", "⡧", "⢿", "⣷"], // 6 dots
7: ["⣿", "⣾", "⣽", "⣻", "⣯", "⣧", "⣏", "⡿"], // 7 dots
8: ["⣿"], // All dots (8)
};
// Function to generate frame with specific dot density
const generateDensityFrame = (dotCount: number): string => {
const chars = BRAILLE_BY_DENSITY[Math.min(8, Math.max(0, dotCount))];
return Array.from(
{ length: 3 },
() => chars[Math.floor(Math.random() * chars.length)]
).join("");
};
// Helper function to generate eased static fade animation with full timing control
const generateEasedStaticFade = (
timingCurve: number[] = [3, 3, 2, 1, 1, 1, 2, 3, 3]
): string[] => {
const frames: string[] = [];
// timingCurve[0] = frames at density 8
// timingCurve[1] = frames at density 7
// timingCurve[2] = frames at density 6
// ... and so on
// timingCurve[8] = frames at density 0
// Going down (8 -> 0)
for (let density = 8; density >= 0; density--) {
const frameCount = timingCurve[8 - density];
for (let i = 0; i < frameCount; i++) {
frames.push(generateDensityFrame(density));
}
}
// Going up (1 -> 8) - skip 0 to avoid double-holding at the bottom
for (let density = 1; density <= 8; density++) {
const frameCount = timingCurve[8 - density];
for (let i = 0; i < frameCount; i++) {
frames.push(generateDensityFrame(density));
}
}
return frames;
};
// Usage examples:
// Default ease-in-ease-out
const TIMING_CURVE = [3, 3, 2, 1, 1, 0, 1, 2, 3];
const STATIC_FADE = [
...generateEasedStaticFade(TIMING_CURVE),
...generateEasedStaticFade(TIMING_CURVE),
...generateEasedStaticFade(TIMING_CURVE),
...generateEasedStaticFade(TIMING_CURVE),
];
// Linear (same speed throughout)
const STATIC_FADE_LINEAR = generateEasedStaticFade([2, 2, 2, 2, 2, 2, 2, 2]);
const STARS = "·+✣✤✻✽❊❈❈❈❈❊✽✻✤✣+";
const SPINNER: string | string[] = STATIC_FADE;
interface LoadingAnimationProps {
visible?: boolean;
@ -50,7 +161,7 @@ const LoadingAnimation: React.FC<LoadingAnimationProps> = ({
const interval = setInterval(() => {
setCurrentIndex((prev) => (prev + 1) % animationChars.length);
}, 300);
}, 150);
return () => clearInterval(interval);
}, [visible, animationChars.length]);