@enact/spotlight 4.7.8 → 4.7.10
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/Accelerator/Accelerator.js +4 -6
- package/CHANGELOG.md +22 -0
- package/Pause/Pause.js +4 -6
- package/Pause/tests/Pause-specs.js +2 -2
- package/README.md +1 -1
- package/SpotlightContainerDecorator/SpotlightContainer.js +6 -8
- package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +9 -12
- package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +4 -4
- package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +4 -4
- package/SpotlightContainerDecorator/useSpotlightContainer.js +2 -2
- package/SpotlightRootDecorator/SpotlightRootDecorator.js +17 -19
- package/SpotlightRootDecorator/tests/SpotlightRootDecorator-specs.js +4 -4
- package/Spottable/Spottable.js +8 -10
- package/Spottable/SpottableCore.js +5 -8
- package/Spottable/tests/Spottable-specs.js +4 -4
- package/Spottable/tests/useSpot-specs.js +6 -6
- package/Spottable/useSpottable.js +6 -8
- package/package.json +3 -3
- package/src/container.js +46 -41
- package/src/inputType.js +6 -11
- package/src/navigate.js +1 -2
- package/src/pointer.js +8 -15
- package/src/spotlight.js +3 -6
- package/src/target.js +117 -100
- package/src/tests/container-specs.js +197 -178
- package/src/tests/spotlight-specs.js +5 -6
- package/src/tests/target-specs.js +14 -16
- package/src/tests/utils-specs.js +76 -0
- package/src/tests/utils.js +15 -26
- package/src/utils.js +32 -7
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
var _container4 = require("../container");
|
|
4
4
|
var _spotlight = _interopRequireDefault(require("../spotlight"));
|
|
5
5
|
var _utils = require("./utils");
|
|
6
|
-
var _container, _container2, _container3;
|
|
7
6
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
8
7
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
-
function _toPropertyKey(
|
|
10
|
-
function _toPrimitive(
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
9
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
11
10
|
var nonSpottable = function nonSpottable() {
|
|
12
11
|
return (0, _utils.node)({
|
|
13
12
|
className: 'other'
|
|
@@ -16,11 +15,11 @@ var nonSpottable = function nonSpottable() {
|
|
|
16
15
|
var scenarios = {
|
|
17
16
|
complexTree: (0, _utils.join)((0, _utils.spottable)({
|
|
18
17
|
'data-spotlight-id': 's1'
|
|
19
|
-
}), (0, _utils.spottable)(nonSpottable()), (0, _utils.container)((
|
|
18
|
+
}), (0, _utils.spottable)(nonSpottable()), (0, _utils.container)(_defineProperty(_defineProperty({}, _container4.containerAttribute, 'first-container'), "children", (0, _utils.join)((0, _utils.someSpottables)(2), (0, _utils.container)(_defineProperty(_defineProperty({}, _container4.containerAttribute, 'second-container'), "children", (0, _utils.join)((0, _utils.spottable)({
|
|
20
19
|
id: 'secondContainerFirstSpottable'
|
|
21
|
-
}), (0, _utils.someSpottables)(2), (0, _utils.container)((
|
|
20
|
+
}), (0, _utils.someSpottables)(2), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container4.containerAttribute, 'third-container'), 'data-spotlight-container-disabled', true), "children", (0, _utils.join)((0, _utils.someSpottables)(4), (0, _utils.node)({
|
|
22
21
|
id: 'child-of-third'
|
|
23
|
-
})))
|
|
22
|
+
})))))))))))
|
|
24
23
|
};
|
|
25
24
|
var setupContainers = function setupContainers() {
|
|
26
25
|
_spotlight["default"].setPointerMode(false);
|
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
var _container12 = require("../container");
|
|
4
4
|
var _target = require("../target");
|
|
5
5
|
var _utils = require("./utils");
|
|
6
|
-
var _container2, _container3, _container4, _container5, _container6, _container7, _container8, _container9, _container10, _container11;
|
|
7
6
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
-
function _toPropertyKey(
|
|
9
|
-
function _toPrimitive(
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
8
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
9
|
var nonSpottable = function nonSpottable() {
|
|
11
10
|
return (0, _utils.node)({
|
|
12
11
|
className: 'other'
|
|
@@ -22,18 +21,17 @@ var positionedSpottable = function positionedSpottable(id, top, left) {
|
|
|
22
21
|
});
|
|
23
22
|
};
|
|
24
23
|
var grid = function grid() {
|
|
25
|
-
|
|
26
|
-
return (0, _utils.container)((_container = {}, _defineProperty(_container, _container12.containerAttribute, 'grid'), _defineProperty(_container, "style", 'position: relative; height: 30px; width: 30px;'), _defineProperty(_container, "children", (0, _utils.join)(positionedSpottable('top-left', 0, 0), positionedSpottable('top-center', 0, 10), positionedSpottable('top-right', 0, 20), positionedSpottable('middle-left', 10, 0), positionedSpottable('middle-center', 10, 10), positionedSpottable('middle-right', 10, 20), positionedSpottable('bottom-left', 20, 0), positionedSpottable('bottom-center', 20, 10), positionedSpottable('bottom-right', 20, 20))), _container));
|
|
24
|
+
return (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'grid'), "style", 'position: relative; height: 30px; width: 30px;'), "children", (0, _utils.join)(positionedSpottable('top-left', 0, 0), positionedSpottable('top-center', 0, 10), positionedSpottable('top-right', 0, 20), positionedSpottable('middle-left', 10, 0), positionedSpottable('middle-center', 10, 10), positionedSpottable('middle-right', 10, 20), positionedSpottable('bottom-left', 20, 0), positionedSpottable('bottom-center', 20, 10), positionedSpottable('bottom-right', 20, 20))));
|
|
27
25
|
};
|
|
28
26
|
var scenarios = {
|
|
29
|
-
complexTree: (0, _utils.join)((0, _utils.spottable)(nonSpottable()), (0, _utils.container)((
|
|
27
|
+
complexTree: (0, _utils.join)((0, _utils.spottable)(nonSpottable()), (0, _utils.container)(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'first-container'), "children", (0, _utils.join)((0, _utils.someSpottables)(2), (0, _utils.container)(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'second-container'), "children", (0, _utils.join)((0, _utils.someSpottables)(3), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'third-container'), 'data-spotlight-container-disabled', true), "children", (0, _utils.join)((0, _utils.someSpottables)(4), (0, _utils.node)({
|
|
30
28
|
id: 'child-of-third'
|
|
31
|
-
})))
|
|
29
|
+
}))))))))))),
|
|
32
30
|
nonSpottableInContainer: (0, _utils.join)((0, _utils.spottable)({
|
|
33
31
|
id: 'in-root'
|
|
34
|
-
}), (0, _utils.container)((
|
|
32
|
+
}), (0, _utils.container)(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'first'), "children", (0, _utils.join)(nonSpottable(), (0, _utils.spottable)({
|
|
35
33
|
id: 'in-first'
|
|
36
|
-
})))
|
|
34
|
+
})))), (0, _utils.container)(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'second'), "children", (0, _utils.join)(nonSpottable())))),
|
|
37
35
|
grid: (0, _utils.join)((0, _utils.spottable)({
|
|
38
36
|
id: 'before-grid',
|
|
39
37
|
style: 'height: 10px'
|
|
@@ -53,7 +51,7 @@ var scenarios = {
|
|
|
53
51
|
}), (0, _utils.node)({
|
|
54
52
|
// allocate some empty space so that overflow items would be otherwise navigable
|
|
55
53
|
style: 'height: 100px'
|
|
56
|
-
}), (0, _utils.container)((
|
|
54
|
+
}), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'overflow-container'), "style", 'position: relative; height: 30px; width: 30px;'), "children", (0, _utils.join)((0, _utils.spottable)({
|
|
57
55
|
id: 'overflow-above',
|
|
58
56
|
style: 'position: absolute; top: -10px; left: 0px; height: 10px; width: 10px;'
|
|
59
57
|
}), (0, _utils.spottable)({
|
|
@@ -62,23 +60,23 @@ var scenarios = {
|
|
|
62
60
|
}), (0, _utils.spottable)({
|
|
63
61
|
id: 'overflow-within',
|
|
64
62
|
style: 'position: absolute; top: 0px; left: 0px; height: 10px; width: 10px;'
|
|
65
|
-
})))
|
|
63
|
+
}))))),
|
|
66
64
|
overflowLargeSubContainer: (0, _utils.join)((0, _utils.spottable)({
|
|
67
65
|
id: 'outside-overflow'
|
|
68
66
|
}), (0, _utils.node)({
|
|
69
67
|
// allocate some empty space so that overflow items would be otherwise navigable
|
|
70
68
|
style: 'height: 100px'
|
|
71
|
-
}), (0, _utils.container)((
|
|
69
|
+
}), (0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'overflow-container'), "style", 'position: relative; height: 30px; width: 30px;'), "children", (0, _utils.join)((0, _utils.container)(_defineProperty(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'inside'), "style", 'position: absolute; top: -10px; left: 0px; height: 50px; width: 10px;'), "children", (0, _utils.join)((0, _utils.node)({
|
|
72
70
|
// allocate space to push following spottable into view
|
|
73
71
|
style: 'height: 10px'
|
|
74
72
|
}), (0, _utils.spottable)({
|
|
75
73
|
id: 'in-large-container'
|
|
76
|
-
})))
|
|
74
|
+
})))), (0, _utils.spottable)({
|
|
77
75
|
id: 'below-large-container',
|
|
78
76
|
style: 'position: absolute; top: 40px; left: 0px; height: 10px; width: 10px;'
|
|
79
|
-
})))
|
|
80
|
-
emptyContainer: (0, _utils.join)(positionedSpottable('above', 0, 10), (0, _utils.container)((
|
|
81
|
-
emptyContainerOverlap: (0, _utils.join)(positionedSpottable('above', 5, 10), (0, _utils.container)((
|
|
77
|
+
}))))),
|
|
78
|
+
emptyContainer: (0, _utils.join)(positionedSpottable('above', 0, 10), (0, _utils.container)(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'empty-container'), "style", position(10, 10))), positionedSpottable('below', 30, 0)),
|
|
79
|
+
emptyContainerOverlap: (0, _utils.join)(positionedSpottable('above', 5, 10), (0, _utils.container)(_defineProperty(_defineProperty({}, _container12.containerAttribute, 'empty-container'), "style", position(10, 10))), positionedSpottable('below', 30, 0))
|
|
82
80
|
};
|
|
83
81
|
var safeTarget = function safeTarget(n, fn) {
|
|
84
82
|
return n ? fn(n) : 'NOT FOUND';
|
package/src/tests/utils-specs.js
CHANGED
|
@@ -37,6 +37,82 @@ var scenarios = {
|
|
|
37
37
|
})
|
|
38
38
|
};
|
|
39
39
|
describe('utils', function () {
|
|
40
|
+
describe('#getIntersectionRect', function () {
|
|
41
|
+
test('should return the intersection rect between two given rects', function () {
|
|
42
|
+
var rect1 = {
|
|
43
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
44
|
+
return {
|
|
45
|
+
left: 0,
|
|
46
|
+
top: 0,
|
|
47
|
+
width: 100,
|
|
48
|
+
height: 100
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var rect2 = {
|
|
53
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
54
|
+
return {
|
|
55
|
+
left: 50,
|
|
56
|
+
top: 50,
|
|
57
|
+
width: 100,
|
|
58
|
+
height: 100
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var expected = {
|
|
63
|
+
left: 50,
|
|
64
|
+
top: 50,
|
|
65
|
+
width: 50,
|
|
66
|
+
height: 50,
|
|
67
|
+
right: 100,
|
|
68
|
+
bottom: 100,
|
|
69
|
+
center: {
|
|
70
|
+
x: 75,
|
|
71
|
+
y: 75,
|
|
72
|
+
left: 75,
|
|
73
|
+
right: 75,
|
|
74
|
+
top: 75,
|
|
75
|
+
bottom: 75
|
|
76
|
+
},
|
|
77
|
+
element: rect2
|
|
78
|
+
};
|
|
79
|
+
var actual = (0, _utils.getIntersectionRect)(rect1, rect2);
|
|
80
|
+
expect(actual).toEqual(expected);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe('#getRect', function () {
|
|
84
|
+
test('should return the rect value calculated based on the given element', function () {
|
|
85
|
+
var element = {
|
|
86
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
87
|
+
return {
|
|
88
|
+
left: 10,
|
|
89
|
+
top: 20,
|
|
90
|
+
width: 100,
|
|
91
|
+
height: 200
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var expected = {
|
|
96
|
+
left: 10,
|
|
97
|
+
top: 20,
|
|
98
|
+
width: 100,
|
|
99
|
+
height: 200,
|
|
100
|
+
right: 110,
|
|
101
|
+
bottom: 220,
|
|
102
|
+
center: {
|
|
103
|
+
x: 60,
|
|
104
|
+
y: 120,
|
|
105
|
+
left: 60,
|
|
106
|
+
right: 60,
|
|
107
|
+
top: 120,
|
|
108
|
+
bottom: 120
|
|
109
|
+
},
|
|
110
|
+
element: element
|
|
111
|
+
};
|
|
112
|
+
var actual = (0, _utils.getRect)(element);
|
|
113
|
+
expect(actual).toEqual(expected);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
40
116
|
describe('#getPointRect', function () {
|
|
41
117
|
test('should return an rect value calculated based on given position', function () {
|
|
42
118
|
var expected = {
|
package/src/tests/utils.js
CHANGED
|
@@ -7,14 +7,13 @@ exports.testScenario = exports.spottable = exports.someSpottablesAndContainers =
|
|
|
7
7
|
var _ramda = _interopRequireDefault(require("ramda"));
|
|
8
8
|
var _container = require("../container");
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
-
function ownKeys(
|
|
11
|
-
function _objectSpread(
|
|
10
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
12
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
-
function _toPropertyKey(
|
|
14
|
-
function _toPrimitive(
|
|
15
|
-
var join = _ramda["default"].unapply(_ramda["default"].join('\n'));
|
|
16
|
-
exports.
|
|
17
|
-
var testScenario = function testScenario(scenario, callback) {
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
14
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
15
|
+
var join = exports.join = _ramda["default"].unapply(_ramda["default"].join('\n'));
|
|
16
|
+
var testScenario = exports.testScenario = function testScenario(scenario, callback) {
|
|
18
17
|
return function () {
|
|
19
18
|
var rootId = 'test-root';
|
|
20
19
|
var html = join("<div id=\"".concat(rootId, "\">"), scenario, '</div>');
|
|
@@ -28,12 +27,10 @@ var testScenario = function testScenario(scenario, callback) {
|
|
|
28
27
|
}
|
|
29
28
|
};
|
|
30
29
|
};
|
|
31
|
-
exports.testScenario = testScenario;
|
|
32
30
|
var _id = 1;
|
|
33
|
-
var generateContainerId = function generateContainerId() {
|
|
31
|
+
var generateContainerId = exports.generateContainerId = function generateContainerId() {
|
|
34
32
|
return "".concat(_container.containerAttribute, "=").concat(_id++);
|
|
35
33
|
};
|
|
36
|
-
exports.generateContainerId = generateContainerId;
|
|
37
34
|
var coerceProps = function coerceProps(v) {
|
|
38
35
|
if (typeof v === 'object') {
|
|
39
36
|
return v;
|
|
@@ -43,7 +40,7 @@ var coerceProps = function coerceProps(v) {
|
|
|
43
40
|
};
|
|
44
41
|
}
|
|
45
42
|
};
|
|
46
|
-
var node = function node(props) {
|
|
43
|
+
var node = exports.node = function node(props) {
|
|
47
44
|
var children = '';
|
|
48
45
|
var attributes = '';
|
|
49
46
|
var tag = 'div';
|
|
@@ -62,25 +59,17 @@ var node = function node(props) {
|
|
|
62
59
|
});
|
|
63
60
|
return "<".concat(tag, " ").concat(attributes, ">").concat(children, "</").concat(tag, ">");
|
|
64
61
|
};
|
|
65
|
-
exports.
|
|
66
|
-
var spottable = function spottable(props) {
|
|
62
|
+
var spottable = exports.spottable = function spottable(props) {
|
|
67
63
|
return node(_objectSpread({
|
|
68
64
|
className: 'spottable'
|
|
69
65
|
}, coerceProps(props)));
|
|
70
66
|
};
|
|
71
|
-
exports.
|
|
72
|
-
|
|
73
|
-
var _objectSpread2;
|
|
74
|
-
return node(_objectSpread((_objectSpread2 = {}, _defineProperty(_objectSpread2, _container.containerAttribute, _id++), _defineProperty(_objectSpread2, 'data-spotlight-container', true), _objectSpread2), coerceProps(props)));
|
|
67
|
+
var container = exports.container = function container(props) {
|
|
68
|
+
return node(_objectSpread(_defineProperty(_defineProperty({}, _container.containerAttribute, _id++), 'data-spotlight-container', true), coerceProps(props)));
|
|
75
69
|
};
|
|
76
70
|
|
|
77
71
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
78
|
-
exports.
|
|
79
|
-
var
|
|
80
|
-
exports.
|
|
81
|
-
var
|
|
82
|
-
exports.someSpottables = someSpottables;
|
|
83
|
-
var someContainers = someNodes(container);
|
|
84
|
-
exports.someContainers = someContainers;
|
|
85
|
-
var someSpottablesAndContainers = _ramda["default"].converge(_ramda["default"].concat, [someSpottables, someContainers]);
|
|
86
|
-
exports.someSpottablesAndContainers = someSpottablesAndContainers;
|
|
72
|
+
var someNodes = exports.someNodes = _ramda["default"].useWith(_ramda["default"].compose(_ramda["default"].join('\n'), _ramda["default"].map), [_ramda["default"].identity, _ramda["default"].range(0)]);
|
|
73
|
+
var someSpottables = exports.someSpottables = someNodes(spottable);
|
|
74
|
+
var someContainers = exports.someContainers = someNodes(container);
|
|
75
|
+
var someSpottablesAndContainers = exports.someSpottablesAndContainers = _ramda["default"].converge(_ramda["default"].concat, [someSpottables, someContainers]);
|
package/src/utils.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.contains = void 0;
|
|
7
7
|
exports.getContainerRect = getContainerRect;
|
|
8
|
+
exports.getIntersectionRect = getIntersectionRect;
|
|
8
9
|
exports.getPointRect = getPointRect;
|
|
9
10
|
exports.getRect = getRect;
|
|
10
11
|
exports.getRects = getRects;
|
|
@@ -23,7 +24,7 @@ var elementMatchesSelector = function elementMatchesSelector(selector) {
|
|
|
23
24
|
if (typeof window === 'object') {
|
|
24
25
|
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;
|
|
25
26
|
}
|
|
26
|
-
var matchSelector = (0, _curry["default"])(function (selector, elem) {
|
|
27
|
+
var matchSelector = exports.matchSelector = (0, _curry["default"])(function (selector, elem) {
|
|
27
28
|
if (typeof selector === 'string') {
|
|
28
29
|
return elementMatchesSelector.call(elem, selector);
|
|
29
30
|
} else if (typeof selector === 'object' && selector.length) {
|
|
@@ -33,7 +34,6 @@ var matchSelector = (0, _curry["default"])(function (selector, elem) {
|
|
|
33
34
|
}
|
|
34
35
|
return false;
|
|
35
36
|
});
|
|
36
|
-
exports.matchSelector = matchSelector;
|
|
37
37
|
function parseSelector(selector) {
|
|
38
38
|
var result = [];
|
|
39
39
|
try {
|
|
@@ -74,17 +74,42 @@ var testIntersection = function testIntersection(type, containerRect, elementRec
|
|
|
74
74
|
b > T - epsilon && b < B + epsilon // bottom
|
|
75
75
|
;
|
|
76
76
|
}
|
|
77
|
-
|
|
78
77
|
return true;
|
|
79
78
|
};
|
|
80
|
-
var intersects = (0, _curry["default"])(function (containerRect, elementRect) {
|
|
79
|
+
var intersects = exports.intersects = (0, _curry["default"])(function (containerRect, elementRect) {
|
|
81
80
|
return testIntersection('intersects', containerRect, elementRect);
|
|
82
81
|
});
|
|
83
|
-
exports.
|
|
84
|
-
var contains = (0, _curry["default"])(function (containerRect, elementRect) {
|
|
82
|
+
var contains = exports.contains = (0, _curry["default"])(function (containerRect, elementRect) {
|
|
85
83
|
return testIntersection('contains', containerRect, elementRect);
|
|
86
84
|
});
|
|
87
|
-
|
|
85
|
+
function getIntersectionRect(container, element) {
|
|
86
|
+
var _container$getBoundin = container.getBoundingClientRect(),
|
|
87
|
+
L = _container$getBoundin.left,
|
|
88
|
+
T = _container$getBoundin.top,
|
|
89
|
+
W = _container$getBoundin.width,
|
|
90
|
+
H = _container$getBoundin.height;
|
|
91
|
+
var _element$getBoundingC = element.getBoundingClientRect(),
|
|
92
|
+
l = _element$getBoundingC.left,
|
|
93
|
+
t = _element$getBoundingC.top,
|
|
94
|
+
w = _element$getBoundingC.width,
|
|
95
|
+
h = _element$getBoundingC.height;
|
|
96
|
+
var intersectionRect = {
|
|
97
|
+
element: element,
|
|
98
|
+
left: Math.max(l, L),
|
|
99
|
+
right: Math.min(l + w, L + W),
|
|
100
|
+
top: Math.max(t, T),
|
|
101
|
+
bottom: Math.min(t + h, T + H)
|
|
102
|
+
};
|
|
103
|
+
intersectionRect.width = intersectionRect.right - intersectionRect.left;
|
|
104
|
+
intersectionRect.height = intersectionRect.bottom - intersectionRect.top;
|
|
105
|
+
intersectionRect.center = {
|
|
106
|
+
x: intersectionRect.left + Math.floor(intersectionRect.width / 2),
|
|
107
|
+
y: intersectionRect.top + Math.floor(intersectionRect.height / 2)
|
|
108
|
+
};
|
|
109
|
+
intersectionRect.center.left = intersectionRect.center.right = intersectionRect.center.x;
|
|
110
|
+
intersectionRect.center.top = intersectionRect.center.bottom = intersectionRect.center.y;
|
|
111
|
+
return intersectionRect;
|
|
112
|
+
}
|
|
88
113
|
function getRect(elem) {
|
|
89
114
|
var cr = elem.getBoundingClientRect();
|
|
90
115
|
var rect = {
|