@tscircuit/schematic-viewer 1.1.9 → 1.1.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
@@ -949,7 +949,8 @@ var collectElementRefs = (elm, allElms) => {
949
949
  "schematic_trace",
950
950
  "schematic_port",
951
951
  "schematic_box",
952
- "schematic_line"
952
+ "schematic_line",
953
+ "schematic_path"
953
954
  ].includes(elm.type)) {
954
955
  const schematic_children = allElms.filter(
955
956
  (e) => "schematic_component_id" in e && e.schematic_component_id === elm.schematic_component_id
@@ -1278,7 +1279,7 @@ var SVGPathComponent = ({ size, center, rotation, paths }) => {
1278
1279
  height: absoluteSize.height,
1279
1280
  viewBox: `${pathBounds.minX} ${pathBounds.minY} ${pathBounds.width} ${pathBounds.height}`,
1280
1281
  children: paths.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
1281
- fill: "none",
1282
+ fill: p.fill ?? "none",
1282
1283
  strokeLinecap: "round",
1283
1284
  strokeWidth: 2 * (p.strokeWidth || 1),
1284
1285
  stroke: p.stroke || "red",
@@ -1711,6 +1712,8 @@ var import_jsx_runtime13 = require("react/jsx-runtime");
1711
1712
  var import_jsx_runtime14 = require("react/jsx-runtime");
1712
1713
  var SchematicComponent = ({ component }) => {
1713
1714
  const { source, schematic } = component;
1715
+ if (!source.ftype)
1716
+ return null;
1714
1717
  switch (source.ftype) {
1715
1718
  case "simple_resistor": {
1716
1719
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(SimpleResistor, {
@@ -1809,44 +1812,89 @@ var SchematicLine = ({ line: { schematic } }) => {
1809
1812
  };
1810
1813
  var SchematicLine_default = SchematicLine;
1811
1814
 
1812
- // src/schematic-components/SchematicElement.tsx
1815
+ // src/schematic-components/SchematicPath.tsx
1816
+ var import_svg_path_generator3 = __toESM(require_svg_path_generator2());
1813
1817
  var import_jsx_runtime17 = require("react/jsx-runtime");
1818
+ var SchematicPath = (props) => {
1819
+ console.log("SchematicPath", props);
1820
+ const { points, is_filled, is_closed, fill_color } = props.path.schematic;
1821
+ if (points.length === 0)
1822
+ return null;
1823
+ const path = (0, import_svg_path_generator3.default)();
1824
+ path.moveTo(points[0].x, points[0].y);
1825
+ for (const point of points.slice(1)) {
1826
+ path.lineTo(point.x, point.y);
1827
+ }
1828
+ if (is_closed) {
1829
+ path.closePath();
1830
+ }
1831
+ const d = path.toString();
1832
+ const pathBounds = get_svg_path_bounds_default(d);
1833
+ pathBounds.height = Math.max(pathBounds.height, 1);
1834
+ pathBounds.width = Math.max(pathBounds.width, 1);
1835
+ const center = {
1836
+ x: pathBounds.minX + pathBounds.width / 2,
1837
+ y: pathBounds.minY + pathBounds.height / 2
1838
+ };
1839
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SVGPathComponent, {
1840
+ rotation: 0,
1841
+ center,
1842
+ size: pathBounds,
1843
+ paths: [
1844
+ {
1845
+ stroke: is_filled ? "none" : fill_color ?? "red",
1846
+ strokeWidth: 0.02,
1847
+ fill: is_filled ? fill_color ?? "red" : void 0,
1848
+ d
1849
+ }
1850
+ ]
1851
+ });
1852
+ };
1853
+ var SchematicPath_default = SchematicPath;
1854
+
1855
+ // src/schematic-components/SchematicElement.tsx
1856
+ var import_jsx_runtime18 = require("react/jsx-runtime");
1814
1857
  var SchematicElement = ({
1815
1858
  element,
1816
1859
  allElements
1817
1860
  }) => {
1818
1861
  if (element.type === "schematic_component") {
1819
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicComponent_default, {
1862
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(SchematicComponent_default, {
1820
1863
  component: collectElementRefs(element, allElements)
1821
1864
  });
1822
1865
  }
1823
1866
  if (element.type === "schematic_trace") {
1824
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicTrace_default, {
1867
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(SchematicTrace_default, {
1825
1868
  trace: collectElementRefs(element, allElements)
1826
1869
  });
1827
1870
  }
1828
1871
  if (element.type === "schematic_port") {
1829
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicPort_default, {
1872
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(SchematicPort_default, {
1830
1873
  port: collectElementRefs(element, allElements)
1831
1874
  });
1832
1875
  }
1833
1876
  if (element.type === "schematic_box") {
1834
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicBox_default, {
1877
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(SchematicBox_default, {
1835
1878
  box: collectElementRefs(element, allElements)
1836
1879
  });
1837
1880
  }
1838
1881
  if (element.type === "schematic_line") {
1839
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicLine_default, {
1882
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(SchematicLine_default, {
1840
1883
  line: collectElementRefs(element, allElements)
1841
1884
  });
1842
1885
  }
1886
+ if (element.type === "schematic_path") {
1887
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(SchematicPath_default, {
1888
+ path: collectElementRefs(element, allElements)
1889
+ });
1890
+ }
1843
1891
  if (element.type === "schematic_text") {
1844
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicText_default, {
1892
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(SchematicText_default, {
1845
1893
  schematic_text: element
1846
1894
  });
1847
1895
  }
1848
1896
  if (element.type === "source_error") {
1849
- return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(RenderError_default, {
1897
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(RenderError_default, {
1850
1898
  text: element.message
1851
1899
  });
1852
1900
  }
@@ -1859,25 +1907,25 @@ var import_react_error_boundary = require("react-error-boundary");
1859
1907
 
1860
1908
  // src/schematic-components/TableViewer.tsx
1861
1909
  var import_react4 = require("react");
1862
- var import_jsx_runtime18 = require("react/jsx-runtime");
1910
+ var import_jsx_runtime19 = require("react/jsx-runtime");
1863
1911
  var LazyTableViewer = (0, import_react4.lazy)(
1864
1912
  () => import("@tscircuit/table-viewer").then((m) => ({
1865
1913
  default: m.SoupTableViewer
1866
1914
  }))
1867
1915
  );
1868
- var TableViewer = (params) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react4.Suspense, {
1869
- fallback: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", {
1916
+ var TableViewer = (params) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_react4.Suspense, {
1917
+ fallback: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", {
1870
1918
  children: "Loading..."
1871
1919
  }),
1872
- children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(LazyTableViewer, {
1920
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(LazyTableViewer, {
1873
1921
  ...params
1874
1922
  })
1875
1923
  });
1876
1924
 
1877
1925
  // src/Schematic.tsx
1878
- var import_jsx_runtime19 = require("react/jsx-runtime");
1926
+ var import_jsx_runtime20 = require("react/jsx-runtime");
1879
1927
  var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
1880
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", {
1928
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", {
1881
1929
  style: { color: "red" },
1882
1930
  children: [
1883
1931
  "error rendering ",
@@ -1944,9 +1992,9 @@ var Schematic = ({
1944
1992
  throw e;
1945
1993
  });
1946
1994
  }, [children]);
1947
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, {
1995
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, {
1948
1996
  children: [
1949
- /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", {
1997
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", {
1950
1998
  style: {
1951
1999
  width: "100%",
1952
2000
  backgroundColor: "rgba(255,255,255,0)",
@@ -1961,7 +2009,7 @@ var Schematic = ({
1961
2009
  boundsRef(el);
1962
2010
  },
1963
2011
  children: [
1964
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_react_supergrid.SuperGrid, {
2012
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_react_supergrid.SuperGrid, {
1965
2013
  stringifyCoord: (x, y, z) => {
1966
2014
  if (z === 0)
1967
2015
  return "";
@@ -1971,16 +2019,16 @@ var Schematic = ({
1971
2019
  height: bounds.height,
1972
2020
  transform: cameraTransform
1973
2021
  }),
1974
- elements == null ? void 0 : elements.map((elm, i) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_react_error_boundary.ErrorBoundary, {
2022
+ elements == null ? void 0 : elements.map((elm, i) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_react_error_boundary.ErrorBoundary, {
1975
2023
  fallbackRender: fallbackRender(elm),
1976
- children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(SchematicElement, {
2024
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SchematicElement, {
1977
2025
  element: elm,
1978
2026
  allElements: elements
1979
2027
  }, JSON.stringify(elm))
1980
2028
  }, i))
1981
2029
  ]
1982
2030
  }),
1983
- showTable !== false && elements && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(TableViewer, {
2031
+ showTable !== false && elements && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(TableViewer, {
1984
2032
  elements
1985
2033
  })
1986
2034
  ]