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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/README.md +1096 -0
  2. package/dist/api/Raph.d.ts +59 -190
  3. package/dist/api/RaphFacadeSession.d.ts +90 -0
  4. package/dist/api/RaphReactivityInstance.d.ts +72 -0
  5. package/dist/api/errors.d.ts +9 -4
  6. package/dist/api/types.d.ts +162 -17
  7. package/dist/core-CyilRD7s.js +1055 -0
  8. package/dist/core-ugchZNqC.cjs +1 -0
  9. package/dist/debug/api/Raph.cjs +1 -1
  10. package/dist/debug/api/Raph.js +368 -366
  11. package/dist/debug/api/RaphFacadeSession.cjs +1 -0
  12. package/dist/debug/api/RaphFacadeSession.js +306 -0
  13. package/dist/debug/api/RaphReactivityInstance.cjs +1 -0
  14. package/dist/debug/api/RaphReactivityInstance.js +149 -0
  15. package/dist/debug/api/errors.cjs +1 -1
  16. package/dist/debug/api/errors.js +10 -7
  17. package/dist/debug/path/DataPath.cjs +1 -0
  18. package/dist/debug/path/{data-path.js → DataPath.js} +151 -180
  19. package/dist/debug/path/PathRouter.cjs +1 -0
  20. package/dist/debug/path/{path-router.js → PathRouter.js} +1 -1
  21. package/dist/debug/path/RaphKernel.cjs +1 -1
  22. package/dist/debug/path/RaphKernel.js +258 -207
  23. package/dist/debug/path/data-path.utils.cjs +1 -0
  24. package/dist/debug/path/data-path.utils.js +56 -0
  25. package/dist/debug/path/derived/DerivedRegistry.cjs +1 -0
  26. package/dist/debug/path/{DerivedRegistry.js → derived/DerivedRegistry.js} +5 -5
  27. package/dist/debug/path/derived/derived-collection.utils.cjs +1 -0
  28. package/dist/debug/path/{derived-collection.js → derived/derived-collection.utils.js} +1 -1
  29. package/dist/debug/path/derived/derived-strategy.types.cjs +1 -0
  30. package/dist/debug/path/derived/derived-strategy.types.js +1 -0
  31. package/dist/debug/path/{MetaController.cjs → meta/MetaController.cjs} +1 -1
  32. package/dist/debug/path/{MetaController.js → meta/MetaController.js} +3 -3
  33. package/dist/debug/path/meta/RaphMetaStore.cjs +1 -0
  34. package/dist/debug/path/{RaphMetaStore.js → meta/RaphMetaStore.js} +1 -1
  35. package/dist/debug/path/meta/meta.types.cjs +1 -0
  36. package/dist/debug/path/meta/meta.types.js +1 -0
  37. package/dist/debug/path/storage/AdapterPathStore.cjs +1 -0
  38. package/dist/debug/path/{AdapterPathStore.js → storage/AdapterPathStore.js} +9 -9
  39. package/dist/debug/path/storage/DefaultDataAdapter.cjs +1 -0
  40. package/dist/debug/path/{data-adapter.js → storage/DefaultDataAdapter.js} +2 -2
  41. package/dist/debug/path/storage/PathEventHub.cjs +1 -0
  42. package/dist/debug/path/{PathEventHub.js → storage/PathEventHub.js} +34 -34
  43. package/dist/debug/path/storage/PathStore.cjs +1 -0
  44. package/dist/debug/path/{PathStore.js → storage/PathStore.js} +28 -28
  45. package/dist/debug/path/storage/data-adapter.types.cjs +1 -0
  46. package/dist/debug/path/storage/data-adapter.types.js +1 -0
  47. package/dist/debug/reactivity/engine.cjs +1 -1
  48. package/dist/debug/reactivity/engine.js +478 -306
  49. package/dist/debug/reactivity/reactive-object.cjs +1 -0
  50. package/dist/debug/reactivity/reactive-object.js +280 -0
  51. package/dist/debug/runtime/RaphRuntime.cjs +1 -1
  52. package/dist/debug/runtime/RaphRuntime.js +798 -519
  53. package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -0
  54. package/dist/debug/runtime/diagnostics/RaphDebug.js +297 -0
  55. package/dist/debug/runtime/errors.cjs +1 -1
  56. package/dist/debug/runtime/errors.js +6 -3
  57. package/dist/debug/runtime/ownership/RaphEffectScope.cjs +1 -0
  58. package/dist/debug/runtime/ownership/RaphEffectScope.js +171 -0
  59. package/dist/debug/runtime/ownership/RaphNode.cjs +1 -0
  60. package/dist/debug/runtime/ownership/RaphNode.js +206 -0
  61. package/dist/debug/runtime/ownership/RaphScope.cjs +1 -0
  62. package/dist/debug/runtime/ownership/RaphScope.js +101 -0
  63. package/dist/debug/runtime/ownership/parent-graph.types.cjs +1 -0
  64. package/dist/debug/runtime/ownership/parent-graph.types.js +1 -0
  65. package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -0
  66. package/dist/debug/runtime/phases/RaphPhasePipeline.js +587 -0
  67. package/dist/debug/runtime/phases/orderPhaseTasks.cjs +1 -0
  68. package/dist/debug/runtime/phases/orderPhaseTasks.js +59 -0
  69. package/dist/debug/runtime/reactivity/PathHandle.cjs +1 -0
  70. package/dist/debug/runtime/{PathHandle.js → reactivity/PathHandle.js} +75 -39
  71. package/dist/debug/runtime/reactivity/RaphMetaSource.cjs +1 -0
  72. package/dist/debug/runtime/reactivity/RaphMetaSource.js +112 -0
  73. package/dist/debug/runtime/reactivity/RaphWorkGraph.cjs +1 -0
  74. package/dist/debug/runtime/reactivity/RaphWorkGraph.js +995 -0
  75. package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -0
  76. package/dist/debug/runtime/reactivity/RuntimeReactivity.js +156 -0
  77. package/dist/debug/runtime/reactivity/RuntimeWatch.cjs +1 -0
  78. package/dist/debug/runtime/reactivity/RuntimeWatch.js +88 -0
  79. package/dist/debug/runtime/reactivity/runtime-reactivity.types.cjs +1 -0
  80. package/dist/debug/runtime/reactivity/runtime-reactivity.types.js +1 -0
  81. package/dist/entrypoints/machine-testing.d.ts +2 -0
  82. package/dist/entrypoints/machine.d.ts +5 -0
  83. package/dist/entrypoints/path.d.ts +14 -0
  84. package/dist/entrypoints/reactivity.d.ts +1 -0
  85. package/dist/entrypoints/runtime.d.ts +17 -0
  86. package/dist/index.cjs +1 -1
  87. package/dist/index.js +46 -38
  88. package/dist/machine/compiler.d.ts +71 -0
  89. package/dist/machine/core.d.ts +50 -0
  90. package/dist/machine/persistence.d.ts +5 -0
  91. package/dist/machine/runtime.d.ts +4 -0
  92. package/dist/machine/testing.d.ts +43 -0
  93. package/dist/machine/types.d.ts +155 -0
  94. package/dist/machine-testing.cjs +1 -0
  95. package/dist/machine-testing.js +188 -0
  96. package/dist/machine.cjs +1 -0
  97. package/dist/machine.js +837 -0
  98. package/dist/main.d.ts +20 -0
  99. package/dist/path/{data-path.d.ts → DataPath.d.ts} +16 -40
  100. package/dist/path/{path-router.d.ts → PathRouter.d.ts} +1 -1
  101. package/dist/path/RaphKernel.d.ts +13 -10
  102. package/dist/path/data-path.types.d.ts +34 -0
  103. package/dist/path/data-path.utils.d.ts +9 -0
  104. package/dist/path/{DerivedRegistry.d.ts → derived/DerivedRegistry.d.ts} +2 -2
  105. package/dist/path/{RaphDerivedHandle.d.ts → derived/RaphDerivedHandle.d.ts} +3 -3
  106. package/dist/path/derived/derived-collection.types.d.ts +12 -0
  107. package/dist/path/{derived-collection.d.ts → derived/derived-collection.utils.d.ts} +3 -13
  108. package/dist/path/{derived-strategies.d.ts → derived/derived-strategy.types.d.ts} +0 -3
  109. package/dist/path/derived/derived-strategy.utils.d.ts +4 -0
  110. package/dist/path/{MetaController.d.ts → meta/MetaController.d.ts} +4 -4
  111. package/dist/path/{RaphMeta.d.ts → meta/RaphMeta.d.ts} +2 -2
  112. package/dist/path/{RaphMetaStore.d.ts → meta/RaphMetaStore.d.ts} +1 -1
  113. package/dist/path/{meta.types.d.ts → meta/meta.types.d.ts} +2 -4
  114. package/dist/path/path.types.d.ts +3 -2
  115. package/dist/path/{segment-key.d.ts → pathSegmentKey.d.ts} +1 -1
  116. package/dist/path/{AdapterPathStore.d.ts → storage/AdapterPathStore.d.ts} +4 -4
  117. package/dist/path/{data-adapter.d.ts → storage/DefaultDataAdapter.d.ts} +2 -17
  118. package/dist/path/{PathEventHub.d.ts → storage/PathEventHub.d.ts} +9 -9
  119. package/dist/path/{PathStore.d.ts → storage/PathStore.d.ts} +3 -3
  120. package/dist/path/storage/data-adapter.types.d.ts +17 -0
  121. package/dist/path.cjs +1 -1
  122. package/dist/path.js +16 -16
  123. package/dist/raph.cjs +1 -1
  124. package/dist/raph.js +46 -38
  125. package/dist/reactivity/engine.d.ts +17 -3
  126. package/dist/reactivity/reactive-object.d.ts +36 -0
  127. package/dist/reactivity/types.d.ts +25 -0
  128. package/dist/reactivity.cjs +1 -1
  129. package/dist/reactivity.js +12 -12
  130. package/dist/runtime/RaphRuntime.d.ts +132 -192
  131. package/dist/runtime/diagnostics/RaphDebug.d.ts +239 -0
  132. package/dist/runtime/errors.d.ts +5 -0
  133. package/dist/runtime/ownership/RaphEffectScope.d.ts +29 -0
  134. package/dist/runtime/ownership/RaphNode.d.ts +40 -0
  135. package/dist/runtime/ownership/RaphScope.d.ts +38 -0
  136. package/dist/runtime/{parent-graph.d.ts → ownership/parent-graph.types.d.ts} +0 -1
  137. package/dist/runtime/ownership/parentGraph.d.ts +3 -0
  138. package/dist/runtime/phases/RaphPhasePipeline.d.ts +79 -0
  139. package/dist/runtime/phases/orderPhaseTasks.d.ts +6 -0
  140. package/dist/runtime/phases/phase.types.d.ts +92 -0
  141. package/dist/runtime/{PathHandle.d.ts → reactivity/PathHandle.d.ts} +14 -6
  142. package/dist/runtime/reactivity/RaphMetaSource.d.ts +32 -0
  143. package/dist/runtime/reactivity/RaphWorkGraph.d.ts +171 -0
  144. package/dist/runtime/{RuntimeReactivity.d.ts → reactivity/RuntimeReactivity.d.ts} +14 -9
  145. package/dist/runtime/{RuntimeWatch.d.ts → reactivity/RuntimeWatch.d.ts} +9 -3
  146. package/dist/runtime/{runtime-reactivity.types.d.ts → reactivity/runtime-reactivity.types.d.ts} +3 -1
  147. package/dist/runtime.cjs +1 -1
  148. package/dist/runtime.js +21 -16
  149. package/package.json +68 -35
  150. package/ReadMe.md +0 -153
  151. package/dist/api/public.d.ts +0 -22
  152. package/dist/debug/api/public.cjs +0 -1
  153. package/dist/debug/api/public.js +0 -40
  154. package/dist/debug/path/AdapterPathStore.cjs +0 -1
  155. package/dist/debug/path/DerivedRegistry.cjs +0 -1
  156. package/dist/debug/path/PathEventHub.cjs +0 -1
  157. package/dist/debug/path/PathStore.cjs +0 -1
  158. package/dist/debug/path/RaphMetaStore.cjs +0 -1
  159. package/dist/debug/path/data-adapter.cjs +0 -1
  160. package/dist/debug/path/data-path.cjs +0 -1
  161. package/dist/debug/path/derived-collection.cjs +0 -1
  162. package/dist/debug/path/path-router.cjs +0 -1
  163. package/dist/debug/path/public.cjs +0 -1
  164. package/dist/debug/path/public.js +0 -18
  165. package/dist/debug/runtime/PathHandle.cjs +0 -1
  166. package/dist/debug/runtime/RaphDebug.cjs +0 -1
  167. package/dist/debug/runtime/RaphDebug.js +0 -15
  168. package/dist/debug/runtime/RaphNode.cjs +0 -1
  169. package/dist/debug/runtime/RaphNode.js +0 -143
  170. package/dist/debug/runtime/RaphPhasePipeline.cjs +0 -1
  171. package/dist/debug/runtime/RaphPhasePipeline.js +0 -526
  172. package/dist/debug/runtime/RaphScope.cjs +0 -1
  173. package/dist/debug/runtime/RaphScope.js +0 -64
  174. package/dist/debug/runtime/RuntimeReactivity.cjs +0 -1
  175. package/dist/debug/runtime/RuntimeReactivity.js +0 -154
  176. package/dist/debug/runtime/RuntimeWatch.cjs +0 -1
  177. package/dist/debug/runtime/RuntimeWatch.js +0 -71
  178. package/dist/debug/runtime/public.cjs +0 -1
  179. package/dist/debug/runtime/public.js +0 -18
  180. package/dist/path/public.d.ts +0 -14
  181. package/dist/runtime/RaphDebug.d.ts +0 -32
  182. package/dist/runtime/RaphNode.d.ts +0 -68
  183. package/dist/runtime/RaphPhasePipeline.d.ts +0 -133
  184. package/dist/runtime/RaphScope.d.ts +0 -50
  185. package/dist/runtime/phase.types.d.ts +0 -49
  186. package/dist/runtime/public.d.ts +0 -13
  187. /package/dist/debug/path/{meta.types.cjs → data-path.types.cjs} +0 -0
  188. /package/dist/debug/path/{meta.types.js → data-path.types.js} +0 -0
  189. /package/dist/debug/path/{RaphDerivedHandle.cjs → derived/RaphDerivedHandle.cjs} +0 -0
  190. /package/dist/debug/path/{RaphDerivedHandle.js → derived/RaphDerivedHandle.js} +0 -0
  191. /package/dist/debug/{runtime/runtime-reactivity.types.cjs → path/derived/derived-collection.types.cjs} +0 -0
  192. /package/dist/debug/{runtime/runtime-reactivity.types.js → path/derived/derived-collection.types.js} +0 -0
  193. /package/dist/debug/path/{derived-strategies.cjs → derived/derived-strategy.utils.cjs} +0 -0
  194. /package/dist/debug/path/{derived-strategies.js → derived/derived-strategy.utils.js} +0 -0
  195. /package/dist/debug/path/{RaphMeta.cjs → meta/RaphMeta.cjs} +0 -0
  196. /package/dist/debug/path/{RaphMeta.js → meta/RaphMeta.js} +0 -0
  197. /package/dist/debug/path/{segment-key.cjs → pathSegmentKey.cjs} +0 -0
  198. /package/dist/debug/path/{segment-key.js → pathSegmentKey.js} +0 -0
  199. /package/dist/debug/path/{data-draft.cjs → storage/createDataDraft.cjs} +0 -0
  200. /package/dist/debug/path/{data-draft.js → storage/createDataDraft.js} +0 -0
  201. /package/dist/debug/runtime/{parent-graph.cjs → ownership/parentGraph.cjs} +0 -0
  202. /package/dist/debug/runtime/{parent-graph.js → ownership/parentGraph.js} +0 -0
  203. /package/dist/debug/runtime/{disposal.cjs → ownership/throwDisposalErrors.cjs} +0 -0
  204. /package/dist/debug/runtime/{disposal.js → ownership/throwDisposalErrors.js} +0 -0
  205. /package/dist/debug/runtime/{RaphFrameLoop.cjs → phases/RaphFrameLoop.cjs} +0 -0
  206. /package/dist/debug/runtime/{RaphFrameLoop.js → phases/RaphFrameLoop.js} +0 -0
  207. /package/dist/debug/runtime/{phase.types.cjs → phases/phase.types.cjs} +0 -0
  208. /package/dist/debug/runtime/{phase.types.js → phases/phase.types.js} +0 -0
  209. /package/dist/path/{data-draft.d.ts → storage/createDataDraft.d.ts} +0 -0
  210. /package/dist/runtime/{disposal.d.ts → ownership/throwDisposalErrors.d.ts} +0 -0
  211. /package/dist/runtime/{RaphFrameLoop.d.ts → phases/RaphFrameLoop.d.ts} +0 -0
@@ -0,0 +1,206 @@
1
+ var y = Object.defineProperty;
2
+ var b = (o, h, t) => h in o ? y(o, h, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[h] = t;
3
+ var l = (o, h, t) => b(o, typeof h != "symbol" ? h + "" : h, t);
4
+ import { RaphCrossRuntimeError as a } from "../errors.js";
5
+ import { RaphScope as w } from "./RaphScope.js";
6
+ import { throwDisposalErrors as v } from "./throwDisposalErrors.js";
7
+ let g = 0;
8
+ const _ = Symbol("RaphProvisionalNode");
9
+ class c extends w {
10
+ constructor(t, e = {}, i, r) {
11
+ const s = i ?? (t instanceof c ? t.runtime : t ?? void 0);
12
+ if (s === void 0)
13
+ throw new Error("[RaphNode] A root node requires an explicit runtime.");
14
+ const n = t instanceof c ? t : (t == null ? void 0 : t.root) ?? null;
15
+ if (n !== null && n.runtime !== s)
16
+ throw new a("[Raph] Parent belongs to another runtime.");
17
+ n == null || n._assertAlive();
18
+ const d = e.priority ?? 0;
19
+ p(d);
20
+ super(e.id ?? `node-${g++}`, s);
21
+ l(this, "priority");
22
+ l(this, "_parent");
23
+ l(this, "_children", []);
24
+ l(this, "_published");
25
+ l(this, "api");
26
+ l(this, "meta");
27
+ l(this, "type");
28
+ /** Distinguishes a subtree granule from the node's self granule. @internal */
29
+ l(this, "_subtreeSourceIdentity", Object.freeze({}));
30
+ this.priority = d, this._parent = n, this.meta = { ...e.meta }, this.type = e.type ?? "default", this.api = Object.freeze({});
31
+ const f = r === _;
32
+ if (this._published = n === null || !f && n._published, n !== null) {
33
+ const m = n._children.length;
34
+ if (n._children.push(this), !this._published)
35
+ return;
36
+ s._notifyNodeStructure(this, {
37
+ node: this,
38
+ newIndex: m,
39
+ newParent: n
40
+ }, [], u(this)), this._assertAlive();
41
+ }
42
+ }
43
+ get node() {
44
+ return this;
45
+ }
46
+ get parent() {
47
+ return this._parent;
48
+ }
49
+ get children() {
50
+ return this._children;
51
+ }
52
+ addChild(t) {
53
+ if (this._assertAlive(), t._assertAlive(), t.runtime !== this.runtime)
54
+ throw new a("[Raph] Child belongs to another runtime.");
55
+ if (this === t)
56
+ throw new Error("[Raph] A node cannot become its own ancestor.");
57
+ if (!t._published || !this._published)
58
+ throw new Error("[Raph] A provisional node cannot be reparented before setup commits.");
59
+ for (let e = this; e !== null; e = e.parent)
60
+ if (e === t)
61
+ throw new Error("[Raph] A node cannot become its own ancestor.");
62
+ return t.parent === this ? !0 : this.runtime._runNodeMutation(() => {
63
+ this.runtime._assertNodeReparentAllowed(t, this);
64
+ const e = u(t), i = t._parent, r = i == null ? void 0 : i._children.indexOf(t);
65
+ i !== null && r !== void 0 && r >= 0 && i._children.splice(r, 1), t._parent = this;
66
+ const s = this._children.length;
67
+ return this._children.push(t), this.runtime._notifyNodeStructure(t, {
68
+ node: t,
69
+ ...i === null ? {} : { oldParent: i },
70
+ ...r === void 0 || r < 0 ? {} : { oldIndex: r },
71
+ newParent: this,
72
+ newIndex: s
73
+ }, e, u(t)), !0;
74
+ });
75
+ }
76
+ reorderChildren(t) {
77
+ if (this._assertAlive(), t.length !== this._children.length || new Set(t).size !== t.length)
78
+ throw new Error("[Raph] Child order must contain every direct child exactly once.");
79
+ for (const e of t)
80
+ if (e._assertAlive(), e._parent !== this)
81
+ throw new Error("[Raph] Child order can contain only direct children of the node.");
82
+ this.runtime._runNodeMutation(() => {
83
+ const e = new Map(this._children.map((i, r) => [i, r]));
84
+ this._children.splice(0, this._children.length, ...t);
85
+ for (let i = 0; i < t.length; i++) {
86
+ const r = t[i], s = e.get(r);
87
+ if (s === i)
88
+ continue;
89
+ const n = u(r);
90
+ this.runtime._notifyNodeStructure(r, {
91
+ node: r,
92
+ oldParent: this,
93
+ newParent: this,
94
+ oldIndex: s,
95
+ newIndex: i
96
+ }, n, n);
97
+ }
98
+ });
99
+ }
100
+ options(t) {
101
+ this._assertAlive(), t.meta !== void 0 && (this.meta = { ...t.meta }), t.priority !== void 0 && (p(t.priority), this.priority = t.priority), t.type !== void 0 && (this.type = t.type), this.touch(Object.freeze({ options: Object.freeze({ ...t }) }));
102
+ }
103
+ /** Invalidates coarse self/subtree/runtime granules for non-reactive state. */
104
+ touch(t) {
105
+ this._assertAlive(), this.runtime._runNodeMutation(() => this.runtime._notifyNodeTouch(this, t));
106
+ }
107
+ remove() {
108
+ this.dispose();
109
+ }
110
+ dispose() {
111
+ if (this._disposed || this._disposing)
112
+ return;
113
+ this._disposing = !0, this.runtime._beginOwnerDisposal();
114
+ const t = [];
115
+ try {
116
+ for (const s of [...this._children])
117
+ try {
118
+ s.dispose();
119
+ } catch (n) {
120
+ t.push(n);
121
+ }
122
+ this._children.length = 0;
123
+ const e = this._parent, i = u(this), r = e == null ? void 0 : e._children.indexOf(this);
124
+ if (e !== null && r !== void 0 && r >= 0 && e._children.splice(r, 1), this._parent = null, this._published)
125
+ try {
126
+ this.runtime._notifyNodeStructure(this, {
127
+ node: this,
128
+ ...e === null ? {} : { oldParent: e },
129
+ ...r === void 0 || r < 0 ? {} : { oldIndex: r }
130
+ }, i, []);
131
+ } catch (s) {
132
+ t.push(s);
133
+ }
134
+ try {
135
+ super.dispose();
136
+ } catch (s) {
137
+ t.push(s);
138
+ }
139
+ this._published = !1;
140
+ try {
141
+ this.runtime._releaseNode(this);
142
+ } catch (s) {
143
+ t.push(s);
144
+ }
145
+ } finally {
146
+ try {
147
+ this.runtime._endOwnerDisposal();
148
+ } catch (e) {
149
+ t.push(e);
150
+ }
151
+ }
152
+ v(t, `[Raph] Node "${this.id}" disposal failed.`);
153
+ }
154
+ /** @internal */
155
+ _setApi(t) {
156
+ const e = typeof t == "object" && t !== null ? Object.freeze(t) : t;
157
+ Object.defineProperty(this, "api", {
158
+ configurable: !1,
159
+ enumerable: !0,
160
+ value: e,
161
+ writable: !1
162
+ });
163
+ }
164
+ /** Publishes a fully initialized provisional subtree. @internal */
165
+ _publishCreation() {
166
+ if (this._published)
167
+ return;
168
+ const t = this._parent;
169
+ if (t === null || !t._published)
170
+ return;
171
+ this._published = !0;
172
+ const e = t._children.indexOf(this);
173
+ try {
174
+ this.runtime._notifyNodeStructure(this, {
175
+ node: this,
176
+ newIndex: e,
177
+ newParent: t
178
+ }, [], u(this));
179
+ for (const i of this._children)
180
+ i._publishCreation();
181
+ } catch (i) {
182
+ throw this._published = !1, i;
183
+ }
184
+ }
185
+ /** @internal */
186
+ _isPublished() {
187
+ return this._published;
188
+ }
189
+ }
190
+ function O(o, h, t) {
191
+ return new c(o, h, t, _);
192
+ }
193
+ function u(o) {
194
+ const h = [];
195
+ for (let t = o; t !== null; t = t.parent)
196
+ h.push(t);
197
+ return h;
198
+ }
199
+ function p(o) {
200
+ if (!Number.isFinite(o))
201
+ throw new TypeError("[Raph] Node priority must be finite.");
202
+ }
203
+ export {
204
+ c as RaphNode,
205
+ O as createProvisionalNode
206
+ };
@@ -0,0 +1 @@
1
+ "use strict";var u=Object.defineProperty;var n=(i,s,e)=>s in i?u(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e;var r=(i,s,e)=>n(i,typeof s!="symbol"?s+"":s,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../../reactivity/scope.cjs"),c=require("../errors.cjs"),d=require("./throwDisposalErrors.cjs");class _{constructor(s,e){r(this,"id");r(this,"runtime");r(this,"_resources");r(this,"_disposed",!1);r(this,"_disposing",!1);this.id=s,this.runtime=e,this._resources=new h.ScopeNode(e._getReactivity()),e._registerOwner(this)}get disposed(){return this._disposed}get active(){return!this._disposed&&!this._disposing}get node(){}signal(s){return this._assertAlive(),this.runtime.signal(s,this)}computed(s){return this._assertAlive(),typeof s=="function"?this.runtime.computed(s,this):this.runtime.computed(s,this)}effect(s,e,t){return this._assertAlive(),this.runtime.effect(this,s,e,t)}watch(s,e,t,o){return this._assertAlive(),this.runtime.watch(this,s,e,t,o)}aggregate(s){return this._assertAlive(),this.runtime.aggregate(this,s)}action(s,e){return this._assertAlive(),typeof s=="function"?this.runtime.action(s,this):this.runtime.action(s,e,this)}own(s){return this.active?this._resources._own(s):(s(),a)}dispose(){if(this._disposed)return;this._disposed=!0,this._disposing=!0;const s=!this.runtime._ownerDisposalActive();s&&this.runtime._beginOwnerDisposal();const e=[];try{try{this._resources.dispose()}catch(t){e.push(t)}}finally{this._disposing=!1;try{this.runtime._unregisterOwner(this)}catch(t){e.push(t)}if(s)try{this.runtime._endOwnerDisposal()}catch(t){e.push(t)}}d.throwDisposalErrors(e,`[Raph] Scope "${this.id}" disposal failed.`)}_adoptResource(s){return this._assertAlive(),this._resources._adoptResource(s)}_adoptSource(s){return this._assertAlive(),this._resources._adoptSource(s)}_debugResourceCount(){return this._resources._debugResourceCount()}_debugSourceCount(){return this._resources._debugSourceCount()}_assertAlive(){if(this._disposed||this._disposing)throw new c.RaphDisposedError(`[Raph] Owner "${this.id}" is disposed.`)}}function a(){}exports.RaphScope=_;
@@ -0,0 +1,101 @@
1
+ var h = Object.defineProperty;
2
+ var u = (i, s, t) => s in i ? h(i, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[s] = t;
3
+ var r = (i, s, t) => u(i, typeof s != "symbol" ? s + "" : s, t);
4
+ import { ScopeNode as n } from "../../reactivity/scope.js";
5
+ import { RaphDisposedError as c } from "../errors.js";
6
+ import { throwDisposalErrors as d } from "./throwDisposalErrors.js";
7
+ class f {
8
+ constructor(s, t) {
9
+ r(this, "id");
10
+ r(this, "runtime");
11
+ r(this, "_resources");
12
+ r(this, "_disposed", !1);
13
+ r(this, "_disposing", !1);
14
+ this.id = s, this.runtime = t, this._resources = new n(t._getReactivity()), t._registerOwner(this);
15
+ }
16
+ get disposed() {
17
+ return this._disposed;
18
+ }
19
+ get active() {
20
+ return !this._disposed && !this._disposing;
21
+ }
22
+ /** Stable selector for process ordering; plain scopes are not tree nodes. */
23
+ get node() {
24
+ }
25
+ signal(s) {
26
+ return this._assertAlive(), this.runtime.signal(s, this);
27
+ }
28
+ computed(s) {
29
+ return this._assertAlive(), typeof s == "function" ? this.runtime.computed(s, this) : this.runtime.computed(s, this);
30
+ }
31
+ effect(s, t, e) {
32
+ return this._assertAlive(), this.runtime.effect(this, s, t, e);
33
+ }
34
+ watch(s, t, e, o) {
35
+ return this._assertAlive(), this.runtime.watch(this, s, t, e, o);
36
+ }
37
+ aggregate(s) {
38
+ return this._assertAlive(), this.runtime.aggregate(this, s);
39
+ }
40
+ action(s, t) {
41
+ return this._assertAlive(), typeof s == "function" ? this.runtime.action(s, this) : this.runtime.action(s, t, this);
42
+ }
43
+ own(s) {
44
+ return this.active ? this._resources._own(s) : (s(), _);
45
+ }
46
+ dispose() {
47
+ if (this._disposed)
48
+ return;
49
+ this._disposed = !0, this._disposing = !0;
50
+ const s = !this.runtime._ownerDisposalActive();
51
+ s && this.runtime._beginOwnerDisposal();
52
+ const t = [];
53
+ try {
54
+ try {
55
+ this._resources.dispose();
56
+ } catch (e) {
57
+ t.push(e);
58
+ }
59
+ } finally {
60
+ this._disposing = !1;
61
+ try {
62
+ this.runtime._unregisterOwner(this);
63
+ } catch (e) {
64
+ t.push(e);
65
+ }
66
+ if (s)
67
+ try {
68
+ this.runtime._endOwnerDisposal();
69
+ } catch (e) {
70
+ t.push(e);
71
+ }
72
+ }
73
+ d(t, `[Raph] Scope "${this.id}" disposal failed.`);
74
+ }
75
+ /** @internal */
76
+ _adoptResource(s) {
77
+ return this._assertAlive(), this._resources._adoptResource(s);
78
+ }
79
+ /** @internal */
80
+ _adoptSource(s) {
81
+ return this._assertAlive(), this._resources._adoptSource(s);
82
+ }
83
+ /** @internal */
84
+ _debugResourceCount() {
85
+ return this._resources._debugResourceCount();
86
+ }
87
+ /** @internal */
88
+ _debugSourceCount() {
89
+ return this._resources._debugSourceCount();
90
+ }
91
+ /** @internal */
92
+ _assertAlive() {
93
+ if (this._disposed || this._disposing)
94
+ throw new c(`[Raph] Owner "${this.id}" is disposed.`);
95
+ }
96
+ }
97
+ function _() {
98
+ }
99
+ export {
100
+ f as RaphScope
101
+ };
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ "use strict";var q=Object.defineProperty;var D=(l,e,s)=>e in l?q(l,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):l[e]=s;var d=(l,e,s)=>D(l,typeof e!="symbol"?e+"":e,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../errors.cjs"),g=Object.freeze([]),k=Object.freeze({now:0,delta:0,elapsed:0,frame:0}),A=1e4,R=1e4,E=Symbol("RaphPhaseTaskRecord");class x{constructor(e,s,t,i=()=>!1,n){d(this,"_phases",[]);d(this,"_phaseByName",new Map);d(this,"_phaseBindings",new Map);d(this,"_queues",new Map);d(this,"_deferred",new Set);d(this,"_idleWaiters",new Set);d(this,"_taskSequence",0);d(this,"_scheduled",!1);d(this,"_scheduleToken",0);d(this,"_frameHandle");d(this,"_frameHandleKind");d(this,"_configurationLocked",!1);d(this,"_running",!1);d(this,"_disposed",!1);d(this,"_firstFrameAt");d(this,"_lastFrameAt");d(this,"_frameNumber",0);d(this,"_frame",k);this._scheduler=e,this._runUntracked=s,this._resolveCause=t,this._deferSync=i,this._tracePhase=n}get frame(){return this._frame}get phases(){return this._phases.map(e=>e.phase)}definePhases(e){if(this._assertAlive(),this._configurationLocked||this._firstFrameAt!==void 0)throw new Error("[Raph] Cannot redefine phases after phase pipeline execution has started.");const s=new Map,t=[];for(const i of e){const n=i.name.trim();if(!n)throw new Error("[Raph] Phase name must not be empty.");if(s.has(n))throw new Error(`[Raph] Duplicate phase name "${n}".`);if(i.process!==void 0&&typeof i.process!="function")throw new TypeError(`[Raph] Phase "${n}" process must be a function.`);const a=Object.freeze({name:n,...i.process===void 0?{}:{process:i.process}}),r={index:t.length,phase:a};t.push(r),s.set(n,r)}this._assertRetainedPhases(s),this._phases=t,this._phaseByName=s}addPhase(e){this.definePhases([...this.phases,e])}clearPhases(){this.definePhases([])}requirePhase(e){if(this._assertAlive(),!this._phaseByName.has(e))throw new Error(`[Raph] Phase "${e}" is not defined.`)}bindTask(e,s,t,i,n){const a=e.trim();if(this.requirePhase(a),!Number.isFinite(i))throw new TypeError("[Raph] Effect priority must be finite.");this._phaseBindings.set(a,(this._phaseBindings.get(a)??0)+1);const r={},h=this._createTask(r);Object.assign(r,{active:!0,paused:!1,pending:!1,deferred:!1,inDelivery:!1,discardAcknowledged:!1,requested:!1,resolution:"unresolved",deferCount:0,sequence:0,phase:a,priority:i,consumerOwner:s,effect:t,runner:n,task:h,deliveryCauses:g,frame:k});const f={dependencyOwner:s,allowScheduleDuringRun:!0,task:h,notify:o=>{const _=this._resolveCause(o);if(_!==void 0){const c=_.kind==="structure"?_.source:o;this._appendCause(r,_,c)}},schedule:()=>this._queue(r),enqueue:(o,_=o.source,c=!0)=>{this._appendCause(r,o,_),this._queue(r,c)},pause:()=>this._pauseTask(r),resume:()=>this._resumeTask(r),dispose:()=>this._disposeTask(r)};return r.binding=f,f}request(){this._assertAlive(),this._hasQueued()&&this._schedule()}afterFlush(){return this._assertAlive(),!this._running&&!this._scheduled&&!this._hasPending()?Promise.resolve():new Promise((e,s)=>{this._idleWaiters.add({reject:s,resolve:e})})}flush(){var n,a,r;if(this._assertAlive(),this._cancelScheduled(),this._running)return;if(!this._hasQueued()&&this._deferred.size!==0&&this._activateDeferred(),!this._hasQueued()){this._settleIdleWaiters(void 0,!1);return}this._configurationLocked=!0,this._running=!0;const e=[],s=this._nextFrame();let t=0;try{for(;this._hasQueued();){if(++t>A){const h=this._describeQueued();this._cancelAllQueued(!0,e),e.push(new Error(`[Raph] Phase flush exceeded 10000 passes.${h?` Pending: ${h}.`:""}`));break}for(const h of this._phases){if(this._disposed)break;const f=this._takePhase(h.phase.name);if(f.length===0)continue;const o=e.length;(n=this._tracePhase)==null||n.call(this,h.phase.name,"start");let _=0,c=!0,p;for(const u of f){if(u.pending=!1,!u.active||u.consumerOwner.disposed){this._disposeTask(u);continue}this._beginDelivery(u,s),p!==void 0&&(u.priority>p.priority||u.priority===p.priority&&u.sequence<p.sequence)&&(c=!1),p=u,f[_++]=u}if(f.length=_,f.length===0)continue;c||f.sort(K);const P=h.phase.process;if(P===void 0)for(const u of f)try{this._runDelivery(u)}catch(m){e.push(m)}else{const u=[];for(const w of f)u.push(w.task);const m=Object.freeze({phase:h.phase.name,frame:s,tasks:Object.freeze(u)});try{this._runUntracked(()=>P(m))}catch(w){e.push(w)}}let y=0;for(const u of f){if(u.resolution==="unresolved"){y++;try{this._deferDelivery(u)}catch(m){u.resolution="cancel",this._acknowledgeDiscard(u,!0,e),e.push(m)}}try{this._finishDelivery(u)}catch(m){u.resolution!=="run"&&this._acknowledgeDiscard(u,!0,e),u.resolution="cancel",u.inDelivery=!1,u.deliveryFirstCauseKey=void 0,u.deliveryExtraCauseKeys=void 0,u.deliveryCauses=g,e.push(m)}}y!==0&&e.push(new v.RaphPhaseProcessError(`[Raph] Phase "${h.phase.name}" left ${y} task(s) unresolved; they were deferred.`)),e.length===o?(a=this._tracePhase)==null||a.call(this,h.phase.name,"end"):(r=this._tracePhase)==null||r.call(this,h.phase.name,"error",e[e.length-1])}}}catch(h){e.push(h),this._cancelAllQueued(!0,e),this._cancelAllDeferred(!0,e)}finally{this._running=!1}try{this._deferred.size!==0&&this._scheduleDeferredTurn()}catch(h){e.push(h)}const i=e.length===1?e[0]:e.length>1?new AggregateError(e,"[Raph] Multiple phase tasks failed."):void 0;if(i!==void 0)throw this._settleIdleWaiters(i,!0),i;this._settleIdleWaiters(void 0,!1)}dispose(){if(this._disposed)return;this._disposed=!0,this._cancelScheduled(),this._cancelAllQueued(!1);const e=[...this._deferred];this._cancelAllDeferred(!1);for(const t of e)t.active=!1;this._phaseBindings.clear(),this._phases=[],this._phaseByName.clear();const s=new v.RaphDisposedError("[Raph] Phase pipeline is disposed.");this._settleIdleWaiters(s,!0)}_debugPending(){return this._scheduled||this._running||this._hasPending()}_describeQueued(){var s;const e=[];for(const t of this._phases){const i=((s=this._queues.get(t.phase.name))==null?void 0:s.filter(a=>a.active&&!a.consumerOwner.disposed))??[];if(i.length===0)continue;const n=i.slice(0,3).map(a=>{var c,p;const r=a.consumerOwner.node,h=r===void 0?void 0:r.componentId,f=r===void 0?a.consumerOwner.id:`${a.consumerOwner.id}/${r.constructor.name}/${r.type}${typeof h=="string"?`/${h}`:""}`,o=(p=(c=a.firstCause)==null?void 0:c.sourceOwner)==null?void 0:p.node,_=o===void 0?"":`<=${o.id}/${o.constructor.name}`;return`${f}${a.firstCause?`:${a.firstCause.kind}${_}`:""}`}).join(", ");e.push(`${t.phase.name}=${i.length}${n?` [${n}]`:""}`)}return e.join("; ")}_createTask(e){const s={get phase(){return e.phase},get consumerOwner(){return e.consumerOwner},get effect(){return e.effect},get causes(){return e.deliveryCauses},get frame(){return e.frame},get priority(){return e.priority},get sequence(){return e.sequence},run:()=>this._runDelivery(e),defer:()=>this._deferDelivery(e),cancel:()=>this._cancelDelivery(e)};return Object.defineProperty(s,E,{value:e}),Object.freeze(s)}_beginDelivery(e,s){e.pending=!1,e.inDelivery=!0,e.discardAcknowledged=!1,e.requested=!1,e.resolution="unresolved",e.frame=s;const t=e.firstCause;if(t===void 0){e.deliveryFirstCauseKey=void 0,e.deliveryExtraCauseKeys=void 0,e.deliveryCauses=g;return}const i=e.extraCauses;if(e.deliveryFirstCauseKey=e.firstCauseKey,e.firstCause=void 0,e.firstCauseKey=void 0,e.extraCauses=void 0,i===void 0||i.size===0){e.deliveryExtraCauseKeys=void 0,e.deliveryCauses=Object.freeze([t]);return}e.deliveryExtraCauseKeys=Object.freeze([...i.keys()]),e.deliveryCauses=Object.freeze([t,...i.values()])}_runDelivery(e){if(!e.active||e.paused||e.consumerOwner.disposed){e.resolution="cancel";return}this._assertDelivery(e),e.resolution="run",e.deferCount=0,this._runUntracked(e.runner)}_deferDelivery(e){if(!e.active||e.paused||e.consumerOwner.disposed){e.resolution="cancel";return}if(this._assertDelivery(e),e.resolution="defer",++e.deferCount>R){e.resolution="cancel";const s=[];throw this._acknowledgeDiscard(e,!0,s),s.length!==0?new AggregateError([new v.RaphPhaseProcessError(`[Raph] Phase task in "${e.phase}" exceeded 10000 deferred deliveries.`),...s],"[Raph] Phase task defer limit and recovery failed."):new v.RaphPhaseProcessError(`[Raph] Phase task in "${e.phase}" exceeded 10000 deferred deliveries.`)}}_cancelDelivery(e){if(!e.active||e.consumerOwner.disposed){e.resolution="cancel";return}this._assertDelivery(e);const s=[];if(this._acknowledgeDiscard(e,!1,s),s.length!==0)throw s.length===1?s[0]:new AggregateError(s,"[Raph] Phase task cancellation failed.");e.discardAcknowledged&&(e.requested=C(e)),e.resolution="cancel",e.deferCount=0}_finishDelivery(e){var t;if(!e.inDelivery)return;const s=e.resolution;if(e.inDelivery=!1,!e.active||e.consumerOwner.disposed){e.deliveryFirstCauseKey=void 0,e.deliveryExtraCauseKeys=void 0,e.deliveryCauses=g;return}if(e.paused){s!=="run"&&!(s==="cancel"&&e.discardAcknowledged)&&(this._restoreDeliveryCausesBeforePending(e),e.requested=!0),e.deliveryFirstCauseKey=void 0,e.deliveryExtraCauseKeys=void 0,e.deliveryCauses=g;return}if(s==="defer"&&(this._restoreDeliveryCausesBeforePending(e),e.deferred=!0,this._deferred.add(e)),e.deliveryFirstCauseKey=void 0,e.deliveryExtraCauseKeys=void 0,e.deliveryCauses=g,s!=="defer"&&(e.requested||C(e))){const i=(t=e.binding)==null?void 0:t.rearmPending;i===void 0?this._queue(e):i()}}_appendCause(e,s,t){if(!e.active)return;const i=e.firstCause;if(i===void 0){e.firstCause=s,e.firstCauseKey=t;return}if(e.firstCauseKey===t){e.firstCause=b(i,s);return}const n=e.extraCauses??(e.extraCauses=new Map),a=n.get(t);n.set(t,a===void 0?s:b(a,s))}_queue(e,s=!0){if(!e.active||e.consumerOwner.disposed||this._disposed)return;if(e.paused){e.requested=!0;return}if(e.inDelivery){e.requested=!0;return}if(e.pending){s&&this._schedule();return}if(e.deferred)return;e.discardAcknowledged=!1,e.pending=!0,e.sequence=this._taskSequence++;let t=this._queues.get(e.phase);t===void 0&&(t=[],this._queues.set(e.phase,t)),t.push(e),s&&this._schedule()}_disposeTask(e){var i;if(!e.active)return;e.active=!1,e.binding!==void 0&&(delete e.binding.cancelPending,delete e.binding.rearmPending,delete e.binding.abort,delete e.binding),e.pending=!1,e.deferred=!1,e.inDelivery&&(e.resolution="cancel"),e.firstCause=void 0,e.firstCauseKey=void 0,(i=e.extraCauses)==null||i.clear(),e.extraCauses=void 0,e.deliveryFirstCauseKey=void 0,e.deliveryExtraCauseKeys=void 0,e.deliveryCauses=g,this._deferred.delete(e);const s=this._queues.get(e.phase);if(s!==void 0){const n=s.indexOf(e);n>=0&&s.splice(n,1),s.length===0&&this._queues.delete(e.phase)}const t=(this._phaseBindings.get(e.phase)??1)-1;t===0?this._phaseBindings.delete(e.phase):this._phaseBindings.set(e.phase,t),this._hasPending()||this._cancelScheduled(),this._settleIdleWaiters(void 0,!1)}_pauseTask(e){if(!e.active||e.paused)return;e.paused=!0,e.requested=e.requested||e.pending||e.deferred||e.inDelivery&&e.resolution!=="run"&&!(e.resolution==="cancel"&&e.discardAcknowledged),e.pending=!1,e.deferred&&(e.deferred=!1,this._deferred.delete(e));const s=this._queues.get(e.phase);if(s!==void 0){const t=s.indexOf(e);t>=0&&s.splice(t,1),s.length===0&&this._queues.delete(e.phase)}this._hasPending()||this._cancelScheduled(),this._settleIdleWaiters(void 0,!1)}_resumeTask(e){!e.active||!e.paused||e.consumerOwner.disposed||(e.paused=!1,(e.requested||C(e))&&(e.requested=!1,this._queue(e)))}_restoreDeliveryCausesBeforePending(e){const s=e.deliveryCauses;if(s.length===0)return;const t=e.firstCause,i=e.firstCauseKey,n=e.extraCauses;e.firstCause=void 0,e.firstCauseKey=void 0,e.extraCauses=void 0,this._appendCause(e,s[0],e.deliveryFirstCauseKey);const a=e.deliveryExtraCauseKeys;for(let r=1;r<s.length;r++)this._appendCause(e,s[r],a[r-1]);if(t!==void 0&&(this._appendCause(e,t,i),n!==void 0))for(const[r,h]of n)this._appendCause(e,h,r)}_takePhase(e){const s=this._queues.get(e);return s===void 0?[]:(this._queues.delete(e),s)}_schedule(){if(this._running||this._scheduled||this._disposed)return;if(this._scheduler==="sync"){if(this._deferSync())return;this.flush();return}this._scheduled=!0;const e=++this._scheduleToken,s=()=>{this._disposed||!this._scheduled||e!==this._scheduleToken||(this._scheduled=!1,this._frameHandle=void 0,this._frameHandleKind=void 0,this.flush())};if(this._scheduler==="microtask"){queueMicrotask(s);return}typeof globalThis.requestAnimationFrame=="function"?(this._frameHandleKind="animation-frame",this._frameHandle=globalThis.requestAnimationFrame(s)):(this._frameHandleKind="timeout",this._frameHandle=setTimeout(s,16))}_scheduleDeferredTurn(){if(this._scheduled||this._disposed)return;this._scheduled=!0;const e=++this._scheduleToken,s=()=>{this._disposed||!this._scheduled||e!==this._scheduleToken||(this._scheduled=!1,this._frameHandle=void 0,this._frameHandleKind=void 0,this._activateDeferred(),this._hasQueued()?this.flush():this._settleIdleWaiters(void 0,!1))};this._scheduler==="animationFrame"?typeof globalThis.requestAnimationFrame=="function"?(this._frameHandleKind="animation-frame",this._frameHandle=globalThis.requestAnimationFrame(s)):(this._frameHandleKind="timeout",this._frameHandle=setTimeout(s,16)):queueMicrotask(s)}_cancelScheduled(){var e;this._scheduled&&(this._scheduled=!1,this._scheduleToken++,this._frameHandleKind==="animation-frame"&&this._frameHandle!==void 0?(e=globalThis.cancelAnimationFrame)==null||e.call(globalThis,this._frameHandle):this._frameHandleKind==="timeout"&&this._frameHandle!==void 0&&clearTimeout(this._frameHandle),this._frameHandle=void 0,this._frameHandleKind=void 0)}_activateDeferred(){const e=[...this._deferred];this._deferred.clear();for(const s of e)s.deferred=!1,this._queue(s,!1)}_nextFrame(){var t;const e=((t=globalThis.performance)==null?void 0:t.now())??Date.now();if(this._firstFrameAt===void 0||this._lastFrameAt===void 0)return this._firstFrameAt=e,this._lastFrameAt=e,this._frame=Object.freeze({now:e,delta:0,elapsed:0,frame:0});this._frameNumber++;const s=Object.freeze({now:e,delta:Math.min(Math.max(e-this._lastFrameAt,0),100),elapsed:Math.max(e-this._firstFrameAt,0),frame:this._frameNumber});return this._lastFrameAt=e,this._frame=s}_assertRetainedPhases(e){for(const s of this._phaseBindings.keys())if(!e.has(s))throw new Error(`[Raph] Cannot remove phase "${s}" while it is still bound.`);for(const s of this._queues.keys())if(!e.has(s))throw new Error(`[Raph] Cannot remove phase "${s}" while it has pending work.`)}_assertDelivery(e){if(!e.active||!e.inDelivery||e.resolution!=="unresolved")throw new v.RaphPhaseProcessError("[Raph] Phase task delivery is already resolved.")}_hasQueued(){for(const e of this._queues.values())if(e.some(s=>s.active&&s.pending))return!0;return!1}_hasPending(){return this._hasQueued()||this._deferred.size!==0}_cancelAllQueued(e,s=[]){const t=new Set;for(const i of this._queues.values())for(const n of i)t.add(n);this._queues.clear();for(const i of t)i.pending=!1,e&&this._acknowledgeDiscard(i,!0,s),this._clearPendingDelivery(i)}_cancelAllDeferred(e,s=[]){const t=[...this._deferred];this._deferred.clear();for(const i of t)i.deferred=!1,e&&this._acknowledgeDiscard(i,!0,s),this._clearPendingDelivery(i)}_acknowledgeDiscard(e,s,t){if(e.discardAcknowledged)return;const i=e.binding,n=i==null?void 0:i.cancelPending;if(n===void 0){e.discardAcknowledged=!0;return}try{if(n()){e.discardAcknowledged=!0;return}if(!s){t.push(new v.RaphPhaseProcessError(`[Raph] Initial effect delivery in "${e.phase}" cannot be cancelled before dependency collection.`));return}const a=i==null?void 0:i.abort;if(a===void 0){t.push(new v.RaphPhaseProcessError(`[Raph] Initial effect delivery in "${e.phase}" could not be aborted safely.`));return}a(),e.discardAcknowledged=!0}catch(a){t.push(a)}}_clearPendingDelivery(e){var s;e.requested=!1,e.firstCause=void 0,e.firstCauseKey=void 0,(s=e.extraCauses)==null||s.clear(),e.extraCauses=void 0}_settleIdleWaiters(e,s){if(!s&&(this._running||this._scheduled||this._hasPending()))return;const t=[...this._idleWaiters];this._idleWaiters.clear();for(const i of t)e===void 0?i.resolve():i.reject(e)}_assertAlive(){if(this._disposed)throw new v.RaphDisposedError("[Raph] Phase pipeline is disposed.")}}function K(l,e){return e.priority-l.priority||l.sequence-e.sequence}function C(l){return l.firstCause!==void 0}function b(l,e){const s=l.events===void 0?e.events:e.events===void 0?l.events:Object.freeze([...l.events,...e.events]),t=l.structure===void 0?e.structure:e.structure===void 0?l.structure:Object.freeze({node:e.structure.node,oldParent:l.structure.oldParent,oldIndex:l.structure.oldIndex,newParent:e.structure.newParent,newIndex:e.structure.newIndex});return Object.freeze({...e,previous:l.previous,...s===void 0?{}:{events:s},...t===void 0?{}:{structure:t}})}exports.RaphPhasePipeline=x;