UNPKG

978 BJavaScriptView Raw
1export function getOffset(value, min, max) {
2 return (value - min) / (max - min);
3}
4export 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 */
28export function getIndex(value, index) {
29 return Array.isArray(value) ? value[index] : value;
30}
\No newline at end of file