@tscircuit/pcb-viewer 1.10.24 → 1.10.25

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.js CHANGED
@@ -616,20 +616,20 @@ var require_dist = __commonJS({
616
616
  });
617
617
  module2.exports = __toCommonJS2(src_exports2);
618
618
  var import_transformation_matrix12 = require("transformation-matrix");
619
- var import_react21 = require("react");
619
+ var import_react22 = require("react");
620
620
  var useMouseMatrixTransform2 = function() {
621
621
  var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
622
- var extRef = (0, import_react21.useRef)(null);
623
- var _ref = _sliced_to_array((0, import_react21.useState)(0), 2), lastDragCancelTime = _ref[0], setLastDragCancelTime = _ref[1];
622
+ var extRef = (0, import_react22.useRef)(null);
623
+ var _ref = _sliced_to_array((0, import_react22.useState)(0), 2), lastDragCancelTime = _ref[0], setLastDragCancelTime = _ref[1];
624
624
  var _props_canvasElm;
625
625
  var outerCanvasElm = (_props_canvasElm = props.canvasElm) !== null && _props_canvasElm !== void 0 ? _props_canvasElm : extRef.current;
626
626
  var _props_initialTransform;
627
- var _ref1 = _sliced_to_array((0, import_react21.useState)((_props_initialTransform = props.initialTransform) !== null && _props_initialTransform !== void 0 ? _props_initialTransform : (0, import_transformation_matrix12.identity)()), 2), internalTransform = _ref1[0], setInternalTransform = _ref1[1];
628
- var _ref2 = _sliced_to_array((0, import_react21.useState)(0), 2), waitCounter = _ref2[0], setWaitCounter = _ref2[1];
629
- var _ref3 = _sliced_to_array((0, import_react21.useReducer)(function(s) {
627
+ var _ref1 = _sliced_to_array((0, import_react22.useState)((_props_initialTransform = props.initialTransform) !== null && _props_initialTransform !== void 0 ? _props_initialTransform : (0, import_transformation_matrix12.identity)()), 2), internalTransform = _ref1[0], setInternalTransform = _ref1[1];
628
+ var _ref2 = _sliced_to_array((0, import_react22.useState)(0), 2), waitCounter = _ref2[0], setWaitCounter = _ref2[1];
629
+ var _ref3 = _sliced_to_array((0, import_react22.useReducer)(function(s) {
630
630
  return s + 1;
631
631
  }, 0), 2), extChangeCounter = _ref3[0], incExtChangeCounter = _ref3[1];
632
- var setTransform = (0, import_react21.useCallback)(function(newTransform) {
632
+ var setTransform = (0, import_react22.useCallback)(function(newTransform) {
633
633
  if (props.onSetTransform) {
634
634
  props.onSetTransform(newTransform);
635
635
  }
@@ -640,7 +640,7 @@ var require_dist = __commonJS({
640
640
  props.onSetTransform,
641
641
  setInternalTransform
642
642
  ]);
643
- var setTransformExt = (0, import_react21.useCallback)(function(newTransform) {
643
+ var setTransformExt = (0, import_react22.useCallback)(function(newTransform) {
644
644
  setTransform(newTransform);
645
645
  incExtChangeCounter();
646
646
  }, [
@@ -648,10 +648,10 @@ var require_dist = __commonJS({
648
648
  ]);
649
649
  var _props_transform;
650
650
  var transform = (_props_transform = props.transform) !== null && _props_transform !== void 0 ? _props_transform : internalTransform;
651
- var cancelDrag = (0, import_react21.useCallback)(function() {
651
+ var cancelDrag = (0, import_react22.useCallback)(function() {
652
652
  setLastDragCancelTime(Date.now());
653
653
  }, []);
654
- (0, import_react21.useEffect)(function() {
654
+ (0, import_react22.useEffect)(function() {
655
655
  var handleMouseDown = function handleMouseDown(e) {
656
656
  m0 = getMousePos(e);
657
657
  if (Date.now() - lastDragCancelTime < 100) return;
@@ -743,7 +743,7 @@ var require_dist = __commonJS({
743
743
  extChangeCounter,
744
744
  lastDragCancelTime
745
745
  ]);
746
- var applyTransformToPoint = (0, import_react21.useCallback)(function(obj) {
746
+ var applyTransformToPoint = (0, import_react22.useCallback)(function(obj) {
747
747
  return (0, import_transformation_matrix12.applyToPoint)(transform, obj);
748
748
  }, [
749
749
  transform
@@ -9673,7 +9673,7 @@ var ToastContainer = function() {
9673
9673
  });
9674
9674
  };
9675
9675
  // src/PCBViewer.tsx
9676
- var import_react20 = require("react");
9676
+ var import_react21 = require("react");
9677
9677
  // node_modules/react-use/esm/misc/util.js
9678
9678
  var noop = function noop() {};
9679
9679
  var isBrowser = typeof window !== "undefined";
@@ -9737,7 +9737,7 @@ var useMeasure_default = isBrowser && typeof window.ResizeObserver !== "undefine
9737
9737
  var import_transformation_matrix11 = require("transformation-matrix");
9738
9738
  var import_use_mouse_matrix_transform = __toESM(require_dist());
9739
9739
  // src/components/CanvasElementsRenderer.tsx
9740
- var import_react18 = require("react");
9740
+ var import_react19 = require("react");
9741
9741
  // src/components/CanvasPrimitiveRenderer.tsx
9742
9742
  var import_react_supergrid = require("react-supergrid");
9743
9743
  var import_react7 = require("react");
@@ -10754,7 +10754,7 @@ var CanvasPrimitiveRenderer = function(param) {
10754
10754
  });
10755
10755
  };
10756
10756
  // src/components/CanvasElementsRenderer.tsx
10757
- var import_react19 = require("react");
10757
+ var import_react20 = require("react");
10758
10758
  // src/lib/util/expand-stroke.ts
10759
10759
  function getExpandedStroke(strokeInput, defaultWidth) {
10760
10760
  if (strokeInput.length < 2) {
@@ -11886,7 +11886,7 @@ var import_css = require("@emotion/css");
11886
11886
  // package.json
11887
11887
  var package_default = {
11888
11888
  name: "@tscircuit/pcb-viewer",
11889
- version: "1.10.23",
11889
+ version: "1.10.24",
11890
11890
  main: "dist/index.js",
11891
11891
  repository: "tscircuit/pcb-viewer",
11892
11892
  license: "MIT",
@@ -12885,28 +12885,103 @@ var EditTraceHintOverlay = function(param) {
12885
12885
  };
12886
12886
  // src/components/RatsNestOverlay.tsx
12887
12887
  var import_transformation_matrix10 = require("transformation-matrix");
12888
+ var import_circuit_json_to_connectivity_map = require("circuit-json-to-connectivity-map");
12889
+ var import_react18 = require("react");
12888
12890
  var import_jsx_runtime12 = require("react/jsx-runtime");
12889
12891
  var RatsNestOverlay = function(param) {
12890
12892
  var transform = param.transform, soup = param.soup, children = param.children;
12891
12893
  var isShowingRatsNest = useGlobalStore(function(s) {
12892
12894
  return s.is_showing_rats_nest;
12893
12895
  });
12896
+ var _ref = (0, import_react18.useMemo)(function() {
12897
+ return (0, import_circuit_json_to_connectivity_map.getFullConnectivityMapFromCircuitJson)(soup || []);
12898
+ }, [
12899
+ soup
12900
+ ]), netMap = _ref.netMap, idToNetMap = _ref.idToNetMap;
12901
+ var ratsNestLines = (0, import_react18.useMemo)(function() {
12902
+ if (!soup || !isShowingRatsNest) return [];
12903
+ var getElementPosition = function(id) {
12904
+ var element = su_default(soup)[id.replace(/_\d+$/, "")].get(id);
12905
+ if (element && "x" in element && "y" in element) {
12906
+ return {
12907
+ x: element.x,
12908
+ y: element.y
12909
+ };
12910
+ }
12911
+ return null;
12912
+ };
12913
+ var findNearestPointInNet = function(sourcePoint, netId) {
12914
+ var connectedIds = netMap[netId] || [];
12915
+ var nearestPoint = null;
12916
+ var minDistance = Infinity;
12917
+ connectedIds.forEach(function(id) {
12918
+ var pos = getElementPosition(id);
12919
+ if (pos) {
12920
+ var distance2 = Math.sqrt(Math.pow(sourcePoint.x - pos.x, 2) + Math.pow(sourcePoint.y - pos.y, 2));
12921
+ if (distance2 < minDistance && distance2 > 0) {
12922
+ minDistance = distance2;
12923
+ nearestPoint = pos;
12924
+ }
12925
+ }
12926
+ });
12927
+ return nearestPoint;
12928
+ };
12929
+ var pcbPorts = su_default(soup).pcb_port.list();
12930
+ var sourceTraces = su_default(soup).source_trace.list();
12931
+ var lines = [];
12932
+ pcbPorts.forEach(function(port, index) {
12933
+ var portId = port.pcb_port_id;
12934
+ var netId = idToNetMap[portId];
12935
+ var isInNet = false;
12936
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
12937
+ try {
12938
+ for(var _iterator = sourceTraces[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
12939
+ var trace = _step.value;
12940
+ var _su_default_source_port_getUsing;
12941
+ var sourceTrace = trace.connected_source_port_ids.includes((_su_default_source_port_getUsing = su_default(soup).source_port.getUsing({
12942
+ pcb_port_id: portId
12943
+ })) === null || _su_default_source_port_getUsing === void 0 ? void 0 : _su_default_source_port_getUsing.source_port_id);
12944
+ if (sourceTrace && trace.connected_source_net_ids.length > 0) {
12945
+ isInNet = true;
12946
+ }
12947
+ }
12948
+ } catch (err) {
12949
+ _didIteratorError = true;
12950
+ _iteratorError = err;
12951
+ } finally{
12952
+ try {
12953
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
12954
+ _iterator.return();
12955
+ }
12956
+ } finally{
12957
+ if (_didIteratorError) {
12958
+ throw _iteratorError;
12959
+ }
12960
+ }
12961
+ }
12962
+ if (!netId) return;
12963
+ var startPoint = {
12964
+ x: port.x,
12965
+ y: port.y
12966
+ };
12967
+ var nearestPoint = findNearestPointInNet(startPoint, netId);
12968
+ if (!nearestPoint) return;
12969
+ lines.push({
12970
+ key: "".concat(portId, "-").concat(index),
12971
+ startPoint: startPoint,
12972
+ endPoint: nearestPoint,
12973
+ isInNet: isInNet
12974
+ });
12975
+ });
12976
+ return lines;
12977
+ }, [
12978
+ soup,
12979
+ netMap,
12980
+ idToNetMap,
12981
+ isShowingRatsNest
12982
+ ]);
12894
12983
  if (!soup || !isShowingRatsNest) return children;
12895
12984
  if (!transform) transform = (0, import_transformation_matrix10.identity)();
12896
- var sourceTraces = su_default(soup).source_trace.list();
12897
- var groups = [];
12898
- sourceTraces.forEach(function(sourceTrace) {
12899
- if (sourceTrace.connected_source_port_ids) {
12900
- var group = [];
12901
- sourceTrace.connected_source_port_ids.forEach(function(source_port_id) {
12902
- var pcbPort = su_default(soup).pcb_port.getWhere({
12903
- source_port_id: source_port_id
12904
- });
12905
- if (pcbPort) group.push(pcbPort);
12906
- });
12907
- groups.push(group);
12908
- }
12909
- });
12910
12985
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", {
12911
12986
  style: {
12912
12987
  position: "relative"
@@ -12924,40 +12999,26 @@ var RatsNestOverlay = function(param) {
12924
12999
  opacity: 0.5,
12925
13000
  zIndex: zIndexMap.ratsNestOverlay
12926
13001
  },
12927
- children: groups.map(function(group, index) {
12928
- var points = group.map(function(port) {
12929
- return (0, import_transformation_matrix10.applyToPoint)(transform, {
12930
- x: port.x,
12931
- y: port.y
12932
- });
12933
- });
12934
- var lines = [];
12935
- for(var i = 0; i < points.length; i++){
12936
- for(var j = i + 1; j < points.length; j++){
12937
- lines.push([
12938
- points[i],
12939
- points[j]
12940
- ]);
12941
- }
12942
- }
12943
- return lines.map(function(param, index2) {
12944
- var _param = _sliced_to_array(param, 2), start = _param[0], end = _param[1];
12945
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("line", {
12946
- x1: start.x,
12947
- y1: start.y,
12948
- x2: end.x,
12949
- y2: end.y,
12950
- stroke: "white",
12951
- strokeWidth: "1"
12952
- }, index2);
12953
- });
13002
+ children: ratsNestLines.map(function(param) {
13003
+ var key = param.key, startPoint = param.startPoint, endPoint = param.endPoint, isInNet = param.isInNet;
13004
+ var transformedStart = (0, import_transformation_matrix10.applyToPoint)(transform, startPoint);
13005
+ var transformedEnd = (0, import_transformation_matrix10.applyToPoint)(transform, endPoint);
13006
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("line", {
13007
+ x1: transformedStart.x,
13008
+ y1: transformedStart.y,
13009
+ x2: transformedEnd.x,
13010
+ y2: transformedEnd.y,
13011
+ stroke: "white",
13012
+ strokeWidth: "1",
13013
+ strokeDasharray: isInNet ? "6,6" : void 0
13014
+ }, key);
12954
13015
  })
12955
13016
  })
12956
13017
  ]
12957
13018
  });
12958
13019
  };
12959
13020
  // src/components/CanvasElementsRenderer.tsx
12960
- var import_circuit_json_to_connectivity_map = require("circuit-json-to-connectivity-map");
13021
+ var import_circuit_json_to_connectivity_map2 = require("circuit-json-to-connectivity-map");
12961
13022
  // src/lib/util/addInteractionMetadataToPrimitives.ts
12962
13023
  function addInteractionMetadataToPrimitives(param) {
12963
13024
  var primitivesWithoutInteractionMetadata = param.primitivesWithoutInteractionMetadata, drawingObjectIdsWithMouseOver = param.drawingObjectIdsWithMouseOver, primitiveIdsInMousedOverNet = param.primitiveIdsInMousedOverNet;
@@ -13000,11 +13061,11 @@ function addInteractionMetadataToPrimitives(param) {
13000
13061
  var import_jsx_runtime13 = require("react/jsx-runtime");
13001
13062
  var CanvasElementsRenderer = function(props) {
13002
13063
  var transform = props.transform, elements = props.elements;
13003
- var _ref = _sliced_to_array((0, import_react19.useMemo)(function() {
13064
+ var _ref = _sliced_to_array((0, import_react20.useMemo)(function() {
13004
13065
  var primitivesWithoutInteractionMetadata2 = props.elements.flatMap(function(elm) {
13005
13066
  return convertElementToPrimitives(elm, props.elements);
13006
13067
  });
13007
- var connectivityMap2 = (0, import_circuit_json_to_connectivity_map.getFullConnectivityMapFromCircuitJson)(props.elements);
13068
+ var connectivityMap2 = (0, import_circuit_json_to_connectivity_map2.getFullConnectivityMapFromCircuitJson)(props.elements);
13008
13069
  return [
13009
13070
  primitivesWithoutInteractionMetadata2,
13010
13071
  connectivityMap2
@@ -13012,7 +13073,7 @@ var CanvasElementsRenderer = function(props) {
13012
13073
  }, [
13013
13074
  props.elements
13014
13075
  ]), 2), primitivesWithoutInteractionMetadata = _ref[0], connectivityMap = _ref[1];
13015
- var _ref1 = _sliced_to_array((0, import_react18.useState)(primitivesWithoutInteractionMetadata), 2), primitives = _ref1[0], setPrimitives = _ref1[1];
13076
+ var _ref1 = _sliced_to_array((0, import_react19.useState)(primitivesWithoutInteractionMetadata), 2), primitives = _ref1[0], setPrimitives = _ref1[1];
13016
13077
  return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(MouseElementTracker, {
13017
13078
  transform: transform,
13018
13079
  primitives: primitivesWithoutInteractionMetadata,
@@ -13100,12 +13161,12 @@ var PCBViewer = function(param) {
13100
13161
  soup !== null && soup !== void 0 ? soup : soup = circuitJson;
13101
13162
  var _ref = (0, import_core.useRenderedCircuit)(children), circuitJsonFromChildren = _ref.circuitJson, errorFromChildren = _ref.error, isLoading = _ref.isLoading;
13102
13163
  var _useMeasure_default = _sliced_to_array(useMeasure_default(), 2), ref = _useMeasure_default[0], refDimensions = _useMeasure_default[1];
13103
- var _ref1 = _sliced_to_array((0, import_react20.useState)(defaultTransform), 2), transform = _ref1[0], setTransformInternal = _ref1[1];
13164
+ var _ref1 = _sliced_to_array((0, import_react21.useState)(defaultTransform), 2), transform = _ref1[0], setTransformInternal = _ref1[1];
13104
13165
  var _ref2 = (0, import_use_mouse_matrix_transform.default)({
13105
13166
  transform: transform,
13106
13167
  onSetTransform: setTransformInternal
13107
13168
  }), transformRef = _ref2.ref, setTransform = _ref2.setTransform, cancelPanDrag = _ref2.cancelDrag;
13108
- var _ref3 = _sliced_to_array((0, import_react20.useState)([]), 2), editEvents = _ref3[0], setEditEvents = _ref3[1];
13169
+ var _ref3 = _sliced_to_array((0, import_react21.useState)([]), 2), editEvents = _ref3[0], setEditEvents = _ref3[1];
13109
13170
  editEvents = editEventsProp !== null && editEventsProp !== void 0 ? editEventsProp : editEvents;
13110
13171
  var _ref4;
13111
13172
  var stateElements = (_ref4 = circuitJsonFromChildren !== null && circuitJsonFromChildren !== void 0 ? circuitJsonFromChildren : soup) !== null && _ref4 !== void 0 ? _ref4 : [];
@@ -13131,7 +13192,7 @@ var PCBViewer = function(param) {
13131
13192
  var _elmBounds_width1, _elmBounds_height1;
13132
13193
  setTransform((0, import_transformation_matrix11.compose)((0, import_transformation_matrix11.translate)(((_elmBounds_width1 = elmBounds.width) !== null && _elmBounds_width1 !== void 0 ? _elmBounds_width1 : 0) / 2, ((_elmBounds_height1 = elmBounds.height) !== null && _elmBounds_height1 !== void 0 ? _elmBounds_height1 : 0) / 2), (0, import_transformation_matrix11.scale)(scaleFactor, -scaleFactor, 0, 0), (0, import_transformation_matrix11.translate)(-center.x, -center.y)));
13133
13194
  };
13134
- (0, import_react20.useEffect)(function() {
13195
+ (0, import_react21.useEffect)(function() {
13135
13196
  if (refDimensions && refDimensions.width !== 0 && (children || soup)) {
13136
13197
  resetTransform();
13137
13198
  }
@@ -13143,7 +13204,7 @@ var PCBViewer = function(param) {
13143
13204
  var pcbElmsPreEdit = ((_ref5 = circuitJson !== null && circuitJson !== void 0 ? circuitJson : soup) !== null && _ref5 !== void 0 ? _ref5 : stateElements).filter(function(e) {
13144
13205
  return e.type.startsWith("pcb_") || e.type.startsWith("source_");
13145
13206
  });
13146
- var elements = (0, import_react20.useMemo)(function() {
13207
+ var elements = (0, import_react21.useMemo)(function() {
13147
13208
  return applyEditEvents(pcbElmsPreEdit, editEvents);
13148
13209
  }, [
13149
13210
  pcbElmsPreEdit,