/** * ═══════════════════════════════════════════════════ * 万能动态模板 · 自适应任何内容 * ═══════════════════════════════════════════════════ * * 不是固定类型。是根据冰朔的文字内容,现场设计。 */ import { STYLES } from '../config.js' /** * 万能动态卡片 * @param {object} data * @param {string} data.title - 提炼的标题 * @param {string} data.body - 正文 * @param {string[]} data.lines - 原文行数组 * @param {string} data.type - 内容类型(analyzeText 的结果) */ export function dynamicCard(data) { const { title, body, lines = [], type = 'general' } = data const C = STYLES.colors const F = STYLES.fonts const T = STYLES.typography const W = 1080 const H = 1080 // 动态计算字号:内容越多字越小 const totalChars = (title + body).length const titleSize = totalChars < 20 ? 52 : totalChars < 50 ? 44 : 36 const bodySize = totalChars < 50 ? 32 : totalChars < 150 ? 26 : 22 // 检测有没有列表 const hasList = lines.some(l => /^[-•·*]\s/.test(l.trim())) // 检测是不是一句话 const isSingleLine = lines.length <= 2 && totalChars < 40 /* ── 生成内容 HTML ── */ let contentHtml = '' if (isSingleLine) { /* 一句话 · 大字居中 */ contentHtml = `
${escapeHtml(title)}
` } else if (hasList) { /* 列表内容 */ const items = lines .filter(l => /^[-•·*]\s/.test(l.trim())) .map(l => `
  • ${escapeHtml(l.replace(/^[-•·*]\s*/, ''))}
  • `) .join('\n') contentHtml = `
    ${escapeHtml(title)}
    ` } else { /* 一般段落 */ const paragraphs = lines .filter(Boolean) .map(l => `

    ${escapeHtml(l)}

    `) .join('\n') contentHtml = `
    ${escapeHtml(title)}
    ${paragraphs}
    ` } return `
    ${contentHtml}
    ${STYLES.brand.text}
    ` } function escapeHtml(str) { return String(str) .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') }