brendmanager/design/brand-visual/build.mjs
Peppa ba63f1ffb7
All checks were successful
peppa/lint lint: success за 1с
peppa/test test: success за 1с
ci / checks (pull_request) Successful in 9s
deploy / deploy (pull_request) Successful in 16s
BRM-41: имя на обложках Telegram помещается целиком и не заходит на круг
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 23:27:09 +05:00

97 lines
5.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Собирает образцы: 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, fitName }) {
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 {
let big = Math.round(h * 0.2);
// Обложка Telegram: имя («Татьяна Сафарова» ≈ 9,3 ширины кегля) целиком, с запасом до края и до круга для фото
if (fitName) {
const room = photo ? w - m - photoW - 6 - 40 - m : w - m * 2 - 60;
big = Math.min(big, Math.floor(room / 9.3));
}
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, fitName: name === 'telegram-cover', 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));
}