修复: 生成质量机制根治——max_tokens截断检测+自动重试/icon白名单机械归一/空image剔除/金句引号伪元素治理/文本溢出扩高+重叠校正/图表y轴自适应防窄幅失真/stat缩字兜底/饼图图例流式排布/卡片icon字体锁定

This commit is contained in:
lxy
2026-08-30 17:27:58 +08:00
parent f7d994842a
commit 4e68773642
11 changed files with 1204 additions and 102 deletions
+68
View File
@@ -0,0 +1,68 @@
/* =====================================================================
* sanitize-contrast.test.ts — 对比度治理测试
* 保护对象:normSlides 内的 sanitizeContrast(深底小字 accent 降级、
* 透明/近背景色空装饰形状丢弃)
* ===================================================================== */
import { describe, it, expect } from 'vitest'
import { normSlides } from '../src/core/ai'
import type { SlideElement } from '../src/core/types'
/* ---------- 测试数据工厂 ---------- */
function textEl(id: string, over: Partial<SlideElement> = {}): SlideElement {
return { id, type: 'text', x: 10, y: 30, w: 60, h: 20, content: '正文', style: { color: 'accent', fontSize: 20 }, ...over }
}
function shapeEl(id: string, over: Partial<SlideElement> = {}): SlideElement {
return { id, type: 'shape', x: 70, y: 80, w: 10, h: 10, content: '', style: { shapeType: 'circle' }, ...over }
}
function norm(background: string, elements: SlideElement[]): SlideElement[] {
return normSlides([{ background, elements }])[0].elements
}
describe('sanitizeContrast 深底小字 accent 降级', () => {
it('深底页 text color=accent fontSize=20 → 降为 muted', () => {
const els = norm('g-primary', [textEl('t')])
expect((els[0].style as any).color).toBe('muted')
})
it('深底页 stat 大数字 color=accent fontSize=72 → 保留 accent', () => {
const els = norm('g-deep', [textEl('st', { type: 'stat', content: '65%', style: { color: 'accent', fontSize: 72 } })])
expect((els[0].style as any).color).toBe('accent')
})
it('浅底页(bgtext color=accent → 不动', () => {
const els = norm('bg', [textEl('t')])
expect((els[0].style as any).color).toBe('accent')
})
it('深底页 text color=accent fontSize=32 → 不动(大字合法)', () => {
const els = norm('primary', [textEl('t', { style: { color: 'accent', fontSize: 32 } })])
expect((els[0].style as any).color).toBe('accent')
})
it('深底页 quote color=muted → 不动(已是 muted', () => {
const els = norm('g-primary', [textEl('q', { type: 'quote', style: { color: 'muted', fontSize: 40 } })])
expect((els[0].style as any).color).toBe('muted')
})
})
describe('sanitizeContrast 空装饰形状丢弃', () => {
it('空装饰形状无 fill(透明)→ 丢弃', () => {
const els = norm('bg', [shapeEl('s1', { style: { shapeType: 'circle' } })])
expect(els.find(e => e.id === 's1')).toBeUndefined()
})
it('空装饰形状 fill=primary 放 g-primary 背景 → 丢弃(同色隐形)', () => {
const els = norm('g-primary', [shapeEl('s1', { style: { shapeType: 'circle', fill: 'primary' } })])
expect(els.find(e => e.id === 's1')).toBeUndefined()
})
it('空装饰形状 fill=accent 放 g-primary 背景 → 保留(不同色)', () => {
const els = norm('g-primary', [shapeEl('s1', { style: { shapeType: 'circle', fill: 'accent' } })])
expect(els.find(e => e.id === 's1')).toBeDefined()
})
it('带内容形状 fill 同背景色 → 保留', () => {
const els = norm('g-primary', [shapeEl('s1', { content: '标签', style: { shapeType: 'bubble', fill: 'primary' } })])
expect(els.find(e => e.id === 's1')).toBeDefined()
})
})