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
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ParamRangeField,
|
|
3
|
+
ParamToggleField,
|
|
4
|
+
PlayPauseButton,
|
|
5
|
+
ResetButton,
|
|
6
|
+
StepButton,
|
|
7
|
+
StopButton,
|
|
8
|
+
TickReadout,
|
|
9
|
+
TickSeekSlider
|
|
10
|
+
} from "../chunk-HTH6FQ7C.js";
|
|
11
|
+
import "../chunk-AIKB2FNR.js";
|
|
12
|
+
import "../chunk-66FUVAAG.js";
|
|
13
|
+
|
|
14
|
+
// src/react/SimulationControls.tsx
|
|
15
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
16
|
+
function asArray(maybeArray) {
|
|
17
|
+
if (!maybeArray) return [];
|
|
18
|
+
return Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
19
|
+
}
|
|
20
|
+
var panelStyle = {
|
|
21
|
+
display: "flex",
|
|
22
|
+
flexDirection: "column",
|
|
23
|
+
gap: 10,
|
|
24
|
+
padding: 12,
|
|
25
|
+
border: "1px solid rgba(0,0,0,0.15)",
|
|
26
|
+
borderRadius: 8
|
|
27
|
+
};
|
|
28
|
+
function StandardControls(props) {
|
|
29
|
+
const controls = asArray(props.controls);
|
|
30
|
+
const maxTime = props.maxTime;
|
|
31
|
+
const canSeek = maxTime !== void 0 && Number.isFinite(maxTime);
|
|
32
|
+
return /* @__PURE__ */ jsxs("div", { style: panelStyle, children: [
|
|
33
|
+
/* @__PURE__ */ jsxs(
|
|
34
|
+
"div",
|
|
35
|
+
{
|
|
36
|
+
style: {
|
|
37
|
+
display: "flex",
|
|
38
|
+
gap: 8,
|
|
39
|
+
alignItems: "center",
|
|
40
|
+
flexWrap: "wrap"
|
|
41
|
+
},
|
|
42
|
+
children: [
|
|
43
|
+
/* @__PURE__ */ jsx(PlayPauseButton, {}),
|
|
44
|
+
props.showStopButton ? /* @__PURE__ */ jsx(StopButton, {}) : null,
|
|
45
|
+
props.showStepButton ? /* @__PURE__ */ jsx(StepButton, {}) : null,
|
|
46
|
+
props.showResetButton !== false ? /* @__PURE__ */ jsx(ResetButton, {}) : null,
|
|
47
|
+
/* @__PURE__ */ jsx(TickReadout, {})
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
),
|
|
51
|
+
canSeek ? /* @__PURE__ */ jsx(TickSeekSlider, { min: props.minTime, max: maxTime }) : null,
|
|
52
|
+
controls.length ? /* @__PURE__ */ jsx("div", { style: { display: "flex", flexDirection: "column", gap: 10 }, children: controls.map((c) => {
|
|
53
|
+
const key = `${c.type ?? "range"}-${c.param}`;
|
|
54
|
+
if (c.type === "toggle") {
|
|
55
|
+
return /* @__PURE__ */ jsx(
|
|
56
|
+
ParamToggleField,
|
|
57
|
+
{
|
|
58
|
+
param: c.param,
|
|
59
|
+
label: c.label
|
|
60
|
+
},
|
|
61
|
+
key
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return /* @__PURE__ */ jsx(
|
|
65
|
+
ParamRangeField,
|
|
66
|
+
{
|
|
67
|
+
param: c.param,
|
|
68
|
+
label: c.label,
|
|
69
|
+
min: c.min,
|
|
70
|
+
max: c.max,
|
|
71
|
+
step: c.step
|
|
72
|
+
},
|
|
73
|
+
key
|
|
74
|
+
);
|
|
75
|
+
}) }) : null
|
|
76
|
+
] });
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
StandardControls
|
|
80
|
+
};
|
|
@@ -0,0 +1,247 @@
|
|
|
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/controlPrimitives.tsx
|
|
31
|
+
var controlPrimitives_exports = {};
|
|
32
|
+
__export(controlPrimitives_exports, {
|
|
33
|
+
ParamRangeField: () => ParamRangeField,
|
|
34
|
+
ParamToggleField: () => ParamToggleField,
|
|
35
|
+
PlayPauseButton: () => PlayPauseButton,
|
|
36
|
+
ResetButton: () => ResetButton,
|
|
37
|
+
StepButton: () => StepButton,
|
|
38
|
+
StopButton: () => StopButton,
|
|
39
|
+
TickReadout: () => TickReadout,
|
|
40
|
+
TickSeekSlider: () => TickSeekSlider
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(controlPrimitives_exports);
|
|
43
|
+
|
|
44
|
+
// src/react/hooks.ts
|
|
45
|
+
var import_react2 = __toESM(require("react"), 1);
|
|
46
|
+
|
|
47
|
+
// src/react/SimulationContext.tsx
|
|
48
|
+
var import_react = __toESM(require("react"), 1);
|
|
49
|
+
var SimulationContext = import_react.default.createContext(null);
|
|
50
|
+
|
|
51
|
+
// src/react/hooks.ts
|
|
52
|
+
function useSimulation() {
|
|
53
|
+
const ctx = import_react2.default.useContext(SimulationContext);
|
|
54
|
+
if (!ctx) {
|
|
55
|
+
throw new Error("useSimulation must be used within a <Simulation>");
|
|
56
|
+
}
|
|
57
|
+
return ctx;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/react/controlPrimitives.tsx
|
|
61
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
62
|
+
var btnStyle = {
|
|
63
|
+
padding: "6px 12px",
|
|
64
|
+
borderRadius: 6,
|
|
65
|
+
border: "1px solid rgba(0,0,0,0.2)",
|
|
66
|
+
background: "#fff",
|
|
67
|
+
cursor: "pointer"
|
|
68
|
+
};
|
|
69
|
+
function PlayPauseButton(props) {
|
|
70
|
+
const { status, play, pause } = useSimulation();
|
|
71
|
+
const { playingLabel = "Pause", pausedLabel = "Play", disabled } = props;
|
|
72
|
+
const isPlaying = status === "playing";
|
|
73
|
+
const canPlay = status === "idle" || status === "paused";
|
|
74
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
75
|
+
"button",
|
|
76
|
+
{
|
|
77
|
+
type: "button",
|
|
78
|
+
style: btnStyle,
|
|
79
|
+
onClick: isPlaying ? pause : play,
|
|
80
|
+
disabled: disabled ?? (!canPlay && !isPlaying),
|
|
81
|
+
children: isPlaying ? playingLabel : pausedLabel
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
function StopButton(props) {
|
|
86
|
+
const { status, stop } = useSimulation();
|
|
87
|
+
const canStop = status === "playing" || status === "paused";
|
|
88
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
89
|
+
"button",
|
|
90
|
+
{
|
|
91
|
+
type: "button",
|
|
92
|
+
style: btnStyle,
|
|
93
|
+
onClick: stop,
|
|
94
|
+
disabled: props.disabled ?? !canStop,
|
|
95
|
+
children: props.label ?? "Stop"
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
function StepButton(props) {
|
|
100
|
+
const { status, advance } = useSimulation();
|
|
101
|
+
const ticks = props.ticks ?? 1;
|
|
102
|
+
const canStep = status === "idle" || status === "paused";
|
|
103
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
104
|
+
"button",
|
|
105
|
+
{
|
|
106
|
+
type: "button",
|
|
107
|
+
style: btnStyle,
|
|
108
|
+
onClick: () => advance(ticks),
|
|
109
|
+
disabled: props.disabled ?? !canStep,
|
|
110
|
+
title: "Advance one or more ticks while paused",
|
|
111
|
+
children: props.label ?? `Step${ticks > 1 ? ` (${ticks})` : ""}`
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
function ResetButton(props) {
|
|
116
|
+
const { resetWith } = useSimulation();
|
|
117
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", style: btnStyle, onClick: () => resetWith(), children: props.label ?? "Reset" });
|
|
118
|
+
}
|
|
119
|
+
function TickSeekSlider(props) {
|
|
120
|
+
const { tick, status, seek } = useSimulation();
|
|
121
|
+
const min = props.min ?? 0;
|
|
122
|
+
const max = props.max;
|
|
123
|
+
const disabled = status === "stopped";
|
|
124
|
+
if (!Number.isFinite(max)) return null;
|
|
125
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
126
|
+
"div",
|
|
127
|
+
{
|
|
128
|
+
style: {
|
|
129
|
+
display: "flex",
|
|
130
|
+
gap: 10,
|
|
131
|
+
alignItems: "center",
|
|
132
|
+
width: "100%"
|
|
133
|
+
},
|
|
134
|
+
children: [
|
|
135
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
136
|
+
"input",
|
|
137
|
+
{
|
|
138
|
+
type: "range",
|
|
139
|
+
min,
|
|
140
|
+
max,
|
|
141
|
+
step: 1,
|
|
142
|
+
value: tick,
|
|
143
|
+
onChange: (e) => seek(Number(e.target.value)),
|
|
144
|
+
disabled,
|
|
145
|
+
style: { flex: 1 }
|
|
146
|
+
}
|
|
147
|
+
),
|
|
148
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
149
|
+
"span",
|
|
150
|
+
{
|
|
151
|
+
style: {
|
|
152
|
+
fontFamily: "monospace",
|
|
153
|
+
opacity: 0.8,
|
|
154
|
+
minWidth: 48,
|
|
155
|
+
textAlign: "right"
|
|
156
|
+
},
|
|
157
|
+
children: tick
|
|
158
|
+
}
|
|
159
|
+
)
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
function ParamRangeField(props) {
|
|
165
|
+
const { params, setParams } = useSimulation();
|
|
166
|
+
const label = props.label ?? props.param;
|
|
167
|
+
const raw = params[props.param];
|
|
168
|
+
const numericValue = Number(raw);
|
|
169
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
170
|
+
"label",
|
|
171
|
+
{
|
|
172
|
+
style: {
|
|
173
|
+
display: "flex",
|
|
174
|
+
gap: 10,
|
|
175
|
+
alignItems: "center",
|
|
176
|
+
width: "100%"
|
|
177
|
+
},
|
|
178
|
+
children: [
|
|
179
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { minWidth: 120, opacity: 0.9 }, children: label }),
|
|
180
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
181
|
+
"input",
|
|
182
|
+
{
|
|
183
|
+
type: "range",
|
|
184
|
+
min: props.min,
|
|
185
|
+
max: props.max,
|
|
186
|
+
step: props.step ?? 1,
|
|
187
|
+
value: Number.isFinite(numericValue) ? numericValue : props.min,
|
|
188
|
+
onChange: (e) => {
|
|
189
|
+
const v = Number(e.target.value);
|
|
190
|
+
setParams({ [props.param]: v });
|
|
191
|
+
},
|
|
192
|
+
style: { flex: 1 }
|
|
193
|
+
}
|
|
194
|
+
),
|
|
195
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
196
|
+
"span",
|
|
197
|
+
{
|
|
198
|
+
style: {
|
|
199
|
+
width: 72,
|
|
200
|
+
textAlign: "right",
|
|
201
|
+
fontFamily: "monospace",
|
|
202
|
+
opacity: 0.8
|
|
203
|
+
},
|
|
204
|
+
children: numericValue
|
|
205
|
+
}
|
|
206
|
+
)
|
|
207
|
+
]
|
|
208
|
+
}
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
function ParamToggleField(props) {
|
|
212
|
+
const { params, setParams } = useSimulation();
|
|
213
|
+
const label = props.label ?? props.param;
|
|
214
|
+
const checked = Boolean(params[props.param]);
|
|
215
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { style: { display: "flex", gap: 10, alignItems: "center" }, children: [
|
|
216
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { minWidth: 120, opacity: 0.9 }, children: label }),
|
|
217
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
218
|
+
"input",
|
|
219
|
+
{
|
|
220
|
+
type: "checkbox",
|
|
221
|
+
checked,
|
|
222
|
+
onChange: (e) => {
|
|
223
|
+
setParams({ [props.param]: e.target.checked });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
)
|
|
227
|
+
] });
|
|
228
|
+
}
|
|
229
|
+
function TickReadout(props) {
|
|
230
|
+
const { tick } = useSimulation();
|
|
231
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { fontFamily: "monospace", opacity: 0.85 }, children: [
|
|
232
|
+
props.prefix ?? "",
|
|
233
|
+
"tick: ",
|
|
234
|
+
tick
|
|
235
|
+
] });
|
|
236
|
+
}
|
|
237
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
238
|
+
0 && (module.exports = {
|
|
239
|
+
ParamRangeField,
|
|
240
|
+
ParamToggleField,
|
|
241
|
+
PlayPauseButton,
|
|
242
|
+
ResetButton,
|
|
243
|
+
StepButton,
|
|
244
|
+
StopButton,
|
|
245
|
+
TickReadout,
|
|
246
|
+
TickSeekSlider
|
|
247
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
type PlayPauseButtonProps = {
|
|
4
|
+
playingLabel?: string;
|
|
5
|
+
pausedLabel?: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare function PlayPauseButton(props: PlayPauseButtonProps): react_jsx_runtime.JSX.Element;
|
|
9
|
+
declare function StopButton(props: {
|
|
10
|
+
label?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}): react_jsx_runtime.JSX.Element;
|
|
13
|
+
type StepButtonProps = {
|
|
14
|
+
ticks?: number;
|
|
15
|
+
label?: string;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
};
|
|
18
|
+
declare function StepButton(props: StepButtonProps): react_jsx_runtime.JSX.Element;
|
|
19
|
+
declare function ResetButton(props: {
|
|
20
|
+
label?: string;
|
|
21
|
+
}): react_jsx_runtime.JSX.Element;
|
|
22
|
+
type TickSeekSliderProps = {
|
|
23
|
+
min?: number;
|
|
24
|
+
max: number;
|
|
25
|
+
};
|
|
26
|
+
declare function TickSeekSlider(props: TickSeekSliderProps): react_jsx_runtime.JSX.Element | null;
|
|
27
|
+
type ParamRangeFieldProps<Params extends Record<string, unknown>> = {
|
|
28
|
+
param: Extract<keyof Params, string>;
|
|
29
|
+
label?: string;
|
|
30
|
+
min: number;
|
|
31
|
+
max: number;
|
|
32
|
+
step?: number;
|
|
33
|
+
};
|
|
34
|
+
declare function ParamRangeField<Params extends Record<string, unknown> = Record<string, unknown>>(props: ParamRangeFieldProps<Params>): react_jsx_runtime.JSX.Element;
|
|
35
|
+
type ParamToggleFieldProps<Params extends Record<string, unknown>> = {
|
|
36
|
+
param: Extract<keyof Params, string>;
|
|
37
|
+
label?: string;
|
|
38
|
+
};
|
|
39
|
+
declare function ParamToggleField<Params extends Record<string, unknown> = Record<string, unknown>>(props: ParamToggleFieldProps<Params>): react_jsx_runtime.JSX.Element;
|
|
40
|
+
type TickReadoutProps = {
|
|
41
|
+
prefix?: string;
|
|
42
|
+
};
|
|
43
|
+
declare function TickReadout(props: TickReadoutProps): react_jsx_runtime.JSX.Element;
|
|
44
|
+
|
|
45
|
+
export { ParamRangeField, type ParamRangeFieldProps, ParamToggleField, type ParamToggleFieldProps, PlayPauseButton, type PlayPauseButtonProps, ResetButton, StepButton, type StepButtonProps, StopButton, TickReadout, type TickReadoutProps, TickSeekSlider, type TickSeekSliderProps };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
type PlayPauseButtonProps = {
|
|
4
|
+
playingLabel?: string;
|
|
5
|
+
pausedLabel?: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare function PlayPauseButton(props: PlayPauseButtonProps): react_jsx_runtime.JSX.Element;
|
|
9
|
+
declare function StopButton(props: {
|
|
10
|
+
label?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}): react_jsx_runtime.JSX.Element;
|
|
13
|
+
type StepButtonProps = {
|
|
14
|
+
ticks?: number;
|
|
15
|
+
label?: string;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
};
|
|
18
|
+
declare function StepButton(props: StepButtonProps): react_jsx_runtime.JSX.Element;
|
|
19
|
+
declare function ResetButton(props: {
|
|
20
|
+
label?: string;
|
|
21
|
+
}): react_jsx_runtime.JSX.Element;
|
|
22
|
+
type TickSeekSliderProps = {
|
|
23
|
+
min?: number;
|
|
24
|
+
max: number;
|
|
25
|
+
};
|
|
26
|
+
declare function TickSeekSlider(props: TickSeekSliderProps): react_jsx_runtime.JSX.Element | null;
|
|
27
|
+
type ParamRangeFieldProps<Params extends Record<string, unknown>> = {
|
|
28
|
+
param: Extract<keyof Params, string>;
|
|
29
|
+
label?: string;
|
|
30
|
+
min: number;
|
|
31
|
+
max: number;
|
|
32
|
+
step?: number;
|
|
33
|
+
};
|
|
34
|
+
declare function ParamRangeField<Params extends Record<string, unknown> = Record<string, unknown>>(props: ParamRangeFieldProps<Params>): react_jsx_runtime.JSX.Element;
|
|
35
|
+
type ParamToggleFieldProps<Params extends Record<string, unknown>> = {
|
|
36
|
+
param: Extract<keyof Params, string>;
|
|
37
|
+
label?: string;
|
|
38
|
+
};
|
|
39
|
+
declare function ParamToggleField<Params extends Record<string, unknown> = Record<string, unknown>>(props: ParamToggleFieldProps<Params>): react_jsx_runtime.JSX.Element;
|
|
40
|
+
type TickReadoutProps = {
|
|
41
|
+
prefix?: string;
|
|
42
|
+
};
|
|
43
|
+
declare function TickReadout(props: TickReadoutProps): react_jsx_runtime.JSX.Element;
|
|
44
|
+
|
|
45
|
+
export { ParamRangeField, type ParamRangeFieldProps, ParamToggleField, type ParamToggleFieldProps, PlayPauseButton, type PlayPauseButtonProps, ResetButton, StepButton, type StepButtonProps, StopButton, TickReadout, type TickReadoutProps, TickSeekSlider, type TickSeekSliderProps };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ParamRangeField,
|
|
3
|
+
ParamToggleField,
|
|
4
|
+
PlayPauseButton,
|
|
5
|
+
ResetButton,
|
|
6
|
+
StepButton,
|
|
7
|
+
StopButton,
|
|
8
|
+
TickReadout,
|
|
9
|
+
TickSeekSlider
|
|
10
|
+
} from "../chunk-HTH6FQ7C.js";
|
|
11
|
+
import "../chunk-AIKB2FNR.js";
|
|
12
|
+
import "../chunk-66FUVAAG.js";
|
|
13
|
+
export {
|
|
14
|
+
ParamRangeField,
|
|
15
|
+
ParamToggleField,
|
|
16
|
+
PlayPauseButton,
|
|
17
|
+
ResetButton,
|
|
18
|
+
StepButton,
|
|
19
|
+
StopButton,
|
|
20
|
+
TickReadout,
|
|
21
|
+
TickSeekSlider
|
|
22
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
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/hooks.ts
|
|
31
|
+
var hooks_exports = {};
|
|
32
|
+
__export(hooks_exports, {
|
|
33
|
+
useSimulation: () => useSimulation
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
36
|
+
var import_react2 = __toESM(require("react"), 1);
|
|
37
|
+
|
|
38
|
+
// src/react/SimulationContext.tsx
|
|
39
|
+
var import_react = __toESM(require("react"), 1);
|
|
40
|
+
var SimulationContext = import_react.default.createContext(null);
|
|
41
|
+
|
|
42
|
+
// src/react/hooks.ts
|
|
43
|
+
function useSimulation() {
|
|
44
|
+
const ctx = import_react2.default.useContext(SimulationContext);
|
|
45
|
+
if (!ctx) {
|
|
46
|
+
throw new Error("useSimulation must be used within a <Simulation>");
|
|
47
|
+
}
|
|
48
|
+
return ctx;
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
useSimulation
|
|
53
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SimulationContextValue } from './SimulationContext.cjs';
|
|
2
|
+
import { SimModule } from '../sim.cjs';
|
|
3
|
+
import 'react';
|
|
4
|
+
import '../engine.cjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Helper type: extract Data and Params from a SimModule type, or use them directly.
|
|
8
|
+
*
|
|
9
|
+
* Supports two usage patterns:
|
|
10
|
+
* useSimulation<typeof mySim>() — infers Data & Params from the module
|
|
11
|
+
* useSimulation<MyData, MyParams>() — explicit type parameters
|
|
12
|
+
*/
|
|
13
|
+
type InferSimTypes<T, FallbackParams = unknown> = T extends SimModule<infer D, infer P> ? SimulationContextValue<D, P> : SimulationContextValue<T, FallbackParams>;
|
|
14
|
+
/**
|
|
15
|
+
* Read simulation state and actions from the nearest `<Simulation>` provider.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Infer types from the sim module:
|
|
19
|
+
* const { data, tick, play } = useSimulation<typeof counterSim>();
|
|
20
|
+
*
|
|
21
|
+
* // Or provide types explicitly:
|
|
22
|
+
* const { data } = useSimulation<{ count: number }, { increment: number }>();
|
|
23
|
+
*/
|
|
24
|
+
declare function useSimulation<T = unknown, FallbackParams = unknown>(): InferSimTypes<T, FallbackParams>;
|
|
25
|
+
|
|
26
|
+
export { useSimulation };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SimulationContextValue } from './SimulationContext.js';
|
|
2
|
+
import { SimModule } from '../sim.js';
|
|
3
|
+
import 'react';
|
|
4
|
+
import '../engine.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Helper type: extract Data and Params from a SimModule type, or use them directly.
|
|
8
|
+
*
|
|
9
|
+
* Supports two usage patterns:
|
|
10
|
+
* useSimulation<typeof mySim>() — infers Data & Params from the module
|
|
11
|
+
* useSimulation<MyData, MyParams>() — explicit type parameters
|
|
12
|
+
*/
|
|
13
|
+
type InferSimTypes<T, FallbackParams = unknown> = T extends SimModule<infer D, infer P> ? SimulationContextValue<D, P> : SimulationContextValue<T, FallbackParams>;
|
|
14
|
+
/**
|
|
15
|
+
* Read simulation state and actions from the nearest `<Simulation>` provider.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Infer types from the sim module:
|
|
19
|
+
* const { data, tick, play } = useSimulation<typeof counterSim>();
|
|
20
|
+
*
|
|
21
|
+
* // Or provide types explicitly:
|
|
22
|
+
* const { data } = useSimulation<{ count: number }, { increment: number }>();
|
|
23
|
+
*/
|
|
24
|
+
declare function useSimulation<T = unknown, FallbackParams = unknown>(): InferSimTypes<T, FallbackParams>;
|
|
25
|
+
|
|
26
|
+
export { useSimulation };
|
|
@@ -0,0 +1,47 @@
|
|
|
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/stableCallback.ts
|
|
31
|
+
var stableCallback_exports = {};
|
|
32
|
+
__export(stableCallback_exports, {
|
|
33
|
+
useStableCallback: () => useStableCallback
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(stableCallback_exports);
|
|
36
|
+
var import_react = __toESM(require("react"), 1);
|
|
37
|
+
function useStableCallback(fn) {
|
|
38
|
+
const fnRef = import_react.default.useRef(fn);
|
|
39
|
+
import_react.default.useEffect(() => {
|
|
40
|
+
fnRef.current = fn;
|
|
41
|
+
});
|
|
42
|
+
return import_react.default.useCallback((...args) => fnRef.current(...args), []);
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
useStableCallback
|
|
47
|
+
});
|