@tscircuit/schematic-viewer 1.2.9 → 1.2.11

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 /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimpleDiode, { component: { source, schematic } });
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,86 @@ 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
- ] });
1923
+ var SimpleDiode = ({ component: { source, schematic } }) => {
1924
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1925
+ SVGPathComponent_default,
1926
+ {
1927
+ rotation: schematic.rotation,
1928
+ center: schematic.center,
1929
+ size: schematic.size,
1930
+ paths: [
1931
+ { stroke: "red", strokeWidth: 2, d: "M 0,0 H 21" },
1932
+ { stroke: "red", strokeWidth: 2, d: "M 49,0 H 59" },
1933
+ { stroke: "red", strokeWidth: 2, d: "M 49,0 L 21 14 V -14 Z" },
1934
+ { stroke: "red", strokeWidth: 2, d: "M 49,-14 V 14" }
1935
+ // For LEDs
1936
+ // {
1937
+ // stroke: "red",
1938
+ // strokeWidth: 2,
1939
+ // d: "M 35 -32 l 7 5.25 l 1.75 -9.625 z m 3.5 2.625 l -5.25 7",
1940
+ // },
1941
+ // {
1942
+ // stroke: "red",
1943
+ // strokeWidth: 2,
1944
+ // d: "M 52 -26 l 7 5.25 l 1.75 -9.625 z m 3.5 2.625 l -5.25 7",
1945
+ // },
1946
+ ]
1956
1947
  }
1948
+ );
1949
+ };
1950
+
1951
+ // src/schematic-components/ContextProviders.tsx
1952
+ var import_react6 = require("react");
1953
+ var import_react7 = require("react");
1954
+ var import_jsx_runtime16 = require("react/jsx-runtime");
1955
+ var StoreContext = (0, import_react7.createContext)(null);
1956
+ var ContextProviders = ({ children }) => {
1957
+ const store = (0, import_react6.useMemo)(() => createRenderContextStore(), []);
1958
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(StoreContext.Provider, { value: store, children });
1959
+ };
1960
+
1961
+ // src/Schematic.tsx
1962
+ var import_react_supergrid = require("react-supergrid");
1963
+ var import_builder3 = require("@tscircuit/builder");
1964
+ var import_react_fiber = __toESM(require("@tscircuit/react-fiber"));
1965
+
1966
+ // src/lib/utils/collect-element-refs.ts
1967
+ var collectElementRefs = (elm, allElms) => {
1968
+ const source_port = allElms.find(
1969
+ (e) => e.type === "source_port" && e.source_port_id === elm.source_port_id
1970
+ );
1971
+ const source_component_id = elm.source_component_id ?? source_port?.source_component_id;
1972
+ const source_component = allElms.find(
1973
+ (e) => e.type === "source_component" && e.source_component_id === source_component_id
1974
+ );
1975
+ if ([
1976
+ "schematic_component",
1977
+ "schematic_trace",
1978
+ "schematic_port",
1979
+ "schematic_box",
1980
+ "schematic_line",
1981
+ "schematic_path"
1982
+ ].includes(elm.type)) {
1983
+ const schematic_children = allElms.filter(
1984
+ (e) => "schematic_component_id" in e && e.schematic_component_id === elm.schematic_component_id
1985
+ );
1986
+ return {
1987
+ schematic_children,
1988
+ schematic: elm,
1989
+ source: source_component,
1990
+ source_component,
1991
+ source_port
1992
+ };
1957
1993
  }
1994
+ return null;
1958
1995
  };
1959
- var SchematicComponent_default = SchematicComponent;
1960
1996
 
1961
1997
  // src/schematic-components/SchematicBox.tsx
1962
- var import_jsx_runtime16 = require("react/jsx-runtime");
1998
+ var import_jsx_runtime17 = require("react/jsx-runtime");
1963
1999
  var SchematicBox = ({ box: { schematic } }) => {
1964
2000
  const { width: w, height: h } = schematic;
1965
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
2001
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1966
2002
  SVGPathComponent,
1967
2003
  {
1968
2004
  rotation: 0,
@@ -1982,7 +2018,7 @@ var SchematicBox_default = SchematicBox;
1982
2018
 
1983
2019
  // src/schematic-components/SchematicLine.tsx
1984
2020
  var import_svg_path_generator2 = __toESM(require_svg_path_generator2());
1985
- var import_jsx_runtime17 = require("react/jsx-runtime");
2021
+ var import_jsx_runtime18 = require("react/jsx-runtime");
1986
2022
  var SchematicLine = ({ line: { schematic } }) => {
1987
2023
  const { x1, x2, y1, y2 } = schematic;
1988
2024
  const dx = x2 - x1;
@@ -1996,7 +2032,7 @@ var SchematicLine = ({ line: { schematic } }) => {
1996
2032
  x: pathBounds.minX + pathBounds.width / 2,
1997
2033
  y: pathBounds.minY + pathBounds.height / 2
1998
2034
  };
1999
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
2035
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2000
2036
  SVGPathComponent,
2001
2037
  {
2002
2038
  rotation: 0,
@@ -2016,7 +2052,7 @@ var SchematicLine_default = SchematicLine;
2016
2052
 
2017
2053
  // src/schematic-components/SchematicPath.tsx
2018
2054
  var import_svg_path_generator3 = __toESM(require_svg_path_generator2());
2019
- var import_jsx_runtime18 = require("react/jsx-runtime");
2055
+ var import_jsx_runtime19 = require("react/jsx-runtime");
2020
2056
  var SchematicPath = (props) => {
2021
2057
  const { points, is_filled, is_closed, fill_color } = props.path.schematic;
2022
2058
  if (points.length === 0)
@@ -2037,7 +2073,7 @@ var SchematicPath = (props) => {
2037
2073
  x: pathBounds.minX + pathBounds.width / 2,
2038
2074
  y: pathBounds.minY + pathBounds.height / 2
2039
2075
  };
2040
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
2076
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2041
2077
  SVGPathComponent,
2042
2078
  {
2043
2079
  rotation: 0,
@@ -2057,15 +2093,15 @@ var SchematicPath = (props) => {
2057
2093
  var SchematicPath_default = SchematicPath;
2058
2094
 
2059
2095
  // src/schematic-components/SchematicNetLabel.tsx
2060
- var import_jsx_runtime19 = require("react/jsx-runtime");
2096
+ var import_jsx_runtime20 = require("react/jsx-runtime");
2061
2097
  var SchematicNetLabel = ({
2062
2098
  net_label
2063
2099
  }) => {
2064
2100
  console.log({ net_label });
2065
2101
  const text_width = net_label.text.length * 0.15;
2066
2102
  const path_width = 31 + net_label.text.length * 5;
2067
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
2068
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2103
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
2104
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2069
2105
  SVGPathComponent_default,
2070
2106
  {
2071
2107
  rotation: 0,
@@ -2083,7 +2119,7 @@ var SchematicNetLabel = ({
2083
2119
  ]
2084
2120
  }
2085
2121
  ),
2086
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2122
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2087
2123
  SchematicText_default,
2088
2124
  {
2089
2125
  schematic_text: {
@@ -2103,13 +2139,13 @@ var SchematicNetLabel = ({
2103
2139
  };
2104
2140
 
2105
2141
  // src/schematic-components/SchematicElement.tsx
2106
- var import_jsx_runtime20 = require("react/jsx-runtime");
2142
+ var import_jsx_runtime21 = require("react/jsx-runtime");
2107
2143
  var SchematicElement = ({
2108
2144
  element,
2109
2145
  allElements
2110
2146
  }) => {
2111
2147
  if (element.type === "schematic_component") {
2112
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2148
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2113
2149
  SchematicComponent_default,
2114
2150
  {
2115
2151
  component: collectElementRefs(element, allElements)
@@ -2117,28 +2153,28 @@ var SchematicElement = ({
2117
2153
  );
2118
2154
  }
2119
2155
  if (element.type === "schematic_trace") {
2120
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SchematicTrace_default, { trace: collectElementRefs(element, allElements) });
2156
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicTrace_default, { trace: collectElementRefs(element, allElements) });
2121
2157
  }
2122
2158
  if (element.type === "schematic_port") {
2123
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SchematicPort_default, { port: collectElementRefs(element, allElements) });
2159
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicPort_default, { port: collectElementRefs(element, allElements) });
2124
2160
  }
2125
2161
  if (element.type === "schematic_box") {
2126
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SchematicBox_default, { box: collectElementRefs(element, allElements) });
2162
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicBox_default, { box: collectElementRefs(element, allElements) });
2127
2163
  }
2128
2164
  if (element.type === "schematic_line") {
2129
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SchematicLine_default, { line: collectElementRefs(element, allElements) });
2165
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicLine_default, { line: collectElementRefs(element, allElements) });
2130
2166
  }
2131
2167
  if (element.type === "schematic_path") {
2132
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SchematicPath_default, { path: collectElementRefs(element, allElements) });
2168
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicPath_default, { path: collectElementRefs(element, allElements) });
2133
2169
  }
2134
2170
  if (element.type === "schematic_text") {
2135
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SchematicText_default, { schematic_text: element });
2171
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicText_default, { schematic_text: element });
2136
2172
  }
2137
2173
  if (element.type === "schematic_net_label") {
2138
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SchematicNetLabel, { net_label: element });
2174
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicNetLabel, { net_label: element });
2139
2175
  }
2140
2176
  if (element.type === "source_error") {
2141
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(RenderError_default, { text: element.message });
2177
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(RenderError_default, { text: element.message });
2142
2178
  }
2143
2179
  return null;
2144
2180
  };
@@ -2148,20 +2184,20 @@ var import_use_mouse_matrix_transform = require("use-mouse-matrix-transform");
2148
2184
  var import_react_error_boundary = require("react-error-boundary");
2149
2185
 
2150
2186
  // src/schematic-components/TableViewer.tsx
2151
- var import_react5 = require("react");
2152
- var import_jsx_runtime21 = require("react/jsx-runtime");
2153
- var LazyTableViewer = (0, import_react5.lazy)(
2187
+ var import_react8 = require("react");
2188
+ var import_jsx_runtime22 = require("react/jsx-runtime");
2189
+ var LazyTableViewer = (0, import_react8.lazy)(
2154
2190
  () => import("@tscircuit/table-viewer").then((m) => ({
2155
2191
  default: m.SoupTableViewer
2156
2192
  }))
2157
2193
  );
2158
- var TableViewer = (params) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react5.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { children: "Loading..." }), children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(LazyTableViewer, { ...params }) });
2194
+ 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 }) });
2159
2195
 
2160
2196
  // src/Schematic.tsx
2161
- var import_jsx_runtime22 = require("react/jsx-runtime");
2197
+ var import_jsx_runtime23 = require("react/jsx-runtime");
2162
2198
  var ErrorBoundary = import_react_error_boundary.ErrorBoundary;
2163
2199
  var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
2164
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { style: { color: "red" }, children: [
2200
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { style: { color: "red" }, children: [
2165
2201
  "error rendering ",
2166
2202
  elm.type,
2167
2203
  ": ",
@@ -2169,7 +2205,10 @@ var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
2169
2205
  ] });
2170
2206
  };
2171
2207
  var toMMSINeg = (v, z) => v >= 0 ? (0, import_react_supergrid.toMMSI)(v, z) : `-${(0, import_react_supergrid.toMMSI)(-v, z)}`;
2172
- var Schematic = ({
2208
+ var Schematic = (props) => {
2209
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ContextProviders, { children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(SchematicWithoutContext, { ...props }) });
2210
+ };
2211
+ var SchematicWithoutContext = ({
2173
2212
  children,
2174
2213
  elements: initialElements,
2175
2214
  soup: initialSoup,
@@ -2177,10 +2216,9 @@ var Schematic = ({
2177
2216
  showTable = false
2178
2217
  }) => {
2179
2218
  initialSoup = initialSoup ?? initialElements ?? [];
2180
- const [elements, setElements] = (0, import_react6.useState)(initialSoup ?? []);
2181
- const [project, setProject] = (0, import_react6.useState)(null);
2182
- const setCameraTransform = useRenderContext((s) => s.setCameraTransform);
2183
- const cameraTransform = useRenderContext((s) => s.camera_transform);
2219
+ const [elements, setElements] = (0, import_react9.useState)(initialSoup ?? []);
2220
+ const [project, setProject] = (0, import_react9.useState)(null);
2221
+ const { setCameraTransform, camera_transform: cameraTransform } = useGlobalStore();
2184
2222
  const [boundsRef, bounds] = useMeasure();
2185
2223
  const { ref, setTransform } = (0, import_use_mouse_matrix_transform.useMouseMatrixTransform)({
2186
2224
  onSetTransform: (transform2) => {
@@ -2188,7 +2226,7 @@ var Schematic = ({
2188
2226
  }
2189
2227
  // initialTransform: compose(scale(100, 100, 0, 0)),
2190
2228
  });
2191
- const setElementsAndCamera = (0, import_react6.useCallback)(
2229
+ const setElementsAndCamera = (0, import_react9.useCallback)(
2192
2230
  (elements2) => {
2193
2231
  const elmBounds = ref.current.getBoundingClientRect();
2194
2232
  const { center, width, height } = elements2.some(
@@ -2206,7 +2244,6 @@ var Schematic = ({
2206
2244
  setTransform(
2207
2245
  compose(
2208
2246
  translate((elmBounds.width ?? 0) / 2, (elmBounds.height ?? 0) / 2),
2209
- // translate(100, 0),
2210
2247
  scale(scaleFactor, -scaleFactor, 0, 0),
2211
2248
  translate(-center.x, -center.y)
2212
2249
  )
@@ -2214,7 +2251,7 @@ var Schematic = ({
2214
2251
  },
2215
2252
  [setElements, setTransform]
2216
2253
  );
2217
- (0, import_react6.useEffect)(() => {
2254
+ (0, import_react9.useEffect)(() => {
2218
2255
  if (initialSoup.length > 0) {
2219
2256
  setElementsAndCamera(initialSoup);
2220
2257
  return;
@@ -2227,8 +2264,8 @@ var Schematic = ({
2227
2264
  throw e;
2228
2265
  });
2229
2266
  }, [children]);
2230
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
2231
- /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
2267
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_jsx_runtime23.Fragment, { children: [
2268
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
2232
2269
  "div",
2233
2270
  {
2234
2271
  style: {
@@ -2246,7 +2283,7 @@ var Schematic = ({
2246
2283
  boundsRef(el);
2247
2284
  },
2248
2285
  children: [
2249
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2286
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2250
2287
  import_react_supergrid.SuperGrid,
2251
2288
  {
2252
2289
  stringifyCoord: (x, y, z) => {
@@ -2259,7 +2296,7 @@ var Schematic = ({
2259
2296
  transform: cameraTransform
2260
2297
  }
2261
2298
  ),
2262
- elements?.map((elm, i) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ErrorBoundary, { fallbackRender: fallbackRender(elm), children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2299
+ elements?.map((elm, i) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ErrorBoundary, { fallbackRender: fallbackRender(elm), children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2263
2300
  SchematicElement,
2264
2301
  {
2265
2302
  element: elm,
@@ -2270,12 +2307,13 @@ var Schematic = ({
2270
2307
  ]
2271
2308
  }
2272
2309
  ),
2273
- showTable !== false && elements && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(TableViewer, { elements })
2310
+ showTable !== false && elements && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(TableViewer, { elements })
2274
2311
  ] });
2275
2312
  };
2276
2313
  // Annotate the CommonJS export names for ESM import in node:
2277
2314
  0 && (module.exports = {
2278
- Schematic
2315
+ Schematic,
2316
+ SchematicWithoutContext
2279
2317
  });
2280
2318
  /*! Bundled license information:
2281
2319