mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 05:05:38 -04:00
- 211 tests across 15 files covering services (tracking, discovery, metadata, backup, credits, webhooks, settings, update-check, colors, person), utilities (config, cron, providers, title-theme), and TMDB image URL helpers - `lib/test-preload.ts` + `bunfig.toml` wire up a global in-memory SQLite DB with migrations for all DB-backed tests - `lib/test-utils.ts` provides `clearAllTables()` and seed helpers (insertUser, insertTitle, insertTvShow, insertMovieWatch, etc.) - Export `getBackupSource`, `isKnownBackup`, `isValidBackupFilename`, `buildBackupCron`, `performUpdateCheck` internals for direct testing - GitHub Actions workflow runs `bun test --coverage` on push/PR to main
32 lines
1016 B
TypeScript
32 lines
1016 B
TypeScript
import type { ColorPalette } from "@/lib/types/title";
|
|
|
|
/** @internal */
|
|
export function hexToRelativeLuminance(hex: string): number {
|
|
const r = Number.parseInt(hex.slice(1, 3), 16) / 255;
|
|
const g = Number.parseInt(hex.slice(3, 5), 16) / 255;
|
|
const b = Number.parseInt(hex.slice(5, 7), 16) / 255;
|
|
const toLinear = (c: number) =>
|
|
c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
return 0.2126 * toLinear(r) + 0.7152 * toLinear(g) + 0.0722 * toLinear(b);
|
|
}
|
|
|
|
export function getTitleThemeStyle(
|
|
palette: ColorPalette | null,
|
|
): React.CSSProperties {
|
|
const color = palette?.vibrant;
|
|
if (!color) return {};
|
|
|
|
const luminance = hexToRelativeLuminance(color);
|
|
const foreground =
|
|
luminance > 0.3
|
|
? "oklch(0.13 0.006 55)" // dark (current --primary-foreground)
|
|
: "oklch(0.93 0.015 80)"; // light (current --foreground)
|
|
|
|
return {
|
|
"--primary": color,
|
|
"--ring": color,
|
|
"--primary-foreground": foreground,
|
|
"--status-watching": color,
|
|
} as React.CSSProperties;
|
|
}
|