@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/tests/utils.js
CHANGED
|
@@ -1,82 +1,104 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.testScenario = exports.spottable = exports.someSpottablesAndContainers = exports.someSpottables = exports.someNodes = exports.someContainers = exports.node = exports.join = exports.generateContainerId = exports.container = void 0;
|
|
7
|
+
|
|
8
|
+
var _ramda = _interopRequireDefault(require("ramda"));
|
|
9
|
+
|
|
10
|
+
var _container = require("../container");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
|
|
14
|
+
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; }
|
|
15
|
+
|
|
16
|
+
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; }
|
|
4
17
|
|
|
5
|
-
|
|
18
|
+
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; }
|
|
6
19
|
|
|
7
|
-
|
|
8
|
-
const rootId = 'test-root';
|
|
9
|
-
const html = join(
|
|
10
|
-
`<div id="${rootId}">`,
|
|
11
|
-
scenario,
|
|
12
|
-
'</div>'
|
|
13
|
-
);
|
|
20
|
+
var join = _ramda["default"].unapply(_ramda["default"].join('\n'));
|
|
14
21
|
|
|
15
|
-
|
|
22
|
+
exports.join = join;
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
var testScenario = function testScenario(scenario, callback) {
|
|
25
|
+
return function () {
|
|
26
|
+
var rootId = 'test-root';
|
|
27
|
+
var html = join("<div id=\"".concat(rootId, "\">"), scenario, '</div>');
|
|
28
|
+
document.body.innerHTML = html;
|
|
29
|
+
var root = document.getElementById(rootId);
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
callback(root);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
console.log(html); // eslint-disable-line no-console
|
|
35
|
+
|
|
36
|
+
throw e;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
24
39
|
};
|
|
25
40
|
|
|
26
|
-
|
|
27
|
-
|
|
41
|
+
exports.testScenario = testScenario;
|
|
42
|
+
var _id = 1;
|
|
28
43
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return v;
|
|
32
|
-
} else if (typeof v !== 'undefined') {
|
|
33
|
-
return {children: v};
|
|
34
|
-
}
|
|
44
|
+
var generateContainerId = function generateContainerId() {
|
|
45
|
+
return "".concat(_container.containerAttribute, "=").concat(_id++);
|
|
35
46
|
};
|
|
36
47
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
attributes += `${key}="${value}" `;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
return `<div ${attributes}>${children}</div>`;
|
|
48
|
+
exports.generateContainerId = generateContainerId;
|
|
49
|
+
|
|
50
|
+
var coerceProps = function coerceProps(v) {
|
|
51
|
+
if (typeof v === 'object') {
|
|
52
|
+
return v;
|
|
53
|
+
} else if (typeof v !== 'undefined') {
|
|
54
|
+
return {
|
|
55
|
+
children: v
|
|
56
|
+
};
|
|
57
|
+
}
|
|
52
58
|
};
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
var node = function node(props) {
|
|
61
|
+
var children = '';
|
|
62
|
+
var attributes = '';
|
|
63
|
+
Object.keys(props).forEach(function (key) {
|
|
64
|
+
if (key === 'children') {
|
|
65
|
+
children = props.children;
|
|
66
|
+
} else {
|
|
67
|
+
var value = props[key];
|
|
68
|
+
if (key === 'className') key = 'class';
|
|
69
|
+
attributes += "".concat(key, "=\"").concat(value, "\" ");
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return "<div ".concat(attributes, ">").concat(children, "</div>");
|
|
73
|
+
};
|
|
58
74
|
|
|
59
|
-
|
|
60
|
-
[containerAttribute]: _id++,
|
|
61
|
-
'data-spotlight-container': true,
|
|
62
|
-
...coerceProps(props)
|
|
63
|
-
});
|
|
75
|
+
exports.node = node;
|
|
64
76
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const someSpottablesAndContainers = R.converge(R.concat, [someSpottables, someContainers]);
|
|
70
|
-
|
|
71
|
-
export {
|
|
72
|
-
container,
|
|
73
|
-
generateContainerId,
|
|
74
|
-
join,
|
|
75
|
-
node,
|
|
76
|
-
someContainers,
|
|
77
|
-
someNodes,
|
|
78
|
-
someSpottables,
|
|
79
|
-
someSpottablesAndContainers,
|
|
80
|
-
spottable,
|
|
81
|
-
testScenario
|
|
77
|
+
var spottable = function spottable(props) {
|
|
78
|
+
return node(_objectSpread({
|
|
79
|
+
className: 'spottable'
|
|
80
|
+
}, coerceProps(props)));
|
|
82
81
|
};
|
|
82
|
+
|
|
83
|
+
exports.spottable = spottable;
|
|
84
|
+
|
|
85
|
+
var container = function container(props) {
|
|
86
|
+
var _objectSpread2;
|
|
87
|
+
|
|
88
|
+
return node(_objectSpread((_objectSpread2 = {}, _defineProperty(_objectSpread2, _container.containerAttribute, _id++), _defineProperty(_objectSpread2, 'data-spotlight-container', true), _objectSpread2), coerceProps(props)));
|
|
89
|
+
}; // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
exports.container = container;
|
|
93
|
+
|
|
94
|
+
var someNodes = _ramda["default"].useWith(_ramda["default"].compose(_ramda["default"].join('\n'), _ramda["default"].map), [_ramda["default"].identity, _ramda["default"].range(0)]);
|
|
95
|
+
|
|
96
|
+
exports.someNodes = someNodes;
|
|
97
|
+
var someSpottables = someNodes(spottable);
|
|
98
|
+
exports.someSpottables = someSpottables;
|
|
99
|
+
var someContainers = someNodes(container);
|
|
100
|
+
exports.someContainers = someContainers;
|
|
101
|
+
|
|
102
|
+
var someSpottablesAndContainers = _ramda["default"].converge(_ramda["default"].concat, [someSpottables, someContainers]);
|
|
103
|
+
|
|
104
|
+
exports.someSpottablesAndContainers = someSpottablesAndContainers;
|
package/src/utils.js
CHANGED
|
@@ -1,183 +1,180 @@
|
|
|
1
|
-
|
|
2
|
-
import warning from 'warning';
|
|
1
|
+
"use strict";
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getContainerRect = getContainerRect;
|
|
7
|
+
exports.getPointRect = getPointRect;
|
|
8
|
+
exports.getRect = getRect;
|
|
9
|
+
exports.getRects = getRects;
|
|
10
|
+
exports.parseSelector = parseSelector;
|
|
11
|
+
exports.matchSelector = exports.intersects = exports.contains = void 0;
|
|
12
|
+
|
|
13
|
+
var _curry = _interopRequireDefault(require("ramda/src/curry"));
|
|
14
|
+
|
|
15
|
+
var _warning = _interopRequireDefault(require("warning"));
|
|
16
|
+
|
|
17
|
+
var _container = require("./container");
|
|
5
18
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
19
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
20
|
+
|
|
21
|
+
var elementMatchesSelector = function elementMatchesSelector(selector) {
|
|
22
|
+
var matchedNodes = (this.parentNode || this.document).querySelectorAll(selector);
|
|
23
|
+
return [].slice.call(matchedNodes).indexOf(this) >= 0;
|
|
9
24
|
};
|
|
25
|
+
|
|
10
26
|
if (typeof window === 'object') {
|
|
11
|
-
|
|
12
|
-
window.Element.prototype.matchesSelector ||
|
|
13
|
-
window.Element.prototype.mozMatchesSelector ||
|
|
14
|
-
window.Element.prototype.webkitMatchesSelector ||
|
|
15
|
-
window.Element.prototype.msMatchesSelector ||
|
|
16
|
-
window.Element.prototype.oMatchesSelector ||
|
|
17
|
-
elementMatchesSelector;
|
|
27
|
+
elementMatchesSelector = window.Element.prototype.matches || window.Element.prototype.matchesSelector || window.Element.prototype.mozMatchesSelector || window.Element.prototype.webkitMatchesSelector || window.Element.prototype.msMatchesSelector || window.Element.prototype.oMatchesSelector || elementMatchesSelector;
|
|
18
28
|
}
|
|
19
29
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return false;
|
|
29
|
-
});
|
|
30
|
+
var matchSelector = (0, _curry["default"])(function (selector, elem) {
|
|
31
|
+
if (typeof selector === 'string') {
|
|
32
|
+
return elementMatchesSelector.call(elem, selector);
|
|
33
|
+
} else if (typeof selector === 'object' && selector.length) {
|
|
34
|
+
return selector.indexOf(elem) >= 0;
|
|
35
|
+
} else if (typeof selector === 'object' && selector.nodeType === 1) {
|
|
36
|
+
return elem === selector;
|
|
37
|
+
}
|
|
30
38
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
return false;
|
|
40
|
+
});
|
|
41
|
+
exports.matchSelector = matchSelector;
|
|
42
|
+
|
|
43
|
+
function parseSelector(selector) {
|
|
44
|
+
var result = [];
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
if (typeof selector === 'string') {
|
|
48
|
+
result = [].slice.call(document.querySelectorAll(selector));
|
|
49
|
+
} else if (typeof selector === 'object' && selector.length) {
|
|
50
|
+
result = [].slice.call(selector);
|
|
51
|
+
} else if (typeof selector === 'object' && selector.nodeType === 1) {
|
|
52
|
+
result = [selector];
|
|
53
|
+
}
|
|
54
|
+
} catch (ex) {
|
|
55
|
+
process.env.NODE_ENV !== "production" ? (0, _warning["default"])(true, "parseSelector failed for selector: ".concat(selector)) : void 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return result;
|
|
46
59
|
}
|
|
47
60
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return (top || bottom || aroundV) && (left || right || aroundH);
|
|
73
|
-
} else if (type === 'contains') {
|
|
74
|
-
return top && bottom && left && right;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return true;
|
|
61
|
+
var testIntersection = function testIntersection(type, containerRect, elementRect) {
|
|
62
|
+
var L = containerRect.left,
|
|
63
|
+
R = containerRect.right,
|
|
64
|
+
T = containerRect.top,
|
|
65
|
+
B = containerRect.bottom;
|
|
66
|
+
var l = elementRect.left,
|
|
67
|
+
r = elementRect.right,
|
|
68
|
+
t = elementRect.top,
|
|
69
|
+
b = elementRect.bottom;
|
|
70
|
+
var right = r >= L && r <= R;
|
|
71
|
+
var left = l >= L && l <= R;
|
|
72
|
+
var top = t >= T && t <= B;
|
|
73
|
+
var bottom = b >= T && b <= B;
|
|
74
|
+
|
|
75
|
+
if (type === 'intersects') {
|
|
76
|
+
var aroundV = t < T && b > B;
|
|
77
|
+
var aroundH = l < L && r > R;
|
|
78
|
+
return (top || bottom || aroundV) && (left || right || aroundH);
|
|
79
|
+
} else if (type === 'contains') {
|
|
80
|
+
return top && bottom && left && right;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return true;
|
|
78
84
|
};
|
|
79
85
|
|
|
80
|
-
|
|
81
|
-
|
|
86
|
+
var intersects = (0, _curry["default"])(function (containerRect, elementRect) {
|
|
87
|
+
return testIntersection('intersects', containerRect, elementRect);
|
|
82
88
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
exports.intersects = intersects;
|
|
90
|
+
var contains = (0, _curry["default"])(function (containerRect, elementRect) {
|
|
91
|
+
return testIntersection('contains', containerRect, elementRect);
|
|
86
92
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
93
|
+
exports.contains = contains;
|
|
94
|
+
|
|
95
|
+
function getRect(elem) {
|
|
96
|
+
var cr = elem.getBoundingClientRect();
|
|
97
|
+
var rect = {
|
|
98
|
+
left: cr.left,
|
|
99
|
+
top: cr.top,
|
|
100
|
+
width: cr.width,
|
|
101
|
+
height: cr.height
|
|
102
|
+
};
|
|
103
|
+
rect.element = elem;
|
|
104
|
+
rect.right = rect.left + rect.width;
|
|
105
|
+
rect.bottom = rect.top + rect.height;
|
|
106
|
+
rect.center = {
|
|
107
|
+
x: rect.left + Math.floor(rect.width / 2),
|
|
108
|
+
y: rect.top + Math.floor(rect.height / 2)
|
|
109
|
+
};
|
|
110
|
+
rect.center.left = rect.center.right = rect.center.x;
|
|
111
|
+
rect.center.top = rect.center.bottom = rect.center.y;
|
|
112
|
+
return rect;
|
|
106
113
|
}
|
|
107
114
|
|
|
108
|
-
function getPointRect
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
115
|
+
function getPointRect(position) {
|
|
116
|
+
var x = position.x,
|
|
117
|
+
y = position.y;
|
|
118
|
+
return {
|
|
119
|
+
left: x,
|
|
120
|
+
top: y,
|
|
121
|
+
width: 0,
|
|
122
|
+
height: 0,
|
|
123
|
+
right: x,
|
|
124
|
+
bottom: y,
|
|
125
|
+
center: {
|
|
126
|
+
x: x,
|
|
127
|
+
y: y,
|
|
128
|
+
left: x,
|
|
129
|
+
right: x,
|
|
130
|
+
top: y,
|
|
131
|
+
bottom: y
|
|
132
|
+
}
|
|
133
|
+
};
|
|
126
134
|
}
|
|
127
135
|
|
|
128
|
-
function getRects
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
136
|
+
function getRects(candidates) {
|
|
137
|
+
if (candidates && candidates.length > 0) {
|
|
138
|
+
return candidates.map(getRect);
|
|
139
|
+
}
|
|
132
140
|
|
|
133
|
-
|
|
141
|
+
return [];
|
|
134
142
|
}
|
|
135
143
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
144
|
+
function getViewportRect() {
|
|
145
|
+
var _window = window,
|
|
146
|
+
width = _window.innerWidth,
|
|
147
|
+
height = _window.innerHeight;
|
|
148
|
+
var x = width / 2;
|
|
149
|
+
var y = height / 2;
|
|
150
|
+
return {
|
|
151
|
+
left: 0,
|
|
152
|
+
top: 0,
|
|
153
|
+
width: width,
|
|
154
|
+
height: height,
|
|
155
|
+
right: width,
|
|
156
|
+
bottom: height,
|
|
157
|
+
center: {
|
|
158
|
+
x: x,
|
|
159
|
+
y: y,
|
|
160
|
+
left: x,
|
|
161
|
+
right: x,
|
|
162
|
+
top: y,
|
|
163
|
+
bottom: y
|
|
164
|
+
}
|
|
165
|
+
};
|
|
158
166
|
}
|
|
159
167
|
|
|
160
|
-
function getContainerRect
|
|
161
|
-
|
|
168
|
+
function getContainerRect(containerId) {
|
|
169
|
+
var containerNode = (0, _container.getContainerNode)(containerId);
|
|
162
170
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
171
|
+
if (!containerNode) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
166
174
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
175
|
+
if (containerNode === document) {
|
|
176
|
+
return getViewportRect();
|
|
177
|
+
}
|
|
170
178
|
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export {
|
|
175
|
-
contains,
|
|
176
|
-
getContainerRect,
|
|
177
|
-
getPointRect,
|
|
178
|
-
getRect,
|
|
179
|
-
getRects,
|
|
180
|
-
intersects,
|
|
181
|
-
matchSelector,
|
|
182
|
-
parseSelector
|
|
183
|
-
};
|
|
179
|
+
return getRect(containerNode);
|
|
180
|
+
}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Accelerator = exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Provides the {@link spotlight/Accelerator.Accelerator} class.
|
|
12
|
-
*
|
|
13
|
-
* @module spotlight/Accelerator
|
|
14
|
-
* @exports Accelerator
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @class Accelerator
|
|
19
|
-
* @memberof spotlight/Accelerator
|
|
20
|
-
*/
|
|
21
|
-
var Accelerator =
|
|
22
|
-
/**
|
|
23
|
-
* @constructor
|
|
24
|
-
* @param {Number[]} frequency - Controls the frequency with which the acceleration will
|
|
25
|
-
* "freeze". While frozen, the current target item cannot change, and all events are directed
|
|
26
|
-
* to it.
|
|
27
|
-
* @memberof spotlight/Accelerator.Accelerator.prototype
|
|
28
|
-
*/
|
|
29
|
-
function Accelerator() {
|
|
30
|
-
var _this = this;
|
|
31
|
-
|
|
32
|
-
var frequency = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [3, 3, 3, 2, 2, 2, 1];
|
|
33
|
-
|
|
34
|
-
_classCallCheck(this, Accelerator);
|
|
35
|
-
|
|
36
|
-
this.processKey = function (event, callback) {
|
|
37
|
-
switch (event.type) {
|
|
38
|
-
case 'keydown':
|
|
39
|
-
if (event.keyCode !== _this.keyCode) {
|
|
40
|
-
_this.reset();
|
|
41
|
-
|
|
42
|
-
_this.time = Date.now();
|
|
43
|
-
_this.keyCode = event.keyCode;
|
|
44
|
-
return callback(event);
|
|
45
|
-
} else if (_this.canceled) {
|
|
46
|
-
// Prevent skipped keydown events from bubbling
|
|
47
|
-
event.preventDefault();
|
|
48
|
-
return true;
|
|
49
|
-
} else {
|
|
50
|
-
var elapsedTime = Date.now() - _this.time,
|
|
51
|
-
seconds = Math.floor(elapsedTime / 1000),
|
|
52
|
-
toSkip = 0;
|
|
53
|
-
|
|
54
|
-
seconds = seconds > _this.frequency.length - 1 ? _this.frequency.length - 1 : seconds;
|
|
55
|
-
toSkip = _this.frequency[seconds] - 1;
|
|
56
|
-
|
|
57
|
-
if (toSkip < 0) {
|
|
58
|
-
toSkip = 0;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
_this.accelerating = !(seconds === 0 && _this.skipped === 0);
|
|
62
|
-
|
|
63
|
-
if (_this.skipped >= toSkip) {
|
|
64
|
-
_this.skipped = 0;
|
|
65
|
-
return callback(event);
|
|
66
|
-
} else {
|
|
67
|
-
_this.skipped++; // Prevent skipped keydown events from bubbling
|
|
68
|
-
|
|
69
|
-
event.preventDefault();
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
case 'keyup':
|
|
75
|
-
_this.reset();
|
|
76
|
-
|
|
77
|
-
return callback(event);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
this.reset = function () {
|
|
82
|
-
_this.skipped = 0;
|
|
83
|
-
_this.time = 0;
|
|
84
|
-
_this.keyCode = 0;
|
|
85
|
-
_this.canceled = false;
|
|
86
|
-
_this.accelerating = false;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
this.cancel = function () {
|
|
90
|
-
_this.canceled = true;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
this.isAccelerating = function () {
|
|
94
|
-
return _this.accelerating;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/*
|
|
98
|
-
* Whether the instance is currently in an accelerating state.
|
|
99
|
-
*
|
|
100
|
-
* @type {Boolean}
|
|
101
|
-
* @default false
|
|
102
|
-
*/
|
|
103
|
-
this.accelerating = false;
|
|
104
|
-
/*
|
|
105
|
-
* The current count of skipped events.
|
|
106
|
-
*
|
|
107
|
-
* @type {Number}
|
|
108
|
-
* @default 0
|
|
109
|
-
*/
|
|
110
|
-
|
|
111
|
-
this.skipped = 0;
|
|
112
|
-
/*
|
|
113
|
-
* The timestamp of the last evaluated event.
|
|
114
|
-
*
|
|
115
|
-
* @type {Number}
|
|
116
|
-
* @default 0
|
|
117
|
-
*/
|
|
118
|
-
|
|
119
|
-
this.time = 0;
|
|
120
|
-
/*
|
|
121
|
-
* The keyCode of the last evaluated event.
|
|
122
|
-
*
|
|
123
|
-
* @type {Number}
|
|
124
|
-
* @default 0
|
|
125
|
-
*/
|
|
126
|
-
|
|
127
|
-
this.keyCode = 0;
|
|
128
|
-
/*
|
|
129
|
-
* Whether the instance is in a state of being canceled.
|
|
130
|
-
*
|
|
131
|
-
* @type {Boolean}
|
|
132
|
-
* @default false
|
|
133
|
-
*/
|
|
134
|
-
|
|
135
|
-
this.canceled = false;
|
|
136
|
-
/*
|
|
137
|
-
* Controls the frequency with which the acceleration will "freeze". While frozen,
|
|
138
|
-
* the current target item cannot change, and all events are directed to it.
|
|
139
|
-
*
|
|
140
|
-
* @type {Number[]}
|
|
141
|
-
* @default [3, 3, 3, 2, 2, 2, 1]
|
|
142
|
-
* @public
|
|
143
|
-
*/
|
|
144
|
-
|
|
145
|
-
this.frequency = frequency;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Called with the current keydown event and callback, which will be called when the event is
|
|
149
|
-
* allowed through.
|
|
150
|
-
*
|
|
151
|
-
* @function
|
|
152
|
-
* @param {Object} event - The current event to validate.
|
|
153
|
-
* @param {Function} callback - The callback to execute.
|
|
154
|
-
* @returns {Boolean} `true` if the event was consumed by processKey and callback was not called
|
|
155
|
-
* @public
|
|
156
|
-
* @memberof spotlight/Accelerator.Accelerator.prototype
|
|
157
|
-
*/
|
|
158
|
-
;
|
|
159
|
-
|
|
160
|
-
exports.Accelerator = Accelerator;
|
|
161
|
-
var _default = Accelerator;
|
|
162
|
-
exports["default"] = _default;
|