fuxi-topology 0.2.8 → 0.3.8

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.
@@ -0,0 +1,12 @@
1
+ import { ActionDef } from './types';
2
+ declare const GLOBAL: ActionDef[];
3
+ declare const SCENE: ActionDef[];
4
+ declare const OBJECT: ActionDef[];
5
+ declare const OBJECT_GROUP: ActionDef[];
6
+ /** 所有动作定义 */
7
+ export declare const ACTION_DEFINITIONS: ActionDef[];
8
+ /** 按 type 索引的动作定义 Map */
9
+ export declare const ACTION_DEF_MAP: Map<string, ActionDef>;
10
+ /** 按维度分组 */
11
+ export declare const ACTION_DEFS_BY_DIMENSION: Record<ActionDef["dimension"], ActionDef[]>;
12
+ export { GLOBAL, SCENE, OBJECT, OBJECT_GROUP };
@@ -0,0 +1,17 @@
1
+ import { Topology } from '../topology';
2
+ import { ActionHandler } from './types';
3
+ /**
4
+ * 创建动作类型到处理器函数的映射表
5
+ *
6
+ * 每个 handler 通过闭包捕获 topology 实例,调用时只需传入 params。
7
+ *
8
+ * @param topology - Topology 实例
9
+ * @returns Map<string, ActionHandler>
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const handlerMap = createHandlerMap(topology);
14
+ * await handlerMap.get("fitView")!({ sceneId: "main" });
15
+ * ```
16
+ */
17
+ export declare function createHandlerMap(topology: Topology): Map<string, ActionHandler>;
@@ -0,0 +1,5 @@
1
+ export type { ActionDimension, ActionParamValueType, ActionParamDef, ActionDef, Action, ActionGroup, ActionHandler, ResolvedElement, ResolvedGroup, } from './types';
2
+ export { createHandlerMap } from './handlers';
3
+ export { ACTION_DEFINITIONS, ACTION_DEF_MAP, ACTION_DEFS_BY_DIMENSION } from './definitions';
4
+ export { resolveScene, resolveSceneSafe, resolveElement, resolveElementById, resolveGroup, getElementContainer, findElementById, ELEMENT_TYPES, } from './ref-resolver';
5
+ export { asString, asNumber, asBoolean, asNumberArray, asStringArray, asObject, asArray, } from './utils';
@@ -0,0 +1,47 @@
1
+ import { Topology } from '../topology';
2
+ import { Scene, SceneItemType } from '../scene/scene';
3
+ import { SceneItem } from '../scene/items';
4
+ import { ResolvedElement, ResolvedGroup } from './types';
5
+ /** 所有支持的元素类型 */
6
+ export declare const ELEMENT_TYPES: SceneItemType[];
7
+ /**
8
+ * 根据 sceneId 解析 Scene 实例
9
+ */
10
+ export declare function resolveScene(topology: Topology, sceneId: string): Scene;
11
+ /**
12
+ * 解析场景(安全版本,返回 undefined 而非抛出)
13
+ */
14
+ export declare function resolveSceneSafe(topology: Topology, sceneId: string): Scene | undefined;
15
+ /**
16
+ * 根据 sceneId + elementType + elementId 解析元素实例
17
+ */
18
+ export declare function resolveElement(topology: Topology, sceneId: string, elementType: SceneItemType, elementId: string): ResolvedElement;
19
+ /**
20
+ * 根据场景中的元素 ID 自动判断元素类型并返回
21
+ * 注意:此函数遍历所有容器,效率较低,仅应在无法确定类型时使用
22
+ */
23
+ export declare function resolveElementById(topology: Topology, sceneId: string, elementId: string): ResolvedElement | undefined;
24
+ /**
25
+ * 按元素 ID 在整个场景中查找元素(遍历所有容器)
26
+ * 与 resolveElementById 类似,但额外检查场景是否存在
27
+ */
28
+ export declare function findElementById(topology: Topology, sceneId: string, elementId: string): ResolvedElement | undefined;
29
+ /**
30
+ * 根据 sceneId + groupId 解析分组实例
31
+ */
32
+ export declare function resolveGroup(topology: Topology, sceneId: string, groupId: string): ResolvedGroup;
33
+ /**
34
+ * 获取元素容器(用于 CRUD 操作)
35
+ * 返回 Scene 上对应的容器实例(Nodes / Lines / ...)
36
+ */
37
+ export declare function getElementContainer(scene: Scene, elementType: SceneItemType): {
38
+ add(options: Record<string, any> & {
39
+ id: string;
40
+ }): SceneItem<any>;
41
+ remove(id: string): void;
42
+ get(id: string): SceneItem<any> | undefined;
43
+ update(id: string, updates: Record<string, any>): SceneItem<any> | undefined;
44
+ has(id: string): boolean;
45
+ getAll(): SceneItem<any>[];
46
+ count: number;
47
+ };
File without changes
@@ -0,0 +1,53 @@
1
+ import { Scene, SceneItemType } from '../scene/scene';
2
+ import { GroupElement } from '../scene/layer-manager';
3
+ import { SceneItem } from '../scene/items';
4
+ /** 动作四维划分 */
5
+ export type ActionDimension = "global" | "scene" | "object" | "objectGroup";
6
+ /** 参数值类型 */
7
+ export type ActionParamValueType = "string" | "number" | "boolean" | "number-array" | "string-array" | "select" | "color" | "element-type" | "scene-ref" | "element-ref" | "group-ref";
8
+ /** 参数定义 —— 描述一个参数的元信息 */
9
+ export interface ActionParamDef {
10
+ name: string;
11
+ label: string;
12
+ valueType: ActionParamValueType;
13
+ required?: boolean;
14
+ default?: unknown;
15
+ options?: {
16
+ label: string;
17
+ value: string;
18
+ }[];
19
+ placeholder?: string;
20
+ }
21
+ /** 动作定义 —— 描述一类动作的元信息 */
22
+ export interface ActionDef {
23
+ type: string;
24
+ label: string;
25
+ dimension: ActionDimension;
26
+ description: string;
27
+ params: ActionParamDef[];
28
+ }
29
+ /** 动作实例 —— 用户配置的具体动作 */
30
+ export interface Action {
31
+ id: string;
32
+ type: string;
33
+ params: Record<string, unknown>;
34
+ }
35
+ /** 动作容器 —— 一个命名的动作集合 */
36
+ export interface ActionGroup {
37
+ id: string;
38
+ name: string;
39
+ actions: Action[];
40
+ }
41
+ /** 动作处理器函数签名 */
42
+ export type ActionHandler = (params: Record<string, unknown>) => Promise<void>;
43
+ /** 解析后的元素引用 */
44
+ export interface ResolvedElement {
45
+ scene: Scene;
46
+ elementType: SceneItemType;
47
+ item: SceneItem<any>;
48
+ }
49
+ /** 解析后的分组引用 */
50
+ export interface ResolvedGroup {
51
+ scene: Scene;
52
+ group: GroupElement;
53
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 将 params 中的值安全转为 string
3
+ */
4
+ export declare function asString(v: unknown, fallback?: string): string;
5
+ /**
6
+ * 将 params 中的值安全转为 number
7
+ */
8
+ export declare function asNumber(v: unknown, fallback?: number): number | undefined;
9
+ /**
10
+ * 将 params 中的值安全转为 boolean
11
+ */
12
+ export declare function asBoolean(v: unknown, fallback?: boolean): boolean;
13
+ /**
14
+ * 将 params 中的值安全转为 number[]
15
+ */
16
+ export declare function asNumberArray(v: unknown): number[];
17
+ /**
18
+ * 将 params 中的值安全转为 string[]
19
+ */
20
+ export declare function asStringArray(v: unknown): string[];
21
+ /**
22
+ * 将 params 中的值安全转为 object(可能是 JSON 字符串)
23
+ */
24
+ export declare function asObject(v: unknown): Record<string, any>;
25
+ /**
26
+ * 将 params 中的值安全转为数组(可能是 JSON 字符串)
27
+ */
28
+ export declare function asArray(v: unknown): any[];