@tscircuit/schematic-viewer 1.0.11 → 1.0.13

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
@@ -1284,10 +1284,18 @@ var collectElementRefs = (elm, allElms) => {
1284
1284
  const source_component = allElms.find(
1285
1285
  (e) => e.type === "source_component" && e.source_component_id === elm.source_component_id
1286
1286
  );
1287
- if (["schematic_component", "schematic_trace", "schematic_port"].includes(
1288
- elm.type
1289
- )) {
1287
+ if ([
1288
+ "schematic_component",
1289
+ "schematic_trace",
1290
+ "schematic_port",
1291
+ "schematic_box",
1292
+ "schematic_line"
1293
+ ].includes(elm.type)) {
1294
+ const schematic_children = allElms.filter(
1295
+ (e) => "schematic_component_id" in e && e.schematic_component_id === elm.schematic_component_id
1296
+ );
1290
1297
  return {
1298
+ schematic_children,
1291
1299
  schematic: elm,
1292
1300
  source: source_component
1293
1301
  };
@@ -1590,9 +1598,6 @@ var SVGPathComponent = ({ size, center, rotation, paths }) => {
1590
1598
  const pathBounds = get_svg_path_bounds_default(paths.map((p) => p.d));
1591
1599
  const badRatio = Math.abs(pathBounds.width / pathBounds.height - size.width / size.height) > 0.01;
1592
1600
  if (badRatio) {
1593
- console.warn(
1594
- `Ratio doesn't match for component. ${pathBounds.width}:${pathBounds.height} is not close to ${size.width}:${size.height}`
1595
- );
1596
1601
  }
1597
1602
  pathBounds.height = Math.max(pathBounds.height, 1);
1598
1603
  pathBounds.width = Math.max(pathBounds.width, 1);
@@ -1943,14 +1948,18 @@ var import_range = __toESM(require_range());
1943
1948
  var import_builder2 = require("@tscircuit/builder");
1944
1949
  var import_jsx_runtime9 = require("react/jsx-runtime");
1945
1950
  var SchematicBug = ({ component: { source, schematic } }) => {
1946
- const ports_arrangement = {
1951
+ const port_arrangement = {
1947
1952
  top_size: 0,
1948
1953
  bottom_size: 0,
1949
1954
  ...schematic.port_arrangement
1950
1955
  };
1951
- const bugw = schematic.size.width;
1952
- const bugh = schematic.size.height;
1953
- const { total_ports } = (0, import_builder2.getPortArrangementSize)(ports_arrangement);
1956
+ let bugw = schematic.size.width;
1957
+ let bugh = schematic.size.height;
1958
+ const { total_ports, width, height } = (0, import_builder2.getPortArrangementSize)(port_arrangement);
1959
+ if (isNaN(bugw))
1960
+ bugw = width;
1961
+ if (isNaN(bugh))
1962
+ bugh = height;
1954
1963
  const paths = [
1955
1964
  {
1956
1965
  stroke: "red",
@@ -1958,7 +1967,7 @@ var SchematicBug = ({ component: { source, schematic } }) => {
1958
1967
  d: `M ${-bugw / 2} ${-bugh / 2} L ${bugw / 2} ${-bugh / 2} L ${bugw / 2} ${bugh / 2} L ${-bugw / 2} ${bugh / 2}Z`
1959
1968
  },
1960
1969
  ...(0, import_range.default)(1, total_ports + 1).map((portNum) => {
1961
- const pos = (0, import_builder2.getPortPosition)(ports_arrangement, portNum);
1970
+ const pos = (0, import_builder2.getPortPosition)(port_arrangement, portNum);
1962
1971
  const x2 = pos.side === "left" ? -bugw / 2 : pos.side === "right" ? bugw / 2 : pos.x;
1963
1972
  const y2 = pos.side === "top" ? -bugh / 2 : pos.side === "bottom" ? bugh / 2 : pos.y;
1964
1973
  return {
@@ -2102,29 +2111,82 @@ var SchematicComponent = ({ component }) => {
2102
2111
  };
2103
2112
  var SchematicComponent_default = SchematicComponent;
2104
2113
 
2105
- // src/schematic-components/SchematicElement.tsx
2114
+ // src/schematic-components/SchematicBox.tsx
2106
2115
  var import_jsx_runtime15 = require("react/jsx-runtime");
2116
+ var SchematicBox = ({ box: { schematic } }) => {
2117
+ const { width: w, height: h } = schematic;
2118
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SVGPathComponent, {
2119
+ rotation: 0,
2120
+ center: schematic,
2121
+ size: { width: schematic.width, height: schematic.height },
2122
+ paths: [
2123
+ {
2124
+ stroke: "red",
2125
+ strokeWidth: 0.2,
2126
+ d: `M 0 0 l ${w} 0 l 0 ${h} l -${w} 0 z`
2127
+ }
2128
+ ]
2129
+ });
2130
+ };
2131
+ var SchematicBox_default = SchematicBox;
2132
+
2133
+ // src/schematic-components/SchematicLine.tsx
2134
+ var import_jsx_runtime16 = require("react/jsx-runtime");
2135
+ var SchematicLine = ({ line: { schematic } }) => {
2136
+ const { x1, x2, y1, y2 } = schematic;
2137
+ const dx = x2 - x1;
2138
+ const dy = y2 - y1;
2139
+ const width = Math.abs(dx) + 0.1;
2140
+ const height = Math.abs(dy) + 0.1;
2141
+ const center = { x: x1 + dx / 2, y: y1 + dy / 2 };
2142
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(SVGPathComponent, {
2143
+ rotation: 0,
2144
+ center,
2145
+ size: { width, height },
2146
+ paths: [
2147
+ {
2148
+ stroke: "red",
2149
+ strokeWidth: 10,
2150
+ d: `M 0 0 l ${dx * 100} ${dy * 100}`
2151
+ }
2152
+ ]
2153
+ });
2154
+ };
2155
+ var SchematicLine_default = SchematicLine;
2156
+
2157
+ // src/schematic-components/SchematicElement.tsx
2158
+ var import_jsx_runtime17 = require("react/jsx-runtime");
2107
2159
  var SchematicElement = ({
2108
2160
  element,
2109
2161
  allElements
2110
2162
  }) => {
2111
2163
  if (element.type === "schematic_component") {
2112
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SchematicComponent_default, {
2164
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicComponent_default, {
2113
2165
  component: collectElementRefs(element, allElements)
2114
2166
  });
2115
2167
  }
2116
2168
  if (element.type === "schematic_trace") {
2117
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SchematicTrace_default, {
2169
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicTrace_default, {
2118
2170
  trace: collectElementRefs(element, allElements)
2119
2171
  });
2120
2172
  }
2121
2173
  if (element.type === "schematic_port") {
2122
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SchematicPort_default, {
2174
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicPort_default, {
2123
2175
  port: collectElementRefs(element, allElements)
2124
2176
  });
2125
2177
  }
2178
+ if (element.type === "schematic_box") {
2179
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicBox_default, {
2180
+ box: collectElementRefs(element, allElements)
2181
+ });
2182
+ }
2183
+ if (element.type === "schematic_line") {
2184
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicLine_default, {
2185
+ line: collectElementRefs(element, allElements)
2186
+ });
2187
+ }
2126
2188
  if (element.type === "schematic_text") {
2127
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SchematicText_default, {
2189
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicText_default, {
2128
2190
  schematic_text: element
2129
2191
  });
2130
2192
  }
@@ -2134,9 +2196,9 @@ var SchematicElement = ({
2134
2196
  // src/Schematic.tsx
2135
2197
  var import_use_mouse_matrix_transform = require("use-mouse-matrix-transform");
2136
2198
  var import_react_error_boundary = require("react-error-boundary");
2137
- var import_jsx_runtime16 = require("react/jsx-runtime");
2199
+ var import_jsx_runtime18 = require("react/jsx-runtime");
2138
2200
  var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
2139
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", {
2201
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", {
2140
2202
  style: { color: "red" },
2141
2203
  children: [
2142
2204
  "error rendering ",
@@ -2167,7 +2229,6 @@ var Schematic = ({
2167
2229
  const { center, width, height } = (0, import_builder3.findBoundsAndCenter)(elements2);
2168
2230
  setElements(elements2);
2169
2231
  setProject((0, import_builder3.createProjectFromElements)(elements2));
2170
- console.log(elmBounds.width);
2171
2232
  setTransform(
2172
2233
  compose(
2173
2234
  translate((elmBounds.width ?? 0) / 2, (elmBounds.height ?? 0) / 2),
@@ -2191,7 +2252,7 @@ var Schematic = ({
2191
2252
  throw e;
2192
2253
  });
2193
2254
  }, [children]);
2194
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", {
2255
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", {
2195
2256
  style: {
2196
2257
  width: "100%",
2197
2258
  backgroundColor: "rgba(255,255,255,0)",
@@ -2202,9 +2263,9 @@ var Schematic = ({
2202
2263
  ...style
2203
2264
  },
2204
2265
  ref,
2205
- children: elements == null ? void 0 : elements.map((elm, i) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_react_error_boundary.ErrorBoundary, {
2266
+ children: elements == null ? void 0 : elements.map((elm, i) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_error_boundary.ErrorBoundary, {
2206
2267
  fallbackRender: fallbackRender(elm),
2207
- children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(SchematicElement, {
2268
+ children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(SchematicElement, {
2208
2269
  element: elm,
2209
2270
  allElements: elements
2210
2271
  }, JSON.stringify(elm))