@tscircuit/runframe 0.0.1798 → 0.0.1800

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.1797";
1733
+ var version = "0.0.1799";
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-4E6GLJQY.js";
11
+ } from "./chunk-YVZ7SK3I.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-4E6GLJQY.js";
37
+ } from "./chunk-YVZ7SK3I.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 { useEffect, useReducer, useRef as useRef2, useState } from "react";
44
+ import { useCallback as useCallback2, 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,9 +346,10 @@ var RunFrame = (props) => {
346
346
  );
347
347
  const setLastRunEvalVersion = useRunnerStore((s) => s.setLastRunEvalVersion);
348
348
  const lastRunCountTriggerRef = useRef2(0);
349
- const runMutex = useMutex();
349
+ const { runWithMutex, cancel: cancelRunMutex } = useMutex();
350
350
  const [isRunning, setIsRunning] = useState(false);
351
351
  const [dependenciesLoaded, setDependenciesLoaded] = useState(false);
352
+ const lastMainComponentPathRef = useRef2(null);
352
353
  const [activeAsyncEffects, setActiveAsyncEffects] = useState({});
353
354
  const [currentDebugOption, setCurrentDebugOption] = useState("");
354
355
  const [showSchematicDebugGrid, setShowSchematicDebugGrid] = useState(false);
@@ -359,6 +360,21 @@ var RunFrame = (props) => {
359
360
  const emitRunCompleted = (payload) => {
360
361
  props.onRunCompleted?.(payload);
361
362
  };
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]);
362
378
  useEffect(() => {
363
379
  const handleKeyDown = (e) => {
364
380
  if ((e.ctrlKey || e.metaKey) && e.key === "Enter" && !isRunning) {
@@ -460,13 +476,21 @@ var RunFrame = (props) => {
460
476
  setIsRunning(false);
461
477
  return;
462
478
  }
479
+ const currentMainComponentPath = props.mainComponentPath ?? null;
463
480
  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
+ }
464
486
  if (lastFsMapRef.current && circuitJson) {
465
487
  const changes = getChangesBetweenFsMaps(lastFsMapRef.current, fsMap);
466
488
  if (Object.keys(changes).length > 0) {
467
489
  debug("code changes detected");
468
490
  } else if (lastEntrypointRef.current !== props.entrypoint) {
469
491
  debug("render triggered by entrypoint change");
492
+ } else if (wasTriggeredByMainComponentChange) {
493
+ debug("render triggered by mainComponentPath change");
470
494
  } else if (!wasTriggeredByRunButton) {
471
495
  debug("render triggered without changes to fsMap, skipping");
472
496
  return;
@@ -477,6 +501,7 @@ var RunFrame = (props) => {
477
501
  }
478
502
  lastFsMapRef.current = fsMap;
479
503
  lastEntrypointRef.current = props.entrypoint ?? null;
504
+ lastMainComponentPathRef.current = currentMainComponentPath;
480
505
  lastRunCountTriggerRef.current = runCountTrigger;
481
506
  setIsRunning(true);
482
507
  const runWorker = async () => {
@@ -487,9 +512,10 @@ var RunFrame = (props) => {
487
512
  setSolverEvents([]);
488
513
  const renderLog2 = { progress: 0, debugOutputs: [] };
489
514
  let cancelled = false;
490
- cancelExecutionRef.current = () => {
515
+ const cancelCurrentExecution = () => {
491
516
  cancelled = true;
492
517
  };
518
+ cancelExecutionRef.current = cancelCurrentExecution;
493
519
  const resolvedEvalVersion = await resolveEvalVersion(
494
520
  props.evalVersion,
495
521
  !globalThis.runFrameWorker && props.forceLatestEvalVersion
@@ -607,6 +633,10 @@ var RunFrame = (props) => {
607
633
  }).then(() => {
608
634
  return { success: true };
609
635
  }).catch((e) => {
636
+ if (cancelled) {
637
+ debug("execution cancelled");
638
+ return { success: false };
639
+ }
610
640
  const message = e.message.replace("Error: ", "");
611
641
  debug(`eval error: ${message}`);
612
642
  props.onError?.(e);
@@ -618,13 +648,19 @@ var RunFrame = (props) => {
618
648
  });
619
649
  debug("worker call started");
620
650
  if (!evalResult.success) {
621
- setIsRunning(false);
622
- setActiveAsyncEffects({});
651
+ if (!cancelled) {
652
+ setIsRunning(false);
653
+ setActiveAsyncEffects({});
654
+ }
623
655
  return;
624
656
  }
625
657
  const $renderResult = worker.renderUntilSettled();
626
658
  debug("waiting for initial circuit json...");
627
659
  let circuitJson2 = await worker.getCircuitJson().catch((e) => {
660
+ if (cancelled) {
661
+ debug("initial circuit json request cancelled");
662
+ return null;
663
+ }
628
664
  debug("error getting initial circuit json", e);
629
665
  props.onError?.(e);
630
666
  emitRunCompleted(buildRunCompletedPayload({ executionError: e }));
@@ -635,13 +671,28 @@ var RunFrame = (props) => {
635
671
  return null;
636
672
  });
637
673
  if (!circuitJson2) return;
674
+ if (cancelled) return;
638
675
  debug("got initial circuit json");
639
676
  setCircuitJson(circuitJson2);
640
677
  props.onCircuitJsonChange?.(circuitJson2);
641
678
  props.onInitialRender?.({ circuitJson: circuitJson2 });
642
- await $renderResult;
679
+ await $renderResult.catch((e) => {
680
+ if (cancelled) {
681
+ debug("render cancelled");
682
+ return null;
683
+ }
684
+ throw e;
685
+ });
686
+ if (cancelled) return;
643
687
  debug("getting final circuit json");
644
- circuitJson2 = await worker.getCircuitJson();
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;
645
696
  props.onCircuitJsonChange?.(circuitJson2);
646
697
  setCircuitJson(circuitJson2);
647
698
  emitRunCompleted(buildRunCompletedPayload({ circuitJson: circuitJson2 }));
@@ -656,12 +707,16 @@ var RunFrame = (props) => {
656
707
  if (!cancelled) {
657
708
  setRenderLog({ ...renderLog2 });
658
709
  }
659
- setIsRunning(false);
660
- setActiveAsyncEffects({});
661
- setCurrentDebugOption("");
662
- cancelExecutionRef.current = null;
710
+ if (!cancelled) {
711
+ setIsRunning(false);
712
+ setActiveAsyncEffects({});
713
+ setCurrentDebugOption("");
714
+ }
715
+ if (cancelExecutionRef.current === cancelCurrentExecution) {
716
+ cancelExecutionRef.current = null;
717
+ }
663
718
  };
664
- runMutex.runWithMutex(runWorker);
719
+ runWithMutex(runWorker);
665
720
  }, [
666
721
  props.fsMap,
667
722
  props.entrypoint,
@@ -670,7 +725,10 @@ var RunFrame = (props) => {
670
725
  props.mainComponentPath,
671
726
  props.isLoadingFiles,
672
727
  currentDebugOption,
673
- isStaticCircuitJson
728
+ isStaticCircuitJson,
729
+ isRunning,
730
+ runWithMutex,
731
+ stopActiveRender
674
732
  ]);
675
733
  const lastEditEventRef = useRef2(null);
676
734
  const dragTimeout = useRef2(null);
@@ -777,19 +835,7 @@ var RunFrame = (props) => {
777
835
  {
778
836
  onClick: (e) => {
779
837
  e.stopPropagation();
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
- }
838
+ stopActiveRender();
793
839
  },
794
840
  variant: "ghost",
795
841
  size: "icon",
@@ -861,7 +907,7 @@ import { applyEditEventsToManualEditsFile } from "@tscircuit/core";
861
907
  import Debug3 from "debug";
862
908
 
863
909
  // lib/hooks/use-edit-event-controller.ts
864
- import { useState as useState2, useCallback as useCallback2, useEffect as useEffect2 } from "react";
910
+ import { useState as useState2, useCallback as useCallback3, useEffect as useEffect2 } from "react";
865
911
  var debug2 = debug_default.extend("useEditEventController");
866
912
  var useEditEventController = () => {
867
913
  const applyEditEventsAndUpdateManualEditsJson = useRunFrameStore(
@@ -872,26 +918,26 @@ var useEditEventController = () => {
872
918
  const unappliedEditEvents = editEvents.filter((ee) => !ee._applied);
873
919
  const appliedEditEvents = editEvents.filter((ee) => ee._applied);
874
920
  const editEventsForRender = isRendering ? editEvents : unappliedEditEvents;
875
- const pushEditEvent = useCallback2((ee) => {
921
+ const pushEditEvent = useCallback3((ee) => {
876
922
  setEditEvents((prev) => [...prev, { ...ee, _applied: false }]);
877
923
  }, []);
878
- const markEditEventApplied = useCallback2((ee) => {
924
+ const markEditEventApplied = useCallback3((ee) => {
879
925
  setEditEvents(
880
926
  (prev) => prev.map(
881
927
  (event) => event === ee ? { ...event, _applied: true } : event
882
928
  )
883
929
  );
884
930
  }, []);
885
- const markAllEditEventsApplied = useCallback2(() => {
931
+ const markAllEditEventsApplied = useCallback3(() => {
886
932
  setEditEvents((prev) => prev.map((ee) => ({ ...ee, _applied: true })));
887
933
  }, []);
888
- const markRenderStarted = useCallback2(() => {
934
+ const markRenderStarted = useCallback3(() => {
889
935
  setIsRendering(true);
890
936
  if (editEvents.length === 0) return;
891
937
  debug2("removing edit events that are applied");
892
938
  setEditEvents((prev) => prev.filter((ee) => !ee._applied));
893
939
  }, [editEvents]);
894
- const markRenderComplete = useCallback2(() => {
940
+ const markRenderComplete = useCallback3(() => {
895
941
  setIsRendering(false);
896
942
  }, []);
897
943
  useEffect2(() => {
@@ -983,7 +1029,7 @@ var useSyncPageTitle = () => {
983
1029
  };
984
1030
 
985
1031
  // lib/components/RunFrameWithApi/RunFrameWithApi.tsx
986
- import { useCallback as useCallback4, useEffect as useEffect7, useMemo as useMemo4, useState as useState6 } from "react";
1032
+ import { useCallback as useCallback5, useEffect as useEffect7, useMemo as useMemo4, useState as useState6 } from "react";
987
1033
 
988
1034
  // lib/utils/get-board-files-from-config.ts
989
1035
  import { projectConfig } from "@tscircuit/props";
@@ -1027,7 +1073,7 @@ import {
1027
1073
  Folder,
1028
1074
  Save
1029
1075
  } from "lucide-react";
1030
- import { useCallback as useCallback3, useEffect as useEffect6, useMemo as useMemo3, useRef as useRef3, useState as useState5 } from "react";
1076
+ import { useCallback as useCallback4, useEffect as useEffect6, useMemo as useMemo3, useRef as useRef3, useState as useState5 } from "react";
1031
1077
 
1032
1078
  // lib/components/ui/command.tsx
1033
1079
  import * as React2 from "react";
@@ -1395,7 +1441,7 @@ var EnhancedFileSelectorCombobox = ({
1395
1441
  navigateToFolder(folderPath);
1396
1442
  setCurrentFileIndex(0);
1397
1443
  };
1398
- const navigateUp = useCallback3(() => {
1444
+ const navigateUp = useCallback4(() => {
1399
1445
  if (!currentFolder) return;
1400
1446
  const lastSlashIndex = currentFolder.lastIndexOf("/");
1401
1447
  const parentPath = lastSlashIndex === -1 ? null : currentFolder.substring(0, lastSlashIndex);
@@ -1412,7 +1458,7 @@ var EnhancedFileSelectorCombobox = ({
1412
1458
  window.addEventListener("keydown", handleKeyDown);
1413
1459
  return () => window.removeEventListener("keydown", handleKeyDown);
1414
1460
  }, [open, navigateUp]);
1415
- const selectFile = useCallback3(
1461
+ const selectFile = useCallback4(
1416
1462
  (filePath, index, updateFolder = false) => {
1417
1463
  setFile(filePath);
1418
1464
  setCurrentFileIndex(index);
@@ -1798,7 +1844,7 @@ var RunFrameWithApi = (props) => {
1798
1844
  []
1799
1845
  );
1800
1846
  const isLoadingFiles = !hasReceivedInitialFiles;
1801
- const handleToggleFavorite = useCallback4(
1847
+ const handleToggleFavorite = useCallback5(
1802
1848
  (filePath) => {
1803
1849
  setFavorites(
1804
1850
  (prev) => prev.includes(filePath) ? prev.filter((f) => f !== filePath) : [...prev, filePath]
@@ -1847,7 +1893,7 @@ var RunFrameWithApi = (props) => {
1847
1893
  props.initialMainComponentPath,
1848
1894
  componentPath
1849
1895
  ]);
1850
- const updateFileHash = useCallback4((filePath) => {
1896
+ const updateFileHash = useCallback5((filePath) => {
1851
1897
  if (typeof window === "undefined") return;
1852
1898
  const params = new URLSearchParams(window.location.hash.slice(1));
1853
1899
  if (params.get("file") === filePath) return;
@@ -1889,7 +1935,7 @@ var RunFrameWithApi = (props) => {
1889
1935
  } : {},
1890
1936
  [componentPath]
1891
1937
  );
1892
- const handleRunCompleted = useCallback4(
1938
+ const handleRunCompleted = useCallback5(
1893
1939
  async (payload) => {
1894
1940
  try {
1895
1941
  await pushEvent({
@@ -1984,10 +2030,10 @@ var RunFrameWithApi = (props) => {
1984
2030
  };
1985
2031
 
1986
2032
  // lib/components/RunFrameForCli/RunFrameForCli.tsx
1987
- import { useCallback as useCallback6, useState as useState8 } from "react";
2033
+ import { useCallback as useCallback7, useState as useState8 } from "react";
1988
2034
 
1989
2035
  // lib/components/RunFrameForCli/LoginDialog.tsx
1990
- import { useCallback as useCallback5, useEffect as useEffect8, useRef as useRef4, useState as useState7 } from "react";
2036
+ import { useCallback as useCallback6, useEffect as useEffect8, useRef as useRef4, useState as useState7 } from "react";
1991
2037
  import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
1992
2038
  var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
1993
2039
  var LoginDialog = ({
@@ -2007,7 +2053,7 @@ var LoginDialog = ({
2007
2053
  }
2008
2054
  };
2009
2055
  }, []);
2010
- const handleSignIn = useCallback5(async () => {
2056
+ const handleSignIn = useCallback6(async () => {
2011
2057
  setLoginState("creating");
2012
2058
  setErrorMessage(null);
2013
2059
  abortControllerRef.current = new AbortController();
@@ -2081,7 +2127,7 @@ var LoginDialog = ({
2081
2127
  toast.error(message);
2082
2128
  }
2083
2129
  }, [pushEvent, onLoginSuccess, onClose]);
2084
- const handleCancel = useCallback5(() => {
2130
+ const handleCancel = useCallback6(() => {
2085
2131
  if (abortControllerRef.current) {
2086
2132
  abortControllerRef.current.abort();
2087
2133
  }
@@ -2149,13 +2195,13 @@ var LoginDialog = ({
2149
2195
  };
2150
2196
  var useLoginDialog = () => {
2151
2197
  const [isOpen, setIsOpen] = useState7(false);
2152
- const openLoginDialog = useCallback5(() => {
2198
+ const openLoginDialog = useCallback6(() => {
2153
2199
  setIsOpen(true);
2154
2200
  }, []);
2155
- const closeLoginDialog = useCallback5(() => {
2201
+ const closeLoginDialog = useCallback6(() => {
2156
2202
  setIsOpen(false);
2157
2203
  }, []);
2158
- const handleLoginSuccess = useCallback5(() => {
2204
+ const handleLoginSuccess = useCallback6(() => {
2159
2205
  setIsOpen(false);
2160
2206
  }, []);
2161
2207
  return {
@@ -2183,7 +2229,7 @@ var RunFrameForCli = (props) => {
2183
2229
  const params = new URLSearchParams(window.location.hash.slice(1));
2184
2230
  return params.get("main_component") ?? void 0;
2185
2231
  });
2186
- const updateMainComponentHash = useCallback6((mainComponentPath) => {
2232
+ const updateMainComponentHash = useCallback7((mainComponentPath) => {
2187
2233
  if (typeof window === "undefined") return;
2188
2234
  const params = new URLSearchParams(window.location.hash.slice(1));
2189
2235
  if (params.get("main_component") === mainComponentPath) return;
@@ -2814,7 +2860,7 @@ var ImportComponentDialog = ({
2814
2860
  };
2815
2861
 
2816
2862
  // lib/components/RunFrameStaticBuildViewer/RunFrameStaticBuildViewer.tsx
2817
- import { useCallback as useCallback7, useEffect as useEffect10, useState as useState10 } from "react";
2863
+ import { useCallback as useCallback8, useEffect as useEffect10, useState as useState10 } from "react";
2818
2864
 
2819
2865
  // lib/components/RunFrameStaticBuildViewer/CircuitJsonFileSelectorCombobox.tsx
2820
2866
  import { jsx as jsx12 } from "react/jsx-runtime";
@@ -2854,7 +2900,7 @@ var RunFrameStaticBuildViewer = (props) => {
2854
2900
  const [failedFiles, setFailedFiles] = useState10(/* @__PURE__ */ new Set());
2855
2901
  const fileReferences = props.files;
2856
2902
  const availableFiles = fileReferences.map((f) => f.filePath);
2857
- const defaultFetchFile = useCallback7(
2903
+ const defaultFetchFile = useCallback8(
2858
2904
  async (fileRef) => {
2859
2905
  if (!fileRef.fileStaticAssetUrl) {
2860
2906
  throw new Error(
@@ -2871,7 +2917,7 @@ var RunFrameStaticBuildViewer = (props) => {
2871
2917
  },
2872
2918
  []
2873
2919
  );
2874
- const loadCircuitJsonFile = useCallback7(
2920
+ const loadCircuitJsonFile = useCallback8(
2875
2921
  async (filePath) => {
2876
2922
  if (fileCache[filePath]) {
2877
2923
  setCircuitJson(fileCache[filePath]);
@@ -2938,10 +2984,10 @@ var RunFrameStaticBuildViewer = (props) => {
2938
2984
  loadCircuitJsonFile(selectedPath);
2939
2985
  }
2940
2986
  }, [currentCircuitJsonPath]);
2941
- const handleFileChange = useCallback7((newPath) => {
2987
+ const handleFileChange = useCallback8((newPath) => {
2942
2988
  setCurrentCircuitJsonPath(newPath);
2943
2989
  }, []);
2944
- const retryFailedFile = useCallback7(
2990
+ const retryFailedFile = useCallback8(
2945
2991
  (filePath) => {
2946
2992
  setFailedFiles((prev) => {
2947
2993
  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.1797",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.1799",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" } } }