@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/build/src/navigate.js
DELETED
|
@@ -1,419 +0,0 @@
|
|
|
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
|
-
};
|
|
16
|
-
|
|
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
|
-
};
|
|
41
|
-
};
|
|
42
|
-
|
|
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
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
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;
|
|
114
|
-
}
|
|
115
|
-
|
|
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;
|
|
179
|
-
}
|
|
180
|
-
|
|
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
|
-
};
|
|
262
|
-
}
|
|
263
|
-
|
|
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;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
var _default = navigate;
|
|
419
|
-
exports["default"] = _default;
|
package/build/src/pointer.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.updatePointerPosition = exports.setPointerMode = exports.notifyPointerMove = exports.notifyKeyDown = exports.hasPointerMoved = exports.getPointerMode = exports.getLastPointerPosition = void 0;
|
|
7
|
-
|
|
8
|
-
var _keymap = require("@enact/core/keymap");
|
|
9
|
-
|
|
10
|
-
var _util = require("@enact/core/util");
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Exports methods and members for working with pointer events in spotlight
|
|
14
|
-
*
|
|
15
|
-
* @module spotlight/pointer
|
|
16
|
-
* @private
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/*
|
|
20
|
-
* Whether Spotlight is in pointer mode (as opposed to 5-way mode).
|
|
21
|
-
*
|
|
22
|
-
* @type {Boolean}
|
|
23
|
-
* @default true
|
|
24
|
-
* @private
|
|
25
|
-
*/
|
|
26
|
-
var _pointerMode = true;
|
|
27
|
-
/**
|
|
28
|
-
* Sets the current pointer mode
|
|
29
|
-
*
|
|
30
|
-
* @param {Boolean} pointerMode `true` to enable pointer mode; `false` to disable pointer mode
|
|
31
|
-
* @memberof spotlight/pointer
|
|
32
|
-
* @private
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
var setPointerMode = function setPointerMode(pointerMode) {
|
|
36
|
-
_pointerMode = pointerMode;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Gets the current pointer mode
|
|
40
|
-
*
|
|
41
|
-
* @returns {Boolean} The current state of pointer mode
|
|
42
|
-
* @memberof spotlight/pointer
|
|
43
|
-
* @private
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
exports.setPointerMode = setPointerMode;
|
|
48
|
-
|
|
49
|
-
var getPointerMode = function getPointerMode() {
|
|
50
|
-
return _pointerMode;
|
|
51
|
-
}; // Cached pointer position
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
exports.getPointerMode = getPointerMode;
|
|
55
|
-
var _pointerX = null;
|
|
56
|
-
var _pointerY = null;
|
|
57
|
-
/**
|
|
58
|
-
* Returns whether or not the current pointer position matches the provided coordinates
|
|
59
|
-
*
|
|
60
|
-
* @param {Number} x Pointer position relative to the left side of the viewport
|
|
61
|
-
* @param {Number} y Pointer position relative to the top side of the viewport
|
|
62
|
-
*
|
|
63
|
-
* @returns {Boolean} `true` if the position was changed
|
|
64
|
-
* @memberof spotlight/pointer
|
|
65
|
-
* @private
|
|
66
|
-
*/
|
|
67
|
-
|
|
68
|
-
var hasPointerMoved = function hasPointerMoved(x, y) {
|
|
69
|
-
return x !== _pointerX || y !== _pointerY;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* Updates the cached pointer position, updating the current pointer mode when the position has
|
|
73
|
-
* changed.
|
|
74
|
-
*
|
|
75
|
-
* @param {Number} x Pointer position relative to the left side of the viewport
|
|
76
|
-
* @param {Number} y Pointer position relative to the top side of the viewport
|
|
77
|
-
*
|
|
78
|
-
* @returns {Boolean} `true` if the position was updated
|
|
79
|
-
* @memberof spotlight/pointer
|
|
80
|
-
* @private
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
exports.hasPointerMoved = hasPointerMoved;
|
|
85
|
-
|
|
86
|
-
var updatePointerPosition = function updatePointerPosition(x, y) {
|
|
87
|
-
// Chrome emits mousemove on scroll, but client coordinates do not change.
|
|
88
|
-
if (hasPointerMoved(x, y)) {
|
|
89
|
-
setPointerMode(true);
|
|
90
|
-
_pointerX = x;
|
|
91
|
-
_pointerY = y;
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return false;
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Returns the last known position of the pointer
|
|
99
|
-
*
|
|
100
|
-
* @returns {Object} Contains `x` and `y` coordinates for the pointer
|
|
101
|
-
* @memberof spotlight/pointer
|
|
102
|
-
* @private
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
exports.updatePointerPosition = updatePointerPosition;
|
|
107
|
-
|
|
108
|
-
var getLastPointerPosition = function getLastPointerPosition() {
|
|
109
|
-
return {
|
|
110
|
-
x: _pointerX,
|
|
111
|
-
y: _pointerY
|
|
112
|
-
};
|
|
113
|
-
}; // 30ms (_pointerHiddenToKeyTimeout) is semi-arbitrary, to account for the time it takes for the
|
|
114
|
-
// following directional key event to fire, and to prevent momentary spotting of the last
|
|
115
|
-
// focused item - needs to be a value large enough to account for the potentially-trailing
|
|
116
|
-
// event, but not too large that another unrelated event can be fired inside the window
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
exports.getLastPointerPosition = getLastPointerPosition;
|
|
120
|
-
var hidePointerJob = new _util.Job(function (callback) {
|
|
121
|
-
setPointerMode(false);
|
|
122
|
-
|
|
123
|
-
if (callback) {
|
|
124
|
-
callback();
|
|
125
|
-
}
|
|
126
|
-
}, 30);
|
|
127
|
-
/**
|
|
128
|
-
* Notifies spotlight of a change in the pointer position
|
|
129
|
-
*
|
|
130
|
-
* @param {Node} target Node under the pointer
|
|
131
|
-
* @param {Number} x Horizontal position relative to the left side of the viewport
|
|
132
|
-
* @param {Number} y Vertical position relative to the top side of the viewport
|
|
133
|
-
*
|
|
134
|
-
* @returns {Boolean} `true` if the change in position results in a change in focus
|
|
135
|
-
* @memberof spotlight/pointer
|
|
136
|
-
* @private
|
|
137
|
-
*/
|
|
138
|
-
|
|
139
|
-
var notifyPointerMove = function notifyPointerMove(current, target, x, y) {
|
|
140
|
-
var priorPointerMode = getPointerMode();
|
|
141
|
-
|
|
142
|
-
if (updatePointerPosition(x, y)) {
|
|
143
|
-
// if we're entering pointer mode and the target element isn't within the currently
|
|
144
|
-
// focused element, there may be a new navigable target
|
|
145
|
-
return !priorPointerMode || !current || !current.contains(target);
|
|
146
|
-
} // the pointer hasn't actually moved (surprise!)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return false;
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* Notifies the pointer module of key events. If the pointer should be hidden, a timer is set and
|
|
153
|
-
* `callback` is invoked after the timer has expired and pointer mode has been disabled. For any
|
|
154
|
-
* other type of key event, pointer mode is disabled and `false` is returned.
|
|
155
|
-
*
|
|
156
|
-
* @param {Number} keyCode Key event key code
|
|
157
|
-
* @param {Function} [callback] Optional callback to invoke upon hiding the pointer.
|
|
158
|
-
*
|
|
159
|
-
* @returns {Boolean} `true` for pointer hide or show key events
|
|
160
|
-
* @memberof spotlight/pointer
|
|
161
|
-
* @private
|
|
162
|
-
*/
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
exports.notifyPointerMove = notifyPointerMove;
|
|
166
|
-
|
|
167
|
-
var notifyKeyDown = function notifyKeyDown(keyCode, callback) {
|
|
168
|
-
var palmSystem = window.PalmSystem; // for hide/show pointer events, handle them and return true
|
|
169
|
-
|
|
170
|
-
if ((0, _keymap.is)('pointerHide', keyCode)) {
|
|
171
|
-
hidePointerJob.start(callback);
|
|
172
|
-
return true;
|
|
173
|
-
} else if ((0, _keymap.is)('pointerShow', keyCode)) {
|
|
174
|
-
setPointerMode(true);
|
|
175
|
-
return true;
|
|
176
|
-
} else if (!(0, _keymap.is)('nonModal', keyCode) && !(0, _keymap.is)('cancel', keyCode) && !((0, _keymap.is)('enter', keyCode) && palmSystem && palmSystem.cursor && palmSystem.cursor.visibility)) {
|
|
177
|
-
setPointerMode(false);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return false;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
exports.notifyKeyDown = notifyKeyDown;
|