type ComposedFocusMode='programmatic'|'tabbable';type FocusTraversalTruncationReason='depth'|'nodes';export interface ComposedFocusCollectionOptions{ /** Includes managed/native actions at `tabindex=-1`, or only sequential Tab stops. */ mode?:ComposedFocusMode; /** Whether an Element root can itself be returned. Defaults to true. */ includeRoot?:boolean; /** Maximum composed descendant depth. */ maxDepth?:number; /** Total element-work ceiling, shared across slots and open shadow roots. */ maxNodes?:number; /** Skips composed-ancestor validation for the supplied root only. */ skipRootAncestorValidation?:boolean;}export interface ComposedFocusCollectionResult{elements:HTMLElement[];truncated:boolean;truncationReasons:readonly FocusTraversalTruncationReason[];visitedElements:number;}export interface ComposedFocusRepairSnapshot{readonly activeElement:Element;readonly candidate:HTMLElement;readonly document:Document;readonly owner:Element;} /** * Where focus should land when the node holding it is about to disappear: a single target, or an * ordered fallback list tried in order until one is actually focusable. Ordering is the caller's * policy -- `[survivingSibling, stableToolbar]` expresses "nearest survivor, else the toolbar", * `[header]` expresses "always this fixed target". * * `null`, `undefined`, an empty list and an all-nullish list all mean the same thing -- no target, * so leave focus alone -- which is what lets a caller pass `rows[index]` or an optional query * result straight through without pre-checking it. */ type ComposedFocusRepairTargets=HTMLElement|null|undefined|readonly(HTMLElement|null|undefined)[]; /** * Repair targets, or a thunk producing them. A thunk defers the lookup to the moment the repair is * applied, so a caller can name nodes that only exist after the render which removed the focus * holder has committed. */ export type ComposedFocusRepairTargetSource=ComposedFocusRepairTargets|(()=>ComposedFocusRepairTargets); /** Realm-neutral classification of native actions and elements carrying an ARIA widget role. */ export declare function isSemanticActionElement(element:Element):element is HTMLElement; /** * Realm-neutral classification of semantic actions and authored sequential focus stops. A plain * `tabindex="-1"` remains programmatically focusable without becoming an action; native and ARIA * actions retain their semantics when a roving owner assigns `-1`. */ export declare function isActionableElement(element:Element):element is HTMLElement; /** Whether a genuine HTML element can currently receive focus through its composed branch. */ export declare function isComposedFocusAvailable(element:Element,options?:Pick):element is HTMLElement; /** Captures a repair only when deep focus is currently inside the branch about to disappear. */ export declare function captureComposedFocusRepair(owner:Element,candidate:HTMLElement|null):ComposedFocusRepairSnapshot|null; /** * Applies a captured repair unless focus moved to a newer external target. Body/document fallback * after removal is treated as the captured focus disappearing, not as an intentional new target. * * `candidateOverride` accepts an ordered fallback list (or a thunk producing one), tried in order * until one both passes `isComposedFocusAvailable()` -- the single predicate that already excludes * `inert`, an `inert` composed ancestor, `hidden`, `aria-hidden`, `:disabled` and unrendered * branches -- and actually takes focus. An empty, all-nullish or nullish list is a safe no-op that * returns false without touching focus, so a caller never has to pre-check its own fallback list. * That includes an explicitly passed `undefined`: only an *omitted* second argument means "use the * captured candidate". Hence the `arguments.length` read rather than a default parameter -- a * default also fires on an explicit `undefined`, so `applyComposedFocusRepair(repair, rows[index])` * under `noUncheckedIndexedAccess` would typecheck and then silently focus the captured candidate * for a caller who meant "no surviving row, leave focus alone". */ export declare function applyComposedFocusRepair(snapshot:ComposedFocusRepairSnapshot,candidateOverride?:ComposedFocusRepairTargetSource):boolean; /** * Focuses the first of an ordered target list that both passes `isComposedFocusAvailable()` and * actually ends up holding focus, and reports whether any of them did. * * Unconditional, and that is the whole difference from `repairComposedFocus()`: it makes no * judgement about where focus currently is. That fits a component handing focus over on its *own* * terminal action -- the control the user just activated is about to unmount or become `disabled`, * so the handoff has to happen whether or not that control is provably the focused one. Use * `repairComposedFocus()` instead whenever the move must be declined because focus sits somewhere * unrelated. * * Both halves of the check are load-bearing. `isComposedFocusAvailable()` is the one predicate that * already excludes `inert`, an `inert` composed ancestor, `hidden`, `aria-hidden`, `:disabled` and * unrendered branches -- an `inert` element refuses `focus()` silently, so a hand-rolled * `a ?? b)?.focus()` chain strands the user on `` at exactly the moment something important * was announced. Availability alone is not sufficient either: a plain `
` with no `tabindex` is * "available" and still refuses focus, so each attempt is verified by reading focus back before the * next candidate is tried. * * An empty, all-nullish or nullish list is a safe no-op returning false, so a caller never has to * pre-check its own fallback list. */ export declare function focusFirstAvailable(targets:ComposedFocusRepairTargetSource):boolean; /** * Capture-then-apply in one synchronous call, for the case where the branch that holds focus is * about to be removed or hidden by the render this call precedes (a collapsing disclosure, a * closing panel, a row leaving a controlled list). * * Focus outside `owner`'s composed subtree is left strictly alone -- the return is false and no * target is touched -- so appending or reordering content never steals focus from an unrelated * control. `owner` is the host element rather than its `ShadowRoot` deliberately: composed * containment also covers the host's slotted light-DOM children, which a `ShadowRoot`-rooted * search would miss. * * Call this *before* the branch goes, not after. Focus that has already fallen back to the body is * outside `owner` and is therefore declined -- unlike `applyComposedFocusRepair()`, which reads a * body fallback as the captured focus disappearing because its snapshot recorded where focus was * beforehand. This one has no such snapshot, so it cannot tell that case apart from focus that was * never inside `owner` at all. * * When the outcome depends on whether a *specific* node survives a render that has not committed * yet, use `captureComposedFocusRepair()` now and `applyComposedFocusRepair()` once the render has * settled instead; this helper resolves both halves immediately. * * @returns true only when focus actually moved to one of the fallback targets. */ export declare function repairComposedFocus(owner:Element,fallbackTargets:ComposedFocusRepairTargetSource):boolean; /** * Resolves once a reactive host has had a realistic chance to commit an update it scheduled * during the task that just ran -- the exact window `deferComposedFocusRepair()` waits out before * re-resolving a return-focus thunk. One microtask, then one animation frame: * * - A microtask covers Lit (this library's own components included), Vue's `nextTick`, and * Svelte's `tick()` -- all three schedule their reactive flush as a microtask off the change * that just happened, so by the time a microtask callback of our own runs, one already queued * ahead of it (because the host's property write happened first, in the same synchronous turn * that led here) has already committed its DOM mutation. * - A following animation frame covers React's default automatic batching, which commits a * click-driven state update synchronously before the browser's next paint rather than * guaranteed inside a single microtask tick. `requestAnimationFrame` runs after the browser has * finished any pending style/layout/paint work for the current frame, so a commit that landed * "before paint" has necessarily already happened by the time this callback fires. * * One evaluation, not a poll loop: a return-focus thunk is "ask again once you have had a * chance", not "keep asking until you succeed" -- see `deferComposedFocusRepair()`'s own doc * comment for the give-up contract that depends on this being a single, bounded wait. */ export declare function nextHostUpdateOpportunity():Promise; /** * Captures a repair on `bridge` right now (the synchronous parking spot a terminal focus handoff * already moved focus to, so there is no focus gap), then -- after `nextHostUpdateOpportunity()` * -- calls `resolveTarget()` again and moves focus to whatever it names if that has since become * connected and focusable, without overriding a newer, genuinely different focus move. * * This exists for exactly one shape: a return-focus thunk whose whole documented reason to exist * is naming a control the host is expected to *re-create* on the way back (an async re-render), so * calling it once, synchronously, at handoff time necessarily finds nothing yet. Call this only * after that first synchronous resolution has already failed and landed focus on `bridge` -- * an immediately-resolving thunk or a plain element value never reaches this function, so * behavior for those already-working cases is unchanged. * * Declines exactly as `applyComposedFocusRepair()` already does: focus that moved to some other * real element outside `owner` in the meantime is left alone. Focus that was lost along with * `owner`'s own branch (the host removed the bridge's entire component, dropping focus to * ``) is NOT treated as "moved on" -- that disappearance is precisely the case a deferred * thunk exists to recover from. * * Bounded and quiet: exactly one deferred re-resolution; a target that still does not exist, is * not connected, or refuses focus (`inert`, removed, hidden) simply leaves focus wherever the * synchronous parking step already put it. */ export declare function deferComposedFocusRepair(owner:Element,bridge:HTMLElement,resolveTarget:()=>HTMLElement|null):void; /** * Iteratively collects composed focus targets with a shared depth/node budget. Programmatic mode * retains native and ARIA-managed actions after a roving owner assigns `tabindex=-1`; tabbable mode * models sequential browser order, including one stop per native radio group. */ export declare function collectComposedFocusTargets(root:Element|ShadowRoot,options?:ComposedFocusCollectionOptions):ComposedFocusCollectionResult; /** Internal companion used by overlay autofocus delegation with the same bounded traversal. */ export declare function collectComposedAutofocusElements(root:Element|ShadowRoot,options?:Omit):ComposedFocusCollectionResult;export{};