automatick 0.0.1
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 +20 -0
- package/README.md +106 -0
- package/dist/chunk-66FUVAAG.js +7 -0
- package/dist/chunk-AIKB2FNR.js +17 -0
- package/dist/chunk-HTH6FQ7C.js +192 -0
- package/dist/chunk-OA6FGXTP.js +9 -0
- package/dist/chunk-SK5SHIWY.js +13 -0
- package/dist/chunk-YNLOTPDY.js +206 -0
- package/dist/engine.cjs +231 -0
- package/dist/engine.d.cts +72 -0
- package/dist/engine.d.ts +72 -0
- package/dist/engine.js +8 -0
- package/dist/react/EngineContext.cjs +43 -0
- package/dist/react/EngineContext.d.cts +18 -0
- package/dist/react/EngineContext.d.ts +18 -0
- package/dist/react/EngineContext.js +6 -0
- package/dist/react/PerformanceOverlay.cjs +341 -0
- package/dist/react/PerformanceOverlay.d.cts +9 -0
- package/dist/react/PerformanceOverlay.d.ts +9 -0
- package/dist/react/PerformanceOverlay.js +290 -0
- package/dist/react/Simulation.cjs +481 -0
- package/dist/react/Simulation.d.cts +31 -0
- package/dist/react/Simulation.d.ts +31 -0
- package/dist/react/Simulation.js +235 -0
- package/dist/react/SimulationContext.cjs +41 -0
- package/dist/react/SimulationContext.d.cts +25 -0
- package/dist/react/SimulationContext.d.ts +25 -0
- package/dist/react/SimulationContext.js +6 -0
- package/dist/react/SimulationControls.cjs +298 -0
- package/dist/react/SimulationControls.d.cts +33 -0
- package/dist/react/SimulationControls.d.ts +33 -0
- package/dist/react/SimulationControls.js +80 -0
- package/dist/react/controlPrimitives.cjs +247 -0
- package/dist/react/controlPrimitives.d.cts +45 -0
- package/dist/react/controlPrimitives.d.ts +45 -0
- package/dist/react/controlPrimitives.js +22 -0
- package/dist/react/hooks.cjs +53 -0
- package/dist/react/hooks.d.cts +26 -0
- package/dist/react/hooks.d.ts +26 -0
- package/dist/react/hooks.js +7 -0
- package/dist/react/stableCallback.cjs +47 -0
- package/dist/react/stableCallback.d.cts +3 -0
- package/dist/react/stableCallback.d.ts +3 -0
- package/dist/react/stableCallback.js +6 -0
- package/dist/react/useSimulationCanvas.cjs +92 -0
- package/dist/react/useSimulationCanvas.d.cts +38 -0
- package/dist/react/useSimulationCanvas.d.ts +38 -0
- package/dist/react/useSimulationCanvas.js +53 -0
- package/dist/sim.cjs +32 -0
- package/dist/sim.d.cts +40 -0
- package/dist/sim.d.ts +40 -0
- package/dist/sim.js +7 -0
- package/dist/worker/createSimWorker.cjs +147 -0
- package/dist/worker/createSimWorker.d.cts +19 -0
- package/dist/worker/createSimWorker.d.ts +19 -0
- package/dist/worker/createSimWorker.js +122 -0
- package/dist/worker/protocol.cjs +18 -0
- package/dist/worker/protocol.d.cts +59 -0
- package/dist/worker/protocol.d.ts +59 -0
- package/dist/worker/protocol.js +0 -0
- package/dist/worker/workerRunner.cjs +100 -0
- package/dist/worker/workerRunner.d.cts +30 -0
- package/dist/worker/workerRunner.d.ts +30 -0
- package/dist/worker/workerRunner.js +73 -0
- package/package.json +102 -0
package/dist/engine.cjs
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/engine.ts
|
|
21
|
+
var engine_exports = {};
|
|
22
|
+
__export(engine_exports, {
|
|
23
|
+
SimulationEngine: () => SimulationEngine,
|
|
24
|
+
createEngine: () => createEngine
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(engine_exports);
|
|
27
|
+
var PERF_BUFFER_SIZE = 120;
|
|
28
|
+
var SimulationEngine = class {
|
|
29
|
+
data;
|
|
30
|
+
params;
|
|
31
|
+
tick = 0;
|
|
32
|
+
status = "idle";
|
|
33
|
+
lastUpdateMs = null;
|
|
34
|
+
lastStepMs = 0;
|
|
35
|
+
initFn;
|
|
36
|
+
stepFn;
|
|
37
|
+
shouldStopFn;
|
|
38
|
+
maxTime;
|
|
39
|
+
delayMs;
|
|
40
|
+
ticksPerFrame;
|
|
41
|
+
listeners = /* @__PURE__ */ new Set();
|
|
42
|
+
historyListeners = /* @__PURE__ */ new Set();
|
|
43
|
+
perfBuffer = [];
|
|
44
|
+
constructor(config) {
|
|
45
|
+
this.initFn = config.init;
|
|
46
|
+
this.stepFn = config.step;
|
|
47
|
+
this.shouldStopFn = config.shouldStop;
|
|
48
|
+
this.maxTime = config.maxTime;
|
|
49
|
+
this.delayMs = config.delayMs ?? 0;
|
|
50
|
+
this.ticksPerFrame = config.ticksPerFrame ?? 1;
|
|
51
|
+
this.params = { ...config.initialParams };
|
|
52
|
+
this.data = this.initFn(this.params);
|
|
53
|
+
}
|
|
54
|
+
getSnapshot() {
|
|
55
|
+
return {
|
|
56
|
+
data: this.data,
|
|
57
|
+
params: this.params,
|
|
58
|
+
tick: this.tick,
|
|
59
|
+
status: this.status,
|
|
60
|
+
stepDurationMs: this.lastStepMs
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
getStatus() {
|
|
64
|
+
return this.status;
|
|
65
|
+
}
|
|
66
|
+
getPerformance() {
|
|
67
|
+
return this.perfBuffer;
|
|
68
|
+
}
|
|
69
|
+
setDelayMs(ms) {
|
|
70
|
+
this.delayMs = ms;
|
|
71
|
+
}
|
|
72
|
+
setTicksPerFrame(n) {
|
|
73
|
+
this.ticksPerFrame = n;
|
|
74
|
+
}
|
|
75
|
+
recordDrawTime(tick, ms) {
|
|
76
|
+
for (let i = this.perfBuffer.length - 1; i >= 0; i--) {
|
|
77
|
+
if (this.perfBuffer[i].tick === tick) {
|
|
78
|
+
this.perfBuffer[i].drawMs = ms;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
subscribe(listener) {
|
|
84
|
+
this.listeners.add(listener);
|
|
85
|
+
return () => {
|
|
86
|
+
this.listeners.delete(listener);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
subscribeHistory(listener) {
|
|
90
|
+
this.historyListeners.add(listener);
|
|
91
|
+
return () => {
|
|
92
|
+
this.historyListeners.delete(listener);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
play() {
|
|
96
|
+
if (this.status === "stopped") return;
|
|
97
|
+
if (this.status === "playing") return;
|
|
98
|
+
this.status = "playing";
|
|
99
|
+
this.lastUpdateMs = null;
|
|
100
|
+
this.emit();
|
|
101
|
+
}
|
|
102
|
+
pause() {
|
|
103
|
+
if (this.status !== "playing") return;
|
|
104
|
+
this.status = "paused";
|
|
105
|
+
this.emit();
|
|
106
|
+
}
|
|
107
|
+
stop() {
|
|
108
|
+
if (this.status === "idle" || this.status === "stopped") return;
|
|
109
|
+
this.status = "stopped";
|
|
110
|
+
this.emit();
|
|
111
|
+
}
|
|
112
|
+
seek(targetTick) {
|
|
113
|
+
if (this.status === "stopped") return;
|
|
114
|
+
if (targetTick <= this.tick) {
|
|
115
|
+
if (this.status !== "paused") {
|
|
116
|
+
this.status = "paused";
|
|
117
|
+
this.emit();
|
|
118
|
+
}
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
this.status = "paused";
|
|
122
|
+
this.lastUpdateMs = null;
|
|
123
|
+
this.advanceTicks(targetTick - this.tick);
|
|
124
|
+
if (this.status === "paused") {
|
|
125
|
+
this.emit();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
advance(count = 1) {
|
|
129
|
+
if (this.status === "stopped") return;
|
|
130
|
+
if (this.status === "playing" || this.status === "idle") {
|
|
131
|
+
this.status = "paused";
|
|
132
|
+
}
|
|
133
|
+
this.lastUpdateMs = null;
|
|
134
|
+
this.advanceTicks(count);
|
|
135
|
+
if (this.status === "paused") {
|
|
136
|
+
this.emit();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
setParams(patch) {
|
|
140
|
+
this.params = { ...this.params, ...patch };
|
|
141
|
+
this.emit();
|
|
142
|
+
}
|
|
143
|
+
resetWith(patch) {
|
|
144
|
+
if (patch) {
|
|
145
|
+
this.params = { ...this.params, ...patch };
|
|
146
|
+
}
|
|
147
|
+
this.data = this.initFn(this.params);
|
|
148
|
+
this.tick = 0;
|
|
149
|
+
this.status = "idle";
|
|
150
|
+
this.lastUpdateMs = null;
|
|
151
|
+
this.lastStepMs = 0;
|
|
152
|
+
this.perfBuffer.length = 0;
|
|
153
|
+
this.emit();
|
|
154
|
+
}
|
|
155
|
+
handleAnimationFrame(nowMs) {
|
|
156
|
+
if (this.status !== "playing") return;
|
|
157
|
+
if (this.lastUpdateMs === null) {
|
|
158
|
+
this.lastUpdateMs = nowMs;
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (this.delayMs > 0 && nowMs - this.lastUpdateMs < this.delayMs) return;
|
|
162
|
+
this.lastUpdateMs = nowMs;
|
|
163
|
+
this.advanceTicks(this.ticksPerFrame);
|
|
164
|
+
if (this.status === "playing") {
|
|
165
|
+
this.emit();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
destroy() {
|
|
169
|
+
this.listeners.clear();
|
|
170
|
+
this.historyListeners.clear();
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Run step up to `count` ticks. Returns true if all ticks completed
|
|
174
|
+
* without termination, false if stopped early.
|
|
175
|
+
*/
|
|
176
|
+
advanceTicks(count) {
|
|
177
|
+
for (let i = 0; i < count; i++) {
|
|
178
|
+
if (this.maxTime !== void 0 && this.tick >= this.maxTime) {
|
|
179
|
+
this.status = "stopped";
|
|
180
|
+
this.emit();
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
this.tick += 1;
|
|
184
|
+
const t0 = performance.now();
|
|
185
|
+
this.data = this.stepFn({
|
|
186
|
+
data: this.data,
|
|
187
|
+
params: this.params,
|
|
188
|
+
tick: this.tick
|
|
189
|
+
});
|
|
190
|
+
const t1 = performance.now();
|
|
191
|
+
this.lastStepMs = t1 - t0;
|
|
192
|
+
if (this.perfBuffer.length >= PERF_BUFFER_SIZE) {
|
|
193
|
+
this.perfBuffer.shift();
|
|
194
|
+
}
|
|
195
|
+
this.perfBuffer.push({ tick: this.tick, stepMs: this.lastStepMs });
|
|
196
|
+
this.emitHistory();
|
|
197
|
+
if (this.shouldStopFn?.(this.data, this.params)) {
|
|
198
|
+
this.status = "stopped";
|
|
199
|
+
this.emit();
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
if (this.maxTime !== void 0 && this.tick >= this.maxTime) {
|
|
203
|
+
this.status = "stopped";
|
|
204
|
+
this.emit();
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
emit() {
|
|
211
|
+
const snap = this.getSnapshot();
|
|
212
|
+
for (const l of this.listeners) {
|
|
213
|
+
l(snap);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
emitHistory() {
|
|
217
|
+
if (this.historyListeners.size === 0) return;
|
|
218
|
+
const entry = { tick: this.tick, data: this.data };
|
|
219
|
+
for (const l of this.historyListeners) {
|
|
220
|
+
l(entry);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
function createEngine(config) {
|
|
225
|
+
return new SimulationEngine(config);
|
|
226
|
+
}
|
|
227
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
228
|
+
0 && (module.exports = {
|
|
229
|
+
SimulationEngine,
|
|
230
|
+
createEngine
|
|
231
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { StepArgs } from './sim.cjs';
|
|
2
|
+
|
|
3
|
+
type SimulationStatus = 'idle' | 'playing' | 'paused' | 'stopped';
|
|
4
|
+
type TickPerformance = {
|
|
5
|
+
tick: number;
|
|
6
|
+
stepMs: number;
|
|
7
|
+
drawMs?: number;
|
|
8
|
+
};
|
|
9
|
+
type EngineConfig<Data, Params> = {
|
|
10
|
+
init: (params: Params) => Data;
|
|
11
|
+
step: (args: StepArgs<Data, Params>) => Data;
|
|
12
|
+
shouldStop?: (data: Data, params: Params) => boolean;
|
|
13
|
+
initialParams: Params;
|
|
14
|
+
maxTime?: number;
|
|
15
|
+
delayMs?: number;
|
|
16
|
+
ticksPerFrame?: number;
|
|
17
|
+
};
|
|
18
|
+
type EngineSnapshot<Data, Params> = {
|
|
19
|
+
data: Data;
|
|
20
|
+
params: Params;
|
|
21
|
+
tick: number;
|
|
22
|
+
status: SimulationStatus;
|
|
23
|
+
stepDurationMs: number;
|
|
24
|
+
};
|
|
25
|
+
declare class SimulationEngine<Data, Params> {
|
|
26
|
+
private data;
|
|
27
|
+
private params;
|
|
28
|
+
private tick;
|
|
29
|
+
private status;
|
|
30
|
+
private lastUpdateMs;
|
|
31
|
+
private lastStepMs;
|
|
32
|
+
private readonly initFn;
|
|
33
|
+
private readonly stepFn;
|
|
34
|
+
private readonly shouldStopFn?;
|
|
35
|
+
private readonly maxTime?;
|
|
36
|
+
private delayMs;
|
|
37
|
+
private ticksPerFrame;
|
|
38
|
+
private readonly listeners;
|
|
39
|
+
private readonly historyListeners;
|
|
40
|
+
private readonly perfBuffer;
|
|
41
|
+
constructor(config: EngineConfig<Data, Params>);
|
|
42
|
+
getSnapshot(): EngineSnapshot<Data, Params>;
|
|
43
|
+
getStatus(): SimulationStatus;
|
|
44
|
+
getPerformance(): readonly TickPerformance[];
|
|
45
|
+
setDelayMs(ms: number): void;
|
|
46
|
+
setTicksPerFrame(n: number): void;
|
|
47
|
+
recordDrawTime(tick: number, ms: number): void;
|
|
48
|
+
subscribe(listener: (snapshot: EngineSnapshot<Data, Params>) => void): () => void;
|
|
49
|
+
subscribeHistory(listener: (entry: {
|
|
50
|
+
tick: number;
|
|
51
|
+
data: Data;
|
|
52
|
+
}) => void): () => void;
|
|
53
|
+
play(): void;
|
|
54
|
+
pause(): void;
|
|
55
|
+
stop(): void;
|
|
56
|
+
seek(targetTick: number): void;
|
|
57
|
+
advance(count?: number): void;
|
|
58
|
+
setParams(patch: Partial<Params>): void;
|
|
59
|
+
resetWith(patch?: Partial<Params>): void;
|
|
60
|
+
handleAnimationFrame(nowMs: number): void;
|
|
61
|
+
destroy(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Run step up to `count` ticks. Returns true if all ticks completed
|
|
64
|
+
* without termination, false if stopped early.
|
|
65
|
+
*/
|
|
66
|
+
private advanceTicks;
|
|
67
|
+
private emit;
|
|
68
|
+
private emitHistory;
|
|
69
|
+
}
|
|
70
|
+
declare function createEngine<Data, Params>(config: EngineConfig<Data, Params>): SimulationEngine<Data, Params>;
|
|
71
|
+
|
|
72
|
+
export { type EngineConfig, type EngineSnapshot, SimulationEngine, type SimulationStatus, type TickPerformance, createEngine };
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { StepArgs } from './sim.js';
|
|
2
|
+
|
|
3
|
+
type SimulationStatus = 'idle' | 'playing' | 'paused' | 'stopped';
|
|
4
|
+
type TickPerformance = {
|
|
5
|
+
tick: number;
|
|
6
|
+
stepMs: number;
|
|
7
|
+
drawMs?: number;
|
|
8
|
+
};
|
|
9
|
+
type EngineConfig<Data, Params> = {
|
|
10
|
+
init: (params: Params) => Data;
|
|
11
|
+
step: (args: StepArgs<Data, Params>) => Data;
|
|
12
|
+
shouldStop?: (data: Data, params: Params) => boolean;
|
|
13
|
+
initialParams: Params;
|
|
14
|
+
maxTime?: number;
|
|
15
|
+
delayMs?: number;
|
|
16
|
+
ticksPerFrame?: number;
|
|
17
|
+
};
|
|
18
|
+
type EngineSnapshot<Data, Params> = {
|
|
19
|
+
data: Data;
|
|
20
|
+
params: Params;
|
|
21
|
+
tick: number;
|
|
22
|
+
status: SimulationStatus;
|
|
23
|
+
stepDurationMs: number;
|
|
24
|
+
};
|
|
25
|
+
declare class SimulationEngine<Data, Params> {
|
|
26
|
+
private data;
|
|
27
|
+
private params;
|
|
28
|
+
private tick;
|
|
29
|
+
private status;
|
|
30
|
+
private lastUpdateMs;
|
|
31
|
+
private lastStepMs;
|
|
32
|
+
private readonly initFn;
|
|
33
|
+
private readonly stepFn;
|
|
34
|
+
private readonly shouldStopFn?;
|
|
35
|
+
private readonly maxTime?;
|
|
36
|
+
private delayMs;
|
|
37
|
+
private ticksPerFrame;
|
|
38
|
+
private readonly listeners;
|
|
39
|
+
private readonly historyListeners;
|
|
40
|
+
private readonly perfBuffer;
|
|
41
|
+
constructor(config: EngineConfig<Data, Params>);
|
|
42
|
+
getSnapshot(): EngineSnapshot<Data, Params>;
|
|
43
|
+
getStatus(): SimulationStatus;
|
|
44
|
+
getPerformance(): readonly TickPerformance[];
|
|
45
|
+
setDelayMs(ms: number): void;
|
|
46
|
+
setTicksPerFrame(n: number): void;
|
|
47
|
+
recordDrawTime(tick: number, ms: number): void;
|
|
48
|
+
subscribe(listener: (snapshot: EngineSnapshot<Data, Params>) => void): () => void;
|
|
49
|
+
subscribeHistory(listener: (entry: {
|
|
50
|
+
tick: number;
|
|
51
|
+
data: Data;
|
|
52
|
+
}) => void): () => void;
|
|
53
|
+
play(): void;
|
|
54
|
+
pause(): void;
|
|
55
|
+
stop(): void;
|
|
56
|
+
seek(targetTick: number): void;
|
|
57
|
+
advance(count?: number): void;
|
|
58
|
+
setParams(patch: Partial<Params>): void;
|
|
59
|
+
resetWith(patch?: Partial<Params>): void;
|
|
60
|
+
handleAnimationFrame(nowMs: number): void;
|
|
61
|
+
destroy(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Run step up to `count` ticks. Returns true if all ticks completed
|
|
64
|
+
* without termination, false if stopped early.
|
|
65
|
+
*/
|
|
66
|
+
private advanceTicks;
|
|
67
|
+
private emit;
|
|
68
|
+
private emitHistory;
|
|
69
|
+
}
|
|
70
|
+
declare function createEngine<Data, Params>(config: EngineConfig<Data, Params>): SimulationEngine<Data, Params>;
|
|
71
|
+
|
|
72
|
+
export { type EngineConfig, type EngineSnapshot, SimulationEngine, type SimulationStatus, type TickPerformance, createEngine };
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/react/EngineContext.tsx
|
|
31
|
+
var EngineContext_exports = {};
|
|
32
|
+
__export(EngineContext_exports, {
|
|
33
|
+
EngineContext: () => EngineContext
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(EngineContext_exports);
|
|
36
|
+
var import_react = __toESM(require("react"), 1);
|
|
37
|
+
var EngineContext = import_react.default.createContext(
|
|
38
|
+
null
|
|
39
|
+
);
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
EngineContext
|
|
43
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { EngineSnapshot, TickPerformance } from '../engine.cjs';
|
|
3
|
+
import '../sim.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Internal context that exposes the engine's subscribe function directly.
|
|
7
|
+
* Used by useSimulationCanvas to bypass React's render cycle for canvas updates,
|
|
8
|
+
* and to record draw timing back to the engine's performance buffer.
|
|
9
|
+
*/
|
|
10
|
+
type EngineContextValue = {
|
|
11
|
+
subscribe: (listener: (snapshot: EngineSnapshot<unknown, unknown>) => void) => () => void;
|
|
12
|
+
getSnapshot: () => EngineSnapshot<unknown, unknown>;
|
|
13
|
+
recordDrawTime: (tick: number, ms: number) => void;
|
|
14
|
+
getPerformance: () => readonly TickPerformance[];
|
|
15
|
+
};
|
|
16
|
+
declare const EngineContext: React.Context<EngineContextValue | null>;
|
|
17
|
+
|
|
18
|
+
export { EngineContext, type EngineContextValue };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { EngineSnapshot, TickPerformance } from '../engine.js';
|
|
3
|
+
import '../sim.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Internal context that exposes the engine's subscribe function directly.
|
|
7
|
+
* Used by useSimulationCanvas to bypass React's render cycle for canvas updates,
|
|
8
|
+
* and to record draw timing back to the engine's performance buffer.
|
|
9
|
+
*/
|
|
10
|
+
type EngineContextValue = {
|
|
11
|
+
subscribe: (listener: (snapshot: EngineSnapshot<unknown, unknown>) => void) => () => void;
|
|
12
|
+
getSnapshot: () => EngineSnapshot<unknown, unknown>;
|
|
13
|
+
recordDrawTime: (tick: number, ms: number) => void;
|
|
14
|
+
getPerformance: () => readonly TickPerformance[];
|
|
15
|
+
};
|
|
16
|
+
declare const EngineContext: React.Context<EngineContextValue | null>;
|
|
17
|
+
|
|
18
|
+
export { EngineContext, type EngineContextValue };
|