Skip to content

@ue-too/board / index / TouchInputTracker

Class: TouchInputTracker ​

Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:99

Production implementation of TouchContext that tracks multi-touch state.

Remarks ​

This class maintains a map of active touch points, storing their initial positions to enable gesture recognition. The state machine uses this context to:

  • Calculate pan deltas (difference between initial and current midpoint)
  • Calculate zoom factors (change in distance between two touch points)
  • Determine gesture type (pan vs zoom based on relative magnitudes)

Touch Point Lifecycle:

  1. addTouchPoints: Called on touchstart to register new touches
  2. updateTouchPoints: Called on touchmove to update current positions
  3. removeTouchPoints: Called on touchend/touchcancel to unregister touches

The initial positions are preserved until the touch ends, allowing continuous calculation of deltas throughout the gesture.

Example ​

typescript
const canvasProxy = new CanvasProxy(canvasElement);
const context = new TouchInputTracker(canvasProxy);
const stateMachine = createTouchInputStateMachine(context);

// When a two-finger touch starts
context.addTouchPoints([
  {ident: 0, x: 100, y: 200},
  {ident: 1, x: 300, y: 200}
]);
console.log(context.getCurrentTouchPointsCount()); // 2

Implements ​

Constructors ​

Constructor ​

new TouchInputTracker(canvas): TouchInputTracker

Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:107

Parameters ​

canvas ​

Canvas

Returns ​

TouchInputTracker

Accessors ​

alignCoordinateSystem ​

Get Signature ​

get alignCoordinateSystem(): boolean

Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:151

Whether to use standard screen coordinate system (vs inverted Y-axis)

Returns ​

boolean

Set Signature ​

set alignCoordinateSystem(value): void

Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:155

Whether to use standard screen coordinate system (vs inverted Y-axis)

Parameters ​
value ​

boolean

Returns ​

void

Whether to use standard screen coordinate system (vs inverted Y-axis)

Implementation of ​

TouchContext.alignCoordinateSystem


canvas ​

Get Signature ​

get canvas(): Canvas

Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:159

Canvas accessor for dimensions and coordinate transformations

Returns ​

Canvas

Canvas accessor for dimensions and coordinate transformations

Implementation of ​

TouchContext.canvas

Methods ​

addTouchPoints() ​

addTouchPoints(points): void

Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:112

Adds new touch points to tracking

Parameters ​

points ​

TouchPoints[]

Returns ​

void

Implementation of ​

TouchContext.addTouchPoints


cleanup() ​

cleanup(): void

Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:163

Returns ​

void

Implementation of ​

TouchContext.cleanup


getCurrentTouchPointsCount() ​

getCurrentTouchPointsCount(): number

Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:126

Returns the current number of active touch points

Returns ​

number

Implementation of ​

TouchContext.getCurrentTouchPointsCount


getInitialTouchPointsPositions() ​

getInitialTouchPointsPositions(idents): TouchPoints[]

Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:130

Retrieves the initial positions of specific touch points

Parameters ​

idents ​

number[]

Returns ​

TouchPoints[]

Implementation of ​

TouchContext.getInitialTouchPointsPositions


removeTouchPoints() ​

removeTouchPoints(identifiers): void

Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:118

Removes touch points from tracking by identifier

Parameters ​

identifiers ​

number[]

Returns ​

void

Implementation of ​

TouchContext.removeTouchPoints


setup() ​

setup(): void

Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:165

Returns ​

void

Implementation of ​

TouchContext.setup


updateTouchPoints() ​

updateTouchPoints(pointsMoved): void

Defined in: packages/board/src/input-interpretation/input-state-machine/touch-input-context.ts:143

Updates the current positions of touch points

Parameters ​

pointsMoved ​

TouchPoints[]

Returns ​

void

Implementation of ​

TouchContext.updateTouchPoints