92 lines
4.9 KiB
JavaScript
92 lines
4.9 KiB
JavaScript
// Собирает образцы: node design/brand-visual/build.mjs (нужны шрифты PT Serif и PT Sans и rsvg-convert)
|
||
import { writeFileSync } from 'node:fs';
|
||
import { execFileSync } from 'node:child_process';
|
||
import { dirname, join } from 'node:path';
|
||
import { fileURLToPath } from 'node:url';
|
||
|
||
const dir = dirname(fileURLToPath(import.meta.url));
|
||
export const C = {
|
||
milk: '#F7F3EC', graphite: '#23262B', navy: '#1F3A5F', terracotta: '#B5472F', mist: '#E3E8EE',
|
||
};
|
||
const H = 'PT Serif', B = 'PT Sans';
|
||
|
||
function lum(hex) {
|
||
const v = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255)
|
||
.map((c) => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4));
|
||
return 0.2126 * v[0] + 0.7152 * v[1] + 0.0722 * v[2];
|
||
}
|
||
export function contrast(a, b) {
|
||
const [x, y] = [lum(a), lum(b)].sort((p, q) => q - p);
|
||
return (x + 0.05) / (y + 0.05);
|
||
}
|
||
|
||
const lines = (arr, x, y, step, attrs) =>
|
||
arr.map((t, i) => `<text x="${x}" y="${y + i * step}" ${attrs}>${t}</text>`).join('');
|
||
|
||
// Образец: канал, вид, размер, фон, с фото или без
|
||
function sample({ w, h, bg, fg, accent, photo, kind }) {
|
||
const m = Math.round(w * 0.07);
|
||
const photoW = kind === 'cover' ? h * 0.7 : Math.min(w, h) * 0.3;
|
||
const textW = photo ? w - photoW - m * 3 : w - m * 2;
|
||
let body = '';
|
||
if (kind === 'post') {
|
||
const big = Math.round(h * (w > h * 1.5 ? 0.095 : 0.062));
|
||
const sm = Math.round(big * 0.5);
|
||
const per = Math.max(14, Math.floor(textW / (big * 0.5)));
|
||
const head = wrap('Клиентский опыт — это система, а не энтузиазм сотрудников.', per);
|
||
const sub = wrap('ИИ делает её сильнее, только если она уже выстроена.', Math.floor(per * 1.5));
|
||
const y0 = m + big * 1.2;
|
||
body += `<rect x="${m}" y="${m}" width="${Math.round(w * 0.08)}" height="8" fill="${accent}"/>`;
|
||
body += lines(head, m, y0 + 20, big * 1.25, `font-family="${H}" font-weight="700" font-size="${big}" fill="${fg}"`);
|
||
const ys = y0 + 20 + head.length * big * 1.25 + sm * 0.6;
|
||
body += lines(sub, m, ys, sm * 1.35, `font-family="${B}" font-size="${sm}" fill="${fg}"`);
|
||
body += `<text x="${m}" y="${h - m}" font-family="${B}" font-weight="700" font-size="${Math.round(sm * 0.8)}" fill="${accent}">Татьяна Сафарова · клиентский опыт и ИИ</text>`;
|
||
} else {
|
||
const big = Math.round(h * 0.2);
|
||
const sm = Math.round(h * 0.085);
|
||
body += `<rect x="${m}" y="${h * 0.2}" width="${Math.round(w * 0.05)}" height="6" fill="${accent}"/>`;
|
||
body += `<text x="${m}" y="${h * 0.2 + big * 1.05}" font-family="${H}" font-weight="700" font-size="${big}" fill="${fg}">Татьяна Сафарова</text>`;
|
||
const per = Math.floor(textW / (sm * 0.5));
|
||
body += lines(wrap('Клиентский сервис, за который клиенты возвращаются. И где в нём работает ИИ.', per),
|
||
m, h * 0.2 + big * 1.05 + sm * 1.6, sm * 1.3, `font-family="${B}" font-size="${sm}" fill="${fg}"`);
|
||
}
|
||
let ph = '';
|
||
if (photo) {
|
||
const r = photoW / 2;
|
||
const cx = w - m - r, cy = kind === 'cover' ? h / 2 : h - m - r - 40;
|
||
ph = `<circle cx="${cx}" cy="${cy}" r="${r}" fill="${C.mist}" stroke="${accent}" stroke-width="6"/>` +
|
||
`<text x="${cx}" y="${cy + 10}" text-anchor="middle" font-family="${B}" font-size="${Math.round(r * 0.25)}" fill="${C.navy}">место для фото</text>`;
|
||
}
|
||
return `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}"><rect width="${w}" height="${h}" fill="${bg}"/>${body}${ph}</svg>`;
|
||
}
|
||
|
||
function wrap(text, per) {
|
||
const out = []; let cur = '';
|
||
for (const word of text.split(' ')) {
|
||
if ((cur + ' ' + word).trim().length > per && cur) { out.push(cur); cur = word; } else cur = (cur + ' ' + word).trim();
|
||
}
|
||
if (cur) out.push(cur);
|
||
return out;
|
||
}
|
||
|
||
const specs = [
|
||
['telegram-post', 1080, 1080, 'post'],
|
||
['telegram-cover', 1280, 720, 'cover'],
|
||
['linkedin-post', 1200, 627, 'post'],
|
||
['linkedin-cover', 1584, 396, 'cover'],
|
||
];
|
||
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
||
for (const [name, w, h, kind] of specs) {
|
||
for (const photo of [false, true]) {
|
||
const dark = kind === 'cover';
|
||
const svg = sample({ w, h, kind, photo, bg: dark ? C.navy : C.milk, fg: dark ? C.milk : C.graphite, accent: dark ? '#F0B8A8' : C.terracotta });
|
||
const base = join(dir, `${name}-${photo ? 'photo' : 'plain'}`);
|
||
writeFileSync(`${base}.svg`, svg);
|
||
execFileSync('rsvg-convert', ['-o', `${base}.png`, `${base}.svg`]);
|
||
}
|
||
}
|
||
const pairs = [['graphite', 'milk'], ['navy', 'milk'], ['terracotta', 'milk'], ['graphite', 'mist'], ['navy', 'mist'], ['milk', 'navy']];
|
||
for (const [a, b] of pairs) console.log(a, 'на', b, contrast(C[a], C[b]).toFixed(1));
|
||
console.log('кор. светлый #F0B8A8 на navy', contrast('#F0B8A8', C.navy).toFixed(1));
|
||
}
|