Private
Public Access
1
0

feat: Fluent UI Outlook Lite + connections mockup

This commit is contained in:
2026-04-14 18:52:25 +00:00
parent 1199eff6c3
commit dfa4010406
34820 changed files with 1003813 additions and 205 deletions

21
node_modules/keyborg/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) Microsoft Corporation.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE

66
node_modules/keyborg/README.md generated vendored Normal file
View File

@@ -0,0 +1,66 @@
# Keyborg ⌨️🤖
Keyborg is a library that tracks the state of current keyboard input on a web page through focus events.
**It does not do anything invasive to the DOM** but provides an event subscription system that allows users to choose how they want to react to changes in focus.
## Getting started
### Installation
```bash
# NPM
npm install --save keyborg
# Yarn
yarn add keyborg
```
### Usage
```js
import { createKeyborg } from "keyborg";
// initializes keyborg on the current window
const keyborg = createKeyborg(window);
// This is called every time the keyboard input state changes
const handler = (isUsingKeyboard) => {
if (isUsingKeyboard) {
document.body.setAttribute("data-is-keyboard", "true");
} else {
document.body.removeAttribute("data-is-keyboard");
}
};
keyborg.subscribe(handler);
keyborg.unsubscribe(handler);
```
## Contributing
Pretty simple currently, you only need to know about theese commands
- `npm install` - install dependencies
- `npm run build` - builds the library
- `npm run format:fix` - runs prettier to format code
- `npm run lint:fix` - runs eslint and fixes issues
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
## Trademarks
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
trademarks or logos is subject to and must follow
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.

474
node_modules/keyborg/dist/esm/index.js generated vendored Normal file
View File

@@ -0,0 +1,474 @@
// src/WeakRefInstance.ts
var _canUseWeakRef = typeof WeakRef !== "undefined";
var WeakRefInstance = class {
constructor(instance) {
if (_canUseWeakRef && typeof instance === "object") {
this._weakRef = new WeakRef(instance);
} else {
this._instance = instance;
}
}
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref}
*/
deref() {
var _a, _b;
let instance;
if (this._weakRef) {
instance = (_a = this._weakRef) == null ? void 0 : _a.deref();
if (!instance) {
delete this._weakRef;
}
} else {
instance = this._instance;
if ((_b = instance == null ? void 0 : instance.isDisposed) == null ? void 0 : _b.call(instance)) {
delete this._instance;
}
}
return instance;
}
};
// src/FocusEvent.ts
var KEYBORG_FOCUSIN = "keyborg:focusin";
var KEYBORG_FOCUSOUT = "keyborg:focusout";
function canOverrideNativeFocus(win) {
const HTMLElement = win.HTMLElement;
const origFocus = HTMLElement.prototype.focus;
let isCustomFocusCalled = false;
HTMLElement.prototype.focus = function focus() {
isCustomFocusCalled = true;
};
const btn = win.document.createElement("button");
btn.focus();
HTMLElement.prototype.focus = origFocus;
return isCustomFocusCalled;
}
var _canOverrideNativeFocus = false;
function nativeFocus(element) {
const focus = element.focus;
if (focus.__keyborgNativeFocus) {
focus.__keyborgNativeFocus.call(element);
} else {
element.focus();
}
}
function setupFocusEvent(win) {
const kwin = win;
if (!_canOverrideNativeFocus) {
_canOverrideNativeFocus = canOverrideNativeFocus(kwin);
}
const origFocus = kwin.HTMLElement.prototype.focus;
if (origFocus.__keyborgNativeFocus) {
return;
}
kwin.HTMLElement.prototype.focus = focus;
const shadowTargets = /* @__PURE__ */ new Set();
const focusOutHandler = (e) => {
const target = e.target;
if (!target) {
return;
}
const event = new CustomEvent(KEYBORG_FOCUSOUT, {
cancelable: true,
bubbles: true,
// Allows the event to bubble past an open shadow root
composed: true,
detail: {
originalEvent: e
}
});
target.dispatchEvent(event);
};
const focusInHandler = (e) => {
const target = e.target;
if (!target) {
return;
}
let node = e.composedPath()[0];
const currentShadows = /* @__PURE__ */ new Set();
while (node) {
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
currentShadows.add(node);
node = node.host;
} else {
node = node.parentNode;
}
}
for (const shadowRootWeakRef of shadowTargets) {
const shadowRoot = shadowRootWeakRef.deref();
if (!shadowRoot || !currentShadows.has(shadowRoot)) {
shadowTargets.delete(shadowRootWeakRef);
if (shadowRoot) {
shadowRoot.removeEventListener("focusin", focusInHandler, true);
shadowRoot.removeEventListener("focusout", focusOutHandler, true);
}
}
}
onFocusIn(target, e.relatedTarget || void 0);
};
const onFocusIn = (target, relatedTarget, originalEvent) => {
var _a;
const shadowRoot = target.shadowRoot;
if (shadowRoot) {
for (const shadowRootWeakRef of shadowTargets) {
if (shadowRootWeakRef.deref() === shadowRoot) {
return;
}
}
shadowRoot.addEventListener("focusin", focusInHandler, true);
shadowRoot.addEventListener("focusout", focusOutHandler, true);
shadowTargets.add(new WeakRefInstance(shadowRoot));
return;
}
const details = {
relatedTarget,
originalEvent
};
const event = new CustomEvent(KEYBORG_FOCUSIN, {
cancelable: true,
bubbles: true,
// Allows the event to bubble past an open shadow root
composed: true,
detail: details
});
event.details = details;
if (_canOverrideNativeFocus || data.lastFocusedProgrammatically) {
details.isFocusedProgrammatically = target === ((_a = data.lastFocusedProgrammatically) == null ? void 0 : _a.deref());
data.lastFocusedProgrammatically = void 0;
}
target.dispatchEvent(event);
};
const data = kwin.__keyborgData = {
focusInHandler,
focusOutHandler,
shadowTargets
};
kwin.document.addEventListener(
"focusin",
kwin.__keyborgData.focusInHandler,
true
);
kwin.document.addEventListener(
"focusout",
kwin.__keyborgData.focusOutHandler,
true
);
function focus() {
const keyborgNativeFocusEvent = kwin.__keyborgData;
if (keyborgNativeFocusEvent) {
keyborgNativeFocusEvent.lastFocusedProgrammatically = new WeakRefInstance(
this
);
}
return origFocus.apply(this, arguments);
}
let activeElement = kwin.document.activeElement;
while (activeElement && activeElement.shadowRoot) {
onFocusIn(activeElement);
activeElement = activeElement.shadowRoot.activeElement;
}
focus.__keyborgNativeFocus = origFocus;
}
function disposeFocusEvent(win) {
const kwin = win;
const proto = kwin.HTMLElement.prototype;
const origFocus = proto.focus.__keyborgNativeFocus;
const keyborgNativeFocusEvent = kwin.__keyborgData;
if (keyborgNativeFocusEvent) {
kwin.document.removeEventListener(
"focusin",
keyborgNativeFocusEvent.focusInHandler,
true
);
kwin.document.removeEventListener(
"focusout",
keyborgNativeFocusEvent.focusOutHandler,
true
);
for (const shadowRootWeakRef of keyborgNativeFocusEvent.shadowTargets) {
const shadowRoot = shadowRootWeakRef.deref();
if (shadowRoot) {
shadowRoot.removeEventListener(
"focusin",
keyborgNativeFocusEvent.focusInHandler,
true
);
shadowRoot.removeEventListener(
"focusout",
keyborgNativeFocusEvent.focusOutHandler,
true
);
}
}
keyborgNativeFocusEvent.shadowTargets.clear();
delete kwin.__keyborgData;
}
if (origFocus) {
proto.focus = origFocus;
}
}
function getLastFocusedProgrammatically(win) {
var _a;
const keyborgNativeFocusEvent = win.__keyborgData;
return keyborgNativeFocusEvent ? ((_a = keyborgNativeFocusEvent.lastFocusedProgrammatically) == null ? void 0 : _a.deref()) || null : void 0;
}
// src/Keyborg.ts
var _dismissTimeout = 500;
var _lastId = 0;
var KeyborgCore = class {
constructor(win, props) {
this._isNavigatingWithKeyboard_DO_NOT_USE = false;
this._onFocusIn = (e) => {
if (this._isMouseOrTouchUsedTimer) {
return;
}
if (this.isNavigatingWithKeyboard) {
return;
}
const details = e.detail;
if (!details.relatedTarget) {
return;
}
if (details.isFocusedProgrammatically || details.isFocusedProgrammatically === void 0) {
return;
}
this.isNavigatingWithKeyboard = true;
};
this._onMouseDown = (e) => {
if (e.buttons === 0 || e.clientX === 0 && e.clientY === 0 && e.screenX === 0 && e.screenY === 0) {
return;
}
this._onMouseOrTouch();
};
this._onMouseOrTouch = () => {
const win = this._win;
if (win) {
if (this._isMouseOrTouchUsedTimer) {
win.clearTimeout(this._isMouseOrTouchUsedTimer);
}
this._isMouseOrTouchUsedTimer = win.setTimeout(() => {
delete this._isMouseOrTouchUsedTimer;
}, 1e3);
}
this.isNavigatingWithKeyboard = false;
};
this._onKeyDown = (e) => {
const isNavigatingWithKeyboard = this.isNavigatingWithKeyboard;
if (isNavigatingWithKeyboard) {
if (this._shouldDismissKeyboardNavigation(e)) {
this._scheduleDismiss();
}
} else {
if (this._shouldTriggerKeyboardNavigation(e)) {
this.isNavigatingWithKeyboard = true;
}
}
};
this.id = "c" + ++_lastId;
this._win = win;
const doc = win.document;
if (props) {
const triggerKeys = props.triggerKeys;
const dismissKeys = props.dismissKeys;
if (triggerKeys == null ? void 0 : triggerKeys.length) {
this._triggerKeys = new Set(triggerKeys);
}
if (dismissKeys == null ? void 0 : dismissKeys.length) {
this._dismissKeys = new Set(dismissKeys);
}
}
doc.addEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true);
doc.addEventListener("mousedown", this._onMouseDown, true);
win.addEventListener("keydown", this._onKeyDown, true);
doc.addEventListener("touchstart", this._onMouseOrTouch, true);
doc.addEventListener("touchend", this._onMouseOrTouch, true);
doc.addEventListener("touchcancel", this._onMouseOrTouch, true);
setupFocusEvent(win);
}
get isNavigatingWithKeyboard() {
return this._isNavigatingWithKeyboard_DO_NOT_USE;
}
set isNavigatingWithKeyboard(val) {
if (this._isNavigatingWithKeyboard_DO_NOT_USE !== val) {
this._isNavigatingWithKeyboard_DO_NOT_USE = val;
this.update();
}
}
dispose() {
const win = this._win;
if (win) {
if (this._isMouseOrTouchUsedTimer) {
win.clearTimeout(this._isMouseOrTouchUsedTimer);
this._isMouseOrTouchUsedTimer = void 0;
}
if (this._dismissTimer) {
win.clearTimeout(this._dismissTimer);
this._dismissTimer = void 0;
}
disposeFocusEvent(win);
const doc = win.document;
doc.removeEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true);
doc.removeEventListener("mousedown", this._onMouseDown, true);
win.removeEventListener("keydown", this._onKeyDown, true);
doc.removeEventListener("touchstart", this._onMouseOrTouch, true);
doc.removeEventListener("touchend", this._onMouseOrTouch, true);
doc.removeEventListener("touchcancel", this._onMouseOrTouch, true);
delete this._win;
}
}
isDisposed() {
return !!this._win;
}
/**
* Updates all keyborg instances with the keyboard navigation state
*/
update() {
var _a, _b;
const keyborgs = (_b = (_a = this._win) == null ? void 0 : _a.__keyborg) == null ? void 0 : _b.refs;
if (keyborgs) {
for (const id of Object.keys(keyborgs)) {
Keyborg.update(keyborgs[id], this.isNavigatingWithKeyboard);
}
}
}
/**
* @returns whether the keyboard event should trigger keyboard navigation mode
*/
_shouldTriggerKeyboardNavigation(e) {
var _a;
if (e.key === "Tab") {
return true;
}
const activeElement = (_a = this._win) == null ? void 0 : _a.document.activeElement;
const isTriggerKey = !this._triggerKeys || this._triggerKeys.has(e.keyCode);
const isEditable = activeElement && (activeElement.tagName === "INPUT" || activeElement.tagName === "TEXTAREA" || activeElement.isContentEditable);
return isTriggerKey && !isEditable;
}
/**
* @returns whether the keyboard event should dismiss keyboard navigation mode
*/
_shouldDismissKeyboardNavigation(e) {
var _a;
return (_a = this._dismissKeys) == null ? void 0 : _a.has(e.keyCode);
}
_scheduleDismiss() {
const win = this._win;
if (win) {
if (this._dismissTimer) {
win.clearTimeout(this._dismissTimer);
this._dismissTimer = void 0;
}
const was = win.document.activeElement;
this._dismissTimer = win.setTimeout(() => {
this._dismissTimer = void 0;
const cur = win.document.activeElement;
if (was && cur && was === cur) {
this.isNavigatingWithKeyboard = false;
}
}, _dismissTimeout);
}
}
};
var Keyborg = class _Keyborg {
constructor(win, props) {
this._cb = [];
this._id = "k" + ++_lastId;
this._win = win;
const current = win.__keyborg;
if (current) {
this._core = current.core;
current.refs[this._id] = this;
} else {
this._core = new KeyborgCore(win, props);
win.__keyborg = {
core: this._core,
refs: { [this._id]: this }
};
}
}
static create(win, props) {
return new _Keyborg(win, props);
}
static dispose(instance) {
instance.dispose();
}
/**
* Updates all subscribed callbacks with the keyboard navigation state
*/
static update(instance, isNavigatingWithKeyboard) {
instance._cb.forEach((callback) => callback(isNavigatingWithKeyboard));
}
dispose() {
var _a;
const current = (_a = this._win) == null ? void 0 : _a.__keyborg;
if (current == null ? void 0 : current.refs[this._id]) {
delete current.refs[this._id];
if (Object.keys(current.refs).length === 0) {
current.core.dispose();
delete this._win.__keyborg;
}
} else if (process.env.NODE_ENV !== "production") {
console.error(
`Keyborg instance ${this._id} is being disposed incorrectly.`
);
}
this._cb = [];
delete this._core;
delete this._win;
}
/**
* @returns Whether the user is navigating with keyboard
*/
isNavigatingWithKeyboard() {
var _a;
return !!((_a = this._core) == null ? void 0 : _a.isNavigatingWithKeyboard);
}
/**
* @param callback - Called when the keyboard navigation state changes
*/
subscribe(callback) {
this._cb.push(callback);
}
/**
* @param callback - Registered with subscribe
*/
unsubscribe(callback) {
const index = this._cb.indexOf(callback);
if (index >= 0) {
this._cb.splice(index, 1);
}
}
/**
* Manually set the keyboard navigtion state
*/
setVal(isNavigatingWithKeyboard) {
if (this._core) {
this._core.isNavigatingWithKeyboard = isNavigatingWithKeyboard;
}
}
};
function createKeyborg(win, props) {
return Keyborg.create(win, props);
}
function disposeKeyborg(instance) {
Keyborg.dispose(instance);
}
// src/index.ts
var version = "2.6.0";
export {
KEYBORG_FOCUSIN,
KEYBORG_FOCUSOUT,
createKeyborg,
disposeKeyborg,
getLastFocusedProgrammatically,
nativeFocus,
version
};
/*!
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
//# sourceMappingURL=index.js.map

1
node_modules/keyborg/dist/esm/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

130
node_modules/keyborg/dist/index.d.mts generated vendored Normal file
View File

@@ -0,0 +1,130 @@
/**
* Allows disposable instances to be used
*/
interface Disposable {
isDisposed?(): boolean;
}
/*!
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
interface WindowWithKeyborg extends Window {
__keyborg?: {
core: KeyborgCore;
refs: {
[id: string]: Keyborg;
};
};
}
interface KeyborgProps {
triggerKeys?: number[];
dismissKeys?: number[];
}
type KeyborgCallback = (isNavigatingWithKeyboard: boolean) => void;
/**
* Manages a collection of Keyborg instances in a window/document and updates keyborg state
*/
declare class KeyborgCore implements Disposable {
readonly id: string;
private _win?;
private _isMouseOrTouchUsedTimer;
private _dismissTimer;
private _triggerKeys?;
private _dismissKeys?;
private _isNavigatingWithKeyboard_DO_NOT_USE;
constructor(win: WindowWithKeyborg, props?: KeyborgProps);
get isNavigatingWithKeyboard(): boolean;
set isNavigatingWithKeyboard(val: boolean);
dispose(): void;
isDisposed(): boolean;
/**
* Updates all keyborg instances with the keyboard navigation state
*/
update(): void;
private _onFocusIn;
private _onMouseDown;
private _onMouseOrTouch;
private _onKeyDown;
/**
* @returns whether the keyboard event should trigger keyboard navigation mode
*/
private _shouldTriggerKeyboardNavigation;
/**
* @returns whether the keyboard event should dismiss keyboard navigation mode
*/
private _shouldDismissKeyboardNavigation;
private _scheduleDismiss;
}
/**
* Used to determine the keyboard navigation state
*/
declare class Keyborg {
private _id;
private _win?;
private _core?;
private _cb;
static create(win: WindowWithKeyborg, props?: KeyborgProps): Keyborg;
static dispose(instance: Keyborg): void;
/**
* Updates all subscribed callbacks with the keyboard navigation state
*/
static update(instance: Keyborg, isNavigatingWithKeyboard: boolean): void;
private constructor();
private dispose;
/**
* @returns Whether the user is navigating with keyboard
*/
isNavigatingWithKeyboard(): boolean;
/**
* @param callback - Called when the keyboard navigation state changes
*/
subscribe(callback: KeyborgCallback): void;
/**
* @param callback - Registered with subscribe
*/
unsubscribe(callback: KeyborgCallback): void;
/**
* Manually set the keyboard navigtion state
*/
setVal(isNavigatingWithKeyboard: boolean): void;
}
declare function createKeyborg(win: Window, props?: KeyborgProps): Keyborg;
declare function disposeKeyborg(instance: Keyborg): void;
declare const KEYBORG_FOCUSIN = "keyborg:focusin";
declare const KEYBORG_FOCUSOUT = "keyborg:focusout";
interface KeyborgFocusInEventDetails {
relatedTarget?: HTMLElement;
isFocusedProgrammatically?: boolean;
originalEvent?: FocusEvent;
}
interface KeyborgFocusInEvent extends CustomEvent<KeyborgFocusInEventDetails> {
/**
* @deprecated - used `event.detail`
*/
details?: KeyborgFocusInEventDetails;
}
interface KeyborgFocusOutEventDetails {
originalEvent: FocusEvent;
}
type KeyborgFocusOutEvent = CustomEvent<KeyborgFocusOutEventDetails>;
/**
* Guarantees that the native `focus` will be used
*/
declare function nativeFocus(element: HTMLElement): void;
/**
* @param win The window that stores keyborg focus events
* @returns The last element focused with element.focus()
*/
declare function getLastFocusedProgrammatically(win: Window): HTMLElement | null | undefined;
/*!
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
declare const version: string | undefined;
export { KEYBORG_FOCUSIN, KEYBORG_FOCUSOUT, Keyborg, type KeyborgCallback, type KeyborgFocusInEvent, type KeyborgFocusInEventDetails, type KeyborgFocusOutEvent, type KeyborgFocusOutEventDetails, createKeyborg, disposeKeyborg, getLastFocusedProgrammatically, nativeFocus, version };

130
node_modules/keyborg/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,130 @@
/**
* Allows disposable instances to be used
*/
interface Disposable {
isDisposed?(): boolean;
}
/*!
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
interface WindowWithKeyborg extends Window {
__keyborg?: {
core: KeyborgCore;
refs: {
[id: string]: Keyborg;
};
};
}
interface KeyborgProps {
triggerKeys?: number[];
dismissKeys?: number[];
}
type KeyborgCallback = (isNavigatingWithKeyboard: boolean) => void;
/**
* Manages a collection of Keyborg instances in a window/document and updates keyborg state
*/
declare class KeyborgCore implements Disposable {
readonly id: string;
private _win?;
private _isMouseOrTouchUsedTimer;
private _dismissTimer;
private _triggerKeys?;
private _dismissKeys?;
private _isNavigatingWithKeyboard_DO_NOT_USE;
constructor(win: WindowWithKeyborg, props?: KeyborgProps);
get isNavigatingWithKeyboard(): boolean;
set isNavigatingWithKeyboard(val: boolean);
dispose(): void;
isDisposed(): boolean;
/**
* Updates all keyborg instances with the keyboard navigation state
*/
update(): void;
private _onFocusIn;
private _onMouseDown;
private _onMouseOrTouch;
private _onKeyDown;
/**
* @returns whether the keyboard event should trigger keyboard navigation mode
*/
private _shouldTriggerKeyboardNavigation;
/**
* @returns whether the keyboard event should dismiss keyboard navigation mode
*/
private _shouldDismissKeyboardNavigation;
private _scheduleDismiss;
}
/**
* Used to determine the keyboard navigation state
*/
declare class Keyborg {
private _id;
private _win?;
private _core?;
private _cb;
static create(win: WindowWithKeyborg, props?: KeyborgProps): Keyborg;
static dispose(instance: Keyborg): void;
/**
* Updates all subscribed callbacks with the keyboard navigation state
*/
static update(instance: Keyborg, isNavigatingWithKeyboard: boolean): void;
private constructor();
private dispose;
/**
* @returns Whether the user is navigating with keyboard
*/
isNavigatingWithKeyboard(): boolean;
/**
* @param callback - Called when the keyboard navigation state changes
*/
subscribe(callback: KeyborgCallback): void;
/**
* @param callback - Registered with subscribe
*/
unsubscribe(callback: KeyborgCallback): void;
/**
* Manually set the keyboard navigtion state
*/
setVal(isNavigatingWithKeyboard: boolean): void;
}
declare function createKeyborg(win: Window, props?: KeyborgProps): Keyborg;
declare function disposeKeyborg(instance: Keyborg): void;
declare const KEYBORG_FOCUSIN = "keyborg:focusin";
declare const KEYBORG_FOCUSOUT = "keyborg:focusout";
interface KeyborgFocusInEventDetails {
relatedTarget?: HTMLElement;
isFocusedProgrammatically?: boolean;
originalEvent?: FocusEvent;
}
interface KeyborgFocusInEvent extends CustomEvent<KeyborgFocusInEventDetails> {
/**
* @deprecated - used `event.detail`
*/
details?: KeyborgFocusInEventDetails;
}
interface KeyborgFocusOutEventDetails {
originalEvent: FocusEvent;
}
type KeyborgFocusOutEvent = CustomEvent<KeyborgFocusOutEventDetails>;
/**
* Guarantees that the native `focus` will be used
*/
declare function nativeFocus(element: HTMLElement): void;
/**
* @param win The window that stores keyborg focus events
* @returns The last element focused with element.focus()
*/
declare function getLastFocusedProgrammatically(win: Window): HTMLElement | null | undefined;
/*!
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
declare const version: string | undefined;
export { KEYBORG_FOCUSIN, KEYBORG_FOCUSOUT, Keyborg, type KeyborgCallback, type KeyborgFocusInEvent, type KeyborgFocusInEventDetails, type KeyborgFocusOutEvent, type KeyborgFocusOutEventDetails, createKeyborg, disposeKeyborg, getLastFocusedProgrammatically, nativeFocus, version };

506
node_modules/keyborg/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,506 @@
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
KEYBORG_FOCUSIN: () => KEYBORG_FOCUSIN,
KEYBORG_FOCUSOUT: () => KEYBORG_FOCUSOUT,
createKeyborg: () => createKeyborg,
disposeKeyborg: () => disposeKeyborg,
getLastFocusedProgrammatically: () => getLastFocusedProgrammatically,
nativeFocus: () => nativeFocus,
version: () => version
});
module.exports = __toCommonJS(src_exports);
// src/WeakRefInstance.ts
var _canUseWeakRef = typeof WeakRef !== "undefined";
var WeakRefInstance = class {
constructor(instance) {
if (_canUseWeakRef && typeof instance === "object") {
this._weakRef = new WeakRef(instance);
} else {
this._instance = instance;
}
}
/**
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref}
*/
deref() {
var _a, _b;
let instance;
if (this._weakRef) {
instance = (_a = this._weakRef) == null ? void 0 : _a.deref();
if (!instance) {
delete this._weakRef;
}
} else {
instance = this._instance;
if ((_b = instance == null ? void 0 : instance.isDisposed) == null ? void 0 : _b.call(instance)) {
delete this._instance;
}
}
return instance;
}
};
// src/FocusEvent.ts
var KEYBORG_FOCUSIN = "keyborg:focusin";
var KEYBORG_FOCUSOUT = "keyborg:focusout";
function canOverrideNativeFocus(win) {
const HTMLElement = win.HTMLElement;
const origFocus = HTMLElement.prototype.focus;
let isCustomFocusCalled = false;
HTMLElement.prototype.focus = function focus() {
isCustomFocusCalled = true;
};
const btn = win.document.createElement("button");
btn.focus();
HTMLElement.prototype.focus = origFocus;
return isCustomFocusCalled;
}
var _canOverrideNativeFocus = false;
function nativeFocus(element) {
const focus = element.focus;
if (focus.__keyborgNativeFocus) {
focus.__keyborgNativeFocus.call(element);
} else {
element.focus();
}
}
function setupFocusEvent(win) {
const kwin = win;
if (!_canOverrideNativeFocus) {
_canOverrideNativeFocus = canOverrideNativeFocus(kwin);
}
const origFocus = kwin.HTMLElement.prototype.focus;
if (origFocus.__keyborgNativeFocus) {
return;
}
kwin.HTMLElement.prototype.focus = focus;
const shadowTargets = /* @__PURE__ */ new Set();
const focusOutHandler = (e) => {
const target = e.target;
if (!target) {
return;
}
const event = new CustomEvent(KEYBORG_FOCUSOUT, {
cancelable: true,
bubbles: true,
// Allows the event to bubble past an open shadow root
composed: true,
detail: {
originalEvent: e
}
});
target.dispatchEvent(event);
};
const focusInHandler = (e) => {
const target = e.target;
if (!target) {
return;
}
let node = e.composedPath()[0];
const currentShadows = /* @__PURE__ */ new Set();
while (node) {
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
currentShadows.add(node);
node = node.host;
} else {
node = node.parentNode;
}
}
for (const shadowRootWeakRef of shadowTargets) {
const shadowRoot = shadowRootWeakRef.deref();
if (!shadowRoot || !currentShadows.has(shadowRoot)) {
shadowTargets.delete(shadowRootWeakRef);
if (shadowRoot) {
shadowRoot.removeEventListener("focusin", focusInHandler, true);
shadowRoot.removeEventListener("focusout", focusOutHandler, true);
}
}
}
onFocusIn(target, e.relatedTarget || void 0);
};
const onFocusIn = (target, relatedTarget, originalEvent) => {
var _a;
const shadowRoot = target.shadowRoot;
if (shadowRoot) {
for (const shadowRootWeakRef of shadowTargets) {
if (shadowRootWeakRef.deref() === shadowRoot) {
return;
}
}
shadowRoot.addEventListener("focusin", focusInHandler, true);
shadowRoot.addEventListener("focusout", focusOutHandler, true);
shadowTargets.add(new WeakRefInstance(shadowRoot));
return;
}
const details = {
relatedTarget,
originalEvent
};
const event = new CustomEvent(KEYBORG_FOCUSIN, {
cancelable: true,
bubbles: true,
// Allows the event to bubble past an open shadow root
composed: true,
detail: details
});
event.details = details;
if (_canOverrideNativeFocus || data.lastFocusedProgrammatically) {
details.isFocusedProgrammatically = target === ((_a = data.lastFocusedProgrammatically) == null ? void 0 : _a.deref());
data.lastFocusedProgrammatically = void 0;
}
target.dispatchEvent(event);
};
const data = kwin.__keyborgData = {
focusInHandler,
focusOutHandler,
shadowTargets
};
kwin.document.addEventListener(
"focusin",
kwin.__keyborgData.focusInHandler,
true
);
kwin.document.addEventListener(
"focusout",
kwin.__keyborgData.focusOutHandler,
true
);
function focus() {
const keyborgNativeFocusEvent = kwin.__keyborgData;
if (keyborgNativeFocusEvent) {
keyborgNativeFocusEvent.lastFocusedProgrammatically = new WeakRefInstance(
this
);
}
return origFocus.apply(this, arguments);
}
let activeElement = kwin.document.activeElement;
while (activeElement && activeElement.shadowRoot) {
onFocusIn(activeElement);
activeElement = activeElement.shadowRoot.activeElement;
}
focus.__keyborgNativeFocus = origFocus;
}
function disposeFocusEvent(win) {
const kwin = win;
const proto = kwin.HTMLElement.prototype;
const origFocus = proto.focus.__keyborgNativeFocus;
const keyborgNativeFocusEvent = kwin.__keyborgData;
if (keyborgNativeFocusEvent) {
kwin.document.removeEventListener(
"focusin",
keyborgNativeFocusEvent.focusInHandler,
true
);
kwin.document.removeEventListener(
"focusout",
keyborgNativeFocusEvent.focusOutHandler,
true
);
for (const shadowRootWeakRef of keyborgNativeFocusEvent.shadowTargets) {
const shadowRoot = shadowRootWeakRef.deref();
if (shadowRoot) {
shadowRoot.removeEventListener(
"focusin",
keyborgNativeFocusEvent.focusInHandler,
true
);
shadowRoot.removeEventListener(
"focusout",
keyborgNativeFocusEvent.focusOutHandler,
true
);
}
}
keyborgNativeFocusEvent.shadowTargets.clear();
delete kwin.__keyborgData;
}
if (origFocus) {
proto.focus = origFocus;
}
}
function getLastFocusedProgrammatically(win) {
var _a;
const keyborgNativeFocusEvent = win.__keyborgData;
return keyborgNativeFocusEvent ? ((_a = keyborgNativeFocusEvent.lastFocusedProgrammatically) == null ? void 0 : _a.deref()) || null : void 0;
}
// src/Keyborg.ts
var _dismissTimeout = 500;
var _lastId = 0;
var KeyborgCore = class {
constructor(win, props) {
this._isNavigatingWithKeyboard_DO_NOT_USE = false;
this._onFocusIn = (e) => {
if (this._isMouseOrTouchUsedTimer) {
return;
}
if (this.isNavigatingWithKeyboard) {
return;
}
const details = e.detail;
if (!details.relatedTarget) {
return;
}
if (details.isFocusedProgrammatically || details.isFocusedProgrammatically === void 0) {
return;
}
this.isNavigatingWithKeyboard = true;
};
this._onMouseDown = (e) => {
if (e.buttons === 0 || e.clientX === 0 && e.clientY === 0 && e.screenX === 0 && e.screenY === 0) {
return;
}
this._onMouseOrTouch();
};
this._onMouseOrTouch = () => {
const win = this._win;
if (win) {
if (this._isMouseOrTouchUsedTimer) {
win.clearTimeout(this._isMouseOrTouchUsedTimer);
}
this._isMouseOrTouchUsedTimer = win.setTimeout(() => {
delete this._isMouseOrTouchUsedTimer;
}, 1e3);
}
this.isNavigatingWithKeyboard = false;
};
this._onKeyDown = (e) => {
const isNavigatingWithKeyboard = this.isNavigatingWithKeyboard;
if (isNavigatingWithKeyboard) {
if (this._shouldDismissKeyboardNavigation(e)) {
this._scheduleDismiss();
}
} else {
if (this._shouldTriggerKeyboardNavigation(e)) {
this.isNavigatingWithKeyboard = true;
}
}
};
this.id = "c" + ++_lastId;
this._win = win;
const doc = win.document;
if (props) {
const triggerKeys = props.triggerKeys;
const dismissKeys = props.dismissKeys;
if (triggerKeys == null ? void 0 : triggerKeys.length) {
this._triggerKeys = new Set(triggerKeys);
}
if (dismissKeys == null ? void 0 : dismissKeys.length) {
this._dismissKeys = new Set(dismissKeys);
}
}
doc.addEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true);
doc.addEventListener("mousedown", this._onMouseDown, true);
win.addEventListener("keydown", this._onKeyDown, true);
doc.addEventListener("touchstart", this._onMouseOrTouch, true);
doc.addEventListener("touchend", this._onMouseOrTouch, true);
doc.addEventListener("touchcancel", this._onMouseOrTouch, true);
setupFocusEvent(win);
}
get isNavigatingWithKeyboard() {
return this._isNavigatingWithKeyboard_DO_NOT_USE;
}
set isNavigatingWithKeyboard(val) {
if (this._isNavigatingWithKeyboard_DO_NOT_USE !== val) {
this._isNavigatingWithKeyboard_DO_NOT_USE = val;
this.update();
}
}
dispose() {
const win = this._win;
if (win) {
if (this._isMouseOrTouchUsedTimer) {
win.clearTimeout(this._isMouseOrTouchUsedTimer);
this._isMouseOrTouchUsedTimer = void 0;
}
if (this._dismissTimer) {
win.clearTimeout(this._dismissTimer);
this._dismissTimer = void 0;
}
disposeFocusEvent(win);
const doc = win.document;
doc.removeEventListener(KEYBORG_FOCUSIN, this._onFocusIn, true);
doc.removeEventListener("mousedown", this._onMouseDown, true);
win.removeEventListener("keydown", this._onKeyDown, true);
doc.removeEventListener("touchstart", this._onMouseOrTouch, true);
doc.removeEventListener("touchend", this._onMouseOrTouch, true);
doc.removeEventListener("touchcancel", this._onMouseOrTouch, true);
delete this._win;
}
}
isDisposed() {
return !!this._win;
}
/**
* Updates all keyborg instances with the keyboard navigation state
*/
update() {
var _a, _b;
const keyborgs = (_b = (_a = this._win) == null ? void 0 : _a.__keyborg) == null ? void 0 : _b.refs;
if (keyborgs) {
for (const id of Object.keys(keyborgs)) {
Keyborg.update(keyborgs[id], this.isNavigatingWithKeyboard);
}
}
}
/**
* @returns whether the keyboard event should trigger keyboard navigation mode
*/
_shouldTriggerKeyboardNavigation(e) {
var _a;
if (e.key === "Tab") {
return true;
}
const activeElement = (_a = this._win) == null ? void 0 : _a.document.activeElement;
const isTriggerKey = !this._triggerKeys || this._triggerKeys.has(e.keyCode);
const isEditable = activeElement && (activeElement.tagName === "INPUT" || activeElement.tagName === "TEXTAREA" || activeElement.isContentEditable);
return isTriggerKey && !isEditable;
}
/**
* @returns whether the keyboard event should dismiss keyboard navigation mode
*/
_shouldDismissKeyboardNavigation(e) {
var _a;
return (_a = this._dismissKeys) == null ? void 0 : _a.has(e.keyCode);
}
_scheduleDismiss() {
const win = this._win;
if (win) {
if (this._dismissTimer) {
win.clearTimeout(this._dismissTimer);
this._dismissTimer = void 0;
}
const was = win.document.activeElement;
this._dismissTimer = win.setTimeout(() => {
this._dismissTimer = void 0;
const cur = win.document.activeElement;
if (was && cur && was === cur) {
this.isNavigatingWithKeyboard = false;
}
}, _dismissTimeout);
}
}
};
var Keyborg = class _Keyborg {
constructor(win, props) {
this._cb = [];
this._id = "k" + ++_lastId;
this._win = win;
const current = win.__keyborg;
if (current) {
this._core = current.core;
current.refs[this._id] = this;
} else {
this._core = new KeyborgCore(win, props);
win.__keyborg = {
core: this._core,
refs: { [this._id]: this }
};
}
}
static create(win, props) {
return new _Keyborg(win, props);
}
static dispose(instance) {
instance.dispose();
}
/**
* Updates all subscribed callbacks with the keyboard navigation state
*/
static update(instance, isNavigatingWithKeyboard) {
instance._cb.forEach((callback) => callback(isNavigatingWithKeyboard));
}
dispose() {
var _a;
const current = (_a = this._win) == null ? void 0 : _a.__keyborg;
if (current == null ? void 0 : current.refs[this._id]) {
delete current.refs[this._id];
if (Object.keys(current.refs).length === 0) {
current.core.dispose();
delete this._win.__keyborg;
}
} else if (process.env.NODE_ENV !== "production") {
console.error(
`Keyborg instance ${this._id} is being disposed incorrectly.`
);
}
this._cb = [];
delete this._core;
delete this._win;
}
/**
* @returns Whether the user is navigating with keyboard
*/
isNavigatingWithKeyboard() {
var _a;
return !!((_a = this._core) == null ? void 0 : _a.isNavigatingWithKeyboard);
}
/**
* @param callback - Called when the keyboard navigation state changes
*/
subscribe(callback) {
this._cb.push(callback);
}
/**
* @param callback - Registered with subscribe
*/
unsubscribe(callback) {
const index = this._cb.indexOf(callback);
if (index >= 0) {
this._cb.splice(index, 1);
}
}
/**
* Manually set the keyboard navigtion state
*/
setVal(isNavigatingWithKeyboard) {
if (this._core) {
this._core.isNavigatingWithKeyboard = isNavigatingWithKeyboard;
}
}
};
function createKeyborg(win, props) {
return Keyborg.create(win, props);
}
function disposeKeyborg(instance) {
Keyborg.dispose(instance);
}
// src/index.ts
var version = "2.6.0";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
KEYBORG_FOCUSIN,
KEYBORG_FOCUSOUT,
createKeyborg,
disposeKeyborg,
getLastFocusedProgrammatically,
nativeFocus,
version
});
/*!
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
//# sourceMappingURL=index.js.map

1
node_modules/keyborg/dist/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

123
node_modules/keyborg/dist/ts3.9/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,123 @@
/**
* Allows disposable instances to be used
*/
interface Disposable {
isDisposed?(): boolean;
}
/*!
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
interface WindowWithKeyborg extends Window {
__keyborg?: {
core: KeyborgCore;
refs: {
[id: string]: Keyborg;
};
};
}
interface KeyborgProps {
triggerKeys?: number[];
dismissKeys?: number[];
}
type KeyborgCallback = (isNavigatingWithKeyboard: boolean) => void;
/**
* Manages a collection of Keyborg instances in a window/document and updates keyborg state
*/
declare class KeyborgCore implements Disposable {
readonly id: string;
private _win?;
private _isMouseOrTouchUsedTimer;
private _dismissTimer;
private _triggerKeys?;
private _dismissKeys?;
private _isNavigatingWithKeyboard_DO_NOT_USE;
constructor(win: WindowWithKeyborg, props?: KeyborgProps);
isNavigatingWithKeyboard: boolean;
dispose(): void;
isDisposed(): boolean;
/**
* Updates all keyborg instances with the keyboard navigation state
*/
update(): void;
private _onFocusIn;
private _onMouseDown;
private _onMouseOrTouch;
private _onKeyDown;
/**
* @returns whether the keyboard event should trigger keyboard navigation mode
*/
private _shouldTriggerKeyboardNavigation;
/**
* @returns whether the keyboard event should dismiss keyboard navigation mode
*/
private _shouldDismissKeyboardNavigation;
private _scheduleDismiss;
}
/**
* Used to determine the keyboard navigation state
*/
declare class Keyborg {
private _id;
private _win?;
private _core?;
private _cb;
static create(win: WindowWithKeyborg, props?: KeyborgProps): Keyborg;
static dispose(instance: Keyborg): void;
/**
* Updates all subscribed callbacks with the keyboard navigation state
*/
static update(instance: Keyborg, isNavigatingWithKeyboard: boolean): void;
private constructor();
private dispose;
/**
* @returns Whether the user is navigating with keyboard
*/
isNavigatingWithKeyboard(): boolean;
/**
* @param callback - Called when the keyboard navigation state changes
*/
subscribe(callback: KeyborgCallback): void;
/**
* @param callback - Registered with subscribe
*/
unsubscribe(callback: KeyborgCallback): void;
/**
* Manually set the keyboard navigtion state
*/
setVal(isNavigatingWithKeyboard: boolean): void;
}
declare function createKeyborg(win: Window, props?: KeyborgProps): Keyborg;
declare function disposeKeyborg(instance: Keyborg): void;
declare const KEYBORG_FOCUSIN = "keyborg:focusin";
declare const KEYBORG_FOCUSOUT = "keyborg:focusout";
interface KeyborgFocusInEventDetails {
relatedTarget?: HTMLElement;
isFocusedProgrammatically?: boolean;
originalEvent?: FocusEvent;
}
interface KeyborgFocusInEvent extends CustomEvent<KeyborgFocusInEventDetails> {
/**
* @deprecated - used `event.detail`
*/
details?: KeyborgFocusInEventDetails;
}
interface KeyborgFocusOutEventDetails {
originalEvent: FocusEvent;
}
type KeyborgFocusOutEvent = CustomEvent<KeyborgFocusOutEventDetails>;
/**
* Guarantees that the native `focus` will be used
*/
declare function nativeFocus(element: HTMLElement): void;
/**
* @param win The window that stores keyborg focus events
* @returns The last element focused with element.focus()
*/
declare function getLastFocusedProgrammatically(win: Window): HTMLElement | null | undefined;
/*!
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
declare const version: string | undefined;
export { KEYBORG_FOCUSIN, KEYBORG_FOCUSOUT, Keyborg, KeyborgCallback, KeyborgFocusInEvent, KeyborgFocusInEventDetails, KeyborgFocusOutEvent, KeyborgFocusOutEventDetails, createKeyborg, disposeKeyborg, getLastFocusedProgrammatically, nativeFocus, version };

56
node_modules/keyborg/package.json generated vendored Normal file
View File

@@ -0,0 +1,56 @@
{
"name": "keyborg",
"version": "2.6.0",
"description": "Keyboard Navigation Detection for Web",
"author": "Marat Abdullin <marata@microsoft.com>",
"license": "MIT",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/esm/index.js",
"typings": "./dist/index.d.ts",
"typesVersions": {
"<4.0": {
"dist/index.d.ts": [
"dist/ts3.9/index.d.ts"
]
}
},
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/microsoft/keyborg"
},
"scripts": {
"build": "tsup && npx downlevel-dts ./dist ./dist/ts3.9",
"bundle-size": "npm run build && monosize measure",
"format": "prettier --check .",
"format:fix": "prettier --write .",
"test": "playwright test",
"test:serve": "ladle serve --port 3000",
"lint": "eslint src/ tests/",
"lint:fix": "npm run lint -- --fix",
"prepublishOnly": "npm run lint && npm run format && npm run build",
"release": "release-it"
},
"devDependencies": {
"@ladle/react": "^4.0.2",
"@playwright/test": "^1.40.1",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"downlevel-dts": "^0.11.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.29.1",
"monosize": "^0.2.1",
"monosize-storage-azure": "^0.0.5",
"playwright": "^1.40.1",
"prettier": "^3.1.1",
"react-shadow": "^20.4.0",
"release-it": "^17.0.1",
"tsup": "^8.0.1",
"typescript": "^5.3.3"
}
}