fix: getAlphaColor should ignore alpha color (#37720)

This commit is contained in:
MadCcc 2022-09-23 17:31:21 +08:00 committed by GitHub
parent 5d37e6264d
commit 06d2c48c31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -0,0 +1,9 @@
import getAlphaColor from '../util/getAlphaColor';
describe('util', () => {
describe('getAlphaColor', () => {
it('should not process color with alpha', () => {
expect(getAlphaColor('rgba(0, 0, 0, 0.5)', 'rgba(255, 255, 255)')).toBe('rgba(0, 0, 0, 0.5)');
});
});
});

View File

@ -5,7 +5,11 @@ function isStableColor(color: number): boolean {
}
function getAlphaColor(frontColor: string, backgroundColor: string): string {
const { r: fR, g: fG, b: fB } = new TinyColor(frontColor).toRgb();
const { r: fR, g: fG, b: fB, a: originAlpha } = new TinyColor(frontColor).toRgb();
if (originAlpha < 1) {
return frontColor;
}
const { r: bR, g: bG, b: bB } = new TinyColor(backgroundColor).toRgb();
for (let fA = 0.01; fA <= 1; fA += 0.01) {