Skip to content

@ue-too/board / CameraMux

Interface: CameraMux

Defined in: packages/board/src/camera/camera-mux/interface.ts:139

Input multiplexer interface for camera control flow management. Acts as a gatekeeper that can allow or block camera inputs based on state.

Remarks

The CameraMux pattern enables:

  • Input arbitration: Decide which inputs should affect the camera
  • Animation systems: Block user input during camera animations
  • State management: Control camera behavior based on application state
  • Input filtering: Modify or clamp inputs before applying to camera

Implementations can be:

  • Stateless: Always pass through (e.g., Relay)
  • Stateful: Block inputs during animations or specific states
  • Smart: Modify inputs based on context (e.g., smooth damping)

Example

typescript
// Simple relay implementation
class SimpleMux implements CameraMux {
  notifyPanInput(diff: Point): CameraMuxPanOutput {
    return { allowPassThrough: true, delta: diff };
  }
  notifyZoomInput(delta: number, anchor: Point): CameraMuxZoomOutput {
    return { allowPassThrough: true, delta, anchorPoint: anchor };
  }
  notifyRotationInput(delta: number): CameraMuxRotationOutput {
    return { allowPassThrough: true, delta };
  }
}

// Animation-blocking implementation
class AnimatedMux implements CameraMux {
  private isAnimating = false;

  notifyPanInput(diff: Point): CameraMuxPanOutput {
    if (this.isAnimating) {
      return { allowPassThrough: false };
    }
    return { allowPassThrough: true, delta: diff };
  }
  // ... similar for zoom and rotation
}

See

Relay for a simple passthrough implementation

Methods

notifyPanInput()

notifyPanInput(diff): CameraMuxPanOutput

Defined in: packages/board/src/camera/camera-mux/interface.ts:146

Processes a pan input request.

Parameters

diff

Point

Pan displacement in viewport space (CSS pixels)

Returns

CameraMuxPanOutput

Output indicating if pan is allowed and the delta to apply


notifyRotationInput()

notifyRotationInput(deltaRotation): CameraMuxRotationOutput

Defined in: packages/board/src/camera/camera-mux/interface.ts:166

Processes a rotation input request.

Parameters

deltaRotation

number

Change in rotation in radians

Returns

CameraMuxRotationOutput

Output indicating if rotation is allowed and the delta to apply


notifyZoomInput()

notifyZoomInput(deltaZoomAmount, anchorPoint): CameraMuxZoomOutput

Defined in: packages/board/src/camera/camera-mux/interface.ts:155

Processes a zoom input request.

Parameters

deltaZoomAmount

number

Change in zoom level (positive = zoom in, negative = zoom out)

anchorPoint

Point

Point to zoom towards in viewport coordinates (typically cursor position)

Returns

CameraMuxZoomOutput

Output indicating if zoom is allowed and the parameters to apply