Files
agency/.pnpm-store/v3/files/b3/d661f5063ba19d332abf7a0cbf24e91f1eef98f0d45ec27c8a9034a7dcd3f5e57c2b32f75ae05e31c2de1d23c208cb455ff9967d9c96c398d54fcfe4db149f
hanzo-agent 5af6960b87 run project
Run: sess_f37640604ae254cb4d11dc6217f7b721
2026-09-30 00:04:56 +00:00

68 lines
1.6 KiB
Plaintext

// src/focusManager.ts
import { Subscribable } from "./subscribable.js";
import { isServer } from "./utils.js";
var FocusManager = class extends Subscribable {
#focused;
#cleanup;
#setup;
constructor() {
super();
this.#setup = (onFocus) => {
if (!isServer && window.addEventListener) {
const listener = () => onFocus();
window.addEventListener("visibilitychange", listener, false);
return () => {
window.removeEventListener("visibilitychange", listener);
};
}
return;
};
}
onSubscribe() {
if (!this.#cleanup) {
this.setEventListener(this.#setup);
}
}
onUnsubscribe() {
if (!this.hasListeners()) {
this.#cleanup?.();
this.#cleanup = void 0;
}
}
setEventListener(setup) {
this.#setup = setup;
this.#cleanup?.();
this.#cleanup = setup((focused) => {
if (typeof focused === "boolean") {
this.setFocused(focused);
} else {
this.onFocus();
}
});
}
setFocused(focused) {
const changed = this.#focused !== focused;
if (changed) {
this.#focused = focused;
this.onFocus();
}
}
onFocus() {
const isFocused = this.isFocused();
this.listeners.forEach((listener) => {
listener(isFocused);
});
}
isFocused() {
if (typeof this.#focused === "boolean") {
return this.#focused;
}
return globalThis.document?.visibilityState !== "hidden";
}
};
var focusManager = new FocusManager();
export {
FocusManager,
focusManager
};
//# sourceMappingURL=focusManager.js.map