@tscircuit/pcb-viewer 1.11.52 → 1.11.53

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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { LayerRef, AnyCircuitElement } from 'circuit-json';
3
+ import { GraphicsObject } from 'graphics-debug';
3
4
  import { Matrix } from 'transformation-matrix';
4
5
 
5
6
  interface State {
@@ -68,8 +69,9 @@ type Props = {
68
69
  focusOnHover?: boolean;
69
70
  clickToInteractEnabled?: boolean;
70
71
  disableAutoFocus?: boolean;
72
+ debugGraphics?: GraphicsObject;
71
73
  };
72
- declare const PCBViewer: ({ children, soup, circuitJson, height, initialState, allowEditing, editEvents: editEventsProp, onEditEventsChanged, focusOnHover, clickToInteractEnabled, disableAutoFocus, }: Props) => react_jsx_runtime.JSX.Element;
74
+ declare const PCBViewer: ({ children, soup, circuitJson, debugGraphics, height, initialState, allowEditing, editEvents: editEventsProp, onEditEventsChanged, focusOnHover, clickToInteractEnabled, disableAutoFocus, }: Props) => react_jsx_runtime.JSX.Element;
73
75
 
74
76
  declare const applyEditEvents: (soup: AnyCircuitElement[], edit_events: EditEvent[]) => AnyCircuitElement[];
75
77
 
@@ -85,6 +87,7 @@ type GridConfig = {
85
87
 
86
88
  interface CanvasElementsRendererProps {
87
89
  elements: AnyCircuitElement[];
90
+ debugGraphics?: GraphicsObject;
88
91
  transform?: Matrix;
89
92
  width?: number;
90
93
  height?: number;
package/dist/index.js CHANGED
@@ -5824,7 +5824,7 @@ var ToastContainer = () => {
5824
5824
  };
5825
5825
 
5826
5826
  // src/PCBViewer.tsx
5827
- import { useEffect as useEffect12, useMemo as useMemo6, useState as useState10 } from "react";
5827
+ import { useEffect as useEffect13, useMemo as useMemo6, useState as useState10 } from "react";
5828
5828
 
5829
5829
  // node_modules/react-use/esm/misc/util.js
5830
5830
  var noop = function() {
@@ -7921,12 +7921,12 @@ var DimensionOverlay = ({
7921
7921
  };
7922
7922
  const addKeyListener = () => {
7923
7923
  if (container2) {
7924
- container2.addEventListener("keydown", down);
7924
+ window.addEventListener("keydown", down);
7925
7925
  }
7926
7926
  };
7927
7927
  const removeKeyListener = () => {
7928
7928
  if (container2) {
7929
- container2.removeEventListener("keydown", down);
7929
+ window.removeEventListener("keydown", down);
7930
7930
  }
7931
7931
  };
7932
7932
  if (container2) {
@@ -8159,7 +8159,7 @@ import { css } from "@emotion/css";
8159
8159
  // package.json
8160
8160
  var package_default = {
8161
8161
  name: "@tscircuit/pcb-viewer",
8162
- version: "1.11.51",
8162
+ version: "1.11.52",
8163
8163
  main: "dist/index.js",
8164
8164
  type: "module",
8165
8165
  repository: "tscircuit/pcb-viewer",
@@ -8211,10 +8211,11 @@ var package_default = {
8211
8211
  },
8212
8212
  dependencies: {
8213
8213
  "@emotion/css": "^11.11.2",
8214
- "circuit-json-to-connectivity-map": "^0.0.19",
8215
8214
  "@tscircuit/math-utils": "^0.0.10",
8215
+ "circuit-json-to-connectivity-map": "^0.0.19",
8216
8216
  "circuit-to-svg": "^0.0.36",
8217
8217
  color: "^4.2.3",
8218
+ "graphics-debug": "^0.0.23",
8218
8219
  "react-supergrid": "^1.0.10",
8219
8220
  "react-toastify": "^10.0.5",
8220
8221
  "transformation-matrix": "^2.13.0",
@@ -9414,8 +9415,54 @@ function addInteractionMetadataToPrimitives({
9414
9415
  return newPrimitives;
9415
9416
  }
9416
9417
 
9418
+ // src/components/DebugGraphicsOverlay.tsx
9419
+ import { drawGraphicsToCanvas } from "graphics-debug";
9420
+ import { useEffect as useEffect12, useRef as useRef7 } from "react";
9421
+ import { jsx as jsx13, jsxs as jsxs10 } from "react/jsx-runtime";
9422
+ var DebugGraphicsOverlay = ({
9423
+ children,
9424
+ transform,
9425
+ debugGraphics
9426
+ }) => {
9427
+ const canvasRef = useRef7(null);
9428
+ const [containerRef, { width, height }] = useMeasure_default();
9429
+ useEffect12(() => {
9430
+ if (canvasRef.current && debugGraphics && width && height) {
9431
+ canvasRef.current.width = width;
9432
+ canvasRef.current.height = height;
9433
+ drawGraphicsToCanvas(debugGraphics, canvasRef.current, {
9434
+ transform
9435
+ });
9436
+ }
9437
+ }, [debugGraphics, transform, width, height]);
9438
+ return /* @__PURE__ */ jsxs10(
9439
+ "div",
9440
+ {
9441
+ ref: containerRef,
9442
+ style: { position: "relative", width: "100%", height: "100%" },
9443
+ children: [
9444
+ children,
9445
+ /* @__PURE__ */ jsx13(
9446
+ "canvas",
9447
+ {
9448
+ ref: canvasRef,
9449
+ style: {
9450
+ position: "absolute",
9451
+ top: 0,
9452
+ left: 0,
9453
+ width: "100%",
9454
+ height: "100%",
9455
+ pointerEvents: "none"
9456
+ }
9457
+ }
9458
+ )
9459
+ ]
9460
+ }
9461
+ );
9462
+ };
9463
+
9417
9464
  // src/components/CanvasElementsRenderer.tsx
9418
- import { jsx as jsx13 } from "react/jsx-runtime";
9465
+ import { jsx as jsx14 } from "react/jsx-runtime";
9419
9466
  var CanvasElementsRenderer = (props) => {
9420
9467
  const { transform, elements } = props;
9421
9468
  const [primitivesWithoutInteractionMetadata, connectivityMap] = useMemo5(() => {
@@ -9430,7 +9477,7 @@ var CanvasElementsRenderer = (props) => {
9430
9477
  const [primitives, setPrimitives] = useState9(
9431
9478
  primitivesWithoutInteractionMetadata
9432
9479
  );
9433
- return /* @__PURE__ */ jsx13(
9480
+ return /* @__PURE__ */ jsx14(
9434
9481
  MouseElementTracker,
9435
9482
  {
9436
9483
  elements,
@@ -9458,7 +9505,7 @@ var CanvasElementsRenderer = (props) => {
9458
9505
  });
9459
9506
  setPrimitives(newPrimitives);
9460
9507
  },
9461
- children: /* @__PURE__ */ jsx13(
9508
+ children: /* @__PURE__ */ jsx14(
9462
9509
  EditPlacementOverlay,
9463
9510
  {
9464
9511
  disabled: !props.allowEditing,
@@ -9467,7 +9514,7 @@ var CanvasElementsRenderer = (props) => {
9467
9514
  cancelPanDrag: props.cancelPanDrag,
9468
9515
  onCreateEditEvent: props.onCreateEditEvent,
9469
9516
  onModifyEditEvent: props.onModifyEditEvent,
9470
- children: /* @__PURE__ */ jsx13(
9517
+ children: /* @__PURE__ */ jsx14(
9471
9518
  EditTraceHintOverlay,
9472
9519
  {
9473
9520
  disabled: !props.allowEditing,
@@ -9476,19 +9523,26 @@ var CanvasElementsRenderer = (props) => {
9476
9523
  cancelPanDrag: props.cancelPanDrag,
9477
9524
  onCreateEditEvent: props.onCreateEditEvent,
9478
9525
  onModifyEditEvent: props.onModifyEditEvent,
9479
- children: /* @__PURE__ */ jsx13(
9526
+ children: /* @__PURE__ */ jsx14(
9480
9527
  DimensionOverlay,
9481
9528
  {
9482
9529
  transform,
9483
9530
  focusOnHover: props.focusOnHover,
9484
- children: /* @__PURE__ */ jsx13(ToolbarOverlay, { elements, children: /* @__PURE__ */ jsx13(ErrorOverlay, { transform, elements, children: /* @__PURE__ */ jsx13(RatsNestOverlay, { transform, soup: elements, children: /* @__PURE__ */ jsx13(
9485
- CanvasPrimitiveRenderer,
9531
+ children: /* @__PURE__ */ jsx14(ToolbarOverlay, { elements, children: /* @__PURE__ */ jsx14(ErrorOverlay, { transform, elements, children: /* @__PURE__ */ jsx14(RatsNestOverlay, { transform, soup: elements, children: /* @__PURE__ */ jsx14(
9532
+ DebugGraphicsOverlay,
9486
9533
  {
9487
9534
  transform,
9488
- primitives,
9489
- width: props.width,
9490
- height: props.height,
9491
- grid: props.grid
9535
+ debugGraphics: props.debugGraphics,
9536
+ children: /* @__PURE__ */ jsx14(
9537
+ CanvasPrimitiveRenderer,
9538
+ {
9539
+ transform,
9540
+ primitives,
9541
+ width: props.width,
9542
+ height: props.height,
9543
+ grid: props.grid
9544
+ }
9545
+ )
9492
9546
  }
9493
9547
  ) }) }) })
9494
9548
  }
@@ -9502,12 +9556,13 @@ var CanvasElementsRenderer = (props) => {
9502
9556
  };
9503
9557
 
9504
9558
  // src/PCBViewer.tsx
9505
- import { jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
9559
+ import { jsx as jsx15, jsxs as jsxs11 } from "react/jsx-runtime";
9506
9560
  var defaultTransform = compose4(translate5(400, 300), scale2(40, -40));
9507
9561
  var PCBViewer = ({
9508
9562
  children,
9509
9563
  soup,
9510
9564
  circuitJson,
9565
+ debugGraphics,
9511
9566
  height = 600,
9512
9567
  initialState,
9513
9568
  allowEditing = true,
@@ -9524,7 +9579,9 @@ var PCBViewer = ({
9524
9579
  isLoading
9525
9580
  } = useRenderedCircuit(children);
9526
9581
  circuitJson ??= circuitJsonFromChildren ?? [];
9527
- const [isInteractionEnabled, setIsInteractionEnabled] = useState10(!clickToInteractEnabled);
9582
+ const [isInteractionEnabled, setIsInteractionEnabled] = useState10(
9583
+ !clickToInteractEnabled
9584
+ );
9528
9585
  const [ref, refDimensions] = useMeasure_default();
9529
9586
  const [transform, setTransformInternal] = useState10(defaultTransform);
9530
9587
  const {
@@ -9581,11 +9638,17 @@ var PCBViewer = ({
9581
9638
  };
9582
9639
  requestAnimationFrame(animateTransform);
9583
9640
  };
9584
- useEffect12(() => {
9641
+ useEffect13(() => {
9585
9642
  if (!disableAutoFocus && refDimensions && refDimensions.width !== 0 && (children || soup) && (!clickToInteractEnabled || isInteractionEnabled)) {
9586
9643
  resetTransform(false);
9587
9644
  }
9588
- }, [children, refDimensions, clickToInteractEnabled, isInteractionEnabled, disableAutoFocus]);
9645
+ }, [
9646
+ children,
9647
+ refDimensions,
9648
+ clickToInteractEnabled,
9649
+ isInteractionEnabled,
9650
+ disableAutoFocus
9651
+ ]);
9589
9652
  const pcbElmsPreEdit = useMemo6(
9590
9653
  () => circuitJson.filter(
9591
9654
  (e) => e.type.startsWith("pcb_") || e.type.startsWith("source_")
@@ -9606,9 +9669,9 @@ var PCBViewer = ({
9606
9669
  setEditEvents(newEditEvents);
9607
9670
  onEditEventsChanged?.(newEditEvents);
9608
9671
  };
9609
- return /* @__PURE__ */ jsxs10("div", { ref: transformRef, style: { position: "relative" }, children: [
9610
- /* @__PURE__ */ jsx14("div", { ref, children: /* @__PURE__ */ jsxs10(ContextProviders, { initialState, children: [
9611
- /* @__PURE__ */ jsx14(
9672
+ return /* @__PURE__ */ jsxs11("div", { ref: transformRef, style: { position: "relative" }, children: [
9673
+ /* @__PURE__ */ jsx15("div", { ref, children: /* @__PURE__ */ jsxs11(ContextProviders, { initialState, children: [
9674
+ /* @__PURE__ */ jsx15(
9612
9675
  CanvasElementsRenderer,
9613
9676
  {
9614
9677
  transform,
@@ -9628,13 +9691,14 @@ var PCBViewer = ({
9628
9691
  bottom: 0
9629
9692
  }
9630
9693
  },
9631
- elements
9694
+ elements,
9695
+ debugGraphics
9632
9696
  },
9633
9697
  refDimensions.width
9634
9698
  ),
9635
- /* @__PURE__ */ jsx14(ToastContainer, {})
9699
+ /* @__PURE__ */ jsx15(ToastContainer, {})
9636
9700
  ] }) }),
9637
- clickToInteractEnabled && !isInteractionEnabled && /* @__PURE__ */ jsx14(
9701
+ clickToInteractEnabled && !isInteractionEnabled && /* @__PURE__ */ jsx15(
9638
9702
  "div",
9639
9703
  {
9640
9704
  onClick: () => {
@@ -9650,7 +9714,7 @@ var PCBViewer = ({
9650
9714
  alignItems: "center",
9651
9715
  justifyContent: "center"
9652
9716
  },
9653
- children: /* @__PURE__ */ jsx14(
9717
+ children: /* @__PURE__ */ jsx15(
9654
9718
  "div",
9655
9719
  {
9656
9720
  style: {