flow like the river
This commit is contained in:
commit
013fe673f3
42435 changed files with 5764238 additions and 0 deletions
59
VISUALIZACION/node_modules/polished/lib/internalHelpers/_rgbToHsl.js.flow
generated
vendored
Executable file
59
VISUALIZACION/node_modules/polished/lib/internalHelpers/_rgbToHsl.js.flow
generated
vendored
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
// @flow
|
||||
|
||||
import type {
|
||||
HslColor, HslaColor, RgbColor, RgbaColor,
|
||||
} from '../types/color'
|
||||
|
||||
function rgbToHsl(color: RgbColor | RgbaColor): HslColor | HslaColor {
|
||||
// make sure rgb are contained in a set of [0, 255]
|
||||
const red = color.red / 255
|
||||
const green = color.green / 255
|
||||
const blue = color.blue / 255
|
||||
|
||||
const max = Math.max(red, green, blue)
|
||||
const min = Math.min(red, green, blue)
|
||||
const lightness = (max + min) / 2
|
||||
|
||||
if (max === min) {
|
||||
// achromatic
|
||||
if (color.alpha !== undefined) {
|
||||
return {
|
||||
hue: 0,
|
||||
saturation: 0,
|
||||
lightness,
|
||||
alpha: color.alpha,
|
||||
}
|
||||
} else {
|
||||
return { hue: 0, saturation: 0, lightness }
|
||||
}
|
||||
}
|
||||
|
||||
let hue
|
||||
const delta = max - min
|
||||
const saturation = lightness > 0.5 ? delta / (2 - max - min) : delta / (max + min)
|
||||
switch (max) {
|
||||
case red:
|
||||
hue = (green - blue) / delta + (green < blue ? 6 : 0)
|
||||
break
|
||||
case green:
|
||||
hue = (blue - red) / delta + 2
|
||||
break
|
||||
default:
|
||||
// blue case
|
||||
hue = (red - green) / delta + 4
|
||||
break
|
||||
}
|
||||
|
||||
hue *= 60
|
||||
if (color.alpha !== undefined) {
|
||||
return {
|
||||
hue,
|
||||
saturation,
|
||||
lightness,
|
||||
alpha: color.alpha,
|
||||
}
|
||||
}
|
||||
return { hue, saturation, lightness }
|
||||
}
|
||||
|
||||
export default rgbToHsl
|
||||
Loading…
Add table
Add a link
Reference in a new issue