diff --git a/src/generate.ts b/src/generate.ts index 0ea3d1c..0424406 100644 --- a/src/generate.ts +++ b/src/generate.ts @@ -1,4 +1,4 @@ -import type { ColorInput} from '@ant-design/fast-color'; +import type { ColorInput } from '@ant-design/fast-color'; import { FastColor } from '@ant-design/fast-color'; const hueStep = 2; // 色相阶梯 @@ -79,9 +79,8 @@ function getValue(hsv: HsvObject, i: number, light?: boolean): number { } else { value = hsv.v - brightnessStep2 * i; } - if (value > 1) { - value = 1; - } + // Clamp value between 0 and 1 + value = Math.max(0, Math.min(1, value)); return Math.round(value * 100) / 100; } diff --git a/tests/index.test.ts b/tests/index.test.ts index d2ee21b..d154970 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -83,3 +83,9 @@ test('should contain preseted palettes', () => { ]); expect([...presetPalettes.blue]).toEqual(presetBlueColors); }); + +test('Generate grey colors', () => { + // 测试灰色(h=0, s=0 的特殊情况) + expect(generate('#666666')).toBeTruthy(); + expect(generate('#666666', { theme: 'dark' })).toBeTruthy(); +});