@krainovsd/js-helpers 0.13.4 → 0.13.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.cjs +229 -350
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/lib/api/core.js +21 -8
- package/lib/esm/lib/api/core.js.map +1 -1
- package/lib/esm/lib/browser/get-visible-position.js +208 -342
- package/lib/esm/lib/browser/get-visible-position.js.map +1 -1
- package/lib/index.d.ts +4 -3
- package/package.json +1 -1
|
@@ -12,36 +12,37 @@ function getVisiblePosition({ initialPosition, node, visibleArea, placement = "b
|
|
|
12
12
|
placement === "right-top" ||
|
|
13
13
|
placement === "right-center"
|
|
14
14
|
? 0
|
|
15
|
-
: 10, flex, }) {
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
15
|
+
: 10, flex, nested, }) {
|
|
16
|
+
/** Viewport Variables */
|
|
17
|
+
const viewport = visibleArea ?? document.documentElement;
|
|
18
|
+
const scrollTop = document.documentElement.scrollTop;
|
|
19
|
+
const scrollLeft = document.documentElement.scrollLeft;
|
|
20
|
+
const rect = viewport.getBoundingClientRect();
|
|
21
|
+
const viewportWidth = viewport.clientWidth;
|
|
22
|
+
const viewportHeight = viewport.clientHeight;
|
|
23
|
+
const xStart = visibleArea ? viewport.offsetLeft - viewport.scrollLeft : Math.abs(rect.left);
|
|
24
|
+
const xEnd = xStart + viewportWidth;
|
|
25
|
+
const yStart = visibleArea ? viewport.offsetTop : Math.abs(rect.top);
|
|
26
|
+
const yEnd = yStart + viewportHeight;
|
|
27
|
+
/** Target Variables */
|
|
29
28
|
let targetHeight = 0;
|
|
30
29
|
let targetWidth = 0;
|
|
31
|
-
let
|
|
30
|
+
let targetTopPosition = 0;
|
|
31
|
+
let targetLeftPosition = 0;
|
|
32
|
+
const { height: nodeHeight, width: nodeWidth } = node.getBoundingClientRect();
|
|
32
33
|
if (initialPosition?.targetNode) {
|
|
33
|
-
const { top
|
|
34
|
+
const { top, left, height, width } = initialPosition.targetNode.getBoundingClientRect();
|
|
34
35
|
targetHeight = height;
|
|
35
36
|
targetWidth = width;
|
|
36
|
-
targetTopPosition =
|
|
37
|
-
targetLeftPosition =
|
|
37
|
+
targetTopPosition = top + scrollTop;
|
|
38
|
+
targetLeftPosition = left + scrollLeft;
|
|
38
39
|
}
|
|
39
40
|
if (initialPosition?.position) {
|
|
40
41
|
if (initialPosition.position.x) {
|
|
41
|
-
targetLeftPosition = initialPosition.position.x;
|
|
42
|
+
targetLeftPosition = initialPosition.position.x + scrollLeft;
|
|
42
43
|
}
|
|
43
44
|
if (initialPosition.position.y) {
|
|
44
|
-
targetTopPosition = initialPosition.position.y;
|
|
45
|
+
targetTopPosition = initialPosition.position.y + scrollTop;
|
|
45
46
|
}
|
|
46
47
|
if (initialPosition.position.height) {
|
|
47
48
|
targetHeight = initialPosition.position.height;
|
|
@@ -50,6 +51,33 @@ function getVisiblePosition({ initialPosition, node, visibleArea, placement = "b
|
|
|
50
51
|
targetWidth = initialPosition.position.width;
|
|
51
52
|
}
|
|
52
53
|
}
|
|
54
|
+
/** Inherit Position */
|
|
55
|
+
let inheritLeft = 0;
|
|
56
|
+
let inheritTop = 0;
|
|
57
|
+
if (nested) {
|
|
58
|
+
const { left = 0, top = 0 } = node.parentElement?.getBoundingClientRect?.() ?? {};
|
|
59
|
+
inheritLeft = left + scrollLeft;
|
|
60
|
+
inheritTop = top + scrollTop;
|
|
61
|
+
}
|
|
62
|
+
/** Initial Position */
|
|
63
|
+
const targetXCenter = targetWidth ? targetLeftPosition + targetWidth / 2 : targetLeftPosition;
|
|
64
|
+
const targetYCenter = targetHeight ? targetTopPosition + targetHeight / 2 : targetTopPosition;
|
|
65
|
+
const targetYEnd = targetHeight ? targetTopPosition + targetHeight : targetTopPosition;
|
|
66
|
+
const x = {
|
|
67
|
+
insideCenter: targetXCenter - nodeWidth / 2 + stepX,
|
|
68
|
+
insideRight: targetLeftPosition + targetWidth + stepX - nodeWidth,
|
|
69
|
+
insideLeft: targetLeftPosition + stepX,
|
|
70
|
+
left: targetLeftPosition - nodeWidth - stepX,
|
|
71
|
+
right: targetLeftPosition + targetWidth + stepX,
|
|
72
|
+
};
|
|
73
|
+
const y = {
|
|
74
|
+
bottom: targetYEnd + stepY,
|
|
75
|
+
top: targetTopPosition - stepY - nodeHeight,
|
|
76
|
+
insideCenter: targetYCenter - nodeHeight / 2 + stepY,
|
|
77
|
+
insideBottom: targetTopPosition + targetHeight - nodeHeight + stepY,
|
|
78
|
+
insideTop: targetTopPosition + stepY,
|
|
79
|
+
};
|
|
80
|
+
/** Find visible position */
|
|
53
81
|
function isCompletelyVisibleX(left) {
|
|
54
82
|
const endXPosition = nodeWidth + left;
|
|
55
83
|
return xStart <= left && xEnd >= endXPosition;
|
|
@@ -58,496 +86,358 @@ function getVisiblePosition({ initialPosition, node, visibleArea, placement = "b
|
|
|
58
86
|
const endYPosition = nodeHeight + top;
|
|
59
87
|
return yStart <= top && yEnd >= endYPosition;
|
|
60
88
|
}
|
|
61
|
-
let
|
|
62
|
-
let correctTop = targetTopPosition;
|
|
63
|
-
const { x, y } = getStartPositions({
|
|
64
|
-
targetHeight,
|
|
65
|
-
targetWidth,
|
|
89
|
+
let visiblePositions = processVisiblePositions({
|
|
66
90
|
targetLeftPosition,
|
|
91
|
+
targetTopPosition,
|
|
92
|
+
x,
|
|
93
|
+
y,
|
|
94
|
+
placement,
|
|
95
|
+
flex,
|
|
67
96
|
nodeHeight,
|
|
68
97
|
nodeWidth,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
98
|
+
xEnd,
|
|
99
|
+
xStart,
|
|
100
|
+
yEnd,
|
|
101
|
+
yStart,
|
|
102
|
+
isCompletelyVisibleX,
|
|
103
|
+
isCompletelyVisibleY,
|
|
72
104
|
});
|
|
73
|
-
|
|
105
|
+
if (flex &&
|
|
106
|
+
(!isCompletelyVisibleX(visiblePositions.left) || !isCompletelyVisibleY(visiblePositions.top))) {
|
|
107
|
+
visiblePositions = getFlexVisiblePosition({
|
|
108
|
+
initialLeft: visiblePositions.left,
|
|
109
|
+
initialTop: visiblePositions.top,
|
|
110
|
+
isCompletelyVisibleX,
|
|
111
|
+
isCompletelyVisibleY,
|
|
112
|
+
nodeHeight,
|
|
113
|
+
nodeWidth,
|
|
114
|
+
xEnd,
|
|
115
|
+
yEnd,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
visiblePositions.left -= inheritLeft;
|
|
119
|
+
visiblePositions.top -= inheritTop;
|
|
120
|
+
return {
|
|
121
|
+
placement: visiblePositions.placement,
|
|
122
|
+
left: visiblePositions.left,
|
|
123
|
+
top: visiblePositions.top,
|
|
124
|
+
bottom: yEnd - scrollTop - (visiblePositions.top + nodeHeight),
|
|
125
|
+
right: xEnd - scrollLeft - (visiblePositions.left + nodeWidth),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function processVisiblePositions(opts) {
|
|
129
|
+
let correctLeft = opts.targetLeftPosition;
|
|
130
|
+
let correctTop = opts.targetTopPosition;
|
|
131
|
+
switch (opts.placement) {
|
|
74
132
|
case "bottom-center": {
|
|
75
|
-
correctLeft = x.
|
|
76
|
-
correctTop = y.bottom;
|
|
133
|
+
correctLeft = opts.x.insideCenter;
|
|
134
|
+
correctTop = opts.y.bottom;
|
|
77
135
|
let placement = "bottom-center";
|
|
78
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
79
|
-
if (isCompletelyVisibleX(x.
|
|
136
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
137
|
+
if (opts.isCompletelyVisibleX(opts.x.insideLeft)) {
|
|
80
138
|
placement = "bottom-left";
|
|
81
|
-
correctLeft = x.
|
|
139
|
+
correctLeft = opts.x.insideLeft;
|
|
82
140
|
}
|
|
83
|
-
else if (isCompletelyVisibleX(x.
|
|
141
|
+
else if (opts.isCompletelyVisibleX(opts.x.insideRight)) {
|
|
84
142
|
placement = "bottom-right";
|
|
85
|
-
correctLeft = x.
|
|
143
|
+
correctLeft = opts.x.insideRight;
|
|
86
144
|
}
|
|
87
145
|
}
|
|
88
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
89
|
-
if (isCompletelyVisibleY(y.top)) {
|
|
146
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
147
|
+
if (opts.isCompletelyVisibleY(opts.y.top)) {
|
|
90
148
|
placement = placement.replace("bottom", "top");
|
|
91
|
-
correctTop = y.top;
|
|
149
|
+
correctTop = opts.y.top;
|
|
92
150
|
}
|
|
93
151
|
}
|
|
94
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
95
|
-
return getFlexVisiblePosition({
|
|
96
|
-
initialLeft: correctLeft,
|
|
97
|
-
initialTop: correctTop,
|
|
98
|
-
isCompletelyVisibleX,
|
|
99
|
-
isCompletelyVisibleY,
|
|
100
|
-
nodeHeight,
|
|
101
|
-
nodeWidth,
|
|
102
|
-
xEnd,
|
|
103
|
-
yEnd,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
152
|
return {
|
|
107
153
|
top: correctTop,
|
|
108
154
|
left: correctLeft,
|
|
109
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
110
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
111
155
|
placement,
|
|
112
156
|
};
|
|
113
157
|
}
|
|
114
158
|
case "bottom-left": {
|
|
115
|
-
correctLeft = x.
|
|
116
|
-
correctTop = y.bottom;
|
|
159
|
+
correctLeft = opts.x.insideLeft;
|
|
160
|
+
correctTop = opts.y.bottom;
|
|
117
161
|
let placement = "bottom-left";
|
|
118
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
119
|
-
if (isCompletelyVisibleX(x.
|
|
162
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
163
|
+
if (opts.isCompletelyVisibleX(opts.x.insideCenter)) {
|
|
120
164
|
placement = "bottom-center";
|
|
121
|
-
correctLeft = x.
|
|
165
|
+
correctLeft = opts.x.insideCenter;
|
|
122
166
|
}
|
|
123
|
-
else if (isCompletelyVisibleX(x.
|
|
167
|
+
else if (opts.isCompletelyVisibleX(opts.x.insideRight)) {
|
|
124
168
|
placement = "bottom-right";
|
|
125
|
-
correctLeft = x.
|
|
169
|
+
correctLeft = opts.x.insideRight;
|
|
126
170
|
}
|
|
127
171
|
}
|
|
128
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
129
|
-
if (isCompletelyVisibleY(y.top)) {
|
|
172
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
173
|
+
if (opts.isCompletelyVisibleY(opts.y.top)) {
|
|
130
174
|
placement = placement.replace("bottom", "top");
|
|
131
|
-
correctTop = y.top;
|
|
175
|
+
correctTop = opts.y.top;
|
|
132
176
|
}
|
|
133
177
|
}
|
|
134
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
135
|
-
return getFlexVisiblePosition({
|
|
136
|
-
initialLeft: correctLeft,
|
|
137
|
-
initialTop: correctTop,
|
|
138
|
-
isCompletelyVisibleX,
|
|
139
|
-
isCompletelyVisibleY,
|
|
140
|
-
nodeHeight,
|
|
141
|
-
nodeWidth,
|
|
142
|
-
xEnd,
|
|
143
|
-
yEnd,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
178
|
return {
|
|
147
179
|
top: correctTop,
|
|
148
180
|
left: correctLeft,
|
|
149
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
150
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
151
181
|
placement,
|
|
152
182
|
};
|
|
153
183
|
}
|
|
154
184
|
case "bottom-right": {
|
|
155
|
-
correctLeft = x.
|
|
156
|
-
correctTop = y.bottom;
|
|
185
|
+
correctLeft = opts.x.insideRight;
|
|
186
|
+
correctTop = opts.y.bottom;
|
|
157
187
|
let placement = "bottom-right";
|
|
158
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
159
|
-
if (isCompletelyVisibleX(x.
|
|
188
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
189
|
+
if (opts.isCompletelyVisibleX(opts.x.insideCenter)) {
|
|
160
190
|
placement = "bottom-center";
|
|
161
|
-
correctLeft = x.
|
|
191
|
+
correctLeft = opts.x.insideCenter;
|
|
162
192
|
}
|
|
163
|
-
else if (isCompletelyVisibleX(x.
|
|
193
|
+
else if (opts.isCompletelyVisibleX(opts.x.insideLeft)) {
|
|
164
194
|
placement = "bottom-left";
|
|
165
|
-
correctLeft = x.
|
|
195
|
+
correctLeft = opts.x.insideLeft;
|
|
166
196
|
}
|
|
167
197
|
}
|
|
168
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
169
|
-
if (isCompletelyVisibleY(y.top)) {
|
|
198
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
199
|
+
if (opts.isCompletelyVisibleY(opts.y.top)) {
|
|
170
200
|
placement = placement.replace("bottom", "top");
|
|
171
|
-
correctTop = y.top;
|
|
201
|
+
correctTop = opts.y.top;
|
|
172
202
|
}
|
|
173
203
|
}
|
|
174
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
175
|
-
return getFlexVisiblePosition({
|
|
176
|
-
initialLeft: correctLeft,
|
|
177
|
-
initialTop: correctTop,
|
|
178
|
-
isCompletelyVisibleX,
|
|
179
|
-
isCompletelyVisibleY,
|
|
180
|
-
nodeHeight,
|
|
181
|
-
nodeWidth,
|
|
182
|
-
xEnd,
|
|
183
|
-
yEnd,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
204
|
return {
|
|
187
205
|
top: correctTop,
|
|
188
206
|
left: correctLeft,
|
|
189
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
190
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
191
207
|
placement,
|
|
192
208
|
};
|
|
193
209
|
}
|
|
194
210
|
case "right-bottom": {
|
|
195
|
-
correctLeft = x.right;
|
|
196
|
-
correctTop = y.
|
|
211
|
+
correctLeft = opts.x.right;
|
|
212
|
+
correctTop = opts.y.insideBottom;
|
|
197
213
|
let placement = "right-bottom";
|
|
198
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
199
|
-
if (isCompletelyVisibleY(y.
|
|
214
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
215
|
+
if (opts.isCompletelyVisibleY(opts.y.insideCenter)) {
|
|
200
216
|
placement = "right-center";
|
|
201
|
-
correctTop = y.
|
|
217
|
+
correctTop = opts.y.insideCenter;
|
|
202
218
|
}
|
|
203
|
-
else if (isCompletelyVisibleY(y.
|
|
219
|
+
else if (opts.isCompletelyVisibleY(opts.y.insideTop)) {
|
|
204
220
|
placement = "right-top";
|
|
205
|
-
correctTop = y.
|
|
221
|
+
correctTop = opts.y.insideTop;
|
|
206
222
|
}
|
|
207
223
|
}
|
|
208
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
209
|
-
if (isCompletelyVisibleX(x.left)) {
|
|
224
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
225
|
+
if (opts.isCompletelyVisibleX(opts.x.left)) {
|
|
210
226
|
placement = placement.replace("right", "left");
|
|
211
|
-
correctLeft = x.left;
|
|
227
|
+
correctLeft = opts.x.left;
|
|
212
228
|
}
|
|
213
229
|
}
|
|
214
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
215
|
-
return getFlexVisiblePosition({
|
|
216
|
-
initialLeft: correctLeft,
|
|
217
|
-
initialTop: correctTop,
|
|
218
|
-
isCompletelyVisibleX,
|
|
219
|
-
isCompletelyVisibleY,
|
|
220
|
-
nodeHeight,
|
|
221
|
-
nodeWidth,
|
|
222
|
-
xEnd,
|
|
223
|
-
yEnd,
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
230
|
return {
|
|
227
231
|
top: correctTop,
|
|
228
232
|
left: correctLeft,
|
|
229
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
230
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
231
233
|
placement,
|
|
232
234
|
};
|
|
233
235
|
}
|
|
234
236
|
case "right-center": {
|
|
235
|
-
correctLeft = x.right;
|
|
236
|
-
correctTop = y.
|
|
237
|
+
correctLeft = opts.x.right;
|
|
238
|
+
correctTop = opts.y.insideCenter;
|
|
237
239
|
let placement = "right-center";
|
|
238
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
239
|
-
if (isCompletelyVisibleY(y.
|
|
240
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
241
|
+
if (opts.isCompletelyVisibleY(opts.y.insideTop)) {
|
|
240
242
|
placement = "right-top";
|
|
241
|
-
correctTop = y.
|
|
243
|
+
correctTop = opts.y.insideTop;
|
|
242
244
|
}
|
|
243
|
-
else if (isCompletelyVisibleY(y.
|
|
245
|
+
else if (opts.isCompletelyVisibleY(opts.y.insideBottom)) {
|
|
244
246
|
placement = "right-bottom";
|
|
245
|
-
correctTop = y.
|
|
247
|
+
correctTop = opts.y.insideBottom;
|
|
246
248
|
}
|
|
247
249
|
}
|
|
248
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
249
|
-
if (isCompletelyVisibleX(x.left)) {
|
|
250
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
251
|
+
if (opts.isCompletelyVisibleX(opts.x.left)) {
|
|
250
252
|
placement = placement.replace("right", "left");
|
|
251
|
-
correctLeft = x.left;
|
|
253
|
+
correctLeft = opts.x.left;
|
|
252
254
|
}
|
|
253
255
|
}
|
|
254
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
255
|
-
return getFlexVisiblePosition({
|
|
256
|
-
initialLeft: correctLeft,
|
|
257
|
-
initialTop: correctTop,
|
|
258
|
-
isCompletelyVisibleX,
|
|
259
|
-
isCompletelyVisibleY,
|
|
260
|
-
nodeHeight,
|
|
261
|
-
nodeWidth,
|
|
262
|
-
xEnd,
|
|
263
|
-
yEnd,
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
256
|
return {
|
|
267
257
|
top: correctTop,
|
|
268
258
|
left: correctLeft,
|
|
269
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
270
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
271
259
|
placement,
|
|
272
260
|
};
|
|
273
261
|
}
|
|
274
262
|
case "right-top": {
|
|
275
|
-
correctLeft = x.right;
|
|
276
|
-
correctTop = y.
|
|
263
|
+
correctLeft = opts.x.right;
|
|
264
|
+
correctTop = opts.y.insideTop;
|
|
277
265
|
let placement = "right-top";
|
|
278
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
279
|
-
if (isCompletelyVisibleY(y.
|
|
266
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
267
|
+
if (opts.isCompletelyVisibleY(opts.y.insideCenter)) {
|
|
280
268
|
placement = "right-center";
|
|
281
|
-
correctTop = y.
|
|
269
|
+
correctTop = opts.y.insideCenter;
|
|
282
270
|
}
|
|
283
|
-
else if (isCompletelyVisibleY(y.
|
|
271
|
+
else if (opts.isCompletelyVisibleY(opts.y.insideBottom)) {
|
|
284
272
|
placement = "right-bottom";
|
|
285
|
-
correctTop = y.
|
|
273
|
+
correctTop = opts.y.insideBottom;
|
|
286
274
|
}
|
|
287
275
|
}
|
|
288
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
289
|
-
if (isCompletelyVisibleX(x.left)) {
|
|
276
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
277
|
+
if (opts.isCompletelyVisibleX(opts.x.left)) {
|
|
290
278
|
placement = placement.replace("right", "left");
|
|
291
|
-
correctLeft = x.left;
|
|
279
|
+
correctLeft = opts.x.left;
|
|
292
280
|
}
|
|
293
281
|
}
|
|
294
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
295
|
-
return getFlexVisiblePosition({
|
|
296
|
-
initialLeft: correctLeft,
|
|
297
|
-
initialTop: correctTop,
|
|
298
|
-
isCompletelyVisibleX,
|
|
299
|
-
isCompletelyVisibleY,
|
|
300
|
-
nodeHeight,
|
|
301
|
-
nodeWidth,
|
|
302
|
-
xEnd,
|
|
303
|
-
yEnd,
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
282
|
return {
|
|
307
283
|
top: correctTop,
|
|
308
284
|
left: correctLeft,
|
|
309
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
310
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
311
285
|
placement,
|
|
312
286
|
};
|
|
313
287
|
}
|
|
314
288
|
case "top-center": {
|
|
315
|
-
correctLeft = x.
|
|
316
|
-
correctTop = y.top;
|
|
289
|
+
correctLeft = opts.x.insideCenter;
|
|
290
|
+
correctTop = opts.y.top;
|
|
317
291
|
let placement = "top-center";
|
|
318
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
319
|
-
if (isCompletelyVisibleX(x.
|
|
292
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
293
|
+
if (opts.isCompletelyVisibleX(opts.x.insideLeft)) {
|
|
320
294
|
placement = "top-left";
|
|
321
|
-
correctLeft = x.
|
|
295
|
+
correctLeft = opts.x.insideLeft;
|
|
322
296
|
}
|
|
323
|
-
else if (isCompletelyVisibleX(x.
|
|
297
|
+
else if (opts.isCompletelyVisibleX(opts.x.insideRight)) {
|
|
324
298
|
placement = "top-right";
|
|
325
|
-
correctLeft = x.
|
|
299
|
+
correctLeft = opts.x.insideRight;
|
|
326
300
|
}
|
|
327
301
|
}
|
|
328
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
329
|
-
if (isCompletelyVisibleY(y.bottom)) {
|
|
302
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
303
|
+
if (opts.isCompletelyVisibleY(opts.y.bottom)) {
|
|
330
304
|
placement = placement.replace("top", "bottom");
|
|
331
|
-
correctTop = y.bottom;
|
|
305
|
+
correctTop = opts.y.bottom;
|
|
332
306
|
}
|
|
333
307
|
}
|
|
334
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
335
|
-
return getFlexVisiblePosition({
|
|
336
|
-
initialLeft: correctLeft,
|
|
337
|
-
initialTop: correctTop,
|
|
338
|
-
isCompletelyVisibleX,
|
|
339
|
-
isCompletelyVisibleY,
|
|
340
|
-
nodeHeight,
|
|
341
|
-
nodeWidth,
|
|
342
|
-
xEnd,
|
|
343
|
-
yEnd,
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
308
|
return {
|
|
347
309
|
top: correctTop,
|
|
348
310
|
left: correctLeft,
|
|
349
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
350
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
351
311
|
placement,
|
|
352
312
|
};
|
|
353
313
|
}
|
|
354
314
|
case "top-left": {
|
|
355
|
-
correctLeft = x.
|
|
356
|
-
correctTop = y.top;
|
|
315
|
+
correctLeft = opts.x.insideLeft;
|
|
316
|
+
correctTop = opts.y.top;
|
|
357
317
|
let placement = "top-left";
|
|
358
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
359
|
-
if (isCompletelyVisibleX(x.
|
|
318
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
319
|
+
if (opts.isCompletelyVisibleX(opts.x.insideCenter)) {
|
|
360
320
|
placement = "top-center";
|
|
361
|
-
correctLeft = x.
|
|
321
|
+
correctLeft = opts.x.insideCenter;
|
|
362
322
|
}
|
|
363
|
-
else if (isCompletelyVisibleX(x.
|
|
323
|
+
else if (opts.isCompletelyVisibleX(opts.x.insideRight)) {
|
|
364
324
|
placement = "top-right";
|
|
365
|
-
correctLeft = x.
|
|
325
|
+
correctLeft = opts.x.insideRight;
|
|
366
326
|
}
|
|
367
327
|
}
|
|
368
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
369
|
-
if (isCompletelyVisibleY(y.bottom)) {
|
|
328
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
329
|
+
if (opts.isCompletelyVisibleY(opts.y.bottom)) {
|
|
370
330
|
placement = placement.replace("top", "bottom");
|
|
371
|
-
correctTop = y.bottom;
|
|
331
|
+
correctTop = opts.y.bottom;
|
|
372
332
|
}
|
|
373
333
|
}
|
|
374
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
375
|
-
return getFlexVisiblePosition({
|
|
376
|
-
initialLeft: correctLeft,
|
|
377
|
-
initialTop: correctTop,
|
|
378
|
-
isCompletelyVisibleX,
|
|
379
|
-
isCompletelyVisibleY,
|
|
380
|
-
nodeHeight,
|
|
381
|
-
nodeWidth,
|
|
382
|
-
xEnd,
|
|
383
|
-
yEnd,
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
334
|
return {
|
|
387
335
|
top: correctTop,
|
|
388
336
|
left: correctLeft,
|
|
389
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
390
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
391
337
|
placement,
|
|
392
338
|
};
|
|
393
339
|
}
|
|
394
340
|
case "top-right": {
|
|
395
|
-
correctLeft = x.
|
|
396
|
-
correctTop = y.top;
|
|
341
|
+
correctLeft = opts.x.insideRight;
|
|
342
|
+
correctTop = opts.y.top;
|
|
397
343
|
let placement = "top-right";
|
|
398
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
399
|
-
if (isCompletelyVisibleX(x.
|
|
344
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
345
|
+
if (opts.isCompletelyVisibleX(opts.x.insideCenter)) {
|
|
400
346
|
placement = "top-center";
|
|
401
|
-
correctLeft = x.
|
|
347
|
+
correctLeft = opts.x.insideCenter;
|
|
402
348
|
}
|
|
403
|
-
else if (isCompletelyVisibleX(x.
|
|
349
|
+
else if (opts.isCompletelyVisibleX(opts.x.insideLeft)) {
|
|
404
350
|
placement = "top-left";
|
|
405
|
-
correctLeft = x.
|
|
351
|
+
correctLeft = opts.x.insideLeft;
|
|
406
352
|
}
|
|
407
353
|
}
|
|
408
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
409
|
-
if (isCompletelyVisibleY(y.bottom)) {
|
|
354
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
355
|
+
if (opts.isCompletelyVisibleY(opts.y.bottom)) {
|
|
410
356
|
placement = placement.replace("top", "bottom");
|
|
411
|
-
correctTop = y.bottom;
|
|
357
|
+
correctTop = opts.y.bottom;
|
|
412
358
|
}
|
|
413
359
|
}
|
|
414
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
415
|
-
return getFlexVisiblePosition({
|
|
416
|
-
initialLeft: correctLeft,
|
|
417
|
-
initialTop: correctTop,
|
|
418
|
-
isCompletelyVisibleX,
|
|
419
|
-
isCompletelyVisibleY,
|
|
420
|
-
nodeHeight,
|
|
421
|
-
nodeWidth,
|
|
422
|
-
xEnd,
|
|
423
|
-
yEnd,
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
360
|
return {
|
|
427
361
|
top: correctTop,
|
|
428
362
|
left: correctLeft,
|
|
429
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
430
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
431
363
|
placement,
|
|
432
364
|
};
|
|
433
365
|
}
|
|
434
366
|
case "left-bottom": {
|
|
435
|
-
correctLeft = x.left;
|
|
436
|
-
correctTop = y.
|
|
367
|
+
correctLeft = opts.x.left;
|
|
368
|
+
correctTop = opts.y.insideBottom;
|
|
437
369
|
let placement = "left-bottom";
|
|
438
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
439
|
-
if (isCompletelyVisibleY(y.
|
|
370
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
371
|
+
if (opts.isCompletelyVisibleY(opts.y.insideCenter)) {
|
|
440
372
|
placement = "left-center";
|
|
441
|
-
correctTop = y.
|
|
373
|
+
correctTop = opts.y.insideCenter;
|
|
442
374
|
}
|
|
443
|
-
else if (isCompletelyVisibleY(y.
|
|
375
|
+
else if (opts.isCompletelyVisibleY(opts.y.insideTop)) {
|
|
444
376
|
placement = "left-top";
|
|
445
|
-
correctTop = y.
|
|
377
|
+
correctTop = opts.y.insideTop;
|
|
446
378
|
}
|
|
447
379
|
}
|
|
448
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
449
|
-
if (isCompletelyVisibleX(x.right)) {
|
|
380
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
381
|
+
if (opts.isCompletelyVisibleX(opts.x.right)) {
|
|
450
382
|
placement = placement.replace("left", "right");
|
|
451
|
-
correctLeft = x.right;
|
|
383
|
+
correctLeft = opts.x.right;
|
|
452
384
|
}
|
|
453
385
|
}
|
|
454
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
455
|
-
return getFlexVisiblePosition({
|
|
456
|
-
initialLeft: correctLeft,
|
|
457
|
-
initialTop: correctTop,
|
|
458
|
-
isCompletelyVisibleX,
|
|
459
|
-
isCompletelyVisibleY,
|
|
460
|
-
nodeHeight,
|
|
461
|
-
nodeWidth,
|
|
462
|
-
xEnd,
|
|
463
|
-
yEnd,
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
386
|
return {
|
|
467
387
|
top: correctTop,
|
|
468
388
|
left: correctLeft,
|
|
469
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
470
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
471
389
|
placement,
|
|
472
390
|
};
|
|
473
391
|
}
|
|
474
392
|
case "left-center": {
|
|
475
|
-
correctLeft = x.left;
|
|
476
|
-
correctTop = y.
|
|
393
|
+
correctLeft = opts.x.left;
|
|
394
|
+
correctTop = opts.y.insideCenter;
|
|
477
395
|
let placement = "left-center";
|
|
478
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
479
|
-
if (isCompletelyVisibleY(y.
|
|
396
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
397
|
+
if (opts.isCompletelyVisibleY(opts.y.insideTop)) {
|
|
480
398
|
placement = "left-top";
|
|
481
|
-
correctTop = y.
|
|
399
|
+
correctTop = opts.y.insideTop;
|
|
482
400
|
}
|
|
483
|
-
else if (isCompletelyVisibleY(y.
|
|
401
|
+
else if (opts.isCompletelyVisibleY(opts.y.insideBottom)) {
|
|
484
402
|
placement = "left-bottom";
|
|
485
|
-
correctTop = y.
|
|
403
|
+
correctTop = opts.y.insideBottom;
|
|
486
404
|
}
|
|
487
405
|
}
|
|
488
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
489
|
-
if (isCompletelyVisibleX(x.right)) {
|
|
406
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
407
|
+
if (opts.isCompletelyVisibleX(opts.x.right)) {
|
|
490
408
|
placement = placement.replace("left", "right");
|
|
491
|
-
correctLeft = x.right;
|
|
409
|
+
correctLeft = opts.x.right;
|
|
492
410
|
}
|
|
493
411
|
}
|
|
494
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
495
|
-
return getFlexVisiblePosition({
|
|
496
|
-
initialLeft: correctLeft,
|
|
497
|
-
initialTop: correctTop,
|
|
498
|
-
isCompletelyVisibleX,
|
|
499
|
-
isCompletelyVisibleY,
|
|
500
|
-
nodeHeight,
|
|
501
|
-
nodeWidth,
|
|
502
|
-
xEnd,
|
|
503
|
-
yEnd,
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
412
|
return {
|
|
507
413
|
top: correctTop,
|
|
508
414
|
left: correctLeft,
|
|
509
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
510
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
511
415
|
placement,
|
|
512
416
|
};
|
|
513
417
|
}
|
|
514
418
|
case "left-top": {
|
|
515
|
-
correctLeft = x.left;
|
|
516
|
-
correctTop = y.
|
|
419
|
+
correctLeft = opts.x.left;
|
|
420
|
+
correctTop = opts.y.insideTop;
|
|
517
421
|
let placement = "left-top";
|
|
518
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
519
|
-
if (isCompletelyVisibleY(y.
|
|
422
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
423
|
+
if (opts.isCompletelyVisibleY(opts.y.insideCenter)) {
|
|
520
424
|
placement = "left-center";
|
|
521
|
-
correctTop = y.
|
|
425
|
+
correctTop = opts.y.insideCenter;
|
|
522
426
|
}
|
|
523
|
-
else if (isCompletelyVisibleY(y.
|
|
427
|
+
else if (opts.isCompletelyVisibleY(opts.y.insideBottom)) {
|
|
524
428
|
placement = "left-bottom";
|
|
525
|
-
correctTop = y.
|
|
429
|
+
correctTop = opts.y.insideBottom;
|
|
526
430
|
}
|
|
527
431
|
}
|
|
528
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
529
|
-
if (isCompletelyVisibleX(x.right)) {
|
|
432
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
433
|
+
if (opts.isCompletelyVisibleX(opts.x.right)) {
|
|
530
434
|
placement = placement.replace("left", "right");
|
|
531
|
-
correctLeft = x.right;
|
|
435
|
+
correctLeft = opts.x.right;
|
|
532
436
|
}
|
|
533
437
|
}
|
|
534
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
535
|
-
return getFlexVisiblePosition({
|
|
536
|
-
initialLeft: correctLeft,
|
|
537
|
-
initialTop: correctTop,
|
|
538
|
-
isCompletelyVisibleX,
|
|
539
|
-
isCompletelyVisibleY,
|
|
540
|
-
nodeHeight,
|
|
541
|
-
nodeWidth,
|
|
542
|
-
xEnd,
|
|
543
|
-
yEnd,
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
438
|
return {
|
|
547
439
|
top: correctTop,
|
|
548
440
|
left: correctLeft,
|
|
549
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
550
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
551
441
|
placement,
|
|
552
442
|
};
|
|
553
443
|
}
|
|
@@ -555,33 +445,11 @@ function getVisiblePosition({ initialPosition, node, visibleArea, placement = "b
|
|
|
555
445
|
return {
|
|
556
446
|
top: correctTop,
|
|
557
447
|
left: correctLeft,
|
|
558
|
-
|
|
559
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
560
|
-
placement,
|
|
448
|
+
placement: opts.placement,
|
|
561
449
|
};
|
|
562
450
|
}
|
|
563
451
|
}
|
|
564
452
|
}
|
|
565
|
-
function getStartPositions({ targetHeight, targetWidth, nodeHeight, nodeWidth, targetLeftPosition, targetTopPosition, stepX, stepY, }) {
|
|
566
|
-
const childBottomCenter = targetWidth ? targetLeftPosition + targetWidth / 2 : targetLeftPosition;
|
|
567
|
-
const childBottom = targetHeight ? targetTopPosition + targetHeight : targetTopPosition;
|
|
568
|
-
const childRightCenter = targetHeight ? targetTopPosition + targetHeight / 2 : targetTopPosition;
|
|
569
|
-
const x = {
|
|
570
|
-
bottomCenter: childBottomCenter - nodeWidth / 2 + stepX,
|
|
571
|
-
bottomRight: targetLeftPosition + targetWidth + stepX - nodeWidth,
|
|
572
|
-
bottomLeft: targetLeftPosition + stepX,
|
|
573
|
-
left: targetLeftPosition - nodeWidth - stepX,
|
|
574
|
-
right: targetLeftPosition + targetWidth + stepX,
|
|
575
|
-
};
|
|
576
|
-
const y = {
|
|
577
|
-
bottom: childBottom + stepY,
|
|
578
|
-
top: targetTopPosition - stepY - nodeHeight,
|
|
579
|
-
rightCenter: childRightCenter - nodeHeight / 2 + stepY,
|
|
580
|
-
rightBottom: targetTopPosition + targetHeight - nodeHeight + stepY,
|
|
581
|
-
rightTop: targetTopPosition + stepY,
|
|
582
|
-
};
|
|
583
|
-
return { x, y };
|
|
584
|
-
}
|
|
585
453
|
function getFlexVisiblePosition({ initialLeft, initialTop, isCompletelyVisibleX, isCompletelyVisibleY, nodeHeight, nodeWidth, xEnd, yEnd, }) {
|
|
586
454
|
if (!isCompletelyVisibleY(initialTop)) {
|
|
587
455
|
initialTop = yEnd - nodeHeight;
|
|
@@ -592,8 +460,6 @@ function getFlexVisiblePosition({ initialLeft, initialTop, isCompletelyVisibleX,
|
|
|
592
460
|
return {
|
|
593
461
|
top: initialTop,
|
|
594
462
|
left: initialLeft,
|
|
595
|
-
bottom: yEnd - initialTop - nodeHeight,
|
|
596
|
-
right: xEnd - initialLeft - nodeWidth,
|
|
597
463
|
placement: "flex",
|
|
598
464
|
};
|
|
599
465
|
}
|