@tscircuit/schematic-viewer 1.0.12 → 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
  };
@@ -2103,29 +2111,82 @@ var SchematicComponent = ({ component }) => {
2103
2111
  };
2104
2112
  var SchematicComponent_default = SchematicComponent;
2105
2113
 
2106
- // src/schematic-components/SchematicElement.tsx
2114
+ // src/schematic-components/SchematicBox.tsx
2107
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");
2108
2159
  var SchematicElement = ({
2109
2160
  element,
2110
2161
  allElements
2111
2162
  }) => {
2112
2163
  if (element.type === "schematic_component") {
2113
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SchematicComponent_default, {
2164
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicComponent_default, {
2114
2165
  component: collectElementRefs(element, allElements)
2115
2166
  });
2116
2167
  }
2117
2168
  if (element.type === "schematic_trace") {
2118
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SchematicTrace_default, {
2169
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicTrace_default, {
2119
2170
  trace: collectElementRefs(element, allElements)
2120
2171
  });
2121
2172
  }
2122
2173
  if (element.type === "schematic_port") {
2123
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SchematicPort_default, {
2174
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicPort_default, {
2124
2175
  port: collectElementRefs(element, allElements)
2125
2176
  });
2126
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
+ }
2127
2188
  if (element.type === "schematic_text") {
2128
- return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SchematicText_default, {
2189
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicText_default, {
2129
2190
  schematic_text: element
2130
2191
  });
2131
2192
  }
@@ -2135,9 +2196,9 @@ var SchematicElement = ({
2135
2196
  // src/Schematic.tsx
2136
2197
  var import_use_mouse_matrix_transform = require("use-mouse-matrix-transform");
2137
2198
  var import_react_error_boundary = require("react-error-boundary");
2138
- var import_jsx_runtime16 = require("react/jsx-runtime");
2199
+ var import_jsx_runtime18 = require("react/jsx-runtime");
2139
2200
  var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
2140
- return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", {
2201
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", {
2141
2202
  style: { color: "red" },
2142
2203
  children: [
2143
2204
  "error rendering ",
@@ -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))