@tscircuit/schematic-viewer 1.2.8 → 1.2.10

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
@@ -292,7 +292,7 @@ var require_with_selector_development = __commonJS({
292
292
  }
293
293
  var objectIs = typeof Object.is === "function" ? Object.is : is;
294
294
  var useSyncExternalStore = shim.useSyncExternalStore;
295
- var useRef2 = React.useRef, useEffect4 = React.useEffect, useMemo2 = React.useMemo, useDebugValue2 = React.useDebugValue;
295
+ var useRef2 = React.useRef, useEffect4 = React.useEffect, useMemo3 = React.useMemo, useDebugValue2 = React.useDebugValue;
296
296
  function useSyncExternalStoreWithSelector2(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
297
297
  var instRef = useRef2(null);
298
298
  var inst;
@@ -305,7 +305,7 @@ var require_with_selector_development = __commonJS({
305
305
  } else {
306
306
  inst = instRef.current;
307
307
  }
308
- var _useMemo = useMemo2(function() {
308
+ var _useMemo = useMemo3(function() {
309
309
  var hasMemo = false;
310
310
  var memoizedSnapshot;
311
311
  var memoizedSelection;
@@ -933,46 +933,13 @@ var require_svg_path_generator2 = __commonJS({
933
933
  // src/index.ts
934
934
  var src_exports = {};
935
935
  __export(src_exports, {
936
- Schematic: () => Schematic
936
+ Schematic: () => Schematic,
937
+ SchematicWithoutContext: () => SchematicWithoutContext
937
938
  });
938
939
  module.exports = __toCommonJS(src_exports);
939
940
 
940
941
  // src/Schematic.tsx
941
- var import_react6 = require("react");
942
- var import_react_supergrid = require("react-supergrid");
943
- var import_builder3 = require("@tscircuit/builder");
944
- var import_react_fiber = __toESM(require("@tscircuit/react-fiber"));
945
-
946
- // src/lib/utils/collect-element-refs.ts
947
- var collectElementRefs = (elm, allElms) => {
948
- const source_port = allElms.find(
949
- (e) => e.type === "source_port" && e.source_port_id === elm.source_port_id
950
- );
951
- const source_component_id = elm.source_component_id ?? source_port?.source_component_id;
952
- const source_component = allElms.find(
953
- (e) => e.type === "source_component" && e.source_component_id === source_component_id
954
- );
955
- if ([
956
- "schematic_component",
957
- "schematic_trace",
958
- "schematic_port",
959
- "schematic_box",
960
- "schematic_line",
961
- "schematic_path"
962
- ].includes(elm.type)) {
963
- const schematic_children = allElms.filter(
964
- (e) => "schematic_component_id" in e && e.schematic_component_id === elm.schematic_component_id
965
- );
966
- return {
967
- schematic_children,
968
- schematic: elm,
969
- source: source_component,
970
- source_component,
971
- source_port
972
- };
973
- }
974
- return null;
975
- };
942
+ var import_react9 = require("react");
976
943
 
977
944
  // node_modules/zustand/esm/vanilla.js
978
945
  var createStoreImpl = (createState) => {
@@ -1017,14 +984,6 @@ function useStore(api, selector = api.getState, equalityFn) {
1017
984
  (0, import_react.useDebugValue)(slice);
1018
985
  return slice;
1019
986
  }
1020
- var createImpl = (createState) => {
1021
- const api = typeof createState === "function" ? createStore(createState) : createState;
1022
- const useBoundStore = (selector, equalityFn) => useStore(api, selector, equalityFn);
1023
- Object.assign(useBoundStore, api);
1024
- return useBoundStore;
1025
- };
1026
- var create = (createState) => createState ? createImpl(createState) : createImpl;
1027
- var create$1 = create;
1028
987
 
1029
988
  // node_modules/transformation-matrix/src/applyToPoint.js
1030
989
  function applyToPoint(matrix, point) {
@@ -1247,11 +1206,15 @@ peg$SyntaxError.buildMessage = function(expected, found) {
1247
1206
  };
1248
1207
 
1249
1208
  // src/lib/render-context/index.ts
1250
- var useRenderContext = create$1((set, get) => ({
1209
+ var import_react2 = require("react");
1210
+ var createRenderContextStore = () => createStore((set) => ({
1251
1211
  camera_transform: compose(scale(100, 100, 0, 0)),
1252
1212
  setCameraTransform: (transform2) => set({ camera_transform: transform2 })
1253
1213
  }));
1254
- var useCameraTransform = () => useRenderContext((s) => s.camera_transform);
1214
+ var useGlobalStore = (s) => {
1215
+ const store = (0, import_react2.useContext)(StoreContext);
1216
+ return useStore(store, s);
1217
+ };
1255
1218
 
1256
1219
  // src/lib/utils/get-svg-path-bounds.ts
1257
1220
  var import_svg_path_bounds = __toESM(require_svg_path_bounds());
@@ -1271,7 +1234,7 @@ function getSVGPathBounds(ds) {
1271
1234
  var get_svg_path_bounds_default = getSVGPathBounds;
1272
1235
 
1273
1236
  // src/schematic-components/SVGPathComponent.tsx
1274
- var import_react2 = require("react");
1237
+ var import_react3 = require("react");
1275
1238
  var import_jsx_runtime = require("react/jsx-runtime");
1276
1239
  var SVGPathComponent = ({
1277
1240
  size,
@@ -1283,7 +1246,7 @@ var SVGPathComponent = ({
1283
1246
  shiftToBottom,
1284
1247
  hoverContent
1285
1248
  }) => {
1286
- const ct = useCameraTransform();
1249
+ const ct = useGlobalStore((s) => s.camera_transform);
1287
1250
  const pathBounds = get_svg_path_bounds_default(paths.map((p) => p.d));
1288
1251
  const badRatio = Math.abs(pathBounds.width / pathBounds.height - size.width / size.height) > 0.01;
1289
1252
  if (badRatio) {
@@ -1301,7 +1264,7 @@ var SVGPathComponent = ({
1301
1264
  width: innerSize.width + padding.x * 2,
1302
1265
  height: innerSize.height + padding.y * 2
1303
1266
  };
1304
- const [hovering, setHovering] = (0, import_react2.useState)(false);
1267
+ const [hovering, setHovering] = (0, import_react3.useState)(false);
1305
1268
  const svgLeft = absoluteCenter.x - fullSize.width / 2;
1306
1269
  const svgTop = absoluteCenter.y - fullSize.height / 2;
1307
1270
  const preferredRatio = pathBounds.width === 0 ? innerSize.height / pathBounds.height : innerSize.width / pathBounds.width;
@@ -1435,12 +1398,50 @@ var SimpleCapacitor = ({
1435
1398
  };
1436
1399
 
1437
1400
  // src/lib/hooks/use-maybe-promise.ts
1438
- var import_react3 = require("react");
1401
+ var import_react4 = require("react");
1439
1402
 
1440
1403
  // src/schematic-components/ProjectComponent.tsx
1441
1404
  var import_builder = require("@tscircuit/builder");
1442
1405
  var import_jsx_runtime4 = require("react/jsx-runtime");
1443
1406
 
1407
+ // src/schematic-components/SchematicComponent.tsx
1408
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1409
+ var SchematicComponent = ({ component }) => {
1410
+ const { source, schematic } = component;
1411
+ if (!source.ftype)
1412
+ return null;
1413
+ switch (source.ftype) {
1414
+ case "simple_resistor": {
1415
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimpleResistor, { component: { source, schematic } });
1416
+ }
1417
+ case "simple_capacitor": {
1418
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimpleCapacitor, { component: { source, schematic } });
1419
+ }
1420
+ case "simple_power_source": {
1421
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimplePowerSource, { component: { source, schematic } });
1422
+ }
1423
+ case "simple_ground": {
1424
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimpleGround, { component: { source, schematic } });
1425
+ }
1426
+ case "simple_inductor": {
1427
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimpleInductor, { component: { source, schematic } });
1428
+ }
1429
+ case "simple_bug": {
1430
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SchematicBug, { component: { source, schematic } });
1431
+ }
1432
+ case "simple_diode": {
1433
+ return null;
1434
+ }
1435
+ default: {
1436
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1437
+ "unknown ftype: ",
1438
+ component.source.ftype
1439
+ ] });
1440
+ }
1441
+ }
1442
+ };
1443
+ var SchematicComponent_default = SchematicComponent;
1444
+
1444
1445
  // src/lib/utils/direction-to-vec.ts
1445
1446
  var directionToVec = (direction) => {
1446
1447
  if (direction === "up")
@@ -1456,19 +1457,19 @@ var directionToVec = (direction) => {
1456
1457
  };
1457
1458
 
1458
1459
  // src/schematic-components/SchematicPort.tsx
1459
- var import_jsx_runtime5 = require("react/jsx-runtime");
1460
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1460
1461
  var SchematicPort = ({
1461
1462
  port: { source_port, source_component, schematic }
1462
1463
  }) => {
1463
1464
  const hoverName = source_component?.name ? `.${source_component.name} > .${source_port?.name ?? source_port?.pin_number}` : `.${source_port?.name ?? source_port?.pin_number}`;
1464
1465
  const vec = directionToVec(schematic.facing_direction);
1465
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1466
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1466
1467
  SVGPathComponent,
1467
1468
  {
1468
1469
  rotation: 0,
1469
- hoverContent: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1470
+ hoverContent: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
1470
1471
  hoverName,
1471
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("br", {}),
1472
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("br", {}),
1472
1473
  source_port?.pin_number && `Pin ${source_port.pin_number}`
1473
1474
  ] }),
1474
1475
  center: schematic.center,
@@ -1495,7 +1496,7 @@ var SchematicPort = ({
1495
1496
  var SchematicPort_default = SchematicPort;
1496
1497
 
1497
1498
  // node_modules/react-use-measure/dist/web.js
1498
- var import_react4 = require("react");
1499
+ var import_react5 = require("react");
1499
1500
  var import_debounce = __toESM(require_debounce());
1500
1501
  function useMeasure(_temp) {
1501
1502
  let {
@@ -1513,7 +1514,7 @@ function useMeasure(_temp) {
1513
1514
  if (!ResizeObserver) {
1514
1515
  throw new Error("This browser does not support ResizeObserver out of the box. See: https://github.com/react-spring/react-use-measure/#resize-observer-polyfills");
1515
1516
  }
1516
- const [bounds, set] = (0, import_react4.useState)({
1517
+ const [bounds, set] = (0, import_react5.useState)({
1517
1518
  left: 0,
1518
1519
  top: 0,
1519
1520
  width: 0,
@@ -1523,7 +1524,7 @@ function useMeasure(_temp) {
1523
1524
  x: 0,
1524
1525
  y: 0
1525
1526
  });
1526
- const state = (0, import_react4.useRef)({
1527
+ const state = (0, import_react5.useRef)({
1527
1528
  element: null,
1528
1529
  scrollContainers: null,
1529
1530
  resizeObserver: null,
@@ -1531,12 +1532,12 @@ function useMeasure(_temp) {
1531
1532
  });
1532
1533
  const scrollDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.scroll : null;
1533
1534
  const resizeDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.resize : null;
1534
- const mounted = (0, import_react4.useRef)(false);
1535
- (0, import_react4.useEffect)(() => {
1535
+ const mounted = (0, import_react5.useRef)(false);
1536
+ (0, import_react5.useEffect)(() => {
1536
1537
  mounted.current = true;
1537
1538
  return () => void (mounted.current = false);
1538
1539
  });
1539
- const [forceRefresh, resizeChange, scrollChange] = (0, import_react4.useMemo)(() => {
1540
+ const [forceRefresh, resizeChange, scrollChange] = (0, import_react5.useMemo)(() => {
1540
1541
  const callback = () => {
1541
1542
  if (!state.current.element)
1542
1543
  return;
@@ -1602,22 +1603,22 @@ function useMeasure(_temp) {
1602
1603
  };
1603
1604
  useOnWindowScroll(scrollChange, Boolean(scroll));
1604
1605
  useOnWindowResize(resizeChange);
1605
- (0, import_react4.useEffect)(() => {
1606
+ (0, import_react5.useEffect)(() => {
1606
1607
  removeListeners();
1607
1608
  addListeners();
1608
1609
  }, [scroll, scrollChange, resizeChange]);
1609
- (0, import_react4.useEffect)(() => removeListeners, []);
1610
+ (0, import_react5.useEffect)(() => removeListeners, []);
1610
1611
  return [ref, bounds, forceRefresh];
1611
1612
  }
1612
1613
  function useOnWindowResize(onWindowResize) {
1613
- (0, import_react4.useEffect)(() => {
1614
+ (0, import_react5.useEffect)(() => {
1614
1615
  const cb = onWindowResize;
1615
1616
  window.addEventListener("resize", cb);
1616
1617
  return () => void window.removeEventListener("resize", cb);
1617
1618
  }, [onWindowResize]);
1618
1619
  }
1619
1620
  function useOnWindowScroll(onScroll, enabled) {
1620
- (0, import_react4.useEffect)(() => {
1621
+ (0, import_react5.useEffect)(() => {
1621
1622
  if (enabled) {
1622
1623
  const cb = onScroll;
1623
1624
  window.addEventListener("scroll", cb, {
@@ -1645,9 +1646,9 @@ var keys = ["x", "y", "top", "bottom", "left", "right", "width", "height"];
1645
1646
  var areBoundsEqual = (a, b) => keys.every((key) => a[key] === b[key]);
1646
1647
 
1647
1648
  // src/schematic-components/SchematicText.tsx
1648
- var import_jsx_runtime6 = require("react/jsx-runtime");
1649
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1649
1650
  var SchematicText = ({ schematic_text }) => {
1650
- const ct = useCameraTransform();
1651
+ const ct = useGlobalStore((s) => s.camera_transform);
1651
1652
  const { text, position, anchor } = schematic_text;
1652
1653
  const tPos = applyToPoint(ct, position);
1653
1654
  const [boundsRef, bounds] = useMeasure();
@@ -1661,7 +1662,7 @@ var SchematicText = ({ schematic_text }) => {
1661
1662
  }
1662
1663
  const fontTransformRatio = 0.15;
1663
1664
  const projectedTextSize = fontTransformRatio * ct.a;
1664
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1665
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1665
1666
  "div",
1666
1667
  {
1667
1668
  ref: boundsRef,
@@ -1682,9 +1683,9 @@ var SchematicText_default = SchematicText;
1682
1683
  var import_svg_path_generator = __toESM(require_svg_path_generator2());
1683
1684
 
1684
1685
  // src/schematic-components/RenderError.tsx
1685
- var import_jsx_runtime7 = require("react/jsx-runtime");
1686
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1686
1687
  var RenderError_default = ({ text }) => {
1687
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1688
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1688
1689
  "div",
1689
1690
  {
1690
1691
  style: {
@@ -1704,7 +1705,7 @@ var RenderError_default = ({ text }) => {
1704
1705
  };
1705
1706
 
1706
1707
  // src/schematic-components/SVGPathComponent2.tsx
1707
- var import_jsx_runtime8 = require("react/jsx-runtime");
1708
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1708
1709
  var SVGPathComponent2 = ({
1709
1710
  size,
1710
1711
  center,
@@ -1715,9 +1716,9 @@ var SVGPathComponent2 = ({
1715
1716
  shiftToBottom,
1716
1717
  hoverContent
1717
1718
  }) => {
1718
- const ct = useCameraTransform();
1719
+ const ct = useGlobalStore((c) => c.camera_transform);
1719
1720
  const pathBounds = get_svg_path_bounds_default(paths.map((p) => p.d));
1720
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1721
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1721
1722
  "svg",
1722
1723
  {
1723
1724
  style: {
@@ -1734,7 +1735,7 @@ var SVGPathComponent2 = ({
1734
1735
  // backgroundColor: "rgba(255, 0, 0, 0.1)",
1735
1736
  },
1736
1737
  overflow: "visible",
1737
- children: paths.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1738
+ children: paths.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1738
1739
  "path",
1739
1740
  {
1740
1741
  transform: toSVG(ct),
@@ -1752,11 +1753,11 @@ var SVGPathComponent2 = ({
1752
1753
  var SVGPathComponent2_default = SVGPathComponent2;
1753
1754
 
1754
1755
  // src/schematic-components/SchematicTrace.tsx
1755
- var import_jsx_runtime9 = require("react/jsx-runtime");
1756
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1756
1757
  var SchematicTrace = ({ trace: { source, schematic } }) => {
1757
1758
  const edges = schematic.edges;
1758
1759
  if (edges.length === 0) {
1759
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(RenderError_default, { text: `Route with 0 edges (${source.source_trace_id})` });
1760
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(RenderError_default, { text: `Route with 0 edges (${source.source_trace_id})` });
1760
1761
  }
1761
1762
  const path = (0, import_svg_path_generator.default)();
1762
1763
  for (let i = 0; i < edges.length; i++) {
@@ -1771,7 +1772,7 @@ var SchematicTrace = ({ trace: { source, schematic } }) => {
1771
1772
  x: pathBounds.minX + pathBounds.width / 2,
1772
1773
  y: pathBounds.minY + pathBounds.height / 2
1773
1774
  };
1774
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1775
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1775
1776
  SVGPathComponent2_default,
1776
1777
  {
1777
1778
  rotation: 0,
@@ -1791,7 +1792,7 @@ var SchematicTrace_default = SchematicTrace;
1791
1792
 
1792
1793
  // src/schematic-components/SchematicBug.tsx
1793
1794
  var import_builder2 = require("@tscircuit/builder");
1794
- var import_jsx_runtime10 = require("react/jsx-runtime");
1795
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1795
1796
  var SchematicBug = ({ component: { source, schematic } }) => {
1796
1797
  const port_arrangement = {
1797
1798
  top_size: 0,
@@ -1828,7 +1829,7 @@ var SchematicBug = ({ component: { source, schematic } }) => {
1828
1829
  x: schematic.center.x + (actualSize.minX + actualSize.maxX) / 2,
1829
1830
  y: schematic.center.y + (actualSize.minY + actualSize.maxY) / 2
1830
1831
  };
1831
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1832
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1832
1833
  SVGPathComponent_default,
1833
1834
  {
1834
1835
  rotation: schematic.rotation,
@@ -1840,11 +1841,11 @@ var SchematicBug = ({ component: { source, schematic } }) => {
1840
1841
  };
1841
1842
 
1842
1843
  // src/schematic-components/SimplePowerSource.tsx
1843
- var import_jsx_runtime11 = require("react/jsx-runtime");
1844
+ var import_jsx_runtime12 = require("react/jsx-runtime");
1844
1845
  var SimplePowerSource = ({
1845
1846
  component: { source, schematic }
1846
1847
  }) => {
1847
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1848
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1848
1849
  SVGPathComponent_default,
1849
1850
  {
1850
1851
  rotation: schematic.rotation,
@@ -1875,9 +1876,9 @@ var SimplePowerSource = ({
1875
1876
  };
1876
1877
 
1877
1878
  // src/schematic-components/SimpleGround.tsx
1878
- var import_jsx_runtime12 = require("react/jsx-runtime");
1879
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1879
1880
  var SimpleGround = ({ component: { source, schematic } }) => {
1880
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1881
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1881
1882
  SVGPathComponent_default,
1882
1883
  {
1883
1884
  rotation: schematic.rotation,
@@ -1897,9 +1898,9 @@ var SimpleGround = ({ component: { source, schematic } }) => {
1897
1898
  };
1898
1899
 
1899
1900
  // src/schematic-components/SimpleInductor.tsx
1900
- var import_jsx_runtime13 = require("react/jsx-runtime");
1901
+ var import_jsx_runtime14 = require("react/jsx-runtime");
1901
1902
  var SimpleInductor = ({ component: { source, schematic } }) => {
1902
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1903
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1903
1904
  SVGPathComponent_default,
1904
1905
  {
1905
1906
  rotation: schematic.rotation,
@@ -1918,51 +1919,59 @@ var SimpleInductor = ({ component: { source, schematic } }) => {
1918
1919
  };
1919
1920
 
1920
1921
  // src/schematic-components/SimpleDiode.tsx
1921
- var import_jsx_runtime14 = require("react/jsx-runtime");
1922
-
1923
- // src/schematic-components/SchematicComponent.tsx
1924
1922
  var import_jsx_runtime15 = require("react/jsx-runtime");
1925
- var SchematicComponent = ({ component }) => {
1926
- const { source, schematic } = component;
1927
- if (!source.ftype)
1928
- return null;
1929
- switch (source.ftype) {
1930
- case "simple_resistor": {
1931
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SimpleResistor, { component: { source, schematic } });
1932
- }
1933
- case "simple_capacitor": {
1934
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SimpleCapacitor, { component: { source, schematic } });
1935
- }
1936
- case "simple_power_source": {
1937
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SimplePowerSource, { component: { source, schematic } });
1938
- }
1939
- case "simple_ground": {
1940
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SimpleGround, { component: { source, schematic } });
1941
- }
1942
- case "simple_inductor": {
1943
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SimpleInductor, { component: { source, schematic } });
1944
- }
1945
- case "simple_bug": {
1946
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SchematicBug, { component: { source, schematic } });
1947
- }
1948
- case "simple_diode": {
1949
- return null;
1950
- }
1951
- default: {
1952
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { children: [
1953
- "unknown ftype: ",
1954
- component.source.ftype
1955
- ] });
1956
- }
1923
+
1924
+ // src/schematic-components/ContextProviders.tsx
1925
+ var import_react6 = require("react");
1926
+ var import_react7 = require("react");
1927
+ var import_jsx_runtime16 = require("react/jsx-runtime");
1928
+ var StoreContext = (0, import_react7.createContext)(null);
1929
+ var ContextProviders = ({ children }) => {
1930
+ const store = (0, import_react6.useMemo)(() => createRenderContextStore(), []);
1931
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(StoreContext.Provider, { value: store, children });
1932
+ };
1933
+
1934
+ // src/Schematic.tsx
1935
+ var import_react_supergrid = require("react-supergrid");
1936
+ var import_builder3 = require("@tscircuit/builder");
1937
+ var import_react_fiber = __toESM(require("@tscircuit/react-fiber"));
1938
+
1939
+ // src/lib/utils/collect-element-refs.ts
1940
+ var collectElementRefs = (elm, allElms) => {
1941
+ const source_port = allElms.find(
1942
+ (e) => e.type === "source_port" && e.source_port_id === elm.source_port_id
1943
+ );
1944
+ const source_component_id = elm.source_component_id ?? source_port?.source_component_id;
1945
+ const source_component = allElms.find(
1946
+ (e) => e.type === "source_component" && e.source_component_id === source_component_id
1947
+ );
1948
+ if ([
1949
+ "schematic_component",
1950
+ "schematic_trace",
1951
+ "schematic_port",
1952
+ "schematic_box",
1953
+ "schematic_line",
1954
+ "schematic_path"
1955
+ ].includes(elm.type)) {
1956
+ const schematic_children = allElms.filter(
1957
+ (e) => "schematic_component_id" in e && e.schematic_component_id === elm.schematic_component_id
1958
+ );
1959
+ return {
1960
+ schematic_children,
1961
+ schematic: elm,
1962
+ source: source_component,
1963
+ source_component,
1964
+ source_port
1965
+ };
1957
1966
  }
1967
+ return null;
1958
1968
  };
1959
- var SchematicComponent_default = SchematicComponent;
1960
1969
 
1961
1970
  // src/schematic-components/SchematicBox.tsx
1962
- var import_jsx_runtime16 = require("react/jsx-runtime");
1971
+ var import_jsx_runtime17 = require("react/jsx-runtime");
1963
1972
  var SchematicBox = ({ box: { schematic } }) => {
1964
1973
  const { width: w, height: h } = schematic;
1965
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1974
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1966
1975
  SVGPathComponent,
1967
1976
  {
1968
1977
  rotation: 0,
@@ -1982,7 +1991,7 @@ var SchematicBox_default = SchematicBox;
1982
1991
 
1983
1992
  // src/schematic-components/SchematicLine.tsx
1984
1993
  var import_svg_path_generator2 = __toESM(require_svg_path_generator2());
1985
- var import_jsx_runtime17 = require("react/jsx-runtime");
1994
+ var import_jsx_runtime18 = require("react/jsx-runtime");
1986
1995
  var SchematicLine = ({ line: { schematic } }) => {
1987
1996
  const { x1, x2, y1, y2 } = schematic;
1988
1997
  const dx = x2 - x1;
@@ -1996,7 +2005,7 @@ var SchematicLine = ({ line: { schematic } }) => {
1996
2005
  x: pathBounds.minX + pathBounds.width / 2,
1997
2006
  y: pathBounds.minY + pathBounds.height / 2
1998
2007
  };
1999
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2008
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2000
2009
  SVGPathComponent,
2001
2010
  {
2002
2011
  rotation: 0,
@@ -2016,7 +2025,7 @@ var SchematicLine_default = SchematicLine;
2016
2025
 
2017
2026
  // src/schematic-components/SchematicPath.tsx
2018
2027
  var import_svg_path_generator3 = __toESM(require_svg_path_generator2());
2019
- var import_jsx_runtime18 = require("react/jsx-runtime");
2028
+ var import_jsx_runtime19 = require("react/jsx-runtime");
2020
2029
  var SchematicPath = (props) => {
2021
2030
  const { points, is_filled, is_closed, fill_color } = props.path.schematic;
2022
2031
  if (points.length === 0)
@@ -2037,7 +2046,7 @@ var SchematicPath = (props) => {
2037
2046
  x: pathBounds.minX + pathBounds.width / 2,
2038
2047
  y: pathBounds.minY + pathBounds.height / 2
2039
2048
  };
2040
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2049
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2041
2050
  SVGPathComponent,
2042
2051
  {
2043
2052
  rotation: 0,
@@ -2056,14 +2065,60 @@ var SchematicPath = (props) => {
2056
2065
  };
2057
2066
  var SchematicPath_default = SchematicPath;
2058
2067
 
2068
+ // src/schematic-components/SchematicNetLabel.tsx
2069
+ var import_jsx_runtime20 = require("react/jsx-runtime");
2070
+ var SchematicNetLabel = ({
2071
+ net_label
2072
+ }) => {
2073
+ console.log({ net_label });
2074
+ const text_width = net_label.text.length * 0.15;
2075
+ const path_width = 31 + net_label.text.length * 5;
2076
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
2077
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2078
+ SVGPathComponent_default,
2079
+ {
2080
+ rotation: 0,
2081
+ center: net_label.center,
2082
+ size: {
2083
+ width: 0.05 + text_width,
2084
+ height: 0.175
2085
+ },
2086
+ paths: [
2087
+ {
2088
+ stroke: "gray",
2089
+ strokeWidth: 0.75,
2090
+ d: `M 0 15 L 5 15 L 11 9 L ${path_width} 9 L ${path_width} 21 L 11 21 L 5 15`
2091
+ }
2092
+ ]
2093
+ }
2094
+ ),
2095
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2096
+ SchematicText_default,
2097
+ {
2098
+ schematic_text: {
2099
+ anchor: "left",
2100
+ position: {
2101
+ x: net_label.center.x - text_width / 4 + 0.025,
2102
+ y: net_label.center.y
2103
+ },
2104
+ schematic_component_id: "SYNTHETIC",
2105
+ schematic_text_id: "SYNTHETIC",
2106
+ text: net_label.text,
2107
+ type: "schematic_text"
2108
+ }
2109
+ }
2110
+ )
2111
+ ] });
2112
+ };
2113
+
2059
2114
  // src/schematic-components/SchematicElement.tsx
2060
- var import_jsx_runtime19 = require("react/jsx-runtime");
2115
+ var import_jsx_runtime21 = require("react/jsx-runtime");
2061
2116
  var SchematicElement = ({
2062
2117
  element,
2063
2118
  allElements
2064
2119
  }) => {
2065
2120
  if (element.type === "schematic_component") {
2066
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2121
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2067
2122
  SchematicComponent_default,
2068
2123
  {
2069
2124
  component: collectElementRefs(element, allElements)
@@ -2071,25 +2126,28 @@ var SchematicElement = ({
2071
2126
  );
2072
2127
  }
2073
2128
  if (element.type === "schematic_trace") {
2074
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(SchematicTrace_default, { trace: collectElementRefs(element, allElements) });
2129
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicTrace_default, { trace: collectElementRefs(element, allElements) });
2075
2130
  }
2076
2131
  if (element.type === "schematic_port") {
2077
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(SchematicPort_default, { port: collectElementRefs(element, allElements) });
2132
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicPort_default, { port: collectElementRefs(element, allElements) });
2078
2133
  }
2079
2134
  if (element.type === "schematic_box") {
2080
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(SchematicBox_default, { box: collectElementRefs(element, allElements) });
2135
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicBox_default, { box: collectElementRefs(element, allElements) });
2081
2136
  }
2082
2137
  if (element.type === "schematic_line") {
2083
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(SchematicLine_default, { line: collectElementRefs(element, allElements) });
2138
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicLine_default, { line: collectElementRefs(element, allElements) });
2084
2139
  }
2085
2140
  if (element.type === "schematic_path") {
2086
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(SchematicPath_default, { path: collectElementRefs(element, allElements) });
2141
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicPath_default, { path: collectElementRefs(element, allElements) });
2087
2142
  }
2088
2143
  if (element.type === "schematic_text") {
2089
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(SchematicText_default, { schematic_text: element });
2144
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicText_default, { schematic_text: element });
2145
+ }
2146
+ if (element.type === "schematic_net_label") {
2147
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicNetLabel, { net_label: element });
2090
2148
  }
2091
2149
  if (element.type === "source_error") {
2092
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(RenderError_default, { text: element.message });
2150
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(RenderError_default, { text: element.message });
2093
2151
  }
2094
2152
  return null;
2095
2153
  };
@@ -2099,20 +2157,20 @@ var import_use_mouse_matrix_transform = require("use-mouse-matrix-transform");
2099
2157
  var import_react_error_boundary = require("react-error-boundary");
2100
2158
 
2101
2159
  // src/schematic-components/TableViewer.tsx
2102
- var import_react5 = require("react");
2103
- var import_jsx_runtime20 = require("react/jsx-runtime");
2104
- var LazyTableViewer = (0, import_react5.lazy)(
2160
+ var import_react8 = require("react");
2161
+ var import_jsx_runtime22 = require("react/jsx-runtime");
2162
+ var LazyTableViewer = (0, import_react8.lazy)(
2105
2163
  () => import("@tscircuit/table-viewer").then((m) => ({
2106
2164
  default: m.SoupTableViewer
2107
2165
  }))
2108
2166
  );
2109
- var TableViewer = (params) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_react5.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { children: "Loading..." }), children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(LazyTableViewer, { ...params }) });
2167
+ var TableViewer = (params) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_react8.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { children: "Loading..." }), children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(LazyTableViewer, { ...params }) });
2110
2168
 
2111
2169
  // src/Schematic.tsx
2112
- var import_jsx_runtime21 = require("react/jsx-runtime");
2170
+ var import_jsx_runtime23 = require("react/jsx-runtime");
2113
2171
  var ErrorBoundary = import_react_error_boundary.ErrorBoundary;
2114
2172
  var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
2115
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { style: { color: "red" }, children: [
2173
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { style: { color: "red" }, children: [
2116
2174
  "error rendering ",
2117
2175
  elm.type,
2118
2176
  ": ",
@@ -2120,7 +2178,10 @@ var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
2120
2178
  ] });
2121
2179
  };
2122
2180
  var toMMSINeg = (v, z) => v >= 0 ? (0, import_react_supergrid.toMMSI)(v, z) : `-${(0, import_react_supergrid.toMMSI)(-v, z)}`;
2123
- var Schematic = ({
2181
+ var Schematic = (props) => {
2182
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ContextProviders, { children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(SchematicWithoutContext, { ...props }) });
2183
+ };
2184
+ var SchematicWithoutContext = ({
2124
2185
  children,
2125
2186
  elements: initialElements,
2126
2187
  soup: initialSoup,
@@ -2128,10 +2189,9 @@ var Schematic = ({
2128
2189
  showTable = false
2129
2190
  }) => {
2130
2191
  initialSoup = initialSoup ?? initialElements ?? [];
2131
- const [elements, setElements] = (0, import_react6.useState)(initialSoup ?? []);
2132
- const [project, setProject] = (0, import_react6.useState)(null);
2133
- const setCameraTransform = useRenderContext((s) => s.setCameraTransform);
2134
- const cameraTransform = useRenderContext((s) => s.camera_transform);
2192
+ const [elements, setElements] = (0, import_react9.useState)(initialSoup ?? []);
2193
+ const [project, setProject] = (0, import_react9.useState)(null);
2194
+ const { setCameraTransform, camera_transform: cameraTransform } = useGlobalStore();
2135
2195
  const [boundsRef, bounds] = useMeasure();
2136
2196
  const { ref, setTransform } = (0, import_use_mouse_matrix_transform.useMouseMatrixTransform)({
2137
2197
  onSetTransform: (transform2) => {
@@ -2139,7 +2199,7 @@ var Schematic = ({
2139
2199
  }
2140
2200
  // initialTransform: compose(scale(100, 100, 0, 0)),
2141
2201
  });
2142
- const setElementsAndCamera = (0, import_react6.useCallback)(
2202
+ const setElementsAndCamera = (0, import_react9.useCallback)(
2143
2203
  (elements2) => {
2144
2204
  const elmBounds = ref.current.getBoundingClientRect();
2145
2205
  const { center, width, height } = elements2.some(
@@ -2157,7 +2217,6 @@ var Schematic = ({
2157
2217
  setTransform(
2158
2218
  compose(
2159
2219
  translate((elmBounds.width ?? 0) / 2, (elmBounds.height ?? 0) / 2),
2160
- // translate(100, 0),
2161
2220
  scale(scaleFactor, -scaleFactor, 0, 0),
2162
2221
  translate(-center.x, -center.y)
2163
2222
  )
@@ -2165,7 +2224,7 @@ var Schematic = ({
2165
2224
  },
2166
2225
  [setElements, setTransform]
2167
2226
  );
2168
- (0, import_react6.useEffect)(() => {
2227
+ (0, import_react9.useEffect)(() => {
2169
2228
  if (initialSoup.length > 0) {
2170
2229
  setElementsAndCamera(initialSoup);
2171
2230
  return;
@@ -2178,8 +2237,8 @@ var Schematic = ({
2178
2237
  throw e;
2179
2238
  });
2180
2239
  }, [children]);
2181
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
2182
- /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
2240
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_jsx_runtime23.Fragment, { children: [
2241
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
2183
2242
  "div",
2184
2243
  {
2185
2244
  style: {
@@ -2197,7 +2256,7 @@ var Schematic = ({
2197
2256
  boundsRef(el);
2198
2257
  },
2199
2258
  children: [
2200
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2259
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2201
2260
  import_react_supergrid.SuperGrid,
2202
2261
  {
2203
2262
  stringifyCoord: (x, y, z) => {
@@ -2210,7 +2269,7 @@ var Schematic = ({
2210
2269
  transform: cameraTransform
2211
2270
  }
2212
2271
  ),
2213
- elements?.map((elm, i) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ErrorBoundary, { fallbackRender: fallbackRender(elm), children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2272
+ elements?.map((elm, i) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ErrorBoundary, { fallbackRender: fallbackRender(elm), children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2214
2273
  SchematicElement,
2215
2274
  {
2216
2275
  element: elm,
@@ -2221,12 +2280,13 @@ var Schematic = ({
2221
2280
  ]
2222
2281
  }
2223
2282
  ),
2224
- showTable !== false && elements && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(TableViewer, { elements })
2283
+ showTable !== false && elements && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(TableViewer, { elements })
2225
2284
  ] });
2226
2285
  };
2227
2286
  // Annotate the CommonJS export names for ESM import in node:
2228
2287
  0 && (module.exports = {
2229
- Schematic
2288
+ Schematic,
2289
+ SchematicWithoutContext
2230
2290
  });
2231
2291
  /*! Bundled license information:
2232
2292