2022-02-23 13:52:06 +00:00
|
|
|
/** Returns whether a hex color is "bright". */
|
2020-10-10 23:32:27 +00:00
|
|
|
export function isColorBright(color: string): boolean {
|
|
|
|
if (color.startsWith('#')) {
|
|
|
|
color = color.slice(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 4 character hex colors have an alpha value, we only need RGB here so remove
|
|
|
|
// the alpha character.
|
|
|
|
if (color.length === 4) {
|
|
|
|
color = color.slice(0, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 8 character hex colors also have an alpha value, so remove the last 2.
|
|
|
|
if (color.length === 8) {
|
|
|
|
color = color.slice(0, 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3 character hex colors can be represented as 6 character ones too, so
|
|
|
|
// transform it. For example "#123" is the same as "#112233".
|
|
|
|
if (color.length === 3) {
|
|
|
|
color = color
|
|
|
|
.split('')
|
|
|
|
.map((value) => value.repeat(2))
|
|
|
|
.join('');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Split the color up into 3 segments of 2 characters and convert them from
|
|
|
|
// hexadecimal to decimal.
|
|
|
|
const [red, green, blue] = color
|
|
|
|
.split(/(.{2})/)
|
|
|
|
.filter((value) => value !== '')
|
|
|
|
.map((value) => Number.parseInt(value, 16));
|
|
|
|
|
|
|
|
// Magical numbers taken from https://stackoverflow.com/a/12043228/12251171.
|
|
|
|
// "Per ITU-R BT.709"
|
|
|
|
const brightness = 0.2126 * red + 0.7152 * green + 0.0722 * blue;
|
|
|
|
return brightness > 128;
|
|
|
|
}
|
|
|
|
|
2022-02-23 13:52:06 +00:00
|
|
|
/** CSS custom properties from the Tildes themes. */
|
2020-10-10 23:32:27 +00:00
|
|
|
export const themeColors = [
|
|
|
|
{
|
|
|
|
name: 'Background Primary',
|
2022-02-23 13:52:06 +00:00
|
|
|
value: '--background-primary-color',
|
2020-10-10 23:32:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Background Secondary',
|
2022-02-23 13:52:06 +00:00
|
|
|
value: '--background-secondary-color',
|
2020-10-10 23:32:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Foreground Primary',
|
2022-02-23 13:52:06 +00:00
|
|
|
value: '--foreground-primary-color',
|
2020-10-10 23:32:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Foreground Secondary',
|
2022-02-23 13:52:06 +00:00
|
|
|
value: '--foreground-secondary-color',
|
2020-10-10 23:32:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Exemplary',
|
2022-02-23 13:52:06 +00:00
|
|
|
value: '--comment-label-exemplary-color',
|
2020-10-10 23:32:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Off-topic',
|
2022-02-23 13:52:06 +00:00
|
|
|
value: '--comment-label-offtopic-color',
|
2020-10-10 23:32:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Joke',
|
2022-02-23 13:52:06 +00:00
|
|
|
value: '--comment-label-joke-color',
|
2020-10-10 23:32:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Noise',
|
2022-02-23 13:52:06 +00:00
|
|
|
value: '--comment-label-noise-color',
|
2020-10-10 23:32:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Malice',
|
2022-02-23 13:52:06 +00:00
|
|
|
value: '--comment-label-malice-color',
|
2020-10-10 23:32:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Mine',
|
2022-02-23 13:52:06 +00:00
|
|
|
value: '--stripe-mine-color',
|
2020-10-10 23:32:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Official',
|
2022-02-23 13:52:06 +00:00
|
|
|
value: '--alert-color',
|
|
|
|
},
|
2020-10-10 23:32:27 +00:00
|
|
|
];
|