@tscircuit/schematic-viewer 1.4.0 → 1.4.1
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/biome.json +45 -0
- package/dist/index.js +55 -16
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
- package/src/Schematic.tsx +3 -1
- package/src/lib/render-context/index.ts +1 -1
- package/src/lib/types/source-component.ts +1 -1
- package/src/lib/utils/collect-element-refs.ts +4 -4
- package/src/lib/utils/colors.ts +215 -216
- package/src/lib/utils/direction-to-vec.ts +3 -3
- package/src/schematic-components/SVGPathComponent.tsx +67 -48
- package/src/schematic-components/SchematicChip.tsx +124 -85
- package/src/schematic-components/SchematicComponent.tsx +17 -8
- package/src/schematic-components/SchematicComponentFromSymbol.tsx +3 -1
- package/src/schematic-components/SchematicNetLabel.tsx +3 -0
- package/src/schematic-components/SchematicText.tsx +4 -6
- package/src/schematic-components/SchematicTrace.tsx +1 -1
- package/src/schematic-components/TableViewer.tsx +1 -1
- package/src/schematic-components/index.tsx +0 -1
- package/src/stories/basics/schematic-net-label.stories.tsx +2 -0
- package/src/stories/bug-connections.stories.tsx +18 -16
- package/src/stories/bug-high-port-numbers.stories.tsx +16 -8
- package/src/stories/bug-one-sided.stories.tsx +17 -15
- package/src/stories/bug-pin-spacing.stories.tsx +19 -17
- package/src/stories/bugs/bug1-y-flip.stories.tsx +7 -5
- package/src/stories/bugs/bug5-diode.stories.tsx +3 -1
- package/src/stories/bugs/bug6-trace-scaling.stories.tsx +5 -41
- package/src/stories/led-circuit-react.stories.tsx +3 -8
- package/src/stories/rotated-resistor.stories.tsx +10 -8
- package/src/stories/three-sided-bug.stories.tsx +17 -15
package/biome.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
|
|
3
|
+
"organizeImports": {
|
|
4
|
+
"enabled": true
|
|
5
|
+
},
|
|
6
|
+
"formatter": {
|
|
7
|
+
"enabled": true,
|
|
8
|
+
"indentStyle": "space"
|
|
9
|
+
},
|
|
10
|
+
"files": {
|
|
11
|
+
"ignore": ["cosmos-export", "dist", "package.json"]
|
|
12
|
+
},
|
|
13
|
+
"javascript": {
|
|
14
|
+
"formatter": {
|
|
15
|
+
"jsxQuoteStyle": "double",
|
|
16
|
+
"quoteProperties": "asNeeded",
|
|
17
|
+
"trailingCommas": "all",
|
|
18
|
+
"semicolons": "asNeeded",
|
|
19
|
+
"arrowParentheses": "always",
|
|
20
|
+
"bracketSpacing": true,
|
|
21
|
+
"bracketSameLine": false
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"linter": {
|
|
25
|
+
"enabled": true,
|
|
26
|
+
"rules": {
|
|
27
|
+
"recommended": true,
|
|
28
|
+
"suspicious": {
|
|
29
|
+
"noExplicitAny": "off"
|
|
30
|
+
},
|
|
31
|
+
"style": {
|
|
32
|
+
"noNonNullAssertion": "off",
|
|
33
|
+
"useNumberNamespace": "off",
|
|
34
|
+
"useFilenamingConvention": {
|
|
35
|
+
"level": "error",
|
|
36
|
+
"options": {
|
|
37
|
+
"strictCase": true,
|
|
38
|
+
"requireAscii": true,
|
|
39
|
+
"filenameCases": ["kebab-case", "export"]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1537,7 +1537,9 @@ var SVGPathComponent = ({
|
|
|
1537
1537
|
hoverContent
|
|
1538
1538
|
}) => {
|
|
1539
1539
|
const ct = useGlobalStore((s) => s.camera_transform);
|
|
1540
|
-
const pathBounds = get_svg_path_bounds_default(
|
|
1540
|
+
const pathBounds = get_svg_path_bounds_default(
|
|
1541
|
+
paths.filter((p) => p.type !== "circle").map((p) => p.d)
|
|
1542
|
+
);
|
|
1541
1543
|
const padding = { x: 0, y: 0 };
|
|
1542
1544
|
const absoluteCenter = applyToPoint(ct, center);
|
|
1543
1545
|
const innerSize = {
|
|
@@ -1583,11 +1585,18 @@ var SVGPathComponent = ({
|
|
|
1583
1585
|
(p, i) => p.type === "circle" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1584
1586
|
"circle",
|
|
1585
1587
|
{
|
|
1588
|
+
transform: toSVG(
|
|
1589
|
+
compose(
|
|
1590
|
+
scale(1, 1),
|
|
1591
|
+
// Add a smaller scale factor for circles
|
|
1592
|
+
svgToScreen
|
|
1593
|
+
)
|
|
1594
|
+
),
|
|
1586
1595
|
cx: p.cx,
|
|
1587
1596
|
cy: p.cy,
|
|
1588
1597
|
r: p.r,
|
|
1589
|
-
fill:
|
|
1590
|
-
strokeWidth:
|
|
1598
|
+
fill: "none",
|
|
1599
|
+
strokeWidth: 2.25 * (p.strokeWidth || 1),
|
|
1591
1600
|
stroke: p.stroke || "red"
|
|
1592
1601
|
},
|
|
1593
1602
|
i
|
|
@@ -1785,7 +1794,8 @@ var SchematicText = ({ schematic_text }) => {
|
|
|
1785
1794
|
position: "absolute",
|
|
1786
1795
|
fontSize: projectedTextSize,
|
|
1787
1796
|
left: tPos.x + offset[0],
|
|
1788
|
-
top: tPos.y + offset[1]
|
|
1797
|
+
top: tPos.y + offset[1],
|
|
1798
|
+
color: schematic_text.color
|
|
1789
1799
|
},
|
|
1790
1800
|
children: text
|
|
1791
1801
|
}
|
|
@@ -1795,7 +1805,9 @@ var SchematicText_default = SchematicText;
|
|
|
1795
1805
|
|
|
1796
1806
|
// src/schematic-components/SchematicChip.tsx
|
|
1797
1807
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1798
|
-
var SchematicChip = ({
|
|
1808
|
+
var SchematicChip = ({
|
|
1809
|
+
component: { source, schematic, allElements }
|
|
1810
|
+
}) => {
|
|
1799
1811
|
const { center, size, rotation, schematic_component_id } = schematic;
|
|
1800
1812
|
const { manufacturerPartNumber, name } = source;
|
|
1801
1813
|
const chipWidth = size.width;
|
|
@@ -1820,6 +1832,10 @@ var SchematicChip = ({ component: { source, schematic, allElements } }) => {
|
|
|
1820
1832
|
let x = 0, y = 0, endX = 0, endY = 0;
|
|
1821
1833
|
let labelX = 0, labelY = 0;
|
|
1822
1834
|
let textAnchor = "middle";
|
|
1835
|
+
let rotation2 = 0;
|
|
1836
|
+
if (side === "center") {
|
|
1837
|
+
return;
|
|
1838
|
+
}
|
|
1823
1839
|
switch (side) {
|
|
1824
1840
|
case "left":
|
|
1825
1841
|
x = -chipWidth / 2;
|
|
@@ -1846,6 +1862,7 @@ var SchematicChip = ({ component: { source, schematic, allElements } }) => {
|
|
|
1846
1862
|
endY = y - portLength;
|
|
1847
1863
|
labelX = x;
|
|
1848
1864
|
labelY = endY + labelOffset;
|
|
1865
|
+
rotation2 = -90;
|
|
1849
1866
|
break;
|
|
1850
1867
|
case "top":
|
|
1851
1868
|
x = chipWidth / 2 - distanceFromEdge;
|
|
@@ -1854,11 +1871,12 @@ var SchematicChip = ({ component: { source, schematic, allElements } }) => {
|
|
|
1854
1871
|
endY = y + portLength;
|
|
1855
1872
|
labelX = x;
|
|
1856
1873
|
labelY = endY + labelOffset;
|
|
1874
|
+
rotation2 = -90;
|
|
1857
1875
|
break;
|
|
1858
1876
|
}
|
|
1859
1877
|
paths.push({
|
|
1860
1878
|
type: "path",
|
|
1861
|
-
strokeWidth: 0.
|
|
1879
|
+
strokeWidth: 0.015,
|
|
1862
1880
|
stroke: colorMap.schematic.component_outline,
|
|
1863
1881
|
d: `M ${x},${y} L ${endX},${endY}`
|
|
1864
1882
|
});
|
|
@@ -1876,7 +1894,8 @@ var SchematicChip = ({ component: { source, schematic, allElements } }) => {
|
|
|
1876
1894
|
x: labelX,
|
|
1877
1895
|
y: labelY,
|
|
1878
1896
|
text: `${pinNumber}`,
|
|
1879
|
-
anchor: textAnchor
|
|
1897
|
+
anchor: textAnchor,
|
|
1898
|
+
rotation: rotation2
|
|
1880
1899
|
});
|
|
1881
1900
|
}
|
|
1882
1901
|
});
|
|
@@ -1895,6 +1914,7 @@ var SchematicChip = ({ component: { source, schematic, allElements } }) => {
|
|
|
1895
1914
|
{
|
|
1896
1915
|
schematic_text: {
|
|
1897
1916
|
anchor: label.anchor,
|
|
1917
|
+
rotation: 0,
|
|
1898
1918
|
position: {
|
|
1899
1919
|
x: center.x + label.x,
|
|
1900
1920
|
y: center.y + label.y
|
|
@@ -1902,7 +1922,8 @@ var SchematicChip = ({ component: { source, schematic, allElements } }) => {
|
|
|
1902
1922
|
schematic_component_id: "SYNTHETIC",
|
|
1903
1923
|
schematic_text_id: `PIN_LABEL_${index}`,
|
|
1904
1924
|
text: label.text,
|
|
1905
|
-
type: "schematic_text"
|
|
1925
|
+
type: "schematic_text",
|
|
1926
|
+
color: colorMap.schematic.pin_number
|
|
1906
1927
|
}
|
|
1907
1928
|
},
|
|
1908
1929
|
index
|
|
@@ -1911,7 +1932,8 @@ var SchematicChip = ({ component: { source, schematic, allElements } }) => {
|
|
|
1911
1932
|
SchematicText_default,
|
|
1912
1933
|
{
|
|
1913
1934
|
schematic_text: {
|
|
1914
|
-
anchor: "
|
|
1935
|
+
anchor: "right",
|
|
1936
|
+
rotation: 0,
|
|
1915
1937
|
position: {
|
|
1916
1938
|
x: center.x,
|
|
1917
1939
|
y: center.y - chipHeight / 2 - 0.2
|
|
@@ -1919,7 +1941,8 @@ var SchematicChip = ({ component: { source, schematic, allElements } }) => {
|
|
|
1919
1941
|
schematic_component_id: "SYNTHETIC",
|
|
1920
1942
|
schematic_text_id: "SYNTHETIC_MPN",
|
|
1921
1943
|
text: manufacturerPartNumber,
|
|
1922
|
-
type: "schematic_text"
|
|
1944
|
+
type: "schematic_text",
|
|
1945
|
+
color: colorMap.schematic.reference
|
|
1923
1946
|
}
|
|
1924
1947
|
}
|
|
1925
1948
|
),
|
|
@@ -1927,7 +1950,8 @@ var SchematicChip = ({ component: { source, schematic, allElements } }) => {
|
|
|
1927
1950
|
SchematicText_default,
|
|
1928
1951
|
{
|
|
1929
1952
|
schematic_text: {
|
|
1930
|
-
anchor: "
|
|
1953
|
+
anchor: "right",
|
|
1954
|
+
rotation: 0,
|
|
1931
1955
|
position: {
|
|
1932
1956
|
x: center.x,
|
|
1933
1957
|
y: center.y + chipHeight / 2 + 0.2
|
|
@@ -1935,7 +1959,8 @@ var SchematicChip = ({ component: { source, schematic, allElements } }) => {
|
|
|
1935
1959
|
schematic_component_id: "SYNTHETIC",
|
|
1936
1960
|
schematic_text_id: "SYNTHETIC_NAME",
|
|
1937
1961
|
text: name,
|
|
1938
|
-
type: "schematic_text"
|
|
1962
|
+
type: "schematic_text",
|
|
1963
|
+
color: colorMap.schematic.reference
|
|
1939
1964
|
}
|
|
1940
1965
|
}
|
|
1941
1966
|
)
|
|
@@ -1955,11 +1980,21 @@ var SchematicComponent = ({ component }) => {
|
|
|
1955
1980
|
case "simple_ground":
|
|
1956
1981
|
case "simple_inductor":
|
|
1957
1982
|
case "simple_diode": {
|
|
1958
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1983
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1984
|
+
SchematicComponentFromSymbol,
|
|
1985
|
+
{
|
|
1986
|
+
component: { source, schematic }
|
|
1987
|
+
}
|
|
1988
|
+
);
|
|
1959
1989
|
}
|
|
1960
1990
|
case "simple_chip":
|
|
1961
1991
|
case "simple_bug": {
|
|
1962
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1992
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1993
|
+
SchematicChip,
|
|
1994
|
+
{
|
|
1995
|
+
component: { source, schematic, allElements }
|
|
1996
|
+
}
|
|
1997
|
+
);
|
|
1963
1998
|
}
|
|
1964
1999
|
default: {
|
|
1965
2000
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
|
|
@@ -1974,7 +2009,9 @@ var SchematicComponent_default = SchematicComponent;
|
|
|
1974
2009
|
// src/schematic-components/SchematicComponentFromSymbol.tsx
|
|
1975
2010
|
var import_schematic_symbols = require("schematic-symbols");
|
|
1976
2011
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1977
|
-
var SchematicComponentFromSymbol = ({
|
|
2012
|
+
var SchematicComponentFromSymbol = ({
|
|
2013
|
+
component: { source, schematic }
|
|
2014
|
+
}) => {
|
|
1978
2015
|
const { center, rotation } = schematic;
|
|
1979
2016
|
const symbol = import_schematic_symbols.symbols[schematic.symbol_name];
|
|
1980
2017
|
const paths = symbol.primitives.filter((p) => p.type === "path").map((p) => ({
|
|
@@ -2151,6 +2188,7 @@ var SchematicNetLabel = ({
|
|
|
2151
2188
|
SchematicText_default,
|
|
2152
2189
|
{
|
|
2153
2190
|
schematic_text: {
|
|
2191
|
+
rotation: is_vertical ? 0 : getRotationFromAnchorSide(anchor_side),
|
|
2154
2192
|
anchor: is_vertical ? "center" : anchor_side,
|
|
2155
2193
|
position: {
|
|
2156
2194
|
x: net_label.center.x + anchor_vec.x,
|
|
@@ -2159,7 +2197,8 @@ var SchematicNetLabel = ({
|
|
|
2159
2197
|
schematic_component_id: "SYNTHETIC",
|
|
2160
2198
|
schematic_text_id: "SYNTHETIC",
|
|
2161
2199
|
text: net_label.text,
|
|
2162
|
-
type: "schematic_text"
|
|
2200
|
+
type: "schematic_text",
|
|
2201
|
+
color: colorMap.schematic.net_name
|
|
2163
2202
|
}
|
|
2164
2203
|
}
|
|
2165
2204
|
)
|