1 | import getBasePlacement from "../utils/getBasePlacement.js";
|
---|
2 | import { top, left, right, placements } from "../enums.js"; // eslint-disable-next-line import/no-unused-modules
|
---|
3 |
|
---|
4 | export function distanceAndSkiddingToXY(placement, rects, offset) {
|
---|
5 | var basePlacement = getBasePlacement(placement);
|
---|
6 | var invertDistance = [left, top].indexOf(basePlacement) >= 0 ? -1 : 1;
|
---|
7 |
|
---|
8 | var _ref = typeof offset === 'function' ? offset(Object.assign({}, rects, {
|
---|
9 | placement: placement
|
---|
10 | })) : offset,
|
---|
11 | skidding = _ref[0],
|
---|
12 | distance = _ref[1];
|
---|
13 |
|
---|
14 | skidding = skidding || 0;
|
---|
15 | distance = (distance || 0) * invertDistance;
|
---|
16 | return [left, right].indexOf(basePlacement) >= 0 ? {
|
---|
17 | x: distance,
|
---|
18 | y: skidding
|
---|
19 | } : {
|
---|
20 | x: skidding,
|
---|
21 | y: distance
|
---|
22 | };
|
---|
23 | }
|
---|
24 |
|
---|
25 | function offset(_ref2) {
|
---|
26 | var state = _ref2.state,
|
---|
27 | options = _ref2.options,
|
---|
28 | name = _ref2.name;
|
---|
29 | var _options$offset = options.offset,
|
---|
30 | offset = _options$offset === void 0 ? [0, 0] : _options$offset;
|
---|
31 | var data = placements.reduce(function (acc, placement) {
|
---|
32 | acc[placement] = distanceAndSkiddingToXY(placement, state.rects, offset);
|
---|
33 | return acc;
|
---|
34 | }, {});
|
---|
35 | var _data$state$placement = data[state.placement],
|
---|
36 | x = _data$state$placement.x,
|
---|
37 | y = _data$state$placement.y;
|
---|
38 |
|
---|
39 | if (state.modifiersData.popperOffsets != null) {
|
---|
40 | state.modifiersData.popperOffsets.x += x;
|
---|
41 | state.modifiersData.popperOffsets.y += y;
|
---|
42 | }
|
---|
43 |
|
---|
44 | state.modifiersData[name] = data;
|
---|
45 | } // eslint-disable-next-line import/no-unused-modules
|
---|
46 |
|
---|
47 |
|
---|
48 | export default {
|
---|
49 | name: 'offset',
|
---|
50 | enabled: true,
|
---|
51 | phase: 'main',
|
---|
52 | requires: ['popperOffsets'],
|
---|
53 | fn: offset
|
---|
54 | }; |
---|