Skip to content

Commit e5cf27d

Browse files
committed
fix: tweak album art color and links to work with dark mode
1 parent 17cd05e commit e5cf27d

File tree

7 files changed

+37
-41
lines changed

7 files changed

+37
-41
lines changed

src/components/CoverArt.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { css, keyframes } from 'goober';
22
import { FC, memo } from 'react';
3+
import { TNowPlayingData } from 'services/now-playing';
34

45
import { useStoreFocusListeners } from 'services/store/utils';
56
import { screen } from 'services/style';
67

7-
type TCoverArtProps = { link: string; src: string; color: string };
8+
type TCoverArtProps = Pick<TNowPlayingData, 'link' | 'coverArtSrc'> & {
9+
color: string | undefined;
10+
};
811

912
const rotate = keyframes`
1013
from { transform: rotate(0deg); }
@@ -59,7 +62,7 @@ const CoverArtLink = css`
5962
}
6063
`;
6164

62-
const CoverArt: FC<TCoverArtProps> = memo(({ link, src, color }) => {
65+
const CoverArt: FC<TCoverArtProps> = memo(({ link, coverArtSrc, color }) => {
6366
return (
6467
<a
6568
href={link}
@@ -69,7 +72,7 @@ const CoverArt: FC<TCoverArtProps> = memo(({ link, src, color }) => {
6972
{...useStoreFocusListeners()}
7073
>
7174
<div style={{ color }}>
72-
<img src={src} />
75+
<img src={coverArtSrc} />
7376
<span />
7477
</div>
7578
</a>

src/components/DynamicCurrentStatus.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ import {
1111
import CoverArt from 'components/CoverArt';
1212
import { Text } from 'components/core';
1313

14+
const clamp = (v: number, min: number, max: number) =>
15+
Math.max(Math.min(v, max), min);
16+
17+
const hslColor = (color: TNowPlayingData['coverArtColor'] = [0, 0, 0]) => {
18+
const [h, s, l] = [
19+
color[0],
20+
clamp(color[1], 0, 60),
21+
// clamp lightness value to make it colorful but still readable
22+
clamp(color[1], 50, 70),
23+
];
24+
return `hsl(${h}, ${s}%, ${l}%)`;
25+
};
26+
1427
const nowPlayingMarkup = ({
1528
name,
1629
artistName,
@@ -27,20 +40,21 @@ const nowPlayingMarkup = ({
2740
const label = `${isPodcast ? podcastName : name}${
2841
hasArtist ? ` by ${artistName}` : ''
2942
}`;
43+
const color = hslColor(coverArtColor);
3044

3145
return [
3246
...action.split(' '),
3347
...label.split(' ').map((s) => (
3448
<Text
3549
bold={s !== 'by'}
3650
style={{
37-
color: coverArtColor,
51+
color,
3852
}}
3953
>
4054
{s}
4155
</Text>
4256
)),
43-
<CoverArt link={link} src={coverArtSrc} color={coverArtColor} />,
57+
<CoverArt link={link} coverArtSrc={coverArtSrc} color={color} />,
4458
];
4559
};
4660

src/components/DynamicTime.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const timeToGradient = (hour: number, time: string): TextGradientInfo => {
5252
return ['120deg', '#5995B7', '#D36C50'];
5353

5454
case '7PM': // sunset
55-
return ['145deg', '#477792', '#A8131C'];
55+
return ['145deg', '#477792', '#b54800'];
5656

5757
case '8PM':
5858
return ['120deg', '#2D1D7A', '#5995B7'];

src/services/color.ts

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// from https://css-tricks.com/converting-color-spaces-in-javascript/
2-
export const rgbToHsl = ([r, g, b]: number[]) => {
2+
const rgbToHsl = ([r, g, b]: number[]) => {
33
r /= 255;
44
g /= 255;
55
b /= 255;
@@ -27,17 +27,8 @@ export const rgbToHsl = ([r, g, b]: number[]) => {
2727
return [h, s, l];
2828
};
2929

30-
export const rgbToHex = (rgb: Rgb): Hex =>
31-
`#${rgb
32-
.map((val) => {
33-
const hex = val.toString(16);
34-
return hex.length === 1 ? `0${hex}` : hex;
35-
})
36-
.join('')}`;
37-
3830
type Args = {
3931
amount: number;
40-
format: string;
4132
group: number;
4233
sample: number;
4334
canvasBuilder: () => any;
@@ -61,14 +52,12 @@ const getSrc = (item: Item): string =>
6152

6253
const getArgs = ({
6354
amount = 3,
64-
format = 'array',
6555
group = 20,
6656
sample = 10,
6757
canvasBuilder = browserCanvasBuilder,
6858
imageClass = Image,
6959
}: ProminentOptions = {}): Args => ({
7060
amount,
71-
format,
7261
group,
7362
sample,
7463
canvasBuilder,
@@ -77,8 +66,7 @@ const getArgs = ({
7766

7867
const format = (input: Input, args: Args): Output => {
7968
const list = input.map((val) => {
80-
const rgb = Array.isArray(val) ? val : (val.split(',').map(Number) as Rgb);
81-
return args.format === 'hex' ? rgbToHex(rgb) : rgb;
69+
return Array.isArray(val) ? val : (val.split(',').map(Number) as Rgb);
8270
});
8371

8472
return args.amount === 1 || list.length === 1 ? list[0] : list;
@@ -143,32 +131,23 @@ const processImage = (
143131
.catch((error) => reject(error))
144132
);
145133

134+
// from https://github.com/luukdv/color.js
146135
const prominent = (item: Item, opts?: ProminentOptions) =>
147136
processImage(getProminent, item, opts);
148137

149138
export const getBestTextColor = async (
150139
coverArt: string | undefined,
151140
colorArgs?: ProminentOptions
152-
): Promise<string> => {
153-
if (!coverArt) return '#000';
141+
): Promise<[h: number, s: number, l: number] | undefined> => {
142+
if (!coverArt) return undefined;
154143

155-
const colors = (await prominent(coverArt, {
144+
const colors = ((await prominent(coverArt, {
156145
amount: 3,
157146
group: 10,
158-
format: 'array',
159-
sample: 10,
160147
...colorArgs,
161-
})) as number[][];
162-
163-
let [bestH, bestS, bestL] = rgbToHsl(colors[0]);
164-
for (const rgb of colors) {
165-
const [h, s, l] = rgbToHsl(rgb);
166-
if (s > 40) {
167-
[bestH, bestS, bestL] = [h, s, l];
168-
break;
169-
}
170-
}
148+
})) as number[][]).map(rgbToHsl);
149+
150+
const saturatedColors = [...colors.filter(([, s]) => s > 10), ...colors];
171151

172-
// clamp lightness value to preserve both colorfulness and readability
173-
return `hsl(${bestH}, ${bestS}%, ${Math.max(Math.min(bestL, 40), 30)}%)`;
152+
return saturatedColors[0] as Rgb;
174153
};

src/services/copy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ export const PAST_EXPERIENCE = [
7070
{
7171
label: 'Hack the North',
7272
href: 'https://hackthenorth.com/',
73-
color: '#004f85',
73+
color: '#007cba',
7474
},
7575
{ label: 'Faire', href: 'https://www.faire.com/about', color: 'textPrimary' },
7676
{ label: 'TEDxUW', href: 'https://tedxuw.com/', color: '#c9200c' },
7777
{
7878
label: 'Flipp',
7979
href: 'https://corp.flipp.com/about-us/',
80-
color: '#007cba',
80+
color: '#0e9cba',
8181
},
8282
];

src/services/now-playing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type TNowPlayingData = {
88
artistName?: string; // name of artist or undefined if podcast
99
podcastName?: string;
1010
coverArtSrc: string;
11-
coverArtColor: string;
11+
coverArtColor?: [h: number, s: number, l: number];
1212
link: string; // song link, podcast episode link, or playlist link
1313
};
1414

src/services/store/site.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export const createSiteModule = (initialProps: TPageInitialProps) => {
104104
!!updatedNowPlayingData &&
105105
updatedNowPlayingData.uri !== lastNowPlayingData?.uri
106106
) {
107-
console.debug(
107+
console.log(
108108
`Now playing: ${
109109
updatedNowPlayingData.podcastName ?? updatedNowPlayingData.name
110110
}`

0 commit comments

Comments
 (0)