import type { DisplayObject } from '@antv/g'; import type { ComboOptions, EdgeOptions, NodeOptions } from '../spec'; import type { Point, Port } from '../types'; /** * 节点类型 * * Node type */ export interface Node extends DisplayObject, ElementHooks, ElementMethods { /** * 获取连接桩 * * Get the ports */ getPorts(): Record; /** * 获取节点中心位置 * * Get the center position of the node */ getCenter(): Point; /** * 获取交点位置 * * Get the intersection point * @param point - 外部位置 | external position * @param useExtendedLine - 是否使用延长线 | whether to use the extended line * @returns 交点位置 | intersection point * @remarks * 给定一个外部位置,返回当前节点与该位置的连边与节点的交点位置 * * Given an external position, return the intersection point of the edge between the current node and the position and the node */ getIntersectPoint(point: Point, useExtendedLine?: boolean): Point; } /** * 边类型 * * Edge type */ export interface Edge extends DisplayObject, ElementHooks, ElementMethods { } /** * 组合类型 * * Combo type */ export interface Combo extends Node { /** * 获取组合的位置 * * Get the position of the combo * @param attributes - 组合属性 | combo attributes */ getComboPosition(attributes: Record): Point; } export type Element = Node | Edge | Combo; export type ElementType = 'node' | 'edge' | 'combo'; export type ElementOptions = NodeOptions | EdgeOptions | ComboOptions; /** * 元素方法 * * Element methods */ export interface ElementMethods { /** * 更新元素属性 * * Update element attributes * @param attr - 属性 | Attributes */ update(attr: any): void; /** * 获取当前元素内的子图形 * * Get the subgraph in the current element * @param shapeID - 子图形 ID | Subgraph ID * @returns 子图形 | Subgraph */ getShape(shapeID: string): T; } /** * 元素钩子方法 * * Element hooks */ export interface ElementHooks { /** * 在元素完成创建并执行完入场动画后调用 * * Called after the element is created and the entrance animation is completed * @override */ onCreate?: () => void; /** * 在元素更新并执行完过渡动画后调用 * * Called after the element is updated and the transition animation is completed * @override */ onUpdate?: () => void; /** * 在元素完成退场动画并销毁后调用 * * Called after the element completes the exit animation and is destroyed * @override */ onDestroy?: () => void; }