@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
@@ -0,0 +1,1157 @@
1
+ import { RaphDisposedError as w, RaphCrossRuntimeError as j } from "../errors.js";
2
+ import { throwDisposalErrors as _ } from "../ownership/throwDisposalErrors.js";
3
+ class v {
4
+ constructor(e, t, s) {
5
+ this.owner = e, this.kind = t, this.includeRuntime = s, this.subscribers = void 0, this.memberships = void 0, this.implicitConsumers = void 0, this.source = void 0, this.activate = void 0, this.runtimeActivation = void 0, this.lastCause = void 0, this.transientNext = void 0, this.revision = 0, this.disposed = !1;
6
+ }
7
+ get runtime() {
8
+ return this.owner.runtime;
9
+ }
10
+ /**
11
+ * Тег Object.prototype.toString: `[object RaphProducer]`. По нему инструменты,
12
+ * которые копируют и обходят только plain objects, принимают producer за
13
+ * неделимое значение: тестовый runner не клонирует его вместе со всем графом
14
+ * Runtime перед печатью diff. Accessor лежит на prototype.
15
+ */
16
+ get [Symbol.toStringTag]() {
17
+ return "RaphProducer";
18
+ }
19
+ /**
20
+ * Возвращает компактное описание вместо собственных полей. Поля producer
21
+ * ведут к владельцу, Runtime и графу зависимостей: без этого метода
22
+ * JSON.stringify упирался бы в циклы, а печать значения в логах и в diff
23
+ * неуспешной проверки тестового runner-а обходила бы весь граф Runtime.
24
+ * Метод лежит на prototype и не добавляет producer ни поля, ни closure.
25
+ */
26
+ toJSON() {
27
+ return {
28
+ kind: this.kind,
29
+ owner: this.owner.id,
30
+ revision: this.revision,
31
+ disposed: this.disposed
32
+ };
33
+ }
34
+ }
35
+ v.prototype._isProducer = !0;
36
+ const R = /* @__PURE__ */ new WeakMap(), k = Object.freeze([]), A = Object.freeze([]);
37
+ class p {
38
+ /** @internal */
39
+ constructor(e, t) {
40
+ this.owner = e, this._sources = H(t);
41
+ }
42
+ _sources;
43
+ _disposed = !1;
44
+ _releaseOwner;
45
+ _memberReleases;
46
+ _firstSubscription;
47
+ _lastSubscription;
48
+ _firstDependent;
49
+ _lastDependent;
50
+ _revision = 0;
51
+ _finalCause;
52
+ /** @internal */
53
+ static _create(e, t) {
54
+ return new p(e, t);
55
+ }
56
+ get runtime() {
57
+ return this.owner.runtime;
58
+ }
59
+ get disposed() {
60
+ return this._disposed;
61
+ }
62
+ get sources() {
63
+ return this._sources;
64
+ }
65
+ dispose() {
66
+ if (this._disposed)
67
+ return;
68
+ const e = this.runtime, t = !e._ownerDisposalActive();
69
+ t && e._beginOwnerDisposal();
70
+ const s = [];
71
+ try {
72
+ const i = this._releaseOwner;
73
+ i !== void 0 ? (this._releaseOwner = void 0, i()) : this._disposeOwned();
74
+ } catch (i) {
75
+ s.push(i);
76
+ } finally {
77
+ if (t)
78
+ try {
79
+ e._endOwnerDisposal();
80
+ } catch (i) {
81
+ s.push(i);
82
+ }
83
+ }
84
+ _(s, "[Raph] Aggregate disposal failed.");
85
+ }
86
+ /** @internal */
87
+ _assertAlive() {
88
+ if (this._disposed || this.owner.disposed)
89
+ throw new w("[Raph] Aggregate is disposed.");
90
+ }
91
+ /** @internal */
92
+ _bindOwner(e) {
93
+ this._releaseOwner = e;
94
+ }
95
+ /** @internal */
96
+ _bindMembers(e) {
97
+ this._memberReleases = e.length === 0 ? void 0 : e;
98
+ }
99
+ /** @internal */
100
+ _removeMember(e) {
101
+ if (this._disposed)
102
+ return;
103
+ const t = this._sources.filter((s) => W(s) !== e);
104
+ t.length !== this._sources.length && (this._sources = t.length === 0 ? k : Object.freeze(t));
105
+ }
106
+ /** @internal */
107
+ _disposeOwned() {
108
+ if (this._disposed)
109
+ return;
110
+ this._disposed = !0, this._releaseOwner = void 0;
111
+ const e = d(this.owner) && !this.owner._isPublished() ? void 0 : this._disposalCause(), t = [];
112
+ let s = this._firstSubscription;
113
+ for (this._firstSubscription = this._lastSubscription = void 0; s !== void 0; ) {
114
+ const o = s.next, u = s.dispose;
115
+ s.aggregate = void 0, s.dispose = void 0, s.previous = s.next = void 0;
116
+ try {
117
+ u?.(e);
118
+ } catch (c) {
119
+ t.push(c);
120
+ }
121
+ s = o;
122
+ }
123
+ const i = this._memberReleases;
124
+ if (this._memberReleases = void 0, i !== void 0)
125
+ for (let o = i.length - 1; o >= 0; o--)
126
+ try {
127
+ i[o]();
128
+ } catch (u) {
129
+ t.push(u);
130
+ }
131
+ this._sources = k;
132
+ let r = this._firstDependent;
133
+ for (this._firstDependent = this._lastDependent = void 0; r !== void 0; ) {
134
+ const o = r.next, u = r.cleanup;
135
+ r.source = void 0, r.cleanup = void 0, r.previous = r.next = void 0;
136
+ try {
137
+ u?.();
138
+ } catch (c) {
139
+ t.push(c);
140
+ }
141
+ r = o;
142
+ }
143
+ _(t, "[Raph] Aggregate owned cleanup failed.");
144
+ }
145
+ /** @internal */
146
+ _linkSubscription(e) {
147
+ this._assertAlive();
148
+ const t = {
149
+ aggregate: this,
150
+ dispose: e,
151
+ previous: this._lastSubscription
152
+ };
153
+ return this._lastSubscription === void 0 ? this._firstSubscription = t : this._lastSubscription.next = t, this._lastSubscription = t, () => K(t);
154
+ }
155
+ /** @internal */
156
+ _linkDependent(e) {
157
+ e.previous = this._lastDependent, this._lastDependent === void 0 ? this._firstDependent = e : this._lastDependent.next = e, this._lastDependent = e;
158
+ }
159
+ /** @internal */
160
+ _detachDependent(e) {
161
+ e.previous === void 0 ? this._firstDependent = e.next : e.previous.next = e.next, e.next === void 0 ? this._lastDependent = e.previous : e.next.previous = e.previous, e.previous = e.next = void 0;
162
+ }
163
+ /** @internal */
164
+ _disposalCause() {
165
+ return this._finalCause ??= Object.freeze({
166
+ kind: "structure",
167
+ source: this,
168
+ sourceOwner: this.owner,
169
+ revision: ++this._revision,
170
+ metadata: Object.freeze({ disposed: !0 })
171
+ });
172
+ }
173
+ /** @internal */
174
+ _detachSubscription(e) {
175
+ if (e.aggregate === void 0)
176
+ return;
177
+ const t = e.dispose;
178
+ e.aggregate = void 0, e.dispose = void 0, e.previous === void 0 ? this._firstSubscription = e.next : e.previous.next = e.next, e.next === void 0 ? this._lastSubscription = e.previous : e.next.previous = e.previous, e.previous = e.next = void 0, t?.();
179
+ }
180
+ }
181
+ class G {
182
+ constructor(e) {
183
+ this._runtime = e;
184
+ }
185
+ _selfSubscribers;
186
+ _subtreeSubscribers;
187
+ _runtimeSubscribers;
188
+ _runtimeSubscriberCount = 0;
189
+ _runtimeActivationProducers;
190
+ _nodeMemberships;
191
+ _nodeRevisions;
192
+ _nodeTouchKeys;
193
+ _implicitProducers;
194
+ _transientProducers;
195
+ _dispatchDepth = 0;
196
+ _detachedEdges;
197
+ _disposed = !1;
198
+ createProducer(e, t = "producer", s = {}) {
199
+ return this._assertAlive(), new v(e, t, s.includeRuntime ?? !0);
200
+ }
201
+ attachProducer(e, t) {
202
+ const s = e.source;
203
+ return s !== void 0 && s !== e && R.delete(s), e.source = t, R.set(t, e), t;
204
+ }
205
+ setProducerActivation(e, t, s = !1) {
206
+ if (e.disposed)
207
+ throw new w("[Raph] Producer is disposed.");
208
+ if (e.activate = t, !s)
209
+ return;
210
+ const i = this._runtimeActivationProducers ??= /* @__PURE__ */ new Set();
211
+ if (i.add(e), this._runtimeSubscriberCount !== 0)
212
+ try {
213
+ e.runtimeActivation = x(t());
214
+ } catch (r) {
215
+ throw i.delete(e), i.size === 0 && (this._runtimeActivationProducers = void 0), r;
216
+ }
217
+ }
218
+ producerHooks(e) {
219
+ return {
220
+ token: e,
221
+ dependencyOwner: e.owner,
222
+ onDependency: (t) => this._linkImplicitDependency(e, t),
223
+ onChange: (t, s, i) => {
224
+ this.notifyProducer(e, t, s, void 0, !0, i, !0);
225
+ },
226
+ onInvalidate: (t) => this.notifyProducer(
227
+ e,
228
+ void 0,
229
+ void 0,
230
+ void 0,
231
+ !0,
232
+ t,
233
+ !1
234
+ ),
235
+ onDispose: (t) => this._disposeProducer(e, t)
236
+ };
237
+ }
238
+ /**
239
+ * Возвращает последнюю причину producer, который engine назвал своим token.
240
+ * Token чужого Runtime и значение, не являющееся producer, причины не имеют.
241
+ *
242
+ * Метод вызывается на каждое уведомление implicit consumer, поэтому producer
243
+ * распознаётся prototype-брендом, а Runtime читается у владельца напрямую:
244
+ * без `instanceof` и без accessor.
245
+ */
246
+ causeForToken(e) {
247
+ if (typeof e != "object" || e === null)
248
+ return;
249
+ const t = e;
250
+ if (!(t._isProducer !== !0 || t.owner.runtime !== this._runtime))
251
+ return t.lastCause;
252
+ }
253
+ /** Clears mutation-local payloads after engine propagation consumed them. */
254
+ clearTransientCauses() {
255
+ let e = this._transientProducers;
256
+ for (this._transientProducers = void 0; e !== void 0; ) {
257
+ const t = e.transientNext;
258
+ e.transientNext = void 0, e.lastCause = void 0, e = t;
259
+ }
260
+ }
261
+ notifyProducer(e, t, s, i, r = !0, o = !1, u = !1) {
262
+ if (this._disposed || e.disposed || e.source === void 0 || d(e.owner) && !e.owner._isPublished() || !u && i === void 0 && e.lastCause !== void 0)
263
+ return;
264
+ if (!o && e.subscribers?.first === void 0 && (!e.includeRuntime || this._runtimeSubscribers?.first === void 0)) {
265
+ this._dispatchProducerLazily(e, t, s, i, r, u);
266
+ return;
267
+ }
268
+ const c = u && i === void 0 ? y(
269
+ e.kind,
270
+ e.source,
271
+ e.owner,
272
+ ++e.revision,
273
+ t,
274
+ s
275
+ ) : {
276
+ kind: e.kind,
277
+ source: e.source,
278
+ sourceOwner: e.owner,
279
+ revision: ++e.revision,
280
+ ...u ? { previous: t, value: s } : {},
281
+ ...i === void 0 ? {} : { events: Object.freeze([...i]) }
282
+ };
283
+ this._setTransientCause(e, c), this._dispatchProducer(e, c, r);
284
+ }
285
+ /**
286
+ * Публикует запись значения producer: форма `notifyProducer()` для причины с
287
+ * `previous` и `value`, без events и с планированием. Так свою запись
288
+ * публикует Runtime signal.
289
+ *
290
+ * Причина создаётся при тех же условиях и с теми же полями. Отличие в цене:
291
+ * у producer с implicit consumers, на который не подписан ни один watch, ни
292
+ * его node, ни поддерево, ни Runtime, причину получают только consumers через
293
+ * `causeForToken()`. Тогда обход подписчиков не начинается: запись не строит
294
+ * массив предков и не выполняет ни одного вызова на каждого из них.
295
+ *
296
+ * @internal
297
+ */
298
+ _notifyValueWrite(e, t, s, i) {
299
+ const r = e.source;
300
+ if (this._disposed || e.disposed || r === void 0)
301
+ return;
302
+ const o = e.owner;
303
+ if (o._isNode && !o._isPublished())
304
+ return;
305
+ const u = e.subscribers;
306
+ if (!i && u?.first === void 0 && (!e.includeRuntime || this._runtimeSubscribers?.first === void 0)) {
307
+ this._dispatchProducerLazily(e, t, s, void 0, !0, !0);
308
+ return;
309
+ }
310
+ const c = y(e.kind, r, o, ++e.revision, t, s);
311
+ e.lastCause === void 0 && (e.transientNext = this._transientProducers, this._transientProducers = e), e.lastCause = c, !(u === void 0 && this._selfSubscribers === void 0 && this._subtreeSubscribers === void 0 && this._runtimeSubscribers === void 0) && this._dispatchProducer(e, c, !0);
312
+ }
313
+ notifyProducerEvents(e, t, s = !0, i = !1) {
314
+ if (this._disposed || e.disposed || e.source === void 0 || d(e.owner) && !e.owner._isPublished())
315
+ return;
316
+ if (!i && e.subscribers?.first === void 0 && (!e.includeRuntime || this._runtimeSubscribers?.first === void 0)) {
317
+ this._dispatchProducerLazily(e, void 0, void 0, t, s, !1);
318
+ return;
319
+ }
320
+ const r = {
321
+ kind: e.kind,
322
+ source: e.source,
323
+ sourceOwner: e.owner,
324
+ revision: ++e.revision,
325
+ events: Object.freeze([...t])
326
+ };
327
+ this._setTransientCause(e, r), this._dispatchProducer(e, r, s);
328
+ }
329
+ /**
330
+ * Дешёвая предварительная проверка structural publication: `false` означает,
331
+ * что `notifyNode` для этой node вернётся до создания cause и без побочных
332
+ * эффектов. `true` консервативен и ведёт на полный путь.
333
+ *
334
+ * @internal
335
+ */
336
+ _hasStructuralDemand(e) {
337
+ if (this._runtimeSubscribers !== void 0 || this._subtreeSubscribers !== void 0)
338
+ return !0;
339
+ const t = this._selfSubscribers;
340
+ return t !== void 0 && t.has(e);
341
+ }
342
+ /**
343
+ * Сообщает, есть ли хотя бы один runtime-, subtree- или self-подписчик.
344
+ * `true` означает, что `_hasStructuralDemand` может вернуть `true` для
345
+ * какой-то node этого Runtime.
346
+ *
347
+ * @internal
348
+ */
349
+ _hasNodeSubscribers() {
350
+ return this._runtimeSubscribers !== void 0 || this._subtreeSubscribers !== void 0 || this._selfSubscribers !== void 0;
351
+ }
352
+ notifyNode(e, t, s = {}) {
353
+ if (this._disposed || !e._isPublished() || this._runtimeSubscribers?.first === void 0 && this._selfSubscribers?.get(e)?.first === void 0 && this._subtreeSubscribers === void 0)
354
+ return;
355
+ const i = s.oldAncestors === void 0 && s.newAncestors === void 0 ? this._subtreeSubscribers === void 0 ? A : P(e) : void 0, r = s.oldAncestors ?? i ?? A, o = s.newAncestors ?? i ?? A;
356
+ if (!this._nodeHasDemand(e, r, o))
357
+ return;
358
+ const u = this._nodeRevisions ??= /* @__PURE__ */ new WeakMap(), c = (u.get(e) ?? 0) + 1;
359
+ u.set(e, c);
360
+ const a = {
361
+ kind: t,
362
+ source: e,
363
+ sourceOwner: e,
364
+ revision: c,
365
+ ...s.metadata === void 0 ? {} : { metadata: s.metadata },
366
+ ...s.structure === void 0 ? {} : { structure: Object.freeze({ ...s.structure }) }
367
+ }, h = t === "structure" ? e : this._nodeTouchKey(e);
368
+ if (this._dispatch(this._selfSubscribers?.get(e), a, h), i !== void 0)
369
+ for (const f of i)
370
+ this._dispatch(this._subtreeSubscribers?.get(f), a, h);
371
+ else {
372
+ const f = /* @__PURE__ */ new Set();
373
+ for (const l of r)
374
+ f.add(l);
375
+ for (const l of o)
376
+ f.add(l);
377
+ for (const l of f)
378
+ this._dispatch(this._subtreeSubscribers?.get(l), a, h);
379
+ }
380
+ this._dispatch(this._runtimeSubscribers, a, h);
381
+ }
382
+ createAggregate(e, t) {
383
+ if (this._assertOwner(e), t.length === 0)
384
+ throw new TypeError("[Raph] Aggregate requires at least one source.");
385
+ this._validateAggregateSources(t, /* @__PURE__ */ new Set());
386
+ for (const o of t)
387
+ this._assertSourceVisibleTo(e, o, /* @__PURE__ */ new Set());
388
+ const s = p._create(e, t), i = [], r = /* @__PURE__ */ new Set();
389
+ try {
390
+ for (const o of s.sources) {
391
+ const u = W(o);
392
+ if (u === void 0 || r.has(u))
393
+ continue;
394
+ r.add(u);
395
+ const c = this._linkSourceCleanup(o, () => s._removeMember(u));
396
+ c !== void 0 && i.push(c);
397
+ }
398
+ return s._bindMembers(i), s._bindOwner(e._adoptResource(() => s._disposeOwned())), s;
399
+ } catch (o) {
400
+ const u = [];
401
+ for (let c = i.length - 1; c >= 0; c--)
402
+ try {
403
+ i[c]();
404
+ } catch (a) {
405
+ u.push(a);
406
+ }
407
+ throw u.length !== 0 ? new AggregateError(
408
+ [o, ...u],
409
+ "[Raph] Aggregate registration and rollback failed."
410
+ ) : o;
411
+ }
412
+ }
413
+ subscribe(e, t, s) {
414
+ this._assertAlive();
415
+ const i = [], r = /* @__PURE__ */ new WeakMap();
416
+ try {
417
+ this._subscribeOne(e, t, s, i, r, /* @__PURE__ */ new Set());
418
+ } catch (u) {
419
+ const c = [];
420
+ for (let a = i.length - 1; a >= 0; a--)
421
+ try {
422
+ i[a]();
423
+ } catch (h) {
424
+ c.push(h);
425
+ }
426
+ throw c.length !== 0 ? new AggregateError(
427
+ [u, ...c],
428
+ "[Raph] Granular subscription registration and rollback failed."
429
+ ) : u;
430
+ }
431
+ let o = !0;
432
+ return () => {
433
+ if (!o)
434
+ return;
435
+ o = !1;
436
+ const u = [];
437
+ for (let c = i.length - 1; c >= 0; c--)
438
+ try {
439
+ i[c]();
440
+ } catch (a) {
441
+ u.push(a);
442
+ }
443
+ _(u, "[Raph] Granular subscription disposal failed.");
444
+ };
445
+ }
446
+ assertSubscriptionAllowed(e, t) {
447
+ this._assertOwner(e), this._assertSourceVisibleTo(e, t, /* @__PURE__ */ new Set());
448
+ }
449
+ /**
450
+ * Rejects a move that would make an existing implicit reactive edge illegal.
451
+ *
452
+ * Рёбра от producers с отдельной записью (computed, machine) берутся из
453
+ * учёта `implicitConsumers`. Рёбра от Runtime signals нигде не учитываются:
454
+ * они читаются из графа в момент проверки.
455
+ */
456
+ assertReparentAllowed(e, t) {
457
+ const s = this._implicitProducers;
458
+ if (s !== void 0)
459
+ for (const i of s) {
460
+ const r = i.owner;
461
+ if (!d(r))
462
+ continue;
463
+ const o = i.implicitConsumers;
464
+ if (o !== void 0)
465
+ for (const u of o.keys())
466
+ E(u, e) && (E(r, e) || L(r, t) || T(e, u, r));
467
+ }
468
+ this._assertSignalEdgesAllowReparent(e, t);
469
+ }
470
+ /**
471
+ * Проверяет живые implicit-рёбра от Runtime signals. Implicit-чтение
472
+ * разрешено только у собственного владельца, его предков и root scope,
473
+ * поэтому внешний для переносимого поддерева источник всегда принадлежит
474
+ * прежнему предку `node`. Предок, который остаётся предком нового parent,
475
+ * сохраняет все свои рёбра законными. Остаются предки от прежнего parent до
476
+ * ближайшего общего с новым parent, не включая его: перенос запрещён, если
477
+ * signal такого предка читает потребитель из переносимого поддерева.
478
+ *
479
+ * Посылка о прежнем предке держится на проверке самого чтения: Runtime
480
+ * signal отклоняет implicit-чтение чужого владельца и тогда, когда общий
481
+ * контекст владельца снят untracked-работой другого Runtime, а потребитель
482
+ * этого Runtime остался активным (assertReadable в RuntimeReactivity).
483
+ *
484
+ * Цена переноса. Перенос под прежнего parent и перенос корня дерева
485
+ * проверки не требуют. Иначе для каждого покидаемого предка обходится весь
486
+ * список его источников (не-signals пропускаются за один шаг), а у каждого
487
+ * signal с записью графа — список его потребителей до первого потребителя
488
+ * из переносимого поддерева. Итого O(покидаемые предки × их источники +
489
+ * потребители их signals), без аллокаций. Цена не зависит от того, сколько
490
+ * рёбер между nodes есть в остальном Runtime, но растёт с числом источников
491
+ * и потребителей у покидаемых предков, даже когда их signals читает только
492
+ * сам владелец: перенос из-под parent с тысячей signals обходит всю тысячу.
493
+ * Прежний учёт рёбер стоил наоборот: ничего для таких signals и обход всех
494
+ * producers Runtime с рёбрами между nodes вместе с их потребителями, где бы
495
+ * в дереве они ни находились.
496
+ */
497
+ _assertSignalEdgesAllowReparent(e, t) {
498
+ const s = e.parent;
499
+ if (s === null)
500
+ return;
501
+ const i = $(s, t);
502
+ if (i === s)
503
+ return;
504
+ const r = this._runtime._getReactivity();
505
+ for (let o = s; o !== null && o !== i; o = o.parent) {
506
+ const u = r._findSignalConsumerOwner(o, I, e);
507
+ u !== void 0 && T(e, u, o);
508
+ }
509
+ }
510
+ releaseNode(e) {
511
+ this._releaseGranule(this._selfSubscribers, e), this._releaseGranule(this._subtreeSubscribers, e);
512
+ const t = this._nodeMemberships?.get(e);
513
+ if (t !== void 0) {
514
+ this._nodeMemberships.delete(e);
515
+ try {
516
+ this._releaseCleanupList(t);
517
+ } finally {
518
+ this._nodeMemberships?.size === 0 && (this._nodeMemberships = void 0);
519
+ }
520
+ }
521
+ }
522
+ dispose() {
523
+ if (this._disposed)
524
+ return;
525
+ this._disposed = !0;
526
+ const e = [];
527
+ if (this.clearTransientCauses(), this._implicitProducers !== void 0) {
528
+ for (const t of this._implicitProducers)
529
+ t.implicitConsumers = void 0;
530
+ this._implicitProducers.clear(), this._implicitProducers = void 0;
531
+ }
532
+ try {
533
+ this._releaseRuntimeActivations();
534
+ } catch (t) {
535
+ e.push(t);
536
+ }
537
+ if (this._runtimeActivationProducers?.clear(), this._runtimeActivationProducers = void 0, this._runtimeSubscriberCount = 0, this._selfSubscribers !== void 0)
538
+ for (const t of [...this._selfSubscribers.keys()])
539
+ this._releaseGranule(this._selfSubscribers, t);
540
+ if (this._subtreeSubscribers !== void 0)
541
+ for (const t of [...this._subtreeSubscribers.keys()])
542
+ this._releaseGranule(this._subtreeSubscribers, t);
543
+ if (this._nodeMemberships !== void 0) {
544
+ for (const t of this._nodeMemberships.values())
545
+ this._releaseCleanupList(t, !1);
546
+ this._nodeMemberships.clear(), this._nodeMemberships = void 0;
547
+ }
548
+ if (this._runtimeSubscribers !== void 0) {
549
+ try {
550
+ this._releaseWorkList(this._runtimeSubscribers);
551
+ } catch (t) {
552
+ e.push(t);
553
+ }
554
+ this._runtimeSubscribers = void 0;
555
+ }
556
+ _(e, "[Raph] Work graph disposal failed.");
557
+ }
558
+ /**
559
+ * Освобождает producer: публикует финальную structural cause при спросе и
560
+ * снимает его подписчиков, memberships и регистрацию. Вызывается hook-ом
561
+ * onDispose owned-источника и самим Runtime signal.
562
+ *
563
+ * @internal
564
+ */
565
+ _disposeProducer(e, t = !1) {
566
+ if (e.disposed)
567
+ return;
568
+ const s = e.source, i = !d(e.owner) || e.owner._isPublished();
569
+ let r;
570
+ if (s !== void 0 && i && (t || this._producerHasDemand(e))) {
571
+ const c = {
572
+ kind: "structure",
573
+ source: s,
574
+ sourceOwner: e.owner,
575
+ revision: ++e.revision,
576
+ metadata: Object.freeze({ disposed: !0 })
577
+ };
578
+ this._setTransientCause(e, c);
579
+ const a = s === e ? c : s;
580
+ try {
581
+ this._dispatchProducer(e, c, !0, a);
582
+ } catch (h) {
583
+ (r ??= []).push(h);
584
+ }
585
+ }
586
+ e.disposed = !0;
587
+ const o = e.runtimeActivation;
588
+ e.runtimeActivation = void 0, this._runtimeActivationProducers?.delete(e), this._runtimeActivationProducers?.size === 0 && (this._runtimeActivationProducers = void 0);
589
+ try {
590
+ o?.();
591
+ } catch (c) {
592
+ (r ??= []).push(c);
593
+ }
594
+ if (e.memberships !== void 0) {
595
+ try {
596
+ this._releaseCleanupList(e.memberships);
597
+ } catch (c) {
598
+ (r ??= []).push(c);
599
+ }
600
+ e.memberships = void 0;
601
+ }
602
+ const u = e.source;
603
+ if (u !== void 0 && u !== e && R.delete(u), e.subscribers !== void 0)
604
+ try {
605
+ this._releaseWorkList(e.subscribers);
606
+ } catch (c) {
607
+ (r ??= []).push(c);
608
+ } finally {
609
+ e.subscribers = void 0;
610
+ }
611
+ e.activate = void 0, e.source = void 0, r !== void 0 && _(r, "[Raph] Runtime producer disposal failed.");
612
+ }
613
+ _dispatchProducer(e, t, s = !0, i = e) {
614
+ this._dispatch(e.subscribers, t, i, s);
615
+ const r = e.owner;
616
+ if (d(r) && (this._dispatch(this._selfSubscribers?.get(r), t, i, s), this._subtreeSubscribers !== void 0))
617
+ for (const o of P(r))
618
+ this._dispatch(this._subtreeSubscribers?.get(o), t, i, s);
619
+ e.includeRuntime && this._dispatch(this._runtimeSubscribers, t, i, s);
620
+ }
621
+ _dispatchProducerLazily(e, t, s, i, r, o) {
622
+ const u = e.owner;
623
+ let c;
624
+ if (d(u)) {
625
+ const h = this._selfSubscribers?.get(u);
626
+ h?.first !== void 0 && (c = this._createProducerCause(e, t, s, i, o), this._dispatch(h, c, e, r));
627
+ const f = this._subtreeSubscribers;
628
+ if (f !== void 0)
629
+ for (let l = u; l !== null; ) {
630
+ const N = l.parent, O = f.get(l);
631
+ O?.first !== void 0 && (c ??= this._createProducerCause(e, t, s, i, o), this._dispatch(O, c, e, r)), l = N;
632
+ }
633
+ }
634
+ const a = e.includeRuntime ? this._runtimeSubscribers : void 0;
635
+ a?.first !== void 0 && (c ??= this._createProducerCause(e, t, s, i, o), this._dispatch(a, c, e, r));
636
+ }
637
+ _createProducerCause(e, t, s, i, r) {
638
+ const o = ++e.revision, u = r ? i === void 0 ? y(e.kind, e.source, e.owner, o, t, s) : {
639
+ kind: e.kind,
640
+ source: e.source,
641
+ sourceOwner: e.owner,
642
+ revision: o,
643
+ previous: t,
644
+ value: s,
645
+ events: Object.freeze([...i])
646
+ } : i === void 0 ? {
647
+ kind: e.kind,
648
+ source: e.source,
649
+ sourceOwner: e.owner,
650
+ revision: o
651
+ } : {
652
+ kind: e.kind,
653
+ source: e.source,
654
+ sourceOwner: e.owner,
655
+ revision: o,
656
+ events: Object.freeze([...i])
657
+ };
658
+ return this._setTransientCause(e, u), u;
659
+ }
660
+ _retainRuntimeSubscriber() {
661
+ if (this._runtimeSubscriberCount++, this._runtimeSubscriberCount !== 1)
662
+ return;
663
+ const e = [], t = [];
664
+ try {
665
+ for (const s of this._runtimeActivationProducers ?? [])
666
+ s.disposed || s.runtimeActivation !== void 0 || (s.runtimeActivation = x(s.activate?.()), e.push(s));
667
+ return;
668
+ } catch (s) {
669
+ t.push(s);
670
+ }
671
+ this._runtimeSubscriberCount = 0;
672
+ for (let s = e.length - 1; s >= 0; s--) {
673
+ const i = e[s], r = i.runtimeActivation;
674
+ i.runtimeActivation = void 0;
675
+ try {
676
+ r?.();
677
+ } catch (o) {
678
+ t.push(o);
679
+ }
680
+ }
681
+ throw t.length === 1 ? t[0] : new AggregateError(t, "[Raph] Runtime granule activation failed and rollback was incomplete.");
682
+ }
683
+ _releaseRuntimeSubscriber() {
684
+ this._runtimeSubscriberCount !== 0 && (this._runtimeSubscriberCount--, this._runtimeSubscriberCount === 0 && this._releaseRuntimeActivations());
685
+ }
686
+ _releaseRuntimeActivations() {
687
+ const e = [];
688
+ for (const t of this._runtimeActivationProducers ?? []) {
689
+ const s = t.runtimeActivation;
690
+ t.runtimeActivation = void 0;
691
+ try {
692
+ s?.();
693
+ } catch (i) {
694
+ e.push(i);
695
+ }
696
+ }
697
+ _(e, "[Raph] Runtime granule activation cleanup failed.");
698
+ }
699
+ /**
700
+ * Учитывает одно фактическое implicit-ребро графа от producer к consumer
701
+ * owner и возвращает его точное снятие. Вызывается hook-ом onDependency
702
+ * producers с отдельной записью; Runtime signal этого hook не имеет, и его
703
+ * рёбра проверка reparent читает прямо из графа.
704
+ *
705
+ * @internal
706
+ */
707
+ _linkImplicitDependency(e, t) {
708
+ const s = e.owner, i = t;
709
+ if (e.disposed || i.runtime !== this._runtime || !d(s) || !d(i) || s === i)
710
+ return;
711
+ const r = e.implicitConsumers ??= /* @__PURE__ */ new Map();
712
+ r.set(i, (r.get(i) ?? 0) + 1), (this._implicitProducers ??= /* @__PURE__ */ new Set()).add(e);
713
+ let u = !0;
714
+ return () => {
715
+ if (!u)
716
+ return;
717
+ u = !1;
718
+ const c = e.implicitConsumers?.get(i);
719
+ if (c !== void 0) {
720
+ if (c > 1) {
721
+ e.implicitConsumers.set(i, c - 1);
722
+ return;
723
+ }
724
+ e.implicitConsumers.delete(i), e.implicitConsumers.size === 0 && (e.implicitConsumers = void 0, this._implicitProducers?.delete(e), this._implicitProducers?.size === 0 && (this._implicitProducers = void 0));
725
+ }
726
+ };
727
+ }
728
+ _subscribeOne(e, t, s, i, r, o) {
729
+ if (t !== void 0 && !d(e))
730
+ throw new TypeError("[Raph] watch include applies only to a bare RaphNode source.");
731
+ if (e instanceof p) {
732
+ if (e._assertAlive(), this._assertRuntime(e.runtime), o.has(e))
733
+ throw new TypeError("[Raph] Aggregate sources cannot contain a cycle.");
734
+ o.add(e);
735
+ const u = [];
736
+ try {
737
+ for (const c of e.sources)
738
+ this._subscribeOne(c, void 0, s, u, r, o);
739
+ i.push(e._linkSubscription((c) => {
740
+ const a = [];
741
+ if (c !== void 0)
742
+ try {
743
+ s(c, e, !0);
744
+ } catch (h) {
745
+ a.push(h);
746
+ }
747
+ for (let h = u.length - 1; h >= 0; h--)
748
+ try {
749
+ u[h]();
750
+ } catch (f) {
751
+ a.push(f);
752
+ }
753
+ _(a, "[Raph] Aggregate member subscription disposal failed.");
754
+ }));
755
+ } catch (c) {
756
+ const a = [];
757
+ for (let h = u.length - 1; h >= 0; h--)
758
+ try {
759
+ u[h]();
760
+ } catch (f) {
761
+ a.push(f);
762
+ }
763
+ throw o.delete(e), a.length !== 0 ? new AggregateError(
764
+ [c, ...a],
765
+ "[Raph] Aggregate subscription registration and rollback failed."
766
+ ) : c;
767
+ }
768
+ o.delete(e);
769
+ return;
770
+ }
771
+ if (m(e)) {
772
+ this._subscribeNode(e.source, e.include, s, i, r);
773
+ return;
774
+ }
775
+ if (d(e)) {
776
+ this._subscribeNode(e, t ?? "self", s, i, r);
777
+ return;
778
+ }
779
+ if (g(e)) {
780
+ this._assertRuntime(e), i.push(C(r, e, () => {
781
+ const u = this._runtimeSubscribers ??= {}, c = { kind: "runtime", sink: s, source: e };
782
+ this._appendWorkEdge(u, c);
783
+ try {
784
+ this._retainRuntimeSubscriber();
785
+ } catch (a) {
786
+ throw c.source = void 0, this._detachWorkEdge(u, c), u.first === void 0 && (this._runtimeSubscribers = void 0), a;
787
+ }
788
+ return () => {
789
+ c.source !== void 0 && (c.source = void 0, this._detachWorkEdge(this._runtimeSubscribers, c), this._runtimeSubscribers?.first === void 0 && (this._runtimeSubscribers = void 0), this._releaseRuntimeSubscriber());
790
+ };
791
+ }));
792
+ return;
793
+ }
794
+ if (b(e)) {
795
+ const u = S(e);
796
+ if (u !== void 0) {
797
+ if (this._assertRuntime(u.runtime), u.disposed)
798
+ throw new w("[Raph] Producer is disposed.");
799
+ i.push(C(r, u, () => {
800
+ const c = u.subscribers ??= {}, a = { kind: "producer", sink: s, source: u };
801
+ this._appendWorkEdge(c, a);
802
+ try {
803
+ a.activationRelease = x(u.activate?.());
804
+ } catch (h) {
805
+ throw a.source = void 0, this._detachWorkEdge(c, a), c.first === void 0 && (u.subscribers = void 0), h;
806
+ }
807
+ return () => {
808
+ const h = a.activationRelease;
809
+ a.activationRelease = void 0;
810
+ const f = a.source;
811
+ f instanceof v && (a.source = void 0, this._detachWorkEdge(f.subscribers, a), f.subscribers?.first === void 0 && (f.subscribers = void 0)), h?.();
812
+ };
813
+ }));
814
+ return;
815
+ }
816
+ }
817
+ throw new TypeError("[Raph] Unsupported or ownerless granular watch source.");
818
+ }
819
+ _subscribeNode(e, t, s, i, r) {
820
+ if (this._assertRuntime(e.runtime), e._assertAlive(), t !== "self" && t !== "subtree")
821
+ throw new TypeError(`[Raph] Unsupported node include mode "${String(t)}".`);
822
+ const o = t === "self" ? e : e._subtreeSourceIdentity;
823
+ i.push(C(r, o, () => {
824
+ const u = t === "self" ? this._selfSubscribers ??= /* @__PURE__ */ new Map() : this._subtreeSubscribers ??= /* @__PURE__ */ new Map();
825
+ let c = u.get(e);
826
+ c === void 0 && (c = {}, u.set(e, c));
827
+ const a = { kind: t, sink: s, source: e };
828
+ return this._appendWorkEdge(c, a), this._createNodeEdgeRelease(a);
829
+ }));
830
+ }
831
+ _createNodeEdgeRelease(e) {
832
+ return () => {
833
+ const t = e.source;
834
+ if (!d(t))
835
+ return;
836
+ e.source = void 0;
837
+ const s = e.kind === "self" ? this._selfSubscribers : this._subtreeSubscribers, i = s?.get(t);
838
+ this._detachWorkEdge(i, e), i?.first === void 0 && (s?.delete(t), s?.size === 0 && (e.kind === "self" ? this._selfSubscribers = void 0 : this._subtreeSubscribers = void 0));
839
+ };
840
+ }
841
+ _linkSourceCleanup(e, t) {
842
+ const s = U(e);
843
+ if (s === void 0)
844
+ return;
845
+ const i = { cleanup: t, source: s };
846
+ if (s instanceof v) {
847
+ const r = s.memberships ??= {};
848
+ z(r, i);
849
+ } else if (s instanceof p)
850
+ s._linkDependent(i);
851
+ else {
852
+ const r = this._nodeMemberships ??= /* @__PURE__ */ new Map();
853
+ let o = r.get(s);
854
+ o === void 0 && (o = {}, r.set(s, o)), z(o, i);
855
+ }
856
+ return () => this._detachCleanupEdge(i);
857
+ }
858
+ _detachCleanupEdge(e) {
859
+ const t = e.source;
860
+ if (t === void 0)
861
+ return;
862
+ if (e.source = void 0, e.cleanup = void 0, t instanceof v) {
863
+ M(t.memberships, e), t.memberships?.first === void 0 && (t.memberships = void 0);
864
+ return;
865
+ }
866
+ if (t instanceof p) {
867
+ t._detachDependent(e);
868
+ return;
869
+ }
870
+ const s = this._nodeMemberships?.get(t);
871
+ M(s, e), s?.first === void 0 && (this._nodeMemberships?.delete(t), this._nodeMemberships?.size === 0 && (this._nodeMemberships = void 0));
872
+ }
873
+ _releaseCleanupList(e, t = !0) {
874
+ let s = e.first;
875
+ e.first = e.last = void 0;
876
+ const i = [];
877
+ for (; s !== void 0; ) {
878
+ const r = s.next, o = s.cleanup;
879
+ if (s.source = void 0, s.cleanup = void 0, s.previous = s.next = void 0, t)
880
+ try {
881
+ o?.();
882
+ } catch (u) {
883
+ i.push(u);
884
+ }
885
+ s = r;
886
+ }
887
+ _(i, "[Raph] Aggregate membership cleanup failed.");
888
+ }
889
+ _validateAggregateSources(e, t) {
890
+ for (const s of e) {
891
+ if (Array.isArray(s))
892
+ throw new TypeError("[Raph] Nested source arrays are not supported; create a named aggregate.");
893
+ if (s instanceof p) {
894
+ if (s._assertAlive(), this._assertRuntime(s.runtime), t.has(s))
895
+ throw new TypeError("[Raph] Aggregate sources cannot contain a cycle.");
896
+ t.add(s), this._validateAggregateSources(s.sources, t), t.delete(s);
897
+ } else if (m(s)) {
898
+ if (this._assertRuntime(s.source.runtime), s.source._assertAlive(), s.include !== "self" && s.include !== "subtree")
899
+ throw new TypeError(`[Raph] Unsupported node include mode "${String(s.include)}".`);
900
+ } else if (d(s))
901
+ this._assertRuntime(s.runtime), s._assertAlive();
902
+ else if (g(s))
903
+ this._assertRuntime(s);
904
+ else if (b(s)) {
905
+ const i = S(s);
906
+ if (i === void 0 || i.disposed)
907
+ throw new w("[Raph] Aggregate producer is disposed or ownerless.");
908
+ this._assertRuntime(i.runtime);
909
+ } else
910
+ throw new TypeError("[Raph] Unsupported aggregate source.");
911
+ }
912
+ }
913
+ _assertSourceVisibleTo(e, t, s) {
914
+ if (t instanceof p) {
915
+ if (this._assertProvisionalOwnerAccess(e, t.owner), s.has(t))
916
+ return;
917
+ s.add(t);
918
+ for (const r of t.sources)
919
+ this._assertSourceVisibleTo(e, r, s);
920
+ s.delete(t);
921
+ return;
922
+ }
923
+ if (m(t)) {
924
+ this._assertProvisionalOwnerAccess(e, t.source);
925
+ return;
926
+ }
927
+ if (d(t)) {
928
+ this._assertProvisionalOwnerAccess(e, t);
929
+ return;
930
+ }
931
+ if (g(t) || !b(t))
932
+ return;
933
+ const i = S(t);
934
+ i !== void 0 && this._assertProvisionalOwnerAccess(e, i.owner);
935
+ }
936
+ _assertProvisionalOwnerAccess(e, t) {
937
+ if (!(!d(t) || t._isPublished()) && !(d(e) && !e._isPublished() && D(e) === D(t)))
938
+ throw new Error(
939
+ `[Raph] Owner "${e.id}" cannot subscribe to provisional source owner "${t.id}".`
940
+ );
941
+ }
942
+ _dispatch(e, t, s, i = !0) {
943
+ let r = e?.first;
944
+ if (r === void 0)
945
+ return;
946
+ const o = e.last;
947
+ this._dispatchDepth++;
948
+ try {
949
+ for (; r !== void 0; ) {
950
+ const u = r.next;
951
+ if (r.source !== void 0 && r.sink(t, s, i), r === o)
952
+ break;
953
+ r = u;
954
+ }
955
+ } finally {
956
+ if (--this._dispatchDepth === 0 && this._detachedEdges !== void 0) {
957
+ for (const u of this._detachedEdges)
958
+ u.previous = u.next = void 0;
959
+ this._detachedEdges = void 0;
960
+ }
961
+ }
962
+ }
963
+ _appendWorkEdge(e, t) {
964
+ t.previous = e.last, e.last === void 0 ? e.first = t : e.last.next = t, e.last = t;
965
+ }
966
+ _detachWorkEdge(e, t) {
967
+ e !== void 0 && (t.previous === void 0 ? e.first = t.next : t.previous.next = t.next, t.next === void 0 ? e.last = t.previous : t.next.previous = t.previous, this._dispatchDepth === 0 ? t.previous = t.next = void 0 : (this._detachedEdges ??= []).push(t));
968
+ }
969
+ _releaseWorkList(e) {
970
+ let t = e.first;
971
+ const s = [];
972
+ for (; t !== void 0; ) {
973
+ const i = t.next, r = t.activationRelease;
974
+ t.activationRelease = void 0, t.source = void 0, this._detachWorkEdge(e, t);
975
+ try {
976
+ r?.();
977
+ } catch (o) {
978
+ s.push(o);
979
+ }
980
+ t = i;
981
+ }
982
+ _(s, "[Raph] Granular source activation cleanup failed.");
983
+ }
984
+ _releaseGranule(e, t) {
985
+ const s = e?.get(t);
986
+ s !== void 0 && (e.delete(t), this._releaseWorkList(s), e.size === 0 && (e === this._selfSubscribers && (this._selfSubscribers = void 0), e === this._subtreeSubscribers && (this._subtreeSubscribers = void 0)));
987
+ }
988
+ _setTransientCause(e, t) {
989
+ e.lastCause === void 0 && (e.transientNext = this._transientProducers, this._transientProducers = e), e.lastCause = t;
990
+ }
991
+ _producerHasDemand(e) {
992
+ if (d(e.owner) && !e.owner._isPublished())
993
+ return !1;
994
+ if (e.subscribers?.first !== void 0 || e.includeRuntime && this._runtimeSubscribers?.first !== void 0)
995
+ return !0;
996
+ const t = e.owner;
997
+ if (!d(t))
998
+ return !1;
999
+ if (this._selfSubscribers?.get(t)?.first !== void 0)
1000
+ return !0;
1001
+ if (this._subtreeSubscribers === void 0)
1002
+ return !1;
1003
+ for (const s of P(t))
1004
+ if (this._subtreeSubscribers.get(s)?.first !== void 0)
1005
+ return !0;
1006
+ return !1;
1007
+ }
1008
+ _nodeTouchKey(e) {
1009
+ const t = this._nodeTouchKeys ??= /* @__PURE__ */ new WeakMap();
1010
+ let s = t.get(e);
1011
+ return s === void 0 && (s = Object.freeze({}), t.set(e, s)), s;
1012
+ }
1013
+ _nodeHasDemand(e, t, s) {
1014
+ if (this._runtimeSubscribers?.first !== void 0 || this._selfSubscribers?.get(e)?.first !== void 0)
1015
+ return !0;
1016
+ if (this._subtreeSubscribers === void 0)
1017
+ return !1;
1018
+ for (const i of t)
1019
+ if (this._subtreeSubscribers.get(i)?.first !== void 0)
1020
+ return !0;
1021
+ for (const i of s)
1022
+ if (this._subtreeSubscribers.get(i)?.first !== void 0)
1023
+ return !0;
1024
+ return !1;
1025
+ }
1026
+ _assertOwner(e) {
1027
+ this._assertRuntime(e.runtime), e._assertAlive();
1028
+ }
1029
+ _assertRuntime(e) {
1030
+ if (e !== this._runtime)
1031
+ throw new j("[Raph] Granular source belongs to another runtime.");
1032
+ }
1033
+ _assertAlive() {
1034
+ if (this._disposed)
1035
+ throw new w("[Raph] Work graph is disposed.");
1036
+ }
1037
+ }
1038
+ function D(n) {
1039
+ let e = n;
1040
+ for (; e.parent !== null && !e.parent._isPublished(); )
1041
+ e = e.parent;
1042
+ return e;
1043
+ }
1044
+ function P(n) {
1045
+ const e = [];
1046
+ for (let t = n; t !== null; t = t.parent)
1047
+ e.push(t);
1048
+ return e;
1049
+ }
1050
+ function E(n, e) {
1051
+ for (let t = n; t !== null; t = t.parent)
1052
+ if (t === e)
1053
+ return !0;
1054
+ return !1;
1055
+ }
1056
+ function L(n, e) {
1057
+ for (let t = e; t !== null; t = t.parent)
1058
+ if (t === n)
1059
+ return !0;
1060
+ return !1;
1061
+ }
1062
+ function I(n, e) {
1063
+ return d(n) && E(n, e);
1064
+ }
1065
+ function $(n, e) {
1066
+ let t = 0;
1067
+ for (let o = n.parent; o !== null; o = o.parent)
1068
+ t++;
1069
+ let s = 0;
1070
+ for (let o = e.parent; o !== null; o = o.parent)
1071
+ s++;
1072
+ let i = n, r = e;
1073
+ for (; t > s; t--)
1074
+ i = i.parent;
1075
+ for (; s > t; s--)
1076
+ r = r.parent;
1077
+ for (; i !== r; )
1078
+ i = i.parent, r = r.parent;
1079
+ return i;
1080
+ }
1081
+ function T(n, e, t) {
1082
+ throw new Error(
1083
+ `[Raph] Cannot reparent "${n.id}": implicit dependency from "${e.id}" to "${t.id}" would become invalid; use watch().`
1084
+ );
1085
+ }
1086
+ function H(n) {
1087
+ return Object.freeze(n.map((e) => m(e) ? Object.freeze({ source: e.source, include: e.include }) : e));
1088
+ }
1089
+ G._valueCauseShapeAnchor = y(
1090
+ "producer",
1091
+ void 0,
1092
+ void 0,
1093
+ 0,
1094
+ void 0,
1095
+ void 0
1096
+ );
1097
+ function y(n, e, t, s, i, r) {
1098
+ return { kind: n, source: e, sourceOwner: t, revision: s, previous: i, value: r };
1099
+ }
1100
+ function W(n) {
1101
+ return n instanceof p ? n : m(n) ? n.source : d(n) || g(n) ? n : b(n) ? S(n) : void 0;
1102
+ }
1103
+ function U(n) {
1104
+ if (n instanceof p)
1105
+ return n;
1106
+ if (m(n))
1107
+ return n.source;
1108
+ if (d(n))
1109
+ return n;
1110
+ if (!g(n))
1111
+ return b(n) ? S(n) : void 0;
1112
+ }
1113
+ function z(n, e) {
1114
+ e.previous = n.last, n.last === void 0 ? n.first = e : n.last.next = e, n.last = e;
1115
+ }
1116
+ function K(n) {
1117
+ n.aggregate?._detachSubscription(n);
1118
+ }
1119
+ function M(n, e) {
1120
+ n !== void 0 && (e.previous === void 0 ? n.first = e.next : e.previous.next = e.next, e.next === void 0 ? n.last = e.previous : e.next.previous = e.previous, e.previous = e.next = void 0);
1121
+ }
1122
+ function C(n, e, t) {
1123
+ let s = n.get(e);
1124
+ s === void 0 && (s = { count: 0, dispose: t() }, n.set(e, s)), s.count++;
1125
+ let i = !0;
1126
+ return () => {
1127
+ if (!i || (i = !1, --s.count !== 0))
1128
+ return;
1129
+ const r = s.dispose;
1130
+ s.dispose = F, r();
1131
+ };
1132
+ }
1133
+ function F() {
1134
+ }
1135
+ function x(n) {
1136
+ return typeof n == "function" ? n : void 0;
1137
+ }
1138
+ function S(n) {
1139
+ return n instanceof v ? n.source === n ? n : void 0 : R.get(n);
1140
+ }
1141
+ function m(n) {
1142
+ return b(n) && "source" in n && d(n.source) && "include" in n;
1143
+ }
1144
+ function d(n) {
1145
+ return b(n) && n._isNode === !0;
1146
+ }
1147
+ function g(n) {
1148
+ return b(n) && "rootScope" in n && "definePhases" in n && "configuration" in n;
1149
+ }
1150
+ function b(n) {
1151
+ return typeof n == "object" && n !== null;
1152
+ }
1153
+ export {
1154
+ p as RaphAggregate,
1155
+ v as RaphProducer,
1156
+ G as RaphWorkGraph
1157
+ };