@generative-a11y/dom 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/composed-tree.ts","../src/attention.ts","../src/focus.ts","../src/preferences.ts"],"sourcesContent":["import type {\n AnnouncementIntent,\n GenerativeA11yRuntime,\n} from \"@generative-a11y/core\";\n\nexport {\n createAttentionStore,\n type AttentionIntersectionObserver,\n type AttentionIntersectionObserverFactory,\n type AttentionSnapshot,\n type AttentionStore,\n type AttentionStoreOptions,\n type ExternalStore,\n} from \"./attention.js\";\n\nexport {\n captureFocus,\n focusElement,\n restoreFocus,\n type FocusCapture,\n type FocusElementOptions,\n type FocusResult,\n type FocusSkippedReason,\n type RestoreFocusOptions,\n} from \"./focus.js\";\n\nexport {\n createPreferenceStore,\n defaultPreferences,\n normalizePreferences,\n preferencesToCoreConfiguration,\n type CorePreferenceConfiguration,\n type PreferenceDiagnostic,\n type PreferenceDiagnosticCode,\n type PreferenceDiagnosticSource,\n type PreferencePersistence,\n type PreferenceSchemaV1,\n type PreferenceStorage,\n type PreferenceStorageEvent,\n type PreferenceStorageEventSource,\n type PreferenceStore,\n type PreferenceStoreOptions,\n samePreferences,\n type StreamingVerbosity,\n type ToolVerbosity,\n} from \"./preferences.js\";\n\nexport type DOMAnnouncementMode = \"auto\" | \"aria-notify\" | \"live-region\";\n\nexport interface DOMLiveRegions {\n polite: HTMLElement;\n assertive: HTMLElement;\n}\n\nexport interface DOMDeliveryResult {\n status: \"notified\" | \"mutated\" | \"unavailable\" | \"disposed\";\n method: \"aria-notify\" | \"live-region\" | \"none\";\n channel: AnnouncementIntent[\"channel\"];\n error?: { name: string; message: string };\n}\n\nexport interface DOMAnnouncerOptions {\n document?: Document;\n mode?: DOMAnnouncementMode;\n regions?: DOMLiveRegions;\n onDiagnostic?: (result: DOMDeliveryResult) => void;\n}\n\nexport interface DOMAnnouncer {\n announce(intent: AnnouncementIntent): DOMDeliveryResult;\n getRegions(): DOMLiveRegions | undefined;\n dispose(): void;\n}\n\nexport interface DOMRuntimeBinding {\n announcer: DOMAnnouncer;\n dispose(): void;\n}\n\nexport function createDOMAnnouncer(\n options: DOMAnnouncerOptions = {},\n): DOMAnnouncer {\n validateSuppliedRegions(options);\n const selectedDocument =\n options.document ??\n options.regions?.polite.ownerDocument ??\n (typeof document === \"undefined\" ? undefined : document);\n const ownsRegions = options.regions === undefined;\n const regions = options.regions ?? createLiveRegions(selectedDocument);\n\n if (regions) {\n configureRegion(regions.polite, \"polite\");\n configureRegion(regions.assertive, \"assertive\");\n }\n let notifierEnabled = true;\n let disposed = false;\n\n const report = (result: DOMDeliveryResult): DOMDeliveryResult => {\n try {\n options.onDiagnostic?.(result);\n } catch {\n // Diagnostics are observational and cannot affect delivery.\n }\n return result;\n };\n\n return {\n announce(intent) {\n if (disposed) {\n return report({\n status: \"disposed\",\n method: \"none\",\n channel: intent.channel,\n });\n }\n if (regions) {\n const region = regions[intent.channel];\n applyLocale(region, intent.locale);\n let error: DOMDeliveryResult[\"error\"];\n if (notifierEnabled && options.mode !== \"live-region\") {\n let notified = false;\n try {\n const ariaNotify = (region as AriaNotifyRegion).ariaNotify;\n if (typeof ariaNotify === \"function\") {\n ariaNotify.call(region, intent.text, {\n priority: intent.channel === \"assertive\" ? \"high\" : \"normal\",\n });\n notified = true;\n }\n } catch (cause) {\n notifierEnabled = false;\n error = serializeError(cause);\n }\n if (notified) {\n return report({\n status: \"notified\",\n method: \"aria-notify\",\n channel: intent.channel,\n });\n }\n }\n region.textContent = intent.text;\n return report({\n status: \"mutated\",\n method: \"live-region\",\n channel: intent.channel,\n ...(error === undefined ? {} : { error }),\n });\n }\n return report({\n status: \"unavailable\",\n method: \"none\",\n channel: intent.channel,\n });\n },\n getRegions() {\n return regions;\n },\n dispose() {\n if (disposed) return;\n disposed = true;\n if (ownsRegions) {\n regions?.polite.remove();\n regions?.assertive.remove();\n }\n },\n };\n}\n\nfunction validateSuppliedRegions(options: DOMAnnouncerOptions): void {\n if (options.regions === undefined) return;\n const { polite, assertive } = options.regions;\n if (polite === assertive) {\n throw new TypeError(\n \"Polite and assertive regions must be distinct elements\",\n );\n }\n if (!polite.isConnected || !assertive.isConnected) {\n throw new TypeError(\"Supplied regions must be connected\");\n }\n if (polite.contains(assertive) || assertive.contains(polite)) {\n throw new TypeError(\n \"Polite and assertive regions must not contain one another\",\n );\n }\n if (polite.ownerDocument !== assertive.ownerDocument) {\n throw new TypeError(\n \"Polite and assertive regions must belong to the same document\",\n );\n }\n if (\n options.document !== undefined &&\n (polite.ownerDocument !== options.document ||\n assertive.ownerDocument !== options.document)\n ) {\n throw new TypeError(\n \"Supplied regions must belong to the provided document\",\n );\n }\n}\n\nfunction serializeError(\n error: unknown,\n): NonNullable<DOMDeliveryResult[\"error\"]> {\n try {\n if (error instanceof Error) {\n return {\n name: readErrorString(error, \"name\", \"Error\"),\n message: readErrorString(error, \"message\", \"Unknown error\"),\n };\n }\n } catch {\n // Hostile proxies can throw during instanceof checks.\n }\n return { name: \"Error\", message: safeString(error, \"Unknown error\") };\n}\n\nfunction readErrorString(\n error: Error,\n property: \"name\" | \"message\",\n fallback: string,\n): string {\n try {\n return safeString(error[property], fallback);\n } catch {\n return fallback;\n }\n}\n\nfunction safeString(value: unknown, fallback: string): string {\n try {\n return String(value);\n } catch {\n return fallback;\n }\n}\n\ninterface AriaNotifyRegion extends HTMLElement {\n ariaNotify?: (\n text: string,\n options?: { priority: \"normal\" | \"high\" },\n ) => void;\n}\n\nfunction createLiveRegions(\n selectedDocument: Document | undefined,\n): DOMLiveRegions | undefined {\n const parent = selectedDocument?.body ?? selectedDocument?.documentElement;\n if (!selectedDocument || !parent) return undefined;\n\n const regions = {\n polite: selectedDocument.createElement(\"div\"),\n assertive: selectedDocument.createElement(\"div\"),\n };\n parent.append(regions.polite, regions.assertive);\n return regions;\n}\n\nfunction configureRegion(\n region: HTMLElement,\n channel: AnnouncementIntent[\"channel\"],\n): void {\n region.removeAttribute(\"role\");\n region.removeAttribute(\"aria-busy\");\n region.removeAttribute(\"hidden\");\n region.removeAttribute(\"aria-hidden\");\n region.inert = false;\n region.removeAttribute(\"inert\");\n region.style.removeProperty(\"display\");\n region.style.removeProperty(\"visibility\");\n region.style.removeProperty(\"content-visibility\");\n region.setAttribute(\"aria-live\", channel);\n region.setAttribute(\"aria-atomic\", \"true\");\n region.setAttribute(\"aria-relevant\", \"additions text\");\n Object.assign(region.style, {\n position: \"absolute\",\n width: \"1px\",\n height: \"1px\",\n padding: \"0\",\n margin: \"-1px\",\n overflow: \"hidden\",\n clip: \"rect(0, 0, 0, 0)\",\n whiteSpace: \"nowrap\",\n border: \"0\",\n });\n}\n\nfunction applyLocale(region: HTMLElement, locale: string | undefined): void {\n if (locale === undefined) region.removeAttribute(\"lang\");\n else region.setAttribute(\"lang\", locale);\n}\n\nexport function connectRuntimeToDOM(\n runtime: GenerativeA11yRuntime,\n options: DOMAnnouncerOptions = {},\n): DOMRuntimeBinding {\n const announcer = createDOMAnnouncer(options);\n let disposed = false;\n let unsubscribe: () => void;\n try {\n unsubscribe = runtime.subscribeAnnouncements((intent) => {\n if (!disposed) announcer.announce(intent);\n });\n } catch (cause) {\n announcer.dispose();\n throw cause;\n }\n\n return {\n announcer,\n dispose() {\n if (disposed) return;\n disposed = true;\n try {\n unsubscribe();\n } finally {\n announcer.dispose();\n }\n },\n };\n}\n","export function deepActiveElement(document: Document): Element | null {\n let active = document.activeElement;\n const visited = new Set<Element>();\n while (active) {\n if (visited.has(active)) throw new Error(\"Cyclic active element\");\n visited.add(active);\n const shadow = (active as Element & { shadowRoot?: ShadowRoot | null })\n .shadowRoot;\n const nested = shadow?.activeElement;\n if (!nested) return active;\n active = nested;\n }\n return null;\n}\n\nexport function composedContains(ancestor: Element, target: Element): boolean {\n let current: Element | null = target;\n const visited = new Set<Element>();\n while (current) {\n if (current === ancestor) return true;\n if (visited.has(current)) throw new Error(\"Cyclic composed tree\");\n visited.add(current);\n current = composedParent(current);\n }\n return false;\n}\n\nexport function composedParent(element: Element): Element | null {\n const assignedSlot = (\n element as Element & { assignedSlot?: HTMLSlotElement | null }\n ).assignedSlot;\n if (assignedSlot) return assignedSlot;\n if (element.parentElement) return element.parentElement;\n const root = element.getRootNode();\n if (root && \"host\" in root) {\n const host = (root as ShadowRoot).host;\n if (host.ownerDocument === element.ownerDocument) return host;\n }\n return null;\n}\n","import { composedContains, deepActiveElement } from \"./composed-tree.js\";\n\nexport interface ExternalStore<T> {\n subscribe(listener: () => void): () => void;\n getSnapshot(): T;\n getServerSnapshot(): T;\n}\n\nexport interface AttentionSnapshot {\n readonly visibility: \"visible\" | \"hidden\" | \"unknown\";\n readonly windowFocus: \"focused\" | \"blurred\" | \"unknown\";\n readonly focusArea:\n \"composer\" | \"conversation\" | \"elsewhere\" | \"none\" | \"unknown\";\n readonly newestResponse: \"visible\" | \"outside\" | \"unobserved\" | \"unknown\";\n readonly mode:\n \"foreground\" | \"background\" | \"reading-history\" | \"away\" | \"unknown\";\n}\n\nexport interface AttentionStore extends ExternalStore<AttentionSnapshot> {\n registerComposer(element: Element): () => void;\n registerConversation(element: Element): () => void;\n registerNewestResponse(element: Element): () => void;\n dispose(): void;\n}\n\nexport interface AttentionStoreOptions {\n document?: Document;\n createIntersectionObserver?: AttentionIntersectionObserverFactory;\n intersectionObserverInit?: IntersectionObserverInit;\n}\n\nexport interface AttentionIntersectionObserver {\n observe(target: Element): void;\n unobserve(target: Element): void;\n disconnect(): void;\n}\n\nexport type AttentionIntersectionObserverFactory = (\n callback: IntersectionObserverCallback,\n options?: IntersectionObserverInit,\n) => AttentionIntersectionObserver;\n\nconst UNKNOWN_SNAPSHOT: AttentionSnapshot = Object.freeze({\n visibility: \"unknown\",\n windowFocus: \"unknown\",\n focusArea: \"unknown\",\n newestResponse: \"unknown\",\n mode: \"unknown\",\n});\n\nexport function createAttentionStore(\n options: AttentionStoreOptions = {},\n): AttentionStore {\n const selectedDocument =\n options.document ??\n (typeof document === \"undefined\" ? undefined : document);\n if (!selectedDocument) {\n return {\n subscribe: () => () => undefined,\n getSnapshot: () => UNKNOWN_SNAPSHOT,\n getServerSnapshot: () => UNKNOWN_SNAPSHOT,\n registerComposer: () => () => undefined,\n registerConversation: () => () => undefined,\n registerNewestResponse: () => () => undefined,\n dispose: () => undefined,\n };\n }\n\n const listeners = new Set<() => void>();\n const composers = new Map<Element, number>();\n const conversations = new Map<Element, number>();\n const selectedWindow = selectedDocument.defaultView;\n let disposed = false;\n let newestTarget: Element | undefined;\n let newestResult: AttentionSnapshot[\"newestResponse\"] = \"unobserved\";\n let newestRegistration = 0;\n let observer: AttentionIntersectionObserver | undefined;\n let snapshot = makeSnapshot(\n selectedDocument,\n composers,\n conversations,\n newestResult,\n );\n const update = () => {\n if (disposed) return;\n const next = makeSnapshot(\n selectedDocument,\n composers,\n conversations,\n newestResult,\n );\n if (sameSnapshot(snapshot, next)) return;\n snapshot = next;\n for (const listener of [...listeners]) {\n try {\n listener();\n } catch {\n // External-store observers cannot prevent other observers from running.\n }\n }\n };\n const handleFocusOut = (event: FocusEvent) => {\n if (event.relatedTarget === null) update();\n };\n const listenerCleanups: Array<() => void> = [];\n const installListener = (install: () => void, cleanup: () => void): void => {\n // Register cleanup first because a hostile EventTarget can install and then\n // throw from addEventListener(). Removing a listener that was not installed\n // is harmless, while omitting cleanup would leak the accepted listener.\n listenerCleanups.push(cleanup);\n install();\n };\n const cleanupListeners = (): void => {\n for (const cleanup of listenerCleanups.splice(0).reverse()) {\n try {\n cleanup();\n } catch {\n // One hostile removal cannot strand the remaining listeners.\n }\n }\n };\n try {\n installListener(\n () => selectedDocument.addEventListener(\"visibilitychange\", update),\n () => selectedDocument.removeEventListener(\"visibilitychange\", update),\n );\n if (selectedWindow) {\n installListener(\n () => selectedWindow.addEventListener(\"focus\", update),\n () => selectedWindow.removeEventListener(\"focus\", update),\n );\n installListener(\n () => selectedWindow.addEventListener(\"blur\", update),\n () => selectedWindow.removeEventListener(\"blur\", update),\n );\n }\n installListener(\n () => selectedDocument.addEventListener(\"focusin\", update),\n () => selectedDocument.removeEventListener(\"focusin\", update),\n );\n installListener(\n () => selectedDocument.addEventListener(\"focusout\", handleFocusOut),\n () => selectedDocument.removeEventListener(\"focusout\", handleFocusOut),\n );\n } catch (error) {\n cleanupListeners();\n throw error;\n }\n\n const register = (\n elements: Map<Element, number>,\n element: Element,\n ): (() => void) => {\n if (disposed) throw new Error(\"AttentionStore is disposed\");\n elements.set(element, (elements.get(element) ?? 0) + 1);\n update();\n let registered = true;\n return () => {\n if (!registered) return;\n registered = false;\n const remaining = (elements.get(element) ?? 1) - 1;\n if (remaining === 0) elements.delete(element);\n else elements.set(element, remaining);\n update();\n };\n };\n\n const createObserver = (\n registration: number,\n target: Element,\n ): AttentionIntersectionObserver | undefined => {\n const factory =\n options.createIntersectionObserver ??\n defaultIntersectionObserverFactory(selectedWindow);\n if (!factory) return undefined;\n let created: AttentionIntersectionObserver | undefined;\n try {\n created = factory((entries) => {\n if (\n disposed ||\n registration !== newestRegistration ||\n newestTarget !== target ||\n observer !== created\n ) {\n return;\n }\n let latest: IntersectionObserverEntry | undefined;\n for (const entry of entries) {\n if (entry.target === target) latest = entry;\n }\n if (!latest) return;\n newestResult = latest.isIntersecting ? \"visible\" : \"outside\";\n update();\n }, options.intersectionObserverInit);\n created.observe(target);\n return created;\n } catch {\n cleanupObserver(created, target);\n return undefined;\n }\n };\n\n const stopObserver = (target?: Element): void => {\n const current = observer;\n observer = undefined;\n cleanupObserver(current, target);\n };\n\n return {\n subscribe(listener) {\n if (disposed) throw new Error(\"AttentionStore is disposed\");\n listeners.add(listener);\n let subscribed = true;\n return () => {\n if (!subscribed) return;\n subscribed = false;\n listeners.delete(listener);\n };\n },\n getSnapshot: () => snapshot,\n getServerSnapshot: () => UNKNOWN_SNAPSHOT,\n registerComposer: (element) => register(composers, element),\n registerConversation: (element) => register(conversations, element),\n registerNewestResponse(element) {\n if (disposed) throw new Error(\"AttentionStore is disposed\");\n const registration = ++newestRegistration;\n stopObserver(newestTarget);\n newestTarget = element;\n newestResult = \"unknown\";\n observer = createObserver(registration, element);\n update();\n let registered = true;\n return () => {\n if (!registered) return;\n registered = false;\n if (registration !== newestRegistration || newestTarget !== element)\n return;\n stopObserver(element);\n newestTarget = undefined;\n newestResult = \"unobserved\";\n update();\n };\n },\n dispose() {\n if (disposed) return;\n disposed = true;\n listeners.clear();\n composers.clear();\n conversations.clear();\n stopObserver(newestTarget);\n newestTarget = undefined;\n cleanupListeners();\n },\n };\n}\n\nfunction makeSnapshot(\n document: Document,\n composers: ReadonlyMap<Element, number>,\n conversations: ReadonlyMap<Element, number>,\n newestResponse: AttentionSnapshot[\"newestResponse\"],\n): AttentionSnapshot {\n const visibility = readVisibility(document);\n const windowFocus = readWindowFocus(document);\n return Object.freeze({\n visibility,\n windowFocus,\n focusArea: readFocusArea(document, composers, conversations),\n newestResponse,\n mode: deriveMode(visibility, windowFocus, newestResponse),\n });\n}\n\nfunction deriveMode(\n visibility: AttentionSnapshot[\"visibility\"],\n windowFocus: AttentionSnapshot[\"windowFocus\"],\n newestResponse: AttentionSnapshot[\"newestResponse\"],\n): AttentionSnapshot[\"mode\"] {\n if (visibility === \"hidden\") return \"background\";\n if (visibility !== \"visible\") return \"unknown\";\n if (windowFocus === \"blurred\") return \"away\";\n if (windowFocus !== \"focused\") return \"unknown\";\n if (newestResponse === \"outside\") return \"reading-history\";\n if (newestResponse === \"visible\") return \"foreground\";\n return \"unknown\";\n}\n\nfunction defaultIntersectionObserverFactory(\n window: (Window & typeof globalThis) | null,\n): AttentionIntersectionObserverFactory | undefined {\n const Constructor = window?.IntersectionObserver;\n if (typeof Constructor !== \"function\") return undefined;\n return (callback, options) => new Constructor(callback, options);\n}\n\nfunction cleanupObserver(\n observer: AttentionIntersectionObserver | undefined,\n target?: Element,\n): void {\n if (!observer) return;\n if (target) {\n try {\n observer.unobserve(target);\n } catch {\n // Intersection cleanup errors are deliberately suppressed.\n }\n }\n try {\n observer.disconnect();\n } catch {\n // Intersection cleanup errors are deliberately suppressed.\n }\n}\n\nfunction readFocusArea(\n document: Document,\n composers: ReadonlyMap<Element, number>,\n conversations: ReadonlyMap<Element, number>,\n): AttentionSnapshot[\"focusArea\"] {\n let activeElement: Element | null;\n try {\n activeElement = deepActiveElement(document);\n } catch {\n return \"unknown\";\n }\n if (\n activeElement === null ||\n activeElement === document.body ||\n activeElement === document.documentElement\n ) {\n return \"none\";\n }\n if (\n [...composers.keys()].some((element) =>\n composedContains(element, activeElement),\n )\n ) {\n return \"composer\";\n }\n if (\n [...conversations.keys()].some((element) =>\n composedContains(element, activeElement),\n )\n ) {\n return \"conversation\";\n }\n return \"elsewhere\";\n}\n\nfunction readVisibility(document: Document): AttentionSnapshot[\"visibility\"] {\n try {\n if (document.visibilityState === \"visible\") return \"visible\";\n if (document.visibilityState === \"hidden\") return \"hidden\";\n } catch {\n // Browser integrations can expose throwing accessors.\n }\n return \"unknown\";\n}\n\nfunction readWindowFocus(document: Document): AttentionSnapshot[\"windowFocus\"] {\n try {\n if (typeof document.hasFocus !== \"function\") return \"unknown\";\n return document.hasFocus() ? \"focused\" : \"blurred\";\n } catch {\n return \"unknown\";\n }\n}\n\nfunction sameSnapshot(\n left: AttentionSnapshot,\n right: AttentionSnapshot,\n): boolean {\n return (\n left.visibility === right.visibility &&\n left.windowFocus === right.windowFocus &&\n left.focusArea === right.focusArea &&\n left.newestResponse === right.newestResponse &&\n left.mode === right.mode\n );\n}\n","import {\n composedContains,\n composedParent,\n deepActiveElement,\n} from \"./composed-tree.js\";\n\nexport interface FocusCapture {\n readonly document: Document | null;\n readonly target: Element | null;\n}\n\nexport interface FocusElementOptions {\n preventScroll?: boolean;\n}\n\nexport interface RestoreFocusOptions extends FocusElementOptions {\n onlyIfFocusWithin?: Element;\n}\n\nexport type FocusSkippedReason =\n | \"unavailable\"\n | \"cross-document\"\n | \"disconnected\"\n | \"disabled\"\n | \"hidden\"\n | \"aria-hidden\"\n | \"inert\"\n | \"missing-focus\"\n | \"guard-mismatch\"\n | \"focus-error\"\n | \"focus-not-applied\";\n\nexport type FocusResult =\n | { readonly status: \"focused\"; readonly target: Element }\n | {\n readonly status: \"skipped\";\n readonly reason: FocusSkippedReason;\n readonly target: Element | null;\n };\n\nexport function captureFocus(selectedDocument?: Document): FocusCapture {\n const document =\n selectedDocument ??\n (typeof globalThis.document === \"undefined\"\n ? undefined\n : globalThis.document);\n if (!document) return Object.freeze({ document: null, target: null });\n let target: Element | null = null;\n try {\n const active = deepActiveElement(document);\n if (\n active !== null &&\n active !== document.body &&\n active !== document.documentElement &&\n active.ownerDocument === document\n ) {\n target = active;\n }\n } catch {\n // A hostile document is captured without a restorable target.\n }\n return Object.freeze({ document, target });\n}\n\nexport function focusElement(\n target: Element,\n options: FocusElementOptions = {},\n): FocusResult {\n const eligibility = focusEligibility(target);\n if (eligibility) {\n return { status: \"skipped\", reason: eligibility, target };\n }\n let focus: ((options?: FocusOptions) => void) | undefined;\n let document: Document;\n let previous: Element | null;\n try {\n document = target.ownerDocument;\n previous = deepActiveElement(document);\n focus = (target as Element & { focus?: (options?: FocusOptions) => void })\n .focus;\n } catch {\n return { status: \"skipped\", reason: \"unavailable\", target };\n }\n if (typeof focus !== \"function\") {\n return { status: \"skipped\", reason: \"missing-focus\", target };\n }\n let focusThrew = false;\n try {\n focus.call(target, { preventScroll: options.preventScroll ?? true });\n } catch {\n focusThrew = true;\n }\n if (focusThrew) {\n restorePreviousFocus(previous, target, document);\n return { status: \"skipped\", reason: \"focus-error\", target };\n }\n const postFocusEligibility = focusEligibility(target);\n let active: Element | null;\n try {\n active = deepActiveElement(document);\n } catch {\n return { status: \"skipped\", reason: \"focus-error\", target };\n }\n if (postFocusEligibility) {\n if (active === target) restorePreviousFocus(previous, target, document);\n return { status: \"skipped\", reason: postFocusEligibility, target };\n }\n if (active !== target) {\n return { status: \"skipped\", reason: \"focus-not-applied\", target };\n }\n return { status: \"focused\", target };\n}\n\nexport function restoreFocus(\n capture: FocusCapture,\n options: RestoreFocusOptions = {},\n): FocusResult {\n let document: Document | null;\n let target: Element | null;\n try {\n document = capture.document;\n target = capture.target;\n } catch {\n return { status: \"skipped\", reason: \"unavailable\", target: null };\n }\n if (!document || !target) {\n return { status: \"skipped\", reason: \"unavailable\", target: null };\n }\n try {\n if (target.ownerDocument !== document) {\n return { status: \"skipped\", reason: \"cross-document\", target };\n }\n const guard = options.onlyIfFocusWithin;\n if (guard !== undefined) {\n const active = deepActiveElement(document);\n if (\n guard.ownerDocument !== document ||\n active === null ||\n !composedContains(guard, active)\n ) {\n return { status: \"skipped\", reason: \"guard-mismatch\", target };\n }\n }\n } catch {\n return { status: \"skipped\", reason: \"guard-mismatch\", target };\n }\n return focusElement(target, options);\n}\n\nfunction focusEligibility(target: Element): FocusSkippedReason | undefined {\n let ownerDocument: Document;\n try {\n ownerDocument = target.ownerDocument;\n const ElementConstructor = ownerDocument.defaultView?.Element;\n if (\n !ownerDocument ||\n (ElementConstructor && !(target instanceof ElementConstructor))\n ) {\n return \"unavailable\";\n }\n if (target.isConnected !== true) return \"disconnected\";\n if (\n target.getAttribute(\"disabled\") !== null ||\n (target as Element & { disabled?: unknown }).disabled === true\n ) {\n return \"disabled\";\n }\n } catch {\n return \"unavailable\";\n }\n try {\n const matches = target.matches;\n if (typeof matches === \"function\" && matches.call(target, \":disabled\")) {\n return \"disabled\";\n }\n } catch {\n // Fall back to the direct disabled checks above.\n }\n\n try {\n let current: Element | null = target;\n const visited = new Set<Element>();\n while (current) {\n if (visited.has(current)) return \"unavailable\";\n visited.add(current);\n if (current.hasAttribute(\"hidden\")) return \"hidden\";\n if (current.getAttribute(\"aria-hidden\")?.trim().toLowerCase() === \"true\")\n return \"aria-hidden\";\n if (\n current.hasAttribute(\"inert\") ||\n (current as Element & { inert?: unknown }).inert === true\n ) {\n return \"inert\";\n }\n current = composedParent(current);\n }\n } catch {\n return \"unavailable\";\n }\n\n try {\n const focus = (\n target as Element & {\n focus?: (options?: FocusOptions) => void;\n }\n ).focus;\n if (typeof focus !== \"function\") return \"missing-focus\";\n } catch {\n return \"unavailable\";\n }\n return undefined;\n}\n\nfunction restorePreviousFocus(\n previous: Element | null,\n attempted: Element,\n document: Document,\n): void {\n try {\n if (\n !previous ||\n deepActiveElement(document) !== attempted ||\n focusEligibility(previous) !== undefined\n ) {\n return;\n }\n const focus = (\n previous as Element & {\n focus?: (options?: FocusOptions) => void;\n }\n ).focus;\n if (typeof focus === \"function\")\n focus.call(previous, { preventScroll: true });\n } catch {\n // Focus rollback is best-effort at hostile DOM boundaries.\n }\n}\n","import type { PolicyOverrides, PresetName } from \"@generative-a11y/core\";\n\nimport type { ExternalStore } from \"./attention.js\";\n\nexport type StreamingVerbosity =\n \"preset\" | \"off\" | \"completion\" | \"paragraph\" | \"sentence\";\n\nexport type ToolVerbosity =\n \"preset\" | \"off\" | \"failures\" | \"status\" | \"progress\";\n\nexport type PreferenceSchemaV1 =\n | Readonly<{ version: 1; preset: \"completion-only\" }>\n | Readonly<{\n version: 1;\n preset: \"minimal\" | \"balanced\" | \"verbose\";\n streaming: StreamingVerbosity;\n tools: ToolVerbosity;\n }>;\n\nexport interface PreferenceStorage {\n getItem(key: string): string | null;\n setItem(key: string, value: string): void;\n}\n\nexport interface PreferenceStorageEvent {\n readonly key: string | null;\n readonly newValue: string | null;\n readonly storageArea?: PreferenceStorage | null;\n}\n\nexport interface PreferenceStorageEventSource {\n subscribe(listener: (event: PreferenceStorageEvent) => void): () => void;\n}\n\nexport type PreferenceDiagnosticSource =\n | \"storage-read\"\n | \"storage-write\"\n | \"storage-event\"\n | \"event-subscribe\"\n | \"event-unsubscribe\";\n\nexport type PreferenceDiagnosticCode =\n | \"operation-failed\"\n | \"invalid-json\"\n | \"invalid-preference\"\n | \"unsupported-version\";\n\nexport interface PreferenceDiagnostic {\n readonly source: PreferenceDiagnosticSource;\n readonly code: PreferenceDiagnosticCode;\n readonly error?: Readonly<{ name: string; message: string }>;\n}\n\nexport interface PreferencePersistence {\n readonly key: string;\n readonly storage?: PreferenceStorage;\n readonly events?: PreferenceStorageEventSource;\n}\n\nexport interface PreferenceStoreOptions {\n readonly defaultValue?: PreferenceSchemaV1;\n readonly persistence?: PreferencePersistence;\n readonly onDiagnostic?: (diagnostic: PreferenceDiagnostic) => void;\n}\n\nexport interface PreferenceStore extends ExternalStore<PreferenceSchemaV1> {\n setPreferences(value: PreferenceSchemaV1): void;\n dispose(): void;\n}\n\nexport interface CorePreferenceConfiguration {\n readonly preset: PresetName;\n readonly policy?: PolicyOverrides;\n}\n\nexport const defaultPreferences: PreferenceSchemaV1 = Object.freeze({\n version: 1,\n preset: \"balanced\",\n streaming: \"preset\",\n tools: \"preset\",\n});\n\nexport function preferencesToCoreConfiguration(\n value: PreferenceSchemaV1,\n): CorePreferenceConfiguration {\n const preferences = normalizePreferences(value);\n if (preferences.preset === \"completion-only\") {\n return { preset: \"completion-only\" };\n }\n const policy: PolicyOverrides = {};\n const text = mapStreaming(preferences.streaming);\n const tools = mapTools(preferences.tools);\n if (text) policy.text = text;\n if (tools) policy.tools = tools;\n return Object.keys(policy).length === 0\n ? { preset: preferences.preset }\n : { preset: preferences.preset, policy };\n}\n\nexport function createPreferenceStore(\n options: PreferenceStoreOptions = {},\n): PreferenceStore {\n const configuredDefault = options.defaultValue\n ? normalizePreferences(options.defaultValue)\n : defaultPreferences;\n const persistence = resolvePersistence(options.persistence);\n const report = (\n source: PreferenceDiagnosticSource,\n code: PreferenceDiagnosticCode,\n cause?: unknown,\n ): void => {\n const diagnostic: PreferenceDiagnostic = {\n source,\n code,\n ...(cause === undefined ? {} : { error: serializeError(cause) }),\n };\n try {\n options.onDiagnostic?.(diagnostic);\n } catch {\n // Diagnostics are observational.\n }\n };\n let current = configuredDefault;\n if (persistence?.storage) {\n try {\n const stored = persistence.storage.getItem(persistence.key);\n if (stored !== null) {\n current = parsePreferences(stored, \"storage-read\", report) ?? current;\n }\n } catch (cause) {\n report(\"storage-read\", \"operation-failed\", cause);\n }\n }\n let disposed = false;\n let eventEpoch = 0;\n const listeners = new Set<() => void>();\n let unsubscribeEvents: (() => void) | undefined;\n\n const notify = (): void => {\n for (const listener of [...listeners]) {\n try {\n listener();\n } catch {\n // External-store listeners cannot prevent other listeners.\n }\n }\n };\n const replace = (next: PreferenceSchemaV1): boolean => {\n if (samePreferences(current, next)) return false;\n current = next;\n notify();\n return true;\n };\n const handleStorageEvent = (event: PreferenceStorageEvent): void => {\n if (disposed || !persistence) return;\n const epoch = ++eventEpoch;\n let key: string | null;\n let newValue: string | null;\n let storageArea: PreferenceStorage | null | undefined;\n try {\n key = event.key;\n newValue = event.newValue;\n storageArea = event.storageArea;\n } catch (cause) {\n if (!disposed && epoch === eventEpoch) {\n report(\"storage-event\", \"operation-failed\", cause);\n }\n return;\n }\n if (disposed || epoch !== eventEpoch) return;\n try {\n if (storageArea != null && storageArea !== persistence.storage) {\n return;\n }\n if (key !== null && key !== persistence.key) return;\n if (key === null || newValue === null) {\n replace(configuredDefault);\n return;\n }\n const next = parsePreferences(newValue, \"storage-event\", report);\n if (!disposed && epoch === eventEpoch && next) replace(next);\n } catch (cause) {\n if (!disposed && epoch === eventEpoch) {\n report(\"storage-event\", \"operation-failed\", cause);\n }\n }\n };\n\n if (persistence?.events) {\n try {\n unsubscribeEvents = persistence.events.subscribe(handleStorageEvent);\n } catch (cause) {\n report(\"event-subscribe\", \"operation-failed\", cause);\n }\n }\n\n return {\n subscribe(listener) {\n if (disposed) throw new Error(\"PreferenceStore is disposed\");\n listeners.add(listener);\n let subscribed = true;\n return () => {\n if (!subscribed) return;\n subscribed = false;\n listeners.delete(listener);\n };\n },\n getSnapshot: () => current,\n getServerSnapshot: () => configuredDefault,\n setPreferences(value) {\n if (disposed) throw new Error(\"PreferenceStore is disposed\");\n const next = normalizePreferences(value);\n const changed = replace(next);\n if (!disposed && persistence?.storage && samePreferences(current, next)) {\n const serialized = JSON.stringify(next);\n if (!changed) {\n const epoch = eventEpoch;\n let matchesStoredValue = false;\n try {\n matchesStoredValue =\n persistence.storage.getItem(persistence.key) === serialized;\n } catch (cause) {\n report(\"storage-read\", \"operation-failed\", cause);\n }\n if (\n matchesStoredValue ||\n disposed ||\n epoch !== eventEpoch ||\n !samePreferences(current, next)\n ) {\n return;\n }\n }\n if (disposed || !samePreferences(current, next)) return;\n try {\n persistence.storage.setItem(persistence.key, serialized);\n } catch (cause) {\n report(\"storage-write\", \"operation-failed\", cause);\n }\n }\n },\n dispose() {\n if (disposed) return;\n disposed = true;\n eventEpoch += 1;\n listeners.clear();\n const unsubscribe = unsubscribeEvents;\n unsubscribeEvents = undefined;\n if (unsubscribe) {\n try {\n unsubscribe();\n } catch (cause) {\n report(\"event-unsubscribe\", \"operation-failed\", cause);\n }\n }\n },\n };\n}\n\ninterface ResolvedPreferencePersistence {\n readonly key: string;\n readonly storage?: PreferenceStorage;\n readonly events?: PreferenceStorageEventSource;\n}\n\nfunction resolvePersistence(\n persistence: PreferencePersistence | undefined,\n): ResolvedPreferencePersistence | undefined {\n if (!persistence) return undefined;\n if (persistence.storage) return persistence;\n const browser = getBrowserPersistence();\n return {\n key: persistence.key,\n ...(browser?.storage ? { storage: browser.storage } : {}),\n ...(persistence.events\n ? { events: persistence.events }\n : browser?.events\n ? { events: browser.events }\n : {}),\n };\n}\n\nfunction getBrowserPersistence():\n | { storage: PreferenceStorage; events: PreferenceStorageEventSource }\n | undefined {\n if (typeof window === \"undefined\") return undefined;\n try {\n const browserWindow = window;\n const storage = browserWindow.localStorage;\n if (!storage) return undefined;\n return {\n storage,\n events: {\n subscribe(listener) {\n const handle = (event: StorageEvent): void => listener(event);\n browserWindow.addEventListener(\"storage\", handle);\n return () => browserWindow.removeEventListener(\"storage\", handle);\n },\n },\n };\n } catch {\n return undefined;\n }\n}\n\nfunction parsePreferences(\n raw: string,\n source: \"storage-read\" | \"storage-event\",\n report: (\n source: PreferenceDiagnosticSource,\n code: PreferenceDiagnosticCode,\n cause?: unknown,\n ) => void,\n): PreferenceSchemaV1 | undefined {\n let value: unknown;\n try {\n value = JSON.parse(raw);\n } catch (cause) {\n report(source, \"invalid-json\", cause);\n return undefined;\n }\n try {\n return normalizePreferences(value as PreferenceSchemaV1);\n } catch (cause) {\n report(\n source,\n cause instanceof UnsupportedPreferenceVersionError\n ? \"unsupported-version\"\n : \"invalid-preference\",\n cause,\n );\n return undefined;\n }\n}\n\nclass UnsupportedPreferenceVersionError extends TypeError {}\n\nexport function normalizePreferences(\n value: PreferenceSchemaV1,\n): PreferenceSchemaV1 {\n const fields = snapshotPreferenceFields(value);\n if (fields.version !== 1)\n throw new UnsupportedPreferenceVersionError(\n \"Unsupported preference version\",\n );\n if (fields.preset === \"completion-only\") {\n if (!hasExactKeys(fields, [\"version\", \"preset\"]))\n throw new TypeError(\"Invalid completion-only preferences\");\n return Object.freeze({ version: 1, preset: \"completion-only\" });\n }\n if (\n !([\"minimal\", \"balanced\", \"verbose\"] as unknown[]).includes(fields.preset)\n )\n throw new TypeError(\"Invalid preference preset\");\n if (!hasExactKeys(fields, [\"version\", \"preset\", \"streaming\", \"tools\"]))\n throw new TypeError(\"Invalid preference fields\");\n if (!STREAMING_VALUES.includes(fields.streaming as StreamingVerbosity))\n throw new TypeError(\"Invalid streaming preference\");\n if (!TOOL_VALUES.includes(fields.tools as ToolVerbosity))\n throw new TypeError(\"Invalid tool preference\");\n return Object.freeze({\n version: 1,\n preset: fields.preset as \"minimal\" | \"balanced\" | \"verbose\",\n streaming: fields.streaming as StreamingVerbosity,\n tools: fields.tools as ToolVerbosity,\n });\n}\n\nconst STREAMING_VALUES: readonly StreamingVerbosity[] = [\n \"preset\",\n \"off\",\n \"completion\",\n \"paragraph\",\n \"sentence\",\n];\nconst TOOL_VALUES: readonly ToolVerbosity[] = [\n \"preset\",\n \"off\",\n \"failures\",\n \"status\",\n \"progress\",\n];\n\nfunction snapshotPreferenceFields(value: unknown): Record<string, unknown> {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new TypeError(\"Invalid preferences\");\n }\n try {\n const descriptors = Object.getOwnPropertyDescriptors(value);\n const fields = Object.create(null) as Record<string, unknown>;\n for (const key of Reflect.ownKeys(descriptors)) {\n if (typeof key !== \"string\")\n throw new TypeError(\"Invalid preference fields\");\n const descriptor = descriptors[key];\n if (!descriptor?.enumerable || !(\"value\" in descriptor)) {\n throw new TypeError(\n \"Preference fields must be enumerable data properties\",\n );\n }\n fields[key] = descriptor.value;\n }\n return fields;\n } catch {\n throw new TypeError(\"Invalid preferences\");\n }\n}\n\nfunction hasExactKeys(\n value: Record<string, unknown>,\n expected: readonly string[],\n): boolean {\n const keys = Object.keys(value);\n return (\n keys.length === expected.length &&\n expected.every((key) => keys.includes(key))\n );\n}\n\nexport function samePreferences(\n left: PreferenceSchemaV1,\n right: PreferenceSchemaV1,\n): boolean {\n return JSON.stringify(left) === JSON.stringify(right);\n}\n\nfunction mapStreaming(\n value: StreamingVerbosity,\n): PolicyOverrides[\"text\"] | undefined {\n if (value === \"preset\") return undefined;\n if (value === \"off\") return { strategy: \"silent\" };\n if (value === \"completion\")\n return { strategy: \"completion\", minimumCharacters: 0, maximumDelayMs: 0 };\n return { strategy: value };\n}\n\nfunction mapTools(value: ToolVerbosity): PolicyOverrides[\"tools\"] | undefined {\n if (value === \"preset\") return undefined;\n return {\n announceStart: value === \"status\" || value === \"progress\",\n announceProgress: value === \"progress\",\n announceCompletion: value === \"status\" || value === \"progress\",\n announceFailure: value !== \"off\",\n };\n}\n\nfunction serializeError(cause: unknown): Readonly<{\n name: string;\n message: string;\n}> {\n const fallback = { name: \"Error\", message: \"Unknown error\" } as const;\n try {\n if (cause instanceof Error) {\n const name = cause.name;\n const message = cause.message;\n if (typeof name !== \"string\" || typeof message !== \"string\") {\n return fallback;\n }\n return { name: name || \"Error\", message };\n }\n if (\n typeof cause === \"string\" ||\n typeof cause === \"number\" ||\n typeof cause === \"boolean\" ||\n typeof cause === \"bigint\" ||\n typeof cause === \"symbol\"\n ) {\n return { name: \"Error\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A,EACH,SAAS,OAAO;AACd,cAAU,QAAQ;AAClB,UAAM;AAAA,EACR;AAEA,SAAO;AAAA,IACL;AAAA,IACA,UAAU;AACR,UAAI,SAAU;AACd,iBAAW;AACX,UAAI;AACF,oBAAY;AAAA,MACd,UAAE;AACA,kBAAU,QAAQ;AAAA,MACpB;AAAA,IACF;AAAA,EACF;AACF;","names":["document","document","window","document","serializeError"]}
@@ -0,0 +1,146 @@
1
+ import { PresetName, PolicyOverrides, AnnouncementIntent, GenerativeA11yRuntime } from '@generative-a11y/core';
2
+
3
+ interface ExternalStore<T> {
4
+ subscribe(listener: () => void): () => void;
5
+ getSnapshot(): T;
6
+ getServerSnapshot(): T;
7
+ }
8
+ interface AttentionSnapshot {
9
+ readonly visibility: "visible" | "hidden" | "unknown";
10
+ readonly windowFocus: "focused" | "blurred" | "unknown";
11
+ readonly focusArea: "composer" | "conversation" | "elsewhere" | "none" | "unknown";
12
+ readonly newestResponse: "visible" | "outside" | "unobserved" | "unknown";
13
+ readonly mode: "foreground" | "background" | "reading-history" | "away" | "unknown";
14
+ }
15
+ interface AttentionStore extends ExternalStore<AttentionSnapshot> {
16
+ registerComposer(element: Element): () => void;
17
+ registerConversation(element: Element): () => void;
18
+ registerNewestResponse(element: Element): () => void;
19
+ dispose(): void;
20
+ }
21
+ interface AttentionStoreOptions {
22
+ document?: Document;
23
+ createIntersectionObserver?: AttentionIntersectionObserverFactory;
24
+ intersectionObserverInit?: IntersectionObserverInit;
25
+ }
26
+ interface AttentionIntersectionObserver {
27
+ observe(target: Element): void;
28
+ unobserve(target: Element): void;
29
+ disconnect(): void;
30
+ }
31
+ type AttentionIntersectionObserverFactory = (callback: IntersectionObserverCallback, options?: IntersectionObserverInit) => AttentionIntersectionObserver;
32
+ declare function createAttentionStore(options?: AttentionStoreOptions): AttentionStore;
33
+
34
+ interface FocusCapture {
35
+ readonly document: Document | null;
36
+ readonly target: Element | null;
37
+ }
38
+ interface FocusElementOptions {
39
+ preventScroll?: boolean;
40
+ }
41
+ interface RestoreFocusOptions extends FocusElementOptions {
42
+ onlyIfFocusWithin?: Element;
43
+ }
44
+ type FocusSkippedReason = "unavailable" | "cross-document" | "disconnected" | "disabled" | "hidden" | "aria-hidden" | "inert" | "missing-focus" | "guard-mismatch" | "focus-error" | "focus-not-applied";
45
+ type FocusResult = {
46
+ readonly status: "focused";
47
+ readonly target: Element;
48
+ } | {
49
+ readonly status: "skipped";
50
+ readonly reason: FocusSkippedReason;
51
+ readonly target: Element | null;
52
+ };
53
+ declare function captureFocus(selectedDocument?: Document): FocusCapture;
54
+ declare function focusElement(target: Element, options?: FocusElementOptions): FocusResult;
55
+ declare function restoreFocus(capture: FocusCapture, options?: RestoreFocusOptions): FocusResult;
56
+
57
+ type StreamingVerbosity = "preset" | "off" | "completion" | "paragraph" | "sentence";
58
+ type ToolVerbosity = "preset" | "off" | "failures" | "status" | "progress";
59
+ type PreferenceSchemaV1 = Readonly<{
60
+ version: 1;
61
+ preset: "completion-only";
62
+ }> | Readonly<{
63
+ version: 1;
64
+ preset: "minimal" | "balanced" | "verbose";
65
+ streaming: StreamingVerbosity;
66
+ tools: ToolVerbosity;
67
+ }>;
68
+ interface PreferenceStorage {
69
+ getItem(key: string): string | null;
70
+ setItem(key: string, value: string): void;
71
+ }
72
+ interface PreferenceStorageEvent {
73
+ readonly key: string | null;
74
+ readonly newValue: string | null;
75
+ readonly storageArea?: PreferenceStorage | null;
76
+ }
77
+ interface PreferenceStorageEventSource {
78
+ subscribe(listener: (event: PreferenceStorageEvent) => void): () => void;
79
+ }
80
+ type PreferenceDiagnosticSource = "storage-read" | "storage-write" | "storage-event" | "event-subscribe" | "event-unsubscribe";
81
+ type PreferenceDiagnosticCode = "operation-failed" | "invalid-json" | "invalid-preference" | "unsupported-version";
82
+ interface PreferenceDiagnostic {
83
+ readonly source: PreferenceDiagnosticSource;
84
+ readonly code: PreferenceDiagnosticCode;
85
+ readonly error?: Readonly<{
86
+ name: string;
87
+ message: string;
88
+ }>;
89
+ }
90
+ interface PreferencePersistence {
91
+ readonly key: string;
92
+ readonly storage?: PreferenceStorage;
93
+ readonly events?: PreferenceStorageEventSource;
94
+ }
95
+ interface PreferenceStoreOptions {
96
+ readonly defaultValue?: PreferenceSchemaV1;
97
+ readonly persistence?: PreferencePersistence;
98
+ readonly onDiagnostic?: (diagnostic: PreferenceDiagnostic) => void;
99
+ }
100
+ interface PreferenceStore extends ExternalStore<PreferenceSchemaV1> {
101
+ setPreferences(value: PreferenceSchemaV1): void;
102
+ dispose(): void;
103
+ }
104
+ interface CorePreferenceConfiguration {
105
+ readonly preset: PresetName;
106
+ readonly policy?: PolicyOverrides;
107
+ }
108
+ declare const defaultPreferences: PreferenceSchemaV1;
109
+ declare function preferencesToCoreConfiguration(value: PreferenceSchemaV1): CorePreferenceConfiguration;
110
+ declare function createPreferenceStore(options?: PreferenceStoreOptions): PreferenceStore;
111
+ declare function normalizePreferences(value: PreferenceSchemaV1): PreferenceSchemaV1;
112
+ declare function samePreferences(left: PreferenceSchemaV1, right: PreferenceSchemaV1): boolean;
113
+
114
+ type DOMAnnouncementMode = "auto" | "aria-notify" | "live-region";
115
+ interface DOMLiveRegions {
116
+ polite: HTMLElement;
117
+ assertive: HTMLElement;
118
+ }
119
+ interface DOMDeliveryResult {
120
+ status: "notified" | "mutated" | "unavailable" | "disposed";
121
+ method: "aria-notify" | "live-region" | "none";
122
+ channel: AnnouncementIntent["channel"];
123
+ error?: {
124
+ name: string;
125
+ message: string;
126
+ };
127
+ }
128
+ interface DOMAnnouncerOptions {
129
+ document?: Document;
130
+ mode?: DOMAnnouncementMode;
131
+ regions?: DOMLiveRegions;
132
+ onDiagnostic?: (result: DOMDeliveryResult) => void;
133
+ }
134
+ interface DOMAnnouncer {
135
+ announce(intent: AnnouncementIntent): DOMDeliveryResult;
136
+ getRegions(): DOMLiveRegions | undefined;
137
+ dispose(): void;
138
+ }
139
+ interface DOMRuntimeBinding {
140
+ announcer: DOMAnnouncer;
141
+ dispose(): void;
142
+ }
143
+ declare function createDOMAnnouncer(options?: DOMAnnouncerOptions): DOMAnnouncer;
144
+ declare function connectRuntimeToDOM(runtime: GenerativeA11yRuntime, options?: DOMAnnouncerOptions): DOMRuntimeBinding;
145
+
146
+ export { type AttentionIntersectionObserver, type AttentionIntersectionObserverFactory, type AttentionSnapshot, type AttentionStore, type AttentionStoreOptions, type CorePreferenceConfiguration, type DOMAnnouncementMode, type DOMAnnouncer, type DOMAnnouncerOptions, type DOMDeliveryResult, type DOMLiveRegions, type DOMRuntimeBinding, type ExternalStore, type FocusCapture, type FocusElementOptions, type FocusResult, type FocusSkippedReason, type PreferenceDiagnostic, type PreferenceDiagnosticCode, type PreferenceDiagnosticSource, type PreferencePersistence, type PreferenceSchemaV1, type PreferenceStorage, type PreferenceStorageEvent, type PreferenceStorageEventSource, type PreferenceStore, type PreferenceStoreOptions, type RestoreFocusOptions, type StreamingVerbosity, type ToolVerbosity, captureFocus, connectRuntimeToDOM, createAttentionStore, createDOMAnnouncer, createPreferenceStore, defaultPreferences, focusElement, normalizePreferences, preferencesToCoreConfiguration, restoreFocus, samePreferences };
@@ -0,0 +1,146 @@
1
+ import { PresetName, PolicyOverrides, AnnouncementIntent, GenerativeA11yRuntime } from '@generative-a11y/core';
2
+
3
+ interface ExternalStore<T> {
4
+ subscribe(listener: () => void): () => void;
5
+ getSnapshot(): T;
6
+ getServerSnapshot(): T;
7
+ }
8
+ interface AttentionSnapshot {
9
+ readonly visibility: "visible" | "hidden" | "unknown";
10
+ readonly windowFocus: "focused" | "blurred" | "unknown";
11
+ readonly focusArea: "composer" | "conversation" | "elsewhere" | "none" | "unknown";
12
+ readonly newestResponse: "visible" | "outside" | "unobserved" | "unknown";
13
+ readonly mode: "foreground" | "background" | "reading-history" | "away" | "unknown";
14
+ }
15
+ interface AttentionStore extends ExternalStore<AttentionSnapshot> {
16
+ registerComposer(element: Element): () => void;
17
+ registerConversation(element: Element): () => void;
18
+ registerNewestResponse(element: Element): () => void;
19
+ dispose(): void;
20
+ }
21
+ interface AttentionStoreOptions {
22
+ document?: Document;
23
+ createIntersectionObserver?: AttentionIntersectionObserverFactory;
24
+ intersectionObserverInit?: IntersectionObserverInit;
25
+ }
26
+ interface AttentionIntersectionObserver {
27
+ observe(target: Element): void;
28
+ unobserve(target: Element): void;
29
+ disconnect(): void;
30
+ }
31
+ type AttentionIntersectionObserverFactory = (callback: IntersectionObserverCallback, options?: IntersectionObserverInit) => AttentionIntersectionObserver;
32
+ declare function createAttentionStore(options?: AttentionStoreOptions): AttentionStore;
33
+
34
+ interface FocusCapture {
35
+ readonly document: Document | null;
36
+ readonly target: Element | null;
37
+ }
38
+ interface FocusElementOptions {
39
+ preventScroll?: boolean;
40
+ }
41
+ interface RestoreFocusOptions extends FocusElementOptions {
42
+ onlyIfFocusWithin?: Element;
43
+ }
44
+ type FocusSkippedReason = "unavailable" | "cross-document" | "disconnected" | "disabled" | "hidden" | "aria-hidden" | "inert" | "missing-focus" | "guard-mismatch" | "focus-error" | "focus-not-applied";
45
+ type FocusResult = {
46
+ readonly status: "focused";
47
+ readonly target: Element;
48
+ } | {
49
+ readonly status: "skipped";
50
+ readonly reason: FocusSkippedReason;
51
+ readonly target: Element | null;
52
+ };
53
+ declare function captureFocus(selectedDocument?: Document): FocusCapture;
54
+ declare function focusElement(target: Element, options?: FocusElementOptions): FocusResult;
55
+ declare function restoreFocus(capture: FocusCapture, options?: RestoreFocusOptions): FocusResult;
56
+
57
+ type StreamingVerbosity = "preset" | "off" | "completion" | "paragraph" | "sentence";
58
+ type ToolVerbosity = "preset" | "off" | "failures" | "status" | "progress";
59
+ type PreferenceSchemaV1 = Readonly<{
60
+ version: 1;
61
+ preset: "completion-only";
62
+ }> | Readonly<{
63
+ version: 1;
64
+ preset: "minimal" | "balanced" | "verbose";
65
+ streaming: StreamingVerbosity;
66
+ tools: ToolVerbosity;
67
+ }>;
68
+ interface PreferenceStorage {
69
+ getItem(key: string): string | null;
70
+ setItem(key: string, value: string): void;
71
+ }
72
+ interface PreferenceStorageEvent {
73
+ readonly key: string | null;
74
+ readonly newValue: string | null;
75
+ readonly storageArea?: PreferenceStorage | null;
76
+ }
77
+ interface PreferenceStorageEventSource {
78
+ subscribe(listener: (event: PreferenceStorageEvent) => void): () => void;
79
+ }
80
+ type PreferenceDiagnosticSource = "storage-read" | "storage-write" | "storage-event" | "event-subscribe" | "event-unsubscribe";
81
+ type PreferenceDiagnosticCode = "operation-failed" | "invalid-json" | "invalid-preference" | "unsupported-version";
82
+ interface PreferenceDiagnostic {
83
+ readonly source: PreferenceDiagnosticSource;
84
+ readonly code: PreferenceDiagnosticCode;
85
+ readonly error?: Readonly<{
86
+ name: string;
87
+ message: string;
88
+ }>;
89
+ }
90
+ interface PreferencePersistence {
91
+ readonly key: string;
92
+ readonly storage?: PreferenceStorage;
93
+ readonly events?: PreferenceStorageEventSource;
94
+ }
95
+ interface PreferenceStoreOptions {
96
+ readonly defaultValue?: PreferenceSchemaV1;
97
+ readonly persistence?: PreferencePersistence;
98
+ readonly onDiagnostic?: (diagnostic: PreferenceDiagnostic) => void;
99
+ }
100
+ interface PreferenceStore extends ExternalStore<PreferenceSchemaV1> {
101
+ setPreferences(value: PreferenceSchemaV1): void;
102
+ dispose(): void;
103
+ }
104
+ interface CorePreferenceConfiguration {
105
+ readonly preset: PresetName;
106
+ readonly policy?: PolicyOverrides;
107
+ }
108
+ declare const defaultPreferences: PreferenceSchemaV1;
109
+ declare function preferencesToCoreConfiguration(value: PreferenceSchemaV1): CorePreferenceConfiguration;
110
+ declare function createPreferenceStore(options?: PreferenceStoreOptions): PreferenceStore;
111
+ declare function normalizePreferences(value: PreferenceSchemaV1): PreferenceSchemaV1;
112
+ declare function samePreferences(left: PreferenceSchemaV1, right: PreferenceSchemaV1): boolean;
113
+
114
+ type DOMAnnouncementMode = "auto" | "aria-notify" | "live-region";
115
+ interface DOMLiveRegions {
116
+ polite: HTMLElement;
117
+ assertive: HTMLElement;
118
+ }
119
+ interface DOMDeliveryResult {
120
+ status: "notified" | "mutated" | "unavailable" | "disposed";
121
+ method: "aria-notify" | "live-region" | "none";
122
+ channel: AnnouncementIntent["channel"];
123
+ error?: {
124
+ name: string;
125
+ message: string;
126
+ };
127
+ }
128
+ interface DOMAnnouncerOptions {
129
+ document?: Document;
130
+ mode?: DOMAnnouncementMode;
131
+ regions?: DOMLiveRegions;
132
+ onDiagnostic?: (result: DOMDeliveryResult) => void;
133
+ }
134
+ interface DOMAnnouncer {
135
+ announce(intent: AnnouncementIntent): DOMDeliveryResult;
136
+ getRegions(): DOMLiveRegions | undefined;
137
+ dispose(): void;
138
+ }
139
+ interface DOMRuntimeBinding {
140
+ announcer: DOMAnnouncer;
141
+ dispose(): void;
142
+ }
143
+ declare function createDOMAnnouncer(options?: DOMAnnouncerOptions): DOMAnnouncer;
144
+ declare function connectRuntimeToDOM(runtime: GenerativeA11yRuntime, options?: DOMAnnouncerOptions): DOMRuntimeBinding;
145
+
146
+ export { type AttentionIntersectionObserver, type AttentionIntersectionObserverFactory, type AttentionSnapshot, type AttentionStore, type AttentionStoreOptions, type CorePreferenceConfiguration, type DOMAnnouncementMode, type DOMAnnouncer, type DOMAnnouncerOptions, type DOMDeliveryResult, type DOMLiveRegions, type DOMRuntimeBinding, type ExternalStore, type FocusCapture, type FocusElementOptions, type FocusResult, type FocusSkippedReason, type PreferenceDiagnostic, type PreferenceDiagnosticCode, type PreferenceDiagnosticSource, type PreferencePersistence, type PreferenceSchemaV1, type PreferenceStorage, type PreferenceStorageEvent, type PreferenceStorageEventSource, type PreferenceStore, type PreferenceStoreOptions, type RestoreFocusOptions, type StreamingVerbosity, type ToolVerbosity, captureFocus, connectRuntimeToDOM, createAttentionStore, createDOMAnnouncer, createPreferenceStore, defaultPreferences, focusElement, normalizePreferences, preferencesToCoreConfiguration, restoreFocus, samePreferences };