@raphy-js/raph 1.0.0-dev.2

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 (139) hide show
  1. package/LICENSE +202 -0
  2. package/ReadMe.md +153 -0
  3. package/dist/api/Raph.d.ts +228 -0
  4. package/dist/api/errors.d.ts +20 -0
  5. package/dist/api/public.d.ts +22 -0
  6. package/dist/api/types.d.ts +25 -0
  7. package/dist/debug/api/Raph.cjs +1 -0
  8. package/dist/debug/api/Raph.js +419 -0
  9. package/dist/debug/api/errors.cjs +1 -0
  10. package/dist/debug/api/errors.js +14 -0
  11. package/dist/debug/api/public.cjs +1 -0
  12. package/dist/debug/api/public.js +40 -0
  13. package/dist/debug/api/types.cjs +1 -0
  14. package/dist/debug/api/types.js +1 -0
  15. package/dist/debug/path/AdapterPathStore.cjs +1 -0
  16. package/dist/debug/path/AdapterPathStore.js +133 -0
  17. package/dist/debug/path/DerivedRegistry.cjs +1 -0
  18. package/dist/debug/path/DerivedRegistry.js +157 -0
  19. package/dist/debug/path/MetaController.cjs +1 -0
  20. package/dist/debug/path/MetaController.js +214 -0
  21. package/dist/debug/path/PathEventHub.cjs +1 -0
  22. package/dist/debug/path/PathEventHub.js +148 -0
  23. package/dist/debug/path/PathStore.cjs +1 -0
  24. package/dist/debug/path/PathStore.js +326 -0
  25. package/dist/debug/path/RaphDerivedHandle.cjs +1 -0
  26. package/dist/debug/path/RaphDerivedHandle.js +125 -0
  27. package/dist/debug/path/RaphKernel.cjs +1 -0
  28. package/dist/debug/path/RaphKernel.js +636 -0
  29. package/dist/debug/path/RaphMeta.cjs +1 -0
  30. package/dist/debug/path/RaphMeta.js +68 -0
  31. package/dist/debug/path/RaphMetaStore.cjs +1 -0
  32. package/dist/debug/path/RaphMetaStore.js +184 -0
  33. package/dist/debug/path/data-adapter.cjs +1 -0
  34. package/dist/debug/path/data-adapter.js +356 -0
  35. package/dist/debug/path/data-draft.cjs +1 -0
  36. package/dist/debug/path/data-draft.js +71 -0
  37. package/dist/debug/path/data-path.cjs +1 -0
  38. package/dist/debug/path/data-path.js +423 -0
  39. package/dist/debug/path/derived-collection.cjs +1 -0
  40. package/dist/debug/path/derived-collection.js +179 -0
  41. package/dist/debug/path/derived-strategies.cjs +1 -0
  42. package/dist/debug/path/derived-strategies.js +20 -0
  43. package/dist/debug/path/meta.types.cjs +1 -0
  44. package/dist/debug/path/meta.types.js +1 -0
  45. package/dist/debug/path/path-router.cjs +1 -0
  46. package/dist/debug/path/path-router.js +86 -0
  47. package/dist/debug/path/path.types.cjs +1 -0
  48. package/dist/debug/path/path.types.js +1 -0
  49. package/dist/debug/path/public.cjs +1 -0
  50. package/dist/debug/path/public.js +18 -0
  51. package/dist/debug/path/segment-key.cjs +1 -0
  52. package/dist/debug/path/segment-key.js +12 -0
  53. package/dist/debug/reactivity/engine.cjs +1 -0
  54. package/dist/debug/reactivity/engine.js +1133 -0
  55. package/dist/debug/reactivity/scope.cjs +1 -0
  56. package/dist/debug/reactivity/scope.js +274 -0
  57. package/dist/debug/reactivity/types.cjs +1 -0
  58. package/dist/debug/reactivity/types.js +1 -0
  59. package/dist/debug/reactivity/watch.cjs +1 -0
  60. package/dist/debug/reactivity/watch.js +64 -0
  61. package/dist/debug/runtime/PathHandle.cjs +1 -0
  62. package/dist/debug/runtime/PathHandle.js +139 -0
  63. package/dist/debug/runtime/RaphDebug.cjs +1 -0
  64. package/dist/debug/runtime/RaphDebug.js +15 -0
  65. package/dist/debug/runtime/RaphFrameLoop.cjs +1 -0
  66. package/dist/debug/runtime/RaphFrameLoop.js +106 -0
  67. package/dist/debug/runtime/RaphNode.cjs +1 -0
  68. package/dist/debug/runtime/RaphNode.js +143 -0
  69. package/dist/debug/runtime/RaphPhasePipeline.cjs +1 -0
  70. package/dist/debug/runtime/RaphPhasePipeline.js +526 -0
  71. package/dist/debug/runtime/RaphRuntime.cjs +1 -0
  72. package/dist/debug/runtime/RaphRuntime.js +700 -0
  73. package/dist/debug/runtime/RaphScope.cjs +1 -0
  74. package/dist/debug/runtime/RaphScope.js +64 -0
  75. package/dist/debug/runtime/RuntimeReactivity.cjs +1 -0
  76. package/dist/debug/runtime/RuntimeReactivity.js +154 -0
  77. package/dist/debug/runtime/RuntimeWatch.cjs +1 -0
  78. package/dist/debug/runtime/RuntimeWatch.js +71 -0
  79. package/dist/debug/runtime/disposal.cjs +1 -0
  80. package/dist/debug/runtime/disposal.js +9 -0
  81. package/dist/debug/runtime/errors.cjs +1 -0
  82. package/dist/debug/runtime/errors.js +12 -0
  83. package/dist/debug/runtime/parent-graph.cjs +1 -0
  84. package/dist/debug/runtime/parent-graph.js +10 -0
  85. package/dist/debug/runtime/phase.types.cjs +1 -0
  86. package/dist/debug/runtime/phase.types.js +8 -0
  87. package/dist/debug/runtime/public.cjs +1 -0
  88. package/dist/debug/runtime/public.js +18 -0
  89. package/dist/debug/runtime/runtime-reactivity.types.cjs +1 -0
  90. package/dist/debug/runtime/runtime-reactivity.types.js +1 -0
  91. package/dist/index.cjs +1 -0
  92. package/dist/index.js +40 -0
  93. package/dist/path/AdapterPathStore.d.ts +45 -0
  94. package/dist/path/DerivedRegistry.d.ts +67 -0
  95. package/dist/path/MetaController.d.ts +85 -0
  96. package/dist/path/PathEventHub.d.ts +48 -0
  97. package/dist/path/PathStore.d.ts +51 -0
  98. package/dist/path/RaphDerivedHandle.d.ts +97 -0
  99. package/dist/path/RaphKernel.d.ts +166 -0
  100. package/dist/path/RaphMeta.d.ts +45 -0
  101. package/dist/path/RaphMetaStore.d.ts +45 -0
  102. package/dist/path/data-adapter.d.ts +78 -0
  103. package/dist/path/data-draft.d.ts +4 -0
  104. package/dist/path/data-path.d.ts +97 -0
  105. package/dist/path/derived-collection.d.ts +30 -0
  106. package/dist/path/derived-strategies.d.ts +15 -0
  107. package/dist/path/meta.types.d.ts +33 -0
  108. package/dist/path/path-router.d.ts +21 -0
  109. package/dist/path/path.types.d.ts +26 -0
  110. package/dist/path/public.d.ts +14 -0
  111. package/dist/path/segment-key.d.ts +2 -0
  112. package/dist/path.cjs +1 -0
  113. package/dist/path.js +18 -0
  114. package/dist/raph.cjs +1 -0
  115. package/dist/raph.js +40 -0
  116. package/dist/reactivity/engine.d.ts +379 -0
  117. package/dist/reactivity/scope.d.ts +146 -0
  118. package/dist/reactivity/types.d.ts +150 -0
  119. package/dist/reactivity/watch.d.ts +15 -0
  120. package/dist/reactivity.cjs +1 -0
  121. package/dist/reactivity.js +14 -0
  122. package/dist/runtime/PathHandle.d.ts +72 -0
  123. package/dist/runtime/RaphDebug.d.ts +32 -0
  124. package/dist/runtime/RaphFrameLoop.d.ts +51 -0
  125. package/dist/runtime/RaphNode.d.ts +68 -0
  126. package/dist/runtime/RaphPhasePipeline.d.ts +133 -0
  127. package/dist/runtime/RaphRuntime.d.ts +285 -0
  128. package/dist/runtime/RaphScope.d.ts +50 -0
  129. package/dist/runtime/RuntimeReactivity.d.ts +40 -0
  130. package/dist/runtime/RuntimeWatch.d.ts +28 -0
  131. package/dist/runtime/disposal.d.ts +1 -0
  132. package/dist/runtime/errors.d.ts +16 -0
  133. package/dist/runtime/parent-graph.d.ts +5 -0
  134. package/dist/runtime/phase.types.d.ts +49 -0
  135. package/dist/runtime/public.d.ts +13 -0
  136. package/dist/runtime/runtime-reactivity.types.d.ts +9 -0
  137. package/dist/runtime.cjs +1 -0
  138. package/dist/runtime.js +18 -0
  139. package/package.json +109 -0
@@ -0,0 +1,700 @@
1
+ var W = Object.defineProperty;
2
+ var b = (a, t, e) => t in a ? W(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
+ var h = (a, t, e) => b(a, typeof t != "symbol" ? t + "" : t, e);
4
+ import { RaphDisposedError as R, RaphCrossRuntimeError as k, RaphActionError as T } from "./errors.js";
5
+ import { parentGraph as x } from "./parent-graph.js";
6
+ import { PathHandle as L } from "./PathHandle.js";
7
+ import { RaphSchedulerType as d } from "./phase.types.js";
8
+ import { RaphNode as m } from "./RaphNode.js";
9
+ import { parseDataPath as q, DataPath as A } from "../path/data-path.js";
10
+ import { RaphKernel as O } from "../path/RaphKernel.js";
11
+ import { RaphMeta as M } from "../path/RaphMeta.js";
12
+ import { watchWithReactivity as $ } from "../reactivity/watch.js";
13
+ import { throwDisposalErrors as D } from "./disposal.js";
14
+ import { createOwnerSnapshot as y } from "./RaphDebug.js";
15
+ import { RaphFrameLoop as H } from "./RaphFrameLoop.js";
16
+ import { RaphPhasePipeline as F } from "./RaphPhasePipeline.js";
17
+ import { RaphScope as S } from "./RaphScope.js";
18
+ import { RuntimeReactivity as U } from "./RuntimeReactivity.js";
19
+ import { RuntimeWatch as g } from "./RuntimeWatch.js";
20
+ const v = class v {
21
+ /**
22
+ * Создаёт изолированный execution graph поверх собственного или shared Kernel.
23
+ */
24
+ constructor(t = {}) {
25
+ // Публикуют immutable configuration и корневых lifecycle owners.
26
+ h(this, "configuration");
27
+ h(this, "rootScope");
28
+ h(this, "root");
29
+ // Владеют изолированным reactive graph и его runtime policy.
30
+ h(this, "_reactivity");
31
+ h(this, "_signalLifecycle");
32
+ // Лениво создают adapters и diagnostics только по запросу consumer.
33
+ h(this, "_pathHandles");
34
+ h(this, "_meta");
35
+ h(this, "_phases");
36
+ h(this, "_frameLoop");
37
+ h(this, "_frameRevision");
38
+ h(this, "_frameRevisionValue", !1);
39
+ h(this, "_debug");
40
+ h(this, "_parentGraph");
41
+ // Регистрируют всех lifecycle owners runtime.
42
+ h(this, "_owners", /* @__PURE__ */ new Set());
43
+ // Координируют вложенные write boundaries и execution requests.
44
+ h(this, "_transactionDepth", 0);
45
+ h(this, "_mutationDepth", 0);
46
+ h(this, "_kernelTransactionDepth", 0);
47
+ h(this, "_actionDepth", 0);
48
+ h(this, "_executionRequested", !1);
49
+ // Хранят окончательное состояние runtime и dispose listeners.
50
+ h(this, "_disposed", !1);
51
+ h(this, "_disposedListeners", /* @__PURE__ */ new Set());
52
+ const e = t.id ?? `runtime-${v._runtimeCounter++}`, s = t.enforceActions ?? !1, i = t.scheduler ?? d.Sync;
53
+ if (!I(i))
54
+ throw new Error(`[Raph] Unsupported scheduler "${String(i)}".`);
55
+ const r = t.kernel ?? new O({ id: `${e}-kernel` });
56
+ this.configuration = Object.freeze({ id: e, kernel: r, enforceActions: s, scheduler: i });
57
+ const o = `[Raph] Runtime "${e}" is disposed.`;
58
+ this._signalLifecycle = {
59
+ owner: this,
60
+ runWrite: (n) => this._runWrite(n),
61
+ ...s ? { assertWriteAllowed: () => this._assertWriteAllowed() } : {},
62
+ throwDisposed: () => {
63
+ throw new R(o);
64
+ },
65
+ throwCrossRuntime: (n) => this._throwCrossRuntime(n)
66
+ }, this._reactivity = new U(this._signalLifecycle), r._attachRuntime(this), this.rootScope = new S(`${e}:root-scope`, this), this.root = new m(null, { id: `${e}:root` }, this);
67
+ }
68
+ /**
69
+ * Возвращает внутренний runtime reactivity adapter.
70
+ * @internal
71
+ */
72
+ _getReactivity() {
73
+ return this._reactivity;
74
+ }
75
+ /**
76
+ * Возвращает стабильный идентификатор runtime.
77
+ */
78
+ get id() {
79
+ return this.configuration.id;
80
+ }
81
+ /**
82
+ * Возвращает data/meta Kernel этого runtime.
83
+ */
84
+ get kernel() {
85
+ return this.configuration.kernel;
86
+ }
87
+ /**
88
+ * Возвращает лениво созданный runtime-owned metadata facade.
89
+ */
90
+ get meta() {
91
+ return this._assertAlive(), this._meta ?? (this._meta = new M(this.kernel, {
92
+ assertReadable: () => this._assertAlive(),
93
+ assertWritable: () => this._assertWriteAllowed(),
94
+ runWrite: (t, e) => this._runWrite(t, e),
95
+ watch: (t, e, s) => this._own(
96
+ this._watchMeta(t, e, s),
97
+ this.rootScope
98
+ )
99
+ }));
100
+ }
101
+ /**
102
+ * Показывает, освобождён ли runtime.
103
+ */
104
+ get disposed() {
105
+ return this._disposed;
106
+ }
107
+ /**
108
+ * Возвращает лениво созданное read-only представление ownership graph.
109
+ */
110
+ get graph() {
111
+ return this._parentGraph ?? (this._parentGraph = x());
112
+ }
113
+ /**
114
+ * Показывает, удерживается ли автоматический frame-loop.
115
+ */
116
+ get loopEnabled() {
117
+ var t;
118
+ return ((t = this._frameLoop) == null ? void 0 : t.running) ?? !1;
119
+ }
120
+ /**
121
+ * Возвращает последний frame context runtime pipeline.
122
+ */
123
+ get frame() {
124
+ var t;
125
+ return ((t = this._phases) == null ? void 0 : t.frame) ?? { now: 0, delta: 0, elapsed: 0, frame: 0 };
126
+ }
127
+ /**
128
+ * Возвращает текущее определение runtime phases.
129
+ */
130
+ get phases() {
131
+ var t;
132
+ return ((t = this._phases) == null ? void 0 : t.phases) ?? [];
133
+ }
134
+ /**
135
+ * Формирует диагностический снимок materialized derived registry.
136
+ */
137
+ getDerivedSnapshot() {
138
+ return this.kernel.getDerivedSnapshot();
139
+ }
140
+ /**
141
+ * Возвращает лениво созданную read-only диагностику runtime и ownership tree.
142
+ */
143
+ get debug() {
144
+ return this._debug ?? (this._debug = Object.freeze({
145
+ snapshot: () => this._createDebugSnapshot(),
146
+ getTree: () => y(this.root)
147
+ }));
148
+ }
149
+ /**
150
+ * Создаёт writable signal, принадлежащий указанному owner.
151
+ */
152
+ signal(t, e = this.rootScope) {
153
+ return this._assertOwnerRuntime(e), this._reactivity.signalForOwner(t, e);
154
+ }
155
+ computed(t, e = this.rootScope) {
156
+ this._assertOwnerRuntime(e);
157
+ const s = typeof t == "function" ? t : t.get, i = this._reactivity.computedForOwner(
158
+ () => this._runTracked(s),
159
+ e
160
+ );
161
+ return typeof t == "function" ? i : this._attachWritableComputed(i, t.set, e);
162
+ }
163
+ effect(t, e, s = {}, i = this.rootScope) {
164
+ const r = typeof t == "string" ? e : t, o = typeof t == "string" ? i : e ?? this.rootScope;
165
+ if (this._assertOwnerRuntime(o), typeof t == "string") {
166
+ const n = t.trim(), c = this._execution;
167
+ c.requirePhase(n);
168
+ const p = s.priority ?? 0, u = s.initial ?? "scheduled";
169
+ if (!Number.isFinite(p))
170
+ throw new TypeError("[Raph] Effect priority must be finite.");
171
+ if (u !== "scheduled" && u !== "sync")
172
+ throw new TypeError(`[Raph] Unsupported effect initial mode "${String(u)}".`);
173
+ u === "sync" && c.lockConfiguration();
174
+ const l = c.phaseMode(n) === "always" ? this._frameRevision ?? (this._frameRevision = this._reactivity.signal(!1)) : void 0, w = this._reactivity.withEffectBinding(
175
+ (_) => c.bindEffect(
176
+ n,
177
+ p,
178
+ _,
179
+ o instanceof m ? o : void 0
180
+ ),
181
+ u,
182
+ () => this._reactivity.effect(() => (l == null || l.get(), this._runTracked(r)))
183
+ );
184
+ return this._own(w, o);
185
+ }
186
+ return this._own(
187
+ this._reactivity._effectImmediate(() => this._runTracked(r)),
188
+ o
189
+ );
190
+ }
191
+ watch(t, e, s = {}, i = this.rootScope) {
192
+ return this._assertOwnerRuntime(i), z(t) ? this._own(this._watchPath(t, e), i) : this._own(
193
+ $(
194
+ this._reactivity._effectImmediate,
195
+ this._reactivity.untracked,
196
+ t,
197
+ e,
198
+ s,
199
+ (r) => this._runTracked(r)
200
+ ),
201
+ i
202
+ );
203
+ }
204
+ /**
205
+ * Возвращает кешируемый runtime-owned handle canonical path.
206
+ */
207
+ path(t, e = {}) {
208
+ this._assertAlive();
209
+ const s = q(t, e), i = this._pathHandles ?? (this._pathHandles = /* @__PURE__ */ new Map()), r = i.get(s.canonical);
210
+ if (r !== void 0)
211
+ return r;
212
+ const o = new L(
213
+ this.kernel,
214
+ s,
215
+ e,
216
+ (n) => this._releasePathHandle(n),
217
+ this._reactivity,
218
+ () => this._assertAlive(),
219
+ () => this._assertTrackedRead(),
220
+ this.configuration.enforceActions ? () => this._assertWriteAllowed() : void 0,
221
+ (n) => this._runWrite(n)
222
+ );
223
+ return i.set(s.canonical, o), o;
224
+ }
225
+ get(t, e) {
226
+ this._assertTrackedRead();
227
+ const s = t ?? "";
228
+ return this._reactivity._isTracking() ? this.path(s, e)._getTracked() : this.kernel.get(s, e);
229
+ }
230
+ peek(t, e) {
231
+ return this._assertAlive(), this.kernel.peek(t ?? "", e);
232
+ }
233
+ /**
234
+ * Проверяет наличие значения Kernel по пути.
235
+ */
236
+ has(t, e) {
237
+ return this._assertAlive(), this.kernel.has(t, e);
238
+ }
239
+ /**
240
+ * Записывает значение Kernel внутри runtime write policy.
241
+ */
242
+ set(t, e, s) {
243
+ this._assertWriteAllowed(), this._runWrite(() => this.kernel.set(t, e, s));
244
+ }
245
+ /**
246
+ * Объединяет значение Kernel внутри runtime write policy.
247
+ */
248
+ merge(t, e, s) {
249
+ this._assertWriteAllowed(), this._runWrite(() => this.kernel.merge(t, e, s));
250
+ }
251
+ /**
252
+ * Удаляет значение Kernel внутри runtime write policy.
253
+ */
254
+ delete(t, e) {
255
+ this._assertWriteAllowed(), this._runWrite(() => this.kernel.delete(t, e));
256
+ }
257
+ /**
258
+ * Выполняет операцию в общей синхронной transaction boundary.
259
+ */
260
+ transaction(t) {
261
+ this._assertAlive(), this._transactionDepth++;
262
+ try {
263
+ return this._reactivity.batch(() => this.kernel.transaction(t));
264
+ } finally {
265
+ this._transactionDepth--, this._requestExecution();
266
+ }
267
+ }
268
+ /**
269
+ * Создаёт именованную action boundary для разрешённых записей.
270
+ */
271
+ action(t, e, s = this.rootScope) {
272
+ if (this._assertOwnerRuntime(s), !t.trim())
273
+ throw new Error("[Raph] Action name must not be empty.");
274
+ return (...i) => (s._assertAlive(), this.runInAction(t, () => e(...i)));
275
+ }
276
+ /**
277
+ * Выполняет операцию внутри action boundary.
278
+ */
279
+ runInAction(t, e) {
280
+ this._assertAlive(), this._actionDepth++;
281
+ try {
282
+ return this.transaction(() => this._runUntracked(e));
283
+ } finally {
284
+ this._actionDepth--;
285
+ }
286
+ }
287
+ /**
288
+ * Выполняет операцию без регистрации реактивных зависимостей.
289
+ */
290
+ untracked(t) {
291
+ return this._assertAlive(), this._reactivity.untrackedWithOwner(t);
292
+ }
293
+ /**
294
+ * Создаёт дочерний lifecycle scope.
295
+ */
296
+ scope(t) {
297
+ return this._assertAlive(), new S(t, this);
298
+ }
299
+ /**
300
+ * Создаёт дочерний execution node.
301
+ */
302
+ node(t, e) {
303
+ this._assertAlive();
304
+ const s = t.parent ?? this.root, i = new m(s, t, this);
305
+ try {
306
+ return i._setApi(e(i)), i;
307
+ } catch (r) {
308
+ try {
309
+ i.dispose();
310
+ } catch (o) {
311
+ throw new AggregateError(
312
+ [r, o],
313
+ `[Raph] Node "${i.id}" setup and cleanup failed.`
314
+ );
315
+ }
316
+ throw r;
317
+ }
318
+ }
319
+ /**
320
+ * Находит принадлежащий runtime node по id для диагностики.
321
+ */
322
+ getNode(t) {
323
+ this._assertAlive();
324
+ const e = [this.root];
325
+ for (; e.length !== 0; ) {
326
+ const s = e.pop();
327
+ if (s.id === t)
328
+ return s;
329
+ e.push(...s.children);
330
+ }
331
+ }
332
+ /**
333
+ * Заменяет полное определение phase pipeline до его первого выполнения.
334
+ */
335
+ definePhases(t) {
336
+ this._execution.definePhases(t);
337
+ }
338
+ /**
339
+ * Добавляет phase до первого выполнения pipeline.
340
+ */
341
+ addPhase(t) {
342
+ this._execution.addPhase(t);
343
+ }
344
+ /**
345
+ * Удаляет пользовательские phases до первого выполнения pipeline.
346
+ */
347
+ clearPhases() {
348
+ var t;
349
+ this._assertAlive(), (t = this._phases) == null || t.clearPhases();
350
+ }
351
+ /**
352
+ * Регистрирует path observer в phase pipeline.
353
+ */
354
+ observeData(t, e, s) {
355
+ return this._assertOwnerRuntime(t), this._own(this._execution.observeData(t, e, s), t);
356
+ }
357
+ /**
358
+ * Регистрирует tracked executor указанной phase.
359
+ */
360
+ track(t, e, s = {}) {
361
+ return this._assertOwnerRuntime(t), this._own(this._execution.track(t, e, s), t);
362
+ }
363
+ /**
364
+ * Помечает node для выполнения в pipeline.
365
+ */
366
+ invalidateNode(t, e) {
367
+ this._assertOwnerRuntime(t), this._execution.invalidate(t, e);
368
+ }
369
+ /**
370
+ * Синхронно выполняет все готовые очереди pipeline.
371
+ */
372
+ flush() {
373
+ var t;
374
+ this._assertAlive(), this._executionRequested = !1, (t = this._phases) == null || t.flush();
375
+ }
376
+ /**
377
+ * Получает lease автоматического frame-loop.
378
+ */
379
+ acquireLoop(t) {
380
+ return this._assertAlive(), this._clock.acquire(t);
381
+ }
382
+ /**
383
+ * Запускает manual lease автоматического frame-loop.
384
+ */
385
+ startLoop() {
386
+ this._assertAlive(), this._clock.start();
387
+ }
388
+ /**
389
+ * Останавливает manual lease автоматического frame-loop.
390
+ */
391
+ stopLoop() {
392
+ var t;
393
+ (t = this._frameLoop) == null || t.stop();
394
+ }
395
+ /**
396
+ * Создаёт управляемое derived-представление source path в target path.
397
+ */
398
+ derive(t) {
399
+ this._assertAlive();
400
+ const e = t.compute, s = this.kernel.derive({
401
+ ...t,
402
+ compute: (i) => this._runUntracked(() => e(i))
403
+ });
404
+ return this._own(() => s.dispose(), this.rootScope), s;
405
+ }
406
+ /**
407
+ * Освобождает execution graph и отсоединяет runtime от shared Kernel.
408
+ */
409
+ dispose() {
410
+ var r, o;
411
+ if (this._disposed)
412
+ return;
413
+ this._disposed = !0, this._executionRequested = !1, this._signalLifecycle.owner = void 0;
414
+ const t = [], e = [...this._owners];
415
+ try {
416
+ (r = this._frameLoop) == null || r.dispose();
417
+ } catch (n) {
418
+ t.push(n);
419
+ }
420
+ this._frameLoop = void 0;
421
+ try {
422
+ (o = this._phases) == null || o.dispose();
423
+ } catch (n) {
424
+ t.push(n);
425
+ }
426
+ this._phases = void 0;
427
+ try {
428
+ this.root.dispose();
429
+ } catch (n) {
430
+ t.push(n);
431
+ }
432
+ for (const n of e.reverse())
433
+ if (!(n === this.root || n === this.rootScope || n.disposed))
434
+ try {
435
+ n.dispose();
436
+ } catch (c) {
437
+ t.push(c);
438
+ }
439
+ try {
440
+ this.rootScope.dispose();
441
+ } catch (n) {
442
+ t.push(n);
443
+ }
444
+ this._owners.clear(), this._meta = void 0, this._frameRevision = void 0;
445
+ const s = this._pathHandles;
446
+ if (this._pathHandles = void 0, s !== void 0) {
447
+ for (const n of s.values())
448
+ try {
449
+ n.dispose();
450
+ } catch (c) {
451
+ t.push(c);
452
+ }
453
+ s.clear();
454
+ }
455
+ try {
456
+ this.kernel._detachRuntime(this);
457
+ } catch (n) {
458
+ t.push(n);
459
+ }
460
+ const i = [...this._disposedListeners];
461
+ this._disposedListeners.clear();
462
+ for (const n of i)
463
+ try {
464
+ n();
465
+ } catch (c) {
466
+ t.push(c);
467
+ }
468
+ D(t, `[Raph] Runtime "${this.id}" disposal failed.`);
469
+ }
470
+ /**
471
+ * Регистрирует listener освобождения runtime.
472
+ * @internal
473
+ */
474
+ _onDisposed(t) {
475
+ return this._disposed ? (t(), () => {
476
+ }) : (this._disposedListeners.add(t), () => {
477
+ this._disposedListeners.delete(t);
478
+ });
479
+ }
480
+ _watchPath(t, e) {
481
+ const s = new g((r) => this._runUntracked(r)), i = this.kernel.watch(t, (r) => {
482
+ s.deliver(() => e(r));
483
+ });
484
+ return () => s.stop(i);
485
+ }
486
+ _createDebugSnapshot() {
487
+ var s, i, r;
488
+ const t = ((s = this._frameLoop) == null ? void 0 : s._debugState()) ?? { running: !1, manual: !1, leases: 0 }, e = [...this._owners].filter((o) => o !== this.rootScope && !(o instanceof m)).map(y);
489
+ return Object.freeze({
490
+ id: this.id,
491
+ disposed: this._disposed,
492
+ pending: !this._disposed && (this._executionRequested || (((i = this._phases) == null ? void 0 : i._debugPending()) ?? !1)),
493
+ transactionDepth: this._transactionDepth,
494
+ kernelTransactionDepth: this._kernelTransactionDepth,
495
+ owners: this._owners.size,
496
+ pathHandles: ((r = this._pathHandles) == null ? void 0 : r.size) ?? 0,
497
+ rootScope: y(this.rootScope),
498
+ scopes: Object.freeze(e),
499
+ root: y(this.root),
500
+ frameLoop: Object.freeze(t)
501
+ });
502
+ }
503
+ _watchMeta(t, e, s) {
504
+ if (s.phase !== void 0)
505
+ return this._watchMetaInPhase(t, e, s);
506
+ if (s.priority !== void 0)
507
+ throw new TypeError("[RaphMeta] watch priority requires a phase.");
508
+ const i = new g((o) => this._runUntracked(o)), r = this.kernel._watchMeta(t, (o) => {
509
+ i.deliver(() => e(o));
510
+ }, s);
511
+ return () => i.stop(r);
512
+ }
513
+ _watchMetaInPhase(t, e, s) {
514
+ const i = s.phase.trim(), r = this._execution;
515
+ r.requirePhase(i);
516
+ const o = s.priority ?? 0;
517
+ if (!Number.isFinite(o))
518
+ throw new TypeError("[RaphMeta] watch priority must be finite.");
519
+ const n = r.retainPhase(i), c = new g((_) => this._runUntracked(_));
520
+ let p = [], u;
521
+ const l = () => {
522
+ u = void 0;
523
+ const _ = p;
524
+ p = [], c.deliver(() => e({ events: _ }));
525
+ };
526
+ let w;
527
+ try {
528
+ w = this.kernel._watchMeta(t, ({ events: _ }) => {
529
+ c.stopped || (p.push(..._), u === void 0 && (u = r.queueEffect(i, o, l, !1)));
530
+ }, s, (_) => {
531
+ !c.stopped && _ && u !== void 0 && r.request();
532
+ });
533
+ } catch (_) {
534
+ throw n(), _;
535
+ }
536
+ return () => {
537
+ if (c.stopped)
538
+ return;
539
+ const _ = [];
540
+ try {
541
+ c.stop(w);
542
+ } catch (f) {
543
+ _.push(f);
544
+ }
545
+ try {
546
+ u == null || u();
547
+ } catch (f) {
548
+ _.push(f);
549
+ }
550
+ try {
551
+ n();
552
+ } catch (f) {
553
+ _.push(f);
554
+ }
555
+ u = void 0, p = [], D(_, "[RaphMeta] Phase watch disposal failed.");
556
+ };
557
+ }
558
+ _releasePathHandle(t) {
559
+ const e = this._pathHandles;
560
+ (e == null ? void 0 : e.get(t.path)) === t && (e.delete(t.path), e.size === 0 && (this._pathHandles = void 0));
561
+ }
562
+ get _execution() {
563
+ return this._assertAlive(), this._phases ?? (this._phases = new F(
564
+ this.kernel,
565
+ this.root,
566
+ this.configuration.scheduler,
567
+ (t) => this._runUntracked(t),
568
+ () => {
569
+ const t = this._mutationDepth !== 0 || this._transactionDepth !== 0 || this._kernelTransactionDepth !== 0 || this._reactivity._isFlushingEffects();
570
+ return t && this.configuration.scheduler === d.Sync && (this._executionRequested = !0), t;
571
+ }
572
+ ));
573
+ }
574
+ get _clock() {
575
+ return this._frameLoop ?? (this._frameLoop = new H(() => this._tickFrameLoop()));
576
+ }
577
+ _tickFrameLoop() {
578
+ var t;
579
+ this._disposed || (this._frameRevision !== void 0 && (this._frameRevisionValue = !this._frameRevisionValue, this._frameRevision.set(this._frameRevisionValue)), (t = this._phases) == null || t.requestAlwaysPhases(), this._requestExecution());
580
+ }
581
+ _attachWritableComputed(t, e, s) {
582
+ let i = e;
583
+ this._own(() => {
584
+ i = void 0;
585
+ }, s);
586
+ const r = t;
587
+ return r.set = (o) => {
588
+ s._assertAlive(), this._assertWriteAllowed(), i(o);
589
+ }, r;
590
+ }
591
+ _own(t, e) {
592
+ try {
593
+ return e._adoptResource(t);
594
+ } catch (s) {
595
+ try {
596
+ t();
597
+ } catch (i) {
598
+ throw new AggregateError(
599
+ [s, i],
600
+ "[Raph] Resource registration and cleanup failed."
601
+ );
602
+ }
603
+ throw s;
604
+ }
605
+ }
606
+ /**
607
+ * Регистрирует lifecycle owner в runtime registry.
608
+ * @internal
609
+ */
610
+ _registerOwner(t) {
611
+ this._assertAlive(), this._owners.add(t);
612
+ }
613
+ /**
614
+ * Удаляет lifecycle owner из runtime registry.
615
+ * @internal
616
+ */
617
+ _unregisterOwner(t) {
618
+ this._owners.delete(t);
619
+ }
620
+ /**
621
+ * Проверяет, что owner принадлежит этому живому runtime.
622
+ * @internal
623
+ */
624
+ _assertOwnerRuntime(t) {
625
+ if (this._assertAlive(), t.runtime !== this)
626
+ throw new k("[Raph] Owner belongs to another runtime.");
627
+ t._assertAlive();
628
+ }
629
+ _runTracked(t) {
630
+ return this._reactivity.runWithOwner(this._signalLifecycle, t);
631
+ }
632
+ _runUntracked(t) {
633
+ return this._reactivity.untrackedWithOwner(t);
634
+ }
635
+ _runWrite(t, e = !0) {
636
+ e && this.configuration.scheduler === d.Sync && (this._executionRequested = !0), this._mutationDepth++;
637
+ try {
638
+ return t();
639
+ } finally {
640
+ this._mutationDepth--, this._requestExecution();
641
+ }
642
+ }
643
+ _requestExecution() {
644
+ var t;
645
+ this.configuration.scheduler !== d.Sync || this._mutationDepth !== 0 || this._transactionDepth !== 0 || this._kernelTransactionDepth !== 0 || this._reactivity._isFlushingEffects() || this._executionRequested && (this._executionRequested = !1, (t = this._phases) == null || t.flush());
646
+ }
647
+ /**
648
+ * Открывает shared Kernel transaction для runtime.
649
+ * @internal
650
+ */
651
+ _beginKernelTransaction() {
652
+ this._disposed || this._kernelTransactionDepth++;
653
+ }
654
+ /**
655
+ * Закрывает shared Kernel transaction и запускает отложенное выполнение.
656
+ * @internal
657
+ */
658
+ _endKernelTransaction() {
659
+ this._kernelTransactionDepth !== 0 && (this._kernelTransactionDepth--, this._disposed || this._requestExecution());
660
+ }
661
+ _assertTrackedRead() {
662
+ this._assertAlive();
663
+ const t = this._reactivity.getActiveOwner();
664
+ t !== void 0 && t !== this && this._throwCrossRuntime(t);
665
+ }
666
+ _assertWriteAllowed() {
667
+ if (this._assertAlive(), this.configuration.enforceActions && this._actionDepth === 0 && this._transactionDepth === 0)
668
+ throw new T(
669
+ "[Raph] Writes are allowed only inside action() or transaction()."
670
+ );
671
+ }
672
+ _throwCrossRuntime(t) {
673
+ throw new k(
674
+ `[Raph] Runtime "${this.id}" cannot be tracked by runtime "${t.id}".`
675
+ );
676
+ }
677
+ _throwDisposed() {
678
+ throw new R(`[Raph] Runtime "${this.id}" is disposed.`);
679
+ }
680
+ _assertAlive() {
681
+ this._disposed && this._throwDisposed();
682
+ }
683
+ };
684
+ // Формирует локальный id для runtime без явно заданного имени.
685
+ h(v, "_runtimeCounter", 0);
686
+ let P = v;
687
+ function z(a) {
688
+ return typeof a == "string" || a instanceof A || E(a) ? !0 : Array.isArray(a) && a.every(
689
+ (t) => typeof t == "string" || t instanceof A || E(t)
690
+ );
691
+ }
692
+ function E(a) {
693
+ return typeof a == "object" && a !== null && "segs" in a && a.segs !== void 0 && Array.isArray(a.segs);
694
+ }
695
+ function I(a) {
696
+ return a === d.Sync || a === d.Microtask || a === d.AnimationFrame;
697
+ }
698
+ export {
699
+ P as RaphRuntime
700
+ };
@@ -0,0 +1 @@
1
+ "use strict";var n=Object.defineProperty;var o=(s,i,t)=>i in s?n(s,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[i]=t;var h=(s,i,t)=>o(s,typeof i!="symbol"?i+"":i,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../reactivity/scope.cjs"),c=require("./errors.cjs");class d extends u.ScopeNode{constructor(t,e){super(e._getReactivity());h(this,"id");h(this,"runtime");this.id=t,this.runtime=e,e._registerOwner(this)}signal(t){return this._assertAlive(),this.runtime.signal(t,this)}computed(t){return this._assertAlive(),typeof t=="function"?this.runtime.computed(t,this):this.runtime.computed(t,this)}effect(t,e,r){return this._assertAlive(),typeof t=="string"?this.runtime.effect(t,e,r,this):this.runtime.effect(t,this)}watch(t,e,r){return this._assertAlive(),this.runtime.watch(t,e,r,this)}action(t,e){return this._assertAlive(),this.runtime.action(t,e,this)}_afterDispose(){this.runtime._unregisterOwner(this)}_disposalMessage(){return`[Raph] Scope "${this.id}" disposal failed.`}_assertAlive(){if(this._disposed||this._disposing)throw new c.RaphDisposedError(`[Raph] Owner "${this.id}" is disposed.`)}}exports.RaphScope=d;