Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/Keyborg.mts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ interface WindowWithKeyborg extends Window {
const _dismissTimeout = 500; // When a key from dismissKeys is pressed and the focus is not moved
// during _dismissTimeout time, dismiss the keyboard navigation mode.

let _lastId = 0;
function generateId(): string {
const arr = new Uint8Array(16);
crypto.getRandomValues(arr);

let id = "";
for (let i = 0; i < arr.length; i++) {
id += arr[i].toString(16).padStart(2, "0");
}

return id;
}

export interface KeyborgProps {
// Keys to be used to trigger keyboard navigation mode. By default, any key will trigger
Expand All @@ -48,7 +58,7 @@ class KeyborgCore implements Disposable {
private _isNavigatingWithKeyboard_DO_NOT_USE = false;

constructor(win: WindowWithKeyborg, props?: KeyborgProps) {
this.id = "c" + ++_lastId;
this.id = generateId();
this._win = win;
const doc = win.document;

Expand Down Expand Up @@ -291,7 +301,7 @@ export class Keyborg {
}

private constructor(win: WindowWithKeyborg, props?: KeyborgProps) {
this._id = "k" + ++_lastId;
this._id = generateId();
this._win = win;

const current = win.__keyborg;
Expand Down
Loading