createAttentionStore
A store that uses page visibility, window focus, the focused area, and response visibility to estimate where the user is working.
Create and register app elements
AttentionStore reads browser focus and visibility. It does not inspect a screen reader's cursor or move focus.
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());
});
unsubscribe();
unregisterNewest();
unregisterConversation();
unregisterComposer();
attention.dispose();How this code works
- 01Read browser signals
AttentionStore reads document visibility, window focus, element focus, and intersection changes.
- 02Register app areas
Register the composer, conversation history, and newest response so the store can identify them.
- 03Clean up
Each registration and subscription returns its own cleanup function.
Options and return values
optionsAttentionStoreOptionsOptional
Injects the document, intersection observer factory, and observer configuration.
- Default
browser document
returnAttentionStoreReturn
External store with snapshots, registrations, subscriptions, and disposal.
- Default
n/a
AttentionSnapshot
A field stays unknown when the browser cannot provide enough information. AttentionStore never guesses.
| Field | Values | Browser signal |
|---|---|---|
| visibility | visible, hidden, unknown | Document visibility |
| windowFocus | focused, blurred, unknown | Window focus |
| focusArea | composer, conversation, elsewhere, none, unknown | Deep active element |
| newestResponse | visible, outside, unobserved, unknown | Intersection observer |
| mode | foreground, background, reading-history, away, unknown | Derived from the fields above |