Calio/shared/theme.js
Elijah 6fc0a01c56
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 1m4s
first commit
2026-10-20 19:04:12 -07:00

55 lines
1.6 KiB
JavaScript

export const DEFAULT_ACCENT = "#8391ed";
export const accentPresets = [
{ name: "Periwinkle", color: "#8391ed" },
{ name: "Sky", color: "#6daed9" },
{ name: "Lavender", color: "#b28adc" },
{ name: "Rose", color: "#d780a2" },
{ name: "Amber", color: "#d9a65d" },
{ name: "Sage", color: "#8ca37a" },
];
function rgb(hex) {
return [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16));
}
export function mixColor(color, other, fraction) {
const first = rgb(color);
const second = rgb(other);
return (
"#" +
first
.map((value, i) =>
Math.round(value * (1 - fraction) + second[i] * fraction)
.toString(16)
.padStart(2, "0"),
)
.join("")
);
}
export function contrastText(color) {
const [r, g, b] = rgb(color).map((v) => {
const s = v / 255;
return s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
});
return r * 0.2126 + g * 0.7152 + b * 0.0722 > 0.179 ? "#000000" : "#ffffff";
}
export function accentPalette(value, dark) {
const accent = /^#[a-fA-F0-9]{6}$/.test(value || "") ? value : DEFAULT_ACCENT;
const hover = mixColor(accent, dark ? "#ffffff" : "#000000", 0.12);
return {
"--accent": accent,
"--accent-dark": hover,
"--accent-soft": mixColor(
accent,
dark ? "#191a20" : "#ffffff",
dark ? 0.84 : 0.9,
),
"--accent-text": mixColor(
accent,
dark ? "#ffffff" : "#000000",
dark ? 0.28 : 0.26,
),
"--on-accent": contrastText(accent),
"--on-accent-hover": contrastText(hover),
"--orb-light": mixColor(accent, "#ffffff", dark ? 0.22 : 0.38),
"--orb-dark": mixColor(accent, "#000000", 0.04),
};
}