@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,294 @@
|
|
|
1
|
+
import type { Edge, PointView, Rect } from "@fulate/share";
|
|
2
|
+
import { type EventOptionKey, type FulateEvent } from "../event";
|
|
3
|
+
import { Node } from "./node";
|
|
4
|
+
import { ElementTransform, type ElementTransformClass } from "./element-transform";
|
|
5
|
+
import { ChangeImpact, TransformProperties, type PropertyChanges, type PreparedPropertyUpdate, type TransformableOptions } from "./properties";
|
|
6
|
+
import { Tween } from "@tweenjs/tween.js";
|
|
7
|
+
import type { ConnectionPortConfiguration, DerivedConnectionPort, ResolvedConnectionPort, ResolvedConnectionPortSlot } from "../utils/connection-port";
|
|
8
|
+
import type { Root } from "../root";
|
|
9
|
+
import type { Layer } from "../layer";
|
|
10
|
+
import type { OwnerPropertyChange } from "../mutation/change-batch";
|
|
11
|
+
type ElementEventOptions<T> = {
|
|
12
|
+
[K in EventOptionKey]?: (this: T, event: FulateEvent<T>) => any;
|
|
13
|
+
};
|
|
14
|
+
/** 任意 Properties 和 Options 的 Element。 */
|
|
15
|
+
export type AnyElement = Element<any, any, any>;
|
|
16
|
+
/** 所有 Element 共用的构造选项。 */
|
|
17
|
+
export interface BaseElementOption<T = Element> extends TransformableOptions, ElementEventOptions<T> {
|
|
18
|
+
/** hover 时写入 Root 容器的 CSS cursor。 */
|
|
19
|
+
cursor?: string;
|
|
20
|
+
/** 是否绘制并参与命中。 */
|
|
21
|
+
visible?: boolean;
|
|
22
|
+
/** 编辑器选择策略是否可选择该元素。 */
|
|
23
|
+
selectable?: boolean;
|
|
24
|
+
/** 是否让整个结构分支退出指针输入。 */
|
|
25
|
+
silent?: boolean;
|
|
26
|
+
/** 当前元素自身是否可成为指针命中目标。 */
|
|
27
|
+
pickable?: boolean;
|
|
28
|
+
/** children 是否可溢出自身边界;默认 `"visible"`。 */
|
|
29
|
+
overflow?: "visible" | "hidden";
|
|
30
|
+
/** Port whole-value;省略/`false` 无 Port,`true` 使用默认 schema,数组为 custom schema。 */
|
|
31
|
+
ports?: ConnectionPortConfiguration;
|
|
32
|
+
/** 初始 children。 */
|
|
33
|
+
children?: readonly AnyElement[];
|
|
34
|
+
}
|
|
35
|
+
/** `setOptions()` 接受的普通运行时补丁。 */
|
|
36
|
+
export type ElementOptionPatch<O extends BaseElementOption<any> = BaseElementOption> = Partial<Omit<O, "key" | "children">>;
|
|
37
|
+
type EventHandlerKey<O> = {
|
|
38
|
+
[K in keyof O]: K extends `on${string}` ? K : never;
|
|
39
|
+
}[keyof O];
|
|
40
|
+
/** Element 的可序列化属性和递归 children。 */
|
|
41
|
+
export type ElementJSON<O extends BaseElementOption<any> = BaseElementOption<any>> = Omit<O, "children" | "key" | "type" | EventHandlerKey<O>> & {
|
|
42
|
+
/** 构造时确定并由 serializer 显式写出的节点 key。 */
|
|
43
|
+
readonly key: string;
|
|
44
|
+
/** 序列化节点类型。 */
|
|
45
|
+
type: string;
|
|
46
|
+
/** 递归序列化的 children。 */
|
|
47
|
+
children?: ElementJSON[];
|
|
48
|
+
};
|
|
49
|
+
/** @internal Core publisher 在零写入阶段完成的 owner commit 数据。 */
|
|
50
|
+
export interface PreparedElementPropertyCommit {
|
|
51
|
+
readonly update: PreparedPropertyUpdate;
|
|
52
|
+
readonly impact: ChangeImpact;
|
|
53
|
+
readonly previousVisualBounds: Readonly<import("@fulate/share").BoundingBox> | null | undefined;
|
|
54
|
+
}
|
|
55
|
+
export { ChangeImpact } from "./properties";
|
|
56
|
+
/** `animate()` 的 Tween 选项。 */
|
|
57
|
+
export interface AnimateOptions<T = any> {
|
|
58
|
+
/** 持续时间,单位为毫秒,默认 `300`。 */
|
|
59
|
+
duration?: number;
|
|
60
|
+
/** 进度缓动函数。 */
|
|
61
|
+
easing?: (amount: number) => number;
|
|
62
|
+
/** 延迟时间,单位为毫秒,默认 `0`。 */
|
|
63
|
+
delay?: number;
|
|
64
|
+
/** 额外重复次数,默认 `0`。 */
|
|
65
|
+
repeat?: number;
|
|
66
|
+
/** 重复时是否反向播放,默认 `false`。 */
|
|
67
|
+
yoyo?: boolean;
|
|
68
|
+
/** 动画正常完成后的回调。 */
|
|
69
|
+
onComplete?: (v: T) => void;
|
|
70
|
+
/** 每次属性提交后的回调。 */
|
|
71
|
+
onUpdate?: (v: T) => void;
|
|
72
|
+
}
|
|
73
|
+
/** 从 Options 中选出可动画的数值与颜色属性。 */
|
|
74
|
+
export type AnimateTarget<O> = {
|
|
75
|
+
[K in keyof O as K extends "key" ? never : NonNullable<O[K]> extends number ? K : K extends string ? Lowercase<K> extends `${string}color${string}` ? K : never : never]?: NonNullable<O[K]> extends number ? Extract<O[K], number> : O[K];
|
|
76
|
+
};
|
|
77
|
+
/** Element 事件选项合并到属性快照后的类型。 */
|
|
78
|
+
export interface ElementProperties extends ElementEventOptions<Element> {
|
|
79
|
+
}
|
|
80
|
+
/** Element 的显示、输入、Port 和事件属性状态。 */
|
|
81
|
+
export declare class ElementProperties extends TransformProperties {
|
|
82
|
+
/** hover 时使用的 CSS cursor。 */
|
|
83
|
+
cursor?: string;
|
|
84
|
+
/** 是否绘制并参与命中。 */
|
|
85
|
+
visible: boolean;
|
|
86
|
+
/** 编辑器选择策略是否可选择该元素。 */
|
|
87
|
+
selectable?: boolean;
|
|
88
|
+
/** 是否让整个结构分支退出指针输入。 */
|
|
89
|
+
silent: boolean;
|
|
90
|
+
/** 当前元素自身是否可成为指针命中目标。 */
|
|
91
|
+
pickable: boolean;
|
|
92
|
+
/** children 是否可溢出自身边界。 */
|
|
93
|
+
overflow: "visible" | "hidden";
|
|
94
|
+
/** 当前采用的 Port whole-value;默认不启用 Port。 */
|
|
95
|
+
ports: ConnectionPortConfiguration;
|
|
96
|
+
/** 创建 Element 属性;结构化字段直接采用输入引用。 */
|
|
97
|
+
constructor(options?: BaseElementOption);
|
|
98
|
+
/** @internal 合并显示、输入和事件属性的提交影响。 */
|
|
99
|
+
getImpact(changes: PropertyChanges): ChangeImpact;
|
|
100
|
+
}
|
|
101
|
+
/** 可变换、可绘制、可命中并支持事件和动画的场景节点。 */
|
|
102
|
+
export declare class Element<P extends ElementProperties = ElementProperties, O extends BaseElementOption<any> = BaseElementOption<any>, Patch extends object = ElementOptionPatch<O>> extends Node<P, AnyElement> {
|
|
103
|
+
readonly type: string;
|
|
104
|
+
/** 当前 Element 唯一的变换与几何运行时。 */
|
|
105
|
+
readonly transform: ElementTransform<this>;
|
|
106
|
+
/** @internal Layer 内用于绘制顺序命中的已提交树序号。 */
|
|
107
|
+
committedPaintOrder: number;
|
|
108
|
+
/** hover 时使用的 CSS cursor。 */
|
|
109
|
+
get cursor(): string;
|
|
110
|
+
/** 是否绘制并参与命中。 */
|
|
111
|
+
get visible(): boolean;
|
|
112
|
+
/** 编辑器选择策略是否可选择该元素。 */
|
|
113
|
+
get selectable(): boolean;
|
|
114
|
+
/** 是否让整个结构分支退出指针输入。 */
|
|
115
|
+
get silent(): boolean;
|
|
116
|
+
/** 当前元素自身是否可成为指针命中目标。 */
|
|
117
|
+
get pickable(): boolean;
|
|
118
|
+
/** children 是否可溢出自身边界。 */
|
|
119
|
+
get overflow(): "visible" | "hidden";
|
|
120
|
+
/** 当前元素是否位于 Root 的 hover path 中。 */
|
|
121
|
+
get isHover(): boolean;
|
|
122
|
+
/** 相对 parent child 坐标空间的 x 位移。 */
|
|
123
|
+
get left(): number;
|
|
124
|
+
/** 相对 parent child 坐标空间的 y 位移。 */
|
|
125
|
+
get top(): number;
|
|
126
|
+
/** 顺时针旋转角度,单位为度。 */
|
|
127
|
+
get angle(): number;
|
|
128
|
+
/** x 轴缩放。 */
|
|
129
|
+
get scaleX(): number;
|
|
130
|
+
/** y 轴缩放。 */
|
|
131
|
+
get scaleY(): number;
|
|
132
|
+
/** x 轴错切角度,单位为度。 */
|
|
133
|
+
get skewX(): number;
|
|
134
|
+
/** y 轴错切角度,单位为度。 */
|
|
135
|
+
get skewY(): number;
|
|
136
|
+
/** x 方向变换原点。 */
|
|
137
|
+
get originX(): import("./properties").OriginX;
|
|
138
|
+
/** y 方向变换原点。 */
|
|
139
|
+
get originY(): import("./properties").OriginY;
|
|
140
|
+
/** Editor 旋转中心的 x 轴位置。 */
|
|
141
|
+
get rotationPivotX(): import("./properties").OriginX;
|
|
142
|
+
/** Editor 旋转中心的 y 轴位置。 */
|
|
143
|
+
get rotationPivotY(): import("./properties").OriginY;
|
|
144
|
+
/** 当前已解析宽度。 */
|
|
145
|
+
get width(): number;
|
|
146
|
+
/** 当前已解析高度。 */
|
|
147
|
+
get height(): number;
|
|
148
|
+
/** 未指定宽度时是否匹配 parent 宽度。 */
|
|
149
|
+
get fitWidth(): boolean;
|
|
150
|
+
/** 未指定高度时是否匹配 parent 高度。 */
|
|
151
|
+
get fitHeight(): boolean;
|
|
152
|
+
/** 当前采用的 Port whole-value;`true` 使用默认 schema。 */
|
|
153
|
+
get ports(): ConnectionPortConfiguration;
|
|
154
|
+
/** @internal 订阅实际 Ports authored commit;返回同一 observer 的注销函数。 */
|
|
155
|
+
observePortsCommit(observer: (element: Element) => void): () => void;
|
|
156
|
+
/**
|
|
157
|
+
* 采用 Port whole-value;数组由 Core 直接采用原引用。
|
|
158
|
+
* @param value `false`、`true` 或 custom definitions。
|
|
159
|
+
*/
|
|
160
|
+
replacePorts(value: ConnectionPortConfiguration): this;
|
|
161
|
+
/**
|
|
162
|
+
* 恢复完整属性快照,并为 Port 变化派发事件。
|
|
163
|
+
* @param snapshot 之前由 `properties.snapshot()` 返回的快照。
|
|
164
|
+
*/
|
|
165
|
+
restorePropertySnapshot(snapshot: Record<string, unknown>): this;
|
|
166
|
+
/** 首次创建动画时才安装的未结束任务集合。 */
|
|
167
|
+
private activeAnimations?;
|
|
168
|
+
/** 首次出现 `on*` handler 时才安装的监听 wrapper 映射。 */
|
|
169
|
+
private optionEventWrappers?;
|
|
170
|
+
/** 只在真实 dependent 存在时创建的内部 Ports commit observers。 */
|
|
171
|
+
private portsCommitObservers?;
|
|
172
|
+
private connectionPortProjectionReady;
|
|
173
|
+
private connectionPortProjectionSource;
|
|
174
|
+
private connectionPortProjectionRevision;
|
|
175
|
+
private connectionPortProjection;
|
|
176
|
+
private connectionPortSlots;
|
|
177
|
+
/** 创建带显示、输入、锚点和可选 children 的元素。 */
|
|
178
|
+
constructor(options?: NoInfer<O>, properties?: P, Transform?: ElementTransformClass);
|
|
179
|
+
/** raw parent link 变化只标记 transform local commit。 */
|
|
180
|
+
protected onParentChanged(): void;
|
|
181
|
+
/** raw children 完整安装后的 transform hook。 */
|
|
182
|
+
protected onChildrenChanged(): void;
|
|
183
|
+
/** raw children、lifecycle 和 hook 完成后的 transform dirty publication。 */
|
|
184
|
+
protected onStructureDirty(): void;
|
|
185
|
+
/** 激活时将未结束动画接入当前 Root。 */
|
|
186
|
+
protected onActivate(root: Root | null, layer: Layer | null): void;
|
|
187
|
+
/** 停用时从 Root 解除动画并结束未恢复的会话。 */
|
|
188
|
+
protected onDeactivate(root: Root | null, layer: Layer | null): void;
|
|
189
|
+
/** 卸载时停止当前元素的全部动画。 */
|
|
190
|
+
protected onUnmount(): void;
|
|
191
|
+
/** 让确有语义转换的派生元素在最终 patch 上处理一次。 */
|
|
192
|
+
protected resolveOptions(options: Patch): Patch;
|
|
193
|
+
/**
|
|
194
|
+
* 创建只借用 typed patch 的 owner effect;batch 合并完成前不解析或复制值。
|
|
195
|
+
*/
|
|
196
|
+
protected createPropertyChange(options: Patch): OwnerPropertyChange;
|
|
197
|
+
/** @internal 在 live write 前一次完成 changed-key diff、impact 和旧 bounds。 */
|
|
198
|
+
preparePropertyCommit(patch: Record<string, unknown>): PreparedElementPropertyCommit | null;
|
|
199
|
+
/** 把 source/effective changed-key delta finalize 为 direct/batch 共用记录。 */
|
|
200
|
+
private finalizePropertyUpdate;
|
|
201
|
+
/** @internal 无 callback 地安装 finalize 后的 source/effective fields。 */
|
|
202
|
+
installPropertyCommit(commit: PreparedElementPropertyCommit): void;
|
|
203
|
+
/** @internal 在全部 owner/tree 安装后同步 option event wrapper。 */
|
|
204
|
+
syncPropertyCommitEvents(commit: PreparedElementPropertyCommit): void;
|
|
205
|
+
/** @internal 在全部 owner/tree 安装及 lifecycle 后运行 owner hook。 */
|
|
206
|
+
runPropertyCommitHook(commit: PreparedElementPropertyCommit): void;
|
|
207
|
+
/** @internal 在 owner hook 后通知依赖实际 Ports commit 的框架消费者。 */
|
|
208
|
+
notifyPortsCommit(commit: PreparedElementPropertyCommit): void;
|
|
209
|
+
/** @internal 在内部 publication 完成后派发 authored `portschange`。 */
|
|
210
|
+
dispatchPortsChange(commit: PreparedElementPropertyCommit): void;
|
|
211
|
+
/** @internal 使用 finalize 已有 impact 登记 dirty,并按 direct 语义通知场景。 */
|
|
212
|
+
publishPropertyCommit(commit: PreparedElementPropertyCommit, notifyScene: boolean, publishRootImpact?: boolean): void;
|
|
213
|
+
/** 应用一份 direct configured/runtime update 并完成一次成功路径 publication。 */
|
|
214
|
+
private commitPreparedProperty;
|
|
215
|
+
private commitConfiguredOptions;
|
|
216
|
+
private prepareRuntimeCommit;
|
|
217
|
+
/** 将 `on*` 属性变化同步到 EventEmitter listener。 */
|
|
218
|
+
private syncOptionEvents;
|
|
219
|
+
/** 属性提交后的派生类扩展点。 */
|
|
220
|
+
protected onPropertiesChanged(_current: P, _changes: PropertyChanges): void;
|
|
221
|
+
/** 把非 geometry impact 路由到绘制、Layer 顺序和 hover 队列。 */
|
|
222
|
+
private invalidate;
|
|
223
|
+
/** 返回在当前元素 local 坐标系中对 children 生效的裁剪区域。 */
|
|
224
|
+
getChildClipRect(): Readonly<Rect> | null;
|
|
225
|
+
/** 判断 local 点是否通过当前元素绘制 children 时使用的裁剪。 */
|
|
226
|
+
containsChildClipPoint(point: PointView): boolean;
|
|
227
|
+
/** 将当前元素绘制到给定上下文。 */
|
|
228
|
+
paint(ctx?: CanvasRenderingContext2D): void;
|
|
229
|
+
/** 按当前 Layer 提交状态绘制可见 children。 */
|
|
230
|
+
protected paintChildren(ctx: CanvasRenderingContext2D): void;
|
|
231
|
+
/** 将 Canvas 切换到当前元素的 local 绘制坐标系。 */
|
|
232
|
+
protected applyPaintTransform(ctx: CanvasRenderingContext2D): void;
|
|
233
|
+
/** 使用当前元素的矩形边界裁剪 children。 */
|
|
234
|
+
protected applyChildClip(ctx: CanvasRenderingContext2D): void;
|
|
235
|
+
/** 绘制默认 hover 轮廓。 */
|
|
236
|
+
paintHover(ctx: CanvasRenderingContext2D, scale: number): void;
|
|
237
|
+
/** 从当前 live owner 直接解析一次可连接 Ports。 */
|
|
238
|
+
getConnectionPorts(): readonly ResolvedConnectionPort[];
|
|
239
|
+
private resolveCurrentConnectionPortProjection;
|
|
240
|
+
/** 直接解析一个当前 Port,不 materialize 其余 Ports。 */
|
|
241
|
+
getConnectionPort(portId: string): ResolvedConnectionPort | undefined;
|
|
242
|
+
/** @internal 按给定 whole-value 解析 Port replacement 的最终投影。 */
|
|
243
|
+
resolveConnectionPorts(ports: ConnectionPortConfiguration): readonly ResolvedConnectionPort[];
|
|
244
|
+
/** 返回元素类型自有的默认 Port;`null` 使用通用四边 Ports。 */
|
|
245
|
+
protected getDefaultConnectionPortSchema(): readonly DerivedConnectionPort[] | null;
|
|
246
|
+
/** 返回 custom Ports 的当前 decoration slots。 @internal */
|
|
247
|
+
getResolvedConnectionPortSlots(): readonly ResolvedConnectionPortSlot[];
|
|
248
|
+
/**
|
|
249
|
+
* 返回矩形指定边和比例对应的 local Port 点。
|
|
250
|
+
* @param edge 要查询的逻辑边。
|
|
251
|
+
* @param ratio 从边起点到终点的比例,通常在 `0..1`。
|
|
252
|
+
*/
|
|
253
|
+
getConnectionPortPosition(edge: Edge, ratio: number): PointView;
|
|
254
|
+
/** @internal 一次借用 owner 当前 configured source 的指定字段。 */
|
|
255
|
+
static readConfiguredPropertyValues(owner: Element, targets: ReadonlyMap<string, {
|
|
256
|
+
value: unknown;
|
|
257
|
+
}>): void;
|
|
258
|
+
/** @internal 借用 owner 当前 configured source 的单个字段。 */
|
|
259
|
+
protected static getConfiguredPropertyValue(owner: Element, key: string): any;
|
|
260
|
+
/**
|
|
261
|
+
* 提交需要持久化的配置属性补丁。
|
|
262
|
+
* @param options 要修改的属性;省略时不修改,字段为 `undefined` 时恢复默认值。
|
|
263
|
+
* 数组、对象等结构化字段按原引用采用;需要输入隔离时由调用者在传入前复制。
|
|
264
|
+
*/
|
|
265
|
+
setOptions(options?: Patch): this;
|
|
266
|
+
/**
|
|
267
|
+
* 合并只影响当前显示、不会进入持久化结果的属性覆盖。
|
|
268
|
+
* @param patch 字段省略时保持现有覆盖;字段为 `undefined` 时清除该字段覆盖。
|
|
269
|
+
* 结构化字段与 configured writer 一样按原引用采用。
|
|
270
|
+
*/
|
|
271
|
+
setRuntimeOptions(patch: Patch): this;
|
|
272
|
+
/** 显式清除指定或全部运行态属性覆盖。 */
|
|
273
|
+
clearRuntimeOptions<Key extends keyof Patch>(keys?: readonly Key[]): this;
|
|
274
|
+
/**
|
|
275
|
+
* 在当前 Root 动画组中补间数值和颜色属性。
|
|
276
|
+
* @param to 动画结束时的属性值。
|
|
277
|
+
* 结构化 target 会保留并在更新时采用同一引用,不生成调用方隔离快照。
|
|
278
|
+
* @param options 时长、缓动、重复和回调;省略时使用默认配置。
|
|
279
|
+
*/
|
|
280
|
+
animate(to: AnimateTarget<O>, options?: AnimateOptions<this>): Promise<void> & {
|
|
281
|
+
/** 当前动画使用的底层 Tween。 */
|
|
282
|
+
tween: Tween<any>;
|
|
283
|
+
};
|
|
284
|
+
/** 停止并清除当前元素的全部动画。 */
|
|
285
|
+
stopAnimations(): void;
|
|
286
|
+
/** 将当前元素的全部动画推进到结束状态。 */
|
|
287
|
+
finishAnimations(): void;
|
|
288
|
+
/** 暂停当前元素的全部动画。 */
|
|
289
|
+
pauseAnimations(): void;
|
|
290
|
+
/** 恢复当前元素的全部动画。 */
|
|
291
|
+
resumeAnimations(): void;
|
|
292
|
+
/** 返回不含事件处理器的递归可序列化快照。 */
|
|
293
|
+
toJSON(): ElementJSON<O>;
|
|
294
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { EventEmitter } from "../event";
|
|
2
|
+
import type { Root } from "../root/index";
|
|
3
|
+
import type { Layer } from "../layer/index";
|
|
4
|
+
import { NodeProperties } from "./properties";
|
|
5
|
+
/** 所有 Node 共用的创建期身份选项。 */
|
|
6
|
+
export interface NodeCreationOptions {
|
|
7
|
+
/** 场景内唯一 key;省略时由 Core 自动生成。 */
|
|
8
|
+
readonly key?: string;
|
|
9
|
+
}
|
|
10
|
+
/** Node 派发的非冒泡生命周期事件名。 */
|
|
11
|
+
export declare enum NodeLifecycleEvent {
|
|
12
|
+
/** 首次完成 mount 初始化。 */
|
|
13
|
+
Mounted = "mounted",
|
|
14
|
+
/** 进入活动 Root/Layer 上下文。 */
|
|
15
|
+
Activated = "activated",
|
|
16
|
+
/** 离开活动 Root/Layer 上下文。 */
|
|
17
|
+
Deactivated = "deactivated",
|
|
18
|
+
/** 完成不可逆卸载。 */
|
|
19
|
+
Unmounted = "unmounted"
|
|
20
|
+
}
|
|
21
|
+
/** 提供场景树所有权、生命周期、key 索引和上下文继承的基础节点。 */
|
|
22
|
+
export declare class Node<P extends NodeProperties = NodeProperties, Child extends Node<any, any> = Node<any, any>> extends EventEmitter {
|
|
23
|
+
#private;
|
|
24
|
+
/** 序列化使用的节点类型。 */
|
|
25
|
+
readonly type: string;
|
|
26
|
+
/** 返回构造期间确定的唯一场景 key。 */
|
|
27
|
+
get key(): string;
|
|
28
|
+
/** 当前由节点拥有的规范化属性状态。 */
|
|
29
|
+
protected readonly propertyState: P;
|
|
30
|
+
/** 当前属性的只读视图。 */
|
|
31
|
+
get properties(): Readonly<P>;
|
|
32
|
+
/** 结构 parent;只读使用,通过树操作修改。 */
|
|
33
|
+
parent: Node | undefined;
|
|
34
|
+
/** 当前节点直接拥有的 children 快照。 */
|
|
35
|
+
private childNodes;
|
|
36
|
+
/** 当前稳定生命周期状态。 */
|
|
37
|
+
private lifecycleState;
|
|
38
|
+
/** 当前正在执行的生命周期阶段。 */
|
|
39
|
+
private lifecycleCommand;
|
|
40
|
+
/** 按结构顺序排列的只读 children 快照。 */
|
|
41
|
+
get children(): readonly Child[];
|
|
42
|
+
/** 下一个 sibling;只读使用,通过树操作维护。 */
|
|
43
|
+
nextSibling: Node | null;
|
|
44
|
+
/** 上一个 sibling;只读使用,通过树操作维护。 */
|
|
45
|
+
previousSibling: Node | null;
|
|
46
|
+
/** 是否已完成首次 mount 且尚未卸载。 */
|
|
47
|
+
get isMounted(): boolean;
|
|
48
|
+
/** 是否处于活动 Root/Layer 上下文。 */
|
|
49
|
+
get isActive(): boolean;
|
|
50
|
+
/** 是否已进入或完成不可逆卸载。 */
|
|
51
|
+
get isUnmounted(): boolean;
|
|
52
|
+
/** 当前节点提供并沿 parent 原型链继承的上下文。 */
|
|
53
|
+
provides: Record<PropertyKey, any>;
|
|
54
|
+
/** 当前活动 Root;非 active 时为 `null`。 @internal */
|
|
55
|
+
activeRoot: Root | null;
|
|
56
|
+
/** 当前活动 Layer;普通读取通过 `layer` getter。 */
|
|
57
|
+
private activeLayer;
|
|
58
|
+
/** 当前节点所属 Layer。 */
|
|
59
|
+
get layer(): Layer;
|
|
60
|
+
/** 当前节点所属 Root。 */
|
|
61
|
+
get root(): Root;
|
|
62
|
+
/** @internal 判断当前节点是否为 Layer。 */
|
|
63
|
+
isLayerNode(): this is Layer;
|
|
64
|
+
/** 第一个 child,没有时为 `null`。 */
|
|
65
|
+
get firstChild(): Child | null;
|
|
66
|
+
/** 最后一个 child,没有时为 `null`。 */
|
|
67
|
+
get lastChild(): Child | null;
|
|
68
|
+
/** 创建持有指定 Properties 和可选 children 的结构节点。 */
|
|
69
|
+
constructor(options?: NodeCreationOptions, properties?: P, children?: readonly Child[]);
|
|
70
|
+
/** 安装最终 children 引用,并在一次循环内更新全部 raw links。 */
|
|
71
|
+
private installChildren;
|
|
72
|
+
/** 建立结构所有权、上下文原型链和事件冒泡 parent。 */
|
|
73
|
+
private linkChild;
|
|
74
|
+
/** 解除结构所有权、sibling、上下文和事件冒泡关系。 */
|
|
75
|
+
private unlinkFromParent;
|
|
76
|
+
/** raw parent link 改变后的派生 owner 接缝。 */
|
|
77
|
+
protected onParentChanged(): void;
|
|
78
|
+
/** 直接 children 事务提交后的扩展点;构造期 children 不触发。 */
|
|
79
|
+
protected onChildrenChanged(): void;
|
|
80
|
+
/** 全部 raw links 安装后的结构 dirty publication 扩展点。 */
|
|
81
|
+
protected onStructureDirty(): void;
|
|
82
|
+
/** 在 children 提交后通知扩展点、Root 和 dirty 路径。 */
|
|
83
|
+
private markStructureDirty;
|
|
84
|
+
/** 安装一次最终 children,并在当前提交仍有效时发布结构变化。 */
|
|
85
|
+
private commitChildren;
|
|
86
|
+
/** @internal trusted batch 解除真实变化节点的旧 placement。 */
|
|
87
|
+
detachBatchParent(): void;
|
|
88
|
+
/** @internal 接收 trusted batch 转移所有权的最终 children 快照。 */
|
|
89
|
+
installBatchChildren(children: readonly Node[]): void;
|
|
90
|
+
/** @internal 在全部 tree placement 安装后同步最终 lifecycle context。 */
|
|
91
|
+
syncBatchPlacementLifecycle(): void;
|
|
92
|
+
/** @internal tree 已完整安装后登记当前 owner 的 dirty path。 */
|
|
93
|
+
publishBatchStructureDirty(): void;
|
|
94
|
+
/** @internal raw links 与 placement lifecycle 同步完成后运行结构 hook。 */
|
|
95
|
+
runBatchStructureHook(): void;
|
|
96
|
+
/** 从当前 owner 移除一个直接 child,可选择同时停用它。 */
|
|
97
|
+
private removeOwnChild;
|
|
98
|
+
/** 从旧 owner 分离 incoming child,并确认同步回调没有再次接管它。 */
|
|
99
|
+
private detachFromParent;
|
|
100
|
+
/** 分离 incoming nodes;只有同步回调改写归属时才创建过滤后的数组。 */
|
|
101
|
+
private adoptIncoming;
|
|
102
|
+
/** 统一实现 append/prepend/before/after 的移动和插入事务。 */
|
|
103
|
+
private insertAt;
|
|
104
|
+
/** 将节点移动或追加到 children 尾部。 */
|
|
105
|
+
append(...children: Child[]): this;
|
|
106
|
+
/** 将节点移动或插入到 children 头部。 */
|
|
107
|
+
prepend(...children: Child[]): this;
|
|
108
|
+
/** 将节点插入指定 child 之前;`null` 表示追加。 */
|
|
109
|
+
insertBefore(newChild: Child, refChild: Child | null): this;
|
|
110
|
+
/** 将节点插入指定 child 之后。 */
|
|
111
|
+
insertAfter(newChild: Child, refChild: Child): this;
|
|
112
|
+
/** 用一个可复用节点替换指定 child。 */
|
|
113
|
+
replaceChild(newChild: Child, oldChild: Child): this;
|
|
114
|
+
/** 原子替换完整 children 序列。 */
|
|
115
|
+
replaceChildren(...children: Child[]): this;
|
|
116
|
+
/** 将节点移动到当前节点之前。 */
|
|
117
|
+
before(...nodes: Node[]): this;
|
|
118
|
+
/** 将节点移动到当前节点之后。 */
|
|
119
|
+
after(...nodes: Node[]): this;
|
|
120
|
+
/** 移除但不卸载指定 children,使其仍可复用。 */
|
|
121
|
+
removeChild(...children: Child[]): this;
|
|
122
|
+
/** 在稳定状态间同步转换;同一 Node 转换期间的再次请求立即报错。 */
|
|
123
|
+
private transitionLifecycle;
|
|
124
|
+
/** 执行首次初始化和 Mounted 事件。 */
|
|
125
|
+
private mountNode;
|
|
126
|
+
/** 只有无 parent 或 parent 已 active 时才允许进入 active。 */
|
|
127
|
+
private canBeActivatedByOwner;
|
|
128
|
+
/** 首次挂载并在 owner 允许时激活当前子树;已卸载节点不可恢复。 */
|
|
129
|
+
mount(): void;
|
|
130
|
+
/** 首次 mount 扩展点;不得再次转换当前 Node 的生命周期。 */
|
|
131
|
+
protected onMount(): void;
|
|
132
|
+
/** 建立 Root/Layer 上下文、注册 key,并递归激活 children。 */
|
|
133
|
+
private activateNode;
|
|
134
|
+
/** 进入活动上下文的扩展点;不得再次转换当前 Node 的生命周期。 */
|
|
135
|
+
protected onActivate(_activeRoot: Root | null, _layer: Layer | null): void;
|
|
136
|
+
/** 清理输入、key、Layer 空间项、children 和派生类 active 状态。 */
|
|
137
|
+
private leaveActiveContext;
|
|
138
|
+
/** 离开 active 上下文并派发 Deactivated。 */
|
|
139
|
+
private deactivateNode;
|
|
140
|
+
/** 离开活动上下文的扩展点;不得再次转换当前 Node 的生命周期。 */
|
|
141
|
+
protected onDeactivate(_activeRoot: Root | null, _layer: Layer | null): void;
|
|
142
|
+
/** children 卸载前调用;不得再次转换当前 Node 的生命周期。 */
|
|
143
|
+
protected onBeforeUnmount(): void;
|
|
144
|
+
/** 释放派生 owner 前调用;不得再次转换当前 Node 的生命周期。 */
|
|
145
|
+
protected onUnmount(): void;
|
|
146
|
+
/** 递归执行不可逆卸载,并释放结构、上下文和监听器。 */
|
|
147
|
+
private unmountNode;
|
|
148
|
+
/** 只在本节点存在监听器时创建同步生命周期事件。 */
|
|
149
|
+
private dispatchLifecycleEvent;
|
|
150
|
+
/** 不可逆卸载当前子树并清理监听器;重复调用不执行额外工作。 */
|
|
151
|
+
unmount(): void;
|
|
152
|
+
/** 在当前节点上下文中提供值。 */
|
|
153
|
+
provide(key: PropertyKey, value: any): this;
|
|
154
|
+
/** 从当前节点或最近 ancestor 上下文读取值。 */
|
|
155
|
+
inject<T = any>(key: PropertyKey): T | undefined;
|
|
156
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import type { NodeCreationOptions } from "./node";
|
|
2
|
+
declare const CONFIGURED_STATE: unique symbol;
|
|
3
|
+
declare const RUNTIME_OVERRIDE_STATE: unique symbol;
|
|
4
|
+
/** x 方向变换原点;数值 `0` 为中心,`-0.5/0.5` 为左右边。 */
|
|
5
|
+
export type OriginX = "center" | "left" | "right" | number;
|
|
6
|
+
/** y 方向变换原点;数值 `0` 为中心,`-0.5/0.5` 为上下边。 */
|
|
7
|
+
export type OriginY = "center" | "top" | "bottom" | number;
|
|
8
|
+
/** 将 origin 枚举或数值解析为以中心为零点的轴向比例。 */
|
|
9
|
+
export declare function resolveOrigin(origin: OriginX | OriginY): number;
|
|
10
|
+
/** 属性变化对下一次提交产生的按位影响。 */
|
|
11
|
+
export declare enum ChangeImpact {
|
|
12
|
+
/** 无运行时影响。 */
|
|
13
|
+
None = 0,
|
|
14
|
+
/** 仅需重绘。 */
|
|
15
|
+
Paint = 1,
|
|
16
|
+
/** canonical local geometry 或 layout reference bounds 变化。 */
|
|
17
|
+
LocalGeometry = 2,
|
|
18
|
+
/** world 矩阵变化。 */
|
|
19
|
+
WorldTransform = 4,
|
|
20
|
+
/** 绘制边界或轮廓变化。 */
|
|
21
|
+
VisualBounds = 8,
|
|
22
|
+
/** 需要重新执行指针命中。 */
|
|
23
|
+
Hover = 16,
|
|
24
|
+
/** 内容或 border 的命中几何变化。 */
|
|
25
|
+
HitBounds = 32,
|
|
26
|
+
/** Layer zIndex 或 Root Canvas 顺序变化。 */
|
|
27
|
+
LayerOrder = 64
|
|
28
|
+
}
|
|
29
|
+
export declare function clonePropertyValue<T>(value: T): T;
|
|
30
|
+
/** 属性名到修改前值的只读变化表。 */
|
|
31
|
+
export type PropertyChanges = ReadonlyMap<string, unknown>;
|
|
32
|
+
/** 属性名到本次提交最终值的只读变化表。 */
|
|
33
|
+
export type PropertyUpdates = ReadonlyMap<string, unknown>;
|
|
34
|
+
/** Node 持有的属性状态,以及显式生成独立结果的快照操作。 */
|
|
35
|
+
export declare class NodeProperties {
|
|
36
|
+
[CONFIGURED_STATE]: Record<string, unknown> | null;
|
|
37
|
+
[RUNTIME_OVERRIDE_STATE]: Record<string, unknown> | null;
|
|
38
|
+
/** 在新 Properties 实例上应用 patch,并返回旧值变化表。 */
|
|
39
|
+
with<T extends NodeProperties>(this: T, patch: Record<string, unknown>): {
|
|
40
|
+
/** 属性名到修改前值的变化表。 */
|
|
41
|
+
changes: Map<string, unknown>;
|
|
42
|
+
/** 应用 patch 后的新 Properties。 */
|
|
43
|
+
properties: T;
|
|
44
|
+
};
|
|
45
|
+
/** 返回可独立修改的完整属性快照。 */
|
|
46
|
+
snapshot(): Record<string, unknown>;
|
|
47
|
+
/** 判断快照与当前属性是否语义相同。 */
|
|
48
|
+
matches(snapshot: Record<string, unknown>): boolean;
|
|
49
|
+
/** 返回省略默认值和函数的可序列化属性。 */
|
|
50
|
+
toJSON(): Record<string, unknown>;
|
|
51
|
+
/** 将属性变化映射为提交影响,供派生 Properties 扩展。 */
|
|
52
|
+
getImpact(_changes: PropertyChanges, _updates?: PropertyUpdates): ChangeImpact;
|
|
53
|
+
/** 返回当前属性的独立完整值对象。 */
|
|
54
|
+
protected values(): {
|
|
55
|
+
[k: string]: any;
|
|
56
|
+
};
|
|
57
|
+
/** 读取把 runtime 字段还原为 configured 后的当前作者值。 */
|
|
58
|
+
private configuredValue;
|
|
59
|
+
/** 返回把 runtime 字段还原为 configured 后的独立完整值。 */
|
|
60
|
+
private configuredValues;
|
|
61
|
+
/** 使用当前运行时构造器创建同类型 Properties。 */
|
|
62
|
+
private create;
|
|
63
|
+
}
|
|
64
|
+
/** @internal 借用单个字段当前的 configured source 值。 */
|
|
65
|
+
export declare function getConfiguredPropertyValue(properties: NodeProperties, key: string): any;
|
|
66
|
+
/** @internal 一次借用同一 owner 多个字段的当前 configured source。 */
|
|
67
|
+
export declare function readConfiguredPropertyValues(properties: NodeProperties, targets: ReadonlyMap<string, {
|
|
68
|
+
value: unknown;
|
|
69
|
+
}>): void;
|
|
70
|
+
/** @internal 只为动画读取 requested keys 的 configured start 与 target 引用。 */
|
|
71
|
+
export declare function preparePropertyAnimationValues(properties: NodeProperties, patch: Record<string, unknown>, keys: readonly string[]): {
|
|
72
|
+
start: Record<string, unknown>;
|
|
73
|
+
target: Record<string, unknown>;
|
|
74
|
+
};
|
|
75
|
+
export type PropertySource = "configured" | "runtime";
|
|
76
|
+
/** @internal 一项 source/effective changed-key 的 install-ready 数据。 */
|
|
77
|
+
export interface PreparedPropertyField {
|
|
78
|
+
readonly key: string;
|
|
79
|
+
readonly sourceRecordBefore: boolean;
|
|
80
|
+
readonly sourceRecordAfter: boolean;
|
|
81
|
+
readonly beforeSource: unknown;
|
|
82
|
+
readonly afterSource: unknown;
|
|
83
|
+
readonly sourceChanged: boolean;
|
|
84
|
+
readonly beforeValue: unknown;
|
|
85
|
+
readonly afterValue: unknown;
|
|
86
|
+
readonly valueChanged: boolean;
|
|
87
|
+
readonly installValue: boolean;
|
|
88
|
+
}
|
|
89
|
+
/** @internal direct 与 trusted batch 共用的最小 owner property delta。 */
|
|
90
|
+
export interface PreparedPropertyUpdate {
|
|
91
|
+
readonly source: PropertySource;
|
|
92
|
+
readonly fields: readonly PreparedPropertyField[];
|
|
93
|
+
readonly changes: PropertyChanges;
|
|
94
|
+
readonly updates: PropertyUpdates;
|
|
95
|
+
}
|
|
96
|
+
/** @internal 解释 configured merge/reset,但不复制完整 source 或 Properties。 */
|
|
97
|
+
export declare function prepareConfiguredPropertyUpdate(properties: NodeProperties, patch: Record<string, unknown>): PreparedPropertyUpdate;
|
|
98
|
+
/** @internal 解释 runtime merge 与 own-undefined clear。 */
|
|
99
|
+
export declare function prepareRuntimePropertyUpdate(properties: NodeProperties, patch: Record<string, unknown>): PreparedPropertyUpdate;
|
|
100
|
+
/** @internal 把指定或全部 runtime keys 解释为同一 clear delta。 */
|
|
101
|
+
export declare function prepareRuntimePropertyClear(properties: NodeProperties, keys?: readonly PropertyKey[]): PreparedPropertyUpdate;
|
|
102
|
+
/** @internal 安装已经 finalize 的 changed source fields 与 effective values。 */
|
|
103
|
+
export declare function installPropertyUpdate(properties: NodeProperties, update: PreparedPropertyUpdate): void;
|
|
104
|
+
/** Element 的作者变换和尺寸选项。 */
|
|
105
|
+
export interface TransformableOptions extends NodeCreationOptions {
|
|
106
|
+
/** parent child 坐标中的 x 位移,默认 `0`。 */
|
|
107
|
+
left?: number;
|
|
108
|
+
/** parent child 坐标中的 y 位移,默认 `0`。 */
|
|
109
|
+
top?: number;
|
|
110
|
+
/** 顺时针旋转角度,单位为度,默认 `0`。 */
|
|
111
|
+
angle?: number;
|
|
112
|
+
/** 作者宽度;未设置时可由布局解析。 */
|
|
113
|
+
width?: number;
|
|
114
|
+
/** 作者高度;未设置时可由布局解析。 */
|
|
115
|
+
height?: number;
|
|
116
|
+
/** x 轴缩放,默认 `1`。 */
|
|
117
|
+
scaleX?: number;
|
|
118
|
+
/** y 轴缩放,默认 `1`。 */
|
|
119
|
+
scaleY?: number;
|
|
120
|
+
/** x 方向变换原点,默认 `center`。 */
|
|
121
|
+
originX?: OriginX;
|
|
122
|
+
/** y 方向变换原点,默认 `center`。 */
|
|
123
|
+
originY?: OriginY;
|
|
124
|
+
/** Editor 旋转中心的 x 轴位置,默认 `center`。 */
|
|
125
|
+
rotationPivotX?: OriginX;
|
|
126
|
+
/** Editor 旋转中心的 y 轴位置,默认 `center`。 */
|
|
127
|
+
rotationPivotY?: OriginY;
|
|
128
|
+
/** x 轴错切角度,单位为度,默认 `0`。 */
|
|
129
|
+
skewX?: number;
|
|
130
|
+
/** y 轴错切角度,单位为度,默认 `0`。 */
|
|
131
|
+
skewY?: number;
|
|
132
|
+
/** 未指定宽度时是否匹配 parent 宽度。 */
|
|
133
|
+
fitWidth?: boolean;
|
|
134
|
+
/** 未指定高度时是否匹配 parent 高度。 */
|
|
135
|
+
fitHeight?: boolean;
|
|
136
|
+
}
|
|
137
|
+
/** Element 的作者变换属性状态。 */
|
|
138
|
+
export declare class TransformProperties extends NodeProperties {
|
|
139
|
+
/** parent child 坐标中的 x 位移。 */
|
|
140
|
+
left: number;
|
|
141
|
+
/** parent child 坐标中的 y 位移。 */
|
|
142
|
+
top: number;
|
|
143
|
+
/** 顺时针旋转角度,单位为度。 */
|
|
144
|
+
angle: number;
|
|
145
|
+
/** 作者宽度;未设置时由布局解析。 */
|
|
146
|
+
width?: number;
|
|
147
|
+
/** 作者高度;未设置时由布局解析。 */
|
|
148
|
+
height?: number;
|
|
149
|
+
/** x 轴缩放。 */
|
|
150
|
+
scaleX: number;
|
|
151
|
+
/** y 轴缩放。 */
|
|
152
|
+
scaleY: number;
|
|
153
|
+
/** x 方向变换原点。 */
|
|
154
|
+
originX: OriginX;
|
|
155
|
+
/** y 方向变换原点。 */
|
|
156
|
+
originY: OriginY;
|
|
157
|
+
/** Editor 旋转中心的 x 轴位置。 */
|
|
158
|
+
rotationPivotX: OriginX;
|
|
159
|
+
/** Editor 旋转中心的 y 轴位置。 */
|
|
160
|
+
rotationPivotY: OriginY;
|
|
161
|
+
/** x 轴错切角度,单位为度。 */
|
|
162
|
+
skewX: number;
|
|
163
|
+
/** y 轴错切角度,单位为度。 */
|
|
164
|
+
skewY: number;
|
|
165
|
+
/** 未指定宽度时是否匹配 parent 宽度。 */
|
|
166
|
+
fitWidth: boolean;
|
|
167
|
+
/** 未指定高度时是否匹配 parent 高度。 */
|
|
168
|
+
fitHeight: boolean;
|
|
169
|
+
/** 创建带声明默认值的作者变换属性。 */
|
|
170
|
+
constructor(options?: TransformableOptions);
|
|
171
|
+
/** @internal 将尺寸和标量变换变化映射为几何影响。 */
|
|
172
|
+
getImpact(changes: PropertyChanges): ChangeImpact;
|
|
173
|
+
}
|
|
174
|
+
export {};
|