104 lines
3.5 KiB
JavaScript
104 lines
3.5 KiB
JavaScript
export const concepts = [
|
|
{
|
|
id: "dock",
|
|
name: "Dock",
|
|
tag: "Персональный инструмент",
|
|
en: "Personal instrument",
|
|
desc: "Компактная панель · раскрытие поверх контента · петроль и бирюза",
|
|
descEn: "Compact rail · overlay navigation · petrol and teal",
|
|
accent: "#12616a",
|
|
darkAccent: "#77cbbb",
|
|
surface: "#fbfdfd",
|
|
text: "#173239",
|
|
muted: "#4c666d",
|
|
bg: "#edf3f3",
|
|
ink: "#173f49",
|
|
line: "#c6d7da",
|
|
radius: "10px",
|
|
font: '"Trebuchet MS", Arial, sans-serif',
|
|
layout: "rail",
|
|
},
|
|
];
|
|
export function tokensFor(id, theme = "light", accent, density = "normal") {
|
|
const c = concepts.find((c) => c.id === id) || concepts[0];
|
|
const dark = theme === "dark";
|
|
const palettes = {
|
|
dock: ["#111f26", "#192c34", "#e3f2f3", "#a5bec5", "#3b535c"],
|
|
};
|
|
const p = palettes[c.id];
|
|
let selected = accent || (dark ? c.darkAccent || c.accent : c.accent);
|
|
const luminance = (hex) =>
|
|
hex
|
|
.match(/\w\w/g)
|
|
.map((x) => parseInt(x, 16) / 255)
|
|
.map((x) => (x <= 0.04045 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4))
|
|
.reduce((s, v, i) => s + v * [0.2126, 0.7152, 0.0722][i], 0);
|
|
const contrast = (a, b) => {
|
|
const x = luminance(a),
|
|
y = luminance(b);
|
|
return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);
|
|
};
|
|
const rowHover = dark ? "#27434b" : "#dcebed";
|
|
const rowActive = dark ? "#2b4a53" : "#cde3e5";
|
|
const backgrounds = [
|
|
...(dark ? [p[0], p[1]] : [c.bg, c.surface || "#ffffff"]),
|
|
rowHover,
|
|
rowActive,
|
|
];
|
|
for (
|
|
let i = 0;
|
|
i < 100 && backgrounds.some((bg) => contrast(selected, bg) < 4.5);
|
|
i++
|
|
)
|
|
selected =
|
|
"#" +
|
|
selected
|
|
.match(/\w\w/g)
|
|
.map((v) =>
|
|
Math.round(parseInt(v, 16) * 0.95 + (dark ? 255 * 0.05 : 0))
|
|
.toString(16)
|
|
.padStart(2, "0"),
|
|
)
|
|
.join("");
|
|
// Accent is also used for text; normalize it for both surfaces before choosing button text.
|
|
const rgb = selected.match(/\w\w/g).map((x) => parseInt(x, 16));
|
|
const lum = rgb
|
|
.map((x) => {
|
|
x /= 255;
|
|
return x <= 0.04045 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;
|
|
})
|
|
.reduce((s, v, i) => s + v * [0.2126, 0.7152, 0.0722][i], 0);
|
|
const on = lum > 0.179 ? "#101810" : "#ffffff";
|
|
return {
|
|
"color.bg": dark ? p[0] : c.bg,
|
|
"color.surface": dark ? p[1] : c.surface || "#ffffff",
|
|
"color.text": dark ? p[2] : c.text || "#202622",
|
|
"color.muted": dark ? p[3] : c.muted || "#59635e",
|
|
"color.border": dark ? p[4] : c.line,
|
|
"color.accent": selected,
|
|
"color.on-accent": on,
|
|
"color.danger": dark ? "#ffafa5" : "#a22923",
|
|
"color.success": dark ? "#a2d3ab" : "#26623b",
|
|
"color.warning": dark ? "#e8c889" : "#795519",
|
|
"color.row-hover": rowHover,
|
|
"color.row-active": rowActive,
|
|
"radius.control": c.radius,
|
|
"font.body": c.font,
|
|
"font.heading": c.font,
|
|
"space.unit": "4px",
|
|
"space.section":
|
|
density === "compact" ? "14px" : density === "relaxed" ? "28px" : "20px",
|
|
"size.control":
|
|
density === "compact" ? "34px" : density === "relaxed" ? "46px" : "40px",
|
|
"space.cell":
|
|
density === "compact" ? "9px" : density === "relaxed" ? "18px" : "13px",
|
|
"motion.duration": "120ms",
|
|
"layout.kind": c.layout,
|
|
};
|
|
}
|
|
export const cssVars = (t) =>
|
|
Object.entries(t)
|
|
.filter(([k]) => k !== "layout.kind")
|
|
.map(([k, v]) => `--${k.replaceAll(".", "-")}: ${v};`)
|
|
.join("\n");
|