@raphy-js/raph 1.0.1-dev.20 → 1.0.1-dev.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/{core-CyilRD7s.js → core-CClhT8WR.js} +389 -400
  2. package/dist/core-cPQWYD4K.cjs +1 -0
  3. package/dist/debug/api/Raph.cjs +1 -1
  4. package/dist/debug/api/Raph.js +46 -47
  5. package/dist/debug/api/RaphFacadeSession.cjs +1 -1
  6. package/dist/debug/api/RaphFacadeSession.js +85 -89
  7. package/dist/debug/api/RaphReactivityInstance.cjs +1 -1
  8. package/dist/debug/api/RaphReactivityInstance.js +27 -30
  9. package/dist/debug/path/DataPath.cjs +1 -1
  10. package/dist/debug/path/DataPath.js +198 -202
  11. package/dist/debug/path/PathRouter.cjs +1 -1
  12. package/dist/debug/path/PathRouter.js +44 -50
  13. package/dist/debug/path/RaphKernel.cjs +1 -1
  14. package/dist/debug/path/RaphKernel.js +257 -228
  15. package/dist/debug/path/data-path.utils.cjs +1 -1
  16. package/dist/debug/path/data-path.utils.js +41 -41
  17. package/dist/debug/path/derived/DerivedRegistry.cjs +1 -1
  18. package/dist/debug/path/derived/DerivedRegistry.js +52 -66
  19. package/dist/debug/path/derived/RaphDerivedHandle.cjs +1 -1
  20. package/dist/debug/path/derived/RaphDerivedHandle.js +19 -22
  21. package/dist/debug/path/derived/derived-collection.utils.cjs +1 -1
  22. package/dist/debug/path/derived/derived-collection.utils.js +70 -70
  23. package/dist/debug/path/meta/MetaController.cjs +1 -1
  24. package/dist/debug/path/meta/MetaController.js +57 -65
  25. package/dist/debug/path/meta/RaphMeta.cjs +1 -1
  26. package/dist/debug/path/meta/RaphMeta.js +26 -32
  27. package/dist/debug/path/meta/RaphMetaStore.cjs +1 -1
  28. package/dist/debug/path/meta/RaphMetaStore.js +24 -30
  29. package/dist/debug/path/storage/AdapterPathStore.cjs +1 -1
  30. package/dist/debug/path/storage/AdapterPathStore.js +49 -54
  31. package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -1
  32. package/dist/debug/path/storage/DefaultDataAdapter.js +46 -56
  33. package/dist/debug/path/storage/PathEventHub.cjs +1 -1
  34. package/dist/debug/path/storage/PathEventHub.js +74 -61
  35. package/dist/debug/path/storage/PathStore.cjs +1 -1
  36. package/dist/debug/path/storage/PathStore.js +89 -99
  37. package/dist/debug/path/storage/createDataDraft.cjs +1 -1
  38. package/dist/debug/path/storage/createDataDraft.js +24 -28
  39. package/dist/debug/reactivity/disposal.cjs +1 -0
  40. package/dist/debug/reactivity/disposal.js +32 -0
  41. package/dist/debug/reactivity/engine.cjs +1 -1
  42. package/dist/debug/reactivity/engine.js +787 -392
  43. package/dist/debug/reactivity/reactive-object.cjs +1 -1
  44. package/dist/debug/reactivity/reactive-object.js +81 -96
  45. package/dist/debug/reactivity/scope.cjs +1 -1
  46. package/dist/debug/reactivity/scope.js +221 -117
  47. package/dist/debug/reactivity/watch.cjs +1 -1
  48. package/dist/debug/reactivity/watch.js +1 -1
  49. package/dist/debug/runtime/RaphRuntime.cjs +1 -1
  50. package/dist/debug/runtime/RaphRuntime.js +764 -411
  51. package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -1
  52. package/dist/debug/runtime/diagnostics/RaphDebug.js +90 -100
  53. package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -1
  54. package/dist/debug/runtime/ownership/RaphEffectScope.js +215 -82
  55. package/dist/debug/runtime/ownership/RaphNode.cjs +1 -1
  56. package/dist/debug/runtime/ownership/RaphNode.js +595 -136
  57. package/dist/debug/runtime/ownership/RaphScope.cjs +1 -1
  58. package/dist/debug/runtime/ownership/RaphScope.js +203 -68
  59. package/dist/debug/runtime/phases/RaphFrameLoop.cjs +1 -1
  60. package/dist/debug/runtime/phases/RaphFrameLoop.js +13 -17
  61. package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -1
  62. package/dist/debug/runtime/phases/RaphPhasePipeline.js +618 -357
  63. package/dist/debug/runtime/phases/RaphPhaseTaskRecord.cjs +1 -0
  64. package/dist/debug/runtime/phases/RaphPhaseTaskRecord.js +176 -0
  65. package/dist/debug/runtime/phases/RaphPhaseWatch.cjs +1 -0
  66. package/dist/debug/runtime/phases/RaphPhaseWatch.js +20 -0
  67. package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -1
  68. package/dist/debug/runtime/reactivity/PathHandle.js +50 -60
  69. package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -1
  70. package/dist/debug/runtime/reactivity/RaphMetaSource.js +28 -32
  71. package/dist/debug/runtime/reactivity/RaphSelector.cjs +1 -0
  72. package/dist/debug/runtime/reactivity/RaphSelector.js +503 -0
  73. package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -1
  74. package/dist/debug/runtime/reactivity/RaphWorkGraph.js +541 -379
  75. package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -1
  76. package/dist/debug/runtime/reactivity/RuntimeReactivity.js +484 -90
  77. package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -1
  78. package/dist/debug/runtime/reactivity/RuntimeWatch.js +33 -44
  79. package/dist/debug/runtime/reactivity/disposal-sweep.utils.cjs +1 -0
  80. package/dist/debug/runtime/reactivity/disposal-sweep.utils.js +42 -0
  81. package/dist/entrypoints/runtime.d.ts +2 -1
  82. package/dist/machine-testing.cjs +1 -1
  83. package/dist/machine-testing.js +1 -1
  84. package/dist/machine.cjs +1 -1
  85. package/dist/machine.js +216 -231
  86. package/dist/path/RaphKernel.d.ts +24 -0
  87. package/dist/path/storage/PathEventHub.d.ts +14 -0
  88. package/dist/path/storage/PathStore.d.ts +4 -4
  89. package/dist/reactivity/disposal.d.ts +14 -0
  90. package/dist/reactivity/engine.d.ts +177 -4
  91. package/dist/reactivity/scope.d.ts +108 -30
  92. package/dist/runtime/RaphRuntime.d.ts +236 -17
  93. package/dist/runtime/ownership/RaphEffectScope.d.ts +70 -1
  94. package/dist/runtime/ownership/RaphNode.d.ts +276 -6
  95. package/dist/runtime/ownership/RaphScope.d.ts +144 -14
  96. package/dist/runtime/phases/RaphPhasePipeline.d.ts +202 -28
  97. package/dist/runtime/phases/RaphPhaseTaskRecord.d.ts +195 -0
  98. package/dist/runtime/phases/RaphPhaseWatch.d.ts +22 -0
  99. package/dist/runtime/phases/phase.types.d.ts +83 -4
  100. package/dist/runtime/reactivity/RaphSelector.d.ts +338 -0
  101. package/dist/runtime/reactivity/RaphWorkGraph.d.ts +163 -25
  102. package/dist/runtime/reactivity/RuntimeReactivity.d.ts +258 -10
  103. package/dist/runtime/reactivity/RuntimeWatch.d.ts +8 -8
  104. package/dist/runtime/reactivity/disposal-sweep.utils.d.ts +19 -0
  105. package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +48 -3
  106. package/package.json +10 -2
  107. package/dist/core-ugchZNqC.cjs +0 -1
@@ -1,50 +1,158 @@
1
- var f = Object.defineProperty;
2
- var l = (r, e, s) => e in r ? f(r, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : r[e] = s;
3
- var o = (r, e, s) => l(r, typeof e != "symbol" ? e + "" : e, s);
4
- import { RaphDisposedError as u } from "../errors.js";
1
+ import { RaphDisposedError as c } from "../errors.js";
2
+ const u = 16;
5
3
  class _ {
6
- constructor(e, s = null) {
7
- o(this, "_registrations");
8
- o(this, "_children");
9
- o(this, "_selfPaused", !1);
10
- o(this, "_ancestorPauses", 0);
11
- o(this, "_disposed", !1);
12
- o(this, "_releaseOwner");
13
- o(this, "_parent");
14
- if (this._owner = e, e._assertAlive(), (s == null ? void 0 : s.disposed) === !0)
15
- throw new u("[Raph] Parent effect scope is disposed.");
16
- if (s !== null && s._owner.runtime !== e.runtime)
4
+ constructor(s, e = null) {
5
+ if (this._owner = s, s._assertAlive(), e?.disposed === !0)
6
+ throw new c("[Raph] Parent effect scope is disposed.");
7
+ if (e !== null && e._owner.runtime !== s.runtime)
17
8
  throw new TypeError("[Raph] Parent effect scope belongs to another runtime.");
18
- this._parent = s, s == null || s._addChild(this), this._ancestorPauses = (s == null ? void 0 : s.paused) === !0 ? 1 : 0, this._releaseOwner = e.own(() => this.dispose());
9
+ this._parent = e, e?._addChild(this), this._ancestorPauses = e?.paused === !0 ? 1 : 0, this._releaseOwner = s.own(() => this.dispose());
19
10
  }
11
+ _registrations;
12
+ // Число регистраций, при котором группа в следующий раз забывает остановленные.
13
+ _pruneAt = u;
14
+ _children;
15
+ _selfPaused = !1;
16
+ _ancestorPauses = 0;
17
+ _disposed = !1;
18
+ _releaseOwner;
19
+ _parent;
20
20
  get paused() {
21
21
  return this._selfPaused || this._ancestorPauses !== 0;
22
22
  }
23
23
  get disposed() {
24
24
  return this._disposed;
25
25
  }
26
- fork(e) {
27
- return this._assertAlive(), new _(e, this);
26
+ fork(s) {
27
+ return this._assertAlive(), new _(s, this);
28
28
  }
29
- effect(e, s, t) {
29
+ effect(s, e, t) {
30
30
  return this._assertAlive(), this._add(this._owner.runtime._effectRegistration(
31
31
  this._owner,
32
- e,
33
32
  s,
33
+ e,
34
34
  t,
35
35
  this.paused
36
36
  ));
37
37
  }
38
- watch(e, s, t, i) {
39
- return this._assertAlive(), this._add(this._owner.runtime._watchRegistration(
38
+ /**
39
+ * Регистрирует в этой группе phase effect без task и без disposer: тело
40
+ * вызывается без аргументов, а binding живёт до освобождения группы или её
41
+ * владельца. Pause и resume группы действуют на него так же, как на effect,
42
+ * зарегистрированный через `effect()`.
43
+ *
44
+ * Binding, зарегистрированный внутри тела другого effect, останавливает ещё и
45
+ * перезапуск этого effect. Остановленный binding больше не исполняется и не
46
+ * реагирует на pause и resume; группа забывает его не сразу, а когда число её
47
+ * регистраций удваивается, поэтому остановленных регистраций в группе не
48
+ * больше, чем действующих, либо меньше `PRUNE_FLOOR`.
49
+ */
50
+ bindEffect(s, e, t) {
51
+ this._assertAlive(), this._track(this._owner.runtime._effectRegistration(
40
52
  this._owner,
53
+ s,
41
54
  e,
55
+ t,
56
+ this.paused,
57
+ !0
58
+ ));
59
+ }
60
+ /**
61
+ * Регистрирует в этой группе регистраций группу из `count` phase effects на
62
+ * одном binding, как `owner.effectGroup()`: без task и без disposer, с
63
+ * отдельным набором зависимостей у каждого slot и с запуском slots через
64
+ * `start()` возвращённой группы. Pause и resume действуют на все slots
65
+ * сразу; slots, запущенные или изменившиеся за время pause, исполняются
66
+ * одной доставкой после resume. Binding живёт до освобождения этой группы
67
+ * регистраций или её владельца.
68
+ *
69
+ * Pause изнутри тела slot останавливает доставку: оставшиеся slots
70
+ * исполняются после resume, и причины прерванной доставки приходят в
71
+ * `causes` следующей целиком, вместе с причинами уже исполненных slots.
72
+ *
73
+ * Освобождение отличается от отдельных bindings этой же группы регистраций:
74
+ * slots останавливаются в порядке, обратном порядку номеров, а не в порядке
75
+ * регистрации, и несколько сбоев их cleanup приходят одним вложенным
76
+ * `AggregateError` с сообщением `[Raph] Effect group disposal failed.`.
77
+ *
78
+ * @typeParam Context — значение, которое получает тело каждого slot.
79
+ * @param phase Имя объявленной phase.
80
+ * @param count Число slots: целое от 1 до 4294967293, иначе `RangeError`.
81
+ * @param runSlot Тело slot: получает запуск с `context` и номером slot.
82
+ * @param context Значение, которое группа передаёт телу каждого slot.
83
+ * @param options `priority` task группы, как у `effect()`.
84
+ */
85
+ effectGroup(s, e, t, r, i) {
86
+ this._assertAlive();
87
+ const o = this._owner.runtime._effectGroupRegistration(
88
+ this._owner,
42
89
  s,
90
+ e,
43
91
  t,
92
+ r,
44
93
  i,
45
94
  this.paused
95
+ );
96
+ return this._track(o), o;
97
+ }
98
+ watch(s, e, t, r) {
99
+ return this._assertAlive(), this._add(this._owner.runtime._watchRegistration(
100
+ this._owner,
101
+ s,
102
+ e,
103
+ t,
104
+ r,
105
+ this.paused
46
106
  ));
47
107
  }
108
+ /**
109
+ * Внутренний путь renderer сохраняет pause ancestry и late-disposal tracking.
110
+ * Возвращаемый disposer renderer не использует; регистрация остаётся у scope.
111
+ * @internal
112
+ */
113
+ _registerEffect(s, e, t, r, i, o) {
114
+ this._assertAlive();
115
+ const h = this._owner.runtime._effectRegistration(
116
+ this._owner,
117
+ s,
118
+ e,
119
+ t,
120
+ this.paused,
121
+ r,
122
+ i,
123
+ o
124
+ );
125
+ o?.() || this._track(h);
126
+ }
127
+ /** @internal */
128
+ _registerWatch(s, e, t, r, i, o) {
129
+ this._assertAlive();
130
+ const h = this._owner.runtime._watchRegistration(
131
+ this._owner,
132
+ s,
133
+ e,
134
+ t,
135
+ r,
136
+ this.paused,
137
+ i,
138
+ o
139
+ );
140
+ o?.() || this._track(h);
141
+ }
142
+ /** @internal */
143
+ _registerEffectGroup(s, e, t, r, i) {
144
+ this._assertAlive();
145
+ const o = this._owner.runtime._effectGroupRegistration(
146
+ this._owner,
147
+ s,
148
+ e,
149
+ t,
150
+ r,
151
+ i,
152
+ this.paused
153
+ );
154
+ return this._track(o), o;
155
+ }
48
156
  pause() {
49
157
  this._assertAlive(), this._owner.runtime._runPhaseTransition(() => this._pause());
50
158
  }
@@ -54,117 +162,142 @@ class _ {
54
162
  _pause() {
55
163
  if (this._selfPaused)
56
164
  return;
57
- const e = this.paused;
58
- if (this._selfPaused = !0, e)
165
+ const s = this.paused;
166
+ if (this._selfPaused = !0, s)
59
167
  return;
60
- const s = [];
168
+ const e = [];
61
169
  for (const t of this._registrations ?? [])
62
170
  try {
63
171
  t.registration.pause();
64
- } catch (i) {
65
- s.push(i);
172
+ } catch (r) {
173
+ e.push(r);
66
174
  }
67
175
  for (const t of this._children ?? [])
68
176
  try {
69
177
  t._changeAncestorPause(1);
70
- } catch (i) {
71
- s.push(i);
178
+ } catch (r) {
179
+ e.push(r);
72
180
  }
73
- n(s, "[Raph] Pausable effect scope pause failed.");
181
+ n(e, "[Raph] Pausable effect scope pause failed.");
74
182
  }
75
183
  _resume() {
76
184
  if (!this._selfPaused || (this._selfPaused = !1, this.paused))
77
185
  return;
78
- const e = [];
79
- for (const s of this._registrations ?? [])
186
+ const s = [];
187
+ for (const e of this._registrations ?? [])
80
188
  try {
81
- s.registration.resume();
189
+ e.registration.resume();
82
190
  } catch (t) {
83
- e.push(t);
191
+ s.push(t);
84
192
  }
85
- for (const s of this._children ?? [])
193
+ for (const e of this._children ?? [])
86
194
  try {
87
- s._changeAncestorPause(-1);
195
+ e._changeAncestorPause(-1);
88
196
  } catch (t) {
89
- e.push(t);
197
+ s.push(t);
90
198
  }
91
- n(e, "[Raph] Pausable effect scope resume failed.");
199
+ n(s, "[Raph] Pausable effect scope resume failed.");
92
200
  }
93
201
  dispose() {
94
- var t, i, h, d;
95
202
  if (this._disposed)
96
203
  return;
97
204
  this._disposed = !0;
98
- const e = this._owner.disposed, s = [];
99
- for (const a of [...this._children ?? []])
205
+ const s = this._owner.disposed, e = [];
206
+ for (const t of [...this._children ?? []])
100
207
  try {
101
- a.dispose();
102
- } catch (c) {
103
- s.push(c);
208
+ t.dispose();
209
+ } catch (r) {
210
+ e.push(r);
104
211
  }
105
- (t = this._children) == null || t.clear(), this._children = void 0;
106
- for (const a of this._registrations ?? [])
107
- if (a.active = !1, !e)
212
+ this._children?.clear(), this._children = void 0;
213
+ for (const t of this._registrations ?? [])
214
+ if (t.active = !1, !s)
108
215
  try {
109
- a.registration.dispose();
110
- } catch (c) {
111
- s.push(c);
216
+ t.registration.dispose();
217
+ } catch (r) {
218
+ e.push(r);
112
219
  }
113
- if ((i = this._registrations) == null || i.clear(), this._registrations = void 0, (d = (h = this._parent) == null ? void 0 : h._children) == null || d.delete(this), !e)
220
+ if (this._registrations?.clear(), this._registrations = void 0, this._parent?._children?.delete(this), !s)
114
221
  try {
115
222
  this._releaseOwner();
116
- } catch (a) {
117
- s.push(a);
223
+ } catch (t) {
224
+ e.push(t);
118
225
  }
119
- n(s, "[Raph] Pausable effect scope disposal failed.");
226
+ n(e, "[Raph] Pausable effect scope disposal failed.");
120
227
  }
121
- _add(e) {
122
- if (this._disposed || this._owner.disposed)
123
- return e.dispose(), p;
124
- const s = { active: !0, registration: e };
125
- return (this._registrations ?? (this._registrations = /* @__PURE__ */ new Set())).add(s), () => {
126
- var t;
127
- s.active && (s.active = !1, (t = this._registrations) == null || t.delete(s), e.dispose());
228
+ _add(s) {
229
+ const e = this._track(s);
230
+ return e === void 0 ? d : () => {
231
+ e.active && (e.active = !1, this._registrations?.delete(e), e.registration.dispose());
128
232
  };
129
233
  }
234
+ /**
235
+ * Вносит регистрацию в группу и возвращает её элемент либо `undefined`,
236
+ * когда группа уже освобождена. Disposer здесь не создаётся: его строит
237
+ * только `_add()`, поэтому `bindEffect()` обходится без closure.
238
+ */
239
+ _track(s) {
240
+ if (this._disposed || this._owner.disposed) {
241
+ s.dispose();
242
+ return;
243
+ }
244
+ const e = { active: !0, registration: s }, t = this._registrations ??= /* @__PURE__ */ new Set();
245
+ return t.add(e), t.size >= this._pruneAt && this._prune(t), e;
246
+ }
247
+ /**
248
+ * Забывает регистрации, которые уже остановлены не через disposer группы:
249
+ * binding, вложенный в тело другого effect, останавливает engine при
250
+ * перезапуске этого effect, а у `bindEffect()` нет disposer, который убрал бы
251
+ * его отсюда. Без этого группа держала бы тело каждого такого binding до
252
+ * собственного освобождения.
253
+ *
254
+ * Проход выполняется, когда число регистраций достигает порога, и ставит
255
+ * следующий порог вдвое выше числа оставшихся: цена регистрации остаётся
256
+ * постоянной в среднем.
257
+ */
258
+ _prune(s) {
259
+ for (const e of s)
260
+ e.registration.active || (e.active = !1, s.delete(e));
261
+ this._pruneAt = Math.max(u, s.size * 2);
262
+ }
130
263
  _assertAlive() {
131
264
  if (this._disposed || this._owner.disposed)
132
- throw new u("[Raph] Pausable effect scope is disposed.");
265
+ throw new c("[Raph] Pausable effect scope is disposed.");
133
266
  }
134
- _addChild(e) {
135
- (this._children ?? (this._children = /* @__PURE__ */ new Set())).add(e);
267
+ _addChild(s) {
268
+ (this._children ??= /* @__PURE__ */ new Set()).add(s);
136
269
  }
137
- _changeAncestorPause(e) {
270
+ _changeAncestorPause(s) {
138
271
  if (this._disposed)
139
272
  return;
140
- const s = this.paused;
141
- if (this._ancestorPauses += e, this._ancestorPauses < 0)
273
+ const e = this.paused;
274
+ if (this._ancestorPauses += s, this._ancestorPauses < 0)
142
275
  throw this._ancestorPauses = 0, new Error("[Raph] Effect scope ancestor pause state is unbalanced.");
143
- if (s === this.paused)
276
+ if (e === this.paused)
144
277
  return;
145
278
  const t = [];
146
- for (const i of this._registrations ?? [])
279
+ for (const r of this._registrations ?? [])
147
280
  try {
148
- this.paused ? i.registration.pause() : i.registration.resume();
149
- } catch (h) {
150
- t.push(h);
281
+ this.paused ? r.registration.pause() : r.registration.resume();
282
+ } catch (i) {
283
+ t.push(i);
151
284
  }
152
- for (const i of this._children ?? [])
285
+ for (const r of this._children ?? [])
153
286
  try {
154
- i._changeAncestorPause(e);
155
- } catch (h) {
156
- t.push(h);
287
+ r._changeAncestorPause(s);
288
+ } catch (i) {
289
+ t.push(i);
157
290
  }
158
291
  n(t, "[Raph] Pausable effect scope ancestor transition failed.");
159
292
  }
160
293
  }
161
- function n(r, e) {
162
- if (r.length === 1)
163
- throw r[0];
164
- if (r.length > 1)
165
- throw new AggregateError(r, e);
294
+ function n(a, s) {
295
+ if (a.length === 1)
296
+ throw a[0];
297
+ if (a.length > 1)
298
+ throw new AggregateError(a, s);
166
299
  }
167
- function p() {
300
+ function d() {
168
301
  }
169
302
  export {
170
303
  _ as RaphEffectScope
@@ -1 +1 @@
1
- "use strict";var b=Object.defineProperty;var y=(o,h,e)=>h in o?b(o,h,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[h]=e;var l=(o,h,e)=>y(o,typeof h!="symbol"?h+"":h,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../errors.cjs"),w=require("./RaphScope.cjs"),v=require("./throwDisposalErrors.cjs");let g=0;const _=Symbol("RaphProvisionalNode");class c extends w.RaphScope{constructor(e,t={},r,i){const s=r??(e instanceof c?e.runtime:e??void 0);if(s===void 0)throw new Error("[RaphNode] A root node requires an explicit runtime.");const n=e instanceof c?e:(e==null?void 0:e.root)??null;if(n!==null&&n.runtime!==s)throw new a.RaphCrossRuntimeError("[Raph] Parent belongs to another runtime.");n==null||n._assertAlive();const d=t.priority??0;p(d);super(t.id??`node-${g++}`,s);l(this,"priority");l(this,"_parent");l(this,"_children",[]);l(this,"_published");l(this,"api");l(this,"meta");l(this,"type");l(this,"_subtreeSourceIdentity",Object.freeze({}));this.priority=d,this._parent=n,this.meta={...t.meta},this.type=t.type??"default",this.api=Object.freeze({});const f=i===_;if(this._published=n===null||!f&&n._published,n!==null){const m=n._children.length;if(n._children.push(this),!this._published)return;s._notifyNodeStructure(this,{node:this,newIndex:m,newParent:n},[],u(this)),this._assertAlive()}}get node(){return this}get parent(){return this._parent}get children(){return this._children}addChild(e){if(this._assertAlive(),e._assertAlive(),e.runtime!==this.runtime)throw new a.RaphCrossRuntimeError("[Raph] Child belongs to another runtime.");if(this===e)throw new Error("[Raph] A node cannot become its own ancestor.");if(!e._published||!this._published)throw new Error("[Raph] A provisional node cannot be reparented before setup commits.");for(let t=this;t!==null;t=t.parent)if(t===e)throw new Error("[Raph] A node cannot become its own ancestor.");return e.parent===this?!0:this.runtime._runNodeMutation(()=>{this.runtime._assertNodeReparentAllowed(e,this);const t=u(e),r=e._parent,i=r==null?void 0:r._children.indexOf(e);r!==null&&i!==void 0&&i>=0&&r._children.splice(i,1),e._parent=this;const s=this._children.length;return this._children.push(e),this.runtime._notifyNodeStructure(e,{node:e,...r===null?{}:{oldParent:r},...i===void 0||i<0?{}:{oldIndex:i},newParent:this,newIndex:s},t,u(e)),!0})}reorderChildren(e){if(this._assertAlive(),e.length!==this._children.length||new Set(e).size!==e.length)throw new Error("[Raph] Child order must contain every direct child exactly once.");for(const t of e)if(t._assertAlive(),t._parent!==this)throw new Error("[Raph] Child order can contain only direct children of the node.");this.runtime._runNodeMutation(()=>{const t=new Map(this._children.map((r,i)=>[r,i]));this._children.splice(0,this._children.length,...e);for(let r=0;r<e.length;r++){const i=e[r],s=t.get(i);if(s===r)continue;const n=u(i);this.runtime._notifyNodeStructure(i,{node:i,oldParent:this,newParent:this,oldIndex:s,newIndex:r},n,n)}})}options(e){this._assertAlive(),e.meta!==void 0&&(this.meta={...e.meta}),e.priority!==void 0&&(p(e.priority),this.priority=e.priority),e.type!==void 0&&(this.type=e.type),this.touch(Object.freeze({options:Object.freeze({...e})}))}touch(e){this._assertAlive(),this.runtime._runNodeMutation(()=>this.runtime._notifyNodeTouch(this,e))}remove(){this.dispose()}dispose(){if(this._disposed||this._disposing)return;this._disposing=!0,this.runtime._beginOwnerDisposal();const e=[];try{for(const s of[...this._children])try{s.dispose()}catch(n){e.push(n)}this._children.length=0;const t=this._parent,r=u(this),i=t==null?void 0:t._children.indexOf(this);if(t!==null&&i!==void 0&&i>=0&&t._children.splice(i,1),this._parent=null,this._published)try{this.runtime._notifyNodeStructure(this,{node:this,...t===null?{}:{oldParent:t},...i===void 0||i<0?{}:{oldIndex:i}},r,[])}catch(s){e.push(s)}try{super.dispose()}catch(s){e.push(s)}this._published=!1;try{this.runtime._releaseNode(this)}catch(s){e.push(s)}}finally{try{this.runtime._endOwnerDisposal()}catch(t){e.push(t)}}v.throwDisposalErrors(e,`[Raph] Node "${this.id}" disposal failed.`)}_setApi(e){const t=typeof e=="object"&&e!==null?Object.freeze(e):e;Object.defineProperty(this,"api",{configurable:!1,enumerable:!0,value:t,writable:!1})}_publishCreation(){if(this._published)return;const e=this._parent;if(e===null||!e._published)return;this._published=!0;const t=e._children.indexOf(this);try{this.runtime._notifyNodeStructure(this,{node:this,newIndex:t,newParent:e},[],u(this));for(const r of this._children)r._publishCreation()}catch(r){throw this._published=!1,r}}_isPublished(){return this._published}}function N(o,h,e){return new c(o,h,e,_)}function u(o){const h=[];for(let e=o;e!==null;e=e.parent)h.push(e);return h}function p(o){if(!Number.isFinite(o))throw new TypeError("[Raph] Node priority must be finite.")}exports.RaphNode=c;exports.createProvisionalNode=N;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../../reactivity/disposal.cjs"),b=require("../errors.cjs"),S=require("../reactivity/RaphWorkGraph.cjs"),w=require("./RaphScope.cjs");let x=0;const C=Symbol("RaphProvisionalNode"),A=Object.freeze({}),O="[Raph] Child order must contain every direct child exactly once.",p="[Raph] Child order can contain only direct children of the node.";let f,c;class u extends w.RaphScope{#i;constructor(i,t={},e,r){const s=e??(i instanceof u?i.runtime:i??void 0);if(s===void 0)throw new Error("[RaphNode] A root node requires an explicit runtime.");const n=i instanceof u?i:i?.root??null;if(n!==null&&n.runtime!==s)throw new b.RaphCrossRuntimeError("[Raph] Parent belongs to another runtime.");const l=t.priority??0,h=t.id,a=t.meta,y=a===void 0?void 0:{...a},g=t.type??"default";n?._assertAlive(),v(l),super(h??x++,s);const m=r===C;if(this.priority=l,this._parent=n,this._prevSibling=null,this._nextSibling=null,this._firstChild=null,this._lastChild=null,this._childCount=0,this._childArray=void 0,this._published=n===null||!m&&n._published,this.#i=A,new.target!==u&&Object.defineProperty(this,"api",{configurable:!0,enumerable:!0,value:this.#i,writable:!0}),this._meta=y,this.type=g,this._subtreeIdentity=void 0,n!==null){if(n._appendChild(this),!this._published)return;s._hasNodeStructureDemand(this)?s._notifyNodeStructure(this,{node:this,newIndex:n._childCount-1,newParent:n},[],d(this)):s._touchMutationBoundary(),this._assertAlive()}else s._addTopOwner(this)}get id(){const i=this._id;return typeof i=="string"?i:this._id=`node-${i}`}get meta(){return this._meta??={}}set meta(i){this._meta=i}get api(){return this.#i}get _subtreeSourceIdentity(){return this._subtreeIdentity??=Object.freeze({})}get node(){return this}get parent(){return this._parent}get children(){return this._childArray??this._materializeChildren()}addChild(i){if(this._assertAlive(),i._assertAlive(),i.runtime!==this.runtime)throw new b.RaphCrossRuntimeError("[Raph] Child belongs to another runtime.");if(this===i)throw new Error("[Raph] A node cannot become its own ancestor.");if(!i._published||!this._published)throw new Error("[Raph] A provisional node cannot be reparented before setup commits.");for(let t=this;t!==null;t=t.parent)if(t===i)throw new Error("[Raph] A node cannot become its own ancestor.");return i.parent===this?!0:this.runtime._runNodeMutation(()=>{const t=this.runtime;t._assertNodeReparentAllowed(i,this);const e=i._parent;if(!t._hasNodeStructureDemand(i))return e!==null&&i._unlinkFrom(e,-1),i._parent=this,this._appendChild(i),e===null&&t._removeTopOwner(i),!0;const r=d(i),s=e===null?-1:i._indexIn(e);e!==null&&i._unlinkFrom(e,s),i._parent=this;const n=this._childCount;return this._appendChild(i),e===null&&t._removeTopOwner(i),t._notifyNodeStructure(i,{node:i,...e===null?{}:{oldParent:e},...s<0?{}:{oldIndex:s},newParent:this,newIndex:n},r,d(i)),!0})}reorderChildren(i){this._assertAlive(),this._applyChildOrder(i)||this._rejectChildOrder(i)}moveChild(i,t){if(this._assertAlive(),i._assertAlive(),t!==null&&t._assertAlive(),i._parent!==this||t!==null&&t._parent!==this)throw new Error(p);const e=this.runtime;if(i===t||i._nextSibling===t){e._touchMutationBoundary();return}const r=e._hasNodeSubscribers()?this._indexChildren():void 0;if(this._relinkBefore(i,t),r!==void 0){this._publishChildOrder(r);return}this._childArray=void 0,e._touchMutationBoundary()}_swapChildren(i,t){if(this._assertAlive(),i._assertAlive(),t._assertAlive(),i._parent!==this||t._parent!==this)throw new Error(p);const e=this.runtime;if(i===t){e._touchMutationBoundary();return}const r=e._hasNodeSubscribers()?this._indexChildren():void 0,s=i._nextSibling,n=t._nextSibling;if(s===t?this._relinkBefore(t,i):n===i?this._relinkBefore(i,t):(this._relinkBefore(i,n),this._relinkBefore(t,s)),r!==void 0){this._publishChildOrder(r);return}this._childArray=void 0,e._touchMutationBoundary()}_disposeChildren(i,t=0,e=i===void 0?0:i.length){let r=i;if(r===void 0&&(r=this._childArray??this._collectChildren(),e=r.length),t>=e)return;const s=this._childArray;s!==void 0&&(s===r||this._firstChild===r[t].node)&&(this._childArray=void 0);const n=this.runtime;let l;n._beginOwnerDisposal();for(let h=t;h<e;h++)try{r[h].node.dispose()}catch(a){(l??=[]).push(a)}try{n._endOwnerDisposal()}catch(h){(l??=[]).push(h)}return l}options(i){this._assertAlive(),i.meta!==void 0&&(this._meta={...i.meta}),i.priority!==void 0&&(v(i.priority),this.priority=i.priority),i.type!==void 0&&(this.type=i.type),this.touch(Object.freeze({options:Object.freeze({...i})}))}touch(i){this._assertAlive(),this.runtime._runNodeMutation(()=>this.runtime._notifyNodeTouch(this,i))}remove(){this.dispose()}dispose(){o.throwDisposalFailure(c.call(this))}_disposeForOwner(){try{const i=this.dispose;if(i===f)return c.call(this);i.call(this);return}catch(i){return o.unroutedDisposalFailure(i)}}_disposeWithOutcome(){if(this._disposed||this._disposing)return;this._disposing=!0;const i=this.runtime;i._beginOwnerDisposal(this);let t;try{if(this._firstChild!==null){const r=this._takeChildSnapshot();for(let s=0;s<r.length;s++){const n=r[s];try{const l=n.dispose;if(l===f){const h=c.call(n);h!==void 0&&(t??=[]).push(h)}else l.call(n)}catch(l){(t??=[]).push(o.unroutedDisposalFailure(l))}}this._resetChildList(r)}const e=this._parent;if(this._published&&i._hasNodeStructureDemand(this)){const r=d(this),s=e===null?-1:this._indexIn(e);e!==null&&(this._unlinkFrom(e,s),this._parent=null);try{i._notifyNodeStructure(this,{node:this,...e===null?{}:{oldParent:e},...s<0?{}:{oldIndex:s}},r,[])}catch(n){(t??=[]).push(o.unroutedDisposalFailure(n))}}else if(e!==null&&(this._unlinkFrom(e,-1),this._parent=null),this._published)try{i._touchMutationBoundary()}catch(r){(t??=[]).push(o.unroutedDisposalFailure(r))}try{const r=super._disposeScopeForOwner(super.dispose);r!==void 0&&(t??=[]).push(r)}catch(r){(t??=[]).push(o.unroutedDisposalFailure(r))}e===null&&i._removeTopOwner(this),this._published=!1;try{i._releaseNode(this)}catch(r){(t??=[]).push(o.unroutedDisposalFailure(r))}}finally{try{i._endOwnerDisposal()}catch(e){(t??=[]).push(o.unroutedDisposalFailure(e))}}if(t!==void 0)return o.combineDisposalFailures(t,`[Raph] Node "${this.id}" disposal failed.`)}_setApi(i){this.#i=typeof i=="object"&&i!==null&&!(i instanceof S.RaphProducer)?Object.freeze(i):i,Object.hasOwn(this,"api")&&Object.defineProperty(this,"api",{configurable:!1,enumerable:!0,value:this.#i,writable:!1})}_publishCreation(){if(this._published)return;const i=this._parent;if(!(i===null||!i._published)){this._published=!0;try{const t=this.runtime;t._hasNodeStructureDemand(this)?t._notifyNodeStructure(this,{node:this,newIndex:this._indexIn(i),newParent:i},[],d(this)):t._touchMutationBoundary();for(let e=this._firstChild;e!==null;e=e._nextSibling)e._publishCreation()}catch(t){throw this._published=!1,t}}}_isPublished(){return this._published}_isLinked(){const i=this._parent;return i!==null&&(this._prevSibling!==null||i._firstChild===this)}_collectDescendants(i){let t=this;for(;;){let e=t._firstChild;for(;e===null;){if(t===this)return;e=t._nextSibling,e===null&&(t=t._parent)}t=e,i.push(t)}}_countSubtree(i){let t=this;for(;;){i.resources+=t._debugResourceCount(),i.sources+=t._debugSourceCount();let e=t._firstChild;for(;e===null;){if(t===this)return;e=t._nextSibling,e===null&&(t=t._parent)}t=e}}_findNode(i){let t=this;for(;;){if(t.id===i)return t;let e=t._lastChild;for(;e===null;){if(t===this)return;e=t._prevSibling,e===null&&(t=t._parent)}t=e}}_applyChildOrder(i){const t=i.length;if(t!==this._childCount)return!1;const e=[];for(let l=0;l<t;l++)e.push(i[l]);if(t!==this._childCount)return!1;const r=this.runtime,s=r._hasNodeSubscribers()?this._indexChildren():void 0;if(!this._relinkChildren(e))return!1;const n=this._childArray;if(n!==void 0&&n!==i)for(let l=0;l<t;l++)n[l]=e[l];return s===void 0?r._touchMutationBoundary():this._notifyChildOrder(e,s),!0}_relinkChildren(i){for(let n=this._firstChild;n!==null;n=n._nextSibling)n._prevSibling=this;const t=i.length;let e=null,r=0;try{for(;r<t;r++){const n=i[r];if(n?._parent!==this||n._prevSibling!==this||n._disposing)break;n._prevSibling=e,e=n}}finally{if(r!==t){let n=null;for(let l=this._firstChild;l!==null;l=l._nextSibling)l._prevSibling=n,n=l}}if(r!==t)return!1;let s=null;for(let n=e;n!==null;n=n._prevSibling)n._nextSibling=s,s=n;return this._firstChild=s,this._lastChild=e,!0}_rejectChildOrder(i){if(i.length===this._childCount&&new Set(i).size===i.length){for(const t of i)if(t._assertAlive(),t._parent!==this)throw new Error(p)}throw new Error(O)}_indexChildren(){const i=new Map;let t=0;for(let e=this._firstChild;e!==null;e=e._nextSibling)i.set(e,t++);return i}_publishChildOrder(i){let t=this._childArray;if(t===void 0)t=this._materializeChildren();else{let e=0;for(let r=this._firstChild;r!==null;r=r._nextSibling)t[e++]=r}this._notifyChildOrder(t,i)}_notifyChildOrder(i,t){const e=this.runtime;e._runNodeMutation(()=>{for(let r=0;r<i.length;r++){const s=i[r],n=t.get(s);if(n===r)continue;const l=d(s);e._notifyNodeStructure(s,{node:s,oldParent:this,newParent:this,oldIndex:n,newIndex:r},l,l)}})}_relinkBefore(i,t){const e=i._prevSibling,r=i._nextSibling;e===null?this._firstChild=r:e._nextSibling=r,r===null?this._lastChild=e:r._prevSibling=e;const s=t===null?this._lastChild:t._prevSibling;i._prevSibling=s,i._nextSibling=t,s===null?this._firstChild=i:s._nextSibling=i,t===null?this._lastChild=i:t._prevSibling=i}_materializeChildren(){return this._childArray=this._collectChildren()}_collectChildren(){const i=[];for(let t=this._firstChild;t!==null;t=t._nextSibling)i.push(t);return i}_clearChildArray(){const i=this._childArray;i!==void 0&&(i.length=0,this._childArray=void 0)}_appendChild(i){const t=this._lastChild;i._prevSibling=t,t===null?this._firstChild=i:t._nextSibling=i,this._lastChild=i,this._childCount++;const e=this._childArray;e!==void 0&&e.push(i)}_indexIn(i){return this._prevSibling===null?i._firstChild===this?0:-1:i._lastChild===this?i._childCount-1:(i._childArray??i._materializeChildren()).indexOf(this)}_unlinkFrom(i,t){const e=this._prevSibling,r=this._nextSibling;if(e===null){if(i._firstChild!==this)return;i._firstChild=r}else e._nextSibling=r,this._prevSibling=null;r===null?i._lastChild=e:(r._prevSibling=e,this._nextSibling=null),i._childCount--;const s=i._childArray;if(s!==void 0)if(r===null)s.pop();else if(t<0&&!i._disposing&&!this.runtime._hasNodeSubscribers())i._childArray=void 0;else if(e===null)s.shift();else{const n=t>=0?t:s.indexOf(this);n>=0?s.splice(n,1):i._childArray=void 0}}_takeChildSnapshot(){const i=this._childArray;return i===void 0?this._collectChildren():(this._childArray=void 0,i)}_resetChildList(i){i.length=0,this._clearChildArray();let t=this._firstChild;for(;t!==null;){const e=t._nextSibling;t._prevSibling=null,t._nextSibling=null,t=e}this._firstChild=null,this._lastChild=null,this._childCount=0}}function N(_,i,t){return new u(_,i,t,C)}u.prototype._isNode=!0;function d(_){const i=[];for(let t=_;t!==null;t=t.parent)i.push(t);return i}function v(_){if(!Number.isFinite(_))throw new TypeError("[Raph] Node priority must be finite.")}f=u.prototype.dispose;c=u.prototype._disposeWithOutcome;exports.RaphNode=u;exports.createProvisionalNode=N;