import type { ArgumentMap, ArgumentValue, Variable } from '@cloudpss/expression/definitions'; import type { ModelImplement } from './index.js'; import type { Simplify, Tagged } from 'type-fest'; import type { ModelConfiguration } from '../configuration.js'; import type { ModelId } from '../index.js'; /** 图形元素属性 */ // eslint-disable-next-line @typescript-eslint/no-empty-object-type export interface DiagramCellAttrs {} /** * 表示接线图中元素信息 */ export interface DiagramCell { /** 元素 ID */ id: string; /** 所在图纸 */ canvas: CanvasKey; /** 元素类型 */ shape: string; /** z index */ zIndex?: number; /** 元素样式 */ attrs?: DiagramCellAttrs; } /** 图形元素属性 */ // eslint-disable-next-line @typescript-eslint/no-empty-object-type export interface DiagramNodeAttrs extends DiagramCellAttrs {} /** 图形位置属性 */ export type DiagramPoint = { x: number; y: number }; /** 图形大小属性 */ export type DiagramSize = { width: number; height: number }; /** * 表示接线图中的节点 */ export interface DiagramNode extends DiagramCell { /** 节点大小 */ size?: DiagramSize; /** 节点位置 */ position?: DiagramPoint; /** 节点旋转角度,顺时针,0-360 */ angle?: number; /** @inheritdoc */ attrs?: DiagramNodeAttrs; } /** 元件属性 */ interface DiagramDiagramComponentPropsData { /** 元件是否生效 */ enabled: boolean; /** 元件的大纲级别,根据缩放隐藏元件 */ outlineLevel: number; } /** 元件属性 */ export type DiagramDiagramComponentProps = ArgumentMap>; /** 元件上下文 */ // eslint-disable-next-line @typescript-eslint/no-empty-object-type export interface DiagramComponentContext extends Record {} /** 表示接线图中的元件信息 */ export interface DiagramComponentConfiguration extends ModelConfiguration { /** 元件定义 */ definition: ModelId; /** 基本属性 */ props: DiagramDiagramComponentProps; /** 元件上下文 */ context: DiagramComponentContext; /** 元件标签 */ label?: string; } /** * 表示接线图中的元件 */ export interface DiagramComponent extends DiagramNode, DiagramComponentConfiguration { /** @inheritdoc */ shape: 'diagram-component'; /** 元件样式 */ style?: Record; /** 水平翻转 */ flip?: boolean; } /** 表示接线图连线悬空的端点 */ // eslint-disable-next-line @typescript-eslint/no-empty-object-type export interface DiagramEdgeTerminalPoint extends DiagramPoint {} /** 表示接线图连线到其他元素的端点 */ export interface DiagramEdgeTerminalCell { /** 连接的元素 ID */ cell: string; /** 连接的元素端口名称 */ port?: string; } /** 表示接线图连线的端点 */ export type DiagramEdgeTerminal = DiagramEdgeTerminalPoint | DiagramEdgeTerminalCell; /** 图形元素属性 */ // eslint-disable-next-line @typescript-eslint/no-empty-object-type export interface DiagramEdgeAttrs extends DiagramCellAttrs {} /** 表示接线图中的连线 */ export interface DiagramEdge extends DiagramCell { /** @inheritdoc */ shape: `${string}edge`; /** 连线的始端 */ source?: DiagramEdgeTerminal; /** 连线的末端 */ target?: DiagramEdgeTerminal; /** @inheritdoc */ attrs?: DiagramEdgeAttrs; } /** * 表示接线图中的连线型元件 */ export interface DiagramComponentEdge extends DiagramEdge, DiagramComponentConfiguration { /** @inheritdoc */ shape: 'diagram-component-edge'; } /** 图纸key */ export type CanvasKey = Tagged; /** 图纸信息 */ export interface CanvasInfo { /** 图纸 key */ key: CanvasKey; /** 图纸名称 */ name: string; } /** 地理信息图 */ export interface GeoInfoMap { /** 图名 */ name: string; /** 图数据,指向地理信息图 SVG 的 URL,可以为 data-url */ url: string; } /** 检查是否为 GeoInfoMap */ export function isGeoInfoMap(data: unknown): data is GeoInfoMap { if (data == null || typeof data != 'object') return false; const d = data as GeoInfoMap; if ('key' in d) return false; return typeof d.name == 'string' && typeof d.url == 'string'; } /** * 接线图方式实现 */ export interface DiagramImplement extends ModelImplement { /** @inheritdoc */ type: 'diagram'; /** 图中元素 */ cells: Record; /** 图纸信息 */ canvas: CanvasInfo[]; /** 全局变量 */ variables: Variable[]; /** 地理信息图 */ geoInfoMaps: GeoInfoMap[]; }