@enact/ui 4.9.0-alpha.1 → 4.9.0-alpha.2

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/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  The following is a curated list of changes in the Enact ui module, newest changes on the top.
4
4
 
5
+ ## [4.9.0-alpha.2] - 2024-05-24
6
+
7
+ No significant changes.
8
+
9
+ ## [4.0.14] - 2024-05-14
10
+
11
+ No significant changes.
12
+
13
+ ## [4.7.11] - 2024-05-13
14
+
15
+ No significant changes.
16
+
5
17
  ## [4.9.0-alpha.1] - 2024-04-09
6
18
 
7
19
  ### Added
@@ -3,38 +3,23 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports["default"] = exports.MarqueeControllerContext = exports.MarqueeController = void 0;
7
- var _handle = require("@enact/core/handle");
6
+ exports.MarqueeController = void 0;
7
+ Object.defineProperty(exports, "MarqueeControllerContext", {
8
+ enumerable: true,
9
+ get: function get() {
10
+ return _useMarqueeController2.MarqueeControllerContext;
11
+ }
12
+ });
13
+ exports["default"] = void 0;
8
14
  var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
9
- var _util = require("@enact/core/util");
10
- var _react = require("react");
15
+ var _useMarqueeController2 = require("./useMarqueeController");
11
16
  var _jsxRuntime = require("react/jsx-runtime");
12
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
18
  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; }
14
19
  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; }
15
20
  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; }
16
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
18
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
19
21
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
20
- 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); }
21
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
22
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
23
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
24
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
25
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
26
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
27
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
28
- var STATE = {
29
- inactive: 0,
30
- // Marquee is not necessary (render or focus not happened)
31
- active: 1,
32
- // Marquee in progress, awaiting complete
33
- ready: 2 // Marquee completed or not needed, but state is active
34
- };
35
- var MarqueeControllerContext = exports.MarqueeControllerContext = /*#__PURE__*/(0, _react.createContext)(null);
36
-
37
- /**
22
+ 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); } /**
38
23
  * Default configuration parameters for {@link ui/Marquee.MarqueeController}.
39
24
  *
40
25
  * @type {Object}
@@ -62,266 +47,20 @@ var defaultConfig = {
62
47
  * @public
63
48
  */
64
49
  var MarqueeController = exports.MarqueeController = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
65
- var _class;
66
50
  var marqueeOnFocus = config.marqueeOnFocus;
67
- var forwardBlur = (0, _handle.forward)('onBlur');
68
- var forwardFocus = (0, _handle.forward)('onFocus');
69
- return _class = /*#__PURE__*/function (_Component) {
70
- _inherits(_class, _Component);
71
- var _super = _createSuper(_class);
72
- function _class(props) {
73
- var _this;
74
- _classCallCheck(this, _class);
75
- _this = _super.call(this, props);
76
- _this.cancelJob = new _util.Job(function () {
77
- return _this.doCancel();
78
- }, 30);
79
- /*
80
- * Registers `component` with a set of handlers for `start` and `stop`.
81
- *
82
- * @param {Object} component A component, typically a React component instance, on
83
- * which handlers will be dispatched.
84
- * @param {Object} handlers An object containing `start` and `stop` functions
85
- *
86
- * @returns {undefined}
87
- */
88
- _this.handleRegister = function (component, handlers) {
89
- var needsStart = !_this.allInactive() || _this.isFocused;
90
- _this.controlled.push(_objectSpread(_objectSpread({}, handlers), {}, {
91
- state: STATE.inactive,
92
- component: component
93
- }));
94
- if (needsStart) {
95
- _this.dispatch('start');
96
- }
97
- };
98
- /*
99
- * Unregisters `component` for synchronization
100
- *
101
- * @param {Object} component A previously registered component
102
- *
103
- * @returns {undefined}
104
- */
105
- _this.handleUnregister = function (component) {
106
- var wasRunning = false;
107
- for (var i = 0; i < _this.controlled.length; i++) {
108
- if (_this.controlled[i].component === component) {
109
- wasRunning = _this.controlled[i].state === STATE.active;
110
- _this.controlled.splice(i, 1);
111
- break;
112
- }
113
- }
114
- if (wasRunning && !_this.anyRunning()) {
115
- _this.dispatch('start');
116
- }
117
- };
118
- /*
119
- * Handler for the `start` context function
120
- *
121
- * @param {Object} component A previously registered component
122
- *
123
- * @returns {undefined}
124
- */
125
- _this.handleStart = function (component) {
126
- _this.cancelJob.stop();
127
- if (!_this.anyRunning()) {
128
- _this.markAll(STATE.ready);
129
- _this.dispatch('start', component);
130
- }
131
- };
132
- /*
133
- * Handler for the `cancel` context function
134
- *
135
- * @param {Object} component A previously registered component
136
- *
137
- * @returns {undefined}
138
- */
139
- _this.handleCancel = function () {
140
- if (_this.anyRunning()) {
141
- _this.cancelJob.start();
142
- }
143
- };
144
- _this.doCancel = function () {
145
- if (_this.isHovered || _this.isFocused) {
146
- return;
147
- }
148
- _this.markAll(STATE.inactive);
149
- _this.dispatch('stop');
150
- };
151
- /*
152
- * Handler for the `complete` context function
153
- *
154
- * @param {Object} component A previously registered component
155
- *
156
- * @returns {undefined}
157
- */
158
- _this.handleComplete = function (component) {
159
- var complete = _this.markReady(component);
160
- if (complete) {
161
- _this.markAll(STATE.ready);
162
- _this.dispatch('start');
163
- }
164
- };
165
- _this.handleEnter = function () {
166
- _this.isHovered = true;
167
- if (!_this.anyRunning()) {
168
- _this.dispatch('start');
169
- }
170
- _this.cancelJob.stop();
171
- };
172
- _this.handleLeave = function () {
173
- _this.isHovered = false;
174
- _this.cancelJob.start();
175
- };
176
- /*
177
- * Handler for the focus event
178
- */
179
- _this.handleFocus = function (ev) {
180
- _this.isFocused = true;
181
- if (!_this.anyRunning()) {
182
- _this.dispatch('start');
183
- }
184
- _this.cancelJob.stop();
185
- forwardFocus(ev, _this.props);
186
- };
187
- /*
188
- * Handler for the blur event
189
- */
190
- _this.handleBlur = function (ev) {
191
- _this.isFocused = false;
192
- if (_this.anyRunning()) {
193
- _this.cancelJob.start();
194
- }
195
- forwardBlur(ev, _this.props);
196
- };
197
- _this.controlled = [];
198
- _this.isFocused = false;
199
- _this.childContext = {
200
- cancel: _this.handleCancel,
201
- complete: _this.handleComplete,
202
- enter: _this.handleEnter,
203
- leave: _this.handleLeave,
204
- register: _this.handleRegister,
205
- start: _this.handleStart,
206
- unregister: _this.handleUnregister
207
- };
208
- return _this;
51
+ return function (props) {
52
+ var _useMarqueeController = (0, _useMarqueeController2.useMarqueeController)(props),
53
+ handleBlur = _useMarqueeController.handleBlur,
54
+ handleFocus = _useMarqueeController.handleFocus,
55
+ provideMarqueeControllerContext = _useMarqueeController.provideMarqueeControllerContext;
56
+ var wrappedProps = props;
57
+ if (marqueeOnFocus) {
58
+ wrappedProps = _objectSpread(_objectSpread({}, props), {}, {
59
+ onBlur: handleBlur,
60
+ onFocus: handleFocus
61
+ });
209
62
  }
210
- _createClass(_class, [{
211
- key: "componentWillUnmount",
212
- value: function componentWillUnmount() {
213
- this.cancelJob.stop();
214
- }
215
- }, {
216
- key: "dispatch",
217
- value:
218
- /*
219
- * Invokes the `action` handler for each synchronized component except the invoking
220
- * `component`.
221
- *
222
- * @param {String} action `'start'` or `'stop'`
223
- * @param {Object} component A previously registered component
224
- *
225
- * @returns {undefined}
226
- */
227
- function dispatch(action, component) {
228
- this.controlled.forEach(function (controlled) {
229
- var controlledComponent = controlled.component,
230
- handler = controlled[action];
231
- if (component !== controlledComponent && typeof handler === 'function') {
232
- var complete = handler.call(controlledComponent);
233
-
234
- // Returning `true` from a start request means that the marqueeing is
235
- // unnecessary and is therefore not awaiting a finish
236
- if (action === 'start' && complete) {
237
- controlled.state = STATE.ready;
238
- } else if (action === 'start') {
239
- controlled.state = STATE.active;
240
- }
241
- } else if (action === 'start' && component === controlledComponent) {
242
- controlled.state = STATE.active;
243
- }
244
- });
245
- }
246
-
247
- /*
248
- * Marks all components with the passed-in state
249
- *
250
- * @param {Enum} state The state to set
251
- *
252
- * @returns {undefined}
253
- */
254
- }, {
255
- key: "markAll",
256
- value: function markAll(state) {
257
- this.controlled.forEach(function (c) {
258
- c.state = state;
259
- });
260
- }
261
-
262
- /*
263
- * Marks `component` as ready for next marquee action
264
- *
265
- * @param {Object} component A previously registered component
266
- *
267
- * @returns {Boolean} `true` if no components are STATE.active
268
- */
269
- }, {
270
- key: "markReady",
271
- value: function markReady(component) {
272
- var complete = true;
273
- this.controlled.forEach(function (c) {
274
- if (c.component === component) {
275
- c.state = STATE.ready;
276
- }
277
- complete = complete && c.state !== STATE.active;
278
- });
279
- return complete;
280
- }
281
-
282
- /*
283
- * Checks that all components are inactive
284
- *
285
- * @returns {Boolean} `true` if any components should be running
286
- */
287
- }, {
288
- key: "allInactive",
289
- value: function allInactive() {
290
- var activeOrReady = this.controlled.reduce(function (res, component) {
291
- return res || !(component.state === STATE.inactive);
292
- }, false);
293
- return !activeOrReady;
294
- }
295
-
296
- /*
297
- * Checks for any components currently marqueeing
298
- *
299
- * @returns {Boolean} `true` if any component is marqueeing
300
- */
301
- }, {
302
- key: "anyRunning",
303
- value: function anyRunning() {
304
- return this.controlled.reduce(function (res, component) {
305
- return res || component.state === STATE.active;
306
- }, false);
307
- }
308
- }, {
309
- key: "render",
310
- value: function render() {
311
- var props = this.props;
312
- if (marqueeOnFocus) {
313
- props = _objectSpread(_objectSpread({}, this.props), {}, {
314
- onBlur: this.handleBlur,
315
- onFocus: this.handleFocus
316
- });
317
- }
318
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(MarqueeControllerContext.Provider, {
319
- value: this.childContext,
320
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapped, _objectSpread({}, props))
321
- });
322
- }
323
- }]);
324
- return _class;
325
- }(_react.Component), _class.displayName = 'MarqueeController', _class;
63
+ return provideMarqueeControllerContext( /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapped, _objectSpread({}, wrappedProps)));
64
+ };
326
65
  });
327
66
  var _default = exports["default"] = MarqueeController;
@@ -5,6 +5,24 @@ import * as React from "react";
5
5
  type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
6
6
  type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
7
7
 
8
+ export interface MarqueeControllerConfig extends Object {
9
+ /**
10
+ * When `true` , any `onFocus` events that bubble to the controller will start the contained
11
+ `Marquee` instances. This is useful when a component contains `Marquee` instances that need to be
12
+ started when sibling components are focused.
13
+ */
14
+ marqueeOnFocus?: boolean;
15
+ }
16
+ export interface MarqueeControllerProps {}
17
+ export function MarqueeController<P>(
18
+ config: MarqueeControllerConfig,
19
+ Component: React.ComponentType<P> | string,
20
+ ): React.ComponentType<P & MarqueeControllerProps>;
21
+
22
+ export function MarqueeController<P>(
23
+ Component: React.ComponentType<P> | string,
24
+ ): React.ComponentType<P & MarqueeControllerProps>;
25
+
8
26
  export interface MarqueeBaseProps {
9
27
  /**
10
28
  * Text alignment value of the marquee
@@ -89,24 +107,6 @@ export class MarqueeBase extends React.Component<
89
107
  Merge<React.HTMLProps<HTMLElement>, MarqueeBaseProps>
90
108
  > {}
91
109
 
92
- export interface MarqueeControllerConfig extends Object {
93
- /**
94
- * When `true` , any `onFocus` events that bubble to the controller will start the contained
95
- `Marquee` instances. This is useful when a component contains `Marquee` instances that need to be
96
- started when sibling components are focused.
97
- */
98
- marqueeOnFocus?: boolean;
99
- }
100
- export interface MarqueeControllerProps {}
101
- export function MarqueeController<P>(
102
- config: MarqueeControllerConfig,
103
- Component: React.ComponentType<P> | string,
104
- ): React.ComponentType<P & MarqueeControllerProps>;
105
-
106
- export function MarqueeController<P>(
107
- Component: React.ComponentType<P> | string,
108
- ): React.ComponentType<P & MarqueeControllerProps>;
109
-
110
110
  export interface MarqueeProps
111
111
  extends Merge<MarqueeBaseProps, MarqueeDecoratorProps> {}
112
112
  /**
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useMarqueeController = exports["default"] = exports.MarqueeControllerContext = void 0;
7
+ var _handle = require("@enact/core/handle");
8
+ var _util = require("@enact/core/util");
9
+ var _react = require("react");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ 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; }
12
+ 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; }
13
+ 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; }
14
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
15
+ 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); }
16
+ var STATE = {
17
+ inactive: 0,
18
+ // Marquee is not necessary (render or focus not happened)
19
+ active: 1,
20
+ // Marquee in progress, awaiting complete
21
+ ready: 2 // Marquee completed or not needed, but state is active
22
+ };
23
+ var MarqueeControllerContext = exports.MarqueeControllerContext = /*#__PURE__*/(0, _react.createContext)(null);
24
+ var forwardBlur = (0, _handle.forward)('onBlur');
25
+ var forwardFocus = (0, _handle.forward)('onFocus');
26
+ var useMarqueeController = exports.useMarqueeController = function useMarqueeController(props) {
27
+ var mutableRef = (0, _react.useRef)({
28
+ controlled: [],
29
+ isFocused: false,
30
+ isHovered: false
31
+ });
32
+
33
+ /*
34
+ * Invokes the `action` handler for each synchronized component except the invoking
35
+ * `component`.
36
+ *
37
+ * @param {String} action `'start'` or `'stop'`
38
+ * @param {Object} component A previously registered component
39
+ *
40
+ * @returns {undefined}
41
+ */
42
+ var dispatch = (0, _react.useCallback)(function (action, component) {
43
+ mutableRef.current.controlled.forEach(function (controlled) {
44
+ var controlledComponent = controlled.component,
45
+ handler = controlled[action];
46
+ if (component !== controlledComponent && typeof handler === 'function') {
47
+ var complete = handler.call(controlledComponent);
48
+
49
+ // Returning `true` from a start request means that the marqueeing is
50
+ // unnecessary and is therefore not awaiting a finish
51
+ if (action === 'start' && complete) {
52
+ controlled.state = STATE.ready;
53
+ } else if (action === 'start') {
54
+ controlled.state = STATE.active;
55
+ }
56
+ } else if (action === 'start' && component === controlledComponent) {
57
+ controlled.state = STATE.active;
58
+ }
59
+ });
60
+ }, []);
61
+
62
+ /*
63
+ * Marks all components with the passed-in state
64
+ *
65
+ * @param {Enum} state The state to set
66
+ *
67
+ * @returns {undefined}
68
+ */
69
+ var markAll = (0, _react.useCallback)(function (state) {
70
+ mutableRef.current.controlled.forEach(function (c) {
71
+ c.state = state;
72
+ });
73
+ }, []);
74
+
75
+ /*
76
+ * Marks `component` as ready for next marquee action
77
+ *
78
+ * @param {Object} component A previously registered component
79
+ *
80
+ * @returns {Boolean} `true` if no components are STATE.active
81
+ */
82
+ var markReady = (0, _react.useCallback)(function (component) {
83
+ var complete = true;
84
+ mutableRef.current.controlled.forEach(function (c) {
85
+ if (c.component === component) {
86
+ c.state = STATE.ready;
87
+ }
88
+ complete = complete && c.state !== STATE.active;
89
+ });
90
+ return complete;
91
+ }, []);
92
+
93
+ /*
94
+ * Checks that all components are inactive
95
+ *
96
+ * @returns {Boolean} `true` if any components should be running
97
+ */
98
+ var allInactive = (0, _react.useCallback)(function () {
99
+ var activeOrReady = mutableRef.current.controlled.reduce(function (res, component) {
100
+ return res || !(component.state === STATE.inactive);
101
+ }, false);
102
+ return !activeOrReady;
103
+ }, []);
104
+
105
+ /*
106
+ * Checks for any components currently marqueeing
107
+ *
108
+ * @returns {Boolean} `true` if any component is marqueeing
109
+ */
110
+ var anyRunning = (0, _react.useCallback)(function () {
111
+ return mutableRef.current.controlled.reduce(function (res, component) {
112
+ return res || component.state === STATE.active;
113
+ }, false);
114
+ }, []);
115
+ var doCancel = (0, _react.useCallback)(function () {
116
+ if (mutableRef.current.isHovered || mutableRef.current.isFocused) {
117
+ return;
118
+ }
119
+ markAll(STATE.inactive);
120
+ dispatch('stop');
121
+ }, [dispatch, markAll]);
122
+ var cancelJob = (0, _react.useMemo)(function () {
123
+ return new _util.Job(function () {
124
+ return doCancel();
125
+ }, 30);
126
+ }, [doCancel]);
127
+
128
+ /*
129
+ * Registers `component` with a set of handlers for `start` and `stop`.
130
+ *
131
+ * @param {Object} component A component, typically a React component instance, on
132
+ * which handlers will be dispatched.
133
+ * @param {Object} handlers An object containing `start` and `stop` functions
134
+ *
135
+ * @returns {undefined}
136
+ */
137
+ var handleRegister = (0, _react.useCallback)(function (component, handlers) {
138
+ var needStart = !allInactive() || mutableRef.current.isFocused;
139
+ mutableRef.current.controlled.push(_objectSpread(_objectSpread({}, handlers), {}, {
140
+ state: STATE.inactive,
141
+ component: component
142
+ }));
143
+ if (needStart) {
144
+ dispatch('start');
145
+ }
146
+ }, [allInactive, dispatch]);
147
+
148
+ /*
149
+ * Unregisters `component` for synchronization
150
+ *
151
+ * @param {Object} component A previously registered component
152
+ *
153
+ * @returns {undefined}
154
+ */
155
+ var handleUnregister = (0, _react.useCallback)(function (component) {
156
+ var wasRunning = false;
157
+ for (var i = 0; i < mutableRef.current.controlled.length; i++) {
158
+ if (mutableRef.current.controlled[i].component === component) {
159
+ wasRunning = mutableRef.current.controlled[i].state === STATE.active;
160
+ mutableRef.current.controlled.splice(i, 1);
161
+ break;
162
+ }
163
+ }
164
+ if (wasRunning && !anyRunning()) {
165
+ dispatch('start');
166
+ }
167
+ }, [anyRunning, dispatch]);
168
+
169
+ /*
170
+ * Handler for the `start` context function
171
+ *
172
+ * @param {Object} component A previously registered component
173
+ *
174
+ * @returns {undefined}f
175
+ */
176
+ var handleStart = (0, _react.useCallback)(function (component) {
177
+ cancelJob.stop();
178
+ if (!anyRunning()) {
179
+ markAll(STATE.ready);
180
+ dispatch('start', component);
181
+ }
182
+ }, [anyRunning, cancelJob, dispatch, markAll]);
183
+
184
+ /*
185
+ * Handler for the `cancel` context function
186
+ *
187
+ * @param {Object} component A previously registered component
188
+ *
189
+ * @returns {undefined}
190
+ */
191
+ var handleCancel = (0, _react.useCallback)(function () {
192
+ if (anyRunning()) {
193
+ cancelJob.start();
194
+ }
195
+ }, [anyRunning, cancelJob]);
196
+
197
+ /*
198
+ * Handler for the `complete` context function
199
+ *
200
+ * @param {Object} component A previously registered component
201
+ *
202
+ * @returns {undefined}
203
+ */
204
+ var handleComplete = (0, _react.useCallback)(function (component) {
205
+ var complete = markReady(component);
206
+ if (complete) {
207
+ markAll(STATE.ready);
208
+ dispatch('start');
209
+ }
210
+ }, [dispatch, markAll, markReady]);
211
+ var handleEnter = (0, _react.useCallback)(function () {
212
+ mutableRef.current.isHovered = true;
213
+ if (!anyRunning()) {
214
+ dispatch('start');
215
+ }
216
+ cancelJob.stop();
217
+ }, [anyRunning, cancelJob, dispatch]);
218
+ var handleLeave = (0, _react.useCallback)(function () {
219
+ mutableRef.current.isHovered = false;
220
+ cancelJob.start();
221
+ }, [cancelJob]);
222
+
223
+ /*
224
+ * Handler for the focus event
225
+ */
226
+ var handleFocus = (0, _react.useCallback)(function (ev) {
227
+ mutableRef.current.isFocused = true;
228
+ if (!anyRunning()) {
229
+ dispatch('start');
230
+ }
231
+ cancelJob.stop();
232
+ forwardFocus(ev, props);
233
+ }, [anyRunning, cancelJob, dispatch, props]);
234
+
235
+ /*
236
+ * Handler for the blur event
237
+ */
238
+ var handleBlur = (0, _react.useCallback)(function (ev) {
239
+ mutableRef.current.isFocused = false;
240
+ if (anyRunning()) {
241
+ cancelJob.start();
242
+ }
243
+ forwardBlur(ev, props);
244
+ }, [anyRunning, cancelJob, props]);
245
+ (0, _react.useEffect)(function () {
246
+ return function () {
247
+ cancelJob.stop();
248
+ };
249
+ }, [cancelJob]);
250
+ var value = (0, _react.useMemo)(function () {
251
+ return {
252
+ cancel: handleCancel,
253
+ complete: handleComplete,
254
+ enter: handleEnter,
255
+ leave: handleLeave,
256
+ register: handleRegister,
257
+ start: handleStart,
258
+ unregister: handleUnregister
259
+ };
260
+ }, [handleCancel, handleComplete, handleEnter, handleLeave, handleRegister, handleStart, handleUnregister]);
261
+ var provideMarqueeControllerContext = (0, _react.useCallback)(function (children) {
262
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(MarqueeControllerContext.Provider, {
263
+ value: value,
264
+ children: children
265
+ });
266
+ }, [value]);
267
+ return {
268
+ handleBlur: handleBlur,
269
+ handleFocus: handleFocus,
270
+ provideMarqueeControllerContext: provideMarqueeControllerContext
271
+ };
272
+ };
273
+ var _default = exports["default"] = useMarqueeController;