perf: 将渐变色添加到主题提取逻辑中

This commit is contained in:
zxc 2024-08-10 21:37:11 +08:00
parent bcd8749a75
commit e277a6abac
2 changed files with 12 additions and 3 deletions

View File

@ -139,6 +139,7 @@ const addPoint = (e: MouseEvent) => {
outline: 1px solid #d9d9d9;
box-shadow: 0 0 2px 2px #d9d9d9;
border-radius: 1px;
cursor: pointer;
&.active {
outline: 1px solid $themeColor;

View File

@ -31,8 +31,9 @@ export default () => {
backgroundColorValues.push({ area: 1, value: slide.background.color })
}
else if (slide.background.type === 'gradient' && slide.background.gradient) {
const len = slide.background.gradient.colors.length
backgroundColorValues.push(...slide.background.gradient.colors.map(item => ({
area: 1,
area: 1 / len,
value: item.color,
})))
}
@ -54,6 +55,13 @@ export default () => {
if (el.fill) {
themeColorValues.push({ area, value: el.fill })
}
if (el.type === 'shape' && el.gradient) {
const len = el.gradient.colors.length
themeColorValues.push(...el.gradient.colors.map(item => ({
area: 1 / len * area,
value: item.color,
})))
}
const text = (el.type === 'shape' ? el.text?.content : el.content) || ''
if (!text) continue
@ -160,8 +168,8 @@ export default () => {
for (const item of backgroundColorValues) {
const color = tinycolor(item.value).toRgbString()
if (color === 'rgba(0, 0, 0, 0)') continue
if (!backgroundColors[color]) backgroundColors[color] = 1
else backgroundColors[color] += 1
if (!backgroundColors[color]) backgroundColors[color] = item.area
else backgroundColors[color] += item.area
}
const themeColors: { [key: string]: number } = {}