mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-05 21:48:19 +08:00
46 lines
1006 B
TypeScript
46 lines
1006 B
TypeScript
|
/* eslint-disable class-methods-use-this */
|
||
|
import type { ColorGenInput } from '@rc-component/color-picker';
|
||
|
import { Color as RcColor } from '@rc-component/color-picker';
|
||
|
import { getHex } from './util';
|
||
|
|
||
|
export interface Color
|
||
|
extends Pick<
|
||
|
RcColor,
|
||
|
'toHsb' | 'toHsbString' | 'toHex' | 'toHexString' | 'toRgb' | 'toRgbString'
|
||
|
> {}
|
||
|
|
||
|
export class ColorFactory {
|
||
|
/** Original Color object */
|
||
|
private metaColor: RcColor;
|
||
|
|
||
|
constructor(color: ColorGenInput<Color>) {
|
||
|
this.metaColor = new RcColor(color as ColorGenInput);
|
||
|
}
|
||
|
|
||
|
toHsb() {
|
||
|
return this.metaColor.toHsb();
|
||
|
}
|
||
|
|
||
|
toHsbString() {
|
||
|
return this.metaColor.toHsbString();
|
||
|
}
|
||
|
|
||
|
toHex() {
|
||
|
return getHex(this.toHexString(), this.metaColor.getAlpha() < 1);
|
||
|
}
|
||
|
|
||
|
toHexString() {
|
||
|
return this.metaColor.getAlpha() === 1
|
||
|
? this.metaColor.toHexString()
|
||
|
: this.metaColor.toHex8String();
|
||
|
}
|
||
|
|
||
|
toRgb() {
|
||
|
return this.metaColor.toRgb();
|
||
|
}
|
||
|
|
||
|
toRgbString() {
|
||
|
return this.metaColor.toRgbString();
|
||
|
}
|
||
|
}
|