@tscircuit/pcb-viewer 1.3.0 → 1.3.2

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
@@ -333,6 +333,26 @@ function _templateObject() {
333
333
  };
334
334
  return data;
335
335
  }
336
+ function _templateObject1() {
337
+ var data = _tagged_template_literal([
338
+ "\n position: absolute;\n z-index: 1000;\n left: ",
339
+ "px;\n top: ",
340
+ "px;\n color: red;\n text-align: center;\n font-family: sans-serif;\n font-size: 12px;\n display: flex;\n flex-direction: column;\n align-items: center;\n cursor: pointer;\n transform: translate(-50%, -100%);\n\n & .error-message {\n opacity: 0;\n pointer-events: none;\n\n width: 200px;\n transition: opacity 0.2s;\n margin-bottom: 10px;\n }\n\n &:hover .error-message {\n opacity: 1;\n display: flex;\n }\n "
341
+ ]);
342
+ _templateObject1 = function _templateObject() {
343
+ return data;
344
+ };
345
+ return data;
346
+ }
347
+ function _templateObject2() {
348
+ var data = _tagged_template_literal([
349
+ "\n width: 10px;\n height: 10px;\n transform: translate(0, 5px) rotate(45deg);\n background-color: red;\n "
350
+ ]);
351
+ _templateObject2 = function _templateObject() {
352
+ return data;
353
+ };
354
+ return data;
355
+ }
336
356
  var __create = Object.create;
337
357
  var __defProp = Object.defineProperty;
338
358
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -458,7 +478,7 @@ var require_dist = __commonJS({
458
478
  }
459
479
  });
460
480
  module2.exports = __toCommonJS2(src_exports2);
461
- var import_transformation_matrix5 = require("transformation-matrix");
481
+ var import_transformation_matrix6 = require("transformation-matrix");
462
482
  var import_react15 = require("react");
463
483
  var useMouseMatrixTransform2 = function() {
464
484
  var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
@@ -466,7 +486,7 @@ var require_dist = __commonJS({
466
486
  var _props_canvasElm;
467
487
  var outerCanvasElm = (_props_canvasElm = props.canvasElm) !== null && _props_canvasElm !== void 0 ? _props_canvasElm : extRef.current;
468
488
  var _props_initialTransform;
469
- var _ref = _sliced_to_array((0, import_react15.useState)((_props_initialTransform = props.initialTransform) !== null && _props_initialTransform !== void 0 ? _props_initialTransform : (0, import_transformation_matrix5.identity)()), 2), internalTransform = _ref[0], setInternalTransform = _ref[1];
489
+ var _ref = _sliced_to_array((0, import_react15.useState)((_props_initialTransform = props.initialTransform) !== null && _props_initialTransform !== void 0 ? _props_initialTransform : (0, import_transformation_matrix6.identity)()), 2), internalTransform = _ref[0], setInternalTransform = _ref[1];
470
490
  var _ref1 = _sliced_to_array((0, import_react15.useState)(0), 2), waitCounter = _ref1[0], setWaitCounter = _ref1[1];
471
491
  var _ref2 = _sliced_to_array((0, import_react15.useReducer)(function(s) {
472
492
  return s + 1;
@@ -498,7 +518,7 @@ var require_dist = __commonJS({
498
518
  };
499
519
  var handleMouseUp = function handleMouseUp(e) {
500
520
  m1 = getMousePos(e);
501
- var new_tf = (0, import_transformation_matrix5.compose)((0, import_transformation_matrix5.translate)(m1.x - m0.x, m1.y - m0.y), init_tf);
521
+ var new_tf = (0, import_transformation_matrix6.compose)((0, import_transformation_matrix6.translate)(m1.x - m0.x, m1.y - m0.y), init_tf);
502
522
  setTransform(new_tf);
503
523
  init_tf = new_tf;
504
524
  md = false;
@@ -507,11 +527,11 @@ var require_dist = __commonJS({
507
527
  mlastrel = getMousePos(e);
508
528
  if (!md) return;
509
529
  m1 = getMousePos(e);
510
- setTransform((0, import_transformation_matrix5.compose)((0, import_transformation_matrix5.translate)(m1.x - m0.x, m1.y - m0.y), init_tf));
530
+ setTransform((0, import_transformation_matrix6.compose)((0, import_transformation_matrix6.translate)(m1.x - m0.x, m1.y - m0.y), init_tf));
511
531
  };
512
532
  var handleMouseWheel = function handleMouseWheel(e) {
513
533
  var center = getMousePos(e);
514
- var new_tf = (0, import_transformation_matrix5.compose)((0, import_transformation_matrix5.translate)(center.x, center.y), (0, import_transformation_matrix5.scale)(1 - e.deltaY / 1e3, 1 - e.deltaY / 1e3), (0, import_transformation_matrix5.translate)(-center.x, -center.y), init_tf);
534
+ var new_tf = (0, import_transformation_matrix6.compose)((0, import_transformation_matrix6.translate)(center.x, center.y), (0, import_transformation_matrix6.scale)(1 - e.deltaY / 1e3, 1 - e.deltaY / 1e3), (0, import_transformation_matrix6.translate)(-center.x, -center.y), init_tf);
515
535
  setTransform(new_tf);
516
536
  init_tf = new_tf;
517
537
  e.preventDefault();
@@ -520,7 +540,7 @@ var require_dist = __commonJS({
520
540
  if (!md) return;
521
541
  md = false;
522
542
  m1 = getMousePos(e);
523
- var new_tf = (0, import_transformation_matrix5.compose)((0, import_transformation_matrix5.translate)(m1.x - m0.x, m1.y - m0.y), init_tf);
543
+ var new_tf = (0, import_transformation_matrix6.compose)((0, import_transformation_matrix6.translate)(m1.x - m0.x, m1.y - m0.y), init_tf);
524
544
  setTransform(new_tf);
525
545
  init_tf = new_tf;
526
546
  };
@@ -574,7 +594,7 @@ var require_dist = __commonJS({
574
594
  extChangeCounter
575
595
  ]);
576
596
  var applyTransformToPoint = (0, import_react15.useCallback)(function(obj) {
577
- return (0, import_transformation_matrix5.applyToPoint)(transform, obj);
597
+ return (0, import_transformation_matrix6.applyToPoint)(transform, obj);
578
598
  }, [
579
599
  transform
580
600
  ]);
@@ -600,14 +620,12 @@ __export(src_exports, {
600
620
  });
601
621
  module.exports = __toCommonJS(src_exports);
602
622
  // src/PCBViewer.tsx
603
- var import_react14 = __toESM(require("react"));
623
+ var import_react14 = require("react");
604
624
  var import_react_fiber = require("@tscircuit/react-fiber");
605
625
  var import_builder3 = require("@tscircuit/builder");
606
- // src/components/CanvasElementsRenderer.tsx
607
- var import_react10 = __toESM(require("react"));
608
626
  // src/components/CanvasPrimitiveRenderer.tsx
609
627
  var import_react_supergrid = require("react-supergrid");
610
- var import_react4 = __toESM(require("react"));
628
+ var import_react4 = require("react");
611
629
  // src/assets/alphabet.ts
612
630
  var svgAlphabet = {
613
631
  "0": "M0.4544564813877358 0L0.2723441540828736 0.03592830447352719L0.1086847233315459 0.14528754990019965L0.020630545837255005 0.3040632652221331L0 0.5395277421960205L0.049259221760993496 0.7369487828466779L0.18080513776237842 0.9005494166306564L0.37036887043974215 0.9872116270037247L0.5864663759301132 1L0.8148695622827444 0.9332890276148733L0.9326583645506394 0.8113052246023419L1 0.4031281830668562L0.833288960385582 0.09886798567812842L0.6801767918233781 0.02483708485091681L0.4544564813877358 0",
@@ -1270,15 +1288,17 @@ var import_zustand = require("zustand");
1270
1288
  // src/components/ContextProviders.tsx
1271
1289
  var import_react = require("react");
1272
1290
  var import_react2 = require("react");
1291
+ var import_jsx_runtime = require("react/jsx-runtime");
1273
1292
  var StoreContext = (0, import_react2.createContext)(null);
1274
1293
  var ContextProviders = function(param) {
1275
1294
  var children = param.children;
1276
1295
  var store = (0, import_react.useMemo)(function() {
1277
1296
  return createStore();
1278
1297
  }, []);
1279
- return /* @__PURE__ */ React.createElement(StoreContext.Provider, {
1280
- value: store
1281
- }, children);
1298
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StoreContext.Provider, {
1299
+ value: store,
1300
+ children: children
1301
+ });
1282
1302
  };
1283
1303
  // src/global-store.ts
1284
1304
  var import_react3 = require("react");
@@ -1300,6 +1320,7 @@ var useStore = function(s) {
1300
1320
  };
1301
1321
  // src/components/CanvasPrimitiveRenderer.tsx
1302
1322
  var import_builder = require("@tscircuit/builder");
1323
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1303
1324
  var CanvasPrimitiveRenderer = function(param) {
1304
1325
  var primitives = param.primitives, transform = param.transform, grid = param.grid, _param_width = param.width, width = _param_width === void 0 ? 500 : _param_width, _param_height = param.height, height = _param_height === void 0 ? 500 : _param_height;
1305
1326
  var canvasRefs = (0, import_react4.useRef)();
@@ -1320,47 +1341,50 @@ var CanvasPrimitiveRenderer = function(param) {
1320
1341
  transform,
1321
1342
  selectedLayer
1322
1343
  ]);
1323
- return /* @__PURE__ */ import_react4.default.createElement("div", {
1344
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", {
1324
1345
  style: {
1325
1346
  backgroundColor: "black",
1326
1347
  width: width,
1327
1348
  height: height,
1328
1349
  position: "relative"
1329
- }
1330
- }, /* @__PURE__ */ import_react4.default.createElement(import_react_supergrid.SuperGrid, {
1331
- textColor: "rgba(0,255,0,0.8)",
1332
- majorColor: "rgba(0,255,0,0.4)",
1333
- minorColor: "rgba(0,255,0,0.2)",
1334
- screenSpaceCellSize: 200,
1335
- width: width,
1336
- height: height,
1337
- transform: transform,
1338
- stringifyCoord: function(x, y, z) {
1339
- return "".concat((0, import_react_supergrid.toMMSI)(x, z), ", ").concat((0, import_react_supergrid.toMMSI)(y, z));
1340
- }
1341
- }), import_builder.all_layers.map(function(l) {
1342
- return l.replace(/-/g, "");
1343
- }).concat([
1344
- "drill",
1345
- "other"
1346
- ]).map(function(layer, i) {
1347
- return /* @__PURE__ */ import_react4.default.createElement("canvas", {
1348
- key: layer,
1349
- ref: function(el) {
1350
- var _canvasRefs_current;
1351
- (_canvasRefs_current = canvasRefs.current) !== null && _canvasRefs_current !== void 0 ? _canvasRefs_current : canvasRefs.current = {};
1352
- canvasRefs.current[layer] = el;
1353
- },
1354
- style: {
1355
- position: "absolute",
1356
- left: 0,
1357
- top: 0,
1358
- pointerEvents: "none"
1359
- },
1360
- width: width,
1361
- height: height
1362
- });
1363
- }));
1350
+ },
1351
+ children: [
1352
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_supergrid.SuperGrid, {
1353
+ textColor: "rgba(0,255,0,0.8)",
1354
+ majorColor: "rgba(0,255,0,0.4)",
1355
+ minorColor: "rgba(0,255,0,0.2)",
1356
+ screenSpaceCellSize: 200,
1357
+ width: width,
1358
+ height: height,
1359
+ transform: transform,
1360
+ stringifyCoord: function(x, y, z) {
1361
+ return "".concat((0, import_react_supergrid.toMMSI)(x, z), ", ").concat((0, import_react_supergrid.toMMSI)(y, z));
1362
+ }
1363
+ }),
1364
+ import_builder.all_layers.map(function(l) {
1365
+ return l.replace(/-/g, "");
1366
+ }).concat([
1367
+ "drill",
1368
+ "other"
1369
+ ]).map(function(layer, i) {
1370
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("canvas", {
1371
+ ref: function(el) {
1372
+ var _canvasRefs_current;
1373
+ (_canvasRefs_current = canvasRefs.current) !== null && _canvasRefs_current !== void 0 ? _canvasRefs_current : canvasRefs.current = {};
1374
+ canvasRefs.current[layer] = el;
1375
+ },
1376
+ style: {
1377
+ position: "absolute",
1378
+ left: 0,
1379
+ top: 0,
1380
+ pointerEvents: "none"
1381
+ },
1382
+ width: width,
1383
+ height: height
1384
+ }, layer);
1385
+ })
1386
+ ]
1387
+ });
1364
1388
  };
1365
1389
  // src/components/CanvasElementsRenderer.tsx
1366
1390
  var import_react11 = require("react");
@@ -1589,11 +1613,12 @@ var convertElementToPrimitives = function(element, allElements) {
1589
1613
  return [];
1590
1614
  };
1591
1615
  // src/components/MouseElementTracker.tsx
1592
- var import_react6 = __toESM(require("react"));
1616
+ var import_react6 = require("react");
1593
1617
  var import_react7 = require("react");
1594
1618
  var import_transformation_matrix2 = require("transformation-matrix");
1595
1619
  // src/components/ElementOverlayBox.tsx
1596
- var import_react5 = __toESM(require("react"));
1620
+ var import_react5 = require("react");
1621
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1597
1622
  var containerStyle = {
1598
1623
  position: "absolute",
1599
1624
  left: 0,
@@ -1651,7 +1676,7 @@ var HighlightedPrimitiveBoxWithText = function(param) {
1651
1676
  var sip = 26;
1652
1677
  var _layerColorHightlightMap_primitive__element_layer;
1653
1678
  var color = (_layerColorHightlightMap_primitive__element_layer = layerColorHightlightMap[primitive === null || primitive === void 0 ? void 0 : (_primitive__element = primitive._element) === null || _primitive__element === void 0 ? void 0 : _primitive__element.layer]) !== null && _layerColorHightlightMap_primitive__element_layer !== void 0 ? _layerColorHightlightMap_primitive__element_layer : "red";
1654
- return /* @__PURE__ */ import_react5.default.createElement("div", {
1679
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", {
1655
1680
  style: {
1656
1681
  position: "absolute",
1657
1682
  left: x - w / 2 - 8,
@@ -1659,45 +1684,49 @@ var HighlightedPrimitiveBoxWithText = function(param) {
1659
1684
  width: w + 16,
1660
1685
  height: h + 16,
1661
1686
  color: color
1662
- }
1663
- }, /* @__PURE__ */ import_react5.default.createElement("div", {
1664
- style: {
1665
- // width: finalState ? `${100 + 20 * si}%` : "100%",
1666
- // height: finalState ? `${100 + 20 * si}%` : "100%",
1667
- // marginLeft: finalState ? `${-10 * si}%` : 0,
1668
- // marginTop: finalState ? `${-10 * si}%` : 0,
1669
- width: finalState ? "calc(100% + ".concat(sip * 2 * si, "px)") : "100%",
1670
- height: finalState ? "calc(100% + ".concat(sip * 2 * si, "px)") : "100%",
1671
- marginLeft: finalState ? "".concat(-sip * si, "px") : 0,
1672
- marginTop: finalState ? "".concat(-sip * si, "px") : 0,
1673
- border: "1px solid ".concat(color),
1674
- opacity: finalState ? 1 : si === 0 ? 1 : 0,
1675
- transition: "width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"
1676
- }
1677
- }, /* @__PURE__ */ import_react5.default.createElement("div", {
1678
- style: {
1679
- position: "absolute",
1680
- left: 0,
1681
- bottom: h + 20 + sip * si,
1682
- marginLeft: finalState ? "".concat(-sip * si, "px") : 0,
1683
- marginBottom: finalState ? 0 : -sip * si,
1684
- transition: "margin-left 0.2s, margin-bottom 0.2s",
1685
- lineHeight: "0.8em"
1686
- }
1687
- }, getTextForHighlightedPrimitive(primitive))));
1687
+ },
1688
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", {
1689
+ style: {
1690
+ // width: finalState ? `${100 + 20 * si}%` : "100%",
1691
+ // height: finalState ? `${100 + 20 * si}%` : "100%",
1692
+ // marginLeft: finalState ? `${-10 * si}%` : 0,
1693
+ // marginTop: finalState ? `${-10 * si}%` : 0,
1694
+ width: finalState ? "calc(100% + ".concat(sip * 2 * si, "px)") : "100%",
1695
+ height: finalState ? "calc(100% + ".concat(sip * 2 * si, "px)") : "100%",
1696
+ marginLeft: finalState ? "".concat(-sip * si, "px") : 0,
1697
+ marginTop: finalState ? "".concat(-sip * si, "px") : 0,
1698
+ border: "1px solid ".concat(color),
1699
+ opacity: finalState ? 1 : si === 0 ? 1 : 0,
1700
+ transition: "width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"
1701
+ },
1702
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", {
1703
+ style: {
1704
+ position: "absolute",
1705
+ left: 0,
1706
+ bottom: h + 20 + sip * si,
1707
+ marginLeft: finalState ? "".concat(-sip * si, "px") : 0,
1708
+ marginBottom: finalState ? 0 : -sip * si,
1709
+ transition: "margin-left 0.2s, margin-bottom 0.2s",
1710
+ lineHeight: "0.8em"
1711
+ },
1712
+ children: getTextForHighlightedPrimitive(primitive)
1713
+ })
1714
+ })
1715
+ });
1688
1716
  };
1689
1717
  var ElementOverlayBox = function(param) {
1690
1718
  var highlightedPrimitives = param.highlightedPrimitives;
1691
- return /* @__PURE__ */ import_react5.default.createElement("div", {
1692
- style: containerStyle
1693
- }, highlightedPrimitives.map(function(primitive, i) {
1694
- return /* @__PURE__ */ import_react5.default.createElement(HighlightedPrimitiveBoxWithText, {
1695
- key: i,
1696
- primitive: primitive
1697
- });
1698
- }));
1719
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", {
1720
+ style: containerStyle,
1721
+ children: highlightedPrimitives.map(function(primitive, i) {
1722
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(HighlightedPrimitiveBoxWithText, {
1723
+ primitive: primitive
1724
+ }, i);
1725
+ })
1726
+ });
1699
1727
  };
1700
1728
  // src/components/MouseElementTracker.tsx
1729
+ var import_jsx_runtime4 = require("react/jsx-runtime");
1701
1730
  var MouseElementTracker = function(param) {
1702
1731
  var children = param.children, transform = param.transform, primitives = param.primitives;
1703
1732
  var _ref = _sliced_to_array((0, import_react6.useState)([]), 2), mousedPrimitives = _ref[0], setMousedPrimitives = _ref[1];
@@ -1748,7 +1777,7 @@ var MouseElementTracker = function(param) {
1748
1777
  mousedPrimitives,
1749
1778
  transform
1750
1779
  ]);
1751
- return /* @__PURE__ */ import_react6.default.createElement("div", {
1780
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", {
1752
1781
  style: {
1753
1782
  position: "relative"
1754
1783
  },
@@ -1790,14 +1819,19 @@ var MouseElementTracker = function(param) {
1790
1819
  }
1791
1820
  setMousedPrimitives(mousedPrimitives2);
1792
1821
  }
1793
- }
1794
- }, children, /* @__PURE__ */ import_react6.default.createElement(ElementOverlayBox, {
1795
- highlightedPrimitives: highlightedPrimitives
1796
- }));
1822
+ },
1823
+ children: [
1824
+ children,
1825
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ElementOverlayBox, {
1826
+ highlightedPrimitives: highlightedPrimitives
1827
+ })
1828
+ ]
1829
+ });
1797
1830
  };
1798
1831
  // src/components/DimensionOverlay.tsx
1799
1832
  var import_react8 = require("react");
1800
1833
  var import_transformation_matrix3 = require("transformation-matrix");
1834
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1801
1835
  var DimensionOverlay = function(param) {
1802
1836
  var children = param.children, transform = param.transform;
1803
1837
  if (!transform) transform = (0, import_transformation_matrix3.identity)();
@@ -1861,7 +1895,7 @@ var DimensionOverlay = function(param) {
1861
1895
  };
1862
1896
  arrowScreenBounds.width = arrowScreenBounds.right - arrowScreenBounds.left;
1863
1897
  arrowScreenBounds.height = arrowScreenBounds.bottom - arrowScreenBounds.top;
1864
- return /* @__PURE__ */ React.createElement("div", {
1898
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", {
1865
1899
  ref: containerRef,
1866
1900
  style: {
1867
1901
  position: "relative"
@@ -1889,131 +1923,178 @@ var DimensionOverlay = function(param) {
1889
1923
  } else if (dimensionToolVisible) {
1890
1924
  setDimensionToolVisible(false);
1891
1925
  }
1892
- }
1893
- }, children, dimensionToolVisible && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
1894
- style: {
1895
- position: "absolute",
1896
- left: arrowScreenBounds.left,
1897
- width: arrowScreenBounds.width,
1898
- textAlign: "center",
1899
- top: screenDStart.y + 2,
1900
- color: "red",
1901
- mixBlendMode: "difference",
1902
- pointerEvents: "none",
1903
- marginTop: arrowScreenBounds.flipY ? 0 : -20,
1904
- fontSize: 12,
1905
- fontFamily: "sans-serif",
1906
- zIndex: 1e3
1907
- }
1908
- }, Math.abs(dStart.x - dEnd.x).toFixed(2)), /* @__PURE__ */ React.createElement("div", {
1909
- style: {
1910
- position: "absolute",
1911
- left: screenDEnd.x,
1912
- height: arrowScreenBounds.height,
1913
- display: "flex",
1914
- flexDirection: "column",
1915
- justifyContent: "center",
1916
- top: arrowScreenBounds.top,
1917
- color: "red",
1918
- pointerEvents: "none",
1919
- mixBlendMode: "difference",
1920
- fontSize: 12,
1921
- fontFamily: "sans-serif",
1922
- zIndex: 1e3
1923
- }
1924
- }, /* @__PURE__ */ React.createElement("div", {
1925
- style: {
1926
- marginLeft: arrowScreenBounds.flipX ? "-100%" : 4,
1927
- paddingRight: 4
1928
- }
1929
- }, Math.abs(dStart.y - dEnd.y).toFixed(2))), /* @__PURE__ */ React.createElement("svg", {
1930
- style: {
1931
- position: "absolute",
1932
- left: 0,
1933
- top: 0,
1934
- pointerEvents: "none",
1935
- mixBlendMode: "difference",
1936
- zIndex: 1e3
1937
1926
  },
1938
- width: containerBounds.width,
1939
- height: containerBounds.height
1940
- }, /* @__PURE__ */ React.createElement("defs", null, /* @__PURE__ */ React.createElement("marker", {
1941
- id: "head",
1942
- orient: "auto",
1943
- markerWidth: "3",
1944
- markerHeight: "4",
1945
- refX: "2",
1946
- refY: "2"
1947
- }, /* @__PURE__ */ React.createElement("path", {
1948
- d: "M0,0 V4 L2,2 Z",
1949
- fill: "red"
1950
- }))), /* @__PURE__ */ React.createElement("line", {
1951
- x1: screenDStart.x,
1952
- y1: screenDStart.y,
1953
- x2: screenDEnd.x,
1954
- y2: screenDEnd.y,
1955
- markerEnd: "url(#head)",
1956
- strokeWidth: 1.5,
1957
- fill: "none",
1958
- stroke: "red"
1959
- }), /* @__PURE__ */ React.createElement("line", {
1960
- x1: screenDStart.x,
1961
- y1: screenDStart.y,
1962
- x2: screenDEnd.x,
1963
- y2: screenDStart.y,
1964
- strokeWidth: 1.5,
1965
- fill: "none",
1966
- strokeDasharray: "2,2",
1967
- stroke: "red"
1968
- }), /* @__PURE__ */ React.createElement("line", {
1969
- x1: screenDEnd.x,
1970
- y1: screenDStart.y,
1971
- x2: screenDEnd.x,
1972
- y2: screenDEnd.y,
1973
- strokeWidth: 1.5,
1974
- fill: "none",
1975
- strokeDasharray: "2,2",
1976
- stroke: "red"
1977
- })), /* @__PURE__ */ React.createElement("div", {
1978
- style: {
1979
- right: 0,
1980
- bottom: 0,
1981
- position: "absolute",
1982
- color: "red",
1983
- fontFamily: "sans-serif",
1984
- fontSize: 12,
1985
- margin: 4
1986
- }
1987
- }, "(", dStart.x.toFixed(2), ",", dStart.y.toFixed(2), ")", /* @__PURE__ */ React.createElement("br", null), "(", dEnd.x.toFixed(2), ",", dEnd.y.toFixed(2), ")", /* @__PURE__ */ React.createElement("br", null), "dist:", " ", Math.sqrt(Math.pow(dEnd.x - dStart.x, 2) + Math.pow(dEnd.y - dStart.y, 2)).toFixed(2))));
1927
+ children: [
1928
+ children,
1929
+ dimensionToolVisible && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, {
1930
+ children: [
1931
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", {
1932
+ style: {
1933
+ position: "absolute",
1934
+ left: arrowScreenBounds.left,
1935
+ width: arrowScreenBounds.width,
1936
+ textAlign: "center",
1937
+ top: screenDStart.y + 2,
1938
+ color: "red",
1939
+ mixBlendMode: "difference",
1940
+ pointerEvents: "none",
1941
+ marginTop: arrowScreenBounds.flipY ? 0 : -20,
1942
+ fontSize: 12,
1943
+ fontFamily: "sans-serif",
1944
+ zIndex: 1e3
1945
+ },
1946
+ children: Math.abs(dStart.x - dEnd.x).toFixed(2)
1947
+ }),
1948
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", {
1949
+ style: {
1950
+ position: "absolute",
1951
+ left: screenDEnd.x,
1952
+ height: arrowScreenBounds.height,
1953
+ display: "flex",
1954
+ flexDirection: "column",
1955
+ justifyContent: "center",
1956
+ top: arrowScreenBounds.top,
1957
+ color: "red",
1958
+ pointerEvents: "none",
1959
+ mixBlendMode: "difference",
1960
+ fontSize: 12,
1961
+ fontFamily: "sans-serif",
1962
+ zIndex: 1e3
1963
+ },
1964
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", {
1965
+ style: {
1966
+ marginLeft: arrowScreenBounds.flipX ? "-100%" : 4,
1967
+ paddingRight: 4
1968
+ },
1969
+ children: Math.abs(dStart.y - dEnd.y).toFixed(2)
1970
+ })
1971
+ }),
1972
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("svg", {
1973
+ style: {
1974
+ position: "absolute",
1975
+ left: 0,
1976
+ top: 0,
1977
+ pointerEvents: "none",
1978
+ mixBlendMode: "difference",
1979
+ zIndex: 1e3
1980
+ },
1981
+ width: containerBounds.width,
1982
+ height: containerBounds.height,
1983
+ children: [
1984
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("defs", {
1985
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("marker", {
1986
+ id: "head",
1987
+ orient: "auto",
1988
+ markerWidth: "3",
1989
+ markerHeight: "4",
1990
+ refX: "2",
1991
+ refY: "2",
1992
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", {
1993
+ d: "M0,0 V4 L2,2 Z",
1994
+ fill: "red"
1995
+ })
1996
+ })
1997
+ }),
1998
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("line", {
1999
+ x1: screenDStart.x,
2000
+ y1: screenDStart.y,
2001
+ x2: screenDEnd.x,
2002
+ y2: screenDEnd.y,
2003
+ markerEnd: "url(#head)",
2004
+ strokeWidth: 1.5,
2005
+ fill: "none",
2006
+ stroke: "red"
2007
+ }),
2008
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("line", {
2009
+ x1: screenDStart.x,
2010
+ y1: screenDStart.y,
2011
+ x2: screenDEnd.x,
2012
+ y2: screenDStart.y,
2013
+ strokeWidth: 1.5,
2014
+ fill: "none",
2015
+ strokeDasharray: "2,2",
2016
+ stroke: "red"
2017
+ }),
2018
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("line", {
2019
+ x1: screenDEnd.x,
2020
+ y1: screenDStart.y,
2021
+ x2: screenDEnd.x,
2022
+ y2: screenDEnd.y,
2023
+ strokeWidth: 1.5,
2024
+ fill: "none",
2025
+ strokeDasharray: "2,2",
2026
+ stroke: "red"
2027
+ })
2028
+ ]
2029
+ }),
2030
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", {
2031
+ style: {
2032
+ right: 0,
2033
+ bottom: 0,
2034
+ position: "absolute",
2035
+ color: "red",
2036
+ fontFamily: "sans-serif",
2037
+ fontSize: 12,
2038
+ margin: 4
2039
+ },
2040
+ children: [
2041
+ "(",
2042
+ dStart.x.toFixed(2),
2043
+ ",",
2044
+ dStart.y.toFixed(2),
2045
+ ")",
2046
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("br", {}),
2047
+ "(",
2048
+ dEnd.x.toFixed(2),
2049
+ ",",
2050
+ dEnd.y.toFixed(2),
2051
+ ")",
2052
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("br", {}),
2053
+ "dist:",
2054
+ " ",
2055
+ Math.sqrt(Math.pow(dEnd.x - dStart.x, 2) + Math.pow(dEnd.y - dStart.y, 2)).toFixed(2)
2056
+ ]
2057
+ })
2058
+ ]
2059
+ })
2060
+ ]
2061
+ });
1988
2062
  };
1989
2063
  // src/components/ToolbarOverlay.tsx
1990
2064
  var import_react9 = require("react");
1991
2065
  var import_css = require("@emotion/css");
1992
2066
  var import_builder2 = require("@tscircuit/builder");
2067
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1993
2068
  var LayerButton = function(param) {
1994
2069
  var name = param.name, selected = param.selected, onClick = param.onClick;
1995
- return /* @__PURE__ */ React.createElement("div", {
2070
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
1996
2071
  className: import_css.css(_templateObject()),
1997
- onClick: onClick
1998
- }, /* @__PURE__ */ React.createElement("span", {
1999
- style: {
2000
- marginRight: 2,
2001
- opacity: selected ? 1 : 0
2002
- }
2003
- }, "•"), /* @__PURE__ */ React.createElement("span", {
2004
- style: {
2005
- marginLeft: 2,
2006
- fontWeight: 500,
2007
- color: LAYER_NAME_TO_COLOR[name.replace(/-/, "")]
2008
- }
2009
- }, name));
2072
+ onClick: onClick,
2073
+ children: [
2074
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", {
2075
+ style: {
2076
+ marginRight: 2,
2077
+ opacity: selected ? 1 : 0
2078
+ },
2079
+ children: "•"
2080
+ }),
2081
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", {
2082
+ style: {
2083
+ marginLeft: 2,
2084
+ fontWeight: 500,
2085
+ color: LAYER_NAME_TO_COLOR[name.replace(/-/, "")]
2086
+ },
2087
+ children: name
2088
+ })
2089
+ ]
2090
+ });
2010
2091
  };
2011
2092
  var ToolbarButton = function(_param) {
2012
2093
  var children = _param.children, props = _object_without_properties(_param, [
2013
2094
  "children"
2014
2095
  ]);
2015
- return /* @__PURE__ */ React.createElement("div", _object_spread_props(_object_spread({}, props), {
2016
- style: {
2096
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", _object_spread_props(_object_spread({}, props), {
2097
+ style: _object_spread({
2017
2098
  backgroundColor: "#1F1F1F",
2018
2099
  border: "1px solid #666",
2019
2100
  margin: 4,
@@ -2024,13 +2105,15 @@ var ToolbarButton = function(_param) {
2024
2105
  alignSelf: "start",
2025
2106
  color: "#eee",
2026
2107
  cursor: "pointer"
2027
- }
2028
- }), children);
2108
+ }, props.style),
2109
+ children: children
2110
+ }));
2029
2111
  };
2030
2112
  var ToolbarOverlay = function(param) {
2031
2113
  var children = param.children, elements = param.elements;
2032
2114
  var _ref = _sliced_to_array((0, import_react9.useState)(false), 2), isMouseOverContainer = _ref[0], setIsMouseOverContainer = _ref[1];
2033
2115
  var _ref1 = _sliced_to_array((0, import_react9.useState)(false), 2), isLayerMenuOpen = _ref1[0], setLayerMenuOpen = _ref1[1];
2116
+ var _ref2 = _sliced_to_array((0, import_react9.useState)(false), 2), isErrorsOpen = _ref2[0], setErrorsOpen = _ref2[1];
2034
2117
  var _useStore = _sliced_to_array(useStore(function(s) {
2035
2118
  return [
2036
2119
  s.selected_layer,
@@ -2041,7 +2124,7 @@ var ToolbarOverlay = function(param) {
2041
2124
  var errorCount = (_elements_filter_length = elements === null || elements === void 0 ? void 0 : elements.filter(function(e) {
2042
2125
  return e.type.includes("error");
2043
2126
  }).length) !== null && _elements_filter_length !== void 0 ? _elements_filter_length : 0;
2044
- return /* @__PURE__ */ React.createElement("div", {
2127
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
2045
2128
  style: {
2046
2129
  position: "relative"
2047
2130
  },
@@ -2051,55 +2134,193 @@ var ToolbarOverlay = function(param) {
2051
2134
  onMouseLeave: function() {
2052
2135
  setIsMouseOverContainer(false);
2053
2136
  setLayerMenuOpen(false);
2054
- }
2055
- }, children, /* @__PURE__ */ React.createElement("div", {
2056
- style: {
2057
- position: "absolute",
2058
- opacity: isMouseOverContainer ? 1 : 0,
2059
- top: 16,
2060
- left: 16,
2061
- transition: isMouseOverContainer ? "opacity 100ms linear" : "opacity 1s linear",
2062
- zIndex: 100,
2063
- color: "red",
2064
- display: "flex",
2065
- fontSize: 12,
2066
- height: 100,
2067
- fontFamily: "sans-serif"
2068
- }
2069
- }, /* @__PURE__ */ React.createElement(ToolbarButton, {
2070
- onClick: function() {
2071
- setLayerMenuOpen(!isLayerMenuOpen);
2072
2137
  },
2073
- onMouseLeave: function() {
2074
- if (isLayerMenuOpen) {
2075
- setLayerMenuOpen(false);
2076
- }
2077
- }
2078
- }, /* @__PURE__ */ React.createElement("div", null, "layer:", " ", /* @__PURE__ */ React.createElement("span", {
2079
- style: {
2080
- marginLeft: 2,
2081
- fontWeight: 500,
2082
- color: LAYER_NAME_TO_COLOR[selectedLayer]
2083
- }
2084
- }, selectedLayer)), isLayerMenuOpen && /* @__PURE__ */ React.createElement("div", {
2138
+ children: [
2139
+ children,
2140
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
2141
+ style: {
2142
+ position: "absolute",
2143
+ opacity: isMouseOverContainer ? 1 : 0,
2144
+ top: 16,
2145
+ left: 16,
2146
+ transition: isMouseOverContainer ? "opacity 100ms linear" : "opacity 1s linear",
2147
+ zIndex: 100,
2148
+ color: "red",
2149
+ display: "flex",
2150
+ fontSize: 12,
2151
+ height: 100,
2152
+ fontFamily: "sans-serif"
2153
+ },
2154
+ children: [
2155
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(ToolbarButton, {
2156
+ onClick: function() {
2157
+ setLayerMenuOpen(!isLayerMenuOpen);
2158
+ },
2159
+ onMouseLeave: function() {
2160
+ if (isLayerMenuOpen) {
2161
+ setLayerMenuOpen(false);
2162
+ }
2163
+ },
2164
+ children: [
2165
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
2166
+ children: [
2167
+ "layer:",
2168
+ " ",
2169
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", {
2170
+ style: {
2171
+ marginLeft: 2,
2172
+ fontWeight: 500,
2173
+ color: LAYER_NAME_TO_COLOR[selectedLayer]
2174
+ },
2175
+ children: selectedLayer
2176
+ })
2177
+ ]
2178
+ }),
2179
+ isLayerMenuOpen && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
2180
+ style: {
2181
+ marginTop: 4,
2182
+ minWidth: 120
2183
+ },
2184
+ children: import_builder2.all_layers.map(function(l) {
2185
+ return l.replace(/-/g, "");
2186
+ }).map(function(layer) {
2187
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(LayerButton, {
2188
+ name: layer,
2189
+ selected: layer === selectedLayer,
2190
+ onClick: function() {
2191
+ selectLayer(layer.replace(/-/, ""));
2192
+ }
2193
+ }, layer);
2194
+ })
2195
+ })
2196
+ ]
2197
+ }),
2198
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(ToolbarButton, {
2199
+ style: errorCount > 0 ? {
2200
+ color: "red"
2201
+ } : {},
2202
+ onClick: function() {
2203
+ return setErrorsOpen(!isErrorsOpen);
2204
+ },
2205
+ onMouseLeave: function() {
2206
+ return setErrorsOpen(false);
2207
+ },
2208
+ children: [
2209
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
2210
+ children: [
2211
+ errorCount,
2212
+ " errors"
2213
+ ]
2214
+ }),
2215
+ isErrorsOpen && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
2216
+ style: {
2217
+ display: "grid",
2218
+ gridTemplateColumns: "100px 300px"
2219
+ },
2220
+ children: elements === null || elements === void 0 ? void 0 : elements.filter(function(e) {
2221
+ return e.type.includes("error");
2222
+ }).map(function(e, i) {
2223
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react9.Fragment, {
2224
+ children: [
2225
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
2226
+ children: e.error_type
2227
+ }),
2228
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
2229
+ children: e.message
2230
+ })
2231
+ ]
2232
+ }, i);
2233
+ })
2234
+ })
2235
+ ]
2236
+ })
2237
+ ]
2238
+ })
2239
+ ]
2240
+ });
2241
+ };
2242
+ // src/components/ErrorOverlay.tsx
2243
+ var import_css2 = require("@emotion/css");
2244
+ var import_react10 = require("react");
2245
+ var import_transformation_matrix4 = require("transformation-matrix");
2246
+ var import_jsx_runtime7 = require("react/jsx-runtime");
2247
+ var ErrorOverlay = function(param) {
2248
+ var children = param.children, transform = param.transform, elements = param.elements;
2249
+ var _containerRef_current;
2250
+ if (!transform) transform = (0, import_transformation_matrix4.identity)();
2251
+ var containerRef = (0, import_react10.useRef)(null);
2252
+ var containerBounds = containerRef === null || containerRef === void 0 ? void 0 : (_containerRef_current = containerRef.current) === null || _containerRef_current === void 0 ? void 0 : _containerRef_current.getBoundingClientRect();
2253
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", {
2085
2254
  style: {
2086
- marginTop: 4,
2087
- minWidth: 120
2088
- }
2089
- }, import_builder2.all_layers.map(function(l) {
2090
- return l.replace(/-/g, "");
2091
- }).map(function(layer) {
2092
- return /* @__PURE__ */ React.createElement(LayerButton, {
2093
- key: layer,
2094
- name: layer,
2095
- selected: layer === selectedLayer,
2096
- onClick: function() {
2097
- selectLayer(layer.replace(/-/, ""));
2098
- }
2099
- });
2100
- }))), /* @__PURE__ */ React.createElement(ToolbarButton, null, errorCount, " errors")));
2255
+ position: "relative"
2256
+ },
2257
+ ref: containerRef,
2258
+ children: [
2259
+ children,
2260
+ elements === null || elements === void 0 ? void 0 : elements.filter(function(el) {
2261
+ return el.type === "pcb_error";
2262
+ }).map(function(el) {
2263
+ var pcb_port_ids = el.pcb_port_ids;
2264
+ var port1 = elements.find(function(el2) {
2265
+ return el2.type === "pcb_port" && el2.pcb_port_id === pcb_port_ids[0];
2266
+ });
2267
+ var port2 = elements.find(function(el2) {
2268
+ return el2.type === "pcb_port" && el2.pcb_port_id === pcb_port_ids[1];
2269
+ });
2270
+ if (!port1 || !port2) return null;
2271
+ var screenPort1 = (0, import_transformation_matrix4.applyToPoint)(transform, {
2272
+ x: port1.x,
2273
+ y: port1.y
2274
+ });
2275
+ var screenPort2 = (0, import_transformation_matrix4.applyToPoint)(transform, {
2276
+ x: port2.x,
2277
+ y: port2.y
2278
+ });
2279
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, {
2280
+ children: [
2281
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("svg", {
2282
+ style: {
2283
+ position: "absolute",
2284
+ left: 0,
2285
+ top: 0,
2286
+ pointerEvents: "none",
2287
+ mixBlendMode: "difference",
2288
+ zIndex: 1e3
2289
+ },
2290
+ width: containerBounds === null || containerBounds === void 0 ? void 0 : containerBounds.width,
2291
+ height: containerBounds === null || containerBounds === void 0 ? void 0 : containerBounds.height,
2292
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("line", {
2293
+ x1: screenPort1.x,
2294
+ y1: screenPort1.y,
2295
+ x2: screenPort2.x,
2296
+ y2: screenPort2.y,
2297
+ markerEnd: "url(#head)",
2298
+ strokeWidth: 1.5,
2299
+ strokeDasharray: "2,2",
2300
+ fill: "none",
2301
+ stroke: "red"
2302
+ })
2303
+ }),
2304
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", {
2305
+ className: import_css2.css(_templateObject1(), (screenPort1.x + screenPort2.x) / 2, (screenPort1.y + screenPort2.y) / 2),
2306
+ children: [
2307
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", {
2308
+ className: "error-message",
2309
+ children: el.message
2310
+ }),
2311
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", {
2312
+ className: import_css2.css(_templateObject2())
2313
+ })
2314
+ ]
2315
+ })
2316
+ ]
2317
+ });
2318
+ })
2319
+ ]
2320
+ });
2101
2321
  };
2102
2322
  // src/components/CanvasElementsRenderer.tsx
2323
+ var import_jsx_runtime8 = require("react/jsx-runtime");
2103
2324
  var CanvasElementsRenderer = function(props) {
2104
2325
  var primitives = (0, import_react11.useMemo)(function() {
2105
2326
  var primitives2 = props.elements.flatMap(function(elm) {
@@ -2109,20 +2330,27 @@ var CanvasElementsRenderer = function(props) {
2109
2330
  }, [
2110
2331
  props.elements
2111
2332
  ]);
2112
- return /* @__PURE__ */ import_react10.default.createElement(MouseElementTracker, {
2113
- transform: props.transform,
2114
- primitives: primitives
2115
- }, /* @__PURE__ */ import_react10.default.createElement(DimensionOverlay, {
2116
- transform: props.transform
2117
- }, /* @__PURE__ */ import_react10.default.createElement(ToolbarOverlay, {
2118
- elements: props.elements
2119
- }, /* @__PURE__ */ import_react10.default.createElement(CanvasPrimitiveRenderer, {
2333
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MouseElementTracker, {
2120
2334
  transform: props.transform,
2121
2335
  primitives: primitives,
2122
- width: props.width,
2123
- height: props.height,
2124
- grid: props.grid
2125
- }))));
2336
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(DimensionOverlay, {
2337
+ transform: props.transform,
2338
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ToolbarOverlay, {
2339
+ elements: props.elements,
2340
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ErrorOverlay, {
2341
+ transform: props.transform,
2342
+ elements: props.elements,
2343
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CanvasPrimitiveRenderer, {
2344
+ transform: props.transform,
2345
+ primitives: primitives,
2346
+ width: props.width,
2347
+ height: props.height,
2348
+ grid: props.grid
2349
+ })
2350
+ })
2351
+ })
2352
+ })
2353
+ });
2126
2354
  };
2127
2355
  // src/PCBViewer.tsx
2128
2356
  var import_use_mouse_matrix_transform = __toESM(require_dist());
@@ -2186,9 +2414,10 @@ var useMeasure_default = isBrowser && typeof window.ResizeObserver !== "undefine
2186
2414
  ];
2187
2415
  };
2188
2416
  // src/PCBViewer.tsx
2189
- var import_transformation_matrix4 = require("transformation-matrix");
2417
+ var import_transformation_matrix5 = require("transformation-matrix");
2190
2418
  var import_builder4 = require("@tscircuit/builder");
2191
- var defaultTransform = (0, import_transformation_matrix4.compose)((0, import_transformation_matrix4.translate)(400, 300), (0, import_transformation_matrix4.scale)(40, -40));
2419
+ var import_jsx_runtime9 = require("react/jsx-runtime");
2420
+ var defaultTransform = (0, import_transformation_matrix5.compose)((0, import_transformation_matrix5.translate)(400, 300), (0, import_transformation_matrix5.scale)(40, -40));
2192
2421
  var PCBViewer = function(param) {
2193
2422
  var children = param.children, soup = param.soup, _param_height = param.height, height = _param_height === void 0 ? 600 : _param_height;
2194
2423
  var _ref = _sliced_to_array((0, import_react14.useState)([]), 2), stateElements = _ref[0], setStateElements = _ref[1];
@@ -2219,8 +2448,8 @@ var PCBViewer = function(param) {
2219
2448
  var _elmBounds_width, _elmBounds_height;
2220
2449
  var scaleFactor = Math.min(((_elmBounds_width = elmBounds.width) !== null && _elmBounds_width !== void 0 ? _elmBounds_width : 0) / width, ((_elmBounds_height = elmBounds.height) !== null && _elmBounds_height !== void 0 ? _elmBounds_height : 0) / height2, 100);
2221
2450
  var _elmBounds_width1, _elmBounds_height1;
2222
- setTransform((0, import_transformation_matrix4.compose)((0, import_transformation_matrix4.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), // translate(100, 0),
2223
- (0, import_transformation_matrix4.scale)(scaleFactor, -scaleFactor, 0, 0), (0, import_transformation_matrix4.translate)(-center.x, -center.y)));
2451
+ setTransform((0, import_transformation_matrix5.compose)((0, import_transformation_matrix5.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), // translate(100, 0),
2452
+ (0, import_transformation_matrix5.scale)(scaleFactor, -scaleFactor, 0, 0), (0, import_transformation_matrix5.translate)(-center.x, -center.y)));
2224
2453
  };
2225
2454
  (0, import_react14.useEffect)(function() {
2226
2455
  var doRender = function doRender() {
@@ -2259,42 +2488,49 @@ var PCBViewer = function(param) {
2259
2488
  children
2260
2489
  ]);
2261
2490
  (0, import_react14.useEffect)(function() {
2262
- if (refDimensions && refDimensions.width !== 0 && children) {
2491
+ if (refDimensions && refDimensions.width !== 0 && (children || soup)) {
2263
2492
  resetTransform();
2264
2493
  }
2265
2494
  }, [
2266
2495
  children,
2267
2496
  refDimensions
2268
2497
  ]);
2269
- if (error) return /* @__PURE__ */ import_react14.default.createElement("div", {
2498
+ if (error) return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", {
2270
2499
  style: {
2271
2500
  color: "red"
2272
- }
2273
- }, " ", error, " ");
2274
- var elements = soup !== null && soup !== void 0 ? soup : stateElements;
2275
- if (elements.length === 0) return null;
2276
- return /* @__PURE__ */ import_react14.default.createElement("div", {
2277
- ref: transformRef
2278
- }, /* @__PURE__ */ import_react14.default.createElement("div", {
2279
- ref: ref
2280
- }, /* @__PURE__ */ import_react14.default.createElement(ContextProviders, null, /* @__PURE__ */ import_react14.default.createElement(CanvasElementsRenderer, {
2281
- key: refDimensions.width,
2282
- transform: transform,
2283
- height: height,
2284
- width: refDimensions.width,
2285
- grid: {
2286
- spacing: 1,
2287
- view_window: {
2288
- left: 0,
2289
- right: refDimensions.width || 500,
2290
- top: height,
2291
- bottom: 0
2292
- }
2293
2501
  },
2294
- elements: elements.filter(function(elm) {
2295
- return elm.type.startsWith("pcb_") || elm.type.startsWith("source_");
2502
+ children: [
2503
+ " ",
2504
+ error,
2505
+ " "
2506
+ ]
2507
+ });
2508
+ var elements = soup !== null && soup !== void 0 ? soup : stateElements;
2509
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", {
2510
+ ref: transformRef,
2511
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", {
2512
+ ref: ref,
2513
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ContextProviders, {
2514
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CanvasElementsRenderer, {
2515
+ transform: transform,
2516
+ height: height,
2517
+ width: refDimensions.width,
2518
+ grid: {
2519
+ spacing: 1,
2520
+ view_window: {
2521
+ left: 0,
2522
+ right: refDimensions.width || 500,
2523
+ top: height,
2524
+ bottom: 0
2525
+ }
2526
+ },
2527
+ elements: elements.filter(function(elm) {
2528
+ return elm.type.startsWith("pcb_") || elm.type.startsWith("source_");
2529
+ })
2530
+ }, refDimensions.width)
2531
+ })
2296
2532
  })
2297
- }))));
2533
+ });
2298
2534
  };
2299
2535
  // Annotate the CommonJS export names for ESM import in node:
2300
2536
  0 && (module.exports = {