'use strict'; const { paletteFor, paletteByName, hash } = require('./palette'); const { STYLES } = require('./styles'); const STYLE_NAMES = Object.keys(STYLES); /** * @param {{title:string, subtitle?:string, author?:string, tags?:string[], slug?:string, * style?:string, width?:number, height?:number, background?:string}} input * @returns {string} SVG-документ */ function render(input) { const title = String(input.title ?? '').trim(); if (!title) throw new Error('title is required'); const seed = String(input.slug || title).toLowerCase(); const styleName = input.style && input.style !== 'auto' ? input.style : STYLE_NAMES[hash(seed) % STYLE_NAMES.length]; const style = STYLES[styleName]; if (!style) { throw new Error(`unknown style "${styleName}", available: ${STYLE_NAMES.join(', ')}`); } const width = Math.max(320, Math.min(4000, Number(input.width) || 1200)); const height = Math.max(320, Math.min(4000, Number(input.height) || 630)); const tags = Array.isArray(input.tags) ? input.tags.map((tag) => String(tag).trim()).filter(Boolean) : String(input.tags ?? '').split(',').map((tag) => tag.trim()).filter(Boolean); const body = style({ width, height, title, subtitle: input.subtitle ?? '', author: input.author ?? '', tags, palette: paletteByName(input.palette) ?? paletteFor(seed), uid: (hash(seed) % 99991).toString(36), }); return ` ${body} `; } function escapeAttr(value) { return String(value).replace(/&/g, '&').replace(/