keyborg 2.4.0-canary.0 → 2.4.1

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/dist/index.js CHANGED
@@ -1,20 +1,36 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- /*!
6
- * Copyright (c) Microsoft Corporation. All rights reserved.
7
- * Licensed under the MIT License.
8
- */
9
- // IE11 compat, checks if WeakRef is supported
10
- const _canUseWeakRef = typeof WeakRef !== "undefined";
11
- /**
12
- * WeakRef wrapper around a HTMLElement that also supports IE11
13
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef}
14
- * @internal
15
- */
16
-
17
- class WeakRefInstance {
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.ts
20
+ var src_exports = {};
21
+ __export(src_exports, {
22
+ KEYBORG_FOCUSIN: () => KEYBORG_FOCUSIN,
23
+ createKeyborg: () => createKeyborg,
24
+ disposeKeyborg: () => disposeKeyborg,
25
+ getLastFocusedProgrammatically: () => getLastFocusedProgrammatically,
26
+ nativeFocus: () => nativeFocus,
27
+ version: () => version
28
+ });
29
+ module.exports = __toCommonJS(src_exports);
30
+
31
+ // src/WeakRefInstance.ts
32
+ var _canUseWeakRef = typeof WeakRef !== "undefined";
33
+ var WeakRefInstance = class {
18
34
  constructor(instance) {
19
35
  if (_canUseWeakRef && typeof instance === "object") {
20
36
  this._weakRef = new WeakRef(instance);
@@ -22,122 +38,89 @@ class WeakRefInstance {
22
38
  this._instance = instance;
23
39
  }
24
40
  }
25
- /**
26
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref}
41
+ /**
42
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref}
27
43
  */
28
-
29
-
30
44
  deref() {
31
- var _a, _b, _c;
32
-
45
+ var _a, _b;
33
46
  let instance;
34
-
35
47
  if (this._weakRef) {
36
- instance = (_a = this._weakRef) === null || _a === void 0 ? void 0 : _a.deref();
37
-
48
+ instance = (_a = this._weakRef) == null ? void 0 : _a.deref();
38
49
  if (!instance) {
39
50
  delete this._weakRef;
40
51
  }
41
52
  } else {
42
53
  instance = this._instance;
43
-
44
- if ((_c = (_b = instance) === null || _b === void 0 ? void 0 : _b.isDisposed) === null || _c === void 0 ? void 0 : _c.call(_b)) {
54
+ if ((_b = instance == null ? void 0 : instance.isDisposed) == null ? void 0 : _b.call(instance)) {
45
55
  delete this._instance;
46
56
  }
47
57
  }
48
-
49
58
  return instance;
50
59
  }
60
+ };
51
61
 
52
- }
53
-
54
- /*!
55
- * Copyright (c) Microsoft Corporation. All rights reserved.
56
- * Licensed under the MIT License.
57
- */
58
- const KEYBORG_FOCUSIN = "keyborg:focusin";
59
-
62
+ // src/FocusEvent.ts
63
+ var KEYBORG_FOCUSIN = "keyborg:focusin";
60
64
  function canOverrideNativeFocus(win) {
61
65
  const HTMLElement = win.HTMLElement;
62
66
  const origFocus = HTMLElement.prototype.focus;
63
67
  let isCustomFocusCalled = false;
64
-
65
68
  HTMLElement.prototype.focus = function focus() {
66
69
  isCustomFocusCalled = true;
67
70
  };
68
-
69
71
  const btn = win.document.createElement("button");
70
72
  btn.focus();
71
73
  HTMLElement.prototype.focus = origFocus;
72
74
  return isCustomFocusCalled;
73
75
  }
74
-
75
- let _canOverrideNativeFocus = false;
76
- /**
77
- * Guarantees that the native `focus` will be used
78
- */
79
-
76
+ var _canOverrideNativeFocus = false;
80
77
  function nativeFocus(element) {
81
78
  const focus = element.focus;
82
-
83
79
  if (focus.__keyborgNativeFocus) {
84
80
  focus.__keyborgNativeFocus.call(element);
85
81
  } else {
86
82
  element.focus();
87
83
  }
88
84
  }
89
- /**
90
- * Overrides the native `focus` and setups the keyborg focus event
91
- */
92
-
93
85
  function setupFocusEvent(win) {
94
86
  const kwin = win;
95
-
96
87
  if (!_canOverrideNativeFocus) {
97
88
  _canOverrideNativeFocus = canOverrideNativeFocus(kwin);
98
89
  }
99
-
100
90
  const origFocus = kwin.HTMLElement.prototype.focus;
101
-
102
91
  if (origFocus.__keyborgNativeFocus) {
103
- // Already set up.
104
92
  return;
105
93
  }
106
-
107
94
  kwin.HTMLElement.prototype.focus = focus;
108
-
109
- const focusOutShadowRootHandler = e => {
95
+ const focusOutShadowRootHandler = (e) => {
110
96
  const relatedTarget = e.relatedTarget;
111
- const currentTarget = e.currentTarget; // cleanup polyfill event handlers once focus leaves the shadow root
112
-
97
+ const currentTarget = e.currentTarget;
113
98
  if (!currentTarget.contains(relatedTarget)) {
114
- currentTarget.removeEventListener("focusin", focusInHandler);
115
- currentTarget.removeEventListener("focusout", focusOutShadowRootHandler);
99
+ currentTarget.removeEventListener("focusin", focusInHandler, true);
100
+ currentTarget.removeEventListener(
101
+ "focusout",
102
+ focusOutShadowRootHandler,
103
+ true
104
+ );
116
105
  }
117
106
  };
118
-
119
- const focusInHandler = e => {
107
+ const focusInHandler = (e) => {
120
108
  var _a;
121
-
122
- let target = e.target;
123
-
109
+ const target = e.target;
124
110
  if (!target) {
125
111
  return;
126
112
  }
127
-
128
113
  if (target.shadowRoot) {
129
- // https://bugs.chromium.org/p/chromium/issues/detail?id=1512028
130
- // focusin events don't bubble up through an open shadow root once focus is inside
131
- // once focus moves into a shadow root - we drop the same focusin handler there
132
- // keyborg's custom event will still bubble up since it is composed
133
- // event handlers should be cleaned up once focus leaves the shadow root
134
- target.shadowRoot.addEventListener("focusin", focusInHandler);
135
- target.shadowRoot.addEventListener("focusout", focusOutShadowRootHandler);
136
- target = e.composedPath()[0];
114
+ target.shadowRoot.addEventListener("focusin", focusInHandler, true);
115
+ target.shadowRoot.addEventListener(
116
+ "focusout",
117
+ focusOutShadowRootHandler,
118
+ true
119
+ );
120
+ return;
137
121
  }
138
-
139
122
  const details = {
140
- relatedTarget: e.relatedTarget || undefined
123
+ relatedTarget: e.relatedTarget || void 0
141
124
  };
142
125
  const event = new CustomEvent(KEYBORG_FOCUSIN, {
143
126
  cancelable: true,
@@ -145,113 +128,84 @@ function setupFocusEvent(win) {
145
128
  // Allows the event to bubble past an open shadow root
146
129
  composed: true,
147
130
  detail: details
148
- }); // Tabster (and other users) can still use the legacy details field - keeping for backwards compat
149
-
131
+ });
150
132
  event.details = details;
151
-
152
133
  if (_canOverrideNativeFocus || data.lastFocusedProgrammatically) {
153
- details.isFocusedProgrammatically = target === ((_a = data.lastFocusedProgrammatically) === null || _a === void 0 ? void 0 : _a.deref());
154
- data.lastFocusedProgrammatically = undefined;
134
+ details.isFocusedProgrammatically = target === ((_a = data.lastFocusedProgrammatically) == null ? void 0 : _a.deref());
135
+ data.lastFocusedProgrammatically = void 0;
155
136
  }
156
-
157
137
  target.dispatchEvent(event);
158
138
  };
159
-
160
139
  const data = kwin.__keyborgData = {
161
140
  focusInHandler
162
141
  };
163
- kwin.document.addEventListener("focusin", kwin.__keyborgData.focusInHandler, true);
164
-
142
+ kwin.document.addEventListener(
143
+ "focusin",
144
+ kwin.__keyborgData.focusInHandler,
145
+ true
146
+ );
165
147
  function focus() {
166
148
  const keyborgNativeFocusEvent = kwin.__keyborgData;
167
-
168
149
  if (keyborgNativeFocusEvent) {
169
- keyborgNativeFocusEvent.lastFocusedProgrammatically = new WeakRefInstance(this);
170
- } // eslint-disable-next-line prefer-rest-params
171
-
172
-
150
+ keyborgNativeFocusEvent.lastFocusedProgrammatically = new WeakRefInstance(
151
+ this
152
+ );
153
+ }
173
154
  return origFocus.apply(this, arguments);
174
155
  }
175
-
176
156
  focus.__keyborgNativeFocus = origFocus;
177
157
  }
178
- /**
179
- * Removes keyborg event listeners and custom focus override
180
- * @param win The window that stores keyborg focus events
181
- */
182
-
183
158
  function disposeFocusEvent(win) {
184
159
  const kwin = win;
185
160
  const proto = kwin.HTMLElement.prototype;
186
161
  const origFocus = proto.focus.__keyborgNativeFocus;
187
162
  const keyborgNativeFocusEvent = kwin.__keyborgData;
188
-
189
163
  if (keyborgNativeFocusEvent) {
190
- kwin.document.removeEventListener("focusin", keyborgNativeFocusEvent.focusInHandler, true);
164
+ kwin.document.removeEventListener(
165
+ "focusin",
166
+ keyborgNativeFocusEvent.focusInHandler,
167
+ true
168
+ );
191
169
  delete kwin.__keyborgData;
192
170
  }
193
-
194
171
  if (origFocus) {
195
172
  proto.focus = origFocus;
196
173
  }
197
174
  }
198
- /**
199
- * @param win The window that stores keyborg focus events
200
- * @returns The last element focused with element.focus()
201
- */
202
-
203
175
  function getLastFocusedProgrammatically(win) {
204
176
  var _a;
205
-
206
177
  const keyborgNativeFocusEvent = win.__keyborgData;
207
- return keyborgNativeFocusEvent ? ((_a = keyborgNativeFocusEvent.lastFocusedProgrammatically) === null || _a === void 0 ? void 0 : _a.deref()) || null : undefined;
178
+ return keyborgNativeFocusEvent ? ((_a = keyborgNativeFocusEvent.lastFocusedProgrammatically) == null ? void 0 : _a.deref()) || null : void 0;
208
179
  }
209
180
 
210
- /*!
211
- * Copyright (c) Microsoft Corporation. All rights reserved.
212
- * Licensed under the MIT License.
213
- */
214
- const _dismissTimeout = 500; // When a key from dismissKeys is pressed and the focus is not moved
215
- // during _dismissTimeout time, dismiss the keyboard navigation mode.
216
-
217
- let _lastId = 0;
218
- /**
219
- * Source of truth for all the keyborg core instances and the current keyboard navigation state
220
- */
221
-
222
- class KeyborgState {
181
+ // src/Keyborg.ts
182
+ var _dismissTimeout = 500;
183
+ var _lastId = 0;
184
+ var KeyborgState = class {
223
185
  constructor() {
224
186
  this.__keyborgCoreRefs = {};
225
187
  this._isNavigatingWithKeyboard = false;
226
188
  }
227
-
228
189
  add(keyborg) {
229
190
  const id = keyborg.id;
230
-
231
191
  if (!(id in this.__keyborgCoreRefs)) {
232
192
  this.__keyborgCoreRefs[id] = new WeakRefInstance(keyborg);
233
193
  }
234
194
  }
235
-
236
195
  remove(id) {
237
196
  delete this.__keyborgCoreRefs[id];
238
-
239
197
  if (Object.keys(this.__keyborgCoreRefs).length === 0) {
240
198
  this._isNavigatingWithKeyboard = false;
241
199
  }
242
200
  }
243
-
244
201
  setVal(isNavigatingWithKeyboard) {
245
202
  if (this._isNavigatingWithKeyboard === isNavigatingWithKeyboard) {
246
203
  return;
247
204
  }
248
-
249
205
  this._isNavigatingWithKeyboard = isNavigatingWithKeyboard;
250
-
251
206
  for (const id of Object.keys(this.__keyborgCoreRefs)) {
252
207
  const ref = this.__keyborgCoreRefs[id];
253
208
  const keyborg = ref.deref();
254
-
255
209
  if (keyborg) {
256
210
  keyborg.update(isNavigatingWithKeyboard);
257
211
  } else {
@@ -259,207 +213,154 @@ class KeyborgState {
259
213
  }
260
214
  }
261
215
  }
262
-
263
216
  getVal() {
264
217
  return this._isNavigatingWithKeyboard;
265
218
  }
266
-
267
- }
268
-
269
- const _state = /*#__PURE__*/new KeyborgState();
270
- /**
271
- * Manages a collection of Keyborg instances in a window/document and updates keyborg state
272
- */
273
-
274
-
275
- class KeyborgCore {
219
+ };
220
+ var _state = new KeyborgState();
221
+ var KeyborgCore = class {
276
222
  constructor(win, props) {
277
- this._onFocusIn = e => {
278
- // When the focus is moved not programmatically and without keydown events,
279
- // it is likely that the focus is moved by screen reader (as it might swallow
280
- // the events when the screen reader shortcuts are used). The screen reader
281
- // usage is keyboard navigation.
223
+ this._onFocusIn = (e) => {
282
224
  if (this._isMouseUsedTimer) {
283
- // There was a mouse event recently.
284
225
  return;
285
226
  }
286
-
287
227
  if (_state.getVal()) {
288
228
  return;
289
229
  }
290
-
291
230
  const details = e.detail;
292
-
293
231
  if (!details.relatedTarget) {
294
232
  return;
295
233
  }
296
-
297
- if (details.isFocusedProgrammatically || details.isFocusedProgrammatically === undefined) {
298
- // The element is focused programmatically, or the programmatic focus detection
299
- // is not working.
234
+ if (details.isFocusedProgrammatically || details.isFocusedProgrammatically === void 0) {
300
235
  return;
301
236
  }
302
-
303
237
  _state.setVal(true);
304
238
  };
305
-
306
- this._onMouseDown = e => {
239
+ this._onMouseDown = (e) => {
307
240
  if (e.buttons === 0 || e.clientX === 0 && e.clientY === 0 && e.screenX === 0 && e.screenY === 0) {
308
- // This is most likely an event triggered by the screen reader to perform
309
- // an action on an element, do not dismiss the keyboard navigation mode.
310
241
  return;
311
242
  }
312
-
313
243
  const win = this._win;
314
-
315
244
  if (win) {
316
245
  if (this._isMouseUsedTimer) {
317
246
  win.clearTimeout(this._isMouseUsedTimer);
318
247
  }
319
-
320
248
  this._isMouseUsedTimer = win.setTimeout(() => {
321
249
  delete this._isMouseUsedTimer;
322
- }, 1000); // Keeping the indication of the mouse usage for some time.
250
+ }, 1e3);
323
251
  }
324
-
325
252
  _state.setVal(false);
326
253
  };
327
-
328
- this._onKeyDown = e => {
329
- var _a, _b;
330
-
254
+ this._onKeyDown = (e) => {
331
255
  const isNavigatingWithKeyboard = _state.getVal();
332
-
333
- const keyCode = e.keyCode;
334
- const triggerKeys = this._triggerKeys;
335
-
336
- if (!isNavigatingWithKeyboard && (!triggerKeys || triggerKeys.has(keyCode))) {
337
- const activeElement = (_a = this._win) === null || _a === void 0 ? void 0 : _a.document.activeElement;
338
-
339
- if (activeElement && (activeElement.tagName === "INPUT" || activeElement.tagName === "TEXTAREA" || activeElement.contentEditable === "true")) {
340
- // We're inside an input, textarea or contenteditable, it's not
341
- // keyboard navigation, it is text editing scenario.
342
- return;
256
+ if (isNavigatingWithKeyboard) {
257
+ if (this._shouldDismissKeyboardNavigation(e)) {
258
+ this._scheduleDismiss();
259
+ }
260
+ } else {
261
+ if (this._shouldTriggerKeyboardNavigation(e)) {
262
+ _state.setVal(true);
343
263
  }
344
-
345
- _state.setVal(true);
346
- } else if (isNavigatingWithKeyboard && ((_b = this._dismissKeys) === null || _b === void 0 ? void 0 : _b.has(keyCode))) {
347
- this._scheduleDismiss();
348
264
  }
349
265
  };
350
-
351
266
  this.id = "c" + ++_lastId;
352
267
  this._win = win;
353
268
  const doc = win.document;
354
-
355
269
  if (props) {
356
270
  const triggerKeys = props.triggerKeys;
357
271
  const dismissKeys = props.dismissKeys;
358
-
359
- if (triggerKeys === null || triggerKeys === void 0 ? void 0 : triggerKeys.length) {
272
+ if (triggerKeys == null ? void 0 : triggerKeys.length) {
360
273
  this._triggerKeys = new Set(triggerKeys);
361
274
  }
362
-
363
- if (dismissKeys === null || dismissKeys === void 0 ? void 0 : dismissKeys.length) {
275
+ if (dismissKeys == null ? void 0 : dismissKeys.length) {
364
276
  this._dismissKeys = new Set(dismissKeys);
365
277
  }
366
278
  }
367
-
368
- doc.addEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true); // Capture!
369
-
370
- doc.addEventListener("mousedown", this._onMouseDown, true); // Capture!
371
-
372
- win.addEventListener("keydown", this._onKeyDown, true); // Capture!
373
-
279
+ doc.addEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true);
280
+ doc.addEventListener("mousedown", this._onMouseDown, true);
281
+ win.addEventListener("keydown", this._onKeyDown, true);
374
282
  setupFocusEvent(win);
375
-
376
283
  _state.add(this);
377
284
  }
378
-
379
285
  dispose() {
380
286
  const win = this._win;
381
-
382
287
  if (win) {
383
288
  if (this._isMouseUsedTimer) {
384
289
  win.clearTimeout(this._isMouseUsedTimer);
385
- this._isMouseUsedTimer = undefined;
290
+ this._isMouseUsedTimer = void 0;
386
291
  }
387
-
388
292
  if (this._dismissTimer) {
389
293
  win.clearTimeout(this._dismissTimer);
390
- this._dismissTimer = undefined;
294
+ this._dismissTimer = void 0;
391
295
  }
392
-
393
296
  disposeFocusEvent(win);
394
297
  const doc = win.document;
395
- doc.removeEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true); // Capture!
396
-
397
- doc.removeEventListener("mousedown", this._onMouseDown, true); // Capture!
398
-
399
- win.removeEventListener("keydown", this._onKeyDown, true); // Capture!
400
-
298
+ doc.removeEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true);
299
+ doc.removeEventListener("mousedown", this._onMouseDown, true);
300
+ win.removeEventListener("keydown", this._onKeyDown, true);
401
301
  delete this._win;
402
-
403
302
  _state.remove(this.id);
404
303
  }
405
304
  }
406
-
407
305
  isDisposed() {
408
306
  return !!this._win;
409
307
  }
410
- /**
411
- * Updates all keyborg instances with the keyboard navigation state
308
+ /**
309
+ * Updates all keyborg instances with the keyboard navigation state
412
310
  */
413
-
414
-
415
311
  update(isNavigatingWithKeyboard) {
416
312
  var _a, _b;
417
-
418
- const keyborgs = (_b = (_a = this._win) === null || _a === void 0 ? void 0 : _a.__keyborg) === null || _b === void 0 ? void 0 : _b.refs;
419
-
313
+ const keyborgs = (_b = (_a = this._win) == null ? void 0 : _a.__keyborg) == null ? void 0 : _b.refs;
420
314
  if (keyborgs) {
421
315
  for (const id of Object.keys(keyborgs)) {
422
316
  Keyborg.update(keyborgs[id], isNavigatingWithKeyboard);
423
317
  }
424
318
  }
425
319
  }
426
-
320
+ /**
321
+ * @returns whether the keyboard event should trigger keyboard navigation mode
322
+ */
323
+ _shouldTriggerKeyboardNavigation(e) {
324
+ var _a;
325
+ if (e.key === "Tab") {
326
+ return true;
327
+ }
328
+ const activeElement = (_a = this._win) == null ? void 0 : _a.document.activeElement;
329
+ const isTriggerKey = !this._triggerKeys || this._triggerKeys.has(e.keyCode);
330
+ const isEditable = activeElement && (activeElement.tagName === "INPUT" || activeElement.tagName === "TEXTAREA" || activeElement.isContentEditable);
331
+ return isTriggerKey && !isEditable;
332
+ }
333
+ /**
334
+ * @returns whether the keyboard event should dismiss keyboard navigation mode
335
+ */
336
+ _shouldDismissKeyboardNavigation(e) {
337
+ var _a;
338
+ return (_a = this._dismissKeys) == null ? void 0 : _a.has(e.keyCode);
339
+ }
427
340
  _scheduleDismiss() {
428
341
  const win = this._win;
429
-
430
342
  if (win) {
431
343
  if (this._dismissTimer) {
432
344
  win.clearTimeout(this._dismissTimer);
433
- this._dismissTimer = undefined;
345
+ this._dismissTimer = void 0;
434
346
  }
435
-
436
347
  const was = win.document.activeElement;
437
348
  this._dismissTimer = win.setTimeout(() => {
438
- this._dismissTimer = undefined;
349
+ this._dismissTimer = void 0;
439
350
  const cur = win.document.activeElement;
440
-
441
351
  if (was && cur && was === cur) {
442
- // Esc was pressed, currently focused element hasn't changed.
443
- // Just dismiss the keyboard navigation mode.
444
352
  _state.setVal(false);
445
353
  }
446
354
  }, _dismissTimeout);
447
355
  }
448
356
  }
449
-
450
- }
451
- /**
452
- * Used to determine the keyboard navigation state
453
- */
454
-
455
-
456
- class Keyborg {
357
+ };
358
+ var Keyborg = class _Keyborg {
457
359
  constructor(win, props) {
458
360
  this._cb = [];
459
361
  this._id = "k" + ++_lastId;
460
362
  this._win = win;
461
363
  const current = win.__keyborg;
462
-
463
364
  if (current) {
464
365
  this._core = current.core;
465
366
  current.refs[this._id] = this;
@@ -467,88 +368,68 @@ class Keyborg {
467
368
  this._core = new KeyborgCore(win, props);
468
369
  win.__keyborg = {
469
370
  core: this._core,
470
- refs: {
471
- [this._id]: this
472
- }
371
+ refs: { [this._id]: this }
473
372
  };
474
373
  }
475
374
  }
476
-
477
375
  static create(win, props) {
478
- return new Keyborg(win, props);
376
+ return new _Keyborg(win, props);
479
377
  }
480
-
481
378
  static dispose(instance) {
482
379
  instance.dispose();
483
380
  }
484
- /**
485
- * Updates all subscribed callbacks with the keyboard navigation state
381
+ /**
382
+ * Updates all subscribed callbacks with the keyboard navigation state
486
383
  */
487
-
488
-
489
384
  static update(instance, isNavigatingWithKeyboard) {
490
- instance._cb.forEach(callback => callback(isNavigatingWithKeyboard));
385
+ instance._cb.forEach((callback) => callback(isNavigatingWithKeyboard));
491
386
  }
492
-
493
387
  dispose() {
494
388
  var _a;
495
-
496
- const current = (_a = this._win) === null || _a === void 0 ? void 0 : _a.__keyborg;
497
-
498
- if (current === null || current === void 0 ? void 0 : current.refs[this._id]) {
389
+ const current = (_a = this._win) == null ? void 0 : _a.__keyborg;
390
+ if (current == null ? void 0 : current.refs[this._id]) {
499
391
  delete current.refs[this._id];
500
-
501
392
  if (Object.keys(current.refs).length === 0) {
502
- current.core.dispose(); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
503
-
393
+ current.core.dispose();
504
394
  delete this._win.__keyborg;
505
395
  }
506
- } else if (process.env.NODE_ENV === 'development') {
507
- console.error("Keyborg instance " + this._id + " is being disposed incorrectly.");
396
+ } else if (process.env.NODE_ENV !== "production") {
397
+ console.error(
398
+ `Keyborg instance ${this._id} is being disposed incorrectly.`
399
+ );
508
400
  }
509
-
510
401
  this._cb = [];
511
402
  delete this._core;
512
403
  delete this._win;
513
404
  }
514
- /**
515
- * @returns Whether the user is navigating with keyboard
405
+ /**
406
+ * @returns Whether the user is navigating with keyboard
516
407
  */
517
-
518
-
519
408
  isNavigatingWithKeyboard() {
520
409
  return _state.getVal();
521
410
  }
522
- /**
523
- * @param callback - Called when the keyboard navigation state changes
411
+ /**
412
+ * @param callback - Called when the keyboard navigation state changes
524
413
  */
525
-
526
-
527
414
  subscribe(callback) {
528
415
  this._cb.push(callback);
529
416
  }
530
- /**
531
- * @param callback - Registered with subscribe
417
+ /**
418
+ * @param callback - Registered with subscribe
532
419
  */
533
-
534
-
535
420
  unsubscribe(callback) {
536
421
  const index = this._cb.indexOf(callback);
537
-
538
422
  if (index >= 0) {
539
423
  this._cb.splice(index, 1);
540
424
  }
541
425
  }
542
- /**
543
- * Manually set the keyboard navigtion state
426
+ /**
427
+ * Manually set the keyboard navigtion state
544
428
  */
545
-
546
-
547
429
  setVal(isNavigatingWithKeyboard) {
548
430
  _state.setVal(isNavigatingWithKeyboard);
549
431
  }
550
-
551
- }
432
+ };
552
433
  function createKeyborg(win, props) {
553
434
  return Keyborg.create(win, props);
554
435
  }
@@ -556,17 +437,19 @@ function disposeKeyborg(instance) {
556
437
  Keyborg.dispose(instance);
557
438
  }
558
439
 
559
- /*!
560
- * Copyright (c) Microsoft Corporation. All rights reserved.
561
- * Licensed under the MIT License.
440
+ // src/index.ts
441
+ var version = "2.4.1";
442
+ // Annotate the CommonJS export names for ESM import in node:
443
+ 0 && (module.exports = {
444
+ KEYBORG_FOCUSIN,
445
+ createKeyborg,
446
+ disposeKeyborg,
447
+ getLastFocusedProgrammatically,
448
+ nativeFocus,
449
+ version
450
+ });
451
+ /*!
452
+ * Copyright (c) Microsoft Corporation. All rights reserved.
453
+ * Licensed under the MIT License.
562
454
  */
563
- const version = "2.4.0-canary.0";
564
-
565
- exports.KEYBORG_FOCUSIN = KEYBORG_FOCUSIN;
566
- exports.Keyborg = Keyborg;
567
- exports.createKeyborg = createKeyborg;
568
- exports.disposeKeyborg = disposeKeyborg;
569
- exports.getLastFocusedProgrammatically = getLastFocusedProgrammatically;
570
- exports.nativeFocus = nativeFocus;
571
- exports.version = version;
572
- //# sourceMappingURL=index.js.map
455
+ //# sourceMappingURL=index.js.map