UNPKG

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