@enact/spotlight 3.4.9-experimental-3 → 3.4.9-experimental-7

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.
Files changed (68) hide show
  1. package/{build/Accelerator → Accelerator}/Accelerator.d.ts +0 -0
  2. package/Accelerator/Accelerator.js +149 -156
  3. package/CHANGELOG.md +22 -0
  4. package/{build/Pause → Pause}/Pause.d.ts +0 -0
  5. package/Pause/Pause.js +102 -80
  6. package/Pause/tests/Pause-specs.js +65 -97
  7. package/SpotlightContainerDecorator/SpotlightContainer.js +175 -140
  8. package/{build/SpotlightContainerDecorator → SpotlightContainerDecorator}/SpotlightContainerDecorator.d.ts +0 -0
  9. package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +222 -176
  10. package/SpotlightContainerDecorator/tests/Element.prototype.closest.js +44 -40
  11. package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +221 -210
  12. package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +150 -243
  13. package/SpotlightContainerDecorator/useSpotlightContainer.js +47 -28
  14. package/{build/SpotlightRootDecorator → SpotlightRootDecorator}/SpotlightRootDecorator.d.ts +0 -0
  15. package/SpotlightRootDecorator/SpotlightRootDecorator.js +206 -111
  16. package/{build/Spottable → Spottable}/Spottable.d.ts +0 -0
  17. package/Spottable/Spottable.js +448 -410
  18. package/Spottable/tests/Spottable-specs.js +90 -117
  19. package/package.json +3 -2
  20. package/src/container.js +718 -653
  21. package/src/navigate.js +406 -491
  22. package/src/pointer.js +86 -78
  23. package/{build/src → src}/spotlight.d.ts +0 -0
  24. package/src/spotlight.js +846 -885
  25. package/src/target.js +448 -474
  26. package/src/tests/container-specs.js +643 -1251
  27. package/src/tests/navigate-specs.js +77 -134
  28. package/src/tests/pointer-specs.js +126 -182
  29. package/src/tests/spotlight-specs.js +103 -133
  30. package/src/tests/target-specs.js +597 -960
  31. package/src/tests/utils.js +89 -67
  32. package/src/utils.js +155 -158
  33. package/build/Accelerator/Accelerator.js +0 -162
  34. package/build/Accelerator/package.json +0 -3
  35. package/build/CHANGELOG.md +0 -838
  36. package/build/Pause/Pause.js +0 -164
  37. package/build/Pause/package.json +0 -3
  38. package/build/Pause/tests/Pause-specs.js +0 -65
  39. package/build/README.md +0 -61
  40. package/build/SpotlightContainerDecorator/SpotlightContainer.js +0 -176
  41. package/build/SpotlightContainerDecorator/SpotlightContainerDecorator.js +0 -282
  42. package/build/SpotlightContainerDecorator/package.json +0 -3
  43. package/build/SpotlightContainerDecorator/tests/Element.prototype.closest.js +0 -45
  44. package/build/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +0 -221
  45. package/build/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +0 -160
  46. package/build/SpotlightContainerDecorator/useSpotlightContainer.js +0 -133
  47. package/build/SpotlightRootDecorator/SpotlightRootDecorator.js +0 -189
  48. package/build/SpotlightRootDecorator/package.json +0 -3
  49. package/build/Spottable/Spottable.js +0 -491
  50. package/build/Spottable/package.json +0 -3
  51. package/build/Spottable/tests/Spottable-specs.js +0 -90
  52. package/build/package-lock.json +0 -229
  53. package/build/package.json +0 -28
  54. package/build/src/container.js +0 -1201
  55. package/build/src/navigate.js +0 -419
  56. package/build/src/pointer.js +0 -183
  57. package/build/src/spotlight.js +0 -896
  58. package/build/src/target.js +0 -507
  59. package/build/src/tests/container-specs.js +0 -653
  60. package/build/src/tests/navigate-specs.js +0 -87
  61. package/build/src/tests/pointer-specs.js +0 -130
  62. package/build/src/tests/spotlight-specs.js +0 -112
  63. package/build/src/tests/target-specs.js +0 -614
  64. package/build/src/tests/utils.js +0 -104
  65. package/build/src/utils.js +0 -180
  66. package/build/styles/debug.less +0 -97
  67. package/build/styles/mixins.less +0 -63
  68. package/docs/index.md +0 -364
@@ -1,507 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getNavigableTarget = getNavigableTarget;
7
- exports.getTargetByContainer = getTargetByContainer;
8
- exports.getTargetByDirectionFromElement = getTargetByDirectionFromElement;
9
- exports.getTargetByDirectionFromPosition = getTargetByDirectionFromPosition;
10
- exports.getTargetBySelector = getTargetBySelector;
11
- exports.isFocusable = isFocusable;
12
- exports.getNearestTargetFromPosition = void 0;
13
-
14
- var _clamp = _interopRequireDefault(require("ramda/src/clamp"));
15
-
16
- var _last = _interopRequireDefault(require("ramda/src/last"));
17
-
18
- var _container = require("./container");
19
-
20
- var _navigate = _interopRequireDefault(require("./navigate"));
21
-
22
- var _utils = require("./utils");
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
25
-
26
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
27
-
28
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
29
-
30
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
31
-
32
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
33
-
34
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
35
-
36
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
37
-
38
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
39
-
40
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
41
-
42
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
43
-
44
- function isFocusable(elem) {
45
- var containers = (0, _container.getContainersForNode)(elem);
46
- var verifySelector = true;
47
-
48
- for (var i = containers.length - 1; i >= 0; i--) {
49
- var containerId = containers[i];
50
-
51
- if (!(0, _container.isNavigable)(elem, containerId, verifySelector)) {
52
- return false;
53
- } // only verify selector for the first (immediate ancestor) container
54
-
55
-
56
- verifySelector = false;
57
- }
58
-
59
- return true;
60
- }
61
-
62
- function getContainersToSearch(containerId) {
63
- var range = [];
64
-
65
- var addRange = function addRange(id) {
66
- var config = (0, _container.getContainerConfig)(id);
67
-
68
- if (id && range.indexOf(id) < 0 && config && !config.selectorDisabled) {
69
- range.push(id);
70
- }
71
- };
72
-
73
- if (containerId) {
74
- addRange(containerId);
75
- } else {
76
- addRange((0, _container.getDefaultContainer)());
77
- addRange((0, _container.getLastContainer)());
78
-
79
- _toConsumableArray((0, _container.getAllContainerIds)()).map(addRange);
80
- }
81
-
82
- return range;
83
- }
84
-
85
- function getTargetByContainer(containerId, enterTo) {
86
- return getContainersToSearch(containerId).reduce(function (next, id) {
87
- return next || (0, _container.getContainerFocusTarget)(id, enterTo);
88
- }, null);
89
- }
90
-
91
- function getTargetBySelector(selector) {
92
- if (!selector) return null;
93
-
94
- if (selector.charAt(0) === '@') {
95
- var containerId = selector.length === 1 ? null : selector.substr(1);
96
- return getTargetByContainer(containerId);
97
- }
98
-
99
- var next = (0, _utils.parseSelector)(selector)[0];
100
-
101
- if (next) {
102
- if ((0, _container.isContainer)(next)) {
103
- return getTargetByContainer((0, _container.getContainerId)(next));
104
- }
105
-
106
- var nextContainerIds = (0, _container.getContainersForNode)(next);
107
-
108
- if ((0, _container.isNavigable)(next, (0, _last["default"])(nextContainerIds), true)) {
109
- return next;
110
- }
111
- }
112
-
113
- return null;
114
- }
115
-
116
- function isRestrictedContainer(containerId) {
117
- var config = (0, _container.getContainerConfig)(containerId);
118
- return config && (config.enterTo === 'last-focused' || config.enterTo === 'default-element');
119
- }
120
-
121
- function filterRects(elementRects, boundingRect) {
122
- if (!boundingRect) {
123
- return elementRects;
124
- } // remove elements that are outside of boundingRect, if specified
125
-
126
-
127
- return elementRects.filter(function (rect) {
128
- if ((0, _container.isContainer)(rect.element)) {
129
- // For containers, test intersection since they may be larger than the bounding rect
130
- return (0, _utils.intersects)(boundingRect, rect);
131
- } else {
132
- // For elements, use contains with the center to include mostly visible elements
133
- return (0, _utils.contains)(boundingRect, rect.center);
134
- }
135
- }).map(function (rect) {
136
- var topUpdate = rect.top < boundingRect.top;
137
- var bottomUpdate = rect.bottom > boundingRect.bottom;
138
- var leftUpdate = rect.left < boundingRect.left;
139
- var rightUpdate = rect.right > boundingRect.right; // if the element's rect is larger than the bounding rect, clamp it to the bounding rect and
140
- // recalculate the center based on the new bounds.
141
-
142
- if (topUpdate || bottomUpdate || leftUpdate || rightUpdate) {
143
- var updated = _objectSpread(_objectSpread({}, rect), {}, {
144
- center: _objectSpread({}, rect.center)
145
- });
146
-
147
- if (topUpdate) updated.top = boundingRect.top;
148
- if (bottomUpdate) updated.bottom = boundingRect.bottom;
149
- if (leftUpdate) updated.left = boundingRect.left;
150
- if (rightUpdate) updated.right = boundingRect.right;
151
-
152
- if (leftUpdate || rightUpdate) {
153
- var centerX = updated.left + (updated.right - updated.left) / 2;
154
- updated.center.x = updated.center.left = updated.center.right = centerX;
155
- }
156
-
157
- if (topUpdate || bottomUpdate) {
158
- var centerY = updated.top + (updated.bottom - updated.top) / 2;
159
- updated.center.y = updated.center.top = updated.center.bottom = centerY;
160
- }
161
-
162
- return updated;
163
- }
164
-
165
- return rect;
166
- });
167
- }
168
-
169
- function getContainerContainingRect(elementRects, elementRect) {
170
- // find candidates that are containers and *visually* contain element
171
- var overlapping = elementRects.filter(function (rect) {
172
- return (0, _container.isContainer)(rect.element) && (0, _utils.contains)(rect, elementRect);
173
- }); // if the next element is a container AND the current element is *visually* contained within
174
- // one of the candidate element, we need to ignore container `enterTo` preferences and
175
- // retrieve its spottable descendants and try to navigate to them.
176
-
177
- if (overlapping.length) {
178
- return overlapping[0].element.dataset.spotlightId;
179
- }
180
-
181
- return false;
182
- }
183
-
184
- function getOverflowContainerRect(containerId) {
185
- // if the target container has overflowing content, update the boundingRect to match its
186
- // bounds to prevent finding elements within the container's hierarchy but not visible.
187
- // This filter only applies when waterfalling to prevent filtering out elements that share
188
- // a container tree with `element`
189
- var nextConfig = (0, _container.getContainerConfig)(containerId);
190
-
191
- if (nextConfig && nextConfig.overflow) {
192
- return (0, _utils.getContainerRect)(containerId);
193
- }
194
- }
195
-
196
- function getTargetInContainerByDirectionFromPosition(direction, containerId, positionRect, elementContainerIds, boundingRect) {
197
- var elements = (0, _container.getDeepSpottableDescendants)(containerId);
198
- var elementRects = filterRects((0, _utils.getRects)(elements), boundingRect);
199
- var next = null;
200
-
201
- var _loop = function _loop() {
202
- var overlappingContainerId = getContainerContainingRect(elementRects, positionRect); // if the pointer is within a container that is a candidate element, we need to ignore container
203
- // `enterTo` preferences and retrieve its spottable descendants and try to navigate to them.
204
-
205
- if (overlappingContainerId) {
206
- next = getTargetInContainerByDirectionFromPosition(direction, overlappingContainerId, positionRect, elementContainerIds, boundingRect);
207
-
208
- if (!next) {
209
- // filter out the container and try again
210
- elementRects = elementRects.filter(function (rect) {
211
- return rect.element.dataset.spotlightId !== overlappingContainerId;
212
- });
213
- return "continue";
214
- } // found a target so break out and return
215
-
216
-
217
- return "break";
218
- } // try to navigate from position to one of the candidates in containerId
219
-
220
-
221
- next = (0, _navigate["default"])(positionRect, direction, elementRects, (0, _container.getContainerConfig)(containerId)); // if we match a container, recurse into it
222
-
223
- if (next && (0, _container.isContainer)(next)) {
224
- var nextContainerId = next.dataset.spotlightId; // need to cache this reference so we can filter it out later if necessary
225
-
226
- var lastNavigated = next;
227
- next = getTargetInContainerByDirectionFromPosition(direction, nextContainerId, positionRect, elementContainerIds, getOverflowContainerRect(nextContainerId) || boundingRect);
228
-
229
- if (!next) {
230
- // filter out the container and try again
231
- elementRects = elementRects.filter(function (rect) {
232
- return rect.element !== lastNavigated;
233
- });
234
- return "continue";
235
- }
236
- } // If we've met every condition and haven't explicitly retried the search via `continue`,
237
- // break out and return
238
-
239
-
240
- return "break";
241
- };
242
-
243
- while (elementRects.length > 0) {
244
- var _ret = _loop();
245
-
246
- if (_ret === "continue") continue;
247
- if (_ret === "break") break;
248
- }
249
-
250
- return next;
251
- }
252
-
253
- function getTargetInContainerByDirectionFromElement(direction, containerId, element, elementRect, elementContainerIds, boundingRect) {
254
- var elements = (0, _container.getDeepSpottableDescendants)(containerId); // shortcut for previous target from element if it were saved
255
-
256
- var previous = (0, _container.getContainerPreviousTarget)(containerId, direction, element);
257
-
258
- if (previous && elements.indexOf(previous) !== -1) {
259
- return previous;
260
- } // `spotlightOverflow` is a private, and likely temporary, API to allow a component within an
261
- // spotlight container with `overflow: true` to be treated as if it were outside of the
262
- // container. The result is that the candidates, `elements` are filtered by the bounds of the
263
- // overflow container effectively hiding those that have overflowed and are visually hidden.
264
- //
265
- // Currently only used by moonstone/Scroller.Scrollbar as a means to allow 5-way navigation to
266
- // escape the Scrollable from paging controls rather than focusing contents that are out of view
267
-
268
-
269
- if (element.dataset.spotlightOverflow === 'ignore') {
270
- boundingRect = getOverflowContainerRect(containerId) || boundingRect;
271
- }
272
-
273
- var elementRects = filterRects((0, _utils.getRects)(elements), boundingRect);
274
- var next = null;
275
-
276
- var _loop2 = function _loop2() {
277
- var overlappingContainerId = getContainerContainingRect(elementRects, elementRect); // if the next element is a container AND the current element is *visually* contained within
278
- // one of the candidate elements, we need to ignore container `enterTo` preferences and
279
- // retrieve its spottable descendants and try to navigate to them.
280
-
281
- if (overlappingContainerId) {
282
- next = getTargetInContainerByDirectionFromElement(direction, overlappingContainerId, element, elementRect, elementContainerIds, boundingRect);
283
-
284
- if (!next) {
285
- // filter out the container and try again
286
- elementRects = elementRects.filter(function (rect) {
287
- return rect.element.dataset.spotlightId !== overlappingContainerId;
288
- });
289
- return "continue";
290
- } // found a target so break out and return
291
-
292
-
293
- return "break";
294
- } // If one of the downstream containers is configured for partition, we use that
295
- // container's bounds as the partition rect for navigation.
296
-
297
-
298
- var partitionContainer = elementContainerIds.slice(elementContainerIds.indexOf(containerId) + 1).find(function (id) {
299
- var cfg = (0, _container.getContainerConfig)(id);
300
- return cfg && cfg.partition;
301
- });
302
- var partitionRect = elementRect;
303
-
304
- if (partitionContainer) {
305
- partitionRect = (0, _utils.getContainerRect)(partitionContainer);
306
- } // try to navigate from element to one of the candidates in containerId
307
-
308
-
309
- next = (0, _navigate["default"])(elementRect, direction, elementRects, (0, _container.getContainerConfig)(containerId), partitionRect); // if we match a container,
310
-
311
- if (next && (0, _container.isContainer)(next)) {
312
- var nextContainerId = next.dataset.spotlightId; // need to cache this reference so we can filter it out later if necessary
313
-
314
- var lastNavigated = next; // and it is restricted, return its target
315
-
316
- if (isRestrictedContainer(nextContainerId)) {
317
- next = getTargetByContainer(nextContainerId);
318
- } else {
319
- // otherwise, recurse into it
320
- next = getTargetInContainerByDirectionFromElement(direction, nextContainerId, element, elementRect, elementContainerIds, getOverflowContainerRect(nextContainerId) || boundingRect);
321
- }
322
-
323
- if (!next) {
324
- elementRects = elementRects.filter(function (rect) {
325
- return rect.element !== lastNavigated;
326
- });
327
- return "continue";
328
- }
329
- } // If we've met every condition and haven't explicitly retried the search via `continue`,
330
- // break out and return
331
-
332
-
333
- return "break";
334
- };
335
-
336
- while (elementRects.length > 0) {
337
- var _ret2 = _loop2();
338
-
339
- if (_ret2 === "continue") continue;
340
- if (_ret2 === "break") break;
341
- }
342
-
343
- return next;
344
- }
345
-
346
- function getTargetByDirectionFromElement(direction, element) {
347
- var extSelector = element.getAttribute('data-spot-' + direction);
348
-
349
- if (typeof extSelector === 'string') {
350
- return getTargetBySelector(extSelector);
351
- }
352
-
353
- var elementRect = (0, _utils.getRect)(element);
354
- var next = (0, _container.getNavigableContainersForNode)(element).reduceRight(function (result, containerId, index, elementContainerIds) {
355
- result = result || getTargetInContainerByDirectionFromElement(direction, containerId, element, elementRect, elementContainerIds);
356
-
357
- if (!result) {
358
- result = getLeaveForTarget(containerId, direction); // To support a `leaveFor` configuration with navigation disallowed in the current
359
- // `direction`, we return the current element to prevent further searches for a
360
- // target in this reduction.
361
-
362
- if (result === false) {
363
- result = element;
364
- }
365
- }
366
-
367
- return result;
368
- }, null); // if the reduce above returns the original element, it means it hit a `leaveFor` config that
369
- // prevents navigation so we enforce that here by returning null.
370
-
371
- return next !== element ? next : null;
372
- }
373
-
374
- function getTargetByDirectionFromPosition(direction, position, containerId) {
375
- var pointerRect = (0, _utils.getPointRect)(position);
376
- return (0, _container.getNavigableContainersForNode)((0, _container.getContainerNode)(containerId)).reduceRight(function (result, id, index, elementContainerIds) {
377
- return result || getTargetInContainerByDirectionFromPosition(direction, id, pointerRect, elementContainerIds);
378
- }, null);
379
- }
380
- /**
381
- * Returns the target identified by the selector configured for the container identified by
382
- * `containerId` for the given `direction`. If the selector is an empty string, the method returns
383
- * `false` indicating that navigation isn't allowed out of the container in that direction.
384
- *
385
- * @param {String} containerId Identifier for a container
386
- * @param {String} direction Direction to navigate (up, down, left, right)
387
- *
388
- * @returns {Node|Boolean} Target, if found, or `false` if navigation is disallowed
389
- * @private
390
- */
391
-
392
-
393
- function getLeaveForTarget(containerId, direction) {
394
- var config = (0, _container.getContainerConfig)(containerId);
395
-
396
- if (config) {
397
- var target = config.restrict !== 'self-only' && config.leaveFor && config.leaveFor[direction];
398
-
399
- if (typeof target === 'string') {
400
- if (target === '') {
401
- return false;
402
- }
403
-
404
- return getTargetBySelector(target);
405
- }
406
-
407
- var nextContainerIds = (0, _container.getContainersForNode)(target);
408
-
409
- if ((0, _container.isNavigable)(target, (0, _last["default"])(nextContainerIds))) {
410
- return target;
411
- }
412
- }
413
-
414
- return null;
415
- }
416
-
417
- function getNavigableTarget(target) {
418
- if (target === document) return null;
419
- var parent;
420
-
421
- while (target && ((0, _container.isContainer)(target) || !isFocusable(target))) {
422
- parent = target.parentNode;
423
- target = parent === document ? null : parent; // calling isNavigable on document is problematic
424
- }
425
-
426
- return target;
427
- }
428
-
429
- var getOffsetDistanceToTargetFromPosition = function getOffsetDistanceToTargetFromPosition(distance, direction, _ref, _ref2) {
430
- var x = _ref.x,
431
- y = _ref.y;
432
- var left = _ref2.left,
433
- right = _ref2.right,
434
- top = _ref2.top,
435
- bottom = _ref2.bottom;
436
-
437
- if (direction === 'left' || direction === 'right') {
438
- if (y > bottom) {
439
- distance += y - bottom;
440
- } else if (y < top) {
441
- distance += top - y;
442
- }
443
- } else if (x > right) {
444
- distance += x - right;
445
- } else if (x < left) {
446
- distance += left - x;
447
- }
448
-
449
- return distance;
450
- };
451
-
452
- var getDistanceToTargetFromPosition = function getDistanceToTargetFromPosition(direction, position, elementRect) {
453
- var x = position.x,
454
- y = position.y;
455
- var distance;
456
-
457
- if (direction === 'left') {
458
- distance = x - elementRect.right;
459
- } else if (direction === 'right') {
460
- distance = elementRect.left - x;
461
- } else if (direction === 'up') {
462
- distance = y - elementRect.bottom;
463
- } else if (direction === 'down') {
464
- distance = elementRect.top - y;
465
- }
466
-
467
- return getOffsetDistanceToTargetFromPosition((0, _clamp["default"])(0, Math.abs(distance), distance), direction, position, elementRect);
468
- };
469
-
470
- var getNearestTargetsInContainerFromPosition = function getNearestTargetsInContainerFromPosition(position, containerId) {
471
- return ['up', 'left', 'right', 'down'].reduce(function (result, direction) {
472
- var target = getTargetByDirectionFromPosition(direction, position, containerId);
473
-
474
- if (target) {
475
- result.push({
476
- direction: direction,
477
- target: target
478
- });
479
- }
480
-
481
- return result;
482
- }, []);
483
- };
484
-
485
- var getNearestTargetInContainerFromPosition = function getNearestTargetInContainerFromPosition(position, containerId) {
486
- var targets = getNearestTargetsInContainerFromPosition(position, containerId);
487
-
488
- if (!targets.length) {
489
- return;
490
- }
491
-
492
- targets.forEach(function (item) {
493
- var direction = item.direction,
494
- target = item.target;
495
- item.distance = getDistanceToTargetFromPosition(direction, position, (0, _utils.getRect)(target));
496
- });
497
- targets.sort(function (a, b) {
498
- return a.distance - b.distance;
499
- });
500
- return targets[0].target;
501
- };
502
-
503
- var getNearestTargetFromPosition = function getNearestTargetFromPosition(position, containerId) {
504
- return getNavigableTarget(document.elementFromPoint(position.x, position.y)) || getNearestTargetInContainerFromPosition(position, containerId);
505
- };
506
-
507
- exports.getNearestTargetFromPosition = getNearestTargetFromPosition;