UNPKG

@ue-too/board

Version:
114 lines (113 loc) 5.89 kB
import { Point } from "@ue-too/math"; import { BoardCamera } from "../interface"; /** * @description Configuration for the pan handler functions. * * @category Camera */ export type PanHandlerConfig = PanHandlerRestrictionConfig & PanHandlerClampConfig; export type PanHandlerClampConfig = { /** * @description Whether to limit the pan to the entire view port. */ limitEntireViewPort: boolean; /** * @description Whether to clamp the translation. */ clampTranslation: boolean; }; export type PanHandlerRestrictionConfig = { /** * @description Whether to restrict the x translation. */ restrictXTranslation: boolean; /** * @description Whether to restrict the y translation. */ restrictYTranslation: boolean; /** * @description Whether to restrict the relative x translation. (because the camera can be rotated, the relative x translation is the horizontal direction of what the user sees on the screen) */ restrictRelativeXTranslation: boolean; /** * @description Whether to restrict the relative y translation. (because the camera can be rotated, the relative y translation is the vertical direction of what the user sees on the screen) */ restrictRelativeYTranslation: boolean; }; /** * @description Function Type that is used to define the "pan to" handler. * The destination is in "stage/context/world" space. * This is structured as a handler pipeline. * @see {@link createHandlerChain} * @category Camera */ export type PanToHandlerFunction = (destination: Point, camera: BoardCamera, config: PanHandlerConfig) => Point; /** * @description Function Type that is used to define the "pan by" handler. * The delta is in "stage/context/world" space. * This is structured as a handler pipeline. * @see {@link createHandlerChain} * @category Camera */ export type PanByHandlerFunction = (delta: Point, camera: BoardCamera, config: PanHandlerConfig) => Point; /** * @description Helper function that creates a default "pan to" handler. * The default pan to handler will first restrict the pan to the view port, then clamp the pan to the boundaries, and then pan to the destination. * * @see {@link createHandlerChain} to create your own custom pan handler pipeline. (you can also use this function as a part of your own custom pan handler pipeline) * @category Camera */ export declare function createDefaultPanToHandler(): PanToHandlerFunction; /** * @description Helper function that creates a default "pan by" handler. * The resulting pan by handler takes in a delta that is in "stage/context/world" space. * The default pan by handler will first restrict the pan by the view port, then clamp the pan by the boundaries, and then pan by the delta. * * @see {@link createHandlerChain} to create your own custom pan handler pipeline. (you can also use this function as a part of your own custom pan handler pipeline) * @category Camera */ export declare function createDefaultPanByHandler(): PanByHandlerFunction; /** * @description Function that is part of the "pan to" handler pipeline. It restricts the "pan to" destination to within a single axis based on the config. (relative to the current camera position) * You can use this function standalone to restrict the "pan to" destination to within a single axis based on the config. * But it is recommended to use this kind of function as part of the pan handler pipeline. (to include this function in your own custom pan handler pipeline) * * @category Camera */ export declare function restrictPanToHandler(destination: Point, camera: BoardCamera, config: PanHandlerRestrictionConfig): Point; /** * @description Function that is part of the "pan by" handler pipeline. It restricts the pan delta to within a single axis based on the config. (relative to the current camera position) * You can use this function standalone to restrict the pan delta to within a single axis based on the config. * But it is recommended to use this kind of function as part of the pan handler pipeline. (to include this function in your own custom pan handler pipeline) * * @category Camera */ export declare function restrictPanByHandler(delta: Point, camera: BoardCamera, config: PanHandlerRestrictionConfig): Point; /** * @description Function that is part of the "pan to" handler pipeline. It clamps the pan destination within the boundaries of the view port. * You can use this function standalone to clamp the pan destination within the boundaries of the view port. * But it is recommended to use this kind of function as part of the pan handler pipeline. (to include this function in your own custom pan handler pipeline) * * @category Camera */ export declare function clampToHandler(destination: Point, camera: BoardCamera, config: PanHandlerClampConfig): Point; /** * @description Function that is part of the "pan by" handler pipeline. It clamps the pan delta within the boundaries of the view port. * You can use this function standalone to clamp the pan delta within the boundaries of the view port. * But it is recommended to use this kind of function as part of the pan handler pipeline. (to include this function in your own custom pan handler pipeline) * * @category Camera */ export declare function clampByHandler(delta: Point, camera: BoardCamera, config: PanHandlerClampConfig): Point; /** * @description Helper function that converts the delta to comply with the restrictions of the config. * * @category Camera */ export declare function convertDeltaToComplyWithRestriction(delta: Point, camera: BoardCamera, config: PanHandlerRestrictionConfig): Point; /** * @description Helper function that converts the user input delta to the camera delta. * * @category Camera */ export declare function convertUserInputDeltaToCameraDelta(delta: Point, camera: BoardCamera): Point;