-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathposition.ts
More file actions
53 lines (48 loc) · 1.04 KB
/
Copy pathposition.ts
File metadata and controls
53 lines (48 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { posMod } from '@stdlib/misc';
export type CSSPosition = 'left' | 'top' | 'right' | 'bottom';
export function posToIndex(pos: CSSPosition) {
switch (pos) {
case 'left':
return 0;
case 'top':
return 1;
case 'right':
return 2;
case 'bottom':
return 3;
}
}
export function indexToPos(index: number): CSSPosition {
switch (posMod(index, 4)) {
case 0:
return 'left';
case 1:
return 'top';
case 2:
return 'right';
case 3:
return 'bottom';
default:
return 'top';
}
}
export function indexToPosBasis(index: number): CSSPosition {
if (posMod(index, 2) === 0) {
return 'left';
} else {
return 'top';
}
}
export function posToBasis(pos: CSSPosition): CSSPosition {
return indexToPosBasis(posToIndex(pos));
}
export function flipPos(pos: CSSPosition): CSSPosition {
return indexToPos(posToIndex(pos) + 2);
}
export function flipPosBasis(basis: CSSPosition): CSSPosition {
if (basis === 'left') {
return 'top';
} else {
return 'left';
}
}