@bevelo/dom 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +40 -2
- package/dist/index.cjs +4709 -0
- package/dist/index.d.cts +1854 -0
- package/dist/index.d.ts +1854 -0
- package/dist/index.js +4583 -0
- package/package.json +38 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1854 @@
|
|
|
1
|
+
import { DismissReason, DismissReason as DismissReason$1, ENDING_STYLE_ATTRIBUTE, LayerPhase, STARTING_STYLE_ATTRIBUTE } from "@bevelo/runtime";
|
|
2
|
+
type Cleanup = () => void;
|
|
3
|
+
/**
|
|
4
|
+
* Whether Tab stops on the element. A radio group is one stop: its checked
|
|
5
|
+
* radio, or every radio while the checked one cannot take focus (it is behind
|
|
6
|
+
* a modal, say), which is what the browser does.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isTabbable(element: Element): element is HTMLElement;
|
|
9
|
+
/**
|
|
10
|
+
* The tabbable elements inside a root, in document order, shadow trees included.
|
|
11
|
+
*
|
|
12
|
+
* Tabbable, not merely focusable: tabindex -1 is skipped (it is focusable
|
|
13
|
+
* programmatically, which is what an overlay root and its items use), hidden,
|
|
14
|
+
* inert, aria-hidden and disabled elements are skipped, a radio group is one
|
|
15
|
+
* stop, and a native control's browser-imposed tabindex is respected.
|
|
16
|
+
*/
|
|
17
|
+
export declare function focusables(root: Element): HTMLElement[];
|
|
18
|
+
/** The tabbable elements inside a root in the order Tab visits them. */
|
|
19
|
+
export declare function tabOrder(root: Element): HTMLElement[];
|
|
20
|
+
/**
|
|
21
|
+
* The first tabbable element after `node` in document order, skipping anything
|
|
22
|
+
* inside `skip`, like the panel that is handing focus on.
|
|
23
|
+
*
|
|
24
|
+
* Document order, not Tab order: a positive tabindex further down the page is
|
|
25
|
+
* not "the element after" anything, even though the browser would visit it first.
|
|
26
|
+
*/
|
|
27
|
+
export declare function nextTabbable(node: Node, skip?: Element): HTMLElement | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* What a dismissal callback may answer.
|
|
30
|
+
*
|
|
31
|
+
* `false` declines the dismissal: an outside press then continues to whatever
|
|
32
|
+
* the user aimed at, and Escape is left unprevented so a host-level shortcut can
|
|
33
|
+
* still see it. Anything else means "handled".
|
|
34
|
+
*/
|
|
35
|
+
export type DismissHandler = (reason: DismissReason$1, event: Event) => boolean | void;
|
|
36
|
+
export interface LayerOptions {
|
|
37
|
+
/**
|
|
38
|
+
* While a modal layer is open the rest of the page is inert and page scroll is
|
|
39
|
+
* locked; releasing the layer restores both. A non-modal layer only sits on
|
|
40
|
+
* the stack (a popover, a tooltip) and leaves the page interactive.
|
|
41
|
+
*/
|
|
42
|
+
modal?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Asked when this layer is the top one and Escape arrives, or when
|
|
45
|
+
* `layer.dismiss` is called. It is not asked for outside presses: those are
|
|
46
|
+
* delivered through `bindDismissals`, which knows the subtree to test.
|
|
47
|
+
*/
|
|
48
|
+
onDismiss?: (reason: DismissReason$1) => boolean | void;
|
|
49
|
+
}
|
|
50
|
+
/** A handle on one entry of the layer stack. */
|
|
51
|
+
export interface Layer {
|
|
52
|
+
/** Stable, increasing; useful for ordering work without comparing elements. */
|
|
53
|
+
readonly id: number;
|
|
54
|
+
/** Dismisses this layer directly, wherever it sits in the stack. Callers use
|
|
55
|
+
* it when the component, not the user, decided to close. The event handed to
|
|
56
|
+
* dismissals is synthetic because no gesture caused it. */
|
|
57
|
+
dismiss(reason: DismissReason$1): void;
|
|
58
|
+
/** Removes the layer and restores whatever opening it changed. Idempotent. */
|
|
59
|
+
release(): void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The element portalled parts are appended to: one lazily created
|
|
63
|
+
* `<div data-ui-layer-root>` per document, as the last child of body.
|
|
64
|
+
*
|
|
65
|
+
* A shared root rather than a per-overlay parent, because stacking order is
|
|
66
|
+
* document order in the layer root and a per-overlay parent would need z-index
|
|
67
|
+
* bookkeeping to reproduce it. The root is re-appended when the host emptied
|
|
68
|
+
* body: that is a host choice we should follow, not a detached page.
|
|
69
|
+
*/
|
|
70
|
+
export declare function layerRoot(doc?: Document): HTMLElement;
|
|
71
|
+
/**
|
|
72
|
+
* The layer root when one already exists, without creating it.
|
|
73
|
+
*
|
|
74
|
+
* Read paths — part resolution, dismissal scans — must not materialize the
|
|
75
|
+
* portal container just to look inside it, so they ask this instead of
|
|
76
|
+
* `layerRoot`, which appends the element on first call.
|
|
77
|
+
*/
|
|
78
|
+
export declare function existingLayerRoot(doc: Document): HTMLElement | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Points the portal root at a host-supplied element (a shadow root's container,
|
|
81
|
+
* a test container). `undefined` restores the default body-level root.
|
|
82
|
+
*/
|
|
83
|
+
export declare function setLayerRoot(root: HTMLElement | undefined): void;
|
|
84
|
+
/**
|
|
85
|
+
* Records the natural parent of a portalled node. The renderer calls this; a
|
|
86
|
+
* component never should.
|
|
87
|
+
*
|
|
88
|
+
* Once a description is appended to the layer root the DOM cannot answer "which
|
|
89
|
+
* component owns this", so dismissal keeps the answer here. `null` forgets the
|
|
90
|
+
* node, which is what removal does.
|
|
91
|
+
*/
|
|
92
|
+
export declare function registerPortal(node: Element, owner: Element | null): void;
|
|
93
|
+
/**
|
|
94
|
+
* The element a portalled node was rendered from, if it is one.
|
|
95
|
+
*
|
|
96
|
+
* Part resolution and dismissal both need "which component does this node
|
|
97
|
+
* belong to" for elements that no longer sit in their owner's subtree; the
|
|
98
|
+
* DOM cannot answer it once the node lives under the layer root, so the
|
|
99
|
+
* answer lives here.
|
|
100
|
+
*/
|
|
101
|
+
export declare function portalOwnerOf(node: Element): Element | undefined;
|
|
102
|
+
export declare function pushLayer(element: HTMLElement, options?: LayerOptions): Layer;
|
|
103
|
+
/** The stacked elements, bottom to top (optionally scoped to `doc`). */
|
|
104
|
+
export declare function layers(doc?: Document): readonly HTMLElement[];
|
|
105
|
+
/** Whether this element is the top layer of its document. */
|
|
106
|
+
export declare function isTopLayer(element: HTMLElement): boolean;
|
|
107
|
+
/** Whether this runtime supports the native HTML Popover Top Layer (`popover="manual"`). */
|
|
108
|
+
export declare function supportsTopLayer(): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Promotes a connected overlay element into the browser's Top Layer via
|
|
111
|
+
* `popover="manual"` + `showPopover()` when supported, returning a cleanup that
|
|
112
|
+
* hides and restores the element's prior `popover` attribute.
|
|
113
|
+
*/
|
|
114
|
+
export declare function promoteTopLayer(element: HTMLElement): () => void;
|
|
115
|
+
/** Whether a node sits inside a persistent layer. */
|
|
116
|
+
export declare function inPersistentLayer(node: Node | null | undefined): boolean;
|
|
117
|
+
/** Marks an element as a persistent layer until the returned cleanup runs. */
|
|
118
|
+
export declare function bindPersistentLayer(element: HTMLElement): () => void;
|
|
119
|
+
/**
|
|
120
|
+
* How long a close may be deferred when the environment cannot report its
|
|
121
|
+
* animations (jsdom) or an animation never finishes. 200 ms is a short close, so a
|
|
122
|
+
* leaking attribute cannot outlive a frame the user can see by more than that.
|
|
123
|
+
*/
|
|
124
|
+
export declare const PRESENCE_TIMEOUT = 200;
|
|
125
|
+
/**
|
|
126
|
+
* The reduced-motion answer for a document.
|
|
127
|
+
*
|
|
128
|
+
* The answer is the platform foundation's media snapshot, read through its own
|
|
129
|
+
* adapter: this module does not open a media query itself, because a component
|
|
130
|
+
* that asks `matchMedia` is a component that can disagree with the one next to
|
|
131
|
+
* it about the same frame. A document with no window, or a window that cannot be
|
|
132
|
+
* asked, is not a document that says "no motion" — it is a document that cannot
|
|
133
|
+
* answer, and the snapshot's fallback (no preference expressed) is what it
|
|
134
|
+
* reports.
|
|
135
|
+
*/
|
|
136
|
+
export declare function prefersReducedMotion(doc?: Document): boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Whether the current device offers a hover-capable pointer.
|
|
139
|
+
*
|
|
140
|
+
* This is a DOM fact, not primitive policy: adapters read it here and pass the
|
|
141
|
+
* answer into overlays as input. A missing or unanswerable window reports false,
|
|
142
|
+
* which keeps a hover-only affordance closed when nobody can prove hover exists.
|
|
143
|
+
*/
|
|
144
|
+
export declare function hoverCapability(view?: Window | undefined): boolean;
|
|
145
|
+
export interface SettleOptions {
|
|
146
|
+
/** Longest the wait may last, in ms. Defaults to {@link PRESENCE_TIMEOUT}. */
|
|
147
|
+
timeout?: number;
|
|
148
|
+
/** The host's reduced-motion answer; omitted, the document's media query decides. */
|
|
149
|
+
reducedMotion?: boolean;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Runs `done` once the element's running animations have finished, after the
|
|
153
|
+
* exit has been painted.
|
|
154
|
+
*
|
|
155
|
+
* The wait is armed after a paint on purpose: read inside the same task as the
|
|
156
|
+
* attribute change, `getAnimations()` does not see the transition that change
|
|
157
|
+
* started, and a settle scheduled from it would cut the animation short.
|
|
158
|
+
*
|
|
159
|
+
* The fallbacks, in order: reduced motion settles on the next frame; an
|
|
160
|
+
* environment without `getAnimations` (jsdom) settles on the timeout, so a test
|
|
161
|
+
* can advance it rather than hang; an element with no animations at all settles
|
|
162
|
+
* on the next frame rather than waiting out a timer nobody needs. The returned
|
|
163
|
+
* cleanup cancels all of them, which is what an interrupted exit calls.
|
|
164
|
+
*/
|
|
165
|
+
export declare function whenSettled(element: HTMLElement, done: () => void, options?: SettleOptions): Cleanup;
|
|
166
|
+
/**
|
|
167
|
+
* Starts an element's entry: `data-starting-style` for one painted frame.
|
|
168
|
+
*
|
|
169
|
+
* The attribute has to be *seen* once — it is the style a transition starts
|
|
170
|
+
* from — so it is cleared after the frame that painted it. Returns a cleanup
|
|
171
|
+
* that clears it early, for an element removed mid-entry.
|
|
172
|
+
*/
|
|
173
|
+
export declare function beginEnter(element: HTMLElement): Cleanup;
|
|
174
|
+
/** What a layer's presence helper exposes. */
|
|
175
|
+
export interface LayerPresence {
|
|
176
|
+
/**
|
|
177
|
+
* Reconciles the phase with the layer's current open state. It does nothing
|
|
178
|
+
* when the open state is the one it last acted on, so a caller may run it as
|
|
179
|
+
* often as it likes.
|
|
180
|
+
*
|
|
181
|
+
* Call it when the open state changes, before the renderer commits it: the
|
|
182
|
+
* phase then reaches the same render as the open value, and the closing
|
|
183
|
+
* render already carries the exit instead of `hidden`. A renderer that
|
|
184
|
+
* commits first hides the layer, and any style read before the next commit
|
|
185
|
+
* (a focus move, a top-layer change, this helper's own motion check) records
|
|
186
|
+
* it as `display: none`, which a CSS transition cannot start from. Call it
|
|
187
|
+
* after every patch too, from the layer element's `ref`, for a host that has
|
|
188
|
+
* no hook on the state change.
|
|
189
|
+
*/
|
|
190
|
+
update(): void;
|
|
191
|
+
/** Stops pending timers and clears the attributes this helper set. */
|
|
192
|
+
stop(): void;
|
|
193
|
+
}
|
|
194
|
+
export interface LayerPresenceOptions {
|
|
195
|
+
/** Reads whether the layer should be showing; called from {@link LayerPresence.update}. */
|
|
196
|
+
isOpen(): boolean;
|
|
197
|
+
/** Receives every phase change; the component stores it in a signal its view
|
|
198
|
+
* renders the attributes and `hidden` from. */
|
|
199
|
+
phase(next: LayerPhase): void;
|
|
200
|
+
/** Longest a close may wait, in ms. Defaults to {@link PRESENCE_TIMEOUT}. */
|
|
201
|
+
timeout?: number;
|
|
202
|
+
/** The host's reduced-motion answer; omitted, the document's media query decides. */
|
|
203
|
+
reducedMotion?: () => boolean;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Binds a layer element's open/closed state to its entry and exit phases.
|
|
207
|
+
*
|
|
208
|
+
* The element is not written to here: the phase the component stores is what its
|
|
209
|
+
* view renders, so `data-starting-style`, `data-ending-style`, `inert` and the
|
|
210
|
+
* deferred `hidden` all survive a patch during the exit (a host re-render would
|
|
211
|
+
* otherwise hide the layer halfway through its own animation).
|
|
212
|
+
*
|
|
213
|
+
* A stylesheet that declares no motion for the closed layer gets a one-frame
|
|
214
|
+
* exit: the motion is read on the frame after the close, since only the closed
|
|
215
|
+
* element shows what the closed state animates. An environment that cannot say
|
|
216
|
+
* what its stylesheets declare (jsdom) gets the timeout, so the lifecycle stays
|
|
217
|
+
* testable.
|
|
218
|
+
*/
|
|
219
|
+
export declare function bindLayerPresence(element: HTMLElement, options: LayerPresenceOptions): LayerPresence;
|
|
220
|
+
/** How much of an outside press a layer keeps from the page. See {@link DismissalOptions.consume}. */
|
|
221
|
+
export type OutsidePressConsumption = "all" | "pointerdown" | "none";
|
|
222
|
+
/** How a layer bound with {@link bindDismissals} hears its dismissals. */
|
|
223
|
+
export interface DismissalOptions {
|
|
224
|
+
/**
|
|
225
|
+
* When an outside press dismisses: at `"pointerdown"`, or at `"click"`, once
|
|
226
|
+
* a primary-button press that started outside is also released outside, so a
|
|
227
|
+
* text selection dragged out of a field or a press that ends inside keeps the
|
|
228
|
+
* layer open. A dialog over a backdrop wants `"click"`.
|
|
229
|
+
* @defaultValue "pointerdown"
|
|
230
|
+
*/
|
|
231
|
+
readonly outsidePress?: "pointerdown" | "click";
|
|
232
|
+
/**
|
|
233
|
+
* Stops an outside press at this layer, so the layers beneath it stay open,
|
|
234
|
+
* like a modal dialog whose backdrop was pressed.
|
|
235
|
+
* @defaultValue true for a layer pushed with `modal: true`, else false
|
|
236
|
+
*/
|
|
237
|
+
readonly shield?: boolean;
|
|
238
|
+
/**
|
|
239
|
+
* How much of an outside press this layer accepted is kept from the page.
|
|
240
|
+
* `"all"`: it moves no focus and its click is swallowed, so it only closes
|
|
241
|
+
* the layer, as a modal layer wants. `"pointerdown"`: it moves no focus, but
|
|
242
|
+
* its click still lands. `"none"`: the press both closes the layer and does
|
|
243
|
+
* what the user aimed at, as a non-modal popover wants.
|
|
244
|
+
* @defaultValue "pointerdown"
|
|
245
|
+
*/
|
|
246
|
+
readonly consume?: OutsidePressConsumption;
|
|
247
|
+
/**
|
|
248
|
+
* Elements that count as inside the layer besides its element, like its
|
|
249
|
+
* trigger: a press or focus there is neither an outside press nor focus leaving.
|
|
250
|
+
*/
|
|
251
|
+
readonly inside?: () => readonly (Element | null | undefined)[];
|
|
252
|
+
/**
|
|
253
|
+
* Whether Escape is this layer's right now, asked while it is the top layer.
|
|
254
|
+
* When not, the key is left to the page. A non-modal dialog answers whether
|
|
255
|
+
* focus is inside it.
|
|
256
|
+
*/
|
|
257
|
+
readonly takesEscape?: () => boolean;
|
|
258
|
+
/**
|
|
259
|
+
* Called when focus leaves the layer: it moves to an element outside the
|
|
260
|
+
* layer, its `inside` elements and the layers portalled from it, or Tab moves
|
|
261
|
+
* it out of the page. With `windowBlur`, also when the window loses focus.
|
|
262
|
+
* Omitted, focus leaving closes nothing.
|
|
263
|
+
*/
|
|
264
|
+
readonly onFocusOut?: (event: Event) => void;
|
|
265
|
+
/**
|
|
266
|
+
* What the window losing focus means, delivered through `onFocusOut`:
|
|
267
|
+
* `"iframe"` only when focus went into an iframe outside the layer (a click
|
|
268
|
+
* into an embed never reaches the page), `"always"` for any window blur, so
|
|
269
|
+
* switching windows closes it too.
|
|
270
|
+
* @defaultValue "never"
|
|
271
|
+
*/
|
|
272
|
+
readonly windowBlur?: "always" | "iframe" | "never";
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Binds Escape and outside-press dismissal to one element.
|
|
276
|
+
*
|
|
277
|
+
* The element is the boundary: a press inside it (or inside a node portalled
|
|
278
|
+
* from it, or an `inside` element) is not an outside press. When the element
|
|
279
|
+
* is already a layer this adds a dismissal handler to it instead of stacking a
|
|
280
|
+
* second entry, so an overlay that used `pushLayer` for modal behaviour keeps
|
|
281
|
+
* one place in the stack.
|
|
282
|
+
*
|
|
283
|
+
* Escape is delivered only when this element is the top layer. An outside press
|
|
284
|
+
* goes to every layer it is outside of, top down, until a layer that contains
|
|
285
|
+
* it or one that shields the layers beneath, so a press outside a popover and
|
|
286
|
+
* the menu open from it closes both.
|
|
287
|
+
*/
|
|
288
|
+
export declare function bindDismissals(element: HTMLElement, onDismiss: (reason: DismissReason$1, event: Event) => boolean | void, options?: DismissalOptions): () => void;
|
|
289
|
+
/**
|
|
290
|
+
* The element the document has focus in, or null.
|
|
291
|
+
*
|
|
292
|
+
* Components ask this instead of reading `document.activeElement` themselves:
|
|
293
|
+
* this module is the one place that knows which document a tree belongs to, and
|
|
294
|
+
* a component reading the global would be wrong inside a shadow root or an
|
|
295
|
+
* iframe the platform was pointed at.
|
|
296
|
+
*/
|
|
297
|
+
export declare function activeElement(doc?: Document): Element | null;
|
|
298
|
+
/**
|
|
299
|
+
* Whether an element is the focused one, or carries focus itself.
|
|
300
|
+
*
|
|
301
|
+
* `matches(":focus")` covers the case `activeElement` cannot: inside a shadow
|
|
302
|
+
* tree `activeElement` is the shadow host, so the node that actually has focus
|
|
303
|
+
* is only visible to the selector.
|
|
304
|
+
*/
|
|
305
|
+
export declare function isFocused(element: Element): boolean;
|
|
306
|
+
export interface FocusFirstOptions {
|
|
307
|
+
/** Focused when the root contains nothing tabbable (a fallback button, or the
|
|
308
|
+
* overlay's own trigger when focus cannot go inside). */
|
|
309
|
+
fallback?: HTMLElement;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Focuses the first tabbable descendant, else the fallback, else the root when
|
|
313
|
+
* the root itself opted into focus with a tabindex. Returns what it focused, so
|
|
314
|
+
* a caller can report "focus could not enter" without reading activeElement.
|
|
315
|
+
*
|
|
316
|
+
* The root is a last resort rather than the first choice: a dialog root with
|
|
317
|
+
* tabindex -1 is where focus goes only when there is nothing inside it.
|
|
318
|
+
*/
|
|
319
|
+
export declare function focusFirst(root: Element, options?: FocusFirstOptions): HTMLElement | undefined;
|
|
320
|
+
/**
|
|
321
|
+
* Keeps Tab inside a root and pulls back focus that escaped it.
|
|
322
|
+
*
|
|
323
|
+
* The listeners are on the document, capture phase, because focus can leave the
|
|
324
|
+
* root without a keydown inside it (a programmatic focus, or a pointer landing
|
|
325
|
+
* on a page area that is not inert). Tab wraps at the ends of Tab order, not
|
|
326
|
+
* document order: a positive tabindex comes first, a shadow root orders its own
|
|
327
|
+
* stops, and a radio group is one stop. Between the ends the browser moves
|
|
328
|
+
* focus, except across a positive tabindex, which the trap steps onto and off
|
|
329
|
+
* itself because the browser would leave for the page's own positive stops.
|
|
330
|
+
*
|
|
331
|
+
* Focus in a layer portalled from the root (a menu opened inside it) is inside
|
|
332
|
+
* the root: the trap neither pulls it back nor takes that layer's Tab.
|
|
333
|
+
*
|
|
334
|
+
* Each layer owns its trap, and the traps of a document share one rule: the
|
|
335
|
+
* innermost connected trap is the only one that may move focus or claim Tab.
|
|
336
|
+
* That is what keeps two modal overlays from calling each other's focus handler
|
|
337
|
+
* in a loop; a single modal behaves exactly as before, because it is the only
|
|
338
|
+
* trap and therefore the innermost one.
|
|
339
|
+
*/
|
|
340
|
+
export declare function trapFocus(root: HTMLElement): () => void;
|
|
341
|
+
/**
|
|
342
|
+
* Moves Tab between a trigger and a panel portalled away from it, so the panel
|
|
343
|
+
* sits in the page's Tab order right after its trigger, wherever it renders.
|
|
344
|
+
*
|
|
345
|
+
* While bound: Tab from the trigger enters the panel's first stop, Shift+Tab
|
|
346
|
+
* from the panel's first stop (or the panel itself) goes back to the trigger,
|
|
347
|
+
* and Tab from its last stop goes to the first tabbable element after the
|
|
348
|
+
* trigger in document order. With nothing after the trigger, Tab is left to the
|
|
349
|
+
* browser, which moves focus out of the page. Call it while the panel is open
|
|
350
|
+
* and non-modal; the returned cleanup removes the listeners.
|
|
351
|
+
*/
|
|
352
|
+
export declare function bindFocusFlow(panel: HTMLElement, trigger: () => HTMLElement | null | undefined): () => void;
|
|
353
|
+
/**
|
|
354
|
+
* What a popup tells its release about the focus it is handing back.
|
|
355
|
+
*
|
|
356
|
+
* Deliberately not exported: the only caller is the release `rememberFocus`
|
|
357
|
+
* returns, and a type a caller cannot name is a type nobody can grow a second,
|
|
358
|
+
* slightly different copy of.
|
|
359
|
+
*/
|
|
360
|
+
interface FocusHandBack {
|
|
361
|
+
/** The popup that is closing. Focus inside it is the fact that matters. */
|
|
362
|
+
readonly panel: Element;
|
|
363
|
+
/** Whether the popup ever moved focus into itself. */
|
|
364
|
+
readonly tookFocus: boolean;
|
|
365
|
+
/**
|
|
366
|
+
* Whether focus is inside the popup as it closes. Omitted, it is measured from
|
|
367
|
+
* the document — right for a panel that keeps its content while it closes. A
|
|
368
|
+
* panel that empties itself first has already lost the fact by then and passes
|
|
369
|
+
* what it observed, because the browser losing focus on removal is not the
|
|
370
|
+
* user moving focus.
|
|
371
|
+
*/
|
|
372
|
+
readonly focusInside?: boolean;
|
|
373
|
+
/**
|
|
374
|
+
* Where focus goes when the opener is gone or cannot take it, before the
|
|
375
|
+
* opener's place in the page is tried.
|
|
376
|
+
*/
|
|
377
|
+
readonly fallback?: () => HTMLElement | null | undefined;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Remembers the element that had focus and returns the release that gives it back.
|
|
381
|
+
*
|
|
382
|
+
* Two shapes of release, because there are two kinds of caller. Called with no
|
|
383
|
+
* argument it is the blind restore it has always been: focus the remembered
|
|
384
|
+
* element if it is still in the document, which is what `restoreFocus` and a
|
|
385
|
+
* menu command want. Called with the closing popup it is the hand-back, and the
|
|
386
|
+
* destination becomes `decideFocusRestore`'s decision — see `handBackFocus`.
|
|
387
|
+
*
|
|
388
|
+
* The blind restore is a no-op when the remembered element left the document:
|
|
389
|
+
* focus must not be forced onto a detached node (browsers silently ignore it,
|
|
390
|
+
* which would make the failure invisible).
|
|
391
|
+
*/
|
|
392
|
+
export declare function rememberFocus(doc?: Document): (handBack?: FocusHandBack) => void;
|
|
393
|
+
/**
|
|
394
|
+
* Tracks whether focus is inside one panel, kept from focus events rather than
|
|
395
|
+
* read on demand: a framework may remove the panel before the close asks, and
|
|
396
|
+
* the document cannot answer where focus was then.
|
|
397
|
+
*
|
|
398
|
+
* A node that loses focus with no related target may be the panel's own close
|
|
399
|
+
* removing, hiding or making it inert, or the user leaving it for nothing.
|
|
400
|
+
* Which one is known only once the close has run (a browser can fire the blur
|
|
401
|
+
* of a removal while the node is still connected), so `held` decides then: the
|
|
402
|
+
* close took focus when that node can no longer hold it and focus has gone
|
|
403
|
+
* nowhere since.
|
|
404
|
+
*/
|
|
405
|
+
export declare function trackFocusHeld(panel: HTMLElement, initiallyHeld?: boolean): {
|
|
406
|
+
/** Whether focus is inside the panel, as of the last focus event. */
|
|
407
|
+
held(): boolean;
|
|
408
|
+
/** Stops tracking and removes the listeners. */
|
|
409
|
+
release(): void;
|
|
410
|
+
};
|
|
411
|
+
/** Focuses whatever the last `rememberFocus` recorded for `doc`, if it is still connected. */
|
|
412
|
+
export declare function restoreFocus(doc?: Document): void;
|
|
413
|
+
/**
|
|
414
|
+
* Makes everything outside the given elements inert, or restores it. Live
|
|
415
|
+
* regions stay usable, and so does anything portalled from a kept element.
|
|
416
|
+
*
|
|
417
|
+
* Scoped per `Document` and stacked: nested modals push onto the document's
|
|
418
|
+
* modal stack, updating the exempt regions to the topmost modal and restoring
|
|
419
|
+
* the previous modal's exemptions (or the full page when empty) on release.
|
|
420
|
+
*/
|
|
421
|
+
export declare function setInertOuter(inert: boolean, except?: HTMLElement[], doc?: Document): () => void;
|
|
422
|
+
/**
|
|
423
|
+
* Locks page scroll while preserving the scrollbar's width.
|
|
424
|
+
*
|
|
425
|
+
* The arithmetic is the platform foundation's `scrollLockEdits`, applied by its
|
|
426
|
+
* adapter: the scrollbar's width is compensated on the side the scrollbar is
|
|
427
|
+
* actually on (left in a right-to-left page), added to whatever padding body
|
|
428
|
+
* already had, and never invented when the document cannot report a client width.
|
|
429
|
+
* The gutter is not rounded, so a fractional scrollbar leaves no sub-pixel gap.
|
|
430
|
+
*
|
|
431
|
+
* Counted per document, so nested overlays share one lock and only the last
|
|
432
|
+
* release restores the styles.
|
|
433
|
+
*/
|
|
434
|
+
export declare function lockScroll(doc?: Document): () => void;
|
|
435
|
+
export type AnnouncePriority = "polite" | "assertive";
|
|
436
|
+
/** What an announcement looks like to an interceptor (tests, a logger host). */
|
|
437
|
+
export type Announcer = (text: string, options: {
|
|
438
|
+
priority: AnnouncePriority;
|
|
439
|
+
}) => void;
|
|
440
|
+
/** Routes announcements to a function instead of the live regions, for tests.
|
|
441
|
+
* `undefined` puts the real regions back. */
|
|
442
|
+
export declare function setAnnouncer(next: Announcer | undefined): void;
|
|
443
|
+
/** Creates both live regions ahead of the first announcement, so a screen
|
|
444
|
+
* reader already follows them when it comes. */
|
|
445
|
+
export declare function prepareAnnouncements(doc?: Document): void;
|
|
446
|
+
/**
|
|
447
|
+
* Announces text through a live region.
|
|
448
|
+
*
|
|
449
|
+
* The region is cleared immediately and written one task later. Writing both in
|
|
450
|
+
* the same task leaves the accessible name unchanged from the screen reader's
|
|
451
|
+
* point of view, so the second `"Saved"` is never read; clearing first is what
|
|
452
|
+
* makes repetition audible. A newer announcement replaces the pending one, so a
|
|
453
|
+
* burst of messages is not queued behind a stale one.
|
|
454
|
+
*/
|
|
455
|
+
export declare function announce(text: string, options?: {
|
|
456
|
+
priority?: AnnouncePriority;
|
|
457
|
+
doc?: Document;
|
|
458
|
+
}): void;
|
|
459
|
+
/** The two answers a keyboard hint needs: Apple's glyphs, or words. */
|
|
460
|
+
type KeyboardPlatform = "mac" | "other";
|
|
461
|
+
/**
|
|
462
|
+
* What a navigator reports, as plain fields.
|
|
463
|
+
*
|
|
464
|
+
* Every field is optional because every field is missing somewhere: a server has
|
|
465
|
+
* no navigator at all, Safari has no `userAgentData`, and a privacy browser
|
|
466
|
+
* reports an empty `platform` rather than lie about it.
|
|
467
|
+
* @experimental
|
|
468
|
+
*/
|
|
469
|
+
interface PlatformProbe {
|
|
470
|
+
readonly userAgent?: string;
|
|
471
|
+
readonly platform?: string;
|
|
472
|
+
readonly userAgentDataPlatform?: string;
|
|
473
|
+
/** `navigator.maxTouchPoints`: 5 on an iPad, 0 on a Mac, 10 on a touchscreen laptop. */
|
|
474
|
+
readonly maxTouchPoints?: number;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Whether a Mac, iPhone or iPad is running the page, which decides between ⌘ and
|
|
478
|
+
* Ctrl in a hint and between the two cap orders.
|
|
479
|
+
*
|
|
480
|
+
* "other" is the answer for a server, a worker and every failed probe: a hint that
|
|
481
|
+
* prints Ctrl on a Mac is wrong but readable, while a glyph the platform does not
|
|
482
|
+
* have is not.
|
|
483
|
+
* @experimental
|
|
484
|
+
*/
|
|
485
|
+
export declare function platformOf(probe: PlatformProbe): KeyboardPlatform;
|
|
486
|
+
/**
|
|
487
|
+
* Whether the device has a touchscreen, which is not the same question as whether
|
|
488
|
+
* it is being used by touch: a touchscreen laptop answers true here and "mouse" to
|
|
489
|
+
* the media layer. Both answers are needed — this one decides whether to offer
|
|
490
|
+
* touch affordances at all, and the media snapshot decides which affordance is the
|
|
491
|
+
* primary one.
|
|
492
|
+
*
|
|
493
|
+
* `maxTouchPoints` is preferred over the UA: it is what the browser knows about
|
|
494
|
+
* the hardware rather than what it decided to say about itself, and an iPad in
|
|
495
|
+
* desktop mode reports a Mac UA with 5 points.
|
|
496
|
+
* @experimental
|
|
497
|
+
*/
|
|
498
|
+
export declare function isTouchDevice(probe: PlatformProbe): boolean;
|
|
499
|
+
/** A modifier, as the chord parser named it. "mod" is not one of these: it is
|
|
500
|
+
* resolved to meta or ctrl before the order is applied. */
|
|
501
|
+
type ModifierKind = "ctrl" | "alt" | "shift" | "meta";
|
|
502
|
+
/**
|
|
503
|
+
* A chord, already parsed. Structural on purpose: `ParsedChord` from
|
|
504
|
+
* `@bevelo/shortcuts` fits as it is, so a caller passes what it parsed instead of
|
|
505
|
+
* the string it parsed it from.
|
|
506
|
+
* @experimental
|
|
507
|
+
*/
|
|
508
|
+
interface ChordShape {
|
|
509
|
+
/** "mod" was written; it means meta on a Mac and ctrl elsewhere. */
|
|
510
|
+
readonly mod?: boolean;
|
|
511
|
+
readonly ctrl?: boolean;
|
|
512
|
+
readonly alt?: boolean;
|
|
513
|
+
readonly shift?: boolean;
|
|
514
|
+
readonly meta?: boolean;
|
|
515
|
+
/** Canonical, lower-case key name: "k", "escape", "arrowup", " ". */
|
|
516
|
+
readonly key: string;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* One cap to render, as data. `name` is there for the stylesheet and the test;
|
|
520
|
+
* `label` is what the user reads.
|
|
521
|
+
* @experimental
|
|
522
|
+
*/
|
|
523
|
+
interface Keycap {
|
|
524
|
+
readonly kind: "modifier" | "key";
|
|
525
|
+
readonly name: string;
|
|
526
|
+
readonly label: string;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* The order the caps are drawn in, left to right.
|
|
530
|
+
* @experimental
|
|
531
|
+
*/
|
|
532
|
+
export declare function keycapOrder(platform: KeyboardPlatform): readonly ModifierKind[];
|
|
533
|
+
/**
|
|
534
|
+
* The caps for a chord: its modifiers in the platform's order, then the key.
|
|
535
|
+
*
|
|
536
|
+
* A chord with no main key answers its modifiers alone — a lone "shift" is what a
|
|
537
|
+
* chord written as a modifier renders as, and returning a cap for an empty key
|
|
538
|
+
* would draw a blank box. A chord that names nothing at all answers no caps, which
|
|
539
|
+
* is what a caller that failed to parse should get rather than a placeholder.
|
|
540
|
+
* @experimental
|
|
541
|
+
*/
|
|
542
|
+
export declare function keycaps(chord: ChordShape, platform: KeyboardPlatform): readonly Keycap[];
|
|
543
|
+
/** A width and a height in CSS pixels. */
|
|
544
|
+
interface Size {
|
|
545
|
+
readonly width: number;
|
|
546
|
+
readonly height: number;
|
|
547
|
+
}
|
|
548
|
+
/** A point in CSS pixels, in the coordinate space named by the function that
|
|
549
|
+
* returns it. */
|
|
550
|
+
interface Point {
|
|
551
|
+
readonly x: number;
|
|
552
|
+
readonly y: number;
|
|
553
|
+
}
|
|
554
|
+
/** Distances from four edges, in CSS pixels: a safe area, an overflow, a gutter. */
|
|
555
|
+
interface Insets {
|
|
556
|
+
readonly top: number;
|
|
557
|
+
readonly right: number;
|
|
558
|
+
readonly bottom: number;
|
|
559
|
+
readonly left: number;
|
|
560
|
+
}
|
|
561
|
+
/** A rectangle in CSS pixels. */
|
|
562
|
+
interface Rect {
|
|
563
|
+
readonly x: number;
|
|
564
|
+
readonly y: number;
|
|
565
|
+
readonly width: number;
|
|
566
|
+
readonly height: number;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Everything a fixed overlay needs to know about the page it is pinned to.
|
|
570
|
+
*
|
|
571
|
+
* `layout` is the viewport the document is laid out in (`innerWidth`), `visual`
|
|
572
|
+
* the part the user can see (the visual viewport, which the on-screen keyboard
|
|
573
|
+
* and pinch-zoom shrink), and `offset` how far the visual viewport is panned
|
|
574
|
+
* across the layout one. All three are in the same CSS-pixel space, so a rect
|
|
575
|
+
* measured from `getBoundingClientRect` can be compared with them directly.
|
|
576
|
+
* @experimental
|
|
577
|
+
*/
|
|
578
|
+
interface ViewportMetrics {
|
|
579
|
+
readonly layout: Size;
|
|
580
|
+
readonly visual: Size;
|
|
581
|
+
readonly offset: Point;
|
|
582
|
+
readonly scale: number;
|
|
583
|
+
readonly pixelRatio: number;
|
|
584
|
+
readonly safeArea: Insets;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* The numbers as an adapter reads them, every one possibly unusable.
|
|
588
|
+
*
|
|
589
|
+
* The optional shape is the point: a window with no `visualViewport` (older
|
|
590
|
+
* browsers, jsdom) supplies only the layout size, and a `document.hidden` iframe
|
|
591
|
+
* supplies zeros. Making the adapter invent defaults would put one copy of the
|
|
592
|
+
* default in the adapter and another in every component that distrusts it.
|
|
593
|
+
* @experimental
|
|
594
|
+
*/
|
|
595
|
+
interface ViewportSample {
|
|
596
|
+
readonly layoutWidth?: number;
|
|
597
|
+
readonly layoutHeight?: number;
|
|
598
|
+
readonly visualWidth?: number;
|
|
599
|
+
readonly visualHeight?: number;
|
|
600
|
+
readonly offsetX?: number;
|
|
601
|
+
readonly offsetY?: number;
|
|
602
|
+
readonly scale?: number;
|
|
603
|
+
readonly pixelRatio?: number;
|
|
604
|
+
readonly safeArea?: Partial<Insets>;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* The metrics a sample describes.
|
|
608
|
+
*
|
|
609
|
+
* A window without a visual viewport still has one in theory — the layout
|
|
610
|
+
* viewport divided by the zoom — so a sample that reports a scale of 2 and no
|
|
611
|
+
* visual size answers a visual viewport half the layout one. That is exactly what
|
|
612
|
+
* a zoomed page looks like, and it is the rule that keeps the two sizes from
|
|
613
|
+
* disagreeing when only one of them was read.
|
|
614
|
+
* @experimental
|
|
615
|
+
*/
|
|
616
|
+
export declare function viewportMetrics(sample: ViewportSample): ViewportMetrics;
|
|
617
|
+
/**
|
|
618
|
+
* The part of the layout viewport the user can see, in layout coordinates.
|
|
619
|
+
*
|
|
620
|
+
* This is the rectangle an overlay must fit inside: not the layout viewport, which
|
|
621
|
+
* extends under the on-screen keyboard, and not the window size, which is the same
|
|
622
|
+
* number as the layout viewport only while nothing is zoomed.
|
|
623
|
+
* @experimental
|
|
624
|
+
*/
|
|
625
|
+
export declare function visibleRect(metrics: ViewportMetrics): Rect;
|
|
626
|
+
/**
|
|
627
|
+
* How much of the layout viewport's bottom the user cannot see, in CSS pixels.
|
|
628
|
+
*
|
|
629
|
+
* A keyboard inset is this number capped by a measured keyboard height. The cap
|
|
630
|
+
* is not here because the keyboard's height is not in the metrics:
|
|
631
|
+
* it is a difference between two measurements taken at different times (before
|
|
632
|
+
* and after focus), which is history, and a value cannot hold history honestly.
|
|
633
|
+
* A caller that measured a keyboard height caps this number itself.
|
|
634
|
+
* @experimental
|
|
635
|
+
*/
|
|
636
|
+
export declare function coveredBottom(metrics: ViewportMetrics): number;
|
|
637
|
+
/**
|
|
638
|
+
* Whether the page is zoomed away from 1, in either direction.
|
|
639
|
+
*
|
|
640
|
+
* A pinch-out (scale below 1) is as much a zoom as a pinch-in, and the reason to
|
|
641
|
+
* ask is the same: a fixed overlay sized from the layout viewport is wrong by the
|
|
642
|
+
* factor. The tolerance absorbs the sub-percent jitter a trackpad pinch leaves
|
|
643
|
+
* behind, which would otherwise make every measurement look new.
|
|
644
|
+
* @experimental
|
|
645
|
+
*/
|
|
646
|
+
export declare function isZoomed(metrics: ViewportMetrics, tolerance?: number): boolean;
|
|
647
|
+
/**
|
|
648
|
+
* How much of a layout-space rectangle the user can see.
|
|
649
|
+
*
|
|
650
|
+
* `fraction` is the visible area over the whole area; a rectangle with no area (a
|
|
651
|
+
* caret, a zero-width anchor) counts as fully visible when it is inside, because
|
|
652
|
+
* the alternative — 0/0 — makes the one component that positions a caret
|
|
653
|
+
* impossible to write. A rectangle that ended up with a NaN size is not visible:
|
|
654
|
+
* a measurement that failed must not read as an element on screen.
|
|
655
|
+
* @experimental
|
|
656
|
+
*/
|
|
657
|
+
export declare function onScreen(metrics: ViewportMetrics, rect: Rect): {
|
|
658
|
+
readonly visible: boolean;
|
|
659
|
+
readonly fraction: number;
|
|
660
|
+
};
|
|
661
|
+
/**
|
|
662
|
+
* Whether two reads describe the same viewport, so an adapter can stay quiet.
|
|
663
|
+
*
|
|
664
|
+
* A resize listener fires for a scrollbar appearing, for a URL bar collapsing and
|
|
665
|
+
* for a sub-pixel layout change nobody can see; notifying on those makes every
|
|
666
|
+
* subscriber re-place itself for nothing. Lengths compare with a half-pixel
|
|
667
|
+
* tolerance, the scale and the pixel ratio with a per-mille one.
|
|
668
|
+
* @experimental
|
|
669
|
+
*/
|
|
670
|
+
export declare function sameViewport(a: ViewportMetrics, b: ViewportMetrics): boolean;
|
|
671
|
+
/** What the CSS `pointer` media feature reports: the primary input device's
|
|
672
|
+
* precision, or that there is none. */
|
|
673
|
+
type PointerPrecision = "none" | "coarse" | "fine";
|
|
674
|
+
/** The colour scheme in effect. `no-preference` resolves to light, which is what
|
|
675
|
+
* CSS does with it, so it is not a third value here. */
|
|
676
|
+
type ColorScheme = "light" | "dark";
|
|
677
|
+
/** What `prefers-contrast` reports. `less` exists because Windows' "high
|
|
678
|
+
* contrast" theme is `more` while a "wash out the page" utility reports `less`. */
|
|
679
|
+
type ContrastPreference = "no-preference" | "more" | "less";
|
|
680
|
+
/** Which way round the viewport is. */
|
|
681
|
+
type Orientation = "portrait" | "landscape";
|
|
682
|
+
/**
|
|
683
|
+
* One read of every preference a component's appearance depends on.
|
|
684
|
+
* @experimental
|
|
685
|
+
*/
|
|
686
|
+
interface MediaSnapshot {
|
|
687
|
+
readonly reducedMotion: boolean;
|
|
688
|
+
readonly colorScheme: ColorScheme;
|
|
689
|
+
readonly contrast: ContrastPreference;
|
|
690
|
+
/** The primary pointer. */
|
|
691
|
+
readonly pointer: PointerPrecision;
|
|
692
|
+
/** Whether any pointer the device has is precise, which is the question a
|
|
693
|
+
* hover affordance asks: a tablet with a trackpad can hover. */
|
|
694
|
+
readonly anyPointer: PointerPrecision;
|
|
695
|
+
readonly hover: boolean;
|
|
696
|
+
readonly anyHover: boolean;
|
|
697
|
+
readonly orientation: Orientation;
|
|
698
|
+
/** The layout viewport in CSS pixels, for {@link breakpointOf}. */
|
|
699
|
+
readonly width: number;
|
|
700
|
+
readonly height: number;
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* What the adapter can answer.
|
|
704
|
+
*
|
|
705
|
+
* `matches` answers `undefined` for a query the environment cannot answer at all,
|
|
706
|
+
* which is different from `false`: a host that guessed at the difference would be
|
|
707
|
+
* reporting a preference the user never expressed.
|
|
708
|
+
* @experimental
|
|
709
|
+
*/
|
|
710
|
+
interface MediaFacts {
|
|
711
|
+
readonly width?: number;
|
|
712
|
+
readonly height?: number;
|
|
713
|
+
/** `navigator.maxTouchPoints`, used only when the pointer queries cannot be
|
|
714
|
+
* asked — on a browser old enough to lack `matchMedia` this is the only hint
|
|
715
|
+
* that the device is a touch device. */
|
|
716
|
+
readonly touchPoints?: number;
|
|
717
|
+
readonly matches: (query: string) => boolean | undefined;
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* The query strings, in one place, so the adapter and a stylesheet cannot drift.
|
|
721
|
+
*
|
|
722
|
+
* `prefers-color-scheme: light` is deliberately absent: the absence of `dark` is
|
|
723
|
+
* light, and a browser that matches neither is a browser with no preference, which
|
|
724
|
+
* CSS resolves the same way.
|
|
725
|
+
* @experimental
|
|
726
|
+
*/
|
|
727
|
+
export declare const MEDIA_QUERIES: Readonly<{
|
|
728
|
+
readonly reducedMotion: "(prefers-reduced-motion: reduce)";
|
|
729
|
+
readonly dark: "(prefers-color-scheme: dark)";
|
|
730
|
+
readonly moreContrast: "(prefers-contrast: more)";
|
|
731
|
+
readonly lessContrast: "(prefers-contrast: less)";
|
|
732
|
+
readonly coarsePointer: "(pointer: coarse)";
|
|
733
|
+
readonly finePointer: "(pointer: fine)";
|
|
734
|
+
readonly anyCoarsePointer: "(any-pointer: coarse)";
|
|
735
|
+
readonly anyFinePointer: "(any-pointer: fine)";
|
|
736
|
+
readonly hover: "(hover: hover)";
|
|
737
|
+
readonly anyHover: "(any-hover: hover)";
|
|
738
|
+
readonly portrait: "(orientation: portrait)";
|
|
739
|
+
}>;
|
|
740
|
+
/**
|
|
741
|
+
* The snapshot the answers describe.
|
|
742
|
+
*
|
|
743
|
+
* Orientation comes from the width and height rather than from a query, even
|
|
744
|
+
* though `(orientation: portrait)` exists: the two would have to agree in the same
|
|
745
|
+
* frame anyway, a square viewport is portrait by the specification, and a number
|
|
746
|
+
* the adapter already read cannot be a frame behind the query beside it. The
|
|
747
|
+
* query is used only when the sizes are unknown, which is the server's case.
|
|
748
|
+
*
|
|
749
|
+
* The fallbacks for an unanswerable environment are conservative on purpose: no
|
|
750
|
+
* pointer known means no pointer, which makes a component show keyboard
|
|
751
|
+
* affordances — always correct, if occasionally not optimal — instead of a hover
|
|
752
|
+
* state a finger can never trigger.
|
|
753
|
+
* @experimental
|
|
754
|
+
*/
|
|
755
|
+
export declare function mediaSnapshot(facts: MediaFacts): MediaSnapshot;
|
|
756
|
+
/** How the user is most likely to operate the page. */
|
|
757
|
+
type InputKind = "mouse" | "touch" | "stylus" | "hybrid" | "keyboard";
|
|
758
|
+
/**
|
|
759
|
+
* What kind of input the snapshot describes, and whether hovering is on offer.
|
|
760
|
+
* @experimental
|
|
761
|
+
*/
|
|
762
|
+
interface InputProfile {
|
|
763
|
+
readonly kind: InputKind;
|
|
764
|
+
/** Whether an affordance may appear on hover. Any hover, not the primary
|
|
765
|
+
* pointer's: a tablet with a trackpad must still show its hover hints. */
|
|
766
|
+
readonly hovers: boolean;
|
|
767
|
+
/** Whether the primary pointer is coarse, which is the question a hit target's
|
|
768
|
+
* size asks. */
|
|
769
|
+
readonly coarse: boolean;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Read the input profile.
|
|
773
|
+
*
|
|
774
|
+
* The table has one row that is not obvious: a fine pointer that cannot hover is a
|
|
775
|
+
* stylus, not a mouse — a mouse always hovers, and a pen hovering over a tablet is
|
|
776
|
+
* a different interaction. A coarse primary pointer on a device that can hover is
|
|
777
|
+
* a tablet with a trackpad, which is the one case where both the touch target and
|
|
778
|
+
* the hover hint are right.
|
|
779
|
+
* @experimental
|
|
780
|
+
*/
|
|
781
|
+
export declare function inputProfile(snapshot: MediaSnapshot): InputProfile;
|
|
782
|
+
/** The rungs the default ladder names. */
|
|
783
|
+
type BreakpointName = "base" | "sm" | "md" | "lg" | "xl" | "2xl";
|
|
784
|
+
/**
|
|
785
|
+
* One rung: a name and the width at which it starts, mobile-first.
|
|
786
|
+
* @experimental
|
|
787
|
+
*/
|
|
788
|
+
interface Breakpoint {
|
|
789
|
+
readonly name: BreakpointName;
|
|
790
|
+
readonly minWidth: number;
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* The default ladder, mobile-first.
|
|
794
|
+
*
|
|
795
|
+
* These are the widths the kit's own sheets use; they are exported rather than
|
|
796
|
+
* inlined because a component that asks for "lg" and a stylesheet that starts its
|
|
797
|
+
* `lg:` at another width is the drift this layer exists to stop. A host with its
|
|
798
|
+
* own scale passes it to {@link breakpointOf} instead of editing this one.
|
|
799
|
+
* @experimental
|
|
800
|
+
*/
|
|
801
|
+
export declare const BREAKPOINTS: readonly Breakpoint[];
|
|
802
|
+
/**
|
|
803
|
+
* The rung a width falls in.
|
|
804
|
+
*
|
|
805
|
+
* A width narrower than the ladder's first rung answers the first rung: a host
|
|
806
|
+
* whose scale starts at 768px still needs a name for a phone, and answering
|
|
807
|
+
* "nothing" would make every component handle a fourth state. A width that is not
|
|
808
|
+
* a number answers the base rung, because that is the layout that assumes nothing.
|
|
809
|
+
* @experimental
|
|
810
|
+
*/
|
|
811
|
+
export declare function breakpointOf(width: number, ladder?: readonly Breakpoint[]): Breakpoint;
|
|
812
|
+
/** What about a snapshot changed, so a subscriber can react to one thing. */
|
|
813
|
+
type MediaAspect = "motion" | "color-scheme" | "contrast" | "pointer" | "hover" | "orientation" | "breakpoint";
|
|
814
|
+
/**
|
|
815
|
+
* Which aspects differ between two snapshots, in a fixed order.
|
|
816
|
+
*
|
|
817
|
+
* A subscriber that re-renders everything on every change is the reason this
|
|
818
|
+
* exists: a phone rotating changes orientation and breakpoint at once but leaves
|
|
819
|
+
* the colour scheme alone, and a component that only draws a hover hint wants to
|
|
820
|
+
* hear about "hover" and nothing else. The breakpoint aspect compares names, not
|
|
821
|
+
* widths, so a one-pixel resize inside a rung is not a change.
|
|
822
|
+
* @experimental
|
|
823
|
+
*/
|
|
824
|
+
export declare function mediaChanges(before: MediaSnapshot, after: MediaSnapshot, ladder?: readonly Breakpoint[]): readonly MediaAspect[];
|
|
825
|
+
/** What an observer watches for: whether the box is still on screen, and whether
|
|
826
|
+
* it changed size. */
|
|
827
|
+
type ObserveRole = "trigger" | "content" | "container";
|
|
828
|
+
/**
|
|
829
|
+
* One box a component needs watched. The key is the component's own name for the
|
|
830
|
+
* box — a slot key, an element id — never an element, so the plan stays a value.
|
|
831
|
+
* @experimental
|
|
832
|
+
*/
|
|
833
|
+
interface ObserveRequest {
|
|
834
|
+
readonly key: string;
|
|
835
|
+
readonly role: ObserveRole;
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* The three watches, already resolved from roles and de-duplicated.
|
|
839
|
+
*
|
|
840
|
+
* Resize and intersection are separate lists because they are separate observers
|
|
841
|
+
* with separate callbacks: a resize delivery is a batch of sizes, an intersection
|
|
842
|
+
* delivery is a threshold crossing, and merging them forces every caller to sort
|
|
843
|
+
* out which kind of entry it got.
|
|
844
|
+
* @experimental
|
|
845
|
+
*/
|
|
846
|
+
interface ObservationPlan {
|
|
847
|
+
/** Keys whose border box is measured. */
|
|
848
|
+
readonly resize: readonly string[];
|
|
849
|
+
/** Keys whose scroll position matters. */
|
|
850
|
+
readonly scroll: readonly string[];
|
|
851
|
+
/** Keys whose on-screen presence matters. */
|
|
852
|
+
readonly intersection: readonly string[];
|
|
853
|
+
/** The box a resize observer measures. Border box, because a popover is anchored
|
|
854
|
+
* and sized on its border box; a content-box measurement is short by the padding
|
|
855
|
+
* on one side and every offset computed from it is off by that much. */
|
|
856
|
+
readonly box: "border-box";
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Turn the boxes a component cares about into the watches it needs.
|
|
860
|
+
*
|
|
861
|
+
* A trigger and its content are both watched for resize and intersection: the
|
|
862
|
+
* content's size can exceed the room the trigger has, and either one leaving the
|
|
863
|
+
* screen means the panel has to move or close. A scroll container is watched for
|
|
864
|
+
* resize and scroll and deliberately not for intersection — an observer on the
|
|
865
|
+
* container measures the container's own visibility, which the panel inside it
|
|
866
|
+
* already learns from its own entry, and a container that scrolls its content out
|
|
867
|
+
* of view is exactly the case IntersectionObserver reports as still intersecting.
|
|
868
|
+
* @experimental
|
|
869
|
+
*/
|
|
870
|
+
export declare function observationPlan(requests: readonly ObserveRequest[]): ObservationPlan;
|
|
871
|
+
/** A measured border box. */
|
|
872
|
+
interface BoxSize {
|
|
873
|
+
readonly width: number;
|
|
874
|
+
readonly height: number;
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* One delivery, flattened to what the decision needs. The adapter reads a
|
|
878
|
+
* `ResizeObserverEntry` and passes this, so the decision can be tested without an
|
|
879
|
+
* observer.
|
|
880
|
+
* @experimental
|
|
881
|
+
*/
|
|
882
|
+
interface ResizeEntryLike {
|
|
883
|
+
readonly key: string;
|
|
884
|
+
readonly size: BoxSize;
|
|
885
|
+
}
|
|
886
|
+
/** What the decision remembers between deliveries. */
|
|
887
|
+
type ResizeState = ReadonlyMap<string, BoxSize>;
|
|
888
|
+
/**
|
|
889
|
+
* What one delivery changed.
|
|
890
|
+
* @experimental
|
|
891
|
+
*/
|
|
892
|
+
interface ResizeBatch {
|
|
893
|
+
/** The sizes to remember for the next delivery. */
|
|
894
|
+
readonly state: ResizeState;
|
|
895
|
+
/** Keys that changed by more than the tolerance, in plan order. */
|
|
896
|
+
readonly resized: readonly string[];
|
|
897
|
+
/** True for the delivery an observer makes on subscribe: it reports what is
|
|
898
|
+
* already there, and treating it as a resize makes every panel animate on open. */
|
|
899
|
+
readonly baseline: boolean;
|
|
900
|
+
/** Keys that were delivered but not used: not in the plan, or not measurable. */
|
|
901
|
+
readonly ignored: readonly string[];
|
|
902
|
+
}
|
|
903
|
+
/** The sub-pixel difference below which two sizes are the same size. Half a CSS
|
|
904
|
+
* pixel: a 1.5 device-pixel ratio rounds a border box to a fraction, and a
|
|
905
|
+
* component that wrote the measured width back to its element would otherwise
|
|
906
|
+
* resize itself again every frame. */
|
|
907
|
+
export declare const RESIZE_TOLERANCE = 0.5;
|
|
908
|
+
/**
|
|
909
|
+
* Read one delivery of measurements against the sizes already known.
|
|
910
|
+
*
|
|
911
|
+
* Four decisions, each a bug a component would otherwise ship:
|
|
912
|
+
*
|
|
913
|
+
* - The first delivery is a baseline. An observer reports what it sees the moment
|
|
914
|
+
* it starts observing; without this, every popover resizes on open and every
|
|
915
|
+
* panel plays an entrance animation nobody asked for.
|
|
916
|
+
* - A difference below the tolerance is not a resize. Fractional device pixels
|
|
917
|
+
* make a border box wobble by a third of a pixel between frames, and a
|
|
918
|
+
* component that acts on that wobbles with it.
|
|
919
|
+
* - A failed measurement never overwrites a good one. A NaN or negative size with
|
|
920
|
+
* no previous value leaves the key absent — absence means "not measured yet",
|
|
921
|
+
* which a component already handles, while a 0×0 anchor is silently placed wrong.
|
|
922
|
+
* - A key that is not in the plan is ignored rather than reported. The observer and
|
|
923
|
+
* the plan disagreeing is the caller's bug, and reporting it as a resize would
|
|
924
|
+
* make the component act on a box it never asked for.
|
|
925
|
+
* @experimental
|
|
926
|
+
*/
|
|
927
|
+
export declare function applyResizeBatch(previous: ResizeState | undefined, entries: readonly ResizeEntryLike[], plan: ObservationPlan, options?: {
|
|
928
|
+
readonly tolerance?: number;
|
|
929
|
+
}): ResizeBatch;
|
|
930
|
+
/**
|
|
931
|
+
* A scroll box, as measured. `scrollHeight` is the content, `clientHeight` the
|
|
932
|
+
* visible part, `scrollTop` how far it has been scrolled.
|
|
933
|
+
* @experimental
|
|
934
|
+
*/
|
|
935
|
+
interface ScrollBox {
|
|
936
|
+
readonly scrollTop: number;
|
|
937
|
+
readonly scrollHeight: number;
|
|
938
|
+
readonly clientHeight: number;
|
|
939
|
+
readonly scrollLeft: number;
|
|
940
|
+
readonly scrollWidth: number;
|
|
941
|
+
readonly clientWidth: number;
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Where a scroll box is, in the four questions a component asks.
|
|
945
|
+
* @experimental
|
|
946
|
+
*/
|
|
947
|
+
interface ScrollEdges {
|
|
948
|
+
readonly atTop: boolean;
|
|
949
|
+
readonly atBottom: boolean;
|
|
950
|
+
readonly atStart: boolean;
|
|
951
|
+
readonly atEnd: boolean;
|
|
952
|
+
readonly scrollsVertically: boolean;
|
|
953
|
+
readonly scrollsHorizontally: boolean;
|
|
954
|
+
}
|
|
955
|
+
/** The default tolerance in pixels for a scroll edge. One, not zero: fractional
|
|
956
|
+
* device pixels leave `scrollTop + clientHeight` a fraction short of
|
|
957
|
+
* `scrollHeight` at the end, and a "scroll to load more" that never fires is
|
|
958
|
+
* indistinguishable from a broken one. */
|
|
959
|
+
export declare const SCROLL_TOLERANCE = 1;
|
|
960
|
+
/**
|
|
961
|
+
* Read a scroll box's edges.
|
|
962
|
+
*
|
|
963
|
+
* "At the bottom" is true when the content fits, not only when the scroll offset
|
|
964
|
+
* reached the end: a list shorter than its frame is at its bottom with nothing to
|
|
965
|
+
* scroll, and the component that hides its own shadow/border unless the content
|
|
966
|
+
* overflows must say so. A negative `scrollTop` is Safari's rubber band
|
|
967
|
+
* overshooting, which is the top of the list, not a position above it.
|
|
968
|
+
* @experimental
|
|
969
|
+
*/
|
|
970
|
+
export declare function scrollEdges(box: ScrollBox, tolerance?: number): ScrollEdges;
|
|
971
|
+
/** The four things a page can be, from the point of view of work worth doing. */
|
|
972
|
+
type VisibilityState = "visible" | "offscreen" | "hidden" | "frozen";
|
|
973
|
+
/**
|
|
974
|
+
* The signals the decision reads.
|
|
975
|
+
* @experimental
|
|
976
|
+
*/
|
|
977
|
+
interface VisibilitySignals {
|
|
978
|
+
/** `document.visibilityState === "hidden"`: another tab, a minimised window. */
|
|
979
|
+
readonly documentHidden?: boolean;
|
|
980
|
+
/** The page lifecycle is frozen (a back/forward cache entry): no timers, no
|
|
981
|
+
* frames, and a state written now is thrown away on restore. */
|
|
982
|
+
readonly pageFrozen?: boolean;
|
|
983
|
+
/** IntersectionObserver's `isIntersecting`, or the element's own measurement. */
|
|
984
|
+
readonly intersecting?: boolean;
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* The state the signals describe.
|
|
988
|
+
*
|
|
989
|
+
* Frozen outranks hidden, and both outrank off screen. The order matters because
|
|
990
|
+
* the signals are not exclusive: a frozen page is also often hidden, and a hidden
|
|
991
|
+
* page's elements report `isIntersecting: false` — the one state that explains
|
|
992
|
+
* why nothing can be done is the strongest one, not the last one read.
|
|
993
|
+
* @experimental
|
|
994
|
+
*/
|
|
995
|
+
export declare function visibilityState(signals: VisibilitySignals): VisibilityState;
|
|
996
|
+
/**
|
|
997
|
+
* What a component is allowed to do in each state.
|
|
998
|
+
* @experimental
|
|
999
|
+
*/
|
|
1000
|
+
interface VisibilityPolicy {
|
|
1001
|
+
readonly state: VisibilityState;
|
|
1002
|
+
/** Whether an animation will be seen. False off screen (nobody is looking) and
|
|
1003
|
+
* false while hidden (the engine throttles frames, so the animation is not
|
|
1004
|
+
* slower, it is skipped and then jumped when the tab returns). */
|
|
1005
|
+
readonly animates: boolean;
|
|
1006
|
+
/** Whether a measurement means anything. Off screen it does — the layout is
|
|
1007
|
+
* current and a panel must be measured before it can be placed. Hidden and
|
|
1008
|
+
* frozen it does not: the last paint's numbers are what a hidden tab reports. */
|
|
1009
|
+
readonly measures: boolean;
|
|
1010
|
+
/** Whether a timer or a fetch is worth starting. */
|
|
1011
|
+
readonly polls: boolean;
|
|
1012
|
+
/** Whether focus may be moved here. A hidden document sends focus() to the body
|
|
1013
|
+
* and the focus is lost; an off-screen element is fine, because focusing it
|
|
1014
|
+
* scrolls it into view, which is how "open this dialog" works from a trigger
|
|
1015
|
+
* below the fold. */
|
|
1016
|
+
readonly acceptsFocus: boolean;
|
|
1017
|
+
/** Whether a live-region write is worth making. Off screen it is: an
|
|
1018
|
+
* announcement is for the assistive technology, which does not need the element
|
|
1019
|
+
* on screen — dropping it would silence the only user who reads it. Hidden it is
|
|
1020
|
+
* not, because the text waits in the DOM and is read in a burst on return. */
|
|
1021
|
+
readonly announces: boolean;
|
|
1022
|
+
}
|
|
1023
|
+
/**
|
|
1024
|
+
* The policy for a state.
|
|
1025
|
+
*
|
|
1026
|
+
* The one option is off-screen polling: a component that must keep a counter
|
|
1027
|
+
* moving while it is scrolled past (an unread count, a ticker) asks for it by
|
|
1028
|
+
* name, because the default — no work while nobody is looking — is what keeps a
|
|
1029
|
+
* long page from running a hundred intervals.
|
|
1030
|
+
* @experimental
|
|
1031
|
+
*/
|
|
1032
|
+
export declare function visibilityPolicy(signals: VisibilitySignals, options?: {
|
|
1033
|
+
readonly offscreenPolling?: boolean;
|
|
1034
|
+
}): VisibilityPolicy;
|
|
1035
|
+
/** What a threshold crossing means. */
|
|
1036
|
+
type Crossing = "entered" | "left" | "unchanged";
|
|
1037
|
+
/**
|
|
1038
|
+
* How much of an element must be on screen before it counts as visible, and how
|
|
1039
|
+
* little before it stops.
|
|
1040
|
+
* @experimental
|
|
1041
|
+
*/
|
|
1042
|
+
interface CrossingOptions {
|
|
1043
|
+
/** Ratio above which the element counts as entered. Default 0: any pixel. */
|
|
1044
|
+
readonly enterAt?: number;
|
|
1045
|
+
/** Ratio at or below which it counts as left. Default 0: no pixel. */
|
|
1046
|
+
readonly exitAt?: number;
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Whether an intersection ratio crossed the line, from the state it was in.
|
|
1050
|
+
*
|
|
1051
|
+
* The two thresholds exist for one bug: an element sitting exactly on a fold
|
|
1052
|
+
* reports ratios around the threshold every frame, and a component that starts
|
|
1053
|
+
* work on "entered" and stops on "left" restarts it dozens of times per scroll.
|
|
1054
|
+
* A gap between the thresholds makes the state sticky. The gap is normalised —
|
|
1055
|
+
* an `exitAt` above `enterAt` would be a band that is both entered and left, so
|
|
1056
|
+
* the exit is pulled down to the entry rather than trusted.
|
|
1057
|
+
*
|
|
1058
|
+
* A ratio that is not a number answers "unchanged": a measurement the page cannot
|
|
1059
|
+
* make must not flip a component's state, and a NaN would do exactly that.
|
|
1060
|
+
* @experimental
|
|
1061
|
+
*/
|
|
1062
|
+
export declare function crossedVisibility(visible: boolean, ratio: number, options?: CrossingOptions): Crossing;
|
|
1063
|
+
/** The device the pointer is, as browsers report it in `pointerType`. */
|
|
1064
|
+
type PointerKind = "mouse" | "touch" | "pen" | "unknown";
|
|
1065
|
+
/**
|
|
1066
|
+
* The least an event has to say. A `PointerEvent` fits as it is.
|
|
1067
|
+
* @experimental
|
|
1068
|
+
*/
|
|
1069
|
+
interface PointerSignal {
|
|
1070
|
+
/** "pointermove", "pointerdown", "pointerup", "pointercancel", "wheel". */
|
|
1071
|
+
readonly type: string;
|
|
1072
|
+
readonly pointerType?: string;
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* What the tracker remembers, and all it remembers.
|
|
1076
|
+
* @experimental
|
|
1077
|
+
*/
|
|
1078
|
+
interface PointerState {
|
|
1079
|
+
/** When the last activity happened, on the caller's clock. */
|
|
1080
|
+
readonly activity: number;
|
|
1081
|
+
readonly kind: PointerKind;
|
|
1082
|
+
/** A button or a finger is down: the pointer may be still without being idle. */
|
|
1083
|
+
readonly pressing: boolean;
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* How long a still pointer stays awake before it counts as idle. Three seconds:
|
|
1087
|
+
* long enough that reading a panel does not dismiss it, short enough that the
|
|
1088
|
+
* chrome is gone before the user's hand reaches the keyboard.
|
|
1089
|
+
* @experimental
|
|
1090
|
+
*/
|
|
1091
|
+
export declare const IDLE_AFTER = 3000;
|
|
1092
|
+
/**
|
|
1093
|
+
* The state a tracker starts in.
|
|
1094
|
+
*
|
|
1095
|
+
* A caller passes the clock it will keep using — `pointerState(performance.now())`
|
|
1096
|
+
* — because starting at 0 and comparing against a clock that starts at 500000
|
|
1097
|
+
* makes the first idle check see an hour of stillness.
|
|
1098
|
+
* @experimental
|
|
1099
|
+
*/
|
|
1100
|
+
export declare function pointerState(now?: number): PointerState;
|
|
1101
|
+
/**
|
|
1102
|
+
* The state after one event.
|
|
1103
|
+
*
|
|
1104
|
+
* Three rules:
|
|
1105
|
+
*
|
|
1106
|
+
* - An event type the tracker does not own leaves everything alone. `pointerenter`
|
|
1107
|
+
* and `pointerleave` are not activity, and a component that passes every event it
|
|
1108
|
+
* receives must not have its hint kept alive by the one that means "gone".
|
|
1109
|
+
* - The clock is only written when it can be read. A broken clock still updates the
|
|
1110
|
+
* press and the device: losing those makes a drag look abandoned, while losing the
|
|
1111
|
+
* timestamp only makes the next idle check answer from the last good reading.
|
|
1112
|
+
* - A press keeps the tracker awake through {@link pointerIdle}, not here: this
|
|
1113
|
+
* function reports the state, and the decision about idleness belongs to the
|
|
1114
|
+
* question.
|
|
1115
|
+
* @experimental
|
|
1116
|
+
*/
|
|
1117
|
+
export declare function pointerActivity(state: PointerState, signal: PointerSignal, now: number): PointerState;
|
|
1118
|
+
/**
|
|
1119
|
+
* The threshold {@link pointerIdle} will use for these options.
|
|
1120
|
+
*
|
|
1121
|
+
* Exported because an adapter that schedules a timer needs the same number the
|
|
1122
|
+
* decision compares against; reading the option again with its own fallback is how
|
|
1123
|
+
* a timer ends up waking a millisecond before the decision agrees that the pointer
|
|
1124
|
+
* is idle. A threshold that cannot be used — zero, negative, NaN, infinite — is
|
|
1125
|
+
* {@link IDLE_AFTER}, not a pointer that is idle on every read.
|
|
1126
|
+
* @experimental
|
|
1127
|
+
*/
|
|
1128
|
+
export declare function idleThreshold(options?: {
|
|
1129
|
+
readonly idleAfter?: number;
|
|
1130
|
+
}): number;
|
|
1131
|
+
/**
|
|
1132
|
+
* The idle question, answered from the state and a clock reading.
|
|
1133
|
+
*
|
|
1134
|
+
* `waited` is clamped at zero: a clock that went backwards (a fake clock in a
|
|
1135
|
+
* test, a monotonic clock reset by a sleep) must not produce a negative wait,
|
|
1136
|
+
* which would read as "idle for -4 seconds" and, in the caller's comparison, as
|
|
1137
|
+
* idle forever. A press suppresses idle while the press lasts — the number a
|
|
1138
|
+
* slider shows while the thumb is held is the case, and a value that disappears
|
|
1139
|
+
* mid-drag is worse than a hint that stays a moment too long.
|
|
1140
|
+
*
|
|
1141
|
+
* The threshold is inclusive: "idle after 3000 ms" means 3000 ms is enough. A
|
|
1142
|
+
* threshold that cannot be used (zero, negative, NaN, infinite) falls back to
|
|
1143
|
+
* {@link IDLE_AFTER} rather than making the pointer idle on every read.
|
|
1144
|
+
* @experimental
|
|
1145
|
+
*/
|
|
1146
|
+
export declare function pointerIdle(state: PointerState, now: number, options?: {
|
|
1147
|
+
readonly idleAfter?: number;
|
|
1148
|
+
}): {
|
|
1149
|
+
readonly idle: boolean;
|
|
1150
|
+
readonly waited: number;
|
|
1151
|
+
};
|
|
1152
|
+
/** Why a clipboard operation did not happen. */
|
|
1153
|
+
type ClipboardFailure =
|
|
1154
|
+
/** No clipboard API here at all: an insecure page, an embed, a worker, jsdom. */
|
|
1155
|
+
"unsupported" |
|
|
1156
|
+
/** The page is not allowed to use the clipboard: no user gesture, no permission,
|
|
1157
|
+
* an unfocused document. */
|
|
1158
|
+
"denied" |
|
|
1159
|
+
/** The API exists and could not be used right now, for a reason the page cannot
|
|
1160
|
+
* fix from CSS or a setting. */
|
|
1161
|
+
"unavailable" |
|
|
1162
|
+
/** The data could not be put on the clipboard (or was not readable as text). */
|
|
1163
|
+
"invalid";
|
|
1164
|
+
/**
|
|
1165
|
+
* What a write did.
|
|
1166
|
+
* @experimental
|
|
1167
|
+
*/
|
|
1168
|
+
type ClipboardWrite = {
|
|
1169
|
+
readonly ok: true;
|
|
1170
|
+
} | {
|
|
1171
|
+
readonly ok: false;
|
|
1172
|
+
readonly reason: ClipboardFailure;
|
|
1173
|
+
};
|
|
1174
|
+
/**
|
|
1175
|
+
* What a read did. A successful read of an empty clipboard is `ok` with an empty
|
|
1176
|
+
* string: "nothing was selected when the user pressed copy" is not a failure.
|
|
1177
|
+
* @experimental
|
|
1178
|
+
*/
|
|
1179
|
+
type ClipboardRead = {
|
|
1180
|
+
readonly ok: true;
|
|
1181
|
+
readonly text: string;
|
|
1182
|
+
} | {
|
|
1183
|
+
readonly ok: false;
|
|
1184
|
+
readonly reason: ClipboardFailure;
|
|
1185
|
+
};
|
|
1186
|
+
/**
|
|
1187
|
+
* The whole clipboard surface a component needs.
|
|
1188
|
+
*
|
|
1189
|
+
* Both methods answer rather than reject. A rejected promise would be caught at
|
|
1190
|
+
* every call site and mapped to the same "failed" message; an adapter that cannot implement a method answers
|
|
1191
|
+
* `{ ok: false, reason: "unsupported" }` instead of leaving it out, so a caller
|
|
1192
|
+
* never has to ask whether the feature exists.
|
|
1193
|
+
* @experimental
|
|
1194
|
+
*/
|
|
1195
|
+
interface ClipboardPort {
|
|
1196
|
+
readonly writeText: (text: string) => Promise<ClipboardWrite>;
|
|
1197
|
+
readonly readText: () => Promise<ClipboardRead>;
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* The reason an error means.
|
|
1201
|
+
*
|
|
1202
|
+
* `undefined` is "unsupported", not "unavailable": a missing API answers by not
|
|
1203
|
+
* being there, so an adapter that found nothing to call has no error to classify
|
|
1204
|
+
* and passes `undefined`. The rejected alternative is an `instanceof DOMException`
|
|
1205
|
+
* check, which is false for the error an iframe's clipboard rejects with — a
|
|
1206
|
+
* cross-realm object — and true for a DOMException a page threw for another reason,
|
|
1207
|
+
* which is why the name is read structurally.
|
|
1208
|
+
* @experimental
|
|
1209
|
+
*/
|
|
1210
|
+
export declare function clipboardFailure(error: unknown): ClipboardFailure;
|
|
1211
|
+
/** What the page can do, as four flags a caller can read from the environment. */
|
|
1212
|
+
interface ClipboardEnvironment {
|
|
1213
|
+
/** `navigator.clipboard` and its methods exist. */
|
|
1214
|
+
readonly api: boolean;
|
|
1215
|
+
/** The page is a secure context (https, localhost). */
|
|
1216
|
+
readonly secure: boolean;
|
|
1217
|
+
/** The document has focus; both directions are refused without it in Safari and
|
|
1218
|
+
* Firefox. */
|
|
1219
|
+
readonly focused: boolean;
|
|
1220
|
+
/** `document.execCommand("copy")` exists and the page can select a node — the
|
|
1221
|
+
* only route an insecure context has. */
|
|
1222
|
+
readonly fallback: boolean;
|
|
1223
|
+
}
|
|
1224
|
+
/** Which mechanism a copy should use. */
|
|
1225
|
+
type ClipboardStrategy = "clipboard-api" | "exec-command" | "none";
|
|
1226
|
+
/**
|
|
1227
|
+
* How a write should be attempted.
|
|
1228
|
+
*
|
|
1229
|
+
* The async API is preferred everywhere it can be used. The synchronous
|
|
1230
|
+
* `execCommand` route is not a "todo": it is the correct answer for an insecure
|
|
1231
|
+
* context and for an unfocused document, both of which refuse the async API
|
|
1232
|
+
* outright, and it costs a visible selection change, which is why it is the
|
|
1233
|
+
* fallback and not the default. A read has no fallback at all — see
|
|
1234
|
+
* {@link canReadClipboard} — so a caller must not assume the two directions share a
|
|
1235
|
+
* strategy.
|
|
1236
|
+
* @experimental
|
|
1237
|
+
*/
|
|
1238
|
+
export declare function clipboardStrategy(environment: ClipboardEnvironment): ClipboardStrategy;
|
|
1239
|
+
/**
|
|
1240
|
+
* Whether a read can be attempted at all.
|
|
1241
|
+
*
|
|
1242
|
+
* A read is refused unless the document is focused and the context is secure, and
|
|
1243
|
+
* there is no synchronous route to fall back to — the old `execCommand("paste")`
|
|
1244
|
+
* was disabled by every engine years ago. So a component that offers "paste" must
|
|
1245
|
+
* hide it when this answers false, instead of showing a button that can only fail.
|
|
1246
|
+
* @experimental
|
|
1247
|
+
*/
|
|
1248
|
+
export declare function canReadClipboard(environment: ClipboardEnvironment): boolean;
|
|
1249
|
+
/** A side a scrollbar can sit on after logical sides are resolved. */
|
|
1250
|
+
type PhysicalSide = "left" | "right";
|
|
1251
|
+
/**
|
|
1252
|
+
* What the page looks like before a lock: the width the scrollbar currently takes,
|
|
1253
|
+
* the direction, and the padding body already has.
|
|
1254
|
+
* @experimental
|
|
1255
|
+
*/
|
|
1256
|
+
interface ScrollLockInput {
|
|
1257
|
+
/** The scrollbar's width in CSS pixels: viewport width minus the document's
|
|
1258
|
+
* client width. 0 for an overlay scrollbar, which takes no room. */
|
|
1259
|
+
readonly scrollbarWidth: number;
|
|
1260
|
+
/** Lays the page out right to left, where the scrollbar is on the left. */
|
|
1261
|
+
readonly direction?: "ltr" | "rtl";
|
|
1262
|
+
readonly paddingLeft?: number;
|
|
1263
|
+
readonly paddingRight?: number;
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* The style changes a lock needs. Restoring them is the caller's job: the input
|
|
1267
|
+
* carries what the padding was, and the lock never spends a value it was not given.
|
|
1268
|
+
* @experimental
|
|
1269
|
+
*/
|
|
1270
|
+
interface ScrollLockEdits {
|
|
1271
|
+
/** The scrollbar width actually compensated for, after unusable values are
|
|
1272
|
+
* refused. */
|
|
1273
|
+
readonly gutter: number;
|
|
1274
|
+
readonly overflow: "hidden";
|
|
1275
|
+
/** The padding to write, or undefined when there is nothing to compensate — in
|
|
1276
|
+
* which case the body is not touched at all, so a host's own padding survives a
|
|
1277
|
+
* lock on a platform with overlay scrollbars. */
|
|
1278
|
+
readonly padding: {
|
|
1279
|
+
readonly side: PhysicalSide;
|
|
1280
|
+
readonly value: number;
|
|
1281
|
+
} | undefined;
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* The edits that keep the page from jumping when its scrollbar goes away.
|
|
1285
|
+
*
|
|
1286
|
+
* Two refusals are deliberate. A negative or non-finite scrollbar width is a
|
|
1287
|
+
* measurement bug — `innerWidth` read before layout in a hidden tab, a client width
|
|
1288
|
+
* of 0 — and compensating for it would shift the page by a made-up amount, so it
|
|
1289
|
+
* is treated as 0. And a width is not capped: a 60px gutter means the measurement
|
|
1290
|
+
* is wrong, and a silently clamped one is a page that jumps a little instead of a
|
|
1291
|
+
* page that reports a bug.
|
|
1292
|
+
*
|
|
1293
|
+
* The padding is added to the existing one rather than replacing it: a body with
|
|
1294
|
+
* 16px already has 16px of its layout to lose, and `padding-right: 15px` would
|
|
1295
|
+
* shrink the page's text to the scrollbar's width.
|
|
1296
|
+
* @experimental
|
|
1297
|
+
*/
|
|
1298
|
+
export declare function scrollLockEdits(input: ScrollLockInput): ScrollLockEdits;
|
|
1299
|
+
/** What a region of the page is, from the point of view of inertness. */
|
|
1300
|
+
type RegionRole =
|
|
1301
|
+
/** The portal root: the overlays themselves live inside it. */
|
|
1302
|
+
"layer" |
|
|
1303
|
+
/** A live region: announcements are ignored inside an inert subtree. */
|
|
1304
|
+
"live" |
|
|
1305
|
+
/** An ordinary region of the page: the modal covers it, so it goes inert. */
|
|
1306
|
+
"content" |
|
|
1307
|
+
/** A region the caller keeps interactive: the modal's own root when it is not
|
|
1308
|
+
* portalled, or a region that contains it. */
|
|
1309
|
+
"exempt";
|
|
1310
|
+
/**
|
|
1311
|
+
* One region of the page as data. `key` is the caller's name for the element —
|
|
1312
|
+
* an id, an attribute, an index — so the decision never holds an element.
|
|
1313
|
+
* @experimental
|
|
1314
|
+
*/
|
|
1315
|
+
interface PageRegion {
|
|
1316
|
+
readonly key: string;
|
|
1317
|
+
readonly role: RegionRole;
|
|
1318
|
+
/** The region already carries `inert`, so it is not this lock's to remove. */
|
|
1319
|
+
readonly alreadyInert?: boolean;
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
* The regions that must become inert while a modal is open.
|
|
1323
|
+
*
|
|
1324
|
+
* A region this lock did not inert is never restored by it: an element that was
|
|
1325
|
+
* already inert belongs to whatever inerted it, and removing the attribute on
|
|
1326
|
+
* release would make a page interactive that another overlay deliberately locked.
|
|
1327
|
+
* Duplicate keys answer once — a host that reports the same region twice (a
|
|
1328
|
+
* portalled node's owner and its parent) must not get two answers for one element.
|
|
1329
|
+
* @experimental
|
|
1330
|
+
*/
|
|
1331
|
+
export declare function inertKeys(regions: readonly PageRegion[]): readonly string[];
|
|
1332
|
+
/** What a guard may do about focus it just saw leave. */
|
|
1333
|
+
type FocusPull =
|
|
1334
|
+
/** Take focus back to the guard's own root. */
|
|
1335
|
+
"pull" |
|
|
1336
|
+
/** A move is already in flight; do nothing this turn. */
|
|
1337
|
+
"hold" |
|
|
1338
|
+
/** Not this guard's business: nobody to pull to, or another guard owns it. */
|
|
1339
|
+
"decline";
|
|
1340
|
+
/**
|
|
1341
|
+
* What a guard knows when a focus event tells it focus left its region.
|
|
1342
|
+
* @experimental
|
|
1343
|
+
*/
|
|
1344
|
+
interface FocusGuardState {
|
|
1345
|
+
/** This guard is the one that moved focus: `focus()` dispatches `focusin`
|
|
1346
|
+
* synchronously, so every guard sees a second event mid-move. */
|
|
1347
|
+
readonly moving?: boolean;
|
|
1348
|
+
/** The guard's root is still in the document. */
|
|
1349
|
+
readonly connected?: boolean;
|
|
1350
|
+
/** The document is visible; a hidden document sends `focus()` to the body. */
|
|
1351
|
+
readonly visible?: boolean;
|
|
1352
|
+
/** This guard is the innermost one for its document. Two guards that both pull
|
|
1353
|
+
* take turns until the stack overflows. */
|
|
1354
|
+
readonly innermost?: boolean;
|
|
1355
|
+
/** The focused element is inside the guard, which is the ordinary case. */
|
|
1356
|
+
readonly focusInside?: boolean;
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* The decision, in the order the checks matter.
|
|
1360
|
+
*
|
|
1361
|
+
* `move` first, because the focus event caused by the guard's own move arrives
|
|
1362
|
+
* before the call returns and answering it schedules a move from inside a move —
|
|
1363
|
+
* the two-guard bounce. Then disconnection, because a guard whose root left the
|
|
1364
|
+
* document has lost its own focus and must release rather than fight for it. Then
|
|
1365
|
+
* visibility, then ownership, and only then the pull.
|
|
1366
|
+
*
|
|
1367
|
+
* The default for every field is the quiet answer: an unstated `innermost` is
|
|
1368
|
+
* false, so a caller that has not worked out the ownership does not pull.
|
|
1369
|
+
* @experimental
|
|
1370
|
+
*/
|
|
1371
|
+
export declare function focusPull(state: FocusGuardState): FocusPull;
|
|
1372
|
+
/** A cleanup: the one shape every helper below returns. */
|
|
1373
|
+
type AdapterCleanup = () => void;
|
|
1374
|
+
/**
|
|
1375
|
+
* Which platform this window is on, for a shortcut display.
|
|
1376
|
+
*
|
|
1377
|
+
* The fields are read here and classified in `environment.ts`; a caller that
|
|
1378
|
+
* renders a hint for another platform passes `platformOf` a probe of its own
|
|
1379
|
+
* instead of calling this.
|
|
1380
|
+
* @experimental
|
|
1381
|
+
*/
|
|
1382
|
+
export declare function readPlatform(view: Window): KeyboardPlatform;
|
|
1383
|
+
/**
|
|
1384
|
+
* Read the metrics the page is drawn in, as the pure value describes them.
|
|
1385
|
+
*
|
|
1386
|
+
* A window without a visual viewport reports only the layout one and
|
|
1387
|
+
* {@link viewportMetrics} derives the rest: that is the correct split, because the
|
|
1388
|
+
* browser that lacks the API is the browser that cannot zoom.
|
|
1389
|
+
* @experimental
|
|
1390
|
+
*/
|
|
1391
|
+
export declare function readViewportMetrics(view: Window): ViewportMetrics;
|
|
1392
|
+
/**
|
|
1393
|
+
* Follow the viewport: window resizes, and the visual viewport's own resize and
|
|
1394
|
+
* scroll (the on-screen keyboard and the pinch-zoom are not window resizes).
|
|
1395
|
+
*
|
|
1396
|
+
* No call on subscribe, which is the rule the runtime's own environment follows:
|
|
1397
|
+
* a synchronous notification from a subscribe call is how a React effect ends up
|
|
1398
|
+
* updating state during render. The caller reads {@link readViewportMetrics} once
|
|
1399
|
+
* for the value it renders. A notification is skipped when the new metrics are the
|
|
1400
|
+
* same viewport at the half-pixel tolerance — a scrollbar appearing is a resize
|
|
1401
|
+
* event and not a resize anybody can see.
|
|
1402
|
+
* @experimental
|
|
1403
|
+
*/
|
|
1404
|
+
export declare function bindViewportMetrics(view: Window, onChange: (metrics: ViewportMetrics) => void): AdapterCleanup;
|
|
1405
|
+
/**
|
|
1406
|
+
* The on-screen keyboard's height on one element, as a CSS custom property.
|
|
1407
|
+
*
|
|
1408
|
+
* `coveredBottom` is the decision — how much of the layout viewport the visual
|
|
1409
|
+
* viewport no longer covers, which is the keyboard and not the URL bar (that
|
|
1410
|
+
* collapse resizes the layout viewport too). This writes it to `property`
|
|
1411
|
+
* (`--keyboard-inset` by default) in CSS pixels on bind and on every metrics
|
|
1412
|
+
* change, so a fixed bottom bar can ride above the keyboard with
|
|
1413
|
+
* `bottom: var(--keyboard-inset)`. The element's own value is restored on
|
|
1414
|
+
* release.
|
|
1415
|
+
*
|
|
1416
|
+
* Same contract as {@link bindViewportMetrics}: the write on bind is a style,
|
|
1417
|
+
* not a state update, so it cannot land during render; a document with no
|
|
1418
|
+
* window gets a no-op.
|
|
1419
|
+
* @experimental
|
|
1420
|
+
*/
|
|
1421
|
+
export declare function bindKeyboardInset(element: HTMLElement, options?: {
|
|
1422
|
+
/** The custom property to write. @default "--keyboard-inset" */
|
|
1423
|
+
readonly property?: string;
|
|
1424
|
+
/** Called with the inset whenever it is written, the first write included. */
|
|
1425
|
+
readonly onInset?: (pixels: number) => void;
|
|
1426
|
+
}): AdapterCleanup;
|
|
1427
|
+
/**
|
|
1428
|
+
* Read the media snapshot for a window.
|
|
1429
|
+
*
|
|
1430
|
+
* A window without `matchMedia` answers `undefined` for every query rather than
|
|
1431
|
+
* `false`: a browser that cannot be asked is not a browser that says "no", and the
|
|
1432
|
+
* pure builder's fallbacks are chosen for exactly that case. The width and height
|
|
1433
|
+
* are read here because they are the breakpoint's input and the orientation's
|
|
1434
|
+
* source of truth.
|
|
1435
|
+
* @experimental
|
|
1436
|
+
*/
|
|
1437
|
+
export declare function readMediaSnapshot(view: Window): MediaSnapshot;
|
|
1438
|
+
/**
|
|
1439
|
+
* Subscribe to the media preferences with one listener set for the window.
|
|
1440
|
+
*
|
|
1441
|
+
* Every query is opened once and every listener fans out to the same callback, so
|
|
1442
|
+
* a component that reads the snapshot does not open a `MediaQueryList` of its own
|
|
1443
|
+
* — the disagreement this module exists to remove. The deprecated `addListener` is
|
|
1444
|
+
* used where `addEventListener` is missing (Safari before 14), detected once per
|
|
1445
|
+
* list so add and remove always go through the same API. A resize is listened for
|
|
1446
|
+
* as well, because the breakpoint changes on width and no query reports that.
|
|
1447
|
+
*
|
|
1448
|
+
* The callback receives the aspects that changed, not the whole snapshot alone: a
|
|
1449
|
+
* phone rotating changes orientation and breakpoint and leaves the colour scheme
|
|
1450
|
+
* alone, and a subscriber that only draws a hover hint wants to hear about "hover"
|
|
1451
|
+
* and nothing else. No notification on subscribe, for the same reason as the
|
|
1452
|
+
* viewport.
|
|
1453
|
+
* @experimental
|
|
1454
|
+
*/
|
|
1455
|
+
export declare function bindMediaQueries(view: Window, onChange: (snapshot: MediaSnapshot, changes: readonly MediaAspect[]) => void): AdapterCleanup;
|
|
1456
|
+
/** What one delivery from an observer means, already decided. */
|
|
1457
|
+
type ObservationReport = {
|
|
1458
|
+
readonly kind: "resize";
|
|
1459
|
+
readonly keys: readonly string[];
|
|
1460
|
+
} | {
|
|
1461
|
+
readonly kind: "intersection";
|
|
1462
|
+
readonly entered: readonly string[];
|
|
1463
|
+
readonly left: readonly string[];
|
|
1464
|
+
} | {
|
|
1465
|
+
readonly kind: "scroll";
|
|
1466
|
+
readonly key: string;
|
|
1467
|
+
readonly edges: ScrollEdges;
|
|
1468
|
+
};
|
|
1469
|
+
interface ObservationOptions {
|
|
1470
|
+
/** The sub-pixel difference below which two sizes are the same; defaults to the
|
|
1471
|
+
* pure module's tolerance. */
|
|
1472
|
+
readonly tolerance?: number;
|
|
1473
|
+
/** The ratios an intersection observer fires at; defaults to [0], the "any part
|
|
1474
|
+
* visible" crossing a panel cares about. */
|
|
1475
|
+
readonly thresholds?: readonly number[];
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* Start watching a plan: one resize observer, one intersection observer and one
|
|
1479
|
+
* capture-phase scroll listener for the whole plan.
|
|
1480
|
+
*
|
|
1481
|
+
* One observer per kind rather than one per element, because the browser delivers a
|
|
1482
|
+
* batch to a single callback: a page that observes twelve boxes gets one callback
|
|
1483
|
+
* per frame instead of twelve, and the pure layer turns that batch into one answer.
|
|
1484
|
+
* The scroll listener is on the document and in the capture phase because a scroll
|
|
1485
|
+
* does not bubble, and a capture listener on the document is the only way to hear a
|
|
1486
|
+
* container's scroll without adding one listener per container.
|
|
1487
|
+
*
|
|
1488
|
+
* `resolve` maps a plan key to the element it names. A key that resolves to nothing
|
|
1489
|
+
* is skipped rather than throwing: a box that has not rendered yet is the ordinary
|
|
1490
|
+
* first frame, and the caller binds again when it does. An environment without the
|
|
1491
|
+
* observer constructors keeps the initial measurement and gets no updates — the
|
|
1492
|
+
* adapter does not fake a resize loop.
|
|
1493
|
+
* @experimental
|
|
1494
|
+
*/
|
|
1495
|
+
export declare function bindObservation(view: Window, plan: ObservationPlan, resolve: (key: string) => Element | undefined, onChange: (report: ObservationReport) => void, options?: ObservationOptions): AdapterCleanup;
|
|
1496
|
+
/**
|
|
1497
|
+
* What a caller gets back from {@link trackPointer}.
|
|
1498
|
+
* @experimental
|
|
1499
|
+
*/
|
|
1500
|
+
interface PointerTracker {
|
|
1501
|
+
/** The current state. */
|
|
1502
|
+
state(): PointerState;
|
|
1503
|
+
/** Re-answer the idle question now, emitting if the answer changed. The idle
|
|
1504
|
+
* timer calls this; a test calls it after moving its own clock. */
|
|
1505
|
+
check(): void;
|
|
1506
|
+
/** Removes the listeners and the timer. */
|
|
1507
|
+
stop(): void;
|
|
1508
|
+
}
|
|
1509
|
+
interface PointerTrackerOptions {
|
|
1510
|
+
/** How long a still pointer stays awake; defaults to {@link IDLE_AFTER}. */
|
|
1511
|
+
readonly idleAfter?: number;
|
|
1512
|
+
/** The clock. Defaults to the window's `performance.now`; a test passes its own. */
|
|
1513
|
+
readonly now?: () => number;
|
|
1514
|
+
/** Receives the state whenever the answer changes — an idle flip, a press, a
|
|
1515
|
+
* change of device. */
|
|
1516
|
+
onChange?: (state: PointerState, idle: boolean) => void;
|
|
1517
|
+
}
|
|
1518
|
+
/**
|
|
1519
|
+
* Track the pointer for a window.
|
|
1520
|
+
*
|
|
1521
|
+
* The timer is scheduled from the clock the caller gave, not from the event: the
|
|
1522
|
+
* next idle flip is "threshold minus the time already waited", so a pointer that
|
|
1523
|
+
* moved 2900 ms into a 3000 ms window flips 100 ms later. The answer itself is
|
|
1524
|
+
* always {@link pointerIdle}'s, so the timer is an optimisation and never the
|
|
1525
|
+
* source of truth — an early or late timer changes when the callback runs, never
|
|
1526
|
+
* what it says.
|
|
1527
|
+
* @experimental
|
|
1528
|
+
*/
|
|
1529
|
+
export declare function trackPointer(view: Window, options?: PointerTrackerOptions): PointerTracker;
|
|
1530
|
+
/**
|
|
1531
|
+
* The clipboard port for a window.
|
|
1532
|
+
*
|
|
1533
|
+
* Writes follow {@link clipboardStrategy}: the async API where it can be used, the
|
|
1534
|
+
* synchronous route where it cannot, and `unsupported` where neither exists. A
|
|
1535
|
+
* refused async write falls back to the synchronous route when the environment has
|
|
1536
|
+
* one — being refused for an unfocused document is exactly the case the fallback is
|
|
1537
|
+
* for — and the original reason is kept when the fallback fails too, because that
|
|
1538
|
+
* reason is the one that tells the user what to change.
|
|
1539
|
+
* @experimental
|
|
1540
|
+
*/
|
|
1541
|
+
export declare function createClipboardPort(view: Window): ClipboardPort;
|
|
1542
|
+
/**
|
|
1543
|
+
* Lock the page's scroll without moving it sideways.
|
|
1544
|
+
*
|
|
1545
|
+
* The scrollbar's width is measured from the document's client width; a document
|
|
1546
|
+
* that reports none (a hidden tab, jsdom, a display:none iframe) is treated as an
|
|
1547
|
+
* overlay scrollbar and gets no padding — a page whose client width cannot be read
|
|
1548
|
+
* must not be shifted by a made-up fifteen pixels.
|
|
1549
|
+
*
|
|
1550
|
+
* Counted per document, like the platform's own lock: nested modals share one lock
|
|
1551
|
+
* and only the last release restores the styles.
|
|
1552
|
+
* @experimental
|
|
1553
|
+
*/
|
|
1554
|
+
export declare function lockPageScroll(doc: Document): AdapterCleanup;
|
|
1555
|
+
interface InertRegionsOptions {
|
|
1556
|
+
/** Elements that stay interactive, with their ancestors: the modal's own
|
|
1557
|
+
* root, wherever it renders. */
|
|
1558
|
+
readonly except?: readonly Element[];
|
|
1559
|
+
/** Keeps an element the walk would make inert, like a node portalled from
|
|
1560
|
+
* inside a kept one, which the DOM alone cannot tell belongs to it. */
|
|
1561
|
+
readonly keeps?: (element: Element) => boolean;
|
|
1562
|
+
}
|
|
1563
|
+
/**
|
|
1564
|
+
* Make the page unreachable behind a modal.
|
|
1565
|
+
*
|
|
1566
|
+
* Everything becomes inert except the kept elements, their ancestors and the
|
|
1567
|
+
* page's live regions: along each kept element's path to the body, every
|
|
1568
|
+
* sibling goes inert, across shadow roots. Inerting siblings rather than whole
|
|
1569
|
+
* top-level regions is what keeps a live region inside the app announcing, and
|
|
1570
|
+
* what leaves each sibling's `inert` a fact a page can read on the element
|
|
1571
|
+
* itself. An element that already carries `inert` belongs to whoever set it and
|
|
1572
|
+
* is left alone, so the release removes only what this call added. Nesting is
|
|
1573
|
+
* the caller's: a second call adds nothing and its release would remove the
|
|
1574
|
+
* first call's attributes, so a modal stack calls this once per top layer
|
|
1575
|
+
* rather than once per layer.
|
|
1576
|
+
* @experimental
|
|
1577
|
+
*/
|
|
1578
|
+
export declare function applyInertRegions(doc: Document, options?: InertRegionsOptions): AdapterCleanup;
|
|
1579
|
+
/** One scroll axis, spelled the way the primitive spells it. */
|
|
1580
|
+
type ScrollAreaDomAxis = "x" | "y";
|
|
1581
|
+
/** The elements a framework adapter rendered for one scroll area. */
|
|
1582
|
+
interface ScrollAreaDomElements {
|
|
1583
|
+
viewport(): HTMLElement | null;
|
|
1584
|
+
track(axis: ScrollAreaDomAxis): HTMLElement | null;
|
|
1585
|
+
thumb(axis: ScrollAreaDomAxis): HTMLElement | null;
|
|
1586
|
+
}
|
|
1587
|
+
/**
|
|
1588
|
+
* Create the imperative channel a scroll-area primitive consumes.
|
|
1589
|
+
*
|
|
1590
|
+
* Every method reads the element lazily, so the channel may be created before
|
|
1591
|
+
* the refs resolve and keeps working when a framework re-renders the same node.
|
|
1592
|
+
*/
|
|
1593
|
+
export declare function createScrollAreaChannel(elements: ScrollAreaDomElements): {
|
|
1594
|
+
read(): {
|
|
1595
|
+
x: number;
|
|
1596
|
+
y: number;
|
|
1597
|
+
clientWidth: number;
|
|
1598
|
+
clientHeight: number;
|
|
1599
|
+
scrollWidth: number;
|
|
1600
|
+
scrollHeight: number;
|
|
1601
|
+
};
|
|
1602
|
+
scroll(axis: ScrollAreaDomAxis, value: number): void;
|
|
1603
|
+
trackLength(axis: ScrollAreaDomAxis): number;
|
|
1604
|
+
focusThumb(axis: ScrollAreaDomAxis): void;
|
|
1605
|
+
captureThumb(axis: ScrollAreaDomAxis, pointerId: number): void;
|
|
1606
|
+
releaseThumb(axis: ScrollAreaDomAxis, pointerId: number): void;
|
|
1607
|
+
};
|
|
1608
|
+
/** Create a lazy measurement channel for one waterfall scroll container. */
|
|
1609
|
+
export declare function createWaterfallChannel(viewport: () => HTMLElement | null): {
|
|
1610
|
+
read(): {
|
|
1611
|
+
scrollTop: number;
|
|
1612
|
+
viewportHeight: number;
|
|
1613
|
+
};
|
|
1614
|
+
};
|
|
1615
|
+
interface ElementLike {
|
|
1616
|
+
closest(selector: string): unknown;
|
|
1617
|
+
getAttribute?(name: string): string | null;
|
|
1618
|
+
}
|
|
1619
|
+
/** Resolve the reading direction for one keyboard event's target. */
|
|
1620
|
+
export declare function directionOfKeyEvent(input: unknown): "ltr" | "rtl";
|
|
1621
|
+
/** Resolve the reading direction for one element. */
|
|
1622
|
+
export declare function directionOfElement(target: (Element & ElementLike) | null): "ltr" | "rtl";
|
|
1623
|
+
/** The star index an opaque input happened on, or undefined when it did not. */
|
|
1624
|
+
export declare function ratingStarIndexForInput(input: unknown): number | undefined;
|
|
1625
|
+
/**
|
|
1626
|
+
* Horizontal press position inside a star, as a 0..1 fraction.
|
|
1627
|
+
*
|
|
1628
|
+
* Undefined means there is no trustworthy measurement (no star, no layout, or
|
|
1629
|
+
* a different star than the part asked about), so core uses its whole-star
|
|
1630
|
+
* fallback instead of inventing a half.
|
|
1631
|
+
*/
|
|
1632
|
+
export declare function ratingStarFractionForPress(input: unknown, index: number): number | undefined;
|
|
1633
|
+
/** One slide's travel in pixels, measured by the adapter. */
|
|
1634
|
+
export declare function carouselViewportExtent(input: unknown, vertical: boolean): number;
|
|
1635
|
+
/** Captures the gesture on the carousel region when the browser supports it. */
|
|
1636
|
+
export declare function carouselCaptureRegion(input: unknown): void;
|
|
1637
|
+
/** Releases the carousel region's capture. */
|
|
1638
|
+
export declare function carouselReleaseRegion(input: unknown): void;
|
|
1639
|
+
/** The viewport's layout box, the one fact only layout knows. */
|
|
1640
|
+
export declare function imageCropperViewportSize(input: unknown): {
|
|
1641
|
+
readonly width: number;
|
|
1642
|
+
readonly height: number;
|
|
1643
|
+
} | undefined;
|
|
1644
|
+
/** The pointer's position from the viewport's centre, in pixels. */
|
|
1645
|
+
export declare function imageCropperAnchor(input: unknown, box: {
|
|
1646
|
+
readonly width: number;
|
|
1647
|
+
readonly height: number;
|
|
1648
|
+
}): {
|
|
1649
|
+
readonly x: number;
|
|
1650
|
+
readonly y: number;
|
|
1651
|
+
} | undefined;
|
|
1652
|
+
/** The pointer's position inside the viewport, from its top left corner. */
|
|
1653
|
+
export declare function imageCropperViewportPoint(input: unknown): {
|
|
1654
|
+
readonly x: number;
|
|
1655
|
+
readonly y: number;
|
|
1656
|
+
} | undefined;
|
|
1657
|
+
/** Captures the gesture on the viewport when the browser supports it. */
|
|
1658
|
+
export declare function imageCropperCaptureViewport(input: unknown): void;
|
|
1659
|
+
/** Releases the viewport's capture. */
|
|
1660
|
+
export declare function imageCropperReleaseViewport(input: unknown): void;
|
|
1661
|
+
/** A position inside a pad, each axis a fraction of the pad's box. */
|
|
1662
|
+
interface PadPoint {
|
|
1663
|
+
/** 0 at the left edge, 1 at the right. */
|
|
1664
|
+
readonly x: number;
|
|
1665
|
+
/** 0 at the top edge, 1 at the bottom. */
|
|
1666
|
+
readonly y: number;
|
|
1667
|
+
}
|
|
1668
|
+
/**
|
|
1669
|
+
* Where a gesture is: the press that started it, one of its moves, the release
|
|
1670
|
+
* that ended it, or a cancel. A caller that only tracks positions ignores it;
|
|
1671
|
+
* one that commits a value at the end of a gesture needs it.
|
|
1672
|
+
*/
|
|
1673
|
+
type PadPhase = "press" | "move" | "end" | "cancel";
|
|
1674
|
+
/**
|
|
1675
|
+
* Starts a pad drag from one opaque pointer input. Returns the session's ender
|
|
1676
|
+
* when the press was claimed, undefined when it was not (no pointer facts, no
|
|
1677
|
+
* pad under the target, a non-primary press, or the pad is already dragged).
|
|
1678
|
+
*
|
|
1679
|
+
* The session emits the position on the press, on every move and on the
|
|
1680
|
+
* release, each with the phase it is in, and ends itself on the gesture
|
|
1681
|
+
* button's release or a cancel. The ender is idempotent; the caller keeps it
|
|
1682
|
+
* for unmounts that arrive mid-drag.
|
|
1683
|
+
*/
|
|
1684
|
+
export declare function startPadSession(input: unknown, padSelector: string, emit: (point: PadPoint, phase: PadPhase) => void): (() => void) | undefined;
|
|
1685
|
+
/** How far a drag has travelled from its press, in CSS pixels. */
|
|
1686
|
+
interface DragTravel {
|
|
1687
|
+
readonly dx: number;
|
|
1688
|
+
readonly dy: number;
|
|
1689
|
+
}
|
|
1690
|
+
/**
|
|
1691
|
+
* Starts a drag from one opaque pointer input. Returns the session's ender when
|
|
1692
|
+
* the press was claimed, undefined when it was not (no pointer facts, a
|
|
1693
|
+
* non-primary press, or a press of another button).
|
|
1694
|
+
*
|
|
1695
|
+
* The session emits zero travel on the press, the travel so far on every move,
|
|
1696
|
+
* and the final travel on the release. The ender is idempotent; the caller
|
|
1697
|
+
* keeps it for unmounts that arrive mid-drag.
|
|
1698
|
+
*/
|
|
1699
|
+
export declare function startDragSession(input: unknown, emit: (travel: DragTravel, phase: PadPhase) => void): (() => void) | undefined;
|
|
1700
|
+
type ResizableDomDirection = "horizontal" | "vertical";
|
|
1701
|
+
/** A handle as the page sees it. */
|
|
1702
|
+
interface ResizableHandleTarget {
|
|
1703
|
+
/** The handle's element. */
|
|
1704
|
+
readonly el: HTMLElement;
|
|
1705
|
+
/** The group's element. A press only counts when it landed inside it. */
|
|
1706
|
+
readonly root: () => HTMLElement | undefined;
|
|
1707
|
+
/** The axis it moves along, or undefined while it cannot move. */
|
|
1708
|
+
readonly axis: () => "x" | "y" | undefined;
|
|
1709
|
+
/** Its cursor now, which points the only way it can go at a limit. */
|
|
1710
|
+
readonly cursor: () => string;
|
|
1711
|
+
/** Starts the gesture. `release` ends the page's own drag styling. */
|
|
1712
|
+
readonly start: (event: PointerEvent, release: () => void) => void;
|
|
1713
|
+
readonly hover: (hovered: boolean) => void;
|
|
1714
|
+
}
|
|
1715
|
+
/** A point of a drag, in client coordinates. */
|
|
1716
|
+
interface ResizableDragSample {
|
|
1717
|
+
readonly x: number;
|
|
1718
|
+
readonly y: number;
|
|
1719
|
+
readonly event: PointerEvent;
|
|
1720
|
+
}
|
|
1721
|
+
/** The pixels a group's panels share: what the panels measure, whatever the handles take. */
|
|
1722
|
+
export declare function resizableSpace(root: Element, direction: ResizableDomDirection): number;
|
|
1723
|
+
/** Makes a handle findable by the presses and hovers near it. Returns the cleanup. */
|
|
1724
|
+
export declare function registerResizableHandle(target: ResizableHandleTarget): () => void;
|
|
1725
|
+
/** Ends a handle's drag in the page's eyes: its cursor and the drag styles go. */
|
|
1726
|
+
export declare function releaseResizableHandle(target: ResizableHandleTarget): void;
|
|
1727
|
+
/** The cursor may have changed, as it does when a handle reaches a limit. */
|
|
1728
|
+
export declare function refreshResizableCursor(doc: Document): void;
|
|
1729
|
+
/** The cursor for a handle: its axis, or at a limit the one way it can still go. */
|
|
1730
|
+
export declare function resizableCursor(value: {
|
|
1731
|
+
readonly now: number;
|
|
1732
|
+
readonly min: number;
|
|
1733
|
+
readonly max: number;
|
|
1734
|
+
} | undefined, direction: ResizableDomDirection, rtl: boolean): string;
|
|
1735
|
+
/**
|
|
1736
|
+
* Tracks one drag from the press that started it: every move is reported as a
|
|
1737
|
+
* point, and the end says whether Escape cancelled it. The returned ender is
|
|
1738
|
+
* idempotent, for a handle that leaves the page mid-drag.
|
|
1739
|
+
*/
|
|
1740
|
+
export declare function trackResizableDrag(el: HTMLElement, event: PointerEvent, handlers: {
|
|
1741
|
+
readonly onMove: (sample: ResizableDragSample) => void;
|
|
1742
|
+
readonly onEnd: (event: PointerEvent | undefined, canceled: boolean) => void;
|
|
1743
|
+
}): () => void;
|
|
1744
|
+
type RovingOrientation = "horizontal" | "vertical";
|
|
1745
|
+
interface RovingFocusOptions {
|
|
1746
|
+
/** Selector for the items. Defaults to the container's element children. */
|
|
1747
|
+
readonly itemSelector?: string;
|
|
1748
|
+
/** Which arrow pair moves. Defaults to horizontal. */
|
|
1749
|
+
readonly orientation?: RovingOrientation;
|
|
1750
|
+
/** Whether the ends wrap. Defaults to false, which clamps at the ends. */
|
|
1751
|
+
readonly loop?: boolean;
|
|
1752
|
+
/**
|
|
1753
|
+
* Whether movement stops on disabled items, as a menu's does so a person can
|
|
1754
|
+
* hear that a command exists but is unavailable. Defaults to false.
|
|
1755
|
+
*/
|
|
1756
|
+
readonly focusableWhenDisabled?: boolean;
|
|
1757
|
+
/**
|
|
1758
|
+
* Whether a chosen item — pressed, checked, selected or the current page —
|
|
1759
|
+
* claims the tab stop ahead of the first enabled one. Defaults to true. A
|
|
1760
|
+
* toolbar turns it off: a pressed toggle is still just an item there, so Tab
|
|
1761
|
+
* lands where the group's own rules put it.
|
|
1762
|
+
*/
|
|
1763
|
+
readonly chooses?: boolean;
|
|
1764
|
+
/**
|
|
1765
|
+
* Asked before a key is handled, with the item focus is on. True leaves the
|
|
1766
|
+
* key to that item, so a text field keeps the arrows that move its caret.
|
|
1767
|
+
*/
|
|
1768
|
+
readonly keeps?: (item: HTMLElement, event: KeyboardEvent) => boolean;
|
|
1769
|
+
/**
|
|
1770
|
+
* Whether an arrow, Home or End only moves when the key was pressed on an
|
|
1771
|
+
* item itself, so a control inside an item keeps the keys it needs. A held
|
|
1772
|
+
* Shift is left alone too, since it is a selection gesture. Defaults to
|
|
1773
|
+
* false, which moves from anywhere inside the group.
|
|
1774
|
+
*/
|
|
1775
|
+
readonly itemTargetOnly?: boolean;
|
|
1776
|
+
/**
|
|
1777
|
+
* Whether Page Down and Page Up move to the next and previous item, from
|
|
1778
|
+
* anywhere inside one, as the feed pattern asks. They never wrap. Defaults
|
|
1779
|
+
* to false, which leaves the keys to the page.
|
|
1780
|
+
*/
|
|
1781
|
+
readonly pageKeys?: boolean;
|
|
1782
|
+
/** Called after a keyboard move lands on an item, never for a pointer focus. */
|
|
1783
|
+
readonly onFocus?: (item: HTMLElement, event: KeyboardEvent) => void;
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Whether a key belongs to the caret of the text field it was pressed in.
|
|
1787
|
+
*
|
|
1788
|
+
* Home and End always move the caret. A horizontal arrow does while the caret
|
|
1789
|
+
* can still travel the way it points, or while text is selected; at the end it
|
|
1790
|
+
* points at, the key is free for whatever moves between the fields' neighbours.
|
|
1791
|
+
* A field with no caret at all, like a checkbox, keeps no arrow.
|
|
1792
|
+
*/
|
|
1793
|
+
export declare function fieldKeepsCaretKey(event: KeyboardEvent, el: Element): boolean;
|
|
1794
|
+
/**
|
|
1795
|
+
* Puts a text field's caret at the end a move pointed at, so pressing the same
|
|
1796
|
+
* key again travels on instead of walking back through the text.
|
|
1797
|
+
*/
|
|
1798
|
+
export declare function placeFieldCaret(el: Element, atEnd: boolean): void;
|
|
1799
|
+
interface RovingFocus {
|
|
1800
|
+
/**
|
|
1801
|
+
* Stops moving focus (removes the listeners) and leaves tabindex alone.
|
|
1802
|
+
* Returns the element that still carries the tab stop, so a host that
|
|
1803
|
+
* disables a group can put focus somewhere sensible afterwards.
|
|
1804
|
+
*/
|
|
1805
|
+
stop(): HTMLElement | undefined;
|
|
1806
|
+
/** Focuses the item at this index among all items (not only enabled ones). */
|
|
1807
|
+
focus(index: number): void;
|
|
1808
|
+
/** Re-reads the items and re-establishes exactly one tab stop. */
|
|
1809
|
+
refresh(): void;
|
|
1810
|
+
/** Stops the engine and removes the tabindex attributes it wrote. */
|
|
1811
|
+
destroy(): void;
|
|
1812
|
+
}
|
|
1813
|
+
/**
|
|
1814
|
+
* Creates a roving-focus engine over the items inside `container`.
|
|
1815
|
+
*
|
|
1816
|
+
* Exactly one item carries tabindex=0 at any time: the item that had focus
|
|
1817
|
+
* last, else the chosen item, else the first enabled one. Disabled items are
|
|
1818
|
+
* skipped by every movement. A container whose items are all disabled has no tab
|
|
1819
|
+
* stop at all — the honest answer, rather than a stop that goes nowhere.
|
|
1820
|
+
*/
|
|
1821
|
+
export declare function createRovingFocus(container: HTMLElement, options?: RovingFocusOptions): RovingFocus;
|
|
1822
|
+
interface TimelinePositionsOptions {
|
|
1823
|
+
/** Whether the events are a feed, whose articles carry their position. */
|
|
1824
|
+
readonly feed?: () => boolean;
|
|
1825
|
+
}
|
|
1826
|
+
interface TimelinePositions {
|
|
1827
|
+
/** Re-reads the events in document order and writes their marks. */
|
|
1828
|
+
refresh(): void;
|
|
1829
|
+
/** Stops observing and removes what it wrote. */
|
|
1830
|
+
destroy(): void;
|
|
1831
|
+
}
|
|
1832
|
+
/** Keeps the event marks inside `root` true to the page's own order. */
|
|
1833
|
+
export declare function createTimelinePositions(root: HTMLElement, options?: TimelinePositionsOptions): TimelinePositions;
|
|
1834
|
+
interface WaterfallChartRoving {
|
|
1835
|
+
attach(element: unknown): void;
|
|
1836
|
+
sync(): void;
|
|
1837
|
+
focus(id: string): void;
|
|
1838
|
+
focusedRowId(): string | undefined;
|
|
1839
|
+
destroy(): void;
|
|
1840
|
+
}
|
|
1841
|
+
/** Creates the DOM half of the waterfall chart's roving-focus contract. */
|
|
1842
|
+
export declare function createWaterfallChartRoving(): WaterfallChartRoving;
|
|
1843
|
+
/** Whether one input's target is or sits inside an element matching selector. */
|
|
1844
|
+
export declare function inputTargetWithin(input: unknown, selector: string): boolean;
|
|
1845
|
+
/** Whether a table press belongs to the row rather than a control inside it. */
|
|
1846
|
+
export declare function tablePressBelongsToRow(input: unknown): boolean;
|
|
1847
|
+
/** Whether a tree-grid press belongs to the row rather than its twisty. */
|
|
1848
|
+
export declare function treeGridPressBelongsToRow(input: unknown): boolean;
|
|
1849
|
+
/** Whether a pointer/focus movement remains inside the target's nearest region. */
|
|
1850
|
+
export declare function inputMovementStaysWithin(input: unknown, selector: string): boolean;
|
|
1851
|
+
export type ChangeSource = "mouse" | "touch" | "pen" | "keyboard" | "virtual" | "programmatic" | "agent";
|
|
1852
|
+
/** How a change came about, for a callback's source field. */
|
|
1853
|
+
export declare function resolveSource(event: Event | undefined): ChangeSource;
|
|
1854
|
+
export { type AdapterCleanup, type BoxSize, type Breakpoint, type BreakpointName, type ChordShape, type ClipboardEnvironment, type ClipboardFailure, type ClipboardPort, type ClipboardRead, type ClipboardStrategy, type ClipboardWrite, type ColorScheme, type ContrastPreference, type Crossing, type CrossingOptions, type DismissReason, type DragTravel, ENDING_STYLE_ATTRIBUTE, type FocusGuardState, type FocusPull, type InertRegionsOptions, type InputKind, type InputProfile, type Insets, type KeyboardPlatform, type Keycap, type LayerPhase, type MediaAspect, type MediaFacts, type MediaSnapshot, type ModifierKind, type ObservationOptions, type ObservationPlan, type ObservationReport, type ObserveRequest, type ObserveRole, type Orientation, type PadPhase, type PadPoint, type PageRegion, type PhysicalSide, type PlatformProbe, type Point, type PointerKind, type PointerPrecision, type PointerSignal, type PointerState, type PointerTracker, type PointerTrackerOptions, type Rect, type RegionRole, type ResizableDomDirection, type ResizableDragSample, type ResizableHandleTarget, type ResizeBatch, type ResizeEntryLike, type ResizeState, type RovingFocus, type RovingFocusOptions, type RovingOrientation, STARTING_STYLE_ATTRIBUTE, type ScrollAreaDomAxis, type ScrollAreaDomElements, type ScrollBox, type ScrollEdges, type ScrollLockEdits, type ScrollLockInput, type Size, type TimelinePositions, type TimelinePositionsOptions, type ViewportMetrics, type ViewportSample, type VisibilityPolicy, type VisibilitySignals, type VisibilityState, type WaterfallChartRoving };
|