@tscircuit/runframe 0.0.1799 → 0.0.1801

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.
@@ -1730,7 +1730,7 @@ var useErrorTelemetry = ({
1730
1730
  };
1731
1731
 
1732
1732
  // package.json
1733
- var version = "0.0.1798";
1733
+ var version = "0.0.1800";
1734
1734
  var package_default = {
1735
1735
  name: "@tscircuit/runframe",
1736
1736
  main: "dist/preview.js",
@@ -1846,7 +1846,7 @@ var package_default = {
1846
1846
  yargs: "^17.7.2"
1847
1847
  },
1848
1848
  dependencies: {
1849
- "@tscircuit/eval": "^0.0.741",
1849
+ "@tscircuit/eval": "^0.0.742",
1850
1850
  "@tscircuit/solver-utils": "^0.0.7"
1851
1851
  }
1852
1852
  };
package/dist/preview.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  linkify,
9
9
  useOrderDialog,
10
10
  useOrderDialogCli
11
- } from "./chunk-H7FIH7TH.js";
11
+ } from "./chunk-4536ZHPL.js";
12
12
  export {
13
13
  BomTable,
14
14
  CadViewer,
package/dist/runner.js CHANGED
@@ -34,14 +34,14 @@ import {
34
34
  useRunFrameStore,
35
35
  useRunnerStore,
36
36
  useStyles
37
- } from "./chunk-H7FIH7TH.js";
37
+ } from "./chunk-4536ZHPL.js";
38
38
 
39
39
  // lib/components/RunFrame/RunFrame.tsx
40
40
  import { createCircuitWebWorker } from "@tscircuit/eval/worker";
41
41
  import Debug from "debug";
42
42
  import { Loader2, Play, Square } from "lucide-react";
43
43
  import { HTTPError } from "ky";
44
- import { useCallback as useCallback2, useEffect, useReducer, useRef as useRef2, useState } from "react";
44
+ import { useEffect, useReducer, useRef as useRef2, useState } from "react";
45
45
  import { ErrorBoundary } from "react-error-boundary";
46
46
 
47
47
  // lib/components/RunFrame/RunFrameErrorFallback.tsx
@@ -346,10 +346,9 @@ var RunFrame = (props) => {
346
346
  );
347
347
  const setLastRunEvalVersion = useRunnerStore((s) => s.setLastRunEvalVersion);
348
348
  const lastRunCountTriggerRef = useRef2(0);
349
- const { runWithMutex, cancel: cancelRunMutex } = useMutex();
349
+ const runMutex = useMutex();
350
350
  const [isRunning, setIsRunning] = useState(false);
351
351
  const [dependenciesLoaded, setDependenciesLoaded] = useState(false);
352
- const lastMainComponentPathRef = useRef2(null);
353
352
  const [activeAsyncEffects, setActiveAsyncEffects] = useState({});
354
353
  const [currentDebugOption, setCurrentDebugOption] = useState("");
355
354
  const [showSchematicDebugGrid, setShowSchematicDebugGrid] = useState(false);
@@ -360,21 +359,6 @@ var RunFrame = (props) => {
360
359
  const emitRunCompleted = (payload) => {
361
360
  props.onRunCompleted?.(payload);
362
361
  };
363
- const stopActiveRender = useCallback2(() => {
364
- setIsRunning(false);
365
- setRenderLog(null);
366
- setError(null);
367
- if (cancelExecutionRef.current) {
368
- cancelExecutionRef.current();
369
- cancelExecutionRef.current = null;
370
- }
371
- cancelRunMutex();
372
- setActiveAsyncEffects({});
373
- if (globalThis.runFrameWorker) {
374
- globalThis.runFrameWorker.kill();
375
- globalThis.runFrameWorker = null;
376
- }
377
- }, [cancelRunMutex]);
378
362
  useEffect(() => {
379
363
  const handleKeyDown = (e) => {
380
364
  if ((e.ctrlKey || e.metaKey) && e.key === "Enter" && !isRunning) {
@@ -476,21 +460,13 @@ var RunFrame = (props) => {
476
460
  setIsRunning(false);
477
461
  return;
478
462
  }
479
- const currentMainComponentPath = props.mainComponentPath ?? null;
480
463
  const wasTriggeredByRunButton = runCountTrigger !== lastRunCountTriggerRef.current;
481
- const wasTriggeredByMainComponentChange = lastMainComponentPathRef.current !== currentMainComponentPath;
482
- if (wasTriggeredByMainComponentChange && isRunning) {
483
- debug("mainComponentPath changed during render, cancelling active render");
484
- stopActiveRender();
485
- }
486
464
  if (lastFsMapRef.current && circuitJson) {
487
465
  const changes = getChangesBetweenFsMaps(lastFsMapRef.current, fsMap);
488
466
  if (Object.keys(changes).length > 0) {
489
467
  debug("code changes detected");
490
468
  } else if (lastEntrypointRef.current !== props.entrypoint) {
491
469
  debug("render triggered by entrypoint change");
492
- } else if (wasTriggeredByMainComponentChange) {
493
- debug("render triggered by mainComponentPath change");
494
470
  } else if (!wasTriggeredByRunButton) {
495
471
  debug("render triggered without changes to fsMap, skipping");
496
472
  return;
@@ -501,7 +477,6 @@ var RunFrame = (props) => {
501
477
  }
502
478
  lastFsMapRef.current = fsMap;
503
479
  lastEntrypointRef.current = props.entrypoint ?? null;
504
- lastMainComponentPathRef.current = currentMainComponentPath;
505
480
  lastRunCountTriggerRef.current = runCountTrigger;
506
481
  setIsRunning(true);
507
482
  const runWorker = async () => {
@@ -512,10 +487,9 @@ var RunFrame = (props) => {
512
487
  setSolverEvents([]);
513
488
  const renderLog2 = { progress: 0, debugOutputs: [] };
514
489
  let cancelled = false;
515
- const cancelCurrentExecution = () => {
490
+ cancelExecutionRef.current = () => {
516
491
  cancelled = true;
517
492
  };
518
- cancelExecutionRef.current = cancelCurrentExecution;
519
493
  const resolvedEvalVersion = await resolveEvalVersion(
520
494
  props.evalVersion,
521
495
  !globalThis.runFrameWorker && props.forceLatestEvalVersion
@@ -633,10 +607,6 @@ var RunFrame = (props) => {
633
607
  }).then(() => {
634
608
  return { success: true };
635
609
  }).catch((e) => {
636
- if (cancelled) {
637
- debug("execution cancelled");
638
- return { success: false };
639
- }
640
610
  const message = e.message.replace("Error: ", "");
641
611
  debug(`eval error: ${message}`);
642
612
  props.onError?.(e);
@@ -648,19 +618,13 @@ var RunFrame = (props) => {
648
618
  });
649
619
  debug("worker call started");
650
620
  if (!evalResult.success) {
651
- if (!cancelled) {
652
- setIsRunning(false);
653
- setActiveAsyncEffects({});
654
- }
621
+ setIsRunning(false);
622
+ setActiveAsyncEffects({});
655
623
  return;
656
624
  }
657
625
  const $renderResult = worker.renderUntilSettled();
658
626
  debug("waiting for initial circuit json...");
659
627
  let circuitJson2 = await worker.getCircuitJson().catch((e) => {
660
- if (cancelled) {
661
- debug("initial circuit json request cancelled");
662
- return null;
663
- }
664
628
  debug("error getting initial circuit json", e);
665
629
  props.onError?.(e);
666
630
  emitRunCompleted(buildRunCompletedPayload({ executionError: e }));
@@ -671,28 +635,13 @@ var RunFrame = (props) => {
671
635
  return null;
672
636
  });
673
637
  if (!circuitJson2) return;
674
- if (cancelled) return;
675
638
  debug("got initial circuit json");
676
639
  setCircuitJson(circuitJson2);
677
640
  props.onCircuitJsonChange?.(circuitJson2);
678
641
  props.onInitialRender?.({ circuitJson: circuitJson2 });
679
- await $renderResult.catch((e) => {
680
- if (cancelled) {
681
- debug("render cancelled");
682
- return null;
683
- }
684
- throw e;
685
- });
686
- if (cancelled) return;
642
+ await $renderResult;
687
643
  debug("getting final circuit json");
688
- circuitJson2 = await worker.getCircuitJson().catch((e) => {
689
- if (cancelled) {
690
- debug("final circuit json request cancelled");
691
- return null;
692
- }
693
- throw e;
694
- });
695
- if (!circuitJson2 || cancelled) return;
644
+ circuitJson2 = await worker.getCircuitJson();
696
645
  props.onCircuitJsonChange?.(circuitJson2);
697
646
  setCircuitJson(circuitJson2);
698
647
  emitRunCompleted(buildRunCompletedPayload({ circuitJson: circuitJson2 }));
@@ -707,16 +656,12 @@ var RunFrame = (props) => {
707
656
  if (!cancelled) {
708
657
  setRenderLog({ ...renderLog2 });
709
658
  }
710
- if (!cancelled) {
711
- setIsRunning(false);
712
- setActiveAsyncEffects({});
713
- setCurrentDebugOption("");
714
- }
715
- if (cancelExecutionRef.current === cancelCurrentExecution) {
716
- cancelExecutionRef.current = null;
717
- }
659
+ setIsRunning(false);
660
+ setActiveAsyncEffects({});
661
+ setCurrentDebugOption("");
662
+ cancelExecutionRef.current = null;
718
663
  };
719
- runWithMutex(runWorker);
664
+ runMutex.runWithMutex(runWorker);
720
665
  }, [
721
666
  props.fsMap,
722
667
  props.entrypoint,
@@ -725,10 +670,7 @@ var RunFrame = (props) => {
725
670
  props.mainComponentPath,
726
671
  props.isLoadingFiles,
727
672
  currentDebugOption,
728
- isStaticCircuitJson,
729
- isRunning,
730
- runWithMutex,
731
- stopActiveRender
673
+ isStaticCircuitJson
732
674
  ]);
733
675
  const lastEditEventRef = useRef2(null);
734
676
  const dragTimeout = useRef2(null);
@@ -835,7 +777,19 @@ var RunFrame = (props) => {
835
777
  {
836
778
  onClick: (e) => {
837
779
  e.stopPropagation();
838
- stopActiveRender();
780
+ setIsRunning(false);
781
+ setRenderLog(null);
782
+ setError(null);
783
+ if (cancelExecutionRef.current) {
784
+ cancelExecutionRef.current();
785
+ cancelExecutionRef.current = null;
786
+ }
787
+ runMutex.cancel();
788
+ setActiveAsyncEffects({});
789
+ if (globalThis.runFrameWorker) {
790
+ globalThis.runFrameWorker.kill();
791
+ globalThis.runFrameWorker = null;
792
+ }
839
793
  },
840
794
  variant: "ghost",
841
795
  size: "icon",
@@ -907,7 +861,7 @@ import { applyEditEventsToManualEditsFile } from "@tscircuit/core";
907
861
  import Debug3 from "debug";
908
862
 
909
863
  // lib/hooks/use-edit-event-controller.ts
910
- import { useState as useState2, useCallback as useCallback3, useEffect as useEffect2 } from "react";
864
+ import { useState as useState2, useCallback as useCallback2, useEffect as useEffect2 } from "react";
911
865
  var debug2 = debug_default.extend("useEditEventController");
912
866
  var useEditEventController = () => {
913
867
  const applyEditEventsAndUpdateManualEditsJson = useRunFrameStore(
@@ -918,26 +872,26 @@ var useEditEventController = () => {
918
872
  const unappliedEditEvents = editEvents.filter((ee) => !ee._applied);
919
873
  const appliedEditEvents = editEvents.filter((ee) => ee._applied);
920
874
  const editEventsForRender = isRendering ? editEvents : unappliedEditEvents;
921
- const pushEditEvent = useCallback3((ee) => {
875
+ const pushEditEvent = useCallback2((ee) => {
922
876
  setEditEvents((prev) => [...prev, { ...ee, _applied: false }]);
923
877
  }, []);
924
- const markEditEventApplied = useCallback3((ee) => {
878
+ const markEditEventApplied = useCallback2((ee) => {
925
879
  setEditEvents(
926
880
  (prev) => prev.map(
927
881
  (event) => event === ee ? { ...event, _applied: true } : event
928
882
  )
929
883
  );
930
884
  }, []);
931
- const markAllEditEventsApplied = useCallback3(() => {
885
+ const markAllEditEventsApplied = useCallback2(() => {
932
886
  setEditEvents((prev) => prev.map((ee) => ({ ...ee, _applied: true })));
933
887
  }, []);
934
- const markRenderStarted = useCallback3(() => {
888
+ const markRenderStarted = useCallback2(() => {
935
889
  setIsRendering(true);
936
890
  if (editEvents.length === 0) return;
937
891
  debug2("removing edit events that are applied");
938
892
  setEditEvents((prev) => prev.filter((ee) => !ee._applied));
939
893
  }, [editEvents]);
940
- const markRenderComplete = useCallback3(() => {
894
+ const markRenderComplete = useCallback2(() => {
941
895
  setIsRendering(false);
942
896
  }, []);
943
897
  useEffect2(() => {
@@ -1029,7 +983,7 @@ var useSyncPageTitle = () => {
1029
983
  };
1030
984
 
1031
985
  // lib/components/RunFrameWithApi/RunFrameWithApi.tsx
1032
- import { useCallback as useCallback5, useEffect as useEffect7, useMemo as useMemo4, useState as useState6 } from "react";
986
+ import { useCallback as useCallback4, useEffect as useEffect7, useMemo as useMemo4, useState as useState6 } from "react";
1033
987
 
1034
988
  // lib/utils/get-board-files-from-config.ts
1035
989
  import { projectConfig } from "@tscircuit/props";
@@ -1073,7 +1027,7 @@ import {
1073
1027
  Folder,
1074
1028
  Save
1075
1029
  } from "lucide-react";
1076
- import { useCallback as useCallback4, useEffect as useEffect6, useMemo as useMemo3, useRef as useRef3, useState as useState5 } from "react";
1030
+ import { useCallback as useCallback3, useEffect as useEffect6, useMemo as useMemo3, useRef as useRef3, useState as useState5 } from "react";
1077
1031
 
1078
1032
  // lib/components/ui/command.tsx
1079
1033
  import * as React2 from "react";
@@ -1441,7 +1395,7 @@ var EnhancedFileSelectorCombobox = ({
1441
1395
  navigateToFolder(folderPath);
1442
1396
  setCurrentFileIndex(0);
1443
1397
  };
1444
- const navigateUp = useCallback4(() => {
1398
+ const navigateUp = useCallback3(() => {
1445
1399
  if (!currentFolder) return;
1446
1400
  const lastSlashIndex = currentFolder.lastIndexOf("/");
1447
1401
  const parentPath = lastSlashIndex === -1 ? null : currentFolder.substring(0, lastSlashIndex);
@@ -1458,7 +1412,7 @@ var EnhancedFileSelectorCombobox = ({
1458
1412
  window.addEventListener("keydown", handleKeyDown);
1459
1413
  return () => window.removeEventListener("keydown", handleKeyDown);
1460
1414
  }, [open, navigateUp]);
1461
- const selectFile = useCallback4(
1415
+ const selectFile = useCallback3(
1462
1416
  (filePath, index, updateFolder = false) => {
1463
1417
  setFile(filePath);
1464
1418
  setCurrentFileIndex(index);
@@ -1844,7 +1798,7 @@ var RunFrameWithApi = (props) => {
1844
1798
  []
1845
1799
  );
1846
1800
  const isLoadingFiles = !hasReceivedInitialFiles;
1847
- const handleToggleFavorite = useCallback5(
1801
+ const handleToggleFavorite = useCallback4(
1848
1802
  (filePath) => {
1849
1803
  setFavorites(
1850
1804
  (prev) => prev.includes(filePath) ? prev.filter((f) => f !== filePath) : [...prev, filePath]
@@ -1893,7 +1847,7 @@ var RunFrameWithApi = (props) => {
1893
1847
  props.initialMainComponentPath,
1894
1848
  componentPath
1895
1849
  ]);
1896
- const updateFileHash = useCallback5((filePath) => {
1850
+ const updateFileHash = useCallback4((filePath) => {
1897
1851
  if (typeof window === "undefined") return;
1898
1852
  const params = new URLSearchParams(window.location.hash.slice(1));
1899
1853
  if (params.get("file") === filePath) return;
@@ -1935,7 +1889,7 @@ var RunFrameWithApi = (props) => {
1935
1889
  } : {},
1936
1890
  [componentPath]
1937
1891
  );
1938
- const handleRunCompleted = useCallback5(
1892
+ const handleRunCompleted = useCallback4(
1939
1893
  async (payload) => {
1940
1894
  try {
1941
1895
  await pushEvent({
@@ -2030,10 +1984,10 @@ var RunFrameWithApi = (props) => {
2030
1984
  };
2031
1985
 
2032
1986
  // lib/components/RunFrameForCli/RunFrameForCli.tsx
2033
- import { useCallback as useCallback7, useState as useState8 } from "react";
1987
+ import { useCallback as useCallback6, useState as useState8 } from "react";
2034
1988
 
2035
1989
  // lib/components/RunFrameForCli/LoginDialog.tsx
2036
- import { useCallback as useCallback6, useEffect as useEffect8, useRef as useRef4, useState as useState7 } from "react";
1990
+ import { useCallback as useCallback5, useEffect as useEffect8, useRef as useRef4, useState as useState7 } from "react";
2037
1991
  import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
2038
1992
  var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
2039
1993
  var LoginDialog = ({
@@ -2053,7 +2007,7 @@ var LoginDialog = ({
2053
2007
  }
2054
2008
  };
2055
2009
  }, []);
2056
- const handleSignIn = useCallback6(async () => {
2010
+ const handleSignIn = useCallback5(async () => {
2057
2011
  setLoginState("creating");
2058
2012
  setErrorMessage(null);
2059
2013
  abortControllerRef.current = new AbortController();
@@ -2127,7 +2081,7 @@ var LoginDialog = ({
2127
2081
  toast.error(message);
2128
2082
  }
2129
2083
  }, [pushEvent, onLoginSuccess, onClose]);
2130
- const handleCancel = useCallback6(() => {
2084
+ const handleCancel = useCallback5(() => {
2131
2085
  if (abortControllerRef.current) {
2132
2086
  abortControllerRef.current.abort();
2133
2087
  }
@@ -2195,13 +2149,13 @@ var LoginDialog = ({
2195
2149
  };
2196
2150
  var useLoginDialog = () => {
2197
2151
  const [isOpen, setIsOpen] = useState7(false);
2198
- const openLoginDialog = useCallback6(() => {
2152
+ const openLoginDialog = useCallback5(() => {
2199
2153
  setIsOpen(true);
2200
2154
  }, []);
2201
- const closeLoginDialog = useCallback6(() => {
2155
+ const closeLoginDialog = useCallback5(() => {
2202
2156
  setIsOpen(false);
2203
2157
  }, []);
2204
- const handleLoginSuccess = useCallback6(() => {
2158
+ const handleLoginSuccess = useCallback5(() => {
2205
2159
  setIsOpen(false);
2206
2160
  }, []);
2207
2161
  return {
@@ -2229,7 +2183,7 @@ var RunFrameForCli = (props) => {
2229
2183
  const params = new URLSearchParams(window.location.hash.slice(1));
2230
2184
  return params.get("main_component") ?? void 0;
2231
2185
  });
2232
- const updateMainComponentHash = useCallback7((mainComponentPath) => {
2186
+ const updateMainComponentHash = useCallback6((mainComponentPath) => {
2233
2187
  if (typeof window === "undefined") return;
2234
2188
  const params = new URLSearchParams(window.location.hash.slice(1));
2235
2189
  if (params.get("main_component") === mainComponentPath) return;
@@ -2860,7 +2814,7 @@ var ImportComponentDialog = ({
2860
2814
  };
2861
2815
 
2862
2816
  // lib/components/RunFrameStaticBuildViewer/RunFrameStaticBuildViewer.tsx
2863
- import { useCallback as useCallback8, useEffect as useEffect10, useState as useState10 } from "react";
2817
+ import { useCallback as useCallback7, useEffect as useEffect10, useState as useState10 } from "react";
2864
2818
 
2865
2819
  // lib/components/RunFrameStaticBuildViewer/CircuitJsonFileSelectorCombobox.tsx
2866
2820
  import { jsx as jsx12 } from "react/jsx-runtime";
@@ -2900,7 +2854,7 @@ var RunFrameStaticBuildViewer = (props) => {
2900
2854
  const [failedFiles, setFailedFiles] = useState10(/* @__PURE__ */ new Set());
2901
2855
  const fileReferences = props.files;
2902
2856
  const availableFiles = fileReferences.map((f) => f.filePath);
2903
- const defaultFetchFile = useCallback8(
2857
+ const defaultFetchFile = useCallback7(
2904
2858
  async (fileRef) => {
2905
2859
  if (!fileRef.fileStaticAssetUrl) {
2906
2860
  throw new Error(
@@ -2917,7 +2871,7 @@ var RunFrameStaticBuildViewer = (props) => {
2917
2871
  },
2918
2872
  []
2919
2873
  );
2920
- const loadCircuitJsonFile = useCallback8(
2874
+ const loadCircuitJsonFile = useCallback7(
2921
2875
  async (filePath) => {
2922
2876
  if (fileCache[filePath]) {
2923
2877
  setCircuitJson(fileCache[filePath]);
@@ -2984,10 +2938,10 @@ var RunFrameStaticBuildViewer = (props) => {
2984
2938
  loadCircuitJsonFile(selectedPath);
2985
2939
  }
2986
2940
  }, [currentCircuitJsonPath]);
2987
- const handleFileChange = useCallback8((newPath) => {
2941
+ const handleFileChange = useCallback7((newPath) => {
2988
2942
  setCurrentCircuitJsonPath(newPath);
2989
2943
  }, []);
2990
- const retryFailedFile = useCallback8(
2944
+ const retryFailedFile = useCallback7(
2991
2945
  (filePath) => {
2992
2946
  setFailedFiles((prev) => {
2993
2947
  const newSet = new Set(prev);
@@ -5671,7 +5671,7 @@ test("${l} should solve problem correctly", () => {
5671
5671
  // Add more specific assertions based on expected output
5672
5672
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5673
5673
  })
5674
- `,d=new Blob([u],{type:"text/plain"}),h=URL.createObjectURL(d),f=document.createElement("a");f.href=h,f.download=`${l}.test.ts`,f.click(),URL.revokeObjectURL(h)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}r(!1)};return G.jsxs("div",{className:`relative ${e}`,ref:i,children:[G.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>r(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&G.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},f0t=t=>t.activeSubSolver?[t,...f0t(t.activeSubSolver)]:[t],fXn=({solver:t})=>{const e=f0t(t);return G.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,r)=>G.jsxs("div",{className:"flex items-center",children:[r>0&&G.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),G.jsx(pXn,{solver:n})]},n.constructor.name))})},mXn=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:r,onSolverCompleted:i})=>{const[o,s]=te.useReducer(m=>!m,!1),a=te.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(r&&r(t),t.solve(),e(),i&&i(t))},u=()=>{o?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},d=()=>{const m=t;if(m.getCurrentPhase&&!t.solved&&!t.failed){const g=m.getCurrentPhase();for(;m.getCurrentPhase()===g&&!t.solved&&!t.failed;)t.step();e()}},h=()=>{if(t.solved||t.failed||o)return;const m=window.prompt("Step until which iteration?",`${t.iterations}`);if(m===null)return;const g=Number(m);if(!Number.isFinite(g)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<g&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};te.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),te.useEffect(()=>{(t.solved||t.failed)&&o&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,o]);const f=t.getCurrentPhase!==void 0,p=f?t.getCurrentPhase():null;return G.jsxs("div",{className:"space-y-2 p-2 border-b",children:[G.jsx("div",{className:"flex items-center",children:G.jsx(fXn,{solver:t})}),G.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[G.jsx("button",{onClick:c,disabled:t.solved||t.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),G.jsx("button",{onClick:l,disabled:t.solved||t.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),G.jsx("button",{onClick:u,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),G.jsx("button",{onClick:h,disabled:t.solved||t.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),f&&G.jsx("button",{onClick:d,disabled:t.solved||t.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),G.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),p&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",G.jsx("span",{className:"font-medium",children:p})]}),t.solved&&G.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&G.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&G.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},yXn=(t,e,n)=>{const r=t.currentPipelineStepIndex;return e<r?"Completed":e===r&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},gXn=(t,e)=>{const r=t.pipelineDef[e].solverName,i=yXn(t,e),o=t[r],s=t.firstIterationOfPhase?.[r]??null,a=t.iterations;let c=0;if(i==="Completed"){const h=t.pipelineDef[e+1],f=h?t.firstIterationOfPhase?.[h.solverName]:void 0;f!==void 0&&s!==null?c=f-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[r]??0;let u=0;i==="Completed"?u=1:i==="In Progress"&&o&&(u=o.progress??0);const d=o?.stats??null;return{index:e,name:r,status:i,firstIteration:s,iterations:c,progress:u,timeSpent:l,stats:d&&Object.keys(d).length>0?d:null,solverInstance:o??null}},_Xn=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return G.jsx("span",{className:`font-medium ${e[t]}`,children:t})},xXn=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:G.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),G.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},bXn=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),vXn=({stats:t})=>{if(!t||Object.keys(t).length===0)return G.jsx("span",{children:"-"});const e=Object.entries(t),n=bXn(t);return G.jsxs("details",{className:"cursor-pointer",children:[G.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),G.jsx("div",{className:"mt-1 text-xs",children:e.map(([r,i])=>G.jsxs("div",{children:[r,": ",String(i)]},r))})]})},Z_e=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Z_e);const e={};for(const[n,r]of Object.entries(t))n.startsWith("_")||(e[n]=Z_e(r));return e},wXn=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Z_e(t.getConstructorParams()),r=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(r),o=document.createElement("a");o.href=i,o.download=`${e}_input.json`,o.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},SXn=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const r=t.pipelineDef.map((a,c)=>gXn(t,c)),i=a=>{e?.(a)},o=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):wXn(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return G.jsxs("div",{className:"border-t border-gray-200",children:[G.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:G.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),G.jsx("div",{className:"overflow-x-auto",children:G.jsxs("table",{className:"w-full text-sm",children:[G.jsx("thead",{children:G.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),G.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",G.jsx("sub",{children:"0"})]}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),G.jsx("tbody",{children:r.map(a=>G.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[G.jsx("td",{className:"px-4 py-2",children:G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),G.jsx("button",{onClick:()=>i(a.name),disabled:a.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${a.name} completes`,children:G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),G.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(_Xn,{status:a.status})}),G.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(xXn,{progress:a.progress})}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),G.jsx("td",{className:"px-4 py-2 text-gray-500",children:G.jsx(vXn,{stats:a.stats})}),G.jsx("td",{className:"px-4 py-2",children:a.solverInstance?G.jsxs("button",{onClick:()=>o(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),G.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},MXn=class extends si.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function TXn({graphics:t}){const e=t.points??[],n=t.lines??[],r=t.rects??[],i=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const u=(g,y)=>{typeof g=="number"&&(g<s&&(s=g),g>c&&(c=g)),typeof y=="number"&&(y<a&&(a=y),y>l&&(l=y))};for(const g of e)u(g.x,g.y);for(const g of n){const y=g.points??[];for(const _ of y)u(_.x,_.y)}for(const g of r){const y=g.x??0,_=g.y??0,x=g.width??0,b=g.height??0;u(y,_),u(y+x,_+b)}for(const g of i){const y=g.x??0,_=g.y??0,x=g.radius??1;u(y-x,_-x),u(y+x,_+x)}for(const g of o)u(g.x,g.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const d=10,h=s-d,f=a-d,p=Math.max(1,c-s+2*d),m=Math.max(1,l-a+2*d);return G.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${h} ${f} ${p} ${m}`,role:"img","aria-label":"Graphics fallback",children:[r.map((g,y)=>G.jsx("rect",{x:g.x??0,y:g.y??0,width:g.width??0,height:g.height??0,fill:"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1},`rect-${y}`)),n.map((g,y)=>G.jsx("polyline",{fill:"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1,points:(g.points??[]).map(_=>`${_.x??0},${_.y??0}`).join(" ")},`line-${y}`)),i.map((g,y)=>G.jsx("circle",{cx:g.x??0,cy:g.y??0,r:g.radius??1.5,fill:g.fillColor??"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1},`circle-${y}`)),e.map((g,y)=>G.jsx("circle",{cx:g.x??0,cy:g.y??0,r:g.radius??1.5,fill:g.color??"black"},`point-${y}`)),o.map((g,y)=>G.jsx("text",{x:g.x??0,y:g.y??0,fontSize:g.fontSize??10,fill:g.color??"black",children:g.text??""},`text-${y}`))]})}var EXn=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:r})=>{const[i,o]=te.useReducer(u=>u+1,0),s=te.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(u){return console.error("Visualization error:",u),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=te.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);te.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const u=document.createElement("script");u.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(u)}},[]);const c=t.pipelineDef!==void 0,l=u=>{const d=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&d.currentPipelineStepIndex<=d.pipelineDef.findIndex(h=>h.solverName===u);)t.step();o()}};return G.jsxs("div",{children:[G.jsx(mXn,{solver:t,triggerRender:o,animationSpeed:e,onSolverStarted:n,onSolverCompleted:r}),a?G.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):G.jsx(MXn,{fallback:G.jsx(TXn,{graphics:s}),children:G.jsx(hXn,{graphics:s})}),c&&G.jsx(SXn,{solver:t,onStepUntilPhase:l})]})};const CXn=()=>{te.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const r=document.createElement("script");r.id=t,r.src="https://cdn.tailwindcss.com",document.head.appendChild(r)},[])},PXn=t=>t.toLowerCase().includes("pack")?XMn:t.toLowerCase().includes("rout")?KMn:DMn,AXn=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);CXn();const r=te.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=te.useMemo(()=>Array.from(r.keys()),[r]),o=e?r.get(e):null,s=te.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const a=yae[o.solverName];if(!a)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(yae).join(", ")}`,classFound:!1};try{const c=o.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[o]);return t.length===0?G.jsx("div",{className:"rf-p-4",children:G.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),G.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):G.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[G.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[G.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=r.get(a),l=e===a;return G.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const u=PXn(c.solverName);return G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[G.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),G.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[G.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),G.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),G.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?G.jsx(Fb,{fallback:G.jsx("div",{className:"rf-p-4",children:G.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),G.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:G.jsx(EXn,{solver:s.instance})}):G.jsxs("div",{className:"rf-p-4",children:[G.jsxs("div",{className:"rf-mb-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),G.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&G.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:G.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),G.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[G.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:G.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),G.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:G.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):G.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:G.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},m0t=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const r=new Error(t);e&&(r.stack=e);try{iD.captureException(r)}catch{}}},[t,e]),te.useEffect(()=>{if(n&&n.length>0)for(const r of n){const i=new Error(r.message||"Circuit JSON Error");r.stack&&(i.stack=r.stack);try{iD.captureException(i,{error_type:r.type})}catch{}}},[n])},y0t="0.0.1798",RXn={version:y0t},K_e={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Q_e=new Map,_G=t=>{const e=Q_e.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,r])=>[n,r.getState()])):{}},IXn=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const r=Q_e.get(n.name);if(r)return{type:"tracked",store:t,...r};const i={connection:e.connect(n),stores:{}};return Q_e.set(n.name,i),{type:"tracked",store:t,...i}},g0t=(t,e={})=>(n,r,i)=>{const{enabled:o,anonymousActionType:s,store:a,...c}=e;let l;try{l=(o??(K_e?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(K_e?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,r,i);const{connection:u,...d}=IXn(a,l,c);let h=!0;i.setState=(m,g,y)=>{const _=n(m,g);if(!h)return _;const x=y===void 0?{type:s||"anonymous"}:typeof y=="string"?{type:y}:y;return a===void 0?(u?.send(x,r()),_):(u?.send({...x,type:`${a}/${x.type}`},{..._G(c.name),[a]:i.getState()}),_)};const f=(...m)=>{const g=h;h=!1,n(...m),h=g},p=t(i.setState,r,i);if(d.type==="untracked"?u?.init(p):(d.stores[d.store]=i,u?.init(Object.fromEntries(Object.entries(d.stores).map(([m,g])=>[m,m===d.store?p:g.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const g=i.dispatch;i.dispatch=(...y)=>{(K_e?"production":void 0)!=="production"&&y[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),g(...y)}}return u.subscribe(m=>{var g;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return J_e(m.payload,y=>{if(y.type==="__setState"){if(a===void 0){f(y.state);return}Object.keys(y.state).length!==1&&console.error(`
5674
+ `,d=new Blob([u],{type:"text/plain"}),h=URL.createObjectURL(d),f=document.createElement("a");f.href=h,f.download=`${l}.test.ts`,f.click(),URL.revokeObjectURL(h)}catch(c){alert(`Error generating test.ts for ${t.constructor.name}: ${c instanceof Error?c.message:String(c)}`)}r(!1)};return G.jsxs("div",{className:`relative ${e}`,ref:i,children:[G.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>r(!n),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),n&&G.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),G.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:a,children:"Download test.ts"})]})]})},f0t=t=>t.activeSubSolver?[t,...f0t(t.activeSubSolver)]:[t],fXn=({solver:t})=>{const e=f0t(t);return G.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:e.map((n,r)=>G.jsxs("div",{className:"flex items-center",children:[r>0&&G.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),G.jsx(pXn,{solver:n})]},n.constructor.name))})},mXn=({solver:t,triggerRender:e,animationSpeed:n=25,onSolverStarted:r,onSolverCompleted:i})=>{const[o,s]=te.useReducer(m=>!m,!1),a=te.useRef(void 0),c=()=>{!t.solved&&!t.failed&&(t.step(),e())},l=()=>{!t.solved&&!t.failed&&(r&&r(t),t.solve(),e(),i&&i(t))},u=()=>{o?(a.current&&(clearInterval(a.current),a.current=void 0),s()):(s(),a.current=setInterval(()=>{if(t.solved||t.failed){a.current&&(clearInterval(a.current),a.current=void 0),s(),e(),i&&t.solved&&i(t);return}t.step(),e()},n))},d=()=>{const m=t;if(m.getCurrentPhase&&!t.solved&&!t.failed){const g=m.getCurrentPhase();for(;m.getCurrentPhase()===g&&!t.solved&&!t.failed;)t.step();e()}},h=()=>{if(t.solved||t.failed||o)return;const m=window.prompt("Step until which iteration?",`${t.iterations}`);if(m===null)return;const g=Number(m);if(!Number.isFinite(g)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<g&&!t.solved&&!t.failed;)t.step();e(),t.solved&&i&&i(t)};te.useEffect(()=>()=>{a.current&&clearInterval(a.current)},[]),te.useEffect(()=>{(t.solved||t.failed)&&o&&(a.current&&(clearInterval(a.current),a.current=void 0),s())},[t.solved,t.failed,o]);const f=t.getCurrentPhase!==void 0,p=f?t.getCurrentPhase():null;return G.jsxs("div",{className:"space-y-2 p-2 border-b",children:[G.jsx("div",{className:"flex items-center",children:G.jsx(fXn,{solver:t})}),G.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[G.jsx("button",{onClick:c,disabled:t.solved||t.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),G.jsx("button",{onClick:l,disabled:t.solved||t.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),G.jsx("button",{onClick:u,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),G.jsx("button",{onClick:h,disabled:t.solved||t.failed||o,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),f&&G.jsx("button",{onClick:d,disabled:t.solved||t.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),G.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),p&&G.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",G.jsx("span",{className:"font-medium",children:p})]}),t.solved&&G.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&G.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&G.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},yXn=(t,e,n)=>{const r=t.currentPipelineStepIndex;return e<r?"Completed":e===r&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},gXn=(t,e)=>{const r=t.pipelineDef[e].solverName,i=yXn(t,e),o=t[r],s=t.firstIterationOfPhase?.[r]??null,a=t.iterations;let c=0;if(i==="Completed"){const h=t.pipelineDef[e+1],f=h?t.firstIterationOfPhase?.[h.solverName]:void 0;f!==void 0&&s!==null?c=f-s:s!==null&&(c=a-s)}else i==="In Progress"&&s!==null&&(c=a-s);const l=t.timeSpentOnPhase?.[r]??0;let u=0;i==="Completed"?u=1:i==="In Progress"&&o&&(u=o.progress??0);const d=o?.stats??null;return{index:e,name:r,status:i,firstIteration:s,iterations:c,progress:u,timeSpent:l,stats:d&&Object.keys(d).length>0?d:null,solverInstance:o??null}},_Xn=({status:t})=>{const e={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return G.jsx("span",{className:`font-medium ${e[t]}`,children:t})},xXn=({progress:t})=>{if(t===0)return null;const e=Math.round(t*100);return G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:G.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${e}%`}})}),G.jsxs("span",{className:"text-xs text-gray-500",children:[e,"%"]})]})},bXn=t=>Object.entries(t).map(([e,n])=>`${e}: ${n}`).join(", "),vXn=({stats:t})=>{if(!t||Object.keys(t).length===0)return G.jsx("span",{children:"-"});const e=Object.entries(t),n=bXn(t);return G.jsxs("details",{className:"cursor-pointer",children:[G.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:n}),G.jsx("div",{className:"mt-1 text-xs",children:e.map(([r,i])=>G.jsxs("div",{children:[r,": ",String(i)]},r))})]})},Z_e=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(Z_e);const e={};for(const[n,r]of Object.entries(t))n.startsWith("_")||(e[n]=Z_e(r));return e},wXn=(t,e)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${e}`);return}const n=Z_e(t.getConstructorParams()),r=new Blob([JSON.stringify(n,null,2)],{type:"application/json"}),i=URL.createObjectURL(r),o=document.createElement("a");o.href=i,o.download=`${e}_input.json`,o.click(),URL.revokeObjectURL(i)}catch(n){alert(`Error downloading input for ${e}: ${n instanceof Error?n.message:String(n)}`)}},SXn=({solver:t,onStepUntilPhase:e,onDownloadInput:n})=>{const r=t.pipelineDef.map((a,c)=>gXn(t,c)),i=a=>{e?.(a)},o=a=>{a.solverInstance&&(n?n(a.solverInstance,a.name):wXn(a.solverInstance,a.name))},s=a=>`${(a/1e3).toFixed(2)}s`;return G.jsxs("div",{className:"border-t border-gray-200",children:[G.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:G.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),G.jsx("div",{className:"overflow-x-auto",children:G.jsxs("table",{className:"w-full text-sm",children:[G.jsx("thead",{children:G.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),G.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",G.jsx("sub",{children:"0"})]}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),G.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),G.jsx("tbody",{children:r.map(a=>G.jsxs("tr",{className:`border-b border-gray-100 ${a.status==="In Progress"?"bg-yellow-50":""}`,children:[G.jsx("td",{className:"px-4 py-2",children:G.jsxs("div",{className:"flex items-center gap-2",children:[G.jsx("span",{className:"text-gray-400 w-6",children:String(a.index+1).padStart(2,"0")}),G.jsx("button",{onClick:()=>i(a.name),disabled:a.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${a.name} completes`,children:G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),G.jsx("span",{className:"font-medium text-gray-900",children:a.name})]})}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(_Xn,{status:a.status})}),G.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:a.firstIteration!==null?a.firstIteration:""}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:a.iterations}),G.jsx("td",{className:"px-4 py-2",children:G.jsx(xXn,{progress:a.progress})}),G.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(a.timeSpent)}),G.jsx("td",{className:"px-4 py-2 text-gray-500",children:G.jsx(vXn,{stats:a.stats})}),G.jsx("td",{className:"px-4 py-2",children:a.solverInstance?G.jsxs("button",{onClick:()=>o(a),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${a.name}`,children:[G.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:G.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),G.jsx("span",{children:"Input"})]}):null})]},a.name))})]})})]})},MXn=class extends si.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function TXn({graphics:t}){const e=t.points??[],n=t.lines??[],r=t.rects??[],i=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY;const u=(g,y)=>{typeof g=="number"&&(g<s&&(s=g),g>c&&(c=g)),typeof y=="number"&&(y<a&&(a=y),y>l&&(l=y))};for(const g of e)u(g.x,g.y);for(const g of n){const y=g.points??[];for(const _ of y)u(_.x,_.y)}for(const g of r){const y=g.x??0,_=g.y??0,x=g.width??0,b=g.height??0;u(y,_),u(y+x,_+b)}for(const g of i){const y=g.x??0,_=g.y??0,x=g.radius??1;u(y-x,_-x),u(y+x,_+x)}for(const g of o)u(g.x,g.y);(!isFinite(s)||!isFinite(a)||!isFinite(c)||!isFinite(l))&&(s=-20,a=-20,c=20,l=20);const d=10,h=s-d,f=a-d,p=Math.max(1,c-s+2*d),m=Math.max(1,l-a+2*d);return G.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${h} ${f} ${p} ${m}`,role:"img","aria-label":"Graphics fallback",children:[r.map((g,y)=>G.jsx("rect",{x:g.x??0,y:g.y??0,width:g.width??0,height:g.height??0,fill:"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1},`rect-${y}`)),n.map((g,y)=>G.jsx("polyline",{fill:"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1,points:(g.points??[]).map(_=>`${_.x??0},${_.y??0}`).join(" ")},`line-${y}`)),i.map((g,y)=>G.jsx("circle",{cx:g.x??0,cy:g.y??0,r:g.radius??1.5,fill:g.fillColor??"none",stroke:g.strokeColor??"black",strokeWidth:g.strokeWidth??1},`circle-${y}`)),e.map((g,y)=>G.jsx("circle",{cx:g.x??0,cy:g.y??0,r:g.radius??1.5,fill:g.color??"black"},`point-${y}`)),o.map((g,y)=>G.jsx("text",{x:g.x??0,y:g.y??0,fontSize:g.fontSize??10,fill:g.color??"black",children:g.text??""},`text-${y}`))]})}var EXn=({solver:t,animationSpeed:e=25,onSolverStarted:n,onSolverCompleted:r})=>{const[i,o]=te.useReducer(u=>u+1,0),s=te.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(u){return console.error("Visualization error:",u),{points:[],lines:[],rects:[],circles:[]}}},[t,i]),a=te.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);te.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const u=document.createElement("script");u.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(u)}},[]);const c=t.pipelineDef!==void 0,l=u=>{const d=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&d.currentPipelineStepIndex<=d.pipelineDef.findIndex(h=>h.solverName===u);)t.step();o()}};return G.jsxs("div",{children:[G.jsx(mXn,{solver:t,triggerRender:o,animationSpeed:e,onSolverStarted:n,onSolverCompleted:r}),a?G.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):G.jsx(MXn,{fallback:G.jsx(TXn,{graphics:s}),children:G.jsx(hXn,{graphics:s})}),c&&G.jsx(SXn,{solver:t,onStepUntilPhase:l})]})};const CXn=()=>{te.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const e=document.createElement("div");e.className="hidden",document.body.appendChild(e);const n=window.getComputedStyle(e).display==="none";if(document.body.removeChild(e),n)return;const r=document.createElement("script");r.id=t,r.src="https://cdn.tailwindcss.com",document.head.appendChild(r)},[])},PXn=t=>t.toLowerCase().includes("pack")?XMn:t.toLowerCase().includes("rout")?KMn:DMn,AXn=({solverEvents:t=[]})=>{const[e,n]=te.useState(null);CXn();const r=te.useMemo(()=>{const a=new Map;for(const c of t){const l=`${c.componentName}-${c.solverName}`;a.set(l,c)}return a},[t]),i=te.useMemo(()=>Array.from(r.keys()),[r]),o=e?r.get(e):null,s=te.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const a=yae[o.solverName];if(!a)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(yae).join(", ")}`,classFound:!1};try{const c=o.solverParams,l=c?.input!==void 0?c.input:c;return{instance:new a(l),error:null,classFound:!0}}catch(c){const l=c instanceof Error?c.message:String(c);return console.error("Failed to reconstruct solver:",c),{instance:null,error:`Failed to instantiate solver: ${l}`,classFound:!0}}},[o]);return t.length===0?G.jsx("div",{className:"rf-p-4",children:G.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:G.jsxs("div",{className:"rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),G.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):G.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[G.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[G.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[i.length," ",i.length===1?"Solver":"Solvers"]}),i.map(a=>{const c=r.get(a),l=e===a;return G.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${l?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>n(a),children:(()=>{const u=PXn(c.solverName);return G.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[G.jsx(u,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),G.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[G.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:c.componentName}),G.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:c.solverName})]})]})})()},a)})]}),G.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?G.jsx(Fb,{fallback:G.jsx("div",{className:"rf-p-4",children:G.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),G.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:G.jsx(EXn,{solver:s.instance})}):G.jsxs("div",{className:"rf-p-4",children:[G.jsxs("div",{className:"rf-mb-4",children:[G.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),G.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&G.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:G.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),G.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[G.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:G.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),G.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:G.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):G.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:G.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},m0t=({errorMessage:t,errorStack:e,circuitJsonErrors:n})=>{te.useEffect(()=>{if(t){const r=new Error(t);e&&(r.stack=e);try{iD.captureException(r)}catch{}}},[t,e]),te.useEffect(()=>{if(n&&n.length>0)for(const r of n){const i=new Error(r.message||"Circuit JSON Error");r.stack&&(i.stack=r.stack);try{iD.captureException(i,{error_type:r.type})}catch{}}},[n])},y0t="0.0.1800",RXn={version:y0t},K_e={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Q_e=new Map,_G=t=>{const e=Q_e.get(t);return e?Object.fromEntries(Object.entries(e.stores).map(([n,r])=>[n,r.getState()])):{}},IXn=(t,e,n)=>{if(t===void 0)return{type:"untracked",connection:e.connect(n)};const r=Q_e.get(n.name);if(r)return{type:"tracked",store:t,...r};const i={connection:e.connect(n),stores:{}};return Q_e.set(n.name,i),{type:"tracked",store:t,...i}},g0t=(t,e={})=>(n,r,i)=>{const{enabled:o,anonymousActionType:s,store:a,...c}=e;let l;try{l=(o??(K_e?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!l)return(K_e?"production":void 0)!=="production"&&o&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),t(n,r,i);const{connection:u,...d}=IXn(a,l,c);let h=!0;i.setState=(m,g,y)=>{const _=n(m,g);if(!h)return _;const x=y===void 0?{type:s||"anonymous"}:typeof y=="string"?{type:y}:y;return a===void 0?(u?.send(x,r()),_):(u?.send({...x,type:`${a}/${x.type}`},{..._G(c.name),[a]:i.getState()}),_)};const f=(...m)=>{const g=h;h=!1,n(...m),h=g},p=t(i.setState,r,i);if(d.type==="untracked"?u?.init(p):(d.stores[d.store]=i,u?.init(Object.fromEntries(Object.entries(d.stores).map(([m,g])=>[m,m===d.store?p:g.getState()])))),i.dispatchFromDevtools&&typeof i.dispatch=="function"){let m=!1;const g=i.dispatch;i.dispatch=(...y)=>{(K_e?"production":void 0)!=="production"&&y[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),g(...y)}}return u.subscribe(m=>{var g;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return J_e(m.payload,y=>{if(y.type==="__setState"){if(a===void 0){f(y.state);return}Object.keys(y.state).length!==1&&console.error(`
5675
5675
  [zustand devtools middleware] Unsupported __setState action format.
5676
5676
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5677
5677
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }