@soonspacejs/plugin-flow 2.11.66

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/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # @soonspacejs/plugin-flow
2
+
3
+ > Flow plugin for SoonSpace.js
4
+
@@ -0,0 +1,12 @@
1
+ import SoonSpace from 'soonspacejs';
2
+ import { FlowParser } from './FlowParser';
3
+ import { ComponentFlowType } from './types';
4
+ declare class ComponentFlowParser extends FlowParser {
5
+ flow: ComponentFlowType;
6
+ constructor(ssp: SoonSpace, flow: ComponentFlowType);
7
+ /**
8
+ * 解析流程
9
+ */
10
+ parse(): void;
11
+ }
12
+ export { ComponentFlowParser, };
package/dist/Edge.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { EdgeType } from './types';
2
+ declare class Edge {
3
+ id: string;
4
+ source: string;
5
+ target: string;
6
+ constructor(edge: EdgeType);
7
+ }
8
+ export { Edge, };
@@ -0,0 +1,27 @@
1
+ import SoonSpace from 'soonspacejs';
2
+ import { Edge } from './Edge';
3
+ import { Node } from './nodes';
4
+ import { NodeGlobalType } from './types';
5
+ declare class FlowParser {
6
+ ssp: SoonSpace;
7
+ nodes: Node[];
8
+ nodesMap: Map<Node['id'], Node>;
9
+ edges: Edge[];
10
+ edgesMap: Map<Edge['id'], Edge>;
11
+ constructor(ssp: SoonSpace);
12
+ addNode(node: Node): void;
13
+ addEdge(edge: Edge): void;
14
+ getNodeById(id: string): Node | undefined;
15
+ getEdgeById(id: string): Edge | undefined;
16
+ /**
17
+ * 获取从某节点出发的连接
18
+ */
19
+ getEdgesSource(nodeId: string): Edge[];
20
+ /**
21
+ * 执行流程
22
+ * @param startNode
23
+ * @param ctx
24
+ */
25
+ run(global?: NodeGlobalType): Promise<void>;
26
+ }
27
+ export { FlowParser, };
@@ -0,0 +1,2 @@
1
+ export { FlowParser, } from './FlowParser';
2
+ export { ComponentFlowParser, } from './ComponentFlowParser';
@@ -0,0 +1 @@
1
+ class s{constructor(s){this.ssp=s,this.nodes=[],this.nodesMap=new Map,this.edges=[],this.edgesMap=new Map}addNode(s){this.nodes.push(s),this.nodesMap.set(s.id,s)}addEdge(s){this.edges.push(s),this.edgesMap.set(s.id,s)}getNodeById(s){return this.nodesMap.get(s)}getEdgeById(s){return this.edgesMap.get(s)}getEdgesSource(s){return this.edges.filter((t=>t.source===s))}async run(s={target:null}){const t=new Map,e=[],r=new Set,n=new Map;for(this.nodes.forEach((({id:s})=>{t.set(s,0),n.set(s,{})})),this.edges.forEach((({target:s})=>{t.set(s,t.get(s)+1)})),t.forEach(((s,t)=>{0===s&&e.push(t)}));e.length>0;){const o=[...e];e.length=0;const i=o.map((async o=>{if(!r.has(o)){r.add(o);const i=n.get(o),c=this.nodesMap.get(o),a=await c.run(i,s),u=this.getEdgesSource(o).map((s=>s.target));u.forEach((s=>{n.has(s)||n.set(s,{});const t=n.get(s);Object.assign(t,i,a)})),u.forEach((s=>{const r=t.get(s)-1;t.set(s,r),0===r&&e.push(s)}))}}));await Promise.all(i)}}}class t{constructor(s){this.id=s.id,this.source=s.source,this.target=s.target}}class e{constructor(s,t){this.ssp=s,this.id=t.id,this.type=t.type,this.props=t.props}readCtx(s,t){return s[t]}findProp(s,t){return this.props.find((e=>e.name===s&&e.type===t))}async run(s,t){}}class r extends e{constructor(s,t){super(s,t)}}var n,o;!function(s){s.LOCAL="LOCAL",s.READ_CTX="READ_CTX",s.WRITE_CTX="WRITE_CTX"}(n||(n={})),function(s){s.START="START",s.HIGHLIGHT="HIGHLIGHT",s.COLOR="COLOR",s.MESH="MESH",s.NUMBER="NUMBER"}(o||(o={}));class i extends e{constructor(s,t){super(s,t)}async run(){const s=this.findProp("color",n.LOCAL),t=this.findProp("out",n.WRITE_CTX);if(s&&t)return{[p(t.value)]:p(s.value)}}}class c extends e{constructor(s,t){super(s,t)}async run(){const s=this.findProp("number",n.LOCAL),t=this.findProp("out",n.WRITE_CTX);if(s&&t)return{[p(t.value)]:p(s.value)}}}class a extends e{constructor(s,t){super(s,t)}async run(s){const t=this.findProp("objects",n.READ_CTX),e=this.findProp("color",n.READ_CTX),r=this.findProp("opacity",n.READ_CTX);if(t&&e&&r){const n=this.readCtx(s,p(t.value)),o=this.readCtx(s,p(e.value)),i=this.readCtx(s,p(r.value));this.ssp.highlightShow(n,{color:o,opacity:i})}}}const u=Symbol("meshCache");class h extends e{constructor(s,t){super(s,t)}async run(s,t){const{viewport:{scene:e}}=this.ssp,r=s.target||e;t[u]||(t[u]={});const o=this.findProp("meshes",n.LOCAL),i=this.findProp("out",n.WRITE_CTX);if(o&&i){const s=[],e=p(o.value),n=p(i.value);return e.forEach((e=>{const n=t[u][e];if(n)return void s.push(n);const o=d(r,e);o&&(s.push(o),t[u][e]=o)})),{[n]:s}}}}function d(s,t){if(s.userData.uuid===t)return s;for(let e=0,r=s.children.length;e<r;e++){const r=d(s.children[e],t);if(void 0!==r)return r}}function p(s){return JSON.parse(s)}class f extends s{constructor(s,t){super(s),this.flow=t}parse(){const{nodes:s,edges:n}=this.flow;s.forEach((s=>{const t=function(s,t){switch(t.type){case o.START:return new r(s,t);case o.MESH:return new h(s,t);case o.COLOR:return new i(s,t);case o.HIGHLIGHT:return new a(s,t);case o.NUMBER:return new c(s,t);default:return new e(s,t)}}(this.ssp,s);this.addNode(t)})),n.forEach((s=>{const e=new t(s);this.addEdge(e)}))}}export{f as ComponentFlowParser,s as FlowParser};
@@ -0,0 +1,10 @@
1
+ import SoonSpace from 'soonspacejs';
2
+ import { NodeType } from '../types';
3
+ import { Node } from './Node';
4
+ declare class ColorNode extends Node {
5
+ constructor(ssp: SoonSpace, node: NodeType);
6
+ run(): Promise<{
7
+ [x: number]: any;
8
+ } | undefined>;
9
+ }
10
+ export { ColorNode, };
@@ -0,0 +1,8 @@
1
+ import SoonSpace from 'soonspacejs';
2
+ import { NodeCtxType, NodeType } from '../types';
3
+ import { Node } from './Node';
4
+ declare class HighlightNode extends Node {
5
+ constructor(ssp: SoonSpace, node: NodeType);
6
+ run(ctx: NodeCtxType): Promise<void>;
7
+ }
8
+ export { HighlightNode, };
@@ -0,0 +1,11 @@
1
+ import { Object3D } from 'three';
2
+ import SoonSpace from 'soonspacejs';
3
+ import { NodeCtxType, NodeGlobalType, NodeType } from '../types';
4
+ import { Node } from './Node';
5
+ declare class MeshNode extends Node {
6
+ constructor(ssp: SoonSpace, node: NodeType);
7
+ run(ctx: NodeCtxType, global: NodeGlobalType): Promise<{
8
+ [x: number]: Object3D<import("three").Object3DEventMap>[];
9
+ } | undefined>;
10
+ }
11
+ export { MeshNode, };
@@ -0,0 +1,13 @@
1
+ import SoonSpace from 'soonspacejs';
2
+ import { NodeType, NodeCtxType, NodePropType, NodeGlobalType } from '../types';
3
+ declare class Node {
4
+ ssp: SoonSpace;
5
+ id: string;
6
+ type: string;
7
+ props: NodeType['props'];
8
+ constructor(ssp: SoonSpace, node: NodeType);
9
+ readCtx<T = any>(ctx: NodeCtxType, key: string): T;
10
+ findProp(name: string, type: NodePropType['type']): NodePropType | undefined;
11
+ run(ctx: NodeCtxType, global: NodeGlobalType): Promise<NodeCtxType | void>;
12
+ }
13
+ export { Node, };
@@ -0,0 +1,10 @@
1
+ import SoonSpace from 'soonspacejs';
2
+ import { NodeType } from '../types';
3
+ import { Node } from './Node';
4
+ declare class NumberNode extends Node {
5
+ constructor(ssp: SoonSpace, node: NodeType);
6
+ run(): Promise<{
7
+ [x: number]: any;
8
+ } | undefined>;
9
+ }
10
+ export { NumberNode, };
@@ -0,0 +1,7 @@
1
+ import SoonSpace from 'soonspacejs';
2
+ import { NodeType } from '../types';
3
+ import { Node } from './Node';
4
+ declare class StartNode extends Node {
5
+ constructor(ssp: SoonSpace, node: NodeType);
6
+ }
7
+ export { StartNode, };
@@ -0,0 +1,6 @@
1
+ export { Node, } from './Node';
2
+ export { StartNode, } from './StartNode';
3
+ export { ColorNode, } from './ColorNode';
4
+ export { NumberNode, } from './NumberNode';
5
+ export { HighlightNode, } from './HighlightNode';
6
+ export { MeshNode, } from './MeshNode';
@@ -0,0 +1,63 @@
1
+ import { Object3D } from 'three';
2
+ export declare enum NodePropTypeEnum {
3
+ LOCAL = "LOCAL",
4
+ READ_CTX = "READ_CTX",
5
+ WRITE_CTX = "WRITE_CTX"
6
+ }
7
+ export declare enum NodeTypeEnum {
8
+ START = "START",
9
+ HIGHLIGHT = "HIGHLIGHT",
10
+ COLOR = "COLOR",
11
+ MESH = "MESH",
12
+ NUMBER = "NUMBER"
13
+ }
14
+ /**
15
+ * 节点 props 数据
16
+ */
17
+ export type NodePropType = {
18
+ name: string;
19
+ type: NodePropTypeEnum;
20
+ value: string;
21
+ valueType: string;
22
+ };
23
+ /**
24
+ * 节点数据
25
+ */
26
+ export type NodeType = {
27
+ id: string;
28
+ type: NodeTypeEnum;
29
+ props: NodePropType[];
30
+ };
31
+ /**
32
+ * 连接数据
33
+ */
34
+ export type EdgeType = {
35
+ id: string;
36
+ source: string;
37
+ target: string;
38
+ };
39
+ /**
40
+ * 组件流程数据
41
+ */
42
+ export type ComponentFlowType = {
43
+ id: string;
44
+ sid: string;
45
+ name: string;
46
+ portal: string;
47
+ editionId: string;
48
+ nodes: NodeType[];
49
+ edges: EdgeType[];
50
+ };
51
+ /**
52
+ * 节点上下文对象
53
+ */
54
+ export type NodeCtxType = {
55
+ [x: string]: any;
56
+ };
57
+ /**
58
+ * 节点全局对象
59
+ */
60
+ export type NodeGlobalType = {
61
+ target: Object3D | null;
62
+ [s: symbol]: any;
63
+ };
@@ -0,0 +1,5 @@
1
+ import SoonSpace from 'soonspacejs';
2
+ import { Node } from './nodes';
3
+ import { NodeType } from './types';
4
+ export declare function parseNodeByType(ssp: SoonSpace, node: NodeType): Node;
5
+ export declare function parseValue<T = any>(value: string): T;
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@soonspacejs/plugin-flow",
3
+ "pluginName": "FlowPlugin",
4
+ "version": "2.11.66",
5
+ "description": "FlowPlugin plugin for SoonSpace.js",
6
+ "main": "dist/index.esm.js",
7
+ "module": "dist/index.esm.js",
8
+ "unpkg": "dist/index.esm.js",
9
+ "typings": "dist/index.d.ts",
10
+ "keywords": [
11
+ "soonspacejs",
12
+ "flow"
13
+ ],
14
+ "author": "xunwei",
15
+ "license": "UNLICENSED",
16
+ "gitHead": "615dd40516eb5d02aede1c5423298592bfb51987",
17
+ "peerDependencies": {
18
+ "soonspacejs": "2.11.66"
19
+ }
20
+ }