UNPKG

react-color

Version:

A Collection of Color Pickers from Sketch, Photoshop, Chrome & more

49 lines (46 loc) 1.22 kB
export var calculateChange = function calculateChange(e, hsl, direction, initialA, container) { var containerWidth = container.clientWidth; var containerHeight = container.clientHeight; var x = typeof e.pageX === 'number' ? e.pageX : e.touches[0].pageX; var y = typeof e.pageY === 'number' ? e.pageY : e.touches[0].pageY; var left = x - (container.getBoundingClientRect().left + window.pageXOffset); var top = y - (container.getBoundingClientRect().top + window.pageYOffset); if (direction === 'vertical') { var a = void 0; if (top < 0) { a = 0; } else if (top > containerHeight) { a = 1; } else { a = Math.round(top * 100 / containerHeight) / 100; } if (hsl.a !== a) { return { h: hsl.h, s: hsl.s, l: hsl.l, a: a, source: 'rgb' }; } } else { var _a = void 0; if (left < 0) { _a = 0; } else if (left > containerWidth) { _a = 1; } else { _a = Math.round(left * 100 / containerWidth) / 100; } if (initialA !== _a) { return { h: hsl.h, s: hsl.s, l: hsl.l, a: _a, source: 'rgb' }; } } return null; };