@raphy-js/raph 1.0.0-dev.2 → 1.0.1-dev.20

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 (211) hide show
  1. package/README.md +1096 -0
  2. package/dist/api/Raph.d.ts +59 -190
  3. package/dist/api/RaphFacadeSession.d.ts +90 -0
  4. package/dist/api/RaphReactivityInstance.d.ts +72 -0
  5. package/dist/api/errors.d.ts +9 -4
  6. package/dist/api/types.d.ts +162 -17
  7. package/dist/core-CyilRD7s.js +1055 -0
  8. package/dist/core-ugchZNqC.cjs +1 -0
  9. package/dist/debug/api/Raph.cjs +1 -1
  10. package/dist/debug/api/Raph.js +368 -366
  11. package/dist/debug/api/RaphFacadeSession.cjs +1 -0
  12. package/dist/debug/api/RaphFacadeSession.js +306 -0
  13. package/dist/debug/api/RaphReactivityInstance.cjs +1 -0
  14. package/dist/debug/api/RaphReactivityInstance.js +149 -0
  15. package/dist/debug/api/errors.cjs +1 -1
  16. package/dist/debug/api/errors.js +10 -7
  17. package/dist/debug/path/DataPath.cjs +1 -0
  18. package/dist/debug/path/{data-path.js → DataPath.js} +151 -180
  19. package/dist/debug/path/PathRouter.cjs +1 -0
  20. package/dist/debug/path/{path-router.js → PathRouter.js} +1 -1
  21. package/dist/debug/path/RaphKernel.cjs +1 -1
  22. package/dist/debug/path/RaphKernel.js +258 -207
  23. package/dist/debug/path/data-path.utils.cjs +1 -0
  24. package/dist/debug/path/data-path.utils.js +56 -0
  25. package/dist/debug/path/derived/DerivedRegistry.cjs +1 -0
  26. package/dist/debug/path/{DerivedRegistry.js → derived/DerivedRegistry.js} +5 -5
  27. package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
  28. package/dist/debug/path/{derived-collection.js → derived/derived-collection.utils.js} +1 -1
  29. package/dist/debug/path/derived/derived-strategy.types.cjs +1 -0
  30. package/dist/debug/path/derived/derived-strategy.types.js +1 -0
  31. package/dist/debug/path/{MetaController.cjs → meta/MetaController.cjs} +1 -1
  32. package/dist/debug/path/{MetaController.js → meta/MetaController.js} +3 -3
  33. package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
  34. package/dist/debug/path/{RaphMetaStore.js → meta/RaphMetaStore.js} +1 -1
  35. package/dist/debug/path/meta/meta.types.cjs +1 -0
  36. package/dist/debug/path/meta/meta.types.js +1 -0
  37. package/dist/debug/path/storage/AdapterPathStore.cjs +1 -0
  38. package/dist/debug/path/{AdapterPathStore.js → storage/AdapterPathStore.js} +9 -9
  39. package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
  40. package/dist/debug/path/{data-adapter.js → storage/DefaultDataAdapter.js} +2 -2
  41. package/dist/debug/path/storage/PathEventHub.cjs +1 -0
  42. package/dist/debug/path/{PathEventHub.js → storage/PathEventHub.js} +34 -34
  43. package/dist/debug/path/storage/PathStore.cjs +1 -0
  44. package/dist/debug/path/{PathStore.js → storage/PathStore.js} +28 -28
  45. package/dist/debug/path/storage/data-adapter.types.cjs +1 -0
  46. package/dist/debug/path/storage/data-adapter.types.js +1 -0
  47. package/dist/debug/reactivity/engine.cjs +1 -1
  48. package/dist/debug/reactivity/engine.js +478 -306
  49. package/dist/debug/reactivity/reactive-object.cjs +1 -0
  50. package/dist/debug/reactivity/reactive-object.js +280 -0
  51. package/dist/debug/runtime/RaphRuntime.cjs +1 -1
  52. package/dist/debug/runtime/RaphRuntime.js +798 -519
  53. package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -0
  54. package/dist/debug/runtime/diagnostics/RaphDebug.js +297 -0
  55. package/dist/debug/runtime/errors.cjs +1 -1
  56. package/dist/debug/runtime/errors.js +6 -3
  57. package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -0
  58. package/dist/debug/runtime/ownership/RaphEffectScope.js +171 -0
  59. package/dist/debug/runtime/ownership/RaphNode.cjs +1 -0
  60. package/dist/debug/runtime/ownership/RaphNode.js +206 -0
  61. package/dist/debug/runtime/ownership/RaphScope.cjs +1 -0
  62. package/dist/debug/runtime/ownership/RaphScope.js +101 -0
  63. package/dist/debug/runtime/ownership/parent-graph.types.cjs +1 -0
  64. package/dist/debug/runtime/ownership/parent-graph.types.js +1 -0
  65. package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -0
  66. package/dist/debug/runtime/phases/RaphPhasePipeline.js +587 -0
  67. package/dist/debug/runtime/phases/orderPhaseTasks.cjs +1 -0
  68. package/dist/debug/runtime/phases/orderPhaseTasks.js +59 -0
  69. package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -0
  70. package/dist/debug/runtime/{PathHandle.js → reactivity/PathHandle.js} +75 -39
  71. package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -0
  72. package/dist/debug/runtime/reactivity/RaphMetaSource.js +112 -0
  73. package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -0
  74. package/dist/debug/runtime/reactivity/RaphWorkGraph.js +995 -0
  75. package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -0
  76. package/dist/debug/runtime/reactivity/RuntimeReactivity.js +156 -0
  77. package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -0
  78. package/dist/debug/runtime/reactivity/RuntimeWatch.js +88 -0
  79. package/dist/debug/runtime/reactivity/runtime-reactivity.types.cjs +1 -0
  80. package/dist/debug/runtime/reactivity/runtime-reactivity.types.js +1 -0
  81. package/dist/entrypoints/machine-testing.d.ts +2 -0
  82. package/dist/entrypoints/machine.d.ts +5 -0
  83. package/dist/entrypoints/path.d.ts +14 -0
  84. package/dist/entrypoints/reactivity.d.ts +1 -0
  85. package/dist/entrypoints/runtime.d.ts +17 -0
  86. package/dist/index.cjs +1 -1
  87. package/dist/index.js +46 -38
  88. package/dist/machine/compiler.d.ts +71 -0
  89. package/dist/machine/core.d.ts +50 -0
  90. package/dist/machine/persistence.d.ts +5 -0
  91. package/dist/machine/runtime.d.ts +4 -0
  92. package/dist/machine/testing.d.ts +43 -0
  93. package/dist/machine/types.d.ts +155 -0
  94. package/dist/machine-testing.cjs +1 -0
  95. package/dist/machine-testing.js +188 -0
  96. package/dist/machine.cjs +1 -0
  97. package/dist/machine.js +837 -0
  98. package/dist/main.d.ts +20 -0
  99. package/dist/path/{data-path.d.ts → DataPath.d.ts} +16 -40
  100. package/dist/path/{path-router.d.ts → PathRouter.d.ts} +1 -1
  101. package/dist/path/RaphKernel.d.ts +13 -10
  102. package/dist/path/data-path.types.d.ts +34 -0
  103. package/dist/path/data-path.utils.d.ts +9 -0
  104. package/dist/path/{DerivedRegistry.d.ts → derived/DerivedRegistry.d.ts} +2 -2
  105. package/dist/path/{RaphDerivedHandle.d.ts → derived/RaphDerivedHandle.d.ts} +3 -3
  106. package/dist/path/derived/derived-collection.types.d.ts +12 -0
  107. package/dist/path/{derived-collection.d.ts → derived/derived-collection.utils.d.ts} +3 -13
  108. package/dist/path/{derived-strategies.d.ts → derived/derived-strategy.types.d.ts} +0 -3
  109. package/dist/path/derived/derived-strategy.utils.d.ts +4 -0
  110. package/dist/path/{MetaController.d.ts → meta/MetaController.d.ts} +4 -4
  111. package/dist/path/{RaphMeta.d.ts → meta/RaphMeta.d.ts} +2 -2
  112. package/dist/path/{RaphMetaStore.d.ts → meta/RaphMetaStore.d.ts} +1 -1
  113. package/dist/path/{meta.types.d.ts → meta/meta.types.d.ts} +2 -4
  114. package/dist/path/path.types.d.ts +3 -2
  115. package/dist/path/{segment-key.d.ts → pathSegmentKey.d.ts} +1 -1
  116. package/dist/path/{AdapterPathStore.d.ts → storage/AdapterPathStore.d.ts} +4 -4
  117. package/dist/path/{data-adapter.d.ts → storage/DefaultDataAdapter.d.ts} +2 -17
  118. package/dist/path/{PathEventHub.d.ts → storage/PathEventHub.d.ts} +9 -9
  119. package/dist/path/{PathStore.d.ts → storage/PathStore.d.ts} +3 -3
  120. package/dist/path/storage/data-adapter.types.d.ts +17 -0
  121. package/dist/path.cjs +1 -1
  122. package/dist/path.js +16 -16
  123. package/dist/raph.cjs +1 -1
  124. package/dist/raph.js +46 -38
  125. package/dist/reactivity/engine.d.ts +17 -3
  126. package/dist/reactivity/reactive-object.d.ts +36 -0
  127. package/dist/reactivity/types.d.ts +25 -0
  128. package/dist/reactivity.cjs +1 -1
  129. package/dist/reactivity.js +12 -12
  130. package/dist/runtime/RaphRuntime.d.ts +132 -192
  131. package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
  132. package/dist/runtime/errors.d.ts +5 -0
  133. package/dist/runtime/ownership/RaphEffectScope.d.ts +29 -0
  134. package/dist/runtime/ownership/RaphNode.d.ts +40 -0
  135. package/dist/runtime/ownership/RaphScope.d.ts +38 -0
  136. package/dist/runtime/{parent-graph.d.ts → ownership/parent-graph.types.d.ts} +0 -1
  137. package/dist/runtime/ownership/parentGraph.d.ts +3 -0
  138. package/dist/runtime/phases/RaphPhasePipeline.d.ts +79 -0
  139. package/dist/runtime/phases/orderPhaseTasks.d.ts +6 -0
  140. package/dist/runtime/phases/phase.types.d.ts +92 -0
  141. package/dist/runtime/{PathHandle.d.ts → reactivity/PathHandle.d.ts} +14 -6
  142. package/dist/runtime/reactivity/RaphMetaSource.d.ts +32 -0
  143. package/dist/runtime/reactivity/RaphWorkGraph.d.ts +171 -0
  144. package/dist/runtime/{RuntimeReactivity.d.ts → reactivity/RuntimeReactivity.d.ts} +14 -9
  145. package/dist/runtime/{RuntimeWatch.d.ts → reactivity/RuntimeWatch.d.ts} +9 -3
  146. package/dist/runtime/{runtime-reactivity.types.d.ts → reactivity/runtime-reactivity.types.d.ts} +3 -1
  147. package/dist/runtime.cjs +1 -1
  148. package/dist/runtime.js +21 -16
  149. package/package.json +68 -35
  150. package/ReadMe.md +0 -153
  151. package/dist/api/public.d.ts +0 -22
  152. package/dist/debug/api/public.cjs +0 -1
  153. package/dist/debug/api/public.js +0 -40
  154. package/dist/debug/path/AdapterPathStore.cjs +0 -1
  155. package/dist/debug/path/DerivedRegistry.cjs +0 -1
  156. package/dist/debug/path/PathEventHub.cjs +0 -1
  157. package/dist/debug/path/PathStore.cjs +0 -1
  158. package/dist/debug/path/RaphMetaStore.cjs +0 -1
  159. package/dist/debug/path/data-adapter.cjs +0 -1
  160. package/dist/debug/path/data-path.cjs +0 -1
  161. package/dist/debug/path/derived-collection.cjs +0 -1
  162. package/dist/debug/path/path-router.cjs +0 -1
  163. package/dist/debug/path/public.cjs +0 -1
  164. package/dist/debug/path/public.js +0 -18
  165. package/dist/debug/runtime/PathHandle.cjs +0 -1
  166. package/dist/debug/runtime/RaphDebug.cjs +0 -1
  167. package/dist/debug/runtime/RaphDebug.js +0 -15
  168. package/dist/debug/runtime/RaphNode.cjs +0 -1
  169. package/dist/debug/runtime/RaphNode.js +0 -143
  170. package/dist/debug/runtime/RaphPhasePipeline.cjs +0 -1
  171. package/dist/debug/runtime/RaphPhasePipeline.js +0 -526
  172. package/dist/debug/runtime/RaphScope.cjs +0 -1
  173. package/dist/debug/runtime/RaphScope.js +0 -64
  174. package/dist/debug/runtime/RuntimeReactivity.cjs +0 -1
  175. package/dist/debug/runtime/RuntimeReactivity.js +0 -154
  176. package/dist/debug/runtime/RuntimeWatch.cjs +0 -1
  177. package/dist/debug/runtime/RuntimeWatch.js +0 -71
  178. package/dist/debug/runtime/public.cjs +0 -1
  179. package/dist/debug/runtime/public.js +0 -18
  180. package/dist/path/public.d.ts +0 -14
  181. package/dist/runtime/RaphDebug.d.ts +0 -32
  182. package/dist/runtime/RaphNode.d.ts +0 -68
  183. package/dist/runtime/RaphPhasePipeline.d.ts +0 -133
  184. package/dist/runtime/RaphScope.d.ts +0 -50
  185. package/dist/runtime/phase.types.d.ts +0 -49
  186. package/dist/runtime/public.d.ts +0 -13
  187. /package/dist/debug/path/{meta.types.cjs → data-path.types.cjs} +0 -0
  188. /package/dist/debug/path/{meta.types.js → data-path.types.js} +0 -0
  189. /package/dist/debug/path/{RaphDerivedHandle.cjs → derived/RaphDerivedHandle.cjs} +0 -0
  190. /package/dist/debug/path/{RaphDerivedHandle.js → derived/RaphDerivedHandle.js} +0 -0
  191. /package/dist/debug/{runtime/runtime-reactivity.types.cjs → path/derived/derived-collection.types.cjs} +0 -0
  192. /package/dist/debug/{runtime/runtime-reactivity.types.js → path/derived/derived-collection.types.js} +0 -0
  193. /package/dist/debug/path/{derived-strategies.cjs → derived/derived-strategy.utils.cjs} +0 -0
  194. /package/dist/debug/path/{derived-strategies.js → derived/derived-strategy.utils.js} +0 -0
  195. /package/dist/debug/path/{RaphMeta.cjs → meta/RaphMeta.cjs} +0 -0
  196. /package/dist/debug/path/{RaphMeta.js → meta/RaphMeta.js} +0 -0
  197. /package/dist/debug/path/{segment-key.cjs → pathSegmentKey.cjs} +0 -0
  198. /package/dist/debug/path/{segment-key.js → pathSegmentKey.js} +0 -0
  199. /package/dist/debug/path/{data-draft.cjs → storage/createDataDraft.cjs} +0 -0
  200. /package/dist/debug/path/{data-draft.js → storage/createDataDraft.js} +0 -0
  201. /package/dist/debug/runtime/{parent-graph.cjs → ownership/parentGraph.cjs} +0 -0
  202. /package/dist/debug/runtime/{parent-graph.js → ownership/parentGraph.js} +0 -0
  203. /package/dist/debug/runtime/{disposal.cjs → ownership/throwDisposalErrors.cjs} +0 -0
  204. /package/dist/debug/runtime/{disposal.js → ownership/throwDisposalErrors.js} +0 -0
  205. /package/dist/debug/runtime/{RaphFrameLoop.cjs → phases/RaphFrameLoop.cjs} +0 -0
  206. /package/dist/debug/runtime/{RaphFrameLoop.js → phases/RaphFrameLoop.js} +0 -0
  207. /package/dist/debug/runtime/{phase.types.cjs → phases/phase.types.cjs} +0 -0
  208. /package/dist/debug/runtime/{phase.types.js → phases/phase.types.js} +0 -0
  209. /package/dist/path/{data-draft.d.ts → storage/createDataDraft.d.ts} +0 -0
  210. /package/dist/runtime/{disposal.d.ts → ownership/throwDisposalErrors.d.ts} +0 -0
  211. /package/dist/runtime/{RaphFrameLoop.d.ts → phases/RaphFrameLoop.d.ts} +0 -0
@@ -1,15 +1,15 @@
1
1
  var R = Object.defineProperty;
2
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 v = (r, e, t) => m(r, typeof e != "symbol" ? e + "" : e, t);
4
- import { parseDataPath as l } from "./data-path.js";
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
5
  import { PathEventHub as H } from "./PathEventHub.js";
6
6
  const u = /* @__PURE__ */ new WeakMap();
7
7
  class $ {
8
8
  constructor() {
9
9
  // Владеют path data и независимым event lifecycle этого store.
10
- v(this, "_root");
11
- v(this, "_eventHub", new H(
12
- "[Raph] Path transaction and publication failed."
10
+ k(this, "_root");
11
+ k(this, "_eventHub", new H(
12
+ "[Raph] Path batch and publication failed."
13
13
  ));
14
14
  }
15
15
  /**
@@ -29,7 +29,7 @@ class $ {
29
29
  * Возвращает значение по пути без создания отсутствующих данных.
30
30
  */
31
31
  get(e, t) {
32
- const n = l(e, t), o = this._root;
32
+ const n = h(e, t), o = this._root;
33
33
  if (o !== void 0)
34
34
  return a(o, n.segments).value;
35
35
  }
@@ -43,14 +43,14 @@ class $ {
43
43
  * Проверяет наличие значения по указанному пути.
44
44
  */
45
45
  has(e, t) {
46
- const n = l(e, t), o = this._root;
46
+ const n = h(e, t), o = this._root;
47
47
  return o !== void 0 && a(o, n.segments).exists;
48
48
  }
49
49
  /**
50
50
  * Записывает значение и публикует соответствующее изменение.
51
51
  */
52
52
  set(e, t, n) {
53
- const o = l(e, n);
53
+ const o = h(e, n);
54
54
  if (o.segments.length === 0) {
55
55
  this._setRoot(t);
56
56
  return;
@@ -70,7 +70,7 @@ class $ {
70
70
  * Объединяет значение по пути и публикует соответствующее изменение.
71
71
  */
72
72
  merge(e, t, n) {
73
- const o = l(e, n);
73
+ const o = h(e, n);
74
74
  if (o.segments.length === 0) {
75
75
  this._mergeRoot(t);
76
76
  return;
@@ -79,7 +79,7 @@ class $ {
79
79
  if (d(i) && d(t)) {
80
80
  g(this._root, o.segments);
81
81
  for (const w of Object.keys(t))
82
- h(i, w, t[w]);
82
+ l(i, w, t[w]);
83
83
  } else
84
84
  this._root ?? (this._root = /* @__PURE__ */ Object.create(null)), O(this._root, o, t);
85
85
  if (!s)
@@ -96,7 +96,7 @@ class $ {
96
96
  * Удаляет значение по пути и публикует изменение при наличии данных.
97
97
  */
98
98
  delete(e, t) {
99
- const n = l(e, t);
99
+ const n = h(e, t);
100
100
  if (n.segments.length === 0) {
101
101
  this._deleteRoot();
102
102
  return;
@@ -110,10 +110,10 @@ class $ {
110
110
  }));
111
111
  }
112
112
  /**
113
- * Выполняет операцию в общей синхронной transaction boundary.
113
+ * Выполняет операцию в общей синхронной batch boundary.
114
114
  */
115
- transaction(e) {
116
- return this._eventHub.transaction(e);
115
+ batch(e) {
116
+ return this._eventHub.batch(e);
117
117
  }
118
118
  /**
119
119
  * Подписывает callback на подходящие изменения и возвращает disposer.
@@ -129,7 +129,7 @@ class $ {
129
129
  const t = this._root, n = this._eventHub.hasWatchers && d(t) && d(e) ? A(t) : t;
130
130
  if (d(t) && d(e))
131
131
  for (const o of Object.keys(e))
132
- h(t, o, e[o]);
132
+ l(t, o, e[o]);
133
133
  else
134
134
  this._root = x(e);
135
135
  this._recordRootEvent("merge", n, this._root);
@@ -146,7 +146,7 @@ function a(r, e) {
146
146
  let t = r;
147
147
  for (const n of e)
148
148
  if (n.kind === "key") {
149
- if (!k(t) || !Object.hasOwn(t, n.key))
149
+ if (!b(t) || !Object.hasOwn(t, n.key))
150
150
  return { exists: !1, value: void 0 };
151
151
  t = t[n.key];
152
152
  } else if (n.kind === "index") {
@@ -166,7 +166,7 @@ function a(r, e) {
166
166
  function g(r, e) {
167
167
  let t = r;
168
168
  for (const n of e) {
169
- if (!k(t))
169
+ if (!b(t))
170
170
  return;
171
171
  const o = j(t, n);
172
172
  Array.isArray(t) && u.delete(t), t = o;
@@ -188,7 +188,7 @@ function E(r, e) {
188
188
  let t = r;
189
189
  for (let s = 0; s < e.segments.length - 1; s++) {
190
190
  const i = e.segments[s], c = j(t, i);
191
- if (!k(c))
191
+ if (!b(c))
192
192
  return;
193
193
  t = c;
194
194
  }
@@ -220,13 +220,13 @@ function P(r, e, t, n) {
220
220
  if (e.kind === "key") {
221
221
  const s = r;
222
222
  let i = s[e.key];
223
- return (!Object.hasOwn(s, e.key) || i === void 0) && (i = p(t), h(s, e.key, i)), b(i, n);
223
+ return (!Object.hasOwn(s, e.key) || i === void 0) && (i = p(t), l(s, e.key, i)), v(i, n);
224
224
  }
225
225
  if (e.kind === "index") {
226
226
  if (!Array.isArray(r))
227
227
  throw y(n);
228
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), b(s, n);
229
+ return (!Object.hasOwn(r, e.index) || s === void 0) && (u.delete(r), s = p(t), r[e.index] = s), v(s, n);
230
230
  }
231
231
  if (!Array.isArray(r))
232
232
  throw y(n);
@@ -236,11 +236,11 @@ function P(r, e, t, n) {
236
236
  const s = /* @__PURE__ */ Object.create(null);
237
237
  s[e.key] = e.value, r.push(s), o = r.length - 1;
238
238
  }
239
- return b(r[o], n);
239
+ return v(r[o], n);
240
240
  }
241
241
  function C(r, e, t, n) {
242
242
  if (e.kind === "key") {
243
- h(r, e.key, t);
243
+ l(r, e.key, t);
244
244
  return;
245
245
  }
246
246
  if (e.kind === "index") {
@@ -270,12 +270,12 @@ function S() {
270
270
  return /* @__PURE__ */ Object.create(null);
271
271
  }
272
272
  function x(r) {
273
- if (k(r))
273
+ if (b(r))
274
274
  return r;
275
275
  throw new TypeError("[Raph] Root value must be an object or array.");
276
276
  }
277
- function b(r, e) {
278
- if (k(r))
277
+ function v(r, e) {
278
+ if (b(r))
279
279
  return r;
280
280
  throw y(e);
281
281
  }
@@ -294,7 +294,7 @@ function _(r, e, t) {
294
294
  }
295
295
  return n || (n = /* @__PURE__ */ new Map(), u.set(r, n)), n.set(e, s), s.get(t) ?? -1;
296
296
  }
297
- function h(r, e, t) {
297
+ function l(r, e, t) {
298
298
  if (e === "__proto__") {
299
299
  Object.defineProperty(r, e, {
300
300
  configurable: !0,
@@ -309,13 +309,13 @@ function h(r, e, t) {
309
309
  function A(r) {
310
310
  const e = Object.create(Object.getPrototypeOf(r));
311
311
  for (const t of Object.keys(r))
312
- h(e, t, r[t]);
312
+ l(e, t, r[t]);
313
313
  return e;
314
314
  }
315
315
  function d(r) {
316
316
  return typeof r == "object" && r !== null && !Array.isArray(r);
317
317
  }
318
- function k(r) {
318
+ function b(r) {
319
319
  return Array.isArray(r) || d(r);
320
320
  }
321
321
  function y(r) {
@@ -0,0 +1 @@
1
+ "use strict";
@@ -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";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 g=(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,d=2,C=4,b=8,W=16,y=32,x=64,O=128,m=256,v=512,E=w|d,_=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={}){g(this,"adaptiveDependencyIndex");g(this,"activeSub",null);g(this,"batchDepth",0);g(this,"effectReadIndex",0);g(this,"effectWriteIndex",0);g(this,"invalidationDepth",0);g(this,"dependencyDepth",0);g(this,"flushingEffects",!1);g(this,"effectQueue",new Array(16).fill(void 0));g(this,"invalidationStack",new Array(512).fill(null));g(this,"dependencyStack",[]);g(this,"handleReaders",this.createHandleReaders());g(this,"effectScheduler");g(this,"flushEffects");g(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,d|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,d|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|=d|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&d&&this.commitSignalValue(e,i),e.cachedValue}writeSignalValue(e,t){if(e.flags&d||this.batchDepth){const s=!!(e.flags&d);if((e.flags&d?e.pendingValue:e.cachedValue)===t)return;if(e.pendingValue=t,e.cachedValue===t)e.flags&=~d,e.pendingAuthor=void 0;else{e.flags|=d;const r=this.activeSub!==null&&this.activeSub.flags&b?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&b||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|b|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?d: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&(d|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&=~d;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|b))===w&&(n.flags=a&~w|d,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,D,u,o,I,A,L,q,F;const i=this.invalidationDepth;let s=i;for(let p=e;p!==null;p=p.nextSub){const f=p.sub,S=f.flags;let k=0;if(S&(E|b)?S&b?k=this.invalidateReadDependency(p,f,S):!t&&!(S&d)&&(f.flags=S&~w|d):(k=S&~C|(t?w:d),f.flags=k),k===0){if(S&y&&S&x){const T=p.dep.flags&v?p.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&b)||((h=f.effectTask)==null?void 0:h.allowScheduleDuringRun)===!0)&&this.enqueueEffect(f,p.dep):(!(S&E)&&f.flags&v&&((u=(D=f.sourceHooks).onInvalidate)==null||u.call(D,f.firstSub!==null)),f.firstSub!==null&&(this.invalidationStack[s++]=f.firstSub))}for(;s!==i;){let p=this.invalidationStack[--s];do{const f=p.sub,S=f.flags;let k=0;if(S&(E|b)?S&b&&(k=this.invalidateReadDependency(p,f,S)):(k=S&~C|w,f.flags=k),k===0){if(S&y&&S&x){const T=p.dep.flags&v?p.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)){p.nextSub!==null&&(this.invalidationStack[s++]=p.nextSub),p=f.firstSub;continue}}else if(k&y)this.enqueueEffect(f,p.dep);else if(!(S&E)&&f.flags&v&&((F=(q=f.sourceHooks).onInvalidate)==null||F.call(q,f.firstSub!==null)),f.firstSub!==null){p.nextSub!==null&&(this.invalidationStack[s++]=p.nextSub),p=f.firstSub;continue}p=p.nextSub}while(p!==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&d||(r.flags=l&~w|d,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|b;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 D=e.cachedValue;return e.cachedValue=a,e.flags=s&v|(r?d:l),D===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&d&&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&d)n=!0;else{const a=t.dep,r=a.flags;if(r&(d|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&(d|C))){const h=e.firstDep;try{if(h===null||!this.refreshDependencies(e,h)){e.flags&=~E;return}}catch(D){throw e.flags&=-80,D}}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|b;const a=this.activeSub;this.activeSub=e;let r;try{r=i()}catch(h){this.activeSub=a,e.flags&=~b,this.failEffectRun(e,h,s)}finally{this.activeSub=a,e.flags&=~b}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|b))===(y|b))){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|b))===(y|b))){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&d?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)},D={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&&(D.hasSubscribers=()=>(n==null?void 0:n.firstSub)!=null),D}_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(D){r.push(D)}if(s.flags!==void 0)try{i.releaseSourceSubs(s)}catch(D){r.push(D)}let l=s.firstDep;for(;l!=null;){const D=l.nextDep;i.detachSubLink(l),l=D}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=$;