You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.6 KiB

4 months ago
import type { RuntimeContext } from '../runtime/types';
import type { IKeyboardEvent, IPointerEvent, Vector2, ViewportAnimationEffectTiming } from '../types';
import type { ShortcutKey } from '../utils/shortcut';
import type { BaseBehaviorOptions } from './base-behavior';
import { BaseBehavior } from './base-behavior';
/**
* <zh/>
*
* <en/> Drag canvas behavior options
*/
export interface DragCanvasOptions extends BaseBehaviorOptions {
/**
* <zh/> 使
*
* <en/> Whether to enable the animation of dragging, only valid when using key movement
*/
animation?: ViewportAnimationEffectTiming;
/**
* <zh/>
*
* <en/> Whether to enable the function of dragging the canvas
* @defaultValue true
*/
enable?: boolean | ((event: IPointerEvent | IKeyboardEvent) => boolean);
/**
* <zh/>
* - `'x'`:
* - `'y'`:
* - `'both'`:
*
* <en/> Allowed drag direction
* - `'x'`: Only allow horizontal drag
* - `'y'`: Only allow vertical drag
* - `'both'`: Allow horizontal and vertical drag
* @defaultValue `'both'`
*/
direction?: 'x' | 'y' | 'both';
/**
* <zh/> [0, Infinity]
*
* <en/> The draggable viewport range allows you to drag up to one screen by default. You can set the range for each direction (top, right, bottom, left) individually, with each direction's range between [0, Infinity]
* @defaultValue Infinity
*/
range?: number | number[];
/**
* <zh/> 使
*
* <en/> The way to trigger dragging, default to dragging with the pointer pressed
*/
trigger?: {
up: ShortcutKey;
down: ShortcutKey;
left: ShortcutKey;
right: ShortcutKey;
};
/**
* <zh/>
*
* <en/> The distance of a single key movement
* @defaultValue 10
*/
sensitivity?: number;
/**
* <zh/>
*
* <en/> Callback when dragging is completed
*/
onFinish?: () => void;
}
/**
* <zh/>
*
* <en/> Drag canvas behavior
*/
export declare class DragCanvas extends BaseBehavior<DragCanvasOptions> {
static defaultOptions: Partial<DragCanvasOptions>;
private shortcut;
private defaultCursor;
constructor(context: RuntimeContext, options: DragCanvasOptions);
/**
* <zh/>
*
* <en/> Update options
* @param options - <zh/> | <en/> Options
* @internal
*/
update(options: Partial<DragCanvasOptions>): void;
private bindEvents;
private isDragging;
private onDragStart;
private onDrag;
private onDragEnd;
private invokeOnFinish;
private onTranslate;
/**
* <zh/>
*
* <en/> Translate canvas
* @param offset - <zh/> | <en/> Translation distance
* @param animation - <zh/> | <en/> Animation configuration
* @internal
*/
protected translate(offset: Vector2, animation?: ViewportAnimationEffectTiming): Promise<void>;
private clampByRotation;
private clampByDirection;
private clampByRange;
private validate;
private unbindEvents;
destroy(): void;
}