@tscircuit/schematic-viewer 0.0.5 → 0.0.7
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 +198 -296
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
- package/src/Schematic.tsx +35 -1
- package/src/lib/render-context/index.ts +6 -5
- package/src/lib/utils/collect-element-refs.ts +20 -0
- package/src/schematic-components/ProjectComponent.tsx +4 -0
- package/src/schematic-components/SchematicComponent.tsx +0 -1
- package/src/schematic-components/SchematicElement.tsx +45 -0
- package/src/schematic-components/SchematicPort.tsx +0 -1
- package/tsconfig.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1276,9 +1276,24 @@ module.exports = __toCommonJS(src_exports);
|
|
|
1276
1276
|
|
|
1277
1277
|
// src/Schematic.tsx
|
|
1278
1278
|
var import_react4 = require("react");
|
|
1279
|
+
var import_builder2 = require("@tscircuit/builder");
|
|
1280
|
+
var import_react_fiber = require("@tscircuit/react-fiber");
|
|
1279
1281
|
|
|
1280
|
-
// src/
|
|
1281
|
-
var
|
|
1282
|
+
// src/lib/utils/collect-element-refs.ts
|
|
1283
|
+
var collectElementRefs = (elm, allElms) => {
|
|
1284
|
+
const source_component = allElms.find(
|
|
1285
|
+
(e) => e.type === "source_component" && e.source_component_id === elm.source_component_id
|
|
1286
|
+
);
|
|
1287
|
+
if (["schematic_component", "schematic_trace", "schematic_port"].includes(
|
|
1288
|
+
elm.type
|
|
1289
|
+
)) {
|
|
1290
|
+
return {
|
|
1291
|
+
schematic: elm,
|
|
1292
|
+
source: source_component
|
|
1293
|
+
};
|
|
1294
|
+
}
|
|
1295
|
+
return null;
|
|
1296
|
+
};
|
|
1282
1297
|
|
|
1283
1298
|
// node_modules/zustand/esm/vanilla.mjs
|
|
1284
1299
|
var createStoreImpl = (createState) => {
|
|
@@ -1544,11 +1559,10 @@ peg$SyntaxError.buildMessage = function(expected, found) {
|
|
|
1544
1559
|
};
|
|
1545
1560
|
|
|
1546
1561
|
// src/lib/render-context/index.ts
|
|
1547
|
-
var useRenderContext = create$1()(
|
|
1548
|
-
(
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
);
|
|
1562
|
+
var useRenderContext = create$1((set, get) => ({
|
|
1563
|
+
camera_transform: compose(scale(100, 100, 0, 0)),
|
|
1564
|
+
setCameraTransform: (transform2) => set({ camera_transform: transform2 })
|
|
1565
|
+
}));
|
|
1552
1566
|
var useCameraTransform = () => useRenderContext((s) => s.camera_transform);
|
|
1553
1567
|
|
|
1554
1568
|
// src/lib/utils/get-svg-path-bounds.ts
|
|
@@ -1569,7 +1583,6 @@ function getSVGPathBounds(ds) {
|
|
|
1569
1583
|
var get_svg_path_bounds_default = getSVGPathBounds;
|
|
1570
1584
|
|
|
1571
1585
|
// src/schematic-components/SVGPathComponent.tsx
|
|
1572
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1573
1586
|
var SVGPathComponent = ({ size, center, rotation, paths }) => {
|
|
1574
1587
|
const ct = useCameraTransform();
|
|
1575
1588
|
const pathBounds = get_svg_path_bounds_default(paths.map((p) => p.d));
|
|
@@ -1586,169 +1599,43 @@ var SVGPathComponent = ({ size, center, rotation, paths }) => {
|
|
|
1586
1599
|
width: Math.max(1, size.width * ct.a),
|
|
1587
1600
|
height: Math.max(1, size.height * ct.d)
|
|
1588
1601
|
};
|
|
1589
|
-
return
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
},
|
|
1596
|
-
overflow: "visible",
|
|
1597
|
-
width: absoluteSize.width,
|
|
1598
|
-
height: absoluteSize.height,
|
|
1599
|
-
viewBox: `${pathBounds.minX} ${pathBounds.minY} ${pathBounds.width} ${pathBounds.height}`,
|
|
1600
|
-
children: paths.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", {
|
|
1601
|
-
fill: "none",
|
|
1602
|
-
strokeWidth: 2 * (p.strokeWidth || 1),
|
|
1603
|
-
stroke: p.stroke || "red",
|
|
1604
|
-
d: p.d
|
|
1605
|
-
}, i))
|
|
1606
|
-
});
|
|
1602
|
+
return <svg style={{
|
|
1603
|
+
position: "absolute",
|
|
1604
|
+
transform: rotation === 0 ? "" : `rotate(${rotation}rad)`,
|
|
1605
|
+
left: absoluteCenter.x - absoluteSize.width / 2,
|
|
1606
|
+
top: absoluteCenter.y - absoluteSize.height / 2
|
|
1607
|
+
}} overflow="visible" width={absoluteSize.width} height={absoluteSize.height} viewBox={`${pathBounds.minX} ${pathBounds.minY} ${pathBounds.width} ${pathBounds.height}`}>{paths.map((p, i) => <path key={i} fill="none" strokeWidth={2 * (p.strokeWidth || 1)} stroke={p.stroke || "red"} d={p.d} />)}</svg>;
|
|
1607
1608
|
};
|
|
1608
1609
|
var SVGPathComponent_default = SVGPathComponent;
|
|
1609
1610
|
|
|
1610
1611
|
// src/schematic-components/SimpleResistor.tsx
|
|
1611
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1612
1612
|
var SimpleResistor = ({ component: { source, schematic } }) => {
|
|
1613
|
-
return
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
strokeWidth: 1,
|
|
1621
|
-
d: "M 0 15 l 10 0 l 0 -6 l 20 0 l 0 12 l -20 0 l 0 -6 m 20 0 l 10 0"
|
|
1622
|
-
}
|
|
1623
|
-
]
|
|
1624
|
-
});
|
|
1613
|
+
return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
|
|
1614
|
+
{
|
|
1615
|
+
stroke: "red",
|
|
1616
|
+
strokeWidth: 1,
|
|
1617
|
+
d: "M 0 15 l 10 0 l 0 -6 l 20 0 l 0 12 l -20 0 l 0 -6 m 20 0 l 10 0"
|
|
1618
|
+
}
|
|
1619
|
+
]} />;
|
|
1625
1620
|
};
|
|
1626
1621
|
|
|
1627
1622
|
// src/schematic-components/SimpleCapacitor.tsx
|
|
1628
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1629
1623
|
var SimpleCapacitor = ({
|
|
1630
1624
|
component: { source, schematic }
|
|
1631
1625
|
}) => {
|
|
1632
|
-
return
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
{ stroke: "red", strokeWidth: 2, d: "M 12 0 l 0 30" },
|
|
1639
|
-
{ stroke: "red", strokeWidth: 2, d: "M 18 0 l 0 30" },
|
|
1640
|
-
{ stroke: "red", strokeWidth: 1, d: "M 18 15 l 12 0" }
|
|
1641
|
-
]
|
|
1642
|
-
});
|
|
1626
|
+
return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
|
|
1627
|
+
{ stroke: "red", strokeWidth: 1, d: "M 0 15 l 12 0" },
|
|
1628
|
+
{ stroke: "red", strokeWidth: 2, d: "M 12 0 l 0 30" },
|
|
1629
|
+
{ stroke: "red", strokeWidth: 2, d: "M 18 0 l 0 30" },
|
|
1630
|
+
{ stroke: "red", strokeWidth: 1, d: "M 18 15 l 12 0" }
|
|
1631
|
+
]} />;
|
|
1643
1632
|
};
|
|
1644
1633
|
|
|
1645
1634
|
// src/lib/hooks/use-maybe-promise.ts
|
|
1646
1635
|
var import_react2 = require("react");
|
|
1647
|
-
var useMaybePromise = (promise) => {
|
|
1648
|
-
const [state, setState] = (0, import_react2.useState)(null);
|
|
1649
|
-
(0, import_react2.useEffect)(() => {
|
|
1650
|
-
if (promise instanceof Promise) {
|
|
1651
|
-
promise.then(setState);
|
|
1652
|
-
} else {
|
|
1653
|
-
setState(promise);
|
|
1654
|
-
}
|
|
1655
|
-
}, [promise]);
|
|
1656
|
-
return state;
|
|
1657
|
-
};
|
|
1658
1636
|
|
|
1659
1637
|
// src/schematic-components/ProjectComponent.tsx
|
|
1660
1638
|
var import_builder = require("@tscircuit/builder");
|
|
1661
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1662
|
-
var ProjectComponent = ({ project: $project }) => {
|
|
1663
|
-
const project = useMaybePromise($project);
|
|
1664
|
-
if (!project)
|
|
1665
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", {
|
|
1666
|
-
children: "loading"
|
|
1667
|
-
});
|
|
1668
|
-
const projectClass = new import_builder.ProjectClass(project);
|
|
1669
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, {
|
|
1670
|
-
children: [
|
|
1671
|
-
project.schematic_components.map((schematic_component) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SchematicComponent, {
|
|
1672
|
-
component: {
|
|
1673
|
-
source: projectClass.getSourceComponent(
|
|
1674
|
-
schematic_component.source_component_id
|
|
1675
|
-
),
|
|
1676
|
-
schematic: schematic_component
|
|
1677
|
-
}
|
|
1678
|
-
}, schematic_component.schematic_component_id)),
|
|
1679
|
-
project.schematic_ports.map((schematic_port) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SchematicPort, {
|
|
1680
|
-
port: {
|
|
1681
|
-
source: projectClass.getSourcePort(
|
|
1682
|
-
schematic_port.schematic_port_id
|
|
1683
|
-
),
|
|
1684
|
-
schematic: schematic_port
|
|
1685
|
-
}
|
|
1686
|
-
}, schematic_port.schematic_port_id)),
|
|
1687
|
-
project.schematic_traces.map((schematic_trace) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SchematicTrace, {
|
|
1688
|
-
trace: {
|
|
1689
|
-
source: projectClass.getSourceTrace(
|
|
1690
|
-
schematic_trace.source_trace_id
|
|
1691
|
-
),
|
|
1692
|
-
schematic: schematic_trace
|
|
1693
|
-
}
|
|
1694
|
-
}, schematic_trace.schematic_trace_id)),
|
|
1695
|
-
project.schematic_texts.map((schematic_text) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SchematicText, {
|
|
1696
|
-
schematic_text
|
|
1697
|
-
}, schematic_text.schematic_text_id))
|
|
1698
|
-
]
|
|
1699
|
-
});
|
|
1700
|
-
};
|
|
1701
|
-
|
|
1702
|
-
// src/schematic-components/SchematicComponent.tsx
|
|
1703
|
-
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1704
|
-
var SchematicComponent = ({ component }) => {
|
|
1705
|
-
const { source, schematic } = component;
|
|
1706
|
-
switch (source.ftype) {
|
|
1707
|
-
case "simple_resistor": {
|
|
1708
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SimpleResistor, {
|
|
1709
|
-
component: { source, schematic }
|
|
1710
|
-
});
|
|
1711
|
-
}
|
|
1712
|
-
case "simple_capacitor": {
|
|
1713
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SimpleCapacitor, {
|
|
1714
|
-
component: { source, schematic }
|
|
1715
|
-
});
|
|
1716
|
-
}
|
|
1717
|
-
case "simple_power_source": {
|
|
1718
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SimplePowerSource, {
|
|
1719
|
-
component: { source, schematic }
|
|
1720
|
-
});
|
|
1721
|
-
}
|
|
1722
|
-
case "simple_ground": {
|
|
1723
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SimpleGround, {
|
|
1724
|
-
component: { source, schematic }
|
|
1725
|
-
});
|
|
1726
|
-
}
|
|
1727
|
-
case "simple_inductor": {
|
|
1728
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SimpleInductor, {
|
|
1729
|
-
component: { source, schematic }
|
|
1730
|
-
});
|
|
1731
|
-
}
|
|
1732
|
-
case "simple_bug": {
|
|
1733
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SchematicBug, {
|
|
1734
|
-
component: { source, schematic }
|
|
1735
|
-
});
|
|
1736
|
-
}
|
|
1737
|
-
case "simple_diode": {
|
|
1738
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SimpleDiode, {
|
|
1739
|
-
component: { source, schematic }
|
|
1740
|
-
});
|
|
1741
|
-
}
|
|
1742
|
-
default: {
|
|
1743
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
|
|
1744
|
-
children: [
|
|
1745
|
-
"unknown ftype: ",
|
|
1746
|
-
component.source.ftype
|
|
1747
|
-
]
|
|
1748
|
-
});
|
|
1749
|
-
}
|
|
1750
|
-
}
|
|
1751
|
-
};
|
|
1752
1639
|
|
|
1753
1640
|
// src/lib/utils/direction-to-vec.ts
|
|
1754
1641
|
var directionToVec = (direction) => {
|
|
@@ -1765,26 +1652,21 @@ var directionToVec = (direction) => {
|
|
|
1765
1652
|
};
|
|
1766
1653
|
|
|
1767
1654
|
// src/schematic-components/SchematicPort.tsx
|
|
1768
|
-
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1769
1655
|
var SchematicPort = ({ port: { source, schematic } }) => {
|
|
1770
|
-
return
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
}
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
strokeWidth: 0.5,
|
|
1783
|
-
d: `M 5 5 l ${directionToVec(schematic.facing_direction).x * 7} ${directionToVec(schematic.facing_direction).y * 7}`
|
|
1784
|
-
} : null
|
|
1785
|
-
].filter(Boolean)
|
|
1786
|
-
});
|
|
1656
|
+
return <SVGPathComponent rotation={0} center={schematic.center} size={{ width: 0.2, height: 0.2 }} paths={[
|
|
1657
|
+
{
|
|
1658
|
+
stroke: "blue",
|
|
1659
|
+
strokeWidth: 1,
|
|
1660
|
+
d: "M 0 0 l 10 0 l 0 10 l -10 0 z"
|
|
1661
|
+
},
|
|
1662
|
+
schematic.facing_direction ? {
|
|
1663
|
+
stroke: "blue",
|
|
1664
|
+
strokeWidth: 0.5,
|
|
1665
|
+
d: `M 5 5 l ${directionToVec(schematic.facing_direction).x * 7} ${directionToVec(schematic.facing_direction).y * 7}`
|
|
1666
|
+
} : null
|
|
1667
|
+
].filter(Boolean)} />;
|
|
1787
1668
|
};
|
|
1669
|
+
var SchematicPort_default = SchematicPort;
|
|
1788
1670
|
|
|
1789
1671
|
// node_modules/react-use-measure/dist/web.js
|
|
1790
1672
|
var import_react3 = require("react");
|
|
@@ -1937,7 +1819,6 @@ var keys = ["x", "y", "top", "bottom", "left", "right", "width", "height"];
|
|
|
1937
1819
|
var areBoundsEqual = (a, b) => keys.every((key) => a[key] === b[key]);
|
|
1938
1820
|
|
|
1939
1821
|
// src/schematic-components/SchematicText.tsx
|
|
1940
|
-
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1941
1822
|
var SchematicText = ({ schematic_text }) => {
|
|
1942
1823
|
const ct = useCameraTransform();
|
|
1943
1824
|
const { text, position, anchor } = schematic_text;
|
|
@@ -1951,48 +1832,38 @@ var SchematicText = ({ schematic_text }) => {
|
|
|
1951
1832
|
} else if (anchor === "right") {
|
|
1952
1833
|
offset = [-bounds.width, -bounds.height / 2];
|
|
1953
1834
|
}
|
|
1954
|
-
return
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
top: tPos.y + offset[1]
|
|
1961
|
-
},
|
|
1962
|
-
children: text
|
|
1963
|
-
});
|
|
1835
|
+
return <div ref={boundsRef} style={{
|
|
1836
|
+
fontFamily: "'IBM Plex Mono', monospace",
|
|
1837
|
+
position: "absolute",
|
|
1838
|
+
left: tPos.x + offset[0],
|
|
1839
|
+
top: tPos.y + offset[1]
|
|
1840
|
+
}}>{text}</div>;
|
|
1964
1841
|
};
|
|
1842
|
+
var SchematicText_default = SchematicText;
|
|
1965
1843
|
|
|
1966
1844
|
// src/schematic-components/SchematicTrace.tsx
|
|
1967
1845
|
var import_svg_path_generator = __toESM(require_svg_path_generator2());
|
|
1968
1846
|
|
|
1969
1847
|
// src/schematic-components/RenderError.tsx
|
|
1970
|
-
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1971
1848
|
var RenderError_default = ({ text }) => {
|
|
1972
|
-
return
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
},
|
|
1984
|
-
children: text
|
|
1985
|
-
});
|
|
1849
|
+
return <div style={{
|
|
1850
|
+
position: "fixed",
|
|
1851
|
+
backgroundColor: "red",
|
|
1852
|
+
color: "white",
|
|
1853
|
+
fontSize: 14,
|
|
1854
|
+
fontFamily: "sans-serif",
|
|
1855
|
+
padding: 5,
|
|
1856
|
+
right: 0,
|
|
1857
|
+
top: 0,
|
|
1858
|
+
opacity: 0.75
|
|
1859
|
+
}}>{text}</div>;
|
|
1986
1860
|
};
|
|
1987
1861
|
|
|
1988
1862
|
// src/schematic-components/SchematicTrace.tsx
|
|
1989
|
-
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1990
1863
|
var SchematicTrace = ({ trace: { source, schematic } }) => {
|
|
1991
1864
|
const edges = schematic.edges;
|
|
1992
1865
|
if (edges.length === 0) {
|
|
1993
|
-
return
|
|
1994
|
-
text: "Route with 0 edges"
|
|
1995
|
-
});
|
|
1866
|
+
return <RenderError_default text="Route with 0 edges" />;
|
|
1996
1867
|
}
|
|
1997
1868
|
const path = (0, import_svg_path_generator.default)();
|
|
1998
1869
|
for (let i = 0; i < edges.length; i++) {
|
|
@@ -2007,23 +1878,18 @@ var SchematicTrace = ({ trace: { source, schematic } }) => {
|
|
|
2007
1878
|
x: pathBounds.minX + pathBounds.width / 2,
|
|
2008
1879
|
y: pathBounds.minY + pathBounds.height / 2
|
|
2009
1880
|
};
|
|
2010
|
-
return
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
strokeWidth: 0.02,
|
|
2018
|
-
d
|
|
2019
|
-
}
|
|
2020
|
-
]
|
|
2021
|
-
});
|
|
1881
|
+
return <SVGPathComponent_default rotation={0} center={center} size={pathBounds} paths={[
|
|
1882
|
+
{
|
|
1883
|
+
stroke: "green",
|
|
1884
|
+
strokeWidth: 0.02,
|
|
1885
|
+
d
|
|
1886
|
+
}
|
|
1887
|
+
]} />;
|
|
2022
1888
|
};
|
|
1889
|
+
var SchematicTrace_default = SchematicTrace;
|
|
2023
1890
|
|
|
2024
1891
|
// src/schematic-components/SchematicBug.tsx
|
|
2025
1892
|
var import_range = __toESM(require_range());
|
|
2026
|
-
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
2027
1893
|
var SchematicBug = ({ component: { source, schematic } }) => {
|
|
2028
1894
|
const ports_arrangement = schematic.port_arrangement;
|
|
2029
1895
|
const port_labels = schematic.port_labels;
|
|
@@ -2031,114 +1897,152 @@ var SchematicBug = ({ component: { source, schematic } }) => {
|
|
|
2031
1897
|
const rh = 15;
|
|
2032
1898
|
const pd = 7.5;
|
|
2033
1899
|
const bugh = Math.max(ports_arrangement.left_size, ports_arrangement.right_size) * rh;
|
|
2034
|
-
return
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
1900
|
+
return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
|
|
1901
|
+
{
|
|
1902
|
+
stroke: "red",
|
|
1903
|
+
strokeWidth: 1,
|
|
1904
|
+
d: `M 0 0 L ${bugw} 0 L ${bugw} ${bugh} L 0 ${bugh}Z`
|
|
1905
|
+
},
|
|
1906
|
+
...(0, import_range.default)(
|
|
1907
|
+
0,
|
|
1908
|
+
ports_arrangement.left_size + ports_arrangement.right_size
|
|
1909
|
+
).map((i) => {
|
|
1910
|
+
const ls = ports_arrangement.left_size;
|
|
1911
|
+
const left = i < ls;
|
|
1912
|
+
const rowi = i % ls;
|
|
1913
|
+
const p1 = [left ? 0 : bugw, rh / 2 + rowi * rh];
|
|
1914
|
+
const rd = [left ? -pd : pd, 0];
|
|
1915
|
+
return {
|
|
2040
1916
|
stroke: "red",
|
|
2041
1917
|
strokeWidth: 1,
|
|
2042
|
-
d: `M
|
|
2043
|
-
}
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
ports_arrangement.left_size + ports_arrangement.right_size
|
|
2047
|
-
).map((i) => {
|
|
2048
|
-
const ls = ports_arrangement.left_size;
|
|
2049
|
-
const left = i < ls;
|
|
2050
|
-
const rowi = i % ls;
|
|
2051
|
-
const p1 = [left ? 0 : bugw, rh / 2 + rowi * rh];
|
|
2052
|
-
const rd = [left ? -pd : pd, 0];
|
|
2053
|
-
return {
|
|
2054
|
-
stroke: "red",
|
|
2055
|
-
strokeWidth: 1,
|
|
2056
|
-
d: `M ${p1.join(" ")} l ${rd.join(" ")}`
|
|
2057
|
-
};
|
|
2058
|
-
})
|
|
2059
|
-
]
|
|
2060
|
-
});
|
|
1918
|
+
d: `M ${p1.join(" ")} l ${rd.join(" ")}`
|
|
1919
|
+
};
|
|
1920
|
+
})
|
|
1921
|
+
]} />;
|
|
2061
1922
|
};
|
|
2062
1923
|
|
|
2063
1924
|
// src/schematic-components/SimplePowerSource.tsx
|
|
2064
|
-
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
2065
1925
|
var SimplePowerSource = ({
|
|
2066
1926
|
component: { source, schematic }
|
|
2067
1927
|
}) => {
|
|
2068
|
-
return
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
strokeWidth: 1,
|
|
2076
|
-
d: "M 0 -17 L 0 -3 M -8 3 L 8 3 M 0 17 L 0 3 M -12 -3 L 12 -3"
|
|
2077
|
-
}
|
|
2078
|
-
]
|
|
2079
|
-
});
|
|
1928
|
+
return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
|
|
1929
|
+
{
|
|
1930
|
+
stroke: "red",
|
|
1931
|
+
strokeWidth: 1,
|
|
1932
|
+
d: "M 0 -17 L 0 -3 M -8 3 L 8 3 M 0 17 L 0 3 M -12 -3 L 12 -3"
|
|
1933
|
+
}
|
|
1934
|
+
]} />;
|
|
2080
1935
|
};
|
|
2081
1936
|
|
|
2082
1937
|
// src/schematic-components/SimpleGround.tsx
|
|
2083
|
-
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
2084
1938
|
var SimpleGround = ({ component: { source, schematic } }) => {
|
|
2085
|
-
return
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
strokeWidth: 0.7,
|
|
2093
|
-
d: "M -3 3 L 3 3 M -6 0 L 6 0 M -9 -3 L 9 -3 M 0 -3 L 0 -12"
|
|
2094
|
-
}
|
|
2095
|
-
]
|
|
2096
|
-
});
|
|
1939
|
+
return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
|
|
1940
|
+
{
|
|
1941
|
+
stroke: "red",
|
|
1942
|
+
strokeWidth: 0.7,
|
|
1943
|
+
d: "M -3 3 L 3 3 M -6 0 L 6 0 M -9 -3 L 9 -3 M 0 -3 L 0 -12"
|
|
1944
|
+
}
|
|
1945
|
+
]} />;
|
|
2097
1946
|
};
|
|
2098
1947
|
|
|
2099
1948
|
// src/schematic-components/SimpleInductor.tsx
|
|
2100
|
-
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
2101
1949
|
var SimpleInductor = ({ component: { source, schematic } }) => {
|
|
2102
|
-
return
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
strokeWidth: 1,
|
|
2110
|
-
d: "m 371,710.41665 h -14 c -0.0421,-16.39898 -14.02104,-16.39898 -14,0 -0.021,-16.399 -14.04182,-16.34072 -14,0 -2.6e-4,-16.45722 -14.04236,-16.45722 -14,0 2.8e-4,-16.3407 -13.97896,-16.39898 -14,0 -0.0421,-16.39898 -13.91338,-16.39898 -13.91338,0 H 273"
|
|
2111
|
-
}
|
|
2112
|
-
]
|
|
2113
|
-
});
|
|
1950
|
+
return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
|
|
1951
|
+
{
|
|
1952
|
+
stroke: "red",
|
|
1953
|
+
strokeWidth: 1,
|
|
1954
|
+
d: "m 371,710.41665 h -14 c -0.0421,-16.39898 -14.02104,-16.39898 -14,0 -0.021,-16.399 -14.04182,-16.34072 -14,0 -2.6e-4,-16.45722 -14.04236,-16.45722 -14,0 2.8e-4,-16.3407 -13.97896,-16.39898 -14,0 -0.0421,-16.39898 -13.91338,-16.39898 -13.91338,0 H 273"
|
|
1955
|
+
}
|
|
1956
|
+
]} />;
|
|
2114
1957
|
};
|
|
2115
1958
|
|
|
2116
1959
|
// src/schematic-components/SimpleDiode.tsx
|
|
2117
|
-
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
2118
1960
|
var SimpleDiode = ({ component: { source, schematic } }) => {
|
|
2119
|
-
return
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
}
|
|
1961
|
+
return <SVGPathComponent_default rotation={schematic.rotation} center={schematic.center} size={schematic.size} paths={[
|
|
1962
|
+
{ stroke: "red", strokeWidth: 2, d: "M 0,0 H 21" },
|
|
1963
|
+
{ stroke: "red", strokeWidth: 2, d: "M 49,0 H 59" },
|
|
1964
|
+
{ stroke: "red", strokeWidth: 2, d: "M 49,0 L 21 14 V -14 Z" },
|
|
1965
|
+
{ stroke: "red", strokeWidth: 2, d: "M 49,-14 V 14" }
|
|
1966
|
+
]} />;
|
|
1967
|
+
};
|
|
1968
|
+
|
|
1969
|
+
// src/schematic-components/SchematicComponent.tsx
|
|
1970
|
+
var SchematicComponent = ({ component }) => {
|
|
1971
|
+
const { source, schematic } = component;
|
|
1972
|
+
switch (source.ftype) {
|
|
1973
|
+
case "simple_resistor": {
|
|
1974
|
+
return <SimpleResistor component={{ source, schematic }} />;
|
|
1975
|
+
}
|
|
1976
|
+
case "simple_capacitor": {
|
|
1977
|
+
return <SimpleCapacitor component={{ source, schematic }} />;
|
|
1978
|
+
}
|
|
1979
|
+
case "simple_power_source": {
|
|
1980
|
+
return <SimplePowerSource component={{ source, schematic }} />;
|
|
1981
|
+
}
|
|
1982
|
+
case "simple_ground": {
|
|
1983
|
+
return <SimpleGround component={{ source, schematic }} />;
|
|
1984
|
+
}
|
|
1985
|
+
case "simple_inductor": {
|
|
1986
|
+
return <SimpleInductor component={{ source, schematic }} />;
|
|
1987
|
+
}
|
|
1988
|
+
case "simple_bug": {
|
|
1989
|
+
return <SchematicBug component={{ source, schematic }} />;
|
|
1990
|
+
}
|
|
1991
|
+
case "simple_diode": {
|
|
1992
|
+
return <SimpleDiode component={{ source, schematic }} />;
|
|
1993
|
+
}
|
|
1994
|
+
default: {
|
|
1995
|
+
return <div>
|
|
1996
|
+
{"unknown ftype: "}
|
|
1997
|
+
{component.source.ftype}
|
|
1998
|
+
</div>;
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
};
|
|
2002
|
+
var SchematicComponent_default = SchematicComponent;
|
|
2003
|
+
|
|
2004
|
+
// src/schematic-components/SchematicElement.tsx
|
|
2005
|
+
var SchematicElement = ({
|
|
2006
|
+
element,
|
|
2007
|
+
allElements
|
|
2008
|
+
}) => {
|
|
2009
|
+
if (element.type === "schematic_component") {
|
|
2010
|
+
return <SchematicComponent_default component={collectElementRefs(element, allElements)} />;
|
|
2011
|
+
}
|
|
2012
|
+
if (element.type === "schematic_trace") {
|
|
2013
|
+
return <SchematicTrace_default trace={collectElementRefs(element, allElements)} />;
|
|
2014
|
+
}
|
|
2015
|
+
if (element.type === "schematic_port") {
|
|
2016
|
+
return <SchematicPort_default port={collectElementRefs(element, allElements)} />;
|
|
2017
|
+
}
|
|
2018
|
+
if (element.type === "schematic_text") {
|
|
2019
|
+
return <SchematicText_default schematic_text={element} />;
|
|
2020
|
+
}
|
|
2021
|
+
return null;
|
|
2130
2022
|
};
|
|
2131
2023
|
|
|
2132
2024
|
// src/Schematic.tsx
|
|
2133
|
-
var
|
|
2134
|
-
var
|
|
2135
|
-
var
|
|
2025
|
+
var import_use_mouse_matrix_transform = require("use-mouse-matrix-transform");
|
|
2026
|
+
var import_react_error_boundary = require("react-error-boundary");
|
|
2027
|
+
var fallbackRender = (elm) => ({ error, resetErrorBoundary }) => {
|
|
2028
|
+
return <div style={{ color: "red" }}>
|
|
2029
|
+
{"error rendering "}
|
|
2030
|
+
{elm.type}
|
|
2031
|
+
{": "}
|
|
2032
|
+
{error.toString()}
|
|
2033
|
+
</div>;
|
|
2034
|
+
};
|
|
2136
2035
|
var Schematic = ({
|
|
2137
2036
|
children,
|
|
2138
2037
|
elements: initialElements = []
|
|
2139
2038
|
}) => {
|
|
2140
2039
|
const [elements, setElements] = (0, import_react4.useState)(initialElements);
|
|
2141
2040
|
const [project, setProject] = (0, import_react4.useState)(null);
|
|
2041
|
+
const setCameraTransform = useRenderContext((s) => s.setCameraTransform);
|
|
2042
|
+
const { ref } = (0, import_use_mouse_matrix_transform.useMouseMatrixTransform)({
|
|
2043
|
+
onSetTransform: (transform2) => setCameraTransform(transform2),
|
|
2044
|
+
initialTransform: compose(scale(100, 100, 0, 0))
|
|
2045
|
+
});
|
|
2142
2046
|
(0, import_react4.useEffect)(() => {
|
|
2143
2047
|
if (initialElements.length > 0) {
|
|
2144
2048
|
setProject((0, import_builder2.createProjectFromElements)(initialElements));
|
|
@@ -2155,9 +2059,7 @@ var Schematic = ({
|
|
|
2155
2059
|
}, [children]);
|
|
2156
2060
|
if (elements.length === 0)
|
|
2157
2061
|
return null;
|
|
2158
|
-
return
|
|
2159
|
-
project
|
|
2160
|
-
});
|
|
2062
|
+
return <div ref={ref}>{elements.map((elm) => <import_react_error_boundary.ErrorBoundary fallbackRender={fallbackRender(elm)}><SchematicElement element={elm} allElements={elements} key={JSON.stringify(elm)} /></import_react_error_boundary.ErrorBoundary>)}</div>;
|
|
2161
2063
|
};
|
|
2162
2064
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2163
2065
|
0 && (module.exports = {
|