element-by-point
Track the element(s) under a client coordinate.
| Package | @vizejs/composable/element-by-point |
| Own the source | vize lib pull composable:element-by-point |
| Runtime exports | useElementByPoint |
| Gzip budget | 1536 B |
Usage
import { useElementByPoint } from "@vizejs/composable/element-by-point";
Runtime contract
| Utility | Category | Stability | SSR | Hydration | Cleanup | Targets | Host globals | Uses |
|---|---|---|---|---|---|---|---|---|
useElementByPoint |
dom | experimental | deterministic-fallback | stable | reactive-scope | web, desktop | document, window |
tryOnScopeDispose |
API
useElementByPoint
Track the element(s) under a client coordinate. Re-queries whenever x/y change and, with poll, on every animation frame until the owning scope stops. Server renders expose null and an empty list.
function useElementByPoint(options: UseElementByPointOptions): ElementByPointControls
Types
ElementByPointHost
Document-like capability used by useElementByPoint.
| Member | Type | Description |
|---|---|---|
elementFromPoint |
(x: number, y: number) => Element | null |
Topmost element at a point. |
elementsFromPoint? |
(x: number, y: number) => Element[] |
Every element at a point, topmost first. Optional: when missing, only the topmost element is reported. |
ElementByPointFrameHost
Frame scheduler used for continuous polling.
| Member | Type | Description |
|---|---|---|
requestAnimationFrame |
(callback: FrameRequestCallback) => number |
Schedule a callback before the next repaint. |
cancelAnimationFrame |
(handle: number) => void |
Cancel a scheduled frame. |
UseElementByPointOptions
Options for useElementByPoint.
| Member | Type | Description |
|---|---|---|
x |
MaybeRefOrGetter<number> |
Horizontal client coordinate. |
y |
MaybeRefOrGetter<number> |
Vertical client coordinate. |
poll? |
boolean |
Also re-query every animation frame (the element under a fixed point can change when the page scrolls or animates). |
host? |
MaybeRefOrGetter<ElementByPointHost | null | undefined> |
Reactive document capability for alternate runtimes and tests. |
frameHost? |
MaybeRefOrGetter<ElementByPointFrameHost | null | undefined> |
Frame scheduler used when poll is enabled. |
ElementByPointControls
Reactive state returned by useElementByPoint.
| Member | Type | Description |
|---|---|---|
isSupported |
Readonly<Ref<boolean>> |
Whether a document capability is attached. false during server rendering. |
element |
Readonly<ShallowRef<Element | null>> |
Topmost element at the point. |
elements |
Readonly<ShallowRef<readonly Element[]>> |
Every element at the point, topmost first. |
update |
() => void |
Re-query immediately. |