@tscircuit/schematic-viewer 1.2.9 → 1.2.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.d.ts +5 -3
- package/dist/index.js +173 -162
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Schematic.tsx +22 -14
- package/src/lib/render-context/index.ts +20 -8
- package/src/schematic-components/ContextProviders.tsx +15 -0
- package/src/schematic-components/SVGPathComponent.tsx +2 -2
- package/src/schematic-components/SVGPathComponent2.tsx +2 -2
- package/src/schematic-components/SchematicText.tsx +2 -2
- package/src/schematic-components/index.tsx +1 -0
- package/src/stories/basics/schematic-net-label.stories.tsx +21 -2
- package/src/stories/bugs/bug7-multiple-schematic-panning.stories.tsx +23 -0
package/dist/index.js
CHANGED
|
@@ -292,7 +292,7 @@ var require_with_selector_development = __commonJS({
|
|
|
292
292
|
}
|
|
293
293
|
var objectIs = typeof Object.is === "function" ? Object.is : is;
|
|
294
294
|
var useSyncExternalStore = shim.useSyncExternalStore;
|
|
295
|
-
var useRef2 = React.useRef, useEffect4 = React.useEffect,
|
|
295
|
+
var useRef2 = React.useRef, useEffect4 = React.useEffect, useMemo3 = React.useMemo, useDebugValue2 = React.useDebugValue;
|
|
296
296
|
function useSyncExternalStoreWithSelector2(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
|
297
297
|
var instRef = useRef2(null);
|
|
298
298
|
var inst;
|
|
@@ -305,7 +305,7 @@ var require_with_selector_development = __commonJS({
|
|
|
305
305
|
} else {
|
|
306
306
|
inst = instRef.current;
|
|
307
307
|
}
|
|
308
|
-
var _useMemo =
|
|
308
|
+
var _useMemo = useMemo3(function() {
|
|
309
309
|
var hasMemo = false;
|
|
310
310
|
var memoizedSnapshot;
|
|
311
311
|
var memoizedSelection;
|
|
@@ -933,46 +933,13 @@ var require_svg_path_generator2 = __commonJS({
|
|
|
933
933
|
// src/index.ts
|
|
934
934
|
var src_exports = {};
|
|
935
935
|
__export(src_exports, {
|
|
936
|
-
Schematic: () => Schematic
|
|
936
|
+
Schematic: () => Schematic,
|
|
937
|
+
SchematicWithoutContext: () => SchematicWithoutContext
|
|
937
938
|
});
|
|
938
939
|
module.exports = __toCommonJS(src_exports);
|
|
939
940
|
|
|
940
941
|
// src/Schematic.tsx
|
|
941
|
-
var
|
|
942
|
-
var import_react_supergrid = require("react-supergrid");
|
|
943
|
-
var import_builder3 = require("@tscircuit/builder");
|
|
944
|
-
var import_react_fiber = __toESM(require("@tscircuit/react-fiber"));
|
|
945
|
-
|
|
946
|
-
// src/lib/utils/collect-element-refs.ts
|
|
947
|
-
var collectElementRefs = (elm, allElms) => {
|
|
948
|
-
const source_port = allElms.find(
|
|
949
|
-
(e) => e.type === "source_port" && e.source_port_id === elm.source_port_id
|
|
950
|
-
);
|
|
951
|
-
const source_component_id = elm.source_component_id ?? source_port?.source_component_id;
|
|
952
|
-
const source_component = allElms.find(
|
|
953
|
-
(e) => e.type === "source_component" && e.source_component_id === source_component_id
|
|
954
|
-
);
|
|
955
|
-
if ([
|
|
956
|
-
"schematic_component",
|
|
957
|
-
"schematic_trace",
|
|
958
|
-
"schematic_port",
|
|
959
|
-
"schematic_box",
|
|
960
|
-
"schematic_line",
|
|
961
|
-
"schematic_path"
|
|
962
|
-
].includes(elm.type)) {
|
|
963
|
-
const schematic_children = allElms.filter(
|
|
964
|
-
(e) => "schematic_component_id" in e && e.schematic_component_id === elm.schematic_component_id
|
|
965
|
-
);
|
|
966
|
-
return {
|
|
967
|
-
schematic_children,
|
|
968
|
-
schematic: elm,
|
|
969
|
-
source: source_component,
|
|
970
|
-
source_component,
|
|
971
|
-
source_port
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
return null;
|
|
975
|
-
};
|
|
942
|
+
var import_react9 = require("react");
|
|
976
943
|
|
|
977
944
|
// node_modules/zustand/esm/vanilla.js
|
|
978
945
|
var createStoreImpl = (createState) => {
|
|
@@ -1017,14 +984,6 @@ function useStore(api, selector = api.getState, equalityFn) {
|
|
|
1017
984
|
(0, import_react.useDebugValue)(slice);
|
|
1018
985
|
return slice;
|
|
1019
986
|
}
|
|
1020
|
-
var createImpl = (createState) => {
|
|
1021
|
-
const api = typeof createState === "function" ? createStore(createState) : createState;
|
|
1022
|
-
const useBoundStore = (selector, equalityFn) => useStore(api, selector, equalityFn);
|
|
1023
|
-
Object.assign(useBoundStore, api);
|
|
1024
|
-
return useBoundStore;
|
|
1025
|
-
};
|
|
1026
|
-
var create = (createState) => createState ? createImpl(createState) : createImpl;
|
|
1027
|
-
var create$1 = create;
|
|
1028
987
|
|
|
1029
988
|
// node_modules/transformation-matrix/src/applyToPoint.js
|
|
1030
989
|
function applyToPoint(matrix, point) {
|
|
@@ -1247,11 +1206,15 @@ peg$SyntaxError.buildMessage = function(expected, found) {
|
|
|
1247
1206
|
};
|
|
1248
1207
|
|
|
1249
1208
|
// src/lib/render-context/index.ts
|
|
1250
|
-
var
|
|
1209
|
+
var import_react2 = require("react");
|
|
1210
|
+
var createRenderContextStore = () => createStore((set) => ({
|
|
1251
1211
|
camera_transform: compose(scale(100, 100, 0, 0)),
|
|
1252
1212
|
setCameraTransform: (transform2) => set({ camera_transform: transform2 })
|
|
1253
1213
|
}));
|
|
1254
|
-
var
|
|
1214
|
+
var useGlobalStore = (s) => {
|
|
1215
|
+
const store = (0, import_react2.useContext)(StoreContext);
|
|
1216
|
+
return useStore(store, s);
|
|
1217
|
+
};
|
|
1255
1218
|
|
|
1256
1219
|
// src/lib/utils/get-svg-path-bounds.ts
|
|
1257
1220
|
var import_svg_path_bounds = __toESM(require_svg_path_bounds());
|
|
@@ -1271,7 +1234,7 @@ function getSVGPathBounds(ds) {
|
|
|
1271
1234
|
var get_svg_path_bounds_default = getSVGPathBounds;
|
|
1272
1235
|
|
|
1273
1236
|
// src/schematic-components/SVGPathComponent.tsx
|
|
1274
|
-
var
|
|
1237
|
+
var import_react3 = require("react");
|
|
1275
1238
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1276
1239
|
var SVGPathComponent = ({
|
|
1277
1240
|
size,
|
|
@@ -1283,7 +1246,7 @@ var SVGPathComponent = ({
|
|
|
1283
1246
|
shiftToBottom,
|
|
1284
1247
|
hoverContent
|
|
1285
1248
|
}) => {
|
|
1286
|
-
const ct =
|
|
1249
|
+
const ct = useGlobalStore((s) => s.camera_transform);
|
|
1287
1250
|
const pathBounds = get_svg_path_bounds_default(paths.map((p) => p.d));
|
|
1288
1251
|
const badRatio = Math.abs(pathBounds.width / pathBounds.height - size.width / size.height) > 0.01;
|
|
1289
1252
|
if (badRatio) {
|
|
@@ -1301,7 +1264,7 @@ var SVGPathComponent = ({
|
|
|
1301
1264
|
width: innerSize.width + padding.x * 2,
|
|
1302
1265
|
height: innerSize.height + padding.y * 2
|
|
1303
1266
|
};
|
|
1304
|
-
const [hovering, setHovering] = (0,
|
|
1267
|
+
const [hovering, setHovering] = (0, import_react3.useState)(false);
|
|
1305
1268
|
const svgLeft = absoluteCenter.x - fullSize.width / 2;
|
|
1306
1269
|
const svgTop = absoluteCenter.y - fullSize.height / 2;
|
|
1307
1270
|
const preferredRatio = pathBounds.width === 0 ? innerSize.height / pathBounds.height : innerSize.width / pathBounds.width;
|
|
@@ -1435,12 +1398,50 @@ var SimpleCapacitor = ({
|
|
|
1435
1398
|
};
|
|
1436
1399
|
|
|
1437
1400
|
// src/lib/hooks/use-maybe-promise.ts
|
|
1438
|
-
var
|
|
1401
|
+
var import_react4 = require("react");
|
|
1439
1402
|
|
|
1440
1403
|
// src/schematic-components/ProjectComponent.tsx
|
|
1441
1404
|
var import_builder = require("@tscircuit/builder");
|
|
1442
1405
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1443
1406
|
|
|
1407
|
+
// src/schematic-components/SchematicComponent.tsx
|
|
1408
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1409
|
+
var SchematicComponent = ({ component }) => {
|
|
1410
|
+
const { source, schematic } = component;
|
|
1411
|
+
if (!source.ftype)
|
|
1412
|
+
return null;
|
|
1413
|
+
switch (source.ftype) {
|
|
1414
|
+
case "simple_resistor": {
|
|
1415
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimpleResistor, { component: { source, schematic } });
|
|
1416
|
+
}
|
|
1417
|
+
case "simple_capacitor": {
|
|
1418
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimpleCapacitor, { component: { source, schematic } });
|
|
1419
|
+
}
|
|
1420
|
+
case "simple_power_source": {
|
|
1421
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimplePowerSource, { component: { source, schematic } });
|
|
1422
|
+
}
|
|
1423
|
+
case "simple_ground": {
|
|
1424
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimpleGround, { component: { source, schematic } });
|
|
1425
|
+
}
|
|
1426
|
+
case "simple_inductor": {
|
|
1427
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SimpleInductor, { component: { source, schematic } });
|
|
1428
|
+
}
|
|
1429
|
+
case "simple_bug": {
|
|
1430
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SchematicBug, { component: { source, schematic } });
|
|
1431
|
+
}
|
|
1432
|
+
case "simple_diode": {
|
|
1433
|
+
return null;
|
|
1434
|
+
}
|
|
1435
|
+
default: {
|
|
1436
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1437
|
+
"unknown ftype: ",
|
|
1438
|
+
component.source.ftype
|
|
1439
|
+
] });
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1443
|
+
var SchematicComponent_default = SchematicComponent;
|
|
1444
|
+
|
|
1444
1445
|
// src/lib/utils/direction-to-vec.ts
|
|
1445
1446
|
var directionToVec = (direction) => {
|
|
1446
1447
|
if (direction === "up")
|
|
@@ -1456,19 +1457,19 @@ var directionToVec = (direction) => {
|
|
|
1456
1457
|
};
|
|
1457
1458
|
|
|
1458
1459
|
// src/schematic-components/SchematicPort.tsx
|
|
1459
|
-
var
|
|
1460
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1460
1461
|
var SchematicPort = ({
|
|
1461
1462
|
port: { source_port, source_component, schematic }
|
|
1462
1463
|
}) => {
|
|
1463
1464
|
const hoverName = source_component?.name ? `.${source_component.name} > .${source_port?.name ?? source_port?.pin_number}` : `.${source_port?.name ?? source_port?.pin_number}`;
|
|
1464
1465
|
const vec = directionToVec(schematic.facing_direction);
|
|
1465
|
-
return /* @__PURE__ */ (0,
|
|
1466
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1466
1467
|
SVGPathComponent,
|
|
1467
1468
|
{
|
|
1468
1469
|
rotation: 0,
|
|
1469
|
-
hoverContent: /* @__PURE__ */ (0,
|
|
1470
|
+
hoverContent: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
|
|
1470
1471
|
hoverName,
|
|
1471
|
-
/* @__PURE__ */ (0,
|
|
1472
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("br", {}),
|
|
1472
1473
|
source_port?.pin_number && `Pin ${source_port.pin_number}`
|
|
1473
1474
|
] }),
|
|
1474
1475
|
center: schematic.center,
|
|
@@ -1495,7 +1496,7 @@ var SchematicPort = ({
|
|
|
1495
1496
|
var SchematicPort_default = SchematicPort;
|
|
1496
1497
|
|
|
1497
1498
|
// node_modules/react-use-measure/dist/web.js
|
|
1498
|
-
var
|
|
1499
|
+
var import_react5 = require("react");
|
|
1499
1500
|
var import_debounce = __toESM(require_debounce());
|
|
1500
1501
|
function useMeasure(_temp) {
|
|
1501
1502
|
let {
|
|
@@ -1513,7 +1514,7 @@ function useMeasure(_temp) {
|
|
|
1513
1514
|
if (!ResizeObserver) {
|
|
1514
1515
|
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");
|
|
1515
1516
|
}
|
|
1516
|
-
const [bounds, set] = (0,
|
|
1517
|
+
const [bounds, set] = (0, import_react5.useState)({
|
|
1517
1518
|
left: 0,
|
|
1518
1519
|
top: 0,
|
|
1519
1520
|
width: 0,
|
|
@@ -1523,7 +1524,7 @@ function useMeasure(_temp) {
|
|
|
1523
1524
|
x: 0,
|
|
1524
1525
|
y: 0
|
|
1525
1526
|
});
|
|
1526
|
-
const state = (0,
|
|
1527
|
+
const state = (0, import_react5.useRef)({
|
|
1527
1528
|
element: null,
|
|
1528
1529
|
scrollContainers: null,
|
|
1529
1530
|
resizeObserver: null,
|
|
@@ -1531,12 +1532,12 @@ function useMeasure(_temp) {
|
|
|
1531
1532
|
});
|
|
1532
1533
|
const scrollDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.scroll : null;
|
|
1533
1534
|
const resizeDebounce = debounce ? typeof debounce === "number" ? debounce : debounce.resize : null;
|
|
1534
|
-
const mounted = (0,
|
|
1535
|
-
(0,
|
|
1535
|
+
const mounted = (0, import_react5.useRef)(false);
|
|
1536
|
+
(0, import_react5.useEffect)(() => {
|
|
1536
1537
|
mounted.current = true;
|
|
1537
1538
|
return () => void (mounted.current = false);
|
|
1538
1539
|
});
|
|
1539
|
-
const [forceRefresh, resizeChange, scrollChange] = (0,
|
|
1540
|
+
const [forceRefresh, resizeChange, scrollChange] = (0, import_react5.useMemo)(() => {
|
|
1540
1541
|
const callback = () => {
|
|
1541
1542
|
if (!state.current.element)
|
|
1542
1543
|
return;
|
|
@@ -1602,22 +1603,22 @@ function useMeasure(_temp) {
|
|
|
1602
1603
|
};
|
|
1603
1604
|
useOnWindowScroll(scrollChange, Boolean(scroll));
|
|
1604
1605
|
useOnWindowResize(resizeChange);
|
|
1605
|
-
(0,
|
|
1606
|
+
(0, import_react5.useEffect)(() => {
|
|
1606
1607
|
removeListeners();
|
|
1607
1608
|
addListeners();
|
|
1608
1609
|
}, [scroll, scrollChange, resizeChange]);
|
|
1609
|
-
(0,
|
|
1610
|
+
(0, import_react5.useEffect)(() => removeListeners, []);
|
|
1610
1611
|
return [ref, bounds, forceRefresh];
|
|
1611
1612
|
}
|
|
1612
1613
|
function useOnWindowResize(onWindowResize) {
|
|
1613
|
-
(0,
|
|
1614
|
+
(0, import_react5.useEffect)(() => {
|
|
1614
1615
|
const cb = onWindowResize;
|
|
1615
1616
|
window.addEventListener("resize", cb);
|
|
1616
1617
|
return () => void window.removeEventListener("resize", cb);
|
|
1617
1618
|
}, [onWindowResize]);
|
|
1618
1619
|
}
|
|
1619
1620
|
function useOnWindowScroll(onScroll, enabled) {
|
|
1620
|
-
(0,
|
|
1621
|
+
(0, import_react5.useEffect)(() => {
|
|
1621
1622
|
if (enabled) {
|
|
1622
1623
|
const cb = onScroll;
|
|
1623
1624
|
window.addEventListener("scroll", cb, {
|
|
@@ -1645,9 +1646,9 @@ var keys = ["x", "y", "top", "bottom", "left", "right", "width", "height"];
|
|
|
1645
1646
|
var areBoundsEqual = (a, b) => keys.every((key) => a[key] === b[key]);
|
|
1646
1647
|
|
|
1647
1648
|
// src/schematic-components/SchematicText.tsx
|
|
1648
|
-
var
|
|
1649
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1649
1650
|
var SchematicText = ({ schematic_text }) => {
|
|
1650
|
-
const ct =
|
|
1651
|
+
const ct = useGlobalStore((s) => s.camera_transform);
|
|
1651
1652
|
const { text, position, anchor } = schematic_text;
|
|
1652
1653
|
const tPos = applyToPoint(ct, position);
|
|
1653
1654
|
const [boundsRef, bounds] = useMeasure();
|
|
@@ -1661,7 +1662,7 @@ var SchematicText = ({ schematic_text }) => {
|
|
|
1661
1662
|
}
|
|
1662
1663
|
const fontTransformRatio = 0.15;
|
|
1663
1664
|
const projectedTextSize = fontTransformRatio * ct.a;
|
|
1664
|
-
return /* @__PURE__ */ (0,
|
|
1665
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1665
1666
|
"div",
|
|
1666
1667
|
{
|
|
1667
1668
|
ref: boundsRef,
|
|
@@ -1682,9 +1683,9 @@ var SchematicText_default = SchematicText;
|
|
|
1682
1683
|
var import_svg_path_generator = __toESM(require_svg_path_generator2());
|
|
1683
1684
|
|
|
1684
1685
|
// src/schematic-components/RenderError.tsx
|
|
1685
|
-
var
|
|
1686
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1686
1687
|
var RenderError_default = ({ text }) => {
|
|
1687
|
-
return /* @__PURE__ */ (0,
|
|
1688
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1688
1689
|
"div",
|
|
1689
1690
|
{
|
|
1690
1691
|
style: {
|
|
@@ -1704,7 +1705,7 @@ var RenderError_default = ({ text }) => {
|
|
|
1704
1705
|
};
|
|
1705
1706
|
|
|
1706
1707
|
// src/schematic-components/SVGPathComponent2.tsx
|
|
1707
|
-
var
|
|
1708
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1708
1709
|
var SVGPathComponent2 = ({
|
|
1709
1710
|
size,
|
|
1710
1711
|
center,
|
|
@@ -1715,9 +1716,9 @@ var SVGPathComponent2 = ({
|
|
|
1715
1716
|
shiftToBottom,
|
|
1716
1717
|
hoverContent
|
|
1717
1718
|
}) => {
|
|
1718
|
-
const ct =
|
|
1719
|
+
const ct = useGlobalStore((c) => c.camera_transform);
|
|
1719
1720
|
const pathBounds = get_svg_path_bounds_default(paths.map((p) => p.d));
|
|
1720
|
-
return /* @__PURE__ */ (0,
|
|
1721
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1721
1722
|
"svg",
|
|
1722
1723
|
{
|
|
1723
1724
|
style: {
|
|
@@ -1734,7 +1735,7 @@ var SVGPathComponent2 = ({
|
|
|
1734
1735
|
// backgroundColor: "rgba(255, 0, 0, 0.1)",
|
|
1735
1736
|
},
|
|
1736
1737
|
overflow: "visible",
|
|
1737
|
-
children: paths.map((p, i) => /* @__PURE__ */ (0,
|
|
1738
|
+
children: paths.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1738
1739
|
"path",
|
|
1739
1740
|
{
|
|
1740
1741
|
transform: toSVG(ct),
|
|
@@ -1752,11 +1753,11 @@ var SVGPathComponent2 = ({
|
|
|
1752
1753
|
var SVGPathComponent2_default = SVGPathComponent2;
|
|
1753
1754
|
|
|
1754
1755
|
// src/schematic-components/SchematicTrace.tsx
|
|
1755
|
-
var
|
|
1756
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1756
1757
|
var SchematicTrace = ({ trace: { source, schematic } }) => {
|
|
1757
1758
|
const edges = schematic.edges;
|
|
1758
1759
|
if (edges.length === 0) {
|
|
1759
|
-
return /* @__PURE__ */ (0,
|
|
1760
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(RenderError_default, { text: `Route with 0 edges (${source.source_trace_id})` });
|
|
1760
1761
|
}
|
|
1761
1762
|
const path = (0, import_svg_path_generator.default)();
|
|
1762
1763
|
for (let i = 0; i < edges.length; i++) {
|
|
@@ -1771,7 +1772,7 @@ var SchematicTrace = ({ trace: { source, schematic } }) => {
|
|
|
1771
1772
|
x: pathBounds.minX + pathBounds.width / 2,
|
|
1772
1773
|
y: pathBounds.minY + pathBounds.height / 2
|
|
1773
1774
|
};
|
|
1774
|
-
return /* @__PURE__ */ (0,
|
|
1775
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1775
1776
|
SVGPathComponent2_default,
|
|
1776
1777
|
{
|
|
1777
1778
|
rotation: 0,
|
|
@@ -1791,7 +1792,7 @@ var SchematicTrace_default = SchematicTrace;
|
|
|
1791
1792
|
|
|
1792
1793
|
// src/schematic-components/SchematicBug.tsx
|
|
1793
1794
|
var import_builder2 = require("@tscircuit/builder");
|
|
1794
|
-
var
|
|
1795
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
1795
1796
|
var SchematicBug = ({ component: { source, schematic } }) => {
|
|
1796
1797
|
const port_arrangement = {
|
|
1797
1798
|
top_size: 0,
|
|
@@ -1828,7 +1829,7 @@ var SchematicBug = ({ component: { source, schematic } }) => {
|
|
|
1828
1829
|
x: schematic.center.x + (actualSize.minX + actualSize.maxX) / 2,
|
|
1829
1830
|
y: schematic.center.y + (actualSize.minY + actualSize.maxY) / 2
|
|
1830
1831
|
};
|
|
1831
|
-
return /* @__PURE__ */ (0,
|
|
1832
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
1832
1833
|
SVGPathComponent_default,
|
|
1833
1834
|
{
|
|
1834
1835
|
rotation: schematic.rotation,
|
|
@@ -1840,11 +1841,11 @@ var SchematicBug = ({ component: { source, schematic } }) => {
|
|
|
1840
1841
|
};
|
|
1841
1842
|
|
|
1842
1843
|
// src/schematic-components/SimplePowerSource.tsx
|
|
1843
|
-
var
|
|
1844
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1844
1845
|
var SimplePowerSource = ({
|
|
1845
1846
|
component: { source, schematic }
|
|
1846
1847
|
}) => {
|
|
1847
|
-
return /* @__PURE__ */ (0,
|
|
1848
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
1848
1849
|
SVGPathComponent_default,
|
|
1849
1850
|
{
|
|
1850
1851
|
rotation: schematic.rotation,
|
|
@@ -1875,9 +1876,9 @@ var SimplePowerSource = ({
|
|
|
1875
1876
|
};
|
|
1876
1877
|
|
|
1877
1878
|
// src/schematic-components/SimpleGround.tsx
|
|
1878
|
-
var
|
|
1879
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1879
1880
|
var SimpleGround = ({ component: { source, schematic } }) => {
|
|
1880
|
-
return /* @__PURE__ */ (0,
|
|
1881
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
1881
1882
|
SVGPathComponent_default,
|
|
1882
1883
|
{
|
|
1883
1884
|
rotation: schematic.rotation,
|
|
@@ -1897,9 +1898,9 @@ var SimpleGround = ({ component: { source, schematic } }) => {
|
|
|
1897
1898
|
};
|
|
1898
1899
|
|
|
1899
1900
|
// src/schematic-components/SimpleInductor.tsx
|
|
1900
|
-
var
|
|
1901
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1901
1902
|
var SimpleInductor = ({ component: { source, schematic } }) => {
|
|
1902
|
-
return /* @__PURE__ */ (0,
|
|
1903
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
1903
1904
|
SVGPathComponent_default,
|
|
1904
1905
|
{
|
|
1905
1906
|
rotation: schematic.rotation,
|
|
@@ -1918,51 +1919,59 @@ var SimpleInductor = ({ component: { source, schematic } }) => {
|
|
|
1918
1919
|
};
|
|
1919
1920
|
|
|
1920
1921
|
// src/schematic-components/SimpleDiode.tsx
|
|
1921
|
-
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1922
|
-
|
|
1923
|
-
// src/schematic-components/SchematicComponent.tsx
|
|
1924
1922
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1923
|
+
|
|
1924
|
+
// src/schematic-components/ContextProviders.tsx
|
|
1925
|
+
var import_react6 = require("react");
|
|
1926
|
+
var import_react7 = require("react");
|
|
1927
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
1928
|
+
var StoreContext = (0, import_react7.createContext)(null);
|
|
1929
|
+
var ContextProviders = ({ children }) => {
|
|
1930
|
+
const store = (0, import_react6.useMemo)(() => createRenderContextStore(), []);
|
|
1931
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(StoreContext.Provider, { value: store, children });
|
|
1932
|
+
};
|
|
1933
|
+
|
|
1934
|
+
// src/Schematic.tsx
|
|
1935
|
+
var import_react_supergrid = require("react-supergrid");
|
|
1936
|
+
var import_builder3 = require("@tscircuit/builder");
|
|
1937
|
+
var import_react_fiber = __toESM(require("@tscircuit/react-fiber"));
|
|
1938
|
+
|
|
1939
|
+
// src/lib/utils/collect-element-refs.ts
|
|
1940
|
+
var collectElementRefs = (elm, allElms) => {
|
|
1941
|
+
const source_port = allElms.find(
|
|
1942
|
+
(e) => e.type === "source_port" && e.source_port_id === elm.source_port_id
|
|
1943
|
+
);
|
|
1944
|
+
const source_component_id = elm.source_component_id ?? source_port?.source_component_id;
|
|
1945
|
+
const source_component = allElms.find(
|
|
1946
|
+
(e) => e.type === "source_component" && e.source_component_id === source_component_id
|
|
1947
|
+
);
|
|
1948
|
+
if ([
|
|
1949
|
+
"schematic_component",
|
|
1950
|
+
"schematic_trace",
|
|
1951
|
+
"schematic_port",
|
|
1952
|
+
"schematic_box",
|
|
1953
|
+
"schematic_line",
|
|
1954
|
+
"schematic_path"
|
|
1955
|
+
].includes(elm.type)) {
|
|
1956
|
+
const schematic_children = allElms.filter(
|
|
1957
|
+
(e) => "schematic_component_id" in e && e.schematic_component_id === elm.schematic_component_id
|
|
1958
|
+
);
|
|
1959
|
+
return {
|
|
1960
|
+
schematic_children,
|
|
1961
|
+
schematic: elm,
|
|
1962
|
+
source: source_component,
|
|
1963
|
+
source_component,
|
|
1964
|
+
source_port
|
|
1965
|
+
};
|
|
1957
1966
|
}
|
|
1967
|
+
return null;
|
|
1958
1968
|
};
|
|
1959
|
-
var SchematicComponent_default = SchematicComponent;
|
|
1960
1969
|
|
|
1961
1970
|
// src/schematic-components/SchematicBox.tsx
|
|
1962
|
-
var
|
|
1971
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
1963
1972
|
var SchematicBox = ({ box: { schematic } }) => {
|
|
1964
1973
|
const { width: w, height: h } = schematic;
|
|
1965
|
-
return /* @__PURE__ */ (0,
|
|
1974
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1966
1975
|
SVGPathComponent,
|
|
1967
1976
|
{
|
|
1968
1977
|
rotation: 0,
|
|
@@ -1982,7 +1991,7 @@ var SchematicBox_default = SchematicBox;
|
|
|
1982
1991
|
|
|
1983
1992
|
// src/schematic-components/SchematicLine.tsx
|
|
1984
1993
|
var import_svg_path_generator2 = __toESM(require_svg_path_generator2());
|
|
1985
|
-
var
|
|
1994
|
+
var import_jsx_runtime18 = require("react/jsx-runtime");
|
|
1986
1995
|
var SchematicLine = ({ line: { schematic } }) => {
|
|
1987
1996
|
const { x1, x2, y1, y2 } = schematic;
|
|
1988
1997
|
const dx = x2 - x1;
|
|
@@ -1996,7 +2005,7 @@ var SchematicLine = ({ line: { schematic } }) => {
|
|
|
1996
2005
|
x: pathBounds.minX + pathBounds.width / 2,
|
|
1997
2006
|
y: pathBounds.minY + pathBounds.height / 2
|
|
1998
2007
|
};
|
|
1999
|
-
return /* @__PURE__ */ (0,
|
|
2008
|
+
return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
|
|
2000
2009
|
SVGPathComponent,
|
|
2001
2010
|
{
|
|
2002
2011
|
rotation: 0,
|
|
@@ -2016,7 +2025,7 @@ var SchematicLine_default = SchematicLine;
|
|
|
2016
2025
|
|
|
2017
2026
|
// src/schematic-components/SchematicPath.tsx
|
|
2018
2027
|
var import_svg_path_generator3 = __toESM(require_svg_path_generator2());
|
|
2019
|
-
var
|
|
2028
|
+
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
2020
2029
|
var SchematicPath = (props) => {
|
|
2021
2030
|
const { points, is_filled, is_closed, fill_color } = props.path.schematic;
|
|
2022
2031
|
if (points.length === 0)
|
|
@@ -2037,7 +2046,7 @@ var SchematicPath = (props) => {
|
|
|
2037
2046
|
x: pathBounds.minX + pathBounds.width / 2,
|
|
2038
2047
|
y: pathBounds.minY + pathBounds.height / 2
|
|
2039
2048
|
};
|
|
2040
|
-
return /* @__PURE__ */ (0,
|
|
2049
|
+
return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
2041
2050
|
SVGPathComponent,
|
|
2042
2051
|
{
|
|
2043
2052
|
rotation: 0,
|
|
@@ -2057,15 +2066,15 @@ var SchematicPath = (props) => {
|
|
|
2057
2066
|
var SchematicPath_default = SchematicPath;
|
|
2058
2067
|
|
|
2059
2068
|
// src/schematic-components/SchematicNetLabel.tsx
|
|
2060
|
-
var
|
|
2069
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
2061
2070
|
var SchematicNetLabel = ({
|
|
2062
2071
|
net_label
|
|
2063
2072
|
}) => {
|
|
2064
2073
|
console.log({ net_label });
|
|
2065
2074
|
const text_width = net_label.text.length * 0.15;
|
|
2066
2075
|
const path_width = 31 + net_label.text.length * 5;
|
|
2067
|
-
return /* @__PURE__ */ (0,
|
|
2068
|
-
/* @__PURE__ */ (0,
|
|
2076
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
|
|
2077
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
2069
2078
|
SVGPathComponent_default,
|
|
2070
2079
|
{
|
|
2071
2080
|
rotation: 0,
|
|
@@ -2083,7 +2092,7 @@ var SchematicNetLabel = ({
|
|
|
2083
2092
|
]
|
|
2084
2093
|
}
|
|
2085
2094
|
),
|
|
2086
|
-
/* @__PURE__ */ (0,
|
|
2095
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
2087
2096
|
SchematicText_default,
|
|
2088
2097
|
{
|
|
2089
2098
|
schematic_text: {
|
|
@@ -2103,13 +2112,13 @@ var SchematicNetLabel = ({
|
|
|
2103
2112
|
};
|
|
2104
2113
|
|
|
2105
2114
|
// src/schematic-components/SchematicElement.tsx
|
|
2106
|
-
var
|
|
2115
|
+
var import_jsx_runtime21 = require("react/jsx-runtime");
|
|
2107
2116
|
var SchematicElement = ({
|
|
2108
2117
|
element,
|
|
2109
2118
|
allElements
|
|
2110
2119
|
}) => {
|
|
2111
2120
|
if (element.type === "schematic_component") {
|
|
2112
|
-
return /* @__PURE__ */ (0,
|
|
2121
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
2113
2122
|
SchematicComponent_default,
|
|
2114
2123
|
{
|
|
2115
2124
|
component: collectElementRefs(element, allElements)
|
|
@@ -2117,28 +2126,28 @@ var SchematicElement = ({
|
|
|
2117
2126
|
);
|
|
2118
2127
|
}
|
|
2119
2128
|
if (element.type === "schematic_trace") {
|
|
2120
|
-
return /* @__PURE__ */ (0,
|
|
2129
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicTrace_default, { trace: collectElementRefs(element, allElements) });
|
|
2121
2130
|
}
|
|
2122
2131
|
if (element.type === "schematic_port") {
|
|
2123
|
-
return /* @__PURE__ */ (0,
|
|
2132
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicPort_default, { port: collectElementRefs(element, allElements) });
|
|
2124
2133
|
}
|
|
2125
2134
|
if (element.type === "schematic_box") {
|
|
2126
|
-
return /* @__PURE__ */ (0,
|
|
2135
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicBox_default, { box: collectElementRefs(element, allElements) });
|
|
2127
2136
|
}
|
|
2128
2137
|
if (element.type === "schematic_line") {
|
|
2129
|
-
return /* @__PURE__ */ (0,
|
|
2138
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicLine_default, { line: collectElementRefs(element, allElements) });
|
|
2130
2139
|
}
|
|
2131
2140
|
if (element.type === "schematic_path") {
|
|
2132
|
-
return /* @__PURE__ */ (0,
|
|
2141
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicPath_default, { path: collectElementRefs(element, allElements) });
|
|
2133
2142
|
}
|
|
2134
2143
|
if (element.type === "schematic_text") {
|
|
2135
|
-
return /* @__PURE__ */ (0,
|
|
2144
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicText_default, { schematic_text: element });
|
|
2136
2145
|
}
|
|
2137
2146
|
if (element.type === "schematic_net_label") {
|
|
2138
|
-
return /* @__PURE__ */ (0,
|
|
2147
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SchematicNetLabel, { net_label: element });
|
|
2139
2148
|
}
|
|
2140
2149
|
if (element.type === "source_error") {
|
|
2141
|
-
return /* @__PURE__ */ (0,
|
|
2150
|
+
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(RenderError_default, { text: element.message });
|
|
2142
2151
|
}
|
|
2143
2152
|
return null;
|
|
2144
2153
|
};
|
|
@@ -2148,20 +2157,20 @@ var import_use_mouse_matrix_transform = require("use-mouse-matrix-transform");
|
|
|
2148
2157
|
var import_react_error_boundary = require("react-error-boundary");
|
|
2149
2158
|
|
|
2150
2159
|
// src/schematic-components/TableViewer.tsx
|
|
2151
|
-
var
|
|
2152
|
-
var
|
|
2153
|
-
var LazyTableViewer = (0,
|
|
2160
|
+
var import_react8 = require("react");
|
|
2161
|
+
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
2162
|
+
var LazyTableViewer = (0, import_react8.lazy)(
|
|
2154
2163
|
() => import("@tscircuit/table-viewer").then((m) => ({
|
|
2155
2164
|
default: m.SoupTableViewer
|
|
2156
2165
|
}))
|
|
2157
2166
|
);
|
|
2158
|
-
var TableViewer = (params) => /* @__PURE__ */ (0,
|
|
2167
|
+
var TableViewer = (params) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_react8.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { children: "Loading..." }), children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(LazyTableViewer, { ...params }) });
|
|
2159
2168
|
|
|
2160
2169
|
// src/Schematic.tsx
|
|
2161
|
-
var
|
|
2170
|
+
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
2162
2171
|
var ErrorBoundary = import_react_error_boundary.ErrorBoundary;
|
|
2163
2172
|
var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
|
|
2164
|
-
return /* @__PURE__ */ (0,
|
|
2173
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { style: { color: "red" }, children: [
|
|
2165
2174
|
"error rendering ",
|
|
2166
2175
|
elm.type,
|
|
2167
2176
|
": ",
|
|
@@ -2169,7 +2178,10 @@ var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
|
|
|
2169
2178
|
] });
|
|
2170
2179
|
};
|
|
2171
2180
|
var toMMSINeg = (v, z) => v >= 0 ? (0, import_react_supergrid.toMMSI)(v, z) : `-${(0, import_react_supergrid.toMMSI)(-v, z)}`;
|
|
2172
|
-
var Schematic = ({
|
|
2181
|
+
var Schematic = (props) => {
|
|
2182
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ContextProviders, { children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(SchematicWithoutContext, { ...props }) });
|
|
2183
|
+
};
|
|
2184
|
+
var SchematicWithoutContext = ({
|
|
2173
2185
|
children,
|
|
2174
2186
|
elements: initialElements,
|
|
2175
2187
|
soup: initialSoup,
|
|
@@ -2177,10 +2189,9 @@ var Schematic = ({
|
|
|
2177
2189
|
showTable = false
|
|
2178
2190
|
}) => {
|
|
2179
2191
|
initialSoup = initialSoup ?? initialElements ?? [];
|
|
2180
|
-
const [elements, setElements] = (0,
|
|
2181
|
-
const [project, setProject] = (0,
|
|
2182
|
-
const setCameraTransform =
|
|
2183
|
-
const cameraTransform = useRenderContext((s) => s.camera_transform);
|
|
2192
|
+
const [elements, setElements] = (0, import_react9.useState)(initialSoup ?? []);
|
|
2193
|
+
const [project, setProject] = (0, import_react9.useState)(null);
|
|
2194
|
+
const { setCameraTransform, camera_transform: cameraTransform } = useGlobalStore();
|
|
2184
2195
|
const [boundsRef, bounds] = useMeasure();
|
|
2185
2196
|
const { ref, setTransform } = (0, import_use_mouse_matrix_transform.useMouseMatrixTransform)({
|
|
2186
2197
|
onSetTransform: (transform2) => {
|
|
@@ -2188,7 +2199,7 @@ var Schematic = ({
|
|
|
2188
2199
|
}
|
|
2189
2200
|
// initialTransform: compose(scale(100, 100, 0, 0)),
|
|
2190
2201
|
});
|
|
2191
|
-
const setElementsAndCamera = (0,
|
|
2202
|
+
const setElementsAndCamera = (0, import_react9.useCallback)(
|
|
2192
2203
|
(elements2) => {
|
|
2193
2204
|
const elmBounds = ref.current.getBoundingClientRect();
|
|
2194
2205
|
const { center, width, height } = elements2.some(
|
|
@@ -2206,7 +2217,6 @@ var Schematic = ({
|
|
|
2206
2217
|
setTransform(
|
|
2207
2218
|
compose(
|
|
2208
2219
|
translate((elmBounds.width ?? 0) / 2, (elmBounds.height ?? 0) / 2),
|
|
2209
|
-
// translate(100, 0),
|
|
2210
2220
|
scale(scaleFactor, -scaleFactor, 0, 0),
|
|
2211
2221
|
translate(-center.x, -center.y)
|
|
2212
2222
|
)
|
|
@@ -2214,7 +2224,7 @@ var Schematic = ({
|
|
|
2214
2224
|
},
|
|
2215
2225
|
[setElements, setTransform]
|
|
2216
2226
|
);
|
|
2217
|
-
(0,
|
|
2227
|
+
(0, import_react9.useEffect)(() => {
|
|
2218
2228
|
if (initialSoup.length > 0) {
|
|
2219
2229
|
setElementsAndCamera(initialSoup);
|
|
2220
2230
|
return;
|
|
@@ -2227,8 +2237,8 @@ var Schematic = ({
|
|
|
2227
2237
|
throw e;
|
|
2228
2238
|
});
|
|
2229
2239
|
}, [children]);
|
|
2230
|
-
return /* @__PURE__ */ (0,
|
|
2231
|
-
/* @__PURE__ */ (0,
|
|
2240
|
+
return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_jsx_runtime23.Fragment, { children: [
|
|
2241
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
|
|
2232
2242
|
"div",
|
|
2233
2243
|
{
|
|
2234
2244
|
style: {
|
|
@@ -2246,7 +2256,7 @@ var Schematic = ({
|
|
|
2246
2256
|
boundsRef(el);
|
|
2247
2257
|
},
|
|
2248
2258
|
children: [
|
|
2249
|
-
/* @__PURE__ */ (0,
|
|
2259
|
+
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
2250
2260
|
import_react_supergrid.SuperGrid,
|
|
2251
2261
|
{
|
|
2252
2262
|
stringifyCoord: (x, y, z) => {
|
|
@@ -2259,7 +2269,7 @@ var Schematic = ({
|
|
|
2259
2269
|
transform: cameraTransform
|
|
2260
2270
|
}
|
|
2261
2271
|
),
|
|
2262
|
-
elements?.map((elm, i) => /* @__PURE__ */ (0,
|
|
2272
|
+
elements?.map((elm, i) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ErrorBoundary, { fallbackRender: fallbackRender(elm), children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
2263
2273
|
SchematicElement,
|
|
2264
2274
|
{
|
|
2265
2275
|
element: elm,
|
|
@@ -2270,12 +2280,13 @@ var Schematic = ({
|
|
|
2270
2280
|
]
|
|
2271
2281
|
}
|
|
2272
2282
|
),
|
|
2273
|
-
showTable !== false && elements && /* @__PURE__ */ (0,
|
|
2283
|
+
showTable !== false && elements && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(TableViewer, { elements })
|
|
2274
2284
|
] });
|
|
2275
2285
|
};
|
|
2276
2286
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2277
2287
|
0 && (module.exports = {
|
|
2278
|
-
Schematic
|
|
2288
|
+
Schematic,
|
|
2289
|
+
SchematicWithoutContext
|
|
2279
2290
|
});
|
|
2280
2291
|
/*! Bundled license information:
|
|
2281
2292
|
|