keyborg 2.3.1-canary.0 → 2.4.0

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,137 @@ 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 => {
254
+ this._onKeyDown = (e) => {
329
255
  var _a, _b;
330
-
331
256
  const isNavigatingWithKeyboard = _state.getVal();
332
-
333
257
  const keyCode = e.keyCode;
334
258
  const triggerKeys = this._triggerKeys;
335
-
336
259
  if (!isNavigatingWithKeyboard && (!triggerKeys || triggerKeys.has(keyCode))) {
337
- const activeElement = (_a = this._win) === null || _a === void 0 ? void 0 : _a.document.activeElement;
338
-
260
+ const activeElement = (_a = this._win) == null ? void 0 : _a.document.activeElement;
339
261
  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
262
  return;
343
263
  }
344
-
345
264
  _state.setVal(true);
346
- } else if (isNavigatingWithKeyboard && ((_b = this._dismissKeys) === null || _b === void 0 ? void 0 : _b.has(keyCode))) {
265
+ } else if (isNavigatingWithKeyboard && ((_b = this._dismissKeys) == null ? void 0 : _b.has(keyCode))) {
347
266
  this._scheduleDismiss();
348
267
  }
349
268
  };
350
-
351
269
  this.id = "c" + ++_lastId;
352
270
  this._win = win;
353
271
  const doc = win.document;
354
-
355
272
  if (props) {
356
273
  const triggerKeys = props.triggerKeys;
357
274
  const dismissKeys = props.dismissKeys;
358
-
359
- if (triggerKeys === null || triggerKeys === void 0 ? void 0 : triggerKeys.length) {
275
+ if (triggerKeys == null ? void 0 : triggerKeys.length) {
360
276
  this._triggerKeys = new Set(triggerKeys);
361
277
  }
362
-
363
- if (dismissKeys === null || dismissKeys === void 0 ? void 0 : dismissKeys.length) {
278
+ if (dismissKeys == null ? void 0 : dismissKeys.length) {
364
279
  this._dismissKeys = new Set(dismissKeys);
365
280
  }
366
281
  }
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
-
282
+ doc.addEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true);
283
+ doc.addEventListener("mousedown", this._onMouseDown, true);
284
+ win.addEventListener("keydown", this._onKeyDown, true);
374
285
  setupFocusEvent(win);
375
-
376
286
  _state.add(this);
377
287
  }
378
-
379
288
  dispose() {
380
289
  const win = this._win;
381
-
382
290
  if (win) {
383
291
  if (this._isMouseUsedTimer) {
384
292
  win.clearTimeout(this._isMouseUsedTimer);
385
- this._isMouseUsedTimer = undefined;
293
+ this._isMouseUsedTimer = void 0;
386
294
  }
387
-
388
295
  if (this._dismissTimer) {
389
296
  win.clearTimeout(this._dismissTimer);
390
- this._dismissTimer = undefined;
297
+ this._dismissTimer = void 0;
391
298
  }
392
-
393
299
  disposeFocusEvent(win);
394
300
  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
-
301
+ doc.removeEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true);
302
+ doc.removeEventListener("mousedown", this._onMouseDown, true);
303
+ win.removeEventListener("keydown", this._onKeyDown, true);
401
304
  delete this._win;
402
-
403
305
  _state.remove(this.id);
404
306
  }
405
307
  }
406
-
407
308
  isDisposed() {
408
309
  return !!this._win;
409
310
  }
410
- /**
411
- * Updates all keyborg instances with the keyboard navigation state
311
+ /**
312
+ * Updates all keyborg instances with the keyboard navigation state
412
313
  */
413
-
414
-
415
314
  update(isNavigatingWithKeyboard) {
416
315
  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
-
316
+ const keyborgs = (_b = (_a = this._win) == null ? void 0 : _a.__keyborg) == null ? void 0 : _b.refs;
420
317
  if (keyborgs) {
421
318
  for (const id of Object.keys(keyborgs)) {
422
319
  Keyborg.update(keyborgs[id], isNavigatingWithKeyboard);
423
320
  }
424
321
  }
425
322
  }
426
-
427
323
  _scheduleDismiss() {
428
324
  const win = this._win;
429
-
430
325
  if (win) {
431
326
  if (this._dismissTimer) {
432
327
  win.clearTimeout(this._dismissTimer);
433
- this._dismissTimer = undefined;
328
+ this._dismissTimer = void 0;
434
329
  }
435
-
436
330
  const was = win.document.activeElement;
437
331
  this._dismissTimer = win.setTimeout(() => {
438
- this._dismissTimer = undefined;
332
+ this._dismissTimer = void 0;
439
333
  const cur = win.document.activeElement;
440
-
441
334
  if (was && cur && was === cur) {
442
- // Esc was pressed, currently focused element hasn't changed.
443
- // Just dismiss the keyboard navigation mode.
444
335
  _state.setVal(false);
445
336
  }
446
337
  }, _dismissTimeout);
447
338
  }
448
339
  }
449
-
450
- }
451
- /**
452
- * Used to determine the keyboard navigation state
453
- */
454
-
455
-
456
- class Keyborg {
340
+ };
341
+ var Keyborg = class _Keyborg {
457
342
  constructor(win, props) {
458
343
  this._cb = [];
459
344
  this._id = "k" + ++_lastId;
460
345
  this._win = win;
461
346
  const current = win.__keyborg;
462
-
463
347
  if (current) {
464
348
  this._core = current.core;
465
349
  current.refs[this._id] = this;
@@ -467,88 +351,68 @@ class Keyborg {
467
351
  this._core = new KeyborgCore(win, props);
468
352
  win.__keyborg = {
469
353
  core: this._core,
470
- refs: {
471
- [this._id]: this
472
- }
354
+ refs: { [this._id]: this }
473
355
  };
474
356
  }
475
357
  }
476
-
477
358
  static create(win, props) {
478
- return new Keyborg(win, props);
359
+ return new _Keyborg(win, props);
479
360
  }
480
-
481
361
  static dispose(instance) {
482
362
  instance.dispose();
483
363
  }
484
- /**
485
- * Updates all subscribed callbacks with the keyboard navigation state
364
+ /**
365
+ * Updates all subscribed callbacks with the keyboard navigation state
486
366
  */
487
-
488
-
489
367
  static update(instance, isNavigatingWithKeyboard) {
490
- instance._cb.forEach(callback => callback(isNavigatingWithKeyboard));
368
+ instance._cb.forEach((callback) => callback(isNavigatingWithKeyboard));
491
369
  }
492
-
493
370
  dispose() {
494
371
  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]) {
372
+ const current = (_a = this._win) == null ? void 0 : _a.__keyborg;
373
+ if (current == null ? void 0 : current.refs[this._id]) {
499
374
  delete current.refs[this._id];
500
-
501
375
  if (Object.keys(current.refs).length === 0) {
502
- current.core.dispose(); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
503
-
376
+ current.core.dispose();
504
377
  delete this._win.__keyborg;
505
378
  }
506
- } else if (process.env.NODE_ENV === 'development') {
507
- console.error("Keyborg instance " + this._id + " is being disposed incorrectly.");
379
+ } else if (process.env.NODE_ENV !== "production") {
380
+ console.error(
381
+ `Keyborg instance ${this._id} is being disposed incorrectly.`
382
+ );
508
383
  }
509
-
510
384
  this._cb = [];
511
385
  delete this._core;
512
386
  delete this._win;
513
387
  }
514
- /**
515
- * @returns Whether the user is navigating with keyboard
388
+ /**
389
+ * @returns Whether the user is navigating with keyboard
516
390
  */
517
-
518
-
519
391
  isNavigatingWithKeyboard() {
520
392
  return _state.getVal();
521
393
  }
522
- /**
523
- * @param callback - Called when the keyboard navigation state changes
394
+ /**
395
+ * @param callback - Called when the keyboard navigation state changes
524
396
  */
525
-
526
-
527
397
  subscribe(callback) {
528
398
  this._cb.push(callback);
529
399
  }
530
- /**
531
- * @param callback - Registered with subscribe
400
+ /**
401
+ * @param callback - Registered with subscribe
532
402
  */
533
-
534
-
535
403
  unsubscribe(callback) {
536
404
  const index = this._cb.indexOf(callback);
537
-
538
405
  if (index >= 0) {
539
406
  this._cb.splice(index, 1);
540
407
  }
541
408
  }
542
- /**
543
- * Manually set the keyboard navigtion state
409
+ /**
410
+ * Manually set the keyboard navigtion state
544
411
  */
545
-
546
-
547
412
  setVal(isNavigatingWithKeyboard) {
548
413
  _state.setVal(isNavigatingWithKeyboard);
549
414
  }
550
-
551
- }
415
+ };
552
416
  function createKeyborg(win, props) {
553
417
  return Keyborg.create(win, props);
554
418
  }
@@ -556,17 +420,19 @@ function disposeKeyborg(instance) {
556
420
  Keyborg.dispose(instance);
557
421
  }
558
422
 
559
- /*!
560
- * Copyright (c) Microsoft Corporation. All rights reserved.
561
- * Licensed under the MIT License.
423
+ // src/index.ts
424
+ var version = "2.4.0";
425
+ // Annotate the CommonJS export names for ESM import in node:
426
+ 0 && (module.exports = {
427
+ KEYBORG_FOCUSIN,
428
+ createKeyborg,
429
+ disposeKeyborg,
430
+ getLastFocusedProgrammatically,
431
+ nativeFocus,
432
+ version
433
+ });
434
+ /*!
435
+ * Copyright (c) Microsoft Corporation. All rights reserved.
436
+ * Licensed under the MIT License.
562
437
  */
563
- const version = "2.3.1-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
438
+ //# sourceMappingURL=index.js.map