pointer
Track the latest pointer (mouse, touch, or pen) state.
| Package | @vizejs/composable/pointer |
| Own the source | vize lib pull composable:pointer |
| Runtime exports | usePointer, toPointerKind |
| Gzip budget | 1792 B |
Usage
import { usePointer, toPointerKind } from "@vizejs/composable/pointer";
Runtime contract
| Utility | Category | Stability | SSR | Hydration | Cleanup | Targets | Host globals | Uses |
|---|---|---|---|---|---|---|---|---|
usePointer |
input | experimental | deterministic-fallback | stable | caller, reactive-scope | web, desktop | window |
toPointerKind, tryOnScopeDispose |
toPointerKind |
input | experimental | safe | not-applicable | none | web, server, worker, native, desktop, terminal | — | — |
API
usePointer
Track the latest pointer (mouse, touch, or pen) state. Listens passively for pointerdown, pointermove, pointerup, and pointerleave on the reactive target and filters by device kind. Listeners are removed with the owning reactive scope; server renders expose the initial snapshot.
function usePointer(options: UsePointerOptions = {}): PointerControls
toPointerKind
Narrow a platform pointerType string to the closed PointerKind union.
function toPointerKind(value: string): PointerKind | null
Types
PointerState
Snapshot of the latest pointer event.
| Member | Type | Description |
|---|---|---|
x |
number |
Horizontal client coordinate. |
y |
number |
Vertical client coordinate. |
pressure |
number |
Normalized pressure in [0, 1]. |
pointerId |
number |
Identifier of the pointer that produced the latest event. |
tiltX |
number |
Pen tilt around the Y axis in degrees. |
tiltY |
number |
Pen tilt around the X axis in degrees. |
width |
number |
Contact geometry width in CSS pixels. |
height |
number |
Contact geometry height in CSS pixels. |
twist |
number |
Pen rotation in degrees. |
pointerType |
PointerKind | null |
Device kind; null before the first event. |
UsePointerOptions
Options for usePointer.
| Member | Type | Description |
|---|---|---|
pointerTypes? |
readonly PointerKind[] |
Device kinds to track. |
target? |
MaybeRefOrGetter<EventTarget | null | undefined> |
Event target to listen on. |
initialValue? |
Partial<PointerState> |
State exposed before any input and during server rendering. |
PointerControls
Reactive pointer state returned by usePointer.
| Member | Type | Description |
|---|---|---|
state |
Readonly<PointerState> |
Latest pointer snapshot. |
isInside |
Readonly<Ref<boolean>> |
Whether the pointer is inside the target (between enter/move and leave). |