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

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