refactor(swatch-scheme): 优化颜色方案构建逻辑

- 添加颜色和设置的转换为 SwatchEntry 和 SwatchSchemeSetting
- 重构颜色方案生成逻辑以提高清晰度和可维护性
This commit is contained in:
徐涛 2025-07-06 22:09:25 +08:00
parent 199bd8c3e5
commit 2bbb46ced1

View File

@ -150,10 +150,19 @@ export function SwatchSchemeBuilder({ scheme, onBuildCompleted }: SwatchSchemeBu
if (!isEmpty(errMsg)) return errMsg;
const generatedScheme = colorFn?.generate_swatch_scheme(
collected.colors,
collected.setting,
// todo: Convert colors to SwatchEntry[], and settings to SwtachSettings.
const swatchSettings = new SwatchSchemeSetting(
collected.setting.amount,
collected.setting.min_lightness,
collected.setting.max_lightness,
collected.setting.include_primary,
new ColorShifting(
collected.setting.dark_convert.chroma,
collected.setting.dark_convert.lightness,
),
);
const colors = collected.colors.map((c) => new SwatchEntry(c.name, c.color));
const generatedScheme = colorFn?.generate_swatch_scheme(colors, swatchSettings);
updateScheme((prev) => {
prev.schemeStorage.source = collected;
prev.schemeStorage.scheme = mapToObject(generatedScheme[0]) as SwatchScheme;