/**
* 文章编辑器样式模板数据
* 所有 HTML 片段使用内联样式,通过 wangEditor 自定义 styled-block 模块保留样式。
* 模板中使用 {{primary}} / {{primaryLight}} 占位符,由 applyTheme() 替换为实际颜色值。
*/
export interface StyleTemplate {
id: string;
name: string;
category: 'heading' | 'content' | 'block';
preview: string;
html: string;
}
export interface ColorTheme {
id: string;
name: string;
primary: string;
primaryLight: string;
}
export const COLOR_THEMES: ColorTheme[] = [
{ id: 'green', name: '清新绿', primary: '#16a34a', primaryLight: '#dcfce7' },
{ id: 'blue', name: '专业蓝', primary: '#2563eb', primaryLight: '#dbeafe' },
{ id: 'red', name: '暖橘红', primary: '#C4623A', primaryLight: '#F0DDD4' },
{ id: 'purple', name: '雅致紫', primary: '#7c3aed', primaryLight: '#ede9fe' },
{ id: 'amber', name: '琥珀金', primary: '#d97706', primaryLight: '#fef3c7' },
];
const W = 'data-w-e-type="styled-block"';
// ═══════════════════════════════════════
// 标题样式 (6 种)
// ═══════════════════════════════════════
export const HEADING_TEMPLATES: StyleTemplate[] = [
{
id: 'heading-classic',
name: '经典 · 左边框',
category: 'heading',
preview: '▎左边框标题',
html: `
标题文本
`,
},
{
id: 'heading-underline',
name: '简约 · 下划线',
category: 'heading',
preview: '标题 ──────',
html: `标题文本
`,
},
{
id: 'heading-badge',
name: '圆标 · 标签式',
category: 'heading',
preview: '■ 标签式标题',
html: `标题文本
`,
},
{
id: 'heading-centered',
name: '居中标题',
category: 'heading',
preview: '── 居中标题 ──',
html: `标题文本
`,
},
{
id: 'heading-double-line',
name: '双线 · 上下框',
category: 'heading',
preview: '───────\n标题\n───────',
html: `标题文本
`,
},
{
id: 'heading-accent-bar',
name: '色带 · 顶部色条',
category: 'heading',
preview: '━━━\n标题文本',
html: `标题文本
`,
},
];
// ═══════════════════════════════════════
// 内容模板 (13 种)
// ═══════════════════════════════════════
export const CONTENT_TEMPLATES: StyleTemplate[] = [
{
id: 'blockquote',
name: '引用框',
category: 'content',
preview: '▎引用文字...',
html: `引用内容请在此处编辑
`,
},
{
id: 'tip-warning',
name: '提示框 · 警告',
category: 'content',
preview: '⚠ 注意事项',
html: `⚠ 注意事项:请在此处编辑警告内容。
`,
},
{
id: 'tip-info',
name: '提示框 · 信息',
category: 'content',
preview: 'ℹ 补充说明',
html: `ℹ 补充说明:请在此处编辑信息内容。
`,
},
{
id: 'tip-success',
name: '提示框 · 正确',
category: 'content',
preview: '✓ 正确做法',
html: `✓ 正确做法:请在此处编辑推荐内容。
`,
},
{
id: 'tip-danger',
name: '提示框 · 危险',
category: 'content',
preview: '✕ 严禁事项',
html: `✕ 严禁事项:请在此处编辑危险警告内容。
`,
},
{
id: 'tip-primary',
name: '提示框 · 强调',
category: 'content',
preview: '★ 重点强调',
html: `★ 重点强调:请在此处编辑重点内容。
`,
},
{
id: 'list-ordered',
name: '有序列表',
category: 'content',
preview: '① ② ③',
html: ``,
},
{
id: 'list-unordered',
name: '无序列表',
category: 'content',
preview: '• • •',
html: ``,
},
{
id: 'card-image-text',
name: '图文卡片',
category: 'content',
preview: '[图] 文字说明',
html: ``,
},
{
id: 'card-data',
name: '数据卡片',
category: 'content',
preview: '血压 120/80',
html: ``,
},
{
id: 'timeline',
name: '时间线',
category: 'content',
preview: '●── 第一步\n●── 第二步',
html: ``,
},
{
id: 'steps',
name: '步骤流程',
category: 'content',
preview: '➊ → ➋ → ➌',
html: ``,
},
{
id: 'comparison',
name: '对比卡片',
category: 'content',
preview: '✓ 推荐 ✕ 避免',
html: `✓ 推荐做法
推荐内容第一项
推荐内容第二项
推荐内容第三项
✕ 应该避免
避免内容第一项
避免内容第二项
避免内容第三项
`,
},
{
id: 'faq',
name: '问答卡片',
category: 'content',
preview: 'Q: 问题\nA: 回答',
html: `Q:这里填写常见问题?
A:这里填写问题的详细回答内容,帮助读者理解相关知识。
`,
},
{
id: 'highlight-text',
name: '重点高亮',
category: 'content',
preview: '▸ 高亮重点内容',
html: `重点:这里是需要高亮强调的关键内容。
`,
},
{
id: 'key-value',
name: '键值对列表',
category: 'content',
preview: '指标: 数值',
html: ``,
},
];
// ═══════════════════════════════════════
// 区块组件 (6 种)
// ═══════════════════════════════════════
export const BLOCK_TEMPLATES: StyleTemplate[] = [
{
id: 'divider',
name: '分割线 · 虚线',
category: 'block',
preview: '─ ─ ─ ─',
html: ``,
},
{
id: 'divider-gradient',
name: '分割线 · 渐变',
category: 'block',
preview: '━━━━━━━━',
html: ``,
},
{
id: 'section-header',
name: '章节编号',
category: 'block',
preview: '§ 带编号章节',
html: `1章节标题
`,
},
{
id: 'table',
name: '数据表格',
category: 'block',
preview: '⊞ 3×2 表格',
html: `项目
数值
备注
收缩压
120 mmHg
正常
舒张压
80 mmHg
正常
`,
},
{
id: 'progress',
name: '进度指示',
category: 'block',
preview: '█████░░░ 65%',
html: ``,
},
{
id: 'quote-card',
name: '引言卡片',
category: 'block',
preview: '「」引用名言',
html: ``,
},
];
/** 所有模板合并列表 */
export const ALL_TEMPLATES: StyleTemplate[] = [
...HEADING_TEMPLATES,
...CONTENT_TEMPLATES,
...BLOCK_TEMPLATES,
];
/** 将模板 HTML 中的颜色占位符替换为主题实际颜色值 */
export function applyTheme(html: string, theme: ColorTheme): string {
return html
.replaceAll('{{primary}}', theme.primary)
.replaceAll('{{primaryLight}}', theme.primaryLight);
}
/** 根据 ID 查找颜色主题 */
export function getColorTheme(themeId: string): ColorTheme {
return COLOR_THEMES.find((t) => t.id === themeId) ?? COLOR_THEMES[0];
}