@raphy-js/raph 1.0.1-dev.25 → 1.0.1-dev.54

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 (127) hide show
  1. package/README.md +100 -0
  2. package/dist/api/Raph.d.ts +15 -15
  3. package/dist/api/RaphFacadeSession.d.ts +4 -4
  4. package/dist/api/RaphReactivityInstance.d.ts +4 -4
  5. package/dist/api/types.d.ts +11 -11
  6. package/dist/compact.cjs +1 -0
  7. package/dist/compact.js +4 -0
  8. package/dist/debug/reactivity/engine-core.cjs +1 -0
  9. package/dist/debug/reactivity/engine-core.js +1760 -0
  10. package/dist/debug/reactivity/engine.cjs +1 -1
  11. package/dist/debug/reactivity/engine.js +25 -1689
  12. package/dist/debug/reactivity/reactive-object.cjs +1 -1
  13. package/dist/debug/reactivity/reactive-object.js +604 -167
  14. package/dist/debug/runtime/RaphCompactExecutionRuntime.cjs +1 -0
  15. package/dist/debug/runtime/RaphCompactExecutionRuntime.js +9 -0
  16. package/dist/debug/runtime/RaphExecutionRuntime.cjs +1 -0
  17. package/dist/debug/runtime/RaphExecutionRuntime.js +11 -0
  18. package/dist/debug/runtime/RaphRuntime.cjs +1 -1
  19. package/dist/debug/runtime/RaphRuntime.js +115 -1176
  20. package/dist/debug/runtime/RaphRuntimeBase.cjs +1 -0
  21. package/dist/debug/runtime/RaphRuntimeBase.js +941 -0
  22. package/dist/debug/runtime/diagnostics/RaphDebug.cjs +1 -1
  23. package/dist/debug/runtime/diagnostics/RaphDebug.js +72 -66
  24. package/dist/debug/runtime/ownership/RaphNode.cjs +1 -1
  25. package/dist/debug/runtime/ownership/RaphNode.js +11 -0
  26. package/dist/debug/runtime/ownership/RaphScope.cjs +1 -1
  27. package/dist/debug/runtime/ownership/RaphScope.js +12 -12
  28. package/dist/debug/runtime/phases/RaphPhasePipeline.cjs +1 -1
  29. package/dist/debug/runtime/phases/RaphPhasePipeline.js +361 -242
  30. package/dist/debug/runtime/phases/RaphPhaseTaskRecord.cjs +1 -1
  31. package/dist/debug/runtime/phases/RaphPhaseTaskRecord.js +23 -22
  32. package/dist/debug/runtime/reactivity/RaphSelector.cjs +1 -1
  33. package/dist/debug/runtime/reactivity/RaphSelector.js +111 -90
  34. package/dist/debug/runtime/reactivity/RuntimeObjectSupport.cjs +1 -0
  35. package/dist/debug/runtime/reactivity/RuntimeObjectSupport.js +11 -0
  36. package/dist/debug/runtime/reactivity/RuntimeReactivity.cjs +1 -1
  37. package/dist/debug/runtime/reactivity/RuntimeReactivity.js +118 -103
  38. package/dist/debug/runtime/reactivity/RuntimeSelectorSupport.cjs +1 -0
  39. package/dist/debug/runtime/reactivity/RuntimeSelectorSupport.js +12 -0
  40. package/dist/entrypoints/compact.d.ts +2 -0
  41. package/dist/entrypoints/execution.d.ts +2 -0
  42. package/dist/entrypoints/machine-testing.d.ts +2 -2
  43. package/dist/entrypoints/machine.d.ts +5 -5
  44. package/dist/entrypoints/observable.d.ts +4 -0
  45. package/dist/entrypoints/path.d.ts +14 -14
  46. package/dist/entrypoints/reactivity.d.ts +1 -1
  47. package/dist/entrypoints/runtime.d.ts +19 -18
  48. package/dist/execution.cjs +1 -0
  49. package/dist/execution.js +4 -0
  50. package/dist/index.cjs +1 -1
  51. package/dist/index.js +23 -21
  52. package/dist/machine/compiler.d.ts +1 -1
  53. package/dist/machine/core.d.ts +2 -2
  54. package/dist/machine/persistence.d.ts +1 -1
  55. package/dist/machine/runtime.d.ts +3 -3
  56. package/dist/machine/testing.d.ts +1 -1
  57. package/dist/machine/types.d.ts +3 -3
  58. package/dist/main.d.ts +19 -19
  59. package/dist/observable/buffer.d.ts +6 -0
  60. package/dist/observable/class-admin.d.ts +63 -0
  61. package/dist/observable/class-plan.d.ts +46 -0
  62. package/dist/observable/classes.d.ts +10 -0
  63. package/dist/observable/context.d.ts +73 -0
  64. package/dist/observable/native.d.ts +2 -0
  65. package/dist/observable/observable.d.ts +13 -0
  66. package/dist/observable/types.d.ts +60 -0
  67. package/dist/observable.cjs +1 -0
  68. package/dist/observable.js +1187 -0
  69. package/dist/path/DataPath.d.ts +2 -2
  70. package/dist/path/PathRouter.d.ts +1 -1
  71. package/dist/path/RaphKernel.d.ts +6 -6
  72. package/dist/path/data-path.types.d.ts +1 -1
  73. package/dist/path/data-path.utils.d.ts +2 -2
  74. package/dist/path/derived/DerivedRegistry.d.ts +3 -3
  75. package/dist/path/derived/RaphDerivedHandle.d.ts +3 -3
  76. package/dist/path/derived/derived-collection.types.d.ts +1 -1
  77. package/dist/path/derived/derived-collection.utils.d.ts +3 -3
  78. package/dist/path/derived/derived-strategy.utils.d.ts +1 -1
  79. package/dist/path/meta/MetaController.d.ts +5 -5
  80. package/dist/path/meta/RaphMeta.d.ts +3 -3
  81. package/dist/path/meta/RaphMetaStore.d.ts +1 -1
  82. package/dist/path/meta/meta.types.d.ts +2 -2
  83. package/dist/path/path.types.d.ts +2 -2
  84. package/dist/path/pathSegmentKey.d.ts +1 -1
  85. package/dist/path/storage/AdapterPathStore.d.ts +2 -2
  86. package/dist/path/storage/DefaultDataAdapter.d.ts +2 -2
  87. package/dist/path/storage/PathEventHub.d.ts +1 -1
  88. package/dist/path/storage/PathStore.d.ts +2 -2
  89. package/dist/path/storage/data-adapter.types.d.ts +1 -1
  90. package/dist/raph.cjs +1 -1
  91. package/dist/raph.js +23 -21
  92. package/dist/reactivity/engine-core.d.ts +600 -0
  93. package/dist/reactivity/engine.d.ts +6 -550
  94. package/dist/reactivity/reactive-object.d.ts +143 -2
  95. package/dist/reactivity/scope.d.ts +7 -6
  96. package/dist/reactivity/types.d.ts +9 -12
  97. package/dist/reactivity/watch.d.ts +1 -1
  98. package/dist/runtime/RaphCompactExecutionRuntime.d.ts +7 -0
  99. package/dist/runtime/RaphExecutionRuntime.d.ts +6 -0
  100. package/dist/runtime/RaphRuntime.d.ts +19 -403
  101. package/dist/runtime/RaphRuntimeBase.d.ts +194 -0
  102. package/dist/runtime/diagnostics/RaphDebug.d.ts +8 -5
  103. package/dist/runtime/errors.d.ts +1 -1
  104. package/dist/runtime/ownership/RaphEffectScope.d.ts +13 -12
  105. package/dist/runtime/ownership/RaphNode.d.ts +28 -21
  106. package/dist/runtime/ownership/RaphScope.d.ts +32 -19
  107. package/dist/runtime/ownership/parent-graph.types.d.ts +1 -1
  108. package/dist/runtime/ownership/parentGraph.d.ts +2 -2
  109. package/dist/runtime/phases/RaphFrameLoop.d.ts +1 -1
  110. package/dist/runtime/phases/RaphPhasePipeline.d.ts +80 -29
  111. package/dist/runtime/phases/RaphPhaseTaskRecord.d.ts +21 -21
  112. package/dist/runtime/phases/RaphPhaseWatch.d.ts +3 -3
  113. package/dist/runtime/phases/orderPhaseTasks.d.ts +4 -2
  114. package/dist/runtime/phases/phase.types.d.ts +36 -35
  115. package/dist/runtime/reactivity/PathHandle.d.ts +5 -5
  116. package/dist/runtime/reactivity/RaphMetaSource.d.ts +7 -7
  117. package/dist/runtime/reactivity/RaphSelector.d.ts +27 -6
  118. package/dist/runtime/reactivity/RaphWorkGraph.d.ts +40 -39
  119. package/dist/runtime/reactivity/RuntimeObjectSupport.d.ts +9 -0
  120. package/dist/runtime/reactivity/RuntimeReactivity.d.ts +27 -19
  121. package/dist/runtime/reactivity/RuntimeSelectorSupport.d.ts +10 -0
  122. package/dist/runtime/reactivity/RuntimeWatch.d.ts +1 -1
  123. package/dist/runtime/reactivity/disposal-sweep.utils.d.ts +1 -1
  124. package/dist/runtime/reactivity/runtime-reactivity.types.d.ts +3 -3
  125. package/dist/runtime.cjs +1 -1
  126. package/dist/runtime.js +13 -11
  127. package/package.json +22 -62
@@ -1,20 +1,28 @@
1
- import { RaphPhaseProcessError as R, RaphDisposedError as I } from "../errors.js";
2
- import { throwDisposalErrors as z } from "../ownership/throwDisposalErrors.js";
3
- import { EMPTY_FRAME as B, RaphPhaseTaskRecord as $, GROUP_NODES as y, GROUP_CONTEXT as M, GROUP_CURSOR as N, TASK_ACTIVE as f, TASK_TASKLESS as G, TASK_PENDING as w, TASK_RESOLUTION as b, TASK_UNRESOLVED as j, TASK_CANCEL as m, TASK_RUN as q, TASK_IN_DELIVERY as p, TASK_CAUSES_DELIVERED as k, TASK_EXECUTED as H, TASK_PAUSED as A, TASK_REQUESTED as g, TASK_DEFER as W, TASK_DISCARD_ACKNOWLEDGED as C, TASK_DEFERRED as E } from "./RaphPhaseTaskRecord.js";
4
- class Q {
1
+ import { RaphPhaseProcessError as K, RaphDisposedError as H } from "../errors.js";
2
+ import { throwDisposalErrors as Q } from "../ownership/throwDisposalErrors.js";
3
+ import { EMPTY_FRAME as V, RaphPhaseTaskRecord as W, GROUP_NODES as k, GROUP_CONTEXT as X, GROUP_CURSOR as L, TASK_ACTIVE as _, TASK_TASKLESS as Y, TASK_PAUSED as P, TASK_IN_DELIVERY as p, TASK_PENDING as g, TASK_DEFERRED as T, TASK_DISCARD_ACKNOWLEDGED as y, TASK_CAUSES_DELIVERED as w, TASK_RESOLUTION as D, TASK_RUN as q, TASK_CANCEL as m, TASK_UNRESOLVED as J, TASK_EXECUTED as U, TASK_REQUESTED as C, TASK_DEFER as j } from "./RaphPhaseTaskRecord.js";
4
+ class Z {
5
5
  constructor(e, t) {
6
- this.name = e, this.pipeline = t, this.queue = [], this.spare = [], this.bindings = 0;
6
+ this.name = e, this.pipeline = t, this.first = void 0, this.queue = [], this.spare = [], this.bindings = 0;
7
7
  }
8
8
  }
9
- const V = 1e4, X = 1e4, P = f | A, x = p | b;
10
- class te {
9
+ const ee = 1e4, te = 1e4, B = g | y | C | D | w, x = _ | P, N = p | D;
10
+ class re {
11
11
  constructor(e, t, s, i = () => !1, a) {
12
12
  this._scheduler = e, this._reactivity = t, this._resolveCause = s, this._deferSync = i, this._tracePhase = a;
13
+ const n = globalThis.performance;
14
+ this._now = n === void 0 ? Date.now : n.now.bind(n);
13
15
  }
14
16
  _phases = [];
15
17
  _phaseByName = /* @__PURE__ */ new Map();
16
- // Последнее разрешённое имя phase в том виде, в каком его передал вызывающий.
18
+ /**
19
+ * Последнее разрешённое имя phase в том виде, в каком его передал вызывающий,
20
+ * и его состояние. Регистрация binding читает этот кэш сама, без вызова
21
+ * resolvePhase().
22
+ * @internal
23
+ */
17
24
  _resolvedInput;
25
+ /** @internal */
18
26
  _resolvedState;
19
27
  // Число записей во всех живых очередях.
20
28
  _queuedCount = 0;
@@ -36,18 +44,53 @@ class te {
36
44
  // значением доставка группы пропускает, не обращаясь к engine.
37
45
  _idleSlotFlags = -1;
38
46
  _disposed = !1;
39
- _firstFrameAt;
40
- _lastFrameAt;
41
- _frameNumber = 0;
42
- _frame = B;
47
+ // Отметки времени всегда числовые; первый кадр определяется счётчиком.
48
+ _firstFrameAt = Number.NaN;
49
+ _lastFrameAt = Number.NaN;
50
+ _frameNumber = -1;
51
+ _frame = V;
52
+ _publicFrames = !1;
53
+ // Raph Top-1: пока ни один frame не прочитан, flush не вызывает clock и не
54
+ // создаёт снимок; true значит, что текущий flush ещё не получил свой frame.
55
+ _frameStale = !1;
56
+ // Снимок, который получили доставки до первого чтения, и кадр, которым его
57
+ // заменило первое чтение: все такие доставки видят этот кадр.
58
+ _unmeasuredFrame;
59
+ _firstReadFrame;
60
+ _readPublicFrame = this._exposeCurrentFrame;
61
+ _now;
62
+ /** @internal */
63
+ _setPhaseTrace(e) {
64
+ this._tracePhase = e;
65
+ }
43
66
  get frame() {
67
+ return this._readPublicFrame();
68
+ }
69
+ _readCurrentFrame() {
44
70
  return this._frame;
45
71
  }
72
+ _exposeCurrentFrame() {
73
+ return this._exposeFrame(this._frame);
74
+ }
75
+ /**
76
+ * Доставка может удерживать ещё не опубликованный снимок.
77
+ * @internal
78
+ */
79
+ _frameForDelivery() {
80
+ return this._frame;
81
+ }
82
+ /**
83
+ * Первое чтение включает заморозку всех последующих кадров.
84
+ * @internal
85
+ */
86
+ _exposeFrame(e) {
87
+ return this._publicFrames || (this._frameStale && (this._unmeasuredFrame = this._frame, this._materializeFrame(), this._firstReadFrame = this._frame), this._publicFrames = !0, Object.freeze(this._frame), this._readPublicFrame = this._readCurrentFrame), e === this._unmeasuredFrame ? this._firstReadFrame : e === this._frame ? e : Object.freeze(e);
88
+ }
46
89
  get phases() {
47
90
  return this._phases.map((e) => e.phase);
48
91
  }
49
92
  definePhases(e) {
50
- if (this._assertAlive(), this._configurationLocked || this._firstFrameAt !== void 0)
93
+ if (this._assertAlive(), this._configurationLocked || this._frameNumber !== -1)
51
94
  throw new Error("[Raph] Cannot redefine phases after phase pipeline execution has started.");
52
95
  const t = this._phaseByName, s = /* @__PURE__ */ new Map(), i = [];
53
96
  for (const a of e) {
@@ -58,15 +101,15 @@ class te {
58
101
  throw new Error(`[Raph] Duplicate phase name "${n}".`);
59
102
  if (a.process !== void 0 && typeof a.process != "function")
60
103
  throw new TypeError(`[Raph] Phase "${n}" process must be a function.`);
61
- const o = Object.freeze({
104
+ const r = Object.freeze({
62
105
  name: n,
63
106
  ...a.process === void 0 ? {} : { process: a.process }
64
- }), r = {
107
+ }), h = {
65
108
  index: i.length,
66
- phase: o,
67
- state: t.get(n)?.state ?? new Q(n, this)
109
+ phase: r,
110
+ state: t.get(n)?.state ?? new Z(n, this)
68
111
  };
69
- i.push(r), s.set(n, r);
112
+ i.push(h), s.set(n, h);
70
113
  }
71
114
  this._assertRetainedPhases(s), this._phases = i, this._phaseByName = s, this._resolvedInput = void 0, this._resolvedState = void 0;
72
115
  }
@@ -101,7 +144,7 @@ class te {
101
144
  * (`node`) или watch lifecycle (`watch`).
102
145
  */
103
146
  bindTask(e, t, s, i) {
104
- return e.bindings++, new $(e, i, t, s);
147
+ return e.bindings++, new W(e, i, t, s);
105
148
  }
106
149
  /**
107
150
  * Создаёт постоянную запись группы из `count` slots: одна запись binding и
@@ -116,10 +159,10 @@ class te {
116
159
  * `TASK_TASKLESS`: вместо task тело получает поле `group`.
117
160
  */
118
161
  bindGroup(e, t, s, i, a, n) {
119
- const o = new Array(y + a);
120
- o[M] = i, o[N] = 0, e.bindings++;
121
- const r = new $(e, n, t, s);
122
- return r.state = f | G, r.group = o, r;
162
+ const r = new Array(k + a);
163
+ r[X] = i, r[L] = 0, e.bindings++;
164
+ const h = new W(e, n, t, s);
165
+ return h.state = _ | Y, h.group = r, h;
123
166
  }
124
167
  request() {
125
168
  this._assertAlive(), this._queuedCount !== 0 && this._schedule();
@@ -130,107 +173,158 @@ class te {
130
173
  });
131
174
  }
132
175
  flush() {
133
- if (this._assertAlive(), this._cancelScheduled(), this._running)
134
- return;
135
- if (this._queuedCount === 0 && this._deferred.size !== 0 && this._activateDeferred(), this._queuedCount === 0) {
136
- this._settleIdleWaiters(void 0, !1);
137
- return;
176
+ if (this._assertAlive(), this._scheduled && this._cancelScheduled(), !this._running) {
177
+ if (this._queuedCount === 0 && this._deferred.size !== 0 && this._activateDeferred(), this._queuedCount === 0) {
178
+ this._settleIdleWaiters(void 0, !1);
179
+ return;
180
+ }
181
+ this._configurationLocked = !0, this._running = !0, this._drain(this._publicFrames ? this._nextFrame() : this._skipFrame());
138
182
  }
139
- this._configurationLocked = !0, this._running = !0;
140
- const e = [], t = this._nextFrame();
141
- let s = 0, i;
183
+ }
184
+ /**
185
+ * Raph Top-1: первая доставка нового binding в простаивающем sync pipeline.
186
+ * Запись встаёт в очередь так же, как через `_queue()`, и разбирается тем же
187
+ * проходом flush, но без цепочки engine schedule → `_schedule()` → пролог
188
+ * flush. False значит, что pipeline не простаивает: тогда вызывающий
189
+ * планирует запись обычным путём.
190
+ *
191
+ * @internal
192
+ */
193
+ _canDeliverFirst(e) {
194
+ return !(this._scheduler !== "sync" || this._running || this._scheduled || this._disposed || this._queuedCount !== 0 || this._deferred.size !== 0 || (e.state & (P | p | g | T)) !== 0 || !(e.state & _) || e.consumerOwner.disposed || this._deferSync());
195
+ }
196
+ /**
197
+ * Выполняет первую доставку после положительного `_canDeliverFirst()`.
198
+ *
199
+ * @internal
200
+ */
201
+ _deliverFirst(e) {
202
+ e.state = e.state & ~y | g, e.sequence = this._taskSequence++, e.phaseState.first = e, this._queuedCount++, this._configurationLocked = !0, this._running = !0, this._drain(this._publicFrames ? this._nextFrame() : this._skipFrame());
203
+ }
204
+ /** Основной проход flush: `_running` уже выставлен, frame выбран. */
205
+ _drain(e) {
206
+ let t, s = 0, i;
142
207
  try {
143
208
  for (; this._queuedCount !== 0; ) {
144
- if (++s > V) {
209
+ if (++s > ee) {
145
210
  const n = this._describeQueued();
146
- this._cancelAllQueued(!0, e), e.push(new Error(`[Raph] Phase flush exceeded 10000 passes.${n ? ` Pending: ${n}.` : ""}`));
211
+ this._cancelAllQueued(!0, t ??= []), t.push(new Error(`[Raph] Phase flush exceeded 10000 passes.${n ? ` Pending: ${n}.` : ""}`));
147
212
  break;
148
213
  }
149
- for (const n of this._phases) {
214
+ const a = this._phases;
215
+ for (let n = 0; n < a.length; n++) {
216
+ const r = a[n];
150
217
  if (this._disposed)
151
218
  break;
152
- const o = n.state, r = o.queue;
153
- if (r.length === 0)
219
+ const h = r.state, l = h.first;
220
+ if (l === void 0)
154
221
  continue;
155
- o.queue = o.spare, o.spare = i = r, this._queuedCount -= r.length;
156
- const d = e.length;
157
- this._tracePhase?.(n.phase.name, "start");
158
- let l = 0, _ = !0, c;
159
- for (const u of r) {
160
- const v = u.state;
161
- if (!(v & f) || u.consumerOwner.disposed) {
162
- u.state = v & ~w, this._disposeTask(u);
222
+ const d = h.queue;
223
+ h.first = void 0;
224
+ const v = d.length === 0 && r.phase.process === void 0;
225
+ v || (h.queue = h.spare, h.spare = i = d), this._queuedCount -= d.length + 1;
226
+ const E = t?.length ?? 0;
227
+ if (this._tracePhase?.(r.phase.name, "start"), v) {
228
+ const u = l, o = u.state;
229
+ if (!(o & _) || u.consumerOwner._disposed) {
230
+ u.state = o & ~g, this._disposeTask(u), i = void 0;
163
231
  continue;
164
232
  }
165
- this._beginDelivery(u, t), c !== void 0 && (u.priority > c.priority || u.priority === c.priority && u.sequence < c.sequence) && (_ = !1), c = u, r[l++] = u;
233
+ const c = o & ~B | p;
234
+ u.state = u.firstCause === void 0 ? c : c | w, u.facade !== void 0 && (u.frame = e);
235
+ try {
236
+ u.group !== void 0 && (t ??= []), this._runDelivery(u, t);
237
+ } catch (F) {
238
+ (t ??= []).push(F);
239
+ }
240
+ try {
241
+ this._finishDelivery(u);
242
+ } catch (F) {
243
+ (u.state & D) !== q && this._acknowledgeDiscard(u, !0, t ??= []), u.state = (u.state | m) & ~p, S(u), t ??= [], t.push(F);
244
+ }
245
+ i = void 0, (t?.length ?? 0) === E ? this._tracePhase?.(r.phase.name, "end") : this._tracePhase?.(r.phase.name, "error", t[t.length - 1]);
246
+ continue;
166
247
  }
167
- if (r.length = l, r.length === 0) {
248
+ d.unshift(l), t ??= [];
249
+ let b = 0, A = !0, R;
250
+ for (let u = 0; u < d.length; u++) {
251
+ const o = d[u], c = o.state;
252
+ if (!(c & _) || o.consumerOwner._disposed) {
253
+ o.state = c & ~g, this._disposeTask(o);
254
+ continue;
255
+ }
256
+ const F = c & ~B | p;
257
+ o.state = o.firstCause === void 0 ? F : F | w, o.facade !== void 0 && (o.frame = e), R !== void 0 && (o.priority > R.priority || o.priority === R.priority && o.sequence < R.sequence) && (A = !1), R = o, d[b++] = o;
258
+ }
259
+ if (d.length = b, d.length === 0) {
168
260
  i = void 0;
169
261
  continue;
170
262
  }
171
- _ || r.sort(Y);
172
- const D = n.phase.process;
173
- if (D === void 0)
174
- for (const u of r)
263
+ A || d.sort(se);
264
+ const z = r.phase.process;
265
+ if (z === void 0)
266
+ for (let u = 0; u < d.length; u++)
175
267
  try {
176
- this._runDelivery(u, e);
177
- } catch (v) {
178
- e.push(v);
268
+ this._runDelivery(d[u], t);
269
+ } catch (o) {
270
+ t.push(o);
179
271
  }
180
272
  else {
181
273
  const u = [];
182
- for (const K of r)
183
- u.push(K.task);
184
- const v = Object.freeze({
185
- phase: n.phase.name,
186
- frame: t,
274
+ for (let c = 0; c < d.length; c++)
275
+ u.push(d[c].task);
276
+ const o = Object.freeze({
277
+ phase: r.phase.name,
278
+ frame: this.frame,
187
279
  tasks: Object.freeze(u)
188
280
  });
189
281
  try {
190
- this._reactivity.untrackedWithOwner(() => D(v));
191
- } catch (K) {
192
- e.push(K);
282
+ this._reactivity.untrackedWithOwner(() => z(o));
283
+ } catch (c) {
284
+ t.push(c);
193
285
  }
194
286
  }
195
- let T = 0;
196
- for (const u of r) {
197
- if ((u.state & b) === j) {
198
- T++;
287
+ let O = 0;
288
+ for (let u = 0; u < d.length; u++) {
289
+ const o = d[u];
290
+ if ((o.state & D) === J) {
291
+ O++;
199
292
  try {
200
- this._deferDelivery(u);
201
- } catch (v) {
202
- u.state |= m, this._acknowledgeDiscard(u, !0, e), e.push(v);
293
+ this._deferDelivery(o);
294
+ } catch (c) {
295
+ o.state |= m, this._acknowledgeDiscard(o, !0, t), t.push(c);
203
296
  }
204
297
  }
205
298
  try {
206
- this._finishDelivery(u);
207
- } catch (v) {
208
- (u.state & b) !== q && this._acknowledgeDiscard(u, !0, e), u.state = (u.state | m) & ~p, S(u), e.push(v);
299
+ this._finishDelivery(o);
300
+ } catch (c) {
301
+ (o.state & D) !== q && this._acknowledgeDiscard(o, !0, t), o.state = (o.state | m) & ~p, S(o), t.push(c);
209
302
  }
210
303
  }
211
- r.length = 0, i = void 0, T !== 0 && e.push(new R(
212
- `[Raph] Phase "${n.phase.name}" left ${T} task(s) unresolved; they were deferred.`
213
- )), e.length === d ? this._tracePhase?.(n.phase.name, "end") : this._tracePhase?.(
214
- n.phase.name,
304
+ d.length = 0, i = void 0, O !== 0 && t.push(new K(
305
+ `[Raph] Phase "${r.phase.name}" left ${O} task(s) unresolved; they were deferred.`
306
+ )), t.length === E ? this._tracePhase?.(r.phase.name, "end") : this._tracePhase?.(
307
+ r.phase.name,
215
308
  "error",
216
- e[e.length - 1]
309
+ t[t.length - 1]
217
310
  );
218
311
  }
219
312
  }
220
- } catch (n) {
221
- e.push(n), i !== void 0 && (i.length = 0), this._cancelAllQueued(!0, e), this._cancelAllDeferred(!0, e);
313
+ } catch (a) {
314
+ (t ??= []).push(a), i !== void 0 && (i.length = 0), this._cancelAllQueued(!0, t), this._cancelAllDeferred(!0, t);
222
315
  } finally {
223
316
  this._running = !1;
224
317
  }
225
318
  try {
226
319
  this._deferred.size !== 0 && this._scheduleDeferredTurn();
227
- } catch (n) {
228
- e.push(n);
320
+ } catch (a) {
321
+ (t ??= []).push(a);
229
322
  }
230
- const a = e.length === 1 ? e[0] : e.length > 1 ? new AggregateError(e, "[Raph] Multiple phase tasks failed.") : void 0;
231
- if (e.length !== 0)
323
+ if (t !== void 0 && t.length !== 0) {
324
+ const a = t.length === 1 ? t[0] : new AggregateError(t, "[Raph] Multiple phase tasks failed.");
232
325
  throw this._settleIdleWaiters(a, !0), a;
233
- this._settleIdleWaiters(void 0, !1);
326
+ }
327
+ this._idleWaiters.size !== 0 && this._settleIdleWaiters(void 0, !1);
234
328
  }
235
329
  dispose() {
236
330
  if (this._disposed)
@@ -239,9 +333,9 @@ class te {
239
333
  const e = [...this._deferred];
240
334
  this._cancelAllDeferred(!1);
241
335
  for (const s of e)
242
- s.state &= ~f;
336
+ s.state &= ~_;
243
337
  this._phases = [], this._phaseByName.clear(), this._resolvedInput = void 0, this._resolvedState = void 0;
244
- const t = new I("[Raph] Phase pipeline is disposed.");
338
+ const t = new H("[Raph] Phase pipeline is disposed.");
245
339
  this._settleIdleWaiters(t, !0);
246
340
  }
247
341
  _debugPending() {
@@ -250,34 +344,19 @@ class te {
250
344
  _describeQueued() {
251
345
  const e = [];
252
346
  for (const t of this._phases) {
253
- const s = t.state.queue.filter(
254
- (a) => (a.state & f) !== 0 && !a.consumerOwner.disposed
347
+ const s = t.state.first, i = (s === void 0 ? [] : [s, ...t.state.queue]).filter(
348
+ (n) => (n.state & _) !== 0 && !n.consumerOwner.disposed
255
349
  );
256
- if (s.length === 0)
350
+ if (i.length === 0)
257
351
  continue;
258
- const i = s.slice(0, 3).map((a) => {
259
- const n = a.consumerOwner.node, o = n === void 0 ? void 0 : n.componentId, r = n === void 0 ? a.consumerOwner.id : `${a.consumerOwner.id}/${n.constructor.name}/${n.type}${typeof o == "string" ? `/${o}` : ""}`, d = a.firstCause?.sourceOwner?.node, l = d === void 0 ? "" : `<=${d.id}/${d.constructor.name}`;
260
- return `${r}${a.firstCause ? `:${a.firstCause.kind}${l}` : ""}`;
352
+ const a = i.slice(0, 3).map((n) => {
353
+ const r = n.consumerOwner.node, h = r === void 0 ? void 0 : r.componentId, l = r === void 0 ? n.consumerOwner.id : `${n.consumerOwner.id}/${r.constructor.name}/${r.type}${typeof h == "string" ? `/${h}` : ""}`, d = n.firstCause?.sourceOwner?.node, v = d === void 0 ? "" : `<=${d.id}/${d.constructor.name}`;
354
+ return `${l}${n.firstCause ? `:${n.firstCause.kind}${v}` : ""}`;
261
355
  }).join(", ");
262
- e.push(`${t.phase.name}=${s.length}${i ? ` [${i}]` : ""}`);
356
+ e.push(`${t.phase.name}=${i.length}${a ? ` [${a}]` : ""}`);
263
357
  }
264
358
  return e.join("; ");
265
359
  }
266
- /**
267
- * Открывает доставку одной записью `state`. Накопленные причины остаются на
268
- * своих местах и становятся причинами доставки под TASK_CAUSES_DELIVERED:
269
- * ничего не копируется, а массив для `task.causes` строится, только если его
270
- * прочитают. Frame доставки получает только запись с facade: без facade его
271
- * нечем прочитать, а запись ссылки на новый frame в каждую доставленную
272
- * запись стоит write barrier.
273
- *
274
- * Запись попадает сюда только из живой очереди, а в ней нет записей с
275
- * открытой доставкой, поэтому причин прошлой доставки здесь не бывает.
276
- */
277
- _beginDelivery(e, t) {
278
- const s = e.state & -1893 | p;
279
- e.state = e.firstCause === void 0 ? s : s | k, e.facade !== void 0 && (e.frame = t);
280
- }
281
360
  /**
282
361
  * Исполняет открытую доставку binding. `failures` передаёт default runner:
283
362
  * группа складывает туда сбой каждого slot отдельно. Без него сбои slots
@@ -288,67 +367,67 @@ class te {
288
367
  */
289
368
  _runDelivery(e, t) {
290
369
  const s = e.state;
291
- if ((s & P) !== f || e.consumerOwner.disposed) {
370
+ if ((s & x) !== _ || e.consumerOwner._disposed) {
292
371
  e.state = s | m;
293
372
  return;
294
373
  }
295
- (s & x) !== p && O(), e.state = s | q;
374
+ (s & N) !== p && $(), e.state = s | q;
296
375
  const i = e.detail;
297
376
  i !== void 0 && (i.deferCount = 0);
298
377
  const a = this._reactivity, n = e.node;
299
378
  if (n !== void 0) {
300
- a._beginTaskEffectRun(n) && (e.state |= H, a._runTaskEffectUntracked(n));
379
+ a._beginTaskEffectRun(n) && (e.state |= U, a._runTaskEffectUntracked(n));
301
380
  return;
302
381
  }
303
- const o = e.group;
304
- if (o === void 0) {
305
- const _ = e.watch;
306
- _ !== void 0 && a.untrackedWithOwner(_.deliver);
382
+ const r = e.group;
383
+ if (r === void 0) {
384
+ const v = e.watch;
385
+ v !== void 0 && a.untrackedWithOwner(v.deliver);
307
386
  return;
308
387
  }
309
- const r = o.length;
310
- let d = this._idleSlotFlags, l;
311
- for (let _ = y; _ < r; _++) {
312
- const c = o[_];
313
- if (c === null || c.flags === d)
388
+ const h = r.length;
389
+ let l = this._idleSlotFlags, d;
390
+ for (let v = k; v < h; v++) {
391
+ const E = r[v];
392
+ if (E === null || E.flags === l)
314
393
  continue;
315
- if (!a._beginTaskEffectRun(c)) {
316
- c.evaluate !== void 0 && (this._idleSlotFlags = d = c.flags);
394
+ if (!a._beginTaskEffectRun(E)) {
395
+ E.evaluate !== void 0 && (this._idleSlotFlags = l = E.flags);
317
396
  continue;
318
397
  }
319
- o[N] = _ - y;
398
+ r[L] = v - k;
320
399
  try {
321
- a._runTaskEffectUntracked(c);
322
- } catch (T) {
323
- t !== void 0 ? t.push(T) : (l ??= []).push(T);
400
+ a._runTaskEffectUntracked(E);
401
+ } catch (A) {
402
+ t !== void 0 ? t.push(A) : (d ??= []).push(A);
324
403
  }
325
- const D = e.state;
326
- if (!(D & f))
404
+ const b = e.state;
405
+ if (!(b & _))
327
406
  break;
328
- if (D & A) {
329
- _ + 1 < r && (this._restoreDeliveryCausesBeforePending(e), e.state |= g);
407
+ if (b & P) {
408
+ v + 1 < h && (this._restoreDeliveryCausesBeforePending(e), e.state |= C);
330
409
  break;
331
410
  }
332
411
  }
333
- if (l !== void 0)
334
- throw l.length === 1 ? l[0] : new AggregateError(l, "[Raph] Effect group delivery failed.");
412
+ if (d !== void 0)
413
+ throw d.length === 1 ? d[0] : new AggregateError(d, "[Raph] Effect group delivery failed.");
335
414
  }
336
415
  /** @internal */
337
416
  _deferDelivery(e) {
338
417
  const t = e.state;
339
- if ((t & P) !== f || e.consumerOwner.disposed) {
418
+ if ((t & x) !== _ || e.consumerOwner.disposed) {
340
419
  e.state = t | m;
341
420
  return;
342
421
  }
343
- if ((t & x) !== p && O(), e.state = t | W, ++e.detailed().deferCount > X) {
422
+ if ((t & N) !== p && $(), e.state = t | j, ++e.detailed().deferCount > te) {
344
423
  e.state |= m;
345
424
  const s = [];
346
425
  throw this._acknowledgeDiscard(e, !0, s), s.length !== 0 ? new AggregateError(
347
- [new R(
426
+ [new K(
348
427
  `[Raph] Phase task in "${e.phase}" exceeded 10000 deferred deliveries.`
349
428
  ), ...s],
350
429
  "[Raph] Phase task defer limit and recovery failed."
351
- ) : new R(
430
+ ) : new K(
352
431
  `[Raph] Phase task in "${e.phase}" exceeded 10000 deferred deliveries.`
353
432
  );
354
433
  }
@@ -356,16 +435,16 @@ class te {
356
435
  /** @internal */
357
436
  _cancelDelivery(e) {
358
437
  const t = e.state;
359
- if (!(t & f) || e.consumerOwner.disposed) {
438
+ if (!(t & _) || e.consumerOwner.disposed) {
360
439
  e.state = t | m;
361
440
  return;
362
441
  }
363
- (t & x) !== p && O();
442
+ (t & N) !== p && $();
364
443
  const s = [];
365
444
  if (this._acknowledgeDiscard(e, !1, s), s.length !== 0)
366
445
  throw s.length === 1 ? s[0] : new AggregateError(s, "[Raph] Phase task cancellation failed.");
367
446
  let i = e.state | m;
368
- i & C && (i = F(e) ? i | g : i & ~g), e.state = i;
447
+ i & y && (i = I(e) ? i | C : i & ~C), e.state = i;
369
448
  const a = e.detail;
370
449
  a !== void 0 && (a.deferCount = 0);
371
450
  }
@@ -373,20 +452,20 @@ class te {
373
452
  const t = e.state;
374
453
  if (!(t & p))
375
454
  return;
376
- const s = t & b;
377
- if (e.state = t & ~p, !(t & f) || e.consumerOwner.disposed) {
455
+ const s = t & D;
456
+ if (e.state = t & ~p, !(t & _) || e.consumerOwner._disposed) {
378
457
  S(e);
379
458
  return;
380
459
  }
381
- if (t & A) {
382
- s !== q && !(s === m && (t & C) !== 0) && (this._restoreDeliveryCausesBeforePending(e), e.state |= g), S(e);
460
+ if (t & P) {
461
+ s !== q && !(s === m && (t & y) !== 0) && (this._restoreDeliveryCausesBeforePending(e), e.state |= C), S(e);
383
462
  return;
384
463
  }
385
- if (s === W) {
386
- this._restoreDeliveryCausesBeforePending(e), e.state |= E, this._deferred.add(e), S(e);
464
+ if (s === j) {
465
+ this._restoreDeliveryCausesBeforePending(e), e.state |= T, this._deferred.add(e), S(e);
387
466
  return;
388
467
  }
389
- if (S(e), (e.state & g) !== 0 || e.firstCause !== void 0) {
468
+ if (((e.state & w) !== 0 || e.detail !== void 0) && S(e), (e.state & C) !== 0 || e.firstCause !== void 0) {
390
469
  const i = e.node;
391
470
  if (i !== void 0)
392
471
  this._reactivity._rearmTaskEffect(i);
@@ -413,7 +492,7 @@ class te {
413
492
  */
414
493
  _rearmGroup(e) {
415
494
  const t = this._reactivity;
416
- for (let s = y; s < e.length; s++) {
495
+ for (let s = k; s < e.length; s++) {
417
496
  const i = e[s];
418
497
  i !== null && i.firstDep !== null && t._beginTaskEffectRun(i) && t._rearmTaskEffect(i);
419
498
  }
@@ -429,20 +508,20 @@ class te {
429
508
  /** @internal */
430
509
  _appendCause(e, t, s) {
431
510
  const i = e.state;
432
- if (!(i & f))
511
+ if (!(i & _))
433
512
  return;
434
- i & k && this._splitDeliveredCauses(e);
513
+ i & w && this._splitDeliveredCauses(e);
435
514
  const a = e.firstCause;
436
515
  if (a === void 0) {
437
516
  e.firstCause = t, e.firstCauseKey = s;
438
517
  return;
439
518
  }
440
519
  if (e.firstCauseKey === s) {
441
- e.firstCause = U(a, t);
520
+ e.firstCause = G(a, t);
442
521
  return;
443
522
  }
444
- const n = e.detailed().extraCauses ??= /* @__PURE__ */ new Map(), o = n.get(s);
445
- n.set(s, o === void 0 ? t : U(o, t));
523
+ const n = e.detailed().extraCauses ??= /* @__PURE__ */ new Map(), r = n.get(s);
524
+ n.set(s, r === void 0 ? t : G(r, t));
446
525
  }
447
526
  /**
448
527
  * Переносит причины открытой доставки с места ожидающих в detail, без
@@ -452,32 +531,36 @@ class te {
452
531
  */
453
532
  _splitDeliveredCauses(e) {
454
533
  const t = e.detailed(), s = t.extraCauses;
455
- t.deliveryFirstCause = e.firstCause, t.deliveryFirstCauseKey = e.firstCauseKey, t.deliveryExtraCauses = s === void 0 || s.size === 0 ? void 0 : s, t.extraCauses = void 0, e.firstCause = void 0, e.firstCauseKey = void 0, e.state &= ~k;
534
+ t.deliveryFirstCause = e.firstCause, t.deliveryFirstCauseKey = e.firstCauseKey, t.deliveryExtraCauses = s === void 0 || s.size === 0 ? void 0 : s, t.extraCauses = void 0, e.firstCause = void 0, e.firstCauseKey = void 0, e.state &= ~w;
456
535
  }
457
536
  /** @internal */
458
537
  _queue(e, t = !0) {
459
538
  const s = e.state;
460
- if (!(!(s & f) || e.consumerOwner.disposed || this._disposed)) {
461
- if (s & (A | p)) {
462
- e.state = s | g;
463
- return;
464
- }
465
- if (s & w) {
466
- t && this._schedule();
467
- return;
468
- }
469
- s & E || (e.state = s & ~C | w, e.sequence = this._taskSequence++, e.phaseState.queue.push(e), this._queuedCount++, t && this._schedule());
539
+ if (!(s & _) || e.consumerOwner._disposed || this._disposed)
540
+ return;
541
+ if (s & (P | p)) {
542
+ e.state = s | C;
543
+ return;
470
544
  }
545
+ if (s & g) {
546
+ t && this._schedule();
547
+ return;
548
+ }
549
+ if (s & T)
550
+ return;
551
+ e.state = s & ~y | g, e.sequence = this._taskSequence++;
552
+ const i = e.phaseState;
553
+ i.first === void 0 ? i.first = e : i.queue.push(e), this._queuedCount++, t && this._schedule();
471
554
  }
472
555
  /** @internal */
473
556
  _disposeTask(e) {
474
557
  const t = e.state;
475
- if (!(t & f))
558
+ if (!(t & _))
476
559
  return;
477
560
  const s = t & -270;
478
561
  e.state = t & p ? s | m : s, e.firstCause = void 0, e.firstCauseKey = void 0;
479
562
  const i = e.detail;
480
- i !== void 0 && (i.extraCauses?.clear(), i.extraCauses = void 0, L(i)), t & E && this._deferred.delete(e), t & w && this._unqueue(e), e.phaseState.bindings--, this._hasPending() || this._cancelScheduled(), this._settleIdleWaiters(void 0, !1);
563
+ i !== void 0 && (i.extraCauses?.clear(), i.extraCauses = void 0, M(i)), t & T && this._deferred.delete(e), t & g && this._unqueue(e), e.phaseState.bindings--, this._scheduled && this._queuedCount === 0 && this._deferred.size === 0 && this._cancelScheduled(), this._idleWaiters.size !== 0 && this._settleIdleWaiters(void 0, !1);
481
564
  }
482
565
  /**
483
566
  * Полностью освобождает один binding; каждый шаг идемпотентен, поэтому
@@ -500,9 +583,13 @@ class te {
500
583
  return;
501
584
  }
502
585
  const i = e.watch;
503
- i !== void 0 && (e.watch = void 0, i.stop(() => this._releaseWatch(e, i)));
586
+ i !== void 0 && (e.watch = void 0, this._stopPhaseWatch(e, i));
504
587
  }
505
- this._disposeTask(e);
588
+ e.state & _ && this._disposeTask(e);
589
+ }
590
+ /** Callback создаётся только на пути explicit watch после очистки record.watch. */
591
+ _stopPhaseWatch(e, t) {
592
+ t.stop(() => this._releaseWatch(e, t));
506
593
  }
507
594
  /**
508
595
  * Убирает из состояния группы slots, записи графа которых уже остановлены, и
@@ -523,7 +610,7 @@ class te {
523
610
  */
524
611
  _forgetStoppedSlots(e) {
525
612
  let t = !1, s = !1;
526
- for (let i = y; i < e.length; i++) {
613
+ for (let i = k; i < e.length; i++) {
527
614
  const a = e[i];
528
615
  a != null && (a.evaluate === void 0 ? (e[i] = null, t = !0) : s = !0);
529
616
  }
@@ -549,13 +636,13 @@ class te {
549
636
  _disposeGroup(e, t) {
550
637
  const s = this._reactivity;
551
638
  let i;
552
- for (let a = t.length - 1; a >= y; a--) {
639
+ for (let a = t.length - 1; a >= k; a--) {
553
640
  const n = t[a];
554
641
  if (n != null)
555
642
  try {
556
643
  s._disposeTaskEffect(n);
557
- } catch (o) {
558
- (i ??= []).push(o);
644
+ } catch (r) {
645
+ (i ??= []).push(r);
559
646
  }
560
647
  }
561
648
  try {
@@ -582,28 +669,33 @@ class te {
582
669
  } catch (a) {
583
670
  s.push(a);
584
671
  }
585
- z(s, "[Raph] Phase watch disposal failed.");
672
+ Q(s, "[Raph] Phase watch disposal failed.");
586
673
  }
587
674
  /** @internal */
588
675
  _pauseTask(e) {
589
676
  const t = e.state;
590
- if ((t & P) !== f)
677
+ if ((t & x) !== _)
591
678
  return;
592
- const s = t & b, i = (t | A) & -13;
593
- e.state = (t & (w | E)) !== 0 || (t & p) !== 0 && s !== q && !(s === m && (t & C) !== 0) ? i | g : i, t & E && this._deferred.delete(e), t & w && this._unqueue(e), this._hasPending() || this._cancelScheduled(), this._settleIdleWaiters(void 0, !1);
679
+ const s = t & D, i = (t | P) & -13;
680
+ e.state = (t & (g | T)) !== 0 || (t & p) !== 0 && s !== q && !(s === m && (t & y) !== 0) ? i | C : i, t & T && this._deferred.delete(e), t & g && this._unqueue(e), this._hasPending() || this._cancelScheduled(), this._settleIdleWaiters(void 0, !1);
594
681
  }
595
682
  /**
596
683
  * Убирает ожидающую запись из живой очереди её phase. Запись, которую flush
597
684
  * уже забрал на разбор, в живой очереди не находится и счётчик не меняет.
598
685
  */
599
686
  _unqueue(e) {
600
- const t = e.phaseState.queue, s = t.indexOf(e);
601
- s >= 0 && (t.splice(s, 1), this._queuedCount--);
687
+ const t = e.phaseState, s = t.queue;
688
+ if (t.first === e) {
689
+ t.first = s.shift(), this._queuedCount--;
690
+ return;
691
+ }
692
+ const i = s.indexOf(e);
693
+ i >= 0 && (s.splice(i, 1), this._queuedCount--);
602
694
  }
603
695
  /** @internal */
604
696
  _resumeTask(e) {
605
697
  const t = e.state;
606
- (t & P) !== P || e.consumerOwner.disposed || ((t & g) !== 0 || F(e) ? (e.state = t & -67, this._queue(e)) : e.state = t & ~A);
698
+ (t & x) !== x || e.consumerOwner.disposed || ((t & C) !== 0 || I(e) ? (e.state = t & -67, this._queue(e)) : e.state = t & ~P);
607
699
  }
608
700
  /**
609
701
  * Возвращает причины открытой доставки в ожидающие, впереди причин, которые
@@ -612,7 +704,7 @@ class te {
612
704
  * отделяются от ожидающих.
613
705
  */
614
706
  _restoreDeliveryCausesBeforePending(e) {
615
- e.state & k && this._splitDeliveredCauses(e);
707
+ e.state & w && this._splitDeliveredCauses(e);
616
708
  const t = e.detail;
617
709
  if (t === void 0)
618
710
  return;
@@ -621,13 +713,13 @@ class te {
621
713
  return;
622
714
  const i = e.firstCause, a = e.firstCauseKey, n = t.extraCauses;
623
715
  e.firstCause = void 0, e.firstCauseKey = void 0, t.extraCauses = void 0, this._appendCause(e, s, t.deliveryFirstCauseKey);
624
- const o = t.deliveryExtraCauses;
625
- if (o !== void 0)
626
- for (const [r, d] of o)
627
- this._appendCause(e, d, r);
716
+ const r = t.deliveryExtraCauses;
717
+ if (r !== void 0)
718
+ for (const [h, l] of r)
719
+ this._appendCause(e, l, h);
628
720
  if (i !== void 0 && (this._appendCause(e, i, a), n !== void 0))
629
- for (const [r, d] of n)
630
- this._appendCause(e, d, r);
721
+ for (const [h, l] of n)
722
+ this._appendCause(e, l, h);
631
723
  }
632
724
  _schedule() {
633
725
  if (this._running || this._scheduled || this._disposed)
@@ -664,20 +756,36 @@ class te {
664
756
  const e = [...this._deferred];
665
757
  this._deferred.clear();
666
758
  for (const t of e)
667
- t.state &= ~E, this._queue(t, !1);
759
+ t.state &= ~T, this._queue(t, !1);
760
+ }
761
+ /** Flush без читателей frame: только номер кадра, без clock и снимка. */
762
+ _skipFrame() {
763
+ return this._frameNumber++, this._frameStale = !0, this._frame;
764
+ }
765
+ /**
766
+ * Вычисляет текущий кадр при первом чтении. История до него не записывалась,
767
+ * поэтому кадр считается первым измеренным: delta и elapsed равны нулю.
768
+ */
769
+ _materializeFrame() {
770
+ const e = this._now();
771
+ this._frameStale = !1, this._firstFrameAt = e, this._lastFrameAt = e, this._frame = { now: e, delta: 0, elapsed: 0, frame: this._frameNumber };
668
772
  }
669
773
  _nextFrame() {
670
- const e = globalThis.performance?.now() ?? Date.now();
671
- if (this._firstFrameAt === void 0 || this._lastFrameAt === void 0)
672
- return this._firstFrameAt = e, this._lastFrameAt = e, this._frame = Object.freeze({ now: e, delta: 0, elapsed: 0, frame: 0 });
774
+ this._frameStale = !1;
775
+ const e = this._now();
776
+ if (this._frameNumber === -1) {
777
+ this._firstFrameAt = e, this._lastFrameAt = e, this._frameNumber = 0;
778
+ const s = { now: e, delta: 0, elapsed: 0, frame: 0 };
779
+ return this._frame = this._publicFrames ? Object.freeze(s) : s;
780
+ }
673
781
  this._frameNumber++;
674
- const t = Object.freeze({
782
+ const t = {
675
783
  now: e,
676
784
  delta: Math.min(Math.max(e - this._lastFrameAt, 0), 100),
677
785
  elapsed: Math.max(e - this._firstFrameAt, 0),
678
786
  frame: this._frameNumber
679
- });
680
- return this._lastFrameAt = e, this._frame = t;
787
+ };
788
+ return this._lastFrameAt = e, this._frame = this._publicFrames ? Object.freeze(t) : t;
681
789
  }
682
790
  _assertRetainedPhases(e) {
683
791
  for (const t of this._phases) {
@@ -687,56 +795,67 @@ class te {
687
795
  }
688
796
  for (const t of this._phases) {
689
797
  const s = t.state;
690
- if (s.queue.length !== 0 && !e.has(s.name))
798
+ if (s.first !== void 0 && !e.has(s.name))
691
799
  throw new Error(`[Raph] Cannot remove phase "${s.name}" while it has pending work.`);
692
800
  }
693
801
  }
694
802
  _hasPending() {
695
803
  return this._queuedCount !== 0 || this._deferred.size !== 0;
696
804
  }
805
+ /**
806
+ * Есть ли то, что изменит flush(): очередь, отложенные записи, запланированный
807
+ * turn или ожидающие afterFlush(). Без этого flush() ничего не делает.
808
+ *
809
+ * @internal
810
+ */
811
+ _hasPendingWork() {
812
+ return this._queuedCount !== 0 || this._deferred.size !== 0 || this._scheduled || this._idleWaiters.size !== 0;
813
+ }
697
814
  _cancelAllQueued(e, t = []) {
698
815
  if (this._queuedCount === 0)
699
816
  return;
700
817
  const s = [];
701
818
  for (const i of this._phases) {
702
- const a = i.state.queue;
703
- for (const n of a)
704
- s.push(n);
705
- a.length = 0;
819
+ const a = i.state;
820
+ a.first !== void 0 && (s.push(a.first), a.first = void 0);
821
+ const n = a.queue;
822
+ for (const r of n)
823
+ s.push(r);
824
+ n.length = 0;
706
825
  }
707
826
  this._queuedCount = 0;
708
827
  for (const i of s)
709
- i.state &= ~w, e && this._acknowledgeDiscard(i, !0, t), this._clearPendingDelivery(i);
828
+ i.state &= ~g, e && this._acknowledgeDiscard(i, !0, t), this._clearPendingDelivery(i);
710
829
  }
711
830
  _cancelAllDeferred(e, t = []) {
712
831
  const s = [...this._deferred];
713
832
  this._deferred.clear();
714
833
  for (const i of s)
715
- i.state &= ~E, e && this._acknowledgeDiscard(i, !0, t), this._clearPendingDelivery(i);
834
+ i.state &= ~T, e && this._acknowledgeDiscard(i, !0, t), this._clearPendingDelivery(i);
716
835
  }
717
836
  _acknowledgeDiscard(e, t, s) {
718
837
  const i = e.state;
719
- if (i & C)
838
+ if (i & y)
720
839
  return;
721
840
  const a = e.node, n = e.group;
722
- if (a === void 0 && n === void 0 || !(i & f)) {
723
- e.state = i | C;
841
+ if (a === void 0 && n === void 0 || !(i & _)) {
842
+ e.state = i | y;
724
843
  return;
725
844
  }
726
845
  try {
727
- if (a !== void 0 ? (i & H) !== 0 && this._reactivity._cancelTaskEffect(a) : this._cancelGroup(e, n, t)) {
728
- e.state |= C;
846
+ if (a !== void 0 ? (i & U) !== 0 && this._reactivity._cancelTaskEffect(a) : this._cancelGroup(e, n, t)) {
847
+ e.state |= y;
729
848
  return;
730
849
  }
731
850
  if (!t) {
732
- s.push(new R(
851
+ s.push(new K(
733
852
  `[Raph] Initial effect delivery in "${e.phase}" cannot be cancelled before dependency collection.`
734
853
  ));
735
854
  return;
736
855
  }
737
- e.dispose(), e.state |= C;
738
- } catch (o) {
739
- s.push(o);
856
+ e.dispose(), e.state |= y;
857
+ } catch (r) {
858
+ s.push(r);
740
859
  }
741
860
  }
742
861
  /**
@@ -763,33 +882,33 @@ class te {
763
882
  _cancelGroup(e, t, s) {
764
883
  const i = this._reactivity;
765
884
  let a = !1;
766
- for (let r = y; r < t.length; r++) {
767
- const d = t[r];
768
- d === null || d.firstDep !== null || !i._beginTaskEffectRun(d) || (s ? i._disposeTaskEffect(d) : (i._requestTaskEffect(d, !1), a = !0));
885
+ for (let h = k; h < t.length; h++) {
886
+ const l = t[h];
887
+ l === null || l.firstDep !== null || !i._beginTaskEffectRun(l) || (s ? i._disposeTaskEffect(l) : (i._requestTaskEffect(l, !1), a = !0));
769
888
  }
770
889
  if (a)
771
890
  return !1;
772
- const n = !s && F(e);
773
- let o = !1;
774
- for (let r = y; r < t.length; r++) {
775
- const d = t[r];
776
- if (d === null)
891
+ const n = !s && I(e);
892
+ let r = !1;
893
+ for (let h = k; h < t.length; h++) {
894
+ const l = t[h];
895
+ if (l === null)
777
896
  continue;
778
- if (d.firstDep === null) {
779
- o = o || d.evaluate !== void 0;
897
+ if (l.firstDep === null) {
898
+ r = r || l.evaluate !== void 0;
780
899
  continue;
781
900
  }
782
- const l = n && i._beginTaskEffectRun(d);
783
- i._cancelTaskEffect(d) && (o = !0, l && i._rearmTaskEffect(d));
901
+ const d = n && i._beginTaskEffectRun(l);
902
+ i._cancelTaskEffect(l) && (r = !0, d && i._rearmTaskEffect(l));
784
903
  }
785
- return o;
904
+ return r;
786
905
  }
787
906
  /**
788
907
  * Сбрасывает ожидающую работу записи, снятой с очереди либо из отложенных.
789
908
  * Такая запись не находится в доставке, поэтому её причины ожидающие.
790
909
  */
791
910
  _clearPendingDelivery(e) {
792
- e.state &= ~g, e.firstCause = void 0, e.firstCauseKey = void 0;
911
+ e.state &= ~C, e.firstCause = void 0, e.firstCauseKey = void 0;
793
912
  const t = e.detail;
794
913
  t !== void 0 && (t.extraCauses?.clear(), t.extraCauses = void 0);
795
914
  }
@@ -804,45 +923,45 @@ class te {
804
923
  }
805
924
  _assertAlive() {
806
925
  if (this._disposed)
807
- throw new I("[Raph] Phase pipeline is disposed.");
926
+ throw new H("[Raph] Phase pipeline is disposed.");
808
927
  }
809
928
  }
810
- function Y(h, e) {
811
- return e.priority - h.priority || h.sequence - e.sequence;
929
+ function se(f, e) {
930
+ return e.priority - f.priority || f.sequence - e.sequence;
812
931
  }
813
- function F(h) {
814
- return h.firstCause !== void 0 && !(h.state & k);
932
+ function I(f) {
933
+ return f.firstCause !== void 0 && !(f.state & w);
815
934
  }
816
- function S(h) {
817
- const e = h.state, t = h.detail;
818
- if (e & k) {
819
- h.state = e & ~k, h.firstCause = void 0, h.firstCauseKey = void 0, t !== void 0 && (t.extraCauses = void 0, t.deliveryCauses = void 0);
935
+ function S(f) {
936
+ const e = f.state, t = f.detail;
937
+ if (e & w) {
938
+ f.state = e & ~w, f.firstCause = void 0, f.firstCauseKey = void 0, t !== void 0 && (t.extraCauses = void 0, t.deliveryCauses = void 0);
820
939
  return;
821
940
  }
822
- t !== void 0 && t.deliveryFirstCause !== void 0 && L(t);
941
+ t !== void 0 && t.deliveryFirstCause !== void 0 && M(t);
823
942
  }
824
- function L(h) {
825
- h.deliveryFirstCause = void 0, h.deliveryFirstCauseKey = void 0, h.deliveryExtraCauses = void 0, h.deliveryCauses = void 0;
943
+ function M(f) {
944
+ f.deliveryFirstCause = void 0, f.deliveryFirstCauseKey = void 0, f.deliveryExtraCauses = void 0, f.deliveryCauses = void 0;
826
945
  }
827
- function O() {
828
- throw new R("[Raph] Phase task delivery is already resolved.");
946
+ function $() {
947
+ throw new K("[Raph] Phase task delivery is already resolved.");
829
948
  }
830
- function U(h, e) {
831
- const t = h.events === void 0 ? e.events : e.events === void 0 ? h.events : Object.freeze([...h.events, ...e.events]), s = h.structure === void 0 ? e.structure : e.structure === void 0 ? h.structure : Object.freeze({
949
+ function G(f, e) {
950
+ const t = f.events === void 0 ? e.events : e.events === void 0 ? f.events : Object.freeze([...f.events, ...e.events]), s = f.structure === void 0 ? e.structure : e.structure === void 0 ? f.structure : Object.freeze({
832
951
  node: e.structure.node,
833
- oldParent: h.structure.oldParent,
834
- oldIndex: h.structure.oldIndex,
952
+ oldParent: f.structure.oldParent,
953
+ oldIndex: f.structure.oldIndex,
835
954
  newParent: e.structure.newParent,
836
955
  newIndex: e.structure.newIndex
837
956
  });
838
957
  return Object.freeze({
839
958
  ...e,
840
- previous: h.previous,
959
+ previous: f.previous,
841
960
  ...t === void 0 ? {} : { events: t },
842
961
  ...s === void 0 ? {} : { structure: s }
843
962
  });
844
963
  }
845
964
  export {
846
- te as RaphPhasePipeline,
847
- Q as RaphPhaseState
965
+ re as RaphPhasePipeline,
966
+ Z as RaphPhaseState
848
967
  };