@simten/ui 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 (307) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +41 -0
  3. package/dist/canvas/CircuitCanvas.d.ts +45 -0
  4. package/dist/canvas/CircuitCanvas.d.ts.map +1 -0
  5. package/dist/canvas/CircuitCanvas.js +293 -0
  6. package/dist/canvas/CircuitCanvas.js.map +1 -0
  7. package/dist/canvas/ClockControls.d.ts +31 -0
  8. package/dist/canvas/ClockControls.d.ts.map +1 -0
  9. package/dist/canvas/ClockControls.js +33 -0
  10. package/dist/canvas/ClockControls.js.map +1 -0
  11. package/dist/canvas/CompositeInspectorDialog.d.ts +24 -0
  12. package/dist/canvas/CompositeInspectorDialog.d.ts.map +1 -0
  13. package/dist/canvas/CompositeInspectorDialog.js +290 -0
  14. package/dist/canvas/CompositeInspectorDialog.js.map +1 -0
  15. package/dist/canvas/dagre-layout.d.ts +40 -0
  16. package/dist/canvas/dagre-layout.d.ts.map +1 -0
  17. package/dist/canvas/dagre-layout.js +86 -0
  18. package/dist/canvas/dagre-layout.js.map +1 -0
  19. package/dist/canvas/drill-down-view.d.ts +35 -0
  20. package/dist/canvas/drill-down-view.d.ts.map +1 -0
  21. package/dist/canvas/drill-down-view.js +134 -0
  22. package/dist/canvas/drill-down-view.js.map +1 -0
  23. package/dist/canvas/hooks/useDetectTheme.d.ts +6 -0
  24. package/dist/canvas/hooks/useDetectTheme.d.ts.map +1 -0
  25. package/dist/canvas/hooks/useDetectTheme.js +20 -0
  26. package/dist/canvas/hooks/useDetectTheme.js.map +1 -0
  27. package/dist/canvas/hooks/useIsMobile.d.ts +2 -0
  28. package/dist/canvas/hooks/useIsMobile.d.ts.map +1 -0
  29. package/dist/canvas/hooks/useIsMobile.js +20 -0
  30. package/dist/canvas/hooks/useIsMobile.js.map +1 -0
  31. package/dist/canvas/hooks/useSimulationSession.d.ts +23 -0
  32. package/dist/canvas/hooks/useSimulationSession.d.ts.map +1 -0
  33. package/dist/canvas/hooks/useSimulationSession.js +41 -0
  34. package/dist/canvas/hooks/useSimulationSession.js.map +1 -0
  35. package/dist/canvas/index.d.ts +22 -0
  36. package/dist/canvas/index.d.ts.map +1 -0
  37. package/dist/canvas/index.js +17 -0
  38. package/dist/canvas/index.js.map +1 -0
  39. package/dist/canvas/label-utils.d.ts +10 -0
  40. package/dist/canvas/label-utils.d.ts.map +1 -0
  41. package/dist/canvas/label-utils.js +32 -0
  42. package/dist/canvas/label-utils.js.map +1 -0
  43. package/dist/canvas/node-types.d.ts +10 -0
  44. package/dist/canvas/node-types.d.ts.map +1 -0
  45. package/dist/canvas/node-types.js +29 -0
  46. package/dist/canvas/node-types.js.map +1 -0
  47. package/dist/canvas/projection.d.ts +19 -0
  48. package/dist/canvas/projection.d.ts.map +1 -0
  49. package/dist/canvas/projection.js +317 -0
  50. package/dist/canvas/projection.js.map +1 -0
  51. package/dist/canvas/types.d.ts +56 -0
  52. package/dist/canvas/types.d.ts.map +1 -0
  53. package/dist/canvas/types.js +6 -0
  54. package/dist/canvas/types.js.map +1 -0
  55. package/dist/canvas/useLayout.d.ts +21 -0
  56. package/dist/canvas/useLayout.d.ts.map +1 -0
  57. package/dist/canvas/useLayout.js +26 -0
  58. package/dist/canvas/useLayout.js.map +1 -0
  59. package/dist/editor/components/CircuitSelector.d.ts +9 -0
  60. package/dist/editor/components/CircuitSelector.d.ts.map +1 -0
  61. package/dist/editor/components/CircuitSelector.js +20 -0
  62. package/dist/editor/components/CircuitSelector.js.map +1 -0
  63. package/dist/editor/components/CircuitTabBar.d.ts +8 -0
  64. package/dist/editor/components/CircuitTabBar.d.ts.map +1 -0
  65. package/dist/editor/components/CircuitTabBar.js +23 -0
  66. package/dist/editor/components/CircuitTabBar.js.map +1 -0
  67. package/dist/editor/components/ClockControls.d.ts +6 -0
  68. package/dist/editor/components/ClockControls.d.ts.map +1 -0
  69. package/dist/editor/components/ClockControls.js +7 -0
  70. package/dist/editor/components/ClockControls.js.map +1 -0
  71. package/dist/editor/components/ComponentTooltip.d.ts +25 -0
  72. package/dist/editor/components/ComponentTooltip.d.ts.map +1 -0
  73. package/dist/editor/components/ComponentTooltip.js +82 -0
  74. package/dist/editor/components/ComponentTooltip.js.map +1 -0
  75. package/dist/editor/components/ConflictResolutionModal.d.ts +19 -0
  76. package/dist/editor/components/ConflictResolutionModal.d.ts.map +1 -0
  77. package/dist/editor/components/ConflictResolutionModal.js +20 -0
  78. package/dist/editor/components/ConflictResolutionModal.js.map +1 -0
  79. package/dist/editor/components/HierarchyBreadcrumb.d.ts +9 -0
  80. package/dist/editor/components/HierarchyBreadcrumb.d.ts.map +1 -0
  81. package/dist/editor/components/HierarchyBreadcrumb.js +32 -0
  82. package/dist/editor/components/HierarchyBreadcrumb.js.map +1 -0
  83. package/dist/editor/components/LabelEditor.d.ts +17 -0
  84. package/dist/editor/components/LabelEditor.d.ts.map +1 -0
  85. package/dist/editor/components/LabelEditor.js +40 -0
  86. package/dist/editor/components/LabelEditor.js.map +1 -0
  87. package/dist/editor/components/SignalOutputPanel.d.ts +11 -0
  88. package/dist/editor/components/SignalOutputPanel.d.ts.map +1 -0
  89. package/dist/editor/components/SignalOutputPanel.js +34 -0
  90. package/dist/editor/components/SignalOutputPanel.js.map +1 -0
  91. package/dist/editor/components/index.d.ts +9 -0
  92. package/dist/editor/components/index.d.ts.map +1 -0
  93. package/dist/editor/components/index.js +9 -0
  94. package/dist/editor/components/index.js.map +1 -0
  95. package/dist/editor/hooks/index.d.ts +1 -0
  96. package/dist/editor/hooks/index.d.ts.map +1 -0
  97. package/dist/editor/hooks/index.js +2 -0
  98. package/dist/editor/hooks/index.js.map +1 -0
  99. package/dist/editor/index.d.ts +5 -0
  100. package/dist/editor/index.d.ts.map +1 -0
  101. package/dist/editor/index.js +5 -0
  102. package/dist/editor/index.js.map +1 -0
  103. package/dist/editor/lib/simulation/index.d.ts +7 -0
  104. package/dist/editor/lib/simulation/index.d.ts.map +1 -0
  105. package/dist/editor/lib/simulation/index.js +8 -0
  106. package/dist/editor/lib/simulation/index.js.map +1 -0
  107. package/dist/editor/lib/utils/circuit-flattener.d.ts +29 -0
  108. package/dist/editor/lib/utils/circuit-flattener.d.ts.map +1 -0
  109. package/dist/editor/lib/utils/circuit-flattener.js +230 -0
  110. package/dist/editor/lib/utils/circuit-flattener.js.map +1 -0
  111. package/dist/editor/lib/utils/component-utils.d.ts +28 -0
  112. package/dist/editor/lib/utils/component-utils.d.ts.map +1 -0
  113. package/dist/editor/lib/utils/component-utils.js +72 -0
  114. package/dist/editor/lib/utils/component-utils.js.map +1 -0
  115. package/dist/editor/lib/utils/index.d.ts +3 -0
  116. package/dist/editor/lib/utils/index.d.ts.map +1 -0
  117. package/dist/editor/lib/utils/index.js +3 -0
  118. package/dist/editor/lib/utils/index.js.map +1 -0
  119. package/dist/editor/lib/visualization/index.d.ts +2 -0
  120. package/dist/editor/lib/visualization/index.d.ts.map +1 -0
  121. package/dist/editor/lib/visualization/index.js +2 -0
  122. package/dist/editor/lib/visualization/index.js.map +1 -0
  123. package/dist/editor/lib/visualization/vcd-generator.d.ts +63 -0
  124. package/dist/editor/lib/visualization/vcd-generator.d.ts.map +1 -0
  125. package/dist/editor/lib/visualization/vcd-generator.js +269 -0
  126. package/dist/editor/lib/visualization/vcd-generator.js.map +1 -0
  127. package/dist/editor/stores/circuit-library-store.d.ts +25 -0
  128. package/dist/editor/stores/circuit-library-store.d.ts.map +1 -0
  129. package/dist/editor/stores/circuit-library-store.js +51 -0
  130. package/dist/editor/stores/circuit-library-store.js.map +1 -0
  131. package/dist/editor/stores/circuit-preview-store.d.ts +687 -0
  132. package/dist/editor/stores/circuit-preview-store.d.ts.map +1 -0
  133. package/dist/editor/stores/circuit-preview-store.js +226 -0
  134. package/dist/editor/stores/circuit-preview-store.js.map +1 -0
  135. package/dist/editor/stores/circuit-store.d.ts +354 -0
  136. package/dist/editor/stores/circuit-store.d.ts.map +1 -0
  137. package/dist/editor/stores/circuit-store.js +227 -0
  138. package/dist/editor/stores/circuit-store.js.map +1 -0
  139. package/dist/editor/stores/index.d.ts +11 -0
  140. package/dist/editor/stores/index.d.ts.map +1 -0
  141. package/dist/editor/stores/index.js +8 -0
  142. package/dist/editor/stores/index.js.map +1 -0
  143. package/dist/editor/stores/ui-store.d.ts +96 -0
  144. package/dist/editor/stores/ui-store.d.ts.map +1 -0
  145. package/dist/editor/stores/ui-store.js +101 -0
  146. package/dist/editor/stores/ui-store.js.map +1 -0
  147. package/dist/editor/types/circuit.d.ts +207 -0
  148. package/dist/editor/types/circuit.d.ts.map +1 -0
  149. package/dist/editor/types/circuit.js +62 -0
  150. package/dist/editor/types/circuit.js.map +1 -0
  151. package/dist/editor/types/index.d.ts +12 -0
  152. package/dist/editor/types/index.d.ts.map +1 -0
  153. package/dist/editor/types/index.js +11 -0
  154. package/dist/editor/types/index.js.map +1 -0
  155. package/dist/editor/types/testbench.d.ts +150 -0
  156. package/dist/editor/types/testbench.d.ts.map +1 -0
  157. package/dist/editor/types/testbench.js +85 -0
  158. package/dist/editor/types/testbench.js.map +1 -0
  159. package/dist/editor/types/testing.d.ts +88 -0
  160. package/dist/editor/types/testing.d.ts.map +1 -0
  161. package/dist/editor/types/testing.js +6 -0
  162. package/dist/editor/types/testing.js.map +1 -0
  163. package/dist/editor/types/ui-model.d.ts +68 -0
  164. package/dist/editor/types/ui-model.d.ts.map +1 -0
  165. package/dist/editor/types/ui-model.js +66 -0
  166. package/dist/editor/types/ui-model.js.map +1 -0
  167. package/dist/editor/types/ui.d.ts +33 -0
  168. package/dist/editor/types/ui.d.ts.map +1 -0
  169. package/dist/editor/types/ui.js +8 -0
  170. package/dist/editor/types/ui.js.map +1 -0
  171. package/dist/editor/types/visual.d.ts +45 -0
  172. package/dist/editor/types/visual.d.ts.map +1 -0
  173. package/dist/editor/types/visual.js +23 -0
  174. package/dist/editor/types/visual.js.map +1 -0
  175. package/dist/editor/utils/index.d.ts +5 -0
  176. package/dist/editor/utils/index.d.ts.map +1 -0
  177. package/dist/editor/utils/index.js +6 -0
  178. package/dist/editor/utils/index.js.map +1 -0
  179. package/dist/index.d.ts +11 -0
  180. package/dist/index.d.ts.map +1 -0
  181. package/dist/index.js +12 -0
  182. package/dist/index.js.map +1 -0
  183. package/dist/lib/utils.d.ts +3 -0
  184. package/dist/lib/utils.d.ts.map +1 -0
  185. package/dist/lib/utils.js +6 -0
  186. package/dist/lib/utils.js.map +1 -0
  187. package/dist/nodes/BaseNode.d.ts +20 -0
  188. package/dist/nodes/BaseNode.d.ts.map +1 -0
  189. package/dist/nodes/BaseNode.js +26 -0
  190. package/dist/nodes/BaseNode.js.map +1 -0
  191. package/dist/nodes/CompositeBadge.d.ts +6 -0
  192. package/dist/nodes/CompositeBadge.d.ts.map +1 -0
  193. package/dist/nodes/CompositeBadge.js +10 -0
  194. package/dist/nodes/CompositeBadge.js.map +1 -0
  195. package/dist/nodes/ConsoleNode.d.ts +8 -0
  196. package/dist/nodes/ConsoleNode.d.ts.map +1 -0
  197. package/dist/nodes/ConsoleNode.js +16 -0
  198. package/dist/nodes/ConsoleNode.js.map +1 -0
  199. package/dist/nodes/EmbedConsoleNode.d.ts +8 -0
  200. package/dist/nodes/EmbedConsoleNode.d.ts.map +1 -0
  201. package/dist/nodes/EmbedConsoleNode.js +24 -0
  202. package/dist/nodes/EmbedConsoleNode.js.map +1 -0
  203. package/dist/nodes/EmbedScreenNode.d.ts +8 -0
  204. package/dist/nodes/EmbedScreenNode.d.ts.map +1 -0
  205. package/dist/nodes/EmbedScreenNode.js +24 -0
  206. package/dist/nodes/EmbedScreenNode.js.map +1 -0
  207. package/dist/nodes/EthFrameInputNode.d.ts +8 -0
  208. package/dist/nodes/EthFrameInputNode.d.ts.map +1 -0
  209. package/dist/nodes/EthFrameInputNode.js +14 -0
  210. package/dist/nodes/EthFrameInputNode.js.map +1 -0
  211. package/dist/nodes/InputNode.d.ts +8 -0
  212. package/dist/nodes/InputNode.d.ts.map +1 -0
  213. package/dist/nodes/InputNode.js +57 -0
  214. package/dist/nodes/InputNode.js.map +1 -0
  215. package/dist/nodes/LogicGateNode.d.ts +8 -0
  216. package/dist/nodes/LogicGateNode.d.ts.map +1 -0
  217. package/dist/nodes/LogicGateNode.js +51 -0
  218. package/dist/nodes/LogicGateNode.js.map +1 -0
  219. package/dist/nodes/NicFifoNode.d.ts +8 -0
  220. package/dist/nodes/NicFifoNode.d.ts.map +1 -0
  221. package/dist/nodes/NicFifoNode.js +10 -0
  222. package/dist/nodes/NicFifoNode.js.map +1 -0
  223. package/dist/nodes/NodeData.d.ts +34 -0
  224. package/dist/nodes/NodeData.d.ts.map +1 -0
  225. package/dist/nodes/NodeData.js +2 -0
  226. package/dist/nodes/NodeData.js.map +1 -0
  227. package/dist/nodes/NumericInputNode.d.ts +8 -0
  228. package/dist/nodes/NumericInputNode.d.ts.map +1 -0
  229. package/dist/nodes/NumericInputNode.js +47 -0
  230. package/dist/nodes/NumericInputNode.js.map +1 -0
  231. package/dist/nodes/OutputNode.d.ts +8 -0
  232. package/dist/nodes/OutputNode.d.ts.map +1 -0
  233. package/dist/nodes/OutputNode.js +32 -0
  234. package/dist/nodes/OutputNode.js.map +1 -0
  235. package/dist/nodes/RAMNode.d.ts +8 -0
  236. package/dist/nodes/RAMNode.d.ts.map +1 -0
  237. package/dist/nodes/RAMNode.js +23 -0
  238. package/dist/nodes/RAMNode.js.map +1 -0
  239. package/dist/nodes/ROMNode.d.ts +8 -0
  240. package/dist/nodes/ROMNode.d.ts.map +1 -0
  241. package/dist/nodes/ROMNode.js +23 -0
  242. package/dist/nodes/ROMNode.js.map +1 -0
  243. package/dist/nodes/RV32IInstrMemNode.d.ts +16 -0
  244. package/dist/nodes/RV32IInstrMemNode.d.ts.map +1 -0
  245. package/dist/nodes/RV32IInstrMemNode.js +183 -0
  246. package/dist/nodes/RV32IInstrMemNode.js.map +1 -0
  247. package/dist/nodes/RasterDisplayNode.d.ts +8 -0
  248. package/dist/nodes/RasterDisplayNode.d.ts.map +1 -0
  249. package/dist/nodes/RasterDisplayNode.js +14 -0
  250. package/dist/nodes/RasterDisplayNode.js.map +1 -0
  251. package/dist/nodes/RegisterNode.d.ts +8 -0
  252. package/dist/nodes/RegisterNode.d.ts.map +1 -0
  253. package/dist/nodes/RegisterNode.js +14 -0
  254. package/dist/nodes/RegisterNode.js.map +1 -0
  255. package/dist/nodes/ScreenNode.d.ts +8 -0
  256. package/dist/nodes/ScreenNode.d.ts.map +1 -0
  257. package/dist/nodes/ScreenNode.js +16 -0
  258. package/dist/nodes/ScreenNode.js.map +1 -0
  259. package/dist/nodes/UartTxNode.d.ts +8 -0
  260. package/dist/nodes/UartTxNode.d.ts.map +1 -0
  261. package/dist/nodes/UartTxNode.js +16 -0
  262. package/dist/nodes/UartTxNode.js.map +1 -0
  263. package/dist/nodes/index.d.ts +27 -0
  264. package/dist/nodes/index.d.ts.map +1 -0
  265. package/dist/nodes/index.js +30 -0
  266. package/dist/nodes/index.js.map +1 -0
  267. package/dist/primitives/button.d.ts +12 -0
  268. package/dist/primitives/button.d.ts.map +1 -0
  269. package/dist/primitives/button.js +32 -0
  270. package/dist/primitives/button.js.map +1 -0
  271. package/dist/primitives/index.d.ts +4 -0
  272. package/dist/primitives/index.d.ts.map +1 -0
  273. package/dist/primitives/index.js +4 -0
  274. package/dist/primitives/index.js.map +1 -0
  275. package/dist/primitives/sheet.d.ts +15 -0
  276. package/dist/primitives/sheet.d.ts.map +1 -0
  277. package/dist/primitives/sheet.js +40 -0
  278. package/dist/primitives/sheet.js.map +1 -0
  279. package/dist/primitives/tooltip.d.ts +8 -0
  280. package/dist/primitives/tooltip.d.ts.map +1 -0
  281. package/dist/primitives/tooltip.js +17 -0
  282. package/dist/primitives/tooltip.js.map +1 -0
  283. package/dist/sandbox/SandboxProvider.d.ts +13 -0
  284. package/dist/sandbox/SandboxProvider.d.ts.map +1 -0
  285. package/dist/sandbox/SandboxProvider.js +34 -0
  286. package/dist/sandbox/SandboxProvider.js.map +1 -0
  287. package/dist/sandbox/index.d.ts +4 -0
  288. package/dist/sandbox/index.d.ts.map +1 -0
  289. package/dist/sandbox/index.js +3 -0
  290. package/dist/sandbox/index.js.map +1 -0
  291. package/dist/sandbox/useSandbox.d.ts +197 -0
  292. package/dist/sandbox/useSandbox.d.ts.map +1 -0
  293. package/dist/sandbox/useSandbox.js +250 -0
  294. package/dist/sandbox/useSandbox.js.map +1 -0
  295. package/dist/share/encode-source.d.ts +13 -0
  296. package/dist/share/encode-source.d.ts.map +1 -0
  297. package/dist/share/encode-source.js +31 -0
  298. package/dist/share/encode-source.js.map +1 -0
  299. package/dist/share/index.d.ts +2 -0
  300. package/dist/share/index.d.ts.map +1 -0
  301. package/dist/share/index.js +2 -0
  302. package/dist/share/index.js.map +1 -0
  303. package/dist/waveform/WaveformViewer.d.ts +30 -0
  304. package/dist/waveform/WaveformViewer.d.ts.map +1 -0
  305. package/dist/waveform/WaveformViewer.js +356 -0
  306. package/dist/waveform/WaveformViewer.js.map +1 -0
  307. package/package.json +110 -0
@@ -0,0 +1,230 @@
1
+ /**
2
+ * Circuit Flattener (IR v0.1)
3
+ *
4
+ * Expands composite components into a flat Circuit containing only primitives.
5
+ * This allows the simulator to work with nested components by flattening the
6
+ * hierarchy into a single level, avoiding recursive evaluation overhead.
7
+ *
8
+ * Key features:
9
+ * - State isolation: Each instance gets unique IDs (componentId__nodeId)
10
+ * - Preserves all port connections through hierarchy
11
+ * - Recursively expands nested composites
12
+ * - Compatible with IR v0.1 Circuit/Node format
13
+ */
14
+ import { useCircuitLibraryStore } from '../../stores/circuit-library-store';
15
+ import { nanoid } from 'nanoid';
16
+ /**
17
+ * Port mapping key format: "nodeId.portName"
18
+ */
19
+ function portMapKey(nodeId, portName) {
20
+ return `${nodeId}.${portName}`;
21
+ }
22
+ /**
23
+ * Flatten a circuit by recursively expanding all composite components into primitives
24
+ */
25
+ export function flattenCircuit(circuit) {
26
+ const library = useCircuitLibraryStore.getState();
27
+ const flatNodes = [];
28
+ const flatConnections = [];
29
+ const nodeMapping = new Map();
30
+ // Port mapping: tracks how ports of composite nodes map to internal primitive ports
31
+ // Format: "nodeId.portName" -> ["expandedNodeId1.portName", "expandedNodeId2.portName", ...]
32
+ // Supports fan-out (one port connecting to multiple internal ports)
33
+ const portMapping = new Map();
34
+ // Known primitive component types (don't need to be expanded)
35
+ const knownPrimitives = new Set([
36
+ 'And', 'Or', 'Not', 'Nand', 'Nor', 'Xor', 'Xnor', 'Buffer',
37
+ 'Switch', 'Button', 'Input', 'Led', 'HexDisplay', 'SevenSegment',
38
+ 'DFlipFlop', 'Register', 'RAM'
39
+ ]);
40
+ // Recursively expand each node
41
+ for (const node of circuit.nodes) {
42
+ // Check if it's a known primitive (don't need library lookup)
43
+ if (knownPrimitives.has(node.componentRef)) {
44
+ flatNodes.push(node);
45
+ nodeMapping.set(node.id, [node.id]);
46
+ continue;
47
+ }
48
+ // Try to resolve from library for user-defined components
49
+ const componentDef = library.resolveCircuit(node.componentRef);
50
+ if (!componentDef) {
51
+ // Unknown component - treat as primitive (fail gracefully)
52
+ console.warn(`[FLATTEN] Component not found: ${node.componentRef}, treating as primitive`);
53
+ flatNodes.push(node);
54
+ nodeMapping.set(node.id, [node.id]);
55
+ continue;
56
+ }
57
+ // If primitive, keep as-is
58
+ if (componentDef.implementation.kind === 'primitive') {
59
+ flatNodes.push(node);
60
+ nodeMapping.set(node.id, [node.id]);
61
+ continue;
62
+ }
63
+ // If composite, expand it
64
+ if (componentDef.implementation.kind === 'composite') {
65
+ const expansionResult = expandCompositeNode(node, componentDef, library.resolveCircuit.bind(library), knownPrimitives);
66
+ flatNodes.push(...expansionResult.nodes);
67
+ nodeMapping.set(node.id, expansionResult.nodes.map(n => n.id));
68
+ // Merge port mappings
69
+ for (const [key, values] of expansionResult.portMapping.entries()) {
70
+ const existing = portMapping.get(key) || [];
71
+ portMapping.set(key, [...existing, ...values]);
72
+ }
73
+ // Add internal connections
74
+ flatConnections.push(...expansionResult.connections);
75
+ }
76
+ }
77
+ // Remap external connections to go through expanded internal nodes
78
+ for (const conn of circuit.connections) {
79
+ const remappedConns = remapConnection(conn, portMapping);
80
+ flatConnections.push(...remappedConns);
81
+ }
82
+ return {
83
+ ...circuit,
84
+ nodes: flatNodes,
85
+ connections: flatConnections,
86
+ nodeMapping,
87
+ };
88
+ }
89
+ function expandCompositeNode(node, componentDef, resolveCircuit, knownPrimitives, visited = new Set()) {
90
+ const nodes = [];
91
+ const connections = [];
92
+ const portMapping = new Map();
93
+ // Create internal nodes with prefixed IDs
94
+ for (const internalNode of componentDef.nodes) {
95
+ const expandedId = `${node.id}__${internalNode.id}`;
96
+ // Check if it's a known primitive
97
+ if (knownPrimitives.has(internalNode.componentRef)) {
98
+ // Primitive node - create expanded version
99
+ const expandedNode = {
100
+ ...internalNode,
101
+ id: expandedId,
102
+ inputs: internalNode.inputs.map(inp => ({
103
+ ...inp,
104
+ id: `${expandedId}.${inp.name}`,
105
+ })),
106
+ outputs: internalNode.outputs.map(out => ({
107
+ ...out,
108
+ id: `${expandedId}.${out.name}`,
109
+ })),
110
+ };
111
+ nodes.push(expandedNode);
112
+ continue;
113
+ }
114
+ // Check if internal node is also composite - recursively expand
115
+ const internalComponentDef = resolveCircuit(internalNode.componentRef);
116
+ if (internalComponentDef?.implementation.kind === 'composite') {
117
+ // Guard against recursive circuit definitions
118
+ if (visited.has(internalNode.componentRef)) {
119
+ console.warn(`[FLATTEN] Recursive circuit reference: ${internalNode.componentRef}, skipping`);
120
+ continue;
121
+ }
122
+ const childVisited = new Set(visited);
123
+ childVisited.add(internalNode.componentRef);
124
+ // Recursively expand nested composite
125
+ const nestedExpansion = expandCompositeNode({ ...internalNode, id: expandedId }, internalComponentDef, resolveCircuit, knownPrimitives, childVisited);
126
+ nodes.push(...nestedExpansion.nodes);
127
+ connections.push(...nestedExpansion.connections);
128
+ // Remap nested port mappings through our prefix
129
+ for (const [key, values] of nestedExpansion.portMapping.entries()) {
130
+ const [keyNodeId, keyPortName] = key.split('.');
131
+ const remappedKey = portMapKey(keyNodeId, keyPortName);
132
+ const existing = portMapping.get(remappedKey) || [];
133
+ portMapping.set(remappedKey, [...existing, ...values]);
134
+ }
135
+ }
136
+ else {
137
+ // Unknown or primitive node - create expanded version
138
+ const expandedNode = {
139
+ ...internalNode,
140
+ id: expandedId,
141
+ inputs: internalNode.inputs.map(inp => ({
142
+ ...inp,
143
+ id: `${expandedId}.${inp.name}`,
144
+ })),
145
+ outputs: internalNode.outputs.map(out => ({
146
+ ...out,
147
+ id: `${expandedId}.${out.name}`,
148
+ })),
149
+ };
150
+ nodes.push(expandedNode);
151
+ }
152
+ }
153
+ // Process internal connections and build port mappings
154
+ for (const conn of componentDef.connections) {
155
+ const sourceNodeId = conn.source.nodeId === '' ? node.id : `${node.id}__${conn.source.nodeId}`;
156
+ const targetNodeId = conn.target.nodeId === '' ? node.id : `${node.id}__${conn.target.nodeId}`;
157
+ // If source is circuit-level input (empty nodeId), create port mapping
158
+ if (conn.source.nodeId === '') {
159
+ // Map: original node's input port -> internal node's input port
160
+ const originalInputKey = portMapKey(node.id, conn.source.portName);
161
+ const internalTargetPath = {
162
+ nodeId: targetNodeId,
163
+ portName: conn.target.portName,
164
+ };
165
+ const existing = portMapping.get(originalInputKey) || [];
166
+ portMapping.set(originalInputKey, [...existing, internalTargetPath]);
167
+ }
168
+ // If target is circuit-level output (empty nodeId), create port mapping
169
+ if (conn.target.nodeId === '') {
170
+ // Map: original node's output port -> internal node's output port
171
+ const originalOutputKey = portMapKey(node.id, conn.target.portName);
172
+ const internalSourcePath = {
173
+ nodeId: sourceNodeId,
174
+ portName: conn.source.portName,
175
+ };
176
+ const existing = portMapping.get(originalOutputKey) || [];
177
+ portMapping.set(originalOutputKey, [...existing, internalSourcePath]);
178
+ }
179
+ // Only create internal connection if both sides are internal nodes
180
+ if (conn.source.nodeId !== '' && conn.target.nodeId !== '') {
181
+ const expandedConn = {
182
+ ...conn,
183
+ id: nanoid(),
184
+ source: { nodeId: sourceNodeId, portName: conn.source.portName },
185
+ target: { nodeId: targetNodeId, portName: conn.target.portName },
186
+ };
187
+ connections.push(expandedConn);
188
+ }
189
+ }
190
+ return { nodes, connections, portMapping };
191
+ }
192
+ /**
193
+ * Remap a connection through port mappings (for composite component ports)
194
+ * Returns an array to handle fan-out (one source to multiple targets)
195
+ */
196
+ function remapConnection(conn, portMapping) {
197
+ // Try to remap source
198
+ const sourceKey = portMapKey(conn.source.nodeId, conn.source.portName);
199
+ const remappedSources = portMapping.get(sourceKey) || [conn.source];
200
+ // Try to remap target
201
+ const targetKey = portMapKey(conn.target.nodeId, conn.target.portName);
202
+ const remappedTargets = portMapping.get(targetKey) || [conn.target];
203
+ // Create connection for each combination of source/target (handles fan-out)
204
+ const connections = [];
205
+ for (const source of remappedSources) {
206
+ for (const target of remappedTargets) {
207
+ connections.push({
208
+ ...conn,
209
+ id: nanoid(),
210
+ source,
211
+ target,
212
+ });
213
+ }
214
+ }
215
+ return connections;
216
+ }
217
+ /**
218
+ * Check if a circuit contains any composite components
219
+ */
220
+ export function hasCompositeComponents(circuit) {
221
+ const library = useCircuitLibraryStore.getState();
222
+ for (const node of circuit.nodes) {
223
+ const componentDef = library.resolveCircuit(node.componentRef);
224
+ if (componentDef?.implementation.kind === 'composite') {
225
+ return true;
226
+ }
227
+ }
228
+ return false;
229
+ }
230
+ //# sourceMappingURL=circuit-flattener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circuit-flattener.js","sourceRoot":"","sources":["../../../../src/editor/lib/utils/circuit-flattener.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAUhC;;GAEG;AACH,SAAS,UAAU,CAAC,MAAc,EAAE,QAAgB;IAClD,OAAO,GAAG,MAAM,IAAI,QAAQ,EAAE,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,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,CAAC,YAAY,CAAC,CAAC;QAC/D,IAAI,YAAY,EAAE,cAAc,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACtD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Circuit Utility Functions
3
+ *
4
+ * Helper functions for analyzing circuit structure and properties.
5
+ */
6
+ import type { Component } from '../../types';
7
+ import type { Circuit } from '../../types/circuit';
8
+ /**
9
+ * Recursively checks if a circuit or any of its nested circuits
10
+ * contains sequential primitives (D_FLIP_FLOP, REGISTER, RAM).
11
+ *
12
+ * @param componentType - The type/name of the circuit to check
13
+ * @param components - The current circuit's component instances
14
+ * @param resolveCircuit - Function to resolve circuit definitions from the library
15
+ * @param visited - Set of already-visited circuit types to prevent infinite recursion
16
+ * @returns true if the circuit or any nested circuit is sequential
17
+ */
18
+ export declare function containsSequentialCircuit(componentType: string, components: Record<string, Component>, resolveCircuit: (name: string) => Circuit | undefined, visited?: Set<string>): boolean;
19
+ /**
20
+ * Checks if the current circuit has any sequential circuits,
21
+ * including those nested inside composite circuits.
22
+ *
23
+ * @param components - The current circuit's component instances
24
+ * @param resolveCircuit - Function to resolve circuit definitions from the library
25
+ * @returns true if any circuit in the hierarchy is or contains sequential primitives
26
+ */
27
+ export declare function hasSequentialCircuits(components: Record<string, Component>, resolveCircuit: (name: string) => Circuit | undefined): boolean;
28
+ //# sourceMappingURL=component-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-utils.d.ts","sourceRoot":"","sources":["../../../../src/editor/lib/utils/component-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAWnD;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EACrC,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,SAAS,EACrD,OAAO,GAAE,GAAG,CAAC,MAAM,CAAa,GAC/B,OAAO,CAoCT;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EACrC,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,SAAS,GACpD,OAAO,CAOT"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Circuit Utility Functions
3
+ *
4
+ * Helper functions for analyzing circuit structure and properties.
5
+ */
6
+ import { isSequentialComponent } from '../../types';
7
+ /**
8
+ * Check if a circuit type is sequential.
9
+ * Delegates entirely to isSequentialComponent (data-driven via clock ports).
10
+ */
11
+ function isSequentialPrimitive(componentType) {
12
+ return isSequentialComponent(componentType);
13
+ }
14
+ /**
15
+ * Recursively checks if a circuit or any of its nested circuits
16
+ * contains sequential primitives (D_FLIP_FLOP, REGISTER, RAM).
17
+ *
18
+ * @param componentType - The type/name of the circuit to check
19
+ * @param components - The current circuit's component instances
20
+ * @param resolveCircuit - Function to resolve circuit definitions from the library
21
+ * @param visited - Set of already-visited circuit types to prevent infinite recursion
22
+ * @returns true if the circuit or any nested circuit is sequential
23
+ */
24
+ export function containsSequentialCircuit(componentType, components, resolveCircuit, visited = new Set()) {
25
+ // Prevent infinite recursion for circular references
26
+ if (visited.has(componentType)) {
27
+ return false;
28
+ }
29
+ visited.add(componentType);
30
+ // Check if this is a sequential primitive (handles both old and new naming)
31
+ if (isSequentialPrimitive(componentType)) {
32
+ return true;
33
+ }
34
+ // Resolve the circuit definition from the library
35
+ const circuit = resolveCircuit(componentType);
36
+ if (!circuit) {
37
+ // Circuit not found in library, assume non-sequential
38
+ return false;
39
+ }
40
+ // If this is a primitive implementation, it's not sequential (we already checked above)
41
+ if (circuit.implementation.kind === 'primitive') {
42
+ return false;
43
+ }
44
+ // For composite circuits, recursively check all internal nodes
45
+ if (circuit.implementation.kind === 'composite') {
46
+ for (const node of circuit.nodes) {
47
+ // Recursively check if this node's circuit is sequential
48
+ if (containsSequentialCircuit(node.componentRef, components, resolveCircuit, visited)) {
49
+ return true;
50
+ }
51
+ }
52
+ }
53
+ // No sequential circuits found
54
+ return false;
55
+ }
56
+ /**
57
+ * Checks if the current circuit has any sequential circuits,
58
+ * including those nested inside composite circuits.
59
+ *
60
+ * @param components - The current circuit's component instances
61
+ * @param resolveCircuit - Function to resolve circuit definitions from the library
62
+ * @returns true if any circuit in the hierarchy is or contains sequential primitives
63
+ */
64
+ export function hasSequentialCircuits(components, resolveCircuit) {
65
+ for (const component of Object.values(components)) {
66
+ if (containsSequentialCircuit(component.type, components, resolveCircuit)) {
67
+ return true;
68
+ }
69
+ }
70
+ return false;
71
+ }
72
+ //# sourceMappingURL=component-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-utils.js","sourceRoot":"","sources":["../../../../src/editor/lib/utils/component-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;GAGG;AACH,SAAS,qBAAqB,CAAC,aAAqB;IAClD,OAAO,qBAAqB,CAAC,aAAa,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,yBAAyB,CACvC,aAAqB,EACrB,UAAqC,EACrC,cAAqD,EACrD,UAAuB,IAAI,GAAG,EAAE;IAEhC,qDAAqD;IACrD,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAE3B,4EAA4E;IAC5E,IAAI,qBAAqB,CAAC,aAAa,CAAC,EAAE,CAAC;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kDAAkD;IAClD,MAAM,OAAO,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;IAC9C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,sDAAsD;QACtD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,wFAAwF;IACxF,IAAI,OAAO,CAAC,cAAc,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,+DAA+D;IAC/D,IAAI,OAAO,CAAC,cAAc,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAChD,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YACjC,yDAAyD;YACzD,IAAI,yBAAyB,CAAC,IAAI,CAAC,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,CAAC;gBACtF,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;IAED,+BAA+B;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAAqC,EACrC,cAAqD;IAErD,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QAClD,IAAI,yBAAyB,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,cAAc,CAAC,EAAE,CAAC;YAC1E,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './circuit-flattener';
2
+ export * from './component-utils';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/editor/lib/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './circuit-flattener';
2
+ export * from './component-utils';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/editor/lib/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './vcd-generator';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/editor/lib/visualization/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './vcd-generator';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/editor/lib/visualization/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * VCD (Value Change Dump) Generator
3
+ *
4
+ * Generates industry-standard VCD waveform files from testbench traces.
5
+ * VCD files can be viewed in GTKWave, ModelSim, Vivado, and other tools.
6
+ *
7
+ * VCD Format Specification:
8
+ * - Header: version, date, timescale, scope, variable declarations
9
+ * - Body: timestamp and value change records
10
+ * - Compact: Only emit value changes, not every cycle
11
+ *
12
+ * References:
13
+ * - IEEE 1364-2001 VCD Format
14
+ * - GTKWave documentation
15
+ */
16
+ import { CaptureData } from '../../types/testbench';
17
+ /**
18
+ * Generate VCD file content from capture data
19
+ *
20
+ * @param captureData - Trace data collected during testbench run
21
+ * @param timescale - Time unit (default: "1 ns" - 1 nanosecond per cycle)
22
+ * @returns VCD file content as string
23
+ */
24
+ export declare function generateVCD(captureData: CaptureData, timescale?: string): string;
25
+ /**
26
+ * Write VCD to file (triggers browser download)
27
+ */
28
+ export declare function writeVCDToFile(captureData: CaptureData, filename: string, timescale?: string): void;
29
+ /**
30
+ * Trigger VCD file download in browser
31
+ */
32
+ export declare function downloadVCD(content: string, filename: string): void;
33
+ /**
34
+ * Parse VCD header to extract signal information
35
+ * (Useful for testing and verification)
36
+ */
37
+ export interface VCDSignalInfo {
38
+ id: string;
39
+ name: string;
40
+ width: number;
41
+ type: string;
42
+ }
43
+ /**
44
+ * Parse VCD file header
45
+ */
46
+ export declare function parseVCDHeader(vcdContent: string): {
47
+ timescale: string;
48
+ signals: VCDSignalInfo[];
49
+ };
50
+ /**
51
+ * Get VCD file statistics
52
+ */
53
+ export declare function getVCDStats(captureData: CaptureData): {
54
+ signalCount: number;
55
+ totalCycles: number;
56
+ totalChanges: number;
57
+ fileSize: number;
58
+ };
59
+ /**
60
+ * Format VCD stats for display
61
+ */
62
+ export declare function formatVCDStats(stats: ReturnType<typeof getVCDStats>): string;
63
+ //# sourceMappingURL=vcd-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vcd-generator.d.ts","sourceRoot":"","sources":["../../../../src/editor/lib/visualization/vcd-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,WAAW,EAAwB,MAAM,uBAAuB,CAAC;AAO1E;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,WAAW,EAAE,WAAW,EACxB,SAAS,SAAS,GACjB,MAAM,CAeR;AAwKD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,SAAS,GACjB,IAAI,CAGN;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAUnE;AAMD;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B,CAqCA;AAMD;;GAEG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,WAAW,GAAG;IACrD,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAoBA;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,GAAG,MAAM,CAQ5E"}