@ue-too/board
Version:
131 lines (130 loc) • 5.02 kB
TypeScript
import { Point } from "@ue-too/math";
import { BaseContext } from "@ue-too/being";
import { UserInputPublisher } from "../raw-input-publisher";
import { CanvasPositionDimensionPublisher } from "../../utils";
export declare enum CursorStyle {
GRAB = "grab",
DEFAULT = "default",
GRABBING = "grabbing"
}
/**
* @description A proxy for the canvas so that client code that needs to access
* the canvas dimensions and position does not need to access the DOM directly.
*/
export interface CanvasOperator {
width: number;
height: number;
position: Point;
setCursor: (style: CursorStyle) => void;
}
/**
* @description A dummy implementation of the CanvasOperator interface.
* This is specifically for the case where a input state machine that is for the relay of the input events to the web worker.
* The input state machine needs a canvas operator in its context, but this context does not have any functionality.
* @see DummyKmtInputContext
*/
export declare class DummyCanvasOperator implements CanvasOperator {
width: number;
height: number;
position: Point;
setCursor: (style: CursorStyle) => void;
}
export declare class CanvasCacheInWebWorker implements CanvasOperator {
private _width;
private _height;
private _position;
private _postMessageFunction;
constructor(postMessageFunction: typeof postMessage);
set width(width: number);
set height(height: number);
set position(position: Point);
get width(): number;
get height(): number;
get position(): Point;
setCursor(style: "grab" | "default" | "grabbing"): void;
}
export declare class CanvasProxy implements CanvasOperator {
private _width;
private _height;
private _position;
private _canvasPositionDimensionPublisher;
private _canvas;
constructor(canvas: HTMLCanvasElement, canvasPositionDimensionPublisher?: CanvasPositionDimensionPublisher);
get width(): number;
get height(): number;
get position(): Point;
setCursor(style: "grab" | "default" | "grabbing"): void;
attach(canvas: HTMLCanvasElement): void;
}
/**
* @description A proxy for the canvas that is used to communicate with the web worker.
* The primary purpose of this class is to cache the canvas dimensions and position in the DOM to reduce the calling of the getBoundingClientRect method.
* This class only serves as a relay of the updated canvas dimensions and position to the web worker.
*
*/
export declare class CanvasProxyWorkerRelay implements CanvasOperator {
private _width;
private _height;
private _position;
private _webWorker;
private _canvas;
constructor(canvas: HTMLCanvasElement, webWorker: Worker, canvasDiemsionPublisher: CanvasPositionDimensionPublisher);
get width(): number;
get height(): number;
get position(): Point;
setCursor(style: "grab" | "default" | "grabbing"): void;
}
/**
* @description The context for the keyboard mouse and trackpad input state machine.
*
* @category Input State Machine
*/
export interface KmtInputContext extends BaseContext {
alignCoordinateSystem: boolean;
canvas: CanvasOperator;
notifyOnPan: (delta: Point) => void;
notifyOnZoom: (zoomAmount: number, anchorPoint: Point) => void;
notifyOnRotate: (deltaRotation: number) => void;
setInitialCursorPosition: (position: Point) => void;
initialCursorPosition: Point;
}
/**
* @description A dummy implementation of the KmtInputContext interface.
* This is specifically for the case where a input state machine that is for the relay of the input events to the web worker.
* The input state machine needs a context, but this context does not have any functionality.
*/
export declare class DummyKmtInputContext implements KmtInputContext {
alignCoordinateSystem: boolean;
canvas: CanvasOperator;
initialCursorPosition: Point;
constructor();
notifyOnPan(delta: Point): void;
notifyOnZoom(zoomAmount: number, anchorPoint: Point): void;
notifyOnRotate(deltaRotation: number): void;
setInitialCursorPosition(position: Point): void;
cleanup(): void;
setup(): void;
}
/**
* @description The observable input tracker.
* This is used as the context for the keyboard mouse and trackpad input state machine.
*
* @category Input State Machine
*/
export declare class ObservableInputTracker implements KmtInputContext {
private _alignCoordinateSystem;
private _canvasOperator;
private _inputPublisher;
private _initialCursorPosition;
constructor(canvasOperator: CanvasOperator, inputPublisher: UserInputPublisher);
get alignCoordinateSystem(): boolean;
get canvas(): CanvasOperator;
get initialCursorPosition(): Point;
set alignCoordinateSystem(value: boolean);
notifyOnPan(delta: Point): void;
notifyOnZoom(zoomAmount: number, anchorPoint: Point): void;
notifyOnRotate(deltaRotation: number): void;
setInitialCursorPosition(position: Point): void;
cleanup(): void;
setup(): void;
}