@raphy-js/raph 1.0.0-dev.2 → 1.0.1-dev.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1096 -0
- package/dist/api/Raph.d.ts +59 -190
- package/dist/api/RaphFacadeSession.d.ts +90 -0
- package/dist/api/RaphReactivityInstance.d.ts +72 -0
- package/dist/api/errors.d.ts +9 -4
- package/dist/api/types.d.ts +162 -17
- package/dist/core-CyilRD7s.js +1055 -0
- package/dist/core-ugchZNqC.cjs +1 -0
- package/dist/debug/api/Raph.cjs +1 -1
- package/dist/debug/api/Raph.js +368 -366
- package/dist/debug/api/RaphFacadeSession.cjs +1 -0
- package/dist/debug/api/RaphFacadeSession.js +306 -0
- package/dist/debug/api/RaphReactivityInstance.cjs +1 -0
- package/dist/debug/api/RaphReactivityInstance.js +149 -0
- package/dist/debug/api/errors.cjs +1 -1
- package/dist/debug/api/errors.js +10 -7
- package/dist/debug/path/DataPath.cjs +1 -0
- package/dist/debug/path/{data-path.js → DataPath.js} +151 -180
- package/dist/debug/path/PathRouter.cjs +1 -0
- package/dist/debug/path/{path-router.js → PathRouter.js} +1 -1
- package/dist/debug/path/RaphKernel.cjs +1 -1
- package/dist/debug/path/RaphKernel.js +258 -207
- package/dist/debug/path/data-path.utils.cjs +1 -0
- package/dist/debug/path/data-path.utils.js +56 -0
- package/dist/debug/path/derived/DerivedRegistry.cjs +1 -0
- package/dist/debug/path/{DerivedRegistry.js → derived/DerivedRegistry.js} +5 -5
- package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
- package/dist/debug/path/{derived-collection.js → derived/derived-collection.utils.js} +1 -1
- package/dist/debug/path/derived/derived-strategy.types.cjs +1 -0
- package/dist/debug/path/derived/derived-strategy.types.js +1 -0
- package/dist/debug/path/{MetaController.cjs → meta/MetaController.cjs} +1 -1
- package/dist/debug/path/{MetaController.js → meta/MetaController.js} +3 -3
- package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
- package/dist/debug/path/{RaphMetaStore.js → meta/RaphMetaStore.js} +1 -1
- package/dist/debug/path/meta/meta.types.cjs +1 -0
- package/dist/debug/path/meta/meta.types.js +1 -0
- package/dist/debug/path/storage/AdapterPathStore.cjs +1 -0
- package/dist/debug/path/{AdapterPathStore.js → storage/AdapterPathStore.js} +9 -9
- package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
- package/dist/debug/path/{data-adapter.js → storage/DefaultDataAdapter.js} +2 -2
- package/dist/debug/path/storage/PathEventHub.cjs +1 -0
- package/dist/debug/path/{PathEventHub.js → storage/PathEventHub.js} +34 -34
- package/dist/debug/path/storage/PathStore.cjs +1 -0
- package/dist/debug/path/{PathStore.js → storage/PathStore.js} +28 -28
- package/dist/debug/path/storage/data-adapter.types.cjs +1 -0
- package/dist/debug/path/storage/data-adapter.types.js +1 -0
- package/dist/debug/reactivity/engine.cjs +1 -1
- package/dist/debug/reactivity/engine.js +478 -306
- package/dist/debug/reactivity/reactive-object.cjs +1 -0
- package/dist/debug/reactivity/reactive-object.js +280 -0
- package/dist/debug/runtime/RaphRuntime.cjs +1 -1
- package/dist/debug/runtime/RaphRuntime.js +798 -519
- package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -0
- package/dist/debug/runtime/diagnostics/RaphDebug.js +297 -0
- package/dist/debug/runtime/errors.cjs +1 -1
- package/dist/debug/runtime/errors.js +6 -3
- package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphEffectScope.js +171 -0
- package/dist/debug/runtime/ownership/RaphNode.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphNode.js +206 -0
- package/dist/debug/runtime/ownership/RaphScope.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphScope.js +101 -0
- package/dist/debug/runtime/ownership/parent-graph.types.cjs +1 -0
- package/dist/debug/runtime/ownership/parent-graph.types.js +1 -0
- package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhasePipeline.js +587 -0
- package/dist/debug/runtime/phases/orderPhaseTasks.cjs +1 -0
- package/dist/debug/runtime/phases/orderPhaseTasks.js +59 -0
- package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -0
- package/dist/debug/runtime/{PathHandle.js → reactivity/PathHandle.js} +75 -39
- package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphMetaSource.js +112 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.js +995 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.js +156 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.js +88 -0
- package/dist/debug/runtime/reactivity/runtime-reactivity.types.cjs +1 -0
- package/dist/debug/runtime/reactivity/runtime-reactivity.types.js +1 -0
- package/dist/entrypoints/machine-testing.d.ts +2 -0
- package/dist/entrypoints/machine.d.ts +5 -0
- package/dist/entrypoints/path.d.ts +14 -0
- package/dist/entrypoints/reactivity.d.ts +1 -0
- package/dist/entrypoints/runtime.d.ts +17 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +46 -38
- package/dist/machine/compiler.d.ts +71 -0
- package/dist/machine/core.d.ts +50 -0
- package/dist/machine/persistence.d.ts +5 -0
- package/dist/machine/runtime.d.ts +4 -0
- package/dist/machine/testing.d.ts +43 -0
- package/dist/machine/types.d.ts +155 -0
- package/dist/machine-testing.cjs +1 -0
- package/dist/machine-testing.js +188 -0
- package/dist/machine.cjs +1 -0
- package/dist/machine.js +837 -0
- package/dist/main.d.ts +20 -0
- package/dist/path/{data-path.d.ts → DataPath.d.ts} +16 -40
- package/dist/path/{path-router.d.ts → PathRouter.d.ts} +1 -1
- package/dist/path/RaphKernel.d.ts +13 -10
- package/dist/path/data-path.types.d.ts +34 -0
- package/dist/path/data-path.utils.d.ts +9 -0
- package/dist/path/{DerivedRegistry.d.ts → derived/DerivedRegistry.d.ts} +2 -2
- package/dist/path/{RaphDerivedHandle.d.ts → derived/RaphDerivedHandle.d.ts} +3 -3
- package/dist/path/derived/derived-collection.types.d.ts +12 -0
- package/dist/path/{derived-collection.d.ts → derived/derived-collection.utils.d.ts} +3 -13
- package/dist/path/{derived-strategies.d.ts → derived/derived-strategy.types.d.ts} +0 -3
- package/dist/path/derived/derived-strategy.utils.d.ts +4 -0
- package/dist/path/{MetaController.d.ts → meta/MetaController.d.ts} +4 -4
- package/dist/path/{RaphMeta.d.ts → meta/RaphMeta.d.ts} +2 -2
- package/dist/path/{RaphMetaStore.d.ts → meta/RaphMetaStore.d.ts} +1 -1
- package/dist/path/{meta.types.d.ts → meta/meta.types.d.ts} +2 -4
- package/dist/path/path.types.d.ts +3 -2
- package/dist/path/{segment-key.d.ts → pathSegmentKey.d.ts} +1 -1
- package/dist/path/{AdapterPathStore.d.ts → storage/AdapterPathStore.d.ts} +4 -4
- package/dist/path/{data-adapter.d.ts → storage/DefaultDataAdapter.d.ts} +2 -17
- package/dist/path/{PathEventHub.d.ts → storage/PathEventHub.d.ts} +9 -9
- package/dist/path/{PathStore.d.ts → storage/PathStore.d.ts} +3 -3
- package/dist/path/storage/data-adapter.types.d.ts +17 -0
- package/dist/path.cjs +1 -1
- package/dist/path.js +16 -16
- package/dist/raph.cjs +1 -1
- package/dist/raph.js +46 -38
- package/dist/reactivity/engine.d.ts +17 -3
- package/dist/reactivity/reactive-object.d.ts +36 -0
- package/dist/reactivity/types.d.ts +25 -0
- package/dist/reactivity.cjs +1 -1
- package/dist/reactivity.js +12 -12
- package/dist/runtime/RaphRuntime.d.ts +132 -192
- package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
- package/dist/runtime/errors.d.ts +5 -0
- package/dist/runtime/ownership/RaphEffectScope.d.ts +29 -0
- package/dist/runtime/ownership/RaphNode.d.ts +40 -0
- package/dist/runtime/ownership/RaphScope.d.ts +38 -0
- package/dist/runtime/{parent-graph.d.ts → ownership/parent-graph.types.d.ts} +0 -1
- package/dist/runtime/ownership/parentGraph.d.ts +3 -0
- package/dist/runtime/phases/RaphPhasePipeline.d.ts +79 -0
- package/dist/runtime/phases/orderPhaseTasks.d.ts +6 -0
- package/dist/runtime/phases/phase.types.d.ts +92 -0
- package/dist/runtime/{PathHandle.d.ts → reactivity/PathHandle.d.ts} +14 -6
- package/dist/runtime/reactivity/RaphMetaSource.d.ts +32 -0
- package/dist/runtime/reactivity/RaphWorkGraph.d.ts +171 -0
- package/dist/runtime/{RuntimeReactivity.d.ts → reactivity/RuntimeReactivity.d.ts} +14 -9
- package/dist/runtime/{RuntimeWatch.d.ts → reactivity/RuntimeWatch.d.ts} +9 -3
- package/dist/runtime/{runtime-reactivity.types.d.ts → reactivity/runtime-reactivity.types.d.ts} +3 -1
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +21 -16
- package/package.json +68 -35
- package/ReadMe.md +0 -153
- package/dist/api/public.d.ts +0 -22
- package/dist/debug/api/public.cjs +0 -1
- package/dist/debug/api/public.js +0 -40
- package/dist/debug/path/AdapterPathStore.cjs +0 -1
- package/dist/debug/path/DerivedRegistry.cjs +0 -1
- package/dist/debug/path/PathEventHub.cjs +0 -1
- package/dist/debug/path/PathStore.cjs +0 -1
- package/dist/debug/path/RaphMetaStore.cjs +0 -1
- package/dist/debug/path/data-adapter.cjs +0 -1
- package/dist/debug/path/data-path.cjs +0 -1
- package/dist/debug/path/derived-collection.cjs +0 -1
- package/dist/debug/path/path-router.cjs +0 -1
- package/dist/debug/path/public.cjs +0 -1
- package/dist/debug/path/public.js +0 -18
- package/dist/debug/runtime/PathHandle.cjs +0 -1
- package/dist/debug/runtime/RaphDebug.cjs +0 -1
- package/dist/debug/runtime/RaphDebug.js +0 -15
- package/dist/debug/runtime/RaphNode.cjs +0 -1
- package/dist/debug/runtime/RaphNode.js +0 -143
- package/dist/debug/runtime/RaphPhasePipeline.cjs +0 -1
- package/dist/debug/runtime/RaphPhasePipeline.js +0 -526
- package/dist/debug/runtime/RaphScope.cjs +0 -1
- package/dist/debug/runtime/RaphScope.js +0 -64
- package/dist/debug/runtime/RuntimeReactivity.cjs +0 -1
- package/dist/debug/runtime/RuntimeReactivity.js +0 -154
- package/dist/debug/runtime/RuntimeWatch.cjs +0 -1
- package/dist/debug/runtime/RuntimeWatch.js +0 -71
- package/dist/debug/runtime/public.cjs +0 -1
- package/dist/debug/runtime/public.js +0 -18
- package/dist/path/public.d.ts +0 -14
- package/dist/runtime/RaphDebug.d.ts +0 -32
- package/dist/runtime/RaphNode.d.ts +0 -68
- package/dist/runtime/RaphPhasePipeline.d.ts +0 -133
- package/dist/runtime/RaphScope.d.ts +0 -50
- package/dist/runtime/phase.types.d.ts +0 -49
- package/dist/runtime/public.d.ts +0 -13
- /package/dist/debug/path/{meta.types.cjs → data-path.types.cjs} +0 -0
- /package/dist/debug/path/{meta.types.js → data-path.types.js} +0 -0
- /package/dist/debug/path/{RaphDerivedHandle.cjs → derived/RaphDerivedHandle.cjs} +0 -0
- /package/dist/debug/path/{RaphDerivedHandle.js → derived/RaphDerivedHandle.js} +0 -0
- /package/dist/debug/{runtime/runtime-reactivity.types.cjs → path/derived/derived-collection.types.cjs} +0 -0
- /package/dist/debug/{runtime/runtime-reactivity.types.js → path/derived/derived-collection.types.js} +0 -0
- /package/dist/debug/path/{derived-strategies.cjs → derived/derived-strategy.utils.cjs} +0 -0
- /package/dist/debug/path/{derived-strategies.js → derived/derived-strategy.utils.js} +0 -0
- /package/dist/debug/path/{RaphMeta.cjs → meta/RaphMeta.cjs} +0 -0
- /package/dist/debug/path/{RaphMeta.js → meta/RaphMeta.js} +0 -0
- /package/dist/debug/path/{segment-key.cjs → pathSegmentKey.cjs} +0 -0
- /package/dist/debug/path/{segment-key.js → pathSegmentKey.js} +0 -0
- /package/dist/debug/path/{data-draft.cjs → storage/createDataDraft.cjs} +0 -0
- /package/dist/debug/path/{data-draft.js → storage/createDataDraft.js} +0 -0
- /package/dist/debug/runtime/{parent-graph.cjs → ownership/parentGraph.cjs} +0 -0
- /package/dist/debug/runtime/{parent-graph.js → ownership/parentGraph.js} +0 -0
- /package/dist/debug/runtime/{disposal.cjs → ownership/throwDisposalErrors.cjs} +0 -0
- /package/dist/debug/runtime/{disposal.js → ownership/throwDisposalErrors.js} +0 -0
- /package/dist/debug/runtime/{RaphFrameLoop.cjs → phases/RaphFrameLoop.cjs} +0 -0
- /package/dist/debug/runtime/{RaphFrameLoop.js → phases/RaphFrameLoop.js} +0 -0
- /package/dist/debug/runtime/{phase.types.cjs → phases/phase.types.cjs} +0 -0
- /package/dist/debug/runtime/{phase.types.js → phases/phase.types.js} +0 -0
- /package/dist/path/{data-draft.d.ts → storage/createDataDraft.d.ts} +0 -0
- /package/dist/runtime/{disposal.d.ts → ownership/throwDisposalErrors.d.ts} +0 -0
- /package/dist/runtime/{RaphFrameLoop.d.ts → phases/RaphFrameLoop.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var A=Object.defineProperty;var M=(s,e,t)=>e in s?A(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var p=(s,e,t)=>M(s,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=Symbol("raph.reactive-object.identity"),P=new Set(["copyWithin","fill","pop","push","reverse","shift","sort","splice","unshift"]),g=new WeakMap,l=new WeakMap,w=new WeakMap,D=Object.freeze({}),W=Object.freeze({assertRead:_,assertWrite:_,throwForeign:_});function m(s,e){l.set(s,e)}function S(s,e=W){l.delete(s);const t=g.get(s);t!==void 0&&(g.delete(s),t.dispose(e))}function E(s,e,t){var o;const r=b(e),i=g.get(s);if(r!==void 0){if(r.context===i)return e;const c=l.get(s)??D;throw(o=c.throwForeign)==null||o.call(c,r.context.owner),new TypeError("[Raph] Reactive object belongs to another reactivity engine.")}return j(e),(i??C(s,t)).wrap(e)}class I{constructor(e,t){p(this,"_rawToProxy",new WeakMap);p(this,"_rawToTracking",new WeakMap);p(this,"_arrayMethods",new Map);p(this,"_bridge");p(this,"_policy");p(this,"_writeDepth",0);p(this,"_disposed",!1);p(this,"_handler");p(this,"_weakSelf");this._bridge=e,this._policy=t,this._weakSelf=new WeakRef(this),this._handler={defineProperty:(r,i,n)=>this._define(r,i,n),deleteProperty:(r,i)=>this._delete(r,i),get:(r,i,n)=>this._get(r,i,n),has:(r,i)=>this._has(r,i),ownKeys:r=>this._ownKeys(r),set:(r,i,n)=>this._set(r,i,n)}}get owner(){return this._policy.owner}get disposed(){return this._disposed}wrap(e){var o,c,f,h;const t=b(e);if(t!==void 0){if(t.context===this)return e;throw(c=(o=this._policy).throwForeign)==null||c.call(o,t.context.owner),new TypeError("[Raph] Reactive object belongs to another reactivity engine.")}j(e);const r=x(e);if(r!==void 0&&r!==this&&!r.disposed)throw(h=(f=this._policy).throwForeign)==null||h.call(f,r.owner),new TypeError("[Raph] Raw reactive object belongs to another reactivity engine.");const i=this._rawToProxy.get(e);if(i!==void 0)return i;const n=new Proxy(e,this._handler);return w.set(e,this._weakSelf),this._rawToProxy.set(e,n),n}dispose(e){this._disposed=!0,this._policy=e,this._bridge=void 0,this._rawToProxy=new WeakMap,this._rawToTracking=new WeakMap,this._arrayMethods.clear()}_get(e,t,r){var n,o;if(t===O)return{context:this,raw:e};(o=(n=this._policy).assertRead)==null||o.call(n);const i=Reflect.get(e,t,r);return this._trackValue(e,t),Array.isArray(e)&&P.has(t)&&i===Array.prototype[t]?this._arrayMutator(t):y(i)?this.wrap(i):i}_set(e,t,r){return this._write(()=>{var a,u;const i=this._unwrap(r),n=Object.hasOwn(e,t),o=Reflect.get(e,t,e),c=Array.isArray(e)?e.length:0;if(n&&o===i)return!0;if(!Reflect.set(e,t,i,e))return!1;const h=this._rawToTracking.get(e);return h===void 0||(this._trigger((a=h.valueDeps)==null?void 0:a.get(t)),n||(this._trigger((u=h.hasDeps)==null?void 0:u.get(t)),this._trigger(h.iterateDep)),this._triggerArrayShape(e,t,i,c,h)),!0})}_define(e,t,r){return this._write(()=>{var R,T;const i=Object.hasOwn(e,t),n=Reflect.getOwnPropertyDescriptor(e,t),o=Reflect.get(e,t,e),c=Array.isArray(e)?e.length:0,f="value"in r?{...r,value:this._unwrap(r.value)}:r;if(!Reflect.defineProperty(e,t,f))return!1;const a=this._rawToTracking.get(e);if(a===void 0)return!0;const u=Reflect.getOwnPropertyDescriptor(e,t),v=Reflect.get(e,t,e);return(!i||o!==v||!N(n,u))&&this._trigger((R=a.valueDeps)==null?void 0:R.get(t)),i?(n==null?void 0:n.enumerable)!==(u==null?void 0:u.enumerable)&&this._trigger(a.iterateDep):(this._trigger((T=a.hasDeps)==null?void 0:T.get(t)),this._trigger(a.iterateDep)),this._triggerArrayShape(e,t,v,c,a),!0})}_delete(e,t){return this._write(()=>{var n,o;if(!Object.hasOwn(e,t))return!0;if(!Reflect.deleteProperty(e,t))return!1;const i=this._rawToTracking.get(e);return i!==void 0&&(this._trigger((n=i.valueDeps)==null?void 0:n.get(t)),this._trigger((o=i.hasDeps)==null?void 0:o.get(t)),this._trigger(i.iterateDep)),!0})}_has(e,t){var r,i;return(i=(r=this._policy).assertRead)==null||i.call(r),this._trackHas(e,t),Reflect.has(e,t)}_ownKeys(e){var t,r;return(r=(t=this._policy).assertRead)==null||r.call(t),this._trackIterate(e),Reflect.ownKeys(e)}_arrayMutator(e){const t=this._arrayMethods.get(e);if(t!==void 0)return t;const r=n=>this._write(n),i=function(...n){return r(()=>Reflect.apply(Array.prototype[e],this,n))};return this._arrayMethods.set(e,i),i}_trackValue(e,t){const r=this._requireBridge();if(!r.isTracking())return;const i=this._ensureTracking(e),n=i.valueDeps??(i.valueDeps=new Map);let o=n.get(t);o===void 0&&(o=r.create(),n.set(t,o)),r.track(o)}_trackHas(e,t){const r=this._requireBridge();if(!r.isTracking())return;const i=this._ensureTracking(e),n=i.hasDeps??(i.hasDeps=new Map);let o=n.get(t);o===void 0&&(o=r.create(),n.set(t,o)),r.track(o)}_trackIterate(e){const t=this._requireBridge();if(!t.isTracking())return;const r=this._ensureTracking(e),i=r.iterateDep??(r.iterateDep=t.create());t.track(i)}_ensureTracking(e){let t=this._rawToTracking.get(e);return t===void 0&&(t={},this._rawToTracking.set(e,t)),t}_trigger(e){e!==void 0&&this._requireBridge().trigger(e)}_triggerArrayShape(e,t,r,i,n){var c,f,h;if(!Array.isArray(e))return;if(d(t)&&Number(t)>=i){this._trigger((c=n.valueDeps)==null?void 0:c.get("length"));return}if(t!=="length"||Number(r)>=i)return;const o=Number(r);for(const[a,u]of((f=n.valueDeps)==null?void 0:f.entries())??[])d(a)&&Number(a)>=o&&this._trigger(u);for(const[a,u]of((h=n.hasDeps)==null?void 0:h.entries())??[])d(a)&&Number(a)>=o&&this._trigger(u);this._trigger(n.iterateDep)}_write(e){var r,i;if((i=(r=this._policy).assertWrite)==null||i.call(r),this._writeDepth!==0)return e();const t=()=>{++this._writeDepth;try{return this._requireBridge().batch(e)}finally{--this._writeDepth}};return this._policy.runWrite===void 0?t():this._policy.runWrite(t)}_unwrap(e){var r,i,n,o;const t=b(e);if(t===void 0){if(y(e)){const c=x(e);if(c!==void 0&&c!==this&&!c.disposed)throw(i=(r=this._policy).throwForeign)==null||i.call(r,c.owner),new TypeError("[Raph] Raw reactive object belongs to another reactivity engine.")}return e}if(t.context!==this)throw(o=(n=this._policy).throwForeign)==null||o.call(n,t.context.owner),new TypeError("[Raph] Reactive object belongs to another reactivity engine.");return t.raw}_requireBridge(){const e=this._bridge;return e===void 0&&_(),e}}function C(s,e){const t=new I(e(),l.get(s)??D);return g.set(s,t),t}function x(s){const e=w.get(s),t=e==null?void 0:e.deref();return e!==void 0&&t===void 0&&w.delete(s),t}function b(s){if(!(s===null||typeof s!="object"))return Reflect.get(s,O)}function y(s){if(s===null||typeof s!="object")return!1;if(Array.isArray(s))return!0;const e=Object.getPrototypeOf(s);return e===Object.prototype||e===null}function j(s){if(!y(s))throw new TypeError("[Raph] reactive() accepts only plain objects and arrays.")}function d(s){if(typeof s!="string"||s==="")return!1;const e=Number(s);return Number.isInteger(e)&&e>=0&&e<4294967295&&String(e)===s}function N(s,e){return s===e?!0:s===void 0||e===void 0?!1:s.configurable===e.configurable&&s.enumerable===e.enumerable&&s.get===e.get&&s.set===e.set&&s.value===e.value&&s.writable===e.writable}function _(){throw new Error("[Raph] Reactive object owner is disposed.")}exports.configureReactiveObjectPolicy=m;exports.disposeReactiveObjectContext=S;exports.reactiveObject=E;
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
var A = Object.defineProperty;
|
|
2
|
+
var M = (s, e, t) => e in s ? A(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var p = (s, e, t) => M(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
const D = Symbol("raph.reactive-object.identity"), P = /* @__PURE__ */ new Set([
|
|
5
|
+
"copyWithin",
|
|
6
|
+
"fill",
|
|
7
|
+
"pop",
|
|
8
|
+
"push",
|
|
9
|
+
"reverse",
|
|
10
|
+
"shift",
|
|
11
|
+
"sort",
|
|
12
|
+
"splice",
|
|
13
|
+
"unshift"
|
|
14
|
+
]), g = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new WeakMap(), O = Object.freeze({}), W = Object.freeze({
|
|
15
|
+
assertRead: f,
|
|
16
|
+
assertWrite: f,
|
|
17
|
+
throwForeign: f
|
|
18
|
+
});
|
|
19
|
+
function N(s, e) {
|
|
20
|
+
l.set(s, e);
|
|
21
|
+
}
|
|
22
|
+
function q(s, e = W) {
|
|
23
|
+
l.delete(s);
|
|
24
|
+
const t = g.get(s);
|
|
25
|
+
t !== void 0 && (g.delete(s), t.dispose(e));
|
|
26
|
+
}
|
|
27
|
+
function B(s, e, t) {
|
|
28
|
+
var o;
|
|
29
|
+
const r = b(e), i = g.get(s);
|
|
30
|
+
if (r !== void 0) {
|
|
31
|
+
if (r.context === i)
|
|
32
|
+
return e;
|
|
33
|
+
const c = l.get(s) ?? O;
|
|
34
|
+
throw (o = c.throwForeign) == null || o.call(c, r.context.owner), new TypeError("[Raph] Reactive object belongs to another reactivity engine.");
|
|
35
|
+
}
|
|
36
|
+
return j(e), (i ?? E(s, t)).wrap(e);
|
|
37
|
+
}
|
|
38
|
+
class m {
|
|
39
|
+
constructor(e, t) {
|
|
40
|
+
p(this, "_rawToProxy", /* @__PURE__ */ new WeakMap());
|
|
41
|
+
p(this, "_rawToTracking", /* @__PURE__ */ new WeakMap());
|
|
42
|
+
p(this, "_arrayMethods", /* @__PURE__ */ new Map());
|
|
43
|
+
p(this, "_bridge");
|
|
44
|
+
p(this, "_policy");
|
|
45
|
+
p(this, "_writeDepth", 0);
|
|
46
|
+
p(this, "_disposed", !1);
|
|
47
|
+
p(this, "_handler");
|
|
48
|
+
p(this, "_weakSelf");
|
|
49
|
+
this._bridge = e, this._policy = t, this._weakSelf = new WeakRef(this), this._handler = {
|
|
50
|
+
defineProperty: (r, i, n) => this._define(r, i, n),
|
|
51
|
+
deleteProperty: (r, i) => this._delete(r, i),
|
|
52
|
+
get: (r, i, n) => this._get(r, i, n),
|
|
53
|
+
has: (r, i) => this._has(r, i),
|
|
54
|
+
ownKeys: (r) => this._ownKeys(r),
|
|
55
|
+
set: (r, i, n) => this._set(r, i, n)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
get owner() {
|
|
59
|
+
return this._policy.owner;
|
|
60
|
+
}
|
|
61
|
+
get disposed() {
|
|
62
|
+
return this._disposed;
|
|
63
|
+
}
|
|
64
|
+
wrap(e) {
|
|
65
|
+
var o, c, _, h;
|
|
66
|
+
const t = b(e);
|
|
67
|
+
if (t !== void 0) {
|
|
68
|
+
if (t.context === this)
|
|
69
|
+
return e;
|
|
70
|
+
throw (c = (o = this._policy).throwForeign) == null || c.call(o, t.context.owner), new TypeError("[Raph] Reactive object belongs to another reactivity engine.");
|
|
71
|
+
}
|
|
72
|
+
j(e);
|
|
73
|
+
const r = x(e);
|
|
74
|
+
if (r !== void 0 && r !== this && !r.disposed)
|
|
75
|
+
throw (h = (_ = this._policy).throwForeign) == null || h.call(_, r.owner), new TypeError("[Raph] Raw reactive object belongs to another reactivity engine.");
|
|
76
|
+
const i = this._rawToProxy.get(e);
|
|
77
|
+
if (i !== void 0)
|
|
78
|
+
return i;
|
|
79
|
+
const n = new Proxy(e, this._handler);
|
|
80
|
+
return d.set(e, this._weakSelf), this._rawToProxy.set(e, n), n;
|
|
81
|
+
}
|
|
82
|
+
dispose(e) {
|
|
83
|
+
this._disposed = !0, this._policy = e, this._bridge = void 0, this._rawToProxy = /* @__PURE__ */ new WeakMap(), this._rawToTracking = /* @__PURE__ */ new WeakMap(), this._arrayMethods.clear();
|
|
84
|
+
}
|
|
85
|
+
_get(e, t, r) {
|
|
86
|
+
var n, o;
|
|
87
|
+
if (t === D)
|
|
88
|
+
return { context: this, raw: e };
|
|
89
|
+
(o = (n = this._policy).assertRead) == null || o.call(n);
|
|
90
|
+
const i = Reflect.get(e, t, r);
|
|
91
|
+
return this._trackValue(e, t), Array.isArray(e) && P.has(t) && i === Array.prototype[t] ? this._arrayMutator(t) : y(i) ? this.wrap(i) : i;
|
|
92
|
+
}
|
|
93
|
+
_set(e, t, r) {
|
|
94
|
+
return this._write(() => {
|
|
95
|
+
var a, u;
|
|
96
|
+
const i = this._unwrap(r), n = Object.hasOwn(e, t), o = Reflect.get(e, t, e), c = Array.isArray(e) ? e.length : 0;
|
|
97
|
+
if (n && o === i)
|
|
98
|
+
return !0;
|
|
99
|
+
if (!Reflect.set(e, t, i, e))
|
|
100
|
+
return !1;
|
|
101
|
+
const h = this._rawToTracking.get(e);
|
|
102
|
+
return h === void 0 || (this._trigger((a = h.valueDeps) == null ? void 0 : a.get(t)), n || (this._trigger((u = h.hasDeps) == null ? void 0 : u.get(t)), this._trigger(h.iterateDep)), this._triggerArrayShape(e, t, i, c, h)), !0;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
_define(e, t, r) {
|
|
106
|
+
return this._write(() => {
|
|
107
|
+
var R, T;
|
|
108
|
+
const i = Object.hasOwn(e, t), n = Reflect.getOwnPropertyDescriptor(e, t), o = Reflect.get(e, t, e), c = Array.isArray(e) ? e.length : 0, _ = "value" in r ? { ...r, value: this._unwrap(r.value) } : r;
|
|
109
|
+
if (!Reflect.defineProperty(e, t, _))
|
|
110
|
+
return !1;
|
|
111
|
+
const a = this._rawToTracking.get(e);
|
|
112
|
+
if (a === void 0)
|
|
113
|
+
return !0;
|
|
114
|
+
const u = Reflect.getOwnPropertyDescriptor(e, t), v = Reflect.get(e, t, e);
|
|
115
|
+
return (!i || o !== v || !S(n, u)) && this._trigger((R = a.valueDeps) == null ? void 0 : R.get(t)), i ? (n == null ? void 0 : n.enumerable) !== (u == null ? void 0 : u.enumerable) && this._trigger(a.iterateDep) : (this._trigger((T = a.hasDeps) == null ? void 0 : T.get(t)), this._trigger(a.iterateDep)), this._triggerArrayShape(
|
|
116
|
+
e,
|
|
117
|
+
t,
|
|
118
|
+
v,
|
|
119
|
+
c,
|
|
120
|
+
a
|
|
121
|
+
), !0;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
_delete(e, t) {
|
|
125
|
+
return this._write(() => {
|
|
126
|
+
var n, o;
|
|
127
|
+
if (!Object.hasOwn(e, t))
|
|
128
|
+
return !0;
|
|
129
|
+
if (!Reflect.deleteProperty(e, t))
|
|
130
|
+
return !1;
|
|
131
|
+
const i = this._rawToTracking.get(e);
|
|
132
|
+
return i !== void 0 && (this._trigger((n = i.valueDeps) == null ? void 0 : n.get(t)), this._trigger((o = i.hasDeps) == null ? void 0 : o.get(t)), this._trigger(i.iterateDep)), !0;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
_has(e, t) {
|
|
136
|
+
var r, i;
|
|
137
|
+
return (i = (r = this._policy).assertRead) == null || i.call(r), this._trackHas(e, t), Reflect.has(e, t);
|
|
138
|
+
}
|
|
139
|
+
_ownKeys(e) {
|
|
140
|
+
var t, r;
|
|
141
|
+
return (r = (t = this._policy).assertRead) == null || r.call(t), this._trackIterate(e), Reflect.ownKeys(e);
|
|
142
|
+
}
|
|
143
|
+
_arrayMutator(e) {
|
|
144
|
+
const t = this._arrayMethods.get(e);
|
|
145
|
+
if (t !== void 0)
|
|
146
|
+
return t;
|
|
147
|
+
const r = (n) => this._write(n), i = function(...n) {
|
|
148
|
+
return r(() => Reflect.apply(
|
|
149
|
+
Array.prototype[e],
|
|
150
|
+
this,
|
|
151
|
+
n
|
|
152
|
+
));
|
|
153
|
+
};
|
|
154
|
+
return this._arrayMethods.set(e, i), i;
|
|
155
|
+
}
|
|
156
|
+
_trackValue(e, t) {
|
|
157
|
+
const r = this._requireBridge();
|
|
158
|
+
if (!r.isTracking())
|
|
159
|
+
return;
|
|
160
|
+
const i = this._ensureTracking(e), n = i.valueDeps ?? (i.valueDeps = /* @__PURE__ */ new Map());
|
|
161
|
+
let o = n.get(t);
|
|
162
|
+
o === void 0 && (o = r.create(), n.set(t, o)), r.track(o);
|
|
163
|
+
}
|
|
164
|
+
_trackHas(e, t) {
|
|
165
|
+
const r = this._requireBridge();
|
|
166
|
+
if (!r.isTracking())
|
|
167
|
+
return;
|
|
168
|
+
const i = this._ensureTracking(e), n = i.hasDeps ?? (i.hasDeps = /* @__PURE__ */ new Map());
|
|
169
|
+
let o = n.get(t);
|
|
170
|
+
o === void 0 && (o = r.create(), n.set(t, o)), r.track(o);
|
|
171
|
+
}
|
|
172
|
+
_trackIterate(e) {
|
|
173
|
+
const t = this._requireBridge();
|
|
174
|
+
if (!t.isTracking())
|
|
175
|
+
return;
|
|
176
|
+
const r = this._ensureTracking(e), i = r.iterateDep ?? (r.iterateDep = t.create());
|
|
177
|
+
t.track(i);
|
|
178
|
+
}
|
|
179
|
+
_ensureTracking(e) {
|
|
180
|
+
let t = this._rawToTracking.get(e);
|
|
181
|
+
return t === void 0 && (t = {}, this._rawToTracking.set(e, t)), t;
|
|
182
|
+
}
|
|
183
|
+
_trigger(e) {
|
|
184
|
+
e !== void 0 && this._requireBridge().trigger(e);
|
|
185
|
+
}
|
|
186
|
+
_triggerArrayShape(e, t, r, i, n) {
|
|
187
|
+
var c, _, h;
|
|
188
|
+
if (!Array.isArray(e))
|
|
189
|
+
return;
|
|
190
|
+
if (w(t) && Number(t) >= i) {
|
|
191
|
+
this._trigger((c = n.valueDeps) == null ? void 0 : c.get("length"));
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (t !== "length" || Number(r) >= i)
|
|
195
|
+
return;
|
|
196
|
+
const o = Number(r);
|
|
197
|
+
for (const [a, u] of ((_ = n.valueDeps) == null ? void 0 : _.entries()) ?? [])
|
|
198
|
+
w(a) && Number(a) >= o && this._trigger(u);
|
|
199
|
+
for (const [a, u] of ((h = n.hasDeps) == null ? void 0 : h.entries()) ?? [])
|
|
200
|
+
w(a) && Number(a) >= o && this._trigger(u);
|
|
201
|
+
this._trigger(n.iterateDep);
|
|
202
|
+
}
|
|
203
|
+
_write(e) {
|
|
204
|
+
var r, i;
|
|
205
|
+
if ((i = (r = this._policy).assertWrite) == null || i.call(r), this._writeDepth !== 0)
|
|
206
|
+
return e();
|
|
207
|
+
const t = () => {
|
|
208
|
+
++this._writeDepth;
|
|
209
|
+
try {
|
|
210
|
+
return this._requireBridge().batch(e);
|
|
211
|
+
} finally {
|
|
212
|
+
--this._writeDepth;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
return this._policy.runWrite === void 0 ? t() : this._policy.runWrite(t);
|
|
216
|
+
}
|
|
217
|
+
_unwrap(e) {
|
|
218
|
+
var r, i, n, o;
|
|
219
|
+
const t = b(e);
|
|
220
|
+
if (t === void 0) {
|
|
221
|
+
if (y(e)) {
|
|
222
|
+
const c = x(e);
|
|
223
|
+
if (c !== void 0 && c !== this && !c.disposed)
|
|
224
|
+
throw (i = (r = this._policy).throwForeign) == null || i.call(r, c.owner), new TypeError("[Raph] Raw reactive object belongs to another reactivity engine.");
|
|
225
|
+
}
|
|
226
|
+
return e;
|
|
227
|
+
}
|
|
228
|
+
if (t.context !== this)
|
|
229
|
+
throw (o = (n = this._policy).throwForeign) == null || o.call(n, t.context.owner), new TypeError("[Raph] Reactive object belongs to another reactivity engine.");
|
|
230
|
+
return t.raw;
|
|
231
|
+
}
|
|
232
|
+
_requireBridge() {
|
|
233
|
+
const e = this._bridge;
|
|
234
|
+
return e === void 0 && f(), e;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function E(s, e) {
|
|
238
|
+
const t = new m(
|
|
239
|
+
e(),
|
|
240
|
+
l.get(s) ?? O
|
|
241
|
+
);
|
|
242
|
+
return g.set(s, t), t;
|
|
243
|
+
}
|
|
244
|
+
function x(s) {
|
|
245
|
+
const e = d.get(s), t = e == null ? void 0 : e.deref();
|
|
246
|
+
return e !== void 0 && t === void 0 && d.delete(s), t;
|
|
247
|
+
}
|
|
248
|
+
function b(s) {
|
|
249
|
+
if (!(s === null || typeof s != "object"))
|
|
250
|
+
return Reflect.get(s, D);
|
|
251
|
+
}
|
|
252
|
+
function y(s) {
|
|
253
|
+
if (s === null || typeof s != "object")
|
|
254
|
+
return !1;
|
|
255
|
+
if (Array.isArray(s))
|
|
256
|
+
return !0;
|
|
257
|
+
const e = Object.getPrototypeOf(s);
|
|
258
|
+
return e === Object.prototype || e === null;
|
|
259
|
+
}
|
|
260
|
+
function j(s) {
|
|
261
|
+
if (!y(s))
|
|
262
|
+
throw new TypeError("[Raph] reactive() accepts only plain objects and arrays.");
|
|
263
|
+
}
|
|
264
|
+
function w(s) {
|
|
265
|
+
if (typeof s != "string" || s === "")
|
|
266
|
+
return !1;
|
|
267
|
+
const e = Number(s);
|
|
268
|
+
return Number.isInteger(e) && e >= 0 && e < 4294967295 && String(e) === s;
|
|
269
|
+
}
|
|
270
|
+
function S(s, e) {
|
|
271
|
+
return s === e ? !0 : s === void 0 || e === void 0 ? !1 : s.configurable === e.configurable && s.enumerable === e.enumerable && s.get === e.get && s.set === e.set && s.value === e.value && s.writable === e.writable;
|
|
272
|
+
}
|
|
273
|
+
function f() {
|
|
274
|
+
throw new Error("[Raph] Reactive object owner is disposed.");
|
|
275
|
+
}
|
|
276
|
+
export {
|
|
277
|
+
N as configureReactiveObjectPolicy,
|
|
278
|
+
q as disposeReactiveObjectContext,
|
|
279
|
+
B as reactiveObject
|
|
280
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var q=Object.defineProperty;var P=(h,e,t)=>e in h?q(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t;var a=(h,e,t)=>P(h,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./errors.cjs"),T=require("./parent-graph.cjs"),E=require("./PathHandle.cjs"),d=require("./phase.types.cjs"),m=require("./RaphNode.cjs"),k=require("../path/data-path.cjs"),W=require("../path/RaphKernel.cjs"),L=require("../path/RaphMeta.cjs"),x=require("../reactivity/watch.cjs"),S=require("./disposal.cjs"),y=require("./RaphDebug.cjs"),O=require("./RaphFrameLoop.cjs"),M=require("./RaphPhasePipeline.cjs"),b=require("./RaphScope.cjs"),H=require("./RuntimeReactivity.cjs"),v=require("./RuntimeWatch.cjs"),R=class R{constructor(e={}){a(this,"configuration");a(this,"rootScope");a(this,"root");a(this,"_reactivity");a(this,"_signalLifecycle");a(this,"_pathHandles");a(this,"_meta");a(this,"_phases");a(this,"_frameLoop");a(this,"_frameRevision");a(this,"_frameRevisionValue",!1);a(this,"_debug");a(this,"_parentGraph");a(this,"_owners",new Set);a(this,"_transactionDepth",0);a(this,"_mutationDepth",0);a(this,"_kernelTransactionDepth",0);a(this,"_actionDepth",0);a(this,"_executionRequested",!1);a(this,"_disposed",!1);a(this,"_disposedListeners",new Set);const t=e.id??`runtime-${R._runtimeCounter++}`,s=e.enforceActions??!1,r=e.scheduler??d.RaphSchedulerType.Sync;if(!F(r))throw new Error(`[Raph] Unsupported scheduler "${String(r)}".`);const i=e.kernel??new W.RaphKernel({id:`${t}-kernel`});this.configuration=Object.freeze({id:t,kernel:i,enforceActions:s,scheduler:r});const o=`[Raph] Runtime "${t}" is disposed.`;this._signalLifecycle={owner:this,runWrite:n=>this._runWrite(n),...s?{assertWriteAllowed:()=>this._assertWriteAllowed()}:{},throwDisposed:()=>{throw new w.RaphDisposedError(o)},throwCrossRuntime:n=>this._throwCrossRuntime(n)},this._reactivity=new H.RuntimeReactivity(this._signalLifecycle),i._attachRuntime(this),this.rootScope=new b.RaphScope(`${t}:root-scope`,this),this.root=new m.RaphNode(null,{id:`${t}:root`},this)}_getReactivity(){return this._reactivity}get id(){return this.configuration.id}get kernel(){return this.configuration.kernel}get meta(){return this._assertAlive(),this._meta??(this._meta=new L.RaphMeta(this.kernel,{assertReadable:()=>this._assertAlive(),assertWritable:()=>this._assertWriteAllowed(),runWrite:(e,t)=>this._runWrite(e,t),watch:(e,t,s)=>this._own(this._watchMeta(e,t,s),this.rootScope)}))}get disposed(){return this._disposed}get graph(){return this._parentGraph??(this._parentGraph=T.parentGraph())}get loopEnabled(){var e;return((e=this._frameLoop)==null?void 0:e.running)??!1}get frame(){var e;return((e=this._phases)==null?void 0:e.frame)??{now:0,delta:0,elapsed:0,frame:0}}get phases(){var e;return((e=this._phases)==null?void 0:e.phases)??[]}getDerivedSnapshot(){return this.kernel.getDerivedSnapshot()}get debug(){return this._debug??(this._debug=Object.freeze({snapshot:()=>this._createDebugSnapshot(),getTree:()=>y.createOwnerSnapshot(this.root)}))}signal(e,t=this.rootScope){return this._assertOwnerRuntime(t),this._reactivity.signalForOwner(e,t)}computed(e,t=this.rootScope){this._assertOwnerRuntime(t);const s=typeof e=="function"?e:e.get,r=this._reactivity.computedForOwner(()=>this._runTracked(s),t);return typeof e=="function"?r:this._attachWritableComputed(r,e.set,t)}effect(e,t,s={},r=this.rootScope){const i=typeof e=="string"?t:e,o=typeof e=="string"?r:t??this.rootScope;if(this._assertOwnerRuntime(o),typeof e=="string"){const n=e.trim(),c=this._execution;c.requirePhase(n);const p=s.priority??0,_=s.initial??"scheduled";if(!Number.isFinite(p))throw new TypeError("[Raph] Effect priority must be finite.");if(_!=="scheduled"&&_!=="sync")throw new TypeError(`[Raph] Unsupported effect initial mode "${String(_)}".`);_==="sync"&&c.lockConfiguration();const l=c.phaseMode(n)==="always"?this._frameRevision??(this._frameRevision=this._reactivity.signal(!1)):void 0,g=this._reactivity.withEffectBinding(u=>c.bindEffect(n,p,u,o instanceof m.RaphNode?o:void 0),_,()=>this._reactivity.effect(()=>(l==null||l.get(),this._runTracked(i))));return this._own(g,o)}return this._own(this._reactivity._effectImmediate(()=>this._runTracked(i)),o)}watch(e,t,s={},r=this.rootScope){return this._assertOwnerRuntime(r),$(e)?this._own(this._watchPath(e,t),r):this._own(x.watchWithReactivity(this._reactivity._effectImmediate,this._reactivity.untracked,e,t,s,i=>this._runTracked(i)),r)}path(e,t={}){this._assertAlive();const s=k.parseDataPath(e,t),r=this._pathHandles??(this._pathHandles=new Map),i=r.get(s.canonical);if(i!==void 0)return i;const o=new E.PathHandle(this.kernel,s,t,n=>this._releasePathHandle(n),this._reactivity,()=>this._assertAlive(),()=>this._assertTrackedRead(),this.configuration.enforceActions?()=>this._assertWriteAllowed():void 0,n=>this._runWrite(n));return r.set(s.canonical,o),o}get(e,t){this._assertTrackedRead();const s=e??"";return this._reactivity._isTracking()?this.path(s,t)._getTracked():this.kernel.get(s,t)}peek(e,t){return this._assertAlive(),this.kernel.peek(e??"",t)}has(e,t){return this._assertAlive(),this.kernel.has(e,t)}set(e,t,s){this._assertWriteAllowed(),this._runWrite(()=>this.kernel.set(e,t,s))}merge(e,t,s){this._assertWriteAllowed(),this._runWrite(()=>this.kernel.merge(e,t,s))}delete(e,t){this._assertWriteAllowed(),this._runWrite(()=>this.kernel.delete(e,t))}transaction(e){this._assertAlive(),this._transactionDepth++;try{return this._reactivity.batch(()=>this.kernel.transaction(e))}finally{this._transactionDepth--,this._requestExecution()}}action(e,t,s=this.rootScope){if(this._assertOwnerRuntime(s),!e.trim())throw new Error("[Raph] Action name must not be empty.");return(...r)=>(s._assertAlive(),this.runInAction(e,()=>t(...r)))}runInAction(e,t){this._assertAlive(),this._actionDepth++;try{return this.transaction(()=>this._runUntracked(t))}finally{this._actionDepth--}}untracked(e){return this._assertAlive(),this._reactivity.untrackedWithOwner(e)}scope(e){return this._assertAlive(),new b.RaphScope(e,this)}node(e,t){this._assertAlive();const s=e.parent??this.root,r=new m.RaphNode(s,e,this);try{return r._setApi(t(r)),r}catch(i){try{r.dispose()}catch(o){throw new AggregateError([i,o],`[Raph] Node "${r.id}" setup and cleanup failed.`)}throw i}}getNode(e){this._assertAlive();const t=[this.root];for(;t.length!==0;){const s=t.pop();if(s.id===e)return s;t.push(...s.children)}}definePhases(e){this._execution.definePhases(e)}addPhase(e){this._execution.addPhase(e)}clearPhases(){var e;this._assertAlive(),(e=this._phases)==null||e.clearPhases()}observeData(e,t,s){return this._assertOwnerRuntime(e),this._own(this._execution.observeData(e,t,s),e)}track(e,t,s={}){return this._assertOwnerRuntime(e),this._own(this._execution.track(e,t,s),e)}invalidateNode(e,t){this._assertOwnerRuntime(e),this._execution.invalidate(e,t)}flush(){var e;this._assertAlive(),this._executionRequested=!1,(e=this._phases)==null||e.flush()}acquireLoop(e){return this._assertAlive(),this._clock.acquire(e)}startLoop(){this._assertAlive(),this._clock.start()}stopLoop(){var e;(e=this._frameLoop)==null||e.stop()}derive(e){this._assertAlive();const t=e.compute,s=this.kernel.derive({...e,compute:r=>this._runUntracked(()=>t(r))});return this._own(()=>s.dispose(),this.rootScope),s}dispose(){var i,o;if(this._disposed)return;this._disposed=!0,this._executionRequested=!1,this._signalLifecycle.owner=void 0;const e=[],t=[...this._owners];try{(i=this._frameLoop)==null||i.dispose()}catch(n){e.push(n)}this._frameLoop=void 0;try{(o=this._phases)==null||o.dispose()}catch(n){e.push(n)}this._phases=void 0;try{this.root.dispose()}catch(n){e.push(n)}for(const n of t.reverse())if(!(n===this.root||n===this.rootScope||n.disposed))try{n.dispose()}catch(c){e.push(c)}try{this.rootScope.dispose()}catch(n){e.push(n)}this._owners.clear(),this._meta=void 0,this._frameRevision=void 0;const s=this._pathHandles;if(this._pathHandles=void 0,s!==void 0){for(const n of s.values())try{n.dispose()}catch(c){e.push(c)}s.clear()}try{this.kernel._detachRuntime(this)}catch(n){e.push(n)}const r=[...this._disposedListeners];this._disposedListeners.clear();for(const n of r)try{n()}catch(c){e.push(c)}S.throwDisposalErrors(e,`[Raph] Runtime "${this.id}" disposal failed.`)}_onDisposed(e){return this._disposed?(e(),()=>{}):(this._disposedListeners.add(e),()=>{this._disposedListeners.delete(e)})}_watchPath(e,t){const s=new v.RuntimeWatch(i=>this._runUntracked(i)),r=this.kernel.watch(e,i=>{s.deliver(()=>t(i))});return()=>s.stop(r)}_createDebugSnapshot(){var s,r,i;const e=((s=this._frameLoop)==null?void 0:s._debugState())??{running:!1,manual:!1,leases:0},t=[...this._owners].filter(o=>o!==this.rootScope&&!(o instanceof m.RaphNode)).map(y.createOwnerSnapshot);return Object.freeze({id:this.id,disposed:this._disposed,pending:!this._disposed&&(this._executionRequested||(((r=this._phases)==null?void 0:r._debugPending())??!1)),transactionDepth:this._transactionDepth,kernelTransactionDepth:this._kernelTransactionDepth,owners:this._owners.size,pathHandles:((i=this._pathHandles)==null?void 0:i.size)??0,rootScope:y.createOwnerSnapshot(this.rootScope),scopes:Object.freeze(t),root:y.createOwnerSnapshot(this.root),frameLoop:Object.freeze(e)})}_watchMeta(e,t,s){if(s.phase!==void 0)return this._watchMetaInPhase(e,t,s);if(s.priority!==void 0)throw new TypeError("[RaphMeta] watch priority requires a phase.");const r=new v.RuntimeWatch(o=>this._runUntracked(o)),i=this.kernel._watchMeta(e,o=>{r.deliver(()=>t(o))},s);return()=>r.stop(i)}_watchMetaInPhase(e,t,s){const r=s.phase.trim(),i=this._execution;i.requirePhase(r);const o=s.priority??0;if(!Number.isFinite(o))throw new TypeError("[RaphMeta] watch priority must be finite.");const n=i.retainPhase(r),c=new v.RuntimeWatch(u=>this._runUntracked(u));let p=[],_;const l=()=>{_=void 0;const u=p;p=[],c.deliver(()=>t({events:u}))};let g;try{g=this.kernel._watchMeta(e,({events:u})=>{c.stopped||(p.push(...u),_===void 0&&(_=i.queueEffect(r,o,l,!1)))},s,u=>{!c.stopped&&u&&_!==void 0&&i.request()})}catch(u){throw n(),u}return()=>{if(c.stopped)return;const u=[];try{c.stop(g)}catch(f){u.push(f)}try{_==null||_()}catch(f){u.push(f)}try{n()}catch(f){u.push(f)}_=void 0,p=[],S.throwDisposalErrors(u,"[RaphMeta] Phase watch disposal failed.")}}_releasePathHandle(e){const t=this._pathHandles;(t==null?void 0:t.get(e.path))===e&&(t.delete(e.path),t.size===0&&(this._pathHandles=void 0))}get _execution(){return this._assertAlive(),this._phases??(this._phases=new M.RaphPhasePipeline(this.kernel,this.root,this.configuration.scheduler,e=>this._runUntracked(e),()=>{const e=this._mutationDepth!==0||this._transactionDepth!==0||this._kernelTransactionDepth!==0||this._reactivity._isFlushingEffects();return e&&this.configuration.scheduler===d.RaphSchedulerType.Sync&&(this._executionRequested=!0),e}))}get _clock(){return this._frameLoop??(this._frameLoop=new O.RaphFrameLoop(()=>this._tickFrameLoop()))}_tickFrameLoop(){var e;this._disposed||(this._frameRevision!==void 0&&(this._frameRevisionValue=!this._frameRevisionValue,this._frameRevision.set(this._frameRevisionValue)),(e=this._phases)==null||e.requestAlwaysPhases(),this._requestExecution())}_attachWritableComputed(e,t,s){let r=t;this._own(()=>{r=void 0},s);const i=e;return i.set=o=>{s._assertAlive(),this._assertWriteAllowed(),r(o)},i}_own(e,t){try{return t._adoptResource(e)}catch(s){try{e()}catch(r){throw new AggregateError([s,r],"[Raph] Resource registration and cleanup failed.")}throw s}}_registerOwner(e){this._assertAlive(),this._owners.add(e)}_unregisterOwner(e){this._owners.delete(e)}_assertOwnerRuntime(e){if(this._assertAlive(),e.runtime!==this)throw new w.RaphCrossRuntimeError("[Raph] Owner belongs to another runtime.");e._assertAlive()}_runTracked(e){return this._reactivity.runWithOwner(this._signalLifecycle,e)}_runUntracked(e){return this._reactivity.untrackedWithOwner(e)}_runWrite(e,t=!0){t&&this.configuration.scheduler===d.RaphSchedulerType.Sync&&(this._executionRequested=!0),this._mutationDepth++;try{return e()}finally{this._mutationDepth--,this._requestExecution()}}_requestExecution(){var e;this.configuration.scheduler!==d.RaphSchedulerType.Sync||this._mutationDepth!==0||this._transactionDepth!==0||this._kernelTransactionDepth!==0||this._reactivity._isFlushingEffects()||this._executionRequested&&(this._executionRequested=!1,(e=this._phases)==null||e.flush())}_beginKernelTransaction(){this._disposed||this._kernelTransactionDepth++}_endKernelTransaction(){this._kernelTransactionDepth!==0&&(this._kernelTransactionDepth--,this._disposed||this._requestExecution())}_assertTrackedRead(){this._assertAlive();const e=this._reactivity.getActiveOwner();e!==void 0&&e!==this&&this._throwCrossRuntime(e)}_assertWriteAllowed(){if(this._assertAlive(),this.configuration.enforceActions&&this._actionDepth===0&&this._transactionDepth===0)throw new w.RaphActionError("[Raph] Writes are allowed only inside action() or transaction().")}_throwCrossRuntime(e){throw new w.RaphCrossRuntimeError(`[Raph] Runtime "${this.id}" cannot be tracked by runtime "${e.id}".`)}_throwDisposed(){throw new w.RaphDisposedError(`[Raph] Runtime "${this.id}" is disposed.`)}_assertAlive(){this._disposed&&this._throwDisposed()}};a(R,"_runtimeCounter",0);let A=R;function $(h){return typeof h=="string"||h instanceof k.DataPath||D(h)?!0:Array.isArray(h)&&h.every(e=>typeof e=="string"||e instanceof k.DataPath||D(e))}function D(h){return typeof h=="object"&&h!==null&&"segs"in h&&h.segs!==void 0&&Array.isArray(h.segs)}function F(h){return h===d.RaphSchedulerType.Sync||h===d.RaphSchedulerType.Microtask||h===d.RaphSchedulerType.AnimationFrame}exports.RaphRuntime=A;
|
|
1
|
+
"use strict";var C=Object.defineProperty;var E=(p,e,t)=>e in p?C(p,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):p[e]=t;var d=(p,e,t)=>E(p,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../path/data-path.utils.cjs"),P=require("../path/DataPath.cjs"),W=require("../path/meta/RaphMeta.cjs"),q=require("../path/RaphKernel.cjs"),S=require("../reactivity/reactive-object.cjs"),g=require("./diagnostics/RaphDebug.cjs"),w=require("./errors.cjs"),G=require("./ownership/parentGraph.cjs"),v=require("./ownership/RaphNode.cjs"),k=require("./ownership/RaphScope.cjs"),R=require("./ownership/throwDisposalErrors.cjs"),m=require("./phases/phase.types.cjs"),x=require("./phases/RaphFrameLoop.cjs"),O=require("./phases/RaphPhasePipeline.cjs"),M=require("./reactivity/PathHandle.cjs"),L=require("./reactivity/RaphMetaSource.cjs"),F=require("./reactivity/RaphWorkGraph.cjs"),B=require("./reactivity/RuntimeReactivity.cjs"),N=require("./reactivity/RuntimeWatch.cjs"),b=class b{constructor(e={}){d(this,"mode","runtime");d(this,"configuration");d(this,"rootScope");d(this,"root");d(this,"frameTick");d(this,"_reactivity");d(this,"_signalLifecycle");d(this,"_workGraph");d(this,"_frameTickWritable");d(this,"_setFrameTick");d(this,"_pathHandles");d(this,"_meta");d(this,"_phases");d(this,"_frameLoop");d(this,"_debug");d(this,"_debugController");d(this,"_parentGraph");d(this,"_owners",new Set);d(this,"_batchDepth",0);d(this,"_mutationDepth",0);d(this,"_kernelBatchDepth",0);d(this,"_ownerDisposalDepth",0);d(this,"_actionDepth",0);d(this,"_actionCounter",0);d(this,"_traceCauseStack",[]);d(this,"_phaseTraceOperations");d(this,"_executionRequested",!1);d(this,"_disposed",!1);d(this,"_disposedListeners",new Set);const t=e.id??`runtime-${b._runtimeCounter++}`,r=e.adaptiveDependencyIndex??!1,s=e.enforceActions??!1,i=e.scheduler??m.RaphSchedulerType.Sync;if(!H(i))throw new Error(`[Raph] Unsupported scheduler "${String(i)}".`);const o=e.kernel??new q.RaphKernel({id:`${t}-kernel`});this.configuration=Object.freeze({adaptiveDependencyIndex:r,...e.debug===void 0?{}:{debug:e.debug},id:t,kernel:o,enforceActions:s,scheduler:i}),this._debugController=new g.RaphDebugController(e.debug);const c=`[Raph] Runtime "${t}" is disposed.`;this._signalLifecycle={owner:this,runWrite:u=>this._runWrite(u),assertDependencyAllowed:(u,l)=>{this._assertImplicitDependency(u,l)},...s?{assertWriteAllowed:()=>this._assertWriteAllowed()}:{},throwDisposed:()=>{throw new w.RaphDisposedError(c)},throwCrossRuntime:u=>this._throwCrossRuntime(u)},this._reactivity=new B.RuntimeReactivity(this._signalLifecycle,{adaptiveDependencyIndex:r}),this._workGraph=new F.RaphWorkGraph(this),o._attachRuntime(this),this.rootScope=new k.RaphScope(`${t}:root-scope`,this),this.root=new v.RaphNode(null,{id:`${t}:root`},this),S.configureReactiveObjectPolicy(this._reactivity,{owner:this,assertRead:()=>{this._assertAlive();const u=this._reactivity.getActiveOwner();u!==void 0&&u!==this&&this._throwCrossRuntime(u);const l=this._reactivity.getActiveConsumerOwner();l!==void 0&&this._assertImplicitDependency(this.rootScope,l)},assertWrite:()=>this._assertWriteAllowed(),runWrite:u=>this._runWrite(u),throwForeign:u=>{throw u instanceof b&&this._throwCrossRuntime(u),new w.RaphCrossRuntimeError("[Raph] Reactive object belongs to another reactivity engine.")}});const n=this._workGraph.createProducer(this.rootScope,"frame",{includeRuntime:!1});let a;const h=this._reactivity.signalForOwner(0,this.rootScope,this._workGraph.producerHooks(n),u=>{a=u});this._setFrameTick=u=>this._runWrite(()=>a(u)),this._frameTickWritable=h,this.frameTick=this._workGraph.attachProducer(n,{get:h.get,peek:h.peek})}_getReactivity(){return this._reactivity}_getWorkGraph(){return this._workGraph}get id(){return this.configuration.id}get kernel(){return this.configuration.kernel}get disposed(){return this._disposed}get graph(){return this._parentGraph??(this._parentGraph=G.parentGraph())}get loopEnabled(){var e;return((e=this._frameLoop)==null?void 0:e.running)??!1}get frame(){var e;return((e=this._phases)==null?void 0:e.frame)??{now:0,delta:0,elapsed:0,frame:0}}get phases(){var e;return((e=this._phases)==null?void 0:e.phases)??[]}get meta(){if(this._assertAlive(),this._meta!==void 0)return this._meta;const e=new W.RaphMeta(this.kernel,{assertReadable:()=>this._assertAlive(),assertWritable:()=>this._assertWriteAllowed(),runWrite:(t,r)=>this._runWrite(t,r)});return this._meta=Object.freeze({delete:e.delete.bind(e),get:e.get.bind(e),has:e.has.bind(e),merge:e.merge.bind(e),set:e.set.bind(e)})}getDerivedSnapshot(){return this.kernel.getDerivedSnapshot()}get debug(){return this._debug??(this._debug=Object.freeze({snapshot:()=>this._createDebugSnapshot(),getTree:()=>this._createDebugTree(),stats:()=>this._createDebugStats(),trace:this._debugController.trace,machines:this._debugController.machines}))}signal(e,t=this.rootScope){this._assertOwnerRuntime(t);const r=this._workGraph.createProducer(t),s=this._reactivity.signalForOwner(e,t,this._workGraph.producerHooks(r));return this._workGraph.attachProducer(r,s)}reactive(e){return this._assertAlive(),this._reactivity.reactive(e)}computed(e,t=this.rootScope){this._assertOwnerRuntime(t);const r=this._workGraph.createProducer(t),s=typeof e=="function"?e:e.get,i=this._reactivity.computedForOwner(()=>this._runTracked(t,s),t,this._workGraph.producerHooks(r));if(this._workGraph.setProducerActivation(r,()=>{i.peek()}),typeof e=="function")return this._workGraph.attachProducer(r,i);const o=this._attachWritableComputed(i,e.set,t);return this._workGraph.attachProducer(r,o)}effect(e,t,r,s={}){return this._effectRegistration(e,t,r,s).dispose}_effectRegistration(e,t,r,s={},i=!1){this._assertOwnerRuntime(e);const o=this._validatePhaseBinding(t,r,s),c=this._execution,n=s.initial??"scheduled";let a,h,u=!1;const l=this._reactivity.withEffectBinding(f=>{const _=c.bindTask(o,e,r,s.priority??0,f);return i&&_.pause(),a=_},()=>this._reactivity.effect(()=>this._runTracked(e,()=>{const f=r(a.task);return typeof f=="function"?()=>this._runUntracked(f):f}),()=>{h===void 0?u=!0:h()}));h=this._own(l,e),u&&h(),a.abort=()=>h==null?void 0:h();try{n==="sync"?this.flush():this._requestExecution()}catch(f){try{h()}catch(_){throw new AggregateError([f,_],"[Raph] Phase effect registration and rollback failed.")}throw f}return{dispose:()=>h==null?void 0:h(),pause:()=>a==null?void 0:a.pause(),resume:()=>a==null?void 0:a.resume()}}watch(e,t,r,s,i={}){return this._watchRegistration(e,t,r,s,i).dispose}_watchRegistration(e,t,r,s,i={},o=!1){this._assertOwnerRuntime(e);const c=this._validatePhaseBinding(r,s,i,!0);this._workGraph.assertSubscriptionAllowed(e,t);let n;const a=new N.RuntimeWatch(_=>this._runUntracked(_),()=>s(n.task));n=this._execution.bindTask(c,e,s,i.priority??0,a.deliver),o&&n.pause();let h;try{h=this._workGraph.subscribe(t,i.include,n.enqueue)}catch(_){throw n.dispose(),_}const u=()=>a.stop(()=>{const _=[];try{h()}catch(y){_.push(y)}try{n.dispose()}catch(y){_.push(y)}R.throwDisposalErrors(_,"[Raph] Phase watch disposal failed.")}),l=this._own(u,e),f=i.initial??"scheduled";try{f!=="none"&&n.schedule(),f==="sync"&&this.flush()}catch(_){try{l()}catch(y){throw new AggregateError([_,y],"[Raph] Phase watch registration and rollback failed.")}throw _}return{dispose:l,pause:n.pause,resume:n.resume}}aggregate(e,t){return this._assertOwnerRuntime(e),this._workGraph.createAggregate(e,t)}metaSource(e,t={}){this._assertAlive(),I(e,t);const r=this._workGraph.createProducer(this.rootScope,"path"),s=this._workGraph.producerHooks(r).onDispose,i=L.RaphMetaSource._create(this.rootScope,e,t,()=>this.kernel._watchMeta(i.masks,({events:o})=>this._workGraph.notifyProducerEvents(r,o,!1),i.options,o=>{o&&this._execution.request()}),()=>s(!1));i._bindOwner(this.rootScope._adoptResource(()=>i._disposeOwned()));try{return this._workGraph.setProducerActivation(r,()=>i._activate(),!0),this._workGraph.attachProducer(r,i),i}catch(o){try{i.dispose()}catch(c){throw new AggregateError([o,c],"[Raph] Meta source activation and rollback failed.")}throw o}}path(e,t={}){this._assertAlive();const r=T.parseDataPath(e,t),s=this._pathHandles??(this._pathHandles=new Map),i=s.get(r.canonical);if(i!==void 0)return i;const o=this._workGraph.createProducer(this.rootScope,"path"),c=this._workGraph.producerHooks(o),n=new M.PathHandle(this.kernel,r,t,a=>this._releasePathHandle(a),this._reactivity,()=>this._assertAlive(),()=>this._assertTrackedRead(),this.configuration.enforceActions?()=>this._assertWriteAllowed():void 0,a=>this._runWrite(a),{token:o,onDispose:c.onDispose},({events:a},h)=>this._workGraph.notifyProducerEvents(o,a,!0,h));try{return this._workGraph.setProducerActivation(o,()=>n._activate(),!0),this._workGraph.attachProducer(o,n),s.set(r.canonical,n),n}catch(a){let h,u=!1;try{n.dispose()}catch(l){u=!0,h=l}throw s.size===0&&this._pathHandles===s&&(this._pathHandles=void 0),u?new AggregateError([a,h],"[Raph] Path source activation and rollback failed."):a}}get(e,t){this._assertTrackedRead();const r=e??"";return this._reactivity._isTracking()?this.path(r,t)._getTracked():this.kernel.get(r,t)}peek(e,t){return this._assertAlive(),this.kernel.peek(e??"",t)}has(e,t){return this._assertAlive(),this.kernel.has(e,t)}set(e,t,r){this._assertWriteAllowed(),this._runWrite(()=>this.kernel.set(e,t,r))}merge(e,t,r){this._assertWriteAllowed(),this._runWrite(()=>this.kernel.merge(e,t,r))}delete(e,t){this._assertWriteAllowed(),this._runWrite(()=>this.kernel.delete(e,t))}batch(e){return this._batch(e,!0)}_batchReactive(e){return this._batch(e,!1)}_batch(e,t){this._assertAlive(),this._batchDepth++;let r,s,i=!1;try{r=this._reactivity.batch(()=>t?this.kernel.batch(e):e())}catch(c){i=!0,s=c}this._batchDepth--;const o=this._finishExecutionBoundary();if(i)throw o.length!==0?new AggregateError([s,...o],"[Raph] Batch and scheduled phase execution failed."):s;return R.throwDisposalErrors(o,"[Raph] Batch phase execution failed."),r}action(e,t,r){const s=typeof e=="function"?e:t,i=typeof e=="function"?t instanceof k.RaphScope?t:this.rootScope:r??this.rootScope,o=typeof e=="string"?e:`action#${++this._actionCounter}`;if(this._assertOwnerRuntime(i),typeof s!="function")throw new TypeError("[Raph] Action operation must be a function.");if(!o.trim())throw new Error("[Raph] Action name must not be empty.");return(...c)=>{i._assertAlive();const n=this._debugController.nextOperationId("action"),h=this._traceCauseStack.at(-1)??n;this._debugController.record({...h===void 0?{}:{causeId:h},kind:"action",name:o,...n===void 0?{}:{operationId:n},status:"start"}),h!==void 0&&this._traceCauseStack.push(h),this._actionDepth++;try{const u=this.batch(()=>this._runUntracked(()=>s(...c)));return this._debugController.record({...h===void 0?{}:{causeId:h},kind:"action",name:o,...n===void 0?{}:{operationId:n},status:"end"}),u}catch(u){throw this._debugController.record({...h===void 0?{}:{causeId:h},details:{message:D(u)},kind:"action",name:o,...n===void 0?{}:{operationId:n},status:"error"}),this._debugController.record({...h===void 0?{}:{causeId:h},details:{message:D(u)},kind:"error",name:`action:${o}`,...n===void 0?{}:{operationId:n},status:"error"}),u}finally{this._actionDepth--,h!==void 0&&this._traceCauseStack.pop()}}}untracked(e){return this._assertAlive(),this._runUntracked(e)}scope(e){return this._assertAlive(),new k.RaphScope(e,this)}node(e,t){this._assertAlive();const r=this._runNodeMutation(()=>{const s=e.parent??this.root,i=v.createProvisionalNode(s,e,this);try{const o=t==null?void 0:t(i);return i._assertAlive(),s._assertAlive(),i._setApi(o),i._publishCreation(),i}catch(o){try{i.dispose()}catch(c){throw new AggregateError([o,c],`[Raph] Node "${i.id}" setup and cleanup failed.`)}throw o}});return r._assertAlive(),r}getNode(e){this._assertAlive();const t=[this.root];for(;t.length!==0;){const r=t.pop();if(r.id===e)return r;t.push(...r.children)}}definePhases(e){this._execution.definePhases(e)}addPhase(e){this._execution.addPhase(e)}clearPhases(){var e;this._assertAlive(),(e=this._phases)==null||e.clearPhases()}requestExecution(){var e;this._assertAlive(),(e=this._phases)==null||e.request()}flush(){var e;this._assertAlive(),this._executionRequested=!1,(e=this._phases)==null||e.flush()}afterFlush(){var e;return this._assertAlive(),((e=this._phases)==null?void 0:e.afterFlush())??Promise.resolve()}acquireLoop(e){return this._assertAlive(),this._clock.acquire(e)}startLoop(){this._assertAlive(),this._clock.start()}stopLoop(){var e;(e=this._frameLoop)==null||e.stop()}derive(e){this._assertAlive();const t=e.compute,r=this.kernel.derive({...e,compute:s=>this._runUntracked(()=>t(s))});return this._own(()=>r.dispose(),this.rootScope),r}dispose(){var c,n;if(this._disposed)return;this._disposed=!0,this._executionRequested=!1,this._signalLifecycle.owner=void 0;const e=[],t=[...this._owners];try{(c=this._frameLoop)==null||c.dispose()}catch(a){e.push(a)}this._frameLoop=void 0;try{(n=this._phases)==null||n.dispose()}catch(a){e.push(a)}this._phases=void 0;try{this.root.dispose()}catch(a){e.push(a)}for(const a of t.reverse())if(!(a===this.root||a===this.rootScope||a.disposed))try{a.dispose()}catch(h){e.push(h)}try{this.rootScope.dispose()}catch(a){e.push(a)}const r=`[Raph] Runtime "${this.id}" is disposed.`,s=()=>{throw new w.RaphDisposedError(r)};try{S.disposeReactiveObjectContext(this._reactivity,{assertRead:s,assertWrite:s,throwForeign:s})}catch(a){e.push(a)}this._owners.clear(),this._meta=void 0;const i=this._pathHandles;if(this._pathHandles=void 0,i!==void 0){for(const a of i.values())try{a.dispose()}catch(h){e.push(h)}i.clear()}try{this._workGraph.dispose()}catch(a){e.push(a)}try{this.kernel._detachRuntime(this)}catch(a){e.push(a)}const o=[...this._disposedListeners];this._disposedListeners.clear();for(const a of o)try{a()}catch(h){e.push(h)}R.throwDisposalErrors(e,`[Raph] Runtime "${this.id}" disposal failed.`)}_onDisposed(e){return this._disposed?(e(),()=>{}):(this._disposedListeners.add(e),()=>{this._disposedListeners.delete(e)})}_notifyNodeStructure(e,t,r,s){this._runNodeMutation(()=>{this._workGraph.notifyNode(e,"structure",{structure:t,oldAncestors:r,newAncestors:s})})}_notifyNodeTouch(e,t){this._runNodeMutation(()=>this._workGraph.notifyNode(e,"touch",{metadata:t}))}_assertNodeReparentAllowed(e,t){this._workGraph.assertReparentAllowed(e,t)}_releaseNode(e){this._workGraph.releaseNode(e)}_runNodeMutation(e){return this._runWrite(e)}_runPhaseTransition(e){return this._runWrite(e,!1)}_beginOwnerDisposal(){this._ownerDisposalDepth++}_endOwnerDisposal(){this._ownerDisposalDepth!==0&&(this._ownerDisposalDepth--,this._clearTransientCausesIfSettled(),this._disposed||this._requestExecution())}_ownerDisposalActive(){return this._ownerDisposalDepth!==0}_registerOwner(e){this._assertAlive(),this._owners.add(e)}_unregisterOwner(e){this._owners.delete(e)}_assertOwnerRuntime(e){if(this._assertAlive(),e.runtime!==this)throw new w.RaphCrossRuntimeError("[Raph] Owner belongs to another runtime.");e._assertAlive()}_beginKernelBatch(){this._disposed||this._kernelBatchDepth++}_endKernelBatch(){this._kernelBatchDepth!==0&&(this._kernelBatchDepth--,this._clearTransientCausesIfSettled(),this._disposed||this._requestExecution())}_registerMachineDebug(e){return this._assertAlive(),this._debugController.registerMachine(e)}_hasMachineDebug(e){return this._debugController.hasMachine(e)}_traces(e){return this._debugController.traces(e)}_currentTraceCauseId(){return this._traceCauseStack.at(-1)}_nextTraceOperation(e){return this._debugController.nextOperationId(e)}_hasActiveReactiveContext(){return this._assertAlive(),this._reactivity.hasActiveContext()}_recordTrace(e){this._debugController.record(e)}_runWithTraceCause(e,t){if(e===void 0)return t();this._traceCauseStack.push(e);try{return t()}finally{this._traceCauseStack.pop()}}_validatePhaseBinding(e,t,r,s=!1){if(typeof t!="function")throw new TypeError("[Raph] Phase callback must be a function.");const i=e.trim();this._execution.requirePhase(i);const o=r.priority??0;if(!Number.isFinite(o))throw new TypeError("[Raph] Effect priority must be finite.");const c=r.initial??"scheduled";if(c!=="scheduled"&&c!=="sync"&&!(s&&c==="none"))throw new TypeError(`[Raph] Unsupported effect initial mode "${String(c)}".`);return i}_createDebugSnapshot(){var r,s,i;const e=((r=this._frameLoop)==null?void 0:r._debugState())??{running:!1,manual:!1,leases:0},t=[...this._owners].filter(o=>o!==this.rootScope&&!(o instanceof v.RaphNode)).map(g.createOwnerSnapshot);return Object.freeze({id:this.id,disposed:this._disposed,pending:!this._disposed&&(this._executionRequested||(((s=this._phases)==null?void 0:s._debugPending())??!1)),batchDepth:this._batchDepth,kernelBatchDepth:this._kernelBatchDepth,owners:this._owners.size,pathHandles:((i=this._pathHandles)==null?void 0:i.size)??0,rootScope:g.createOwnerSnapshot(this.rootScope),scopes:Object.freeze(t),root:g.createOwnerSnapshot(this.root),frameLoop:Object.freeze(e),actionDepth:this._actionDepth,machines:this._debugController.machineCount,traceEvents:this._debugController.traceSize})}_createDebugTree(){const e=this._debugController.machineTreeNodesByOwner(),t=[g.createOwnerTree(this.rootScope,e),g.createOwnerTree(this.root,e),...[...this._owners].filter(r=>r!==this.rootScope&&r!==this.root&&!(r instanceof v.RaphNode)).map(r=>g.createOwnerTree(r,e))];return Object.freeze({children:Object.freeze(t),disposed:this._disposed,id:this.id,kind:"runtime"})}_createDebugStats(){var i,o;let e=0,t=0,r=0,s=0;for(const c of this._owners)c instanceof v.RaphNode?e++:t++,r+=c._debugResourceCount(),s+=c._debugSourceCount();return Object.freeze({actors:this._debugController.actorCount,machines:this._debugController.machineCount,nodes:e,owners:this._owners.size,pathHandles:((i=this._pathHandles)==null?void 0:i.size)??0,pending:!this._disposed&&(this._executionRequested||(((o=this._phases)==null?void 0:o._debugPending())??!1)),resources:r,scopes:t,sources:s,traceEvents:this._debugController.traceSize})}_releasePathHandle(e){const t=this._pathHandles;(t==null?void 0:t.get(e.path))===e&&(t.delete(e.path),t.size===0&&(this._pathHandles=void 0))}get _execution(){return this._assertAlive(),this._phases??(this._phases=new O.RaphPhasePipeline(this.configuration.scheduler,e=>this._runUntracked(e),e=>this._workGraph.causeForToken(e),()=>{const e=this._mutationDepth!==0||this._batchDepth!==0||this._kernelBatchDepth!==0||this._ownerDisposalDepth!==0||this._reactivity._isFlushingEffects();return e&&this.configuration.scheduler===m.RaphSchedulerType.Sync&&(this._executionRequested=!0),e},(e,t,r)=>{var i,o,c;let s;t==="start"?(s=this._debugController.nextOperationId("phase"),s!==void 0&&(this._phaseTraceOperations??(this._phaseTraceOperations=new Map)).set(e,s)):(s=(i=this._phaseTraceOperations)==null?void 0:i.get(e),(o=this._phaseTraceOperations)==null||o.delete(e),((c=this._phaseTraceOperations)==null?void 0:c.size)===0&&(this._phaseTraceOperations=void 0)),this._debugController.record({...s===void 0?{}:{causeId:s},...r===void 0?{}:{details:{message:D(r)}},kind:"phase",name:e,...s===void 0?{}:{operationId:s},status:t})}))}get _clock(){return this._frameLoop??(this._frameLoop=new x.RaphFrameLoop(()=>this._tickFrameLoop()))}_tickFrameLoop(){this._disposed||this._setFrameTick(this._frameTickWritable.peek()+1)}_attachWritableComputed(e,t,r){let s=t;this._own(()=>{s=void 0},r);const i=e;return i.set=o=>{r._assertAlive(),this._assertWriteAllowed(),this._runWrite(()=>s(o))},i}_own(e,t){try{return t._adoptResource(e)}catch(r){try{e()}catch(s){throw new AggregateError([r,s],"[Raph] Resource registration and cleanup failed.")}throw r}}_runTracked(e,t){return this._reactivity.runWithOwner(this._signalLifecycle,e,t)}_runUntracked(e){return this._reactivity.untrackedWithOwner(e)}_runWrite(e,t=!0){t&&this.configuration.scheduler===m.RaphSchedulerType.Sync&&(this._executionRequested=!0),this._mutationDepth++;let r,s,i=!1;try{r=e()}catch(c){i=!0,s=c}this._mutationDepth--;const o=this._finishExecutionBoundary();if(i)throw o.length!==0?new AggregateError([s,...o],"[Raph] Mutation and scheduled phase execution failed."):s;return R.throwDisposalErrors(o,"[Raph] Mutation phase execution failed."),r}_finishExecutionBoundary(){const e=[];try{this._clearTransientCausesIfSettled()}catch(t){e.push(t)}try{this._requestExecution()}catch(t){e.push(t)}return e}_clearTransientCausesIfSettled(){this._mutationDepth===0&&this._batchDepth===0&&this._kernelBatchDepth===0&&this._ownerDisposalDepth===0&&!this._reactivity._isFlushingEffects()&&this._workGraph.clearTransientCauses()}_requestExecution(){var e;this._disposed||this.configuration.scheduler!==m.RaphSchedulerType.Sync||this._mutationDepth!==0||this._batchDepth!==0||this._kernelBatchDepth!==0||this._ownerDisposalDepth!==0||this._reactivity._isFlushingEffects()||this._executionRequested&&(this._executionRequested=!1,(e=this._phases)==null||e.flush())}_assertTrackedRead(){this._assertAlive();const e=this._reactivity.getActiveOwner();e!==void 0&&e!==this&&this._throwCrossRuntime(e);const t=this._reactivity.getActiveConsumerOwner();t!==void 0&&this._assertImplicitDependency(this.rootScope,t)}_assertSourceReadable(e){this._assertAlive();const t=this._reactivity.getActiveOwner();t!==void 0&&t!==this&&this._throwCrossRuntime(t);const r=this._reactivity.getActiveConsumerOwner();r!==void 0&&this._assertImplicitDependency(e,r),e._assertAlive()}_assertImplicitDependency(e,t){if(e.runtime!==this||t.runtime!==this)throw new w.RaphCrossRuntimeError("[Raph] Implicit dependency crosses runtime boundaries.");if(!(e===this.rootScope||e===t)){if(e instanceof v.RaphNode&&t instanceof v.RaphNode){for(let r=t.parent;r!==null;r=r.parent)if(r===e)return}throw new Error(`[Raph] Implicit dependency from "${t.id}" to "${e.id}" is not allowed; use watch().`)}}_assertWriteAllowed(){if(this._assertAlive(),this.configuration.enforceActions&&this._batchDepth===0)throw new w.RaphActionError("[Raph] Writes are allowed only inside action() or batch().")}_throwCrossRuntime(e){throw new w.RaphCrossRuntimeError(`[Raph] Runtime "${this.id}" cannot be tracked by runtime "${e.id}".`)}_assertAlive(){if(this._disposed)throw new w.RaphDisposedError(`[Raph] Runtime "${this.id}" is disposed.`)}};d(b,"_runtimeCounter",0);let A=b;function H(p){return p===m.RaphSchedulerType.Sync||p===m.RaphSchedulerType.Microtask||p===m.RaphSchedulerType.AnimationFrame}function I(p,e){const t=Array.isArray(p)?p:[p];if(t.length===0)throw new TypeError("[RaphMeta] watch requires at least one mask.");if(e.namespace!==void 0&&!e.namespace.trim())throw new Error("[RaphMeta] namespace must not be empty.");for(const r of t)P.DataPath.from(r,e)._asMask()}function D(p){return p instanceof Error?p.message:String(p)}exports.RaphRuntime=A;
|