@raphy-js/raph 1.0.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/LICENSE +202 -0
  2. package/ReadMe.md +153 -0
  3. package/dist/api/Raph.d.ts +228 -0
  4. package/dist/api/errors.d.ts +20 -0
  5. package/dist/api/public.d.ts +22 -0
  6. package/dist/api/types.d.ts +25 -0
  7. package/dist/debug/api/Raph.cjs +1 -0
  8. package/dist/debug/api/Raph.js +419 -0
  9. package/dist/debug/api/errors.cjs +1 -0
  10. package/dist/debug/api/errors.js +14 -0
  11. package/dist/debug/api/public.cjs +1 -0
  12. package/dist/debug/api/public.js +40 -0
  13. package/dist/debug/api/types.cjs +1 -0
  14. package/dist/debug/api/types.js +1 -0
  15. package/dist/debug/path/AdapterPathStore.cjs +1 -0
  16. package/dist/debug/path/AdapterPathStore.js +133 -0
  17. package/dist/debug/path/DerivedRegistry.cjs +1 -0
  18. package/dist/debug/path/DerivedRegistry.js +157 -0
  19. package/dist/debug/path/MetaController.cjs +1 -0
  20. package/dist/debug/path/MetaController.js +214 -0
  21. package/dist/debug/path/PathEventHub.cjs +1 -0
  22. package/dist/debug/path/PathEventHub.js +148 -0
  23. package/dist/debug/path/PathStore.cjs +1 -0
  24. package/dist/debug/path/PathStore.js +326 -0
  25. package/dist/debug/path/RaphDerivedHandle.cjs +1 -0
  26. package/dist/debug/path/RaphDerivedHandle.js +125 -0
  27. package/dist/debug/path/RaphKernel.cjs +1 -0
  28. package/dist/debug/path/RaphKernel.js +636 -0
  29. package/dist/debug/path/RaphMeta.cjs +1 -0
  30. package/dist/debug/path/RaphMeta.js +68 -0
  31. package/dist/debug/path/RaphMetaStore.cjs +1 -0
  32. package/dist/debug/path/RaphMetaStore.js +184 -0
  33. package/dist/debug/path/data-adapter.cjs +1 -0
  34. package/dist/debug/path/data-adapter.js +356 -0
  35. package/dist/debug/path/data-draft.cjs +1 -0
  36. package/dist/debug/path/data-draft.js +71 -0
  37. package/dist/debug/path/data-path.cjs +1 -0
  38. package/dist/debug/path/data-path.js +423 -0
  39. package/dist/debug/path/derived-collection.cjs +1 -0
  40. package/dist/debug/path/derived-collection.js +179 -0
  41. package/dist/debug/path/derived-strategies.cjs +1 -0
  42. package/dist/debug/path/derived-strategies.js +20 -0
  43. package/dist/debug/path/meta.types.cjs +1 -0
  44. package/dist/debug/path/meta.types.js +1 -0
  45. package/dist/debug/path/path-router.cjs +1 -0
  46. package/dist/debug/path/path-router.js +86 -0
  47. package/dist/debug/path/path.types.cjs +1 -0
  48. package/dist/debug/path/path.types.js +1 -0
  49. package/dist/debug/path/public.cjs +1 -0
  50. package/dist/debug/path/public.js +18 -0
  51. package/dist/debug/path/segment-key.cjs +1 -0
  52. package/dist/debug/path/segment-key.js +12 -0
  53. package/dist/debug/reactivity/engine.cjs +1 -0
  54. package/dist/debug/reactivity/engine.js +1133 -0
  55. package/dist/debug/reactivity/scope.cjs +1 -0
  56. package/dist/debug/reactivity/scope.js +274 -0
  57. package/dist/debug/reactivity/types.cjs +1 -0
  58. package/dist/debug/reactivity/types.js +1 -0
  59. package/dist/debug/reactivity/watch.cjs +1 -0
  60. package/dist/debug/reactivity/watch.js +64 -0
  61. package/dist/debug/runtime/PathHandle.cjs +1 -0
  62. package/dist/debug/runtime/PathHandle.js +139 -0
  63. package/dist/debug/runtime/RaphDebug.cjs +1 -0
  64. package/dist/debug/runtime/RaphDebug.js +15 -0
  65. package/dist/debug/runtime/RaphFrameLoop.cjs +1 -0
  66. package/dist/debug/runtime/RaphFrameLoop.js +106 -0
  67. package/dist/debug/runtime/RaphNode.cjs +1 -0
  68. package/dist/debug/runtime/RaphNode.js +143 -0
  69. package/dist/debug/runtime/RaphPhasePipeline.cjs +1 -0
  70. package/dist/debug/runtime/RaphPhasePipeline.js +526 -0
  71. package/dist/debug/runtime/RaphRuntime.cjs +1 -0
  72. package/dist/debug/runtime/RaphRuntime.js +700 -0
  73. package/dist/debug/runtime/RaphScope.cjs +1 -0
  74. package/dist/debug/runtime/RaphScope.js +64 -0
  75. package/dist/debug/runtime/RuntimeReactivity.cjs +1 -0
  76. package/dist/debug/runtime/RuntimeReactivity.js +154 -0
  77. package/dist/debug/runtime/RuntimeWatch.cjs +1 -0
  78. package/dist/debug/runtime/RuntimeWatch.js +71 -0
  79. package/dist/debug/runtime/disposal.cjs +1 -0
  80. package/dist/debug/runtime/disposal.js +9 -0
  81. package/dist/debug/runtime/errors.cjs +1 -0
  82. package/dist/debug/runtime/errors.js +12 -0
  83. package/dist/debug/runtime/parent-graph.cjs +1 -0
  84. package/dist/debug/runtime/parent-graph.js +10 -0
  85. package/dist/debug/runtime/phase.types.cjs +1 -0
  86. package/dist/debug/runtime/phase.types.js +8 -0
  87. package/dist/debug/runtime/public.cjs +1 -0
  88. package/dist/debug/runtime/public.js +18 -0
  89. package/dist/debug/runtime/runtime-reactivity.types.cjs +1 -0
  90. package/dist/debug/runtime/runtime-reactivity.types.js +1 -0
  91. package/dist/index.cjs +1 -0
  92. package/dist/index.js +40 -0
  93. package/dist/path/AdapterPathStore.d.ts +45 -0
  94. package/dist/path/DerivedRegistry.d.ts +67 -0
  95. package/dist/path/MetaController.d.ts +85 -0
  96. package/dist/path/PathEventHub.d.ts +48 -0
  97. package/dist/path/PathStore.d.ts +51 -0
  98. package/dist/path/RaphDerivedHandle.d.ts +97 -0
  99. package/dist/path/RaphKernel.d.ts +166 -0
  100. package/dist/path/RaphMeta.d.ts +45 -0
  101. package/dist/path/RaphMetaStore.d.ts +45 -0
  102. package/dist/path/data-adapter.d.ts +78 -0
  103. package/dist/path/data-draft.d.ts +4 -0
  104. package/dist/path/data-path.d.ts +97 -0
  105. package/dist/path/derived-collection.d.ts +30 -0
  106. package/dist/path/derived-strategies.d.ts +15 -0
  107. package/dist/path/meta.types.d.ts +33 -0
  108. package/dist/path/path-router.d.ts +21 -0
  109. package/dist/path/path.types.d.ts +26 -0
  110. package/dist/path/public.d.ts +14 -0
  111. package/dist/path/segment-key.d.ts +2 -0
  112. package/dist/path.cjs +1 -0
  113. package/dist/path.js +18 -0
  114. package/dist/raph.cjs +1 -0
  115. package/dist/raph.js +40 -0
  116. package/dist/reactivity/engine.d.ts +379 -0
  117. package/dist/reactivity/scope.d.ts +146 -0
  118. package/dist/reactivity/types.d.ts +150 -0
  119. package/dist/reactivity/watch.d.ts +15 -0
  120. package/dist/reactivity.cjs +1 -0
  121. package/dist/reactivity.js +14 -0
  122. package/dist/runtime/PathHandle.d.ts +72 -0
  123. package/dist/runtime/RaphDebug.d.ts +32 -0
  124. package/dist/runtime/RaphFrameLoop.d.ts +51 -0
  125. package/dist/runtime/RaphNode.d.ts +68 -0
  126. package/dist/runtime/RaphPhasePipeline.d.ts +133 -0
  127. package/dist/runtime/RaphRuntime.d.ts +285 -0
  128. package/dist/runtime/RaphScope.d.ts +50 -0
  129. package/dist/runtime/RuntimeReactivity.d.ts +40 -0
  130. package/dist/runtime/RuntimeWatch.d.ts +28 -0
  131. package/dist/runtime/disposal.d.ts +1 -0
  132. package/dist/runtime/errors.d.ts +16 -0
  133. package/dist/runtime/parent-graph.d.ts +5 -0
  134. package/dist/runtime/phase.types.d.ts +49 -0
  135. package/dist/runtime/public.d.ts +13 -0
  136. package/dist/runtime/runtime-reactivity.types.d.ts +9 -0
  137. package/dist/runtime.cjs +1 -0
  138. package/dist/runtime.js +18 -0
  139. package/package.json +109 -0
@@ -0,0 +1,86 @@
1
+ var h = Object.defineProperty;
2
+ var u = (n, t, i) => t in n ? h(n, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : n[t] = i;
3
+ var p = (n, t, i) => u(n, typeof t != "symbol" ? t + "" : t, i);
4
+ import { pathSegmentKey as x } from "./segment-key.js";
5
+ class m {
6
+ constructor() {
7
+ // Корень trie разделяет exact и indexed-wildcard transitions.
8
+ p(this, "_root", {});
9
+ }
10
+ /**
11
+ * Регистрирует route mask и возвращает функцию удаления.
12
+ */
13
+ add(t, i) {
14
+ let e = this._root;
15
+ const o = [];
16
+ for (const c of t.segments)
17
+ if (c.kind === "wildcard") {
18
+ const d = e.indexedWildcard ?? (e.indexedWildcard = {});
19
+ o.push({ child: d, parent: e, indexedWildcard: !0 }), e = d;
20
+ } else {
21
+ const d = x(c), a = e.exact ?? (e.exact = /* @__PURE__ */ new Map());
22
+ let s = a.get(d);
23
+ s === void 0 && (s = {}, a.set(d, s)), o.push({ child: s, key: d, parent: e, indexedWildcard: !1 }), e = s;
24
+ }
25
+ const r = t.deep ? e.deep ?? (e.deep = /* @__PURE__ */ new Set()) : e.end ?? (e.end = /* @__PURE__ */ new Set());
26
+ r.add(i);
27
+ let l = !0;
28
+ return () => {
29
+ if (l) {
30
+ l = !1, r.delete(i), r.size === 0 && (t.deep ? e.deep = void 0 : e.end = void 0);
31
+ for (let c = o.length - 1; c >= 0; c--) {
32
+ const d = o[c];
33
+ if (!v(d.child))
34
+ break;
35
+ d.indexedWildcard ? d.parent.indexedWildcard = void 0 : (d.parent.exact.delete(d.key), d.parent.exact.size === 0 && (d.parent.exact = void 0));
36
+ }
37
+ }
38
+ };
39
+ }
40
+ /**
41
+ * Возвращает routes, чьи masks соответствуют указанному событию.
42
+ */
43
+ match(t) {
44
+ var o;
45
+ let i = [this._root];
46
+ const e = /* @__PURE__ */ new Set();
47
+ for (let r = 0; r <= t.length; r++) {
48
+ const l = r === t.length, c = [];
49
+ for (const d of i) {
50
+ if (f(e, d.deep), l) {
51
+ f(e, d.end);
52
+ continue;
53
+ }
54
+ const a = t[r], s = (o = d.exact) == null ? void 0 : o.get(x(a));
55
+ s !== void 0 && c.push(s), d.indexedWildcard !== void 0 && (a.kind === "index" || a.kind === "selector") && c.push(d.indexedWildcard);
56
+ }
57
+ if (l || (i = c, i.length === 0))
58
+ break;
59
+ }
60
+ return e;
61
+ }
62
+ /**
63
+ * При замене root возвращает все зарегистрированные path masks.
64
+ */
65
+ matchAll() {
66
+ const t = /* @__PURE__ */ new Set(), i = [this._root];
67
+ for (; i.length; ) {
68
+ const e = i.pop();
69
+ if (f(t, e.deep), f(t, e.end), e.indexedWildcard !== void 0 && i.push(e.indexedWildcard), e.exact !== void 0)
70
+ for (const o of e.exact.values())
71
+ i.push(o);
72
+ }
73
+ return t;
74
+ }
75
+ }
76
+ function f(n, t) {
77
+ if (t !== void 0)
78
+ for (const i of t)
79
+ n.add(i);
80
+ }
81
+ function v(n) {
82
+ return n.deep === void 0 && n.end === void 0 && n.exact === void 0 && n.indexedWildcard === void 0;
83
+ }
84
+ export {
85
+ m as PathRouter
86
+ };
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./data-adapter.cjs"),a=require("./data-path.cjs"),e=require("./derived-strategies.cjs"),r=require("./PathStore.cjs"),d=require("./RaphDerivedHandle.cjs"),h=require("./RaphKernel.cjs"),l=require("./RaphMeta.cjs");exports.DefaultDataAdapter=t.DefaultDataAdapter;exports.DataPath=a.DataPath;exports.collectionByKey=e.collectionByKey;exports.filterByKey=e.filterByKey;exports.full=e.full;exports.PathStore=r.PathStore;exports.RaphDerivedHandle=d.RaphDerivedHandle;exports.RaphKernel=h.RaphKernel;exports.RaphMeta=l.RaphMeta;
@@ -0,0 +1,18 @@
1
+ import { DefaultDataAdapter as o } from "./data-adapter.js";
2
+ import { DataPath as a } from "./data-path.js";
3
+ import { collectionByKey as f, filterByKey as l, full as m } from "./derived-strategies.js";
4
+ import { PathStore as h } from "./PathStore.js";
5
+ import { RaphDerivedHandle as D } from "./RaphDerivedHandle.js";
6
+ import { RaphKernel as i } from "./RaphKernel.js";
7
+ import { RaphMeta as K } from "./RaphMeta.js";
8
+ export {
9
+ a as DataPath,
10
+ o as DefaultDataAdapter,
11
+ h as PathStore,
12
+ D as RaphDerivedHandle,
13
+ i as RaphKernel,
14
+ K as RaphMeta,
15
+ f as collectionByKey,
16
+ l as filterByKey,
17
+ m as full
18
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function e(n){return n.kind==="key"?`k${r(n.key)}`:n.kind==="index"?`i:${n.index}`:n.kind==="selector"?`s${r(n.key)}${i(n.value)}`:`w:${n.indexed?"index":"key"}`}function r(n){return`:${n.length}:${n}`}function i(n){return n===null?":null":typeof n=="string"?`:string${r(n)}`:typeof n=="boolean"?n?":boolean:1":":boolean:0":`:number:${Object.is(n,-0)?"-0":String(n)}`}exports.pathSegmentKey=e;
@@ -0,0 +1,12 @@
1
+ function t(n) {
2
+ return n.kind === "key" ? `k${r(n.key)}` : n.kind === "index" ? `i:${n.index}` : n.kind === "selector" ? `s${r(n.key)}${i(n.value)}` : `w:${n.indexed ? "index" : "key"}`;
3
+ }
4
+ function r(n) {
5
+ return `:${n.length}:${n}`;
6
+ }
7
+ function i(n) {
8
+ return n === null ? ":null" : typeof n == "string" ? `:string${r(n)}` : typeof n == "boolean" ? n ? ":boolean:1" : ":boolean:0" : `:number:${Object.is(n, -0) ? "-0" : String(n)}`;
9
+ }
10
+ export {
11
+ t as pathSegmentKey
12
+ };
@@ -0,0 +1 @@
1
+ "use strict";var V=Object.defineProperty;var C=(a,e,t)=>e in a?V(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var p=(a,e,t)=>C(a,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./scope.cjs"),R=require("./watch.cjs"),d=1,f=2,S=4,h=8,w=16,o=32,D=64,k=128,x=256,g=d|f,I=16;function _(a,e){const t=a.firstSub;if(t===null)return;if(t===a.lastSub)return t.sub===e?t:void 0;const i=a.subSearchCursor??t;if(i.sub===e)return a.subSearchCursor=i.nextSub??t,i;let s=i.nextSub??t;for(;s!==i;){if(s.sub===e)return a.subSearchCursor=s.nextSub??t,s;s=s.nextSub??t}}class E{constructor(e={}){p(this,"activeSub",null);p(this,"batchDepth",0);p(this,"effectReadIndex",0);p(this,"effectWriteIndex",0);p(this,"invalidationDepth",0);p(this,"dependencyDepth",0);p(this,"flushingEffects",!1);p(this,"effectQueue",new Array(16).fill(void 0));p(this,"invalidationStack",new Array(512).fill(null));p(this,"dependencyStack",[]);p(this,"handleReaders",this.createHandleReaders());p(this,"effectScheduler");p(this,"flushEffects");p(this,"_effectImmediate");this.effectScheduler=e.effectScheduler,this._effectImmediate=this.effect.bind(this),this.signal=this.signal.bind(this),this.computed=this.computed.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 c=this.activeSub;return c===null||(i=this.materializeSignal(t,c)),t},n=r=>{const c=i;if(c!==void 0){this.writeSignalValue(c,r);return}t!==r&&(t=r)};return{get:s,peek:this.handleReaders.peek,set:n}}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|d|o);t!==void 0&&(i.onStop=t);const s=this.activeSub;s!==null&&s.flags&o&&b.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 R.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 b.ScopeNode(this)}allocateGraphRecord(e,t,i){return{flags:i,firstSub:null,lastSub:null,firstDep:null,tailDep:null,depCount:0,evaluate:t,cachedValue:e}}materializeSignal(e,t){const i=this.allocateGraphRecord(e,void 0,0);return t.flags&k?this.appendInitialDependency(i,t):this.trackDependency(i,t),i}createComputedHandle(e){return{evaluate:e,get:this.handleReaders.initializeComputed,peek:this.handleReaders.peek}}createScheduledEffect(e,t){const i=this.allocateGraphRecord(void 0,e,f|d|o);t!==void 0&&(i.onStop=t);const s=this.activeSub;s!==null&&s.flags&o&&b.appendScopeChild(s,i);const n=()=>{if(!(!(i.flags&D)||i.evaluate===void 0)){i.flags&=~D;try{this.executeEffect(i)}catch(r){if(!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex)try{this.flushEffects()}catch(c){throw new AggregateError([r,c],"Effect execution and queue processing failed.")}throw r}!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects()}};try{i.effectTask=this.effectScheduler.bind(n),this.requestEffectTask(i)}catch(r){try{this.disposeEffect(i)}catch(c){throw new AggregateError([r,c],"Effect registration and cleanup failed.")}throw r}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 c=this.activeSub!==null&&this.activeSub.flags&h?this.activeSub:null;s?e.pendingAuthor!==c&&(e.pendingAuthor=null):e.pendingAuthor=c}const r=e.firstSub;r!=null&&(!s||this.activeSub!==null&&this.activeSub.flags&h)&&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,i=t&(w|g|x),s=i===0?e.cachedValue:i&w?this.evaluateFirstValue(e):this.refreshComputedValue(e,t),n=this.activeSub;if(n!==null){const r=n.tailDep;n.flags&k?(r===null||r.dep!==e)&&this.appendInitialDependency(e,n):this.trackDependency(e,n)}return s}evaluateFirstValue(e){e.flags=h|k;const t=this.activeSub;this.activeSub=e;try{const i=e.evaluate();return e.cachedValue=i,e.flags=e.flags&S?f:0,i}catch(i){throw e.flags=x,t!==null&&this.trackDependency(e,t),i}finally{this.activeSub=t}}refreshComputedValue(e,t){try{if(t&(f|S|x))return this.recomputeValue(e)||(e.flags&=~g),e.cachedValue;const i=e.firstDep;return(i===null||!this.refreshDependencies(e,i)||!this.recomputeValue(e))&&(e.flags&=~g),e.cachedValue}catch(i){throw this.activeSub!==null&&this.trackDependency(e,this.activeSub),i}}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<=I){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<I;){const l=r;if(l.dep===e)return this.reorderDependency(t,l,i),t.tailDep=l,l;r=l.nextDep,++n}let c=i;for(;c!==null&&n<I;){const l=c;if(l.dep===e)return l;c=l.prevDep,++n}if(r!==null||c!==null){const l=_(e,t);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,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,n}reuseDepLink(e,t){this.detachSubLink(e);const i=t.lastSub;return e.dep=t,e.prevSub=i,e.nextSub=null,i===null?t.firstSub=e:i.nextSub=e,t.lastSub=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)for(t===null?e.firstDep=null:t.nextDep=null;i!==null;){const s=i.nextDep;this.detachSubLink(i),--e.depCount,i=s}}detachSubLink(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}releaseSourceSubs(e){let t=e.firstSub;for(;t!=null;){const i=t.nextSub,s=t.sub;this.detachDependencyLink(t),this.detachSubLink(t);const n=s.flags;(n&(g|h))===d&&(s.flags=n&~d|f,n&o&&this.enqueueEffect(s)),t=i}e.firstSub=e.lastSub=null,e.subSearchCursor=void 0}detachDependencyLink(e){const t=e.sub,i=e.prevDep,s=e.nextDep;i===null?t.firstDep=s:i.nextDep=s,s!==null&&(s.prevDep=i),t.tailDep===e&&(t.tailDep=i),--t.depCount}enqueueEffect(e){e.flags&D||(e.flags|=D,this.effectQueue[this.effectWriteIndex]=e,++this.effectWriteIndex)}propagateInvalidation(e,t=!1){const i=this.invalidationDepth;let s=i;for(let n=e;n!==null;n=n.nextSub){const r=n.sub,c=r.flags;let l=0;c&(g|h)?c&h&&(l=this.invalidateReadDependency(n,r,c)):(l=c&~S|(t?d:f),r.flags=l),l!==0&&(l&o&&!(l&h)?this.enqueueEffect(r):r.firstSub!==null&&(this.invalidationStack[s++]=r.firstSub))}for(;s!==i;){let n=this.invalidationStack[--s];for(;n!==null;){const r=n.sub,c=r.flags;let l=0;if(c&(g|h)?c&h&&(l=this.invalidateReadDependency(n,r,c)):(l=c&~S|d,r.flags=l),l!==0){if(l&o)this.enqueueEffect(r);else if(r.firstSub!==null){n.nextSub!==null&&(this.invalidationStack[s++]=n.nextSub),n=r.firstSub;continue}}n=n.nextSub}}this.invalidationDepth=i}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|S|d;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&~d|f,r&o&&this.enqueueEffect(n))}}recomputeValue(e,t=null){const i=e.evaluate;e.tailDep=null;const s=e.flags&~S|h;e.flags=s;const n=this.activeSub;this.activeSub=e;let r;try{r=i()}catch(m){throw this.restoreComputedFailure(e,t),m}finally{this.activeSub=n}const c=e.flags&S,l=s&-268,u=e.tailDep;(u===null?e.firstDep:u.nextDep)!==null&&this.pruneUnreadDependencies(e);const v=e.cachedValue;return e.cachedValue=r,e.flags=c?f:l,v===r?!1:(e.firstSub!==null&&this.confirmSubUpdates(e.firstSub,t),!0)}restoreComputedFailure(e,t){e.flags=e.flags&-144|x,this.pruneUnreadDependencies(e),t!==null&&this.restoreFailedDependency(t.sub)}refreshDependencies(e,t){const i=this.dependencyDepth;try{return this.walkDependencyChain(e,t)}catch(s){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}}walkDependencyChain(e,t){const i=this.dependencyDepth;let s=i,n=!1;e:for(;;){if(e.flags&f)n=!0;else{const r=t.dep,c=r.flags;if(c&(f|x))this.dependencyDepth=s,n=r.evaluate===void 0?this.commitSignalValue(r,t):this.recomputeValue(r,t);else if(c&d){if(r.firstDep!==null){this.dependencyStack[s++]=t,e=r,t=r.firstDep;continue e}this.dependencyDepth=s,n=this.recomputeValue(r,t)}else n=!1}if(!n&&t.nextDep!==null){t=t.nextDep;continue}if(n){for(;s!==i;){this.dependencyDepth=--s;const r=this.dependencyStack[s];if(n=this.recomputeValue(e,r),e=r.sub,!n){if(r.nextDep!==null){t=r.nextDep;continue e}break}}if(n)return this.dependencyDepth=i,!0}for(;s!==i;){this.dependencyDepth=--s;const r=this.dependencyStack[s];if(e.flags&=~d,e=r.sub,r.nextDep!==null){t=r.nextDep;continue e}}return e.flags&=~d,this.dependencyDepth=i,!1}}restoreFailedDependency(e){e.flags&=-16,e.flags&o||(e.flags|=x)}executeEffect(e){const t=e.flags;if(!(t&g))return;if(!(t&(f|S))){const u=e.firstDep;try{if(u===null||!this.refreshDependencies(e,u)){e.flags&=~g;return}}catch(v){throw e.flags&=-80,v}}const i=e.evaluate;if(i===void 0){e.flags&=~g;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&=~S,n!==void 0)try{this.untracked(n)}catch(u){s??(s=[]),s.push(u)}if(s!==void 0){try{this.disposeEffect(e)}catch(u){s.push(u)}b.throwScopeErrors(s,"Effect cleanup failed.")}if(e.evaluate===void 0)return;e.tailDep=null,e.flags=e.flags&~S|h;const r=this.activeSub;this.activeSub=e;let c;try{c=i()}catch(u){this.activeSub=r,e.flags&=~h,this.failEffectRun(e,u,s)}finally{this.activeSub=r,e.flags&=~h}const l=e.tailDep;if((l===null?e.firstDep:l.nextDep)!==null&&this.pruneUnreadDependencies(e),typeof c=="function")if(e.evaluate===void 0)try{this.untracked(c)}catch(u){s??(s=[]),s.push(u)}else e.cachedValue=c;e.flags&D?e.flags=e.flags&-7|d: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&(o|h))===(o|h))){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&=~D,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&(o|h))===(o|h))){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&=~D,t.effectTask===void 0?this.executeEffect(t):this.requestEffectTask(t)}}catch(e){this.drainQueueAfterError(e,!0)}finally{this.effectReadIndex=0,this.effectWriteIndex=0,this.flushingEffects=!1}}}drainQueueAfterError(e,t){const i=[e];for(;this.effectReadIndex!==this.effectWriteIndex;){const s=this.effectReadIndex++,n=this.effectQueue[s];this.effectQueue[s]=void 0,n.flags&=~D;try{t&&n.effectTask!==void 0?this.requestEffectTask(n):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;if(!(t===void 0||e.evaluate===void 0)){e.flags|=D;try{t.schedule()}catch(i){throw e.flags&=-72,i}}}disposeEffect(e){if(e.evaluate===void 0)return;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),b.detachScopeChild(e);let n=e.firstDep;for(;n!==null;){const c=n.nextDep;this.detachSubLink(n),n=c}e.firstDep=e.tailDep=null,e.depCount=0;let r;if(t!==void 0)try{t.dispose()}catch(c){r=[c]}try{this.disposeNestedEffects(e)}catch(c){r??(r=[]),r.push(c)}if(s!==void 0)try{this.untracked(s)}catch(c){r??(r=[]),r.push(c)}if(i!==void 0)try{this.untracked(i)}catch(c){r??(r=[]),r.push(c)}this.invalidationStack.length=this.invalidationDepth,this.dependencyStack.length=this.dependencyDepth,r!==void 0&&b.throwScopeErrors(r,"Effect disposal failed.")}disposeNestedEffects(e){let t;for(;e.scopeLastChild!==void 0;)try{this.disposeEffect(e.scopeLastChild)}catch(i){t??(t=[]),t.push(i)}t!==void 0&&b.throwScopeErrors(t,"Nested effect disposal failed.")}static materializeComputed(e){e.flags=w,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 E.materializeComputed(i),this.get=t,e.readComputedValue(i)},initializeRaw(){const i=this;E.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 c=s;if(c!==void 0)return t.readSignalValue(c);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){const t=this;let i=e,s,n=!1;const r=()=>{const u=s;if(u!==void 0)return this.readSignalValue(u);const v=this.activeSub;return v===null||(s=this.materializeSignal(i,v)),i},c=u=>{const v=s;if(v!==void 0){this.writeSignalValue(v,u);return}i!==u&&(i=u)};return{source:{get:r,peek:this.handleReaders.peek,set:c},dispose(){return n||(n=!0,i=void 0,s!==void 0&&(t.releaseSourceSubs(s),s.cachedValue=void 0,s.pendingValue=void 0,s.pendingAuthor=void 0,s.flags=0),s=void 0),!0}}}_ownedComputed(e){const t=this,i=this.createComputedHandle(e);let s=!1;return{source:i,dispose(){if(s)return!0;s=!0,i.flags!==void 0&&t.releaseSourceSubs(i);let n=i.firstDep;for(;n!=null;){const r=n.nextDep;t.detachSubLink(n),n=r}return i.firstDep=i.tailDep=null,i.depCount=0,i.evaluate=void 0,i.cachedValue=void 0,i.flags=0,!0}}}_startBatch(){++this.batchDepth}_endBatch(){!--this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects()}_isTracking(){return this.activeSub!==null}_isFlushingEffects(){return this.flushingEffects}}let A;function y(){return A??(A=new E)}const T=a=>y().signal(a);function L(a){return y().computed(a)}const N=(a,e)=>y().effect(a,e),U=(a,e,t)=>y().watch(a,e,t),W=a=>y().batch(a),q=a=>y().untracked(a),F=()=>y().scope();exports.ScopeNode=b.ScopeNode;exports.RaphReactivity=E;exports.batch=W;exports.computed=L;exports.effect=N;exports.scope=F;exports.signal=T;exports.untracked=q;exports.watch=U;