Files
KML-Verification/src/colors.ts
2026-04-27 12:48:37 +05:30

35 lines
829 B
TypeScript

// Stable video_name -> RGB hash (12-color palette).
const PALETTE: ReadonlyArray<readonly [number, number, number]> = [
[231, 76, 60],
[52, 152, 219],
[46, 204, 113],
[241, 196, 15],
[155, 89, 182],
[230, 126, 34],
[26, 188, 156],
[233, 30, 99],
[3, 169, 244],
[205, 220, 57],
[255, 87, 34],
[121, 85, 72],
];
const cache = new Map<string, readonly [number, number, number]>();
export function videoColorRGB(
name: string | null | undefined,
): readonly [number, number, number] {
const key = name ?? "";
const hit = cache.get(key);
if (hit) return hit;
let h = 0;
for (let i = 0; i < key.length; i++) {
h = ((h << 5) - h + key.charCodeAt(i)) | 0;
}
const idx = ((h % PALETTE.length) + PALETTE.length) % PALETTE.length;
const c = PALETTE[idx];
cache.set(key, c);
return c;
}