util.js 979 B

12345678910111213141516171819202122232425262728293031
  1. export function getOffset(value, min, max) {
  2. return (value - min) / (max - min);
  3. }
  4. export function getDirectionStyle(direction, value, min, max) {
  5. var offset = getOffset(value, min, max);
  6. var positionStyle = {};
  7. switch (direction) {
  8. case 'rtl':
  9. positionStyle.right = "".concat(offset * 100, "%");
  10. positionStyle.transform = 'translateX(50%)';
  11. break;
  12. case 'btt':
  13. positionStyle.bottom = "".concat(offset * 100, "%");
  14. positionStyle.transform = 'translateY(50%)';
  15. break;
  16. case 'ttb':
  17. positionStyle.top = "".concat(offset * 100, "%");
  18. positionStyle.transform = 'translateY(-50%)';
  19. break;
  20. default:
  21. positionStyle.left = "".concat(offset * 100, "%");
  22. positionStyle.transform = 'translateX(-50%)';
  23. break;
  24. }
  25. return positionStyle;
  26. }
  27. /** Return index value if is list or return value directly */
  28. export function getIndex(value, index) {
  29. return Array.isArray(value) ? value[index] : value;
  30. }