@tscircuit/schematic-viewer 1.4.1 → 1.4.2
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.css +7 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +118 -105
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Schematic.tsx +6 -5
- package/src/pages/style.css +5 -0
- package/src/schematic-components/SVGPathComponent.tsx +68 -29
- package/src/schematic-components/SchematicChip.tsx +35 -55
- package/src/schematic-components/SchematicComponent.tsx +1 -1
- package/src/schematic-components/SchematicText.tsx +1 -1
- package/src/schematic-components/SchematicTrace.tsx +4 -5
- package/src/stories/bug-high-port-numbers.stories.tsx +6 -1
package/dist/index.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/pages/style.css"],"sourcesContent":["@import url(\"https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&display=swap\");\n\n.schematic-text {\n font-family: \"IBM Plex Mono\", monospace;\n}\n"],"mappings":";;;AAEA;AACE;AAAA;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -89,8 +89,8 @@ var require_use_sync_external_store_shim_development = __commonJS({
|
|
|
89
89
|
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
90
90
|
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
91
91
|
}
|
|
92
|
-
var
|
|
93
|
-
var ReactSharedInternals =
|
|
92
|
+
var React = require("react");
|
|
93
|
+
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
94
94
|
function error(format) {
|
|
95
95
|
{
|
|
96
96
|
{
|
|
@@ -120,13 +120,13 @@ var require_use_sync_external_store_shim_development = __commonJS({
|
|
|
120
120
|
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
121
121
|
}
|
|
122
122
|
var objectIs = typeof Object.is === "function" ? Object.is : is;
|
|
123
|
-
var useState4 =
|
|
123
|
+
var useState4 = React.useState, useEffect3 = React.useEffect, useLayoutEffect = React.useLayoutEffect, useDebugValue2 = React.useDebugValue;
|
|
124
124
|
var didWarnOld18Alpha = false;
|
|
125
125
|
var didWarnUncachedGetSnapshot = false;
|
|
126
126
|
function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
|
|
127
127
|
{
|
|
128
128
|
if (!didWarnOld18Alpha) {
|
|
129
|
-
if (
|
|
129
|
+
if (React.startTransition !== void 0) {
|
|
130
130
|
didWarnOld18Alpha = true;
|
|
131
131
|
error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release.");
|
|
132
132
|
}
|
|
@@ -191,7 +191,7 @@ var require_use_sync_external_store_shim_development = __commonJS({
|
|
|
191
191
|
var canUseDOM = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
|
|
192
192
|
var isServerEnvironment = !canUseDOM;
|
|
193
193
|
var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
|
|
194
|
-
var useSyncExternalStore$2 =
|
|
194
|
+
var useSyncExternalStore$2 = React.useSyncExternalStore !== void 0 ? React.useSyncExternalStore : shim;
|
|
195
195
|
exports.useSyncExternalStore = useSyncExternalStore$2;
|
|
196
196
|
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function") {
|
|
197
197
|
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
@@ -285,14 +285,14 @@ var require_with_selector_development = __commonJS({
|
|
|
285
285
|
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
286
286
|
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
287
287
|
}
|
|
288
|
-
var
|
|
288
|
+
var React = require("react");
|
|
289
289
|
var shim = require_shim();
|
|
290
290
|
function is(x, y) {
|
|
291
291
|
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
292
292
|
}
|
|
293
293
|
var objectIs = typeof Object.is === "function" ? Object.is : is;
|
|
294
294
|
var useSyncExternalStore = shim.useSyncExternalStore;
|
|
295
|
-
var useRef3 =
|
|
295
|
+
var useRef3 = React.useRef, useEffect3 = React.useEffect, useMemo3 = React.useMemo, useDebugValue2 = React.useDebugValue;
|
|
296
296
|
function useSyncExternalStoreWithSelector2(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
|
|
297
297
|
var instRef = useRef3(null);
|
|
298
298
|
var inst;
|
|
@@ -1538,7 +1538,7 @@ var SVGPathComponent = ({
|
|
|
1538
1538
|
}) => {
|
|
1539
1539
|
const ct = useGlobalStore((s) => s.camera_transform);
|
|
1540
1540
|
const pathBounds = get_svg_path_bounds_default(
|
|
1541
|
-
paths.filter((p) => p.type !== "circle").map((p) => p.d)
|
|
1541
|
+
paths.filter((p) => p.type !== "circle" && p.type !== "text").map((p) => p.d)
|
|
1542
1542
|
);
|
|
1543
1543
|
const padding = { x: 0, y: 0 };
|
|
1544
1544
|
const absoluteCenter = applyToPoint(ct, center);
|
|
@@ -1561,59 +1561,85 @@ var SVGPathComponent = ({
|
|
|
1561
1561
|
),
|
|
1562
1562
|
translate(-pathBounds.minX, -pathBounds.minY)
|
|
1563
1563
|
);
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
{
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1564
|
+
const baseFontSize = 0.15;
|
|
1565
|
+
return (
|
|
1566
|
+
// biome-ignore lint/a11y/noSvgWithoutTitle: <explanation>
|
|
1567
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1568
|
+
"svg",
|
|
1569
|
+
{
|
|
1570
|
+
onMouseOver: () => setHovering(Boolean(hoverContent)),
|
|
1571
|
+
onFocus: () => setHovering(Boolean(hoverContent)),
|
|
1572
|
+
onMouseOut: () => setHovering(false),
|
|
1573
|
+
onBlur: () => setHovering(false),
|
|
1574
|
+
style: {
|
|
1575
|
+
position: "absolute",
|
|
1576
|
+
cursor: hovering ? "pointer" : void 0,
|
|
1577
|
+
zIndex,
|
|
1578
|
+
transform: [
|
|
1579
|
+
invertY ? "scale(1, 1)" : "scale(1, -1)",
|
|
1580
|
+
shiftToBottom ? "translate(0, 100%)" : "",
|
|
1581
|
+
rotation === 0 ? "" : `rotate(${rotation}deg)`
|
|
1582
|
+
].join(" "),
|
|
1583
|
+
left: svgLeft,
|
|
1584
|
+
top: svgTop
|
|
1585
|
+
},
|
|
1586
|
+
overflow: "visible",
|
|
1587
|
+
width: fullSize.width,
|
|
1588
|
+
height: fullSize.height,
|
|
1589
|
+
children: paths.map((p, i) => {
|
|
1590
|
+
if (p.type === "circle") {
|
|
1591
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1592
|
+
"circle",
|
|
1593
|
+
{
|
|
1594
|
+
transform: toSVG(compose(scale(1, 1), svgToScreen)),
|
|
1595
|
+
cx: p.cx,
|
|
1596
|
+
cy: p.cy,
|
|
1597
|
+
r: p.r,
|
|
1598
|
+
fill: "none",
|
|
1599
|
+
strokeWidth: 2.25 * (p.strokeWidth || 1),
|
|
1600
|
+
stroke: p.stroke || "red"
|
|
1601
|
+
},
|
|
1602
|
+
`${p.type}-${i}`
|
|
1603
|
+
);
|
|
1604
|
+
}
|
|
1605
|
+
if (p.type === "text") {
|
|
1606
|
+
const transformedPos = applyToPoint(svgToScreen, { x: p.cx, y: p.cy });
|
|
1607
|
+
const scaleFactor = fullSize.width / pathBounds.width || 1;
|
|
1608
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("g", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1609
|
+
"text",
|
|
1610
|
+
{
|
|
1611
|
+
className: "schematic-text",
|
|
1612
|
+
x: transformedPos.x,
|
|
1613
|
+
y: transformedPos.y,
|
|
1614
|
+
fill: p.fill,
|
|
1615
|
+
fontSize: baseFontSize * scaleFactor,
|
|
1616
|
+
textAnchor: p.anchor || "middle",
|
|
1617
|
+
dominantBaseline: "middle",
|
|
1618
|
+
transform: `scale(1,-1) rotate(${p.rotation || 0})`,
|
|
1619
|
+
style: {
|
|
1620
|
+
transformBox: "fill-box",
|
|
1621
|
+
transformOrigin: "center"
|
|
1622
|
+
},
|
|
1623
|
+
stroke: p.stroke,
|
|
1624
|
+
children: p.text
|
|
1625
|
+
}
|
|
1626
|
+
) }, `${p.type}-${i}`);
|
|
1627
|
+
}
|
|
1628
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1629
|
+
"path",
|
|
1630
|
+
{
|
|
1631
|
+
transform: toSVG(svgToScreen),
|
|
1632
|
+
fill: p.fill ?? "none",
|
|
1633
|
+
strokeLinecap: "round",
|
|
1634
|
+
strokeWidth: 1.5 * (p.strokeWidth || 1),
|
|
1635
|
+
stroke: p.stroke || "red",
|
|
1636
|
+
d: p.d || ""
|
|
1637
|
+
},
|
|
1638
|
+
`${p.type}-${i}`
|
|
1639
|
+
);
|
|
1640
|
+
})
|
|
1641
|
+
}
|
|
1642
|
+
)
|
|
1617
1643
|
);
|
|
1618
1644
|
};
|
|
1619
1645
|
var SVGPathComponent_default = SVGPathComponent;
|
|
@@ -1823,18 +1849,21 @@ var SchematicChip = ({
|
|
|
1823
1849
|
const schematicPorts = allElements.filter(
|
|
1824
1850
|
(item) => item.type === "schematic_port" && item.schematic_component_id === schematic_component_id
|
|
1825
1851
|
);
|
|
1826
|
-
const portLength = 0.
|
|
1827
|
-
const circleRadius = 0.
|
|
1852
|
+
const portLength = 0.5;
|
|
1853
|
+
const circleRadius = 0.04;
|
|
1828
1854
|
const labelOffset = 0.1;
|
|
1829
|
-
const
|
|
1830
|
-
schematicPorts.forEach((port) => {
|
|
1855
|
+
for (const port of schematicPorts) {
|
|
1831
1856
|
const { side, pinNumber, distanceFromEdge } = port.center;
|
|
1832
|
-
let x = 0
|
|
1833
|
-
let
|
|
1857
|
+
let x = 0;
|
|
1858
|
+
let y = 0;
|
|
1859
|
+
let endX = 0;
|
|
1860
|
+
let endY = 0;
|
|
1861
|
+
let pinX = 0;
|
|
1862
|
+
let pinY = 0;
|
|
1834
1863
|
let textAnchor = "middle";
|
|
1835
1864
|
let rotation2 = 0;
|
|
1836
1865
|
if (side === "center") {
|
|
1837
|
-
|
|
1866
|
+
continue;
|
|
1838
1867
|
}
|
|
1839
1868
|
switch (side) {
|
|
1840
1869
|
case "left":
|
|
@@ -1842,17 +1871,17 @@ var SchematicChip = ({
|
|
|
1842
1871
|
y = -chipHeight / 2 + distanceFromEdge;
|
|
1843
1872
|
endX = x - portLength;
|
|
1844
1873
|
endY = y;
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
textAnchor = "
|
|
1874
|
+
pinX = x - portLength / 2;
|
|
1875
|
+
pinY = y + labelOffset;
|
|
1876
|
+
textAnchor = "middle";
|
|
1848
1877
|
break;
|
|
1849
1878
|
case "right":
|
|
1850
1879
|
x = chipWidth / 2;
|
|
1851
1880
|
y = chipHeight / 2 - distanceFromEdge;
|
|
1852
1881
|
endX = x + portLength;
|
|
1853
1882
|
endY = y;
|
|
1854
|
-
|
|
1855
|
-
|
|
1883
|
+
pinX = x + portLength / 2 - labelOffset;
|
|
1884
|
+
pinY = y + labelOffset;
|
|
1856
1885
|
textAnchor = "start";
|
|
1857
1886
|
break;
|
|
1858
1887
|
case "bottom":
|
|
@@ -1860,8 +1889,8 @@ var SchematicChip = ({
|
|
|
1860
1889
|
y = -chipHeight / 2;
|
|
1861
1890
|
endX = x;
|
|
1862
1891
|
endY = y - portLength;
|
|
1863
|
-
|
|
1864
|
-
|
|
1892
|
+
pinX = x - labelOffset;
|
|
1893
|
+
pinY = y - portLength / 2;
|
|
1865
1894
|
rotation2 = -90;
|
|
1866
1895
|
break;
|
|
1867
1896
|
case "top":
|
|
@@ -1869,8 +1898,8 @@ var SchematicChip = ({
|
|
|
1869
1898
|
y = chipHeight / 2;
|
|
1870
1899
|
endX = x;
|
|
1871
1900
|
endY = y + portLength;
|
|
1872
|
-
|
|
1873
|
-
|
|
1901
|
+
pinX = x - labelOffset;
|
|
1902
|
+
pinY = y + portLength / 2;
|
|
1874
1903
|
rotation2 = -90;
|
|
1875
1904
|
break;
|
|
1876
1905
|
}
|
|
@@ -1885,20 +1914,23 @@ var SchematicChip = ({
|
|
|
1885
1914
|
cx: endX,
|
|
1886
1915
|
cy: endY,
|
|
1887
1916
|
r: circleRadius,
|
|
1888
|
-
strokeWidth:
|
|
1917
|
+
strokeWidth: 5e-3,
|
|
1889
1918
|
stroke: colorMap.schematic.component_outline,
|
|
1890
1919
|
fill: colorMap.schematic.component_outline
|
|
1891
1920
|
});
|
|
1892
1921
|
if (pinNumber !== void 0) {
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1922
|
+
paths.push({
|
|
1923
|
+
type: "text",
|
|
1924
|
+
cx: pinX,
|
|
1925
|
+
cy: pinY,
|
|
1896
1926
|
text: `${pinNumber}`,
|
|
1897
1927
|
anchor: textAnchor,
|
|
1898
|
-
rotation: rotation2
|
|
1928
|
+
rotation: rotation2,
|
|
1929
|
+
strokeWidth: 5e-3,
|
|
1930
|
+
stroke: colorMap.schematic.pin_number
|
|
1899
1931
|
});
|
|
1900
1932
|
}
|
|
1901
|
-
}
|
|
1933
|
+
}
|
|
1902
1934
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
1903
1935
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1904
1936
|
SVGPathComponent_default,
|
|
@@ -1909,25 +1941,6 @@ var SchematicChip = ({
|
|
|
1909
1941
|
paths
|
|
1910
1942
|
}
|
|
1911
1943
|
),
|
|
1912
|
-
pinLabels.map((label, index) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1913
|
-
SchematicText_default,
|
|
1914
|
-
{
|
|
1915
|
-
schematic_text: {
|
|
1916
|
-
anchor: label.anchor,
|
|
1917
|
-
rotation: 0,
|
|
1918
|
-
position: {
|
|
1919
|
-
x: center.x + label.x,
|
|
1920
|
-
y: center.y + label.y
|
|
1921
|
-
},
|
|
1922
|
-
schematic_component_id: "SYNTHETIC",
|
|
1923
|
-
schematic_text_id: `PIN_LABEL_${index}`,
|
|
1924
|
-
text: label.text,
|
|
1925
|
-
type: "schematic_text",
|
|
1926
|
-
color: colorMap.schematic.pin_number
|
|
1927
|
-
}
|
|
1928
|
-
},
|
|
1929
|
-
index
|
|
1930
|
-
)),
|
|
1931
1944
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1932
1945
|
SchematicText_default,
|
|
1933
1946
|
{
|
|
@@ -2318,7 +2331,7 @@ var SchematicWithoutContext = ({
|
|
|
2318
2331
|
);
|
|
2319
2332
|
updateTransform(newTransform);
|
|
2320
2333
|
}
|
|
2321
|
-
}, [elements,
|
|
2334
|
+
}, [elements, updateTransform]);
|
|
2322
2335
|
const handleMouseDown = (0, import_react8.useCallback)((e) => {
|
|
2323
2336
|
isDraggingRef.current = true;
|
|
2324
2337
|
lastMousePosRef.current = { x: e.clientX, y: e.clientY };
|
|
@@ -2346,7 +2359,7 @@ var SchematicWithoutContext = ({
|
|
|
2346
2359
|
const handleWheel = (0, import_react8.useCallback)(
|
|
2347
2360
|
(e) => {
|
|
2348
2361
|
e.preventDefault();
|
|
2349
|
-
const scaleMultiplier =
|
|
2362
|
+
const scaleMultiplier = 0.999 ** e.deltaY;
|
|
2350
2363
|
if (containerRef.current) {
|
|
2351
2364
|
const rect = containerRef.current.getBoundingClientRect();
|
|
2352
2365
|
const mouseX = e.clientX - rect.left;
|
|
@@ -2425,7 +2438,7 @@ var SchematicWithoutContext = ({
|
|
|
2425
2438
|
allElements: elements
|
|
2426
2439
|
},
|
|
2427
2440
|
JSON.stringify(elm)
|
|
2428
|
-
) },
|
|
2441
|
+
) }, `${elm}`))
|
|
2429
2442
|
]
|
|
2430
2443
|
}
|
|
2431
2444
|
),
|