@meshflow/core 0.5.1 → 0.5.2
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/index.d.mts +16 -8
- package/index.d.ts +16 -8
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +1 -1
package/index.d.mts
CHANGED
|
@@ -218,7 +218,7 @@ interface MeshFlowTaskNode<P extends MeshPath = MeshPath, V = any, NM = any> {
|
|
|
218
218
|
proxy: MeshNodeProxy<MeshFlowTaskNode<P, V, NM>, V, NM>;
|
|
219
219
|
calledBy: TriggerCause;
|
|
220
220
|
meta: NM;
|
|
221
|
-
dependOn: (cb: (val: V) => V, key?:
|
|
221
|
+
dependOn: (cb: (val: V) => V, key?: SuggestKey<NM>) => void;
|
|
222
222
|
createView: <E extends Record<string, any> = {}>(extraProps?: E) => MeshNodeProxy<MeshFlowTaskNode<P, V, NM>, V, NM, E>;
|
|
223
223
|
}
|
|
224
224
|
/**
|
|
@@ -655,11 +655,11 @@ declare function useEngineInstance<T, P extends MeshPath, S = any, M extends Rec
|
|
|
655
655
|
on: (event: MeshEventName, cb: Function) => () => boolean | undefined;
|
|
656
656
|
}) => void;
|
|
657
657
|
}) => () => void;
|
|
658
|
-
SetValue: (path: P, key:
|
|
658
|
+
SetValue: (path: P, key: SuggestKey<NM>, value: any) => void;
|
|
659
659
|
GetValue: (path: P, key?: string) => any;
|
|
660
660
|
SetValues: (updates: {
|
|
661
661
|
path: P;
|
|
662
|
-
key:
|
|
662
|
+
key: SuggestKey<NM>;
|
|
663
663
|
value: any;
|
|
664
664
|
}[]) => void;
|
|
665
665
|
GetGroupByPath: (path: MeshPath) => MeshFlowGroupNode<MeshPath>;
|
|
@@ -692,7 +692,7 @@ declare function useEngineInstance<T, P extends MeshPath, S = any, M extends Rec
|
|
|
692
692
|
notifyAll: () => Promise<void>;
|
|
693
693
|
batchNotify: (updates: {
|
|
694
694
|
path: P;
|
|
695
|
-
key:
|
|
695
|
+
key: SuggestKey<NM>;
|
|
696
696
|
value: any;
|
|
697
697
|
}[]) => void;
|
|
698
698
|
useEntangle: (config: EntangleArgType<P>) => void;
|
|
@@ -700,11 +700,13 @@ declare function useEngineInstance<T, P extends MeshPath, S = any, M extends Rec
|
|
|
700
700
|
SetBucket: (newBucket: SchemaBucket<P>) => number;
|
|
701
701
|
GetBucket: (bucketId: number) => SchemaBucket<P>;
|
|
702
702
|
CancelTask: () => void;
|
|
703
|
+
stageValueFn: (uid: number, key: SuggestKey<NM>, value: any) => void;
|
|
703
704
|
UITrigger: any;
|
|
704
705
|
UidToNodeMap: MeshFlowTaskNode<P, any, NM>[];
|
|
705
706
|
};
|
|
706
707
|
destroyPlugin: () => void;
|
|
707
708
|
CancelTask: () => void;
|
|
709
|
+
StageValue: (path: P, key: SuggestKey<NM>, value: any) => void;
|
|
708
710
|
};
|
|
709
711
|
|
|
710
712
|
/**
|
|
@@ -741,7 +743,7 @@ B extends Record<string, any> = StandardUITrigger<T>, NM = any>(config: {
|
|
|
741
743
|
notifyAll: () => Promise<void>;
|
|
742
744
|
batchNotify: (updates: {
|
|
743
745
|
path: P;
|
|
744
|
-
key:
|
|
746
|
+
key: SuggestKey<NM>;
|
|
745
747
|
value: any;
|
|
746
748
|
}[]) => void;
|
|
747
749
|
useEntangle: (config: EntangleArgType<P>) => void;
|
|
@@ -749,6 +751,7 @@ B extends Record<string, any> = StandardUITrigger<T>, NM = any>(config: {
|
|
|
749
751
|
SetBucket: (newBucket: SchemaBucket<P>) => number;
|
|
750
752
|
GetBucket: (bucketId: number) => SchemaBucket<P>;
|
|
751
753
|
CancelTask: () => void;
|
|
754
|
+
stageValueFn: (uid: number, key: SuggestKey<NM>, value: any) => void;
|
|
752
755
|
UITrigger: B;
|
|
753
756
|
UidToNodeMap: MeshFlowTaskNode<P, any, NM>[];
|
|
754
757
|
};
|
|
@@ -774,6 +777,9 @@ type BaseEngine<T> = {
|
|
|
774
777
|
GetGroupByPath: T extends {
|
|
775
778
|
GetGroupByPath: infer F;
|
|
776
779
|
} ? F : never;
|
|
780
|
+
StageValue: T extends {
|
|
781
|
+
StageValue: infer F;
|
|
782
|
+
} ? F : never;
|
|
777
783
|
};
|
|
778
784
|
config: {
|
|
779
785
|
SetRule: T extends {
|
|
@@ -888,11 +894,11 @@ M extends Record<string, any>, NM extends Record<string, any> = IsNever<Normaliz
|
|
|
888
894
|
on: (event: MeshEventName, cb: Function) => () => boolean | undefined;
|
|
889
895
|
}) => void;
|
|
890
896
|
}) => () => void;
|
|
891
|
-
SetValue: (path: P, key:
|
|
897
|
+
SetValue: (path: P, key: SuggestKey<NM>, value: any) => void;
|
|
892
898
|
GetValue: (path: P, key?: string) => any;
|
|
893
899
|
SetValues: (updates: {
|
|
894
900
|
path: P;
|
|
895
|
-
key:
|
|
901
|
+
key: SuggestKey<NM>;
|
|
896
902
|
value: any;
|
|
897
903
|
}[]) => void;
|
|
898
904
|
GetGroupByPath: (path: MeshPath) => MeshFlowGroupNode<MeshPath>;
|
|
@@ -925,7 +931,7 @@ M extends Record<string, any>, NM extends Record<string, any> = IsNever<Normaliz
|
|
|
925
931
|
notifyAll: () => Promise<void>;
|
|
926
932
|
batchNotify: (updates: {
|
|
927
933
|
path: P;
|
|
928
|
-
key:
|
|
934
|
+
key: SuggestKey<NM>;
|
|
929
935
|
value: any;
|
|
930
936
|
}[]) => void;
|
|
931
937
|
useEntangle: (config: EntangleArgType<P>) => void;
|
|
@@ -933,11 +939,13 @@ M extends Record<string, any>, NM extends Record<string, any> = IsNever<Normaliz
|
|
|
933
939
|
SetBucket: (newBucket: SchemaBucket<P>) => number;
|
|
934
940
|
GetBucket: (bucketId: number) => SchemaBucket<P>;
|
|
935
941
|
CancelTask: () => void;
|
|
942
|
+
stageValueFn: (uid: number, key: SuggestKey<NM>, value: any) => void;
|
|
936
943
|
UITrigger: any;
|
|
937
944
|
UidToNodeMap: MeshFlowTaskNode<P, any, NM>[];
|
|
938
945
|
};
|
|
939
946
|
destroyPlugin: () => void;
|
|
940
947
|
CancelTask: () => void;
|
|
948
|
+
StageValue: (path: P, key: SuggestKey<NM>, value: any) => void;
|
|
941
949
|
}, M, P>;
|
|
942
950
|
/**
|
|
943
951
|
* 类型工厂:锁定全局路径与元数据类型,生成定制化的实例化函数。
|
package/index.d.ts
CHANGED
|
@@ -218,7 +218,7 @@ interface MeshFlowTaskNode<P extends MeshPath = MeshPath, V = any, NM = any> {
|
|
|
218
218
|
proxy: MeshNodeProxy<MeshFlowTaskNode<P, V, NM>, V, NM>;
|
|
219
219
|
calledBy: TriggerCause;
|
|
220
220
|
meta: NM;
|
|
221
|
-
dependOn: (cb: (val: V) => V, key?:
|
|
221
|
+
dependOn: (cb: (val: V) => V, key?: SuggestKey<NM>) => void;
|
|
222
222
|
createView: <E extends Record<string, any> = {}>(extraProps?: E) => MeshNodeProxy<MeshFlowTaskNode<P, V, NM>, V, NM, E>;
|
|
223
223
|
}
|
|
224
224
|
/**
|
|
@@ -655,11 +655,11 @@ declare function useEngineInstance<T, P extends MeshPath, S = any, M extends Rec
|
|
|
655
655
|
on: (event: MeshEventName, cb: Function) => () => boolean | undefined;
|
|
656
656
|
}) => void;
|
|
657
657
|
}) => () => void;
|
|
658
|
-
SetValue: (path: P, key:
|
|
658
|
+
SetValue: (path: P, key: SuggestKey<NM>, value: any) => void;
|
|
659
659
|
GetValue: (path: P, key?: string) => any;
|
|
660
660
|
SetValues: (updates: {
|
|
661
661
|
path: P;
|
|
662
|
-
key:
|
|
662
|
+
key: SuggestKey<NM>;
|
|
663
663
|
value: any;
|
|
664
664
|
}[]) => void;
|
|
665
665
|
GetGroupByPath: (path: MeshPath) => MeshFlowGroupNode<MeshPath>;
|
|
@@ -692,7 +692,7 @@ declare function useEngineInstance<T, P extends MeshPath, S = any, M extends Rec
|
|
|
692
692
|
notifyAll: () => Promise<void>;
|
|
693
693
|
batchNotify: (updates: {
|
|
694
694
|
path: P;
|
|
695
|
-
key:
|
|
695
|
+
key: SuggestKey<NM>;
|
|
696
696
|
value: any;
|
|
697
697
|
}[]) => void;
|
|
698
698
|
useEntangle: (config: EntangleArgType<P>) => void;
|
|
@@ -700,11 +700,13 @@ declare function useEngineInstance<T, P extends MeshPath, S = any, M extends Rec
|
|
|
700
700
|
SetBucket: (newBucket: SchemaBucket<P>) => number;
|
|
701
701
|
GetBucket: (bucketId: number) => SchemaBucket<P>;
|
|
702
702
|
CancelTask: () => void;
|
|
703
|
+
stageValueFn: (uid: number, key: SuggestKey<NM>, value: any) => void;
|
|
703
704
|
UITrigger: any;
|
|
704
705
|
UidToNodeMap: MeshFlowTaskNode<P, any, NM>[];
|
|
705
706
|
};
|
|
706
707
|
destroyPlugin: () => void;
|
|
707
708
|
CancelTask: () => void;
|
|
709
|
+
StageValue: (path: P, key: SuggestKey<NM>, value: any) => void;
|
|
708
710
|
};
|
|
709
711
|
|
|
710
712
|
/**
|
|
@@ -741,7 +743,7 @@ B extends Record<string, any> = StandardUITrigger<T>, NM = any>(config: {
|
|
|
741
743
|
notifyAll: () => Promise<void>;
|
|
742
744
|
batchNotify: (updates: {
|
|
743
745
|
path: P;
|
|
744
|
-
key:
|
|
746
|
+
key: SuggestKey<NM>;
|
|
745
747
|
value: any;
|
|
746
748
|
}[]) => void;
|
|
747
749
|
useEntangle: (config: EntangleArgType<P>) => void;
|
|
@@ -749,6 +751,7 @@ B extends Record<string, any> = StandardUITrigger<T>, NM = any>(config: {
|
|
|
749
751
|
SetBucket: (newBucket: SchemaBucket<P>) => number;
|
|
750
752
|
GetBucket: (bucketId: number) => SchemaBucket<P>;
|
|
751
753
|
CancelTask: () => void;
|
|
754
|
+
stageValueFn: (uid: number, key: SuggestKey<NM>, value: any) => void;
|
|
752
755
|
UITrigger: B;
|
|
753
756
|
UidToNodeMap: MeshFlowTaskNode<P, any, NM>[];
|
|
754
757
|
};
|
|
@@ -774,6 +777,9 @@ type BaseEngine<T> = {
|
|
|
774
777
|
GetGroupByPath: T extends {
|
|
775
778
|
GetGroupByPath: infer F;
|
|
776
779
|
} ? F : never;
|
|
780
|
+
StageValue: T extends {
|
|
781
|
+
StageValue: infer F;
|
|
782
|
+
} ? F : never;
|
|
777
783
|
};
|
|
778
784
|
config: {
|
|
779
785
|
SetRule: T extends {
|
|
@@ -888,11 +894,11 @@ M extends Record<string, any>, NM extends Record<string, any> = IsNever<Normaliz
|
|
|
888
894
|
on: (event: MeshEventName, cb: Function) => () => boolean | undefined;
|
|
889
895
|
}) => void;
|
|
890
896
|
}) => () => void;
|
|
891
|
-
SetValue: (path: P, key:
|
|
897
|
+
SetValue: (path: P, key: SuggestKey<NM>, value: any) => void;
|
|
892
898
|
GetValue: (path: P, key?: string) => any;
|
|
893
899
|
SetValues: (updates: {
|
|
894
900
|
path: P;
|
|
895
|
-
key:
|
|
901
|
+
key: SuggestKey<NM>;
|
|
896
902
|
value: any;
|
|
897
903
|
}[]) => void;
|
|
898
904
|
GetGroupByPath: (path: MeshPath) => MeshFlowGroupNode<MeshPath>;
|
|
@@ -925,7 +931,7 @@ M extends Record<string, any>, NM extends Record<string, any> = IsNever<Normaliz
|
|
|
925
931
|
notifyAll: () => Promise<void>;
|
|
926
932
|
batchNotify: (updates: {
|
|
927
933
|
path: P;
|
|
928
|
-
key:
|
|
934
|
+
key: SuggestKey<NM>;
|
|
929
935
|
value: any;
|
|
930
936
|
}[]) => void;
|
|
931
937
|
useEntangle: (config: EntangleArgType<P>) => void;
|
|
@@ -933,11 +939,13 @@ M extends Record<string, any>, NM extends Record<string, any> = IsNever<Normaliz
|
|
|
933
939
|
SetBucket: (newBucket: SchemaBucket<P>) => number;
|
|
934
940
|
GetBucket: (bucketId: number) => SchemaBucket<P>;
|
|
935
941
|
CancelTask: () => void;
|
|
942
|
+
stageValueFn: (uid: number, key: SuggestKey<NM>, value: any) => void;
|
|
936
943
|
UITrigger: any;
|
|
937
944
|
UidToNodeMap: MeshFlowTaskNode<P, any, NM>[];
|
|
938
945
|
};
|
|
939
946
|
destroyPlugin: () => void;
|
|
940
947
|
CancelTask: () => void;
|
|
948
|
+
StageValue: (path: P, key: SuggestKey<NM>, value: any) => void;
|
|
941
949
|
}, M, P>;
|
|
942
950
|
/**
|
|
943
951
|
* 类型工厂:锁定全局路径与元数据类型,生成定制化的实例化函数。
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var Fe=(S=>(S[S.FlowStart=0]="FlowStart",S[S.FlowSuccess=1]="FlowSuccess",S[S.FlowEnd=2]="FlowEnd",S[S.FlowAbort=3]="FlowAbort",S[S.FlowWait=4]="FlowWait",S[S.FlowFire=5]="FlowFire",S[S.NodeStart=6]="NodeStart",S[S.NodeSuccess=7]="NodeSuccess",S[S.NodeProcessing=8]="NodeProcessing",S[S.NodeError=9]="NodeError",S[S.NodePending=10]="NodePending",S[S.NodeRevive=11]="NodeRevive",S[S.NodeIntercept=12]="NodeIntercept",S[S.NodeRelease=13]="NodeRelease",S[S.NodeStagnate=14]="NodeStagnate",S[S.NodeBucketSuccess=15]="NodeBucketSuccess",S[S.EntangleWarn=16]="EntangleWarn",S[S.EntangleBlocked=17]="EntangleBlocked",S))(Fe||{}),Ue=(r=>(r[r.CAUSALITY=0]="CAUSALITY",r[r.INVERSION=1]="INVERSION",r[r.REPERCUSSION=2]="REPERCUSSION",r))(Ue||{});var Ve=(r=>(r.OR="OR",r.PRIORITY="PRIORITY",r.MERGE="MERGE",r))(Ve||{});var Le=class{computedRules=[];getRuleResult(e,t,r){if(e.entityId==="__base__")return e.logic(t);if(!(!e._hasRun||r(e.triggerUids)))return e._lastResult;let i=e.logic(t);return i instanceof Promise?i.then(l=>(e._lastResult=l,e._hasRun=true,l)):(e._lastResult=i,e._hasRun=true,i)}store={OR:(e,t,r)=>{let o,i,l=this.computedRules;for(let s=0;s<l.length;s++){let a=l[s],p=this.getRuleResult(a,e,r);if(p instanceof Promise)return (async()=>{let n=await p;if(a.entityId==="__base__"?i=n:n&&(o=n),typeof o>"u")for(let T=s+1;T<l.length;T++){let f=l[T],m=this.getRuleResult(f,e,r),N=m instanceof Promise?await m:m;if(f.entityId==="__base__"){i=N;continue}if(N){o=f.value;break}}return typeof o>"u"&&(o=i),{res:o,version:t}})();let h=p;if(a.entityId==="__base__"){i=h;continue}if(h){o=a.value;break}}return typeof o>"u"&&(o=i),{res:o,version:t}},PRIORITY:(e,t,r)=>{let o,i=this.computedRules;for(let l=0;l<i.length;l++){let s=i[l],a=this.getRuleResult(s,e,r);if(a instanceof Promise)return (async()=>{let p=await a;if(p!==void 0)return {res:s.value!==void 0?s.value:p,version:t};for(let h=l+1;h<i.length;h++){let n=i[h],T=this.getRuleResult(n,e,r),f=T instanceof Promise?await T:T;if(f!==void 0)return {res:f,version:t}}return {res:void 0,version:t}})();if(a!==void 0)return {res:s.value!==void 0?s.value:a,version:t}}return {res:o,version:t}},MERGE:(e,t,r)=>{let o,i,l=this.computedRules,s=(p,h)=>p===void 0?h:h===void 0?p:Array.isArray(p)&&Array.isArray(h)?[...h,...p]:typeof p=="object"&&typeof h=="object"?{...h,...p}:p;for(let p=0;p<l.length;p++){let h=l[p],n=this.getRuleResult(h,e,r);if(n instanceof Promise)return (async()=>{let f=await n,m=(M,b)=>{if(M.entityId==="__base__")i=s(i,b);else if(b){let S=M.value!==void 0?M.value:b;o=s(o,S);}};m(h,f);for(let M=p+1;M<l.length;M++){let b=l[M],S=this.getRuleResult(b,e,r),ne=S instanceof Promise?await S:S;m(b,ne);}return {res:s(o,i),version:t}})();let T=n;if(h.entityId==="__base__"){i=s(i,T);continue}if(T){let f=h.value!==void 0?h.value:T;o=s(o,f);}}return {res:s(o,i),version:t}}};CurrentStrategy=()=>{};CurrentStrategyType="PRIORITY";getRules=()=>{};constructor(e){this.getRules=e,this.CurrentStrategy=this.store.PRIORITY,this.updateComputedRules();}updateComputedRules(){let e=this.getRules();this.CurrentStrategyType==="PRIORITY"||this.CurrentStrategyType==="MERGE"?this.computedRules=Array.from(e.values()).map(t=>Array.from(t)).flat().sort((t,r)=>r.priority-t.priority):this.computedRules=Array.from(e.values()).map(t=>Array.from(t)).flat();}setStrategy(e){this.CurrentStrategyType=e,this.CurrentStrategy=this.store[e],this.updateComputedRules();}evaluate(e,t,r){return this.CurrentStrategy(e,t,r)}},Ae=class{path;strategy;contract;rules=new Map;isValue=false;id=0;cache=void 0;pendingPromise=null;version=0;deps=new Map;_forceNotify=false;promiseToken=null;useCache=true;effectArray=[];constructor(e,t,r){let o=()=>this.rules;this.strategy=new Le(o),this.path=r,this.isValue=t==="value",this.contract=this.inferType(e),this.cache=e,this.setRule({priority:0,entityId:"__base__",logic:()=>e});}setUseCache(e){this.useCache=e;}forceNotify(){this._forceNotify=true;}isForceNotify(){return this._forceNotify}setStrategy(e){this.strategy.setStrategy(e);}setDefaultRule(e){let t=new Set;t.add(e),this.rules.set(-1,t);}setRules(e,t){t&&this.updateDeps(t);let r=++this.id,o={...e,entityId:r};for(let i of e.triggerUids)this.rules.has(i)||this.rules.set(i,new Set),this.rules.get(i).add(o);return this.strategy.updateComputedRules(),()=>{for(let i of e.triggerUids){let l=this.rules.get(i);l&&(l.delete(o),l.size===0&&(this.rules.delete(i),this.deps.delete(i)));}this.strategy.updateComputedRules();}}updateDeps(e){for(let[t,r,o]of e){if(r.length==0)continue;let i=this.deps.get(t)||Object.create(null);for(let l of r)i[l]=o[l];this.deps.set(t,i);}}setRule(e,t){if(t&&this.updateDeps(t),typeof e.entityId=="string"){this.setDefaultRule(e);return}let r=++this.id,o={...e,entityId:r};if(e)for(let i of e.triggerUids)this.rules.has(i)||this.rules.set(i,new Set),this.rules.get(i).add(o);return this.strategy.updateComputedRules(),()=>{for(let i of e.triggerUids){let l=this.rules.get(i);l&&(l.delete(o),l.size===0&&(this.rules.delete(i),this.deps.delete(i)));}this.strategy.updateComputedRules();}}setSideEffect(e){this.effectArray.push(e);}getSideEffect(){return [...this.effectArray]}evaluate(e){let t=null;if(e.GetToken&&(t=e.GetToken()),this.pendingPromise&&this.promiseToken!==t&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;let r=false;if(typeof e.triggerUid=="number"){r=true,this.deps.size==0&&(r=false);for(let[s,a]of this.deps.entries()){let p=e.getStateByUid(s);if(!p){r=false;break}for(let h in a){let n=a[h],T=p[h];if(typeof n=="object"&&n!==null){r=false;break}if(n!==T){r=false;break}}if(!r)break}}if(r&&this.useCache)return this.cache;this.promiseToken=t;let o=++this.version,i=s=>{if(!s||s.length===0)return true;for(let a of s){let p=this.deps.get(a);if(!p)return true;let h=e.getProxyByUid(a);if(!h)return true;for(let n in p){let T=p[n],f=h[n];if(typeof T=="object"&&T!==null||T!==f)return true}}return false},l=this.strategy.evaluate(e,o,i);if(!(l instanceof Promise)){let{res:s,version:a}=l;return this.finalizeSync(s,a,e,t)}return this.pendingPromise=(async()=>{try{let{res:s,version:a}=await l;return this.finalizeSync(s,a,e,t)}catch(s){throw {path:this.path,error:s}}finally{this.promiseToken===t&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}finalizeSync(e,t,r,o){return o!==this.promiseToken||t<this.version?this.cache:(this.cache=e,this.deps.forEach((i,l)=>{let s=r.getProxyByUid(l);if(!s)return;let a=Object.keys(i);for(let p of a)i[p]=s[p];}),e)}inferType(e){return Array.isArray(e)?"array":typeof e}};var We=(g,e,t)=>{let o=i=>{let l=t.triggerUids.map(p=>{let h=i.getProxyByUid(p);if(t.triggerKeys.length===0)return h;let n={};return t.triggerKeys.forEach(T=>{n[T]=h[T];}),n}),s=Object.create(null);return Object.defineProperty(s,"triggerTargets",{get:()=>l}),Object.defineProperty(s,"affectedTatget",{get:()=>i.getProxyByUid(g)[e]}),t.logic({slot:s})};return {value:t.value,targetUid:g,triggerUids:t.triggerUids,priority:t.priority??10,logic:o}},ze=(g,e,t,r,o,i,l,s)=>{if(!g)throw Error();let a=g,p=(T,f)=>{typeof r[T]>"u"&&(r[T]=[],i[T]=new Set),i[T].add(f),i[T].size>r[T].length&&r[T].push(f),typeof o[f]>"u"&&(o[f]=[],l[f]=new Set),l[f].add(T),l[f].size>o[f].length&&o[f].push(T);};return {SetRule:(T,f,m,N)=>{let M=a(T),b=a(f),S=N.triggerKeys||[],ne=s.get(b.uid)||0,H=s.get(M.uid)||0;ne+=1,H+=1,s.set(b.uid,ne),s.set(M.uid,H);let $=We(b.uid,m,{...N,triggerUids:[M.uid],triggerKeys:S}),Y=[T].map(U=>{let L=a(U);return [L.uid,S,L.proxy]});if(p(M.uid,b.uid),typeof b.nodeBucket[m]=="number"){let U=t(b.nodeBucket[m]);U.setRule($,Y),N.effect&&U.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[m]});}else {let U=b.meta[m],L=new Ae(U,m,f);L.setRule($,Y),N.effect&&L.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[m]}),b.nodeBucket[m]=e(L);}b.state[m]=b.meta[m];let c=t(b.nodeBucket[m]);N.forceNotify&&c.forceNotify(),N.cacheStrategy=="none"&&c.setUseCache(false);},SetRules:(T,f,m,N)=>{let M=a(f),b=s.get(M.uid)||0;b+=1,s.set(M.uid,b);let S=[];for(let c of T){let U=a(c);S.push(U.uid);let L=s.get(U.uid)||0;L+=1,s.set(U.uid,L),p(U.uid,M.uid);}let ne=N.triggerKeys||[],H=We(M.uid,m,{...N,triggerUids:S,triggerKeys:ne}),$=T.map(c=>{let U=a(c);return [U.uid,ne,U.state]});if(typeof M.nodeBucket[m]=="number"){let c=t(M.nodeBucket[m]);c.setRules(H,$),N.effect&&c.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[m]});}else {let c=M.meta[m],U=new Ae(c,m,f);U.setRules(H,$),N.effect&&U.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[m]}),M.nodeBucket[m]=e(U);}M.state[m]=M.meta[m];let Y=t(M.nodeBucket[m]);N.forceNotify&&Y.forceNotify(),N.cacheStrategy=="none"&&Y.setUseCache(false);}}};var qe=(g,e)=>{let t=g||void 0;if(!t)throw Error();return {SetStrategy:(o,i,l)=>{let s=t(o);e(s.nodeBucket[i]).setStrategy(l);}}};function Qe(){let g=new Map,e=new Map,t=new Set,r=(l,s)=>{g.set(l,s);let a=e.get(l);a&&a(s);};return {SetTrace:(l,s)=>{e.set(l,s);let a=g.get(l)||"idle";return s(a),{cancel:()=>{e.delete(l);}}},useTrace:()=>({apply:s=>{s.on(0,()=>{t.forEach(a=>r(a,"idle")),t.clear(),g.clear();}),s.on(13,({path:a,type:p})=>{(p==1||p==2)&&(t.add(a),r(a,"pending"));}),s.on(10,({path:a})=>{t.add(a),(!g.has(a)||g.get(a)==="idle")&&r(a,"pending");}),s.on(6,({path:a})=>{t.add(a),r(a,"calculating");}),s.on(7,({path:a})=>{r(a,"calculated");}),s.on(12,({path:a,type:p})=>{p==3&&r(a,"calculating"),p==6&&r(a,"idle");}),s.on(14,({path:a})=>{r(a,"pending");}),s.on(9,({path:a})=>r(a,"error"));}})}}function Xe(g,e,t,r){return {GetNextDependency:h=>r()[h]||[],GetPrevDependency:h=>t()[h]||[],GetAllPrevDependency:h=>e()[h]||[],GetAllNextDependency:h=>g()[h]||[],rebuildDirectDependencyMaps:h=>{let n=[],T=[],f=g();for(let m of h){let N=f[m]||[];n[m]=N;for(let M=0;M<N.length;M++){let b=N[M];typeof T[b]>"u"&&(T[b]=[]),T[b].push(m);}}return {directNextMap:n,directPrevMap:T}}}}function Ze(g,e){let t=o=>{let i=[],l=[],s=new Map,a=o.size,p=0,h=0;for(let[n,T]of o)T===0&&l.push(n);if(l.length===0&&a>0)throw Error("Circular dependency detected");for(;l.length>0;){i.push([...l]);let n=[];for(let T of l){p++,s.set(T,h);let f=g[T];if(f)for(let m of f){let N=o.get(m)-1;o.set(m,N),N===0&&n.push(m);}}l=n,h++;}if(p<a)throw Error("Circular dependency detected");return {steps:i,levelMap:s}};return ()=>{let o=new Map;for(let i of e.keys()){let l=g[i]||[];o.has(i)||o.set(i,0);for(let s of l){let a=o.get(s)||0;o.set(s,++a);}}return t(o)}}var be=()=>{let g=[];return {on:e=>(g.push(e),()=>{let t=g.indexOf(e);t>-1&&g.splice(t,1);}),call:e=>g.forEach(t=>{t(e);})}};function Je(){let{on:g,call:e}=be();return {onError:g,callOnError:e}}function et(){let{on:g,call:e}=be();return {onSuccess:g,callOnSuccess:e}}var tt=()=>{let g=new Set,e=new Map,t=new Set,r=(s,a)=>{e.get(s)?.forEach(p=>p(a));},o=(s,a)=>(e.has(s)||e.set(s,new Set),e.get(s).add(a),()=>e.get(s)?.delete(a));return {usePlugin:s=>{let a=new Set,p=(n,T)=>{let f=o(n,T);return a.add(f),f};s.apply({on:p}),g.add(s);let h=()=>{a.forEach(n=>n()),a.clear(),g.delete(s),t.delete(h);};return t.add(h),h},emit:r,destroyPlugin:()=>{t.forEach(s=>s()),t.clear(),e.clear(),g.clear();}}};function nt(){let{on:g,call:e}=be();return {onStart:g,callOnStart:e}}var rt=(g={frameQuota:12})=>{let e=performance.now(),t=0,r=false,o=()=>!!navigator?.scheduling?.isInputPending?.({includeContinuous:true});return {getIsFirstFrame:()=>r,reset(){e=performance.now(),t=0,r=true;},shouldYield(){return !r&&(++t&15)!==0?false:!!(performance.now()-e>g.frameQuota||o())},async yieldToMain(){return new Promise(i=>{_e(()=>{e=performance.now(),t=0,r&&(r=false),i();});})}}},_e=g=>{let{port1:e,port2:t}=new MessageChannel;e.onmessage=g,t.postMessage(null);};function st(g,e,t,r,o,i){let l=new Map,s=g.useGreedy,a=null,p=()=>{l.clear();},h={path:null,level:0,targetLevel:0,currentLevel:0,pendingParentsCount:0,active:0,pending:0,blocked:0,nums:0,asyncNums:0},n={path:null,type:0,triggerPath:null,calledBy:0,key:null,value:null,error:null,token:null,duration:null,detail:h};return {TaskRunner:async(f,m)=>{let M=Symbol("token"),b=typeof f=="number"?f:"__NOTIFY_ALL__";l.set(b,M),a=M;let S=false,ne=false;i.reset(),t.Turnstile.nextEpoch();let H=t.GetMaxUid()+3,$=new Array(H).fill(0),Y=0,c=new Uint8Array(H),U=new Int32Array(H),L=new Int32Array(H),d=new Int32Array(H*2),x=0,O=0,k=new Int32Array(H*2),V=0,F=0,v=new Int32Array(H*2),A=0,G=0;m.forEach(R=>{$[R]=1,e.GetAllNextDependency(R).forEach(ae=>{$[ae]=1;});});let _=new Array(H).fill(null),u=[],y=t.Turnstile,P=new Array(H).fill(null).map(()=>[]),W=new Array(H).fill(null).map(()=>[]),q=y.volatileLevels.size>0,re=q?y.hasObserver:R=>false,se=q?y.receiveGhosts:()=>[],Me=q?y.resolveGhosts:()=>[],me=q?y.getTriggerKeys:()=>[],Re=y?.volatileLevels||new Set,ye=-1,ee=e.GetUidToLevelMap(),ie=0,xe=0,Pe=R=>{e.GetAllNextDependency(R).forEach(oe=>{let w=ee.get(oe)||0;w>xe&&(xe=w);});},Ge=new Set;typeof f=="number"&&(c[f]|=16,Ge.add(f),Pe(f),o.flushPathSet.add(f));let we=typeof f=="number"?[f]:m;i.shouldYield()&&(o.requestUpdate(),await i.yieldToMain());let Ie=we.map(async R=>{if(re(R)){let ae=t.GetNodeByUid(R),oe=me(R);if(oe.length>0){let w=se(ae,oe);return w instanceof Promise&&(w=await w),{seed:R,hitTargets:w}}}return {seed:R,hitTargets:[]}});if((await Promise.all(Ie)).forEach(({seed:R,hitTargets:ae})=>{if(ae&&ae.length>0){u.push(...ae);let oe=ee.get(R)||0;ye=Math.max(ye,oe);}}),(u.length>0||we.length>1)&&(o.requestUpdate(),await i.yieldToMain(),l.get(b)!==M))return;let Ce=u.length>0;m.forEach(R=>{if(!Ge.has(R))if(Ce){let ae=ee.get(R)??0;L[R]=ae,c[R]&4||(c[R]|=4,v[A++]=R,G++);let oe=t.GetPathByUid(R);n.path=oe,n.type=2,r.emit(14,n);}else c[R]&1||(c[R]|=1,d[x++]=R,O++),Pe(R);}),typeof f=="number"?ie=ee.get(f)??0:ie=Math.min(...m.map(R=>ee.get(R)??0));let Oe=performance.now(),De=typeof b=="number"?t.GetPathByUid(b):"__NOTIFY_ALL__";n.path=De,n.token=M,r.emit(0,n),r.callOnStart({path:De});let Be=false,Ye=30,je=(R,ae)=>{let oe=false,w=false,j=false,B=t.GetNodeByUid(R),Z=t.GetPathByUid(R),Q=B.calledBy,K=P[R];K.length=0;let C=re(R),I=C?me(R):[],D=E=>{C&&(I.length===0||I.includes(E))&&K.push(E);},le=W[R];le.length=0;let ce=false;if(B.calledBy===1){ce=true,oe=true,o.flushPathSet.add(R);let E=_[R];E&&(K.push(...E),_[R]=null);}let de=(E,J)=>{let te=ee.get(E)??0,pe=t.GetNodeByUid(E),X=t.GetPathByUid(E),he=(Q===1||Q===2)&&te<=ye;he&&c[E]&16&&(c[E]&=-17,n.path=X,n.triggerPath=Z,r.emit(11,n));let ue=0;if(!(c[E]&49)){if(c[E]&2)ue=U[E]-1;else {if(te>ie&&F>Ye){L[E]=te,c[E]&4||(c[E]|=4,v[A++]=E,G++),n.path=X,n.type=7,r.emit(12,n);return}let Se=e.GetPrevDependency(E),z=0;for(let ge of Se){if(c[ge]&16)continue;(ee.get(ge)??0)>ie&&z++;}ue=z;}if(ue<=0){let Se=(c[E]&1)!==0,z=(c[E]&32)!==0;if(Se||z){n.path=X,n.type=z?3:3.1,r.emit(12,n);return}c[E]&2&&(c[E]&=-3,F--),he?pe.calledBy=2:pe.calledBy=0,c[E]&1||(c[E]|=1,d[x++]=E,O++),n.path=X,n.type=J,h.path=Z,r.emit(13,n);}else U[E]=ue,c[E]&2||(c[E]|=2,k[V++]=E,F++);}},Ne=(E=[])=>{if(l.get(b)!==M)return;if(E.length){let te={},pe=B.proxy;for(let X of E){let he=(X.args||[]).reduce((ue,Se)=>(ue[Se]=pe[Se],ue),{});try{let ue=X.fn(he);ue&&typeof ue=="object"&&Object.assign(te,ue);}catch(ue){}}for(let X in te)if(X in B.state)Object.is(B.state[X],te[X])||(B.state[X]=te[X],D(X),oe=true,(B.notifyKeys.size===0||B.notifyKeys.has(X))&&(w=true));else throw {error:`wrong effect in ${String(B.path)}`}}oe&&o.flushPathSet.add(R);let J=(te=[])=>{if(l.get(b)!==M)return;te&&te.length>0&&(u.push(...te),ye=Math.max(ye,ee.get(R)||0)),K.length=0,n.path=Z,n.calledBy=B.calledBy,r.emit(7,n),c[R]|=16;let pe=e.GetNextDependency(R);(w||j)&&(Pe(R),e.GetAllNextDependency(R).forEach(ge=>{$[ge]=1;}));let X=t.GetNodeByUid(R),he=ee.get(R)??0,ue=Re.has(he)||u.length>0;for(let z of pe){let ge=ee.get(z)??0,Te=t.GetPathByUid(z);if(ue&&ge>=he){L[z]=ge,c[z]&4||(c[z]|=4,v[A++]=z,G++),n.path=Te,n.type=2,r.emit(14,n);continue}if(c[z]&16){n.path=Te,n.type=2,r.emit(12,n);continue}if(c[z]&32||(c[z]&1)!==0){n.path=Te,n.type=c[z]&32?3:3.1,r.emit(12,n);continue}if(w||j)de(z,1);else if(c[z]&2)de(z,2);else {let lt=ee.get(z);L[z]=lt,c[z]&4||(c[z]|=4,v[A++]=z,G++,n.path=Te,n.type=1,r.emit(14,n));}}c[R]&32&&(c[R]&=-33,Y--),X.calledBy=0,(()=>{if(!S){S=true;let z=Y,ge=O,Te=F;n.path=Z,n.type=1,h.active=z,h.pending=ge,h.blocked=Te,r.emit(5,n),Ke();}})();};if(re(R)&&K.length>0){let te=se(B,K);te instanceof Promise?te.then(J).catch(ke):J(te);}else J([]);},ke=E=>{n.path=Z,n.error=E,r.emit(9,n);let J=Symbol("abort");l.set(b,J),x=0,O=0,V=0,F=0,A=0,G=0,c.fill(0),Y=0,_.fill(null),r.callOnError(E);},fe=(E,J)=>{E!==B.state[J]&&(B.state[J]=E,oe=true,D(String(J)),n.path=Z,n.key=J,n.value=E,n.calledBy=B.calledBy,r.emit(15,n),(B.notifyKeys.size===0||B.notifyKeys.has(J))&&(w=true)),t.GetBucket(B.nodeBucket[J]).isForceNotify()&&(j=true),(w||j)&&Pe(R);};n.path=Z,n.calledBy=B.calledBy,r.emit(6,n);try{let E=[];for(let J in B.nodeBucket){let te=t.GetBucket(B.nodeBucket[J]);if(E.push(...te.getSideEffect()),ce){r.emit(15,{path:Z,key:String(J),value:B.state[J],calledBy:B.calledBy}),te.isForceNotify()&&(j=!0),(B.notifyKeys.size===0||B.notifyKeys.has(J))&&Pe(R);continue}let pe=te.evaluate({affectKey:J,triggerUid:ae,getProxyByUid:X=>t.GetNodeByUid(X).proxy,getStateByUid:X=>t.GetNodeByUid(X).state,GetToken:()=>M});if(pe instanceof Promise){let X=pe.then(he=>{l.get(b)===M&&fe(he,J);});le.push(X);}else fe(pe,J);}if(le.length>0)return Promise.all(le).then(()=>{Ne(E);}).catch(ke);Ne(E);return}catch(E){ke(E);}},Ke=async()=>{if(l.get(b)!==M){S=false;return}S=true;let R=i.getIsFirstFrame(),ae=0,oe=()=>30,w=0,j=oe();try{for(;l.get(b)===M;){let B=w>=j,Z=i.shouldYield();if(B||Z){if(w>0&&(ae++,(R||ae%2===0)&&o.requestUpdate()),await i.yieldToMain(),l.get(b)!==M)break;w=0,R=i.getIsFirstFrame();}if(O>0&&Y<40){let Q=x,K=0;for(let C=0;C<Q;C++){let I=d[C];if((c[I]&1)===0)continue;if(Y>=40||w>=j||i.shouldYield()){for(let fe=C;fe<x;fe++){let E=d[fe];c[E]&1&&(d[K++]=E);}x=K,O=K;break}let D=t.GetNodeByUid(I),le=t.GetPathByUid(I),ce=ee.get(I)??0,de=e.GetPrevDependency(I),Ne=de.length>1;if((!s||Ne)&&ce>ie){c[I]&=-2,O--;let fe=de.filter(E=>$[E]===1&&(c[E]&16)===0).length;U[I]=fe||0,c[I]&2||(c[I]|=2,k[V++]=I,F++),n.path=le,n.type=fe>0?4:5,h.targetLevel=ce,h.currentLevel=ie,h.pendingParentsCount=fe,r.emit(12,n);continue}c[I]&=-2,O--,(c[I]&32)===0&&(c[I]|=32,Y++),n.path=le,n.calledBy=D.calledBy,r.emit(8,n),je(I,f),w++;}if(x>Q){for(let C=Q;C<x;C++){let I=d[C];c[I]&1&&(d[K++]=I);}x=K,O=x;}else x=K;if(O>0&&Y<40)continue}if(w<j&&s&&F>0&&Y<40){let Q=!1,K=0,C=0;for(let I=0;I<V;I++){let D=k[I];if((c[D]&2)===0)continue;if(U[D]<=0&&K<j){let ce=ee.get(D)??0,de=e.GetPrevDependency(D);if(ce<=ie||de.length<=1){c[D]&=-3,F--,c[D]&1||(c[D]|=1,d[x++]=D,O++),K++,Q=!0;let Ne=t.GetPathByUid(D);n.path=Ne,n.type=4,r.emit(13,n);continue}}k[C++]=D;}if(V=C,K>0)continue;if(Q){if(i.shouldYield()&&(await i.yieldToMain(),l.get(b)!==M))break;continue}}if(Y===0&&O===0){if(y.inFlightCount>0)break;if(u.length>0){let K=!1,C=ie,I=Array.from(new Set(u));u.length=0;for(let D of I){let le=t.GetNodeByUid(D),ce=Me(le);if(ce&&ce.length>0){K=!0,le.calledBy=1,_[D]=ce,c[D]&=-17,c[D]&2&&(c[D]&=-3,F--),c[D]&1||(c[D]|=1,d[x++]=D,O++);let de=ee.get(le.uid)??0;de<C&&(C=de),Pe(le.uid),o.flushPathSet.add(le.uid);}}if(K){if(C<ie&&(ie=C),o.requestUpdate(),i.shouldYield()&&(await i.yieldToMain(),l.get(b)!==M))break;continue}}let Q=1/0;for(let K=0;K<A;K++){let C=v[K];if(c[C]&4){let I=L[C];I<Q&&(Q=I);}}for(let K=0;K<V;K++){let C=k[K];if(c[C]&2){let I=ee.get(C)??0;I>ie&&I<Q&&(Q=I);}}if(Q!==1/0&&Q<=xe){ie=Q;let K=0;for(let I=0;I<A;I++){let D=v[I];c[D]&4&&(L[D]===Q?(c[D]&=-5,G--,c[D]&1||(c[D]|=1,d[x++]=D,O++)):v[K++]=D);}A=K;let C=0;for(let I=0;I<V;I++){let D=k[I];if(c[D]&2)if((ee.get(D)??0)===Q){c[D]&=-3,F--,c[D]&1||(c[D]|=1,d[x++]=D,O++);let ce=t.GetPathByUid(D);n.path=ce,n.type=3,h.level=Q,r.emit(13,n);}else k[C++]=D;}V=C;continue}else {for(let K=0;K<A;K++){let C=v[K];if(c[C]&4){c[C]|=16;let I=t.GetPathByUid(C);n.path=I,n.type=6,r.emit(12,n);}}A=0,G=0;for(let K=0;K<V;K++){let C=k[K];if(c[C]&2){c[C]|=16;let I=t.GetPathByUid(C);n.path=I,n.type=6,r.emit(12,n);}}V=0,F=0;break}}O>0&&Y>=40&&(n.type=2,r.emit(4,n));break}}finally{S=false;let B=Y+F+O,Z=y.inFlightCount||0;if(!(a===M)){n.token=M,r.emit(3,n);return}if(o.requestUpdate(),B===0&&Z===0){if(l.get(b)===M&&!Be){Be=true,n.type=1,r.emit(2,n),y.resetCounters(),_.fill(null);let K=performance.now();ye=-1,l.delete(b),n.token=M,n.duration=(K-Oe).toFixed(2.1)+"ms",r.emit(1,n),Promise.resolve().then(()=>{r.callOnSuccess();});}}else {let K=B===0&&Z>0?3:1;if(n.type=K,h.nums=Y,h.asyncNums=Z,r.emit(4,n),Z>0&&!ne){ne=true;let C=()=>{a===M&&(y.inFlightCount,y.inFlightCount===0?_e(()=>{y.inFlightCount===0?Ke():requestAnimationFrame(C);}):requestAnimationFrame(C));};requestAnimationFrame(C);}}}};Ke();},CancelTask:p}}function He(g){let{path:e,uid:t,type:r,meta:o,dirtySignal:i,state:l}=g,s=null,a=["path","uid","type","dependOn","nodeBucket"],h={path:e,uid:t,type:r,meta:o,dirtySignal:i,createView:(n={})=>{if(s&&Object.keys(n).length===0)return s;let T=new Proxy(n,{get(f,m){let N=m;return Reflect.has(f,m)?Reflect.get(f,m):N in g.state?g.state[N]:N in g?g[N]:o&&N in o?o[N]:Reflect.get(f,m)},set(f,m,N){return false},ownKeys(f){let m=new Set([...Reflect.ownKeys(f),...Object.keys(l||{}),...Object.keys(o||{}),...a]);return Array.from(m)},getOwnPropertyDescriptor(f,m){let N=m;return Reflect.has(f,m)||l&&N in l||o&&N in o||a.includes(N)?{enumerable:true,configurable:true}:Reflect.getOwnPropertyDescriptor(f,m)}});return s=T,T}};return "children"in g?{...h,children:g.children}:{...h,state:g.state,nodeBucket:g.nodeBucket,notifyKeys:g.notifyKeys,dependOn:g.dependOn,calledBy:0,get proxy(){return s}}}var at=(g,e,t,r,o,i,l)=>{let s=g.useEntangleStep,a=[],p=[],h=new Set,n=r,m=t,N=0,M=0,b=0,S=100,ne=()=>{let d={link:null,impactNode:null,impactUid:-1,hitTargetUids:null,isDirty:false,propose:null};return d.propose={set:(x,O,k=1)=>{d.epoch===b&&O!==d.impactNode.state[x]&&(d.link.count++,(!p[d.impactUid]||p[d.impactUid].length===0)&&(p[d.impactUid]=[],M++),p[d.impactUid].push({key:x,value:O,weight:k}),d.isDirty||(d.hitTargetUids.push(d.impactUid),d.isDirty=true));},update:(x,O,k="add")=>{d.epoch===b&&(d.link.count++,(!p[d.impactUid]||p[d.impactUid].length===0)&&(p[d.impactUid]=[],M++),p[d.impactUid].push({key:x,delta:O,op:k,weight:1}),d.isDirty||(d.hitTargetUids.push(d.impactUid),d.isDirty=true));},patch:(x,O)=>{d.epoch===b&&(d.link.count++,(!p[d.impactUid]||p[d.impactUid].length===0)&&(p[d.impactUid]=[],M++),p[d.impactUid].push({key:x,patch:O,weight:1}),d.isDirty||(d.hitTargetUids.push(d.impactUid),d.isDirty=true));}},d},H=Array.from({length:S},ne),$=S-1,Y=(d,x,O)=>{let k=x.path,V=d.impact;if(d.count>=s){l.emit("entangle:blocked",{observer:k,target:V,count:d.count});return}let F=n(V),v=d.isProxy?x.proxy:x,A=d.isProxy?F.proxy:F;if(d.filter&&!d.filter(v,A))return;let G,_=true;$<0?(G=ne(),_=false):G=H[$--];let u=b;G.epoch=u,G.isDirty=false,G.link=d,G.impactNode=F,G.impactUid=F.uid,G.hitTargetUids=O;let y=d.emit(v,A,G.propose);if(y instanceof Promise||y&&typeof y.then=="function")return N++,(async()=>{try{await y;}catch(P){l.emit("node:error",{path:k,error:P}),l.onError({path:k,error:P});}finally{u===b&&N--,_&&(H[++$]=G);}})();_&&(H[++$]=G);};return {useEntangle:d=>{let{cause:x,impact:O,via:k,emit:V,filter:F,isProxy:v}=d;if(!k||k.length===0){l.emit("entangle:warn",{path:x,type:"no_keys"});return}let G=n(x).uid;a[G]||(a[G]=new Map);let _=a[G];for(let u=0;u<k.length;u++){let y=k[u];_.has(y)||_.set(y,[]),_.get(y).push({impact:O,emit:V,filter:F,count:0,isProxy:!!v});}},updateEntangleLevel:()=>{let d=m();h.clear();for(let x=0;x<a.length;x++)if(a[x]!==void 0){let O=d.get(x)||0;h.add(O);}},Turnstile:{volatileLevels:h,get inFlightCount(){return N},get hasPendingGhosts(){return M>0},nextEpoch:()=>{b++,N=0,M=0,p.length=0;},hasObserver:d=>a[d]!==void 0,getTriggerKeys:d=>{let x=a[d];return x?Array.from(x.keys()):[]},receiveGhosts:(d,x=[])=>{let O=d.uid,k=[],V=a[O];if(!V||x.length===0)return k;let F=[];for(let u=0;u<x.length;u++){let y=V.get(x[u]);if(y)for(let P=0;P<y.length;P++)F.push(y[P]);}let v=0,A=false,G=null;for(;v<F.length;v++){if(e.shouldYield()){A=true;break}let u=Y(F[v],d,k);if(u){G=u,A=true,v++;break}}let _=()=>{if(k.length<=1)return k;let u=[],y=Object.create(null);for(let P=0;P<k.length;P++){let W=k[P];y[W]||(y[W]=true,u.push(W));}return u};return A?(async()=>{for(G&&await G,e.shouldYield()&&await e.yieldToMain();v<F.length;){let u=[],y=Math.min(v+S,F.length);for(;v<y;v++){let P=Y(F[v],d,k);P&&u.push(P);}u.length>0&&await Promise.all(u.map(async P=>{await P,e.shouldYield()&&await e.yieldToMain();})),e.shouldYield()&&await e.yieldToMain();}return _()})():_()},resolveGhosts:d=>{let x=d.uid,O=p[x];if(!O||O.length===0)return [];let k=[],V=Object.create(null);for(let F=0;F<O.length;F++){let v=O[F];V[v.key]||(V[v.key]=[]),V[v.key].push(v);}for(let F in V){let v=V[F],A=d.state[F],G,_=-1/0,u=false;for(let y=0;y<v.length;y++){let P=v[y];if(P.patch!==void 0&&(A=P.patch(A)),P.value!==void 0){let W=P.weight??1;W>=_&&(_=W,G=P.value,u=true);}}u&&(A=G);for(let y=0;y<v.length;y++){let P=v[y];if(P.delta!==void 0)switch(P.op||"add"){case "add":A=(typeof A=="number"?A:0)+P.delta;break;case "remove":A=Array.isArray(A)?A.filter(q=>q!==P.delta):A;break;case "intersect":A=Array.isArray(A)?A.filter(q=>P.delta.includes(q)):P.delta;break;case "union":{let q=Array.isArray(A)?A:[],re=Array.isArray(P.delta)?P.delta:[P.delta];A=[...new Set([...q,...re])];break}case "merge":{let q=typeof A=="object"&&A!==null&&!Array.isArray(A)?A:{},re=typeof P.delta=="object"&&P.delta!==null&&!Array.isArray(P.delta)?P.delta:{};A={...q,...re};break}}}Object.is(d.state[F],A)||(d.state[F]=A,k.push(F));}return p[x]=[],M--,k.length>0?k:[]},resetCounters:()=>{for(let d=0;d<a.length;d++){let x=a[d];if(x)for(let O of x.values())for(let k=0;k<O.length;k++)O[k].count=0;}}}}};function ot(g,e,t,r,o){let i=rt(),l=0,s=new Map,a=[],p=[],h=[],n=[],T=false,f=new Set,N=async()=>{let u=Array.from(f);if(f.clear(),"signalTrigger"in o&&typeof o.signalTrigger=="function")for(let y of u){let P=d(y);o.signalTrigger(P.dirtySignal);}else "emit"in o&&o.emit(u);},M=()=>{T||(T=true,requestAnimationFrame(()=>{try{for(;f.size>0;)N();}finally{T=false;}}));},{useEntangle:b,updateEntangleLevel:S,Turnstile:ne}=at({useEntangleStep:g.useEntangleStep},i,e.GetUidToLevelMap,L,d,x,{emit:r.emit,onError:r.callOnError}),{TaskRunner:H,CancelTask:$}=st({useGreedy:g.useGreedy},e,{GetNodeByPath:L,GetNodeByUid:d,GetPathByUid:x,GetBucket:V,GetMaxUid:F,Turnstile:ne},r,{requestUpdate:M,flushPathSet:f},i),Y=u=>{throw new Error(`[MeshFlow] Duplicate Path: ${u}`)},c=u=>{s.has(u.path)&&Y(String(u.path));let y=++l,P={path:u.path,getNode:re=>L(re)},W=(re,se="value")=>{let Me=re({...P}),me=L(u.path);if(!Object.is(me.state[se],Me)){if(t.createHistoryAction&&t.pushIntoHistory){let Re=t.createHistoryAction([{path:u.path,value:me.state[se]},{path:u.path,value:Me}],ye=>{let ee=L(ye.path);ee.state[se]=ye.value,v(ye.path);});t.pushIntoHistory(Re);}me.state[se]=Me,v(u.path);}},q=He({uid:y,type:u.type,path:u.path,state:u.state,meta:u.meta,nodeBucket:{},dirtySignal:"signalCreator"in o?o.signalCreator():void 0,notifyKeys:u.notifyKeys,dependOn:W});return s.set(q.path,y),h[y]=q.path,a[y]=q,q},U=u=>{s.has(u.path)&&Y(String(u.path));let y=++l,P=He({uid:y,type:u.type,path:u.path,state:{},meta:u,nodeBucket:{},children:u.children});return s.set(P.path,y),p[y]=P,P};function L(u){let y=s.get(u),P=a[y];if(!P)throw Error("Wrong id");return P}function d(u){let y=a[u];if(!y)throw Error("Wrong id");return y}function x(u){return h[u]}function O(u){let y=s.get(u);return p[y]}function k(u){return n.push(u)-1}function V(u){let y=n[u];if(!y)throw Error("Wrong id");return y}function F(){return l}let v=u=>{let y=L(u);if(!y)throw Error("Wrong id");f.add(y.uid),M();let P=e.GetNextDependency(y.uid);A(y.uid,P);};function A(u,y){H(u,y);}return {registerNode:c,registerGroupNode:U,GetNodeByPath:L,GetGroupByPath:O,notify:v,notifyAll:async()=>{Promise.resolve().then(async()=>{let u=e.GetDependencyOrder();if(!u||u.length===0)return;let y=u[0];try{H(null,y);}catch(P){throw r.callOnError(P),P}finally{M();}});},batchNotify:u=>{if(!u||u.length===0)return;if(t.createHistoryAction&&t.pushIntoHistory){let P=t.createHistoryAction([u.map(W=>({path:W.path,key:W.key,value:L(W.path).state[W.key]})),u.map(W=>({path:W.path,key:W.key,value:W.value}))],W=>{let q=new Set;W.forEach(re=>{let se=L(re.path);se.state[re.key]=re.value,f.add(re.path),q.add(re.uid);}),M(),q.size>0&&H(null,Array.from(q));});t.pushIntoHistory(P);}let y=new Set;u.forEach(P=>{let W=L(P.path);W.state[P.key]=P.value,f.add(W.uid),y.add(W.uid);}),M(),y.size>0&&H(null,Array.from(y));},useEntangle:b,updateEntangleLevel:S,SetBucket:k,GetBucket:V,CancelTask:$,UITrigger:o,UidToNodeMap:a}}function it(g,e){let t=false,r=false,o=false,i=false,l=new Map,s=[],a=[],p=[],h=[],n=[],T=[],f=[],m=new Map,{GetNextDependency:M,GetPrevDependency:b,GetAllPrevDependency:S,GetAllNextDependency:ne,rebuildDirectDependencyMaps:H}=Xe(()=>s,()=>p,()=>T,()=>n),$={},Y={};if(e.modules.useHistory){let w=e.modules.useHistory,j;w.isMeshModuleInited?j=w:j=w();let{Undo:B,Redo:Z,PushIntoHistory:Q,CreateHistoryAction:K,updateUndoSize:C,updateRedoSize:I}=j();$.pushIntoHistory=Q,$.createHistoryAction=K,Y={Undo:B,Redo:Z,updateUndoSize:C,updateRedoSize:I};}let c=!!e.modules.useMeshRenderGate,U={};if(c){let w=e.modules.useMeshRenderGate.isMeshModuleInited,j=e.modules.useMeshRenderGate;U=(w?j:j())(()=>se);}let{onError:L,callOnError:d}=Je(),{onSuccess:x,callOnSuccess:O}=et(),{onStart:k,callOnStart:V}=nt(),{emit:F,usePlugin:v,destroyPlugin:A}=tt(),{SetTrace:G,useTrace:_}=Qe(),u=_();v(u);let y=c?{...U}:{...e.UITrigger},P=ot({useGreedy:e.config.useGreedy,useEntangleStep:e.config.useEntangleStep||100},{GetDependencyOrder:()=>f,GetAllNextDependency:ne,GetNextDependency:M,GetPrevDependency:b,GetAllPrevDependency:S,GetUidToLevelMap:()=>m},$,{callOnError:d,callOnSuccess:O,callOnStart:V,emit:F},y),{SetBucket:W,GetBucket:q,GetGroupByPath:re,GetNodeByPath:se,notifyAll:Me,useEntangle:me,updateEntangleLevel:Re,CancelTask:ye}=P;c&&U.init();let ee={};if(e.modules.useInternalForm){let{uiSchema:w,GetFormData:j}=e.modules.useInternalForm(P,g);ee={uiSchema:w,GetFormData:j};}let ie={};if(e.modules.useSchemaValidators){let{SetValidators:w}=e.modules.useSchemaValidators(se);ie={SetValidators:w};}let{SetRule:xe,SetRules:Pe}=ze(se,W,q,s,p,a,h,l),{SetStrategy:Ge}=qe(se,q),we=Ze(s,l),Ie=()=>{let w=we();f=w.steps,m=w.levelMap,Ee();},Ee=()=>{o&&(Re(),o=false);},Ce=()=>{i||(i=true,Promise.resolve().then(Ee).finally(()=>{i=false;}));},Oe=()=>{r||(r=true,Promise.resolve().then(()=>{if(Ie(),t){let{directNextMap:w,directPrevMap:j}=H(f.flat());n=w,T=j;}}).finally(()=>{r=false,t=false;}));};return {SetRule:(w,j,B,Z)=>{xe(w,j,B,Z),t=true,Oe();},SetRules:(w,j,B,Z)=>{Pe(w,j,B,Z),t=true,Oe();},SetStrategy:Ge,useEntangle:w=>{me(w),o=true,Ce();},SetTrace:G,usePlugin:v,SetValue:(w,j,B)=>{Ee(),se(w).dependOn(()=>B,j);},GetValue:(w,j="value")=>se(w).proxy[j],SetValues:w=>{Ee(),P.batchNotify(w);},GetGroupByPath:re,notifyAll:async()=>{Ie(),await Me();},GetAllDependency:()=>s,GetDependencyOrder:()=>f,historyExports:Y,formExports:ee,validatorExports:ie,batchRenderExport:U,hasRenderGate:()=>c,onError:L,onSuccess:x,onStart:k,scheduler:P,destroyPlugin:A,CancelTask:ye}}var ve=new Map,ut=(g,e,t)=>{try{if(ve.has(g))throw Error("engineID repeated");let r=it(e,{config:t.config||{useGreedy:!1},UITrigger:t.UITrigger,modules:t.modules??{},plugins:{}}),{SetRule:o,SetRules:i,SetValues:l,SetStrategy:s,SetValue:a,GetValue:p,usePlugin:h,useEntangle:n,GetGroupByPath:T,notifyAll:f,SetTrace:m,GetAllDependency:N,GetDependencyOrder:M,historyExports:b,formExports:S,validatorExports:ne,batchRenderExport:H,hasRenderGate:$,onError:Y,onSuccess:c,onStart:U,scheduler:L,destroyPlugin:d,CancelTask:x}=r,O={config:{SetRule:o,SetRules:i,SetStrategy:s,notifyAll:f,SetTrace:m,usePlugin:h,hasRenderGate:$,useEntangle:n},data:{SetValue:a,GetValue:p,SetValues:l,GetGroupByPath:T},dependency:{GetAllDependency:N,GetDependencyOrder:M},hooks:{onError:Y,onSuccess:c,onStart:U}},k=(v,A,G)=>{!A||typeof A!="object"||Object.keys(A).forEach(_=>{let u=A[_];if(typeof u=="object"&&u!==null)v[_]=v[_]||{},k(v[_],u,G);else if(typeof u=="function"){let y=_;if(y==="useMeshRenderGate")y="render";else if(y.startsWith("use")){let P=y.slice(3);y=P.charAt(0).toLowerCase()+P.slice(1);}_==="useHistory"&&G.exports.history&&Object.keys(G.exports.history).length>0?v[y]=G.exports.history:_==="useInternalForm"&&G.exports.form&&Object.keys(G.exports.form).length>0?v[y]=G.exports.form:_==="useSchemaValidators"&&G.exports.validator&&Object.keys(G.exports.validator).length>0?v[y]=G.exports.validator:_==="useMeshRenderGate"&&G.exports.render?v[y]=G.exports.render:v[y]=u(G.scheduler,G.Schema);}});},V={...O,destroyPlugin:d,CancelTask:x,modules:{}},F=t.modules;return F&&k(V.modules,F,{scheduler:L,Schema:e,exports:{history:b,form:S,validator:ne,render:H}}),ve.set(g,V),V}catch(r){throw Error(r)}},Sn=()=>(g,e,t)=>ut(g,e,t),Mn=g=>{let e=ve.get(g);if(!e)throw Error("Engine not found.");return e},Tn=g=>{let e=ve.get(g);e.destroyPlugin(),e.CancelTask(),ve.delete(g);};exports.DefaultStrategy=Ve;exports.MeshFlowEventsName=Fe;exports.TriggerCause=Ue;exports.deleteEngine=Tn;exports.useEngine=Mn;exports.useMeshFlow=ut;exports.useMeshFlowDefiner=Sn;exports.useScheduler=ot;
|
|
1
|
+
'use strict';var Ce=(M=>(M[M.FlowStart=0]="FlowStart",M[M.FlowSuccess=1]="FlowSuccess",M[M.FlowEnd=2]="FlowEnd",M[M.FlowAbort=3]="FlowAbort",M[M.FlowWait=4]="FlowWait",M[M.FlowFire=5]="FlowFire",M[M.NodeStart=6]="NodeStart",M[M.NodeSuccess=7]="NodeSuccess",M[M.NodeProcessing=8]="NodeProcessing",M[M.NodeError=9]="NodeError",M[M.NodePending=10]="NodePending",M[M.NodeRevive=11]="NodeRevive",M[M.NodeIntercept=12]="NodeIntercept",M[M.NodeRelease=13]="NodeRelease",M[M.NodeStagnate=14]="NodeStagnate",M[M.NodeBucketSuccess=15]="NodeBucketSuccess",M[M.EntangleWarn=16]="EntangleWarn",M[M.EntangleBlocked=17]="EntangleBlocked",M))(Ce||{}),Le=(r=>(r[r.CAUSALITY=0]="CAUSALITY",r[r.INVERSION=1]="INVERSION",r[r.REPERCUSSION=2]="REPERCUSSION",r))(Le||{});var _e=(r=>(r.OR="OR",r.PRIORITY="PRIORITY",r.MERGE="MERGE",r))(_e||{});var He=class{computedRules=[];getRuleResult(e,t,r){if(e.entityId==="__base__")return e.logic(t);if(!(!e._hasRun||r(e.triggerUids)))return e._lastResult;let l=e.logic(t);return l instanceof Promise?l.then(u=>(e._lastResult=u,e._hasRun=true,u)):(e._lastResult=l,e._hasRun=true,l)}store={OR:(e,t,r)=>{let i,l,u=this.computedRules;for(let a=0;a<u.length;a++){let o=u[a],p=this.getRuleResult(o,e,r);if(p instanceof Promise)return (async()=>{let n=await p;if(o.entityId==="__base__"?l=n:n&&(i=n),typeof i>"u")for(let P=a+1;P<u.length;P++){let m=u[P],S=this.getRuleResult(m,e,r),N=S instanceof Promise?await S:S;if(m.entityId==="__base__"){l=N;continue}if(N){i=m.value;break}}return typeof i>"u"&&(i=l),{res:i,version:t}})();let h=p;if(o.entityId==="__base__"){l=h;continue}if(h){i=o.value;break}}return typeof i>"u"&&(i=l),{res:i,version:t}},PRIORITY:(e,t,r)=>{let i,l=this.computedRules;for(let u=0;u<l.length;u++){let a=l[u],o=this.getRuleResult(a,e,r);if(o instanceof Promise)return (async()=>{let p=await o;if(p!==void 0)return {res:a.value!==void 0?a.value:p,version:t};for(let h=u+1;h<l.length;h++){let n=l[h],P=this.getRuleResult(n,e,r),m=P instanceof Promise?await P:P;if(m!==void 0)return {res:m,version:t}}return {res:void 0,version:t}})();if(o!==void 0)return {res:a.value!==void 0?a.value:o,version:t}}return {res:i,version:t}},MERGE:(e,t,r)=>{let i,l,u=this.computedRules,a=(p,h)=>p===void 0?h:h===void 0?p:Array.isArray(p)&&Array.isArray(h)?[...h,...p]:typeof p=="object"&&typeof h=="object"?{...h,...p}:p;for(let p=0;p<u.length;p++){let h=u[p],n=this.getRuleResult(h,e,r);if(n instanceof Promise)return (async()=>{let m=await n,S=(x,b)=>{if(x.entityId==="__base__")l=a(l,b);else if(b){let M=x.value!==void 0?x.value:b;i=a(i,M);}};S(h,m);for(let x=p+1;x<u.length;x++){let b=u[x],M=this.getRuleResult(b,e,r),se=M instanceof Promise?await M:M;S(b,se);}return {res:a(i,l),version:t}})();let P=n;if(h.entityId==="__base__"){l=a(l,P);continue}if(P){let m=h.value!==void 0?h.value:P;i=a(i,m);}}return {res:a(i,l),version:t}}};CurrentStrategy=()=>{};CurrentStrategyType="PRIORITY";getRules=()=>{};constructor(e){this.getRules=e,this.CurrentStrategy=this.store.PRIORITY,this.updateComputedRules();}updateComputedRules(){let e=this.getRules();this.CurrentStrategyType==="PRIORITY"||this.CurrentStrategyType==="MERGE"?this.computedRules=Array.from(e.values()).map(t=>Array.from(t)).flat().sort((t,r)=>r.priority-t.priority):this.computedRules=Array.from(e.values()).map(t=>Array.from(t)).flat();}setStrategy(e){this.CurrentStrategyType=e,this.CurrentStrategy=this.store[e],this.updateComputedRules();}evaluate(e,t,r){return this.CurrentStrategy(e,t,r)}},we=class{path;strategy;contract;rules=new Map;isValue=false;id=0;cache=void 0;pendingPromise=null;version=0;deps=new Map;_forceNotify=false;promiseToken=null;useCache=true;effectArray=[];constructor(e,t,r){let i=()=>this.rules;this.strategy=new He(i),this.path=r,this.isValue=t==="value",this.contract=this.inferType(e),this.cache=e,this.setRule({priority:0,entityId:"__base__",logic:()=>e});}setUseCache(e){this.useCache=e;}forceNotify(){this._forceNotify=true;}isForceNotify(){return this._forceNotify}setStrategy(e){this.strategy.setStrategy(e);}setDefaultRule(e){let t=new Set;t.add(e),this.rules.set(-1,t);}setRules(e,t){t&&this.updateDeps(t);let r=++this.id,i={...e,entityId:r};for(let l of e.triggerUids)this.rules.has(l)||this.rules.set(l,new Set),this.rules.get(l).add(i);return this.strategy.updateComputedRules(),()=>{for(let l of e.triggerUids){let u=this.rules.get(l);u&&(u.delete(i),u.size===0&&(this.rules.delete(l),this.deps.delete(l)));}this.strategy.updateComputedRules();}}updateDeps(e){for(let[t,r,i]of e){if(r.length==0)continue;let l=this.deps.get(t)||Object.create(null);for(let u of r)l[u]=i[u];this.deps.set(t,l);}}setRule(e,t){if(t&&this.updateDeps(t),typeof e.entityId=="string"){this.setDefaultRule(e);return}let r=++this.id,i={...e,entityId:r};if(e)for(let l of e.triggerUids)this.rules.has(l)||this.rules.set(l,new Set),this.rules.get(l).add(i);return this.strategy.updateComputedRules(),()=>{for(let l of e.triggerUids){let u=this.rules.get(l);u&&(u.delete(i),u.size===0&&(this.rules.delete(l),this.deps.delete(l)));}this.strategy.updateComputedRules();}}setSideEffect(e){this.effectArray.push(e);}getSideEffect(){return [...this.effectArray]}evaluate(e){let t=null;if(e.GetToken&&(t=e.GetToken()),this.pendingPromise&&this.promiseToken!==t&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;let r=false;if(typeof e.triggerUid=="number"){r=true,this.deps.size==0&&(r=false);for(let[a,o]of this.deps.entries()){let p=e.getStateByUid(a);if(!p){r=false;break}for(let h in o){let n=o[h],P=p[h];if(typeof n=="object"&&n!==null){r=false;break}if(n!==P){r=false;break}}if(!r)break}}if(r&&this.useCache)return this.cache;this.promiseToken=t;let i=++this.version,l=a=>{if(!a||a.length===0)return true;for(let o of a){let p=this.deps.get(o);if(!p)return true;let h=e.getProxyByUid(o);if(!h)return true;for(let n in p){let P=p[n],m=h[n];if(typeof P=="object"&&P!==null||P!==m)return true}}return false},u=this.strategy.evaluate(e,i,l);if(!(u instanceof Promise)){let{res:a,version:o}=u;return this.finalizeSync(a,o,e,t)}return this.pendingPromise=(async()=>{try{let{res:a,version:o}=await u;return this.finalizeSync(a,o,e,t)}catch(a){throw {path:this.path,error:a}}finally{this.promiseToken===t&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}finalizeSync(e,t,r,i){return i!==this.promiseToken||t<this.version?this.cache:(this.cache=e,this.deps.forEach((l,u)=>{let a=r.getProxyByUid(u);if(!a)return;let o=Object.keys(l);for(let p of o)l[p]=a[p];}),e)}inferType(e){return Array.isArray(e)?"array":typeof e}};var Xe=(g,e,t)=>{let i=l=>{let u=t.triggerUids.map(p=>{let h=l.getProxyByUid(p);if(t.triggerKeys.length===0)return h;let n={};return t.triggerKeys.forEach(P=>{n[P]=h[P];}),n}),a=Object.create(null);return Object.defineProperty(a,"triggerTargets",{get:()=>u}),Object.defineProperty(a,"affectedTatget",{get:()=>l.getProxyByUid(g)[e]}),t.logic({slot:a})};return {value:t.value,targetUid:g,triggerUids:t.triggerUids,priority:t.priority??10,logic:i}},Ze=(g,e,t,r,i,l,u,a)=>{if(!g)throw Error();let o=g,p=(P,m)=>{typeof r[P]>"u"&&(r[P]=[],l[P]=new Set),l[P].add(m),l[P].size>r[P].length&&r[P].push(m),typeof i[m]>"u"&&(i[m]=[],u[m]=new Set),u[m].add(P),u[m].size>i[m].length&&i[m].push(P);};return {SetRule:(P,m,S,N)=>{let x=o(P),b=o(m),M=N.triggerKeys||[],se=a.get(b.uid)||0,U=a.get(x.uid)||0;se+=1,U+=1,a.set(b.uid,se),a.set(x.uid,U);let _=Xe(b.uid,S,{...N,triggerUids:[x.uid],triggerKeys:M}),ee=[P].map(C=>{let te=o(C);return [te.uid,M,te.proxy]});if(p(x.uid,b.uid),typeof b.nodeBucket[S]=="number"){let C=t(b.nodeBucket[S]);C.setRule(_,ee),N.effect&&C.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[S]});}else {let C=b.meta[S],te=new we(C,S,m);te.setRule(_,ee),N.effect&&te.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[S]}),b.nodeBucket[S]=e(te);}b.state[S]=b.meta[S];let z=t(b.nodeBucket[S]);N.forceNotify&&z.forceNotify(),N.cacheStrategy=="none"&&z.setUseCache(false);},SetRules:(P,m,S,N)=>{let x=o(m),b=a.get(x.uid)||0;b+=1,a.set(x.uid,b);let M=[];for(let z of P){let C=o(z);M.push(C.uid);let te=a.get(C.uid)||0;te+=1,a.set(C.uid,te),p(C.uid,x.uid);}let se=N.triggerKeys||[],U=Xe(x.uid,S,{...N,triggerUids:M,triggerKeys:se}),_=P.map(z=>{let C=o(z);return [C.uid,se,C.state]});if(typeof x.nodeBucket[S]=="number"){let z=t(x.nodeBucket[S]);z.setRules(U,_),N.effect&&z.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[S]});}else {let z=x.meta[S],C=new we(z,S,m);C.setRules(U,_),N.effect&&C.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[S]}),x.nodeBucket[S]=e(C);}x.state[S]=x.meta[S];let ee=t(x.nodeBucket[S]);N.forceNotify&&ee.forceNotify(),N.cacheStrategy=="none"&&ee.setUseCache(false);}}};var Je=(g,e)=>{let t=g||void 0;if(!t)throw Error();return {SetStrategy:(i,l,u)=>{let a=t(i);e(a.nodeBucket[l]).setStrategy(u);}}};function et(){let g=new Map,e=new Map,t=new Set,r=(u,a)=>{g.set(u,a);let o=e.get(u);o&&o(a);};return {SetTrace:(u,a)=>{e.set(u,a);let o=g.get(u)||"idle";return a(o),{cancel:()=>{e.delete(u);}}},useTrace:()=>({apply:a=>{a.on(0,()=>{t.forEach(o=>r(o,"idle")),t.clear(),g.clear();}),a.on(13,({path:o,type:p})=>{(p==1||p==2)&&(t.add(o),r(o,"pending"));}),a.on(10,({path:o})=>{t.add(o),(!g.has(o)||g.get(o)==="idle")&&r(o,"pending");}),a.on(6,({path:o})=>{t.add(o),r(o,"calculating");}),a.on(7,({path:o})=>{r(o,"calculated");}),a.on(12,({path:o,type:p})=>{p==3&&r(o,"calculating"),p==6&&r(o,"idle");}),a.on(14,({path:o})=>{r(o,"pending");}),a.on(9,({path:o})=>r(o,"error"));}})}}function nt(g,e,t,r){return {GetNextDependency:h=>r()[h]||[],GetPrevDependency:h=>t()[h]||[],GetAllPrevDependency:h=>e()[h]||[],GetAllNextDependency:h=>g()[h]||[],rebuildDirectDependencyMaps:h=>{let n=[],P=[],m=g();for(let S of h){let N=m[S]||[];n[S]=N;for(let x=0;x<N.length;x++){let b=N[x];typeof P[b]>"u"&&(P[b]=[]),P[b].push(S);}}return {directNextMap:n,directPrevMap:P}}}}function rt(g,e){let t=i=>{let l=[],u=[],a=new Map,o=i.size,p=0,h=0;for(let[n,P]of i)P===0&&u.push(n);if(u.length===0&&o>0)throw Error("Circular dependency detected");for(;u.length>0;){l.push([...u]);let n=[];for(let P of u){p++,a.set(P,h);let m=g[P];if(m)for(let S of m){let N=i.get(S)-1;i.set(S,N),N===0&&n.push(S);}}u=n,h++;}if(p<o)throw Error("Circular dependency detected");return {steps:l,levelMap:a}};return ()=>{let i=new Map;for(let l of e.keys()){let u=g[l]||[];i.has(l)||i.set(l,0);for(let a of u){let o=i.get(a)||0;i.set(a,++o);}}return t(i)}}var Ge=()=>{let g=[];return {on:e=>(g.push(e),()=>{let t=g.indexOf(e);t>-1&&g.splice(t,1);}),call:e=>g.forEach(t=>{t(e);})}};function st(){let{on:g,call:e}=Ge();return {onError:g,callOnError:e}}function at(){let{on:g,call:e}=Ge();return {onSuccess:g,callOnSuccess:e}}var ot=()=>{let g=new Set,e=new Map,t=new Set,r=(a,o)=>{e.get(a)?.forEach(p=>p(o));},i=(a,o)=>(e.has(a)||e.set(a,new Set),e.get(a).add(o),()=>e.get(a)?.delete(o));return {usePlugin:a=>{let o=new Set,p=(n,P)=>{let m=i(n,P);return o.add(m),m};a.apply({on:p}),g.add(a);let h=()=>{o.forEach(n=>n()),o.clear(),g.delete(a),t.delete(h);};return t.add(h),h},emit:r,destroyPlugin:()=>{t.forEach(a=>a()),t.clear(),e.clear(),g.clear();}}};function it(){let{on:g,call:e}=Ge();return {onStart:g,callOnStart:e}}var lt=(g={frameQuota:12})=>{let e=performance.now(),t=0,r=false,i=()=>!!navigator?.scheduling?.isInputPending?.({includeContinuous:true});return {getIsFirstFrame:()=>r,reset(){e=performance.now(),t=0,r=true;},shouldYield(){return !r&&(++t&15)!==0?false:!!(performance.now()-e>g.frameQuota||i())},async yieldToMain(){return new Promise(l=>{Ye(()=>{e=performance.now(),t=0,r&&(r=false),l();});})}}},Ye=g=>{let{port1:e,port2:t}=new MessageChannel;e.onmessage=g,t.postMessage(null);};function ut(g,e,t,r,i,l){let u=new Map,a=g.useGreedy,o=null,p=()=>{u.clear();},h={path:null,level:0,targetLevel:0,currentLevel:0,pendingParentsCount:0,active:0,pending:0,blocked:0,nums:0,asyncNums:0},n={path:null,type:0,triggerPath:null,calledBy:0,key:null,value:null,error:null,token:null,duration:null,detail:h},P=false,m=[],S=null,N=(b,M,se)=>{m.push({uid:b,key:M,value:se}),!P&&(S||(S=Promise.resolve().then(()=>{S=null,P||x(null,[]);})));},x=async(b,M)=>{let U=Symbol("token"),_=typeof b=="number"?b:"__NOTIFY_ALL__";u.set(_,U),o=U,P=true;let ee=false,z=false;l.reset(),t.Turnstile.nextEpoch();let C=t.GetMaxUid()+3,te=new Array(C).fill(0),d=0,s=new Uint8Array(C),H=new Int32Array(C),k=new Int32Array(C),Y=new Int32Array(C*2),A=0,E=0,T=new Int32Array(C*2),O=0,v=0,G=new Int32Array(C*2),c=0,y=0;M.forEach(f=>{te[f]=1,e.GetAllNextDependency(f).forEach(W=>{te[W]=1;});});let w=new Array(C).fill(null),V=[],q=t.Turnstile,ae=new Array(C).fill(null).map(()=>[]),de=new Array(C).fill(null).map(()=>[]),me=[],Ne=()=>{if(m.length===0)return false;let f=false,W=1/0;for(;m.length>0;){let{uid:D,key:Q,value:le}=m.shift(),L=t.GetNodeByUid(D);if(me.includes(D)||me.push(D),!Object.is(L.state[Q],le)){f=true,L.state[Q]=le,i.flushPathSet.add(D),L.calledBy=1;let ne=w[D]||[];ne.includes(Q)||ne.push(Q),w[D]=ne,s[D]&=-17,s[D]&2&&(s[D]&=-3,v--),s[D]&1||(s[D]|=1,Y[A++]=D,E++);let X=e.GetUidToLevelMap().get(D)??0;X<W&&(W=X),Se(D);}}return f&&(ie===void 0||ie>W)&&(ie=W),f},Te=q.volatileLevels.size>0,Pe=Te?q.hasObserver:f=>false,xe=Te?q.receiveGhosts:()=>[],Oe=Te?q.resolveGhosts:()=>[],ke=Te?q.getTriggerKeys:()=>[],De=q?.volatileLevels||new Set,be=-1,oe=e.GetUidToLevelMap(),ie=0,Re=0,Se=f=>{e.GetAllNextDependency(f).forEach(D=>{let Q=oe.get(D)||0;Q>Re&&(Re=Q);});};Ne();let Ie=new Set;typeof b=="number"&&(s[b]|=16,Ie.add(b),Se(b),i.flushPathSet.add(b));let Be=typeof b=="number"?[b]:[...M,...me];l.shouldYield()&&(i.requestUpdate(),await l.yieldToMain());let We=Be.map(async f=>{if(Pe(f)){let W=t.GetNodeByUid(f),D=ke(f);if(D.length>0){let Q=xe(W,D);return Q instanceof Promise&&(Q=await Q),{seed:f,hitTargets:Q}}}return {seed:f,hitTargets:[]}});if((await Promise.all(We)).forEach(({seed:f,hitTargets:W})=>{if(W&&W.length>0){V.push(...W);let D=oe.get(f)||0;be=Math.max(be,D);}}),(V.length>0||Be.length>1)&&(i.requestUpdate(),await l.yieldToMain(),u.get(_)!==U))return;let ze=V.length>0;M.forEach(f=>{if(!Ie.has(f))if(ze){let W=oe.get(f)??0;k[f]=W,s[f]&4||(s[f]|=4,G[c++]=f,y++);let D=t.GetPathByUid(f);n.path=D,n.type=2,r.emit(14,n);}else s[f]&1||(s[f]|=1,Y[A++]=f,E++),Se(f);}),typeof b=="number"?ie=oe.get(b)??0:ie=Math.min(...M.map(f=>oe.get(f)??0));let qe=performance.now(),Ue=typeof _=="number"?t.GetPathByUid(_):"__NOTIFY_ALL__";n.path=Ue,n.token=U,r.emit(0,n),r.callOnStart({path:Ue});let Ve=false,Qe=30,$e=(f,W)=>{let D=false,Q=false,le=false,L=t.GetNodeByUid(f),ne=t.GetPathByUid(f),X=L.calledBy,K=ae[f];K.length=0;let B=Pe(f),I=B?ke(f):[],F=R=>{B&&(I.length===0||I.includes(R))&&K.push(R);},ue=de[f];ue.length=0;let ye=false;if(L.calledBy===1){ye=true,D=true,i.flushPathSet.add(f);let R=w[f];R&&(K.push(...R),w[f]=null);}let fe=(R,J)=>{let re=oe.get(R)??0,he=t.GetNodeByUid(R),Z=t.GetPathByUid(R),ge=(X===1||X===2)&&re<=be;ge&&s[R]&16&&(s[R]&=-17,n.path=Z,n.triggerPath=ne,r.emit(11,n));let ce=0;if(!(s[R]&49)){if(s[R]&2)ce=H[R]-1;else {if(re>ie&&v>Qe){k[R]=re,s[R]&4||(s[R]|=4,G[c++]=R,y++),n.path=Z,n.type=7,r.emit(12,n);return}let Ee=e.GetPrevDependency(R),$=0;for(let Me of Ee){if(s[Me]&16)continue;(oe.get(Me)??0)>ie&&$++;}ce=$;}if(ce<=0){let Ee=(s[R]&1)!==0,$=(s[R]&32)!==0;if(Ee||$){n.path=Z,n.type=$?3:3.1,r.emit(12,n);return}s[R]&2&&(s[R]&=-3,v--),ge?he.calledBy=2:he.calledBy=0,s[R]&1||(s[R]|=1,Y[A++]=R,E++),n.path=Z,n.type=J,h.path=ne,r.emit(13,n);}else H[R]=ce,s[R]&2||(s[R]|=2,T[O++]=R,v++);}},ve=(R=[])=>{if(u.get(_)!==U)return;if(R.length){let re={},he=L.proxy;for(let Z of R){let ge=(Z.args||[]).reduce((ce,Ee)=>(ce[Ee]=he[Ee],ce),{});try{let ce=Z.fn(ge);ce&&typeof ce=="object"&&Object.assign(re,ce);}catch(ce){}}for(let Z in re)if(Z in L.state)Object.is(L.state[Z],re[Z])||(L.state[Z]=re[Z],F(Z),D=true,(L.notifyKeys.size===0||L.notifyKeys.has(Z))&&(Q=true));else throw {error:`wrong effect in ${String(L.path)}`}}D&&i.flushPathSet.add(f);let J=(re=[])=>{if(u.get(_)!==U)return;re&&re.length>0&&(V.push(...re),be=Math.max(be,oe.get(f)||0)),K.length=0,n.path=ne,n.calledBy=L.calledBy,r.emit(7,n),s[f]|=16;let he=e.GetNextDependency(f);(Q||le)&&(Se(f),e.GetAllNextDependency(f).forEach(Me=>{te[Me]=1;}));let Z=t.GetNodeByUid(f),ge=oe.get(f)??0,ce=De.has(ge)||V.length>0;for(let $ of he){let Me=oe.get($)??0,Ae=t.GetPathByUid($);if(ce&&Me>=ge){k[$]=Me,s[$]&4||(s[$]|=4,G[c++]=$,y++),n.path=Ae,n.type=2,r.emit(14,n);continue}if(s[$]&16){n.path=Ae,n.type=2,r.emit(12,n);continue}if(s[$]&32||(s[$]&1)!==0){n.path=Ae,n.type=s[$]&32?3:3.1,r.emit(12,n);continue}if(Q||le)fe($,1);else if(s[$]&2)fe($,2);else {let pt=oe.get($);k[$]=pt,s[$]&4||(s[$]|=4,G[c++]=$,y++,n.path=Ae,n.type=1,r.emit(14,n));}}s[f]&32&&(s[f]&=-33,d--),Z.calledBy=0,(()=>{if(!ee){ee=true;let $=d,Me=E,Ae=v;n.path=ne,n.type=1,h.active=$,h.pending=Me,h.blocked=Ae,r.emit(5,n),j();}})();};if(Pe(f)&&K.length>0){let re=xe(L,K);re instanceof Promise?re.then(J).catch(Fe):J(re);}else J([]);},Fe=R=>{n.path=ne,n.error=R,r.emit(9,n);let J=Symbol("abort");u.set(_,J),A=0,E=0,O=0,v=0,c=0,y=0,s.fill(0),d=0,w.fill(null),P=false,r.callOnError(R);},pe=(R,J)=>{R!==L.state[J]&&(L.state[J]=R,D=true,F(String(J)),n.path=ne,n.key=J,n.value=R,n.calledBy=L.calledBy,r.emit(15,n),(L.notifyKeys.size===0||L.notifyKeys.has(J))&&(Q=true)),t.GetBucket(L.nodeBucket[J]).isForceNotify()&&(le=true),(Q||le)&&Se(f);};n.path=ne,n.calledBy=L.calledBy,r.emit(6,n);try{let R=[];for(let J in L.nodeBucket){let re=t.GetBucket(L.nodeBucket[J]);if(R.push(...re.getSideEffect()),ye){r.emit(15,{path:ne,key:String(J),value:L.state[J],calledBy:L.calledBy}),re.isForceNotify()&&(le=!0),(L.notifyKeys.size===0||L.notifyKeys.has(J))&&Se(f);continue}let he=re.evaluate({affectKey:J,triggerUid:W,getProxyByUid:Z=>t.GetNodeByUid(Z).proxy,getStateByUid:Z=>t.GetNodeByUid(Z).state,GetToken:()=>U});if(he instanceof Promise){let Z=he.then(ge=>{u.get(_)===U&&pe(ge,J);});ue.push(Z);}else pe(he,J);}if(ue.length>0)return Promise.all(ue).then(()=>{ve(R);}).catch(Fe);ve(R);return}catch(R){Fe(R);}},j=async()=>{if(u.get(_)!==U){ee=false;return}ee=true;let f=l.getIsFirstFrame(),W=0,D=()=>30,Q=0,le=D();try{for(;u.get(_)===U;){let L=Q>=le,ne=l.shouldYield();if(L||ne){if(Q>0&&(W++,(f||W%2===0)&&i.requestUpdate()),await l.yieldToMain(),u.get(_)!==U)break;Q=0,f=l.getIsFirstFrame();}if(E>0&&d<40){let X=A,K=0;for(let B=0;B<X;B++){let I=Y[B];if((s[I]&1)===0)continue;if(d>=40||Q>=le||l.shouldYield()){for(let pe=B;pe<A;pe++){let R=Y[pe];s[R]&1&&(Y[K++]=R);}A=K,E=K;break}let F=t.GetNodeByUid(I),ue=t.GetPathByUid(I),ye=oe.get(I)??0,fe=e.GetPrevDependency(I),ve=fe.length>1;if((!a||ve)&&ye>ie){s[I]&=-2,E--;let pe=fe.filter(R=>te[R]===1&&(s[R]&16)===0).length;H[I]=pe||0,s[I]&2||(s[I]|=2,T[O++]=I,v++),n.path=ue,n.type=pe>0?4:5,h.targetLevel=ye,h.currentLevel=ie,h.pendingParentsCount=pe,r.emit(12,n);continue}s[I]&=-2,E--,(s[I]&32)===0&&(s[I]|=32,d++),n.path=ue,n.calledBy=F.calledBy,r.emit(8,n),$e(I,b),Q++;}if(A>X){for(let B=X;B<A;B++){let I=Y[B];s[I]&1&&(Y[K++]=I);}A=K,E=A;}else A=K;if(E>0&&d<40)continue}if(Q<le&&a&&v>0&&d<40){let X=!1,K=0,B=0;for(let I=0;I<O;I++){let F=T[I];if((s[F]&2)===0)continue;if(H[F]<=0&&K<le){let ye=oe.get(F)??0,fe=e.GetPrevDependency(F);if(ye<=ie||fe.length<=1){s[F]&=-3,v--,s[F]&1||(s[F]|=1,Y[A++]=F,E++),K++,X=!0;let ve=t.GetPathByUid(F);n.path=ve,n.type=4,r.emit(13,n);continue}}T[B++]=F;}if(O=B,K>0)continue;if(X){if(l.shouldYield()&&(await l.yieldToMain(),u.get(_)!==U))break;continue}}if(d===0&&E===0){if(q.inFlightCount>0)break;if(V.length>0){let K=!1,B=ie,I=Array.from(new Set(V));V.length=0;for(let F of I){let ue=t.GetNodeByUid(F),ye=Oe(ue);if(ye&&ye.length>0){K=!0,ue.calledBy=1,w[F]=ye,s[F]&=-17,s[F]&2&&(s[F]&=-3,v--),s[F]&1||(s[F]|=1,Y[A++]=F,E++);let fe=oe.get(ue.uid)??0;fe<B&&(B=fe),Se(ue.uid),i.flushPathSet.add(ue.uid);}}if(K){if(B<ie&&(ie=B),i.requestUpdate(),l.shouldYield()&&(await l.yieldToMain(),u.get(_)!==U))break;continue}}let X=1/0;for(let K=0;K<c;K++){let B=G[K];if(s[B]&4){let I=k[B];I<X&&(X=I);}}for(let K=0;K<O;K++){let B=T[K];if(s[B]&2){let I=oe.get(B)??0;I>ie&&I<X&&(X=I);}}if(X!==1/0&&X<=Re){ie=X;let K=0;for(let I=0;I<c;I++){let F=G[I];s[F]&4&&(k[F]===X?(s[F]&=-5,y--,s[F]&1||(s[F]|=1,Y[A++]=F,E++)):G[K++]=F);}c=K;let B=0;for(let I=0;I<O;I++){let F=T[I];if(s[F]&2)if((oe.get(F)??0)===X){s[F]&=-3,v--,s[F]&1||(s[F]|=1,Y[A++]=F,E++);let ye=t.GetPathByUid(F);n.path=ye,n.type=3,h.level=X,r.emit(13,n);}else T[B++]=F;}O=B;continue}else {for(let K=0;K<c;K++){let B=G[K];if(s[B]&4){s[B]|=16;let I=t.GetPathByUid(B);n.path=I,n.type=6,r.emit(12,n);}}c=0,y=0;for(let K=0;K<O;K++){let B=T[K];if(s[B]&2){s[B]|=16;let I=t.GetPathByUid(B);n.path=I,n.type=6,r.emit(12,n);}}O=0,v=0;break}}E>0&&d>=40&&(n.type=2,r.emit(4,n));break}}finally{ee=false;let L=d+v+E,ne=q.inFlightCount||0;if(!(o===U)){n.token=U,r.emit(3,n);return}if(i.requestUpdate(),L===0&&ne===0){if(u.get(_)===U&&!Ve){Ve=true,n.type=1,r.emit(2,n),q.resetCounters(),w.fill(null),P=false;let K=performance.now();be=-1,u.delete(_),n.token=U,n.duration=(K-qe).toFixed(2.1)+"ms",r.emit(1,n),Promise.resolve().then(()=>{r.callOnSuccess();});}}else {let K=L===0&&ne>0?3:1;if(n.type=K,h.nums=d,h.asyncNums=ne,r.emit(4,n),ne>0&&!z){z=true;let B=()=>{if(o!==U){z=false;return}if(q.inFlightCount===0){z=false,Ne(),Ye(()=>{o===U&&q.inFlightCount===0&&j();});return}else q.inFlightCount,requestAnimationFrame(B);};requestAnimationFrame(B);}}}};j();};return {TaskRunner:x,CancelTask:p,stageValueFn:N}}function je(g){let{path:e,uid:t,type:r,meta:i,dirtySignal:l,state:u}=g,a=null,o=["path","uid","type","dependOn","nodeBucket"],h={path:e,uid:t,type:r,meta:i,dirtySignal:l,createView:(n={})=>{if(a&&Object.keys(n).length===0)return a;let P=new Proxy(n,{get(m,S){let N=S;return Reflect.has(m,S)?Reflect.get(m,S):N in g.state?g.state[N]:N in g?g[N]:i&&N in i?i[N]:Reflect.get(m,S)},set(m,S,N){return false},ownKeys(m){let S=new Set([...Reflect.ownKeys(m),...Object.keys(u||{}),...Object.keys(i||{}),...o]);return Array.from(S)},getOwnPropertyDescriptor(m,S){let N=S;return Reflect.has(m,S)||u&&N in u||i&&N in i||o.includes(N)?{enumerable:true,configurable:true}:Reflect.getOwnPropertyDescriptor(m,S)}});return a=P,P}};return "children"in g?{...h,children:g.children}:{...h,state:g.state,nodeBucket:g.nodeBucket,notifyKeys:g.notifyKeys,dependOn:g.dependOn,calledBy:0,get proxy(){return a}}}var ct=(g,e,t,r,i,l,u)=>{let a=g.useEntangleStep,o=[],p=[],h=new Set,n=r,S=t,N=0,x=0,b=0,M=100,se=()=>{let d={link:null,impactNode:null,impactUid:-1,hitTargetUids:null,isDirty:false,propose:null};return d.propose={set:(s,H,k=1)=>{d.epoch===b&&H!==d.impactNode.state[s]&&(d.link.count++,(!p[d.impactUid]||p[d.impactUid].length===0)&&(p[d.impactUid]=[],x++),p[d.impactUid].push({key:s,value:H,weight:k}),d.isDirty||(d.hitTargetUids.push(d.impactUid),d.isDirty=true));},update:(s,H,k="add")=>{d.epoch===b&&(d.link.count++,(!p[d.impactUid]||p[d.impactUid].length===0)&&(p[d.impactUid]=[],x++),p[d.impactUid].push({key:s,delta:H,op:k,weight:1}),d.isDirty||(d.hitTargetUids.push(d.impactUid),d.isDirty=true));},patch:(s,H)=>{d.epoch===b&&(d.link.count++,(!p[d.impactUid]||p[d.impactUid].length===0)&&(p[d.impactUid]=[],x++),p[d.impactUid].push({key:s,patch:H,weight:1}),d.isDirty||(d.hitTargetUids.push(d.impactUid),d.isDirty=true));}},d},U=Array.from({length:M},se),_=M-1,ee=(d,s,H)=>{let k=s.path,Y=d.impact;if(d.count>=a){u.emit("entangle:blocked",{observer:k,target:Y,count:d.count});return}let A=n(Y),E=d.isProxy?s.proxy:s,T=d.isProxy?A.proxy:A;if(d.filter&&!d.filter(E,T))return;let O,v=true;_<0?(O=se(),v=false):O=U[_--];let G=b;O.epoch=G,O.isDirty=false,O.link=d,O.impactNode=A,O.impactUid=A.uid,O.hitTargetUids=H;let c=d.emit(E,T,O.propose);if(c instanceof Promise||c&&typeof c.then=="function")return N++,(async()=>{try{await c;}catch(y){u.emit("node:error",{path:k,error:y}),u.onError({path:k,error:y});}finally{G===b&&N--,v&&(U[++_]=O);}})();v&&(U[++_]=O);};return {useEntangle:d=>{let{cause:s,impact:H,via:k,emit:Y,filter:A,isProxy:E}=d;if(!k||k.length===0){u.emit("entangle:warn",{path:s,type:"no_keys"});return}let O=n(s).uid;o[O]||(o[O]=new Map);let v=o[O];for(let G=0;G<k.length;G++){let c=k[G];v.has(c)||v.set(c,[]),v.get(c).push({impact:H,emit:Y,filter:A,count:0,isProxy:!!E});}},updateEntangleLevel:()=>{let d=S();h.clear();for(let s=0;s<o.length;s++)if(o[s]!==void 0){let H=d.get(s)||0;h.add(H);}},Turnstile:{volatileLevels:h,get inFlightCount(){return N},get hasPendingGhosts(){return x>0},nextEpoch:()=>{b++,N=0,x=0,p.length=0;},hasObserver:d=>o[d]!==void 0,getTriggerKeys:d=>{let s=o[d];return s?Array.from(s.keys()):[]},receiveGhosts:(d,s=[])=>{let H=d.uid,k=[],Y=o[H];if(!Y||s.length===0)return k;let A=[];for(let G=0;G<s.length;G++){let c=Y.get(s[G]);if(c)for(let y=0;y<c.length;y++)A.push(c[y]);}let E=0,T=false,O=null;for(;E<A.length;E++){if(e.shouldYield()){T=true;break}let G=ee(A[E],d,k);if(G){O=G,T=true,E++;break}}let v=()=>{if(k.length<=1)return k;let G=[],c=Object.create(null);for(let y=0;y<k.length;y++){let w=k[y];c[w]||(c[w]=true,G.push(w));}return G};return T?(async()=>{for(O&&await O,e.shouldYield()&&await e.yieldToMain();E<A.length;){let G=[],c=Math.min(E+M,A.length);for(;E<c;E++){let y=ee(A[E],d,k);y&&G.push(y);}G.length>0&&await Promise.all(G.map(async y=>{await y,e.shouldYield()&&await e.yieldToMain();})),e.shouldYield()&&await e.yieldToMain();}return v()})():v()},resolveGhosts:d=>{let s=d.uid,H=p[s];if(!H||H.length===0)return [];let k=[],Y=Object.create(null);for(let A=0;A<H.length;A++){let E=H[A];Y[E.key]||(Y[E.key]=[]),Y[E.key].push(E);}for(let A in Y){let E=Y[A],T=d.state[A],O,v=-1/0,G=false;for(let c=0;c<E.length;c++){let y=E[c];if(y.patch!==void 0&&(T=y.patch(T)),y.value!==void 0){let w=y.weight??1;w>=v&&(v=w,O=y.value,G=true);}}G&&(T=O);for(let c=0;c<E.length;c++){let y=E[c];if(y.delta!==void 0)switch(y.op||"add"){case "add":T=(typeof T=="number"?T:0)+y.delta;break;case "remove":T=Array.isArray(T)?T.filter(V=>V!==y.delta):T;break;case "intersect":T=Array.isArray(T)?T.filter(V=>y.delta.includes(V)):y.delta;break;case "union":{let V=Array.isArray(T)?T:[],q=Array.isArray(y.delta)?y.delta:[y.delta];T=[...new Set([...V,...q])];break}case "merge":{let V=typeof T=="object"&&T!==null&&!Array.isArray(T)?T:{},q=typeof y.delta=="object"&&y.delta!==null&&!Array.isArray(y.delta)?y.delta:{};T={...V,...q};break}}}Object.is(d.state[A],T)||(d.state[A]=T,k.push(A));}return p[s]=[],x--,k.length>0?k:[]},resetCounters:()=>{for(let d=0;d<o.length;d++){let s=o[d];if(s)for(let H of s.values())for(let k=0;k<H.length;k++)H[k].count=0;}}}}};function yt(g,e,t,r,i){let l=lt(),u=0,a=new Map,o=[],p=[],h=[],n=[],P=false,m=new Set,N=async()=>{let c=Array.from(m);if(m.clear(),"signalTrigger"in i&&typeof i.signalTrigger=="function")for(let y of c){let w=s(y);i.signalTrigger(w.dirtySignal);}else "emit"in i&&i.emit(c);},x=()=>{P||(P=true,requestAnimationFrame(()=>{try{for(;m.size>0;)N();}finally{P=false;}}));},{useEntangle:b,updateEntangleLevel:M,Turnstile:se}=ct({useEntangleStep:g.useEntangleStep},l,e.GetUidToLevelMap,d,s,H,{emit:r.emit,onError:r.callOnError}),{TaskRunner:U,CancelTask:_,stageValueFn:ee}=ut({useGreedy:g.useGreedy},e,{GetNodeByPath:d,GetNodeByUid:s,GetPathByUid:H,GetBucket:A,GetMaxUid:E,Turnstile:se},r,{requestUpdate:x,flushPathSet:m},l),z=c=>{throw new Error(`[MeshFlow] Duplicate Path: ${c}`)},C=c=>{a.has(c.path)&&z(String(c.path));let y=++u,w={path:c.path,getNode:ae=>d(ae)},V=(ae,de="value")=>{let me=ae({...w}),Ne=d(c.path);if(!Object.is(Ne.state[de],me)){if(t.createHistoryAction&&t.pushIntoHistory){let Te=t.createHistoryAction([{path:c.path,value:Ne.state[de]},{path:c.path,value:me}],Pe=>{let xe=d(Pe.path);xe.state[de]=Pe.value,T(Pe.path);});t.pushIntoHistory(Te);}Ne.state[de]=me,T(c.path);}},q=je({uid:y,type:c.type,path:c.path,state:c.state,meta:c.meta,nodeBucket:{},dirtySignal:"signalCreator"in i?i.signalCreator():void 0,notifyKeys:c.notifyKeys,dependOn:V});return a.set(q.path,y),h[y]=q.path,o[y]=q,q},te=c=>{a.has(c.path)&&z(String(c.path));let y=++u,w=je({uid:y,type:c.type,path:c.path,state:{},meta:c,nodeBucket:{},children:c.children});return a.set(w.path,y),p[y]=w,w};function d(c){let y=a.get(c),w=o[y];if(!w)throw Error("Wrong id");return w}function s(c){let y=o[c];if(!y)throw Error("Wrong id");return y}function H(c){return h[c]}function k(c){let y=a.get(c);return p[y]}function Y(c){return n.push(c)-1}function A(c){let y=n[c];if(!y)throw Error("Wrong id");return y}function E(){return u}let T=c=>{let y=d(c);if(!y)throw Error("Wrong id");m.add(y.uid),x();let w=e.GetNextDependency(y.uid);O(y.uid,w);};function O(c,y){U(c,y);}return {registerNode:C,registerGroupNode:te,GetNodeByPath:d,GetGroupByPath:k,notify:T,notifyAll:async()=>{Promise.resolve().then(async()=>{let c=e.GetDependencyOrder();if(!c||c.length===0)return;let y=c[0];try{U(null,y);}catch(w){throw r.callOnError(w),w}finally{x();}});},batchNotify:c=>{if(!c||c.length===0)return;if(t.createHistoryAction&&t.pushIntoHistory){let w=t.createHistoryAction([c.map(V=>({path:V.path,key:V.key,value:d(V.path).state[V.key]})),c.map(V=>({path:V.path,key:V.key,value:V.value}))],V=>{let q=new Set;V.forEach(ae=>{let de=d(ae.path);de.state[ae.key]=ae.value,m.add(ae.path),q.add(ae.uid);}),x(),q.size>0&&U(null,Array.from(q));});t.pushIntoHistory(w);}let y=new Set;c.forEach(w=>{let V=d(w.path);V.state[w.key]=w.value,m.add(V.uid),y.add(V.uid);}),x(),y.size>0&&U(null,Array.from(y));},useEntangle:b,updateEntangleLevel:M,SetBucket:Y,GetBucket:A,CancelTask:_,stageValueFn:ee,UITrigger:i,UidToNodeMap:o}}function dt(g,e){let t=false,r=false,i=false,l=false,u=new Map,a=[],o=[],p=[],h=[],n=[],P=[],m=[],S=new Map,{GetNextDependency:x,GetPrevDependency:b,GetAllPrevDependency:M,GetAllNextDependency:se,rebuildDirectDependencyMaps:U}=nt(()=>a,()=>p,()=>P,()=>n),_={},ee={};if(e.modules.useHistory){let j=e.modules.useHistory,f;j.isMeshModuleInited?f=j:f=j();let{Undo:W,Redo:D,PushIntoHistory:Q,CreateHistoryAction:le,updateUndoSize:L,updateRedoSize:ne}=f();_.pushIntoHistory=Q,_.createHistoryAction=le,ee={Undo:W,Redo:D,updateUndoSize:L,updateRedoSize:ne};}let z=!!e.modules.useMeshRenderGate,C={};if(z){let j=e.modules.useMeshRenderGate.isMeshModuleInited,f=e.modules.useMeshRenderGate;C=(j?f:f())(()=>ae);}let{onError:te,callOnError:d}=st(),{onSuccess:s,callOnSuccess:H}=at(),{onStart:k,callOnStart:Y}=it(),{emit:A,usePlugin:E,destroyPlugin:T}=ot(),{SetTrace:O,useTrace:v}=et(),G=v();E(G);let c=z?{...C}:{...e.UITrigger},y=yt({useGreedy:e.config.useGreedy,useEntangleStep:e.config.useEntangleStep||100},{GetDependencyOrder:()=>m,GetAllNextDependency:se,GetNextDependency:x,GetPrevDependency:b,GetAllPrevDependency:M,GetUidToLevelMap:()=>S},_,{callOnError:d,callOnSuccess:H,callOnStart:Y,emit:A},c),{SetBucket:w,GetBucket:V,GetGroupByPath:q,GetNodeByPath:ae,notifyAll:de,useEntangle:me,updateEntangleLevel:Ne,CancelTask:Te,stageValueFn:Pe}=y;z&&C.init();let xe={};if(e.modules.useInternalForm){let{uiSchema:j,GetFormData:f}=e.modules.useInternalForm(y,g);xe={uiSchema:j,GetFormData:f};}let Oe={};if(e.modules.useSchemaValidators){let{SetValidators:j}=e.modules.useSchemaValidators(ae);Oe={SetValidators:j};}let{SetRule:ke,SetRules:De}=Ze(ae,w,V,a,p,o,h,u),{SetStrategy:be}=Je(ae,V),oe=rt(a,u),ie=()=>{let j=oe();m=j.steps,S=j.levelMap,Re();},Re=()=>{i&&(Ne(),i=false);},Se=()=>{l||(l=true,Promise.resolve().then(Re).finally(()=>{l=false;}));},Ie=()=>{r||(r=true,Promise.resolve().then(()=>{if(ie(),t){let{directNextMap:j,directPrevMap:f}=U(m.flat());n=j,P=f;}}).finally(()=>{r=false,t=false;}));};return {SetRule:(j,f,W,D)=>{ke(j,f,W,D),t=true,Ie();},SetRules:(j,f,W,D)=>{De(j,f,W,D),t=true,Ie();},SetStrategy:be,useEntangle:j=>{me(j),i=true,Se();},SetTrace:O,usePlugin:E,SetValue:(j,f,W)=>{Re(),ae(j).dependOn(()=>W,f);},GetValue:(j,f="value")=>ae(j).proxy[f],SetValues:j=>{Re(),y.batchNotify(j);},GetGroupByPath:q,notifyAll:async()=>{ie(),await de();},GetAllDependency:()=>a,GetDependencyOrder:()=>m,historyExports:ee,formExports:xe,validatorExports:Oe,batchRenderExport:C,hasRenderGate:()=>z,onError:te,onSuccess:s,onStart:k,scheduler:y,destroyPlugin:T,CancelTask:Te,StageValue:(j,f,W)=>{let D=ae(j);Pe(D.uid,f,W);}}}var Ke=new Map,ht=(g,e,t)=>{try{if(Ke.has(g))throw Error("engineID repeated");let r=dt(e,{config:t.config||{useGreedy:!1},UITrigger:t.UITrigger,modules:t.modules??{},plugins:{}}),{SetRule:i,SetRules:l,SetValues:u,SetStrategy:a,SetValue:o,GetValue:p,usePlugin:h,useEntangle:n,GetGroupByPath:P,notifyAll:m,SetTrace:S,GetAllDependency:N,GetDependencyOrder:x,historyExports:b,formExports:M,validatorExports:se,batchRenderExport:U,hasRenderGate:_,onError:ee,onSuccess:z,onStart:C,scheduler:te,destroyPlugin:d,CancelTask:s,StageValue:H}=r,k={config:{SetRule:i,SetRules:l,SetStrategy:a,notifyAll:m,SetTrace:S,usePlugin:h,hasRenderGate:_,useEntangle:n},data:{SetValue:o,GetValue:p,SetValues:u,GetGroupByPath:P,StageValue:H},dependency:{GetAllDependency:N,GetDependencyOrder:x},hooks:{onError:ee,onSuccess:z,onStart:C}},Y=(T,O,v)=>{!O||typeof O!="object"||Object.keys(O).forEach(G=>{let c=O[G];if(typeof c=="object"&&c!==null)T[G]=T[G]||{},Y(T[G],c,v);else if(typeof c=="function"){let y=G;if(y==="useMeshRenderGate")y="render";else if(y.startsWith("use")){let w=y.slice(3);y=w.charAt(0).toLowerCase()+w.slice(1);}G==="useHistory"&&v.exports.history&&Object.keys(v.exports.history).length>0?T[y]=v.exports.history:G==="useInternalForm"&&v.exports.form&&Object.keys(v.exports.form).length>0?T[y]=v.exports.form:G==="useSchemaValidators"&&v.exports.validator&&Object.keys(v.exports.validator).length>0?T[y]=v.exports.validator:G==="useMeshRenderGate"&&v.exports.render?T[y]=v.exports.render:T[y]=c(v.scheduler,v.Schema);}});},A={...k,destroyPlugin:d,CancelTask:s,modules:{}},E=t.modules;return E&&Y(A.modules,E,{scheduler:te,Schema:e,exports:{history:b,form:M,validator:se,render:U}}),Ke.set(g,A),A}catch(r){throw Error(r)}},xn=()=>(g,e,t)=>ht(g,e,t),An=g=>{let e=Ke.get(g);if(!e)throw Error("Engine not found.");return e},vn=g=>{let e=Ke.get(g);e.destroyPlugin(),e.CancelTask(),Ke.delete(g);};exports.DefaultStrategy=_e;exports.MeshFlowEventsName=Ce;exports.TriggerCause=Le;exports.deleteEngine=vn;exports.useEngine=An;exports.useMeshFlow=ht;exports.useMeshFlowDefiner=xn;exports.useScheduler=yt;
|
package/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Fe=(S=>(S[S.FlowStart=0]="FlowStart",S[S.FlowSuccess=1]="FlowSuccess",S[S.FlowEnd=2]="FlowEnd",S[S.FlowAbort=3]="FlowAbort",S[S.FlowWait=4]="FlowWait",S[S.FlowFire=5]="FlowFire",S[S.NodeStart=6]="NodeStart",S[S.NodeSuccess=7]="NodeSuccess",S[S.NodeProcessing=8]="NodeProcessing",S[S.NodeError=9]="NodeError",S[S.NodePending=10]="NodePending",S[S.NodeRevive=11]="NodeRevive",S[S.NodeIntercept=12]="NodeIntercept",S[S.NodeRelease=13]="NodeRelease",S[S.NodeStagnate=14]="NodeStagnate",S[S.NodeBucketSuccess=15]="NodeBucketSuccess",S[S.EntangleWarn=16]="EntangleWarn",S[S.EntangleBlocked=17]="EntangleBlocked",S))(Fe||{}),Ue=(r=>(r[r.CAUSALITY=0]="CAUSALITY",r[r.INVERSION=1]="INVERSION",r[r.REPERCUSSION=2]="REPERCUSSION",r))(Ue||{});var Ve=(r=>(r.OR="OR",r.PRIORITY="PRIORITY",r.MERGE="MERGE",r))(Ve||{});var Le=class{computedRules=[];getRuleResult(e,t,r){if(e.entityId==="__base__")return e.logic(t);if(!(!e._hasRun||r(e.triggerUids)))return e._lastResult;let i=e.logic(t);return i instanceof Promise?i.then(l=>(e._lastResult=l,e._hasRun=true,l)):(e._lastResult=i,e._hasRun=true,i)}store={OR:(e,t,r)=>{let o,i,l=this.computedRules;for(let s=0;s<l.length;s++){let a=l[s],p=this.getRuleResult(a,e,r);if(p instanceof Promise)return (async()=>{let n=await p;if(a.entityId==="__base__"?i=n:n&&(o=n),typeof o>"u")for(let T=s+1;T<l.length;T++){let f=l[T],m=this.getRuleResult(f,e,r),N=m instanceof Promise?await m:m;if(f.entityId==="__base__"){i=N;continue}if(N){o=f.value;break}}return typeof o>"u"&&(o=i),{res:o,version:t}})();let h=p;if(a.entityId==="__base__"){i=h;continue}if(h){o=a.value;break}}return typeof o>"u"&&(o=i),{res:o,version:t}},PRIORITY:(e,t,r)=>{let o,i=this.computedRules;for(let l=0;l<i.length;l++){let s=i[l],a=this.getRuleResult(s,e,r);if(a instanceof Promise)return (async()=>{let p=await a;if(p!==void 0)return {res:s.value!==void 0?s.value:p,version:t};for(let h=l+1;h<i.length;h++){let n=i[h],T=this.getRuleResult(n,e,r),f=T instanceof Promise?await T:T;if(f!==void 0)return {res:f,version:t}}return {res:void 0,version:t}})();if(a!==void 0)return {res:s.value!==void 0?s.value:a,version:t}}return {res:o,version:t}},MERGE:(e,t,r)=>{let o,i,l=this.computedRules,s=(p,h)=>p===void 0?h:h===void 0?p:Array.isArray(p)&&Array.isArray(h)?[...h,...p]:typeof p=="object"&&typeof h=="object"?{...h,...p}:p;for(let p=0;p<l.length;p++){let h=l[p],n=this.getRuleResult(h,e,r);if(n instanceof Promise)return (async()=>{let f=await n,m=(M,b)=>{if(M.entityId==="__base__")i=s(i,b);else if(b){let S=M.value!==void 0?M.value:b;o=s(o,S);}};m(h,f);for(let M=p+1;M<l.length;M++){let b=l[M],S=this.getRuleResult(b,e,r),ne=S instanceof Promise?await S:S;m(b,ne);}return {res:s(o,i),version:t}})();let T=n;if(h.entityId==="__base__"){i=s(i,T);continue}if(T){let f=h.value!==void 0?h.value:T;o=s(o,f);}}return {res:s(o,i),version:t}}};CurrentStrategy=()=>{};CurrentStrategyType="PRIORITY";getRules=()=>{};constructor(e){this.getRules=e,this.CurrentStrategy=this.store.PRIORITY,this.updateComputedRules();}updateComputedRules(){let e=this.getRules();this.CurrentStrategyType==="PRIORITY"||this.CurrentStrategyType==="MERGE"?this.computedRules=Array.from(e.values()).map(t=>Array.from(t)).flat().sort((t,r)=>r.priority-t.priority):this.computedRules=Array.from(e.values()).map(t=>Array.from(t)).flat();}setStrategy(e){this.CurrentStrategyType=e,this.CurrentStrategy=this.store[e],this.updateComputedRules();}evaluate(e,t,r){return this.CurrentStrategy(e,t,r)}},Ae=class{path;strategy;contract;rules=new Map;isValue=false;id=0;cache=void 0;pendingPromise=null;version=0;deps=new Map;_forceNotify=false;promiseToken=null;useCache=true;effectArray=[];constructor(e,t,r){let o=()=>this.rules;this.strategy=new Le(o),this.path=r,this.isValue=t==="value",this.contract=this.inferType(e),this.cache=e,this.setRule({priority:0,entityId:"__base__",logic:()=>e});}setUseCache(e){this.useCache=e;}forceNotify(){this._forceNotify=true;}isForceNotify(){return this._forceNotify}setStrategy(e){this.strategy.setStrategy(e);}setDefaultRule(e){let t=new Set;t.add(e),this.rules.set(-1,t);}setRules(e,t){t&&this.updateDeps(t);let r=++this.id,o={...e,entityId:r};for(let i of e.triggerUids)this.rules.has(i)||this.rules.set(i,new Set),this.rules.get(i).add(o);return this.strategy.updateComputedRules(),()=>{for(let i of e.triggerUids){let l=this.rules.get(i);l&&(l.delete(o),l.size===0&&(this.rules.delete(i),this.deps.delete(i)));}this.strategy.updateComputedRules();}}updateDeps(e){for(let[t,r,o]of e){if(r.length==0)continue;let i=this.deps.get(t)||Object.create(null);for(let l of r)i[l]=o[l];this.deps.set(t,i);}}setRule(e,t){if(t&&this.updateDeps(t),typeof e.entityId=="string"){this.setDefaultRule(e);return}let r=++this.id,o={...e,entityId:r};if(e)for(let i of e.triggerUids)this.rules.has(i)||this.rules.set(i,new Set),this.rules.get(i).add(o);return this.strategy.updateComputedRules(),()=>{for(let i of e.triggerUids){let l=this.rules.get(i);l&&(l.delete(o),l.size===0&&(this.rules.delete(i),this.deps.delete(i)));}this.strategy.updateComputedRules();}}setSideEffect(e){this.effectArray.push(e);}getSideEffect(){return [...this.effectArray]}evaluate(e){let t=null;if(e.GetToken&&(t=e.GetToken()),this.pendingPromise&&this.promiseToken!==t&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;let r=false;if(typeof e.triggerUid=="number"){r=true,this.deps.size==0&&(r=false);for(let[s,a]of this.deps.entries()){let p=e.getStateByUid(s);if(!p){r=false;break}for(let h in a){let n=a[h],T=p[h];if(typeof n=="object"&&n!==null){r=false;break}if(n!==T){r=false;break}}if(!r)break}}if(r&&this.useCache)return this.cache;this.promiseToken=t;let o=++this.version,i=s=>{if(!s||s.length===0)return true;for(let a of s){let p=this.deps.get(a);if(!p)return true;let h=e.getProxyByUid(a);if(!h)return true;for(let n in p){let T=p[n],f=h[n];if(typeof T=="object"&&T!==null||T!==f)return true}}return false},l=this.strategy.evaluate(e,o,i);if(!(l instanceof Promise)){let{res:s,version:a}=l;return this.finalizeSync(s,a,e,t)}return this.pendingPromise=(async()=>{try{let{res:s,version:a}=await l;return this.finalizeSync(s,a,e,t)}catch(s){throw {path:this.path,error:s}}finally{this.promiseToken===t&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}finalizeSync(e,t,r,o){return o!==this.promiseToken||t<this.version?this.cache:(this.cache=e,this.deps.forEach((i,l)=>{let s=r.getProxyByUid(l);if(!s)return;let a=Object.keys(i);for(let p of a)i[p]=s[p];}),e)}inferType(e){return Array.isArray(e)?"array":typeof e}};var We=(g,e,t)=>{let o=i=>{let l=t.triggerUids.map(p=>{let h=i.getProxyByUid(p);if(t.triggerKeys.length===0)return h;let n={};return t.triggerKeys.forEach(T=>{n[T]=h[T];}),n}),s=Object.create(null);return Object.defineProperty(s,"triggerTargets",{get:()=>l}),Object.defineProperty(s,"affectedTatget",{get:()=>i.getProxyByUid(g)[e]}),t.logic({slot:s})};return {value:t.value,targetUid:g,triggerUids:t.triggerUids,priority:t.priority??10,logic:o}},ze=(g,e,t,r,o,i,l,s)=>{if(!g)throw Error();let a=g,p=(T,f)=>{typeof r[T]>"u"&&(r[T]=[],i[T]=new Set),i[T].add(f),i[T].size>r[T].length&&r[T].push(f),typeof o[f]>"u"&&(o[f]=[],l[f]=new Set),l[f].add(T),l[f].size>o[f].length&&o[f].push(T);};return {SetRule:(T,f,m,N)=>{let M=a(T),b=a(f),S=N.triggerKeys||[],ne=s.get(b.uid)||0,H=s.get(M.uid)||0;ne+=1,H+=1,s.set(b.uid,ne),s.set(M.uid,H);let $=We(b.uid,m,{...N,triggerUids:[M.uid],triggerKeys:S}),Y=[T].map(U=>{let L=a(U);return [L.uid,S,L.proxy]});if(p(M.uid,b.uid),typeof b.nodeBucket[m]=="number"){let U=t(b.nodeBucket[m]);U.setRule($,Y),N.effect&&U.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[m]});}else {let U=b.meta[m],L=new Ae(U,m,f);L.setRule($,Y),N.effect&&L.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[m]}),b.nodeBucket[m]=e(L);}b.state[m]=b.meta[m];let c=t(b.nodeBucket[m]);N.forceNotify&&c.forceNotify(),N.cacheStrategy=="none"&&c.setUseCache(false);},SetRules:(T,f,m,N)=>{let M=a(f),b=s.get(M.uid)||0;b+=1,s.set(M.uid,b);let S=[];for(let c of T){let U=a(c);S.push(U.uid);let L=s.get(U.uid)||0;L+=1,s.set(U.uid,L),p(U.uid,M.uid);}let ne=N.triggerKeys||[],H=We(M.uid,m,{...N,triggerUids:S,triggerKeys:ne}),$=T.map(c=>{let U=a(c);return [U.uid,ne,U.state]});if(typeof M.nodeBucket[m]=="number"){let c=t(M.nodeBucket[m]);c.setRules(H,$),N.effect&&c.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[m]});}else {let c=M.meta[m],U=new Ae(c,m,f);U.setRules(H,$),N.effect&&U.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[m]}),M.nodeBucket[m]=e(U);}M.state[m]=M.meta[m];let Y=t(M.nodeBucket[m]);N.forceNotify&&Y.forceNotify(),N.cacheStrategy=="none"&&Y.setUseCache(false);}}};var qe=(g,e)=>{let t=g||void 0;if(!t)throw Error();return {SetStrategy:(o,i,l)=>{let s=t(o);e(s.nodeBucket[i]).setStrategy(l);}}};function Qe(){let g=new Map,e=new Map,t=new Set,r=(l,s)=>{g.set(l,s);let a=e.get(l);a&&a(s);};return {SetTrace:(l,s)=>{e.set(l,s);let a=g.get(l)||"idle";return s(a),{cancel:()=>{e.delete(l);}}},useTrace:()=>({apply:s=>{s.on(0,()=>{t.forEach(a=>r(a,"idle")),t.clear(),g.clear();}),s.on(13,({path:a,type:p})=>{(p==1||p==2)&&(t.add(a),r(a,"pending"));}),s.on(10,({path:a})=>{t.add(a),(!g.has(a)||g.get(a)==="idle")&&r(a,"pending");}),s.on(6,({path:a})=>{t.add(a),r(a,"calculating");}),s.on(7,({path:a})=>{r(a,"calculated");}),s.on(12,({path:a,type:p})=>{p==3&&r(a,"calculating"),p==6&&r(a,"idle");}),s.on(14,({path:a})=>{r(a,"pending");}),s.on(9,({path:a})=>r(a,"error"));}})}}function Xe(g,e,t,r){return {GetNextDependency:h=>r()[h]||[],GetPrevDependency:h=>t()[h]||[],GetAllPrevDependency:h=>e()[h]||[],GetAllNextDependency:h=>g()[h]||[],rebuildDirectDependencyMaps:h=>{let n=[],T=[],f=g();for(let m of h){let N=f[m]||[];n[m]=N;for(let M=0;M<N.length;M++){let b=N[M];typeof T[b]>"u"&&(T[b]=[]),T[b].push(m);}}return {directNextMap:n,directPrevMap:T}}}}function Ze(g,e){let t=o=>{let i=[],l=[],s=new Map,a=o.size,p=0,h=0;for(let[n,T]of o)T===0&&l.push(n);if(l.length===0&&a>0)throw Error("Circular dependency detected");for(;l.length>0;){i.push([...l]);let n=[];for(let T of l){p++,s.set(T,h);let f=g[T];if(f)for(let m of f){let N=o.get(m)-1;o.set(m,N),N===0&&n.push(m);}}l=n,h++;}if(p<a)throw Error("Circular dependency detected");return {steps:i,levelMap:s}};return ()=>{let o=new Map;for(let i of e.keys()){let l=g[i]||[];o.has(i)||o.set(i,0);for(let s of l){let a=o.get(s)||0;o.set(s,++a);}}return t(o)}}var be=()=>{let g=[];return {on:e=>(g.push(e),()=>{let t=g.indexOf(e);t>-1&&g.splice(t,1);}),call:e=>g.forEach(t=>{t(e);})}};function Je(){let{on:g,call:e}=be();return {onError:g,callOnError:e}}function et(){let{on:g,call:e}=be();return {onSuccess:g,callOnSuccess:e}}var tt=()=>{let g=new Set,e=new Map,t=new Set,r=(s,a)=>{e.get(s)?.forEach(p=>p(a));},o=(s,a)=>(e.has(s)||e.set(s,new Set),e.get(s).add(a),()=>e.get(s)?.delete(a));return {usePlugin:s=>{let a=new Set,p=(n,T)=>{let f=o(n,T);return a.add(f),f};s.apply({on:p}),g.add(s);let h=()=>{a.forEach(n=>n()),a.clear(),g.delete(s),t.delete(h);};return t.add(h),h},emit:r,destroyPlugin:()=>{t.forEach(s=>s()),t.clear(),e.clear(),g.clear();}}};function nt(){let{on:g,call:e}=be();return {onStart:g,callOnStart:e}}var rt=(g={frameQuota:12})=>{let e=performance.now(),t=0,r=false,o=()=>!!navigator?.scheduling?.isInputPending?.({includeContinuous:true});return {getIsFirstFrame:()=>r,reset(){e=performance.now(),t=0,r=true;},shouldYield(){return !r&&(++t&15)!==0?false:!!(performance.now()-e>g.frameQuota||o())},async yieldToMain(){return new Promise(i=>{_e(()=>{e=performance.now(),t=0,r&&(r=false),i();});})}}},_e=g=>{let{port1:e,port2:t}=new MessageChannel;e.onmessage=g,t.postMessage(null);};function st(g,e,t,r,o,i){let l=new Map,s=g.useGreedy,a=null,p=()=>{l.clear();},h={path:null,level:0,targetLevel:0,currentLevel:0,pendingParentsCount:0,active:0,pending:0,blocked:0,nums:0,asyncNums:0},n={path:null,type:0,triggerPath:null,calledBy:0,key:null,value:null,error:null,token:null,duration:null,detail:h};return {TaskRunner:async(f,m)=>{let M=Symbol("token"),b=typeof f=="number"?f:"__NOTIFY_ALL__";l.set(b,M),a=M;let S=false,ne=false;i.reset(),t.Turnstile.nextEpoch();let H=t.GetMaxUid()+3,$=new Array(H).fill(0),Y=0,c=new Uint8Array(H),U=new Int32Array(H),L=new Int32Array(H),d=new Int32Array(H*2),x=0,O=0,k=new Int32Array(H*2),V=0,F=0,v=new Int32Array(H*2),A=0,G=0;m.forEach(R=>{$[R]=1,e.GetAllNextDependency(R).forEach(ae=>{$[ae]=1;});});let _=new Array(H).fill(null),u=[],y=t.Turnstile,P=new Array(H).fill(null).map(()=>[]),W=new Array(H).fill(null).map(()=>[]),q=y.volatileLevels.size>0,re=q?y.hasObserver:R=>false,se=q?y.receiveGhosts:()=>[],Me=q?y.resolveGhosts:()=>[],me=q?y.getTriggerKeys:()=>[],Re=y?.volatileLevels||new Set,ye=-1,ee=e.GetUidToLevelMap(),ie=0,xe=0,Pe=R=>{e.GetAllNextDependency(R).forEach(oe=>{let w=ee.get(oe)||0;w>xe&&(xe=w);});},Ge=new Set;typeof f=="number"&&(c[f]|=16,Ge.add(f),Pe(f),o.flushPathSet.add(f));let we=typeof f=="number"?[f]:m;i.shouldYield()&&(o.requestUpdate(),await i.yieldToMain());let Ie=we.map(async R=>{if(re(R)){let ae=t.GetNodeByUid(R),oe=me(R);if(oe.length>0){let w=se(ae,oe);return w instanceof Promise&&(w=await w),{seed:R,hitTargets:w}}}return {seed:R,hitTargets:[]}});if((await Promise.all(Ie)).forEach(({seed:R,hitTargets:ae})=>{if(ae&&ae.length>0){u.push(...ae);let oe=ee.get(R)||0;ye=Math.max(ye,oe);}}),(u.length>0||we.length>1)&&(o.requestUpdate(),await i.yieldToMain(),l.get(b)!==M))return;let Ce=u.length>0;m.forEach(R=>{if(!Ge.has(R))if(Ce){let ae=ee.get(R)??0;L[R]=ae,c[R]&4||(c[R]|=4,v[A++]=R,G++);let oe=t.GetPathByUid(R);n.path=oe,n.type=2,r.emit(14,n);}else c[R]&1||(c[R]|=1,d[x++]=R,O++),Pe(R);}),typeof f=="number"?ie=ee.get(f)??0:ie=Math.min(...m.map(R=>ee.get(R)??0));let Oe=performance.now(),De=typeof b=="number"?t.GetPathByUid(b):"__NOTIFY_ALL__";n.path=De,n.token=M,r.emit(0,n),r.callOnStart({path:De});let Be=false,Ye=30,je=(R,ae)=>{let oe=false,w=false,j=false,B=t.GetNodeByUid(R),Z=t.GetPathByUid(R),Q=B.calledBy,K=P[R];K.length=0;let C=re(R),I=C?me(R):[],D=E=>{C&&(I.length===0||I.includes(E))&&K.push(E);},le=W[R];le.length=0;let ce=false;if(B.calledBy===1){ce=true,oe=true,o.flushPathSet.add(R);let E=_[R];E&&(K.push(...E),_[R]=null);}let de=(E,J)=>{let te=ee.get(E)??0,pe=t.GetNodeByUid(E),X=t.GetPathByUid(E),he=(Q===1||Q===2)&&te<=ye;he&&c[E]&16&&(c[E]&=-17,n.path=X,n.triggerPath=Z,r.emit(11,n));let ue=0;if(!(c[E]&49)){if(c[E]&2)ue=U[E]-1;else {if(te>ie&&F>Ye){L[E]=te,c[E]&4||(c[E]|=4,v[A++]=E,G++),n.path=X,n.type=7,r.emit(12,n);return}let Se=e.GetPrevDependency(E),z=0;for(let ge of Se){if(c[ge]&16)continue;(ee.get(ge)??0)>ie&&z++;}ue=z;}if(ue<=0){let Se=(c[E]&1)!==0,z=(c[E]&32)!==0;if(Se||z){n.path=X,n.type=z?3:3.1,r.emit(12,n);return}c[E]&2&&(c[E]&=-3,F--),he?pe.calledBy=2:pe.calledBy=0,c[E]&1||(c[E]|=1,d[x++]=E,O++),n.path=X,n.type=J,h.path=Z,r.emit(13,n);}else U[E]=ue,c[E]&2||(c[E]|=2,k[V++]=E,F++);}},Ne=(E=[])=>{if(l.get(b)!==M)return;if(E.length){let te={},pe=B.proxy;for(let X of E){let he=(X.args||[]).reduce((ue,Se)=>(ue[Se]=pe[Se],ue),{});try{let ue=X.fn(he);ue&&typeof ue=="object"&&Object.assign(te,ue);}catch(ue){}}for(let X in te)if(X in B.state)Object.is(B.state[X],te[X])||(B.state[X]=te[X],D(X),oe=true,(B.notifyKeys.size===0||B.notifyKeys.has(X))&&(w=true));else throw {error:`wrong effect in ${String(B.path)}`}}oe&&o.flushPathSet.add(R);let J=(te=[])=>{if(l.get(b)!==M)return;te&&te.length>0&&(u.push(...te),ye=Math.max(ye,ee.get(R)||0)),K.length=0,n.path=Z,n.calledBy=B.calledBy,r.emit(7,n),c[R]|=16;let pe=e.GetNextDependency(R);(w||j)&&(Pe(R),e.GetAllNextDependency(R).forEach(ge=>{$[ge]=1;}));let X=t.GetNodeByUid(R),he=ee.get(R)??0,ue=Re.has(he)||u.length>0;for(let z of pe){let ge=ee.get(z)??0,Te=t.GetPathByUid(z);if(ue&&ge>=he){L[z]=ge,c[z]&4||(c[z]|=4,v[A++]=z,G++),n.path=Te,n.type=2,r.emit(14,n);continue}if(c[z]&16){n.path=Te,n.type=2,r.emit(12,n);continue}if(c[z]&32||(c[z]&1)!==0){n.path=Te,n.type=c[z]&32?3:3.1,r.emit(12,n);continue}if(w||j)de(z,1);else if(c[z]&2)de(z,2);else {let lt=ee.get(z);L[z]=lt,c[z]&4||(c[z]|=4,v[A++]=z,G++,n.path=Te,n.type=1,r.emit(14,n));}}c[R]&32&&(c[R]&=-33,Y--),X.calledBy=0,(()=>{if(!S){S=true;let z=Y,ge=O,Te=F;n.path=Z,n.type=1,h.active=z,h.pending=ge,h.blocked=Te,r.emit(5,n),Ke();}})();};if(re(R)&&K.length>0){let te=se(B,K);te instanceof Promise?te.then(J).catch(ke):J(te);}else J([]);},ke=E=>{n.path=Z,n.error=E,r.emit(9,n);let J=Symbol("abort");l.set(b,J),x=0,O=0,V=0,F=0,A=0,G=0,c.fill(0),Y=0,_.fill(null),r.callOnError(E);},fe=(E,J)=>{E!==B.state[J]&&(B.state[J]=E,oe=true,D(String(J)),n.path=Z,n.key=J,n.value=E,n.calledBy=B.calledBy,r.emit(15,n),(B.notifyKeys.size===0||B.notifyKeys.has(J))&&(w=true)),t.GetBucket(B.nodeBucket[J]).isForceNotify()&&(j=true),(w||j)&&Pe(R);};n.path=Z,n.calledBy=B.calledBy,r.emit(6,n);try{let E=[];for(let J in B.nodeBucket){let te=t.GetBucket(B.nodeBucket[J]);if(E.push(...te.getSideEffect()),ce){r.emit(15,{path:Z,key:String(J),value:B.state[J],calledBy:B.calledBy}),te.isForceNotify()&&(j=!0),(B.notifyKeys.size===0||B.notifyKeys.has(J))&&Pe(R);continue}let pe=te.evaluate({affectKey:J,triggerUid:ae,getProxyByUid:X=>t.GetNodeByUid(X).proxy,getStateByUid:X=>t.GetNodeByUid(X).state,GetToken:()=>M});if(pe instanceof Promise){let X=pe.then(he=>{l.get(b)===M&&fe(he,J);});le.push(X);}else fe(pe,J);}if(le.length>0)return Promise.all(le).then(()=>{Ne(E);}).catch(ke);Ne(E);return}catch(E){ke(E);}},Ke=async()=>{if(l.get(b)!==M){S=false;return}S=true;let R=i.getIsFirstFrame(),ae=0,oe=()=>30,w=0,j=oe();try{for(;l.get(b)===M;){let B=w>=j,Z=i.shouldYield();if(B||Z){if(w>0&&(ae++,(R||ae%2===0)&&o.requestUpdate()),await i.yieldToMain(),l.get(b)!==M)break;w=0,R=i.getIsFirstFrame();}if(O>0&&Y<40){let Q=x,K=0;for(let C=0;C<Q;C++){let I=d[C];if((c[I]&1)===0)continue;if(Y>=40||w>=j||i.shouldYield()){for(let fe=C;fe<x;fe++){let E=d[fe];c[E]&1&&(d[K++]=E);}x=K,O=K;break}let D=t.GetNodeByUid(I),le=t.GetPathByUid(I),ce=ee.get(I)??0,de=e.GetPrevDependency(I),Ne=de.length>1;if((!s||Ne)&&ce>ie){c[I]&=-2,O--;let fe=de.filter(E=>$[E]===1&&(c[E]&16)===0).length;U[I]=fe||0,c[I]&2||(c[I]|=2,k[V++]=I,F++),n.path=le,n.type=fe>0?4:5,h.targetLevel=ce,h.currentLevel=ie,h.pendingParentsCount=fe,r.emit(12,n);continue}c[I]&=-2,O--,(c[I]&32)===0&&(c[I]|=32,Y++),n.path=le,n.calledBy=D.calledBy,r.emit(8,n),je(I,f),w++;}if(x>Q){for(let C=Q;C<x;C++){let I=d[C];c[I]&1&&(d[K++]=I);}x=K,O=x;}else x=K;if(O>0&&Y<40)continue}if(w<j&&s&&F>0&&Y<40){let Q=!1,K=0,C=0;for(let I=0;I<V;I++){let D=k[I];if((c[D]&2)===0)continue;if(U[D]<=0&&K<j){let ce=ee.get(D)??0,de=e.GetPrevDependency(D);if(ce<=ie||de.length<=1){c[D]&=-3,F--,c[D]&1||(c[D]|=1,d[x++]=D,O++),K++,Q=!0;let Ne=t.GetPathByUid(D);n.path=Ne,n.type=4,r.emit(13,n);continue}}k[C++]=D;}if(V=C,K>0)continue;if(Q){if(i.shouldYield()&&(await i.yieldToMain(),l.get(b)!==M))break;continue}}if(Y===0&&O===0){if(y.inFlightCount>0)break;if(u.length>0){let K=!1,C=ie,I=Array.from(new Set(u));u.length=0;for(let D of I){let le=t.GetNodeByUid(D),ce=Me(le);if(ce&&ce.length>0){K=!0,le.calledBy=1,_[D]=ce,c[D]&=-17,c[D]&2&&(c[D]&=-3,F--),c[D]&1||(c[D]|=1,d[x++]=D,O++);let de=ee.get(le.uid)??0;de<C&&(C=de),Pe(le.uid),o.flushPathSet.add(le.uid);}}if(K){if(C<ie&&(ie=C),o.requestUpdate(),i.shouldYield()&&(await i.yieldToMain(),l.get(b)!==M))break;continue}}let Q=1/0;for(let K=0;K<A;K++){let C=v[K];if(c[C]&4){let I=L[C];I<Q&&(Q=I);}}for(let K=0;K<V;K++){let C=k[K];if(c[C]&2){let I=ee.get(C)??0;I>ie&&I<Q&&(Q=I);}}if(Q!==1/0&&Q<=xe){ie=Q;let K=0;for(let I=0;I<A;I++){let D=v[I];c[D]&4&&(L[D]===Q?(c[D]&=-5,G--,c[D]&1||(c[D]|=1,d[x++]=D,O++)):v[K++]=D);}A=K;let C=0;for(let I=0;I<V;I++){let D=k[I];if(c[D]&2)if((ee.get(D)??0)===Q){c[D]&=-3,F--,c[D]&1||(c[D]|=1,d[x++]=D,O++);let ce=t.GetPathByUid(D);n.path=ce,n.type=3,h.level=Q,r.emit(13,n);}else k[C++]=D;}V=C;continue}else {for(let K=0;K<A;K++){let C=v[K];if(c[C]&4){c[C]|=16;let I=t.GetPathByUid(C);n.path=I,n.type=6,r.emit(12,n);}}A=0,G=0;for(let K=0;K<V;K++){let C=k[K];if(c[C]&2){c[C]|=16;let I=t.GetPathByUid(C);n.path=I,n.type=6,r.emit(12,n);}}V=0,F=0;break}}O>0&&Y>=40&&(n.type=2,r.emit(4,n));break}}finally{S=false;let B=Y+F+O,Z=y.inFlightCount||0;if(!(a===M)){n.token=M,r.emit(3,n);return}if(o.requestUpdate(),B===0&&Z===0){if(l.get(b)===M&&!Be){Be=true,n.type=1,r.emit(2,n),y.resetCounters(),_.fill(null);let K=performance.now();ye=-1,l.delete(b),n.token=M,n.duration=(K-Oe).toFixed(2.1)+"ms",r.emit(1,n),Promise.resolve().then(()=>{r.callOnSuccess();});}}else {let K=B===0&&Z>0?3:1;if(n.type=K,h.nums=Y,h.asyncNums=Z,r.emit(4,n),Z>0&&!ne){ne=true;let C=()=>{a===M&&(y.inFlightCount,y.inFlightCount===0?_e(()=>{y.inFlightCount===0?Ke():requestAnimationFrame(C);}):requestAnimationFrame(C));};requestAnimationFrame(C);}}}};Ke();},CancelTask:p}}function He(g){let{path:e,uid:t,type:r,meta:o,dirtySignal:i,state:l}=g,s=null,a=["path","uid","type","dependOn","nodeBucket"],h={path:e,uid:t,type:r,meta:o,dirtySignal:i,createView:(n={})=>{if(s&&Object.keys(n).length===0)return s;let T=new Proxy(n,{get(f,m){let N=m;return Reflect.has(f,m)?Reflect.get(f,m):N in g.state?g.state[N]:N in g?g[N]:o&&N in o?o[N]:Reflect.get(f,m)},set(f,m,N){return false},ownKeys(f){let m=new Set([...Reflect.ownKeys(f),...Object.keys(l||{}),...Object.keys(o||{}),...a]);return Array.from(m)},getOwnPropertyDescriptor(f,m){let N=m;return Reflect.has(f,m)||l&&N in l||o&&N in o||a.includes(N)?{enumerable:true,configurable:true}:Reflect.getOwnPropertyDescriptor(f,m)}});return s=T,T}};return "children"in g?{...h,children:g.children}:{...h,state:g.state,nodeBucket:g.nodeBucket,notifyKeys:g.notifyKeys,dependOn:g.dependOn,calledBy:0,get proxy(){return s}}}var at=(g,e,t,r,o,i,l)=>{let s=g.useEntangleStep,a=[],p=[],h=new Set,n=r,m=t,N=0,M=0,b=0,S=100,ne=()=>{let d={link:null,impactNode:null,impactUid:-1,hitTargetUids:null,isDirty:false,propose:null};return d.propose={set:(x,O,k=1)=>{d.epoch===b&&O!==d.impactNode.state[x]&&(d.link.count++,(!p[d.impactUid]||p[d.impactUid].length===0)&&(p[d.impactUid]=[],M++),p[d.impactUid].push({key:x,value:O,weight:k}),d.isDirty||(d.hitTargetUids.push(d.impactUid),d.isDirty=true));},update:(x,O,k="add")=>{d.epoch===b&&(d.link.count++,(!p[d.impactUid]||p[d.impactUid].length===0)&&(p[d.impactUid]=[],M++),p[d.impactUid].push({key:x,delta:O,op:k,weight:1}),d.isDirty||(d.hitTargetUids.push(d.impactUid),d.isDirty=true));},patch:(x,O)=>{d.epoch===b&&(d.link.count++,(!p[d.impactUid]||p[d.impactUid].length===0)&&(p[d.impactUid]=[],M++),p[d.impactUid].push({key:x,patch:O,weight:1}),d.isDirty||(d.hitTargetUids.push(d.impactUid),d.isDirty=true));}},d},H=Array.from({length:S},ne),$=S-1,Y=(d,x,O)=>{let k=x.path,V=d.impact;if(d.count>=s){l.emit("entangle:blocked",{observer:k,target:V,count:d.count});return}let F=n(V),v=d.isProxy?x.proxy:x,A=d.isProxy?F.proxy:F;if(d.filter&&!d.filter(v,A))return;let G,_=true;$<0?(G=ne(),_=false):G=H[$--];let u=b;G.epoch=u,G.isDirty=false,G.link=d,G.impactNode=F,G.impactUid=F.uid,G.hitTargetUids=O;let y=d.emit(v,A,G.propose);if(y instanceof Promise||y&&typeof y.then=="function")return N++,(async()=>{try{await y;}catch(P){l.emit("node:error",{path:k,error:P}),l.onError({path:k,error:P});}finally{u===b&&N--,_&&(H[++$]=G);}})();_&&(H[++$]=G);};return {useEntangle:d=>{let{cause:x,impact:O,via:k,emit:V,filter:F,isProxy:v}=d;if(!k||k.length===0){l.emit("entangle:warn",{path:x,type:"no_keys"});return}let G=n(x).uid;a[G]||(a[G]=new Map);let _=a[G];for(let u=0;u<k.length;u++){let y=k[u];_.has(y)||_.set(y,[]),_.get(y).push({impact:O,emit:V,filter:F,count:0,isProxy:!!v});}},updateEntangleLevel:()=>{let d=m();h.clear();for(let x=0;x<a.length;x++)if(a[x]!==void 0){let O=d.get(x)||0;h.add(O);}},Turnstile:{volatileLevels:h,get inFlightCount(){return N},get hasPendingGhosts(){return M>0},nextEpoch:()=>{b++,N=0,M=0,p.length=0;},hasObserver:d=>a[d]!==void 0,getTriggerKeys:d=>{let x=a[d];return x?Array.from(x.keys()):[]},receiveGhosts:(d,x=[])=>{let O=d.uid,k=[],V=a[O];if(!V||x.length===0)return k;let F=[];for(let u=0;u<x.length;u++){let y=V.get(x[u]);if(y)for(let P=0;P<y.length;P++)F.push(y[P]);}let v=0,A=false,G=null;for(;v<F.length;v++){if(e.shouldYield()){A=true;break}let u=Y(F[v],d,k);if(u){G=u,A=true,v++;break}}let _=()=>{if(k.length<=1)return k;let u=[],y=Object.create(null);for(let P=0;P<k.length;P++){let W=k[P];y[W]||(y[W]=true,u.push(W));}return u};return A?(async()=>{for(G&&await G,e.shouldYield()&&await e.yieldToMain();v<F.length;){let u=[],y=Math.min(v+S,F.length);for(;v<y;v++){let P=Y(F[v],d,k);P&&u.push(P);}u.length>0&&await Promise.all(u.map(async P=>{await P,e.shouldYield()&&await e.yieldToMain();})),e.shouldYield()&&await e.yieldToMain();}return _()})():_()},resolveGhosts:d=>{let x=d.uid,O=p[x];if(!O||O.length===0)return [];let k=[],V=Object.create(null);for(let F=0;F<O.length;F++){let v=O[F];V[v.key]||(V[v.key]=[]),V[v.key].push(v);}for(let F in V){let v=V[F],A=d.state[F],G,_=-1/0,u=false;for(let y=0;y<v.length;y++){let P=v[y];if(P.patch!==void 0&&(A=P.patch(A)),P.value!==void 0){let W=P.weight??1;W>=_&&(_=W,G=P.value,u=true);}}u&&(A=G);for(let y=0;y<v.length;y++){let P=v[y];if(P.delta!==void 0)switch(P.op||"add"){case "add":A=(typeof A=="number"?A:0)+P.delta;break;case "remove":A=Array.isArray(A)?A.filter(q=>q!==P.delta):A;break;case "intersect":A=Array.isArray(A)?A.filter(q=>P.delta.includes(q)):P.delta;break;case "union":{let q=Array.isArray(A)?A:[],re=Array.isArray(P.delta)?P.delta:[P.delta];A=[...new Set([...q,...re])];break}case "merge":{let q=typeof A=="object"&&A!==null&&!Array.isArray(A)?A:{},re=typeof P.delta=="object"&&P.delta!==null&&!Array.isArray(P.delta)?P.delta:{};A={...q,...re};break}}}Object.is(d.state[F],A)||(d.state[F]=A,k.push(F));}return p[x]=[],M--,k.length>0?k:[]},resetCounters:()=>{for(let d=0;d<a.length;d++){let x=a[d];if(x)for(let O of x.values())for(let k=0;k<O.length;k++)O[k].count=0;}}}}};function ot(g,e,t,r,o){let i=rt(),l=0,s=new Map,a=[],p=[],h=[],n=[],T=false,f=new Set,N=async()=>{let u=Array.from(f);if(f.clear(),"signalTrigger"in o&&typeof o.signalTrigger=="function")for(let y of u){let P=d(y);o.signalTrigger(P.dirtySignal);}else "emit"in o&&o.emit(u);},M=()=>{T||(T=true,requestAnimationFrame(()=>{try{for(;f.size>0;)N();}finally{T=false;}}));},{useEntangle:b,updateEntangleLevel:S,Turnstile:ne}=at({useEntangleStep:g.useEntangleStep},i,e.GetUidToLevelMap,L,d,x,{emit:r.emit,onError:r.callOnError}),{TaskRunner:H,CancelTask:$}=st({useGreedy:g.useGreedy},e,{GetNodeByPath:L,GetNodeByUid:d,GetPathByUid:x,GetBucket:V,GetMaxUid:F,Turnstile:ne},r,{requestUpdate:M,flushPathSet:f},i),Y=u=>{throw new Error(`[MeshFlow] Duplicate Path: ${u}`)},c=u=>{s.has(u.path)&&Y(String(u.path));let y=++l,P={path:u.path,getNode:re=>L(re)},W=(re,se="value")=>{let Me=re({...P}),me=L(u.path);if(!Object.is(me.state[se],Me)){if(t.createHistoryAction&&t.pushIntoHistory){let Re=t.createHistoryAction([{path:u.path,value:me.state[se]},{path:u.path,value:Me}],ye=>{let ee=L(ye.path);ee.state[se]=ye.value,v(ye.path);});t.pushIntoHistory(Re);}me.state[se]=Me,v(u.path);}},q=He({uid:y,type:u.type,path:u.path,state:u.state,meta:u.meta,nodeBucket:{},dirtySignal:"signalCreator"in o?o.signalCreator():void 0,notifyKeys:u.notifyKeys,dependOn:W});return s.set(q.path,y),h[y]=q.path,a[y]=q,q},U=u=>{s.has(u.path)&&Y(String(u.path));let y=++l,P=He({uid:y,type:u.type,path:u.path,state:{},meta:u,nodeBucket:{},children:u.children});return s.set(P.path,y),p[y]=P,P};function L(u){let y=s.get(u),P=a[y];if(!P)throw Error("Wrong id");return P}function d(u){let y=a[u];if(!y)throw Error("Wrong id");return y}function x(u){return h[u]}function O(u){let y=s.get(u);return p[y]}function k(u){return n.push(u)-1}function V(u){let y=n[u];if(!y)throw Error("Wrong id");return y}function F(){return l}let v=u=>{let y=L(u);if(!y)throw Error("Wrong id");f.add(y.uid),M();let P=e.GetNextDependency(y.uid);A(y.uid,P);};function A(u,y){H(u,y);}return {registerNode:c,registerGroupNode:U,GetNodeByPath:L,GetGroupByPath:O,notify:v,notifyAll:async()=>{Promise.resolve().then(async()=>{let u=e.GetDependencyOrder();if(!u||u.length===0)return;let y=u[0];try{H(null,y);}catch(P){throw r.callOnError(P),P}finally{M();}});},batchNotify:u=>{if(!u||u.length===0)return;if(t.createHistoryAction&&t.pushIntoHistory){let P=t.createHistoryAction([u.map(W=>({path:W.path,key:W.key,value:L(W.path).state[W.key]})),u.map(W=>({path:W.path,key:W.key,value:W.value}))],W=>{let q=new Set;W.forEach(re=>{let se=L(re.path);se.state[re.key]=re.value,f.add(re.path),q.add(re.uid);}),M(),q.size>0&&H(null,Array.from(q));});t.pushIntoHistory(P);}let y=new Set;u.forEach(P=>{let W=L(P.path);W.state[P.key]=P.value,f.add(W.uid),y.add(W.uid);}),M(),y.size>0&&H(null,Array.from(y));},useEntangle:b,updateEntangleLevel:S,SetBucket:k,GetBucket:V,CancelTask:$,UITrigger:o,UidToNodeMap:a}}function it(g,e){let t=false,r=false,o=false,i=false,l=new Map,s=[],a=[],p=[],h=[],n=[],T=[],f=[],m=new Map,{GetNextDependency:M,GetPrevDependency:b,GetAllPrevDependency:S,GetAllNextDependency:ne,rebuildDirectDependencyMaps:H}=Xe(()=>s,()=>p,()=>T,()=>n),$={},Y={};if(e.modules.useHistory){let w=e.modules.useHistory,j;w.isMeshModuleInited?j=w:j=w();let{Undo:B,Redo:Z,PushIntoHistory:Q,CreateHistoryAction:K,updateUndoSize:C,updateRedoSize:I}=j();$.pushIntoHistory=Q,$.createHistoryAction=K,Y={Undo:B,Redo:Z,updateUndoSize:C,updateRedoSize:I};}let c=!!e.modules.useMeshRenderGate,U={};if(c){let w=e.modules.useMeshRenderGate.isMeshModuleInited,j=e.modules.useMeshRenderGate;U=(w?j:j())(()=>se);}let{onError:L,callOnError:d}=Je(),{onSuccess:x,callOnSuccess:O}=et(),{onStart:k,callOnStart:V}=nt(),{emit:F,usePlugin:v,destroyPlugin:A}=tt(),{SetTrace:G,useTrace:_}=Qe(),u=_();v(u);let y=c?{...U}:{...e.UITrigger},P=ot({useGreedy:e.config.useGreedy,useEntangleStep:e.config.useEntangleStep||100},{GetDependencyOrder:()=>f,GetAllNextDependency:ne,GetNextDependency:M,GetPrevDependency:b,GetAllPrevDependency:S,GetUidToLevelMap:()=>m},$,{callOnError:d,callOnSuccess:O,callOnStart:V,emit:F},y),{SetBucket:W,GetBucket:q,GetGroupByPath:re,GetNodeByPath:se,notifyAll:Me,useEntangle:me,updateEntangleLevel:Re,CancelTask:ye}=P;c&&U.init();let ee={};if(e.modules.useInternalForm){let{uiSchema:w,GetFormData:j}=e.modules.useInternalForm(P,g);ee={uiSchema:w,GetFormData:j};}let ie={};if(e.modules.useSchemaValidators){let{SetValidators:w}=e.modules.useSchemaValidators(se);ie={SetValidators:w};}let{SetRule:xe,SetRules:Pe}=ze(se,W,q,s,p,a,h,l),{SetStrategy:Ge}=qe(se,q),we=Ze(s,l),Ie=()=>{let w=we();f=w.steps,m=w.levelMap,Ee();},Ee=()=>{o&&(Re(),o=false);},Ce=()=>{i||(i=true,Promise.resolve().then(Ee).finally(()=>{i=false;}));},Oe=()=>{r||(r=true,Promise.resolve().then(()=>{if(Ie(),t){let{directNextMap:w,directPrevMap:j}=H(f.flat());n=w,T=j;}}).finally(()=>{r=false,t=false;}));};return {SetRule:(w,j,B,Z)=>{xe(w,j,B,Z),t=true,Oe();},SetRules:(w,j,B,Z)=>{Pe(w,j,B,Z),t=true,Oe();},SetStrategy:Ge,useEntangle:w=>{me(w),o=true,Ce();},SetTrace:G,usePlugin:v,SetValue:(w,j,B)=>{Ee(),se(w).dependOn(()=>B,j);},GetValue:(w,j="value")=>se(w).proxy[j],SetValues:w=>{Ee(),P.batchNotify(w);},GetGroupByPath:re,notifyAll:async()=>{Ie(),await Me();},GetAllDependency:()=>s,GetDependencyOrder:()=>f,historyExports:Y,formExports:ee,validatorExports:ie,batchRenderExport:U,hasRenderGate:()=>c,onError:L,onSuccess:x,onStart:k,scheduler:P,destroyPlugin:A,CancelTask:ye}}var ve=new Map,ut=(g,e,t)=>{try{if(ve.has(g))throw Error("engineID repeated");let r=it(e,{config:t.config||{useGreedy:!1},UITrigger:t.UITrigger,modules:t.modules??{},plugins:{}}),{SetRule:o,SetRules:i,SetValues:l,SetStrategy:s,SetValue:a,GetValue:p,usePlugin:h,useEntangle:n,GetGroupByPath:T,notifyAll:f,SetTrace:m,GetAllDependency:N,GetDependencyOrder:M,historyExports:b,formExports:S,validatorExports:ne,batchRenderExport:H,hasRenderGate:$,onError:Y,onSuccess:c,onStart:U,scheduler:L,destroyPlugin:d,CancelTask:x}=r,O={config:{SetRule:o,SetRules:i,SetStrategy:s,notifyAll:f,SetTrace:m,usePlugin:h,hasRenderGate:$,useEntangle:n},data:{SetValue:a,GetValue:p,SetValues:l,GetGroupByPath:T},dependency:{GetAllDependency:N,GetDependencyOrder:M},hooks:{onError:Y,onSuccess:c,onStart:U}},k=(v,A,G)=>{!A||typeof A!="object"||Object.keys(A).forEach(_=>{let u=A[_];if(typeof u=="object"&&u!==null)v[_]=v[_]||{},k(v[_],u,G);else if(typeof u=="function"){let y=_;if(y==="useMeshRenderGate")y="render";else if(y.startsWith("use")){let P=y.slice(3);y=P.charAt(0).toLowerCase()+P.slice(1);}_==="useHistory"&&G.exports.history&&Object.keys(G.exports.history).length>0?v[y]=G.exports.history:_==="useInternalForm"&&G.exports.form&&Object.keys(G.exports.form).length>0?v[y]=G.exports.form:_==="useSchemaValidators"&&G.exports.validator&&Object.keys(G.exports.validator).length>0?v[y]=G.exports.validator:_==="useMeshRenderGate"&&G.exports.render?v[y]=G.exports.render:v[y]=u(G.scheduler,G.Schema);}});},V={...O,destroyPlugin:d,CancelTask:x,modules:{}},F=t.modules;return F&&k(V.modules,F,{scheduler:L,Schema:e,exports:{history:b,form:S,validator:ne,render:H}}),ve.set(g,V),V}catch(r){throw Error(r)}},Sn=()=>(g,e,t)=>ut(g,e,t),Mn=g=>{let e=ve.get(g);if(!e)throw Error("Engine not found.");return e},Tn=g=>{let e=ve.get(g);e.destroyPlugin(),e.CancelTask(),ve.delete(g);};export{Ve as DefaultStrategy,Fe as MeshFlowEventsName,Ue as TriggerCause,Tn as deleteEngine,Mn as useEngine,ut as useMeshFlow,Sn as useMeshFlowDefiner,ot as useScheduler};
|
|
1
|
+
var Ce=(M=>(M[M.FlowStart=0]="FlowStart",M[M.FlowSuccess=1]="FlowSuccess",M[M.FlowEnd=2]="FlowEnd",M[M.FlowAbort=3]="FlowAbort",M[M.FlowWait=4]="FlowWait",M[M.FlowFire=5]="FlowFire",M[M.NodeStart=6]="NodeStart",M[M.NodeSuccess=7]="NodeSuccess",M[M.NodeProcessing=8]="NodeProcessing",M[M.NodeError=9]="NodeError",M[M.NodePending=10]="NodePending",M[M.NodeRevive=11]="NodeRevive",M[M.NodeIntercept=12]="NodeIntercept",M[M.NodeRelease=13]="NodeRelease",M[M.NodeStagnate=14]="NodeStagnate",M[M.NodeBucketSuccess=15]="NodeBucketSuccess",M[M.EntangleWarn=16]="EntangleWarn",M[M.EntangleBlocked=17]="EntangleBlocked",M))(Ce||{}),Le=(r=>(r[r.CAUSALITY=0]="CAUSALITY",r[r.INVERSION=1]="INVERSION",r[r.REPERCUSSION=2]="REPERCUSSION",r))(Le||{});var _e=(r=>(r.OR="OR",r.PRIORITY="PRIORITY",r.MERGE="MERGE",r))(_e||{});var He=class{computedRules=[];getRuleResult(e,t,r){if(e.entityId==="__base__")return e.logic(t);if(!(!e._hasRun||r(e.triggerUids)))return e._lastResult;let l=e.logic(t);return l instanceof Promise?l.then(u=>(e._lastResult=u,e._hasRun=true,u)):(e._lastResult=l,e._hasRun=true,l)}store={OR:(e,t,r)=>{let i,l,u=this.computedRules;for(let a=0;a<u.length;a++){let o=u[a],p=this.getRuleResult(o,e,r);if(p instanceof Promise)return (async()=>{let n=await p;if(o.entityId==="__base__"?l=n:n&&(i=n),typeof i>"u")for(let P=a+1;P<u.length;P++){let m=u[P],S=this.getRuleResult(m,e,r),N=S instanceof Promise?await S:S;if(m.entityId==="__base__"){l=N;continue}if(N){i=m.value;break}}return typeof i>"u"&&(i=l),{res:i,version:t}})();let h=p;if(o.entityId==="__base__"){l=h;continue}if(h){i=o.value;break}}return typeof i>"u"&&(i=l),{res:i,version:t}},PRIORITY:(e,t,r)=>{let i,l=this.computedRules;for(let u=0;u<l.length;u++){let a=l[u],o=this.getRuleResult(a,e,r);if(o instanceof Promise)return (async()=>{let p=await o;if(p!==void 0)return {res:a.value!==void 0?a.value:p,version:t};for(let h=u+1;h<l.length;h++){let n=l[h],P=this.getRuleResult(n,e,r),m=P instanceof Promise?await P:P;if(m!==void 0)return {res:m,version:t}}return {res:void 0,version:t}})();if(o!==void 0)return {res:a.value!==void 0?a.value:o,version:t}}return {res:i,version:t}},MERGE:(e,t,r)=>{let i,l,u=this.computedRules,a=(p,h)=>p===void 0?h:h===void 0?p:Array.isArray(p)&&Array.isArray(h)?[...h,...p]:typeof p=="object"&&typeof h=="object"?{...h,...p}:p;for(let p=0;p<u.length;p++){let h=u[p],n=this.getRuleResult(h,e,r);if(n instanceof Promise)return (async()=>{let m=await n,S=(x,b)=>{if(x.entityId==="__base__")l=a(l,b);else if(b){let M=x.value!==void 0?x.value:b;i=a(i,M);}};S(h,m);for(let x=p+1;x<u.length;x++){let b=u[x],M=this.getRuleResult(b,e,r),se=M instanceof Promise?await M:M;S(b,se);}return {res:a(i,l),version:t}})();let P=n;if(h.entityId==="__base__"){l=a(l,P);continue}if(P){let m=h.value!==void 0?h.value:P;i=a(i,m);}}return {res:a(i,l),version:t}}};CurrentStrategy=()=>{};CurrentStrategyType="PRIORITY";getRules=()=>{};constructor(e){this.getRules=e,this.CurrentStrategy=this.store.PRIORITY,this.updateComputedRules();}updateComputedRules(){let e=this.getRules();this.CurrentStrategyType==="PRIORITY"||this.CurrentStrategyType==="MERGE"?this.computedRules=Array.from(e.values()).map(t=>Array.from(t)).flat().sort((t,r)=>r.priority-t.priority):this.computedRules=Array.from(e.values()).map(t=>Array.from(t)).flat();}setStrategy(e){this.CurrentStrategyType=e,this.CurrentStrategy=this.store[e],this.updateComputedRules();}evaluate(e,t,r){return this.CurrentStrategy(e,t,r)}},we=class{path;strategy;contract;rules=new Map;isValue=false;id=0;cache=void 0;pendingPromise=null;version=0;deps=new Map;_forceNotify=false;promiseToken=null;useCache=true;effectArray=[];constructor(e,t,r){let i=()=>this.rules;this.strategy=new He(i),this.path=r,this.isValue=t==="value",this.contract=this.inferType(e),this.cache=e,this.setRule({priority:0,entityId:"__base__",logic:()=>e});}setUseCache(e){this.useCache=e;}forceNotify(){this._forceNotify=true;}isForceNotify(){return this._forceNotify}setStrategy(e){this.strategy.setStrategy(e);}setDefaultRule(e){let t=new Set;t.add(e),this.rules.set(-1,t);}setRules(e,t){t&&this.updateDeps(t);let r=++this.id,i={...e,entityId:r};for(let l of e.triggerUids)this.rules.has(l)||this.rules.set(l,new Set),this.rules.get(l).add(i);return this.strategy.updateComputedRules(),()=>{for(let l of e.triggerUids){let u=this.rules.get(l);u&&(u.delete(i),u.size===0&&(this.rules.delete(l),this.deps.delete(l)));}this.strategy.updateComputedRules();}}updateDeps(e){for(let[t,r,i]of e){if(r.length==0)continue;let l=this.deps.get(t)||Object.create(null);for(let u of r)l[u]=i[u];this.deps.set(t,l);}}setRule(e,t){if(t&&this.updateDeps(t),typeof e.entityId=="string"){this.setDefaultRule(e);return}let r=++this.id,i={...e,entityId:r};if(e)for(let l of e.triggerUids)this.rules.has(l)||this.rules.set(l,new Set),this.rules.get(l).add(i);return this.strategy.updateComputedRules(),()=>{for(let l of e.triggerUids){let u=this.rules.get(l);u&&(u.delete(i),u.size===0&&(this.rules.delete(l),this.deps.delete(l)));}this.strategy.updateComputedRules();}}setSideEffect(e){this.effectArray.push(e);}getSideEffect(){return [...this.effectArray]}evaluate(e){let t=null;if(e.GetToken&&(t=e.GetToken()),this.pendingPromise&&this.promiseToken!==t&&(this.pendingPromise=null,this.promiseToken=null),this.pendingPromise)return this.pendingPromise;let r=false;if(typeof e.triggerUid=="number"){r=true,this.deps.size==0&&(r=false);for(let[a,o]of this.deps.entries()){let p=e.getStateByUid(a);if(!p){r=false;break}for(let h in o){let n=o[h],P=p[h];if(typeof n=="object"&&n!==null){r=false;break}if(n!==P){r=false;break}}if(!r)break}}if(r&&this.useCache)return this.cache;this.promiseToken=t;let i=++this.version,l=a=>{if(!a||a.length===0)return true;for(let o of a){let p=this.deps.get(o);if(!p)return true;let h=e.getProxyByUid(o);if(!h)return true;for(let n in p){let P=p[n],m=h[n];if(typeof P=="object"&&P!==null||P!==m)return true}}return false},u=this.strategy.evaluate(e,i,l);if(!(u instanceof Promise)){let{res:a,version:o}=u;return this.finalizeSync(a,o,e,t)}return this.pendingPromise=(async()=>{try{let{res:a,version:o}=await u;return this.finalizeSync(a,o,e,t)}catch(a){throw {path:this.path,error:a}}finally{this.promiseToken===t&&(this.pendingPromise=null,this.promiseToken=null);}})(),this.pendingPromise}finalizeSync(e,t,r,i){return i!==this.promiseToken||t<this.version?this.cache:(this.cache=e,this.deps.forEach((l,u)=>{let a=r.getProxyByUid(u);if(!a)return;let o=Object.keys(l);for(let p of o)l[p]=a[p];}),e)}inferType(e){return Array.isArray(e)?"array":typeof e}};var Xe=(g,e,t)=>{let i=l=>{let u=t.triggerUids.map(p=>{let h=l.getProxyByUid(p);if(t.triggerKeys.length===0)return h;let n={};return t.triggerKeys.forEach(P=>{n[P]=h[P];}),n}),a=Object.create(null);return Object.defineProperty(a,"triggerTargets",{get:()=>u}),Object.defineProperty(a,"affectedTatget",{get:()=>l.getProxyByUid(g)[e]}),t.logic({slot:a})};return {value:t.value,targetUid:g,triggerUids:t.triggerUids,priority:t.priority??10,logic:i}},Ze=(g,e,t,r,i,l,u,a)=>{if(!g)throw Error();let o=g,p=(P,m)=>{typeof r[P]>"u"&&(r[P]=[],l[P]=new Set),l[P].add(m),l[P].size>r[P].length&&r[P].push(m),typeof i[m]>"u"&&(i[m]=[],u[m]=new Set),u[m].add(P),u[m].size>i[m].length&&i[m].push(P);};return {SetRule:(P,m,S,N)=>{let x=o(P),b=o(m),M=N.triggerKeys||[],se=a.get(b.uid)||0,U=a.get(x.uid)||0;se+=1,U+=1,a.set(b.uid,se),a.set(x.uid,U);let _=Xe(b.uid,S,{...N,triggerUids:[x.uid],triggerKeys:M}),ee=[P].map(C=>{let te=o(C);return [te.uid,M,te.proxy]});if(p(x.uid,b.uid),typeof b.nodeBucket[S]=="number"){let C=t(b.nodeBucket[S]);C.setRule(_,ee),N.effect&&C.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[S]});}else {let C=b.meta[S],te=new we(C,S,m);te.setRule(_,ee),N.effect&&te.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[S]}),b.nodeBucket[S]=e(te);}b.state[S]=b.meta[S];let z=t(b.nodeBucket[S]);N.forceNotify&&z.forceNotify(),N.cacheStrategy=="none"&&z.setUseCache(false);},SetRules:(P,m,S,N)=>{let x=o(m),b=a.get(x.uid)||0;b+=1,a.set(x.uid,b);let M=[];for(let z of P){let C=o(z);M.push(C.uid);let te=a.get(C.uid)||0;te+=1,a.set(C.uid,te),p(C.uid,x.uid);}let se=N.triggerKeys||[],U=Xe(x.uid,S,{...N,triggerUids:M,triggerKeys:se}),_=P.map(z=>{let C=o(z);return [C.uid,se,C.state]});if(typeof x.nodeBucket[S]=="number"){let z=t(x.nodeBucket[S]);z.setRules(U,_),N.effect&&z.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[S]});}else {let z=x.meta[S],C=new we(z,S,m);C.setRules(U,_),N.effect&&C.setSideEffect({fn:N.effect,args:N.effectArgs?N.effectArgs:[S]}),x.nodeBucket[S]=e(C);}x.state[S]=x.meta[S];let ee=t(x.nodeBucket[S]);N.forceNotify&&ee.forceNotify(),N.cacheStrategy=="none"&&ee.setUseCache(false);}}};var Je=(g,e)=>{let t=g||void 0;if(!t)throw Error();return {SetStrategy:(i,l,u)=>{let a=t(i);e(a.nodeBucket[l]).setStrategy(u);}}};function et(){let g=new Map,e=new Map,t=new Set,r=(u,a)=>{g.set(u,a);let o=e.get(u);o&&o(a);};return {SetTrace:(u,a)=>{e.set(u,a);let o=g.get(u)||"idle";return a(o),{cancel:()=>{e.delete(u);}}},useTrace:()=>({apply:a=>{a.on(0,()=>{t.forEach(o=>r(o,"idle")),t.clear(),g.clear();}),a.on(13,({path:o,type:p})=>{(p==1||p==2)&&(t.add(o),r(o,"pending"));}),a.on(10,({path:o})=>{t.add(o),(!g.has(o)||g.get(o)==="idle")&&r(o,"pending");}),a.on(6,({path:o})=>{t.add(o),r(o,"calculating");}),a.on(7,({path:o})=>{r(o,"calculated");}),a.on(12,({path:o,type:p})=>{p==3&&r(o,"calculating"),p==6&&r(o,"idle");}),a.on(14,({path:o})=>{r(o,"pending");}),a.on(9,({path:o})=>r(o,"error"));}})}}function nt(g,e,t,r){return {GetNextDependency:h=>r()[h]||[],GetPrevDependency:h=>t()[h]||[],GetAllPrevDependency:h=>e()[h]||[],GetAllNextDependency:h=>g()[h]||[],rebuildDirectDependencyMaps:h=>{let n=[],P=[],m=g();for(let S of h){let N=m[S]||[];n[S]=N;for(let x=0;x<N.length;x++){let b=N[x];typeof P[b]>"u"&&(P[b]=[]),P[b].push(S);}}return {directNextMap:n,directPrevMap:P}}}}function rt(g,e){let t=i=>{let l=[],u=[],a=new Map,o=i.size,p=0,h=0;for(let[n,P]of i)P===0&&u.push(n);if(u.length===0&&o>0)throw Error("Circular dependency detected");for(;u.length>0;){l.push([...u]);let n=[];for(let P of u){p++,a.set(P,h);let m=g[P];if(m)for(let S of m){let N=i.get(S)-1;i.set(S,N),N===0&&n.push(S);}}u=n,h++;}if(p<o)throw Error("Circular dependency detected");return {steps:l,levelMap:a}};return ()=>{let i=new Map;for(let l of e.keys()){let u=g[l]||[];i.has(l)||i.set(l,0);for(let a of u){let o=i.get(a)||0;i.set(a,++o);}}return t(i)}}var Ge=()=>{let g=[];return {on:e=>(g.push(e),()=>{let t=g.indexOf(e);t>-1&&g.splice(t,1);}),call:e=>g.forEach(t=>{t(e);})}};function st(){let{on:g,call:e}=Ge();return {onError:g,callOnError:e}}function at(){let{on:g,call:e}=Ge();return {onSuccess:g,callOnSuccess:e}}var ot=()=>{let g=new Set,e=new Map,t=new Set,r=(a,o)=>{e.get(a)?.forEach(p=>p(o));},i=(a,o)=>(e.has(a)||e.set(a,new Set),e.get(a).add(o),()=>e.get(a)?.delete(o));return {usePlugin:a=>{let o=new Set,p=(n,P)=>{let m=i(n,P);return o.add(m),m};a.apply({on:p}),g.add(a);let h=()=>{o.forEach(n=>n()),o.clear(),g.delete(a),t.delete(h);};return t.add(h),h},emit:r,destroyPlugin:()=>{t.forEach(a=>a()),t.clear(),e.clear(),g.clear();}}};function it(){let{on:g,call:e}=Ge();return {onStart:g,callOnStart:e}}var lt=(g={frameQuota:12})=>{let e=performance.now(),t=0,r=false,i=()=>!!navigator?.scheduling?.isInputPending?.({includeContinuous:true});return {getIsFirstFrame:()=>r,reset(){e=performance.now(),t=0,r=true;},shouldYield(){return !r&&(++t&15)!==0?false:!!(performance.now()-e>g.frameQuota||i())},async yieldToMain(){return new Promise(l=>{Ye(()=>{e=performance.now(),t=0,r&&(r=false),l();});})}}},Ye=g=>{let{port1:e,port2:t}=new MessageChannel;e.onmessage=g,t.postMessage(null);};function ut(g,e,t,r,i,l){let u=new Map,a=g.useGreedy,o=null,p=()=>{u.clear();},h={path:null,level:0,targetLevel:0,currentLevel:0,pendingParentsCount:0,active:0,pending:0,blocked:0,nums:0,asyncNums:0},n={path:null,type:0,triggerPath:null,calledBy:0,key:null,value:null,error:null,token:null,duration:null,detail:h},P=false,m=[],S=null,N=(b,M,se)=>{m.push({uid:b,key:M,value:se}),!P&&(S||(S=Promise.resolve().then(()=>{S=null,P||x(null,[]);})));},x=async(b,M)=>{let U=Symbol("token"),_=typeof b=="number"?b:"__NOTIFY_ALL__";u.set(_,U),o=U,P=true;let ee=false,z=false;l.reset(),t.Turnstile.nextEpoch();let C=t.GetMaxUid()+3,te=new Array(C).fill(0),d=0,s=new Uint8Array(C),H=new Int32Array(C),k=new Int32Array(C),Y=new Int32Array(C*2),A=0,E=0,T=new Int32Array(C*2),O=0,v=0,G=new Int32Array(C*2),c=0,y=0;M.forEach(f=>{te[f]=1,e.GetAllNextDependency(f).forEach(W=>{te[W]=1;});});let w=new Array(C).fill(null),V=[],q=t.Turnstile,ae=new Array(C).fill(null).map(()=>[]),de=new Array(C).fill(null).map(()=>[]),me=[],Ne=()=>{if(m.length===0)return false;let f=false,W=1/0;for(;m.length>0;){let{uid:D,key:Q,value:le}=m.shift(),L=t.GetNodeByUid(D);if(me.includes(D)||me.push(D),!Object.is(L.state[Q],le)){f=true,L.state[Q]=le,i.flushPathSet.add(D),L.calledBy=1;let ne=w[D]||[];ne.includes(Q)||ne.push(Q),w[D]=ne,s[D]&=-17,s[D]&2&&(s[D]&=-3,v--),s[D]&1||(s[D]|=1,Y[A++]=D,E++);let X=e.GetUidToLevelMap().get(D)??0;X<W&&(W=X),Se(D);}}return f&&(ie===void 0||ie>W)&&(ie=W),f},Te=q.volatileLevels.size>0,Pe=Te?q.hasObserver:f=>false,xe=Te?q.receiveGhosts:()=>[],Oe=Te?q.resolveGhosts:()=>[],ke=Te?q.getTriggerKeys:()=>[],De=q?.volatileLevels||new Set,be=-1,oe=e.GetUidToLevelMap(),ie=0,Re=0,Se=f=>{e.GetAllNextDependency(f).forEach(D=>{let Q=oe.get(D)||0;Q>Re&&(Re=Q);});};Ne();let Ie=new Set;typeof b=="number"&&(s[b]|=16,Ie.add(b),Se(b),i.flushPathSet.add(b));let Be=typeof b=="number"?[b]:[...M,...me];l.shouldYield()&&(i.requestUpdate(),await l.yieldToMain());let We=Be.map(async f=>{if(Pe(f)){let W=t.GetNodeByUid(f),D=ke(f);if(D.length>0){let Q=xe(W,D);return Q instanceof Promise&&(Q=await Q),{seed:f,hitTargets:Q}}}return {seed:f,hitTargets:[]}});if((await Promise.all(We)).forEach(({seed:f,hitTargets:W})=>{if(W&&W.length>0){V.push(...W);let D=oe.get(f)||0;be=Math.max(be,D);}}),(V.length>0||Be.length>1)&&(i.requestUpdate(),await l.yieldToMain(),u.get(_)!==U))return;let ze=V.length>0;M.forEach(f=>{if(!Ie.has(f))if(ze){let W=oe.get(f)??0;k[f]=W,s[f]&4||(s[f]|=4,G[c++]=f,y++);let D=t.GetPathByUid(f);n.path=D,n.type=2,r.emit(14,n);}else s[f]&1||(s[f]|=1,Y[A++]=f,E++),Se(f);}),typeof b=="number"?ie=oe.get(b)??0:ie=Math.min(...M.map(f=>oe.get(f)??0));let qe=performance.now(),Ue=typeof _=="number"?t.GetPathByUid(_):"__NOTIFY_ALL__";n.path=Ue,n.token=U,r.emit(0,n),r.callOnStart({path:Ue});let Ve=false,Qe=30,$e=(f,W)=>{let D=false,Q=false,le=false,L=t.GetNodeByUid(f),ne=t.GetPathByUid(f),X=L.calledBy,K=ae[f];K.length=0;let B=Pe(f),I=B?ke(f):[],F=R=>{B&&(I.length===0||I.includes(R))&&K.push(R);},ue=de[f];ue.length=0;let ye=false;if(L.calledBy===1){ye=true,D=true,i.flushPathSet.add(f);let R=w[f];R&&(K.push(...R),w[f]=null);}let fe=(R,J)=>{let re=oe.get(R)??0,he=t.GetNodeByUid(R),Z=t.GetPathByUid(R),ge=(X===1||X===2)&&re<=be;ge&&s[R]&16&&(s[R]&=-17,n.path=Z,n.triggerPath=ne,r.emit(11,n));let ce=0;if(!(s[R]&49)){if(s[R]&2)ce=H[R]-1;else {if(re>ie&&v>Qe){k[R]=re,s[R]&4||(s[R]|=4,G[c++]=R,y++),n.path=Z,n.type=7,r.emit(12,n);return}let Ee=e.GetPrevDependency(R),$=0;for(let Me of Ee){if(s[Me]&16)continue;(oe.get(Me)??0)>ie&&$++;}ce=$;}if(ce<=0){let Ee=(s[R]&1)!==0,$=(s[R]&32)!==0;if(Ee||$){n.path=Z,n.type=$?3:3.1,r.emit(12,n);return}s[R]&2&&(s[R]&=-3,v--),ge?he.calledBy=2:he.calledBy=0,s[R]&1||(s[R]|=1,Y[A++]=R,E++),n.path=Z,n.type=J,h.path=ne,r.emit(13,n);}else H[R]=ce,s[R]&2||(s[R]|=2,T[O++]=R,v++);}},ve=(R=[])=>{if(u.get(_)!==U)return;if(R.length){let re={},he=L.proxy;for(let Z of R){let ge=(Z.args||[]).reduce((ce,Ee)=>(ce[Ee]=he[Ee],ce),{});try{let ce=Z.fn(ge);ce&&typeof ce=="object"&&Object.assign(re,ce);}catch(ce){}}for(let Z in re)if(Z in L.state)Object.is(L.state[Z],re[Z])||(L.state[Z]=re[Z],F(Z),D=true,(L.notifyKeys.size===0||L.notifyKeys.has(Z))&&(Q=true));else throw {error:`wrong effect in ${String(L.path)}`}}D&&i.flushPathSet.add(f);let J=(re=[])=>{if(u.get(_)!==U)return;re&&re.length>0&&(V.push(...re),be=Math.max(be,oe.get(f)||0)),K.length=0,n.path=ne,n.calledBy=L.calledBy,r.emit(7,n),s[f]|=16;let he=e.GetNextDependency(f);(Q||le)&&(Se(f),e.GetAllNextDependency(f).forEach(Me=>{te[Me]=1;}));let Z=t.GetNodeByUid(f),ge=oe.get(f)??0,ce=De.has(ge)||V.length>0;for(let $ of he){let Me=oe.get($)??0,Ae=t.GetPathByUid($);if(ce&&Me>=ge){k[$]=Me,s[$]&4||(s[$]|=4,G[c++]=$,y++),n.path=Ae,n.type=2,r.emit(14,n);continue}if(s[$]&16){n.path=Ae,n.type=2,r.emit(12,n);continue}if(s[$]&32||(s[$]&1)!==0){n.path=Ae,n.type=s[$]&32?3:3.1,r.emit(12,n);continue}if(Q||le)fe($,1);else if(s[$]&2)fe($,2);else {let pt=oe.get($);k[$]=pt,s[$]&4||(s[$]|=4,G[c++]=$,y++,n.path=Ae,n.type=1,r.emit(14,n));}}s[f]&32&&(s[f]&=-33,d--),Z.calledBy=0,(()=>{if(!ee){ee=true;let $=d,Me=E,Ae=v;n.path=ne,n.type=1,h.active=$,h.pending=Me,h.blocked=Ae,r.emit(5,n),j();}})();};if(Pe(f)&&K.length>0){let re=xe(L,K);re instanceof Promise?re.then(J).catch(Fe):J(re);}else J([]);},Fe=R=>{n.path=ne,n.error=R,r.emit(9,n);let J=Symbol("abort");u.set(_,J),A=0,E=0,O=0,v=0,c=0,y=0,s.fill(0),d=0,w.fill(null),P=false,r.callOnError(R);},pe=(R,J)=>{R!==L.state[J]&&(L.state[J]=R,D=true,F(String(J)),n.path=ne,n.key=J,n.value=R,n.calledBy=L.calledBy,r.emit(15,n),(L.notifyKeys.size===0||L.notifyKeys.has(J))&&(Q=true)),t.GetBucket(L.nodeBucket[J]).isForceNotify()&&(le=true),(Q||le)&&Se(f);};n.path=ne,n.calledBy=L.calledBy,r.emit(6,n);try{let R=[];for(let J in L.nodeBucket){let re=t.GetBucket(L.nodeBucket[J]);if(R.push(...re.getSideEffect()),ye){r.emit(15,{path:ne,key:String(J),value:L.state[J],calledBy:L.calledBy}),re.isForceNotify()&&(le=!0),(L.notifyKeys.size===0||L.notifyKeys.has(J))&&Se(f);continue}let he=re.evaluate({affectKey:J,triggerUid:W,getProxyByUid:Z=>t.GetNodeByUid(Z).proxy,getStateByUid:Z=>t.GetNodeByUid(Z).state,GetToken:()=>U});if(he instanceof Promise){let Z=he.then(ge=>{u.get(_)===U&&pe(ge,J);});ue.push(Z);}else pe(he,J);}if(ue.length>0)return Promise.all(ue).then(()=>{ve(R);}).catch(Fe);ve(R);return}catch(R){Fe(R);}},j=async()=>{if(u.get(_)!==U){ee=false;return}ee=true;let f=l.getIsFirstFrame(),W=0,D=()=>30,Q=0,le=D();try{for(;u.get(_)===U;){let L=Q>=le,ne=l.shouldYield();if(L||ne){if(Q>0&&(W++,(f||W%2===0)&&i.requestUpdate()),await l.yieldToMain(),u.get(_)!==U)break;Q=0,f=l.getIsFirstFrame();}if(E>0&&d<40){let X=A,K=0;for(let B=0;B<X;B++){let I=Y[B];if((s[I]&1)===0)continue;if(d>=40||Q>=le||l.shouldYield()){for(let pe=B;pe<A;pe++){let R=Y[pe];s[R]&1&&(Y[K++]=R);}A=K,E=K;break}let F=t.GetNodeByUid(I),ue=t.GetPathByUid(I),ye=oe.get(I)??0,fe=e.GetPrevDependency(I),ve=fe.length>1;if((!a||ve)&&ye>ie){s[I]&=-2,E--;let pe=fe.filter(R=>te[R]===1&&(s[R]&16)===0).length;H[I]=pe||0,s[I]&2||(s[I]|=2,T[O++]=I,v++),n.path=ue,n.type=pe>0?4:5,h.targetLevel=ye,h.currentLevel=ie,h.pendingParentsCount=pe,r.emit(12,n);continue}s[I]&=-2,E--,(s[I]&32)===0&&(s[I]|=32,d++),n.path=ue,n.calledBy=F.calledBy,r.emit(8,n),$e(I,b),Q++;}if(A>X){for(let B=X;B<A;B++){let I=Y[B];s[I]&1&&(Y[K++]=I);}A=K,E=A;}else A=K;if(E>0&&d<40)continue}if(Q<le&&a&&v>0&&d<40){let X=!1,K=0,B=0;for(let I=0;I<O;I++){let F=T[I];if((s[F]&2)===0)continue;if(H[F]<=0&&K<le){let ye=oe.get(F)??0,fe=e.GetPrevDependency(F);if(ye<=ie||fe.length<=1){s[F]&=-3,v--,s[F]&1||(s[F]|=1,Y[A++]=F,E++),K++,X=!0;let ve=t.GetPathByUid(F);n.path=ve,n.type=4,r.emit(13,n);continue}}T[B++]=F;}if(O=B,K>0)continue;if(X){if(l.shouldYield()&&(await l.yieldToMain(),u.get(_)!==U))break;continue}}if(d===0&&E===0){if(q.inFlightCount>0)break;if(V.length>0){let K=!1,B=ie,I=Array.from(new Set(V));V.length=0;for(let F of I){let ue=t.GetNodeByUid(F),ye=Oe(ue);if(ye&&ye.length>0){K=!0,ue.calledBy=1,w[F]=ye,s[F]&=-17,s[F]&2&&(s[F]&=-3,v--),s[F]&1||(s[F]|=1,Y[A++]=F,E++);let fe=oe.get(ue.uid)??0;fe<B&&(B=fe),Se(ue.uid),i.flushPathSet.add(ue.uid);}}if(K){if(B<ie&&(ie=B),i.requestUpdate(),l.shouldYield()&&(await l.yieldToMain(),u.get(_)!==U))break;continue}}let X=1/0;for(let K=0;K<c;K++){let B=G[K];if(s[B]&4){let I=k[B];I<X&&(X=I);}}for(let K=0;K<O;K++){let B=T[K];if(s[B]&2){let I=oe.get(B)??0;I>ie&&I<X&&(X=I);}}if(X!==1/0&&X<=Re){ie=X;let K=0;for(let I=0;I<c;I++){let F=G[I];s[F]&4&&(k[F]===X?(s[F]&=-5,y--,s[F]&1||(s[F]|=1,Y[A++]=F,E++)):G[K++]=F);}c=K;let B=0;for(let I=0;I<O;I++){let F=T[I];if(s[F]&2)if((oe.get(F)??0)===X){s[F]&=-3,v--,s[F]&1||(s[F]|=1,Y[A++]=F,E++);let ye=t.GetPathByUid(F);n.path=ye,n.type=3,h.level=X,r.emit(13,n);}else T[B++]=F;}O=B;continue}else {for(let K=0;K<c;K++){let B=G[K];if(s[B]&4){s[B]|=16;let I=t.GetPathByUid(B);n.path=I,n.type=6,r.emit(12,n);}}c=0,y=0;for(let K=0;K<O;K++){let B=T[K];if(s[B]&2){s[B]|=16;let I=t.GetPathByUid(B);n.path=I,n.type=6,r.emit(12,n);}}O=0,v=0;break}}E>0&&d>=40&&(n.type=2,r.emit(4,n));break}}finally{ee=false;let L=d+v+E,ne=q.inFlightCount||0;if(!(o===U)){n.token=U,r.emit(3,n);return}if(i.requestUpdate(),L===0&&ne===0){if(u.get(_)===U&&!Ve){Ve=true,n.type=1,r.emit(2,n),q.resetCounters(),w.fill(null),P=false;let K=performance.now();be=-1,u.delete(_),n.token=U,n.duration=(K-qe).toFixed(2.1)+"ms",r.emit(1,n),Promise.resolve().then(()=>{r.callOnSuccess();});}}else {let K=L===0&&ne>0?3:1;if(n.type=K,h.nums=d,h.asyncNums=ne,r.emit(4,n),ne>0&&!z){z=true;let B=()=>{if(o!==U){z=false;return}if(q.inFlightCount===0){z=false,Ne(),Ye(()=>{o===U&&q.inFlightCount===0&&j();});return}else q.inFlightCount,requestAnimationFrame(B);};requestAnimationFrame(B);}}}};j();};return {TaskRunner:x,CancelTask:p,stageValueFn:N}}function je(g){let{path:e,uid:t,type:r,meta:i,dirtySignal:l,state:u}=g,a=null,o=["path","uid","type","dependOn","nodeBucket"],h={path:e,uid:t,type:r,meta:i,dirtySignal:l,createView:(n={})=>{if(a&&Object.keys(n).length===0)return a;let P=new Proxy(n,{get(m,S){let N=S;return Reflect.has(m,S)?Reflect.get(m,S):N in g.state?g.state[N]:N in g?g[N]:i&&N in i?i[N]:Reflect.get(m,S)},set(m,S,N){return false},ownKeys(m){let S=new Set([...Reflect.ownKeys(m),...Object.keys(u||{}),...Object.keys(i||{}),...o]);return Array.from(S)},getOwnPropertyDescriptor(m,S){let N=S;return Reflect.has(m,S)||u&&N in u||i&&N in i||o.includes(N)?{enumerable:true,configurable:true}:Reflect.getOwnPropertyDescriptor(m,S)}});return a=P,P}};return "children"in g?{...h,children:g.children}:{...h,state:g.state,nodeBucket:g.nodeBucket,notifyKeys:g.notifyKeys,dependOn:g.dependOn,calledBy:0,get proxy(){return a}}}var ct=(g,e,t,r,i,l,u)=>{let a=g.useEntangleStep,o=[],p=[],h=new Set,n=r,S=t,N=0,x=0,b=0,M=100,se=()=>{let d={link:null,impactNode:null,impactUid:-1,hitTargetUids:null,isDirty:false,propose:null};return d.propose={set:(s,H,k=1)=>{d.epoch===b&&H!==d.impactNode.state[s]&&(d.link.count++,(!p[d.impactUid]||p[d.impactUid].length===0)&&(p[d.impactUid]=[],x++),p[d.impactUid].push({key:s,value:H,weight:k}),d.isDirty||(d.hitTargetUids.push(d.impactUid),d.isDirty=true));},update:(s,H,k="add")=>{d.epoch===b&&(d.link.count++,(!p[d.impactUid]||p[d.impactUid].length===0)&&(p[d.impactUid]=[],x++),p[d.impactUid].push({key:s,delta:H,op:k,weight:1}),d.isDirty||(d.hitTargetUids.push(d.impactUid),d.isDirty=true));},patch:(s,H)=>{d.epoch===b&&(d.link.count++,(!p[d.impactUid]||p[d.impactUid].length===0)&&(p[d.impactUid]=[],x++),p[d.impactUid].push({key:s,patch:H,weight:1}),d.isDirty||(d.hitTargetUids.push(d.impactUid),d.isDirty=true));}},d},U=Array.from({length:M},se),_=M-1,ee=(d,s,H)=>{let k=s.path,Y=d.impact;if(d.count>=a){u.emit("entangle:blocked",{observer:k,target:Y,count:d.count});return}let A=n(Y),E=d.isProxy?s.proxy:s,T=d.isProxy?A.proxy:A;if(d.filter&&!d.filter(E,T))return;let O,v=true;_<0?(O=se(),v=false):O=U[_--];let G=b;O.epoch=G,O.isDirty=false,O.link=d,O.impactNode=A,O.impactUid=A.uid,O.hitTargetUids=H;let c=d.emit(E,T,O.propose);if(c instanceof Promise||c&&typeof c.then=="function")return N++,(async()=>{try{await c;}catch(y){u.emit("node:error",{path:k,error:y}),u.onError({path:k,error:y});}finally{G===b&&N--,v&&(U[++_]=O);}})();v&&(U[++_]=O);};return {useEntangle:d=>{let{cause:s,impact:H,via:k,emit:Y,filter:A,isProxy:E}=d;if(!k||k.length===0){u.emit("entangle:warn",{path:s,type:"no_keys"});return}let O=n(s).uid;o[O]||(o[O]=new Map);let v=o[O];for(let G=0;G<k.length;G++){let c=k[G];v.has(c)||v.set(c,[]),v.get(c).push({impact:H,emit:Y,filter:A,count:0,isProxy:!!E});}},updateEntangleLevel:()=>{let d=S();h.clear();for(let s=0;s<o.length;s++)if(o[s]!==void 0){let H=d.get(s)||0;h.add(H);}},Turnstile:{volatileLevels:h,get inFlightCount(){return N},get hasPendingGhosts(){return x>0},nextEpoch:()=>{b++,N=0,x=0,p.length=0;},hasObserver:d=>o[d]!==void 0,getTriggerKeys:d=>{let s=o[d];return s?Array.from(s.keys()):[]},receiveGhosts:(d,s=[])=>{let H=d.uid,k=[],Y=o[H];if(!Y||s.length===0)return k;let A=[];for(let G=0;G<s.length;G++){let c=Y.get(s[G]);if(c)for(let y=0;y<c.length;y++)A.push(c[y]);}let E=0,T=false,O=null;for(;E<A.length;E++){if(e.shouldYield()){T=true;break}let G=ee(A[E],d,k);if(G){O=G,T=true,E++;break}}let v=()=>{if(k.length<=1)return k;let G=[],c=Object.create(null);for(let y=0;y<k.length;y++){let w=k[y];c[w]||(c[w]=true,G.push(w));}return G};return T?(async()=>{for(O&&await O,e.shouldYield()&&await e.yieldToMain();E<A.length;){let G=[],c=Math.min(E+M,A.length);for(;E<c;E++){let y=ee(A[E],d,k);y&&G.push(y);}G.length>0&&await Promise.all(G.map(async y=>{await y,e.shouldYield()&&await e.yieldToMain();})),e.shouldYield()&&await e.yieldToMain();}return v()})():v()},resolveGhosts:d=>{let s=d.uid,H=p[s];if(!H||H.length===0)return [];let k=[],Y=Object.create(null);for(let A=0;A<H.length;A++){let E=H[A];Y[E.key]||(Y[E.key]=[]),Y[E.key].push(E);}for(let A in Y){let E=Y[A],T=d.state[A],O,v=-1/0,G=false;for(let c=0;c<E.length;c++){let y=E[c];if(y.patch!==void 0&&(T=y.patch(T)),y.value!==void 0){let w=y.weight??1;w>=v&&(v=w,O=y.value,G=true);}}G&&(T=O);for(let c=0;c<E.length;c++){let y=E[c];if(y.delta!==void 0)switch(y.op||"add"){case "add":T=(typeof T=="number"?T:0)+y.delta;break;case "remove":T=Array.isArray(T)?T.filter(V=>V!==y.delta):T;break;case "intersect":T=Array.isArray(T)?T.filter(V=>y.delta.includes(V)):y.delta;break;case "union":{let V=Array.isArray(T)?T:[],q=Array.isArray(y.delta)?y.delta:[y.delta];T=[...new Set([...V,...q])];break}case "merge":{let V=typeof T=="object"&&T!==null&&!Array.isArray(T)?T:{},q=typeof y.delta=="object"&&y.delta!==null&&!Array.isArray(y.delta)?y.delta:{};T={...V,...q};break}}}Object.is(d.state[A],T)||(d.state[A]=T,k.push(A));}return p[s]=[],x--,k.length>0?k:[]},resetCounters:()=>{for(let d=0;d<o.length;d++){let s=o[d];if(s)for(let H of s.values())for(let k=0;k<H.length;k++)H[k].count=0;}}}}};function yt(g,e,t,r,i){let l=lt(),u=0,a=new Map,o=[],p=[],h=[],n=[],P=false,m=new Set,N=async()=>{let c=Array.from(m);if(m.clear(),"signalTrigger"in i&&typeof i.signalTrigger=="function")for(let y of c){let w=s(y);i.signalTrigger(w.dirtySignal);}else "emit"in i&&i.emit(c);},x=()=>{P||(P=true,requestAnimationFrame(()=>{try{for(;m.size>0;)N();}finally{P=false;}}));},{useEntangle:b,updateEntangleLevel:M,Turnstile:se}=ct({useEntangleStep:g.useEntangleStep},l,e.GetUidToLevelMap,d,s,H,{emit:r.emit,onError:r.callOnError}),{TaskRunner:U,CancelTask:_,stageValueFn:ee}=ut({useGreedy:g.useGreedy},e,{GetNodeByPath:d,GetNodeByUid:s,GetPathByUid:H,GetBucket:A,GetMaxUid:E,Turnstile:se},r,{requestUpdate:x,flushPathSet:m},l),z=c=>{throw new Error(`[MeshFlow] Duplicate Path: ${c}`)},C=c=>{a.has(c.path)&&z(String(c.path));let y=++u,w={path:c.path,getNode:ae=>d(ae)},V=(ae,de="value")=>{let me=ae({...w}),Ne=d(c.path);if(!Object.is(Ne.state[de],me)){if(t.createHistoryAction&&t.pushIntoHistory){let Te=t.createHistoryAction([{path:c.path,value:Ne.state[de]},{path:c.path,value:me}],Pe=>{let xe=d(Pe.path);xe.state[de]=Pe.value,T(Pe.path);});t.pushIntoHistory(Te);}Ne.state[de]=me,T(c.path);}},q=je({uid:y,type:c.type,path:c.path,state:c.state,meta:c.meta,nodeBucket:{},dirtySignal:"signalCreator"in i?i.signalCreator():void 0,notifyKeys:c.notifyKeys,dependOn:V});return a.set(q.path,y),h[y]=q.path,o[y]=q,q},te=c=>{a.has(c.path)&&z(String(c.path));let y=++u,w=je({uid:y,type:c.type,path:c.path,state:{},meta:c,nodeBucket:{},children:c.children});return a.set(w.path,y),p[y]=w,w};function d(c){let y=a.get(c),w=o[y];if(!w)throw Error("Wrong id");return w}function s(c){let y=o[c];if(!y)throw Error("Wrong id");return y}function H(c){return h[c]}function k(c){let y=a.get(c);return p[y]}function Y(c){return n.push(c)-1}function A(c){let y=n[c];if(!y)throw Error("Wrong id");return y}function E(){return u}let T=c=>{let y=d(c);if(!y)throw Error("Wrong id");m.add(y.uid),x();let w=e.GetNextDependency(y.uid);O(y.uid,w);};function O(c,y){U(c,y);}return {registerNode:C,registerGroupNode:te,GetNodeByPath:d,GetGroupByPath:k,notify:T,notifyAll:async()=>{Promise.resolve().then(async()=>{let c=e.GetDependencyOrder();if(!c||c.length===0)return;let y=c[0];try{U(null,y);}catch(w){throw r.callOnError(w),w}finally{x();}});},batchNotify:c=>{if(!c||c.length===0)return;if(t.createHistoryAction&&t.pushIntoHistory){let w=t.createHistoryAction([c.map(V=>({path:V.path,key:V.key,value:d(V.path).state[V.key]})),c.map(V=>({path:V.path,key:V.key,value:V.value}))],V=>{let q=new Set;V.forEach(ae=>{let de=d(ae.path);de.state[ae.key]=ae.value,m.add(ae.path),q.add(ae.uid);}),x(),q.size>0&&U(null,Array.from(q));});t.pushIntoHistory(w);}let y=new Set;c.forEach(w=>{let V=d(w.path);V.state[w.key]=w.value,m.add(V.uid),y.add(V.uid);}),x(),y.size>0&&U(null,Array.from(y));},useEntangle:b,updateEntangleLevel:M,SetBucket:Y,GetBucket:A,CancelTask:_,stageValueFn:ee,UITrigger:i,UidToNodeMap:o}}function dt(g,e){let t=false,r=false,i=false,l=false,u=new Map,a=[],o=[],p=[],h=[],n=[],P=[],m=[],S=new Map,{GetNextDependency:x,GetPrevDependency:b,GetAllPrevDependency:M,GetAllNextDependency:se,rebuildDirectDependencyMaps:U}=nt(()=>a,()=>p,()=>P,()=>n),_={},ee={};if(e.modules.useHistory){let j=e.modules.useHistory,f;j.isMeshModuleInited?f=j:f=j();let{Undo:W,Redo:D,PushIntoHistory:Q,CreateHistoryAction:le,updateUndoSize:L,updateRedoSize:ne}=f();_.pushIntoHistory=Q,_.createHistoryAction=le,ee={Undo:W,Redo:D,updateUndoSize:L,updateRedoSize:ne};}let z=!!e.modules.useMeshRenderGate,C={};if(z){let j=e.modules.useMeshRenderGate.isMeshModuleInited,f=e.modules.useMeshRenderGate;C=(j?f:f())(()=>ae);}let{onError:te,callOnError:d}=st(),{onSuccess:s,callOnSuccess:H}=at(),{onStart:k,callOnStart:Y}=it(),{emit:A,usePlugin:E,destroyPlugin:T}=ot(),{SetTrace:O,useTrace:v}=et(),G=v();E(G);let c=z?{...C}:{...e.UITrigger},y=yt({useGreedy:e.config.useGreedy,useEntangleStep:e.config.useEntangleStep||100},{GetDependencyOrder:()=>m,GetAllNextDependency:se,GetNextDependency:x,GetPrevDependency:b,GetAllPrevDependency:M,GetUidToLevelMap:()=>S},_,{callOnError:d,callOnSuccess:H,callOnStart:Y,emit:A},c),{SetBucket:w,GetBucket:V,GetGroupByPath:q,GetNodeByPath:ae,notifyAll:de,useEntangle:me,updateEntangleLevel:Ne,CancelTask:Te,stageValueFn:Pe}=y;z&&C.init();let xe={};if(e.modules.useInternalForm){let{uiSchema:j,GetFormData:f}=e.modules.useInternalForm(y,g);xe={uiSchema:j,GetFormData:f};}let Oe={};if(e.modules.useSchemaValidators){let{SetValidators:j}=e.modules.useSchemaValidators(ae);Oe={SetValidators:j};}let{SetRule:ke,SetRules:De}=Ze(ae,w,V,a,p,o,h,u),{SetStrategy:be}=Je(ae,V),oe=rt(a,u),ie=()=>{let j=oe();m=j.steps,S=j.levelMap,Re();},Re=()=>{i&&(Ne(),i=false);},Se=()=>{l||(l=true,Promise.resolve().then(Re).finally(()=>{l=false;}));},Ie=()=>{r||(r=true,Promise.resolve().then(()=>{if(ie(),t){let{directNextMap:j,directPrevMap:f}=U(m.flat());n=j,P=f;}}).finally(()=>{r=false,t=false;}));};return {SetRule:(j,f,W,D)=>{ke(j,f,W,D),t=true,Ie();},SetRules:(j,f,W,D)=>{De(j,f,W,D),t=true,Ie();},SetStrategy:be,useEntangle:j=>{me(j),i=true,Se();},SetTrace:O,usePlugin:E,SetValue:(j,f,W)=>{Re(),ae(j).dependOn(()=>W,f);},GetValue:(j,f="value")=>ae(j).proxy[f],SetValues:j=>{Re(),y.batchNotify(j);},GetGroupByPath:q,notifyAll:async()=>{ie(),await de();},GetAllDependency:()=>a,GetDependencyOrder:()=>m,historyExports:ee,formExports:xe,validatorExports:Oe,batchRenderExport:C,hasRenderGate:()=>z,onError:te,onSuccess:s,onStart:k,scheduler:y,destroyPlugin:T,CancelTask:Te,StageValue:(j,f,W)=>{let D=ae(j);Pe(D.uid,f,W);}}}var Ke=new Map,ht=(g,e,t)=>{try{if(Ke.has(g))throw Error("engineID repeated");let r=dt(e,{config:t.config||{useGreedy:!1},UITrigger:t.UITrigger,modules:t.modules??{},plugins:{}}),{SetRule:i,SetRules:l,SetValues:u,SetStrategy:a,SetValue:o,GetValue:p,usePlugin:h,useEntangle:n,GetGroupByPath:P,notifyAll:m,SetTrace:S,GetAllDependency:N,GetDependencyOrder:x,historyExports:b,formExports:M,validatorExports:se,batchRenderExport:U,hasRenderGate:_,onError:ee,onSuccess:z,onStart:C,scheduler:te,destroyPlugin:d,CancelTask:s,StageValue:H}=r,k={config:{SetRule:i,SetRules:l,SetStrategy:a,notifyAll:m,SetTrace:S,usePlugin:h,hasRenderGate:_,useEntangle:n},data:{SetValue:o,GetValue:p,SetValues:u,GetGroupByPath:P,StageValue:H},dependency:{GetAllDependency:N,GetDependencyOrder:x},hooks:{onError:ee,onSuccess:z,onStart:C}},Y=(T,O,v)=>{!O||typeof O!="object"||Object.keys(O).forEach(G=>{let c=O[G];if(typeof c=="object"&&c!==null)T[G]=T[G]||{},Y(T[G],c,v);else if(typeof c=="function"){let y=G;if(y==="useMeshRenderGate")y="render";else if(y.startsWith("use")){let w=y.slice(3);y=w.charAt(0).toLowerCase()+w.slice(1);}G==="useHistory"&&v.exports.history&&Object.keys(v.exports.history).length>0?T[y]=v.exports.history:G==="useInternalForm"&&v.exports.form&&Object.keys(v.exports.form).length>0?T[y]=v.exports.form:G==="useSchemaValidators"&&v.exports.validator&&Object.keys(v.exports.validator).length>0?T[y]=v.exports.validator:G==="useMeshRenderGate"&&v.exports.render?T[y]=v.exports.render:T[y]=c(v.scheduler,v.Schema);}});},A={...k,destroyPlugin:d,CancelTask:s,modules:{}},E=t.modules;return E&&Y(A.modules,E,{scheduler:te,Schema:e,exports:{history:b,form:M,validator:se,render:U}}),Ke.set(g,A),A}catch(r){throw Error(r)}},xn=()=>(g,e,t)=>ht(g,e,t),An=g=>{let e=Ke.get(g);if(!e)throw Error("Engine not found.");return e},vn=g=>{let e=Ke.get(g);e.destroyPlugin(),e.CancelTask(),Ke.delete(g);};export{_e as DefaultStrategy,Ce as MeshFlowEventsName,Le as TriggerCause,vn as deleteEngine,An as useEngine,ht as useMeshFlow,xn as useMeshFlowDefiner,yt as useScheduler};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshflow/core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "A logic orchestration engine utilizing topological scheduling and watermark control to resolve asynchronous race conditions in complex dependency linkages.",
|
|
5
5
|
"main": "./index.cjs",
|
|
6
6
|
"module": "./index.js",
|