@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 @@
1
+ {"version":3,"file":"tooltip.js","sourceRoot":"","sources":["../../src/primitives/tooltip.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAEtD,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAA;AAEjC,SAAS,eAAe,CAAC,EACvB,aAAa,GAAG,CAAC,EACjB,GAAG,KAAK,EAC+C;IACvD,OAAO,CACL,KAAC,gBAAgB,CAAC,QAAQ,iBACd,kBAAkB,EAC5B,aAAa,EAAE,aAAa,KACxB,KAAK,GACT,CACH,CAAA;AACH,CAAC;AAED,SAAS,OAAO,CAAC,EACf,GAAG,KAAK,EAC2C;IACnD,OAAO,KAAC,gBAAgB,CAAC,IAAI,iBAAW,SAAS,KAAK,KAAK,GAAI,CAAA;AACjE,CAAC;AAED,SAAS,cAAc,CAAC,EACtB,GAAG,KAAK,EAC8C;IACtD,OAAO,KAAC,gBAAgB,CAAC,OAAO,iBAAW,iBAAiB,KAAK,KAAK,GAAI,CAAA;AAC5E,CAAC;AAED,SAAS,cAAc,CAAC,EACtB,SAAS,EACT,UAAU,GAAG,CAAC,EACd,QAAQ,EACR,GAAG,KAAK,EAC8C;IACtD,OAAO,CACL,KAAC,gBAAgB,CAAC,MAAM,cACtB,MAAC,gBAAgB,CAAC,OAAO,iBACb,iBAAiB,EAC3B,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,EAAE,CACX,maAAma,EACna,SAAS,CACV,KACG,KAAK,aAER,QAAQ,EACT,KAAC,gBAAgB,CAAC,KAAK,IAAC,SAAS,EAAC,oGAAoG,GAAG,IAChH,GACH,CAC3B,CAAA;AACH,CAAC;AAED,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,CAAA"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * SandboxProvider — singleton sandbox context
3
+ *
4
+ * Wraps the app so all consumers share a single hidden iframe.
5
+ * Use `useSandboxContext()` to get the SandboxHandle.
6
+ */
7
+ import { type ReactNode } from 'react';
8
+ import { type SandboxHandle } from './useSandbox.js';
9
+ export declare function SandboxProvider({ children }: {
10
+ children: ReactNode;
11
+ }): import("react/jsx-runtime").JSX.Element;
12
+ export declare function useSandboxContext(): SandboxHandle;
13
+ //# sourceMappingURL=SandboxProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SandboxProvider.d.ts","sourceRoot":"","sources":["../../src/sandbox/SandboxProvider.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAc,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIjE,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,2CAOpE;AAmBD,wBAAgB,iBAAiB,IAAI,aAAa,CAEjD"}
@@ -0,0 +1,34 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * SandboxProvider — singleton sandbox context
4
+ *
5
+ * Wraps the app so all consumers share a single hidden iframe.
6
+ * Use `useSandboxContext()` to get the SandboxHandle.
7
+ */
8
+ import { createContext, useContext } from 'react';
9
+ import { useSandbox } from './useSandbox.js';
10
+ const SandboxContext = createContext(null);
11
+ export function SandboxProvider({ children }) {
12
+ const sandbox = useSandbox();
13
+ return (_jsx(SandboxContext.Provider, { value: sandbox, children: children }));
14
+ }
15
+ // No-op handle returned before the sandbox iframe is ready (SSR / pre-mount)
16
+ const NULL_HANDLE = {
17
+ compile: async () => ({ type: 'error', error: 'Sandbox not ready' }),
18
+ compileIR: async () => ({ type: 'error', error: 'Sandbox not ready' }),
19
+ tick: async () => ({ type: 'error', error: 'Sandbox not ready' }),
20
+ tickN: async () => ({ type: 'error', error: 'Sandbox not ready' }),
21
+ scanPort: async () => ({ type: 'error', error: 'Sandbox not ready' }),
22
+ simulate: async () => ({ type: 'error', error: 'Sandbox not ready' }),
23
+ reset: async () => ({ type: 'error', error: 'Sandbox not ready' }),
24
+ setNode: async () => ({ type: 'error', error: 'Sandbox not ready' }),
25
+ snapshot: async () => ({ type: 'error', error: 'Sandbox not ready' }),
26
+ restore: async () => ({ type: 'error', error: 'Sandbox not ready' }),
27
+ pruneSnapshots: async () => ({ type: 'error', error: 'Sandbox not ready' }),
28
+ dispose: async () => { },
29
+ isReady: () => false,
30
+ };
31
+ export function useSandboxContext() {
32
+ return useContext(SandboxContext) ?? NULL_HANDLE;
33
+ }
34
+ //# sourceMappingURL=SandboxProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SandboxProvider.js","sourceRoot":"","sources":["../../src/sandbox/SandboxProvider.tsx"],"names":[],"mappings":";AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAkB,MAAM,OAAO,CAAC;AAClE,OAAO,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E,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC;IACrE,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC;IACpE,cAAc,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC;IAC3E,OAAO,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;IACvB,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK;CACrB,CAAC;AAEF,MAAM,UAAU,iBAAiB;IAC/B,OAAO,UAAU,CAAC,cAAc,CAAC,IAAI,WAAW,CAAC;AACnD,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { useSandbox } from './useSandbox.js';
2
+ export { SandboxProvider, useSandboxContext } from './SandboxProvider.js';
3
+ export type { SandboxHandle, CompileResult, CompileIRResult, TickResult, SimulateResult, ResetResult, SetNodeResult, SandboxError, EvalSource, SimSlot, } from './useSandbox.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC1E,YAAY,EACV,aAAa,EACb,aAAa,EACb,eAAe,EACf,UAAU,EACV,cAAc,EACd,WAAW,EACX,aAAa,EACb,YAAY,EACZ,UAAU,EACV,OAAO,GACR,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { useSandbox } from './useSandbox.js';
2
+ export { SandboxProvider, useSandboxContext } from './SandboxProvider.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,197 @@
1
+ /**
2
+ * useSandbox — iframe execution sandbox manager (HOST side of the bridge).
3
+ *
4
+ * The iframe-side counterpart lives at `apps/sandbox/src/main.ts`. Most
5
+ * consumers should NOT call this directly — use `useCircuitSimulator` from
6
+ * `@simten/embed`, which composes this transport with circuit-level concerns.
7
+ * See `apps/web/content/docs/architecture.mdx` → "Runtime topology".
8
+ *
9
+ * Creates and manages a hidden iframe at SANDBOX_ORIGIN with
10
+ * sandbox="allow-scripts". All circuit compilation and simulation
11
+ * runs inside the sandbox — never in the main frame.
12
+ *
13
+ * Security guarantees:
14
+ * - Separate origin → browser enforces isolation (no access to
15
+ * main-frame cookies, localStorage, or DOM)
16
+ * - sandbox="allow-scripts" blocks ALL network at the browser
17
+ * kernel level (no fetch, XHR, WebSocket possible)
18
+ * - postMessage boundary: only plain JSON crosses. No functions,
19
+ * no Maps, no class instances.
20
+ * - Infinite loops: 5s timeout kills and recreates the iframe;
21
+ * main UI is unaffected.
22
+ *
23
+ * Usage:
24
+ * const sandbox = useSandbox();
25
+ * const result = await sandbox.compile(source);
26
+ * const tick = await sandbox.tick({ a: true });
27
+ */
28
+ import type { Circuit } from '@simten/core';
29
+ import type { RLEValue } from '@simten/core/api';
30
+ /**
31
+ * State of nodes on a peripheral's bus — exposed across the sandbox boundary
32
+ * so the UI can render displays, consoles, NIC FIFOs, etc.
33
+ *
34
+ * Values are whatever the simulator stores for each node: number | boolean |
35
+ * Map<number, number> | string. The sandbox only snapshots state for nodes
36
+ * tagged (via circuit `meta.synthesizable: false`) or wired directly to such
37
+ * a node — the sim analog of memory-mapped I/O.
38
+ */
39
+ export type PeripheralState = Record<string, unknown>;
40
+ export interface CompileResult {
41
+ circuits: Circuit[];
42
+ libraryCircuits: Circuit[];
43
+ portValues: Record<string, number | boolean>;
44
+ peripheralState?: PeripheralState;
45
+ }
46
+ export interface TickResult {
47
+ portValues: Record<string, number | boolean>;
48
+ cycle: number;
49
+ peripheralState?: PeripheralState;
50
+ /** Snapshot id returned when the tick was requested with `{ snapshot: true }`. */
51
+ snapshotId?: number;
52
+ }
53
+ export interface SimulateResult {
54
+ circuitName: string;
55
+ signals: Record<string, RLEValue[]>;
56
+ vcd: string;
57
+ ticks: number;
58
+ steadyStateAt?: number;
59
+ }
60
+ export interface ResetResult {
61
+ portValues: Record<string, number | boolean>;
62
+ peripheralState?: PeripheralState;
63
+ }
64
+ export interface SetNodeResult {
65
+ portValues: Record<string, number | boolean>;
66
+ peripheralState?: PeripheralState;
67
+ /** Snapshot id returned when `{ snapshot: true }` was passed. */
68
+ snapshotId?: number;
69
+ }
70
+ export interface SnapshotResult {
71
+ /** Undefined for combinational-only circuits (nothing to snapshot). */
72
+ snapshotId?: number;
73
+ }
74
+ export interface RestoreResult {
75
+ portValues: Record<string, number | boolean>;
76
+ cycle: number;
77
+ peripheralState?: PeripheralState;
78
+ }
79
+ export interface SandboxError {
80
+ type: 'error';
81
+ error: string;
82
+ }
83
+ export type SandboxResult = ({
84
+ type: 'compiled';
85
+ } & CompileResult) | ({
86
+ type: 'compiled-ir';
87
+ } & {
88
+ portValues: Record<string, number | boolean>;
89
+ peripheralState?: PeripheralState;
90
+ snapshotId?: number;
91
+ }) | ({
92
+ type: 'ticked';
93
+ } & TickResult) | ({
94
+ type: 'ticked-n';
95
+ } & TickResult) | ({
96
+ type: 'scanned-port';
97
+ } & {
98
+ values: number[];
99
+ }) | ({
100
+ type: 'simulated';
101
+ } & SimulateResult) | ({
102
+ type: 'reset';
103
+ } & ResetResult) | ({
104
+ type: 'set-node';
105
+ } & SetNodeResult) | ({
106
+ type: 'snapshot';
107
+ } & SnapshotResult) | ({
108
+ type: 'restored';
109
+ } & RestoreResult) | ({
110
+ type: 'pruned';
111
+ } & {}) | ({
112
+ type: 'disposed';
113
+ } & {}) | ({
114
+ type: 'error';
115
+ } & SandboxError);
116
+ export interface CompileIRResult {
117
+ portValues: Record<string, number | boolean>;
118
+ peripheralState?: PeripheralState;
119
+ /** Snapshot of the initial state, returned when `{ snapshot: true }` was requested. */
120
+ snapshotId?: number;
121
+ }
122
+ /** Serialized eval entry used to transfer eval functions to the sandbox */
123
+ export interface EvalSource {
124
+ evalSource: string;
125
+ onTickSource?: string;
126
+ inputNames: string[];
127
+ outputNames: string[];
128
+ stateKeys?: string[];
129
+ }
130
+ /** Slot IDs are arbitrary strings — use any unique identifier per simulation context. */
131
+ export type SimSlot = string;
132
+ export interface SandboxHandle {
133
+ compile(source: string, slot?: SimSlot): Promise<CompileResult | SandboxError>;
134
+ /**
135
+ * Compile from Circuit IR (e.g. auto-harnessed circuit).
136
+ * Optional evalSources map transfers eval functions from the caller's context.
137
+ * If omitted, inherits eval functions from any previously-compiled slot.
138
+ * Pass `{ snapshot: true }` to capture the initial state for time-travel.
139
+ */
140
+ compileIR(circuit: any, libraryCircuits: any[], slot: SimSlot, options?: {
141
+ evalSources?: Record<string, EvalSource>;
142
+ snapshot?: boolean;
143
+ }): Promise<CompileIRResult | SandboxError>;
144
+ /** Pass `{ snapshot: true }` to also capture a post-tick snapshot for time-travel. */
145
+ tick(inputs?: Record<string, number | boolean>, slot?: SimSlot, options?: {
146
+ snapshot?: boolean;
147
+ }): Promise<TickResult | SandboxError>;
148
+ /**
149
+ * Advance the simulator by N ticks in a single round-trip. Returns final
150
+ * port values + one peripheral-state snapshot. Use for demos that need
151
+ * many ticks per frame (raster displays, batched compute).
152
+ * Pass `{ snapshot: true }` to capture a post-tickN snapshot.
153
+ */
154
+ tickN(n: number, inputs?: Record<string, number | boolean>, slot?: SimSlot, options?: {
155
+ snapshot?: boolean;
156
+ }): Promise<TickResult | SandboxError>;
157
+ /**
158
+ * Combinationally scan a debug address input across 0..count-1, sampling
159
+ * a value output port after each setting. Returns the array in one
160
+ * round-trip. Clock is NOT advanced. Models JTAG-style halted-mode reads.
161
+ */
162
+ scanPort(addrNodeId: string, valuePortKey: string, count: number, slot?: SimSlot): Promise<{
163
+ values: number[];
164
+ } | SandboxError>;
165
+ simulate(params: {
166
+ source?: string;
167
+ ticks: number;
168
+ inputs?: Record<string, number | boolean>;
169
+ memoryData?: Record<string, Record<string, number>>;
170
+ slot?: SimSlot;
171
+ }): Promise<SimulateResult | SandboxError>;
172
+ reset(slot?: SimSlot): Promise<ResetResult | SandboxError>;
173
+ setNode(nodeId: string, value: number | boolean | Map<number, number>, slot?: SimSlot, options?: {
174
+ snapshot?: boolean;
175
+ }): Promise<SetNodeResult | SandboxError>;
176
+ /**
177
+ * Take a snapshot of the current simulator state. Returns an opaque
178
+ * snapshotId the host can later pass to `restore()`. For combinational-only
179
+ * circuits returns `{ snapshotId: undefined }` — nothing to save.
180
+ */
181
+ snapshot(slot?: SimSlot): Promise<SnapshotResult | SandboxError>;
182
+ /** Restore the simulator to a previously-captured snapshot. */
183
+ restore(snapshotId: number, slot?: SimSlot): Promise<RestoreResult | SandboxError>;
184
+ /**
185
+ * Drop all snapshots with id <= keepAfterId. Called by the host when its
186
+ * local history cap is exceeded, so old snapshots get garbage-collected
187
+ * inside the sandbox. Silently succeeds if the slot has no snapshots.
188
+ */
189
+ pruneSnapshots(keepAfterId: number, slot?: SimSlot): Promise<{
190
+ type: 'pruned';
191
+ } | SandboxError>;
192
+ /** Free a slot's simulator + library when no longer needed (e.g. embed unmount). */
193
+ dispose(slot: SimSlot): Promise<void>;
194
+ isReady(): boolean;
195
+ }
196
+ export declare function useSandbox(): SandboxHandle;
197
+ //# sourceMappingURL=useSandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSandbox.d.ts","sourceRoot":"","sources":["../../src/sandbox/useSandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,O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AY,CAAC,CAAC;IAChK;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,GAAG,YAAY,CAAC,CAAC;IACjE,+DAA+D;IAC/D,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,GAAG,YAAY,CAAC,CAAC;IACnF;;;;OAIG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,QAAQ,CAAA;KAAE,GAAG,YAAY,CAAC,CAAC;IAChG,oFAAoF;IACpF,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,OAAO,IAAI,OAAO,CAAC;CACpB;AAED,wBAAgB,UAAU,IAAI,aAAa,CAgP1C"}
@@ -0,0 +1,250 @@
1
+ /**
2
+ * useSandbox — iframe execution sandbox manager (HOST side of the bridge).
3
+ *
4
+ * The iframe-side counterpart lives at `apps/sandbox/src/main.ts`. Most
5
+ * consumers should NOT call this directly — use `useCircuitSimulator` from
6
+ * `@simten/embed`, which composes this transport with circuit-level concerns.
7
+ * See `apps/web/content/docs/architecture.mdx` → "Runtime topology".
8
+ *
9
+ * Creates and manages a hidden iframe at SANDBOX_ORIGIN with
10
+ * sandbox="allow-scripts". All circuit compilation and simulation
11
+ * runs inside the sandbox — never in the main frame.
12
+ *
13
+ * Security guarantees:
14
+ * - Separate origin → browser enforces isolation (no access to
15
+ * main-frame cookies, localStorage, or DOM)
16
+ * - sandbox="allow-scripts" blocks ALL network at the browser
17
+ * kernel level (no fetch, XHR, WebSocket possible)
18
+ * - postMessage boundary: only plain JSON crosses. No functions,
19
+ * no Maps, no class instances.
20
+ * - Infinite loops: 5s timeout kills and recreates the iframe;
21
+ * main UI is unaffected.
22
+ *
23
+ * Usage:
24
+ * const sandbox = useSandbox();
25
+ * const result = await sandbox.compile(source);
26
+ * const tick = await sandbox.tick({ a: true });
27
+ */
28
+ import { useRef, useEffect, useCallback } from 'react';
29
+ // ============================================================================
30
+ // Config
31
+ // ============================================================================
32
+ // Sandbox origin: defaults work for normal dev (localhost:3002) and production
33
+ // (sandbox.simten.dev). VITE_SANDBOX_ORIGIN is an optional escape hatch for
34
+ // unusual setups (e.g. pointing local dev at a staging sandbox).
35
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
+ const env = typeof import.meta !== 'undefined' ? import.meta.env : undefined;
37
+ const SANDBOX_ORIGIN = env?.VITE_SANDBOX_ORIGIN
38
+ || (env?.PROD ? 'https://sandbox.simten.dev' : 'http://localhost:3002');
39
+ function createIframe(state, container, handleMessage, onCrash) {
40
+ // Remove old iframe if any
41
+ if (state.iframe) {
42
+ state.iframe.remove();
43
+ state.iframe = null;
44
+ state.ready = false;
45
+ }
46
+ const iframe = document.createElement('iframe');
47
+ iframe.src = SANDBOX_ORIGIN;
48
+ // allow-same-origin: keeps iframe's declared origin (sandbox.simten.dev / localhost:3002)
49
+ // so the browser can load scripts and Vite dev server works.
50
+ // Origin isolation still holds: the main app (simten.dev / localhost:3001) is a
51
+ // different origin, so the iframe cannot access the main app's cookies or localStorage.
52
+ iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
53
+ iframe.style.cssText = 'display:none;width:0;height:0;position:absolute;';
54
+ iframe.setAttribute('aria-hidden', 'true');
55
+ // Recover from catastrophic iframe crash (e.g. OOM, failed load)
56
+ iframe.onerror = onCrash;
57
+ container.appendChild(iframe);
58
+ state.iframe = iframe;
59
+ state.ready = false;
60
+ window.addEventListener('message', handleMessage);
61
+ return iframe;
62
+ }
63
+ function nextId(state) {
64
+ return `sb-${++state.idCounter}`;
65
+ }
66
+ export function useSandbox() {
67
+ const stateRef = useRef({
68
+ iframe: null,
69
+ ready: false,
70
+ pending: new Map(),
71
+ readyQueue: [],
72
+ idCounter: 0,
73
+ });
74
+ // Container div injected into document body (avoids React tree)
75
+ const containerRef = useRef(null);
76
+ const handleMessageRef = useRef(() => { });
77
+ const recreateIframe = useCallback(() => {
78
+ const state = stateRef.current;
79
+ const container = containerRef.current;
80
+ if (!container)
81
+ return;
82
+ // Fail all pending promises — sandbox crashed, no response coming
83
+ for (const [, resolve] of state.pending) {
84
+ resolve({ type: 'error', error: 'Sandbox restarted (crash)' });
85
+ }
86
+ state.pending.clear();
87
+ state.readyQueue = [];
88
+ window.removeEventListener('message', handleMessageRef.current);
89
+ createIframe(state, container, handleMessageRef.current, recreateIframeRef.current);
90
+ }, []);
91
+ const handleMessage = useCallback((event) => {
92
+ if (event.origin !== SANDBOX_ORIGIN)
93
+ return;
94
+ const state = stateRef.current;
95
+ const data = event.data;
96
+ if (data.type === 'ready') {
97
+ state.ready = true;
98
+ // Flush queued sends
99
+ for (const fn of state.readyQueue)
100
+ fn();
101
+ state.readyQueue = [];
102
+ return;
103
+ }
104
+ if (!data.id)
105
+ return;
106
+ const resolve = state.pending.get(data.id);
107
+ if (!resolve)
108
+ return;
109
+ state.pending.delete(data.id);
110
+ resolve(data);
111
+ }, []);
112
+ // Keep refs in sync
113
+ handleMessageRef.current = handleMessage;
114
+ const recreateIframeRef = useRef(recreateIframe);
115
+ recreateIframeRef.current = recreateIframe;
116
+ useEffect(() => {
117
+ const container = document.createElement('div');
118
+ container.style.cssText = 'position:absolute;left:-9999px;top:-9999px;';
119
+ document.body.appendChild(container);
120
+ containerRef.current = container;
121
+ const state = stateRef.current;
122
+ createIframe(state, container, handleMessage, recreateIframe);
123
+ return () => {
124
+ window.removeEventListener('message', handleMessage);
125
+ container.remove();
126
+ containerRef.current = null;
127
+ };
128
+ }, [handleMessage]);
129
+ // No timeout here — the sandbox's own 5s worker timeout always sends back an
130
+ // error response if user code hangs. recreateIframe() is only called by the
131
+ // iframe's onerror handler (catastrophic crash, failed load, OOM).
132
+ const send = useCallback((message) => {
133
+ return new Promise((resolve) => {
134
+ const state = stateRef.current;
135
+ const id = nextId(state);
136
+ const msgWithId = { ...message, id };
137
+ state.pending.set(id, resolve);
138
+ const doSend = () => {
139
+ const iframe = state.iframe;
140
+ if (!iframe?.contentWindow) {
141
+ state.pending.delete(id);
142
+ resolve({ type: 'error', error: 'Sandbox iframe not available' });
143
+ return;
144
+ }
145
+ iframe.contentWindow.postMessage(msgWithId, SANDBOX_ORIGIN);
146
+ };
147
+ if (state.ready) {
148
+ doSend();
149
+ }
150
+ else {
151
+ state.readyQueue.push(doSend);
152
+ }
153
+ });
154
+ }, []);
155
+ const compile = useCallback(async (source, slot = 'default') => {
156
+ const result = await send({ type: 'compile', source, slot });
157
+ if ('error' in result)
158
+ return result;
159
+ const r = result;
160
+ return { circuits: r.circuits, libraryCircuits: r.libraryCircuits, portValues: r.portValues, peripheralState: r.peripheralState };
161
+ }, [send]);
162
+ const compileIR = useCallback(async (circuit, libraryCircuits, slot, options) => {
163
+ const result = await send({
164
+ type: 'compile-ir',
165
+ circuit,
166
+ libraryCircuits,
167
+ slot,
168
+ evalSources: options?.evalSources,
169
+ snapshot: options?.snapshot,
170
+ });
171
+ if ('error' in result)
172
+ return result;
173
+ const r = result;
174
+ return { portValues: r.portValues, peripheralState: r.peripheralState, snapshotId: r.snapshotId };
175
+ }, [send]);
176
+ const tick = useCallback(async (inputs, slot = 'default', options) => {
177
+ const result = await send({ type: 'tick', inputs, slot, snapshot: options?.snapshot });
178
+ if ('error' in result)
179
+ return result;
180
+ const r = result;
181
+ return { portValues: r.portValues, cycle: r.cycle, peripheralState: r.peripheralState, snapshotId: r.snapshotId };
182
+ }, [send]);
183
+ const tickN = useCallback(async (n, inputs, slot = 'default', options) => {
184
+ const result = await send({ type: 'tick-n', n, inputs, slot, snapshot: options?.snapshot });
185
+ if ('error' in result)
186
+ return result;
187
+ const r = result;
188
+ return { portValues: r.portValues, cycle: r.cycle, peripheralState: r.peripheralState, snapshotId: r.snapshotId };
189
+ }, [send]);
190
+ const scanPort = useCallback(async (addrNodeId, valuePortKey, count, slot = 'default') => {
191
+ const result = await send({ type: 'scan-port', addrNodeId, valuePortKey, count, slot });
192
+ if ('error' in result)
193
+ return result;
194
+ const r = result;
195
+ return { values: r.values };
196
+ }, [send]);
197
+ const simulate = useCallback(async (params) => {
198
+ const result = await send({ type: 'simulate', ...params });
199
+ if ('error' in result)
200
+ return result;
201
+ const r = result;
202
+ return {
203
+ circuitName: r.circuitName,
204
+ signals: r.signals,
205
+ vcd: r.vcd,
206
+ ticks: r.ticks,
207
+ steadyStateAt: r.steadyStateAt,
208
+ };
209
+ }, [send]);
210
+ const reset = useCallback(async (slot = 'default') => {
211
+ const result = await send({ type: 'reset', slot });
212
+ if ('error' in result)
213
+ return result;
214
+ const r = result;
215
+ return { portValues: r.portValues, peripheralState: r.peripheralState };
216
+ }, [send]);
217
+ const setNode = useCallback(async (nodeId, value, slot = 'default', options) => {
218
+ const result = await send({ type: 'set-node', nodeId, value, slot, snapshot: options?.snapshot });
219
+ if ('error' in result)
220
+ return result;
221
+ const r = result;
222
+ return { portValues: r.portValues, peripheralState: r.peripheralState, snapshotId: r.snapshotId };
223
+ }, [send]);
224
+ const snapshot = useCallback(async (slot = 'default') => {
225
+ const result = await send({ type: 'snapshot', slot });
226
+ if ('error' in result)
227
+ return result;
228
+ const r = result;
229
+ return { snapshotId: r.snapshotId };
230
+ }, [send]);
231
+ const restore = useCallback(async (snapshotId, slot = 'default') => {
232
+ const result = await send({ type: 'restore', snapshotId, slot });
233
+ if ('error' in result)
234
+ return result;
235
+ const r = result;
236
+ return { portValues: r.portValues, cycle: r.cycle, peripheralState: r.peripheralState };
237
+ }, [send]);
238
+ const pruneSnapshots = useCallback(async (keepAfterId, slot = 'default') => {
239
+ const result = await send({ type: 'prune-snapshots', keepAfterId, slot });
240
+ if ('error' in result)
241
+ return result;
242
+ return result;
243
+ }, [send]);
244
+ const dispose = useCallback(async (slot) => {
245
+ await send({ type: 'dispose', slot });
246
+ }, [send]);
247
+ const isReady = useCallback(() => stateRef.current.ready, []);
248
+ return { compile, compileIR, tick, tickN, scanPort, simulate, reset, setNode, snapshot, restore, pruneSnapshots, dispose, isReady };
249
+ }
250
+ //# sourceMappingURL=useSandbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSandbox.js","sourceRoot":"","sources":["../../src/sandbox/useSandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAIvD,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E,+EAA+E;AAC/E,4EAA4E;AAC5E,iEAAiE;AACjE,8DAA8D;AAC9D,MAAM,GAAG,GAAG,OAAO,MAAM,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAE,MAAM,CAAC,IAAY,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AACtF,MAAM,cAAc,GAClB,GAAG,EAAE,mBAAmB;OACnB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC;AAiG5E,SAAS,YAAY,CACnB,KAAmB,EACnB,SAAsB,EACtB,aAA4C,EAC5C,OAAmB;IAEnB,2BAA2B;IAC3B,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACjB,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACtB,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;QACpB,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,CAAC,GAAG,GAAG,cAAc,CAAC;IAC5B,0FAA0F;IAC1F,6DAA6D;IAC7D,gFAAgF;IAChF,wFAAwF;IACxF,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,iCAAiC,CAAC,CAAC;IAClE,MAAM,CAAC,KAAK,C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,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AACtI,CAAC"}
@@ -0,0 +1,13 @@
1
+ export declare const INLINE_URL_THRESHOLD = 4000;
2
+ export declare function encodeSourceForUrl(source: string): string;
3
+ export declare function decodeSourceFromUrl(encoded: string): string | null;
4
+ export declare function shouldUseShortLink(encoded: string): boolean;
5
+ /**
6
+ * 10 bytes (80 bits) of SHA-256, hex-encoded → 20-char key.
7
+ *
8
+ * Content-addressed: identical sources collapse to one key, so re-sharing
9
+ * the same circuit is idempotent and `put` is a safe overwrite-with-same-value.
10
+ * Birthday collisions are actuarially impossible at any plausible scale.
11
+ */
12
+ export declare function hashSource(source: string): Promise<string>;
13
+ //# sourceMappingURL=encode-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-source.d.ts","sourceRoot":"","sources":["../../src/share/encode-source.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAEzC,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMlE;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMhE"}
@@ -0,0 +1,31 @@
1
+ import { compressToEncodedURIComponent, decompressFromEncodedURIComponent, } from "lz-string";
2
+ export const INLINE_URL_THRESHOLD = 4000;
3
+ export function encodeSourceForUrl(source) {
4
+ return compressToEncodedURIComponent(source);
5
+ }
6
+ export function decodeSourceFromUrl(encoded) {
7
+ try {
8
+ return decompressFromEncodedURIComponent(encoded) || null;
9
+ }
10
+ catch {
11
+ return null;
12
+ }
13
+ }
14
+ export function shouldUseShortLink(encoded) {
15
+ return encoded.length > INLINE_URL_THRESHOLD;
16
+ }
17
+ /**
18
+ * 10 bytes (80 bits) of SHA-256, hex-encoded → 20-char key.
19
+ *
20
+ * Content-addressed: identical sources collapse to one key, so re-sharing
21
+ * the same circuit is idempotent and `put` is a safe overwrite-with-same-value.
22
+ * Birthday collisions are actuarially impossible at any plausible scale.
23
+ */
24
+ export async function hashSource(source) {
25
+ const buf = new TextEncoder().encode(source);
26
+ const digest = await crypto.subtle.digest("SHA-256", buf);
27
+ return Array.from(new Uint8Array(digest).slice(0, 10))
28
+ .map((b) => b.toString(16).padStart(2, "0"))
29
+ .join("");
30
+ }
31
+ //# sourceMappingURL=encode-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-source.js","sourceRoot":"","sources":["../../src/share/encode-source.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,iCAAiC,GAClC,MAAM,WAAW,CAAC;AAEnB,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAEzC,MAAM,UAAU,kBAAkB,CAAC,MAAc;IAC/C,OAAO,6BAA6B,CAAC,MAAM,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,OAAe;IACjD,IAAI,CAAC;QACH,OAAO,iCAAiC,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,OAAO,OAAO,CAAC,MAAM,GAAG,oBAAoB,CAAC;AAC/C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAc;IAC7C,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAC1D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;SACnD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAC3C,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { INLINE_URL_THRESHOLD, encodeSourceForUrl, decodeSourceFromUrl, shouldUseShortLink, hashSource, } from "./encode-source.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/share/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,UAAU,GACX,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { INLINE_URL_THRESHOLD, encodeSourceForUrl, decodeSourceFromUrl, shouldUseShortLink, hashSource, } from "./encode-source.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/share/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,UAAU,GACX,MAAM,oBAAoB,CAAC"}