Files
Trilium/apps/client/src/services/css_class_manager.ts

29 lines
718 B
TypeScript
Raw Normal View History

const registeredClasses = new Set<string>();
2022-09-25 14:19:30 +02:00
2024-07-25 20:36:15 +03:00
function createClassForColor(color: string | null) {
2022-09-25 14:19:30 +02:00
if (!color?.trim()) {
return "";
}
const normalizedColorName = color.replace(/[^a-z0-9]/gi, "");
if (!normalizedColorName.trim()) {
return "";
}
const className = `color-${normalizedColorName}`;
2022-09-25 14:19:30 +02:00
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>`);
2022-09-25 14:19:30 +02:00
registeredClasses.add(className);
}
return className;
}
export default {
createClassForColor
};