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.

106 lines
3.4 KiB

4 months ago
import { BaseStyleProps, DisplayObject } from '@antv/g';
import type { RuntimeContext } from '../../runtime/types';
import type { IDragEvent, Node } from '../../types';
import type { BasePluginOptions } from '../base-plugin';
import { BasePlugin } from '../base-plugin';
/**
* <zh/> 线
*
* <en/> Snapline plugin options
*/
export interface SnaplineOptions extends BasePluginOptions {
/**
* <zh/> tolerance 线
*
* <en/> The alignment accuracy, that is, when the distance between the moved node and the target position is less than tolerance, the alignment line is displayed
* @defaultValue 5
*/
tolerance?: number;
/**
* <zh/> 线[0, Infinity]
*
* <en/> The extension distance of the snapline. The value range is [0, Infinity]
* @defaultValue 20
*/
offset?: number;
/**
* <zh/>
*
* <en/> Whether to enable automatic adsorption
* @defaultValue true
*/
autoSnap?: boolean;
/**
* <zh/>
*
* <en/> Specifies which shape on the element to use as the reference shape
* @defaultValue `'key'`
* @remarks
* <zh/>
* - 'key' 使
* -
*
* <en/>
* - `'key'` uses the key shape of the element as the reference shape
* - You can also pass in a function that receives the element and returns a shape
*/
shape?: string | ((node: Node) => DisplayObject);
/**
* <zh/> 线
*
* <en/> Vertical snapline style
* @defaultValue `{ stroke: '#1783FF' }`
*/
verticalLineStyle?: BaseStyleProps;
/**
* <zh/> 线
*
* <en/> Horizontal snapline style
* @defaultValue `{ stroke: '#1783FF' }`
*/
horizontalLineStyle?: BaseStyleProps;
/**
* <zh/>
*
* <en/> Filter, used to filter nodes that do not need to be used as references
* @defaultValue `() => true`
*/
filter?: (node: Node) => boolean;
}
/**
* <zh/> 线
*
* <en/> Snapline plugin
*/
export declare class Snapline extends BasePlugin<SnaplineOptions> {
static defaultOptions: Partial<SnaplineOptions>;
private horizontalLine;
private verticalLine;
constructor(context: RuntimeContext, options: SnaplineOptions);
private initSnapline;
private getNodes;
private hideSnapline;
private getLineWidth;
private updateSnapline;
private isHorizontalSticking;
private isVerticalSticking;
private enableStick;
private autoSnapToLine;
/**
* Get the delta of the drag
* @param event - drag event object
* @returns delta
* @internal
*/
protected getDelta(event: IDragEvent<Node>): import("../../types").Vector2 | import("../../types").Vector3;
private enableSnap;
private calcSnaplineMetadata;
protected onDragStart: () => void;
protected onDrag: (event: IDragEvent<Node>) => Promise<void>;
protected onDragEnd: () => void;
private bindEvents;
private unbindEvents;
private destroyElements;
destroy(): void;
}