@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,4 +1,18 @@
1
- const R = Symbol("raph.reactive-object.identity"), x = /* @__PURE__ */ new Set([
1
+ class R {
2
+ constructor(t, e) {
3
+ this._key = t, this._source = e;
4
+ }
5
+ get(t) {
6
+ return this._key === t ? this._source : void 0;
7
+ }
8
+ set(t, e) {
9
+ return /* @__PURE__ */ new Map([[this._key, this._source], [t, e]]);
10
+ }
11
+ entries() {
12
+ return [[this._key, this._source]].values();
13
+ }
14
+ }
15
+ const D = Symbol("raph.reactive-object.identity"), _ = 0, I = 1, p = 2, H = /* @__PURE__ */ new Set([
2
16
  "copyWithin",
3
17
  "fill",
4
18
  "pop",
@@ -8,40 +22,121 @@ const R = Symbol("raph.reactive-object.identity"), x = /* @__PURE__ */ new Set([
8
22
  "sort",
9
23
  "splice",
10
24
  "unshift"
11
- ]), f = /* @__PURE__ */ new WeakMap(), _ = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), T = Object.freeze({}), O = Object.freeze({
12
- assertRead: p,
13
- assertWrite: p,
14
- throwForeign: p
25
+ ]), E = 0, T = 1, P = 2, S = 3, C = 4;
26
+ function V(o, t, e) {
27
+ switch (t) {
28
+ case "push":
29
+ return function(i) {
30
+ const n = o._fastArrayTarget(this);
31
+ return n === void 0 || arguments.length !== 1 ? Reflect.apply(e, this, arguments) : o._arrayWrite(E, n, i, void 0, void 0, 1);
32
+ };
33
+ case "pop":
34
+ return function() {
35
+ const i = o._fastArrayTarget(this);
36
+ return i === void 0 || arguments.length !== 0 ? Reflect.apply(e, this, arguments) : o._arrayWrite(T, i, void 0, void 0, void 0, 0);
37
+ };
38
+ case "shift":
39
+ return function() {
40
+ const i = o._fastArrayTarget(this);
41
+ return i === void 0 || arguments.length !== 0 ? Reflect.apply(e, this, arguments) : o._arrayWrite(P, i, void 0, void 0, void 0, 0);
42
+ };
43
+ case "unshift":
44
+ return function(i) {
45
+ const n = o._fastArrayTarget(this);
46
+ return n === void 0 || arguments.length !== 1 ? Reflect.apply(e, this, arguments) : o._arrayWrite(S, n, i, void 0, void 0, 1);
47
+ };
48
+ case "splice":
49
+ return function(i, n, s) {
50
+ const a = arguments.length, c = o._fastArrayTarget(this), h = a >= 1 && a <= 3 && typeof i == "number" && (a === 1 || typeof n == "number");
51
+ return c === void 0 || !h ? Reflect.apply(e, this, arguments) : o._arrayWrite(C, c, i, n, s, a);
52
+ };
53
+ default:
54
+ return e;
55
+ }
56
+ }
57
+ const f = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), A = /* @__PURE__ */ new WeakMap();
58
+ let j = 0;
59
+ class N {
60
+ owner;
61
+ proxy = void 0;
62
+ tracking = void 0;
63
+ extension = void 0;
64
+ /** Plain view слоя observable и его глубина. */
65
+ view = void 0;
66
+ deep = !1;
67
+ constructor(t) {
68
+ this.owner = t;
69
+ }
70
+ }
71
+ let O;
72
+ class q {
73
+ constructor(t) {
74
+ return t;
75
+ }
76
+ }
77
+ class g extends q {
78
+ #t;
79
+ static read(t) {
80
+ return #t in t ? t.#t : O?.get(t);
81
+ }
82
+ static write(t, e) {
83
+ if (#t in t) {
84
+ t.#t = e;
85
+ return;
86
+ }
87
+ if (Object.isExtensible(t)) {
88
+ const r = new g(t);
89
+ r.#t = e;
90
+ return;
91
+ }
92
+ (O ??= /* @__PURE__ */ new WeakMap()).set(t, e);
93
+ }
94
+ }
95
+ const B = Object.freeze({}), F = Object.freeze({
96
+ assertRead: v,
97
+ assertWrite: v,
98
+ throwForeign: v
15
99
  });
16
- function P(s, e) {
17
- _.set(s, e);
100
+ function U(o, t) {
101
+ m.set(o, t);
102
+ const e = f.get(o);
103
+ e !== void 0 && !e.disposed && e._setPolicy(t);
18
104
  }
19
- function W(s, e = O) {
20
- _.delete(s);
21
- const t = f.get(s);
22
- t !== void 0 && (f.delete(s), t.dispose(e));
105
+ function z(o, t = F) {
106
+ m.delete(o);
107
+ const e = f.get(o);
108
+ e !== void 0 && (f.delete(o), e.dispose(t));
23
109
  }
24
- function m(s, e, t) {
25
- const r = w(e), i = f.get(s);
110
+ function $(o, t, e) {
111
+ const r = x(t), i = f.get(o);
26
112
  if (r !== void 0) {
27
113
  if (r.context === i)
28
- return e;
29
- throw (_.get(s) ?? T).throwForeign?.(r.context.owner), new TypeError("[Raph] Reactive object belongs to another reactivity engine.");
114
+ return t;
115
+ throw (m.get(o) ?? B).throwForeign?.(r.context.owner), new TypeError("[Raph] Reactive object belongs to another reactivity engine.");
30
116
  }
31
- return D(e), (i ?? A(s, t)).wrap(e);
117
+ return M(t), (i ?? L(o, e)).wrap(t);
32
118
  }
33
- class j {
34
- _rawToProxy = /* @__PURE__ */ new WeakMap();
35
- _rawToTracking = /* @__PURE__ */ new WeakMap();
119
+ class Y {
120
+ // Записи raw для context без Runtime; у context Runtime — undefined.
121
+ _admins;
36
122
  _arrayMethods = /* @__PURE__ */ new Map();
37
123
  _bridge;
38
124
  _policy;
39
125
  _writeDepth = 0;
126
+ // Граница, открытая _openWrite(); не undefined только между open и close.
127
+ _openBridge;
128
+ _openBoundary;
40
129
  _disposed = !1;
130
+ _extendedHandlers;
131
+ // Proxy и raw последнего чтения мутатора массива; сбрасываются при вызове.
132
+ _mutatorProxy;
133
+ _mutatorTarget;
134
+ // Цели, чьё поле стало non-configurable через defineProperty trap этого context.
135
+ _lockedTargets;
41
136
  _handler;
42
137
  _weakSelf;
43
- constructor(e, t) {
44
- this._bridge = e, this._policy = t, this._weakSelf = new WeakRef(this), this._handler = {
138
+ constructor(t, e) {
139
+ this._bridge = t, this._policy = e, this._weakSelf = new WeakRef(this), e.owner === void 0 && (this._admins = /* @__PURE__ */ new WeakMap(), j++), this._handler = {
45
140
  defineProperty: (r, i, n) => this._define(r, i, n),
46
141
  deleteProperty: (r, i) => this._delete(r, i),
47
142
  get: (r, i, n) => this._get(r, i, n),
@@ -53,213 +148,555 @@ class j {
53
148
  get owner() {
54
149
  return this._policy.owner;
55
150
  }
151
+ _setPolicy(t) {
152
+ this._policy = t;
153
+ }
56
154
  get disposed() {
57
155
  return this._disposed;
58
156
  }
59
- wrap(e) {
60
- const t = w(e);
61
- if (t !== void 0) {
62
- if (t.context === this)
63
- return e;
64
- throw this._policy.throwForeign?.(t.context.owner), new TypeError("[Raph] Reactive object belongs to another reactivity engine.");
65
- }
66
- D(e);
67
- const r = v(e);
157
+ support() {
158
+ const t = {
159
+ bridge: this._requireBridge(),
160
+ wrap: (e, r, i) => {
161
+ const n = this._ownAdmin(e), s = n?.extension;
162
+ if (s !== void 0) {
163
+ if (this._policy.assertRead?.(), s.extension !== r || s.deep !== i)
164
+ throw new TypeError("[Raph] Observable depth is already fixed for this value.");
165
+ return n.proxy;
166
+ }
167
+ const a = this._extensionHandler(r, i), c = this.wrap(e, a), h = this._ownAdmin(e);
168
+ return h !== void 0 && (h.extension = a), c;
169
+ },
170
+ observedView: (e) => {
171
+ const r = this._ownAdmin(e);
172
+ return r?.view === void 0 ? void 0 : r;
173
+ },
174
+ setObservedView: (e, r, i) => {
175
+ const n = this._ownAdmin(e);
176
+ n !== void 0 && (n.view = r, n.deep = i);
177
+ },
178
+ claim: (e) => this.claim(e),
179
+ unwrap: (e) => this._unwrap(e),
180
+ identity: (e) => ({ context: this, raw: e }),
181
+ hasView: (e) => this._ownAdmin(e)?.proxy !== void 0,
182
+ write: (e) => this._write(e),
183
+ openWrite: () => this._openWrite(),
184
+ closeWrite: () => this._closeWrite(),
185
+ failWrite: (e) => this._failOpenWrite(e),
186
+ tryDirectWrite: () => (this._policy.assertWrite?.(), this._writeDepth !== 0 || this._policy.writeBoundary?._isWriteBatchOpen() === !0)
187
+ };
188
+ return Object.defineProperty(t, "policy", { enumerable: !0, get: () => this._policy }), t;
189
+ }
190
+ claim(t) {
191
+ this._policy.assertRead?.(), this._claimAdmin(t);
192
+ }
193
+ /** Запись raw, принадлежащая этому context, либо undefined. */
194
+ _ownAdmin(t) {
195
+ const e = this._admins;
196
+ if (e !== void 0)
197
+ return e.get(t);
198
+ const r = g.read(t);
199
+ return r !== void 0 && r.owner === this._weakSelf ? r : void 0;
200
+ }
201
+ /**
202
+ * Запись raw этого context. Запись освобождённого или собранного владельца
203
+ * заменяется новой; живой чужой владелец отклоняет raw.
204
+ */
205
+ _claimAdmin(t) {
206
+ const e = this._ownAdmin(t);
207
+ if (e !== void 0)
208
+ return e;
209
+ const r = W(t);
68
210
  if (r !== void 0 && r !== this && !r.disposed)
69
211
  throw this._policy.throwForeign?.(r.owner), new TypeError("[Raph] Raw reactive object belongs to another reactivity engine.");
70
- const i = this._rawToProxy.get(e);
71
- if (i !== void 0)
72
- return i;
73
- const n = new Proxy(e, this._handler);
74
- return l.set(e, this._weakSelf), this._rawToProxy.set(e, n), n;
75
- }
76
- dispose(e) {
77
- this._disposed = !0, this._policy = e, this._bridge = void 0, this._rawToProxy = /* @__PURE__ */ new WeakMap(), this._rawToTracking = /* @__PURE__ */ new WeakMap(), this._arrayMethods.clear();
78
- }
79
- _get(e, t, r) {
80
- if (t === R)
81
- return { context: this, raw: e };
212
+ const i = new N(this._weakSelf), n = this._admins;
213
+ return n === void 0 ? g.write(t, i) : (n.set(t, i), A.set(t, this._weakSelf)), i;
214
+ }
215
+ wrap(t, e) {
216
+ const r = x(t);
217
+ if (r !== void 0) {
218
+ if (r.context === this)
219
+ return t;
220
+ throw this._policy.throwForeign?.(r.context.owner), new TypeError("[Raph] Reactive object belongs to another reactivity engine.");
221
+ }
222
+ M(t);
223
+ const i = this._claimAdmin(t), n = i.proxy;
224
+ if (n !== void 0)
225
+ return n;
226
+ const s = new Proxy(t, e?.handler ?? this._handler);
227
+ return i.proxy = s, s;
228
+ }
229
+ dispose(t) {
230
+ if (this._disposed = !0, this._policy = t, this._bridge = void 0, this._admins !== void 0 && (this._admins = /* @__PURE__ */ new WeakMap()), this._arrayMethods.clear(), this._lockedTargets = void 0, this._mutatorProxy = void 0, this._mutatorTarget = void 0, this._extendedHandlers !== void 0) {
231
+ for (const e of this._extendedHandlers.values())
232
+ e.deep !== void 0 && (e.deep.extension = void 0), e.shallow !== void 0 && (e.shallow.extension = void 0);
233
+ this._extendedHandlers = void 0;
234
+ }
235
+ }
236
+ _extensionHandler(t, e) {
237
+ const r = this._extendedHandlers ??= /* @__PURE__ */ new Map();
238
+ let i = r.get(t);
239
+ i === void 0 && r.set(t, i = {});
240
+ const n = e ? "deep" : "shallow";
241
+ let s = i[n];
242
+ if (s === void 0) {
243
+ const a = Object.create(this._handler), c = { extension: t, deep: e, handler: a };
244
+ a.get = (h, l, u) => this._get(h, l, u, c), i[n] = s = c;
245
+ }
246
+ return s;
247
+ }
248
+ _get(t, e, r, i) {
249
+ if (e === D)
250
+ return { context: this, raw: t };
82
251
  this._policy.assertRead?.();
83
- const i = Reflect.get(e, t, r);
84
- return this._trackValue(e, t), Array.isArray(e) && x.has(t) && i === Array.prototype[t] ? this._arrayMutator(t) : d(i) ? this.wrap(i) : i;
85
- }
86
- _set(e, t, r) {
87
- return this._write(() => {
88
- const i = this._unwrap(r), n = Object.hasOwn(e, t), o = Reflect.get(e, t, e), c = Array.isArray(e) ? e.length : 0;
89
- if (n && o === i)
90
- return !0;
91
- if (!Reflect.set(e, t, i, e))
92
- return !1;
93
- const h = this._rawToTracking.get(e);
94
- return h === void 0 || (this._trigger(h.valueDeps?.get(t)), n || (this._trigger(h.hasDeps?.get(t)), this._trigger(h.iterateDep)), this._triggerArrayShape(e, t, i, c, h)), !0;
95
- });
252
+ const n = Reflect.get(t, e, r);
253
+ if (this._trackValue(t, e), n === null || typeof n != "object")
254
+ return typeof n == "function" && Array.isArray(t) && H.has(e) && n === Array.prototype[e] ? (this._mutatorProxy = r, this._mutatorTarget = t, this._arrayMutator(e)) : n;
255
+ const s = i ?? this._ownAdmin(t)?.extension;
256
+ if (s !== void 0) {
257
+ if (!Object.isExtensible(t) || this._lockedTargets?.has(t) === !0) {
258
+ const a = Object.getOwnPropertyDescriptor(t, e);
259
+ if (a?.configurable === !1 && a.writable === !1 && "value" in a)
260
+ return n;
261
+ }
262
+ return s.extension.readValue(n, s.deep);
263
+ }
264
+ return w(n) ? this.wrap(n) : n;
96
265
  }
97
- _define(e, t, r) {
98
- return this._write(() => {
99
- const i = Object.hasOwn(e, t), n = Reflect.getOwnPropertyDescriptor(e, t), o = Reflect.get(e, t, e), c = Array.isArray(e) ? e.length : 0, a = "value" in r ? { ...r, value: this._unwrap(r.value) } : r;
100
- if (!Reflect.defineProperty(e, t, a))
101
- return !1;
102
- const u = this._rawToTracking.get(e);
103
- if (u === void 0)
104
- return !0;
105
- const y = Reflect.getOwnPropertyDescriptor(e, t), b = Reflect.get(e, t, e);
106
- return (!i || o !== b || !M(n, y)) && this._trigger(u.valueDeps?.get(t)), i ? n?.enumerable !== y?.enumerable && this._trigger(u.iterateDep) : (this._trigger(u.hasDeps?.get(t)), this._trigger(u.iterateDep)), this._triggerArrayShape(
107
- e,
108
- t,
109
- b,
110
- c,
111
- u
112
- ), !0;
113
- });
266
+ _set(t, e, r) {
267
+ const i = this._openWrite();
268
+ if (i === _)
269
+ return this._applySet(t, e, r);
270
+ if (i === p)
271
+ return this._writeThroughPolicy(() => this._applySet(t, e, r));
272
+ let n;
273
+ try {
274
+ n = this._applySet(t, e, r);
275
+ } catch (s) {
276
+ throw this._failOpenWrite(s);
277
+ }
278
+ return this._closeWrite(), n;
114
279
  }
115
- _delete(e, t) {
116
- return this._write(() => {
117
- if (!Object.hasOwn(e, t))
118
- return !0;
119
- if (!Reflect.deleteProperty(e, t))
120
- return !1;
121
- const i = this._rawToTracking.get(e);
122
- return i !== void 0 && (this._trigger(i.valueDeps?.get(t)), this._trigger(i.hasDeps?.get(t)), this._trigger(i.iterateDep)), !0;
123
- });
280
+ _applySet(t, e, r) {
281
+ const i = this._unwrap(r), n = Object.hasOwn(t, e), s = Reflect.get(t, e, t), a = Array.isArray(t) ? t.length : 0;
282
+ if (n && s === i)
283
+ return !0;
284
+ if (!Reflect.set(t, e, i, t))
285
+ return !1;
286
+ const h = this._ownAdmin(t)?.tracking;
287
+ return h === void 0 || (this._trigger(h.valueDeps?.get(e)), n || (this._trigger(h.hasDeps?.get(e)), this._trigger(h.iterateDep)), this._triggerArrayShape(t, e, i, a, h)), !0;
124
288
  }
125
- _has(e, t) {
126
- return this._policy.assertRead?.(), this._trackHas(e, t), Reflect.has(e, t);
289
+ _define(t, e, r) {
290
+ const i = this._openWrite();
291
+ if (i === _)
292
+ return this._applyDefine(t, e, r);
293
+ if (i === p)
294
+ return this._writeThroughPolicy(() => this._applyDefine(t, e, r));
295
+ let n;
296
+ try {
297
+ n = this._applyDefine(t, e, r);
298
+ } catch (s) {
299
+ throw this._failOpenWrite(s);
300
+ }
301
+ return this._closeWrite(), n;
127
302
  }
128
- _ownKeys(e) {
129
- return this._policy.assertRead?.(), this._trackIterate(e), Reflect.ownKeys(e);
303
+ _applyDefine(t, e, r) {
304
+ const i = Object.hasOwn(t, e), n = Reflect.getOwnPropertyDescriptor(t, e), s = Reflect.get(t, e, t), a = Array.isArray(t) ? t.length : 0, c = "value" in r ? { ...r, value: this._unwrap(r.value) } : r;
305
+ if (!Reflect.defineProperty(t, e, c))
306
+ return !1;
307
+ (n?.configurable === !1 || Reflect.getOwnPropertyDescriptor(t, e)?.configurable === !1) && (this._lockedTargets ??= /* @__PURE__ */ new WeakSet()).add(t);
308
+ const l = this._ownAdmin(t)?.tracking;
309
+ if (l === void 0)
310
+ return !0;
311
+ const u = Reflect.getOwnPropertyDescriptor(t, e), d = Reflect.get(t, e, t);
312
+ return (!i || s !== d || !K(n, u)) && this._trigger(l.valueDeps?.get(e)), i ? n?.enumerable !== u?.enumerable && this._trigger(l.iterateDep) : (this._trigger(l.hasDeps?.get(e)), this._trigger(l.iterateDep)), this._triggerArrayShape(
313
+ t,
314
+ e,
315
+ d,
316
+ a,
317
+ l
318
+ ), !0;
130
319
  }
131
- _arrayMutator(e) {
132
- const t = this._arrayMethods.get(e);
133
- if (t !== void 0)
134
- return t;
135
- const r = (n) => this._write(n), i = function(...n) {
320
+ _delete(t, e) {
321
+ const r = this._openWrite();
322
+ if (r === _)
323
+ return this._applyDelete(t, e);
324
+ if (r === p)
325
+ return this._writeThroughPolicy(() => this._applyDelete(t, e));
326
+ let i;
327
+ try {
328
+ i = this._applyDelete(t, e);
329
+ } catch (n) {
330
+ throw this._failOpenWrite(n);
331
+ }
332
+ return this._closeWrite(), i;
333
+ }
334
+ _applyDelete(t, e) {
335
+ if (!Object.hasOwn(t, e))
336
+ return !0;
337
+ if (!Reflect.deleteProperty(t, e))
338
+ return !1;
339
+ const i = this._ownAdmin(t)?.tracking;
340
+ return i !== void 0 && (this._trigger(i.valueDeps?.get(e)), this._trigger(i.hasDeps?.get(e)), this._trigger(i.iterateDep)), !0;
341
+ }
342
+ _has(t, e) {
343
+ return this._policy.assertRead?.(), this._trackHas(t, e), Reflect.has(t, e);
344
+ }
345
+ _ownKeys(t) {
346
+ return this._policy.assertRead?.(), this._trackIterate(t), Reflect.ownKeys(t);
347
+ }
348
+ _arrayMutator(t) {
349
+ const e = this._arrayMethods.get(t);
350
+ if (e !== void 0)
351
+ return e;
352
+ const r = (s) => this._write(s), n = V(this, t, function(...s) {
136
353
  return r(() => Reflect.apply(
137
- Array.prototype[e],
354
+ Array.prototype[t],
138
355
  this,
139
- n
356
+ s
140
357
  ));
141
- };
142
- return this._arrayMethods.set(e, i), i;
358
+ });
359
+ return this._arrayMethods.set(t, n), n;
360
+ }
361
+ /**
362
+ * Raw массива для специализированного мутатора: только сразу после чтения
363
+ * метода через этот Proxy, вне отслеживания и для обычного Array.prototype.
364
+ * Иначе мутатор идёт прежним путём через ловушки Proxy.
365
+ *
366
+ * @internal
367
+ */
368
+ _fastArrayTarget(t) {
369
+ const e = this._mutatorProxy, r = this._mutatorTarget;
370
+ if (this._mutatorProxy = void 0, this._mutatorTarget = void 0, r === void 0 || e !== t || Object.getPrototypeOf(r) !== Array.prototype)
371
+ return;
372
+ const i = this._bridge;
373
+ return i === void 0 || i.isTracking() ? void 0 : r;
374
+ }
375
+ /**
376
+ * Выполняет специализированный мутатор в границе записи без closure.
377
+ *
378
+ * @internal
379
+ */
380
+ _arrayWrite(t, e, r, i, n, s) {
381
+ const a = this._openWrite();
382
+ if (a === _)
383
+ return this._arrayOperation(t, e, r, i, n, s);
384
+ if (a === p)
385
+ return this._writeThroughPolicy(() => this._arrayOperation(t, e, r, i, n, s));
386
+ let c;
387
+ try {
388
+ c = this._arrayOperation(t, e, r, i, n, s);
389
+ } catch (h) {
390
+ throw this._failOpenWrite(h);
391
+ }
392
+ return this._closeWrite(), c;
393
+ }
394
+ // Операции повторяют шаги Array.prototype над raw теми же _applySet/_applyDelete,
395
+ // которые вызывали ловушки Proxy: уведомления и их порядок сохраняются.
396
+ _arrayOperation(t, e, r, i, n, s) {
397
+ switch (t) {
398
+ case E: {
399
+ const a = e.length;
400
+ return this._setArrayEntry(e, String(a), r), this._setArrayEntry(e, "length", a + 1), a + 1;
401
+ }
402
+ case T: {
403
+ const a = e.length;
404
+ if (a === 0) {
405
+ this._setArrayEntry(e, "length", 0);
406
+ return;
407
+ }
408
+ const c = String(a - 1), h = e[a - 1];
409
+ return this._deleteArrayEntry(e, c), this._setArrayEntry(e, "length", a - 1), this._viewOf(e, c, h);
410
+ }
411
+ case P: {
412
+ const a = e.length;
413
+ if (a === 0) {
414
+ this._setArrayEntry(e, "length", 0);
415
+ return;
416
+ }
417
+ const c = e[0];
418
+ for (let h = 1; h < a; h++)
419
+ this._moveArrayEntry(e, h, h - 1);
420
+ return this._deleteArrayEntry(e, String(a - 1)), this._setArrayEntry(e, "length", a - 1), this._viewOf(e, "0", c);
421
+ }
422
+ case S: {
423
+ const a = e.length;
424
+ for (let c = a; c > 0; c--)
425
+ this._moveArrayEntry(e, c - 1, c);
426
+ return this._setArrayEntry(e, "0", r), this._setArrayEntry(e, "length", a + 1), a + 1;
427
+ }
428
+ default:
429
+ return this._splice(e, r, i, n, s);
430
+ }
431
+ }
432
+ // Array.prototype.splice для числовых аргументов и не более одного элемента.
433
+ _splice(t, e, r, i, n) {
434
+ const s = t.length, a = Number.isNaN(e) ? 0 : Math.trunc(e), c = a < 0 ? Math.max(s + a, 0) : Math.min(a, s), h = n > 2 ? 1 : 0;
435
+ let l = 0;
436
+ if (n === 1)
437
+ l = s - c;
438
+ else if (n > 1) {
439
+ const d = Number.isNaN(r) ? 0 : Math.trunc(r);
440
+ l = Math.min(Math.max(d, 0), s - c);
441
+ }
442
+ const u = [];
443
+ for (let d = 0; d < l; d++) {
444
+ const b = c + d;
445
+ b in t && (u[d] = this._viewOf(t, String(b), t[b]));
446
+ }
447
+ if (u.length = l, h < l) {
448
+ for (let d = c; d < s - l; d++)
449
+ this._moveArrayEntry(t, d + l, d + h);
450
+ for (let d = s; d > s - l + h; d--)
451
+ this._deleteArrayEntry(t, String(d - 1));
452
+ } else if (h > l)
453
+ for (let d = s - l; d > c; d--)
454
+ this._moveArrayEntry(t, d + l - 1, d + h - 1);
455
+ return h === 1 && this._setArrayEntry(t, String(c), i), this._setArrayEntry(t, "length", s - l + h), u;
143
456
  }
144
- _trackValue(e, t) {
457
+ // HasProperty(from) ? Set(to, Get(from)) : DeletePropertyOrThrow(to).
458
+ _moveArrayEntry(t, e, r) {
459
+ e in t ? this._setArrayEntry(t, String(r), t[e]) : this._deleteArrayEntry(t, String(r));
460
+ }
461
+ _setArrayEntry(t, e, r) {
462
+ if (!this._applySet(t, e, r))
463
+ throw new TypeError(`[Raph] Cannot assign array property "${e}".`);
464
+ }
465
+ _deleteArrayEntry(t, e) {
466
+ if (!this._applyDelete(t, e))
467
+ throw new TypeError(`[Raph] Cannot delete array property "${e}".`);
468
+ }
469
+ // Значение элемента так же, как его вернула бы ловушка get (без отслеживания).
470
+ _viewOf(t, e, r) {
471
+ if (r === null || typeof r != "object")
472
+ return r;
473
+ const i = this._ownAdmin(t)?.extension;
474
+ if (i !== void 0) {
475
+ if (!Object.isExtensible(t) || this._lockedTargets?.has(t) === !0) {
476
+ const n = Object.getOwnPropertyDescriptor(t, e);
477
+ if (n?.configurable === !1 && n.writable === !1 && "value" in n)
478
+ return r;
479
+ }
480
+ return i.extension.readValue(r, i.deep);
481
+ }
482
+ return w(r) ? this.wrap(r) : r;
483
+ }
484
+ _trackValue(t, e) {
145
485
  const r = this._requireBridge();
146
486
  if (!r.isTracking())
147
487
  return;
148
- const i = this._ensureTracking(e), n = i.valueDeps ??= /* @__PURE__ */ new Map();
149
- let o = n.get(t);
150
- o === void 0 && (o = r.create(), n.set(t, o)), r.track(o);
488
+ const i = this._ensureTracking(t), n = i.valueDeps;
489
+ let s = n?.get(e);
490
+ if (s === void 0) {
491
+ s = r.create(), i.valueDeps = n === void 0 ? new R(e, s) : n.set(e, s);
492
+ const a = Array.isArray(t) ? y(e) : -1;
493
+ a >= 0 && (i.maxValueIndex = Math.max(i.maxValueIndex ?? -1, a));
494
+ }
495
+ r.track(s);
151
496
  }
152
- _trackHas(e, t) {
497
+ _trackHas(t, e) {
153
498
  const r = this._requireBridge();
154
499
  if (!r.isTracking())
155
500
  return;
156
- const i = this._ensureTracking(e), n = i.hasDeps ??= /* @__PURE__ */ new Map();
157
- let o = n.get(t);
158
- o === void 0 && (o = r.create(), n.set(t, o)), r.track(o);
501
+ const i = this._ensureTracking(t), n = i.hasDeps;
502
+ let s = n?.get(e);
503
+ if (s === void 0) {
504
+ s = r.create(), i.hasDeps = n === void 0 ? new R(e, s) : n.set(e, s);
505
+ const a = Array.isArray(t) ? y(e) : -1;
506
+ a >= 0 && (i.maxHasIndex = Math.max(i.maxHasIndex ?? -1, a));
507
+ }
508
+ r.track(s);
159
509
  }
160
- _trackIterate(e) {
161
- const t = this._requireBridge();
162
- if (!t.isTracking())
510
+ _trackIterate(t) {
511
+ const e = this._requireBridge();
512
+ if (!e.isTracking())
163
513
  return;
164
- const r = this._ensureTracking(e), i = r.iterateDep ??= t.create();
165
- t.track(i);
514
+ const r = this._ensureTracking(t), i = r.iterateDep ??= e.create();
515
+ e.track(i);
166
516
  }
167
- _ensureTracking(e) {
168
- let t = this._rawToTracking.get(e);
169
- return t === void 0 && (t = {}, this._rawToTracking.set(e, t)), t;
517
+ _ensureTracking(t) {
518
+ const e = this._claimAdmin(t);
519
+ return e.tracking ??= {};
170
520
  }
171
- _trigger(e) {
172
- e !== void 0 && this._requireBridge().trigger(e);
521
+ _trigger(t) {
522
+ t !== void 0 && this._requireBridge().trigger(t);
173
523
  }
174
- _triggerArrayShape(e, t, r, i, n) {
175
- if (!Array.isArray(e))
524
+ _triggerArrayShape(t, e, r, i, n) {
525
+ if (!Array.isArray(t))
176
526
  return;
177
- if (g(t) && Number(t) >= i) {
527
+ if (y(e) >= i) {
178
528
  this._trigger(n.valueDeps?.get("length"));
179
529
  return;
180
530
  }
181
- if (t !== "length" || Number(r) >= i)
531
+ if (e !== "length" || Number(r) >= i)
182
532
  return;
183
- const o = Number(r);
184
- for (const [c, a] of n.valueDeps?.entries() ?? [])
185
- g(c) && Number(c) >= o && this._trigger(a);
186
- for (const [c, a] of n.hasDeps?.entries() ?? [])
187
- g(c) && Number(c) >= o && this._trigger(a);
533
+ const s = Number(r);
534
+ if (n.maxValueIndex !== void 0 && n.maxValueIndex >= s)
535
+ for (const [a, c] of n.valueDeps.entries())
536
+ y(a) >= s && this._trigger(c);
537
+ if (n.maxHasIndex !== void 0 && n.maxHasIndex >= s)
538
+ for (const [a, c] of n.hasDeps.entries())
539
+ y(a) >= s && this._trigger(c);
188
540
  this._trigger(n.iterateDep);
189
541
  }
190
- _write(e) {
191
- if (this._policy.assertWrite?.(), this._writeDepth !== 0)
192
- return e();
193
- const t = () => {
542
+ _write(t) {
543
+ const e = this._openWrite();
544
+ if (e === _)
545
+ return t();
546
+ if (e === p)
547
+ return this._writeThroughPolicy(t);
548
+ let r;
549
+ try {
550
+ r = t();
551
+ } catch (i) {
552
+ throw this._failOpenWrite(i);
553
+ }
554
+ return this._closeWrite(), r;
555
+ }
556
+ /**
557
+ * Проверяет право записи и открывает внешнюю границу без closure операции.
558
+ * WRITE_OPENED обязывает вызывающего завершить её через _closeWrite() или
559
+ * _failOpenWrite(). Пока граница открыта, _writeDepth не равен нулю, поэтому
560
+ * вложенная запись получает WRITE_NESTED и сохранённые поля не перезаписывает.
561
+ */
562
+ _openWrite() {
563
+ this._policy.assertWrite?.();
564
+ const t = this._policy.writeBoundary;
565
+ if (this._writeDepth !== 0 || t?._isWriteBatchOpen())
566
+ return _;
567
+ if (t === void 0 && this._policy.runWrite !== void 0)
568
+ return p;
569
+ const e = this._requireBridge();
570
+ return t?._enterWrite(), ++this._writeDepth, e.startBatch(), this._openBridge = e, this._openBoundary = t, I;
571
+ }
572
+ _closeWrite() {
573
+ const t = this._openBridge, e = this._openBoundary;
574
+ this._openBridge = void 0, this._openBoundary = void 0;
575
+ let r, i = !1;
576
+ try {
577
+ t.endBatch();
578
+ } catch (n) {
579
+ i = !0, r = n;
580
+ }
581
+ if (--this._writeDepth, i)
582
+ throw e === void 0 ? r : e._failWrite(r);
583
+ e?._exitWrite();
584
+ }
585
+ /** Закрывает открытую границу после сбоя операции и возвращает ошибку для throw. */
586
+ _failOpenWrite(t) {
587
+ const e = this._openBridge, r = this._openBoundary;
588
+ this._openBridge = void 0, this._openBoundary = void 0;
589
+ let i = t;
590
+ try {
591
+ e.endBatch();
592
+ } catch (n) {
593
+ i = new AggregateError([t, n], "[Raph] Batch operation and effect flush failed.");
594
+ }
595
+ return --this._writeDepth, r === void 0 ? i : r._failWrite(i);
596
+ }
597
+ _writeThroughPolicy(t) {
598
+ const e = () => {
194
599
  ++this._writeDepth;
195
600
  try {
196
- return this._requireBridge().batch(e);
601
+ return this._requireBridge().batch(t);
197
602
  } finally {
198
603
  --this._writeDepth;
199
604
  }
200
605
  };
201
- return this._policy.runWrite === void 0 ? t() : this._policy.runWrite(t);
606
+ return this._policy.runWrite === void 0 ? e() : this._policy.runWrite(e);
202
607
  }
203
- _unwrap(e) {
204
- const t = w(e);
205
- if (t === void 0) {
206
- if (d(e)) {
207
- const r = v(e);
608
+ _unwrap(t) {
609
+ const e = x(t);
610
+ if (e === void 0) {
611
+ if (t !== null && typeof t == "object") {
612
+ const r = W(t);
208
613
  if (r !== void 0 && r !== this && !r.disposed)
209
614
  throw this._policy.throwForeign?.(r.owner), new TypeError("[Raph] Raw reactive object belongs to another reactivity engine.");
210
615
  }
211
- return e;
616
+ return t;
212
617
  }
213
- if (t.context !== this)
214
- throw this._policy.throwForeign?.(t.context.owner), new TypeError("[Raph] Reactive object belongs to another reactivity engine.");
215
- return t.raw;
618
+ if (e.context !== this)
619
+ throw this._policy.throwForeign?.(e.context.owner), new TypeError("[Raph] Reactive object belongs to another reactivity engine.");
620
+ return e.raw;
216
621
  }
217
622
  _requireBridge() {
218
- const e = this._bridge;
219
- return e === void 0 && p(), e;
623
+ const t = this._bridge;
624
+ return t === void 0 && v(), t;
220
625
  }
221
626
  }
222
- function A(s, e) {
223
- const t = new j(
224
- e(),
225
- _.get(s) ?? T
627
+ function k(o) {
628
+ const t = f.get(o);
629
+ if (t === void 0)
630
+ throw new Error("[Raph] Reactive object context must be initialized first.");
631
+ return t.support();
632
+ }
633
+ function J(o) {
634
+ return w(o);
635
+ }
636
+ function L(o, t) {
637
+ const e = new Y(
638
+ t(),
639
+ m.get(o) ?? B
226
640
  );
227
- return f.set(s, t), t;
641
+ return f.set(o, e), e;
228
642
  }
229
- function v(s) {
230
- const e = l.get(s), t = e?.deref();
231
- return e !== void 0 && t === void 0 && l.delete(s), t;
643
+ function W(o) {
644
+ const t = g.read(o)?.owner.deref();
645
+ if (t !== void 0 && !t.disposed || j === 0)
646
+ return t;
647
+ const e = A.get(o), r = e?.deref();
648
+ return e !== void 0 && r === void 0 && A.delete(o), r !== void 0 && !r.disposed ? r : t ?? r;
232
649
  }
233
- function w(s) {
234
- if (!(s === null || typeof s != "object"))
235
- return Reflect.get(s, R);
650
+ function x(o) {
651
+ if (!(o === null || typeof o != "object"))
652
+ return Reflect.get(o, D);
236
653
  }
237
- function d(s) {
238
- if (s === null || typeof s != "object")
654
+ function w(o) {
655
+ if (o === null || typeof o != "object")
239
656
  return !1;
240
- if (Array.isArray(s))
657
+ if (Array.isArray(o))
241
658
  return !0;
242
- const e = Object.getPrototypeOf(s);
243
- return e === Object.prototype || e === null;
659
+ const t = Object.getPrototypeOf(o);
660
+ return t === Object.prototype || t === null;
244
661
  }
245
- function D(s) {
246
- if (!d(s))
662
+ function M(o) {
663
+ if (!w(o))
247
664
  throw new TypeError("[Raph] reactive() accepts only plain objects and arrays.");
248
665
  }
249
- function g(s) {
250
- if (typeof s != "string" || s === "")
251
- return !1;
252
- const e = Number(s);
253
- return Number.isInteger(e) && e >= 0 && e < 4294967295 && String(e) === s;
666
+ function y(o) {
667
+ if (typeof o != "string")
668
+ return -1;
669
+ const t = o.length;
670
+ if (t === 0 || t > 10)
671
+ return -1;
672
+ const e = o.charCodeAt(0) - 48;
673
+ if (e < 0 || e > 9)
674
+ return -1;
675
+ if (e === 0)
676
+ return t === 1 ? 0 : -1;
677
+ let r = e;
678
+ for (let i = 1; i < t; i++) {
679
+ const n = o.charCodeAt(i) - 48;
680
+ if (n < 0 || n > 9)
681
+ return -1;
682
+ r = r * 10 + n;
683
+ }
684
+ return r < 4294967295 ? r : -1;
254
685
  }
255
- function M(s, e) {
256
- return s === e ? !0 : s === void 0 || e === void 0 ? !1 : s.configurable === e.configurable && s.enumerable === e.enumerable && s.get === e.get && s.set === e.set && s.value === e.value && s.writable === e.writable;
686
+ function K(o, t) {
687
+ return o === t ? !0 : o === void 0 || t === void 0 ? !1 : o.configurable === t.configurable && o.enumerable === t.enumerable && o.get === t.get && o.set === t.set && o.value === t.value && o.writable === t.writable;
257
688
  }
258
- function p() {
689
+ function v() {
259
690
  throw new Error("[Raph] Reactive object owner is disposed.");
260
691
  }
261
692
  export {
262
- P as configureReactiveObjectPolicy,
263
- W as disposeReactiveObjectContext,
264
- m as reactiveObject
693
+ D as REACTIVE_OBJECT_IDENTITY,
694
+ p as WRITE_CALLBACK,
695
+ _ as WRITE_NESTED,
696
+ I as WRITE_OPENED,
697
+ U as configureReactiveObjectPolicy,
698
+ z as disposeReactiveObjectContext,
699
+ k as getReactiveObjectSupport,
700
+ J as isPlainReactiveValue,
701
+ $ as reactiveObject
265
702
  };