@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,23 @@
1
+ import React, { type ErrorInfo, type ReactNode } from "react";
2
+ interface ErrorBoundaryProps {
3
+ children: ReactNode;
4
+ fallback?: ReactNode | ((error: Error) => ReactNode);
5
+ onError?: (error: Error, errorInfo: ErrorInfo) => void;
6
+ title?: string;
7
+ }
8
+ interface ErrorBoundaryState {
9
+ error: Error | null;
10
+ }
11
+ /**
12
+ * React error boundary for circuit embed components.
13
+ * Catches render errors and displays a styled fallback instead of crashing.
14
+ */
15
+ export declare class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
16
+ constructor(props: ErrorBoundaryProps);
17
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState;
18
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
19
+ handleRetry: () => void;
20
+ render(): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=ErrorBoundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorBoundary.d.ts","sourceRoot":"","sources":["../../src/components/ErrorBoundary.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAG9D,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC;IACrD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,kBAAkB;IAC1B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED;;;GAGG;AACH,qBAAa,aAAc,SAAQ,KAAK,CAAC,SAAS,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;gBAC5E,KAAK,EAAE,kBAAkB;IAKrC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,kBAAkB;IAIjE,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS;IAIpD,WAAW,aAET;IAEF,MAAM;CAiBP"}
@@ -0,0 +1,34 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React from "react";
3
+ import { ErrorDisplay } from "./ErrorDisplay";
4
+ /**
5
+ * React error boundary for circuit embed components.
6
+ * Catches render errors and displays a styled fallback instead of crashing.
7
+ */
8
+ export class ErrorBoundary extends React.Component {
9
+ constructor(props) {
10
+ super(props);
11
+ this.state = { error: null };
12
+ }
13
+ static getDerivedStateFromError(error) {
14
+ return { error };
15
+ }
16
+ componentDidCatch(error, errorInfo) {
17
+ this.props.onError?.(error, errorInfo);
18
+ }
19
+ handleRetry = () => {
20
+ this.setState({ error: null });
21
+ };
22
+ render() {
23
+ if (this.state.error) {
24
+ if (this.props.fallback) {
25
+ return typeof this.props.fallback === "function"
26
+ ? this.props.fallback(this.state.error)
27
+ : this.props.fallback;
28
+ }
29
+ return (_jsx(ErrorDisplay, { error: this.state.error.message, title: this.props.title ?? "Render Error", onRetry: this.handleRetry }));
30
+ }
31
+ return this.props.children;
32
+ }
33
+ }
34
+ //# sourceMappingURL=ErrorBoundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorBoundary.js","sourceRoot":"","sources":["../../src/components/ErrorBoundary.tsx"],"names":[],"mappings":";AACA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAa9C;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK,CAAC,SAAiD;IACxF,YAAY,KAAyB;QACnC,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,KAAK,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,wBAAwB,CAAC,KAAY;QAC1C,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC;IAED,iBAAiB,CAAC,KAAY,EAAE,SAAoB;QAClD,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACzC,CAAC;IAED,WAAW,GAAG,GAAG,EAAE;QACjB,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACjC,CAAC,CAAC;IAEF,MAAM;QACJ,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACrB,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;gBACxB,OAAO,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,UAAU;oBAC9C,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;oBACvC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC1B,CAAC;YACD,OAAO,CACL,KAAC,YAAY,IACX,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAC/B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,cAAc,EACzC,OAAO,EAAE,IAAI,CAAC,WAAW,GACzB,CACH,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,18 @@
1
+ export interface SimulatorError {
2
+ message: string;
3
+ line?: number;
4
+ column?: number;
5
+ stage: "parse" | "compile" | "elaborate" | "simulate";
6
+ }
7
+ interface ErrorDisplayProps {
8
+ error: string | SimulatorError | SimulatorError[];
9
+ title?: string;
10
+ onRetry?: () => void;
11
+ }
12
+ /**
13
+ * Styled error display for circuit embed components.
14
+ * Renders structured error messages with optional line/column info.
15
+ */
16
+ export declare function ErrorDisplay({ error, title, onRetry }: ErrorDisplayProps): import("react/jsx-runtime").JSX.Element;
17
+ export {};
18
+ //# sourceMappingURL=ErrorDisplay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorDisplay.d.ts","sourceRoot":"","sources":["../../src/components/ErrorDisplay.tsx"],"names":[],"mappings":"AACA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,CAAC;CACvD;AAED,UAAU,iBAAiB;IACzB,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,cAAc,EAAE,CAAC;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAgBD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,KAAuB,EAAE,OAAO,EAAE,EAAE,iBAAiB,2CA8C1F"}
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ function parseErrors(error) {
3
+ if (Array.isArray(error))
4
+ return error;
5
+ if (typeof error === "object")
6
+ return [error];
7
+ // Legacy: semicolon-joined strings from older hook versions
8
+ return error.split("; ").map((msg) => ({ message: msg, stage: "compile" }));
9
+ }
10
+ const STAGE_LABELS = {
11
+ parse: "Parse",
12
+ compile: "Compile",
13
+ elaborate: "Elaborate",
14
+ simulate: "Simulate",
15
+ };
16
+ /**
17
+ * Styled error display for circuit embed components.
18
+ * Renders structured error messages with optional line/column info.
19
+ */
20
+ export function ErrorDisplay({ error, title = "Circuit Error", onRetry }) {
21
+ const errors = parseErrors(error);
22
+ return (_jsx("div", { className: "rounded-xl border border-red-800/40 bg-red-950/20 p-4 overflow-hidden", role: "alert", "aria-live": "assertive", children: _jsxs("div", { className: "flex items-start gap-3", children: [_jsx("div", { className: "shrink-0 mt-0.5", children: _jsx("svg", { className: "w-5 h-5 text-red-400", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z" }) }) }), _jsxs("div", { className: "flex-1 min-w-0", children: [_jsx("h4", { className: "text-sm font-semibold text-red-300", children: title }), _jsx("div", { className: "mt-2 space-y-1.5", children: errors.map((err, i) => (_jsxs("div", { className: "flex items-start gap-2", children: [_jsx("span", { className: "text-[10px] font-mono text-red-400/60 bg-red-900/30 px-1.5 py-0.5 rounded shrink-0 mt-0.5", children: STAGE_LABELS[err.stage] || err.stage }), _jsxs("span", { className: "text-xs font-mono text-red-300/80 break-all", children: [err.message, err.line !== undefined && (_jsxs("span", { className: "text-red-400/50 ml-1", children: ["(line ", err.line, err.column !== undefined ? `:${err.column}` : "", ")"] }))] })] }, i))) }), onRetry && (_jsx("button", { onClick: onRetry, className: "mt-3 px-3 py-1 text-xs font-medium rounded-md bg-red-900/30 hover:bg-red-900/50 text-red-300 transition-colors", children: "Retry" }))] })] }) }));
23
+ }
24
+ //# sourceMappingURL=ErrorDisplay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorDisplay.js","sourceRoot":"","sources":["../../src/components/ErrorDisplay.tsx"],"names":[],"mappings":";AAcA,SAAS,WAAW,CAAC,KAAiD;IACpE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9C,4DAA4D;IAC5D,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,SAAkB,EAAE,CAAC,CAAC,CAAC;AACvF,CAAC;AAED,MAAM,YAAY,GAA2B;IAC3C,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;CACrB,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,eAAe,EAAE,OAAO,EAAqB;IACzF,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IAElC,OAAO,CACL,cACE,SAAS,EAAC,uEAAuE,EACjF,IAAI,EAAC,OAAO,eACF,WAAW,YAErB,eAAK,SAAS,EAAC,wBAAwB,aACrC,cAAK,SAAS,EAAC,iBAAiB,YAC9B,cAAK,SAAS,EAAC,sBAAsB,EAAC,IAAI,EAAC,MAAM,EAAC,OAAO,EAAC,WAAW,EAAC,MAAM,EAAC,cAAc,EAAC,WAAW,EAAE,CAAC,YACxG,eAAM,aAAa,EAAC,OAAO,EAAC,cAAc,EAAC,OAAO,EAAC,CAAC,EAAC,0EAA0E,GAAG,GAC9H,GACF,EACN,eAAK,SAAS,EAAC,gBAAgB,aAC7B,aAAI,SAAS,EAAC,oCAAoC,YAAE,KAAK,GAAM,EAC/D,cAAK,SAAS,EAAC,kBAAkB,YAC9B,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CACtB,eAAa,SAAS,EAAC,wBAAwB,aAC7C,eAAM,SAAS,EAAC,2FAA2F,YACxG,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,KAAK,GAChC,EACP,gBAAM,SAAS,EAAC,6CAA6C,aAC1D,GAAG,CAAC,OAAO,EACX,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,CACzB,gBAAM,SAAS,EAAC,sBAAsB,uBAC7B,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,SAC5D,CACR,IACI,KAXC,CAAC,CAYL,CACP,CAAC,GACE,EACL,OAAO,IAAI,CACV,iBACE,OAAO,EAAE,OAAO,EAChB,SAAS,EAAC,gHAAgH,sBAGnH,CACV,IACG,IACF,GACF,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ interface LoadingSkeletonProps {
2
+ height?: number | string;
3
+ }
4
+ /**
5
+ * Loading skeleton for circuit embeds.
6
+ * Shows fake node placeholders with connecting lines, matching the dark theme.
7
+ * Respects height to prevent layout shift.
8
+ */
9
+ export declare function LoadingSkeleton({ height }: LoadingSkeletonProps): import("react/jsx-runtime").JSX.Element;
10
+ export {};
11
+ //# sourceMappingURL=LoadingSkeleton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoadingSkeleton.d.ts","sourceRoot":"","sources":["../../src/components/LoadingSkeleton.tsx"],"names":[],"mappings":"AAGA,UAAU,oBAAoB;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,MAAY,EAAE,EAAE,oBAAoB,2CAmCrE"}
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Loading skeleton for circuit embeds.
4
+ * Shows fake node placeholders with connecting lines, matching the dark theme.
5
+ * Respects height to prevent layout shift.
6
+ */
7
+ export function LoadingSkeleton({ height = 300 }) {
8
+ return (_jsxs("div", { className: "rounded-xl border border-[var(--embed-border)] bg-[var(--embed-bg-primary)] overflow-hidden flex items-center justify-center", style: { height }, role: "status", "aria-label": "Loading circuit", children: [_jsxs("div", { className: "flex items-center gap-8", children: [_jsxs("div", { className: "flex flex-col gap-4", children: [_jsx("div", { className: "w-20 h-14 rounded-lg bg-[var(--embed-bg-tertiary)]/60 animate-pulse" }), _jsx("div", { className: "w-20 h-14 rounded-lg bg-[var(--embed-bg-tertiary)]/60 animate-pulse", style: { animationDelay: "150ms" } })] }), _jsxs("div", { className: "flex flex-col gap-6 items-center", children: [_jsx("div", { className: "w-12 h-0.5 bg-[var(--embed-border)]/40 animate-pulse", style: { animationDelay: "300ms" } }), _jsx("div", { className: "w-12 h-0.5 bg-[var(--embed-border)]/40 animate-pulse", style: { animationDelay: "350ms" } })] }), _jsx("div", { className: "w-24 h-20 rounded-lg bg-[var(--embed-bg-tertiary)]/60 animate-pulse", style: { animationDelay: "200ms" } }), _jsx("div", { className: "w-12 h-0.5 bg-[var(--embed-border)]/40 animate-pulse", style: { animationDelay: "400ms" } }), _jsx("div", { className: "w-20 h-14 rounded-lg bg-[var(--embed-bg-tertiary)]/60 animate-pulse", style: { animationDelay: "250ms" } })] }), _jsx("span", { className: "sr-only", children: "Compiling and laying out circuit..." })] }));
9
+ }
10
+ //# sourceMappingURL=LoadingSkeleton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoadingSkeleton.js","sourceRoot":"","sources":["../../src/components/LoadingSkeleton.tsx"],"names":[],"mappings":";AAOA;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,EAAE,MAAM,GAAG,GAAG,EAAwB;IACpE,OAAO,CACL,eACE,SAAS,EAAC,8HAA8H,EACxI,KAAK,EAAE,EAAE,MAAM,EAAE,EACjB,IAAI,EAAC,QAAQ,gBACF,iBAAiB,aAE5B,eAAK,SAAS,EAAC,yBAAyB,aAEtC,eAAK,SAAS,EAAC,qBAAqB,aAClC,cAAK,SAAS,EAAC,qEAAqE,GAAG,EACvF,cAAK,SAAS,EAAC,qEAAqE,EAAC,KAAK,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,GAAI,IACvH,EAGN,eAAK,SAAS,EAAC,kCAAkC,aAC/C,cAAK,SAAS,EAAC,sDAAsD,EAAC,KAAK,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,GAAI,EAC5G,cAAK,SAAS,EAAC,sDAAsD,EAAC,KAAK,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,GAAI,IACxG,EAGN,cAAK,SAAS,EAAC,qEAAqE,EAAC,KAAK,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,GAAI,EAG3H,cAAK,SAAS,EAAC,sDAAsD,EAAC,KAAK,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,GAAI,EAG5G,cAAK,SAAS,EAAC,qEAAqE,EAAC,KAAK,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,GAAI,IACvH,EAGN,eAAM,SAAS,EAAC,SAAS,oDAA2C,IAChE,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Re-export canonical node components from @simten/ui/nodes.
3
+ * This allows external consumers to import from @simten/embed/nodes
4
+ * while the source of truth lives in the ui package.
5
+ */
6
+ export { BaseNode, type PortConfig, type BaseNodeProps, InputNode, OutputNode, LogicGateNode, EmbedConsoleNode, EmbedScreenNode, CompositeBadge, type NodeData, } from "@simten/ui/nodes";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/nodes/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,QAAQ,EACR,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,SAAS,EACT,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,KAAK,QAAQ,GACd,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Re-export canonical node components from @simten/ui/nodes.
3
+ * This allows external consumers to import from @simten/embed/nodes
4
+ * while the source of truth lives in the ui package.
5
+ */
6
+ export { BaseNode, InputNode, OutputNode, LogicGateNode, EmbedConsoleNode, EmbedScreenNode, CompositeBadge, } from "@simten/ui/nodes";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/nodes/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,QAAQ,EAGR,SAAS,EACT,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,cAAc,GAEf,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * useCircuitSimulator — the public circuit-simulation hook.
3
+ *
4
+ * Composes the sandbox bridge (`useSandbox` in @simten/ui) with circuit-level
5
+ * concerns: auto-harness, time-travel history, auto-run, snapshot/restore.
6
+ * This is what every embed/blog/editor consumer calls.
7
+ *
8
+ * Runtime topology (browser path):
9
+ * useCircuitSimulator (here)
10
+ * → useSandbox — packages/ui/src/sandbox/useSandbox.ts (postMessage bridge)
11
+ * → apps/sandbox/main.ts — runs inside the cross-origin iframe
12
+ * → core/simulator — pure simulator engine
13
+ *
14
+ * For non-browser callers (vitest, CI), skip this hook entirely and use
15
+ * `@simten/core/sim` directly — no iframe, no React, just the engine.
16
+ *
17
+ * See: apps/web/content/docs/architecture.mdx → "Runtime topology".
18
+ */
19
+ import { type SimulatorEngine, type CircuitLibrary, type FlatPortValueMap, type FlatSequentialState } from "@simten/core/simulator";
20
+ import type { Circuit } from "@simten/core";
21
+ import type { BuiltCircuit } from "@simten/core/circuit";
22
+ export interface SimulatorState {
23
+ outputs: Record<string, boolean | number>;
24
+ inputs: Record<string, boolean | number>;
25
+ cycleCount: number;
26
+ ready: boolean;
27
+ error: string | null;
28
+ isSequential: boolean;
29
+ circuit: Circuit | null;
30
+ portValues: FlatPortValueMap | null;
31
+ sequentialState: FlatSequentialState | null;
32
+ componentLibrary: CircuitLibrary | null;
33
+ history: readonly {
34
+ engineSnapshot: unknown;
35
+ metadata?: unknown;
36
+ }[];
37
+ historyIndex: number;
38
+ isViewingPast: boolean;
39
+ isRunning: boolean;
40
+ speed: number;
41
+ }
42
+ export interface SimulatorActions {
43
+ setNode: (name: string, value: boolean | number) => void;
44
+ toggleInput: (name: string) => void;
45
+ toggleNode: (nodeId: string) => void;
46
+ /**
47
+ * Set a node's value. Returns the resulting port-value Map (so scan-style
48
+ * callers can read debug outputs without waiting for a React re-render),
49
+ * or null if the sandbox isn't ready / errored.
50
+ */
51
+ setNodeValue: (nodeId: string, value: number | boolean | Map<number, number>) => Promise<ReadonlyMap<string, boolean | number> | null>;
52
+ tick: () => void;
53
+ /** Advance N ticks in a single sandbox round-trip; one React update. */
54
+ tickN: (n: number) => Promise<void>;
55
+ /**
56
+ * Combinationally scan a debug-address node across 0..count-1, sampling
57
+ * a value port after each setting. Single round-trip; clock not advanced.
58
+ * Returns the `number[]` of length `count`, or null on error.
59
+ */
60
+ scanPort: (addrNodeId: string, valuePortKey: string, count: number) => Promise<number[] | null>;
61
+ reset: () => void;
62
+ stepBack: () => void;
63
+ stepForward: () => void;
64
+ seek: (index: number) => void;
65
+ startAutoRun: (ticksPerSecond: number, options?: {
66
+ displayRate?: number;
67
+ onBeforeTick?: () => void;
68
+ }) => void;
69
+ stopAutoRun: () => void;
70
+ setSpeed: (ticksPerSecond: number) => void;
71
+ runCombinational: () => void;
72
+ getSimulator: () => SimulatorEngine | null;
73
+ }
74
+ export interface UseCircuitSimulatorOptions {
75
+ /** Wrap the circuit with auto-generated Switch/Led nodes */
76
+ autoHarness?: boolean;
77
+ /** Initial values for input ports (only used when autoHarness is true) */
78
+ initialInputs?: Record<string, number | boolean>;
79
+ }
80
+ /**
81
+ * Build a minimal BuiltCircuit-like object from a Circuit IR and its dependencies.
82
+ * Used by the editor to adapt sandbox compile results into the shape useCircuitSimulator expects.
83
+ * The resulting object has no live eval functions (empty registry lookups) — the sandbox
84
+ * is expected to already have the evals registered from a prior sandbox.compile(source).
85
+ */
86
+ export declare function builtFromIR(circuit: Circuit, dependencies: Circuit[]): BuiltCircuit;
87
+ /**
88
+ * Circuit simulator hook — runs simulation in the sandbox iframe.
89
+ *
90
+ * Takes a BuiltCircuit and returns reactive simulation state + actions.
91
+ * All simulation happens inside the sandbox for security (CSP-isolated,
92
+ * cross-origin) — no user code runs in the main frame at simulation time.
93
+ */
94
+ export declare function useCircuitSimulator(circuit: BuiltCircuit | null, options?: UseCircuitSimulatorOptions): SimulatorState & SimulatorActions;
95
+ //# sourceMappingURL=useCircuitSimulator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCircuitSimulator.d.ts","sourceRoot":"","sources":["../../src/hooks/useCircuitSimulator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,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