Documentation / @ripl/core / Navigator
Class: Navigator
Defined in: packages/core/src/core/navigator.ts:133
An interactive 2D pan/zoom/brush controller — the flat-scene analogue of the 3D Camera. This base class is deliberately context-agnostic: it owns the view model (a { k, x, y } transform plus an optional brush selection) and the imperative commands that mutate it, but it attaches no input listeners of its own. That mirrors the Context/DOMContext split — the DOM-bound DOMNavigator in @ripl/dom extends this class to translate real wheel/pointer/touch gestures into these commands, while non-DOM environments can drive the same view model programmatically (or subclass it with their own input source).
The navigator does not itself repaint; consumers react to the emitted zoom/pan/change/ brush/brushend events (e.g. rescaling axis domains via rescaleDomain, or applying the transform to a context). Translation is unbounded, so a consumer can pan and zoom to content that currently sits outside the viewport — the Figma-style "navigate anywhere" behaviour.
Extends
Extended by
Constructors
Constructor
new Navigator(
options?):Navigator
Defined in: packages/core/src/core/navigator.ts:145
Parameters
| Parameter | Type |
|---|---|
options? | NavigatorOptions |
Returns
Navigator
Overrides
Properties
| Property | Modifier | Type | Default value | Description | Inherited from | Defined in |
|---|---|---|---|---|---|---|
_brush | protected | NavigatorBrush | null | null | - | - | packages/core/src/core/navigator.ts:141 |
_scaleExtent | protected | [number, number] | undefined | - | - | packages/core/src/core/navigator.ts:142 |
_transform | protected | NavigatorTransform | undefined | - | - | packages/core/src/core/navigator.ts:135 |
_viewport | protected | NavigatorViewport | undefined | - | - | packages/core/src/core/navigator.ts:143 |
parent? | public | EventBus<NavigatorEventMap> | undefined | The parent event bus that emitted events bubble up to, if any. | EventBus.parent | packages/core/src/core/event-bus.ts:89 |
defaultKey | readonly | typeof defaultKey | undefined | The key under which resources are retained when no explicit key is provided. | EventBus.defaultKey | packages/core/src/core/disposer.ts:11 |
Accessors
brush
Get Signature
get brush():
NavigatorBrush|null
Defined in: packages/core/src/core/navigator.ts:163
The current brush selection, or null when nothing is selected.
Returns
NavigatorBrush | null
scaleExtent
Get Signature
get scaleExtent(): [
number,number]
Defined in: packages/core/src/core/navigator.ts:170
The minimum/maximum zoom factor the transform is clamped to.
Returns
[number, number]
transform
Get Signature
get transform():
NavigatorTransform
Defined in: packages/core/src/core/navigator.ts:156
The current view transform (a copy — mutating it does not affect the navigator).
Returns
viewport
Get Signature
get viewport():
NavigatorViewport
Defined in: packages/core/src/core/navigator.ts:177
The viewport dimensions used by centerOn/fitBounds.
Returns
Set Signature
set viewport(
viewport):void
Defined in: packages/core/src/core/navigator.ts:183
Parameters
| Parameter | Type |
|---|---|
viewport | NavigatorViewport |
Returns
void
Methods
_commit()
protected_commit(event):void
Defined in: packages/core/src/core/navigator.ts:189
Parameters
| Parameter | Type |
|---|---|
event | "zoom" | "pan" |
Returns
void
applyPoint()
applyPoint(
point):Point
Defined in: packages/core/src/core/navigator.ts:197
Applies the transform to a point in content space, returning its on-screen position.
Parameters
| Parameter | Type |
|---|---|
point | Point |
Returns
centerOn()
centerOn(
point,viewport?):void
Defined in: packages/core/src/core/navigator.ts:268
Centres a content-space point within the viewport, keeping the current zoom. Useful for bringing an off-screen element into view without changing scale.
Parameters
| Parameter | Type |
|---|---|
point | Point |
viewport | NavigatorViewport |
Returns
void
clearBrush()
clearBrush():
void
Defined in: packages/core/src/core/navigator.ts:336
Clears the brush selection and emits a brushend event with null.
Returns
void
destroy()
destroy():
void
Defined in: packages/core/src/core/event-bus.ts:165
Emits a destroyed event, clears all listeners, and disposes retained resources.
Returns
void
Inherited from
dispose()
protecteddispose(key?):void
Defined in: packages/core/src/core/disposer.ts:25
Disposes all resources under the given key, or all resources if no key is provided.
Parameters
| Parameter | Type |
|---|---|
key? | PropertyKey |
Returns
void
Inherited from
emit()
Call Signature
emit<
TEvent>(event):TEvent
Defined in: packages/core/src/core/event-bus.ts:137
Emits an event, invoking all matching handlers and bubbling to the parent if applicable.
Type Parameters
| Type Parameter | Default type |
|---|---|
TEvent extends Event<undefined> | Event<undefined> |
Parameters
| Parameter | Type |
|---|---|
event | TEvent |
Returns
TEvent
Inherited from
Call Signature
emit<
TEvent>(type,data):Event<NavigatorEventMap[TEvent]>
Defined in: packages/core/src/core/event-bus.ts:138
Emits an event, invoking all matching handlers and bubbling to the parent if applicable.
Type Parameters
| Type Parameter |
|---|
TEvent extends keyof NavigatorEventMap |
Parameters
| Parameter | Type |
|---|---|
type | TEvent |
data | NavigatorEventMap[TEvent] |
Returns
Event<NavigatorEventMap[TEvent]>
Inherited from
fitBounds()
fitBounds(
bounds,options?):void
Defined in: packages/core/src/core/navigator.ts:285
Zooms and pans so a content-space box fills the viewport (respecting the scale extent and an optional padding). This is the primary way to jump the view to content — including content that currently lies entirely outside the viewport.
Parameters
| Parameter | Type |
|---|---|
bounds | NavigatorBrush |
options? | NavigatorFitOptions |
Returns
void
has()
has(
type):boolean
Defined in: packages/core/src/core/event-bus.ts:94
Returns whether there are any listeners registered for the given event type.
Parameters
| Parameter | Type |
|---|---|
type | keyof NavigatorEventMap |
Returns
boolean
Inherited from
invertPoint()
invertPoint(
point):Point
Defined in: packages/core/src/core/navigator.ts:205
Inverts a screen-space point back to content space.
Parameters
| Parameter | Type |
|---|---|
point | Point |
Returns
off()
off<
TEvent>(type,handler):void
Defined in: packages/core/src/core/event-bus.ts:112
Removes a previously registered handler for the given event type.
Type Parameters
| Type Parameter |
|---|
TEvent extends keyof NavigatorEventMap |
Parameters
| Parameter | Type |
|---|---|
type | TEvent |
handler | EventHandler<NavigatorEventMap[TEvent]> |
Returns
void
Inherited from
on()
on<
TEvent>(type,handler,options?):Disposable
Defined in: packages/core/src/core/event-bus.ts:99
Subscribes a handler to the given event type and returns a disposable for cleanup.
Type Parameters
| Type Parameter |
|---|
TEvent extends keyof NavigatorEventMap |
Parameters
| Parameter | Type |
|---|---|
type | TEvent |
handler | EventHandler<NavigatorEventMap[TEvent]> |
options? | EventSubscriptionOptions |
Returns
Inherited from
once()
once<
TEvent>(type,handler,options?):Disposable
Defined in: packages/core/src/core/event-bus.ts:127
Subscribes a handler that is automatically removed after it fires once.
Type Parameters
| Type Parameter |
|---|
TEvent extends keyof NavigatorEventMap |
Parameters
| Parameter | Type |
|---|---|
type | TEvent |
handler | EventHandler<NavigatorEventMap[TEvent]> |
options? | EventSubscriptionOptions |
Returns
Inherited from
panBy()
panBy(
dx,dy):void
Defined in: packages/core/src/core/navigator.ts:224
Pans the view by a pixel delta.
Parameters
| Parameter | Type |
|---|---|
dx | number |
dy | number |
Returns
void
panTo()
panTo(
x,y):void
Defined in: packages/core/src/core/navigator.ts:235
Pans the view to an absolute translation.
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns
void
reset()
reset():
void
Defined in: packages/core/src/core/navigator.ts:313
Resets the transform to the identity (no zoom, no pan).
Returns
void
retain()
protectedretain(value,key?):void
Defined in: packages/core/src/core/disposer.ts:14
Registers a disposable resource under an optional key for later cleanup.
Parameters
| Parameter | Type | Default value |
|---|---|---|
value | Disposable | undefined |
key | PropertyKey | Disposer.defaultKey |
Returns
void
Inherited from
setBrush()
setBrush(
brush):void
Defined in: packages/core/src/core/navigator.ts:324
Sets the brush selection, normalising the extent, and emits a brush event.
Parameters
| Parameter | Type |
|---|---|
brush | NavigatorBrush |
Returns
void
setTransform()
setTransform(
transform):void
Defined in: packages/core/src/core/navigator.ts:213
Replaces the view transform outright (clamping k to the scale extent).
Parameters
| Parameter | Type |
|---|---|
transform | NavigatorTransform |
Returns
void
zoomBy()
zoomBy(
factor,center?):void
Defined in: packages/core/src/core/navigator.ts:246
Multiplies the zoom by factor, keeping center (screen pixels, defaults to the origin) fixed.
Parameters
| Parameter | Type |
|---|---|
factor | number |
center | Point |
Returns
void
zoomTo()
zoomTo(
k,center?):void
Defined in: packages/core/src/core/navigator.ts:260
Sets the absolute zoom factor, keeping center fixed.
Parameters
| Parameter | Type |
|---|---|
k | number |
center | Point |
Returns
void