@soonspacejs/plugin-flow 2.11.68 → 2.11.70

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.
@@ -1,8 +1,8 @@
1
1
  import SoonSpace from 'soonspacejs';
2
- import { NodeType } from '../../types';
2
+ import { NodeGlobalType, NodeType } from '../../types';
3
3
  import { Node } from '../Node';
4
4
  declare class ClipAnimationNode extends Node {
5
5
  constructor(ssp: SoonSpace, node: NodeType);
6
- exec(): Promise<void>;
6
+ exec(global: NodeGlobalType): Promise<void>;
7
7
  }
8
8
  export { ClipAnimationNode, };
@@ -1,8 +1,8 @@
1
1
  import SoonSpace from 'soonspacejs';
2
- import { NodeType } from '../../types';
2
+ import { NodeGlobalType, NodeType } from '../../types';
3
3
  import { Node } from '../Node';
4
4
  declare class UnClipAnimationNode extends Node {
5
5
  constructor(ssp: SoonSpace, node: NodeType);
6
- exec(): Promise<void>;
6
+ exec(global: NodeGlobalType): Promise<void>;
7
7
  }
8
8
  export { UnClipAnimationNode, };
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
1
- import s from"soonspacejs";import{AnimationPlayer as t}from"umanager-animation-parser";class e{constructor(s){this.id=s.id,this.source=s.source,this.target=s.target}}class i{constructor(s,t){this.prevNodes=[],this.postNodes=[],this.ssp=s,this.id=t.id,this.type=t.type,this.props=t.props,this.reset()}reset(){this.ctx={},this.promise=new Promise(((s,t)=>{this.resolve=s,this.reject=t}))}readContext(s){return this.ctx[s]}writeContext(s,t){this.ctx[s]=t}findProp(s,t){return this.props.find((e=>e.name===s&&e.type===t))}async waitForPrevNodes(){await Promise.all(this.prevNodes.map((s=>s.promise)))}mergeContext(){this.prevNodes.forEach((s=>{Object.assign(this.ctx,s.ctx)}))}async exec(s){}async run(s){await this.waitForPrevNodes(),this.mergeContext(),await this.exec(s).then(this.resolve)}}class n extends i{constructor(s,t){super(s,t)}}var o,a;!function(s){s.LOCAL="LOCAL",s.READ_CTX="READ_CTX",s.WRITE_CTX="WRITE_CTX"}(o||(o={})),function(s){s.START="START",s.COLOR="COLOR",s.NUMBER="NUMBER",s.HIGHLIGHT="HIGHLIGHT",s.UN_HIGHLIGHT="UN_HIGHLIGHT",s.OPACITY="OPACITY",s.UN_OPACITY="UN_OPACITY",s.EMISSIVE="EMISSIVE",s.UN_EMISSIVE="UN_EMISSIVE",s.MESH="MESH",s.MESHES="MESHES",s.MODEL="MODEL",s.MODELS="MODELS",s.DELAY="DELAY",s.SHOW="SHOW",s.HIDE="HIDE",s.CLIP_ANIMATION="CLIP_ANIMATION",s.UN_CLIP_ANIMATION="UN_CLIP_ANIMATION",s.TWEEN_ANIMATION="TWEEN_ANIMATION",s.UN_TWEEN_ANIMATION="UN_TWEEN_ANIMATION",s.COMPONENT_TWEEN_ANIMATION="COMPONENT_TWEEN_ANIMATION",s.UN_COMPONENT_TWEEN_ANIMATION="UN_COMPONENT_TWEEN_ANIMATION"}(a||(a={}));class r extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("color",o.LOCAL),t=this.findProp("out",o.WRITE_CTX);s&&t&&this.writeContext(H(t.value),H(s.value))}}class c extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("number",o.LOCAL),t=this.findProp("out",o.WRITE_CTX);s&&t&&this.writeContext(H(t.value),H(s.value))}}class h extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX),t=this.findProp("color",o.READ_CTX),e=this.findProp("opacity",o.READ_CTX);if(s&&t&&e){const i=this.readContext(H(s.value)),n=this.readContext(H(t.value)),o=this.readContext(H(e.value));i&&this.ssp.highlightShow(i,{color:n,opacity:o})}}}class d extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX);if(s){const t=this.readContext(H(s.value));t&&this.ssp.unHighlightShow(t)}}}class l extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX),t=this.findProp("color",o.READ_CTX),e=this.findProp("opacity",o.READ_CTX);if(s&&t&&e){const i=this.readContext(H(s.value)),n=this.readContext(H(t.value)),o=this.readContext(H(e.value));i&&this.ssp.opacityShow(i,{color:n,opacity:o})}}}class u extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX);if(s){const t=this.readContext(H(s.value));t&&this.ssp.unOpacityShow(t)}}}class p extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX),t=this.findProp("color",o.READ_CTX),e=this.findProp("baseColor",o.READ_CTX),i=this.findProp("minOpacity",o.READ_CTX),n=this.findProp("maxOpacity",o.READ_CTX),a=this.findProp("duration",o.READ_CTX);if(s&&t&&e&&i&&n&&a){const o=this.readContext(H(s.value)),r=this.readContext(H(t.value)),c=this.readContext(H(e.value)),h=this.readContext(H(i.value)),d=this.readContext(H(n.value)),l=this.readContext(H(a.value));o&&this.ssp.emissiveShow(o,{color:r,baseColor:c,minOpacity:h,maxOpacity:d,duration:l})}}}class E extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX);if(s){const t=this.readContext(H(s.value));t&&this.ssp.unEmissiveShow(t)}}}const C=Symbol("meshCache");class T extends i{constructor(s,t){super(s,t)}async exec(s){var t;const{viewport:{scene:e}}=this.ssp,i=await(null===(t=s.getTarget)||void 0===t?void 0:t.call(s,this))||e;s[C]||(s[C]={});const n=this.findProp("mesh",o.LOCAL),a=this.findProp("out",o.WRITE_CTX);if(n&&a){let t=null;const e=H(n.value),o=H(a.value),r=s[C][e];if(r)return void(t=r);const c=b(i,e);c&&(t=c,s[C][e]=c),this.writeContext(o,t)}}}const f=Symbol("meshesCache");class I extends i{constructor(s,t){super(s,t)}async exec(s){var t;const{viewport:{scene:e}}=this.ssp,i=await(null===(t=s.getTarget)||void 0===t?void 0:t.call(s,this))||e;s[f]||(s[f]={});const n=this.findProp("meshes",o.LOCAL),a=this.findProp("out",o.WRITE_CTX);if(n&&a){const t=[],e=H(n.value),o=H(a.value);e.forEach((e=>{const n=s[f][e];if(n)return void t.push(n);const o=b(i,e);o&&(t.push(o),s[f][e]=o)})),this.writeContext(o,t)}}}class N extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("model",o.LOCAL),t=this.findProp("out",o.WRITE_CTX);if(s&&t){const o=H(s.value),a=H(t.value);this.writeContext(a,(e=this.ssp,i=o,null!==(n=e.getAllModel().find((s=>s.userData.id===i||s.userData.uuid===i)))&&void 0!==n?n:null))}var e,i,n}}class A extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("models",o.LOCAL),t=this.findProp("out",o.WRITE_CTX);if(s&&t){const e=H(s.value),i=H(t.value);this.writeContext(i,function(s,t){const e=new Set(t);return s.getAllModel().filter((s=>e.has(s.userData.id)||e.has(s.userData.uuid)))}(this.ssp,e))}}}class O extends i{constructor(s,t){super(s,t)}async exec(){const t=this.findProp("delay",o.LOCAL);if(t){const e=H(t.value);await s.utils.sleep(e)}}}const{objectHandle:v}=s.utils;class _ extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX);if(s){const t=this.readContext(H(s.value));t&&(v(t,(s=>{s.visible=!0})),this.ssp.render())}}}const{objectHandle:L}=s.utils;class x extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX);if(s){const t=this.readContext(H(s.value));t&&(L(t,(s=>{s.visible=!1})),this.ssp.render())}}}class M extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("object",o.READ_CTX),t=this.findProp("animation",o.LOCAL);if(s&&t){const e=this.readContext(H(s.value)),i=H(t.value);if(e){const s=e.animations[i];s&&this.ssp.playModelAnimation(e,s)}}}}class w extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("object",o.READ_CTX),t=this.findProp("animation",o.LOCAL);if(s&&t){const e=this.readContext(H(s.value)),i=H(t.value);if(e){const s=e.animations[i];s&&this.ssp.stopModelAnimation(e,s)}}}}const P=new Map;class g extends i{constructor(s,t){super(s,t)}async exec(s){var e;const i=this.findProp("object",o.READ_CTX),n=this.findProp("animation",o.LOCAL),a=this.findProp("wait",o.LOCAL);if(i&&n&&a){const o=this.readContext(H(i.value)),r=H(n.value),c=H(a.value);if(o){const i=await(null===(e=s.getAnimations)||void 0===e?void 0:e.call(s,this,o,r));if(i){const s=i.find((s=>s.id===r));s&&await R((async()=>{await async function(s,e,i){var n;const{id:o,keyframes:a}=i,r=new t(s,e);P.has(o)||P.set(o,new Set),null===(n=P.get(o))||void 0===n||n.add(r),await r.play(a)}(this.ssp,o,s)}),c)}}}}}class y extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("animation",o.LOCAL);if(s){const n=H(s.value);t=n,null===(e=P.get(t))||void 0===e||e.forEach((s=>s.stop())),null===(i=P.get(t))||void 0===i||i.clear()}var t,e,i}}const m=new Map;class D extends i{constructor(s,t){super(s,t)}async exec(s){var e;const i=this.findProp("object",o.READ_CTX),n=this.findProp("animation",o.LOCAL),a=this.findProp("wait",o.LOCAL);if(i&&n&&a){const o=this.readContext(H(i.value)),r=H(n.value),c=H(a.value);if(o){const n=await(null===(e=s.getComponentAnimations)||void 0===e?void 0:e.call(s,this,o,r));if(n){const s=n.find((s=>s.id===r));if(s){let e=null;"Mesh"===i.valueType?e=o:"Model"===i.valueType&&(e=b(o,s.refId)),e&&await R((async()=>{e&&await async function(s,e,i){var n;const{id:o,keyframes:a}=i,r=new t(s,e);m.has(o)||m.set(o,new Set),null===(n=m.get(o))||void 0===n||n.add(r),await r.play(a)}(this.ssp,e,s)}),c)}}}}}}class S extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("animation",o.LOCAL);if(s){const n=H(s.value);t=n,null===(e=m.get(t))||void 0===e||e.forEach((s=>s.stop())),null===(i=m.get(t))||void 0===i||i.clear()}var t,e,i}}function H(s){return JSON.parse(s)}async function R(s,t){t?await s():s()}function b(s,t){if(s.userData.key===t)return s;for(let e=0,i=s.children.length;e<i;e++){const i=b(s.children[e],t);if(null!==i)return i}return null}class X{constructor(s,t){this.ssp=s,this.flow=t,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)}clear(){this.nodes.length=0,this.nodesMap.clear(),this.edges.length=0,this.edgesMap.clear()}parse(){this.clear();const{nodes:s,edges:t}=this.flow;s.forEach((s=>{const t=function(s,t){switch(t.type){case a.START:return new n(s,t);case a.COLOR:return new r(s,t);case a.NUMBER:return new c(s,t);case a.HIGHLIGHT:return new h(s,t);case a.UN_HIGHLIGHT:return new d(s,t);case a.OPACITY:return new l(s,t);case a.UN_OPACITY:return new u(s,t);case a.EMISSIVE:return new p(s,t);case a.UN_EMISSIVE:return new E(s,t);case a.MESH:return new T(s,t);case a.MESHES:return new I(s,t);case a.MODEL:return new N(s,t);case a.MODELS:return new A(s,t);case a.DELAY:return new O(s,t);case a.SHOW:return new _(s,t);case a.HIDE:return new x(s,t);case a.CLIP_ANIMATION:return new M(s,t);case a.UN_CLIP_ANIMATION:return new w(s,t);case a.TWEEN_ANIMATION:return new g(s,t);case a.UN_TWEEN_ANIMATION:return new y(s,t);case a.COMPONENT_TWEEN_ANIMATION:return new D(s,t);case a.UN_COMPONENT_TWEEN_ANIMATION:return new S(s,t);default:return new i(s,t)}}(this.ssp,s);this.addNode(t)})),t.forEach((s=>{const t=new e(s);this.addEdge(t);const i=this.getNodeById(s.source),n=this.getNodeById(s.target);i&&n&&(i.postNodes.push(n),n.prevNodes.push(i))}))}async run(s={}){const t=this.nodes.map((t=>t.run(s)));await Promise.all(t)}}class U extends X{constructor(s,t){super(s,t),this.flow=t}}class G{constructor(s){this.disposables=[],this.ssp=s}dispose(){this.disposables.forEach((s=>s()))}}var W,k,B,j;!function(s){s.GLOBAL="GLOBAL",s.SELF="SELF",s.OTHER="OTHER"}(W||(W={})),function(s){s.FLOW="FLOW",s.ANIMATION="ANIMATION",s.DELAY="DELAY"}(k||(k={})),function(s){s.GLOBAL="GLOBAL",s.INSTANCE="INSTANCE",s.FAMILY="FAMILY"}(B||(B={})),function(s){s.MOUSE_CLICK="MOUSE_CLICK",s.MOUSE_DB_CLICK="MOUSE_DB_CLICK",s.MOUSE_RIGHT_CLICK="MOUSE_RIGHT_CLICK",s.THING_PROP_CHANGE="THING_PROP_CHANGE",s.THING_EVENT="THING_EVENT",s.LOADED="LOADED"}(j||(j={}));const{groupBy:Y}=s.utils;class F extends G{constructor(s,t,e,i){super(s),this.target=t,this.interaction=e,this.flows=i,this.flowsMap=Y(i,"id"),this.init()}init(){switch(this.interaction.type){case j.MOUSE_CLICK:this.initMouseClick();break;case j.MOUSE_DB_CLICK:this.initMouseDbClick();break;case j.MOUSE_RIGHT_CLICK:this.initMouseRightClick();break;case j.LOADED:this.initLoaded();break;case j.THING_PROP_CHANGE:this.initThingPropChange();break;case j.THING_EVENT:this.initThingEvent()}}modelHandler(s){var t;const{currentTarget:e}=s;null===(t=this.interaction.obsTargets)||void 0===t||t.forEach((s=>{s===e.userData.key&&this.execBehavior()}))}runFlowByIds(s){s.forEach((s=>{const t=this.flowsMap.get(s);if(t){const s=new U(this.ssp,t[0]);s.parse(),s.run({getTarget:async()=>this.target})}}))}async execBehavior(){const{behaviors:s}=this.interaction;null==s||s.forEach((s=>{if(s.action===k.FLOW)s.actionRefs&&this.runFlowByIds(s.actionRefs)}))}initMouseClick(){this.ssp.signals.modelClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelClick.remove(this.modelHandler)))}initMouseDbClick(){this.ssp.signals.modelDblClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelDblClick.remove(this.modelHandler)))}initMouseRightClick(){this.ssp.signals.modelRightClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelRightClick.remove(this.modelHandler)))}initLoaded(){const s=()=>{this.execBehavior()};this.target.addEventListener("load",s),this.disposables.push((()=>this.target.removeEventListener("load",s)))}initThingPropChange(){}initThingEvent(){}}export{U as ComponentFlowParser,F as ComponentTrigger,X as FlowParser,k as InteractionAction,W as InteractionActionType,B as InteractionObsType,j as InteractionType,o as NodePropTypeEnum,a as NodeTypeEnum,G as Trigger};
1
+ import s from"soonspacejs";import{AnimationPlayer as t}from"umanager-animation-parser";class e{constructor(s){this.id=s.id,this.source=s.source,this.target=s.target}}class i{constructor(s,t){this.prevNodes=[],this.postNodes=[],this.ssp=s,this.id=t.id,this.type=t.type,this.props=t.props,this.reset()}reset(){this.ctx={},this.promise=new Promise(((s,t)=>{this.resolve=s,this.reject=t}))}readContext(s){return this.ctx[s]}writeContext(s,t){this.ctx[s]=t}findProp(s,t){return this.props.find((e=>e.name===s&&e.type===t))}async waitForPrevNodes(){await Promise.all(this.prevNodes.map((s=>s.promise)))}mergeContext(){this.prevNodes.forEach((s=>{Object.assign(this.ctx,s.ctx)}))}async exec(s){}async run(s){await this.waitForPrevNodes(),this.mergeContext(),await this.exec(s).then(this.resolve)}}class n extends i{constructor(s,t){super(s,t)}}var o,a;!function(s){s.LOCAL="LOCAL",s.READ_CTX="READ_CTX",s.WRITE_CTX="WRITE_CTX"}(o||(o={})),function(s){s.START="START",s.COLOR="COLOR",s.NUMBER="NUMBER",s.HIGHLIGHT="HIGHLIGHT",s.UN_HIGHLIGHT="UN_HIGHLIGHT",s.OPACITY="OPACITY",s.UN_OPACITY="UN_OPACITY",s.EMISSIVE="EMISSIVE",s.UN_EMISSIVE="UN_EMISSIVE",s.MESH="MESH",s.MESHES="MESHES",s.MODEL="MODEL",s.MODELS="MODELS",s.DELAY="DELAY",s.SHOW="SHOW",s.HIDE="HIDE",s.CLIP_ANIMATION="CLIP_ANIMATION",s.UN_CLIP_ANIMATION="UN_CLIP_ANIMATION",s.TWEEN_ANIMATION="TWEEN_ANIMATION",s.UN_TWEEN_ANIMATION="UN_TWEEN_ANIMATION",s.COMPONENT_TWEEN_ANIMATION="COMPONENT_TWEEN_ANIMATION",s.UN_COMPONENT_TWEEN_ANIMATION="UN_COMPONENT_TWEEN_ANIMATION"}(a||(a={}));class r extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("color",o.LOCAL),t=this.findProp("out",o.WRITE_CTX);s&&t&&this.writeContext(H(t.value),H(s.value))}}class c extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("number",o.LOCAL),t=this.findProp("out",o.WRITE_CTX);s&&t&&this.writeContext(H(t.value),H(s.value))}}class h extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX),t=this.findProp("color",o.READ_CTX),e=this.findProp("opacity",o.READ_CTX);if(s&&t&&e){const i=this.readContext(H(s.value)),n=this.readContext(H(t.value)),o=this.readContext(H(e.value));i&&this.ssp.highlightShow(i,{color:n,opacity:o})}}}class l extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX);if(s){const t=this.readContext(H(s.value));t&&this.ssp.unHighlightShow(t)}}}class d extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX),t=this.findProp("color",o.READ_CTX),e=this.findProp("opacity",o.READ_CTX);if(s&&t&&e){const i=this.readContext(H(s.value)),n=this.readContext(H(t.value)),o=this.readContext(H(e.value));i&&this.ssp.opacityShow(i,{color:n,opacity:o})}}}class u extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX);if(s){const t=this.readContext(H(s.value));t&&this.ssp.unOpacityShow(t)}}}class p extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX),t=this.findProp("color",o.READ_CTX),e=this.findProp("baseColor",o.READ_CTX),i=this.findProp("minOpacity",o.READ_CTX),n=this.findProp("maxOpacity",o.READ_CTX),a=this.findProp("duration",o.READ_CTX);if(s&&t&&e&&i&&n&&a){const o=this.readContext(H(s.value)),r=this.readContext(H(t.value)),c=this.readContext(H(e.value)),h=this.readContext(H(i.value)),l=this.readContext(H(n.value)),d=this.readContext(H(a.value));o&&this.ssp.emissiveShow(o,{color:r,baseColor:c,minOpacity:h,maxOpacity:l,duration:d})}}}class E extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX);if(s){const t=this.readContext(H(s.value));t&&this.ssp.unEmissiveShow(t)}}}const C=Symbol("meshCache");class T extends i{constructor(s,t){super(s,t)}async exec(s){var t;const{viewport:{scene:e}}=this.ssp,i=await(null===(t=s.getTarget)||void 0===t?void 0:t.call(s,this))||e;s[C]||(s[C]={});const n=this.findProp("mesh",o.LOCAL),a=this.findProp("out",o.WRITE_CTX);if(n&&a){let t=null;const e=H(n.value),o=H(a.value),r=s[C][e];if(r)return void(t=r);const c=b(i,e);c&&(t=c,s[C][e]=c),this.writeContext(o,t)}}}const f=Symbol("meshesCache");class I extends i{constructor(s,t){super(s,t)}async exec(s){var t;const{viewport:{scene:e}}=this.ssp,i=await(null===(t=s.getTarget)||void 0===t?void 0:t.call(s,this))||e;s[f]||(s[f]={});const n=this.findProp("meshes",o.LOCAL),a=this.findProp("out",o.WRITE_CTX);if(n&&a){const t=[],e=H(n.value),o=H(a.value);e.forEach((e=>{const n=s[f][e];if(n)return void t.push(n);const o=b(i,e);o&&(t.push(o),s[f][e]=o)})),this.writeContext(o,t)}}}class N extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("model",o.LOCAL),t=this.findProp("out",o.WRITE_CTX);if(s&&t){const o=H(s.value),a=H(t.value);this.writeContext(a,(e=this.ssp,i=o,null!==(n=e.getAllModel().find((s=>s.userData.id===i||s.userData.uuid===i)))&&void 0!==n?n:null))}var e,i,n}}class A extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("models",o.LOCAL),t=this.findProp("out",o.WRITE_CTX);if(s&&t){const e=H(s.value),i=H(t.value);this.writeContext(i,function(s,t){const e=new Set(t);return s.getAllModel().filter((s=>e.has(s.userData.id)||e.has(s.userData.uuid)))}(this.ssp,e))}}}class v extends i{constructor(s,t){super(s,t)}async exec(){const t=this.findProp("delay",o.LOCAL);if(t){const e=H(t.value);await s.utils.sleep(e)}}}const{objectHandle:O}=s.utils;class _ extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX);if(s){const t=this.readContext(H(s.value));t&&(O(t,(s=>{s.visible=!0})),this.ssp.render())}}}const{objectHandle:L}=s.utils;class x extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX);if(s){const t=this.readContext(H(s.value));t&&(L(t,(s=>{s.visible=!1})),this.ssp.render())}}}class M extends i{constructor(s,t){super(s,t)}async exec(s){var t;let e=await(null===(t=s.getTarget)||void 0===t?void 0:t.call(s,this));if(!e){const s=this.findProp("object",o.READ_CTX);s&&(e=this.readContext(H(s.value)))}const i=this.findProp("animation",o.LOCAL);if(e&&i){const s=H(i.value),t=e.animations[s];t&&this.ssp.playModelAnimation(e,t)}}}class w extends i{constructor(s,t){super(s,t)}async exec(s){var t;let e=await(null===(t=s.getTarget)||void 0===t?void 0:t.call(s,this));if(!e){const s=this.findProp("object",o.READ_CTX);s&&(e=this.readContext(H(s.value)))}const i=this.findProp("animation",o.LOCAL);if(e&&i){const s=H(i.value),t=e.animations[s];t&&this.ssp.stopModelAnimation(e,t)}}}const g=new Map;class P extends i{constructor(s,t){super(s,t)}async exec(s){var e;const i=this.findProp("object",o.READ_CTX),n=this.findProp("animation",o.LOCAL),a=this.findProp("wait",o.LOCAL);if(i&&n&&a){const o=this.readContext(H(i.value)),r=H(n.value),c=H(a.value);if(o){const i=await(null===(e=s.getAnimations)||void 0===e?void 0:e.call(s,this,o,r));if(i){const s=i.find((s=>s.id===r));s&&await R((async()=>{await async function(s,e,i){var n;const{id:o,keyframes:a}=i,r=new t(s,e);g.has(o)||g.set(o,new Set),null===(n=g.get(o))||void 0===n||n.add(r),await r.play(a)}(this.ssp,o,s)}),c)}}}}}class y extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("animation",o.LOCAL);if(s){const n=H(s.value);t=n,null===(e=g.get(t))||void 0===e||e.forEach((s=>s.stop())),null===(i=g.get(t))||void 0===i||i.clear()}var t,e,i}}const m=new Map;class D extends i{constructor(s,t){super(s,t)}async exec(s){var e;const i=this.findProp("object",o.READ_CTX),n=this.findProp("animation",o.LOCAL),a=this.findProp("wait",o.LOCAL);if(i&&n&&a){const o=this.readContext(H(i.value)),r=H(n.value),c=H(a.value);if(o){const n=await(null===(e=s.getComponentAnimations)||void 0===e?void 0:e.call(s,this,o,r));if(n){const s=n.find((s=>s.id===r));if(s){let e=null;"Mesh"===i.valueType?e=o:"Model"===i.valueType&&(e=b(o,s.refId)),e&&await R((async()=>{e&&await async function(s,e,i){var n;const{id:o,keyframes:a}=i,r=new t(s,e);m.has(o)||m.set(o,new Set),null===(n=m.get(o))||void 0===n||n.add(r),await r.play(a)}(this.ssp,e,s)}),c)}}}}}}class S extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("animation",o.LOCAL);if(s){const n=H(s.value);t=n,null===(e=m.get(t))||void 0===e||e.forEach((s=>s.stop())),null===(i=m.get(t))||void 0===i||i.clear()}var t,e,i}}function H(s){return JSON.parse(s)}async function R(s,t){t?await s():s()}function b(s,t){if(s.userData.key===t)return s;for(let e=0,i=s.children.length;e<i;e++){const i=b(s.children[e],t);if(null!==i)return i}return null}class X{constructor(s,t){this.ssp=s,this.flow=t,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)}clear(){this.nodes.length=0,this.nodesMap.clear(),this.edges.length=0,this.edgesMap.clear()}parse(){this.clear();const{nodes:s,edges:t}=this.flow;s.forEach((s=>{const t=function(s,t){switch(t.type){case a.START:return new n(s,t);case a.COLOR:return new r(s,t);case a.NUMBER:return new c(s,t);case a.HIGHLIGHT:return new h(s,t);case a.UN_HIGHLIGHT:return new l(s,t);case a.OPACITY:return new d(s,t);case a.UN_OPACITY:return new u(s,t);case a.EMISSIVE:return new p(s,t);case a.UN_EMISSIVE:return new E(s,t);case a.MESH:return new T(s,t);case a.MESHES:return new I(s,t);case a.MODEL:return new N(s,t);case a.MODELS:return new A(s,t);case a.DELAY:return new v(s,t);case a.SHOW:return new _(s,t);case a.HIDE:return new x(s,t);case a.CLIP_ANIMATION:return new M(s,t);case a.UN_CLIP_ANIMATION:return new w(s,t);case a.TWEEN_ANIMATION:return new P(s,t);case a.UN_TWEEN_ANIMATION:return new y(s,t);case a.COMPONENT_TWEEN_ANIMATION:return new D(s,t);case a.UN_COMPONENT_TWEEN_ANIMATION:return new S(s,t);default:return new i(s,t)}}(this.ssp,s);this.addNode(t)})),t.forEach((s=>{const t=new e(s);this.addEdge(t);const i=this.getNodeById(s.source),n=this.getNodeById(s.target);i&&n&&(i.postNodes.push(n),n.prevNodes.push(i))}))}async run(s={}){const t=this.nodes.map((t=>t.run(s)));await Promise.all(t)}}class U extends X{constructor(s,t){super(s,t),this.flow=t}}class G{constructor(s){this.disposables=[],this.ssp=s}dispose(){this.disposables.forEach((s=>s()))}}var W,k,B,j;!function(s){s.GLOBAL="GLOBAL",s.SELF="SELF",s.OTHER="OTHER"}(W||(W={})),function(s){s.FLOW="FLOW",s.ANIMATION="ANIMATION",s.DELAY="DELAY"}(k||(k={})),function(s){s.GLOBAL="GLOBAL",s.INSTANCE="INSTANCE",s.FAMILY="FAMILY"}(B||(B={})),function(s){s.MOUSE_CLICK="MOUSE_CLICK",s.MOUSE_DB_CLICK="MOUSE_DB_CLICK",s.MOUSE_RIGHT_CLICK="MOUSE_RIGHT_CLICK",s.THING_PROP_CHANGE="THING_PROP_CHANGE",s.THING_EVENT="THING_EVENT",s.LOADED="LOADED"}(j||(j={}));const{groupBy:Y}=s.utils;class F extends G{constructor(s,t,e,i){super(s),this.target=t,this.interaction=e,this.flows=i,this.flowsMap=Y(i,"id"),this.init()}init(){switch(this.interaction.type){case j.MOUSE_CLICK:this.initMouseClick();break;case j.MOUSE_DB_CLICK:this.initMouseDbClick();break;case j.MOUSE_RIGHT_CLICK:this.initMouseRightClick();break;case j.LOADED:this.initLoaded();break;case j.THING_PROP_CHANGE:this.initThingPropChange();break;case j.THING_EVENT:this.initThingEvent()}}modelHandler(s){var t;const{currentTarget:e}=s;null===(t=this.interaction.obsTargets)||void 0===t||t.forEach((s=>{s===e.userData.key&&this.execBehavior()}))}runFlowByIds(s){s.forEach((s=>{const t=this.flowsMap.get(s);if(t){const s=new U(this.ssp,t[0]);s.parse(),s.run({getTarget:async()=>this.target})}}))}async execBehavior(){const{behaviors:s}=this.interaction;null==s||s.forEach((s=>{if(s.action===k.FLOW)s.actionRefs&&this.runFlowByIds(s.actionRefs)}))}initMouseClick(){this.ssp.signals.modelClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelClick.remove(this.modelHandler)))}initMouseDbClick(){this.ssp.signals.modelDblClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelDblClick.remove(this.modelHandler)))}initMouseRightClick(){this.ssp.signals.modelRightClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelRightClick.remove(this.modelHandler)))}initLoaded(){const s=()=>{this.execBehavior()};this.target.addEventListener("load",s),this.disposables.push((()=>this.target.removeEventListener("load",s)))}initThingPropChange(){}initThingEvent(){}}export{U as ComponentFlowParser,F as ComponentTrigger,X as FlowParser,k as InteractionAction,W as InteractionActionType,B as InteractionObsType,j as InteractionType,o as NodePropTypeEnum,a as NodeTypeEnum,G as Trigger};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soonspacejs/plugin-flow",
3
3
  "pluginName": "FlowPlugin",
4
- "version": "2.11.68",
4
+ "version": "2.11.70",
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": "2d0ffb4b53484c1192762c995b8f926615d81372",
16
+ "gitHead": "05c206c574a3ccf65377d5e787161cdaa0c1cdca",
17
17
  "peerDependencies": {
18
- "soonspacejs": "2.11.68",
18
+ "soonspacejs": "2.11.70",
19
19
  "umanager-animation-parser": "^0.0.6"
20
20
  }
21
21
  }