Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
hsva () {
let prevHsva = this.previousHsva
let hsva = tinycolor(this.color).toHsv()
// fix
if (prevHsva.h % 360 === hsva.h % 360) {
// 因为色相是 360度循环的,360 被 tinycolor 转换成了 0,直接用的话会导致滑块跳变,所以这个特殊处理下
hsva.h = prevHsva.h
}
if (tinycolor.equals(hsva, prevHsva)) {
// 连续纯黑色情况下(SaturationBrightnessField底部区域),
// 传出再传入的 hsv 不一样,导致信息丢失,这里恢复一下,不然取色圈会跳变
// hsv(40, 0.001, 0.001) -> rgb(0, 0, 0) -> hsv(0, 0, 0)
hsva.h = prevHsva.h
hsva.s = prevHsva.s
}
if (hsva.s === 0 && prevHsva.s !== 0) {
hsva.h = prevHsva.h
}
if (hsva.h === undefined) {
hsva.h = prevHsva.h
}
if (!this.uiProps.alpha) {
hsva.a = 1
}
componentWillReceiveProps(nextProps) {
if (!tinycolor.equals(nextProps.color, this.state.color)) {
const c = tinycolor(nextProps.color).toHsv()
this.setState({
color: this.toPercentage(c),
})
}
}
private static equals(color1: MaybeColor, color2: MaybeColor) {
if (_.isNil(color1) || _.isNil(color2)) {
return false
}
return tinycolor.equals(color1, color2)
}
{color => {
const match = tinycolor.equals(color, value);
const icon = match ? (
) : null;
return (
!match && onChange(color)}
className="canvasColorPalette__dot"
>
{icon}
);
}}
const match = colors.filter(color => tinycolor.equals(value, color));
canRemove = match.length > 0;
handlePaletteColorAdd () {
if (tinycolor.equals(this.color, this.colors[this.colors.length - 1])) {
return
}
this.colors.push(this.color)
}
}