@raphy-js/raph 1.0.0-dev.18
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/LICENSE +202 -0
- package/dist/api/Raph.d.ts +97 -0
- package/dist/api/RaphFacadeSession.d.ts +90 -0
- package/dist/api/RaphReactivityInstance.d.ts +72 -0
- package/dist/api/errors.d.ts +25 -0
- package/dist/api/types.d.ts +170 -0
- package/dist/core-CyilRD7s.js +1055 -0
- package/dist/core-ugchZNqC.cjs +1 -0
- package/dist/debug/api/Raph.cjs +1 -0
- package/dist/debug/api/Raph.js +421 -0
- package/dist/debug/api/RaphFacadeSession.cjs +1 -0
- package/dist/debug/api/RaphFacadeSession.js +306 -0
- package/dist/debug/api/RaphReactivityInstance.cjs +1 -0
- package/dist/debug/api/RaphReactivityInstance.js +149 -0
- package/dist/debug/api/errors.cjs +1 -0
- package/dist/debug/api/errors.js +17 -0
- package/dist/debug/api/types.cjs +1 -0
- package/dist/debug/api/types.js +1 -0
- package/dist/debug/path/DataPath.cjs +1 -0
- package/dist/debug/path/DataPath.js +394 -0
- package/dist/debug/path/PathRouter.cjs +1 -0
- package/dist/debug/path/PathRouter.js +86 -0
- package/dist/debug/path/RaphKernel.cjs +1 -0
- package/dist/debug/path/RaphKernel.js +687 -0
- package/dist/debug/path/data-path.types.cjs +1 -0
- package/dist/debug/path/data-path.types.js +1 -0
- 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 +157 -0
- package/dist/debug/path/derived/RaphDerivedHandle.cjs +1 -0
- package/dist/debug/path/derived/RaphDerivedHandle.js +125 -0
- package/dist/debug/path/derived/derived-collection.types.cjs +1 -0
- package/dist/debug/path/derived/derived-collection.types.js +1 -0
- package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
- package/dist/debug/path/derived/derived-collection.utils.js +179 -0
- 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/derived/derived-strategy.utils.cjs +1 -0
- package/dist/debug/path/derived/derived-strategy.utils.js +20 -0
- package/dist/debug/path/meta/MetaController.cjs +1 -0
- package/dist/debug/path/meta/MetaController.js +214 -0
- package/dist/debug/path/meta/RaphMeta.cjs +1 -0
- package/dist/debug/path/meta/RaphMeta.js +68 -0
- package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
- package/dist/debug/path/meta/RaphMetaStore.js +184 -0
- package/dist/debug/path/meta/meta.types.cjs +1 -0
- package/dist/debug/path/meta/meta.types.js +1 -0
- package/dist/debug/path/path.types.cjs +1 -0
- package/dist/debug/path/path.types.js +1 -0
- package/dist/debug/path/pathSegmentKey.cjs +1 -0
- package/dist/debug/path/pathSegmentKey.js +12 -0
- package/dist/debug/path/storage/AdapterPathStore.cjs +1 -0
- package/dist/debug/path/storage/AdapterPathStore.js +133 -0
- package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
- package/dist/debug/path/storage/DefaultDataAdapter.js +356 -0
- package/dist/debug/path/storage/PathEventHub.cjs +1 -0
- package/dist/debug/path/storage/PathEventHub.js +148 -0
- package/dist/debug/path/storage/PathStore.cjs +1 -0
- package/dist/debug/path/storage/PathStore.js +326 -0
- package/dist/debug/path/storage/createDataDraft.cjs +1 -0
- package/dist/debug/path/storage/createDataDraft.js +71 -0
- package/dist/debug/path/storage/data-adapter.types.cjs +1 -0
- package/dist/debug/path/storage/data-adapter.types.js +1 -0
- package/dist/debug/reactivity/engine.cjs +1 -0
- package/dist/debug/reactivity/engine.js +1305 -0
- package/dist/debug/reactivity/reactive-object.cjs +1 -0
- package/dist/debug/reactivity/reactive-object.js +280 -0
- package/dist/debug/reactivity/scope.cjs +1 -0
- package/dist/debug/reactivity/scope.js +274 -0
- package/dist/debug/reactivity/types.cjs +1 -0
- package/dist/debug/reactivity/types.js +1 -0
- package/dist/debug/reactivity/watch.cjs +1 -0
- package/dist/debug/reactivity/watch.js +64 -0
- package/dist/debug/runtime/RaphRuntime.cjs +1 -0
- package/dist/debug/runtime/RaphRuntime.js +979 -0
- package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -0
- package/dist/debug/runtime/diagnostics/RaphDebug.js +297 -0
- package/dist/debug/runtime/errors.cjs +1 -0
- package/dist/debug/runtime/errors.js +15 -0
- package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphEffectScope.js +171 -0
- package/dist/debug/runtime/ownership/RaphNode.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphNode.js +206 -0
- package/dist/debug/runtime/ownership/RaphScope.cjs +1 -0
- package/dist/debug/runtime/ownership/RaphScope.js +101 -0
- package/dist/debug/runtime/ownership/parent-graph.types.cjs +1 -0
- package/dist/debug/runtime/ownership/parent-graph.types.js +1 -0
- package/dist/debug/runtime/ownership/parentGraph.cjs +1 -0
- package/dist/debug/runtime/ownership/parentGraph.js +10 -0
- package/dist/debug/runtime/ownership/throwDisposalErrors.cjs +1 -0
- package/dist/debug/runtime/ownership/throwDisposalErrors.js +9 -0
- package/dist/debug/runtime/phases/RaphFrameLoop.cjs +1 -0
- package/dist/debug/runtime/phases/RaphFrameLoop.js +106 -0
- package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -0
- package/dist/debug/runtime/phases/RaphPhasePipeline.js +587 -0
- package/dist/debug/runtime/phases/orderPhaseTasks.cjs +1 -0
- package/dist/debug/runtime/phases/orderPhaseTasks.js +59 -0
- package/dist/debug/runtime/phases/phase.types.cjs +1 -0
- package/dist/debug/runtime/phases/phase.types.js +8 -0
- package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -0
- package/dist/debug/runtime/reactivity/PathHandle.js +175 -0
- package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphMetaSource.js +112 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -0
- package/dist/debug/runtime/reactivity/RaphWorkGraph.js +995 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeReactivity.js +156 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -0
- package/dist/debug/runtime/reactivity/RuntimeWatch.js +88 -0
- package/dist/debug/runtime/reactivity/runtime-reactivity.types.cjs +1 -0
- package/dist/debug/runtime/reactivity/runtime-reactivity.types.js +1 -0
- package/dist/entrypoints/machine-testing.d.ts +2 -0
- package/dist/entrypoints/machine.d.ts +5 -0
- package/dist/entrypoints/path.d.ts +14 -0
- package/dist/entrypoints/reactivity.d.ts +1 -0
- package/dist/entrypoints/runtime.d.ts +17 -0
- package/dist/index.cjs +1 -0
- package/dist/index.js +48 -0
- package/dist/machine/compiler.d.ts +71 -0
- package/dist/machine/core.d.ts +50 -0
- package/dist/machine/persistence.d.ts +5 -0
- package/dist/machine/runtime.d.ts +4 -0
- package/dist/machine/testing.d.ts +43 -0
- package/dist/machine/types.d.ts +155 -0
- package/dist/machine-testing.cjs +1 -0
- package/dist/machine-testing.js +188 -0
- package/dist/machine.cjs +1 -0
- package/dist/machine.js +837 -0
- package/dist/main.d.ts +20 -0
- package/dist/path/DataPath.d.ts +73 -0
- package/dist/path/PathRouter.d.ts +21 -0
- package/dist/path/RaphKernel.d.ts +169 -0
- package/dist/path/data-path.types.d.ts +34 -0
- package/dist/path/data-path.utils.d.ts +9 -0
- package/dist/path/derived/DerivedRegistry.d.ts +67 -0
- package/dist/path/derived/RaphDerivedHandle.d.ts +97 -0
- package/dist/path/derived/derived-collection.types.d.ts +12 -0
- package/dist/path/derived/derived-collection.utils.d.ts +20 -0
- package/dist/path/derived/derived-strategy.types.d.ts +12 -0
- package/dist/path/derived/derived-strategy.utils.d.ts +4 -0
- package/dist/path/meta/MetaController.d.ts +85 -0
- package/dist/path/meta/RaphMeta.d.ts +45 -0
- package/dist/path/meta/RaphMetaStore.d.ts +45 -0
- package/dist/path/meta/meta.types.d.ts +31 -0
- package/dist/path/path.types.d.ts +27 -0
- package/dist/path/pathSegmentKey.d.ts +2 -0
- package/dist/path/storage/AdapterPathStore.d.ts +45 -0
- package/dist/path/storage/DefaultDataAdapter.d.ts +63 -0
- package/dist/path/storage/PathEventHub.d.ts +48 -0
- package/dist/path/storage/PathStore.d.ts +51 -0
- package/dist/path/storage/createDataDraft.d.ts +4 -0
- package/dist/path/storage/data-adapter.types.d.ts +17 -0
- package/dist/path.cjs +1 -0
- package/dist/path.js +18 -0
- package/dist/raph.cjs +1 -0
- package/dist/raph.js +48 -0
- package/dist/reactivity/engine.d.ts +393 -0
- package/dist/reactivity/reactive-object.d.ts +36 -0
- package/dist/reactivity/scope.d.ts +146 -0
- package/dist/reactivity/types.d.ts +175 -0
- package/dist/reactivity/watch.d.ts +15 -0
- package/dist/reactivity.cjs +1 -0
- package/dist/reactivity.js +14 -0
- package/dist/runtime/RaphRuntime.d.ts +225 -0
- package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
- package/dist/runtime/errors.d.ts +21 -0
- package/dist/runtime/ownership/RaphEffectScope.d.ts +29 -0
- package/dist/runtime/ownership/RaphNode.d.ts +40 -0
- package/dist/runtime/ownership/RaphScope.d.ts +38 -0
- package/dist/runtime/ownership/parent-graph.types.d.ts +4 -0
- package/dist/runtime/ownership/parentGraph.d.ts +3 -0
- package/dist/runtime/ownership/throwDisposalErrors.d.ts +1 -0
- package/dist/runtime/phases/RaphFrameLoop.d.ts +51 -0
- package/dist/runtime/phases/RaphPhasePipeline.d.ts +79 -0
- package/dist/runtime/phases/orderPhaseTasks.d.ts +6 -0
- package/dist/runtime/phases/phase.types.d.ts +92 -0
- package/dist/runtime/reactivity/PathHandle.d.ts +80 -0
- package/dist/runtime/reactivity/RaphMetaSource.d.ts +32 -0
- package/dist/runtime/reactivity/RaphWorkGraph.d.ts +171 -0
- package/dist/runtime/reactivity/RuntimeReactivity.d.ts +45 -0
- package/dist/runtime/reactivity/RuntimeWatch.d.ts +34 -0
- package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +11 -0
- package/dist/runtime.cjs +1 -0
- package/dist/runtime.js +23 -0
- package/package.json +141 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
var R = Object.defineProperty;
|
|
2
|
+
var m = (r, e, t) => e in r ? R(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var k = (r, e, t) => m(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { parseDataPath as h } from "../data-path.utils.js";
|
|
5
|
+
import { PathEventHub as H } from "./PathEventHub.js";
|
|
6
|
+
const u = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
class $ {
|
|
8
|
+
constructor() {
|
|
9
|
+
// Владеют path data и независимым event lifecycle этого store.
|
|
10
|
+
k(this, "_root");
|
|
11
|
+
k(this, "_eventHub", new H(
|
|
12
|
+
"[Raph] Path batch and publication failed."
|
|
13
|
+
));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Возвращает внутренний router для диагностического контракта Kernel.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
get _router() {
|
|
20
|
+
return this._eventHub.router;
|
|
21
|
+
}
|
|
22
|
+
get _events() {
|
|
23
|
+
return this._eventHub.events;
|
|
24
|
+
}
|
|
25
|
+
get _watcherCount() {
|
|
26
|
+
return this._eventHub.watcherCount;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Возвращает значение по пути без создания отсутствующих данных.
|
|
30
|
+
*/
|
|
31
|
+
get(e, t) {
|
|
32
|
+
const n = h(e, t), o = this._root;
|
|
33
|
+
if (o !== void 0)
|
|
34
|
+
return a(o, n.segments).value;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Читает значение по пути без регистрации реактивной зависимости.
|
|
38
|
+
*/
|
|
39
|
+
peek(e, t) {
|
|
40
|
+
return this.get(e, t);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Проверяет наличие значения по указанному пути.
|
|
44
|
+
*/
|
|
45
|
+
has(e, t) {
|
|
46
|
+
const n = h(e, t), o = this._root;
|
|
47
|
+
return o !== void 0 && a(o, n.segments).exists;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Записывает значение и публикует соответствующее изменение.
|
|
51
|
+
*/
|
|
52
|
+
set(e, t, n) {
|
|
53
|
+
const o = h(e, n);
|
|
54
|
+
if (o.segments.length === 0) {
|
|
55
|
+
this._setRoot(t);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const s = this._eventHub.hasWatchers, i = s ? a(this._root, o.segments).value : void 0;
|
|
59
|
+
if (this._root ?? (this._root = /* @__PURE__ */ Object.create(null)), O(this._root, o, t), !s)
|
|
60
|
+
return;
|
|
61
|
+
const c = a(this._root, o.segments).value;
|
|
62
|
+
this._eventHub.record({
|
|
63
|
+
kind: "set",
|
|
64
|
+
path: o.canonical,
|
|
65
|
+
previous: i,
|
|
66
|
+
value: c
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Объединяет значение по пути и публикует соответствующее изменение.
|
|
71
|
+
*/
|
|
72
|
+
merge(e, t, n) {
|
|
73
|
+
const o = h(e, n);
|
|
74
|
+
if (o.segments.length === 0) {
|
|
75
|
+
this._mergeRoot(t);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const s = this._eventHub.hasWatchers, i = a(this._root, o.segments).value, c = s && d(i) && d(t) ? A(i) : i;
|
|
79
|
+
if (d(i) && d(t)) {
|
|
80
|
+
g(this._root, o.segments);
|
|
81
|
+
for (const w of Object.keys(t))
|
|
82
|
+
l(i, w, t[w]);
|
|
83
|
+
} else
|
|
84
|
+
this._root ?? (this._root = /* @__PURE__ */ Object.create(null)), O(this._root, o, t);
|
|
85
|
+
if (!s)
|
|
86
|
+
return;
|
|
87
|
+
const f = a(this._root, o.segments).value;
|
|
88
|
+
this._eventHub.record({
|
|
89
|
+
kind: "merge",
|
|
90
|
+
path: o.canonical,
|
|
91
|
+
previous: c,
|
|
92
|
+
value: f
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Удаляет значение по пути и публикует изменение при наличии данных.
|
|
97
|
+
*/
|
|
98
|
+
delete(e, t) {
|
|
99
|
+
const n = h(e, t);
|
|
100
|
+
if (n.segments.length === 0) {
|
|
101
|
+
this._deleteRoot();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const o = a(this._root, n.segments);
|
|
105
|
+
!o.exists || this._root === void 0 || (g(this._root, n.segments), E(this._root, n), this._eventHub.hasWatchers && this._eventHub.record({
|
|
106
|
+
kind: "delete",
|
|
107
|
+
path: n.canonical,
|
|
108
|
+
previous: o.value,
|
|
109
|
+
value: void 0
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Выполняет операцию в общей синхронной batch boundary.
|
|
114
|
+
*/
|
|
115
|
+
batch(e) {
|
|
116
|
+
return this._eventHub.batch(e);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Подписывает callback на подходящие изменения и возвращает disposer.
|
|
120
|
+
*/
|
|
121
|
+
watch(e, t) {
|
|
122
|
+
return this._eventHub.watch(e, t);
|
|
123
|
+
}
|
|
124
|
+
_setRoot(e) {
|
|
125
|
+
const t = x(e), n = this._root;
|
|
126
|
+
this._root = t, this._recordRootEvent("set", n, t);
|
|
127
|
+
}
|
|
128
|
+
_mergeRoot(e) {
|
|
129
|
+
const t = this._root, n = this._eventHub.hasWatchers && d(t) && d(e) ? A(t) : t;
|
|
130
|
+
if (d(t) && d(e))
|
|
131
|
+
for (const o of Object.keys(e))
|
|
132
|
+
l(t, o, e[o]);
|
|
133
|
+
else
|
|
134
|
+
this._root = x(e);
|
|
135
|
+
this._recordRootEvent("merge", n, this._root);
|
|
136
|
+
}
|
|
137
|
+
_deleteRoot() {
|
|
138
|
+
const e = this._root;
|
|
139
|
+
e !== void 0 && (this._root = S(), this._recordRootEvent("delete", e, void 0));
|
|
140
|
+
}
|
|
141
|
+
_recordRootEvent(e, t, n) {
|
|
142
|
+
this._eventHub.record({ kind: e, path: "", previous: t, value: n });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function a(r, e) {
|
|
146
|
+
let t = r;
|
|
147
|
+
for (const n of e)
|
|
148
|
+
if (n.kind === "key") {
|
|
149
|
+
if (!b(t) || !Object.hasOwn(t, n.key))
|
|
150
|
+
return { exists: !1, value: void 0 };
|
|
151
|
+
t = t[n.key];
|
|
152
|
+
} else if (n.kind === "index") {
|
|
153
|
+
if (!Array.isArray(t) || !Object.hasOwn(t, n.index))
|
|
154
|
+
return { exists: !1, value: void 0 };
|
|
155
|
+
t = t[n.index];
|
|
156
|
+
} else {
|
|
157
|
+
if (!Array.isArray(t))
|
|
158
|
+
return { exists: !1, value: void 0 };
|
|
159
|
+
const o = _(t, n.key, n.value);
|
|
160
|
+
if (o === -1)
|
|
161
|
+
return { exists: !1, value: void 0 };
|
|
162
|
+
t = t[o];
|
|
163
|
+
}
|
|
164
|
+
return { exists: !0, value: t };
|
|
165
|
+
}
|
|
166
|
+
function g(r, e) {
|
|
167
|
+
let t = r;
|
|
168
|
+
for (const n of e) {
|
|
169
|
+
if (!b(t))
|
|
170
|
+
return;
|
|
171
|
+
const o = j(t, n);
|
|
172
|
+
Array.isArray(t) && u.delete(t), t = o;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function O(r, e, t) {
|
|
176
|
+
let n = r, o;
|
|
177
|
+
for (let i = 0; i < e.segments.length - 1; i++) {
|
|
178
|
+
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 = P(n, c, f, e.canonical);
|
|
180
|
+
}
|
|
181
|
+
const s = e.segments[e.segments.length - 1];
|
|
182
|
+
if (C(n, s, t, e.canonical), s.kind === "key" && o !== void 0) {
|
|
183
|
+
const i = u.get(o);
|
|
184
|
+
i == null || i.delete(s.key), (i == null ? void 0 : i.size) === 0 && u.delete(o);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function E(r, e) {
|
|
188
|
+
let t = r;
|
|
189
|
+
for (let s = 0; s < e.segments.length - 1; s++) {
|
|
190
|
+
const i = e.segments[s], c = j(t, i);
|
|
191
|
+
if (!b(c))
|
|
192
|
+
return;
|
|
193
|
+
t = c;
|
|
194
|
+
}
|
|
195
|
+
const n = e.segments[e.segments.length - 1];
|
|
196
|
+
if (n.kind === "key") {
|
|
197
|
+
delete t[n.key];
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (!Array.isArray(t))
|
|
201
|
+
return;
|
|
202
|
+
if (n.kind === "index") {
|
|
203
|
+
u.delete(t), delete t[n.index];
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const o = _(t, n.key, n.value);
|
|
207
|
+
o !== -1 && (u.delete(t), delete t[o]);
|
|
208
|
+
}
|
|
209
|
+
function j(r, e) {
|
|
210
|
+
if (e.kind === "key")
|
|
211
|
+
return Object.hasOwn(r, e.key) ? r[e.key] : void 0;
|
|
212
|
+
if (!Array.isArray(r))
|
|
213
|
+
return;
|
|
214
|
+
if (e.kind === "index")
|
|
215
|
+
return r[e.index];
|
|
216
|
+
const t = _(r, e.key, e.value);
|
|
217
|
+
return t === -1 ? void 0 : r[t];
|
|
218
|
+
}
|
|
219
|
+
function P(r, e, t, n) {
|
|
220
|
+
if (e.kind === "key") {
|
|
221
|
+
const s = r;
|
|
222
|
+
let i = s[e.key];
|
|
223
|
+
return (!Object.hasOwn(s, e.key) || i === void 0) && (i = p(t), l(s, e.key, i)), v(i, n);
|
|
224
|
+
}
|
|
225
|
+
if (e.kind === "index") {
|
|
226
|
+
if (!Array.isArray(r))
|
|
227
|
+
throw y(n);
|
|
228
|
+
let s = r[e.index];
|
|
229
|
+
return (!Object.hasOwn(r, e.index) || s === void 0) && (u.delete(r), s = p(t), r[e.index] = s), v(s, n);
|
|
230
|
+
}
|
|
231
|
+
if (!Array.isArray(r))
|
|
232
|
+
throw y(n);
|
|
233
|
+
let o = _(r, e.key, e.value);
|
|
234
|
+
if (o === -1) {
|
|
235
|
+
u.delete(r);
|
|
236
|
+
const s = /* @__PURE__ */ Object.create(null);
|
|
237
|
+
s[e.key] = e.value, r.push(s), o = r.length - 1;
|
|
238
|
+
}
|
|
239
|
+
return v(r[o], n);
|
|
240
|
+
}
|
|
241
|
+
function C(r, e, t, n) {
|
|
242
|
+
if (e.kind === "key") {
|
|
243
|
+
l(r, e.key, t);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (e.kind === "index") {
|
|
247
|
+
if (!Array.isArray(r))
|
|
248
|
+
throw y(n);
|
|
249
|
+
u.delete(r), r[e.index] = t;
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (!Array.isArray(r))
|
|
253
|
+
throw y(n);
|
|
254
|
+
const o = _(r, e.key, e.value);
|
|
255
|
+
if (o !== -1) {
|
|
256
|
+
u.delete(r), r[o] = t;
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (!d(t))
|
|
260
|
+
throw new TypeError(`[Raph] New selector target at "${n}" must be an object.`);
|
|
261
|
+
const s = t[e.key];
|
|
262
|
+
if (Object.hasOwn(t, e.key) && !Object.is(s, e.value))
|
|
263
|
+
throw new TypeError(`[Raph] Selector target at "${n}" has a conflicting key.`);
|
|
264
|
+
u.delete(r), r.push(Object.hasOwn(t, e.key) ? t : { ...t, [e.key]: e.value });
|
|
265
|
+
}
|
|
266
|
+
function p(r) {
|
|
267
|
+
return r.kind === "index" || r.kind === "selector" ? [] : /* @__PURE__ */ Object.create(null);
|
|
268
|
+
}
|
|
269
|
+
function S() {
|
|
270
|
+
return /* @__PURE__ */ Object.create(null);
|
|
271
|
+
}
|
|
272
|
+
function x(r) {
|
|
273
|
+
if (b(r))
|
|
274
|
+
return r;
|
|
275
|
+
throw new TypeError("[Raph] Root value must be an object or array.");
|
|
276
|
+
}
|
|
277
|
+
function v(r, e) {
|
|
278
|
+
if (b(r))
|
|
279
|
+
return r;
|
|
280
|
+
throw y(e);
|
|
281
|
+
}
|
|
282
|
+
function _(r, e, t) {
|
|
283
|
+
let n = u.get(r);
|
|
284
|
+
const o = n == null ? void 0 : n.get(e);
|
|
285
|
+
if (o)
|
|
286
|
+
return o.get(t) ?? -1;
|
|
287
|
+
const s = /* @__PURE__ */ new Map();
|
|
288
|
+
for (let i = 0; i < r.length; i++) {
|
|
289
|
+
const c = r[i];
|
|
290
|
+
if (d(c) && Object.hasOwn(c, e)) {
|
|
291
|
+
const f = c[e];
|
|
292
|
+
(f === null || typeof f == "string" || typeof f == "number" || typeof f == "boolean") && !s.has(f) && s.set(f, i);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return n || (n = /* @__PURE__ */ new Map(), u.set(r, n)), n.set(e, s), s.get(t) ?? -1;
|
|
296
|
+
}
|
|
297
|
+
function l(r, e, t) {
|
|
298
|
+
if (e === "__proto__") {
|
|
299
|
+
Object.defineProperty(r, e, {
|
|
300
|
+
configurable: !0,
|
|
301
|
+
enumerable: !0,
|
|
302
|
+
value: t,
|
|
303
|
+
writable: !0
|
|
304
|
+
});
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
r[e] = t;
|
|
308
|
+
}
|
|
309
|
+
function A(r) {
|
|
310
|
+
const e = Object.create(Object.getPrototypeOf(r));
|
|
311
|
+
for (const t of Object.keys(r))
|
|
312
|
+
l(e, t, r[t]);
|
|
313
|
+
return e;
|
|
314
|
+
}
|
|
315
|
+
function d(r) {
|
|
316
|
+
return typeof r == "object" && r !== null && !Array.isArray(r);
|
|
317
|
+
}
|
|
318
|
+
function b(r) {
|
|
319
|
+
return Array.isArray(r) || d(r);
|
|
320
|
+
}
|
|
321
|
+
function y(r) {
|
|
322
|
+
return new TypeError(`[Raph] Cannot traverse non-container data at "${r}".`);
|
|
323
|
+
}
|
|
324
|
+
export {
|
|
325
|
+
$ as PathStore
|
|
326
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function y(S,x){const m=new WeakMap,v=new WeakMap,b=(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)b(c,r,s)}},w=(n,u,s)=>{if(!n||typeof n!="object")return n;const c=Object.getPrototypeOf(n);let l=v.get(n)??m.get(n);if(!l){const r=n,g=Array.isArray(r),d=g?[]:Object.create(c);g&&(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)),i=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)=>w(i(e),t,e),has:(a,e)=>O(e),set:(a,e,f)=>{if(g&&e==="length"){const o=Number(f);if(!Number.isInteger(o)||o<0||o>4294967295)throw new RangeError("Invalid array length");for(let h=o;h<Number(i("length"));h++)t.removed.add(String(h)),t.values.delete(String(h));d.length=o}else if(g&&typeof e=="string"&&/^(?:0|[1-9]\d*)$/.test(e)){const o=Number(e);o<4294967295&&o>=Number(i("length"))&&(t.values.set("length",o+1),d.length=o+1)}return t.values.set(e,f),t.removed.delete(e),b(t,e),!0},deleteProperty:(a,e)=>g&&e==="length"?!1:(t.values.delete(e),t.removed.add(e),b(t,e),!0),ownKeys:()=>[...new Set([...Reflect.ownKeys(r),...t.values.keys()])].filter(a=>!t.removed.has(a)),getOwnPropertyDescriptor:(a,e)=>{if(g&&e==="length")return{value:i(e),writable:!0,enumerable:!1,configurable:!1};const f=Object.getOwnPropertyDescriptor(r,e);if(!(t.removed.has(e)||!f&&!t.values.has(e)))return{value:w(i(e),t,e),writable:!0,enumerable:(f==null?void 0:f.enumerable)??!0,configurable:!0}}}),m.set(r,t),v.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:w(S),unchangedArray(n,u){const s=v.get(n);if(!s)return null;for(const c of s.changed){if(s.values.has(c)||s.removed.has(c))return null;const l=m.get(s.source[c]);if(l!=null&&l.changed.has(u))return null}return s.source}}}exports.createDataDraft=y;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
function k(x, S) {
|
|
2
|
+
const m = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), w = (n, u, a = /* @__PURE__ */ new Set()) => {
|
|
3
|
+
if (!a.has(n)) {
|
|
4
|
+
a.add(n), n.changed.add(u), Array.isArray(n.source) && S(n.proxy);
|
|
5
|
+
for (const [c, l] of n.parents)
|
|
6
|
+
for (const r of l)
|
|
7
|
+
w(c, r, a);
|
|
8
|
+
}
|
|
9
|
+
}, b = (n, u, a) => {
|
|
10
|
+
if (!n || typeof n != "object")
|
|
11
|
+
return n;
|
|
12
|
+
const c = Object.getPrototypeOf(n);
|
|
13
|
+
let l = v.get(n) ?? m.get(n);
|
|
14
|
+
if (!l) {
|
|
15
|
+
const r = n, g = Array.isArray(r), i = g ? [] : Object.create(c);
|
|
16
|
+
g && (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)), d = (s) => t.removed.has(s) ? void 0 : t.values.has(s) ? t.values.get(s) : Reflect.get(r, s);
|
|
18
|
+
t.proxy = new Proxy(i, {
|
|
19
|
+
get: (s, e) => b(d(e), t, e),
|
|
20
|
+
has: (s, e) => O(e),
|
|
21
|
+
set: (s, e, f) => {
|
|
22
|
+
if (g && e === "length") {
|
|
23
|
+
const o = Number(f);
|
|
24
|
+
if (!Number.isInteger(o) || o < 0 || o > 4294967295)
|
|
25
|
+
throw new RangeError("Invalid array length");
|
|
26
|
+
for (let h = o; h < Number(d("length")); h++)
|
|
27
|
+
t.removed.add(String(h)), t.values.delete(String(h));
|
|
28
|
+
i.length = o;
|
|
29
|
+
} else if (g && typeof e == "string" && /^(?:0|[1-9]\d*)$/.test(e)) {
|
|
30
|
+
const o = Number(e);
|
|
31
|
+
o < 4294967295 && o >= Number(d("length")) && (t.values.set("length", o + 1), i.length = o + 1);
|
|
32
|
+
}
|
|
33
|
+
return t.values.set(e, f), t.removed.delete(e), w(t, e), !0;
|
|
34
|
+
},
|
|
35
|
+
deleteProperty: (s, e) => g && e === "length" ? !1 : (t.values.delete(e), t.removed.add(e), w(t, e), !0),
|
|
36
|
+
ownKeys: () => [.../* @__PURE__ */ new Set([...Reflect.ownKeys(r), ...t.values.keys()])].filter((s) => !t.removed.has(s)),
|
|
37
|
+
getOwnPropertyDescriptor: (s, e) => {
|
|
38
|
+
if (g && e === "length")
|
|
39
|
+
return { value: d(e), writable: !0, enumerable: !1, configurable: !1 };
|
|
40
|
+
const f = Object.getOwnPropertyDescriptor(r, e);
|
|
41
|
+
if (!(t.removed.has(e) || !f && !t.values.has(e)))
|
|
42
|
+
return { value: b(d(e), t, e), writable: !0, enumerable: (f == null ? void 0 : f.enumerable) ?? !0, configurable: !0 };
|
|
43
|
+
}
|
|
44
|
+
}), m.set(r, t), v.set(t.proxy, t);
|
|
45
|
+
}
|
|
46
|
+
if (u && a !== void 0) {
|
|
47
|
+
let r = l.parents.get(u);
|
|
48
|
+
r || (r = /* @__PURE__ */ new Set(), l.parents.set(u, r)), r.add(a);
|
|
49
|
+
}
|
|
50
|
+
return l.proxy;
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
root: b(x),
|
|
54
|
+
unchangedArray(n, u) {
|
|
55
|
+
const a = v.get(n);
|
|
56
|
+
if (!a)
|
|
57
|
+
return null;
|
|
58
|
+
for (const c of a.changed) {
|
|
59
|
+
if (a.values.has(c) || a.removed.has(c))
|
|
60
|
+
return null;
|
|
61
|
+
const l = m.get(a.source[c]);
|
|
62
|
+
if (l != null && l.changed.has(u))
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return a.source;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
k as createDataDraft
|
|
71
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var z=Object.defineProperty;var P=(c,e,t)=>e in c?z(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var b=(c,e,t)=>P(c,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("./reactive-object.cjs"),R=require("./scope.cjs"),G=require("./watch.cjs"),w=1,p=2,C=4,S=8,W=16,y=32,x=64,O=128,m=256,v=512,E=w|p,_=16,M=2;function U(c){c.dependencyLookupDebt===void 0&&c.dependencyIndex===void 0||(c.dependencyIndex=void 0,c.dependencyLookupDebt=void 0,c.dependencyLookupSearches=void 0)}function Q(c,e){if(e<=_||c.flags&O||c.dependencyIndex!==void 0)return;const t=(c.dependencyLookupSearches??0)+1,i=(c.dependencyLookupDebt??0)+e;if(c.dependencyLookupSearches=t,c.dependencyLookupDebt=i,t<M||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 j(c,e,t){var r;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 l=(r=e.dependencyIndex)==null?void 0:r.get(c);if(l!==void 0)return c.subSearchCursor=l.nextSub??i,l;if(e.dependencyIndex!==void 0)return}let a=s.nextSub??i;for(;a!==s;){if(++n,a.sub===e)return c.subSearchCursor=a.nextSub??i,t&&Q(e,n),a;a=a.nextSub??i}t&&Q(e,n)}class N{constructor(e={}){b(this,"adaptiveDependencyIndex");b(this,"activeSub",null);b(this,"batchDepth",0);b(this,"effectReadIndex",0);b(this,"effectWriteIndex",0);b(this,"invalidationDepth",0);b(this,"dependencyDepth",0);b(this,"flushingEffects",!1);b(this,"effectQueue",new Array(16).fill(void 0));b(this,"invalidationStack",new Array(512).fill(null));b(this,"dependencyStack",[]);b(this,"handleReaders",this.createHandleReaders());b(this,"effectScheduler");b(this,"flushEffects");b(this,"_effectImmediate");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 a=i;if(a!==void 0)return this.readSignalValue(a);const r=this.activeSub;return r===null||(i=this.materializeSignal(t,r)),t},n=a=>{const r=i;if(r!==void 0){this.writeSignalValue(r,a);return}t!==a&&(t=a)};return{get:s,peek:this.handleReaders.peek,set:n}}reactive(e){return B.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,p|w|y);t!==void 0&&(i.onStop=t);const s=this.activeSub;s!==null&&s.flags&y&&R.appendScopeChild(s,i);try{this.executeEffect(i)}catch(n){try{this.disposeEffect(i)}catch(a){throw new AggregateError([n,a],"Effect registration and cleanup failed.")}throw n}return this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects(),()=>this.disposeEffect(i)}watch(e,t,i){return G.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 R.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|=v),t.flags&O?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,p|w|y);let s=!1;t!==void 0&&(i.onStop=t);const n=this.activeSub;n!==null&&n.flags&y&&R.appendScopeChild(n,i);const a=()=>{if(!(!(i.flags&x)||i.evaluate===void 0)){i.flags&=~x,s=!0;try{this.executeEffect(i)}catch(r){if(!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex)try{this.flushEffects()}catch(l){throw new AggregateError([r,l],"Effect execution and queue processing failed.")}throw r}!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects()}};try{const r=this.effectScheduler.bind(a);r.cancelPending=()=>i.evaluate===void 0||!s?!1:(this.settleCancelledDependencies(i),i.flags&=~(x|E|C),!this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects(),!0),r.rearmPending=()=>{i.evaluate!==void 0&&(i.flags|=p|x,r.schedule())},i.effectTask=r,this.requestEffectTask(i)}catch(r){try{this.disposeEffect(i)}catch(l){throw new AggregateError([r,l],"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&p&&this.commitSignalValue(e,i),e.cachedValue}writeSignalValue(e,t){if(e.flags&p||this.batchDepth){const s=!!(e.flags&p);if((e.flags&p?e.pendingValue:e.cachedValue)===t)return;if(e.pendingValue=t,e.cachedValue===t)e.flags&=~p,e.pendingAuthor=void 0;else{e.flags|=p;const r=this.activeSub!==null&&this.activeSub.flags&S?this.activeSub:null;s?e.pendingAuthor!==r&&(e.pendingAuthor=null):e.pendingAuthor=r}const a=e.firstSub;a!=null&&(!s||this.activeSub!==null&&this.activeSub.flags&S||e.flags&v)&&this.propagateInvalidation(a,!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|E|m),s=i===0?e.cachedValue:i&W?this.evaluateFirstValue(e):this.refreshComputedValue(e,t);if(e.evaluate===void 0)return s;const n=this.activeSub;if(n!==null){const a=n.tailDep;n.flags&O?(a===null||a.dep!==e)&&this.appendInitialDependency(e,n):this.trackDependency(e,n)}return s}evaluateFirstValue(e){const t=e.flags&v,i=e.evaluate;e.flags=t|S|O;const s=this.activeSub;this.activeSub=e;try{const n=i();return e.evaluate!==i?(e.cachedValue=void 0,e.flags=0,n):(e.cachedValue=n,e.flags=t|(e.flags&C?p:0),n)}catch(n){throw e.evaluate!==i?(e.cachedValue=void 0,e.flags=0,n):(e.flags=t|m,s!==null&&this.trackDependency(e,s),n)}finally{this.activeSub=s}}refreshComputedValue(e,t,i=null){try{if(t&(p|C|m))return this.recomputeValue(e,i)||(e.flags&=~E),e.cachedValue;const s=e.firstDep;return(s===null||!this.refreshDependencies(e,s)||!this.recomputeValue(e,i))&&(e.flags&=~E),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&=~p;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<=_){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,a=s;for(;a!==null&&n<_;){const l=a;if(l.dep===e)return this.reorderDependency(t,l,i),t.tailDep=l,l;a=l.nextDep,++n}let r=i;for(;r!==null&&n<_;){const l=r;if(l.dep===e)return l;r=l.prevDep,++n}if(a!==null||r!==null){const l=j(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){var a;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,(a=t.dependencyIndex)==null||a.set(e,n),e.flags&v&&this.attachDependencyCleanup(n),n}insertDependency(e,t,i){var r;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 a=i===null?t.firstDep:i.nextDep;return n.nextDep=a,a!==null&&(a.prevDep=n),i===null?t.firstDep=n:i.nextDep=n,++t.depCount,(r=t.dependencyIndex)==null||r.set(e,n),e.flags&v&&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==null||i.set(t,e),t.flags&v&&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 a=i===null?e.firstDep:i.nextDep;t.prevDep=i,t.nextDep=a,a!==null&&(a.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}e.depCount<=_&&U(e)}}detachSubLink(e){var t;if((t=e.sub.dependencyIndex)==null||t.delete(e.dep),e.dep.flags&v){const i=e.dependencyCleanup;e.dependencyCleanup=void 0,i==null||i()}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){var n,a;const t=e.dep.sourceHooks,i=t==null?void 0:t.onDependency;if(i===void 0)return;const s=((n=e.sub.sourceHooks)==null?void 0:n.dependencyOwner)??((a=e.sub.effectTask)==null?void 0:a.dependencyOwner);s!==void 0&&(e.dependencyCleanup=i(s))}releaseSourceSubs(e){if(!(e.flags&v)){let i=e.firstSub;for(;i!=null;){const s=i.nextSub,n=i.sub;this.detachDependencyLink(i),this.detachSubLink(i);const a=n.flags;(a&(E|S))===w&&(n.flags=a&~w|p,a&y&&this.enqueueEffect(n,e)),i=s}e.firstSub=e.lastSub=null,e.subSearchCursor=void 0;return}let t=e.firstSub;for(;t!=null;){const i=t.nextSub;this.detachDependencyLink(t),this.detachSubLink(t),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,t.depCount<=_&&U(t)}enqueueEffect(e,t){var s,n;const i=t!==void 0&&t.flags&v?t.sourceHooks.token:void 0;i!==void 0&&((n=(s=e.effectTask)==null?void 0:s.notify)==null||n.call(s,i)),!(e.flags&x)&&(e.flags|=x,this.effectQueue[this.effectWriteIndex]=e,++this.effectWriteIndex)}propagateInvalidation(e,t=!1){var n,a,r,l,h,g,u,o,I,A,L,q,F;const i=this.invalidationDepth;let s=i;for(let d=e;d!==null;d=d.nextSub){const f=d.sub,D=f.flags;let k=0;if(D&(E|S)?D&S&&(k=this.invalidateReadDependency(d,f,D)):(k=D&~C|(t?w:p),f.flags=k),k===0){if(D&y&&D&x){const T=d.dep.flags&v?d.dep.sourceHooks.token:void 0;T!==void 0&&((a=(n=f.effectTask)==null?void 0:n.notify)==null||a.call(n,T))}else f.flags&v&&((l=(r=f.sourceHooks).onInvalidate)==null||l.call(r,f.firstSub!==null),f.firstSub!==null&&(this.invalidationStack[s++]=f.firstSub));continue}k&y?(!(k&S)||((h=f.effectTask)==null?void 0:h.allowScheduleDuringRun)===!0)&&this.enqueueEffect(f,d.dep):(!(D&E)&&f.flags&v&&((u=(g=f.sourceHooks).onInvalidate)==null||u.call(g,f.firstSub!==null)),f.firstSub!==null&&(this.invalidationStack[s++]=f.firstSub))}for(;s!==i;){let d=this.invalidationStack[--s];do{const f=d.sub,D=f.flags;let k=0;if(D&(E|S)?D&S&&(k=this.invalidateReadDependency(d,f,D)):(k=D&~C|w,f.flags=k),k===0){if(D&y&&D&x){const T=d.dep.flags&v?d.dep.sourceHooks.token:void 0;T!==void 0&&((I=(o=f.effectTask)==null?void 0:o.notify)==null||I.call(o,T))}else if(f.flags&v&&((L=(A=f.sourceHooks).onInvalidate)==null||L.call(A,f.firstSub!==null),f.firstSub!==null)){d.nextSub!==null&&(this.invalidationStack[s++]=d.nextSub),d=f.firstSub;continue}}else if(k&y)this.enqueueEffect(f,d.dep);else if(!(D&E)&&f.flags&v&&((F=(q=f.sourceHooks).onInvalidate)==null||F.call(q,f.firstSub!==null)),f.firstSub!==null){d.nextSub!==null&&(this.invalidationStack[s++]=d.nextSub),d=f.firstSub;continue}d=d.nextSub}while(d!==null)}this.invalidationDepth=i}invalidateReadDependency(e,t,i){const s=t.tailDep;if(s===null)return 0;if(e!==s){for(let a=e.prevDep;a!==null;a=a.prevDep)if(a===s)return 0}const n=i|C|w;return t.flags=n,n}confirmSubUpdates(e,t,i=null){var s,n;for(let a=e;a!==null;a=a.nextSub){if(a===t||a.sub===i)continue;const r=a.sub,l=r.flags;l&p||(r.flags=l&~w|p,l&y?this.enqueueEffect(r,a.dep):l&E||r.flags&v&&((n=(s=r.sourceHooks).onInvalidate)==null||n.call(s,r.firstSub!==null)))}}recomputeValue(e,t=null){const i=e.evaluate;e.tailDep=null;const s=e.flags&~C|S;e.flags=s;const n=this.activeSub;this.activeSub=e;let a;try{a=i()}catch(u){throw e.evaluate!==i?(e.cachedValue=void 0,e.flags=0,u):(this.restoreComputedFailure(e,t),u)}finally{this.activeSub=n}if(e.evaluate!==i)return e.cachedValue=void 0,e.flags=0,!1;const r=e.flags&C,l=s&-268,h=e.tailDep;(h===null?e.firstDep:h.nextDep)!==null&&this.pruneUnreadDependencies(e);const g=e.cachedValue;return e.cachedValue=a,e.flags=s&v|(r?p:l),g===a?!1:(e.firstSub!==null&&this.confirmSubUpdates(e.firstSub,t),!0)}restoreComputedFailure(e,t){e.flags=e.flags&-144|m,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}}settleCancelledDependencies(e){for(let t=e.firstDep;t!==null;t=t.nextDep){const i=t.dep,s=i.flags;s&(W|E|m)&&(i.evaluate===void 0?s&p&&this.commitSignalValue(i,t):this.refreshComputedValue(i,s,t))}}walkDependencyChain(e,t){const i=this.dependencyDepth;let s=i,n=!1;e:for(;;){if(e.flags&p)n=!0;else{const a=t.dep,r=a.flags;if(r&(p|m))this.dependencyDepth=s,n=a.evaluate===void 0?this.commitSignalValue(a,t):this.recomputeValue(a,t);else if(r&w){if(a.firstDep!==null){this.dependencyStack[s++]=t,e=a,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(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;){this.dependencyDepth=--s;const a=this.dependencyStack[s];if(e.flags&=~w,e=a.sub,a.nextDep!==null){t=a.nextDep;continue e}}return e.flags&=~w,this.dependencyDepth=i,!1}}restoreFailedDependency(e){e.flags&=-16,e.flags&y||(e.flags|=m)}executeEffect(e){const t=e.flags;if(!(t&E))return;if(!(t&(p|C))){const h=e.firstDep;try{if(h===null||!this.refreshDependencies(e,h)){e.flags&=~E;return}}catch(g){throw e.flags&=-80,g}}const i=e.evaluate;if(i===void 0){e.flags&=~E;return}let s;if(e.scopeLastChild!==void 0)try{this.disposeNestedEffects(e)}catch(h){s=[h]}const n=typeof e.cachedValue=="function"?e.cachedValue:void 0;if(e.cachedValue=void 0,e.flags&=~C,n!==void 0)try{this.untracked(n)}catch(h){s??(s=[]),s.push(h)}if(s!==void 0){try{this.disposeEffect(e)}catch(h){s.push(h)}R.throwScopeErrors(s,"Effect cleanup failed.")}if(e.evaluate===void 0)return;e.tailDep=null,e.flags=e.flags&~C|S;const a=this.activeSub;this.activeSub=e;let r;try{r=i()}catch(h){this.activeSub=a,e.flags&=~S,this.failEffectRun(e,h,s)}finally{this.activeSub=a,e.flags&=~S}const l=e.tailDep;if((l===null?e.firstDep:l.nextDep)!==null&&this.pruneUnreadDependencies(e),typeof r=="function")if(e.evaluate===void 0)try{this.untracked(r)}catch(h){s??(s=[]),s.push(h)}else e.cachedValue=r;e.flags&x?e.flags=e.flags&-7|w: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&(y|S))===(y|S))){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&=~x,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&(y|S))===(y|S))){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&=~x,this.executeEffect(t)):t.evaluate!==void 0?this.scheduleEffectTask(t,i):t.flags&=~x}}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;try{const a=t?n.effectTask:void 0;a!==void 0&&n.evaluate!==void 0?this.scheduleEffectTask(n,a):(n.flags&=~x,this.executeEffect(n))}catch(a){i.push(a)}}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|=x,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),R.detachScopeChild(e);let n=e.firstDep;for(;n!==null;){const r=n.nextDep;this.detachSubLink(n),n=r}e.firstDep=e.tailDep=null,e.depCount=0,U(e);let a;if(t!==void 0)try{t.dispose()}catch(r){a=[r]}try{this.disposeNestedEffects(e)}catch(r){a??(a=[]),a.push(r)}if(s!==void 0)try{this.untracked(s)}catch(r){a??(a=[]),a.push(r)}if(i!==void 0)try{this.untracked(i)}catch(r){a??(a=[]),a.push(r)}this.invalidationStack.length=this.invalidationDepth,this.dependencyStack.length=this.dependencyDepth,a!==void 0&&R.throwScopeErrors(a,"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&&R.throwScopeErrors(t,"Nested effect disposal failed.")}static materializeComputed(e){e.flags=W|(e.sourceHooks===void 0?0:v),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 N.materializeComputed(i),this.get=t,e.readComputedValue(i)},initializeRaw(){const i=this;N.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(a){if(arguments.length!==0){const h=s;h!==void 0?t.writeSignalValue(h,a):i!==a&&(i=a);return}const r=s;if(r!==void 0)return t.readSignalValue(r);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,a=!1;const r=()=>{const u=n;if(u!==void 0)return this.readSignalValue(u);const o=this.activeSub;if(o===null)return s;const I=s;return n=this.materializeSignal(I,o,t),s=void 0,I},l=t===void 0?u=>{const o=n;o!==void 0?this.writeSignalValue(o,u):s!==u&&(s=u)}:u=>{var I,A;const o=n;if(o!==void 0){const L=o.flags&p?o.pendingValue:o.cachedValue;L!==u&&((I=t.onChange)==null||I.call(t,L,u,o.firstSub!==null)),this.writeSignalValue(o,u);return}s!==u&&((A=t.onChange)==null||A.call(t,s,u,!1),s=u)},g={source:{get:r,peek:this.handleReaders.peek,set:l},dispose(){var o;if(a)return!0;a=!0,s=void 0;let u;try{(o=t==null?void 0:t.onDispose)==null||o.call(t,(n==null?void 0:n.firstSub)!=null)}catch(I){(u??(u=[])).push(I)}if(n!==void 0){try{i.releaseSourceSubs(n)}catch(I){(u??(u=[])).push(I)}n.cachedValue=void 0,n.pendingValue=void 0,n.pendingAuthor=void 0,n.flags=0}if(n=void 0,(u==null?void 0:u.length)===1)throw u[0];if(u!==void 0&&u.length>1)throw new AggregateError(u,"Owned signal disposal failed.");return!0}};return t!==void 0&&(g.hasSubscribers=()=>(n==null?void 0:n.firstSub)!=null),g}_ownedComputed(e,t){const i=this,s=this.createComputedHandle(e,t);let n=!1;const a={source:s,dispose(){var h;if(n)return!0;n=!0,i.activeSub===s&&(i.activeSub=null);const r=[];try{(h=t==null?void 0:t.onDispose)==null||h.call(t,s.firstSub!=null)}catch(g){r.push(g)}if(s.flags!==void 0)try{i.releaseSourceSubs(s)}catch(g){r.push(g)}let l=s.firstDep;for(;l!=null;){const g=l.nextDep;i.detachSubLink(l),l=g}if(s.firstDep=s.tailDep=null,s.depCount=0,U(s),s.evaluate=void 0,s.cachedValue=void 0,s.flags=0,r.length===1)throw r[0];if(r.length>1)throw new AggregateError(r,"Owned computed disposal failed.");return!0}};return t!==void 0&&(a.hasSubscribers=()=>s.firstSub!=null),a}_startBatch(){++this.batchDepth}_endBatch(){!--this.batchDepth&&this.effectReadIndex!==this.effectWriteIndex&&this.flushEffects()}_isTracking(){return this.activeSub!==null}_isFlushingEffects(){return this.flushingEffects}}let K;function V(){return K??(K=new N)}const Y=c=>V().signal(c),X=c=>V().reactive(c);function Z(c){return V().computed(c)}const J=(c,e)=>V().effect(c,e),$=(c,e,t)=>V().watch(c,e,t),H=c=>V().batch(c),ee=c=>V().untracked(c),te=()=>V().scope();exports.ScopeNode=R.ScopeNode;exports.RaphReactivity=N;exports.batch=H;exports.computed=Z;exports.effect=J;exports.reactive=X;exports.scope=te;exports.signal=Y;exports.untracked=ee;exports.watch=$;
|