Skip to content

Commit

Permalink
fix: broken ci (#95)
Browse files Browse the repository at this point in the history
* fast-color

* chore: update @ant-design/fast-color dependency to version 2.0.6

* fix: improve value handling in getValue function by adding boundary checks for negative values

* test: add test case

* chore: code logic optimization

---------

Co-authored-by: 鹤仙 <[email protected]>
  • Loading branch information
aojunhao123 and guoyunhe authored Dec 31, 2024
1 parent 690cffd commit 6624c7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/generate.ts
Original file line number Diff line number Diff line change
@@ -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; // 色相阶梯
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit 6624c7c

Please sign in to comment.