@krainovsd/js-helpers 0.13.3 → 0.13.5

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.
@@ -13,35 +13,36 @@ function getVisiblePosition({ initialPosition, node, visibleArea, placement = "b
13
13
  placement === "right-center"
14
14
  ? 0
15
15
  : 10, flex, }) {
16
- const windowWidth = document.documentElement.clientWidth;
17
- const windowHeight = document.documentElement.clientHeight;
18
- let xStart = 0;
19
- let xEnd = windowWidth;
20
- let yStart = 0;
21
- let yEnd = windowHeight;
22
- if (visibleArea) {
23
- const { top, left, height, width } = visibleArea.getBoundingClientRect();
24
- xStart = left;
25
- xEnd = left + width;
26
- yStart = top;
27
- yEnd = top + height;
28
- }
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 { top: targetTopPosition, left: targetLeftPosition, height: nodeHeight, width: nodeWidth, } = node.getBoundingClientRect();
30
+ let targetTopPosition = 0;
31
+ let targetLeftPosition = 0;
32
+ const { height: nodeHeight, width: nodeWidth } = node.getBoundingClientRect();
32
33
  if (initialPosition?.targetNode) {
33
- const { top: childTop, left: childLeft, height, width, } = initialPosition.targetNode.getBoundingClientRect();
34
+ const { top, left, height, width } = initialPosition.targetNode.getBoundingClientRect();
34
35
  targetHeight = height;
35
36
  targetWidth = width;
36
- targetTopPosition = childTop;
37
- targetLeftPosition = childLeft;
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,25 @@ function getVisiblePosition({ initialPosition, node, visibleArea, placement = "b
50
51
  targetWidth = initialPosition.position.width;
51
52
  }
52
53
  }
54
+ /** Initial Position */
55
+ const targetXCenter = targetWidth ? targetLeftPosition + targetWidth / 2 : targetLeftPosition;
56
+ const targetYCenter = targetHeight ? targetTopPosition + targetHeight / 2 : targetTopPosition;
57
+ const targetYEnd = targetHeight ? targetTopPosition + targetHeight : targetTopPosition;
58
+ const x = {
59
+ insideCenter: targetXCenter - nodeWidth / 2 + stepX,
60
+ insideRight: targetLeftPosition + targetWidth + stepX - nodeWidth,
61
+ insideLeft: targetLeftPosition + stepX,
62
+ left: targetLeftPosition - nodeWidth - stepX,
63
+ right: targetLeftPosition + targetWidth + stepX,
64
+ };
65
+ const y = {
66
+ bottom: targetYEnd + stepY,
67
+ top: targetTopPosition - stepY - nodeHeight,
68
+ insideCenter: targetYCenter - nodeHeight / 2 + stepY,
69
+ insideBottom: targetTopPosition + targetHeight - nodeHeight + stepY,
70
+ insideTop: targetTopPosition + stepY,
71
+ };
72
+ /** Find visible position */
53
73
  function isCompletelyVisibleX(left) {
54
74
  const endXPosition = nodeWidth + left;
55
75
  return xStart <= left && xEnd >= endXPosition;
@@ -58,496 +78,356 @@ function getVisiblePosition({ initialPosition, node, visibleArea, placement = "b
58
78
  const endYPosition = nodeHeight + top;
59
79
  return yStart <= top && yEnd >= endYPosition;
60
80
  }
61
- let correctLeft = targetLeftPosition;
62
- let correctTop = targetTopPosition;
63
- const { x, y } = getStartPositions({
64
- targetHeight,
65
- targetWidth,
81
+ let visiblePositions = processVisiblePositions({
66
82
  targetLeftPosition,
83
+ targetTopPosition,
84
+ x,
85
+ y,
86
+ placement,
87
+ flex,
67
88
  nodeHeight,
68
89
  nodeWidth,
69
- stepX,
70
- stepY,
71
- targetTopPosition,
90
+ xEnd,
91
+ xStart,
92
+ yEnd,
93
+ yStart,
94
+ isCompletelyVisibleX,
95
+ isCompletelyVisibleY,
72
96
  });
73
- switch (placement) {
97
+ if (flex &&
98
+ (!isCompletelyVisibleX(visiblePositions.left) || !isCompletelyVisibleY(visiblePositions.top))) {
99
+ visiblePositions = getFlexVisiblePosition({
100
+ initialLeft: visiblePositions.left,
101
+ initialTop: visiblePositions.top,
102
+ isCompletelyVisibleX,
103
+ isCompletelyVisibleY,
104
+ nodeHeight,
105
+ nodeWidth,
106
+ xEnd,
107
+ yEnd,
108
+ });
109
+ }
110
+ return {
111
+ placement: visiblePositions.placement,
112
+ left: visiblePositions.left,
113
+ top: visiblePositions.top,
114
+ bottom: yEnd - scrollTop - (visiblePositions.top + nodeHeight),
115
+ right: xEnd - scrollLeft - (visiblePositions.left + nodeWidth),
116
+ };
117
+ }
118
+ function processVisiblePositions(opts) {
119
+ let correctLeft = opts.targetLeftPosition;
120
+ let correctTop = opts.targetTopPosition;
121
+ switch (opts.placement) {
74
122
  case "bottom-center": {
75
- correctLeft = x.bottomCenter;
76
- correctTop = y.bottom;
123
+ correctLeft = opts.x.insideCenter;
124
+ correctTop = opts.y.bottom;
77
125
  let placement = "bottom-center";
78
- if (!isCompletelyVisibleX(correctLeft)) {
79
- if (isCompletelyVisibleX(x.bottomLeft)) {
126
+ if (!opts.isCompletelyVisibleX(correctLeft)) {
127
+ if (opts.isCompletelyVisibleX(opts.x.insideLeft)) {
80
128
  placement = "bottom-left";
81
- correctLeft = x.bottomLeft;
129
+ correctLeft = opts.x.insideLeft;
82
130
  }
83
- else if (isCompletelyVisibleX(x.bottomRight)) {
131
+ else if (opts.isCompletelyVisibleX(opts.x.insideRight)) {
84
132
  placement = "bottom-right";
85
- correctLeft = x.bottomRight;
133
+ correctLeft = opts.x.insideRight;
86
134
  }
87
135
  }
88
- if (!isCompletelyVisibleY(correctTop)) {
89
- if (isCompletelyVisibleY(y.top)) {
136
+ if (!opts.isCompletelyVisibleY(correctTop)) {
137
+ if (opts.isCompletelyVisibleY(opts.y.top)) {
90
138
  placement = placement.replace("bottom", "top");
91
- correctTop = y.top;
139
+ correctTop = opts.y.top;
92
140
  }
93
141
  }
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
142
  return {
107
143
  top: correctTop,
108
144
  left: correctLeft,
109
- right: xEnd - correctLeft - nodeWidth,
110
- bottom: yEnd - correctTop - nodeHeight,
111
145
  placement,
112
146
  };
113
147
  }
114
148
  case "bottom-left": {
115
- correctLeft = x.bottomLeft;
116
- correctTop = y.bottom;
149
+ correctLeft = opts.x.insideLeft;
150
+ correctTop = opts.y.bottom;
117
151
  let placement = "bottom-left";
118
- if (!isCompletelyVisibleX(correctLeft)) {
119
- if (isCompletelyVisibleX(x.bottomCenter)) {
152
+ if (!opts.isCompletelyVisibleX(correctLeft)) {
153
+ if (opts.isCompletelyVisibleX(opts.x.insideCenter)) {
120
154
  placement = "bottom-center";
121
- correctLeft = x.bottomCenter;
155
+ correctLeft = opts.x.insideCenter;
122
156
  }
123
- else if (isCompletelyVisibleX(x.bottomRight)) {
157
+ else if (opts.isCompletelyVisibleX(opts.x.insideRight)) {
124
158
  placement = "bottom-right";
125
- correctLeft = x.bottomRight;
159
+ correctLeft = opts.x.insideRight;
126
160
  }
127
161
  }
128
- if (!isCompletelyVisibleY(correctTop)) {
129
- if (isCompletelyVisibleY(y.top)) {
162
+ if (!opts.isCompletelyVisibleY(correctTop)) {
163
+ if (opts.isCompletelyVisibleY(opts.y.top)) {
130
164
  placement = placement.replace("bottom", "top");
131
- correctTop = y.top;
165
+ correctTop = opts.y.top;
132
166
  }
133
167
  }
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
168
  return {
147
169
  top: correctTop,
148
170
  left: correctLeft,
149
- right: xEnd - correctLeft - nodeWidth,
150
- bottom: yEnd - correctTop - nodeHeight,
151
171
  placement,
152
172
  };
153
173
  }
154
174
  case "bottom-right": {
155
- correctLeft = x.bottomRight;
156
- correctTop = y.bottom;
175
+ correctLeft = opts.x.insideRight;
176
+ correctTop = opts.y.bottom;
157
177
  let placement = "bottom-right";
158
- if (!isCompletelyVisibleX(correctLeft)) {
159
- if (isCompletelyVisibleX(x.bottomCenter)) {
178
+ if (!opts.isCompletelyVisibleX(correctLeft)) {
179
+ if (opts.isCompletelyVisibleX(opts.x.insideCenter)) {
160
180
  placement = "bottom-center";
161
- correctLeft = x.bottomCenter;
181
+ correctLeft = opts.x.insideCenter;
162
182
  }
163
- else if (isCompletelyVisibleX(x.bottomLeft)) {
183
+ else if (opts.isCompletelyVisibleX(opts.x.insideLeft)) {
164
184
  placement = "bottom-left";
165
- correctLeft = x.bottomLeft;
185
+ correctLeft = opts.x.insideLeft;
166
186
  }
167
187
  }
168
- if (!isCompletelyVisibleY(correctTop)) {
169
- if (isCompletelyVisibleY(y.top)) {
188
+ if (!opts.isCompletelyVisibleY(correctTop)) {
189
+ if (opts.isCompletelyVisibleY(opts.y.top)) {
170
190
  placement = placement.replace("bottom", "top");
171
- correctTop = y.top;
191
+ correctTop = opts.y.top;
172
192
  }
173
193
  }
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
194
  return {
187
195
  top: correctTop,
188
196
  left: correctLeft,
189
- right: xEnd - correctLeft - nodeWidth,
190
- bottom: yEnd - correctTop - nodeHeight,
191
197
  placement,
192
198
  };
193
199
  }
194
200
  case "right-bottom": {
195
- correctLeft = x.right;
196
- correctTop = y.rightBottom;
201
+ correctLeft = opts.x.right;
202
+ correctTop = opts.y.insideBottom;
197
203
  let placement = "right-bottom";
198
- if (!isCompletelyVisibleY(correctTop)) {
199
- if (isCompletelyVisibleY(y.rightCenter)) {
204
+ if (!opts.isCompletelyVisibleY(correctTop)) {
205
+ if (opts.isCompletelyVisibleY(opts.y.insideCenter)) {
200
206
  placement = "right-center";
201
- correctTop = y.rightCenter;
207
+ correctTop = opts.y.insideCenter;
202
208
  }
203
- else if (isCompletelyVisibleY(y.rightTop)) {
209
+ else if (opts.isCompletelyVisibleY(opts.y.insideTop)) {
204
210
  placement = "right-top";
205
- correctTop = y.rightTop;
211
+ correctTop = opts.y.insideTop;
206
212
  }
207
213
  }
208
- if (!isCompletelyVisibleX(correctLeft)) {
209
- if (isCompletelyVisibleX(x.left)) {
214
+ if (!opts.isCompletelyVisibleX(correctLeft)) {
215
+ if (opts.isCompletelyVisibleX(opts.x.left)) {
210
216
  placement = placement.replace("right", "left");
211
- correctLeft = x.left;
217
+ correctLeft = opts.x.left;
212
218
  }
213
219
  }
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
220
  return {
227
221
  top: correctTop,
228
222
  left: correctLeft,
229
- right: xEnd - correctLeft - nodeWidth,
230
- bottom: yEnd - correctTop - nodeHeight,
231
223
  placement,
232
224
  };
233
225
  }
234
226
  case "right-center": {
235
- correctLeft = x.right;
236
- correctTop = y.rightCenter;
227
+ correctLeft = opts.x.right;
228
+ correctTop = opts.y.insideCenter;
237
229
  let placement = "right-center";
238
- if (!isCompletelyVisibleY(correctTop)) {
239
- if (isCompletelyVisibleY(y.rightTop)) {
230
+ if (!opts.isCompletelyVisibleY(correctTop)) {
231
+ if (opts.isCompletelyVisibleY(opts.y.insideTop)) {
240
232
  placement = "right-top";
241
- correctTop = y.rightTop;
233
+ correctTop = opts.y.insideTop;
242
234
  }
243
- else if (isCompletelyVisibleY(y.rightBottom)) {
235
+ else if (opts.isCompletelyVisibleY(opts.y.insideBottom)) {
244
236
  placement = "right-bottom";
245
- correctTop = y.rightBottom;
237
+ correctTop = opts.y.insideBottom;
246
238
  }
247
239
  }
248
- if (!isCompletelyVisibleX(correctLeft)) {
249
- if (isCompletelyVisibleX(x.left)) {
240
+ if (!opts.isCompletelyVisibleX(correctLeft)) {
241
+ if (opts.isCompletelyVisibleX(opts.x.left)) {
250
242
  placement = placement.replace("right", "left");
251
- correctLeft = x.left;
243
+ correctLeft = opts.x.left;
252
244
  }
253
245
  }
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
246
  return {
267
247
  top: correctTop,
268
248
  left: correctLeft,
269
- right: xEnd - correctLeft - nodeWidth,
270
- bottom: yEnd - correctTop - nodeHeight,
271
249
  placement,
272
250
  };
273
251
  }
274
252
  case "right-top": {
275
- correctLeft = x.right;
276
- correctTop = y.rightTop;
253
+ correctLeft = opts.x.right;
254
+ correctTop = opts.y.insideTop;
277
255
  let placement = "right-top";
278
- if (!isCompletelyVisibleY(correctTop)) {
279
- if (isCompletelyVisibleY(y.rightCenter)) {
256
+ if (!opts.isCompletelyVisibleY(correctTop)) {
257
+ if (opts.isCompletelyVisibleY(opts.y.insideCenter)) {
280
258
  placement = "right-center";
281
- correctTop = y.rightCenter;
259
+ correctTop = opts.y.insideCenter;
282
260
  }
283
- else if (isCompletelyVisibleY(y.rightBottom)) {
261
+ else if (opts.isCompletelyVisibleY(opts.y.insideBottom)) {
284
262
  placement = "right-bottom";
285
- correctTop = y.rightBottom;
263
+ correctTop = opts.y.insideBottom;
286
264
  }
287
265
  }
288
- if (!isCompletelyVisibleX(correctLeft)) {
289
- if (isCompletelyVisibleX(x.left)) {
266
+ if (!opts.isCompletelyVisibleX(correctLeft)) {
267
+ if (opts.isCompletelyVisibleX(opts.x.left)) {
290
268
  placement = placement.replace("right", "left");
291
- correctLeft = x.left;
269
+ correctLeft = opts.x.left;
292
270
  }
293
271
  }
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
272
  return {
307
273
  top: correctTop,
308
274
  left: correctLeft,
309
- right: xEnd - correctLeft - nodeWidth,
310
- bottom: yEnd - correctTop - nodeHeight,
311
275
  placement,
312
276
  };
313
277
  }
314
278
  case "top-center": {
315
- correctLeft = x.bottomCenter;
316
- correctTop = y.top;
279
+ correctLeft = opts.x.insideCenter;
280
+ correctTop = opts.y.top;
317
281
  let placement = "top-center";
318
- if (!isCompletelyVisibleX(correctLeft)) {
319
- if (isCompletelyVisibleX(x.bottomLeft)) {
282
+ if (!opts.isCompletelyVisibleX(correctLeft)) {
283
+ if (opts.isCompletelyVisibleX(opts.x.insideLeft)) {
320
284
  placement = "top-left";
321
- correctLeft = x.bottomLeft;
285
+ correctLeft = opts.x.insideLeft;
322
286
  }
323
- else if (isCompletelyVisibleX(x.bottomRight)) {
287
+ else if (opts.isCompletelyVisibleX(opts.x.insideRight)) {
324
288
  placement = "top-right";
325
- correctLeft = x.bottomRight;
289
+ correctLeft = opts.x.insideRight;
326
290
  }
327
291
  }
328
- if (!isCompletelyVisibleY(correctTop)) {
329
- if (isCompletelyVisibleY(y.bottom)) {
292
+ if (!opts.isCompletelyVisibleY(correctTop)) {
293
+ if (opts.isCompletelyVisibleY(opts.y.bottom)) {
330
294
  placement = placement.replace("top", "bottom");
331
- correctTop = y.bottom;
295
+ correctTop = opts.y.bottom;
332
296
  }
333
297
  }
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
298
  return {
347
299
  top: correctTop,
348
300
  left: correctLeft,
349
- right: xEnd - correctLeft - nodeWidth,
350
- bottom: yEnd - correctTop - nodeHeight,
351
301
  placement,
352
302
  };
353
303
  }
354
304
  case "top-left": {
355
- correctLeft = x.bottomLeft;
356
- correctTop = y.top;
305
+ correctLeft = opts.x.insideLeft;
306
+ correctTop = opts.y.top;
357
307
  let placement = "top-left";
358
- if (!isCompletelyVisibleX(correctLeft)) {
359
- if (isCompletelyVisibleX(x.bottomCenter)) {
308
+ if (!opts.isCompletelyVisibleX(correctLeft)) {
309
+ if (opts.isCompletelyVisibleX(opts.x.insideCenter)) {
360
310
  placement = "top-center";
361
- correctLeft = x.bottomCenter;
311
+ correctLeft = opts.x.insideCenter;
362
312
  }
363
- else if (isCompletelyVisibleX(x.bottomRight)) {
313
+ else if (opts.isCompletelyVisibleX(opts.x.insideRight)) {
364
314
  placement = "top-right";
365
- correctLeft = x.bottomRight;
315
+ correctLeft = opts.x.insideRight;
366
316
  }
367
317
  }
368
- if (!isCompletelyVisibleY(correctTop)) {
369
- if (isCompletelyVisibleY(y.bottom)) {
318
+ if (!opts.isCompletelyVisibleY(correctTop)) {
319
+ if (opts.isCompletelyVisibleY(opts.y.bottom)) {
370
320
  placement = placement.replace("top", "bottom");
371
- correctTop = y.bottom;
321
+ correctTop = opts.y.bottom;
372
322
  }
373
323
  }
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
324
  return {
387
325
  top: correctTop,
388
326
  left: correctLeft,
389
- right: xEnd - correctLeft - nodeWidth,
390
- bottom: yEnd - correctTop - nodeHeight,
391
327
  placement,
392
328
  };
393
329
  }
394
330
  case "top-right": {
395
- correctLeft = x.bottomRight;
396
- correctTop = y.top;
331
+ correctLeft = opts.x.insideRight;
332
+ correctTop = opts.y.top;
397
333
  let placement = "top-right";
398
- if (!isCompletelyVisibleX(correctLeft)) {
399
- if (isCompletelyVisibleX(x.bottomCenter)) {
334
+ if (!opts.isCompletelyVisibleX(correctLeft)) {
335
+ if (opts.isCompletelyVisibleX(opts.x.insideCenter)) {
400
336
  placement = "top-center";
401
- correctLeft = x.bottomCenter;
337
+ correctLeft = opts.x.insideCenter;
402
338
  }
403
- else if (isCompletelyVisibleX(x.bottomLeft)) {
339
+ else if (opts.isCompletelyVisibleX(opts.x.insideLeft)) {
404
340
  placement = "top-left";
405
- correctLeft = x.bottomLeft;
341
+ correctLeft = opts.x.insideLeft;
406
342
  }
407
343
  }
408
- if (!isCompletelyVisibleY(correctTop)) {
409
- if (isCompletelyVisibleY(y.bottom)) {
344
+ if (!opts.isCompletelyVisibleY(correctTop)) {
345
+ if (opts.isCompletelyVisibleY(opts.y.bottom)) {
410
346
  placement = placement.replace("top", "bottom");
411
- correctTop = y.bottom;
347
+ correctTop = opts.y.bottom;
412
348
  }
413
349
  }
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
350
  return {
427
351
  top: correctTop,
428
352
  left: correctLeft,
429
- right: xEnd - correctLeft - nodeWidth,
430
- bottom: yEnd - correctTop - nodeHeight,
431
353
  placement,
432
354
  };
433
355
  }
434
356
  case "left-bottom": {
435
- correctLeft = x.left;
436
- correctTop = y.rightBottom;
357
+ correctLeft = opts.x.left;
358
+ correctTop = opts.y.insideBottom;
437
359
  let placement = "left-bottom";
438
- if (!isCompletelyVisibleY(correctTop)) {
439
- if (isCompletelyVisibleY(y.rightCenter)) {
360
+ if (!opts.isCompletelyVisibleY(correctTop)) {
361
+ if (opts.isCompletelyVisibleY(opts.y.insideCenter)) {
440
362
  placement = "left-center";
441
- correctTop = y.rightCenter;
363
+ correctTop = opts.y.insideCenter;
442
364
  }
443
- else if (isCompletelyVisibleY(y.rightTop)) {
365
+ else if (opts.isCompletelyVisibleY(opts.y.insideTop)) {
444
366
  placement = "left-top";
445
- correctTop = y.rightTop;
367
+ correctTop = opts.y.insideTop;
446
368
  }
447
369
  }
448
- if (!isCompletelyVisibleX(correctLeft)) {
449
- if (isCompletelyVisibleX(x.right)) {
370
+ if (!opts.isCompletelyVisibleX(correctLeft)) {
371
+ if (opts.isCompletelyVisibleX(opts.x.right)) {
450
372
  placement = placement.replace("left", "right");
451
- correctLeft = x.right;
373
+ correctLeft = opts.x.right;
452
374
  }
453
375
  }
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
376
  return {
467
377
  top: correctTop,
468
378
  left: correctLeft,
469
- right: xEnd - correctLeft - nodeWidth,
470
- bottom: yEnd - correctTop - nodeHeight,
471
379
  placement,
472
380
  };
473
381
  }
474
382
  case "left-center": {
475
- correctLeft = x.left;
476
- correctTop = y.rightCenter;
383
+ correctLeft = opts.x.left;
384
+ correctTop = opts.y.insideCenter;
477
385
  let placement = "left-center";
478
- if (!isCompletelyVisibleY(correctTop)) {
479
- if (isCompletelyVisibleY(y.rightTop)) {
386
+ if (!opts.isCompletelyVisibleY(correctTop)) {
387
+ if (opts.isCompletelyVisibleY(opts.y.insideTop)) {
480
388
  placement = "left-top";
481
- correctTop = y.rightTop;
389
+ correctTop = opts.y.insideTop;
482
390
  }
483
- else if (isCompletelyVisibleY(y.rightBottom)) {
391
+ else if (opts.isCompletelyVisibleY(opts.y.insideBottom)) {
484
392
  placement = "left-bottom";
485
- correctTop = y.rightBottom;
393
+ correctTop = opts.y.insideBottom;
486
394
  }
487
395
  }
488
- if (!isCompletelyVisibleX(correctLeft)) {
489
- if (isCompletelyVisibleX(x.right)) {
396
+ if (!opts.isCompletelyVisibleX(correctLeft)) {
397
+ if (opts.isCompletelyVisibleX(opts.x.right)) {
490
398
  placement = placement.replace("left", "right");
491
- correctLeft = x.right;
399
+ correctLeft = opts.x.right;
492
400
  }
493
401
  }
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
402
  return {
507
403
  top: correctTop,
508
404
  left: correctLeft,
509
- right: xEnd - correctLeft - nodeWidth,
510
- bottom: yEnd - correctTop - nodeHeight,
511
405
  placement,
512
406
  };
513
407
  }
514
408
  case "left-top": {
515
- correctLeft = x.left;
516
- correctTop = y.rightTop;
409
+ correctLeft = opts.x.left;
410
+ correctTop = opts.y.insideTop;
517
411
  let placement = "left-top";
518
- if (!isCompletelyVisibleY(correctTop)) {
519
- if (isCompletelyVisibleY(y.rightCenter)) {
412
+ if (!opts.isCompletelyVisibleY(correctTop)) {
413
+ if (opts.isCompletelyVisibleY(opts.y.insideCenter)) {
520
414
  placement = "left-center";
521
- correctTop = y.rightCenter;
415
+ correctTop = opts.y.insideCenter;
522
416
  }
523
- else if (isCompletelyVisibleY(y.rightBottom)) {
417
+ else if (opts.isCompletelyVisibleY(opts.y.insideBottom)) {
524
418
  placement = "left-bottom";
525
- correctTop = y.rightBottom;
419
+ correctTop = opts.y.insideBottom;
526
420
  }
527
421
  }
528
- if (!isCompletelyVisibleX(correctLeft)) {
529
- if (isCompletelyVisibleX(x.right)) {
422
+ if (!opts.isCompletelyVisibleX(correctLeft)) {
423
+ if (opts.isCompletelyVisibleX(opts.x.right)) {
530
424
  placement = placement.replace("left", "right");
531
- correctLeft = x.right;
425
+ correctLeft = opts.x.right;
532
426
  }
533
427
  }
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
428
  return {
547
429
  top: correctTop,
548
430
  left: correctLeft,
549
- right: xEnd - correctLeft - nodeWidth,
550
- bottom: yEnd - correctTop - nodeHeight,
551
431
  placement,
552
432
  };
553
433
  }
@@ -555,33 +435,11 @@ function getVisiblePosition({ initialPosition, node, visibleArea, placement = "b
555
435
  return {
556
436
  top: correctTop,
557
437
  left: correctLeft,
558
- right: xEnd - correctLeft - nodeWidth,
559
- bottom: yEnd - correctTop - nodeHeight,
560
- placement,
438
+ placement: opts.placement,
561
439
  };
562
440
  }
563
441
  }
564
442
  }
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
443
  function getFlexVisiblePosition({ initialLeft, initialTop, isCompletelyVisibleX, isCompletelyVisibleY, nodeHeight, nodeWidth, xEnd, yEnd, }) {
586
444
  if (!isCompletelyVisibleY(initialTop)) {
587
445
  initialTop = yEnd - nodeHeight;
@@ -592,8 +450,6 @@ function getFlexVisiblePosition({ initialLeft, initialTop, isCompletelyVisibleX,
592
450
  return {
593
451
  top: initialTop,
594
452
  left: initialLeft,
595
- bottom: yEnd - initialTop - nodeHeight,
596
- right: xEnd - initialLeft - nodeWidth,
597
453
  placement: "flex",
598
454
  };
599
455
  }