@storm-software/config-tools
Version:
A package containing various utilities to support custom workspace configurations and environment management for Storm Software projects, including configuration file handling, environment variable management, and logging utilities.
84 lines (82 loc) • 2.38 kB
JavaScript
// src/utilities/colors.ts
var DEFAULT_COLOR_CONFIG = {
light: {
background: "#fafafa",
foreground: "#1d1e22",
brand: "#1fb2a6",
alternate: "#db2777",
help: "#5C4EE5",
success: "#087f5b",
info: "#0550ae",
debug: "#8afafc",
warning: "#e3b341",
danger: "#D8314A",
fatal: "#51070f",
performance: "#13c302",
link: "#3fa6ff",
positive: "#22c55e",
negative: "#dc2626",
gradient: ["#1fb2a6", "#db2777", "#5C4EE5"]
},
dark: {
background: "#1d1e22",
foreground: "#cbd5e1",
brand: "#2dd4bf",
alternate: "#db2777",
help: "#818cf8",
success: "#10b981",
info: "#58a6ff",
debug: "#8afafc",
warning: "#f3d371",
danger: "#D8314A",
fatal: "#a40e26",
performance: "#80fd74",
link: "#3fa6ff",
positive: "#22c55e",
negative: "#dc2626",
gradient: ["#1fb2a6", "#db2777", "#818cf8"]
}
};
function getColors(config) {
if (!config?.colors || typeof config.colors !== "object" || !config.colors["dark"] && (!config.colors["base"] || typeof config.colors !== "object" || !config.colors["base"]?.["dark"])) {
return DEFAULT_COLOR_CONFIG;
}
if (config.colors["base"]) {
if (typeof config.colors["base"]["dark"] === "object") {
return config.colors["base"]["dark"];
} else if (config.colors["base"]["dark"] === "string") {
return config.colors["base"];
}
}
if (typeof config.colors["dark"] === "object") {
return config.colors["dark"];
}
return config.colors ?? DEFAULT_COLOR_CONFIG;
}
function getColor(key, config) {
const colors = getColors(config);
const result = (typeof colors["dark"] === "object" ? colors["dark"][key] : colors[key]) || DEFAULT_COLOR_CONFIG["dark"][key] || DEFAULT_COLOR_CONFIG[key];
if (result) {
return result;
}
if (key === "link" || key === "debug") {
return getColor("info", config);
} else if (key === "fatal") {
return getColor("danger", config);
}
return getColor("brand", config);
}
function getGradient(config) {
const colors = getColors(config);
const result = (typeof colors["dark"] === "object" ? colors["dark"].gradient : colors.gradient) || DEFAULT_COLOR_CONFIG["dark"].gradient;
if (result && Array.isArray(result) && result.length > 0) {
return result;
}
return void 0;
}
export {
DEFAULT_COLOR_CONFIG,
getColors,
getColor,
getGradient
};