@raphy-js/raph 1.0.1-dev.26 → 1.0.1-dev.54
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 +100 -0
- package/dist/api/Raph.d.ts +15 -15
- package/dist/api/RaphFacadeSession.d.ts +4 -4
- package/dist/api/RaphReactivityInstance.d.ts +4 -4
- package/dist/api/types.d.ts +11 -11
- package/dist/compact.cjs +1 -0
- package/dist/compact.js +4 -0
- package/dist/debug/reactivity/engine-core.cjs +1 -0
- package/dist/debug/reactivity/engine-core.js +1760 -0
- package/dist/debug/reactivity/engine.cjs +1 -1
- package/dist/debug/reactivity/engine.js +25 -1689
- package/dist/debug/reactivity/reactive-object.cjs +1 -1
- package/dist/debug/reactivity/reactive-object.js +604 -167
- package/dist/debug/runtime/RaphCompactExecutionRuntime.cjs +1 -0
- package/dist/debug/runtime/RaphCompactExecutionRuntime.js +9 -0
- package/dist/debug/runtime/RaphExecutionRuntime.cjs +1 -0
- package/dist/debug/runtime/RaphExecutionRuntime.js +11 -0
- package/dist/debug/runtime/RaphRuntime.cjs +1 -1
- package/dist/debug/runtime/RaphRuntime.js +115 -1176
- package/dist/debug/runtime/RaphRuntimeBase.cjs +1 -0
- package/dist/debug/runtime/RaphRuntimeBase.js +941 -0
- package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -1
- package/dist/debug/runtime/diagnostics/RaphDebug.js +72 -66
- package/dist/debug/runtime/ownership/RaphNode.cjs +1 -1
- package/dist/debug/runtime/ownership/RaphNode.js +11 -0
- package/dist/debug/runtime/ownership/RaphScope.cjs +1 -1
- package/dist/debug/runtime/ownership/RaphScope.js +12 -12
- package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -1
- package/dist/debug/runtime/phases/RaphPhasePipeline.js +361 -242
- package/dist/debug/runtime/phases/RaphPhaseTaskRecord.cjs +1 -1
- package/dist/debug/runtime/phases/RaphPhaseTaskRecord.js +23 -22
- package/dist/debug/runtime/reactivity/RaphSelector.cjs +1 -1
- package/dist/debug/runtime/reactivity/RaphSelector.js +111 -90
- package/dist/debug/runtime/reactivity/RuntimeObjectSupport.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeObjectSupport.js +11 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -1
- package/dist/debug/runtime/reactivity/RuntimeReactivity.js +118 -103
- package/dist/debug/runtime/reactivity/RuntimeSelectorSupport.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeSelectorSupport.js +12 -0
- package/dist/entrypoints/compact.d.ts +2 -0
- package/dist/entrypoints/execution.d.ts +2 -0
- package/dist/entrypoints/machine-testing.d.ts +2 -2
- package/dist/entrypoints/machine.d.ts +5 -5
- package/dist/entrypoints/observable.d.ts +4 -0
- package/dist/entrypoints/path.d.ts +14 -14
- package/dist/entrypoints/reactivity.d.ts +1 -1
- package/dist/entrypoints/runtime.d.ts +19 -18
- package/dist/execution.cjs +1 -0
- package/dist/execution.js +4 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +23 -21
- package/dist/machine/compiler.d.ts +1 -1
- package/dist/machine/core.d.ts +2 -2
- package/dist/machine/persistence.d.ts +1 -1
- package/dist/machine/runtime.d.ts +3 -3
- package/dist/machine/testing.d.ts +1 -1
- package/dist/machine/types.d.ts +3 -3
- package/dist/main.d.ts +19 -19
- package/dist/observable/buffer.d.ts +6 -0
- package/dist/observable/class-admin.d.ts +63 -0
- package/dist/observable/class-plan.d.ts +46 -0
- package/dist/observable/classes.d.ts +10 -0
- package/dist/observable/context.d.ts +73 -0
- package/dist/observable/native.d.ts +2 -0
- package/dist/observable/observable.d.ts +13 -0
- package/dist/observable/types.d.ts +60 -0
- package/dist/observable.cjs +1 -0
- package/dist/observable.js +1187 -0
- package/dist/path/DataPath.d.ts +2 -2
- package/dist/path/PathRouter.d.ts +1 -1
- package/dist/path/RaphKernel.d.ts +6 -6
- package/dist/path/data-path.types.d.ts +1 -1
- package/dist/path/data-path.utils.d.ts +2 -2
- package/dist/path/derived/DerivedRegistry.d.ts +3 -3
- package/dist/path/derived/RaphDerivedHandle.d.ts +3 -3
- package/dist/path/derived/derived-collection.types.d.ts +1 -1
- package/dist/path/derived/derived-collection.utils.d.ts +3 -3
- package/dist/path/derived/derived-strategy.utils.d.ts +1 -1
- package/dist/path/meta/MetaController.d.ts +5 -5
- package/dist/path/meta/RaphMeta.d.ts +3 -3
- package/dist/path/meta/RaphMetaStore.d.ts +1 -1
- package/dist/path/meta/meta.types.d.ts +2 -2
- package/dist/path/path.types.d.ts +2 -2
- package/dist/path/pathSegmentKey.d.ts +1 -1
- package/dist/path/storage/AdapterPathStore.d.ts +2 -2
- package/dist/path/storage/DefaultDataAdapter.d.ts +2 -2
- package/dist/path/storage/PathEventHub.d.ts +1 -1
- package/dist/path/storage/PathStore.d.ts +2 -2
- package/dist/path/storage/data-adapter.types.d.ts +1 -1
- package/dist/raph.cjs +1 -1
- package/dist/raph.js +23 -21
- package/dist/reactivity/engine-core.d.ts +600 -0
- package/dist/reactivity/engine.d.ts +6 -550
- package/dist/reactivity/reactive-object.d.ts +143 -2
- package/dist/reactivity/scope.d.ts +7 -6
- package/dist/reactivity/types.d.ts +9 -12
- package/dist/reactivity/watch.d.ts +1 -1
- package/dist/runtime/RaphCompactExecutionRuntime.d.ts +7 -0
- package/dist/runtime/RaphExecutionRuntime.d.ts +6 -0
- package/dist/runtime/RaphRuntime.d.ts +19 -403
- package/dist/runtime/RaphRuntimeBase.d.ts +194 -0
- package/dist/runtime/diagnostics/RaphDebug.d.ts +8 -5
- package/dist/runtime/errors.d.ts +1 -1
- package/dist/runtime/ownership/RaphEffectScope.d.ts +13 -12
- package/dist/runtime/ownership/RaphNode.d.ts +28 -21
- package/dist/runtime/ownership/RaphScope.d.ts +32 -19
- package/dist/runtime/ownership/parent-graph.types.d.ts +1 -1
- package/dist/runtime/ownership/parentGraph.d.ts +2 -2
- package/dist/runtime/phases/RaphFrameLoop.d.ts +1 -1
- package/dist/runtime/phases/RaphPhasePipeline.d.ts +80 -29
- package/dist/runtime/phases/RaphPhaseTaskRecord.d.ts +21 -21
- package/dist/runtime/phases/RaphPhaseWatch.d.ts +3 -3
- package/dist/runtime/phases/orderPhaseTasks.d.ts +4 -2
- package/dist/runtime/phases/phase.types.d.ts +36 -35
- package/dist/runtime/reactivity/PathHandle.d.ts +5 -5
- package/dist/runtime/reactivity/RaphMetaSource.d.ts +7 -7
- package/dist/runtime/reactivity/RaphSelector.d.ts +27 -6
- package/dist/runtime/reactivity/RaphWorkGraph.d.ts +40 -39
- package/dist/runtime/reactivity/RuntimeObjectSupport.d.ts +9 -0
- package/dist/runtime/reactivity/RuntimeReactivity.d.ts +27 -19
- package/dist/runtime/reactivity/RuntimeSelectorSupport.d.ts +10 -0
- package/dist/runtime/reactivity/RuntimeWatch.d.ts +1 -1
- package/dist/runtime/reactivity/disposal-sweep.utils.d.ts +1 -1
- package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +3 -3
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +13 -11
- package/package.json +22 -62
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("./reactive-object.cjs"),D=require("./scope.cjs"),O=require("./watch.cjs"),g=1,f=2,y=4,p=8,T=16,d=32,v=64,w=128,x=256,o=512,N=2048,k=4096,R=8192,m=N|k,A=1e4,b=g|f,C=16,U=2;function L(c){c.dependencyLookupDebt===void 0&&c.dependencyIndex===void 0||(c.dependencyIndex=void 0,c.dependencyLookupDebt=void 0,c.dependencyLookupSearches=void 0)}function W(c,e){if(e<=C||c.flags&w||c.dependencyIndex!==void 0)return;const t=(c.dependencyLookupSearches??0)+1,i=(c.dependencyLookupDebt??0)+e;if(c.dependencyLookupSearches=t,c.dependencyLookupDebt=i,t<U||i<c.depCount)return;const s=new Map;for(let n=c.firstDep;n!==null;n=n.nextDep)s.set(n.dep,n);c.dependencyIndex=s,c.dependencyLookupDebt=void 0,c.dependencyLookupSearches=void 0}function q(c,e,t){const i=c.firstSub;if(i===null)return;if(i===c.lastSub)return i.sub===e?i:void 0;const s=c.subSearchCursor??i;let n=1;if(s.sub===e)return c.subSearchCursor=s.nextSub??i,s;if(t){const a=e.dependencyIndex?.get(c);if(a!==void 0)return c.subSearchCursor=a.nextSub??i,a;if(e.dependencyIndex!==void 0)return}let r=s.nextSub??i;for(;r!==s;){if(++n,r.sub===e)return c.subSearchCursor=r.nextSub??i,t&&W(e,n),r;r=r.nextSub??i}t&&W(e,n)}class _{adaptiveDependencyIndex;activeSub=null;batchDepth=0;effectReadIndex=0;effectWriteIndex=0;invalidationDepth=0;dependencyDepth=0;checkingDepth=0;flushingEffects=!1;effectQueue=new Array(16).fill(void 0);invalidationStack=new Array(512).fill(null);dependencyStack=[];handleReaders=this.createHandleReaders();effectScheduler;flushEffects;_effectImmediate;constructor(e={}){this.adaptiveDependencyIndex=e.adaptiveDependencyIndex??!1,this.effectScheduler=e.effectScheduler,this._effectImmediate=this.effect.bind(this),this.signal=this.signal.bind(this),this.computed=this.computed.bind(this),this.reactive=this.reactive.bind(this),this.watch=this.watch.bind(this),this.batch=this.batch.bind(this),this.untracked=this.untracked.bind(this),this.scope=this.scope.bind(this),this._signalAccess=this._signalAccess.bind(this),this._computedAccess=this._computedAccess.bind(this),this._ownedSignal=this._ownedSignal.bind(this),this._ownedComputed=this._ownedComputed.bind(this),this._isTracking=this._isTracking.bind(this),this._isFlushingEffects=this._isFlushingEffects.bind(this),this._startBatch=this._startBatch.bind(this),this._endBatch=this._endBatch.bind(this),this.effect=this.effectScheduler===void 0?this._effectImmediate:this.createScheduledEffect.bind(this),this.flushEffects=this.effectScheduler===void 0?this.flushSyncEffects:this.flushExternalEffects}signal(e){let t=e,i;const s=()=>{const r=i;if(r!==void 0)return this.readSignalValue(r);const a=this.activeSub;return a===null||(i=this.materializeSignal(t,a)),t},n=r=>{const a=i;if(a!==void 0){this.writeSignalValue(a,r);return}t!==r&&(t=r)};return{get:s,peek:this.handleReaders.peek,set:n}}reactive(e){return H.reactiveObject(this,e,()=>this.createReactivePropertySourceBridge())}computed(e){if(typeof e=="function")return this.createComputedHandle(e);const t=this.createComputedHandle(e.get);return t.set=e.set,t}effect(e,t){const i=this.allocateGraphRecord(void 0,e,f|g|d);t!==void 0&&(i.onStop=t);const s=this.activeSub;s!==null&&s.flags&d&&D.appendScopeChild(s,i);try{this.executeEffect(i)}catch(n){try{this.disposeEffect(i)}catch(r){throw new AggregateError([n,r],"Effect registration and cleanup failed.")}throw n}return this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects(),()=>this.disposeEffect(i)}watch(e,t,i){return O.watchWithReactivity(this.effect,this.untracked,e,t,i)}batch(e){++this.batchDepth;let t;try{t=e()}catch(i){if(!--this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex)try{this.flushEffects()}catch(s){throw new AggregateError([i,s],"Batch operation and effect queue processing failed.")}throw i}return!--this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects(),t}untracked(e){if(this.activeSub===null)return e();const t=this.activeSub;this.activeSub=null;try{return e()}finally{this.activeSub=t}}scope(){return new D.ScopeNode(this)}allocateGraphRecord(e,t,i){return{flags:i,firstSub:null,lastSub:null,firstDep:null,tailDep:null,depCount:0,evaluate:t,cachedValue:e}}createReactivePropertySourceBridge(){return{batch:this.batch,create:()=>{if(this.activeSub===null)throw new Error("[Raph] Reactive property source requires a tracked read.");return{firstSub:null,lastSub:null}},isTracking:this._isTracking,track:e=>{const t=this.activeSub;t!==null&&this.trackDependency(e,t)},trigger:e=>{const t=e.firstSub;t!==null&&(this.propagateInvalidation(t),!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects())}}}materializeSignal(e,t,i){const s=this.allocateGraphRecord(e,void 0,0);return i!==void 0&&(s.sourceHooks=i,s.flags|=o),t.flags&w?this.appendInitialDependency(s,t):this.trackDependency(s,t),s}createComputedHandle(e,t){const i={evaluate:e,get:this.handleReaders.initializeComputed,peek:this.handleReaders.peek};return t!==void 0&&(i.sourceHooks=t),i}createScheduledEffect(e,t){const i=this.allocateGraphRecord(void 0,e,f|g|d);let s=!1;t!==void 0&&(i.onStop=t);const n=this.activeSub;n!==null&&n.flags&d&&D.appendScopeChild(n,i);const r=()=>{if(!(!(i.flags&v)||i.evaluate===void 0)){i.flags&=~v,s=!0;try{this.executeEffect(i)}catch(a){if(!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex)try{this.flushEffects()}catch(l){throw new AggregateError([a,l],"Effect execution and queue processing failed.")}throw a}!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects()}};try{const a=this.effectScheduler.bind(r);a.cancelPending=()=>i.evaluate===void 0||!s?!1:(this.settleCancelledDependencies(i),i.flags&=~(v|b|y),!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects(),!0),a.rearmPending=()=>{i.evaluate!==void 0&&(i.flags|=f|v,a.schedule())},i.effectTask=a,this.requestEffectTask(i)}catch(a){try{this.disposeEffect(i)}catch(l){throw new AggregateError([a,l],"Effect registration and cleanup failed.")}throw a}return!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects(),()=>this.disposeEffect(i)}readSignalValue(e){const t=this.activeSub;let i=null;return t!==null&&(i=this.trackDependency(e,t)),e.flags&f&&this.commitSignalValue(e,i),e.cachedValue}writeSignalValue(e,t){if(e.flags&f||this.batchDepth){const s=!!(e.flags&f);if((e.flags&f?e.pendingValue:e.cachedValue)===t)return;if(e.pendingValue=t,e.cachedValue===t)e.flags&=~f,e.pendingAuthor=void 0;else{e.flags|=f;const a=this.activeSub!==null&&this.activeSub.flags&p?this.activeSub:null;s?e.pendingAuthor!==a&&(e.pendingAuthor=null):e.pendingAuthor=a}const r=e.firstSub;r!=null&&(!s||this.activeSub!==null&&this.activeSub.flags&p||e.flags&o)&&this.propagateInvalidation(r,!0);return}if(e.cachedValue===t)return;e.cachedValue=t;const i=e.firstSub;i!=null&&(this.propagateInvalidation(i),!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects())}readComputedValue(e){const t=e.flags;if((t&(p|w))===(p|w))throw new Error("Computed value is already being evaluated.");const i=t&(T|b|x),s=i===0?e.cachedValue:i&T?this.evaluateFirstValue(e):this.refreshComputedValue(e,t);if(e.evaluate===void 0)return s;const n=this.activeSub;if(n!==null){const r=n.tailDep;n.flags&w?(r===null||r.dep!==e)&&this.appendInitialDependency(e,n):this.trackDependency(e,n)}return s}evaluateFirstValue(e){const t=e.flags&o,i=e.evaluate;e.flags=t|p|w;const s=this.activeSub;this.activeSub=e;let n;try{if(n=i(),e.evaluate!==i)return e.cachedValue=void 0,e.flags=0,n;e.flags=t|(e.flags&y?f:0)}catch(r){throw e.evaluate!==i?(e.cachedValue=void 0,e.flags=0,r):(e.flags=t|x,s!==null&&this.trackDependency(e,s),r)}finally{this.activeSub=s}return e.flags&f?this.refreshComputedValue(e,e.flags):(e.cachedValue=n,n)}refreshComputedValue(e,t,i=null){try{if(t&(f|y|x))return this.recomputeValue(e,i),e.cachedValue;const s=e.firstDep;return s!==null&&this.refreshDependencies(e,s)?this.recomputeValue(e,i):e.flags&=~b,e.cachedValue}catch(s){throw this.activeSub!==null&&this.trackDependency(e,this.activeSub),s}}commitSignalValue(e,t){const i=e.cachedValue;e.cachedValue=e.pendingValue,e.flags&=~f;const s=e.pendingAuthor;return e.pendingAuthor=void 0,i===e.cachedValue?!1:(e.firstSub!==null&&this.confirmSubUpdates(e.firstSub,t,s??null),!0)}trackDependency(e,t){const i=t.tailDep;if(i!==null){const n=i.nextDep;return n!==null&&n.dep===e?(t.tailDep=n,n):i.dep===e?i:this.reconcileDependency(e,t,i,n)}const s=t.firstDep;return s===null?t.tailDep=this.insertDependency(e,t,null):s.dep===e?(t.tailDep=s,s):this.reconcileDependency(e,t,null,s)}reconcileDependency(e,t,i,s){if(t.depCount<=C){for(let l=s;l!==null;l=l.nextDep)if(l.dep===e)return this.reorderDependency(t,l,i),t.tailDep=l,l;for(let l=i;l!==null;l=l.prevDep)if(l.dep===e)return l;return s!==null?(t.tailDep=this.reuseDepLink(s,e),s):t.tailDep=this.insertDependency(e,t,i)}let n=0,r=s;for(;r!==null&&n<C;){const l=r;if(l.dep===e)return this.reorderDependency(t,l,i),t.tailDep=l,l;r=l.nextDep,++n}let a=i;for(;a!==null&&n<C;){const l=a;if(l.dep===e)return l;a=l.prevDep,++n}if(r!==null||a!==null){const l=q(e,t,this.adaptiveDependencyIndex);if(l!==void 0)return this.reorderDependency(t,l,i),t.tailDep=l,l}return s!==null?(t.tailDep=this.reuseDepLink(s,e),s):t.tailDep=this.insertDependency(e,t,i)}appendInitialDependency(e,t){const i=t.tailDep,s=e.lastSub,n={dep:e,sub:t,prevSub:s,nextSub:null,prevDep:i,nextDep:null};return s===null?e.firstSub=n:s.nextSub=n,e.lastSub=n,i===null?t.firstDep=n:i.nextDep=n,t.tailDep=n,++t.depCount,t.dependencyIndex?.set(e,n),e.flags&o&&this.attachDependencyCleanup(n),n}insertDependency(e,t,i){const s=e.lastSub,n={dep:e,sub:t,prevSub:s,nextSub:null,prevDep:i,nextDep:null};s===null?e.firstSub=n:s.nextSub=n,e.lastSub=n;const r=i===null?t.firstDep:i.nextDep;return n.nextDep=r,r!==null&&(r.prevDep=n),i===null?t.firstDep=n:i.nextDep=n,++t.depCount,t.dependencyIndex?.set(e,n),e.flags&o&&this.attachDependencyCleanup(n),n}reuseDepLink(e,t){const i=e.sub.dependencyIndex;this.detachSubLink(e);const s=t.lastSub;return e.dep=t,e.prevSub=s,e.nextSub=null,s===null?t.firstSub=e:s.nextSub=e,t.lastSub=e,i?.set(t,e),t.flags&o&&this.attachDependencyCleanup(e),e}reorderDependency(e,t,i){if(t.prevDep===i)return;const s=t.prevDep,n=t.nextDep;s===null?e.firstDep=n:s.nextDep=n,n!==null&&(n.prevDep=s);const r=i===null?e.firstDep:i.nextDep;t.prevDep=i,t.nextDep=r,r!==null&&(r.prevDep=t),i===null?e.firstDep=t:i.nextDep=t}pruneUnreadDependencies(e){const t=e.tailDep;let i=t===null?e.firstDep:t.nextDep;if(i===null)return;t===null?e.firstDep=null:t.nextDep=null;for(let n=i;n!==null;n=n.nextDep)n.prevDep=null,--e.depCount;e.depCount<=C&&L(e);let s;for(;i!==null;){const n=i.nextDep;try{this.detachSubLink(i,!0)}catch(r){this.unlinkSubLink(i,!0),s??=[],s.push(r)}i=n}s!==void 0&&D.throwScopeErrors(s,"Dependency cleanup failed.")}detachSubLink(e,t=!1){e.sub.dependencyIndex?.delete(e.dep);let i;e.dep.flags&o&&(i=e.dependencyCleanup,e.dependencyCleanup=void 0,i?.()),this.unlinkSubLink(e,t||i!==void 0)}unlinkSubLink(e,t){t&&((e.prevSub===null?e.dep.firstSub!==e:e.prevSub.nextSub!==e)||(e.nextSub===null?e.dep.lastSub!==e:e.nextSub.prevSub!==e))||(e.dep.subSearchCursor===e&&(e.dep.subSearchCursor=e.nextSub??(e.dep.firstSub===e?void 0:e.dep.firstSub??void 0)),e.prevSub===null?e.dep.firstSub=e.nextSub:e.prevSub.nextSub=e.nextSub,e.nextSub===null?e.dep.lastSub=e.prevSub:e.nextSub.prevSub=e.prevSub)}attachDependencyCleanup(e){const i=e.dep.sourceHooks?.onDependency;if(i===void 0)return;const s=e.sub.sourceHooks?.dependencyOwner??e.sub.effectTask?.dependencyOwner;s!==void 0&&(e.dependencyCleanup=i(s))}releaseSourceSubs(e){if(!(e.flags&o)){let s=e.firstSub;for(;s!=null;){const n=s.nextSub,r=s.sub;this.detachDependencyLink(s),this.detachSubLink(s);const a=r.flags;(a&(b|p))===g&&(r.flags=a&~g|f,a&d&&this.enqueueEffect(r,e)),s=n}e.firstSub=e.lastSub=null,e.subSearchCursor=void 0;return}let t=e.firstSub,i;for(;t!=null;){const s=t.nextSub;this.detachDependencyLink(t);try{this.detachSubLink(t,!0)}catch(n){this.unlinkSubLink(t,!0),i??=[],i.push(n)}t=s}e.firstSub=e.lastSub=null,e.subSearchCursor=void 0,i!==void 0&&D.throwScopeErrors(i,"Source dependency cleanup failed.")}detachDependencyLink(e){const t=e.sub,i=e.prevDep,s=e.nextDep;(i===null?t.firstDep!==e:i.nextDep!==e)||(i===null?t.firstDep=s:i.nextDep=s,s!==null&&(s.prevDep=i),t.tailDep===e&&(t.tailDep=i),--t.depCount,t.depCount<=C&&L(t))}enqueueEffect(e,t){const i=t!==void 0&&t.flags&o?t.sourceHooks.token:void 0;i!==void 0&&e.effectTask?.notify?.(i),!(e.flags&v)&&(e.flags|=v,this.effectQueue[this.effectWriteIndex]=e,++this.effectWriteIndex)}propagateInvalidation(e,t=!1){this.checkingDepth!==0&&this.markActiveChecks(e);const i=this.invalidationDepth;let s=i;for(let n=e;n!==null;n=n.nextSub){const r=n.sub,a=r.flags;let l=0;if(a&(b|p)?a&p?l=this.invalidateReadDependency(n,r,a):!t&&!(a&f)&&(r.flags=a&~g|f):(l=a&~y|(t?g:f),r.flags=l),l===0){if(a&d&&a&v){const u=n.dep.flags&o?n.dep.sourceHooks.token:void 0;u!==void 0&&r.effectTask?.notify?.(u)}else r.flags&(o|R)&&(r.flags&o&&r.sourceHooks.onInvalidate?.(r.firstSub!==null),r.flags&=~R,r.firstSub!==null&&(this.invalidationStack[s++]=r.firstSub));continue}l&d?(!(l&p)||r.effectTask?.allowScheduleDuringRun===!0)&&this.enqueueEffect(r,n.dep):(!(a&b)&&r.flags&o&&r.sourceHooks.onInvalidate?.(r.firstSub!==null),r.firstSub!==null&&(this.invalidationStack[s++]=r.firstSub))}for(;s!==i;){let n=this.invalidationStack[--s];do{const r=n.sub,a=r.flags;let l=0;if(a&(b|p)?a&p&&(l=this.invalidateReadDependency(n,r,a)):(l=a&~y|g,r.flags=l),l===0){if(a&d&&a&v){const u=n.dep.flags&o?n.dep.sourceHooks.token:void 0;u!==void 0&&r.effectTask?.notify?.(u)}else if(r.flags&(o|R)&&(r.flags&o&&r.sourceHooks.onInvalidate?.(r.firstSub!==null),r.flags&=~R,r.firstSub!==null)){n.nextSub!==null&&(this.invalidationStack[s++]=n.nextSub),n=r.firstSub;continue}}else if(l&d)this.enqueueEffect(r,n.dep);else if(!(a&b)&&r.flags&o&&r.sourceHooks.onInvalidate?.(r.firstSub!==null),r.firstSub!==null){n.nextSub!==null&&(this.invalidationStack[s++]=n.nextSub),n=r.firstSub;continue}n=n.nextSub}while(n!==null)}this.invalidationDepth=i}markActiveChecks(e){const t=[e],i=new Set;for(;t.length!==0;)for(let s=t.pop();s!==null;s=s.nextSub){const n=s.sub;i.has(n)||(i.add(n),n.flags&N&&(n.flags|=k),!(n.flags&d)&&n.firstSub!==null&&t.push(n.firstSub))}}invalidateReadDependency(e,t,i){const s=t.tailDep;if(s===null)return 0;if(e!==s){for(let r=e.prevDep;r!==null;r=r.prevDep)if(r===s)return 0}const n=i|y|g;return t.flags=n,n}confirmSubUpdates(e,t,i=null){for(let s=e;s!==null;s=s.nextSub){if(s===t||s.sub===i)continue;const n=s.sub,r=n.flags;r&f||(n.flags=r&~g|f,r&d?this.enqueueEffect(n,s.dep):r&b||n.flags&o&&n.sourceHooks.onInvalidate?.(n.firstSub!==null))}}recomputeValue(e,t=null){const i=e.cachedValue;for(let s=0;s<A;s++){const n=e.evaluate;e.tailDep=null;const r=e.flags&-6149|p;e.flags=r;const a=this.activeSub;this.activeSub=e;let l;try{l=n()}catch(h){if(e.evaluate!==n)throw e.cachedValue=void 0,e.flags=0,h;this.failComputedValue(e,t,h)}finally{this.activeSub=a}if(e.evaluate!==n)return e.cachedValue=void 0,e.flags=0,!1;const u=e.tailDep;if((u===null?e.firstDep:u.nextDep)!==null)try{this.pruneUnreadDependencies(e)}catch(h){this.failComputedValue(e,t,h)}if(e.evaluate!==n)return e.cachedValue=void 0,e.flags=0,!1;const I=e.flags&y;if(e.flags=r&-8460,I){e.flags|=f;continue}return e.cachedValue=l,i===l?!1:(e.firstSub!==null&&this.confirmSubUpdates(e.firstSub,t),!0)}return this.failComputedValue(e,t,new Error(`Computed settlement exceeded ${A} attempts.`))}failComputedValue(e,t,i){try{this.restoreComputedFailure(e,t)}catch(s){throw new AggregateError([i,s],"Computed evaluation and dependency cleanup failed.")}throw i}restoreComputedFailure(e,t){e.evaluate!==void 0&&(e.flags=e.flags&-6288|x);try{e.evaluate!==void 0&&this.pruneUnreadDependencies(e)}finally{e.evaluate===void 0&&(e.cachedValue=void 0,e.flags=0),t!==null&&this.restoreFailedDependency(t.sub)}}refreshDependencies(e,t){const i=this.dependencyDepth;try{return this.walkDependencyChain(e,t)}catch(s){this.markRecoveryDependencies(e),this.restoreFailedDependency(e);for(let n=i;n<this.dependencyDepth;n++)this.restoreFailedDependency(this.dependencyStack[n].sub);throw this.dependencyDepth=i,this.dependencyStack.length=i,s}}settleCancelledDependencies(e){for(let t=e.firstDep;t!==null;t=t.nextDep){const i=t.dep,s=i.flags;s&(T|b|x)&&(i.evaluate===void 0?s&f&&this.commitSignalValue(i,t):this.refreshComputedValue(i,s,t))}}walkDependencyChain(e,t){const i=this.dependencyDepth;let s=i,n=!1,r;e.flags=e.flags&~k|N,++this.checkingDepth;try{e:for(;;){if(e.flags&k){r??=new Map;const a=(r.get(e)??0)+1;if(r.set(e,a),a>A)throw new Error(`Dependency check exceeded ${A} restarts.`);e.flags&=~k,e.firstDep!==null&&(t=e.firstDep)}if(e.flags&f)n=!0;else{const a=t.dep,l=a.flags;if(l&(f|x))this.dependencyDepth=s,n=a.evaluate===void 0?this.commitSignalValue(a,t):this.recomputeValue(a,t);else if(l&g){if(a.firstDep!==null){this.dependencyStack[s++]=t,e=a,e.flags=e.flags&~k|N,t=a.firstDep;continue e}this.dependencyDepth=s,n=this.recomputeValue(a,t)}else n=!1}if(!n&&t.nextDep!==null){t=t.nextDep;continue}if(n){for(;s!==i;){this.dependencyDepth=--s;const a=this.dependencyStack[s];if(e.flags&=~m,n=this.recomputeValue(e,a),e=a.sub,!n){if(a.nextDep!==null){t=a.nextDep;continue e}break}}if(n)return this.dependencyDepth=i,!0}for(;s!==i;){if(e.flags&(f|k))continue e;this.dependencyDepth=--s;const a=this.dependencyStack[s];if(e.flags&=~(g|m),e=a.sub,a.nextDep!==null){t=a.nextDep;continue e}}if(e.flags&(f|k))continue e;return e.flags&=~(g|m),this.dependencyDepth=i,!1}}finally{e.flags&=~m;for(let a=i;a<s;a++)this.dependencyStack[a].sub.flags&=~m;--this.checkingDepth}}restoreFailedDependency(e){if(e.evaluate===void 0){e.cachedValue=void 0,e.flags=0;return}e.flags&=-6160,e.flags&d||(e.flags|=x)}executeEffect(e){const t=e.flags;if(!(t&b))return;if(!(t&(f|y))){const u=e.firstDep;try{if(u===null||!this.refreshDependencies(e,u)){e.flags&=~b;return}}catch(I){throw e.flags&=-80,I}}const i=e.evaluate;if(i===void 0){e.flags&=~b;return}let s;if(e.scopeLastChild!==void 0)try{this.disposeNestedEffects(e)}catch(u){s=[u]}const n=typeof e.cachedValue=="function"?e.cachedValue:void 0;if(e.cachedValue=void 0,e.flags&=~y,n!==void 0)try{this.untracked(n)}catch(u){s??=[],s.push(u)}if(s!==void 0){try{this.disposeEffect(e)}catch(u){s.push(u)}D.throwScopeErrors(s,"Effect cleanup failed.")}if(e.evaluate===void 0)return;e.tailDep=null,e.flags=e.flags&~y|p;const r=this.activeSub;this.activeSub=e;let a;try{a=i()}catch(u){this.activeSub=r,e.flags&=~p,this.failEffectRun(e,u,s)}finally{this.activeSub=r,e.flags&=~p}const l=e.tailDep;if((l===null?e.firstDep:l.nextDep)!==null&&this.pruneUnreadDependencies(e),typeof a=="function")if(e.evaluate===void 0)try{this.untracked(a)}catch(u){s??=[],s.push(u)}else e.cachedValue=a;e.flags&v?e.flags=e.flags&-7|g:e.flags&=-8}failEffectRun(e,t,i){const s=i??[];s.push(t),this.pruneUnreadDependencies(e);try{this.disposeNestedEffects(e)}catch(n){s.push(n)}throw e.flags&=-72,s.length===1?s[0]:new AggregateError(s,"Effect execution failed.")}flushSyncEffects(){if(!(this.flushingEffects||this.activeSub!==null&&(this.activeSub.flags&(d|p))===(d|p))){this.flushingEffects=!0;try{for(;this.effectReadIndex!==this.effectWriteIndex;){const e=this.effectReadIndex,t=this.effectQueue[e];this.effectQueue[e]=void 0,++this.effectReadIndex,t.flags&=~v,this.executeEffect(t)}}catch(e){this.drainQueueAfterError(e,!1)}finally{this.effectReadIndex=0,this.effectWriteIndex=0,this.flushingEffects=!1}}}flushExternalEffects(){if(!(this.flushingEffects||this.activeSub!==null&&(this.activeSub.flags&(d|p))===(d|p))){this.flushingEffects=!0;try{for(;this.effectReadIndex!==this.effectWriteIndex;){const e=this.effectReadIndex,t=this.effectQueue[e];this.effectQueue[e]=void 0,++this.effectReadIndex;const i=t.effectTask;i===void 0?(t.flags&=~v,this.executeEffect(t)):t.evaluate!==void 0?this.scheduleEffectTask(t,i):t.flags&=~v}}catch(e){this.drainQueueAfterError(e,!0)}finally{this.effectReadIndex=0,this.effectWriteIndex=0,this.flushingEffects=!1}}}markRecoveryDependencies(e){const t=[e],i=new Set;for(;t.length!==0;){const s=t.pop();if(!i.has(s)){i.add(s);for(let n=s.firstDep;n!==null;n=n.nextDep){const r=n.dep;r.evaluate!==void 0&&!(r.flags&d)&&(r.flags|=R,t.push(r))}}}}drainQueueAfterError(e,t){const i=[e];for(;this.effectReadIndex!==this.effectWriteIndex;){const s=this.effectReadIndex++,n=this.effectQueue[s];this.effectQueue[s]=void 0;try{const r=t?n.effectTask:void 0;r!==void 0&&n.evaluate!==void 0?this.scheduleEffectTask(n,r):(n.flags&=~v,this.executeEffect(n))}catch(r){i.push(r)}}throw i.length===1?e:new AggregateError(i,"Effect queue processing failed.")}requestEffectTask(e){const t=e.effectTask;t===void 0||e.evaluate===void 0||(e.flags|=v,this.scheduleEffectTask(e,t))}scheduleEffectTask(e,t){try{t.schedule()}catch(i){throw e.flags&=-72,i}}disposeEffect(e){if(e.evaluate===void 0)return;this.activeSub===e&&(this.activeSub=null);const t=e.effectTask,i=e.onStop,s=typeof e.cachedValue=="function"?e.cachedValue:void 0;e.evaluate=void 0,e.flags=0,e.cachedValue=void 0,e.effectTask=void 0,i!==void 0&&(e.onStop=void 0),D.detachScopeChild(e);let n;e.tailDep=null;try{this.pruneUnreadDependencies(e)}catch(r){n=[r]}if(e.firstDep=e.tailDep=null,e.depCount=0,L(e),t!==void 0)try{t.dispose()}catch(r){n??=[],n.push(r)}try{this.disposeNestedEffects(e)}catch(r){n??=[],n.push(r)}if(s!==void 0)try{this.untracked(s)}catch(r){n??=[],n.push(r)}if(i!==void 0)try{this.untracked(i)}catch(r){n??=[],n.push(r)}this.invalidationStack.length!==this.invalidationDepth&&(this.invalidationStack.length=this.invalidationDepth),this.dependencyStack.length!==this.dependencyDepth&&(this.dependencyStack.length=this.dependencyDepth),n!==void 0&&D.throwScopeErrors(n,"Effect disposal failed.")}disposeNestedEffects(e){let t;for(;e.scopeLastChild!==void 0;)try{this.disposeEffect(e.scopeLastChild)}catch(i){t??=[],t.push(i)}t!==void 0&&D.throwScopeErrors(t,"Nested effect disposal failed.")}static materializeComputed(e){e.flags=T|(e.sourceHooks===void 0?0:o),e.firstSub=null,e.lastSub=null,e.firstDep=null,e.tailDep=null,e.depCount=0,e.cachedValue=void 0}createHandleReaders(){const e=this;function t(){return e.readComputedValue(this)}return{initializeComputed(){const i=this;return _.materializeComputed(i),this.get=t,e.readComputedValue(i)},initializeRaw(){const i=this;_.materializeComputed(i);const s=()=>e.readComputedValue(i);return this.read=s,s()},peek(){return e.peekHandle(this)}}}peekHandle(e){const t=this.activeSub;if(t===null)return e.get();this.activeSub=null;try{return e.get()}finally{this.activeSub=t}}_signalAccess(e){const t=this;let i=e,s;function n(r){if(arguments.length!==0){const u=s;u!==void 0?t.writeSignalValue(u,r):i!==r&&(i=r);return}const a=s;if(a!==void 0)return t.readSignalValue(a);const l=t.activeSub;return l===null||(s=t.materializeSignal(i,l)),i}return{read:n,write:n}}_computedAccess(e){return{evaluate:e,read:this.handleReaders.initializeRaw}}_ownedSignal(e,t){const i=this;let s=e,n,r=!1;const a=()=>{const h=n;if(h!==void 0)return this.readSignalValue(h);const S=this.activeSub;if(S===null)return s;const V=s;return n=this.materializeSignal(V,S,t),s=void 0,V},l=t===void 0?h=>{const S=n;S!==void 0?this.writeSignalValue(S,h):s!==h&&(s=h)}:h=>{const S=n;if(S!==void 0){const V=S.flags&f?S.pendingValue:S.cachedValue;V!==h&&t.onChange?.(V,h,S.firstSub!==null),this.writeSignalValue(S,h);return}s!==h&&(t.onChange?.(s,h,!1),s=h)},I={source:{get:a,peek:this.handleReaders.peek,set:l},dispose(){if(r)return!0;r=!0,s=void 0;let h;try{t?.onDispose?.(n?.firstSub!=null)}catch(S){(h??=[]).push(S)}if(n!==void 0){try{i.releaseSourceSubs(n)}catch(S){(h??=[]).push(S)}n.cachedValue=void 0,n.pendingValue=void 0,n.pendingAuthor=void 0,n.flags=0}if(n=void 0,h?.length===1)throw h[0];if(h!==void 0&&h.length>1)throw new AggregateError(h,"Owned signal disposal failed.");return!0}};return t!==void 0&&(I.hasSubscribers=()=>n?.firstSub!=null),I}_ownedComputed(e,t){const i=this,s=this.createComputedHandle(e,t);let n=!1;const r={source:s,dispose(){if(n)return!0;n=!0,i.activeSub===s&&(i.activeSub=null);const a=[];try{t?.onDispose?.(s.firstSub!=null)}catch(u){a.push(u)}if(s.flags!==void 0)try{i.releaseSourceSubs(s)}catch(u){a.push(u)}const l=s.flags!==void 0;if(s.evaluate=void 0,s.cachedValue=void 0,s.flags=0,s.tailDep=null,l)try{i.pruneUnreadDependencies(s)}catch(u){a.push(u)}if(s.firstDep=s.tailDep=null,s.depCount=0,L(s),a.length===1)throw a[0];if(a.length>1)throw new AggregateError(a,"Owned computed disposal failed.");return!0}};return t!==void 0&&(r.hasSubscribers=()=>s.firstSub!=null),r}_startBatch(){++this.batchDepth}_endBatch(){!--this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects()}_isTracking(){return this.activeSub!==null}_isFlushingEffects(){return this.flushingEffects}_allocateTaskEffect(e,t){const i=this.allocateGraphRecord(void 0,e,f|g|d),s=this.activeSub;return s!==null&&s.flags&d&&D.appendScopeChild(s,i),i.effectTask=t,i}_requestTaskEffect(e,t){t?this.requestEffectTask(e):e.effectTask!==void 0&&e.evaluate!==void 0&&(e.flags|=v),!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects()}_beginTaskEffectRun(e){return!(e.flags&v)||e.evaluate===void 0?!1:(e.flags&=~v,!0)}_finishTaskEffectRun(e){const t=this.activeSub;this.activeSub=null;try{try{this.executeEffect(e)}catch(i){if(!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex)try{this.flushEffects()}catch(s){throw new AggregateError([i,s],"Effect execution and queue processing failed.")}throw i}!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects()}finally{this.activeSub=t}}_cancelTaskEffect(e){return e.evaluate===void 0?!1:(this.settleCancelledDependencies(e),e.flags&=-72,!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects(),!0)}_rearmTaskEffect(e){const t=e.effectTask;t===void 0||e.evaluate===void 0||(e.flags|=f|v,t.schedule())}_disposeTaskEffect(e){this.disposeEffect(e)}_trackSignalNode(e,t){const i=this.activeSub;if(i!==null)return this.materializeSignal(e,i,t)}_readSignalNode(e){return this.readSignalValue(e)}_peekSignalNode(e){const t=this.activeSub;if(t===null)return this.readSignalValue(e);this.activeSub=null;try{return this.readSignalValue(e)}finally{this.activeSub=t}}_visibleSignalValue(e){return e.flags&f?e.pendingValue:e.cachedValue}_writeSignalNode(e,t){this.writeSignalValue(e,t)}_signalNodeHasSubscribers(e){return e.firstSub!==null}_releaseSignalNode(e){try{this.releaseSourceSubs(e)}finally{e.cachedValue=void 0,e.pendingValue!==void 0&&(e.pendingValue=void 0),e.pendingAuthor!=null&&(e.pendingAuthor=void 0),e.flags=0}}_findSubscriberOwner(e,t,i){for(let s=e.firstSub;s!==null;s=s.nextSub){const n=s.sub,r=n.sourceHooks?.dependencyOwner??n.effectTask?.dependencyOwner;if(r!==void 0&&t(r,i))return r}}_activeSubscriberOwner(){const e=this.activeSub;if(e!==null)return e.sourceHooks?.dependencyOwner??e.effectTask?.dependencyOwner}_bumpSignalNode(e){return e.firstSub===null?!1:(this.writeSignalValue(e,(e.flags&f?e.pendingValue:e.cachedValue)+1),!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects(),!0)}_trackCounterNode(e){const t=this.activeSub;if(t===null)return;const i={flags:o,firstSub:null,lastSub:null,evaluate:void 0,cachedValue:0,sourceHooks:e};return t.flags&w?this.appendInitialDependency(i,t):this.trackDependency(i,t),i}_activeEffectTask(){const e=this.activeSub;return e===null?void 0:e.effectTask}}let z;function E(){return z??=new _}const F=c=>E().signal(c),Q=c=>E().reactive(c);function P(c){return E().computed(c)}const B=(c,e)=>E().effect(c,e),G=(c,e,t)=>E().watch(c,e,t),M=c=>E().batch(c),K=c=>E().untracked(c),Y=()=>E().scope();exports.ScopeNode=D.ScopeNode;exports.RaphReactivity=_;exports.batch=M;exports.computed=P;exports.effect=B;exports.reactive=Q;exports.scope=Y;exports.signal=F;exports.untracked=K;exports.watch=G;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./engine-core.cjs"),o=require("./reactive-object.cjs"),n=require("./scope.cjs");class i extends a.ReactivityEngine{constructor(c={}){super(c),this.reactive=this.reactive.bind(this)}reactive(c){return o.reactiveObject(this,c,()=>this._createReactivePropertySourceBridge())}}let s;function t(){return s??=new i}const u=e=>t().signal(e),d=e=>t().reactive(e);function v(e){return t().computed(e)}const p=(e,c)=>t().effect(e,c),f=(e,c,r)=>t().watch(e,c,r),h=e=>t().batch(e),g=e=>t().untracked(e),y=()=>t().scope();exports.ScopeNode=n.ScopeNode;exports.RaphReactivity=i;exports.batch=h;exports.computed=v;exports.effect=p;exports.reactive=d;exports.scope=y;exports.signal=u;exports.untracked=g;exports.watch=f;
|