@tscircuit/schematic-viewer 1.0.12 → 1.0.14
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 +99 -19
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/Schematic.tsx +20 -1
- package/src/lib/types/core.ts +21 -0
- package/src/lib/utils/collect-element-refs.ts +14 -3
- package/src/schematic-components/SchematicBox.tsx +29 -0
- package/src/schematic-components/SchematicComponent.tsx +1 -0
- package/src/schematic-components/SchematicElement.tsx +14 -0
- package/src/schematic-components/SchematicLine.tsx +35 -0
- package/src/schematic-components/SchematicText.tsx +1 -0
- package/src/stories/net-alias.stories.tsx +92 -0
package/dist/index.js
CHANGED
|
@@ -1276,6 +1276,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
1276
1276
|
|
|
1277
1277
|
// src/Schematic.tsx
|
|
1278
1278
|
var import_react4 = require("react");
|
|
1279
|
+
var import_react_supergrid = require("react-supergrid");
|
|
1279
1280
|
var import_builder3 = require("@tscircuit/builder");
|
|
1280
1281
|
var import_react_fiber = require("@tscircuit/react-fiber");
|
|
1281
1282
|
|
|
@@ -1284,10 +1285,18 @@ var collectElementRefs = (elm, allElms) => {
|
|
|
1284
1285
|
const source_component = allElms.find(
|
|
1285
1286
|
(e) => e.type === "source_component" && e.source_component_id === elm.source_component_id
|
|
1286
1287
|
);
|
|
1287
|
-
if ([
|
|
1288
|
-
|
|
1289
|
-
|
|
1288
|
+
if ([
|
|
1289
|
+
"schematic_component",
|
|
1290
|
+
"schematic_trace",
|
|
1291
|
+
"schematic_port",
|
|
1292
|
+
"schematic_box",
|
|
1293
|
+
"schematic_line"
|
|
1294
|
+
].includes(elm.type)) {
|
|
1295
|
+
const schematic_children = allElms.filter(
|
|
1296
|
+
(e) => "schematic_component_id" in e && e.schematic_component_id === elm.schematic_component_id
|
|
1297
|
+
);
|
|
1290
1298
|
return {
|
|
1299
|
+
schematic_children,
|
|
1291
1300
|
schematic: elm,
|
|
1292
1301
|
source: source_component
|
|
1293
1302
|
};
|
|
@@ -2103,29 +2112,82 @@ var SchematicComponent = ({ component }) => {
|
|
|
2103
2112
|
};
|
|
2104
2113
|
var SchematicComponent_default = SchematicComponent;
|
|
2105
2114
|
|
|
2106
|
-
// src/schematic-components/
|
|
2115
|
+
// src/schematic-components/SchematicBox.tsx
|
|
2107
2116
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
2117
|
+
var SchematicBox = ({ box: { schematic } }) => {
|
|
2118
|
+
const { width: w, height: h } = schematic;
|
|
2119
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SVGPathComponent, {
|
|
2120
|
+
rotation: 0,
|
|
2121
|
+
center: schematic,
|
|
2122
|
+
size: { width: schematic.width, height: schematic.height },
|
|
2123
|
+
paths: [
|
|
2124
|
+
{
|
|
2125
|
+
stroke: "red",
|
|
2126
|
+
strokeWidth: 0.2,
|
|
2127
|
+
d: `M 0 0 l ${w} 0 l 0 ${h} l -${w} 0 z`
|
|
2128
|
+
}
|
|
2129
|
+
]
|
|
2130
|
+
});
|
|
2131
|
+
};
|
|
2132
|
+
var SchematicBox_default = SchematicBox;
|
|
2133
|
+
|
|
2134
|
+
// src/schematic-components/SchematicLine.tsx
|
|
2135
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
2136
|
+
var SchematicLine = ({ line: { schematic } }) => {
|
|
2137
|
+
const { x1, x2, y1, y2 } = schematic;
|
|
2138
|
+
const dx = x2 - x1;
|
|
2139
|
+
const dy = y2 - y1;
|
|
2140
|
+
const width = Math.abs(dx) + 0.1;
|
|
2141
|
+
const height = Math.abs(dy) + 0.1;
|
|
2142
|
+
const center = { x: x1 + dx / 2, y: y1 + dy / 2 };
|
|
2143
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(SVGPathComponent, {
|
|
2144
|
+
rotation: 0,
|
|
2145
|
+
center,
|
|
2146
|
+
size: { width, height },
|
|
2147
|
+
paths: [
|
|
2148
|
+
{
|
|
2149
|
+
stroke: "red",
|
|
2150
|
+
strokeWidth: 10,
|
|
2151
|
+
d: `M 0 0 l ${dx * 100} ${dy * 100}`
|
|
2152
|
+
}
|
|
2153
|
+
]
|
|
2154
|
+
});
|
|
2155
|
+
};
|
|
2156
|
+
var SchematicLine_default = SchematicLine;
|
|
2157
|
+
|
|
2158
|
+
// src/schematic-components/SchematicElement.tsx
|
|
2159
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
2108
2160
|
var SchematicElement = ({
|
|
2109
2161
|
element,
|
|
2110
2162
|
allElements
|
|
2111
2163
|
}) => {
|
|
2112
2164
|
if (element.type === "schematic_component") {
|
|
2113
|
-
return /* @__PURE__ */ (0,
|
|
2165
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicComponent_default, {
|
|
2114
2166
|
component: collectElementRefs(element, allElements)
|
|
2115
2167
|
});
|
|
2116
2168
|
}
|
|
2117
2169
|
if (element.type === "schematic_trace") {
|
|
2118
|
-
return /* @__PURE__ */ (0,
|
|
2170
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicTrace_default, {
|
|
2119
2171
|
trace: collectElementRefs(element, allElements)
|
|
2120
2172
|
});
|
|
2121
2173
|
}
|
|
2122
2174
|
if (element.type === "schematic_port") {
|
|
2123
|
-
return /* @__PURE__ */ (0,
|
|
2175
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicPort_default, {
|
|
2124
2176
|
port: collectElementRefs(element, allElements)
|
|
2125
2177
|
});
|
|
2126
2178
|
}
|
|
2179
|
+
if (element.type === "schematic_box") {
|
|
2180
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicBox_default, {
|
|
2181
|
+
box: collectElementRefs(element, allElements)
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
2184
|
+
if (element.type === "schematic_line") {
|
|
2185
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicLine_default, {
|
|
2186
|
+
line: collectElementRefs(element, allElements)
|
|
2187
|
+
});
|
|
2188
|
+
}
|
|
2127
2189
|
if (element.type === "schematic_text") {
|
|
2128
|
-
return /* @__PURE__ */ (0,
|
|
2190
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SchematicText_default, {
|
|
2129
2191
|
schematic_text: element
|
|
2130
2192
|
});
|
|
2131
2193
|
}
|
|
@@ -2135,9 +2197,9 @@ var SchematicElement = ({
|
|
|
2135
2197
|
// src/Schematic.tsx
|
|
2136
2198
|
var import_use_mouse_matrix_transform = require("use-mouse-matrix-transform");
|
|
2137
2199
|
var import_react_error_boundary = require("react-error-boundary");
|
|
2138
|
-
var
|
|
2200
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
2139
2201
|
var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
|
|
2140
|
-
return /* @__PURE__ */ (0,
|
|
2202
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", {
|
|
2141
2203
|
style: { color: "red" },
|
|
2142
2204
|
children: [
|
|
2143
2205
|
"error rendering ",
|
|
@@ -2147,6 +2209,7 @@ var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
|
|
|
2147
2209
|
]
|
|
2148
2210
|
});
|
|
2149
2211
|
};
|
|
2212
|
+
var toMMSINeg = (v, z) => v >= 0 ? (0, import_react_supergrid.toMMSI)(v, z) : `-${(0, import_react_supergrid.toMMSI)(-v, z)}`;
|
|
2150
2213
|
var Schematic = ({
|
|
2151
2214
|
children,
|
|
2152
2215
|
elements: initialElements,
|
|
@@ -2157,6 +2220,8 @@ var Schematic = ({
|
|
|
2157
2220
|
const [elements, setElements] = (0, import_react4.useState)(initialSoup ?? []);
|
|
2158
2221
|
const [project, setProject] = (0, import_react4.useState)(null);
|
|
2159
2222
|
const setCameraTransform = useRenderContext((s) => s.setCameraTransform);
|
|
2223
|
+
const cameraTransform = useRenderContext((s) => s.camera_transform);
|
|
2224
|
+
const [boundsRef, bounds] = useMeasure();
|
|
2160
2225
|
const { ref, setTransform } = (0, import_use_mouse_matrix_transform.useMouseMatrixTransform)({
|
|
2161
2226
|
onSetTransform: (transform2) => {
|
|
2162
2227
|
setCameraTransform(transform2);
|
|
@@ -2191,7 +2256,7 @@ var Schematic = ({
|
|
|
2191
2256
|
throw e;
|
|
2192
2257
|
});
|
|
2193
2258
|
}, [children]);
|
|
2194
|
-
return /* @__PURE__ */ (0,
|
|
2259
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", {
|
|
2195
2260
|
style: {
|
|
2196
2261
|
width: "100%",
|
|
2197
2262
|
backgroundColor: "rgba(255,255,255,0)",
|
|
@@ -2201,14 +2266,29 @@ var Schematic = ({
|
|
|
2201
2266
|
cursor: "grab",
|
|
2202
2267
|
...style
|
|
2203
2268
|
},
|
|
2204
|
-
ref
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2269
|
+
ref: (el) => {
|
|
2270
|
+
ref.current = el;
|
|
2271
|
+
boundsRef(el);
|
|
2272
|
+
},
|
|
2273
|
+
children: [
|
|
2274
|
+
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_supergrid.SuperGrid, {
|
|
2275
|
+
stringifyCoord: (x, y, z) => {
|
|
2276
|
+
if (z === 0)
|
|
2277
|
+
return "";
|
|
2278
|
+
return `${toMMSINeg(x, z)}, ${toMMSINeg(y, z)}`;
|
|
2279
|
+
},
|
|
2280
|
+
width: bounds.width,
|
|
2281
|
+
height: bounds.height,
|
|
2282
|
+
transform: cameraTransform
|
|
2283
|
+
}),
|
|
2284
|
+
elements == null ? void 0 : elements.map((elm, i) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_react_error_boundary.ErrorBoundary, {
|
|
2285
|
+
fallbackRender: fallbackRender(elm),
|
|
2286
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(SchematicElement, {
|
|
2287
|
+
element: elm,
|
|
2288
|
+
allElements: elements
|
|
2289
|
+
}, JSON.stringify(elm))
|
|
2290
|
+
}, i))
|
|
2291
|
+
]
|
|
2212
2292
|
});
|
|
2213
2293
|
};
|
|
2214
2294
|
// Annotate the CommonJS export names for ESM import in node:
|