util.js 1.1 KB

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