@tscircuit/runframe 0.0.898 → 0.0.900

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.
@@ -1225,13 +1225,52 @@ var RenderTimingsBar_default = RenderTimingsBar;
1225
1225
  // lib/components/RenderLogViewer/RenderLogViewer.tsx
1226
1226
  import { jsx as jsx16, jsxs as jsxs11 } from "react/jsx-runtime";
1227
1227
  var RenderLogViewer = ({
1228
- renderLog
1228
+ renderLog,
1229
+ onRerunWithDebug
1229
1230
  }) => {
1230
1231
  const [sortOption, setSortOption] = useState4(
1231
1232
  "chronological"
1232
1233
  );
1234
+ const [selectedDebugOption, setSelectedDebugOption] = useState4("");
1235
+ const debugOptions = [
1236
+ { value: "", label: "None" },
1237
+ {
1238
+ value: "DEBUG=Group_doInitialSchematicTraceRender",
1239
+ label: "DEBUG=Group_doInitialSchematicTraceRender"
1240
+ },
1241
+ {
1242
+ value: "DEBUG=Group_doInitialSchematicLayoutMatchpack",
1243
+ label: "DEBUG=Group_doInitialSchematicLayoutMatchpack"
1244
+ },
1245
+ {
1246
+ value: "DEBUG=Group_doInitialPcbLayoutPack",
1247
+ label: "DEBUG=Group_doInitialPcbLayoutPack"
1248
+ }
1249
+ ];
1233
1250
  if (!renderLog)
1234
- return /* @__PURE__ */ jsx16("div", { className: "rf-p-4 rf-bg-gray-100 rf-rounded-md", children: "No render log, make sure this tab is open when you render (TODO add a rerender button here)" });
1251
+ return /* @__PURE__ */ jsxs11("div", { className: "rf-p-4 rf-bg-gray-100 rf-rounded-md", children: [
1252
+ /* @__PURE__ */ jsx16("div", { className: "rf-mb-4", children: "No render log, make sure this tab is open when you render" }),
1253
+ onRerunWithDebug && /* @__PURE__ */ jsxs11("div", { className: "rf-flex rf-gap-2 rf-items-center", children: [
1254
+ /* @__PURE__ */ jsx16(
1255
+ "select",
1256
+ {
1257
+ value: selectedDebugOption,
1258
+ onChange: (e) => setSelectedDebugOption(e.target.value),
1259
+ className: "rf-px-3 rf-py-1 rf-border rf-rounded rf-text-xs rf-bg-white",
1260
+ children: debugOptions.map((option) => /* @__PURE__ */ jsx16("option", { value: option.value, children: option.label }, option.value))
1261
+ }
1262
+ ),
1263
+ /* @__PURE__ */ jsx16(
1264
+ Button,
1265
+ {
1266
+ onClick: () => onRerunWithDebug(selectedDebugOption),
1267
+ size: "sm",
1268
+ className: "rf-text-xs",
1269
+ children: "Rerun Render with Debug"
1270
+ }
1271
+ )
1272
+ ] })
1273
+ ] });
1235
1274
  const orderedPhaseTimings = Object.entries(renderLog?.phaseTimings ?? {});
1236
1275
  if (sortOption === "chronological") {
1237
1276
  orderedPhaseTimings.sort(
@@ -1245,22 +1284,76 @@ var RenderLogViewer = ({
1245
1284
  0
1246
1285
  );
1247
1286
  return /* @__PURE__ */ jsxs11("div", { className: "rf-bg-white", children: [
1248
- /* @__PURE__ */ jsxs11("div", { className: "rf-flex rf-justify-between rf-items-center", children: [
1287
+ /* @__PURE__ */ jsxs11("div", { className: "rf-flex rf-justify-between rf-items-center rf-mb-4", children: [
1249
1288
  /* @__PURE__ */ jsx16("div", { children: "Render Logs" }),
1250
- /* @__PURE__ */ jsxs11("div", { className: "rf-mb-4 rf-pr-2 rf-flex rf-text-xs rf-items-center", children: [
1251
- /* @__PURE__ */ jsx16("div", { className: "rf-mr-2", children: "Sort by:" }),
1252
- /* @__PURE__ */ jsxs11(
1289
+ /* @__PURE__ */ jsxs11("div", { className: "rf-flex rf-gap-4 rf-items-center", children: [
1290
+ onRerunWithDebug && /* @__PURE__ */ jsxs11("div", { className: "rf-flex rf-gap-2 rf-items-center", children: [
1291
+ /* @__PURE__ */ jsx16(
1292
+ "select",
1293
+ {
1294
+ value: selectedDebugOption,
1295
+ onChange: (e) => setSelectedDebugOption(e.target.value),
1296
+ className: "rf-px-3 rf-py-1 rf-border rf-rounded rf-text-xs rf-bg-white",
1297
+ children: debugOptions.map((option) => /* @__PURE__ */ jsx16("option", { value: option.value, children: option.label }, option.value))
1298
+ }
1299
+ ),
1300
+ /* @__PURE__ */ jsx16(
1301
+ Button,
1302
+ {
1303
+ onClick: () => onRerunWithDebug(selectedDebugOption),
1304
+ size: "sm",
1305
+ className: "rf-text-xs",
1306
+ children: "Rerun Render with Debug"
1307
+ }
1308
+ )
1309
+ ] }),
1310
+ /* @__PURE__ */ jsx16("div", { className: "rf-flex rf-gap-2 rf-items-center", children: /* @__PURE__ */ jsxs11(
1253
1311
  "select",
1254
1312
  {
1255
- value: sortOption,
1256
- onChange: (e) => setSortOption(e.target.value),
1257
- className: "rf-px-2 rf-py-1 rf-border rf-rounded rf-text-xs",
1313
+ onChange: (e) => {
1314
+ if (e.target.value) {
1315
+ const debugOutput = renderLog?.debugOutputs?.find(
1316
+ (output) => output.name === e.target.value
1317
+ );
1318
+ if (debugOutput) {
1319
+ const blob = new Blob([debugOutput.content], {
1320
+ type: "text/plain"
1321
+ });
1322
+ const url = URL.createObjectURL(blob);
1323
+ const a = document.createElement("a");
1324
+ a.href = url;
1325
+ a.download = `debug-${debugOutput.name}.txt`;
1326
+ document.body.appendChild(a);
1327
+ a.click();
1328
+ document.body.removeChild(a);
1329
+ URL.revokeObjectURL(url);
1330
+ }
1331
+ e.target.value = "";
1332
+ }
1333
+ },
1334
+ disabled: !renderLog?.debugOutputs || renderLog.debugOutputs.length === 0,
1335
+ className: "rf-px-3 rf-py-1 rf-border rf-rounded rf-text-xs rf-bg-white disabled:rf-opacity-50 disabled:rf-cursor-not-allowed",
1258
1336
  children: [
1259
- /* @__PURE__ */ jsx16("option", { value: "chronological", children: "Phase Order" }),
1260
- /* @__PURE__ */ jsx16("option", { value: "longest", children: "Duration" })
1337
+ /* @__PURE__ */ jsx16("option", { value: "", children: "Download Debug Output" }),
1338
+ renderLog?.debugOutputs?.map((output) => /* @__PURE__ */ jsx16("option", { value: output.name, children: output.name }, output.name))
1261
1339
  ]
1262
1340
  }
1263
- )
1341
+ ) }),
1342
+ /* @__PURE__ */ jsxs11("div", { className: "rf-flex rf-text-xs rf-items-center", children: [
1343
+ /* @__PURE__ */ jsx16("div", { className: "rf-mr-2", children: "Sort by:" }),
1344
+ /* @__PURE__ */ jsxs11(
1345
+ "select",
1346
+ {
1347
+ value: sortOption,
1348
+ onChange: (e) => setSortOption(e.target.value),
1349
+ className: "rf-px-2 rf-py-1 rf-border rf-rounded rf-text-xs",
1350
+ children: [
1351
+ /* @__PURE__ */ jsx16("option", { value: "chronological", children: "Phase Order" }),
1352
+ /* @__PURE__ */ jsx16("option", { value: "longest", children: "Duration" })
1353
+ ]
1354
+ }
1355
+ )
1356
+ ] })
1264
1357
  ] })
1265
1358
  ] }),
1266
1359
  /* @__PURE__ */ jsx16(RenderTimingsBar_default, { phaseTimings: renderLog.phaseTimings }),
@@ -1333,7 +1426,7 @@ var useErrorTelemetry = ({
1333
1426
  };
1334
1427
 
1335
1428
  // package.json
1336
- var version = "0.0.897";
1429
+ var version = "0.0.899";
1337
1430
 
1338
1431
  // lib/hooks/use-eval-versions.ts
1339
1432
  import { useEffect as useEffect5, useMemo as useMemo2, useState as useState6 } from "react";
@@ -3490,7 +3583,8 @@ var CircuitJsonPreview = ({
3490
3583
  activeEffectName,
3491
3584
  allowSelectingVersion = true,
3492
3585
  showFileMenu = false,
3493
- isWebEmbedded = false
3586
+ isWebEmbedded = false,
3587
+ onRerunWithDebug
3494
3588
  }) => {
3495
3589
  useStyles();
3496
3590
  const {
@@ -3918,7 +4012,13 @@ var CircuitJsonPreview = ({
3918
4012
  ) : /* @__PURE__ */ jsx31(PreviewEmptyState_default, { onRunClicked })
3919
4013
  }
3920
4014
  ) }),
3921
- showRenderLogTab && (!availableTabs || availableTabs.includes("render_log")) && /* @__PURE__ */ jsx31(TabsContent, { value: "render_log", children: /* @__PURE__ */ jsx31(RenderLogViewer, { renderLog }) })
4015
+ showRenderLogTab && (!availableTabs || availableTabs.includes("render_log")) && /* @__PURE__ */ jsx31(TabsContent, { value: "render_log", children: /* @__PURE__ */ jsx31(
4016
+ RenderLogViewer,
4017
+ {
4018
+ renderLog,
4019
+ onRerunWithDebug
4020
+ }
4021
+ ) })
3922
4022
  ]
3923
4023
  }
3924
4024
  )
package/dist/preview.d.ts CHANGED
@@ -25,6 +25,11 @@ interface RenderLog {
25
25
  progress?: number;
26
26
  renderEvents?: RenderEvent[];
27
27
  phaseTimings?: Record<string, number>;
28
+ debugOutputs?: Array<{
29
+ type: string;
30
+ name: string;
31
+ content: string;
32
+ }>;
28
33
  }
29
34
 
30
35
  type TabId = "code" | "pcb" | "schematic" | "assembly" | "cad" | "bom" | "circuit_json" | "errors" | "render_log";
@@ -100,6 +105,10 @@ interface PreviewContentProps {
100
105
  * Whether the preview is being embedded in a web page
101
106
  */
102
107
  isWebEmbedded?: boolean;
108
+ /**
109
+ * Callback to rerun render with debug options
110
+ */
111
+ onRerunWithDebug?: (debugOption: string) => void;
103
112
  }
104
113
 
105
114
  declare global {
@@ -108,7 +117,7 @@ declare global {
108
117
  }
109
118
  }
110
119
 
111
- declare const CircuitJsonPreview: ({ code, fsMap, onRunClicked, errorMessage, errorStack, circuitJson, autoroutingGraphics, showRightHeaderContent, showCodeTab, codeTabContent, showJsonTab, showRenderLogTab, onActiveTabChange, renderLog, showImportAndFormatButtons, className, headerClassName, leftHeaderContent, readOnly, isStreaming, autoroutingLog, onReportAutoroutingLog, isRunningCode, hasCodeChangedSinceLastRun, onEditEvent, editEvents, defaultActiveTab, defaultTab, availableTabs, autoRotate3dViewerDisabled, showSchematicDebugGrid, showToggleFullScreen, defaultToFullScreen, activeEffectName, allowSelectingVersion, showFileMenu, isWebEmbedded, }: PreviewContentProps) => react_jsx_runtime.JSX.Element;
120
+ declare const CircuitJsonPreview: ({ code, fsMap, onRunClicked, errorMessage, errorStack, circuitJson, autoroutingGraphics, showRightHeaderContent, showCodeTab, codeTabContent, showJsonTab, showRenderLogTab, onActiveTabChange, renderLog, showImportAndFormatButtons, className, headerClassName, leftHeaderContent, readOnly, isStreaming, autoroutingLog, onReportAutoroutingLog, isRunningCode, hasCodeChangedSinceLastRun, onEditEvent, editEvents, defaultActiveTab, defaultTab, availableTabs, autoRotate3dViewerDisabled, showSchematicDebugGrid, showToggleFullScreen, defaultToFullScreen, activeEffectName, allowSelectingVersion, showFileMenu, isWebEmbedded, onRerunWithDebug, }: PreviewContentProps) => react_jsx_runtime.JSX.Element;
112
121
 
113
122
  interface BomTableProps {
114
123
  circuitJson: AnyCircuitElement[];
package/dist/preview.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  linkify,
9
9
  useOrderDialog,
10
10
  useOrderDialogCli
11
- } from "./chunk-2ZVVFUMY.js";
11
+ } from "./chunk-ID4MISF7.js";
12
12
  export {
13
13
  BomTable,
14
14
  CadViewer,
package/dist/runner.js CHANGED
@@ -23,7 +23,7 @@ import {
23
23
  useRunFrameStore,
24
24
  useRunnerStore,
25
25
  useStyles
26
- } from "./chunk-2ZVVFUMY.js";
26
+ } from "./chunk-ID4MISF7.js";
27
27
 
28
28
  // lib/components/RunFrame/RunFrame.tsx
29
29
  import { createCircuitWebWorker } from "@tscircuit/eval/worker";
@@ -176,6 +176,7 @@ var RunFrame = (props) => {
176
176
  const [isRunning, setIsRunning] = useState(false);
177
177
  const [dependenciesLoaded, setDependenciesLoaded] = useState(false);
178
178
  const [activeAsyncEffects, setActiveAsyncEffects] = useState({});
179
+ const [currentDebugOption, setCurrentDebugOption] = useState("");
179
180
  const activeEffectName = Object.values(activeAsyncEffects).sort(
180
181
  (a, b) => a.startTime - b.startTime
181
182
  )[0]?.effectName;
@@ -248,7 +249,7 @@ var RunFrame = (props) => {
248
249
  setIsRunning(false);
249
250
  return;
250
251
  }
251
- const wasTriggeredByRunButton = props.showRunButton && runCountTrigger !== lastRunCountTriggerRef.current;
252
+ const wasTriggeredByRunButton = runCountTrigger !== lastRunCountTriggerRef.current;
252
253
  if (lastFsMapRef.current && circuitJson) {
253
254
  const changes = getChangesBetweenFsMaps(lastFsMapRef.current, fsMap);
254
255
  if (Object.keys(changes).length > 0) {
@@ -272,7 +273,7 @@ var RunFrame = (props) => {
272
273
  setError(null);
273
274
  setRenderLog(null);
274
275
  setActiveAsyncEffects({});
275
- const renderLog2 = { progress: 0 };
276
+ const renderLog2 = { progress: 0, debugOutputs: [] };
276
277
  let cancelled = false;
277
278
  cancelExecutionRef.current = () => {
278
279
  cancelled = true;
@@ -292,6 +293,9 @@ var RunFrame = (props) => {
292
293
  });
293
294
  globalThis.runFrameWorker = worker;
294
295
  setLastRunEvalVersion(resolvedEvalVersion);
296
+ if (currentDebugOption?.trim()) {
297
+ worker.enableDebug(currentDebugOption.replace("DEBUG=", ""));
298
+ }
295
299
  debug("Starting render...");
296
300
  props.onRenderStarted?.();
297
301
  const fsMapObj2 = fsMap instanceof Map ? Object.fromEntries(fsMap.entries()) : fsMap;
@@ -348,6 +352,17 @@ var RunFrame = (props) => {
348
352
  worker.on("autorouting:progress", (event) => {
349
353
  setAutoroutingGraphics(event.debugGraphics);
350
354
  });
355
+ worker.on("debug:logOutput", (event) => {
356
+ renderLog2.debugOutputs = renderLog2.debugOutputs ?? [];
357
+ renderLog2.debugOutputs.push({
358
+ type: "debug",
359
+ name: event.name,
360
+ content: event.content
361
+ });
362
+ if (!cancelled) {
363
+ setRenderLog({ ...renderLog2 });
364
+ }
365
+ });
351
366
  debug("Executing fsMap...");
352
367
  const evalResult = await worker.executeWithFsMap({
353
368
  entrypoint: props.entrypoint,
@@ -404,6 +419,7 @@ var RunFrame = (props) => {
404
419
  }
405
420
  setIsRunning(false);
406
421
  setActiveAsyncEffects({});
422
+ setCurrentDebugOption("");
407
423
  cancelExecutionRef.current = null;
408
424
  };
409
425
  runMutex.runWithMutex(runWorker);
@@ -413,7 +429,8 @@ var RunFrame = (props) => {
413
429
  runCountTrigger,
414
430
  props.evalVersion,
415
431
  props.mainComponentPath,
416
- props.isLoadingFiles
432
+ props.isLoadingFiles,
433
+ currentDebugOption
417
434
  ]);
418
435
  const lastEditEventRef = useRef2(null);
419
436
  const dragTimeout = useRef2(null);
@@ -565,7 +582,11 @@ var RunFrame = (props) => {
565
582
  errorStack: error?.stack,
566
583
  onEditEvent: handleEditEvent,
567
584
  editEvents: props.editEvents,
568
- defaultToFullScreen: props.defaultToFullScreen
585
+ defaultToFullScreen: props.defaultToFullScreen,
586
+ onRerunWithDebug: (debugOption) => {
587
+ setCurrentDebugOption(debugOption || "");
588
+ incRunCountTrigger(1);
589
+ }
569
590
  }
570
591
  );
571
592
  };