@fulate/core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation.d.ts +15 -0
- package/dist/event.d.ts +156 -0
- package/dist/geometry/authored.d.ts +62 -0
- package/dist/geometry/common.d.ts +133 -0
- package/dist/geometry/index.d.ts +10 -0
- package/dist/geometry/rectangle.d.ts +22 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +6824 -0
- package/dist/layer/dirty-grid.d.ts +17 -0
- package/dist/layer/index.d.ts +224 -0
- package/dist/mutation/change-batch.d.ts +29 -0
- package/dist/mutation/structure-change.d.ts +30 -0
- package/dist/node/element-transform.d.ts +252 -0
- package/dist/node/element.d.ts +294 -0
- package/dist/node/node.d.ts +156 -0
- package/dist/node/properties.d.ts +174 -0
- package/dist/node/reference-transform.d.ts +64 -0
- package/dist/node/shape.d.ts +146 -0
- package/dist/root/frame-runtime.d.ts +122 -0
- package/dist/root/hit-test.d.ts +34 -0
- package/dist/root/index.d.ts +196 -0
- package/dist/root/input-controller.d.ts +103 -0
- package/dist/root/scene-registry.d.ts +45 -0
- package/dist/root/viewport.d.ts +165 -0
- package/dist/skin.d.ts +117 -0
- package/dist/utils/connection-port.d.ts +79 -0
- package/package.json +30 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Node } from "../node/node";
|
|
2
|
+
/** 监听一个 key 对应节点的注册和注销。 */
|
|
3
|
+
export type NodeKeyObserver = (node: Node, registered: boolean) => void;
|
|
4
|
+
/** 监听当前 Root 中节点进入或离开 active 生命周期。 */
|
|
5
|
+
export type NodeRegistrationObserver = (node: Node, registered: boolean) => void;
|
|
6
|
+
/** 监听会影响场景查询或工具缓存的变化;省略 node 表示批量结构变化。 */
|
|
7
|
+
export type SceneChangeObserver = (node?: Node, affected?: readonly Node[]) => void;
|
|
8
|
+
/** 管理活动场景的节点 key 索引和轻量变化观察器。 */
|
|
9
|
+
export declare class SceneRegistry {
|
|
10
|
+
/** 活动节点的 key 索引。 */
|
|
11
|
+
readonly keyElements: Map<string, Node<import("..").NodeProperties, Node<any, any>>>;
|
|
12
|
+
/** 按 key 保存观察注册和注销的回调。 */
|
|
13
|
+
private readonly nodeKeyObservers;
|
|
14
|
+
/** 监听结构、geometry 和命中策略变化的回调。 */
|
|
15
|
+
private readonly sceneChangeObservers;
|
|
16
|
+
/** 监听 active registration 的轻量观察器。 */
|
|
17
|
+
private readonly nodeRegistrationObservers;
|
|
18
|
+
/** 创建注册表;可注入已有 Map 以共享或测试已经成立的 key 索引。 */
|
|
19
|
+
constructor(
|
|
20
|
+
/** 活动节点的 key 索引。 */
|
|
21
|
+
keyElements?: Map<string, Node<import("..").NodeProperties, Node<any, any>>>);
|
|
22
|
+
/** 订阅场景变化并返回注销函数。 */
|
|
23
|
+
observeSceneChanges(observer: SceneChangeObserver): () => boolean;
|
|
24
|
+
/** @internal 当前是否存在真实 scene change consumer。 */
|
|
25
|
+
get hasSceneChangeObservers(): boolean;
|
|
26
|
+
/** 订阅节点 active registration 并返回注销函数。 */
|
|
27
|
+
observeNodeRegistrations(observer: NodeRegistrationObserver): () => boolean;
|
|
28
|
+
/** @internal 通知场景观察器;node 省略时表示整批变化。 */
|
|
29
|
+
notifySceneChange(node?: Node, affected?: readonly Node[]): void;
|
|
30
|
+
/** 订阅指定 key 的注册状态变化并返回注销函数。 */
|
|
31
|
+
observeNodeKey(key: string, observer: NodeKeyObserver): () => void;
|
|
32
|
+
/** 按当前索引状态通知指定 key 的观察者。 */
|
|
33
|
+
private notifyNodeKeyObservers;
|
|
34
|
+
/** @internal 节点进入 active 状态后发送 key 注册通知。 */
|
|
35
|
+
notifyNodeRegistered(node: Node): void;
|
|
36
|
+
/** @internal 写入活动身份;producer 违约时只做 O(1) 诊断。 */
|
|
37
|
+
registerNodeKey(node: Node): void;
|
|
38
|
+
/** @internal 从索引移除停用节点并通知 key 观察器。 */
|
|
39
|
+
unregisterNodeKey(node: Node): void;
|
|
40
|
+
private notifyNodeRegistrationObservers;
|
|
41
|
+
/** 返回活动场景中指定 key 对应的节点。 */
|
|
42
|
+
getByKey(key: string): Node<import("..").NodeProperties, Node<any, any>>;
|
|
43
|
+
/** @internal 清空 key 索引和全部观察器。 */
|
|
44
|
+
clear(): void;
|
|
45
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { Root } from "./index";
|
|
2
|
+
import type { Rect, RectWithCenter } from "@fulate/share";
|
|
3
|
+
import { type PointView } from "@fulate/share";
|
|
4
|
+
import type { Layer } from "../layer";
|
|
5
|
+
/** 可序列化的 Viewport 平移和缩放快照。 */
|
|
6
|
+
export interface ViewportSnapshot {
|
|
7
|
+
/** Root 容器 CSS 像素中的水平平移。 */
|
|
8
|
+
readonly x: number;
|
|
9
|
+
/** Root 容器 CSS 像素中的垂直平移。 */
|
|
10
|
+
readonly y: number;
|
|
11
|
+
/** world 到容器 CSS 像素的缩放倍率。 */
|
|
12
|
+
readonly scale: number;
|
|
13
|
+
}
|
|
14
|
+
/** `focus()` 在四边预留的 client 像素。 */
|
|
15
|
+
export interface ViewportInsets {
|
|
16
|
+
/** 顶部预留的 client 像素。 */
|
|
17
|
+
top?: number;
|
|
18
|
+
/** 右侧预留的 client 像素。 */
|
|
19
|
+
right?: number;
|
|
20
|
+
/** 底部预留的 client 像素。 */
|
|
21
|
+
bottom?: number;
|
|
22
|
+
/** 左侧预留的 client 像素。 */
|
|
23
|
+
left?: number;
|
|
24
|
+
}
|
|
25
|
+
/** 管理 Root 的平移、缩放、DPR、坐标换算和 CSS 快速预览。 */
|
|
26
|
+
export declare class Viewport {
|
|
27
|
+
/** 当前 Viewport 所属的 Root。 */
|
|
28
|
+
private readonly activeRoot;
|
|
29
|
+
/** 当前 Root 的平移、缩放和 DPR。 */
|
|
30
|
+
private viewportState;
|
|
31
|
+
/** 复用的可见 world 矩形返回对象。 */
|
|
32
|
+
private readonly worldRectView;
|
|
33
|
+
/** Root 创建时固定的缩放下限。 */
|
|
34
|
+
private readonly minimumScale;
|
|
35
|
+
/** Root 创建时固定的缩放上限。 */
|
|
36
|
+
private readonly maximumScale;
|
|
37
|
+
/** 当前 focus 动画;新的平移或缩放会停止它。 */
|
|
38
|
+
private focusTween?;
|
|
39
|
+
/** 每个 Layer 最近一次真实绘制所使用的 Viewport 快照。 */
|
|
40
|
+
private renderedViewports;
|
|
41
|
+
/** CSS 预览的自动刷新定时器。 */
|
|
42
|
+
private cssTransformTimer;
|
|
43
|
+
/** 是否仍有未提交的 CSS 预览。 */
|
|
44
|
+
private cssPreviewActive;
|
|
45
|
+
/** 是否已安装宿主窗口的 DPR resize 监听。 */
|
|
46
|
+
private resizeListening;
|
|
47
|
+
/** 创建 Root 拥有的 Viewport,并设置允许的缩放范围。 */
|
|
48
|
+
constructor(
|
|
49
|
+
/** 当前 Viewport 所属的 Root。 */
|
|
50
|
+
activeRoot: Root, options?: {
|
|
51
|
+
/** 最小缩放倍率,默认 `0.1`。 */
|
|
52
|
+
minScale?: number;
|
|
53
|
+
/** 最大缩放倍率,默认 `10`。 */
|
|
54
|
+
maxScale?: number;
|
|
55
|
+
});
|
|
56
|
+
/** 从宿主窗口读取最新 DPR,并重设所有 Layer surface。 */
|
|
57
|
+
private readonly onDevicePixelRatioChange;
|
|
58
|
+
/** @internal Root 激活时开始监听宿主窗口的 DPR 变化。 */
|
|
59
|
+
activate(): void;
|
|
60
|
+
/** @internal Root 停用时移除宿主窗口监听。 */
|
|
61
|
+
deactivate(): void;
|
|
62
|
+
/** Root 容器 CSS 像素中的水平平移。 */
|
|
63
|
+
get x(): number;
|
|
64
|
+
/** Root 容器 CSS 像素中的垂直平移。 */
|
|
65
|
+
get y(): number;
|
|
66
|
+
/** 当前 world 到容器 CSS 像素的缩放倍率。 */
|
|
67
|
+
get scale(): number;
|
|
68
|
+
/** 当前 Canvas backing store 使用的设备像素比。 */
|
|
69
|
+
get dpr(): number;
|
|
70
|
+
/** Root 创建时确定的最小缩放倍率。 */
|
|
71
|
+
get minScale(): number;
|
|
72
|
+
/** Root 创建时确定的最大缩放倍率。 */
|
|
73
|
+
get maxScale(): number;
|
|
74
|
+
/** 是否正在用 CSS transform 预览尚未真实绘制的 Viewport。 */
|
|
75
|
+
get isCssTransforming(): boolean;
|
|
76
|
+
/** @internal 返回复用的可见 world 矩形;调用方不能修改或保存。 */
|
|
77
|
+
getWorldRectView(): Readonly<Rect>;
|
|
78
|
+
/** 返回当前可见 world 矩形的独立副本。 */
|
|
79
|
+
getWorldRect(): Rect;
|
|
80
|
+
/**
|
|
81
|
+
* 将浏览器 client 坐标转换为 Root world 坐标。
|
|
82
|
+
* @param clientX DOM 指针事件的 `clientX`。
|
|
83
|
+
* @param clientY DOM 指针事件的 `clientY`。
|
|
84
|
+
*/
|
|
85
|
+
getLogicalPosition(clientX: number, clientY: number): PointView;
|
|
86
|
+
/**
|
|
87
|
+
* 将 DPR、Viewport 和可选 own world matrix 写入 Canvas Context。
|
|
88
|
+
* @param ctx 要更新 transform 的 Layer 2D Context。
|
|
89
|
+
* @param ownMatrix 元素已提交的 own world matrix;绘制 Layer 本身时省略。
|
|
90
|
+
*/
|
|
91
|
+
applyTransform(ctx: CanvasRenderingContext2D, ownMatrix?: DOMMatrixReadOnly): void;
|
|
92
|
+
/** 将倍率限制在 Root 创建时的 min/max 范围内。 */
|
|
93
|
+
private clampScale;
|
|
94
|
+
/** 提交 Viewport 状态,并决定走 CSS 预览还是完整 Canvas 重绘。 */
|
|
95
|
+
private commit;
|
|
96
|
+
/** 根据实际变化派发 zoom、translation 和 viewportchange。 */
|
|
97
|
+
private emitChange;
|
|
98
|
+
/** @internal 更新 DPR、重设 Layer surface 并完整重绘,不派发 Viewport 事件。 */
|
|
99
|
+
setDevicePixelRatio(dpr: number): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* 按容器 CSS 像素增量平移,可选择使用 CSS 快速预览。
|
|
102
|
+
* @param dx 水平 CSS 像素增量。
|
|
103
|
+
* @param dy 垂直 CSS 像素增量。
|
|
104
|
+
* @param useCssTransform 是否先用 CSS transform 预览,默认 `false`。
|
|
105
|
+
*/
|
|
106
|
+
translateBy(dx: number, dy: number, useCssTransform?: boolean): void;
|
|
107
|
+
/**
|
|
108
|
+
* 以容器 CSS 像素点为中心按倍率缩放,并返回约束后的实际 scale。
|
|
109
|
+
* @param delta 相对当前 scale 的倍率;`1.2` 表示放大 20%,不是目标 scale。
|
|
110
|
+
* @param center Root 容器内的 CSS 像素坐标;省略时使用容器中心。
|
|
111
|
+
* @param useCssTransform 是否先用 CSS transform 预览,默认 `false`。
|
|
112
|
+
*/
|
|
113
|
+
zoom(delta: number, center?: PointView, useCssTransform?: boolean): number;
|
|
114
|
+
/** 将平移恢复为 0、缩放恢复为受 min/max 约束的 1。 */
|
|
115
|
+
reset(): void;
|
|
116
|
+
/** 恢复 `captureSnapshot()` 返回的状态,scale 会经过 min/max 约束。 */
|
|
117
|
+
restore(snapshot: ViewportSnapshot): void;
|
|
118
|
+
/**
|
|
119
|
+
* 将 world 矩形适配到可见区域,可选动画、padding 和 client 像素 insets。
|
|
120
|
+
* 目标倍率不会因小矩形主动放大到 1 以上,之后仍受 min/max 约束。
|
|
121
|
+
* @param rect 要显示的 world 坐标矩形。
|
|
122
|
+
* @param options 适配留白、动画和四边预留。
|
|
123
|
+
*/
|
|
124
|
+
focus(rect: RectWithCenter, options?: {
|
|
125
|
+
/** 矩形四周的容器 CSS 像素留白,默认 `10`。 */
|
|
126
|
+
padding?: number;
|
|
127
|
+
/** 启用 Tween;duration 单位为毫秒。 */
|
|
128
|
+
animate?: {
|
|
129
|
+
duration?: number;
|
|
130
|
+
easing?: (amount: number) => number;
|
|
131
|
+
};
|
|
132
|
+
/** 从可见区域四边扣除的容器 CSS 像素。 */
|
|
133
|
+
insets?: number | ViewportInsets;
|
|
134
|
+
}): Promise<void>;
|
|
135
|
+
/** 返回当前 x、y 和 scale 的独立快照。 */
|
|
136
|
+
captureSnapshot(): ViewportSnapshot;
|
|
137
|
+
/** @internal 记录 Layer 最近真实绘制的 Viewport,供 CSS 预览计算相对变换。 */
|
|
138
|
+
commitLayerPaint(layer: Layer, snapshot?: ViewportSnapshot): void;
|
|
139
|
+
/** @internal Layer 停用时删除它最近的真实绘制快照。 */
|
|
140
|
+
forgetLayer(layer: Layer): void;
|
|
141
|
+
/** 为已有真实绘制的 Layer 应用短暂 CSS 预览。 */
|
|
142
|
+
private applyCssTransform;
|
|
143
|
+
/** 结束 CSS 快速预览并请求真实 Canvas 重绘。 */
|
|
144
|
+
flushCssTransform(): void;
|
|
145
|
+
/** 清除所有 Layer 的 CSS 预览和自动刷新定时器。 */
|
|
146
|
+
private clearCssTransform;
|
|
147
|
+
private cancelCssTransformTimer;
|
|
148
|
+
/** 停止当前 focus Tween,但不改变已有 Viewport 状态。 */
|
|
149
|
+
private stopFocusAnimation;
|
|
150
|
+
/** @internal 清理 CSS 预览计时器和 focus Tween。 */
|
|
151
|
+
dispose(): void;
|
|
152
|
+
/** 导出 Viewport 平移、缩放和缩放范围。 */
|
|
153
|
+
toJSON(): {
|
|
154
|
+
/** 水平平移,单位为容器 CSS 像素。 */
|
|
155
|
+
x: number;
|
|
156
|
+
/** 垂直平移,单位为容器 CSS 像素。 */
|
|
157
|
+
y: number;
|
|
158
|
+
/** world 到容器 CSS 像素的缩放倍率。 */
|
|
159
|
+
scale: number;
|
|
160
|
+
/** 允许的最小缩放倍率。 */
|
|
161
|
+
minScale: number;
|
|
162
|
+
/** 允许的最大缩放倍率。 */
|
|
163
|
+
maxScale: number;
|
|
164
|
+
};
|
|
165
|
+
}
|
package/dist/skin.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { BackgroundColor } from "@fulate/share";
|
|
2
|
+
import type { ShadowOption } from "./node/shape";
|
|
3
|
+
import type { Root } from "./root";
|
|
4
|
+
/** Core 文本组件共享的皮肤配置。 */
|
|
5
|
+
export interface TextStyleConfig {
|
|
6
|
+
/** 文本填充颜色或渐变,默认 `"#000000"`。 */
|
|
7
|
+
color?: BackgroundColor;
|
|
8
|
+
/** 字号,单位为逻辑像素,默认 `14`。 */
|
|
9
|
+
fontSize?: number;
|
|
10
|
+
/** CSS 字体族,默认 `"Arial"`。 */
|
|
11
|
+
fontFamily?: string;
|
|
12
|
+
/** CSS 字重,默认 `"normal"`。 */
|
|
13
|
+
fontWeight?: string | number;
|
|
14
|
+
/** CSS 字体样式,默认 `"normal"`。 */
|
|
15
|
+
fontStyle?: string;
|
|
16
|
+
/** 文本行的水平对齐方式,默认 `"center"`。 */
|
|
17
|
+
textAlign?: "left" | "center" | "right";
|
|
18
|
+
/** Canvas 文本基线,默认 `"top"`。 */
|
|
19
|
+
textBaseline?: CanvasTextBaseline;
|
|
20
|
+
/** 文本块在元素内的垂直对齐方式,默认 `"middle"`。 */
|
|
21
|
+
verticalAlign?: "top" | "middle" | "bottom";
|
|
22
|
+
/** 是否绘制下划线,默认 `false`。 */
|
|
23
|
+
underline?: boolean;
|
|
24
|
+
/** 是否绘制删除线,默认 `false`。 */
|
|
25
|
+
strikethrough?: boolean;
|
|
26
|
+
/** 字号的行高倍数,默认 `1.5`。 */
|
|
27
|
+
lineHeight?: number;
|
|
28
|
+
/** 是否按可用宽度换行,默认 `false`。 */
|
|
29
|
+
wordWrap?: boolean;
|
|
30
|
+
/** 最大显示行数;`0` 表示不限制,默认 `0`。 */
|
|
31
|
+
maxLines?: number;
|
|
32
|
+
/** 字符间距,单位为逻辑像素,默认 `0`。 */
|
|
33
|
+
letterSpacing?: number;
|
|
34
|
+
/** 文字描边颜色或渐变,空字符串表示不描边。 */
|
|
35
|
+
textStrokeColor?: BackgroundColor;
|
|
36
|
+
/** 文字描边宽度,单位为逻辑像素,默认 `0`。 */
|
|
37
|
+
textStrokeWidth?: number;
|
|
38
|
+
/** 文字阴影;`null` 表示无阴影,默认 `null`。 */
|
|
39
|
+
textShadow?: ShadowOption | null;
|
|
40
|
+
}
|
|
41
|
+
/** Skin 构造参数;省略字段使用 Fulate 当前默认外观。 */
|
|
42
|
+
export interface SkinOptions {
|
|
43
|
+
/** Shape 未显式配置时使用的填充,默认 `null`。 */
|
|
44
|
+
shapeFill?: BackgroundColor | null;
|
|
45
|
+
/** Shape 未显式配置时使用的描边,默认 `null`。 */
|
|
46
|
+
shapeStroke?: BackgroundColor | null;
|
|
47
|
+
/** Line 和 LineTree 未显式配置时使用的线色,默认 `"#333333"`。 */
|
|
48
|
+
lineStroke?: string;
|
|
49
|
+
/** 选择、hover、控制点和编辑器确认态共用的颜色,默认 `"#4F81FF"`。 */
|
|
50
|
+
selection?: string;
|
|
51
|
+
/** Text 未显式配置时使用的完整文字样式。 */
|
|
52
|
+
text?: TextStyleConfig;
|
|
53
|
+
}
|
|
54
|
+
/** 当前版本唯一的内置皮肤默认值。 */
|
|
55
|
+
export declare const SKIN_DEFAULTS: {
|
|
56
|
+
readonly shapeFill: any;
|
|
57
|
+
readonly shapeStroke: any;
|
|
58
|
+
readonly lineStroke: "#333333";
|
|
59
|
+
readonly selection: "#4F81FF";
|
|
60
|
+
readonly text: {
|
|
61
|
+
readonly color: "#000000";
|
|
62
|
+
readonly fontSize: 14;
|
|
63
|
+
readonly fontFamily: "Arial";
|
|
64
|
+
readonly fontWeight: "normal";
|
|
65
|
+
readonly fontStyle: "normal";
|
|
66
|
+
readonly textAlign: "center";
|
|
67
|
+
readonly textBaseline: "top";
|
|
68
|
+
readonly verticalAlign: "middle";
|
|
69
|
+
readonly underline: false;
|
|
70
|
+
readonly strikethrough: false;
|
|
71
|
+
readonly lineHeight: 1.5;
|
|
72
|
+
readonly wordWrap: false;
|
|
73
|
+
readonly maxLines: 0;
|
|
74
|
+
readonly letterSpacing: 0;
|
|
75
|
+
readonly textStrokeColor: "";
|
|
76
|
+
readonly textStrokeWidth: 0;
|
|
77
|
+
readonly textShadow: any;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
/** Skin 变化影响的消费范围。 */
|
|
81
|
+
export type SkinChange = "paint" | "text";
|
|
82
|
+
/** Root 共享且可继承的皮肤;直接修改属性会通知所有当前 consumer。 */
|
|
83
|
+
export declare class Skin {
|
|
84
|
+
private shapeFillValue;
|
|
85
|
+
private shapeStrokeValue;
|
|
86
|
+
private lineStrokeValue;
|
|
87
|
+
private selectionValue;
|
|
88
|
+
/** @internal 当前直接采用此 Skin 的 Root。 */
|
|
89
|
+
root: Root | null;
|
|
90
|
+
/** 可直接修改并自动更新文字布局和绘制的 Text 默认样式。 */
|
|
91
|
+
readonly text: Required<TextStyleConfig>;
|
|
92
|
+
/** 创建一份独立 Skin;各结构化字段值按原引用采用。 */
|
|
93
|
+
constructor(options?: SkinOptions);
|
|
94
|
+
/** Shape 未显式配置时使用的填充。 */
|
|
95
|
+
get shapeFill(): BackgroundColor;
|
|
96
|
+
/** 安装 Shape 默认填充并触发当前 consumer 重绘。 */
|
|
97
|
+
set shapeFill(value: BackgroundColor);
|
|
98
|
+
/** Shape 未显式配置时使用的描边。 */
|
|
99
|
+
get shapeStroke(): BackgroundColor;
|
|
100
|
+
/** 安装 Shape 默认描边并触发当前 consumer 重绘。 */
|
|
101
|
+
set shapeStroke(value: BackgroundColor);
|
|
102
|
+
/** Line 和 LineTree 未显式配置时使用的线色。 */
|
|
103
|
+
get lineStroke(): string;
|
|
104
|
+
/** 安装 Line 默认线色并触发当前 consumer 重绘。 */
|
|
105
|
+
set lineStroke(value: string);
|
|
106
|
+
/** 选择、hover、控制点和编辑器确认态共用的颜色。 */
|
|
107
|
+
get selection(): string;
|
|
108
|
+
/** 安装选择颜色并触发当前 consumer 重绘。 */
|
|
109
|
+
set selection(value: string);
|
|
110
|
+
/** 子类 setter 在安装自己的新值后调用,默认只影响绘制。 */
|
|
111
|
+
protected changed(change?: SkinChange): void;
|
|
112
|
+
/**
|
|
113
|
+
* 返回可独立持久化的当前内置 Skin 字段。
|
|
114
|
+
* 子类新增的持久化字段由子类覆写并追加。
|
|
115
|
+
*/
|
|
116
|
+
toJSON(): Required<SkinOptions>;
|
|
117
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Edge, PointView } from "@fulate/share";
|
|
2
|
+
import type { Element } from "../node/element";
|
|
3
|
+
/** Element owner 内稳定、由调用者直接提供的普通字符串 Port ID。 */
|
|
4
|
+
export type ConnectionPortId = string;
|
|
5
|
+
/** Port 在连接关系中的可用方向。 */
|
|
6
|
+
export type ConnectionPortDirection = "input" | "output" | "both";
|
|
7
|
+
/** 一个方向允许单连接或多连接。 */
|
|
8
|
+
export type ConnectionPortLimit = "single" | "multiple";
|
|
9
|
+
/** Port 入、出方向各自的连接数量限制。 */
|
|
10
|
+
export interface ConnectionPortLimits {
|
|
11
|
+
readonly input?: ConnectionPortLimit;
|
|
12
|
+
readonly output?: ConnectionPortLimit;
|
|
13
|
+
}
|
|
14
|
+
/** Port 标签的可选文字样式。 */
|
|
15
|
+
export interface ConnectionPortLabelStyle {
|
|
16
|
+
readonly fontSize?: number;
|
|
17
|
+
readonly color?: string;
|
|
18
|
+
readonly fontFamily?: string;
|
|
19
|
+
readonly fontWeight?: string | number;
|
|
20
|
+
}
|
|
21
|
+
/** 当前产品支持的边位置。 */
|
|
22
|
+
export interface EdgeConnectionPortPosition {
|
|
23
|
+
readonly edge: Edge;
|
|
24
|
+
readonly ratio: number;
|
|
25
|
+
}
|
|
26
|
+
/** 由业务数据声明的 owner-local custom Port。 */
|
|
27
|
+
export interface ConnectionPortDefinition {
|
|
28
|
+
readonly id: ConnectionPortId;
|
|
29
|
+
readonly position: EdgeConnectionPortPosition;
|
|
30
|
+
readonly name?: string;
|
|
31
|
+
readonly label: string;
|
|
32
|
+
readonly labelWidth?: number;
|
|
33
|
+
readonly labelStyle?: ConnectionPortLabelStyle;
|
|
34
|
+
readonly multiLine?: boolean;
|
|
35
|
+
readonly direction?: ConnectionPortDirection;
|
|
36
|
+
readonly connectionLimit?: ConnectionPortLimits;
|
|
37
|
+
readonly keepLabelUpright?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** Element authored Port 配置;默认 Port 必须显式启用。 */
|
|
40
|
+
export type ConnectionPortConfiguration = false | true | readonly ConnectionPortDefinition[];
|
|
41
|
+
/** 跨元素引用一个稳定 Port。 */
|
|
42
|
+
export interface ConnectionPortRef {
|
|
43
|
+
readonly elementKey: string;
|
|
44
|
+
readonly portId: ConnectionPortId;
|
|
45
|
+
}
|
|
46
|
+
/** Element 类型自有的 derived Port 定位器。 @internal */
|
|
47
|
+
export interface DerivedConnectionPort {
|
|
48
|
+
readonly id: ConnectionPortId;
|
|
49
|
+
/** 按当前 Element 的本地几何返回 Port 位置。 */
|
|
50
|
+
localPosition(element: Element): PointView;
|
|
51
|
+
}
|
|
52
|
+
/** owner 当前一次直接解析出的 Port。 */
|
|
53
|
+
export interface ResolvedConnectionPort {
|
|
54
|
+
readonly ref: ConnectionPortRef;
|
|
55
|
+
readonly kind: "endpoint-binding";
|
|
56
|
+
readonly localPosition: PointView;
|
|
57
|
+
readonly origin: "builtin" | "custom";
|
|
58
|
+
readonly definition?: ConnectionPortDefinition;
|
|
59
|
+
}
|
|
60
|
+
/** custom Port decoration 需要的边布局信息。 @internal */
|
|
61
|
+
export interface ResolvedConnectionPortSlot extends ResolvedConnectionPort {
|
|
62
|
+
readonly origin: "custom";
|
|
63
|
+
readonly definition: ConnectionPortDefinition;
|
|
64
|
+
readonly edge: Edge;
|
|
65
|
+
readonly ratio: number;
|
|
66
|
+
readonly edgeCount: number;
|
|
67
|
+
}
|
|
68
|
+
/** top、right、bottom、left 四条逻辑边中点组成的默认 Port。 */
|
|
69
|
+
export declare const DEFAULT_CONNECTION_PORT_SCHEMA: readonly DerivedConnectionPort[];
|
|
70
|
+
/** 直接从 custom definitions 解析当前 local Port;不缓存、复制或改写输入。 */
|
|
71
|
+
export declare function resolveConnectionPortSlots(element: Element, definitions: readonly ConnectionPortDefinition[]): readonly ResolvedConnectionPortSlot[];
|
|
72
|
+
/** 将 local 点投影到当前已提交 world matrix。 */
|
|
73
|
+
export declare function projectConnectionPortPoint(matrix: DOMMatrixReadOnly, point: PointView): PointView;
|
|
74
|
+
/** 按 owner-local ID 读取一个已知 Port;不受发现开关影响。 */
|
|
75
|
+
export declare function getElementConnectionPort(element: Element, portId: ConnectionPortId): ResolvedConnectionPort | undefined;
|
|
76
|
+
/** 返回一个 Port 的当前 committed world 坐标。 */
|
|
77
|
+
export declare function getElementConnectionPortPoint(element: Element, portId: ConnectionPortId): PointView | undefined;
|
|
78
|
+
/** 返回 owner 全部 Port 的当前 committed world 投影。 */
|
|
79
|
+
export declare function getElementConnectionPortPoints(element: Element): Array<ResolvedConnectionPort & PointView>;
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fulate/core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "vitest run --config vitest.config.ts",
|
|
19
|
+
"test:watch": "vitest --config vitest.config.ts"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@fulate/share": "*",
|
|
23
|
+
"@tweenjs/tween.js": "^25.0.0",
|
|
24
|
+
"lodash-es": "^4.17.22",
|
|
25
|
+
"rbush": "^4.0.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/rbush": "^4.0.0"
|
|
29
|
+
}
|
|
30
|
+
}
|