Skip to content

Commit aafa343

Browse files
authoredDec 12, 2024··
perf(preset-mini): reduce redundant getThemeColor (#4324)
1 parent 121d3a6 commit aafa343

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed
 

‎packages/preset-mini/src/_utils/utilities.ts

+12-17
Original file line numberDiff line numberDiff line change
@@ -128,26 +128,21 @@ export function parseColor(body: string, theme: Theme, key?: ThemeColorKeys): Pa
128128

129129
let no = 'DEFAULT'
130130
if (!color) {
131-
let colorData
131+
let keys = colors
132+
let _no
132133
const [scale] = colors.slice(-1)
134+
133135
if (/^\d+$/.test(scale)) {
134-
no = scale
135-
colorData = getThemeColor(theme, colors.slice(0, -1), key)
136-
if (!colorData || typeof colorData === 'string')
137-
color = undefined
138-
else
139-
color = colorData[no] as string
136+
no = _no = scale
137+
keys = colors.slice(0, -1)
140138
}
141-
else {
142-
colorData = getThemeColor(theme, colors, key)
143-
if (!colorData && colors.length <= 2) {
144-
[, no = no] = colors
145-
colorData = getThemeColor(theme, [name], key)
146-
}
147-
if (typeof colorData === 'string')
148-
color = colorData
149-
else if (no && colorData)
150-
color = colorData[no] as string
139+
140+
const colorData = getThemeColor(theme, keys, key)
141+
if (typeof colorData === 'object') {
142+
color = colorData[_no ?? no] as string
143+
}
144+
else if (typeof colorData === 'string' && !_no) {
145+
color = colorData
151146
}
152147
}
153148

0 commit comments

Comments
 (0)
Please sign in to comment.