Files

17 lines
765 B
JavaScript

const DEFAULT_USER_COLOR = '#2563eb';
const USER_COLORS = ['#2563eb', '#7c3aed', '#db2777', '#dc2626', '#ea580c', '#d97706', '#16a34a', '#0d9488', '#0891b2', '#4f46e5', '#9333ea', '#475569'];
function normalizeUserColor(value, fallback) {
const raw = String(value === undefined || value === null ? '' : value).trim();
if (/^#[0-9a-fA-F]{6}$/.test(raw)) return raw.toLowerCase();
const base = String(fallback === undefined || fallback === null ? '' : fallback).trim();
if (/^#[0-9a-fA-F]{6}$/.test(base)) return base.toLowerCase();
return DEFAULT_USER_COLOR;
}
function randomUserColor() {
return USER_COLORS[Math.floor(Math.random() * USER_COLORS.length)];
}
module.exports = { DEFAULT_USER_COLOR, USER_COLORS, normalizeUserColor, randomUserColor };