client-ts: Port services/css_class_manager

This commit is contained in:
Elian Doran
2024-07-25 00:01:39 +03:00
parent 81327a09d5
commit 6c94cbf388
3 changed files with 19 additions and 2 deletions

View File

@@ -0,0 +1,28 @@
const registeredClasses = new Set<string>();
function createClassForColor(color: string) {
if (!color?.trim()) {
return "";
}
const normalizedColorName = color.replace(/[^a-z0-9]/gi, "");
if (!normalizedColorName.trim()) {
return "";
}
const className = `color-${normalizedColorName}`;
if (!registeredClasses.has(className)) {
// make the active fancytree selector more specific than the normal color setting
$("head").append(`<style>.${className}, span.fancytree-active.${className} { color: ${color} !important; }</style>`);
registeredClasses.add(className);
}
return className;
}
export default {
createClassForColor
};