add web app & add concurrency

This commit is contained in:
2026-02-20 20:22:06 +03:00
parent b42a556ec5
commit 1f65301a05
19 changed files with 2732 additions and 97 deletions

25
web/src/getContrastYIQ.ts Normal file
View File

@@ -0,0 +1,25 @@
export function getContrastYIQ(hexcolor: string) {
// Remove leading # if present
if (hexcolor.startsWith("#")) {
hexcolor = hexcolor.slice(1);
}
// Handle 3-digit hex codes (e.g., #abc → #aabbcc)
if (hexcolor.length === 3) {
hexcolor = hexcolor
.split("")
.map((c) => c + c)
.join("");
}
// Parse RGB values
const r = parseInt(hexcolor.substr(0, 2), 16);
const g = parseInt(hexcolor.substr(2, 2), 16);
const b = parseInt(hexcolor.substr(4, 2), 16);
// Calculate YIQ brightness
const yiq = (r * 299 + g * 587 + b * 114) / 1000;
// Return black or white based on contrast
return yiq >= 128 ? "black" : "white";
}