@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,76 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * CircuitViewer — the single "render an interactive circuit" component.
4
+ *
5
+ * Takes a BuiltCircuit, wires up simulation, and renders CircuitCanvas + ClockControls.
6
+ * Pure props — no stores. Everything else (CircuitEmbed, EditorWorkspace, <circuit-embed>)
7
+ * is a thin wrapper around this.
8
+ */
9
+ import { useCallback, useEffect, useRef, forwardRef, useImperativeHandle } from "react";
10
+ import { useCircuitSimulator } from "./hooks/useCircuitSimulator";
11
+ import { CircuitCanvas, ClockControls, useDetectTheme } from "@simten/ui/canvas";
12
+ const CircuitViewerImpl = forwardRef(function CircuitViewer({ circuit, height = 300, showControls = true, autoHarness = false, initialInputs, layout, theme, focus, showPortLabels, onPortClick, glowUnconnected, renderEmptyState, renderOverlay, onPortValuesChange, }, ref) {
13
+ const sim = useCircuitSimulator(circuit, { autoHarness, initialInputs });
14
+ const detectedTheme = useDetectTheme();
15
+ const resolvedTheme = theme ?? detectedTheme;
16
+ // Capture the callback in a ref so inline functions don't cause the
17
+ // firing effect below to re-run on every parent render. The effect
18
+ // depends only on [sim.ready, sim.portValues], not on the callback
19
+ // identity, so passing `onPortValuesChange={(pv) => setX(pv)}` is
20
+ // safe even though it creates a new function reference each render.
21
+ const onPortValuesChangeRef = useRef(onPortValuesChange);
22
+ useEffect(() => {
23
+ onPortValuesChangeRef.current = onPortValuesChange;
24
+ });
25
+ // Fire once the sim is ready and port values have first settled; then
26
+ // fire on every subsequent settled change. The empty-map guard avoids
27
+ // a spurious fire during the initial compile-but-not-yet-propagated
28
+ // window. The hook only exposes settled states, so no debouncing is
29
+ // needed for intermediate propagation steps.
30
+ useEffect(() => {
31
+ if (!sim.ready || !sim.portValues || sim.portValues.size === 0)
32
+ return;
33
+ onPortValuesChangeRef.current?.(sim.portValues);
34
+ }, [sim.ready, sim.portValues]);
35
+ const handleTick = useCallback(() => {
36
+ sim.tick();
37
+ }, [sim.tick]);
38
+ const handleReset = useCallback(() => {
39
+ sim.reset();
40
+ }, [sim.reset]);
41
+ useImperativeHandle(ref, () => ({
42
+ tick: handleTick,
43
+ reset: handleReset,
44
+ setNodeValue: sim.setNodeValue,
45
+ startAutoRun: sim.startAutoRun,
46
+ stopAutoRun: sim.stopAutoRun,
47
+ }), [handleTick, handleReset, sim.setNodeValue, sim.startAutoRun, sim.stopAutoRun]);
48
+ if (sim.error) {
49
+ return (_jsx("div", { style: { height }, className: "flex items-center justify-center p-4", children: _jsxs("div", { className: "text-sm text-red-400 bg-red-500/10 rounded p-3 border border-red-500/20", children: [_jsx("div", { className: "font-medium mb-1", children: "Compilation Error" }), _jsx("div", { className: "font-mono text-xs", children: sim.error })] }) }));
50
+ }
51
+ if (!sim.ready) {
52
+ return (_jsx("div", { style: { height }, className: "flex items-center justify-center text-muted-foreground/60 text-sm", children: "Compiling..." }));
53
+ }
54
+ const controlHeight = sim.isSequential && showControls ? 40 : 0;
55
+ const canvasHeight = typeof height === "number" ? height - controlHeight : height;
56
+ return (_jsxs("div", { style: { height }, className: "flex flex-col", "data-embed-theme": resolvedTheme, children: [_jsx("div", { className: "flex-1 min-h-0", children: _jsx(CircuitCanvas, { circuit: sim.circuit, componentLibrary: sim.componentLibrary ?? undefined, portValues: sim.portValues, sequentialState: sim.sequentialState, onToggleNode: sim.toggleNode, onSetNodeValue: sim.setNodeValue, onLoadMemory: (nodeId, memData) => {
57
+ const engine = sim.getSimulator();
58
+ if (engine) {
59
+ engine.setNode(nodeId, memData);
60
+ sim.runCombinational();
61
+ }
62
+ }, height: canvasHeight, focus: focus, showPortLabels: showPortLabels, onPortClick: onPortClick, glowUnconnected: glowUnconnected, renderEmptyState: renderEmptyState, renderOverlay: renderOverlay, ...(layout ? { layout } : {}), ...(theme ? { theme } : {}) }) }), sim.isSequential && showControls && (_jsx(ClockControls, { cycle: sim.cycleCount, historyLength: sim.history?.length ?? 0, historyIndex: sim.historyIndex ?? -1, isRunning: sim.isRunning, isViewingPast: sim.isViewingPast ?? false, onStep: handleTick, onRun: () => sim.startAutoRun(5), onPause: () => sim.stopAutoRun(), onReset: handleReset, onStepBack: () => sim.stepBack(), onStepForward: () => {
63
+ if (sim.isViewingPast) {
64
+ sim.stepForward();
65
+ }
66
+ else {
67
+ handleTick();
68
+ }
69
+ }, speed: 5 }))] }));
70
+ });
71
+ /**
72
+ * CircuitViewer with generic inference over the circuit type.
73
+ * Cast preserves the generic so `layout` keys are constrained at compile time.
74
+ */
75
+ export const CircuitViewer = CircuitViewerImpl;
76
+ //# sourceMappingURL=CircuitViewer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CircuitViewer.js","sourceRoot":"","sources":["../src/CircuitViewer.tsx"],"names":[],"mappings":";AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,SAAS,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AC,OAAO,EAAE,MAAM,IAAI,CAAC,EACvC,YAAY,EAAE,GAAG,CAAC,YAAY,IAAI,CAAC,CAAC,EACpC,SAAS,EAAE,GAAG,CAAC,SAAS,EACxB,aAAa,EAAE,GAAG,CAAC,aAAa,IAAI,KAAK,EACzC,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAChC,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,EAChC,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,EAChC,aAAa,EAAE,GAAG,EAAE;oBAClB,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC;wBACtB,GAAG,CAAC,WAAW,EAAE,CAAC;oBACpB,CAAC;yBAAM,CAAC;wBACN,UAAU,EAAE,CAAC;oBACf,CAAC;gBACH,CAAC,EACD,KAAK,EAAE,CAAC,GACR,CACH,IACG,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,iBAEZ,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Re-export from @simten/ui/canvas.
3
+ */
4
+ export { CircuitCanvas } from "@simten/ui/canvas";
5
+ export type { CircuitCanvasProps } from "@simten/ui/canvas";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/canvas/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Re-export from @simten/ui/canvas.
3
+ */
4
+ export { CircuitCanvas } from "@simten/ui/canvas";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/canvas/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC"}