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.
Files changed (65) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +106 -0
  3. package/dist/chunk-66FUVAAG.js +7 -0
  4. package/dist/chunk-AIKB2FNR.js +17 -0
  5. package/dist/chunk-HTH6FQ7C.js +192 -0
  6. package/dist/chunk-OA6FGXTP.js +9 -0
  7. package/dist/chunk-SK5SHIWY.js +13 -0
  8. package/dist/chunk-YNLOTPDY.js +206 -0
  9. package/dist/engine.cjs +231 -0
  10. package/dist/engine.d.cts +72 -0
  11. package/dist/engine.d.ts +72 -0
  12. package/dist/engine.js +8 -0
  13. package/dist/react/EngineContext.cjs +43 -0
  14. package/dist/react/EngineContext.d.cts +18 -0
  15. package/dist/react/EngineContext.d.ts +18 -0
  16. package/dist/react/EngineContext.js +6 -0
  17. package/dist/react/PerformanceOverlay.cjs +341 -0
  18. package/dist/react/PerformanceOverlay.d.cts +9 -0
  19. package/dist/react/PerformanceOverlay.d.ts +9 -0
  20. package/dist/react/PerformanceOverlay.js +290 -0
  21. package/dist/react/Simulation.cjs +481 -0
  22. package/dist/react/Simulation.d.cts +31 -0
  23. package/dist/react/Simulation.d.ts +31 -0
  24. package/dist/react/Simulation.js +235 -0
  25. package/dist/react/SimulationContext.cjs +41 -0
  26. package/dist/react/SimulationContext.d.cts +25 -0
  27. package/dist/react/SimulationContext.d.ts +25 -0
  28. package/dist/react/SimulationContext.js +6 -0
  29. package/dist/react/SimulationControls.cjs +298 -0
  30. package/dist/react/SimulationControls.d.cts +33 -0
  31. package/dist/react/SimulationControls.d.ts +33 -0
  32. package/dist/react/SimulationControls.js +80 -0
  33. package/dist/react/controlPrimitives.cjs +247 -0
  34. package/dist/react/controlPrimitives.d.cts +45 -0
  35. package/dist/react/controlPrimitives.d.ts +45 -0
  36. package/dist/react/controlPrimitives.js +22 -0
  37. package/dist/react/hooks.cjs +53 -0
  38. package/dist/react/hooks.d.cts +26 -0
  39. package/dist/react/hooks.d.ts +26 -0
  40. package/dist/react/hooks.js +7 -0
  41. package/dist/react/stableCallback.cjs +47 -0
  42. package/dist/react/stableCallback.d.cts +3 -0
  43. package/dist/react/stableCallback.d.ts +3 -0
  44. package/dist/react/stableCallback.js +6 -0
  45. package/dist/react/useSimulationCanvas.cjs +92 -0
  46. package/dist/react/useSimulationCanvas.d.cts +38 -0
  47. package/dist/react/useSimulationCanvas.d.ts +38 -0
  48. package/dist/react/useSimulationCanvas.js +53 -0
  49. package/dist/sim.cjs +32 -0
  50. package/dist/sim.d.cts +40 -0
  51. package/dist/sim.d.ts +40 -0
  52. package/dist/sim.js +7 -0
  53. package/dist/worker/createSimWorker.cjs +147 -0
  54. package/dist/worker/createSimWorker.d.cts +19 -0
  55. package/dist/worker/createSimWorker.d.ts +19 -0
  56. package/dist/worker/createSimWorker.js +122 -0
  57. package/dist/worker/protocol.cjs +18 -0
  58. package/dist/worker/protocol.d.cts +59 -0
  59. package/dist/worker/protocol.d.ts +59 -0
  60. package/dist/worker/protocol.js +0 -0
  61. package/dist/worker/workerRunner.cjs +100 -0
  62. package/dist/worker/workerRunner.d.cts +30 -0
  63. package/dist/worker/workerRunner.d.ts +30 -0
  64. package/dist/worker/workerRunner.js +73 -0
  65. package/package.json +102 -0
@@ -0,0 +1,341 @@
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/PerformanceOverlay.tsx
31
+ var PerformanceOverlay_exports = {};
32
+ __export(PerformanceOverlay_exports, {
33
+ PerformanceOverlay: () => PerformanceOverlay
34
+ });
35
+ module.exports = __toCommonJS(PerformanceOverlay_exports);
36
+ var import_react4 = __toESM(require("react"), 1);
37
+
38
+ // src/react/hooks.ts
39
+ var import_react2 = __toESM(require("react"), 1);
40
+
41
+ // src/react/SimulationContext.tsx
42
+ var import_react = __toESM(require("react"), 1);
43
+ var SimulationContext = import_react.default.createContext(null);
44
+
45
+ // src/react/hooks.ts
46
+ function useSimulation() {
47
+ const ctx = import_react2.default.useContext(SimulationContext);
48
+ if (!ctx) {
49
+ throw new Error("useSimulation must be used within a <Simulation>");
50
+ }
51
+ return ctx;
52
+ }
53
+
54
+ // src/react/EngineContext.tsx
55
+ var import_react3 = __toESM(require("react"), 1);
56
+ var EngineContext = import_react3.default.createContext(
57
+ null
58
+ );
59
+
60
+ // src/react/PerformanceOverlay.tsx
61
+ var import_jsx_runtime = require("react/jsx-runtime");
62
+ function formatTime(ms) {
63
+ if (ms < 1e-3) return "<1\xB5s";
64
+ if (ms < 1) return `${Math.round(ms * 1e3)}\xB5s`;
65
+ if (ms < 10) return `${ms.toFixed(1)}ms`;
66
+ return `${Math.round(ms)}ms`;
67
+ }
68
+ var CHART_WIDTH = 120;
69
+ var CHART_HEIGHT = 60;
70
+ function PerfChart({
71
+ entries
72
+ }) {
73
+ if (entries.length === 0) {
74
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
75
+ "canvas",
76
+ {
77
+ width: CHART_WIDTH,
78
+ height: CHART_HEIGHT,
79
+ style: { display: "block", width: CHART_WIDTH, height: CHART_HEIGHT }
80
+ }
81
+ );
82
+ }
83
+ let currentMax = 0;
84
+ for (const e of entries) {
85
+ const total = e.stepMs + (e.drawMs ?? 0);
86
+ if (total > currentMax) currentMax = total;
87
+ }
88
+ const max = Math.max(currentMax, 1e-3);
89
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { position: "relative" }, children: [
90
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
91
+ "div",
92
+ {
93
+ style: {
94
+ position: "absolute",
95
+ top: -2,
96
+ right: 0,
97
+ fontSize: 10,
98
+ color: "#888"
99
+ },
100
+ children: formatTime(max)
101
+ }
102
+ ),
103
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
104
+ "canvas",
105
+ {
106
+ width: CHART_WIDTH,
107
+ height: CHART_HEIGHT,
108
+ style: { display: "block", width: CHART_WIDTH, height: CHART_HEIGHT },
109
+ ref: (canvas) => {
110
+ if (!canvas) return;
111
+ const ctx = canvas.getContext("2d");
112
+ if (!ctx) return;
113
+ ctx.clearRect(0, 0, CHART_WIDTH, CHART_HEIGHT);
114
+ const n = entries.length;
115
+ const chartTop = 10;
116
+ const chartH = CHART_HEIGHT - chartTop;
117
+ function yPos(ms) {
118
+ return chartTop + chartH - ms / max * chartH;
119
+ }
120
+ const hasAnyDraw = entries.some((e) => e.drawMs !== void 0);
121
+ const stepGrad = ctx.createLinearGradient(0, 0, 0, CHART_HEIGHT);
122
+ stepGrad.addColorStop(0, "rgba(79, 195, 247, 0.25)");
123
+ stepGrad.addColorStop(1, "rgba(79, 195, 247, 0.05)");
124
+ ctx.fillStyle = stepGrad;
125
+ ctx.beginPath();
126
+ ctx.moveTo(0, CHART_HEIGHT);
127
+ for (let i = 0; i < n; i++) {
128
+ ctx.lineTo(
129
+ i / Math.max(n - 1, 1) * CHART_WIDTH,
130
+ yPos(entries[i].stepMs)
131
+ );
132
+ }
133
+ ctx.lineTo(CHART_WIDTH, CHART_HEIGHT);
134
+ ctx.closePath();
135
+ ctx.fill();
136
+ if (hasAnyDraw) {
137
+ const drawGrad = ctx.createLinearGradient(0, 0, 0, CHART_HEIGHT);
138
+ drawGrad.addColorStop(0, "rgba(129, 199, 132, 0.25)");
139
+ drawGrad.addColorStop(1, "rgba(129, 199, 132, 0.05)");
140
+ ctx.fillStyle = drawGrad;
141
+ ctx.beginPath();
142
+ for (let i = 0; i < n; i++) {
143
+ const e = entries[i];
144
+ const x = i / Math.max(n - 1, 1) * CHART_WIDTH;
145
+ ctx.lineTo(x, yPos(e.stepMs + (e.drawMs ?? 0)));
146
+ }
147
+ for (let i = n - 1; i >= 0; i--) {
148
+ const x = i / Math.max(n - 1, 1) * CHART_WIDTH;
149
+ ctx.lineTo(x, yPos(entries[i].stepMs));
150
+ }
151
+ ctx.closePath();
152
+ ctx.fill();
153
+ }
154
+ ctx.strokeStyle = "rgba(255,255,255,0.2)";
155
+ ctx.setLineDash([3, 3]);
156
+ ctx.beginPath();
157
+ ctx.moveTo(0, chartTop);
158
+ ctx.lineTo(CHART_WIDTH, chartTop);
159
+ ctx.stroke();
160
+ ctx.setLineDash([]);
161
+ ctx.strokeStyle = "#4fc3f7";
162
+ ctx.lineWidth = 1;
163
+ ctx.beginPath();
164
+ for (let i = 0; i < n; i++) {
165
+ const x = i / Math.max(n - 1, 1) * CHART_WIDTH;
166
+ const y = yPos(entries[i].stepMs);
167
+ if (i === 0) ctx.moveTo(x, y);
168
+ else ctx.lineTo(x, y);
169
+ }
170
+ ctx.stroke();
171
+ if (hasAnyDraw) {
172
+ ctx.strokeStyle = "#81c784";
173
+ ctx.beginPath();
174
+ for (let i = 0; i < n; i++) {
175
+ const e = entries[i];
176
+ const x = i / Math.max(n - 1, 1) * CHART_WIDTH;
177
+ const y = yPos(e.stepMs + (e.drawMs ?? 0));
178
+ if (i === 0) ctx.moveTo(x, y);
179
+ else ctx.lineTo(x, y);
180
+ }
181
+ ctx.stroke();
182
+ }
183
+ }
184
+ }
185
+ )
186
+ ] });
187
+ }
188
+ function PerformanceOverlay() {
189
+ const { tick } = useSimulation();
190
+ const engineCtx = import_react4.default.useContext(EngineContext);
191
+ const [view, setView] = import_react4.default.useState("compact");
192
+ const [perf, setPerf] = import_react4.default.useState([]);
193
+ import_react4.default.useEffect(() => {
194
+ if (engineCtx) {
195
+ setPerf(engineCtx.getPerformance());
196
+ }
197
+ }, [engineCtx, tick]);
198
+ const stepValues = perf.map((p) => p.stepMs);
199
+ const drawValues = perf.filter((p) => p.drawMs !== void 0).map((p) => p.drawMs);
200
+ const hasDrawData = drawValues.length > 0;
201
+ const avgStep = stepValues.length > 0 ? stepValues.reduce((a, b) => a + b, 0) / stepValues.length : 0;
202
+ const avgDraw = hasDrawData ? drawValues.reduce((a, b) => a + b, 0) / drawValues.length : 0;
203
+ const avgTotal = avgStep + avgDraw;
204
+ if (view === "hidden") {
205
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
206
+ "button",
207
+ {
208
+ type: "button",
209
+ onClick: () => setView("compact"),
210
+ style: {
211
+ display: "inline-flex",
212
+ alignItems: "center",
213
+ gap: 6,
214
+ padding: "4px 12px",
215
+ background: "rgba(20, 20, 28, 0.92)",
216
+ border: "1px solid rgba(255,255,255,0.08)",
217
+ borderRadius: 20,
218
+ fontFamily: "monospace",
219
+ fontSize: 11,
220
+ color: "#ddd",
221
+ cursor: "pointer",
222
+ lineHeight: 1
223
+ },
224
+ children: [
225
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
226
+ "span",
227
+ {
228
+ style: {
229
+ width: 6,
230
+ height: 6,
231
+ borderRadius: "50%",
232
+ background: "#81c784",
233
+ boxShadow: "0 0 4px #81c784"
234
+ }
235
+ }
236
+ ),
237
+ formatTime(avgTotal)
238
+ ]
239
+ }
240
+ );
241
+ }
242
+ const isExpanded = view === "expanded";
243
+ const headerBtn = {
244
+ background: "none",
245
+ border: "none",
246
+ color: "#888",
247
+ cursor: "pointer",
248
+ padding: "2px 4px",
249
+ fontSize: 10,
250
+ lineHeight: 1
251
+ };
252
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
253
+ "div",
254
+ {
255
+ style: {
256
+ display: "flex",
257
+ flexDirection: "column",
258
+ width: 140,
259
+ padding: "8px 10px",
260
+ background: "rgba(20, 20, 28, 0.92)",
261
+ borderRadius: 8,
262
+ fontFamily: "monospace",
263
+ fontSize: 11,
264
+ lineHeight: 1,
265
+ border: "1px solid rgba(255,255,255,0.08)",
266
+ boxSizing: "border-box"
267
+ },
268
+ children: [
269
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
270
+ "div",
271
+ {
272
+ style: {
273
+ display: "flex",
274
+ justifyContent: "space-between",
275
+ alignItems: "center",
276
+ marginBottom: 8,
277
+ color: "#999"
278
+ },
279
+ children: [
280
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
281
+ "avg / ",
282
+ stepValues.length,
283
+ "f"
284
+ ] }),
285
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { display: "flex", gap: 0 }, children: [
286
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
287
+ "button",
288
+ {
289
+ type: "button",
290
+ style: headerBtn,
291
+ onClick: () => setView(isExpanded ? "compact" : "expanded"),
292
+ title: isExpanded ? "Collapse" : "Expand",
293
+ children: isExpanded ? "\u25BC" : "\u25B6"
294
+ }
295
+ ),
296
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
297
+ "button",
298
+ {
299
+ type: "button",
300
+ style: headerBtn,
301
+ onClick: () => setView("hidden"),
302
+ title: "Hide",
303
+ children: "\xD7"
304
+ }
305
+ )
306
+ ] })
307
+ ]
308
+ }
309
+ ),
310
+ isExpanded && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { marginBottom: 8 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PerfChart, { entries: perf }) }),
311
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
312
+ "div",
313
+ {
314
+ style: {
315
+ display: "grid",
316
+ gridTemplateColumns: hasDrawData ? "1fr 1fr 1fr" : "1fr 1fr"
317
+ },
318
+ children: [
319
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
320
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { color: "#4fc3f7", marginBottom: 4 }, children: "step" }),
321
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { color: "#ddd" }, children: formatTime(avgStep) })
322
+ ] }),
323
+ hasDrawData && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
324
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { color: "#81c784", marginBottom: 4 }, children: "draw" }),
325
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { color: "#ddd" }, children: formatTime(avgDraw) })
326
+ ] }),
327
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
328
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { color: "#999", marginBottom: 4 }, children: "total" }),
329
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { color: "#ddd" }, children: formatTime(avgTotal) })
330
+ ] })
331
+ ]
332
+ }
333
+ )
334
+ ]
335
+ }
336
+ );
337
+ }
338
+ // Annotate the CommonJS export names for ESM import in node:
339
+ 0 && (module.exports = {
340
+ PerformanceOverlay
341
+ });
@@ -0,0 +1,9 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ /**
4
+ * Performance overlay with three states: hidden (pill), compact (numbers),
5
+ * expanded (chart + numbers). Place inside a `<Simulation>`.
6
+ */
7
+ declare function PerformanceOverlay(): react_jsx_runtime.JSX.Element;
8
+
9
+ export { PerformanceOverlay };
@@ -0,0 +1,9 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ /**
4
+ * Performance overlay with three states: hidden (pill), compact (numbers),
5
+ * expanded (chart + numbers). Place inside a `<Simulation>`.
6
+ */
7
+ declare function PerformanceOverlay(): react_jsx_runtime.JSX.Element;
8
+
9
+ export { PerformanceOverlay };
@@ -0,0 +1,290 @@
1
+ import {
2
+ EngineContext
3
+ } from "../chunk-OA6FGXTP.js";
4
+ import {
5
+ useSimulation
6
+ } from "../chunk-AIKB2FNR.js";
7
+ import "../chunk-66FUVAAG.js";
8
+
9
+ // src/react/PerformanceOverlay.tsx
10
+ import React from "react";
11
+ import { jsx, jsxs } from "react/jsx-runtime";
12
+ function formatTime(ms) {
13
+ if (ms < 1e-3) return "<1\xB5s";
14
+ if (ms < 1) return `${Math.round(ms * 1e3)}\xB5s`;
15
+ if (ms < 10) return `${ms.toFixed(1)}ms`;
16
+ return `${Math.round(ms)}ms`;
17
+ }
18
+ var CHART_WIDTH = 120;
19
+ var CHART_HEIGHT = 60;
20
+ function PerfChart({
21
+ entries
22
+ }) {
23
+ if (entries.length === 0) {
24
+ return /* @__PURE__ */ jsx(
25
+ "canvas",
26
+ {
27
+ width: CHART_WIDTH,
28
+ height: CHART_HEIGHT,
29
+ style: { display: "block", width: CHART_WIDTH, height: CHART_HEIGHT }
30
+ }
31
+ );
32
+ }
33
+ let currentMax = 0;
34
+ for (const e of entries) {
35
+ const total = e.stepMs + (e.drawMs ?? 0);
36
+ if (total > currentMax) currentMax = total;
37
+ }
38
+ const max = Math.max(currentMax, 1e-3);
39
+ return /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
40
+ /* @__PURE__ */ jsx(
41
+ "div",
42
+ {
43
+ style: {
44
+ position: "absolute",
45
+ top: -2,
46
+ right: 0,
47
+ fontSize: 10,
48
+ color: "#888"
49
+ },
50
+ children: formatTime(max)
51
+ }
52
+ ),
53
+ /* @__PURE__ */ jsx(
54
+ "canvas",
55
+ {
56
+ width: CHART_WIDTH,
57
+ height: CHART_HEIGHT,
58
+ style: { display: "block", width: CHART_WIDTH, height: CHART_HEIGHT },
59
+ ref: (canvas) => {
60
+ if (!canvas) return;
61
+ const ctx = canvas.getContext("2d");
62
+ if (!ctx) return;
63
+ ctx.clearRect(0, 0, CHART_WIDTH, CHART_HEIGHT);
64
+ const n = entries.length;
65
+ const chartTop = 10;
66
+ const chartH = CHART_HEIGHT - chartTop;
67
+ function yPos(ms) {
68
+ return chartTop + chartH - ms / max * chartH;
69
+ }
70
+ const hasAnyDraw = entries.some((e) => e.drawMs !== void 0);
71
+ const stepGrad = ctx.createLinearGradient(0, 0, 0, CHART_HEIGHT);
72
+ stepGrad.addColorStop(0, "rgba(79, 195, 247, 0.25)");
73
+ stepGrad.addColorStop(1, "rgba(79, 195, 247, 0.05)");
74
+ ctx.fillStyle = stepGrad;
75
+ ctx.beginPath();
76
+ ctx.moveTo(0, CHART_HEIGHT);
77
+ for (let i = 0; i < n; i++) {
78
+ ctx.lineTo(
79
+ i / Math.max(n - 1, 1) * CHART_WIDTH,
80
+ yPos(entries[i].stepMs)
81
+ );
82
+ }
83
+ ctx.lineTo(CHART_WIDTH, CHART_HEIGHT);
84
+ ctx.closePath();
85
+ ctx.fill();
86
+ if (hasAnyDraw) {
87
+ const drawGrad = ctx.createLinearGradient(0, 0, 0, CHART_HEIGHT);
88
+ drawGrad.addColorStop(0, "rgba(129, 199, 132, 0.25)");
89
+ drawGrad.addColorStop(1, "rgba(129, 199, 132, 0.05)");
90
+ ctx.fillStyle = drawGrad;
91
+ ctx.beginPath();
92
+ for (let i = 0; i < n; i++) {
93
+ const e = entries[i];
94
+ const x = i / Math.max(n - 1, 1) * CHART_WIDTH;
95
+ ctx.lineTo(x, yPos(e.stepMs + (e.drawMs ?? 0)));
96
+ }
97
+ for (let i = n - 1; i >= 0; i--) {
98
+ const x = i / Math.max(n - 1, 1) * CHART_WIDTH;
99
+ ctx.lineTo(x, yPos(entries[i].stepMs));
100
+ }
101
+ ctx.closePath();
102
+ ctx.fill();
103
+ }
104
+ ctx.strokeStyle = "rgba(255,255,255,0.2)";
105
+ ctx.setLineDash([3, 3]);
106
+ ctx.beginPath();
107
+ ctx.moveTo(0, chartTop);
108
+ ctx.lineTo(CHART_WIDTH, chartTop);
109
+ ctx.stroke();
110
+ ctx.setLineDash([]);
111
+ ctx.strokeStyle = "#4fc3f7";
112
+ ctx.lineWidth = 1;
113
+ ctx.beginPath();
114
+ for (let i = 0; i < n; i++) {
115
+ const x = i / Math.max(n - 1, 1) * CHART_WIDTH;
116
+ const y = yPos(entries[i].stepMs);
117
+ if (i === 0) ctx.moveTo(x, y);
118
+ else ctx.lineTo(x, y);
119
+ }
120
+ ctx.stroke();
121
+ if (hasAnyDraw) {
122
+ ctx.strokeStyle = "#81c784";
123
+ ctx.beginPath();
124
+ for (let i = 0; i < n; i++) {
125
+ const e = entries[i];
126
+ const x = i / Math.max(n - 1, 1) * CHART_WIDTH;
127
+ const y = yPos(e.stepMs + (e.drawMs ?? 0));
128
+ if (i === 0) ctx.moveTo(x, y);
129
+ else ctx.lineTo(x, y);
130
+ }
131
+ ctx.stroke();
132
+ }
133
+ }
134
+ }
135
+ )
136
+ ] });
137
+ }
138
+ function PerformanceOverlay() {
139
+ const { tick } = useSimulation();
140
+ const engineCtx = React.useContext(EngineContext);
141
+ const [view, setView] = React.useState("compact");
142
+ const [perf, setPerf] = React.useState([]);
143
+ React.useEffect(() => {
144
+ if (engineCtx) {
145
+ setPerf(engineCtx.getPerformance());
146
+ }
147
+ }, [engineCtx, tick]);
148
+ const stepValues = perf.map((p) => p.stepMs);
149
+ const drawValues = perf.filter((p) => p.drawMs !== void 0).map((p) => p.drawMs);
150
+ const hasDrawData = drawValues.length > 0;
151
+ const avgStep = stepValues.length > 0 ? stepValues.reduce((a, b) => a + b, 0) / stepValues.length : 0;
152
+ const avgDraw = hasDrawData ? drawValues.reduce((a, b) => a + b, 0) / drawValues.length : 0;
153
+ const avgTotal = avgStep + avgDraw;
154
+ if (view === "hidden") {
155
+ return /* @__PURE__ */ jsxs(
156
+ "button",
157
+ {
158
+ type: "button",
159
+ onClick: () => setView("compact"),
160
+ style: {
161
+ display: "inline-flex",
162
+ alignItems: "center",
163
+ gap: 6,
164
+ padding: "4px 12px",
165
+ background: "rgba(20, 20, 28, 0.92)",
166
+ border: "1px solid rgba(255,255,255,0.08)",
167
+ borderRadius: 20,
168
+ fontFamily: "monospace",
169
+ fontSize: 11,
170
+ color: "#ddd",
171
+ cursor: "pointer",
172
+ lineHeight: 1
173
+ },
174
+ children: [
175
+ /* @__PURE__ */ jsx(
176
+ "span",
177
+ {
178
+ style: {
179
+ width: 6,
180
+ height: 6,
181
+ borderRadius: "50%",
182
+ background: "#81c784",
183
+ boxShadow: "0 0 4px #81c784"
184
+ }
185
+ }
186
+ ),
187
+ formatTime(avgTotal)
188
+ ]
189
+ }
190
+ );
191
+ }
192
+ const isExpanded = view === "expanded";
193
+ const headerBtn = {
194
+ background: "none",
195
+ border: "none",
196
+ color: "#888",
197
+ cursor: "pointer",
198
+ padding: "2px 4px",
199
+ fontSize: 10,
200
+ lineHeight: 1
201
+ };
202
+ return /* @__PURE__ */ jsxs(
203
+ "div",
204
+ {
205
+ style: {
206
+ display: "flex",
207
+ flexDirection: "column",
208
+ width: 140,
209
+ padding: "8px 10px",
210
+ background: "rgba(20, 20, 28, 0.92)",
211
+ borderRadius: 8,
212
+ fontFamily: "monospace",
213
+ fontSize: 11,
214
+ lineHeight: 1,
215
+ border: "1px solid rgba(255,255,255,0.08)",
216
+ boxSizing: "border-box"
217
+ },
218
+ children: [
219
+ /* @__PURE__ */ jsxs(
220
+ "div",
221
+ {
222
+ style: {
223
+ display: "flex",
224
+ justifyContent: "space-between",
225
+ alignItems: "center",
226
+ marginBottom: 8,
227
+ color: "#999"
228
+ },
229
+ children: [
230
+ /* @__PURE__ */ jsxs("span", { children: [
231
+ "avg / ",
232
+ stepValues.length,
233
+ "f"
234
+ ] }),
235
+ /* @__PURE__ */ jsxs("span", { style: { display: "flex", gap: 0 }, children: [
236
+ /* @__PURE__ */ jsx(
237
+ "button",
238
+ {
239
+ type: "button",
240
+ style: headerBtn,
241
+ onClick: () => setView(isExpanded ? "compact" : "expanded"),
242
+ title: isExpanded ? "Collapse" : "Expand",
243
+ children: isExpanded ? "\u25BC" : "\u25B6"
244
+ }
245
+ ),
246
+ /* @__PURE__ */ jsx(
247
+ "button",
248
+ {
249
+ type: "button",
250
+ style: headerBtn,
251
+ onClick: () => setView("hidden"),
252
+ title: "Hide",
253
+ children: "\xD7"
254
+ }
255
+ )
256
+ ] })
257
+ ]
258
+ }
259
+ ),
260
+ isExpanded && /* @__PURE__ */ jsx("div", { style: { marginBottom: 8 }, children: /* @__PURE__ */ jsx(PerfChart, { entries: perf }) }),
261
+ /* @__PURE__ */ jsxs(
262
+ "div",
263
+ {
264
+ style: {
265
+ display: "grid",
266
+ gridTemplateColumns: hasDrawData ? "1fr 1fr 1fr" : "1fr 1fr"
267
+ },
268
+ children: [
269
+ /* @__PURE__ */ jsxs("div", { children: [
270
+ /* @__PURE__ */ jsx("div", { style: { color: "#4fc3f7", marginBottom: 4 }, children: "step" }),
271
+ /* @__PURE__ */ jsx("div", { style: { color: "#ddd" }, children: formatTime(avgStep) })
272
+ ] }),
273
+ hasDrawData && /* @__PURE__ */ jsxs("div", { children: [
274
+ /* @__PURE__ */ jsx("div", { style: { color: "#81c784", marginBottom: 4 }, children: "draw" }),
275
+ /* @__PURE__ */ jsx("div", { style: { color: "#ddd" }, children: formatTime(avgDraw) })
276
+ ] }),
277
+ /* @__PURE__ */ jsxs("div", { children: [
278
+ /* @__PURE__ */ jsx("div", { style: { color: "#999", marginBottom: 4 }, children: "total" }),
279
+ /* @__PURE__ */ jsx("div", { style: { color: "#ddd" }, children: formatTime(avgTotal) })
280
+ ] })
281
+ ]
282
+ }
283
+ )
284
+ ]
285
+ }
286
+ );
287
+ }
288
+ export {
289
+ PerformanceOverlay
290
+ };