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;
9
10function getOffset(value, min, max) {
11 return (value - min) / (max - min);
12}
13
14function getDirectionStyle(direction, value, min, max) {
15 var offset = getOffset(value, min, max);
16 var positionStyle = {};
17
18 switch (direction) {
19 case 'rtl':
20 positionStyle.right = "".concat(offset * 100, "%");
21 positionStyle.transform = 'translateX(50%)';
22 break;
23
24 case 'btt':
25 positionStyle.bottom = "".concat(offset * 100, "%");
26 positionStyle.transform = 'translateY(50%)';
27 break;
28
29 case 'ttb':
30 positionStyle.top = "".concat(offset * 100, "%");
31 positionStyle.transform = 'translateY(-50%)';
32 break;
33
34 default:
35 positionStyle.left = "".concat(offset * 100, "%");
36 positionStyle.transform = 'translateX(-50%)';
37 break;
38 }
39
40 return positionStyle;
41}
42/** Return index value if is list or return value directly */
43
44
45function getIndex(value, index) {
46 return Array.isArray(value) ? value[index] : value;
47}
\No newline at end of file