@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
package/src/navigate.js CHANGED
@@ -1,504 +1,419 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.navigate = navigate;
7
+ exports["default"] = void 0;
8
+ var obliqueMinDistance = 1;
9
+ var straightMinDistance = 0;
10
+
11
+ var calcGroupId = function calcGroupId(_ref) {
12
+ var x = _ref.x,
13
+ y = _ref.y;
14
+ return y * 3 + x;
15
+ };
1
16
 
2
- const obliqueMinDistance = 1;
3
- const straightMinDistance = 0;
4
-
5
- const calcGroupId = ({x, y}) => y * 3 + x;
6
-
7
- const calcNextGridPosition = (current, next) => {
8
- const center = current.center;
9
- let x, y;
10
-
11
- if (center.x < next.left) {
12
- x = 0;
13
- } else if (center.x <= next.right) {
14
- x = 1;
15
- } else {
16
- x = 2;
17
- }
18
-
19
- if (center.y < next.top) {
20
- y = 0;
21
- } else if (center.y <= next.bottom) {
22
- y = 1;
23
- } else {
24
- y = 2;
25
- }
26
-
27
- return {x, y};
17
+ var calcNextGridPosition = function calcNextGridPosition(current, next) {
18
+ var center = current.center;
19
+ var x, y;
20
+
21
+ if (center.x < next.left) {
22
+ x = 0;
23
+ } else if (center.x <= next.right) {
24
+ x = 1;
25
+ } else {
26
+ x = 2;
27
+ }
28
+
29
+ if (center.y < next.top) {
30
+ y = 0;
31
+ } else if (center.y <= next.bottom) {
32
+ y = 1;
33
+ } else {
34
+ y = 2;
35
+ }
36
+
37
+ return {
38
+ x: x,
39
+ y: y
40
+ };
28
41
  };
29
42
 
30
- const calcNextExtendedGridPosition = (current, next) => {
31
- let x, y;
32
-
33
- if (current.right <= next.left) {
34
- x = 0;
35
- } else if (current.left < next.right) {
36
- x = 1;
37
- } else {
38
- x = 2;
39
- }
40
-
41
- if (current.bottom <= next.top) {
42
- y = 0;
43
- } else if (current.top < next.bottom) {
44
- y = 1;
45
- } else {
46
- y = 2;
47
- }
48
-
49
- return {x, y};
43
+ var calcNextExtendedGridPosition = function calcNextExtendedGridPosition(current, next) {
44
+ var x, y;
45
+
46
+ if (current.right <= next.left) {
47
+ x = 0;
48
+ } else if (current.left < next.right) {
49
+ x = 1;
50
+ } else {
51
+ x = 2;
52
+ }
53
+
54
+ if (current.bottom <= next.top) {
55
+ y = 0;
56
+ } else if (current.top < next.bottom) {
57
+ y = 1;
58
+ } else {
59
+ y = 2;
60
+ }
61
+
62
+ return {
63
+ x: x,
64
+ y: y
65
+ };
50
66
  };
51
67
 
52
- function prioritize (priorities, targetEdge) {
53
- const destGroup = [];
54
-
55
- for (let index = 0; index < priorities.length; index++) {
56
- const destPriority = priorities[index];
57
-
58
- if (destPriority.group.length) {
59
- const destDistance = destPriority.distance;
60
- const destDifference = destPriority.difference;
61
- let distance = 0;
62
- let target;
63
-
64
- destPriority.group.sort(function (a, b) {
65
- for (let i = 0; i < destDistance.length; i++) {
66
- const calcDistance = destDistance[i];
67
- const delta = calcDistance(a) - calcDistance(b);
68
- if (delta) {
69
- return delta;
70
- }
71
- }
72
- return 0;
73
- });
74
-
75
- target = destPriority.group[0];
76
- for (let i = 0; i < destDifference.length; i++) {
77
- distance += destDifference[i](target);
78
- }
79
-
80
- destGroup.push({
81
- distance: Math.pow(destPriority.multiplier * (distance || destPriority.minDistance) / targetEdge, 2) + targetEdge,
82
- target
83
- });
84
- }
85
- }
86
-
87
- if (!destGroup.length) {
88
- return null;
89
- }
90
-
91
- destGroup.sort(function (a, b) {
92
- return a.distance - b.distance;
93
- });
94
-
95
- return destGroup;
68
+ function prioritize(priorities, targetEdge) {
69
+ var destGroup = [];
70
+
71
+ for (var index = 0; index < priorities.length; index++) {
72
+ var destPriority = priorities[index];
73
+
74
+ if (destPriority.group.length) {
75
+ (function () {
76
+ var destDistance = destPriority.distance;
77
+ var destDifference = destPriority.difference;
78
+ var distance = 0;
79
+ var target = void 0;
80
+ destPriority.group.sort(function (a, b) {
81
+ for (var i = 0; i < destDistance.length; i++) {
82
+ var calcDistance = destDistance[i];
83
+ var delta = calcDistance(a) - calcDistance(b);
84
+
85
+ if (delta) {
86
+ return delta;
87
+ }
88
+ }
89
+
90
+ return 0;
91
+ });
92
+ target = destPriority.group[0];
93
+
94
+ for (var i = 0; i < destDifference.length; i++) {
95
+ distance += destDifference[i](target);
96
+ }
97
+
98
+ destGroup.push({
99
+ distance: Math.pow(destPriority.multiplier * (distance || destPriority.minDistance) / targetEdge, 2) + targetEdge,
100
+ target: target
101
+ });
102
+ })();
103
+ }
104
+ }
105
+
106
+ if (!destGroup.length) {
107
+ return null;
108
+ }
109
+
110
+ destGroup.sort(function (a, b) {
111
+ return a.distance - b.distance;
112
+ });
113
+ return destGroup;
96
114
  }
97
115
 
98
- function partition (rects, targetRect, straightOverlapThreshold, getGroupId) {
99
- // a matrix of elements where the center of the element in relation to targetRect is:
100
- const groups = [
101
- [/* [0] => above/left */], [/* [1] => above/within */], [/* [2] => above/right */],
102
- [/* [3] => within/left */], [/* [4] => within */], [/* [5] => within/right */],
103
- [/* [6] => below/left */], [/* [7] => below and within */], [/* [8] => below/right */]
104
- ];
105
-
106
- for (let i = 0; i < rects.length; i++) {
107
- const rect = rects[i];
108
- const groupId = getGroupId(rect, targetRect);
109
- groups[groupId].push(rect);
110
-
111
- if ([0, 2, 6, 8].indexOf(groupId) !== -1) {
112
- if (rect.left <= targetRect.right - targetRect.width * straightOverlapThreshold) {
113
- if (groupId === 2) {
114
- groups[1].push(rect);
115
- } else if (groupId === 8) {
116
- groups[7].push(rect);
117
- }
118
- }
119
-
120
- if (rect.right >= targetRect.left + targetRect.width * straightOverlapThreshold) {
121
- if (groupId === 0) {
122
- groups[1].push(rect);
123
- } else if (groupId === 6) {
124
- groups[7].push(rect);
125
- }
126
- }
127
-
128
- if (rect.top <= targetRect.bottom - targetRect.height * straightOverlapThreshold) {
129
- if (groupId === 6) {
130
- groups[3].push(rect);
131
- } else if (groupId === 8) {
132
- groups[5].push(rect);
133
- }
134
- }
135
-
136
- if (rect.bottom >= targetRect.top + targetRect.height * straightOverlapThreshold) {
137
- if (groupId === 0) {
138
- groups[3].push(rect);
139
- } else if (groupId === 2) {
140
- groups[5].push(rect);
141
- }
142
- }
143
- }
144
- }
145
-
146
- return groups;
116
+ function partition(rects, targetRect, straightOverlapThreshold, getGroupId) {
117
+ // a matrix of elements where the center of the element in relation to targetRect is:
118
+ var groups = [[
119
+ /* [0] => above/left */
120
+ ], [
121
+ /* [1] => above/within */
122
+ ], [
123
+ /* [2] => above/right */
124
+ ], [
125
+ /* [3] => within/left */
126
+ ], [
127
+ /* [4] => within */
128
+ ], [
129
+ /* [5] => within/right */
130
+ ], [
131
+ /* [6] => below/left */
132
+ ], [
133
+ /* [7] => below and within */
134
+ ], [
135
+ /* [8] => below/right */
136
+ ]];
137
+
138
+ for (var i = 0; i < rects.length; i++) {
139
+ var rect = rects[i];
140
+ var groupId = getGroupId(rect, targetRect);
141
+ groups[groupId].push(rect);
142
+
143
+ if ([0, 2, 6, 8].indexOf(groupId) !== -1) {
144
+ if (rect.left <= targetRect.right - targetRect.width * straightOverlapThreshold) {
145
+ if (groupId === 2) {
146
+ groups[1].push(rect);
147
+ } else if (groupId === 8) {
148
+ groups[7].push(rect);
149
+ }
150
+ }
151
+
152
+ if (rect.right >= targetRect.left + targetRect.width * straightOverlapThreshold) {
153
+ if (groupId === 0) {
154
+ groups[1].push(rect);
155
+ } else if (groupId === 6) {
156
+ groups[7].push(rect);
157
+ }
158
+ }
159
+
160
+ if (rect.top <= targetRect.bottom - targetRect.height * straightOverlapThreshold) {
161
+ if (groupId === 6) {
162
+ groups[3].push(rect);
163
+ } else if (groupId === 8) {
164
+ groups[5].push(rect);
165
+ }
166
+ }
167
+
168
+ if (rect.bottom >= targetRect.top + targetRect.height * straightOverlapThreshold) {
169
+ if (groupId === 0) {
170
+ groups[3].push(rect);
171
+ } else if (groupId === 2) {
172
+ groups[5].push(rect);
173
+ }
174
+ }
175
+ }
176
+ }
177
+
178
+ return groups;
147
179
  }
148
180
 
149
- function generateDistancefunction (targetRect) {
150
- return {
151
- nearPlumbLineIsBetter: function (rect) {
152
- let d;
153
- if (rect.center.x < targetRect.center.x) {
154
- d = targetRect.center.x - rect.right;
155
- } else {
156
- d = rect.left - targetRect.center.x;
157
- }
158
- return d < 0 ? 0 : d;
159
- },
160
- nearHorizonIsBetter: function (rect) {
161
- let d;
162
- if (rect.center.y < targetRect.center.y) {
163
- d = targetRect.center.y - rect.bottom;
164
- } else {
165
- d = rect.top - targetRect.center.y;
166
- }
167
- return d < 0 ? 0 : d;
168
- },
169
- nearTargetBottomIsBetter: function (rect) {
170
- let d;
171
- if (rect.center.y < targetRect.center.y) {
172
- d = targetRect.bottom - rect.top;
173
- } else {
174
- d = rect.top - targetRect.bottom;
175
- }
176
- return d < 0 ? 0 : d;
177
- },
178
- nearTargetLeftIsBetter: function (rect) {
179
- let d;
180
- if (rect.center.x < targetRect.center.x) {
181
- d = targetRect.left - rect.right;
182
- } else {
183
- d = rect.left - targetRect.left;
184
- }
185
- return d < 0 ? 0 : d;
186
- },
187
- nearTargetRightIsBetter: function (rect) {
188
- let d;
189
- if (rect.center.x < targetRect.center.x) {
190
- d = targetRect.right - rect.left;
191
- } else {
192
- d = rect.left - targetRect.right;
193
- }
194
- return d < 0 ? 0 : d;
195
- },
196
- nearTargetTopIsBetter: function (rect) {
197
- let d;
198
- if (rect.center.y < targetRect.center.y) {
199
- d = targetRect.top - rect.bottom;
200
- } else {
201
- d = rect.top - targetRect.top;
202
- }
203
- return d < 0 ? 0 : d;
204
- },
205
- topIsBetter: function (rect) {
206
- return rect.top;
207
- },
208
- bottomIsBetter: function (rect) {
209
- return -1 * rect.bottom;
210
- },
211
- leftIsBetter: function (rect) {
212
- return rect.left;
213
- },
214
- rightIsBetter: function (rect) {
215
- return -1 * rect.right;
216
- }
217
- };
181
+ function generateDistancefunction(targetRect) {
182
+ return {
183
+ nearPlumbLineIsBetter: function nearPlumbLineIsBetter(rect) {
184
+ var d;
185
+
186
+ if (rect.center.x < targetRect.center.x) {
187
+ d = targetRect.center.x - rect.right;
188
+ } else {
189
+ d = rect.left - targetRect.center.x;
190
+ }
191
+
192
+ return d < 0 ? 0 : d;
193
+ },
194
+ nearHorizonIsBetter: function nearHorizonIsBetter(rect) {
195
+ var d;
196
+
197
+ if (rect.center.y < targetRect.center.y) {
198
+ d = targetRect.center.y - rect.bottom;
199
+ } else {
200
+ d = rect.top - targetRect.center.y;
201
+ }
202
+
203
+ return d < 0 ? 0 : d;
204
+ },
205
+ nearTargetBottomIsBetter: function nearTargetBottomIsBetter(rect) {
206
+ var d;
207
+
208
+ if (rect.center.y < targetRect.center.y) {
209
+ d = targetRect.bottom - rect.top;
210
+ } else {
211
+ d = rect.top - targetRect.bottom;
212
+ }
213
+
214
+ return d < 0 ? 0 : d;
215
+ },
216
+ nearTargetLeftIsBetter: function nearTargetLeftIsBetter(rect) {
217
+ var d;
218
+
219
+ if (rect.center.x < targetRect.center.x) {
220
+ d = targetRect.left - rect.right;
221
+ } else {
222
+ d = rect.left - targetRect.left;
223
+ }
224
+
225
+ return d < 0 ? 0 : d;
226
+ },
227
+ nearTargetRightIsBetter: function nearTargetRightIsBetter(rect) {
228
+ var d;
229
+
230
+ if (rect.center.x < targetRect.center.x) {
231
+ d = targetRect.right - rect.left;
232
+ } else {
233
+ d = rect.left - targetRect.right;
234
+ }
235
+
236
+ return d < 0 ? 0 : d;
237
+ },
238
+ nearTargetTopIsBetter: function nearTargetTopIsBetter(rect) {
239
+ var d;
240
+
241
+ if (rect.center.y < targetRect.center.y) {
242
+ d = targetRect.top - rect.bottom;
243
+ } else {
244
+ d = rect.top - targetRect.top;
245
+ }
246
+
247
+ return d < 0 ? 0 : d;
248
+ },
249
+ topIsBetter: function topIsBetter(rect) {
250
+ return rect.top;
251
+ },
252
+ bottomIsBetter: function bottomIsBetter(rect) {
253
+ return -1 * rect.bottom;
254
+ },
255
+ leftIsBetter: function leftIsBetter(rect) {
256
+ return rect.left;
257
+ },
258
+ rightIsBetter: function rightIsBetter(rect) {
259
+ return -1 * rect.right;
260
+ }
261
+ };
218
262
  }
219
263
 
220
- function navigate (targetRect, direction, rects, config, partitionRect = targetRect) {
221
- if (!targetRect || !direction || !rects || !rects.length || !config) {
222
- return null;
223
- }
224
-
225
- const distanceFunction = generateDistancefunction(targetRect);
226
- const {obliqueMultiplier, straightMultiplier, straightOnly, straightOverlapThreshold} = config;
227
-
228
- const groups = partition(
229
- rects,
230
- partitionRect,
231
- straightOverlapThreshold,
232
- (rect, destRect) => (
233
- calcGroupId(
234
- direction === 'up' || direction === 'down' ? calcNextExtendedGridPosition(rect, destRect) : calcNextGridPosition(rect, destRect)
235
- )
236
- )
237
- );
238
-
239
- const internalGroups = partition(
240
- groups[4],
241
- targetRect.center,
242
- straightOverlapThreshold,
243
- (rect, destRect) => calcGroupId(calcNextGridPosition(rect, destRect))
244
- );
245
-
246
- let priorities, targetEdge;
247
-
248
- switch (direction) {
249
- case 'left':
250
- targetEdge = direction;
251
- priorities = [
252
- {
253
- group: internalGroups[0].concat(internalGroups[3]).concat(internalGroups[6]),
254
- distance: [
255
- distanceFunction.nearPlumbLineIsBetter,
256
- distanceFunction.nearHorizonIsBetter,
257
- distanceFunction.topIsBetter
258
- ],
259
- difference: [
260
- distanceFunction.nearTargetLeftIsBetter
261
- ],
262
- minDistance: straightMinDistance,
263
- multiplier: straightMultiplier
264
- },
265
- {
266
- group: groups[3],
267
- distance: [
268
- distanceFunction.nearPlumbLineIsBetter,
269
- distanceFunction.nearHorizonIsBetter,
270
- distanceFunction.topIsBetter
271
- ],
272
- difference: [
273
- distanceFunction.nearTargetLeftIsBetter
274
- ],
275
- minDistance: straightMinDistance,
276
- multiplier: straightMultiplier
277
- },
278
- {
279
- group: groups[0],
280
- distance: [
281
- distanceFunction.nearHorizonIsBetter,
282
- distanceFunction.rightIsBetter,
283
- distanceFunction.nearTargetTopIsBetter
284
- ],
285
- difference: [
286
- distanceFunction.nearTargetLeftIsBetter,
287
- distanceFunction.nearTargetTopIsBetter
288
- ],
289
- minDistance: obliqueMinDistance,
290
- multiplier: obliqueMultiplier
291
- },
292
- {
293
- group: groups[6],
294
- distance: [
295
- distanceFunction.nearHorizonIsBetter,
296
- distanceFunction.rightIsBetter,
297
- distanceFunction.nearTargetTopIsBetter
298
- ],
299
- difference: [
300
- distanceFunction.nearTargetLeftIsBetter,
301
- distanceFunction.nearTargetBottomIsBetter
302
- ],
303
- minDistance: obliqueMinDistance,
304
- multiplier: obliqueMultiplier
305
- }
306
- ];
307
- break;
308
- case 'right':
309
- targetEdge = direction;
310
- priorities = [
311
- {
312
- group: internalGroups[2].concat(internalGroups[5]).concat(internalGroups[8]),
313
- distance: [
314
- distanceFunction.nearPlumbLineIsBetter,
315
- distanceFunction.nearHorizonIsBetter,
316
- distanceFunction.topIsBetter
317
- ],
318
- difference: [
319
- distanceFunction.nearTargetRightIsBetter
320
- ],
321
- minDistance: straightMinDistance,
322
- multiplier: straightMultiplier
323
- },
324
- {
325
- group: groups[5],
326
- distance: [
327
- distanceFunction.nearPlumbLineIsBetter,
328
- distanceFunction.nearHorizonIsBetter,
329
- distanceFunction.topIsBetter
330
- ],
331
- difference: [
332
- distanceFunction.nearTargetRightIsBetter
333
- ],
334
- minDistance: straightMinDistance,
335
- multiplier: straightMultiplier
336
- },
337
- {
338
- group: groups[2],
339
- distance: [
340
- distanceFunction.nearHorizonIsBetter,
341
- distanceFunction.leftIsBetter,
342
- distanceFunction.nearTargetTopIsBetter
343
- ],
344
- difference: [
345
- distanceFunction.nearTargetRightIsBetter,
346
- distanceFunction.nearTargetTopIsBetter
347
- ],
348
- minDistance: obliqueMinDistance,
349
- multiplier: obliqueMultiplier
350
- },
351
- {
352
- group: groups[8],
353
- distance: [
354
- distanceFunction.nearHorizonIsBetter,
355
- distanceFunction.leftIsBetter,
356
- distanceFunction.nearTargetTopIsBetter
357
- ],
358
- difference: [
359
- distanceFunction.nearTargetRightIsBetter,
360
- distanceFunction.nearTargetBottomIsBetter
361
- ],
362
- minDistance: obliqueMinDistance,
363
- multiplier: obliqueMultiplier
364
- }
365
- ];
366
- break;
367
- case 'up':
368
- targetEdge = 'top';
369
- priorities = [
370
- {
371
- group: internalGroups[0].concat(internalGroups[1]).concat(internalGroups[2]),
372
- distance: [
373
- distanceFunction.nearHorizonIsBetter,
374
- distanceFunction.nearPlumbLineIsBetter,
375
- distanceFunction.leftIsBetter
376
- ],
377
- difference: [
378
- distanceFunction.nearTargetTopIsBetter
379
- ],
380
- minDistance: straightMinDistance,
381
- multiplier: straightMultiplier
382
- },
383
- {
384
- group: groups[1],
385
- distance: [
386
- distanceFunction.nearHorizonIsBetter,
387
- distanceFunction.nearPlumbLineIsBetter,
388
- distanceFunction.leftIsBetter
389
- ],
390
- difference: [
391
- distanceFunction.nearTargetTopIsBetter
392
- ],
393
- minDistance: straightMinDistance,
394
- multiplier: straightMultiplier
395
- },
396
- {
397
- group: groups[0],
398
- distance: [
399
- distanceFunction.nearPlumbLineIsBetter,
400
- distanceFunction.bottomIsBetter,
401
- distanceFunction.nearTargetLeftIsBetter
402
- ],
403
- difference: [
404
- distanceFunction.nearTargetTopIsBetter,
405
- distanceFunction.nearTargetLeftIsBetter
406
- ],
407
- minDistance: obliqueMinDistance,
408
- multiplier: obliqueMultiplier
409
- },
410
- {
411
- group: groups[2],
412
- distance: [
413
- distanceFunction.nearPlumbLineIsBetter,
414
- distanceFunction.bottomIsBetter,
415
- distanceFunction.nearTargetLeftIsBetter
416
- ],
417
- difference: [
418
- distanceFunction.nearTargetTopIsBetter,
419
- distanceFunction.nearTargetRightIsBetter
420
- ],
421
- minDistance: obliqueMinDistance,
422
- multiplier: obliqueMultiplier
423
- }
424
- ];
425
- break;
426
- case 'down':
427
- targetEdge = 'bottom';
428
- priorities = [
429
- {
430
- group: internalGroups[6].concat(internalGroups[7]).concat(internalGroups[8]),
431
- distance: [
432
- distanceFunction.nearHorizonIsBetter,
433
- distanceFunction.nearPlumbLineIsBetter,
434
- distanceFunction.leftIsBetter
435
- ],
436
- difference: [
437
- distanceFunction.nearTargetBottomIsBetter
438
- ],
439
- minDistance: straightMinDistance,
440
- multiplier: straightMultiplier
441
- },
442
- {
443
- group: groups[7],
444
- distance: [
445
- distanceFunction.nearHorizonIsBetter,
446
- distanceFunction.nearPlumbLineIsBetter,
447
- distanceFunction.leftIsBetter
448
- ],
449
- difference: [
450
- distanceFunction.nearTargetBottomIsBetter
451
- ],
452
- minDistance: straightMinDistance,
453
- multiplier: straightMultiplier
454
- },
455
- {
456
- group: groups[6],
457
- distance: [
458
- distanceFunction.nearPlumbLineIsBetter,
459
- distanceFunction.topIsBetter,
460
- distanceFunction.nearTargetLeftIsBetter
461
- ],
462
- difference: [
463
- distanceFunction.nearTargetBottomIsBetter,
464
- distanceFunction.nearTargetLeftIsBetter
465
- ],
466
- minDistance: obliqueMinDistance,
467
- multiplier: obliqueMultiplier
468
- },
469
- {
470
- group: groups[8],
471
- distance: [
472
- distanceFunction.nearPlumbLineIsBetter,
473
- distanceFunction.topIsBetter,
474
- distanceFunction.nearTargetLeftIsBetter
475
- ],
476
- difference: [
477
- distanceFunction.nearTargetBottomIsBetter,
478
- distanceFunction.nearTargetRightIsBetter
479
- ],
480
- minDistance: obliqueMinDistance,
481
- multiplier: obliqueMultiplier
482
- }
483
- ];
484
- break;
485
- default:
486
- return null;
487
- }
488
-
489
- if (straightOnly) {
490
- priorities.splice(2, 2);
491
- }
492
-
493
- const destGroup = prioritize(priorities, targetRect[targetEdge]);
494
- if (!destGroup) {
495
- return null;
496
- }
497
-
498
- return destGroup[0].target.element;
264
+ function navigate(targetRect, direction, rects, config) {
265
+ var partitionRect = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : targetRect;
266
+
267
+ if (!targetRect || !direction || !rects || !rects.length || !config) {
268
+ return null;
269
+ }
270
+
271
+ var distanceFunction = generateDistancefunction(targetRect);
272
+ var obliqueMultiplier = config.obliqueMultiplier,
273
+ straightMultiplier = config.straightMultiplier,
274
+ straightOnly = config.straightOnly,
275
+ straightOverlapThreshold = config.straightOverlapThreshold;
276
+ var groups = partition(rects, partitionRect, straightOverlapThreshold, function (rect, destRect) {
277
+ return calcGroupId(direction === 'up' || direction === 'down' ? calcNextExtendedGridPosition(rect, destRect) : calcNextGridPosition(rect, destRect));
278
+ });
279
+ var internalGroups = partition(groups[4], targetRect.center, straightOverlapThreshold, function (rect, destRect) {
280
+ return calcGroupId(calcNextGridPosition(rect, destRect));
281
+ });
282
+ var priorities, targetEdge;
283
+
284
+ switch (direction) {
285
+ case 'left':
286
+ targetEdge = direction;
287
+ priorities = [{
288
+ group: internalGroups[0].concat(internalGroups[3]).concat(internalGroups[6]),
289
+ distance: [distanceFunction.nearPlumbLineIsBetter, distanceFunction.nearHorizonIsBetter, distanceFunction.topIsBetter],
290
+ difference: [distanceFunction.nearTargetLeftIsBetter],
291
+ minDistance: straightMinDistance,
292
+ multiplier: straightMultiplier
293
+ }, {
294
+ group: groups[3],
295
+ distance: [distanceFunction.nearPlumbLineIsBetter, distanceFunction.nearHorizonIsBetter, distanceFunction.topIsBetter],
296
+ difference: [distanceFunction.nearTargetLeftIsBetter],
297
+ minDistance: straightMinDistance,
298
+ multiplier: straightMultiplier
299
+ }, {
300
+ group: groups[0],
301
+ distance: [distanceFunction.nearHorizonIsBetter, distanceFunction.rightIsBetter, distanceFunction.nearTargetTopIsBetter],
302
+ difference: [distanceFunction.nearTargetLeftIsBetter, distanceFunction.nearTargetTopIsBetter],
303
+ minDistance: obliqueMinDistance,
304
+ multiplier: obliqueMultiplier
305
+ }, {
306
+ group: groups[6],
307
+ distance: [distanceFunction.nearHorizonIsBetter, distanceFunction.rightIsBetter, distanceFunction.nearTargetTopIsBetter],
308
+ difference: [distanceFunction.nearTargetLeftIsBetter, distanceFunction.nearTargetBottomIsBetter],
309
+ minDistance: obliqueMinDistance,
310
+ multiplier: obliqueMultiplier
311
+ }];
312
+ break;
313
+
314
+ case 'right':
315
+ targetEdge = direction;
316
+ priorities = [{
317
+ group: internalGroups[2].concat(internalGroups[5]).concat(internalGroups[8]),
318
+ distance: [distanceFunction.nearPlumbLineIsBetter, distanceFunction.nearHorizonIsBetter, distanceFunction.topIsBetter],
319
+ difference: [distanceFunction.nearTargetRightIsBetter],
320
+ minDistance: straightMinDistance,
321
+ multiplier: straightMultiplier
322
+ }, {
323
+ group: groups[5],
324
+ distance: [distanceFunction.nearPlumbLineIsBetter, distanceFunction.nearHorizonIsBetter, distanceFunction.topIsBetter],
325
+ difference: [distanceFunction.nearTargetRightIsBetter],
326
+ minDistance: straightMinDistance,
327
+ multiplier: straightMultiplier
328
+ }, {
329
+ group: groups[2],
330
+ distance: [distanceFunction.nearHorizonIsBetter, distanceFunction.leftIsBetter, distanceFunction.nearTargetTopIsBetter],
331
+ difference: [distanceFunction.nearTargetRightIsBetter, distanceFunction.nearTargetTopIsBetter],
332
+ minDistance: obliqueMinDistance,
333
+ multiplier: obliqueMultiplier
334
+ }, {
335
+ group: groups[8],
336
+ distance: [distanceFunction.nearHorizonIsBetter, distanceFunction.leftIsBetter, distanceFunction.nearTargetTopIsBetter],
337
+ difference: [distanceFunction.nearTargetRightIsBetter, distanceFunction.nearTargetBottomIsBetter],
338
+ minDistance: obliqueMinDistance,
339
+ multiplier: obliqueMultiplier
340
+ }];
341
+ break;
342
+
343
+ case 'up':
344
+ targetEdge = 'top';
345
+ priorities = [{
346
+ group: internalGroups[0].concat(internalGroups[1]).concat(internalGroups[2]),
347
+ distance: [distanceFunction.nearHorizonIsBetter, distanceFunction.nearPlumbLineIsBetter, distanceFunction.leftIsBetter],
348
+ difference: [distanceFunction.nearTargetTopIsBetter],
349
+ minDistance: straightMinDistance,
350
+ multiplier: straightMultiplier
351
+ }, {
352
+ group: groups[1],
353
+ distance: [distanceFunction.nearHorizonIsBetter, distanceFunction.nearPlumbLineIsBetter, distanceFunction.leftIsBetter],
354
+ difference: [distanceFunction.nearTargetTopIsBetter],
355
+ minDistance: straightMinDistance,
356
+ multiplier: straightMultiplier
357
+ }, {
358
+ group: groups[0],
359
+ distance: [distanceFunction.nearPlumbLineIsBetter, distanceFunction.bottomIsBetter, distanceFunction.nearTargetLeftIsBetter],
360
+ difference: [distanceFunction.nearTargetTopIsBetter, distanceFunction.nearTargetLeftIsBetter],
361
+ minDistance: obliqueMinDistance,
362
+ multiplier: obliqueMultiplier
363
+ }, {
364
+ group: groups[2],
365
+ distance: [distanceFunction.nearPlumbLineIsBetter, distanceFunction.bottomIsBetter, distanceFunction.nearTargetLeftIsBetter],
366
+ difference: [distanceFunction.nearTargetTopIsBetter, distanceFunction.nearTargetRightIsBetter],
367
+ minDistance: obliqueMinDistance,
368
+ multiplier: obliqueMultiplier
369
+ }];
370
+ break;
371
+
372
+ case 'down':
373
+ targetEdge = 'bottom';
374
+ priorities = [{
375
+ group: internalGroups[6].concat(internalGroups[7]).concat(internalGroups[8]),
376
+ distance: [distanceFunction.nearHorizonIsBetter, distanceFunction.nearPlumbLineIsBetter, distanceFunction.leftIsBetter],
377
+ difference: [distanceFunction.nearTargetBottomIsBetter],
378
+ minDistance: straightMinDistance,
379
+ multiplier: straightMultiplier
380
+ }, {
381
+ group: groups[7],
382
+ distance: [distanceFunction.nearHorizonIsBetter, distanceFunction.nearPlumbLineIsBetter, distanceFunction.leftIsBetter],
383
+ difference: [distanceFunction.nearTargetBottomIsBetter],
384
+ minDistance: straightMinDistance,
385
+ multiplier: straightMultiplier
386
+ }, {
387
+ group: groups[6],
388
+ distance: [distanceFunction.nearPlumbLineIsBetter, distanceFunction.topIsBetter, distanceFunction.nearTargetLeftIsBetter],
389
+ difference: [distanceFunction.nearTargetBottomIsBetter, distanceFunction.nearTargetLeftIsBetter],
390
+ minDistance: obliqueMinDistance,
391
+ multiplier: obliqueMultiplier
392
+ }, {
393
+ group: groups[8],
394
+ distance: [distanceFunction.nearPlumbLineIsBetter, distanceFunction.topIsBetter, distanceFunction.nearTargetLeftIsBetter],
395
+ difference: [distanceFunction.nearTargetBottomIsBetter, distanceFunction.nearTargetRightIsBetter],
396
+ minDistance: obliqueMinDistance,
397
+ multiplier: obliqueMultiplier
398
+ }];
399
+ break;
400
+
401
+ default:
402
+ return null;
403
+ }
404
+
405
+ if (straightOnly) {
406
+ priorities.splice(2, 2);
407
+ }
408
+
409
+ var destGroup = prioritize(priorities, targetRect[targetEdge]);
410
+
411
+ if (!destGroup) {
412
+ return null;
413
+ }
414
+
415
+ return destGroup[0].target.element;
499
416
  }
500
417
 
501
- export default navigate;
502
- export {
503
- navigate
504
- };
418
+ var _default = navigate;
419
+ exports["default"] = _default;