source: imaps-frontend/node_modules/@popperjs/core/lib/utils/computeOffsets.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
Line 
1import getBasePlacement from "./getBasePlacement.js";
2import getVariation from "./getVariation.js";
3import getMainAxisFromPlacement from "./getMainAxisFromPlacement.js";
4import { top, right, bottom, left, start, end } from "../enums.js";
5export default function computeOffsets(_ref) {
6 var reference = _ref.reference,
7 element = _ref.element,
8 placement = _ref.placement;
9 var basePlacement = placement ? getBasePlacement(placement) : null;
10 var variation = placement ? getVariation(placement) : null;
11 var commonX = reference.x + reference.width / 2 - element.width / 2;
12 var commonY = reference.y + reference.height / 2 - element.height / 2;
13 var offsets;
14
15 switch (basePlacement) {
16 case top:
17 offsets = {
18 x: commonX,
19 y: reference.y - element.height
20 };
21 break;
22
23 case bottom:
24 offsets = {
25 x: commonX,
26 y: reference.y + reference.height
27 };
28 break;
29
30 case right:
31 offsets = {
32 x: reference.x + reference.width,
33 y: commonY
34 };
35 break;
36
37 case left:
38 offsets = {
39 x: reference.x - element.width,
40 y: commonY
41 };
42 break;
43
44 default:
45 offsets = {
46 x: reference.x,
47 y: reference.y
48 };
49 }
50
51 var mainAxis = basePlacement ? getMainAxisFromPlacement(basePlacement) : null;
52
53 if (mainAxis != null) {
54 var len = mainAxis === 'y' ? 'height' : 'width';
55
56 switch (variation) {
57 case start:
58 offsets[mainAxis] = offsets[mainAxis] - (reference[len] / 2 - element[len] / 2);
59 break;
60
61 case end:
62 offsets[mainAxis] = offsets[mainAxis] + (reference[len] / 2 - element[len] / 2);
63 break;
64
65 default:
66 }
67 }
68
69 return offsets;
70}
Note: See TracBrowser for help on using the repository browser.