@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.
- package/{build/Accelerator → Accelerator}/Accelerator.d.ts +0 -0
- package/Accelerator/Accelerator.js +149 -156
- package/CHANGELOG.md +22 -0
- package/{build/Pause → Pause}/Pause.d.ts +0 -0
- package/Pause/Pause.js +102 -80
- package/Pause/tests/Pause-specs.js +65 -97
- package/SpotlightContainerDecorator/SpotlightContainer.js +175 -140
- package/{build/SpotlightContainerDecorator → SpotlightContainerDecorator}/SpotlightContainerDecorator.d.ts +0 -0
- package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +222 -176
- package/SpotlightContainerDecorator/tests/Element.prototype.closest.js +44 -40
- package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +221 -210
- package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +150 -243
- package/SpotlightContainerDecorator/useSpotlightContainer.js +47 -28
- package/{build/SpotlightRootDecorator → SpotlightRootDecorator}/SpotlightRootDecorator.d.ts +0 -0
- package/SpotlightRootDecorator/SpotlightRootDecorator.js +206 -111
- package/{build/Spottable → Spottable}/Spottable.d.ts +0 -0
- package/Spottable/Spottable.js +448 -410
- package/Spottable/tests/Spottable-specs.js +90 -117
- package/package.json +3 -2
- package/src/container.js +718 -653
- package/src/navigate.js +406 -491
- package/src/pointer.js +86 -78
- package/{build/src → src}/spotlight.d.ts +0 -0
- package/src/spotlight.js +846 -885
- package/src/target.js +448 -474
- package/src/tests/container-specs.js +643 -1251
- package/src/tests/navigate-specs.js +77 -134
- package/src/tests/pointer-specs.js +126 -182
- package/src/tests/spotlight-specs.js +103 -133
- package/src/tests/target-specs.js +597 -960
- package/src/tests/utils.js +89 -67
- package/src/utils.js +155 -158
- package/build/Accelerator/Accelerator.js +0 -162
- package/build/Accelerator/package.json +0 -3
- package/build/CHANGELOG.md +0 -838
- package/build/Pause/Pause.js +0 -164
- package/build/Pause/package.json +0 -3
- package/build/Pause/tests/Pause-specs.js +0 -65
- package/build/README.md +0 -61
- package/build/SpotlightContainerDecorator/SpotlightContainer.js +0 -176
- package/build/SpotlightContainerDecorator/SpotlightContainerDecorator.js +0 -282
- package/build/SpotlightContainerDecorator/package.json +0 -3
- package/build/SpotlightContainerDecorator/tests/Element.prototype.closest.js +0 -45
- package/build/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +0 -221
- package/build/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +0 -160
- package/build/SpotlightContainerDecorator/useSpotlightContainer.js +0 -133
- package/build/SpotlightRootDecorator/SpotlightRootDecorator.js +0 -189
- package/build/SpotlightRootDecorator/package.json +0 -3
- package/build/Spottable/Spottable.js +0 -491
- package/build/Spottable/package.json +0 -3
- package/build/Spottable/tests/Spottable-specs.js +0 -90
- package/build/package-lock.json +0 -229
- package/build/package.json +0 -28
- package/build/src/container.js +0 -1201
- package/build/src/navigate.js +0 -419
- package/build/src/pointer.js +0 -183
- package/build/src/spotlight.js +0 -896
- package/build/src/target.js +0 -507
- package/build/src/tests/container-specs.js +0 -653
- package/build/src/tests/navigate-specs.js +0 -87
- package/build/src/tests/pointer-specs.js +0 -130
- package/build/src/tests/spotlight-specs.js +0 -112
- package/build/src/tests/target-specs.js +0 -614
- package/build/src/tests/utils.js +0 -104
- package/build/src/utils.js +0 -180
- package/build/styles/debug.less +0 -97
- package/build/styles/mixins.less +0 -63
- 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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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
|
-
|
|
502
|
-
|
|
503
|
-
navigate
|
|
504
|
-
};
|
|
418
|
+
var _default = navigate;
|
|
419
|
+
exports["default"] = _default;
|