File size: 835 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
export const calculateChange = (e, hsl, container) => {
const { width: containerWidth, height: containerHeight } = container.getBoundingClientRect()
const x = typeof e.pageX === 'number' ? e.pageX : e.touches[0].pageX
const y = typeof e.pageY === 'number' ? e.pageY : e.touches[0].pageY
let left = x - (container.getBoundingClientRect().left + window.pageXOffset)
let top = y - (container.getBoundingClientRect().top + window.pageYOffset)
if (left < 0) {
left = 0
} else if (left > containerWidth) {
left = containerWidth
}
if (top < 0) {
top = 0
} else if (top > containerHeight) {
top = containerHeight
}
const saturation = left / containerWidth
const bright = 1 - (top / containerHeight)
return {
h: hsl.h,
s: saturation,
v: bright,
a: hsl.a,
source: 'hsv',
}
}
|