185 lines
6.1 KiB
JavaScript
185 lines
6.1 KiB
JavaScript
export const concepts = [
|
|
{
|
|
id: "relay",
|
|
name: "Relay",
|
|
tag: "Инженерная ясность",
|
|
en: "Engineering clarity",
|
|
desc: "Левая навигация · нейтральная типографика · тонкие разделители",
|
|
descEn: "Sidebar · neutral typography · fine dividers",
|
|
accent: "#27634c",
|
|
bg: "#f6f8f6",
|
|
ink: "#203f31",
|
|
line: "#ccd8cf",
|
|
radius: "5px",
|
|
font: "Arial, Helvetica, sans-serif",
|
|
layout: "sidebar",
|
|
},
|
|
{
|
|
id: "ledger",
|
|
name: "Ledger",
|
|
tag: "Редакционный порядок",
|
|
en: "Editorial order",
|
|
desc: "Индекс разделов · антиква · широкие строки",
|
|
descEn: "Section index · serif headings · broad rows",
|
|
accent: "#9b3c25",
|
|
bg: "#f5f0e7",
|
|
ink: "#4b3429",
|
|
line: "#c9bca7",
|
|
radius: "0px",
|
|
font: 'Georgia, "Times New Roman", serif',
|
|
layout: "editorial",
|
|
},
|
|
{
|
|
id: "signal",
|
|
name: "Signal",
|
|
tag: "Операционная консоль",
|
|
en: "Operations console",
|
|
desc: "Строка команд · моноширинный шрифт · плотный журнал",
|
|
descEn: "Command bar · monospace · dense log",
|
|
accent: "#26754b",
|
|
bg: "#eaf0e9",
|
|
ink: "#214c31",
|
|
line: "#b6cbbb",
|
|
radius: "0px",
|
|
font: 'Consolas, "Courier New", monospace',
|
|
layout: "terminal",
|
|
},
|
|
{
|
|
id: "axis",
|
|
name: "Axis",
|
|
tag: "Пространство продукта",
|
|
en: "Product workspace",
|
|
desc: "Верхняя навигация · крупные секции · цветовая полоса",
|
|
descEn: "Top navigation · generous sections · color band",
|
|
accent: "#285e9d",
|
|
bg: "#f0f4fa",
|
|
ink: "#173c68",
|
|
line: "#c8d7ed",
|
|
radius: "7px",
|
|
font: '"Segoe UI", Arial, sans-serif',
|
|
layout: "horizontal",
|
|
},
|
|
{
|
|
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",
|
|
},
|
|
{
|
|
id: "grid",
|
|
name: "Grid",
|
|
tag: "Структурный характер",
|
|
en: "Structural character",
|
|
desc: "Контрастная навигация · жёсткая сетка · рубленый ритм",
|
|
descEn: "Contrast navigation · rigid grid · bold rhythm",
|
|
accent: "#a53b21",
|
|
bg: "#f6f5f1",
|
|
ink: "#292a25",
|
|
line: "#bfbfb1",
|
|
radius: "0px",
|
|
font: "Arial, Helvetica, sans-serif",
|
|
layout: "grid",
|
|
},
|
|
];
|
|
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 = {
|
|
relay: ["#151c19", "#1b2520", "#e4ece7", "#aabcb1", "#3c4e42"],
|
|
ledger: ["#211e1a", "#2b2721", "#efe5d6", "#c1b6a6", "#584e41"],
|
|
signal: ["#101a13", "#16231a", "#d4e8d9", "#a4bfa9", "#36533e"],
|
|
axis: ["#141c28", "#1b2738", "#e6edf8", "#a6bad6", "#3b4f6c"],
|
|
dock: ["#111f26", "#192c34", "#e3f2f3", "#a5bec5", "#3b535c"],
|
|
grid: ["#191a18", "#252622", "#f1f1e7", "#b8bcaf", "#53574a"],
|
|
};
|
|
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 backgrounds = dark ? [p[0], p[1]] : [c.bg, c.surface || "#ffffff"];
|
|
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",
|
|
"radius.control": c.radius,
|
|
"font.body": c.id === "ledger" ? "Arial, Helvetica, sans-serif" : c.font,
|
|
"font.heading": c.font,
|
|
"space.unit": "4px",
|
|
"space.section":
|
|
c.id === "dock"
|
|
? density === "compact"
|
|
? "14px"
|
|
: density === "relaxed"
|
|
? "28px"
|
|
: "20px"
|
|
: density === "compact"
|
|
? "18px"
|
|
: density === "relaxed"
|
|
? "36px"
|
|
: "26px",
|
|
"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");
|