automatick 0.0.1 → 0.0.3
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/README.md +2 -0
- package/dist/{chunk-YNLOTPDY.js → chunk-A375T3UD.js} +39 -3
- package/dist/chunk-IKR53C2U.js +12 -0
- package/dist/chunk-LMHH7YPE.js +89 -0
- package/dist/chunk-VPS3ZXWI.js +132 -0
- package/dist/engine.cjs +42 -3
- package/dist/engine.d.cts +42 -18
- package/dist/engine.d.ts +42 -18
- package/dist/engine.js +2 -1
- package/dist/react/EngineContext.d.cts +4 -3
- package/dist/react/EngineContext.d.ts +4 -3
- package/dist/react/Simulation.cjs +341 -102
- package/dist/react/Simulation.d.cts +36 -16
- package/dist/react/Simulation.d.ts +36 -16
- package/dist/react/Simulation.js +93 -100
- package/dist/react/SimulationContext.d.cts +1 -2
- package/dist/react/SimulationContext.d.ts +1 -2
- package/dist/react/hooks.d.cts +1 -1
- package/dist/react/hooks.d.ts +1 -1
- package/dist/react/useSimulationCanvas.cjs +2 -10
- package/dist/react/useSimulationCanvas.d.cts +4 -7
- package/dist/react/useSimulationCanvas.d.ts +4 -7
- package/dist/react/useSimulationCanvas.js +2 -10
- package/dist/sim.cjs +7 -2
- package/dist/sim.d.cts +34 -14
- package/dist/sim.d.ts +34 -14
- package/dist/sim.js +6 -5
- package/dist/standalone/engine.js +242 -0
- package/dist/standalone/sim.js +11 -0
- package/dist/state.cjs +18 -0
- package/dist/state.d.cts +16 -0
- package/dist/state.d.ts +16 -0
- package/dist/state.js +0 -0
- package/dist/worker/createSimWorker.cjs +12 -3
- package/dist/worker/createSimWorker.d.cts +1 -2
- package/dist/worker/createSimWorker.d.ts +1 -2
- package/dist/worker/createSimWorker.js +3 -119
- package/dist/worker/protocol.d.cts +5 -5
- package/dist/worker/protocol.d.ts +5 -5
- package/dist/worker/workerRunner.cjs +21 -6
- package/dist/worker/workerRunner.d.cts +11 -3
- package/dist/worker/workerRunner.d.ts +11 -3
- package/dist/worker/workerRunner.js +3 -70
- package/package.json +2 -2
|
@@ -1,73 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
function serializeMainMessage(msg) {
|
|
6
|
-
return msg;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// src/worker/workerRunner.ts
|
|
10
|
-
function createWorkerRunner(worker, config) {
|
|
11
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
12
|
-
let currentSnapshot = {
|
|
13
|
-
data: void 0,
|
|
14
|
-
params: config.initialParams,
|
|
15
|
-
tick: 0,
|
|
16
|
-
status: "idle",
|
|
17
|
-
stepDurationMs: 0
|
|
18
|
-
};
|
|
19
|
-
let errorMessage = null;
|
|
20
|
-
function send(msg) {
|
|
21
|
-
worker.postMessage(serializeMainMessage(msg));
|
|
22
|
-
}
|
|
23
|
-
function emit() {
|
|
24
|
-
for (const l of listeners) {
|
|
25
|
-
l(currentSnapshot);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
worker.onmessage = (event) => {
|
|
29
|
-
const msg = deserializeWorkerMessage(event.data);
|
|
30
|
-
switch (msg.kind) {
|
|
31
|
-
case "snapshot":
|
|
32
|
-
currentSnapshot = msg.snapshot;
|
|
33
|
-
emit();
|
|
34
|
-
break;
|
|
35
|
-
case "error":
|
|
36
|
-
errorMessage = msg.error.message;
|
|
37
|
-
currentSnapshot = { ...currentSnapshot, status: "stopped" };
|
|
38
|
-
emit();
|
|
39
|
-
break;
|
|
40
|
-
case "ready":
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
worker.onerror = (event) => {
|
|
45
|
-
errorMessage = event.message ?? "Unknown worker error";
|
|
46
|
-
currentSnapshot = { ...currentSnapshot, status: "stopped" };
|
|
47
|
-
emit();
|
|
48
|
-
};
|
|
49
|
-
return {
|
|
50
|
-
getSnapshot: () => currentSnapshot,
|
|
51
|
-
subscribe(listener) {
|
|
52
|
-
listeners.add(listener);
|
|
53
|
-
return () => {
|
|
54
|
-
listeners.delete(listener);
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
play: () => send({ kind: "play" }),
|
|
58
|
-
pause: () => send({ kind: "pause" }),
|
|
59
|
-
stop: () => send({ kind: "stop" }),
|
|
60
|
-
seek: (tick) => send({ kind: "seek", tick }),
|
|
61
|
-
advance: (count = 1) => send({ kind: "advance", count }),
|
|
62
|
-
setParams: (patch) => send({ kind: "setParams", patch }),
|
|
63
|
-
resetWith: (patch) => send({ kind: "resetWith", patch }),
|
|
64
|
-
destroy() {
|
|
65
|
-
listeners.clear();
|
|
66
|
-
send({ kind: "destroy" });
|
|
67
|
-
worker.terminate();
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
createWorkerRunner
|
|
3
|
+
} from "../chunk-LMHH7YPE.js";
|
|
71
4
|
export {
|
|
72
5
|
createWorkerRunner
|
|
73
6
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "automatick",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "State-machine engine for tick-based simulations in React",
|
|
5
5
|
"author": "jckr",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
|
-
"build": "tsup src/engine.ts src/sim.ts src/worker/workerRunner.ts src/worker/createSimWorker.ts src/worker/protocol.ts src/react/Simulation.tsx src/react/hooks.ts src/react/useSimulationCanvas.ts src/react/PerformanceOverlay.tsx src/react/SimulationContext.tsx src/react/EngineContext.tsx src/react/SimulationControls.tsx src/react/controlPrimitives.tsx src/react/stableCallback.ts --format esm,cjs --dts --clean --external react --external react-dom --external react/jsx-runtime",
|
|
32
|
+
"build": "tsup src/engine.ts src/sim.ts src/state.ts src/worker/workerRunner.ts src/worker/createSimWorker.ts src/worker/protocol.ts src/react/Simulation.tsx src/react/hooks.ts src/react/useSimulationCanvas.ts src/react/PerformanceOverlay.tsx src/react/SimulationContext.tsx src/react/EngineContext.tsx src/react/SimulationControls.tsx src/react/controlPrimitives.tsx src/react/stableCallback.ts --format esm,cjs --dts --clean --external react --external react-dom --external react/jsx-runtime && tsup src/engine.ts src/sim.ts --format esm --no-splitting --no-dts --outDir dist/standalone",
|
|
33
33
|
"test": "vitest run"
|
|
34
34
|
},
|
|
35
35
|
"exports": {
|