@enact/spotlight 3.4.9-experimental-3 → 3.4.9-experimental-7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/{build/Accelerator → Accelerator}/Accelerator.d.ts +0 -0
  2. package/Accelerator/Accelerator.js +149 -156
  3. package/CHANGELOG.md +22 -0
  4. package/{build/Pause → Pause}/Pause.d.ts +0 -0
  5. package/Pause/Pause.js +102 -80
  6. package/Pause/tests/Pause-specs.js +65 -97
  7. package/SpotlightContainerDecorator/SpotlightContainer.js +175 -140
  8. package/{build/SpotlightContainerDecorator → SpotlightContainerDecorator}/SpotlightContainerDecorator.d.ts +0 -0
  9. package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +222 -176
  10. package/SpotlightContainerDecorator/tests/Element.prototype.closest.js +44 -40
  11. package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +221 -210
  12. package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +150 -243
  13. package/SpotlightContainerDecorator/useSpotlightContainer.js +47 -28
  14. package/{build/SpotlightRootDecorator → SpotlightRootDecorator}/SpotlightRootDecorator.d.ts +0 -0
  15. package/SpotlightRootDecorator/SpotlightRootDecorator.js +206 -111
  16. package/{build/Spottable → Spottable}/Spottable.d.ts +0 -0
  17. package/Spottable/Spottable.js +448 -410
  18. package/Spottable/tests/Spottable-specs.js +90 -117
  19. package/package.json +3 -2
  20. package/src/container.js +718 -653
  21. package/src/navigate.js +406 -491
  22. package/src/pointer.js +86 -78
  23. package/{build/src → src}/spotlight.d.ts +0 -0
  24. package/src/spotlight.js +846 -885
  25. package/src/target.js +448 -474
  26. package/src/tests/container-specs.js +643 -1251
  27. package/src/tests/navigate-specs.js +77 -134
  28. package/src/tests/pointer-specs.js +126 -182
  29. package/src/tests/spotlight-specs.js +103 -133
  30. package/src/tests/target-specs.js +597 -960
  31. package/src/tests/utils.js +89 -67
  32. package/src/utils.js +155 -158
  33. package/build/Accelerator/Accelerator.js +0 -162
  34. package/build/Accelerator/package.json +0 -3
  35. package/build/CHANGELOG.md +0 -838
  36. package/build/Pause/Pause.js +0 -164
  37. package/build/Pause/package.json +0 -3
  38. package/build/Pause/tests/Pause-specs.js +0 -65
  39. package/build/README.md +0 -61
  40. package/build/SpotlightContainerDecorator/SpotlightContainer.js +0 -176
  41. package/build/SpotlightContainerDecorator/SpotlightContainerDecorator.js +0 -282
  42. package/build/SpotlightContainerDecorator/package.json +0 -3
  43. package/build/SpotlightContainerDecorator/tests/Element.prototype.closest.js +0 -45
  44. package/build/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +0 -221
  45. package/build/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +0 -160
  46. package/build/SpotlightContainerDecorator/useSpotlightContainer.js +0 -133
  47. package/build/SpotlightRootDecorator/SpotlightRootDecorator.js +0 -189
  48. package/build/SpotlightRootDecorator/package.json +0 -3
  49. package/build/Spottable/Spottable.js +0 -491
  50. package/build/Spottable/package.json +0 -3
  51. package/build/Spottable/tests/Spottable-specs.js +0 -90
  52. package/build/package-lock.json +0 -229
  53. package/build/package.json +0 -28
  54. package/build/src/container.js +0 -1201
  55. package/build/src/navigate.js +0 -419
  56. package/build/src/pointer.js +0 -183
  57. package/build/src/spotlight.js +0 -896
  58. package/build/src/target.js +0 -507
  59. package/build/src/tests/container-specs.js +0 -653
  60. package/build/src/tests/navigate-specs.js +0 -87
  61. package/build/src/tests/pointer-specs.js +0 -130
  62. package/build/src/tests/spotlight-specs.js +0 -112
  63. package/build/src/tests/target-specs.js +0 -614
  64. package/build/src/tests/utils.js +0 -104
  65. package/build/src/utils.js +0 -180
  66. package/build/styles/debug.less +0 -97
  67. package/build/styles/mixins.less +0 -63
  68. package/docs/index.md +0 -364
@@ -1,82 +1,104 @@
1
- import R from 'ramda';
1
+ "use strict";
2
2
 
3
- import {containerAttribute} from '../container';
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
- const join = R.unapply(R.join('\n'));
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
- const testScenario = (scenario, callback) => () => {
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
- document.body.innerHTML = html;
22
+ exports.join = join;
16
23
 
17
- const root = document.getElementById(rootId);
18
- try {
19
- callback(root);
20
- } catch (e) {
21
- console.log(html); // eslint-disable-line no-console
22
- throw e;
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
- let _id = 1;
27
- const generateContainerId = () => `${containerAttribute}=${_id++}`;
41
+ exports.testScenario = testScenario;
42
+ var _id = 1;
28
43
 
29
- const coerceProps = (v) => {
30
- if (typeof v === 'object') {
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
- const node = (props) => {
38
- let children = '';
39
- let attributes = '';
40
-
41
- Object.keys(props).forEach(key => {
42
- if (key === 'children') {
43
- children = props.children;
44
- } else {
45
- const value = props[key];
46
- if (key === 'className') key = 'class';
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
- const spottable = (props) => node({
55
- className: 'spottable',
56
- ...coerceProps(props)
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
- const container = (props) => node({
60
- [containerAttribute]: _id++,
61
- 'data-spotlight-container': true,
62
- ...coerceProps(props)
63
- });
75
+ exports.node = node;
64
76
 
65
- // eslint-disable-next-line react-hooks/rules-of-hooks
66
- const someNodes = R.useWith(R.compose(R.join('\n'), R.map), [R.identity, R.range(0)]);
67
- const someSpottables = someNodes(spottable);
68
- const someContainers = someNodes(container);
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
- import curry from 'ramda/src/curry';
2
- import warning from 'warning';
1
+ "use strict";
3
2
 
4
- import {getContainerNode} from './container';
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
- let elementMatchesSelector = function (selector) {
7
- const matchedNodes = (this.parentNode || this.document).querySelectorAll(selector);
8
- return [].slice.call(matchedNodes).indexOf(this) >= 0;
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
- elementMatchesSelector = window.Element.prototype.matches ||
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
- const matchSelector = curry((selector, elem) => {
21
- if (typeof selector === 'string') {
22
- return elementMatchesSelector.call(elem, selector);
23
- } else if (typeof selector === 'object' && selector.length) {
24
- return selector.indexOf(elem) >= 0;
25
- } else if (typeof selector === 'object' && selector.nodeType === 1) {
26
- return elem === selector;
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
- function parseSelector (selector) {
32
- let result = [];
33
- try {
34
- if (typeof selector === 'string') {
35
- result = [].slice.call(document.querySelectorAll(selector));
36
- } else if (typeof selector === 'object' && selector.length) {
37
- result = [].slice.call(selector);
38
- } else if (typeof selector === 'object' && selector.nodeType === 1) {
39
- result = [selector];
40
- }
41
- } catch (ex) {
42
- warning(true, `parseSelector failed for selector: ${selector}`);
43
- }
44
-
45
- return result;
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
- const testIntersection = (type, containerRect, elementRect) => {
49
- const {
50
- left: L,
51
- right: R,
52
- top: T,
53
- bottom: B
54
- } = containerRect;
55
-
56
- const {
57
- left: l,
58
- right: r,
59
- top: t,
60
- bottom: b
61
- } = elementRect;
62
-
63
- const right = r >= L && r <= R;
64
- const left = l >= L && l <= R;
65
- const top = t >= T && t <= B;
66
- const bottom = b >= T && b <= B;
67
-
68
- if (type === 'intersects') {
69
- const aroundV = t < T && b > B;
70
- const aroundH = l < L && r > R;
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
- const intersects = curry((containerRect, elementRect) => {
81
- return testIntersection('intersects', containerRect, elementRect);
86
+ var intersects = (0, _curry["default"])(function (containerRect, elementRect) {
87
+ return testIntersection('intersects', containerRect, elementRect);
82
88
  });
83
-
84
- const contains = curry((containerRect, elementRect) => {
85
- return testIntersection('contains', containerRect, elementRect);
89
+ exports.intersects = intersects;
90
+ var contains = (0, _curry["default"])(function (containerRect, elementRect) {
91
+ return testIntersection('contains', containerRect, elementRect);
86
92
  });
87
-
88
- function getRect (elem) {
89
- const cr = elem.getBoundingClientRect();
90
- const rect = {
91
- left: cr.left,
92
- top: cr.top,
93
- width: cr.width,
94
- height: cr.height
95
- };
96
- rect.element = elem;
97
- rect.right = rect.left + rect.width;
98
- rect.bottom = rect.top + rect.height;
99
- rect.center = {
100
- x: rect.left + Math.floor(rect.width / 2),
101
- y: rect.top + Math.floor(rect.height / 2)
102
- };
103
- rect.center.left = rect.center.right = rect.center.x;
104
- rect.center.top = rect.center.bottom = rect.center.y;
105
- return rect;
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 (position) {
109
- const {x, y} = position;
110
- return {
111
- left: x,
112
- top: y,
113
- width: 0,
114
- height: 0,
115
- right: x,
116
- bottom: y,
117
- center: {
118
- x,
119
- y,
120
- left: x,
121
- right: x,
122
- top: y,
123
- bottom: y
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 (candidates) {
129
- if (candidates && candidates.length > 0) {
130
- return candidates.map(getRect);
131
- }
136
+ function getRects(candidates) {
137
+ if (candidates && candidates.length > 0) {
138
+ return candidates.map(getRect);
139
+ }
132
140
 
133
- return [];
141
+ return [];
134
142
  }
135
143
 
136
-
137
- function getViewportRect () {
138
- const {innerWidth: width, innerHeight: height} = window;
139
- const x = width / 2;
140
- const y = height / 2;
141
-
142
- return {
143
- left: 0,
144
- top: 0,
145
- width,
146
- height,
147
- right: width,
148
- bottom: height,
149
- center: {
150
- x,
151
- y,
152
- left: x,
153
- right: x,
154
- top: y,
155
- bottom: y
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 (containerId) {
161
- const containerNode = getContainerNode(containerId);
168
+ function getContainerRect(containerId) {
169
+ var containerNode = (0, _container.getContainerNode)(containerId);
162
170
 
163
- if (!containerNode) {
164
- return null;
165
- }
171
+ if (!containerNode) {
172
+ return null;
173
+ }
166
174
 
167
- if (containerNode === document) {
168
- return getViewportRect();
169
- }
175
+ if (containerNode === document) {
176
+ return getViewportRect();
177
+ }
170
178
 
171
- return getRect(containerNode);
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;
@@ -1,3 +0,0 @@
1
- {
2
- "main": "Accelerator.js"
3
- }