@tscircuit/schematic-viewer 1.2.14 → 1.3.0

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.
@@ -0,0 +1,30 @@
1
+ name: "Chromatic"
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - main
10
+
11
+ jobs:
12
+ chromatic:
13
+ name: Run Chromatic
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - name: Checkout code
17
+ uses: actions/checkout@v4
18
+ with:
19
+ fetch-depth: 0
20
+ - uses: actions/setup-node@v4
21
+ with:
22
+ node-version: 20
23
+ - name: Install dependencies
24
+ # ⚠️ See your package manager's documentation for the correct command to install dependencies in a CI environment.
25
+ run: npm ci
26
+ - name: Run Chromatic
27
+ uses: chromaui/action@latest
28
+ with:
29
+ # ⚠️ Make sure to configure a `CHROMATIC_PROJECT_TOKEN` repository secret
30
+ projectToken: chpt_d88a6beb0734bbe
@@ -0,0 +1,26 @@
1
+ # Created using @tscircuit/plop (npm install -g @tscircuit/plop)
2
+ name: Build
3
+
4
+ on:
5
+ push:
6
+ branches: [main]
7
+ pull_request:
8
+ branches: [main]
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+
17
+ - name: Use Node.js
18
+ uses: actions/setup-node@v3
19
+ with:
20
+ node-version: "20"
21
+
22
+ - name: Install dependencies
23
+ run: npm ci
24
+
25
+ - name: Run build
26
+ run: npm run build
@@ -0,0 +1,26 @@
1
+ # Created using @tscircuit/plop (npm install -g @tscircuit/plop)
2
+ name: Type Check
3
+
4
+ on:
5
+ push:
6
+ branches: [main]
7
+ pull_request:
8
+ branches: [main]
9
+
10
+ jobs:
11
+ type-check:
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v3
16
+
17
+ - name: Use Node.js
18
+ uses: actions/setup-node@v3
19
+ with:
20
+ node-version: "20"
21
+
22
+ - name: Install dependencies
23
+ run: npm ci
24
+
25
+ - name: Run typecheck
26
+ run: npx tsc --noEmit
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { AnySoupElement } from '@tscircuit/soup';
2
+ import { AnyCircuitElement } from 'circuit-json';
3
3
 
4
4
  interface SchematicProps {
5
5
  children?: any;
6
6
  /** @deprecated use soup */
7
7
  elements?: any;
8
- soup?: AnySoupElement[];
8
+ soup?: AnyCircuitElement[];
9
9
  style?: any;
10
10
  showTable?: boolean;
11
- _soupPostProcessor?: (soup: AnySoupElement[]) => AnySoupElement[];
11
+ _soupPostProcessor?: (soup: AnyCircuitElement[]) => AnyCircuitElement[];
12
12
  }
13
13
  declare const Schematic: (props: SchematicProps) => react_jsx_runtime.JSX.Element;
14
14
  declare const SchematicWithoutContext: ({ children, elements: initialElements, soup: initialSoup, style, showTable, _soupPostProcessor, }: SchematicProps) => react_jsx_runtime.JSX.Element;
package/dist/index.js CHANGED
@@ -939,7 +939,8 @@ __export(src_exports, {
939
939
  module.exports = __toCommonJS(src_exports);
940
940
 
941
941
  // src/Schematic.tsx
942
- var import_react9 = require("react");
942
+ var import_builder3 = require("@tscircuit/builder");
943
+ var import_react_fiber = __toESM(require("@tscircuit/react-fiber"));
943
944
 
944
945
  // node_modules/zustand/esm/vanilla.mjs
945
946
  var import_meta = {};
@@ -1221,15 +1222,7 @@ peg$SyntaxError.buildMessage = function(expected, found) {
1221
1222
  };
1222
1223
 
1223
1224
  // src/lib/render-context/index.ts
1224
- var import_react2 = require("react");
1225
- var createRenderContextStore = () => createStore((set) => ({
1226
- camera_transform: compose(scale(100, 100, 0, 0)),
1227
- setCameraTransform: (transform2) => set({ camera_transform: transform2 })
1228
- }));
1229
- var useGlobalStore = (s) => {
1230
- const store = (0, import_react2.useContext)(StoreContext);
1231
- return useStore(store, s);
1232
- };
1225
+ var import_react7 = require("react");
1233
1226
 
1234
1227
  // src/lib/utils/get-svg-path-bounds.ts
1235
1228
  var import_svg_path_bounds = __toESM(require_svg_path_bounds());
@@ -1249,7 +1242,7 @@ function getSVGPathBounds(ds) {
1249
1242
  var get_svg_path_bounds_default = getSVGPathBounds;
1250
1243
 
1251
1244
  // src/schematic-components/SVGPathComponent.tsx
1252
- var import_react3 = require("react");
1245
+ var import_react2 = require("react");
1253
1246
  var import_jsx_runtime = require("react/jsx-runtime");
1254
1247
  var SVGPathComponent = ({
1255
1248
  size,
@@ -1279,7 +1272,7 @@ var SVGPathComponent = ({
1279
1272
  width: innerSize.width + padding.x * 2,
1280
1273
  height: innerSize.height + padding.y * 2
1281
1274
  };
1282
- const [hovering, setHovering] = (0, import_react3.useState)(false);
1275
+ const [hovering, setHovering] = (0, import_react2.useState)(false);
1283
1276
  const svgLeft = absoluteCenter.x - fullSize.width / 2;
1284
1277
  const svgTop = absoluteCenter.y - fullSize.height / 2;
1285
1278
  const preferredRatio = pathBounds.width === 0 ? innerSize.height / pathBounds.height : innerSize.width / pathBounds.width;
@@ -1413,7 +1406,7 @@ var SimpleCapacitor = ({
1413
1406
  };
1414
1407
 
1415
1408
  // src/lib/hooks/use-maybe-promise.ts
1416
- var import_react4 = require("react");
1409
+ var import_react3 = require("react");
1417
1410
 
1418
1411
  // src/schematic-components/ProjectComponent.tsx
1419
1412
  var import_builder = require("@tscircuit/builder");
@@ -1511,7 +1504,7 @@ var SchematicPort = ({
1511
1504
  var SchematicPort_default = SchematicPort;
1512
1505
 
1513
1506
  // node_modules/react-use-measure/dist/web.js
1514
- var import_react5 = require("react");
1507
+ var import_react4 = require("react");
1515
1508
  var import_debounce = __toESM(require_debounce());
1516
1509
  function useMeasure(_temp) {
1517
1510
  let {
@@ -1529,7 +1522,7 @@ function useMeasure(_temp) {
1529
1522
  if (!ResizeObserver) {
1530
1523
  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");
1531
1524
  }
1532
- const [bounds, set] = (0, import_react5.useState)({
1525
+ const [bounds, set] = (0, import_react4.useState)({
1533
1526
  left: 0,
1534
1527
  top: 0,
1535
1528
  width: 0,
@@ -1539,7 +1532,7 @@ function useMeasure(_temp) {
1539
1532
  x: 0,
1540
1533
  y: 0
1541
1534
  });
1542
- const state = (0, import_react5.useRef)({
1535
+ const state = (0, import_react4.useRef)({
1543
1536
  element: null,
1544
1537
  scrollContainers: null,
1545
1538
  resizeObserver: null,
@@ -1547,12 +1540,12 @@ function useMeasure(_temp) {
1547
1540
  });
1548
1541
  const scrollDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.scroll : null;
1549
1542
  const resizeDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.resize : null;
1550
- const mounted = (0, import_react5.useRef)(false);
1551
- (0, import_react5.useEffect)(() => {
1543
+ const mounted = (0, import_react4.useRef)(false);
1544
+ (0, import_react4.useEffect)(() => {
1552
1545
  mounted.current = true;
1553
1546
  return () => void (mounted.current = false);
1554
1547
  });
1555
- const [forceRefresh, resizeChange, scrollChange] = (0, import_react5.useMemo)(() => {
1548
+ const [forceRefresh, resizeChange, scrollChange] = (0, import_react4.useMemo)(() => {
1556
1549
  const callback = () => {
1557
1550
  if (!state.current.element)
1558
1551
  return;
@@ -1618,22 +1611,22 @@ function useMeasure(_temp) {
1618
1611
  };
1619
1612
  useOnWindowScroll(scrollChange, Boolean(scroll));
1620
1613
  useOnWindowResize(resizeChange);
1621
- (0, import_react5.useEffect)(() => {
1614
+ (0, import_react4.useEffect)(() => {
1622
1615
  removeListeners();
1623
1616
  addListeners();
1624
1617
  }, [scroll, scrollChange, resizeChange]);
1625
- (0, import_react5.useEffect)(() => removeListeners, []);
1618
+ (0, import_react4.useEffect)(() => removeListeners, []);
1626
1619
  return [ref, bounds, forceRefresh];
1627
1620
  }
1628
1621
  function useOnWindowResize(onWindowResize) {
1629
- (0, import_react5.useEffect)(() => {
1622
+ (0, import_react4.useEffect)(() => {
1630
1623
  const cb = onWindowResize;
1631
1624
  window.addEventListener("resize", cb);
1632
1625
  return () => void window.removeEventListener("resize", cb);
1633
1626
  }, [onWindowResize]);
1634
1627
  }
1635
1628
  function useOnWindowScroll(onScroll, enabled) {
1636
- (0, import_react5.useEffect)(() => {
1629
+ (0, import_react4.useEffect)(() => {
1637
1630
  if (enabled) {
1638
1631
  const cb = onScroll;
1639
1632
  window.addEventListener("scroll", cb, {
@@ -1809,11 +1802,13 @@ var SchematicTrace_default = SchematicTrace;
1809
1802
  var import_builder2 = require("@tscircuit/builder");
1810
1803
  var import_jsx_runtime11 = require("react/jsx-runtime");
1811
1804
  var SchematicBug = ({ component: { source, schematic } }) => {
1805
+ const location = schematic.center;
1812
1806
  const port_arrangement = {
1813
1807
  top_size: 0,
1814
1808
  bottom_size: 0,
1815
1809
  ...schematic.port_arrangement
1816
1810
  };
1811
+ const manufacturerPartNumber = source.manufacturerPartNumber;
1817
1812
  let bugw = schematic.size.width;
1818
1813
  let bugh = schematic.size.height;
1819
1814
  const { total_ports, width, height } = (0, import_builder2.getPortArrangementSize)(port_arrangement);
@@ -1847,15 +1842,33 @@ var SchematicBug = ({ component: { source, schematic } }) => {
1847
1842
  x: schematic.center.x + (actualSize.minX + actualSize.maxX) / 2,
1848
1843
  y: schematic.center.y + (actualSize.minY + actualSize.maxY) / 2
1849
1844
  };
1850
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1851
- SVGPathComponent_default,
1852
- {
1853
- rotation: schematic.rotation,
1854
- center: actualCenter,
1855
- size: actualSize,
1856
- paths
1857
- }
1858
- );
1845
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
1846
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1847
+ SVGPathComponent_default,
1848
+ {
1849
+ rotation: schematic.rotation,
1850
+ center: actualCenter,
1851
+ size: actualSize,
1852
+ paths
1853
+ }
1854
+ ),
1855
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1856
+ SchematicText_default,
1857
+ {
1858
+ schematic_text: {
1859
+ anchor: "bottom",
1860
+ position: {
1861
+ x: location.x + actualSize.minX / 1.5,
1862
+ y: location.y + actualSize.minY
1863
+ },
1864
+ schematic_component_id: "SYNTHETIC",
1865
+ schematic_text_id: "SYNTHETIC",
1866
+ text: manufacturerPartNumber,
1867
+ type: "schematic_text"
1868
+ }
1869
+ }
1870
+ )
1871
+ ] });
1859
1872
  };
1860
1873
 
1861
1874
  // src/schematic-components/SimplePowerSource.tsx
@@ -1970,19 +1983,29 @@ var SimpleDiode = ({ component: { source, schematic } }) => {
1970
1983
  };
1971
1984
 
1972
1985
  // src/schematic-components/ContextProviders.tsx
1986
+ var import_react5 = require("react");
1973
1987
  var import_react6 = require("react");
1974
- var import_react7 = require("react");
1975
1988
  var import_jsx_runtime16 = require("react/jsx-runtime");
1976
- var StoreContext = (0, import_react7.createContext)(null);
1989
+ var StoreContext = (0, import_react6.createContext)(null);
1977
1990
  var ContextProviders = ({ children }) => {
1978
- const store = (0, import_react6.useMemo)(() => createRenderContextStore(), []);
1991
+ const store = (0, import_react5.useMemo)(() => createRenderContextStore(), []);
1979
1992
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(StoreContext.Provider, { value: store, children });
1980
1993
  };
1981
1994
 
1995
+ // src/lib/render-context/index.ts
1996
+ var createRenderContextStore = () => createStore((set) => ({
1997
+ camera_transform: compose(scale(100, 100, 0, 0)),
1998
+ setCameraTransform: (transform2) => set({ camera_transform: transform2 })
1999
+ }));
2000
+ var useGlobalStore = (s) => {
2001
+ const store = (0, import_react7.useContext)(StoreContext);
2002
+ return useStore(store, s);
2003
+ };
2004
+
1982
2005
  // src/Schematic.tsx
2006
+ var import_react9 = require("react");
2007
+ var import_react_error_boundary = require("react-error-boundary");
1983
2008
  var import_react_supergrid = require("react-supergrid");
1984
- var import_builder3 = require("@tscircuit/builder");
1985
- var import_react_fiber = __toESM(require("@tscircuit/react-fiber"));
1986
2009
 
1987
2010
  // src/lib/utils/collect-element-refs.ts
1988
2011
  var collectElementRefs = (elm, allElms) => {
@@ -2071,48 +2094,6 @@ var SchematicLine = ({ line: { schematic } }) => {
2071
2094
  };
2072
2095
  var SchematicLine_default = SchematicLine;
2073
2096
 
2074
- // src/schematic-components/SchematicPath.tsx
2075
- var import_svg_path_generator3 = __toESM(require_svg_path_generator2());
2076
- var import_jsx_runtime19 = require("react/jsx-runtime");
2077
- var SchematicPath = (props) => {
2078
- const { points, is_filled, is_closed, fill_color } = props.path.schematic;
2079
- if (points.length === 0)
2080
- return null;
2081
- const path = (0, import_svg_path_generator3.default)();
2082
- path.moveTo(points[0].x, points[0].y);
2083
- for (const point of points.slice(1)) {
2084
- path.lineTo(point.x, point.y);
2085
- }
2086
- if (is_closed) {
2087
- path.closePath();
2088
- }
2089
- const d = path.toString();
2090
- const pathBounds = get_svg_path_bounds_default(d);
2091
- pathBounds.height = Math.max(pathBounds.height, 1);
2092
- pathBounds.width = Math.max(pathBounds.width, 1);
2093
- const center = {
2094
- x: pathBounds.minX + pathBounds.width / 2,
2095
- y: pathBounds.minY + pathBounds.height / 2
2096
- };
2097
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2098
- SVGPathComponent,
2099
- {
2100
- rotation: 0,
2101
- center,
2102
- size: pathBounds,
2103
- paths: [
2104
- {
2105
- stroke: is_filled ? "none" : fill_color ?? "red",
2106
- strokeWidth: 0.02,
2107
- fill: is_filled ? fill_color ?? "red" : void 0,
2108
- d
2109
- }
2110
- ]
2111
- }
2112
- );
2113
- };
2114
- var SchematicPath_default = SchematicPath;
2115
-
2116
2097
  // src/lib/utils/get-rotation-from-anchor-side.ts
2117
2098
  var getRotationFromAnchorSide = (anchor_side) => {
2118
2099
  if (anchor_side === "left")
@@ -2140,7 +2121,7 @@ var getVecFromAnchorSide = (anchor_side) => {
2140
2121
  };
2141
2122
 
2142
2123
  // src/schematic-components/SchematicNetLabel.tsx
2143
- var import_jsx_runtime20 = require("react/jsx-runtime");
2124
+ var import_jsx_runtime19 = require("react/jsx-runtime");
2144
2125
  var SchematicNetLabel = ({
2145
2126
  net_label
2146
2127
  }) => {
@@ -2152,8 +2133,8 @@ var SchematicNetLabel = ({
2152
2133
  const anchor_dist = is_vertical ? 0.04 : text_width / 4;
2153
2134
  anchor_vec.x *= anchor_dist;
2154
2135
  anchor_vec.y *= anchor_dist;
2155
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
2156
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2136
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
2137
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2157
2138
  SVGPathComponent_default,
2158
2139
  {
2159
2140
  rotation: getRotationFromAnchorSide(anchor_side),
@@ -2172,7 +2153,7 @@ var SchematicNetLabel = ({
2172
2153
  ]
2173
2154
  }
2174
2155
  ),
2175
- /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2156
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
2176
2157
  SchematicText_default,
2177
2158
  {
2178
2159
  schematic_text: {
@@ -2191,6 +2172,48 @@ var SchematicNetLabel = ({
2191
2172
  ] });
2192
2173
  };
2193
2174
 
2175
+ // src/schematic-components/SchematicPath.tsx
2176
+ var import_svg_path_generator3 = __toESM(require_svg_path_generator2());
2177
+ var import_jsx_runtime20 = require("react/jsx-runtime");
2178
+ var SchematicPath = (props) => {
2179
+ const { points, is_filled, is_closed, fill_color } = props.path.schematic;
2180
+ if (points.length === 0)
2181
+ return null;
2182
+ const path = (0, import_svg_path_generator3.default)();
2183
+ path.moveTo(points[0].x, points[0].y);
2184
+ for (const point of points.slice(1)) {
2185
+ path.lineTo(point.x, point.y);
2186
+ }
2187
+ if (is_closed) {
2188
+ path.closePath();
2189
+ }
2190
+ const d = path.toString();
2191
+ const pathBounds = get_svg_path_bounds_default(d);
2192
+ pathBounds.height = Math.max(pathBounds.height, 1);
2193
+ pathBounds.width = Math.max(pathBounds.width, 1);
2194
+ const center = {
2195
+ x: pathBounds.minX + pathBounds.width / 2,
2196
+ y: pathBounds.minY + pathBounds.height / 2
2197
+ };
2198
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2199
+ SVGPathComponent,
2200
+ {
2201
+ rotation: 0,
2202
+ center,
2203
+ size: pathBounds,
2204
+ paths: [
2205
+ {
2206
+ stroke: is_filled ? "none" : fill_color ?? "red",
2207
+ strokeWidth: 0.02,
2208
+ fill: is_filled ? fill_color ?? "red" : void 0,
2209
+ d
2210
+ }
2211
+ ]
2212
+ }
2213
+ );
2214
+ };
2215
+ var SchematicPath_default = SchematicPath;
2216
+
2194
2217
  // src/schematic-components/SchematicElement.tsx
2195
2218
  var import_jsx_runtime21 = require("react/jsx-runtime");
2196
2219
  var SchematicElement = ({
@@ -2226,15 +2249,11 @@ var SchematicElement = ({
2226
2249
  if (element.type === "schematic_net_label") {
2227
2250
  return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicNetLabel, { net_label: element });
2228
2251
  }
2229
- if (element.type === "source_error") {
2230
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(RenderError_default, { text: element.message });
2231
- }
2232
2252
  return null;
2233
2253
  };
2234
2254
 
2235
2255
  // src/Schematic.tsx
2236
2256
  var import_use_mouse_matrix_transform = require("use-mouse-matrix-transform");
2237
- var import_react_error_boundary = require("react-error-boundary");
2238
2257
 
2239
2258
  // src/schematic-components/TableViewer.tsx
2240
2259
  var import_react8 = require("react");