@soonspacejs/plugin-flow 2.13.7 → 2.13.9

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.
Files changed (60) hide show
  1. package/README.md +4 -4
  2. package/dist/flows/ComponentFlowParser.d.ts +8 -0
  3. package/dist/flows/FlowParser.d.ts +46 -0
  4. package/dist/flows/edges/index.d.ts +9 -0
  5. package/dist/flows/index.d.ts +4 -0
  6. package/dist/flows/nodes/ColorNode.d.ts +8 -0
  7. package/dist/flows/nodes/ConditionNode.d.ts +9 -0
  8. package/dist/flows/nodes/DataExtractionNode.d.ts +8 -0
  9. package/dist/flows/nodes/DataFilterNode.d.ts +8 -0
  10. package/dist/flows/nodes/DelayNode.d.ts +8 -0
  11. package/dist/flows/nodes/EmissiveNode.d.ts +10 -0
  12. package/dist/flows/nodes/FlyToNode.d.ts +8 -0
  13. package/dist/flows/nodes/HideNode.d.ts +10 -0
  14. package/dist/flows/nodes/HighlightNode.d.ts +10 -0
  15. package/dist/flows/nodes/MeshNode.d.ts +8 -0
  16. package/dist/flows/nodes/MeshesNode.d.ts +8 -0
  17. package/dist/flows/nodes/ModelNode.d.ts +8 -0
  18. package/dist/flows/nodes/ModelsNode.d.ts +8 -0
  19. package/dist/flows/nodes/Node.d.ts +48 -0
  20. package/dist/flows/nodes/NumberNode.d.ts +8 -0
  21. package/dist/flows/nodes/OpacityNode.d.ts +10 -0
  22. package/dist/flows/nodes/POINode.d.ts +8 -0
  23. package/dist/flows/nodes/POISNode.d.ts +8 -0
  24. package/dist/flows/nodes/PathNode.d.ts +8 -0
  25. package/dist/flows/nodes/PathsNode.d.ts +8 -0
  26. package/dist/flows/nodes/RotateNode.d.ts +8 -0
  27. package/dist/flows/nodes/ScaleNode.d.ts +8 -0
  28. package/dist/flows/nodes/ShowNode.d.ts +10 -0
  29. package/dist/flows/nodes/SpaceNode.d.ts +8 -0
  30. package/dist/flows/nodes/SpacesNode.d.ts +8 -0
  31. package/dist/flows/nodes/StartNode.d.ts +7 -0
  32. package/dist/flows/nodes/TranslateNode.d.ts +8 -0
  33. package/dist/flows/nodes/UnEmissiveNode.d.ts +10 -0
  34. package/dist/flows/nodes/UnHighlightNode.d.ts +10 -0
  35. package/dist/flows/nodes/UnOpacityNode.d.ts +10 -0
  36. package/dist/flows/nodes/clip-animation/ClipAnimationNode.d.ts +8 -0
  37. package/dist/flows/nodes/clip-animation/UnClipAnimationNode.d.ts +8 -0
  38. package/dist/flows/nodes/clip-animation/index.d.ts +2 -0
  39. package/dist/flows/nodes/component-tween-animation/ComponentTweenAnimationNode.d.ts +8 -0
  40. package/dist/flows/nodes/component-tween-animation/UnComponentTweenAnimationNode.d.ts +8 -0
  41. package/dist/flows/nodes/component-tween-animation/index.d.ts +2 -0
  42. package/dist/flows/nodes/component-tween-animation/utils.d.ts +5 -0
  43. package/dist/flows/nodes/index.d.ts +33 -0
  44. package/dist/flows/nodes/tween-animation/TweenAnimationNode.d.ts +8 -0
  45. package/dist/flows/nodes/tween-animation/UnTweenAnimationNode.d.ts +8 -0
  46. package/dist/flows/nodes/tween-animation/index.d.ts +2 -0
  47. package/dist/flows/nodes/tween-animation/utils.d.ts +5 -0
  48. package/dist/flows/types.d.ts +106 -0
  49. package/dist/flows/utils.d.ts +12 -0
  50. package/dist/index.d.ts +3 -0
  51. package/dist/index.esm.js +1 -1881
  52. package/dist/triggers/ComponentTrigger.d.ts +18 -0
  53. package/dist/triggers/Trigger.d.ts +27 -0
  54. package/dist/triggers/index.d.ts +3 -0
  55. package/dist/triggers/types.d.ts +54 -0
  56. package/dist/triggers/utils.d.ts +2 -0
  57. package/dist/types.d.ts +16 -0
  58. package/package.json +3 -3
  59. package/test/test.ts +118 -118
  60. package/dist/index.esm.js.map +0 -1
@@ -0,0 +1,18 @@
1
+ import SoonSpace, { ModelEventParams } from 'soonspacejs';
2
+ import { Trigger } from './Trigger';
3
+ import { Interaction, TriggerOptions } from './types';
4
+ import { ComponentFlowType } from '../flows/types';
5
+ declare class ComponentTrigger extends Trigger {
6
+ #private;
7
+ flows: ComponentFlowType[];
8
+ flowsMap: Map<string, ComponentFlowType[]>;
9
+ constructor(ssp: SoonSpace, interaction: Interaction, flows: ComponentFlowType[], options: TriggerOptions);
10
+ modelHandler(params: ModelEventParams): void;
11
+ runFlowByIds(flowIds: string[]): void;
12
+ execBehavior(): Promise<void>;
13
+ initLoaded(): void;
14
+ initThingPropChange(): void;
15
+ initThingEvent(): void;
16
+ onThingPropChange(newProps: string): void;
17
+ }
18
+ export { ComponentTrigger, };
@@ -0,0 +1,27 @@
1
+ import SoonSpace, { Model, ModelEventParams } from 'soonspacejs';
2
+ import { FlowType, Interaction, TriggerOptions } from '@soonspacejs/plugin-flow';
3
+ declare class Trigger {
4
+ #private;
5
+ ssp: SoonSpace;
6
+ interaction: Interaction;
7
+ flows: FlowType[];
8
+ flowsMap: Map<string, FlowType[]>;
9
+ options: TriggerOptions;
10
+ disposables: (() => void)[];
11
+ status: 'ready' | 'running' | 'error';
12
+ target?: Model;
13
+ constructor(ssp: SoonSpace, interaction: Interaction, flows: FlowType[], options: TriggerOptions);
14
+ modelHandler(params: ModelEventParams): void;
15
+ runFlowByIds(flowIds: string[]): void;
16
+ execBehavior(): Promise<void>;
17
+ initMouseClick(): void;
18
+ initMouseDbClick(): void;
19
+ initMouseRightClick(): void;
20
+ initLoaded(): void;
21
+ modelPropChangeHandler(properties: any): void;
22
+ initModelPropChange(): void;
23
+ initThingPropChange(): void;
24
+ initThingEvent(): void;
25
+ dispose(): void;
26
+ }
27
+ export { Trigger, };
@@ -0,0 +1,3 @@
1
+ export { Trigger, } from './Trigger';
2
+ export { ComponentTrigger, } from './ComponentTrigger';
3
+ export * from './types';
@@ -0,0 +1,54 @@
1
+ import { Object3D } from 'three';
2
+ import { IAnimation, IComponentAnimation } from '../types';
3
+ import { Node } from '../flows';
4
+ export declare enum InteractionActionType {
5
+ GLOBAL = "GLOBAL",
6
+ SELF = "SELF",
7
+ OTHER = "OTHER"
8
+ }
9
+ export declare enum InteractionAction {
10
+ FLOW = "FLOW",
11
+ ANIMATION = "ANIMATION",
12
+ DELAY = "DELAY"
13
+ }
14
+ export declare enum InteractionObsType {
15
+ GLOBAL = "GLOBAL",
16
+ INSTANCE = "INSTANCE",
17
+ FAMILY = "FAMILY"
18
+ }
19
+ export declare enum InteractionType {
20
+ MOUSE_CLICK = "MOUSE_CLICK",
21
+ MOUSE_DB_CLICK = "MOUSE_DB_CLICK",
22
+ MOUSE_RIGHT_CLICK = "MOUSE_RIGHT_CLICK",
23
+ THING_PROP_CHANGE = "THING_PROP_CHANGE",
24
+ THING_EVENT = "THING_EVENT",
25
+ LOADED = "LOADED",
26
+ MODEL_PROP_CHANGE = "MODEL_PROP_CHANGE"
27
+ }
28
+ export type InteractionBehavior = {
29
+ id: string;
30
+ uuid: string;
31
+ actionType: InteractionActionType;
32
+ action: InteractionAction;
33
+ actionTargets: string[] | null;
34
+ actionRefs: string[] | null;
35
+ };
36
+ export type Interaction = {
37
+ id: string;
38
+ sid: string;
39
+ name: string;
40
+ modelId: string;
41
+ type: InteractionType;
42
+ obsType: InteractionObsType;
43
+ obsTargets: string[] | null;
44
+ obsProps: string[] | null;
45
+ behaviors: InteractionBehavior[] | null;
46
+ active: boolean;
47
+ editionId?: string;
48
+ };
49
+ export type TriggerOptions = {
50
+ onError?: (e: Error) => void;
51
+ onTrigger?: (interaction: Interaction) => void;
52
+ getAnimations?: (currentNode: Node, object: Object3D, animationId: string) => Promise<IAnimation[] | null>;
53
+ getComponentAnimations?: (currentNode: Node, object: Object3D, animationId: string) => Promise<IComponentAnimation[] | null>;
54
+ };
@@ -0,0 +1,2 @@
1
+ import { Object3D } from 'three';
2
+ export declare const findObjectFromTarget: (target: Object3D, key: string) => boolean;
@@ -0,0 +1,16 @@
1
+ import { TAnimationFrame } from 'umanager-animation-parser';
2
+ export interface IComponentAnimation {
3
+ id: string;
4
+ sid: string;
5
+ name: string;
6
+ refId: string;
7
+ editionId: string;
8
+ keyframes: TAnimationFrame[];
9
+ }
10
+ export interface IAnimation {
11
+ id: string;
12
+ sid: string;
13
+ modelId: string;
14
+ name: string;
15
+ keyframes: TAnimationFrame[];
16
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soonspacejs/plugin-flow",
3
3
  "pluginName": "FlowPlugin",
4
- "version": "2.13.7",
4
+ "version": "2.13.9",
5
5
  "description": "FlowPlugin plugin for SoonSpace.js",
6
6
  "main": "dist/index.esm.js",
7
7
  "module": "dist/index.esm.js",
@@ -13,9 +13,9 @@
13
13
  ],
14
14
  "author": "xunwei",
15
15
  "license": "UNLICENSED",
16
- "gitHead": "550040550bf20ec0015982ff1159d0cfe9b35ed3",
16
+ "gitHead": "a5596909f48bd136905b85f239e13690f9f2c66e",
17
17
  "peerDependencies": {
18
- "soonspacejs": "2.13.7",
18
+ "soonspacejs": "2.13.9",
19
19
  "umanager-animation-parser": "^0.0.6"
20
20
  }
21
21
  }
package/test/test.ts CHANGED
@@ -1,119 +1,119 @@
1
- import componentThingJson from '../example/scene-test/db/component_thing.json'
2
-
3
- function generateMockData ( schema: any ): any {
4
-
5
- const result: Record<string, any> = {}
6
-
7
- // 遍历schema的properties属性
8
- for ( const prop of schema.thing.properties ) {
9
-
10
- const identifier = prop.identifier
11
- const defineType = prop.define.type
12
-
13
- switch ( defineType ) {
14
-
15
- case 'string':
16
- result[ identifier ] = `模拟${prop.name}`
17
- break
18
- case 'int':
19
- result[ identifier ] = Math.floor( Math.random() * 10000 )
20
- break
21
- case 'enum':
22
- const keys = Object.keys( prop.define.mapping )
23
-
24
- result[ identifier ] = keys[ Math.floor( Math.random() * keys.length ) ]
25
- break
26
- case 'struct':
27
- result[ identifier ] = generateMockData( { thing: { properties: prop.define.properties, }, } )
28
- break
29
- default:
30
- result[ identifier ] = null
31
-
32
- }
33
-
34
- }
35
-
36
- return result
37
-
38
- }
39
-
40
- interface SchemaMapping {
41
- sourceField: string;
42
- targetField: string;
43
- transform?: ( value: any ) => any;
44
- }
45
-
46
- function transformData (
47
- sourceData: any,
48
- mappings: SchemaMapping[],
49
- defaultValues: Record<string, any> = {}
50
- ): any {
51
-
52
- const result: Record<string, any> = { ...defaultValues, }
53
-
54
- for ( const mapping of mappings ) {
55
-
56
- const { sourceField, targetField, transform, } = mapping
57
-
58
- // 获取源数据的值
59
- const value = sourceField.split( '.' ).reduce( ( obj, key ) =>
60
- obj && obj[ key ] !== undefined ? obj[ key ] : undefined, sourceData )
61
-
62
- // 如果存在值并且有transform函数,则应用transform
63
- if ( value !== undefined ) {
64
-
65
- const transformedValue = transform ? transform( value ) : value
66
-
67
- // 将转换后的值设置到目标字段
68
- const fieldParts = targetField.split( '.' )
69
- let current = result
70
-
71
- for ( let i = 0; i < fieldParts.length - 1; i++ ) {
72
-
73
- const part = fieldParts[ i ]
74
-
75
- if ( !current[ part ] ) {
76
-
77
- current[ part ] = {}
78
-
79
- }
80
- current = current[ part ]
81
-
82
- }
83
-
84
- current[ fieldParts[ fieldParts.length - 1 ] ] = transformedValue
85
-
86
- }
87
-
88
- }
89
-
90
- return result
91
-
92
- }
93
-
94
-
95
- // 1. 生成模拟数据
96
- const schema = componentThingJson[ 0 ] // 你的JSON文件中的第一个元素
97
- const mockData = generateMockData( schema )
98
-
99
- console.log( '生成的模拟数据:', mockData )
100
-
101
- // 2. 定义映射(从一种模式到另一种模式)
102
- const mappings: SchemaMapping[] = [
103
- { sourceField: 'name', targetField: 'user.basicInfo.fullName', },
104
- { sourceField: 'id', targetField: 'user.basicInfo.idNumber', },
105
- { sourceField: 'gender', targetField: 'user.basicInfo.gender',
106
- transform: ( value ) => value === 'male' ? '男' : ( value === 'female' ? '女' : '未知' ), },
107
- { sourceField: 'phoneNumber', targetField: 'user.contact.mobile', },
108
- { sourceField: 'address', targetField: 'user.contact.address', },
109
- { sourceField: 'image.data', targetField: 'user.avatar',
110
- transform: ( value ) => ( { url: value, } ), }
111
- ]
112
-
113
- // 3. 转换数据
114
- const transformedData = transformData( mockData, mappings, {
115
- version: '1.0',
116
- createdAt: new Date().toISOString(),
117
- } )
118
-
1
+ import componentThingJson from '../example/scene-test/db/component_thing.json'
2
+
3
+ function generateMockData ( schema: any ): any {
4
+
5
+ const result: Record<string, any> = {}
6
+
7
+ // 遍历schema的properties属性
8
+ for ( const prop of schema.thing.properties ) {
9
+
10
+ const identifier = prop.identifier
11
+ const defineType = prop.define.type
12
+
13
+ switch ( defineType ) {
14
+
15
+ case 'string':
16
+ result[ identifier ] = `模拟${prop.name}`
17
+ break
18
+ case 'int':
19
+ result[ identifier ] = Math.floor( Math.random() * 10000 )
20
+ break
21
+ case 'enum':
22
+ const keys = Object.keys( prop.define.mapping )
23
+
24
+ result[ identifier ] = keys[ Math.floor( Math.random() * keys.length ) ]
25
+ break
26
+ case 'struct':
27
+ result[ identifier ] = generateMockData( { thing: { properties: prop.define.properties, }, } )
28
+ break
29
+ default:
30
+ result[ identifier ] = null
31
+
32
+ }
33
+
34
+ }
35
+
36
+ return result
37
+
38
+ }
39
+
40
+ interface SchemaMapping {
41
+ sourceField: string;
42
+ targetField: string;
43
+ transform?: ( value: any ) => any;
44
+ }
45
+
46
+ function transformData (
47
+ sourceData: any,
48
+ mappings: SchemaMapping[],
49
+ defaultValues: Record<string, any> = {}
50
+ ): any {
51
+
52
+ const result: Record<string, any> = { ...defaultValues, }
53
+
54
+ for ( const mapping of mappings ) {
55
+
56
+ const { sourceField, targetField, transform, } = mapping
57
+
58
+ // 获取源数据的值
59
+ const value = sourceField.split( '.' ).reduce( ( obj, key ) =>
60
+ obj && obj[ key ] !== undefined ? obj[ key ] : undefined, sourceData )
61
+
62
+ // 如果存在值并且有transform函数,则应用transform
63
+ if ( value !== undefined ) {
64
+
65
+ const transformedValue = transform ? transform( value ) : value
66
+
67
+ // 将转换后的值设置到目标字段
68
+ const fieldParts = targetField.split( '.' )
69
+ let current = result
70
+
71
+ for ( let i = 0; i < fieldParts.length - 1; i++ ) {
72
+
73
+ const part = fieldParts[ i ]
74
+
75
+ if ( !current[ part ] ) {
76
+
77
+ current[ part ] = {}
78
+
79
+ }
80
+ current = current[ part ]
81
+
82
+ }
83
+
84
+ current[ fieldParts[ fieldParts.length - 1 ] ] = transformedValue
85
+
86
+ }
87
+
88
+ }
89
+
90
+ return result
91
+
92
+ }
93
+
94
+
95
+ // 1. 生成模拟数据
96
+ const schema = componentThingJson[ 0 ] // 你的JSON文件中的第一个元素
97
+ const mockData = generateMockData( schema )
98
+
99
+ console.log( '生成的模拟数据:', mockData )
100
+
101
+ // 2. 定义映射(从一种模式到另一种模式)
102
+ const mappings: SchemaMapping[] = [
103
+ { sourceField: 'name', targetField: 'user.basicInfo.fullName', },
104
+ { sourceField: 'id', targetField: 'user.basicInfo.idNumber', },
105
+ { sourceField: 'gender', targetField: 'user.basicInfo.gender',
106
+ transform: ( value ) => value === 'male' ? '男' : ( value === 'female' ? '女' : '未知' ), },
107
+ { sourceField: 'phoneNumber', targetField: 'user.contact.mobile', },
108
+ { sourceField: 'address', targetField: 'user.contact.address', },
109
+ { sourceField: 'image.data', targetField: 'user.avatar',
110
+ transform: ( value ) => ( { url: value, } ), }
111
+ ]
112
+
113
+ // 3. 转换数据
114
+ const transformedData = transformData( mockData, mappings, {
115
+ version: '1.0',
116
+ createdAt: new Date().toISOString(),
117
+ } )
118
+
119
119
  console.log( '转换后的数据:', transformedData )