feat: configure user color with CSS

This commit is contained in:
sup39 2024-01-18 05:46:04 +09:00
parent d4174ac449
commit bb4763e509
Signed by: sup39
GPG key ID: 111C00916C1641E5

View file

@ -19,7 +19,9 @@ export function hashCode(str) {
export function cssColorMXID(userId) { export function cssColorMXID(userId) {
const colorNumber = hashCode(userId) % 8; const colorNumber = hashCode(userId) % 8;
return `--mx-uc-${colorNumber + 1}`; // @user:a.b.c => -user-a_b_c
const escapedUserId = userId.replace(/[@:]/g, '-').replace(/[^\w-]/g, '_');
return `--mx-uc-${escapedUserId}, var(--mx-uc-${colorNumber + 1})`;
} }
export default function colorMXID(userId) { export default function colorMXID(userId) {