'use strict';
const { esc, fit } = require('../typeset');
// ВАЖНО: внутри — только одиночные кавычки. Эти строки попадают в XML-атрибут
// font-family="...", и двойные кавычки делают SVG невалидным (rsvg-convert и любой
// строгий XML-парсер падают с «Extra content at the end of the document»).
const SERIF = "Georgia, 'Times New Roman', 'DejaVu Serif', serif";
const SANS = "Inter, 'Helvetica Neue', Helvetica, Arial, 'DejaVu Sans', sans-serif";
const MONO = "ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', monospace";
function tagsLine(ctx) {
return (ctx.tags ?? []).slice(0, 3).map((tag) => `#${tag}`).join(' ');
}
/** Крупный плакатный заголовок по центру, тонкая рамка, подпись снизу. */
function poster(ctx) {
const { width: w, height: h, palette: p, uid } = ctx;
const pad = Math.round(w * 0.1);
const title = fit(ctx.title, { maxWidth: w - pad * 2, maxLines: 4, size: Math.round(h * 0.13), min: 22 });
const blockH = title.lines.length * title.lineHeight;
const top = Math.round((h - blockH) / 2 - h * 0.02);
const lines = title.lines
.map((line, i) => `${esc(line)}`)
.join('');
return `
${lines}
${esc((ctx.subtitle ?? '').toUpperCase())}`;
}
/** Геометрия баухауса: круг, прямоугольник, диагональ; заголовок слева снизу. */
function bauhaus(ctx) {
const { width: w, height: h, palette: p, uid } = ctx;
const title = fit(ctx.title, { maxWidth: w * 0.72, maxLines: 3, size: Math.round(h * 0.11), min: 20 });
const baseline = h - Math.round(h * 0.14);
const lines = title.lines
.map((line, i) => `${esc(line)}`)
.join('');
return `
${lines}
${esc(tagsLine(ctx) || (ctx.subtitle ?? ''))}`;
}
/** Конструктивизм: диагональная плашка и наклонный заголовок. */
function constructivist(ctx) {
const { width: w, height: h, palette: p, uid } = ctx;
const title = fit(ctx.title, { maxWidth: w * 0.68, maxLines: 3, size: Math.round(h * 0.105), min: 20 });
const originX = Math.round(w * 0.08);
// Первая строка садится так, чтобы весь блок из 3 строк оставался в кадре даже с наклоном.
const originY = Math.round(h * 0.34) + Math.round(title.lineHeight * 0.6);
const lines = title.lines
.map((line, i) => {
const y = originY + i * title.lineHeight;
return `${esc(line.toUpperCase())}`;
})
.join('');
return `
${lines}
${esc((ctx.subtitle ?? '').toUpperCase())}`;
}
/** Мягкие радиальные пятна: «северное сияние» на тёмном фоне. */
function aurora(ctx) {
const { width: w, height: h, palette: p, uid } = ctx;
const title = fit(ctx.title, { maxWidth: w * 0.78, maxLines: 4, size: Math.round(h * 0.1), min: 20 });
const blockH = title.lines.length * title.lineHeight;
const top = Math.round((h - blockH) / 2);
const lines = title.lines
.map((line, i) => `${esc(line)}`)
.join('');
return `
${lines}
${esc(tagsLine(ctx))}`;
}
/** Минимализм: линейки, серифный заголовок, автор внизу. */
function paper(ctx) {
const { width: w, height: h, palette: p } = ctx;
const pad = Math.round(w * 0.09);
const title = fit(ctx.title, { maxWidth: w - pad * 2, maxLines: 4, size: Math.round(h * 0.1), min: 20 });
const lines = title.lines
.map((line, i) => `${esc(line)}`)
.join('');
const rules = [0.14, 0.3, 0.84, 0.9]
.map((y) => ``)
.join('');
return `
${rules}
${lines}
${esc((ctx.subtitle ?? '').toUpperCase())}
${esc(ctx.author ?? '')}`;
}
const STYLES = { poster, bauhaus, constructivist, aurora, paper };
module.exports = { STYLES, SERIF, SANS, MONO };