Files
otunes/apps/mobile/lib/now-playing-colors.ts
T

47 lines
1.5 KiB
TypeScript

import type { CoverPalette } from "@/lib/cover-palette"
/** Now Playing colors: the cover palette plus translucent tints of its text color. */
export type NowPlayingColors = {
background: string
foreground: string
secondaryForeground: string
sliderTrack: string
sliderFill: string
control: string
controlPressed: string
selected: string
selectedForeground: string
highlight: string
/** Lyrics lines other than the one playing. */
lyricsInactive: string
/** Words of the playing line not yet sung. */
lyricsUnsung: string
isDark: boolean
}
export function nowPlayingColors(palette: CoverPalette): NowPlayingColors {
const { foreground } = palette
return {
background: palette.background,
foreground,
secondaryForeground: palette.secondaryForeground,
sliderTrack: withAlpha(foreground, 0.2),
sliderFill: withAlpha(foreground, 0.6),
control: withAlpha(foreground, 0.14),
controlPressed: withAlpha(foreground, 0.1),
selected: withAlpha(foreground, 0.8),
selectedForeground: palette.background,
highlight: withAlpha(foreground, 0.1),
lyricsInactive: withAlpha(foreground, 0.35),
lyricsUnsung: withAlpha(foreground, 0.55),
isDark: palette.isDark,
}
}
function withAlpha(color: string, alpha: number) {
const match = /^#([0-9a-f]{6})$/i.exec(color.trim())
if (!match) return color
const value = parseInt(match[1], 16)
return `rgba(${(value >> 16) & 255}, ${(value >> 8) & 255}, ${value & 255}, ${alpha})`
}