owncast/webroot/js/utils/user-colors.js
Aral Balkan 2409cab5b6
Closes #910: make transparency of message bubbles overridable via CSS (#911)
* Closes #910: make transparency of message bubbles overridable via CSS

* Fix CSS variable declaration
2021-04-11 14:08:06 -07:00

32 lines
898 B
JavaScript

export function messageBubbleColorForString(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
// eslint-disable-next-line
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
// Tweak these to adjust the result of the color
const saturation = 25;
const lightness = 45;
const alpha = 'var(--message-background-alpha)';
const hue = parseInt(Math.abs(hash), 16) % 360;
return `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
}
export function textColorForString(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
// eslint-disable-next-line
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
// Tweak these to adjust the result of the color
const saturation = 80;
const lightness = 80;
const alpha = 0.8;
const hue = parseInt(Math.abs(hash), 16) % 360;
return `hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha})`;
}