@raphy-js/raph 1.0.0-dev.2 → 1.0.1-dev.25
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-CClhT8WR.js +1044 -0
- package/dist/core-cPQWYD4K.cjs +1 -0
- package/dist/debug/api/Raph.cjs +1 -1
- package/dist/debug/api/Raph.js +368 -367
- package/dist/debug/api/RaphFacadeSession.cjs +1 -0
- package/dist/debug/api/RaphFacadeSession.js +302 -0
- package/dist/debug/api/RaphReactivityInstance.cjs +1 -0
- package/dist/debug/api/RaphReactivityInstance.js +146 -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/DataPath.js +390 -0
- package/dist/debug/path/PathRouter.cjs +1 -0
- package/dist/debug/path/PathRouter.js +80 -0
- package/dist/debug/path/RaphKernel.cjs +1 -1
- package/dist/debug/path/RaphKernel.js +316 -236
- 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/derived/DerivedRegistry.js +143 -0
- package/dist/debug/path/derived/RaphDerivedHandle.cjs +1 -0
- package/dist/debug/path/{RaphDerivedHandle.js → derived/RaphDerivedHandle.js} +19 -22
- package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
- package/dist/debug/path/{derived-collection.js → derived/derived-collection.utils.js} +71 -71
- 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/meta/MetaController.cjs +1 -0
- package/dist/debug/path/{MetaController.js → meta/MetaController.js} +58 -66
- package/dist/debug/path/meta/RaphMeta.cjs +1 -0
- package/dist/debug/path/meta/RaphMeta.js +62 -0
- package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
- package/dist/debug/path/{RaphMetaStore.js → meta/RaphMetaStore.js} +24 -30
- 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/storage/AdapterPathStore.js +128 -0
- package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
- package/dist/debug/path/{data-adapter.js → storage/DefaultDataAdapter.js} +47 -57
- package/dist/debug/path/storage/PathEventHub.cjs +1 -0
- package/dist/debug/path/storage/PathEventHub.js +161 -0
- package/dist/debug/path/storage/PathStore.cjs +1 -0
- package/dist/debug/path/{PathStore.js → storage/PathStore.js} +88 -98
- package/dist/debug/path/storage/createDataDraft.cjs +1 -0
- package/dist/debug/path/{data-draft.js → storage/createDataDraft.js} +24 -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/disposal.cjs +1 -0
- package/dist/debug/reactivity/disposal.js +32 -0
- package/dist/debug/reactivity/engine.cjs +1 -1
- package/dist/debug/reactivity/engine.js +888 -321
- package/dist/debug/reactivity/reactive-object.cjs +1 -0
- package/dist/debug/reactivity/reactive-object.js +265 -0
- package/dist/debug/reactivity/scope.cjs +1 -1
- package/dist/debug/reactivity/scope.js +221 -117
- package/dist/debug/reactivity/watch.cjs +1 -1
- package/dist/debug/reactivity/watch.js +1 -1
- package/dist/debug/runtime/RaphRuntime.cjs +1 -1
- package/dist/debug/runtime/RaphRuntime.js +1134 -502
- package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -0
- package/dist/debug/runtime/diagnostics/RaphDebug.js +287 -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 +304 -0
- package/dist/debug/runtime/ownership/RaphNode.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphNode.js +665 -0
- package/dist/debug/runtime/ownership/RaphScope.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphScope.js +236 -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/RaphFrameLoop.cjs +1 -0
- package/dist/debug/runtime/{RaphFrameLoop.js → phases/RaphFrameLoop.js} +13 -17
- package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhasePipeline.js +848 -0
- package/dist/debug/runtime/phases/RaphPhaseTaskRecord.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhaseTaskRecord.js +176 -0
- package/dist/debug/runtime/phases/RaphPhaseWatch.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhaseWatch.js +20 -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/reactivity/PathHandle.js +165 -0
- package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphMetaSource.js +108 -0
- package/dist/debug/runtime/reactivity/RaphSelector.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphSelector.js +503 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.js +1157 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.js +550 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.js +77 -0
- package/dist/debug/runtime/reactivity/disposal-sweep.utils.cjs +1 -0
- package/dist/debug/runtime/reactivity/disposal-sweep.utils.js +42 -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 +18 -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 +822 -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 +37 -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/storage/PathEventHub.d.ts +62 -0
- package/dist/path/{PathStore.d.ts → storage/PathStore.d.ts} +7 -7
- 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/disposal.d.ts +14 -0
- package/dist/reactivity/engine.d.ts +193 -6
- package/dist/reactivity/reactive-object.d.ts +36 -0
- package/dist/reactivity/scope.d.ts +108 -30
- 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 +319 -160
- package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
- package/dist/runtime/errors.d.ts +5 -0
- package/dist/runtime/ownership/RaphEffectScope.d.ts +98 -0
- package/dist/runtime/ownership/RaphNode.d.ts +310 -0
- package/dist/runtime/ownership/RaphScope.d.ts +168 -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 +253 -0
- package/dist/runtime/phases/RaphPhaseTaskRecord.d.ts +195 -0
- package/dist/runtime/phases/RaphPhaseWatch.d.ts +22 -0
- package/dist/runtime/phases/orderPhaseTasks.d.ts +6 -0
- package/dist/runtime/phases/phase.types.d.ts +171 -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/RaphSelector.d.ts +338 -0
- package/dist/runtime/reactivity/RaphWorkGraph.d.ts +309 -0
- package/dist/runtime/reactivity/RuntimeReactivity.d.ts +293 -0
- package/dist/runtime/{RuntimeWatch.d.ts → reactivity/RuntimeWatch.d.ts} +12 -6
- package/dist/runtime/reactivity/disposal-sweep.utils.d.ts +19 -0
- package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +56 -0
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +21 -16
- package/package.json +76 -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/AdapterPathStore.js +0 -133
- package/dist/debug/path/DerivedRegistry.cjs +0 -1
- package/dist/debug/path/DerivedRegistry.js +0 -157
- package/dist/debug/path/MetaController.cjs +0 -1
- package/dist/debug/path/PathEventHub.cjs +0 -1
- package/dist/debug/path/PathEventHub.js +0 -148
- package/dist/debug/path/PathStore.cjs +0 -1
- package/dist/debug/path/RaphDerivedHandle.cjs +0 -1
- package/dist/debug/path/RaphMeta.cjs +0 -1
- package/dist/debug/path/RaphMeta.js +0 -68
- package/dist/debug/path/RaphMetaStore.cjs +0 -1
- package/dist/debug/path/data-adapter.cjs +0 -1
- package/dist/debug/path/data-draft.cjs +0 -1
- package/dist/debug/path/data-path.cjs +0 -1
- package/dist/debug/path/data-path.js +0 -423
- package/dist/debug/path/derived-collection.cjs +0 -1
- package/dist/debug/path/path-router.cjs +0 -1
- package/dist/debug/path/path-router.js +0 -86
- 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/PathHandle.js +0 -139
- package/dist/debug/runtime/RaphDebug.cjs +0 -1
- package/dist/debug/runtime/RaphDebug.js +0 -15
- package/dist/debug/runtime/RaphFrameLoop.cjs +0 -1
- 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/PathEventHub.d.ts +0 -48
- 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/RuntimeReactivity.d.ts +0 -40
- package/dist/runtime/phase.types.d.ts +0 -49
- package/dist/runtime/public.d.ts +0 -13
- package/dist/runtime/runtime-reactivity.types.d.ts +0 -9
- /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/{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/{segment-key.cjs → pathSegmentKey.cjs} +0 -0
- /package/dist/debug/path/{segment-key.js → pathSegmentKey.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/{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
|
@@ -1,37 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
v(this, "_root");
|
|
11
|
-
v(this, "_eventHub", new H(
|
|
12
|
-
"[Raph] Path transaction and publication failed."
|
|
13
|
-
));
|
|
14
|
-
}
|
|
1
|
+
import { parseDataPath as a } from "../data-path.utils.js";
|
|
2
|
+
import { PathEventHub as j } from "./PathEventHub.js";
|
|
3
|
+
const d = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
class S {
|
|
5
|
+
// Владеют path data и независимым event lifecycle этого store.
|
|
6
|
+
_root;
|
|
7
|
+
_eventHub = new j(
|
|
8
|
+
"[Raph] Path batch and publication failed."
|
|
9
|
+
);
|
|
15
10
|
/**
|
|
16
|
-
* Возвращает
|
|
11
|
+
* Возвращает владельца batch boundary этого store: Kernel открывает и
|
|
12
|
+
* закрывает её без closure операции.
|
|
17
13
|
* @internal
|
|
18
14
|
*/
|
|
19
|
-
get
|
|
20
|
-
return this._eventHub
|
|
21
|
-
}
|
|
22
|
-
get _events() {
|
|
23
|
-
return this._eventHub.events;
|
|
24
|
-
}
|
|
25
|
-
get _watcherCount() {
|
|
26
|
-
return this._eventHub.watcherCount;
|
|
15
|
+
get _batchHub() {
|
|
16
|
+
return this._eventHub;
|
|
27
17
|
}
|
|
28
18
|
/**
|
|
29
19
|
* Возвращает значение по пути без создания отсутствующих данных.
|
|
30
20
|
*/
|
|
31
21
|
get(e, t) {
|
|
32
|
-
const n =
|
|
22
|
+
const n = a(e, t), o = this._root;
|
|
33
23
|
if (o !== void 0)
|
|
34
|
-
return
|
|
24
|
+
return l(o, n.segments).value;
|
|
35
25
|
}
|
|
36
26
|
/**
|
|
37
27
|
* Читает значение по пути без регистрации реактивной зависимости.
|
|
@@ -43,22 +33,22 @@ class $ {
|
|
|
43
33
|
* Проверяет наличие значения по указанному пути.
|
|
44
34
|
*/
|
|
45
35
|
has(e, t) {
|
|
46
|
-
const n =
|
|
47
|
-
return o !== void 0 &&
|
|
36
|
+
const n = a(e, t), o = this._root;
|
|
37
|
+
return o !== void 0 && l(o, n.segments).exists;
|
|
48
38
|
}
|
|
49
39
|
/**
|
|
50
40
|
* Записывает значение и публикует соответствующее изменение.
|
|
51
41
|
*/
|
|
52
42
|
set(e, t, n) {
|
|
53
|
-
const o =
|
|
43
|
+
const o = a(e, n);
|
|
54
44
|
if (o.segments.length === 0) {
|
|
55
45
|
this._setRoot(t);
|
|
56
46
|
return;
|
|
57
47
|
}
|
|
58
|
-
const s = this._eventHub.hasWatchers, i = s ?
|
|
59
|
-
if (this._root
|
|
48
|
+
const s = this._eventHub.hasWatchers, i = s ? l(this._root, o.segments).value : void 0;
|
|
49
|
+
if (this._root ??= /* @__PURE__ */ Object.create(null), w(this._root, o, t), !s)
|
|
60
50
|
return;
|
|
61
|
-
const c =
|
|
51
|
+
const c = l(this._root, o.segments).value;
|
|
62
52
|
this._eventHub.record({
|
|
63
53
|
kind: "set",
|
|
64
54
|
path: o.canonical,
|
|
@@ -70,21 +60,21 @@ class $ {
|
|
|
70
60
|
* Объединяет значение по пути и публикует соответствующее изменение.
|
|
71
61
|
*/
|
|
72
62
|
merge(e, t, n) {
|
|
73
|
-
const o =
|
|
63
|
+
const o = a(e, n);
|
|
74
64
|
if (o.segments.length === 0) {
|
|
75
65
|
this._mergeRoot(t);
|
|
76
66
|
return;
|
|
77
67
|
}
|
|
78
|
-
const s = this._eventHub.hasWatchers, i =
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
for (const
|
|
82
|
-
h(i,
|
|
68
|
+
const s = this._eventHub.hasWatchers, i = l(this._root, o.segments).value, c = s && u(i) && u(t) ? p(i) : i;
|
|
69
|
+
if (u(i) && u(t)) {
|
|
70
|
+
x(this._root, o.segments);
|
|
71
|
+
for (const v of Object.keys(t))
|
|
72
|
+
h(i, v, t[v]);
|
|
83
73
|
} else
|
|
84
|
-
this._root
|
|
74
|
+
this._root ??= /* @__PURE__ */ Object.create(null), w(this._root, o, t);
|
|
85
75
|
if (!s)
|
|
86
76
|
return;
|
|
87
|
-
const f =
|
|
77
|
+
const f = l(this._root, o.segments).value;
|
|
88
78
|
this._eventHub.record({
|
|
89
79
|
kind: "merge",
|
|
90
80
|
path: o.canonical,
|
|
@@ -96,13 +86,13 @@ class $ {
|
|
|
96
86
|
* Удаляет значение по пути и публикует изменение при наличии данных.
|
|
97
87
|
*/
|
|
98
88
|
delete(e, t) {
|
|
99
|
-
const n =
|
|
89
|
+
const n = a(e, t);
|
|
100
90
|
if (n.segments.length === 0) {
|
|
101
91
|
this._deleteRoot();
|
|
102
92
|
return;
|
|
103
93
|
}
|
|
104
|
-
const o =
|
|
105
|
-
!o.exists || this._root === void 0 || (
|
|
94
|
+
const o = l(this._root, n.segments);
|
|
95
|
+
!o.exists || this._root === void 0 || (x(this._root, n.segments), R(this._root, n), this._eventHub.hasWatchers && this._eventHub.record({
|
|
106
96
|
kind: "delete",
|
|
107
97
|
path: n.canonical,
|
|
108
98
|
previous: o.value,
|
|
@@ -110,10 +100,10 @@ class $ {
|
|
|
110
100
|
}));
|
|
111
101
|
}
|
|
112
102
|
/**
|
|
113
|
-
* Выполняет операцию в общей синхронной
|
|
103
|
+
* Выполняет операцию в общей синхронной batch boundary.
|
|
114
104
|
*/
|
|
115
|
-
|
|
116
|
-
return this._eventHub.
|
|
105
|
+
batch(e) {
|
|
106
|
+
return this._eventHub.batch(e);
|
|
117
107
|
}
|
|
118
108
|
/**
|
|
119
109
|
* Подписывает callback на подходящие изменения и возвращает disposer.
|
|
@@ -122,31 +112,31 @@ class $ {
|
|
|
122
112
|
return this._eventHub.watch(e, t);
|
|
123
113
|
}
|
|
124
114
|
_setRoot(e) {
|
|
125
|
-
const t =
|
|
115
|
+
const t = g(e), n = this._root;
|
|
126
116
|
this._root = t, this._recordRootEvent("set", n, t);
|
|
127
117
|
}
|
|
128
118
|
_mergeRoot(e) {
|
|
129
|
-
const t = this._root, n = this._eventHub.hasWatchers &&
|
|
130
|
-
if (
|
|
119
|
+
const t = this._root, n = this._eventHub.hasWatchers && u(t) && u(e) ? p(t) : t;
|
|
120
|
+
if (u(t) && u(e))
|
|
131
121
|
for (const o of Object.keys(e))
|
|
132
122
|
h(t, o, e[o]);
|
|
133
123
|
else
|
|
134
|
-
this._root =
|
|
124
|
+
this._root = g(e);
|
|
135
125
|
this._recordRootEvent("merge", n, this._root);
|
|
136
126
|
}
|
|
137
127
|
_deleteRoot() {
|
|
138
128
|
const e = this._root;
|
|
139
|
-
e !== void 0 && (this._root =
|
|
129
|
+
e !== void 0 && (this._root = E(), this._recordRootEvent("delete", e, void 0));
|
|
140
130
|
}
|
|
141
131
|
_recordRootEvent(e, t, n) {
|
|
142
132
|
this._eventHub.record({ kind: e, path: "", previous: t, value: n });
|
|
143
133
|
}
|
|
144
134
|
}
|
|
145
|
-
function
|
|
135
|
+
function l(r, e) {
|
|
146
136
|
let t = r;
|
|
147
137
|
for (const n of e)
|
|
148
138
|
if (n.kind === "key") {
|
|
149
|
-
if (!
|
|
139
|
+
if (!_(t) || !Object.hasOwn(t, n.key))
|
|
150
140
|
return { exists: !1, value: void 0 };
|
|
151
141
|
t = t[n.key];
|
|
152
142
|
} else if (n.kind === "index") {
|
|
@@ -156,39 +146,39 @@ function a(r, e) {
|
|
|
156
146
|
} else {
|
|
157
147
|
if (!Array.isArray(t))
|
|
158
148
|
return { exists: !1, value: void 0 };
|
|
159
|
-
const o =
|
|
149
|
+
const o = b(t, n.key, n.value);
|
|
160
150
|
if (o === -1)
|
|
161
151
|
return { exists: !1, value: void 0 };
|
|
162
152
|
t = t[o];
|
|
163
153
|
}
|
|
164
154
|
return { exists: !0, value: t };
|
|
165
155
|
}
|
|
166
|
-
function
|
|
156
|
+
function x(r, e) {
|
|
167
157
|
let t = r;
|
|
168
158
|
for (const n of e) {
|
|
169
|
-
if (!
|
|
159
|
+
if (!_(t))
|
|
170
160
|
return;
|
|
171
|
-
const o =
|
|
172
|
-
Array.isArray(t) &&
|
|
161
|
+
const o = A(t, n);
|
|
162
|
+
Array.isArray(t) && d.delete(t), t = o;
|
|
173
163
|
}
|
|
174
164
|
}
|
|
175
|
-
function
|
|
165
|
+
function w(r, e, t) {
|
|
176
166
|
let n = r, o;
|
|
177
167
|
for (let i = 0; i < e.segments.length - 1; i++) {
|
|
178
168
|
const c = e.segments[i], f = e.segments[i + 1];
|
|
179
|
-
c.kind === "selector" && Array.isArray(n) && (o = n), c.kind === "index" && Array.isArray(n) && (o = n), n =
|
|
169
|
+
c.kind === "selector" && Array.isArray(n) && (o = n), c.kind === "index" && Array.isArray(n) && (o = n), n = m(n, c, f, e.canonical);
|
|
180
170
|
}
|
|
181
171
|
const s = e.segments[e.segments.length - 1];
|
|
182
|
-
if (
|
|
183
|
-
const i =
|
|
184
|
-
i
|
|
172
|
+
if (H(n, s, t, e.canonical), s.kind === "key" && o !== void 0) {
|
|
173
|
+
const i = d.get(o);
|
|
174
|
+
i?.delete(s.key), i?.size === 0 && d.delete(o);
|
|
185
175
|
}
|
|
186
176
|
}
|
|
187
|
-
function
|
|
177
|
+
function R(r, e) {
|
|
188
178
|
let t = r;
|
|
189
179
|
for (let s = 0; s < e.segments.length - 1; s++) {
|
|
190
|
-
const i = e.segments[s], c =
|
|
191
|
-
if (!
|
|
180
|
+
const i = e.segments[s], c = A(t, i);
|
|
181
|
+
if (!_(c))
|
|
192
182
|
return;
|
|
193
183
|
t = c;
|
|
194
184
|
}
|
|
@@ -200,45 +190,45 @@ function E(r, e) {
|
|
|
200
190
|
if (!Array.isArray(t))
|
|
201
191
|
return;
|
|
202
192
|
if (n.kind === "index") {
|
|
203
|
-
|
|
193
|
+
d.delete(t), delete t[n.index];
|
|
204
194
|
return;
|
|
205
195
|
}
|
|
206
|
-
const o =
|
|
207
|
-
o !== -1 && (
|
|
196
|
+
const o = b(t, n.key, n.value);
|
|
197
|
+
o !== -1 && (d.delete(t), delete t[o]);
|
|
208
198
|
}
|
|
209
|
-
function
|
|
199
|
+
function A(r, e) {
|
|
210
200
|
if (e.kind === "key")
|
|
211
201
|
return Object.hasOwn(r, e.key) ? r[e.key] : void 0;
|
|
212
202
|
if (!Array.isArray(r))
|
|
213
203
|
return;
|
|
214
204
|
if (e.kind === "index")
|
|
215
205
|
return r[e.index];
|
|
216
|
-
const t =
|
|
206
|
+
const t = b(r, e.key, e.value);
|
|
217
207
|
return t === -1 ? void 0 : r[t];
|
|
218
208
|
}
|
|
219
|
-
function
|
|
209
|
+
function m(r, e, t, n) {
|
|
220
210
|
if (e.kind === "key") {
|
|
221
211
|
const s = r;
|
|
222
212
|
let i = s[e.key];
|
|
223
|
-
return (!Object.hasOwn(s, e.key) || i === void 0) && (i =
|
|
213
|
+
return (!Object.hasOwn(s, e.key) || i === void 0) && (i = O(t), h(s, e.key, i)), k(i, n);
|
|
224
214
|
}
|
|
225
215
|
if (e.kind === "index") {
|
|
226
216
|
if (!Array.isArray(r))
|
|
227
217
|
throw y(n);
|
|
228
218
|
let s = r[e.index];
|
|
229
|
-
return (!Object.hasOwn(r, e.index) || s === void 0) && (
|
|
219
|
+
return (!Object.hasOwn(r, e.index) || s === void 0) && (d.delete(r), s = O(t), r[e.index] = s), k(s, n);
|
|
230
220
|
}
|
|
231
221
|
if (!Array.isArray(r))
|
|
232
222
|
throw y(n);
|
|
233
|
-
let o =
|
|
223
|
+
let o = b(r, e.key, e.value);
|
|
234
224
|
if (o === -1) {
|
|
235
|
-
|
|
225
|
+
d.delete(r);
|
|
236
226
|
const s = /* @__PURE__ */ Object.create(null);
|
|
237
227
|
s[e.key] = e.value, r.push(s), o = r.length - 1;
|
|
238
228
|
}
|
|
239
|
-
return
|
|
229
|
+
return k(r[o], n);
|
|
240
230
|
}
|
|
241
|
-
function
|
|
231
|
+
function H(r, e, t, n) {
|
|
242
232
|
if (e.kind === "key") {
|
|
243
233
|
h(r, e.key, t);
|
|
244
234
|
return;
|
|
@@ -246,53 +236,53 @@ function C(r, e, t, n) {
|
|
|
246
236
|
if (e.kind === "index") {
|
|
247
237
|
if (!Array.isArray(r))
|
|
248
238
|
throw y(n);
|
|
249
|
-
|
|
239
|
+
d.delete(r), r[e.index] = t;
|
|
250
240
|
return;
|
|
251
241
|
}
|
|
252
242
|
if (!Array.isArray(r))
|
|
253
243
|
throw y(n);
|
|
254
|
-
const o =
|
|
244
|
+
const o = b(r, e.key, e.value);
|
|
255
245
|
if (o !== -1) {
|
|
256
|
-
|
|
246
|
+
d.delete(r), r[o] = t;
|
|
257
247
|
return;
|
|
258
248
|
}
|
|
259
|
-
if (!
|
|
249
|
+
if (!u(t))
|
|
260
250
|
throw new TypeError(`[Raph] New selector target at "${n}" must be an object.`);
|
|
261
251
|
const s = t[e.key];
|
|
262
252
|
if (Object.hasOwn(t, e.key) && !Object.is(s, e.value))
|
|
263
253
|
throw new TypeError(`[Raph] Selector target at "${n}" has a conflicting key.`);
|
|
264
|
-
|
|
254
|
+
d.delete(r), r.push(Object.hasOwn(t, e.key) ? t : { ...t, [e.key]: e.value });
|
|
265
255
|
}
|
|
266
|
-
function
|
|
256
|
+
function O(r) {
|
|
267
257
|
return r.kind === "index" || r.kind === "selector" ? [] : /* @__PURE__ */ Object.create(null);
|
|
268
258
|
}
|
|
269
|
-
function
|
|
259
|
+
function E() {
|
|
270
260
|
return /* @__PURE__ */ Object.create(null);
|
|
271
261
|
}
|
|
272
|
-
function
|
|
273
|
-
if (
|
|
262
|
+
function g(r) {
|
|
263
|
+
if (_(r))
|
|
274
264
|
return r;
|
|
275
265
|
throw new TypeError("[Raph] Root value must be an object or array.");
|
|
276
266
|
}
|
|
277
|
-
function
|
|
278
|
-
if (
|
|
267
|
+
function k(r, e) {
|
|
268
|
+
if (_(r))
|
|
279
269
|
return r;
|
|
280
270
|
throw y(e);
|
|
281
271
|
}
|
|
282
|
-
function
|
|
283
|
-
let n =
|
|
284
|
-
const o = n
|
|
272
|
+
function b(r, e, t) {
|
|
273
|
+
let n = d.get(r);
|
|
274
|
+
const o = n?.get(e);
|
|
285
275
|
if (o)
|
|
286
276
|
return o.get(t) ?? -1;
|
|
287
277
|
const s = /* @__PURE__ */ new Map();
|
|
288
278
|
for (let i = 0; i < r.length; i++) {
|
|
289
279
|
const c = r[i];
|
|
290
|
-
if (
|
|
280
|
+
if (u(c) && Object.hasOwn(c, e)) {
|
|
291
281
|
const f = c[e];
|
|
292
282
|
(f === null || typeof f == "string" || typeof f == "number" || typeof f == "boolean") && !s.has(f) && s.set(f, i);
|
|
293
283
|
}
|
|
294
284
|
}
|
|
295
|
-
return n || (n = /* @__PURE__ */ new Map(),
|
|
285
|
+
return n || (n = /* @__PURE__ */ new Map(), d.set(r, n)), n.set(e, s), s.get(t) ?? -1;
|
|
296
286
|
}
|
|
297
287
|
function h(r, e, t) {
|
|
298
288
|
if (e === "__proto__") {
|
|
@@ -306,21 +296,21 @@ function h(r, e, t) {
|
|
|
306
296
|
}
|
|
307
297
|
r[e] = t;
|
|
308
298
|
}
|
|
309
|
-
function
|
|
299
|
+
function p(r) {
|
|
310
300
|
const e = Object.create(Object.getPrototypeOf(r));
|
|
311
301
|
for (const t of Object.keys(r))
|
|
312
302
|
h(e, t, r[t]);
|
|
313
303
|
return e;
|
|
314
304
|
}
|
|
315
|
-
function
|
|
305
|
+
function u(r) {
|
|
316
306
|
return typeof r == "object" && r !== null && !Array.isArray(r);
|
|
317
307
|
}
|
|
318
|
-
function
|
|
319
|
-
return Array.isArray(r) ||
|
|
308
|
+
function _(r) {
|
|
309
|
+
return Array.isArray(r) || u(r);
|
|
320
310
|
}
|
|
321
311
|
function y(r) {
|
|
322
312
|
return new TypeError(`[Raph] Cannot traverse non-container data at "${r}".`);
|
|
323
313
|
}
|
|
324
314
|
export {
|
|
325
|
-
|
|
315
|
+
S as PathStore
|
|
326
316
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function y(S,x){const w=new WeakMap,m=new WeakMap,v=(n,u,s=new Set)=>{if(!s.has(n)){s.add(n),n.changed.add(u),Array.isArray(n.source)&&x(n.proxy);for(const[c,l]of n.parents)for(const r of l)v(c,r,s)}},b=(n,u,s)=>{if(!n||typeof n!="object")return n;const c=Object.getPrototypeOf(n);let l=m.get(n)??w.get(n);if(!l){const r=n,f=Array.isArray(r),d=f?[]:Object.create(c);f&&(d.length=r.length),l={source:r,proxy:null,values:new Map,removed:new Set,changed:new Set,parents:new Map};const t=l,O=a=>!t.removed.has(a)&&(t.values.has(a)||Reflect.has(r,a)),g=a=>t.removed.has(a)?void 0:t.values.has(a)?t.values.get(a):Reflect.get(r,a);t.proxy=new Proxy(d,{get:(a,e)=>b(g(e),t,e),has:(a,e)=>O(e),set:(a,e,i)=>{if(f&&e==="length"){const o=Number(i);if(!Number.isInteger(o)||o<0||o>4294967295)throw new RangeError("Invalid array length");for(let h=o;h<Number(g("length"));h++)t.removed.add(String(h)),t.values.delete(String(h));d.length=o}else if(f&&typeof e=="string"&&/^(?:0|[1-9]\d*)$/.test(e)){const o=Number(e);o<4294967295&&o>=Number(g("length"))&&(t.values.set("length",o+1),d.length=o+1)}return t.values.set(e,i),t.removed.delete(e),v(t,e),!0},deleteProperty:(a,e)=>f&&e==="length"?!1:(t.values.delete(e),t.removed.add(e),v(t,e),!0),ownKeys:()=>[...new Set([...Reflect.ownKeys(r),...t.values.keys()])].filter(a=>!t.removed.has(a)),getOwnPropertyDescriptor:(a,e)=>{if(f&&e==="length")return{value:g(e),writable:!0,enumerable:!1,configurable:!1};const i=Object.getOwnPropertyDescriptor(r,e);if(!(t.removed.has(e)||!i&&!t.values.has(e)))return{value:b(g(e),t,e),writable:!0,enumerable:i?.enumerable??!0,configurable:!0}}}),w.set(r,t),m.set(t.proxy,t)}if(u&&s!==void 0){let r=l.parents.get(u);r||(r=new Set,l.parents.set(u,r)),r.add(s)}return l.proxy};return{root:b(S),unchangedArray(n,u){const s=m.get(n);if(!s)return null;for(const c of s.changed)if(s.values.has(c)||s.removed.has(c)||w.get(s.source[c])?.changed.has(u))return null;return s.source}}}exports.createDataDraft=y;
|
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
function k(x, S) {
|
|
2
|
-
const
|
|
2
|
+
const w = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), v = (n, u, a = /* @__PURE__ */ new Set()) => {
|
|
3
3
|
if (!a.has(n)) {
|
|
4
4
|
a.add(n), n.changed.add(u), Array.isArray(n.source) && S(n.proxy);
|
|
5
5
|
for (const [c, l] of n.parents)
|
|
6
6
|
for (const r of l)
|
|
7
|
-
|
|
7
|
+
v(c, r, a);
|
|
8
8
|
}
|
|
9
9
|
}, b = (n, u, a) => {
|
|
10
10
|
if (!n || typeof n != "object")
|
|
11
11
|
return n;
|
|
12
12
|
const c = Object.getPrototypeOf(n);
|
|
13
|
-
let l =
|
|
13
|
+
let l = m.get(n) ?? w.get(n);
|
|
14
14
|
if (!l) {
|
|
15
|
-
const r = n,
|
|
16
|
-
|
|
17
|
-
const t = l, O = (s) => !t.removed.has(s) && (t.values.has(s) || Reflect.has(r, s)),
|
|
15
|
+
const r = n, f = Array.isArray(r), i = f ? [] : Object.create(c);
|
|
16
|
+
f && (i.length = r.length), l = { source: r, proxy: null, values: /* @__PURE__ */ new Map(), removed: /* @__PURE__ */ new Set(), changed: /* @__PURE__ */ new Set(), parents: /* @__PURE__ */ new Map() };
|
|
17
|
+
const t = l, O = (s) => !t.removed.has(s) && (t.values.has(s) || Reflect.has(r, s)), g = (s) => t.removed.has(s) ? void 0 : t.values.has(s) ? t.values.get(s) : Reflect.get(r, s);
|
|
18
18
|
t.proxy = new Proxy(i, {
|
|
19
|
-
get: (s, e) => b(
|
|
19
|
+
get: (s, e) => b(g(e), t, e),
|
|
20
20
|
has: (s, e) => O(e),
|
|
21
|
-
set: (s, e,
|
|
22
|
-
if (
|
|
23
|
-
const o = Number(
|
|
21
|
+
set: (s, e, d) => {
|
|
22
|
+
if (f && e === "length") {
|
|
23
|
+
const o = Number(d);
|
|
24
24
|
if (!Number.isInteger(o) || o < 0 || o > 4294967295)
|
|
25
25
|
throw new RangeError("Invalid array length");
|
|
26
|
-
for (let h = o; h < Number(
|
|
26
|
+
for (let h = o; h < Number(g("length")); h++)
|
|
27
27
|
t.removed.add(String(h)), t.values.delete(String(h));
|
|
28
28
|
i.length = o;
|
|
29
|
-
} else if (
|
|
29
|
+
} else if (f && typeof e == "string" && /^(?:0|[1-9]\d*)$/.test(e)) {
|
|
30
30
|
const o = Number(e);
|
|
31
|
-
o < 4294967295 && o >= Number(
|
|
31
|
+
o < 4294967295 && o >= Number(g("length")) && (t.values.set("length", o + 1), i.length = o + 1);
|
|
32
32
|
}
|
|
33
|
-
return t.values.set(e,
|
|
33
|
+
return t.values.set(e, d), t.removed.delete(e), v(t, e), !0;
|
|
34
34
|
},
|
|
35
|
-
deleteProperty: (s, e) =>
|
|
35
|
+
deleteProperty: (s, e) => f && e === "length" ? !1 : (t.values.delete(e), t.removed.add(e), v(t, e), !0),
|
|
36
36
|
ownKeys: () => [.../* @__PURE__ */ new Set([...Reflect.ownKeys(r), ...t.values.keys()])].filter((s) => !t.removed.has(s)),
|
|
37
37
|
getOwnPropertyDescriptor: (s, e) => {
|
|
38
|
-
if (
|
|
39
|
-
return { value:
|
|
40
|
-
const
|
|
41
|
-
if (!(t.removed.has(e) || !
|
|
42
|
-
return { value: b(
|
|
38
|
+
if (f && e === "length")
|
|
39
|
+
return { value: g(e), writable: !0, enumerable: !1, configurable: !1 };
|
|
40
|
+
const d = Object.getOwnPropertyDescriptor(r, e);
|
|
41
|
+
if (!(t.removed.has(e) || !d && !t.values.has(e)))
|
|
42
|
+
return { value: b(g(e), t, e), writable: !0, enumerable: d?.enumerable ?? !0, configurable: !0 };
|
|
43
43
|
}
|
|
44
|
-
}),
|
|
44
|
+
}), w.set(r, t), m.set(t.proxy, t);
|
|
45
45
|
}
|
|
46
46
|
if (u && a !== void 0) {
|
|
47
47
|
let r = l.parents.get(u);
|
|
@@ -52,16 +52,12 @@ function k(x, S) {
|
|
|
52
52
|
return {
|
|
53
53
|
root: b(x),
|
|
54
54
|
unchangedArray(n, u) {
|
|
55
|
-
const a =
|
|
55
|
+
const a = m.get(n);
|
|
56
56
|
if (!a)
|
|
57
57
|
return null;
|
|
58
|
-
for (const c of a.changed)
|
|
59
|
-
if (a.values.has(c) || a.removed.has(c))
|
|
58
|
+
for (const c of a.changed)
|
|
59
|
+
if (a.values.has(c) || a.removed.has(c) || w.get(a.source[c])?.changed.has(u))
|
|
60
60
|
return null;
|
|
61
|
-
const l = m.get(a.source[c]);
|
|
62
|
-
if (l != null && l.changed.has(u))
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
61
|
return a.source;
|
|
66
62
|
}
|
|
67
63
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function l(r){return{error:r,hasUnrouted:!0}}function s(r,n){if(r===void 0||r.length===0)return;if(r.length===1)return r[0];const i=[];let e,t=!1;for(const o of r)i.push(o.error),t||=o.hasUnrouted,o.completed!==void 0&&(e??=[]).push(o.completed.error);const u=new AggregateError(i,n);return{error:u,hasUnrouted:t,...e===void 0?{}:{completed:{error:t?e.length===1?e[0]:new AggregateError(e,n):u}}}}function d(r){if(r!==void 0)throw r.error}exports.combineDisposalFailures=s;exports.throwDisposalFailure=d;exports.unroutedDisposalFailure=l;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function d(r) {
|
|
2
|
+
return { error: r, hasUnrouted: !0 };
|
|
3
|
+
}
|
|
4
|
+
function l(r, n) {
|
|
5
|
+
if (r === void 0 || r.length === 0)
|
|
6
|
+
return;
|
|
7
|
+
if (r.length === 1)
|
|
8
|
+
return r[0];
|
|
9
|
+
const i = [];
|
|
10
|
+
let o, t = !1;
|
|
11
|
+
for (const e of r)
|
|
12
|
+
i.push(e.error), t ||= e.hasUnrouted, e.completed !== void 0 && (o ??= []).push(e.completed.error);
|
|
13
|
+
const u = new AggregateError(i, n);
|
|
14
|
+
return {
|
|
15
|
+
error: u,
|
|
16
|
+
hasUnrouted: t,
|
|
17
|
+
...o === void 0 ? {} : {
|
|
18
|
+
completed: {
|
|
19
|
+
error: t ? o.length === 1 ? o[0] : new AggregateError(o, n) : u
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function c(r) {
|
|
25
|
+
if (r !== void 0)
|
|
26
|
+
throw r.error;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
l as combineDisposalFailures,
|
|
30
|
+
c as throwDisposalFailure,
|
|
31
|
+
d as unroutedDisposalFailure
|
|
32
|
+
};
|
|
@@ -1 +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;
|
|
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;
|