UNPKG

2.58 kBPlain TextView Raw
1/*
2 * Copyright 2015 Palantir Technologies, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17export const Position = {
18 BOTTOM: "bottom" as "bottom",
19 BOTTOM_LEFT: "bottom-left" as "bottom-left",
20 BOTTOM_RIGHT: "bottom-right" as "bottom-right",
21 LEFT: "left" as "left",
22 LEFT_BOTTOM: "left-bottom" as "left-bottom",
23 LEFT_TOP: "left-top" as "left-top",
24 RIGHT: "right" as "right",
25 RIGHT_BOTTOM: "right-bottom" as "right-bottom",
26 RIGHT_TOP: "right-top" as "right-top",
27 TOP: "top" as "top",
28 TOP_LEFT: "top-left" as "top-left",
29 TOP_RIGHT: "top-right" as "top-right",
30};
31// eslint-disable-next-line @typescript-eslint/no-redeclare
32export type Position = typeof Position[keyof typeof Position];
33
34export function isPositionHorizontal(position: Position) {
35 /* istanbul ignore next */
36 return (
37 position === Position.TOP ||
38 position === Position.TOP_LEFT ||
39 position === Position.TOP_RIGHT ||
40 position === Position.BOTTOM ||
41 position === Position.BOTTOM_LEFT ||
42 position === Position.BOTTOM_RIGHT
43 );
44}
45
46export function isPositionVertical(position: Position) {
47 /* istanbul ignore next */
48 return (
49 position === Position.LEFT ||
50 position === Position.LEFT_TOP ||
51 position === Position.LEFT_BOTTOM ||
52 position === Position.RIGHT ||
53 position === Position.RIGHT_TOP ||
54 position === Position.RIGHT_BOTTOM
55 );
56}
57
58export function getPositionIgnoreAngles(position: Position) {
59 if (position === Position.TOP || position === Position.TOP_LEFT || position === Position.TOP_RIGHT) {
60 return Position.TOP;
61 } else if (
62 position === Position.BOTTOM ||
63 position === Position.BOTTOM_LEFT ||
64 position === Position.BOTTOM_RIGHT
65 ) {
66 return Position.BOTTOM;
67 } else if (position === Position.LEFT || position === Position.LEFT_TOP || position === Position.LEFT_BOTTOM) {
68 return Position.LEFT;
69 } else {
70 return Position.RIGHT;
71 }
72}