generative-a11y
DOM

createAttentionStore

Observe browser focus and visibility for your existing interface.

Create and register app elements

AttentionStore reads browser focus and visibility. It does not inspect a screen reader's cursor or move focus.

attention.ts
import { createAttentionStore } from "@generative-a11y/dom";

const attention = createAttentionStore({ document });

const unregisterComposer = attention.registerComposer(composer);
const unregisterConversation = attention.registerConversation(conversation);
const unregisterNewest = attention.registerNewestResponse(latestResponse);

const unsubscribe = attention.subscribe(() => {
  console.log(attention.getSnapshot());
});

// Call when the owning surface is removed.
function disposeAttention() {
  unsubscribe();
  unregisterNewest();
  unregisterConversation();
  unregisterComposer();
  attention.dispose();
}

Register the elements your app already owns. Each registration and subscription returns a cleanup function; dispose() releases the store and its browser listeners.

Prop

Type

AttentionSnapshot

A field stays unknown when the browser cannot provide enough information. AttentionStore never guesses.

FieldValuesBrowser signal
visibilityvisible, hidden, unknownDocument visibility
windowFocusfocused, blurred, unknownWindow focus
focusAreacomposer, conversation, elsewhere, none, unknownDeep active element
newestResponsevisible, outside, unobserved, unknownIntersection observer
modeforeground, background, reading-history, away, unknownDerived from the fields above

bindAttention

bindAttention({ runtime, attentionStore }) explicitly forwards initial and changed observations to the core runtime. Both inputs are borrowed. dispose() unsubscribes and sends attention.changed with mode unknown, without disposing either input. Competing bindings for one runtime throw. Core filtering still requires policy.attention.enabled.

Actual newest-response intersection contributes browser evidence; this cannot identify a screen reader virtual cursor. Read the attention guide.