@simten/embed 0.1.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 (61) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +167 -0
  3. package/dist/CircuitEmbed.d.ts +92 -0
  4. package/dist/CircuitEmbed.d.ts.map +1 -0
  5. package/dist/CircuitEmbed.js +104 -0
  6. package/dist/CircuitEmbed.js.map +1 -0
  7. package/dist/CircuitViewer.d.ts +100 -0
  8. package/dist/CircuitViewer.d.ts.map +1 -0
  9. package/dist/CircuitViewer.js +76 -0
  10. package/dist/CircuitViewer.js.map +1 -0
  11. package/dist/canvas/index.d.ts +6 -0
  12. package/dist/canvas/index.d.ts.map +1 -0
  13. package/dist/canvas/index.js +5 -0
  14. package/dist/canvas/index.js.map +1 -0
  15. package/dist/circuit-embed.js +79 -0
  16. package/dist/components/ErrorBoundary.d.ts +23 -0
  17. package/dist/components/ErrorBoundary.d.ts.map +1 -0
  18. package/dist/components/ErrorBoundary.js +34 -0
  19. package/dist/components/ErrorBoundary.js.map +1 -0
  20. package/dist/components/ErrorDisplay.d.ts +18 -0
  21. package/dist/components/ErrorDisplay.d.ts.map +1 -0
  22. package/dist/components/ErrorDisplay.js +24 -0
  23. package/dist/components/ErrorDisplay.js.map +1 -0
  24. package/dist/components/LoadingSkeleton.d.ts +11 -0
  25. package/dist/components/LoadingSkeleton.d.ts.map +1 -0
  26. package/dist/components/LoadingSkeleton.js +10 -0
  27. package/dist/components/LoadingSkeleton.js.map +1 -0
  28. package/dist/components/nodes/index.d.ts +7 -0
  29. package/dist/components/nodes/index.d.ts.map +1 -0
  30. package/dist/components/nodes/index.js +7 -0
  31. package/dist/components/nodes/index.js.map +1 -0
  32. package/dist/hooks/useCircuitSimulator.d.ts +95 -0
  33. package/dist/hooks/useCircuitSimulator.d.ts.map +1 -0
  34. package/dist/hooks/useCircuitSimulator.js +568 -0
  35. package/dist/hooks/useCircuitSimulator.js.map +1 -0
  36. package/dist/index.d.ts +13 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +8 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/lib/utils.d.ts +3 -0
  41. package/dist/lib/utils.d.ts.map +1 -0
  42. package/dist/lib/utils.js +6 -0
  43. package/dist/lib/utils.js.map +1 -0
  44. package/dist/share-context.d.ts +18 -0
  45. package/dist/share-context.d.ts.map +1 -0
  46. package/dist/share-context.js +10 -0
  47. package/dist/share-context.js.map +1 -0
  48. package/dist/styles.css +1 -0
  49. package/dist/types.d.ts +30 -0
  50. package/dist/types.d.ts.map +1 -0
  51. package/dist/types.js +6 -0
  52. package/dist/types.js.map +1 -0
  53. package/dist/webcomponent/WebComponentEmbed.d.ts +24 -0
  54. package/dist/webcomponent/WebComponentEmbed.d.ts.map +1 -0
  55. package/dist/webcomponent/WebComponentEmbed.js +61 -0
  56. package/dist/webcomponent/WebComponentEmbed.js.map +1 -0
  57. package/dist/webcomponent/index.d.ts +19 -0
  58. package/dist/webcomponent/index.d.ts.map +1 -0
  59. package/dist/webcomponent/index.js +38 -0
  60. package/dist/webcomponent/index.js.map +1 -0
  61. package/package.json +85 -0
@@ -0,0 +1,568 @@
1
+ /**
2
+ * useCircuitSimulator — the public circuit-simulation hook.
3
+ *
4
+ * Composes the sandbox bridge (`useSandbox` in @simten/ui) with circuit-level
5
+ * concerns: auto-harness, time-travel history, auto-run, snapshot/restore.
6
+ * This is what every embed/blog/editor consumer calls.
7
+ *
8
+ * Runtime topology (browser path):
9
+ * useCircuitSimulator (here)
10
+ * → useSandbox — packages/ui/src/sandbox/useSandbox.ts (postMessage bridge)
11
+ * → apps/sandbox/main.ts — runs inside the cross-origin iframe
12
+ * → core/simulator — pure simulator engine
13
+ *
14
+ * For non-browser callers (vitest, CI), skip this hook entirely and use
15
+ * `@simten/core/sim` directly — no iframe, no React, just the engine.
16
+ *
17
+ * See: apps/web/content/docs/architecture.mdx → "Runtime topology".
18
+ */
19
+ import { useState, useEffect, useCallback, useRef, useMemo } from "react";
20
+ import { getCircuitEval, autoHarness, isSequentialCircuit } from "@simten/core/circuit";
21
+ import { Switch, Button, Led, Input, Output, HexDisplay } from "@simten/core/std";
22
+ import { useSandboxContext } from "@simten/ui/sandbox";
23
+ const TOP_LEVEL_NODE = "__top__";
24
+ /**
25
+ * Extract eval function sources from a BuiltCircuit and its dependencies.
26
+ * These are serialized and sent to the sandbox, which reconstructs them with new Function().
27
+ * Returns empty object if the circuit's evals aren't registered in this frame
28
+ * (e.g. editor case where evals live only in the sandbox from prior compile).
29
+ */
30
+ function extractEvalSources(circuit) {
31
+ const sources = {};
32
+ const visited = new Set();
33
+ function collect(c) {
34
+ const name = c.circuit.name;
35
+ if (visited.has(name))
36
+ return;
37
+ visited.add(name);
38
+ const entry = getCircuitEval(name);
39
+ if (entry) {
40
+ sources[name] = {
41
+ evalSource: entry.evalFn.toString(),
42
+ onTickSource: entry.onTickFn?.toString(),
43
+ inputNames: entry.inputNames,
44
+ outputNames: entry.outputNames,
45
+ stateKeys: entry.stateKeys,
46
+ };
47
+ }
48
+ for (const [, dep] of c._dependencies) {
49
+ if (dep)
50
+ collect(dep);
51
+ }
52
+ }
53
+ collect(circuit);
54
+ return sources;
55
+ }
56
+ /**
57
+ * Build a minimal BuiltCircuit-like object from a Circuit IR and its dependencies.
58
+ * Used by the editor to adapt sandbox compile results into the shape useCircuitSimulator expects.
59
+ * The resulting object has no live eval functions (empty registry lookups) — the sandbox
60
+ * is expected to already have the evals registered from a prior sandbox.compile(source).
61
+ */
62
+ export function builtFromIR(circuit, dependencies) {
63
+ const depMap = new Map();
64
+ for (const dep of dependencies) {
65
+ depMap.set(dep.name, {
66
+ circuit: dep,
67
+ _dependencies: new Map(),
68
+ });
69
+ }
70
+ return {
71
+ circuit,
72
+ _dependencies: depMap,
73
+ };
74
+ }
75
+ /**
76
+ * Circuit simulator hook — runs simulation in the sandbox iframe.
77
+ *
78
+ * Takes a BuiltCircuit and returns reactive simulation state + actions.
79
+ * All simulation happens inside the sandbox for security (CSP-isolated,
80
+ * cross-origin) — no user code runs in the main frame at simulation time.
81
+ */
82
+ export function useCircuitSimulator(circuit, options) {
83
+ const sandbox = useSandboxContext();
84
+ const slotId = useMemo(() => `embed-${typeof crypto !== 'undefined' && crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36).slice(2)}`, []);
85
+ // ── Build library + resolve circuit IR ──
86
+ const { rawCircuit, componentLibrary } = useMemo(() => {
87
+ const circuitMap = new Map();
88
+ const lib = {
89
+ resolveCircuit: (name) => circuitMap.get(name),
90
+ getAllPrimitiveNames: () => [...circuitMap.entries()].filter(([, c]) => c.implementation.kind === 'primitive').map(([n]) => n),
91
+ addCircuit: (c) => { circuitMap.set(c.name, c); },
92
+ };
93
+ for (const c of [Switch(), Button(), Led, Input(), Output, HexDisplay]) {
94
+ lib.addCircuit(c.circuit);
95
+ }
96
+ if (circuit) {
97
+ lib.addCircuit(circuit.circuit);
98
+ if (circuit._dependencies) {
99
+ for (const [, dep] of circuit._dependencies) {
100
+ if (dep?.circuit)
101
+ lib.addCircuit(dep.circuit);
102
+ }
103
+ }
104
+ }
105
+ return { rawCircuit: circuit?.circuit ?? null, componentLibrary: lib };
106
+ }, [circuit]);
107
+ // ── Auto-harness (wrap with Switches/LEDs if enabled) ──
108
+ const harnessedCircuit = useMemo(() => {
109
+ if (!rawCircuit)
110
+ return null;
111
+ if (!options?.autoHarness)
112
+ return rawCircuit;
113
+ return autoHarness(rawCircuit, componentLibrary, options.initialInputs);
114
+ }, [rawCircuit, componentLibrary, options?.autoHarness, options?.initialInputs]);
115
+ // ── Detect sequential (recursively) using shared core util ──
116
+ const isSequential = useMemo(() => isSequentialCircuit(harnessedCircuit, componentLibrary.resolveCircuit), [harnessedCircuit, componentLibrary]);
117
+ // ── Sandbox simulation state ──
118
+ const [portValues, setPortValues] = useState(new Map());
119
+ // Peripheral-bus state exposed by the sandbox — only includes nodes on a
120
+ // peripheral's bus (displays, consoles, etc.). Consumers read it through
121
+ // the `sequentialState` shape below so rendering code doesn't need to know
122
+ // it's narrower than a full FlatSequentialState.
123
+ const [peripheralState, setPeripheralState] = useState({});
124
+ const [cycle, setCycle] = useState(0);
125
+ const [ready, setReady] = useState(false);
126
+ const [isRunning, setIsRunning] = useState(false);
127
+ const [speed, setSpeedState] = useState(5);
128
+ const autoRunRef = useRef(null);
129
+ const historyRef = useRef([]);
130
+ const [historyIndex, setHistoryIndex] = useState(-1);
131
+ const [historyLen, setHistoryLen] = useState(0); // duplicate of historyRef.length for re-renders
132
+ const HISTORY_CAP = 200;
133
+ // Default inputs from the harnessed circuit's top-level inputs
134
+ const defaultInputs = useMemo(() => {
135
+ const result = {};
136
+ if (!harnessedCircuit)
137
+ return result;
138
+ for (const input of harnessedCircuit.inputs) {
139
+ result[input.name] = input.portType.kind === 'bit' ? false : 0;
140
+ }
141
+ return result;
142
+ }, [harnessedCircuit]);
143
+ const [outputs, setOutputs] = useState({});
144
+ const [inputs, setInputs] = useState(defaultInputs);
145
+ // Mirror of inputs in a ref so tick/tickN can snapshot the latest value
146
+ // synchronously without waiting for setState → re-render.
147
+ const inputsRef = useRef(inputs);
148
+ useEffect(() => { inputsRef.current = inputs; }, [inputs]);
149
+ // ── Compile to sandbox on mount / circuit change ──
150
+ useEffect(() => {
151
+ if (!circuit || !harnessedCircuit) {
152
+ setReady(false);
153
+ setPortValues(new Map());
154
+ return;
155
+ }
156
+ let cancelled = false;
157
+ async function initSandbox() {
158
+ if (!circuit || !harnessedCircuit)
159
+ return;
160
+ // Extract eval sources from the BuiltCircuit and its dependencies
161
+ const evalSources = extractEvalSources(circuit);
162
+ // Collect all library circuits (stdlib + user).
163
+ // The harnessed circuit references the raw circuit as "dut" by name, so we
164
+ // need to include it + all its dependencies + harness components.
165
+ const libCircuits = [];
166
+ const seen = new Set();
167
+ const addCircuit = (c) => {
168
+ if (seen.has(c.name))
169
+ return;
170
+ seen.add(c.name);
171
+ libCircuits.push(c);
172
+ };
173
+ // The raw circuit (referenced as "dut" by the harness)
174
+ addCircuit(circuit.circuit);
175
+ // Its transitive dependencies
176
+ for (const [, dep] of circuit._dependencies) {
177
+ if (dep?.circuit)
178
+ addCircuit(dep.circuit);
179
+ }
180
+ // Harness components (Switch, Led, etc.)
181
+ for (const c of [Switch(), Button(), Led, Input(), Output, HexDisplay]) {
182
+ addCircuit(c.circuit);
183
+ }
184
+ // Anything else in the library
185
+ const primNames = componentLibrary.getAllPrimitiveNames();
186
+ for (const name of primNames) {
187
+ const c = componentLibrary.resolveCircuit(name);
188
+ if (c)
189
+ addCircuit(c);
190
+ }
191
+ // Only bother snapshotting if the circuit is sequential — combinational
192
+ // circuits don't have state worth rewinding to.
193
+ const result = await sandbox.compileIR(harnessedCircuit, libCircuits, slotId, {
194
+ evalSources,
195
+ snapshot: isSequential,
196
+ });
197
+ if (cancelled)
198
+ return;
199
+ if ('error' in result) {
200
+ console.error('[useCircuitSimulator] compileIR failed:', result.error);
201
+ setReady(false);
202
+ return;
203
+ }
204
+ const pvMap = new Map();
205
+ for (const [k, v] of Object.entries(result.portValues)) {
206
+ pvMap.set(k, v);
207
+ }
208
+ setPortValues(pvMap);
209
+ if (result.peripheralState)
210
+ setPeripheralState(result.peripheralState);
211
+ setCycle(0);
212
+ // Seed history with the initial snapshot (if any). Fresh compile means
213
+ // the previous history (if any) is invalid anyway — sandbox already
214
+ // cleared its own snapshots on the recompile.
215
+ historyRef.current = result.snapshotId !== undefined
216
+ ? [{ snapshotId: result.snapshotId, cycle: 0, inputs: { ...defaultInputs } }]
217
+ : [];
218
+ setHistoryIndex(result.snapshotId !== undefined ? 0 : -1);
219
+ setHistoryLen(historyRef.current.length);
220
+ setReady(true);
221
+ // isSequential is computed synchronously via useMemo above — no need to set async
222
+ }
223
+ initSandbox();
224
+ return () => {
225
+ cancelled = true;
226
+ sandbox.dispose(slotId).catch(() => { });
227
+ };
228
+ }, [circuit, harnessedCircuit, componentLibrary, sandbox, slotId, isSequential]);
229
+ // Sync inputs when underlying circuit changes
230
+ useEffect(() => {
231
+ setInputs(defaultInputs);
232
+ }, [defaultInputs]);
233
+ // Extract outputs from portValues
234
+ useEffect(() => {
235
+ if (!ready || portValues.size === 0 || !harnessedCircuit)
236
+ return;
237
+ const newOutputs = {};
238
+ for (const output of harnessedCircuit.outputs) {
239
+ const key = `${TOP_LEVEL_NODE}.${output.name}`;
240
+ const value = portValues.get(key);
241
+ if (value !== undefined) {
242
+ newOutputs[output.name] = typeof value === 'number' ? value : Boolean(value);
243
+ }
244
+ }
245
+ setOutputs(newOutputs);
246
+ }, [ready, portValues, harnessedCircuit]);
247
+ // ── History bookkeeping helper ──
248
+ //
249
+ // Called after any state-mutating sandbox operation that returns a snapshot.
250
+ // Handles branch-on-past-edit (truncates future), enforces the 200-entry cap,
251
+ // and updates React state so the UI re-renders with fresh ◀▶ counts.
252
+ //
253
+ // The `inputsSnapshot` is what the user-visible inputs (switches, buttons,
254
+ // etc.) looked like at this moment — used on rewind so the UI restores not
255
+ // just the simulator state but the user inputs too.
256
+ const recordSnapshot = useCallback((snapshotId, newCycle, inputsSnapshot) => {
257
+ if (snapshotId === undefined)
258
+ return; // combinational circuit — nothing to record
259
+ const hist = historyRef.current;
260
+ const currentIdx = historyIndexRef.current;
261
+ // If the user was viewing the past and just made a mutating action,
262
+ // we branch: discard everything after their current position, then
263
+ // append the new snapshot as the new head. The orphaned sandbox
264
+ // snapshots leak until the next cap-prune or slot disposal.
265
+ if (currentIdx >= 0 && currentIdx < hist.length - 1) {
266
+ hist.length = currentIdx + 1;
267
+ }
268
+ hist.push({ snapshotId, cycle: newCycle, inputs: { ...inputsSnapshot } });
269
+ // Cap at HISTORY_CAP: drop oldest entries and tell the sandbox to
270
+ // free their snapshots. `keepAfterId` is the highest snapshotId we
271
+ // DO NOT want to keep — anything <= that gets freed in the sandbox.
272
+ if (hist.length > HISTORY_CAP) {
273
+ const drop = hist.length - HISTORY_CAP;
274
+ const keepAfterId = hist[drop - 1].snapshotId;
275
+ hist.splice(0, drop);
276
+ sandbox.pruneSnapshots(keepAfterId, slotId).catch(() => { });
277
+ }
278
+ historyIndexRef.current = hist.length - 1;
279
+ setHistoryIndex(hist.length - 1);
280
+ setHistoryLen(hist.length);
281
+ }, [sandbox, slotId]);
282
+ // Mirror historyIndex in a ref so the helper above can see its live value
283
+ // without recompiling on every change (avoids rebuilding every callback).
284
+ const historyIndexRef = useRef(-1);
285
+ useEffect(() => { historyIndexRef.current = historyIndex; }, [historyIndex]);
286
+ // ── Actions ──
287
+ const setNode = useCallback(async (name, value) => {
288
+ // Input changes (switch toggles, button presses) don't create a new
289
+ // history entry — history tracks CYCLES (post-tick states), not every
290
+ // input edit. The current cycle's "inputs" stay live: the next tick
291
+ // will snapshot them as part of its history entry. If the user is
292
+ // viewing the past when they toggle, the next tick branches from there.
293
+ const newInputs = { ...inputsRef.current, [name]: value };
294
+ inputsRef.current = newInputs;
295
+ setInputs(newInputs);
296
+ if (!ready)
297
+ return;
298
+ const result = await sandbox.setNode(name, value, slotId);
299
+ if ('error' in result)
300
+ return;
301
+ const pvMap = new Map();
302
+ for (const [k, v] of Object.entries(result.portValues))
303
+ pvMap.set(k, v);
304
+ setPortValues(pvMap);
305
+ if (result.peripheralState)
306
+ setPeripheralState(result.peripheralState);
307
+ }, [ready, sandbox, slotId]);
308
+ const toggleInput = useCallback((name) => {
309
+ const current = inputs[name];
310
+ const newValue = typeof current === 'boolean' ? !current : (current === 0 ? 1 : 0);
311
+ setNode(name, newValue);
312
+ }, [inputs, setNode]);
313
+ const toggleNode = useCallback(async (nodeId) => {
314
+ if (!ready)
315
+ return;
316
+ const outKey = `${nodeId}.out`;
317
+ const current = portValues.get(outKey);
318
+ const newValue = typeof current === 'boolean' ? !current : (current === 1 ? 0 : 1);
319
+ // Same reasoning as setNode: no new history entry on input edit.
320
+ const result = await sandbox.setNode(nodeId, newValue, slotId);
321
+ if ('error' in result)
322
+ return;
323
+ const pvMap = new Map();
324
+ for (const [k, v] of Object.entries(result.portValues))
325
+ pvMap.set(k, v);
326
+ setPortValues(pvMap);
327
+ if (result.peripheralState)
328
+ setPeripheralState(result.peripheralState);
329
+ }, [ready, portValues, sandbox, slotId]);
330
+ const setNodeValue = useCallback(async (nodeId, value) => {
331
+ if (!ready)
332
+ return null;
333
+ // Map values (for ROM/RAM loading) are supported via structured clone in postMessage.
334
+ // Same reasoning as setNode: no history entry on this path.
335
+ const result = await sandbox.setNode(nodeId, value, slotId);
336
+ if ('error' in result)
337
+ return null;
338
+ const pvMap = new Map();
339
+ for (const [k, v] of Object.entries(result.portValues))
340
+ pvMap.set(k, v);
341
+ setPortValues(pvMap);
342
+ if (result.peripheralState)
343
+ setPeripheralState(result.peripheralState);
344
+ return pvMap;
345
+ }, [ready, sandbox, slotId]);
346
+ const tick = useCallback(async () => {
347
+ if (!ready)
348
+ return;
349
+ const result = await sandbox.tick(undefined, slotId, { snapshot: isSequential });
350
+ if ('error' in result)
351
+ return;
352
+ const pvMap = new Map();
353
+ for (const [k, v] of Object.entries(result.portValues))
354
+ pvMap.set(k, v);
355
+ setPortValues(pvMap);
356
+ setCycle(result.cycle);
357
+ if (result.peripheralState)
358
+ setPeripheralState(result.peripheralState);
359
+ // tick() doesn't modify user inputs — the switch position at tick time
360
+ // is what goes into history.
361
+ recordSnapshot(result.snapshotId, result.cycle, inputsRef.current);
362
+ }, [ready, sandbox, slotId, isSequential, recordSnapshot]);
363
+ // Batched tick — advances N cycles in one round-trip; one React update.
364
+ // Only snapshots the final state (not every intermediate cycle) — time-travel
365
+ // through a batched tick jumps straight to pre-batch.
366
+ const tickN = useCallback(async (n) => {
367
+ if (!ready || n <= 0)
368
+ return;
369
+ const result = await sandbox.tickN(n, undefined, slotId, { snapshot: isSequential });
370
+ if ('error' in result)
371
+ return;
372
+ const pvMap = new Map();
373
+ for (const [k, v] of Object.entries(result.portValues))
374
+ pvMap.set(k, v);
375
+ setPortValues(pvMap);
376
+ setCycle(result.cycle);
377
+ if (result.peripheralState)
378
+ setPeripheralState(result.peripheralState);
379
+ recordSnapshot(result.snapshotId, result.cycle, inputsRef.current);
380
+ }, [ready, sandbox, slotId, isSequential, recordSnapshot]);
381
+ const scanPort = useCallback(async (addrNodeId, valuePortKey, count) => {
382
+ if (!ready || count <= 0)
383
+ return null;
384
+ const result = await sandbox.scanPort(addrNodeId, valuePortKey, count, slotId);
385
+ if ('error' in result)
386
+ return null;
387
+ return result.values;
388
+ }, [ready, sandbox, slotId]);
389
+ const reset = useCallback(async () => {
390
+ const result = await sandbox.reset(slotId);
391
+ if ('error' in result)
392
+ return;
393
+ const pvMap = new Map();
394
+ for (const [k, v] of Object.entries(result.portValues))
395
+ pvMap.set(k, v);
396
+ setPortValues(pvMap);
397
+ setCycle(0);
398
+ setInputs(defaultInputs);
399
+ if (result.peripheralState)
400
+ setPeripheralState(result.peripheralState);
401
+ else
402
+ setPeripheralState({});
403
+ // Sandbox reset already cleared its own snapshots. Clear ours too,
404
+ // then seed a fresh initial snapshot for the post-reset state so
405
+ // time-travel starts over from here.
406
+ historyRef.current = [];
407
+ if (isSequential) {
408
+ const snap = await sandbox.snapshot(slotId);
409
+ if (!('error' in snap) && snap.snapshotId !== undefined) {
410
+ historyRef.current = [{ snapshotId: snap.snapshotId, cycle: 0, inputs: { ...defaultInputs } }];
411
+ }
412
+ }
413
+ historyIndexRef.current = historyRef.current.length > 0 ? 0 : -1;
414
+ setHistoryIndex(historyRef.current.length > 0 ? 0 : -1);
415
+ setHistoryLen(historyRef.current.length);
416
+ }, [sandbox, slotId, defaultInputs, isSequential]);
417
+ // ── Time-travel actions ──
418
+ // Shared restore helper — applies a history entry to both the simulator
419
+ // and the host-side input state. We restore inputs because the UI "rewind"
420
+ // promise is a full restoration of user-visible state: switch positions,
421
+ // input values, circuit state. Omitting inputs would leave the UI showing
422
+ // a stale switch while the circuit actually runs with the restored value —
423
+ // see environmental-state.ts in packages/core for the same distinction.
424
+ const applyHistoryEntry = useCallback(async (entry, targetIndex) => {
425
+ const result = await sandbox.restore(entry.snapshotId, slotId);
426
+ if ('error' in result)
427
+ return;
428
+ const pvMap = new Map();
429
+ for (const [k, v] of Object.entries(result.portValues))
430
+ pvMap.set(k, v);
431
+ setPortValues(pvMap);
432
+ setCycle(result.cycle);
433
+ if (result.peripheralState)
434
+ setPeripheralState(result.peripheralState);
435
+ else
436
+ setPeripheralState({});
437
+ // Restore user inputs too. Keep inputsRef in lockstep so that any
438
+ // immediately-following setNode sees the restored values as its base.
439
+ const restoredInputs = { ...entry.inputs };
440
+ inputsRef.current = restoredInputs;
441
+ setInputs(restoredInputs);
442
+ historyIndexRef.current = targetIndex;
443
+ setHistoryIndex(targetIndex);
444
+ }, [sandbox, slotId]);
445
+ const stepBack = useCallback(async () => {
446
+ if (!ready)
447
+ return;
448
+ const hist = historyRef.current;
449
+ const idx = historyIndexRef.current;
450
+ if (idx <= 0)
451
+ return; // already at or before the start
452
+ await applyHistoryEntry(hist[idx - 1], idx - 1);
453
+ }, [ready, applyHistoryEntry]);
454
+ const stepForward = useCallback(async () => {
455
+ if (!ready)
456
+ return;
457
+ const hist = historyRef.current;
458
+ const idx = historyIndexRef.current;
459
+ // Already at the live head — nothing to step into yet.
460
+ // (Clicking ▶ at the head is a no-op, not a tick. Users run the clock
461
+ // explicitly via Tick/autorun to add new history.)
462
+ if (idx >= hist.length - 1)
463
+ return;
464
+ await applyHistoryEntry(hist[idx + 1], idx + 1);
465
+ }, [ready, applyHistoryEntry]);
466
+ const seek = useCallback(async (index) => {
467
+ if (!ready)
468
+ return;
469
+ const hist = historyRef.current;
470
+ if (index < 0 || index >= hist.length)
471
+ return;
472
+ await applyHistoryEntry(hist[index], index);
473
+ }, [ready, applyHistoryEntry]);
474
+ // Stable indirection so setInterval always calls the latest tick(). Without
475
+ // this, an auto-run started before `ready` flips true would capture the
476
+ // bail-early version of tick and never recover, even after the sandbox
477
+ // becomes ready — the interval would fire forever calling a stale closure.
478
+ const tickRef = useRef(tick);
479
+ useEffect(() => { tickRef.current = tick; }, [tick]);
480
+ const startAutoRun = useCallback((ticksPerSecond, _opts) => {
481
+ if (autoRunRef.current)
482
+ clearInterval(autoRunRef.current);
483
+ setSpeedState(ticksPerSecond);
484
+ setIsRunning(true);
485
+ const interval = Math.max(1, Math.floor(1000 / ticksPerSecond));
486
+ autoRunRef.current = setInterval(() => { tickRef.current(); }, interval);
487
+ }, []);
488
+ const stopAutoRun = useCallback(() => {
489
+ if (autoRunRef.current) {
490
+ clearInterval(autoRunRef.current);
491
+ autoRunRef.current = null;
492
+ }
493
+ setIsRunning(false);
494
+ }, []);
495
+ const setSpeed = useCallback((ticksPerSecond) => {
496
+ setSpeedState(ticksPerSecond);
497
+ if (autoRunRef.current) {
498
+ // Restart with new speed
499
+ clearInterval(autoRunRef.current);
500
+ const interval = Math.max(1, Math.floor(1000 / ticksPerSecond));
501
+ autoRunRef.current = setInterval(() => { tickRef.current(); }, interval);
502
+ }
503
+ }, []);
504
+ useEffect(() => {
505
+ return () => {
506
+ if (autoRunRef.current)
507
+ clearInterval(autoRunRef.current);
508
+ };
509
+ }, []);
510
+ // Expose peripheral-bus state as a FlatSequentialState-compatible shape so
511
+ // projection code (which was written against in-process simulation) doesn't
512
+ // need to learn about the sandbox boundary. Only nodes on a peripheral's
513
+ // bus appear here — internal logic state stays sandbox-internal.
514
+ const sequentialState = useMemo(() => {
515
+ const entries = Object.entries(peripheralState);
516
+ if (entries.length === 0)
517
+ return null;
518
+ const currentState = new Map();
519
+ for (const [k, v] of entries)
520
+ currentState.set(k, v);
521
+ return {
522
+ currentState,
523
+ nextState: new Map(),
524
+ clocks: new Map(),
525
+ cycleCount: cycle,
526
+ };
527
+ }, [peripheralState, cycle]);
528
+ // Shadow-typed history for the UI: the consumer only needs a length for
529
+ // showing the `N/M` counter and the ◀ ▶ enable logic. historyLen drives
530
+ // re-renders; the array identity is intentionally stable per-slot.
531
+ const historyForUi = useMemo(() => historyRef.current.slice(0, historyLen).map(h => ({ engineSnapshot: h.snapshotId, metadata: h.cycle })), [historyLen]);
532
+ return {
533
+ // State
534
+ outputs,
535
+ inputs,
536
+ cycleCount: cycle,
537
+ ready,
538
+ error: null,
539
+ isSequential,
540
+ circuit: harnessedCircuit,
541
+ portValues: portValues.size > 0 ? portValues : null,
542
+ sequentialState,
543
+ componentLibrary,
544
+ history: historyForUi,
545
+ historyIndex,
546
+ isViewingPast: historyIndex >= 0 && historyIndex < historyLen - 1,
547
+ isRunning,
548
+ speed,
549
+ // Actions
550
+ setNode,
551
+ toggleInput,
552
+ toggleNode,
553
+ setNodeValue,
554
+ tick,
555
+ tickN,
556
+ scanPort,
557
+ reset,
558
+ stepBack,
559
+ stepForward,
560
+ seek,
561
+ startAutoRun,
562
+ stopAutoRun,
563
+ setSpeed,
564
+ runCombinational: () => { }, // sandbox.setNode already runs combinational
565
+ getSimulator: () => null, // no local engine when running in sandbox
566
+ };
567
+ }
568
+ //# sourceMappingURL=useCircuitSimulator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCircuitSimulator.js","sourceRoot":"","sources":["../../src/hooks/useCircuitSimulator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAS1E,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAmB,MAAM,oBAAoB,CAAC;AAExE,MAAM,cAAc,GAAG,SAAS,CAAC;AAyDjC;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,OAAqB;IAC/C,MAAM,OAAO,GAA+B,EAAE,CAAC;IAC/C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAElC,SAAS,OAAO,CAAC,CAAe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C,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,EAC7G,CAAC,UAAU,CAAC,CACb,CAAC;IAEF,OAAO;QACL,QAAQ;QACR,OAAO;QACP,MAAM;QACN,UAAU,EAAE,KAAK;QACjB,KAAK;QACL,KAAK,EAAE,IAAI;QACX,YAAY;QACZ,OAAO,EAAE,gBAAgB;QACzB,UAAU,EAAE,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI;QACnD,eAAe;QACf,gBAAgB;QAChB,OAAO,EAAE,YAAY;QACrB,YAAY;QACZ,aAAa,EAAE,YAAY,IAAI,CAAC,IAAI,YAAY,GAAG,UAAU,GAAG,CAAC;QACjE,SAAS;QACT,KAAK;QAEL,UAAU;QACV,OAAO;QACP,WAAW;QACX,UAAU;QACV,YAAY;QACZ,IAAI;QACJ,KAAK;QACL,QAAQ;QACR,KAAK;QACL,QAAQ;QACR,WAAW;QACX,IAAI;QACJ,YAAY;QACZ,WAAW;QACX,QAAQ;QACR,gBAAgB,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,6CAA6C;QACzE,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,0CAA0C;KACrE,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ export { CircuitViewer } from './CircuitViewer';
2
+ export type { CircuitViewerProps, CircuitViewerHandle } from './CircuitViewer';
3
+ export { CircuitEmbed } from './CircuitEmbed';
4
+ export type { CircuitEmbedProps, CircuitEmbedHandle } from './CircuitEmbed';
5
+ export { useCircuitSimulator, builtFromIR } from './hooks/useCircuitSimulator';
6
+ export type { SimulatorState, SimulatorActions, UseCircuitSimulatorOptions } from './hooks/useCircuitSimulator';
7
+ export { CircuitCanvas } from '@simten/ui/canvas';
8
+ export type { CircuitCanvasProps } from '@simten/ui/canvas';
9
+ export { ErrorBoundary } from './components/ErrorBoundary';
10
+ export { ErrorDisplay } from './components/ErrorDisplay';
11
+ export type { SimulatorError } from './components/ErrorDisplay';
12
+ export { ShareCircuitProvider, useShareCircuit, type ShareCircuitFn } from './share-context';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,YAAY,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/E,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AAChH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,YAAY,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { CircuitViewer } from './CircuitViewer';
2
+ export { CircuitEmbed } from './CircuitEmbed';
3
+ export { useCircuitSimulator, builtFromIR } from './hooks/useCircuitSimulator';
4
+ export { CircuitCanvas } from '@simten/ui/canvas';
5
+ export { ErrorBoundary } from './components/ErrorBoundary';
6
+ export { ErrorDisplay } from './components/ErrorDisplay';
7
+ export { ShareCircuitProvider, useShareCircuit } from './share-context';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/E,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAuB,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type ClassValue } from "clsx";
2
+ export declare function cn(...inputs: ClassValue[]): string;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,MAAM,CAAC;AAG7C,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC"}
@@ -0,0 +1,6 @@
1
+ import { clsx } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+ export function cn(...inputs) {
4
+ return twMerge(clsx(inputs));
5
+ }
6
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,MAAM,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,MAAM,UAAU,EAAE,CAAC,GAAG,MAAoB;IACxC,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/B,CAAC"}