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